1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-12 05:01:15 +03:00

Second pass over run-time configuration system. Adjust priorities on some

option settings. Sort out SIGHUP vs BACKEND -- there is no total ordering
here, so make explicit checks. Add comments explaining all of this.
Removed permissions check on SHOW command.

Add examine_subclass to the game, rename to SQL_inheritance to fit the
official data model better. Adjust documentation.

Standalone backend needs to reset all options before it starts. To
facilitate that, have IsUnderPostmaster be set by the postmaster itself,
don't wait for the magic -p switch.

Also make sure that all environment variables and argv's survive
init_ps_display(). Use strdup where necessary.

Have initdb make configuration files (postgresql.conf, pg_hba.conf) mode
0600 -- having configuration files is no fun if you can't edit them.
This commit is contained in:
Peter Eisentraut
2000-06-22 22:31:24 +00:00
parent bc06269495
commit c446509565
13 changed files with 228 additions and 179 deletions

View File

@@ -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.86 2000/06/17 23:41:27 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.87 2000/06/22 22:31:17 petere Exp $
*
*-------------------------------------------------------------------------
*/
@@ -35,6 +35,7 @@
#include "tcop/tcopprot.h"
#include "utils/builtins.h"
#include "utils/fmgroids.h"
#include "utils/guc.h"
#include "utils/lsyscache.h"
#include "utils/portal.h"
@@ -248,8 +249,11 @@ BootstrapMain(int argc, char *argv[])
Quiet = false;
Noversion = false;
dbName = NULL;
DataDir = getenv("PGDATA"); /* Null if no PGDATA variable */
IsUnderPostmaster = false;
if (!IsUnderPostmaster)
{
ResetAllOptions();
DataDir = getenv("PGDATA"); /* Null if no PGDATA variable */
}
while ((flag = getopt(argc, argv, "D:dCQxpB:F")) != EOF)
{
@@ -275,7 +279,7 @@ BootstrapMain(int argc, char *argv[])
xloginit = true;
break;
case 'p':
IsUnderPostmaster = true;
/* indicates fork from postmaster */
break;
case 'B':
NBuffers = atoi(optarg);

View File

@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.37 2000/06/14 18:17:25 petere Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.38 2000/06/22 22:31:17 petere Exp $
*
*-------------------------------------------------------------------------
*/
@@ -49,12 +49,7 @@ static bool parse_XactIsoLevel(char *);
static bool parse_random_seed(char *);
static bool show_random_seed(void);
static bool reset_random_seed(void);
static bool parse_examine_subclass(char *);
static bool show_examine_subclass(void);
static bool reset_examine_subclass(void);
#define examine_subclass_default true
bool examine_subclass = examine_subclass_default;
/*
* get_token
@@ -169,44 +164,6 @@ get_token(char **tok, char **val, char *str)
return str;
}
/*
*
* EXAMINE_SUBCLASS
*
*/
#define EXAMINE_SUBCLASS "EXAMINE_SUBCLASS"
static bool
parse_examine_subclass(char *value)
{
if (strcasecmp(value, "on") == 0)
examine_subclass = true;
else if (strcasecmp(value, "off") == 0)
examine_subclass = false;
else if (strcasecmp(value, "default") == 0)
examine_subclass = examine_subclass_default;
else
elog(ERROR, "Bad value for %s (%s)", EXAMINE_SUBCLASS, value);
return TRUE;
}
static bool
show_examine_subclass()
{
if (examine_subclass)
elog(NOTICE, "%s is ON", EXAMINE_SUBCLASS);
else
elog(NOTICE, "%s is OFF", EXAMINE_SUBCLASS);
return TRUE;
}
static bool
reset_examine_subclass(void)
{
examine_subclass = examine_subclass_default;
return TRUE;
}
/*
* DATE_STYLE
@@ -571,7 +528,7 @@ void
SetPGVariable(const char *name, const char *value)
{
/*
* Special cases ought to be removed are handled separately
* Special cases ought to be removed and handled separately
* by TCOP
*/
if (strcasecmp(name, "datestyle")==0)
@@ -588,8 +545,6 @@ SetPGVariable(const char *name, const char *value)
#endif
else if (strcasecmp(name, "random_seed")==0)
parse_random_seed(pstrdup(value));
else if (strcasecmp(name, "examine_subclass")==0)
parse_examine_subclass(pstrdup(value));
else
SetConfigOption(name, value, superuser() ? PGC_SUSET : PGC_USERSET);
}
@@ -612,12 +567,10 @@ GetPGVariable(const char *name)
#endif
else if (strcasecmp(name, "random_seed")==0)
show_random_seed();
else if (strcasecmp(name, "examine_subclass")==0)
show_examine_subclass();
else
{
const char * val = GetConfigOption(name, superuser());
elog(NOTICE, "%s = %s", name, val);
const char * val = GetConfigOption(name);
elog(NOTICE, "%s is %s", name, val);
}
}
@@ -638,8 +591,6 @@ ResetPGVariable(const char *name)
#endif
else if (strcasecmp(name, "random_seed")==0)
reset_random_seed();
else if (strcasecmp(name, "examine_subclass")==0)
reset_examine_subclass();
else
SetConfigOption(name, NULL, superuser() ? PGC_SUSET : PGC_USERSET);
}

View File

@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.173 2000/06/12 19:40:40 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.174 2000/06/22 22:31:18 petere Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
@@ -49,7 +49,7 @@
#include "storage/lmgr.h"
#include "utils/acl.h"
#include "utils/numeric.h"
#include "commands/variable.h"
#include "utils/guc.h"
#ifdef MULTIBYTE
#include "miscadmin.h"
@@ -884,7 +884,7 @@ AlterTableStmt:
AlterTableStmt *n = makeNode(AlterTableStmt);
n->subtype = 'A';
n->relname = $3;
n->inh = $4 || examine_subclass;
n->inh = $4 || SQL_inheritance;
n->def = $7;
$$ = (Node *)n;
}
@@ -894,7 +894,7 @@ AlterTableStmt:
AlterTableStmt *n = makeNode(AlterTableStmt);
n->subtype = 'T';
n->relname = $3;
n->inh = $4 || examine_subclass;
n->inh = $4 || SQL_inheritance;
n->name = $7;
n->def = $8;
$$ = (Node *)n;
@@ -905,7 +905,7 @@ AlterTableStmt:
AlterTableStmt *n = makeNode(AlterTableStmt);
n->subtype = 'D';
n->relname = $3;
n->inh = $4 || examine_subclass;
n->inh = $4 || SQL_inheritance;
n->name = $7;
n->behavior = $8;
$$ = (Node *)n;
@@ -916,7 +916,7 @@ AlterTableStmt:
AlterTableStmt *n = makeNode(AlterTableStmt);
n->subtype = 'C';
n->relname = $3;
n->inh = $4 || examine_subclass;
n->inh = $4 || SQL_inheritance;
n->def = $6;
$$ = (Node *)n;
}
@@ -926,7 +926,7 @@ AlterTableStmt:
AlterTableStmt *n = makeNode(AlterTableStmt);
n->subtype = 'X';
n->relname = $3;
n->inh = $4 || examine_subclass;
n->inh = $4 || SQL_inheritance;
n->name = $7;
n->behavior = $8;
$$ = (Node *)n;
@@ -2562,7 +2562,7 @@ RenameStmt: ALTER TABLE relation_name opt_inh_star
{
RenameStmt *n = makeNode(RenameStmt);
n->relname = $3;
n->inh = $4 || examine_subclass;
n->inh = $4 || SQL_inheritance;
n->column = $7;
n->newname = $9;
$$ = (Node *)n;
@@ -3806,7 +3806,7 @@ relation_expr: relation_name
/* default inheritance */
$$ = makeNode(RelExpr);
$$->relname = $1;
$$->inh = examine_subclass;
$$->inh = SQL_inheritance;
}
| relation_name '*' %prec '='
{

View File

@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.148 2000/06/14 18:17:38 petere Exp $
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.149 2000/06/22 22:31:20 petere Exp $
*
* NOTES
*
@@ -364,6 +364,8 @@ PostmasterMain(int argc, char *argv[])
bool DataDirOK; /* We have a usable PGDATA value */
char original_extraoptions[MAXPGPATH];
IsUnderPostmaster = true; /* so that backends know this */
*original_extraoptions = '\0';
progname = argv[0];
@@ -379,7 +381,8 @@ PostmasterMain(int argc, char *argv[])
ResetAllOptions();
MyProcPid = getpid();
DataDir = getenv("PGDATA"); /* default value */
if (getenv("PGDATA"))
DataDir = strdup(getenv("PGDATA")); /* default value */
if (getenv("PGPORT"))
PostPortName = atoi(getenv("PGPORT"));
@@ -401,7 +404,11 @@ PostmasterMain(int argc, char *argv[])
while ((opt = getopt(argc, argv, "A:a:B:b:D:d:Film:MN:no:p:Ss-:")) != EOF)
{
if (opt == 'D')
DataDir = optarg;
{
if (DataDir)
free(DataDir);
DataDir = strdup(optarg);
}
}
optind = 1; /* start over */
@@ -2040,7 +2047,7 @@ PostmasterRandom(void)
if (!initialized)
{
Assert(random_seed != 0 && !IsUnderPostmaster);
Assert(random_seed != 0);
srandom(random_seed);
initialized = true;
}

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.160 2000/06/15 04:10:19 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.161 2000/06/22 22:31:20 petere Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
@@ -824,13 +824,15 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
/*
* Set default values for command-line options.
*/
IsUnderPostmaster = false;
Noversion = false;
EchoQuery = false;
#ifdef LOCK_MGR_DEBUG
LockDebug = 0;
#endif
DataDir = getenv("PGDATA");
if (!IsUnderPostmaster)
{
ResetAllOptions();
if (getenv("PGDATA"))
DataDir = strdup(getenv("PGDATA"));
}
StatFp = stderr;
SetProcessingMode(InitProcessing);
@@ -891,7 +893,11 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
case 'D': /* PGDATA directory */
if (secure)
DataDir = optarg;
{
if (DataDir)
free(DataDir);
DataDir = strdup(optarg);
}
break;
case 'd': /* debug level */
@@ -1022,8 +1028,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
*/
if (secure)
{
IsUnderPostmaster = true;
DBName = optarg;
DBName = strdup(optarg);
secure = false; /* subsequent switches are NOT
* secure */
}
@@ -1170,12 +1175,6 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
proc_exit(1);
}
/*
* Make a copy of DataDir because the arguments and environment
* might be moved around later on.
*/
DataDir = strdup(DataDir);
/*
* 1. Set BlockSig and UnBlockSig masks. 2. Set up signal handlers. 3.
* Allow only SIGUSR1 signal (we never block it) during
@@ -1330,7 +1329,12 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
/*
* Set process params for ps
* Set process parameters for ps
*
* WARNING: On some platforms the environment will be moved
* around to make room for the ps display string. So any
* references to optarg or getenv() from above will be invalid
* after this call. Better use strdup or something similar.
*/
init_ps_display(real_argc, real_argv, userName, DBName, remote_host);
set_ps_display("startup");
@@ -1382,7 +1386,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
if (!IsUnderPostmaster)
{
puts("\nPOSTGRES backend interactive interface ");
puts("$Revision: 1.160 $ $Date: 2000/06/15 04:10:19 $\n");
puts("$Revision: 1.161 $ $Date: 2000/06/22 22:31:20 $\n");
}
/*

View File

@@ -4,7 +4,7 @@
* Support for grand unified configuration scheme, including SET
* command, configuration file, and command line options.
*
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.3 2000/06/15 04:10:30 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.4 2000/06/22 22:31:21 petere Exp $
*
* Copyright 2000 by PostgreSQL Global Development Group
* Written by Peter Eisentraut <peter_e@gmx.net>.
@@ -49,6 +49,7 @@ bool Show_executor_stats = false;
bool Show_query_stats = false; /* this is sort of all three above together */
bool Show_btree_build_stats = false;
bool SQL_inheritance;
enum config_type
@@ -115,6 +116,23 @@ struct config_string
};
/*
* TO ADD AN OPTION:
*
* 1. Declare a global variable of type bool, int, double, or char*
* and make use of it.
*
* 2. Decide at what times it's safe to set the option. See guc.h for
* details.
*
* 3. Decide on a name, a default value, upper and lower bounds (if
* applicable), etc.
*
* 4. Add a record below.
*
* 5. Don't forget to document that option.
*/
/******** option names follow ********/
@@ -133,27 +151,27 @@ ConfigureNamesBool[] =
{"geqo", PGC_USERSET, &enable_geqo, true},
{"net_server", PGC_POSTMASTER, &NetServer, false},
{"fsync", PGC_BACKEND, &enableFsync, true},
{"fsync", PGC_USERSET, &enableFsync, true},
{"log_connections", PGC_POSTMASTER, &Log_connections, false},
{"log_timestamp", PGC_BACKEND, &Log_timestamp, false},
{"log_pid", PGC_BACKEND, &Log_pid, false},
{"log_connections", PGC_SIGHUP, &Log_connections, false},
{"log_timestamp", PGC_SIGHUP, &Log_timestamp, false},
{"log_pid", PGC_SIGHUP, &Log_pid, false},
{"debug_print_query", PGC_SUSET, &Debug_print_query, false},
{"debug_print_parse", PGC_SUSET, &Debug_print_parse, false},
{"debug_print_rewritten", PGC_SUSET, &Debug_print_rewritten, false},
{"debug_print_plan", PGC_SUSET, &Debug_print_plan, false},
{"debug_pretty_print", PGC_SUSET, &Debug_pretty_print, false},
{"debug_print_query", PGC_USERSET, &Debug_print_query, false},
{"debug_print_parse", PGC_USERSET, &Debug_print_parse, false},
{"debug_print_rewritten", PGC_USERSET, &Debug_print_rewritten, false},
{"debug_print_plan", PGC_USERSET, &Debug_print_plan, false},
{"debug_pretty_print", PGC_USERSET, &Debug_pretty_print, false},
{"show_parser_stats", PGC_SUSET, &Show_parser_stats, false},
{"show_planner_stats", PGC_SUSET, &Show_planner_stats, false},
{"show_executor_stats", PGC_SUSET, &Show_executor_stats, false},
{"show_query_stats", PGC_SUSET, &Show_query_stats, false},
{"show_parser_stats", PGC_USERSET, &Show_parser_stats, false},
{"show_planner_stats", PGC_USERSET, &Show_planner_stats, false},
{"show_executor_stats", PGC_USERSET, &Show_executor_stats, false},
{"show_query_stats", PGC_USERSET, &Show_query_stats, false},
#ifdef BTREE_BUILD_STATS
{"show_btree_build_stats", PGC_SUSET, &Show_btree_build_stats, false},
#endif
{"trace_notify", PGC_SUSET, &Trace_notify, false},
{"trace_notify", PGC_USERSET, &Trace_notify, false},
#ifdef LOCK_DEBUG
{"trace_locks", PGC_SUSET, &Trace_locks, false},
@@ -162,8 +180,10 @@ ConfigureNamesBool[] =
{"debug_deadlocks", PGC_SUSET, &Debug_deadlocks, false},
#endif
{"hostlookup", PGC_POSTMASTER, &HostnameLookup, false},
{"showportnumber", PGC_POSTMASTER, &ShowPortNumber, false},
{"hostlookup", PGC_SIGHUP, &HostnameLookup, false},
{"showportnumber", PGC_SIGHUP, &ShowPortNumber, false},
{"sql_inheritance", PGC_USERSET, &SQL_inheritance, true},
{NULL, 0, NULL, false}
};
@@ -187,7 +207,7 @@ ConfigureNamesInt[] =
1000, 0, INT_MAX},
#ifdef ENABLE_SYSLOG
{"syslog", PGC_POSTMASTER, &Use_syslog,
{"syslog", PGC_SIGHUP, &Use_syslog,
0, 0, 2},
#endif
@@ -203,11 +223,10 @@ ConfigureNamesInt[] =
{"port", PGC_POSTMASTER, &PostPortName,
DEF_PGPORT, 1, 65535},
/* XXX Is this really changeable at runtime? */
{"sort_mem", PGC_SUSET, &SortMem,
{"sort_mem", PGC_USERSET, &SortMem,
512, 1, INT_MAX},
{"debug_level", PGC_SUSET, &DebugLvl,
{"debug_level", PGC_USERSET, &DebugLvl,
0, 0, 16},
#ifdef LOCK_DEBUG
@@ -217,7 +236,7 @@ ConfigureNamesInt[] =
0, 0, INT_MAX},
#endif
{"max_expr_depth", PGC_USERSET, &max_expr_depth,
DEFAULT_MAX_EXPR_DEPTH, 10, INT_MAX},
DEFAULT_MAX_EXPR_DEPTH, 10, INT_MAX},
{NULL, 0, NULL, 0, 0, 0}
};
@@ -483,29 +502,45 @@ set_config_option(const char * name, const char * value, GucContext
return false;
}
if (record->context < context)
/*
* Check if the option can be set at this time. See guc.h for the
* precise rules. Note that we don't want to throw errors if we're
* in the SIGHUP context. In that case we just ignore the attempt.
*/
if (record->context == PGC_POSTMASTER && context != PGC_POSTMASTER)
{
/* can't set option right now */
switch (context)
{
case PGC_USERSET:
elog(ERROR, "permission denied");
/*NORETURN*/
case PGC_SUSET:
elog(ERROR, "%s can only be set at startup", name);
/*NORETURN*/
case PGC_SIGHUP:
/* ignore the option */
return true;
case PGC_BACKEND:
/* ignore; is this the right thing to do? */
return true;
default:
elog(FATAL, "%s:%d: internal error", __FILE__, __LINE__);
/*NORETURN*/
}
if (context != PGC_SIGHUP)
elog(ERROR, "%s cannot be changed after server start", name);
else
return true;
}
else if (record->context == PGC_SIGHUP && context != PGC_SIGHUP &&
context != PGC_POSTMASTER)
{
elog(ERROR, "%s cannot be changed now", name);
/* Hmm, the idea of the SIGHUP context is "ought to be global,
* but can be changed after postmaster start". But there's
* nothing that prevents a crafty administrator from sending
* SIGHUP signals to individual backends only. */
}
else if (record->context == PGC_BACKEND && context != PGC_BACKEND
&& context != PGC_POSTMASTER)
{
if (context != PGC_SIGHUP)
elog(ERROR, "%s cannot be set after connection start", name);
else
return true;
}
else if (record->context == PGC_SUSET && (context == PGC_USERSET
|| context == PGC_BACKEND))
{
elog(ERROR, "permission denied");
}
/*
* Evaluate value and set variable
*/
switch(type)
{
case PGC_BOOL:
@@ -652,7 +687,7 @@ SetConfigOption(const char * name, const char * value, GucContext
* valid until the next call to configuration related functions.
*/
const char *
GetConfigOption(const char * name, bool issuper)
GetConfigOption(const char * name)
{
struct config_generic * record;
static char buffer[256];
@@ -662,13 +697,10 @@ GetConfigOption(const char * name, bool issuper)
if (opttype == PGC_NONE)
elog(ERROR, "not a valid option name: %s", name);
if (record->context < PGC_USERSET && !issuper)
elog(ERROR, "permission denied");
switch(opttype)
{
case PGC_BOOL:
return *((struct config_bool *)record)->variable ? "true" : "false";
return *((struct config_bool *)record)->variable ? "on" : "off";
case PGC_INT:
snprintf(buffer, 256, "%d", *((struct config_int *)record)->variable);