Commit 51f19558 authored by Peter Eisentraut's avatar Peter Eisentraut

Save source of GUC settings, allowing different sources to be processed in

any order without affecting results.
parent ab786f62
......@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.120 2002/01/10 01:11:45 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.121 2002/02/23 01:31:34 petere Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -262,7 +262,7 @@ BootstrapMain(int argc, char *argv[])
* parsing */
break;
case 'F':
SetConfigOption("fsync", "false", PGC_POSTMASTER, true);
SetConfigOption("fsync", "false", PGC_POSTMASTER, PGC_S_ARGV);
break;
case 'o':
StrNCpy(OutputFileName, optarg, MAXPGPATH);
......@@ -274,7 +274,7 @@ BootstrapMain(int argc, char *argv[])
/* indicates fork from postmaster */
break;
case 'B':
SetConfigOption("shared_buffers", optarg, PGC_POSTMASTER, true);
SetConfigOption("shared_buffers", optarg, PGC_POSTMASTER, PGC_S_ARGV);
break;
default:
usage();
......
......@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.57 2001/12/09 04:37:50 thomas Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.58 2002/02/23 01:31:35 petere Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -780,7 +780,7 @@ SetPGVariable(const char *name, List *args)
if (strcasecmp(name, "session_authorization") == 0)
SetSessionAuthorization(value);
else
SetConfigOption(name, value, superuser() ? PGC_SUSET : PGC_USERSET, false);
SetConfigOption(name, value, superuser() ? PGC_SUSET : PGC_USERSET, PGC_S_SESSION);
}
return;
}
......@@ -846,5 +846,5 @@ ResetPGVariable(const char *name)
else
SetConfigOption(name, NULL,
superuser() ? PGC_SUSET : PGC_USERSET,
false);
PGC_S_SESSION);
}
......@@ -37,7 +37,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.266 2002/02/19 20:45:04 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.267 2002/02/23 01:31:35 petere Exp $
*
* NOTES
*
......@@ -396,6 +396,8 @@ PostmasterMain(int argc, char *argv[])
ALLOCSET_DEFAULT_MAXSIZE);
MemoryContextSwitchTo(PostmasterContext);
IgnoreSystemIndexes(false);
/*
* Options setup
*/
......@@ -403,60 +405,12 @@ PostmasterMain(int argc, char *argv[])
/* PGPORT environment variable, if set, overrides GUC setting */
if (getenv("PGPORT"))
SetConfigOption("port", getenv("PGPORT"), PGC_POSTMASTER, true);
SetConfigOption("port", getenv("PGPORT"),
PGC_POSTMASTER, PGC_S_ARGV/*sortof*/);
potential_DataDir = getenv("PGDATA"); /* default value */
/*
* First we must scan for a -D argument to get the data dir. Then read
* the config file. Finally, scan all the other arguments. (Command
* line switches override config file.)
*
* Note: The two lists of options must be exactly the same, even though
* perhaps the first one would only have to be "D:" with opterr turned
* off. But some versions of getopt (notably GNU) are going to
* arbitrarily permute some "non-options" (according to the local
* world view) which will result in some switches being associated
* with the wrong argument. Death and destruction will occur.
*/
opterr = 1;
while ((opt = getopt(argc, argv, "A:a:B:b:c:D:d:Fh:ik:lm:MN:no:p:Ss-:")) != -1)
{
switch (opt)
{
case 'D':
potential_DataDir = optarg;
break;
case '?':
fprintf(stderr, gettext("Try '%s --help' for more information.\n"), progname);
ExitPostmaster(1);
}
}
/*
* Postmaster accepts no non-option switch arguments.
*/
if (optind < argc)
{
postmaster_error("invalid argument -- %s", argv[optind]);
fprintf(stderr, gettext("Try '%s --help' for more information.\n"),
progname);
ExitPostmaster(1);
}
checkDataDir(potential_DataDir); /* issues error messages */
SetDataDir(potential_DataDir);
ProcessConfigFile(PGC_POSTMASTER);
IgnoreSystemIndexes(false);
/* reset getopt(3) to rescan arguments */
optind = 1;
#ifdef HAVE_INT_OPTRESET
optreset = 1; /* some systems need this too */
#endif
while ((opt = getopt(argc, argv, "A:a:B:b:c:D:d:Fh:ik:lm:MN:no:p:Ss-:")) != -1)
{
......@@ -464,7 +418,7 @@ PostmasterMain(int argc, char *argv[])
{
case 'A':
#ifdef USE_ASSERT_CHECKING
SetConfigOption("debug_assertions", optarg, PGC_POSTMASTER, true);
SetConfigOption("debug_assertions", optarg, PGC_POSTMASTER, PGC_S_ARGV);
#else
postmaster_error("Assert checking is not compiled in.");
#endif
......@@ -473,13 +427,13 @@ PostmasterMain(int argc, char *argv[])
/* Can no longer set authentication method. */
break;
case 'B':
SetConfigOption("shared_buffers", optarg, PGC_POSTMASTER, true);
SetConfigOption("shared_buffers", optarg, PGC_POSTMASTER, PGC_S_ARGV);
break;
case 'b':
/* Can no longer set the backend executable file to use. */
break;
case 'D':
/* already done above */
potential_DataDir = optarg;
break;
case 'd':
......@@ -487,23 +441,23 @@ PostmasterMain(int argc, char *argv[])
* Turn on debugging for the postmaster and the backend
* servers descended from it.
*/
SetConfigOption("debug_level", optarg, PGC_POSTMASTER, true);
SetConfigOption("debug_level", optarg, PGC_POSTMASTER, PGC_S_ARGV);
break;
case 'F':
SetConfigOption("fsync", "false", PGC_POSTMASTER, true);
SetConfigOption("fsync", "false", PGC_POSTMASTER, PGC_S_ARGV);
break;
case 'h':
SetConfigOption("virtual_host", optarg, PGC_POSTMASTER, true);
SetConfigOption("virtual_host", optarg, PGC_POSTMASTER, PGC_S_ARGV);
break;
case 'i':
SetConfigOption("tcpip_socket", "true", PGC_POSTMASTER, true);
SetConfigOption("tcpip_socket", "true", PGC_POSTMASTER, PGC_S_ARGV);
break;
case 'k':
SetConfigOption("unix_socket_directory", optarg, PGC_POSTMASTER, true);
SetConfigOption("unix_socket_directory", optarg, PGC_POSTMASTER, PGC_S_ARGV);
break;
#ifdef USE_SSL
case 'l':
SetConfigOption("ssl", "true", PGC_POSTMASTER, true);
SetConfigOption("ssl", "true", PGC_POSTMASTER, PGC_S_ARGV);
break;
#endif
case 'm':
......@@ -519,7 +473,7 @@ PostmasterMain(int argc, char *argv[])
break;
case 'N':
/* The max number of backends to start. */
SetConfigOption("max_connections", optarg, PGC_POSTMASTER, true);
SetConfigOption("max_connections", optarg, PGC_POSTMASTER, PGC_S_ARGV);
break;
case 'n':
/* Don't reinit shared mem after abnormal exit */
......@@ -536,7 +490,7 @@ PostmasterMain(int argc, char *argv[])
strcpy(original_extraoptions, optarg);
break;
case 'p':
SetConfigOption("port", optarg, PGC_POSTMASTER, true);
SetConfigOption("port", optarg, PGC_POSTMASTER, PGC_S_ARGV);
break;
case 'S':
......@@ -546,7 +500,7 @@ PostmasterMain(int argc, char *argv[])
* it's most badly needed on SysV-derived systems like
* SVR4 and HP-UX.
*/
SetConfigOption("silent_mode", "true", PGC_POSTMASTER, true);
SetConfigOption("silent_mode", "true", PGC_POSTMASTER, PGC_S_ARGV);
break;
case 's':
......@@ -573,7 +527,7 @@ PostmasterMain(int argc, char *argv[])
elog(ERROR, "-c %s requires argument", optarg);
}
SetConfigOption(name, value, PGC_POSTMASTER, true);
SetConfigOption(name, value, PGC_POSTMASTER, PGC_S_ARGV);
free(name);
if (value)
free(value);
......@@ -581,12 +535,22 @@ PostmasterMain(int argc, char *argv[])
}
default:
/* shouldn't get here */
fprintf(stderr, gettext("Try '%s --help' for more information.\n"), progname);
ExitPostmaster(1);
}
}
/*
* Postmaster accepts no non-option switch arguments.
*/
if (optind < argc)
{
postmaster_error("invalid argument -- %s", argv[optind]);
fprintf(stderr, gettext("Try '%s --help' for more information.\n"),
progname);
ExitPostmaster(1);
}
/*
* Check for invalid combinations of switches
*/
......@@ -601,6 +565,11 @@ PostmasterMain(int argc, char *argv[])
ExitPostmaster(1);
}
checkDataDir(potential_DataDir); /* issues error messages */
SetDataDir(potential_DataDir);
ProcessConfigFile(PGC_POSTMASTER);
/*
* Now that we are done processing the postmaster arguments, reset
* getopt(3) library so that it will work correctly in subprocesses.
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.246 2002/02/19 19:54:43 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.247 2002/02/23 01:31:36 petere Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
......@@ -1089,6 +1089,7 @@ PostgresMain(int argc, char *argv[], const char *username)
bool secure;
int errs = 0;
GucContext ctx;
GucSource gucsource;
char *tmp;
int firstchar;
......@@ -1164,13 +1165,14 @@ PostgresMain(int argc, char *argv[], const char *username)
/* all options are allowed until '-p' */
secure = true;
ctx = PGC_POSTMASTER;
gucsource = PGC_S_ARGV; /* initial switches came from command line */
while ((flag = getopt(argc, argv, "A:B:c:CD:d:Eef:FiNOPo:p:S:st:v:W:x:-:")) != -1)
switch (flag)
{
case 'A':
#ifdef USE_ASSERT_CHECKING
SetConfigOption("debug_assertions", optarg, ctx, true);
SetConfigOption("debug_assertions", optarg, ctx, gucsource);
#else
elog(NOTICE, "Assert checking is not compiled in");
#endif
......@@ -1181,7 +1183,7 @@ PostgresMain(int argc, char *argv[], const char *username)
/*
* specify the size of buffer pool
*/
SetConfigOption("shared_buffers", optarg, ctx, true);
SetConfigOption("shared_buffers", optarg, ctx, gucsource);
break;
case 'C':
......@@ -1198,17 +1200,17 @@ PostgresMain(int argc, char *argv[], const char *username)
break;
case 'd': /* debug level */
SetConfigOption("debug_level", optarg, ctx, true);
SetConfigOption("debug_level", optarg, ctx, gucsource);
if (DebugLvl >= 1)
SetConfigOption("log_connections", "true", ctx, true);
SetConfigOption("log_connections", "true", ctx, gucsource);
if (DebugLvl >= 2)
SetConfigOption("debug_print_query", "true", ctx, true);
SetConfigOption("debug_print_query", "true", ctx, gucsource);
if (DebugLvl >= 3)
SetConfigOption("debug_print_parse", "true", ctx, true);
SetConfigOption("debug_print_parse", "true", ctx, gucsource);
if (DebugLvl >= 4)
SetConfigOption("debug_print_plan", "true", ctx, true);
SetConfigOption("debug_print_plan", "true", ctx, gucsource);
if (DebugLvl >= 5)
SetConfigOption("debug_print_rewritten", "true", ctx, true);
SetConfigOption("debug_print_rewritten", "true", ctx, gucsource);
break;
case 'E':
......@@ -1232,7 +1234,7 @@ PostgresMain(int argc, char *argv[], const char *username)
/*
* turn off fsync
*/
SetConfigOption("fsync", "false", ctx, true);
SetConfigOption("fsync", "false", ctx, gucsource);
break;
case 'f':
......@@ -1265,7 +1267,7 @@ PostgresMain(int argc, char *argv[], const char *username)
errs++;
}
if (tmp)
SetConfigOption(tmp, "false", ctx, true);
SetConfigOption(tmp, "false", ctx, gucsource);
break;
case 'i':
......@@ -1319,6 +1321,7 @@ PostgresMain(int argc, char *argv[], const char *username)
secure = false; /* subsequent switches are NOT
* secure */
ctx = PGC_BACKEND;
gucsource = PGC_S_CLIENT;
}
break;
......@@ -1327,7 +1330,7 @@ PostgresMain(int argc, char *argv[], const char *username)
/*
* S - amount of sort memory to use in 1k bytes
*/
SetConfigOption("sort_mem", optarg, ctx, true);
SetConfigOption("sort_mem", optarg, ctx, gucsource);
break;
case 's':
......@@ -1335,7 +1338,7 @@ PostgresMain(int argc, char *argv[], const char *username)
/*
* s - report usage statistics (timings) after each query
*/
SetConfigOption("show_query_stats", "true", ctx, true);
SetConfigOption("show_query_stats", "true", ctx, gucsource);
break;
case 't':
......@@ -1368,7 +1371,7 @@ PostgresMain(int argc, char *argv[], const char *username)
break;
}
if (tmp)
SetConfigOption(tmp, "true", ctx, true);
SetConfigOption(tmp, "true", ctx, gucsource);
break;
case 'v':
......@@ -1432,7 +1435,7 @@ PostgresMain(int argc, char *argv[], const char *username)
elog(ERROR, "-c %s requires argument", optarg);
}
SetConfigOption(name, value, ctx, true);
SetConfigOption(name, value, ctx, gucsource);
free(name);
if (value)
free(value);
......@@ -1451,7 +1454,7 @@ PostgresMain(int argc, char *argv[], const char *username)
(Show_parser_stats || Show_planner_stats || Show_executor_stats))
{
elog(NOTICE, "Query statistics are disabled because parser, planner, or executor statistics are on.");
SetConfigOption("show_query_stats", "false", ctx, true);
SetConfigOption("show_query_stats", "false", ctx, gucsource);
}
if (!IsUnderPostmaster)
......@@ -1623,7 +1626,7 @@ PostgresMain(int argc, char *argv[], const char *username)
if (!IsUnderPostmaster)
{
puts("\nPOSTGRES backend interactive interface ");
puts("$Revision: 1.246 $ $Date: 2002/02/19 19:54:43 $\n");
puts("$Revision: 1.247 $ $Date: 2002/02/23 01:31:36 $\n");
}
/*
......
......@@ -4,7 +4,7 @@
*
* Copyright 2000 by PostgreSQL Global Development Group
*
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc-file.l,v 1.9 2001/08/06 13:45:15 petere Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc-file.l,v 1.10 2002/02/23 01:31:36 petere Exp $
*/
%{
......@@ -240,13 +240,15 @@ ProcessConfigFile(GucContext context)
*/
for(item = head; item; item=item->next)
{
if (!set_config_option(item->name, item->value, context, false, false))
if (!set_config_option(item->name, item->value, context,
false, PGC_S_INFINITY))
goto cleanup_exit;
}
/* If we got here all the options parsed okay. */
for(item = head; item; item=item->next)
set_config_option(item->name, item->value, context, true, true);
set_config_option(item->name, item->value, context,
true, PGC_S_FILE);
cleanup_exit:
free_name_value_list(head);
......
This diff is collapsed.
......@@ -4,7 +4,7 @@
* External declarations pertaining to backend/utils/misc/guc.c and
* backend/utils/misc/guc-file.l
*
* $Id: guc.h,v 1.13 2001/11/05 17:46:36 momjian Exp $
* $Id: guc.h,v 1.14 2002/02/23 01:31:37 petere Exp $
*/
#ifndef GUC_H
#define GUC_H
......@@ -46,15 +46,32 @@ typedef enum
PGC_USERSET
} GucContext;
/*
* The following type records the source of the current setting. A
* new setting can only take effect if the previous setting had the
* same or lower level. (E.g, changing the config file doesn't
* override the postmaster command line.)
*/
typedef enum
{
PGC_S_DEFAULT = 0, /* wired-in default */
PGC_S_FILE = 1, /* postgresql.conf */
PGC_S_ARGV = 2, /* postmaster command line */
PGC_S_DATABASE = 3, /* per-database setting */
PGC_S_USER = 4, /* per-user setting */
PGC_S_CLIENT = 5, /* from client (PGOPTIONS) */
PGC_S_SESSION = 6, /* SET command */
PGC_S_INFINITY = 100 /* can be used to avoid checks */
} GucSource;
extern void SetConfigOption(const char *name, const char *value,
GucContext context, bool makeDefault);
GucContext context, GucSource source);
extern const char *GetConfigOption(const char *name);
extern void ProcessConfigFile(GucContext context);
extern void ResetAllOptions(bool isStartup);
extern void ParseLongOption(const char *string, char **name, char **value);
extern bool set_config_option(const char *name, const char *value,
GucContext context, bool DoIt, bool makeDefault);
GucContext context, bool DoIt, GucSource source);
extern void ShowAllGUCConfig(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