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

Go to the source code of this file.

Data Structures

struct  ConfigVariable
 
struct  config_enum_entry
 

Macros

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

Typedefs

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

Enumerations

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

Functions

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

Variables

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

Macro Definition Documentation

◆ GUC_check_errdetail

◆ GUC_check_errhint

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

Definition at line 413 of file guc.h.

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

◆ GUC_check_errmsg

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

Definition at line 405 of file guc.h.

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

◆ GUC_CUSTOM_PLACEHOLDER

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

◆ GUC_DISALLOW_IN_AUTO_FILE

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

Definition at line 215 of file guc.h.

Referenced by AlterSystemSetConfigFile().

◆ GUC_DISALLOW_IN_FILE

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

Definition at line 210 of file guc.h.

Referenced by AlterSystemSetConfigFile(), and displayStruct().

◆ GUC_IS_NAME

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

Definition at line 213 of file guc.h.

Referenced by parse_and_validate_value().

◆ GUC_LIST_INPUT

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

Definition at line 204 of file guc.h.

Referenced by _PG_init(), and flatten_set_variable_args().

◆ GUC_LIST_QUOTE

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

Definition at line 205 of file guc.h.

Referenced by flatten_set_variable_args().

◆ GUC_NO_RESET_ALL

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

Definition at line 207 of file guc.h.

Referenced by ResetAllOptions().

◆ GUC_NO_SHOW_ALL

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

◆ GUC_NOT_IN_SAMPLE

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

Definition at line 209 of file guc.h.

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

◆ GUC_NOT_WHILE_SEC_REST

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

Definition at line 214 of file guc.h.

Referenced by set_config_option().

◆ GUC_QUALIFIER_SEPARATOR

#define GUC_QUALIFIER_SEPARATOR   '.'

Definition at line 199 of file guc.h.

Referenced by EmitWarningsOnPlaceholders(), and find_option().

◆ GUC_REPORT

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

◆ GUC_SUPERUSER_ONLY

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

◆ GUC_UNIT

#define GUC_UNIT   (GUC_UNIT_MEMORY | GUC_UNIT_TIME)

Definition at line 230 of file guc.h.

Referenced by _ShowOption(), and parse_int().

◆ GUC_UNIT_BLOCKS

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

Definition at line 219 of file guc.h.

Referenced by GetConfigOptionByNum().

◆ GUC_UNIT_BYTE

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

Definition at line 222 of file guc.h.

Referenced by GetConfigOptionByNum().

◆ GUC_UNIT_KB

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

Definition at line 218 of file guc.h.

Referenced by GetConfigOptionByNum().

◆ GUC_UNIT_MB

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

Definition at line 221 of file guc.h.

Referenced by GetConfigOptionByNum().

◆ GUC_UNIT_MEMORY

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

◆ GUC_UNIT_MIN

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

Definition at line 227 of file guc.h.

Referenced by GetConfigOptionByNum().

◆ GUC_UNIT_MS

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

Definition at line 225 of file guc.h.

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

◆ GUC_UNIT_S

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

Definition at line 226 of file guc.h.

Referenced by _PG_init(), and GetConfigOptionByNum().

◆ GUC_UNIT_TIME

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

Definition at line 228 of file guc.h.

Referenced by GetConfigOptionByNum().

◆ GUC_UNIT_XBLOCKS

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

Definition at line 220 of file guc.h.

Referenced by GetConfigOptionByNum().

◆ MAX_KILOBYTES

#define MAX_KILOBYTES   (INT_MAX / 1024)

Definition at line 26 of file guc.h.

◆ PG_AUTOCONF_FILENAME

#define PG_AUTOCONF_FILENAME   "postgresql.auto.conf"

Definition at line 34 of file guc.h.

Referenced by AlterSystemSetConfigFile().

Typedef Documentation

◆ ConfigVariable

◆ GucBoolAssignHook

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

Definition at line 180 of file guc.h.

◆ GucBoolCheckHook

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

Definition at line 174 of file guc.h.

◆ GucEnumAssignHook

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

Definition at line 184 of file guc.h.

◆ GucEnumCheckHook

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

Definition at line 178 of file guc.h.

◆ GucIntAssignHook

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

Definition at line 181 of file guc.h.

◆ GucIntCheckHook

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

Definition at line 175 of file guc.h.

◆ GucRealAssignHook

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

Definition at line 182 of file guc.h.

◆ GucRealCheckHook

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

Definition at line 176 of file guc.h.

◆ GucShowHook

typedef const char*(* GucShowHook) (void)

Definition at line 186 of file guc.h.

◆ GucStringAssignHook

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

Definition at line 183 of file guc.h.

◆ GucStringCheckHook

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

Definition at line 177 of file guc.h.

Enumeration Type Documentation

◆ GucAction

enum GucAction
Enumerator
GUC_ACTION_SET 
GUC_ACTION_LOCAL 
GUC_ACTION_SAVE 

Definition at line 191 of file guc.h.

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

◆ GucContext

enum GucContext
Enumerator
PGC_INTERNAL 
PGC_POSTMASTER 
PGC_SIGHUP 
PGC_SU_BACKEND 
PGC_BACKEND 
PGC_SUSET 
PGC_USERSET 

Definition at line 68 of file guc.h.

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

◆ GucSource

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

Definition at line 105 of file guc.h.

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

Function Documentation

◆ AlterSystemSetConfigFile()

void AlterSystemSetConfigFile ( AlterSystemStmt setstmt)

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

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

◆ assign_search_path()

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

Definition at line 4094 of file namespace.c.

References baseSearchPathValid.

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

◆ assign_temp_tablespaces()

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

Definition at line 1262 of file tablespace.c.

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

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

◆ assign_xlog_sync_method()

void assign_xlog_sync_method ( int  new_sync_method,
void *  extra 
)

Definition at line 10085 of file xlog.c.

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

10086 {
10087  if (sync_method != new_sync_method)
10088  {
10089  /*
10090  * To ensure that no blocks escape unsynced, force an fsync on the
10091  * currently open log segment (if any). Also, if the open flag is
10092  * changing, close the log file so it will be reopened (with new flag
10093  * bit) at next use.
10094  */
10095  if (openLogFile >= 0)
10096  {
10098  if (pg_fsync(openLogFile) != 0)
10099  ereport(PANIC,
10101  errmsg("could not fsync log segment %s: %m",
10104  if (get_sync_bit(sync_method) != get_sync_bit(new_sync_method))
10105  XLogFileClose();
10106  }
10107  }
10108 }
static int get_sync_bit(int method)
Definition: xlog.c:10029
#define PANIC
Definition: elog.h:53
static XLogSegNo openLogSegNo
Definition: xlog.c:775
static void XLogFileClose(void)
Definition: xlog.c:3707
char * XLogFileNameP(TimeLineID tli, XLogSegNo segno)
Definition: xlog.c:10161
int errcode_for_file_access(void)
Definition: elog.c:598
static void pgstat_report_wait_end(void)
Definition: pgstat.h:1244
#define ereport(elevel, rest)
Definition: elog.h:122
static int openLogFile
Definition: xlog.c:774
TimeLineID ThisTimeLineID
Definition: xlog.c:181
static void pgstat_report_wait_start(uint32 wait_event_info)
Definition: pgstat.h:1220
int sync_method
Definition: xlog.c:103
int errmsg(const char *fmt,...)
Definition: elog.c:797
int pg_fsync(int fd)
Definition: fd.c:347

◆ AtEOXact_GUC()

void AtEOXact_GUC ( bool  isCommit,
int  nestLevel 
)

Definition at line 5107 of file guc.c.

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

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

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

◆ AtStart_GUC()

void AtStart_GUC ( void  )

Definition at line 5073 of file guc.c.

References elog, and WARNING.

Referenced by StartTransaction().

5074 {
5075  /*
5076  * The nest level should be 0 between transactions; if it isn't, somebody
5077  * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
5078  * throw a warning but make no other effort to clean up.
5079  */
5080  if (GUCNestLevel != 0)
5081  elog(WARNING, "GUC nest level = %d at transaction start",
5082  GUCNestLevel);
5083  GUCNestLevel = 1;
5084 }
static int GUCNestLevel
Definition: guc.c:3976
#define WARNING
Definition: elog.h:40
#define elog
Definition: elog.h:219

◆ BeginReportingGUCOptions()

void BeginReportingGUCOptions ( void  )

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

5389 {
5390  int i;
5391 
5392  /*
5393  * Don't do anything unless talking to an interactive frontend of protocol
5394  * 3.0 or later.
5395  */
5396  if (whereToSendOutput != DestRemote ||
5398  return;
5399 
5400  reporting_enabled = true;
5401 
5402  /* Transmit initial values of interesting variables */
5403  for (i = 0; i < num_guc_variables; i++)
5404  {
5405  struct config_generic *conf = guc_variables[i];
5406 
5407  if (conf->flags & GUC_REPORT)
5408  ReportGUCOption(conf);
5409  }
5410 }
#define PG_PROTOCOL_MAJOR(v)
Definition: pqcomm.h:104
static int num_guc_variables
Definition: guc.c:3966
#define GUC_REPORT
Definition: guc.h:208
static struct config_generic ** guc_variables
Definition: guc.c:3963
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:5416
CommandDest whereToSendOutput
Definition: postgres.c:88
static bool reporting_enabled
Definition: guc.c:3974
ProtocolVersion FrontendProtocol
Definition: globals.c:27

◆ check_default_tablespace()

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

Definition at line 1062 of file tablespace.c.

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

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

◆ check_search_path()

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

Definition at line 4060 of file namespace.c.

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

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

◆ check_temp_tablespaces()

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

Definition at line 1157 of file tablespace.c.

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

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

◆ check_wal_buffers()

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

Definition at line 4787 of file xlog.c.

References XLOGbuffers, and XLOGChooseNumBuffers().

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

◆ DefineCustomBoolVariable()

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

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

7766 {
7767  struct config_bool *var;
7768 
7769  var = (struct config_bool *)
7770  init_custom_variable(name, short_desc, long_desc, context, flags,
7771  PGC_BOOL, sizeof(struct config_bool));
7772  var->variable = valueAddr;
7773  var->boot_val = bootValue;
7774  var->reset_val = bootValue;
7775  var->check_hook = check_hook;
7776  var->assign_hook = assign_hook;
7777  var->show_hook = show_hook;
7778  define_custom_variable(&var->gen);
7779 }
bool * variable
Definition: guc_tables.h:181
GucBoolAssignHook assign_hook
Definition: guc_tables.h:184
bool boot_val
Definition: guc_tables.h:182
struct config_generic gen
Definition: guc_tables.h:179
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:7524
GucBoolCheckHook check_hook
Definition: guc_tables.h:183
GucShowHook show_hook
Definition: guc_tables.h:185
const char * name
Definition: encode.c:521
bool reset_val
Definition: guc_tables.h:187
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7575

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

7878 {
7879  struct config_enum *var;
7880 
7881  var = (struct config_enum *)
7882  init_custom_variable(name, short_desc, long_desc, context, flags,
7883  PGC_ENUM, sizeof(struct config_enum));
7884  var->variable = valueAddr;
7885  var->boot_val = bootValue;
7886  var->reset_val = bootValue;
7887  var->options = options;
7888  var->check_hook = check_hook;
7889  var->assign_hook = assign_hook;
7890  var->show_hook = show_hook;
7891  define_custom_variable(&var->gen);
7892 }
GucEnumCheckHook check_hook
Definition: guc_tables.h:244
GucEnumAssignHook assign_hook
Definition: guc_tables.h:245
int * variable
Definition: guc_tables.h:241
const struct config_enum_entry * options
Definition: guc_tables.h:243
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:7524
GucShowHook show_hook
Definition: guc_tables.h:246
struct config_generic gen
Definition: guc_tables.h:239
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7575

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

7794 {
7795  struct config_int *var;
7796 
7797  var = (struct config_int *)
7798  init_custom_variable(name, short_desc, long_desc, context, flags,
7799  PGC_INT, sizeof(struct config_int));
7800  var->variable = valueAddr;
7801  var->boot_val = bootValue;
7802  var->reset_val = bootValue;
7803  var->min = minValue;
7804  var->max = maxValue;
7805  var->check_hook = check_hook;
7806  var->assign_hook = assign_hook;
7807  var->show_hook = show_hook;
7808  define_custom_variable(&var->gen);
7809 }
int boot_val
Definition: guc_tables.h:196
GucIntAssignHook assign_hook
Definition: guc_tables.h:200
GucIntCheckHook check_hook
Definition: guc_tables.h:199
GucShowHook show_hook
Definition: guc_tables.h:201
int * variable
Definition: guc_tables.h:195
struct config_generic gen
Definition: guc_tables.h:193
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:7524
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7575
int reset_val
Definition: guc_tables.h:203

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

7824 {
7825  struct config_real *var;
7826 
7827  var = (struct config_real *)
7828  init_custom_variable(name, short_desc, long_desc, context, flags,
7829  PGC_REAL, sizeof(struct config_real));
7830  var->variable = valueAddr;
7831  var->boot_val = bootValue;
7832  var->reset_val = bootValue;
7833  var->min = minValue;
7834  var->max = maxValue;
7835  var->check_hook = check_hook;
7836  var->assign_hook = assign_hook;
7837  var->show_hook = show_hook;
7838  define_custom_variable(&var->gen);
7839 }
GucRealAssignHook assign_hook
Definition: guc_tables.h:216
double reset_val
Definition: guc_tables.h:219
GucRealCheckHook check_hook
Definition: guc_tables.h:215
GucShowHook show_hook
Definition: guc_tables.h:217
double * variable
Definition: guc_tables.h:211
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:7524
double max
Definition: guc_tables.h:214
double boot_val
Definition: guc_tables.h:212
const char * name
Definition: encode.c:521
double min
Definition: guc_tables.h:213
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7575
struct config_generic gen
Definition: guc_tables.h:209

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

7852 {
7853  struct config_string *var;
7854 
7855  var = (struct config_string *)
7856  init_custom_variable(name, short_desc, long_desc, context, flags,
7857  PGC_STRING, sizeof(struct config_string));
7858  var->variable = valueAddr;
7859  var->boot_val = bootValue;
7860  var->check_hook = check_hook;
7861  var->assign_hook = assign_hook;
7862  var->show_hook = show_hook;
7863  define_custom_variable(&var->gen);
7864 }
char ** variable
Definition: guc_tables.h:227
GucStringCheckHook check_hook
Definition: guc_tables.h:229
const char * boot_val
Definition: guc_tables.h:228
GucShowHook show_hook
Definition: guc_tables.h:231
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:7524
struct config_generic gen
Definition: guc_tables.h:225
GucStringAssignHook assign_hook
Definition: guc_tables.h:230
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7575

◆ EmitWarningsOnPlaceholders()

void EmitWarningsOnPlaceholders ( const char *  className)

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

7896 {
7897  int classLen = strlen(className);
7898  int i;
7899 
7900  for (i = 0; i < num_guc_variables; i++)
7901  {
7902  struct config_generic *var = guc_variables[i];
7903 
7904  if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
7905  strncmp(className, var->name, classLen) == 0 &&
7906  var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
7907  {
7908  ereport(WARNING,
7909  (errcode(ERRCODE_UNDEFINED_OBJECT),
7910  errmsg("unrecognized configuration parameter \"%s\"",
7911  var->name)));
7912  }
7913  }
7914 }
const char * name
Definition: guc_tables.h:146
int errcode(int sqlerrcode)
Definition: elog.c:575
#define GUC_QUALIFIER_SEPARATOR
Definition: guc.h:199
static int num_guc_variables
Definition: guc.c:3966
#define ereport(elevel, rest)
Definition: elog.h:122
static struct config_generic ** guc_variables
Definition: guc.c:3963
#define WARNING
Definition: elog.h:40
#define GUC_CUSTOM_PLACEHOLDER
Definition: guc.h:211
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i

◆ EstimateGUCStateSpace()

Size EstimateGUCStateSpace ( void  )

Definition at line 9127 of file guc.c.

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

Referenced by InitializeParallelDSM().

9128 {
9129  Size size;
9130  int i;
9131 
9132  /* Add space reqd for saving the data size of the guc state */
9133  size = sizeof(Size);
9134 
9135  /* Add up the space needed for each GUC variable */
9136  for (i = 0; i < num_guc_variables; i++)
9137  size = add_size(size,
9139 
9140  return size;
9141 }
static int num_guc_variables
Definition: guc.c:3966
static struct config_generic ** guc_variables
Definition: guc.c:3963
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
size_t Size
Definition: c.h:404
static Size estimate_variable_size(struct config_generic *gconf)
Definition: guc.c:9029
int i

◆ ExecSetVariableStmt()

void ExecSetVariableStmt ( VariableSetStmt stmt,
bool  isTopLevel 
)

Definition at line 7312 of file guc.c.

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

Referenced by standard_ProcessUtility().

7313 {
7315 
7316  /*
7317  * Workers synchronize these parameters at the start of the parallel
7318  * operation; then, we block SET during the operation.
7319  */
7320  if (IsInParallelMode())
7321  ereport(ERROR,
7322  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
7323  errmsg("cannot set parameters during a parallel operation")));
7324 
7325  switch (stmt->kind)
7326  {
7327  case VAR_SET_VALUE:
7328  case VAR_SET_CURRENT:
7329  if (stmt->is_local)
7330  WarnNoTransactionChain(isTopLevel, "SET LOCAL");
7331  (void) set_config_option(stmt->name,
7332  ExtractSetVariableArgs(stmt),
7334  PGC_S_SESSION,
7335  action, true, 0, false);
7336  break;
7337  case VAR_SET_MULTI:
7338 
7339  /*
7340  * Special-case SQL syntaxes. The TRANSACTION and SESSION
7341  * CHARACTERISTICS cases effectively set more than one variable
7342  * per statement. TRANSACTION SNAPSHOT only takes one argument,
7343  * but we put it here anyway since it's a special case and not
7344  * related to any GUC variable.
7345  */
7346  if (strcmp(stmt->name, "TRANSACTION") == 0)
7347  {
7348  ListCell *head;
7349 
7350  WarnNoTransactionChain(isTopLevel, "SET TRANSACTION");
7351 
7352  foreach(head, stmt->args)
7353  {
7354  DefElem *item = (DefElem *) lfirst(head);
7355 
7356  if (strcmp(item->defname, "transaction_isolation") == 0)
7357  SetPGVariable("transaction_isolation",
7358  list_make1(item->arg), stmt->is_local);
7359  else if (strcmp(item->defname, "transaction_read_only") == 0)
7360  SetPGVariable("transaction_read_only",
7361  list_make1(item->arg), stmt->is_local);
7362  else if (strcmp(item->defname, "transaction_deferrable") == 0)
7363  SetPGVariable("transaction_deferrable",
7364  list_make1(item->arg), stmt->is_local);
7365  else
7366  elog(ERROR, "unexpected SET TRANSACTION element: %s",
7367  item->defname);
7368  }
7369  }
7370  else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
7371  {
7372  ListCell *head;
7373 
7374  foreach(head, stmt->args)
7375  {
7376  DefElem *item = (DefElem *) lfirst(head);
7377 
7378  if (strcmp(item->defname, "transaction_isolation") == 0)
7379  SetPGVariable("default_transaction_isolation",
7380  list_make1(item->arg), stmt->is_local);
7381  else if (strcmp(item->defname, "transaction_read_only") == 0)
7382  SetPGVariable("default_transaction_read_only",
7383  list_make1(item->arg), stmt->is_local);
7384  else if (strcmp(item->defname, "transaction_deferrable") == 0)
7385  SetPGVariable("default_transaction_deferrable",
7386  list_make1(item->arg), stmt->is_local);
7387  else
7388  elog(ERROR, "unexpected SET SESSION element: %s",
7389  item->defname);
7390  }
7391  }
7392  else if (strcmp(stmt->name, "TRANSACTION SNAPSHOT") == 0)
7393  {
7394  A_Const *con = linitial_node(A_Const, stmt->args);
7395 
7396  if (stmt->is_local)
7397  ereport(ERROR,
7398  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7399  errmsg("SET LOCAL TRANSACTION SNAPSHOT is not implemented")));
7400 
7401  WarnNoTransactionChain(isTopLevel, "SET TRANSACTION");
7402  Assert(nodeTag(&con->val) == T_String);
7403  ImportSnapshot(strVal(&con->val));
7404  }
7405  else
7406  elog(ERROR, "unexpected SET MULTI element: %s",
7407  stmt->name);
7408  break;
7409  case VAR_SET_DEFAULT:
7410  if (stmt->is_local)
7411  WarnNoTransactionChain(isTopLevel, "SET LOCAL");
7412  /* fall through */
7413  case VAR_RESET:
7414  if (strcmp(stmt->name, "transaction_isolation") == 0)
7415  WarnNoTransactionChain(isTopLevel, "RESET TRANSACTION");
7416 
7417  (void) set_config_option(stmt->name,
7418  NULL,
7420  PGC_S_SESSION,
7421  action, true, 0, false);
7422  break;
7423  case VAR_RESET_ALL:
7424  ResetAllOptions();
7425  break;
7426  }
7427 }
void ImportSnapshot(const char *idstr)
Definition: snapmgr.c:1430
VariableSetKind kind
Definition: parsenodes.h:1984
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:575
bool superuser(void)
Definition: superuser.c:47
#define linitial_node(type, l)
Definition: pg_list.h:114
GucAction
Definition: guc.h:191
#define list_make1(x1)
Definition: pg_list.h:139
bool IsInParallelMode(void)
Definition: xact.c:906
#define ERROR
Definition: elog.h:43
Definition: guc.h:75
void ResetAllOptions(void)
Definition: guc.c:4892
#define ereport(elevel, rest)
Definition: elog.h:122
Node * arg
Definition: parsenodes.h:720
void WarnNoTransactionChain(bool isTopLevel, const char *stmtType)
Definition: xact.c:3200
#define Assert(condition)
Definition: c.h:670
#define lfirst(lc)
Definition: pg_list.h:106
#define nodeTag(nodeptr)
Definition: nodes.h:517
int errmsg(const char *fmt,...)
Definition: elog.c:797
char * defname
Definition: parsenodes.h:719
#define elog
Definition: elog.h:219
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
Definition: guc.c:7436
Value val
Definition: parsenodes.h:287
int set_config_option(const char *name, const char *value, GucContext context, GucSource source, GucAction action, bool changeVal, int elevel, bool is_reload)
Definition: guc.c:5936
void SetPGVariable(const char *name, List *args, bool is_local)
Definition: guc.c:7456

◆ ExtractSetVariableArgs()

char* ExtractSetVariableArgs ( VariableSetStmt stmt)

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

7437 {
7438  switch (stmt->kind)
7439  {
7440  case VAR_SET_VALUE:
7441  return flatten_set_variable_args(stmt->name, stmt->args);
7442  case VAR_SET_CURRENT:
7443  return GetConfigOptionByName(stmt->name, NULL, false);
7444  default:
7445  return NULL;
7446  }
7447 }
VariableSetKind kind
Definition: parsenodes.h:1984
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:8062
static char * flatten_set_variable_args(const char *name, List *args)
Definition: guc.c:6835

◆ FreeConfigVariables()

◆ GetConfigOption()

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

Definition at line 6724 of file guc.c.

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

Referenced by applyRemoteGucs(), and PostmasterMain().

6725 {
6726  struct config_generic *record;
6727  static char buffer[256];
6728 
6729  record = find_option(name, false, ERROR);
6730  if (record == NULL)
6731  {
6732  if (missing_ok)
6733  return NULL;
6734  ereport(ERROR,
6735  (errcode(ERRCODE_UNDEFINED_OBJECT),
6736  errmsg("unrecognized configuration parameter \"%s\"",
6737  name)));
6738  }
6739  if (restrict_superuser &&
6740  (record->flags & GUC_SUPERUSER_ONLY) &&
6742  ereport(ERROR,
6743  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6744  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
6745  name)));
6746 
6747  switch (record->vartype)
6748  {
6749  case PGC_BOOL:
6750  return *((struct config_bool *) record)->variable ? "on" : "off";
6751 
6752  case PGC_INT:
6753  snprintf(buffer, sizeof(buffer), "%d",
6754  *((struct config_int *) record)->variable);
6755  return buffer;
6756 
6757  case PGC_REAL:
6758  snprintf(buffer, sizeof(buffer), "%g",
6759  *((struct config_real *) record)->variable);
6760  return buffer;
6761 
6762  case PGC_STRING:
6763  return *((struct config_string *) record)->variable;
6764 
6765  case PGC_ENUM:
6766  return config_enum_lookup_by_value((struct config_enum *) record,
6767  *((struct config_enum *) record)->variable);
6768  }
6769  return NULL;
6770 }
Oid GetUserId(void)
Definition: miscinit.c:284
int errcode(int sqlerrcode)
Definition: elog.c:575
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5645
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
enum config_type vartype
Definition: guc_tables.h:153
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4857
#define DEFAULT_ROLE_READ_ALL_SETTINGS
Definition: pg_authid.h:106
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4400
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:214
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ GetConfigOptionByName()

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

Definition at line 8062 of file guc.c.

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

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

8063 {
8064  struct config_generic *record;
8065 
8066  record = find_option(name, false, ERROR);
8067  if (record == NULL)
8068  {
8069  if (missing_ok)
8070  {
8071  if (varname)
8072  *varname = NULL;
8073  return NULL;
8074  }
8075 
8076  ereport(ERROR,
8077  (errcode(ERRCODE_UNDEFINED_OBJECT),
8078  errmsg("unrecognized configuration parameter \"%s\"", name)));
8079  }
8080 
8081  if ((record->flags & GUC_SUPERUSER_ONLY) &&
8083  ereport(ERROR,
8084  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
8085  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
8086  name)));
8087 
8088  if (varname)
8089  *varname = record->name;
8090 
8091  return _ShowOption(record, true);
8092 }
static char * _ShowOption(struct config_generic *record, bool use_units)
Definition: guc.c:8663
Oid GetUserId(void)
Definition: miscinit.c:284
const char * name
Definition: guc_tables.h:146
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4857
#define DEFAULT_ROLE_READ_ALL_SETTINGS
Definition: pg_authid.h:106
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4400
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ GetConfigOptionByNum()

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

