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

Go to the source code of this file.

Data Structures

struct  ConfigVariable
 
struct  config_enum_entry
 

Macros

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

Typedefs

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

Enumerations

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

Functions

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

Variables

bool Debug_print_plan
 
bool Debug_print_parse
 
bool Debug_print_rewritten
 
bool Debug_pretty_print
 
bool log_parser_stats
 
bool log_planner_stats
 
bool log_executor_stats
 
bool log_statement_stats
 
bool log_btree_build_stats
 
PGDLLIMPORT bool check_function_bodies
 
bool session_auth_is_superuser
 
bool compute_query_id
 
bool log_duration
 
int log_parameter_max_length
 
int log_parameter_max_length_on_error
 
int log_min_error_statement
 
PGDLLIMPORT int log_min_messages
 
PGDLLIMPORT int client_min_messages
 
int log_min_duration_sample
 
int log_min_duration_statement
 
int log_temp_files
 
double log_statement_sample_rate
 
double log_xact_sample_rate
 
char * backtrace_functions
 
char * backtrace_symbol_list
 
int temp_file_limit
 
int num_temp_buffers
 
char * cluster_name
 
PGDLLIMPORT char * ConfigFileName
 
char * HbaFileName
 
char * IdentFileName
 
char * external_pid_file
 
PGDLLIMPORT char * application_name
 
int tcp_keepalives_idle
 
int tcp_keepalives_interval
 
int tcp_keepalives_count
 
int tcp_user_timeout
 
PGDLLIMPORT char * GUC_check_errmsg_string
 
PGDLLIMPORT char * GUC_check_errdetail_string
 
PGDLLIMPORT char * GUC_check_errhint_string
 

Macro Definition Documentation

◆ GUC_check_errdetail

◆ GUC_check_errhint

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

Definition at line 421 of file guc.h.

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

◆ GUC_check_errmsg

#define GUC_check_errmsg

◆ GUC_CUSTOM_PLACEHOLDER

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

◆ GUC_DISALLOW_IN_AUTO_FILE

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

Definition at line 215 of file guc.h.

Referenced by AlterSystemSetConfigFile().

◆ GUC_DISALLOW_IN_FILE

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

Definition at line 210 of file guc.h.

Referenced by AlterSystemSetConfigFile(), and displayStruct().

◆ GUC_EXPLAIN

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

Definition at line 230 of file guc.h.

Referenced by get_explain_guc_options().

◆ GUC_IS_NAME

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

Definition at line 213 of file guc.h.

Referenced by parse_and_validate_value().

◆ GUC_LIST_INPUT

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

Definition at line 204 of file guc.h.

Referenced by _PG_init(), and flatten_set_variable_args().

◆ GUC_LIST_QUOTE

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

Definition at line 205 of file guc.h.

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

◆ GUC_NO_RESET_ALL

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

Definition at line 207 of file guc.h.

Referenced by ResetAllOptions().

◆ GUC_NO_SHOW_ALL

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

◆ GUC_NOT_IN_SAMPLE

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

Definition at line 209 of file guc.h.

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

◆ GUC_NOT_WHILE_SEC_REST

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

Definition at line 214 of file guc.h.

Referenced by set_config_option().

◆ GUC_QUALIFIER_SEPARATOR

#define GUC_QUALIFIER_SEPARATOR   '.'

Definition at line 199 of file guc.h.

Referenced by EmitWarningsOnPlaceholders(), find_option(), and valid_custom_variable_name().

◆ GUC_REPORT

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

◆ GUC_SUPERUSER_ONLY

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

◆ GUC_UNIT

#define GUC_UNIT   (GUC_UNIT_MEMORY | GUC_UNIT_TIME)

Definition at line 232 of file guc.h.

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

◆ GUC_UNIT_BLOCKS

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

Definition at line 219 of file guc.h.

Referenced by get_config_unit_name().

◆ GUC_UNIT_BYTE

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

Definition at line 222 of file guc.h.

Referenced by get_config_unit_name().

◆ GUC_UNIT_KB

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

Definition at line 218 of file guc.h.

Referenced by get_config_unit_name().

◆ GUC_UNIT_MB

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

Definition at line 221 of file guc.h.

Referenced by get_config_unit_name().

◆ GUC_UNIT_MEMORY

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

◆ GUC_UNIT_MIN

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

Definition at line 227 of file guc.h.

Referenced by get_config_unit_name().

◆ GUC_UNIT_MS

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

Definition at line 225 of file guc.h.

Referenced by _PG_init(), and get_config_unit_name().

◆ GUC_UNIT_S

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

Definition at line 226 of file guc.h.

Referenced by _PG_init(), and get_config_unit_name().

◆ GUC_UNIT_TIME

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

Definition at line 228 of file guc.h.

Referenced by get_config_unit_name().

◆ GUC_UNIT_XBLOCKS

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

Definition at line 220 of file guc.h.

Referenced by get_config_unit_name().

◆ MAX_KILOBYTES

#define MAX_KILOBYTES   (INT_MAX / 1024)

Definition at line 26 of file guc.h.

Referenced by get_hash_mem().

◆ PG_AUTOCONF_FILENAME

#define PG_AUTOCONF_FILENAME   "postgresql.auto.conf"

Definition at line 34 of file guc.h.

Referenced by AlterSystemSetConfigFile().

Typedef Documentation

◆ ConfigVariable

◆ GucBoolAssignHook

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

Definition at line 180 of file guc.h.

◆ GucBoolCheckHook

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

Definition at line 174 of file guc.h.

◆ GucEnumAssignHook

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

Definition at line 184 of file guc.h.

◆ GucEnumCheckHook

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

Definition at line 178 of file guc.h.

◆ GucIntAssignHook

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

Definition at line 181 of file guc.h.

◆ GucIntCheckHook

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

Definition at line 175 of file guc.h.

◆ GucRealAssignHook

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

Definition at line 182 of file guc.h.

◆ GucRealCheckHook

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

Definition at line 176 of file guc.h.

◆ GucShowHook

typedef const char*(* GucShowHook) (void)

Definition at line 186 of file guc.h.

◆ GucStringAssignHook

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

Definition at line 183 of file guc.h.

◆ GucStringCheckHook

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

Definition at line 177 of file guc.h.

Enumeration Type Documentation

◆ GucAction

enum GucAction
Enumerator
GUC_ACTION_SET 
GUC_ACTION_LOCAL 
GUC_ACTION_SAVE 

Definition at line 191 of file guc.h.

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

◆ GucContext

enum GucContext
Enumerator
PGC_INTERNAL 
PGC_POSTMASTER 
PGC_SIGHUP 
PGC_SU_BACKEND 
PGC_BACKEND 
PGC_SUSET 
PGC_USERSET 

Definition at line 68 of file guc.h.

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

◆ GucSource

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

Definition at line 104 of file guc.h.

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

Function Documentation

◆ AlterSystemSetConfigFile()

void AlterSystemSetConfigFile ( AlterSystemStmt altersysstmt)

Definition at line 8505 of file guc.c.

References AllocateFile(), Assert, 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().

8506 {
8507  char *name;
8508  char *value;
8509  bool resetall = false;
8510  ConfigVariable *head = NULL;
8511  ConfigVariable *tail = NULL;
8512  volatile int Tmpfd;
8513  char AutoConfFileName[MAXPGPATH];
8514  char AutoConfTmpFileName[MAXPGPATH];
8515 
8516  if (!superuser())
8517  ereport(ERROR,
8518  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
8519  errmsg("must be superuser to execute ALTER SYSTEM command")));
8520 
8521  /*
8522  * Extract statement arguments
8523  */
8524  name = altersysstmt->setstmt->name;
8525 
8526  switch (altersysstmt->setstmt->kind)
8527  {
8528  case VAR_SET_VALUE:
8529  value = ExtractSetVariableArgs(altersysstmt->setstmt);
8530  break;
8531 
8532  case VAR_SET_DEFAULT:
8533  case VAR_RESET:
8534  value = NULL;
8535  break;
8536 
8537  case VAR_RESET_ALL:
8538  value = NULL;
8539  resetall = true;
8540  break;
8541 
8542  default:
8543  elog(ERROR, "unrecognized alter system stmt type: %d",
8544  altersysstmt->setstmt->kind);
8545  break;
8546  }
8547 
8548  /*
8549  * Unless it's RESET_ALL, validate the target variable and value
8550  */
8551  if (!resetall)
8552  {
8553  struct config_generic *record;
8554 
8555  record = find_option(name, false, false, ERROR);
8556  Assert(record != NULL);
8557 
8558  /*
8559  * Don't allow parameters that can't be set in configuration files to
8560  * be set in PG_AUTOCONF_FILENAME file.
8561  */
8562  if ((record->context == PGC_INTERNAL) ||
8563  (record->flags & GUC_DISALLOW_IN_FILE) ||
8564  (record->flags & GUC_DISALLOW_IN_AUTO_FILE))
8565  ereport(ERROR,
8566  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
8567  errmsg("parameter \"%s\" cannot be changed",
8568  name)));
8569 
8570  /*
8571  * If a value is specified, verify that it's sane.
8572  */
8573  if (value)
8574  {
8575  union config_var_val newval;
8576  void *newextra = NULL;
8577 
8578  /* Check that it's acceptable for the indicated parameter */
8579  if (!parse_and_validate_value(record, name, value,
8580  PGC_S_FILE, ERROR,
8581  &newval, &newextra))
8582  ereport(ERROR,
8583  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8584  errmsg("invalid value for parameter \"%s\": \"%s\"",
8585  name, value)));
8586 
8587  if (record->vartype == PGC_STRING && newval.stringval != NULL)
8588  free(newval.stringval);
8589  if (newextra)
8590  free(newextra);
8591 
8592  /*
8593  * We must also reject values containing newlines, because the
8594  * grammar for config files doesn't support embedded newlines in
8595  * string literals.
8596  */
8597  if (strchr(value, '\n'))
8598  ereport(ERROR,
8599  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8600  errmsg("parameter value for ALTER SYSTEM must not contain a newline")));
8601  }
8602  }
8603 
8604  /*
8605  * PG_AUTOCONF_FILENAME and its corresponding temporary file are always in
8606  * the data directory, so we can reference them by simple relative paths.
8607  */
8608  snprintf(AutoConfFileName, sizeof(AutoConfFileName), "%s",
8610  snprintf(AutoConfTmpFileName, sizeof(AutoConfTmpFileName), "%s.%s",
8611  AutoConfFileName,
8612  "tmp");
8613 
8614  /*
8615  * Only one backend is allowed to operate on PG_AUTOCONF_FILENAME at a
8616  * time. Use AutoFileLock to ensure that. We must hold the lock while
8617  * reading the old file contents.
8618  */
8619  LWLockAcquire(AutoFileLock, LW_EXCLUSIVE);
8620 
8621  /*
8622  * If we're going to reset everything, then no need to open or parse the
8623  * old file. We'll just write out an empty list.
8624  */
8625  if (!resetall)
8626  {
8627  struct stat st;
8628 
8629  if (stat(AutoConfFileName, &st) == 0)
8630  {
8631  /* open old file PG_AUTOCONF_FILENAME */
8632  FILE *infile;
8633 
8634  infile = AllocateFile(AutoConfFileName, "r");
8635  if (infile == NULL)
8636  ereport(ERROR,
8638  errmsg("could not open file \"%s\": %m",
8639  AutoConfFileName)));
8640 
8641  /* parse it */
8642  if (!ParseConfigFp(infile, AutoConfFileName, 0, LOG, &head, &tail))
8643  ereport(ERROR,
8644  (errcode(ERRCODE_CONFIG_FILE_ERROR),
8645  errmsg("could not parse contents of file \"%s\"",
8646  AutoConfFileName)));
8647 
8648  FreeFile(infile);
8649  }
8650 
8651  /*
8652  * Now, replace any existing entry with the new value, or add it if
8653  * not present.
8654  */
8655  replace_auto_config_value(&head, &tail, name, value);
8656  }
8657 
8658  /*
8659  * To ensure crash safety, first write the new file data to a temp file,
8660  * then atomically rename it into place.
8661  *
8662  * If there is a temp file left over due to a previous crash, it's okay to
8663  * truncate and reuse it.
8664  */
8665  Tmpfd = BasicOpenFile(AutoConfTmpFileName,
8666  O_CREAT | O_RDWR | O_TRUNC);
8667  if (Tmpfd < 0)
8668  ereport(ERROR,
8670  errmsg("could not open file \"%s\": %m",
8671  AutoConfTmpFileName)));
8672 
8673  /*
8674  * Use a TRY block to clean up the file if we fail. Since we need a TRY
8675  * block anyway, OK to use BasicOpenFile rather than OpenTransientFile.
8676  */
8677  PG_TRY();
8678  {
8679  /* Write and sync the new contents to the temporary file */
8680  write_auto_conf_file(Tmpfd, AutoConfTmpFileName, head);
8681 
8682  /* Close before renaming; may be required on some platforms */
8683  close(Tmpfd);
8684  Tmpfd = -1;
8685 
8686  /*
8687  * As the rename is atomic operation, if any problem occurs after this
8688  * at worst it can lose the parameters set by last ALTER SYSTEM
8689  * command.
8690  */
8691  durable_rename(AutoConfTmpFileName, AutoConfFileName, ERROR);
8692  }
8693  PG_CATCH();
8694  {
8695  /* Close file first, else unlink might fail on some platforms */
8696  if (Tmpfd >= 0)
8697  close(Tmpfd);
8698 
8699  /* Unlink, but ignore any error */
8700  (void) unlink(AutoConfTmpFileName);
8701 
8702  PG_RE_THROW();
8703  }
8704  PG_END_TRY();
8705 
8706  FreeConfigVariables(head);
8707 
8708  LWLockRelease(AutoFileLock);
8709 }
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:7111
VariableSetKind kind
Definition: parsenodes.h:2120
static struct @142 value
int errcode(int sqlerrcode)
Definition: elog.c:698
bool superuser(void)
Definition: superuser.c:46
#define LOG
Definition: elog.h:26
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1805
#define ERROR
Definition: elog.h:46
#define MAXPGPATH
VariableSetStmt * setstmt
Definition: parsenodes.h:3291
int errcode_for_file_access(void)
Definition: elog.c:721
FILE * AllocateFile(const char *name, const char *mode)
Definition: fd.c:2373
int durable_rename(const char *oldfile, const char *newfile, int elevel)
Definition: fd.c:692
static struct config_generic * find_option(const char *name, bool create_placeholders, bool skip_errors, int elevel)
Definition: guc.c:5504
enum config_type vartype
Definition: guc_tables.h:156
#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:8367
#define ereport(elevel,...)
Definition: elog.h:157
static void infile(const char *filename)
Definition: zic.c:1241
#define free(a)
Definition: header.h:65
#define PG_CATCH()
Definition: elog.h:323
#define Assert(condition)
Definition: c.h:804
#define newval
#define PG_AUTOCONF_FILENAME
Definition: guc.h:34
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1203
#define PG_RE_THROW()
Definition: elog.h:354
const char * name
Definition: encode.c:515
#define GUC_DISALLOW_IN_AUTO_FILE
Definition: guc.h:215
int BasicOpenFile(const char *fileName, int fileFlags)
Definition: fd.c:1033
int FreeFile(FILE *file)
Definition: fd.c:2572
int errmsg(const char *fmt,...)
Definition: elog.c:909
bool ParseConfigFp(FILE *fp, const char *config_file, int depth, int elevel, ConfigVariable **head_p, ConfigVariable **tail_p)
#define elog(elevel,...)
Definition: elog.h:232
static void replace_auto_config_value(ConfigVariable **head_p, ConfigVariable **tail_p, const char *name, const char *value)
Definition: guc.c:8435
void FreeConfigVariables(ConfigVariable *list)
#define close(a)
Definition: win32.h:12
#define PG_TRY()
Definition: elog.h:313
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
Definition: guc.c:8839
#define snprintf
Definition: port.h:216
#define PG_END_TRY()
Definition: elog.h:338
#define stat
Definition: win32_port.h:275
GucContext context
Definition: guc_tables.h:150

◆ assign_recovery_prefetch()

void assign_recovery_prefetch ( bool  new_value,
void *  extra 
)

Definition at line 909 of file xlogprefetch.c.

References AmStartupProcess, recovery_prefetch, and XLogPrefetchReconfigure().

910 {
911  /* Reconfigure prefetching, because a setting it depends on changed. */
912  recovery_prefetch = new_value;
913  if (AmStartupProcess())
915 }
#define AmStartupProcess()
Definition: miscadmin.h:433
bool recovery_prefetch
Definition: xlogprefetch.c:74
void XLogPrefetchReconfigure(void)
Definition: xlogprefetch.c:222

◆ assign_recovery_prefetch_fpw()

void assign_recovery_prefetch_fpw ( bool  new_value,
void *  extra 
)

Definition at line 918 of file xlogprefetch.c.

References AmStartupProcess, recovery_prefetch_fpw, and XLogPrefetchReconfigure().

919 {
920  /* Reconfigure prefetching, because a setting it depends on changed. */
921  recovery_prefetch_fpw = new_value;
922  if (AmStartupProcess())
924 }
#define AmStartupProcess()
Definition: miscadmin.h:433
bool recovery_prefetch_fpw
Definition: xlogprefetch.c:75
void XLogPrefetchReconfigure(void)
Definition: xlogprefetch.c:222

◆ assign_search_path()

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

Definition at line 4307 of file namespace.c.

References baseSearchPathValid.

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

◆ assign_temp_tablespaces()

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

Definition at line 1313 of file tablespace.c.

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

1314 {
1315  temp_tablespaces_extra *myextra = (temp_tablespaces_extra *) extra;
1316 
1317  /*
1318  * If check_temp_tablespaces was executed inside a transaction, then pass
1319  * the list it made to fd.c. Otherwise, clear fd.c's list; we must be
1320  * still outside a transaction, or else restoring during transaction exit,
1321  * and in either case we can just let the next PrepareTempTablespaces call
1322  * make things sane.
1323  */
1324  if (myextra)
1325  SetTempTablespaces(myextra->tblSpcs, myextra->numSpcs);
1326  else
1327  SetTempTablespaces(NULL, 0);
1328 }
Oid tblSpcs[FLEXIBLE_ARRAY_MEMBER]
Definition: tablespace.c:1200
void SetTempTablespaces(Oid *tableSpaces, int numSpaces)
Definition: fd.c:2840

◆ assign_xlog_sync_method()

void assign_xlog_sync_method ( int  new_sync_method,
void *  extra 
)

Definition at line 10587 of file xlog.c.

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

10588 {
10589  if (sync_method != new_sync_method)
10590  {
10591  /*
10592  * To ensure that no blocks escape unsynced, force an fsync on the
10593  * currently open log segment (if any). Also, if the open flag is
10594  * changing, close the log file so it will be reopened (with new flag
10595  * bit) at next use.
10596  */
10597  if (openLogFile >= 0)
10598  {
10600  if (pg_fsync(openLogFile) != 0)
10601  {
10602  char xlogfname[MAXFNAMELEN];
10603  int save_errno;
10604 
10605  save_errno = errno;
10608  errno = save_errno;
10609  ereport(PANIC,
10611  errmsg("could not fsync file \"%s\": %m", xlogfname)));
10612  }
10613 
10615  if (get_sync_bit(sync_method) != get_sync_bit(new_sync_method))
10616  XLogFileClose();
10617  }
10618  }
10619 }
static void pgstat_report_wait_end(void)
Definition: wait_event.h:277
int wal_segment_size
Definition: xlog.c:121
static int get_sync_bit(int method)
Definition: xlog.c:10531
#define PANIC
Definition: elog.h:50
static XLogSegNo openLogSegNo
Definition: xlog.c:810
static void XLogFileClose(void)
Definition: xlog.c:3901
int errcode_for_file_access(void)
Definition: elog.c:721
static void pgstat_report_wait_start(uint32 wait_event_info)
Definition: wait_event.h:261
#define MAXFNAMELEN
static int openLogFile
Definition: xlog.c:809
TimeLineID ThisTimeLineID
Definition: xlog.c:196
#define ereport(elevel,...)
Definition: elog.h:157
#define XLogFileName(fname, tli, logSegNo, wal_segsz_bytes)
int sync_method
Definition: xlog.c:108
int errmsg(const char *fmt,...)
Definition: elog.c:909
int pg_fsync(int fd)
Definition: fd.c:352

◆ AtEOXact_GUC()

void AtEOXact_GUC ( bool  isCommit,
int  nestLevel 
)

Definition at line 6235 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_NEEDS_REPORT, 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, 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_generic::status, config_var_val::stringval, config_var_value::val, config_bool::variable, config_int::variable, config_real::variable, config_string::variable, config_enum::variable, and config_generic::vartype.

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

6236 {
6237  bool still_dirty;
6238  int i;
6239 
6240  /*
6241  * Note: it's possible to get here with GUCNestLevel == nestLevel-1 during
6242  * abort, if there is a failure during transaction start before
6243  * AtStart_GUC is called.
6244  */
6245  Assert(nestLevel > 0 &&
6246  (nestLevel <= GUCNestLevel ||
6247  (nestLevel == GUCNestLevel + 1 && !isCommit)));
6248 
6249  /* Quick exit if nothing's changed in this transaction */
6250  if (!guc_dirty)
6251  {
6252  GUCNestLevel = nestLevel - 1;
6253  return;
6254  }
6255 
6256  still_dirty = false;
6257  for (i = 0; i < num_guc_variables; i++)
6258  {
6259  struct config_generic *gconf = guc_variables[i];
6260  GucStack *stack;
6261 
6262  /*
6263  * Process and pop each stack entry within the nest level. To simplify
6264  * fmgr_security_definer() and other places that use GUC_ACTION_SAVE,
6265  * we allow failure exit from code that uses a local nest level to be
6266  * recovered at the surrounding transaction or subtransaction abort;
6267  * so there could be more than one stack entry to pop.
6268  */
6269  while ((stack = gconf->stack) != NULL &&
6270  stack->nest_level >= nestLevel)
6271  {
6272  GucStack *prev = stack->prev;
6273  bool restorePrior = false;
6274  bool restoreMasked = false;
6275  bool changed;
6276 
6277  /*
6278  * In this next bit, if we don't set either restorePrior or
6279  * restoreMasked, we must "discard" any unwanted fields of the
6280  * stack entries to avoid leaking memory. If we do set one of
6281  * those flags, unused fields will be cleaned up after restoring.
6282  */
6283  if (!isCommit) /* if abort, always restore prior value */
6284  restorePrior = true;
6285  else if (stack->state == GUC_SAVE)
6286  restorePrior = true;
6287  else if (stack->nest_level == 1)
6288  {
6289  /* transaction commit */
6290  if (stack->state == GUC_SET_LOCAL)
6291  restoreMasked = true;
6292  else if (stack->state == GUC_SET)
6293  {
6294  /* we keep the current active value */
6295  discard_stack_value(gconf, &stack->prior);
6296  }
6297  else /* must be GUC_LOCAL */
6298  restorePrior = true;
6299  }
6300  else if (prev == NULL ||
6301  prev->nest_level < stack->nest_level - 1)
6302  {
6303  /* decrement entry's level and do not pop it */
6304  stack->nest_level--;
6305  continue;
6306  }
6307  else
6308  {
6309  /*
6310  * We have to merge this stack entry into prev. See README for
6311  * discussion of this bit.
6312  */
6313  switch (stack->state)
6314  {
6315  case GUC_SAVE:
6316  Assert(false); /* can't get here */
6317  break;
6318 
6319  case GUC_SET:
6320  /* next level always becomes SET */
6321  discard_stack_value(gconf, &stack->prior);
6322  if (prev->state == GUC_SET_LOCAL)
6323  discard_stack_value(gconf, &prev->masked);
6324  prev->state = GUC_SET;
6325  break;
6326 
6327  case GUC_LOCAL:
6328  if (prev->state == GUC_SET)
6329  {
6330  /* LOCAL migrates down */
6331  prev->masked_scontext = stack->scontext;
6332  prev->masked = stack->prior;
6333  prev->state = GUC_SET_LOCAL;
6334  }
6335  else
6336  {
6337  /* else just forget this stack level */
6338  discard_stack_value(gconf, &stack->prior);
6339  }
6340  break;
6341 
6342  case GUC_SET_LOCAL:
6343  /* prior state at this level no longer wanted */
6344  discard_stack_value(gconf, &stack->prior);
6345  /* copy down the masked state */
6346  prev->masked_scontext = stack->masked_scontext;
6347  if (prev->state == GUC_SET_LOCAL)
6348  discard_stack_value(gconf, &prev->masked);
6349  prev->masked = stack->masked;
6350  prev->state = GUC_SET_LOCAL;
6351  break;
6352  }
6353  }
6354 
6355  changed = false;
6356 
6357  if (restorePrior || restoreMasked)
6358  {
6359  /* Perform appropriate restoration of the stacked value */
6360  config_var_value newvalue;
6361  GucSource newsource;
6362  GucContext newscontext;
6363 
6364  if (restoreMasked)
6365  {
6366  newvalue = stack->masked;
6367  newsource = PGC_S_SESSION;
6368  newscontext = stack->masked_scontext;
6369  }
6370  else
6371  {
6372  newvalue = stack->prior;
6373  newsource = stack->source;
6374  newscontext = stack->scontext;
6375  }
6376 
6377  switch (gconf->vartype)
6378  {
6379  case PGC_BOOL:
6380  {
6381  struct config_bool *conf = (struct config_bool *) gconf;
6382  bool newval = newvalue.val.boolval;
6383  void *newextra = newvalue.extra;
6384 
6385  if (*conf->variable != newval ||
6386  conf->gen.extra != newextra)
6387  {
6388  if (conf->assign_hook)
6389  conf->assign_hook(newval, newextra);
6390  *conf->variable = newval;
6391  set_extra_field(&conf->gen, &conf->gen.extra,
6392  newextra);
6393  changed = true;
6394  }
6395  break;
6396  }
6397  case PGC_INT:
6398  {
6399  struct config_int *conf = (struct config_int *) gconf;
6400  int newval = newvalue.val.intval;
6401  void *newextra = newvalue.extra;
6402 
6403  if (*conf->variable != newval ||
6404  conf->gen.extra != newextra)
6405  {
6406  if (conf->assign_hook)
6407  conf->assign_hook(newval, newextra);
6408  *conf->variable = newval;
6409  set_extra_field(&conf->gen, &conf->gen.extra,
6410  newextra);
6411  changed = true;
6412  }
6413  break;
6414  }
6415  case PGC_REAL:
6416  {
6417  struct config_real *conf = (struct config_real *) gconf;
6418  double newval = newvalue.val.realval;
6419  void *newextra = newvalue.extra;
6420 
6421  if (*conf->variable != newval ||
6422  conf->gen.extra != newextra)
6423  {
6424  if (conf->assign_hook)
6425  conf->assign_hook(newval, newextra);
6426  *conf->variable = newval;
6427  set_extra_field(&conf->gen, &conf->gen.extra,
6428  newextra);
6429  changed = true;
6430  }
6431  break;
6432  }
6433  case PGC_STRING:
6434  {
6435  struct config_string *conf = (struct config_string *) gconf;
6436  char *newval = newvalue.val.stringval;
6437  void *newextra = newvalue.extra;
6438 
6439  if (*conf->variable != newval ||
6440  conf->gen.extra != newextra)
6441  {
6442  if (conf->assign_hook)
6443  conf->assign_hook(newval, newextra);
6444  set_string_field(conf, conf->variable, newval);
6445  set_extra_field(&conf->gen, &conf->gen.extra,
6446  newextra);
6447  changed = true;
6448  }
6449 
6450  /*
6451  * Release stacked values if not used anymore. We
6452  * could use discard_stack_value() here, but since
6453  * we have type-specific code anyway, might as
6454  * well inline it.
6455  */
6456  set_string_field(conf, &stack->prior.val.stringval, NULL);
6457  set_string_field(conf, &stack->masked.val.stringval, NULL);
6458  break;
6459  }
6460  case PGC_ENUM:
6461  {
6462  struct config_enum *conf = (struct config_enum *) gconf;
6463  int newval = newvalue.val.enumval;
6464  void *newextra = newvalue.extra;
6465 
6466  if (*conf->variable != newval ||
6467  conf->gen.extra != newextra)
6468  {
6469  if (conf->assign_hook)
6470  conf->assign_hook(newval, newextra);
6471  *conf->variable = newval;
6472  set_extra_field(&conf->gen, &conf->gen.extra,
6473  newextra);
6474  changed = true;
6475  }
6476  break;
6477  }
6478  }
6479 
6480  /*
6481  * Release stacked extra values if not used anymore.
6482  */
6483  set_extra_field(gconf, &(stack->prior.extra), NULL);
6484  set_extra_field(gconf, &(stack->masked.extra), NULL);
6485 
6486  /* And restore source information */
6487  gconf->source = newsource;
6488  gconf->scontext = newscontext;
6489  }
6490 
6491  /* Finish popping the state stack */
6492  gconf->stack = prev;
6493  pfree(stack);
6494 
6495  /* Report new value if we changed it */
6496  if (changed && (gconf->flags & GUC_REPORT))
6497  {
6498  gconf->status |= GUC_NEEDS_REPORT;
6499  report_needed = true;
6500  }
6501  } /* end of stack-popping loop */
6502 
6503  if (stack != NULL)
6504  still_dirty = true;
6505  }
6506 
6507  /* If there are no remaining stack entries, we can reset guc_dirty */
6508  guc_dirty = still_dirty;
6509 
6510  /* Update nesting level */
6511  GUCNestLevel = nestLevel - 1;
6512 }
struct guc_stack * prev
Definition: guc_tables.h:123
GucSource source
Definition: guc_tables.h:158
GucContext
Definition: guc.h:68
union config_var_val val
Definition: guc_tables.h:46
static bool report_needed
Definition: guc.c:5029
int nest_level
Definition: guc_tables.h:124
GucRealAssignHook assign_hook
Definition: guc_tables.h:222
char ** variable
Definition: guc_tables.h:233
static int GUCNestLevel
Definition: guc.c:5031
bool * variable
Definition: guc_tables.h:187
GucEnumAssignHook assign_hook
Definition: guc_tables.h:251
GucBoolAssignHook assign_hook
Definition: guc_tables.h:190
config_var_value masked
Definition: guc_tables.h:131
GucContext scontext
Definition: guc_tables.h:160
GucIntAssignHook assign_hook
Definition: guc_tables.h:206
GucSource
Definition: guc.h:104
int * variable
Definition: guc_tables.h:201
int * variable
Definition: guc_tables.h:247
void pfree(void *pointer)
Definition: mcxt.c:1169
static int num_guc_variables
Definition: guc.c:5019
static void discard_stack_value(struct config_generic *gconf, config_var_value *val)
Definition: guc.c:5246
GucSource source
Definition: guc_tables.h:126
static void set_extra_field(struct config_generic *gconf, void **field, void *newval)
Definition: guc.c:5192
struct config_generic gen
Definition: guc_tables.h:185
struct config_generic gen
Definition: guc_tables.h:199
GucContext masked_scontext
Definition: guc_tables.h:129
#define GUC_REPORT
Definition: guc.h:208
double * variable
Definition: guc_tables.h:217
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:5131
static struct config_generic ** guc_variables
Definition: guc.c:5016
enum config_type vartype
Definition: guc_tables.h:156
GucContext scontext
Definition: guc_tables.h:128
struct config_generic gen
Definition: guc_tables.h:245
struct config_generic gen
Definition: guc_tables.h:231
GucStackState state
Definition: guc_tables.h:125
GucStringAssignHook assign_hook
Definition: guc_tables.h:236
#define Assert(condition)
Definition: c.h:804
#define newval
char * stringval
Definition: guc_tables.h:36
int i
GucStack * stack
Definition: guc_tables.h:162
double realval
Definition: guc_tables.h:35
static bool guc_dirty
Definition: guc.c:5025
config_var_value prior
Definition: guc_tables.h:130
#define GUC_NEEDS_REPORT
Definition: guc_tables.h:178
struct config_generic gen
Definition: guc_tables.h:215

◆ AtStart_GUC()

void AtStart_GUC ( void  )

Definition at line 6201 of file guc.c.

References elog, and WARNING.

Referenced by StartTransaction().

6202 {
6203  /*
6204  * The nest level should be 0 between transactions; if it isn't, somebody
6205  * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
6206  * throw a warning but make no other effort to clean up.
6207  */
6208  if (GUCNestLevel != 0)
6209  elog(WARNING, "GUC nest level = %d at transaction start",
6210  GUCNestLevel);
6211  GUCNestLevel = 1;
6212 }
static int GUCNestLevel
Definition: guc.c:5031
#define WARNING
Definition: elog.h:40
#define elog(elevel,...)
Definition: elog.h:232

◆ BeginReportingGUCOptions()

void BeginReportingGUCOptions ( void  )

Definition at line 6520 of file guc.c.

References DestRemote, config_generic::flags, GUC_REPORT, i, num_guc_variables, RecoveryInProgress(), ReportGUCOption(), and whereToSendOutput.

Referenced by PostgresMain().

6521 {
6522  int i;
6523 
6524  /*
6525  * Don't do anything unless talking to an interactive frontend.
6526  */
6528  return;
6529 
6530  reporting_enabled = true;
6531 
6532  /*
6533  * Hack for in_hot_standby: initialize with the value we're about to send.
6534  * (This could be out of date by the time we actually send it, in which
6535  * case the next ReportChangedGUCOptions call will send a duplicate
6536  * report.)
6537  */
6539 
6540  /* Transmit initial values of interesting variables */
6541  for (i = 0; i < num_guc_variables; i++)
6542  {
6543  struct config_generic *conf = guc_variables[i];
6544 
6545  if (conf->flags & GUC_REPORT)
6546  ReportGUCOption(conf);
6547  }
6548 
6549  report_needed = false;
6550 }
static bool report_needed
Definition: guc.c:5029
static bool in_hot_standby
Definition: guc.c:640
bool RecoveryInProgress(void)
Definition: xlog.c:8237
static int num_guc_variables
Definition: guc.c:5019
#define GUC_REPORT
Definition: guc.h:208
static struct config_generic ** guc_variables
Definition: guc.c:5016
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:6612
CommandDest whereToSendOutput
Definition: postgres.c:92
static bool reporting_enabled
Definition: guc.c:5027

◆ check_default_tablespace()

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

Definition at line 1098 of file tablespace.c.

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

1099 {
1100  /*
1101  * If we aren't inside a transaction, or connected to a database, we
1102  * cannot do the catalog accesses necessary to verify the name. Must
1103  * accept the value on faith.
1104  */
1106  {
1107  if (**newval != '\0' &&
1109  {
1110  /*
1111  * When source == PGC_S_TEST, don't throw a hard error for a
1112  * nonexistent tablespace, only a NOTICE. See comments in guc.h.
1113  */
1114  if (source == PGC_S_TEST)
1115  {
1116  ereport(NOTICE,
1117  (errcode(ERRCODE_UNDEFINED_OBJECT),
1118  errmsg("tablespace \"%s\" does not exist",
1119  *newval)));
1120  }
1121  else
1122  {
1123  GUC_check_errdetail("Tablespace \"%s\" does not exist.",
1124  *newval);
1125  return false;
1126  }
1127  }
1128  }
1129 
1130  return true;
1131 }
Oid get_tablespace_oid(const char *tablespacename, bool missing_ok)
Definition: tablespace.c:1433
#define GUC_check_errdetail
Definition: guc.h:417
int errcode(int sqlerrcode)
Definition: elog.c:698
#define OidIsValid(objectId)
Definition: c.h:710
Oid MyDatabaseId
Definition: globals.c:88
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:157
#define NOTICE
Definition: elog.h:37
static rewind_source * source
Definition: pg_rewind.c:79
#define newval
bool IsTransactionState(void)
Definition: xact.c:371
int errmsg(const char *fmt,...)
Definition: elog.c:909

◆ check_search_path()

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

Definition at line 4273 of file namespace.c.

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

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

◆ check_temp_tablespaces()

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

Definition at line 1205 of file tablespace.c.

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

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

◆ check_wal_buffers()

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

Definition at line 5041 of file xlog.c.

References XLOGbuffers, and XLOGChooseNumBuffers().

5042 {
5043  /*
5044  * -1 indicates a request for auto-tune.
5045  */
5046  if (*newval == -1)
5047  {
5048  /*
5049  * If we haven't yet changed the boot_val default of -1, just let it
5050  * be. We'll fix it when XLOGShmemSize is called.
5051  */
5052  if (XLOGbuffers == -1)
5053  return true;
5054 
5055  /* Otherwise, substitute the auto-tune value */
5057  }
5058 
5059  /*
5060  * We clamp manually-set values to at least 4 blocks. Prior to PostgreSQL
5061  * 9.1, a minimum of 4 was enforced by guc.c, but since that is no longer
5062  * the case, we just silently treat such values as a request for the
5063  * minimum. (We could throw an error instead, but that doesn't seem very
5064  * helpful.)
5065  */
5066  if (*newval < 4)
5067  *newval = 4;
5068 
5069  return true;
5070 }
static int XLOGChooseNumBuffers(void)
Definition: xlog.c:5025
#define newval
int XLOGbuffers
Definition: xlog.c:95

◆ DeescapeQuotedString()

char* DeescapeQuotedString ( const char *  s)

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

9178 {
9179  struct config_bool *var;
9180 
9181  var = (struct config_bool *)
9182  init_custom_variable(name, short_desc, long_desc, context, flags,
9183  PGC_BOOL, sizeof(struct config_bool));
9184  var->variable = valueAddr;
9185  var->boot_val = bootValue;
9186  var->reset_val = bootValue;
9187  var->check_hook = check_hook;
9188  var->assign_hook = assign_hook;
9189  var->show_hook = show_hook;
9190  define_custom_variable(&var->gen);
9191 }
bool * variable
Definition: guc_tables.h:187
GucBoolAssignHook assign_hook
Definition: guc_tables.h:190
bool boot_val
Definition: guc_tables.h:188
struct config_generic gen
Definition: guc_tables.h:185
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:8927
GucBoolCheckHook check_hook
Definition: guc_tables.h:189
GucShowHook show_hook
Definition: guc_tables.h:191
const char * name
Definition: encode.c:515
bool reset_val
Definition: guc_tables.h:193
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8987

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

9290 {
9291  struct config_enum *var;
9292 
9293  var = (struct config_enum *)
9294  init_custom_variable(name, short_desc, long_desc, context, flags,
9295  PGC_ENUM, sizeof(struct config_enum));
9296  var->variable = valueAddr;
9297  var->boot_val = bootValue;
9298  var->reset_val = bootValue;
9299  var->options = options;
9300  var->check_hook = check_hook;
9301  var->assign_hook = assign_hook;
9302  var->show_hook = show_hook;
9303  define_custom_variable(&var->gen);
9304 }
GucEnumCheckHook check_hook
Definition: guc_tables.h:250
GucEnumAssignHook assign_hook
Definition: guc_tables.h:251
int * variable
Definition: guc_tables.h:247
const struct config_enum_entry * options
Definition: guc_tables.h:249
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:8927
GucShowHook show_hook
Definition: guc_tables.h:252
struct config_generic gen
Definition: guc_tables.h:245
const char * name
Definition: encode.c:515
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8987

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

9206 {
9207  struct config_int *var;
9208 
9209  var = (struct config_int *)
9210  init_custom_variable(name, short_desc, long_desc, context, flags,
9211  PGC_INT, sizeof(struct config_int));
9212  var->variable = valueAddr;
9213  var->boot_val = bootValue;
9214  var->reset_val = bootValue;
9215  var->min = minValue;
9216  var->max = maxValue;
9217  var->check_hook = check_hook;
9218  var->assign_hook = assign_hook;
9219  var->show_hook = show_hook;
9220  define_custom_variable(&var->gen);
9221 }
int boot_val
Definition: guc_tables.h:202
GucIntAssignHook assign_hook
Definition: guc_tables.h:206
GucIntCheckHook check_hook
Definition: guc_tables.h:205
GucShowHook show_hook
Definition: guc_tables.h:207
int * variable
Definition: guc_tables.h:201
struct config_generic gen
Definition: guc_tables.h:199
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:8927
const char * name
Definition: encode.c:515
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8987
int reset_val
Definition: guc_tables.h:209

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

9236 {
9237  struct config_real *var;
9238 
9239  var = (struct config_real *)
9240  init_custom_variable(name, short_desc, long_desc, context, flags,
9241  PGC_REAL, sizeof(struct config_real));
9242  var->variable = valueAddr;
9243  var->boot_val = bootValue;
9244  var->reset_val = bootValue;
9245  var->min = minValue;
9246  var->max = maxValue;
9247  var->check_hook = check_hook;
9248  var->assign_hook = assign_hook;
9249  var->show_hook = show_hook;
9250  define_custom_variable(&var->gen);
9251 }
GucRealAssignHook assign_hook
Definition: guc_tables.h:222
double reset_val
Definition: guc_tables.h:225
GucRealCheckHook check_hook
Definition: guc_tables.h:221
GucShowHook show_hook
Definition: guc_tables.h:223
double * variable
Definition: guc_tables.h:217
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:8927
double max
Definition: guc_tables.h:220
double boot_val
Definition: guc_tables.h:218
const char * name
Definition: encode.c:515
double min
Definition: guc_tables.h:219
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8987
struct config_generic gen
Definition: guc_tables.h:215

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

9264 {
9265  struct config_string *var;
9266 
9267  var = (struct config_string *)
9268  init_custom_variable(name, short_desc, long_desc, context, flags,
9269  PGC_STRING, sizeof(struct config_string));
9270  var->variable = valueAddr;
9271  var->boot_val = bootValue;
9272  var->check_hook = check_hook;
9273  var->assign_hook = assign_hook;
9274  var->show_hook = show_hook;
9275  define_custom_variable(&var->gen);
9276 }
char ** variable
Definition: guc_tables.h:233
GucStringCheckHook check_hook
Definition: guc_tables.h:235
const char * boot_val
Definition: guc_tables.h:234
GucShowHook show_hook
Definition: guc_tables.h:237
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:8927
struct config_generic gen
Definition: guc_tables.h:231
GucStringAssignHook assign_hook
Definition: guc_tables.h:236
const char * name
Definition: encode.c:515
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8987

◆ EmitWarningsOnPlaceholders()

void EmitWarningsOnPlaceholders ( const char *  className)

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

9308 {
9309  int classLen = strlen(className);
9310  int i;
9311 
9312  for (i = 0; i < num_guc_variables; i++)
9313  {
9314  struct config_generic *var = guc_variables[i];
9315 
9316  if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
9317  strncmp(className, var->name, classLen) == 0 &&
9318  var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
9319  {
9320  ereport(WARNING,
9321  (errcode(ERRCODE_UNDEFINED_OBJECT),
9322  errmsg("unrecognized configuration parameter \"%s\"",
9323  var->name)));
9324  }
9325  }
9326 }
const char * name
Definition: guc_tables.h:149
int errcode(int sqlerrcode)
Definition: elog.c:698
#define GUC_QUALIFIER_SEPARATOR
Definition: guc.h:199
static int num_guc_variables
Definition: guc.c:5019
static struct config_generic ** guc_variables
Definition: guc.c:5016
#define WARNING
Definition: elog.h:40
#define ereport(elevel,...)
Definition: elog.h:157
#define GUC_CUSTOM_PLACEHOLDER
Definition: guc.h:211
int errmsg(const char *fmt,...)
Definition: elog.c:909
int i

◆ EstimateGUCStateSpace()

Size EstimateGUCStateSpace ( void  )

Definition at line 10602 of file guc.c.

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

Referenced by InitializeParallelDSM().

10603 {
10604  Size size;
10605  int i;
10606 
10607  /* Add space reqd for saving the data size of the guc state */
10608  size = sizeof(Size);
10609 
10610  /* Add up the space needed for each GUC variable */
10611  for (i = 0; i < num_guc_variables; i++)
10612  size = add_size(size,
10614 
10615  return size;
10616 }
static int num_guc_variables
Definition: guc.c:5019
static struct config_generic ** guc_variables
Definition: guc.c:5016
Size add_size(Size s1, Size s2)
Definition: shmem.c:502
size_t Size
Definition: c.h:540
static Size estimate_variable_size(struct config_generic *gconf)
Definition: guc.c:10503
int i

◆ ExecSetVariableStmt()

void ExecSetVariableStmt ( VariableSetStmt stmt,
bool  isTopLevel 
)

Definition at line 8715 of file guc.c.

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

Referenced by standard_ProcessUtility().

8716 {
8718 
8719  /*
8720  * Workers synchronize these parameters at the start of the parallel
8721  * operation; then, we block SET during the operation.
8722  */
8723  if (IsInParallelMode())
8724  ereport(ERROR,
8725  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
8726  errmsg("cannot set parameters during a parallel operation")));
8727 
8728  switch (stmt->kind)
8729  {
8730  case VAR_SET_VALUE:
8731  case VAR_SET_CURRENT:
8732  if (stmt->is_local)
8733  WarnNoTransactionBlock(isTopLevel, "SET LOCAL");
8734  (void) set_config_option(stmt->name,
8735  ExtractSetVariableArgs(stmt),
8737  PGC_S_SESSION,
8738  action, true, 0, false);
8739  break;
8740  case VAR_SET_MULTI:
8741 
8742  /*
8743  * Special-case SQL syntaxes. The TRANSACTION and SESSION
8744  * CHARACTERISTICS cases effectively set more than one variable
8745  * per statement. TRANSACTION SNAPSHOT only takes one argument,
8746  * but we put it here anyway since it's a special case and not
8747  * related to any GUC variable.
8748  */
8749  if (strcmp(stmt->name, "TRANSACTION") == 0)
8750  {
8751  ListCell *head;
8752 
8753  WarnNoTransactionBlock(isTopLevel, "SET TRANSACTION");
8754 
8755  foreach(head, stmt->args)
8756  {
8757  DefElem *item = (DefElem *) lfirst(head);
8758 
8759  if (strcmp(item->defname, "transaction_isolation") == 0)
8760  SetPGVariable("transaction_isolation",
8761  list_make1(item->arg), stmt->is_local);
8762  else if (strcmp(item->defname, "transaction_read_only") == 0)
8763  SetPGVariable("transaction_read_only",
8764  list_make1(item->arg), stmt->is_local);
8765  else if (strcmp(item->defname, "transaction_deferrable") == 0)
8766  SetPGVariable("transaction_deferrable",
8767  list_make1(item->arg), stmt->is_local);
8768  else
8769  elog(ERROR, "unexpected SET TRANSACTION element: %s",
8770  item->defname);
8771  }
8772  }
8773  else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
8774  {
8775  ListCell *head;
8776 
8777  foreach(head, stmt->args)
8778  {
8779  DefElem *item = (DefElem *) lfirst(head);
8780 
8781  if (strcmp(item->defname, "transaction_isolation") == 0)
8782  SetPGVariable("default_transaction_isolation",
8783  list_make1(item->arg), stmt->is_local);
8784  else if (strcmp(item->defname, "transaction_read_only") == 0)
8785  SetPGVariable("default_transaction_read_only",
8786  list_make1(item->arg), stmt->is_local);
8787  else if (strcmp(item->defname, "transaction_deferrable") == 0)
8788  SetPGVariable("default_transaction_deferrable",
8789  list_make1(item->arg), stmt->is_local);
8790  else
8791  elog(ERROR, "unexpected SET SESSION element: %s",
8792  item->defname);
8793  }
8794  }
8795  else if (strcmp(stmt->name, "TRANSACTION SNAPSHOT") == 0)
8796  {
8797  A_Const *con = linitial_node(A_Const, stmt->args);
8798 
8799  if (stmt->is_local)
8800  ereport(ERROR,
8801  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8802  errmsg("SET LOCAL TRANSACTION SNAPSHOT is not implemented")));
8803 
8804  WarnNoTransactionBlock(isTopLevel, "SET TRANSACTION");
8805  Assert(nodeTag(&con->val) == T_String);
8806  ImportSnapshot(strVal(&con->val));
8807  }
8808  else
8809  elog(ERROR, "unexpected SET MULTI element: %s",
8810  stmt->name);
8811  break;
8812  case VAR_SET_DEFAULT:
8813  if (stmt->is_local)
8814  WarnNoTransactionBlock(isTopLevel, "SET LOCAL");
8815  /* fall through */
8816  case VAR_RESET:
8817  if (strcmp(stmt->name, "transaction_isolation") == 0)
8818  WarnNoTransactionBlock(isTopLevel, "RESET TRANSACTION");
8819 
8820  (void) set_config_option(stmt->name,
8821  NULL,
8823  PGC_S_SESSION,
8824  action, true, 0, false);
8825  break;
8826  case VAR_RESET_ALL:
8827  ResetAllOptions();
8828  break;
8829  }
8830 }
void ImportSnapshot(const char *idstr)
Definition: snapmgr.c:1377
VariableSetKind kind
Definition: parsenodes.h:2120
void WarnNoTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3439
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:698
bool superuser(void)
Definition: superuser.c:46
#define linitial_node(type, l)
Definition: pg_list.h:177
GucAction
Definition: guc.h:191
#define list_make1(x1)
Definition: pg_list.h:206
bool IsInParallelMode(void)
Definition: xact.c:1012
#define ERROR
Definition: elog.h:46
Definition: guc.h:75
void ResetAllOptions(void)
Definition: guc.c:6017
Node * arg
Definition: parsenodes.h:747
#define ereport(elevel,...)
Definition: elog.h:157
#define Assert(condition)
Definition: c.h:804
#define lfirst(lc)
Definition: pg_list.h:169
#define nodeTag(nodeptr)
Definition: nodes.h:544
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define elog(elevel,...)
Definition: elog.h:232
char * defname
Definition: parsenodes.h:746
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
Definition: guc.c:8839
Value val
Definition: parsenodes.h:298
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:7312
void SetPGVariable(const char *name, List *args, bool is_local)
Definition: guc.c:8859

◆ ExtractSetVariableArgs()

char* ExtractSetVariableArgs ( VariableSetStmt stmt)

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

8840 {
8841  switch (stmt->kind)
8842  {
8843  case VAR_SET_VALUE:
8844  return flatten_set_variable_args(stmt->name, stmt->args);
8845  case VAR_SET_CURRENT:
8846  return GetConfigOptionByName(stmt->name, NULL, false);
8847  default:
8848  return NULL;
8849  }
8850 }
VariableSetKind kind
Definition: parsenodes.h:2120
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:9568
static char * flatten_set_variable_args(const char *name, List *args)
Definition: guc.c:8245

◆ FreeConfigVariables()

void FreeConfigVariables ( ConfigVariable list)

◆ GetConfigOption()

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

Definition at line 8127 of file guc.c.

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

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

8128 {
8129  struct config_generic *record;
8130  static char buffer[256];
8131 
8132  record = find_option(name, false, missing_ok, ERROR);
8133  if (record == NULL)
8134  return NULL;
8135  if (restrict_privileged &&
8136  (record->flags & GUC_SUPERUSER_ONLY) &&
8137  !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))
8138  ereport(ERROR,
8139  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
8140  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
8141  name)));
8142 
8143  switch (record->vartype)
8144  {
8145  case PGC_BOOL:
8146  return *((struct config_bool *) record)->variable ? "on" : "off";
8147 
8148  case PGC_INT:
8149  snprintf(buffer, sizeof(buffer), "%d",
8150  *((struct config_int *) record)->variable);
8151  return buffer;
8152 
8153  case PGC_REAL:
8154  snprintf(buffer, sizeof(buffer), "%g",
8155  *((struct config_real *) record)->variable);
8156  return buffer;
8157 
8158  case PGC_STRING:
8159  return *((struct config_string *) record)->variable;
8160 
8161  case PGC_ENUM:
8162  return config_enum_lookup_by_value((struct config_enum *) record,
8163  *((struct config_enum *) record)->variable);
8164  }
8165  return NULL;
8166 }
Oid GetUserId(void)
Definition: miscinit.c:478
int errcode(int sqlerrcode)
Definition: elog.c:698
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:7004
#define ERROR
Definition: elog.h:46
static struct config_generic * find_option(const char *name, bool create_placeholders, bool skip_errors, int elevel)
Definition: guc.c:5504
enum config_type vartype
Definition: guc_tables.h:156
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
#define ereport(elevel,...)
Definition: elog.h:157
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4869
const char * name
Definition: encode.c:515
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define snprintf
Definition: port.h:216

◆ GetConfigOptionByName()

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

Definition at line 9568 of file guc.c.

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

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

9569 {
9570  struct config_generic *record;
9571 
9572  record = find_option(name, false, missing_ok, ERROR);
9573  if (record == NULL)
9574  {
9575  if (varname)
9576  *varname = NULL;
9577  return NULL;
9578  }
9579 
9580  if ((record->flags & GUC_SUPERUSER_ONLY) &&
9581  !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))
9582  ereport(ERROR,
9583  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
9584  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
9585  name)));
9586 
9587  if (varname)
9588  *varname = record->name;
9589 
9590  return _ShowOption(record, true);
9591 }
static char * _ShowOption(struct config_generic *record, bool use_units)
Definition: guc.c:10121
Oid GetUserId(void)
Definition: miscinit.c:478
const char * name
Definition: guc_tables.h:149
int errcode(int sqlerrcode)
Definition: elog.c:698
#define ERROR
Definition: elog.h:46
static struct config_generic * find_option(const char *name, bool create_placeholders, bool skip_errors, int elevel)
Definition: guc.c:5504
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
#define ereport(elevel,...)
Definition: elog.h:157
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4869
const char * name
Definition: encode.c:515
int errmsg(const char *fmt,...)
Definition: elog.c:909

◆ GetConfigOptionByNum()

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

Definition at line 9598 of file guc.c.

References _, _ShowOption(), Assert, config_bool::boot_val, config_int::boot_val, config_real::boot_val, config_string::boot_val, config_enum::boot_val, config_enum_get_options(), config_enum_lookup_by_value(), config_generic::context, config_generic::flags, get_config_unit_name(), GetUserId(), config_generic::group, GUC_NO_SHOW_ALL, GUC_PENDING_RESTART, GUC_SUPERUSER_ONLY, is_member_of_role(), config_generic::long_desc, config_int::max, config_real::max, config_int::min, config_real::min, config_generic::name, PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_S_FILE, PGC_STRING, pstrdup(), config_bool::reset_val, config_int::reset_val, config_real::reset_val, config_string::reset_val, config_enum::reset_val, config_generic::short_desc, snprintf, config_generic::source, config_generic::sourcefile, config_generic::sourceline, config_generic::status, and config_generic::vartype.

Referenced by show_all_settings().

9599 {
9600  char buffer[256];
9601  struct config_generic *conf;
9602 
9603  /* check requested variable number valid */
9604  Assert((varnum >= 0) && (varnum < num_guc_variables));
9605 
9606  conf = guc_variables[varnum];
9607 
9608  if (noshow)
9609  {
9610  if ((conf->flags & GUC_NO_SHOW_ALL) ||
9611  ((conf->flags & GUC_SUPERUSER_ONLY) &&
9612  !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)))
9613  *noshow = true;
9614  else
9615  *noshow = false;
9616  }
9617 
9618  /* first get the generic attributes */
9619 
9620  /* name */
9621  values[0] = conf->name;
9622 
9623  /* setting: use _ShowOption in order to avoid duplicating the logic */
9624  values[1] = _ShowOption(conf, false);
9625 
9626  /* unit, if any (NULL is fine) */
9627  values[2] = get_config_unit_name(conf->flags);
9628 
9629  /* group */
9630  values[3] = _(config_group_names[conf->group]);
9631 
9632  /* short_desc */
9633  values[4] = _(conf->short_desc);
9634 
9635  /* extra_desc */
9636  values[5] = _(conf->long_desc);
9637 
9638  /* context */
9639  values[6] = GucContext_Names[conf->context];
9640 
9641  /* vartype */
9642  values[7] = config_type_names[conf->vartype];
9643 
9644  /* source */
9645  values[8] = GucSource_Names[conf->source];
9646 
9647  /* now get the type specific attributes */
9648  switch (conf->vartype)
9649  {
9650  case PGC_BOOL:
9651  {
9652  struct config_bool *lconf = (struct config_bool *) conf;
9653 
9654  /* min_val */
9655  values[9] = NULL;
9656 
9657  /* max_val */
9658  values[10] = NULL;
9659 
9660  /* enumvals */
9661  values[11] = NULL;
9662 
9663  /* boot_val */
9664  values[12] = pstrdup(lconf->boot_val ? "on" : "off");
9665 
9666  /* reset_val */
9667  values[13] = pstrdup(lconf->reset_val ? "on" : "off");
9668  }
9669  break;
9670 
9671  case PGC_INT:
9672  {
9673  struct config_int *lconf = (struct config_int *) conf;
9674 
9675  /* min_val */
9676  snprintf(buffer, sizeof(buffer), "%d", lconf->min);
9677  values[9] = pstrdup(buffer);
9678 
9679  /* max_val */
9680  snprintf(buffer, sizeof(buffer), "%d", lconf->max);
9681  values[10] = pstrdup(buffer);
9682 
9683  /* enumvals */
9684  values[11] = NULL;
9685 
9686  /* boot_val */
9687  snprintf(buffer, sizeof(buffer), "%d", lconf->boot_val);
9688  values[12] = pstrdup(buffer);
9689 
9690  /* reset_val */
9691  snprintf(buffer, sizeof(buffer), "%d", lconf->reset_val);
9692  values[13] = pstrdup(buffer);
9693  }
9694  break;
9695 
9696  case PGC_REAL:
9697  {
9698  struct config_real *lconf = (struct config_real *) conf;
9699 
9700  /* min_val */
9701  snprintf(buffer, sizeof(buffer), "%g", lconf->min);
9702  values[9] = pstrdup(buffer);
9703 
9704  /* max_val */
9705  snprintf(buffer, sizeof(buffer), "%g", lconf->max);
9706  values[10] = pstrdup(buffer);
9707 
9708  /* enumvals */
9709  values[11] = NULL;
9710 
9711  /* boot_val */
9712  snprintf(buffer, sizeof(buffer), "%g", lconf->boot_val);
9713  values[12] = pstrdup(buffer);
9714 
9715  /* reset_val */
9716  snprintf(buffer, sizeof(buffer), "%g", lconf->reset_val);
9717  values[13] = pstrdup(buffer);
9718  }
9719  break;
9720 
9721  case PGC_STRING:
9722  {
9723  struct config_string *lconf = (struct config_string *) conf;
9724 
9725  /* min_val */
9726  values[9] = NULL;
9727 
9728  /* max_val */
9729  values[10] = NULL;
9730 
9731  /* enumvals */
9732  values[11] = NULL;
9733 
9734  /* boot_val */
9735  if (lconf->boot_val == NULL)
9736  values[12] = NULL;
9737  else
9738  values[12] = pstrdup(lconf->boot_val);
9739 
9740  /* reset_val */
9741  if (lconf->reset_val == NULL)
9742  values[13] = NULL;
9743  else
9744  values[13] = pstrdup(lconf->reset_val);
9745  }
9746  break;
9747 
9748  case PGC_ENUM:
9749  {
9750  struct config_enum *lconf = (struct config_enum *) conf;
9751 
9752  /* min_val */
9753  values[9] = NULL;
9754 
9755  /* max_val */
9756  values[10] = NULL;
9757 
9758  /* enumvals */
9759 
9760  /*
9761  * NOTE! enumvals with double quotes in them are not
9762  * supported!
9763  */
9764  values[11] = config_enum_get_options((struct config_enum *) conf,
9765  "{\"", "\"}", "\",\"");
9766 
9767  /* boot_val */
9769  lconf->boot_val));
9770 
9771  /* reset_val */
9773  lconf->reset_val));
9774  }
9775  break;
9776 
9777  default:
9778  {
9779  /*
9780  * should never get here, but in case we do, set 'em to NULL
9781  */
9782 
9783  /* min_val */
9784  values[9] = NULL;
9785 
9786  /* max_val */
9787  values[10] = NULL;
9788 
9789  /* enumvals */
9790  values[11] = NULL;
9791 
9792  /* boot_val */
9793  values[12] = NULL;
9794 
9795  /* reset_val */
9796  values[13] = NULL;
9797  }
9798  break;
9799  }
9800 
9801  /*
9802  * If the setting came from a config file, set the source location. For
9803  * security reasons, we don't show source file/line number for
9804  * insufficiently-privileged users.
9805  */
9806  if (conf->source == PGC_S_FILE &&
9807  is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))
9808  {
9809  values[14] = conf->sourcefile;
9810  snprintf(buffer, sizeof(buffer), "%d", conf->sourceline);
9811  values[15] = pstrdup(buffer);
9812  }
9813  else
9814  {
9815  values[14] = NULL;
9816  values[15] = NULL;
9817  }
9818 
9819  values[16] = (conf->status & GUC_PENDING_RESTART) ? "t" : "f";
9820 }
GucSource source
Definition: guc_tables.h:158
static char * _ShowOption(struct config_generic *record, bool use_units)
Definition: guc.c:10121
const char * long_desc
Definition: guc_tables.h:153
double reset_val
Definition: guc_tables.h:225
Oid GetUserId(void)
Definition: miscinit.c:478
const char * name
Definition: guc_tables.h:149
const char *const config_type_names[]
Definition: guc.c:816
char * pstrdup(const char *in)
Definition: mcxt.c:1299
const char * short_desc
Definition: guc_tables.h:152
int boot_val
Definition: guc_tables.h:202
const char * boot_val
Definition: guc_tables.h:234
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:7004
#define GUC_NO_SHOW_ALL
Definition: guc.h:206
const char *const GucContext_Names[]
Definition: guc.c:657
const char *const config_group_names[]
Definition: guc.c:700
static int num_guc_variables
Definition: guc.c:5019
char * sourcefile
Definition: guc_tables.h:166
bool boot_val
Definition: guc_tables.h:188
static const char * get_config_unit_name(int flags)
Definition: guc.c:6795
static struct config_generic ** guc_variables
Definition: guc.c:5016
enum config_type vartype
Definition: guc_tables.h:156
double max
Definition: guc_tables.h:220
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4869
char * reset_val
Definition: guc_tables.h:239
double boot_val
Definition: guc_tables.h:218
#define Assert(condition)
Definition: c.h:804
#define GUC_PENDING_RESTART
Definition: guc_tables.h:177
double min
Definition: guc_tables.h:219
static Datum values[MAXATTR]
Definition: bootstrap.c:166
enum config_group group
Definition: guc_tables.h:151
bool reset_val
Definition: guc_tables.h:193
const char *const GucSource_Names[]
Definition: guc.c:676
#define snprintf
Definition: port.h:216
#define _(x)
Definition: elog.c:89
static char * config_enum_get_options(struct config_enum *record, const char *prefix, const char *suffix, const char *separator)
Definition: guc.c:7053
GucContext context
Definition: guc_tables.h:150
int reset_val
Definition: guc_tables.h:209

◆ GetConfigOptionFlags()

int GetConfigOptionFlags ( const char *  name,
bool  missing_ok 
)

Definition at line 8222 of file guc.c.

References ERROR, find_option(), and config_generic::flags.

Referenced by pg_get_functiondef().

8223 {
8224  struct config_generic *record;
8225 
8226  record = find_option(name, false, missing_ok, ERROR);
8227  if (record == NULL)
8228  return 0;
8229  return record->flags;
8230 }
#define ERROR
Definition: elog.h:46
static struct config_generic * find_option(const char *name, bool create_placeholders, bool skip_errors, int elevel)
Definition: guc.c:5504
const char * name
Definition: encode.c:515

◆ GetConfigOptionResetString()

const char* GetConfigOptionResetString ( const char *  name)

Definition at line 8176 of file guc.c.

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

Referenced by check_datestyle().

8177 {
8178  struct config_generic *record;
8179  static char buffer[256];
8180 
8181  record = find_option(name, false, false, ERROR);
8182  Assert(record != NULL);
8183  if ((record->flags & GUC_SUPERUSER_ONLY) &&
8184  !is_member_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS))
8185  ereport(ERROR,
8186  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
8187  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
8188  name)));
8189 
8190  switch (record->vartype)
8191  {
8192  case PGC_BOOL:
8193  return ((struct config_bool *) record)->reset_val ? "on" : "off";
8194 
8195  case PGC_INT:
8196  snprintf(buffer, sizeof(buffer), "%d",
8197  ((struct config_int *) record)->reset_val);
8198  return buffer;
8199 
8200  case PGC_REAL:
8201  snprintf(buffer, sizeof(buffer), "%g",
8202  ((struct config_real *) record)->reset_val);
8203  return buffer;
8204 
8205  case PGC_STRING:
8206  return ((struct config_string *) record)->reset_val;
8207 
8208  case PGC_ENUM:
8209  return config_enum_lookup_by_value((struct config_enum *) record,
8210  ((struct config_enum *) record)->reset_val);
8211  }
8212  return NULL;
8213 }
Oid GetUserId(void)
Definition: miscinit.c:478
int errcode(int sqlerrcode)
Definition: elog.c:698
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:7004
#define ERROR
Definition: elog.h:46
static struct config_generic * find_option(const char *name, bool create_placeholders, bool skip_errors, int elevel)
Definition: guc.c:5504
enum config_type vartype
Definition: guc_tables.h:156
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
#define ereport(elevel,...)
Definition: elog.h:157
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4869
#define Assert(condition)
Definition: c.h:804
const char * name
Definition: encode.c:515
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define snprintf
Definition: port.h:216

◆ GetNumConfigOptions()

int GetNumConfigOptions ( void  )

Definition at line 9826 of file guc.c.

References num_guc_variables.

Referenced by GucInfoMain(), and show_all_settings().

9827 {
9828  return num_guc_variables;
9829 }
static int num_guc_variables
Definition: guc.c:5019

◆ GetPGVariable()

void GetPGVariable ( const char *  name,
DestReceiver dest 
)

Definition at line 9333 of file guc.c.

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

Referenced by exec_replication_command(), and standard_ProcessUtility().

9334 {
9335  if (guc_name_compare(name, "all") == 0)
9336  ShowAllGUCConfig(dest);
9337  else
9338  ShowGUCConfigOption(name, dest);
9339 }
static void ShowGUCConfigOption(const char *name, DestReceiver *dest)
Definition: guc.c:9377
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:5585
static void ShowAllGUCConfig(DestReceiver *dest)
Definition: guc.c:9405
const char * name
Definition: encode.c:515

◆ GetPGVariableResultDesc()

TupleDesc GetPGVariableResultDesc ( const char *  name)

Definition at line 9342 of file guc.c.

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

Referenced by UtilityTupleDescriptor().

9343 {
9344  TupleDesc tupdesc;
9345 
9346  if (guc_name_compare(name, "all") == 0)
9347  {
9348  /* need a tuple descriptor representing three TEXT columns */
9349  tupdesc = CreateTemplateTupleDesc(3);
9350  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
9351  TEXTOID, -1, 0);
9352  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
9353  TEXTOID, -1, 0);
9354  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
9355  TEXTOID, -1, 0);
9356  }
9357  else
9358  {
9359  const char *varname;
9360 
9361  /* Get the canonical spelling of name */
9362  (void) GetConfigOptionByName(name, &varname, false);
9363 
9364  /* need a tuple descriptor representing a single TEXT column */
9365  tupdesc = CreateTemplateTupleDesc(1);
9366  TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
9367  TEXTOID, -1, 0);
9368  }
9369  return tupdesc;
9370 }
TupleDesc CreateTemplateTupleDesc(int natts)
Definition: tupdesc.c:45
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:5585
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:9568
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:580
const char * name
Definition: encode.c:515
int16 AttrNumber
Definition: attnum.h:21

◆ GUC_check_errcode()

void GUC_check_errcode ( int  sqlerrcode)

◆ GUCArrayAdd()

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

Definition at line 11099 of file guc.c.

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

Referenced by AlterSetting(), and update_proconfig_value().

