/dev/shm size recommendation for postgres database in docker We have postgresql 11.7 database in docker container.
We had an issue &quot;pq: could not resize shared memory segment &quot;/PostgreSQL.XXX&quot; to XXX bytes: No space left on device&quot;, 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?
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.