HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqldockerMinor

/dev/shm size recommendation for postgres database in docker

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
postgresdockersizedevshmrecommendationdatabasefor

Problem

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?

Solution

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.

Context

StackExchange Database Administrators Q#275378, answer score: 5

Revisions (0)

No revisions yet.