Postgres: Hit by size limit of /dev/shm

Created on 20 Feb 2018  路  5Comments  路  Source: docker-library/postgres

The default limit for Docker containers seems to be 64MB

ERROR:  could not resize shared memory segment "/PostgreSQL.2088012784" to 50438144 bytes: No space left on device

I couldn't really find how to calculate the required size of /dev/shm looking at the documentation. Which Postgres configuration options affect the required size and would it be feasable to tune shm_size accordingly?

Maybe it would be worth to extend the image documentation.

Request question

Most helpful comment

I think at least the information about changing the default SHM size should be added to the documentation (like a tip: "You may want to change the default shared memory by passing --shm-size=256M to docker run"). I did not found the file which maps to the "Full Description" section on postgres page on docker hub - where I can find it so I can submit a PR?

Related issue (change SHM size of a running container): https://github.com/docker/cli/issues/1278

All 5 comments

According to @macdice the issue seems to be triggered by complex queries and an increased number of max_parallel_workers_per_gather (tested with 4; the default is 2).

Indeed, the default in Docker for /dev/shm size is 64MB:

$ docker run -it --rm alpine:3.7 df -hT /dev/shm
Filesystem           Type            Size      Used Available Use% Mounted on
shm                  tmpfs          64.0M         0     64.0M   0% /dev/shm

There is also a --shm-size argument to docker run which can be used to adjust this:

$ docker run -it --rm --shm-size 128m alpine:3.7 df -hT /dev/shm
Filesystem           Type            Size      Used Available Use% Mounted on
shm                  tmpfs         128.0M         0    128.0M   0% /dev/shm

This is _not_ something the image can set automatically, and as you alluded to, I think the "recommended value" is going to vary from deployment to deployment (based on both user requirements and supplied configuration).

I think it would be a good idea to add it to the image documentation. The limited /dev/shm size is a potential pitfal as the error in the Postgres log isn't really straightforward and will only affect containerized Postgres installations.

I think at least the information about changing the default SHM size should be added to the documentation (like a tip: "You may want to change the default shared memory by passing --shm-size=256M to docker run"). I did not found the file which maps to the "Full Description" section on postgres page on docker hub - where I can find it so I can submit a PR?

Related issue (change SHM size of a running container): https://github.com/docker/cli/issues/1278

@turicas :wink:

Was this page helpful?
0 / 5 - 0 ratings