Skip to content

Commit 262a7bc

Browse files
committed
Allow commenting of variables in postgresql.conf to restore them to
defaults. Zdenek Kotala
1 parent f91ddb7 commit 262a7bc

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
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,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
struct config_bool *conf = (struct config_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
case PGC_INT:
27052705
{
27062706
struct config_int *conf = (struct config_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
case PGC_REAL:
27192719
{
27202720
struct config_real *conf = (struct config_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
case PGC_STRING:
@@ -3179,7 +3179,7 @@ AtEOXact_GUC(bool isCommit, bool isSubXact)
31793179
for (i = 0; i < num_guc_variables; i++)
31803180
{
31813181
struct config_generic *gconf = guc_variables[i];
3182-
int my_status = gconf->status;
3182+
int my_status = gconf->status & (~GUC_IN_CONFFILE);
31833183
GucStack *stack = gconf->stack;
31843184
bool useTentative;
31853185
bool changed;
@@ -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+
else if (*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
else if (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
#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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy