Relationship between shared buffer and shm_size
mfvas
PROOP

10 months ago

As the title says: What's the relationship between shared buffer and the shm size (RAILWAY_SHM_SIZE_BYTES)?

My guess would be that shm_size limits how much shared buffer the postgres db can create. But by default, shared buffer is 128MB and shm_size 64MB, as far as I remember. So that doesn't seem true.

And the conventional rule-of-thumb is to set shared buffet to 25% of available ram, whereas you always recommend being conservative with shm_size.

$10 Bounty

6 Replies

lofimit
HOBBY

10 months ago

Alright, so PostgreSQL's shared_buffers is basically memory it grabs from the OS’s shared memory (shm). If your shm_size (RAILWAY_SHM_SIZE_BYTES) is smaller than shared_buffers, Postgres won't start or will crash with errors.

On Railway, default shm_size might be 64MB but shared_buffers defaults to 128MB, so that mismatch breaks stuff.

Most likely problem: shm_size is too small for the shared_buffers you want.

Solution: Set shm_size at least a bit bigger than shared_buffers. For example, if you want 8GB shared_buffers, you should set shm_size to like 8.5GB.

Keep shared_buffers around 25% of your RAM, but make sure shm_size matches or exceeds it. That usually fixes the problem.

PostgreSQL: Documentation: 17: 19.4. Resource Consumption


lofimit

Alright, so PostgreSQL's shared_buffers is basically memory it grabs from the OS’s shared memory (shm). If your shm_size (RAILWAY_SHM_SIZE_BYTES) is smaller than shared_buffers, Postgres won't start or will crash with errors.On Railway, default shm_size might be 64MB but shared_buffers defaults to 128MB, so that mismatch breaks stuff.Most likely problem: shm_size is too small for the shared_buffers you want.Solution: Set shm_size at least a bit bigger than shared_buffers. For example, if you want 8GB shared_buffers, you should set shm_size to like 8.5GB.Keep shared_buffers around 25% of your RAM, but make sure shm_size matches or exceeds it. That usually fixes the problem.PostgreSQL: Documentation: 17: 19.4. Resource Consumption

10 months ago

We do not allow setting the shm size anywhere near 8GB, is most cases you should never need to set it above 500 MB, so please don't recommend that users set it to gigabyte values.


brody

We do not allow setting the shm size anywhere near 8GB, is most cases you should never need to set it above 500 MB, so please don't recommend that users set it to gigabyte values.

lofimit
HOBBY

10 months ago

I did not, it was simply an example.
The size is always subjective to each project and server, I am just giving an example on how I'd calculate the proportions and I found it easier to do in GBs.


brody

We do not allow setting the shm size anywhere near 8GB, is most cases you should never need to set it above 500 MB, so please don't recommend that users set it to gigabyte values.

mfvas
PROOP

10 months ago

Why not, though? If the rule of thumb us 25% or RAM, and the instance can use up to 32GB of RAM, why not set the shm size at 8GB?


lofimit

Alright, so PostgreSQL's shared_buffers is basically memory it grabs from the OS’s shared memory (shm). If your shm_size (RAILWAY_SHM_SIZE_BYTES) is smaller than shared_buffers, Postgres won't start or will crash with errors.On Railway, default shm_size might be 64MB but shared_buffers defaults to 128MB, so that mismatch breaks stuff.Most likely problem: shm_size is too small for the shared_buffers you want.Solution: Set shm_size at least a bit bigger than shared_buffers. For example, if you want 8GB shared_buffers, you should set shm_size to like 8.5GB.Keep shared_buffers around 25% of your RAM, but make sure shm_size matches or exceeds it. That usually fixes the problem.PostgreSQL: Documentation: 17: 19.4. Resource Consumption

mfvas
PROOP

10 months ago

Thanks for your thorough answer! That’s what I thought, too. But my DB starts fine despite the mismatch. So, that's why I got curious. I had some errors when vacuum’ing, though.


mfvas

Thanks for your thorough answer! That’s what I thought, too. But my DB starts fine despite the mismatch. So, that's why I got curious. I had some errors when vacuum’ing, though.

lofimit
HOBBY

10 months ago

Reminding you to mark the thread as solved in case you have no other questions/issues heart emoji


Loading...