- AIX
At least as of version 5.1, it should not be necessary to do
any special configuration for such parameters as
SHMMAX, as it appears this is configured to
allow all memory to be used as shared memory. That is the
sort of configuration commonly used for other databases such
as DB/2.
It might, however, be necessary to modify the global
ulimit information in
/etc/security/limits, as the default hard
limits for file sizes (fsize) and numbers of
files (nofiles) might be too low.
- BSD/OS
- FreeBSD
The default settings are only suitable for small installations
(for example, default SHMMAX is 32
MB). Changes can be made via the sysctl or
loader interfaces. The following
parameters can be set using sysctl:
$ sysctl -w kern.ipc.shmall=32768
$ sysctl -w kern.ipc.shmmax=134217728
$ sysctl -w kern.ipc.semmap=256
To have these settings persist over reboots, modify
/etc/sysctl.conf.
The remaining semaphore settings are read-only as far as
sysctl is concerned, but can be changed
before boot using the loader prompt:
(loader) set kern.ipc.semmni=256
(loader) set kern.ipc.semmns=512
(loader) set kern.ipc.semmnu=256
Similarly these can be saved between reboots in
/boot/loader.conf.
You might also want to configure your kernel to lock shared
memory into RAM and prevent it from being paged out to swap.
This can be accomplished using the sysctl
setting kern.ipc.shm_use_phys.
If running in FreeBSD jails by enabling sysctl's
security.jail.sysvipc_allowed, postmasters
running in different jails should be run by different operating system
users. This improves security because it prevents non-root users
from interfering with shared memory or semaphores in different jails,
and it allows the PostgreSQL IPC cleanup code to function properly.
(In FreeBSD 6.0 and later the IPC cleanup code does not properly detect
processes in other jails, preventing the running of postmasters on the
same port in different jails.)
FreeBSD versions before 4.0 work like
NetBSD and OpenBSD (see below).
- NetBSD
OpenBSD The options SYSVSHM and SYSVSEM need
to be enabled when the kernel is compiled. (They are by
default.) The maximum size of shared memory is determined by
the option SHMMAXPGS (in pages). The following
shows an example of how to set the various parameters on
NetBSD
(OpenBSD uses option instead):
options SYSVSHM
options SHMMAXPGS=4096
options SHMSEG=256
options SYSVSEM
options SEMMNI=256
options SEMMNS=512
options SEMMNU=256
options SEMMAP=256
You might also want to configure your kernel to lock shared
memory into RAM and prevent it from being paged out to swap.
This can be accomplished using the sysctl
setting kern.ipc.shm_use_phys.
- HP-UX
The default settings tend to suffice for normal installations.
On HP-UX 10, the factory default for
SEMMNS is 128, which might be too low for larger
database sites.
IPC parameters can be set in the System
Administration Manager (SAM) under
->. Choose
Create A New Kernel when you're done.
- Linux
The default maximum segment size is 32 MB, which is only adequate
for very small PostgreSQL
installations. The default maximum total size is 2097152
pages. A page is almost always 4096 bytes except in unusual
kernel configurations with "huge pages"
(use getconf PAGE_SIZE to verify). That
makes a default limit of 8 GB, which is often enough, but not
always.
The shared memory size settings can be changed via the
sysctl interface. For example, to allow 16 GB:
$ sysctl -w kernel.shmmax=17179869184
$ sysctl -w kernel.shmall=4194304
In addition these settings can be preserved between reboots in
the file /etc/sysctl.conf. Doing that is
highly recommended.
Ancient distributions might not have the sysctl program,
but equivalent changes can be made by manipulating the
/proc file system:
$ echo 17179869184 >/proc/sys/kernel/shmmax
$ echo 4194304 >/proc/sys/kernel/shmall
The remaining defaults are quite generously sized, and usually
do not require changes.
- Mac OS X
The recommended method for configuring shared memory in OS X
is to create a file named /etc/sysctl.conf,
containing variable assignments such as:
kern.sysv.shmmax=4194304
kern.sysv.shmmin=1
kern.sysv.shmmni=32
kern.sysv.shmseg=8
kern.sysv.shmall=1024
Note that in some OS X versions,
all five shared-memory parameters must be set in
/etc/sysctl.conf, else the values will be ignored.
Beware that recent releases of OS X ignore attempts to set
SHMMAX to a value that isn't an exact multiple of 4096.
SHMALL is measured in 4 kB pages on this platform.
In older OS X versions, you will need to reboot to have changes in the
shared memory parameters take effect. As of 10.5 it is possible to
change all but SHMMNI on the fly, using
sysctl. But it's still best to set up your preferred
values via /etc/sysctl.conf, so that the values will be
kept across reboots.
The file /etc/sysctl.conf is only honored in OS X
10.3.9 and later. If you are running a previous 10.3.x release,
you must edit the file /etc/rc
and change the values in the following commands:
sysctl -w kern.sysv.shmmax
sysctl -w kern.sysv.shmmin
sysctl -w kern.sysv.shmmni
sysctl -w kern.sysv.shmseg
sysctl -w kern.sysv.shmall
Note that
/etc/rc is usually overwritten by OS X system updates,
so you should expect to have to redo these edits after each update.
In OS X 10.2 and earlier, instead edit these commands in the file
/System/Library/StartupItems/SystemTuning/SystemTuning.
- SCO OpenServer
In the default configuration, only 512 kB of shared memory per
segment is allowed. To increase the setting, first change to the
directory /etc/conf/cf.d. To display the current value of
SHMMAX, run:
./configure -y SHMMAX
To set a new value for SHMMAX, run:
./configure SHMMAX=value
where value is the new value you want to use
(in bytes). After setting SHMMAX, rebuild the kernel:
./link_unix
and reboot.
- Solaris 2.6 to 2.9 (Solaris
6 to Solaris 9)
The default maximum size of a shared memory segment is too low for
PostgreSQL. The relevant settings can be changed in
/etc/system, for example:
set shmsys:shminfo_shmmax=0x2000000
set shmsys:shminfo_shmmin=1
set shmsys:shminfo_shmmni=256
set shmsys:shminfo_shmseg=256
set semsys:seminfo_semmap=256
set semsys:seminfo_semmni=512
set semsys:seminfo_semmns=512
set semsys:seminfo_semmsl=32
You need to reboot for the changes to take effect. See also
http://sunsite.uakom.sk/sunworldonline/swol-09-1997/swol-09-insidesolaris.html
for information on shared memory under older versions of Solaris.
- Solaris 2.10 (Solaris
10)
OpenSolaris In Solaris 10 and OpenSolaris, the default shared memory and
semaphore settings are good enough for most
PostgreSQL applications. Solaris now defaults
to a SHMMAX of one-quarter of system RAM. If
you need to increase this in order to set shared memory settings
slightly higher, you should use a project setting associated
with the postgres user. For example, run the
following as root:
projadd -c "PostgreSQL DB User" -K "project.max-shm-memory=(privileged,8GB,deny)" -U postgres -G postgres user.postgres
This command adds the user.postgres project and
raises the shared memory maximum for the postgres
user to 8GB, and takes effect the next time that user logs
in, or when you restart PostgreSQL (not reload).
The above assumes that PostgreSQL is run by
the postgres user in the postgres
group. No server reboot is required.
Other recommended kernel setting changes for database servers which will
have a large number of connections are:
project.max-shm-ids=(priv,32768,deny)
project.max-sem-ids=(priv,4096,deny)
project.max-msg-ids=(priv,4096,deny)
Additionally, if you are running PostgreSQL
inside a zone, you may need to raise the zone resource usage
limits as well. See "Chapter2: Projects and Tasks" in the
Solaris 10 System Administrator's Guide for more
information on projects and prctl.
- UnixWare
On UnixWare 7, the maximum size for shared
memory segments is only 512 kB in the default configuration.
To display the current value of SHMMAX, run:
/etc/conf/bin/idtune -g SHMMAX
which displays the current, default, minimum, and maximum
values. To set a new value for SHMMAX,
run:
/etc/conf/bin/idtune SHMMAX value
where value is the new value you want to use
(in bytes). After setting SHMMAX, rebuild the
kernel:
/etc/conf/bin/idbuild -B
and reboot.