Skip to content

Commit f09fb71

Browse files
committed
Recommit patch to allow commented GUC variables to return to their
default values.
1 parent e7da38b commit f09fb71

File tree

3 files changed

+151
-51
lines changed

3 files changed

+151
-51
lines changed

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

Lines changed: 55 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.43 2006/08/13 01:30:17 momjian Exp $
7+
* $PostgreSQL: pgsql/src/backend/utils/misc/guc-file.l,v 1.44 2006/08/13 02:22:24 momjian Exp $
88
*/
99

1010
%{
@@ -117,6 +117,7 @@ ProcessConfigFile(GucContext context)
117117
{
118118
int elevel, i;
119119
struct name_value_pair *item, *head, *tail;
120+
char *env;
120121
bool *apply_list = NULL;
121122
int varcount = 0;
122123
@@ -183,6 +184,59 @@ 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+
197+
if (gconf->reset_source == PGC_S_FILE &&
198+
!(gconf->status & GUC_IN_CONFFILE))
199+
{
200+
if (gconf->context == PGC_BACKEND && IsUnderPostmaster)
201+
; /* Be silent. Does any body want message from each session? */
202+
else if (gconf->context == PGC_POSTMASTER)
203+
ereport(elevel,
204+
(errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
205+
errmsg("parameter \"%s\" cannot be changed (commented) after server start; configuration file change ignored",
206+
gconf->name)));
207+
else if (set_config_option(gconf->name, NULL, context,
208+
PGC_S_FILE, false, true))
209+
{
210+
GucStack *stack;
211+
212+
gconf->reset_source = PGC_S_DEFAULT;
213+
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 returned to default value", gconf->name)));
221+
}
222+
}
223+
gconf->status &= ~GUC_IN_CONFFILE;
224+
}
225+
226+
/*
227+
* Revert to environment variable. PGPORT is ignored, because it cannot be
228+
* set in running state.
229+
*/
230+
env = getenv("PGDATESTYLE");
231+
if (env != NULL)
232+
set_config_option("datestyle", env, context,
233+
PGC_S_ENV_VAR, false, true);
234+
235+
env = getenv("PGCLIENTENCODING");
236+
if (env != NULL)
237+
set_config_option("client_encoding", env, context,
238+
PGC_S_ENV_VAR, false, true);
239+
}
186240
187241
cleanup_list:
188242
if (apply_list)

src/backend/utils/misc/guc.c

Lines changed: 87 additions & 45 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.338 2006/08/13 01:30:17 momjian Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.339 2006/08/13 02:22:24 momjian Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -2692,40 +2692,40 @@ InitializeGUCOptions(void)
26922692
{
26932693
struct config_bool *conf = (struct config_bool *) gconf;
26942694

2695-
if (conf->assign_hook)
2696-
if (!(*conf->assign_hook) (conf->reset_val, true,
2697-
PGC_S_DEFAULT))
2698-
elog(FATAL, "failed to initialize %s to %d",
2699-
conf->gen.name, (int) conf->reset_val);
2700-
*conf->variable = conf->reset_val;
2695+
if (conf->assign_hook &&
2696+
!(*conf->assign_hook) (conf->boot_val, true,
2697+
PGC_S_DEFAULT))
2698+
elog(FATAL, "failed to initialize %s to %d",
2699+
conf->gen.name, (int) conf->boot_val);
2700+
*conf->variable = conf->reset_val = conf->boot_val;
27012701
break;
27022702
}
27032703
case PGC_INT:
27042704
{
27052705
struct config_int *conf = (struct config_int *) gconf;
27062706

2707-
Assert(conf->reset_val >= conf->min);
2708-
Assert(conf->reset_val <= conf->max);
2709-
if (conf->assign_hook)
2710-
if (!(*conf->assign_hook) (conf->reset_val, true,
2711-
PGC_S_DEFAULT))
2712-
elog(FATAL, "failed to initialize %s to %d",
2713-
conf->gen.name, conf->reset_val);
2714-
*conf->variable = conf->reset_val;
2707+
Assert(conf->boot_val >= conf->min);
2708+
Assert(conf->boot_val <= conf->max);
2709+
if (conf->assign_hook &&
2710+
!(*conf->assign_hook) (conf->boot_val, true,
2711+
PGC_S_DEFAULT))
2712+
elog(FATAL, "failed to initialize %s to %d",
2713+
conf->gen.name, conf->boot_val);
2714+
*conf->variable = conf->reset_val = conf->boot_val;
27152715
break;
27162716
}
27172717
case PGC_REAL:
27182718
{
27192719
struct config_real *conf = (struct config_real *) gconf;
27202720

2721-
Assert(conf->reset_val >= conf->min);
2722-
Assert(conf->reset_val <= conf->max);
2723-
if (conf->assign_hook)
2724-
if (!(*conf->assign_hook) (conf->reset_val, true,
2725-
PGC_S_DEFAULT))
2726-
elog(FATAL, "failed to initialize %s to %g",
2727-
conf->gen.name, conf->reset_val);
2728-
*conf->variable = conf->reset_val;
2721+
Assert(conf->boot_val >= conf->min);
2722+
Assert(conf->boot_val <= conf->max);
2723+
if (conf->assign_hook &&
2724+
!(*conf->assign_hook) (conf->boot_val, true,
2725+
PGC_S_DEFAULT))
2726+
elog(FATAL, "failed to initialize %s to %g",
2727+
conf->gen.name, conf->boot_val);
2728+
*conf->variable = conf->reset_val = conf->boot_val;
27292729
break;
27302730
}
27312731
case PGC_STRING:
@@ -2738,10 +2738,8 @@ InitializeGUCOptions(void)
27382738
conf->tentative_val = NULL;
27392739

27402740
if (conf->boot_val == NULL)
2741-
{
27422741
/* Cannot set value yet */
27432742
break;
2744-
}
27452743

27462744
str = guc_strdup(FATAL, conf->boot_val);
27472745
conf->reset_val = str;
@@ -2753,10 +2751,8 @@ InitializeGUCOptions(void)
27532751
newstr = (*conf->assign_hook) (str, true,
27542752
PGC_S_DEFAULT);
27552753
if (newstr == NULL)
2756-
{
27572754
elog(FATAL, "failed to initialize %s to \"%s\"",
27582755
conf->gen.name, str);
2759-
}
27602756
else if (newstr != str)
27612757
{
27622758
free(str);
@@ -2796,12 +2792,10 @@ InitializeGUCOptions(void)
27962792
if (env != NULL)
27972793
SetConfigOption("port", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
27982794

2799-
env = getenv("PGDATESTYLE");
2800-
if (env != NULL)
2795+
if ((env = getenv("PGDATESTYLE")) != NULL)
28012796
SetConfigOption("datestyle", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
28022797

2803-
env = getenv("PGCLIENTENCODING");
2804-
if (env != NULL)
2798+
if ((env = getenv("PGCLIENTENCODING")) != NULL)
28052799
SetConfigOption("client_encoding", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
28062800
}
28072801

@@ -3178,7 +3172,7 @@ AtEOXact_GUC(bool isCommit, bool isSubXact)
31783172
for (i = 0; i < num_guc_variables; i++)
31793173
{
31803174
struct config_generic *gconf = guc_variables[i];
3181-
int my_status = gconf->status;
3175+
int my_status = gconf->status & (~GUC_IN_CONFFILE);
31823176
GucStack *stack = gconf->stack;
31833177
bool useTentative;
31843178
bool changed;
@@ -3723,12 +3717,22 @@ parse_value(int elevel, const struct config_generic *record,
37233717
}
37243718
else
37253719
{
3726-
newval = conf->reset_val;
3727-
*source = conf->gen.reset_source;
3720+
/*
3721+
* Revert value to default if source is configuration file. It is used when
3722+
* configuration parameter is removed/commented out in the config file. Else
3723+
* RESET or SET TO DEFAULT command is called and reset_val is used.
3724+
*/
3725+
if (*source == PGC_S_FILE)
3726+
newval = conf->boot_val;
3727+
else
3728+
{
3729+
newval = conf->reset_val;
3730+
*source = conf->gen.reset_source;
3731+
}
37283732
}
37293733

3730-
if (conf->assign_hook)
3731-
if (!(*conf->assign_hook) (newval, changeVal, *source))
3734+
if (conf->assign_hook &&
3735+
!(*conf->assign_hook) (newval, changeVal, *source))
37323736
{
37333737
ereport(elevel,
37343738
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
@@ -3767,8 +3771,18 @@ parse_value(int elevel, const struct config_generic *record,
37673771
}
37683772
else
37693773
{
3770-
newval = conf->reset_val;
3771-
*source = conf->gen.reset_source;
3774+
/*
3775+
* Revert value to default if source is configuration file. It is used when
3776+
* configuration parameter is removed/commented out in the config file. Else
3777+
* RESET or SET TO DEFAULT command is called and reset_val is used.
3778+
*/
3779+
if (*source == PGC_S_FILE)
3780+
newval = conf->boot_val;
3781+
else
3782+
{
3783+
newval = conf->reset_val;
3784+
*source = conf->gen.reset_source;
3785+
}
37723786
}
37733787

37743788
if (conf->assign_hook)
@@ -3811,12 +3825,22 @@ parse_value(int elevel, const struct config_generic *record,
38113825
}
38123826
else
38133827
{
3814-
newval = conf->reset_val;
3815-
*source = conf->gen.reset_source;
3828+
/*
3829+
* Revert value to default if source is configuration file. It is used when
3830+
* configuration parameter is removed/commented out in the config file. Else
3831+
* RESET or SET TO DEFAULT command is called and reset_val is used.
3832+
*/
3833+
if (*source == PGC_S_FILE)
3834+
newval = conf->boot_val;
3835+
else
3836+
{
3837+
newval = conf->reset_val;
3838+
*source = conf->gen.reset_source;
3839+
}
38163840
}
38173841

3818-
if (conf->assign_hook)
3819-
if (!(*conf->assign_hook) (newval, changeVal, *source))
3842+
if (conf->assign_hook &&
3843+
!(*conf->assign_hook) (newval, changeVal, *source))
38203844
{
38213845
ereport(elevel,
38223846
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
@@ -3845,6 +3869,18 @@ parse_value(int elevel, const struct config_generic *record,
38453869
if (conf->gen.flags & GUC_IS_NAME)
38463870
truncate_identifier(newval, strlen(newval), true);
38473871
}
3872+
else if (*source == PGC_S_FILE)
3873+
{
3874+
/* Revert value to default when item is removed from config file. */
3875+
if (conf->boot_val != NULL)
3876+
{
3877+
newval = guc_strdup(elevel, conf->boot_val);
3878+
if (newval == NULL)
3879+
return false;
3880+
}
3881+
else
3882+
return false;
3883+
}
38483884
else if (conf->reset_val)
38493885
{
38503886
/*
@@ -3856,10 +3892,8 @@ parse_value(int elevel, const struct config_generic *record,
38563892
*source = conf->gen.reset_source;
38573893
}
38583894
else
3859-
{
38603895
/* Nothing to reset to, as yet; so do nothing */
38613896
break;
3862-
}
38633897

38643898
if (conf->assign_hook)
38653899
{
@@ -4047,6 +4081,13 @@ verify_config_option(const char *name, const char *value,
40474081

40484082
if (parse_value(elevel, record, value, &source, false, NULL))
40494083
{
4084+
/*
4085+
* Mark record like presented in the config file. Be carefull if
4086+
* you use this function for another purpose than config file
4087+
* verification. It causes confusion configfile parser.
4088+
*/
4089+
record->status |= GUC_IN_CONFFILE;
4090+
40504091
if (isNewEqual != NULL)
40514092
*isNewEqual = is_newvalue_equal(record, value);
40524093
if (isContextOK != NULL)
@@ -4109,7 +4150,8 @@ set_config_option(const char *name, const char *value,
41094150
* Should we set reset/stacked values? (If so, the behavior is not
41104151
* transactional.)
41114152
*/
4112-
makeDefault = changeVal && (source <= PGC_S_OVERRIDE) && (value != NULL);
4153+
makeDefault = changeVal && (source <= PGC_S_OVERRIDE) &&
4154+
(value != NULL || source == PGC_S_FILE);
41134155

41144156
/*
41154157
* 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.26 2006/08/12 04:11:50 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/guc_tables.h,v 1.27 2006/08/13 02:22:24 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -143,7 +143,8 @@ struct config_generic
143143
#define GUC_HAVE_TENTATIVE 0x0001 /* tentative value is defined */
144144
#define GUC_HAVE_LOCAL 0x0002 /* a SET LOCAL has been executed */
145145
#define GUC_HAVE_STACK 0x0004 /* we have stacked prior value(s) */
146-
146+
#define GUC_IN_CONFFILE 0x0008 /* 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-
bool reset_val;
157+
bool boot_val;
157158
GucBoolAssignHook assign_hook;
158159
GucShowHook show_hook;
159160
/* variable fields, initialized at runtime: */
160161
bool tentative_val;
162+
bool reset_val;
161163
};
162164

163165
struct config_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-
int reset_val;
171+
int boot_val;
170172
int min;
171173
int max;
172174
GucIntAssignHook assign_hook;
173175
GucShowHook show_hook;
174176
/* variable fields, initialized at runtime: */
175177
int tentative_val;
178+
int reset_val;
176179
};
177180

178181
struct config_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-
double reset_val;
187+
double boot_val;
185188
double min;
186189
double max;
187190
GucRealAssignHook assign_hook;
188191
GucShowHook show_hook;
189192
/* variable fields, initialized at runtime: */
190193
double tentative_val;
194+
double reset_val;
191195
};
192196

193197
struct config_string

0 commit comments

Comments
 (0)