diff options
author | Alvaro Herrera | 2008-09-10 18:09:20 +0000 |
---|---|---|
committer | Alvaro Herrera | 2008-09-10 18:09:20 +0000 |
commit | d995a86b11dfec1550b900f2fde5392b7fb16be7 (patch) | |
tree | 02cfde522ac1d814dca3649baed40ebc8d8c76e5 | |
parent | 1340294815f358ae22d41ecd63ef8f2982293d89 (diff) |
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.
-rw-r--r-- | doc/src/sgml/catalogs.sgml | 14 | ||||
-rw-r--r-- | src/backend/utils/misc/guc-file.l | 17 | ||||
-rw-r--r-- | src/backend/utils/misc/guc.c | 59 | ||||
-rw-r--r-- | src/include/catalog/catversion.h | 2 | ||||
-rw-r--r-- | src/include/catalog/pg_proc.h | 2 | ||||
-rw-r--r-- | src/include/utils/guc_tables.h | 2 | ||||
-rw-r--r-- | src/test/regress/expected/rules.out | 2 |
7 files changed, 87 insertions, 11 deletions
diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml index 2181135ac7..947c470d26 100644 --- a/doc/src/sgml/catalogs.sgml +++ b/doc/src/sgml/catalogs.sgml @@ -6414,6 +6414,20 @@ <entry>Allowed values in enum parameters (NULL for non-enum values)</entry> </row> + <row> + <entry><structfield>sourcefile</structfield></entry> + <entry><type>text</type></entry> + <entry>Input file the current value was set from (NULL for values set in + sources other than configuration files). Helpful when using + configuration include directives.</entry> + </row> + <row> + <entry><structfield>sourceline</structfield></entry> + <entry><type>text</type></entry> + <entry>Line number within the sourcefile the current value was set + from (NULL for values set in sources other than configuration files) + </entry> + </row> </tbody> </tgroup> </table> diff --git a/src/backend/utils/misc/guc-file.l b/src/backend/utils/misc/guc-file.l index 6a7441dcbb..1e3e972e8a 100644 --- a/src/backend/utils/misc/guc-file.l +++ b/src/backend/utils/misc/guc-file.l @@ -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 4ca25dc5ab..df64ad5a58 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -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); } @@ -5108,9 +5109,38 @@ 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 e07e7db779..76ff03064f 100644 --- a/src/include/catalog/catversion.h +++ b/src/include/catalog/catversion.h @@ -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 0d2ef978cd..6f0c5e9f2e 100644 --- a/src/include/catalog/pg_proc.h +++ b/src/include/catalog/pg_proc.h @@ -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 e726a875e7..bc569d8095 100644 --- a/src/include/utils/guc_tables.h +++ b/src/include/utils/guc_tables.h @@ -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 f1ed3c37f1..05235428de 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"])); |