1- <!-- $PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.429 2009/12/10 06:32:28 petere Exp $ -->
1+ <!-- $PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.430 2010/01/11 18:39:32 tgl Exp $ -->
22
33<chapter Id="runtime">
44 <title>Server Setup and Operation</title>
@@ -1244,7 +1244,7 @@ default:\
12441244 this (consult your system documentation and configuration on where
12451245 to look for such a message):
12461246<programlisting>
1247- Out of Memory: Killed process 12345 (postgres).
1247+ Out of Memory: Killed process 12345 (postgres).
12481248</programlisting>
12491249 This indicates that the <filename>postgres</filename> process
12501250 has been terminated due to memory pressure.
@@ -1258,13 +1258,13 @@ Out of Memory: Killed process 12345 (postgres).
12581258 <productname>PostgreSQL</productname> on a machine where you can
12591259 be sure that other processes will not run the machine out of
12601260 memory. If memory is tight, increasing the swap space of the
1261- operating system can help avoiding the problem, because the
1262- out-of-memory (OOM) killer is invoked whenever physical memory and
1261+ operating system can help avoid the problem, because the
1262+ out-of-memory (OOM) killer is invoked only when physical memory and
12631263 swap space are exhausted.
12641264 </para>
12651265
12661266 <para>
1267- On Linux 2.6 and later, an additional measure is to modify the
1267+ On Linux 2.6 and later, it is possible to modify the
12681268 kernel's behavior so that it will not <quote>overcommit</> memory.
12691269 Although this setting will not prevent the <ulink
12701270 url="http://lwn.net/Articles/104179/">OOM killer</> from being invoked
@@ -1275,11 +1275,31 @@ Out of Memory: Killed process 12345 (postgres).
12751275sysctl -w vm.overcommit_memory=2
12761276</programlisting>
12771277 or placing an equivalent entry in <filename>/etc/sysctl.conf</>.
1278- You might also wish to modify the related setting
1279- <literal >vm.overcommit_ratio</>. For details see the kernel documentation
1278+ You might also wish to modify the related setting
1279+ <varname >vm.overcommit_ratio</>. For details see the kernel documentation
12801280 file <filename>Documentation/vm/overcommit-accounting</>.
12811281 </para>
12821282
1283+ <para>
1284+ Another approach, which can be used with or without altering
1285+ <varname>vm.overcommit_memory</>, is to set the process-specific
1286+ <varname>oom_adj</> value for the postmaster process to <literal>-17</>,
1287+ thereby guaranteeing it will not be targeted by the OOM killer. The
1288+ simplest way to do this is to execute
1289+ <programlisting>
1290+ echo -17 > /proc/self/oom_adj
1291+ </programlisting>
1292+ in the postmaster's startup script just before invoking the postmaster.
1293+ Note that this action must be done as root, or it will have no effect;
1294+ so a root-owned startup script is the easiest place to do it. If you
1295+ do this, you may also wish to build <productname>PostgreSQL</>
1296+ with <literal>-DLINUX_OOM_ADJ=0</> added to <varname>CFLAGS</>.
1297+ That will cause postmaster child processes to run with the normal
1298+ <varname>oom_adj</> value of zero, so that the OOM killer can still
1299+ target them at need.
1300+ </para>
1301+
1302+ <note>
12831303 <para>
12841304 Some vendors' Linux 2.4 kernels are reported to have early versions
12851305 of the 2.6 overcommit <command>sysctl</command> parameter. However, setting
@@ -1294,6 +1314,7 @@ sysctl -w vm.overcommit_memory=2
12941314 feature is there. If in any doubt, consult a kernel expert or your
12951315 kernel vendor.
12961316 </para>
1317+ </note>
12971318 </sect2>
12981319 </sect1>
12991320
0 commit comments