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.

Referenced by get_hash_mem().

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

8134 {
8135  char *name;
8136  char *value;
8137  bool resetall = false;
8138  ConfigVariable *head = NULL;
8139  ConfigVariable *tail = NULL;
8140  volatile int Tmpfd;
8141  char AutoConfFileName[MAXPGPATH];
8142  char AutoConfTmpFileName[MAXPGPATH];
8143 
8144  if (!superuser())
8145  ereport(ERROR,
8146  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
8147  errmsg("must be superuser to execute ALTER SYSTEM command")));
8148 
8149  /*
8150  * Extract statement arguments
8151  */
8152  name = altersysstmt->setstmt->name;
8153 
8154  switch (altersysstmt->setstmt->kind)
8155  {
8156  case VAR_SET_VALUE:
8157  value = ExtractSetVariableArgs(altersysstmt->setstmt);
8158  break;
8159 
8160  case VAR_SET_DEFAULT:
8161  case VAR_RESET:
8162  value = NULL;
8163  break;
8164 
8165  case VAR_RESET_ALL:
8166  value = NULL;
8167  resetall = true;
8168  break;
8169 
8170  default:
8171  elog(ERROR, "unrecognized alter system stmt type: %d",
8172  altersysstmt->setstmt->kind);
8173  break;
8174  }
8175 
8176  /*
8177  * Unless it's RESET_ALL, validate the target variable and value
8178  */
8179  if (!resetall)
8180  {
8181  struct config_generic *record;
8182 
8183  record = find_option(name, false, ERROR);
8184  if (record == NULL)
8185  ereport(ERROR,
8186  (errcode(ERRCODE_UNDEFINED_OBJECT),
8187  errmsg("unrecognized configuration parameter \"%s\"",
8188  name)));
8189 
8190  /*
8191  * Don't allow parameters that can't be set in configuration files to
8192  * be set in PG_AUTOCONF_FILENAME file.
8193  */
8194  if ((record->context == PGC_INTERNAL) ||
8195  (record->flags & GUC_DISALLOW_IN_FILE) ||
8196  (record->flags & GUC_DISALLOW_IN_AUTO_FILE))
8197  ereport(ERROR,
8198  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
8199  errmsg("parameter \"%s\" cannot be changed",
8200  name)));
8201 
8202  /*
8203  * If a value is specified, verify that it's sane.
8204  */
8205  if (value)
8206  {
8207  union config_var_val newval;
8208  void *newextra = NULL;
8209 
8210  /* Check that it's acceptable for the indicated parameter */
8211  if (!parse_and_validate_value(record, name, value,
8212  PGC_S_FILE, ERROR,
8213  &newval, &newextra))
8214  ereport(ERROR,
8215  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8216  errmsg("invalid value for parameter \"%s\": \"%s\"",
8217  name, value)));
8218 
8219  if (record->vartype == PGC_STRING && newval.stringval != NULL)
8220  free(newval.stringval);
8221  if (newextra)
8222  free(newextra);
8223 
8224  /*
8225  * We must also reject values containing newlines, because the
8226  * grammar for config files doesn't support embedded newlines in
8227  * string literals.
8228  */
8229  if (strchr(value, '\n'))
8230  ereport(ERROR,
8231  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8232  errmsg("parameter value for ALTER SYSTEM must not contain a newline")));
8233  }
8234  }
8235 
8236  /*
8237  * PG_AUTOCONF_FILENAME and its corresponding temporary file are always in
8238  * the data directory, so we can reference them by simple relative paths.
8239  */
8240  snprintf(AutoConfFileName, sizeof(AutoConfFileName), "%s",
8242  snprintf(AutoConfTmpFileName, sizeof(AutoConfTmpFileName), "%s.%s",
8243  AutoConfFileName,
8244  "tmp");
8245 
8246  /*
8247  * Only one backend is allowed to operate on PG_AUTOCONF_FILENAME at a
8248  * time. Use AutoFileLock to ensure that. We must hold the lock while
8249  * reading the old file contents.
8250  */
8251  LWLockAcquire(AutoFileLock, LW_EXCLUSIVE);
8252 
8253  /*
8254  * If we're going to reset everything, then no need to open or parse the
8255  * old file. We'll just write out an empty list.
8256  */
8257  if (!resetall)
8258  {
8259  struct stat st;
8260 
8261  if (stat(AutoConfFileName, &st) == 0)
8262  {
8263  /* open old file PG_AUTOCONF_FILENAME */
8264  FILE *infile;
8265 
8266  infile = AllocateFile(AutoConfFileName, "r");
8267  if (infile == NULL)
8268  ereport(ERROR,
8270  errmsg("could not open file \"%s\": %m",
8271  AutoConfFileName)));
8272 
8273  /* parse it */
8274  if (!ParseConfigFp(infile, AutoConfFileName, 0, LOG, &head, &tail))
8275  ereport(ERROR,
8276  (errcode(ERRCODE_CONFIG_FILE_ERROR),
8277  errmsg("could not parse contents of file \"%s\"",
8278  AutoConfFileName)));
8279 
8280  FreeFile(infile);
8281  }
8282 
8283  /*
8284  * Now, replace any existing entry with the new value, or add it if
8285  * not present.
8286  */
8287  replace_auto_config_value(&head, &tail, name, value);
8288  }
8289 
8290  /*
8291  * To ensure crash safety, first write the new file data to a temp file,
8292  * then atomically rename it into place.
8293  *
8294  * If there is a temp file left over due to a previous crash, it's okay to
8295  * truncate and reuse it.
8296  */
8297  Tmpfd = BasicOpenFile(AutoConfTmpFileName,
8298  O_CREAT | O_RDWR | O_TRUNC);
8299  if (Tmpfd < 0)
8300  ereport(ERROR,
8302  errmsg("could not open file \"%s\": %m",
8303  AutoConfTmpFileName)));
8304 
8305  /*
8306  * Use a TRY block to clean up the file if we fail. Since we need a TRY
8307  * block anyway, OK to use BasicOpenFile rather than OpenTransientFile.
8308  */
8309  PG_TRY();
8310  {
8311  /* Write and sync the new contents to the temporary file */
8312  write_auto_conf_file(Tmpfd, AutoConfTmpFileName, head);
8313 
8314  /* Close before renaming; may be required on some platforms */
8315  close(Tmpfd);
8316  Tmpfd = -1;
8317 
8318  /*
8319  * As the rename is atomic operation, if any problem occurs after this
8320  * at worst it can lose the parameters set by last ALTER SYSTEM
8321  * command.
8322  */
8323  durable_rename(AutoConfTmpFileName, AutoConfFileName, ERROR);
8324  }
8325  PG_CATCH();
8326  {
8327  /* Close file first, else unlink might fail on some platforms */
8328  if (Tmpfd >= 0)
8329  close(Tmpfd);
8330 
8331  /* Unlink, but ignore any error */
8332  (void) unlink(AutoConfTmpFileName);
8333 
8334  PG_RE_THROW();
8335  }
8336  PG_END_TRY();
8337 
8338  FreeConfigVariables(head);
8339 
8340  LWLockRelease(AutoFileLock);
8341 }
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:6752
VariableSetKind kind
Definition: parsenodes.h:2044
static struct @142 value
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:3196
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:659
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:7995
#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:5249
#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:986
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:8063
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:8471
#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 4307 of file namespace.c.

References baseSearchPathValid.

4308 {
4309  /*
4310  * We mark the path as needing recomputation, but don't do anything until
4311  * it's needed. This avoids trying to do database access during GUC
4312  * initialization, or outside a transaction.
4313  */
4314  baseSearchPathValid = false;
4315 }
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 10374 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.

10375 {
10376  if (sync_method != new_sync_method)
10377  {
10378  /*
10379  * To ensure that no blocks escape unsynced, force an fsync on the
10380  * currently open log segment (if any). Also, if the open flag is
10381  * changing, close the log file so it will be reopened (with new flag
10382  * bit) at next use.
10383  */
10384  if (openLogFile >= 0)
10385  {
10387  if (pg_fsync(openLogFile) != 0)
10388  {
10389  char xlogfname[MAXFNAMELEN];
10390  int save_errno;
10391 
10392  save_errno = errno;
10395  errno = save_errno;
10396  ereport(PANIC,
10398  errmsg("could not fsync file \"%s\": %m", xlogfname)));
10399  }
10400 
10402  if (get_sync_bit(sync_method) != get_sync_bit(new_sync_method))
10403  XLogFileClose();
10404  }
10405  }
10406 }
int wal_segment_size
Definition: xlog.c:117
static int get_sync_bit(int method)
Definition: xlog.c:10318
#define PANIC
Definition: elog.h:53
static XLogSegNo openLogSegNo
Definition: xlog.c:799
static void XLogFileClose(void)
Definition: xlog.c:3851
int errcode_for_file_access(void)
Definition: elog.c:633
static void pgstat_report_wait_end(void)
Definition: pgstat.h:1386
#define MAXFNAMELEN
static int openLogFile
Definition: xlog.c:798
TimeLineID ThisTimeLineID
Definition: xlog.c:192
#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:1362
int sync_method
Definition: xlog.c:106
int errmsg(const char *fmt,...)
Definition: elog.c:824
int pg_fsync(int fd)
Definition: fd.c:346

◆ AtEOXact_GUC()

void AtEOXact_GUC ( bool  isCommit,
int  nestLevel 
)

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

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

References elog, and WARNING.

Referenced by StartTransaction().

5923 {
5924  /*
5925  * The nest level should be 0 between transactions; if it isn't, somebody
5926  * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
5927  * throw a warning but make no other effort to clean up.
5928  */
5929  if (GUCNestLevel != 0)
5930  elog(WARNING, "GUC nest level = %d at transaction start",
5931  GUCNestLevel);
5932  GUCNestLevel = 1;
5933 }
static int GUCNestLevel
Definition: guc.c:4825
#define WARNING
Definition: elog.h:40
#define elog(elevel,...)
Definition: elog.h:214

◆ BeginReportingGUCOptions()

void BeginReportingGUCOptions ( void  )

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

6239 {
6240  int i;
6241 
6242  /*
6243  * Don't do anything unless talking to an interactive frontend of protocol
6244  * 3.0 or later.
6245  */
6246  if (whereToSendOutput != DestRemote ||
6248  return;
6249 
6250  reporting_enabled = true;
6251 
6252  /* Transmit initial values of interesting variables */
6253  for (i = 0; i < num_guc_variables; i++)
6254  {
6255  struct config_generic *conf = guc_variables[i];
6256 
6257  if (conf->flags & GUC_REPORT)
6258  ReportGUCOption(conf);
6259  }
6260 }
#define PG_PROTOCOL_MAJOR(v)
Definition: pqcomm.h:104
static int num_guc_variables
Definition: guc.c:4815
#define GUC_REPORT
Definition: guc.h:208
static struct config_generic ** guc_variables
Definition: guc.c:4812
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:6266
CommandDest whereToSendOutput
Definition: postgres.c:91
static bool reporting_enabled
Definition: guc.c:4823
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:651
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:371
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 4273 of file namespace.c.

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

4274 {
4275  char *rawname;
4276  List *namelist;
4277 
4278  /* Need a modifiable copy of string */
4279  rawname = pstrdup(*newval);
4280 
4281  /* Parse string into list of identifiers */
4282  if (!SplitIdentifierString(rawname, ',', &namelist))
4283  {
4284  /* syntax error in name list */
4285  GUC_check_errdetail("List syntax is invalid.");
4286  pfree(rawname);
4287  list_free(namelist);
4288  return false;
4289  }
4290 
4291  /*
4292  * We used to try to check that the named schemas exist, but there are
4293  * many valid use-cases for having search_path settings that include
4294  * schemas that don't exist; and often, we are not inside a transaction
4295  * here and so can't consult the system catalogs anyway. So now, the only
4296  * requirement is syntactic validity of the identifier list.
4297  */
4298 
4299  pfree(rawname);
4300  list_free(namelist);
4301 
4302  return true;
4303 }
#define GUC_check_errdetail
Definition: guc.h:415
char * pstrdup(const char *in)
Definition: mcxt.c:1187
void pfree(void *pointer)
Definition: mcxt.c:1057
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3702
#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:476
#define GUC_check_errdetail
Definition: guc.h:415
char * pstrdup(const char *in)
Definition: mcxt.c:1187
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:1057
#define ACL_CREATE
Definition: parsenodes.h:84
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3702
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:169
static int list_length(const List *l)
Definition: pg_list.h:149
#define newval
bool IsTransactionState(void)
Definition: xact.c:371
void * palloc(Size size)
Definition: mcxt.c:950
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:668

◆ check_wal_buffers()

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

Definition at line 4987 of file xlog.c.

References XLOGbuffers, and XLOGChooseNumBuffers().

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

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

8810 {
8811  struct config_bool *var;
8812 
8813  var = (struct config_bool *)
8814  init_custom_variable(name, short_desc, long_desc, context, flags,
8815  PGC_BOOL, sizeof(struct config_bool));
8816  var->variable = valueAddr;
8817  var->boot_val = bootValue;
8818  var->reset_val = bootValue;
8819  var->check_hook = check_hook;
8820  var->assign_hook = assign_hook;
8821  var->show_hook = show_hook;
8822  define_custom_variable(&var->gen);
8823 }
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:8559
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:8619

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

8922 {
8923  struct config_enum *var;
8924 
8925  var = (struct config_enum *)
8926  init_custom_variable(name, short_desc, long_desc, context, flags,
8927  PGC_ENUM, sizeof(struct config_enum));
8928  var->variable = valueAddr;
8929  var->boot_val = bootValue;
8930  var->reset_val = bootValue;
8931  var->options = options;
8932  var->check_hook = check_hook;
8933  var->assign_hook = assign_hook;
8934  var->show_hook = show_hook;
8935  define_custom_variable(&var->gen);
8936 }
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:8559
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:8619

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

8838 {
8839  struct config_int *var;
8840 
8841  var = (struct config_int *)
8842  init_custom_variable(name, short_desc, long_desc, context, flags,
8843  PGC_INT, sizeof(struct config_int));
8844  var->variable = valueAddr;
8845  var->boot_val = bootValue;
8846  var->reset_val = bootValue;
8847  var->min = minValue;
8848  var->max = maxValue;
8849  var->check_hook = check_hook;
8850  var->assign_hook = assign_hook;
8851  var->show_hook = show_hook;
8852  define_custom_variable(&var->gen);
8853 }
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:8559
const char * name
Definition: encode.c:561
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8619
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 8856 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().

8868 {
8869  struct config_real *var;
8870 
8871  var = (struct config_real *)
8872  init_custom_variable(name, short_desc, long_desc, context, flags,
8873  PGC_REAL, sizeof(struct config_real));
8874  var->variable = valueAddr;
8875  var->boot_val = bootValue;
8876  var->reset_val = bootValue;
8877  var->min = minValue;
8878  var->max = maxValue;
8879  var->check_hook = check_hook;
8880  var->assign_hook = assign_hook;
8881  var->show_hook = show_hook;
8882  define_custom_variable(&var->gen);
8883 }
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:8559
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:8619
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 8886 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().

8896 {
8897  struct config_string *var;
8898 
8899  var = (struct config_string *)
8900  init_custom_variable(name, short_desc, long_desc, context, flags,
8901  PGC_STRING, sizeof(struct config_string));
8902  var->variable = valueAddr;
8903  var->boot_val = bootValue;
8904  var->check_hook = check_hook;
8905  var->assign_hook = assign_hook;
8906  var->show_hook = show_hook;
8907  define_custom_variable(&var->gen);
8908 }
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:8559
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:8619

◆ EmitWarningsOnPlaceholders()

void EmitWarningsOnPlaceholders ( const char *  className)

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

8940 {
8941  int classLen = strlen(className);
8942  int i;
8943 
8944  for (i = 0; i < num_guc_variables; i++)
8945  {
8946  struct config_generic *var = guc_variables[i];
8947 
8948  if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
8949  strncmp(className, var->name, classLen) == 0 &&
8950  var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
8951  {
8952  ereport(WARNING,
8953  (errcode(ERRCODE_UNDEFINED_OBJECT),
8954  errmsg("unrecognized configuration parameter \"%s\"",
8955  var->name)));
8956  }
8957  }
8958 }
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:4815
static struct config_generic ** guc_variables
Definition: guc.c:4812
#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 10233 of file guc.c.

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

Referenced by InitializeParallelDSM().

10234 {
10235  Size size;
10236  int i;
10237 
10238  /* Add space reqd for saving the data size of the guc state */
10239  size = sizeof(Size);
10240 
10241  /* Add up the space needed for each GUC variable */
10242  for (i = 0; i < num_guc_variables; i++)
10243  size = add_size(size,
10245 
10246  return size;
10247 }
static int num_guc_variables
Definition: guc.c:4815
static struct config_generic ** guc_variables
Definition: guc.c:4812
Size add_size(Size s1, Size s2)
Definition: shmem.c:498
size_t Size
Definition: c.h:473
static Size estimate_variable_size(struct config_generic *gconf)
Definition: guc.c:10135
int i

◆ ExecSetVariableStmt()

void ExecSetVariableStmt ( VariableSetStmt stmt,
bool  isTopLevel 
)

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

8348 {
8350 
8351  /*
8352  * Workers synchronize these parameters at the start of the parallel
8353  * operation; then, we block SET during the operation.
8354  */
8355  if (IsInParallelMode())
8356  ereport(ERROR,
8357  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
8358  errmsg("cannot set parameters during a parallel operation")));
8359 
8360  switch (stmt->kind)
8361  {
8362  case VAR_SET_VALUE:
8363  case VAR_SET_CURRENT:
8364  if (stmt->is_local)
8365  WarnNoTransactionBlock(isTopLevel, "SET LOCAL");
8366  (void) set_config_option(stmt->name,
8367  ExtractSetVariableArgs(stmt),
8369  PGC_S_SESSION,
8370  action, true, 0, false);
8371  break;
8372  case VAR_SET_MULTI:
8373 
8374  /*
8375  * Special-case SQL syntaxes. The TRANSACTION and SESSION
8376  * CHARACTERISTICS cases effectively set more than one variable
8377  * per statement. TRANSACTION SNAPSHOT only takes one argument,
8378  * but we put it here anyway since it's a special case and not
8379  * related to any GUC variable.
8380  */
8381  if (strcmp(stmt->name, "TRANSACTION") == 0)
8382  {
8383  ListCell *head;
8384 
8385  WarnNoTransactionBlock(isTopLevel, "SET TRANSACTION");
8386 
8387  foreach(head, stmt->args)
8388  {
8389  DefElem *item = (DefElem *) lfirst(head);
8390 
8391  if (strcmp(item->defname, "transaction_isolation") == 0)
8392  SetPGVariable("transaction_isolation",
8393  list_make1(item->arg), stmt->is_local);
8394  else if (strcmp(item->defname, "transaction_read_only") == 0)
8395  SetPGVariable("transaction_read_only",
8396  list_make1(item->arg), stmt->is_local);
8397  else if (strcmp(item->defname, "transaction_deferrable") == 0)
8398  SetPGVariable("transaction_deferrable",
8399  list_make1(item->arg), stmt->is_local);
8400  else
8401  elog(ERROR, "unexpected SET TRANSACTION element: %s",
8402  item->defname);
8403  }
8404  }
8405  else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
8406  {
8407  ListCell *head;
8408 
8409  foreach(head, stmt->args)
8410  {
8411  DefElem *item = (DefElem *) lfirst(head);
8412 
8413  if (strcmp(item->defname, "transaction_isolation") == 0)
8414  SetPGVariable("default_transaction_isolation",
8415  list_make1(item->arg), stmt->is_local);
8416  else if (strcmp(item->defname, "transaction_read_only") == 0)
8417  SetPGVariable("default_transaction_read_only",
8418  list_make1(item->arg), stmt->is_local);
8419  else if (strcmp(item->defname, "transaction_deferrable") == 0)
8420  SetPGVariable("default_transaction_deferrable",
8421  list_make1(item->arg), stmt->is_local);
8422  else
8423  elog(ERROR, "unexpected SET SESSION element: %s",
8424  item->defname);
8425  }
8426  }
8427  else if (strcmp(stmt->name, "TRANSACTION SNAPSHOT") == 0)
8428  {
8429  A_Const *con = linitial_node(A_Const, stmt->args);
8430 
8431  if (stmt->is_local)
8432  ereport(ERROR,
8433  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8434  errmsg("SET LOCAL TRANSACTION SNAPSHOT is not implemented")));
8435 
8436  WarnNoTransactionBlock(isTopLevel, "SET TRANSACTION");
8437  Assert(nodeTag(&con->val) == T_String);
8438  ImportSnapshot(strVal(&con->val));
8439  }
8440  else
8441  elog(ERROR, "unexpected SET MULTI element: %s",
8442  stmt->name);
8443  break;
8444  case VAR_SET_DEFAULT:
8445  if (stmt->is_local)
8446  WarnNoTransactionBlock(isTopLevel, "SET LOCAL");
8447  /* fall through */
8448  case VAR_RESET:
8449  if (strcmp(stmt->name, "transaction_isolation") == 0)
8450  WarnNoTransactionBlock(isTopLevel, "RESET TRANSACTION");
8451 
8452  (void) set_config_option(stmt->name,
8453  NULL,
8455  PGC_S_SESSION,
8456  action, true, 0, false);
8457  break;
8458  case VAR_RESET_ALL:
8459  ResetAllOptions();
8460  break;
8461  }
8462 }
void ImportSnapshot(const char *idstr)
Definition: snapmgr.c:1377
VariableSetKind kind
Definition: parsenodes.h:2044
void WarnNoTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3440
#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:177
GucAction
Definition: guc.h:191
#define list_make1(x1)
Definition: pg_list.h:206
bool IsInParallelMode(void)
Definition: xact.c:1012
#define ERROR
Definition: elog.h:43
Definition: guc.h:75
void ResetAllOptions(void)
Definition: guc.c:5741
Node * arg
Definition: parsenodes.h:734
#define ereport(elevel,...)
Definition: elog.h:144
#define Assert(condition)
Definition: c.h:745
#define lfirst(lc)
Definition: pg_list.h:169
#define nodeTag(nodeptr)
Definition: nodes.h:533
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214
char * defname
Definition: parsenodes.h:733
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
Definition: guc.c:8471
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:6949
void SetPGVariable(const char *name, List *args, bool is_local)
Definition: guc.c:8491

◆ ExtractSetVariableArgs()

char* ExtractSetVariableArgs ( VariableSetStmt stmt)

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

8472 {
8473  switch (stmt->kind)
8474  {
8475  case VAR_SET_VALUE:
8476  return flatten_set_variable_args(stmt->name, stmt->args);
8477  case VAR_SET_CURRENT:
8478  return GetConfigOptionByName(stmt->name, NULL, false);
8479  default:
8480  return NULL;
8481  }
8482 }
VariableSetKind kind
Definition: parsenodes.h:2044
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:9200
static char * flatten_set_variable_args(const char *name, List *args)
Definition: guc.c:7873

◆ FreeConfigVariables()

void FreeConfigVariables ( ConfigVariable list)

◆ GetConfigOption()

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

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

7739 {
7740  struct config_generic *record;
7741  static char buffer[256];
7742 
7743  record = find_option(name, false, ERROR);
7744  if (record == NULL)
7745  {
7746  if (missing_ok)
7747  return NULL;
7748  ereport(ERROR,
7749  (errcode(ERRCODE_UNDEFINED_OBJECT),
7750  errmsg("unrecognized configuration parameter \"%s\"",
7751  name)));
7752  }
7753  if (restrict_privileged &&
7754  (record->flags & GUC_SUPERUSER_ONLY) &&
7755  !is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
7756  ereport(ERROR,
7757  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7758  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
7759  name)));
7760 
7761  switch (record->vartype)
7762  {
7763  case PGC_BOOL:
7764  return *((struct config_bool *) record)->variable ? "on" : "off";
7765 
7766  case PGC_INT:
7767  snprintf(buffer, sizeof(buffer), "%d",
7768  *((struct config_int *) record)->variable);
7769  return buffer;
7770 
7771  case PGC_REAL:
7772  snprintf(buffer, sizeof(buffer), "%g",
7773  *((struct config_real *) record)->variable);
7774  return buffer;
7775 
7776  case PGC_STRING:
7777  return *((struct config_string *) record)->variable;
7778 
7779  case PGC_ENUM:
7780  return config_enum_lookup_by_value((struct config_enum *) record,
7781  *((struct config_enum *) record)->variable);
7782  }
7783  return NULL;
7784 }
Oid GetUserId(void)
Definition: miscinit.c:476
int errcode(int sqlerrcode)
Definition: elog.c:610
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:6645
#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:5249
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 9200 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().

9201 {
9202  struct config_generic *record;
9203 
9204  record = find_option(name, false, ERROR);
9205  if (record == NULL)
9206  {
9207  if (missing_ok)
9208  {
9209  if (varname)
9210  *varname = NULL;
9211  return NULL;
9212  }
9213 
9214  ereport(ERROR,
9215  (errcode(ERRCODE_UNDEFINED_OBJECT),
9216  errmsg("unrecognized configuration parameter \"%s\"", name)));
9217  }
9218 
9219  if ((record->flags & GUC_SUPERUSER_ONLY) &&
9220  !is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
9221  ereport(ERROR,
9222  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
9223  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
9224  name)));
9225 
9226  if (varname)
9227  *varname = record->name;
9228 
9229  return _ShowOption(record, true);
9230 }
static char * _ShowOption(struct config_generic *record, bool use_units)
Definition: guc.c:9760
Oid GetUserId(void)
Definition: miscinit.c:476
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:5249
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 9237 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().

9238 {
9239  char buffer[256];
9240  struct config_generic *conf;
9241 
9242  /* check requested variable number valid */
9243  Assert((varnum >= 0) && (varnum < num_guc_variables));
9244 
9245  conf = guc_variables[varnum];
9246 
9247  if (noshow)
9248  {
9249  if ((conf->flags & GUC_NO_SHOW_ALL) ||
9250  ((conf->flags & GUC_SUPERUSER_ONLY) &&
9251  !is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS)))
9252  *noshow = true;
9253  else
9254  *noshow = false;
9255  }
9256 
9257  /* first get the generic attributes */
9258 
9259  /* name */
9260  values[0] = conf->name;
9261 
9262  /* setting: use _ShowOption in order to avoid duplicating the logic */
9263  values[1] = _ShowOption(conf, false);
9264 
9265  /* unit, if any (NULL is fine) */
9266  values[2] = get_config_unit_name(conf->flags);
9267 
9268  /* group */
9269  values[3] = _(config_group_names[conf->group]);
9270 
9271  /* short_desc */
9272  values[4] = _(conf->short_desc);
9273 
9274  /* extra_desc */
9275  values[5] = _(conf->long_desc);
9276 
9277  /* context */
9278  values[6] = GucContext_Names[conf->context];
9279 
9280  /* vartype */
9281  values[7] = config_type_names[conf->vartype];
9282 
9283  /* source */
9284  values[8] = GucSource_Names[conf->source];
9285 
9286  /* now get the type specific attributes */
9287  switch (conf->vartype)
9288  {
9289  case PGC_BOOL:
9290  {
9291  struct config_bool *lconf = (struct config_bool *) conf;
9292 
9293  /* min_val */
9294  values[9] = NULL;
9295 
9296  /* max_val */
9297  values[10] = NULL;
9298 
9299  /* enumvals */
9300  values[11] = NULL;
9301 
9302  /* boot_val */
9303  values[12] = pstrdup(lconf->boot_val ? "on" : "off");
9304 
9305  /* reset_val */
9306  values[13] = pstrdup(lconf->reset_val ? "on" : "off");
9307  }
9308  break;
9309 
9310  case PGC_INT:
9311  {
9312  struct config_int *lconf = (struct config_int *) conf;
9313 
9314  /* min_val */
9315  snprintf(buffer, sizeof(buffer), "%d", lconf->min);
9316  values[9] = pstrdup(buffer);
9317 
9318  /* max_val */
9319  snprintf(buffer, sizeof(buffer), "%d", lconf->max);
9320  values[10] = pstrdup(buffer);
9321 
9322  /* enumvals */
9323  values[11] = NULL;
9324 
9325  /* boot_val */
9326  snprintf(buffer, sizeof(buffer), "%d", lconf->boot_val);
9327  values[12] = pstrdup(buffer);
9328 
9329  /* reset_val */
9330  snprintf(buffer, sizeof(buffer), "%d", lconf->reset_val);
9331  values[13] = pstrdup(buffer);
9332  }
9333  break;
9334 
9335  case PGC_REAL:
9336  {
9337  struct config_real *lconf = (struct config_real *) conf;
9338 
9339  /* min_val */
9340  snprintf(buffer, sizeof(buffer), "%g", lconf->min);
9341  values[9] = pstrdup(buffer);
9342 
9343  /* max_val */
9344  snprintf(buffer, sizeof(buffer), "%g", lconf->max);
9345  values[10] = pstrdup(buffer);
9346 
9347  /* enumvals */
9348  values[11] = NULL;
9349 
9350  /* boot_val */
9351  snprintf(buffer, sizeof(buffer), "%g", lconf->boot_val);
9352  values[12] = pstrdup(buffer);
9353 
9354  /* reset_val */
9355  snprintf(buffer, sizeof(buffer), "%g", lconf->reset_val);
9356  values[13] = pstrdup(buffer);
9357  }
9358  break;
9359 
9360  case PGC_STRING:
9361  {
9362  struct config_string *lconf = (struct config_string *) conf;
9363 
9364  /* min_val */
9365  values[9] = NULL;
9366 
9367  /* max_val */
9368  values[10] = NULL;
9369 
9370  /* enumvals */
9371  values[11] = NULL;
9372 
9373  /* boot_val */
9374  if (lconf->boot_val == NULL)
9375  values[12] = NULL;
9376  else
9377  values[12] = pstrdup(lconf->boot_val);
9378 
9379  /* reset_val */
9380  if (lconf->reset_val == NULL)
9381  values[13] = NULL;
9382  else
9383  values[13] = pstrdup(lconf->reset_val);
9384  }
9385  break;
9386 
9387  case PGC_ENUM:
9388  {
9389  struct config_enum *lconf = (struct config_enum *) conf;
9390 
9391  /* min_val */
9392  values[9] = NULL;
9393 
9394  /* max_val */
9395  values[10] = NULL;
9396 
9397  /* enumvals */
9398 
9399  /*
9400  * NOTE! enumvals with double quotes in them are not
9401  * supported!
9402  */
9403  values[11] = config_enum_get_options((struct config_enum *) conf,
9404  "{\"", "\"}", "\",\"");
9405 
9406  /* boot_val */
9408  lconf->boot_val));
9409 
9410  /* reset_val */
9412  lconf->reset_val));
9413  }
9414  break;
9415 
9416  default:
9417  {
9418  /*
9419  * should never get here, but in case we do, set 'em to NULL
9420  */
9421 
9422  /* min_val */
9423  values[9] = NULL;
9424 
9425  /* max_val */
9426  values[10] = NULL;
9427 
9428  /* enumvals */
9429  values[11] = NULL;
9430 
9431  /* boot_val */
9432  values[12] = NULL;
9433 
9434  /* reset_val */
9435  values[13] = NULL;
9436  }
9437  break;
9438  }
9439 
9440  /*
9441  * If the setting came from a config file, set the source location. For
9442  * security reasons, we don't show source file/line number for
9443  * insufficiently-privileged users.
9444  */
9445  if (conf->source == PGC_S_FILE &&
9446  is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
9447  {
9448  values[14] = conf->sourcefile;
9449  snprintf(buffer, sizeof(buffer), "%d", conf->sourceline);
9450  values[15] = pstrdup(buffer);
9451  }
9452  else
9453  {
9454  values[14] = NULL;
9455  values[15] = NULL;
9456  }
9457 
9458  values[16] = (conf->status & GUC_PENDING_RESTART) ? "t" : "f";
9459 }
GucSource source
Definition: guc_tables.h:158
static char * _ShowOption(struct config_generic *record, bool use_units)
Definition: guc.c:9760
const char * long_desc
Definition: guc_tables.h:153
double reset_val
Definition: guc_tables.h:222
Oid GetUserId(void)
Definition: miscinit.c:476
const char * name
Definition: guc_tables.h:149
const char *const config_type_names[]
Definition: guc.c:788
char * pstrdup(const char *in)
Definition: mcxt.c:1187
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:6645
#define GUC_NO_SHOW_ALL
Definition: guc.h:206
const char *const GucContext_Names[]
Definition: guc.c:629
const char *const config_group_names[]
Definition: guc.c:672
static int num_guc_variables
Definition: guc.c:4815
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:6436
static struct config_generic ** guc_variables
Definition: guc.c:4812
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:745
#define GUC_PENDING_RESTART
Definition: guc_tables.h:175
double min
Definition: guc_tables.h:216
static Datum values[MAXATTR]
Definition: bootstrap.c:165
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:648
#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:6694
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 7843 of file guc.c.

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

Referenced by pg_get_functiondef().

7844 {
7845  struct config_generic *record;
7846 
7847  record = find_option(name, false, WARNING);
7848  if (record == NULL)
7849  {
7850  if (missing_ok)
7851  return 0;
7852  ereport(ERROR,
7853  (errcode(ERRCODE_UNDEFINED_OBJECT),
7854  errmsg("unrecognized configuration parameter \"%s\"",
7855  name)));
7856  }
7857  return record->flags;
7858 }
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:5249
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 7794 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().

7795 {
7796  struct config_generic *record;
7797  static char buffer[256];
7798 
7799  record = find_option(name, false, ERROR);
7800  if (record == NULL)
7801  ereport(ERROR,
7802  (errcode(ERRCODE_UNDEFINED_OBJECT),
7803  errmsg("unrecognized configuration parameter \"%s\"", name)));
7804  if ((record->flags & GUC_SUPERUSER_ONLY) &&
7805  !is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
7806  ereport(ERROR,
7807  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7808  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
7809  name)));
7810 
7811  switch (record->vartype)
7812  {
7813  case PGC_BOOL:
7814  return ((struct config_bool *) record)->reset_val ? "on" : "off";
7815 
7816  case PGC_INT:
7817  snprintf(buffer, sizeof(buffer), "%d",
7818  ((struct config_int *) record)->reset_val);
7819  return buffer;
7820 
7821  case PGC_REAL:
7822  snprintf(buffer, sizeof(buffer), "%g",
7823  ((struct config_real *) record)->reset_val);
7824  return buffer;
7825 
7826  case PGC_STRING:
7827  return ((struct config_string *) record)->reset_val;
7828 
7829  case PGC_ENUM:
7830  return config_enum_lookup_by_value((struct config_enum *) record,
7831  ((struct config_enum *) record)->reset_val);
7832  }
7833  return NULL;
7834 }
Oid GetUserId(void)
Definition: miscinit.c:476
int errcode(int sqlerrcode)
Definition: elog.c:610
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:6645
#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:5249
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 9465 of file guc.c.

References num_guc_variables.

Referenced by GucInfoMain(), and show_all_settings().

9466 {
9467  return num_guc_variables;
9468 }
static int num_guc_variables
Definition: guc.c:4815

◆ GetPGVariable()

void GetPGVariable ( const char *  name,
DestReceiver dest 
)

Definition at line 8965 of file guc.c.

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

Referenced by exec_replication_command(), and standard_ProcessUtility().

8966 {
8967  if (guc_name_compare(name, "all") == 0)
8968  ShowAllGUCConfig(dest);
8969  else
8970  ShowGUCConfigOption(name, dest);
8971 }
static void ShowGUCConfigOption(const char *name, DestReceiver *dest)
Definition: guc.c:9009
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:5310
static void ShowAllGUCConfig(DestReceiver *dest)
Definition: guc.c:9037
const char * name
Definition: encode.c:561

◆ GetPGVariableResultDesc()

TupleDesc GetPGVariableResultDesc ( const char *  name)

Definition at line 8974 of file guc.c.

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

Referenced by UtilityTupleDescriptor().

8975 {
8976  TupleDesc tupdesc;
8977 
8978  if (guc_name_compare(name, "all") == 0)
8979  {
8980  /* need a tuple descriptor representing three TEXT columns */
8981  tupdesc = CreateTemplateTupleDesc(3);
8982  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
8983  TEXTOID, -1, 0);
8984  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
8985  TEXTOID, -1, 0);
8986  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
8987  TEXTOID, -1, 0);
8988  }
8989  else
8990  {
8991  const char *varname;
8992 
8993  /* Get the canonical spelling of name */
8994  (void) GetConfigOptionByName(name, &varname, false);
8995 
8996  /* need a tuple descriptor representing a single TEXT column */
8997  tupdesc = CreateTemplateTupleDesc(1);
8998  TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
8999  TEXTOID, -1, 0);
9000  }
9001  return tupdesc;
9002 }
TupleDesc CreateTemplateTupleDesc(int natts)
Definition: tupdesc.c:44
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:5310
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:9200
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 10625 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().

10626 {
10627  struct config_generic *record;
10628  Datum datum;
10629  char *newval;
10630  ArrayType *a;
10631 
10632  Assert(name);
10633  Assert(value);
10634 
10635  /* test if the option is valid and we're allowed to set it */
10636  (void) validate_option_array_item(name, value, false);
10637 
10638  /* normalize name (converts obsolete GUC names to modern spellings) */
10639  record = find_option(name, false, WARNING);
10640  if (record)
10641  name = record->name;
10642 
10643  /* build new item for array */
10644  newval = psprintf("%s=%s", name, value);
10645  datum = CStringGetTextDatum(newval);
10646 
10647  if (array)
10648  {
10649  int index;
10650  bool isnull;
10651  int i;
10652 
10653  Assert(ARR_ELEMTYPE(array) == TEXTOID);
10654  Assert(ARR_NDIM(array) == 1);
10655  Assert(ARR_LBOUND(array)[0] == 1);
10656 
10657  index = ARR_DIMS(array)[0] + 1; /* add after end */
10658 
10659  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
10660  {
10661  Datum d;
10662  char *current;
10663 
10664  d = array_ref(array, 1, &i,
10665  -1 /* varlenarray */ ,
10666  -1 /* TEXT's typlen */ ,
10667  false /* TEXT's typbyval */ ,
10668  TYPALIGN_INT /* TEXT's typalign */ ,
10669  &isnull);
10670  if (isnull)
10671  continue;
10672  current = TextDatumGetCString(d);
10673 
10674  /* check for match up through and including '=' */
10675  if (strncmp(current, newval, strlen(name) + 1) == 0)
10676  {
10677  index = i;
10678  break;
10679  }
10680  }
10681 
10682  a = array_set(array, 1, &index,
10683  datum,
10684  false,
10685  -1 /* varlena array */ ,
10686  -1 /* TEXT's typlen */ ,
10687  false /* TEXT's typbyval */ ,
10688  TYPALIGN_INT /* TEXT's typalign */ );
10689  }
10690  else
10691  a = construct_array(&datum, 1,
10692  TEXTOID,
10693  -1, false, TYPALIGN_INT);
10694 
10695  return a;
10696 }
static struct @142 value
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:3313
ArrayType * array_set(ArrayType *array, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3115
#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:10851
#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:3098
#define WARNING
Definition: elog.h:40
#define TextDatumGetCString(d)
Definition: builtins.h:87
uintptr_t Datum
Definition: postgres.h:367
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:5249
#define Assert(condition)
Definition: c.h:745
#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:86
#define ARR_ELEMTYPE(a)
Definition: array.h:280

◆ GUCArrayDelete()

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

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

10706 {
10707  struct config_generic *record;
10708  ArrayType *newarray;
10709  int i;
10710  int index;
10711 
10712  Assert(name);
10713 
10714  /* test if the option is valid and we're allowed to set it */
10715  (void) validate_option_array_item(name, NULL, false);
10716 
10717  /* normalize name (converts obsolete GUC names to modern spellings) */
10718  record = find_option(name, false, WARNING);
10719  if (record)
10720  name = record->name;
10721 
10722  /* if array is currently null, then surely nothing to delete */
10723  if (!array)
10724  return NULL;
10725 
10726  newarray = NULL;
10727  index = 1;
10728 
10729  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
10730  {
10731  Datum d;
10732  char *val;
10733  bool isnull;
10734 
10735  d = array_ref(array, 1, &i,
10736  -1 /* varlenarray */ ,
10737  -1 /* TEXT's typlen */ ,
10738  false /* TEXT's typbyval */ ,
10739  TYPALIGN_INT /* TEXT's typalign */ ,
10740  &isnull);
10741  if (isnull)
10742  continue;
10743  val = TextDatumGetCString(d);
10744 
10745  /* ignore entry if it's what we want to delete */
10746  if (strncmp(val, name, strlen(name)) == 0
10747  && val[strlen(name)] == '=')
10748  continue;
10749 
10750  /* else add it to the output array */
10751  if (newarray)
10752  newarray = array_set(newarray, 1, &index,
10753  d,
10754  false,
10755  -1 /* varlenarray */ ,
10756  -1 /* TEXT's typlen */ ,
10757  false /* TEXT's typbyval */ ,
10758  TYPALIGN_INT /* TEXT's typalign */ );
10759  else
10760  newarray = construct_array(&d, 1,
10761  TEXTOID,
10762  -1, false, TYPALIGN_INT);
10763 
10764  index++;
10765  }
10766 
10767  return newarray;
10768 }
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:3313
ArrayType * array_set(ArrayType *array, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3115
Definition: type.h:89
static bool validate_option_array_item(const char *name, const char *value, bool skipIfNoPermissions)
Definition: guc.c:10851
#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:3098
#define WARNING
Definition: elog.h:40
#define TextDatumGetCString(d)
Definition: builtins.h:87
uintptr_t Datum
Definition: postgres.h:367
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:5249
#define Assert(condition)
Definition: c.h:745
const char * name
Definition: encode.c:561
int i
long val
Definition: informix.c:664

◆ GUCArrayReset()

ArrayType* GUCArrayReset ( ArrayType array)

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

10778 {
10779  ArrayType *newarray;
10780  int i;
10781  int index;
10782 
10783  /* if array is currently null, nothing to do */
10784  if (!array)
10785  return NULL;
10786 
10787  /* if we're superuser, we can delete everything, so just do it */
10788  if (superuser())
10789  return NULL;
10790 
10791  newarray = NULL;
10792  index = 1;
10793 
10794  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
10795  {
10796  Datum d;
10797  char *val;
10798  char *eqsgn;
10799  bool isnull;
10800 
10801  d = array_ref(array, 1, &i,
10802  -1 /* varlenarray */ ,
10803  -1 /* TEXT's typlen */ ,
10804  false /* TEXT's typbyval */ ,
10805  TYPALIGN_INT /* TEXT's typalign */ ,
10806  &isnull);
10807  if (isnull)
10808  continue;
10809  val = TextDatumGetCString(d);
10810 
10811  eqsgn = strchr(val, '=');
10812  *eqsgn = '\0';
10813 
10814  /* skip if we have permission to delete it */
10815  if (validate_option_array_item(val, NULL, true))
10816  continue;
10817 
10818  /* else add it to the output array */
10819  if (newarray)
10820  newarray = array_set(newarray, 1, &index,
10821  d,
10822  false,
10823  -1 /* varlenarray */ ,
10824  -1 /* TEXT's typlen */ ,
10825  false /* TEXT's typbyval */ ,
10826  TYPALIGN_INT /* TEXT's typalign */ );
10827  else
10828  newarray = construct_array(&d, 1,
10829  TEXTOID,
10830  -1, false, TYPALIGN_INT);
10831 
10832  index++;
10833  pfree(val);
10834  }
10835 
10836  return newarray;
10837 }
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3313
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:3115
Definition: type.h:89
void pfree(void *pointer)
Definition: mcxt.c:1057
static bool validate_option_array_item(const char *name, const char *value, bool skipIfNoPermissions)
Definition: guc.c:10851
#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:3098
#define TextDatumGetCString(d)
Definition: builtins.h:87
uintptr_t Datum
Definition: postgres.h:367
int i
long val
Definition: informix.c:664

◆ InitializeGUCOptions()

void InitializeGUCOptions ( void  )

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

5345 {
5346  int i;
5347 
5348  /*
5349  * Before log_line_prefix could possibly receive a nonempty setting, make
5350  * sure that timezone processing is minimally alive (see elog.c).
5351  */
5353 
5354  /*
5355  * Build sorted array of all GUC variables.
5356  */
5358 
5359  /*
5360  * Load all variables with their compiled-in defaults, and initialize
5361  * status fields as needed.
5362  */
5363  for (i = 0; i < num_guc_variables; i++)
5364  {
5366  }
5367 
5368  guc_dirty = false;
5369 
5370  reporting_enabled = false;
5371 
5372  /*
5373  * Prevent any attempt to override the transaction modes from
5374  * non-interactive sources.
5375  */
5376  SetConfigOption("transaction_isolation", "read committed",
5378  SetConfigOption("transaction_read_only", "no",
5380  SetConfigOption("transaction_deferrable", "no",
5382 
5383  /*
5384  * For historical reasons, some GUC parameters can receive defaults from
5385  * environment variables. Process those settings.
5386  */
5388 }
void build_guc_variables(void)
Definition: guc.c:5076
static void InitializeGUCOptionsFromEnvironment(void)
Definition: guc.c:5400
void pg_timezone_initialize(void)
Definition: pgtz.c:363
static int num_guc_variables
Definition: guc.c:4815
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:7714
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:5446
static struct config_generic ** guc_variables
Definition: guc.c:4812
int i
static bool reporting_enabled
Definition: guc.c:4823
static bool guc_dirty
Definition: guc.c:4821

◆ NewGUCNestLevel()

◆ parse_int()

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

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

6494 {
6495  /*
6496  * We assume here that double is wide enough to represent any integer
6497  * value with adequate precision.
6498  */
6499  double val;
6500  char *endptr;
6501 
6502  /* To suppress compiler warnings, always set output params */
6503  if (result)
6504  *result = 0;
6505  if (hintmsg)
6506  *hintmsg = NULL;
6507 
6508  /*
6509  * Try to parse as an integer (allowing octal or hex input). If the
6510  * conversion stops at a decimal point or 'e', or overflows, re-parse as
6511  * float. This should work fine as long as we have no unit names starting
6512  * with 'e'. If we ever do, the test could be extended to check for a
6513  * sign or digit after 'e', but for now that's unnecessary.
6514  */
6515  errno = 0;
6516  val = strtol(value, &endptr, 0);
6517  if (*endptr == '.' || *endptr == 'e' || *endptr == 'E' ||
6518  errno == ERANGE)
6519  {
6520  errno = 0;
6521  val = strtod(value, &endptr);
6522  }
6523 
6524  if (endptr == value || errno == ERANGE)
6525  return false; /* no HINT for these cases */
6526 
6527  /* reject NaN (infinities will fail range check below) */
6528  if (isnan(val))
6529  return false; /* treat same as syntax error; no HINT */
6530 
6531  /* allow whitespace between number and unit */
6532  while (isspace((unsigned char) *endptr))
6533  endptr++;
6534 
6535  /* Handle possible unit */
6536  if (*endptr != '\0')
6537  {
6538  if ((flags & GUC_UNIT) == 0)
6539  return false; /* this setting does not accept a unit */
6540 
6541  if (!convert_to_base_unit(val,
6542  endptr, (flags & GUC_UNIT),
6543  &val))
6544  {
6545  /* invalid unit, or garbage after the unit; set hint and fail. */
6546  if (hintmsg)
6547  {
6548  if (flags & GUC_UNIT_MEMORY)
6549  *hintmsg = memory_units_hint;
6550  else
6551  *hintmsg = time_units_hint;
6552  }
6553  return false;
6554  }
6555  }
6556 
6557  /* Round to int, then check for overflow */
6558  val = rint(val);
6559 
6560  if (val > INT_MAX || val < INT_MIN)
6561  {
6562  if (hintmsg)
6563  *hintmsg = gettext_noop("Value exceeds integer range.");
6564  return false;
6565  }
6566 
6567  if (result)
6568  *result = (int) val;
6569  return true;
6570 }
static struct @142 value
#define gettext_noop(x)
Definition: c.h:1137
#define GUC_UNIT
Definition: guc.h:232
static const char * time_units_hint
Definition: guc.c:870
static bool convert_to_base_unit(double value, const char *unit, int base_unit, double *base_value)
Definition: guc.c:6293
long val
Definition: informix.c:664
static const char * memory_units_hint
Definition: guc.c:833
#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 6583 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().

6584 {
6585  double val;
6586  char *endptr;
6587 
6588  /* To suppress compiler warnings, always set output params */
6589  if (result)
6590  *result = 0;
6591  if (hintmsg)
6592  *hintmsg = NULL;
6593 
6594  errno = 0;
6595  val = strtod(value, &endptr);
6596 
6597  if (endptr == value || errno == ERANGE)
6598  return false; /* no HINT for these cases */
6599 
6600  /* reject NaN (infinities will fail range checks later) */
6601  if (isnan(val))
6602  return false; /* treat same as syntax error; no HINT */
6603 
6604  /* allow whitespace between number and unit */
6605  while (isspace((unsigned char) *endptr))
6606  endptr++;
6607 
6608  /* Handle possible unit */
6609  if (*endptr != '\0')
6610  {
6611  if ((flags & GUC_UNIT) == 0)
6612  return false; /* this setting does not accept a unit */
6613 
6614  if (!convert_to_base_unit(val,
6615  endptr, (flags & GUC_UNIT),
6616  &val))
6617  {
6618  /* invalid unit, or garbage after the unit; set hint and fail. */
6619  if (hintmsg)
6620  {
6621  if (flags & GUC_UNIT_MEMORY)
6622  *hintmsg = memory_units_hint;
6623  else
6624  *hintmsg = time_units_hint;
6625  }
6626  return false;
6627  }
6628  }
6629 
6630  if (result)
6631  *result = val;
6632  return true;
6633 }
static struct @142 value
#define GUC_UNIT
Definition: guc.h:232
static const char * time_units_hint
Definition: guc.c:870
static bool convert_to_base_unit(double value, const char *unit, int base_unit, double *base_value)
Definition: guc.c:6293
long val
Definition: informix.c:664
static const char * memory_units_hint
Definition: guc.c:833
#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 10529 of file guc.c.

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

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

10530 {
10531  size_t equal_pos;
10532  char *cp;
10533 
10534  AssertArg(string);
10535  AssertArg(name);
10536  AssertArg(value);
10537 
10538  equal_pos = strcspn(string, "=");
10539 
10540  if (string[equal_pos] == '=')
10541  {
10542  *name = guc_malloc(FATAL, equal_pos + 1);
10543  strlcpy(*name, string, equal_pos + 1);
10544 
10545  *value = guc_strdup(FATAL, &string[equal_pos + 1]);
10546  }
10547  else
10548  {
10549  /* no equal sign in string */
10550  *name = guc_strdup(FATAL, string);
10551  *value = NULL;
10552  }
10553 
10554  for (cp = *name; *cp; cp++)
10555  if (*cp == '-')
10556  *cp = '_';
10557 }
static struct @142 value
static char * guc_strdup(int elevel, const char *src)
Definition: guc.c:4885
#define FATAL
Definition: elog.h:52
#define AssertArg(condition)
Definition: c.h:747
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:4853

◆ ProcessConfigFile()

◆ ProcessGUCArray()

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

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

10569 {
10570  int i;
10571 
10572  Assert(array != NULL);
10573  Assert(ARR_ELEMTYPE(array) == TEXTOID);
10574  Assert(ARR_NDIM(array) == 1);
10575  Assert(ARR_LBOUND(array)[0] == 1);
10576 
10577  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
10578  {
10579  Datum d;
10580  bool isnull;
10581  char *s;
10582  char *name;
10583  char *value;
10584 
10585  d = array_ref(array, 1, &i,
10586  -1 /* varlenarray */ ,
10587  -1 /* TEXT's typlen */ ,
10588  false /* TEXT's typbyval */ ,
10589  TYPALIGN_INT /* TEXT's typalign */ ,
10590  &isnull);
10591 
10592  if (isnull)
10593  continue;
10594 
10595  s = TextDatumGetCString(d);
10596 
10597  ParseLongOption(s, &name, &value);
10598  if (!value)
10599  {
10600  ereport(WARNING,
10601  (errcode(ERRCODE_SYNTAX_ERROR),
10602  errmsg("could not parse setting for parameter \"%s\"",
10603  name)));
10604  free(name);
10605  continue;
10606  }
10607 
10608  (void) set_config_option(name, value,
10609  context, source,
10610  action, true, 0, false);
10611 
10612  free(name);
10613  if (value)
10614  free(value);
10615  pfree(s);
10616  }
10617 }
GucSource source
Definition: guc_tables.h:158
static struct @142 value
void ParseLongOption(const char *string, char **name, char **value)
Definition: guc.c:10529
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ARR_LBOUND(a)
Definition: array.h:284
void pfree(void *pointer)
Definition: mcxt.c:1057
#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:3098
#define WARNING
Definition: elog.h:40
#define TextDatumGetCString(d)
Definition: builtins.h:87
uintptr_t Datum
Definition: postgres.h:367
#define ereport(elevel,...)
Definition: elog.h:144
#define free(a)
Definition: header.h:65
#define Assert(condition)
Definition: c.h:745
#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:6949
#define ARR_ELEMTYPE(a)
Definition: array.h:280
GucContext context
Definition: guc_tables.h:150

◆ ResetAllOptions()

void ResetAllOptions ( void  )

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

5742 {
5743  int i;
5744 
5745  for (i = 0; i < num_guc_variables; i++)
5746  {
5747  struct config_generic *gconf = guc_variables[i];
5748 
5749  /* Don't reset non-SET-able values */
5750  if (gconf->context != PGC_SUSET &&
5751  gconf->context != PGC_USERSET)
5752  continue;
5753  /* Don't reset if special exclusion from RESET ALL */
5754  if (gconf->flags & GUC_NO_RESET_ALL)
5755  continue;
5756  /* No need to reset if wasn't SET */
5757  if (gconf->source <= PGC_S_OVERRIDE)
5758  continue;
5759 
5760  /* Save old value to support transaction abort */
5762 
5763  switch (gconf->vartype)
5764  {
5765  case PGC_BOOL:
5766  {
5767  struct config_bool *conf = (struct config_bool *) gconf;
5768 
5769  if (conf->assign_hook)
5770  conf->assign_hook(conf->reset_val,
5771  conf->reset_extra);
5772  *conf->variable = conf->reset_val;
5773  set_extra_field(&conf->gen, &conf->gen.extra,
5774  conf->reset_extra);
5775  break;
5776  }
5777  case PGC_INT:
5778  {
5779  struct config_int *conf = (struct config_int *) gconf;
5780 
5781  if (conf->assign_hook)
5782  conf->assign_hook(conf->reset_val,
5783  conf->reset_extra);
5784  *conf->variable = conf->reset_val;
5785  set_extra_field(&conf->gen, &conf->gen.extra,
5786  conf->reset_extra);
5787  break;
5788  }
5789  case PGC_REAL:
5790  {
5791  struct config_real *conf = (struct config_real *) gconf;
5792 
5793  if (conf->assign_hook)
5794  conf->assign_hook(conf->reset_val,
5795  conf->reset_extra);
5796  *conf->variable = conf->reset_val;
5797  set_extra_field(&conf->gen, &conf->gen.extra,
5798  conf->reset_extra);
5799  break;
5800  }
5801  case PGC_STRING:
5802  {
5803  struct config_string *conf = (struct config_string *) gconf;
5804 
5805  if (conf->assign_hook)
5806  conf->assign_hook(conf->reset_val,
5807  conf->reset_extra);
5808  set_string_field(conf, conf->variable, conf->reset_val);
5809  set_extra_field(&conf->gen, &conf->gen.extra,
5810  conf->reset_extra);
5811  break;
5812  }
5813  case PGC_ENUM:
5814  {
5815  struct config_enum *conf = (struct config_enum *) gconf;
5816 
5817  if (conf->assign_hook)
5818  conf->assign_hook(conf->reset_val,
5819  conf->reset_extra);
5820  *conf->variable = conf->reset_val;
5821  set_extra_field(&conf->gen, &conf->gen.extra,
5822  conf->reset_extra);
5823  break;
5824  }
5825  }
5826 
5827  gconf->source = gconf->reset_source;
5828  gconf->scontext = gconf->reset_scontext;
5829 
5830  if (gconf->flags & GUC_REPORT)
5831  ReportGUCOption(gconf);
5832  }
5833 }
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:5841
int * variable
Definition: guc_tables.h:198
int * variable
Definition: guc_tables.h:244
static int num_guc_variables
Definition: guc.c:4815
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:4986
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:4925
static struct config_generic ** guc_variables
Definition: guc.c:4812
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:6266
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 10455 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().

10456 {
10457  char *varname,
10458  *varvalue,
10459  *varsourcefile;
10460  int varsourceline;
10461  GucSource varsource;
10462  GucContext varscontext;
10463  char *srcptr = (char *) gucstate;
10464  char *srcend;
10465  Size len;
10466  int i;
10467  ErrorContextCallback error_context_callback;
10468 
10469  /* See comment at can_skip_gucvar(). */
10470  for (i = 0; i < num_guc_variables; i++)
10471  if (!can_skip_gucvar(guc_variables[i]))
10473 
10474  /* First item is the length of the subsequent data */
10475  memcpy(&len, gucstate, sizeof(len));
10476 
10477  srcptr += sizeof(len);
10478  srcend = srcptr + len;
10479 
10480  /* If the GUC value check fails, we want errors to show useful context. */
10481  error_context_callback.callback = guc_restore_error_context_callback;
10482  error_context_callback.previous = error_context_stack;
10483  error_context_callback.arg = NULL;
10484  error_context_stack = &error_context_callback;
10485 
10486  while (srcptr < srcend)
10487  {
10488  int result;
10489  char *error_context_name_and_value[2];
10490 
10491  varname = read_gucstate(&srcptr, srcend);
10492  varvalue = read_gucstate(&srcptr, srcend);
10493  varsourcefile = read_gucstate(&srcptr, srcend);
10494  if (varsourcefile[0])
10495  read_gucstate_binary(&srcptr, srcend,
10496  &varsourceline, sizeof(varsourceline));
10497  else
10498  varsourceline = 0;
10499  read_gucstate_binary(&srcptr, srcend,
10500  &varsource, sizeof(varsource));
10501  read_gucstate_binary(&srcptr, srcend,
10502  &varscontext, sizeof(varscontext));
10503 
10504  error_context_name_and_value[0] = varname;
10505  error_context_name_and_value[1] = varvalue;
10506  error_context_callback.arg = &error_context_name_and_value[0];
10507  result = set_config_option(varname, varvalue, varscontext, varsource,
10508  GUC_ACTION_SET, true, ERROR, true);
10509  if (result <= 0)
10510  ereport(ERROR,
10511  (errcode(ERRCODE_INTERNAL_ERROR),
10512  errmsg("parameter \"%s\" could not be set", varname)));
10513  if (varsourcefile[0])
10514  set_config_sourcefile(varname, varsourcefile, varsourceline);
10515  error_context_callback.arg = NULL;
10516  }
10517 
10518  error_context_stack = error_context_callback.previous;
10519 }
GucContext
Definition: guc.h:68
static void static void set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
Definition: guc.c:7680
static void read_gucstate_binary(char **srcptr, char *srcend, void *dest, Size size)
Definition: guc.c:10425
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:4815
static bool can_skip_gucvar(struct config_generic *gconf)
Definition: guc.c:10121
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:5446
static void guc_restore_error_context_callback(void *arg)
Definition: guc.c:10439
static struct config_generic ** guc_variables
Definition: guc.c:4812
static char * read_gucstate(char **srcptr, char *srcend)
Definition: guc.c:10402
#define ereport(elevel,...)
Definition: elog.h:144
size_t Size
Definition: c.h:473
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:6949

◆ SelectConfigFiles()

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

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

5567 {
5568  char *configdir;
5569  char *fname;
5570  struct stat stat_buf;
5571 
5572  /* configdir is -D option, or $PGDATA if no -D */
5573  if (userDoption)
5574  configdir = make_absolute_path(userDoption);
5575  else
5576  configdir = make_absolute_path(getenv("PGDATA"));
5577 
5578  if (configdir && stat(configdir, &stat_buf) != 0)
5579  {
5580  write_stderr("%s: could not access directory \"%s\": %s\n",
5581  progname,
5582  configdir,
5583  strerror(errno));
5584  if (errno == ENOENT)
5585  write_stderr("Run initdb or pg_basebackup to initialize a PostgreSQL data directory.\n");
5586  return false;
5587  }
5588 
5589  /*
5590  * Find the configuration file: if config_file was specified on the
5591  * command line, use it, else use configdir/postgresql.conf. In any case
5592  * ensure the result is an absolute path, so that it will be interpreted
5593  * the same way by future backends.
5594  */
5595  if (ConfigFileName)
5597  else if (configdir)
5598  {
5599  fname = guc_malloc(FATAL,
5600  strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
5601  sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
5602  }
5603  else
5604  {
5605  write_stderr("%s does not know where to find the server configuration file.\n"
5606  "You must specify the --config-file or -D invocation "
5607  "option or set the PGDATA environment variable.\n",
5608  progname);
5609  return false;
5610  }
5611 
5612  /*
5613  * Set the ConfigFileName GUC variable to its final value, ensuring that
5614  * it can't be overridden later.
5615  */
5616  SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
5617  free(fname);
5618 
5619  /*
5620  * Now read the config file for the first time.
5621  */
5622  if (stat(ConfigFileName, &stat_buf) != 0)
5623  {
5624  write_stderr("%s: could not access the server configuration file \"%s\": %s\n",
5625  progname, ConfigFileName, strerror(errno));
5626  free(configdir);
5627  return false;
5628  }
5629 
5630  /*
5631  * Read the configuration file for the first time. This time only the
5632  * data_directory parameter is picked up to determine the data directory,
5633  * so that we can read the PG_AUTOCONF_FILENAME file next time.
5634  */
5636 
5637  /*
5638  * If the data_directory GUC variable has been set, use that as DataDir;
5639  * otherwise use configdir if set; else punt.
5640  *
5641  * Note: SetDataDir will copy and absolute-ize its argument, so we don't
5642  * have to.
5643  */
5644  if (data_directory)
5646  else if (configdir)
5647  SetDataDir(configdir);
5648  else
5649  {
5650  write_stderr("%s does not know where to find the database system data.\n"
5651  "This can be specified as \"data_directory\" in \"%s\", "
5652  "or by the -D invocation option, or by the "
5653  "PGDATA environment variable.\n",
5655  return false;
5656  }
5657 
5658  /*
5659  * Reflect the final DataDir value back into the data_directory GUC var.
5660  * (If you are wondering why we don't just make them a single variable,
5661  * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
5662  * child backends specially. XXX is that still true? Given that we now
5663  * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
5664  * DataDir in advance.)
5665  */
5667 
5668  /*
5669  * Now read the config file a second time, allowing any settings in the
5670  * PG_AUTOCONF_FILENAME file to take effect. (This is pretty ugly, but
5671  * since we have to determine the DataDir before we can find the autoconf
5672  * file, the alternatives seem worse.)
5673  */
5675 
5676  /*
5677  * If timezone_abbreviations wasn't set in the configuration file, install
5678  * the default value. We do it this way because we can't safely install a
5679  * "real" value until my_exec_path is set, which may not have happened
5680  * when InitializeGUCOptions runs, so the bootstrap default value cannot
5681  * be the real desired default.
5682  */
5684 
5685  /*
5686  * Figure out where pg_hba.conf is, and make sure the path is absolute.
5687  */
5688  if (HbaFileName)
5690  else if (configdir)
5691  {
5692  fname = guc_malloc(FATAL,
5693  strlen(configdir) + strlen(HBA_FILENAME) + 2);
5694  sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
5695  }
5696  else
5697  {
5698  write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
5699  "This can be specified as \"hba_file\" in \"%s\", "
5700  "or by the -D invocation option, or by the "
5701  "PGDATA environment variable.\n",
5703  return false;
5704  }
5705  SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
5706  free(fname);
5707 
5708  /*
5709  * Likewise for pg_ident.conf.
5710  */
5711  if (IdentFileName)
5713  else if (configdir)
5714  {
5715  fname = guc_malloc(FATAL,
5716  strlen(configdir) + strlen(IDENT_FILENAME) + 2);
5717  sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
5718  }
5719  else
5720  {
5721  write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
5722  "This can be specified as \"ident_file\" in \"%s\", "
5723  "or by the -D invocation option, or by the "
5724  "PGDATA environment variable.\n",
5726  return false;
5727  }
5728  SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
5729  free(fname);
5730 
5731  free(configdir);
5732 
5733  return true;
5734 }
char * make_absolute_path(const char *path)
Definition: path.c:608
void ProcessConfigFile(GucContext context)
void SetDataDir(const char *dir)
Definition: miscinit.c:395
char * ConfigFileName
Definition: guc.c:556
static void pg_timezone_abbrev_initialize(void)
Definition: guc.c:11419
#define CONFIG_FILENAME
Definition: guc.c:109
#define write_stderr(str)
Definition: parallel.c:186
const char * progname
Definition: pg_standby.c:36
char * HbaFileName
Definition: guc.c:557
#define sprintf
Definition: port.h:195
#define HBA_FILENAME
Definition: guc.c:110
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:7714
char * IdentFileName
Definition: guc.c:558
#define stat(a, b)
Definition: win32_port.h:255
#define IDENT_FILENAME
Definition: guc.c:111
#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:4853
static char * data_directory
Definition: guc.c:602

◆ SerializeGUCState()

void SerializeGUCState ( Size  maxsize,
char *  start_address 
)

Definition at line 10375 of file guc.c.

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

Referenced by InitializeParallelDSM().

10376 {
10377  char *curptr;
10378  Size actual_size;
10379  Size bytes_left;
10380  int i;
10381 
10382  /* Reserve space for saving the actual size of the guc state */
10383  Assert(maxsize > sizeof(actual_size));
10384  curptr = start_address + sizeof(actual_size);
10385  bytes_left = maxsize - sizeof(actual_size);
10386 
10387  for (i = 0; i < num_guc_variables; i++)
10388  serialize_variable(&curptr, &bytes_left, guc_variables[i]);
10389 
10390  /* Store actual size without assuming alignment of start_address. */
10391  actual_size = maxsize - bytes_left - sizeof(actual_size);
10392  memcpy(start_address, &actual_size, sizeof(actual_size));
10393 }
static void serialize_variable(char **destptr, Size *maxbytes, struct config_generic *gconf)
Definition: guc.c:10301
static int num_guc_variables
Definition: guc.c:4815
static struct config_generic ** guc_variables
Definition: guc.c:4812
#define Assert(condition)
Definition: c.h:745
size_t Size
Definition: c.h:473
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 6949 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().

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