Skip to content

Commit 9ba78fb

Browse files
committed
Don't allow data_directory to be set in postgresql.auto.conf by ALTER SYSTEM.
data_directory could be set both in postgresql.conf and postgresql.auto.conf so far. This could cause some problematic situations like circular definition. To avoid such situations, this commit forbids a user to set data_directory in postgresql.auto.conf. Backpatch this to 9.4 where ALTER SYSTEM command was introduced. Amit Kapila, reviewed by Abhijit Menon-Sen, with minor adjustments by me.
1 parent df8b7bc commit 9ba78fb

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

doc/src/sgml/ref/alter_system.sgml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ ALTER SYSTEM SET <replaceable class="PARAMETER">configuration_parameter</replace
7676
</variablelist>
7777
</refsect1>
7878

79+
<refsect1>
80+
<title>Notes</title>
81+
82+
<para>
83+
This command can't be used to set <xref linkend="guc-data-directory">
84+
and any parameters (e.g., <link linkend="runtime-config-preset">preset options</>)
85+
that are not allowed in <filename>postgresql.conf</>.
86+
</para>
87+
</refsect1>
88+
7989
<refsect1>
8090
<title>Examples</title>
8191

src/backend/utils/misc/guc.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3095,10 +3095,14 @@ static struct config_string ConfigureNamesString[] =
30953095
},
30963096

30973097
{
3098+
/*
3099+
* Can't be set by ALTER SYSTEM as it can lead to recursive definition
3100+
* of data_directory.
3101+
*/
30983102
{"data_directory", PGC_POSTMASTER, FILE_LOCATIONS,
30993103
gettext_noop("Sets the server's data directory."),
31003104
NULL,
3101-
GUC_SUPERUSER_ONLY
3105+
GUC_SUPERUSER_ONLY | GUC_DISALLOW_IN_AUTO_FILE
31023106
},
31033107
&data_directory,
31043108
NULL,
@@ -6735,12 +6739,17 @@ AlterSystemSetConfigFile(AlterSystemStmt *altersysstmt)
67356739
(errcode(ERRCODE_UNDEFINED_OBJECT),
67366740
errmsg("unrecognized configuration parameter \"%s\"", name)));
67376741

6742+
/*
6743+
* Don't allow the parameters which can't be set in configuration
6744+
* files to be set in PG_AUTOCONF_FILENAME file.
6745+
*/
67386746
if ((record->context == PGC_INTERNAL) ||
6739-
(record->flags & GUC_DISALLOW_IN_FILE))
6740-
ereport(ERROR,
6741-
(errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6742-
errmsg("parameter \"%s\" cannot be changed",
6743-
name)));
6747+
(record->flags & GUC_DISALLOW_IN_FILE) ||
6748+
(record->flags & GUC_DISALLOW_IN_AUTO_FILE))
6749+
ereport(ERROR,
6750+
(errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6751+
errmsg("parameter \"%s\" cannot be changed",
6752+
name)));
67446753

67456754
if (!validate_conf_option(record, name, value, PGC_S_FILE,
67466755
ERROR, true, NULL,

src/include/utils/guc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ typedef enum
195195
#define GUC_UNIT_TIME 0x7000 /* mask for MS, S, MIN */
196196

197197
#define GUC_NOT_WHILE_SEC_REST 0x8000 /* can't set if security restricted */
198+
#define GUC_DISALLOW_IN_AUTO_FILE 0x00010000 /* can't set in PG_AUTOCONF_FILENAME */
198199

199200
/* GUC vars that are actually declared in guc.c, rather than elsewhere */
200201
extern bool log_duration;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy