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

Commit65d6e4c

Browse files
committed
Add ALTER SYSTEM command to edit the server configuration file.
Patch contributed by Amit Kapila. Reviewed by Hari Babu, Masao Fujii,Boszormenyi Zoltan, Andres Freund, Greg Smith and others.
1 parentdba5a9d commit65d6e4c

File tree

18 files changed

+797
-95
lines changed

18 files changed

+797
-95
lines changed

‎doc/src/sgml/config.sgml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,19 @@ SET ENABLE_SEQSCAN TO OFF;
158158
require superuser permission to change via <command>SET</command> or
159159
<command>ALTER</>.
160160
</para>
161+
162+
<para>
163+
Another way to change configuration parameters persistently is by
164+
use of <xref linkend="SQL-ALTERSYSTEM">
165+
command, for example:
166+
<screen>
167+
ALTER SYSTEM SET checkpoint_timeout TO 600;
168+
</screen>
169+
This command will allow users to change values persistently
170+
through SQL command. The values will be effective after reload of server configuration
171+
(<acronym>SIGHUP</>) or server startup. The effect of this command is similar to when
172+
user manually changes values in <filename>postgresql.conf</filename>.
173+
</para>
161174
</sect2>
162175

163176
<sect2 id="config-setting-examining">

‎doc/src/sgml/ref/allfiles.sgml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Complete list of usable sgml source files in this directory.
3030
<!ENTITY alterSchema SYSTEM "alter_schema.sgml">
3131
<!ENTITY alterServer SYSTEM "alter_server.sgml">
3232
<!ENTITY alterSequence SYSTEM "alter_sequence.sgml">
33+
<!ENTITY alterSystem SYSTEM "alter_system.sgml">
3334
<!ENTITY alterTable SYSTEM "alter_table.sgml">
3435
<!ENTITY alterTableSpace SYSTEM "alter_tablespace.sgml">
3536
<!ENTITY alterTSConfig SYSTEM "alter_tsconfig.sgml">

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

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<!--
2+
doc/src/sgml/ref/alter_system.sgml
3+
PostgreSQL documentation
4+
-->
5+
6+
<refentry id="SQL-ALTERSYSTEM">
7+
<refmeta>
8+
<refentrytitle>ALTER SYSTEM</refentrytitle>
9+
<manvolnum>7</manvolnum>
10+
<refmiscinfo>SQL - Language Statements</refmiscinfo>
11+
</refmeta>
12+
13+
<refnamediv>
14+
<refname>ALTER SYSTEM</refname>
15+
<refpurpose>change a server configuration parameter</refpurpose>
16+
</refnamediv>
17+
18+
<indexterm zone="sql-altersystem">
19+
<primary>ALTER SYSTEM</primary>
20+
</indexterm>
21+
22+
<refsynopsisdiv>
23+
<synopsis>
24+
ALTER SYSTEM SET <replaceable class="PARAMETER">configuration_parameter</replaceable> { TO | = } { <replaceable class="PARAMETER">value</replaceable> | '<replaceable class="PARAMETER">value</replaceable>' | DEFAULT }
25+
</synopsis>
26+
</refsynopsisdiv>
27+
28+
<refsect1>
29+
<title>Description</title>
30+
31+
<para>
32+
<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
37+
server start based on the type of configuration parameter modified.
38+
</para>
39+
40+
<para>
41+
This command is not allowed inside transaction block or function.
42+
</para>
43+
44+
<para>
45+
See <xref linkend="config-setting"> for other ways to set the parameters and
46+
how they become effective.
47+
</para>
48+
</refsect1>
49+
50+
<refsect1>
51+
<title>Parameters</title>
52+
53+
<variablelist>
54+
<varlistentry>
55+
<term><replaceable class="parameter">configuration_parameter</replaceable></term>
56+
<listitem>
57+
<para>
58+
Name of a settable run-time parameter. Available parameters are
59+
documented in <xref linkend="runtime-config">.
60+
</para>
61+
</listitem>
62+
</varlistentry>
63+
64+
<varlistentry>
65+
<term><replaceable class="parameter">value</replaceable></term>
66+
<listitem>
67+
<para>
68+
New value of parameter. Values can be specified as string
69+
constants, identifiers, numbers, or comma-separated lists of
70+
these, as appropriate for the particular parameter.
71+
<literal>DEFAULT</literal> can be written to specify to remove the
72+
parameter and its value from <filename>postgresql.auto.conf</filename>
73+
</para>
74+
</listitem>
75+
</varlistentry>
76+
</variablelist>
77+
</refsect1>
78+
79+
<refsect1>
80+
<title>Examples</title>
81+
82+
<para>
83+
Set the <literal>wal_level</>:
84+
<programlisting>
85+
ALTER SYSTEM SET wal_level = hot_standby;
86+
</programlisting>
87+
</para>
88+
89+
<para>
90+
Set the <literal>authentication_timeout</>:
91+
<programlisting>
92+
ALTER SYSTEM SET authentication_timeout = 10;
93+
</programlisting></para>
94+
</refsect1>
95+
96+
<refsect1>
97+
<title>Compatibility</title>
98+
99+
<para>
100+
The <command>ALTER SYSTEM</command> statement is a
101+
<productname>PostgreSQL</productname> extension.
102+
</para>
103+
</refsect1>
104+
105+
<refsect1>
106+
<title>See Also</title>
107+
108+
<simplelist type="inline">
109+
<member><xref linkend="SQL-SET"></member>
110+
<member><xref linkend="SQL-SHOW"></member>
111+
</simplelist>
112+
</refsect1>
113+
114+
</refentry>

‎doc/src/sgml/reference.sgml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
&alterSchema;
5959
&alterSequence;
6060
&alterServer;
61+
&alterSystem;
6162
&alterTable;
6263
&alterTableSpace;
6364
&alterTSConfig;

‎doc/src/sgml/storage.sgml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ Item
125125
<entry>Subdirectory containing WAL (Write Ahead Log) files</entry>
126126
</row>
127127

128+
<row>
129+
<entry><filename>postgresql.auto.conf</></entry>
130+
<entry>A file used for storing configuration parameters that are set by
131+
<command>ALTER SYSTEM</command></entry>
132+
</row>
133+
128134
<row>
129135
<entry><filename>postmaster.opts</></entry>
130136
<entry>A file recording the command-line options the server was

‎src/backend/nodes/copyfuncs.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3292,6 +3292,16 @@ _copyReplicaIdentityStmt(const ReplicaIdentityStmt *from)
32923292
returnnewnode;
32933293
}
32943294

3295+
staticAlterSystemStmt*
3296+
_copyAlterSystemStmt(constAlterSystemStmt*from)
3297+
{
3298+
AlterSystemStmt*newnode=makeNode(AlterSystemStmt);
3299+
3300+
COPY_NODE_FIELD(setstmt);
3301+
3302+
returnnewnode;
3303+
}
3304+
32953305
staticCreateSeqStmt*
32963306
_copyCreateSeqStmt(constCreateSeqStmt*from)
32973307
{
@@ -4368,6 +4378,9 @@ copyObject(const void *from)
43684378
caseT_ReplicaIdentityStmt:
43694379
retval=_copyReplicaIdentityStmt(from);
43704380
break;
4381+
caseT_AlterSystemStmt:
4382+
retval=_copyAlterSystemStmt(from);
4383+
break;
43714384
caseT_CreateSeqStmt:
43724385
retval=_copyCreateSeqStmt(from);
43734386
break;

‎src/backend/nodes/equalfuncs.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,6 +1546,15 @@ _equalReplicaIdentityStmt(const ReplicaIdentityStmt *a, const ReplicaIdentityStm
15461546
return true;
15471547
}
15481548

1549+
staticbool
1550+
_equalAlterSystemStmt(constAlterSystemStmt*a,constAlterSystemStmt*b)
1551+
{
1552+
COMPARE_NODE_FIELD(setstmt);
1553+
1554+
return true;
1555+
}
1556+
1557+
15491558
staticbool
15501559
_equalCreateSeqStmt(constCreateSeqStmt*a,constCreateSeqStmt*b)
15511560
{
@@ -2838,6 +2847,9 @@ equal(const void *a, const void *b)
28382847
caseT_ReplicaIdentityStmt:
28392848
retval=_equalReplicaIdentityStmt(a,b);
28402849
break;
2850+
caseT_AlterSystemStmt:
2851+
retval=_equalAlterSystemStmt(a,b);
2852+
break;
28412853
caseT_CreateSeqStmt:
28422854
retval=_equalCreateSeqStmt(a,b);
28432855
break;

‎src/backend/parser/gram.y

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
216216
AlterEventTrigStmt
217217
AlterDatabaseStmtAlterDatabaseSetStmtAlterDomainStmtAlterEnumStmt
218218
AlterFdwStmtAlterForeignServerStmtAlterGroupStmt
219-
AlterObjectSchemaStmtAlterOwnerStmtAlterSeqStmtAlterTableStmt
219+
AlterObjectSchemaStmtAlterOwnerStmtAlterSeqStmtAlterSystemStmtAlterTableStmt
220220
AlterExtensionStmtAlterExtensionContentsStmtAlterForeignTableStmt
221221
AlterCompositeTypeStmtAlterUserStmtAlterUserMappingStmtAlterUserSetStmt
222222
AlterRoleStmtAlterRoleSetStmt
@@ -397,7 +397,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
397397

398398
%type<istmt>insert_rest
399399

400-
%type<vsetstmt>set_restset_rest_moreSetResetClauseFunctionSetResetClause
400+
%type<vsetstmt>generic_setset_restset_rest_moreSetResetClauseFunctionSetResetClause
401401

402402
%type<node>TableElementTypedTableElementConstraintElemTableFuncElement
403403
%type<node>columnDefcolumnOptions
@@ -724,6 +724,7 @@ stmt :
724724
|AlterObjectSchemaStmt
725725
|AlterOwnerStmt
726726
|AlterSeqStmt
727+
|AlterSystemStmt
727728
|AlterTableStmt
728729
|AlterCompositeTypeStmt
729730
|AlterRoleSetStmt
@@ -1333,7 +1334,7 @@ set_rest:
13331334
|set_rest_more
13341335
;
13351336

1336-
set_rest_more:/* Generic SET syntaxes:*/
1337+
generic_set:
13371338
var_nameTOvar_list
13381339
{
13391340
VariableSetStmt *n = makeNode(VariableSetStmt);
@@ -1364,6 +1365,9 @@ set_rest_more:/* Generic SET syntaxes: */
13641365
n->name =$1;
13651366
$$ = n;
13661367
}
1368+
1369+
set_rest_more:/* Generic SET syntaxes:*/
1370+
generic_set {$$ =$1;}
13671371
|var_nameFROMCURRENT_P
13681372
{
13691373
VariableSetStmt *n = makeNode(VariableSetStmt);
@@ -8310,6 +8314,23 @@ DropdbStmt: DROP DATABASE database_name
83108314
;
83118315

83128316

8317+
/*****************************************************************************
8318+
*
8319+
*ALTER SYSTEM SET
8320+
*
8321+
* This is used to change configuration parameters persistently.
8322+
*****************************************************************************/
8323+
8324+
AlterSystemStmt:
8325+
ALTERSYSTEM_PSETgeneric_set
8326+
{
8327+
AlterSystemStmt *n = makeNode(AlterSystemStmt);
8328+
n->setstmt =$4;
8329+
$$ = (Node *)n;
8330+
}
8331+
;
8332+
8333+
83138334
/*****************************************************************************
83148335
*
83158336
* Manipulate a domain

‎src/backend/replication/basebackup.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,13 @@ sendDir(char *path, int basepathlen, bool sizeonly)
811811
strlen(PG_TEMP_FILE_PREFIX))==0)
812812
continue;
813813

814+
/* skip auto conf temporary file */
815+
if (strncmp(de->d_name,
816+
PG_AUTOCONF_FILENAME".temp",
817+
sizeof(PG_AUTOCONF_FILENAME)+4)==0)
818+
continue;
819+
820+
814821
/*
815822
* If there's a backup_label file, it belongs to a backup started by
816823
* the user with pg_start_backup(). It is *not* correct for this

‎src/backend/tcop/utility.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,11 @@ standard_ProcessUtility(Node *parsetree,
687687
ExplainQuery((ExplainStmt*)parsetree,queryString,params,dest);
688688
break;
689689

690+
caseT_AlterSystemStmt:
691+
PreventTransactionChain(isTopLevel,"ALTER SYSTEM");
692+
AlterSystemSetConfigFile((AlterSystemStmt*)parsetree);
693+
break;
694+
690695
caseT_VariableSetStmt:
691696
ExecSetVariableStmt((VariableSetStmt*)parsetree,isTopLevel);
692697
break;
@@ -2157,6 +2162,10 @@ CreateCommandTag(Node *parsetree)
21572162
tag="REFRESH MATERIALIZED VIEW";
21582163
break;
21592164

2165+
caseT_AlterSystemStmt:
2166+
tag="ALTER SYSTEM";
2167+
break;
2168+
21602169
caseT_VariableSetStmt:
21612170
switch (((VariableSetStmt*)parsetree)->kind)
21622171
{
@@ -2726,6 +2735,10 @@ GetCommandLogLevel(Node *parsetree)
27262735
lev=LOGSTMT_DDL;
27272736
break;
27282737

2738+
caseT_AlterSystemStmt:
2739+
lev=LOGSTMT_ALL;
2740+
break;
2741+
27292742
caseT_VariableSetStmt:
27302743
lev=LOGSTMT_ALL;
27312744
break;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp