Give up on running with NetBSD/OpenBSD's default semaphore settings.
authorTom Lane <[email protected]>
Tue, 29 Apr 2025 21:27:52 +0000 (17:27 -0400)
committerTom Lane <[email protected]>
Tue, 29 Apr 2025 21:27:52 +0000 (17:27 -0400)
This reverts commit 38da053463bef32adf563ddee5277d16d2b6c5af, which
attempted to preserve our ability to start with only 60 semaphores.

Subsequent changes (particularly 55b454d0e) 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 38da05346's changes in SEMAS_PER_SET and the minimum
tested value of max_connections.  Adjust a comment from the subsequent
patch 6d0154196, 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 38da05346 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 <[email protected]>
Reviewed-by: Nathan Bossart <[email protected]>
Discussion: https://postgr.es/m/[email protected]
Discussion: https://postgr.es/m/1052019.1745947915@sss.pgh.pa.us

doc/src/sgml/runtime.sgml
src/backend/port/sysv_sema.c
src/bin/initdb/initdb.c

index 3a6d308ae355bd3d320251295be5776eddf015db..0c60bafac635d027078b63f7e36260453e66ebd4 100644 (file)
@@ -782,19 +782,19 @@ psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such
        <row>
         <entry><varname>SEMMNI</varname></entry>
         <entry>Maximum number of semaphore identifiers (i.e., sets)</entry>
-        <entry>at least <literal>ceil(num_os_semaphores / 19)</literal> plus room for other applications</entry>
+        <entry>at least <literal>ceil(num_os_semaphores / 16)</literal> plus room for other applications</entry>
        </row>
 
        <row>
         <entry><varname>SEMMNS</varname></entry>
         <entry>Maximum number of semaphores system-wide</entry>
-        <entry><literal>ceil(num_os_semaphores / 19) * 20</literal> plus room for other applications</entry>
+        <entry><literal>ceil(num_os_semaphores / 16) * 17</literal> plus room for other applications</entry>
        </row>
 
        <row>
         <entry><varname>SEMMSL</varname></entry>
         <entry>Maximum number of semaphores per set</entry>
-        <entry>at least 20</entry>
+        <entry>at least 17</entry>
        </row>
 
        <row>
@@ -841,7 +841,7 @@ psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such
     (<xref linkend="guc-max-connections"/>), allowed autovacuum worker process
     (<xref linkend="guc-autovacuum-worker-slots"/>), allowed WAL sender process
     (<xref linkend="guc-max-wal-senders"/>), allowed background
-    process (<xref linkend="guc-max-worker-processes"/>), etc., in sets of 19.
+    process (<xref linkend="guc-max-worker-processes"/>), etc., in sets of 16.
     The runtime-computed parameter <xref linkend="guc-num-os-semaphores"/>
     reports the number of semaphores required.  This parameter can be viewed
     before starting the server with a <command>postgres</command> command like:
@@ -851,17 +851,17 @@ $ <userinput>postgres -D $PGDATA -C num_os_semaphores</userinput>
    </para>
 
    <para>
-    Each set of 19 semaphores will
-    also contain a 20th semaphore which contains a <quote>magic
+    Each set of 16 semaphores will
+    also contain a 17th semaphore which contains a <quote>magic
     number</quote>, to detect collision with semaphore sets used by
     other applications. The maximum number of semaphores in the system
     is set by <varname>SEMMNS</varname>, which consequently must be at least
     as high as <literal>num_os_semaphores</literal> plus one extra for
-    each set of 19 required semaphores (see the formula in <xref
+    each set of 16 required semaphores (see the formula in <xref
     linkend="sysvipc-parameters"/>).  The parameter <varname>SEMMNI</varname>
     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 <literal>ceil(num_os_semaphores / 19)</literal>.
+    least <literal>ceil(num_os_semaphores / 16)</literal>.
     Lowering the number
     of allowed connections is a temporary workaround for failures,
     which are usually confusingly worded <quote>No space
@@ -953,10 +953,10 @@ $ <userinput>postgres -D $PGDATA -C num_os_semaphores</userinput>
        <para>
         The default shared memory settings are usually good enough, unless
         you have set <literal>shared_memory_type</literal> to <literal>sysv</literal>.
-        You will usually want to increase <literal>kern.ipc.semmni</literal>
+        However, you will need to increase <literal>kern.ipc.semmni</literal>
         and <literal>kern.ipc.semmns</literal>,
         as <systemitem class="osname">NetBSD</systemitem>'s default settings
-        for these are uncomfortably small.
+        for these are unworkably small.
        </para>
 
        <para>
@@ -987,11 +987,11 @@ $ <userinput>postgres -D $PGDATA -C num_os_semaphores</userinput>
        <para>
         The default shared memory settings are usually good enough, unless
         you have set <literal>shared_memory_type</literal> to <literal>sysv</literal>.
-        You will usually want to
+        However, you will need to
         increase <literal>kern.seminfo.semmni</literal>
         and <literal>kern.seminfo.semmns</literal>,
         as <systemitem class="osname">OpenBSD</systemitem>'s default settings
-        for these are uncomfortably small.
+        for these are unworkably small.
        </para>
 
        <para>
index f7c8638aec5b87af80463f623a73480d6544fb03..423b2b4f9d6d1416f12a7e83e02733eace2084b7 100644 (file)
@@ -50,14 +50,8 @@ typedef int IpcSemaphoreId;      /* semaphore ID returned by semget(2) */
  * we allocate.  It must be *less than* your kernel's SEMMSL (max semaphores
  * per set) parameter, which is often around 25.  (Less than, because we
  * allocate one extra sema in each set for identification purposes.)
- *
- * The present value of 19 is chosen with one eye on NetBSD/OpenBSD's default
- * SEMMNS setting of 60.  Remembering the extra sema per set, this lets us
- * allocate three sets with 57 useful semaphores before exceeding that, which
- * is enough to run our core regression tests.  Users of those systems will
- * still want to raise SEMMNS for any sort of production work, though.
  */
-#define SEMAS_PER_SET  19
+#define SEMAS_PER_SET  16
 
 #define IPCProtection  (0600)  /* access/modify by user only */
 
index aefe8130a68ee80e20efc6b2bdf68469006b1080..62bbd08d9f658749a371d482a3ba66c9e9fb1777 100644 (file)
@@ -1128,15 +1128,14 @@ test_config_settings(void)
     * for a given max_connections value.  Note that it has been carefully
     * crafted to provide specific values for the associated values in
     * trial_conns.  We want it to return autovacuum_worker_slots's initial
-    * default value (16) for the maximum value in trial_conns (100), and we
-    * want it to return close to the minimum value we'd consider (3, which is
-    * the default of autovacuum_max_workers) for the minimum value in
-    * trial_conns (25).
+    * default value (16) for the maximum value in trial_conns[] (100), while
+    * it mustn't return less than the default value of autovacuum_max_workers
+    * (3) for the minimum value in trial_conns[].
     */
 #define AV_SLOTS_FOR_CONNS(nconns) ((nconns) / 6)
 
    static const int trial_conns[] = {
-       100, 50, 40, 30, 25
+       100, 50, 40, 30, 20
    };
    static const int trial_bufs[] = {
        16384, 8192, 4096, 3584, 3072, 2560, 2048, 1536,