Hi All,
I tried to follow the instructions that are described here:
http://www.postgresql.org/docs/8.1/interactive/kernel-resources.html#SHARED-MEMORY-PARAMETERS
http://www.postgresql.org/docs/8.1/interactive/kernel-resources.html#SYSVIPC
My values config are:
page size = 4096
BLCKSZ = 8
max_connections=50
max_prepared_transactions=5
shared_buffers=2048
wal_buffers=8
max_fsm_relations=3000
max_fsm_pages=450000
I'm using FreeBSD 6.2 and I have a test machine with 1GB memory. I would
like to use 25% (256MB) as shared memory.
Here is what I have calculated (Python syntax, but probably everybody
will understand):
shmmin = \
parvalues['max_connections']*(400 +
220*parvalues['max_locks_per_transaction']) +\
parvalues['max_prepared_transactions']*(600 +
220*parvalues['max_locks_per_transaction']) +\
parvalues['shared_buffers']*parvalues['BLCKSZ']*8300 +\
parvalues['wal_buffers']*parvalues['BLCKSZ']*8200 +\
parvalues['max_fsm_relations']*70 +\
parvalues['max_fsm_pages']*6+\
500*1024 # From the docs: As a rough approximation, you can estimate
the required segment size as 500 kB plus the variable amounts shown in
the table.
The result for this was:
Minimum shared mem: 140731400 bytes = 135.0 MB
Maximum shared mem: 268435456 bytes = 256.0 MB
So far I put these values in /boot/loader.conf (they were also
calculated, I followed the recommendations in the docs):
kern.ipc.shmall="65536"
kern.ipc.shmmin="140731400"
kern.ipc.shmmax="268435456"
kern.ipc.shmseg="10"
kern.ipc.shmmni="30"
kern.ipc.semmni="66"
kern.ipc.semmns="372"
kern.ipc.semmsl="240"
kern.ipc.semmap="372"
kern.ipc.shm_use_phys="1"
After rebooted I got this message:
Nov 13 20:46:19 neptunus postgres[669]: [1-1] FATAL: could not create
shared memory segment: Invalid argument
Nov 13 20:46:19 neptunus postgres[669]: [1-2] DETAIL: Failed system
call was shmget(key=5432001, size=21725184, 03600).
Nov 13 20:46:19 neptunus postgres[669]: [1-3] HINT: This error usually
means that PostgreSQL's request for a shared memory segment exceeded
your kernel's SHMMAX parameter.
Nov 13 20:46:19 neptunus postgres[669]: [1-4] You can either reduce the
request size or reconfigure the kernel with larger SHMMAX. To reduce
the request size (currently
Nov 13 20:46:19 neptunus postgres[669]: [1-5] 21725184 bytes), reduce
PostgreSQL's shared_buffers parameter (currently 2048) and/or its
max_connections parameter (currently
Nov 13 20:46:19 neptunus postgres[669]: [1-6] 50).
Nov 13 20:46:19 neptunus postgres[669]: [1-7] If the request size is
already small, it's possible that it is less than your kernel's SHMMIN
parameter, in which case raising
Nov 13 20:46:19 neptunus postgres[669]: [1-8] the request size or
reconfiguring SHMMIN is called for.
What is wrong with my calculation?
The reason for this question: I'm writing a program that reads some
input parameters (PostgreSQL and kernel configuration parameters),
queries the computer for kernel page size, total available memory etc.
and finally it calculates sysctl values.
This is not a toy: I have a server with memory problems and I would also
like to find the optimal settings. (e.g. keep shared memory in physical
memory, optimize for performance, but do not reserve more memory than
needed). I would also like to contribute this program so other beginners
will be able to set these parameters easily. My idea was that this
program would warn me whenever there is a problem (e.g. SHMMIN > SHMMAX)
but apparently I could not understand the basics and I failed to write
the calculations.
Thanks,
Laszlo
---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings