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_EXPLAIN   0x100000 /* include in explain */
 
#define GUC_UNIT   (GUC_UNIT_MEMORY | GUC_UNIT_TIME)
 
#define GUC_check_errmsg
 
#define GUC_check_errdetail
 
#define GUC_check_errhint
 

Typedefs

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

Enumerations

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

Functions

bool ParseConfigFile (const char *config_file, bool strict, const char *calling_file, int calling_lineno, int depth, int elevel, ConfigVariable **head_p, ConfigVariable **tail_p)
 
bool ParseConfigFp (FILE *fp, const char *config_file, int depth, int elevel, ConfigVariable **head_p, ConfigVariable **tail_p)
 
bool ParseConfigDirectory (const char *includedir, const char *calling_file, int calling_lineno, int depth, int elevel, ConfigVariable **head_p, ConfigVariable **tail_p)
 
void FreeConfigVariables (ConfigVariable *list)
 
void SetConfigOption (const char *name, const char *value, GucContext context, GucSource source)
 
void DefineCustomBoolVariable (const char *name, const char *short_desc, const char *long_desc, bool *valueAddr, bool bootValue, GucContext context, int flags, GucBoolCheckHook check_hook, GucBoolAssignHook assign_hook, GucShowHook show_hook)
 
void DefineCustomIntVariable (const char *name, const char *short_desc, const char *long_desc, int *valueAddr, int bootValue, int minValue, int maxValue, GucContext context, int flags, GucIntCheckHook check_hook, GucIntAssignHook assign_hook, GucShowHook show_hook)
 
void DefineCustomRealVariable (const char *name, const char *short_desc, const char *long_desc, double *valueAddr, double bootValue, double minValue, double maxValue, GucContext context, int flags, GucRealCheckHook check_hook, GucRealAssignHook assign_hook, GucShowHook show_hook)
 
void DefineCustomStringVariable (const char *name, const char *short_desc, const char *long_desc, char **valueAddr, const char *bootValue, GucContext context, int flags, GucStringCheckHook check_hook, GucStringAssignHook assign_hook, GucShowHook show_hook)
 
void DefineCustomEnumVariable (const char *name, const char *short_desc, const char *long_desc, int *valueAddr, int bootValue, const struct config_enum_entry *options, GucContext context, int flags, GucEnumCheckHook check_hook, GucEnumAssignHook assign_hook, GucShowHook show_hook)
 
void EmitWarningsOnPlaceholders (const char *className)
 
const char * GetConfigOption (const char *name, bool missing_ok, bool restrict_privileged)
 
const char * GetConfigOptionResetString (const char *name)
 
int GetConfigOptionFlags (const char *name, bool missing_ok)
 
void ProcessConfigFile (GucContext context)
 
void InitializeGUCOptions (void)
 
bool SelectConfigFiles (const char *userDoption, const char *progname)
 
void ResetAllOptions (void)
 
void AtStart_GUC (void)
 
int NewGUCNestLevel (void)
 
void AtEOXact_GUC (bool isCommit, int nestLevel)
 
void BeginReportingGUCOptions (void)
 
void ParseLongOption (const char *string, char **name, char **value)
 
bool parse_int (const char *value, int *result, int flags, const char **hintmsg)
 
bool parse_real (const char *value, double *result, int flags, const char **hintmsg)
 
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 *altersysstmt)
 
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 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 session_auth_is_superuser
 
bool log_duration
 
int log_parameter_max_length
 
int log_parameter_max_length_on_error
 
int log_min_error_statement
 
PGDLLIMPORT int log_min_messages
 
PGDLLIMPORT int client_min_messages
 
int log_min_duration_sample
 
int log_min_duration_statement
 
int log_temp_files
 
double log_statement_sample_rate
 
double log_xact_sample_rate
 
char * backtrace_functions
 
char * backtrace_symbol_list
 
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
 
int tcp_user_timeout
 
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:147
char * format_elog_string(const char *fmt,...)
Definition: elog.c:1390
void pre_format_elog_string(int errnumber, const char *domain)
Definition: elog.c:1381

Definition at line 419 of file guc.h.

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

◆ GUC_check_errmsg

#define GUC_check_errmsg

◆ 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_EXPLAIN

#define GUC_EXPLAIN   0x100000 /* include in explain */

Definition at line 230 of file guc.h.

Referenced by get_explain_guc_options().

◆ GUC_IS_NAME

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

Definition at line 213 of file guc.h.

Referenced by parse_and_validate_value().

◆ GUC_LIST_INPUT

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

Definition at line 204 of file guc.h.

Referenced by _PG_init(), and flatten_set_variable_args().

◆ GUC_LIST_QUOTE

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

Definition at line 205 of file guc.h.

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

◆ GUC_NO_RESET_ALL

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

Definition at line 207 of file guc.h.

Referenced by ResetAllOptions().

◆ GUC_NO_SHOW_ALL

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

◆ GUC_NOT_IN_SAMPLE

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

Definition at line 209 of file guc.h.

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

◆ GUC_NOT_WHILE_SEC_REST

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

Definition at line 214 of file guc.h.

Referenced by set_config_option().

◆ GUC_QUALIFIER_SEPARATOR

#define GUC_QUALIFIER_SEPARATOR   '.'

Definition at line 199 of file guc.h.

Referenced by EmitWarningsOnPlaceholders(), and find_option().

◆ GUC_REPORT

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

◆ GUC_SUPERUSER_ONLY

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

◆ GUC_UNIT

#define GUC_UNIT   (GUC_UNIT_MEMORY | GUC_UNIT_TIME)

Definition at line 232 of file guc.h.

Referenced by _ShowOption(), parse_int(), and parse_real().

◆ GUC_UNIT_BLOCKS

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

Definition at line 219 of file guc.h.

Referenced by get_config_unit_name().

◆ GUC_UNIT_BYTE

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

Definition at line 222 of file guc.h.

Referenced by get_config_unit_name().

◆ GUC_UNIT_KB

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

Definition at line 218 of file guc.h.

Referenced by get_config_unit_name().

◆ GUC_UNIT_MB

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

Definition at line 221 of file guc.h.

Referenced by get_config_unit_name().

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

◆ GUC_UNIT_MS

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

Definition at line 225 of file guc.h.

Referenced by _PG_init(), and get_config_unit_name().

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

◆ GUC_UNIT_TIME

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

Definition at line 228 of file guc.h.

Referenced by get_config_unit_name().

◆ GUC_UNIT_XBLOCKS

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

Definition at line 220 of file guc.h.

Referenced by get_config_unit_name().

◆ 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 altersysstmt)

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

8105 {
8106  char *name;
8107  char *value;
8108  bool resetall = false;
8109  ConfigVariable *head = NULL;
8110  ConfigVariable *tail = NULL;
8111  volatile int Tmpfd;
8112  char AutoConfFileName[MAXPGPATH];
8113  char AutoConfTmpFileName[MAXPGPATH];
8114 
8115  if (!superuser())
8116  ereport(ERROR,
8117  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
8118  errmsg("must be superuser to execute ALTER SYSTEM command")));
8119 
8120  /*
8121  * Extract statement arguments
8122  */
8123  name = altersysstmt->setstmt->name;
8124 
8125  switch (altersysstmt->setstmt->kind)
8126  {
8127  case VAR_SET_VALUE:
8128  value = ExtractSetVariableArgs(altersysstmt->setstmt);
8129  break;
8130 
8131  case VAR_SET_DEFAULT:
8132  case VAR_RESET:
8133  value = NULL;
8134  break;
8135 
8136  case VAR_RESET_ALL:
8137  value = NULL;
8138  resetall = true;
8139  break;
8140 
8141  default:
8142  elog(ERROR, "unrecognized alter system stmt type: %d",
8143  altersysstmt->setstmt->kind);
8144  break;
8145  }
8146 
8147  /*
8148  * Unless it's RESET_ALL, validate the target variable and value
8149  */
8150  if (!resetall)
8151  {
8152  struct config_generic *record;
8153 
8154  record = find_option(name, false, ERROR);
8155  if (record == NULL)
8156  ereport(ERROR,
8157  (errcode(ERRCODE_UNDEFINED_OBJECT),
8158  errmsg("unrecognized configuration parameter \"%s\"",
8159  name)));
8160 
8161  /*
8162  * Don't allow parameters that can't be set in configuration files to
8163  * be set in PG_AUTOCONF_FILENAME file.
8164  */
8165  if ((record->context == PGC_INTERNAL) ||
8166  (record->flags & GUC_DISALLOW_IN_FILE) ||
8167  (record->flags & GUC_DISALLOW_IN_AUTO_FILE))
8168  ereport(ERROR,
8169  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
8170  errmsg("parameter \"%s\" cannot be changed",
8171  name)));
8172 
8173  /*
8174  * If a value is specified, verify that it's sane.
8175  */
8176  if (value)
8177  {
8178  union config_var_val newval;
8179  void *newextra = NULL;
8180 
8181  /* Check that it's acceptable for the indicated parameter */
8182  if (!parse_and_validate_value(record, name, value,
8183  PGC_S_FILE, ERROR,
8184  &newval, &newextra))
8185  ereport(ERROR,
8186  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8187  errmsg("invalid value for parameter \"%s\": \"%s\"",
8188  name, value)));
8189 
8190  if (record->vartype == PGC_STRING && newval.stringval != NULL)
8191  free(newval.stringval);
8192  if (newextra)
8193  free(newextra);
8194 
8195  /*
8196  * We must also reject values containing newlines, because the
8197  * grammar for config files doesn't support embedded newlines in
8198  * string literals.
8199  */
8200  if (strchr(value, '\n'))
8201  ereport(ERROR,
8202  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8203  errmsg("parameter value for ALTER SYSTEM must not contain a newline")));
8204  }
8205  }
8206 
8207  /*
8208  * PG_AUTOCONF_FILENAME and its corresponding temporary file are always in
8209  * the data directory, so we can reference them by simple relative paths.
8210  */
8211  snprintf(AutoConfFileName, sizeof(AutoConfFileName), "%s",
8213  snprintf(AutoConfTmpFileName, sizeof(AutoConfTmpFileName), "%s.%s",
8214  AutoConfFileName,
8215  "tmp");
8216 
8217  /*
8218  * Only one backend is allowed to operate on PG_AUTOCONF_FILENAME at a
8219  * time. Use AutoFileLock to ensure that. We must hold the lock while
8220  * reading the old file contents.
8221  */
8222  LWLockAcquire(AutoFileLock, LW_EXCLUSIVE);
8223 
8224  /*
8225  * If we're going to reset everything, then no need to open or parse the
8226  * old file. We'll just write out an empty list.
8227  */
8228  if (!resetall)
8229  {
8230  struct stat st;
8231 
8232  if (stat(AutoConfFileName, &st) == 0)
8233  {
8234  /* open old file PG_AUTOCONF_FILENAME */
8235  FILE *infile;
8236 
8237  infile = AllocateFile(AutoConfFileName, "r");
8238  if (infile == NULL)
8239  ereport(ERROR,
8241  errmsg("could not open file \"%s\": %m",
8242  AutoConfFileName)));
8243 
8244  /* parse it */
8245  if (!ParseConfigFp(infile, AutoConfFileName, 0, LOG, &head, &tail))
8246  ereport(ERROR,
8247  (errcode(ERRCODE_CONFIG_FILE_ERROR),
8248  errmsg("could not parse contents of file \"%s\"",
8249  AutoConfFileName)));
8250 
8251  FreeFile(infile);
8252  }
8253 
8254  /*
8255  * Now, replace any existing entry with the new value, or add it if
8256  * not present.
8257  */
8258  replace_auto_config_value(&head, &tail, name, value);
8259  }
8260 
8261  /*
8262  * To ensure crash safety, first write the new file data to a temp file,
8263  * then atomically rename it into place.
8264  *
8265  * If there is a temp file left over due to a previous crash, it's okay to
8266  * truncate and reuse it.
8267  */
8268  Tmpfd = BasicOpenFile(AutoConfTmpFileName,
8269  O_CREAT | O_RDWR | O_TRUNC);
8270  if (Tmpfd < 0)
8271  ereport(ERROR,
8273  errmsg("could not open file \"%s\": %m",
8274  AutoConfTmpFileName)));
8275 
8276  /*
8277  * Use a TRY block to clean up the file if we fail. Since we need a TRY
8278  * block anyway, OK to use BasicOpenFile rather than OpenTransientFile.
8279  */
8280  PG_TRY();
8281  {
8282  /* Write and sync the new contents to the temporary file */
8283  write_auto_conf_file(Tmpfd, AutoConfTmpFileName, head);
8284 
8285  /* Close before renaming; may be required on some platforms */
8286  close(Tmpfd);
8287  Tmpfd = -1;
8288 
8289  /*
8290  * As the rename is atomic operation, if any problem occurs after this
8291  * at worst it can lose the parameters set by last ALTER SYSTEM
8292  * command.
8293  */
8294  durable_rename(AutoConfTmpFileName, AutoConfFileName, ERROR);
8295  }
8296  PG_CATCH();
8297  {
8298  /* Close file first, else unlink might fail on some platforms */
8299  if (Tmpfd >= 0)
8300  close(Tmpfd);
8301 
8302  /* Unlink, but ignore any error */
8303  (void) unlink(AutoConfTmpFileName);
8304 
8305  PG_RE_THROW();
8306  }
8307  PG_END_TRY();
8308 
8309  FreeConfigVariables(head);
8310 
8311  LWLockRelease(AutoFileLock);
8312 }
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:6723
VariableSetKind kind
Definition: parsenodes.h:2042
int errcode(int sqlerrcode)
Definition: elog.c:610
bool superuser(void)
Definition: superuser.c:46
#define LOG
Definition: elog.h:26
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1812
#define ERROR
Definition: elog.h:43
#define MAXPGPATH
VariableSetStmt * setstmt
Definition: parsenodes.h:3194
int errcode_for_file_access(void)
Definition: elog.c:633
FILE * AllocateFile(const char *name, const char *mode)
Definition: fd.c:2322
int durable_rename(const char *oldfile, const char *newfile, int elevel)
Definition: fd.c:658
enum config_type vartype
Definition: guc_tables.h:156
#define stat(a, b)
Definition: win32_port.h:255
#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:7966
static struct @143 value
#define ereport(elevel,...)
Definition: elog.h:144
static void infile(const char *filename)
Definition: zic.c:1245
#define free(a)
Definition: header.h:65
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:5220
#define PG_CATCH()
Definition: elog.h:305
#define newval
#define PG_AUTOCONF_FILENAME
Definition: guc.h:34
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1208
#define PG_RE_THROW()
Definition: elog.h:336
const char * name
Definition: encode.c:561
#define GUC_DISALLOW_IN_AUTO_FILE
Definition: guc.h:215
int BasicOpenFile(const char *fileName, int fileFlags)
Definition: fd.c:985
int FreeFile(FILE *file)
Definition: fd.c:2521
int errmsg(const char *fmt,...)
Definition: elog.c:824
bool ParseConfigFp(FILE *fp, const char *config_file, int depth, int elevel, ConfigVariable **head_p, ConfigVariable **tail_p)
#define elog(elevel,...)
Definition: elog.h:214
static void replace_auto_config_value(ConfigVariable **head_p, ConfigVariable **tail_p, const char *name, const char *value)
Definition: guc.c:8034
void FreeConfigVariables(ConfigVariable *list)
#define close(a)
Definition: win32.h:12
#define PG_TRY()
Definition: elog.h:295
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
Definition: guc.c:8442
#define snprintf
Definition: port.h:193
#define PG_END_TRY()
Definition: elog.h:320
GucContext context
Definition: guc_tables.h:150

◆ assign_search_path()

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

Definition at line 4308 of file namespace.c.

References baseSearchPathValid.

4309 {
4310  /*
4311  * We mark the path as needing recomputation, but don't do anything until
4312  * it's needed. This avoids trying to do database access during GUC
4313  * initialization, or outside a transaction.
4314  */
4315  baseSearchPathValid = false;
4316 }
static bool baseSearchPathValid
Definition: namespace.c:160

◆ assign_temp_tablespaces()

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

Definition at line 1301 of file tablespace.c.

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

1302 {
1303  temp_tablespaces_extra *myextra = (temp_tablespaces_extra *) extra;
1304 
1305  /*
1306  * If check_temp_tablespaces was executed inside a transaction, then pass
1307  * the list it made to fd.c. Otherwise, clear fd.c's list; we must be
1308  * still outside a transaction, or else restoring during transaction exit,
1309  * and in either case we can just let the next PrepareTempTablespaces call
1310  * make things sane.
1311  */
1312  if (myextra)
1313  SetTempTablespaces(myextra->tblSpcs, myextra->numSpcs);
1314  else
1315  SetTempTablespaces(NULL, 0);
1316 }
Oid tblSpcs[FLEXIBLE_ARRAY_MEMBER]
Definition: tablespace.c:1188
void SetTempTablespaces(Oid *tableSpaces, int numSpaces)
Definition: fd.c:2789

◆ assign_xlog_sync_method()

void assign_xlog_sync_method ( int  new_sync_method,
void *  extra 
)

Definition at line 10353 of file xlog.c.

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

10354 {
10355  if (sync_method != new_sync_method)
10356  {
10357  /*
10358  * To ensure that no blocks escape unsynced, force an fsync on the
10359  * currently open log segment (if any). Also, if the open flag is
10360  * changing, close the log file so it will be reopened (with new flag
10361  * bit) at next use.
10362  */
10363  if (openLogFile >= 0)
10364  {
10366  if (pg_fsync(openLogFile) != 0)
10367  {
10368  char xlogfname[MAXFNAMELEN];
10369  int save_errno;
10370 
10371  save_errno = errno;
10374  errno = save_errno;
10375  ereport(PANIC,
10377  errmsg("could not fsync file \"%s\": %m", xlogfname)));
10378  }
10379 
10381  if (get_sync_bit(sync_method) != get_sync_bit(new_sync_method))
10382  XLogFileClose();
10383  }
10384  }
10385 }
int wal_segment_size
Definition: xlog.c:116
static int get_sync_bit(int method)
Definition: xlog.c:10297
#define PANIC
Definition: elog.h:53
static XLogSegNo openLogSegNo
Definition: xlog.c:800
static void XLogFileClose(void)
Definition: xlog.c:3852
int errcode_for_file_access(void)
Definition: elog.c:633
static void pgstat_report_wait_end(void)
Definition: pgstat.h:1381
#define MAXFNAMELEN
static int openLogFile
Definition: xlog.c:799
TimeLineID ThisTimeLineID
Definition: xlog.c:191
#define ereport(elevel,...)
Definition: elog.h:144
#define XLogFileName(fname, tli, logSegNo, wal_segsz_bytes)
static void pgstat_report_wait_start(uint32 wait_event_info)
Definition: pgstat.h:1357
int sync_method
Definition: xlog.c:105
int errmsg(const char *fmt,...)
Definition: elog.c:824
int pg_fsync(int fd)
Definition: fd.c:345

◆ AtEOXact_GUC()

void AtEOXact_GUC ( bool  isCommit,
int  nestLevel 
)

Definition at line 5927 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(), DefineIndex(), do_analyze_rel(), ExecCreateTableAs(), ExecRefreshMatView(), execute_extension_script(), fmgr_security_definer(), index_build(), PrepareTransaction(), ProcedureCreate(), reset_transmission_modes(), restoreLocalGucs(), RI_Initial_Check(), RI_PartitionRemove_Check(), vacuum_rel(), and validate_index().

5928 {
5929  bool still_dirty;
5930  int i;
5931 
5932  /*
5933  * Note: it's possible to get here with GUCNestLevel == nestLevel-1 during
5934  * abort, if there is a failure during transaction start before
5935  * AtStart_GUC is called.
5936  */
5937  Assert(nestLevel > 0 &&
5938  (nestLevel <= GUCNestLevel ||
5939  (nestLevel == GUCNestLevel + 1 && !isCommit)));
5940 
5941  /* Quick exit if nothing's changed in this transaction */
5942  if (!guc_dirty)
5943  {
5944  GUCNestLevel = nestLevel - 1;
5945  return;
5946  }
5947 
5948  still_dirty = false;
5949  for (i = 0; i < num_guc_variables; i++)
5950  {
5951  struct config_generic *gconf = guc_variables[i];
5952  GucStack *stack;
5953 
5954  /*
5955  * Process and pop each stack entry within the nest level. To simplify
5956  * fmgr_security_definer() and other places that use GUC_ACTION_SAVE,
5957  * we allow failure exit from code that uses a local nest level to be
5958  * recovered at the surrounding transaction or subtransaction abort;
5959  * so there could be more than one stack entry to pop.
5960  */
5961  while ((stack = gconf->stack) != NULL &&
5962  stack->nest_level >= nestLevel)
5963  {
5964  GucStack *prev = stack->prev;
5965  bool restorePrior = false;
5966  bool restoreMasked = false;
5967  bool changed;
5968 
5969  /*
5970  * In this next bit, if we don't set either restorePrior or
5971  * restoreMasked, we must "discard" any unwanted fields of the
5972  * stack entries to avoid leaking memory. If we do set one of
5973  * those flags, unused fields will be cleaned up after restoring.
5974  */
5975  if (!isCommit) /* if abort, always restore prior value */
5976  restorePrior = true;
5977  else if (stack->state == GUC_SAVE)
5978  restorePrior = true;
5979  else if (stack->nest_level == 1)
5980  {
5981  /* transaction commit */
5982  if (stack->state == GUC_SET_LOCAL)
5983  restoreMasked = true;
5984  else if (stack->state == GUC_SET)
5985  {
5986  /* we keep the current active value */
5987  discard_stack_value(gconf, &stack->prior);
5988  }
5989  else /* must be GUC_LOCAL */
5990  restorePrior = true;
5991  }
5992  else if (prev == NULL ||
5993  prev->nest_level < stack->nest_level - 1)
5994  {
5995  /* decrement entry's level and do not pop it */
5996  stack->nest_level--;
5997  continue;
5998  }
5999  else
6000  {
6001  /*
6002  * We have to merge this stack entry into prev. See README for
6003  * discussion of this bit.
6004  */
6005  switch (stack->state)
6006  {
6007  case GUC_SAVE:
6008  Assert(false); /* can't get here */
6009  break;
6010 
6011  case GUC_SET:
6012  /* next level always becomes SET */
6013  discard_stack_value(gconf, &stack->prior);
6014  if (prev->state == GUC_SET_LOCAL)
6015  discard_stack_value(gconf, &prev->masked);
6016  prev->state = GUC_SET;
6017  break;
6018 
6019  case GUC_LOCAL:
6020  if (prev->state == GUC_SET)
6021  {
6022  /* LOCAL migrates down */
6023  prev->masked_scontext = stack->scontext;
6024  prev->masked = stack->prior;
6025  prev->state = GUC_SET_LOCAL;
6026  }
6027  else
6028  {
6029  /* else just forget this stack level */
6030  discard_stack_value(gconf, &stack->prior);
6031  }
6032  break;
6033 
6034  case GUC_SET_LOCAL:
6035  /* prior state at this level no longer wanted */
6036  discard_stack_value(gconf, &stack->prior);
6037  /* copy down the masked state */
6038  prev->masked_scontext = stack->masked_scontext;
6039  if (prev->state == GUC_SET_LOCAL)
6040  discard_stack_value(gconf, &prev->masked);
6041  prev->masked = stack->masked;
6042  prev->state = GUC_SET_LOCAL;
6043  break;
6044  }
6045  }
6046 
6047  changed = false;
6048 
6049  if (restorePrior || restoreMasked)
6050  {
6051  /* Perform appropriate restoration of the stacked value */
6052  config_var_value newvalue;
6053  GucSource newsource;
6054  GucContext newscontext;
6055 
6056  if (restoreMasked)
6057  {
6058  newvalue = stack->masked;
6059  newsource = PGC_S_SESSION;
6060  newscontext = stack->masked_scontext;
6061  }
6062  else
6063  {
6064  newvalue = stack->prior;
6065  newsource = stack->source;
6066  newscontext = stack->scontext;
6067  }
6068 
6069  switch (gconf->vartype)
6070  {
6071  case PGC_BOOL:
6072  {
6073  struct config_bool *conf = (struct config_bool *) gconf;
6074  bool newval = newvalue.val.boolval;
6075  void *newextra = newvalue.extra;
6076 
6077  if (*conf->variable != newval ||
6078  conf->gen.extra != newextra)
6079  {
6080  if (conf->assign_hook)
6081  conf->assign_hook(newval, newextra);
6082  *conf->variable = newval;
6083  set_extra_field(&conf->gen, &conf->gen.extra,
6084  newextra);
6085  changed = true;
6086  }
6087  break;
6088  }
6089  case PGC_INT:
6090  {
6091  struct config_int *conf = (struct config_int *) gconf;
6092  int newval = newvalue.val.intval;
6093  void *newextra = newvalue.extra;
6094 
6095  if (*conf->variable != newval ||
6096  conf->gen.extra != newextra)
6097  {
6098  if (conf->assign_hook)
6099  conf->assign_hook(newval, newextra);
6100  *conf->variable = newval;
6101  set_extra_field(&conf->gen, &conf->gen.extra,
6102  newextra);
6103  changed = true;
6104  }
6105  break;
6106  }
6107  case PGC_REAL:
6108  {
6109  struct config_real *conf = (struct config_real *) gconf;
6110  double newval = newvalue.val.realval;
6111  void *newextra = newvalue.extra;
6112 
6113  if (*conf->variable != newval ||
6114  conf->gen.extra != newextra)
6115  {
6116  if (conf->assign_hook)
6117  conf->assign_hook(newval, newextra);
6118  *conf->variable = newval;
6119  set_extra_field(&conf->gen, &conf->gen.extra,
6120  newextra);
6121  changed = true;
6122  }
6123  break;
6124  }
6125  case PGC_STRING:
6126  {
6127  struct config_string *conf = (struct config_string *) gconf;
6128  char *newval = newvalue.val.stringval;
6129  void *newextra = newvalue.extra;
6130 
6131  if (*conf->variable != newval ||
6132  conf->gen.extra != newextra)
6133  {
6134  if (conf->assign_hook)
6135  conf->assign_hook(newval, newextra);
6136  set_string_field(conf, conf->variable, newval);
6137  set_extra_field(&conf->gen, &conf->gen.extra,
6138  newextra);
6139  changed = true;
6140  }
6141 
6142  /*
6143  * Release stacked values if not used anymore. We
6144  * could use discard_stack_value() here, but since
6145  * we have type-specific code anyway, might as
6146  * well inline it.
6147  */
6148  set_string_field(conf, &stack->prior.val.stringval, NULL);
6149  set_string_field(conf, &stack->masked.val.stringval, NULL);
6150  break;
6151  }
6152  case PGC_ENUM:
6153  {
6154  struct config_enum *conf = (struct config_enum *) gconf;
6155  int newval = newvalue.val.enumval;
6156  void *newextra = newvalue.extra;
6157 
6158  if (*conf->variable != newval ||
6159  conf->gen.extra != newextra)
6160  {
6161  if (conf->assign_hook)
6162  conf->assign_hook(newval, newextra);
6163  *conf->variable = newval;
6164  set_extra_field(&conf->gen, &conf->gen.extra,
6165  newextra);
6166  changed = true;
6167  }
6168  break;
6169  }
6170  }
6171 
6172  /*
6173  * Release stacked extra values if not used anymore.
6174  */
6175  set_extra_field(gconf, &(stack->prior.extra), NULL);
6176  set_extra_field(gconf, &(stack->masked.extra), NULL);
6177 
6178  /* And restore source information */
6179  gconf->source = newsource;
6180  gconf->scontext = newscontext;
6181  }
6182 
6183  /* Finish popping the state stack */
6184  gconf->stack = prev;
6185  pfree(stack);
6186 
6187  /* Report new value if we changed it */
6188  if (changed && (gconf->flags & GUC_REPORT))
6189  ReportGUCOption(gconf);
6190  } /* end of stack-popping loop */
6191 
6192  if (stack != NULL)
6193  still_dirty = true;
6194  }
6195 
6196  /* If there are no remaining stack entries, we can reset guc_dirty */
6197  guc_dirty = still_dirty;
6198 
6199  /* Update nesting level */
6200  GUCNestLevel = nestLevel - 1;
6201 }
struct guc_stack * prev
Definition: guc_tables.h:123
GucSource source
Definition: guc_tables.h:158
GucContext
Definition: guc.h:68
union config_var_val val
Definition: guc_tables.h:46
int nest_level
Definition: guc_tables.h:124
GucRealAssignHook assign_hook
Definition: guc_tables.h:219
char ** variable
Definition: guc_tables.h:230
static int GUCNestLevel
Definition: guc.c:4796
bool * variable
Definition: guc_tables.h:184
GucEnumAssignHook assign_hook
Definition: guc_tables.h:248
GucBoolAssignHook assign_hook
Definition: guc_tables.h:187
config_var_value masked
Definition: guc_tables.h:131
GucContext scontext
Definition: guc_tables.h:160
GucIntAssignHook assign_hook
Definition: guc_tables.h:203
GucSource
Definition: guc.h:105
int * variable
Definition: guc_tables.h:198
int * variable
Definition: guc_tables.h:244
void pfree(void *pointer)
Definition: mcxt.c:1056
static int num_guc_variables
Definition: guc.c:4786
static void discard_stack_value(struct config_generic *gconf, config_var_value *val)
Definition: guc.c:5011
GucSource source
Definition: guc_tables.h:126
static void set_extra_field(struct config_generic *gconf, void **field, void *newval)
Definition: guc.c:4957
struct config_generic gen
Definition: guc_tables.h:182
struct config_generic gen
Definition: guc_tables.h:196
GucContext masked_scontext
Definition: guc_tables.h:129
#define GUC_REPORT
Definition: guc.h:208
double * variable
Definition: guc_tables.h:214
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4896
static struct config_generic ** guc_variables
Definition: guc.c:4783
enum config_type vartype
Definition: guc_tables.h:156
GucContext scontext
Definition: guc_tables.h:128
struct config_generic gen
Definition: guc_tables.h:242
struct config_generic gen
Definition: guc_tables.h:228
GucStackState state
Definition: guc_tables.h:125
GucStringAssignHook assign_hook
Definition: guc_tables.h:233
#define Assert(condition)
Definition: c.h:738
#define newval
char * stringval
Definition: guc_tables.h:36
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:6237
GucStack * stack
Definition: guc_tables.h:162
double realval
Definition: guc_tables.h:35
static bool guc_dirty
Definition: guc.c:4792
config_var_value prior
Definition: guc_tables.h:130
struct config_generic gen
Definition: guc_tables.h:212

◆ AtStart_GUC()

void AtStart_GUC ( void  )

Definition at line 5893 of file guc.c.

References elog, and WARNING.

Referenced by StartTransaction().

5894 {
5895  /*
5896  * The nest level should be 0 between transactions; if it isn't, somebody
5897  * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
5898  * throw a warning but make no other effort to clean up.
5899  */
5900  if (GUCNestLevel != 0)
5901  elog(WARNING, "GUC nest level = %d at transaction start",
5902  GUCNestLevel);
5903  GUCNestLevel = 1;
5904 }
static int GUCNestLevel
Definition: guc.c:4796
#define WARNING
Definition: elog.h:40
#define elog(elevel,...)
Definition: elog.h:214

◆ BeginReportingGUCOptions()

void BeginReportingGUCOptions ( void  )

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

6210 {
6211  int i;
6212 
6213  /*
6214  * Don't do anything unless talking to an interactive frontend of protocol
6215  * 3.0 or later.
6216  */
6217  if (whereToSendOutput != DestRemote ||
6219  return;
6220 
6221  reporting_enabled = true;
6222 
6223  /* Transmit initial values of interesting variables */
6224  for (i = 0; i < num_guc_variables; i++)
6225  {
6226  struct config_generic *conf = guc_variables[i];
6227 
6228  if (conf->flags & GUC_REPORT)
6229  ReportGUCOption(conf);
6230  }
6231 }
#define PG_PROTOCOL_MAJOR(v)
Definition: pqcomm.h:104
static int num_guc_variables
Definition: guc.c:4786
#define GUC_REPORT
Definition: guc.h:208
static struct config_generic ** guc_variables
Definition: guc.c:4783
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:6237
CommandDest whereToSendOutput
Definition: postgres.c:91
static bool reporting_enabled
Definition: guc.c:4794
ProtocolVersion FrontendProtocol
Definition: globals.c:28

◆ check_default_tablespace()

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

Definition at line 1086 of file tablespace.c.

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

1087 {
1088  /*
1089  * If we aren't inside a transaction, or connected to a database, we
1090  * cannot do the catalog accesses necessary to verify the name. Must
1091  * accept the value on faith.
1092  */
1094  {
1095  if (**newval != '\0' &&
1097  {
1098  /*
1099  * When source == PGC_S_TEST, don't throw a hard error for a
1100  * nonexistent tablespace, only a NOTICE. See comments in guc.h.
1101  */
1102  if (source == PGC_S_TEST)
1103  {
1104  ereport(NOTICE,
1105  (errcode(ERRCODE_UNDEFINED_OBJECT),
1106  errmsg("tablespace \"%s\" does not exist",
1107  *newval)));
1108  }
1109  else
1110  {
1111  GUC_check_errdetail("Tablespace \"%s\" does not exist.",
1112  *newval);
1113  return false;
1114  }
1115  }
1116  }
1117 
1118  return true;
1119 }
Oid get_tablespace_oid(const char *tablespacename, bool missing_ok)
Definition: tablespace.c:1421
GucSource source
Definition: guc_tables.h:158
#define GUC_check_errdetail
Definition: guc.h:415
int errcode(int sqlerrcode)
Definition: elog.c:610
#define OidIsValid(objectId)
Definition: c.h:644
Oid MyDatabaseId
Definition: globals.c:85
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:144
#define NOTICE
Definition: elog.h:37
#define newval
bool IsTransactionState(void)
Definition: xact.c:356
int errmsg(const char *fmt,...)
Definition: elog.c:824

◆ check_search_path()

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

Definition at line 4274 of file namespace.c.

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

4275 {
4276  char *rawname;
4277  List *namelist;
4278 
4279  /* Need a modifiable copy of string */
4280  rawname = pstrdup(*newval);
4281 
4282  /* Parse string into list of identifiers */
4283  if (!SplitIdentifierString(rawname, ',', &namelist))
4284  {
4285  /* syntax error in name list */
4286  GUC_check_errdetail("List syntax is invalid.");
4287  pfree(rawname);
4288  list_free(namelist);
4289  return false;
4290  }
4291 
4292  /*
4293  * We used to try to check that the named schemas exist, but there are
4294  * many valid use-cases for having search_path settings that include
4295  * schemas that don't exist; and often, we are not inside a transaction
4296  * here and so can't consult the system catalogs anyway. So now, the only
4297  * requirement is syntactic validity of the identifier list.
4298  */
4299 
4300  pfree(rawname);
4301  list_free(namelist);
4302 
4303  return true;
4304 }
#define GUC_check_errdetail
Definition: guc.h:415
char * pstrdup(const char *in)
Definition: mcxt.c:1186
void pfree(void *pointer)
Definition: mcxt.c:1056
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3686
#define newval
void list_free(List *list)
Definition: list.c:1376
Definition: pg_list.h:50

◆ check_temp_tablespaces()

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

Definition at line 1193 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, MyDatabaseId, 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.

1194 {
1195  char *rawname;
1196  List *namelist;
1197 
1198  /* Need a modifiable copy of string */
1199  rawname = pstrdup(*newval);
1200 
1201  /* Parse string into list of identifiers */
1202  if (!SplitIdentifierString(rawname, ',', &namelist))
1203  {
1204  /* syntax error in name list */
1205  GUC_check_errdetail("List syntax is invalid.");
1206  pfree(rawname);
1207  list_free(namelist);
1208  return false;
1209  }
1210 
1211  /*
1212  * If we aren't inside a transaction, or connected to a database, we
1213  * cannot do the catalog accesses necessary to verify the name. Must
1214  * accept the value on faith. Fortunately, there's then also no need to
1215  * pass the data to fd.c.
1216  */
1218  {
1219  temp_tablespaces_extra *myextra;
1220  Oid *tblSpcs;
1221  int numSpcs;
1222  ListCell *l;
1223 
1224  /* temporary workspace until we are done verifying the list */
1225  tblSpcs = (Oid *) palloc(list_length(namelist) * sizeof(Oid));
1226  numSpcs = 0;
1227  foreach(l, namelist)
1228  {
1229  char *curname = (char *) lfirst(l);
1230  Oid curoid;
1231  AclResult aclresult;
1232 
1233  /* Allow an empty string (signifying database default) */
1234  if (curname[0] == '\0')
1235  {
1236  /* InvalidOid signifies database's default tablespace */
1237  tblSpcs[numSpcs++] = InvalidOid;
1238  continue;
1239  }
1240 
1241  /*
1242  * In an interactive SET command, we ereport for bad info. When
1243  * source == PGC_S_TEST, don't throw a hard error for a
1244  * nonexistent tablespace, only a NOTICE. See comments in guc.h.
1245  */
1246  curoid = get_tablespace_oid(curname, source <= PGC_S_TEST);
1247  if (curoid == InvalidOid)
1248  {
1249  if (source == PGC_S_TEST)
1250  ereport(NOTICE,
1251  (errcode(ERRCODE_UNDEFINED_OBJECT),
1252  errmsg("tablespace \"%s\" does not exist",
1253  curname)));
1254  continue;
1255  }
1256 
1257  /*
1258  * Allow explicit specification of database's default tablespace
1259  * in temp_tablespaces without triggering permissions checks.
1260  */
1261  if (curoid == MyDatabaseTableSpace)
1262  {
1263  /* InvalidOid signifies database's default tablespace */
1264  tblSpcs[numSpcs++] = InvalidOid;
1265  continue;
1266  }
1267 
1268  /* Check permissions, similarly complaining only if interactive */
1269  aclresult = pg_tablespace_aclcheck(curoid, GetUserId(),
1270  ACL_CREATE);
1271  if (aclresult != ACLCHECK_OK)
1272  {
1273  if (source >= PGC_S_INTERACTIVE)
1274  aclcheck_error(aclresult, OBJECT_TABLESPACE, curname);
1275  continue;
1276  }
1277 
1278  tblSpcs[numSpcs++] = curoid;
1279  }
1280 
1281  /* Now prepare an "extra" struct for assign_temp_tablespaces */
1282  myextra = malloc(offsetof(temp_tablespaces_extra, tblSpcs) +
1283  numSpcs * sizeof(Oid));
1284  if (!myextra)
1285  return false;
1286  myextra->numSpcs = numSpcs;
1287  memcpy(myextra->tblSpcs, tblSpcs, numSpcs * sizeof(Oid));
1288  *extra = (void *) myextra;
1289 
1290  pfree(tblSpcs);
1291  }
1292 
1293  pfree(rawname);
1294  list_free(namelist);
1295 
1296  return true;
1297 }
Oid get_tablespace_oid(const char *tablespacename, bool missing_ok)
Definition: tablespace.c:1421
GucSource source
Definition: guc_tables.h:158
AclResult pg_tablespace_aclcheck(Oid spc_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4637
Oid GetUserId(void)
Definition: miscinit.c:448
#define GUC_check_errdetail
Definition: guc.h:415
char * pstrdup(const char *in)
Definition: mcxt.c:1186
int errcode(int sqlerrcode)
Definition: elog.c:610
unsigned int Oid
Definition: postgres_ext.h:31
Oid MyDatabaseTableSpace
Definition: globals.c:87
#define malloc(a)
Definition: header.h:50
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3294
void pfree(void *pointer)
Definition: mcxt.c:1056
#define ACL_CREATE
Definition: parsenodes.h:84
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3686
Oid tblSpcs[FLEXIBLE_ARRAY_MEMBER]
Definition: tablespace.c:1188
AclResult
Definition: acl.h:177
Oid MyDatabaseId
Definition: globals.c:85
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:144
#define NOTICE
Definition: elog.h:37
#define lfirst(lc)
Definition: pg_list.h:190
static int list_length(const List *l)
Definition: pg_list.h:169
#define newval
bool IsTransactionState(void)
Definition: xact.c:356
void * palloc(Size size)
Definition: mcxt.c:949
int errmsg(const char *fmt,...)
Definition: elog.c:824
void list_free(List *list)
Definition: list.c:1376
Definition: pg_list.h:50
#define offsetof(type, field)
Definition: c.h:661

◆ check_wal_buffers()

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

Definition at line 4988 of file xlog.c.

References XLOGbuffers, and XLOGChooseNumBuffers().

4989 {
4990  /*
4991  * -1 indicates a request for auto-tune.
4992  */
4993  if (*newval == -1)
4994  {
4995  /*
4996  * If we haven't yet changed the boot_val default of -1, just let it
4997  * be. We'll fix it when XLOGShmemSize is called.
4998  */
4999  if (XLOGbuffers == -1)
5000  return true;
5001 
5002  /* Otherwise, substitute the auto-tune value */
5004  }
5005 
5006  /*
5007  * We clamp manually-set values to at least 4 blocks. Prior to PostgreSQL
5008  * 9.1, a minimum of 4 was enforced by guc.c, but since that is no longer
5009  * the case, we just silently treat such values as a request for the
5010  * minimum. (We could throw an error instead, but that doesn't seem very
5011  * helpful.)
5012  */
5013  if (*newval < 4)
5014  *newval = 4;
5015 
5016  return true;
5017 }
static int XLOGChooseNumBuffers(void)
Definition: xlog.c:4972
#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 8771 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().

8781 {
8782  struct config_bool *var;
8783 
8784  var = (struct config_bool *)
8785  init_custom_variable(name, short_desc, long_desc, context, flags,
8786  PGC_BOOL, sizeof(struct config_bool));
8787  var->variable = valueAddr;
8788  var->boot_val = bootValue;
8789  var->reset_val = bootValue;
8790  var->check_hook = check_hook;
8791  var->assign_hook = assign_hook;
8792  var->show_hook = show_hook;
8793  define_custom_variable(&var->gen);
8794 }
bool * variable
Definition: guc_tables.h:184
GucBoolAssignHook assign_hook
Definition: guc_tables.h:187
bool boot_val
Definition: guc_tables.h:185
struct config_generic gen
Definition: guc_tables.h:182
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:8530
GucBoolCheckHook check_hook
Definition: guc_tables.h:186
GucShowHook show_hook
Definition: guc_tables.h:188
const char * name
Definition: encode.c:561
bool reset_val
Definition: guc_tables.h:190
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8590

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

8893 {
8894  struct config_enum *var;
8895 
8896  var = (struct config_enum *)
8897  init_custom_variable(name, short_desc, long_desc, context, flags,
8898  PGC_ENUM, sizeof(struct config_enum));
8899  var->variable = valueAddr;
8900  var->boot_val = bootValue;
8901  var->reset_val = bootValue;
8902  var->options = options;
8903  var->check_hook = check_hook;
8904  var->assign_hook = assign_hook;
8905  var->show_hook = show_hook;
8906  define_custom_variable(&var->gen);
8907 }
GucEnumCheckHook check_hook
Definition: guc_tables.h:247
GucEnumAssignHook assign_hook
Definition: guc_tables.h:248
int * variable
Definition: guc_tables.h:244
const struct config_enum_entry * options
Definition: guc_tables.h:246
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:8530
GucShowHook show_hook
Definition: guc_tables.h:249
struct config_generic gen
Definition: guc_tables.h:242
const char * name
Definition: encode.c:561
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8590

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

8809 {
8810  struct config_int *var;
8811 
8812  var = (struct config_int *)
8813  init_custom_variable(name, short_desc, long_desc, context, flags,
8814  PGC_INT, sizeof(struct config_int));
8815  var->variable = valueAddr;
8816  var->boot_val = bootValue;
8817  var->reset_val = bootValue;
8818  var->min = minValue;
8819  var->max = maxValue;
8820  var->check_hook = check_hook;
8821  var->assign_hook = assign_hook;
8822  var->show_hook = show_hook;
8823  define_custom_variable(&var->gen);
8824 }
int boot_val
Definition: guc_tables.h:199
GucIntAssignHook assign_hook
Definition: guc_tables.h:203
GucIntCheckHook check_hook
Definition: guc_tables.h:202
GucShowHook show_hook
Definition: guc_tables.h:204
int * variable
Definition: guc_tables.h:198
struct config_generic gen
Definition: guc_tables.h:196
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:8530
const char * name
Definition: encode.c:561
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8590
int reset_val
Definition: guc_tables.h:206

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

8839 {
8840  struct config_real *var;
8841 
8842  var = (struct config_real *)
8843  init_custom_variable(name, short_desc, long_desc, context, flags,
8844  PGC_REAL, sizeof(struct config_real));
8845  var->variable = valueAddr;
8846  var->boot_val = bootValue;
8847  var->reset_val = bootValue;
8848  var->min = minValue;
8849  var->max = maxValue;
8850  var->check_hook = check_hook;
8851  var->assign_hook = assign_hook;
8852  var->show_hook = show_hook;
8853  define_custom_variable(&var->gen);
8854 }
GucRealAssignHook assign_hook
Definition: guc_tables.h:219
double reset_val
Definition: guc_tables.h:222
GucRealCheckHook check_hook
Definition: guc_tables.h:218
GucShowHook show_hook
Definition: guc_tables.h:220
double * variable
Definition: guc_tables.h:214
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:8530
double max
Definition: guc_tables.h:217
double boot_val
Definition: guc_tables.h:215
const char * name
Definition: encode.c:561
double min
Definition: guc_tables.h:216
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8590
struct config_generic gen
Definition: guc_tables.h:212

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

8867 {
8868  struct config_string *var;
8869 
8870  var = (struct config_string *)
8871  init_custom_variable(name, short_desc, long_desc, context, flags,
8872  PGC_STRING, sizeof(struct config_string));
8873  var->variable = valueAddr;
8874  var->boot_val = bootValue;
8875  var->check_hook = check_hook;
8876  var->assign_hook = assign_hook;
8877  var->show_hook = show_hook;
8878  define_custom_variable(&var->gen);
8879 }
char ** variable
Definition: guc_tables.h:230
GucStringCheckHook check_hook
Definition: guc_tables.h:232
const char * boot_val
Definition: guc_tables.h:231
GucShowHook show_hook
Definition: guc_tables.h:234
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:8530
struct config_generic gen
Definition: guc_tables.h:228
GucStringAssignHook assign_hook
Definition: guc_tables.h:233
const char * name
Definition: encode.c:561
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8590

◆ EmitWarningsOnPlaceholders()

void EmitWarningsOnPlaceholders ( const char *  className)

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

8911 {
8912  int classLen = strlen(className);
8913  int i;
8914 
8915  for (i = 0; i < num_guc_variables; i++)
8916  {
8917  struct config_generic *var = guc_variables[i];
8918 
8919  if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
8920  strncmp(className, var->name, classLen) == 0 &&
8921  var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
8922  {
8923  ereport(WARNING,
8924  (errcode(ERRCODE_UNDEFINED_OBJECT),
8925  errmsg("unrecognized configuration parameter \"%s\"",
8926  var->name)));
8927  }
8928  }
8929 }
const char * name
Definition: guc_tables.h:149
int errcode(int sqlerrcode)
Definition: elog.c:610
#define GUC_QUALIFIER_SEPARATOR
Definition: guc.h:199
static int num_guc_variables
Definition: guc.c:4786
static struct config_generic ** guc_variables
Definition: guc.c:4783
#define WARNING
Definition: elog.h:40
#define ereport(elevel,...)
Definition: elog.h:144
#define GUC_CUSTOM_PLACEHOLDER
Definition: guc.h:211
int errmsg(const char *fmt,...)
Definition: elog.c:824
int i

◆ EstimateGUCStateSpace()

Size EstimateGUCStateSpace ( void  )

Definition at line 10204 of file guc.c.

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

Referenced by InitializeParallelDSM().

10205 {
10206  Size size;
10207  int i;
10208 
10209  /* Add space reqd for saving the data size of the guc state */
10210  size = sizeof(Size);
10211 
10212  /* Add up the space needed for each GUC variable */
10213  for (i = 0; i < num_guc_variables; i++)
10214  size = add_size(size,
10216 
10217  return size;
10218 }
static int num_guc_variables
Definition: guc.c:4786
static struct config_generic ** guc_variables
Definition: guc.c:4783
Size add_size(Size s1, Size s2)
Definition: shmem.c:498
size_t Size
Definition: c.h:466
static Size estimate_variable_size(struct config_generic *gconf)
Definition: guc.c:10106
int i

◆ ExecSetVariableStmt()

void ExecSetVariableStmt ( VariableSetStmt stmt,
bool  isTopLevel 
)

Definition at line 8318 of file guc.c.

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

Referenced by standard_ProcessUtility().

8319 {
8321 
8322  /*
8323  * Workers synchronize these parameters at the start of the parallel
8324  * operation; then, we block SET during the operation.
8325  */
8326  if (IsInParallelMode())
8327  ereport(ERROR,
8328  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
8329  errmsg("cannot set parameters during a parallel operation")));
8330 
8331  switch (stmt->kind)
8332  {
8333  case VAR_SET_VALUE:
8334  case VAR_SET_CURRENT:
8335  if (stmt->is_local)
8336  WarnNoTransactionBlock(isTopLevel, "SET LOCAL");
8337  (void) set_config_option(stmt->name,
8338  ExtractSetVariableArgs(stmt),
8340  PGC_S_SESSION,
8341  action, true, 0, false);
8342  break;
8343  case VAR_SET_MULTI:
8344 
8345  /*
8346  * Special-case SQL syntaxes. The TRANSACTION and SESSION
8347  * CHARACTERISTICS cases effectively set more than one variable
8348  * per statement. TRANSACTION SNAPSHOT only takes one argument,
8349  * but we put it here anyway since it's a special case and not
8350  * related to any GUC variable.
8351  */
8352  if (strcmp(stmt->name, "TRANSACTION") == 0)
8353  {
8354  ListCell *head;
8355 
8356  WarnNoTransactionBlock(isTopLevel, "SET TRANSACTION");
8357 
8358  foreach(head, stmt->args)
8359  {
8360  DefElem *item = (DefElem *) lfirst(head);
8361 
8362  if (strcmp(item->defname, "transaction_isolation") == 0)
8363  SetPGVariable("transaction_isolation",
8364  list_make1(item->arg), stmt->is_local);
8365  else if (strcmp(item->defname, "transaction_read_only") == 0)
8366  SetPGVariable("transaction_read_only",
8367  list_make1(item->arg), stmt->is_local);
8368  else if (strcmp(item->defname, "transaction_deferrable") == 0)
8369  SetPGVariable("transaction_deferrable",
8370  list_make1(item->arg), stmt->is_local);
8371  else
8372  elog(ERROR, "unexpected SET TRANSACTION element: %s",
8373  item->defname);
8374  }
8375  }
8376  else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
8377  {
8378  ListCell *head;
8379 
8380  foreach(head, stmt->args)
8381  {
8382  DefElem *item = (DefElem *) lfirst(head);
8383 
8384  if (strcmp(item->defname, "transaction_isolation") == 0)
8385  SetPGVariable("default_transaction_isolation",
8386  list_make1(item->arg), stmt->is_local);
8387  else if (strcmp(item->defname, "transaction_read_only") == 0)
8388  SetPGVariable("default_transaction_read_only",
8389  list_make1(item->arg), stmt->is_local);
8390  else if (strcmp(item->defname, "transaction_deferrable") == 0)
8391  SetPGVariable("default_transaction_deferrable",
8392  list_make1(item->arg), stmt->is_local);
8393  else
8394  elog(ERROR, "unexpected SET SESSION element: %s",
8395  item->defname);
8396  }
8397  }
8398  else if (strcmp(stmt->name, "TRANSACTION SNAPSHOT") == 0)
8399  {
8400  A_Const *con = linitial_node(A_Const, stmt->args);
8401 
8402  if (stmt->is_local)
8403  ereport(ERROR,
8404  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8405  errmsg("SET LOCAL TRANSACTION SNAPSHOT is not implemented")));
8406 
8407  WarnNoTransactionBlock(isTopLevel, "SET TRANSACTION");
8408  Assert(nodeTag(&con->val) == T_String);
8409  ImportSnapshot(strVal(&con->val));
8410  }
8411  else
8412  elog(ERROR, "unexpected SET MULTI element: %s",
8413  stmt->name);
8414  break;
8415  case VAR_SET_DEFAULT:
8416  if (stmt->is_local)
8417  WarnNoTransactionBlock(isTopLevel, "SET LOCAL");
8418  /* fall through */
8419  case VAR_RESET:
8420  if (strcmp(stmt->name, "transaction_isolation") == 0)
8421  WarnNoTransactionBlock(isTopLevel, "RESET TRANSACTION");
8422 
8423  (void) set_config_option(stmt->name,
8424  NULL,
8426  PGC_S_SESSION,
8427  action, true, 0, false);
8428  break;
8429  case VAR_RESET_ALL:
8430  ResetAllOptions();
8431  break;
8432  }
8433 }
void ImportSnapshot(const char *idstr)
Definition: snapmgr.c:1462
VariableSetKind kind
Definition: parsenodes.h:2042
void WarnNoTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3412
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:610
bool superuser(void)
Definition: superuser.c:46
#define linitial_node(type, l)
Definition: pg_list.h:198
GucAction
Definition: guc.h:191
#define list_make1(x1)
Definition: pg_list.h:227
bool IsInParallelMode(void)
Definition: xact.c:997
#define ERROR
Definition: elog.h:43
Definition: guc.h:75
void ResetAllOptions(void)
Definition: guc.c:5712
Node * arg
Definition: parsenodes.h:733
#define ereport(elevel,...)
Definition: elog.h:144
#define Assert(condition)
Definition: c.h:738
#define lfirst(lc)
Definition: pg_list.h:190
#define nodeTag(nodeptr)
Definition: nodes.h:534
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214
char * defname
Definition: parsenodes.h:732
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
Definition: guc.c:8442
Value val
Definition: parsenodes.h:289
int set_config_option(const char *name, const char *value, GucContext context, GucSource source, GucAction action, bool changeVal, int elevel, bool is_reload)
Definition: guc.c:6920
void SetPGVariable(const char *name, List *args, bool is_local)
Definition: guc.c:8462

◆ ExtractSetVariableArgs()

char* ExtractSetVariableArgs ( VariableSetStmt stmt)

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

8443 {
8444  switch (stmt->kind)
8445  {
8446  case VAR_SET_VALUE:
8447  return flatten_set_variable_args(stmt->name, stmt->args);
8448  case VAR_SET_CURRENT:
8449  return GetConfigOptionByName(stmt->name, NULL, false);
8450  default:
8451  return NULL;
8452  }
8453 }
VariableSetKind kind
Definition: parsenodes.h:2042
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:9171
static char * flatten_set_variable_args(const char *name, List *args)
Definition: guc.c:7844

◆ FreeConfigVariables()

void FreeConfigVariables ( ConfigVariable list)

◆ GetConfigOption()

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

Definition at line 7709 of file guc.c.

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

Referenced by applyRemoteGucs(), be_tls_init(), and PostmasterMain().

7710 {
7711  struct config_generic *record;
7712  static char buffer[256];
7713 
7714  record = find_option(name, false, ERROR);
7715  if (record == NULL)
7716  {
7717  if (missing_ok)
7718  return NULL;
7719  ereport(ERROR,
7720  (errcode(ERRCODE_UNDEFINED_OBJECT),
7721  errmsg("unrecognized configuration parameter \"%s\"",
7722  name)));
7723  }
7724  if (restrict_privileged &&
7725  (record->flags & GUC_SUPERUSER_ONLY) &&
7726  !is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
7727  ereport(ERROR,
7728  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7729  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
7730  name)));
7731 
7732  switch (record->vartype)
7733  {
7734  case PGC_BOOL:
7735  return *((struct config_bool *) record)->variable ? "on" : "off";
7736 
7737  case PGC_INT:
7738  snprintf(buffer, sizeof(buffer), "%d",
7739  *((struct config_int *) record)->variable);
7740  return buffer;
7741 
7742  case PGC_REAL:
7743  snprintf(buffer, sizeof(buffer), "%g",
7744  *((struct config_real *) record)->variable);
7745  return buffer;
7746 
7747  case PGC_STRING:
7748  return *((struct config_string *) record)->variable;
7749 
7750  case PGC_ENUM:
7751  return config_enum_lookup_by_value((struct config_enum *) record,
7752  *((struct config_enum *) record)->variable);
7753  }
7754  return NULL;
7755 }
Oid GetUserId(void)
Definition: miscinit.c:448
int errcode(int sqlerrcode)
Definition: elog.c:610
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:6616
#define ERROR
Definition: elog.h:43
enum config_type vartype
Definition: guc_tables.h:156
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
#define ereport(elevel,...)
Definition: elog.h:144
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4916
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:5220
const char * name
Definition: encode.c:561
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define snprintf
Definition: port.h:193

◆ GetConfigOptionByName()

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

Definition at line 9171 of file guc.c.

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

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

9172 {
9173  struct config_generic *record;
9174 
9175  record = find_option(name, false, ERROR);
9176  if (record == NULL)
9177  {
9178  if (missing_ok)
9179  {
9180  if (varname)
9181  *varname = NULL;
9182  return NULL;
9183  }
9184 
9185  ereport(ERROR,
9186  (errcode(ERRCODE_UNDEFINED_OBJECT),
9187  errmsg("unrecognized configuration parameter \"%s\"", name)));
9188  }
9189 
9190  if ((record->flags & GUC_SUPERUSER_ONLY) &&
9191  !is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
9192  ereport(ERROR,
9193  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
9194  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
9195  name)));
9196 
9197  if (varname)
9198  *varname = record->name;
9199 
9200  return _ShowOption(record, true);
9201 }
static char * _ShowOption(struct config_generic *record, bool use_units)
Definition: guc.c:9731
Oid GetUserId(void)
Definition: miscinit.c:448
const char * name
Definition: guc_tables.h:149
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
#define ereport(elevel,...)
Definition: elog.h:144
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4916
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:5220
const char * name
Definition: encode.c:561
int errmsg(const char *fmt,...)
Definition: elog.c:824

◆ GetConfigOptionByNum()

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

Definition at line 9208 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, config_enum_get_options(), config_enum_lookup_by_value(), config_generic::context, config_generic::flags, get_config_unit_name(), GetUserId(), config_generic::group, GUC_NO_SHOW_ALL, GUC_PENDING_RESTART, GUC_SUPERUSER_ONLY, is_member_of_role(), config_generic::long_desc, config_int::max, config_real::max, config_int::min, config_real::min, config_generic::name, PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_S_FILE, PGC_STRING, pstrdup(), config_bool::reset_val, config_int::reset_val, config_real::reset_val, config_string::reset_val, config_enum::reset_val, config_generic::short_desc, snprintf, config_generic::source, config_generic::sourcefile, config_generic::sourceline, config_generic::status, and config_generic::vartype.

Referenced by show_all_settings().

9209 {
9210  char buffer[256];
9211  struct config_generic *conf;
9212 
9213  /* check requested variable number valid */
9214  Assert((varnum >= 0) && (varnum < num_guc_variables));
9215 
9216  conf = guc_variables[varnum];
9217 
9218  if (noshow)
9219  {
9220  if ((conf->flags & GUC_NO_SHOW_ALL) ||
9221  ((conf->flags & GUC_SUPERUSER_ONLY) &&
9222  !is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS)))
9223  *noshow = true;
9224  else
9225  *noshow = false;
9226  }
9227 
9228  /* first get the generic attributes */
9229 
9230  /* name */
9231  values[0] = conf->name;
9232 
9233  /* setting: use _ShowOption in order to avoid duplicating the logic */
9234  values[1] = _ShowOption(conf, false);
9235 
9236  /* unit, if any (NULL is fine) */
9237  values[2] = get_config_unit_name(conf->flags);
9238 
9239  /* group */
9240  values[3] = _(config_group_names[conf->group]);
9241 
9242  /* short_desc */
9243  values[4] = _(conf->short_desc);
9244 
9245  /* extra_desc */
9246  values[5] = _(conf->long_desc);
9247 
9248  /* context */
9249  values[6] = GucContext_Names[conf->context];
9250 
9251  /* vartype */
9252  values[7] = config_type_names[conf->vartype];
9253 
9254  /* source */
9255  values[8] = GucSource_Names[conf->source];
9256 
9257  /* now get the type specific attributes */
9258  switch (conf->vartype)
9259  {
9260  case PGC_BOOL:
9261  {
9262  struct config_bool *lconf = (struct config_bool *) conf;
9263 
9264  /* min_val */
9265  values[9] = NULL;
9266 
9267  /* max_val */
9268  values[10] = NULL;
9269 
9270  /* enumvals */
9271  values[11] = NULL;
9272 
9273  /* boot_val */
9274  values[12] = pstrdup(lconf->boot_val ? "on" : "off");
9275 
9276  /* reset_val */
9277  values[13] = pstrdup(lconf->reset_val ? "on" : "off");
9278  }
9279  break;
9280 
9281  case PGC_INT:
9282  {
9283  struct config_int *lconf = (struct config_int *) conf;
9284 
9285  /* min_val */
9286  snprintf(buffer, sizeof(buffer), "%d", lconf->min);
9287  values[9] = pstrdup(buffer);
9288 
9289  /* max_val */
9290  snprintf(buffer, sizeof(buffer), "%d", lconf->max);
9291  values[10] = pstrdup(buffer);
9292 
9293  /* enumvals */
9294  values[11] = NULL;
9295 
9296  /* boot_val */
9297  snprintf(buffer, sizeof(buffer), "%d", lconf->boot_val);
9298  values[12] = pstrdup(buffer);
9299 
9300  /* reset_val */
9301  snprintf(buffer, sizeof(buffer), "%d", lconf->reset_val);
9302  values[13] = pstrdup(buffer);
9303  }
9304  break;
9305 
9306  case PGC_REAL:
9307  {
9308  struct config_real *lconf = (struct config_real *) conf;
9309 
9310  /* min_val */
9311  snprintf(buffer, sizeof(buffer), "%g", lconf->min);
9312  values[9] = pstrdup(buffer);
9313 
9314  /* max_val */
9315  snprintf(buffer, sizeof(buffer), "%g", lconf->max);
9316  values[10] = pstrdup(buffer);
9317 
9318  /* enumvals */
9319  values[11] = NULL;
9320 
9321  /* boot_val */
9322  snprintf(buffer, sizeof(buffer), "%g", lconf->boot_val);
9323  values[12] = pstrdup(buffer);
9324 
9325  /* reset_val */
9326  snprintf(buffer, sizeof(buffer), "%g", lconf->reset_val);
9327  values[13] = pstrdup(buffer);
9328  }
9329  break;
9330 
9331  case PGC_STRING:
9332  {
9333  struct config_string *lconf = (struct config_string *) conf;
9334 
9335  /* min_val */
9336  values[9] = NULL;
9337 
9338  /* max_val */
9339  values[10] = NULL;
9340 
9341  /* enumvals */
9342  values[11] = NULL;
9343 
9344  /* boot_val */
9345  if (lconf->boot_val == NULL)
9346  values[12] = NULL;
9347  else
9348  values[12] = pstrdup(lconf->boot_val);
9349 
9350  /* reset_val */
9351  if (lconf->reset_val == NULL)
9352  values[13] = NULL;
9353  else
9354  values[13] = pstrdup(lconf->reset_val);
9355  }
9356  break;
9357 
9358  case PGC_ENUM:
9359  {
9360  struct config_enum *lconf = (struct config_enum *) conf;
9361 
9362  /* min_val */
9363  values[9] = NULL;
9364 
9365  /* max_val */
9366  values[10] = NULL;
9367 
9368  /* enumvals */
9369 
9370  /*
9371  * NOTE! enumvals with double quotes in them are not
9372  * supported!
9373  */
9374  values[11] = config_enum_get_options((struct config_enum *) conf,
9375  "{\"", "\"}", "\",\"");
9376 
9377  /* boot_val */
9379  lconf->boot_val));
9380 
9381  /* reset_val */
9383  lconf->reset_val));
9384  }
9385  break;
9386 
9387  default:
9388  {
9389  /*
9390  * should never get here, but in case we do, set 'em to NULL
9391  */
9392 
9393  /* min_val */
9394  values[9] = NULL;
9395 
9396  /* max_val */
9397  values[10] = NULL;
9398 
9399  /* enumvals */
9400  values[11] = NULL;
9401 
9402  /* boot_val */
9403  values[12] = NULL;
9404 
9405  /* reset_val */
9406  values[13] = NULL;
9407  }
9408  break;
9409  }
9410 
9411  /*
9412  * If the setting came from a config file, set the source location. For
9413  * security reasons, we don't show source file/line number for
9414  * insufficiently-privileged users.
9415  */
9416  if (conf->source == PGC_S_FILE &&
9417  is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
9418  {
9419  values[14] = conf->sourcefile;
9420  snprintf(buffer, sizeof(buffer), "%d", conf->sourceline);
9421  values[15] = pstrdup(buffer);
9422  }
9423  else
9424  {
9425  values[14] = NULL;
9426  values[15] = NULL;
9427  }
9428 
9429  values[16] = (conf->status & GUC_PENDING_RESTART) ? "t" : "f";
9430 }
GucSource source
Definition: guc_tables.h:158
static char * _ShowOption(struct config_generic *record, bool use_units)
Definition: guc.c:9731
const char * long_desc
Definition: guc_tables.h:153
double reset_val
Definition: guc_tables.h:222
Oid GetUserId(void)
Definition: miscinit.c:448
const char * name
Definition: guc_tables.h:149
const char *const config_type_names[]
Definition: guc.c:783
char * pstrdup(const char *in)
Definition: mcxt.c:1186
const char * short_desc
Definition: guc_tables.h:152
int boot_val
Definition: guc_tables.h:199
const char * boot_val
Definition: guc_tables.h:231
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:6616
#define GUC_NO_SHOW_ALL
Definition: guc.h:206
const char *const GucContext_Names[]
Definition: guc.c:624
const char *const config_group_names[]
Definition: guc.c:667
static int num_guc_variables
Definition: guc.c:4786
char * sourcefile
Definition: guc_tables.h:164
bool boot_val
Definition: guc_tables.h:185
static const char * get_config_unit_name(int flags)
Definition: guc.c:6407
static struct config_generic ** guc_variables
Definition: guc.c:4783
enum config_type vartype
Definition: guc_tables.h:156
double max
Definition: guc_tables.h:217
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4916
char * reset_val
Definition: guc_tables.h:236
double boot_val
Definition: guc_tables.h:215
#define Assert(condition)
Definition: c.h:738
#define GUC_PENDING_RESTART
Definition: guc_tables.h:175
double min
Definition: guc_tables.h:216
static Datum values[MAXATTR]
Definition: bootstrap.c:167
enum config_group group
Definition: guc_tables.h:151
bool reset_val
Definition: guc_tables.h:190
const char *const GucSource_Names[]
Definition: guc.c:643
#define snprintf
Definition: port.h:193
#define _(x)
Definition: elog.c:88
static char * config_enum_get_options(struct config_enum *record, const char *prefix, const char *suffix, const char *separator)
Definition: guc.c:6665
GucContext context
Definition: guc_tables.h:150
int reset_val
Definition: guc_tables.h:206

