PostgreSQL Source Code  git master
guc.h File Reference
#include "nodes/parsenodes.h"
#include "tcop/dest.h"
#include "utils/array.h"
Include dependency graph for guc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ConfigVariable
 
struct  config_enum_entry
 

Macros

#define MAX_KILOBYTES   (INT_MAX / 1024)
 
#define PG_AUTOCONF_FILENAME   "postgresql.auto.conf"
 
#define GUC_QUALIFIER_SEPARATOR   '.'
 
#define GUC_LIST_INPUT   0x0001 /* input can be list format */
 
#define GUC_LIST_QUOTE   0x0002 /* double-quote list elements */
 
#define GUC_NO_SHOW_ALL   0x0004 /* exclude from SHOW ALL */
 
#define GUC_NO_RESET_ALL   0x0008 /* exclude from RESET ALL */
 
#define GUC_REPORT   0x0010 /* auto-report changes to client */
 
#define GUC_NOT_IN_SAMPLE   0x0020 /* not in postgresql.conf.sample */
 
#define GUC_DISALLOW_IN_FILE   0x0040 /* can't set in postgresql.conf */
 
#define GUC_CUSTOM_PLACEHOLDER   0x0080 /* placeholder for custom variable */
 
#define GUC_SUPERUSER_ONLY   0x0100 /* show only to superusers */
 
#define GUC_IS_NAME   0x0200 /* limit string to NAMEDATALEN-1 */
 
#define GUC_NOT_WHILE_SEC_REST   0x0400 /* can't set if security restricted */
 
#define GUC_DISALLOW_IN_AUTO_FILE
 
#define GUC_UNIT_KB   0x1000 /* value is in kilobytes */
 
#define GUC_UNIT_BLOCKS   0x2000 /* value is in blocks */
 
#define GUC_UNIT_XBLOCKS   0x3000 /* value is in xlog blocks */
 
#define GUC_UNIT_MB   0x4000 /* value is in megabytes */
 
#define GUC_UNIT_BYTE   0x8000 /* value is in bytes */
 
#define GUC_UNIT_MEMORY   0xF000 /* mask for size-related units */
 
#define GUC_UNIT_MS   0x10000 /* value is in milliseconds */
 
#define GUC_UNIT_S   0x20000 /* value is in seconds */
 
#define GUC_UNIT_MIN   0x30000 /* value is in minutes */
 
#define GUC_UNIT_TIME   0xF0000 /* mask for time-related units */
 
#define GUC_UNIT   (GUC_UNIT_MEMORY | GUC_UNIT_TIME)
 
#define GUC_check_errmsg
 
#define GUC_check_errdetail
 
#define GUC_check_errhint
 

Typedefs

typedef struct ConfigVariable ConfigVariable
 
typedef bool(* GucBoolCheckHook) (bool *newval, void **extra, GucSource source)
 
typedef bool(* GucIntCheckHook) (int *newval, void **extra, GucSource source)
 
typedef bool(* GucRealCheckHook) (double *newval, void **extra, GucSource source)
 
typedef bool(* GucStringCheckHook) (char **newval, void **extra, GucSource source)
 
typedef bool(* GucEnumCheckHook) (int *newval, void **extra, GucSource source)
 
typedef void(* GucBoolAssignHook) (bool newval, void *extra)
 
typedef void(* GucIntAssignHook) (int newval, void *extra)
 
typedef void(* GucRealAssignHook) (double newval, void *extra)
 
typedef void(* GucStringAssignHook) (const char *newval, void *extra)
 
typedef void(* GucEnumAssignHook) (int newval, void *extra)
 
typedef const char *(* GucShowHook) (void)
 

Enumerations

enum  GucContext {
  PGC_INTERNAL, PGC_POSTMASTER, PGC_SIGHUP, PGC_SU_BACKEND,
  PGC_BACKEND, PGC_SUSET, PGC_USERSET
}
 
enum  GucSource {
  PGC_S_DEFAULT, PGC_S_DYNAMIC_DEFAULT, PGC_S_ENV_VAR, PGC_S_FILE,
  PGC_S_ARGV, PGC_S_GLOBAL, PGC_S_DATABASE, PGC_S_USER,
  PGC_S_DATABASE_USER, PGC_S_CLIENT, PGC_S_OVERRIDE, PGC_S_INTERACTIVE,
  PGC_S_TEST, PGC_S_SESSION
}
 
enum  GucAction { GUC_ACTION_SET, GUC_ACTION_LOCAL, GUC_ACTION_SAVE }
 

Functions

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)
 
bool ParseConfigFp (FILE *fp, const char *config_file, int depth, int elevel, ConfigVariable **head_p, ConfigVariable **tail_p)
 
bool ParseConfigDirectory (const char *includedir, const char *calling_file, int calling_lineno, int depth, int elevel, ConfigVariable **head_p, ConfigVariable **tail_p)
 
void FreeConfigVariables (ConfigVariable *list)
 
void SetConfigOption (const char *name, const char *value, GucContext context, GucSource source)
 
void DefineCustomBoolVariable (const char *name, const char *short_desc, const char *long_desc, bool *valueAddr, bool bootValue, GucContext context, int flags, GucBoolCheckHook check_hook, GucBoolAssignHook assign_hook, GucShowHook show_hook)
 
void DefineCustomIntVariable (const char *name, const char *short_desc, const char *long_desc, int *valueAddr, int bootValue, int minValue, int maxValue, GucContext context, int flags, GucIntCheckHook check_hook, GucIntAssignHook assign_hook, GucShowHook show_hook)
 
void DefineCustomRealVariable (const char *name, const char *short_desc, const char *long_desc, double *valueAddr, double bootValue, double minValue, double maxValue, GucContext context, int flags, GucRealCheckHook check_hook, GucRealAssignHook assign_hook, GucShowHook show_hook)
 
void DefineCustomStringVariable (const char *name, const char *short_desc, const char *long_desc, char **valueAddr, const char *bootValue, GucContext context, int flags, GucStringCheckHook check_hook, GucStringAssignHook assign_hook, GucShowHook show_hook)
 
void DefineCustomEnumVariable (const char *name, const char *short_desc, const char *long_desc, int *valueAddr, int bootValue, const struct config_enum_entry *options, GucContext context, int flags, GucEnumCheckHook check_hook, GucEnumAssignHook assign_hook, GucShowHook show_hook)
 
void EmitWarningsOnPlaceholders (const char *className)
 
const char * GetConfigOption (const char *name, bool missing_ok, bool restrict_privileged)
 
const char * GetConfigOptionResetString (const char *name)
 
int GetConfigOptionFlags (const char *name, bool missing_ok)
 
void ProcessConfigFile (GucContext context)
 
void InitializeGUCOptions (void)
 
bool SelectConfigFiles (const char *userDoption, const char *progname)
 
void ResetAllOptions (void)
 
void AtStart_GUC (void)
 
int NewGUCNestLevel (void)
 
void AtEOXact_GUC (bool isCommit, int nestLevel)
 
void BeginReportingGUCOptions (void)
 
void ParseLongOption (const char *string, char **name, char **value)
 
bool parse_int (const char *value, int *result, int flags, const char **hintmsg)
 
bool parse_real (const char *value, double *result)
 
int set_config_option (const char *name, const char *value, GucContext context, GucSource source, GucAction action, bool changeVal, int elevel, bool is_reload)
 
void AlterSystemSetConfigFile (AlterSystemStmt *setstmt)
 
char * GetConfigOptionByName (const char *name, const char **varname, bool missing_ok)
 
void GetConfigOptionByNum (int varnum, const char **values, bool *noshow)
 
int GetNumConfigOptions (void)
 
void SetPGVariable (const char *name, List *args, bool is_local)
 
void GetPGVariable (const char *name, DestReceiver *dest)
 
TupleDesc GetPGVariableResultDesc (const char *name)
 
void ExecSetVariableStmt (VariableSetStmt *stmt, bool isTopLevel)
 
char * ExtractSetVariableArgs (VariableSetStmt *stmt)
 
void ProcessGUCArray (ArrayType *array, GucContext context, GucSource source, GucAction action)
 
ArrayTypeGUCArrayAdd (ArrayType *array, const char *name, const char *value)
 
ArrayTypeGUCArrayDelete (ArrayType *array, const char *name)
 
ArrayTypeGUCArrayReset (ArrayType *array)
 
Size EstimateGUCStateSpace (void)
 
void SerializeGUCState (Size maxsize, char *start_address)
 
void RestoreGUCState (void *gucstate)
 
void GUC_check_errcode (int sqlerrcode)
 
bool check_default_tablespace (char **newval, void **extra, GucSource source)
 
bool check_temp_tablespaces (char **newval, void **extra, GucSource source)
 
void assign_temp_tablespaces (const char *newval, void *extra)
 
bool check_search_path (char **newval, void **extra, GucSource source)
 
void assign_search_path (const char *newval, void *extra)
 
bool check_wal_buffers (int *newval, void **extra, GucSource source)
 
void assign_xlog_sync_method (int new_sync_method, void *extra)
 

Variables

bool log_duration
 
bool Debug_print_plan
 
bool Debug_print_parse
 
bool Debug_print_rewritten
 
bool Debug_pretty_print
 
bool log_parser_stats
 
bool log_planner_stats
 
bool log_executor_stats
 
bool log_statement_stats
 
bool log_btree_build_stats
 
PGDLLIMPORT bool check_function_bodies
 
bool default_with_oids
 
bool session_auth_is_superuser
 
int log_min_error_statement
 
PGDLLIMPORT int log_min_messages
 
PGDLLIMPORT int client_min_messages
 
int log_min_duration_statement
 
int log_temp_files
 
int temp_file_limit
 
int num_temp_buffers
 
char * cluster_name
 
PGDLLIMPORT char * ConfigFileName
 
char * HbaFileName
 
char * IdentFileName
 
char * external_pid_file
 
PGDLLIMPORT char * application_name
 
int tcp_keepalives_idle
 
int tcp_keepalives_interval
 
int tcp_keepalives_count
 
PGDLLIMPORT char * GUC_check_errmsg_string
 
PGDLLIMPORT char * GUC_check_errdetail_string
 
PGDLLIMPORT char * GUC_check_errhint_string
 

Macro Definition Documentation

◆ GUC_check_errdetail

◆ GUC_check_errhint

#define GUC_check_errhint
Value:
GUC_check_errhint_string = format_elog_string
#define TEXTDOMAIN
Definition: elog.h:125
char * format_elog_string(const char *fmt,...)
Definition: elog.c:1413
void pre_format_elog_string(int errnumber, const char *domain)
Definition: elog.c:1404

Definition at line 414 of file guc.h.

Referenced by check_max_stack_depth(), check_XactIsoLevel(), and ParseTzFile().

◆ GUC_check_errmsg

#define GUC_check_errmsg
Value:
GUC_check_errmsg_string = format_elog_string
#define TEXTDOMAIN
Definition: elog.h:125
char * format_elog_string(const char *fmt,...)
Definition: elog.c:1413
void pre_format_elog_string(int errnumber, const char *domain)
Definition: elog.c:1404

Definition at line 406 of file guc.h.

Referenced by addToArray(), check_bonjour(), check_log_timezone(), check_role(), check_session_authorization(), check_ssl(), check_synchronous_standby_names(), check_timezone(), check_transaction_deferrable(), check_transaction_read_only(), check_XactIsoLevel(), load_tzoffsets(), ParseTzFile(), splitTzLine(), and validateTzEntry().

◆ GUC_CUSTOM_PLACEHOLDER

#define GUC_CUSTOM_PLACEHOLDER   0x0080 /* placeholder for custom variable */

◆ GUC_DISALLOW_IN_AUTO_FILE

#define GUC_DISALLOW_IN_AUTO_FILE
Value:
0x0800 /* can't set in
* PG_AUTOCONF_FILENAME */

Definition at line 215 of file guc.h.

Referenced by AlterSystemSetConfigFile().

◆ GUC_DISALLOW_IN_FILE

#define GUC_DISALLOW_IN_FILE   0x0040 /* can't set in postgresql.conf */

Definition at line 210 of file guc.h.

Referenced by AlterSystemSetConfigFile(), and displayStruct().

◆ GUC_IS_NAME

#define GUC_IS_NAME   0x0200 /* limit string to NAMEDATALEN-1 */

Definition at line 213 of file guc.h.

Referenced by parse_and_validate_value().

◆ GUC_LIST_INPUT

#define GUC_LIST_INPUT   0x0001 /* input can be list format */

Definition at line 204 of file guc.h.

Referenced by _PG_init(), and flatten_set_variable_args().

◆ GUC_LIST_QUOTE

#define GUC_LIST_QUOTE   0x0002 /* double-quote list elements */

Definition at line 205 of file guc.h.

Referenced by flatten_set_variable_args(), init_custom_variable(), and pg_get_functiondef().

◆ GUC_NO_RESET_ALL

#define GUC_NO_RESET_ALL   0x0008 /* exclude from RESET ALL */

Definition at line 207 of file guc.h.

Referenced by ResetAllOptions().

◆ GUC_NO_SHOW_ALL

#define GUC_NO_SHOW_ALL   0x0004 /* exclude from SHOW ALL */

◆ GUC_NOT_IN_SAMPLE

#define GUC_NOT_IN_SAMPLE   0x0020 /* not in postgresql.conf.sample */

Definition at line 209 of file guc.h.

Referenced by _PG_init(), add_placeholder_variable(), and displayStruct().

◆ GUC_NOT_WHILE_SEC_REST

#define GUC_NOT_WHILE_SEC_REST   0x0400 /* can't set if security restricted */

Definition at line 214 of file guc.h.

Referenced by set_config_option().

◆ GUC_QUALIFIER_SEPARATOR

#define GUC_QUALIFIER_SEPARATOR   '.'

Definition at line 199 of file guc.h.

Referenced by EmitWarningsOnPlaceholders(), and find_option().

◆ GUC_REPORT

#define GUC_REPORT   0x0010 /* auto-report changes to client */

◆ GUC_SUPERUSER_ONLY

#define GUC_SUPERUSER_ONLY   0x0100 /* show only to superusers */

◆ GUC_UNIT

#define GUC_UNIT   (GUC_UNIT_MEMORY | GUC_UNIT_TIME)

Definition at line 230 of file guc.h.

Referenced by _ShowOption(), and parse_int().

◆ GUC_UNIT_BLOCKS

#define GUC_UNIT_BLOCKS   0x2000 /* value is in blocks */

Definition at line 219 of file guc.h.

Referenced by GetConfigOptionByNum().

◆ GUC_UNIT_BYTE

#define GUC_UNIT_BYTE   0x8000 /* value is in bytes */

Definition at line 222 of file guc.h.

Referenced by GetConfigOptionByNum().

◆ GUC_UNIT_KB

#define GUC_UNIT_KB   0x1000 /* value is in kilobytes */

Definition at line 218 of file guc.h.

Referenced by GetConfigOptionByNum().

◆ GUC_UNIT_MB

#define GUC_UNIT_MB   0x4000 /* value is in megabytes */

Definition at line 221 of file guc.h.

Referenced by GetConfigOptionByNum().

◆ GUC_UNIT_MEMORY

#define GUC_UNIT_MEMORY   0xF000 /* mask for size-related units */

◆ GUC_UNIT_MIN

#define GUC_UNIT_MIN   0x30000 /* value is in minutes */

Definition at line 227 of file guc.h.

Referenced by GetConfigOptionByNum().

◆ GUC_UNIT_MS

#define GUC_UNIT_MS   0x10000 /* value is in milliseconds */

Definition at line 225 of file guc.h.

Referenced by _PG_init(), GetConfigOptionByNum(), and readRecoveryCommandFile().

◆ GUC_UNIT_S

#define GUC_UNIT_S   0x20000 /* value is in seconds */

Definition at line 226 of file guc.h.

Referenced by _PG_init(), and GetConfigOptionByNum().

◆ GUC_UNIT_TIME

#define GUC_UNIT_TIME   0xF0000 /* mask for time-related units */

Definition at line 228 of file guc.h.

Referenced by GetConfigOptionByNum().

◆ GUC_UNIT_XBLOCKS

#define GUC_UNIT_XBLOCKS   0x3000 /* value is in xlog blocks */

Definition at line 220 of file guc.h.

Referenced by GetConfigOptionByNum().

◆ MAX_KILOBYTES

#define MAX_KILOBYTES   (INT_MAX / 1024)

Definition at line 26 of file guc.h.

◆ PG_AUTOCONF_FILENAME

#define PG_AUTOCONF_FILENAME   "postgresql.auto.conf"

Definition at line 34 of file guc.h.

Referenced by AlterSystemSetConfigFile().

Typedef Documentation

◆ ConfigVariable

◆ GucBoolAssignHook

typedef void(* GucBoolAssignHook) (bool newval, void *extra)

Definition at line 180 of file guc.h.

◆ GucBoolCheckHook

typedef bool(* GucBoolCheckHook) (bool *newval, void **extra, GucSource source)

Definition at line 174 of file guc.h.

◆ GucEnumAssignHook

typedef void(* GucEnumAssignHook) (int newval, void *extra)

Definition at line 184 of file guc.h.

◆ GucEnumCheckHook

typedef bool(* GucEnumCheckHook) (int *newval, void **extra, GucSource source)

Definition at line 178 of file guc.h.

◆ GucIntAssignHook

typedef void(* GucIntAssignHook) (int newval, void *extra)

Definition at line 181 of file guc.h.

◆ GucIntCheckHook

typedef bool(* GucIntCheckHook) (int *newval, void **extra, GucSource source)

Definition at line 175 of file guc.h.

◆ GucRealAssignHook

typedef void(* GucRealAssignHook) (double newval, void *extra)

Definition at line 182 of file guc.h.

◆ GucRealCheckHook

typedef bool(* GucRealCheckHook) (double *newval, void **extra, GucSource source)

Definition at line 176 of file guc.h.

◆ GucShowHook

typedef const char*(* GucShowHook) (void)

Definition at line 186 of file guc.h.

◆ GucStringAssignHook

typedef void(* GucStringAssignHook) (const char *newval, void *extra)

Definition at line 183 of file guc.h.

◆ GucStringCheckHook

typedef bool(* GucStringCheckHook) (char **newval, void **extra, GucSource source)

Definition at line 177 of file guc.h.

Enumeration Type Documentation

◆ GucAction

enum GucAction
Enumerator
GUC_ACTION_SET 
GUC_ACTION_LOCAL 
GUC_ACTION_SAVE 

Definition at line 191 of file guc.h.

192 {
193  /* Types of set_config_option actions */
194  GUC_ACTION_SET, /* regular SET command */
195  GUC_ACTION_LOCAL, /* SET LOCAL command */
196  GUC_ACTION_SAVE /* function SET option, or temp assignment */
197 } GucAction;
GucAction
Definition: guc.h:191

◆ GucContext

enum GucContext
Enumerator
PGC_INTERNAL 
PGC_POSTMASTER 
PGC_SIGHUP 
PGC_SU_BACKEND 
PGC_BACKEND 
PGC_SUSET 
PGC_USERSET 

Definition at line 68 of file guc.h.

69 {
72  PGC_SIGHUP,
75  PGC_SUSET,
77 } GucContext;
GucContext
Definition: guc.h:68
Definition: guc.h:75
Definition: guc.h:72

◆ GucSource

enum GucSource
Enumerator
PGC_S_DEFAULT 
PGC_S_DYNAMIC_DEFAULT 
PGC_S_ENV_VAR 
PGC_S_FILE 
PGC_S_ARGV 
PGC_S_GLOBAL 
PGC_S_DATABASE 
PGC_S_USER 
PGC_S_DATABASE_USER 
PGC_S_CLIENT 
PGC_S_OVERRIDE 
PGC_S_INTERACTIVE 
PGC_S_TEST 
PGC_S_SESSION 

Definition at line 105 of file guc.h.

106 {
107  PGC_S_DEFAULT, /* hard-wired default ("boot_val") */
108  PGC_S_DYNAMIC_DEFAULT, /* default computed during initialization */
109  PGC_S_ENV_VAR, /* postmaster environment variable */
110  PGC_S_FILE, /* postgresql.conf */
111  PGC_S_ARGV, /* postmaster command line */
112  PGC_S_GLOBAL, /* global in-database setting */
113  PGC_S_DATABASE, /* per-database setting */
114  PGC_S_USER, /* per-user setting */
115  PGC_S_DATABASE_USER, /* per-user-and-database setting */
116  PGC_S_CLIENT, /* from client connection request */
117  PGC_S_OVERRIDE, /* special case to forcibly set default */
118  PGC_S_INTERACTIVE, /* dividing line for error reporting */
119  PGC_S_TEST, /* test per-database or per-user setting */
120  PGC_S_SESSION /* SET command */
121 } GucSource;
GucSource
Definition: guc.h:105

Function Documentation

◆ AlterSystemSetConfigFile()

void AlterSystemSetConfigFile ( AlterSystemStmt setstmt)

Definition at line 7339 of file guc.c.

References AllocateFile(), BasicOpenFile(), close, config_generic::context, durable_rename(), elog, ereport, errcode(), errcode_for_file_access(), errmsg(), ERROR, ExtractSetVariableArgs(), find_option(), config_generic::flags, free, FreeConfigVariables(), FreeFile(), GUC_DISALLOW_IN_AUTO_FILE, GUC_DISALLOW_IN_FILE, infile(), VariableSetStmt::kind, LOG, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MAXPGPATH, name, VariableSetStmt::name, parse_and_validate_value(), ParseConfigFp(), PG_AUTOCONF_FILENAME, PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, PGC_INTERNAL, PGC_S_FILE, PGC_STRING, replace_auto_config_value(), AlterSystemStmt::setstmt, snprintf(), stat, config_var_val::stringval, superuser(), value, VAR_RESET, VAR_RESET_ALL, VAR_SET_DEFAULT, VAR_SET_VALUE, config_generic::vartype, and write_auto_conf_file().

Referenced by standard_ProcessUtility().

7340 {
7341  char *name;
7342  char *value;
7343  bool resetall = false;
7344  ConfigVariable *head = NULL;
7345  ConfigVariable *tail = NULL;
7346  volatile int Tmpfd;
7347  char AutoConfFileName[MAXPGPATH];
7348  char AutoConfTmpFileName[MAXPGPATH];
7349 
7350  if (!superuser())
7351  ereport(ERROR,
7352  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7353  (errmsg("must be superuser to execute ALTER SYSTEM command"))));
7354 
7355  /*
7356  * Extract statement arguments
7357  */
7358  name = altersysstmt->setstmt->name;
7359 
7360  switch (altersysstmt->setstmt->kind)
7361  {
7362  case VAR_SET_VALUE:
7363  value = ExtractSetVariableArgs(altersysstmt->setstmt);
7364  break;
7365 
7366  case VAR_SET_DEFAULT:
7367  case VAR_RESET:
7368  value = NULL;
7369  break;
7370 
7371  case VAR_RESET_ALL:
7372  value = NULL;
7373  resetall = true;
7374  break;
7375 
7376  default:
7377  elog(ERROR, "unrecognized alter system stmt type: %d",
7378  altersysstmt->setstmt->kind);
7379  break;
7380  }
7381 
7382  /*
7383  * Unless it's RESET_ALL, validate the target variable and value
7384  */
7385  if (!resetall)
7386  {
7387  struct config_generic *record;
7388 
7389  record = find_option(name, false, ERROR);
7390  if (record == NULL)
7391  ereport(ERROR,
7392  (errcode(ERRCODE_UNDEFINED_OBJECT),
7393  errmsg("unrecognized configuration parameter \"%s\"",
7394  name)));
7395 
7396  /*
7397  * Don't allow parameters that can't be set in configuration files to
7398  * be set in PG_AUTOCONF_FILENAME file.
7399  */
7400  if ((record->context == PGC_INTERNAL) ||
7401  (record->flags & GUC_DISALLOW_IN_FILE) ||
7402  (record->flags & GUC_DISALLOW_IN_AUTO_FILE))
7403  ereport(ERROR,
7404  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
7405  errmsg("parameter \"%s\" cannot be changed",
7406  name)));
7407 
7408  /*
7409  * If a value is specified, verify that it's sane.
7410  */
7411  if (value)
7412  {
7413  union config_var_val newval;
7414  void *newextra = NULL;
7415 
7416  /* Check that it's acceptable for the indicated parameter */
7417  if (!parse_and_validate_value(record, name, value,
7418  PGC_S_FILE, ERROR,
7419  &newval, &newextra))
7420  ereport(ERROR,
7421  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7422  errmsg("invalid value for parameter \"%s\": \"%s\"",
7423  name, value)));
7424 
7425  if (record->vartype == PGC_STRING && newval.stringval != NULL)
7426  free(newval.stringval);
7427  if (newextra)
7428  free(newextra);
7429 
7430  /*
7431  * We must also reject values containing newlines, because the
7432  * grammar for config files doesn't support embedded newlines in
7433  * string literals.
7434  */
7435  if (strchr(value, '\n'))
7436  ereport(ERROR,
7437  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7438  errmsg("parameter value for ALTER SYSTEM must not contain a newline")));
7439  }
7440  }
7441 
7442  /*
7443  * PG_AUTOCONF_FILENAME and its corresponding temporary file are always in
7444  * the data directory, so we can reference them by simple relative paths.
7445  */
7446  snprintf(AutoConfFileName, sizeof(AutoConfFileName), "%s",
7448  snprintf(AutoConfTmpFileName, sizeof(AutoConfTmpFileName), "%s.%s",
7449  AutoConfFileName,
7450  "tmp");
7451 
7452  /*
7453  * Only one backend is allowed to operate on PG_AUTOCONF_FILENAME at a
7454  * time. Use AutoFileLock to ensure that. We must hold the lock while
7455  * reading the old file contents.
7456  */
7457  LWLockAcquire(AutoFileLock, LW_EXCLUSIVE);
7458 
7459  /*
7460  * If we're going to reset everything, then no need to open or parse the
7461  * old file. We'll just write out an empty list.
7462  */
7463  if (!resetall)
7464  {
7465  struct stat st;
7466 
7467  if (stat(AutoConfFileName, &st) == 0)
7468  {
7469  /* open old file PG_AUTOCONF_FILENAME */
7470  FILE *infile;
7471 
7472  infile = AllocateFile(AutoConfFileName, "r");
7473  if (infile == NULL)
7474  ereport(ERROR,
7476  errmsg("could not open file \"%s\": %m",
7477  AutoConfFileName)));
7478 
7479  /* parse it */
7480  if (!ParseConfigFp(infile, AutoConfFileName, 0, LOG, &head, &tail))
7481  ereport(ERROR,
7482  (errcode(ERRCODE_CONFIG_FILE_ERROR),
7483  errmsg("could not parse contents of file \"%s\"",
7484  AutoConfFileName)));
7485 
7486  FreeFile(infile);
7487  }
7488 
7489  /*
7490  * Now, replace any existing entry with the new value, or add it if
7491  * not present.
7492  */
7493  replace_auto_config_value(&head, &tail, name, value);
7494  }
7495 
7496  /*
7497  * To ensure crash safety, first write the new file data to a temp file,
7498  * then atomically rename it into place.
7499  *
7500  * If there is a temp file left over due to a previous crash, it's okay to
7501  * truncate and reuse it.
7502  */
7503  Tmpfd = BasicOpenFile(AutoConfTmpFileName,
7504  O_CREAT | O_RDWR | O_TRUNC);
7505  if (Tmpfd < 0)
7506  ereport(ERROR,
7508  errmsg("could not open file \"%s\": %m",
7509  AutoConfTmpFileName)));
7510 
7511  /*
7512  * Use a TRY block to clean up the file if we fail. Since we need a TRY
7513  * block anyway, OK to use BasicOpenFile rather than OpenTransientFile.
7514  */
7515  PG_TRY();
7516  {
7517  /* Write and sync the new contents to the temporary file */
7518  write_auto_conf_file(Tmpfd, AutoConfTmpFileName, head);
7519 
7520  /* Close before renaming; may be required on some platforms */
7521  close(Tmpfd);
7522  Tmpfd = -1;
7523 
7524  /*
7525  * As the rename is atomic operation, if any problem occurs after this
7526  * at worst it can lose the parameters set by last ALTER SYSTEM
7527  * command.
7528  */
7529  durable_rename(AutoConfTmpFileName, AutoConfFileName, ERROR);
7530  }
7531  PG_CATCH();
7532  {
7533  /* Close file first, else unlink might fail on some platforms */
7534  if (Tmpfd >= 0)
7535  close(Tmpfd);
7536 
7537  /* Unlink, but ignore any error */
7538  (void) unlink(AutoConfTmpFileName);
7539 
7540  PG_RE_THROW();
7541  }
7542  PG_END_TRY();
7543 
7544  FreeConfigVariables(head);
7545 
7546  LWLockRelease(AutoFileLock);
7547 }
static bool parse_and_validate_value(struct config_generic *record, const char *name, const char *value, GucSource source, int elevel, union config_var_val *newval, void **newextra)
Definition: guc.c:5968
int errcode(int sqlerrcode)
Definition: elog.c:575
bool superuser(void)
Definition: superuser.c:47
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define LOG
Definition: elog.h:26
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1725
#define ERROR
Definition: elog.h:43
#define MAXPGPATH
int errcode_for_file_access(void)
Definition: elog.c:598
FILE * AllocateFile(const char *name, const char *mode)
Definition: fd.c:2336
#define ereport(elevel, rest)
Definition: elog.h:122
int durable_rename(const char *oldfile, const char *newfile, int elevel)
Definition: fd.c:601
enum config_type vartype
Definition: guc_tables.h:154
#define stat(a, b)
Definition: win32_port.h:266
#define GUC_DISALLOW_IN_FILE
Definition: guc.h:210
static struct @131 value
static void write_auto_conf_file(int fd, const char *filename, ConfigVariable *head_p)
Definition: guc.c:7198
static void infile(const char *filename)
Definition: zic.c:1182
#define free(a)
Definition: header.h:65
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4615
#define PG_CATCH()
Definition: elog.h:293
#define newval
#define PG_AUTOCONF_FILENAME
Definition: guc.h:34
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1121
#define PG_RE_THROW()
Definition: elog.h:314
const char * name
Definition: encode.c:521
#define GUC_DISALLOW_IN_AUTO_FILE
Definition: guc.h:215
int BasicOpenFile(const char *fileName, int fileFlags)
Definition: fd.c:932
int FreeFile(FILE *file)
Definition: fd.c:2528
int errmsg(const char *fmt,...)
Definition: elog.c:797
bool ParseConfigFp(FILE *fp, const char *config_file, int depth, int elevel, ConfigVariable **head_p, ConfigVariable **tail_p)
static void replace_auto_config_value(ConfigVariable **head_p, ConfigVariable **tail_p, const char *name, const char *value)
Definition: guc.c:7266
void FreeConfigVariables(ConfigVariable *list)
#define elog
Definition: elog.h:219
#define close(a)
Definition: win32.h:12
#define PG_TRY()
Definition: elog.h:284
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
Definition: guc.c:7677
#define PG_END_TRY()
Definition: elog.h:300
GucContext context
Definition: guc_tables.h:148

◆ assign_search_path()

void assign_search_path ( const char *  newval,
void *  extra 
)

Definition at line 4113 of file namespace.c.

References baseSearchPathValid.

4114 {
4115  /*
4116  * We mark the path as needing recomputation, but don't do anything until
4117  * it's needed. This avoids trying to do database access during GUC
4118  * initialization, or outside a transaction.
4119  */
4120  baseSearchPathValid = false;
4121 }
static bool baseSearchPathValid
Definition: namespace.c:152

◆ assign_temp_tablespaces()

void assign_temp_tablespaces ( const char *  newval,
void *  extra 
)

Definition at line 1264 of file tablespace.c.

References temp_tablespaces_extra::numSpcs, SetTempTablespaces(), and temp_tablespaces_extra::tblSpcs.

1265 {
1266  temp_tablespaces_extra *myextra = (temp_tablespaces_extra *) extra;
1267 
1268  /*
1269  * If check_temp_tablespaces was executed inside a transaction, then pass
1270  * the list it made to fd.c. Otherwise, clear fd.c's list; we must be
1271  * still outside a transaction, or else restoring during transaction exit,
1272  * and in either case we can just let the next PrepareTempTablespaces call
1273  * make things sane.
1274  */
1275  if (myextra)
1276  SetTempTablespaces(myextra->tblSpcs, myextra->numSpcs);
1277  else
1278  SetTempTablespaces(NULL, 0);
1279 }
Oid tblSpcs[FLEXIBLE_ARRAY_MEMBER]
Definition: tablespace.c:1154
void SetTempTablespaces(Oid *tableSpaces, int numSpaces)
Definition: fd.c:2793

◆ assign_xlog_sync_method()

void assign_xlog_sync_method ( int  new_sync_method,
void *  extra 
)

Definition at line 10121 of file xlog.c.

References ereport, errcode_for_file_access(), errmsg(), get_sync_bit(), openLogFile, openLogSegNo, PANIC, pg_fsync(), pgstat_report_wait_end(), pgstat_report_wait_start(), sync_method, ThisTimeLineID, WAIT_EVENT_WAL_SYNC_METHOD_ASSIGN, XLogFileClose(), and XLogFileNameP().

10122 {
10123  if (sync_method != new_sync_method)
10124  {
10125  /*
10126  * To ensure that no blocks escape unsynced, force an fsync on the
10127  * currently open log segment (if any). Also, if the open flag is
10128  * changing, close the log file so it will be reopened (with new flag
10129  * bit) at next use.
10130  */
10131  if (openLogFile >= 0)
10132  {
10134  if (pg_fsync(openLogFile) != 0)
10135  ereport(PANIC,
10137  errmsg("could not fsync log segment %s: %m",
10140  if (get_sync_bit(sync_method) != get_sync_bit(new_sync_method))
10141  XLogFileClose();
10142  }
10143  }
10144 }
static int get_sync_bit(int method)
Definition: xlog.c:10065
#define PANIC
Definition: elog.h:53
static XLogSegNo openLogSegNo
Definition: xlog.c:775
static void XLogFileClose(void)
Definition: xlog.c:3727
char * XLogFileNameP(TimeLineID tli, XLogSegNo segno)
Definition: xlog.c:10197
int errcode_for_file_access(void)
Definition: elog.c:598
static void pgstat_report_wait_end(void)
Definition: pgstat.h:1260
#define ereport(elevel, rest)
Definition: elog.h:122
static int openLogFile
Definition: xlog.c:774
TimeLineID ThisTimeLineID
Definition: xlog.c:181
static void pgstat_report_wait_start(uint32 wait_event_info)
Definition: pgstat.h:1236
int sync_method
Definition: xlog.c:103
int errmsg(const char *fmt,...)
Definition: elog.c:797
int pg_fsync(int fd)
Definition: fd.c:341

◆ AtEOXact_GUC()

void AtEOXact_GUC ( bool  isCommit,
int  nestLevel 
)

Definition at line 5322 of file guc.c.

References Assert, config_bool::assign_hook, config_int::assign_hook, config_real::assign_hook, config_string::assign_hook, config_enum::assign_hook, config_var_val::boolval, discard_stack_value(), config_var_val::enumval, config_var_value::extra, config_generic::extra, config_generic::flags, config_bool::gen, config_int::gen, config_real::gen, config_string::gen, config_enum::gen, GUC_LOCAL, GUC_REPORT, GUC_SAVE, GUC_SET, GUC_SET_LOCAL, i, config_var_val::intval, guc_stack::masked, guc_stack::masked_scontext, guc_stack::nest_level, newval, num_guc_variables, pfree(), PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_S_SESSION, PGC_STRING, guc_stack::prev, guc_stack::prior, config_var_val::realval, ReportGUCOption(), guc_stack::scontext, config_generic::scontext, set_extra_field(), set_string_field(), guc_stack::source, config_generic::source, config_generic::stack, guc_stack::state, config_var_val::stringval, config_var_value::val, config_bool::variable, config_int::variable, config_real::variable, config_string::variable, config_enum::variable, and config_generic::vartype.

Referenced by AbortSubTransaction(), AbortTransaction(), CommitSubTransaction(), CommitTransaction(), do_analyze_rel(), ExecCreateTableAs(), ExecRefreshMatView(), execute_extension_script(), fmgr_security_definer(), index_build(), PrepareTransaction(), ProcedureCreate(), reset_transmission_modes(), restoreLocalGucs(), RI_Initial_Check(), vacuum_rel(), and validate_index().

5323 {
5324  bool still_dirty;
5325  int i;
5326 
5327  /*
5328  * Note: it's possible to get here with GUCNestLevel == nestLevel-1 during
5329  * abort, if there is a failure during transaction start before
5330  * AtStart_GUC is called.
5331  */
5332  Assert(nestLevel > 0 &&
5333  (nestLevel <= GUCNestLevel ||
5334  (nestLevel == GUCNestLevel + 1 && !isCommit)));
5335 
5336  /* Quick exit if nothing's changed in this transaction */
5337  if (!guc_dirty)
5338  {
5339  GUCNestLevel = nestLevel - 1;
5340  return;
5341  }
5342 
5343  still_dirty = false;
5344  for (i = 0; i < num_guc_variables; i++)
5345  {
5346  struct config_generic *gconf = guc_variables[i];
5347  GucStack *stack;
5348 
5349  /*
5350  * Process and pop each stack entry within the nest level. To simplify
5351  * fmgr_security_definer() and other places that use GUC_ACTION_SAVE,
5352  * we allow failure exit from code that uses a local nest level to be
5353  * recovered at the surrounding transaction or subtransaction abort;
5354  * so there could be more than one stack entry to pop.
5355  */
5356  while ((stack = gconf->stack) != NULL &&
5357  stack->nest_level >= nestLevel)
5358  {
5359  GucStack *prev = stack->prev;
5360  bool restorePrior = false;
5361  bool restoreMasked = false;
5362  bool changed;
5363 
5364  /*
5365  * In this next bit, if we don't set either restorePrior or
5366  * restoreMasked, we must "discard" any unwanted fields of the
5367  * stack entries to avoid leaking memory. If we do set one of
5368  * those flags, unused fields will be cleaned up after restoring.
5369  */
5370  if (!isCommit) /* if abort, always restore prior value */
5371  restorePrior = true;
5372  else if (stack->state == GUC_SAVE)
5373  restorePrior = true;
5374  else if (stack->nest_level == 1)
5375  {
5376  /* transaction commit */
5377  if (stack->state == GUC_SET_LOCAL)
5378  restoreMasked = true;
5379  else if (stack->state == GUC_SET)
5380  {
5381  /* we keep the current active value */
5382  discard_stack_value(gconf, &stack->prior);
5383  }
5384  else /* must be GUC_LOCAL */
5385  restorePrior = true;
5386  }
5387  else if (prev == NULL ||
5388  prev->nest_level < stack->nest_level - 1)
5389  {
5390  /* decrement entry's level and do not pop it */
5391  stack->nest_level--;
5392  continue;
5393  }
5394  else
5395  {
5396  /*
5397  * We have to merge this stack entry into prev. See README for
5398  * discussion of this bit.
5399  */
5400  switch (stack->state)
5401  {
5402  case GUC_SAVE:
5403  Assert(false); /* can't get here */
5404  break;
5405 
5406  case GUC_SET:
5407  /* next level always becomes SET */
5408  discard_stack_value(gconf, &stack->prior);
5409  if (prev->state == GUC_SET_LOCAL)
5410  discard_stack_value(gconf, &prev->masked);
5411  prev->state = GUC_SET;
5412  break;
5413 
5414  case GUC_LOCAL:
5415  if (prev->state == GUC_SET)
5416  {
5417  /* LOCAL migrates down */
5418  prev->masked_scontext = stack->scontext;
5419  prev->masked = stack->prior;
5420  prev->state = GUC_SET_LOCAL;
5421  }
5422  else
5423  {
5424  /* else just forget this stack level */
5425  discard_stack_value(gconf, &stack->prior);
5426  }
5427  break;
5428 
5429  case GUC_SET_LOCAL:
5430  /* prior state at this level no longer wanted */
5431  discard_stack_value(gconf, &stack->prior);
5432  /* copy down the masked state */
5433  prev->masked_scontext = stack->masked_scontext;
5434  if (prev->state == GUC_SET_LOCAL)
5435  discard_stack_value(gconf, &prev->masked);
5436  prev->masked = stack->masked;
5437  prev->state = GUC_SET_LOCAL;
5438  break;
5439  }
5440  }
5441 
5442  changed = false;
5443 
5444  if (restorePrior || restoreMasked)
5445  {
5446  /* Perform appropriate restoration of the stacked value */
5447  config_var_value newvalue;
5448  GucSource newsource;
5449  GucContext newscontext;
5450 
5451  if (restoreMasked)
5452  {
5453  newvalue = stack->masked;
5454  newsource = PGC_S_SESSION;
5455  newscontext = stack->masked_scontext;
5456  }
5457  else
5458  {
5459  newvalue = stack->prior;
5460  newsource = stack->source;
5461  newscontext = stack->scontext;
5462  }
5463 
5464  switch (gconf->vartype)
5465  {
5466  case PGC_BOOL:
5467  {
5468  struct config_bool *conf = (struct config_bool *) gconf;
5469  bool newval = newvalue.val.boolval;
5470  void *newextra = newvalue.extra;
5471 
5472  if (*conf->variable != newval ||
5473  conf->gen.extra != newextra)
5474  {
5475  if (conf->assign_hook)
5476  conf->assign_hook(newval, newextra);
5477  *conf->variable = newval;
5478  set_extra_field(&conf->gen, &conf->gen.extra,
5479  newextra);
5480  changed = true;
5481  }
5482  break;
5483  }
5484  case PGC_INT:
5485  {
5486  struct config_int *conf = (struct config_int *) gconf;
5487  int newval = newvalue.val.intval;
5488  void *newextra = newvalue.extra;
5489 
5490  if (*conf->variable != newval ||
5491  conf->gen.extra != newextra)
5492  {
5493  if (conf->assign_hook)
5494  conf->assign_hook(newval, newextra);
5495  *conf->variable = newval;
5496  set_extra_field(&conf->gen, &conf->gen.extra,
5497  newextra);
5498  changed = true;
5499  }
5500  break;
5501  }
5502  case PGC_REAL:
5503  {
5504  struct config_real *conf = (struct config_real *) gconf;
5505  double newval = newvalue.val.realval;
5506  void *newextra = newvalue.extra;
5507 
5508  if (*conf->variable != newval ||
5509  conf->gen.extra != newextra)
5510  {
5511  if (conf->assign_hook)
5512  conf->assign_hook(newval, newextra);
5513  *conf->variable = newval;
5514  set_extra_field(&conf->gen, &conf->gen.extra,
5515  newextra);
5516  changed = true;
5517  }
5518  break;
5519  }
5520  case PGC_STRING:
5521  {
5522  struct config_string *conf = (struct config_string *) gconf;
5523  char *newval = newvalue.val.stringval;
5524  void *newextra = newvalue.extra;
5525 
5526  if (*conf->variable != newval ||
5527  conf->gen.extra != newextra)
5528  {
5529  if (conf->assign_hook)
5530  conf->assign_hook(newval, newextra);
5531  set_string_field(conf, conf->variable, newval);
5532  set_extra_field(&conf->gen, &conf->gen.extra,
5533  newextra);
5534  changed = true;
5535  }
5536 
5537  /*
5538  * Release stacked values if not used anymore. We
5539  * could use discard_stack_value() here, but since
5540  * we have type-specific code anyway, might as
5541  * well inline it.
5542  */
5543  set_string_field(conf, &stack->prior.val.stringval, NULL);
5544  set_string_field(conf, &stack->masked.val.stringval, NULL);
5545  break;
5546  }
5547  case PGC_ENUM:
5548  {
5549  struct config_enum *conf = (struct config_enum *) gconf;
5550  int newval = newvalue.val.enumval;
5551  void *newextra = newvalue.extra;
5552 
5553  if (*conf->variable != newval ||
5554  conf->gen.extra != newextra)
5555  {
5556  if (conf->assign_hook)
5557  conf->assign_hook(newval, newextra);
5558  *conf->variable = newval;
5559  set_extra_field(&conf->gen, &conf->gen.extra,
5560  newextra);
5561  changed = true;
5562  }
5563  break;
5564  }
5565  }
5566 
5567  /*
5568  * Release stacked extra values if not used anymore.
5569  */
5570  set_extra_field(gconf, &(stack->prior.extra), NULL);
5571  set_extra_field(gconf, &(stack->masked.extra), NULL);
5572 
5573  /* And restore source information */
5574  gconf->source = newsource;
5575  gconf->scontext = newscontext;
5576  }
5577 
5578  /* Finish popping the state stack */
5579  gconf->stack = prev;
5580  pfree(stack);
5581 
5582  /* Report new value if we changed it */
5583  if (changed && (gconf->flags & GUC_REPORT))
5584  ReportGUCOption(gconf);
5585  } /* end of stack-popping loop */
5586 
5587  if (stack != NULL)
5588  still_dirty = true;
5589  }
5590 
5591  /* If there are no remaining stack entries, we can reset guc_dirty */
5592  guc_dirty = still_dirty;
5593 
5594  /* Update nesting level */
5595  GUCNestLevel = nestLevel - 1;
5596 }
struct guc_stack * prev
Definition: guc_tables.h:121
GucSource source
Definition: guc_tables.h:156
GucContext
Definition: guc.h:68
union config_var_val val
Definition: guc_tables.h:46
int nest_level
Definition: guc_tables.h:122
GucRealAssignHook assign_hook
Definition: guc_tables.h:217
char ** variable
Definition: guc_tables.h:228
static int GUCNestLevel
Definition: guc.c:4191
bool * variable
Definition: guc_tables.h:182
GucEnumAssignHook assign_hook
Definition: guc_tables.h:246
GucBoolAssignHook assign_hook
Definition: guc_tables.h:185
config_var_value masked
Definition: guc_tables.h:129
GucContext scontext
Definition: guc_tables.h:158
GucIntAssignHook assign_hook
Definition: guc_tables.h:201
GucSource
Definition: guc.h:105
int * variable
Definition: guc_tables.h:196
int * variable
Definition: guc_tables.h:242
void pfree(void *pointer)
Definition: mcxt.c:1031
static int num_guc_variables
Definition: guc.c:4181
static void discard_stack_value(struct config_generic *gconf, config_var_value *val)
Definition: guc.c:4406
GucSource source
Definition: guc_tables.h:124
static void set_extra_field(struct config_generic *gconf, void **field, void *newval)
Definition: guc.c:4352
struct config_generic gen
Definition: guc_tables.h:180
struct config_generic gen
Definition: guc_tables.h:194
GucContext masked_scontext
Definition: guc_tables.h:127
#define GUC_REPORT
Definition: guc.h:208
double * variable
Definition: guc_tables.h:212
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4291
static struct config_generic ** guc_variables
Definition: guc.c:4178
enum config_type vartype
Definition: guc_tables.h:154
GucContext scontext
Definition: guc_tables.h:126
struct config_generic gen
Definition: guc_tables.h:240
struct config_generic gen
Definition: guc_tables.h:226
GucStackState state
Definition: guc_tables.h:123
GucStringAssignHook assign_hook
Definition: guc_tables.h:231
#define Assert(condition)
Definition: c.h:699
#define newval
char * stringval
Definition: guc_tables.h:36
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:5632
GucStack * stack
Definition: guc_tables.h:160
double realval
Definition: guc_tables.h:35
static bool guc_dirty
Definition: guc.c:4187
config_var_value prior
Definition: guc_tables.h:128
struct config_generic gen
Definition: guc_tables.h:210

◆ AtStart_GUC()

void AtStart_GUC ( void  )

Definition at line 5288 of file guc.c.

References elog, and WARNING.

Referenced by StartTransaction().

5289 {
5290  /*
5291  * The nest level should be 0 between transactions; if it isn't, somebody
5292  * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
5293  * throw a warning but make no other effort to clean up.
5294  */
5295  if (GUCNestLevel != 0)
5296  elog(WARNING, "GUC nest level = %d at transaction start",
5297  GUCNestLevel);
5298  GUCNestLevel = 1;
5299 }
static int GUCNestLevel
Definition: guc.c:4191
#define WARNING
Definition: elog.h:40
#define elog
Definition: elog.h:219

◆ BeginReportingGUCOptions()

void BeginReportingGUCOptions ( void  )

Definition at line 5604 of file guc.c.

References DestRemote, config_generic::flags, FrontendProtocol, GUC_REPORT, i, num_guc_variables, PG_PROTOCOL_MAJOR, ReportGUCOption(), and whereToSendOutput.

Referenced by PostgresMain().

5605 {
5606  int i;
5607 
5608  /*
5609  * Don't do anything unless talking to an interactive frontend of protocol
5610  * 3.0 or later.
5611  */
5612  if (whereToSendOutput != DestRemote ||
5614  return;
5615 
5616  reporting_enabled = true;
5617 
5618  /* Transmit initial values of interesting variables */
5619  for (i = 0; i < num_guc_variables; i++)
5620  {
5621  struct config_generic *conf = guc_variables[i];
5622 
5623  if (conf->flags & GUC_REPORT)
5624  ReportGUCOption(conf);
5625  }
5626 }
#define PG_PROTOCOL_MAJOR(v)
Definition: pqcomm.h:104
static int num_guc_variables
Definition: guc.c:4181
#define GUC_REPORT
Definition: guc.h:208
static struct config_generic ** guc_variables
Definition: guc.c:4178
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:5632
CommandDest whereToSendOutput
Definition: postgres.c:90
static bool reporting_enabled
Definition: guc.c:4189
ProtocolVersion FrontendProtocol
Definition: globals.c:28

◆ check_default_tablespace()

bool check_default_tablespace ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 1064 of file tablespace.c.

References ereport, errcode(), errmsg(), get_tablespace_oid(), GUC_check_errdetail, IsTransactionState(), NOTICE, OidIsValid, and PGC_S_TEST.

1065 {
1066  /*
1067  * If we aren't inside a transaction, we cannot do database access so
1068  * cannot verify the name. Must accept the value on faith.
1069  */
1070  if (IsTransactionState())
1071  {
1072  if (**newval != '\0' &&
1074  {
1075  /*
1076  * When source == PGC_S_TEST, don't throw a hard error for a
1077  * nonexistent tablespace, only a NOTICE. See comments in guc.h.
1078  */
1079  if (source == PGC_S_TEST)
1080  {
1081  ereport(NOTICE,
1082  (errcode(ERRCODE_UNDEFINED_OBJECT),
1083  errmsg("tablespace \"%s\" does not exist",
1084  *newval)));
1085  }
1086  else
1087  {
1088  GUC_check_errdetail("Tablespace \"%s\" does not exist.",
1089  *newval);
1090  return false;
1091  }
1092  }
1093  }
1094 
1095  return true;
1096 }
Oid get_tablespace_oid(const char *tablespacename, bool missing_ok)
Definition: tablespace.c:1382
GucSource source
Definition: guc_tables.h:156
#define GUC_check_errdetail
Definition: guc.h:410
int errcode(int sqlerrcode)
Definition: elog.c:575
#define OidIsValid(objectId)
Definition: c.h:605
#define ereport(elevel, rest)
Definition: elog.h:122
#define NOTICE
Definition: elog.h:37
#define newval
bool IsTransactionState(void)
Definition: xact.c:350
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ check_search_path()

bool check_search_path ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 4079 of file namespace.c.

References GUC_check_errdetail, list_free(), pfree(), pstrdup(), and SplitIdentifierString().

4080 {
4081  char *rawname;
4082  List *namelist;
4083 
4084  /* Need a modifiable copy of string */
4085  rawname = pstrdup(*newval);
4086 
4087  /* Parse string into list of identifiers */
4088  if (!SplitIdentifierString(rawname, ',', &namelist))
4089  {
4090  /* syntax error in name list */
4091  GUC_check_errdetail("List syntax is invalid.");
4092  pfree(rawname);
4093  list_free(namelist);
4094  return false;
4095  }
4096 
4097  /*
4098  * We used to try to check that the named schemas exist, but there are
4099  * many valid use-cases for having search_path settings that include
4100  * schemas that don't exist; and often, we are not inside a transaction
4101  * here and so can't consult the system catalogs anyway. So now, the only
4102  * requirement is syntactic validity of the identifier list.
4103  */
4104 
4105  pfree(rawname);
4106  list_free(namelist);
4107 
4108  return true;
4109 }
#define GUC_check_errdetail
Definition: guc.h:410
char * pstrdup(const char *in)
Definition: mcxt.c:1161
void pfree(void *pointer)
Definition: mcxt.c:1031
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3290
#define newval
void list_free(List *list)
Definition: list.c:1133
Definition: pg_list.h:45

◆ check_temp_tablespaces()

bool check_temp_tablespaces ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 1159 of file tablespace.c.

References ACL_CREATE, aclcheck_error(), ACLCHECK_OK, ereport, errcode(), errmsg(), get_tablespace_oid(), GetUserId(), GUC_check_errdetail, InvalidOid, IsTransactionState(), lfirst, list_free(), list_length(), malloc, MyDatabaseTableSpace, NOTICE, temp_tablespaces_extra::numSpcs, OBJECT_TABLESPACE, offsetof, palloc(), pfree(), pg_tablespace_aclcheck(), PGC_S_INTERACTIVE, PGC_S_TEST, pstrdup(), SplitIdentifierString(), and temp_tablespaces_extra::tblSpcs.

1160 {
1161  char *rawname;
1162  List *namelist;
1163 
1164  /* Need a modifiable copy of string */
1165  rawname = pstrdup(*newval);
1166 
1167  /* Parse string into list of identifiers */
1168  if (!SplitIdentifierString(rawname, ',', &namelist))
1169  {
1170  /* syntax error in name list */
1171  GUC_check_errdetail("List syntax is invalid.");
1172  pfree(rawname);
1173  list_free(namelist);
1174  return false;
1175  }
1176 
1177  /*
1178  * If we aren't inside a transaction, we cannot do database access so
1179  * cannot verify the individual names. Must accept the list on faith.
1180  * Fortunately, there's then also no need to pass the data to fd.c.
1181  */
1182  if (IsTransactionState())
1183  {
1184  temp_tablespaces_extra *myextra;
1185  Oid *tblSpcs;
1186  int numSpcs;
1187  ListCell *l;
1188 
1189  /* temporary workspace until we are done verifying the list */
1190  tblSpcs = (Oid *) palloc(list_length(namelist) * sizeof(Oid));
1191  numSpcs = 0;
1192  foreach(l, namelist)
1193  {
1194  char *curname = (char *) lfirst(l);
1195  Oid curoid;
1196  AclResult aclresult;
1197 
1198  /* Allow an empty string (signifying database default) */
1199  if (curname[0] == '\0')
1200  {
1201  tblSpcs[numSpcs++] = InvalidOid;
1202  continue;
1203  }
1204 
1205  /*
1206  * In an interactive SET command, we ereport for bad info. When
1207  * source == PGC_S_TEST, don't throw a hard error for a
1208  * nonexistent tablespace, only a NOTICE. See comments in guc.h.
1209  */
1210  curoid = get_tablespace_oid(curname, source <= PGC_S_TEST);
1211  if (curoid == InvalidOid)
1212  {
1213  if (source == PGC_S_TEST)
1214  ereport(NOTICE,
1215  (errcode(ERRCODE_UNDEFINED_OBJECT),
1216  errmsg("tablespace \"%s\" does not exist",
1217  curname)));
1218  continue;
1219  }
1220 
1221  /*
1222  * Allow explicit specification of database's default tablespace
1223  * in temp_tablespaces without triggering permissions checks.
1224  */
1225  if (curoid == MyDatabaseTableSpace)
1226  {
1227  tblSpcs[numSpcs++] = InvalidOid;
1228  continue;
1229  }
1230 
1231  /* Check permissions, similarly complaining only if interactive */
1232  aclresult = pg_tablespace_aclcheck(curoid, GetUserId(),
1233  ACL_CREATE);
1234  if (aclresult != ACLCHECK_OK)
1235  {
1236  if (source >= PGC_S_INTERACTIVE)
1237  aclcheck_error(aclresult, OBJECT_TABLESPACE, curname);
1238  continue;
1239  }
1240 
1241  tblSpcs[numSpcs++] = curoid;
1242  }
1243 
1244  /* Now prepare an "extra" struct for assign_temp_tablespaces */
1245  myextra = malloc(offsetof(temp_tablespaces_extra, tblSpcs) +
1246  numSpcs * sizeof(Oid));
1247  if (!myextra)
1248  return false;
1249  myextra->numSpcs = numSpcs;
1250  memcpy(myextra->tblSpcs, tblSpcs, numSpcs * sizeof(Oid));
1251  *extra = (void *) myextra;
1252 
1253  pfree(tblSpcs);
1254  }
1255 
1256  pfree(rawname);
1257  list_free(namelist);
1258 
1259  return true;
1260 }
Oid get_tablespace_oid(const char *tablespacename, bool missing_ok)
Definition: tablespace.c:1382
GucSource source
Definition: guc_tables.h:156
AclResult pg_tablespace_aclcheck(Oid spc_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4701
Oid GetUserId(void)
Definition: miscinit.c:379
#define GUC_check_errdetail
Definition: guc.h:410
char * pstrdup(const char *in)
Definition: mcxt.c:1161
int errcode(int sqlerrcode)
Definition: elog.c:575
unsigned int Oid
Definition: postgres_ext.h:31
Oid MyDatabaseTableSpace
Definition: globals.c:86
#define malloc(a)
Definition: header.h:50
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3349
void pfree(void *pointer)
Definition: mcxt.c:1031
#define ACL_CREATE
Definition: parsenodes.h:84
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3290
Oid tblSpcs[FLEXIBLE_ARRAY_MEMBER]
Definition: tablespace.c:1154
#define ereport(elevel, rest)
Definition: elog.h:122
AclResult
Definition: acl.h:178
#define InvalidOid
Definition: postgres_ext.h:36
#define NOTICE
Definition: elog.h:37
#define lfirst(lc)
Definition: pg_list.h:106
static int list_length(const List *l)
Definition: pg_list.h:89
#define newval
bool IsTransactionState(void)
Definition: xact.c:350
void * palloc(Size size)
Definition: mcxt.c:924
int errmsg(const char *fmt,...)
Definition: elog.c:797
void list_free(List *list)
Definition: list.c:1133
Definition: pg_list.h:45
#define offsetof(type, field)
Definition: c.h:622

◆ check_wal_buffers()

bool check_wal_buffers ( int *  newval,
void **  extra,
GucSource  source 
)

Definition at line 4817 of file xlog.c.

References XLOGbuffers, and XLOGChooseNumBuffers().

4818 {
4819  /*
4820  * -1 indicates a request for auto-tune.
4821  */
4822  if (*newval == -1)
4823  {
4824  /*
4825  * If we haven't yet changed the boot_val default of -1, just let it
4826  * be. We'll fix it when XLOGShmemSize is called.
4827  */
4828  if (XLOGbuffers == -1)
4829  return true;
4830 
4831  /* Otherwise, substitute the auto-tune value */
4833  }
4834 
4835  /*
4836  * We clamp manually-set values to at least 4 blocks. Prior to PostgreSQL
4837  * 9.1, a minimum of 4 was enforced by guc.c, but since that is no longer
4838  * the case, we just silently treat such values as a request for the
4839  * minimum. (We could throw an error instead, but that doesn't seem very
4840  * helpful.)
4841  */
4842  if (*newval < 4)
4843  *newval = 4;
4844 
4845  return true;
4846 }
static int XLOGChooseNumBuffers(void)
Definition: xlog.c:4801
#define newval
int XLOGbuffers
Definition: xlog.c:92

◆ DefineCustomBoolVariable()

void DefineCustomBoolVariable ( const char *  name,
const char *  short_desc,
const char *  long_desc,
bool valueAddr,
bool  bootValue,
GucContext  context,
int  flags,
GucBoolCheckHook  check_hook,
GucBoolAssignHook  assign_hook,
GucShowHook  show_hook 
)

Definition at line 8006 of file guc.c.

References config_bool::assign_hook, config_bool::boot_val, config_bool::check_hook, define_custom_variable(), config_bool::gen, init_custom_variable(), PGC_BOOL, config_bool::reset_val, config_bool::show_hook, and config_bool::variable.

Referenced by _PG_init().

8016 {
8017  struct config_bool *var;
8018 
8019  var = (struct config_bool *)
8020  init_custom_variable(name, short_desc, long_desc, context, flags,
8021  PGC_BOOL, sizeof(struct config_bool));
8022  var->variable = valueAddr;
8023  var->boot_val = bootValue;
8024  var->reset_val = bootValue;
8025  var->check_hook = check_hook;
8026  var->assign_hook = assign_hook;
8027  var->show_hook = show_hook;
8028  define_custom_variable(&var->gen);
8029 }
bool * variable
Definition: guc_tables.h:182
GucBoolAssignHook assign_hook
Definition: guc_tables.h:185
bool boot_val
Definition: guc_tables.h:183
struct config_generic gen
Definition: guc_tables.h:180
static struct config_generic * init_custom_variable(const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
Definition: guc.c:7765
GucBoolCheckHook check_hook
Definition: guc_tables.h:184
GucShowHook show_hook
Definition: guc_tables.h:186
const char * name
Definition: encode.c:521
bool reset_val
Definition: guc_tables.h:188
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7825

◆ DefineCustomEnumVariable()

void DefineCustomEnumVariable ( const char *  name,
const char *  short_desc,
const char *  long_desc,
int *  valueAddr,
int  bootValue,
const struct config_enum_entry options,
GucContext  context,
int  flags,
GucEnumCheckHook  check_hook,
GucEnumAssignHook  assign_hook,
GucShowHook  show_hook 
)

Definition at line 8117 of file guc.c.

References config_enum::assign_hook, config_enum::boot_val, config_enum::check_hook, define_custom_variable(), config_enum::gen, init_custom_variable(), options, config_enum::options, PGC_ENUM, config_enum::reset_val, config_enum::show_hook, and config_enum::variable.

Referenced by _PG_init().

8128 {
8129  struct config_enum *var;
8130 
8131  var = (struct config_enum *)
8132  init_custom_variable(name, short_desc, long_desc, context, flags,
8133  PGC_ENUM, sizeof(struct config_enum));
8134  var->variable = valueAddr;
8135  var->boot_val = bootValue;
8136  var->reset_val = bootValue;
8137  var->options = options;
8138  var->check_hook = check_hook;
8139  var->assign_hook = assign_hook;
8140  var->show_hook = show_hook;
8141  define_custom_variable(&var->gen);
8142 }
GucEnumCheckHook check_hook
Definition: guc_tables.h:245
GucEnumAssignHook assign_hook
Definition: guc_tables.h:246
int * variable
Definition: guc_tables.h:242
const struct config_enum_entry * options
Definition: guc_tables.h:244
static char ** options
static struct config_generic * init_custom_variable(const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
Definition: guc.c:7765
GucShowHook show_hook
Definition: guc_tables.h:247
struct config_generic gen
Definition: guc_tables.h:240
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7825

◆ DefineCustomIntVariable()

void DefineCustomIntVariable ( const char *  name,
const char *  short_desc,
const char *  long_desc,
int *  valueAddr,
int  bootValue,
int  minValue,
int  maxValue,
GucContext  context,
int  flags,
GucIntCheckHook  check_hook,
GucIntAssignHook  assign_hook,
GucShowHook  show_hook 
)

Definition at line 8032 of file guc.c.

References config_int::assign_hook, config_int::boot_val, config_int::check_hook, define_custom_variable(), config_int::gen, init_custom_variable(), config_int::max, config_int::min, PGC_INT, config_int::reset_val, config_int::show_hook, and config_int::variable.

Referenced by _PG_init().

8044 {
8045  struct config_int *var;
8046 
8047  var = (struct config_int *)
8048  init_custom_variable(name, short_desc, long_desc, context, flags,
8049  PGC_INT, sizeof(struct config_int));
8050  var->variable = valueAddr;
8051  var->boot_val = bootValue;
8052  var->reset_val = bootValue;
8053  var->min = minValue;
8054  var->max = maxValue;
8055  var->check_hook = check_hook;
8056  var->assign_hook = assign_hook;
8057  var->show_hook = show_hook;
8058  define_custom_variable(&var->gen);
8059 }
int boot_val
Definition: guc_tables.h:197
GucIntAssignHook assign_hook
Definition: guc_tables.h:201
GucIntCheckHook check_hook
Definition: guc_tables.h:200
GucShowHook show_hook
Definition: guc_tables.h:202
int * variable
Definition: guc_tables.h:196
struct config_generic gen
Definition: guc_tables.h:194
static struct config_generic * init_custom_variable(const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
Definition: guc.c:7765
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7825
int reset_val
Definition: guc_tables.h:204

◆ DefineCustomRealVariable()

void DefineCustomRealVariable ( const char *  name,
const char *  short_desc,
const char *  long_desc,
double *  valueAddr,
double  bootValue,
double  minValue,
double  maxValue,
GucContext  context,
int  flags,
GucRealCheckHook  check_hook,
GucRealAssignHook  assign_hook,
GucShowHook  show_hook 
)

Definition at line 8062 of file guc.c.

References config_real::assign_hook, config_real::boot_val, config_real::check_hook, define_custom_variable(), config_real::gen, init_custom_variable(), config_real::max, config_real::min, PGC_REAL, config_real::reset_val, config_real::show_hook, and config_real::variable.

Referenced by _PG_init().

8074 {
8075  struct config_real *var;
8076 
8077  var = (struct config_real *)
8078  init_custom_variable(name, short_desc, long_desc, context, flags,
8079  PGC_REAL, sizeof(struct config_real));
8080  var->variable = valueAddr;
8081  var->boot_val = bootValue;
8082  var->reset_val = bootValue;
8083  var->min = minValue;
8084  var->max = maxValue;
8085  var->check_hook = check_hook;
8086  var->assign_hook = assign_hook;
8087  var->show_hook = show_hook;
8088  define_custom_variable(&var->gen);
8089 }
GucRealAssignHook assign_hook
Definition: guc_tables.h:217
double reset_val
Definition: guc_tables.h:220
GucRealCheckHook check_hook
Definition: guc_tables.h:216
GucShowHook show_hook
Definition: guc_tables.h:218
double * variable
Definition: guc_tables.h:212
static struct config_generic * init_custom_variable(const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
Definition: guc.c:7765
double max
Definition: guc_tables.h:215
double boot_val
Definition: guc_tables.h:213
const char * name
Definition: encode.c:521
double min
Definition: guc_tables.h:214
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7825
struct config_generic gen
Definition: guc_tables.h:210

◆ DefineCustomStringVariable()

void DefineCustomStringVariable ( const char *  name,
const char *  short_desc,
const char *  long_desc,
char **  valueAddr,
const char *  bootValue,
GucContext  context,
int  flags,
GucStringCheckHook  check_hook,
GucStringAssignHook  assign_hook,
GucShowHook  show_hook 
)

Definition at line 8092 of file guc.c.

References config_string::assign_hook, config_string::boot_val, config_string::check_hook, define_custom_variable(), config_string::gen, init_custom_variable(), PGC_STRING, config_string::show_hook, and config_string::variable.

Referenced by _PG_init().

8102 {
8103  struct config_string *var;
8104 
8105  var = (struct config_string *)
8106  init_custom_variable(name, short_desc, long_desc, context, flags,
8107  PGC_STRING, sizeof(struct config_string));
8108  var->variable = valueAddr;
8109  var->boot_val = bootValue;
8110  var->check_hook = check_hook;
8111  var->assign_hook = assign_hook;
8112  var->show_hook = show_hook;
8113  define_custom_variable(&var->gen);
8114 }
char ** variable
Definition: guc_tables.h:228
GucStringCheckHook check_hook
Definition: guc_tables.h:230
const char * boot_val
Definition: guc_tables.h:229
GucShowHook show_hook
Definition: guc_tables.h:232
static struct config_generic * init_custom_variable(const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
Definition: guc.c:7765
struct config_generic gen
Definition: guc_tables.h:226
GucStringAssignHook assign_hook
Definition: guc_tables.h:231
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7825

◆ EmitWarningsOnPlaceholders()

void EmitWarningsOnPlaceholders ( const char *  className)

Definition at line 8145 of file guc.c.

References ereport, errcode(), errmsg(), config_generic::flags, GUC_CUSTOM_PLACEHOLDER, GUC_QUALIFIER_SEPARATOR, i, config_generic::name, num_guc_variables, and WARNING.

Referenced by _PG_init().

8146 {
8147  int classLen = strlen(className);
8148  int i;
8149 
8150  for (i = 0; i < num_guc_variables; i++)
8151  {
8152  struct config_generic *var = guc_variables[i];
8153 
8154  if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
8155  strncmp(className, var->name, classLen) == 0 &&
8156  var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
8157  {
8158  ereport(WARNING,
8159  (errcode(ERRCODE_UNDEFINED_OBJECT),
8160  errmsg("unrecognized configuration parameter \"%s\"",
8161  var->name)));
8162  }
8163  }
8164 }
const char * name
Definition: guc_tables.h:147
int errcode(int sqlerrcode)
Definition: elog.c:575
#define GUC_QUALIFIER_SEPARATOR
Definition: guc.h:199
static int num_guc_variables
Definition: guc.c:4181
#define ereport(elevel, rest)
Definition: elog.h:122
static struct config_generic ** guc_variables
Definition: guc.c:4178
#define WARNING
Definition: elog.h:40
#define GUC_CUSTOM_PLACEHOLDER
Definition: guc.h:211
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i

◆ EstimateGUCStateSpace()

Size EstimateGUCStateSpace ( void  )

Definition at line 9378 of file guc.c.

References add_size(), estimate_variable_size(), i, and num_guc_variables.

Referenced by InitializeParallelDSM().

9379 {
9380  Size size;
9381  int i;
9382 
9383  /* Add space reqd for saving the data size of the guc state */
9384  size = sizeof(Size);
9385 
9386  /* Add up the space needed for each GUC variable */
9387  for (i = 0; i < num_guc_variables; i++)
9388  size = add_size(size,
9390 
9391  return size;
9392 }
static int num_guc_variables
Definition: guc.c:4181
static struct config_generic ** guc_variables
Definition: guc.c:4178
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
size_t Size
Definition: c.h:433
static Size estimate_variable_size(struct config_generic *gconf)
Definition: guc.c:9280
int i

◆ ExecSetVariableStmt()

void ExecSetVariableStmt ( VariableSetStmt stmt,
bool  isTopLevel 
)

Definition at line 7553 of file guc.c.

References generate_unaccent_rules::action, DefElem::arg, VariableSetStmt::args, Assert, DefElem::defname, elog, ereport, errcode(), errmsg(), ERROR, ExtractSetVariableArgs(), GUC_ACTION_LOCAL, GUC_ACTION_SET, ImportSnapshot(), VariableSetStmt::is_local, IsInParallelMode(), VariableSetStmt::kind, lfirst, linitial_node, list_make1, VariableSetStmt::name, nodeTag, PGC_S_SESSION, PGC_SUSET, PGC_USERSET, ResetAllOptions(), set_config_option(), SetPGVariable(), strVal, superuser(), T_String, A_Const::val, VAR_RESET, VAR_RESET_ALL, VAR_SET_CURRENT, VAR_SET_DEFAULT, VAR_SET_MULTI, VAR_SET_VALUE, and WarnNoTransactionBlock().

Referenced by standard_ProcessUtility().

7554 {
7556 
7557  /*
7558  * Workers synchronize these parameters at the start of the parallel
7559  * operation; then, we block SET during the operation.
7560  */
7561  if (IsInParallelMode())
7562  ereport(ERROR,
7563  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
7564  errmsg("cannot set parameters during a parallel operation")));
7565 
7566  switch (stmt->kind)
7567  {
7568  case VAR_SET_VALUE:
7569  case VAR_SET_CURRENT:
7570  if (stmt->is_local)
7571  WarnNoTransactionBlock(isTopLevel, "SET LOCAL");
7572  (void) set_config_option(stmt->name,
7573  ExtractSetVariableArgs(stmt),
7575  PGC_S_SESSION,
7576  action, true, 0, false);
7577  break;
7578  case VAR_SET_MULTI:
7579 
7580  /*
7581  * Special-case SQL syntaxes. The TRANSACTION and SESSION
7582  * CHARACTERISTICS cases effectively set more than one variable
7583  * per statement. TRANSACTION SNAPSHOT only takes one argument,
7584  * but we put it here anyway since it's a special case and not
7585  * related to any GUC variable.
7586  */
7587  if (strcmp(stmt->name, "TRANSACTION") == 0)
7588  {
7589  ListCell *head;
7590 
7591  WarnNoTransactionBlock(isTopLevel, "SET TRANSACTION");
7592 
7593  foreach(head, stmt->args)
7594  {
7595  DefElem *item = (DefElem *) lfirst(head);
7596 
7597  if (strcmp(item->defname, "transaction_isolation") == 0)
7598  SetPGVariable("transaction_isolation",
7599  list_make1(item->arg), stmt->is_local);
7600  else if (strcmp(item->defname, "transaction_read_only") == 0)
7601  SetPGVariable("transaction_read_only",
7602  list_make1(item->arg), stmt->is_local);
7603  else if (strcmp(item->defname, "transaction_deferrable") == 0)
7604  SetPGVariable("transaction_deferrable",
7605  list_make1(item->arg), stmt->is_local);
7606  else
7607  elog(ERROR, "unexpected SET TRANSACTION element: %s",
7608  item->defname);
7609  }
7610  }
7611  else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
7612  {
7613  ListCell *head;
7614 
7615  foreach(head, stmt->args)
7616  {
7617  DefElem *item = (DefElem *) lfirst(head);
7618 
7619  if (strcmp(item->defname, "transaction_isolation") == 0)
7620  SetPGVariable("default_transaction_isolation",
7621  list_make1(item->arg), stmt->is_local);
7622  else if (strcmp(item->defname, "transaction_read_only") == 0)
7623  SetPGVariable("default_transaction_read_only",
7624  list_make1(item->arg), stmt->is_local);
7625  else if (strcmp(item->defname, "transaction_deferrable") == 0)
7626  SetPGVariable("default_transaction_deferrable",
7627  list_make1(item->arg), stmt->is_local);
7628  else
7629  elog(ERROR, "unexpected SET SESSION element: %s",
7630  item->defname);
7631  }
7632  }
7633  else if (strcmp(stmt->name, "TRANSACTION SNAPSHOT") == 0)
7634  {
7635  A_Const *con = linitial_node(A_Const, stmt->args);
7636 
7637  if (stmt->is_local)
7638  ereport(ERROR,
7639  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7640  errmsg("SET LOCAL TRANSACTION SNAPSHOT is not implemented")));
7641 
7642  WarnNoTransactionBlock(isTopLevel, "SET TRANSACTION");
7643  Assert(nodeTag(&con->val) == T_String);
7644  ImportSnapshot(strVal(&con->val));
7645  }
7646  else
7647  elog(ERROR, "unexpected SET MULTI element: %s",
7648  stmt->name);
7649  break;
7650  case VAR_SET_DEFAULT:
7651  if (stmt->is_local)
7652  WarnNoTransactionBlock(isTopLevel, "SET LOCAL");
7653  /* fall through */
7654  case VAR_RESET:
7655  if (strcmp(stmt->name, "transaction_isolation") == 0)
7656  WarnNoTransactionBlock(isTopLevel, "RESET TRANSACTION");
7657 
7658  (void) set_config_option(stmt->name,
7659  NULL,
7661  PGC_S_SESSION,
7662  action, true, 0, false);
7663  break;
7664  case VAR_RESET_ALL:
7665  ResetAllOptions();
7666  break;
7667  }
7668 }
void ImportSnapshot(const char *idstr)
Definition: snapmgr.c:1430
VariableSetKind kind
Definition: parsenodes.h:1984
void WarnNoTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3213
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:575
bool superuser(void)
Definition: superuser.c:47
#define linitial_node(type, l)
Definition: pg_list.h:114
GucAction
Definition: guc.h:191
#define list_make1(x1)
Definition: pg_list.h:139
bool IsInParallelMode(void)
Definition: xact.c:905
#define ERROR
Definition: elog.h:43
Definition: guc.h:75
void ResetAllOptions(void)
Definition: guc.c:5107
#define ereport(elevel, rest)
Definition: elog.h:122
Node * arg
Definition: parsenodes.h:731
#define Assert(condition)
Definition: c.h:699
#define lfirst(lc)
Definition: pg_list.h:106
#define nodeTag(nodeptr)
Definition: nodes.h:521
int errmsg(const char *fmt,...)
Definition: elog.c:797
char * defname
Definition: parsenodes.h:730
#define elog
Definition: elog.h:219
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
Definition: guc.c:7677
Value val
Definition: parsenodes.h:289
int set_config_option(const char *name, const char *value, GucContext context, GucSource source, GucAction action, bool changeVal, int elevel, bool is_reload)
Definition: guc.c:6152
void SetPGVariable(const char *name, List *args, bool is_local)
Definition: guc.c:7697

◆ ExtractSetVariableArgs()

char* ExtractSetVariableArgs ( VariableSetStmt stmt)

Definition at line 7677 of file guc.c.

References VariableSetStmt::args, flatten_set_variable_args(), GetConfigOptionByName(), VariableSetStmt::kind, VariableSetStmt::name, VAR_SET_CURRENT, and VAR_SET_VALUE.

Referenced by AlterSetting(), AlterSystemSetConfigFile(), ExecSetVariableStmt(), and update_proconfig_value().

7678 {
7679  switch (stmt->kind)
7680  {
7681  case VAR_SET_VALUE:
7682  return flatten_set_variable_args(stmt->name, stmt->args);
7683  case VAR_SET_CURRENT:
7684  return GetConfigOptionByName(stmt->name, NULL, false);
7685  default:
7686  return NULL;
7687  }
7688 }
VariableSetKind kind
Definition: parsenodes.h:1984
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:8312
static char * flatten_set_variable_args(const char *name, List *args)
Definition: guc.c:7076

◆ FreeConfigVariables()

◆ GetConfigOption()

const char* GetConfigOption ( const char *  name,
bool  missing_ok,
bool  restrict_privileged 
)

Definition at line 6941 of file guc.c.

References buffer, config_enum_lookup_by_value(), ereport, errcode(), errmsg(), ERROR, find_option(), config_generic::flags, GetUserId(), GUC_SUPERUSER_ONLY, is_member_of_role(), PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_STRING, snprintf(), and config_generic::vartype.

Referenced by applyRemoteGucs(), and PostmasterMain().

6942 {
6943  struct config_generic *record;
6944  static char buffer[256];
6945 
6946  record = find_option(name, false, ERROR);
6947  if (record == NULL)
6948  {
6949  if (missing_ok)
6950  return NULL;
6951  ereport(ERROR,
6952  (errcode(ERRCODE_UNDEFINED_OBJECT),
6953  errmsg("unrecognized configuration parameter \"%s\"",
6954  name)));
6955  }
6956  if (restrict_privileged &&
6957  (record->flags & GUC_SUPERUSER_ONLY) &&
6958  !is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
6959  ereport(ERROR,
6960  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6961  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
6962  name)));
6963 
6964  switch (record->vartype)
6965  {
6966  case PGC_BOOL:
6967  return *((struct config_bool *) record)->variable ? "on" : "off";
6968 
6969  case PGC_INT:
6970  snprintf(buffer, sizeof(buffer), "%d",
6971  *((struct config_int *) record)->variable);
6972  return buffer;
6973 
6974  case PGC_REAL:
6975  snprintf(buffer, sizeof(buffer), "%g",
6976  *((struct config_real *) record)->variable);
6977  return buffer;
6978 
6979  case PGC_STRING:
6980  return *((struct config_string *) record)->variable;
6981 
6982  case PGC_ENUM:
6983  return config_enum_lookup_by_value((struct config_enum *) record,
6984  *((struct config_enum *) record)->variable);
6985  }
6986  return NULL;
6987 }
Oid GetUserId(void)
Definition: miscinit.c:379
int errcode(int sqlerrcode)
Definition: elog.c:575
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5861
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
enum config_type vartype
Definition: guc_tables.h:154
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4857
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4615
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:215
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ GetConfigOptionByName()

char* GetConfigOptionByName ( const char *  name,
const char **  varname,
bool  missing_ok 
)

Definition at line 8312 of file guc.c.

References _ShowOption(), ereport, errcode(), errmsg(), ERROR, find_option(), config_generic::flags, GetUserId(), GUC_SUPERUSER_ONLY, is_member_of_role(), and config_generic::name.

Referenced by ExtractSetVariableArgs(), GetPGVariableResultDesc(), set_config_by_name(), show_config_by_name(), show_config_by_name_missing_ok(), and ShowGUCConfigOption().

8313 {
8314  struct config_generic *record;
8315 
8316  record = find_option(name, false, ERROR);
8317  if (record == NULL)
8318  {
8319  if (missing_ok)
8320  {
8321  if (varname)
8322  *varname = NULL;
8323  return NULL;
8324  }
8325 
8326  ereport(ERROR,
8327  (errcode(ERRCODE_UNDEFINED_OBJECT),
8328  errmsg("unrecognized configuration parameter \"%s\"", name)));
8329  }
8330 
8331  if ((record->flags & GUC_SUPERUSER_ONLY) &&
8332  !is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
8333  ereport(ERROR,
8334  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
8335  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
8336  name)));
8337 
8338  if (varname)
8339  *varname = record->name;
8340 
8341  return _ShowOption(record, true);
8342 }
static char * _ShowOption(struct config_generic *record, bool use_units)
Definition: guc.c:8914
Oid GetUserId(void)
Definition: miscinit.c:379
const char * name
Definition: guc_tables.h:147
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4857
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4615
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ GetConfigOptionByNum()

void GetConfigOptionByNum ( int  varnum,
const char **  values,
bool noshow 
)

Definition at line 8349 of file guc.c.

References _ShowOption(), Assert, config_bool::boot_val, config_int::boot_val, config_real::boot_val, config_string::boot_val, config_enum::boot_val, buffer, config_enum_get_options(), config_enum_lookup_by_value(), config_generic::context, elog, ERROR, config_generic::flags, GetUserId(), config_generic::group, GUC_NO_SHOW_ALL, GUC_PENDING_RESTART, GUC_SUPERUSER_ONLY, GUC_UNIT_BLOCKS, GUC_UNIT_BYTE, GUC_UNIT_KB, GUC_UNIT_MB, GUC_UNIT_MEMORY, GUC_UNIT_MIN, GUC_UNIT_MS, GUC_UNIT_S, GUC_UNIT_TIME, GUC_UNIT_XBLOCKS, is_member_of_role(), config_generic::long_desc, config_int::max, config_real::max, config_int::min, config_real::min, config_generic::name, PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_S_FILE, PGC_STRING, pstrdup(), config_bool::reset_val, config_int::reset_val, config_real::reset_val, config_string::reset_val, config_enum::reset_val, config_generic::short_desc, snprintf(), config_generic::source, config_generic::sourcefile, config_generic::sourceline, config_generic::status, and config_generic::vartype.

Referenced by show_all_settings().

8350 {
8351  char buffer[256];
8352  struct config_generic *conf;
8353 
8354  /* check requested variable number valid */
8355  Assert((varnum >= 0) && (varnum < num_guc_variables));
8356 
8357  conf = guc_variables[varnum];
8358 
8359  if (noshow)
8360  {
8361  if ((conf->flags & GUC_NO_SHOW_ALL) ||
8362  ((conf->flags & GUC_SUPERUSER_ONLY) &&
8363  !is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS)))
8364  *noshow = true;
8365  else
8366  *noshow = false;
8367  }
8368 
8369  /* first get the generic attributes */
8370 
8371  /* name */
8372  values[0] = conf->name;
8373 
8374  /* setting : use _ShowOption in order to avoid duplicating the logic */
8375  values[1] = _ShowOption(conf, false);
8376 
8377  /* unit */
8378  if (conf->vartype == PGC_INT)
8379  {
8380  switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
8381  {
8382  case GUC_UNIT_BYTE:
8383  values[2] = "B";
8384  break;
8385  case GUC_UNIT_KB:
8386  values[2] = "kB";
8387  break;
8388  case GUC_UNIT_MB:
8389  values[2] = "MB";
8390  break;
8391  case GUC_UNIT_BLOCKS:
8392  snprintf(buffer, sizeof(buffer), "%dkB", BLCKSZ / 1024);
8393  values[2] = pstrdup(buffer);
8394  break;
8395  case GUC_UNIT_XBLOCKS:
8396  snprintf(buffer, sizeof(buffer), "%dkB", XLOG_BLCKSZ / 1024);
8397  values[2] = pstrdup(buffer);
8398  break;
8399  case GUC_UNIT_MS:
8400  values[2] = "ms";
8401  break;
8402  case GUC_UNIT_S:
8403  values[2] = "s";
8404  break;
8405  case GUC_UNIT_MIN:
8406  values[2] = "min";
8407  break;
8408  case 0:
8409  values[2] = NULL;
8410  break;
8411  default:
8412  elog(ERROR, "unrecognized GUC units value: %d",
8413  conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME));
8414  values[2] = NULL;
8415  break;
8416  }
8417  }
8418  else
8419  values[2] = NULL;
8420 
8421  /* group */
8422  values[3] = config_group_names[conf->group];
8423 
8424  /* short_desc */
8425  values[4] = conf->short_desc;
8426 
8427  /* extra_desc */
8428  values[5] = conf->long_desc;
8429 
8430  /* context */
8431  values[6] = GucContext_Names[conf->context];
8432 
8433  /* vartype */
8434  values[7] = config_type_names[conf->vartype];
8435 
8436  /* source */
8437  values[8] = GucSource_Names[conf->source];
8438 
8439  /* now get the type specific attributes */
8440  switch (conf->vartype)
8441  {
8442  case PGC_BOOL:
8443  {
8444  struct config_bool *lconf = (struct config_bool *) conf;
8445 
8446  /* min_val */
8447  values[9] = NULL;
8448 
8449  /* max_val */
8450  values[10] = NULL;
8451 
8452  /* enumvals */
8453  values[11] = NULL;
8454 
8455  /* boot_val */
8456  values[12] = pstrdup(lconf->boot_val ? "on" : "off");
8457 
8458  /* reset_val */
8459  values[13] = pstrdup(lconf->reset_val ? "on" : "off");
8460  }
8461  break;
8462 
8463  case PGC_INT:
8464  {
8465  struct config_int *lconf = (struct config_int *) conf;
8466 
8467  /* min_val */
8468  snprintf(buffer, sizeof(buffer), "%d", lconf->min);
8469  values[9] = pstrdup(buffer);
8470 
8471  /* max_val */
8472  snprintf(buffer, sizeof(buffer), "%d", lconf->max);
8473  values[10] = pstrdup(buffer);
8474 
8475  /* enumvals */
8476  values[11] = NULL;
8477 
8478  /* boot_val */
8479  snprintf(buffer, sizeof(buffer), "%d", lconf->boot_val);
8480  values[12] = pstrdup(buffer);
8481 
8482  /* reset_val */
8483  snprintf(buffer, sizeof(buffer), "%d", lconf->reset_val);
8484  values[13] = pstrdup(buffer);
8485  }
8486  break;
8487 
8488  case PGC_REAL:
8489  {
8490  struct config_real *lconf = (struct config_real *) conf;
8491 
8492  /* min_val */
8493  snprintf(buffer, sizeof(buffer), "%g", lconf->min);
8494  values[9] = pstrdup(buffer);
8495 
8496  /* max_val */
8497  snprintf(buffer, sizeof(buffer), "%g", lconf->max);
8498  values[10] = pstrdup(buffer);
8499 
8500  /* enumvals */
8501  values[11] = NULL;
8502 
8503  /* boot_val */
8504  snprintf(buffer, sizeof(buffer), "%g", lconf->boot_val);
8505  values[12] = pstrdup(buffer);
8506 
8507  /* reset_val */
8508  snprintf(buffer, sizeof(buffer), "%g", lconf->reset_val);
8509  values[13] = pstrdup(buffer);
8510  }
8511  break;
8512 
8513  case PGC_STRING:
8514  {
8515  struct config_string *lconf = (struct config_string *) conf;
8516 
8517  /* min_val */
8518  values[9] = NULL;
8519 
8520  /* max_val */
8521  values[10] = NULL;
8522 
8523  /* enumvals */
8524  values[11] = NULL;
8525 
8526  /* boot_val */
8527  if (lconf->boot_val == NULL)
8528  values[12] = NULL;
8529  else
8530  values[12] = pstrdup(lconf->boot_val);
8531 
8532  /* reset_val */
8533  if (lconf->reset_val == NULL)
8534  values[13] = NULL;
8535  else
8536  values[13] = pstrdup(lconf->reset_val);
8537  }
8538  break;
8539 
8540  case PGC_ENUM:
8541  {
8542  struct config_enum *lconf = (struct config_enum *) conf;
8543 
8544  /* min_val */
8545  values[9] = NULL;
8546 
8547  /* max_val */
8548  values[10] = NULL;
8549 
8550  /* enumvals */
8551 
8552  /*
8553  * NOTE! enumvals with double quotes in them are not
8554  * supported!
8555  */
8556  values[11] = config_enum_get_options((struct config_enum *) conf,
8557  "{\"", "\"}", "\",\"");
8558 
8559  /* boot_val */
8561  lconf->boot_val));
8562 
8563  /* reset_val */
8565  lconf->reset_val));
8566  }
8567  break;
8568 
8569  default:
8570  {
8571  /*
8572  * should never get here, but in case we do, set 'em to NULL
8573  */
8574 
8575  /* min_val */
8576  values[9] = NULL;
8577 
8578  /* max_val */
8579  values[10] = NULL;
8580 
8581  /* enumvals */
8582  values[11] = NULL;
8583 
8584  /* boot_val */
8585  values[12] = NULL;
8586 
8587  /* reset_val */
8588  values[13] = NULL;
8589  }
8590  break;
8591  }
8592 
8593  /*
8594  * If the setting came from a config file, set the source location. For
8595  * security reasons, we don't show source file/line number for
8596  * insufficiently-privileged users.
8597  */
8598  if (conf->source == PGC_S_FILE &&
8599  is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
8600  {
8601  values[14] = conf->sourcefile;
8602  snprintf(buffer, sizeof(buffer), "%d", conf->sourceline);
8603  values[15] = pstrdup(buffer);
8604  }
8605  else
8606  {
8607  values[14] = NULL;
8608  values[15] = NULL;
8609  }
8610 
8611  values[16] = (conf->status & GUC_PENDING_RESTART) ? "t" : "f";
8612 }
GucSource source
Definition: guc_tables.h:156
static char * _ShowOption(struct config_generic *record, bool use_units)
Definition: guc.c:8914
const char * long_desc
Definition: guc_tables.h:151
double reset_val
Definition: guc_tables.h:220
Oid GetUserId(void)
Definition: miscinit.c:379
const char * name
Definition: guc_tables.h:147
const char *const config_type_names[]
Definition: guc.c:677
char * pstrdup(const char *in)
Definition: mcxt.c:1161
const char * short_desc
Definition: guc_tables.h:150
int boot_val
Definition: guc_tables.h:197
const char * boot_val
Definition: guc_tables.h:229
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5861
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define GUC_UNIT_KB
Definition: guc.h:218
#define GUC_UNIT_BLOCKS
Definition: guc.h:219
#define GUC_NO_SHOW_ALL
Definition: guc.h:206
const char *const GucContext_Names[]
Definition: guc.c:531
#define GUC_UNIT_MIN
Definition: guc.h:227
const char *const config_group_names[]
Definition: guc.c:568
#define ERROR
Definition: elog.h:43
#define GUC_UNIT_XBLOCKS
Definition: guc.h:220
#define GUC_UNIT_BYTE
Definition: guc.h:222
static int num_guc_variables
Definition: guc.c:4181
#define GUC_UNIT_S
Definition: guc.h:226
char * sourcefile
Definition: guc_tables.h:162
bool boot_val
Definition: guc_tables.h:183
static struct config_generic ** guc_variables
Definition: guc.c:4178
enum config_type vartype
Definition: guc_tables.h:154
#define GUC_UNIT_TIME
Definition: guc.h:228
double max
Definition: guc_tables.h:215
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4857
char * reset_val
Definition: guc_tables.h:234
double boot_val
Definition: guc_tables.h:213
#define Assert(condition)
Definition: c.h:699
#define GUC_UNIT_MB
Definition: guc.h:221
#define GUC_PENDING_RESTART
Definition: guc_tables.h:173
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:215
double min
Definition: guc_tables.h:214
static Datum values[MAXATTR]
Definition: bootstrap.c:164
enum config_group group
Definition: guc_tables.h:149
#define elog
Definition: elog.h:219
bool reset_val
Definition: guc_tables.h:188
const char *const GucSource_Names[]
Definition: guc.c:547
static char * config_enum_get_options(struct config_enum *record, const char *prefix, const char *suffix, const char *separator)
Definition: guc.c:5910
#define GUC_UNIT_MS
Definition: guc.h:225
GucContext context
Definition: guc_tables.h:148
#define GUC_UNIT_MEMORY
Definition: guc.h:223
int reset_val
Definition: guc_tables.h:204

◆ GetConfigOptionFlags()

int GetConfigOptionFlags ( const char *  name,
bool  missing_ok 
)

Definition at line 7046 of file guc.c.

References ereport, errcode(), errmsg(), ERROR, find_option(), config_generic::flags, and WARNING.

Referenced by pg_get_functiondef().

7047 {
7048  struct config_generic *record;
7049 
7050  record = find_option(name, false, WARNING);
7051  if (record == NULL)
7052  {
7053  if (missing_ok)
7054  return 0;
7055  ereport(ERROR,
7056  (errcode(ERRCODE_UNDEFINED_OBJECT),
7057  errmsg("unrecognized configuration parameter \"%s\"",
7058  name)));
7059  }
7060  return record->flags;
7061 }
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define WARNING
Definition: elog.h:40
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4615
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ GetConfigOptionResetString()

const char* GetConfigOptionResetString ( const char *  name)

Definition at line 6997 of file guc.c.

References buffer, config_enum_lookup_by_value(), ereport, errcode(), errmsg(), ERROR, find_option(), config_generic::flags, GetUserId(), GUC_SUPERUSER_ONLY, is_member_of_role(), PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_STRING, snprintf(), and config_generic::vartype.

Referenced by check_datestyle().

6998 {
6999  struct config_generic *record;
7000  static char buffer[256];
7001 
7002  record = find_option(name, false, ERROR);
7003  if (record == NULL)
7004  ereport(ERROR,
7005  (errcode(ERRCODE_UNDEFINED_OBJECT),
7006  errmsg("unrecognized configuration parameter \"%s\"", name)));
7007  if ((record->flags & GUC_SUPERUSER_ONLY) &&
7008  !is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
7009  ereport(ERROR,
7010  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7011  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
7012  name)));
7013 
7014  switch (record->vartype)
7015  {
7016  case PGC_BOOL:
7017  return ((struct config_bool *) record)->reset_val ? "on" : "off";
7018 
7019  case PGC_INT:
7020  snprintf(buffer, sizeof(buffer), "%d",
7021  ((struct config_int *) record)->reset_val);
7022  return buffer;
7023 
7024  case PGC_REAL:
7025  snprintf(buffer, sizeof(buffer), "%g",
7026  ((struct config_real *) record)->reset_val);
7027  return buffer;
7028 
7029  case PGC_STRING:
7030  return ((struct config_string *) record)->reset_val;
7031 
7032  case PGC_ENUM:
7033  return config_enum_lookup_by_value((struct config_enum *) record,
7034  ((struct config_enum *) record)->reset_val);
7035  }
7036  return NULL;
7037 }
Oid GetUserId(void)
Definition: miscinit.c:379
int errcode(int sqlerrcode)
Definition: elog.c:575
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5861
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
enum config_type vartype
Definition: guc_tables.h:154
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4857
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4615
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:215
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ GetNumConfigOptions()

int GetNumConfigOptions ( void  )

Definition at line 8618 of file guc.c.

References num_guc_variables.

Referenced by GucInfoMain(), and show_all_settings().

8619 {
8620  return num_guc_variables;
8621 }
static int num_guc_variables
Definition: guc.c:4181

◆ GetPGVariable()

void GetPGVariable ( const char *  name,
DestReceiver dest 
)

Definition at line 8171 of file guc.c.

References guc_name_compare(), ShowAllGUCConfig(), and ShowGUCConfigOption().

Referenced by exec_replication_command(), and standard_ProcessUtility().

8172 {
8173  if (guc_name_compare(name, "all") == 0)
8174  ShowAllGUCConfig(dest);
8175  else
8176  ShowGUCConfigOption(name, dest);
8177 }
static void ShowGUCConfigOption(const char *name, DestReceiver *dest)
Definition: guc.c:8215
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:4676
static void ShowAllGUCConfig(DestReceiver *dest)
Definition: guc.c:8243
const char * name
Definition: encode.c:521

◆ GetPGVariableResultDesc()

TupleDesc GetPGVariableResultDesc ( const char *  name)

Definition at line 8180 of file guc.c.

References CreateTemplateTupleDesc(), GetConfigOptionByName(), guc_name_compare(), and TupleDescInitEntry().

Referenced by UtilityTupleDescriptor().

8181 {
8182  TupleDesc tupdesc;
8183 
8184  if (guc_name_compare(name, "all") == 0)
8185  {
8186  /* need a tuple descriptor representing three TEXT columns */
8187  tupdesc = CreateTemplateTupleDesc(3, false);
8188  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
8189  TEXTOID, -1, 0);
8190  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
8191  TEXTOID, -1, 0);
8192  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
8193  TEXTOID, -1, 0);
8194  }
8195  else
8196  {
8197  const char *varname;
8198 
8199  /* Get the canonical spelling of name */
8200  (void) GetConfigOptionByName(name, &varname, false);
8201 
8202  /* need a tuple descriptor representing a single TEXT column */
8203  tupdesc = CreateTemplateTupleDesc(1, false);
8204  TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
8205  TEXTOID, -1, 0);
8206  }
8207  return tupdesc;
8208 }
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:4676
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:8312
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:600
TupleDesc CreateTemplateTupleDesc(int natts, bool hasoid)
Definition: tupdesc.c:45
const char * name
Definition: encode.c:521
int16 AttrNumber
Definition: attnum.h:21

