285{
287 bool applying = false;
288 const char *ConfFileWithError;
290 *head,
291 *tail;
294
295 /* Parse the main config file into a list of option names and values */
297 head = tail = NULL;
298
301 &head, &tail))
302 {
303 /* Syntax error(s) detected in the file, so bail out */
306 }
307
308 /*
309 * Parse the PG_AUTOCONF_FILENAME file, if present, after the main file to
310 * replace any parameters set by ALTER SYSTEM command. Because this file
311 * is in the data directory, we can't read it until the DataDir has been
312 * set.
313 */
315 {
318 &head, &tail))
319 {
320 /* Syntax error(s) detected in the file, so bail out */
324 }
325 }
326 else
327 {
328 /*
329 * If DataDir is not set, the PG_AUTOCONF_FILENAME file cannot be
330 * read. In this case, we don't want to accept any settings but
331 * data_directory from postgresql.conf, because they might be
332 * overwritten with settings in the PG_AUTOCONF_FILENAME file which
333 * will be read later. OTOH, since data_directory isn't allowed in the
334 * PG_AUTOCONF_FILENAME file, it will never be overwritten later.
335 */
337
338 /*
339 * Prune all items except the last "data_directory" from the list.
340 */
341 for (item = head; item; item = item->
next)
342 {
344 strcmp(item->
name,
"data_directory") == 0)
345 newlist = item;
346 }
347
348 if (newlist)
349 newlist->
next = NULL;
350 head = tail = newlist;
351
352 /*
353 * Quick exit if data_directory is not present in file.
354 *
355 * We need not do any further processing, in particular we don't set
356 * PgReloadTime; that will be set soon by subsequent full loading of
357 * the config file.
358 */
359 if (head == NULL)
361 }
362
363 /*
364 * Mark all extant GUC variables as not present in the config file. We
365 * need this so that we can tell below which ones have been removed from
366 * the file since we last processed it.
367 */
370 {
372
373 gconf->
status &= ~GUC_IS_IN_FILE;
374 }
375
376 /*
377 * Check if all the supplied option names are valid, as an additional
378 * quasi-syntactic check on the validity of the config file. It is
379 * important that the postmaster and all backends agree on the results of
380 * this phase, else we will have strange inconsistencies about which
381 * processes accept a config file update and which don't. Hence, unknown
382 * custom variable names have to be accepted without complaint. For the
383 * same reason, we don't attempt to validate the options' values here.
384 *
385 * In addition, the GUC_IS_IN_FILE flag is set on each existing GUC
386 * variable mentioned in the file; and we detect duplicate entries in the
387 * file and mark the earlier occurrences as ignorable.
388 */
389 for (item = head; item; item = item->
next)
390 {
392
393 /* Ignore anything already marked as ignorable */
395 continue;
396
397 /*
398 * Try to find the variable; but do not create a custom placeholder if
399 * it's not there already.
400 */
402
403 if (record)
404 {
405 /* If it's already marked, then this is a duplicate entry */
407 {
408 /*
409 * Mark the earlier occurrence(s) as dead/ignorable. We could
410 * avoid the O(N^2) behavior here with some additional state,
411 * but it seems unlikely to be worth the trouble.
412 */
414
415 for (pitem = head; pitem != item; pitem = pitem->
next)
416 {
418 strcmp(pitem->
name, item->
name) == 0)
420 }
421 }
422 /* Now mark it as present in file */
424 }
426 {
427 /* Invalid non-custom variable, so complain */
429 (
errcode(ERRCODE_UNDEFINED_OBJECT),
430 errmsg(
"unrecognized configuration parameter \"%s\" in file \"%s\" line %d",
433 item->
errmsg =
pstrdup(
"unrecognized configuration parameter");
436 }
437 }
438
439 /*
440 * If we've detected any errors so far, we don't want to risk applying any
441 * changes.
442 */
445
446 /* Otherwise, set flag that we're beginning to apply changes */
447 applying = true;
448
449 /*
450 * Check for variables having been removed from the config file, and
451 * revert their reset values (and perhaps also effective values) to the
452 * boot-time defaults. If such a variable can't be changed after startup,
453 * report that and continue.
454 */
457 {
460
463 continue;
465 {
466 /* The removal can't be effective without a restart */
469 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
470 errmsg(
"parameter \"%s\" cannot be changed without restarting the server",
474 NULL, 0,
475 &head, &tail);
477 continue;
478 }
479
480 /* No more to do if we're just doing show_all_file_settings() */
481 if (!applySettings)
482 continue;
483
484 /*
485 * Reset any "file" sources to "default", else set_config_option will
486 * not override those settings.
487 */
493 {
496 }
497
498 /* Now we can re-apply the wired-in default (i.e., the boot_val) */
502 {
503 /* Log the change if appropriate */
506 (
errmsg(
"parameter \"%s\" removed from configuration file, reset to default",
508 }
509 }
510
511 /*
512 * Restore any variables determined by environment variables or
513 * dynamically-computed defaults. This is a no-op except in the case
514 * where one of these had been in the config file and is now removed.
515 *
516 * In particular, we *must not* do this during the postmaster's initial
517 * loading of the file, since the timezone functions in particular should
518 * be run only after initialization is complete.
519 *
520 * XXX this is an unmaintainable crock, because we have to know how to set
521 * (or at least what to call to set) every non-PGC_INTERNAL variable that
522 * could potentially have PGC_S_DYNAMIC_DEFAULT or PGC_S_ENV_VAR source.
523 */
525 {
528 /* this selects SQL_ASCII in processes not connected to a database */
531 }
532
533 /*
534 * Now apply the values from the config file.
535 */
536 for (item = head; item; item = item->
next)
537 {
538 char *pre_value = NULL;
539 int scres;
540
541 /* Ignore anything marked as ignorable */
543 continue;
544
545 /* In SIGHUP cases in the postmaster, we want to report changes */
547 {
549
550 /* If option doesn't exist yet or is NULL, treat as empty string */
551 if (!preval)
552 preval = "";
553 /* must dup, else might have dangling pointer below */
555 }
556
560 if (scres > 0)
561 {
562 /* variable was updated, so log the change if appropriate */
563 if (pre_value)
564 {
566
567 if (!post_value)
568 post_value = "";
569 if (strcmp(pre_value, post_value) != 0)
571 (
errmsg(
"parameter \"%s\" changed to \"%s\"",
573 }
575 }
576 else if (scres == 0)
577 {
581 }
582 else
583 {
584 /* no error, but variable's active value was not changed */
586 }
587
588 /*
589 * We should update source location unless there was an error, since
590 * even if the active value didn't change, the reset value might have.
591 * (In the postmaster, there won't be a difference, but it does matter
592 * in backends.)
593 */
594 if (scres != 0 && applySettings)
597
598 if (pre_value)
600 }
601
602 /* Remember when we last successfully loaded the config file. */
603 if (applySettings)
605
607 if (
error && applySettings)
608 {
609 /* During postmaster startup, any error is fatal */
612 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
613 errmsg(
"configuration file \"%s\" contains errors",
614 ConfFileWithError)));
615 else if (applying)
617 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
618 errmsg(
"configuration file \"%s\" contains errors; unaffected changes were applied",
619 ConfFileWithError)));
620 else
622 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
623 errmsg(
"configuration file \"%s\" contains errors; no changes were applied",
624 ConfFileWithError)));
625 }
626
627 /* Successful or otherwise, return the collected data list */
628 return head;
629}
TimestampTz GetCurrentTimestamp(void)
#define CONF_FILE_START_DEPTH
void * hash_seq_search(HASH_SEQ_STATUS *status)
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
void record_config_file_error(const char *errmsg, const char *config_file, int lineno, ConfigVariable **head_p, ConfigVariable **tail_p)
bool ParseConfigFile(const char *config_file, bool strict, const char *calling_file, int calling_lineno, int depth, int elevel, ConfigVariable **head_p, ConfigVariable **tail_p)
static void set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
static bool valid_custom_variable_name(const char *name)
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
const char * GetConfigOption(const char *name, bool missing_ok, bool restrict_privileged)
static void pg_timezone_abbrev_initialize(void)
struct config_generic * find_option(const char *name, bool create_placeholders, bool skip_errors, int elevel)
static void InitializeGUCOptionsFromEnvironment(void)
static void set_guc_source(struct config_generic *gconf, GucSource newsource)
static HTAB * guc_hashtab
int set_config_option(const char *name, const char *value, GucContext context, GucSource source, GucAction action, bool changeVal, int elevel, bool is_reload)
#define PG_AUTOCONF_FILENAME
#define GUC_PENDING_RESTART
const char * GetDatabaseEncodingName(void)
char * pstrdup(const char *in)
void pfree(void *pointer)
static void bail_out(bool noatexit, const char *fmt,...) pg_attribute_printf(2
char * psprintf(const char *fmt,...)
struct ConfigVariable * next
struct config_generic * gucvar