Skip to content

Commit 810a8b1

Browse files
committed
Give up on running with NetBSD/OpenBSD's default semaphore settings.
This reverts commit 38da053, which attempted to preserve our ability to start with only 60 semaphores. Subsequent changes (particularly 55b454d) have put that idea pretty much permanently out of reach: people wishing to use Postgres v18 on OpenBSD or NetBSD will have no choice but to increase those platforms' default values of SEMMNI and SEMMNS. Hence, revert 38da053's changes in SEMAS_PER_SET and the minimum tested value of max_connections. Adjust a comment from the subsequent patch 6d01541, and tweak the wording in runtime.sgml to make it clear that changing SEMMNI/SEMMNS is no longer even a little bit optional on these platforms. Although 38da053 was later back-patched into v17, leave that branch alone: it's still capable of starting with 60 semaphores, and there's no reason to break that. Author: Tom Lane <tgl@sss.pgh.pa.us> Reviewed-by: Nathan Bossart <nathandbossart@gmail.com> Discussion: https://postgr.es/m/E1tuZNv-0037Gs-34@gemulon.postgresql.org Discussion: https://postgr.es/m/1052019.1745947915@sss.pgh.pa.us
1 parent e974f1c commit 810a8b1

File tree

3 files changed

+17
-24
lines changed

3 files changed

+17
-24
lines changed

doc/src/sgml/runtime.sgml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -782,19 +782,19 @@ psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such
782782
<row>
783783
<entry><varname>SEMMNI</varname></entry>
784784
<entry>Maximum number of semaphore identifiers (i.e., sets)</entry>
785-
<entry>at least <literal>ceil(num_os_semaphores / 19)</literal> plus room for other applications</entry>
785+
<entry>at least <literal>ceil(num_os_semaphores / 16)</literal> plus room for other applications</entry>
786786
</row>
787787

788788
<row>
789789
<entry><varname>SEMMNS</varname></entry>
790790
<entry>Maximum number of semaphores system-wide</entry>
791-
<entry><literal>ceil(num_os_semaphores / 19) * 20</literal> plus room for other applications</entry>
791+
<entry><literal>ceil(num_os_semaphores / 16) * 17</literal> plus room for other applications</entry>
792792
</row>
793793

794794
<row>
795795
<entry><varname>SEMMSL</varname></entry>
796796
<entry>Maximum number of semaphores per set</entry>
797-
<entry>at least 20</entry>
797+
<entry>at least 17</entry>
798798
</row>
799799

800800
<row>
@@ -841,7 +841,7 @@ psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such
841841
(<xref linkend="guc-max-connections"/>), allowed autovacuum worker process
842842
(<xref linkend="guc-autovacuum-worker-slots"/>), allowed WAL sender process
843843
(<xref linkend="guc-max-wal-senders"/>), allowed background
844-
process (<xref linkend="guc-max-worker-processes"/>), etc., in sets of 19.
844+
process (<xref linkend="guc-max-worker-processes"/>), etc., in sets of 16.
845845
The runtime-computed parameter <xref linkend="guc-num-os-semaphores"/>
846846
reports the number of semaphores required. This parameter can be viewed
847847
before starting the server with a <command>postgres</command> command like:
@@ -851,17 +851,17 @@ $ <userinput>postgres -D $PGDATA -C num_os_semaphores</userinput>
851851
</para>
852852

853853
<para>
854-
Each set of 19 semaphores will
855-
also contain a 20th semaphore which contains a <quote>magic
854+
Each set of 16 semaphores will
855+
also contain a 17th semaphore which contains a <quote>magic
856856
number</quote>, to detect collision with semaphore sets used by
857857
other applications. The maximum number of semaphores in the system
858858
is set by <varname>SEMMNS</varname>, which consequently must be at least
859859
as high as <literal>num_os_semaphores</literal> plus one extra for
860-
each set of 19 required semaphores (see the formula in <xref
860+
each set of 16 required semaphores (see the formula in <xref
861861
linkend="sysvipc-parameters"/>). The parameter <varname>SEMMNI</varname>
862862
determines the limit on the number of semaphore sets that can
863863
exist on the system at one time. Hence this parameter must be at
864-
least <literal>ceil(num_os_semaphores / 19)</literal>.
864+
least <literal>ceil(num_os_semaphores / 16)</literal>.
865865
Lowering the number
866866
of allowed connections is a temporary workaround for failures,
867867
which are usually confusingly worded <quote>No space
@@ -953,10 +953,10 @@ $ <userinput>postgres -D $PGDATA -C num_os_semaphores</userinput>
953953
<para>
954954
The default shared memory settings are usually good enough, unless
955955
you have set <literal>shared_memory_type</literal> to <literal>sysv</literal>.
956-
You will usually want to increase <literal>kern.ipc.semmni</literal>
956+
However, you will need to increase <literal>kern.ipc.semmni</literal>
957957
and <literal>kern.ipc.semmns</literal>,
958958
as <systemitem class="osname">NetBSD</systemitem>'s default settings
959-
for these are uncomfortably small.
959+
for these are unworkably small.
960960
</para>
961961

962962
<para>
@@ -987,11 +987,11 @@ $ <userinput>postgres -D $PGDATA -C num_os_semaphores</userinput>
987987
<para>
988988
The default shared memory settings are usually good enough, unless
989989
you have set <literal>shared_memory_type</literal> to <literal>sysv</literal>.
990-
You will usually want to
990+
However, you will need to
991991
increase <literal>kern.seminfo.semmni</literal>
992992
and <literal>kern.seminfo.semmns</literal>,
993993
as <systemitem class="osname">OpenBSD</systemitem>'s default settings
994-
for these are uncomfortably small.
994+
for these are unworkably small.
995995
</para>
996996

997997
<para>

src/backend/port/sysv_sema.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,8 @@ typedef int IpcSemaphoreId; /* semaphore ID returned by semget(2) */
5050
* we allocate. It must be *less than* your kernel's SEMMSL (max semaphores
5151
* per set) parameter, which is often around 25. (Less than, because we
5252
* allocate one extra sema in each set for identification purposes.)
53-
*
54-
* The present value of 19 is chosen with one eye on NetBSD/OpenBSD's default
55-
* SEMMNS setting of 60. Remembering the extra sema per set, this lets us
56-
* allocate three sets with 57 useful semaphores before exceeding that, which
57-
* is enough to run our core regression tests. Users of those systems will
58-
* still want to raise SEMMNS for any sort of production work, though.
5953
*/
60-
#define SEMAS_PER_SET 19
54+
#define SEMAS_PER_SET 16
6155

6256
#define IPCProtection (0600) /* access/modify by user only */
6357

src/bin/initdb/initdb.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,15 +1128,14 @@ test_config_settings(void)
11281128
* for a given max_connections value. Note that it has been carefully
11291129
* crafted to provide specific values for the associated values in
11301130
* trial_conns. We want it to return autovacuum_worker_slots's initial
1131-
* default value (16) for the maximum value in trial_conns (100), and we
1132-
* want it to return close to the minimum value we'd consider (3, which is
1133-
* the default of autovacuum_max_workers) for the minimum value in
1134-
* trial_conns (25).
1131+
* default value (16) for the maximum value in trial_conns[] (100), while
1132+
* it mustn't return less than the default value of autovacuum_max_workers
1133+
* (3) for the minimum value in trial_conns[].
11351134
*/
11361135
#define AV_SLOTS_FOR_CONNS(nconns) ((nconns) / 6)
11371136

11381137
static const int trial_conns[] = {
1139-
100, 50, 40, 30, 25
1138+
100, 50, 40, 30, 20
11401139
};
11411140
static const int trial_bufs[] = {
11421141
16384, 8192, 4096, 3584, 3072, 2560, 2048, 1536,

0 commit comments

Comments
 (0)