◆ GUC_check_errcode()

void GUC_check_errcode ( int  sqlerrcode)

Definition at line 10049 of file guc.c.

References GUC_check_errcode_value.

Referenced by check_client_encoding(), check_role(), check_synchronous_standby_names(), check_transaction_deferrable(), check_transaction_read_only(), and check_XactIsoLevel().

10050 {
10051  GUC_check_errcode_value = sqlerrcode;
10052 }
static int GUC_check_errcode_value
Definition: guc.c:129

◆ GUCArrayAdd()

ArrayType* GUCArrayAdd ( ArrayType array,
const char *  name,
const char *  value 
)

Definition at line 9746 of file guc.c.

References ARR_DIMS, ARR_ELEMTYPE, ARR_LBOUND, ARR_NDIM, array_ref(), array_set(), Assert, construct_array(), CStringGetTextDatum, find_option(), i, config_generic::name, newval, psprintf(), TextDatumGetCString, validate_option_array_item(), and WARNING.

Referenced by AlterSetting(), and update_proconfig_value().

9747 {
9748  struct config_generic *record;
9749  Datum datum;
9750  char *newval;
9751  ArrayType *a;
9752 
9753  Assert(name);
9754  Assert(value);
9755 
9756  /* test if the option is valid and we're allowed to set it */
9757  (void) validate_option_array_item(name, value, false);
9758 
9759  /* normalize name (converts obsolete GUC names to modern spellings) */
9760  record = find_option(name, false, WARNING);
9761  if (record)
9762  name = record->name;
9763 
9764  /* build new item for array */
9765  newval = psprintf("%s=%s", name, value);
9766  datum = CStringGetTextDatum(newval);
9767 
9768  if (array)
9769  {
9770  int index;
9771  bool isnull;
9772  int i;
9773 
9774  Assert(ARR_ELEMTYPE(array) == TEXTOID);
9775  Assert(ARR_NDIM(array) == 1);
9776  Assert(ARR_LBOUND(array)[0] == 1);
9777 
9778  index = ARR_DIMS(array)[0] + 1; /* add after end */
9779 
9780  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9781  {
9782  Datum d;
9783  char *current;
9784 
9785  d = array_ref(array, 1, &i,
9786  -1 /* varlenarray */ ,
9787  -1 /* TEXT's typlen */ ,
9788  false /* TEXT's typbyval */ ,
9789  'i' /* TEXT's typalign */ ,
9790  &isnull);
9791  if (isnull)
9792  continue;
9793  current = TextDatumGetCString(d);
9794 
9795  /* check for match up through and including '=' */
9796  if (strncmp(current, newval, strlen(name) + 1) == 0)
9797  {
9798  index = i;
9799  break;
9800  }
9801  }
9802 
9803  a = array_set(array, 1, &index,
9804  datum,
9805  false,
9806  -1 /* varlena array */ ,
9807  -1 /* TEXT's typlen */ ,
9808  false /* TEXT's typbyval */ ,
9809  'i' /* TEXT's typalign */ );
9810  }
9811  else
9812  a = construct_array(&datum, 1,
9813  TEXTOID,
9814  -1, false, 'i');
9815 
9816  return a;
9817 }
const char * name
Definition: guc_tables.h:147
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3279
ArrayType * array_set(ArrayType *array, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3081
#define ARR_LBOUND(a)
Definition: array.h:281
Definition: type.h:89
static bool validate_option_array_item(const char *name, const char *value, bool skipIfNoPermissions)
Definition: guc.c:9972
#define ARR_DIMS(a)
Definition: array.h:279
Datum array_ref(ArrayType *array, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:3064
#define WARNING
Definition: elog.h:40
#define TextDatumGetCString(d)
Definition: builtins.h:96
uintptr_t Datum
Definition: postgres.h:367
static struct @131 value
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4615
#define Assert(condition)
Definition: c.h:699
#define newval
#define ARR_NDIM(a)
Definition: array.h:275
const char * name
Definition: encode.c:521
int i
#define CStringGetTextDatum(s)
Definition: builtins.h:95
#define ARR_ELEMTYPE(a)
Definition: array.h:277

◆ GUCArrayDelete()

ArrayType* GUCArrayDelete ( ArrayType array,
const char *  name 
)

Definition at line 9826 of file guc.c.

References ARR_DIMS, array_ref(), array_set(), Assert, construct_array(), find_option(), i, config_generic::name, TextDatumGetCString, val, validate_option_array_item(), and WARNING.

Referenced by AlterSetting(), and update_proconfig_value().

9827 {
9828  struct config_generic *record;
9829  ArrayType *newarray;
9830  int i;
9831  int index;
9832 
9833  Assert(name);
9834 
9835  /* test if the option is valid and we're allowed to set it */
9836  (void) validate_option_array_item(name, NULL, false);
9837 
9838  /* normalize name (converts obsolete GUC names to modern spellings) */
9839  record = find_option(name, false, WARNING);
9840  if (record)
9841  name = record->name;
9842 
9843  /* if array is currently null, then surely nothing to delete */
9844  if (!array)
9845  return NULL;
9846 
9847  newarray = NULL;
9848  index = 1;
9849 
9850  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9851  {
9852  Datum d;
9853  char *val;
9854  bool isnull;
9855 
9856  d = array_ref(array, 1, &i,
9857  -1 /* varlenarray */ ,
9858  -1 /* TEXT's typlen */ ,
9859  false /* TEXT's typbyval */ ,
9860  'i' /* TEXT's typalign */ ,
9861  &isnull);
9862  if (isnull)
9863  continue;
9864  val = TextDatumGetCString(d);
9865 
9866  /* ignore entry if it's what we want to delete */
9867  if (strncmp(val, name, strlen(name)) == 0
9868  && val[strlen(name)] == '=')
9869  continue;
9870 
9871  /* else add it to the output array */
9872  if (newarray)
9873  newarray = array_set(newarray, 1, &index,
9874  d,
9875  false,
9876  -1 /* varlenarray */ ,
9877  -1 /* TEXT's typlen */ ,
9878  false /* TEXT's typbyval */ ,
9879  'i' /* TEXT's typalign */ );
9880  else
9881  newarray = construct_array(&d, 1,
9882  TEXTOID,
9883  -1, false, 'i');
9884 
9885  index++;
9886  }
9887 
9888  return newarray;
9889 }
const char * name
Definition: guc_tables.h:147
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3279
ArrayType * array_set(ArrayType *array, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3081
Definition: type.h:89
static bool validate_option_array_item(const char *name, const char *value, bool skipIfNoPermissions)
Definition: guc.c:9972
#define ARR_DIMS(a)
Definition: array.h:279
Datum array_ref(ArrayType *array, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:3064
#define WARNING
Definition: elog.h:40
#define TextDatumGetCString(d)
Definition: builtins.h:96
uintptr_t Datum
Definition: postgres.h:367
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4615
#define Assert(condition)
Definition: c.h:699
const char * name
Definition: encode.c:521
int i
long val
Definition: informix.c:689

◆ GUCArrayReset()

ArrayType* GUCArrayReset ( ArrayType array)

Definition at line 9898 of file guc.c.

References ARR_DIMS, array_ref(), array_set(), construct_array(), i, pfree(), superuser(), TextDatumGetCString, val, and validate_option_array_item().

Referenced by AlterSetting().

9899 {
9900  ArrayType *newarray;
9901  int i;
9902  int index;
9903 
9904  /* if array is currently null, nothing to do */
9905  if (!array)
9906  return NULL;
9907 
9908  /* if we're superuser, we can delete everything, so just do it */
9909  if (superuser())
9910  return NULL;
9911 
9912  newarray = NULL;
9913  index = 1;
9914 
9915  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9916  {
9917  Datum d;
9918  char *val;
9919  char *eqsgn;
9920  bool isnull;
9921 
9922  d = array_ref(array, 1, &i,
9923  -1 /* varlenarray */ ,
9924  -1 /* TEXT's typlen */ ,
9925  false /* TEXT's typbyval */ ,
9926  'i' /* TEXT's typalign */ ,
9927  &isnull);
9928  if (isnull)
9929  continue;
9930  val = TextDatumGetCString(d);
9931 
9932  eqsgn = strchr(val, '=');
9933  *eqsgn = '\0';
9934 
9935  /* skip if we have permission to delete it */
9936  if (validate_option_array_item(val, NULL, true))
9937  continue;
9938 
9939  /* else add it to the output array */
9940  if (newarray)
9941  newarray = array_set(newarray, 1, &index,
9942  d,
9943  false,
9944  -1 /* varlenarray */ ,
9945  -1 /* TEXT's typlen */ ,
9946  false /* TEXT's typbyval */ ,
9947  'i' /* TEXT's typalign */ );
9948  else
9949  newarray = construct_array(&d, 1,
9950  TEXTOID,
9951  -1, false, 'i');
9952 
9953  index++;
9954  pfree(val);
9955  }
9956 
9957  return newarray;
9958 }
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3279
bool superuser(void)
Definition: superuser.c:47
ArrayType * array_set(ArrayType *array, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3081
Definition: type.h:89
void pfree(void *pointer)
Definition: mcxt.c:1031
static bool validate_option_array_item(const char *name, const char *value, bool skipIfNoPermissions)
Definition: guc.c:9972
#define ARR_DIMS(a)
Definition: array.h:279
Datum array_ref(ArrayType *array, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:3064
#define TextDatumGetCString(d)
Definition: builtins.h:96
uintptr_t Datum
Definition: postgres.h:367
int i
long val
Definition: informix.c:689

◆ InitializeGUCOptions()

void InitializeGUCOptions ( void  )

Definition at line 4710 of file guc.c.

References build_guc_variables(), i, InitializeGUCOptionsFromEnvironment(), InitializeOneGUCOption(), num_guc_variables, pg_timezone_initialize(), PGC_POSTMASTER, PGC_S_OVERRIDE, and SetConfigOption().

Referenced by AuxiliaryProcessMain(), BackendRun(), PostgresMain(), and PostmasterMain().

4711 {
4712  int i;
4713 
4714  /*
4715  * Before log_line_prefix could possibly receive a nonempty setting, make
4716  * sure that timezone processing is minimally alive (see elog.c).
4717  */
4719 
4720  /*
4721  * Build sorted array of all GUC variables.
4722  */
4724 
4725  /*
4726  * Load all variables with their compiled-in defaults, and initialize
4727  * status fields as needed.
4728  */
4729  for (i = 0; i < num_guc_variables; i++)
4730  {
4732  }
4733 
4734  guc_dirty = false;
4735 
4736  reporting_enabled = false;
4737 
4738  /*
4739  * Prevent any attempt to override the transaction modes from
4740  * non-interactive sources.
4741  */
4742  SetConfigOption("transaction_isolation", "default",
4744  SetConfigOption("transaction_read_only", "no",
4746  SetConfigOption("transaction_deferrable", "no",
4748 
4749  /*
4750  * For historical reasons, some GUC parameters can receive defaults from
4751  * environment variables. Process those settings.
4752  */
4754 }
void build_guc_variables(void)
Definition: guc.c:4442
static void InitializeGUCOptionsFromEnvironment(void)
Definition: guc.c:4766
void pg_timezone_initialize(void)
Definition: pgtz.c:363
static int num_guc_variables
Definition: guc.c:4181
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:6917
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:4812
static struct config_generic ** guc_variables
Definition: guc.c:4178
int i
static bool reporting_enabled
Definition: guc.c:4189
static bool guc_dirty
Definition: guc.c:4187

◆ NewGUCNestLevel()

◆ parse_int()

bool parse_int ( const char *  value,
int *  result,
int  flags,
const char **  hintmsg 
)

Definition at line 5741 of file guc.c.

References convert_to_base_unit(), gettext_noop, GUC_UNIT, GUC_UNIT_MEMORY, MAX_UNIT_LEN, memory_units_hint, time_units_hint, and val.

Referenced by parse_and_validate_value(), parse_one_reloption(), and readRecoveryCommandFile().

5742 {
5743  int64 val;
5744  char *endptr;
5745 
5746  /* To suppress compiler warnings, always set output params */
5747  if (result)
5748  *result = 0;
5749  if (hintmsg)
5750  *hintmsg = NULL;
5751 
5752  /* We assume here that int64 is at least as wide as long */
5753  errno = 0;
5754  val = strtol(value, &endptr, 0);
5755 
5756  if (endptr == value)
5757  return false; /* no HINT for integer syntax error */
5758 
5759  if (errno == ERANGE || val != (int64) ((int32) val))
5760  {
5761  if (hintmsg)
5762  *hintmsg = gettext_noop("Value exceeds integer range.");
5763  return false;
5764  }
5765 
5766  /* allow whitespace between integer and unit */
5767  while (isspace((unsigned char) *endptr))
5768  endptr++;
5769 
5770  /* Handle possible unit */
5771  if (*endptr != '\0')
5772  {
5773  char unit[MAX_UNIT_LEN + 1];
5774  int unitlen;
5775  bool converted = false;
5776 
5777  if ((flags & GUC_UNIT) == 0)
5778  return false; /* this setting does not accept a unit */
5779 
5780  unitlen = 0;
5781  while (*endptr != '\0' && !isspace((unsigned char) *endptr) &&
5782  unitlen < MAX_UNIT_LEN)
5783  unit[unitlen++] = *(endptr++);
5784  unit[unitlen] = '\0';
5785  /* allow whitespace after unit */
5786  while (isspace((unsigned char) *endptr))
5787  endptr++;
5788 
5789  if (*endptr == '\0')
5790  converted = convert_to_base_unit(val, unit, (flags & GUC_UNIT),
5791  &val);
5792  if (!converted)
5793  {
5794  /* invalid unit, or garbage after the unit; set hint and fail. */
5795  if (hintmsg)
5796  {
5797  if (flags & GUC_UNIT_MEMORY)
5798  *hintmsg = memory_units_hint;
5799  else
5800  *hintmsg = time_units_hint;
5801  }
5802  return false;
5803  }
5804 
5805  /* Check for overflow due to units conversion */
5806  if (val != (int64) ((int32) val))
5807  {
5808  if (hintmsg)
5809  *hintmsg = gettext_noop("Value exceeds integer range.");
5810  return false;
5811  }
5812  }
5813 
5814  if (result)
5815  *result = (int) val;
5816  return true;
5817 }
#define MAX_UNIT_LEN
Definition: guc.c:701
#define gettext_noop(x)
Definition: c.h:1036
#define GUC_UNIT
Definition: guc.h:230
signed int int32
Definition: c.h:313
static const char * time_units_hint
Definition: guc.c:763
static bool convert_to_base_unit(int64 value, const char *unit, int base_unit, int64 *base_value)
Definition: guc.c:5656
static struct @131 value
long val
Definition: informix.c:689
static const char * memory_units_hint
Definition: guc.c:721
#define GUC_UNIT_MEMORY
Definition: guc.h:223

◆ parse_real()

bool parse_real ( const char *  value,
double *  result 
)

Definition at line 5827 of file guc.c.

References val.

Referenced by parse_and_validate_value(), and parse_one_reloption().

5828 {
5829  double val;
5830  char *endptr;
5831 
5832  if (result)
5833  *result = 0; /* suppress compiler warning */
5834 
5835  errno = 0;
5836  val = strtod(value, &endptr);
5837  if (endptr == value || errno == ERANGE)
5838  return false;
5839 
5840  /* allow whitespace after number */
5841  while (isspace((unsigned char) *endptr))
5842  endptr++;
5843  if (*endptr != '\0')
5844  return false;
5845 
5846  if (result)
5847  *result = val;
5848  return true;
5849 }
static struct @131 value
long val
Definition: informix.c:689

◆ ParseConfigDirectory()

bool ParseConfigDirectory ( const char *  includedir,
const char *  calling_file,
int  calling_lineno,
int  depth,
int  elevel,
ConfigVariable **  head_p,
ConfigVariable **  tail_p 
)

◆ ParseConfigFile()

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 
)

◆ ParseConfigFp()

bool ParseConfigFp ( FILE *  fp,
const char *  config_file,
int  depth,
int  elevel,
ConfigVariable **  head_p,
ConfigVariable **  tail_p 
)

◆ ParseLongOption()

void ParseLongOption ( const char *  string,
char **  name,
char **  value 
)

Definition at line 9650 of file guc.c.

References AssertArg, FATAL, guc_malloc(), guc_strdup(), and strlcpy().

Referenced by AuxiliaryProcessMain(), PostmasterMain(), process_postgres_switches(), and ProcessGUCArray().

9651 {
9652  size_t equal_pos;
9653  char *cp;
9654 
9655  AssertArg(string);
9656  AssertArg(name);
9657  AssertArg(value);
9658 
9659  equal_pos = strcspn(string, "=");
9660 
9661  if (string[equal_pos] == '=')
9662  {
9663  *name = guc_malloc(FATAL, equal_pos + 1);
9664  strlcpy(*name, string, equal_pos + 1);
9665 
9666  *value = guc_strdup(FATAL, &string[equal_pos + 1]);
9667  }
9668  else
9669  {
9670  /* no equal sign in string */
9671  *name = guc_strdup(FATAL, string);
9672  *value = NULL;
9673  }
9674 
9675  for (cp = *name; *cp; cp++)
9676  if (*cp == '-')
9677  *cp = '_';
9678 }
static char * guc_strdup(int elevel, const char *src)
Definition: guc.c:4251
#define FATAL
Definition: elog.h:52
#define AssertArg(condition)
Definition: c.h:701
static struct @131 value
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
const char * name
Definition: encode.c:521
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4219

◆ ProcessConfigFile()

◆ ProcessGUCArray()

void ProcessGUCArray ( ArrayType array,
GucContext  context,
GucSource  source,
GucAction  action 
)

Definition at line 9688 of file guc.c.

References ARR_DIMS, ARR_ELEMTYPE, ARR_LBOUND, ARR_NDIM, array_ref(), Assert, ereport, errcode(), errmsg(), free, i, name, ParseLongOption(), pfree(), set_config_option(), TextDatumGetCString, value, and WARNING.

Referenced by ApplySetting(), fmgr_security_definer(), and ProcedureCreate().

9690 {
9691  int i;
9692 
9693  Assert(array != NULL);
9694  Assert(ARR_ELEMTYPE(array) == TEXTOID);
9695  Assert(ARR_NDIM(array) == 1);
9696  Assert(ARR_LBOUND(array)[0] == 1);
9697 
9698  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9699  {
9700  Datum d;
9701  bool isnull;
9702  char *s;
9703  char *name;
9704  char *value;
9705 
9706  d = array_ref(array, 1, &i,
9707  -1 /* varlenarray */ ,
9708  -1 /* TEXT's typlen */ ,
9709  false /* TEXT's typbyval */ ,
9710  'i' /* TEXT's typalign */ ,
9711  &isnull);
9712 
9713  if (isnull)
9714  continue;
9715 
9716  s = TextDatumGetCString(d);
9717 
9718  ParseLongOption(s, &name, &value);
9719  if (!value)
9720  {
9721  ereport(WARNING,
9722  (errcode(ERRCODE_SYNTAX_ERROR),
9723  errmsg("could not parse setting for parameter \"%s\"",
9724  name)));
9725  free(name);
9726  continue;
9727  }
9728 
9729  (void) set_config_option(name, value,
9730  context, source,
9731  action, true, 0, false);
9732 
9733  free(name);
9734  if (value)
9735  free(value);
9736  pfree(s);
9737  }
9738 }
GucSource source
Definition: guc_tables.h:156
void ParseLongOption(const char *string, char **name, char **value)
Definition: guc.c:9650
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ARR_LBOUND(a)
Definition: array.h:281
void pfree(void *pointer)
Definition: mcxt.c:1031
#define ARR_DIMS(a)
Definition: array.h:279
#define ereport(elevel, rest)
Definition: elog.h:122
Datum array_ref(ArrayType *array, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:3064
#define WARNING
Definition: elog.h:40
#define TextDatumGetCString(d)
Definition: builtins.h:96
uintptr_t Datum
Definition: postgres.h:367
static struct @131 value
#define free(a)
Definition: header.h:65
#define Assert(condition)
Definition: c.h:699
#define ARR_NDIM(a)
Definition: array.h:275
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
int set_config_option(const char *name, const char *value, GucContext context, GucSource source, GucAction action, bool changeVal, int elevel, bool is_reload)
Definition: guc.c:6152
#define ARR_ELEMTYPE(a)
Definition: array.h:277
GucContext context
Definition: guc_tables.h:148

◆ ResetAllOptions()

void ResetAllOptions ( void  )

Definition at line 5107 of file guc.c.

References config_bool::assign_hook, config_int::assign_hook, config_real::assign_hook, config_string::assign_hook, config_enum::assign_hook, config_generic::context, config_generic::extra, config_generic::flags, config_bool::gen, config_int::gen, config_real::gen, config_string::gen, config_enum::gen, GUC_ACTION_SET, GUC_NO_RESET_ALL, GUC_REPORT, i, num_guc_variables, PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_S_OVERRIDE, PGC_STRING, PGC_SUSET, PGC_USERSET, push_old_value(), ReportGUCOption(), config_bool::reset_extra, config_int::reset_extra, config_real::reset_extra, config_string::reset_extra, config_enum::reset_extra, config_generic::reset_scontext, config_generic::reset_source, config_bool::reset_val, config_int::reset_val, config_real::reset_val, config_string::reset_val, config_enum::reset_val, config_generic::scontext, set_extra_field(), set_string_field(), config_generic::source, config_bool::variable, config_int::variable, config_real::variable, config_string::variable, config_enum::variable, and config_generic::vartype.

Referenced by DiscardAll(), and ExecSetVariableStmt().

5108 {
5109  int i;
5110 
5111  for (i = 0; i < num_guc_variables; i++)
5112  {
5113  struct config_generic *gconf = guc_variables[i];
5114 
5115  /* Don't reset non-SET-able values */
5116  if (gconf->context != PGC_SUSET &&
5117  gconf->context != PGC_USERSET)
5118  continue;
5119  /* Don't reset if special exclusion from RESET ALL */
5120  if (gconf->flags & GUC_NO_RESET_ALL)
5121  continue;
5122  /* No need to reset if wasn't SET */
5123  if (gconf->source <= PGC_S_OVERRIDE)
5124  continue;
5125 
5126  /* Save old value to support transaction abort */
5128 
5129  switch (gconf->vartype)
5130  {
5131  case PGC_BOOL:
5132  {
5133  struct config_bool *conf = (struct config_bool *) gconf;
5134 
5135  if (conf->assign_hook)
5136  conf->assign_hook(conf->reset_val,
5137  conf->reset_extra);
5138  *conf->variable = conf->reset_val;
5139  set_extra_field(&conf->gen, &conf->gen.extra,
5140  conf->reset_extra);
5141  break;
5142  }
5143  case PGC_INT:
5144  {
5145  struct config_int *conf = (struct config_int *) gconf;
5146 
5147  if (conf->assign_hook)
5148  conf->assign_hook(conf->reset_val,
5149  conf->reset_extra);
5150  *conf->variable = conf->reset_val;
5151  set_extra_field(&conf->gen, &conf->gen.extra,
5152  conf->reset_extra);
5153  break;
5154  }
5155  case PGC_REAL:
5156  {
5157  struct config_real *conf = (struct config_real *) gconf;
5158 
5159  if (conf->assign_hook)
5160  conf->assign_hook(conf->reset_val,
5161  conf->reset_extra);
5162  *conf->variable = conf->reset_val;
5163  set_extra_field(&conf->gen, &conf->gen.extra,
5164  conf->reset_extra);
5165  break;
5166  }
5167  case PGC_STRING:
5168  {
5169  struct config_string *conf = (struct config_string *) gconf;
5170 
5171  if (conf->assign_hook)
5172  conf->assign_hook(conf->reset_val,
5173  conf->reset_extra);
5174  set_string_field(conf, conf->variable, conf->reset_val);
5175  set_extra_field(&conf->gen, &conf->gen.extra,
5176  conf->reset_extra);
5177  break;
5178  }
5179  case PGC_ENUM:
5180  {
5181  struct config_enum *conf = (struct config_enum *) gconf;
5182 
5183  if (conf->assign_hook)
5184  conf->assign_hook(conf->reset_val,
5185  conf->reset_extra);
5186  *conf->variable = conf->reset_val;
5187  set_extra_field(&conf->gen, &conf->gen.extra,
5188  conf->reset_extra);
5189  break;
5190  }
5191  }
5192 
5193  gconf->source = gconf->reset_source;
5194  gconf->scontext = gconf->reset_scontext;
5195 
5196  if (gconf->flags & GUC_REPORT)
5197  ReportGUCOption(gconf);
5198  }
5199 }
GucSource source
Definition: guc_tables.h:156
void * reset_extra
Definition: guc_tables.h:205
GucRealAssignHook assign_hook
Definition: guc_tables.h:217
double reset_val
Definition: guc_tables.h:220
#define GUC_NO_RESET_ALL
Definition: guc.h:207
char ** variable
Definition: guc_tables.h:228
bool * variable
Definition: guc_tables.h:182
GucEnumAssignHook assign_hook
Definition: guc_tables.h:246
GucBoolAssignHook assign_hook
Definition: guc_tables.h:185
GucContext scontext
Definition: guc_tables.h:158
GucIntAssignHook assign_hook
Definition: guc_tables.h:201
static void push_old_value(struct config_generic *gconf, GucAction action)
Definition: guc.c:5207
int * variable
Definition: guc_tables.h:196
int * variable
Definition: guc_tables.h:242
static int num_guc_variables
Definition: guc.c:4181
void * reset_extra
Definition: guc_tables.h:250
Definition: guc.h:75
static void set_extra_field(struct config_generic *gconf, void **field, void *newval)
Definition: guc.c:4352
GucSource reset_source
Definition: guc_tables.h:157
struct config_generic gen
Definition: guc_tables.h:180
struct config_generic gen
Definition: guc_tables.h:194
#define GUC_REPORT
Definition: guc.h:208
double * variable
Definition: guc_tables.h:212
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4291
static struct config_generic ** guc_variables
Definition: guc.c:4178
enum config_type vartype
Definition: guc_tables.h:154
void * reset_extra
Definition: guc_tables.h:221
struct config_generic gen
Definition: guc_tables.h:240
struct config_generic gen
Definition: guc_tables.h:226
char * reset_val
Definition: guc_tables.h:234
GucStringAssignHook assign_hook
Definition: guc_tables.h:231
void * reset_extra
Definition: guc_tables.h:235
void * reset_extra
Definition: guc_tables.h:189
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:5632
bool reset_val
Definition: guc_tables.h:188
GucContext context
Definition: guc_tables.h:148
struct config_generic gen
Definition: guc_tables.h:210
GucContext reset_scontext
Definition: guc_tables.h:159
int reset_val
Definition: guc_tables.h:204

◆ RestoreGUCState()

void RestoreGUCState ( void *  gucstate)

Definition at line 9590 of file guc.c.

References can_skip_gucvar(), ereport, errcode(), errmsg(), ERROR, GUC_ACTION_SET, i, InitializeOneGUCOption(), num_guc_variables, read_gucstate(), read_gucstate_binary(), set_config_option(), and set_config_sourcefile().

Referenced by ParallelWorkerMain().

9591 {
9592  char *varname,
9593  *varvalue,
9594  *varsourcefile;
9595  int varsourceline;
9596  GucSource varsource;
9597  GucContext varscontext;
9598  char *srcptr = (char *) gucstate;
9599  char *srcend;
9600  Size len;
9601  int i;
9602 
9603  /* See comment at can_skip_gucvar(). */
9604  for (i = 0; i < num_guc_variables; i++)
9605  if (!can_skip_gucvar(guc_variables[i]))
9607 
9608  /* First item is the length of the subsequent data */
9609  memcpy(&len, gucstate, sizeof(len));
9610 
9611  srcptr += sizeof(len);
9612  srcend = srcptr + len;
9613 
9614  while (srcptr < srcend)
9615  {
9616  int result;
9617 
9618  varname = read_gucstate(&srcptr, srcend);
9619  varvalue = read_gucstate(&srcptr, srcend);
9620  varsourcefile = read_gucstate(&srcptr, srcend);
9621  if (varsourcefile[0])
9622  read_gucstate_binary(&srcptr, srcend,
9623  &varsourceline, sizeof(varsourceline));
9624  else
9625  varsourceline = 0;
9626  read_gucstate_binary(&srcptr, srcend,
9627  &varsource, sizeof(varsource));
9628  read_gucstate_binary(&srcptr, srcend,
9629  &varscontext, sizeof(varscontext));
9630 
9631  result = set_config_option(varname, varvalue, varscontext, varsource,
9632  GUC_ACTION_SET, true, ERROR, true);
9633  if (result <= 0)
9634  ereport(ERROR,
9635  (errcode(ERRCODE_INTERNAL_ERROR),
9636  errmsg("parameter \"%s\" could not be set", varname)));
9637  if (varsourcefile[0])
9638  set_config_sourcefile(varname, varsourcefile, varsourceline);
9639  }
9640 }
GucContext
Definition: guc.h:68
static void static void set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
Definition: guc.c:6883
static void read_gucstate_binary(char **srcptr, char *srcend, void *dest, Size size)
Definition: guc.c:9575
int errcode(int sqlerrcode)
Definition: elog.c:575
GucSource
Definition: guc.h:105
#define ERROR
Definition: elog.h:43
static int num_guc_variables
Definition: guc.c:4181
static bool can_skip_gucvar(struct config_generic *gconf)
Definition: guc.c:9266
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:4812
#define ereport(elevel, rest)
Definition: elog.h:122
static struct config_generic ** guc_variables
Definition: guc.c:4178
static char * read_gucstate(char **srcptr, char *srcend)
Definition: guc.c:9552
size_t Size
Definition: c.h:433
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
int set_config_option(const char *name, const char *value, GucContext context, GucSource source, GucAction action, bool changeVal, int elevel, bool is_reload)
Definition: guc.c:6152

◆ SelectConfigFiles()

bool SelectConfigFiles ( const char *  userDoption,
const char *  progname 
)

Definition at line 4932 of file guc.c.

References CONFIG_FILENAME, DataDir, FATAL, free, guc_malloc(), HBA_FILENAME, IDENT_FILENAME, make_absolute_path(), pg_timezone_abbrev_initialize(), PGC_POSTMASTER, PGC_S_OVERRIDE, ProcessConfigFile(), SetConfigOption(), SetDataDir(), stat, strerror(), and write_stderr.

Referenced by AuxiliaryProcessMain(), PostgresMain(), and PostmasterMain().

4933 {
4934  char *configdir;
4935  char *fname;
4936  struct stat stat_buf;
4937 
4938  /* configdir is -D option, or $PGDATA if no -D */
4939  if (userDoption)
4940  configdir = make_absolute_path(userDoption);
4941  else
4942  configdir = make_absolute_path(getenv("PGDATA"));
4943 
4944  if (configdir && stat(configdir, &stat_buf) != 0)
4945  {
4946  write_stderr("%s: could not access directory \"%s\": %s\n",
4947  progname,
4948  configdir,
4949  strerror(errno));
4950  if (errno == ENOENT)
4951  write_stderr("Run initdb or pg_basebackup to initialize a PostgreSQL data directory.\n");
4952  return false;
4953  }
4954 
4955  /*
4956  * Find the configuration file: if config_file was specified on the
4957  * command line, use it, else use configdir/postgresql.conf. In any case
4958  * ensure the result is an absolute path, so that it will be interpreted
4959  * the same way by future backends.
4960  */
4961  if (ConfigFileName)
4963  else if (configdir)
4964  {
4965  fname = guc_malloc(FATAL,
4966  strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
4967  sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
4968  }
4969  else
4970  {
4971  write_stderr("%s does not know where to find the server configuration file.\n"
4972  "You must specify the --config-file or -D invocation "
4973  "option or set the PGDATA environment variable.\n",
4974  progname);
4975  return false;
4976  }
4977 
4978  /*
4979  * Set the ConfigFileName GUC variable to its final value, ensuring that
4980  * it can't be overridden later.
4981  */
4982  SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4983  free(fname);
4984 
4985  /*
4986  * Now read the config file for the first time.
4987  */
4988  if (stat(ConfigFileName, &stat_buf) != 0)
4989  {
4990  write_stderr("%s: could not access the server configuration file \"%s\": %s\n",
4991  progname, ConfigFileName, strerror(errno));
4992  free(configdir);
4993  return false;
4994  }
4995 
4996  /*
4997  * Read the configuration file for the first time. This time only the
4998  * data_directory parameter is picked up to determine the data directory,
4999  * so that we can read the PG_AUTOCONF_FILENAME file next time.
5000  */
5002 
5003  /*
5004  * If the data_directory GUC variable has been set, use that as DataDir;
5005  * otherwise use configdir if set; else punt.
5006  *
5007  * Note: SetDataDir will copy and absolute-ize its argument, so we don't
5008  * have to.
5009  */
5010  if (data_directory)
5012  else if (configdir)
5013  SetDataDir(configdir);
5014  else
5015  {
5016  write_stderr("%s does not know where to find the database system data.\n"
5017  "This can be specified as \"data_directory\" in \"%s\", "
5018  "or by the -D invocation option, or by the "
5019  "PGDATA environment variable.\n",
5021  return false;
5022  }
5023 
5024  /*
5025  * Reflect the final DataDir value back into the data_directory GUC var.
5026  * (If you are wondering why we don't just make them a single variable,
5027  * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
5028  * child backends specially. XXX is that still true? Given that we now
5029  * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
5030  * DataDir in advance.)
5031  */
5033 
5034  /*
5035  * Now read the config file a second time, allowing any settings in the
5036  * PG_AUTOCONF_FILENAME file to take effect. (This is pretty ugly, but
5037  * since we have to determine the DataDir before we can find the autoconf
5038  * file, the alternatives seem worse.)
5039  */
5041 
5042  /*
5043  * If timezone_abbreviations wasn't set in the configuration file, install
5044  * the default value. We do it this way because we can't safely install a
5045  * "real" value until my_exec_path is set, which may not have happened
5046  * when InitializeGUCOptions runs, so the bootstrap default value cannot
5047  * be the real desired default.
5048  */
5050 
5051  /*
5052  * Figure out where pg_hba.conf is, and make sure the path is absolute.
5053  */
5054  if (HbaFileName)
5056  else if (configdir)
5057  {
5058  fname = guc_malloc(FATAL,
5059  strlen(configdir) + strlen(HBA_FILENAME) + 2);
5060  sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
5061  }
5062  else
5063  {
5064  write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
5065  "This can be specified as \"hba_file\" in \"%s\", "
5066  "or by the -D invocation option, or by the "
5067  "PGDATA environment variable.\n",
5069  return false;
5070  }
5071  SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
5072  free(fname);
5073 
5074  /*
5075  * Likewise for pg_ident.conf.
5076  */
5077  if (IdentFileName)
5079  else if (configdir)
5080  {
5081  fname = guc_malloc(FATAL,
5082  strlen(configdir) + strlen(IDENT_FILENAME) + 2);
5083  sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
5084  }
5085  else
5086  {
5087  write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
5088  "This can be specified as \"ident_file\" in \"%s\", "
5089  "or by the -D invocation option, or by the "
5090  "PGDATA environment variable.\n",
5092  return false;
5093  }
5094  SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
5095  free(fname);
5096 
5097  free(configdir);
5098 
5099  return true;
5100 }
char * make_absolute_path(const char *path)
Definition: path.c:608
void ProcessConfigFile(GucContext context)
void SetDataDir(const char *dir)
Definition: miscinit.c:190
char * ConfigFileName
Definition: guc.c:465
static void pg_timezone_abbrev_initialize(void)
Definition: guc.c:10540
#define CONFIG_FILENAME
Definition: guc.c:98
#define write_stderr(str)
Definition: parallel.c:182
const char * progname
Definition: pg_standby.c:37
char * HbaFileName
Definition: guc.c:466
#define HBA_FILENAME
Definition: guc.c:99
struct stat stat_buf
Definition: pg_standby.c:103
#define FATAL
Definition: elog.h:52
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:6917
char * IdentFileName
Definition: guc.c:467
#define stat(a, b)
Definition: win32_port.h:266
#define IDENT_FILENAME
Definition: guc.c:100
#define free(a)
Definition: header.h:65
static const char * userDoption
Definition: postgres.c:161
const char * strerror(int errnum)
Definition: strerror.c:19
char * DataDir
Definition: globals.c:61
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4219
static char * data_directory
Definition: guc.c:510

◆ SerializeGUCState()

void SerializeGUCState ( Size  maxsize,
char *  start_address 
)

Definition at line 9525 of file guc.c.

References Assert, i, num_guc_variables, and serialize_variable().

Referenced by InitializeParallelDSM().

9526 {
9527  char *curptr;
9528  Size actual_size;
9529  Size bytes_left;
9530  int i;
9531 
9532  /* Reserve space for saving the actual size of the guc state */
9533  Assert(maxsize > sizeof(actual_size));
9534  curptr = start_address + sizeof(actual_size);
9535  bytes_left = maxsize - sizeof(actual_size);
9536 
9537  for (i = 0; i < num_guc_variables; i++)
9538  serialize_variable(&curptr, &bytes_left, guc_variables[i]);
9539 
9540  /* Store actual size without assuming alignment of start_address. */
9541  actual_size = maxsize - bytes_left - sizeof(actual_size);
9542  memcpy(start_address, &actual_size, sizeof(actual_size));
9543 }
static void serialize_variable(char **destptr, Size *maxbytes, struct config_generic *gconf)
Definition: guc.c:9451
static int num_guc_variables
Definition: guc.c:4181
static struct config_generic ** guc_variables
Definition: guc.c:4178
#define Assert(condition)
Definition: c.h:699
size_t Size
Definition: c.h:433
int i

◆ set_config_option()

int set_config_option ( const char *  name,
const char *  value,
GucContext  context,
GucSource  source,
GucAction  action,
bool  changeVal,
int  elevel,
bool  is_reload 
)

Definition at line 6152 of file guc.c.

References config_bool::assign_hook, config_int::assign_hook, config_real::assign_hook, config_string::assign_hook, config_enum::assign_hook, config_var_val::boolval, config_bool::boot_val, config_int::boot_val, config_real::boot_val, config_string::boot_val, config_enum::boot_val, call_bool_check_hook(), call_enum_check_hook(), call_int_check_hook(), call_real_check_hook(), call_string_check_hook(), config_generic::context, DEBUG3, elog, config_var_val::enumval, ereport, errcode(), errmsg(), ERROR, config_var_value::extra, config_generic::extra, extra_field_used(), find_option(), config_generic::flags, free, config_bool::gen, config_int::gen, config_real::gen, config_string::gen, config_enum::gen, GUC_ACTION_SAVE, GUC_NOT_WHILE_SEC_REST, GUC_PENDING_RESTART, GUC_REPORT, guc_strdup(), InLocalUserIdChange(), InSecurityRestrictedOperation(), config_var_val::intval, IsInParallelMode(), IsUnderPostmaster, LOG, newval, parse_and_validate_value(), PGC_BACKEND, PGC_BOOL, PGC_ENUM, PGC_INT, PGC_INTERNAL, PGC_POSTMASTER, PGC_REAL, PGC_S_CLIENT, PGC_S_DATABASE, PGC_S_DATABASE_USER, PGC_S_DEFAULT, PGC_S_FILE, PGC_S_GLOBAL, PGC_S_OVERRIDE, PGC_S_USER, PGC_SIGHUP, PGC_STRING, PGC_SU_BACKEND, PGC_SUSET, PGC_USERSET, guc_stack::prev, guc_stack::prior, push_old_value(), config_var_val::realval, ReportGUCOption(), config_bool::reset_extra, config_int::reset_extra, config_real::reset_extra, config_string::reset_extra, config_enum::reset_extra, config_generic::reset_scontext, config_generic::reset_source, config_bool::reset_val, config_int::reset_val, config_real::reset_val, config_string::reset_val, config_enum::reset_val, guc_stack::scontext, config_generic::scontext, set_extra_field(), set_string_field(), guc_stack::source, config_generic::source, config_generic::stack, config_generic::status, string_field_used(), config_var_val::stringval, config_var_value::val, config_bool::variable, config_int::variable, config_real::variable, config_string::variable, config_enum::variable, config_generic::vartype, and WARNING.

Referenced by _ShowOption(), applyRemoteGucs(), define_custom_variable(), ExecSetVariableStmt(), execute_extension_script(), parse_subscription_options(), ProcessGUCArray(), reapply_stacked_values(), RestoreGUCState(), RI_Initial_Check(), set_config_by_name(), set_transmission_modes(), SetConfigOption(), SetPGVariable(), and validate_option_array_item().

6156 {
6157  struct config_generic *record;
6158  union config_var_val newval_union;
6159  void *newextra = NULL;
6160  bool prohibitValueChange = false;
6161  bool makeDefault;
6162 
6163  if (elevel == 0)
6164  {
6165  if (source == PGC_S_DEFAULT || source == PGC_S_FILE)
6166  {
6167  /*
6168  * To avoid cluttering the log, only the postmaster bleats loudly
6169  * about problems with the config file.
6170  */
6172  }
6173  else if (source == PGC_S_GLOBAL ||
6174  source == PGC_S_DATABASE ||
6175  source == PGC_S_USER ||
6176  source == PGC_S_DATABASE_USER)
6177  elevel = WARNING;
6178  else
6179  elevel = ERROR;
6180  }
6181 
6182  /*
6183  * GUC_ACTION_SAVE changes are acceptable during a parallel operation,
6184  * because the current worker will also pop the change. We're probably
6185  * dealing with a function having a proconfig entry. Only the function's
6186  * body should observe the change, and peer workers do not share in the
6187  * execution of a function call started by this worker.
6188  *
6189  * Other changes might need to affect other workers, so forbid them.
6190  */
6191  if (IsInParallelMode() && changeVal && action != GUC_ACTION_SAVE)
6192  ereport(elevel,
6193  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
6194  errmsg("cannot set parameters during a parallel operation")));
6195 
6196  record = find_option(name, true, elevel);
6197  if (record == NULL)
6198  {
6199  ereport(elevel,
6200  (errcode(ERRCODE_UNDEFINED_OBJECT),
6201  errmsg("unrecognized configuration parameter \"%s\"", name)));
6202  return 0;
6203  }
6204 
6205  /*
6206  * Check if the option can be set at this time. See guc.h for the precise
6207  * rules.
6208  */
6209  switch (record->context)
6210  {
6211  case PGC_INTERNAL:
6212  if (context != PGC_INTERNAL)
6213  {
6214  ereport(elevel,
6215  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6216  errmsg("parameter \"%s\" cannot be changed",
6217  name)));
6218  return 0;
6219  }
6220  break;
6221  case PGC_POSTMASTER:
6222  if (context == PGC_SIGHUP)
6223  {
6224  /*
6225  * We are re-reading a PGC_POSTMASTER variable from
6226  * postgresql.conf. We can't change the setting, so we should
6227  * give a warning if the DBA tries to change it. However,
6228  * because of variant formats, canonicalization by check
6229  * hooks, etc, we can't just compare the given string directly
6230  * to what's stored. Set a flag to check below after we have
6231  * the final storable value.
6232  */
6233  prohibitValueChange = true;
6234  }
6235  else if (context != PGC_POSTMASTER)
6236  {
6237  ereport(elevel,
6238  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6239  errmsg("parameter \"%s\" cannot be changed without restarting the server",
6240  name)));
6241  return 0;
6242  }
6243  break;
6244  case PGC_SIGHUP:
6245  if (context != PGC_SIGHUP && context != PGC_POSTMASTER)
6246  {
6247  ereport(elevel,
6248  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6249  errmsg("parameter \"%s\" cannot be changed now",
6250  name)));
6251  return 0;
6252  }
6253 
6254  /*
6255  * Hmm, the idea of the SIGHUP context is "ought to be global, but
6256  * can be changed after postmaster start". But there's nothing
6257  * that prevents a crafty administrator from sending SIGHUP
6258  * signals to individual backends only.
6259  */
6260  break;
6261  case PGC_SU_BACKEND:
6262  /* Reject if we're connecting but user is not superuser */
6263  if (context == PGC_BACKEND)
6264  {
6265  ereport(elevel,
6266  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6267  errmsg("permission denied to set parameter \"%s\"",
6268  name)));
6269  return 0;
6270  }
6271  /* fall through to process the same as PGC_BACKEND */
6272  /* FALLTHROUGH */
6273  case PGC_BACKEND:
6274  if (context == PGC_SIGHUP)
6275  {
6276  /*
6277  * If a PGC_BACKEND or PGC_SU_BACKEND parameter is changed in
6278  * the config file, we want to accept the new value in the
6279  * postmaster (whence it will propagate to
6280  * subsequently-started backends), but ignore it in existing
6281  * backends. This is a tad klugy, but necessary because we
6282  * don't re-read the config file during backend start.
6283  *
6284  * In EXEC_BACKEND builds, this works differently: we load all
6285  * non-default settings from the CONFIG_EXEC_PARAMS file
6286  * during backend start. In that case we must accept
6287  * PGC_SIGHUP settings, so as to have the same value as if
6288  * we'd forked from the postmaster. This can also happen when
6289  * using RestoreGUCState() within a background worker that
6290  * needs to have the same settings as the user backend that
6291  * started it. is_reload will be true when either situation
6292  * applies.
6293  */
6294  if (IsUnderPostmaster && !is_reload)
6295  return -1;
6296  }
6297  else if (context != PGC_POSTMASTER &&
6298  context != PGC_BACKEND &&
6299  context != PGC_SU_BACKEND &&
6300  source != PGC_S_CLIENT)
6301  {
6302  ereport(elevel,
6303  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6304  errmsg("parameter \"%s\" cannot be set after connection start",
6305  name)));
6306  return 0;
6307  }
6308  break;
6309  case PGC_SUSET:
6310  if (context == PGC_USERSET || context == PGC_BACKEND)
6311  {
6312  ereport(elevel,
6313  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6314  errmsg("permission denied to set parameter \"%s\"",
6315  name)));
6316  return 0;
6317  }
6318  break;
6319  case PGC_USERSET:
6320  /* always okay */
6321  break;
6322  }
6323 
6324  /*
6325  * Disallow changing GUC_NOT_WHILE_SEC_REST values if we are inside a
6326  * security restriction context. We can reject this regardless of the GUC
6327  * context or source, mainly because sources that it might be reasonable
6328  * to override for won't be seen while inside a function.
6329  *
6330  * Note: variables marked GUC_NOT_WHILE_SEC_REST should usually be marked
6331  * GUC_NO_RESET_ALL as well, because ResetAllOptions() doesn't check this.
6332  * An exception might be made if the reset value is assumed to be "safe".
6333  *
6334  * Note: this flag is currently used for "session_authorization" and
6335  * "role". We need to prohibit changing these inside a local userid
6336  * context because when we exit it, GUC won't be notified, leaving things
6337  * out of sync. (This could be fixed by forcing a new GUC nesting level,
6338  * but that would change behavior in possibly-undesirable ways.) Also, we
6339  * prohibit changing these in a security-restricted operation because
6340  * otherwise RESET could be used to regain the session user's privileges.
6341  */
6342  if (record->flags & GUC_NOT_WHILE_SEC_REST)
6343  {
6344  if (InLocalUserIdChange())
6345  {
6346  /*
6347  * Phrasing of this error message is historical, but it's the most
6348  * common case.
6349  */
6350  ereport(elevel,
6351  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6352  errmsg("cannot set parameter \"%s\" within security-definer function",
6353  name)));
6354  return 0;
6355  }
6357  {
6358  ereport(elevel,
6359  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6360  errmsg("cannot set parameter \"%s\" within security-restricted operation",
6361  name)));
6362  return 0;
6363  }
6364  }
6365 
6366  /*
6367  * Should we set reset/stacked values? (If so, the behavior is not
6368  * transactional.) This is done either when we get a default value from
6369  * the database's/user's/client's default settings or when we reset a
6370  * value to its default.
6371  */
6372  makeDefault = changeVal && (source <= PGC_S_OVERRIDE) &&
6373  ((value != NULL) || source == PGC_S_DEFAULT);
6374 
6375  /*
6376  * Ignore attempted set if overridden by previously processed setting.
6377  * However, if changeVal is false then plow ahead anyway since we are
6378  * trying to find out if the value is potentially good, not actually use
6379  * it. Also keep going if makeDefault is true, since we may want to set
6380  * the reset/stacked values even if we can't set the variable itself.
6381  */
6382  if (record->source > source)
6383  {
6384  if (changeVal && !makeDefault)
6385  {
6386  elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
6387  name);
6388  return -1;
6389  }
6390  changeVal = false;
6391  }
6392 
6393  /*
6394  * Evaluate value and set variable.
6395  */
6396  switch (record->vartype)
6397  {
6398  case PGC_BOOL:
6399  {
6400  struct config_bool *conf = (struct config_bool *) record;
6401 
6402 #define newval (newval_union.boolval)
6403 
6404  if (value)
6405  {
6406  if (!parse_and_validate_value(record, name, value,
6407  source, elevel,
6408  &newval_union, &newextra))
6409  return 0;
6410  }
6411  else if (source == PGC_S_DEFAULT)
6412  {
6413  newval = conf->boot_val;
6414  if (!call_bool_check_hook(conf, &newval, &newextra,
6415  source, elevel))
6416  return 0;
6417  }
6418  else
6419  {
6420  newval = conf->reset_val;
6421  newextra = conf->reset_extra;
6422  source = conf->gen.reset_source;
6423  context = conf->gen.reset_scontext;
6424  }
6425 
6426  if (prohibitValueChange)
6427  {
6428  if (*conf->variable != newval)
6429  {
6430  record->status |= GUC_PENDING_RESTART;
6431  ereport(elevel,
6432  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6433  errmsg("parameter \"%s\" cannot be changed without restarting the server",
6434  name)));
6435  return 0;
6436  }
6437  record->status &= ~GUC_PENDING_RESTART;
6438  return -1;
6439  }
6440 
6441  if (changeVal)
6442  {
6443  /* Save old value to support transaction abort */
6444  if (!makeDefault)
6445  push_old_value(&conf->gen, action);
6446 
6447  if (conf->assign_hook)
6448  conf->assign_hook(newval, newextra);
6449  *conf->variable = newval;
6450  set_extra_field(&conf->gen, &conf->gen.extra,
6451  newextra);
6452  conf->gen.source = source;
6453  conf->gen.scontext = context;
6454  }
6455  if (makeDefault)
6456  {
6457  GucStack *stack;
6458 
6459  if (conf->gen.reset_source <= source)
6460  {
6461  conf->reset_val = newval;
6462  set_extra_field(&conf->gen, &conf->reset_extra,
6463  newextra);
6464  conf->gen.reset_source = source;
6465  conf->gen.reset_scontext = context;
6466  }
6467  for (stack = conf->gen.stack; stack; stack = stack->prev)
6468  {
6469  if (stack->source <= source)
6470  {
6471  stack->prior.val.boolval = newval;
6472  set_extra_field(&conf->gen, &stack->prior.extra,
6473  newextra);
6474  stack->source = source;
6475  stack->scontext = context;
6476  }
6477  }
6478  }
6479 
6480  /* Perhaps we didn't install newextra anywhere */
6481  if (newextra && !extra_field_used(&conf->gen, newextra))
6482  free(newextra);
6483  break;
6484 
6485 #undef newval
6486  }
6487 
6488  case PGC_INT:
6489  {
6490  struct config_int *conf = (struct config_int *) record;
6491 
6492 #define newval (newval_union.intval)
6493 
6494  if (value)
6495  {
6496  if (!parse_and_validate_value(record, name, value,
6497  source, elevel,
6498  &newval_union, &newextra))
6499  return 0;
6500  }
6501  else if (source == PGC_S_DEFAULT)
6502  {
6503  newval = conf->boot_val;
6504  if (!call_int_check_hook(conf, &newval, &newextra,
6505  source, elevel))
6506  return 0;
6507  }
6508  else
6509  {
6510  newval = conf->reset_val;
6511  newextra = conf->reset_extra;
6512  source = conf->gen.reset_source;
6513  context = conf->gen.reset_scontext;
6514  }
6515 
6516  if (prohibitValueChange)
6517  {
6518  if (*conf->variable != newval)
6519  {
6520  record->status |= GUC_PENDING_RESTART;
6521  ereport(elevel,
6522  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6523  errmsg("parameter \"%s\" cannot be changed without restarting the server",
6524  name)));
6525  return 0;
6526  }
6527  record->status &= ~GUC_PENDING_RESTART;
6528  return -1;
6529  }
6530 
6531  if (changeVal)
6532  {
6533  /* Save old value to support transaction abort */
6534  if (!makeDefault)
6535  push_old_value(&conf->gen, action);
6536 
6537  if (conf->assign_hook)
6538  conf->assign_hook(newval, newextra);
6539  *conf->variable = newval;
6540  set_extra_field(&conf->gen, &conf->gen.extra,
6541  newextra);
6542  conf->gen.source = source;
6543  conf->gen.scontext = context;
6544  }
6545  if (makeDefault)
6546  {
6547  GucStack *stack;
6548 
6549  if (conf->gen.reset_source <= source)
6550  {
6551  conf->reset_val = newval;
6552  set_extra_field(&conf->gen, &conf->reset_extra,
6553  newextra);
6554  conf->gen.reset_source = source;
6555  conf->gen.reset_scontext = context;
6556  }
6557  for (stack = conf->gen.stack; stack; stack = stack->prev)
6558  {
6559  if (stack->source <= source)
6560  {
6561  stack->prior.val.intval = newval;
6562  set_extra_field(&conf->gen, &stack->prior.extra,
6563  newextra);
6564  stack->source = source;
6565  stack->scontext = context;
6566  }
6567  }
6568  }
6569 
6570  /* Perhaps we didn't install newextra anywhere */
6571  if (newextra && !extra_field_used(&conf->gen, newextra))
6572  free(newextra);
6573  break;
6574 
6575 #undef newval
6576  }
6577 
6578  case PGC_REAL:
6579  {
6580  struct config_real *conf = (struct config_real *) record;
6581 
6582 #define newval (newval_union.realval)
6583 
6584  if (value)
6585  {
6586  if (!parse_and_validate_value(record, name, value,
6587  source, elevel,
6588  &newval_union, &newextra))
6589  return 0;
6590  }
6591  else if (source == PGC_S_DEFAULT)
6592  {
6593  newval = conf->boot_val;
6594  if (!call_real_check_hook(conf, &newval, &newextra,
6595  source, elevel))
6596  return 0;
6597  }
6598  else
6599  {
6600  newval = conf->reset_val;
6601  newextra = conf->reset_extra;
6602  source = conf->gen.reset_source;
6603  context = conf->gen.reset_scontext;
6604  }
6605 
6606  if (prohibitValueChange)
6607  {
6608  if (*conf->variable != newval)
6609  {
6610  record->status |= GUC_PENDING_RESTART;
6611  ereport(elevel,
6612  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6613  errmsg("parameter \"%s\" cannot be changed without restarting the server",
6614  name)));
6615  return 0;
6616  }
6617  record->status &= ~GUC_PENDING_RESTART;
6618  return -1;
6619  }
6620 
6621  if (changeVal)
6622  {
6623  /* Save old value to support transaction abort */
6624  if (!makeDefault)
6625  push_old_value(&conf->gen, action);
6626 
6627  if (conf->assign_hook)
6628  conf->assign_hook(newval, newextra);
6629  *conf->variable = newval;
6630  set_extra_field(&conf->gen, &conf->gen.extra,
6631  newextra);
6632  conf->gen.source = source;
6633  conf->gen.scontext = context;
6634  }
6635  if (makeDefault)
6636  {
6637  GucStack *stack;
6638 
6639  if (conf->gen.reset_source <= source)
6640  {
6641  conf->reset_val = newval;
6642  set_extra_field(&conf->gen, &conf->reset_extra,
6643  newextra);
6644  conf->gen.reset_source = source;
6645  conf->gen.reset_scontext = context;
6646  }
6647  for (stack = conf->gen.stack; stack; stack = stack->prev)
6648  {
6649  if (stack->source <= source)
6650  {
6651  stack->prior.val.realval = newval;
6652  set_extra_field(&conf->gen, &stack->prior.extra,
6653  newextra);
6654  stack->source = source;
6655  stack->scontext = context;
6656  }
6657  }
6658  }
6659 
6660  /* Perhaps we didn't install newextra anywhere */
6661  if (newextra && !extra_field_used(&conf->gen, newextra))
6662  free(newextra);
6663  break;
6664 
6665 #undef newval
6666  }
6667 
6668  case PGC_STRING:
6669  {
6670  struct config_string *conf = (struct config_string *) record;
6671 
6672 #define newval (newval_union.stringval)
6673 
6674  if (value)
6675  {
6676  if (!parse_and_validate_value(record, name, value,
6677  source, elevel,
6678  &newval_union, &newextra))
6679  return 0;
6680  }
6681  else if (source == PGC_S_DEFAULT)
6682  {
6683  /* non-NULL boot_val must always get strdup'd */
6684  if (conf->boot_val != NULL)
6685  {
6686  newval = guc_strdup(elevel, conf->boot_val);
6687  if (newval == NULL)
6688  return 0;
6689  }
6690  else
6691  newval = NULL;
6692 
6693  if (!call_string_check_hook(conf, &newval, &newextra,
6694  source, elevel))
6695  {
6696  free(newval);
6697  return 0;
6698  }
6699  }
6700  else
6701  {
6702  /*
6703  * strdup not needed, since reset_val is already under
6704  * guc.c's control
6705  */
6706  newval = conf->reset_val;
6707  newextra = conf->reset_extra;
6708  source = conf->gen.reset_source;
6709  context = conf->gen.reset_scontext;
6710  }
6711 
6712  if (prohibitValueChange)
6713  {
6714  /* newval shouldn't be NULL, so we're a bit sloppy here */
6715  if (*conf->variable == NULL || newval == NULL ||
6716  strcmp(*conf->variable, newval) != 0)
6717  {
6718  record->status |= GUC_PENDING_RESTART;
6719  ereport(elevel,
6720  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6721  errmsg("parameter \"%s\" cannot be changed without restarting the server",
6722  name)));
6723  return 0;
6724  }
6725  record->status &= ~GUC_PENDING_RESTART;
6726  return -1;
6727  }
6728 
6729  if (changeVal)
6730  {
6731  /* Save old value to support transaction abort */
6732  if (!makeDefault)
6733  push_old_value(&conf->gen, action);
6734 
6735  if (conf->assign_hook)
6736  conf->assign_hook(newval, newextra);
6737  set_string_field(conf, conf->variable, newval);
6738  set_extra_field(&conf->gen, &conf->gen.extra,
6739  newextra);
6740  conf->gen.source = source;
6741  conf->gen.scontext = context;
6742  }
6743 
6744  if (makeDefault)
6745  {
6746  GucStack *stack;
6747 
6748  if (conf->gen.reset_source <= source)
6749  {
6750  set_string_field(conf, &conf->reset_val, newval);
6751  set_extra_field(&conf->gen, &conf->reset_extra,
6752  newextra);
6753  conf->gen.reset_source = source;
6754  conf->gen.reset_scontext = context;
6755  }
6756  for (stack = conf->gen.stack; stack; stack = stack->prev)
6757  {
6758  if (stack->source <= source)
6759  {
6760  set_string_field(conf, &stack->prior.val.stringval,
6761  newval);
6762  set_extra_field(&conf->gen, &stack->prior.extra,
6763  newextra);
6764  stack->source = source;
6765  stack->scontext = context;
6766  }
6767  }
6768  }
6769 
6770  /* Perhaps we didn't install newval anywhere */
6771  if (newval && !string_field_used(conf, newval))
6772  free(newval);
6773  /* Perhaps we didn't install newextra anywhere */
6774  if (newextra && !extra_field_used(&conf->gen, newextra))
6775  free(newextra);
6776  break;
6777 
6778 #undef newval
6779  }
6780 
6781  case PGC_ENUM:
6782  {
6783  struct config_enum *conf = (struct config_enum *) record;
6784 
6785 #define newval (newval_union.enumval)
6786 
6787  if (value)
6788  {
6789  if (!parse_and_validate_value(record, name, value,
6790  source, elevel,
6791  &newval_union, &newextra))
6792  return 0;
6793  }
6794  else if (source == PGC_S_DEFAULT)
6795  {
6796  newval = conf->boot_val;
6797  if (!call_enum_check_hook(conf, &newval, &newextra,
6798  source, elevel))
6799  return 0;
6800  }
6801  else
6802  {
6803  newval = conf->reset_val;
6804  newextra = conf->reset_extra;
6805  source = conf->gen.reset_source;
6806  context = conf->