/dev/shm size recommendation for postgres database in docker
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.