Extend check_GUC_init() with checks on flag combinations when loading GUCs

This extends the work begun by a73952b, with the addition of a GUC check
for flag combinations in check_GUC_init(), making sure that anything
defined with GUC_NO_SHOW_ALL also includes GUC_NOT_IN_SAMPLE, as first
step.  There has never been any GUCs of this kind in the core code, and
this combination makes little sense as a parameter marked as not fit for
SHOW ALL should not be hidden in postgresql.conf.sample.

Note that GUCs marked with GUC_NO_SHOW_ALL are not listed under
pg_settings or SHOW ALL (still they can be queried individually), making
them unfit for checks via SQL queries in the regression tests that do a
full scan of the parameters available.  The SQL tests are still a bit
incorrect about that, and will be cleaned up in a separate commit.  We
have also discussed the possibility to extend the SQL functions for GUCs
so as they could show more information about parameters defined with
GUC_NO_SHOW_ALL, though it has been concluded that this is not worth the
extra complication in the long run, an enforced policy at initialization
time being enough to do the same job.

Per discussion with Nitin Jadhav and Tom Lane.

Discussion: https://postgr.es/m/CAMm1aWaYe0muu3ABo7iSAgK+OWDS9yNe8GGRYnCyeEpScYKa+g@mail.gmail.com
This commit is contained in:
Michael Paquier 2023-02-06 15:22:04 +09:00
parent d07c2948bf
commit 009f8d1714
1 changed files with 22 additions and 4 deletions

View File

@ -1383,11 +1383,14 @@ check_GUC_name_for_parameter_acl(const char *name)
}
/*
* 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.
* Routine in charge of checking various states of a GUC.
*
* The following validation rules apply:
* This performs two sanity checks. First, it checks 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. Second, it checks for incorrect flag combinations.
*
* The following validation rules apply for the values:
* 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
@ -1398,6 +1401,7 @@ check_GUC_name_for_parameter_acl(const char *name)
static bool
check_GUC_init(struct config_generic *gconf)
{
/* Checks on values */
switch (gconf->vartype)
{
case PGC_BOOL:
@ -1462,6 +1466,20 @@ check_GUC_init(struct config_generic *gconf)
}
}
/* Flag combinations */
/*
* GUC_NO_SHOW_ALL requires GUC_NOT_IN_SAMPLE, as a parameter not part
* of SHOW ALL should not be hidden in postgresql.conf.sample.
*/
if ((gconf->flags & GUC_NO_SHOW_ALL) &&
!(gconf->flags & GUC_NOT_IN_SAMPLE))
{
elog(LOG, "GUC %s flags: NO_SHOW_ALL and !NOT_IN_SAMPLE",
gconf->name);
return false;
}
return true;
}
#endif