GUC values - recommended way to declare the C variables?
Hi hackers.
I have a question about the recommended way to declare the C variables
used for the GUC values.
Here are some examples from the code:
~
The GUC boot values are defined in src/backend.utils/misc/guc_tables.c
e.g. See the 4, and 2 below
{
{"max_logical_replication_workers",
PGC_POSTMASTER,
REPLICATION_SUBSCRIBERS,
gettext_noop("Maximum number of logical replication worker processes."),
NULL,
},
&max_logical_replication_workers,
4, 0, MAX_BACKENDS,
NULL, NULL, NULL
},
{
{"max_sync_workers_per_subscription",
PGC_SIGHUP,
REPLICATION_SUBSCRIBERS,
gettext_noop("Maximum number of table synchronization workers per
subscription."),
NULL,
},
&max_sync_workers_per_subscription,
2, 0, MAX_BACKENDS,
NULL, NULL, NULL
},
~~
Meanwhile, the associated C variables are declared in their respective modules.
e.g. src/backend/replication/launcher.c
int max_logical_replication_workers = 4;
int max_sync_workers_per_subscription = 2;
~~
It seems confusing to me that for the above code the initial value is
"hardwired" in multiple places. Specifically, it looks tempting to
just change the variable declaration value, but IIUC that's going to
achieve nothing because it will just be overwritten by the
"boot-value" during the GUC mechanism start-up.
Furthermore, there seems no consistency with how these C variables are
auto-initialized:
a) Sometimes the static variable is assigned some (dummy?) value that
is not the same as the boot value
- See src/backend/utils/misc/guc_tables.c, max_replication_slots boot
value is 10
- See src/backend/replication/slot.c, int max_replication_slots = 0;
b) Sometimes the static value is assigned the same hardwired value as
the GUC boot value
- See src/backend/utils/misc/guc_tables.c,
max_logical_replication_workers boot value is 4
- See src/backend/replication/launcher.c, int
max_logical_replication_workers = 4;
c) Sometimes the GUC C variables don't even have a comment saying that
they are GUC variables, so it is not at all obvious their initial
values are going to get overwritten by some external mechanism.
- See src/backend/replication/launcher.c, int
max_logical_replication_workers = 4;
~
I would like to know what is the recommended way/convention to write
the C variable declarations for the GUC values.
IMO I felt the launch.c code as shown would be greatly improved simply
by starting with 0 values, and including an explanatory comment.
e.g.
CURRENT
int max_logical_replication_workers = 4;
int max_sync_workers_per_subscription = 2;
SUGGESTION
/*
* GUC variables. Initial values are assigned at startup via
InitializeGUCOptions.
*/
int max_logical_replication_workers = 0;
int max_sync_workers_per_subscription = 0;
Thoughts?
------
Kind Regards,
Peter Smith.
Fujitsu Australia
Peter Smith <smithpb2250@gmail.com> writes:
It seems confusing to me that for the above code the initial value is
"hardwired" in multiple places. Specifically, it looks tempting to
just change the variable declaration value, but IIUC that's going to
achieve nothing because it will just be overwritten by the
"boot-value" during the GUC mechanism start-up.
Well, if you try that you'll soon discover it doesn't work ;-)
IIRC, the primary argument for hand-initializing GUC variables is to
ensure that they have a sane value even before InitializeGUCOptions runs.
Obviously, that only matters for some subset of the GUCs that could be
consulted very early in startup ... but it's not perfectly clear just
which ones it matters for.
a) Sometimes the static variable is assigned some (dummy?) value that
is not the same as the boot value
- See src/backend/utils/misc/guc_tables.c, max_replication_slots boot
value is 10
- See src/backend/replication/slot.c, int max_replication_slots = 0;
That seems pretty bogus. I think if we're not initializing a GUC to
the "correct" value then we should just leave it as not explicitly
initialized.
c) Sometimes the GUC C variables don't even have a comment saying that
they are GUC variables, so it is not at all obvious their initial
values are going to get overwritten by some external mechanism.
That's flat out sloppy commenting. There are a lot of people around
here who seem to think comments are optional :-(
SUGGESTION
/*
* GUC variables. Initial values are assigned at startup via
InitializeGUCOptions.
*/
int max_logical_replication_workers = 0;
int max_sync_workers_per_subscription = 0;
1. Comment far wordier than necessary. In most places we just
annotate these as "GUC variables", and I think that's sufficient.
You're going to have a hard time getting people to write more
than that anyway.
2. I don't agree with explicitly initializing to a wrong value.
It'd be sufficient to do
int max_logical_replication_workers;
int max_sync_workers_per_subscription;
which would also make it clearer that initialization happens
through some other mechanism.
regards, tom lane
On Tue, Sep 27, 2022 at 10:08 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
Peter Smith <smithpb2250@gmail.com> writes:
It seems confusing to me that for the above code the initial value is
"hardwired" in multiple places. Specifically, it looks tempting to
just change the variable declaration value, but IIUC that's going to
achieve nothing because it will just be overwritten by the
"boot-value" during the GUC mechanism start-up.Well, if you try that you'll soon discover it doesn't work ;-)
IIRC, the primary argument for hand-initializing GUC variables is to
ensure that they have a sane value even before InitializeGUCOptions runs.
Obviously, that only matters for some subset of the GUCs that could be
consulted very early in startup ... but it's not perfectly clear just
which ones it matters for.a) Sometimes the static variable is assigned some (dummy?) value that
is not the same as the boot value
- See src/backend/utils/misc/guc_tables.c, max_replication_slots boot
value is 10
- See src/backend/replication/slot.c, int max_replication_slots = 0;That seems pretty bogus. I think if we're not initializing a GUC to
the "correct" value then we should just leave it as not explicitly
initialized.c) Sometimes the GUC C variables don't even have a comment saying that
they are GUC variables, so it is not at all obvious their initial
values are going to get overwritten by some external mechanism.That's flat out sloppy commenting. There are a lot of people around
here who seem to think comments are optional :-(SUGGESTION
/*
* GUC variables. Initial values are assigned at startup via
InitializeGUCOptions.
*/
int max_logical_replication_workers = 0;
int max_sync_workers_per_subscription = 0;1. Comment far wordier than necessary. In most places we just
annotate these as "GUC variables", and I think that's sufficient.
You're going to have a hard time getting people to write more
than that anyway.2. I don't agree with explicitly initializing to a wrong value.
It'd be sufficient to doint max_logical_replication_workers;
int max_sync_workers_per_subscription;which would also make it clearer that initialization happens
through some other mechanism.
Thanks for your advice.
I will try to post a patch in the new few days to address (per your
suggestions) some of the variables that I am more familiar with.
------
Kind Regards,
Peter Smith.
Fujitsu Australia.
On Tue, Sep 27, 2022 at 11:07 AM Peter Smith <smithpb2250@gmail.com> wrote:
...
I will try to post a patch in the new few days to address (per your
suggestions) some of the variables that I am more familiar with.
PSA a small patch to tidy a few of the GUC C variables - adding
comments and removing unnecessary declaration assignments.
make check-world passed OK.
------
Kind Regards,
Peter Smith.
Fujitsu Australia.
Attachments:
v1-0001-Tidied-some-GUC-C-variable-declarations.patchapplication/octet-stream; name=v1-0001-Tidied-some-GUC-C-variable-declarations.patchDownload
From 8deac37278ba4388de7259d921e6e4e6385072a1 Mon Sep 17 00:00:00 2001
From: Peter Smith <peter.b.smith@fujitsu.com>
Date: Wed, 28 Sep 2022 09:48:33 +1000
Subject: [PATCH v1] Tidied some GUC C variable declarations.
Added comments to indicate the GUC variables.
Removed some unnecessary C variable assignments since the default values
will be assigned/overwritten by the GUC mechanism.
---
src/backend/replication/logical/launcher.c | 5 +++--
src/backend/replication/slot.c | 6 +++---
src/backend/replication/walsender.c | 10 +++++-----
3 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/replication/logical/launcher.c b/src/backend/replication/logical/launcher.c
index 3bbd522..66007ca 100644
--- a/src/backend/replication/logical/launcher.c
+++ b/src/backend/replication/logical/launcher.c
@@ -52,8 +52,9 @@
/* max sleep time between cycles (3min) */
#define DEFAULT_NAPTIME_PER_CYCLE 180000L
-int max_logical_replication_workers = 4;
-int max_sync_workers_per_subscription = 2;
+/* GUC variables. */
+int max_logical_replication_workers;
+int max_sync_workers_per_subscription;
LogicalRepWorker *MyLogicalRepWorker = NULL;
diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c
index 0bd0031..b265fa8 100644
--- a/src/backend/replication/slot.c
+++ b/src/backend/replication/slot.c
@@ -97,9 +97,9 @@ ReplicationSlotCtlData *ReplicationSlotCtl = NULL;
/* My backend's replication slot in the shared memory array */
ReplicationSlot *MyReplicationSlot = NULL;
-/* GUCs */
-int max_replication_slots = 0; /* the maximum number of replication
- * slots */
+/* GUC variable. */
+int max_replication_slots; /* the maximum number of replication
+ * slots */
static void ReplicationSlotShmemExit(int code, Datum arg);
static void ReplicationSlotDropAcquired(void);
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index e9ba500..e9c1429 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -118,12 +118,12 @@ bool am_cascading_walsender = false; /* Am I cascading WAL to another
* standby? */
bool am_db_walsender = false; /* Connected to a database? */
-/* User-settable parameters for walsender */
-int max_wal_senders = 0; /* the maximum number of concurrent
+/* GUC variables. */
+int max_wal_senders; /* the maximum number of concurrent
* walsenders */
-int wal_sender_timeout = 60 * 1000; /* maximum time to send one WAL
- * data message */
-bool log_replication_commands = false;
+int wal_sender_timeout; /* maximum time to send one WAL
+ * data message */
+bool log_replication_commands;
/*
* State for WalSndWakeupRequest
--
1.8.3.1
On Wed, Sep 28, 2022 at 10:13:22AM +1000, Peter Smith wrote:
PSA a small patch to tidy a few of the GUC C variables - adding
comments and removing unnecessary declaration assignments.make check-world passed OK.
Looks reasonable to me. I've marked this as ready-for-committer.
--
Nathan Bossart
Amazon Web Services: https://aws.amazon.com
On Wed, Oct 12, 2022 at 12:12:15PM -0700, Nathan Bossart wrote:
Looks reasonable to me. I've marked this as ready-for-committer.
So, the initial values of max_wal_senders and max_replication_slots
became out of sync with their defaults in guc_tables.c. FWIW, I would
argue the opposite way: rather than removing the initializations, I
would fix and keep them as these references can be useful when
browsing the area of the code related to such GUCs, without having to
look at guc_tables.c for this information.
--
Michael
On Thu, Oct 13, 2022 at 09:47:25AM +0900, Michael Paquier wrote:
So, the initial values of max_wal_senders and max_replication_slots
became out of sync with their defaults in guc_tables.c. FWIW, I would
argue the opposite way: rather than removing the initializations, I
would fix and keep them as these references can be useful when
browsing the area of the code related to such GUCs, without having to
look at guc_tables.c for this information.
Well, those initializations are only useful when they are kept in sync,
which, as demonstrated by this patch, isn't always the case. I don't have
a terribly strong opinion about this, but I'd lean towards reducing the
number of places that track the default value of GUCs.
--
Nathan Bossart
Amazon Web Services: https://aws.amazon.com
On Fri, Oct 14, 2022 at 8:26 AM Nathan Bossart <nathandbossart@gmail.com> wrote:
On Thu, Oct 13, 2022 at 09:47:25AM +0900, Michael Paquier wrote:
So, the initial values of max_wal_senders and max_replication_slots
became out of sync with their defaults in guc_tables.c. FWIW, I would
argue the opposite way: rather than removing the initializations, I
would fix and keep them as these references can be useful when
browsing the area of the code related to such GUCs, without having to
look at guc_tables.c for this information.Well, those initializations are only useful when they are kept in sync,
which, as demonstrated by this patch, isn't always the case. I don't have
a terribly strong opinion about this, but I'd lean towards reducing the
number of places that track the default value of GUCs.
I agree if constants are used in both places then there will always be
some risk they can get out of sync again.
But probably it is no problem to just add #defines (e.g. in
logicallauncher.h?) to be commonly used for the C variable declaration
and also in the guc_tables. I chose not to do that way only because it
didn't seem to be the typical convention for all the other numeric
GUCs I looked at, but it's fine by me if that way is preferred
------
Kind Regards,
Peter Smith.
Fujitsu Australia
Peter Smith <smithpb2250@gmail.com> writes:
I agree if constants are used in both places then there will always be
some risk they can get out of sync again.
Yeah.
But probably it is no problem to just add #defines (e.g. in
logicallauncher.h?) to be commonly used for the C variable declaration
and also in the guc_tables.
The problem is exactly that there's no great place to put those #define's,
at least not without incurring a lot of fresh #include bloat.
Also, if you did it like that, then it doesn't really address Michael's
desire to see the default value in the variable declaration.
I do lean towards having the data available, mainly because of the
fear I mentioned upthread that some GUCs may be accessed before
InitializeGUCOptions runs.
Could we fix the out-of-sync risk by having InitializeGUCOptions insist
that the pre-existing value of the variable match what is in guc_tables.c?
That may not work for string values but I think we could insist on it
for other GUC data types. For strings, maybe the rule could be "the
old value must be NULL or strcmp-equal to the boot_val".
regards, tom lane
On Thu, Oct 13, 2022 at 11:14:57PM -0400, Tom Lane wrote:
Could we fix the out-of-sync risk by having InitializeGUCOptions insist
that the pre-existing value of the variable match what is in guc_tables.c?
That may not work for string values but I think we could insist on it
for other GUC data types. For strings, maybe the rule could be "the
old value must be NULL or strcmp-equal to the boot_val".
pg_strcasecmp()'d would be more flexible here? Sometimes the
character casing on the values is not entirely consistent, but no
objections to use something stricter, either.
--
Michael
Michael Paquier <michael@paquier.xyz> writes:
On Thu, Oct 13, 2022 at 11:14:57PM -0400, Tom Lane wrote:
For strings, maybe the rule could be "the
old value must be NULL or strcmp-equal to the boot_val".
pg_strcasecmp()'d would be more flexible here?
Don't see the point for that. The case we're talking about is
where the variable is declared like
char *my_guc_variable = "foo_bar";
where the initialization value is going to be a compile-time
constant. I don't see why we'd need to allow any difference
between that constant and the one used in guc_tables.c.
On the other hand, we could insist that string values be strcmp-equal with
no allowance for NULL. But that probably results in duplicate copies of
the string constant, and I'm not sure it buys anything in most places.
Allowing NULL doesn't seem like it creates any extra hazard for early
references, because they'd just crash if they try to use the value
while it's still NULL.
regards, tom lane
PSA v2* patches.
Patch 0001 is just a minor tidy of the GUC C variables of logical
replication. The C variable initial values are present again, how
Michael preferred them [1]prefer to have C initial values - /messages/by-id/Y0dgHfEGvvay5nle@paquier.xyz.
Patch 0002 adds a sanity-check function called by
InitializeGUCOptions, as suggested by Tom [2]sanity-check idea - /messages/by-id/1113448.1665717297@sss.pgh.pa.us. This is to ensure that
the GUC C variable initial values are sensible and/or have not gone
stale compared with the compiled-in defaults of guc_tables.c. This
patch also changes some GUC C variable initial values which were
already found (by this sanity-checker) to be different.
~~~
FYI, here are examples of errors when (contrived) mismatched values
are detected:
[postgres@CentOS7-x64 ~]$ pg_ctl -D ./MYDATAOSS/ start
waiting for server to start....FATAL: GUC (PGC_INT)
max_replication_slots, boot_val=10, C-var=999
stopped waiting
pg_ctl: could not start server
Examine the log output.
[postgres@CentOS7-x64 ~]$ pg_ctl -D ./MYDATAOSS/ start
waiting for server to start....FATAL: GUC (PGC_BOOL)
enable_partitionwise_aggregate, boot_val=0, C-var=1
stopped waiting
pg_ctl: could not start server
Examine the log output.
[postgres@CentOS7-x64 ~]$ pg_ctl -D ./MYDATAOSS/ start
waiting for server to start....FATAL: GUC (PGC_REAL)
cpu_operator_cost, boot_val=0.0025, C-var=99.99
stopped waiting
pg_ctl: could not start server
Examine the log output.
[postgres@CentOS7-x64 ~]$ pg_ctl -D ./MYDATAOSS/ start
waiting for server to start....FATAL: GUC (PGC_STRING)
archive_command, boot_val=, C-var=banana
stopped waiting
pg_ctl: could not start server
Examine the log output.
[postgres@CentOS7-x64 ~]$ pg_ctl -D ./MYDATAOSS/ start
waiting for server to start....FATAL: GUC (PGC_ENUM) wal_level,
boot_val=1, C-var=99
stopped waiting
pg_ctl: could not start server
Examine the log output.
------
[1]: prefer to have C initial values - /messages/by-id/Y0dgHfEGvvay5nle@paquier.xyz
/messages/by-id/Y0dgHfEGvvay5nle@paquier.xyz
[2]: sanity-check idea - /messages/by-id/1113448.1665717297@sss.pgh.pa.us
/messages/by-id/1113448.1665717297@sss.pgh.pa.us
Kind Regards,
Peter Smith.
Fujitsu Australia
Attachments:
v2-0001-Tidied-some-GUC-C-variable-declarations.patchapplication/octet-stream; name=v2-0001-Tidied-some-GUC-C-variable-declarations.patchDownload
From 3d58d6940ed6341e66d711c8d4e0aba2608e3cee Mon Sep 17 00:00:00 2001
From: Peter Smith <peter.b.smith@fujitsu.com>
Date: Thu, 20 Oct 2022 10:25:30 +1100
Subject: [PATCH v2] Tidied some GUC C variable declarations.
---
src/backend/replication/logical/launcher.c | 1 +
src/backend/replication/slot.c | 6 +++---
src/backend/replication/walsender.c | 8 ++++----
3 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/src/backend/replication/logical/launcher.c b/src/backend/replication/logical/launcher.c
index ff57421..6833eb9 100644
--- a/src/backend/replication/logical/launcher.c
+++ b/src/backend/replication/logical/launcher.c
@@ -52,6 +52,7 @@
/* max sleep time between cycles (3min) */
#define DEFAULT_NAPTIME_PER_CYCLE 180000L
+/* GUC variables. */
int max_logical_replication_workers = 4;
int max_sync_workers_per_subscription = 2;
diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c
index d58d16e..5b73aa1 100644
--- a/src/backend/replication/slot.c
+++ b/src/backend/replication/slot.c
@@ -97,9 +97,9 @@ ReplicationSlotCtlData *ReplicationSlotCtl = NULL;
/* My backend's replication slot in the shared memory array */
ReplicationSlot *MyReplicationSlot = NULL;
-/* GUCs */
-int max_replication_slots = 0; /* the maximum number of replication
- * slots */
+/* GUC variable. */
+int max_replication_slots = 10; /* the maximum number of replication
+ * slots */
static void ReplicationSlotShmemExit(int code, Datum arg);
static void ReplicationSlotDropAcquired(void);
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 2193dca..142028a 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -118,11 +118,11 @@ bool am_cascading_walsender = false; /* Am I cascading WAL to another
* standby? */
bool am_db_walsender = false; /* Connected to a database? */
-/* User-settable parameters for walsender */
-int max_wal_senders = 0; /* the maximum number of concurrent
+/* GUC variables. */
+int max_wal_senders = 10; /* the maximum number of concurrent
* walsenders */
-int wal_sender_timeout = 60 * 1000; /* maximum time to send one WAL
- * data message */
+int wal_sender_timeout = 60 * 1000; /* maximum time to send one WAL
+ * data message */
bool log_replication_commands = false;
/*
--
1.8.3.1
v2-0002-GUC-C-variable-sanity-check.patchapplication/octet-stream; name=v2-0002-GUC-C-variable-sanity-check.patchDownload
From 95c4e62158d6573c3a1413c53b2ecff7eb5e20ec Mon Sep 17 00:00:00 2001
From: Peter Smith <peter.b.smith@fujitsu.com>
Date: Thu, 20 Oct 2022 11:07:26 +1100
Subject: [PATCH v2] GUC C variable sanity check
Added a function to perform a sanity-check comparison of the C variable initial
value with the compiled-in default (boot_val). The purpose of this is to prevent
anybody reading those C declarations from being fooled by mismatched values.
Also fixed some existing mismatching values.
---
src/backend/access/transam/xact.c | 2 +-
src/backend/access/transam/xlog.c | 2 +-
src/backend/libpq/be-secure.c | 4 +-
src/backend/storage/ipc/dsm_impl.c | 2 +-
src/backend/utils/adt/xml.c | 4 +-
src/backend/utils/cache/plancache.c | 2 +-
src/backend/utils/error/elog.c | 2 +-
src/backend/utils/init/globals.c | 4 +-
src/backend/utils/misc/guc.c | 74 +++++++++++++++++++++++++++++++++++++
src/backend/utils/misc/guc_tables.c | 9 ++++-
10 files changed, 92 insertions(+), 13 deletions(-)
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index fd5103a..f45c95f 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -75,7 +75,7 @@
* User-tweakable parameters
*/
int DefaultXactIsoLevel = XACT_READ_COMMITTED;
-int XactIsoLevel;
+int XactIsoLevel = XACT_READ_COMMITTED;
bool DefaultXactReadOnly = false;
bool XactReadOnly;
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 27085b1..32e2b97 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -131,7 +131,7 @@ bool wal_init_zero = true;
bool wal_recycle = true;
bool log_checkpoints = true;
int sync_method = DEFAULT_SYNC_METHOD;
-int wal_level = WAL_LEVEL_MINIMAL;
+int wal_level = WAL_LEVEL_REPLICA;
int CommitDelay = 0; /* precommit delay in microseconds */
int CommitSiblings = 5; /* # concurrent xacts needed to sleep */
int wal_retrieve_retry_interval = 5000;
diff --git a/src/backend/libpq/be-secure.c b/src/backend/libpq/be-secure.c
index e3e5471..c896357 100644
--- a/src/backend/libpq/be-secure.c
+++ b/src/backend/libpq/be-secure.c
@@ -58,8 +58,8 @@ char *SSLECDHCurve;
/* GUC variable: if false, prefer client ciphers */
bool SSLPreferServerCiphers;
-int ssl_min_protocol_version;
-int ssl_max_protocol_version;
+int ssl_min_protocol_version = PG_TLS1_2_VERSION;
+int ssl_max_protocol_version = PG_TLS_ANY;
/* ------------------------------------------------------------ */
/* Procedures common to all secure sessions */
diff --git a/src/backend/storage/ipc/dsm_impl.c b/src/backend/storage/ipc/dsm_impl.c
index e1b90c5..6ddd46a 100644
--- a/src/backend/storage/ipc/dsm_impl.c
+++ b/src/backend/storage/ipc/dsm_impl.c
@@ -109,7 +109,7 @@ const struct config_enum_entry dynamic_shared_memory_options[] = {
};
/* Implementation selector. */
-int dynamic_shared_memory_type;
+int dynamic_shared_memory_type = DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE;
/* Amount of space reserved for DSM segments in the main area. */
int min_dynamic_shared_memory;
diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c
index d32cb11..8cd5262 100644
--- a/src/backend/utils/adt/xml.c
+++ b/src/backend/utils/adt/xml.c
@@ -94,8 +94,8 @@
/* GUC variables */
-int xmlbinary;
-int xmloption;
+int xmlbinary = XMLBINARY_BASE64;
+int xmloption = XMLOPTION_CONTENT;
#ifdef USE_LIBXML
diff --git a/src/backend/utils/cache/plancache.c b/src/backend/utils/cache/plancache.c
index 0d6a295..cc94320 100644
--- a/src/backend/utils/cache/plancache.c
+++ b/src/backend/utils/cache/plancache.c
@@ -116,7 +116,7 @@ static void PlanCacheObjectCallback(Datum arg, int cacheid, uint32 hashvalue);
static void PlanCacheSysCallback(Datum arg, int cacheid, uint32 hashvalue);
/* GUC parameter */
-int plan_cache_mode;
+int plan_cache_mode = PLAN_CACHE_MODE_AUTO;
/*
* InitPlanCache: initialize module during InitPostgres.
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 6e0a66c..2585e24 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -107,7 +107,7 @@ extern bool redirection_done;
emit_log_hook_type emit_log_hook = NULL;
/* GUC parameters */
-int Log_error_verbosity = PGERROR_VERBOSE;
+int Log_error_verbosity = PGERROR_DEFAULT;
char *Log_line_prefix = NULL; /* format for extra log line info */
int Log_destination = LOG_DESTINATION_STDERR;
char *Log_destination_string = NULL;
diff --git a/src/backend/utils/init/globals.c b/src/backend/utils/init/globals.c
index 1a5d29a..00bceec 100644
--- a/src/backend/utils/init/globals.c
+++ b/src/backend/utils/init/globals.c
@@ -133,8 +133,8 @@ int max_parallel_maintenance_workers = 2;
* MaxBackends is computed by PostmasterMain after modules have had a chance to
* register background workers.
*/
-int NBuffers = 1000;
-int MaxConnections = 90;
+int NBuffers = 16384;
+int MaxConnections = 100;
int max_worker_processes = 8;
int max_parallel_workers = 8;
int MaxBackends = 0;
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 6f21752..f138798 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -1382,6 +1382,76 @@ check_GUC_name_for_parameter_acl(const char *name)
return false;
}
+#ifdef USE_ASSERT_CHECKING
+/*
+ * A GUC C variable can be declared with an initial value, but the GUC mechanism
+ * will overwrite that using the compiled-in default (boot_val) as per
+ * guc_tables.c.
+ *
+ * This function performs a sanity-check comparison of the C variable initial
+ * value with the boot_val, to prevent anybody reading those C declarations
+ * from being fooled by mismatched values.
+ *
+ * GUC C variable declared value:
+ * bool - can be false, otherwise must be same as the boot_val
+ * int - can be 0, otherwise must be same as the boot_val
+ * real - can be 0.0, otherwise must be same as the boot_val
+ * string - can be NULL, otherwise must be strcmp equal to the boot_val
+ * enum - must be same as the boot_val
+ */
+static void
+sanity_check_GUC_C_var(struct config_generic *gconf)
+{
+ switch (gconf->vartype)
+ {
+ case PGC_BOOL:
+ {
+ struct config_bool *conf = (struct config_bool *) gconf;
+
+ if (*conf->variable && !conf->boot_val)
+ elog(FATAL, "GUC (PGC_BOOL) %s, boot_val=%d, C-var=%d",
+ conf->gen.name, conf->boot_val, *conf->variable);
+ break;
+ }
+ case PGC_INT:
+ {
+ struct config_int *conf = (struct config_int *) gconf;
+
+ if (*conf->variable != 0 && *conf->variable != conf->boot_val)
+ elog(FATAL, "GUC (PGC_INT) %s, boot_val=%d, C-var=%d",
+ conf->gen.name, conf->boot_val, *conf->variable);
+ break;
+ }
+ case PGC_REAL:
+ {
+ struct config_real *conf = (struct config_real *) gconf;
+
+ if (*conf->variable != 0.0 && *conf->variable != conf->boot_val)
+ elog(FATAL, "GUC (PGC_REAL) %s, boot_val=%g, C-var=%g",
+ conf->gen.name, conf->boot_val, *conf->variable);
+ break;
+ }
+ case PGC_STRING:
+ {
+ struct config_string *conf = (struct config_string *) gconf;
+
+ if (*conf->variable != NULL && strcmp(*conf->variable, conf->boot_val) != 0)
+ elog(FATAL, "GUC (PGC_STRING) %s, boot_val=%s, C-var=%s",
+ conf->gen.name, conf->boot_val ? conf->boot_val : "<null>", *conf->variable);
+ break;
+ }
+ case PGC_ENUM:
+ {
+ struct config_enum *conf = (struct config_enum *) gconf;
+
+ if (*conf->variable != conf->boot_val)
+ elog(FATAL, "GUC (PGC_ENUM) %s, boot_val=%d, C-var=%d",
+ conf->gen.name, conf->boot_val, *conf->variable);
+ break;
+ }
+ }
+}
+#endif
/*
* Initialize GUC options during program startup.
@@ -1413,6 +1483,10 @@ InitializeGUCOptions(void)
hash_seq_init(&status, guc_hashtab);
while ((hentry = (GUCHashEntry *) hash_seq_search(&status)) != NULL)
{
+#ifdef USE_ASSERT_CHECKING
+ sanity_check_GUC_C_var(hentry->gucvar);
+#endif
+
InitializeOneGUCOption(hentry->gucvar);
}
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 05ab087..23a1b0d 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -526,7 +526,7 @@ int ssl_renegotiation_limit;
* This really belongs in pg_shmem.c, but is defined here so that it doesn't
* need to be duplicated in all the different implementations of pg_shmem.c.
*/
-int huge_pages;
+int huge_pages = HUGE_PAGES_TRY;
int huge_page_size;
/*
@@ -543,7 +543,12 @@ static char *locale_ctype;
static char *server_encoding_string;
static char *server_version_string;
static int server_version_num;
-static int syslog_facility;
+static int syslog_facility =
+#ifdef HAVE_SYSLOG
+ LOG_LOCAL0;
+#else
+ 0;
+#endif
static char *timezone_string;
static char *log_timezone_string;
static char *timezone_abbreviations_string;
--
1.8.3.1
On Thu, Oct 20, 2022 at 11:56:58AM +1100, Peter Smith wrote:
Patch 0002 adds a sanity-check function called by
InitializeGUCOptions, as suggested by Tom [2]. This is to ensure that
the GUC C variable initial values are sensible and/or have not gone
stale compared with the compiled-in defaults of guc_tables.c. This
patch also changes some GUC C variable initial values which were
already found (by this sanity-checker) to be different.
I like it.
However it's fails on windows:
https://cirrus-ci.com/task/5545965036765184
running bootstrap script ... FATAL: GUC (PGC_BOOL) update_process_title, boot_val=0, C-var=1
Maybe you need to exclude dynamically set gucs ?
See also this other thread, where I added a flag identifying exactly
that. https://commitfest.postgresql.org/40/3736/
I need to polish that patch some, but maybe it'll be useful for you, too.
--
Justin
On Thu, Oct 20, 2022 at 3:16 PM Justin Pryzby <pryzby@telsasoft.com> wrote:
On Thu, Oct 20, 2022 at 11:56:58AM +1100, Peter Smith wrote:
Patch 0002 adds a sanity-check function called by
InitializeGUCOptions, as suggested by Tom [2]. This is to ensure that
the GUC C variable initial values are sensible and/or have not gone
stale compared with the compiled-in defaults of guc_tables.c. This
patch also changes some GUC C variable initial values which were
already found (by this sanity-checker) to be different.I like it.
However it's fails on windows:
https://cirrus-ci.com/task/5545965036765184
running bootstrap script ... FATAL: GUC (PGC_BOOL) update_process_title, boot_val=0, C-var=1
Maybe you need to exclude dynamically set gucs ?
See also this other thread, where I added a flag identifying exactly
that. https://commitfest.postgresql.org/40/3736/
I need to polish that patch some, but maybe it'll be useful for you, too.
Great, this looks very helpful. I will try again tomorrow by skipping
over such GUCs.
And I noticed a couple of other C initial values I had changed
coincide with what you've marked as GUC_DYNAMIC_DEFAULT so I'll
restore those to how they were before too.
------
Kind Regards,
Peter Smith.
Fujitsu Australia
On Thu, Oct 20, 2022 at 6:52 PM Peter Smith <smithpb2250@gmail.com> wrote:
On Thu, Oct 20, 2022 at 3:16 PM Justin Pryzby <pryzby@telsasoft.com> wrote:
On Thu, Oct 20, 2022 at 11:56:58AM +1100, Peter Smith wrote:
Patch 0002 adds a sanity-check function called by
InitializeGUCOptions, as suggested by Tom [2]. This is to ensure that
the GUC C variable initial values are sensible and/or have not gone
stale compared with the compiled-in defaults of guc_tables.c. This
patch also changes some GUC C variable initial values which were
already found (by this sanity-checker) to be different.I like it.
However it's fails on windows:
https://cirrus-ci.com/task/5545965036765184
running bootstrap script ... FATAL: GUC (PGC_BOOL) update_process_title, boot_val=0, C-var=1
Maybe you need to exclude dynamically set gucs ?
See also this other thread, where I added a flag identifying exactly
that. https://commitfest.postgresql.org/40/3736/
I need to polish that patch some, but maybe it'll be useful for you, too.
PSA patch set v3.
This is essentially the same as before except now, utilizing the
GUC_DEFAULT_COMPILE flag added by Justin's patch [1]Justin's patch of 24/Oct - /messages/by-id/20221024220544.GJ16921@telsasoft.com, the sanity-check
skips over any dynamic compiler-dependent GUCs.
Patch 0001 - GUC trivial mods to logical replication GUC C var declarations
Patch 0002 - (TMP) Justin's patch adds the GUC_DEFAULT_COMPILE flag
support -- this is now a prerequisite for 0003
Patch 0003 - GUC sanity-check comparisons of GUC C var declarations
with the GUC defaults from guc_tables.c
------
[1]: Justin's patch of 24/Oct - /messages/by-id/20221024220544.GJ16921@telsasoft.com
/messages/by-id/20221024220544.GJ16921@telsasoft.com
Kind Regards,
Peter Smith.
Fujitsu Australia
Attachments:
v3-0003-GUC-C-variable-sanity-check.patchapplication/octet-stream; name=v3-0003-GUC-C-variable-sanity-check.patchDownload
From 5f8cb9daba5e7b50e4b8fae8de101077bd2eac17 Mon Sep 17 00:00:00 2001
From: Peter Smith <peter.b.smith@fujitsu.com>
Date: Tue, 25 Oct 2022 14:30:41 +1100
Subject: [PATCH v3] GUC C variable sanity check
Added a function to perform a sanity-check comparison of the C variable initial
value with the compiled-in default (boot_val). The purpose of this is to prevent
anybody reading those C declarations from being fooled by mismatched values.
Also fixed some existing mismatching values.
Checking is skipped for GUCs flagged as compiler-dependent (GUC_DEFAULT_COMPILE).
---
src/backend/access/transam/xact.c | 2 +-
src/backend/access/transam/xlog.c | 2 +-
src/backend/libpq/be-secure.c | 4 +-
src/backend/utils/adt/xml.c | 4 +-
src/backend/utils/cache/plancache.c | 2 +-
src/backend/utils/error/elog.c | 2 +-
src/backend/utils/init/globals.c | 4 +-
src/backend/utils/misc/guc.c | 78 +++++++++++++++++++++++++++++++++++++
src/backend/utils/misc/guc_tables.c | 2 +-
9 files changed, 89 insertions(+), 11 deletions(-)
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index fd5103a..f45c95f 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -75,7 +75,7 @@
* User-tweakable parameters
*/
int DefaultXactIsoLevel = XACT_READ_COMMITTED;
-int XactIsoLevel;
+int XactIsoLevel = XACT_READ_COMMITTED;
bool DefaultXactReadOnly = false;
bool XactReadOnly;
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 8f10eff..be54c23 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -131,7 +131,7 @@ bool wal_init_zero = true;
bool wal_recycle = true;
bool log_checkpoints = true;
int sync_method = DEFAULT_SYNC_METHOD;
-int wal_level = WAL_LEVEL_MINIMAL;
+int wal_level = WAL_LEVEL_REPLICA;
int CommitDelay = 0; /* precommit delay in microseconds */
int CommitSiblings = 5; /* # concurrent xacts needed to sleep */
int wal_retrieve_retry_interval = 5000;
diff --git a/src/backend/libpq/be-secure.c b/src/backend/libpq/be-secure.c
index e3e5471..c896357 100644
--- a/src/backend/libpq/be-secure.c
+++ b/src/backend/libpq/be-secure.c
@@ -58,8 +58,8 @@ char *SSLECDHCurve;
/* GUC variable: if false, prefer client ciphers */
bool SSLPreferServerCiphers;
-int ssl_min_protocol_version;
-int ssl_max_protocol_version;
+int ssl_min_protocol_version = PG_TLS1_2_VERSION;
+int ssl_max_protocol_version = PG_TLS_ANY;
/* ------------------------------------------------------------ */
/* Procedures common to all secure sessions */
diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c
index d32cb11..8cd5262 100644
--- a/src/backend/utils/adt/xml.c
+++ b/src/backend/utils/adt/xml.c
@@ -94,8 +94,8 @@
/* GUC variables */
-int xmlbinary;
-int xmloption;
+int xmlbinary = XMLBINARY_BASE64;
+int xmloption = XMLOPTION_CONTENT;
#ifdef USE_LIBXML
diff --git a/src/backend/utils/cache/plancache.c b/src/backend/utils/cache/plancache.c
index 0d6a295..cc94320 100644
--- a/src/backend/utils/cache/plancache.c
+++ b/src/backend/utils/cache/plancache.c
@@ -116,7 +116,7 @@ static void PlanCacheObjectCallback(Datum arg, int cacheid, uint32 hashvalue);
static void PlanCacheSysCallback(Datum arg, int cacheid, uint32 hashvalue);
/* GUC parameter */
-int plan_cache_mode;
+int plan_cache_mode = PLAN_CACHE_MODE_AUTO;
/*
* InitPlanCache: initialize module during InitPostgres.
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 6e0a66c..2585e24 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -107,7 +107,7 @@ extern bool redirection_done;
emit_log_hook_type emit_log_hook = NULL;
/* GUC parameters */
-int Log_error_verbosity = PGERROR_VERBOSE;
+int Log_error_verbosity = PGERROR_DEFAULT;
char *Log_line_prefix = NULL; /* format for extra log line info */
int Log_destination = LOG_DESTINATION_STDERR;
char *Log_destination_string = NULL;
diff --git a/src/backend/utils/init/globals.c b/src/backend/utils/init/globals.c
index 1a5d29a..00bceec 100644
--- a/src/backend/utils/init/globals.c
+++ b/src/backend/utils/init/globals.c
@@ -133,8 +133,8 @@ int max_parallel_maintenance_workers = 2;
* MaxBackends is computed by PostmasterMain after modules have had a chance to
* register background workers.
*/
-int NBuffers = 1000;
-int MaxConnections = 90;
+int NBuffers = 16384;
+int MaxConnections = 100;
int max_worker_processes = 8;
int max_parallel_workers = 8;
int MaxBackends = 0;
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 6f21752..9e19a3e 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -1382,6 +1382,80 @@ check_GUC_name_for_parameter_acl(const char *name)
return false;
}
+#ifdef USE_ASSERT_CHECKING
+/*
+ * A GUC C variable can be declared with an initial value, but the GUC mechanism
+ * will overwrite that using the compiled-in default (boot_val) as per
+ * guc_tables.c.
+ *
+ * This function performs a sanity-check comparison of the C variable initial
+ * value with the boot_val, to prevent anybody reading those C declarations
+ * from being fooled by mismatched values.
+ *
+ * GUC C variable validation rules:
+ * bool - can be false, otherwise must be same as the boot_val
+ * int - can be 0, otherwise must be same as the boot_val
+ * real - can be 0.0, otherwise must be same as the boot_val
+ * string - can be NULL, otherwise must be strcmp equal to the boot_val
+ * enum - must be same as the boot_val
+ */
+static void
+sanity_check_GUC_C_var(struct config_generic *gconf)
+{
+ /* Skip checking for dynamic (compiler-dependent) GUCs. */
+ if (gconf->flags & GUC_DEFAULT_COMPILE)
+ return;
+
+ switch (gconf->vartype)
+ {
+ case PGC_BOOL:
+ {
+ struct config_bool *conf = (struct config_bool *) gconf;
+
+ if (*conf->variable && !conf->boot_val)
+ elog(FATAL, "GUC (PGC_BOOL) %s, boot_val=%d, C-var=%d",
+ conf->gen.name, conf->boot_val, *conf->variable);
+ break;
+ }
+ case PGC_INT:
+ {
+ struct config_int *conf = (struct config_int *) gconf;
+
+ if (*conf->variable != 0 && *conf->variable != conf->boot_val)
+ elog(FATAL, "GUC (PGC_INT) %s, boot_val=%d, C-var=%d",
+ conf->gen.name, conf->boot_val, *conf->variable);
+ break;
+ }
+ case PGC_REAL:
+ {
+ struct config_real *conf = (struct config_real *) gconf;
+
+ if (*conf->variable != 0.0 && *conf->variable != conf->boot_val)
+ elog(FATAL, "GUC (PGC_REAL) %s, boot_val=%g, C-var=%g",
+ conf->gen.name, conf->boot_val, *conf->variable);
+ break;
+ }
+ case PGC_STRING:
+ {
+ struct config_string *conf = (struct config_string *) gconf;
+
+ if (*conf->variable != NULL && strcmp(*conf->variable, conf->boot_val) != 0)
+ elog(FATAL, "GUC (PGC_STRING) %s, boot_val=%s, C-var=%s",
+ conf->gen.name, conf->boot_val ? conf->boot_val : "<null>", *conf->variable);
+ break;
+ }
+ case PGC_ENUM:
+ {
+ struct config_enum *conf = (struct config_enum *) gconf;
+
+ if (*conf->variable != conf->boot_val)
+ elog(FATAL, "GUC (PGC_ENUM) %s, boot_val=%d, C-var=%d",
+ conf->gen.name, conf->boot_val, *conf->variable);
+ break;
+ }
+ }
+}
+#endif
/*
* Initialize GUC options during program startup.
@@ -1413,6 +1487,10 @@ InitializeGUCOptions(void)
hash_seq_init(&status, guc_hashtab);
while ((hentry = (GUCHashEntry *) hash_seq_search(&status)) != NULL)
{
+#ifdef USE_ASSERT_CHECKING
+ sanity_check_GUC_C_var(hentry->gucvar);
+#endif
+
InitializeOneGUCOption(hentry->gucvar);
}
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 871be3e..0ff2b67 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -526,7 +526,7 @@ int ssl_renegotiation_limit;
* This really belongs in pg_shmem.c, but is defined here so that it doesn't
* need to be duplicated in all the different implementations of pg_shmem.c.
*/
-int huge_pages;
+int huge_pages = HUGE_PAGES_TRY;
int huge_page_size;
/*
--
1.8.3.1
v3-0001-GUC-tidy-some-C-variable-declarations.patchapplication/octet-stream; name=v3-0001-GUC-tidy-some-C-variable-declarations.patchDownload
From 841cd2e64b8a8033e2e2953a9b14da9401dd497c Mon Sep 17 00:00:00 2001
From: Peter Smith <peter.b.smith@fujitsu.com>
Date: Tue, 25 Oct 2022 10:10:58 +1100
Subject: [PATCH v3] GUC - tidy some C variable declarations.
---
src/backend/replication/logical/launcher.c | 1 +
src/backend/replication/slot.c | 6 +++---
src/backend/replication/walsender.c | 4 ++--
3 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/src/backend/replication/logical/launcher.c b/src/backend/replication/logical/launcher.c
index f2c55f3..c6d8376 100644
--- a/src/backend/replication/logical/launcher.c
+++ b/src/backend/replication/logical/launcher.c
@@ -52,6 +52,7 @@
/* max sleep time between cycles (3min) */
#define DEFAULT_NAPTIME_PER_CYCLE 180000L
+/* GUC variables. */
int max_logical_replication_workers = 4;
int max_sync_workers_per_subscription = 2;
diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c
index d58d16e..5b73aa1 100644
--- a/src/backend/replication/slot.c
+++ b/src/backend/replication/slot.c
@@ -97,9 +97,9 @@ ReplicationSlotCtlData *ReplicationSlotCtl = NULL;
/* My backend's replication slot in the shared memory array */
ReplicationSlot *MyReplicationSlot = NULL;
-/* GUCs */
-int max_replication_slots = 0; /* the maximum number of replication
- * slots */
+/* GUC variable. */
+int max_replication_slots = 10; /* the maximum number of replication
+ * slots */
static void ReplicationSlotShmemExit(int code, Datum arg);
static void ReplicationSlotDropAcquired(void);
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 2193dca..3faae4a 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -118,8 +118,8 @@ bool am_cascading_walsender = false; /* Am I cascading WAL to another
* standby? */
bool am_db_walsender = false; /* Connected to a database? */
-/* User-settable parameters for walsender */
-int max_wal_senders = 0; /* the maximum number of concurrent
+/* GUC variables. */
+int max_wal_senders = 10; /* the maximum number of concurrent
* walsenders */
int wal_sender_timeout = 60 * 1000; /* maximum time to send one WAL
* data message */
--
1.8.3.1
v3-0002-TMP-Justins-DYNAMIC_DEFAULT-patch.patchapplication/octet-stream; name=v3-0002-TMP-Justins-DYNAMIC_DEFAULT-patch.patchDownload
From 02abb26f30a262137b48d87945932d42342ff535 Mon Sep 17 00:00:00 2001
From: Peter Smith <peter.b.smith@fujitsu.com>
Date: Tue, 25 Oct 2022 11:07:56 +1100
Subject: [PATCH v3] TMP - Justins DYNAMIC_DEFAULT patch.
From 24/10 attachment: https://www.postgresql.org/message-id/20221024220544.GJ16921%40telsasoft.com
---
doc/src/sgml/func.sgml | 15 +++++++
src/backend/utils/misc/guc_funcs.c | 6 ++-
src/backend/utils/misc/guc_tables.c | 78 +++++++++++++++++++++++--------------
src/include/utils/guc.h | 2 +
4 files changed, 70 insertions(+), 31 deletions(-)
diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index 6e0425c..b8e0507 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -24374,6 +24374,21 @@ SELECT collation for ('foo' COLLATE "de_DE");
<row><entry>Flag</entry><entry>Description</entry></row>
</thead>
<tbody>
+
+ <row>
+ <entry><literal>DEFAULT_COMPILE</literal></entry>
+ <entry>Parameters with this flag have default values which vary by
+ platform, or compile-time options.
+ </entry>
+ </row>
+
+ <row>
+ <entry><literal>DEFAULT_INITDB</literal></entry>
+ <entry>Parameters with this flag have default values which are
+ determined dynamically during initdb.
+ </entry>
+ </row>
+
<row>
<entry><literal>EXPLAIN</literal></entry>
<entry>Parameters with this flag are included in
diff --git a/src/backend/utils/misc/guc_funcs.c b/src/backend/utils/misc/guc_funcs.c
index 108b3bd..2b666e8 100644
--- a/src/backend/utils/misc/guc_funcs.c
+++ b/src/backend/utils/misc/guc_funcs.c
@@ -538,7 +538,7 @@ ShowAllGUCConfig(DestReceiver *dest)
Datum
pg_settings_get_flags(PG_FUNCTION_ARGS)
{
-#define MAX_GUC_FLAGS 6
+#define MAX_GUC_FLAGS 8
char *varname = TextDatumGetCString(PG_GETARG_DATUM(0));
struct config_generic *record;
int cnt = 0;
@@ -551,6 +551,10 @@ pg_settings_get_flags(PG_FUNCTION_ARGS)
if (record == NULL)
PG_RETURN_NULL();
+ if (record->flags & GUC_DEFAULT_COMPILE)
+ flags[cnt++] = CStringGetTextDatum("DEFAULT_COMPILE");
+ if (record->flags & GUC_DEFAULT_INITDB)
+ flags[cnt++] = CStringGetTextDatum("DEFAULT_INITDB");
if (record->flags & GUC_EXPLAIN)
flags[cnt++] = CStringGetTextDatum("EXPLAIN");
if (record->flags & GUC_NO_RESET)
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 05ab087..871be3e 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -600,7 +600,7 @@ StaticAssertDecl(lengthof(GucContext_Names) == (PGC_USERSET + 1),
const char *const GucSource_Names[] =
{
/* PGC_S_DEFAULT */ "default",
- /* PGC_S_DYNAMIC_DEFAULT */ "default",
+ /* PGC_S_DYNAMIC_DEFAULT */ "default", //
/* PGC_S_ENV_VAR */ "environment variable",
/* PGC_S_FILE */ "configuration file",
/* PGC_S_ARGV */ "command line",
@@ -1178,7 +1178,7 @@ struct config_bool ConfigureNamesBool[] =
{"debug_assertions", PGC_INTERNAL, PRESET_OPTIONS,
gettext_noop("Shows whether the running server has assertion checks enabled."),
NULL,
- GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
+ GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_DEFAULT_COMPILE
},
&assert_enabled,
#ifdef USE_ASSERT_CHECKING
@@ -1354,7 +1354,8 @@ struct config_bool ConfigureNamesBool[] =
{
{"update_process_title", PGC_SUSET, PROCESS_TITLE,
gettext_noop("Updates the process title to show the active SQL command."),
- gettext_noop("Enables updating of the process title every time a new SQL command is received by the server.")
+ gettext_noop("Enables updating of the process title every time a new SQL command is received by the server."),
+ GUC_DEFAULT_COMPILE
},
&update_process_title,
#ifdef WIN32
@@ -2103,7 +2104,8 @@ struct config_int ConfigureNamesInt[] =
{
{"max_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
gettext_noop("Sets the maximum number of concurrent connections."),
- NULL
+ NULL,
+ GUC_DEFAULT_INITDB
},
&MaxConnections,
100, 1, MAX_BACKENDS,
@@ -2140,7 +2142,7 @@ struct config_int ConfigureNamesInt[] =
{"shared_buffers", PGC_POSTMASTER, RESOURCES_MEM,
gettext_noop("Sets the number of shared memory buffers used by the server."),
NULL,
- GUC_UNIT_BLOCKS
+ GUC_UNIT_BLOCKS | GUC_DEFAULT_INITDB
},
&NBuffers,
16384, 16, INT_MAX / 2,
@@ -2183,7 +2185,8 @@ struct config_int ConfigureNamesInt[] =
{
{"port", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
gettext_noop("Sets the TCP port the server listens on."),
- NULL
+ NULL,
+ GUC_DEFAULT_COMPILE
},
&PostPortNumber,
DEF_PGPORT, 1, 65535,
@@ -2212,7 +2215,8 @@ struct config_int ConfigureNamesInt[] =
"to be a numeric mode specification 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).)")
+ "start with a 0 (zero).)"),
+ GUC_DEFAULT_INITDB
},
&Log_file_mode,
0600, 0000, 0777,
@@ -2654,7 +2658,7 @@ struct config_int ConfigureNamesInt[] =
{"checkpoint_flush_after", PGC_SIGHUP, WAL_CHECKPOINTS,
gettext_noop("Number of pages after which previously performed writes are flushed to disk."),
NULL,
- GUC_UNIT_BLOCKS
+ GUC_UNIT_BLOCKS | GUC_DEFAULT_COMPILE
},
&checkpoint_flush_after,
DEFAULT_CHECKPOINT_FLUSH_AFTER, 0, WRITEBACK_MAX_PENDING_FLUSHES,
@@ -2872,7 +2876,7 @@ struct config_int ConfigureNamesInt[] =
{"bgwriter_flush_after", PGC_SIGHUP, RESOURCES_BGWRITER,
gettext_noop("Number of pages after which previously performed writes are flushed to disk."),
NULL,
- GUC_UNIT_BLOCKS
+ GUC_UNIT_BLOCKS | GUC_DEFAULT_COMPILE
},
&bgwriter_flush_after,
DEFAULT_BGWRITER_FLUSH_AFTER, 0, WRITEBACK_MAX_PENDING_FLUSHES,
@@ -2885,7 +2889,7 @@ struct config_int ConfigureNamesInt[] =
RESOURCES_ASYNCHRONOUS,
gettext_noop("Number of simultaneous requests that can be handled efficiently by the disk subsystem."),
NULL,
- GUC_EXPLAIN
+ GUC_EXPLAIN | GUC_DEFAULT_COMPILE
},
&effective_io_concurrency,
#ifdef USE_PREFETCH
@@ -2903,7 +2907,7 @@ struct config_int ConfigureNamesInt[] =
RESOURCES_ASYNCHRONOUS,
gettext_noop("A variant of effective_io_concurrency that is used for maintenance work."),
NULL,
- GUC_EXPLAIN
+ GUC_EXPLAIN | GUC_DEFAULT_COMPILE
},
&maintenance_io_concurrency,
#ifdef USE_PREFETCH
@@ -2920,7 +2924,7 @@ struct config_int ConfigureNamesInt[] =
{"backend_flush_after", PGC_USERSET, RESOURCES_ASYNCHRONOUS,
gettext_noop("Number of pages after which previously performed writes are flushed to disk."),
NULL,
- GUC_UNIT_BLOCKS
+ GUC_UNIT_BLOCKS | GUC_DEFAULT_COMPILE
},
&backend_flush_after,
DEFAULT_BACKEND_FLUSH_AFTER, 0, WRITEBACK_MAX_PENDING_FLUSHES,
@@ -3363,7 +3367,7 @@ struct config_int ConfigureNamesInt[] =
{"debug_discard_caches", PGC_SUSET, DEVELOPER_OPTIONS,
gettext_noop("Aggressively flush system caches for debugging purposes."),
NULL,
- GUC_NOT_IN_SAMPLE
+ GUC_NOT_IN_SAMPLE | GUC_DEFAULT_COMPILE
},
&debug_discard_caches,
#ifdef DISCARD_CACHES_ENABLED
@@ -3856,7 +3860,8 @@ struct config_string ConfigureNamesString[] =
{
{"log_timezone", PGC_SIGHUP, LOGGING_WHAT,
gettext_noop("Sets the time zone to use in log messages."),
- NULL
+ NULL,
+ GUC_DEFAULT_INITDB
},
&log_timezone_string,
"GMT",
@@ -3868,7 +3873,7 @@ struct config_string ConfigureNamesString[] =
gettext_noop("Sets the display format for date and time values."),
gettext_noop("Also controls interpretation of ambiguous "
"date inputs."),
- GUC_LIST_INPUT | GUC_REPORT
+ GUC_LIST_INPUT | GUC_REPORT | GUC_DEFAULT_INITDB
},
&datestyle_string,
"ISO, MDY",
@@ -3970,7 +3975,8 @@ struct config_string ConfigureNamesString[] =
{
{"lc_messages", PGC_SUSET, CLIENT_CONN_LOCALE,
gettext_noop("Sets the language in which messages are displayed."),
- NULL
+ NULL,
+ GUC_DEFAULT_INITDB
},
&locale_messages,
"",
@@ -3980,7 +3986,8 @@ struct config_string ConfigureNamesString[] =
{
{"lc_monetary", PGC_USERSET, CLIENT_CONN_LOCALE,
gettext_noop("Sets the locale for formatting monetary amounts."),
- NULL
+ NULL,
+ GUC_DEFAULT_INITDB
},
&locale_monetary,
"C",
@@ -3990,7 +3997,8 @@ struct config_string ConfigureNamesString[] =
{
{"lc_numeric", PGC_USERSET, CLIENT_CONN_LOCALE,
gettext_noop("Sets the locale for formatting numbers."),
- NULL
+ NULL,
+ GUC_DEFAULT_INITDB
},
&locale_numeric,
"C",
@@ -4000,7 +4008,8 @@ struct config_string ConfigureNamesString[] =
{
{"lc_time", PGC_USERSET, CLIENT_CONN_LOCALE,
gettext_noop("Sets the locale for formatting date and time values."),
- NULL
+ NULL,
+ GUC_DEFAULT_INITDB
},
&locale_time,
"C",
@@ -4159,7 +4168,8 @@ struct config_string ConfigureNamesString[] =
{"TimeZone", PGC_USERSET, CLIENT_CONN_LOCALE,
gettext_noop("Sets the time zone for displaying and interpreting time stamps."),
NULL,
- GUC_REPORT
+ GUC_REPORT | GUC_DEFAULT_INITDB
+
},
&timezone_string,
"GMT",
@@ -4190,7 +4200,7 @@ struct config_string ConfigureNamesString[] =
{"unix_socket_directories", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
gettext_noop("Sets the directories where Unix-domain sockets will be created."),
NULL,
- GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
+ GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY | GUC_DEFAULT_COMPILE
},
&Unix_socket_directories,
DEFAULT_PGSOCKET_DIR,
@@ -4271,7 +4281,7 @@ struct config_string ConfigureNamesString[] =
{"ssl_library", PGC_INTERNAL, PRESET_OPTIONS,
gettext_noop("Shows the name of the SSL library."),
NULL,
- GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
+ GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_DEFAULT_COMPILE
},
&ssl_library,
#ifdef USE_SSL
@@ -4346,7 +4356,9 @@ struct config_string ConfigureNamesString[] =
{
{"default_text_search_config", PGC_USERSET, CLIENT_CONN_LOCALE,
gettext_noop("Sets default text search configuration."),
- NULL
+ NULL,
+ GUC_DEFAULT_INITDB
+
},
&TSCurrentConfig,
"pg_catalog.simple",
@@ -4357,7 +4369,7 @@ struct config_string ConfigureNamesString[] =
{"ssl_ciphers", PGC_SIGHUP, CONN_AUTH_SSL,
gettext_noop("Sets the list of allowed SSL ciphers."),
NULL,
- GUC_SUPERUSER_ONLY
+ GUC_SUPERUSER_ONLY | GUC_DEFAULT_COMPILE
},
&SSLCipherSuites,
#ifdef USE_OPENSSL
@@ -4372,7 +4384,7 @@ struct config_string ConfigureNamesString[] =
{"ssl_ecdh_curve", PGC_SIGHUP, CONN_AUTH_SSL,
gettext_noop("Sets the curve to use for ECDH."),
NULL,
- GUC_SUPERUSER_ONLY
+ GUC_SUPERUSER_ONLY | GUC_DEFAULT_COMPILE
},
&SSLECDHCurve,
#ifdef USE_SSL
@@ -4610,7 +4622,8 @@ struct config_enum ConfigureNamesEnum[] =
{
{"syslog_facility", PGC_SIGHUP, LOGGING_WHERE,
gettext_noop("Sets the syslog \"facility\" to be used when syslog enabled."),
- NULL
+ NULL,
+ GUC_DEFAULT_COMPILE
},
&syslog_facility,
#ifdef HAVE_SYSLOG
@@ -4723,7 +4736,9 @@ struct config_enum ConfigureNamesEnum[] =
{
{"dynamic_shared_memory_type", PGC_POSTMASTER, RESOURCES_MEM,
gettext_noop("Selects the dynamic shared memory implementation used."),
- NULL
+ NULL,
+ /* platform-specific default, which is also overriden during initdb */
+ GUC_DEFAULT_COMPILE | GUC_DEFAULT_INITDB
},
&dynamic_shared_memory_type,
DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE, dynamic_shared_memory_options,
@@ -4733,7 +4748,8 @@ struct config_enum ConfigureNamesEnum[] =
{
{"shared_memory_type", PGC_POSTMASTER, RESOURCES_MEM,
gettext_noop("Selects the shared memory implementation used for the main shared memory region."),
- NULL
+ NULL,
+ GUC_DEFAULT_COMPILE
},
&shared_memory_type,
DEFAULT_SHARED_MEMORY_TYPE, shared_memory_options,
@@ -4743,7 +4759,8 @@ struct config_enum ConfigureNamesEnum[] =
{
{"wal_sync_method", PGC_SIGHUP, WAL_SETTINGS,
gettext_noop("Selects the method used for forcing WAL updates to disk."),
- NULL
+ NULL,
+ GUC_DEFAULT_COMPILE
},
&sync_method,
DEFAULT_SYNC_METHOD, sync_method_options,
@@ -4805,7 +4822,8 @@ struct config_enum ConfigureNamesEnum[] =
{
{"password_encryption", PGC_USERSET, CONN_AUTH_AUTH,
gettext_noop("Chooses the algorithm for encrypting passwords."),
- NULL
+ NULL,
+ GUC_DEFAULT_INITDB
},
&Password_encryption,
PASSWORD_TYPE_SCRAM_SHA_256, password_encryption_options,
diff --git a/src/include/utils/guc.h b/src/include/utils/guc.h
index b3aaff9..7905358 100644
--- a/src/include/utils/guc.h
+++ b/src/include/utils/guc.h
@@ -221,6 +221,8 @@ typedef enum
#define GUC_DISALLOW_IN_AUTO_FILE \
0x002000 /* can't set in PG_AUTOCONF_FILENAME */
#define GUC_RUNTIME_COMPUTED 0x004000 /* delay processing in 'postgres -C' */
+#define GUC_DEFAULT_COMPILE 0x008000 /* default is determined at compile time */
+#define GUC_DEFAULT_INITDB 0x010000 /* default is determined at during initdb */
#define GUC_UNIT_KB 0x01000000 /* value is in kilobytes */
#define GUC_UNIT_BLOCKS 0x02000000 /* value is in blocks */
--
1.8.3.1
On Tue, Oct 25, 2022 at 02:43:43PM +1100, Peter Smith wrote:
This is essentially the same as before except now, utilizing the
GUC_DEFAULT_COMPILE flag added by Justin's patch [1], the sanity-check
skips over any dynamic compiler-dependent GUCs.
Yeah, this is a self-reminder that I should try to look at what's on
the other thread.
Patch 0001 - GUC trivial mods to logical replication GUC C var declarations
This one seems fine, so done.
--
Michael
On Tue, Oct 25, 2022 at 4:09 PM Michael Paquier <michael@paquier.xyz> wrote:
On Tue, Oct 25, 2022 at 02:43:43PM +1100, Peter Smith wrote:
This is essentially the same as before except now, utilizing the
GUC_DEFAULT_COMPILE flag added by Justin's patch [1], the sanity-check
skips over any dynamic compiler-dependent GUCs.Yeah, this is a self-reminder that I should try to look at what's on
the other thread.Patch 0001 - GUC trivial mods to logical replication GUC C var declarations
This one seems fine, so done.
--
Thanks for pushing v3-0001.
PSA v4. Rebased the remaining 2 patches so the cfbot can still work.
------
Kind Regards,
Peter Smith.
Fujitsu Australia
Attachments:
v4-0001-TMP-Justins-DYNAMIC_DEFAULT-patch.patchapplication/octet-stream; name=v4-0001-TMP-Justins-DYNAMIC_DEFAULT-patch.patchDownload
From 896d322a671d395dd5b51572d6c91ce4759f0f99 Mon Sep 17 00:00:00 2001
From: Peter Smith <peter.b.smith@fujitsu.com>
Date: Tue, 25 Oct 2022 16:56:47 +1100
Subject: [PATCH v4] TMP - Justins DYNAMIC_DEFAULT patch.
From 24/10 attachment: https://www.postgresql.org/message-id/20221024220544.GJ16921%40telsasoft.com
---
doc/src/sgml/func.sgml | 15 +++++++
src/backend/utils/misc/guc_funcs.c | 6 ++-
src/backend/utils/misc/guc_tables.c | 78 +++++++++++++++++++++++--------------
src/include/utils/guc.h | 2 +
4 files changed, 70 insertions(+), 31 deletions(-)
diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index 6e0425c..b8e0507 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -24374,6 +24374,21 @@ SELECT collation for ('foo' COLLATE "de_DE");
<row><entry>Flag</entry><entry>Description</entry></row>
</thead>
<tbody>
+
+ <row>
+ <entry><literal>DEFAULT_COMPILE</literal></entry>
+ <entry>Parameters with this flag have default values which vary by
+ platform, or compile-time options.
+ </entry>
+ </row>
+
+ <row>
+ <entry><literal>DEFAULT_INITDB</literal></entry>
+ <entry>Parameters with this flag have default values which are
+ determined dynamically during initdb.
+ </entry>
+ </row>
+
<row>
<entry><literal>EXPLAIN</literal></entry>
<entry>Parameters with this flag are included in
diff --git a/src/backend/utils/misc/guc_funcs.c b/src/backend/utils/misc/guc_funcs.c
index 108b3bd..2b666e8 100644
--- a/src/backend/utils/misc/guc_funcs.c
+++ b/src/backend/utils/misc/guc_funcs.c
@@ -538,7 +538,7 @@ ShowAllGUCConfig(DestReceiver *dest)
Datum
pg_settings_get_flags(PG_FUNCTION_ARGS)
{
-#define MAX_GUC_FLAGS 6
+#define MAX_GUC_FLAGS 8
char *varname = TextDatumGetCString(PG_GETARG_DATUM(0));
struct config_generic *record;
int cnt = 0;
@@ -551,6 +551,10 @@ pg_settings_get_flags(PG_FUNCTION_ARGS)
if (record == NULL)
PG_RETURN_NULL();
+ if (record->flags & GUC_DEFAULT_COMPILE)
+ flags[cnt++] = CStringGetTextDatum("DEFAULT_COMPILE");
+ if (record->flags & GUC_DEFAULT_INITDB)
+ flags[cnt++] = CStringGetTextDatum("DEFAULT_INITDB");
if (record->flags & GUC_EXPLAIN)
flags[cnt++] = CStringGetTextDatum("EXPLAIN");
if (record->flags & GUC_NO_RESET)
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 05ab087..871be3e 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -600,7 +600,7 @@ StaticAssertDecl(lengthof(GucContext_Names) == (PGC_USERSET + 1),
const char *const GucSource_Names[] =
{
/* PGC_S_DEFAULT */ "default",
- /* PGC_S_DYNAMIC_DEFAULT */ "default",
+ /* PGC_S_DYNAMIC_DEFAULT */ "default", //
/* PGC_S_ENV_VAR */ "environment variable",
/* PGC_S_FILE */ "configuration file",
/* PGC_S_ARGV */ "command line",
@@ -1178,7 +1178,7 @@ struct config_bool ConfigureNamesBool[] =
{"debug_assertions", PGC_INTERNAL, PRESET_OPTIONS,
gettext_noop("Shows whether the running server has assertion checks enabled."),
NULL,
- GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
+ GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_DEFAULT_COMPILE
},
&assert_enabled,
#ifdef USE_ASSERT_CHECKING
@@ -1354,7 +1354,8 @@ struct config_bool ConfigureNamesBool[] =
{
{"update_process_title", PGC_SUSET, PROCESS_TITLE,
gettext_noop("Updates the process title to show the active SQL command."),
- gettext_noop("Enables updating of the process title every time a new SQL command is received by the server.")
+ gettext_noop("Enables updating of the process title every time a new SQL command is received by the server."),
+ GUC_DEFAULT_COMPILE
},
&update_process_title,
#ifdef WIN32
@@ -2103,7 +2104,8 @@ struct config_int ConfigureNamesInt[] =
{
{"max_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
gettext_noop("Sets the maximum number of concurrent connections."),
- NULL
+ NULL,
+ GUC_DEFAULT_INITDB
},
&MaxConnections,
100, 1, MAX_BACKENDS,
@@ -2140,7 +2142,7 @@ struct config_int ConfigureNamesInt[] =
{"shared_buffers", PGC_POSTMASTER, RESOURCES_MEM,
gettext_noop("Sets the number of shared memory buffers used by the server."),
NULL,
- GUC_UNIT_BLOCKS
+ GUC_UNIT_BLOCKS | GUC_DEFAULT_INITDB
},
&NBuffers,
16384, 16, INT_MAX / 2,
@@ -2183,7 +2185,8 @@ struct config_int ConfigureNamesInt[] =
{
{"port", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
gettext_noop("Sets the TCP port the server listens on."),
- NULL
+ NULL,
+ GUC_DEFAULT_COMPILE
},
&PostPortNumber,
DEF_PGPORT, 1, 65535,
@@ -2212,7 +2215,8 @@ struct config_int ConfigureNamesInt[] =
"to be a numeric mode specification 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).)")
+ "start with a 0 (zero).)"),
+ GUC_DEFAULT_INITDB
},
&Log_file_mode,
0600, 0000, 0777,
@@ -2654,7 +2658,7 @@ struct config_int ConfigureNamesInt[] =
{"checkpoint_flush_after", PGC_SIGHUP, WAL_CHECKPOINTS,
gettext_noop("Number of pages after which previously performed writes are flushed to disk."),
NULL,
- GUC_UNIT_BLOCKS
+ GUC_UNIT_BLOCKS | GUC_DEFAULT_COMPILE
},
&checkpoint_flush_after,
DEFAULT_CHECKPOINT_FLUSH_AFTER, 0, WRITEBACK_MAX_PENDING_FLUSHES,
@@ -2872,7 +2876,7 @@ struct config_int ConfigureNamesInt[] =
{"bgwriter_flush_after", PGC_SIGHUP, RESOURCES_BGWRITER,
gettext_noop("Number of pages after which previously performed writes are flushed to disk."),
NULL,
- GUC_UNIT_BLOCKS
+ GUC_UNIT_BLOCKS | GUC_DEFAULT_COMPILE
},
&bgwriter_flush_after,
DEFAULT_BGWRITER_FLUSH_AFTER, 0, WRITEBACK_MAX_PENDING_FLUSHES,
@@ -2885,7 +2889,7 @@ struct config_int ConfigureNamesInt[] =
RESOURCES_ASYNCHRONOUS,
gettext_noop("Number of simultaneous requests that can be handled efficiently by the disk subsystem."),
NULL,
- GUC_EXPLAIN
+ GUC_EXPLAIN | GUC_DEFAULT_COMPILE
},
&effective_io_concurrency,
#ifdef USE_PREFETCH
@@ -2903,7 +2907,7 @@ struct config_int ConfigureNamesInt[] =
RESOURCES_ASYNCHRONOUS,
gettext_noop("A variant of effective_io_concurrency that is used for maintenance work."),
NULL,
- GUC_EXPLAIN
+ GUC_EXPLAIN | GUC_DEFAULT_COMPILE
},
&maintenance_io_concurrency,
#ifdef USE_PREFETCH
@@ -2920,7 +2924,7 @@ struct config_int ConfigureNamesInt[] =
{"backend_flush_after", PGC_USERSET, RESOURCES_ASYNCHRONOUS,
gettext_noop("Number of pages after which previously performed writes are flushed to disk."),
NULL,
- GUC_UNIT_BLOCKS
+ GUC_UNIT_BLOCKS | GUC_DEFAULT_COMPILE
},
&backend_flush_after,
DEFAULT_BACKEND_FLUSH_AFTER, 0, WRITEBACK_MAX_PENDING_FLUSHES,
@@ -3363,7 +3367,7 @@ struct config_int ConfigureNamesInt[] =
{"debug_discard_caches", PGC_SUSET, DEVELOPER_OPTIONS,
gettext_noop("Aggressively flush system caches for debugging purposes."),
NULL,
- GUC_NOT_IN_SAMPLE
+ GUC_NOT_IN_SAMPLE | GUC_DEFAULT_COMPILE
},
&debug_discard_caches,
#ifdef DISCARD_CACHES_ENABLED
@@ -3856,7 +3860,8 @@ struct config_string ConfigureNamesString[] =
{
{"log_timezone", PGC_SIGHUP, LOGGING_WHAT,
gettext_noop("Sets the time zone to use in log messages."),
- NULL
+ NULL,
+ GUC_DEFAULT_INITDB
},
&log_timezone_string,
"GMT",
@@ -3868,7 +3873,7 @@ struct config_string ConfigureNamesString[] =
gettext_noop("Sets the display format for date and time values."),
gettext_noop("Also controls interpretation of ambiguous "
"date inputs."),
- GUC_LIST_INPUT | GUC_REPORT
+ GUC_LIST_INPUT | GUC_REPORT | GUC_DEFAULT_INITDB
},
&datestyle_string,
"ISO, MDY",
@@ -3970,7 +3975,8 @@ struct config_string ConfigureNamesString[] =
{
{"lc_messages", PGC_SUSET, CLIENT_CONN_LOCALE,
gettext_noop("Sets the language in which messages are displayed."),
- NULL
+ NULL,
+ GUC_DEFAULT_INITDB
},
&locale_messages,
"",
@@ -3980,7 +3986,8 @@ struct config_string ConfigureNamesString[] =
{
{"lc_monetary", PGC_USERSET, CLIENT_CONN_LOCALE,
gettext_noop("Sets the locale for formatting monetary amounts."),
- NULL
+ NULL,
+ GUC_DEFAULT_INITDB
},
&locale_monetary,
"C",
@@ -3990,7 +3997,8 @@ struct config_string ConfigureNamesString[] =
{
{"lc_numeric", PGC_USERSET, CLIENT_CONN_LOCALE,
gettext_noop("Sets the locale for formatting numbers."),
- NULL
+ NULL,
+ GUC_DEFAULT_INITDB
},
&locale_numeric,
"C",
@@ -4000,7 +4008,8 @@ struct config_string ConfigureNamesString[] =
{
{"lc_time", PGC_USERSET, CLIENT_CONN_LOCALE,
gettext_noop("Sets the locale for formatting date and time values."),
- NULL
+ NULL,
+ GUC_DEFAULT_INITDB
},
&locale_time,
"C",
@@ -4159,7 +4168,8 @@ struct config_string ConfigureNamesString[] =
{"TimeZone", PGC_USERSET, CLIENT_CONN_LOCALE,
gettext_noop("Sets the time zone for displaying and interpreting time stamps."),
NULL,
- GUC_REPORT
+ GUC_REPORT | GUC_DEFAULT_INITDB
+
},
&timezone_string,
"GMT",
@@ -4190,7 +4200,7 @@ struct config_string ConfigureNamesString[] =
{"unix_socket_directories", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
gettext_noop("Sets the directories where Unix-domain sockets will be created."),
NULL,
- GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
+ GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY | GUC_DEFAULT_COMPILE
},
&Unix_socket_directories,
DEFAULT_PGSOCKET_DIR,
@@ -4271,7 +4281,7 @@ struct config_string ConfigureNamesString[] =
{"ssl_library", PGC_INTERNAL, PRESET_OPTIONS,
gettext_noop("Shows the name of the SSL library."),
NULL,
- GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
+ GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_DEFAULT_COMPILE
},
&ssl_library,
#ifdef USE_SSL
@@ -4346,7 +4356,9 @@ struct config_string ConfigureNamesString[] =
{
{"default_text_search_config", PGC_USERSET, CLIENT_CONN_LOCALE,
gettext_noop("Sets default text search configuration."),
- NULL
+ NULL,
+ GUC_DEFAULT_INITDB
+
},
&TSCurrentConfig,
"pg_catalog.simple",
@@ -4357,7 +4369,7 @@ struct config_string ConfigureNamesString[] =
{"ssl_ciphers", PGC_SIGHUP, CONN_AUTH_SSL,
gettext_noop("Sets the list of allowed SSL ciphers."),
NULL,
- GUC_SUPERUSER_ONLY
+ GUC_SUPERUSER_ONLY | GUC_DEFAULT_COMPILE
},
&SSLCipherSuites,
#ifdef USE_OPENSSL
@@ -4372,7 +4384,7 @@ struct config_string ConfigureNamesString[] =
{"ssl_ecdh_curve", PGC_SIGHUP, CONN_AUTH_SSL,
gettext_noop("Sets the curve to use for ECDH."),
NULL,
- GUC_SUPERUSER_ONLY
+ GUC_SUPERUSER_ONLY | GUC_DEFAULT_COMPILE
},
&SSLECDHCurve,
#ifdef USE_SSL
@@ -4610,7 +4622,8 @@ struct config_enum ConfigureNamesEnum[] =
{
{"syslog_facility", PGC_SIGHUP, LOGGING_WHERE,
gettext_noop("Sets the syslog \"facility\" to be used when syslog enabled."),
- NULL
+ NULL,
+ GUC_DEFAULT_COMPILE
},
&syslog_facility,
#ifdef HAVE_SYSLOG
@@ -4723,7 +4736,9 @@ struct config_enum ConfigureNamesEnum[] =
{
{"dynamic_shared_memory_type", PGC_POSTMASTER, RESOURCES_MEM,
gettext_noop("Selects the dynamic shared memory implementation used."),
- NULL
+ NULL,
+ /* platform-specific default, which is also overriden during initdb */
+ GUC_DEFAULT_COMPILE | GUC_DEFAULT_INITDB
},
&dynamic_shared_memory_type,
DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE, dynamic_shared_memory_options,
@@ -4733,7 +4748,8 @@ struct config_enum ConfigureNamesEnum[] =
{
{"shared_memory_type", PGC_POSTMASTER, RESOURCES_MEM,
gettext_noop("Selects the shared memory implementation used for the main shared memory region."),
- NULL
+ NULL,
+ GUC_DEFAULT_COMPILE
},
&shared_memory_type,
DEFAULT_SHARED_MEMORY_TYPE, shared_memory_options,
@@ -4743,7 +4759,8 @@ struct config_enum ConfigureNamesEnum[] =
{
{"wal_sync_method", PGC_SIGHUP, WAL_SETTINGS,
gettext_noop("Selects the method used for forcing WAL updates to disk."),
- NULL
+ NULL,
+ GUC_DEFAULT_COMPILE
},
&sync_method,
DEFAULT_SYNC_METHOD, sync_method_options,
@@ -4805,7 +4822,8 @@ struct config_enum ConfigureNamesEnum[] =
{
{"password_encryption", PGC_USERSET, CONN_AUTH_AUTH,
gettext_noop("Chooses the algorithm for encrypting passwords."),
- NULL
+ NULL,
+ GUC_DEFAULT_INITDB
},
&Password_encryption,
PASSWORD_TYPE_SCRAM_SHA_256, password_encryption_options,
diff --git a/src/include/utils/guc.h b/src/include/utils/guc.h
index b3aaff9..7905358 100644
--- a/src/include/utils/guc.h
+++ b/src/include/utils/guc.h
@@ -221,6 +221,8 @@ typedef enum
#define GUC_DISALLOW_IN_AUTO_FILE \
0x002000 /* can't set in PG_AUTOCONF_FILENAME */
#define GUC_RUNTIME_COMPUTED 0x004000 /* delay processing in 'postgres -C' */
+#define GUC_DEFAULT_COMPILE 0x008000 /* default is determined at compile time */
+#define GUC_DEFAULT_INITDB 0x010000 /* default is determined at during initdb */
#define GUC_UNIT_KB 0x01000000 /* value is in kilobytes */
#define GUC_UNIT_BLOCKS 0x02000000 /* value is in blocks */
--
1.8.3.1
v4-0002-GUC-C-variable-sanity-check.patchapplication/octet-stream; name=v4-0002-GUC-C-variable-sanity-check.patchDownload
From d8fea6973cec7aad20e9fbb2afe9a19d579bb04b Mon Sep 17 00:00:00 2001
From: Peter Smith <peter.b.smith@fujitsu.com>
Date: Tue, 25 Oct 2022 16:57:32 +1100
Subject: [PATCH v4] GUC C variable sanity check
Added a function to perform a sanity-check comparison of the C variable initial
value with the compiled-in default (boot_val). The purpose of this is to prevent
anybody reading those C declarations from being fooled by mismatched values.
Also fixed some existing mismatching values.
Checking is skipped for GUCs flagged as compiler-dependent (GUC_DEFAULT_COMPILE).
---
src/backend/access/transam/xact.c | 2 +-
src/backend/access/transam/xlog.c | 2 +-
src/backend/libpq/be-secure.c | 4 +-
src/backend/utils/adt/xml.c | 4 +-
src/backend/utils/cache/plancache.c | 2 +-
src/backend/utils/error/elog.c | 2 +-
src/backend/utils/init/globals.c | 4 +-
src/backend/utils/misc/guc.c | 78 +++++++++++++++++++++++++++++++++++++
src/backend/utils/misc/guc_tables.c | 2 +-
9 files changed, 89 insertions(+), 11 deletions(-)
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index fd5103a..f45c95f 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -75,7 +75,7 @@
* User-tweakable parameters
*/
int DefaultXactIsoLevel = XACT_READ_COMMITTED;
-int XactIsoLevel;
+int XactIsoLevel = XACT_READ_COMMITTED;
bool DefaultXactReadOnly = false;
bool XactReadOnly;
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 8f10eff..be54c23 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -131,7 +131,7 @@ bool wal_init_zero = true;
bool wal_recycle = true;
bool log_checkpoints = true;
int sync_method = DEFAULT_SYNC_METHOD;
-int wal_level = WAL_LEVEL_MINIMAL;
+int wal_level = WAL_LEVEL_REPLICA;
int CommitDelay = 0; /* precommit delay in microseconds */
int CommitSiblings = 5; /* # concurrent xacts needed to sleep */
int wal_retrieve_retry_interval = 5000;
diff --git a/src/backend/libpq/be-secure.c b/src/backend/libpq/be-secure.c
index e3e5471..c896357 100644
--- a/src/backend/libpq/be-secure.c
+++ b/src/backend/libpq/be-secure.c
@@ -58,8 +58,8 @@ char *SSLECDHCurve;
/* GUC variable: if false, prefer client ciphers */
bool SSLPreferServerCiphers;
-int ssl_min_protocol_version;
-int ssl_max_protocol_version;
+int ssl_min_protocol_version = PG_TLS1_2_VERSION;
+int ssl_max_protocol_version = PG_TLS_ANY;
/* ------------------------------------------------------------ */
/* Procedures common to all secure sessions */
diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c
index d32cb11..8cd5262 100644
--- a/src/backend/utils/adt/xml.c
+++ b/src/backend/utils/adt/xml.c
@@ -94,8 +94,8 @@
/* GUC variables */
-int xmlbinary;
-int xmloption;
+int xmlbinary = XMLBINARY_BASE64;
+int xmloption = XMLOPTION_CONTENT;
#ifdef USE_LIBXML
diff --git a/src/backend/utils/cache/plancache.c b/src/backend/utils/cache/plancache.c
index 0d6a295..cc94320 100644
--- a/src/backend/utils/cache/plancache.c
+++ b/src/backend/utils/cache/plancache.c
@@ -116,7 +116,7 @@ static void PlanCacheObjectCallback(Datum arg, int cacheid, uint32 hashvalue);
static void PlanCacheSysCallback(Datum arg, int cacheid, uint32 hashvalue);
/* GUC parameter */
-int plan_cache_mode;
+int plan_cache_mode = PLAN_CACHE_MODE_AUTO;
/*
* InitPlanCache: initialize module during InitPostgres.
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 6e0a66c..2585e24 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -107,7 +107,7 @@ extern bool redirection_done;
emit_log_hook_type emit_log_hook = NULL;
/* GUC parameters */
-int Log_error_verbosity = PGERROR_VERBOSE;
+int Log_error_verbosity = PGERROR_DEFAULT;
char *Log_line_prefix = NULL; /* format for extra log line info */
int Log_destination = LOG_DESTINATION_STDERR;
char *Log_destination_string = NULL;
diff --git a/src/backend/utils/init/globals.c b/src/backend/utils/init/globals.c
index 1a5d29a..00bceec 100644
--- a/src/backend/utils/init/globals.c
+++ b/src/backend/utils/init/globals.c
@@ -133,8 +133,8 @@ int max_parallel_maintenance_workers = 2;
* MaxBackends is computed by PostmasterMain after modules have had a chance to
* register background workers.
*/
-int NBuffers = 1000;
-int MaxConnections = 90;
+int NBuffers = 16384;
+int MaxConnections = 100;
int max_worker_processes = 8;
int max_parallel_workers = 8;
int MaxBackends = 0;
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 6f21752..9e19a3e 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -1382,6 +1382,80 @@ check_GUC_name_for_parameter_acl(const char *name)
return false;
}
+#ifdef USE_ASSERT_CHECKING
+/*
+ * A GUC C variable can be declared with an initial value, but the GUC mechanism
+ * will overwrite that using the compiled-in default (boot_val) as per
+ * guc_tables.c.
+ *
+ * This function performs a sanity-check comparison of the C variable initial
+ * value with the boot_val, to prevent anybody reading those C declarations
+ * from being fooled by mismatched values.
+ *
+ * GUC C variable validation rules:
+ * bool - can be false, otherwise must be same as the boot_val
+ * int - can be 0, otherwise must be same as the boot_val
+ * real - can be 0.0, otherwise must be same as the boot_val
+ * string - can be NULL, otherwise must be strcmp equal to the boot_val
+ * enum - must be same as the boot_val
+ */
+static void
+sanity_check_GUC_C_var(struct config_generic *gconf)
+{
+ /* Skip checking for dynamic (compiler-dependent) GUCs. */
+ if (gconf->flags & GUC_DEFAULT_COMPILE)
+ return;
+
+ switch (gconf->vartype)
+ {
+ case PGC_BOOL:
+ {
+ struct config_bool *conf = (struct config_bool *) gconf;
+
+ if (*conf->variable && !conf->boot_val)
+ elog(FATAL, "GUC (PGC_BOOL) %s, boot_val=%d, C-var=%d",
+ conf->gen.name, conf->boot_val, *conf->variable);
+ break;
+ }
+ case PGC_INT:
+ {
+ struct config_int *conf = (struct config_int *) gconf;
+
+ if (*conf->variable != 0 && *conf->variable != conf->boot_val)
+ elog(FATAL, "GUC (PGC_INT) %s, boot_val=%d, C-var=%d",
+ conf->gen.name, conf->boot_val, *conf->variable);
+ break;
+ }
+ case PGC_REAL:
+ {
+ struct config_real *conf = (struct config_real *) gconf;
+
+ if (*conf->variable != 0.0 && *conf->variable != conf->boot_val)
+ elog(FATAL, "GUC (PGC_REAL) %s, boot_val=%g, C-var=%g",
+ conf->gen.name, conf->boot_val, *conf->variable);
+ break;
+ }
+ case PGC_STRING:
+ {
+ struct config_string *conf = (struct config_string *) gconf;
+
+ if (*conf->variable != NULL && strcmp(*conf->variable, conf->boot_val) != 0)
+ elog(FATAL, "GUC (PGC_STRING) %s, boot_val=%s, C-var=%s",
+ conf->gen.name, conf->boot_val ? conf->boot_val : "<null>", *conf->variable);
+ break;
+ }
+ case PGC_ENUM:
+ {
+ struct config_enum *conf = (struct config_enum *) gconf;
+
+ if (*conf->variable != conf->boot_val)
+ elog(FATAL, "GUC (PGC_ENUM) %s, boot_val=%d, C-var=%d",
+ conf->gen.name, conf->boot_val, *conf->variable);
+ break;
+ }
+ }
+}
+#endif
/*
* Initialize GUC options during program startup.
@@ -1413,6 +1487,10 @@ InitializeGUCOptions(void)
hash_seq_init(&status, guc_hashtab);
while ((hentry = (GUCHashEntry *) hash_seq_search(&status)) != NULL)
{
+#ifdef USE_ASSERT_CHECKING
+ sanity_check_GUC_C_var(hentry->gucvar);
+#endif
+
InitializeOneGUCOption(hentry->gucvar);
}
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 871be3e..0ff2b67 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -526,7 +526,7 @@ int ssl_renegotiation_limit;
* This really belongs in pg_shmem.c, but is defined here so that it doesn't
* need to be duplicated in all the different implementations of pg_shmem.c.
*/
-int huge_pages;
+int huge_pages = HUGE_PAGES_TRY;
int huge_page_size;
/*
--
1.8.3.1
+#ifdef USE_ASSERT_CHECKING
+ sanity_check_GUC_C_var(hentry->gucvar);
+#endif
=> You can conditionally define that as an empty function so #ifdefs
aren't needed in the caller:
void sanity_check_GUC_C_var()
{
#ifdef USE_ASSERT_CHECKING
...
#endif
}
+ /* Skip checking for dynamic (compiler-dependent) GUCs. */
=> This should say that the GUC's default is determined at compile-time.
But actually, I don't think you should use my patch. You needed to
exclude update_process_title:
src/backend/utils/misc/ps_status.c:bool update_process_title = true;
...
src/backend/utils/misc/guc_tables.c-#ifdef WIN32
src/backend/utils/misc/guc_tables.c- false,
src/backend/utils/misc/guc_tables.c-#else
src/backend/utils/misc/guc_tables.c- true,
src/backend/utils/misc/guc_tables.c-#endif
src/backend/utils/misc/guc_tables.c- NULL, NULL, NULL
My patch would also exclude the 16 other GUCs with compile-time defaults
from your check. It'd be better not to exclude them; I think the right
solution is to change the C variable initialization to a compile-time
constant:
#ifdef WIN32
bool update_process_title = false;
#else
bool update_process_title = true;
#endif
Or something more indirect like:
#ifdef WIN32
#define DEFAULT_PROCESS_TITLE false
#else
#define DEFAULT_PROCESS_TITLE true
#endif
bool update_process_title = DEFAULT_PROCESS_TITLE;
I suspect there's not many GUCs that would need to change - this might
be the only one. If this GUC were defined in the inverse (bool
skip_process_title), it wouldn't need special help, either.
--
Justin
Thanks for the feedback. PSA the v5 patch.
On Wed, Oct 26, 2022 at 7:04 AM Justin Pryzby <pryzby@telsasoft.com> wrote:
+#ifdef USE_ASSERT_CHECKING + sanity_check_GUC_C_var(hentry->gucvar); +#endif=> You can conditionally define that as an empty function so #ifdefs
aren't needed in the caller:void sanity_check_GUC_C_var()
{
#ifdef USE_ASSERT_CHECKING
...
#endif
}
Fixed as suggested.
But actually, I don't think you should use my patch. You needed to
exclude update_process_title:src/backend/utils/misc/ps_status.c:bool update_process_title = true;
...
src/backend/utils/misc/guc_tables.c-#ifdef WIN32
src/backend/utils/misc/guc_tables.c- false,
src/backend/utils/misc/guc_tables.c-#else
src/backend/utils/misc/guc_tables.c- true,
src/backend/utils/misc/guc_tables.c-#endif
src/backend/utils/misc/guc_tables.c- NULL, NULL, NULLMy patch would also exclude the 16 other GUCs with compile-time defaults
from your check. It'd be better not to exclude them; I think the right
solution is to change the C variable initialization to a compile-time
constant:#ifdef WIN32
bool update_process_title = false;
#else
bool update_process_title = true;
#endifOr something more indirect like:
#ifdef WIN32
#define DEFAULT_PROCESS_TITLE false
#else
#define DEFAULT_PROCESS_TITLE true
#endifbool update_process_title = DEFAULT_PROCESS_TITLE;
I suspect there's not many GUCs that would need to change - this might
be the only one. If this GUC were defined in the inverse (bool
skip_process_title), it wouldn't need special help, either.
I re-checked all the GUC C vars which your patch flags as
GUC_DEFAULT_COMPILE. For some of them, where it was not any trouble, I
made the C var assignment use the same preprocessor rules as used by
guc_tables. For others (mostly the string ones) I left the GUC C var
untouched because the sanity checker function already has a rule not
to complain about int GUC C vars which are 0 or string GUC vars which
are NULL.
------
Kind Regards,
Peter Smith.
Fujitsu Australia
Attachments:
v5-0001-GUC-C-variable-sanity-check.patchapplication/octet-stream; name=v5-0001-GUC-C-variable-sanity-check.patchDownload
From b3ca1502ede271f68d7db8e8273bee355ce7e0f1 Mon Sep 17 00:00:00 2001
From: Peter Smith <peter.b.smith@fujitsu.com>
Date: Wed, 26 Oct 2022 18:25:08 +1100
Subject: [PATCH v5] GUC C variable sanity check
Added a function to perform a sanity-check comparison of the C variable initial
value with the compiled-in default (boot_val). The purpose of this is to prevent
anybody reading those C declarations from being fooled by mismatched values.
Also fixed some existing mismatching values.
---
src/backend/access/transam/xact.c | 2 +-
src/backend/access/transam/xlog.c | 2 +-
src/backend/libpq/be-secure.c | 4 +--
src/backend/postmaster/postmaster.c | 2 +-
src/backend/storage/buffer/bufmgr.c | 20 ++++++++---
src/backend/storage/ipc/dsm_impl.c | 2 +-
src/backend/utils/adt/xml.c | 4 +--
src/backend/utils/cache/plancache.c | 2 +-
src/backend/utils/error/elog.c | 2 +-
src/backend/utils/init/globals.c | 4 +--
src/backend/utils/misc/guc.c | 72 +++++++++++++++++++++++++++++++++++++
src/backend/utils/misc/guc_tables.c | 19 ++++++++--
src/backend/utils/misc/ps_status.c | 8 ++++-
13 files changed, 122 insertions(+), 21 deletions(-)
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index fd5103a..f45c95f 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -75,7 +75,7 @@
* User-tweakable parameters
*/
int DefaultXactIsoLevel = XACT_READ_COMMITTED;
-int XactIsoLevel;
+int XactIsoLevel = XACT_READ_COMMITTED;
bool DefaultXactReadOnly = false;
bool XactReadOnly;
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 8f10eff..be54c23 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -131,7 +131,7 @@ bool wal_init_zero = true;
bool wal_recycle = true;
bool log_checkpoints = true;
int sync_method = DEFAULT_SYNC_METHOD;
-int wal_level = WAL_LEVEL_MINIMAL;
+int wal_level = WAL_LEVEL_REPLICA;
int CommitDelay = 0; /* precommit delay in microseconds */
int CommitSiblings = 5; /* # concurrent xacts needed to sleep */
int wal_retrieve_retry_interval = 5000;
diff --git a/src/backend/libpq/be-secure.c b/src/backend/libpq/be-secure.c
index e3e5471..c896357 100644
--- a/src/backend/libpq/be-secure.c
+++ b/src/backend/libpq/be-secure.c
@@ -58,8 +58,8 @@ char *SSLECDHCurve;
/* GUC variable: if false, prefer client ciphers */
bool SSLPreferServerCiphers;
-int ssl_min_protocol_version;
-int ssl_max_protocol_version;
+int ssl_min_protocol_version = PG_TLS1_2_VERSION;
+int ssl_max_protocol_version = PG_TLS_ANY;
/* ------------------------------------------------------------ */
/* Procedures common to all secure sessions */
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 30fb576..0b637ba 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -196,7 +196,7 @@ BackgroundWorker *MyBgworkerEntry = NULL;
/* The socket number we are listening for connections on */
-int PostPortNumber;
+int PostPortNumber = DEF_PGPORT;
/* The directory names for Unix socket(s) */
char *Unix_socket_directories;
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c
index 6b95381..e5d31e8 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -142,22 +142,32 @@ bool track_io_timing = false;
* for buffers not belonging to tablespaces that have their
* effective_io_concurrency parameter set.
*/
-int effective_io_concurrency = 0;
+int effective_io_concurrency =
+#ifdef USE_PREFETCH
+ 1;
+#else
+ 0;
+#endif
/*
* Like effective_io_concurrency, but used by maintenance code paths that might
* benefit from a higher setting because they work on behalf of many sessions.
* Overridden by the tablespace setting of the same name.
*/
-int maintenance_io_concurrency = 0;
+int maintenance_io_concurrency =
+#ifdef USE_PREFETCH
+ 10;
+#else
+ 0;
+#endif
/*
* GUC variables about triggering kernel writeback for buffers written; OS
* dependent defaults are set via the GUC mechanism.
*/
-int checkpoint_flush_after = 0;
-int bgwriter_flush_after = 0;
-int backend_flush_after = 0;
+int checkpoint_flush_after = DEFAULT_CHECKPOINT_FLUSH_AFTER;
+int bgwriter_flush_after = DEFAULT_BGWRITER_FLUSH_AFTER;
+int backend_flush_after = DEFAULT_BACKEND_FLUSH_AFTER;
/* local state for StartBufferIO and related functions */
static BufferDesc *InProgressBuf = NULL;
diff --git a/src/backend/storage/ipc/dsm_impl.c b/src/backend/storage/ipc/dsm_impl.c
index e1b90c5..6ddd46a 100644
--- a/src/backend/storage/ipc/dsm_impl.c
+++ b/src/backend/storage/ipc/dsm_impl.c
@@ -109,7 +109,7 @@ const struct config_enum_entry dynamic_shared_memory_options[] = {
};
/* Implementation selector. */
-int dynamic_shared_memory_type;
+int dynamic_shared_memory_type = DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE;
/* Amount of space reserved for DSM segments in the main area. */
int min_dynamic_shared_memory;
diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c
index d32cb11..8cd5262 100644
--- a/src/backend/utils/adt/xml.c
+++ b/src/backend/utils/adt/xml.c
@@ -94,8 +94,8 @@
/* GUC variables */
-int xmlbinary;
-int xmloption;
+int xmlbinary = XMLBINARY_BASE64;
+int xmloption = XMLOPTION_CONTENT;
#ifdef USE_LIBXML
diff --git a/src/backend/utils/cache/plancache.c b/src/backend/utils/cache/plancache.c
index 0d6a295..cc94320 100644
--- a/src/backend/utils/cache/plancache.c
+++ b/src/backend/utils/cache/plancache.c
@@ -116,7 +116,7 @@ static void PlanCacheObjectCallback(Datum arg, int cacheid, uint32 hashvalue);
static void PlanCacheSysCallback(Datum arg, int cacheid, uint32 hashvalue);
/* GUC parameter */
-int plan_cache_mode;
+int plan_cache_mode = PLAN_CACHE_MODE_AUTO;
/*
* InitPlanCache: initialize module during InitPostgres.
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 6e0a66c..2585e24 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -107,7 +107,7 @@ extern bool redirection_done;
emit_log_hook_type emit_log_hook = NULL;
/* GUC parameters */
-int Log_error_verbosity = PGERROR_VERBOSE;
+int Log_error_verbosity = PGERROR_DEFAULT;
char *Log_line_prefix = NULL; /* format for extra log line info */
int Log_destination = LOG_DESTINATION_STDERR;
char *Log_destination_string = NULL;
diff --git a/src/backend/utils/init/globals.c b/src/backend/utils/init/globals.c
index 1a5d29a..00bceec 100644
--- a/src/backend/utils/init/globals.c
+++ b/src/backend/utils/init/globals.c
@@ -133,8 +133,8 @@ int max_parallel_maintenance_workers = 2;
* MaxBackends is computed by PostmasterMain after modules have had a chance to
* register background workers.
*/
-int NBuffers = 1000;
-int MaxConnections = 90;
+int NBuffers = 16384;
+int MaxConnections = 100;
int max_worker_processes = 8;
int max_parallel_workers = 8;
int MaxBackends = 0;
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 6f21752..7c9c4be 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -1382,6 +1382,77 @@ check_GUC_name_for_parameter_acl(const char *name)
return false;
}
+/*
+ * A GUC C variable can be declared with an initial value, but the GUC mechanism
+ * will overwrite that using the compiled-in default (boot_val) as per
+ * guc_tables.c.
+ *
+ * This function performs a sanity-check comparison of the C variable initial
+ * value with the boot_val, to prevent anybody reading those C declarations
+ * from being fooled by mismatched values.
+ *
+ * GUC C variable validation rules:
+ * bool - can be false, otherwise must be same as the boot_val
+ * int - can be 0, otherwise must be same as the boot_val
+ * real - can be 0.0, otherwise must be same as the boot_val
+ * string - can be NULL, otherwise must be strcmp equal to the boot_val
+ * enum - must be same as the boot_val
+ */
+static void
+sanity_check_GUC_C_var(struct config_generic *gconf)
+{
+#ifdef USE_ASSERT_CHECKING
+
+ switch (gconf->vartype)
+ {
+ case PGC_BOOL:
+ {
+ struct config_bool *conf = (struct config_bool *) gconf;
+
+ if (*conf->variable && !conf->boot_val)
+ elog(FATAL, "GUC (PGC_BOOL) %s, boot_val=%d, C-var=%d",
+ conf->gen.name, conf->boot_val, *conf->variable);
+ break;
+ }
+ case PGC_INT:
+ {
+ struct config_int *conf = (struct config_int *) gconf;
+
+ if (*conf->variable != 0 && *conf->variable != conf->boot_val)
+ elog(FATAL, "GUC (PGC_INT) %s, boot_val=%d, C-var=%d",
+ conf->gen.name, conf->boot_val, *conf->variable);
+ break;
+ }
+ case PGC_REAL:
+ {
+ struct config_real *conf = (struct config_real *) gconf;
+
+ if (*conf->variable != 0.0 && *conf->variable != conf->boot_val)
+ elog(FATAL, "GUC (PGC_REAL) %s, boot_val=%g, C-var=%g",
+ conf->gen.name, conf->boot_val, *conf->variable);
+ break;
+ }
+ case PGC_STRING:
+ {
+ struct config_string *conf = (struct config_string *) gconf;
+
+ if (*conf->variable != NULL && strcmp(*conf->variable, conf->boot_val) != 0)
+ elog(FATAL, "GUC (PGC_STRING) %s, boot_val=%s, C-var=%s",
+ conf->gen.name, conf->boot_val ? conf->boot_val : "<null>", *conf->variable);
+ break;
+ }
+ case PGC_ENUM:
+ {
+ struct config_enum *conf = (struct config_enum *) gconf;
+
+ if (*conf->variable != conf->boot_val)
+ elog(FATAL, "GUC (PGC_ENUM) %s, boot_val=%d, C-var=%d",
+ conf->gen.name, conf->boot_val, *conf->variable);
+ break;
+ }
+ }
+#endif
+}
/*
* Initialize GUC options during program startup.
@@ -1413,6 +1484,7 @@ InitializeGUCOptions(void)
hash_seq_init(&status, guc_hashtab);
while ((hentry = (GUCHashEntry *) hash_seq_search(&status)) != NULL)
{
+ sanity_check_GUC_C_var(hentry->gucvar);
InitializeOneGUCOption(hentry->gucvar);
}
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 05ab087..da387f1 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -526,13 +526,16 @@ int ssl_renegotiation_limit;
* This really belongs in pg_shmem.c, but is defined here so that it doesn't
* need to be duplicated in all the different implementations of pg_shmem.c.
*/
-int huge_pages;
+int huge_pages = HUGE_PAGES_TRY;
int huge_page_size;
/*
* These variables are all dummies that don't do anything, except in some
* cases provide the value for SHOW to display. The real state is elsewhere
* and is kept in sync by assign_hooks.
+ *
+ * Declaration assignments here are for keeping the GUC C var sanity-checker
+ * happy.
*/
static char *syslog_ident_str;
static double phony_random_seed;
@@ -543,7 +546,12 @@ static char *locale_ctype;
static char *server_encoding_string;
static char *server_version_string;
static int server_version_num;
-static int syslog_facility;
+static int syslog_facility =
+#ifdef HAVE_SYSLOG
+ LOG_LOCAL0;
+#else
+ 0;
+#endif
static char *timezone_string;
static char *log_timezone_string;
static char *timezone_abbreviations_string;
@@ -559,7 +567,12 @@ static int shared_memory_size_in_huge_pages;
static int wal_block_size;
static bool data_checksums;
static bool integer_datetimes;
-static bool assert_enabled;
+static bool assert_enabled =
+#ifdef USE_ASSERT_CHECKING
+ true;
+#else
+ false;
+#endif
static char *recovery_target_timeline_string;
static char *recovery_target_string;
static char *recovery_target_xid_string;
diff --git a/src/backend/utils/misc/ps_status.c b/src/backend/utils/misc/ps_status.c
index 8520ce7..46ade41 100644
--- a/src/backend/utils/misc/ps_status.c
+++ b/src/backend/utils/misc/ps_status.c
@@ -30,8 +30,14 @@
#include "utils/ps_status.h"
extern char **environ;
-bool update_process_title = true;
+/* GUC variable */
+bool update_process_title =
+#ifdef WIN32
+ false;
+#else
+ true;
+#endif
/*
* Alternative ways of updating ps display:
--
1.8.3.1
On Wed, Oct 26, 2022 at 06:31:56PM +1100, Peter Smith wrote:
I re-checked all the GUC C vars which your patch flags as
GUC_DEFAULT_COMPILE. For some of them, where it was not any trouble, I
made the C var assignment use the same preprocessor rules as used by
guc_tables. For others (mostly the string ones) I left the GUC C var
untouched because the sanity checker function already has a rule not
to complain about int GUC C vars which are 0 or string GUC vars which
are NULL.
I see. So you have on this thread an independent patch to make the CF
bot happy, still depend on the patch posted on [1]/messages/by-id/20221024220544.GJ16921@telsasoft.com -- Michael to bypass the
changes with variables whose boot values are compilation-dependent.
Is it right to believe that the only requirement here is
GUC_DEFAULT_COMPILE but not GUC_DEFAULT_INITDB? The former is much
more intuitive than the latter. Still, I see an inconsistency here in
what you are doing here.
sanity_check_GUC_C_var() would need to skip all the GUCs marked as
GUC_DEFAULT_COMPILE, meaning that one could still be "fooled by a
mismatched value" in these cases. We are talking about a limited set
of them, but it seems to me that we have no need for this flag at all
once the default GUC values are set with a #defined'd value, no?
checkpoint_flush_after, bgwriter_flush_after, port and
effective_io_concurrency do that, which is why
v5-0001-GUC-C-variable-sanity-check.patch does its stuff only for
maintenance_io_concurrency, update_process_title, assert_enabled and
syslog_facility. I think that it would be simpler to have a default
for these last four with a centralized definition, meaning that we
would not need a GUC_DEFAULT_COMPILE at all, while the validation
could be done for basically all the GUCs with default values
assigned. In short, this patch has no need to depend on what's posted
in [1]/messages/by-id/20221024220544.GJ16921@telsasoft.com -- Michael.
[1]: /messages/by-id/20221024220544.GJ16921@telsasoft.com -- Michael
--
Michael
On Thu, Oct 27, 2022 at 11:06:56AM +0900, Michael Paquier wrote:
On Wed, Oct 26, 2022 at 06:31:56PM +1100, Peter Smith wrote:
I re-checked all the GUC C vars which your patch flags as
GUC_DEFAULT_COMPILE. For some of them, where it was not any trouble, I
made the C var assignment use the same preprocessor rules as used by
guc_tables. For others (mostly the string ones) I left the GUC C var
untouched because the sanity checker function already has a rule not
to complain about int GUC C vars which are 0 or string GUC vars which
are NULL.I see. So you have on this thread an independent patch to make the CF
bot happy, still depend on the patch posted on [1] to bypass the
changes with variables whose boot values are compilation-dependent.
It seems like you're reviewing the previous version of the patch, rather
than the one attached to the message you responded to (which doesn't
have anything to do with GUC_DEFAULT_COMPILE).
I don't know what you meant by "make the CF bot happy" (?)
--
Justin
On Wed, Oct 26, 2022 at 09:14:37PM -0500, Justin Pryzby wrote:
It seems like you're reviewing the previous version of the patch, rather
than the one attached to the message you responded to (which doesn't
have anything to do with GUC_DEFAULT_COMPILE).
It does not seem so as things stand, I have been looking at
v5-0001-GUC-C-variable-sanity-check.patch as posted by Peter here:
/messages/by-id/CAHut+PuCHjYXiTGdTOvHvDnjpbivLLr49gWVS+8VwnfoM4hJTw@mail.gmail.com
In combination with a two-patch set as posted by you here:
0001-add-DYNAMIC_DEFAULT-for-settings-which-vary-by-.-con.patch
0002-WIP-test-guc-default-values.patch
/messages/by-id/20221024220544.GJ16921@telsasoft.com
These are the latest patch versions posted on their respective thread
I am aware of, and based on the latest updates of each thread it still
looked like there was a dependency between both. So, is that the case
or not? If not, sorry if I misunderstood things.
I don't know what you meant by "make the CF bot happy" (?)
It is in my opinion confusing to see that the v5 posted on this
thread, which was marked as ready for committer as of
https://commitfest.postgresql.org/40/3934/, seem to rely on a facility
that it makes no use of. Hence it looks to me that this patch has
been posted as-is to allow the CF bot to pass (I would have posted
that as an isolated two-patch set with the first patch introducing the
flag if need be).
Anyway, per my previous comments in my last message of this thread as
of https://www.postgresql.org/message-id/Y1nnwFTrnL3ItleP@paquier.xyz,
I don't see a need for DYNAMIC_DEFAULT from the other thread, nor do I
see a need to a style like that:
+/* GUC variable */
+bool update_process_title =
+#ifdef WIN32
+ false;
+#else
+ true;
+#endif
I think that it would be cleaner to use the same approach as
checking_after_flush and similar GUCs with a centralized definition,
rather than spreading such style in two places for each GUC that this
patch touches (aka its declaration and its default value in
guc_tables.c). In any case, the patch of this thread still needs some
adjustments IMO.
--
Michael
On Thu, Oct 27, 2022 at 11:33:48AM +0900, Michael Paquier wrote:
On Wed, Oct 26, 2022 at 09:14:37PM -0500, Justin Pryzby wrote:
It seems like you're reviewing the previous version of the patch, rather
than the one attached to the message you responded to (which doesn't
have anything to do with GUC_DEFAULT_COMPILE).It does not seem so as things stand, I have been looking at
v5-0001-GUC-C-variable-sanity-check.patch as posted by Peter here:
/messages/by-id/CAHut+PuCHjYXiTGdTOvHvDnjpbivLLr49gWVS+8VwnfoM4hJTw@mail.gmail.com
This thread is about consistency of the global variables with what's set
by the GUC infrastructure.
In v4, Peter posted a 2-patch series with my patch as 001.
But I pointed out that it's better to fix the initialization of the
compile-time GUCs rather than exclude them from the check.
Then Peter submitted v5 whcih does that, and isn't built on top of my
patch.
In combination with a two-patch set as posted by you here:
0001-add-DYNAMIC_DEFAULT-for-settings-which-vary-by-.-con.patch
0002-WIP-test-guc-default-values.patch
/messages/by-id/20221024220544.GJ16921@telsasoft.com
That's a separate thread regarding consistency of the default values
(annotations) shown in postgresql.conf. (I'm not sure whether or not my
patch adding GUC flags is an agreed way forward, although they might
turn out to be useful for other purposes).
--
Justin
On Thu, Oct 27, 2022 at 1:33 PM Michael Paquier <michael@paquier.xyz> wrote:
On Wed, Oct 26, 2022 at 09:14:37PM -0500, Justin Pryzby wrote:
It seems like you're reviewing the previous version of the patch, rather
than the one attached to the message you responded to (which doesn't
have anything to do with GUC_DEFAULT_COMPILE).It does not seem so as things stand, I have been looking at
v5-0001-GUC-C-variable-sanity-check.patch as posted by Peter here:
/messages/by-id/CAHut+PuCHjYXiTGdTOvHvDnjpbivLLr49gWVS+8VwnfoM4hJTw@mail.gmail.comIn combination with a two-patch set as posted by you here:
0001-add-DYNAMIC_DEFAULT-for-settings-which-vary-by-.-con.patch
0002-WIP-test-guc-default-values.patch
/messages/by-id/20221024220544.GJ16921@telsasoft.comThese are the latest patch versions posted on their respective thread
I am aware of, and based on the latest updates of each thread it still
looked like there was a dependency between both. So, is that the case
or not? If not, sorry if I misunderstood things.
No. My v5 is no longer dependent on the other patch.
I don't know what you meant by "make the CF bot happy" (?)
It is in my opinion confusing to see that the v5 posted on this
thread, which was marked as ready for committer as of
https://commitfest.postgresql.org/40/3934/, seem to rely on a facility
that it makes no use of. Hence it looks to me that this patch has
been posted as-is to allow the CF bot to pass (I would have posted
that as an isolated two-patch set with the first patch introducing the
flag if need be).
Yeah, my v4 was posted along with the other GUC flag patch as a
prerequisite to make the cfbot happy. This is no longer the case - v5
is a single independent patch. Sorry for the "ready for the committer"
status being confusing. At that time I thought it was.
Anyway, per my previous comments in my last message of this thread as of https://www.postgresql.org/message-id/Y1nnwFTrnL3ItleP@paquier.xyz, I don't see a need for DYNAMIC_DEFAULT from the other thread, nor do I see a need to a style like that: +/* GUC variable */ +bool update_process_title = +#ifdef WIN32 + false; +#else + true; +#endifI think that it would be cleaner to use the same approach as
checking_after_flush and similar GUCs with a centralized definition,
rather than spreading such style in two places for each GUC that this
patch touches (aka its declaration and its default value in
guc_tables.c). In any case, the patch of this thread still needs some
adjustments IMO.
OK, I can make that adjustment if it is preferred. I think it is the
same as what I already suggested a while ago [1]/messages/by-id/1113448.1665717297@sss.pgh.pa.us ("But probably it is
no problem to just add #defines...")
------
[1]: /messages/by-id/1113448.1665717297@sss.pgh.pa.us
Kind Regards,
Peter Smith.
Fujitsu Australia.
On Wed, Oct 26, 2022 at 09:49:34PM -0500, Justin Pryzby wrote:
In v4, Peter posted a 2-patch series with my patch as 001.
But I pointed out that it's better to fix the initialization of the
compile-time GUCs rather than exclude them from the check.
Then Peter submitted v5 whcih does that, and isn't built on top of my
patch.
Okidoki, thanks for the clarification.
--
Michael
On Thu, Oct 27, 2022 at 1:33 PM Michael Paquier <michael@paquier.xyz> wrote:
...
Anyway, per my previous comments in my last message of this thread as of https://www.postgresql.org/message-id/Y1nnwFTrnL3ItleP@paquier.xyz, I don't see a need for DYNAMIC_DEFAULT from the other thread, nor do I see a need to a style like that: +/* GUC variable */ +bool update_process_title = +#ifdef WIN32 + false; +#else + true; +#endifI think that it would be cleaner to use the same approach as
checking_after_flush and similar GUCs with a centralized definition,
rather than spreading such style in two places for each GUC that this
patch touches (aka its declaration and its default value in
guc_tables.c). In any case, the patch of this thread still needs some
adjustments IMO.
PSA patch v6.
The GUC defaults of guc_tables.c, and the modified GUC C var
declarations now share the same common #define'd value (instead of
cut/paste preprocessor code).
Per Michael's suggestion [1]/messages/by-id/Y1nuDNZDncx7+A1j@paquier.xyz to use centralized definitions.
------
[1]: /messages/by-id/Y1nuDNZDncx7+A1j@paquier.xyz
Kind Regards,
Peter Smith.
Fujitsu Australia
Attachments:
v6-0001-GUC-C-variable-sanity-check.patchapplication/octet-stream; name=v6-0001-GUC-C-variable-sanity-check.patchDownload
From cfc89f2e5b418a64c30a5b6e88aee8e27769c71b Mon Sep 17 00:00:00 2001
From: Peter Smith <peter.b.smith@fujitsu.com>
Date: Thu, 27 Oct 2022 18:45:34 +1100
Subject: [PATCH v6] GUC C variable sanity check
Added a function to perform a sanity-check comparison of the C variable initial
value with the compiled-in default (boot_val). The purpose of this is to prevent
anybody reading those C declarations from being fooled by mismatched values.
Also fixed some existing mismatching values.
---
src/backend/access/transam/xact.c | 2 +-
src/backend/access/transam/xlog.c | 2 +-
src/backend/libpq/be-secure.c | 4 +--
src/backend/postmaster/postmaster.c | 2 +-
src/backend/storage/buffer/bufmgr.c | 10 +++---
src/backend/storage/ipc/dsm_impl.c | 2 +-
src/backend/utils/adt/xml.c | 4 +--
src/backend/utils/cache/plancache.c | 2 +-
src/backend/utils/error/elog.c | 2 +-
src/backend/utils/init/globals.c | 4 +--
src/backend/utils/misc/guc.c | 72 +++++++++++++++++++++++++++++++++++++
src/backend/utils/misc/guc_tables.c | 53 +++++++++++++--------------
src/backend/utils/misc/ps_status.c | 3 +-
src/include/storage/bufmgr.h | 8 +++++
src/include/utils/ps_status.h | 5 +++
15 files changed, 129 insertions(+), 46 deletions(-)
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index fd5103a..f45c95f 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -75,7 +75,7 @@
* User-tweakable parameters
*/
int DefaultXactIsoLevel = XACT_READ_COMMITTED;
-int XactIsoLevel;
+int XactIsoLevel = XACT_READ_COMMITTED;
bool DefaultXactReadOnly = false;
bool XactReadOnly;
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 8f10eff..be54c23 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -131,7 +131,7 @@ bool wal_init_zero = true;
bool wal_recycle = true;
bool log_checkpoints = true;
int sync_method = DEFAULT_SYNC_METHOD;
-int wal_level = WAL_LEVEL_MINIMAL;
+int wal_level = WAL_LEVEL_REPLICA;
int CommitDelay = 0; /* precommit delay in microseconds */
int CommitSiblings = 5; /* # concurrent xacts needed to sleep */
int wal_retrieve_retry_interval = 5000;
diff --git a/src/backend/libpq/be-secure.c b/src/backend/libpq/be-secure.c
index e3e5471..c896357 100644
--- a/src/backend/libpq/be-secure.c
+++ b/src/backend/libpq/be-secure.c
@@ -58,8 +58,8 @@ char *SSLECDHCurve;
/* GUC variable: if false, prefer client ciphers */
bool SSLPreferServerCiphers;
-int ssl_min_protocol_version;
-int ssl_max_protocol_version;
+int ssl_min_protocol_version = PG_TLS1_2_VERSION;
+int ssl_max_protocol_version = PG_TLS_ANY;
/* ------------------------------------------------------------ */
/* Procedures common to all secure sessions */
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 30fb576..0b637ba 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -196,7 +196,7 @@ BackgroundWorker *MyBgworkerEntry = NULL;
/* The socket number we are listening for connections on */
-int PostPortNumber;
+int PostPortNumber = DEF_PGPORT;
/* The directory names for Unix socket(s) */
char *Unix_socket_directories;
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c
index 6b95381..73d30bf 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -142,22 +142,22 @@ bool track_io_timing = false;
* for buffers not belonging to tablespaces that have their
* effective_io_concurrency parameter set.
*/
-int effective_io_concurrency = 0;
+int effective_io_concurrency = DEFAULT_EFFECTIVE_IO_CONCURRENCY;
/*
* Like effective_io_concurrency, but used by maintenance code paths that might
* benefit from a higher setting because they work on behalf of many sessions.
* Overridden by the tablespace setting of the same name.
*/
-int maintenance_io_concurrency = 0;
+int maintenance_io_concurrency = DEFAULT_MAINTENANCE_IO_CONCURRENCY;
/*
* GUC variables about triggering kernel writeback for buffers written; OS
* dependent defaults are set via the GUC mechanism.
*/
-int checkpoint_flush_after = 0;
-int bgwriter_flush_after = 0;
-int backend_flush_after = 0;
+int checkpoint_flush_after = DEFAULT_CHECKPOINT_FLUSH_AFTER;
+int bgwriter_flush_after = DEFAULT_BGWRITER_FLUSH_AFTER;
+int backend_flush_after = DEFAULT_BACKEND_FLUSH_AFTER;
/* local state for StartBufferIO and related functions */
static BufferDesc *InProgressBuf = NULL;
diff --git a/src/backend/storage/ipc/dsm_impl.c b/src/backend/storage/ipc/dsm_impl.c
index e1b90c5..6ddd46a 100644
--- a/src/backend/storage/ipc/dsm_impl.c
+++ b/src/backend/storage/ipc/dsm_impl.c
@@ -109,7 +109,7 @@ const struct config_enum_entry dynamic_shared_memory_options[] = {
};
/* Implementation selector. */
-int dynamic_shared_memory_type;
+int dynamic_shared_memory_type = DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE;
/* Amount of space reserved for DSM segments in the main area. */
int min_dynamic_shared_memory;
diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c
index d32cb11..8cd5262 100644
--- a/src/backend/utils/adt/xml.c
+++ b/src/backend/utils/adt/xml.c
@@ -94,8 +94,8 @@
/* GUC variables */
-int xmlbinary;
-int xmloption;
+int xmlbinary = XMLBINARY_BASE64;
+int xmloption = XMLOPTION_CONTENT;
#ifdef USE_LIBXML
diff --git a/src/backend/utils/cache/plancache.c b/src/backend/utils/cache/plancache.c
index 0d6a295..cc94320 100644
--- a/src/backend/utils/cache/plancache.c
+++ b/src/backend/utils/cache/plancache.c
@@ -116,7 +116,7 @@ static void PlanCacheObjectCallback(Datum arg, int cacheid, uint32 hashvalue);
static void PlanCacheSysCallback(Datum arg, int cacheid, uint32 hashvalue);
/* GUC parameter */
-int plan_cache_mode;
+int plan_cache_mode = PLAN_CACHE_MODE_AUTO;
/*
* InitPlanCache: initialize module during InitPostgres.
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 6e0a66c..2585e24 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -107,7 +107,7 @@ extern bool redirection_done;
emit_log_hook_type emit_log_hook = NULL;
/* GUC parameters */
-int Log_error_verbosity = PGERROR_VERBOSE;
+int Log_error_verbosity = PGERROR_DEFAULT;
char *Log_line_prefix = NULL; /* format for extra log line info */
int Log_destination = LOG_DESTINATION_STDERR;
char *Log_destination_string = NULL;
diff --git a/src/backend/utils/init/globals.c b/src/backend/utils/init/globals.c
index 1a5d29a..00bceec 100644
--- a/src/backend/utils/init/globals.c
+++ b/src/backend/utils/init/globals.c
@@ -133,8 +133,8 @@ int max_parallel_maintenance_workers = 2;
* MaxBackends is computed by PostmasterMain after modules have had a chance to
* register background workers.
*/
-int NBuffers = 1000;
-int MaxConnections = 90;
+int NBuffers = 16384;
+int MaxConnections = 100;
int max_worker_processes = 8;
int max_parallel_workers = 8;
int MaxBackends = 0;
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 6f21752..7c9c4be 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -1382,6 +1382,77 @@ check_GUC_name_for_parameter_acl(const char *name)
return false;
}
+/*
+ * A GUC C variable can be declared with an initial value, but the GUC mechanism
+ * will overwrite that using the compiled-in default (boot_val) as per
+ * guc_tables.c.
+ *
+ * This function performs a sanity-check comparison of the C variable initial
+ * value with the boot_val, to prevent anybody reading those C declarations
+ * from being fooled by mismatched values.
+ *
+ * GUC C variable validation rules:
+ * bool - can be false, otherwise must be same as the boot_val
+ * int - can be 0, otherwise must be same as the boot_val
+ * real - can be 0.0, otherwise must be same as the boot_val
+ * string - can be NULL, otherwise must be strcmp equal to the boot_val
+ * enum - must be same as the boot_val
+ */
+static void
+sanity_check_GUC_C_var(struct config_generic *gconf)
+{
+#ifdef USE_ASSERT_CHECKING
+
+ switch (gconf->vartype)
+ {
+ case PGC_BOOL:
+ {
+ struct config_bool *conf = (struct config_bool *) gconf;
+
+ if (*conf->variable && !conf->boot_val)
+ elog(FATAL, "GUC (PGC_BOOL) %s, boot_val=%d, C-var=%d",
+ conf->gen.name, conf->boot_val, *conf->variable);
+ break;
+ }
+ case PGC_INT:
+ {
+ struct config_int *conf = (struct config_int *) gconf;
+
+ if (*conf->variable != 0 && *conf->variable != conf->boot_val)
+ elog(FATAL, "GUC (PGC_INT) %s, boot_val=%d, C-var=%d",
+ conf->gen.name, conf->boot_val, *conf->variable);
+ break;
+ }
+ case PGC_REAL:
+ {
+ struct config_real *conf = (struct config_real *) gconf;
+
+ if (*conf->variable != 0.0 && *conf->variable != conf->boot_val)
+ elog(FATAL, "GUC (PGC_REAL) %s, boot_val=%g, C-var=%g",
+ conf->gen.name, conf->boot_val, *conf->variable);
+ break;
+ }
+ case PGC_STRING:
+ {
+ struct config_string *conf = (struct config_string *) gconf;
+
+ if (*conf->variable != NULL && strcmp(*conf->variable, conf->boot_val) != 0)
+ elog(FATAL, "GUC (PGC_STRING) %s, boot_val=%s, C-var=%s",
+ conf->gen.name, conf->boot_val ? conf->boot_val : "<null>", *conf->variable);
+ break;
+ }
+ case PGC_ENUM:
+ {
+ struct config_enum *conf = (struct config_enum *) gconf;
+
+ if (*conf->variable != conf->boot_val)
+ elog(FATAL, "GUC (PGC_ENUM) %s, boot_val=%d, C-var=%d",
+ conf->gen.name, conf->boot_val, *conf->variable);
+ break;
+ }
+ }
+#endif
+}
/*
* Initialize GUC options during program startup.
@@ -1413,6 +1484,7 @@ InitializeGUCOptions(void)
hash_seq_init(&status, guc_hashtab);
while ((hentry = (GUCHashEntry *) hash_seq_search(&status)) != NULL)
{
+ sanity_check_GUC_C_var(hentry->gucvar);
InitializeOneGUCOption(hentry->gucvar);
}
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 05ab087..9fd1674 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -526,13 +526,16 @@ int ssl_renegotiation_limit;
* This really belongs in pg_shmem.c, but is defined here so that it doesn't
* need to be duplicated in all the different implementations of pg_shmem.c.
*/
-int huge_pages;
+int huge_pages = HUGE_PAGES_TRY;
int huge_page_size;
/*
* These variables are all dummies that don't do anything, except in some
* cases provide the value for SHOW to display. The real state is elsewhere
* and is kept in sync by assign_hooks.
+ *
+ * Declaration assignments here are for keeping the GUC C var sanity-checker
+ * happy.
*/
static char *syslog_ident_str;
static double phony_random_seed;
@@ -543,7 +546,14 @@ static char *locale_ctype;
static char *server_encoding_string;
static char *server_version_string;
static int server_version_num;
-static int syslog_facility;
+
+#ifdef HAVE_SYSLOG
+#define DEFAULT_SYSLOG_FACILITY LOG_LOCAL0
+#else
+#define DEFAULT_SYSLOG_FACILITY 0
+#endif
+static int syslog_facility = DEFAULT_SYSLOG_FACILITY;
+
static char *timezone_string;
static char *log_timezone_string;
static char *timezone_abbreviations_string;
@@ -559,7 +569,14 @@ static int shared_memory_size_in_huge_pages;
static int wal_block_size;
static bool data_checksums;
static bool integer_datetimes;
-static bool assert_enabled;
+
+#ifdef USE_ASSERT_CHECKING
+#define DEFAULT_ASSERT_ENABLED true
+#else
+#define DEFAULT_ASSERT_ENABLED false
+#endif
+static bool assert_enabled = DEFAULT_ASSERT_ENABLED;
+
static char *recovery_target_timeline_string;
static char *recovery_target_string;
static char *recovery_target_xid_string;
@@ -1181,11 +1198,7 @@ struct config_bool ConfigureNamesBool[] =
GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
},
&assert_enabled,
-#ifdef USE_ASSERT_CHECKING
- true,
-#else
- false,
-#endif
+ DEFAULT_ASSERT_ENABLED,
NULL, NULL, NULL
},
@@ -1357,11 +1370,7 @@ struct config_bool ConfigureNamesBool[] =
gettext_noop("Enables updating of the process title every time a new SQL command is received by the server.")
},
&update_process_title,
-#ifdef WIN32
- false,
-#else
- true,
-#endif
+ DEFAULT_UPDATE_PROCESS_TITLE,
NULL, NULL, NULL
},
@@ -2888,11 +2897,7 @@ struct config_int ConfigureNamesInt[] =
GUC_EXPLAIN
},
&effective_io_concurrency,
-#ifdef USE_PREFETCH
- 1,
-#else
- 0,
-#endif
+ DEFAULT_EFFECTIVE_IO_CONCURRENCY,
0, MAX_IO_CONCURRENCY,
check_effective_io_concurrency, NULL, NULL
},
@@ -2906,11 +2911,7 @@ struct config_int ConfigureNamesInt[] =
GUC_EXPLAIN
},
&maintenance_io_concurrency,
-#ifdef USE_PREFETCH
- 10,
-#else
- 0,
-#endif
+ DEFAULT_MAINTENANCE_IO_CONCURRENCY,
0, MAX_IO_CONCURRENCY,
check_maintenance_io_concurrency, assign_maintenance_io_concurrency,
NULL
@@ -4613,11 +4614,7 @@ struct config_enum ConfigureNamesEnum[] =
NULL
},
&syslog_facility,
-#ifdef HAVE_SYSLOG
- LOG_LOCAL0,
-#else
- 0,
-#endif
+ DEFAULT_SYSLOG_FACILITY,
syslog_facility_options,
NULL, assign_syslog_facility, NULL
},
diff --git a/src/backend/utils/misc/ps_status.c b/src/backend/utils/misc/ps_status.c
index 8520ce7..d81a67b 100644
--- a/src/backend/utils/misc/ps_status.c
+++ b/src/backend/utils/misc/ps_status.c
@@ -30,8 +30,9 @@
#include "utils/ps_status.h"
extern char **environ;
-bool update_process_title = true;
+/* GUC variable */
+bool update_process_title = DEFAULT_UPDATE_PROCESS_TITLE;
/*
* Alternative ways of updating ps display:
diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h
index 6f4dfa0..185c3b9 100644
--- a/src/include/storage/bufmgr.h
+++ b/src/include/storage/bufmgr.h
@@ -69,6 +69,14 @@ extern PGDLLIMPORT bool zero_damaged_pages;
extern PGDLLIMPORT int bgwriter_lru_maxpages;
extern PGDLLIMPORT double bgwriter_lru_multiplier;
extern PGDLLIMPORT bool track_io_timing;
+
+#ifdef USE_PREFETCH
+#define DEFAULT_EFFECTIVE_IO_CONCURRENCY 1
+#define DEFAULT_MAINTENANCE_IO_CONCURRENCY 10
+#else
+#define DEFAULT_EFFECTIVE_IO_CONCURRENCY 0
+#define DEFAULT_MAINTENANCE_IO_CONCURRENCY 0
+#endif
extern PGDLLIMPORT int effective_io_concurrency;
extern PGDLLIMPORT int maintenance_io_concurrency;
diff --git a/src/include/utils/ps_status.h b/src/include/utils/ps_status.h
index bba4635..3e9e98d 100644
--- a/src/include/utils/ps_status.h
+++ b/src/include/utils/ps_status.h
@@ -12,6 +12,11 @@
#ifndef PS_STATUS_H
#define PS_STATUS_H
+#ifdef WIN32
+#define DEFAULT_UPDATE_PROCESS_TITLE false
+#else
+#define DEFAULT_UPDATE_PROCESS_TITLE true
+#endif
extern PGDLLIMPORT bool update_process_title;
extern char **save_ps_display_args(int argc, char **argv);
--
1.8.3.1
On Thu, Oct 27, 2022 at 07:00:26PM +1100, Peter Smith wrote:
The GUC defaults of guc_tables.c, and the modified GUC C var
declarations now share the same common #define'd value (instead of
cut/paste preprocessor code).
Thanks. I have not looked at the checkup logic yet, but the central
declarations seem rather sane, and I have a few comments about the
latter.
+#ifdef WIN32
+#define DEFAULT_UPDATE_PROCESS_TITLE false
+#else
+#define DEFAULT_UPDATE_PROCESS_TITLE true
+#endif
This is the kind of things I would document as a comment, say
"Disabled on Windows as the performance overhead can be significant".
Actually, pg_iovec.h uses WIN32 without any previous header declared,
but win32.h tells a different story as of ed9b3606, where we would
define WIN32 if it does not exist yet. That may impact the default
depending on the environment used? I am wondering whether the top of
win32.h could be removed, these days..
+#ifdef USE_PREFETCH
+#define DEFAULT_EFFECTIVE_IO_CONCURRENCY 1
+#define DEFAULT_MAINTENANCE_IO_CONCURRENCY 10
+#else
+#define DEFAULT_EFFECTIVE_IO_CONCURRENCY 0
+#define DEFAULT_MAINTENANCE_IO_CONCURRENCY 0
+#endif
These don't make sense without prefetching available. Perhaps that's
obvious enough when reading the code still I would add a small note.
--
Michael
On Fri, Oct 28, 2022 at 11:48:13AM +0900, Michael Paquier wrote:
Actually, pg_iovec.h uses WIN32 without any previous header declared,
but win32.h tells a different story as of ed9b3606, where we would
define WIN32 if it does not exist yet.
Seeing all the places where pg_status.h is included, that should be
fine, so please just ignore this part.
--
Michael
On Fri, Oct 28, 2022 at 11:48:13AM +0900, Michael Paquier wrote:
Thanks. I have not looked at the checkup logic yet, but the central
declarations seem rather sane, and I have a few comments about the
latter.
So, I've had the energy to look at the check logic today, and noticed
that, while the proposed patch is doing the job when loading the
in-core GUCs, nothing is happening for the custom GUCs that could be
loaded through shared_preload_libraries or just from a LOAD command.
After adding an extra check in define_custom_variable() (reworking a
bit the interface proposed while on it), I have found a few more
issues than what's been already found on this thread:
- 5 missing spots in pg_stat_statements.
- 3 float rounding issues in pg_trgm.
- 1 spot in pg_prewarm.
- A few more that had no initialization, but these had a default of
false/0/0.0 so it does not influence the end result but I have added
some initializations anyway.
With all that addressed, I am finishing with the attached. I have
added some comments for the default definitions depending on the
CFLAGS, explaining the reasons behind the choices made. The CI has
produced a green run, which is not the same as the buildfarm, still
gives some confidence.
Thoughts?
--
Michael
Attachments:
v7-0001-GUC-C-variable-sanity-check.patchtext/x-diff; charset=us-asciiDownload
From 3f742d6433d88895720f6801c59213f0f4ad17f9 Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@paquier.xyz>
Date: Fri, 28 Oct 2022 16:03:08 +0900
Subject: [PATCH v7] GUC C variable sanity check
Added a function to perform a sanity-check comparison of the C variable initial
value with the compiled-in default (boot_val). The purpose of this is to prevent
anybody reading those C declarations from being fooled by mismatched values.
Also fixed some existing mismatching values.
---
src/include/storage/bufmgr.h | 9 ++
src/include/utils/ps_status.h | 6 ++
src/backend/access/transam/xact.c | 2 +-
src/backend/access/transam/xlog.c | 2 +-
src/backend/libpq/be-secure.c | 4 +-
src/backend/postmaster/postmaster.c | 2 +-
src/backend/storage/buffer/bufmgr.c | 10 +--
src/backend/storage/ipc/dsm_impl.c | 2 +-
src/backend/utils/adt/xml.c | 4 +-
src/backend/utils/cache/plancache.c | 2 +-
src/backend/utils/error/elog.c | 2 +-
src/backend/utils/init/globals.c | 4 +-
src/backend/utils/misc/guc.c | 89 +++++++++++++++++++
src/backend/utils/misc/guc_tables.c | 50 +++++------
src/backend/utils/misc/ps_status.c | 3 +-
contrib/auth_delay/auth_delay.c | 2 +-
contrib/pg_prewarm/autoprewarm.c | 2 +-
.../pg_stat_statements/pg_stat_statements.c | 10 +--
contrib/pg_trgm/trgm_op.c | 6 +-
contrib/sepgsql/hooks.c | 4 +-
20 files changed, 157 insertions(+), 58 deletions(-)
diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h
index 6f4dfa0960..a1e933f62e 100644
--- a/src/include/storage/bufmgr.h
+++ b/src/include/storage/bufmgr.h
@@ -69,6 +69,15 @@ extern PGDLLIMPORT bool zero_damaged_pages;
extern PGDLLIMPORT int bgwriter_lru_maxpages;
extern PGDLLIMPORT double bgwriter_lru_multiplier;
extern PGDLLIMPORT bool track_io_timing;
+
+/* effective when prefetching is available */
+#ifdef USE_PREFETCH
+#define DEFAULT_EFFECTIVE_IO_CONCURRENCY 1
+#define DEFAULT_MAINTENANCE_IO_CONCURRENCY 10
+#else
+#define DEFAULT_EFFECTIVE_IO_CONCURRENCY 0
+#define DEFAULT_MAINTENANCE_IO_CONCURRENCY 0
+#endif
extern PGDLLIMPORT int effective_io_concurrency;
extern PGDLLIMPORT int maintenance_io_concurrency;
diff --git a/src/include/utils/ps_status.h b/src/include/utils/ps_status.h
index bba463591f..3bf212e3fd 100644
--- a/src/include/utils/ps_status.h
+++ b/src/include/utils/ps_status.h
@@ -12,6 +12,12 @@
#ifndef PS_STATUS_H
#define PS_STATUS_H
+/* Disabled on Windows as the performance overhead can be significant */
+#ifdef WIN32
+#define DEFAULT_UPDATE_PROCESS_TITLE false
+#else
+#define DEFAULT_UPDATE_PROCESS_TITLE true
+#endif
extern PGDLLIMPORT bool update_process_title;
extern char **save_ps_display_args(int argc, char **argv);
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index fd5103a78e..f45c95faf6 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -75,7 +75,7 @@
* User-tweakable parameters
*/
int DefaultXactIsoLevel = XACT_READ_COMMITTED;
-int XactIsoLevel;
+int XactIsoLevel = XACT_READ_COMMITTED;
bool DefaultXactReadOnly = false;
bool XactReadOnly;
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 8f10effe3a..be54c23187 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -131,7 +131,7 @@ bool wal_init_zero = true;
bool wal_recycle = true;
bool log_checkpoints = true;
int sync_method = DEFAULT_SYNC_METHOD;
-int wal_level = WAL_LEVEL_MINIMAL;
+int wal_level = WAL_LEVEL_REPLICA;
int CommitDelay = 0; /* precommit delay in microseconds */
int CommitSiblings = 5; /* # concurrent xacts needed to sleep */
int wal_retrieve_retry_interval = 5000;
diff --git a/src/backend/libpq/be-secure.c b/src/backend/libpq/be-secure.c
index e3e54713e8..c8963572a7 100644
--- a/src/backend/libpq/be-secure.c
+++ b/src/backend/libpq/be-secure.c
@@ -58,8 +58,8 @@ char *SSLECDHCurve;
/* GUC variable: if false, prefer client ciphers */
bool SSLPreferServerCiphers;
-int ssl_min_protocol_version;
-int ssl_max_protocol_version;
+int ssl_min_protocol_version = PG_TLS1_2_VERSION;
+int ssl_max_protocol_version = PG_TLS_ANY;
/* ------------------------------------------------------------ */
/* Procedures common to all secure sessions */
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 30fb576ac3..0b637ba6a2 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -196,7 +196,7 @@ BackgroundWorker *MyBgworkerEntry = NULL;
/* The socket number we are listening for connections on */
-int PostPortNumber;
+int PostPortNumber = DEF_PGPORT;
/* The directory names for Unix socket(s) */
char *Unix_socket_directories;
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c
index 6b95381481..73d30bf619 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -142,22 +142,22 @@ bool track_io_timing = false;
* for buffers not belonging to tablespaces that have their
* effective_io_concurrency parameter set.
*/
-int effective_io_concurrency = 0;
+int effective_io_concurrency = DEFAULT_EFFECTIVE_IO_CONCURRENCY;
/*
* Like effective_io_concurrency, but used by maintenance code paths that might
* benefit from a higher setting because they work on behalf of many sessions.
* Overridden by the tablespace setting of the same name.
*/
-int maintenance_io_concurrency = 0;
+int maintenance_io_concurrency = DEFAULT_MAINTENANCE_IO_CONCURRENCY;
/*
* GUC variables about triggering kernel writeback for buffers written; OS
* dependent defaults are set via the GUC mechanism.
*/
-int checkpoint_flush_after = 0;
-int bgwriter_flush_after = 0;
-int backend_flush_after = 0;
+int checkpoint_flush_after = DEFAULT_CHECKPOINT_FLUSH_AFTER;
+int bgwriter_flush_after = DEFAULT_BGWRITER_FLUSH_AFTER;
+int backend_flush_after = DEFAULT_BACKEND_FLUSH_AFTER;
/* local state for StartBufferIO and related functions */
static BufferDesc *InProgressBuf = NULL;
diff --git a/src/backend/storage/ipc/dsm_impl.c b/src/backend/storage/ipc/dsm_impl.c
index e1b90c5de4..6ddd46a4e7 100644
--- a/src/backend/storage/ipc/dsm_impl.c
+++ b/src/backend/storage/ipc/dsm_impl.c
@@ -109,7 +109,7 @@ const struct config_enum_entry dynamic_shared_memory_options[] = {
};
/* Implementation selector. */
-int dynamic_shared_memory_type;
+int dynamic_shared_memory_type = DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE;
/* Amount of space reserved for DSM segments in the main area. */
int min_dynamic_shared_memory;
diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c
index d32cb11436..8cd5262a3c 100644
--- a/src/backend/utils/adt/xml.c
+++ b/src/backend/utils/adt/xml.c
@@ -94,8 +94,8 @@
/* GUC variables */
-int xmlbinary;
-int xmloption;
+int xmlbinary = XMLBINARY_BASE64;
+int xmloption = XMLOPTION_CONTENT;
#ifdef USE_LIBXML
diff --git a/src/backend/utils/cache/plancache.c b/src/backend/utils/cache/plancache.c
index 0d6a295674..cc943205d3 100644
--- a/src/backend/utils/cache/plancache.c
+++ b/src/backend/utils/cache/plancache.c
@@ -116,7 +116,7 @@ static void PlanCacheObjectCallback(Datum arg, int cacheid, uint32 hashvalue);
static void PlanCacheSysCallback(Datum arg, int cacheid, uint32 hashvalue);
/* GUC parameter */
-int plan_cache_mode;
+int plan_cache_mode = PLAN_CACHE_MODE_AUTO;
/*
* InitPlanCache: initialize module during InitPostgres.
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 6e0a66c29e..2585e24845 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -107,7 +107,7 @@ extern bool redirection_done;
emit_log_hook_type emit_log_hook = NULL;
/* GUC parameters */
-int Log_error_verbosity = PGERROR_VERBOSE;
+int Log_error_verbosity = PGERROR_DEFAULT;
char *Log_line_prefix = NULL; /* format for extra log line info */
int Log_destination = LOG_DESTINATION_STDERR;
char *Log_destination_string = NULL;
diff --git a/src/backend/utils/init/globals.c b/src/backend/utils/init/globals.c
index 1a5d29ac9b..00bceec8fa 100644
--- a/src/backend/utils/init/globals.c
+++ b/src/backend/utils/init/globals.c
@@ -133,8 +133,8 @@ int max_parallel_maintenance_workers = 2;
* MaxBackends is computed by PostmasterMain after modules have had a chance to
* register background workers.
*/
-int NBuffers = 1000;
-int MaxConnections = 90;
+int NBuffers = 16384;
+int MaxConnections = 100;
int max_worker_processes = 8;
int max_parallel_workers = 8;
int MaxBackends = 0;
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 6f21752b84..6657f0d92e 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -1382,6 +1382,89 @@ check_GUC_name_for_parameter_acl(const char *name)
return false;
}
+/*
+ * Routine in charge of checking that the initial value of a GUC is the
+ * same when declared and when loaded to prevent anybody looking at the
+ * C declarations of these GUCS from being fooled by mismatched values.
+ *
+ * The following validation rules apply:
+ * bool - can be false, otherwise must be same as the boot_val
+ * int - can be 0, otherwise must be same as the boot_val
+ * real - can be 0.0, otherwise must be same as the boot_val
+ * string - can be NULL, otherwise must be strcmp equal to the boot_val
+ * enum - must be same as the boot_val
+ */
+#ifdef USE_ASSERT_CHECKING
+static bool
+check_GUC_init(struct config_generic *gconf)
+{
+ switch (gconf->vartype)
+ {
+ case PGC_BOOL:
+ {
+ struct config_bool *conf = (struct config_bool *) gconf;
+
+ if (*conf->variable && !conf->boot_val)
+ {
+ elog(LOG, "GUC (PGC_BOOL) %s, boot_val=%d, C-var=%d",
+ conf->gen.name, conf->boot_val, *conf->variable);
+ return false;
+ }
+ break;
+ }
+ case PGC_INT:
+ {
+ struct config_int *conf = (struct config_int *) gconf;
+
+ if (*conf->variable != 0 && *conf->variable != conf->boot_val)
+ {
+ elog(LOG, "GUC (PGC_INT) %s, boot_val=%d, C-var=%d",
+ conf->gen.name, conf->boot_val, *conf->variable);
+ return false;
+ }
+ break;
+ }
+ case PGC_REAL:
+ {
+ struct config_real *conf = (struct config_real *) gconf;
+
+ if (*conf->variable != 0.0 && *conf->variable != conf->boot_val)
+ {
+ elog(LOG, "GUC (PGC_REAL) %s, boot_val=%g, C-var=%g",
+ conf->gen.name, conf->boot_val, *conf->variable);
+ return false;
+ }
+ break;
+ }
+ case PGC_STRING:
+ {
+ struct config_string *conf = (struct config_string *) gconf;
+
+ if (*conf->variable != NULL && strcmp(*conf->variable, conf->boot_val) != 0)
+ {
+ elog(LOG, "GUC (PGC_STRING) %s, boot_val=%s, C-var=%s",
+ conf->gen.name, conf->boot_val ? conf->boot_val : "<null>", *conf->variable);
+ return false;
+ }
+ break;
+ }
+ case PGC_ENUM:
+ {
+ struct config_enum *conf = (struct config_enum *) gconf;
+
+ if (*conf->variable != conf->boot_val)
+ {
+ elog(LOG, "GUC (PGC_ENUM) %s, boot_val=%d, C-var=%d",
+ conf->gen.name, conf->boot_val, *conf->variable);
+ return false;
+ }
+ break;
+ }
+ }
+
+ return true;
+}
+#endif
/*
* Initialize GUC options during program startup.
@@ -1413,6 +1496,9 @@ InitializeGUCOptions(void)
hash_seq_init(&status, guc_hashtab);
while ((hentry = (GUCHashEntry *) hash_seq_search(&status)) != NULL)
{
+ /* check mapping between initial and default value */
+ Assert(check_GUC_init(hentry->gucvar));
+
InitializeOneGUCOption(hentry->gucvar);
}
@@ -4654,6 +4740,9 @@ define_custom_variable(struct config_generic *variable)
GUCHashEntry *hentry;
struct config_string *pHolder;
+ /* check mapping between initial and default value */
+ Assert(check_GUC_init(variable));
+
/*
* See if there's a placeholder by the same name.
*/
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 05ab087934..836b49484a 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -526,7 +526,7 @@ int ssl_renegotiation_limit;
* This really belongs in pg_shmem.c, but is defined here so that it doesn't
* need to be duplicated in all the different implementations of pg_shmem.c.
*/
-int huge_pages;
+int huge_pages = HUGE_PAGES_TRY;
int huge_page_size;
/*
@@ -543,7 +543,14 @@ static char *locale_ctype;
static char *server_encoding_string;
static char *server_version_string;
static int server_version_num;
-static int syslog_facility;
+
+#ifdef HAVE_SYSLOG
+#define DEFAULT_SYSLOG_FACILITY LOG_LOCAL0
+#else
+#define DEFAULT_SYSLOG_FACILITY 0
+#endif
+static int syslog_facility = DEFAULT_SYSLOG_FACILITY;
+
static char *timezone_string;
static char *log_timezone_string;
static char *timezone_abbreviations_string;
@@ -559,7 +566,14 @@ static int shared_memory_size_in_huge_pages;
static int wal_block_size;
static bool data_checksums;
static bool integer_datetimes;
-static bool assert_enabled;
+
+#ifdef USE_ASSERT_CHECKING
+#define DEFAULT_ASSERT_ENABLED true
+#else
+#define DEFAULT_ASSERT_ENABLED false
+#endif
+static bool assert_enabled = DEFAULT_ASSERT_ENABLED;
+
static char *recovery_target_timeline_string;
static char *recovery_target_string;
static char *recovery_target_xid_string;
@@ -1181,11 +1195,7 @@ struct config_bool ConfigureNamesBool[] =
GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
},
&assert_enabled,
-#ifdef USE_ASSERT_CHECKING
- true,
-#else
- false,
-#endif
+ DEFAULT_ASSERT_ENABLED,
NULL, NULL, NULL
},
@@ -1357,11 +1367,7 @@ struct config_bool ConfigureNamesBool[] =
gettext_noop("Enables updating of the process title every time a new SQL command is received by the server.")
},
&update_process_title,
-#ifdef WIN32
- false,
-#else
- true,
-#endif
+ DEFAULT_UPDATE_PROCESS_TITLE,
NULL, NULL, NULL
},
@@ -2888,11 +2894,7 @@ struct config_int ConfigureNamesInt[] =
GUC_EXPLAIN
},
&effective_io_concurrency,
-#ifdef USE_PREFETCH
- 1,
-#else
- 0,
-#endif
+ DEFAULT_EFFECTIVE_IO_CONCURRENCY,
0, MAX_IO_CONCURRENCY,
check_effective_io_concurrency, NULL, NULL
},
@@ -2906,11 +2908,7 @@ struct config_int ConfigureNamesInt[] =
GUC_EXPLAIN
},
&maintenance_io_concurrency,
-#ifdef USE_PREFETCH
- 10,
-#else
- 0,
-#endif
+ DEFAULT_MAINTENANCE_IO_CONCURRENCY,
0, MAX_IO_CONCURRENCY,
check_maintenance_io_concurrency, assign_maintenance_io_concurrency,
NULL
@@ -4613,11 +4611,7 @@ struct config_enum ConfigureNamesEnum[] =
NULL
},
&syslog_facility,
-#ifdef HAVE_SYSLOG
- LOG_LOCAL0,
-#else
- 0,
-#endif
+ DEFAULT_SYSLOG_FACILITY,
syslog_facility_options,
NULL, assign_syslog_facility, NULL
},
diff --git a/src/backend/utils/misc/ps_status.c b/src/backend/utils/misc/ps_status.c
index 8520ce76bb..d81a67be79 100644
--- a/src/backend/utils/misc/ps_status.c
+++ b/src/backend/utils/misc/ps_status.c
@@ -30,8 +30,9 @@
#include "utils/ps_status.h"
extern char **environ;
-bool update_process_title = true;
+/* GUC variable */
+bool update_process_title = DEFAULT_UPDATE_PROCESS_TITLE;
/*
* Alternative ways of updating ps display:
diff --git a/contrib/auth_delay/auth_delay.c b/contrib/auth_delay/auth_delay.c
index c3d78e5020..4ca9b4afb1 100644
--- a/contrib/auth_delay/auth_delay.c
+++ b/contrib/auth_delay/auth_delay.c
@@ -21,7 +21,7 @@
PG_MODULE_MAGIC;
/* GUC Variables */
-static int auth_delay_milliseconds;
+static int auth_delay_milliseconds = 0;
/* Original Hook */
static ClientAuthentication_hook_type original_client_auth_hook = NULL;
diff --git a/contrib/pg_prewarm/autoprewarm.c b/contrib/pg_prewarm/autoprewarm.c
index 1843b1862e..fe002b17e0 100644
--- a/contrib/pg_prewarm/autoprewarm.c
+++ b/contrib/pg_prewarm/autoprewarm.c
@@ -103,7 +103,7 @@ static AutoPrewarmSharedState *apw_state = NULL;
/* GUC variables. */
static bool autoprewarm = true; /* start worker? */
-static int autoprewarm_interval; /* dump interval */
+static int autoprewarm_interval = 300; /* dump interval */
/*
* Module load callback.
diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c
index e5aa429995..198e4e84ad 100644
--- a/contrib/pg_stat_statements/pg_stat_statements.c
+++ b/contrib/pg_stat_statements/pg_stat_statements.c
@@ -283,11 +283,11 @@ static const struct config_enum_entry track_options[] =
{NULL, 0, false}
};
-static int pgss_max; /* max # statements to track */
-static int pgss_track; /* tracking level */
-static bool pgss_track_utility; /* whether to track utility commands */
-static bool pgss_track_planning; /* whether to track planning duration */
-static bool pgss_save; /* whether to save stats across shutdown */
+static int pgss_max = 5000; /* max # statements to track */
+static int pgss_track = PGSS_TRACK_TOP; /* tracking level */
+static bool pgss_track_utility = true; /* whether to track utility commands */
+static bool pgss_track_planning = false ; /* whether to track planning duration */
+static bool pgss_save = true; /* whether to save stats across shutdown */
#define pgss_enabled(level) \
diff --git a/contrib/pg_trgm/trgm_op.c b/contrib/pg_trgm/trgm_op.c
index 154346398a..2c644bc148 100644
--- a/contrib/pg_trgm/trgm_op.c
+++ b/contrib/pg_trgm/trgm_op.c
@@ -68,7 +68,7 @@ _PG_init(void)
"Sets the threshold used by the % operator.",
"Valid range is 0.0 .. 1.0.",
&similarity_threshold,
- 0.3,
+ 0.3f,
0.0,
1.0,
PGC_USERSET,
@@ -80,7 +80,7 @@ _PG_init(void)
"Sets the threshold used by the <% operator.",
"Valid range is 0.0 .. 1.0.",
&word_similarity_threshold,
- 0.6,
+ 0.6f,
0.0,
1.0,
PGC_USERSET,
@@ -92,7 +92,7 @@ _PG_init(void)
"Sets the threshold used by the <<% operator.",
"Valid range is 0.0 .. 1.0.",
&strict_word_similarity_threshold,
- 0.5,
+ 0.5f,
0.0,
1.0,
PGC_USERSET,
diff --git a/contrib/sepgsql/hooks.c b/contrib/sepgsql/hooks.c
index 87fdd972c2..363ac06700 100644
--- a/contrib/sepgsql/hooks.c
+++ b/contrib/sepgsql/hooks.c
@@ -57,7 +57,7 @@ static sepgsql_context_info_t sepgsql_context_info;
/*
* GUC: sepgsql.permissive = (on|off)
*/
-static bool sepgsql_permissive;
+static bool sepgsql_permissive = false;
bool
sepgsql_get_permissive(void)
@@ -68,7 +68,7 @@ sepgsql_get_permissive(void)
/*
* GUC: sepgsql.debug_audit = (on|off)
*/
-static bool sepgsql_debug_audit;
+static bool sepgsql_debug_audit = false;
bool
sepgsql_get_debug_audit(void)
--
2.37.2
On Fri, Oct 28, 2022 at 6:05 PM Michael Paquier <michael@paquier.xyz> wrote:
On Fri, Oct 28, 2022 at 11:48:13AM +0900, Michael Paquier wrote:
Thanks. I have not looked at the checkup logic yet, but the central
declarations seem rather sane, and I have a few comments about the
latter.So, I've had the energy to look at the check logic today, and noticed
that, while the proposed patch is doing the job when loading the
in-core GUCs, nothing is happening for the custom GUCs that could be
loaded through shared_preload_libraries or just from a LOAD command.After adding an extra check in define_custom_variable() (reworking a
bit the interface proposed while on it), I have found a few more
issues than what's been already found on this thread:
- 5 missing spots in pg_stat_statements.
- 3 float rounding issues in pg_trgm.
- 1 spot in pg_prewarm.
- A few more that had no initialization, but these had a default of
false/0/0.0 so it does not influence the end result but I have added
some initializations anyway.With all that addressed, I am finishing with the attached. I have
added some comments for the default definitions depending on the
CFLAGS, explaining the reasons behind the choices made. The CI has
produced a green run, which is not the same as the buildfarm, still
gives some confidence.Thoughts?
LGTM.
The patch was intended to expose mismatches, and it seems to be doing
that job already...
I only had some nitpicks for a couple of the new comments, below:
======
1. src/include/storage/bufmgr.h
+
+/* effective when prefetching is available */
+#ifdef USE_PREFETCH
+#define DEFAULT_EFFECTIVE_IO_CONCURRENCY 1
+#define DEFAULT_MAINTENANCE_IO_CONCURRENCY 10
+#else
+#define DEFAULT_EFFECTIVE_IO_CONCURRENCY 0
+#define DEFAULT_MAINTENANCE_IO_CONCURRENCY 0
+#endif
Maybe avoid the word "effective" since that is also one of the GUC names.
Use uppercase.
SUGGESTION
/* Only applicable when prefetching is available */
======
2. src/include/utils/ps_status.h
+/* Disabled on Windows as the performance overhead can be significant */
+#ifdef WIN32
+#define DEFAULT_UPDATE_PROCESS_TITLE false
+#else
+#define DEFAULT_UPDATE_PROCESS_TITLE true
+#endif
extern PGDLLIMPORT bool update_process_title;
Perhaps put that comment inside the #ifdef WIN32
SUGGESTION
#ifdef WIN32
/* Disabled on Windows because the performance overhead can be significant */
#define DEFAULT_UPDATE_PROCESS_TITLE false
#else
...
======
src/backend/utils/misc/guc.c
3. InitializeGUCOptions
@@ -1413,6 +1496,9 @@ InitializeGUCOptions(void)
hash_seq_init(&status, guc_hashtab);
while ((hentry = (GUCHashEntry *) hash_seq_search(&status)) != NULL)
{
+ /* check mapping between initial and default value */
+ Assert(check_GUC_init(hentry->gucvar));
+
Use uppercase.
Minor re-wording.
SUGGESTION
/* Check the GUC default and declared initial value for consistency */
~~~
4. define_custom_variable
Same as #3.
------
Kind Regards,
Peter Smith
Fujitsu Australia
On Mon, Oct 31, 2022 at 12:01:33PM +1100, Peter Smith wrote:
SUGGESTION
/* Only applicable when prefetching is available */
Thanks for the suggestion. Done this way, then.
+/* Disabled on Windows as the performance overhead can be significant */ +#ifdef WIN32 +#define DEFAULT_UPDATE_PROCESS_TITLE false +#else +#define DEFAULT_UPDATE_PROCESS_TITLE true +#endif extern PGDLLIMPORT bool update_process_title;Perhaps put that comment inside the #ifdef WIN32
I'd keep that externally, as ps_status.h does so.
[...]
SUGGESTION
/* Check the GUC default and declared initial value for consistency */
Okay, fine by me.
I have split the change into two parts at the end: one to refactor and
fix the C declarations, and a second to introduce the check routine
with all the correct declarations in place.
FWIW, I have been testing that with my own in-house modules and it has
caught a few stupid inconsistencies. Let's see how it goes.
--
Michael
On Mon, Oct 31, 2022 at 4:02 PM Michael Paquier <michael@paquier.xyz> wrote:
On Mon, Oct 31, 2022 at 12:01:33PM +1100, Peter Smith wrote:
SUGGESTION
/* Only applicable when prefetching is available */Thanks for the suggestion. Done this way, then.
+/* Disabled on Windows as the performance overhead can be significant */ +#ifdef WIN32 +#define DEFAULT_UPDATE_PROCESS_TITLE false +#else +#define DEFAULT_UPDATE_PROCESS_TITLE true +#endif extern PGDLLIMPORT bool update_process_title;Perhaps put that comment inside the #ifdef WIN32
I'd keep that externally, as ps_status.h does so.
[...]
SUGGESTION
/* Check the GUC default and declared initial value for consistency */Okay, fine by me.
I have split the change into two parts at the end: one to refactor and
fix the C declarations, and a second to introduce the check routine
with all the correct declarations in place.FWIW, I have been testing that with my own in-house modules and it has
caught a few stupid inconsistencies. Let's see how it goes.
Thanks for pushing.
------
Kind Regards,
Peter Smith.
Fujitsu Australia.