54 #define CONFIG_FILENAME "postgresql.conf"
55 #define HBA_FILENAME "pg_hba.conf"
56 #define IDENT_FILENAME "pg_ident.conf"
59 #define CONFIG_EXEC_PARAMS "global/config_exec_params"
60 #define CONFIG_EXEC_PARAMS_NEW "global/config_exec_params.new"
67 #define REALTYPE_PRECISION 17
97 #define MAX_UNIT_LEN 3
108 #if BLCKSZ < 1024 || BLCKSZ > (1024*1024)
109 #error BLCKSZ must be between 1KB and 1MB
111 #if XLOG_BLCKSZ < 1024 || XLOG_BLCKSZ > (1024*1024)
112 #error XLOG_BLCKSZ must be between 1KB and 1MB
143 {
"TB",
GUC_UNIT_XBLOCKS, (1024.0 * 1024.0 * 1024.0) / (XLOG_BLCKSZ / 1024)},
187 "sort_mem",
"work_mem",
188 "vacuum_mem",
"maintenance_work_mem",
244 const char *curvalue,
248 bool skipIfNoPermissions);
280 bool applying =
false;
281 const char *ConfFileWithError;
334 for (item = head; item; item = item->
next)
337 strcmp(item->
name,
"data_directory") == 0)
342 newlist->
next = NULL;
343 head = tail = newlist;
382 for (item = head; item; item = item->
next)
408 for (pitem = head; pitem != item; pitem = pitem->
next)
411 strcmp(pitem->
name, item->
name) == 0)
422 (
errcode(ERRCODE_UNDEFINED_OBJECT),
423 errmsg(
"unrecognized configuration parameter \"%s\" in file \"%s\" line %d",
426 item->
errmsg =
pstrdup(
"unrecognized configuration parameter");
462 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
463 errmsg(
"parameter \"%s\" cannot be changed without restarting the server",
499 (
errmsg(
"parameter \"%s\" removed from configuration file, reset to default",
529 for (item = head; item; item = item->
next)
531 char *pre_value = NULL;
562 if (strcmp(pre_value, post_value) != 0)
564 (
errmsg(
"parameter \"%s\" changed to \"%s\"",
587 if (scres != 0 && applySettings)
600 if (
error && applySettings)
605 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
606 errmsg(
"configuration file \"%s\" contains errors",
607 ConfFileWithError)));
610 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
611 errmsg(
"configuration file \"%s\" contains errors; unaffected changes were applied",
612 ConfFileWithError)));
615 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
616 errmsg(
"configuration file \"%s\" contains errors; no changes were applied",
617 ConfFileWithError)));
641 (
errcode(ERRCODE_OUT_OF_MEMORY),
642 errmsg(
"out of memory")));
666 (
errcode(ERRCODE_OUT_OF_MEMORY),
667 errmsg(
"out of memory")));
675 size_t len = strlen(src) + 1;
728 char *oldval = *field;
789 void *oldval = *field;
825 &(
val->val.stringval),
853 &(
val->val.stringval),
885 qsort(result, *num_vars,
962 size_vars = num_vars + num_vars / 4;
964 hash_ctl.
keysize =
sizeof(
char *);
1054 (
errcode(ERRCODE_OUT_OF_MEMORY),
1055 errmsg(
"out of memory")));
1073 bool saw_sep =
false;
1074 bool name_start =
true;
1076 for (
const char *p =
name; *p; p++)
1085 else if (strchr(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1086 "abcdefghijklmnopqrstuvwxyz_", *p) != NULL ||
1092 else if (!name_start && strchr(
"0123456789$", *p) != NULL)
1123 size_t classLen = sep -
name;
1131 (
errcode(ERRCODE_INVALID_NAME),
1132 errmsg(
"invalid configuration parameter name \"%s\"",
1134 errdetail(
"Custom parameter names must be two or more simple identifiers separated by dots.")));
1140 const char *rcprefix =
lfirst(lc);
1142 if (strlen(rcprefix) == classLen &&
1143 strncmp(
name, rcprefix, classLen) == 0)
1147 (
errcode(ERRCODE_INVALID_NAME),
1148 errmsg(
"invalid configuration parameter name \"%s\"",
1150 errdetail(
"\"%s\" is a reserved prefix.",
1162 (
errcode(ERRCODE_UNDEFINED_OBJECT),
1163 errmsg(
"unrecognized configuration parameter \"%s\"",
1202 var->
variable = (
char **) (var + 1);
1255 skip_errors, elevel);
1258 if (create_placeholders)
1272 (
errcode(ERRCODE_UNDEFINED_OBJECT),
1273 errmsg(
"unrecognized configuration parameter \"%s\"",
1302 while (*namea && *nameb)
1304 char cha = *namea++;
1305 char chb = *nameb++;
1307 if (cha >=
'A' && cha <=
'Z')
1309 if (chb >=
'A' && chb <=
'Z')
1328 const char *
name = *(
const char *
const *)
key;
1335 if (ch >=
'A' && ch <=
'Z')
1351 const char *name1 = *(
const char *
const *) key1;
1352 const char *name2 = *(
const char *
const *) key2;
1385 for (
char *ptr = result; *ptr !=
'\0'; ptr++)
1389 if (ch >=
'A' && ch <=
'Z')
1429 #ifdef USE_ASSERT_CHECKING
1442 elog(
LOG,
"GUC (PGC_BOOL) %s, boot_val=%d, C-var=%d",
1454 elog(
LOG,
"GUC (PGC_INT) %s, boot_val=%d, C-var=%d",
1466 elog(
LOG,
"GUC (PGC_REAL) %s, boot_val=%g, C-var=%g",
1480 elog(
LOG,
"GUC (PGC_STRING) %s, boot_val=%s, C-var=%s",
1492 elog(
LOG,
"GUC (PGC_ENUM) %s, boot_val=%d, C-var=%d",
1509 elog(
LOG,
"GUC %s flags: NO_SHOW_ALL and !NOT_IN_SAMPLE",
1589 env = getenv(
"PGPORT");
1593 env = getenv(
"PGDATESTYLE");
1597 env = getenv(
"PGCLIENTENCODING");
1609 if (stack_rlimit > 0)
1613 if (new_limit > 100)
1618 if (new_limit < 2048)
1625 snprintf(limbuf,
sizeof(limbuf),
"%ld", new_limit);
1646 gconf->
srole = BOOTSTRAP_SUPERUSERID;
1648 gconf->
stack = NULL;
1649 gconf->
extra = NULL;
1664 elog(
FATAL,
"failed to initialize %s to %d",
1682 elog(
FATAL,
"failed to initialize %s to %d",
1700 elog(
FATAL,
"failed to initialize %s to %g",
1722 elog(
FATAL,
"failed to initialize %s to \"%s\"",
1738 elog(
FATAL,
"failed to initialize %s to %d",
1760 if (gconf->
stack != NULL)
1783 bool fname_is_malloced;
1784 struct stat stat_buf;
1793 if (configdir &&
stat(configdir, &stat_buf) != 0)
1795 write_stderr(
"%s: could not access directory \"%s\": %s\n",
1799 if (errno == ENOENT)
1800 write_stderr(
"Run initdb or pg_basebackup to initialize a PostgreSQL data directory.\n");
1813 fname_is_malloced =
true;
1820 fname_is_malloced =
false;
1824 write_stderr(
"%s does not know where to find the server configuration file.\n"
1825 "You must specify the --config-file or -D invocation "
1826 "option or set the PGDATA environment variable.\n",
1837 if (fname_is_malloced)
1847 write_stderr(
"%s: could not access the server configuration file \"%s\": %s\n",
1875 write_stderr(
"%s does not know where to find the database system data.\n"
1876 "This can be specified as data_directory in \"%s\", "
1877 "or by the -D invocation option, or by the "
1878 "PGDATA environment variable.\n",
1916 fname_is_malloced =
true;
1923 fname_is_malloced =
false;
1927 write_stderr(
"%s does not know where to find the \"hba\" configuration file.\n"
1928 "This can be specified as \"hba_file\" in \"%s\", "
1929 "or by the -D invocation option, or by the "
1930 "PGDATA environment variable.\n",
1936 if (fname_is_malloced)
1947 fname_is_malloced =
true;
1954 fname_is_malloced =
false;
1958 write_stderr(
"%s does not know where to find the \"ident\" configuration file.\n"
1959 "This can be specified as \"ident_file\" in \"%s\", "
1960 "or by the -D invocation option, or by the "
1961 "PGDATA environment variable.\n",
1967 if (fname_is_malloced)
2121 gconf->
source = newsource;
2139 stack = gconf->
stack;
2201 if (gconf->
stack == NULL)
2203 gconf->
stack = stack;
2219 elog(
WARNING,
"GUC nest level = %d at transaction start",
2276 bool restorePrior =
false;
2277 bool restoreMasked =
false;
2287 restorePrior =
true;
2289 restorePrior =
true;
2294 restoreMasked =
true;
2301 restorePrior =
true;
2303 else if (prev == NULL ||
2362 if (restorePrior || restoreMasked)
2391 void *newextra = newvalue.
extra;
2409 void *newextra = newvalue.
extra;
2427 void *newextra = newvalue.
extra;
2445 void *newextra = newvalue.
extra;
2472 void *newextra = newvalue.
extra;
2497 gconf->
srole = newsrole;
2504 gconf->
stack = prev;
2655 int base_unit,
double *base_value)
2664 while (*unit !=
'\0' && !isspace((
unsigned char) *unit) &&
2666 unitstr[unitlen++] = *(unit++);
2667 unitstr[unitlen] =
'\0';
2669 while (isspace((
unsigned char) *unit))
2680 for (
i = 0; *table[
i].
unit;
i++)
2682 if (base_unit == table[
i].base_unit &&
2683 strcmp(unitstr, table[
i].unit) == 0)
2692 if (*table[
i + 1].unit &&
2693 base_unit == table[
i + 1].base_unit)
2694 cvalue = rint(cvalue / table[
i + 1].multiplier) *
2697 *base_value = cvalue;
2713 int64 *
value,
const char **unit)
2725 for (
i = 0; *table[
i].
unit;
i++)
2727 if (base_unit == table[
i].base_unit)
2734 if (table[
i].multiplier <= 1.0 ||
2735 base_value % (int64) table[
i].multiplier == 0)
2737 *
value = (int64) rint(base_value / table[
i].multiplier);
2738 *unit = table[
i].
unit;
2755 double *
value,
const char **unit)
2767 for (
i = 0; *table[
i].
unit;
i++)
2769 if (base_unit == table[
i].base_unit)
2782 *unit = table[
i].
unit;
2811 static char bbuf[8];
2814 if (bbuf[0] ==
'\0')
2815 snprintf(bbuf,
sizeof(bbuf),
"%dkB", BLCKSZ / 1024);
2820 static char xbuf[8];
2823 if (xbuf[0] ==
'\0')
2824 snprintf(xbuf,
sizeof(xbuf),
"%dkB", XLOG_BLCKSZ / 1024);
2834 elog(
ERROR,
"unrecognized GUC units value: %d",
2878 if (*endptr ==
'.' || *endptr ==
'e' || *endptr ==
'E' ||
2885 if (endptr ==
value || errno == ERANGE)
2893 while (isspace((
unsigned char) *endptr))
2897 if (*endptr !=
'\0')
2921 if (
val > INT_MAX ||
val < INT_MIN)
2924 *hintmsg =
gettext_noop(
"Value exceeds integer range.");
2929 *result = (int)
val;
2958 if (endptr ==
value || errno == ERANGE)
2966 while (isspace((
unsigned char) *endptr))
2970 if (*endptr !=
'\0')
3010 for (entry = record->
options; entry && entry->
name; entry++)
3016 elog(
ERROR,
"could not find enum option %d for %s",
3034 for (entry = record->
options; entry && entry->
name; entry++)
3038 *retval = entry->
val;
3056 const char *suffix,
const char *
separator)
3066 for (entry = record->
options; entry && entry->
name; entry++)
3082 if (retstr.
len >= seplen)
3085 retstr.
data[retstr.
len - seplen] =
'\0';
3086 retstr.
len -= seplen;
3127 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3128 errmsg(
"parameter \"%s\" requires a Boolean value",
3141 const char *hintmsg;
3147 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3148 errmsg(
"invalid value for parameter \"%s\": \"%s\"",
3150 hintmsg ?
errhint(
"%s",
_(hintmsg)) : 0));
3159 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3160 errmsg(
"%d%s%s is outside the valid range for parameter \"%s\" (%d .. %d)",
3177 const char *hintmsg;
3183 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3184 errmsg(
"invalid value for parameter \"%s\": \"%s\"",
3186 hintmsg ?
errhint(
"%s",
_(hintmsg)) : 0));
3195 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3196 errmsg(
"%g%s%s is outside the valid range for parameter \"%s\" (%g .. %g)",
3219 if (
newval->stringval == NULL)
3228 strlen(
newval->stringval),
3235 newval->stringval = NULL;
3249 "Available values: ",
3253 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3254 errmsg(
"invalid value for parameter \"%s\": \"%s\"",
3256 hintmsg ?
errhint(
"%s",
_(hintmsg)) : 0));
3330 srole = BOOTSTRAP_SUPERUSERID;
3334 action, changeVal, elevel,
3361 action, changeVal, elevel,
3382 void *newextra = NULL;
3383 bool prohibitValueChange =
false;
3416 (
errcode(ERRCODE_INVALID_TRANSACTION_STATE),
3417 errmsg(
"cannot set parameters during a parallel operation")));
3439 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3440 errmsg(
"parameter \"%s\" cannot be changed",
3457 prohibitValueChange =
true;
3462 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3463 errmsg(
"parameter \"%s\" cannot be changed without restarting the server",
3472 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3473 errmsg(
"parameter \"%s\" cannot be changed now",
3499 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3500 errmsg(
"permission denied to set parameter \"%s\"",
3537 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3538 errmsg(
"parameter \"%s\" cannot be set after connection start",
3557 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3558 errmsg(
"permission denied to set parameter \"%s\"",
3596 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3597 errmsg(
"cannot set parameter \"%s\" within security-definer function",
3604 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3605 errmsg(
"cannot set parameter \"%s\" within security-restricted operation",
3617 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3618 errmsg(
"parameter \"%s\" cannot be reset",
name)));
3624 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3625 errmsg(
"parameter \"%s\" cannot be set locally in functions",
3649 if (changeVal && !makeDefault)
3651 elog(
DEBUG3,
"\"%s\": setting ignored because previous source is higher priority",
3667 #define newval (newval_union.boolval)
3673 &newval_union, &newextra))
3692 if (prohibitValueChange)
3702 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3703 errmsg(
"parameter \"%s\" cannot be changed without restarting the server",
3739 for (stack = conf->
gen.
stack; stack; stack = stack->
prev)
3748 stack->
srole = srole;
3765 #define newval (newval_union.intval)
3771 &newval_union, &newextra))
3790 if (prohibitValueChange)
3800 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3801 errmsg(
"parameter \"%s\" cannot be changed without restarting the server",
3837 for (stack = conf->
gen.
stack; stack; stack = stack->
prev)
3846 stack->
srole = srole;
3863 #define newval (newval_union.realval)
3869 &newval_union, &newextra))
3888 if (prohibitValueChange)
3898 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3899 errmsg(
"parameter \"%s\" cannot be changed without restarting the server",
3935 for (stack = conf->
gen.
stack; stack; stack = stack->
prev)
3944 stack->
srole = srole;
3961 #define newval (newval_union.stringval)
3967 &newval_union, &newextra))
4002 if (prohibitValueChange)
4004 bool newval_different;
4007 newval_different = (*conf->
variable == NULL ||
4018 if (newval_different)
4022 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4023 errmsg(
"parameter \"%s\" cannot be changed without restarting the server",
4060 for (stack = conf->
gen.
stack; stack; stack = stack->
prev)
4070 stack->
srole = srole;
4090 #define newval (newval_union.enumval)
4096 &newval_union, &newextra))
4115 if (prohibitValueChange)
4125 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4126 errmsg(
"parameter \"%s\" cannot be changed without restarting the server",
4162 for (stack = conf->
gen.
stack; stack; stack = stack->
prev)
4171 stack->
srole = srole;
4192 return changeVal ? 1 : -1;
4275 static char buffer[256];
4280 if (restrict_privileged &&
4283 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4284 errmsg(
"permission denied to examine \"%s\"",
name),
4285 errdetail(
"Only roles with privileges of the \"%s\" role may examine this parameter.",
4286 "pg_read_all_settings")));
4291 return *((
struct config_bool *) record)->variable ?
"on" :
"off";
4294 snprintf(buffer,
sizeof(buffer),
"%d",
4299 snprintf(buffer,
sizeof(buffer),
"%g",
4325 static char buffer[256];
4331 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4332 errmsg(
"permission denied to examine \"%s\"",
name),
4333 errdetail(
"Only roles with privileges of the \"%s\" role may examine this parameter.",
4334 "pg_read_all_settings")));
4339 return ((
struct config_bool *) record)->reset_val ?
"on" :
"off";
4342 snprintf(buffer,
sizeof(buffer),
"%d",
4347 snprintf(buffer,
sizeof(buffer),
"%g",
4376 return record->
flags;
4409 for (item = head; item != NULL; item = item->
next)
4421 (
errcode(ERRCODE_OUT_OF_MEMORY),
4422 errmsg(
"out of memory")));
4466 for (item = *head_p; item != NULL; item =
next)
4493 item =
palloc(
sizeof *item);
4503 if (*head_p == NULL)
4506 (*tail_p)->
next = item;
4528 bool resetall =
false;
4557 elog(
ERROR,
"unrecognized alter system stmt type: %d",
4569 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4570 errmsg(
"permission denied to perform ALTER SYSTEM RESET ALL")));
4579 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4580 errmsg(
"permission denied to set parameter \"%s\"",
4604 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4605 errmsg(
"parameter \"%s\" cannot be changed",
4614 void *newextra = NULL;
4620 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4621 errmsg(
"invalid value for parameter \"%s\": \"%s\"",
4648 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4649 errmsg(
"parameter value for ALTER SYSTEM must not contain a newline")));
4656 snprintf(AutoConfFileName,
sizeof(AutoConfFileName),
"%s",
4658 snprintf(AutoConfTmpFileName,
sizeof(AutoConfTmpFileName),
"%s.%s",
4677 if (
stat(AutoConfFileName, &st) == 0)
4686 errmsg(
"could not open file \"%s\": %m",
4687 AutoConfFileName)));
4693 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
4694 errmsg(
"could not parse contents of file \"%s\"",
4695 AutoConfFileName)));
4732 O_CREAT | O_RDWR | O_TRUNC);
4736 errmsg(
"could not open file \"%s\": %m",
4737 AutoConfTmpFileName)));
4766 (void) unlink(AutoConfTmpFileName);
4802 elog(
FATAL,
"cannot create PGC_POSTMASTER variables after startup");
4811 elog(
FATAL,
"extensions cannot define GUC_LIST_QUOTE variables");
4820 (strcmp(
name,
"pljava.classpath") == 0 ||
4821 strcmp(
name,
"pljava.vmoptions") == 0))
4875 (
errcode(ERRCODE_INTERNAL_ERROR),
4876 errmsg(
"attempt to redefine parameter \"%s\"",
name)));
4955 const char *curvalue,
4970 switch (stack->
state)
4974 curscontext, cursource, cursrole,
4981 curscontext, cursource, cursrole,
4988 curscontext, cursource, cursrole,
5003 curscontext, cursource, cursrole,
5010 if (
variable->stack != oldvarstack)
5029 curscontext, cursource, cursrole,
5045 const char *short_desc,
5046 const char *long_desc,
5071 const char *short_desc,
5072 const char *long_desc,
5091 var->
min = minValue;
5092 var->
max = maxValue;
5101 const char *short_desc,
5102 const char *long_desc,
5121 var->
min = minValue;
5122 var->
max = maxValue;
5131 const char *short_desc,
5132 const char *long_desc,
5134 const char *bootValue,
5156 const char *short_desc,
5157 const char *long_desc,
5193 int classLen = strlen(className);
5210 strncmp(className, var->
name, classLen) == 0 &&
5214 (
errcode(ERRCODE_INVALID_NAME),
5215 errmsg(
"invalid configuration parameter name \"%s\", removing it",
5217 errdetail(
"\"%s\" is now a reserved prefix.",
5307 else if (lconf->
boot_val == NULL ||
5331 result[*num] = conf;
5358 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5359 errmsg(
"permission denied to examine \"%s\"",
name),
5360 errdetail(
"Only roles with privileges of the \"%s\" role may examine this parameter.",
5361 "pg_read_all_settings")));
5364 *varname = record->
name;