From 3b9ec4682c2f1baeeeba10b6d782386656a98f4a Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Wed, 10 Sep 2008 18:09:20 +0000 Subject: [PATCH] Add "source file" and "source line" information to each GUC variable. initdb forced due to changes in the pg_settings view. Magnus Hagander and Alvaro Herrera. --- doc/src/sgml/catalogs.sgml | 16 +++++++- src/backend/utils/misc/guc-file.l | 19 +++++++-- src/backend/utils/misc/guc.c | 61 +++++++++++++++++++++++++---- src/include/catalog/catversion.h | 4 +- src/include/catalog/pg_proc.h | 4 +- src/include/utils/guc_tables.h | 4 +- src/test/regress/expected/rules.out | 2 +- 7 files changed, 93 insertions(+), 17 deletions(-) diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml index f756830a95d..97a624f453e 100644 --- a/doc/src/sgml/catalogs.sgml +++ b/doc/src/sgml/catalogs.sgml @@ -1,4 +1,4 @@ - + @@ -6414,6 +6414,20 @@ Allowed values in enum parameters (NULL for non-enum values) + + sourcefile + text + Input file the current value was set from (NULL for values set in + sources other than configuration files). Helpful when using + configuration include directives. + + + sourceline + text + Line number within the sourcefile the current value was set + from (NULL for values set in sources other than configuration files) + + diff --git a/src/backend/utils/misc/guc-file.l b/src/backend/utils/misc/guc-file.l index a95a35d2f75..5b4a68635b7 100644 --- a/src/backend/utils/misc/guc-file.l +++ b/src/backend/utils/misc/guc-file.l @@ -4,7 +4,7 @@ * * Copyright (c) 2000-2008, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/backend/utils/misc/guc-file.l,v 1.56 2008/08/22 00:20:40 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/utils/misc/guc-file.l,v 1.57 2008/09/10 18:09:19 alvherre Exp $ */ %{ @@ -39,6 +39,8 @@ struct name_value_pair { char *name; char *value; + char *filename; + int sourceline; struct name_value_pair *next; }; @@ -307,8 +309,12 @@ ProcessConfigFile(GucContext context) /* If we got here all the options checked out okay, so apply them. */ for (item = head; item; item = item->next) { - set_config_option(item->name, item->value, context, - PGC_S_FILE, GUC_ACTION_SET, true); + if (set_config_option(item->name, item->value, context, + PGC_S_FILE, GUC_ACTION_SET, true)) + { + set_config_sourcefile(item->name, item->filename, + item->sourceline); + } } /* Remember when we last successfully loaded the config file. */ @@ -483,6 +489,8 @@ ParseConfigFile(const char *config_file, const char *calling_file, pfree(item->value); item->name = opt_name; item->value = opt_value; + item->filename = pstrdup(config_file); + item->sourceline = ConfigFileLineno-1; } else { @@ -490,6 +498,8 @@ ParseConfigFile(const char *config_file, const char *calling_file, item = palloc(sizeof *item); item->name = opt_name; item->value = opt_value; + item->filename = pstrdup(config_file); + item->sourceline = ConfigFileLineno-1; item->next = *head_p; *head_p = item; if (*tail_p == NULL) @@ -502,6 +512,8 @@ ParseConfigFile(const char *config_file, const char *calling_file, item = palloc(sizeof *item); item->name = opt_name; item->value = opt_value; + item->filename = pstrdup(config_file); + item->sourceline = ConfigFileLineno-1; item->next = NULL; if (*head_p == NULL) *head_p = item; @@ -553,6 +565,7 @@ free_name_value_list(struct name_value_pair *list) pfree(item->name); pfree(item->value); + pfree(item->filename); pfree(item); item = next; } diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 149817e6c96..4cc1ef3a94e 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -10,7 +10,7 @@ * Written by Peter Eisentraut . * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.470 2008/08/25 15:11:00 mha Exp $ + * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.471 2008/09/10 18:09:19 alvherre Exp $ * *-------------------------------------------------------------------- */ @@ -129,6 +129,8 @@ extern bool optimize_bounded_sort; extern char *SSLCipherSuites; #endif +static void set_config_sourcefile(const char *name, char *sourcefile, + int sourceline); static const char *assign_log_destination(const char *value, bool doit, GucSource source); @@ -3200,6 +3202,8 @@ InitializeGUCOptions(void) gconf->reset_source = PGC_S_DEFAULT; gconf->source = PGC_S_DEFAULT; gconf->stack = NULL; + gconf->sourcefile = NULL; + gconf->sourceline = 0; switch (gconf->vartype) { @@ -3541,7 +3545,6 @@ ResetAllOptions(void) PGC_S_SESSION)) elog(ERROR, "failed to reset %s", conf->gen.name); *conf->variable = conf->reset_val; - conf->gen.source = conf->gen.reset_source; break; } case PGC_INT: @@ -3553,7 +3556,6 @@ ResetAllOptions(void) PGC_S_SESSION)) elog(ERROR, "failed to reset %s", conf->gen.name); *conf->variable = conf->reset_val; - conf->gen.source = conf->gen.reset_source; break; } case PGC_REAL: @@ -3565,7 +3567,6 @@ ResetAllOptions(void) PGC_S_SESSION)) elog(ERROR, "failed to reset %s", conf->gen.name); *conf->variable = conf->reset_val; - conf->gen.source = conf->gen.reset_source; break; } case PGC_STRING: @@ -3594,7 +3595,6 @@ ResetAllOptions(void) } set_string_field(conf, conf->variable, str); - conf->gen.source = conf->gen.reset_source; break; } case PGC_ENUM: @@ -3606,11 +3606,12 @@ ResetAllOptions(void) PGC_S_SESSION)) elog(ERROR, "failed to reset %s", conf->gen.name); *conf->variable = conf->reset_val; - conf->gen.source = conf->gen.reset_source; break; } } + gconf->source = gconf->reset_source; + if (gconf->flags & GUC_REPORT) ReportGUCOption(gconf); } @@ -5107,10 +5108,39 @@ set_config_option(const char *name, const char *value, } +/* + * Set the fields for source file and line number the setting came from. + */ +static void +set_config_sourcefile(const char *name, char *sourcefile, int sourceline) +{ + struct config_generic *record; + int elevel; + + /* + * To avoid cluttering the log, only the postmaster bleats loudly + * about problems with the config file. + */ + elevel = IsUnderPostmaster ? DEBUG3 : LOG; + + record = find_option(name, true, elevel); + /* should not happen */ + if (record == NULL) + elog(ERROR, "unrecognized configuration parameter \"%s\"", name); + + if (record->sourcefile) + free(record->sourcefile); + record->sourcefile = guc_strdup(elevel, sourcefile); + record->sourceline = sourceline; +} + /* * Set a config option to the given value. See also set_config_option, * this is just the wrapper to be called from outside GUC. NB: this * is used only for non-transactional operations. + * + * Note: there is no support here for setting source file/line, as it + * is currently not needed. */ void SetConfigOption(const char *name, const char *value, @@ -6144,6 +6174,19 @@ GetConfigOptionByNum(int varnum, const char **values, bool *noshow) } break; } + + /* If the setting came from a config file, set the source location */ + if (conf->source == PGC_S_FILE) + { + values[12] = conf->sourcefile; + snprintf(buffer, sizeof(buffer), "%d", conf->sourceline); + values[13] = pstrdup(buffer); + } + else + { + values[12] = NULL; + values[13] = NULL; + } } /* @@ -6179,7 +6222,7 @@ show_config_by_name(PG_FUNCTION_ARGS) * show_all_settings - equiv to SHOW ALL command but implemented as * a Table Function. */ -#define NUM_PG_SETTINGS_ATTS 12 +#define NUM_PG_SETTINGS_ATTS 14 Datum show_all_settings(PG_FUNCTION_ARGS) @@ -6231,6 +6274,10 @@ show_all_settings(PG_FUNCTION_ARGS) TEXTOID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 12, "enumvals", TEXTOID, -1, 0); + TupleDescInitEntry(tupdesc, (AttrNumber) 13, "sourcefile", + TEXTOID, -1, 0); + TupleDescInitEntry(tupdesc, (AttrNumber) 14, "sourceline", + INT4OID, -1, 0); /* * Generate attribute metadata needed later to produce tuples from raw diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h index 272093e5a00..6e4b4d40f9d 100644 --- a/src/include/catalog/catversion.h +++ b/src/include/catalog/catversion.h @@ -37,7 +37,7 @@ * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.484 2008/09/08 00:47:41 tgl Exp $ + * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.485 2008/09/10 18:09:20 alvherre Exp $ * *------------------------------------------------------------------------- */ @@ -53,6 +53,6 @@ */ /* yyyymmddN */ -#define CATALOG_VERSION_NO 200809071 +#define CATALOG_VERSION_NO 200809101 #endif diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h index cf946508aeb..06c970372c9 100644 --- a/src/include/catalog/pg_proc.h +++ b/src/include/catalog/pg_proc.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.513 2008/09/06 00:01:24 tgl Exp $ + * $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.514 2008/09/10 18:09:20 alvherre Exp $ * * NOTES * The script catalog/genbki.sh reads this file and generates .bki @@ -3159,7 +3159,7 @@ DATA(insert OID = 2077 ( current_setting PGNSP PGUID 12 1 0 0 f f t f s 1 25 "2 DESCR("SHOW X as a function"); DATA(insert OID = 2078 ( set_config PGNSP PGUID 12 1 0 0 f f f f v 3 25 "25 25 16" _null_ _null_ _null_ set_config_by_name _null_ _null_ _null_ )); DESCR("SET X as a function"); -DATA(insert OID = 2084 ( pg_show_all_settings PGNSP PGUID 12 1 1000 0 f f t t s 0 2249 "" "{25,25,25,25,25,25,25,25,25,25,25,25}" "{o,o,o,o,o,o,o,o,o,o,o,o}" "{name,setting,unit,category,short_desc,extra_desc,context,vartype,source,min_val,max_val,enumvals}" show_all_settings _null_ _null_ _null_ )); +DATA(insert OID = 2084 ( pg_show_all_settings PGNSP PGUID 12 1 1000 0 f f t t s 0 2249 "" "{25,25,25,25,25,25,25,25,25,25,25,25,25,23}" "{o,o,o,o,o,o,o,o,o,o,o,o,o,o}" "{name,setting,unit,category,short_desc,extra_desc,context,vartype,source,min_val,max_val,enumvals,sourcefile,sourceline}" show_all_settings _null_ _null_ _null_ )); DESCR("SHOW ALL as a function"); DATA(insert OID = 1371 ( pg_lock_status PGNSP PGUID 12 1 1000 0 f f t t v 0 2249 "" "{25,26,26,23,21,25,28,26,26,21,25,23,25,16}" "{o,o,o,o,o,o,o,o,o,o,o,o,o,o}" "{locktype,database,relation,page,tuple,virtualxid,transactionid,classid,objid,objsubid,virtualtransaction,pid,mode,granted}" pg_lock_status _null_ _null_ _null_ )); DESCR("view system lock information"); diff --git a/src/include/utils/guc_tables.h b/src/include/utils/guc_tables.h index 9e52adfcc8b..436b003286c 100644 --- a/src/include/utils/guc_tables.h +++ b/src/include/utils/guc_tables.h @@ -7,7 +7,7 @@ * * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/include/utils/guc_tables.h,v 1.41 2008/03/17 17:45:09 mha Exp $ + * $PostgreSQL: pgsql/src/include/utils/guc_tables.h,v 1.42 2008/09/10 18:09:20 alvherre Exp $ * *------------------------------------------------------------------------- */ @@ -126,6 +126,8 @@ struct config_generic GucSource reset_source; /* source of the reset_value */ GucSource source; /* source of the current actual value */ GucStack *stack; /* stacked prior values */ + char *sourcefile; /* file this settings is from (NULL if not file) */ + int sourceline; /* line in source file */ }; /* bit values in flags field */ diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index f1ed3c37f1c..05235428de7 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1287,7 +1287,7 @@ SELECT viewname, definition FROM pg_views WHERE schemaname <> 'information_schem pg_prepared_xacts | SELECT p.transaction, p.gid, p.prepared, u.rolname AS owner, d.datname AS database FROM ((pg_prepared_xact() p(transaction, gid, prepared, ownerid, dbid) LEFT JOIN pg_authid u ON ((p.ownerid = u.oid))) LEFT JOIN pg_database d ON ((p.dbid = d.oid))); pg_roles | SELECT pg_authid.rolname, pg_authid.rolsuper, pg_authid.rolinherit, pg_authid.rolcreaterole, pg_authid.rolcreatedb, pg_authid.rolcatupdate, pg_authid.rolcanlogin, pg_authid.rolconnlimit, '********'::text AS rolpassword, pg_authid.rolvaliduntil, pg_authid.rolconfig, pg_authid.oid FROM pg_authid; pg_rules | SELECT n.nspname AS schemaname, c.relname AS tablename, r.rulename, pg_get_ruledef(r.oid) AS definition FROM ((pg_rewrite r JOIN pg_class c ON ((c.oid = r.ev_class))) LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) WHERE (r.rulename <> '_RETURN'::name); - pg_settings | SELECT a.name, a.setting, a.unit, a.category, a.short_desc, a.extra_desc, a.context, a.vartype, a.source, a.min_val, a.max_val, a.enumvals FROM pg_show_all_settings() a(name, setting, unit, category, short_desc, extra_desc, context, vartype, source, min_val, max_val, enumvals); + pg_settings | SELECT a.name, a.setting, a.unit, a.category, a.short_desc, a.extra_desc, a.context, a.vartype, a.source, a.min_val, a.max_val, a.enumvals, a.sourcefile, a.sourceline FROM pg_show_all_settings() a(name, setting, unit, category, short_desc, extra_desc, context, vartype, source, min_val, max_val, enumvals, sourcefile, sourceline); pg_shadow | SELECT pg_authid.rolname AS usename, pg_authid.oid AS usesysid, pg_authid.rolcreatedb AS usecreatedb, pg_authid.rolsuper AS usesuper, pg_authid.rolcatupdate AS usecatupd, pg_authid.rolpassword AS passwd, (pg_authid.rolvaliduntil)::abstime AS valuntil, pg_authid.rolconfig AS useconfig FROM pg_authid WHERE pg_authid.rolcanlogin; pg_stat_activity | SELECT s.datid, d.datname, s.procpid, s.usesysid, u.rolname AS usename, s.current_query, s.waiting, s.xact_start, s.query_start, s.backend_start, s.client_addr, s.client_port FROM pg_database d, pg_stat_get_activity(NULL::integer) s(datid, procpid, usesysid, current_query, waiting, xact_start, query_start, backend_start, client_addr, client_port), pg_authid u WHERE ((s.datid = d.oid) AND (s.usesysid = u.oid)); pg_stat_all_indexes | SELECT c.oid AS relid, i.oid AS indexrelid, n.nspname AS schemaname, c.relname, i.relname AS indexrelname, pg_stat_get_numscans(i.oid) AS idx_scan, pg_stat_get_tuples_returned(i.oid) AS idx_tup_read, pg_stat_get_tuples_fetched(i.oid) AS idx_tup_fetch FROM (((pg_class c JOIN pg_index x ON ((c.oid = x.indrelid))) JOIN pg_class i ON ((i.oid = x.indexrelid))) LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) WHERE (c.relkind = ANY (ARRAY['r'::"char", 't'::"char"]));