Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mQLF0-0007n0-EV for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Sep 2021 03:05:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mQLEz-000720-AS for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Sep 2021 03:05:41 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mQLEx-00071s-P0 for pgsql-hackers@lists.postgresql.org; Wed, 15 Sep 2021 03:05:41 +0000 Received: from wnew2-smtp.messagingengine.com ([64.147.123.27]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mQLEs-0004UK-G3 for pgsql-hackers@postgresql.org; Wed, 15 Sep 2021 03:05:38 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailnew.west.internal (Postfix) with ESMTP id D55ED2B007E7; Tue, 14 Sep 2021 23:05:30 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Tue, 14 Sep 2021 23:05:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm2; bh=RZL2OnkoGX1xbc1fE11OO+m2Gx6 haTj9ovHff9rskRs=; b=qBtUo7a7F7blE6ixbPG9T11nwtRGavsbCRTOk1YX4qS Rthx1eJl9MdUEDv/QFDUWKmHmZkXXdOYsXjkIcQngJ21yHrm+otY6tTMF/k8ivyY ybKN2SED1xtaXE9jZ6WwqQj6jqr8DuULEX3GRq0s8AltF4upifbKjWt/ycISMR5v UjIjOZUxf5/I+MrEj1tGSAjk68UeRmA/Vs40fuf3+J3MbNksUR5zMU6STdaFi1hc O2LgjZQdOYNj5ppfC29dM9BJgZLsQHYHQK/bygBbOBA/CFbIebRizwUbUpZIE3za XR5kqRC5/RHBwSLEQijfg2Z6z8zRElWO000Vh3D2dXQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=RZL2On koGX1xbc1fE11OO+m2Gx6haTj9ovHff9rskRs=; b=M2rXAzfc/C4QdmgC9FBWvA KJ9fvU2SOFNKwLhMKrTIkeS/vePOxTPTmyBSWpL2z3mW+JTEX7Ji+KtSrX2PEjPv Hpk45oWcnG4amjaWdP6Len+RpJYwOkgEukmQAXpAqdbMw8H+Q1iPjrFo0qIP9B08 ASrFQrRnqvMBYSq1JtwCJ+lrfxe976wt83iqI7//h4ixoJyN+9mwyvRJ4wiKHsgw evfChwNoVAshCXBf9I0r47m9C3hlscWNoBXVJ6SO6ORyR1NSsQSpoGl3pvEKTM8T Cf+37Or62V4PMnoY2Ih6xPui97KkCpB6spTlT9NaesRctiZP6P7DCqKo6NvxRvpQ == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrudehtddgieehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvuffkfhggtggujgesghdtreertddt vdenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrhcuoehmihgthhgrvghlsehprg hquhhivghrrdighiiiqeenucggtffrrghtthgvrhhnpedvgeduuefhtdeuleettdevjeeh heeiveeuieegleetgeeljeelieeuieehgeevhfenucevlhhushhtvghrufhiiigvpedtne curfgrrhgrmhepmhgrihhlfhhrohhmpehmihgthhgrvghlsehprghquhhivghrrdighiii X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 14 Sep 2021 23:05:26 -0400 (EDT) Date: Wed, 15 Sep 2021 12:05:21 +0900 From: Michael Paquier To: "Bossart, Nathan" Cc: Kyotaro Horiguchi , "tgl@sss.pgh.pa.us" , "robertmhaas@gmail.com" , "masao.fujii@oss.nttdata.com" , "pryzby@telsasoft.com" , "andres@anarazel.de" , "magnus@hagander.net" , "mark.dilger@enterprisedb.com" , "don@seiler.us" , "pgsql-hackers@postgresql.org" Subject: Re: Estimating HugePages Requirements? Message-ID: References: <506431.1631564654@sss.pgh.pa.us> <20210914.094936.565951707453489109.horikyota.ntt@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="YXZXfOaaPB8ueePN" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --YXZXfOaaPB8ueePN Content-Type: multipart/mixed; boundary="Z8lH/WIjrDMrcKuf" Content-Disposition: inline --Z8lH/WIjrDMrcKuf Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Sep 14, 2021 at 06:00:44PM +0000, Bossart, Nathan wrote: > I think I see more support for shared_memory_size_in_huge_pages than > for huge_pages_needed_for_shared_memory at the moment. I'll update > the patch set in the next day or two to use > shared_memory_size_in_huge_pages unless something changes in the > meantime. I have been looking at the patch to add the new GUC flag and the new sequence for postgres -C, and we could have some TAP tests. There were two places that made sense to me: pg_checksums/t/002_actions.pl and recovery/t/017_shm.pl. I have chosen the former as it has coverage across more platforms, and used data_checksums for this purpose, with an extra positive test to check for the case where a GUC can be queried while the server is running. There are four parameters that are updated here: - shared_memory_size - wal_segment_size - data_checksums - data_directory_mode That looks sensible, after looking at the full set of GUCs. Attached is a refreshed patch (commit message is the same as v9 for now), with some minor tweaks and the tests. Thoughts? -- Michael --Z8lH/WIjrDMrcKuf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v10-0001-Provide-useful-values-for-postgres-C-with-runtim.patch" Content-Transfer-Encoding: quoted-printable =46rom e24d151efe45e1bc7048ec72ea66097c94f633be Mon Sep 17 00:00:00 2001 =46rom: Michael Paquier Date: Wed, 15 Sep 2021 12:02:32 +0900 Subject: [PATCH v10] Provide useful values for 'postgres -C' with=20 runtime-computed GUCs The -C option is handled before a small subset of GUCs that are computed at runtime are initialized. Unfortunately, we cannot move this handling to after they are initialized without disallowing 'postgres -C' on a running server. One notable reason for this is that loadable libraries' _PG_init() functions are called before all runtime-computed GUCs are initialized, and this is not guaranteed to be safe to do on running servers. In order to provide useful values for 'postgres -C' for runtime- computed GUCs, this change adds a new section for handling just these GUCs just before shared memory is initialized. While users won't be able to use -C for runtime-computed GUCs on running servers, providing a useful value with this restriction seems better than not providing a useful value at all. --- src/include/utils/guc.h | 6 ++++ src/backend/postmaster/postmaster.c | 50 +++++++++++++++++++++++---- src/backend/utils/misc/guc.c | 8 ++--- src/bin/pg_checksums/t/002_actions.pl | 21 ++++++++++- doc/src/sgml/ref/postgres-ref.sgml | 11 ++++-- 5 files changed, 82 insertions(+), 14 deletions(-) diff --git a/src/include/utils/guc.h b/src/include/utils/guc.h index a7c3a4958e..aa18d304ac 100644 --- a/src/include/utils/guc.h +++ b/src/include/utils/guc.h @@ -229,6 +229,12 @@ typedef enum =20 #define GUC_EXPLAIN 0x100000 /* include in explain */ =20 +/* + * GUC_RUNTIME_COMPUTED is intended for runtime-computed GUCs that are only + * available via 'postgres -C' if the server is not running. + */ +#define GUC_RUNTIME_COMPUTED 0x200000 + #define GUC_UNIT (GUC_UNIT_MEMORY | GUC_UNIT_TIME) =20 =20 diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/p= ostmaster.c index b2fe420c3c..f5b91c7af7 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -896,15 +896,31 @@ PostmasterMain(int argc, char *argv[]) if (output_config_variable !=3D NULL) { /* - * "-C guc" was specified, so print GUC's value and exit. No extra - * permission check is needed because the user is reading inside the - * data dir. + * If this is a runtime-computed GUC, it hasn't yet been initialized, + * and the present value is not useful. However, this is a convenient + * place to print the value for most GUCs because it is safe to run + * postmaster startup to this point even if the server is already + * running. For the handful of runtime-computed GUCs that we can't + * provide meaningful values for yet, we wait until later in + * postmaster startup to print the value. We won't be able to use -C + * on running servers for those GUCs, but otherwise this option is + * unusable for them. */ - const char *config_val =3D GetConfigOption(output_config_variable, - false, false); + int flags =3D GetConfigOptionFlags(output_config_variable, true); =20 - puts(config_val ? config_val : ""); - ExitPostmaster(0); + if ((flags & GUC_RUNTIME_COMPUTED) =3D=3D 0) + { + /* + * "-C guc" was specified, so print GUC's value and exit. No + * extra permission check is needed because the user is reading + * inside the data dir. + */ + const char *config_val =3D GetConfigOption(output_config_variable, + false, false); + + puts(config_val ? config_val : ""); + ExitPostmaster(0); + } } =20 /* Verify that DataDir looks reasonable */ @@ -1033,6 +1049,26 @@ PostmasterMain(int argc, char *argv[]) */ InitializeShmemGUCs(); =20 + /* + * If -C was specified with a runtime-computed GUC, we held off printing + * the value earlier, as the GUC was not yet initialized. We handle -C + * for most GUCs before we lock the data directory so that the option may + * be used on a running server. However, a handful of GUCs are runtime- + * computed and do not have meaningful values until after locking the data + * directory, and we cannot safely calculate their values earlier on a + * running server. At this point, such GUCs should be properly + * initialized, and we haven't yet set up shared memory, so this is a good + * time to handle the -C option for these special GUCs. + */ + if (output_config_variable !=3D NULL) + { + const char *config_val =3D GetConfigOption(output_config_variable, + false, false); + + puts(config_val ? config_val : ""); + ExitPostmaster(0); + } + /* * Set up shared memory and semaphores. */ diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 23236fa4c3..a6e4fcc24e 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -1983,7 +1983,7 @@ static struct config_bool ConfigureNamesBool[] =3D {"data_checksums", PGC_INTERNAL, PRESET_OPTIONS, gettext_noop("Shows whether data checksums are turned on for this clust= er."), NULL, - GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE + GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_RUNTIME_COMPUTED }, &data_checksums, false, @@ -2342,7 +2342,7 @@ static struct config_int ConfigureNamesInt[] =3D {"shared_memory_size", PGC_INTERNAL, PRESET_OPTIONS, gettext_noop("Shows the size of the server's main shared memory area (r= ounded up to the nearest MB)."), NULL, - GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_UNIT_MB + GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_UNIT_MB | GUC_RUNTIME_CO= MPUTED }, &shared_memory_size_mb, 0, 0, INT_MAX, @@ -2407,7 +2407,7 @@ static struct config_int ConfigureNamesInt[] =3D "in the form accepted by the chmod and umask system " "calls. (To use the customary octal format the number " "must start with a 0 (zero).)"), - GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE + GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_RUNTIME_COMPUTED }, &data_directory_mode, 0700, 0000, 0777, @@ -3231,7 +3231,7 @@ static struct config_int ConfigureNamesInt[] =3D {"wal_segment_size", PGC_INTERNAL, PRESET_OPTIONS, gettext_noop("Shows the size of write ahead log segments."), NULL, - GUC_UNIT_BYTE | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE + GUC_UNIT_BYTE | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_RUNTIME_= COMPUTED }, &wal_segment_size, DEFAULT_XLOG_SEG_SIZE, diff --git a/src/bin/pg_checksums/t/002_actions.pl b/src/bin/pg_checksums/t= /002_actions.pl index a18c104a94..e98586c3f8 100644 --- a/src/bin/pg_checksums/t/002_actions.pl +++ b/src/bin/pg_checksums/t/002_actions.pl @@ -10,7 +10,7 @@ use PostgresNode; use TestLib; =20 use Fcntl qw(:seek); -use Test::More tests =3D> 63; +use Test::More tests =3D> 69; =20 =20 # Utility routine to create and check a table with corrupted checksums @@ -178,11 +178,30 @@ command_fails( [ 'pg_checksums', '--enable', '--filenode', '1234', '-D', $pgdata ], "fails when relfilenodes are requested and action is --enable"); =20 +# Test postgres -C for an offline cluster. +# Run-time GUCs are safe to query here. Note that a lock file is created, +# then unlinked, leading to an extra LOG entry showing in stderr. +command_checks_all( + [ 'postgres', '-D', $pgdata, '-C', 'data_checksums' ], + 0, + [qr/^on$/], + # LOG entry when unlinking lock file. + [qr/database system is shut down/], + 'data_checksums=3Don is reported on an offline cluster'); + # Checks cannot happen with an online cluster $node->start; command_fails([ 'pg_checksums', '--check', '-D', $pgdata ], "fails with online cluster"); =20 +# Test postgres -C on an online cluster. +command_fails_like( + [ 'postgres', '-D', $pgdata, '-C', 'data_checksums' ], + qr/lock file .* already exists/, + 'data_checksums is not reported on an online cluster'); +command_ok([ 'postgres', '-D', $pgdata, '-C', 'work_mem' ], + 'non-runtime parameter is reported on an online cluster'); + # Check corruption of table on default tablespace. check_relation_corruption($node, 'corrupt1', 'pg_default'); =20 diff --git a/doc/src/sgml/ref/postgres-ref.sgml b/doc/src/sgml/ref/postgres= -ref.sgml index 4aaa7abe1a..02142ffab2 100644 --- a/doc/src/sgml/ref/postgres-ref.sgml +++ b/doc/src/sgml/ref/postgres-ref.sgml @@ -133,13 +133,20 @@ PostgreSQL documentation Prints the value of the named run-time parameter, and exits. - (See the option above for details.) This can - be used on a running server, and returns values from + (See the option above for details.) This + returns values from postgresql.conf, modified by any parameters supplied in this invocation. It does not reflect parameters supplied when the cluster was started. =20 + + This can be used on a running server for most parameters. However, + the server must be shut down for some runtime-computed parameters + (e.g., , and + ). + + This option is meant for other programs that interact with a server instance, such as , to query configu= ration --=20 2.33.0 --Z8lH/WIjrDMrcKuf-- --YXZXfOaaPB8ueePN Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmFBYvEACgkQnvQgOdby QH14Kg/+IM1vOW3kQofi6KkJc7QD085JqwmCjVATcqvWFyjdn0KcfyXqhtOrXPKb lVHo8L9DZpdSVJaT3hd/8B1yDS8fqMlCgzcKks2KxgSnacLRJp5VtNayq4/av6l0 EamtdiXjPAo6gWmuwSUVjCf71RqAOFuWKFtP9DGv93asKA3CJem0gcGnSdEFmSKu Oh6cUn7gCZbJa/4cfkmo2Y6M9Vev5aJrDGt1yhVcFVE1sE0JJa7jr5+cKgsTjchu a6dTktRZ2SheQUV243KiFk+rr3v6NBwL7d5VPB4fXSOLmzcEESj5we1FBP/ChP6f OFT9V8yJHVv7HI/0lSe9EfAgOj4ftoGZGc4IL7+niizGclQrOYAu9q566xutdAQW 1uq5sz0FVexaJoHaDcHqWT3Ex0nIsb9lCakZMnHRttT+NsIQUDqBadbvYdll7pJh 8KX5MTl+iVtgAC46dbIYLY2/Hj4g3vteJzLigoMV0qY2JavAx9YD33KGMKoGpSHd De9Ytz9AQR+jaP1+v23CZJjJUc9NBhT6E7uXaS/F+D2u69I+DVnCNEtNl4NkS964 jNVbuMbu+JcanMSjqfn8aZ3zLfBFFRGAn+3f8yDqrkWFNL4rurY6V7kxzKXX5FwJ u0x5Ld9r+qxrFQWJ1LXifYIIvG74kL9af7QM7YnjRrZKmzz9ot0= =Q/cO -----END PGP SIGNATURE----- --YXZXfOaaPB8ueePN--