11100 {
11101  struct config_generic *record;
11102  Datum datum;
11103  char *newval;
11104  ArrayType *a;
11105 
11106  Assert(name);
11107  Assert(value);
11108 
11109  /* test if the option is valid and we're allowed to set it */
11110  (void) validate_option_array_item(name, value, false);
11111 
11112  /* normalize name (converts obsolete GUC names to modern spellings) */
11113  record = find_option(name, false, true, WARNING);
11114  if (record)
11115  name = record->name;
11116 
11117  /* build new item for array */
11118  newval = psprintf("%s=%s", name, value);
11119  datum = CStringGetTextDatum(newval);
11120 
11121  if (array)
11122  {
11123  int index;
11124  bool isnull;
11125  int i;
11126 
11127  Assert(ARR_ELEMTYPE(array) == TEXTOID);
11128  Assert(ARR_NDIM(array) == 1);
11129  Assert(ARR_LBOUND(array)[0] == 1);
11130 
11131  index = ARR_DIMS(array)[0] + 1; /* add after end */
11132 
11133  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
11134  {
11135  Datum d;
11136  char *current;
11137 
11138  d = array_ref(array, 1, &i,
11139  -1 /* varlenarray */ ,
11140  -1 /* TEXT's typlen */ ,
11141  false /* TEXT's typbyval */ ,
11142  TYPALIGN_INT /* TEXT's typalign */ ,
11143  &isnull);
11144  if (isnull)
11145  continue;
11146  current = TextDatumGetCString(d);
11147 
11148  /* check for match up through and including '=' */
11149  if (strncmp(current, newval, strlen(name) + 1) == 0)
11150  {
11151  index = i;
11152  break;
11153  }
11154  }
11155 
11156  a = array_set(array, 1, &index,
11157  datum,
11158  false,
11159  -1 /* varlena array */ ,
11160  -1 /* TEXT's typlen */ ,
11161  false /* TEXT's typbyval */ ,
11162  TYPALIGN_INT /* TEXT's typalign */ );
11163  }
11164  else
11165  a = construct_array(&datum, 1,
11166  TEXTOID,
11167  -1, false, TYPALIGN_INT);
11168 
11169  return a;
11170 }
static struct @142 value
const char * name
Definition: guc_tables.h:149
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3318
ArrayType * array_set(ArrayType *array, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3120
#define ARR_LBOUND(a)
Definition: array.h:289
Definition: type.h:89
static bool validate_option_array_item(const char *name, const char *value, bool skipIfNoPermissions)
Definition: guc.c:11325
#define ARR_DIMS(a)
Definition: array.h:287
Datum array_ref(ArrayType *array, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:3103
static struct config_generic * find_option(const char *name, bool create_placeholders, bool skip_errors, int elevel)
Definition: guc.c:5504
#define WARNING
Definition: elog.h:40
#define TextDatumGetCString(d)
Definition: builtins.h:83
uintptr_t Datum
Definition: postgres.h:411
#define Assert(condition)
Definition: c.h:804
#define newval
#define ARR_NDIM(a)
Definition: array.h:283
const char * name
Definition: encode.c:515
int i
#define CStringGetTextDatum(s)
Definition: builtins.h:82
#define ARR_ELEMTYPE(a)
Definition: array.h:285

◆ GUCArrayDelete()

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

Definition at line 11179 of file guc.c.

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

Referenced by AlterSetting(), and update_proconfig_value().

11180 {
11181  struct config_generic *record;
11182  ArrayType *newarray;
11183  int i;
11184  int index;
11185 
11186  Assert(name);
11187 
11188  /* test if the option is valid and we're allowed to set it */
11189  (void) validate_option_array_item(name, NULL, false);
11190 
11191  /* normalize name (converts obsolete GUC names to modern spellings) */
11192  record = find_option(name, false, true, WARNING);
11193  if (record)
11194  name = record->name;
11195 
11196  /* if array is currently null, then surely nothing to delete */
11197  if (!array)
11198  return NULL;
11199 
11200  newarray = NULL;
11201  index = 1;
11202 
11203  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
11204  {
11205  Datum d;
11206  char *val;
11207  bool isnull;
11208 
11209  d = array_ref(array, 1, &i,
11210  -1 /* varlenarray */ ,
11211  -1 /* TEXT's typlen */ ,
11212  false /* TEXT's typbyval */ ,
11213  TYPALIGN_INT /* TEXT's typalign */ ,
11214  &isnull);
11215  if (isnull)
11216  continue;
11217  val = TextDatumGetCString(d);
11218 
11219  /* ignore entry if it's what we want to delete */
11220  if (strncmp(val, name, strlen(name)) == 0
11221  && val[strlen(name)] == '=')
11222  continue;
11223 
11224  /* else add it to the output array */
11225  if (newarray)
11226  newarray = array_set(newarray, 1, &index,
11227  d,
11228  false,
11229  -1 /* varlenarray */ ,
11230  -1 /* TEXT's typlen */ ,
11231  false /* TEXT's typbyval */ ,
11232  TYPALIGN_INT /* TEXT's typalign */ );
11233  else
11234  newarray = construct_array(&d, 1,
11235  TEXTOID,
11236  -1, false, TYPALIGN_INT);
11237 
11238  index++;
11239  }
11240 
11241  return newarray;
11242 }
const char * name
Definition: guc_tables.h:149
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3318
ArrayType * array_set(ArrayType *array, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3120
Definition: type.h:89
static bool validate_option_array_item(const char *name, const char *value, bool skipIfNoPermissions)
Definition: guc.c:11325
#define ARR_DIMS(a)
Definition: array.h:287
Datum array_ref(ArrayType *array, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:3103
static struct config_generic * find_option(const char *name, bool create_placeholders, bool skip_errors, int elevel)
Definition: guc.c:5504
#define WARNING
Definition: elog.h:40
#define TextDatumGetCString(d)
Definition: builtins.h:83
uintptr_t Datum
Definition: postgres.h:411
#define Assert(condition)
Definition: c.h:804
const char * name
Definition: encode.c:515
int i
long val
Definition: informix.c:664

◆ GUCArrayReset()

ArrayType* GUCArrayReset ( ArrayType array)

Definition at line 11251 of file guc.c.

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

Referenced by AlterSetting().

11252 {
11253  ArrayType *newarray;
11254  int i;
11255  int index;
11256 
11257  /* if array is currently null, nothing to do */
11258  if (!array)
11259  return NULL;
11260 
11261  /* if we're superuser, we can delete everything, so just do it */
11262  if (superuser())
11263  return NULL;
11264 
11265  newarray = NULL;
11266  index = 1;
11267 
11268  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
11269  {
11270  Datum d;
11271  char *val;
11272  char *eqsgn;
11273  bool isnull;
11274 
11275  d = array_ref(array, 1, &i,
11276  -1 /* varlenarray */ ,
11277  -1 /* TEXT's typlen */ ,
11278  false /* TEXT's typbyval */ ,
11279  TYPALIGN_INT /* TEXT's typalign */ ,
11280  &isnull);
11281  if (isnull)
11282  continue;
11283  val = TextDatumGetCString(d);
11284 
11285  eqsgn = strchr(val, '=');
11286  *eqsgn = '\0';
11287 
11288  /* skip if we have permission to delete it */
11289  if (validate_option_array_item(val, NULL, true))
11290  continue;
11291 
11292  /* else add it to the output array */
11293  if (newarray)
11294  newarray = array_set(newarray, 1, &index,
11295  d,
11296  false,
11297  -1 /* varlenarray */ ,
11298  -1 /* TEXT's typlen */ ,
11299  false /* TEXT's typbyval */ ,
11300  TYPALIGN_INT /* TEXT's typalign */ );
11301  else
11302  newarray = construct_array(&d, 1,
11303  TEXTOID,
11304  -1, false, TYPALIGN_INT);
11305 
11306  index++;
11307  pfree(val);
11308  }
11309 
11310  return newarray;
11311 }
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3318
bool superuser(void)
Definition: superuser.c:46
ArrayType * array_set(ArrayType *array, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3120
Definition: type.h:89
void pfree(void *pointer)
Definition: mcxt.c:1169
static bool validate_option_array_item(const char *name, const char *value, bool skipIfNoPermissions)
Definition: guc.c:11325
#define ARR_DIMS(a)
Definition: array.h:287
Datum array_ref(ArrayType *array, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:3103
#define TextDatumGetCString(d)
Definition: builtins.h:83
uintptr_t Datum
Definition: postgres.h:411
int i
long val
Definition: informix.c:664

◆ InitializeGUCOptions()

void InitializeGUCOptions ( void  )

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

5620 {
5621  int i;
5622 
5623  /*
5624  * Before log_line_prefix could possibly receive a nonempty setting, make
5625  * sure that timezone processing is minimally alive (see elog.c).
5626  */
5628 
5629  /*
5630  * Build sorted array of all GUC variables.
5631  */
5633 
5634  /*
5635  * Load all variables with their compiled-in defaults, and initialize
5636  * status fields as needed.
5637  */
5638  for (i = 0; i < num_guc_variables; i++)
5639  {
5641  }
5642 
5643  guc_dirty = false;
5644 
5645  reporting_enabled = false;
5646 
5647  /*
5648  * Prevent any attempt to override the transaction modes from
5649  * non-interactive sources.
5650  */
5651  SetConfigOption("transaction_isolation", "read committed",
5653  SetConfigOption("transaction_read_only", "no",
5655  SetConfigOption("transaction_deferrable", "no",
5657 
5658  /*
5659  * For historical reasons, some GUC parameters can receive defaults from
5660  * environment variables. Process those settings.
5661  */
5663 }
void build_guc_variables(void)
Definition: guc.c:5282
static void InitializeGUCOptionsFromEnvironment(void)
Definition: guc.c:5675
void pg_timezone_initialize(void)
Definition: pgtz.c:361
static int num_guc_variables
Definition: guc.c:5019
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:8103
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:5721
static struct config_generic ** guc_variables
Definition: guc.c:5016
int i
static bool reporting_enabled
Definition: guc.c:5027
static bool guc_dirty
Definition: guc.c:5025

◆ NewGUCNestLevel()

◆ parse_int()

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

Definition at line 6852 of file guc.c.

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

Referenced by parse_and_validate_value(), and parse_one_reloption().

6853 {
6854  /*
6855  * We assume here that double is wide enough to represent any integer
6856  * value with adequate precision.
6857  */
6858  double val;
6859  char *endptr;
6860 
6861  /* To suppress compiler warnings, always set output params */
6862  if (result)
6863  *result = 0;
6864  if (hintmsg)
6865  *hintmsg = NULL;
6866 
6867  /*
6868  * Try to parse as an integer (allowing octal or hex input). If the
6869  * conversion stops at a decimal point or 'e', or overflows, re-parse as
6870  * float. This should work fine as long as we have no unit names starting
6871  * with 'e'. If we ever do, the test could be extended to check for a
6872  * sign or digit after 'e', but for now that's unnecessary.
6873  */
6874  errno = 0;
6875  val = strtol(value, &endptr, 0);
6876  if (*endptr == '.' || *endptr == 'e' || *endptr == 'E' ||
6877  errno == ERANGE)
6878  {
6879  errno = 0;
6880  val = strtod(value, &endptr);
6881  }
6882 
6883  if (endptr == value || errno == ERANGE)
6884  return false; /* no HINT for these cases */
6885 
6886  /* reject NaN (infinities will fail range check below) */
6887  if (isnan(val))
6888  return false; /* treat same as syntax error; no HINT */
6889 
6890  /* allow whitespace between number and unit */
6891  while (isspace((unsigned char) *endptr))
6892  endptr++;
6893 
6894  /* Handle possible unit */
6895  if (*endptr != '\0')
6896  {
6897  if ((flags & GUC_UNIT) == 0)
6898  return false; /* this setting does not accept a unit */
6899 
6900  if (!convert_to_base_unit(val,
6901  endptr, (flags & GUC_UNIT),
6902  &val))
6903  {
6904  /* invalid unit, or garbage after the unit; set hint and fail. */
6905  if (hintmsg)
6906  {
6907  if (flags & GUC_UNIT_MEMORY)
6908  *hintmsg = memory_units_hint;
6909  else
6910  *hintmsg = time_units_hint;
6911  }
6912  return false;
6913  }
6914  }
6915 
6916  /* Round to int, then check for overflow */
6917  val = rint(val);
6918 
6919  if (val > INT_MAX || val < INT_MIN)
6920  {
6921  if (hintmsg)
6922  *hintmsg = gettext_noop("Value exceeds integer range.");
6923  return false;
6924  }
6925 
6926  if (result)
6927  *result = (int) val;
6928  return true;
6929 }
static struct @142 value
#define gettext_noop(x)
Definition: c.h:1197
#define GUC_UNIT
Definition: guc.h:232
static const char * time_units_hint
Definition: guc.c:898
static bool convert_to_base_unit(double value, const char *unit, int base_unit, double *base_value)
Definition: guc.c:6652
long val
Definition: informix.c:664
static const char * memory_units_hint
Definition: guc.c:861
#define GUC_UNIT_MEMORY
Definition: guc.h:223

◆ parse_real()

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

Definition at line 6942 of file guc.c.

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

Referenced by parse_and_validate_value(), and parse_one_reloption().

6943 {
6944  double val;
6945  char *endptr;
6946 
6947  /* To suppress compiler warnings, always set output params */
6948  if (result)
6949  *result = 0;
6950  if (hintmsg)
6951  *hintmsg = NULL;
6952 
6953  errno = 0;
6954  val = strtod(value, &endptr);
6955 
6956  if (endptr == value || errno == ERANGE)
6957  return false; /* no HINT for these cases */
6958 
6959  /* reject NaN (infinities will fail range checks later) */
6960  if (isnan(val))
6961  return false; /* treat same as syntax error; no HINT */
6962 
6963  /* allow whitespace between number and unit */
6964  while (isspace((unsigned char) *endptr))
6965  endptr++;
6966 
6967  /* Handle possible unit */
6968  if (*endptr != '\0')
6969  {
6970  if ((flags & GUC_UNIT) == 0)
6971  return false; /* this setting does not accept a unit */
6972 
6973  if (!convert_to_base_unit(val,
6974  endptr, (flags & GUC_UNIT),
6975  &val))
6976  {
6977  /* invalid unit, or garbage after the unit; set hint and fail. */
6978  if (hintmsg)
6979  {
6980  if (flags & GUC_UNIT_MEMORY)
6981  *hintmsg = memory_units_hint;
6982  else
6983  *hintmsg = time_units_hint;
6984  }
6985  return false;
6986  }
6987  }
6988 
6989  if (result)
6990  *result = val;
6991  return true;
6992 }
static struct @142 value
#define GUC_UNIT
Definition: guc.h:232
static const char * time_units_hint
Definition: guc.c:898
static bool convert_to_base_unit(double value, const char *unit, int base_unit, double *base_value)
Definition: guc.c:6652
long val
Definition: informix.c:664
static const char * memory_units_hint
Definition: guc.c:861
#define GUC_UNIT_MEMORY
Definition: guc.h:223

◆ ParseConfigDirectory()

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

◆ ParseConfigFile()

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

◆ ParseConfigFp()

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

◆ ParseLongOption()

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

Definition at line 10996 of file guc.c.

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

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

10997 {
10998  size_t equal_pos;
10999  char *cp;
11000 
11001  AssertArg(string);
11002  AssertArg(name);
11003  AssertArg(value);
11004 
11005  equal_pos = strcspn(string, "=");
11006 
11007  if (string[equal_pos] == '=')
11008  {
11009  *name = guc_malloc(FATAL, equal_pos + 1);
11010  strlcpy(*name, string, equal_pos + 1);
11011 
11012  *value = guc_strdup(FATAL, &string[equal_pos + 1]);
11013  }
11014  else
11015  {
11016  /* no equal sign in string */
11017  *name = guc_strdup(FATAL, string);
11018  *value = NULL;
11019  }
11020 
11021  for (cp = *name; *cp; cp++)
11022  if (*cp == '-')
11023  *cp = '_';
11024 }
static struct @142 value
static char * guc_strdup(int elevel, const char *src)
Definition: guc.c:5091
#define FATAL
Definition: elog.h:49
#define AssertArg(condition)
Definition: c.h:806
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
const char * name
Definition: encode.c:515
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:5059

◆ ProcessConfigFile()

◆ ProcessGUCArray()

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

Definition at line 11034 of file guc.c.

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

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

11036 {
11037  int i;
11038 
11039  Assert(array != NULL);
11040  Assert(ARR_ELEMTYPE(array) == TEXTOID);
11041  Assert(ARR_NDIM(array) == 1);
11042  Assert(ARR_LBOUND(array)[0] == 1);
11043 
11044  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
11045  {
11046  Datum d;
11047  bool isnull;
11048  char *s;
11049  char *name;
11050  char *value;
11051  char *namecopy;
11052  char *valuecopy;
11053 
11054  d = array_ref(array, 1, &i,
11055  -1 /* varlenarray */ ,
11056  -1 /* TEXT's typlen */ ,
11057  false /* TEXT's typbyval */ ,
11058  TYPALIGN_INT /* TEXT's typalign */ ,
11059  &isnull);
11060 
11061  if (isnull)
11062  continue;
11063 
11064  s = TextDatumGetCString(d);
11065 
11066  ParseLongOption(s, &name, &value);
11067  if (!value)
11068  {
11069  ereport(WARNING,
11070  (errcode(ERRCODE_SYNTAX_ERROR),
11071  errmsg("could not parse setting for parameter \"%s\"",
11072  name)));
11073  free(name);
11074  continue;
11075  }
11076 
11077  /* free malloc'd strings immediately to avoid leak upon error */
11078  namecopy = pstrdup(name);
11079  free(name);
11080  valuecopy = pstrdup(value);
11081  free(value);
11082 
11083  (void) set_config_option(namecopy, valuecopy,
11084  context, source,
11085  action, true, 0, false);
11086 
11087  pfree(namecopy);
11088  pfree(valuecopy);
11089  pfree(s);
11090  }
11091 }
static struct @142 value
char * pstrdup(const char *in)
Definition: mcxt.c:1299
void ParseLongOption(const char *string, char **name, char **value)
Definition: guc.c:10996
int errcode(int sqlerrcode)
Definition: elog.c:698
#define ARR_LBOUND(a)
Definition: array.h:289
void pfree(void *pointer)
Definition: mcxt.c:1169
#define ARR_DIMS(a)
Definition: array.h:287
Datum array_ref(ArrayType *array, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:3103
#define WARNING
Definition: elog.h:40
#define TextDatumGetCString(d)
Definition: builtins.h:83
uintptr_t Datum
Definition: postgres.h:411
#define ereport(elevel,...)
Definition: elog.h:157
#define free(a)
Definition: header.h:65
#define Assert(condition)
Definition: c.h:804
static rewind_source * source
Definition: pg_rewind.c:79
#define ARR_NDIM(a)
Definition: array.h:283
const char * name
Definition: encode.c:515
int errmsg(const char *fmt,...)
Definition: elog.c:909
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:7312
#define ARR_ELEMTYPE(a)
Definition: array.h:285
GucContext context
Definition: guc_tables.h:150

◆ ReportChangedGUCOptions()

void ReportChangedGUCOptions ( void  )

Definition at line 6566 of file guc.c.

References Assert, ERROR, find_option(), config_generic::flags, GUC_NEEDS_REPORT, GUC_REPORT, i, num_guc_variables, RecoveryInProgress(), ReportGUCOption(), and config_generic::status.

Referenced by PostgresMain().

6567 {
6568  /* Quick exit if not (yet) enabled */
6569  if (!reporting_enabled)
6570  return;
6571 
6572  /*
6573  * Since in_hot_standby isn't actually changed by normal GUC actions, we
6574  * need a hack to check whether a new value needs to be reported to the
6575  * client. For speed, we rely on the assumption that it can never
6576  * transition from false to true.
6577  */
6579  {
6580  struct config_generic *record;
6581 
6582  record = find_option("in_hot_standby", false, false, ERROR);
6583  Assert(record != NULL);
6584  record->status |= GUC_NEEDS_REPORT;
6585  report_needed = true;
6586  in_hot_standby = false;
6587  }
6588 
6589  /* Quick exit if no values have been changed */
6590  if (!report_needed)
6591  return;
6592 
6593  /* Transmit new values of interesting variables */
6594  for (int i = 0; i < num_guc_variables; i++)
6595  {
6596  struct config_generic *conf = guc_variables[i];
6597 
6598  if ((conf->flags & GUC_REPORT) && (conf->status & GUC_NEEDS_REPORT))
6599  ReportGUCOption(conf);
6600  }
6601 
6602  report_needed = false;
6603 }
static bool report_needed
Definition: guc.c:5029
static bool in_hot_standby
Definition: guc.c:640
bool RecoveryInProgress(void)
Definition: xlog.c:8237
#define ERROR
Definition: elog.h:46
static int num_guc_variables
Definition: guc.c:5019
#define GUC_REPORT
Definition: guc.h:208
static struct config_generic * find_option(const char *name, bool create_placeholders, bool skip_errors, int elevel)
Definition: guc.c:5504
static struct config_generic ** guc_variables
Definition: guc.c:5016
#define Assert(condition)
Definition: c.h:804
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:6612
static bool reporting_enabled
Definition: guc.c:5027
#define GUC_NEEDS_REPORT
Definition: guc_tables.h:178

◆ ResetAllOptions()

void ResetAllOptions ( void  )

Definition at line 6017 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_NEEDS_REPORT, 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(), 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_generic::status, config_bool::variable, config_int::variable, config_real::variable, config_string::variable, config_enum::variable, and config_generic::vartype.

Referenced by DiscardAll(), and ExecSetVariableStmt().

6018 {
6019  int i;
6020 
6021  for (i = 0; i < num_guc_variables; i++)
6022  {
6023  struct config_generic *gconf = guc_variables[i];
6024 
6025  /* Don't reset non-SET-able values */
6026  if (gconf->context != PGC_SUSET &&
6027  gconf->context != PGC_USERSET)
6028  continue;
6029  /* Don't reset if special exclusion from RESET ALL */
6030  if (gconf->flags & GUC_NO_RESET_ALL)
6031  continue;
6032  /* No need to reset if wasn't SET */
6033  if (gconf->source <= PGC_S_OVERRIDE)
6034  continue;
6035 
6036  /* Save old value to support transaction abort */
6038 
6039  switch (gconf->vartype)
6040  {
6041  case PGC_BOOL:
6042  {
6043  struct config_bool *conf = (struct config_bool *) gconf;
6044 
6045  if (conf->assign_hook)
6046  conf->assign_hook(conf->reset_val,
6047  conf->reset_extra);
6048  *conf->variable = conf->reset_val;
6049  set_extra_field(&conf->gen, &conf->gen.extra,
6050  conf->reset_extra);
6051  break;
6052  }
6053  case PGC_INT:
6054  {
6055  struct config_int *conf = (struct config_int *) gconf;
6056 
6057  if (conf->assign_hook)
6058  conf->assign_hook(conf->reset_val,
6059  conf->reset_extra);
6060  *conf->variable = conf->reset_val;
6061  set_extra_field(&conf->gen, &conf->gen.extra,
6062  conf->reset_extra);
6063  break;
6064  }
6065  case PGC_REAL:
6066  {
6067  struct config_real *conf = (struct config_real *) gconf;
6068 
6069  if (conf->assign_hook)
6070  conf->assign_hook(conf->reset_val,
6071  conf->reset_extra);
6072  *conf->variable = conf->reset_val;
6073  set_extra_field(&conf->gen, &conf->gen.extra,
6074  conf->reset_extra);
6075  break;
6076  }
6077  case PGC_STRING:
6078  {
6079  struct config_string *conf = (struct config_string *) gconf;
6080 
6081  if (conf->assign_hook)
6082  conf->assign_hook(conf->reset_val,
6083  conf->reset_extra);
6084  set_string_field(conf, conf->variable, conf->reset_val);
6085  set_extra_field(&conf->gen, &conf->gen.extra,
6086  conf->reset_extra);
6087  break;
6088  }
6089  case PGC_ENUM:
6090  {
6091  struct config_enum *conf = (struct config_enum *) gconf;
6092 
6093  if (conf->assign_hook)
6094  conf->assign_hook(conf->reset_val,
6095  conf->reset_extra);
6096  *conf->variable = conf->reset_val;
6097  set_extra_field(&conf->gen, &conf->gen.extra,
6098  conf->reset_extra);
6099  break;
6100  }
6101  }
6102 
6103  gconf->source = gconf->reset_source;
6104  gconf->scontext = gconf->reset_scontext;
6105 
6106  if (gconf->flags & GUC_REPORT)
6107  {
6108  gconf->status |= GUC_NEEDS_REPORT;
6109  report_needed = true;
6110  }
6111  }
6112 }
GucSource source
Definition: guc_tables.h:158
void * reset_extra
Definition: guc_tables.h:210
static bool report_needed
Definition: guc.c:5029
GucRealAssignHook assign_hook
Definition: guc_tables.h:222
double reset_val
Definition: guc_tables.h:225
#define GUC_NO_RESET_ALL
Definition: guc.h:207
char ** variable
Definition: guc_tables.h:233
bool * variable
Definition: guc_tables.h:187
GucEnumAssignHook assign_hook
Definition: guc_tables.h:251
GucBoolAssignHook assign_hook
Definition: guc_tables.h:190
GucContext scontext
Definition: guc_tables.h:160
GucIntAssignHook assign_hook
Definition: guc_tables.h:206
static void push_old_value(struct config_generic *gconf, GucAction action)
Definition: guc.c:6120
int * variable
Definition: guc_tables.h:201
int * variable
Definition: guc_tables.h:247
static int num_guc_variables
Definition: guc.c:5019
void * reset_extra
Definition: guc_tables.h:255
Definition: guc.h:75
static void set_extra_field(struct config_generic *gconf, void **field, void *newval)
Definition: guc.c:5192
GucSource reset_source
Definition: guc_tables.h:159
struct config_generic gen
Definition: guc_tables.h:185
struct config_generic gen
Definition: guc_tables.h:199
#define GUC_REPORT
Definition: guc.h:208
double * variable
Definition: guc_tables.h:217
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:5131
static struct config_generic ** guc_variables
Definition: guc.c:5016
enum config_type vartype
Definition: guc_tables.h:156
void * reset_extra
Definition: guc_tables.h:226
struct config_generic gen
Definition: guc_tables.h:245
struct config_generic gen
Definition: guc_tables.h:231
char * reset_val
Definition: guc_tables.h:239
GucStringAssignHook assign_hook
Definition: guc_tables.h:236
void * reset_extra
Definition: guc_tables.h:240
void * reset_extra
Definition: guc_tables.h:194
int i
bool reset_val
Definition: guc_tables.h:193
#define GUC_NEEDS_REPORT
Definition: guc_tables.h:178
GucContext context
Definition: guc_tables.h:150
struct config_generic gen
Definition: guc_tables.h:215
GucContext reset_scontext
Definition: guc_tables.h:161
int reset_val
Definition: guc_tables.h:209

◆ RestoreGUCState()

void RestoreGUCState ( void *  gucstate)

Definition at line 10831 of file guc.c.

References ErrorContextCallback::arg, Assert, ErrorContextCallback::callback, can_skip_gucvar(), ereport, errcode(), errmsg(), ERROR, error_context_stack, config_generic::extra, free, GUC_ACTION_SET, guc_restore_error_context_callback(), i, InitializeOneGUCOption(), config_generic::last_reported, num_guc_variables, PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_STRING, ErrorContextCallback::previous, read_gucstate(), read_gucstate_binary(), config_bool::reset_extra, config_int::reset_extra, config_real::reset_extra, config_string::reset_extra, config_enum::reset_extra, config_string::reset_val, set_config_option(), set_config_sourcefile(), config_generic::sourcefile, config_generic::stack, config_string::variable, and config_generic::vartype.

Referenced by ParallelWorkerMain().

10832 {
10833  char *varname,
10834  *varvalue,
10835  *varsourcefile;
10836  int varsourceline;
10837  GucSource varsource;
10838  GucContext varscontext;
10839  char *srcptr = (char *) gucstate;
10840  char *srcend;
10841  Size len;
10842  int i;
10843  ErrorContextCallback error_context_callback;
10844 
10845  /*
10846  * First, ensure that all potentially-shippable GUCs are reset to their
10847  * default values. We must not touch those GUCs that the leader will
10848  * never ship, while there is no need to touch those that are shippable
10849  * but already have their default values. Thus, this ends up being the
10850  * same test that SerializeGUCState uses, even though the sets of
10851  * variables involved may well be different since the leader's set of
10852  * variables-not-at-default-values can differ from the set that are
10853  * not-default in this freshly started worker.
10854  *
10855  * Once we have set all the potentially-shippable GUCs to default values,
10856  * restoring the GUCs that the leader sent (because they had non-default
10857  * values over there) leads us to exactly the set of GUC values that the
10858  * leader has. This is true even though the worker may have initially
10859  * absorbed postgresql.conf settings that the leader hasn't yet seen, or
10860  * ALTER USER/DATABASE SET settings that were established after the leader
10861  * started.
10862  *
10863  * Note that ensuring all the potential target GUCs are at PGC_S_DEFAULT
10864  * also ensures that set_config_option won't refuse to set them because of
10865  * source-priority comparisons.
10866  */
10867  for (i = 0; i < num_guc_variables; i++)
10868  {
10869  struct config_generic *gconf = guc_variables[i];
10870 
10871  /* Do nothing if non-shippable or if already at PGC_S_DEFAULT. */
10872  if (can_skip_gucvar(gconf))
10873  continue;
10874 
10875  /*
10876  * We can use InitializeOneGUCOption to reset the GUC to default, but
10877  * first we must free any existing subsidiary data to avoid leaking
10878  * memory. The stack must be empty, but we have to clean up all other
10879  * fields. Beware that there might be duplicate value or "extra"
10880  * pointers.
10881  */
10882  Assert(gconf->stack == NULL);
10883  if (gconf->extra)
10884  free(gconf->extra);
10885  if (gconf->last_reported) /* probably can't happen */
10886  free(gconf->last_reported);
10887  if (gconf->sourcefile)
10888  free(gconf->sourcefile);
10889  switch (gconf->vartype)
10890  {
10891  case PGC_BOOL:
10892  {
10893  struct config_bool *conf = (struct config_bool *) gconf;
10894 
10895  if (conf->reset_extra && conf->reset_extra != gconf->extra)
10896  free(conf->reset_extra);
10897  break;
10898  }
10899  case PGC_INT:
10900  {
10901  struct config_int *conf = (struct config_int *) gconf;
10902 
10903  if (conf->reset_extra && conf->reset_extra != gconf->extra)
10904  free(conf->reset_extra);
10905  break;
10906  }
10907  case PGC_REAL:
10908  {
10909  struct config_real *conf = (struct config_real *) gconf;
10910 
10911  if (conf->reset_extra && conf->reset_extra != gconf->extra)
10912  free(conf->reset_extra);
10913  break;
10914  }
10915  case PGC_STRING:
10916  {
10917  struct config_string *conf = (struct config_string *) gconf;
10918 
10919  if (*conf->variable)
10920  free(*conf->variable);
10921  if (conf->reset_val && conf->reset_val != *conf->variable)
10922  free(conf->reset_val);
10923  if (conf->reset_extra && conf->reset_extra != gconf->extra)
10924  free(conf->reset_extra);
10925  break;
10926  }
10927  case PGC_ENUM:
10928  {
10929  struct config_enum *conf = (struct config_enum *) gconf;
10930 
10931  if (conf->reset_extra && conf->reset_extra != gconf->extra)
10932  free(conf->reset_extra);
10933  break;
10934  }
10935  }
10936  /* Now we can reset the struct to PGS_S_DEFAULT state. */
10937  InitializeOneGUCOption(gconf);
10938  }
10939 
10940  /* First item is the length of the subsequent data */
10941  memcpy(&len, gucstate, sizeof(len));
10942 
10943  srcptr += sizeof(len);
10944  srcend = srcptr + len;
10945 
10946  /* If the GUC value check fails, we want errors to show useful context. */
10947  error_context_callback.callback = guc_restore_error_context_callback;
10948  error_context_callback.previous = error_context_stack;
10949  error_context_callback.arg = NULL;
10950  error_context_stack = &error_context_callback;
10951 
10952  /* Restore all the listed GUCs. */
10953  while (srcptr < srcend)
10954  {
10955  int result;
10956  char *error_context_name_and_value[2];
10957 
10958  varname = read_gucstate(&srcptr, srcend);
10959  varvalue = read_gucstate(&srcptr, srcend);
10960  varsourcefile = read_gucstate(&srcptr, srcend);
10961  if (varsourcefile[0])
10962  read_gucstate_binary(&srcptr, srcend,
10963  &varsourceline, sizeof(varsourceline));
10964  else
10965  varsourceline = 0;
10966  read_gucstate_binary(&srcptr, srcend,
10967  &varsource, sizeof(varsource));
10968  read_gucstate_binary(&srcptr, srcend,
10969  &varscontext, sizeof(varscontext));
10970 
10971  error_context_name_and_value[0] = varname;
10972  error_context_name_and_value[1] = varvalue;
10973  error_context_callback.arg = &error_context_name_and_value[0];
10974  result = set_config_option(varname, varvalue, varscontext, varsource,
10975  GUC_ACTION_SET, true, ERROR, true);
10976  if (result <= 0)
10977  ereport(ERROR,
10978  (errcode(ERRCODE_INTERNAL_ERROR),
10979  errmsg("parameter \"%s\" could not be set", varname)));
10980  if (varsourcefile[0])
10981  set_config_sourcefile(varname, varsourcefile, varsourceline);
10982  error_context_callback.arg = NULL;
10983  }
10984 
10985  error_context_stack = error_context_callback.previous;
10986 }
void * reset_extra
Definition: guc_tables.h:210
GucContext
Definition: guc.h:68
static void static void set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
Definition: guc.c:8069
char ** variable
Definition: guc_tables.h:233
static void read_gucstate_binary(char **srcptr, char *srcend, void *dest, Size size)
Definition: guc.c:10795
int errcode(int sqlerrcode)
Definition: elog.c:698
void(* callback)(void *arg)
Definition: elog.h:247
struct ErrorContextCallback * previous
Definition: elog.h:246
GucSource
Definition: guc.h:104
ErrorContextCallback * error_context_stack
Definition: elog.c:93
#define ERROR
Definition: elog.h:46
static int num_guc_variables
Definition: guc.c:5019
void * reset_extra
Definition: guc_tables.h:255
char * sourcefile
Definition: guc_tables.h:166
static bool can_skip_gucvar(struct config_generic *gconf)
Definition: guc.c:10463
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:5721
static void guc_restore_error_context_callback(void *arg)
Definition: guc.c:10809
static struct config_generic ** guc_variables
Definition: guc.c:5016
enum config_type vartype
Definition: guc_tables.h:156
void * reset_extra
Definition: guc_tables.h:226
static char * read_gucstate(char **srcptr, char *srcend)
Definition: guc.c:10772
#define ereport(elevel,...)
Definition: elog.h:157
char * last_reported
Definition: guc_tables.h:164
#define free(a)
Definition: header.h:65
char * reset_val
Definition: guc_tables.h:239
#define Assert(condition)
Definition: c.h:804
size_t Size
Definition: c.h:540
void * reset_extra
Definition: guc_tables.h:240
int errmsg(const char *fmt,...)
Definition: elog.c:909
void * reset_extra
Definition: guc_tables.h:194
int i
GucStack * stack
Definition: guc_tables.h:162
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:7312

◆ SelectConfigFiles()

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

Definition at line 5842 of file guc.c.

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

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

5843 {
5844  char *configdir;
5845  char *fname;
5846  struct stat stat_buf;
5847 
5848  /* configdir is -D option, or $PGDATA if no -D */
5849  if (userDoption)
5850  configdir = make_absolute_path(userDoption);
5851  else
5852  configdir = make_absolute_path(getenv("PGDATA"));
5853 
5854  if (configdir && stat(configdir, &stat_buf) != 0)
5855  {
5856  write_stderr("%s: could not access directory \"%s\": %s\n",
5857  progname,
5858  configdir,
5859  strerror(errno));
5860  if (errno == ENOENT)
5861  write_stderr("Run initdb or pg_basebackup to initialize a PostgreSQL data directory.\n");
5862  return false;
5863  }
5864 
5865  /*
5866  * Find the configuration file: if config_file was specified on the
5867  * command line, use it, else use configdir/postgresql.conf. In any case
5868  * ensure the result is an absolute path, so that it will be interpreted
5869  * the same way by future backends.
5870  */
5871  if (ConfigFileName)
5873  else if (configdir)
5874  {
5875  fname = guc_malloc(FATAL,
5876  strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
5877  sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
5878  }
5879  else
5880  {
5881  write_stderr("%s does not know where to find the server configuration file.\n"
5882  "You must specify the --config-file or -D invocation "
5883  "option or set the PGDATA environment variable.\n",
5884  progname);
5885  return false;
5886  }
5887 
5888  /*
5889  * Set the ConfigFileName GUC variable to its final value, ensuring that
5890  * it can't be overridden later.
5891  */
5892  SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
5893  free(fname);
5894 
5895  /*
5896  * Now read the config file for the first time.
5897  */
5898  if (stat(ConfigFileName, &stat_buf) != 0)
5899  {
5900  write_stderr("%s: could not access the server configuration file \"%s\": %s\n",
5901  progname, ConfigFileName, strerror(errno));
5902  free(configdir);
5903  return false;
5904  }
5905 
5906  /*
5907  * Read the configuration file for the first time. This time only the
5908  * data_directory parameter is picked up to determine the data directory,
5909  * so that we can read the PG_AUTOCONF_FILENAME file next time.
5910  */
5912 
5913  /*
5914  * If the data_directory GUC variable has been set, use that as DataDir;
5915  * otherwise use configdir if set; else punt.
5916  *
5917  * Note: SetDataDir will copy and absolute-ize its argument, so we don't
5918  * have to.
5919  */
5920  if (data_directory)
5922  else if (configdir)
5923  SetDataDir(configdir);
5924  else
5925  {
5926  write_stderr("%s does not know where to find the database system data.\n"
5927  "This can be specified as \"data_directory\" in \"%s\", "
5928  "or by the -D invocation option, or by the "
5929  "PGDATA environment variable.\n",
5931  return false;
5932  }
5933 
5934  /*
5935  * Reflect the final DataDir value back into the data_directory GUC var.
5936  * (If you are wondering why we don't just make them a single variable,
5937  * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
5938  * child backends specially. XXX is that still true? Given that we now
5939  * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
5940  * DataDir in advance.)
5941  */
5943 
5944  /*
5945  * Now read the config file a second time, allowing any settings in the
5946  * PG_AUTOCONF_FILENAME file to take effect. (This is pretty ugly, but
5947  * since we have to determine the DataDir before we can find the autoconf
5948  * file, the alternatives seem worse.)
5949  */
5951 
5952  /*
5953  * If timezone_abbreviations wasn't set in the configuration file, install
5954  * the default value. We do it this way because we can't safely install a
5955  * "real" value until my_exec_path is set, which may not have happened
5956  * when InitializeGUCOptions runs, so the bootstrap default value cannot
5957  * be the real desired default.
5958  */
5960 
5961  /*
5962  * Figure out where pg_hba.conf is, and make sure the path is absolute.
5963  */
5964  if (HbaFileName)
5966  else if (configdir)
5967  {
5968  fname = guc_malloc(FATAL,
5969  strlen(configdir) + strlen(HBA_FILENAME) + 2);
5970  sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
5971  }
5972  else
5973  {
5974  write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
5975  "This can be specified as \"hba_file\" in \"%s\", "
5976  "or by the -D invocation option, or by the "
5977  "PGDATA environment variable.\n",
5979  return false;
5980  }
5981  SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
5982  free(fname);
5983 
5984  /*
5985  * Likewise for pg_ident.conf.
5986  */
5987  if (IdentFileName)
5989  else if (configdir)
5990  {
5991  fname = guc_malloc(FATAL,
5992  strlen(configdir) + strlen(IDENT_FILENAME) + 2);
5993  sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
5994  }
5995  else
5996  {
5997  write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
5998  "This can be specified as \"ident_file\" in \"%s\", "
5999  "or by the -D invocation option, or by the "
6000  "PGDATA environment variable.\n",
6002  return false;
6003  }
6004  SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
6005  free(fname);
6006 
6007  free(configdir);
6008 
6009  return true;
6010 }
char * make_absolute_path(const char *path)
Definition: path.c:608
const char * progname
Definition: main.c:46
void ProcessConfigFile(GucContext context)
void SetDataDir(const char *dir)
Definition: miscinit.c:397
char * ConfigFileName
Definition: guc.c:583
static void pg_timezone_abbrev_initialize(void)
Definition: guc.c:11905
#define CONFIG_FILENAME
Definition: guc.c:116
#define write_stderr(str)
Definition: parallel.c:186
char * HbaFileName
Definition: guc.c:584
#define sprintf
Definition: port.h:218
#define HBA_FILENAME
Definition: guc.c:117
#define FATAL
Definition: elog.h:49
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:8103
char * IdentFileName
Definition: guc.c:585
#define IDENT_FILENAME
Definition: guc.c:118
#define free(a)
Definition: header.h:65
#define strerror
Definition: port.h:229
static const char * userDoption
Definition: postgres.c:172
char * DataDir
Definition: globals.c:65
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:5059
static char * data_directory
Definition: guc.c:629
#define stat
Definition: win32_port.h:275

◆ SerializeGUCState()

void SerializeGUCState ( Size  maxsize,
char *  start_address 
)

Definition at line 10745 of file guc.c.

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

Referenced by InitializeParallelDSM().

10746 {
10747  char *curptr;
10748  Size actual_size;
10749  Size bytes_left;
10750  int i;
10751 
10752  /* Reserve space for saving the actual size of the guc state */
10753  Assert(maxsize > sizeof(actual_size));
10754  curptr = start_address + sizeof(actual_size);
10755  bytes_left = maxsize - sizeof(actual_size);
10756 
10757  for (i = 0; i < num_guc_variables; i++)
10758  serialize_variable(&curptr, &bytes_left, guc_variables[i]);
10759 
10760  /* Store actual size without assuming alignment of start_address. */
10761  actual_size = maxsize - bytes_left - sizeof(actual_size);
10762  memcpy(start_address, &actual_size, sizeof(actual_size));
10763 }
static void serialize_variable(char **destptr, Size *maxbytes, struct config_generic *gconf)
Definition: guc.c:10670
static int num_guc_variables
Definition: guc.c:5019
static struct config_generic ** guc_variables
Definition: guc.c:5016
#define Assert(condition)
Definition: c.h:804
size_t Size
Definition: c.h:540
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 7312 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_NEEDS_REPORT, 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, 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(), source, guc_stack::source, config_generic::source, config_generic::stack, config_generic::status, string_field_used(), config_var_val::stringval, config_var_value::val, config_bool::variable, config_int::variable, config_real::variable, config_string::variable, config_enum::variable, config_generic::vartype, and WARNING.

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

7316 {
7317  struct config_generic *record;
7318  union config_var_val newval_union;
7319  void *newextra = NULL;
7320  bool prohibitValueChange = false;
7321  bool makeDefault;
7322 
7323  if (elevel == 0)
7324  {
7325  if (source == PGC_S_DEFAULT || source == PGC_S_FILE)
7326  {
7327  /*
7328  * To avoid cluttering the log, only the postmaster bleats loudly
7329  * about problems with the config file.
7330  */
7332  }
7333  else if (source == PGC_S_GLOBAL ||
7334  source == PGC_S_DATABASE ||
7335  source == PGC_S_USER ||
7337  elevel = WARNING;
7338  else
7339  elevel = ERROR;
7340  }
7341 
7342  /*
7343  * GUC_ACTION_SAVE changes are acceptable during a parallel operation,
7344  * because the current worker will also pop the change. We're probably
7345  * dealing with a function having a proconfig entry. Only the function's
7346  * body should observe the change, and peer workers do not share in the
7347  * execution of a function call started by this worker.
7348  *
7349  * Other changes might need to affect other workers, so forbid them.
7350  */
7351  if (IsInParallelMode() && changeVal && action != GUC_ACTION_SAVE)
7352  ereport(elevel,
7353  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
7354  errmsg("cannot set parameters during a parallel operation")));
7355 
7356  record = find_option(name, true, false, elevel);
7357  if (record == NULL)
7358  return 0;
7359 
7360  /*
7361  * Check if the option can be set at this time. See guc.h for the precise
7362  * rules.
7363  */
7364  switch (record->context)
7365  {
7366  case PGC_INTERNAL:
7367  if (context != PGC_INTERNAL)
7368  {
7369  ereport(elevel,
7370  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
7371  errmsg("parameter \"%s\" cannot be changed",
7372  name)));
7373  return 0;
7374  }
7375  break;
7376  case PGC_POSTMASTER:
7377  if (context == PGC_SIGHUP)
7378  {
7379  /*
7380  * We are re-reading a PGC_POSTMASTER variable from
7381  * postgresql.conf. We can't change the setting, so we should
7382  * give a warning if the DBA tries to change it. However,
7383  * because of variant formats, canonicalization by check
7384  * hooks, etc, we can't just compare the given string directly
7385  * to what's stored. Set a flag to check below after we have
7386  * the final storable value.
7387  */
7388  prohibitValueChange = true;
7389  }
7390  else if (context != PGC_POSTMASTER)
7391  {
7392  ereport(elevel,
7393  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
7394  errmsg("parameter \"%s\" cannot be changed without restarting the server",
7395  name)));
7396  return 0;
7397  }
7398  break;
7399  case PGC_SIGHUP:
7400  if (context != PGC_SIGHUP && context != PGC_POSTMASTER)
7401  {
7402  ereport(elevel,
7403  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
7404  errmsg("parameter \"%s\" cannot be changed now",
7405  name)));
7406  return 0;
7407  }
7408 
7409  /*
7410  * Hmm, the idea of the SIGHUP context is "ought to be global, but
7411  * can be changed after postmaster start". But there's nothing
7412  * that prevents a crafty administrator from sending SIGHUP
7413  * signals to individual backends only.
7414  */
7415  break;
7416  case PGC_SU_BACKEND:
7417  /* Reject if we're connecting but user is not superuser */
7418  if (context == PGC_BACKEND)
7419  {
7420  ereport(elevel,
7421  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7422  errmsg("permission denied to set parameter \"%s\"",
7423  name)));
7424  return 0;
7425  }
7426  /* fall through to process the same as PGC_BACKEND */
7427  /* FALLTHROUGH */
7428  case PGC_BACKEND:
7429  if (context == PGC_SIGHUP)
7430  {
7431  /*
7432  * If a PGC_BACKEND or PGC_SU_BACKEND parameter is changed in
7433  * the config file, we want to accept the new value in the
7434  * postmaster (whence it will propagate to
7435  * subsequently-started backends), but ignore it in existing
7436  * backends. This is a tad klugy, but necessary because we
7437  * don't re-read the config file during backend start.
7438  *
7439  * In EXEC_BACKEND builds, this works differently: we load all
7440  * non-default settings from the CONFIG_EXEC_PARAMS file
7441  * during backend start. In that case we must accept
7442  * PGC_SIGHUP settings, so as to have the same value as if
7443  * we'd forked from the postmaster. This can also happen when
7444  * using RestoreGUCState() within a background worker that
7445  * needs to have the same settings as the user backend that
7446  * started it. is_reload will be true when either situation
7447  * applies.
7448  */
7449  if (IsUnderPostmaster && !is_reload)
7450  return -1;
7451  }
7452  else if (context != PGC_POSTMASTER &&
7453  context != PGC_BACKEND &&
7454  context != PGC_SU_BACKEND &&
7455  source != PGC_S_CLIENT)
7456  {
7457  ereport(elevel,
7458  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
7459  errmsg("parameter \"%s\" cannot be set after connection start",
7460  name)));
7461  return 0;
7462  }
7463  break;
7464  case PGC_SUSET:
7465  if (context == PGC_USERSET || context == PGC_BACKEND)
7466  {
7467  ereport(elevel,
7468  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7469  errmsg("permission denied to set parameter \"%s\"",
7470  name)));
7471  return 0;
7472  }
7473  break;
7474  case PGC_USERSET:
7475  /* always okay */
7476  break;
7477  }
7478 
7479  /*
7480  * Disallow changing GUC_NOT_WHILE_SEC_REST values if we are inside a
7481  * security restriction context. We can reject this regardless of the GUC
7482  * context or source, mainly because sources that it might be reasonable
7483  * to override for won't be seen while inside a function.
7484  *
7485  * Note: variables marked GUC_NOT_WHILE_SEC_REST should usually be marked
7486  * GUC_NO_RESET_ALL as well, because ResetAllOptions() doesn't check this.
7487  * An exception might be made if the reset value is assumed to be "safe".
7488  *
7489  * Note: this flag is currently used for "session_authorization" and
7490  * "role". We need to prohibit changing these inside a local userid
7491  * context because when we exit it, GUC won't be notified, leaving things
7492  * out of sync. (This could be fixed by forcing a new GUC nesting level,
7493  * but that would change behavior in possibly-undesirable ways.) Also, we
7494  * prohibit changing these in a security-restricted operation because
7495  * otherwise RESET could be used to regain the session user's privileges.
7496  */
7497  if (record->flags & GUC_NOT_WHILE_SEC_REST)
7498  {
7499  if (InLocalUserIdChange())
7500  {
7501  /*
7502  * Phrasing of this error message is historical, but it's the most
7503  * common case.
7504  */
7505  ereport(elevel,
7506  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7507  errmsg("cannot set parameter \"%s\" within security-definer function",
7508  name)));
7509  return 0;
7510  }
7512  {
7513  ereport(elevel,
7514  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7515  errmsg("cannot set parameter \"%s\" within security-restricted operation",
7516  name)));
7517  return 0;
7518  }
7519  }
7520 
7521  /*
7522  * Should we set reset/stacked values? (If so, the behavior is not
7523  * transactional.) This is done either when we get a default value from
7524  * the database's/user's/client's default settings or when we reset a
7525  * value to its default.
7526  */
7527  makeDefault = changeVal && (source <= PGC_S_OVERRIDE) &&
7528  ((value != NULL) || source == PGC_S_DEFAULT);
7529 
7530  /*
7531  * Ignore attempted set if overridden by previously processed setting.
7532  * However, if changeVal is false then plow ahead anyway since we are
7533  * trying to find out if the value is potentially good, not actually use
7534  * it. Also keep going if makeDefault is true, since we may want to set
7535  * the reset/stacked values even if we can't set the variable itself.
7536  */
7537  if (record->source > source)
7538  {
7539  if (changeVal && !makeDefault)
7540  {
7541  elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
7542  name);
7543  return -1;
7544  }
7545  changeVal = false;
7546  }
7547 
7548  /*
7549  * Evaluate value and set variable.
7550  */
7551  switch (record->vartype)
7552  {
7553  case PGC_BOOL:
7554  {
7555  struct config_bool *conf = (struct config_bool *) record;
7556 
7557 #define newval (newval_union.boolval)
7558 
7559  if (value)
7560  {
7561  if (!parse_and_validate_value(record, name, value,
7562  source, elevel,
7563  &newval_union, &newextra))
7564  return 0;
7565  }
7566  else if (source == PGC_S_DEFAULT)
7567  {
7568  newval = conf->boot_val;
7569  if (!call_bool_check_hook(conf, &newval, &newextra,
7570  source, elevel))
7571  return 0;
7572  }
7573  else
7574  {
7575  newval = conf->reset_val;
7576  newextra = conf->reset_extra;
7577  source = conf->gen.reset_source;
7578  context = conf->gen.reset_scontext;
7579  }
7580 
7581  if (prohibitValueChange)
7582  {
7583  /* Release newextra, unless it's reset_extra */
7584  if (newextra && !extra_field_used(&conf->gen, newextra))
7585  free(newextra);
7586 
7587  if (*conf->variable != newval)
7588  {
7589  record->status |= GUC_PENDING_RESTART;
7590  ereport(elevel,
7591