Definition at line 8099 of file guc.c.

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

Referenced by show_all_settings().

8100 {
8101  char buffer[256];
8102  struct config_generic *conf;
8103 
8104  /* check requested variable number valid */
8105  Assert((varnum >= 0) && (varnum < num_guc_variables));
8106 
8107  conf = guc_variables[varnum];
8108 
8109  if (noshow)
8110  {
8111  if ((conf->flags & GUC_NO_SHOW_ALL) ||
8112  ((conf->flags & GUC_SUPERUSER_ONLY) &&
8114  *noshow = true;
8115  else
8116  *noshow = false;
8117  }
8118 
8119  /* first get the generic attributes */
8120 
8121  /* name */
8122  values[0] = conf->name;
8123 
8124  /* setting : use _ShowOption in order to avoid duplicating the logic */
8125  values[1] = _ShowOption(conf, false);
8126 
8127  /* unit */
8128  if (conf->vartype == PGC_INT)
8129  {
8130  switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
8131  {
8132  case GUC_UNIT_BYTE:
8133  values[2] = "B";
8134  break;
8135  case GUC_UNIT_KB:
8136  values[2] = "kB";
8137  break;
8138  case GUC_UNIT_MB:
8139  values[2] = "MB";
8140  break;
8141  case GUC_UNIT_BLOCKS:
8142  snprintf(buffer, sizeof(buffer), "%dkB", BLCKSZ / 1024);
8143  values[2] = pstrdup(buffer);
8144  break;
8145  case GUC_UNIT_XBLOCKS:
8146  snprintf(buffer, sizeof(buffer), "%dkB", XLOG_BLCKSZ / 1024);
8147  values[2] = pstrdup(buffer);
8148  break;
8149  case GUC_UNIT_MS:
8150  values[2] = "ms";
8151  break;
8152  case GUC_UNIT_S:
8153  values[2] = "s";
8154  break;
8155  case GUC_UNIT_MIN:
8156  values[2] = "min";
8157  break;
8158  case 0:
8159  values[2] = NULL;
8160  break;
8161  default:
8162  elog(ERROR, "unrecognized GUC units value: %d",
8163  conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME));
8164  values[2] = NULL;
8165  break;
8166  }
8167  }
8168  else
8169  values[2] = NULL;
8170 
8171  /* group */
8172  values[3] = config_group_names[conf->group];
8173 
8174  /* short_desc */
8175  values[4] = conf->short_desc;
8176 
8177  /* extra_desc */
8178  values[5] = conf->long_desc;
8179 
8180  /* context */
8181  values[6] = GucContext_Names[conf->context];
8182 
8183  /* vartype */
8184  values[7] = config_type_names[conf->vartype];
8185 
8186  /* source */
8187  values[8] = GucSource_Names[conf->source];
8188 
8189  /* now get the type specific attributes */
8190  switch (conf->vartype)
8191  {
8192  case PGC_BOOL:
8193  {
8194  struct config_bool *lconf = (struct config_bool *) conf;
8195 
8196  /* min_val */
8197  values[9] = NULL;
8198 
8199  /* max_val */
8200  values[10] = NULL;
8201 
8202  /* enumvals */
8203  values[11] = NULL;
8204 
8205  /* boot_val */
8206  values[12] = pstrdup(lconf->boot_val ? "on" : "off");
8207 
8208  /* reset_val */
8209  values[13] = pstrdup(lconf->reset_val ? "on" : "off");
8210  }
8211  break;
8212 
8213  case PGC_INT:
8214  {
8215  struct config_int *lconf = (struct config_int *) conf;
8216 
8217  /* min_val */
8218  snprintf(buffer, sizeof(buffer), "%d", lconf->min);
8219  values[9] = pstrdup(buffer);
8220 
8221  /* max_val */
8222  snprintf(buffer, sizeof(buffer), "%d", lconf->max);
8223  values[10] = pstrdup(buffer);
8224 
8225  /* enumvals */
8226  values[11] = NULL;
8227 
8228  /* boot_val */
8229  snprintf(buffer, sizeof(buffer), "%d", lconf->boot_val);
8230  values[12] = pstrdup(buffer);
8231 
8232  /* reset_val */
8233  snprintf(buffer, sizeof(buffer), "%d", lconf->reset_val);
8234  values[13] = pstrdup(buffer);
8235  }
8236  break;
8237 
8238  case PGC_REAL:
8239  {
8240  struct config_real *lconf = (struct config_real *) conf;
8241 
8242  /* min_val */
8243  snprintf(buffer, sizeof(buffer), "%g", lconf->min);
8244  values[9] = pstrdup(buffer);
8245 
8246  /* max_val */
8247  snprintf(buffer, sizeof(buffer), "%g", lconf->max);
8248  values[10] = pstrdup(buffer);
8249 
8250  /* enumvals */
8251  values[11] = NULL;
8252 
8253  /* boot_val */
8254  snprintf(buffer, sizeof(buffer), "%g", lconf->boot_val);
8255  values[12] = pstrdup(buffer);
8256 
8257  /* reset_val */
8258  snprintf(buffer, sizeof(buffer), "%g", lconf->reset_val);
8259  values[13] = pstrdup(buffer);
8260  }
8261  break;
8262 
8263  case PGC_STRING:
8264  {
8265  struct config_string *lconf = (struct config_string *) conf;
8266 
8267  /* min_val */
8268  values[9] = NULL;
8269 
8270  /* max_val */
8271  values[10] = NULL;
8272 
8273  /* enumvals */
8274  values[11] = NULL;
8275 
8276  /* boot_val */
8277  if (lconf->boot_val == NULL)
8278  values[12] = NULL;
8279  else
8280  values[12] = pstrdup(lconf->boot_val);
8281 
8282  /* reset_val */
8283  if (lconf->reset_val == NULL)
8284  values[13] = NULL;
8285  else
8286  values[13] = pstrdup(lconf->reset_val);
8287  }
8288  break;
8289 
8290  case PGC_ENUM:
8291  {
8292  struct config_enum *lconf = (struct config_enum *) conf;
8293 
8294  /* min_val */
8295  values[9] = NULL;
8296 
8297  /* max_val */
8298  values[10] = NULL;
8299 
8300  /* enumvals */
8301 
8302  /*
8303  * NOTE! enumvals with double quotes in them are not
8304  * supported!
8305  */
8306  values[11] = config_enum_get_options((struct config_enum *) conf,
8307  "{\"", "\"}", "\",\"");
8308 
8309  /* boot_val */
8311  lconf->boot_val));
8312 
8313  /* reset_val */
8315  lconf->reset_val));
8316  }
8317  break;
8318 
8319  default:
8320  {
8321  /*
8322  * should never get here, but in case we do, set 'em to NULL
8323  */
8324 
8325  /* min_val */
8326  values[9] = NULL;
8327 
8328  /* max_val */
8329  values[10] = NULL;
8330 
8331  /* enumvals */
8332  values[11] = NULL;
8333 
8334  /* boot_val */
8335  values[12] = NULL;
8336 
8337  /* reset_val */
8338  values[13] = NULL;
8339  }
8340  break;
8341  }
8342 
8343  /*
8344  * If the setting came from a config file, set the source location. For
8345  * security reasons, we don't show source file/line number for
8346  * non-superusers.
8347  */
8348  if (conf->source == PGC_S_FILE && superuser())
8349  {
8350  values[14] = conf->sourcefile;
8351  snprintf(buffer, sizeof(buffer), "%d", conf->sourceline);
8352  values[15] = pstrdup(buffer);
8353  }
8354  else
8355  {
8356  values[14] = NULL;
8357  values[15] = NULL;
8358  }
8359 
8360  values[16] = (conf->status & GUC_PENDING_RESTART) ? "t" : "f";
8361 }
GucSource source
Definition: guc_tables.h:155
static char * _ShowOption(struct config_generic *record, bool use_units)
Definition: guc.c:8663
const char * long_desc
Definition: guc_tables.h:150
double reset_val
Definition: guc_tables.h:219
Oid GetUserId(void)
Definition: miscinit.c:284
const char * name
Definition: guc_tables.h:146
const char *const config_type_names[]
Definition: guc.c:673
char * pstrdup(const char *in)
Definition: mcxt.c:1076
const char * short_desc
Definition: guc_tables.h:149
int boot_val
Definition: guc_tables.h:196
const char * boot_val
Definition: guc_tables.h:228
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5645
bool superuser(void)
Definition: superuser.c:47
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define GUC_UNIT_KB
Definition: guc.h:218
#define GUC_UNIT_BLOCKS
Definition: guc.h:219
#define GUC_NO_SHOW_ALL
Definition: guc.h:206
const char *const GucContext_Names[]
Definition: guc.c:529
#define GUC_UNIT_MIN
Definition: guc.h:227
const char *const config_group_names[]
Definition: guc.c:566
#define ERROR
Definition: elog.h:43
#define GUC_UNIT_XBLOCKS
Definition: guc.h:220
#define GUC_UNIT_BYTE
Definition: guc.h:222
static int num_guc_variables
Definition: guc.c:3966
#define GUC_UNIT_S
Definition: guc.h:226
char * sourcefile
Definition: guc_tables.h:161
bool boot_val
Definition: guc_tables.h:182
static struct config_generic ** guc_variables
Definition: guc.c:3963
enum config_type vartype
Definition: guc_tables.h:153
#define GUC_UNIT_TIME
Definition: guc.h:228
double max
Definition: guc_tables.h:214
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4857
#define DEFAULT_ROLE_READ_ALL_SETTINGS
Definition: pg_authid.h:106
char * reset_val
Definition: guc_tables.h:233
double boot_val
Definition: guc_tables.h:212
#define Assert(condition)
Definition: c.h:670
#define GUC_UNIT_MB
Definition: guc.h:221
#define GUC_PENDING_RESTART
Definition: guc_tables.h:172
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:214
double min
Definition: guc_tables.h:213
static Datum values[MAXATTR]
Definition: bootstrap.c:164
enum config_group group
Definition: guc_tables.h:148
#define elog
Definition: elog.h:219
bool reset_val
Definition: guc_tables.h:187
const char *const GucSource_Names[]
Definition: guc.c:545
static char * config_enum_get_options(struct config_enum *record, const char *prefix, const char *suffix, const char *separator)
Definition: guc.c:5694
#define GUC_UNIT_MS
Definition: guc.h:225
GucContext context
Definition: guc_tables.h:147
#define GUC_UNIT_MEMORY
Definition: guc.h:223
int reset_val
Definition: guc_tables.h:203

◆ GetConfigOptionResetString()

const char* GetConfigOptionResetString ( const char *  name)

Definition at line 6780 of file guc.c.

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

Referenced by check_datestyle().

6781 {
6782  struct config_generic *record;
6783  static char buffer[256];
6784 
6785  record = find_option(name, false, ERROR);
6786  if (record == NULL)
6787  ereport(ERROR,
6788  (errcode(ERRCODE_UNDEFINED_OBJECT),
6789  errmsg("unrecognized configuration parameter \"%s\"", name)));
6790  if ((record->flags & GUC_SUPERUSER_ONLY) &&
6792  ereport(ERROR,
6793  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6794  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
6795  name)));
6796 
6797  switch (record->vartype)
6798  {
6799  case PGC_BOOL:
6800  return ((struct config_bool *) record)->reset_val ? "on" : "off";
6801 
6802  case PGC_INT:
6803  snprintf(buffer, sizeof(buffer), "%d",
6804  ((struct config_int *) record)->reset_val);
6805  return buffer;
6806 
6807  case PGC_REAL:
6808  snprintf(buffer, sizeof(buffer), "%g",
6809  ((struct config_real *) record)->reset_val);
6810  return buffer;
6811 
6812  case PGC_STRING:
6813  return ((struct config_string *) record)->reset_val;
6814 
6815  case PGC_ENUM:
6816  return config_enum_lookup_by_value((struct config_enum *) record,
6817  ((struct config_enum *) record)->reset_val);
6818  }
6819  return NULL;
6820 }
Oid GetUserId(void)
Definition: miscinit.c:284
int errcode(int sqlerrcode)
Definition: elog.c:575
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5645
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
enum config_type vartype
Definition: guc_tables.h:153
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4857
#define DEFAULT_ROLE_READ_ALL_SETTINGS
Definition: pg_authid.h:106
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4400
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:214
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ GetNumConfigOptions()

