Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7dfab04

Browse files
committed
Support ALTER SYSTEM RESET command.
This patch allows us to execute ALTER SYSTEM RESET command toremove the configuration entry from postgresql.auto.conf.Vik Fearing, reviewed by Amit Kapila and me.
1 parent79ee637 commit7dfab04

File tree

4 files changed

+115
-62
lines changed

4 files changed

+115
-62
lines changed

‎doc/src/sgml/ref/alter_system.sgml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ PostgreSQL documentation
2222
<refsynopsisdiv>
2323
<synopsis>
2424
ALTER SYSTEM SET <replaceable class="PARAMETER">configuration_parameter</replaceable> { TO | = } { <replaceable class="PARAMETER">value</replaceable> | '<replaceable class="PARAMETER">value</replaceable>' | DEFAULT }
25+
26+
ALTER SYSTEM RESET <replaceable class="PARAMETER">configuration_parameter</replaceable>
27+
ALTER SYSTEM RESET ALL
2528
</synopsis>
2629
</refsynopsisdiv>
2730

@@ -30,10 +33,12 @@ ALTER SYSTEM SET <replaceable class="PARAMETER">configuration_parameter</replace
3033

3134
<para>
3235
<command>ALTER SYSTEM</command> writes the configuration parameter
33-
values to the <filename>postgresql.auto.conf</filename> file. With
34-
<literal>DEFAULT</literal>, it removes a configuration entry from
35-
<filename>postgresql.auto.conf</filename> file. The values will be
36-
effective after reload of server configuration (SIGHUP) or in next
36+
values to the <filename>postgresql.auto.conf</filename> file.
37+
Setting the parameter to <literal>DEFAULT</literal>, or using the
38+
<command>RESET</command> variant, removes the configuration entry from
39+
<filename>postgresql.auto.conf</filename> file. Use <literal>RESET
40+
ALL</literal> to clear all configuration entries. The values will
41+
be effective after reload of server configuration (SIGHUP) or in next
3742
server start based on the type of configuration parameter modified.
3843
</para>
3944

‎src/backend/parser/gram.y

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,8 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
398398

399399
%type<istmt>insert_rest
400400

401-
%type<vsetstmt>generic_setset_restset_rest_moreSetResetClauseFunctionSetResetClause
401+
%type<vsetstmt>generic_setset_restset_rest_moregeneric_resetreset_rest
402+
SetResetClauseFunctionSetResetClause
402403

403404
%type<node>TableElementTypedTableElementConstraintElemTableFuncElement
404405
%type<node>columnDefcolumnOptions
@@ -1564,39 +1565,47 @@ NonReservedWord_or_Sconst:
15641565
;
15651566

15661567
VariableResetStmt:
1567-
RESETvar_name
1568+
RESETreset_rest{$$ = (Node *)$2; }
1569+
;
1570+
1571+
reset_rest:
1572+
generic_reset{$$ =$1; }
1573+
|TIMEZONE
15681574
{
15691575
VariableSetStmt *n = makeNode(VariableSetStmt);
15701576
n->kind = VAR_RESET;
1571-
n->name =$2;
1572-
$$ =(Node *)n;
1577+
n->name ="timezone";
1578+
$$ = n;
15731579
}
1574-
|RESETTIMEZONE
1580+
|TRANSACTIONISOLATIONLEVEL
15751581
{
15761582
VariableSetStmt *n = makeNode(VariableSetStmt);
15771583
n->kind = VAR_RESET;
1578-
n->name ="timezone";
1579-
$$ =(Node *)n;
1584+
n->name ="transaction_isolation";
1585+
$$ = n;
15801586
}
1581-
|RESETTRANSACTIONISOLATIONLEVEL
1587+
|SESSIONAUTHORIZATION
15821588
{
15831589
VariableSetStmt *n = makeNode(VariableSetStmt);
15841590
n->kind = VAR_RESET;
1585-
n->name ="transaction_isolation";
1586-
$$ =(Node *)n;
1591+
n->name ="session_authorization";
1592+
$$ = n;
15871593
}
1588-
|RESETSESSIONAUTHORIZATION
1594+
;
1595+
1596+
generic_reset:
1597+
var_name
15891598
{
15901599
VariableSetStmt *n = makeNode(VariableSetStmt);
15911600
n->kind = VAR_RESET;
1592-
n->name ="session_authorization";
1593-
$$ =(Node *)n;
1601+
n->name =$1;
1602+
$$ = n;
15941603
}
1595-
|RESETALL
1604+
|ALL
15961605
{
15971606
VariableSetStmt *n = makeNode(VariableSetStmt);
15981607
n->kind = VAR_RESET_ALL;
1599-
$$ =(Node *)n;
1608+
$$ = n;
16001609
}
16011610
;
16021611

@@ -8442,7 +8451,7 @@ DropdbStmt: DROP DATABASE database_name
84428451

84438452
/*****************************************************************************
84448453
*
8445-
*ALTER SYSTEM SET
8454+
*ALTER SYSTEM
84468455
*
84478456
* This is used to change configuration parameters persistently.
84488457
*****************************************************************************/
@@ -8454,6 +8463,12 @@ AlterSystemStmt:
84548463
n->setstmt =$4;
84558464
$$ = (Node *)n;
84568465
}
8466+
|ALTERSYSTEM_PRESETgeneric_reset
8467+
{
8468+
AlterSystemStmt *n = makeNode(AlterSystemStmt);
8469+
n->setstmt =$4;
8470+
$$ = (Node *)n;
8471+
}
84578472
;
84588473

84598474

‎src/backend/utils/misc/guc.c

Lines changed: 60 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6691,6 +6691,8 @@ replace_auto_config_value(ConfigVariable **head_p, ConfigVariable **tail_p,
66916691
* This function takes all previous configuration parameters
66926692
* set by ALTER SYSTEM command and the currently set ones
66936693
* and write them all to the automatic configuration file.
6694+
* It just writes an empty file incase user wants to reset
6695+
* all the parameters.
66946696
*
66956697
* The configuration parameters are written to a temporary
66966698
* file then renamed to the final name.
@@ -6705,6 +6707,7 @@ AlterSystemSetConfigFile(AlterSystemStmt *altersysstmt)
67056707
{
67066708
char*name;
67076709
char*value;
6710+
boolresetall= false;
67086711
intTmpfd=-1;
67096712
FILE*infile;
67106713
structconfig_generic*record;
@@ -6732,37 +6735,48 @@ AlterSystemSetConfigFile(AlterSystemStmt *altersysstmt)
67326735
break;
67336736

67346737
caseVAR_SET_DEFAULT:
6738+
caseVAR_RESET:
6739+
value=NULL;
6740+
break;
6741+
6742+
caseVAR_RESET_ALL:
67356743
value=NULL;
6744+
resetall= true;
67366745
break;
6746+
67376747
default:
67386748
elog(ERROR,"unrecognized alter system stmt type: %d",
67396749
altersysstmt->setstmt->kind);
67406750
break;
67416751
}
67426752

6743-
record=find_option(name, false,LOG);
6744-
if (record==NULL)
6745-
ereport(ERROR,
6746-
(errcode(ERRCODE_UNDEFINED_OBJECT),
6747-
errmsg("unrecognized configuration parameter \"%s\"",name)));
6753+
/* If we're resetting everything, there's no need to validate anything */
6754+
if (!resetall)
6755+
{
6756+
record=find_option(name, false,LOG);
6757+
if (record==NULL)
6758+
ereport(ERROR,
6759+
(errcode(ERRCODE_UNDEFINED_OBJECT),
6760+
errmsg("unrecognized configuration parameter \"%s\"",name)));
67486761

6749-
/*
6750-
* Don't allow the parameters which can't be set in configuration
6751-
* files to be set in PG_AUTOCONF_FILENAME file.
6752-
*/
6753-
if ((record->context==PGC_INTERNAL)||
6754-
(record->flags&GUC_DISALLOW_IN_FILE)||
6755-
(record->flags&GUC_DISALLOW_IN_AUTO_FILE))
6756-
ereport(ERROR,
6757-
(errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6758-
errmsg("parameter \"%s\" cannot be changed",
6759-
name)));
6760-
6761-
if (!validate_conf_option(record,name,value,PGC_S_FILE,
6762-
ERROR, true,NULL,
6763-
&newextra))
6764-
ereport(ERROR,
6765-
(errmsg("invalid value for parameter \"%s\": \"%s\"",name,value)));
6762+
/*
6763+
* Don't allow the parameters which can't be set in configuration
6764+
* files to be set in PG_AUTOCONF_FILENAME file.
6765+
*/
6766+
if ((record->context==PGC_INTERNAL)||
6767+
(record->flags&GUC_DISALLOW_IN_FILE)||
6768+
(record->flags&GUC_DISALLOW_IN_AUTO_FILE))
6769+
ereport(ERROR,
6770+
(errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6771+
errmsg("parameter \"%s\" cannot be changed",
6772+
name)));
6773+
6774+
if (!validate_conf_option(record,name,value,PGC_S_FILE,
6775+
ERROR, true,NULL,
6776+
&newextra))
6777+
ereport(ERROR,
6778+
(errmsg("invalid value for parameter \"%s\": \"%s\"",name,value)));
6779+
}
67666780

67676781

67686782
/*
@@ -6794,26 +6808,34 @@ AlterSystemSetConfigFile(AlterSystemStmt *altersysstmt)
67946808

67956809
PG_TRY();
67966810
{
6797-
if (stat(AutoConfFileName,&st)==0)
6811+
/*
6812+
* If we're going to reset everything, then don't open the file, don't
6813+
* parse it, and don't do anything with the configuration list. Just
6814+
* write out an empty file.
6815+
*/
6816+
if (!resetall)
67986817
{
6799-
/* open file PG_AUTOCONF_FILENAME */
6800-
infile=AllocateFile(AutoConfFileName,"r");
6801-
if (infile==NULL)
6802-
ereport(ERROR,
6803-
(errmsg("failed to open auto conf file \"%s\": %m ",
6804-
AutoConfFileName)));
6818+
if (stat(AutoConfFileName,&st)==0)
6819+
{
6820+
/* open file PG_AUTOCONF_FILENAME */
6821+
infile=AllocateFile(AutoConfFileName,"r");
6822+
if (infile==NULL)
6823+
ereport(ERROR,
6824+
(errmsg("failed to open auto conf file \"%s\": %m ",
6825+
AutoConfFileName)));
68056826

6806-
/* parse it */
6807-
ParseConfigFp(infile,AutoConfFileName,0,LOG,&head,&tail);
6827+
/* parse it */
6828+
ParseConfigFp(infile,AutoConfFileName,0,LOG,&head,&tail);
68086829

6809-
FreeFile(infile);
6810-
}
6830+
FreeFile(infile);
6831+
}
68116832

6812-
/*
6813-
* replace with new value if the configuration parameter already
6814-
* exists OR add it as a new cofiguration parameter in the file.
6815-
*/
6816-
replace_auto_config_value(&head,&tail,AutoConfFileName,name,value);
6833+
/*
6834+
* replace with new value if the configuration parameter already
6835+
* exists OR add it as a new cofiguration parameter in the file.
6836+
*/
6837+
replace_auto_config_value(&head,&tail,AutoConfFileName,name,value);
6838+
}
68176839

68186840
/* Write and sync the new contents to the temporary file */
68196841
write_auto_conf_file(Tmpfd,AutoConfTmpFileName,&head);

‎src/bin/psql/tab-complete.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,8 @@ static const SchemaQuery Query_for_list_of_matviews = {
545545
"SELECT name FROM "\
546546
" (SELECT pg_catalog.lower(name) AS name FROM pg_catalog.pg_settings "\
547547
" WHERE context != 'internal') ss "\
548-
" WHERE substring(name,1,%d)='%s'"
548+
" WHERE substring(name,1,%d)='%s'"\
549+
" UNION ALL SELECT 'all' ss"
549550

550551
#defineQuery_for_list_of_set_vars \
551552
"SELECT name FROM "\
@@ -949,7 +950,7 @@ psql_completion(const char *text, int start, int end)
949950
{"AGGREGATE","COLLATION","CONVERSION","DATABASE","DEFAULT PRIVILEGES","DOMAIN",
950951
"EVENT TRIGGER","EXTENSION","FOREIGN DATA WRAPPER","FOREIGN TABLE","FUNCTION",
951952
"GROUP","INDEX","LANGUAGE","LARGE OBJECT","MATERIALIZED VIEW","OPERATOR",
952-
"ROLE","RULE","SCHEMA","SERVER","SEQUENCE","SYSTEM SET","TABLE",
953+
"ROLE","RULE","SCHEMA","SERVER","SEQUENCE","SYSTEM","TABLE",
953954
"TABLESPACE","TEXT SEARCH","TRIGGER","TYPE",
954955
"USER","USER MAPPING FOR","VIEW",NULL};
955956

@@ -1340,10 +1341,20 @@ psql_completion(const char *text, int start, int end)
13401341

13411342
COMPLETE_WITH_LIST(list_ALTER_SERVER);
13421343
}
1343-
/* ALTER SYSTEM SET <name> */
1344+
/* ALTER SYSTEM SET, RESET, RESET ALL */
1345+
elseif (pg_strcasecmp(prev2_wd,"ALTER")==0&&
1346+
pg_strcasecmp(prev_wd,"SYSTEM")==0)
1347+
{
1348+
staticconstchar*constlist_ALTERSYSTEM[]=
1349+
{"SET","RESET",NULL};
1350+
1351+
COMPLETE_WITH_LIST(list_ALTERSYSTEM);
1352+
}
1353+
/* ALTER SYSTEM SET|RESET <name> */
13441354
elseif (pg_strcasecmp(prev3_wd,"ALTER")==0&&
13451355
pg_strcasecmp(prev2_wd,"SYSTEM")==0&&
1346-
pg_strcasecmp(prev_wd,"SET")==0)
1356+
(pg_strcasecmp(prev_wd,"SET")==0||
1357+
pg_strcasecmp(prev_wd,"RESET")==0))
13471358
COMPLETE_WITH_QUERY(Query_for_list_of_alter_system_set_vars);
13481359
/* ALTER VIEW <name> */
13491360
elseif (pg_strcasecmp(prev3_wd,"ALTER")==0&&

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp