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",
243 const char *curvalue,
247 bool user_set,
bool skipIfNoPermissions);
277 bool applying =
false;
278 const char *ConfFileWithError;
331 for (item = head; item; item = item->
next)
334 strcmp(item->
name,
"data_directory") == 0)
339 newlist->
next = NULL;
340 head = tail = newlist;
379 for (item = head; item; item = item->
next)
405 for (pitem = head; pitem != item; pitem = pitem->
next)
408 strcmp(pitem->
name, item->
name) == 0)
419 (
errcode(ERRCODE_UNDEFINED_OBJECT),
420 errmsg(
"unrecognized configuration parameter \"%s\" in file \"%s\" line %d",
423 item->
errmsg =
pstrdup(
"unrecognized configuration parameter");
459 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
460 errmsg(
"parameter \"%s\" cannot be changed without restarting the server",
496 (
errmsg(
"parameter \"%s\" removed from configuration file, reset to default",
526 for (item = head; item; item = item->
next)
528 char *pre_value = NULL;
559 if (strcmp(pre_value, post_value) != 0)
561 (
errmsg(
"parameter \"%s\" changed to \"%s\"",
584 if (scres != 0 && applySettings)
597 if (
error && applySettings)
602 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
603 errmsg(
"configuration file \"%s\" contains errors",
604 ConfFileWithError)));
607 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
608 errmsg(
"configuration file \"%s\" contains errors; unaffected changes were applied",
609 ConfFileWithError)));
612 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
613 errmsg(
"configuration file \"%s\" contains errors; no changes were applied",
614 ConfFileWithError)));
638 (
errcode(ERRCODE_OUT_OF_MEMORY),
639 errmsg(
"out of memory")));
663 (
errcode(ERRCODE_OUT_OF_MEMORY),
664 errmsg(
"out of memory")));
672 size_t len = strlen(src) + 1;
725 char *oldval = *field;
786 void *oldval = *field;
822 &(
val->val.stringval),
850 &(
val->val.stringval),
882 qsort(result, *num_vars,
959 size_vars = num_vars + num_vars / 4;
961 hash_ctl.
keysize =
sizeof(
char *);
1051 (
errcode(ERRCODE_OUT_OF_MEMORY),
1052 errmsg(
"out of memory")));
1070 bool saw_sep =
false;
1071 bool name_start =
true;
1073 for (
const char *p =
name; *p; p++)
1082 else if (strchr(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1083 "abcdefghijklmnopqrstuvwxyz_", *p) != NULL ||
1089 else if (!name_start && strchr(
"0123456789$", *p) != NULL)
1134 var->
variable = (
char **) (var + 1);
1187 skip_errors, elevel);
1190 if (create_placeholders)
1201 size_t classLen = sep -
name;
1209 (
errcode(ERRCODE_INVALID_NAME),
1210 errmsg(
"invalid configuration parameter name \"%s\"",
1212 errdetail(
"Custom parameter names must be two or more simple identifiers separated by dots.")));
1218 const char *rcprefix =
lfirst(lc);
1220 if (strlen(rcprefix) == classLen &&
1221 strncmp(
name, rcprefix, classLen) == 0)
1225 (
errcode(ERRCODE_INVALID_NAME),
1226 errmsg(
"invalid configuration parameter name \"%s\"",
1228 errdetail(
"\"%s\" is a reserved prefix.",
1241 (
errcode(ERRCODE_UNDEFINED_OBJECT),
1242 errmsg(
"unrecognized configuration parameter \"%s\"",
1271 while (*namea && *nameb)
1273 char cha = *namea++;
1274 char chb = *nameb++;
1276 if (cha >=
'A' && cha <=
'Z')
1278 if (chb >=
'A' && chb <=
'Z')
1297 const char *
name = *(
const char *
const *)
key;
1304 if (ch >=
'A' && ch <=
'Z')
1320 const char *name1 = *(
const char *
const *) key1;
1321 const char *name2 = *(
const char *
const *) key2;
1354 for (
char *ptr = result; *ptr !=
'\0'; ptr++)
1358 if (ch >=
'A' && ch <=
'Z')
1397 #ifdef USE_ASSERT_CHECKING
1409 elog(
LOG,
"GUC (PGC_BOOL) %s, boot_val=%d, C-var=%d",
1421 elog(
LOG,
"GUC (PGC_INT) %s, boot_val=%d, C-var=%d",
1433 elog(
LOG,
"GUC (PGC_REAL) %s, boot_val=%g, C-var=%g",
1445 elog(
LOG,
"GUC (PGC_STRING) %s, boot_val=%s, C-var=%s",
1457 elog(
LOG,
"GUC (PGC_ENUM) %s, boot_val=%d, C-var=%d",
1540 env = getenv(
"PGPORT");
1544 env = getenv(
"PGDATESTYLE");
1548 env = getenv(
"PGCLIENTENCODING");
1560 if (stack_rlimit > 0)
1564 if (new_limit > 100)
1569 if (new_limit < 2048)
1576 snprintf(limbuf,
sizeof(limbuf),
"%ld", new_limit);
1597 gconf->
srole = BOOTSTRAP_SUPERUSERID;
1599 gconf->
stack = NULL;
1600 gconf->
extra = NULL;
1615 elog(
FATAL,
"failed to initialize %s to %d",
1633 elog(
FATAL,
"failed to initialize %s to %d",
1651 elog(
FATAL,
"failed to initialize %s to %g",
1673 elog(
FATAL,
"failed to initialize %s to \"%s\"",
1689 elog(
FATAL,
"failed to initialize %s to %d",
1711 if (gconf->
stack != NULL)
1734 bool fname_is_malloced;
1735 struct stat stat_buf;
1744 if (configdir &&
stat(configdir, &stat_buf) != 0)
1746 write_stderr(
"%s: could not access directory \"%s\": %s\n",
1750 if (errno == ENOENT)
1751 write_stderr(
"Run initdb or pg_basebackup to initialize a PostgreSQL data directory.\n");
1764 fname_is_malloced =
true;
1771 fname_is_malloced =
false;
1775 write_stderr(
"%s does not know where to find the server configuration file.\n"
1776 "You must specify the --config-file or -D invocation "
1777 "option or set the PGDATA environment variable.\n",
1788 if (fname_is_malloced)
1798 write_stderr(
"%s: could not access the server configuration file \"%s\": %s\n",
1826 write_stderr(
"%s does not know where to find the database system data.\n"
1827 "This can be specified as \"data_directory\" in \"%s\", "
1828 "or by the -D invocation option, or by the "
1829 "PGDATA environment variable.\n",
1867 fname_is_malloced =
true;
1874 fname_is_malloced =
false;
1878 write_stderr(
"%s does not know where to find the \"hba\" configuration file.\n"
1879 "This can be specified as \"hba_file\" in \"%s\", "
1880 "or by the -D invocation option, or by the "
1881 "PGDATA environment variable.\n",
1887 if (fname_is_malloced)
1898 fname_is_malloced =
true;
1905 fname_is_malloced =
false;
1909 write_stderr(
"%s does not know where to find the \"ident\" configuration file.\n"
1910 "This can be specified as \"ident_file\" in \"%s\", "
1911 "or by the -D invocation option, or by the "
1912 "PGDATA environment variable.\n",
1918 if (fname_is_malloced)
2072 gconf->
source = newsource;
2090 stack = gconf->
stack;
2152 if (gconf->
stack == NULL)
2154 gconf->
stack = stack;
2170 elog(
WARNING,
"GUC nest level = %d at transaction start",
2227 bool restorePrior =
false;
2228 bool restoreMasked =
false;
2238 restorePrior =
true;
2240 restorePrior =
true;
2245 restoreMasked =
true;
2252 restorePrior =
true;
2254 else if (prev == NULL ||
2313 if (restorePrior || restoreMasked)
2342 void *newextra = newvalue.
extra;
2360 void *newextra = newvalue.
extra;
2378 void *newextra = newvalue.
extra;
2396 void *newextra = newvalue.
extra;
2423 void *newextra = newvalue.
extra;
2448 gconf->
srole = newsrole;
2455 gconf->
stack = prev;
2606 int base_unit,
double *base_value)
2615 while (*unit !=
'\0' && !isspace((
unsigned char) *unit) &&
2617 unitstr[unitlen++] = *(unit++);
2618 unitstr[unitlen] =
'\0';
2620 while (isspace((
unsigned char) *unit))
2631 for (
i = 0; *table[
i].
unit;
i++)
2633 if (base_unit == table[
i].base_unit &&
2634 strcmp(unitstr, table[
i].unit) == 0)
2643 if (*table[
i + 1].unit &&
2644 base_unit == table[
i + 1].base_unit)
2645 cvalue = rint(cvalue / table[
i + 1].multiplier) *
2648 *base_value = cvalue;
2664 int64 *
value,
const char **unit)
2676 for (
i = 0; *table[
i].
unit;
i++)
2678 if (base_unit == table[
i].base_unit)
2685 if (table[
i].multiplier <= 1.0 ||
2686 base_value % (int64) table[
i].multiplier == 0)
2688 *
value = (int64) rint(base_value / table[
i].multiplier);
2689 *unit = table[
i].
unit;
2706 double *
value,
const char **unit)
2718 for (
i = 0; *table[
i].
unit;
i++)
2720 if (base_unit == table[
i].base_unit)
2733 *unit = table[
i].
unit;
2762 static char bbuf[8];
2765 if (bbuf[0] ==
'\0')
2766 snprintf(bbuf,
sizeof(bbuf),
"%dkB", BLCKSZ / 1024);
2771 static char xbuf[8];
2774 if (xbuf[0] ==
'\0')
2775 snprintf(xbuf,
sizeof(xbuf),
"%dkB", XLOG_BLCKSZ / 1024);
2785 elog(
ERROR,
"unrecognized GUC units value: %d",
2829 if (*endptr ==
'.' || *endptr ==
'e' || *endptr ==
'E' ||
2836 if (endptr ==
value || errno == ERANGE)
2844 while (isspace((
unsigned char) *endptr))
2848 if (*endptr !=
'\0')
2872 if (
val > INT_MAX ||
val < INT_MIN)
2875 *hintmsg =
gettext_noop(
"Value exceeds integer range.");
2880 *result = (int)
val;
2909 if (endptr ==
value || errno == ERANGE)
2917 while (isspace((
unsigned char) *endptr))
2921 if (*endptr !=
'\0')
2961 for (entry = record->
options; entry && entry->
name; entry++)
2967 elog(
ERROR,
"could not find enum option %d for %s",
2985 for (entry = record->
options; entry && entry->
name; entry++)
2989 *retval = entry->
val;
3007 const char *suffix,
const char *
separator)
3017 for (entry = record->
options; entry && entry->
name; entry++)
3033 if (retstr.
len >= seplen)
3036 retstr.
data[retstr.
len - seplen] =
'\0';
3037 retstr.
len -= seplen;
3078 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3079 errmsg(
"parameter \"%s\" requires a Boolean value",
3092 const char *hintmsg;
3098 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3099 errmsg(
"invalid value for parameter \"%s\": \"%s\"",
3101 hintmsg ?
errhint(
"%s",
_(hintmsg)) : 0));
3110 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3111 errmsg(
"%d%s%s is outside the valid range for parameter \"%s\" (%d .. %d)",
3128 const char *hintmsg;
3134 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3135 errmsg(
"invalid value for parameter \"%s\": \"%s\"",
3137 hintmsg ?
errhint(
"%s",
_(hintmsg)) : 0));
3146 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3147 errmsg(
"%g%s%s is outside the valid range for parameter \"%s\" (%g .. %g)",
3170 if (
newval->stringval == NULL)
3179 strlen(
newval->stringval),
3186 newval->stringval = NULL;
3200 "Available values: ",
3204 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3205 errmsg(
"invalid value for parameter \"%s\": \"%s\"",
3207 hintmsg ?
errhint(
"%s",
_(hintmsg)) : 0));
3281 srole = BOOTSTRAP_SUPERUSERID;
3285 action, changeVal, elevel,
3312 void *newextra = NULL;
3313 bool prohibitValueChange =
false;
3346 (
errcode(ERRCODE_INVALID_TRANSACTION_STATE),
3347 errmsg(
"cannot set parameters during a parallel operation")));
3363 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3364 errmsg(
"parameter \"%s\" cannot be changed",
3381 prohibitValueChange =
true;
3386 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3387 errmsg(
"parameter \"%s\" cannot be changed without restarting the server",
3396 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3397 errmsg(
"parameter \"%s\" cannot be changed now",
3423 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3424 errmsg(
"permission denied to set parameter \"%s\"",
3461 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3462 errmsg(
"parameter \"%s\" cannot be set after connection start",
3481 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3482 errmsg(
"permission denied to set parameter \"%s\"",
3520 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3521 errmsg(
"cannot set parameter \"%s\" within security-definer function",
3528 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3529 errmsg(
"cannot set parameter \"%s\" within security-restricted operation",
3541 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3542 errmsg(
"parameter \"%s\" cannot be reset",
name)));
3548 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3549 errmsg(
"parameter \"%s\" cannot be set locally in functions",
3573 if (changeVal && !makeDefault)
3575 elog(
DEBUG3,
"\"%s\": setting ignored because previous source is higher priority",
3591 #define newval (newval_union.boolval)
3597 &newval_union, &newextra))
3616 if (prohibitValueChange)
3626 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3627 errmsg(
"parameter \"%s\" cannot be changed without restarting the server",
3663 for (stack = conf->
gen.
stack; stack; stack = stack->
prev)
3672 stack->
srole = srole;
3689 #define newval (newval_union.intval)
3695 &newval_union, &newextra))
3714 if (prohibitValueChange)
3724 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3725 errmsg(
"parameter \"%s\" cannot be changed without restarting the server",
3761 for (stack = conf->
gen.
stack; stack; stack = stack->
prev)
3770 stack->
srole = srole;
3787 #define newval (newval_union.realval)
3793 &newval_union, &newextra))
3812 if (prohibitValueChange)
3822 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3823 errmsg(
"parameter \"%s\" cannot be changed without restarting the server",
3859 for (stack = conf->
gen.
stack; stack; stack = stack->
prev)
3868 stack->
srole = srole;
3885 #define newval (newval_union.stringval)
3891 &newval_union, &newextra))
3926 if (prohibitValueChange)
3928 bool newval_different;
3931 newval_different = (*conf->
variable == NULL ||
3942 if (newval_different)
3946 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3947 errmsg(
"parameter \"%s\" cannot be changed without restarting the server",
3984 for (stack = conf->
gen.
stack; stack; stack = stack->
prev)
3994 stack->
srole = srole;
4014 #define newval (newval_union.enumval)
4020 &newval_union, &newextra))
4039 if (prohibitValueChange)
4049 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4050 errmsg(
"parameter \"%s\" cannot be changed without restarting the server",
4086 for (stack = conf->
gen.
stack; stack; stack = stack->
prev)
4095 stack->
srole = srole;
4116 return changeVal ? 1 : -1;
4184 static char buffer[256];
4189 if (restrict_privileged &&
4192 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4193 errmsg(
"must be superuser or have privileges of pg_read_all_settings to examine \"%s\"",
4199 return *((
struct config_bool *) record)->variable ?
"on" :
"off";
4202 snprintf(buffer,
sizeof(buffer),
"%d",
4207 snprintf(buffer,
sizeof(buffer),
"%g",
4232 static char buffer[256];
4238 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4239 errmsg(
"must be superuser or have privileges of pg_read_all_settings to examine \"%s\"",
4245 return ((
struct config_bool *) record)->reset_val ?
"on" :
"off";
4248 snprintf(buffer,
sizeof(buffer),
"%d",
4253 snprintf(buffer,
sizeof(buffer),
"%g",
4281 return record->
flags;
4314 for (item = head; item != NULL; item = item->
next)
4326 (
errcode(ERRCODE_OUT_OF_MEMORY),
4327 errmsg(
"out of memory")));
4371 for (item = *head_p; item != NULL; item =
next)
4398 item =
palloc(
sizeof *item);
4408 if (*head_p == NULL)
4411 (*tail_p)->
next = item;
4433 bool resetall =
false;
4462 elog(
ERROR,
"unrecognized alter system stmt type: %d",
4474 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4475 errmsg(
"permission denied to perform ALTER SYSTEM RESET ALL")));
4484 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4485 errmsg(
"permission denied to set parameter \"%s\"",
4508 (
errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4509 errmsg(
"parameter \"%s\" cannot be changed",
4518 void *newextra = NULL;
4525 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4526 errmsg(
"invalid value for parameter \"%s\": \"%s\"",
4538 if (strchr(
value,
'\n'))
4540 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4541 errmsg(
"parameter value for ALTER SYSTEM must not contain a newline")));
4549 snprintf(AutoConfFileName,
sizeof(AutoConfFileName),
"%s",
4551 snprintf(AutoConfTmpFileName,
sizeof(AutoConfTmpFileName),
"%s.%s",
4570 if (
stat(AutoConfFileName, &st) == 0)
4579 errmsg(
"could not open file \"%s\": %m",
4580 AutoConfFileName)));
4586 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
4587 errmsg(
"could not parse contents of file \"%s\"",
4588 AutoConfFileName)));
4625 O_CREAT | O_RDWR | O_TRUNC);
4629 errmsg(
"could not open file \"%s\": %m",
4630 AutoConfTmpFileName)));
4659 (void) unlink(AutoConfTmpFileName);
4695 elog(
FATAL,
"cannot create PGC_POSTMASTER variables after startup");
4704 elog(
FATAL,
"extensions cannot define GUC_LIST_QUOTE variables");
4713 (strcmp(
name,
"pljava.classpath") == 0 ||
4714 strcmp(
name,
"pljava.vmoptions") == 0))
4768 (
errcode(ERRCODE_INTERNAL_ERROR),
4769 errmsg(
"attempt to redefine parameter \"%s\"",
name)));
4848 const char *curvalue,
4863 switch (stack->
state)
4867 curscontext, cursource, cursrole,
4874 curscontext, cursource, cursrole,
4881 curscontext, cursource, cursrole,
4896 curscontext, cursource, cursrole,
4903 if (
variable->stack != oldvarstack)
4922 curscontext, cursource, cursrole,
4938 const char *short_desc,
4939 const char *long_desc,
4964 const char *short_desc,
4965 const char *long_desc,
4984 var->
min = minValue;
4985 var->
max = maxValue;
4994 const char *short_desc,
4995 const char *long_desc,
5014 var->
min = minValue;
5015 var->
max = maxValue;
5024 const char *short_desc,
5025 const char *long_desc,
5027 const char *bootValue,
5049 const char *short_desc,
5050 const char *long_desc,
5086 int classLen = strlen(className);
5103 strncmp(className, var->
name, classLen) == 0 &&
5107 (
errcode(ERRCODE_INVALID_NAME),
5108 errmsg(
"invalid configuration parameter name \"%s\", removing it",
5110 errdetail(
"\"%s\" is now a reserved prefix.",
5217 result[*num] = conf;
5244 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5245 errmsg(
"must be superuser or have privileges of pg_read_all_settings to examine \"%s\"",
5249 *varname = record->
name;
5327 snprintf(buffer,
sizeof(buffer),
"%g%s",
5383 write_one_nondefault_variable(FILE *fp,
struct config_generic *gconf)