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_superuser)
 
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 7327 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().

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

◆ assign_xlog_sync_method()

void assign_xlog_sync_method ( int  new_sync_method,
void *  extra 
)

Definition at line 10111 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().

10112 {
10113  if (sync_method != new_sync_method)
10114  {
10115  /*
10116  * To ensure that no blocks escape unsynced, force an fsync on the
10117  * currently open log segment (if any). Also, if the open flag is
10118  * changing, close the log file so it will be reopened (with new flag
10119  * bit) at next use.
10120  */
10121  if (openLogFile >= 0)
10122  {
10124  if (pg_fsync(openLogFile) != 0)
10125  ereport(PANIC,
10127  errmsg("could not fsync log segment %s: %m",
10130  if (get_sync_bit(sync_method) != get_sync_bit(new_sync_method))
10131  XLogFileClose();
10132  }
10133  }
10134 }
static int get_sync_bit(int method)
Definition: xlog.c:10055
#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:10187
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 5312 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().

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

References elog, and WARNING.

Referenced by StartTransaction().

5279 {
5280  /*
5281  * The nest level should be 0 between transactions; if it isn't, somebody
5282  * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
5283  * throw a warning but make no other effort to clean up.
5284  */
5285  if (GUCNestLevel != 0)
5286  elog(WARNING, "GUC nest level = %d at transaction start",
5287  GUCNestLevel);
5288  GUCNestLevel = 1;
5289 }
static int GUCNestLevel
Definition: guc.c:4181
#define WARNING
Definition: elog.h:40
#define elog
Definition: elog.h:219

◆ BeginReportingGUCOptions()

void BeginReportingGUCOptions ( void  )

Definition at line 5593 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().

5594 {
5595  int i;
5596 
5597  /*
5598  * Don't do anything unless talking to an interactive frontend of protocol
5599  * 3.0 or later.
5600  */
5601  if (whereToSendOutput != DestRemote ||
5603  return;
5604 
5605  reporting_enabled = true;
5606 
5607  /* Transmit initial values of interesting variables */
5608  for (i = 0; i < num_guc_variables; i++)
5609  {
5610  struct config_generic *conf = guc_variables[i];
5611 
5612  if (conf->flags & GUC_REPORT)
5613  ReportGUCOption(conf);
5614  }
5615 }
#define PG_PROTOCOL_MAJOR(v)
Definition: pqcomm.h:104
static int num_guc_variables
Definition: guc.c:4171
#define GUC_REPORT
Definition: guc.h:208
static struct config_generic ** guc_variables
Definition: guc.c:4168
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:5621
CommandDest whereToSendOutput
Definition: postgres.c:89
static bool reporting_enabled
Definition: guc.c:4179
ProtocolVersion FrontendProtocol
Definition: globals.c:30

◆ 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:88
#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 4807 of file xlog.c.

References XLOGbuffers, and XLOGChooseNumBuffers().

4808 {
4809  /*
4810  * -1 indicates a request for auto-tune.
4811  */
4812  if (*newval == -1)
4813  {
4814  /*
4815  * If we haven't yet changed the boot_val default of -1, just let it
4816  * be. We'll fix it when XLOGShmemSize is called.
4817  */
4818  if (XLOGbuffers == -1)
4819  return true;
4820 
4821  /* Otherwise, substitute the auto-tune value */
4823  }
4824 
4825  /*
4826  * We clamp manually-set values to at least 4 blocks. Prior to PostgreSQL
4827  * 9.1, a minimum of 4 was enforced by guc.c, but since that is no longer
4828  * the case, we just silently treat such values as a request for the
4829  * minimum. (We could throw an error instead, but that doesn't seem very
4830  * helpful.)
4831  */
4832  if (*newval < 4)
4833  *newval = 4;
4834 
4835  return true;
4836 }
static int XLOGChooseNumBuffers(void)
Definition: xlog.c:4791
#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 7994 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().

8004 {
8005  struct config_bool *var;
8006 
8007  var = (struct config_bool *)
8008  init_custom_variable(name, short_desc, long_desc, context, flags,
8009  PGC_BOOL, sizeof(struct config_bool));
8010  var->variable = valueAddr;
8011  var->boot_val = bootValue;
8012  var->reset_val = bootValue;
8013  var->check_hook = check_hook;
8014  var->assign_hook = assign_hook;
8015  var->show_hook = show_hook;
8016  define_custom_variable(&var->gen);
8017 }
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:7753
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:7813

◆ 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 8105 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().

8116 {
8117  struct config_enum *var;
8118 
8119  var = (struct config_enum *)
8120  init_custom_variable(name, short_desc, long_desc, context, flags,
8121  PGC_ENUM, sizeof(struct config_enum));
8122  var->variable = valueAddr;
8123  var->boot_val = bootValue;
8124  var->reset_val = bootValue;
8125  var->options = options;
8126  var->check_hook = check_hook;
8127  var->assign_hook = assign_hook;
8128  var->show_hook = show_hook;
8129  define_custom_variable(&var->gen);
8130 }
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:7753
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:7813

◆ 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 8020 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().

8032 {
8033  struct config_int *var;
8034 
8035  var = (struct config_int *)
8036  init_custom_variable(name, short_desc, long_desc, context, flags,
8037  PGC_INT, sizeof(struct config_int));
8038  var->variable = valueAddr;
8039  var->boot_val = bootValue;
8040  var->reset_val = bootValue;
8041  var->min = minValue;
8042  var->max = maxValue;
8043  var->check_hook = check_hook;
8044  var->assign_hook = assign_hook;
8045  var->show_hook = show_hook;
8046  define_custom_variable(&var->gen);
8047 }
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:7753
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7813
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 8050 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().

8062 {
8063  struct config_real *var;
8064 
8065  var = (struct config_real *)
8066  init_custom_variable(name, short_desc, long_desc, context, flags,
8067  PGC_REAL, sizeof(struct config_real));
8068  var->variable = valueAddr;
8069  var->boot_val = bootValue;
8070  var->reset_val = bootValue;
8071  var->min = minValue;
8072  var->max = maxValue;
8073  var->check_hook = check_hook;
8074  var->assign_hook = assign_hook;
8075  var->show_hook = show_hook;
8076  define_custom_variable(&var->gen);
8077 }
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:7753
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:7813
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 8080 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().

8090 {
8091  struct config_string *var;
8092 
8093  var = (struct config_string *)
8094  init_custom_variable(name, short_desc, long_desc, context, flags,
8095  PGC_STRING, sizeof(struct config_string));
8096  var->variable = valueAddr;
8097  var->boot_val = bootValue;
8098  var->check_hook = check_hook;
8099  var->assign_hook = assign_hook;
8100  var->show_hook = show_hook;
8101  define_custom_variable(&var->gen);
8102 }
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:7753
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:7813

◆ EmitWarningsOnPlaceholders()

void EmitWarningsOnPlaceholders ( const char *  className)

Definition at line 8133 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().

8134 {
8135  int classLen = strlen(className);
8136  int i;
8137 
8138  for (i = 0; i < num_guc_variables; i++)
8139  {
8140  struct config_generic *var = guc_variables[i];
8141 
8142  if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
8143  strncmp(className, var->name, classLen) == 0 &&
8144  var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
8145  {
8146  ereport(WARNING,
8147  (errcode(ERRCODE_UNDEFINED_OBJECT),
8148  errmsg("unrecognized configuration parameter \"%s\"",
8149  var->name)));
8150  }
8151  }
8152 }
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:4171
#define ereport(elevel, rest)
Definition: elog.h:122
static struct config_generic ** guc_variables
Definition: guc.c:4168
#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 9365 of file guc.c.

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

Referenced by InitializeParallelDSM().

9366 {
9367  Size size;
9368  int i;
9369 
9370  /* Add space reqd for saving the data size of the guc state */
9371  size = sizeof(Size);
9372 
9373  /* Add up the space needed for each GUC variable */
9374  for (i = 0; i < num_guc_variables; i++)
9375  size = add_size(size,
9377 
9378  return size;
9379 }
static int num_guc_variables
Definition: guc.c:4171
static struct config_generic ** guc_variables
Definition: guc.c:4168
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:9267
int i

◆ ExecSetVariableStmt()

void ExecSetVariableStmt ( VariableSetStmt stmt,
bool  isTopLevel 
)

Definition at line 7541 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().

7542 {
7544 
7545  /*
7546  * Workers synchronize these parameters at the start of the parallel
7547  * operation; then, we block SET during the operation.
7548  */
7549  if (IsInParallelMode())
7550  ereport(ERROR,
7551  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
7552  errmsg("cannot set parameters during a parallel operation")));
7553 
7554  switch (stmt->kind)
7555  {
7556  case VAR_SET_VALUE:
7557  case VAR_SET_CURRENT:
7558  if (stmt->is_local)
7559  WarnNoTransactionBlock(isTopLevel, "SET LOCAL");
7560  (void) set_config_option(stmt->name,
7561  ExtractSetVariableArgs(stmt),
7563  PGC_S_SESSION,
7564  action, true, 0, false);
7565  break;
7566  case VAR_SET_MULTI:
7567 
7568  /*
7569  * Special-case SQL syntaxes. The TRANSACTION and SESSION
7570  * CHARACTERISTICS cases effectively set more than one variable
7571  * per statement. TRANSACTION SNAPSHOT only takes one argument,
7572  * but we put it here anyway since it's a special case and not
7573  * related to any GUC variable.
7574  */
7575  if (strcmp(stmt->name, "TRANSACTION") == 0)
7576  {
7577  ListCell *head;
7578 
7579  WarnNoTransactionBlock(isTopLevel, "SET TRANSACTION");
7580 
7581  foreach(head, stmt->args)
7582  {
7583  DefElem *item = (DefElem *) lfirst(head);
7584 
7585  if (strcmp(item->defname, "transaction_isolation") == 0)
7586  SetPGVariable("transaction_isolation",
7587  list_make1(item->arg), stmt->is_local);
7588  else if (strcmp(item->defname, "transaction_read_only") == 0)
7589  SetPGVariable("transaction_read_only",
7590  list_make1(item->arg), stmt->is_local);
7591  else if (strcmp(item->defname, "transaction_deferrable") == 0)
7592  SetPGVariable("transaction_deferrable",
7593  list_make1(item->arg), stmt->is_local);
7594  else
7595  elog(ERROR, "unexpected SET TRANSACTION element: %s",
7596  item->defname);
7597  }
7598  }
7599  else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
7600  {
7601  ListCell *head;
7602 
7603  foreach(head, stmt->args)
7604  {
7605  DefElem *item = (DefElem *) lfirst(head);
7606 
7607  if (strcmp(item->defname, "transaction_isolation") == 0)
7608  SetPGVariable("default_transaction_isolation",
7609  list_make1(item->arg), stmt->is_local);
7610  else if (strcmp(item->defname, "transaction_read_only") == 0)
7611  SetPGVariable("default_transaction_read_only",
7612  list_make1(item->arg), stmt->is_local);
7613  else if (strcmp(item->defname, "transaction_deferrable") == 0)
7614  SetPGVariable("default_transaction_deferrable",
7615  list_make1(item->arg), stmt->is_local);
7616  else
7617  elog(ERROR, "unexpected SET SESSION element: %s",
7618  item->defname);
7619  }
7620  }
7621  else if (strcmp(stmt->name, "TRANSACTION SNAPSHOT") == 0)
7622  {
7623  A_Const *con = linitial_node(A_Const, stmt->args);
7624 
7625  if (stmt->is_local)
7626  ereport(ERROR,
7627  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7628  errmsg("SET LOCAL TRANSACTION SNAPSHOT is not implemented")));
7629 
7630  WarnNoTransactionBlock(isTopLevel, "SET TRANSACTION");
7631  Assert(nodeTag(&con->val) == T_String);
7632  ImportSnapshot(strVal(&con->val));
7633  }
7634  else
7635  elog(ERROR, "unexpected SET MULTI element: %s",
7636  stmt->name);
7637  break;
7638  case VAR_SET_DEFAULT:
7639  if (stmt->is_local)
7640  WarnNoTransactionBlock(isTopLevel, "SET LOCAL");
7641  /* fall through */
7642  case VAR_RESET:
7643  if (strcmp(stmt->name, "transaction_isolation") == 0)
7644  WarnNoTransactionBlock(isTopLevel, "RESET TRANSACTION");
7645 
7646  (void) set_config_option(stmt->name,
7647  NULL,
7649  PGC_S_SESSION,
7650  action, true, 0, false);
7651  break;
7652  case VAR_RESET_ALL:
7653  ResetAllOptions();
7654  break;
7655  }
7656 }
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:5097
#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:522
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:7665
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:6141
void SetPGVariable(const char *name, List *args, bool is_local)
Definition: guc.c:7685

◆ ExtractSetVariableArgs()

char* ExtractSetVariableArgs ( VariableSetStmt stmt)

Definition at line 7665 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().

7666 {
7667  switch (stmt->kind)
7668  {
7669  case VAR_SET_VALUE:
7670  return flatten_set_variable_args(stmt->name, stmt->args);
7671  case VAR_SET_CURRENT:
7672  return GetConfigOptionByName(stmt->name, NULL, false);
7673  default:
7674  return NULL;
7675  }
7676 }
VariableSetKind kind
Definition: parsenodes.h:1984
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:8300
static char * flatten_set_variable_args(const char *name, List *args)
Definition: guc.c:7064

◆ FreeConfigVariables()

◆ GetConfigOption()

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

Definition at line 6929 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().

6930 {
6931  struct config_generic *record;
6932  static char buffer[256];
6933 
6934  record = find_option(name, false, ERROR);
6935  if (record == NULL)
6936  {
6937  if (missing_ok)
6938  return NULL;
6939  ereport(ERROR,
6940  (errcode(ERRCODE_UNDEFINED_OBJECT),
6941  errmsg("unrecognized configuration parameter \"%s\"",
6942  name)));
6943  }
6944  if (restrict_superuser &&
6945  (record->flags & GUC_SUPERUSER_ONLY) &&
6946  !is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
6947  ereport(ERROR,
6948  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6949  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
6950  name)));
6951 
6952  switch (record->vartype)
6953  {
6954  case PGC_BOOL:
6955  return *((struct config_bool *) record)->variable ? "on" : "off";
6956 
6957  case PGC_INT:
6958  snprintf(buffer, sizeof(buffer), "%d",
6959  *((struct config_int *) record)->variable);
6960  return buffer;
6961 
6962  case PGC_REAL:
6963  snprintf(buffer, sizeof(buffer), "%g",
6964  *((struct config_real *) record)->variable);
6965  return buffer;
6966 
6967  case PGC_STRING:
6968  return *((struct config_string *) record)->variable;
6969 
6970  case PGC_ENUM:
6971  return config_enum_lookup_by_value((struct config_enum *) record,
6972  *((struct config_enum *) record)->variable);
6973  }
6974  return NULL;
6975 }
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:5850
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:4605
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 8300 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().

8301 {
8302  struct config_generic *record;
8303 
8304  record = find_option(name, false, ERROR);
8305  if (record == NULL)
8306  {
8307  if (missing_ok)
8308  {
8309  if (varname)
8310  *varname = NULL;
8311  return NULL;
8312  }
8313 
8314  ereport(ERROR,
8315  (errcode(ERRCODE_UNDEFINED_OBJECT),
8316  errmsg("unrecognized configuration parameter \"%s\"", name)));
8317  }
8318 
8319  if ((record->flags & GUC_SUPERUSER_ONLY) &&
8320  !is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
8321  ereport(ERROR,
8322  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
8323  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
8324  name)));
8325 
8326  if (varname)
8327  *varname = record->name;
8328 
8329  return _ShowOption(record, true);
8330 }
static char * _ShowOption(struct config_generic *record, bool use_units)
Definition: guc.c:8901
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:4605
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 8337 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, superuser(), and config_generic::vartype.

Referenced by show_all_settings().

8338 {
8339  char buffer[256];
8340  struct config_generic *conf;
8341 
8342  /* check requested variable number valid */
8343  Assert((varnum >= 0) && (varnum < num_guc_variables));
8344 
8345  conf = guc_variables[varnum];
8346 
8347  if (noshow)
8348  {
8349  if ((conf->flags & GUC_NO_SHOW_ALL) ||
8350  ((conf->flags & GUC_SUPERUSER_ONLY) &&
8351  !is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS)))
8352  *noshow = true;
8353  else
8354  *noshow = false;
8355  }
8356 
8357  /* first get the generic attributes */
8358 
8359  /* name */
8360  values[0] = conf->name;
8361 
8362  /* setting : use _ShowOption in order to avoid duplicating the logic */
8363  values[1] = _ShowOption(conf, false);
8364 
8365  /* unit */
8366  if (conf->vartype == PGC_INT)
8367  {
8368  switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
8369  {
8370  case GUC_UNIT_BYTE:
8371  values[2] = "B";
8372  break;
8373  case GUC_UNIT_KB:
8374  values[2] = "kB";
8375  break;
8376  case GUC_UNIT_MB:
8377  values[2] = "MB";
8378  break;
8379  case GUC_UNIT_BLOCKS:
8380  snprintf(buffer, sizeof(buffer), "%dkB", BLCKSZ / 1024);
8381  values[2] = pstrdup(buffer);
8382  break;
8383  case GUC_UNIT_XBLOCKS:
8384  snprintf(buffer, sizeof(buffer), "%dkB", XLOG_BLCKSZ / 1024);
8385  values[2] = pstrdup(buffer);
8386  break;
8387  case GUC_UNIT_MS:
8388  values[2] = "ms";
8389  break;
8390  case GUC_UNIT_S:
8391  values[2] = "s";
8392  break;
8393  case GUC_UNIT_MIN:
8394  values[2] = "min";
8395  break;
8396  case 0:
8397  values[2] = NULL;
8398  break;
8399  default:
8400  elog(ERROR, "unrecognized GUC units value: %d",
8401  conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME));
8402  values[2] = NULL;
8403  break;
8404  }
8405  }
8406  else
8407  values[2] = NULL;
8408 
8409  /* group */
8410  values[3] = config_group_names[conf->group];
8411 
8412  /* short_desc */
8413  values[4] = conf->short_desc;
8414 
8415  /* extra_desc */
8416  values[5] = conf->long_desc;
8417 
8418  /* context */
8419  values[6] = GucContext_Names[conf->context];
8420 
8421  /* vartype */
8422  values[7] = config_type_names[conf->vartype];
8423 
8424  /* source */
8425  values[8] = GucSource_Names[conf->source];
8426 
8427  /* now get the type specific attributes */
8428  switch (conf->vartype)
8429  {
8430  case PGC_BOOL:
8431  {
8432  struct config_bool *lconf = (struct config_bool *) conf;
8433 
8434  /* min_val */
8435  values[9] = NULL;
8436 
8437  /* max_val */
8438  values[10] = NULL;
8439 
8440  /* enumvals */
8441  values[11] = NULL;
8442 
8443  /* boot_val */
8444  values[12] = pstrdup(lconf->boot_val ? "on" : "off");
8445 
8446  /* reset_val */
8447  values[13] = pstrdup(lconf->reset_val ? "on" : "off");
8448  }
8449  break;
8450 
8451  case PGC_INT:
8452  {
8453  struct config_int *lconf = (struct config_int *) conf;
8454 
8455  /* min_val */
8456  snprintf(buffer, sizeof(buffer), "%d", lconf->min);
8457  values[9] = pstrdup(buffer);
8458 
8459  /* max_val */
8460  snprintf(buffer, sizeof(buffer), "%d", lconf->max);
8461  values[10] = pstrdup(buffer);
8462 
8463  /* enumvals */
8464  values[11] = NULL;
8465 
8466  /* boot_val */
8467  snprintf(buffer, sizeof(buffer), "%d", lconf->boot_val);
8468  values[12] = pstrdup(buffer);
8469 
8470  /* reset_val */
8471  snprintf(buffer, sizeof(buffer), "%d", lconf->reset_val);
8472  values[13] = pstrdup(buffer);
8473  }
8474  break;
8475 
8476  case PGC_REAL:
8477  {
8478  struct config_real *lconf = (struct config_real *) conf;
8479 
8480  /* min_val */
8481  snprintf(buffer, sizeof(buffer), "%g", lconf->min);
8482  values[9] = pstrdup(buffer);
8483 
8484  /* max_val */
8485  snprintf(buffer, sizeof(buffer), "%g", lconf->max);
8486  values[10] = pstrdup(buffer);
8487 
8488  /* enumvals */
8489  values[11] = NULL;
8490 
8491  /* boot_val */
8492  snprintf(buffer, sizeof(buffer), "%g", lconf->boot_val);
8493  values[12] = pstrdup(buffer);
8494 
8495  /* reset_val */
8496  snprintf(buffer, sizeof(buffer), "%g", lconf->reset_val);
8497  values[13] = pstrdup(buffer);
8498  }
8499  break;
8500 
8501  case PGC_STRING:
8502  {
8503  struct config_string *lconf = (struct config_string *) conf;
8504 
8505  /* min_val */
8506  values[9] = NULL;
8507 
8508  /* max_val */
8509  values[10] = NULL;
8510 
8511  /* enumvals */
8512  values[11] = NULL;
8513 
8514  /* boot_val */
8515  if (lconf->boot_val == NULL)
8516  values[12] = NULL;
8517  else
8518  values[12] = pstrdup(lconf->boot_val);
8519 
8520  /* reset_val */
8521  if (lconf->reset_val == NULL)
8522  values[13] = NULL;
8523  else
8524  values[13] = pstrdup(lconf->reset_val);
8525  }
8526  break;
8527 
8528  case PGC_ENUM:
8529  {
8530  struct config_enum *lconf = (struct config_enum *) conf;
8531 
8532  /* min_val */
8533  values[9] = NULL;
8534 
8535  /* max_val */
8536  values[10] = NULL;
8537 
8538  /* enumvals */
8539 
8540  /*
8541  * NOTE! enumvals with double quotes in them are not
8542  * supported!
8543  */
8544  values[11] = config_enum_get_options((struct config_enum *) conf,
8545  "{\"", "\"}", "\",\"");
8546 
8547  /* boot_val */
8549  lconf->boot_val));
8550 
8551  /* reset_val */
8553  lconf->reset_val));
8554  }
8555  break;
8556 
8557  default:
8558  {
8559  /*
8560  * should never get here, but in case we do, set 'em to NULL
8561  */
8562 
8563  /* min_val */
8564  values[9] = NULL;
8565 
8566  /* max_val */
8567  values[10] = NULL;
8568 
8569  /* enumvals */
8570  values[11] = NULL;
8571 
8572  /* boot_val */
8573  values[12] = NULL;
8574 
8575  /* reset_val */
8576  values[13] = NULL;
8577  }
8578  break;
8579  }
8580 
8581  /*
8582  * If the setting came from a config file, set the source location. For
8583  * security reasons, we don't show source file/line number for
8584  * non-superusers.
8585  */
8586  if (conf->source == PGC_S_FILE && superuser())
8587  {
8588  values[14] = conf->sourcefile;
8589  snprintf(buffer, sizeof(buffer), "%d", conf->sourceline);
8590  values[15] = pstrdup(buffer);
8591  }
8592  else
8593  {
8594  values[14] = NULL;
8595  values[15] = NULL;
8596  }
8597 
8598  values[16] = (conf->status & GUC_PENDING_RESTART) ? "t" : "f";
8599 }
GucSource source
Definition: guc_tables.h:156
static char * _ShowOption(struct config_generic *record, bool use_units)
Definition: guc.c:8901
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:5850
bool superuser(void)
Definition: superuser.c:47
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:4171
#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:4168
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:5899
#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 7034 of file guc.c.

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

Referenced by pg_get_functiondef().

7035 {
7036  struct config_generic *record;
7037 
7038  record = find_option(name, false, WARNING);
7039  if (record == NULL)
7040  {
7041  if (missing_ok)
7042  return 0;
7043  ereport(ERROR,
7044  (errcode(ERRCODE_UNDEFINED_OBJECT),
7045  errmsg("unrecognized configuration parameter \"%s\"",
7046  name)));
7047  }
7048  return record->flags;
7049 }
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:4605
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 6985 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().

6986 {
6987  struct config_generic *record;
6988  static char buffer[256];
6989 
6990  record = find_option(name, false, ERROR);
6991  if (record == NULL)
6992  ereport(ERROR,
6993  (errcode(ERRCODE_UNDEFINED_OBJECT),
6994  errmsg("unrecognized configuration parameter \"%s\"", name)));
6995  if ((record->flags & GUC_SUPERUSER_ONLY) &&
6996  !is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
6997  ereport(ERROR,
6998  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6999  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
7000  name)));
7001 
7002  switch (record->vartype)
7003  {
7004  case PGC_BOOL:
7005  return ((struct config_bool *) record)->reset_val ? "on" : "off";
7006 
7007  case PGC_INT:
7008  snprintf(buffer, sizeof(buffer), "%d",
7009  ((struct config_int *) record)->reset_val);
7010  return buffer;
7011 
7012  case PGC_REAL:
7013  snprintf(buffer, sizeof(buffer), "%g",
7014  ((struct config_real *) record)->reset_val);
7015  return buffer;
7016 
7017  case PGC_STRING:
7018  return ((struct config_string *) record)->reset_val;
7019 
7020  case PGC_ENUM:
7021  return config_enum_lookup_by_value((struct config_enum *) record,
7022  ((struct config_enum *) record)->reset_val);
7023  }
7024  return NULL;
7025 }
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:5850
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:4605
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 8605 of file guc.c.

References num_guc_variables.

Referenced by GucInfoMain(), and show_all_settings().

8606 {
8607  return num_guc_variables;
8608 }
static int num_guc_variables
Definition: guc.c:4171

◆ GetPGVariable()

void GetPGVariable ( const char *  name,
DestReceiver dest 
)

Definition at line 8159 of file guc.c.

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

Referenced by exec_replication_command(), and standard_ProcessUtility().

8160 {
8161  if (guc_name_compare(name, "all") == 0)
8162  ShowAllGUCConfig(dest);
8163  else
8164  ShowGUCConfigOption(name, dest);
8165 }
static void ShowGUCConfigOption(const char *name, DestReceiver *dest)
Definition: guc.c:8203
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:4666
static void ShowAllGUCConfig(DestReceiver *dest)
Definition: guc.c:8231
const char * name
Definition: encode.c:521

◆ GetPGVariableResultDesc()

TupleDesc GetPGVariableResultDesc ( const char *  name)

Definition at line 8168 of file guc.c.

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

Referenced by UtilityTupleDescriptor().

8169 {
8170  TupleDesc tupdesc;
8171 
8172  if (guc_name_compare(name, "all") == 0)
8173  {
8174  /* need a tuple descriptor representing three TEXT columns */
8175  tupdesc = CreateTemplateTupleDesc(3, false);
8176  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
8177  TEXTOID, -1, 0);
8178  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
8179  TEXTOID, -1, 0);
8180  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
8181  TEXTOID, -1, 0);
8182  }
8183  else
8184  {
8185  const char *varname;
8186 
8187  /* Get the canonical spelling of name */
8188  (void) GetConfigOptionByName(name, &varname, false);
8189 
8190  /* need a tuple descriptor representing a single TEXT column */
8191  tupdesc = CreateTemplateTupleDesc(1, false);
8192  TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
8193  TEXTOID, -1, 0);
8194  }
8195  return tupdesc;
8196 }
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:4666
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:8300
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 10034 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().

10035 {
10036  GUC_check_errcode_value = sqlerrcode;
10037 }
static int GUC_check_errcode_value
Definition: guc.c:129

◆ GUCArrayAdd()

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

Definition at line 9731 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().

9732 {
9733  struct config_generic *record;
9734  Datum datum;
9735  char *newval;
9736  ArrayType *a;
9737 
9738  Assert(name);
9739  Assert(value);
9740 
9741  /* test if the option is valid and we're allowed to set it */
9742  (void) validate_option_array_item(name, value, false);
9743 
9744  /* normalize name (converts obsolete GUC names to modern spellings) */
9745  record = find_option(name, false, WARNING);
9746  if (record)
9747  name = record->name;
9748 
9749  /* build new item for array */
9750  newval = psprintf("%s=%s", name, value);
9751  datum = CStringGetTextDatum(newval);
9752 
9753  if (array)
9754  {
9755  int index;
9756  bool isnull;
9757  int i;
9758 
9759  Assert(ARR_ELEMTYPE(array) == TEXTOID);
9760  Assert(ARR_NDIM(array) == 1);
9761  Assert(ARR_LBOUND(array)[0] == 1);
9762 
9763  index = ARR_DIMS(array)[0] + 1; /* add after end */
9764 
9765  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9766  {
9767  Datum d;
9768  char *current;
9769 
9770  d = array_ref(array, 1, &i,
9771  -1 /* varlenarray */ ,
9772  -1 /* TEXT's typlen */ ,
9773  false /* TEXT's typbyval */ ,
9774  'i' /* TEXT's typalign */ ,
9775  &isnull);
9776  if (isnull)
9777  continue;
9778  current = TextDatumGetCString(d);
9779 
9780  /* check for match up through and including '=' */
9781  if (strncmp(current, newval, strlen(name) + 1) == 0)
9782  {
9783  index = i;
9784  break;
9785  }
9786  }
9787 
9788  a = array_set(array, 1, &index,
9789  datum,
9790  false,
9791  -1 /* varlena array */ ,
9792  -1 /* TEXT's typlen */ ,
9793  false /* TEXT's typbyval */ ,
9794  'i' /* TEXT's typalign */ );
9795  }
9796  else
9797  a = construct_array(&datum, 1,
9798  TEXTOID,
9799  -1, false, 'i');
9800 
9801  return a;
9802 }
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:9957
#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:365
static struct @131 value
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4605
#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 9811 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().

