55#define CONFIG_FILENAME "postgresql.conf"
56#define HBA_FILENAME "pg_hba.conf"
57#define IDENT_FILENAME "pg_ident.conf"
60#define CONFIG_EXEC_PARAMS "global/config_exec_params"
61#define CONFIG_EXEC_PARAMS_NEW "global/config_exec_params.new"
68#define REALTYPE_PRECISION 17
74#define GUC_SAFE_SEARCH_PATH "pg_catalog, pg_temp"
101#define MAX_UNIT_LEN 3
112#if BLCKSZ < 1024 || BLCKSZ > (1024*1024)
113#error BLCKSZ must be between 1KB and 1MB
115#if XLOG_BLCKSZ < 1024 || XLOG_BLCKSZ > (1024*1024)
116#error XLOG_BLCKSZ must be between 1KB and 1MB
147 {
"TB",
GUC_UNIT_XBLOCKS, (1024.0 * 1024.0 * 1024.0) / (XLOG_BLCKSZ / 1024)},
191 "sort_mem",
"work_mem",
192 "vacuum_mem",
"maintenance_work_mem",
193 "ssl_ecdh_curve",
"ssl_groups",
249 const char *curvalue,
253 bool skipIfNoPermissions);
285 bool applying =
false;
286 const char *ConfFileWithError;
339 for (item = head; item; item = item->
next)
342 strcmp(item->
name,
"data_directory") == 0)
347 newlist->
next = NULL;
348 head = tail = newlist;
371 gconf->
status &= ~GUC_IS_IN_FILE;
387 for (item = head; item; item = item->
next)
413 for (pitem = head; pitem != item; pitem = pitem->
next)
416 strcmp(pitem->
name, item->
name) == 0)
427 (
errcode(ERRCODE_UNDEFINED_OBJECT),
428 errmsg(
"unrecognized configuration parameter \"%s\" in file \"%s\" line %d",
431 item->
errmsg =
pstrdup(
"unrecognized configuration parameter");
467 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
468 errmsg(
"parameter \"%s\" cannot be changed without restarting the server",
504 (
errmsg(
"parameter \"%s\" removed from configuration file, reset to default",
534 for (item = head; item; item = item->
next)
536 char *pre_value = NULL;
567 if (strcmp(pre_value, post_value) != 0)
569 (
errmsg(
"parameter \"%s\" changed to \"%s\"",
592 if (scres != 0 && applySettings)
605 if (
error && applySettings)
610 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
611 errmsg(
"configuration file \"%s\" contains errors",
612 ConfFileWithError)));
615 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
616 errmsg(
"configuration file \"%s\" contains errors; unaffected changes were applied",
617 ConfFileWithError)));
620 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
621 errmsg(
"configuration file \"%s\" contains errors; no changes were applied",
622 ConfFileWithError)));
646 (
errcode(ERRCODE_OUT_OF_MEMORY),
647 errmsg(
"out of memory")));
671 (
errcode(ERRCODE_OUT_OF_MEMORY),
672 errmsg(
"out of memory")));
680 size_t len = strlen(src) + 1;
733 char *oldval = *field;
794 void *oldval = *field;
830 &(
val->val.stringval),
858 &(
val->val.stringval),
890 qsort(result, *num_vars,
967 size_vars = num_vars + num_vars / 4;
969 hash_ctl.
keysize =
sizeof(
char *);
1059 (
errcode(ERRCODE_OUT_OF_MEMORY),
1060 errmsg(
"out of memory")));
1078 bool saw_sep =
false;
1079 bool name_start =
true;
1081 for (
const char *p =
name; *p; p++)
1090 else if (strchr(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1091 "abcdefghijklmnopqrstuvwxyz_", *p) != NULL ||
1097 else if (!name_start && strchr(
"0123456789$", *p) != NULL)
1128 size_t classLen = sep -
name;
1136 (
errcode(ERRCODE_INVALID_NAME),
1137 errmsg(
"invalid configuration parameter name \"%s\"",
1139 errdetail(
"Custom parameter names must be two or more simple identifiers separated by dots.")));
1145 const char *rcprefix =
lfirst(lc);
1147 if (strlen(rcprefix) == classLen &&
1148 strncmp(
name, rcprefix, classLen) == 0)
1152 (
errcode(ERRCODE_INVALID_NAME),
1153 errmsg(
"invalid configuration parameter name \"%s\"",
1155 errdetail(
"\"%s\" is a reserved prefix.",
1167 (
errcode(ERRCODE_UNDEFINED_OBJECT),
1168 errmsg(
"unrecognized configuration parameter \"%s\"",
1207 var->
variable = (
char **) (var + 1);
1260 skip_errors, elevel);
1263 if (create_placeholders)
1277 (
errcode(ERRCODE_UNDEFINED_OBJECT),
1278 errmsg(
"unrecognized configuration parameter \"%s\"",
1290 const char *namea = **(
const char **
const *)
a;
1291 const char *nameb = **(
const char **
const *)
b;
1307 while (*namea && *nameb)
1309 char cha = *namea++;
1310 char chb = *nameb++;
1312 if (cha >=
'A' && cha <=
'Z')
1314 if (chb >=
'A' && chb <=
'Z')
1333 const char *
name = *(
const char *
const *)
key;
1340 if (ch >=
'A' && ch <=
'Z')
1356 const char *name1 = *(
const char *
const *) key1;
1357 const char *name2 = *(
const char *
const *) key2;
1390 for (
char *ptr = result; *ptr !=
'\0'; ptr++)
1394 if (ch >=
'A' && ch <=
'Z')
1434#ifdef USE_ASSERT_CHECKING
1447 elog(
LOG,
"GUC (PGC_BOOL) %s, boot_val=%d, C-var=%d",
1459 elog(
LOG,
"GUC (PGC_INT) %s, boot_val=%d, C-var=%d",
1471 elog(
LOG,
"GUC (PGC_REAL) %s, boot_val=%g, C-var=%g",
1485 elog(
LOG,
"GUC (PGC_STRING) %s, boot_val=%s, C-var=%s",
1497 elog(
LOG,
"GUC (PGC_ENUM) %s, boot_val=%d, C-var=%d",
1514 elog(
LOG,
"GUC %s flags: NO_SHOW_ALL and !NOT_IN_SAMPLE",
1594 env = getenv(
"PGPORT");
1598 env = getenv(
"PGDATESTYLE");
1602 env = getenv(
"PGCLIENTENCODING");
1614 if (stack_rlimit > 0)
1618 if (new_limit > 100)
1623 if (new_limit < 2048)
1630 snprintf(limbuf,
sizeof(limbuf),
"%ld", new_limit);
1651 gconf->
srole = BOOTSTRAP_SUPERUSERID;
1653 gconf->
stack = NULL;
1654 gconf->
extra = NULL;
1669 elog(
FATAL,
"failed to initialize %s to %d",
1687 elog(
FATAL,
"failed to initialize %s to %d",
1705 elog(
FATAL,
"failed to initialize %s to %g",
1727 elog(
FATAL,
"failed to initialize %s to \"%s\"",
1743 elog(
FATAL,
"failed to initialize %s to %d",
1765 if (gconf->
stack != NULL)
1788 bool fname_is_malloced;
1789 struct stat stat_buf;
1798 if (configdir &&
stat(configdir, &stat_buf) != 0)
1800 write_stderr(
"%s: could not access directory \"%s\": %m\n",
1803 if (errno == ENOENT)
1804 write_stderr(
"Run initdb or pg_basebackup to initialize a PostgreSQL data directory.\n");
1817 fname_is_malloced =
true;
1824 fname_is_malloced =
false;
1828 write_stderr(
"%s does not know where to find the server configuration file.\n"
1829 "You must specify the --config-file or -D invocation "
1830 "option or set the PGDATA environment variable.\n",
1841 if (fname_is_malloced)
1851 write_stderr(
"%s: could not access the server configuration file \"%s\": %m\n",
1879 write_stderr(
"%s does not know where to find the database system data.\n"
1880 "This can be specified as \"data_directory\" in \"%s\", "
1881 "or by the -D invocation option, or by the "
1882 "PGDATA environment variable.\n",
1920 fname_is_malloced =
true;
1927 fname_is_malloced =
false;
1931 write_stderr(
"%s does not know where to find the \"hba\" configuration file.\n"
1932 "This can be specified as \"hba_file\" in \"%s\", "
1933 "or by the -D invocation option, or by the "
1934 "PGDATA environment variable.\n",
1940 if (fname_is_malloced)
1951 fname_is_malloced =
true;
1958 fname_is_malloced =
false;
1962 write_stderr(
"%s does not know where to find the \"ident\" configuration file.\n"
1963 "This can be specified as \"ident_file\" in \"%s\", "
1964 "or by the -D invocation option, or by the "
1965 "PGDATA environment variable.\n",
1971 if (fname_is_malloced)
2125 gconf->
source = newsource;
2143 stack = gconf->
stack;
2205 if (gconf->
stack == NULL)
2207 gconf->
stack = stack;
2223 elog(
WARNING,
"GUC nest level = %d at transaction start",
2293 bool restorePrior =
false;
2294 bool restoreMasked =
false;
2304 restorePrior =
true;
2306 restorePrior =
true;
2311 restoreMasked =
true;
2318 restorePrior =
true;
2320 else if (prev == NULL ||
2379 if (restorePrior || restoreMasked)
2408 void *newextra = newvalue.
extra;
2426 void *newextra = newvalue.
extra;
2444 void *newextra = newvalue.
extra;
2462 void *newextra = newvalue.
extra;
2489 void *newextra = newvalue.
extra;
2514 gconf->
srole = newsrole;
2521 gconf->
stack = prev;
2622 conf->
status &= ~GUC_NEEDS_REPORT;
2672 int base_unit,
double *base_value)
2681 while (*unit !=
'\0' && !isspace((
unsigned char) *unit) &&
2683 unitstr[unitlen++] = *(unit++);
2684 unitstr[unitlen] =
'\0';
2686 while (isspace((
unsigned char) *unit))
2697 for (
i = 0; *table[
i].
unit;
i++)
2699 if (base_unit == table[
i].base_unit &&
2700 strcmp(unitstr, table[
i].unit) == 0)
2709 if (*table[
i + 1].unit &&
2710 base_unit == table[
i + 1].base_unit)
2711 cvalue = rint(cvalue / table[
i + 1].multiplier) *
2714 *base_value = cvalue;
2742 for (
i = 0; *table[
i].
unit;
i++)
2744 if (base_unit == table[
i].base_unit)
2751 if (table[
i].multiplier <= 1.0 ||
2752 base_value % (
int64) table[
i].multiplier == 0)
2754 *
value = (
int64) rint(base_value / table[
i].multiplier);
2755 *unit = table[
i].
unit;
2772 double *
value,
const char **unit)
2784 for (
i = 0; *table[
i].
unit;
i++)
2786 if (base_unit == table[
i].base_unit)
2799 *unit = table[
i].
unit;
2828 static char bbuf[8];
2831 if (bbuf[0] ==
'\0')
2832 snprintf(bbuf,
sizeof(bbuf),
"%dkB", BLCKSZ / 1024);
2837 static char xbuf[8];
2840 if (xbuf[0] ==
'\0')
2841 snprintf(xbuf,
sizeof(xbuf),
"%dkB", XLOG_BLCKSZ / 1024);
2851 elog(
ERROR,
"unrecognized GUC units value: %d",
2895 if (*endptr ==
'.' || *endptr ==
'e' || *endptr ==
'E' ||
2902 if (endptr ==
value || errno == ERANGE)
2910 while (isspace((
unsigned char) *endptr))
2914 if (*endptr !=
'\0')
2938 if (
val > INT_MAX ||
val < INT_MIN)
2941 *hintmsg =
gettext_noop(
"Value exceeds integer range.");
2946 *result = (int)
val;
2975 if (endptr ==
value || errno == ERANGE)
2983 while (isspace((
unsigned char) *endptr))
2987 if (*endptr !=
'\0')
3027 for (entry = record->
options; entry && entry->
name; entry++)
3033 elog(
ERROR,
"could not find enum option %d for %s",
3051 for (entry = record->
options; entry && entry->
name; entry++)
3055 *retval = entry->
val;
3073 const char *suffix,
const char *
separator)
3083 for (entry = record->
options; entry && entry->
name; entry++)
3099 if (retstr.
len >= seplen)
3102 retstr.
data[retstr.
len - seplen] =
'\0';
3103 retstr.
len -= seplen;
3143 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3144 errmsg(
"parameter \"%s\" requires a Boolean value",
3157 const char *hintmsg;
3163 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3164 errmsg(
"invalid value for parameter \"%s\": \"%s\"",
3166 hintmsg ?
errhint(
"%s",
_(hintmsg)) : 0));
3173 const char *unitspace;
3178 unit = unitspace =
"";
3181 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3182 errmsg(
"%d%s%s is outside the valid range for parameter \"%s\" (%d%s%s .. %d%s%s)",
3183 newval->intval, unitspace, unit,
3185 conf->
min, unitspace, unit,
3186 conf->
max, unitspace, unit)));
3198 const char *hintmsg;
3204 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3205 errmsg(
"invalid value for parameter \"%s\": \"%s\"",
3207 hintmsg ?
errhint(
"%s",
_(hintmsg)) : 0));
3214 const char *unitspace;
3219 unit = unitspace =
"";
3222 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3223 errmsg(
"%g%s%s is outside the valid range for parameter \"%s\" (%g%s%s .. %g%s%s)",
3224 newval->realval, unitspace, unit,
3226 conf->
min, unitspace, unit,
3227 conf->
max, unitspace, unit)));
3245 if (
newval->stringval == NULL)
3254 strlen(
newval->stringval),
3261 newval->stringval = NULL;
3275 "Available values: ",
3279 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3280 errmsg(
"invalid value for parameter \"%s\": \"%s\"",
3282 hintmsg ?
errhint(
"%s",
_(hintmsg)) : 0));
3358 srole = BOOTSTRAP_SUPERUSERID;
3362 action, changeVal, elevel,
3389 action, changeVal, elevel,
3413 void *newextra = NULL;
3414 bool prohibitValueChange =
false;
3461 (
errcode(ERRCODE_INVALID_TRANSACTION_STATE),
3462 errmsg(
"parameter \"%s\" cannot be set during a parallel operation",
3477 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3478 errmsg(
"parameter \"%s\" cannot be changed",
3495 prohibitValueChange =
true;
3500 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3501 errmsg(
"parameter \"%s\" cannot be changed without restarting the server",
3510 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3511 errmsg(
"parameter \"%s\" cannot be changed now",
3537 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3538 errmsg(
"permission denied to set parameter \"%s\"",
3579 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3580 errmsg(
"parameter \"%s\" cannot be set after connection start",
3599 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3600 errmsg(
"permission denied to set parameter \"%s\"",
3638 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3639 errmsg(
"cannot set parameter \"%s\" within security-definer function",
3646 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3647 errmsg(
"cannot set parameter \"%s\" within security-restricted operation",
3659 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3660 errmsg(
"parameter \"%s\" cannot be reset", record->
name)));
3666 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3667 errmsg(
"parameter \"%s\" cannot be set locally in functions",
3691 if (changeVal && !makeDefault)
3693 elog(
DEBUG3,
"\"%s\": setting ignored because previous source is higher priority",
3709#define newval (newval_union.boolval)
3715 &newval_union, &newextra))
3734 if (prohibitValueChange)
3744 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3745 errmsg(
"parameter \"%s\" cannot be changed without restarting the server",
3749 record->
status &= ~GUC_PENDING_RESTART;
3781 for (stack = conf->
gen.
stack; stack; stack = stack->
prev)
3790 stack->
srole = srole;
3807#define newval (newval_union.intval)
3813 &newval_union, &newextra))
3832 if (prohibitValueChange)
3842 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3843 errmsg(
"parameter \"%s\" cannot be changed without restarting the server",
3847 record->
status &= ~GUC_PENDING_RESTART;
3879 for (stack = conf->
gen.
stack; stack; stack = stack->
prev)
3888 stack->
srole = srole;
3905#define newval (newval_union.realval)
3911 &newval_union, &newextra))
3930 if (prohibitValueChange)
3940 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3941 errmsg(
"parameter \"%s\" cannot be changed without restarting the server",
3945 record->
status &= ~GUC_PENDING_RESTART;
3977 for (stack = conf->
gen.
stack; stack; stack = stack->
prev)
3986 stack->
srole = srole;
4004 Oid orig_srole = srole;
4006#define newval (newval_union.stringval)
4012 &newval_union, &newextra))
4047 if (prohibitValueChange)
4049 bool newval_different;
4052 newval_different = (*conf->
variable == NULL ||
4063 if (newval_different)
4067 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4068 errmsg(
"parameter \"%s\" cannot be changed without restarting the server",
4072 record->
status &= ~GUC_PENDING_RESTART;
4116 strcmp(conf->
gen.
name,
"session_authorization") == 0)
4118 value ?
"none" : NULL,
4143 for (stack = conf->
gen.
stack; stack; stack = stack->
prev)
4153 stack->
srole = srole;
4173#define newval (newval_union.enumval)
4179 &newval_union, &newextra))
4198 if (prohibitValueChange)
4208 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4209 errmsg(
"parameter \"%s\" cannot be changed without restarting the server",
4213 record->
status &= ~GUC_PENDING_RESTART;
4245 for (stack = conf->
gen.
stack; stack; stack = stack->
prev)
4254 stack->
srole = srole;
4275 return changeVal ? 1 : -1;
4358 static char buffer[256];
4363 if (restrict_privileged &&
4366 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4367 errmsg(
"permission denied to examine \"%s\"",
name),
4368 errdetail(
"Only roles with privileges of the \"%s\" role may examine this parameter.",
4369 "pg_read_all_settings")));
4374 return *((
struct config_bool *) record)->variable ?
"on" :
"off";
4377 snprintf(buffer,
sizeof(buffer),
"%d",
4382 snprintf(buffer,
sizeof(buffer),
"%g",
4408 static char buffer[256];
4414 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4415 errmsg(
"permission denied to examine \"%s\"",
name),
4416 errdetail(
"Only roles with privileges of the \"%s\" role may examine this parameter.",
4417 "pg_read_all_settings")));
4422 return ((
struct config_bool *) record)->reset_val ?
"on" :
"off";
4425 snprintf(buffer,
sizeof(buffer),
"%d",
4430 snprintf(buffer,
sizeof(buffer),
"%g",
4459 return record->
flags;
4492 for (item = head; item != NULL; item = item->
next)
4504 (
errcode(ERRCODE_OUT_OF_MEMORY),
4505 errmsg(
"out of memory")));
4549 for (item = *head_p; item != NULL; item =
next)
4576 item =
palloc(
sizeof *item);
4586 if (*head_p == NULL)
4589 (*tail_p)->
next = item;
4611 bool resetall =
false;
4625 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4626 errmsg(
"ALTER SYSTEM is not allowed in this environment")));
4645 elog(
ERROR,
"unrecognized alter system stmt type: %d",
4657 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4658 errmsg(
"permission denied to perform ALTER SYSTEM RESET ALL")));
4667 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4668 errmsg(
"permission denied to set parameter \"%s\"",
4692 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4693 errmsg(
"parameter \"%s\" cannot be changed",
4702 void *newextra = NULL;
4708 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4709 errmsg(
"invalid value for parameter \"%s\": \"%s\"",
4736 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4737 errmsg(
"parameter value for ALTER SYSTEM must not contain a newline")));
4744 snprintf(AutoConfFileName,
sizeof(AutoConfFileName),
"%s",
4746 snprintf(AutoConfTmpFileName,
sizeof(AutoConfTmpFileName),
"%s.%s",
4765 if (
stat(AutoConfFileName, &st) == 0)
4774 errmsg(
"could not open file \"%s\": %m",
4775 AutoConfFileName)));
4781 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
4782 errmsg(
"could not parse contents of file \"%s\"",
4783 AutoConfFileName)));
4820 O_CREAT | O_RDWR | O_TRUNC);
4824 errmsg(
"could not open file \"%s\": %m",
4825 AutoConfTmpFileName)));
4854 (void) unlink(AutoConfTmpFileName);
4890 elog(
FATAL,
"cannot create PGC_POSTMASTER variables after startup");
4899 elog(
FATAL,
"extensions cannot define GUC_LIST_QUOTE variables");
4908 (strcmp(
name,
"pljava.classpath") == 0 ||
4909 strcmp(
name,
"pljava.vmoptions") == 0))
4963 (
errcode(ERRCODE_INTERNAL_ERROR),
4964 errmsg(
"attempt to redefine parameter \"%s\"",
name)));