pq: could not resize shared memory segment. No space left on device
You can increase shm size by remounting it without restarting/rebuilding container
mount -o remount,size=256m -t tmpfs /var/lib/docker/containers/your-container-id/mounts/shm
Change your-container-id and needed size (256m)
Sorry for the late reply. Building a new image is not necessary. But you must be sure the container is recreated, and you are not using the old one.
Docker-compose file must be changed with, adding shm_size
at service level. Build section is not necessary.
version: "3.5"
services:
#other containers go here..
postgres:
restart: always
image: postgres:10
#THIS MUST BE ADDED AT SERVICE LEVEL
shm_size: 1gb
hostname: postgres
container_name: fiware-postgres
expose:
- "5432"
ports:
- "5432:5432"
networks:
- default
environment:
- "POSTGRES_PASSWORD=password"
- "POSTGRES_USER=postgres"
- "POSTGRES_DB=postgres"
volumes:
- ./postgres-data:/var/lib/postgresql/data
Then you must completely recreate the container
docker-compose rm postgres
# alternatively you can docker-compose down to destroy all containers
docker-compose up -d
to destroy the old container and create a new one.
You can check the change inside the container (enter with docker-compose exec postgres bash
) and run df -h | grep shm
Reference:docker SHM_SIZE /dev/shm: resizing shared memory
After increasing shm_size: did not help me out, I turned to db optimization and found that adding some missing indexes solved this error in my particular case.
Specifically I had several views that used joins on fields w/o indexes, and once the db got to typical size (1M rows in "many" side of joins) these errors began.
This is because docker by-default restrict size of shared memory to 64MB
.
You can override this default value by using --shm-size
option in docker run
.
docker run -itd --shm-size=1g postgres
or in docker-compose:
db:
image: "postgres:11.3-alpine"
shm_size: 1g
Check this out. More info here.
Hope this helps.