diff options
author | Nathan Bossart <nathan@postgresql.org> | 2024-07-26 15:28:55 -0500 |
---|---|---|
committer | Nathan Bossart <nathan@postgresql.org> | 2024-07-26 15:28:55 -0500 |
commit | 0dcaea56903489e8abedf231f286272495c3beb4 (patch) | |
tree | 3c8bc2c6f4c1a6af0f2e3046f0d6a473af26b7c1 /doc/src | |
parent | 8a53539bd603e5fe8fa52bdbb7277f6f49724522 (diff) | |
download | postgresql-0dcaea56903489e8abedf231f286272495c3beb4.tar.gz postgresql-0dcaea56903489e8abedf231f286272495c3beb4.zip |
Introduce num_os_semaphores GUC.
The documentation for System V IPC parameters provides complicated
formulas to determine the appropriate values for SEMMNI and SEMMNS.
Furthermore, these formulas have often been wrong because folks
forget to update them (e.g., when adding a new auxiliary process).
This commit introduces a new runtime-computed GUC named
num_os_semaphores that reports the number of semaphores needed for
the configured number of allowed connections, worker processes,
etc. This new GUC allows us to simplify the formulas in the
documentation, and it should help prevent future inaccuracies.
Like the other runtime-computed GUCs, users can view it with
"postgres -C" before starting the server, which is useful for
preconfiguring the necessary operating system resources.
Reviewed-by: Tom Lane, Sami Imseih, Andres Freund, Robert Haas
Discussion: https://postgr.es/m/20240517164452.GA1914161%40nathanxps13
Diffstat (limited to 'doc/src')
-rw-r--r-- | doc/src/sgml/config.sgml | 18 | ||||
-rw-r--r-- | doc/src/sgml/runtime.sgml | 31 |
2 files changed, 37 insertions, 12 deletions
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index 3dec0b7cfeb..57cd7bb9727 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -11145,6 +11145,24 @@ dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir' </listitem> </varlistentry> + <varlistentry id="guc-num-os-semaphores" xreflabel="num_os_semaphores"> + <term><varname>num_os_semaphores</varname> (<type>integer</type>) + <indexterm> + <primary><varname>num_os_semaphores</varname> configuration parameter</primary> + </indexterm> + </term> + <listitem> + <para> + Reports the number of semaphores that are needed for the server based + on the configured number of allowed connections + (<xref linkend="guc-max-connections"/>), allowed autovacuum worker + processes (<xref linkend="guc-autovacuum-max-workers"/>), allowed WAL + sender processes (<xref linkend="guc-max-wal-senders"/>), allowed + background processes (<xref linkend="guc-max-worker-processes"/>), etc. + </para> + </listitem> + </varlistentry> + <varlistentry id="guc-segment-size" xreflabel="segment_size"> <term><varname>segment_size</varname> (<type>integer</type>) <indexterm> diff --git a/doc/src/sgml/runtime.sgml b/doc/src/sgml/runtime.sgml index 2f7c6188869..2c4d5ef640d 100644 --- a/doc/src/sgml/runtime.sgml +++ b/doc/src/sgml/runtime.sgml @@ -781,13 +781,13 @@ 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((max_connections + autovacuum_max_workers + max_wal_senders + max_worker_processes + 7) / 16)</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((max_connections + autovacuum_max_workers + max_wal_senders + max_worker_processes + 7) / 16) * 17</literal> plus room for other applications</entry> + <entry><literal>ceil(num_os_semaphores / 16) * 17</literal> plus room for other applications</entry> </row> <row> @@ -839,21 +839,28 @@ psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such <productname>PostgreSQL</productname> uses one semaphore per allowed connection (<xref linkend="guc-max-connections"/>), allowed autovacuum worker process (<xref linkend="guc-autovacuum-max-workers"/>), allowed WAL sender process - (<xref linkend="guc-max-wal-senders"/>), and allowed background - process (<xref linkend="guc-max-worker-processes"/>), in sets of 16. - Each such set will + (<xref linkend="guc-max-wal-senders"/>), allowed background + 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: +<programlisting> +$ <userinput>postgres -D $PGDATA -C num_os_semaphores</userinput> +</programlisting> + </para> + + <para> + 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 <varname>max_connections</varname> plus - <varname>autovacuum_max_workers</varname> plus <varname>max_wal_senders</varname>, - plus <varname>max_worker_processes</varname>, plus one extra for each 16 - allowed connections plus workers (see the formula in <xref + as high as <literal>num_os_semaphores</literal> plus one extra for + 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((max_connections + autovacuum_max_workers + max_wal_senders + max_worker_processes + 7) / 16)</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 @@ -885,8 +892,8 @@ psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such same as for System V, that is one semaphore per allowed connection (<xref linkend="guc-max-connections"/>), allowed autovacuum worker process (<xref linkend="guc-autovacuum-max-workers"/>), allowed WAL sender process - (<xref linkend="guc-max-wal-senders"/>), and allowed background - process (<xref linkend="guc-max-worker-processes"/>). + (<xref linkend="guc-max-wal-senders"/>), allowed background + process (<xref linkend="guc-max-worker-processes"/>), etc. On the platforms where this option is preferred, there is no specific kernel limit on the number of POSIX semaphores. </para> |