Skip to content

Commit 5f82b3f

Browse files
committed
doc: Add advice about systemd RemoveIPC
Reviewed-by: Magnus Hagander <magnus@hagander.net>
1 parent facd94e commit 5f82b3f

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

doc/src/sgml/runtime.sgml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,85 @@ project.max-msg-ids=(priv,4096,deny)
11711171

11721172
</sect2>
11731173

1174+
<sect2 id="systemd-removeipc">
1175+
<title>systemd RemoveIPC</title>
1176+
1177+
<indexterm>
1178+
<primary>systemd</primary>
1179+
<secondary>RemoveIPC</secondary>
1180+
</indexterm>
1181+
1182+
<para>
1183+
If <productname>systemd</productname> is in use, some care must be taken
1184+
that IPC resources (shared memory and semaphores) are not prematurely
1185+
removed by the operating system. This is especially of concern when
1186+
installing PostgreSQL from source. Users of distribution packages of
1187+
PostgreSQL are less likely to be affected, as
1188+
the <literal>postgres</literal> user is then normally created as a system
1189+
user.
1190+
</para>
1191+
1192+
<para>
1193+
The setting <literal>RemoveIPC</literal>
1194+
in <filename>logind.conf</filename> controls whether IPC objects are
1195+
removed when a user fully logs out. System users are exempt. This
1196+
setting defaults to on in stock <productname>systemd</productname>, but
1197+
some operating system distributions default it to off.
1198+
</para>
1199+
1200+
<para>
1201+
A typical observed effect when this setting is on is that the semaphore
1202+
objects used by a PostgreSQL server are removed at apparently random
1203+
times, leading to the server crashing with log messages like
1204+
<screen>
1205+
LOG: semctl(1234567890, 0, IPC_RMID, ...) failed: Invalid argument
1206+
</screen>
1207+
Different types of IPC objects (shared memory vs. semaphores, System V
1208+
vs. POSIX) are treated slightly differently
1209+
by <productname>systemd</productname>, so one might observe that some IPC
1210+
resources are not removed in the same way as others. But it is not
1211+
advisable to rely on these subtle differences.
1212+
</para>
1213+
1214+
<para>
1215+
A <quote>user logging out</quote> might happen as part of a maintenance
1216+
job or manually when an administrator logs in as
1217+
the <literal>postgres</literal> user or something similar, so it is hard
1218+
to prevent in general.
1219+
</para>
1220+
1221+
<para>
1222+
What is a <quote>system user</quote> is determined
1223+
at <productname>systemd</productname> compile time from
1224+
the <symbol>SYS_UID_MAX</symbol> setting
1225+
in <filename>/etc/login.defs</filename>.
1226+
</para>
1227+
1228+
<para>
1229+
Packaging and deployment scripts should be careful to create
1230+
the <literal>postgres</literal> user as a system user by
1231+
using <literal>useradd -r</literal>, <literal>adduser --system</literal>,
1232+
or equivalent.
1233+
</para>
1234+
1235+
<para>
1236+
Alternatively, if the user account was created incorrectly or cannot be
1237+
changed, it is recommended to set
1238+
<programlisting>
1239+
RemoveIPC=no
1240+
</programlisting>
1241+
in <filename>/etc/systemd/logind.conf</filename> or another appropriate
1242+
configuration file.
1243+
</para>
1244+
1245+
<caution>
1246+
<para>
1247+
At least one of these two things has to be ensured, or the PostgreSQL
1248+
server will be very unreliable.
1249+
</para>
1250+
</caution>
1251+
</sect2>
1252+
11741253
<sect2>
11751254
<title>Resource Limits</title>
11761255

0 commit comments

Comments
 (0)