Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3dc37cd

Browse files
committed
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 declareconfiguration parameters. The postmaster has no knowledge of suchmodules when it reads the postgresql.conf file. Rather than allowingtotally unknown configuration parameters, the concept of a variable"class" is introduced. Variables that belongs to a declared classes willcreate a placeholder value of string type and will not generate anerror. When a module is loaded, it will declare variables for such aclass and make those variables "consume" any placeholders that has beendefined. Finally, the module will generate warnings for unrecognizedplaceholders defined for its class.More detail:The design is outlined after the suggestions made by Tom Lane and JoeConway in this thread:http://archives.postgresql.org/pgsql-hackers/2004-02/msg00229.phpA new string variable 'custom_variable_classes' is introduced. Thisvariable is a comma separated string of identifiers. Each identifierdenots 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 namein the form <ID>.<ID> as the name of a variable. I also changed so thatthe 'custom_variable_classes', if found, is added first of all variablesin order to remove the order of declaration issue.The guc_variables table is made more dynamic. It is originally createdwith 20% slack and can grow dynamically. A capacity is introduced toavoid resizing every time a new variable is added. guc_variables andnum_guc_variables becomes static (hidden).The GucInfoMain now uses the new function get_guc_variables() andGetNumConfigOptions instead or using the guc_variables directly.The find_option() function, when passed a missing name, will check ifthe name is qualified. If the name is qualified and if the qualifierdenotes a class included in the 'custom_variable_classes', a placeholdervariable will be created. Such a placeholder will not participate in alist operation but will otherwise function as a normal string variable.Define<type>GucVariable() functions will be added, one for each variabletype. 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 callto these functions will define a new GUC-variable. If a placeholderexists it will be replaced but it's value will be used in place of thedefault value. The valueAddr is assumed ot point at a default value whenthe define function is called. The only constraint that is imposed on aCustom 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 completedits variable definitions. At that time, no placeholders should remainfor the class that the module uses. If they do, elog(INFO, ...) messageswill be issued to inform the user that unrecognized variables arepresent.Thomas Hallgren
1 parentcfbfdc5 commit3dc37cd

File tree

7 files changed

+555
-31
lines changed

7 files changed

+555
-31
lines changed

‎doc/src/sgml/runtime.sgml

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.263 2004/04/29 04:37:09 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.264 2004/05/26 15:07:33 momjian Exp $
33
-->
44

55
<Chapter Id="runtime">
@@ -2924,6 +2924,60 @@ dynamic_library_path = '/usr/local/lib/postgresql:/home/my_project/lib:$libdir'
29242924
</variablelist>
29252925
</sect2>
29262926

2927+
<sect2 id="runtime-config-custom">
2928+
<title>Customized Options</title>
2929+
2930+
<para>
2931+
The following was designed to allow options not normally known to
2932+
<productname>PostgreSQL</productname> to be declared in the posgresql.conf
2933+
file and/or manipulated using the <command>SET</command> in a controlled
2934+
manner so that add-on modules to the postgres proper (such as lanugage
2935+
mappings for triggers and functions) can be configured in a unified way.
2936+
</para>
2937+
2938+
<variablelist>
2939+
2940+
<varlistentry id="guc-custom-variable-classes" xreflabel="custom-variable-classes">
2941+
<term><varname>custom_variable_classes</varname> (<type>string</type>)</term>
2942+
<indexterm><primary>custom_variable_classes</></>
2943+
<listitem>
2944+
<para>
2945+
This variable specifies one or several classes to be used for custom
2946+
variables. A custom variable is a variable not normally known to
2947+
the <productname>PostgreSQL</productname> proper but used by some add
2948+
on module.
2949+
</para>
2950+
2951+
<para>
2952+
Aribtrary variables can be defined for each class specified here. Those
2953+
variables will be treated as placeholders and have no meaning until the
2954+
module that defines them is loaded. When a module for a specific class is
2955+
loaded, it will add the proper variable definitions for the class
2956+
associated with it, convert any placeholder values according to those
2957+
definitions, and issue warnings for any placeholders that then remains.
2958+
</para>
2959+
2960+
<para>
2961+
Here is an example what custom variables might look like:
2962+
2963+
<programlisting>
2964+
custom_variable_class = 'plr,pljava'
2965+
plr.foo = '/usr/lib/R'
2966+
pljava.baz = 1
2967+
plruby.var = true <== this one would generate an error
2968+
</programlisting>
2969+
</para>
2970+
2971+
<para>
2972+
This option can only be set at server start or in the
2973+
<filename>postgresql.conf</filename> configuration file.
2974+
</para>
2975+
2976+
</listitem>
2977+
</varlistentry>
2978+
</variablelist>
2979+
</sect2>
2980+
29272981
<sect2 id="runtime-config-developer">
29282982
<title>Developer Options</title>
29292983

‎src/backend/parser/gram.y

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.456 2004/05/2613:56:51 momjian Exp $
14+
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.457 2004/05/2615:07:37 momjian Exp $
1515
*
1616
* HISTORY
1717
* AUTHORDATEMAJOR EVENT
@@ -310,7 +310,7 @@ static void doNegateFloat(Value *v);
310310
%type<str>Sconstcomment_text
311311
%type<str>UserIdopt_booleanColId_or_Sconst
312312
%type<list>var_listvar_list_or_default
313-
%type<str>ColIdColLabeltype_nameparam_name
313+
%type<str>ColIdColLabelvar_nametype_nameparam_name
314314
%type<node>var_valuezone_value
315315

316316
%type<keyword>unreserved_keywordfunc_name_keyword
@@ -859,14 +859,14 @@ VariableSetStmt:
859859
}
860860
;
861861

862-
set_rest:ColIdTOvar_list_or_default
862+
set_rest:var_nameTOvar_list_or_default
863863
{
864864
VariableSetStmt *n = makeNode(VariableSetStmt);
865865
n->name =$1;
866866
n->args =$3;
867867
$$ = n;
868868
}
869-
|ColId'='var_list_or_default
869+
|var_name'='var_list_or_default
870870
{
871871
VariableSetStmt *n = makeNode(VariableSetStmt);
872872
n->name =$1;
@@ -919,6 +919,19 @@ set_rest: ColId TO var_list_or_default
919919
}
920920
;
921921

922+
var_name:
923+
ColId{$$ =$1; }
924+
|var_name'.'ColId
925+
{
926+
int qLen = strlen($1);
927+
char* qualName = palloc(qLen + strlen($3) +2);
928+
strcpy(qualName, $1);
929+
qualName[qLen] ='.';
930+
strcpy(qualName + qLen +1, $3);
931+
$$ = qualName;
932+
}
933+
;
934+
922935
var_list_or_default:
923936
var_list{$$ =$1; }
924937
|DEFAULT{$$ = NIL; }

‎src/backend/utils/misc/guc-file.l

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
66
*
7-
* $PostgreSQL: pgsql/src/backend/utils/misc/guc-file.l,v 1.21 2004/02/24 22:06:32 tgl Exp $
7+
* $PostgreSQL: pgsql/src/backend/utils/misc/guc-file.l,v 1.22 2004/05/26 15:07:38 momjian Exp $
88
*/
99

1010
%{
@@ -34,6 +34,7 @@ enum {
3434
GUC_REAL =4,
3535
GUC_EQUALS =5,
3636
GUC_UNQUOTED_STRING =6,
37+
GUC_QUALIFIED_ID =7,
3738
GUC_EOL =99,
3839
GUC_ERROR =100
3940
};
@@ -65,6 +66,7 @@ LETTER [A-Za-z_\200-\377]
6566
LETTER_OR_DIGIT [A-Za-z_0-9\200-\377]
6667

6768
ID {LETTER}{LETTER_OR_DIGIT}*
69+
QUALIFIED_ID {ID}"."{ID}
6870

6971
UNQUOTED_STRING {LETTER}({LETTER_OR_DIGIT}|[-._:/])*
7072
STRING \'([^'\n]|\\.)*\'
@@ -76,6 +78,7 @@ STRING \'([^'\n]|\\.)*\'
7678
#.*$ /* eat comment */
7779
7880
{ID} return GUC_ID;
81+
{QUALIFIED_ID} return GUC_QUALIFIED_ID;
7982
{STRING} return GUC_STRING;
8083
{UNQUOTED_STRING} return GUC_UNQUOTED_STRING;
8184
{INTEGER} return GUC_INTEGER;
@@ -180,7 +183,7 @@ ProcessConfigFile(GucContext context)
180183
case 0: /* no previous input */
181184
if (token == GUC_EOL) /* empty line */
182185
continue;
183-
if (token != GUC_ID)
186+
if (token != GUC_ID && token != GUC_QUALIFIED_ID)
184187
goto parse_error;
185188
opt_name = strdup(yytext);
186189
if (opt_name == NULL)
@@ -217,6 +220,24 @@ ProcessConfigFile(GucContext context)
217220
if (token != GUC_EOL)
218221
goto parse_error;
219222

223+
if (strcmp(opt_name,"custom_variable_classes") ==0)
224+
{
225+
/* This variable must be added first as it controls the validity
226+
* of other variables
227+
*/
228+
if (!set_config_option(opt_name, opt_value, context,
229+
PGC_S_FILE,false,true))
230+
{
231+
FreeFile(fp);
232+
free(filename);
233+
goto cleanup_exit;
234+
}
235+
236+
/* Don't include in list */
237+
parse_state =0;
238+
break;
239+
}
240+
220241
/* append to list */
221242
item = malloc(sizeof *item);
222243
if (item ==NULL)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp