提交 4ee76ad8 编写于 作者: B Bruce Momjian

reset all: command line and .conf options change defaults

on RESET ALL those are restored.

show all: GUC + non-GUC.

SHOW ALL, RESET ALL

Marko Kreen
上级 d927ed20
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/reset.sgml,v 1.10 2000/12/25 23:15:26 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/reset.sgml,v 1.11 2001/06/07 04:50:56 momjian Exp $
Postgres documentation Postgres documentation
--> -->
...@@ -16,6 +16,9 @@ Postgres documentation ...@@ -16,6 +16,9 @@ Postgres documentation
<synopsis> <synopsis>
RESET <replaceable class="PARAMETER">variable</replaceable> RESET <replaceable class="PARAMETER">variable</replaceable>
</synopsis> </synopsis>
<synopsis>
RESET ALL
</synopsis>
<refsect2 id="R2-SQL-RESET-1"> <refsect2 id="R2-SQL-RESET-1">
<title>Inputs</title> <title>Inputs</title>
...@@ -30,6 +33,14 @@ RESET <replaceable class="PARAMETER">variable</replaceable> ...@@ -30,6 +33,14 @@ RESET <replaceable class="PARAMETER">variable</replaceable>
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term>ALL</term>
<listitem>
<para>
Resets all run-time parameters to default values.
</para>
</listitem>
</varlistentry>
</variablelist> </variablelist>
</para> </para>
</refsect2> </refsect2>
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/show.sgml,v 1.11 2000/12/25 23:15:26 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/show.sgml,v 1.12 2001/06/07 04:50:56 momjian Exp $
Postgres documentation Postgres documentation
--> -->
...@@ -16,6 +16,9 @@ Postgres documentation ...@@ -16,6 +16,9 @@ Postgres documentation
<synopsis> <synopsis>
SHOW <replaceable class="PARAMETER">name</replaceable> SHOW <replaceable class="PARAMETER">name</replaceable>
</synopsis> </synopsis>
<synopsis>
SHOW ALL
</synopsis>
<refsect2 id="R2-SQL-SHOW-1"> <refsect2 id="R2-SQL-SHOW-1">
<title>Inputs</title> <title>Inputs</title>
...@@ -32,6 +35,14 @@ SHOW <replaceable class="PARAMETER">name</replaceable> ...@@ -32,6 +35,14 @@ SHOW <replaceable class="PARAMETER">name</replaceable>
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term>ALL</term>
<listitem>
<para>
Show all current session parameters.
</para>
</listitem>
</varlistentry>
</variablelist> </variablelist>
</para> </para>
</refsect2> </refsect2>
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.48 2001/05/08 21:06:42 petere Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.49 2001/06/07 04:50:56 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -39,9 +39,9 @@ ...@@ -39,9 +39,9 @@
#endif #endif
static bool show_date(void); static bool show_datestyle(void);
static bool reset_date(void); static bool reset_datestyle(void);
static bool parse_date(char *); static bool parse_datestyle(char *);
static bool show_timezone(void); static bool show_timezone(void);
static bool reset_timezone(void); static bool reset_timezone(void);
static bool parse_timezone(char *); static bool parse_timezone(char *);
...@@ -192,7 +192,7 @@ static int DefaultDateStyle; ...@@ -192,7 +192,7 @@ static int DefaultDateStyle;
static bool DefaultEuroDates; static bool DefaultEuroDates;
static bool static bool
parse_date(char *value) parse_datestyle(char *value)
{ {
char *tok; char *tok;
int dcnt = 0, int dcnt = 0,
...@@ -200,7 +200,7 @@ parse_date(char *value) ...@@ -200,7 +200,7 @@ parse_date(char *value)
if (value == NULL) if (value == NULL)
{ {
reset_date(); reset_datestyle();
return TRUE; return TRUE;
} }
...@@ -261,7 +261,7 @@ parse_date(char *value) ...@@ -261,7 +261,7 @@ parse_date(char *value)
} }
static bool static bool
show_date(void) show_datestyle(void)
{ {
char buf[64]; char buf[64];
...@@ -291,7 +291,7 @@ show_date(void) ...@@ -291,7 +291,7 @@ show_date(void)
} }
static bool static bool
reset_date(void) reset_datestyle(void)
{ {
DateStyle = DefaultDateStyle; DateStyle = DefaultDateStyle;
EuroDates = DefaultEuroDates; EuroDates = DefaultEuroDates;
...@@ -325,7 +325,7 @@ set_default_datestyle(void) ...@@ -325,7 +325,7 @@ set_default_datestyle(void)
DBDate = strdup(DBDate); DBDate = strdup(DBDate);
/* Parse desired setting into DateStyle/EuroDates */ /* Parse desired setting into DateStyle/EuroDates */
parse_date(DBDate); parse_datestyle(DBDate);
free(DBDate); free(DBDate);
...@@ -396,7 +396,7 @@ show_timezone(void) ...@@ -396,7 +396,7 @@ show_timezone(void)
tz = getenv("TZ"); tz = getenv("TZ");
elog(NOTICE, "Time zone is %s", ((tz != NULL) ? tz : "unknown")); elog(NOTICE, "Time zone is %s", ((tz != NULL) ? tz : "unset"));
return TRUE; return TRUE;
} /* show_timezone() */ } /* show_timezone() */
...@@ -586,7 +586,7 @@ parse_random_seed(char *value) ...@@ -586,7 +586,7 @@ parse_random_seed(char *value)
static bool static bool
show_random_seed(void) show_random_seed(void)
{ {
elog(NOTICE, "Seed for random number generator is not known"); elog(NOTICE, "Seed for random number generator is unavailable");
return (TRUE); return (TRUE);
} }
...@@ -708,7 +708,7 @@ SetPGVariable(const char *name, const char *value) ...@@ -708,7 +708,7 @@ SetPGVariable(const char *name, const char *value)
* Special cases ought to be removed and handled separately by TCOP * Special cases ought to be removed and handled separately by TCOP
*/ */
if (strcasecmp(name, "datestyle") == 0) if (strcasecmp(name, "datestyle") == 0)
parse_date(mvalue); parse_datestyle(mvalue);
else if (strcasecmp(name, "timezone") == 0) else if (strcasecmp(name, "timezone") == 0)
parse_timezone(mvalue); parse_timezone(mvalue);
else if (strcasecmp(name, "DefaultXactIsoLevel") == 0) else if (strcasecmp(name, "DefaultXactIsoLevel") == 0)
...@@ -724,18 +724,17 @@ SetPGVariable(const char *name, const char *value) ...@@ -724,18 +724,17 @@ SetPGVariable(const char *name, const char *value)
else if (strcasecmp(name, "session_authorization") == 0) else if (strcasecmp(name, "session_authorization") == 0)
SetSessionAuthorization(value); SetSessionAuthorization(value);
else else
SetConfigOption(name, value, superuser() ? PGC_SUSET : PGC_USERSET); SetConfigOption(name, value, superuser() ? PGC_SUSET : PGC_USERSET, false);
if (mvalue) if (mvalue)
pfree(mvalue); pfree(mvalue);
} }
void void
GetPGVariable(const char *name) GetPGVariable(const char *name)
{ {
if (strcasecmp(name, "datestyle") == 0) if (strcasecmp(name, "datestyle") == 0)
show_date(); show_datestyle();
else if (strcasecmp(name, "timezone") == 0) else if (strcasecmp(name, "timezone") == 0)
show_timezone(); show_timezone();
else if (strcasecmp(name, "DefaultXactIsoLevel") == 0) else if (strcasecmp(name, "DefaultXactIsoLevel") == 0)
...@@ -748,7 +747,17 @@ GetPGVariable(const char *name) ...@@ -748,7 +747,17 @@ GetPGVariable(const char *name)
show_server_encoding(); show_server_encoding();
else if (strcasecmp(name, "seed") == 0) else if (strcasecmp(name, "seed") == 0)
show_random_seed(); show_random_seed();
else else if (strcasecmp(name, "all") == 0)
{
ShowAllGUCConfig();
show_datestyle();
show_timezone();
show_DefaultXactIsoLevel();
show_XactIsoLevel();
show_client_encoding();
show_server_encoding();
show_random_seed();
} else
{ {
const char *val = GetConfigOption(name); const char *val = GetConfigOption(name);
...@@ -760,7 +769,7 @@ void ...@@ -760,7 +769,7 @@ void
ResetPGVariable(const char *name) ResetPGVariable(const char *name)
{ {
if (strcasecmp(name, "datestyle") == 0) if (strcasecmp(name, "datestyle") == 0)
reset_date(); reset_datestyle();
else if (strcasecmp(name, "timezone") == 0) else if (strcasecmp(name, "timezone") == 0)
reset_timezone(); reset_timezone();
else if (strcasecmp(name, "DefaultXactIsoLevel") == 0) else if (strcasecmp(name, "DefaultXactIsoLevel") == 0)
...@@ -773,6 +782,17 @@ ResetPGVariable(const char *name) ...@@ -773,6 +782,17 @@ ResetPGVariable(const char *name)
reset_server_encoding(); reset_server_encoding();
else if (strcasecmp(name, "seed") == 0) else if (strcasecmp(name, "seed") == 0)
reset_random_seed(); reset_random_seed();
else else if (strcasecmp(name, "all") == 0)
SetConfigOption(name, NULL, superuser() ? PGC_SUSET : PGC_USERSET); {
reset_DefaultXactIsoLevel();
reset_XactIsoLevel();
reset_random_seed();
/* reset_server_encoding(); */
reset_client_encoding();
reset_datestyle();
reset_timezone();
ResetAllOptions();
} else
SetConfigOption(name, NULL, superuser() ? PGC_SUSET : PGC_USERSET, false);
} }
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.228 2001/06/04 23:27:23 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.229 2001/06/07 04:50:56 momjian Exp $
* *
* HISTORY * HISTORY
* AUTHOR DATE MAJOR EVENT * AUTHOR DATE MAJOR EVENT
...@@ -860,6 +860,12 @@ VariableShowStmt: SHOW ColId ...@@ -860,6 +860,12 @@ VariableShowStmt: SHOW ColId
n->name = "timezone"; n->name = "timezone";
$$ = (Node *) n; $$ = (Node *) n;
} }
| SHOW ALL
{
VariableShowStmt *n = makeNode(VariableShowStmt);
n->name = "all";
$$ = (Node *) n;
}
| SHOW TRANSACTION ISOLATION LEVEL | SHOW TRANSACTION ISOLATION LEVEL
{ {
VariableShowStmt *n = makeNode(VariableShowStmt); VariableShowStmt *n = makeNode(VariableShowStmt);
...@@ -886,6 +892,12 @@ VariableResetStmt: RESET ColId ...@@ -886,6 +892,12 @@ VariableResetStmt: RESET ColId
n->name = "XactIsoLevel"; n->name = "XactIsoLevel";
$$ = (Node *) n; $$ = (Node *) n;
} }
| RESET ALL
{
VariableResetStmt *n = makeNode(VariableResetStmt);
n->name = "all";
$$ = (Node *) n;
}
; ;
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.216 2001/06/03 14:53:56 petere Exp $ * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.217 2001/06/07 04:50:57 momjian Exp $
* *
* NOTES * NOTES
* *
...@@ -533,7 +533,7 @@ PostmasterMain(int argc, char *argv[]) ...@@ -533,7 +533,7 @@ PostmasterMain(int argc, char *argv[])
elog(ERROR, "-c %s requires argument", optarg); elog(ERROR, "-c %s requires argument", optarg);
} }
SetConfigOption(name, value, PGC_POSTMASTER); SetConfigOption(name, value, PGC_POSTMASTER, true);
free(name); free(name);
if (value) if (value)
free(value); free(value);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.218 2001/04/14 19:11:45 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.219 2001/06/07 04:50:57 momjian Exp $
* *
* NOTES * NOTES
* this is the "main" module of the postgres backend and * this is the "main" module of the postgres backend and
...@@ -1462,7 +1462,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha ...@@ -1462,7 +1462,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
/* all options are allowed if not under postmaster */ /* all options are allowed if not under postmaster */
SetConfigOption(name, value, SetConfigOption(name, value,
(IsUnderPostmaster) ? PGC_BACKEND : PGC_POSTMASTER); (IsUnderPostmaster) ? PGC_BACKEND : PGC_POSTMASTER, true);
free(name); free(name);
if (value) if (value)
free(value); free(value);
...@@ -1709,7 +1709,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha ...@@ -1709,7 +1709,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
if (!IsUnderPostmaster) if (!IsUnderPostmaster)
{ {
puts("\nPOSTGRES backend interactive interface "); puts("\nPOSTGRES backend interactive interface ");
puts("$Revision: 1.218 $ $Date: 2001/04/14 19:11:45 $\n"); puts("$Revision: 1.219 $ $Date: 2001/06/07 04:50:57 $\n");
} }
/* /*
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* *
* Copyright 2000 by PostgreSQL Global Development Group * Copyright 2000 by PostgreSQL Global Development Group
* *
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc-file.l,v 1.7 2001/06/01 20:29:43 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc-file.l,v 1.8 2001/06/07 04:50:57 momjian Exp $
*/ */
%{ %{
...@@ -260,13 +260,13 @@ ProcessConfigFile(GucContext context) ...@@ -260,13 +260,13 @@ ProcessConfigFile(GucContext context)
*/ */
for(item = head; item; item=item->next) for(item = head; item; item=item->next)
{ {
if (!set_config_option(item->name, item->value, context, false)) if (!set_config_option(item->name, item->value, context, false, false))
goto cleanup_exit; goto cleanup_exit;
} }
/* If we got here all the options parsed okay. */ /* If we got here all the options parsed okay. */
for(item = head; item; item=item->next) for(item = head; item; item=item->next)
set_config_option(item->name, item->value, context, true); set_config_option(item->name, item->value, context, true, true);
cleanup_exit: cleanup_exit:
free_name_value_list(head); free_name_value_list(head);
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* Support for grand unified configuration scheme, including SET * Support for grand unified configuration scheme, including SET
* command, configuration file, and command line options. * command, configuration file, and command line options.
* *
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.36 2001/05/17 17:44:18 petere Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.37 2001/06/07 04:50:57 momjian Exp $
* *
* Copyright 2000 by PostgreSQL Global Development Group * Copyright 2000 by PostgreSQL Global Development Group
* Written by Peter Eisentraut <peter_e@gmx.net>. * Written by Peter Eisentraut <peter_e@gmx.net>.
...@@ -136,9 +136,10 @@ struct config_string ...@@ -136,9 +136,10 @@ struct config_string
const char *name; const char *name;
GucContext context; GucContext context;
char **variable; char **variable;
const char *default_val; const char *boot_default_val;
bool (*parse_hook) (const char *proposed); bool (*parse_hook) (const char *proposed);
void (*assign_hook) (const char *newval); void (*assign_hook) (const char *newval);
char *default_val;
}; };
...@@ -433,6 +434,15 @@ ResetAllOptions(void) ...@@ -433,6 +434,15 @@ ResetAllOptions(void)
{ {
char *str = NULL; char *str = NULL;
if (!ConfigureNamesString[i].default_val
&& ConfigureNamesString[i].boot_default_val)
{
str = strdup(ConfigureNamesString[i].boot_default_val);
if (str == NULL)
elog(ERROR, "out of memory");
ConfigureNamesString[i].default_val = str;
}
if (ConfigureNamesString[i].default_val) if (ConfigureNamesString[i].default_val)
{ {
str = strdup(ConfigureNamesString[i].default_val); str = strdup(ConfigureNamesString[i].default_val);
...@@ -582,7 +592,7 @@ parse_real(const char *value, double *result) ...@@ -582,7 +592,7 @@ parse_real(const char *value, double *result)
*/ */
bool bool
set_config_option(const char *name, const char *value, GucContext set_config_option(const char *name, const char *value, GucContext
context, bool DoIt) context, bool DoIt, bool makeDefault)
{ {
struct config_generic *record; struct config_generic *record;
enum config_type type; enum config_type type;
...@@ -653,7 +663,11 @@ set_config_option(const char *name, const char *value, GucContext ...@@ -653,7 +663,11 @@ set_config_option(const char *name, const char *value, GucContext
return false; return false;
} }
if (DoIt) if (DoIt)
{
*conf->variable = boolval; *conf->variable = boolval;
if (makeDefault)
conf->default_val = boolval;
}
} }
else if (DoIt) else if (DoIt)
*conf->variable = conf->default_val; *conf->variable = conf->default_val;
...@@ -681,7 +695,11 @@ set_config_option(const char *name, const char *value, GucContext ...@@ -681,7 +695,11 @@ set_config_option(const char *name, const char *value, GucContext
return false; return false;
} }
if (DoIt) if (DoIt)
{
*conf->variable = intval; *conf->variable = intval;
if (makeDefault)
conf->default_val = intval;
}
} }
else if (DoIt) else if (DoIt)
*conf->variable = conf->default_val; *conf->variable = conf->default_val;
...@@ -709,7 +727,11 @@ set_config_option(const char *name, const char *value, GucContext ...@@ -709,7 +727,11 @@ set_config_option(const char *name, const char *value, GucContext
return false; return false;
} }
if (DoIt) if (DoIt)
{
*conf->variable = dval; *conf->variable = dval;
if (makeDefault)
conf->default_val = dval;
}
} }
else if (DoIt) else if (DoIt)
*conf->variable = conf->default_val; *conf->variable = conf->default_val;
...@@ -742,12 +764,33 @@ set_config_option(const char *name, const char *value, GucContext ...@@ -742,12 +764,33 @@ set_config_option(const char *name, const char *value, GucContext
if (*conf->variable) if (*conf->variable)
free(*conf->variable); free(*conf->variable);
*conf->variable = str; *conf->variable = str;
if (makeDefault)
{
if (conf->default_val)
free(conf->default_val);
str = strdup(value);
if (str == NULL) {
elog(elevel, "out of memory");
return false;
}
conf->default_val = str;
}
} }
} }
else if (DoIt) else if (DoIt)
{ {
char *str; char *str;
if (!conf->default_val && conf->boot_default_val)
{
str = strdup(conf->boot_default_val);
if (str == NULL)
{
elog(elevel, "out of memory");
return false;
}
conf->boot_default_val = str;
}
str = strdup(conf->default_val); str = strdup(conf->default_val);
if (str == NULL) if (str == NULL)
{ {
...@@ -776,9 +819,9 @@ set_config_option(const char *name, const char *value, GucContext ...@@ -776,9 +819,9 @@ set_config_option(const char *name, const char *value, GucContext
*/ */
void void
SetConfigOption(const char *name, const char *value, GucContext SetConfigOption(const char *name, const char *value, GucContext
context) context, bool makeDefault)
{ {
(void) set_config_option(name, value, context, true); (void) set_config_option(name, value, context, true, makeDefault);
} }
...@@ -826,6 +869,58 @@ GetConfigOption(const char *name) ...@@ -826,6 +869,58 @@ GetConfigOption(const char *name)
return NULL; return NULL;
} }
static void
_ShowOption(enum config_type opttype, struct config_generic *record)
{
static char buffer[256];
char *val;
switch (opttype)
{
case PGC_BOOL:
val = *((struct config_bool *) record)->variable ? "on" : "off";
break;
case PGC_INT:
snprintf(buffer, 256, "%d", *((struct config_int *) record)->variable);
val = buffer;
break;
case PGC_REAL:
snprintf(buffer, 256, "%g", *((struct config_real *) record)->variable);
val = buffer;
break;
case PGC_STRING:
val = strlen(*((struct config_string *) record)->variable) != 0 ?
*((struct config_string *) record)->variable : "unset";
break;
default:
val = "???";
}
elog(NOTICE, "%s is %s", record->name, val);
}
void
ShowAllGUCConfig(void)
{
int i;
for (i = 0; ConfigureNamesBool[i].name; i++)
_ShowOption(PGC_BOOL, (struct config_generic *)&ConfigureNamesBool[i]);
for (i = 0; ConfigureNamesInt[i].name; i++)
_ShowOption(PGC_INT, (struct config_generic *)&ConfigureNamesInt[i]);
for (i = 0; ConfigureNamesReal[i].name; i++)
_ShowOption(PGC_REAL, (struct config_generic *)&ConfigureNamesReal[i]);
for (i = 0; ConfigureNamesString[i].name; i++)
_ShowOption(PGC_STRING, (struct config_generic *)&ConfigureNamesString[i]);
}
/* /*
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* External declarations pertaining to backend/utils/misc/guc.c and * External declarations pertaining to backend/utils/misc/guc.c and
* backend/utils/misc/guc-file.l * backend/utils/misc/guc-file.l
* *
* $Header: /cvsroot/pgsql/src/include/utils/guc.h,v 1.6 2001/03/22 04:01:12 momjian Exp $ * $Header: /cvsroot/pgsql/src/include/utils/guc.h,v 1.7 2001/06/07 04:50:57 momjian Exp $
*/ */
#ifndef GUC_H #ifndef GUC_H
#define GUC_H #define GUC_H
...@@ -46,12 +46,13 @@ typedef enum ...@@ -46,12 +46,13 @@ typedef enum
} GucContext; } GucContext;
void SetConfigOption(const char *name, const char *value, GucContext context); void SetConfigOption(const char *name, const char *value, GucContext context, bool makeDefault);
const char *GetConfigOption(const char *name); const char *GetConfigOption(const char *name);
void ProcessConfigFile(GucContext context); void ProcessConfigFile(GucContext context);
void ResetAllOptions(void); void ResetAllOptions(void);
void ParseLongOption(const char *string, char **name, char **value); void ParseLongOption(const char *string, char **name, char **value);
bool set_config_option(const char *name, const char *value, GucContext context, bool DoIt); bool set_config_option(const char *name, const char *value, GucContext context, bool DoIt, bool makeDefault);
void ShowAllGUCConfig(void);
extern bool Debug_print_query; extern bool Debug_print_query;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册