◆ GetConfigOptionFlags()

int GetConfigOptionFlags ( const char *  name,
bool  missing_ok 
)

Definition at line 7814 of file guc.c.

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

Referenced by pg_get_functiondef().

7815 {
7816  struct config_generic *record;
7817 
7818  record = find_option(name, false, WARNING);
7819  if (record == NULL)
7820  {
7821  if (missing_ok)
7822  return 0;
7823  ereport(ERROR,
7824  (errcode(ERRCODE_UNDEFINED_OBJECT),
7825  errmsg("unrecognized configuration parameter \"%s\"",
7826  name)));
7827  }
7828  return record->flags;
7829 }
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
#define WARNING
Definition: elog.h:40
#define ereport(elevel,...)
Definition: elog.h:144
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:5220
const char * name
Definition: encode.c:561
int errmsg(const char *fmt,...)
Definition: elog.c:824

◆ GetConfigOptionResetString()

const char* GetConfigOptionResetString ( const char *  name)

Definition at line 7765 of file guc.c.

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

Referenced by check_datestyle().

7766 {
7767  struct config_generic *record;
7768  static char buffer[256];
7769 
7770  record = find_option(name, false, ERROR);
7771  if (record == NULL)
7772  ereport(ERROR,
7773  (errcode(ERRCODE_UNDEFINED_OBJECT),
7774  errmsg("unrecognized configuration parameter \"%s\"", name)));
7775  if ((record->flags & GUC_SUPERUSER_ONLY) &&
7776  !is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
7777  ereport(ERROR,
7778  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7779  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
7780  name)));
7781 
7782  switch (record->vartype)
7783  {
7784  case PGC_BOOL:
7785  return ((struct config_bool *) record)->reset_val ? "on" : "off";
7786 
7787  case PGC_INT:
7788  snprintf(buffer, sizeof(buffer), "%d",
7789  ((struct config_int *) record)->reset_val);
7790  return buffer;
7791 
7792  case PGC_REAL:
7793  snprintf(buffer, sizeof(buffer), "%g",
7794  ((struct config_real *) record)->reset_val);
7795  return buffer;
7796 
7797  case PGC_STRING:
7798  return ((struct config_string *) record)->reset_val;
7799 
7800  case PGC_ENUM:
7801  return config_enum_lookup_by_value((struct config_enum *) record,
7802  ((struct config_enum *) record)->reset_val);
7803  }
7804  return NULL;
7805 }
Oid GetUserId(void)
Definition: miscinit.c:448
int errcode(int sqlerrcode)
Definition: elog.c:610
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:6616
#define ERROR
Definition: elog.h:43
enum config_type vartype
Definition: guc_tables.h:156
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
#define ereport(elevel,...)
Definition: elog.h:144
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4916
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:5220
const char * name
Definition: encode.c:561
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define snprintf
Definition: port.h:193

◆ GetNumConfigOptions()

int GetNumConfigOptions ( void  )

Definition at line 9436 of file guc.c.

References num_guc_variables.

Referenced by GucInfoMain(), and show_all_settings().

9437 {
9438  return num_guc_variables;
9439 }
static int num_guc_variables
Definition: guc.c:4786

◆ GetPGVariable()

void GetPGVariable ( const char *  name,
DestReceiver dest 
)

Definition at line 8936 of file guc.c.

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

Referenced by exec_replication_command(), and standard_ProcessUtility().

8937 {
8938  if (guc_name_compare(name, "all") == 0)
8939  ShowAllGUCConfig(dest);
8940  else
8941  ShowGUCConfigOption(name, dest);
8942 }
static void ShowGUCConfigOption(const char *name, DestReceiver *dest)
Definition: guc.c:8980
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:5281
static void ShowAllGUCConfig(DestReceiver *dest)
Definition: guc.c:9008
const char * name
Definition: encode.c:561

◆ GetPGVariableResultDesc()

TupleDesc GetPGVariableResultDesc ( const char *  name)

Definition at line 8945 of file guc.c.

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

Referenced by UtilityTupleDescriptor().

8946 {
8947  TupleDesc tupdesc;
8948 
8949  if (guc_name_compare(name, "all") == 0)
8950  {
8951  /* need a tuple descriptor representing three TEXT columns */
8952  tupdesc = CreateTemplateTupleDesc(3);
8953  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
8954  TEXTOID, -1, 0);
8955  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
8956  TEXTOID, -1, 0);
8957  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
8958  TEXTOID, -1, 0);
8959  }
8960  else
8961  {
8962  const char *varname;
8963 
8964  /* Get the canonical spelling of name */
8965  (void) GetConfigOptionByName(name, &varname, false);
8966 
8967  /* need a tuple descriptor representing a single TEXT column */
8968  tupdesc = CreateTemplateTupleDesc(1);
8969  TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
8970  TEXTOID, -1, 0);
8971  }
8972  return tupdesc;
8973 }
TupleDesc CreateTemplateTupleDesc(int natts)
Definition: tupdesc.c:44
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:5281
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:9171
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:603
const char * name
Definition: encode.c:561
int16 AttrNumber
Definition: attnum.h:21

◆ GUC_check_errcode()

void GUC_check_errcode ( int  sqlerrcode)

◆ GUCArrayAdd()

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

Definition at line 10596 of file guc.c.

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

Referenced by AlterSetting(), and update_proconfig_value().