int GetNumConfigOptions ( void  )

Definition at line 8367 of file guc.c.

References num_guc_variables.

Referenced by GucInfoMain(), and show_all_settings().

8368 {
8369  return num_guc_variables;
8370 }
static int num_guc_variables
Definition: guc.c:3966

◆ GetPGVariable()

void GetPGVariable ( const char *  name,
DestReceiver dest 
)

Definition at line 7921 of file guc.c.

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

Referenced by exec_replication_command(), and standard_ProcessUtility().

7922 {
7923  if (guc_name_compare(name, "all") == 0)
7924  ShowAllGUCConfig(dest);
7925  else
7926  ShowGUCConfigOption(name, dest);
7927 }
static void ShowGUCConfigOption(const char *name, DestReceiver *dest)
Definition: guc.c:7965
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:4461
static void ShowAllGUCConfig(DestReceiver *dest)
Definition: guc.c:7993
const char * name
Definition: encode.c:521

◆ GetPGVariableResultDesc()

TupleDesc GetPGVariableResultDesc ( const char *  name)

Definition at line 7930 of file guc.c.

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

Referenced by UtilityTupleDescriptor().

7931 {
7932  TupleDesc tupdesc;
7933 
7934  if (guc_name_compare(name, "all") == 0)
7935  {
7936  /* need a tuple descriptor representing three TEXT columns */
7937  tupdesc = CreateTemplateTupleDesc(3, false);
7938  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
7939  TEXTOID, -1, 0);
7940  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
7941  TEXTOID, -1, 0);
7942  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
7943  TEXTOID, -1, 0);
7944  }
7945  else
7946  {
7947  const char *varname;
7948 
7949  /* Get the canonical spelling of name */
7950  (void) GetConfigOptionByName(name, &varname, false);
7951 
7952  /* need a tuple descriptor representing a single TEXT column */
7953  tupdesc = CreateTemplateTupleDesc(1, false);
7954  TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
7955  TEXTOID, -1, 0);
7956  }
7957  return tupdesc;
7958 }
#define TEXTOID
Definition: pg_type.h:324
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:4461
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:8062
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:505
TupleDesc CreateTemplateTupleDesc(int natts, bool hasoid)
Definition: tupdesc.c:43
const char * name
Definition: encode.c:521
int16 AttrNumber
Definition: attnum.h:21

◆ GUC_check_errcode()

void GUC_check_errcode ( int  sqlerrcode)

Definition at line 9796 of file guc.c.

References GUC_check_errcode_value.

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

9797 {
9798  GUC_check_errcode_value = sqlerrcode;
9799 }
static int GUC_check_errcode_value
Definition: guc.c:128

◆ GUCArrayAdd()

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

Definition at line 9493 of file guc.c.

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

Referenced by AlterSetting(), and update_proconfig_value().

9494 {
9495  struct config_generic *record;
9496  Datum datum;
9497  char *newval;
9498  ArrayType *a;
9499 
9500  Assert(name);
9501  Assert(value);
9502 
9503  /* test if the option is valid and we're allowed to set it */
9504  (void) validate_option_array_item(name, value, false);
9505 
9506  /* normalize name (converts obsolete GUC names to modern spellings) */
9507  record = find_option(name, false, WARNING);
9508  if (record)
9509  name = record->name;
9510 
9511  /* build new item for array */
9512  newval = psprintf("%s=%s", name, value);
9513  datum = CStringGetTextDatum(newval);
9514 
9515  if (array)
9516  {
9517  int index;
9518  bool isnull;
9519  int i;
9520 
9521  Assert(ARR_ELEMTYPE(array) == TEXTOID);
9522  Assert(ARR_NDIM(array) == 1);
9523  Assert(ARR_LBOUND(array)[0] == 1);
9524 
9525  index = ARR_DIMS(array)[0] + 1; /* add after end */
9526 
9527  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9528  {
9529  Datum d;
9530  char *current;
9531 
9532  d = array_ref(array, 1, &i,
9533  -1 /* varlenarray */ ,
9534  -1 /* TEXT's typlen */ ,
9535  false /* TEXT's typbyval */ ,
9536  'i' /* TEXT's typalign */ ,
9537  &isnull);
9538  if (isnull)
9539  continue;
9540  current = TextDatumGetCString(d);
9541 
9542  /* check for match up through and including '=' */
9543  if (strncmp(current, newval, strlen(name) + 1) == 0)
9544  {
9545  index = i;
9546  break;
9547  }
9548  }
9549 
9550  a = array_set(array, 1, &index,
9551  datum,
9552  false,
9553  -1 /* varlena array */ ,
9554  -1 /* TEXT's typlen */ ,
9555  false /* TEXT's typbyval */ ,
9556  'i' /* TEXT's typalign */ );
9557  }
9558  else
9559  a = construct_array(&datum, 1,
9560  TEXTOID,
9561  -1, false, 'i');
9562 
9563  return a;
9564 }
const char * name
Definition: guc_tables.h:146
#define TEXTOID
Definition: pg_type.h:324
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3279
ArrayType * array_set(ArrayType *array, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3081
#define ARR_LBOUND(a)
Definition: array.h:281
Definition: type.h:89
static bool validate_option_array_item(const char *name, const char *value, bool skipIfNoPermissions)
Definition: guc.c:9719
#define ARR_DIMS(a)
Definition: array.h:279
static struct @121 value
Datum array_ref(ArrayType *array, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:3064
#define WARNING
Definition: elog.h:40
#define TextDatumGetCString(d)
Definition: builtins.h:92
uintptr_t Datum
Definition: postgres.h:372
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4400
#define Assert(condition)
Definition: c.h:670
#define newval
#define ARR_NDIM(a)
Definition: array.h:275
const char * name
Definition: encode.c:521
int i
#define CStringGetTextDatum(s)
Definition: builtins.h:91
#define ARR_ELEMTYPE(a)
Definition: array.h:277

◆ GUCArrayDelete()

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

Definition at line 9573 of file guc.c.

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

Referenced by AlterSetting(), and update_proconfig_value().

9574 {
9575  struct config_generic *record;
9576  ArrayType *newarray;
9577  int i;
9578  int index;
9579 
9580  Assert(name);
9581 
9582  /* test if the option is valid and we're allowed to set it */
9583  (void) validate_option_array_item(name, NULL, false);
9584 
9585  /* normalize name (converts obsolete GUC names to modern spellings) */
9586  record = find_option(name, false, WARNING);
9587  if (record)
9588  name = record->name;
9589 
9590  /* if array is currently null, then surely nothing to delete */
9591  if (!array)
9592  return NULL;
9593 
9594  newarray = NULL;
9595  index = 1;
9596 
9597  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9598  {
9599  Datum d;
9600  char *val;
9601  bool isnull;
9602 
9603  d = array_ref(array, 1, &i,
9604  -1 /* varlenarray */ ,
9605  -1 /* TEXT's typlen */ ,
9606  false /* TEXT's typbyval */ ,
9607  'i' /* TEXT's typalign */ ,
9608  &isnull);
9609  if (isnull)
9610  continue;
9611  val = TextDatumGetCString(d);
9612 
9613  /* ignore entry if it's what we want to delete */
9614  if (strncmp(val, name, strlen(name)) == 0
9615  && val[strlen(name)] == '=')
9616  continue;
9617 
9618  /* else add it to the output array */
9619  if (newarray)
9620  newarray = array_set(newarray, 1, &index,
9621  d,
9622  false,
9623  -1 /* varlenarray */ ,
9624  -1 /* TEXT's typlen */ ,
9625  false /* TEXT's typbyval */ ,
9626  'i' /* TEXT's typalign */ );
9627  else
9628  newarray = construct_array(&d, 1,
9629  TEXTOID,
9630  -1, false, 'i');
9631 
9632  index++;
9633  }
9634 
9635  return newarray;
9636 }
const char * name
Definition: guc_tables.h:146
#define TEXTOID
Definition: pg_type.h:324
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3279
ArrayType * array_set(ArrayType *array, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3081
Definition: type.h:89
static bool validate_option_array_item(const char *name, const char *value, bool skipIfNoPermissions)
Definition: guc.c:9719
#define ARR_DIMS(a)
Definition: array.h:279
Datum array_ref(ArrayType *array, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:3064
#define WARNING
Definition: elog.h:40
#define TextDatumGetCString(d)
Definition: builtins.h:92
uintptr_t Datum
Definition: postgres.h:372
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4400
#define Assert(condition)
Definition: c.h:670
const char * name
Definition: encode.c:521
int i
long val
Definition: informix.c:689

◆ GUCArrayReset()

ArrayType* GUCArrayReset ( ArrayType array)

Definition at line 9645 of file guc.c.

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

Referenced by AlterSetting().

9646 {
9647  ArrayType *newarray;
9648  int i;
9649  int index;
9650 
9651  /* if array is currently null, nothing to do */
9652  if (!array)
9653  return NULL;
9654 
9655  /* if we're superuser, we can delete everything, so just do it */
9656  if (superuser())
9657  return NULL;
9658 
9659  newarray = NULL;
9660  index = 1;
9661 
9662  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9663  {
9664  Datum d;
9665  char *val;
9666  char *eqsgn;
9667  bool isnull;
9668 
9669  d = array_ref(array, 1, &i,
9670  -1 /* varlenarray */ ,
9671  -1 /* TEXT's typlen */ ,
9672  false /* TEXT's typbyval */ ,
9673  'i' /* TEXT's typalign */ ,
9674  &isnull);
9675  if (isnull)
9676  continue;
9677  val = TextDatumGetCString(d);
9678 
9679  eqsgn = strchr(val, '=');
9680  *eqsgn = '\0';
9681 
9682  /* skip if we have permission to delete it */
9683  if (validate_option_array_item(val, NULL, true))
9684  continue;
9685 
9686  /* else add it to the output array */
9687  if (newarray)
9688  newarray = array_set(newarray, 1, &index,
9689  d,
9690  false,
9691  -1 /* varlenarray */ ,
9692  -1 /* TEXT's typlen */ ,
9693  false /* TEXT's typbyval */ ,
9694  'i' /* TEXT's typalign */ );
9695  else
9696  newarray = construct_array(&d, 1,
9697  TEXTOID,
9698  -1, false, 'i');
9699 
9700  index++;
9701  pfree(val);
9702  }
9703 
9704  return newarray;
9705 }
#define TEXTOID
Definition: pg_type.h:324
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3279
bool superuser(void)
Definition: superuser.c:47
ArrayType * array_set(ArrayType *array, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3081
Definition: type.h:89
void pfree(void *pointer)
Definition: mcxt.c:949
static bool validate_option_array_item(const char *name, const char *value, bool skipIfNoPermissions)
Definition: guc.c:9719
#define ARR_DIMS(a)
Definition: array.h:279
Datum array_ref(ArrayType *array, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:3064
#define TextDatumGetCString(d)
Definition: builtins.h:92
uintptr_t Datum
Definition: postgres.h:372
int i
long val
Definition: informix.c:689

◆ InitializeGUCOptions()

void InitializeGUCOptions ( void  )

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

4496 {
4497  int i;
4498 
4499  /*
4500  * Before log_line_prefix could possibly receive a nonempty setting, make
4501  * sure that timezone processing is minimally alive (see elog.c).
4502  */
4504 
4505  /*
4506  * Build sorted array of all GUC variables.
4507  */
4509 
4510  /*
4511  * Load all variables with their compiled-in defaults, and initialize
4512  * status fields as needed.
4513  */
4514  for (i = 0; i < num_guc_variables; i++)
4515  {
4517  }
4518 
4519  guc_dirty = false;
4520 
4521  reporting_enabled = false;
4522 
4523  /*
4524  * Prevent any attempt to override the transaction modes from
4525  * non-interactive sources.
4526  */
4527  SetConfigOption("transaction_isolation", "default",
4529  SetConfigOption("transaction_read_only", "no",
4531  SetConfigOption("transaction_deferrable", "no",
4533 
4534  /*
4535  * For historical reasons, some GUC parameters can receive defaults from
4536  * environment variables. Process those settings.
4537  */
4539 }
void build_guc_variables(void)
Definition: guc.c:4227
static void InitializeGUCOptionsFromEnvironment(void)
Definition: guc.c:4551
void pg_timezone_initialize(void)
Definition: pgtz.c:363
static int num_guc_variables
Definition: guc.c:3966
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:6700
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:4597
static struct config_generic ** guc_variables
Definition: guc.c:3963
int i
static bool reporting_enabled
Definition: guc.c:3974
static bool guc_dirty
Definition: guc.c:3972

◆ NewGUCNestLevel()

◆ parse_int()

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

Definition at line 5525 of file guc.c.

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

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

5526 {
5527  int64 val;
5528  char *endptr;
5529 
5530  /* To suppress compiler warnings, always set output params */
5531  if (result)
5532  *result = 0;
5533  if (hintmsg)
5534  *hintmsg = NULL;
5535 
5536  /* We assume here that int64 is at least as wide as long */
5537  errno = 0;
5538  val = strtol(value, &endptr, 0);
5539 
5540  if (endptr == value)
5541  return false; /* no HINT for integer syntax error */
5542 
5543  if (errno == ERANGE || val != (int64) ((int32) val))
5544  {
5545  if (hintmsg)
5546  *hintmsg = gettext_noop("Value exceeds integer range.");
5547  return false;
5548  }
5549 
5550  /* allow whitespace between integer and unit */
5551  while (isspace((unsigned char) *endptr))
5552  endptr++;
5553 
5554  /* Handle possible unit */
5555  if (*endptr != '\0')
5556  {
5557  char unit[MAX_UNIT_LEN + 1];
5558  int unitlen;
5559  bool converted = false;
5560 
5561  if ((flags & GUC_UNIT) == 0)
5562  return false; /* this setting does not accept a unit */
5563 
5564  unitlen = 0;
5565  while (*endptr != '\0' && !isspace((unsigned char) *endptr) &&
5566  unitlen < MAX_UNIT_LEN)
5567  unit[unitlen++] = *(endptr++);
5568  unit[unitlen] = '\0';
5569  /* allow whitespace after unit */
5570  while (isspace((unsigned char) *endptr))
5571  endptr++;
5572 
5573  if (*endptr == '\0')
5574  converted = convert_to_base_unit(val, unit, (flags & GUC_UNIT),
5575  &val);
5576  if (!converted)
5577  {
5578  /* invalid unit, or garbage after the unit; set hint and fail. */
5579  if (hintmsg)
5580  {
5581  if (flags & GUC_UNIT_MEMORY)
5582  *hintmsg = memory_units_hint;
5583  else
5584  *hintmsg = time_units_hint;
5585  }
5586  return false;
5587  }
5588 
5589  /* Check for overflow due to units conversion */
5590  if (val != (int64) ((int32) val))
5591  {
5592  if (hintmsg)
5593  *hintmsg = gettext_noop("Value exceeds integer range.");
5594  return false;
5595  }
5596  }
5597 
5598  if (result)
5599  *result = (int) val;
5600  return true;
5601 }
#define MAX_UNIT_LEN
Definition: guc.c:697
#define gettext_noop(x)
Definition: c.h:981
#define GUC_UNIT
Definition: guc.h:230
signed int int32
Definition: c.h:284
static struct @121 value
static const char * time_units_hint
Definition: guc.c:749
static bool convert_to_base_unit(int64 value, const char *unit, int base_unit, int64 *base_value)
Definition: guc.c:5440
long val
Definition: informix.c:689
static const char * memory_units_hint
Definition: guc.c:717
#define GUC_UNIT_MEMORY
Definition: guc.h:223

◆ parse_real()

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

Definition at line 5611 of file guc.c.

References val.

Referenced by parse_and_validate_value(), and parse_one_reloption().

5612 {
5613  double val;
5614  char *endptr;
5615 
5616  if (result)
5617  *result = 0; /* suppress compiler warning */
5618 
5619  errno = 0;
5620  val = strtod(value, &endptr);
5621  if (endptr == value || errno == ERANGE)
5622  return false;
5623 
5624  /* allow whitespace after number */
5625  while (isspace((unsigned char) *endptr))
5626  endptr++;
5627  if (*endptr != '\0')
5628  return false;
5629 
5630  if (result)
5631  *result = val;
5632  return true;
5633 }
static struct @121 value
long val
Definition: informix.c:689

◆ ParseConfigDirectory()

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

◆ ParseConfigFile()

bool ParseConfigFile ( const char *  config_file,
bool  strict,
const char *  calling_file,
int  calling_lineno,
int  depth,
int  elevel,
ConfigVariable **  head_p,
ConfigVariable **  tail_p 
)

◆ ParseConfigFp()

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

◆ ParseLongOption()

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

Definition at line 9397 of file guc.c.

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

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

9398 {
9399  size_t equal_pos;
9400  char *cp;
9401 
9402  AssertArg(string);
9403  AssertArg(name);
9404  AssertArg(value);
9405 
9406  equal_pos = strcspn(string, "=");
9407 
9408  if (string[equal_pos] == '=')
9409  {
9410  *name = guc_malloc(FATAL, equal_pos + 1);
9411  strlcpy(*name, string, equal_pos + 1);
9412 
9413  *value = guc_strdup(FATAL, &string[equal_pos + 1]);
9414  }
9415  else
9416  {
9417  /* no equal sign in string */
9418  *name = guc_strdup(FATAL, string);
9419  *value = NULL;
9420  }
9421 
9422  for (cp = *name; *cp; cp++)
9423  if (*cp == '-')
9424  *cp = '_';
9425 }
static char * guc_strdup(int elevel, const char *src)
Definition: guc.c:4036
#define FATAL
Definition: elog.h:52
static struct @121 value
#define AssertArg(condition)
Definition: c.h:672
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
const char * name
Definition: encode.c:521
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4004

◆ ProcessConfigFile()

◆ ProcessGUCArray()

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

Definition at line 9435 of file guc.c.

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

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

9437 {
9438  int i;
9439 
9440  Assert(array != NULL);
9441  Assert(ARR_ELEMTYPE(array) == TEXTOID);
9442  Assert(ARR_NDIM(array) == 1);
9443  Assert(ARR_LBOUND(array)[0] == 1);
9444 
9445  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9446  {
9447  Datum d;
9448  bool isnull;
9449  char *s;
9450  char *name;
9451  char *value;
9452 
9453  d = array_ref(array, 1, &i,
9454  -1 /* varlenarray */ ,
9455  -1 /* TEXT's typlen */ ,
9456  false /* TEXT's typbyval */ ,
9457  'i' /* TEXT's typalign */ ,
9458  &isnull);
9459 
9460  if (isnull)
9461  continue;
9462 
9463  s = TextDatumGetCString(d);
9464 
9465  ParseLongOption(s, &name, &value);
9466  if (!value)
9467  {
9468  ereport(WARNING,
9469  (errcode(ERRCODE_SYNTAX_ERROR),
9470  errmsg("could not parse setting for parameter \"%s\"",
9471  name)));
9472  free(name);
9473  continue;
9474  }
9475 
9476  (void) set_config_option(name, value,
9477  context, source,
9478  action, true, 0, false);
9479 
9480  free(name);
9481  if (value)
9482  free(value);
9483  pfree(s);
9484  }
9485 }
GucSource source
Definition: guc_tables.h:155
#define TEXTOID
Definition: pg_type.h:324
void ParseLongOption(const char *string, char **name, char **value)
Definition: guc.c:9397
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ARR_LBOUND(a)
Definition: array.h:281
void pfree(void *pointer)
Definition: mcxt.c:949
#define ARR_DIMS(a)
Definition: array.h:279
static struct @121 value
#define ereport(elevel, rest)
Definition: elog.h:122
Datum array_ref(ArrayType *array, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:3064
#define WARNING
Definition: elog.h:40
#define TextDatumGetCString(d)
Definition: builtins.h:92
uintptr_t Datum
Definition: postgres.h:372
#define free(a)
Definition: header.h:65
#define Assert(condition)
Definition: c.h:670
#define ARR_NDIM(a)
Definition: array.h:275
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
int set_config_option(const char *name, const char *value, GucContext context, GucSource source, GucAction action, bool changeVal, int elevel, bool is_reload)
Definition: guc.c:5936
#define ARR_ELEMTYPE(a)
Definition: array.h:277
GucContext context
Definition: guc_tables.h:147

◆ ResetAllOptions()

void ResetAllOptions ( void  )

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

4893 {
4894  int i;
4895 
4896  for (i = 0; i < num_guc_variables; i++)
4897  {
4898  struct config_generic *gconf = guc_variables[i];
4899 
4900  /* Don't reset non-SET-able values */
4901  if (gconf->context != PGC_SUSET &&
4902  gconf->context != PGC_USERSET)
4903  continue;
4904  /* Don't reset if special exclusion from RESET ALL */
4905  if (gconf->flags & GUC_NO_RESET_ALL)
4906  continue;
4907  /* No need to reset if wasn't SET */
4908  if (gconf->source <= PGC_S_OVERRIDE)
4909  continue;
4910 
4911  /* Save old value to support transaction abort */
4913 
4914  switch (gconf->vartype)
4915  {
4916  case PGC_BOOL:
4917  {
4918  struct config_bool *conf = (struct config_bool *) gconf;
4919 
4920  if (conf->assign_hook)
4921  conf->assign_hook(conf->reset_val,
4922  conf->reset_extra);
4923  *conf->variable = conf->reset_val;
4924  set_extra_field(&conf->gen, &conf->gen.extra,
4925  conf->reset_extra);
4926  break;
4927  }
4928  case PGC_INT:
4929  {
4930  struct config_int *conf = (struct config_int *) gconf;
4931 
4932  if (conf->assign_hook)
4933  conf->assign_hook(conf->reset_val,
4934  conf->reset_extra);
4935  *conf->variable = conf->reset_val;
4936  set_extra_field(&conf->gen, &conf->gen.extra,
4937  conf->reset_extra);
4938  break;
4939  }
4940  case PGC_REAL:
4941  {
4942  struct config_real *conf = (struct config_real *) gconf;
4943 
4944  if (conf->assign_hook)
4945  conf->assign_hook(conf->reset_val,
4946  conf->reset_extra);
4947  *conf->variable = conf->reset_val;
4948  set_extra_field(&conf->gen, &conf->gen.extra,
4949  conf->reset_extra);
4950  break;
4951  }
4952  case PGC_STRING:
4953  {
4954  struct config_string *conf = (struct config_string *) gconf;
4955 
4956  if (conf->assign_hook)
4957  conf->assign_hook(conf->reset_val,
4958  conf->reset_extra);
4959  set_string_field(conf, conf->variable, conf->reset_val);
4960  set_extra_field(&conf->gen, &conf->gen.extra,
4961  conf->reset_extra);
4962  break;
4963  }
4964  case PGC_ENUM:
4965  {
4966  struct config_enum *conf = (struct config_enum *) gconf;
4967 
4968  if (conf->assign_hook)
4969  conf->assign_hook(conf->reset_val,
4970  conf->reset_extra);
4971  *conf->variable = conf->reset_val;
4972  set_extra_field(&conf->gen, &conf->gen.extra,
4973  conf->reset_extra);
4974  break;
4975  }
4976  }
4977 
4978  gconf->source = gconf->reset_source;
4979  gconf->scontext = gconf->reset_scontext;
4980 
4981  if (gconf->flags & GUC_REPORT)
4982  ReportGUCOption(gconf);
4983  }
4984 }
GucSource source
Definition: guc_tables.h:155
void * reset_extra
Definition: guc_tables.h:204
GucRealAssignHook assign_hook
Definition: guc_tables.h:216
double reset_val
Definition: guc_tables.h:219
#define GUC_NO_RESET_ALL
Definition: guc.h:207
char ** variable
Definition: guc_tables.h:227
bool * variable
Definition: guc_tables.h:181
GucEnumAssignHook assign_hook
Definition: guc_tables.h:245
GucBoolAssignHook assign_hook
Definition: guc_tables.h:184
GucContext scontext
Definition: guc_tables.h:157
GucIntAssignHook assign_hook
Definition: guc_tables.h:200
static void push_old_value(struct config_generic *gconf, GucAction action)
Definition: guc.c:4992
int * variable
Definition: guc_tables.h:195
int * variable
Definition: guc_tables.h:241
static int num_guc_variables
Definition: guc.c:3966
void * reset_extra
Definition: guc_tables.h:249
Definition: guc.h:75
static void set_extra_field(struct config_generic *gconf, void **field, void *newval)
Definition: guc.c:4137
GucSource reset_source
Definition: guc_tables.h:156
struct config_generic gen
Definition: guc_tables.h:179
struct config_generic gen
Definition: guc_tables.h:193
#define GUC_REPORT
Definition: guc.h:208
double * variable
Definition: guc_tables.h:211
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4076
static struct config_generic ** guc_variables
Definition: guc.c:3963
enum config_type vartype
Definition: guc_tables.h:153
void * reset_extra
Definition: guc_tables.h:220
struct config_generic gen
Definition: guc_tables.h:239
struct config_generic gen
Definition: guc_tables.h:225
char * reset_val
Definition: guc_tables.h:233
GucStringAssignHook assign_hook
Definition: guc_tables.h:230
void * reset_extra
Definition: guc_tables.h:234
void * reset_extra
Definition: guc_tables.h:188
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:5416
bool reset_val
Definition: guc_tables.h:187
GucContext context
Definition: guc_tables.h:147
struct config_generic gen
Definition: guc_tables.h:209
GucContext reset_scontext
Definition: guc_tables.h:158
int reset_val
Definition: guc_tables.h:203

◆ RestoreGUCState()

void RestoreGUCState ( void *  gucstate)

Definition at line 9339 of file guc.c.

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

Referenced by ParallelWorkerMain().

9340 {
9341  char *varname,
9342  *varvalue,
9343  *varsourcefile;
9344  int varsourceline;
9345  GucSource varsource;
9346  GucContext varscontext;
9347  char *srcptr = (char *) gucstate;
9348  char *srcend;
9349  Size len;
9350  int i;
9351 
9352  /* See comment at can_skip_gucvar(). */
9353  for (i = 0; i < num_guc_variables; i++)
9354  if (!can_skip_gucvar(guc_variables[i]))
9356 
9357  /* First item is the length of the subsequent data */
9358  memcpy(&len, gucstate, sizeof(len));
9359 
9360  srcptr += sizeof(len);
9361  srcend = srcptr + len;
9362 
9363  while (srcptr < srcend)
9364  {
9365  int result;
9366 
9367  varname = read_gucstate(&srcptr, srcend);
9368  varvalue = read_gucstate(&srcptr, srcend);
9369  varsourcefile = read_gucstate(&srcptr, srcend);
9370  if (varsourcefile[0])
9371  read_gucstate_binary(&srcptr, srcend,
9372  &varsourceline, sizeof(varsourceline));
9373  read_gucstate_binary(&srcptr, srcend,
9374  &varsource, sizeof(varsource));
9375  read_gucstate_binary(&srcptr, srcend,
9376  &varscontext, sizeof(varscontext));
9377 
9378  result = set_config_option(varname, varvalue, varscontext, varsource,
9379  GUC_ACTION_SET, true, ERROR, true);
9380  if (result <= 0)
9381  ereport(ERROR,
9382  (errcode(ERRCODE_INTERNAL_ERROR),
9383  errmsg("parameter \"%s\" could not be set", varname)));
9384  if (varsourcefile[0])
9385  set_config_sourcefile(varname, varsourcefile, varsourceline);
9386  }
9387 }
GucContext
Definition: guc.h:68
static void static void set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
Definition: guc.c:6666
static void read_gucstate_binary(char **srcptr, char *srcend, void *dest, Size size)
Definition: guc.c:9324
int errcode(int sqlerrcode)
Definition: elog.c:575
GucSource
Definition: guc.h:105
#define ERROR
Definition: elog.h:43
static int num_guc_variables
Definition: guc.c:3966
static bool can_skip_gucvar(struct config_generic *gconf)
Definition: guc.c:9015
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:4597
#define ereport(elevel, rest)
Definition: elog.h:122
static struct config_generic ** guc_variables
Definition: guc.c:3963
static char * read_gucstate(char **srcptr, char *srcend)
Definition: guc.c:9301
size_t Size
Definition: c.h:404
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
int set_config_option(const char *name, const char *value, GucContext context, GucSource source, GucAction action, bool changeVal, int elevel, bool is_reload)
Definition: guc.c:5936

◆ SelectConfigFiles()

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

Definition at line 4717 of file guc.c.

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

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

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

◆ SerializeGUCState()

void SerializeGUCState ( Size  maxsize,
char *  start_address 
)

Definition at line 9274 of file guc.c.

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

Referenced by InitializeParallelDSM().

9275 {
9276  char *curptr;
9277  Size actual_size;
9278  Size bytes_left;
9279  int i;
9280 
9281  /* Reserve space for saving the actual size of the guc state */
9282  Assert(maxsize > sizeof(actual_size));
9283  curptr = start_address + sizeof(actual_size);
9284  bytes_left = maxsize - sizeof(actual_size);
9285 
9286  for (i = 0; i < num_guc_variables; i++)
9287  serialize_variable(&curptr, &bytes_left, guc_variables[i]);
9288 
9289  /* Store actual size without assuming alignment of start_address. */
9290  actual_size = maxsize - bytes_left - sizeof(actual_size);
9291  memcpy(start_address, &actual_size, sizeof(actual_size));
9292 }
static void serialize_variable(char **destptr, Size *maxbytes, struct config_generic *gconf)
Definition: guc.c:9200
static int num_guc_variables
Definition: guc.c:3966
static struct config_generic ** guc_variables
Definition: guc.c:3963
#define Assert(condition)
Definition: c.h:670
size_t Size
Definition: c.h:404
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 5936 of file guc.c.

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

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

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