Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3e3f659

Browse files
committed
Change first call of ProcessConfigFile so as to process only data_directory.
When both postgresql.conf and postgresql.auto.conf have their own entry of the same parameter, PostgreSQL uses the entry in postgresql.auto.conf because it appears last in the configuration scan. IOW, the other entries which appear earlier are ignored. But, previously, ProcessConfigFile() detected the invalid settings of even those unused entries and emitted the error messages complaining about them, at postmaster startup. Complaining about the entries to ignore is basically useless. This problem happened because ProcessConfigFile() was called twice at postmaster startup and the first call read only postgresql.conf. That is, the first call could check the entry which might be ignored eventually by the second call which read both postgresql.conf and postgresql.auto.conf. To work around the problem, this commit changes ProcessConfigFile so that its first call processes only data_directory and the second one does all the entries. It's OK to process data_directory in the first call because it's ensured that data_directory doesn't exist in postgresql.auto.conf. Back-patch to 9.4 where postgresql.auto.conf was added. Patch by me. Review by Amit Kapila
1 parent e15c4ab commit 3e3f659

File tree

2 files changed

+85
-12
lines changed

2 files changed

+85
-12
lines changed

src/backend/utils/misc/guc-file.l

+78-12
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ static unsigned int ConfigFileLineno;
4545
static const char *GUC_flex_fatal_errmsg;
4646
static sigjmp_buf *GUC_flex_fatal_jmp;
4747

48+
static void FreeConfigVariable(ConfigVariable *item);
49+
4850
/* flex fails to supply a prototype for yylex, so provide one */
4951
int GUC_yylex(void);
5052

@@ -151,14 +153,66 @@ ProcessConfigFile(GucContext context)
151153
* file is in the data directory, we can't read it until the DataDir has
152154
* been set.
153155
*/
154-
if (DataDir &&
155-
!ParseConfigFile(PG_AUTOCONF_FILENAME, NULL, false, 0, elevel,
156-
&head, &tail))
156+
if (DataDir)
157157
{
158-
/* Syntax error(s) detected in the file, so bail out */
159-
error = true;
160-
ErrorConfFile = PG_AUTOCONF_FILENAME;
161-
goto cleanup_list;
158+
if (!ParseConfigFile(PG_AUTOCONF_FILENAME, NULL, false, 0, elevel,
159+
&head, &tail))
160+
{
161+
/* Syntax error(s) detected in the file, so bail out */
162+
error = true;
163+
ErrorConfFile = PG_AUTOCONF_FILENAME;
164+
goto cleanup_list;
165+
}
166+
}
167+
else
168+
{
169+
ConfigVariable *prev = NULL;
170+
171+
/*
172+
* Pick up only the data_directory if DataDir is not set, which
173+
* means that the configuration file is read for the first time and
174+
* PG_AUTOCONF_FILENAME file cannot be read yet. In this case,
175+
* we shouldn't pick any settings except the data_directory
176+
* from postgresql.conf because they might be overwritten
177+
* with the settings in PG_AUTOCONF_FILENAME file which will be
178+
* read later. OTOH, since it's ensured that data_directory doesn't
179+
* exist in PG_AUTOCONF_FILENAME file, it will never be overwritten
180+
* later.
181+
*/
182+
for (item = head; item;)
183+
{
184+
ConfigVariable *ptr = item;
185+
186+
item = item->next;
187+
if (strcmp(ptr->name, "data_directory") != 0)
188+
{
189+
if (prev == NULL)
190+
head = ptr->next;
191+
else
192+
{
193+
prev->next = ptr->next;
194+
/*
195+
* On removing last item in list, we need to update tail
196+
* to ensure that list will be maintianed.
197+
*/
198+
if (prev->next == NULL)
199+
tail = prev;
200+
}
201+
FreeConfigVariable(ptr);
202+
}
203+
else
204+
prev = ptr;
205+
}
206+
207+
/*
208+
* Quick exit if data_directory is not present in list.
209+
*
210+
* Don't remember when we last successfully loaded the config file in
211+
* this case because that time will be set soon by subsequent load of
212+
* the config file.
213+
*/
214+
if (head == NULL)
215+
return;
162216
}
163217

164218
/*
@@ -677,7 +731,7 @@ ParseConfigFp(FILE *fp, const char *config_file, int depth, int elevel,
677731
*tail_p = prev_item;
678732
}
679733

680-
pfree(cur_item);
734+
FreeConfigVariable(cur_item);
681735
break;
682736
}
683737
}
@@ -857,6 +911,21 @@ cleanup:
857911
return status;
858912
}
859913

914+
/*
915+
* Free a ConfigVariable
916+
*/
917+
static void
918+
FreeConfigVariable(ConfigVariable *item)
919+
{
920+
if (item != NULL)
921+
{
922+
pfree(item->name);
923+
pfree(item->value);
924+
pfree(item->filename);
925+
pfree(item);
926+
}
927+
}
928+
860929
/*
861930
* Free a list of ConfigVariables, including the names and the values
862931
*/
@@ -870,10 +939,7 @@ FreeConfigVariables(ConfigVariable *list)
870939
{
871940
ConfigVariable *next = item->next;
872941

873-
pfree(item->name);
874-
pfree(item->value);
875-
pfree(item->filename);
876-
pfree(item);
942+
FreeConfigVariable(item);
877943
item = next;
878944
}
879945
}

src/backend/utils/misc/guc.c

+7
Original file line numberDiff line numberDiff line change
@@ -4339,6 +4339,13 @@ SelectConfigFiles(const char *userDoption, const char *progname)
43394339
return false;
43404340
}
43414341

4342+
/*
4343+
* Read the configuration file for the first time. This time only
4344+
* data_directory parameter is picked up to determine the data directory
4345+
* so that we can read PG_AUTOCONF_FILENAME file next time. Then don't
4346+
* forget to read the configuration file again later to pick up all the
4347+
* parameters.
4348+
*/
43424349
ProcessConfigFile(PGC_POSTMASTER);
43434350

43444351
/*

0 commit comments

Comments
 (0)