Commit 3dc37cd8 authored by Bruce Momjian's avatar Bruce Momjian

The patch adresses the TODO list item "Allow external interfaces to

extend the GUC variable set".

Plugin modules like the pl<lang> modules needs a way to declare
configuration parameters. The postmaster has no knowledge of such
modules when it reads the postgresql.conf file. Rather than allowing
totally unknown configuration parameters, the concept of a variable
"class" is introduced. Variables that belongs to a declared classes will
create a placeholder value of string type and will not generate an
error. When a module is loaded, it will declare variables for such a
class and make those variables "consume" any placeholders that has been
defined. Finally, the module will generate warnings for unrecognized
placeholders defined for its class.

More detail:
The design is outlined after the suggestions made by Tom Lane and Joe
Conway in this thread:

http://archives.postgresql.org/pgsql-hackers/2004-02/msg00229.php

A new string variable 'custom_variable_classes' is introduced. This
variable is a comma separated string of identifiers. Each identifier
denots a 'class' that will allow its members to be added without error.
This variable must be defined in postmaster.conf.

The lexer (guc_file.l) is changed so that it can accept a qualified name
in the form <ID>.<ID> as the name of a variable. I also changed so that
the 'custom_variable_classes', if found, is added first of all variables
in order to remove the order of declaration issue.

The guc_variables table is made more dynamic. It is originally created
with 20% slack and can grow dynamically. A capacity is introduced to
avoid resizing every time a new variable is added. guc_variables and
num_guc_variables becomes static (hidden).

The GucInfoMain now uses the new function get_guc_variables() and
GetNumConfigOptions  instead or using the guc_variables directly.

The find_option() function, when passed a missing name, will check if
the name is qualified. If the name is qualified and if the qualifier
denotes a class included in the 'custom_variable_classes', a placeholder
variable will be created. Such a placeholder will not participate in a
list operation but will otherwise function as a normal string variable.

Define<type>GucVariable() functions will be added, one for each variable
type. They are inteded to be used by add-on modules like the pl<lang>
mappings. Example:

extern void DefineCustomBoolVariable(
         const char* name,
         const char* short_desc,
         const char* long_desc,
         bool* valueAddr,
         GucContext context,
         GucBoolAssignHook assign_hook,
         GucShowHook show_hook);

(I created typedefs for the assign-hook and show-hook functions). A call
to these functions will define a new GUC-variable. If a placeholder
exists it will be replaced but it's value will be used in place of the
default value. The valueAddr is assumed ot point at a default value when
the define function is called. The only constraint that is imposed on a
Custom variable is that its name is qualified.

Finally, a function:

void EmittWarningsOnPlacholders(const char* className)

was added. This function should be called when a module has completed
its variable definitions. At that time, no placeholders should remain
for the class that the module uses. If they do, elog(INFO, ...) messages
will be issued to inform the user that unrecognized variables are
present.

Thomas Hallgren
parent cfbfdc55
<!--
$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.263 2004/04/29 04:37:09 tgl Exp $
$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.264 2004/05/26 15:07:33 momjian Exp $
-->
<Chapter Id="runtime">
......@@ -2924,6 +2924,60 @@ dynamic_library_path = '/usr/local/lib/postgresql:/home/my_project/lib:$libdir'
</variablelist>
</sect2>
<sect2 id="runtime-config-custom">
<title>Customized Options</title>
<para>
The following was designed to allow options not normally known to
<productname>PostgreSQL</productname> to be declared in the posgresql.conf
file and/or manipulated using the <command>SET</command> in a controlled
manner so that add-on modules to the postgres proper (such as lanugage
mappings for triggers and functions) can be configured in a unified way.
</para>
<variablelist>
<varlistentry id="guc-custom-variable-classes" xreflabel="custom-variable-classes">
<term><varname>custom_variable_classes</varname> (<type>string</type>)</term>
<indexterm><primary>custom_variable_classes</></>
<listitem>
<para>
This variable specifies one or several classes to be used for custom
variables. A custom variable is a variable not normally known to
the <productname>PostgreSQL</productname> proper but used by some add
on module.
</para>
<para>
Aribtrary variables can be defined for each class specified here. Those
variables will be treated as placeholders and have no meaning until the
module that defines them is loaded. When a module for a specific class is
loaded, it will add the proper variable definitions for the class
associated with it, convert any placeholder values according to those
definitions, and issue warnings for any placeholders that then remains.
</para>
<para>
Here is an example what custom variables might look like:
<programlisting>
custom_variable_class = 'plr,pljava'
plr.foo = '/usr/lib/R'
pljava.baz = 1
plruby.var = true <== this one would generate an error
</programlisting>
</para>
<para>
This option can only be set at server start or in the
<filename>postgresql.conf</filename> configuration file.
</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
<sect2 id="runtime-config-developer">
<title>Developer Options</title>
......
......@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.456 2004/05/26 13:56:51 momjian Exp $
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.457 2004/05/26 15:07:37 momjian Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
......@@ -310,7 +310,7 @@ static void doNegateFloat(Value *v);
%type <str> Sconst comment_text
%type <str> UserId opt_boolean ColId_or_Sconst
%type <list> var_list var_list_or_default
%type <str> ColId ColLabel type_name param_name
%type <str> ColId ColLabel var_name type_name param_name
%type <node> var_value zone_value
%type <keyword> unreserved_keyword func_name_keyword
......@@ -859,14 +859,14 @@ VariableSetStmt:
}
;
set_rest: ColId TO var_list_or_default
set_rest: var_name TO var_list_or_default
{
VariableSetStmt *n = makeNode(VariableSetStmt);
n->name = $1;
n->args = $3;
$$ = n;
}
| ColId '=' var_list_or_default
| var_name '=' var_list_or_default
{
VariableSetStmt *n = makeNode(VariableSetStmt);
n->name = $1;
......@@ -919,6 +919,19 @@ set_rest: ColId TO var_list_or_default
}
;
var_name:
ColId { $$ = $1; }
| var_name '.' ColId
{
int qLen = strlen($1);
char* qualName = palloc(qLen + strlen($3) + 2);
strcpy(qualName, $1);
qualName[qLen] = '.';
strcpy(qualName + qLen + 1, $3);
$$ = qualName;
}
;
var_list_or_default:
var_list { $$ = $1; }
| DEFAULT { $$ = NIL; }
......
......@@ -4,7 +4,7 @@
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/backend/utils/misc/guc-file.l,v 1.21 2004/02/24 22:06:32 tgl Exp $
* $PostgreSQL: pgsql/src/backend/utils/misc/guc-file.l,v 1.22 2004/05/26 15:07:38 momjian Exp $
*/
%{
......@@ -34,6 +34,7 @@ enum {
GUC_REAL = 4,
GUC_EQUALS = 5,
GUC_UNQUOTED_STRING = 6,
GUC_QUALIFIED_ID = 7,
GUC_EOL = 99,
GUC_ERROR = 100
};
......@@ -65,6 +66,7 @@ LETTER [A-Za-z_\200-\377]
LETTER_OR_DIGIT [A-Za-z_0-9\200-\377]
ID {LETTER}{LETTER_OR_DIGIT}*
QUALIFIED_ID {ID}"."{ID}
UNQUOTED_STRING {LETTER}({LETTER_OR_DIGIT}|[-._:/])*
STRING \'([^'\n]|\\.)*\'
......@@ -76,6 +78,7 @@ STRING \'([^'\n]|\\.)*\'
#.*$ /* eat comment */
{ID} return GUC_ID;
{QUALIFIED_ID} return GUC_QUALIFIED_ID;
{STRING} return GUC_STRING;
{UNQUOTED_STRING} return GUC_UNQUOTED_STRING;
{INTEGER} return GUC_INTEGER;
......@@ -180,7 +183,7 @@ ProcessConfigFile(GucContext context)
case 0: /* no previous input */
if (token == GUC_EOL) /* empty line */
continue;
if (token != GUC_ID)
if (token != GUC_ID && token != GUC_QUALIFIED_ID)
goto parse_error;
opt_name = strdup(yytext);
if (opt_name == NULL)
......@@ -217,6 +220,24 @@ ProcessConfigFile(GucContext context)
if (token != GUC_EOL)
goto parse_error;
if (strcmp(opt_name, "custom_variable_classes") == 0)
{
/* This variable must be added first as it controls the validity
* of other variables
*/
if (!set_config_option(opt_name, opt_value, context,
PGC_S_FILE, false, true))
{
FreeFile(fp);
free(filename);
goto cleanup_exit;
}
/* Don't include in list */
parse_state = 0;
break;
}
/* append to list */
item = malloc(sizeof *item);
if (item == NULL)
......
This diff is collapsed.
......@@ -10,7 +10,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/misc/help_config.c,v 1.9 2003/11/29 19:52:04 pgsql Exp $
* $PostgreSQL: pgsql/src/backend/utils/misc/help_config.c,v 1.10 2004/05/26 15:07:39 momjian Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -47,13 +47,15 @@ int
GucInfoMain(void)
{
int i;
struct config_generic **guc_vars = get_guc_variables();
int numOpts = GetNumConfigOptions();
/* Initialize the guc_variables[] array */
build_guc_variables();
for (i = 0; i < num_guc_variables; i++)
for (i = 0; i < numOpts; i++)
{
mixedStruct *var = (mixedStruct *) guc_variables[i];
mixedStruct *var = (mixedStruct *) guc_vars[i];
if (displayStruct(var))
printMixedStruct(var);
......
......@@ -7,7 +7,7 @@
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
* Written by Peter Eisentraut <peter_e@gmx.net>.
*
* $PostgreSQL: pgsql/src/include/utils/guc.h,v 1.45 2004/04/07 05:05:50 momjian Exp $
* $PostgreSQL: pgsql/src/include/utils/guc.h,v 1.46 2004/05/26 15:07:41 momjian Exp $
*--------------------------------------------------------------------
*/
#ifndef GUC_H
......@@ -102,6 +102,15 @@ typedef enum
PGC_S_SESSION /* SET command */
} GucSource;
typedef const char* (*GucStringAssignHook)(const char *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 (*GucRealAssignHook)(double newval, bool doit, GucSource source);
typedef const char* (*GucShowHook)(void);
#define GUC_QUALIFIER_SEPARATOR '.'
/* GUC vars that are actually declared in guc.c, rather than elsewhere */
extern bool log_duration;
extern bool Debug_print_plan;
......@@ -129,6 +138,45 @@ extern int log_min_duration_statement;
extern void SetConfigOption(const char *name, const char *value,
GucContext context, GucSource source);
extern void DefineCustomBoolVariable(
const char* name,
const char* short_desc,
const char* long_desc,
bool* valueAddr,
GucContext context,
GucBoolAssignHook assign_hook,
GucShowHook show_hook);
extern void DefineCustomIntVariable(
const char* name,
const char* short_desc,
const char* long_desc,
int* valueAddr,
GucContext context,
GucIntAssignHook assign_hook,
GucShowHook show_hook);
extern void DefineCustomRealVariable(
const char* name,
const char* short_desc,
const char* long_desc,
double* valueAddr,
GucContext context,
GucRealAssignHook assign_hook,
GucShowHook show_hook);
extern void DefineCustomStringVariable(
const char* name,
const char* short_desc,
const char* long_desc,
char** valueAddr,
GucContext context,
GucStringAssignHook assign_hook,
GucShowHook show_hook);
extern void EmittWarningsOnPlaceholders(const char* className);
extern const char *GetConfigOption(const char *name);
extern const char *GetConfigOptionResetString(const char *name);
extern void ProcessConfigFile(GucContext context);
......
......@@ -7,7 +7,7 @@
*
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/include/utils/guc_tables.h,v 1.10 2004/04/05 03:02:11 momjian Exp $
* $PostgreSQL: pgsql/src/include/utils/guc_tables.h,v 1.11 2004/05/26 15:07:41 momjian Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -51,7 +51,8 @@ enum config_group
COMPAT_OPTIONS_PREVIOUS,
COMPAT_OPTIONS_CLIENT,
DEVELOPER_OPTIONS,
COMPILE_OPTIONS
COMPILE_OPTIONS,
CUSTOM_OPTIONS
};
/*
......@@ -98,6 +99,7 @@ struct config_generic
#define GUC_REPORT 0x0010 /* auto-report changes to client */
#define GUC_NOT_IN_SAMPLE 0x0020 /* not in postgresql.conf.sample */
#define GUC_DISALLOW_IN_FILE 0x0040 /* can't set in postgresql.conf */
#define GUC_CUSTOM_PLACEHOLDER 0x0080 /* placeholder for a custom variable */
/* bit values in status field */
#define GUC_HAVE_TENTATIVE 0x0001 /* tentative value is defined */
......@@ -113,8 +115,8 @@ struct config_bool
/* (all but reset_val are constants) */
bool *variable;
bool reset_val;
bool (*assign_hook) (bool newval, bool doit, GucSource source);
const char *(*show_hook) (void);
GucBoolAssignHook assign_hook;
GucShowHook show_hook;
/* variable fields, initialized at runtime: */
bool session_val;
bool tentative_val;
......@@ -129,8 +131,8 @@ struct config_int
int reset_val;
int min;
int max;
bool (*assign_hook) (int newval, bool doit, GucSource source);
const char *(*show_hook) (void);
GucIntAssignHook assign_hook;
GucShowHook show_hook;
/* variable fields, initialized at runtime: */
int session_val;
int tentative_val;
......@@ -145,8 +147,8 @@ struct config_real
double reset_val;
double min;
double max;
bool (*assign_hook) (double newval, bool doit, GucSource source);
const char *(*show_hook) (void);
GucRealAssignHook assign_hook;
GucShowHook show_hook;
/* variable fields, initialized at runtime: */
double session_val;
double tentative_val;
......@@ -159,8 +161,8 @@ struct config_string
/* (all are constants) */
char **variable;
const char *boot_val;
const char *(*assign_hook) (const char *newval, bool doit, GucSource source);
const char *(*show_hook) (void);
GucStringAssignHook assign_hook;
GucShowHook show_hook;
/* variable fields, initialized at runtime: */
char *reset_val;
char *session_val;
......@@ -173,9 +175,8 @@ extern const char *const config_type_names[];
extern const char *const GucContext_Names[];
extern const char *const GucSource_Names[];
/* the current set of variables */
extern struct config_generic **guc_variables;
extern int num_guc_variables;
/* get the current set of variables */
extern struct config_generic **get_guc_variables(void);
extern void build_guc_variables(void);
......
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