We have postgresql 11.7 database in docker container.

We had an issue "pq: could not resize shared memory segment "/PostgreSQL.XXX" to XXX bytes: No space left on device", described here.

Solution helped, we do not have an issue anymore. But which size should we set for shm_size for docker container with Postgres?

Is any recommendation? How can we calculate 'optimal size' for shm_size?

  • Depends on your shared_buffers setting. That depends on your requirements. Sep 11, 2020 at 13:39
  • We also found that shm size depend on max_parallel_workers_per_gather parameter, not just only shared_buffers. We want to know more detailed recommensation... We set shared_buffers to 1GB and shm size to 1.1GB but isse still persist. We set max_parallel_workers_per_gather from 2 to 1 and iisue was resolved. For now we set shm_size to 2.2GB, shared_buffers 1 GB, max_parallel_workers_per_gather =2 and all fine. Sep 11, 2020 at 15:07

1 Answer 1


There are two things that use shared memory:

  • The shared memory that is allocated at server start. This consists of several parts, but the lion's share is shared_buffers, the data cache.

    So you have to have more shared memory than that.

  • Shared memory segments allocated by parallel query to communicate between parallel workers.

    Their size depends on the data transferred, and several of them can be allocated, so that is a resource that is harder to control.

On a memory-constrained system, I'd recommend that you disable parallel query. It makes queries faster, but uses more resources per query, so overall throughput doesn't improve. It is good if you want to throw a lot of resources on a single query.

To disable parallel query, set max_parallel_workers to 0.

  • Based on postgrespro.com/list/thread-id/2448119 and observing the behavior of the PostgreSQL Docker image, I'm not convinced shared_buffers is allocated from shm. We're running with 1GB shared_buffers and shm-size of 256MB and it seems to be OK. Jul 28 at 14:03
  • @lmsurprenant PostgreSQL doesn't use a lot of System V shared memory, so those limits won't apply. It uses POSIX shared memory. Aug 12 at 18:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.