Commit 195e81af authored by Tom Lane's avatar Tom Lane

Find postgresql.auto.conf in PGDATA even when postgresql.conf is elsewhere.

The original coding for ALTER SYSTEM made a fundamentally bogus assumption
that postgresql.auto.conf could be sought relative to the main config file
if we hadn't yet determined the value of data_directory.  This fails for
common arrangements with the config file elsewhere, as reported by
Christoph Berg.

The simplest fix is to not try to read postgresql.auto.conf until after
SelectConfigFiles has chosen (and locked down) the data_directory setting.

Because of the logic in ProcessConfigFile for handling resetting of GUCs
that've been removed from the config file, we cannot easily read the main
and auto config files separately; so this patch adopts a brute force
approach of reading the main config file twice during postmaster startup.
That's a tad ugly, but the actual time cost is likely to be negligible,
and there's no time for a more invasive redesign before beta.

With this patch, any attempt to set data_directory via ALTER SYSTEM
will be silently ignored.  It would probably be better to throw an
error, but that can be dealt with later.  This bug, however, would
prevent any testing of ALTER SYSTEM by a significant fraction of the
userbase, so it seems important to get it fixed before beta.
parent 12e611d4
......@@ -120,8 +120,7 @@ ProcessConfigFile(GucContext context)
*head,
*tail;
int i;
char *ErrorConfFile;
char *CallingFileName;
char *ErrorConfFile = ConfigFileName;
/*
* Config files are processed on startup (by the postmaster only)
......@@ -136,9 +135,7 @@ ProcessConfigFile(GucContext context)
*/
elevel = IsUnderPostmaster ? DEBUG2 : LOG;
ErrorConfFile = ConfigFileName;
/* Parse the file into a list of option names and values */
/* Parse the main config file into a list of option names and values */
head = tail = NULL;
if (!ParseConfigFile(ConfigFileName, NULL, true, 0, elevel, &head, &tail))
......@@ -149,17 +146,14 @@ ProcessConfigFile(GucContext context)
}
/*
* Parse file PG_AUTOCONF_FILENAME after postgresql.conf to replace
* parameters set by ALTER SYSTEM command. This file is present in
* data directory, however when called during initdb data directory is not
* set till this point, so use ConfigFile path which will be same.
* Parse the PG_AUTOCONF_FILENAME file, if present, after the main file
* to replace any parameters set by ALTER SYSTEM command. Because this
* file is in the data directory, we can't read it until the DataDir has
* been set.
*/
if (data_directory)
CallingFileName = NULL;
else
CallingFileName = ConfigFileName;
if (!ParseConfigFile(PG_AUTOCONF_FILENAME, CallingFileName, false, 0, elevel, &head, &tail))
if (DataDir &&
!ParseConfigFile(PG_AUTOCONF_FILENAME, NULL, false, 0, elevel,
&head, &tail))
{
/* Syntax error(s) detected in the file, so bail out */
error = true;
......@@ -397,7 +391,7 @@ ProcessConfigFile(GucContext context)
/*
* Given a configuration file or directory location that may be a relative
* path, return an absolute one. We consider the location to be relative to
* the directory holding the calling file.
* the directory holding the calling file, or to DataDir if no calling file.
*/
static char *
AbsoluteConfigLocation(const char *location, const char *calling_file)
......@@ -417,10 +411,8 @@ AbsoluteConfigLocation(const char *location, const char *calling_file)
}
else
{
/*
* calling_file is NULL, we make an absolute path from $PGDATA
*/
join_path_components(abs_path, data_directory, location);
AssertState(DataDir);
join_path_components(abs_path, DataDir, location);
canonicalize_path(abs_path);
}
return pstrdup(abs_path);
......
......@@ -4363,6 +4363,14 @@ SelectConfigFiles(const char *userDoption, const char *progname)
*/
SetConfigOption("data_directory", DataDir, PGC_POSTMASTER, PGC_S_OVERRIDE);
/*
* Now read the config file a second time, allowing any settings in
* the PG_AUTOCONF_FILENAME file to take effect. (This is pretty ugly,
* but since we have to determine the DataDir before we can find the
* autoconf file, the alternatives seem worse.)
*/
ProcessConfigFile(PGC_POSTMASTER);
/*
* If timezone_abbreviations wasn't set in the configuration file, install
* the default value. We do it this way because we can't safely install a
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment