How to Resolve ERROR: could not resize shared memory segment “/PostgreSQL” No space left on device with Postgres Docker Image
If you are using Postgres DB server with a docker image and if you want to add more users for your database there is a chance that you may encounter the error mentioned in the subject of this blog post. I will mention the quick steps that you can follow to get this resolved by resizing your shared memory allocated for the docker container.
I was able to get this resolved on top of a ubuntu 16.04 OS with the below steps.
- Get the docker image container ID for the relevant postgres server
sudo docker ps -a
2. Now check the allocated shm space for that conatiner id. (a1d302620d5c is the container id)
sudo docker exec -it a1d302620d5c df -h /dev/shm
OUTPUT
Filesystem Size Used Avail Use% Mounted on
shm 64M 28K 64M 1% /dev/shm
3. Stop the docker container if its running
sudo docker stop a1d302620d5c
4. With your local machine navigate to below folder location
/var/lib/docker/containers/a1d302620d5ca267f633eea8f5d99f05b5f5c132b0b6dd13fcbf51379d24be35(container id)
5. Shut down the docker service (This is mandotory if not the changes you apply would not be available)
sudo service docker stop
6. Check the status
sudo service docker status
7. Open the file with vi tool /var/lib/docker/containers/a1d302620d5ca267f633eea8f5d99f05b5f5c132b0b6dd13fcbf51379d24be35/hostconfig.json
8. Locate the element “ShmSize”: and change it as below to allocate 1GB space
“ShmSize”:1073741824
9. save the file
:wq!
10. Start the docker service
sudo service docker start
11. Check the server status and it should show as its running.
12. Now get the docker container ID and start the docker container
sudo docker ps -a
sudo docker start a1d302620d5c
13. Now check the allocated shm space for that container ID
sudo docker exec -it a1d302620d5c df -h /dev/shm
OUTPUT
Filesystem Size Used Avail Use% Mounted on
shm 1.0G 28K 1.0G 1% /dev/shm