<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >Managing Kernel Resources</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REV="MADE" HREF="mailto:pgsql-docs@postgresql.org"><LINK REL="HOME" TITLE="PostgreSQL 8.0.11 Documentation" HREF="index.html"><LINK REL="UP" TITLE="Server Run-time Environment" HREF="runtime.html"><LINK REL="PREVIOUS" TITLE="Run-time Configuration" HREF="runtime-config.html"><LINK REL="NEXT" TITLE="Shutting Down the Server" HREF="postmaster-shutdown.html"><LINK REL="STYLESHEET" TYPE="text/css" HREF="stylesheet.css"><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1"><META NAME="creation" CONTENT="2007-02-02T03:57:22"></HEAD ><BODY CLASS="SECT1" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="5" ALIGN="center" VALIGN="bottom" >PostgreSQL 8.0.11 Documentation</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="top" ><A HREF="runtime-config.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="10%" ALIGN="left" VALIGN="top" ><A HREF="runtime.html" >Fast Backward</A ></TD ><TD WIDTH="60%" ALIGN="center" VALIGN="bottom" >Chapter 16. Server Run-time Environment</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="top" ><A HREF="runtime.html" >Fast Forward</A ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="top" ><A HREF="postmaster-shutdown.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="SECT1" ><H1 CLASS="SECT1" ><A NAME="KERNEL-RESOURCES" >16.5. Managing Kernel Resources</A ></H1 ><P > A large <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN > installation can quickly exhaust various operating system resource limits. (On some systems, the factory defaults are so low that you don't even need a really <SPAN CLASS="QUOTE" >"large"</SPAN > installation.) If you have encountered this kind of problem, keep reading. </P ><DIV CLASS="SECT2" ><H2 CLASS="SECT2" ><A NAME="SYSVIPC" >16.5.1. Shared Memory and Semaphores</A ></H2 ><A NAME="AEN18940" ></A ><A NAME="AEN18942" ></A ><P > Shared memory and semaphores are collectively referred to as <SPAN CLASS="QUOTE" >"<SPAN CLASS="SYSTEMITEM" >System V</SPAN > <ACRONYM CLASS="ACRONYM" >IPC</ACRONYM >"</SPAN > (together with message queues, which are not relevant for <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN >). Almost all modern operating systems provide these features, but not all of them have them turned on or sufficiently sized by default, especially systems with BSD heritage. (For the <SPAN CLASS="SYSTEMITEM" >QNX</SPAN > and <SPAN CLASS="SYSTEMITEM" >BeOS</SPAN > ports, <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN > provides its own replacement implementation of these facilities.) </P ><P > The complete lack of these facilities is usually manifested by an <SPAN CLASS="ERRORNAME" >Illegal system call</SPAN > error upon server start. In that case there's nothing left to do but to reconfigure your kernel. <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN > won't work without them. </P ><P > When <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN > exceeds one of the various hard <ACRONYM CLASS="ACRONYM" >IPC</ACRONYM > limits, the server will refuse to start and should leave an instructive error message describing the problem encountered and what to do about it. (See also <A HREF="postmaster-start.html#POSTMASTER-START-FAILURES" >Section 16.3.1</A >.) The relevant kernel parameters are named consistently across different systems; <A HREF="kernel-resources.html#SYSVIPC-PARAMETERS" >Table 16-2</A > gives an overview. The methods to set them, however, vary. Suggestions for some platforms are given below. Be warned that it is often necessary to reboot your machine, and possibly even recompile the kernel, to change these settings. </P ><DIV CLASS="TABLE" ><A NAME="SYSVIPC-PARAMETERS" ></A ><P ><B >Table 16-2. <SPAN CLASS="SYSTEMITEM" >System V</SPAN > <ACRONYM CLASS="ACRONYM" >IPC</ACRONYM > parameters</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><COL><THEAD ><TR ><TH >Name</TH ><TH >Description</TH ><TH >Reasonable values</TH ></TR ></THEAD ><TBODY ><TR ><TD ><TT CLASS="VARNAME" >SHMMAX</TT ></TD ><TD >Maximum size of shared memory segment (bytes)</TD ><TD >250 kB + 8.2 kB * <A HREF="runtime-config.html#GUC-SHARED-BUFFERS" >shared_buffers</A > + 14.2 kB * <A HREF="runtime-config.html#GUC-MAX-CONNECTIONS" >max_connections</A > up to infinity</TD ></TR ><TR ><TD ><TT CLASS="VARNAME" >SHMMIN</TT ></TD ><TD >Minimum size of shared memory segment (bytes)</TD ><TD >1</TD ></TR ><TR ><TD ><TT CLASS="VARNAME" >SHMALL</TT ></TD ><TD >Total amount of shared memory available (bytes or pages)</TD ><TD >if bytes, same as <TT CLASS="VARNAME" >SHMMAX</TT >; if pages, <TT CLASS="LITERAL" >ceil(SHMMAX/PAGE_SIZE)</TT ></TD ></TR ><TR ><TD ><TT CLASS="VARNAME" >SHMSEG</TT ></TD ><TD >Maximum number of shared memory segments per process</TD ><TD >only 1 segment is needed, but the default is much higher</TD ></TR ><TR ><TD ><TT CLASS="VARNAME" >SHMMNI</TT ></TD ><TD >Maximum number of shared memory segments system-wide</TD ><TD >like <TT CLASS="VARNAME" >SHMSEG</TT > plus room for other applications</TD ></TR ><TR ><TD ><TT CLASS="VARNAME" >SEMMNI</TT ></TD ><TD >Maximum number of semaphore identifiers (i.e., sets)</TD ><TD >at least <TT CLASS="LITERAL" >ceil(max_connections / 16)</TT ></TD ></TR ><TR ><TD ><TT CLASS="VARNAME" >SEMMNS</TT ></TD ><TD >Maximum number of semaphores system-wide</TD ><TD ><TT CLASS="LITERAL" >ceil(max_connections / 16) * 17</TT > plus room for other applications</TD ></TR ><TR ><TD ><TT CLASS="VARNAME" >SEMMSL</TT ></TD ><TD >Maximum number of semaphores per set</TD ><TD >at least 17</TD ></TR ><TR ><TD ><TT CLASS="VARNAME" >SEMMAP</TT ></TD ><TD >Number of entries in semaphore map</TD ><TD >see text</TD ></TR ><TR ><TD ><TT CLASS="VARNAME" >SEMVMX</TT ></TD ><TD >Maximum value of semaphore</TD ><TD >at least 1000 (The default is often 32767, don't change unless forced to)</TD ></TR ></TBODY ></TABLE ></DIV ><P > <A NAME="AEN19029" ></A > The most important shared memory parameter is <TT CLASS="VARNAME" >SHMMAX</TT >, the maximum size, in bytes, of a shared memory segment. If you get an error message from <CODE CLASS="FUNCTION" >shmget</CODE > like <SPAN CLASS="ERRORNAME" >Invalid argument</SPAN >, it is likely that this limit has been exceeded. The size of the required shared memory segment varies both with the number of requested buffers (<TT CLASS="OPTION" >-B</TT > option) and the number of allowed connections (<TT CLASS="OPTION" >-N</TT > option), although the former is the most significant. (You can, as a temporary solution, lower these settings to eliminate the failure.) As a rough approximation, you can estimate the required segment size as suggested in <A HREF="kernel-resources.html#SYSVIPC-PARAMETERS" >Table 16-2</A >. Any error message you might get will contain the size of the failed allocation request. </P ><P > Some systems also have a limit on the total amount of shared memory in the system (<TT CLASS="VARNAME" >SHMALL</TT >). Make sure this is large enough for <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN > plus any other applications that are using shared memory segments. (Caution: <TT CLASS="VARNAME" >SHMALL</TT > is measured in pages rather than bytes on many systems.) </P ><P > Less likely to cause problems is the minimum size for shared memory segments (<TT CLASS="VARNAME" >SHMMIN</TT >), which should be at most approximately 256 kB for <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN > (it is usually just 1). The maximum number of segments system-wide (<TT CLASS="VARNAME" >SHMMNI</TT >) or per-process (<TT CLASS="VARNAME" >SHMSEG</TT >) are unlikely to cause a problem unless your system has them set to zero. </P ><P > <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN > uses one semaphore per allowed connection (<TT CLASS="OPTION" >-N</TT > option), in sets of 16. Each such set will also contain a 17th semaphore which contains a <SPAN CLASS="QUOTE" >"magic number"</SPAN >, to detect collision with semaphore sets used by other applications. The maximum number of semaphores in the system is set by <TT CLASS="VARNAME" >SEMMNS</TT >, which consequently must be at least as high as <TT CLASS="VARNAME" >max_connections</TT > plus one extra for each 16 allowed connections (see the formula in <A HREF="kernel-resources.html#SYSVIPC-PARAMETERS" >Table 16-2</A >). The parameter <TT CLASS="VARNAME" >SEMMNI</TT > 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 <TT CLASS="LITERAL" >ceil(max_connections / 16)</TT >. Lowering the number of allowed connections is a temporary workaround for failures, which are usually confusingly worded <SPAN CLASS="ERRORNAME" >No space left on device</SPAN >, from the function <CODE CLASS="FUNCTION" >semget</CODE >. </P ><P > In some cases it might also be necessary to increase <TT CLASS="VARNAME" >SEMMAP</TT > to be at least on the order of <TT CLASS="VARNAME" >SEMMNS</TT >. 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 get lost (until reboot). Fragmentation of the semaphore space could over time lead to fewer available semaphores than there should be. </P ><P > The <TT CLASS="VARNAME" >SEMMSL</TT > parameter, which determines how many semaphores can be in a set, must be at least 17 for <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN >. </P ><P > Various other settings related to <SPAN CLASS="QUOTE" >"semaphore undo"</SPAN >, such as <TT CLASS="VARNAME" >SEMMNU</TT > and <TT CLASS="VARNAME" >SEMUME</TT >, are not of concern for <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN >. </P ><P ></P ><DIV CLASS="VARIABLELIST" ><DL ><DT ><SPAN CLASS="SYSTEMITEM" >BSD/OS</SPAN ></DT ><DD ><DIV CLASS="FORMALPARA" ><P ><B >Shared Memory. </B > 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 amount of shared memory supported by your system, add something like the following to your kernel configuration file: </P><PRE CLASS="PROGRAMLISTING" >options "SHMALL=8192" options "SHMMAX=\(SHMALL*PAGE_SIZE\)"</PRE ><P> <TT CLASS="VARNAME" >SHMALL</TT > is measured in 4KB pages, so a value of 1024 represents 4 MB of shared memory. Therefore the above increases the maximum shared memory area to 32 MB. For those running 4.3 or later, you will probably also need to increase <TT CLASS="VARNAME" >KERNEL_VIRTUAL_MB</TT > above the default <TT CLASS="LITERAL" >248</TT >. Once all changes have been made, recompile the kernel, and reboot. </P ></DIV ><P > For those running 4.0 and earlier releases, use <TT CLASS="COMMAND" >bpatch</TT > to find the <TT CLASS="VARNAME" >sysptsize</TT > value in the current kernel. This is computed dynamically at boot time. </P><PRE CLASS="SCREEN" >$ <KBD CLASS="USERINPUT" >bpatch -r sysptsize</KBD > <SAMP CLASS="COMPUTEROUTPUT" >0x9 = 9</SAMP ></PRE ><P> Next, add <TT CLASS="VARNAME" >SYSPTSIZE</TT > as a hard-coded value in the kernel configuration file. Increase the value you found using <TT CLASS="COMMAND" >bpatch</TT >. Add 1 for every additional 4 MB of shared memory you desire. </P><PRE CLASS="PROGRAMLISTING" >options "SYSPTSIZE=16"</PRE ><P> <TT CLASS="VARNAME" >sysptsize</TT > cannot be changed by <TT CLASS="COMMAND" >sysctl</TT >. </P ><DIV CLASS="FORMALPARA" ><P ><B >Semaphores. </B > You will probably want to increase the number of semaphores as well; the default system total of 60 will only allow about 50 <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN > connections. Set the values you want in your kernel configuration file, e.g.: </P><PRE CLASS="PROGRAMLISTING" >options "SEMMNI=40" options "SEMMNS=240"</PRE ><P> </P ></DIV ></DD ><DT ><SPAN CLASS="SYSTEMITEM" >FreeBSD</SPAN ><BR><SPAN CLASS="SYSTEMITEM" >NetBSD</SPAN ><BR><SPAN CLASS="SYSTEMITEM" >OpenBSD</SPAN ></DT ><DD ><P > The options <TT CLASS="VARNAME" >SYSVSHM</TT > and <TT CLASS="VARNAME" >SYSVSEM</TT > need to be enabled when the kernel is compiled. (They are by default.) The maximum size of shared memory is determined by the option <TT CLASS="VARNAME" >SHMMAXPGS</TT > (in pages). The following shows an example of how to set the various parameters: </P><PRE CLASS="PROGRAMLISTING" >options SYSVSHM options SHMMAXPGS=4096 options SHMSEG=256 options SYSVSEM options SEMMNI=256 options SEMMNS=512 options SEMMNU=256 options SEMMAP=256</PRE ><P> (On <SPAN CLASS="SYSTEMITEM" >OpenBSD</SPAN > the key word is actually <TT CLASS="LITERAL" >option</TT > singular.) </P ><P > You might also want to configure your kernel to lock shared memory into RAM and prevent it from being paged out to swap. Use the <TT CLASS="COMMAND" >sysctl</TT > setting <TT CLASS="LITERAL" >kern.ipc.shm_use_phys</TT >. </P ></DD ><DT ><SPAN CLASS="SYSTEMITEM" >HP-UX</SPAN ></DT ><DD ><P > The default settings tend to suffice for normal installations. On <SPAN CLASS="PRODUCTNAME" >HP-UX</SPAN > 10, the factory default for <TT CLASS="VARNAME" >SEMMNS</TT > is 128, which might be too low for larger database sites. </P ><P > <ACRONYM CLASS="ACRONYM" >IPC</ACRONYM > parameters can be set in the <SPAN CLASS="APPLICATION" >System Administration Manager</SPAN > (<ACRONYM CLASS="ACRONYM" >SAM</ACRONYM >) under <SPAN CLASS="GUIMENU" >Kernel Configuration</SPAN >-><SPAN CLASS="GUIMENUITEM" >Configurable Parameters</SPAN >. Hit <SPAN CLASS="GUIBUTTON" >Create A New Kernel</SPAN > when you're done. </P ></DD ><DT ><SPAN CLASS="SYSTEMITEM" >Linux</SPAN ></DT ><DD ><P > The default shared memory limit (both <TT CLASS="VARNAME" >SHMMAX</TT > and <TT CLASS="VARNAME" >SHMALL</TT >) is 32 MB in 2.2 kernels, but it can be changed in the <TT CLASS="FILENAME" >proc</TT > file system (without reboot). For example, to allow 128 MB: </P><PRE CLASS="SCREEN" ><SAMP CLASS="PROMPT" >$</SAMP > <KBD CLASS="USERINPUT" >echo 134217728 >/proc/sys/kernel/shmall</KBD > <SAMP CLASS="PROMPT" >$</SAMP > <KBD CLASS="USERINPUT" >echo 134217728 >/proc/sys/kernel/shmmax</KBD ></PRE ><P> You could put these commands into a script run at boot-time. </P ><P > Alternatively, you can use <TT CLASS="COMMAND" >sysctl</TT >, if available, to control these parameters. Look for a file called <TT CLASS="FILENAME" >/etc/sysctl.conf</TT > and add lines like the following to it: </P><PRE CLASS="PROGRAMLISTING" >kernel.shmall = 134217728 kernel.shmmax = 134217728</PRE ><P> This file is usually processed at boot time, but <TT CLASS="COMMAND" >sysctl</TT > can also be called explicitly later. </P ><P > Other parameters are sufficiently sized for any application. If you want to see for yourself look in <TT CLASS="FILENAME" >/usr/src/linux/include/asm-<TT CLASS="REPLACEABLE" ><I >xxx</I ></TT >/shmparam.h</TT > and <TT CLASS="FILENAME" >/usr/src/linux/include/linux/sem.h</TT >. </P ></DD ><DT ><SPAN CLASS="SYSTEMITEM" >MacOS X</SPAN ></DT ><DD ><P > In OS X 10.2 and earlier, edit the file <TT CLASS="FILENAME" >/System/Library/StartupItems/SystemTuning/SystemTuning</TT > and change the values in the following commands: </P><PRE CLASS="PROGRAMLISTING" >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</PRE ><P> In OS X 10.3, these commands have been moved to <TT CLASS="FILENAME" >/etc/rc</TT > and must be edited there. You'll need to reboot to make changes take effect. Note that <TT CLASS="FILENAME" >/etc/rc</TT > is usually overwritten by OS X updates (such as 10.3.6 to 10.3.7) so you should expect to have to redo your editing after each update. </P ><P > <TT CLASS="VARNAME" >SHMALL</TT > is measured in 4KB pages on this platform. </P ></DD ><DT ><SPAN CLASS="SYSTEMITEM" >SCO OpenServer</SPAN ></DT ><DD ><P > In the default configuration, only 512 kB of shared memory per segment is allowed, which is about enough for <TT CLASS="OPTION" >-B 24 -N 12</TT >. To increase the setting, first change to the directory <TT CLASS="FILENAME" >/etc/conf/cf.d</TT >. To display the current value of <TT CLASS="VARNAME" >SHMMAX</TT >, run </P><PRE CLASS="PROGRAMLISTING" >./configure -y SHMMAX</PRE ><P> To set a new value for <TT CLASS="VARNAME" >SHMMAX</TT >, run </P><PRE CLASS="PROGRAMLISTING" >./configure SHMMAX=<TT CLASS="REPLACEABLE" ><I >value</I ></TT ></PRE ><P> where <TT CLASS="REPLACEABLE" ><I >value</I ></TT > is the new value you want to use (in bytes). After setting <TT CLASS="VARNAME" >SHMMAX</TT >, rebuild the kernel: </P><PRE CLASS="PROGRAMLISTING" >./link_unix</PRE ><P> and reboot. </P ></DD ><DT ><SPAN CLASS="SYSTEMITEM" >AIX</SPAN ></DT ><DD ><P > At least as of version 5.1, it should not be necessary to do any special configuration for such parameters as <TT CLASS="VARNAME" >SHMMAX</TT >, 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 <SPAN CLASS="APPLICATION" >DB/2</SPAN >.</P ><P > It may, however, be necessary to modify the global <TT CLASS="COMMAND" >ulimit</TT > information in <TT CLASS="FILENAME" >/etc/security/limits</TT >, as the default hard limits for file sizes (<TT CLASS="VARNAME" >fsize</TT >) and numbers of files (<TT CLASS="VARNAME" >nofiles</TT >) may be too low. </P ></DD ><DT ><SPAN CLASS="SYSTEMITEM" >Solaris</SPAN ></DT ><DD ><P > At least in version 2.6, the default maximum size of a shared memory segments is too low for <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN >. The relevant settings can be changed in <TT CLASS="FILENAME" >/etc/system</TT >, for example: </P><PRE CLASS="PROGRAMLISTING" >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</PRE ><P> You need to reboot for the changes to take effect. </P ><P > See also <A HREF="http://sunsite.uakom.sk/sunworldonline/swol-09-1997/swol-09-insidesolaris.html" TARGET="_top" >http://sunsite.uakom.sk/sunworldonline/swol-09-1997/swol-09-insidesolaris.html</A > for information on shared memory under <SPAN CLASS="PRODUCTNAME" >Solaris</SPAN >. </P ></DD ><DT ><SPAN CLASS="SYSTEMITEM" >UnixWare</SPAN ></DT ><DD ><P > On <SPAN CLASS="PRODUCTNAME" >UnixWare</SPAN > 7, the maximum size for shared memory segments is 512 kB in the default configuration. This is enough for about <TT CLASS="OPTION" >-B 24 -N 12</TT >. To display the current value of <TT CLASS="VARNAME" >SHMMAX</TT >, run </P><PRE CLASS="PROGRAMLISTING" >/etc/conf/bin/idtune -g SHMMAX</PRE ><P> which displays the current, default, minimum, and maximum values. To set a new value for <TT CLASS="VARNAME" >SHMMAX</TT >, run </P><PRE CLASS="PROGRAMLISTING" >/etc/conf/bin/idtune SHMMAX <TT CLASS="REPLACEABLE" ><I >value</I ></TT ></PRE ><P> where <TT CLASS="REPLACEABLE" ><I >value</I ></TT > is the new value you want to use (in bytes). After setting <TT CLASS="VARNAME" >SHMMAX</TT >, rebuild the kernel: </P><PRE CLASS="PROGRAMLISTING" >/etc/conf/bin/idbuild -B</PRE ><P> and reboot. </P ></DD ></DL ></DIV ></DIV ><DIV CLASS="SECT2" ><H2 CLASS="SECT2" ><A NAME="AEN19248" >16.5.2. Resource Limits</A ></H2 ><P > Unix-like operating systems enforce various kinds of resource limits that might interfere with the operation of your <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN > server. Of particular importance are limits on the number of processes per user, the number of open files per process, and the amount of memory available to each process. Each of these have a <SPAN CLASS="QUOTE" >"hard"</SPAN > and a <SPAN CLASS="QUOTE" >"soft"</SPAN > limit. The soft limit is what actually counts but it can be changed by the user up to the hard limit. The hard limit can only be changed by the root user. The system call <CODE CLASS="FUNCTION" >setrlimit</CODE > is responsible for setting these parameters. The shell's built-in command <TT CLASS="COMMAND" >ulimit</TT > (Bourne shells) or <TT CLASS="COMMAND" >limit</TT > (<SPAN CLASS="APPLICATION" >csh</SPAN >) is used to control the resource limits from the command line. On BSD-derived systems the file <TT CLASS="FILENAME" >/etc/login.conf</TT > controls the various resource limits set during login. See the operating system documentation for details. The relevant parameters are <TT CLASS="VARNAME" >maxproc</TT >, <TT CLASS="VARNAME" >openfiles</TT >, and <TT CLASS="VARNAME" >datasize</TT >. For example: </P><PRE CLASS="PROGRAMLISTING" >default:\ ... :datasize-cur=256M:\ :maxproc-cur=256:\ :openfiles-cur=256:\ ...</PRE ><P> (<TT CLASS="LITERAL" >-cur</TT > is the soft limit. Append <TT CLASS="LITERAL" >-max</TT > to set the hard limit.) </P ><P > Kernels can also have system-wide limits on some resources. <P ></P ></P><UL ><LI ><P > On <SPAN CLASS="PRODUCTNAME" >Linux</SPAN > <TT CLASS="FILENAME" >/proc/sys/fs/file-max</TT > determines the maximum number of open files that the kernel will support. It can be changed by writing a different number into the file or by adding an assignment in <TT CLASS="FILENAME" >/etc/sysctl.conf</TT >. The maximum limit of files per process is fixed at the time the kernel is compiled; see <TT CLASS="FILENAME" >/usr/src/linux/Documentation/proc.txt</TT > for more information. </P ></LI ></UL ><P> </P ><P > The <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN > server uses one process per connection so you should provide for at least as many processes as allowed connections, in addition to what you need for the rest of your system. This is usually not a problem but if you run several servers on one machine things might get tight. </P ><P > The factory default limit on open files is often set to <SPAN CLASS="QUOTE" >"socially friendly"</SPAN > values that allow many users to coexist on a machine without using an inappropriate fraction of the system resources. If you run many servers on a machine this is perhaps what you want, but on dedicated servers you may want to raise this limit. </P ><P > On the other side of the coin, some systems allow individual processes to open large numbers of files; if more than a few processes do so then the system-wide limit can easily be exceeded. If you find this happening, and you do not want to alter the system-wide limit, you can set <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN >'s <A HREF="runtime-config.html#GUC-MAX-FILES-PER-PROCESS" >max_files_per_process</A > configuration parameter to limit the consumption of open files. </P ></DIV ><DIV CLASS="SECT2" ><H2 CLASS="SECT2" ><A NAME="AEN19280" >16.5.3. Linux Memory Overcommit</A ></H2 ><P > In Linux 2.4 and later, the default virtual memory behavior is not optimal for <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN >. Because of the way that the kernel implements memory overcommit, the kernel may terminate the <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN > server (the <TT CLASS="FILENAME" >postmaster</TT > process) if the memory demands of another process cause the system to run out of virtual memory. </P ><P > If this happens, you will see a kernel message that looks like this (consult your system documentation and configuration on where to look for such a message): </P><PRE CLASS="PROGRAMLISTING" >Out of Memory: Killed process 12345 (postmaster). </PRE ><P> This indicates that the <TT CLASS="FILENAME" >postmaster</TT > process has been terminated due to memory pressure. Although existing database connections will continue to function normally, no new connections will be accepted. To recover, <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN > will need to be restarted. </P ><P > One way to avoid this problem is to run <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN > on a machine where you can be sure that other processes will not run the machine out of memory. </P ><P > On Linux 2.6 and later, a better solution is to modify the kernel's behavior so that it will not <SPAN CLASS="QUOTE" >"overcommit"</SPAN > memory. This is done by selecting strict overcommit mode via <TT CLASS="COMMAND" >sysctl</TT >: </P><PRE CLASS="PROGRAMLISTING" >sysctl -w vm.overcommit_memory=2</PRE ><P> or placing an equivalent entry in <TT CLASS="FILENAME" >/etc/sysctl.conf</TT >. You may also wish to modify the related setting <TT CLASS="LITERAL" >vm.overcommit_ratio</TT >. For details see the kernel documentation file <TT CLASS="FILENAME" >Documentation/vm/overcommit-accounting</TT >. </P ><P > Some vendors' Linux 2.4 kernels are reported to have early versions of the 2.6 overcommit <TT CLASS="COMMAND" >sysctl</TT > parameter. However, setting <TT CLASS="LITERAL" >vm.overcommit_memory</TT > to 2 on a kernel that does not have the relevant code will make things worse not better. It is recommended that you inspect the actual kernel source code (see the function <CODE CLASS="FUNCTION" >vm_enough_memory</CODE > in the file <TT CLASS="FILENAME" >mm/mmap.c</TT >) to verify what is supported in your copy before you try this in a 2.4 installation. The presence of the <TT CLASS="FILENAME" >overcommit-accounting</TT > documentation file should <SPAN CLASS="emphasis" ><I CLASS="EMPHASIS" >not</I ></SPAN > be taken as evidence that the feature is there. If in any doubt, consult a kernel expert or your kernel vendor. </P ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="runtime-config.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="postmaster-shutdown.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Run-time Configuration</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="runtime.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Shutting Down the Server</TD ></TR ></TABLE ></DIV ></BODY ></HTML >