+ linkend="sysvipc-parameters"> gives an overview. The methods to
+ set them, however, vary; suggestions for some platforms are given
+ below. Be aware, however, that you will have to reboot your
+ machine at best, or possibly recompile the kernel, to change these
+ settings.
+
+
+
+
+
System V IPC parameters>
+
+
+
+ |
+ Name>
+ Description>
+ Reasonable values>
+
+
+
+
+ |
+ SHMMAX>>
+ Maximum size of shared memory segment (bytes)>
+ 512 kB + 8192 * buffers + extra ... infinity
+
+
+ |
+ SHMMIN>>
+ Minimum size of shared memory segment (bytes)>
+ 1 (at most 144)>
+
+
+ |
+ SHMSEG>>
+ Maximum number of shared memory segments per process>
+ Must be at least 3, but the default is much higher.>
+
+
+ |
+ SHMMNI>>
+ Maximum number of shared memory segments system-wide>
+ like SHMSEG> + room for other applications>
+
+
+ |
+ SEMMNI>>
+ Maximum number of semaphore identifiers (i.e., sets)>
+ >= ceil(max_connections % 16)>
+
+
+ |
+ SEMMNS>>
+ Maximum number of semaphores system-wide>
+ number of allowed connections, rounded up to multiple of 16>
+
+
+ |
+ SEMMSL>>
+ Maximum number of semaphores per set>
+ >= 16>
+
+
+ |
+ SEMMAP>>
+ Number of entries in semaphore map>
+ see text>
+
+
+ |
+ SEMVMX>>
+ Maximum value of semaphore>
+ >= 255 (The default is often 32767, don't change unless asked to.)>
+
+
+
+
+
+
+
+ The most important shared memory parameter is SHMMAX>,
+ the maximum size, in bytes, that a shared memory segment can have.
+ If you get an error message from shmget> along the
+ lines of Invalid argument> then it is possible that
+ this limit has been exceeded. The size of the required shared
+ memory segments varies both with the number of requested buffers
+ (
+ (
+ (You can therefore, as a temporary solution, lower these settings
+ to get rid of the failures.) As a rough approximation you can
+ estimate the required segment size as the number of buffers times
+ the block size (8192 kB by default) plus ample overhead (at least
+ half a megabyte). Any error message you might get will contain the
+ size of the failed allocation. (
Postgres> will
+ actually use three shared memory segments, but the size of the
+ other two is negligible for this consideration.)
+
+
+ Less likely to cause problems is the minimum size for shared
+ memory segments (SHMMIN>), which must be at least 144
+ for
Postgres> (it's usually just 1), and the
+ maximum number of segments system-wide (SHMMNI>, as
+ mentioned, 3 are needed) or per-process (SHMSEG>,
+ ditto). Some systems also have a limit on the total amount of
+ shared memory in the system; see the platform-specific
+ instructions below.
+
+
+
Postgres> uses one semaphore per allowed connection
+ (
+ semaphores in the system is set by SEMMNS>, which
+ consequently must be at least as high as the connection setting.
+ The parameter SEMMNI> determines the limit on the
+ number of semaphore sets that can exist on the system at one time.
+ Hence this parameter must be at least
+ ceil(max_connections % 16)>. Lowering the number of
+ allowed connections is a temporary workaround for failures, which
+ are usually confusingly worded No space left on
+ device>>, from the function semget()>.
+
+
+ In some cases it might also turn out to be necessary to increase
+ SEMMAP> to be at least on the order of
+ SEMMNS>. This parameter defines the size of the
+ semaphore resource map, in which each contiguous block of available
+ semaphores needs an entry. When a semaphore set is freed it is
+ either added to an existing entry that is adjacent to the freed
+ block or it is registered under a new map entry. If the map is
+ full, the freed semaphores gets lost (until reboot). Fragmentation
+ of the semaphore space could therefore over time lead to less
+ available semaphores than there should be.
+
+
+ The SEMMSL> parameter, which determines how many
+ semaphores can be in a set, must be at least 16 for
+
+
+ Various settings related to semaphore undo>, such as
+ SEMMNU> and SEMUME>, are not of relevance
+
+
+
+
+
+
+ BSD/OS>
+
+
+
Shared Memory>
+ By default, only 4 MB of shared memory is supported. Keep in
+ mind that shared memory is not pageable; it is locked in RAM.
+ To increase the number of buffers supported by the
+ postmaster, increase SHMMAXPGS> by 1024 for every
+ additional 4 MB of shared memory:
+/sys/sys/shm.h:69:#define SHMMAXPGS 1024 /* max hardware pages... */
+
+ The default setting of 1024 is for a maximum of 4 MB of shared
+ memory.
+
+
+
+ For those running 4.1 or later, just recompile the kernel and
+ reboot. For those running earlier releases, use
+
bpatch> to find the sysptsize> value
+ for the current kernel. This is computed dynamically at
+ bootup.
+
+$ bpatch -r sysptsize>
+0x9 = 9>
+
+ Next, change SYSPTSIZE> to a hard-coded value. Use
+ the bpatch value, plus add 1 for every additional 4 MB of
+ shared memory you desire.
+/sys/i386/i386/i386_param.c:28:#define SYSPTSIZE 0 /* dynamically... */
+
+ sysptsize> can not be changed by sysctl on the fly.
+
+
+
+
Semaphores>
+ You may need to increase the number of semaphores. By
+ default,
Postgres> allocates 32 semaphores,
+ one for each backend connection. This is just over half the
+ default system total of 60.
+
+
+
+ The defaults are in /sys/sys/sem.h>:
+/* Configuration parameters */
+#ifndef SEMMNI
+#define SEMMNI 10 /* # of semaphore identifiers */
+#endif
+#ifndef SEMMNS
+#define SEMMNS 60 /* # of semaphores in system */
+#endif
+#ifndef SEMUME
+#define SEMUME 10 /* max # of undo entries per process */
+#endif
+#ifndef SEMMNU
+#define SEMMNU 30 /* # of undo structures in system */
+#endif
+
+ Set the values you want in your kernel config file, e.g.:
+options "SEMMNI=40"
+options "SEMMNS=240"
+options "SEMUME=40"
+options "SEMMNU=120"
+
+
+
+
+
+
+
+ FreeBSD>
+
+ 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 on how to set the various parameters:
+options SYSVSHM
+options SHMMAXPGS=4096
+options SHMSEG=256
+
+options SYSVSEM
+options SEMMNI=256
+options SEMMNS=512
+options SEMMNU=256
+options SEMMAP=256
+
+
+
+
+
+
+
+ HPUX>
+
+ The default settings tend to suffice for normal installations.
+ On
HPUX> 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
+ Kernel
+ Configuration>Configurable Parameters>>.
+ Hit Create A New Kernel> when you're done.
+
+
+
+
+
+
+ Linux>
+
+ System V IPC is enabled by default and sufficiently sized for
+ most uses. The relevant parameters are in
+ /usr/src/linux/include/asm-xxx>/shmparam.h>
+ and /usr/src/linux/include/linux/sem.h>. Be sure
+ to do make dep> before rebuilding the kernel.
+
+
+
+
+
+
+ SCO OpenServer>
+
+ In the default configuration, only 512 kB of shared memory per
+ segment is allowed, which is about enough for
+ 12>. To increase the setting, first change the directory to
+ /etc/conf/cf.d>. To display the current value of
+ SHMMAX>, in bytes, 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>
+
+ At least in version 2.6, the maximum size of a shared memory
+ segment is set too low for
Postgres>. 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 to make the changes effective.
+
+
+ See also
+ url="http://www.sunworld.com/swol-09-1997/swol-09-insidesolaris.html">http://www.sunworld.com/swol-09-1997/swol-09-insidesolaris.html>
+ for information on shared memory under
+
+
+
+
+
+
+ UnixWare>
+
+ On
UnixWare> 7, the maximum size for shared
+ memory segments is 512 kB in the default configuration. This
+ is enough for about
+ current value of SHMMAX>, run
+/etc/conf/bin/idtune -g SHMMAX
+
+ which displays the current, default, minimum, and maximum
+ values, in bytes. 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.
+
+
+
+
+
+
+
+ If your platform is not listed here, please consider
+ contributing some information.
+
+
+
+
+
+
+
+
+
+
Locale Support
and if locale is broken perl -v> will complain
something like:
-8:17[mira]:~/WWW/postgres>setenv LC_CTYPE not_exist
-8:18[mira]:~/WWW/postgres>perl -v
+
$> export LC_CTYPE='not_exist'>
+
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LC_ALL = (unset),
LANG = (unset)
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
+
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipc.c,v 1.48 2000/05/31 00:28:29 petere Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipc.c,v 1.49 2000/07/22 14:49:01 petere Exp $
*
* NOTES
*
static int UsePrivateMemory = 0;
static void IpcMemoryDetach(int status, char *shmaddr);
-static void IpcConfigTip(void);
/* ----------------------------------------------------------------
* exit() handling stuff
union semun semun;
semun.val = 0; /* unused */
- semctl(semId, 0, IPC_RMID, semun);
+ if (semctl(semId, 0, IPC_RMID, semun) == -1)
+ elog(NOTICE, "IPCPrivateSemaphoreKill: semctl(%d, 0, IPC_RMID, ...) failed: %s",
+ semId, strerror(errno));
}
{
if (shmctl(shmId, IPC_RMID, (struct shmid_ds *) NULL) < 0)
{
- elog(NOTICE, "IPCPrivateMemoryKill: shmctl(%d, %d, 0) failed: %m",
- shmId, IPC_RMID);
+ elog(NOTICE, "IPCPrivateMemoryKill: shmctl(id=%d, IPC_RMID, NULL) failed: %m",
+ shmId);
}
}
}
if (semId < 0)
{
- fprintf(stderr, "IpcSemaphoreCreate: semget(%d, %d, 0%o) failed: %s\n",
+ fprintf(stderr, "IpcSemaphoreCreate: semget(key=%d, num=%d, 0%o) failed: %s\n",
semKey, semNum, (unsigned)(permission|IPC_CREAT),
strerror(errno));
- IpcConfigTip();
+
+ if (errno == ENOSPC)
+ fprintf(stderr,
+ "\nThis error does *not* mean that you have run out of disk space.\n\n"
+ "It occurs either because system limit for the maximum number of\n"
+ "semaphore sets (SEMMNI), or the system wide maximum number of\n"
+ "semaphores (SEMMNS), would be exceeded. You need to raise the\n"
+ "respective kernel parameter. Look into the PostgreSQL documentation\n"
+ "for details.\n\n");
+
return (-1);
}
for (i = 0; i < semNum; i++)
errStatus = semctl(semId, 0, SETALL, semun);
if (errStatus == -1)
{
- fprintf(stderr, "IpcSemaphoreCreate: semctl(id=%d) failed: %s\n",
+ fprintf(stderr, "IpcSemaphoreCreate: semctl(id=%d, 0, SETALL, ...) failed: %s\n",
semId, strerror(errno));
+
+ if (errno == ERANGE)
+ fprintf(stderr,
+ "You possibly need to raise your kernel's SEMVMX value to be at least\n"
+ "%d. Look into the PostgreSQL documentation for details.\n",
+ semStartValue);
+
semctl(semId, 0, IPC_RMID, semun);
- IpcConfigTip();
return (-1);
}
if (shmid < 0)
{
- fprintf(stderr, "IpcMemoryCreate: shmget(%d, %d, 0%o) failed: %s\n",
- memKey, size, (unsigned)(IPC_CREAT|permission), strerror(errno));
- IpcConfigTip();
+ fprintf(stderr, "IpcMemoryCreate: shmget(key=%d, size=%d, 0%o) failed: %s\n",
+ (int)memKey, size, (unsigned)(IPC_CREAT|permission),
+ strerror(errno));
+
+ if (errno == EINVAL)
+ fprintf(stderr,
+ "\nThis error can be caused by one of three things:\n\n"
+ "1. The maximum size for shared memory segments on your system was\n"
+ " exceeded. You need to raise the SHMMAX parameter in your kernel\n"
+ " to be at least %d bytes.\n\n"
+ "2. The requested shared memory segment was too small for your system.\n"
+ " You need to lower the SHMMIN parameter in your kernel.\n\n"
+ "3. The requested shared memory segment already exists but is of the\n"
+ " wrong size. This is most likely the case if an old version of\n"
+ " PostgreSQL crashed and didn't clean up. The `ipcclean' utility\n"
+ " can be used to remedy this.\n\n"
+ "The PostgreSQL Administrator's Guide contains more information about\n"
+ "shared memory configuration.\n\n",
+ size);
+
+ else if (errno == ENOSPC)
+ fprintf(stderr,
+ "\nThis error does *not* mean that you have run out of disk space.\n\n"
+ "It occurs either if all available shared memory ids have been taken,\n"
+ "in which case you need to raise the SHMMNI parameter in your kernel,\n"
+ "or because the system's overall limit for shared memory has been\n"
+ "reached. The PostgreSQL Administrator's Guide contains more\n"
+ "information about shared memory configuration.\n\n");
+
return IpcMemCreationFailed;
}
if (shmid < 0)
{
- fprintf(stderr, "IpcMemoryIdGet: shmget(%d, %d, 0) failed: %s\n",
+ fprintf(stderr, "IpcMemoryIdGet: shmget(key=%d, size=%d, 0) failed: %s\n",
memKey, size, strerror(errno));
return IpcMemIdGetFailed;
}
IpcMemoryDetach(int status, char *shmaddr)
{
if (shmdt(shmaddr) < 0)
- elog(NOTICE, "IpcMemoryDetach: shmdt(0x%p): %m", shmaddr);
+ elog(NOTICE, "IpcMemoryDetach: shmdt(0x%p) failed: %m", shmaddr);
}
/****************************************************************************/
#endif
#endif /* HAS_TEST_AND_SET */
-
-static void
-IpcConfigTip(void)
-{
- fprintf(stderr, "This type of error is usually caused by an improper\n");
- fprintf(stderr, "shared memory or System V IPC semaphore configuration.\n");
- fprintf(stderr, "For more information, see the FAQ and platform-specific\n");
- fprintf(stderr, "FAQ's in the source directory pgsql/doc or on our\n");
- fprintf(stderr, "web site at http://www.postgresql.org.\n");
-}