Commit 52a8d4f8 authored by Magnus Hagander's avatar Magnus Hagander

Implement enum type for guc parameters, and convert a couple of existing

variables to it. More need to be converted, but I wanted to get this in
before it conflicts with too much...

Other than just centralising the text-to-int conversion for parameters,
this allows the pg_settings view to contain a list of available options
and allows an error hint to show what values are allowed.
parent 23c356cc
<!-- $PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.162 2008/03/06 18:49:32 momjian Exp $ --> <!-- $PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.163 2008/03/10 12:55:13 mha Exp $ -->
<!-- <!--
Documentation of the system catalogs, directed toward PostgreSQL developers Documentation of the system catalogs, directed toward PostgreSQL developers
--> -->
...@@ -6260,8 +6260,8 @@ ...@@ -6260,8 +6260,8 @@
<row> <row>
<entry><structfield>vartype</structfield></entry> <entry><structfield>vartype</structfield></entry>
<entry><type>text</type></entry> <entry><type>text</type></entry>
<entry>Parameter type (<literal>bool</>, <literal>integer</>, <entry>Parameter type (<literal>bool</>, <literal>enum</>,
<literal>real</>, or <literal>string</>) <literal>integer</>, <literal>real</>, or <literal>string</>)
</entry> </entry>
</row> </row>
<row> <row>
...@@ -6281,6 +6281,12 @@ ...@@ -6281,6 +6281,12 @@
<entry>Maximum allowed value of the parameter (NULL for non-numeric <entry>Maximum allowed value of the parameter (NULL for non-numeric
values)</entry> values)</entry>
</row> </row>
<row>
<entry><structfield>enumvals</structfield></entry>
<entry><type>text</type></entry>
<entry>Allowed values in enum parameters (NULL for non-enum
values)</entry>
</row>
</tbody> </tbody>
</tgroup> </tgroup>
</table> </table>
......
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.169 2008/03/10 03:22:29 tgl Exp $ --> <!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.170 2008/03/10 12:55:13 mha Exp $ -->
<chapter Id="runtime-config"> <chapter Id="runtime-config">
<title>Server Configuration</title> <title>Server Configuration</title>
...@@ -162,7 +162,8 @@ SET ENABLE_SEQSCAN TO OFF; ...@@ -162,7 +162,8 @@ SET ENABLE_SEQSCAN TO OFF;
displaying and updating session run-time parameters. It is equivalent displaying and updating session run-time parameters. It is equivalent
to <command>SHOW</> and <command>SET</>, but can be more convenient to <command>SHOW</> and <command>SET</>, but can be more convenient
to use because it can be joined with other tables, or selected from using to use because it can be joined with other tables, or selected from using
any desired selection condition. any desired selection condition. It also contains more information about
what values are allowed for the parameters.
</para> </para>
</sect1> </sect1>
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright (c) 1996-2008, PostgreSQL Global Development Group * Copyright (c) 1996-2008, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/backend/catalog/system_views.sql,v 1.48 2008/01/01 19:45:48 momjian Exp $ * $PostgreSQL: pgsql/src/backend/catalog/system_views.sql,v 1.49 2008/03/10 12:55:13 mha Exp $
*/ */
CREATE VIEW pg_roles AS CREATE VIEW pg_roles AS
...@@ -173,7 +173,7 @@ CREATE VIEW pg_settings AS ...@@ -173,7 +173,7 @@ CREATE VIEW pg_settings AS
SELECT * SELECT *
FROM pg_show_all_settings() AS A FROM pg_show_all_settings() AS A
(name text, setting text, unit text, category text, short_desc text, extra_desc text, (name text, setting text, unit text, category text, short_desc text, extra_desc text,
context text, vartype text, source text, min_val text, max_val text); context text, vartype text, source text, min_val text, max_val text, enumvals text);
CREATE RULE pg_settings_u AS CREATE RULE pg_settings_u AS
ON UPDATE TO pg_settings ON UPDATE TO pg_settings
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.543 2008/02/17 04:21:05 tgl Exp $ * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.544 2008/03/10 12:55:13 mha Exp $
* *
* NOTES * NOTES
* this is the "main" module of the postgres backend and * this is the "main" module of the postgres backend and
...@@ -85,7 +85,7 @@ CommandDest whereToSendOutput = DestDebug; ...@@ -85,7 +85,7 @@ CommandDest whereToSendOutput = DestDebug;
/* flag for logging end of session */ /* flag for logging end of session */
bool Log_disconnections = false; bool Log_disconnections = false;
LogStmtLevel log_statement = LOGSTMT_NONE; int log_statement = LOGSTMT_NONE;
/* GUC variable for maximum stack depth (measured in kilobytes) */ /* GUC variable for maximum stack depth (measured in kilobytes) */
int max_stack_depth = 100; int max_stack_depth = 100;
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.201 2008/01/01 19:45:53 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.202 2008/03/10 12:55:13 mha Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -80,7 +80,7 @@ sigjmp_buf *PG_exception_stack = NULL; ...@@ -80,7 +80,7 @@ sigjmp_buf *PG_exception_stack = NULL;
extern bool redirection_done; extern bool redirection_done;
/* GUC parameters */ /* GUC parameters */
PGErrorVerbosity Log_error_verbosity = PGERROR_VERBOSE; int Log_error_verbosity = PGERROR_VERBOSE;
char *Log_line_prefix = NULL; /* format for extra log line info */ char *Log_line_prefix = NULL; /* format for extra log line info */
int Log_destination = LOG_DESTINATION_STDERR; int Log_destination = LOG_DESTINATION_STDERR;
......
This diff is collapsed.
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/tcop/tcopprot.h,v 1.92 2008/01/01 19:45:59 momjian Exp $ * $PostgreSQL: pgsql/src/include/tcop/tcopprot.h,v 1.93 2008/03/10 12:55:13 mha Exp $
* *
* OLD COMMENTS * OLD COMMENTS
* This file was created so that other c files could get the two * This file was created so that other c files could get the two
...@@ -42,7 +42,7 @@ typedef enum ...@@ -42,7 +42,7 @@ typedef enum
LOGSTMT_ALL /* log all statements */ LOGSTMT_ALL /* log all statements */
} LogStmtLevel; } LogStmtLevel;
extern LogStmtLevel log_statement; extern int log_statement;
extern List *pg_parse_and_rewrite(const char *query_string, extern List *pg_parse_and_rewrite(const char *query_string,
Oid *paramTypes, int numParams); Oid *paramTypes, int numParams);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/utils/elog.h,v 1.90 2008/01/01 19:45:59 momjian Exp $ * $PostgreSQL: pgsql/src/include/utils/elog.h,v 1.91 2008/03/10 12:55:13 mha Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -283,7 +283,7 @@ typedef enum ...@@ -283,7 +283,7 @@ typedef enum
PGERROR_VERBOSE /* all the facts, ma'am */ PGERROR_VERBOSE /* all the facts, ma'am */
} PGErrorVerbosity; } PGErrorVerbosity;
extern PGErrorVerbosity Log_error_verbosity; extern int Log_error_verbosity;
extern char *Log_line_prefix; extern char *Log_line_prefix;
extern int Log_destination; extern int Log_destination;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Copyright (c) 2000-2008, PostgreSQL Global Development Group * Copyright (c) 2000-2008, PostgreSQL Global Development Group
* Written by Peter Eisentraut <peter_e@gmx.net>. * Written by Peter Eisentraut <peter_e@gmx.net>.
* *
* $PostgreSQL: pgsql/src/include/utils/guc.h,v 1.90 2008/01/01 19:45:59 momjian Exp $ * $PostgreSQL: pgsql/src/include/utils/guc.h,v 1.91 2008/03/10 12:55:13 mha Exp $
*-------------------------------------------------------------------- *--------------------------------------------------------------------
*/ */
#ifndef GUC_H #ifndef GUC_H
...@@ -97,6 +97,7 @@ typedef const char *(*GucStringAssignHook) (const char *newval, bool doit, GucSo ...@@ -97,6 +97,7 @@ typedef const char *(*GucStringAssignHook) (const char *newval, bool doit, GucSo
typedef bool (*GucBoolAssignHook) (bool newval, bool doit, GucSource source); typedef bool (*GucBoolAssignHook) (bool newval, bool doit, GucSource source);
typedef bool (*GucIntAssignHook) (int newval, bool doit, GucSource source); typedef bool (*GucIntAssignHook) (int newval, bool doit, GucSource source);
typedef bool (*GucRealAssignHook) (double newval, bool doit, GucSource source); typedef bool (*GucRealAssignHook) (double newval, bool doit, GucSource source);
typedef bool (*GucEnumAssignHook) (int newval, bool doit, GucSource source);
typedef const char *(*GucShowHook) (void); typedef const char *(*GucShowHook) (void);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/include/utils/guc_tables.h,v 1.38 2008/01/01 19:45:59 momjian Exp $ * $PostgreSQL: pgsql/src/include/utils/guc_tables.h,v 1.39 2008/03/10 12:55:13 mha Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -24,7 +24,8 @@ enum config_type ...@@ -24,7 +24,8 @@ enum config_type
PGC_BOOL, PGC_BOOL,
PGC_INT, PGC_INT,
PGC_REAL, PGC_REAL,
PGC_STRING PGC_STRING,
PGC_ENUM
}; };
union config_var_value union config_var_value
...@@ -33,6 +34,16 @@ union config_var_value ...@@ -33,6 +34,16 @@ union config_var_value
int intval; int intval;
double realval; double realval;
char *stringval; char *stringval;
int enumval;
};
/*
* Enum values are made up of an array of name-value pairs
*/
struct config_enum_entry
{
const char *name;
int val;
}; };
/* /*
...@@ -210,6 +221,19 @@ struct config_string ...@@ -210,6 +221,19 @@ struct config_string
char *reset_val; char *reset_val;
}; };
struct config_enum
{
struct config_generic gen;
/* constant fields, must be set correctly in initial value: */
int *variable;
int boot_val;
const struct config_enum_entry *options;
GucEnumAssignHook assign_hook;
GucShowHook show_hook;
/* variable fields, initialized at runtime: */
int reset_val;
};
/* constant tables corresponding to enums above and in guc.h */ /* constant tables corresponding to enums above and in guc.h */
extern const char *const config_group_names[]; extern const char *const config_group_names[];
extern const char *const config_type_names[]; extern const char *const config_type_names[];
......
...@@ -1287,7 +1287,7 @@ SELECT viewname, definition FROM pg_views WHERE schemaname <> 'information_schem ...@@ -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 xid, gid text, prepared timestamp with time zone, ownerid oid, dbid oid) LEFT JOIN pg_authid u ON ((p.ownerid = u.oid))) LEFT JOIN pg_database d ON ((p.dbid = d.oid))); pg_prepared_xacts | SELECT p.transaction, p.gid, p.prepared, u.rolname AS owner, d.datname AS database FROM ((pg_prepared_xact() p(transaction xid, gid text, prepared timestamp with time zone, ownerid oid, dbid oid) 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_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_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 FROM pg_show_all_settings() a(name text, setting text, unit text, category text, short_desc text, extra_desc text, context text, vartype text, source text, min_val text, max_val text); 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 text, setting text, unit text, category text, short_desc text, extra_desc text, context text, vartype text, source text, min_val text, max_val text, enumvals text);
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_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 d.oid AS datid, d.datname, pg_stat_get_backend_pid(s.backendid) AS procpid, pg_stat_get_backend_userid(s.backendid) AS usesysid, u.rolname AS usename, pg_stat_get_backend_activity(s.backendid) AS current_query, pg_stat_get_backend_waiting(s.backendid) AS waiting, pg_stat_get_backend_xact_start(s.backendid) AS xact_start, pg_stat_get_backend_activity_start(s.backendid) AS query_start, pg_stat_get_backend_start(s.backendid) AS backend_start, pg_stat_get_backend_client_addr(s.backendid) AS client_addr, pg_stat_get_backend_client_port(s.backendid) AS client_port FROM pg_database d, (SELECT pg_stat_get_backend_idset() AS backendid) s, pg_authid u WHERE ((pg_stat_get_backend_dbid(s.backendid) = d.oid) AND (pg_stat_get_backend_userid(s.backendid) = u.oid)); pg_stat_activity | SELECT d.oid AS datid, d.datname, pg_stat_get_backend_pid(s.backendid) AS procpid, pg_stat_get_backend_userid(s.backendid) AS usesysid, u.rolname AS usename, pg_stat_get_backend_activity(s.backendid) AS current_query, pg_stat_get_backend_waiting(s.backendid) AS waiting, pg_stat_get_backend_xact_start(s.backendid) AS xact_start, pg_stat_get_backend_activity_start(s.backendid) AS query_start, pg_stat_get_backend_start(s.backendid) AS backend_start, pg_stat_get_backend_client_addr(s.backendid) AS client_addr, pg_stat_get_backend_client_port(s.backendid) AS client_port FROM pg_database d, (SELECT pg_stat_get_backend_idset() AS backendid) s, pg_authid u WHERE ((pg_stat_get_backend_dbid(s.backendid) = d.oid) AND (pg_stat_get_backend_userid(s.backendid) = 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"])); 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"]));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment