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)
 
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 413 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 405 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().

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

7119 {
7120  char *name;
7121  char *value;
7122  bool resetall = false;
7123  ConfigVariable *head = NULL;
7124  ConfigVariable *tail = NULL;
7125  volatile int Tmpfd;
7126  char AutoConfFileName[MAXPGPATH];
7127  char AutoConfTmpFileName[MAXPGPATH];
7128 
7129  if (!superuser())
7130  ereport(ERROR,
7131  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7132  (errmsg("must be superuser to execute ALTER SYSTEM command"))));
7133 
7134  /*
7135  * Extract statement arguments
7136  */
7137  name = altersysstmt->setstmt->name;
7138 
7139  switch (altersysstmt->setstmt->kind)
7140  {
7141  case VAR_SET_VALUE:
7142  value = ExtractSetVariableArgs(altersysstmt->setstmt);
7143  break;
7144 
7145  case VAR_SET_DEFAULT:
7146  case VAR_RESET:
7147  value = NULL;
7148  break;
7149 
7150  case VAR_RESET_ALL:
7151  value = NULL;
7152  resetall = true;
7153  break;
7154 
7155  default:
7156  elog(ERROR, "unrecognized alter system stmt type: %d",
7157  altersysstmt->setstmt->kind);
7158  break;
7159  }
7160 
7161  /*
7162  * Unless it's RESET_ALL, validate the target variable and value
7163  */
7164  if (!resetall)
7165  {
7166  struct config_generic *record;
7167 
7168  record = find_option(name, false, ERROR);
7169  if (record == NULL)
7170  ereport(ERROR,
7171  (errcode(ERRCODE_UNDEFINED_OBJECT),
7172  errmsg("unrecognized configuration parameter \"%s\"",
7173  name)));
7174 
7175  /*
7176  * Don't allow parameters that can't be set in configuration files to
7177  * be set in PG_AUTOCONF_FILENAME file.
7178  */
7179  if ((record->context == PGC_INTERNAL) ||
7180  (record->flags & GUC_DISALLOW_IN_FILE) ||
7181  (record->flags & GUC_DISALLOW_IN_AUTO_FILE))
7182  ereport(ERROR,
7183  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
7184  errmsg("parameter \"%s\" cannot be changed",
7185  name)));
7186 
7187  /*
7188  * If a value is specified, verify that it's sane.
7189  */
7190  if (value)
7191  {
7192  union config_var_val newval;
7193  void *newextra = NULL;
7194 
7195  /* Check that it's acceptable for the indicated parameter */
7196  if (!parse_and_validate_value(record, name, value,
7197  PGC_S_FILE, ERROR,
7198  &newval, &newextra))
7199  ereport(ERROR,
7200  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7201  errmsg("invalid value for parameter \"%s\": \"%s\"",
7202  name, value)));
7203 
7204  if (record->vartype == PGC_STRING && newval.stringval != NULL)
7205  free(newval.stringval);
7206  if (newextra)
7207  free(newextra);
7208 
7209  /*
7210  * We must also reject values containing newlines, because the
7211  * grammar for config files doesn't support embedded newlines in
7212  * string literals.
7213  */
7214  if (strchr(value, '\n'))
7215  ereport(ERROR,
7216  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7217  errmsg("parameter value for ALTER SYSTEM must not contain a newline")));
7218  }
7219  }
7220 
7221  /*
7222  * PG_AUTOCONF_FILENAME and its corresponding temporary file are always in
7223  * the data directory, so we can reference them by simple relative paths.
7224  */
7225  snprintf(AutoConfFileName, sizeof(AutoConfFileName), "%s",
7227  snprintf(AutoConfTmpFileName, sizeof(AutoConfTmpFileName), "%s.%s",
7228  AutoConfFileName,
7229  "tmp");
7230 
7231  /*
7232  * Only one backend is allowed to operate on PG_AUTOCONF_FILENAME at a
7233  * time. Use AutoFileLock to ensure that. We must hold the lock while
7234  * reading the old file contents.
7235  */
7236  LWLockAcquire(AutoFileLock, LW_EXCLUSIVE);
7237 
7238  /*
7239  * If we're going to reset everything, then no need to open or parse the
7240  * old file. We'll just write out an empty list.
7241  */
7242  if (!resetall)
7243  {
7244  struct stat st;
7245 
7246  if (stat(AutoConfFileName, &st) == 0)
7247  {
7248  /* open old file PG_AUTOCONF_FILENAME */
7249  FILE *infile;
7250 
7251  infile = AllocateFile(AutoConfFileName, "r");
7252  if (infile == NULL)
7253  ereport(ERROR,
7255  errmsg("could not open file \"%s\": %m",
7256  AutoConfFileName)));
7257 
7258  /* parse it */
7259  if (!ParseConfigFp(infile, AutoConfFileName, 0, LOG, &head, &tail))
7260  ereport(ERROR,
7261  (errcode(ERRCODE_CONFIG_FILE_ERROR),
7262  errmsg("could not parse contents of file \"%s\"",
7263  AutoConfFileName)));
7264 
7265  FreeFile(infile);
7266  }
7267 
7268  /*
7269  * Now, replace any existing entry with the new value, or add it if
7270  * not present.
7271  */
7272  replace_auto_config_value(&head, &tail, name, value);
7273  }
7274 
7275  /*
7276  * To ensure crash safety, first write the new file data to a temp file,
7277  * then atomically rename it into place.
7278  *
7279  * If there is a temp file left over due to a previous crash, it's okay to
7280  * truncate and reuse it.
7281  */
7282  Tmpfd = BasicOpenFile(AutoConfTmpFileName,
7283  O_CREAT | O_RDWR | O_TRUNC);
7284  if (Tmpfd < 0)
7285  ereport(ERROR,
7287  errmsg("could not open file \"%s\": %m",
7288  AutoConfTmpFileName)));
7289 
7290  /*
7291  * Use a TRY block to clean up the file if we fail. Since we need a TRY
7292  * block anyway, OK to use BasicOpenFile rather than OpenTransientFile.
7293  */
7294  PG_TRY();
7295  {
7296  /* Write and sync the new contents to the temporary file */
7297  write_auto_conf_file(Tmpfd, AutoConfTmpFileName, head);
7298 
7299  /* Close before renaming; may be required on some platforms */
7300  close(Tmpfd);
7301  Tmpfd = -1;
7302 
7303  /*
7304  * As the rename is atomic operation, if any problem occurs after this
7305  * at worst it can lose the parameters set by last ALTER SYSTEM
7306  * command.
7307  */
7308  durable_rename(AutoConfTmpFileName, AutoConfFileName, ERROR);
7309  }
7310  PG_CATCH();
7311  {
7312  /* Close file first, else unlink might fail on some platforms */
7313  if (Tmpfd >= 0)
7314  close(Tmpfd);
7315 
7316  /* Unlink, but ignore any error */
7317  (void) unlink(AutoConfTmpFileName);
7318 
7319  PG_RE_THROW();
7320  }
7321  PG_END_TRY();
7322 
7323  FreeConfigVariables(head);
7324 
7325  LWLockRelease(AutoFileLock);
7326 }
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:5772
static struct @130 value
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:1724
#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:2353
#define ereport(elevel, rest)
Definition: elog.h:122
int durable_rename(const char *oldfile, const char *newfile, int elevel)
Definition: fd.c:608
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 void write_auto_conf_file(int fd, const char *filename, ConfigVariable *head_p)
Definition: guc.c:6977
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:4420
#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:1120
#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:939
int FreeFile(FILE *file)
Definition: fd.c:2545
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:7045
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:7456
#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 4094 of file namespace.c.

References baseSearchPathValid.

4095 {
4096  /*
4097  * We mark the path as needing recomputation, but don't do anything until
4098  * it's needed. This avoids trying to do database access during GUC
4099  * initialization, or outside a transaction.
4100  */
4101  baseSearchPathValid = false;
4102 }
static bool baseSearchPathValid
Definition: namespace.c:153

◆ assign_temp_tablespaces()

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

Definition at line 1262 of file tablespace.c.

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

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

◆ assign_xlog_sync_method()

void assign_xlog_sync_method ( int  new_sync_method,
void *  extra 
)

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

10083 {
10084  if (sync_method != new_sync_method)
10085  {
10086  /*
10087  * To ensure that no blocks escape unsynced, force an fsync on the
10088  * currently open log segment (if any). Also, if the open flag is
10089  * changing, close the log file so it will be reopened (with new flag
10090  * bit) at next use.
10091  */
10092  if (openLogFile >= 0)
10093  {
10095  if (pg_fsync(openLogFile) != 0)
10096  ereport(PANIC,
10098  errmsg("could not fsync log segment %s: %m",
10101  if (get_sync_bit(sync_method) != get_sync_bit(new_sync_method))
10102  XLogFileClose();
10103  }
10104  }
10105 }
static int get_sync_bit(int method)
Definition: xlog.c:10026
#define PANIC
Definition: elog.h:53
static XLogSegNo openLogSegNo
Definition: xlog.c:775
static void XLogFileClose(void)
Definition: xlog.c:3707
char * XLogFileNameP(TimeLineID tli, XLogSegNo segno)
Definition: xlog.c:10158
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:348

◆ AtEOXact_GUC()

void AtEOXact_GUC ( bool  isCommit,
int  nestLevel 
)

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

5128 {
5129  bool still_dirty;
5130  int i;
5131 
5132  /*
5133  * Note: it's possible to get here with GUCNestLevel == nestLevel-1 during
5134  * abort, if there is a failure during transaction start before
5135  * AtStart_GUC is called.
5136  */
5137  Assert(nestLevel > 0 &&
5138  (nestLevel <= GUCNestLevel ||
5139  (nestLevel == GUCNestLevel + 1 && !isCommit)));
5140 
5141  /* Quick exit if nothing's changed in this transaction */
5142  if (!guc_dirty)
5143  {
5144  GUCNestLevel = nestLevel - 1;
5145  return;
5146  }
5147 
5148  still_dirty = false;
5149  for (i = 0; i < num_guc_variables; i++)
5150  {
5151  struct config_generic *gconf = guc_variables[i];
5152  GucStack *stack;
5153 
5154  /*
5155  * Process and pop each stack entry within the nest level. To simplify
5156  * fmgr_security_definer() and other places that use GUC_ACTION_SAVE,
5157  * we allow failure exit from code that uses a local nest level to be
5158  * recovered at the surrounding transaction or subtransaction abort;
5159  * so there could be more than one stack entry to pop.
5160  */
5161  while ((stack = gconf->stack) != NULL &&
5162  stack->nest_level >= nestLevel)
5163  {
5164  GucStack *prev = stack->prev;
5165  bool restorePrior = false;
5166  bool restoreMasked = false;
5167  bool changed;
5168 
5169  /*
5170  * In this next bit, if we don't set either restorePrior or
5171  * restoreMasked, we must "discard" any unwanted fields of the
5172  * stack entries to avoid leaking memory. If we do set one of
5173  * those flags, unused fields will be cleaned up after restoring.
5174  */
5175  if (!isCommit) /* if abort, always restore prior value */
5176  restorePrior = true;
5177  else if (stack->state == GUC_SAVE)
5178  restorePrior = true;
5179  else if (stack->nest_level == 1)
5180  {
5181  /* transaction commit */
5182  if (stack->state == GUC_SET_LOCAL)
5183  restoreMasked = true;
5184  else if (stack->state == GUC_SET)
5185  {
5186  /* we keep the current active value */
5187  discard_stack_value(gconf, &stack->prior);
5188  }
5189  else /* must be GUC_LOCAL */
5190  restorePrior = true;
5191  }
5192  else if (prev == NULL ||
5193  prev->nest_level < stack->nest_level - 1)
5194  {
5195  /* decrement entry's level and do not pop it */
5196  stack->nest_level--;
5197  continue;
5198  }
5199  else
5200  {
5201  /*
5202  * We have to merge this stack entry into prev. See README for
5203  * discussion of this bit.
5204  */
5205  switch (stack->state)
5206  {
5207  case GUC_SAVE:
5208  Assert(false); /* can't get here */
5209 
5210  case GUC_SET:
5211  /* next level always becomes SET */
5212  discard_stack_value(gconf, &stack->prior);
5213  if (prev->state == GUC_SET_LOCAL)
5214  discard_stack_value(gconf, &prev->masked);
5215  prev->state = GUC_SET;
5216  break;
5217 
5218  case GUC_LOCAL:
5219  if (prev->state == GUC_SET)
5220  {
5221  /* LOCAL migrates down */
5222  prev->masked_scontext = stack->scontext;
5223  prev->masked = stack->prior;
5224  prev->state = GUC_SET_LOCAL;
5225  }
5226  else
5227  {
5228  /* else just forget this stack level */
5229  discard_stack_value(gconf, &stack->prior);
5230  }
5231  break;
5232 
5233  case GUC_SET_LOCAL:
5234  /* prior state at this level no longer wanted */
5235  discard_stack_value(gconf, &stack->prior);
5236  /* copy down the masked state */
5237  prev->masked_scontext = stack->masked_scontext;
5238  if (prev->state == GUC_SET_LOCAL)
5239  discard_stack_value(gconf, &prev->masked);
5240  prev->masked = stack->masked;
5241  prev->state = GUC_SET_LOCAL;
5242  break;
5243  }
5244  }
5245 
5246  changed = false;
5247 
5248  if (restorePrior || restoreMasked)
5249  {
5250  /* Perform appropriate restoration of the stacked value */
5251  config_var_value newvalue;
5252  GucSource newsource;
5253  GucContext newscontext;
5254 
5255  if (restoreMasked)
5256  {
5257  newvalue = stack->masked;
5258  newsource = PGC_S_SESSION;
5259  newscontext = stack->masked_scontext;
5260  }
5261  else
5262  {
5263  newvalue = stack->prior;
5264  newsource = stack->source;
5265  newscontext = stack->scontext;
5266  }
5267 
5268  switch (gconf->vartype)
5269  {
5270  case PGC_BOOL:
5271  {
5272  struct config_bool *conf = (struct config_bool *) gconf;
5273  bool newval = newvalue.val.boolval;
5274  void *newextra = newvalue.extra;
5275 
5276  if (*conf->variable != newval ||
5277  conf->gen.extra != newextra)
5278  {
5279  if (conf->assign_hook)
5280  conf->assign_hook(newval, newextra);
5281  *conf->variable = newval;
5282  set_extra_field(&conf->gen, &conf->gen.extra,
5283  newextra);
5284  changed = true;
5285  }
5286  break;
5287  }
5288  case PGC_INT:
5289  {
5290  struct config_int *conf = (struct config_int *) gconf;
5291  int newval = newvalue.val.intval;
5292  void *newextra = newvalue.extra;
5293 
5294  if (*conf->variable != newval ||
5295  conf->gen.extra != newextra)
5296  {
5297  if (conf->assign_hook)
5298  conf->assign_hook(newval, newextra);
5299  *conf->variable = newval;
5300  set_extra_field(&conf->gen, &conf->gen.extra,
5301  newextra);
5302  changed = true;
5303  }
5304  break;
5305  }
5306  case PGC_REAL:
5307  {
5308  struct config_real *conf = (struct config_real *) gconf;
5309  double newval = newvalue.val.realval;
5310  void *newextra = newvalue.extra;
5311 
5312  if (*conf->variable != newval ||
5313  conf->gen.extra != newextra)
5314  {
5315  if (conf->assign_hook)
5316  conf->assign_hook(newval, newextra);
5317  *conf->variable = newval;
5318  set_extra_field(&conf->gen, &conf->gen.extra,
5319  newextra);
5320  changed = true;
5321  }
5322  break;
5323  }
5324  case PGC_STRING:
5325  {
5326  struct config_string *conf = (struct config_string *) gconf;
5327  char *newval = newvalue.val.stringval;
5328  void *newextra = newvalue.extra;
5329 
5330  if (*conf->variable != newval ||
5331  conf->gen.extra != newextra)
5332  {
5333  if (conf->assign_hook)
5334  conf->assign_hook(newval, newextra);
5335  set_string_field(conf, conf->variable, newval);
5336  set_extra_field(&conf->gen, &conf->gen.extra,
5337  newextra);
5338  changed = true;
5339  }
5340 
5341  /*
5342  * Release stacked values if not used anymore. We
5343  * could use discard_stack_value() here, but since
5344  * we have type-specific code anyway, might as
5345  * well inline it.
5346  */
5347  set_string_field(conf, &stack->prior.val.stringval, NULL);
5348  set_string_field(conf, &stack->masked.val.stringval, NULL);
5349  break;
5350  }
5351  case PGC_ENUM:
5352  {
5353  struct config_enum *conf = (struct config_enum *) gconf;
5354  int newval = newvalue.val.enumval;
5355  void *newextra = newvalue.extra;
5356 
5357  if (*conf->variable != newval ||
5358  conf->gen.extra != newextra)
5359  {
5360  if (conf->assign_hook)
5361  conf->assign_hook(newval, newextra);
5362  *conf->variable = newval;
5363  set_extra_field(&conf->gen, &conf->gen.extra,
5364  newextra);
5365  changed = true;
5366  }
5367  break;
5368  }
5369  }
5370 
5371  /*
5372  * Release stacked extra values if not used anymore.
5373  */
5374  set_extra_field(gconf, &(stack->prior.extra), NULL);
5375  set_extra_field(gconf, &(stack->masked.extra), NULL);
5376 
5377  /* And restore source information */
5378  gconf->source = newsource;
5379  gconf->scontext = newscontext;
5380  }
5381 
5382  /* Finish popping the state stack */
5383  gconf->stack = prev;
5384  pfree(stack);
5385 
5386  /* Report new value if we changed it */
5387  if (changed && (gconf->flags & GUC_REPORT))
5388  ReportGUCOption(gconf);
5389  } /* end of stack-popping loop */
5390 
5391  if (stack != NULL)
5392  still_dirty = true;
5393  }
5394 
5395  /* If there are no remaining stack entries, we can reset guc_dirty */
5396  guc_dirty = still_dirty;
5397 
5398  /* Update nesting level */
5399  GUCNestLevel = nestLevel - 1;
5400 }
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:3996
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:936
static int num_guc_variables
Definition: guc.c:3986
static void discard_stack_value(struct config_generic *gconf, config_var_value *val)
Definition: guc.c:4211
GucSource source
Definition: guc_tables.h:124
static void set_extra_field(struct config_generic *gconf, void **field, void *newval)
Definition: guc.c:4157
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:4096
static struct config_generic ** guc_variables
Definition: guc.c:3983
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:688
#define newval
char * stringval
Definition: guc_tables.h:36
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:5436
GucStack * stack
Definition: guc_tables.h:160
double realval
Definition: guc_tables.h:35
static bool guc_dirty
Definition: guc.c:3992
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 5093 of file guc.c.

References elog, and WARNING.

Referenced by StartTransaction().

5094 {
5095  /*
5096  * The nest level should be 0 between transactions; if it isn't, somebody
5097  * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
5098  * throw a warning but make no other effort to clean up.
5099  */
5100  if (GUCNestLevel != 0)
5101  elog(WARNING, "GUC nest level = %d at transaction start",
5102  GUCNestLevel);
5103  GUCNestLevel = 1;
5104 }
static int GUCNestLevel
Definition: guc.c:3996
#define WARNING
Definition: elog.h:40
#define elog
Definition: elog.h:219

◆ BeginReportingGUCOptions()

void BeginReportingGUCOptions ( void  )

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

5409 {
5410  int i;
5411 
5412  /*
5413  * Don't do anything unless talking to an interactive frontend of protocol
5414  * 3.0 or later.
5415  */
5416  if (whereToSendOutput != DestRemote ||
5418  return;
5419 
5420  reporting_enabled = true;
5421 
5422  /* Transmit initial values of interesting variables */
5423  for (i = 0; i < num_guc_variables; i++)
5424  {
5425  struct config_generic *conf = guc_variables[i];
5426 
5427  if (conf->flags & GUC_REPORT)
5428  ReportGUCOption(conf);
5429  }
5430 }
#define PG_PROTOCOL_MAJOR(v)
Definition: pqcomm.h:104
static int num_guc_variables
Definition: guc.c:3986
#define GUC_REPORT
Definition: guc.h:208
static struct config_generic ** guc_variables
Definition: guc.c:3983
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:5436
CommandDest whereToSendOutput
Definition: postgres.c:88
static bool reporting_enabled
Definition: guc.c:3994
ProtocolVersion FrontendProtocol
Definition: globals.c:27

◆ check_default_tablespace()

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

Definition at line 1062 of file tablespace.c.

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

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

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

4061 {
4062  char *rawname;
4063  List *namelist;
4064 
4065  /* Need a modifiable copy of string */
4066  rawname = pstrdup(*newval);
4067 
4068  /* Parse string into list of identifiers */
4069  if (!SplitIdentifierString(rawname, ',', &namelist))
4070  {
4071  /* syntax error in name list */
4072  GUC_check_errdetail("List syntax is invalid.");
4073  pfree(rawname);
4074  list_free(namelist);
4075  return false;
4076  }
4077 
4078  /*
4079  * We used to try to check that the named schemas exist, but there are
4080  * many valid use-cases for having search_path settings that include
4081  * schemas that don't exist; and often, we are not inside a transaction
4082  * here and so can't consult the system catalogs anyway. So now, the only
4083  * requirement is syntactic validity of the identifier list.
4084  */
4085 
4086  pfree(rawname);
4087  list_free(namelist);
4088 
4089  return true;
4090 }
#define GUC_check_errdetail
Definition: guc.h:409
char * pstrdup(const char *in)
Definition: mcxt.c:1063
void pfree(void *pointer)
Definition: mcxt.c:936
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3263
#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 1157 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.

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

◆ check_wal_buffers()

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

Definition at line 4787 of file xlog.c.

References XLOGbuffers, and XLOGChooseNumBuffers().

4788 {
4789  /*
4790  * -1 indicates a request for auto-tune.
4791  */
4792  if (*newval == -1)
4793  {
4794  /*
4795  * If we haven't yet changed the boot_val default of -1, just let it
4796  * be. We'll fix it when XLOGShmemSize is called.
4797  */
4798  if (XLOGbuffers == -1)
4799  return true;
4800 
4801  /* Otherwise, substitute the auto-tune value */
4803  }
4804 
4805  /*
4806  * We clamp manually-set values to at least 4 blocks. Prior to PostgreSQL
4807  * 9.1, a minimum of 4 was enforced by guc.c, but since that is no longer
4808  * the case, we just silently treat such values as a request for the
4809  * minimum. (We could throw an error instead, but that doesn't seem very
4810  * helpful.)
4811  */
4812  if (*newval < 4)
4813  *newval = 4;
4814 
4815  return true;
4816 }
static int XLOGChooseNumBuffers(void)
Definition: xlog.c:4771
#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 7776 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().

7786 {
7787  struct config_bool *var;
7788 
7789  var = (struct config_bool *)
7790  init_custom_variable(name, short_desc, long_desc, context, flags,
7791  PGC_BOOL, sizeof(struct config_bool));
7792  var->variable = valueAddr;
7793  var->boot_val = bootValue;
7794  var->reset_val = bootValue;
7795  var->check_hook = check_hook;
7796  var->assign_hook = assign_hook;
7797  var->show_hook = show_hook;
7798  define_custom_variable(&var->gen);
7799 }
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:7544
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:7595

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

7898 {
7899  struct config_enum *var;
7900 
7901  var = (struct config_enum *)
7902  init_custom_variable(name, short_desc, long_desc, context, flags,
7903  PGC_ENUM, sizeof(struct config_enum));
7904  var->variable = valueAddr;
7905  var->boot_val = bootValue;
7906  var->reset_val = bootValue;
7907  var->options = options;
7908  var->check_hook = check_hook;
7909  var->assign_hook = assign_hook;
7910  var->show_hook = show_hook;
7911  define_custom_variable(&var->gen);
7912 }
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:7544
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:7595

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

7814 {
7815  struct config_int *var;
7816 
7817  var = (struct config_int *)
7818  init_custom_variable(name, short_desc, long_desc, context, flags,
7819  PGC_INT, sizeof(struct config_int));
7820  var->variable = valueAddr;
7821  var->boot_val = bootValue;
7822  var->reset_val = bootValue;
7823  var->min = minValue;
7824  var->max = maxValue;
7825  var->check_hook = check_hook;
7826  var->assign_hook = assign_hook;
7827  var->show_hook = show_hook;
7828  define_custom_variable(&var->gen);
7829 }
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:7544
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7595
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 7832 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().

7844 {
7845  struct config_real *var;
7846 
7847  var = (struct config_real *)
7848  init_custom_variable(name, short_desc, long_desc, context, flags,
7849  PGC_REAL, sizeof(struct config_real));
7850  var->variable = valueAddr;
7851  var->boot_val = bootValue;
7852  var->reset_val = bootValue;
7853  var->min = minValue;
7854  var->max = maxValue;
7855  var->check_hook = check_hook;
7856  var->assign_hook = assign_hook;
7857  var->show_hook = show_hook;
7858  define_custom_variable(&var->gen);
7859 }
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:7544
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:7595
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 7862 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().

7872 {
7873  struct config_string *var;
7874 
7875  var = (struct config_string *)
7876  init_custom_variable(name, short_desc, long_desc, context, flags,
7877  PGC_STRING, sizeof(struct config_string));
7878  var->variable = valueAddr;
7879  var->boot_val = bootValue;
7880  var->check_hook = check_hook;
7881  var->assign_hook = assign_hook;
7882  var->show_hook = show_hook;
7883  define_custom_variable(&var->gen);
7884 }
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:7544
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:7595

◆ EmitWarningsOnPlaceholders()

void EmitWarningsOnPlaceholders ( const char *  className)

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

7916 {
7917  int classLen = strlen(className);
7918  int i;
7919 
7920  for (i = 0; i < num_guc_variables; i++)
7921  {
7922  struct config_generic *var = guc_variables[i];
7923 
7924  if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
7925  strncmp(className, var->name, classLen) == 0 &&
7926  var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
7927  {
7928  ereport(WARNING,
7929  (errcode(ERRCODE_UNDEFINED_OBJECT),
7930  errmsg("unrecognized configuration parameter \"%s\"",
7931  var->name)));
7932  }
7933  }
7934 }
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:3986
#define ereport(elevel, rest)
Definition: elog.h:122
static struct config_generic ** guc_variables
Definition: guc.c:3983
#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 9147 of file guc.c.

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

Referenced by InitializeParallelDSM().

9148 {
9149  Size size;
9150  int i;
9151 
9152  /* Add space reqd for saving the data size of the guc state */
9153  size = sizeof(Size);
9154 
9155  /* Add up the space needed for each GUC variable */
9156  for (i = 0; i < num_guc_variables; i++)
9157  size = add_size(size,
9159 
9160  return size;
9161 }
static int num_guc_variables
Definition: guc.c:3986
static struct config_generic ** guc_variables
Definition: guc.c:3983
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
size_t Size
Definition: c.h:422
static Size estimate_variable_size(struct config_generic *gconf)
Definition: guc.c:9049
int i

◆ ExecSetVariableStmt()

void ExecSetVariableStmt ( VariableSetStmt stmt,
bool  isTopLevel 
)

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

Referenced by standard_ProcessUtility().

7333 {
7335 
7336  /*
7337  * Workers synchronize these parameters at the start of the parallel
7338  * operation; then, we block SET during the operation.
7339  */
7340  if (IsInParallelMode())
7341  ereport(ERROR,
7342  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
7343  errmsg("cannot set parameters during a parallel operation")));
7344 
7345  switch (stmt->kind)
7346  {
7347  case VAR_SET_VALUE:
7348  case VAR_SET_CURRENT:
7349  if (stmt->is_local)
7350  WarnNoTransactionChain(isTopLevel, "SET LOCAL");
7351  (void) set_config_option(stmt->name,
7352  ExtractSetVariableArgs(stmt),
7354  PGC_S_SESSION,
7355  action, true, 0, false);
7356  break;
7357  case VAR_SET_MULTI:
7358 
7359  /*
7360  * Special-case SQL syntaxes. The TRANSACTION and SESSION
7361  * CHARACTERISTICS cases effectively set more than one variable
7362  * per statement. TRANSACTION SNAPSHOT only takes one argument,
7363  * but we put it here anyway since it's a special case and not
7364  * related to any GUC variable.
7365  */
7366  if (strcmp(stmt->name, "TRANSACTION") == 0)
7367  {
7368  ListCell *head;
7369 
7370  WarnNoTransactionChain(isTopLevel, "SET TRANSACTION");
7371 
7372  foreach(head, stmt->args)
7373  {
7374  DefElem *item = (DefElem *) lfirst(head);
7375 
7376  if (strcmp(item->defname, "transaction_isolation") == 0)
7377  SetPGVariable("transaction_isolation",
7378  list_make1(item->arg), stmt->is_local);
7379  else if (strcmp(item->defname, "transaction_read_only") == 0)
7380  SetPGVariable("transaction_read_only",
7381  list_make1(item->arg), stmt->is_local);
7382  else if (strcmp(item->defname, "transaction_deferrable") == 0)
7383  SetPGVariable("transaction_deferrable",
7384  list_make1(item->arg), stmt->is_local);
7385  else
7386  elog(ERROR, "unexpected SET TRANSACTION element: %s",
7387  item->defname);
7388  }
7389  }
7390  else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
7391  {
7392  ListCell *head;
7393 
7394  foreach(head, stmt->args)
7395  {
7396  DefElem *item = (DefElem *) lfirst(head);
7397 
7398  if (strcmp(item->defname, "transaction_isolation") == 0)
7399  SetPGVariable("default_transaction_isolation",
7400  list_make1(item->arg), stmt->is_local);
7401  else if (strcmp(item->defname, "transaction_read_only") == 0)
7402  SetPGVariable("default_transaction_read_only",
7403  list_make1(item->arg), stmt->is_local);
7404  else if (strcmp(item->defname, "transaction_deferrable") == 0)
7405  SetPGVariable("default_transaction_deferrable",
7406  list_make1(item->arg), stmt->is_local);
7407  else
7408  elog(ERROR, "unexpected SET SESSION element: %s",
7409  item->defname);
7410  }
7411  }
7412  else if (strcmp(stmt->name, "TRANSACTION SNAPSHOT") == 0)
7413  {
7414  A_Const *con = linitial_node(A_Const, stmt->args);
7415 
7416  if (stmt->is_local)
7417  ereport(ERROR,
7418  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7419  errmsg("SET LOCAL TRANSACTION SNAPSHOT is not implemented")));
7420 
7421  WarnNoTransactionChain(isTopLevel, "SET TRANSACTION");
7422  Assert(nodeTag(&con->val) == T_String);
7423  ImportSnapshot(strVal(&con->val));
7424  }
7425  else
7426  elog(ERROR, "unexpected SET MULTI element: %s",
7427  stmt->name);
7428  break;
7429  case VAR_SET_DEFAULT:
7430  if (stmt->is_local)
7431  WarnNoTransactionChain(isTopLevel, "SET LOCAL");
7432  /* fall through */
7433  case VAR_RESET:
7434  if (strcmp(stmt->name, "transaction_isolation") == 0)
7435  WarnNoTransactionChain(isTopLevel, "RESET TRANSACTION");
7436 
7437  (void) set_config_option(stmt->name,
7438  NULL,
7440  PGC_S_SESSION,
7441  action, true, 0, false);
7442  break;
7443  case VAR_RESET_ALL:
7444  ResetAllOptions();
7445  break;
7446  }
7447 }
void ImportSnapshot(const char *idstr)
Definition: snapmgr.c:1430
VariableSetKind kind
Definition: parsenodes.h:1981
#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:906
#define ERROR
Definition: elog.h:43
Definition: guc.h:75
void ResetAllOptions(void)
Definition: guc.c:4912
#define ereport(elevel, rest)
Definition: elog.h:122
Node * arg
Definition: parsenodes.h:728
void WarnNoTransactionChain(bool isTopLevel, const char *stmtType)
Definition: xact.c:3201
#define Assert(condition)
Definition: c.h:688
#define lfirst(lc)
Definition: pg_list.h:106
#define nodeTag(nodeptr)
Definition: nodes.h:518
int errmsg(const char *fmt,...)
Definition: elog.c:797
char * defname
Definition: parsenodes.h:727
#define elog
Definition: elog.h:219
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
Definition: guc.c:7456
Value val
Definition: parsenodes.h:287
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:5956
void SetPGVariable(const char *name, List *args, bool is_local)
Definition: guc.c:7476

◆ ExtractSetVariableArgs()

char* ExtractSetVariableArgs ( VariableSetStmt stmt)

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

7457 {
7458  switch (stmt->kind)
7459  {
7460  case VAR_SET_VALUE:
7461  return flatten_set_variable_args(stmt->name, stmt->args);
7462  case VAR_SET_CURRENT:
7463  return GetConfigOptionByName(stmt->name, NULL, false);
7464  default:
7465  return NULL;
7466  }
7467 }
VariableSetKind kind
Definition: parsenodes.h:1981
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:8082
static char * flatten_set_variable_args(const char *name, List *args)
Definition: guc.c:6855

◆ FreeConfigVariables()

◆ GetConfigOption()

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

Definition at line 6744 of file guc.c.

References buffer, config_enum_lookup_by_value(), DEFAULT_ROLE_READ_ALL_SETTINGS, 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().

6745 {
6746  struct config_generic *record;
6747  static char buffer[256];
6748 
6749  record = find_option(name, false, ERROR);
6750  if (record == NULL)
6751  {
6752  if (missing_ok)
6753  return NULL;
6754  ereport(ERROR,
6755  (errcode(ERRCODE_UNDEFINED_OBJECT),
6756  errmsg("unrecognized configuration parameter \"%s\"",
6757  name)));
6758  }
6759  if (restrict_superuser &&
6760  (record->flags & GUC_SUPERUSER_ONLY) &&
6762  ereport(ERROR,
6763  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6764  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
6765  name)));
6766 
6767  switch (record->vartype)
6768  {
6769  case PGC_BOOL:
6770  return *((struct config_bool *) record)->variable ? "on" : "off";
6771 
6772  case PGC_INT:
6773  snprintf(buffer, sizeof(buffer), "%d",
6774  *((struct config_int *) record)->variable);
6775  return buffer;
6776 
6777  case PGC_REAL:
6778  snprintf(buffer, sizeof(buffer), "%g",
6779  *((struct config_real *) record)->variable);
6780  return buffer;
6781 
6782  case PGC_STRING:
6783  return *((struct config_string *) record)->variable;
6784 
6785  case PGC_ENUM:
6786  return config_enum_lookup_by_value((struct config_enum *) record,
6787  *((struct config_enum *) record)->variable);
6788  }
6789  return NULL;
6790 }
Oid GetUserId(void)
Definition: miscinit.c:284
int errcode(int sqlerrcode)
Definition: elog.c:575
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5665
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
#define DEFAULT_ROLE_READ_ALL_SETTINGS
Definition: pg_authid.h:106
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4420
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 8082 of file guc.c.

References _ShowOption(), DEFAULT_ROLE_READ_ALL_SETTINGS, 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().

8083 {
8084  struct config_generic *record;
8085 
8086  record = find_option(name, false, ERROR);
8087  if (record == NULL)
8088  {
8089  if (missing_ok)
8090  {
8091  if (varname)
8092  *varname = NULL;
8093  return NULL;
8094  }
8095 
8096  ereport(ERROR,
8097  (errcode(ERRCODE_UNDEFINED_OBJECT),
8098  errmsg("unrecognized configuration parameter \"%s\"", name)));
8099  }
8100 
8101  if ((record->flags & GUC_SUPERUSER_ONLY) &&
8103  ereport(ERROR,
8104  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
8105  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
8106  name)));
8107 
8108  if (varname)
8109  *varname = record->name;
8110 
8111  return _ShowOption(record, true);
8112 }
static char * _ShowOption(struct config_generic *record, bool use_units)
Definition: guc.c:8683
Oid GetUserId(void)
Definition: miscinit.c:284
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
#define DEFAULT_ROLE_READ_ALL_SETTINGS
Definition: pg_authid.h:106
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4420
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 8119 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, DEFAULT_ROLE_READ_ALL_SETTINGS, 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().

8120 {
8121  char buffer[256];
8122  struct config_generic *conf;
8123 
8124  /* check requested variable number valid */
8125  Assert((varnum >= 0) && (varnum < num_guc_variables));
8126 
8127  conf = guc_variables[varnum];
8128 
8129  if (noshow)
8130  {
8131  if ((conf->flags & GUC_NO_SHOW_ALL) ||
8132  ((conf->flags & GUC_SUPERUSER_ONLY) &&
8134  *noshow = true;
8135  else
8136  *noshow = false;
8137  }
8138 
8139  /* first get the generic attributes */
8140 
8141  /* name */
8142  values[0] = conf->name;
8143 
8144  /* setting : use _ShowOption in order to avoid duplicating the logic */
8145  values[1] = _ShowOption(conf, false);
8146 
8147  /* unit */
8148  if (conf->vartype == PGC_INT)
8149  {
8150  switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
8151  {
8152  case GUC_UNIT_BYTE:
8153  values[2] = "B";
8154  break;
8155  case GUC_UNIT_KB:
8156  values[2] = "kB";
8157  break;
8158  case GUC_UNIT_MB:
8159  values[2] = "MB";
8160  break;
8161  case GUC_UNIT_BLOCKS:
8162  snprintf(buffer, sizeof(buffer), "%dkB", BLCKSZ / 1024);
8163  values[2] = pstrdup(buffer);
8164  break;
8165  case GUC_UNIT_XBLOCKS:
8166  snprintf(buffer, sizeof(buffer), "%dkB", XLOG_BLCKSZ / 1024);
8167  values[2] = pstrdup(buffer);
8168  break;
8169  case GUC_UNIT_MS:
8170  values[2] = "ms";
8171  break;
8172  case GUC_UNIT_S:
8173  values[2] = "s";
8174  break;
8175  case GUC_UNIT_MIN:
8176  values[2] = "min";
8177  break;
8178  case 0:
8179  values[2] = NULL;
8180  break;
8181  default:
8182  elog(ERROR, "unrecognized GUC units value: %d",
8183  conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME));
8184  values[2] = NULL;
8185  break;
8186  }
8187  }
8188  else
8189  values[2] = NULL;
8190 
8191  /* group */
8192  values[3] = config_group_names[conf->group];
8193 
8194  /* short_desc */
8195  values[4] = conf->short_desc;
8196 
8197  /* extra_desc */
8198  values[5] = conf->long_desc;
8199 
8200  /* context */
8201  values[6] = GucContext_Names[conf->context];
8202 
8203  /* vartype */
8204  values[7] = config_type_names[conf->vartype];
8205 
8206  /* source */
8207  values[8] = GucSource_Names[conf->source];
8208 
8209  /* now get the type specific attributes */
8210  switch (conf->vartype)
8211  {
8212  case PGC_BOOL:
8213  {
8214  struct config_bool *lconf = (struct config_bool *) conf;
8215 
8216  /* min_val */
8217  values[9] = NULL;
8218 
8219  /* max_val */
8220  values[10] = NULL;
8221 
8222  /* enumvals */
8223  values[11] = NULL;
8224 
8225  /* boot_val */
8226  values[12] = pstrdup(lconf->boot_val ? "on" : "off");
8227 
8228  /* reset_val */
8229  values[13] = pstrdup(lconf->reset_val ? "on" : "off");
8230  }
8231  break;
8232 
8233  case PGC_INT:
8234  {
8235  struct config_int *lconf = (struct config_int *) conf;
8236 
8237  /* min_val */
8238  snprintf(buffer, sizeof(buffer), "%d", lconf->min);
8239  values[9] = pstrdup(buffer);
8240 
8241  /* max_val */
8242  snprintf(buffer, sizeof(buffer), "%d", lconf->max);
8243  values[10] = pstrdup(buffer);
8244 
8245  /* enumvals */
8246  values[11] = NULL;
8247 
8248  /* boot_val */
8249  snprintf(buffer, sizeof(buffer), "%d", lconf->boot_val);
8250  values[12] = pstrdup(buffer);
8251 
8252  /* reset_val */
8253  snprintf(buffer, sizeof(buffer), "%d", lconf->reset_val);
8254  values[13] = pstrdup(buffer);
8255  }
8256  break;
8257 
8258  case PGC_REAL:
8259  {
8260  struct config_real *lconf = (struct config_real *) conf;
8261 
8262  /* min_val */
8263  snprintf(buffer, sizeof(buffer), "%g", lconf->min);
8264  values[9] = pstrdup(buffer);
8265 
8266  /* max_val */
8267  snprintf(buffer, sizeof(buffer), "%g", lconf->max);
8268  values[10] = pstrdup(buffer);
8269 
8270  /* enumvals */
8271  values[11] = NULL;
8272 
8273  /* boot_val */
8274  snprintf(buffer, sizeof(buffer), "%g", lconf->boot_val);
8275  values[12] = pstrdup(buffer);
8276 
8277  /* reset_val */
8278  snprintf(buffer, sizeof(buffer), "%g", lconf->reset_val);
8279  values[13] = pstrdup(buffer);
8280  }
8281  break;
8282 
8283  case PGC_STRING:
8284  {
8285  struct config_string *lconf = (struct config_string *) conf;
8286 
8287  /* min_val */
8288  values[9] = NULL;
8289 
8290  /* max_val */
8291  values[10] = NULL;
8292 
8293  /* enumvals */
8294  values[11] = NULL;
8295 
8296  /* boot_val */
8297  if (lconf->boot_val == NULL)
8298  values[12] = NULL;
8299  else
8300  values[12] = pstrdup(lconf->boot_val);
8301 
8302  /* reset_val */
8303  if (lconf->reset_val == NULL)
8304  values[13] = NULL;
8305  else
8306  values[13] = pstrdup(lconf->reset_val);
8307  }
8308  break;
8309 
8310  case PGC_ENUM:
8311  {
8312  struct config_enum *lconf = (struct config_enum *) conf;
8313 
8314  /* min_val */
8315  values[9] = NULL;
8316 
8317  /* max_val */
8318  values[10] = NULL;
8319 
8320  /* enumvals */
8321 
8322  /*
8323  * NOTE! enumvals with double quotes in them are not
8324  * supported!
8325  */
8326  values[11] = config_enum_get_options((struct config_enum *) conf,
8327  "{\"", "\"}", "\",\"");
8328 
8329  /* boot_val */
8331  lconf->boot_val));
8332 
8333  /* reset_val */
8335  lconf->reset_val));
8336  }
8337  break;
8338 
8339  default:
8340  {
8341  /*
8342  * should never get here, but in case we do, set 'em to NULL
8343  */
8344 
8345  /* min_val */
8346  values[9] = NULL;
8347 
8348  /* max_val */
8349  values[10] = NULL;
8350 
8351  /* enumvals */
8352  values[11] = NULL;
8353 
8354  /* boot_val */
8355  values[12] = NULL;
8356 
8357  /* reset_val */
8358  values[13] = NULL;
8359  }
8360  break;
8361  }
8362 
8363  /*
8364  * If the setting came from a config file, set the source location. For
8365  * security reasons, we don't show source file/line number for
8366  * non-superusers.
8367  */
8368  if (conf->source == PGC_S_FILE && superuser())
8369  {
8370  values[14] = conf->sourcefile;
8371  snprintf(buffer, sizeof(buffer), "%d", conf->sourceline);
8372  values[15] = pstrdup(buffer);
8373  }
8374  else
8375  {
8376  values[14] = NULL;
8377  values[15] = NULL;
8378  }
8379 
8380  values[16] = (conf->status & GUC_PENDING_RESTART) ? "t" : "f";
8381 }
GucSource source
Definition: guc_tables.h:156
static char * _ShowOption(struct config_generic *record, bool use_units)
Definition: guc.c:8683
const char * long_desc
Definition: guc_tables.h:151
double reset_val
Definition: guc_tables.h:220
Oid GetUserId(void)
Definition: miscinit.c:284
const char * name
Definition: guc_tables.h:147
const char *const config_type_names[]
Definition: guc.c:675
char * pstrdup(const char *in)
Definition: mcxt.c:1063
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:5665
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:529
#define GUC_UNIT_MIN
Definition: guc.h:227
const char *const config_group_names[]
Definition: guc.c:566
#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:3986
#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:3983
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
#define DEFAULT_ROLE_READ_ALL_SETTINGS
Definition: pg_authid.h:106
char * reset_val
Definition: guc_tables.h:234
double boot_val
Definition: guc_tables.h:213
#define Assert(condition)
Definition: c.h:688
#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:545
static char * config_enum_get_options(struct config_enum *record, const char *prefix, const char *suffix, const char *separator)
Definition: guc.c:5714
#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

◆ GetConfigOptionResetString()

const char* GetConfigOptionResetString ( const char *  name)

Definition at line 6800 of file guc.c.

References buffer, config_enum_lookup_by_value(), DEFAULT_ROLE_READ_ALL_SETTINGS, 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().

6801 {
6802  struct config_generic *record;
6803  static char buffer[256];
6804 
6805  record = find_option(name, false, ERROR);
6806  if (record == NULL)
6807  ereport(ERROR,
6808  (errcode(ERRCODE_UNDEFINED_OBJECT),
6809  errmsg("unrecognized configuration parameter \"%s\"", name)));
6810  if ((record->flags & GUC_SUPERUSER_ONLY) &&
6812  ereport(ERROR,
6813  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6814  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
6815  name)));
6816 
6817  switch (record->vartype)
6818  {
6819  case PGC_BOOL:
6820  return ((struct config_bool *) record)->reset_val ? "on" : "off";
6821 
6822  case PGC_INT:
6823  snprintf(buffer, sizeof(buffer), "%d",
6824  ((struct config_int *) record)->reset_val);
6825  return buffer;
6826 
6827  case PGC_REAL:
6828  snprintf(buffer, sizeof(buffer), "%g",
6829  ((struct config_real *) record)->reset_val);
6830  return buffer;
6831 
6832  case PGC_STRING:
6833  return ((struct config_string *) record)->reset_val;
6834 
6835  case PGC_ENUM:
6836  return config_enum_lookup_by_value((struct config_enum *) record,
6837  ((struct config_enum *) record)->reset_val);
6838  }
6839  return NULL;
6840 }
Oid GetUserId(void)
Definition: miscinit.c:284
int errcode(int sqlerrcode)
Definition: elog.c:575
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5665
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
#define DEFAULT_ROLE_READ_ALL_SETTINGS
Definition: pg_authid.h:106
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4420
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 8387 of file guc.c.

References num_guc_variables.

Referenced by GucInfoMain(), and show_all_settings().

8388 {
8389  return num_guc_variables;
8390 }
static int num_guc_variables
Definition: guc.c:3986

◆ GetPGVariable()

void GetPGVariable ( const char *  name,
DestReceiver dest 
)

Definition at line 7941 of file guc.c.

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

Referenced by exec_replication_command(), and standard_ProcessUtility().

7942 {
7943  if (guc_name_compare(name, "all") == 0)
7944  ShowAllGUCConfig(dest);
7945  else
7946  ShowGUCConfigOption(name, dest);
7947 }
static void ShowGUCConfigOption(const char *name, DestReceiver *dest)
Definition: guc.c:7985
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:4481
static void ShowAllGUCConfig(DestReceiver *dest)
Definition: guc.c:8013
const char * name
Definition: encode.c:521

◆ GetPGVariableResultDesc()

TupleDesc GetPGVariableResultDesc ( const char *  name)

Definition at line 7950 of file guc.c.

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

Referenced by UtilityTupleDescriptor().

7951 {
7952  TupleDesc tupdesc;
7953 
7954  if (guc_name_compare(name, "all") == 0)
7955  {
7956  /* need a tuple descriptor representing three TEXT columns */
7957  tupdesc = CreateTemplateTupleDesc(3, false);
7958  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
7959  TEXTOID, -1, 0);
7960  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
7961  TEXTOID, -1, 0);
7962  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
7963  TEXTOID, -1, 0);
7964  }
7965  else
7966  {
7967  const char *varname;
7968 
7969  /* Get the canonical spelling of name */
7970  (void) GetConfigOptionByName(name, &varname, false);
7971 
7972  /* need a tuple descriptor representing a single TEXT column */
7973  tupdesc = CreateTemplateTupleDesc(1, false);
7974  TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
7975  TEXTOID, -1, 0);
7976  }
7977  return tupdesc;
7978 }
#define TEXTOID
Definition: pg_type.h:324
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:4481
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:8082
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:543
TupleDesc CreateTemplateTupleDesc(int natts, bool hasoid)
Definition: tupdesc.c:43
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 9816 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().

9817 {
9818  GUC_check_errcode_value = sqlerrcode;
9819 }
static int GUC_check_errcode_value
Definition: guc.c:128

◆ GUCArrayAdd()

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

Definition at line 9513 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, TEXTOID, validate_option_array_item(), and WARNING.

Referenced by AlterSetting(), and update_proconfig_value().

9514 {
9515  struct config_generic *record;
9516  Datum datum;
9517  char *newval;
9518  ArrayType *a;
9519 
9520  Assert(name);
9521  Assert(value);
9522 
9523  /* test if the option is valid and we're allowed to set it */
9524  (void) validate_option_array_item(name, value, false);
9525 
9526  /* normalize name (converts obsolete GUC names to modern spellings) */
9527  record = find_option(name, false, WARNING);
9528  if (record)
9529  name = record->name;
9530 
9531  /* build new item for array */
9532  newval = psprintf("%s=%s", name, value);
9533  datum = CStringGetTextDatum(newval);
9534 
9535  if (array)
9536  {
9537  int index;
9538  bool isnull;
9539  int i;
9540 
9541  Assert(ARR_ELEMTYPE(array) == TEXTOID);
9542  Assert(ARR_NDIM(array) == 1);
9543  Assert(ARR_LBOUND(array)[0] == 1);
9544 
9545  index = ARR_DIMS(array)[0] + 1; /* add after end */
9546 
9547  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9548  {
9549  Datum d;
9550  char *current;
9551 
9552  d = array_ref(array, 1, &i,
9553  -1 /* varlenarray */ ,
9554  -1 /* TEXT's typlen */ ,
9555  false /* TEXT's typbyval */ ,
9556  'i' /* TEXT's typalign */ ,
9557  &isnull);
9558  if (isnull)
9559  continue;
9560  current = TextDatumGetCString(d);
9561 
9562  /* check for match up through and including '=' */
9563  if (strncmp(current, newval, strlen(name) + 1) == 0)
9564  {
9565  index = i;
9566  break;
9567  }
9568  }
9569 
9570  a = array_set(array, 1, &index,
9571  datum,
9572  false,
9573  -1 /* varlena array */ ,
9574  -1 /* TEXT's typlen */ ,
9575  false /* TEXT's typbyval */ ,
9576  'i' /* TEXT's typalign */ );
9577  }
9578  else
9579  a = construct_array(&datum, 1,
9580  TEXTOID,
9581  -1, false, 'i');
9582 
9583  return a;
9584 }
static struct @130 value
const char * name
Definition: guc_tables.h:147
#define TEXTOID
Definition: pg_type.h:324
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:9739
#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:92
uintptr_t Datum
Definition: postgres.h:365
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4420
#define Assert(condition)
Definition: c.h:688
#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:91
#define ARR_ELEMTYPE(a)
Definition: array.h:277

◆ GUCArrayDelete()

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

Definition at line 9593 of file guc.c.

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

Referenced by AlterSetting(), and update_proconfig_value().

9594 {
9595  struct config_generic *record;
9596  ArrayType *newarray;
9597  int i;
9598  int index;
9599 
9600  Assert(name);
9601 
9602  /* test if the option is valid and we're allowed to set it */
9603  (void) validate_option_array_item(name, NULL, false);
9604 
9605  /* normalize name (converts obsolete GUC names to modern spellings) */
9606  record = find_option(name, false, WARNING);
9607  if (record)
9608  name = record->name;
9609 
9610  /* if array is currently null, then surely nothing to delete */
9611  if (!array)
9612  return NULL;
9613 
9614  newarray = NULL;
9615  index = 1;
9616 
9617  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9618  {
9619  Datum d;
9620  char *val;
9621  bool isnull;
9622 
9623  d = array_ref(array, 1, &i,
9624  -1 /* varlenarray */ ,
9625  -1 /* TEXT's typlen */ ,
9626  false /* TEXT's typbyval */ ,
9627  'i' /* TEXT's typalign */ ,
9628  &isnull);
9629  if (isnull)
9630  continue;
9631  val = TextDatumGetCString(d);
9632 
9633  /* ignore entry if it's what we want to delete */
9634  if (strncmp(val, name, strlen(name)) == 0
9635  && val[strlen(name)] == '=')
9636  continue;
9637 
9638  /* else add it to the output array */
9639  if (newarray)
9640  newarray = array_set(newarray, 1, &index,
9641  d,
9642  false,
9643  -1 /* varlenarray */ ,
9644  -1 /* TEXT's typlen */ ,
9645  false /* TEXT's typbyval */ ,
9646  'i' /* TEXT's typalign */ );
9647  else
9648  newarray = construct_array(&d, 1,
9649  TEXTOID,
9650  -1, false, 'i');
9651 
9652  index++;
9653  }
9654 
9655  return newarray;
9656 }
const char * name
Definition: guc_tables.h:147
#define TEXTOID
Definition: pg_type.h:324
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:9739
#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:92
uintptr_t Datum
Definition: postgres.h:365
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4420
#define Assert(condition)
Definition: c.h:688
const char * name
Definition: encode.c:521
int i
long val
Definition: informix.c:689

◆ GUCArrayReset()

ArrayType* GUCArrayReset ( ArrayType array)

Definition at line 9665 of file guc.c.

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

Referenced by AlterSetting().

9666 {
9667  ArrayType *newarray;
9668  int i;
9669  int index;
9670 
9671  /* if array is currently null, nothing to do */
9672  if (!array)
9673  return NULL;
9674 
9675  /* if we're superuser, we can delete everything, so just do it */
9676  if (superuser())
9677  return NULL;
9678 
9679  newarray = NULL;
9680  index = 1;
9681 
9682  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9683  {
9684  Datum d;
9685  char *val;
9686  char *eqsgn;
9687  bool isnull;
9688 
9689  d = array_ref(array, 1, &i,
9690  -1 /* varlenarray */ ,
9691  -1 /* TEXT's typlen */ ,
9692  false /* TEXT's typbyval */ ,
9693  'i' /* TEXT's typalign */ ,
9694  &isnull);
9695  if (isnull)
9696  continue;
9697  val = TextDatumGetCString(d);
9698 
9699  eqsgn = strchr(val, '=');
9700  *eqsgn = '\0';
9701 
9702  /* skip if we have permission to delete it */
9703  if (validate_option_array_item(val, NULL, true))
9704  continue;
9705 
9706  /* else add it to the output array */
9707  if (newarray)
9708  newarray = array_set(newarray, 1, &index,
9709  d,
9710  false,
9711  -1 /* varlenarray */ ,
9712  -1 /* TEXT's typlen */ ,
9713  false /* TEXT's typbyval */ ,
9714  'i' /* TEXT's typalign */ );
9715  else
9716  newarray = construct_array(&d, 1,
9717  TEXTOID,
9718  -1, false, 'i');
9719 
9720  index++;
9721  pfree(val);
9722  }
9723 
9724  return newarray;
9725 }
#define TEXTOID
Definition: pg_type.h:324
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:936
static bool validate_option_array_item(const char *name, const char *value, bool skipIfNoPermissions)
Definition: guc.c:9739
#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:92
uintptr_t Datum
Definition: postgres.h:365
int i
long val
Definition: informix.c:689

◆ InitializeGUCOptions()

void InitializeGUCOptions ( void  )

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

4516 {
4517  int i;
4518 
4519  /*
4520  * Before log_line_prefix could possibly receive a nonempty setting, make
4521  * sure that timezone processing is minimally alive (see elog.c).
4522  */
4524 
4525  /*
4526  * Build sorted array of all GUC variables.
4527  */
4529 
4530  /*
4531  * Load all variables with their compiled-in defaults, and initialize
4532  * status fields as needed.
4533  */
4534  for (i = 0; i < num_guc_variables; i++)
4535  {
4537  }
4538 
4539  guc_dirty = false;
4540 
4541  reporting_enabled = false;
4542 
4543  /*
4544  * Prevent any attempt to override the transaction modes from
4545  * non-interactive sources.
4546  */
4547  SetConfigOption("transaction_isolation", "default",
4549  SetConfigOption("transaction_read_only", "no",
4551  SetConfigOption("transaction_deferrable", "no",
4553 
4554  /*
4555  * For historical reasons, some GUC parameters can receive defaults from
4556  * environment variables. Process those settings.
4557  */
4559 }
void build_guc_variables(void)
Definition: guc.c:4247
static void InitializeGUCOptionsFromEnvironment(void)
Definition: guc.c:4571
void pg_timezone_initialize(void)
Definition: pgtz.c:363
static int num_guc_variables
Definition: guc.c:3986
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:6720
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:4617
static struct config_generic ** guc_variables
Definition: guc.c:3983
int i
static bool reporting_enabled
Definition: guc.c:3994
static bool guc_dirty
Definition: guc.c:3992

◆ NewGUCNestLevel()

◆ parse_int()

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

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

5546 {
5547  int64 val;
5548  char *endptr;
5549 
5550  /* To suppress compiler warnings, always set output params */
5551  if (result)
5552  *result = 0;
5553  if (hintmsg)
5554  *hintmsg = NULL;
5555 
5556  /* We assume here that int64 is at least as wide as long */
5557  errno = 0;
5558  val = strtol(value, &endptr, 0);
5559 
5560  if (endptr == value)
5561  return false; /* no HINT for integer syntax error */
5562 
5563  if (errno == ERANGE || val != (int64) ((int32) val))
5564  {
5565  if (hintmsg)
5566  *hintmsg = gettext_noop("Value exceeds integer range.");
5567  return false;
5568  }
5569 
5570  /* allow whitespace between integer and unit */
5571  while (isspace((unsigned char) *endptr))
5572  endptr++;
5573 
5574  /* Handle possible unit */
5575  if (*endptr != '\0')
5576  {
5577  char unit[MAX_UNIT_LEN + 1];
5578  int unitlen;
5579  bool converted = false;
5580 
5581  if ((flags & GUC_UNIT) == 0)
5582  return false; /* this setting does not accept a unit */
5583 
5584  unitlen = 0;
5585  while (*endptr != '\0' && !isspace((unsigned char) *endptr) &&
5586  unitlen < MAX_UNIT_LEN)
5587  unit[unitlen++] = *(endptr++);
5588  unit[unitlen] = '\0';
5589  /* allow whitespace after unit */
5590  while (isspace((unsigned char) *endptr))
5591  endptr++;
5592 
5593  if (*endptr == '\0')
5594  converted = convert_to_base_unit(val, unit, (flags & GUC_UNIT),
5595  &val);
5596  if (!converted)
5597  {
5598  /* invalid unit, or garbage after the unit; set hint and fail. */
5599  if (hintmsg)
5600  {
5601  if (flags & GUC_UNIT_MEMORY)
5602  *hintmsg = memory_units_hint;
5603  else
5604  *hintmsg = time_units_hint;
5605  }
5606  return false;
5607  }
5608 
5609  /* Check for overflow due to units conversion */
5610  if (val != (int64) ((int32) val))
5611  {
5612  if (hintmsg)
5613  *hintmsg = gettext_noop("Value exceeds integer range.");
5614  return false;
5615  }
5616  }
5617 
5618  if (result)
5619  *result = (int) val;
5620  return true;
5621 }
static struct @130 value
#define MAX_UNIT_LEN
Definition: guc.c:699
#define gettext_noop(x)
Definition: c.h:1025
#define GUC_UNIT
Definition: guc.h:230
signed int int32
Definition: c.h:302
static const char * time_units_hint
Definition: guc.c:751
static bool convert_to_base_unit(int64 value, const char *unit, int base_unit, int64 *base_value)
Definition: guc.c:5460
long val
Definition: informix.c:689
static const char * memory_units_hint
Definition: guc.c:719
#define GUC_UNIT_MEMORY
Definition: guc.h:223

◆ parse_real()

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

Definition at line 5631 of file guc.c.

References val.

Referenced by parse_and_validate_value(), and parse_one_reloption().

5632 {
5633  double val;
5634  char *endptr;
5635 
5636  if (result)
5637  *result = 0; /* suppress compiler warning */
5638 
5639  errno = 0;
5640  val = strtod(value, &endptr);
5641  if (endptr == value || errno == ERANGE)
5642  return false;
5643 
5644  /* allow whitespace after number */
5645  while (isspace((unsigned char) *endptr))
5646  endptr++;
5647  if (*endptr != '\0')
5648  return false;
5649 
5650  if (result)
5651  *result = val;
5652  return true;
5653 }
static struct @130 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 9417 of file guc.c.

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

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

9418 {
9419  size_t equal_pos;
9420  char *cp;
9421 
9422  AssertArg(string);
9423  AssertArg(name);
9424  AssertArg(value);
9425 
9426  equal_pos = strcspn(string, "=");
9427 
9428  if (string[equal_pos] == '=')
9429  {
9430  *name = guc_malloc(FATAL, equal_pos + 1);
9431  strlcpy(*name, string, equal_pos + 1);
9432 
9433  *value = guc_strdup(FATAL, &string[equal_pos + 1]);
9434  }
9435  else
9436  {
9437  /* no equal sign in string */
9438  *name = guc_strdup(FATAL, string);
9439  *value = NULL;
9440  }
9441 
9442  for (cp = *name; *cp; cp++)
9443  if (*cp == '-')
9444  *cp = '_';
9445 }
static struct @130 value
static char * guc_strdup(int elevel, const char *src)
Definition: guc.c:4056
#define FATAL
Definition: elog.h:52
#define AssertArg(condition)
Definition: c.h:690
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:4024

◆ ProcessConfigFile()

◆ ProcessGUCArray()

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

Definition at line 9455 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, TEXTOID, value, and WARNING.

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

9457 {
9458  int i;
9459 
9460  Assert(array != NULL);
9461  Assert(ARR_ELEMTYPE(array) == TEXTOID);
9462  Assert(ARR_NDIM(array) == 1);
9463  Assert(ARR_LBOUND(array)[0] == 1);
9464 
9465  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9466  {
9467  Datum d;
9468  bool isnull;
9469  char *s;
9470  char *name;
9471  char *value;
9472 
9473  d = array_ref(array, 1, &i,
9474  -1 /* varlenarray */ ,
9475  -1 /* TEXT's typlen */ ,
9476  false /* TEXT's typbyval */ ,
9477  'i' /* TEXT's typalign */ ,
9478  &isnull);
9479 
9480  if (isnull)
9481  continue;
9482 
9483  s = TextDatumGetCString(d);
9484 
9485  ParseLongOption(s, &name, &value);
9486  if (!value)
9487  {
9488  ereport(WARNING,
9489  (errcode(ERRCODE_SYNTAX_ERROR),
9490  errmsg("could not parse setting for parameter \"%s\"",
9491  name)));
9492  free(name);
9493  continue;
9494  }
9495 
9496  (void) set_config_option(name, value,
9497  context, source,
9498  action, true, 0, false);
9499 
9500  free(name);
9501  if (value)
9502  free(value);
9503  pfree(s);
9504  }
9505 }
GucSource source
Definition: guc_tables.h:156
static struct @130 value
#define TEXTOID
Definition: pg_type.h:324
void ParseLongOption(const char *string, char **name, char **value)
Definition: guc.c:9417
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ARR_LBOUND(a)
Definition: array.h:281
void pfree(void *pointer)
Definition: mcxt.c:936
#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:92
uintptr_t Datum
Definition: postgres.h:365
#define free(a)
Definition: header.h:65
#define Assert(condition)
Definition: c.h:688
#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:5956
#define ARR_ELEMTYPE(a)
Definition: array.h:277
GucContext context
Definition: guc_tables.h:148

◆ ResetAllOptions()

void ResetAllOptions ( void  )

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

4913 {
4914  int i;
4915 
4916  for (i = 0; i < num_guc_variables; i++)
4917  {
4918  struct config_generic *gconf = guc_variables[i];
4919 
4920  /* Don't reset non-SET-able values */
4921  if (gconf->context != PGC_SUSET &&
4922  gconf->context != PGC_USERSET)
4923  continue;
4924  /* Don't reset if special exclusion from RESET ALL */
4925  if (gconf->flags & GUC_NO_RESET_ALL)
4926  continue;
4927  /* No need to reset if wasn't SET */
4928  if (gconf->source <= PGC_S_OVERRIDE)
4929  continue;
4930 
4931  /* Save old value to support transaction abort */
4933 
4934  switch (gconf->vartype)
4935  {
4936  case PGC_BOOL:
4937  {
4938  struct config_bool *conf = (struct config_bool *) gconf;
4939 
4940  if (conf->assign_hook)
4941  conf->assign_hook(conf->reset_val,
4942  conf->reset_extra);
4943  *conf->variable = conf->reset_val;
4944  set_extra_field(&conf->gen, &conf->gen.extra,
4945  conf->reset_extra);
4946  break;
4947  }
4948  case PGC_INT:
4949  {
4950  struct config_int *conf = (struct config_int *) gconf;
4951 
4952  if (conf->assign_hook)
4953  conf->assign_hook(conf->reset_val,
4954  conf->reset_extra);
4955  *conf->variable = conf->reset_val;
4956  set_extra_field(&conf->gen, &conf->gen.extra,
4957  conf->reset_extra);
4958  break;
4959  }
4960  case PGC_REAL:
4961  {
4962  struct config_real *conf = (struct config_real *) gconf;
4963 
4964  if (conf->assign_hook)
4965  conf->assign_hook(conf->reset_val,
4966  conf->reset_extra);
4967  *conf->variable = conf->reset_val;
4968  set_extra_field(&conf->gen, &conf->gen.extra,
4969  conf->reset_extra);
4970  break;
4971  }
4972  case PGC_STRING:
4973  {
4974  struct config_string *conf = (struct config_string *) gconf;
4975 
4976  if (conf->assign_hook)
4977  conf->assign_hook(conf->reset_val,
4978  conf->reset_extra);
4979  set_string_field(conf, conf->variable, conf->reset_val);
4980  set_extra_field(&conf->gen, &conf->gen.extra,
4981  conf->reset_extra);
4982  break;
4983  }
4984  case PGC_ENUM:
4985  {
4986  struct config_enum *conf = (struct config_enum *) gconf;
4987 
4988  if (conf->assign_hook)
4989  conf->assign_hook(conf->reset_val,
4990  conf->reset_extra);
4991  *conf->variable = conf->reset_val;
4992  set_extra_field(&conf->gen, &conf->gen.extra,
4993  conf->reset_extra);
4994  break;
4995  }
4996  }
4997 
4998  gconf->source = gconf->reset_source;
4999  gconf->scontext = gconf->reset_scontext;
5000 
5001  if (gconf->flags & GUC_REPORT)
5002  ReportGUCOption(gconf);
5003  }
5004 }
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:5012
int * variable
Definition: guc_tables.h:196
int * variable
Definition: guc_tables.h:242
static int num_guc_variables
Definition: guc.c:3986
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:4157
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:4096
static struct config_generic ** guc_variables
Definition: guc.c:3983
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:5436
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 9359 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().

9360 {
9361  char *varname,
9362  *varvalue,
9363  *varsourcefile;
9364  int varsourceline;
9365  GucSource varsource;
9366  GucContext varscontext;
9367  char *srcptr = (char *) gucstate;
9368  char *srcend;
9369  Size len;
9370  int i;
9371 
9372  /* See comment at can_skip_gucvar(). */
9373  for (i = 0; i < num_guc_variables; i++)
9374  if (!can_skip_gucvar(guc_variables[i]))
9376 
9377  /* First item is the length of the subsequent data */
9378  memcpy(&len, gucstate, sizeof(len));
9379 
9380  srcptr += sizeof(len);
9381  srcend = srcptr + len;
9382 
9383  while (srcptr < srcend)
9384  {
9385  int result;
9386 
9387  varname = read_gucstate(&srcptr, srcend);
9388  varvalue = read_gucstate(&srcptr, srcend);
9389  varsourcefile = read_gucstate(&srcptr, srcend);
9390  if (varsourcefile[0])
9391  read_gucstate_binary(&srcptr, srcend,
9392  &varsourceline, sizeof(varsourceline));
9393  read_gucstate_binary(&srcptr, srcend,
9394  &varsource, sizeof(varsource));
9395  read_gucstate_binary(&srcptr, srcend,
9396  &varscontext, sizeof(varscontext));
9397 
9398  result = set_config_option(varname, varvalue, varscontext, varsource,
9399  GUC_ACTION_SET, true, ERROR, true);
9400  if (result <= 0)
9401  ereport(ERROR,
9402  (errcode(ERRCODE_INTERNAL_ERROR),
9403  errmsg("parameter \"%s\" could not be set", varname)));
9404  if (varsourcefile[0])
9405  set_config_sourcefile(varname, varsourcefile, varsourceline);
9406  }
9407 }
GucContext
Definition: guc.h:68
static void static void set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
Definition: guc.c:6686
static void read_gucstate_binary(char **srcptr, char *srcend, void *dest, Size size)
Definition: guc.c:9344
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:3986
static bool can_skip_gucvar(struct config_generic *gconf)
Definition: guc.c:9035
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:4617
#define ereport(elevel, rest)
Definition: elog.h:122
static struct config_generic ** guc_variables
Definition: guc.c:3983
static char * read_gucstate(char **srcptr, char *srcend)
Definition: guc.c:9321
size_t Size
Definition: c.h:422
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:5956

◆ SelectConfigFiles()

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

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

4738 {
4739  char *configdir;
4740  char *fname;
4741  struct stat stat_buf;
4742 
4743  /* configdir is -D option, or $PGDATA if no -D */
4744  if (userDoption)
4745  configdir = make_absolute_path(userDoption);
4746  else
4747  configdir = make_absolute_path(getenv("PGDATA"));
4748 
4749  if (configdir && stat(configdir, &stat_buf) != 0)
4750  {
4751  write_stderr("%s: could not access directory \"%s\": %s\n",
4752  progname,
4753  configdir,
4754  strerror(errno));
4755  if (errno == ENOENT)
4756  write_stderr("Run initdb or pg_basebackup to initialize a PostgreSQL data directory.\n");
4757  return false;
4758  }
4759 
4760  /*
4761  * Find the configuration file: if config_file was specified on the
4762  * command line, use it, else use configdir/postgresql.conf. In any case
4763  * ensure the result is an absolute path, so that it will be interpreted
4764  * the same way by future backends.
4765  */
4766  if (ConfigFileName)
4768  else if (configdir)
4769  {
4770  fname = guc_malloc(FATAL,
4771  strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
4772  sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
4773  }
4774  else
4775  {
4776  write_stderr("%s does not know where to find the server configuration file.\n"
4777  "You must specify the --config-file or -D invocation "
4778  "option or set the PGDATA environment variable.\n",
4779  progname);
4780  return false;
4781  }
4782 
4783  /*
4784  * Set the ConfigFileName GUC variable to its final value, ensuring that
4785  * it can't be overridden later.
4786  */
4787  SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4788  free(fname);
4789 
4790  /*
4791  * Now read the config file for the first time.
4792  */
4793  if (stat(ConfigFileName, &stat_buf) != 0)
4794  {
4795  write_stderr("%s: could not access the server configuration file \"%s\": %s\n",
4796  progname, ConfigFileName, strerror(errno));
4797  free(configdir);
4798  return false;
4799  }
4800 
4801  /*
4802  * Read the configuration file for the first time. This time only the
4803  * data_directory parameter is picked up to determine the data directory,
4804  * so that we can read the PG_AUTOCONF_FILENAME file next time.
4805  */
4807 
4808  /*
4809  * If the data_directory GUC variable has been set, use that as DataDir;
4810  * otherwise use configdir if set; else punt.
4811  *
4812  * Note: SetDataDir will copy and absolute-ize its argument, so we don't
4813  * have to.
4814  */
4815  if (data_directory)
4817  else if (configdir)
4818  SetDataDir(configdir);
4819  else
4820  {
4821  write_stderr("%s does not know where to find the database system data.\n"
4822  "This can be specified as \"data_directory\" in \"%s\", "
4823  "or by the -D invocation option, or by the "
4824  "PGDATA environment variable.\n",
4826  return false;
4827  }
4828 
4829  /*
4830  * Reflect the final DataDir value back into the data_directory GUC var.
4831  * (If you are wondering why we don't just make them a single variable,
4832  * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
4833  * child backends specially. XXX is that still true? Given that we now
4834  * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
4835  * DataDir in advance.)
4836  */
4838 
4839  /*
4840  * Now read the config file a second time, allowing any settings in the
4841  * PG_AUTOCONF_FILENAME file to take effect. (This is pretty ugly, but
4842  * since we have to determine the DataDir before we can find the autoconf
4843  * file, the alternatives seem worse.)
4844  */
4846 
4847  /*
4848  * If timezone_abbreviations wasn't set in the configuration file, install
4849  * the default value. We do it this way because we can't safely install a
4850  * "real" value until my_exec_path is set, which may not have happened
4851  * when InitializeGUCOptions runs, so the bootstrap default value cannot
4852  * be the real desired default.
4853  */
4855 
4856  /*
4857  * Figure out where pg_hba.conf is, and make sure the path is absolute.
4858  */
4859  if (HbaFileName)
4861  else if (configdir)
4862  {
4863  fname = guc_malloc(FATAL,
4864  strlen(configdir) + strlen(HBA_FILENAME) + 2);
4865  sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
4866  }
4867  else
4868  {
4869  write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
4870  "This can be specified as \"hba_file\" in \"%s\", "
4871  "or by the -D invocation option, or by the "
4872  "PGDATA environment variable.\n",
4874  return false;
4875  }
4876  SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4877  free(fname);
4878 
4879  /*
4880  * Likewise for pg_ident.conf.
4881  */
4882  if (IdentFileName)
4884  else if (configdir)
4885  {
4886  fname = guc_malloc(FATAL,
4887  strlen(configdir) + strlen(IDENT_FILENAME) + 2);
4888  sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
4889  }
4890  else
4891  {
4892  write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
4893  "This can be specified as \"ident_file\" in \"%s\", "
4894  "or by the -D invocation option, or by the "
4895  "PGDATA environment variable.\n",
4897  return false;
4898  }
4899  SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4900  free(fname);
4901 
4902  free(configdir);
4903 
4904  return true;
4905 }
char * make_absolute_path(const char *path)
Definition: path.c:608
void ProcessConfigFile(GucContext context)
void SetDataDir(const char *dir)
Definition: miscinit.c:95
char * ConfigFileName
Definition: guc.c:463
static void pg_timezone_abbrev_initialize(void)
Definition: guc.c:10307
#define CONFIG_FILENAME
Definition: guc.c:97
#define write_stderr(str)
Definition: parallel.c:182
const char * progname
Definition: pg_standby.c:37
char * HbaFileName
Definition: guc.c:464
#define HBA_FILENAME
Definition: guc.c:98
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:6720
char * IdentFileName
Definition: guc.c:465
#define stat(a, b)
Definition: win32_port.h:266
#define IDENT_FILENAME
Definition: guc.c:99
#define free(a)
Definition: header.h:65
static const char * userDoption
Definition: postgres.c:159
const char * strerror(int errnum)
Definition: strerror.c:19
char * DataDir
Definition: globals.c:60
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4024
static char * data_directory
Definition: guc.c:508

◆ SerializeGUCState()

void SerializeGUCState ( Size  maxsize,
char *  start_address 
)

Definition at line 9294 of file guc.c.

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

Referenced by InitializeParallelDSM().

9295 {
9296  char *curptr;
9297  Size actual_size;
9298  Size bytes_left;
9299  int i;
9300 
9301  /* Reserve space for saving the actual size of the guc state */
9302  Assert(maxsize > sizeof(actual_size));
9303  curptr = start_address + sizeof(actual_size);
9304  bytes_left = maxsize - sizeof(actual_size);
9305 
9306  for (i = 0; i < num_guc_variables; i++)
9307  serialize_variable(&curptr, &bytes_left, guc_variables[i]);
9308 
9309  /* Store actual size without assuming alignment of start_address. */
9310  actual_size = maxsize - bytes_left - sizeof(actual_size);
9311  memcpy(start_address, &actual_size, sizeof(actual_size));
9312 }
static void serialize_variable(char **destptr, Size *maxbytes, struct config_generic *gconf)
Definition: guc.c:9220
static int num_guc_variables
Definition: guc.c:3986
static struct config_generic ** guc_variables
Definition: guc.c:3983
#define Assert(condition)
Definition: c.h:688
size_t Size
Definition: c.h:422
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 5956 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().

5960 {
5961  struct config_generic *record;
5962  union config_var_val newval_union;
5963  void *newextra = NULL;
5964  bool prohibitValueChange = false;
5965  bool makeDefault;
5966 
5967  if (elevel == 0)
5968  {
5969  if (source == PGC_S_DEFAULT || source == PGC_S_FILE)
5970  {
5971  /*
5972  * To avoid cluttering the log, only the postmaster bleats loudly
5973  * about problems with the config file.
5974  */
5976  }
5977  else if (source == PGC_S_GLOBAL ||
5978  source == PGC_S_DATABASE ||
5979  source == PGC_S_USER ||
5980  source == PGC_S_DATABASE_USER)
5981  elevel = WARNING;
5982  else
5983  elevel = ERROR;
5984  }
5985 
5986  /*
5987  * GUC_ACTION_SAVE changes are acceptable during a parallel operation,
5988  * because the current worker will also pop the change. We're probably
5989  * dealing with a function having a proconfig entry. Only the function's
5990  * body should observe the change, and peer workers do not share in the
5991  * execution of a function call started by this worker.
5992  *
5993  * Other changes might need to affect other workers, so forbid them.
5994  */
5995  if (IsInParallelMode() && changeVal && action != GUC_ACTION_SAVE)
5996  ereport(elevel,
5997  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
5998  errmsg("cannot set parameters during a parallel operation")));
5999 
6000  record = find_option(name, true, elevel);
6001  if (record == NULL)
6002  {
6003  ereport(elevel,
6004  (errcode(ERRCODE_UNDEFINED_OBJECT),
6005  errmsg("unrecognized configuration parameter \"%s\"", name)));
6006  return 0;
6007  }
6008 
6009  /*
6010  * Check if the option can be set at this time. See guc.h for the precise
6011  * rules.
6012  */
6013  switch (record->context)
6014  {
6015  case PGC_INTERNAL:
6016  if (context != PGC_INTERNAL)
6017  {
6018  ereport(elevel,
6019  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6020  errmsg("parameter \"%s\" cannot be changed",
6021  name)));
6022  return 0;
6023  }
6024  break;
6025  case PGC_POSTMASTER:
6026  if (context == PGC_SIGHUP)
6027  {
6028  /*
6029  * We are re-reading a PGC_POSTMASTER variable from
6030  * postgresql.conf. We can't change the setting, so we should
6031  * give a warning if the DBA tries to change it. However,
6032  * because of variant formats, canonicalization by check
6033  * hooks, etc, we can't just compare the given string directly
6034  * to what's stored. Set a flag to check below after we have
6035  * the final storable value.
6036  */
6037  prohibitValueChange = true;
6038  }
6039  else if (context != PGC_POSTMASTER)
6040  {
6041  ereport(elevel,
6042  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6043  errmsg("parameter \"%s\" cannot be changed without restarting the server",
6044  name)));
6045  return 0;
6046  }
6047  break;
6048  case PGC_SIGHUP:
6049  if (context != PGC_SIGHUP && context != PGC_POSTMASTER)
6050  {
6051  ereport(elevel,
6052  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6053  errmsg("parameter \"%s\" cannot be changed now",
6054  name)));
6055  return 0;
6056  }
6057 
6058  /*
6059  * Hmm, the idea of the SIGHUP context is "ought to be global, but
6060  * can be changed after postmaster start". But there's nothing
6061  * that prevents a crafty administrator from sending SIGHUP
6062  * signals to individual backends only.
6063  */
6064  break;
6065  case PGC_SU_BACKEND:
6066  /* Reject if we're connecting but user is not superuser */
6067  if (context == PGC_BACKEND)
6068  {
6069  ereport(elevel,
6070  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6071  errmsg("permission denied to set parameter \"%s\"",
6072  name)));
6073  return 0;
6074  }
6075  /* FALL THRU to process the same as PGC_BACKEND */
6076  case PGC_BACKEND:
6077  if (context == PGC_SIGHUP)
6078  {
6079  /*
6080  * If a PGC_BACKEND or PGC_SU_BACKEND parameter is changed in
6081  * the config file, we want to accept the new value in the
6082  * postmaster (whence it will propagate to
6083  * subsequently-started backends), but ignore it in existing
6084  * backends. This is a tad klugy, but necessary because we
6085  * don't re-read the config file during backend start.
6086  *
6087  * In EXEC_BACKEND builds, this works differently: we load all
6088  * non-default settings from the CONFIG_EXEC_PARAMS file
6089  * during backend start. In that case we must accept
6090  * PGC_SIGHUP settings, so as to have the same value as if
6091  * we'd forked from the postmaster. This can also happen when
6092  * using RestoreGUCState() within a background worker that
6093  * needs to have the same settings as the user backend that
6094  * started it. is_reload will be true when either situation
6095  * applies.
6096  */
6097  if (IsUnderPostmaster && !is_reload)
6098  return -1;
6099  }
6100  else if (context != PGC_POSTMASTER &&
6101  context != PGC_BACKEND &&
6102  context != PGC_SU_BACKEND &&
6103  source != PGC_S_CLIENT)
6104  {
6105  ereport(elevel,
6106  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6107  errmsg("parameter \"%s\" cannot be set after connection start",
6108  name)));
6109  return 0;
6110  }
6111  break;
6112  case PGC_SUSET:
6113  if (context == PGC_USERSET || context == PGC_BACKEND)
6114  {
6115  ereport(elevel,
6116  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6117  errmsg("permission denied to set parameter \"%s\"",
6118  name)));
6119  return 0;
6120  }
6121  break;
6122  case PGC_USERSET:
6123  /* always okay */
6124  break;
6125  }
6126 
6127  /*
6128  * Disallow changing GUC_NOT_WHILE_SEC_REST values if we are inside a
6129  * security restriction context. We can reject this regardless of the GUC
6130  * context or source, mainly because sources that it might be reasonable
6131  * to override for won't be seen while inside a function.
6132  *
6133  * Note: variables marked GUC_NOT_WHILE_SEC_REST should usually be marked
6134  * GUC_NO_RESET_ALL as well, because ResetAllOptions() doesn't check this.
6135  * An exception might be made if the reset value is assumed to be "safe".
6136  *
6137  * Note: this flag is currently used for "session_authorization" and
6138  * "role". We need to prohibit changing these inside a local userid
6139  * context because when we exit it, GUC won't be notified, leaving things
6140  * out of sync. (This could be fixed by forcing a new GUC nesting level,
6141  * but that would change behavior in possibly-undesirable ways.) Also, we
6142  * prohibit changing these in a security-restricted operation because
6143  * otherwise RESET could be used to regain the session user's privileges.
6144  */
6145  if (record->flags & GUC_NOT_WHILE_SEC_REST)
6146  {
6147  if (InLocalUserIdChange())
6148  {
6149  /*
6150  * Phrasing of this error message is historical, but it's the most
6151  * common case.
6152  */
6153  ereport(elevel,
6154  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6155  errmsg("cannot set parameter \"%s\" within security-definer function",
6156  name)));
6157  return 0;
6158  }
6160  {
6161  ereport(elevel,
6162  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6163  errmsg("cannot set parameter \"%s\" within security-restricted operation",
6164  name)));
6165  return 0;
6166  }
6167  }
6168 
6169  /*
6170  * Should we set reset/stacked values? (If so, the behavior is not
6171  * transactional.) This is done either when we get a default value from
6172  * the database's/user's/client's default settings or when we reset a
6173  * value to its default.
6174  */
6175  makeDefault = changeVal && (source <= PGC_S_OVERRIDE) &&
6176  ((value != NULL) || source == PGC_S_DEFAULT);
6177 
6178  /*
6179  * Ignore attempted set if overridden by previously processed setting.
6180  * However, if changeVal is false then plow ahead anyway since we are
6181  * trying to find out if the value is potentially good, not actually use
6182  * it. Also keep going if makeDefault is true, since we may want to set
6183  * the reset/stacked values even if we can't set the variable itself.
6184  */
6185  if (record->source > source)
6186  {
6187  if (changeVal && !makeDefault)
6188  {
6189  elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
6190  name);
6191  return -1;
6192  }
6193  changeVal = false;
6194  }
6195 
6196  /*
6197  * Evaluate value and set variable.
6198  */
6199  switch (record->vartype)
6200  {
6201  case PGC_BOOL:
6202  {
6203  struct config_bool *conf = (struct config_bool *) record;
6204 
6205 #define newval (newval_union.boolval)
6206 
6207  if (value)
6208  {
6209  if (!parse_and_validate_value(record, name, value,
6210  source, elevel,
6211  &newval_union, &newextra))
6212  return 0;
6213  }
6214  else if (source == PGC_S_DEFAULT)
6215  {
6216  newval = conf->boot_val;
6217  if (!call_bool_check_hook(conf, &newval, &newextra,
6218  source, elevel))
6219  return 0;
6220  }
6221  else
6222  {
6223  newval = conf->reset_val;
6224  newextra = conf->reset_extra;
6225  source = conf->gen.reset_source;
6226  context = conf->gen.reset_scontext;
6227  }
6228 
6229  if (prohibitValueChange)
6230  {
6231  if (*conf->variable != newval)
6232  {
6233  record->status |= GUC_PENDING_RESTART;
6234  ereport(elevel,
6235  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6236  errmsg("parameter \"%s\" cannot be changed without restarting the server",
6237  name)));
6238  return 0;
6239  }
6240  record->status &= ~GUC_PENDING_RESTART;
6241  return -1;
6242  }
6243 
6244  if (changeVal)
6245  {
6246  /* Save old value to support transaction abort */
6247  if (!makeDefault)
6248  push_old_value(&conf->gen, action);
6249 
6250  if (conf->assign_hook)
6251  conf->assign_hook(newval, newextra);
6252  *conf->variable = newval;
6253  set_extra_field(&conf->gen, &conf->gen.extra,
6254  newextra);
6255  conf->gen.source = source;
6256  conf->gen.scontext = context;
6257  }
6258  if (makeDefault)
6259  {
6260  GucStack *stack;
6261 
6262  if (conf->gen.reset_source <= source)
6263  {
6264  conf->reset_val = newval;
6265  set_extra_field(&conf->gen, &conf->reset_extra,
6266  newextra);
6267  conf->gen.reset_source = source;
6268  conf->gen.reset_scontext = context;
6269  }
6270  for (stack = conf->gen.stack; stack; stack = stack->prev)
6271  {
6272  if (stack->source <= source)
6273  {
6274  stack->prior.val.boolval = newval;
6275  set_extra_field(&conf->gen, &stack->prior.extra,
6276  newextra);
6277  stack->source = source;
6278  stack->scontext = context;
6279  }
6280  }
6281  }
6282 
6283  /* Perhaps we didn't install newextra anywhere */
6284  if (newextra && !extra_field_used(&conf->gen, newextra))
6285  free(newextra);
6286  break;
6287 
6288 #undef newval
6289  }
6290 
6291  case PGC_INT:
6292  {
6293  struct config_int *conf = (struct config_int *) record;
6294 
6295 #define newval (newval_union.intval)
6296 
6297  if (value)
6298  {
6299  if (!parse_and_validate_value(record, name, value,
6300  source, elevel,
6301  &newval_union, &newextra))
6302  return 0;
6303  }
6304  else if (source == PGC_S_DEFAULT)
6305  {
6306  newval = conf->boot_val;
6307  if (!call_int_check_hook(conf, &newval, &newextra,
6308  source, elevel))
6309  return 0;
6310  }
6311  else
6312  {
6313  newval = conf->reset_val;
6314  newextra = conf->reset_extra;
6315  source = conf->gen.reset_source;
6316  context = conf->gen.reset_scontext;
6317  }
6318 
6319  if (prohibitValueChange)
6320  {
6321  if (*conf->variable != newval)
6322  {
6323  record->status |= GUC_PENDING_RESTART;
6324  ereport(elevel,
6325  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6326  errmsg("parameter \"%s\" cannot be changed without restarting the server",
6327  name)));
6328  return 0;
6329  }
6330  record->status &= ~GUC_PENDING_RESTART;
6331  return -1;
6332  }
6333 
6334  if (changeVal)
6335  {
6336  /* Save old value to support transaction abort */
6337  if (!makeDefault)
6338  push_old_value(&conf->gen, action);
6339 
6340  if (conf->assign_hook)
6341  conf->assign_hook(newval, newextra);
6342  *conf->variable = newval;
6343  set_extra_field(&conf->gen, &conf->gen.extra,
6344  newextra);
6345  conf->gen.source = source;
6346  conf->gen.scontext = context;
6347  }
6348  if (makeDefault)
6349  {
6350  GucStack *stack;
6351 
6352  if (conf->gen.reset_source <= source)
6353  {
6354  conf->reset_val = newval;
6355  set_extra_field(&conf->gen, &conf->reset_extra,
6356  newextra);
6357  conf->gen.reset_source = source;
6358  conf->gen.reset_scontext = context;
6359  }
6360  for (stack = conf->gen.stack; stack; stack = stack->prev)
6361  {
6362  if (stack->source <= source)
6363  {
6364  stack->prior.val.intval = newval;
6365  set_extra_field(&conf->gen, &stack->prior.extra,
6366  newextra);
6367  stack->source = source;
6368  stack->scontext = context;
6369  }
6370  }
6371  }
6372 
6373  /* Perhaps we didn't install newextra anywhere */
6374  if (newextra && !extra_field_used(&conf->gen, newextra))
6375  free(newextra);
6376  break;
6377 
6378 #undef newval
6379  }
6380 
6381  case PGC_REAL:
6382  {
6383  struct config_real *conf = (struct config_real *) record;
6384 
6385 #define newval (newval_union.realval)
6386 
6387  if (value)
6388  {
6389  if (!parse_and_validate_value(record, name, value,
6390  source, elevel,
6391  &newval_union, &newextra))
6392  return 0;
6393  }
6394  else if (source == PGC_S_DEFAULT)
6395  {
6396  newval = conf->boot_val;
6397  if (!call_real_check_hook(conf, &newval, &newextra,
6398  source, elevel))
6399  return 0;
6400  }
6401  else
6402  {
6403  newval = conf->reset_val;
6404  newextra = conf->reset_extra;
6405  source = conf->gen.reset_source;
6406  context = conf->gen.reset_scontext;
6407  }
6408 
6409  if (prohibitValueChange)
6410  {
6411  if (*conf->variable != newval)
6412  {
6413  record->status |= GUC_PENDING_RESTART;
6414  ereport(elevel,
6415  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6416  errmsg("parameter \"%s\" cannot be changed without restarting the server",
6417  name)));
6418  return 0;
6419  }
6420  record->status &= ~GUC_PENDING_RESTART;
6421  return -1;
6422  }
6423 
6424  if (changeVal)
6425  {
6426  /* Save old value to support transaction abort */
6427  if (!makeDefault)
6428  push_old_value(&conf->gen, action);
6429 
6430  if (conf->assign_hook)
6431  conf->assign_hook(newval, newextra);
6432  *conf->variable = newval;
6433  set_extra_field(&conf->gen, &conf->gen.extra,
6434  newextra);
6435  conf->gen.source = source;
6436  conf->gen.scontext = context;
6437  }
6438  if (makeDefault)
6439  {
6440  GucStack *stack;
6441 
6442  if (conf->gen.reset_source <= source)
6443  {
6444  conf->reset_val = newval;
6445  set_extra_field(&conf->gen, &conf->reset_extra,
6446  newextra);
6447  conf->gen.reset_source = source;
6448  conf->gen.reset_scontext = context;
6449  }
6450  for (stack = conf->gen.stack; stack; stack = stack->prev)
6451  {
6452  if (stack->source <= source)
6453  {
6454  stack->prior.val.realval = newval;
6455  set_extra_field(&conf->gen, &stack->prior.extra,
6456  newextra);
6457  stack->source = source;
6458  stack->scontext = context;
6459  }
6460  }
6461  }
6462 
6463  /* Perhaps we didn't install newextra anywhere */
6464  if (newextra && !extra_field_used(&conf->gen, newextra))
6465  free(newextra);
6466  break;
6467 
6468 #undef newval
6469  }
6470 
6471  case PGC_STRING:
6472  {
6473  struct config_string *conf = (struct config_string *) record;
6474 
6475 #define newval (newval_union.stringval)
6476 
6477  if (value)
6478  {
6479  if (!parse_and_validate_value(record, name, value,
6480  source, elevel,
6481  &newval_union, &newextra))
6482  return 0;
6483  }
6484  else if (source == PGC_S_DEFAULT)
6485  {
6486  /* non-NULL boot_val must always get strdup'd */
6487  if (conf->boot_val != NULL)
6488  {
6489  newval = guc_strdup(elevel, conf->boot_val);
6490  if (newval == NULL)
6491  return 0;
6492  }
6493  else
6494  newval = NULL;
6495 
6496  if (!call_string_check_hook(conf, &newval, &newextra,
6497  source, elevel))
6498  {
6499  free(newval);
6500  return 0;
6501  }
6502  }
6503  else
6504  {
6505  /*
6506  * strdup not needed, since reset_val is already under
6507  * guc.c's control
6508  */
6509  newval = conf->reset_val;
6510  newextra = conf->reset_extra;
6511  source = conf->gen.reset_source;
6512  context = conf->gen.reset_scontext;
6513  }
6514 
6515  if (prohibitValueChange)
6516  {
6517  /* newval shouldn't be NULL, so we're a bit sloppy here */
6518  if (*conf->variable == NULL || newval == NULL ||
6519  strcmp(*conf->variable, newval) != 0)
6520  {
6521  record->status |= GUC_PENDING_RESTART;
6522  ereport(elevel,
6523  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6524  errmsg("parameter \"%s\" cannot be changed without restarting the server",
6525  name)));
6526  return 0;
6527  }
6528  record->status &= ~GUC_PENDING_RESTART;
6529  return -1;
6530  }
6531 
6532  if (changeVal)
6533  {
6534  /* Save old value to support transaction abort */
6535  if (!makeDefault)
6536  push_old_value(&conf->gen, action);
6537 
6538  if (conf->assign_hook)
6539  conf->assign_hook(newval, newextra);
6540  set_string_field(conf, conf->variable, newval);
6541  set_extra_field(&conf->gen, &conf->gen.extra,
6542  newextra);
6543  conf->gen.source = source;
6544  conf->gen.scontext = context;
6545  }
6546 
6547  if (makeDefault)
6548  {
6549  GucStack *stack;
6550 
6551  if (conf->gen.reset_source <= source)
6552  {
6553  set_string_field(conf, &conf->reset_val, newval);
6554  set_extra_field(&conf->gen, &conf->reset_extra,
6555  newextra);
6556  conf->gen.reset_source = source;
6557  conf->gen.reset_scontext = context;
6558  }
6559  for (stack = conf->gen.stack; stack; stack = stack->prev)
6560  {
6561  if (stack->source <= source)
6562  {
6563  set_string_field(conf, &stack->prior.val.stringval,
6564  newval);
6565  set_extra_field(&conf->gen, &stack->prior.extra,
6566  newextra);
6567  stack->source = source;
6568  stack->scontext = context;
6569  }
6570  }
6571  }
6572 
6573  /* Perhaps we didn't install newval anywhere */
6574  if (newval && !string_field_used(conf, newval))
6575  free(newval);
6576  /* Perhaps we didn't install newextra anywhere */
6577  if (newextra && !extra_field_used(&conf->gen, newextra))
6578  free(newextra);
6579  break;
6580 
6581 #undef newval
6582  }
6583 
6584  case PGC_ENUM:
6585  {
6586  struct config_enum *conf = (struct config_enum *) record;
6587 
6588 #define newval (newval_union.enumval)
6589 
6590  if (value)
6591  {
6592  if (!parse_and_validate_value(record, name, value,
6593  source, elevel,
6594  &newval_union, &newextra))
6595  return 0;
6596  }
6597  else if (source == PGC_S_DEFAULT)
6598  {
6599  newval = conf->boot_val;
6600  if (!call_enum_check_hook(conf, &newval, &newextra,
6601  source, elevel))
6602  return 0;
6603  }
6604  else
6605  {
6606  newval = conf->reset_val;
6607  newextra = conf->reset_extra;
6608  source = conf->gen.reset_source;
6609  context = conf->gen.reset_scontext;
6610  }
6611 
6612  if (prohibitValueChange)
6613  {
6614  if (*conf->variable != newval)
6615  {
6616  record->status |= GUC_PENDING_RESTART;
6617  ereport(elevel,
6618  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6619  errmsg("parameter \"%s\" cannot be changed without restarting the server",
6620  name)));
6621  return 0;
6622  }
6623  record->status &= ~GUC_PENDING_RESTART;
6624  return -1;