9812 {
9813  struct config_generic *record;
9814  ArrayType *newarray;
9815  int i;
9816  int index;
9817 
9818  Assert(name);
9819 
9820  /* test if the option is valid and we're allowed to set it */
9821  (void) validate_option_array_item(name, NULL, false);
9822 
9823  /* normalize name (converts obsolete GUC names to modern spellings) */
9824  record = find_option(name, false, WARNING);
9825  if (record)
9826  name = record->name;
9827 
9828  /* if array is currently null, then surely nothing to delete */
9829  if (!array)
9830  return NULL;
9831 
9832  newarray = NULL;
9833  index = 1;
9834 
9835  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9836  {
9837  Datum d;
9838  char *val;
9839  bool isnull;
9840 
9841  d = array_ref(array, 1, &i,
9842  -1 /* varlenarray */ ,
9843  -1 /* TEXT's typlen */ ,
9844  false /* TEXT's typbyval */ ,
9845  'i' /* TEXT's typalign */ ,
9846  &isnull);
9847  if (isnull)
9848  continue;
9849  val = TextDatumGetCString(d);
9850 
9851  /* ignore entry if it's what we want to delete */
9852  if (strncmp(val, name, strlen(name)) == 0
9853  && val[strlen(name)] == '=')
9854  continue;
9855 
9856  /* else add it to the output array */
9857  if (newarray)
9858  newarray = array_set(newarray, 1, &index,
9859  d,
9860  false,
9861  -1 /* varlenarray */ ,
9862  -1 /* TEXT's typlen */ ,
9863  false /* TEXT's typbyval */ ,
9864  'i' /* TEXT's typalign */ );
9865  else
9866  newarray = construct_array(&d, 1,
9867  TEXTOID,
9868  -1, false, 'i');
9869 
9870  index++;
9871  }
9872 
9873  return newarray;
9874 }
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:9957
#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:365
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4605
#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 9883 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().

9884 {
9885  ArrayType *newarray;
9886  int i;
9887  int index;
9888 
9889  /* if array is currently null, nothing to do */
9890  if (!array)
9891  return NULL;
9892 
9893  /* if we're superuser, we can delete everything, so just do it */
9894  if (superuser())
9895  return NULL;
9896 
9897  newarray = NULL;
9898  index = 1;
9899 
9900  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9901  {
9902  Datum d;
9903  char *val;
9904  char *eqsgn;
9905  bool isnull;
9906 
9907  d = array_ref(array, 1, &i,
9908  -1 /* varlenarray */ ,
9909  -1 /* TEXT's typlen */ ,
9910  false /* TEXT's typbyval */ ,
9911  'i' /* TEXT's typalign */ ,
9912  &isnull);
9913  if (isnull)
9914  continue;
9915  val = TextDatumGetCString(d);
9916 
9917  eqsgn = strchr(val, '=');
9918  *eqsgn = '\0';
9919 
9920  /* skip if we have permission to delete it */
9921  if (validate_option_array_item(val, NULL, true))
9922  continue;
9923 
9924  /* else add it to the output array */
9925  if (newarray)
9926  newarray = array_set(newarray, 1, &index,
9927  d,
9928  false,
9929  -1 /* varlenarray */ ,
9930  -1 /* TEXT's typlen */ ,
9931  false /* TEXT's typbyval */ ,
9932  'i' /* TEXT's typalign */ );
9933  else
9934  newarray = construct_array(&d, 1,
9935  TEXTOID,
9936  -1, false, 'i');
9937 
9938  index++;
9939  pfree(val);
9940  }
9941 
9942  return newarray;
9943 }
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:9957
#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:365
int i
long val
Definition: informix.c:689

◆ InitializeGUCOptions()

void InitializeGUCOptions ( void  )

Definition at line 4700 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().

4701 {
4702  int i;
4703 
4704  /*
4705  * Before log_line_prefix could possibly receive a nonempty setting, make
4706  * sure that timezone processing is minimally alive (see elog.c).
4707  */
4709 
4710  /*
4711  * Build sorted array of all GUC variables.
4712  */
4714 
4715  /*
4716  * Load all variables with their compiled-in defaults, and initialize
4717  * status fields as needed.
4718  */
4719  for (i = 0; i < num_guc_variables; i++)
4720  {
4722  }
4723 
4724  guc_dirty = false;
4725 
4726  reporting_enabled = false;
4727 
4728  /*
4729  * Prevent any attempt to override the transaction modes from
4730  * non-interactive sources.
4731  */
4732  SetConfigOption("transaction_isolation", "default",
4734  SetConfigOption("transaction_read_only", "no",
4736  SetConfigOption("transaction_deferrable", "no",
4738 
4739  /*
4740  * For historical reasons, some GUC parameters can receive defaults from
4741  * environment variables. Process those settings.
4742  */
4744 }
void build_guc_variables(void)
Definition: guc.c:4432
static void InitializeGUCOptionsFromEnvironment(void)
Definition: guc.c:4756
void pg_timezone_initialize(void)
Definition: pgtz.c:363
static int num_guc_variables
Definition: guc.c:4171
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:6905
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:4802
static struct config_generic ** guc_variables
Definition: guc.c:4168
int i
static bool reporting_enabled
Definition: guc.c:4179
static bool guc_dirty
Definition: guc.c:4177

◆ NewGUCNestLevel()

◆ parse_int()

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

Definition at line 5730 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().

5731 {
5732  int64 val;
5733  char *endptr;
5734 
5735  /* To suppress compiler warnings, always set output params */
5736  if (result)
5737  *result = 0;
5738  if (hintmsg)
5739  *hintmsg = NULL;
5740 
5741  /* We assume here that int64 is at least as wide as long */
5742  errno = 0;
5743  val = strtol(value, &endptr, 0);
5744 
5745  if (endptr == value)
5746  return false; /* no HINT for integer syntax error */
5747 
5748  if (errno == ERANGE || val != (int64) ((int32) val))
5749  {
5750  if (hintmsg)
5751  *hintmsg = gettext_noop("Value exceeds integer range.");
5752  return false;
5753  }
5754 
5755  /* allow whitespace between integer and unit */
5756  while (isspace((unsigned char) *endptr))
5757  endptr++;
5758 
5759  /* Handle possible unit */
5760  if (*endptr != '\0')
5761  {
5762  char unit[MAX_UNIT_LEN + 1];
5763  int unitlen;
5764  bool converted = false;
5765 
5766  if ((flags & GUC_UNIT) == 0)
5767  return false; /* this setting does not accept a unit */
5768 
5769  unitlen = 0;
5770  while (*endptr != '\0' && !isspace((unsigned char) *endptr) &&
5771  unitlen < MAX_UNIT_LEN)
5772  unit[unitlen++] = *(endptr++);
5773  unit[unitlen] = '\0';
5774  /* allow whitespace after unit */
5775  while (isspace((unsigned char) *endptr))
5776  endptr++;
5777 
5778  if (*endptr == '\0')
5779  converted = convert_to_base_unit(val, unit, (flags & GUC_UNIT),
5780  &val);
5781  if (!converted)
5782  {
5783  /* invalid unit, or garbage after the unit; set hint and fail. */
5784  if (hintmsg)
5785  {
5786  if (flags & GUC_UNIT_MEMORY)
5787  *hintmsg = memory_units_hint;
5788  else
5789  *hintmsg = time_units_hint;
5790  }
5791  return false;
5792  }
5793 
5794  /* Check for overflow due to units conversion */
5795  if (val != (int64) ((int32) val))
5796  {
5797  if (hintmsg)
5798  *hintmsg = gettext_noop("Value exceeds integer range.");
5799  return false;
5800  }
5801  }
5802 
5803  if (result)
5804  *result = (int) val;
5805  return true;
5806 }
#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:753
static bool convert_to_base_unit(int64 value, const char *unit, int base_unit, int64 *base_value)
Definition: guc.c:5645
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 5816 of file guc.c.

References val.

Referenced by parse_and_validate_value(), and parse_one_reloption().

5817 {
5818  double val;
5819  char *endptr;
5820 
5821  if (result)
5822  *result = 0; /* suppress compiler warning */
5823 
5824  errno = 0;
5825  val = strtod(value, &endptr);
5826  if (endptr == value || errno == ERANGE)
5827  return false;
5828 
5829  /* allow whitespace after number */
5830  while (isspace((unsigned char) *endptr))
5831  endptr++;
5832  if (*endptr != '\0')
5833  return false;
5834 
5835  if (result)
5836  *result = val;
5837  return true;
5838 }
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 9635 of file guc.c.

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

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

9636 {
9637  size_t equal_pos;
9638  char *cp;
9639 
9640  AssertArg(string);
9641  AssertArg(name);
9642  AssertArg(value);
9643 
9644  equal_pos = strcspn(string, "=");
9645 
9646  if (string[equal_pos] == '=')
9647  {
9648  *name = guc_malloc(FATAL, equal_pos + 1);
9649  strlcpy(*name, string, equal_pos + 1);
9650 
9651  *value = guc_strdup(FATAL, &string[equal_pos + 1]);
9652  }
9653  else
9654  {
9655  /* no equal sign in string */
9656  *name = guc_strdup(FATAL, string);
9657  *value = NULL;
9658  }
9659 
9660  for (cp = *name; *cp; cp++)
9661  if (*cp == '-')
9662  *cp = '_';
9663 }
static char * guc_strdup(int elevel, const char *src)
Definition: guc.c:4241
#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:4209

◆ ProcessConfigFile()

◆ ProcessGUCArray()

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

Definition at line 9673 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().

9675 {
9676  int i;
9677 
9678  Assert(array != NULL);
9679  Assert(ARR_ELEMTYPE(array) == TEXTOID);
9680  Assert(ARR_NDIM(array) == 1);
9681  Assert(ARR_LBOUND(array)[0] == 1);
9682 
9683  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9684  {
9685  Datum d;
9686  bool isnull;
9687  char *s;
9688  char *name;
9689  char *value;
9690 
9691  d = array_ref(array, 1, &i,
9692  -1 /* varlenarray */ ,
9693  -1 /* TEXT's typlen */ ,
9694  false /* TEXT's typbyval */ ,
9695  'i' /* TEXT's typalign */ ,
9696  &isnull);
9697 
9698  if (isnull)
9699  continue;
9700 
9701  s = TextDatumGetCString(d);
9702 
9703  ParseLongOption(s, &name, &value);
9704  if (!value)
9705  {
9706  ereport(WARNING,
9707  (errcode(ERRCODE_SYNTAX_ERROR),
9708  errmsg("could not parse setting for parameter \"%s\"",
9709  name)));
9710  free(name);
9711  continue;
9712  }
9713 
9714  (void) set_config_option(name, value,
9715  context, source,
9716  action, true, 0, false);
9717 
9718  free(name);
9719  if (value)
9720  free(value);
9721  pfree(s);
9722  }
9723 }
GucSource source
Definition: guc_tables.h:156
void ParseLongOption(const char *string, char **name, char **value)
Definition: guc.c:9635
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:365
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:6141
#define ARR_ELEMTYPE(a)
Definition: array.h:277
GucContext context
Definition: guc_tables.h:148

◆ ResetAllOptions()

void ResetAllOptions ( void  )

Definition at line 5097 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().

5098 {
5099  int i;
5100 
5101  for (i = 0; i < num_guc_variables; i++)
5102  {
5103  struct config_generic *gconf = guc_variables[i];
5104 
5105  /* Don't reset non-SET-able values */
5106  if (gconf->context != PGC_SUSET &&
5107  gconf->context != PGC_USERSET)
5108  continue;
5109  /* Don't reset if special exclusion from RESET ALL */
5110  if (gconf->flags & GUC_NO_RESET_ALL)
5111  continue;
5112  /* No need to reset if wasn't SET */
5113  if (gconf->source <= PGC_S_OVERRIDE)
5114  continue;
5115 
5116  /* Save old value to support transaction abort */
5118 
5119  switch (gconf->vartype)
5120  {
5121  case PGC_BOOL:
5122  {
5123  struct config_bool *conf = (struct config_bool *) gconf;
5124 
5125  if (conf->assign_hook)
5126  conf->assign_hook(conf->reset_val,
5127  conf->reset_extra);
5128  *conf->variable = conf->reset_val;
5129  set_extra_field(&conf->gen, &conf->gen.extra,
5130  conf->reset_extra);
5131  break;
5132  }
5133  case PGC_INT:
5134  {
5135  struct config_int *conf = (struct config_int *) gconf;
5136 
5137  if (conf->assign_hook)
5138  conf->assign_hook(conf->reset_val,
5139  conf->reset_extra);
5140  *conf->variable = conf->reset_val;
5141  set_extra_field(&conf->gen, &conf->gen.extra,
5142  conf->reset_extra);
5143  break;
5144  }
5145  case PGC_REAL:
5146  {
5147  struct config_real *conf = (struct config_real *) gconf;
5148 
5149  if (conf->assign_hook)
5150  conf->assign_hook(conf->reset_val,
5151  conf->reset_extra);
5152  *conf->variable = conf->reset_val;
5153  set_extra_field(&conf->gen, &conf->gen.extra,
5154  conf->reset_extra);
5155  break;
5156  }
5157  case PGC_STRING:
5158  {
5159  struct config_string *conf = (struct config_string *) gconf;
5160 
5161  if (conf->assign_hook)
5162  conf->assign_hook(conf->reset_val,
5163  conf->reset_extra);
5164  set_string_field(conf, conf->variable, conf->reset_val);
5165  set_extra_field(&conf->gen, &conf->gen.extra,
5166  conf->reset_extra);
5167  break;
5168  }
5169  case PGC_ENUM:
5170  {
5171  struct config_enum *conf = (struct config_enum *) gconf;
5172 
5173  if (conf->assign_hook)
5174  conf->assign_hook(conf->reset_val,
5175  conf->reset_extra);
5176  *conf->variable = conf->reset_val;
5177  set_extra_field(&conf->gen, &conf->gen.extra,
5178  conf->reset_extra);
5179  break;
5180  }
5181  }
5182 
5183  gconf->source = gconf->reset_source;
5184  gconf->scontext = gconf->reset_scontext;
5185 
5186  if (gconf->flags & GUC_REPORT)
5187  ReportGUCOption(gconf);
5188  }
5189 }
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:5197
int * variable
Definition: guc_tables.h:196
int * variable
Definition: guc_tables.h:242
static int num_guc_variables
Definition: guc.c:4171
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:4342
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:4281
static struct config_generic ** guc_variables
Definition: guc.c:4168
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:5621
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 9577 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().

9578 {
9579  char *varname,
9580  *varvalue,
9581  *varsourcefile;
9582  int varsourceline;
9583  GucSource varsource;
9584  GucContext varscontext;
9585  char *srcptr = (char *) gucstate;
9586  char *srcend;
9587  Size len;
9588  int i;
9589 
9590  /* See comment at can_skip_gucvar(). */
9591  for (i = 0; i < num_guc_variables; i++)
9592  if (!can_skip_gucvar(guc_variables[i]))
9594 
9595  /* First item is the length of the subsequent data */
9596  memcpy(&len, gucstate, sizeof(len));
9597 
9598  srcptr += sizeof(len);
9599  srcend = srcptr + len;
9600 
9601  while (srcptr < srcend)
9602  {
9603  int result;
9604 
9605  varname = read_gucstate(&srcptr, srcend);
9606  varvalue = read_gucstate(&srcptr, srcend);
9607  varsourcefile = read_gucstate(&srcptr, srcend);
9608  if (varsourcefile[0])
9609  read_gucstate_binary(&srcptr, srcend,
9610  &varsourceline, sizeof(varsourceline));
9611  read_gucstate_binary(&srcptr, srcend,
9612  &varsource, sizeof(varsource));
9613  read_gucstate_binary(&srcptr, srcend,
9614  &varscontext, sizeof(varscontext));
9615 
9616  result = set_config_option(varname, varvalue, varscontext, varsource,
9617  GUC_ACTION_SET, true, ERROR, true);
9618  if (result <= 0)
9619  ereport(ERROR,
9620  (errcode(ERRCODE_INTERNAL_ERROR),
9621  errmsg("parameter \"%s\" could not be set", varname)));
9622  if (varsourcefile[0])
9623  set_config_sourcefile(varname, varsourcefile, varsourceline);
9624  }
9625 }
GucContext
Definition: guc.h:68
static void static void set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
Definition: guc.c:6871
static void read_gucstate_binary(char **srcptr, char *srcend, void *dest, Size size)
Definition: guc.c:9562
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:4171
static bool can_skip_gucvar(struct config_generic *gconf)
Definition: guc.c:9253
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:4802
#define ereport(elevel, rest)
Definition: elog.h:122
static struct config_generic ** guc_variables
Definition: guc.c:4168
static char * read_gucstate(char **srcptr, char *srcend)
Definition: guc.c:9539
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:6141

◆ SelectConfigFiles()

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

Definition at line 4922 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().

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

◆ SerializeGUCState()

void SerializeGUCState ( Size  maxsize,
char *  start_address 
)

Definition at line 9512 of file guc.c.

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

Referenced by InitializeParallelDSM().

9513 {
9514  char *curptr;
9515  Size actual_size;
9516  Size bytes_left;
9517  int i;
9518 
9519  /* Reserve space for saving the actual size of the guc state */
9520  Assert(maxsize > sizeof(actual_size));
9521  curptr = start_address + sizeof(actual_size);
9522  bytes_left = maxsize - sizeof(actual_size);
9523 
9524  for (i = 0; i < num_guc_variables; i++)
9525  serialize_variable(&curptr, &bytes_left, guc_variables[i]);
9526 
9527  /* Store actual size without assuming alignment of start_address. */
9528  actual_size = maxsize - bytes_left - sizeof(actual_size);
9529  memcpy(start_address, &actual_size, sizeof(actual_size));
9530 }
static void serialize_variable(char **destptr, Size *maxbytes, struct config_generic *gconf)
Definition: guc.c:9438
static int num_guc_variables
Definition: guc.c:4171
static struct config_generic ** guc_variables
Definition: guc.c:4168
#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 6141 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().

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