10597 {
10598  struct config_generic *record;
10599  Datum datum;
10600  char *newval;
10601  ArrayType *a;
10602 
10603  Assert(name);
10604  Assert(value);
10605 
10606  /* test if the option is valid and we're allowed to set it */
10607  (void) validate_option_array_item(name, value, false);
10608 
10609  /* normalize name (converts obsolete GUC names to modern spellings) */
10610  record = find_option(name, false, WARNING);
10611  if (record)
10612  name = record->name;
10613 
10614  /* build new item for array */
10615  newval = psprintf("%s=%s", name, value);
10616  datum = CStringGetTextDatum(newval);
10617 
10618  if (array)
10619  {
10620  int index;
10621  bool isnull;
10622  int i;
10623 
10624  Assert(ARR_ELEMTYPE(array) == TEXTOID);
10625  Assert(ARR_NDIM(array) == 1);
10626  Assert(ARR_LBOUND(array)[0] == 1);
10627 
10628  index = ARR_DIMS(array)[0] + 1; /* add after end */
10629 
10630  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
10631  {
10632  Datum d;
10633  char *current;
10634 
10635  d = array_ref(array, 1, &i,
10636  -1 /* varlenarray */ ,
10637  -1 /* TEXT's typlen */ ,
10638  false /* TEXT's typbyval */ ,
10639  TYPALIGN_INT /* TEXT's typalign */ ,
10640  &isnull);
10641  if (isnull)
10642  continue;
10643  current = TextDatumGetCString(d);
10644 
10645  /* check for match up through and including '=' */
10646  if (strncmp(current, newval, strlen(name) + 1) == 0)
10647  {
10648  index = i;
10649  break;
10650  }
10651  }
10652 
10653  a = array_set(array, 1, &index,
10654  datum,
10655  false,
10656  -1 /* varlena array */ ,
10657  -1 /* TEXT's typlen */ ,
10658  false /* TEXT's typbyval */ ,
10659  TYPALIGN_INT /* TEXT's typalign */ );
10660  }
10661  else
10662  a = construct_array(&datum, 1,
10663  TEXTOID,
10664  -1, false, TYPALIGN_INT);
10665 
10666  return a;
10667 }
const char * name
Definition: guc_tables.h:149
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:3292
ArrayType * array_set(ArrayType *array, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3094
#define ARR_LBOUND(a)
Definition: array.h:284
Definition: type.h:89
static bool validate_option_array_item(const char *name, const char *value, bool skipIfNoPermissions)
Definition: guc.c:10822
#define ARR_DIMS(a)
Definition: array.h:282
Datum array_ref(ArrayType *array, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:3077
#define WARNING
Definition: elog.h:40
#define TextDatumGetCString(d)
Definition: builtins.h:88
uintptr_t Datum
Definition: postgres.h:367
static struct @143 value
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:5220
#define Assert(condition)
Definition: c.h:738
#define newval
#define ARR_NDIM(a)
Definition: array.h:278
const char * name
Definition: encode.c:561
int i
#define CStringGetTextDatum(s)
Definition: builtins.h:87
#define ARR_ELEMTYPE(a)
Definition: array.h:280

◆ GUCArrayDelete()

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

Definition at line 10676 of file guc.c.

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

Referenced by AlterSetting(), and update_proconfig_value().

10677 {
10678  struct config_generic *record;
10679  ArrayType *newarray;
10680  int i;
10681  int index;
10682 
10683  Assert(name);
10684 
10685  /* test if the option is valid and we're allowed to set it */
10686  (void) validate_option_array_item(name, NULL, false);
10687 
10688  /* normalize name (converts obsolete GUC names to modern spellings) */
10689  record = find_option(name, false, WARNING);
10690  if (record)
10691  name = record->name;
10692 
10693  /* if array is currently null, then surely nothing to delete */
10694  if (!array)
10695  return NULL;
10696 
10697  newarray = NULL;
10698  index = 1;
10699 
10700  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
10701  {
10702  Datum d;
10703  char *val;
10704  bool isnull;
10705 
10706  d = array_ref(array, 1, &i,
10707  -1 /* varlenarray */ ,
10708  -1 /* TEXT's typlen */ ,
10709  false /* TEXT's typbyval */ ,
10710  TYPALIGN_INT /* TEXT's typalign */ ,
10711  &isnull);
10712  if (isnull)
10713  continue;
10714  val = TextDatumGetCString(d);
10715 
10716  /* ignore entry if it's what we want to delete */
10717  if (strncmp(val, name, strlen(name)) == 0
10718  && val[strlen(name)] == '=')
10719  continue;
10720 
10721  /* else add it to the output array */
10722  if (newarray)
10723  newarray = array_set(newarray, 1, &index,
10724  d,
10725  false,
10726  -1 /* varlenarray */ ,
10727  -1 /* TEXT's typlen */ ,
10728  false /* TEXT's typbyval */ ,
10729  TYPALIGN_INT /* TEXT's typalign */ );
10730  else
10731  newarray = construct_array(&d, 1,
10732  TEXTOID,
10733  -1, false, TYPALIGN_INT);
10734 
10735  index++;
10736  }
10737 
10738  return newarray;
10739 }
const char * name
Definition: guc_tables.h:149
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3292
ArrayType * array_set(ArrayType *array, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3094
Definition: type.h:89
static bool validate_option_array_item(const char *name, const char *value, bool skipIfNoPermissions)
Definition: guc.c:10822
#define ARR_DIMS(a)
Definition: array.h:282
Datum array_ref(ArrayType *array, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:3077
#define WARNING
Definition: elog.h:40
#define TextDatumGetCString(d)
Definition: builtins.h:88
uintptr_t Datum
Definition: postgres.h:367
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:5220
#define Assert(condition)
Definition: c.h:738
const char * name
Definition: encode.c:561
int i
long val
Definition: informix.c:664

◆ GUCArrayReset()

ArrayType* GUCArrayReset ( ArrayType array)

Definition at line 10748 of file guc.c.

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

Referenced by AlterSetting().

10749 {
10750  ArrayType *newarray;
10751  int i;
10752  int index;
10753 
10754  /* if array is currently null, nothing to do */
10755  if (!array)
10756  return NULL;
10757 
10758  /* if we're superuser, we can delete everything, so just do it */
10759  if (superuser())
10760  return NULL;
10761 
10762  newarray = NULL;
10763  index = 1;
10764 
10765  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
10766  {
10767  Datum d;
10768  char *val;
10769  char *eqsgn;
10770  bool isnull;
10771 
10772  d = array_ref(array, 1, &i,
10773  -1 /* varlenarray */ ,
10774  -1 /* TEXT's typlen */ ,
10775  false /* TEXT's typbyval */ ,
10776  TYPALIGN_INT /* TEXT's typalign */ ,
10777  &isnull);
10778  if (isnull)
10779  continue;
10780  val = TextDatumGetCString(d);
10781 
10782  eqsgn = strchr(val, '=');
10783  *eqsgn = '\0';
10784 
10785  /* skip if we have permission to delete it */
10786  if (validate_option_array_item(val, NULL, true))
10787  continue;
10788 
10789  /* else add it to the output array */
10790  if (newarray)
10791  newarray = array_set(newarray, 1, &index,
10792  d,
10793  false,
10794  -1 /* varlenarray */ ,
10795  -1 /* TEXT's typlen */ ,
10796  false /* TEXT's typbyval */ ,
10797  TYPALIGN_INT /* TEXT's typalign */ );
10798  else
10799  newarray = construct_array(&d, 1,
10800  TEXTOID,
10801  -1, false, TYPALIGN_INT);
10802 
10803  index++;
10804  pfree(val);
10805  }
10806 
10807  return newarray;
10808 }
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3292
bool superuser(void)
Definition: superuser.c:46
ArrayType * array_set(ArrayType *array, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3094
Definition: type.h:89
void pfree(void *pointer)
Definition: mcxt.c:1056
static bool validate_option_array_item(const char *name, const char *value, bool skipIfNoPermissions)
Definition: guc.c:10822
#define ARR_DIMS(a)
Definition: array.h:282
Datum array_ref(ArrayType *array, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:3077
#define TextDatumGetCString(d)
Definition: builtins.h:88
uintptr_t Datum
Definition: postgres.h:367
int i
long val
Definition: informix.c:664

◆ InitializeGUCOptions()

void InitializeGUCOptions ( void  )

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

5316 {
5317  int i;
5318 
5319  /*
5320  * Before log_line_prefix could possibly receive a nonempty setting, make
5321  * sure that timezone processing is minimally alive (see elog.c).
5322  */
5324 
5325  /*
5326  * Build sorted array of all GUC variables.
5327  */
5329 
5330  /*
5331  * Load all variables with their compiled-in defaults, and initialize
5332  * status fields as needed.
5333  */
5334  for (i = 0; i < num_guc_variables; i++)
5335  {
5337  }
5338 
5339  guc_dirty = false;
5340 
5341  reporting_enabled = false;
5342 
5343  /*
5344  * Prevent any attempt to override the transaction modes from
5345  * non-interactive sources.
5346  */
5347  SetConfigOption("transaction_isolation", "read committed",
5349  SetConfigOption("transaction_read_only", "no",
5351  SetConfigOption("transaction_deferrable", "no",
5353 
5354  /*
5355  * For historical reasons, some GUC parameters can receive defaults from
5356  * environment variables. Process those settings.
5357  */
5359 }
void build_guc_variables(void)
Definition: guc.c:5047
static void InitializeGUCOptionsFromEnvironment(void)
Definition: guc.c:5371
void pg_timezone_initialize(void)
Definition: pgtz.c:363
static int num_guc_variables
Definition: guc.c:4786
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:7685
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:5417
static struct config_generic ** guc_variables
Definition: guc.c:4783
int i
static bool reporting_enabled
Definition: guc.c:4794
static bool guc_dirty
Definition: guc.c:4792

◆ NewGUCNestLevel()

◆ parse_int()

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

Definition at line 6464 of file guc.c.

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

Referenced by parse_and_validate_value(), and parse_one_reloption().

6465 {
6466  /*
6467  * We assume here that double is wide enough to represent any integer
6468  * value with adequate precision.
6469  */
6470  double val;
6471  char *endptr;
6472 
6473  /* To suppress compiler warnings, always set output params */
6474  if (result)
6475  *result = 0;
6476  if (hintmsg)
6477  *hintmsg = NULL;
6478 
6479  /*
6480  * Try to parse as an integer (allowing octal or hex input). If the
6481  * conversion stops at a decimal point or 'e', or overflows, re-parse as
6482  * float. This should work fine as long as we have no unit names starting
6483  * with 'e'. If we ever do, the test could be extended to check for a
6484  * sign or digit after 'e', but for now that's unnecessary.
6485  */
6486  errno = 0;
6487  val = strtol(value, &endptr, 0);
6488  if (*endptr == '.' || *endptr == 'e' || *endptr == 'E' ||
6489  errno == ERANGE)
6490  {
6491  errno = 0;
6492  val = strtod(value, &endptr);
6493  }
6494 
6495  if (endptr == value || errno == ERANGE)
6496  return false; /* no HINT for these cases */
6497 
6498  /* reject NaN (infinities will fail range check below) */
6499  if (isnan(val))
6500  return false; /* treat same as syntax error; no HINT */
6501 
6502  /* allow whitespace between number and unit */
6503  while (isspace((unsigned char) *endptr))
6504  endptr++;
6505 
6506  /* Handle possible unit */
6507  if (*endptr != '\0')
6508  {
6509  if ((flags & GUC_UNIT) == 0)
6510  return false; /* this setting does not accept a unit */
6511 
6512  if (!convert_to_base_unit(val,
6513  endptr, (flags & GUC_UNIT),
6514  &val))
6515  {
6516  /* invalid unit, or garbage after the unit; set hint and fail. */
6517  if (hintmsg)
6518  {
6519  if (flags & GUC_UNIT_MEMORY)
6520  *hintmsg = memory_units_hint;
6521  else
6522  *hintmsg = time_units_hint;
6523  }
6524  return false;
6525  }
6526  }
6527 
6528  /* Round to int, then check for overflow */
6529  val = rint(val);
6530 
6531  if (val > INT_MAX || val < INT_MIN)
6532  {
6533  if (hintmsg)
6534  *hintmsg = gettext_noop("Value exceeds integer range.");
6535  return false;
6536  }
6537 
6538  if (result)
6539  *result = (int) val;
6540  return true;
6541 }
#define gettext_noop(x)
Definition: c.h:1159
#define GUC_UNIT
Definition: guc.h:232
static const char * time_units_hint
Definition: guc.c:865
static struct @143 value
static bool convert_to_base_unit(double value, const char *unit, int base_unit, double *base_value)
Definition: guc.c:6264
long val
Definition: informix.c:664
static const char * memory_units_hint
Definition: guc.c:828
#define GUC_UNIT_MEMORY
Definition: guc.h:223

◆ parse_real()

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

Definition at line 6554 of file guc.c.

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

Referenced by parse_and_validate_value(), and parse_one_reloption().

6555 {
6556  double val;
6557  char *endptr;
6558 
6559  /* To suppress compiler warnings, always set output params */
6560  if (result)
6561  *result = 0;
6562  if (hintmsg)
6563  *hintmsg = NULL;
6564 
6565  errno = 0;
6566  val = strtod(value, &endptr);
6567 
6568  if (endptr == value || errno == ERANGE)
6569  return false; /* no HINT for these cases */
6570 
6571  /* reject NaN (infinities will fail range checks later) */
6572  if (isnan(val))
6573  return false; /* treat same as syntax error; no HINT */
6574 
6575  /* allow whitespace between number and unit */
6576  while (isspace((unsigned char) *endptr))
6577  endptr++;
6578 
6579  /* Handle possible unit */
6580  if (*endptr != '\0')
6581  {
6582  if ((flags & GUC_UNIT) == 0)
6583  return false; /* this setting does not accept a unit */
6584 
6585  if (!convert_to_base_unit(val,
6586  endptr, (flags & GUC_UNIT),
6587  &val))
6588  {
6589  /* invalid unit, or garbage after the unit; set hint and fail. */
6590  if (hintmsg)
6591  {
6592  if (flags & GUC_UNIT_MEMORY)
6593  *hintmsg = memory_units_hint;
6594  else
6595  *hintmsg = time_units_hint;
6596  }
6597  return false;
6598  }
6599  }
6600 
6601  if (result)
6602  *result = val;
6603  return true;
6604 }
#define GUC_UNIT
Definition: guc.h:232
static const char * time_units_hint
Definition: guc.c:865
static struct @143 value
static bool convert_to_base_unit(double value, const char *unit, int base_unit, double *base_value)
Definition: guc.c:6264
long val
Definition: informix.c:664
static const char * memory_units_hint
Definition: guc.c:828
#define GUC_UNIT_MEMORY
Definition: guc.h:223

◆ 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 10500 of file guc.c.

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

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

10501 {
10502  size_t equal_pos;
10503  char *cp;
10504 
10505  AssertArg(string);
10506  AssertArg(name);
10507  AssertArg(value);
10508 
10509  equal_pos = strcspn(string, "=");
10510 
10511  if (string[equal_pos] == '=')
10512  {
10513  *name = guc_malloc(FATAL, equal_pos + 1);
10514  strlcpy(*name, string, equal_pos + 1);
10515 
10516  *value = guc_strdup(FATAL, &string[equal_pos + 1]);
10517  }
10518  else
10519  {
10520  /* no equal sign in string */
10521  *name = guc_strdup(FATAL, string);
10522  *value = NULL;
10523  }
10524 
10525  for (cp = *name; *cp; cp++)
10526  if (*cp == '-')
10527  *cp = '_';
10528 }
static char * guc_strdup(int elevel, const char *src)
Definition: guc.c:4856
#define FATAL
Definition: elog.h:52
#define AssertArg(condition)
Definition: c.h:740
static struct @143 value
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
const char * name
Definition: encode.c:561
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4824

◆ ProcessConfigFile()

◆ ProcessGUCArray()

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

Definition at line 10538 of file guc.c.

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

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

10540 {
10541  int i;
10542 
10543  Assert(array != NULL);
10544  Assert(ARR_ELEMTYPE(array) == TEXTOID);
10545  Assert(ARR_NDIM(array) == 1);
10546  Assert(ARR_LBOUND(array)[0] == 1);
10547 
10548  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
10549  {
10550  Datum d;
10551  bool isnull;
10552  char *s;
10553  char *name;
10554  char *value;
10555 
10556  d = array_ref(array, 1, &i,
10557  -1 /* varlenarray */ ,
10558  -1 /* TEXT's typlen */ ,
10559  false /* TEXT's typbyval */ ,
10560  TYPALIGN_INT /* TEXT's typalign */ ,
10561  &isnull);
10562 
10563  if (isnull)
10564  continue;
10565 
10566  s = TextDatumGetCString(d);
10567 
10568  ParseLongOption(s, &name, &value);
10569  if (!value)
10570  {
10571  ereport(WARNING,
10572  (errcode(ERRCODE_SYNTAX_ERROR),
10573  errmsg("could not parse setting for parameter \"%s\"",
10574  name)));
10575  free(name);
10576  continue;
10577  }
10578 
10579  (void) set_config_option(name, value,
10580  context, source,
10581  action, true, 0, false);
10582 
10583  free(name);
10584  if (value)
10585  free(value);
10586  pfree(s);
10587  }
10588 }
GucSource source
Definition: guc_tables.h:158
void ParseLongOption(const char *string, char **name, char **value)
Definition: guc.c:10500
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ARR_LBOUND(a)
Definition: array.h:284
void pfree(void *pointer)
Definition: mcxt.c:1056
#define ARR_DIMS(a)
Definition: array.h:282
Datum array_ref(ArrayType *array, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:3077
#define WARNING
Definition: elog.h:40
#define TextDatumGetCString(d)
Definition: builtins.h:88
uintptr_t Datum
Definition: postgres.h:367
static struct @143 value
#define ereport(elevel,...)
Definition: elog.h:144
#define free(a)
Definition: header.h:65
#define Assert(condition)
Definition: c.h:738
#define ARR_NDIM(a)
Definition: array.h:278
const char * name
Definition: encode.c:561
int errmsg(const char *fmt,...)
Definition: elog.c:824
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:6920
#define ARR_ELEMTYPE(a)
Definition: array.h:280
GucContext context
Definition: guc_tables.h:150

◆ ResetAllOptions()

void ResetAllOptions ( void  )

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

5713 {
5714  int i;
5715 
5716  for (i = 0; i < num_guc_variables; i++)
5717  {
5718  struct config_generic *gconf = guc_variables[i];
5719 
5720  /* Don't reset non-SET-able values */
5721  if (gconf->context != PGC_SUSET &&
5722  gconf->context != PGC_USERSET)
5723  continue;
5724  /* Don't reset if special exclusion from RESET ALL */
5725  if (gconf->flags & GUC_NO_RESET_ALL)
5726  continue;
5727  /* No need to reset if wasn't SET */
5728  if (gconf->source <= PGC_S_OVERRIDE)
5729  continue;
5730 
5731  /* Save old value to support transaction abort */
5733 
5734  switch (gconf->vartype)
5735  {
5736  case PGC_BOOL:
5737  {
5738  struct config_bool *conf = (struct config_bool *) gconf;
5739 
5740  if (conf->assign_hook)
5741  conf->assign_hook(conf->reset_val,
5742  conf->reset_extra);
5743  *conf->variable = conf->reset_val;
5744  set_extra_field(&conf->gen, &conf->gen.extra,
5745  conf->reset_extra);
5746  break;
5747  }
5748  case PGC_INT:
5749  {
5750  struct config_int *conf = (struct config_int *) gconf;
5751 
5752  if (conf->assign_hook)
5753  conf->assign_hook(conf->reset_val,
5754  conf->reset_extra);
5755  *conf->variable = conf->reset_val;
5756  set_extra_field(&conf->gen, &conf->gen.extra,
5757  conf->reset_extra);
5758  break;
5759  }
5760  case PGC_REAL:
5761  {
5762  struct config_real *conf = (struct config_real *) gconf;
5763 
5764  if (conf->assign_hook)
5765  conf->assign_hook(conf->reset_val,
5766  conf->reset_extra);
5767  *conf->variable = conf->reset_val;
5768  set_extra_field(&conf->gen, &conf->gen.extra,
5769  conf->reset_extra);
5770  break;
5771  }
5772  case PGC_STRING:
5773  {
5774  struct config_string *conf = (struct config_string *) gconf;
5775 
5776  if (conf->assign_hook)
5777  conf->assign_hook(conf->reset_val,
5778  conf->reset_extra);
5779  set_string_field(conf, conf->variable, conf->reset_val);
5780  set_extra_field(&conf->gen, &conf->gen.extra,
5781  conf->reset_extra);
5782  break;
5783  }
5784  case PGC_ENUM:
5785  {
5786  struct config_enum *conf = (struct config_enum *) gconf;
5787 
5788  if (conf->assign_hook)
5789  conf->assign_hook(conf->reset_val,
5790  conf->reset_extra);
5791  *conf->variable = conf->reset_val;
5792  set_extra_field(&conf->gen, &conf->gen.extra,
5793  conf->reset_extra);
5794  break;
5795  }
5796  }
5797 
5798  gconf->source = gconf->reset_source;
5799  gconf->scontext = gconf->reset_scontext;
5800 
5801  if (gconf->flags & GUC_REPORT)
5802  ReportGUCOption(gconf);
5803  }
5804 }
GucSource source
Definition: guc_tables.h:158
void * reset_extra
Definition: guc_tables.h:207
GucRealAssignHook assign_hook
Definition: guc_tables.h:219
double reset_val
Definition: guc_tables.h:222
#define GUC_NO_RESET_ALL
Definition: guc.h:207
char ** variable
Definition: guc_tables.h:230
bool * variable
Definition: guc_tables.h:184
GucEnumAssignHook assign_hook
Definition: guc_tables.h:248
GucBoolAssignHook assign_hook
Definition: guc_tables.h:187
GucContext scontext
Definition: guc_tables.h:160
GucIntAssignHook assign_hook
Definition: guc_tables.h:203
static void push_old_value(struct config_generic *gconf, GucAction action)
Definition: guc.c:5812
int * variable
Definition: guc_tables.h:198
int * variable
Definition: guc_tables.h:244
static int num_guc_variables
Definition: guc.c:4786
void * reset_extra
Definition: guc_tables.h:252
Definition: guc.h:75
static void set_extra_field(struct config_generic *gconf, void **field, void *newval)
Definition: guc.c:4957
GucSource reset_source
Definition: guc_tables.h:159
struct config_generic gen
Definition: guc_tables.h:182
struct config_generic gen
Definition: guc_tables.h:196
#define GUC_REPORT
Definition: guc.h:208
double * variable
Definition: guc_tables.h:214
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4896
static struct config_generic ** guc_variables
Definition: guc.c:4783
enum config_type vartype
Definition: guc_tables.h:156
void * reset_extra
Definition: guc_tables.h:223
struct config_generic gen
Definition: guc_tables.h:242
struct config_generic gen
Definition: guc_tables.h:228
char * reset_val
Definition: guc_tables.h:236
GucStringAssignHook assign_hook
Definition: guc_tables.h:233
void * reset_extra
Definition: guc_tables.h:237
void * reset_extra
Definition: guc_tables.h:191
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:6237
bool reset_val
Definition: guc_tables.h:190
GucContext context
Definition: guc_tables.h:150
struct config_generic gen
Definition: guc_tables.h:212
GucContext reset_scontext
Definition: guc_tables.h:161
int reset_val
Definition: guc_tables.h:206

◆ RestoreGUCState()

void RestoreGUCState ( void *  gucstate)

Definition at line 10426 of file guc.c.

References ErrorContextCallback::arg, ErrorContextCallback::callback, can_skip_gucvar(), ereport, errcode(), errmsg(), ERROR, error_context_stack, GUC_ACTION_SET, guc_restore_error_context_callback(), i, InitializeOneGUCOption(), num_guc_variables, ErrorContextCallback::previous, read_gucstate(), read_gucstate_binary(), set_config_option(), and set_config_sourcefile().

Referenced by ParallelWorkerMain().

10427 {
10428  char *varname,
10429  *varvalue,
10430  *varsourcefile;
10431  int varsourceline;
10432  GucSource varsource;
10433  GucContext varscontext;
10434  char *srcptr = (char *) gucstate;
10435  char *srcend;
10436  Size len;
10437  int i;
10438  ErrorContextCallback error_context_callback;
10439 
10440  /* See comment at can_skip_gucvar(). */
10441  for (i = 0; i < num_guc_variables; i++)
10442  if (!can_skip_gucvar(guc_variables[i]))
10444 
10445  /* First item is the length of the subsequent data */
10446  memcpy(&len, gucstate, sizeof(len));
10447 
10448  srcptr += sizeof(len);
10449  srcend = srcptr + len;
10450 
10451  /* If the GUC value check fails, we want errors to show useful context. */
10452  error_context_callback.callback = guc_restore_error_context_callback;
10453  error_context_callback.previous = error_context_stack;
10454  error_context_callback.arg = NULL;
10455  error_context_stack = &error_context_callback;
10456 
10457  while (srcptr < srcend)
10458  {
10459  int result;
10460  char *error_context_name_and_value[2];
10461 
10462  varname = read_gucstate(&srcptr, srcend);
10463  varvalue = read_gucstate(&srcptr, srcend);
10464  varsourcefile = read_gucstate(&srcptr, srcend);
10465  if (varsourcefile[0])
10466  read_gucstate_binary(&srcptr, srcend,
10467  &varsourceline, sizeof(varsourceline));
10468  else
10469  varsourceline = 0;
10470  read_gucstate_binary(&srcptr, srcend,
10471  &varsource, sizeof(varsource));
10472  read_gucstate_binary(&srcptr, srcend,
10473  &varscontext, sizeof(varscontext));
10474 
10475  error_context_name_and_value[0] = varname;
10476  error_context_name_and_value[1] = varvalue;
10477  error_context_callback.arg = &error_context_name_and_value[0];
10478  result = set_config_option(varname, varvalue, varscontext, varsource,
10479  GUC_ACTION_SET, true, ERROR, true);
10480  if (result <= 0)
10481  ereport(ERROR,
10482  (errcode(ERRCODE_INTERNAL_ERROR),
10483  errmsg("parameter \"%s\" could not be set", varname)));
10484  if (varsourcefile[0])
10485  set_config_sourcefile(varname, varsourcefile, varsourceline);
10486  error_context_callback.arg = NULL;
10487  }
10488 
10489  error_context_stack = error_context_callback.previous;
10490 }
GucContext
Definition: guc.h:68
static void static void set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
Definition: guc.c:7651
static void read_gucstate_binary(char **srcptr, char *srcend, void *dest, Size size)
Definition: guc.c:10396
int errcode(int sqlerrcode)
Definition: elog.c:610
void(* callback)(void *arg)
Definition: elog.h:229
struct ErrorContextCallback * previous
Definition: elog.h:228
GucSource
Definition: guc.h:105
ErrorContextCallback * error_context_stack
Definition: elog.c:92
#define ERROR
Definition: elog.h:43
static int num_guc_variables
Definition: guc.c:4786
static bool can_skip_gucvar(struct config_generic *gconf)
Definition: guc.c:10092
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:5417
static void guc_restore_error_context_callback(void *arg)
Definition: guc.c:10410
static struct config_generic ** guc_variables
Definition: guc.c:4783
static char * read_gucstate(char **srcptr, char *srcend)
Definition: guc.c:10373
#define ereport(elevel,...)
Definition: elog.h:144
size_t Size
Definition: c.h:466
int errmsg(const char *fmt,...)
Definition: elog.c:824
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:6920

◆ SelectConfigFiles()

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

Definition at line 5537 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(), sprintf, stat, strerror, and write_stderr.

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

5538 {
5539  char *configdir;
5540  char *fname;
5541  struct stat stat_buf;
5542 
5543  /* configdir is -D option, or $PGDATA if no -D */
5544  if (userDoption)
5545  configdir = make_absolute_path(userDoption);
5546  else
5547  configdir = make_absolute_path(getenv("PGDATA"));
5548 
5549  if (configdir && stat(configdir, &stat_buf) != 0)
5550  {
5551  write_stderr("%s: could not access directory \"%s\": %s\n",
5552  progname,
5553  configdir,
5554  strerror(errno));
5555  if (errno == ENOENT)
5556  write_stderr("Run initdb or pg_basebackup to initialize a PostgreSQL data directory.\n");
5557  return false;
5558  }
5559 
5560  /*
5561  * Find the configuration file: if config_file was specified on the
5562  * command line, use it, else use configdir/postgresql.conf. In any case
5563  * ensure the result is an absolute path, so that it will be interpreted
5564  * the same way by future backends.
5565  */
5566  if (ConfigFileName)
5568  else if (configdir)
5569  {
5570  fname = guc_malloc(FATAL,
5571  strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
5572  sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
5573  }
5574  else
5575  {
5576  write_stderr("%s does not know where to find the server configuration file.\n"
5577  "You must specify the --config-file or -D invocation "
5578  "option or set the PGDATA environment variable.\n",
5579  progname);
5580  return false;
5581  }
5582 
5583  /*
5584  * Set the ConfigFileName GUC variable to its final value, ensuring that
5585  * it can't be overridden later.
5586  */
5587  SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
5588  free(fname);
5589 
5590  /*
5591  * Now read the config file for the first time.
5592  */
5593  if (stat(ConfigFileName, &stat_buf) != 0)
5594  {
5595  write_stderr("%s: could not access the server configuration file \"%s\": %s\n",
5596  progname, ConfigFileName, strerror(errno));
5597  free(configdir);
5598  return false;
5599  }
5600 
5601  /*
5602  * Read the configuration file for the first time. This time only the
5603  * data_directory parameter is picked up to determine the data directory,
5604  * so that we can read the PG_AUTOCONF_FILENAME file next time.
5605  */
5607 
5608  /*
5609  * If the data_directory GUC variable has been set, use that as DataDir;
5610  * otherwise use configdir if set; else punt.
5611  *
5612  * Note: SetDataDir will copy and absolute-ize its argument, so we don't
5613  * have to.
5614  */
5615  if (data_directory)
5617  else if (configdir)
5618  SetDataDir(configdir);
5619  else
5620  {
5621  write_stderr("%s does not know where to find the database system data.\n"
5622  "This can be specified as \"data_directory\" in \"%s\", "
5623  "or by the -D invocation option, or by the "
5624  "PGDATA environment variable.\n",
5626  return false;
5627  }
5628 
5629  /*
5630  * Reflect the final DataDir value back into the data_directory GUC var.
5631  * (If you are wondering why we don't just make them a single variable,
5632  * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
5633  * child backends specially. XXX is that still true? Given that we now
5634  * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
5635  * DataDir in advance.)
5636  */
5638 
5639  /*
5640  * Now read the config file a second time, allowing any settings in the
5641  * PG_AUTOCONF_FILENAME file to take effect. (This is pretty ugly, but
5642  * since we have to determine the DataDir before we can find the autoconf
5643  * file, the alternatives seem worse.)
5644  */
5646 
5647  /*
5648  * If timezone_abbreviations wasn't set in the configuration file, install
5649  * the default value. We do it this way because we can't safely install a
5650  * "real" value until my_exec_path is set, which may not have happened
5651  * when InitializeGUCOptions runs, so the bootstrap default value cannot
5652  * be the real desired default.
5653  */
5655 
5656  /*
5657  * Figure out where pg_hba.conf is, and make sure the path is absolute.
5658  */
5659  if (HbaFileName)
5661  else if (configdir)
5662  {
5663  fname = guc_malloc(FATAL,
5664  strlen(configdir) + strlen(HBA_FILENAME) + 2);
5665  sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
5666  }
5667  else
5668  {
5669  write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
5670  "This can be specified as \"hba_file\" in \"%s\", "
5671  "or by the -D invocation option, or by the "
5672  "PGDATA environment variable.\n",
5674  return false;
5675  }
5676  SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
5677  free(fname);
5678 
5679  /*
5680  * Likewise for pg_ident.conf.
5681  */
5682  if (IdentFileName)
5684  else if (configdir)
5685  {
5686  fname = guc_malloc(FATAL,
5687  strlen(configdir) + strlen(IDENT_FILENAME) + 2);
5688  sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
5689  }
5690  else
5691  {
5692  write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
5693  "This can be specified as \"ident_file\" in \"%s\", "
5694  "or by the -D invocation option, or by the "
5695  "PGDATA environment variable.\n",
5697  return false;
5698  }
5699  SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
5700  free(fname);
5701 
5702  free(configdir);
5703 
5704  return true;
5705 }
char * make_absolute_path(const char *path)
Definition: path.c:608
void ProcessConfigFile(GucContext context)
void SetDataDir(const char *dir)
Definition: miscinit.c:367
char * ConfigFileName
Definition: guc.c:552
static void pg_timezone_abbrev_initialize(void)
Definition: guc.c:11390
#define CONFIG_FILENAME
Definition: guc.c:106
#define write_stderr(str)
Definition: parallel.c:186
const char * progname
Definition: pg_standby.c:36
char * HbaFileName
Definition: guc.c:553
#define sprintf
Definition: port.h:195
#define HBA_FILENAME
Definition: guc.c:107
struct stat stat_buf
Definition: pg_standby.c:100
#define FATAL
Definition: elog.h:52
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:7685
char * IdentFileName
Definition: guc.c:554
#define stat(a, b)
Definition: win32_port.h:255
#define IDENT_FILENAME
Definition: guc.c:108
#define free(a)
Definition: header.h:65
#define strerror
Definition: port.h:206
static const char * userDoption
Definition: postgres.c:157
char * DataDir
Definition: globals.c:62
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4824
static char * data_directory
Definition: guc.c:597

◆ SerializeGUCState()

void SerializeGUCState ( Size  maxsize,
char *  start_address 
)

Definition at line 10346 of file guc.c.

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

Referenced by InitializeParallelDSM().

10347 {
10348  char *curptr;
10349  Size actual_size;
10350  Size bytes_left;
10351  int i;
10352 
10353  /* Reserve space for saving the actual size of the guc state */
10354  Assert(maxsize > sizeof(actual_size));
10355  curptr = start_address + sizeof(actual_size);
10356  bytes_left = maxsize - sizeof(actual_size);
10357 
10358  for (i = 0; i < num_guc_variables; i++)
10359  serialize_variable(&curptr, &bytes_left, guc_variables[i]);
10360 
10361  /* Store actual size without assuming alignment of start_address. */
10362  actual_size = maxsize - bytes_left - sizeof(actual_size);
10363  memcpy(start_address, &actual_size, sizeof(actual_size));
10364 }
static void serialize_variable(char **destptr, Size *maxbytes, struct config_generic *gconf)
Definition: guc.c:10272
static int num_guc_variables
Definition: guc.c:4786
static struct config_generic ** guc_variables
Definition: guc.c:4783
#define Assert(condition)
Definition: c.h:738
size_t Size
Definition: c.h:466
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 6920 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(), DefineIndex(), ExecSetVariableStmt(), execute_extension_script(), parse_subscription_options(), ProcessGUCArray(), reapply_stacked_values(), RestoreGUCState(), RI_Initial_Check(), RI_PartitionRemove_Check(), set_config_by_name(), set_transmission_modes(), SetConfigOption(), SetPGVariable(), and validate_option_array_item().

6924 {
6925  struct config_generic *record;
6926  union config_var_val newval_union;
6927  void *newextra = NULL;
6928  bool prohibitValueChange = false;
6929  bool makeDefault;
6930 
6931  if (elevel == 0)
6932  {
6933  if (source == PGC_S_DEFAULT || source == PGC_S_FILE)
6934  {
6935  /*
6936  * To avoid cluttering the log, only the postmaster bleats loudly
6937  * about problems with the config file.
6938  */
6940  }
6941  else if (source == PGC_S_GLOBAL ||
6942  source == PGC_S_DATABASE ||
6943  source == PGC_S_USER ||
6944  source == PGC_S_DATABASE_USER)
6945  elevel = WARNING;
6946  else
6947  elevel = ERROR;
6948  }
6949 
6950  /*
6951  * GUC_ACTION_SAVE changes are acceptable during a parallel operation,
6952  * because the current worker will also pop the change. We're probably
6953  * dealing with a function having a proconfig entry. Only the function's
6954  * body should observe the change, and peer workers do not share in the
6955  * execution of a function call started by this worker.
6956  *
6957  * Other changes might need to affect other workers, so forbid them.
6958  */
6959  if (IsInParallelMode() && changeVal && action != GUC_ACTION_SAVE)
6960  ereport(elevel,
6961  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
6962  errmsg("cannot set parameters during a parallel operation")));
6963 
6964  record = find_option(name, true, elevel);
6965  if (record == NULL)
6966  {
6967  ereport(elevel,
6968  (errcode(ERRCODE_UNDEFINED_OBJECT),
6969  errmsg("unrecognized configuration parameter \"%s\"", name)));
6970  return 0;
6971  }
6972 
6973  /*
6974  * Check if the option can be set at this time. See guc.h for the precise
6975  * rules.
6976  */
6977  switch (record->context)
6978  {
6979  case PGC_INTERNAL:
6980  if (context != PGC_INTERNAL)
6981  {
6982  ereport(elevel,
6983  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6984  errmsg("parameter \"%s\" cannot be changed",
6985  name)));
6986  return 0;
6987  }
6988  break;
6989  case PGC_POSTMASTER:
6990  if (context == PGC_SIGHUP)
6991  {
6992  /*
6993  * We are re-reading a PGC_POSTMASTER variable from
6994  * postgresql.conf. We can't change the setting, so we should
6995  * give a warning if the DBA tries to change it. However,
6996  * because of variant formats, canonicalization by check
6997  * hooks, etc, we can't just compare the given string directly
6998  * to what's stored. Set a flag to check below after we have
6999  * the final storable value.
7000  */
7001  prohibitValueChange = true;
7002  }
7003  else if (context != PGC_POSTMASTER)
7004  {
7005  ereport(elevel,
7006  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
7007  errmsg("parameter \"%s\" cannot be changed without restarting the server",
7008  name)));
7009  return 0;
7010  }
7011  break;
7012  case PGC_SIGHUP:
7013  if (context != PGC_SIGHUP && context != PGC_POSTMASTER)
7014  {
7015  ereport(elevel,
7016  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
7017  errmsg("parameter \"%s\" cannot be changed now",
7018  name)));
7019  return 0;
7020  }
7021 
7022  /*
7023  * Hmm, the idea of the SIGHUP context is "ought to be global, but
7024  * can be changed after postmaster start". But there's nothing
7025  * that prevents a crafty administrator from sending SIGHUP
7026  * signals to individual backends only.
7027  */
7028  break;
7029  case PGC_SU_BACKEND:
7030  /* Reject if we're connecting but user is not superuser */
7031  if (context == PGC_BACKEND)
7032  {
7033  ereport(elevel,
7034  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7035  errmsg("permission denied to set parameter \"%s\"",
7036  name)));
7037  return 0;
7038  }
7039  /* fall through to process the same as PGC_BACKEND */
7040  /* FALLTHROUGH */
7041  case PGC_BACKEND:
7042  if (context == PGC_SIGHUP)
7043  {
7044  /*
7045  * If a PGC_BACKEND or PGC_SU_BACKEND parameter is changed in
7046  * the config file, we want to accept the new value in the
7047  * postmaster (whence it will propagate to
7048  * subsequently-started backends), but ignore it in existing
7049  * backends. This is a tad klugy, but necessary because we
7050  * don't re-read the config file during backend start.
7051  *
7052  * In EXEC_BACKEND builds, this works differently: we load all
7053  * non-default settings from the CONFIG_EXEC_PARAMS file
7054  * during backend start. In that case we must accept
7055  * PGC_SIGHUP settings, so as to have the same value as if
7056  * we'd forked from the postmaster. This can also happen when
7057  * using RestoreGUCState() within a background worker that
7058  * needs to have the same settings as the user backend that
7059  * started it. is_reload will be true when either situation
7060  * applies.
7061  */
7062  if (IsUnderPostmaster && !is_reload)
7063  return -1;
7064  }
7065  else if (context != PGC_POSTMASTER &&
7066  context != PGC_BACKEND &&
7067  context != PGC_SU_BACKEND &&
7068  source != PGC_S_CLIENT)
7069  {
7070  ereport(elevel,
7071  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
7072  errmsg("parameter \"%s\" cannot be set after connection start",
7073  name)));
7074  return 0;
7075  }
7076  break;
7077  case PGC_SUSET:
7078  if (context == PGC_USERSET || context == PGC_BACKEND)
7079  {
7080  ereport(elevel,
7081  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7082  errmsg("permission denied to set parameter \"%s\"",
7083  name)));
7084  return 0;
7085  }
7086  break;
7087  case PGC_USERSET:
7088  /* always okay */
7089  break;
7090  }
7091 
7092  /*
7093  * Disallow changing GUC_NOT_WHILE_SEC_REST values if we are inside a
7094  * security restriction context. We can reject this regardless of the GUC
7095  * context or source, mainly because sources that it might be reasonable
7096  * to override for won't be seen while inside a function.
7097  *
7098  * Note: variables marked GUC_NOT_WHILE_SEC_REST should usually be marked
7099  * GUC_NO_RESET_ALL as well, because ResetAllOptions() doesn't check this.
7100  * An exception might be made if the reset value is assumed to be "safe".
7101  *
7102  * Note: this flag is currently used for "session_authorization" and
7103  * "role". We need to prohibit changing these inside a local userid
7104  * context because when we exit it, GUC won't be notified, leaving things
7105  * out of sync. (This could be fixed by forcing a new GUC nesting level,
7106  * but that would change behavior in possibly-undesirable ways.) Also, we
7107  * prohibit changing these in a security-restricted operation because
7108  * otherwise RESET could be used to regain the session user's privileges.
7109  */
7110  if (record->flags & GUC_NOT_WHILE_SEC_REST)
7111  {
7112  if (InLocalUserIdChange())
7113  {
7114  /*
7115  * Phrasing of this error message is historical, but it's the most
7116  * common case.
7117  */
7118  ereport(elevel,
7119  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7120  errmsg("cannot set parameter \"%s\" within security-definer function",
7121  name)));
7122  return 0;
7123  }
7125  {
7126  ereport(elevel,
7127  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7128  errmsg("cannot set parameter \"%s\" within security-restricted operation",
7129  name)));
7130  return 0;
7131  }
7132  }
7133 
7134  /*
7135  * Should we set reset/stacked values? (If so, the behavior is not
7136  * transactional.) This is done either when we get a default value from
7137  * the database's/user's/client's default settings or when we reset a
7138  * value to its default.
7139  */
7140  makeDefault = changeVal && (source <= PGC_S_OVERRIDE) &&
7141  ((value != NULL) || source == PGC_S_DEFAULT);
7142 
7143  /*
7144  * Ignore attempted set if overridden by previously processed setting.
7145  * However, if changeVal is false then plow ahead anyway since we are
7146  * trying to find out if the value is potentially good, not actually use
7147  * it. Also keep going if makeDefault is true, since we may want to set
7148  * the reset/stacked values even if we can't set the variable itself.
7149  */
7150  if (record->source > source)
7151  {
7152  if (changeVal && !makeDefault)
7153  {
7154  elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
7155  name);
7156  return -1;
7157  }
7158  changeVal = false;
7159  }
7160 
7161  /*
7162  * Evaluate value and set variable.
7163  */
7164  switch (record->vartype)
7165  {
7166  case PGC_BOOL:
7167  {
7168  struct config_bool *conf = (struct config_bool *) record;
7169 
7170 #define newval (newval_union.boolval)
7171 
7172  if (value)
7173  {
7174  if (!parse_and_validate_value(record, name, value,
7175  source, elevel,
7176  &newval_union, &newextra))
7177  return 0;
7178  }
7179  else if (source == PGC_S_DEFAULT)
7180  {
7181  newval = conf->boot_val;
7182  if (!call_bool_check_hook(conf, &newval, &newextra,
7183  source, elevel))
7184  return 0;
7185  }
7186  else
7187  {
7188  newval = conf->reset_val;
7189  newextra = conf->reset_extra;
7190  source = conf->gen.reset_source;
7191  context = conf->gen.reset_scontext;
7192  }
7193 
7194  if (prohibitValueChange)
7195  {
7196  if (*conf->variable != newval)
7197  {
7198  record->status |= GUC_PENDING_RESTART;
7199  ereport(elevel,
7200  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
7201  errmsg("parameter \"%s\" cannot be changed without restarting the server",
7202  name)));
7203  return 0;
7204  }
7205  record->status &= ~GUC_PENDING_RESTART;
7206  return -1;
7207  }
7208 
7209  if (changeVal)
7210  {
7211  /* Save old value to support transaction abort */
7212  if (!makeDefault)
7213  push_old_value(&conf->gen, action);
7214 
7215  if (conf->assign_hook)
7216  conf->assign_hook(newval, newextra);
7217  *conf->variable = newval;
7218  set_extra_field(&conf->gen, &conf->gen.extra,
7219  newextra);
7220  conf->gen.source = source;
7221  conf->gen.scontext = context;
7222  }
7223  if (makeDefault)
7224  {
7225  GucStack *stack;
7226 
7227  if (conf->gen.reset_source <= source)
7228  {
7229  conf->reset_val = newval;
7230  set_extra_field(&conf->gen, &conf->reset_extra,
7231  newextra);
7232  conf->gen.reset_source = source;
7233  conf->gen.reset_scontext = context;
7234  }
7235  for (stack = conf->gen.stack; stack; stack = stack->prev)
7236  {
7237  if (stack->source <= source)
7238  {
7239  stack->prior.val.boolval = newval;
7240  set_extra_field(&conf->gen, &stack->prior.extra,
7241  newextra);
7242  stack->source = source;
7243  stack->scontext = context;
7244  }
7245  }
7246  }
7247 
7248  /* Perhaps we didn't install newextra anywhere */
7249  if (newextra && !extra_field_used(&conf->gen, newextra))
7250  free(newextra);
7251  break;
7252 
7253 #undef newval
7254  }
7255 
7256  case PGC_INT:
7257  {
7258  struct config_int *conf = (struct config_int *) record;
7259 
7260 #define newval (newval_union.intval)
7261 
7262  if (value)
7263  {
7264  if (!parse_and_validate_value(record, name, value,
7265  source, elevel,
7266  &newval_union, &newextra))
7267  return 0;
7268  }
7269  else if (source == PGC_S_DEFAULT)
7270  {
7271  newval = conf->boot_val;
7272  if (!call_int_check_hook(conf, &newval, &newextra,
7273  source, elevel))
7274  return 0;
7275  }
7276  else
7277  {
7278  newval = conf->reset_val;
7279  newextra = conf->reset_extra;
7280  source = conf->gen.reset_source;
7281  context = conf->gen.reset_scontext;
7282  }
7283 
7284  if (prohibitValueChange)
7285  {
7286  if (*conf->variable != newval)
7287  {
7288  record->status |= GUC_PENDING_RESTART;
7289  ereport(elevel,
7290  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
7291  errmsg("parameter \"%s\" cannot be changed without restarting the server",
7292  name)));
7293  return 0;
7294  }
7295  record->status &= ~GUC_PENDING_RESTART;
7296  return -1;
7297  }
7298 
7299  if (changeVal)
7300  {
7301  /* Save old value to support transaction abort */
7302  if (!makeDefault)
7303  push_old_value(&conf->gen, action);
7304 
7305  if (conf->assign_hook)
7306  conf->assign_hook(newval, newextra);
7307  *conf->variable = newval;
7308  set_extra_field(&conf->gen, &conf->gen.extra,
7309  newextra);
7310  conf->gen.source = source;
7311  conf->gen.scontext = context;
7312  }
7313  if (makeDefault)
7314  {
7315  GucStack *stack;
7316 
7317  if (conf->gen.reset_source <= source)
7318  {
7319  conf->reset_val = newval;
7320  set_extra_field(&conf->gen, &conf->reset_extra,
7321  newextra);
7322  conf->gen.reset_source = source;
7323  conf->gen.reset_scontext = context;
7324  }
7325  for (stack = conf->gen.stack; stack; stack = stack->prev)
7326  {
7327  if (stack->source <= source)
7328  {
7329  stack->prior.val.intval = newval;
7330  set_extra_field(&conf->gen, &stack->prior.extra,
7331  newextra);
7332  stack->source = source;
7333  stack->scontext = context;
7334  }
7335  }
7336  }
7337 
7338  /* Perhaps we didn't install newextra anywhere */
7339  if (newextra && !extra_field_used(&conf->gen, newextra))
7340  free(newextra);
7341  break;
7342 
7343 #undef newval
7344  }
7345 
7346  case PGC_REAL:
7347  {
7348  struct config_real *conf = (struct config_real *) record;
7349 
7350 #define newval (newval_union.realval)
7351 
7352  if (value)
7353  {
7354  if (!parse_and_validate_value(record, name, value,
7355  source, elevel,
7356  &newval_union, &newextra))
7357  return 0;
7358  }
7359  else if (source == PGC_S_DEFAULT)
7360  {
7361  newval = conf->boot_val;
7362  if (!call_real_check_hook(conf, &newval, &newextra,
7363  source, elevel))
7364  return 0;
7365  }
7366  else
7367  {
7368  newval = conf->reset_val;
7369  newextra = conf->reset_extra;
7370  source = conf->gen.reset_source;
7371  context = conf->gen.reset_scontext;
7372  }
7373 
7374  if (prohibitValueChange)
7375  {
7376  if (*conf->variable != newval)
7377  {
7378  record->status |= GUC_PENDING_RESTART;
7379  ereport(elevel,
7380  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
7381  errmsg("parameter \"%s\" cannot be changed without restarting the server",
7382  name)));
7383  return 0;
7384  }
7385  record->status &= ~GUC_PENDING_RESTART;
7386  return -1;
7387  }
7388 
7389  if (changeVal)
7390  {
7391  /* Save old value to support transaction abort */
7392  if (!makeDefault)
7393  push_old_value(&conf->gen, action);
7394 
7395  if (conf->assign_hook)
7396  conf->assign_hook(newval, newextra);
7397  *conf->variable = newval;
7398  set_extra_field(&conf->gen, &conf->gen.extra,
7399  newextra);
7400  conf->gen.source = source;
7401  conf->gen.scontext = context;
7402  }
7403  if (makeDefault)
7404  {
7405  GucStack *stack;
7406 
7407  if (conf->gen.reset_source <= source)
7408  {
7409  conf->reset_val = newval;
7410  set_extra_field(&conf->gen, &conf->reset_extra,
7411  newextra);
7412  conf->gen.reset_source = source;
7413  conf->gen.reset_scontext = context;
7414  }
7415  for (stack = conf->gen.stack; stack; stack = stack->prev)
7416  {
7417  if (stack->source <= source)
7418  {
7419  stack->prior.val.realval = newval;
7420  set_extra_field(&conf->gen, &stack->prior.extra,
7421  newextra);
7422  stack->source = source;
7423  stack->scontext = context;
7424  }
7425  }
7426  }
7427 
7428  /* Perhaps we didn't install newextra anywhere */
7429  if (newextra && !extra_field_used(&conf->gen, newextra))
7430  free(newextra);
7431  break;
7432 
7433 #undef newval
7434  }
7435 
7436  case PGC_STRING:
7437  {
7438  struct config_string *conf = (struct config_string *) record;
7439 
7440 #define newval (newval_union.stringval)
7441 
7442  if (value)
7443  {
7444  if (!parse_and_validate_value(record, name, value,
7445  source, elevel,
7446  &newval_union, &newextra))
7447  return 0;
7448  }
7449  else if (source == PGC_S_DEFAULT)
7450  {
7451  /* non-NULL boot_val must always get strdup'd */
7452  if (conf->boot_val != NULL)
7453  {
7454  newval = guc_strdup(elevel, conf->boot_val);
7455  if (newval == NULL)
7456  return 0;
7457  }
7458  else
7459  newval = NULL;
7460 
7461  if (!call_string_check_hook(conf, &newval, &newextra,
7462  source, elevel))
7463  {
7464  free(newval);
7465  return 0;
7466  }
7467  }
7468  else
7469  {
7470  /*
7471  * strdup not needed, since reset_val is already under
7472  * guc.c's control
7473  */
7474  newval = conf->reset_val;
7475  newextra = conf->reset_extra;
7476  source = conf->gen.reset_source;
7477  context = conf->gen.reset_scontext;
7478  }
7479 
7480  if (prohibitValueChange)
7481  {
7482  /* newval shouldn't be NULL, so we're a bit sloppy here */
7483  if (*conf->variable == NULL || newval == NULL ||
7484  strcmp(*conf->variable, newval) != 0)
7485  {
7486  record->status |= GUC_PENDING_RESTART;
7487