Thread: How to calculate shared memory size

How to calculate shared memory size

From
Rébeli-Szabó Tamás
Date:
Hello all,

I want to do a proper calculation of the number of huge pages needed for 
PostgreSQL to start.

For that I need to know how much shared memory will be allocated at 
startup.

Looking at the shared memory calculation in the source (ipci.c), I can 
see that two terms stand out:

   size = add_size(size, BufferShmemSize()); ---> shared_buffers
   size = add_size(size, XLOGShmemSize()); --> 1/32 * shared_buffers, but 
max WAL segment size

However, if I only use those two terms (shared buffers + WAL segment 
size) for my calculation, the result will be off by a lot, especially 
with bigger shared buffers (e.g. 32 GB).

What are any other major terms (in the order of 10 megabytes or more) 
that I need to take into account to get a better result?

Regards,

tamas



Re: How to calculate shared memory size

From
Tom Lane
Date:
=?UTF-8?Q?R=C3=A9beli-Szab=C3=B3_Tam=C3=A1s?= <t@rblst.info> writes:
> I want to do a proper calculation of the number of huge pages needed for 
> PostgreSQL to start.
> For that I need to know how much shared memory will be allocated at 
> startup.

TBH, the only method that's not going to break over time is
"start the server with the parameters you want, and look to
see how big the shmem segment is".

We used to have an approximate formula in the documentation,
but we took it out years ago because it was constantly out of date.

            regards, tom lane