diff options
Diffstat (limited to 'src/backend/utils/misc')
-rw-r--r-- | src/backend/utils/misc/README | 24 | ||||
-rw-r--r-- | src/backend/utils/misc/guc.c | 101 |
2 files changed, 81 insertions, 44 deletions
diff --git a/src/backend/utils/misc/README b/src/backend/utils/misc/README index 263f97790f7..c0f90c9f6c7 100644 --- a/src/backend/utils/misc/README +++ b/src/backend/utils/misc/README @@ -1,4 +1,4 @@ -$PostgreSQL: pgsql/src/backend/utils/misc/README,v 1.7 2007/09/11 00:06:42 tgl Exp $ +$PostgreSQL: pgsql/src/backend/utils/misc/README,v 1.8 2007/12/28 00:23:23 tgl Exp $ GUC IMPLEMENTATION NOTES @@ -28,16 +28,18 @@ function returns "true" then the assignment is completed; if it returns performed. If "doit" is false then the function should simply check validity of newvalue and not change any derived state. The "source" parameter indicates where the new value came from. If it is >= PGC_S_INTERACTIVE, -then we are performing an interactive assignment (e.g., a SET command). -In such cases it is okay for the assign_hook to raise an error via ereport(). -If the function returns false for an interactive assignment then guc.c will -report a generic "invalid value" error message. (An internal ereport() in -an assign_hook is only needed if you want to generate a specialized error -message.) But when source < PGC_S_INTERACTIVE, we are reading a -non-interactive option source, such as postgresql.conf. In this case the -assign_hook should *not* ereport but should just return false if it doesn't -like the newvalue. (An ereport(LOG) call would be acceptable if you feel a -need for a custom complaint in this situation.) +then we are performing an interactive assignment (e.g., a SET command), and +ereport(ERROR) is safe to do. But when source < PGC_S_INTERACTIVE, we are +reading a non-interactive option source, such as postgresql.conf. In this +case the assign_hook should *not* ereport but should just return false if it +doesn't like the newvalue. + +If an assign_hook returns false then guc.c will report a generic "invalid +value for option FOO" error message. If you feel the need to provide a more +specific error message, ereport() it using "GUC_complaint_elevel(source)" +as the error level. Note that this might return either ERROR or a lower level +such as LOG, so the ereport call might or might not return. If it does +return, return false out of the assign_hook. For string variables, the signature for assign hooks is a bit different: const char *assign_hook(const char *newvalue, diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 421449c1bd3..a222eb9023e 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -10,7 +10,7 @@ * Written by Peter Eisentraut <peter_e@gmx.net>. * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.427 2007/12/27 13:02:48 petere Exp $ + * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.428 2007/12/28 00:23:23 tgl Exp $ * *-------------------------------------------------------------------- */ @@ -4157,7 +4157,7 @@ call_string_assign_hook(GucStringAssignHook assign_hook, * If there is an error (non-existing option, invalid value) then an * ereport(ERROR) is thrown *unless* this is called in a context where we * don't want to ereport (currently, startup or SIGHUP config file reread). - * In that case we write a suitable error message via ereport(DEBUG) and + * In that case we write a suitable error message via ereport(LOG) and * return false. This is working around the deficiencies in the ereport * mechanism, so don't blame me. In all other cases, the function * returns true, including cases where the input is valid but we chose @@ -4180,7 +4180,7 @@ set_config_option(const char *name, const char *value, * To avoid cluttering the log, only the postmaster bleats loudly * about problems with the config file. */ - elevel = IsUnderPostmaster ? DEBUG2 : LOG; + elevel = IsUnderPostmaster ? DEBUG3 : LOG; } else if (source == PGC_S_DATABASE || source == PGC_S_USER) elevel = INFO; @@ -4804,6 +4804,41 @@ IsSuperuserConfigOption(const char *name) /* + * GUC_complaint_elevel + * Get the ereport error level to use in an assign_hook's error report. + * + * This should be used by assign hooks that want to emit a custom error + * report (in addition to the generic "invalid value for option FOO" that + * guc.c will provide). Note that the result might be ERROR or a lower + * level, so the caller must be prepared for control to return from ereport, + * or not. If control does return, return false/NULL from the hook function. + * + * At some point it'd be nice to replace this with a mechanism that allows + * the custom message to become the DETAIL line of guc.c's generic message. + */ +int +GUC_complaint_elevel(GucSource source) +{ + int elevel; + + if (source == PGC_S_FILE) + { + /* + * To avoid cluttering the log, only the postmaster bleats loudly + * about problems with the config file. + */ + elevel = IsUnderPostmaster ? DEBUG3 : LOG; + } + else if (source < PGC_S_INTERACTIVE) + elevel = LOG; + else + elevel = ERROR; + + return elevel; +} + + +/* * flatten_set_variable_args * Given a parsenode List as emitted by the grammar for SET, * convert to the flat string representation used by GUC. @@ -6406,9 +6441,8 @@ assign_log_destination(const char *value, bool doit, GucSource source) /* syntax error in list */ pfree(rawstring); list_free(elemlist); - if (source >= PGC_S_INTERACTIVE) - ereport(ERROR, - (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + ereport(GUC_complaint_elevel(source), + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid list syntax for parameter \"log_destination\""))); return NULL; } @@ -6431,9 +6465,8 @@ assign_log_destination(const char *value, bool doit, GucSource source) #endif else { - if (source >= PGC_S_INTERACTIVE) - ereport(ERROR, - (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + ereport(GUC_complaint_elevel(source), + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("unrecognized \"log_destination\" key word: \"%s\"", tok))); pfree(rawstring); @@ -6719,10 +6752,9 @@ assign_phony_autocommit(bool newval, bool doit, GucSource source) { if (!newval) { - if (doit && source >= PGC_S_INTERACTIVE) - ereport(ERROR, - (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("SET AUTOCOMMIT TO OFF is no longer supported"))); + ereport(GUC_complaint_elevel(source), + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("SET AUTOCOMMIT TO OFF is no longer supported"))); return false; } return true; @@ -6791,9 +6823,12 @@ assign_debug_assertions(bool newval, bool doit, GucSource source) { #ifndef USE_ASSERT_CHECKING if (newval) - ereport(ERROR, + { + ereport(GUC_complaint_elevel(source), (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("assertion checking is not supported by this build"))); + return false; + } #endif return true; } @@ -6803,9 +6838,12 @@ assign_ssl(bool newval, bool doit, GucSource source) { #ifndef USE_SSL if (newval) - ereport(ERROR, + { + ereport(GUC_complaint_elevel(source), (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("SSL is not supported by this build"))); + return false; + } #endif return true; } @@ -6815,12 +6853,11 @@ assign_stage_log_stats(bool newval, bool doit, GucSource source) { if (newval && log_statement_stats) { - if (source >= PGC_S_INTERACTIVE) - ereport(ERROR, - (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("cannot enable parameter when \"log_statement_stats\" is true"))); + ereport(GUC_complaint_elevel(source), + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("cannot enable parameter when \"log_statement_stats\" is true"))); /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */ - else if (source != PGC_S_OVERRIDE) + if (source != PGC_S_OVERRIDE) return false; } return true; @@ -6832,14 +6869,13 @@ assign_log_stats(bool newval, bool doit, GucSource source) if (newval && (log_parser_stats || log_planner_stats || log_executor_stats)) { - if (source >= PGC_S_INTERACTIVE) - ereport(ERROR, - (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("cannot enable \"log_statement_stats\" when " - "\"log_parser_stats\", \"log_planner_stats\", " - "or \"log_executor_stats\" is true"))); + ereport(GUC_complaint_elevel(source), + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("cannot enable \"log_statement_stats\" when " + "\"log_parser_stats\", \"log_planner_stats\", " + "or \"log_executor_stats\" is true"))); /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */ - else if (source != PGC_S_OVERRIDE) + if (source != PGC_S_OVERRIDE) return false; } return true; @@ -6851,12 +6887,11 @@ assign_transaction_read_only(bool newval, bool doit, GucSource source) /* Can't go to r/w mode inside a r/o transaction */ if (newval == false && XactReadOnly && IsSubTransaction()) { - if (source >= PGC_S_INTERACTIVE) - ereport(ERROR, - (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("cannot set transaction read-write mode inside a read-only transaction"))); + ereport(GUC_complaint_elevel(source), + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("cannot set transaction read-write mode inside a read-only transaction"))); /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */ - else if (source != PGC_S_OVERRIDE) + if (source != PGC_S_OVERRIDE) return false; } return true; @@ -6934,7 +6969,7 @@ assign_timezone_abbreviations(const char *newval, bool doit, GucSource source) * and we use WARNING message level. */ if (source == PGC_S_FILE) - elevel = IsUnderPostmaster ? DEBUG2 : LOG; + elevel = IsUnderPostmaster ? DEBUG3 : LOG; else elevel = WARNING; if (!load_tzoffsets(newval, doit, elevel)) |