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);
278 bool applying =
false;
279 const char *ConfFileWithError;
332 for (item = head; item; item = item->
next)
335 strcmp(item->
name,
"data_directory") == 0)
340 newlist->
next = NULL;
341 head = tail = newlist;
380 for (item = head; item; item = item->
next)
406 for (pitem = head; pitem != item; pitem = pitem->
next)
409 strcmp(pitem->
name, item->
name) == 0)
420 (
errcode(ERRCODE_UNDEFINED_OBJECT),
421 errmsg(
"unrecognized configuration parameter \"%s\" in file \"%s\" line %d",
424 item->
errmsg =
pstrdup(
"unrecognized configuration parameter");
460 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
461 errmsg(
"parameter \"%s\" cannot be changed without restarting the server",
497 (
errmsg(
"parameter \"%s\" removed from configuration file, reset to default",
527 for (item = head; item; item = item->
next)
529 char *pre_value = NULL;
560 if (strcmp(pre_value, post_value) != 0)
562 (
errmsg(
"parameter \"%s\" changed to \"%s\"",
585 if (scres != 0 && applySettings)
598 if (
error && applySettings)
603 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
604 errmsg(
"configuration file \"%s\" contains errors",
605 ConfFileWithError)));
608 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
609 errmsg(
"configuration file \"%s\" contains errors; unaffected changes were applied",
610 ConfFileWithError)));
613 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
614 errmsg(
"configuration file \"%s\" contains errors; no changes were applied",
615 ConfFileWithError)));
639 (
errcode(ERRCODE_OUT_OF_MEMORY),
640 errmsg(
"out of memory")));
664 (
errcode(ERRCODE_OUT_OF_MEMORY),
665 errmsg(
"out of memory")));
673 size_t len = strlen(src) + 1;
726 char *oldval = *field;
787 void *oldval = *field;
823 &(
val->val.stringval),
851 &(
val->val.stringval),
883 qsort(result, *num_vars,
960 size_vars = num_vars + num_vars / 4;
962 hash_ctl.
keysize =
sizeof(
char *);
1052 (
errcode(ERRCODE_OUT_OF_MEMORY),
1053 errmsg(
"out of memory")));
1071 bool saw_sep =
false;
1072 bool name_start =
true;
1074 for (
const char *p =
name; *p; p++)
1083 else if (strchr(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1084 "abcdefghijklmnopqrstuvwxyz_", *p) != NULL ||
1090 else if (!name_start && strchr(
"0123456789$", *p) != NULL)
1135 var->
variable = (
char **) (var + 1);
1188 skip_errors, elevel);
1191 if (create_placeholders)
1202 size_t classLen = sep -
name;
1210 (
errcode(ERRCODE_INVALID_NAME),
1211 errmsg(
"invalid configuration parameter name \"%s\"",
1213 errdetail(
"Custom parameter names must be two or more simple identifiers separated by dots.")));
1219 const char *rcprefix =
lfirst(lc);
1221 if (strlen(rcprefix) == classLen &&
1222 strncmp(
name, rcprefix, classLen) == 0)
1226 (
errcode(ERRCODE_INVALID_NAME),
1227 errmsg(
"invalid configuration parameter name \"%s\"",
1229 errdetail(
"\"%s\" is a reserved prefix.",
1242 (
errcode(ERRCODE_UNDEFINED_OBJECT),
1243 errmsg(
"unrecognized configuration parameter \"%s\"",
1272 while (*namea && *nameb)
1274 char cha = *namea++;
1275 char chb = *nameb++;
1277 if (cha >=
'A' && cha <=
'Z')
1279 if (chb >=
'A' && chb <=
'Z')
1298 const char *
name = *(
const char *
const *)
key;
1305 if (ch >=
'A' && ch <=
'Z')
1321 const char *name1 = *(
const char *
const *) key1;
1322 const char *name2 = *(
const char *
const *) key2;
1355 for (
char *ptr = result; *ptr !=
'\0'; ptr++)
1359 if (ch >=
'A' && ch <=
'Z')
1401 #ifdef USE_ASSERT_CHECKING
1414 elog(
LOG,
"GUC (PGC_BOOL) %s, boot_val=%d, C-var=%d",
1426 elog(
LOG,
"GUC (PGC_INT) %s, boot_val=%d, C-var=%d",
1438 elog(
LOG,
"GUC (PGC_REAL) %s, boot_val=%g, C-var=%g",
1450 elog(
LOG,
"GUC (PGC_STRING) %s, boot_val=%s, C-var=%s",
1462 elog(
LOG,
"GUC (PGC_ENUM) %s, boot_val=%d, C-var=%d",
1479 elog(
LOG,
"GUC %s flags: NO_SHOW_ALL and !NOT_IN_SAMPLE",
1559 env = getenv(
"PGPORT");
1563 env = getenv(
"PGDATESTYLE");
1567 env = getenv(
"PGCLIENTENCODING");
1579 if (stack_rlimit > 0)
1583 if (new_limit > 100)
1588 if (new_limit < 2048)
1595 snprintf(limbuf,
sizeof(limbuf),
"%ld", new_limit);
1616 gconf->
srole = BOOTSTRAP_SUPERUSERID;
1618 gconf->
stack = NULL;
1619 gconf->
extra = NULL;
1634 elog(
FATAL,
"failed to initialize %s to %d",
1652 elog(
FATAL,
"failed to initialize %s to %d",
1670 elog(
FATAL,
"failed to initialize %s to %g",
1692 elog(
FATAL,
"failed to initialize %s to \"%s\"",
1708 elog(
FATAL,
"failed to initialize %s to %d",
1730 if (gconf->
stack != NULL)
1753 bool fname_is_malloced;
1754 struct stat stat_buf;
1763 if (configdir &&
stat(configdir, &stat_buf) != 0)
1765 write_stderr(
"%s: could not access directory \"%s\": %s\n",
1769 if (errno == ENOENT)
1770 write_stderr(
"Run initdb or pg_basebackup to initialize a PostgreSQL data directory.\n");
1783 fname_is_malloced =
true;
1790 fname_is_malloced =
false;
1794 write_stderr(
"%s does not know where to find the server configuration file.\n"
1795 "You must specify the --config-file or -D invocation "
1796 "option or set the PGDATA environment variable.\n",
1807 if (fname_is_malloced)
1817 write_stderr(
"%s: could not access the server configuration file \"%s\": %s\n",
1845 write_stderr(
"%s does not know where to find the database system data.\n"
1846 "This can be specified as \"data_directory\" in \"%s\", "
1847 "or by the -D invocation option, or by the "
1848 "PGDATA environment variable.\n",
1886 fname_is_malloced =
true;
1893 fname_is_malloced =
false;
1897 write_stderr(
"%s does not know where to find the \"hba\" configuration file.\n"
1898 "This can be specified as \"hba_file\" in \"%s\", "
1899 "or by the -D invocation option, or by the "
1900 "PGDATA environment variable.\n",
1906 if (fname_is_malloced)
1917 fname_is_malloced =
true;
1924 fname_is_malloced =
false;
1928 write_stderr(
"%s does not know where to find the \"ident\" configuration file.\n"
1929 "This can be specified as \"ident_file\" in \"%s\", "
1930 "or by the -D invocation option, or by the "
1931 "PGDATA environment variable.\n",
1937 if (fname_is_malloced)
2091 gconf->
source = newsource;
2109 stack = gconf->
stack;
2171 if (gconf->
stack == NULL)
2173 gconf->
stack = stack;
2189 elog(
WARNING,
"GUC nest level = %d at transaction start",
2246 bool restorePrior =
false;
2247 bool restoreMasked =
false;
2257 restorePrior =
true;
2259 restorePrior =
true;
2264 restoreMasked =
true;
2271 restorePrior =
true;
2273 else if (prev == NULL ||
2332 if (restorePrior || restoreMasked)
2361 void *newextra = newvalue.
extra;
2379 void *newextra = newvalue.
extra;
2397 void *newextra = newvalue.
extra;
2415 void *newextra = newvalue.
extra;
2442 void *newextra = newvalue.
extra;
2467 gconf->
srole = newsrole;
2474 gconf->
stack = prev;
2625 int base_unit,
double *base_value)
2634 while (*unit !=
'\0' && !isspace((
unsigned char) *unit) &&
2636 unitstr[unitlen++] = *(unit++);
2637 unitstr[unitlen] =
'\0';
2639 while (isspace((
unsigned char) *unit))
2650 for (
i = 0; *table[
i].
unit;
i++)
2652 if (base_unit == table[
i].base_unit &&
2653 strcmp(unitstr, table[
i].unit) == 0)
2662 if (*table[
i + 1].unit &&
2663 base_unit == table[
i + 1].base_unit)
2664 cvalue = rint(cvalue / table[
i + 1].multiplier) *
2667 *base_value = cvalue;
2683 int64 *
value,
const char **unit)
2695 for (
i = 0; *table[
i].
unit;
i++)
2697 if (base_unit == table[
i].base_unit)
2704 if (table[
i].multiplier <= 1.0 ||
2705 base_value % (int64) table[
i].multiplier == 0)
2707 *
value = (int64) rint(base_value / table[
i].multiplier);
2708 *unit = table[
i].
unit;
2725 double *
value,
const char **unit)
2737 for (
i = 0; *table[
i].
unit;
i++)
2739 if (base_unit == table[
i].base_unit)
2752 *unit = table[
i].
unit;
2781 static char bbuf[8];
2784 if (bbuf[0] ==
'\0')
2785 snprintf(bbuf,
sizeof(bbuf),
"%dkB", BLCKSZ / 1024);
2790 static char xbuf[8];
2793 if (xbuf[0] ==
'\0')
2794 snprintf(xbuf,
sizeof(xbuf),
"%dkB", XLOG_BLCKSZ / 1024);
2804 elog(
ERROR,
"unrecognized GUC units value: %d",
2848 if (*endptr ==
'.' || *endptr ==
'e' || *endptr ==
'E' ||
2855 if (endptr ==
value || errno == ERANGE)
2863 while (isspace((
unsigned char) *endptr))
2867 if (*endptr !=
'\0')
2891 if (
val > INT_MAX ||
val < INT_MIN)
2894 *hintmsg =
gettext_noop(
"Value exceeds integer range.");
2899 *result = (int)
val;
2928 if (endptr ==
value || errno == ERANGE)
2936 while (isspace((
unsigned char) *endptr))
2940 if (*endptr !=
'\0')
2980 for (entry = record->
options; entry && entry->
name; entry++)
2986 elog(
ERROR,
"could not find enum option %d for %s",
3004 for (entry = record->
options; entry && entry->
name; entry++)
3008 *retval = entry->
val;
3026 const char *suffix,
const char *
separator)
3036 for (entry = record->
options; entry && entry->
name; entry++)
3052 if (retstr.
len >= seplen)
3055 retstr.
data[retstr.
len - seplen] =
'\0';
3056 retstr.
len -= seplen;
3097 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3098 errmsg(
"parameter \"%s\" requires a Boolean value",
3111 const char *hintmsg;
3117 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3118 errmsg(
"invalid value for parameter \"%s\": \"%s\"",
3120 hintmsg ?
errhint(
"%s",
_(hintmsg)) : 0));
3129 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3130 errmsg(
"%d%s%s is outside the valid range for parameter \"%s\" (%d .. %d)",
3147 const char *hintmsg;
3153 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3154 errmsg(
"invalid value for parameter \"%s\": \"%s\"",
3156 hintmsg ?
errhint(
"%s",
_(hintmsg)) : 0));
3165 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3166 errmsg(
"%g%s%s is outside the valid range for parameter \"%s\" (%g .. %g)",
3189 if (
newval->stringval == NULL)
3198 strlen(
newval->stringval),
3205 newval->stringval = NULL;
3219 "Available values: ",
3223 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3224 errmsg(
"invalid value for parameter \"%s\": \"%s\"",
3226 hintmsg ?
errhint(
"%s",
_(hintmsg)) : 0));
3300 srole = BOOTSTRAP_SUPERUSERID;
3304 action, changeVal, elevel,
3331 void *newextra = NULL;
3332 bool prohibitValueChange =
false;
3365 (
errcode(ERRCODE_INVALID_TRANSACTION_STATE),
3366 errmsg(
"cannot set parameters during a parallel operation")));
3382 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3383 errmsg(
"parameter \"%s\" cannot be changed",
3400 prohibitValueChange =
true;
3405 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3406 errmsg(
"parameter \"%s\" cannot be changed without restarting the server",
3415 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3416 errmsg(
"parameter \"%s\" cannot be changed now",
3442 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3443 errmsg(
"permission denied to set parameter \"%s\"",
3480 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3481 errmsg(
"parameter \"%s\" cannot be set after connection start",
3500 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3501 errmsg(
"permission denied to set parameter \"%s\"",
3539 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3540 errmsg(
"cannot set parameter \"%s\" within security-definer function",
3547 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3548 errmsg(
"cannot set parameter \"%s\" within security-restricted operation",
3560 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3561 errmsg(
"parameter \"%s\" cannot be reset",
name)));
3567 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3568 errmsg(
"parameter \"%s\" cannot be set locally in functions",
3592 if (changeVal && !makeDefault)
3594 elog(
DEBUG3,
"\"%s\": setting ignored because previous source is higher priority",
3610 #define newval (newval_union.boolval)
3616 &newval_union, &newextra))
3635 if (prohibitValueChange)
3645 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3646 errmsg(
"parameter \"%s\" cannot be changed without restarting the server",
3682 for (stack = conf->
gen.
stack; stack; stack = stack->
prev)
3691 stack->
srole = srole;
3708 #define newval (newval_union.intval)
3714 &newval_union, &newextra))
3733 if (prohibitValueChange)
3743 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3744 errmsg(
"parameter \"%s\" cannot be changed without restarting the server",
3780 for (stack = conf->
gen.
stack; stack; stack = stack->
prev)
3789 stack->
srole = srole;
3806 #define newval (newval_union.realval)
3812 &newval_union, &newextra))
3831 if (prohibitValueChange)
3841 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3842 errmsg(
"parameter \"%s\" cannot be changed without restarting the server",
3878 for (stack = conf->
gen.
stack; stack; stack = stack->
prev)
3887 stack->
srole = srole;
3904 #define newval (newval_union.stringval)
3910 &newval_union, &newextra))
3945 if (prohibitValueChange)
3947 bool newval_different;
3950 newval_different = (*conf->
variable == NULL ||
3961 if (newval_different)
3965 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3966 errmsg(
"parameter \"%s\" cannot be changed without restarting the server",
4003 for (stack = conf->
gen.
stack; stack; stack = stack->
prev)
4013 stack->
srole = srole;
4033 #define newval (newval_union.enumval)
4039 &newval_union, &newextra))
4058 if (prohibitValueChange)
4068 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4069 errmsg(
"parameter \"%s\" cannot be changed without restarting the server",
4105 for (stack = conf->
gen.
stack; stack; stack = stack->
prev)
4114 stack->
srole = srole;
4135 return changeVal ? 1 : -1;
4203 static char buffer[256];
4208 if (restrict_privileged &&
4211 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4212 errmsg(
"permission denied to examine \"%s\"",
name),
4213 errdetail(
"Only roles with privileges of the \"%s\" role may examine this parameter.",
4214 "pg_read_all_settings")));
4219 return *((
struct config_bool *) record)->variable ?
"on" :
"off";
4222 snprintf(buffer,
sizeof(buffer),
"%d",
4227 snprintf(buffer,
sizeof(buffer),
"%g",
4252 static char buffer[256];
4258 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4259 errmsg(
"permission denied to examine \"%s\"",
name),
4260 errdetail(
"Only roles with privileges of the \"%s\" role may examine this parameter.",
4261 "pg_read_all_settings")));
4266 return ((
struct config_bool *) record)->reset_val ?
"on" :
"off";
4269 snprintf(buffer,
sizeof(buffer),
"%d",
4274 snprintf(buffer,
sizeof(buffer),
"%g",
4302 return record->
flags;
4335 for (item = head; item != NULL; item = item->
next)
4347 (
errcode(ERRCODE_OUT_OF_MEMORY),
4348 errmsg(
"out of memory")));
4392 for (item = *head_p; item != NULL; item =
next)
4419 item =
palloc(
sizeof *item);
4429 if (*head_p == NULL)
4432 (*tail_p)->
next = item;
4454 bool resetall =
false;
4483 elog(
ERROR,
"unrecognized alter system stmt type: %d",
4495 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4496 errmsg(
"permission denied to perform ALTER SYSTEM RESET ALL")));
4505 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4506 errmsg(
"permission denied to set parameter \"%s\"",
4529 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4530 errmsg(
"parameter \"%s\" cannot be changed",
4539 void *newextra = NULL;
4546 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4547 errmsg(
"invalid value for parameter \"%s\": \"%s\"",
4559 if (strchr(
value,
'\n'))
4561 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4562 errmsg(
"parameter value for ALTER SYSTEM must not contain a newline")));
4570 snprintf(AutoConfFileName,
sizeof(AutoConfFileName),
"%s",
4572 snprintf(AutoConfTmpFileName,
sizeof(AutoConfTmpFileName),
"%s.%s",
4591 if (
stat(AutoConfFileName, &st) == 0)
4600 errmsg(
"could not open file \"%s\": %m",
4601 AutoConfFileName)));
4607 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
4608 errmsg(
"could not parse contents of file \"%s\"",
4609 AutoConfFileName)));
4646 O_CREAT | O_RDWR | O_TRUNC);
4650 errmsg(
"could not open file \"%s\": %m",
4651 AutoConfTmpFileName)));
4680 (void) unlink(AutoConfTmpFileName);
4716 elog(
FATAL,
"cannot create PGC_POSTMASTER variables after startup");
4725 elog(
FATAL,
"extensions cannot define GUC_LIST_QUOTE variables");
4734 (strcmp(
name,
"pljava.classpath") == 0 ||
4735 strcmp(
name,
"pljava.vmoptions") == 0))
4789 (
errcode(ERRCODE_INTERNAL_ERROR),
4790 errmsg(
"attempt to redefine parameter \"%s\"",
name)));
4869 const char *curvalue,
4884 switch (stack->
state)
4888 curscontext, cursource, cursrole,
4895 curscontext, cursource, cursrole,
4902 curscontext, cursource, cursrole,
4917 curscontext, cursource, cursrole,
4924 if (
variable->stack != oldvarstack)
4943 curscontext, cursource, cursrole,
4959 const char *short_desc,
4960 const char *long_desc,
4985 const char *short_desc,
4986 const char *long_desc,
5005 var->
min = minValue;
5006 var->
max = maxValue;
5015 const char *short_desc,
5016 const char *long_desc,
5035 var->
min = minValue;
5036 var->
max = maxValue;
5045 const char *short_desc,
5046 const char *long_desc,
5048 const char *bootValue,
5070 const char *short_desc,
5071 const char *long_desc,
5107 int classLen = strlen(className);
5124 strncmp(className, var->
name, classLen) == 0 &&
5128 (
errcode(ERRCODE_INVALID_NAME),
5129 errmsg(
"invalid configuration parameter name \"%s\", removing it",
5131 errdetail(
"\"%s\" is now a reserved prefix.",
5238 result[*num] = conf;
5265 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5266 errmsg(
"permission denied to examine \"%s\"",
name),
5267 errdetail(
"Only roles with privileges of the \"%s\" role may examine this parameter.",
5268 "pg_read_all_settings")));
5271 *varname = record->
name;
5349 snprintf(buffer,
sizeof(buffer),
"%g%s",