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

Commit262a7bc

Browse files
committed
Allow commenting of variables in postgresql.conf to restore them to
defaults.Zdenek Kotala
1 parentf91ddb7 commit262a7bc

File tree

3 files changed

+137
-28
lines changed

3 files changed

+137
-28
lines changed

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

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* Copyright (c) 2000-2006, PostgreSQL Global Development Group
66
*
7-
* $PostgreSQL: pgsql/src/backend/utils/misc/guc-file.l,v 1.39 2006/08/11 20:08:28 momjian Exp $
7+
* $PostgreSQL: pgsql/src/backend/utils/misc/guc-file.l,v 1.40 2006/08/11 20:15:16 momjian Exp $
88
*/
99

1010
%{
@@ -117,6 +117,7 @@ ProcessConfigFile(GucContext context)
117117
{
118118
intelevel, i;
119119
struct name_value_pair *item, *head, *tail;
120+
char *env;
120121
bool *apply_list = NULL;
121122
intvarcount = 0;
122123
@@ -183,6 +184,58 @@ ProcessConfigFile(GucContext context)
183184
set_config_option(item->name, item->value, context,
184185
PGC_S_FILE, false, true);
185186
187+
if( context == PGC_SIGHUP)
188+
{
189+
/*
190+
* Revert all "untouched" options with reset source PGC_S_FILE to
191+
* default/boot value.
192+
*/
193+
for (i = 0; i < num_guc_variables; i++)
194+
{
195+
struct config_generic *gconf = guc_variables[i];
196+
if ( gconf->reset_source == PGC_S_FILE &&
197+
!(gconf->status & GUC_IN_CONFFILE) )
198+
{
199+
if ( gconf->context == PGC_BACKEND && IsUnderPostmaster)
200+
; /* Be silent. Does any body want message from each session? */
201+
else if (gconf->context == PGC_POSTMASTER)
202+
ereport(elevel,
203+
(errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
204+
errmsg("parameter\"%s\" cannot be changed (commented) after server start; configuration file change ignored",
205+
gconf->name)));
206+
else if(set_config_option(gconf->name,
207+
NULL, context,
208+
PGC_S_FILE,
209+
false, true))
210+
{
211+
GucStack *stack;
212+
/* set correctly source */
213+
gconf->reset_source = PGC_S_DEFAULT;
214+
for (stack = gconf->stack; stack; stack = stack->prev)
215+
if (stack->source == PGC_S_FILE)
216+
stack->source = PGC_S_DEFAULT;
217+
218+
ereport(elevel,
219+
(errcode(ERRCODE_SUCCESSFUL_COMPLETION),
220+
errmsg("configuration option %s falls back to default value", gconf->name)));
221+
}
222+
}
223+
gconf->status &= ~GUC_IN_CONFFILE;
224+
}
225+
226+
/* Revert to environment variable. PGPORT is ignored, because it cannot be
227+
* set in running state.
228+
*/
229+
env = getenv("PGDATESTYLE");
230+
if (env != NULL)
231+
set_config_option("datestyle", env, context,
232+
PGC_S_ENV_VAR, false, true);
233+
234+
env = getenv("PGCLIENTENCODING");
235+
if (env != NULL)
236+
set_config_option("client_encoding", env, context,
237+
PGC_S_ENV_VAR, false, true);
238+
}
186239
187240
cleanup_list:
188241
if (apply_list)

‎src/backend/utils/misc/guc.c

Lines changed: 74 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Written by Peter Eisentraut <peter_e@gmx.net>.
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.334 2006/08/11 20:08:28 momjian Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.335 2006/08/11 20:15:16 momjian Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -2694,39 +2694,39 @@ InitializeGUCOptions(void)
26942694
structconfig_bool*conf= (structconfig_bool*)gconf;
26952695

26962696
if (conf->assign_hook)
2697-
if (!(*conf->assign_hook) (conf->reset_val, true,
2697+
if (!(*conf->assign_hook) (conf->boot_val, true,
26982698
PGC_S_DEFAULT))
26992699
elog(FATAL,"failed to initialize %s to %d",
2700-
conf->gen.name, (int)conf->reset_val);
2701-
*conf->variable=conf->reset_val;
2700+
conf->gen.name, (int)conf->boot_val);
2701+
*conf->variable=conf->reset_val=conf->boot_val;
27022702
break;
27032703
}
27042704
casePGC_INT:
27052705
{
27062706
structconfig_int*conf= (structconfig_int*)gconf;
27072707

2708-
Assert(conf->reset_val >=conf->min);
2709-
Assert(conf->reset_val <=conf->max);
2708+
Assert(conf->boot_val >=conf->min);
2709+
Assert(conf->boot_val <=conf->max);
27102710
if (conf->assign_hook)
2711-
if (!(*conf->assign_hook) (conf->reset_val, true,
2711+
if (!(*conf->assign_hook) (conf->boot_val, true,
27122712
PGC_S_DEFAULT))
27132713
elog(FATAL,"failed to initialize %s to %d",
2714-
conf->gen.name,conf->reset_val);
2715-
*conf->variable=conf->reset_val;
2714+
conf->gen.name,conf->boot_val);
2715+
*conf->variable=conf->reset_val=conf->boot_val;
27162716
break;
27172717
}
27182718
casePGC_REAL:
27192719
{
27202720
structconfig_real*conf= (structconfig_real*)gconf;
27212721

2722-
Assert(conf->reset_val >=conf->min);
2723-
Assert(conf->reset_val <=conf->max);
2722+
Assert(conf->boot_val >=conf->min);
2723+
Assert(conf->boot_val <=conf->max);
27242724
if (conf->assign_hook)
2725-
if (!(*conf->assign_hook) (conf->reset_val, true,
2725+
if (!(*conf->assign_hook) (conf->boot_val, true,
27262726
PGC_S_DEFAULT))
27272727
elog(FATAL,"failed to initialize %s to %g",
2728-
conf->gen.name,conf->reset_val);
2729-
*conf->variable=conf->reset_val;
2728+
conf->gen.name,conf->boot_val);
2729+
*conf->variable=conf->reset_val=conf->boot_val;
27302730
break;
27312731
}
27322732
casePGC_STRING:
@@ -3179,7 +3179,7 @@ AtEOXact_GUC(bool isCommit, bool isSubXact)
31793179
for (i=0;i<num_guc_variables;i++)
31803180
{
31813181
structconfig_generic*gconf=guc_variables[i];
3182-
intmy_status=gconf->status;
3182+
intmy_status=gconf->status& (~GUC_IN_CONFFILE);
31833183
GucStack*stack=gconf->stack;
31843184
booluseTentative;
31853185
boolchanged;
@@ -3726,8 +3726,19 @@ parse_value(int elevel, const struct config_generic *record,
37263726
}
37273727
else
37283728
{
3729-
newval=conf->reset_val;
3730-
*source=conf->gen.reset_source;
3729+
/* Revert value to default if source is configuration file. It is used when
3730+
* configuration parameter is removed/commented out in the config file. Else
3731+
* RESET or SET TO DEFAULT command is called and reset_val is used.
3732+
*/
3733+
if(*source==PGC_S_FILE )
3734+
{
3735+
newval=conf->boot_val;
3736+
}
3737+
else
3738+
{
3739+
newval=conf->reset_val;
3740+
*source=conf->gen.reset_source;
3741+
}
37313742
}
37323743

37333744
if (conf->assign_hook)
@@ -3770,8 +3781,19 @@ parse_value(int elevel, const struct config_generic *record,
37703781
}
37713782
else
37723783
{
3773-
newval=conf->reset_val;
3774-
*source=conf->gen.reset_source;
3784+
/* Revert value to default if source is configuration file. It is used when
3785+
* configuration parameter is removed/commented out in the config file. Else
3786+
* RESET or SET TO DEFAULT command is called and reset_val is used.
3787+
*/
3788+
if(*source==PGC_S_FILE )
3789+
{
3790+
newval=conf->boot_val;
3791+
}
3792+
else
3793+
{
3794+
newval=conf->reset_val;
3795+
*source=conf->gen.reset_source;
3796+
}
37753797
}
37763798

37773799
if (conf->assign_hook)
@@ -3814,8 +3836,19 @@ parse_value(int elevel, const struct config_generic *record,
38143836
}
38153837
else
38163838
{
3817-
newval=conf->reset_val;
3818-
*source=conf->gen.reset_source;
3839+
/* Revert value to default if source is configuration file. It is used when
3840+
* configuration parameter is removed/commented out in the config file. Else
3841+
* RESET or SET TO DEFAULT command is called and reset_val is used.
3842+
*/
3843+
if(*source==PGC_S_FILE )
3844+
{
3845+
newval=conf->boot_val;
3846+
}
3847+
else
3848+
{
3849+
newval=conf->reset_val;
3850+
*source=conf->gen.reset_source;
3851+
}
38193852
}
38203853

38213854
if (conf->assign_hook)
@@ -3849,6 +3882,20 @@ parse_value(int elevel, const struct config_generic *record,
38493882
if (conf->gen.flags&GUC_IS_NAME)
38503883
truncate_identifier(newval,strlen(newval), true);
38513884
}
3885+
elseif (*source==PGC_S_FILE)
3886+
{
3887+
/* Revert value to default when item is removed from config file. */
3888+
if (conf->boot_val!=NULL )
3889+
{
3890+
newval=guc_strdup(elevel,conf->boot_val);
3891+
if (newval==NULL)
3892+
return false;
3893+
}
3894+
else
3895+
{
3896+
return false;
3897+
}
3898+
}
38523899
elseif (conf->reset_val)
38533900
{
38543901
/*
@@ -4053,6 +4100,11 @@ verify_config_option(const char *name, const char *value,
40534100

40544101
if(parse_value(elevel,record,value,&source, false,&newval) )
40554102
{
4103+
/* Mark record like presented in the config file. Be carefull if
4104+
* you use this function for another purpose than config file
4105+
* verification. It causes confusion configfile parser. */
4106+
record->status |=GUC_IN_CONFFILE;
4107+
40564108
if(isNewEqual!=NULL)
40574109
*isNewEqual=is_newvalue_equal(record,value);
40584110
if(isContextOK!=NULL)
@@ -4115,7 +4167,7 @@ set_config_option(const char *name, const char *value,
41154167
* Should we set reset/stacked values?(If so, the behavior is not
41164168
* transactional.)
41174169
*/
4118-
makeDefault=changeVal&& (source <=PGC_S_OVERRIDE)&& (value!=NULL);
4170+
makeDefault=changeVal&& (source <=PGC_S_OVERRIDE)&& (value!=NULL||source==PGC_S_FILE);
41194171

41204172
/*
41214173
* Ignore attempted set if overridden by previously processed setting.

‎src/include/utils/guc_tables.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
99
*
10-
* $PostgreSQL: pgsql/src/include/utils/guc_tables.h,v 1.24 2006/07/27 08:30:41 petere Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/guc_tables.h,v 1.25 2006/08/11 20:15:16 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -143,7 +143,8 @@ struct config_generic
143143
#defineGUC_HAVE_TENTATIVE0x0001/* tentative value is defined */
144144
#defineGUC_HAVE_LOCAL0x0002/* a SET LOCAL has been executed */
145145
#defineGUC_HAVE_STACK0x0004/* we have stacked prior value(s) */
146-
146+
#defineGUC_IN_CONFFILE0x0008/* value shows up in the configuration
147+
file (is not commented) */
147148

148149
/* GUC records for specific variable types */
149150

@@ -153,11 +154,12 @@ struct config_bool
153154
/* these fields must be set correctly in initial value: */
154155
/* (all but reset_val are constants) */
155156
bool*variable;
156-
boolreset_val;
157+
boolboot_val;
157158
GucBoolAssignHookassign_hook;
158159
GucShowHookshow_hook;
159160
/* variable fields, initialized at runtime: */
160161
booltentative_val;
162+
boolreset_val;
161163
};
162164

163165
structconfig_int
@@ -166,13 +168,14 @@ struct config_int
166168
/* these fields must be set correctly in initial value: */
167169
/* (all but reset_val are constants) */
168170
int*variable;
169-
intreset_val;
171+
intboot_val;
170172
intmin;
171173
intmax;
172174
GucIntAssignHookassign_hook;
173175
GucShowHookshow_hook;
174176
/* variable fields, initialized at runtime: */
175177
inttentative_val;
178+
intreset_val;
176179
};
177180

178181
structconfig_real
@@ -181,13 +184,14 @@ struct config_real
181184
/* these fields must be set correctly in initial value: */
182185
/* (all but reset_val are constants) */
183186
double*variable;
184-
doublereset_val;
187+
doubleboot_val;
185188
doublemin;
186189
doublemax;
187190
GucRealAssignHookassign_hook;
188191
GucShowHookshow_hook;
189192
/* variable fields, initialized at runtime: */
190193
doubletentative_val;
194+
doublereset_val;
191195
};
192196

193197
structconfig_string

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp