From a2b0719cc22d6f7fffa316b5da0fb5b22526c63e Mon Sep 17 00:00:00 2001 From: Thomas Munro Date: Sat, 2 Jul 2022 16:06:47 +1200 Subject: [PATCH] Default to dynamic_shared_memory_type=sysv on Solaris. POSIX shm_open() can sleep for a long time and fail spuriously because of contention on an internal lock file on Solaris (and presumably illumos). Commit 389869af fixed the main problem with this, namely that we could crash, but it's now clear that "posix" is not a good default. Therefore, choose "sysv" at initdb time on Solaris and illumos. Other choices are still available by editing the postgresql.conf file. Back-patch only to 15, because contention is much less likely further back, and it doesn't seem like a good idea to change this in released branches. This should clear up the failures on build farm animal margay. Discussion: https://postgr.es/m/CA%2BhUKGKqKrCV5xKWfh9rnm%3Do%3DDwZLTLtnsj_XpUi9g5%3DV%2B9oyg%40mail.gmail.com --- doc/src/sgml/config.sgml | 2 +- src/backend/utils/misc/postgresql.conf.sample | 2 +- src/bin/initdb/initdb.c | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index 48478b1024..37fd80388c 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -2036,7 +2036,7 @@ include_dir 'conf.d' and mmap (to simulate shared memory using memory-mapped files stored in the data directory). Not all values are supported on all platforms; the first supported - option is the default for that platform. The use of the + option is usually the default for that platform. The use of the mmap option, which is not the default on any platform, is generally discouraged because the operating system may write modified pages back to disk repeatedly, increasing system I/O load; diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample index 48ad80cf2e..b4bc06e5f5 100644 --- a/src/backend/utils/misc/postgresql.conf.sample +++ b/src/backend/utils/misc/postgresql.conf.sample @@ -147,7 +147,7 @@ # sysv # windows # (change requires restart) -#dynamic_shared_memory_type = posix # the default is the first option +#dynamic_shared_memory_type = posix # the default is usually the first option # supported by the operating system: # posix # sysv diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index ed6de7ca94..89b888eaa5 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -842,11 +842,14 @@ set_null_conf(void) * segment in dsm_impl.c; if it doesn't work, we assume it won't work for * the postmaster either, and configure the cluster for System V shared * memory instead. + * + * We avoid choosing Solaris's implementation of shm_open() by default. It + * can sleep and fail spuriously under contention. */ static const char * choose_dsm_implementation(void) { -#ifdef HAVE_SHM_OPEN +#if defined(HAVE_SHM_OPEN) && !defined(__sun__) int ntries = 10; pg_prng_state prng_state;