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)
 

Variables

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

Macro Definition Documentation

◆ GUC_check_errdetail

◆ GUC_check_errhint

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

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 216 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 211 of file guc.h.

Referenced by AlterSystemSetConfigFile(), and displayStruct().

◆ GUC_EXPLAIN

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

Definition at line 231 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 214 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 205 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 206 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 208 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 210 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 215 of file guc.h.

Referenced by set_config_option().

◆ GUC_QUALIFIER_SEPARATOR

#define GUC_QUALIFIER_SEPARATOR   '.'

Definition at line 200 of file guc.h.

Referenced by EmitWarningsOnPlaceholders(), and find_option().

◆ GUC_REPORT

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

◆ GUC_SUPERUSER_ONLY

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

◆ GUC_UNIT

#define GUC_UNIT   (GUC_UNIT_MEMORY | GUC_UNIT_TIME)

Definition at line 233 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 220 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 223 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 219 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 222 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 228 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 226 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 227 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 229 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 221 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 181 of file guc.h.

◆ GucBoolCheckHook

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

Definition at line 175 of file guc.h.

◆ GucEnumAssignHook

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

Definition at line 185 of file guc.h.

◆ GucEnumCheckHook

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

Definition at line 179 of file guc.h.

◆ GucIntAssignHook

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

Definition at line 182 of file guc.h.

◆ GucIntCheckHook

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

Definition at line 176 of file guc.h.

◆ GucRealAssignHook

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

Definition at line 183 of file guc.h.

◆ GucRealCheckHook

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

Definition at line 177 of file guc.h.

◆ GucShowHook

typedef const char*(* GucShowHook) (void)

Definition at line 187 of file guc.h.

◆ GucStringAssignHook

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

Definition at line 184 of file guc.h.

◆ GucStringCheckHook

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

Definition at line 178 of file guc.h.

Enumeration Type Documentation

◆ GucAction

enum GucAction
Enumerator
GUC_ACTION_SET 
GUC_ACTION_LOCAL 
GUC_ACTION_SAVE 

Definition at line 192 of file guc.h.

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

◆ GucContext

enum GucContext
Enumerator
PGC_INTERNAL 
PGC_POSTMASTER 
PGC_SIGHUP 
PGC_SU_BACKEND 
PGC_BACKEND 
PGC_SUSET 
PGC_USERSET 

Definition at line 68 of file guc.h.

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

◆ GucSource

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

Definition at line 105 of file guc.h.

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

Function Documentation

◆ AlterSystemSetConfigFile()

void AlterSystemSetConfigFile ( AlterSystemStmt altersysstmt)

Definition at line 8298 of file guc.c.

References AllocateFile(), BasicOpenFile(), close, config_generic::context, durable_rename(), elog, ereport, errcode(), errcode_for_file_access(), errmsg(), ERROR, ExtractSetVariableArgs(), find_option(), config_generic::flags, free, FreeConfigVariables(), FreeFile(), GUC_DISALLOW_IN_AUTO_FILE, GUC_DISALLOW_IN_FILE, infile(), VariableSetStmt::kind, LOG, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MAXPGPATH, name, VariableSetStmt::name, parse_and_validate_value(), ParseConfigFp(), PG_AUTOCONF_FILENAME, PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, PGC_INTERNAL, PGC_S_FILE, PGC_STRING, replace_auto_config_value(), AlterSystemStmt::setstmt, snprintf, stat, config_var_val::stringval, superuser(), value, VAR_RESET, VAR_RESET_ALL, VAR_SET_DEFAULT, VAR_SET_VALUE, config_generic::vartype, and write_auto_conf_file().

Referenced by standard_ProcessUtility().

8299 {
8300  char *name;
8301  char *value;
8302  bool resetall = false;
8303  ConfigVariable *head = NULL;
8304  ConfigVariable *tail = NULL;
8305  volatile int Tmpfd;
8306  char AutoConfFileName[MAXPGPATH];
8307  char AutoConfTmpFileName[MAXPGPATH];
8308 
8309  if (!superuser())
8310  ereport(ERROR,
8311  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
8312  errmsg("must be superuser to execute ALTER SYSTEM command")));
8313 
8314  /*
8315  * Extract statement arguments
8316  */
8317  name = altersysstmt->setstmt->name;
8318 
8319  switch (altersysstmt->setstmt->kind)
8320  {
8321  case VAR_SET_VALUE:
8322  value = ExtractSetVariableArgs(altersysstmt->setstmt);
8323  break;
8324 
8325  case VAR_SET_DEFAULT:
8326  case VAR_RESET:
8327  value = NULL;
8328  break;
8329 
8330  case VAR_RESET_ALL:
8331  value = NULL;
8332  resetall = true;
8333  break;
8334 
8335  default:
8336  elog(ERROR, "unrecognized alter system stmt type: %d",
8337  altersysstmt->setstmt->kind);
8338  break;
8339  }
8340 
8341  /*
8342  * Unless it's RESET_ALL, validate the target variable and value
8343  */
8344  if (!resetall)
8345  {
8346  struct config_generic *record;
8347 
8348  record = find_option(name, false, ERROR);
8349  if (record == NULL)
8350  ereport(ERROR,
8351  (errcode(ERRCODE_UNDEFINED_OBJECT),
8352  errmsg("unrecognized configuration parameter \"%s\"",
8353  name)));
8354 
8355  /*
8356  * Don't allow parameters that can't be set in configuration files to
8357  * be set in PG_AUTOCONF_FILENAME file.
8358  */
8359  if ((record->context == PGC_INTERNAL) ||
8360  (record->flags & GUC_DISALLOW_IN_FILE) ||
8361  (record->flags & GUC_DISALLOW_IN_AUTO_FILE))
8362  ereport(ERROR,
8363  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
8364  errmsg("parameter \"%s\" cannot be changed",
8365  name)));
8366 
8367  /*
8368  * If a value is specified, verify that it's sane.
8369  */
8370  if (value)
8371  {
8372  union config_var_val newval;
8373  void *newextra = NULL;
8374 
8375  /* Check that it's acceptable for the indicated parameter */
8376  if (!parse_and_validate_value(record, name, value,
8377  PGC_S_FILE, ERROR,
8378  &newval, &newextra))
8379  ereport(ERROR,
8380  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8381  errmsg("invalid value for parameter \"%s\": \"%s\"",
8382  name, value)));
8383 
8384  if (record->vartype == PGC_STRING && newval.stringval != NULL)
8385  free(newval.stringval);
8386  if (newextra)
8387  free(newextra);
8388 
8389  /*
8390  * We must also reject values containing newlines, because the
8391  * grammar for config files doesn't support embedded newlines in
8392  * string literals.
8393  */
8394  if (strchr(value, '\n'))
8395  ereport(ERROR,
8396  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8397  errmsg("parameter value for ALTER SYSTEM must not contain a newline")));
8398  }
8399  }
8400 
8401  /*
8402  * PG_AUTOCONF_FILENAME and its corresponding temporary file are always in
8403  * the data directory, so we can reference them by simple relative paths.
8404  */
8405  snprintf(AutoConfFileName, sizeof(AutoConfFileName), "%s",
8407  snprintf(AutoConfTmpFileName, sizeof(AutoConfTmpFileName), "%s.%s",
8408  AutoConfFileName,
8409  "tmp");
8410 
8411  /*
8412  * Only one backend is allowed to operate on PG_AUTOCONF_FILENAME at a
8413  * time. Use AutoFileLock to ensure that. We must hold the lock while
8414  * reading the old file contents.
8415  */
8416  LWLockAcquire(AutoFileLock, LW_EXCLUSIVE);
8417 
8418  /*
8419  * If we're going to reset everything, then no need to open or parse the
8420  * old file. We'll just write out an empty list.
8421  */
8422  if (!resetall)
8423  {
8424  struct stat st;
8425 
8426  if (stat(AutoConfFileName, &st) == 0)
8427  {
8428  /* open old file PG_AUTOCONF_FILENAME */
8429  FILE *infile;
8430 
8431  infile = AllocateFile(AutoConfFileName, "r");
8432  if (infile == NULL)
8433  ereport(ERROR,
8435  errmsg("could not open file \"%s\": %m",
8436  AutoConfFileName)));
8437 
8438  /* parse it */
8439  if (!ParseConfigFp(infile, AutoConfFileName, 0, LOG, &head, &tail))
8440  ereport(ERROR,
8441  (errcode(ERRCODE_CONFIG_FILE_ERROR),
8442  errmsg("could not parse contents of file \"%s\"",
8443  AutoConfFileName)));
8444 
8445  FreeFile(infile);
8446  }
8447 
8448  /*
8449  * Now, replace any existing entry with the new value, or add it if
8450  * not present.
8451  */
8452  replace_auto_config_value(&head, &tail, name, value);
8453  }
8454 
8455  /*
8456  * To ensure crash safety, first write the new file data to a temp file,
8457  * then atomically rename it into place.
8458  *
8459  * If there is a temp file left over due to a previous crash, it's okay to
8460  * truncate and reuse it.
8461  */
8462  Tmpfd = BasicOpenFile(AutoConfTmpFileName,
8463  O_CREAT | O_RDWR | O_TRUNC);
8464  if (Tmpfd < 0)
8465  ereport(ERROR,
8467  errmsg("could not open file \"%s\": %m",
8468  AutoConfTmpFileName)));
8469 
8470  /*
8471  * Use a TRY block to clean up the file if we fail. Since we need a TRY
8472  * block anyway, OK to use BasicOpenFile rather than OpenTransientFile.
8473  */
8474  PG_TRY();
8475  {
8476  /* Write and sync the new contents to the temporary file */
8477  write_auto_conf_file(Tmpfd, AutoConfTmpFileName, head);
8478 
8479  /* Close before renaming; may be required on some platforms */
8480  close(Tmpfd);
8481  Tmpfd = -1;
8482 
8483  /*
8484  * As the rename is atomic operation, if any problem occurs after this
8485  * at worst it can lose the parameters set by last ALTER SYSTEM
8486  * command.
8487  */
8488  durable_rename(AutoConfTmpFileName, AutoConfFileName, ERROR);
8489  }
8490  PG_CATCH();
8491  {
8492  /* Close file first, else unlink might fail on some platforms */
8493  if (Tmpfd >= 0)
8494  close(Tmpfd);
8495 
8496  /* Unlink, but ignore any error */
8497  (void) unlink(AutoConfTmpFileName);
8498 
8499  PG_RE_THROW();
8500  }
8501  PG_END_TRY();
8502 
8503  FreeConfigVariables(head);
8504 
8505  LWLockRelease(AutoFileLock);
8506 }
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:6886
VariableSetKind kind
Definition: parsenodes.h:2058
static struct @144 value
int errcode(int sqlerrcode)
Definition: elog.c:704
bool superuser(void)
Definition: superuser.c:46
#define LOG
Definition: elog.h:26
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1810
#define ERROR
Definition: elog.h:45
#define MAXPGPATH
VariableSetStmt * setstmt
Definition: parsenodes.h:3211
int errcode_for_file_access(void)
Definition: elog.c:727
FILE * AllocateFile(const char *name, const char *mode)
Definition: fd.c:2354
int durable_rename(const char *oldfile, const char *newfile, int elevel)
Definition: fd.c:687
enum config_type vartype
Definition: guc_tables.h:156
#define GUC_DISALLOW_IN_FILE
Definition: guc.h:211
static void write_auto_conf_file(int fd, const char *filename, ConfigVariable *head_p)
Definition: guc.c:8160
#define ereport(elevel,...)
Definition: elog.h:155
static void infile(const char *filename)
Definition: zic.c:1241
#define free(a)
Definition: header.h:65
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:5297
#define PG_CATCH()
Definition: elog.h:319
#define newval
#define PG_AUTOCONF_FILENAME
Definition: guc.h:34
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1206
#define PG_RE_THROW()
Definition: elog.h:350
const char * name
Definition: encode.c:515
#define GUC_DISALLOW_IN_AUTO_FILE
Definition: guc.h:216
int BasicOpenFile(const char *fileName, int fileFlags)
Definition: fd.c:1014
int FreeFile(FILE *file)
Definition: fd.c:2553
int errmsg(const char *fmt,...)
Definition: elog.c:915
bool ParseConfigFp(FILE *fp, const char *config_file, int depth, int elevel, ConfigVariable **head_p, ConfigVariable **tail_p)
#define elog(elevel,...)
Definition: elog.h:228
static void replace_auto_config_value(ConfigVariable **head_p, ConfigVariable **tail_p, const char *name, const char *value)
Definition: guc.c:8228
void FreeConfigVariables(ConfigVariable *list)
#define close(a)
Definition: win32.h:12
#define PG_TRY()
Definition: elog.h:309
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
Definition: guc.c:8636
#define snprintf
Definition: port.h:215
#define PG_END_TRY()
Definition: elog.h:334
#define stat
Definition: win32_port.h:275
GucContext context
Definition: guc_tables.h:150

◆ assign_search_path()

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

Definition at line 4307 of file namespace.c.

References baseSearchPathValid.

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

◆ assign_temp_tablespaces()

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

Definition at line 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:2821

◆ assign_xlog_sync_method()

void assign_xlog_sync_method ( int  new_sync_method,
void *  extra 
)

Definition at line 10524 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.

10525 {
10526  if (sync_method != new_sync_method)
10527  {
10528  /*
10529  * To ensure that no blocks escape unsynced, force an fsync on the
10530  * currently open log segment (if any). Also, if the open flag is
10531  * changing, close the log file so it will be reopened (with new flag
10532  * bit) at next use.
10533  */
10534  if (openLogFile >= 0)
10535  {
10537  if (pg_fsync(openLogFile) != 0)
10538  {
10539  char xlogfname[MAXFNAMELEN];
10540  int save_errno;
10541 
10542  save_errno = errno;
10545  errno = save_errno;
10546  ereport(PANIC,
10548  errmsg("could not fsync file \"%s\": %m", xlogfname)));
10549  }
10550 
10552  if (get_sync_bit(sync_method) != get_sync_bit(new_sync_method))
10553  XLogFileClose();
10554  }
10555  }
10556 }
int wal_segment_size
Definition: xlog.c:118
static int get_sync_bit(int method)
Definition: xlog.c:10468
#define PANIC
Definition: elog.h:55
static XLogSegNo openLogSegNo
Definition: xlog.c:810
static void XLogFileClose(void)
Definition: xlog.c:3881
int errcode_for_file_access(void)
Definition: elog.c:727
static void pgstat_report_wait_end(void)
Definition: pgstat.h:1512
#define MAXFNAMELEN
static int openLogFile
Definition: xlog.c:809
TimeLineID ThisTimeLineID
Definition: xlog.c:193
#define ereport(elevel,...)
Definition: elog.h:155
#define XLogFileName(fname, tli, logSegNo, wal_segsz_bytes)
static void pgstat_report_wait_start(uint32 wait_event_info)
Definition: pgstat.h:1488
int sync_method
Definition: xlog.c:107
int errmsg(const char *fmt,...)
Definition: elog.c:915
int pg_fsync(int fd)
Definition: fd.c:347

◆ AtEOXact_GUC()

void AtEOXact_GUC ( bool  isCommit,
int  nestLevel 
)

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

6009 {
6010  bool still_dirty;
6011  int i;
6012 
6013  /*
6014  * Note: it's possible to get here with GUCNestLevel == nestLevel-1 during
6015  * abort, if there is a failure during transaction start before
6016  * AtStart_GUC is called.
6017  */
6018  Assert(nestLevel > 0 &&
6019  (nestLevel <= GUCNestLevel ||
6020  (nestLevel == GUCNestLevel + 1 && !isCommit)));
6021 
6022  /* Quick exit if nothing's changed in this transaction */
6023  if (!guc_dirty)
6024  {
6025  GUCNestLevel = nestLevel - 1;
6026  return;
6027  }
6028 
6029  still_dirty = false;
6030  for (i = 0; i < num_guc_variables; i++)
6031  {
6032  struct config_generic *gconf = guc_variables[i];
6033  GucStack *stack;
6034 
6035  /*
6036  * Process and pop each stack entry within the nest level. To simplify
6037  * fmgr_security_definer() and other places that use GUC_ACTION_SAVE,
6038  * we allow failure exit from code that uses a local nest level to be
6039  * recovered at the surrounding transaction or subtransaction abort;
6040  * so there could be more than one stack entry to pop.
6041  */
6042  while ((stack = gconf->stack) != NULL &&
6043  stack->nest_level >= nestLevel)
6044  {
6045  GucStack *prev = stack->prev;
6046  bool restorePrior = false;
6047  bool restoreMasked = false;
6048  bool changed;
6049 
6050  /*
6051  * In this next bit, if we don't set either restorePrior or
6052  * restoreMasked, we must "discard" any unwanted fields of the
6053  * stack entries to avoid leaking memory. If we do set one of
6054  * those flags, unused fields will be cleaned up after restoring.
6055  */
6056  if (!isCommit) /* if abort, always restore prior value */
6057  restorePrior = true;
6058  else if (stack->state == GUC_SAVE)
6059  restorePrior = true;
6060  else if (stack->nest_level == 1)
6061  {
6062  /* transaction commit */
6063  if (stack->state == GUC_SET_LOCAL)
6064  restoreMasked = true;
6065  else if (stack->state == GUC_SET)
6066  {
6067  /* we keep the current active value */
6068  discard_stack_value(gconf, &stack->prior);
6069  }
6070  else /* must be GUC_LOCAL */
6071  restorePrior = true;
6072  }
6073  else if (prev == NULL ||
6074  prev->nest_level < stack->nest_level - 1)
6075  {
6076  /* decrement entry's level and do not pop it */
6077  stack->nest_level--;
6078  continue;
6079  }
6080  else
6081  {
6082  /*
6083  * We have to merge this stack entry into prev. See README for
6084  * discussion of this bit.
6085  */
6086  switch (stack->state)
6087  {
6088  case GUC_SAVE:
6089  Assert(false); /* can't get here */
6090  break;
6091 
6092  case GUC_SET:
6093  /* next level always becomes SET */
6094  discard_stack_value(gconf, &stack->prior);
6095  if (prev->state == GUC_SET_LOCAL)
6096  discard_stack_value(gconf, &prev->masked);
6097  prev->state = GUC_SET;
6098  break;
6099 
6100  case GUC_LOCAL:
6101  if (prev->state == GUC_SET)
6102  {
6103  /* LOCAL migrates down */
6104  prev->masked_scontext = stack->scontext;
6105  prev->masked = stack->prior;
6106  prev->state = GUC_SET_LOCAL;
6107  }
6108  else
6109  {
6110  /* else just forget this stack level */
6111  discard_stack_value(gconf, &stack->prior);
6112  }
6113  break;
6114 
6115  case GUC_SET_LOCAL:
6116  /* prior state at this level no longer wanted */
6117  discard_stack_value(gconf, &stack->prior);
6118  /* copy down the masked state */
6119  prev->masked_scontext = stack->masked_scontext;
6120  if (prev->state == GUC_SET_LOCAL)
6121  discard_stack_value(gconf, &prev->masked);
6122  prev->masked = stack->masked;
6123  prev->state = GUC_SET_LOCAL;
6124  break;
6125  }
6126  }
6127 
6128  changed = false;
6129 
6130  if (restorePrior || restoreMasked)
6131  {
6132  /* Perform appropriate restoration of the stacked value */
6133  config_var_value newvalue;
6134  GucSource newsource;
6135  GucContext newscontext;
6136 
6137  if (restoreMasked)
6138  {
6139  newvalue = stack->masked;
6140  newsource = PGC_S_SESSION;
6141  newscontext = stack->masked_scontext;
6142  }
6143  else
6144  {
6145  newvalue = stack->prior;
6146  newsource = stack->source;
6147  newscontext = stack->scontext;
6148  }
6149 
6150  switch (gconf->vartype)
6151  {
6152  case PGC_BOOL:
6153  {
6154  struct config_bool *conf = (struct config_bool *) gconf;
6155  bool newval = newvalue.val.boolval;
6156  void *newextra = newvalue.extra;
6157 
6158  if (*conf->variable != newval ||
6159  conf->gen.extra != newextra)
6160  {
6161  if (conf->assign_hook)
6162  conf->assign_hook(newval, newextra);
6163  *conf->variable = newval;
6164  set_extra_field(&conf->gen, &conf->gen.extra,
6165  newextra);
6166  changed = true;
6167  }
6168  break;
6169  }
6170  case PGC_INT:
6171  {
6172  struct config_int *conf = (struct config_int *) gconf;
6173  int newval = newvalue.val.intval;
6174  void *newextra = newvalue.extra;
6175 
6176  if (*conf->variable != newval ||
6177  conf->gen.extra != newextra)
6178  {
6179  if (conf->assign_hook)
6180  conf->assign_hook(newval, newextra);
6181  *conf->variable = newval;
6182  set_extra_field(&conf->gen, &conf->gen.extra,
6183  newextra);
6184  changed = true;
6185  }
6186  break;
6187  }
6188  case PGC_REAL:
6189  {
6190  struct config_real *conf = (struct config_real *) gconf;
6191  double newval = newvalue.val.realval;
6192  void *newextra = newvalue.extra;
6193 
6194  if (*conf->variable != newval ||
6195  conf->gen.extra != newextra)
6196  {
6197  if (conf->assign_hook)
6198  conf->assign_hook(newval, newextra);
6199  *conf->variable = newval;
6200  set_extra_field(&conf->gen, &conf->gen.extra,
6201  newextra);
6202  changed = true;
6203  }
6204  break;
6205  }
6206  case PGC_STRING:
6207  {
6208  struct config_string *conf = (struct config_string *) gconf;
6209  char *newval = newvalue.val.stringval;
6210  void *newextra = newvalue.extra;
6211 
6212  if (*conf->variable != newval ||
6213  conf->gen.extra != newextra)
6214  {
6215  if (conf->assign_hook)
6216  conf->assign_hook(newval, newextra);
6217  set_string_field(conf, conf->variable, newval);
6218  set_extra_field(&conf->gen, &conf->gen.extra,
6219  newextra);
6220  changed = true;
6221  }
6222 
6223  /*
6224  * Release stacked values if not used anymore. We
6225  * could use discard_stack_value() here, but since
6226  * we have type-specific code anyway, might as
6227  * well inline it.
6228  */
6229  set_string_field(conf, &stack->prior.val.stringval, NULL);
6230  set_string_field(conf, &stack->masked.val.stringval, NULL);
6231  break;
6232  }
6233  case PGC_ENUM:
6234  {
6235  struct config_enum *conf = (struct config_enum *) gconf;
6236  int newval = newvalue.val.enumval;
6237  void *newextra = newvalue.extra;
6238 
6239  if (*conf->variable != newval ||
6240  conf->gen.extra != newextra)
6241  {
6242  if (conf->assign_hook)
6243  conf->assign_hook(newval, newextra);
6244  *conf->variable = newval;
6245  set_extra_field(&conf->gen, &conf->gen.extra,
6246  newextra);
6247  changed = true;
6248  }
6249  break;
6250  }
6251  }
6252 
6253  /*
6254  * Release stacked extra values if not used anymore.
6255  */
6256  set_extra_field(gconf, &(stack->prior.extra), NULL);
6257  set_extra_field(gconf, &(stack->masked.extra), NULL);
6258 
6259  /* And restore source information */
6260  gconf->source = newsource;
6261  gconf->scontext = newscontext;
6262  }
6263 
6264  /* Finish popping the state stack */
6265  gconf->stack = prev;
6266  pfree(stack);
6267 
6268  /* Report new value if we changed it */
6269  if (changed && (gconf->flags & GUC_REPORT))
6270  {
6271  gconf->status |= GUC_NEEDS_REPORT;
6272  report_needed = true;
6273  }
6274  } /* end of stack-popping loop */
6275 
6276  if (stack != NULL)
6277  still_dirty = true;
6278  }
6279 
6280  /* If there are no remaining stack entries, we can reset guc_dirty */
6281  guc_dirty = still_dirty;
6282 
6283  /* Update nesting level */
6284  GUCNestLevel = nestLevel - 1;
6285 }
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:4871
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:4873
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:105
int * variable
Definition: guc_tables.h:201
int * variable
Definition: guc_tables.h:247
void pfree(void *pointer)
Definition: mcxt.c:1057
static int num_guc_variables
Definition: guc.c:4861
static void discard_stack_value(struct config_generic *gconf, config_var_value *val)
Definition: guc.c:5088
GucSource source
Definition: guc_tables.h:126
static void set_extra_field(struct config_generic *gconf, void **field, void *newval)
Definition: guc.c:5034
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:209
double * variable
Definition: guc_tables.h:217
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4973
static struct config_generic ** guc_variables
Definition: guc.c:4858
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:792
#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:4867
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 5974 of file guc.c.

References elog, and WARNING.

Referenced by StartTransaction().

5975 {
5976  /*
5977  * The nest level should be 0 between transactions; if it isn't, somebody
5978  * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
5979  * throw a warning but make no other effort to clean up.
5980  */
5981  if (GUCNestLevel != 0)
5982  elog(WARNING, "GUC nest level = %d at transaction start",
5983  GUCNestLevel);
5984  GUCNestLevel = 1;
5985 }
static int GUCNestLevel
Definition: guc.c:4873
#define WARNING
Definition: elog.h:40
#define elog(elevel,...)
Definition: elog.h:228

◆ BeginReportingGUCOptions()

void BeginReportingGUCOptions ( void  )

Definition at line 6293 of file guc.c.

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

Referenced by PostgresMain().

6294 {
6295  int i;
6296 
6297  /*
6298  * Don't do anything unless talking to an interactive frontend of protocol
6299  * 3.0 or later.
6300  */
6301  if (whereToSendOutput != DestRemote ||
6303  return;
6304 
6305  reporting_enabled = true;
6306 
6307  /*
6308  * Hack for in_hot_standby: initialize with the value we're about to send.
6309  * (This could be out of date by the time we actually send it, in which
6310  * case the next ReportChangedGUCOptions call will send a duplicate
6311  * report.)
6312  */
6314 
6315  /* Transmit initial values of interesting variables */
6316  for (i = 0; i < num_guc_variables; i++)
6317  {
6318  struct config_generic *conf = guc_variables[i];
6319 
6320  if (conf->flags & GUC_REPORT)
6321  ReportGUCOption(conf);
6322  }
6323 
6324  report_needed = false;
6325 }
static bool report_needed
Definition: guc.c:4871
static bool in_hot_standby
Definition: guc.c:615
bool RecoveryInProgress(void)
Definition: xlog.c:8148
#define PG_PROTOCOL_MAJOR(v)
Definition: pqcomm.h:113
static int num_guc_variables
Definition: guc.c:4861
#define GUC_REPORT
Definition: guc.h:209
static struct config_generic ** guc_variables
Definition: guc.c:4858
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:6387
CommandDest whereToSendOutput
Definition: postgres.c:92
static bool reporting_enabled
Definition: guc.c:4869
ProtocolVersion FrontendProtocol
Definition: globals.c:28

◆ 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:704
#define OidIsValid(objectId)
Definition: c.h:698
Oid MyDatabaseId
Definition: globals.c:86
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:155
#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:915

◆ 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:1187
void pfree(void *pointer)
Definition: mcxt.c:1057
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3741
#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:4640
Oid GetUserId(void)
Definition: miscinit.c:476
#define GUC_check_errdetail
Definition: guc.h:417
char * pstrdup(const char *in)
Definition: mcxt.c:1187
int errcode(int sqlerrcode)
Definition: elog.c:704
unsigned int Oid
Definition: postgres_ext.h:31
Oid MyDatabaseTableSpace
Definition: globals.c:88
#define malloc(a)
Definition: header.h:50
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3297
void pfree(void *pointer)
Definition: mcxt.c:1057
#define ACL_CREATE
Definition: parsenodes.h:84
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3741
Oid tblSpcs[FLEXIBLE_ARRAY_MEMBER]
Definition: tablespace.c:1200
AclResult
Definition: acl.h:177
Oid MyDatabaseId
Definition: globals.c:86
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:155
#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:950
int errmsg(const char *fmt,...)
Definition: elog.c:915
void list_free(List *list)
Definition: list.c:1391
Definition: pg_list.h:50
#define offsetof(type, field)
Definition: c.h:715

◆ check_wal_buffers()

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

Definition at line 5017 of file xlog.c.

References XLOGbuffers, and XLOGChooseNumBuffers().

5018 {
5019  /*
5020  * -1 indicates a request for auto-tune.
5021  */
5022  if (*newval == -1)
5023  {
5024  /*
5025  * If we haven't yet changed the boot_val default of -1, just let it
5026  * be. We'll fix it when XLOGShmemSize is called.
5027  */
5028  if (XLOGbuffers == -1)
5029  return true;
5030 
5031  /* Otherwise, substitute the auto-tune value */
5033  }
5034 
5035  /*
5036  * We clamp manually-set values to at least 4 blocks. Prior to PostgreSQL
5037  * 9.1, a minimum of 4 was enforced by guc.c, but since that is no longer
5038  * the case, we just silently treat such values as a request for the
5039  * minimum. (We could throw an error instead, but that doesn't seem very
5040  * helpful.)
5041  */
5042  if (*newval < 4)
5043  *newval = 4;
5044 
5045  return true;
5046 }
static int XLOGChooseNumBuffers(void)
Definition: xlog.c:5001
#define newval
int XLOGbuffers
Definition: xlog.c:94

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

8975 {
8976  struct config_bool *var;
8977 
8978  var = (struct config_bool *)
8979  init_custom_variable(name, short_desc, long_desc, context, flags,
8980  PGC_BOOL, sizeof(struct config_bool));
8981  var->variable = valueAddr;
8982  var->boot_val = bootValue;
8983  var->reset_val = bootValue;
8984  var->check_hook = check_hook;
8985  var->assign_hook = assign_hook;
8986  var->show_hook = show_hook;
8987  define_custom_variable(&var->gen);
8988 }
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:8724
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:8784

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

9087 {
9088  struct config_enum *var;
9089 
9090  var = (struct config_enum *)
9091  init_custom_variable(name, short_desc, long_desc, context, flags,
9092  PGC_ENUM, sizeof(struct config_enum));
9093  var->variable = valueAddr;
9094  var->boot_val = bootValue;
9095  var->reset_val = bootValue;
9096  var->options = options;
9097  var->check_hook = check_hook;
9098  var->assign_hook = assign_hook;
9099  var->show_hook = show_hook;
9100  define_custom_variable(&var->gen);
9101 }
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:8724
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:8784

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

9003 {
9004  struct config_int *var;
9005 
9006  var = (struct config_int *)
9007  init_custom_variable(name, short_desc, long_desc, context, flags,
9008  PGC_INT, sizeof(struct config_int));
9009  var->variable = valueAddr;
9010  var->boot_val = bootValue;
9011  var->reset_val = bootValue;
9012  var->min = minValue;
9013  var->max = maxValue;
9014  var->check_hook = check_hook;
9015  var->assign_hook = assign_hook;
9016  var->show_hook = show_hook;
9017  define_custom_variable(&var->gen);
9018 }
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:8724
const char * name
Definition: encode.c:515
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8784
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 9021 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().

9033 {
9034  struct config_real *var;
9035 
9036  var = (struct config_real *)
9037  init_custom_variable(name, short_desc, long_desc, context, flags,
9038  PGC_REAL, sizeof(struct config_real));
9039  var->variable = valueAddr;
9040  var->boot_val = bootValue;
9041  var->reset_val = bootValue;
9042  var->min = minValue;
9043  var->max = maxValue;
9044  var->check_hook = check_hook;
9045  var->assign_hook = assign_hook;
9046  var->show_hook = show_hook;
9047  define_custom_variable(&var->gen);
9048 }
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:8724
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:8784
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 9051 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().

9061 {
9062  struct config_string *var;
9063 
9064  var = (struct config_string *)
9065  init_custom_variable(name, short_desc, long_desc, context, flags,
9066  PGC_STRING, sizeof(struct config_string));
9067  var->variable = valueAddr;
9068  var->boot_val = bootValue;
9069  var->check_hook = check_hook;
9070  var->assign_hook = assign_hook;
9071  var->show_hook = show_hook;
9072  define_custom_variable(&var->gen);
9073 }
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:8724
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:8784

◆ EmitWarningsOnPlaceholders()

void EmitWarningsOnPlaceholders ( const char *  className)

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

9105 {
9106  int classLen = strlen(className);
9107  int i;
9108 
9109  for (i = 0; i < num_guc_variables; i++)
9110  {
9111  struct config_generic *var = guc_variables[i];
9112 
9113  if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
9114  strncmp(className, var->name, classLen) == 0 &&
9115  var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
9116  {
9117  ereport(WARNING,
9118  (errcode(ERRCODE_UNDEFINED_OBJECT),
9119  errmsg("unrecognized configuration parameter \"%s\"",
9120  var->name)));
9121  }
9122  }
9123 }
const char * name
Definition: guc_tables.h:149
int errcode(int sqlerrcode)
Definition: elog.c:704
#define GUC_QUALIFIER_SEPARATOR
Definition: guc.h:200
static int num_guc_variables
Definition: guc.c:4861
static struct config_generic ** guc_variables
Definition: guc.c:4858
#define WARNING
Definition: elog.h:40
#define ereport(elevel,...)
Definition: elog.h:155
#define GUC_CUSTOM_PLACEHOLDER
Definition: guc.h:212
int errmsg(const char *fmt,...)
Definition: elog.c:915
int i

◆ EstimateGUCStateSpace()

Size EstimateGUCStateSpace ( void  )

Definition at line 10398 of file guc.c.

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

Referenced by InitializeParallelDSM().

10399 {
10400  Size size;
10401  int i;
10402 
10403  /* Add space reqd for saving the data size of the guc state */
10404  size = sizeof(Size);
10405 
10406  /* Add up the space needed for each GUC variable */
10407  for (i = 0; i < num_guc_variables; i++)
10408  size = add_size(size,
10410 
10411  return size;
10412 }
static int num_guc_variables
Definition: guc.c:4861
static struct config_generic ** guc_variables
Definition: guc.c:4858
Size add_size(Size s1, Size s2)
Definition: shmem.c:502
size_t Size
Definition: c.h:528
static Size estimate_variable_size(struct config_generic *gconf)
Definition: guc.c:10300
int i

◆ ExecSetVariableStmt()

void ExecSetVariableStmt ( VariableSetStmt stmt,
bool  isTopLevel 
)

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

8513 {
8515 
8516  /*
8517  * Workers synchronize these parameters at the start of the parallel
8518  * operation; then, we block SET during the operation.
8519  */
8520  if (IsInParallelMode())
8521  ereport(ERROR,
8522  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
8523  errmsg("cannot set parameters during a parallel operation")));
8524 
8525  switch (stmt->kind)
8526  {
8527  case VAR_SET_VALUE:
8528  case VAR_SET_CURRENT:
8529  if (stmt->is_local)
8530  WarnNoTransactionBlock(isTopLevel, "SET LOCAL");
8531  (void) set_config_option(stmt->name,
8532  ExtractSetVariableArgs(stmt),
8534  PGC_S_SESSION,
8535  action, true, 0, false);
8536  break;
8537  case VAR_SET_MULTI:
8538 
8539  /*
8540  * Special-case SQL syntaxes. The TRANSACTION and SESSION
8541  * CHARACTERISTICS cases effectively set more than one variable
8542  * per statement. TRANSACTION SNAPSHOT only takes one argument,
8543  * but we put it here anyway since it's a special case and not
8544  * related to any GUC variable.
8545  */
8546  if (strcmp(stmt->name, "TRANSACTION") == 0)
8547  {
8548  ListCell *head;
8549 
8550  WarnNoTransactionBlock(isTopLevel, "SET TRANSACTION");
8551 
8552  foreach(head, stmt->args)
8553  {
8554  DefElem *item = (DefElem *) lfirst(head);
8555 
8556  if (strcmp(item->defname, "transaction_isolation") == 0)
8557  SetPGVariable("transaction_isolation",
8558  list_make1(item->arg), stmt->is_local);
8559  else if (strcmp(item->defname, "transaction_read_only") == 0)
8560  SetPGVariable("transaction_read_only",
8561  list_make1(item->arg), stmt->is_local);
8562  else if (strcmp(item->defname, "transaction_deferrable") == 0)
8563  SetPGVariable("transaction_deferrable",
8564  list_make1(item->arg), stmt->is_local);
8565  else
8566  elog(ERROR, "unexpected SET TRANSACTION element: %s",
8567  item->defname);
8568  }
8569  }
8570  else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
8571  {
8572  ListCell *head;
8573 
8574  foreach(head, stmt->args)
8575  {
8576  DefElem *item = (DefElem *) lfirst(head);
8577 
8578  if (strcmp(item->defname, "transaction_isolation") == 0)
8579  SetPGVariable("default_transaction_isolation",
8580  list_make1(item->arg), stmt->is_local);
8581  else if (strcmp(item->defname, "transaction_read_only") == 0)
8582  SetPGVariable("default_transaction_read_only",
8583  list_make1(item->arg), stmt->is_local);
8584  else if (strcmp(item->defname, "transaction_deferrable") == 0)
8585  SetPGVariable("default_transaction_deferrable",
8586  list_make1(item->arg), stmt->is_local);
8587  else
8588  elog(ERROR, "unexpected SET SESSION element: %s",
8589  item->defname);
8590  }
8591  }
8592  else if (strcmp(stmt->name, "TRANSACTION SNAPSHOT") == 0)
8593  {
8594  A_Const *con = linitial_node(A_Const, stmt->args);
8595 
8596  if (stmt->is_local)
8597  ereport(ERROR,
8598  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8599  errmsg("SET LOCAL TRANSACTION SNAPSHOT is not implemented")));
8600 
8601  WarnNoTransactionBlock(isTopLevel, "SET TRANSACTION");
8602  Assert(nodeTag(&con->val) == T_String);
8603  ImportSnapshot(strVal(&con->val));
8604  }
8605  else
8606  elog(ERROR, "unexpected SET MULTI element: %s",
8607  stmt->name);
8608  break;
8609  case VAR_SET_DEFAULT:
8610  if (stmt->is_local)
8611  WarnNoTransactionBlock(isTopLevel, "SET LOCAL");
8612  /* fall through */
8613  case VAR_RESET:
8614  if (strcmp(stmt->name, "transaction_isolation") == 0)
8615  WarnNoTransactionBlock(isTopLevel, "RESET TRANSACTION");
8616 
8617  (void) set_config_option(stmt->name,
8618  NULL,
8620  PGC_S_SESSION,
8621  action, true, 0, false);
8622  break;
8623  case VAR_RESET_ALL:
8624  ResetAllOptions();
8625  break;
8626  }
8627 }
void ImportSnapshot(const char *idstr)
Definition: snapmgr.c:1377
VariableSetKind kind
Definition: parsenodes.h:2058
void WarnNoTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3441
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:704
bool superuser(void)
Definition: superuser.c:46
#define linitial_node(type, l)
Definition: pg_list.h:177
GucAction
Definition: guc.h:192
#define list_make1(x1)
Definition: pg_list.h:206
bool IsInParallelMode(void)
Definition: xact.c:1012
#define ERROR
Definition: elog.h:45
Definition: guc.h:75
void ResetAllOptions(void)
Definition: guc.c:5790
Node * arg
Definition: parsenodes.h:734
#define ereport(elevel,...)
Definition: elog.h:155
#define Assert(condition)
Definition: c.h:792
#define lfirst(lc)
Definition: pg_list.h:169
#define nodeTag(nodeptr)
Definition: nodes.h:533
int errmsg(const char *fmt,...)
Definition: elog.c:915
#define elog(elevel,...)
Definition: elog.h:228
char * defname
Definition: parsenodes.h:733
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
Definition: guc.c:8636
Value val
Definition: parsenodes.h:287
int set_config_option(const char *name, const char *value, GucContext context, GucSource source, GucAction action, bool changeVal, int elevel, bool is_reload)
Definition: guc.c:7083
void SetPGVariable(const char *name, List *args, bool is_local)
Definition: guc.c:8656

◆ ExtractSetVariableArgs()

char* ExtractSetVariableArgs ( VariableSetStmt stmt)

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

8637 {
8638  switch (stmt->kind)
8639  {
8640  case VAR_SET_VALUE:
8641  return flatten_set_variable_args(stmt->name, stmt->args);
8642  case VAR_SET_CURRENT:
8643  return GetConfigOptionByName(stmt->name, NULL, false);
8644  default:
8645  return NULL;
8646  }
8647 }
VariableSetKind kind
Definition: parsenodes.h:2058
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:9365
static char * flatten_set_variable_args(const char *name, List *args)
Definition: guc.c:8038

◆ FreeConfigVariables()

void FreeConfigVariables ( ConfigVariable list)

◆ GetConfigOption()

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

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

7904 {
7905  struct config_generic *record;
7906  static char buffer[256];
7907 
7908  record = find_option(name, false, ERROR);
7909  if (record == NULL)
7910  {
7911  if (missing_ok)
7912  return NULL;
7913  ereport(ERROR,
7914  (errcode(ERRCODE_UNDEFINED_OBJECT),
7915  errmsg("unrecognized configuration parameter \"%s\"",
7916  name)));
7917  }
7918  if (restrict_privileged &&
7919  (record->flags & GUC_SUPERUSER_ONLY) &&
7920  !is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
7921  ereport(ERROR,
7922  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7923  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
7924  name)));
7925 
7926  switch (record->vartype)
7927  {
7928  case PGC_BOOL:
7929  return *((struct config_bool *) record)->variable ? "on" : "off";
7930 
7931  case PGC_INT:
7932  snprintf(buffer, sizeof(buffer), "%d",
7933  *((struct config_int *) record)->variable);
7934  return buffer;
7935 
7936  case PGC_REAL:
7937  snprintf(buffer, sizeof(buffer), "%g",
7938  *((struct config_real *) record)->variable);
7939  return buffer;
7940 
7941  case PGC_STRING:
7942  return *((struct config_string *) record)->variable;
7943 
7944  case PGC_ENUM:
7945  return config_enum_lookup_by_value((struct config_enum *) record,
7946  *((struct config_enum *) record)->variable);
7947  }
7948  return NULL;
7949 }
Oid GetUserId(void)
Definition: miscinit.c:476
int errcode(int sqlerrcode)
Definition: elog.c:704
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:6779
#define ERROR
Definition: elog.h:45
enum config_type vartype
Definition: guc_tables.h:156
#define GUC_SUPERUSER_ONLY
Definition: guc.h:213
#define ereport(elevel,...)
Definition: elog.h:155
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4919
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:5297
const char * name
Definition: encode.c:515
int errmsg(const char *fmt,...)
Definition: elog.c:915
#define snprintf
Definition: port.h:215

◆ GetConfigOptionByName()

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

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

9366 {
9367  struct config_generic *record;
9368 
9369  record = find_option(name, false, ERROR);
9370  if (record == NULL)
9371  {
9372  if (missing_ok)
9373  {
9374  if (varname)
9375  *varname = NULL;
9376  return NULL;
9377  }
9378 
9379  ereport(ERROR,
9380  (errcode(ERRCODE_UNDEFINED_OBJECT),
9381  errmsg("unrecognized configuration parameter \"%s\"", name)));
9382  }
9383 
9384  if ((record->flags & GUC_SUPERUSER_ONLY) &&
9385  !is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
9386  ereport(ERROR,
9387  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
9388  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
9389  name)));
9390 
9391  if (varname)
9392  *varname = record->name;
9393 
9394  return _ShowOption(record, true);
9395 }
static char * _ShowOption(struct config_generic *record, bool use_units)
Definition: guc.c:9925
Oid GetUserId(void)
Definition: miscinit.c:476
const char * name
Definition: guc_tables.h:149
int errcode(int sqlerrcode)
Definition: elog.c:704
#define ERROR
Definition: elog.h:45
#define GUC_SUPERUSER_ONLY
Definition: guc.h:213
#define ereport(elevel,...)
Definition: elog.h:155
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4919
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:5297
const char * name
Definition: encode.c:515
int errmsg(const char *fmt,...)
Definition: elog.c:915

◆ GetConfigOptionByNum()

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

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

9403 {
9404  char buffer[256];
9405  struct config_generic *conf;
9406 
9407  /* check requested variable number valid */
9408  Assert((varnum >= 0) && (varnum < num_guc_variables));
9409 
9410  conf = guc_variables[varnum];
9411 
9412  if (noshow)
9413  {
9414  if ((conf->flags & GUC_NO_SHOW_ALL) ||
9415  ((conf->flags & GUC_SUPERUSER_ONLY) &&
9416  !is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS)))
9417  *noshow = true;
9418  else
9419  *noshow = false;
9420  }
9421 
9422  /* first get the generic attributes */
9423 
9424  /* name */
9425  values[0] = conf->name;
9426 
9427  /* setting: use _ShowOption in order to avoid duplicating the logic */
9428  values[1] = _ShowOption(conf, false);
9429 
9430  /* unit, if any (NULL is fine) */
9431  values[2] = get_config_unit_name(conf->flags);
9432 
9433  /* group */
9434  values[3] = _(config_group_names[conf->group]);
9435 
9436  /* short_desc */
9437  values[4] = _(conf->short_desc);
9438 
9439  /* extra_desc */
9440  values[5] = _(conf->long_desc);
9441 
9442  /* context */
9443  values[6] = GucContext_Names[conf->context];
9444 
9445  /* vartype */
9446  values[7] = config_type_names[conf->vartype];
9447 
9448  /* source */
9449  values[8] = GucSource_Names[conf->source];
9450 
9451  /* now get the type specific attributes */
9452  switch (conf->vartype)
9453  {
9454  case PGC_BOOL:
9455  {
9456  struct config_bool *lconf = (struct config_bool *) conf;
9457 
9458  /* min_val */
9459  values[9] = NULL;
9460 
9461  /* max_val */
9462  values[10] = NULL;
9463 
9464  /* enumvals */
9465  values[11] = NULL;
9466 
9467  /* boot_val */
9468  values[12] = pstrdup(lconf->boot_val ? "on" : "off");
9469 
9470  /* reset_val */
9471  values[13] = pstrdup(lconf->reset_val ? "on" : "off");
9472  }
9473  break;
9474 
9475  case PGC_INT:
9476  {
9477  struct config_int *lconf = (struct config_int *) conf;
9478 
9479  /* min_val */
9480  snprintf(buffer, sizeof(buffer), "%d", lconf->min);
9481  values[9] = pstrdup(buffer);
9482 
9483  /* max_val */
9484  snprintf(buffer, sizeof(buffer), "%d", lconf->max);
9485  values[10] = pstrdup(buffer);
9486 
9487  /* enumvals */
9488  values[11] = NULL;
9489 
9490  /* boot_val */
9491  snprintf(buffer, sizeof(buffer), "%d", lconf->boot_val);
9492  values[12] = pstrdup(buffer);
9493 
9494  /* reset_val */
9495  snprintf(buffer, sizeof(buffer), "%d", lconf->reset_val);
9496  values[13] = pstrdup(buffer);
9497  }
9498  break;
9499 
9500  case PGC_REAL:
9501  {
9502  struct config_real *lconf = (struct config_real *) conf;
9503 
9504  /* min_val */
9505  snprintf(buffer, sizeof(buffer), "%g", lconf->min);
9506  values[9] = pstrdup(buffer);
9507 
9508  /* max_val */
9509  snprintf(buffer, sizeof(buffer), "%g", lconf->max);
9510  values[10] = pstrdup(buffer);
9511 
9512  /* enumvals */
9513  values[11] = NULL;
9514 
9515  /* boot_val */
9516  snprintf(buffer, sizeof(buffer), "%g", lconf->boot_val);
9517  values[12] = pstrdup(buffer);
9518 
9519  /* reset_val */
9520  snprintf(buffer, sizeof(buffer), "%g", lconf->reset_val);
9521  values[13] = pstrdup(buffer);
9522  }
9523  break;
9524 
9525  case PGC_STRING:
9526  {
9527  struct config_string *lconf = (struct config_string *) conf;
9528 
9529  /* min_val */
9530  values[9] = NULL;
9531 
9532  /* max_val */
9533  values[10] = NULL;
9534 
9535  /* enumvals */
9536  values[11] = NULL;
9537 
9538  /* boot_val */
9539  if (lconf->boot_val == NULL)
9540  values[12] = NULL;
9541  else
9542  values[12] = pstrdup(lconf->boot_val);
9543 
9544  /* reset_val */
9545  if (lconf->reset_val == NULL)
9546  values[13] = NULL;
9547  else
9548  values[13] = pstrdup(lconf->reset_val);
9549  }
9550  break;
9551 
9552  case PGC_ENUM:
9553  {
9554  struct config_enum *lconf = (struct config_enum *) conf;
9555 
9556  /* min_val */
9557  values[9] = NULL;
9558 
9559  /* max_val */
9560  values[10] = NULL;
9561 
9562  /* enumvals */
9563 
9564  /*
9565  * NOTE! enumvals with double quotes in them are not
9566  * supported!
9567  */
9568  values[11] = config_enum_get_options((struct config_enum *) conf,
9569  "{\"", "\"}", "\",\"");
9570 
9571  /* boot_val */
9573  lconf->boot_val));
9574 
9575  /* reset_val */
9577  lconf->reset_val));
9578  }
9579  break;
9580 
9581  default:
9582  {
9583  /*
9584  * should never get here, but in case we do, set 'em to NULL
9585  */
9586 
9587  /* min_val */
9588  values[9] = NULL;
9589 
9590  /* max_val */
9591  values[10] = NULL;
9592 
9593  /* enumvals */
9594  values[11] = NULL;
9595 
9596  /* boot_val */
9597  values[12] = NULL;
9598 
9599  /* reset_val */
9600  values[13] = NULL;
9601  }
9602  break;
9603  }
9604 
9605  /*
9606  * If the setting came from a config file, set the source location. For
9607  * security reasons, we don't show source file/line number for
9608  * insufficiently-privileged users.
9609  */
9610  if (conf->source == PGC_S_FILE &&
9611  is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
9612  {
9613  values[14] = conf->sourcefile;
9614  snprintf(buffer, sizeof(buffer), "%d", conf->sourceline);
9615  values[15] = pstrdup(buffer);
9616  }
9617  else
9618  {
9619  values[14] = NULL;
9620  values[15] = NULL;
9621  }
9622 
9623  values[16] = (conf->status & GUC_PENDING_RESTART) ? "t" : "f";
9624 }
GucSource source
Definition: guc_tables.h:158
static char * _ShowOption(struct config_generic *record, bool use_units)
Definition: guc.c:9925
const char * long_desc
Definition: guc_tables.h:153
double reset_val
Definition: guc_tables.h:225
Oid GetUserId(void)
Definition: miscinit.c:476
const char * name
Definition: guc_tables.h:149
const char *const config_type_names[]
Definition: guc.c:791
char * pstrdup(const char *in)
Definition: mcxt.c:1187
const char * short_desc
Definition: guc_tables.h:152
int boot_val
Definition: guc_tables.h: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:6779
#define GUC_NO_SHOW_ALL
Definition: guc.h:207
const char *const GucContext_Names[]
Definition: guc.c:632
const char *const config_group_names[]
Definition: guc.c:675
static int num_guc_variables
Definition: guc.c:4861
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:6570
static struct config_generic ** guc_variables
Definition: guc.c:4858
enum config_type vartype
Definition: guc_tables.h:156
double max
Definition: guc_tables.h:220
#define GUC_SUPERUSER_ONLY
Definition: guc.h:213
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4919
char * reset_val
Definition: guc_tables.h:239
double boot_val
Definition: guc_tables.h:218
#define Assert(condition)
Definition: c.h:792
#define GUC_PENDING_RESTART
Definition: guc_tables.h:177
double min
Definition: guc_tables.h:219
static Datum values[MAXATTR]
Definition: bootstrap.c:165
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:651
#define snprintf
Definition: port.h:215
#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:6828
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 8008 of file guc.c.

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

Referenced by pg_get_functiondef().

8009 {
8010  struct config_generic *record;
8011 
8012  record = find_option(name, false, WARNING);
8013  if (record == NULL)
8014  {
8015  if (missing_ok)
8016  return 0;
8017  ereport(ERROR,
8018  (errcode(ERRCODE_UNDEFINED_OBJECT),
8019  errmsg("unrecognized configuration parameter \"%s\"",
8020  name)));
8021  }
8022  return record->flags;
8023 }
int errcode(int sqlerrcode)
Definition: elog.c:704
#define ERROR
Definition: elog.h:45
#define WARNING
Definition: elog.h:40
#define ereport(elevel,...)
Definition: elog.h:155
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:5297
const char * name
Definition: encode.c:515
int errmsg(const char *fmt,...)
Definition: elog.c:915

◆ GetConfigOptionResetString()

const char* GetConfigOptionResetString ( const char *  name)

Definition at line 7959 of file guc.c.

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

Referenced by check_datestyle().

7960 {
7961  struct config_generic *record;
7962  static char buffer[256];
7963 
7964  record = find_option(name, false, ERROR);
7965  if (record == NULL)
7966  ereport(ERROR,
7967  (errcode(ERRCODE_UNDEFINED_OBJECT),
7968  errmsg("unrecognized configuration parameter \"%s\"", name)));
7969  if ((record->flags & GUC_SUPERUSER_ONLY) &&
7970  !is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
7971  ereport(ERROR,
7972  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7973  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
7974  name)));
7975 
7976  switch (record->vartype)
7977  {
7978  case PGC_BOOL:
7979  return ((struct config_bool *) record)->reset_val ? "on" : "off";
7980 
7981  case PGC_INT:
7982  snprintf(buffer, sizeof(buffer), "%d",
7983  ((struct config_int *) record)->reset_val);
7984  return buffer;
7985 
7986  case PGC_REAL:
7987  snprintf(buffer, sizeof(buffer), "%g",
7988  ((struct config_real *) record)->reset_val);
7989  return buffer;
7990 
7991  case PGC_STRING:
7992  return ((struct config_string *) record)->reset_val;
7993 
7994  case PGC_ENUM:
7995  return config_enum_lookup_by_value((struct config_enum *) record,
7996  ((struct config_enum *) record)->reset_val);
7997  }
7998  return NULL;
7999 }
Oid GetUserId(void)
Definition: miscinit.c:476
int errcode(int sqlerrcode)
Definition: elog.c:704
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:6779
#define ERROR
Definition: elog.h:45
enum config_type vartype
Definition: guc_tables.h:156
#define GUC_SUPERUSER_ONLY
Definition: guc.h:213
#define ereport(elevel,...)
Definition: elog.h:155
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4919
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:5297
const char * name
Definition: encode.c:515
int errmsg(const char *fmt,...)
Definition: elog.c:915
#define snprintf
Definition: port.h:215

◆ GetNumConfigOptions()

int GetNumConfigOptions ( void  )

Definition at line 9630 of file guc.c.

References num_guc_variables.

Referenced by GucInfoMain(), and show_all_settings().

9631 {
9632  return num_guc_variables;
9633 }
static int num_guc_variables
Definition: guc.c:4861

◆ GetPGVariable()

void GetPGVariable ( const char *  name,
DestReceiver dest 
)

Definition at line 9130 of file guc.c.

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

Referenced by exec_replication_command(), and standard_ProcessUtility().

9131 {
9132  if (guc_name_compare(name, "all") == 0)
9133  ShowAllGUCConfig(dest);
9134  else
9135  ShowGUCConfigOption(name, dest);
9136 }
static void ShowGUCConfigOption(const char *name, DestReceiver *dest)
Definition: guc.c:9174
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:5358
static void ShowAllGUCConfig(DestReceiver *dest)
Definition: guc.c:9202
const char * name
Definition: encode.c:515

◆ GetPGVariableResultDesc()

TupleDesc GetPGVariableResultDesc ( const char *  name)

Definition at line 9139 of file guc.c.

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

Referenced by UtilityTupleDescriptor().

9140 {
9141  TupleDesc tupdesc;
9142 
9143  if (guc_name_compare(name, "all") == 0)
9144  {
9145  /* need a tuple descriptor representing three TEXT columns */
9146  tupdesc = CreateTemplateTupleDesc(3);
9147  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
9148  TEXTOID, -1, 0);
9149  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
9150  TEXTOID, -1, 0);
9151  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
9152  TEXTOID, -1, 0);
9153  }
9154  else
9155  {
9156  const char *varname;
9157 
9158  /* Get the canonical spelling of name */
9159  (void) GetConfigOptionByName(name, &varname, false);
9160 
9161  /* need a tuple descriptor representing a single TEXT column */
9162  tupdesc = CreateTemplateTupleDesc(1);
9163  TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
9164  TEXTOID, -1, 0);
9165  }
9166  return tupdesc;
9167 }
TupleDesc CreateTemplateTupleDesc(int natts)
Definition: tupdesc.c:44
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:5358
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:9365
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:603
const char * name
Definition: encode.c: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 10790 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().

10791 {
10792  struct config_generic *record;
10793  Datum datum;
10794  char *newval;
10795  ArrayType *a;
10796 
10797  Assert(name);
10798  Assert(value);
10799 
10800  /* test if the option is valid and we're allowed to set it */
10801  (void) validate_option_array_item(name, value, false);
10802 
10803  /* normalize name (converts obsolete GUC names to modern spellings) */
10804  record = find_option(name, false, WARNING);
10805  if (record)
10806  name = record->name;
10807 
10808  /* build new item for array */
10809  newval = psprintf("%s=%s", name, value);
10810  datum = CStringGetTextDatum(newval);
10811 
10812  if (array)
10813  {
10814  int index;
10815  bool isnull;
10816  int i;
10817 
10818  Assert(ARR_ELEMTYPE(array) == TEXTOID);
10819  Assert(ARR_NDIM(array) == 1);
10820  Assert(ARR_LBOUND(array)[0] == 1);
10821 
10822  index = ARR_DIMS(array)[0] + 1; /* add after end */
10823 
10824  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
10825  {
10826  Datum d;
10827  char *current;
10828 
10829  d = array_ref(array, 1, &i,
10830  -1 /* varlenarray */ ,
10831  -1 /* TEXT's typlen */ ,
10832  false /* TEXT's typbyval */ ,
10833  TYPALIGN_INT /* TEXT's typalign */ ,
10834  &isnull);
10835  if (isnull)
10836  continue;
10837  current = TextDatumGetCString(d);
10838 
10839  /* check for match up through and including '=' */
10840  if (strncmp(current, newval, strlen(name) + 1) == 0)
10841  {
10842  index = i;
10843  break;
10844  }
10845  }
10846 
10847  a = array_set(array, 1, &index,
10848  datum,
10849  false,
10850  -1 /* varlena array */ ,
10851  -1 /* TEXT's typlen */ ,
10852  false /* TEXT's typbyval */ ,
10853  TYPALIGN_INT /* TEXT's typalign */ );
10854  }
10855  else
10856  a = construct_array(&datum, 1,
10857  TEXTOID,
10858  -1, false, TYPALIGN_INT);
10859 
10860  return a;
10861 }
const char * name
Definition: guc_tables.h:149
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
static struct @144 value
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:11016
#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:367
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:5297
#define Assert(condition)
Definition: c.h:792
#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 10870 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().

10871 {
10872  struct config_generic *record;
10873  ArrayType *newarray;
10874  int i;
10875  int index;
10876 
10877  Assert(name);
10878 
10879  /* test if the option is valid and we're allowed to set it */
10880  (void) validate_option_array_item(name, NULL, false);
10881 
10882  /* normalize name (converts obsolete GUC names to modern spellings) */
10883  record = find_option(name, false, WARNING);
10884  if (record)
10885  name = record->name;
10886 
10887  /* if array is currently null, then surely nothing to delete */
10888  if (!array)
10889  return NULL;
10890 
10891  newarray = NULL;
10892  index = 1;
10893 
10894  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
10895  {
10896  Datum d;
10897  char *val;
10898  bool isnull;
10899 
10900  d = array_ref(array, 1, &i,
10901  -1 /* varlenarray */ ,
10902  -1 /* TEXT's typlen */ ,
10903  false /* TEXT's typbyval */ ,
10904  TYPALIGN_INT /* TEXT's typalign */ ,
10905  &isnull);
10906  if (isnull)
10907  continue;
10908  val = TextDatumGetCString(d);
10909 
10910  /* ignore entry if it's what we want to delete */
10911  if (strncmp(val, name, strlen(name)) == 0
10912  && val[strlen(name)] == '=')
10913  continue;
10914 
10915  /* else add it to the output array */
10916  if (newarray)
10917  newarray = array_set(newarray, 1, &index,
10918  d,
10919  false,
10920  -1 /* varlenarray */ ,
10921  -1 /* TEXT's typlen */ ,
10922  false /* TEXT's typbyval */ ,
10923  TYPALIGN_INT /* TEXT's typalign */ );
10924  else
10925  newarray = construct_array(&d, 1,
10926  TEXTOID,
10927  -1, false, TYPALIGN_INT);
10928 
10929  index++;
10930  }
10931 
10932  return newarray;
10933 }
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:11016
#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:367
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:5297
#define Assert(condition)
Definition: c.h:792
const char * name
Definition: encode.c:515
int i
long val
Definition: informix.c:664

◆ GUCArrayReset()

ArrayType* GUCArrayReset ( ArrayType array)

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

10943 {
10944  ArrayType *newarray;
10945  int i;
10946  int index;
10947 
10948  /* if array is currently null, nothing to do */
10949  if (!array)
10950  return NULL;
10951 
10952  /* if we're superuser, we can delete everything, so just do it */
10953  if (superuser())
10954  return NULL;
10955 
10956  newarray = NULL;
10957  index = 1;
10958 
10959  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
10960  {
10961  Datum d;
10962  char *val;
10963  char *eqsgn;
10964  bool isnull;
10965 
10966  d = array_ref(array, 1, &i,
10967  -1 /* varlenarray */ ,
10968  -1 /* TEXT's typlen */ ,
10969  false /* TEXT's typbyval */ ,
10970  TYPALIGN_INT /* TEXT's typalign */ ,
10971  &isnull);
10972  if (isnull)
10973  continue;
10974  val = TextDatumGetCString(d);
10975 
10976  eqsgn = strchr(val, '=');
10977  *eqsgn = '\0';
10978 
10979  /* skip if we have permission to delete it */
10980  if (validate_option_array_item(val, NULL, true))
10981  continue;
10982 
10983  /* else add it to the output array */
10984  if (newarray)
10985  newarray = array_set(newarray, 1, &index,
10986  d,
10987  false,
10988  -1 /* varlenarray */ ,
10989  -1 /* TEXT's typlen */ ,
10990  false /* TEXT's typbyval */ ,
10991  TYPALIGN_INT /* TEXT's typalign */ );
10992  else
10993  newarray = construct_array(&d, 1,
10994  TEXTOID,
10995  -1, false, TYPALIGN_INT);
10996 
10997  index++;
10998  pfree(val);
10999  }
11000 
11001  return newarray;
11002 }
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:1057
static bool validate_option_array_item(const char *name, const char *value, bool skipIfNoPermissions)
Definition: guc.c:11016
#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:367
int i
long val
Definition: informix.c:664

◆ InitializeGUCOptions()

void InitializeGUCOptions ( void  )

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

5393 {
5394  int i;
5395 
5396  /*
5397  * Before log_line_prefix could possibly receive a nonempty setting, make
5398  * sure that timezone processing is minimally alive (see elog.c).
5399  */
5401 
5402  /*
5403  * Build sorted array of all GUC variables.
5404  */
5406 
5407  /*
5408  * Load all variables with their compiled-in defaults, and initialize
5409  * status fields as needed.
5410  */
5411  for (i = 0; i < num_guc_variables; i++)
5412  {
5414  }
5415 
5416  guc_dirty = false;
5417 
5418  reporting_enabled = false;
5419 
5420  /*
5421  * Prevent any attempt to override the transaction modes from
5422  * non-interactive sources.
5423  */
5424  SetConfigOption("transaction_isolation", "read committed",
5426  SetConfigOption("transaction_read_only", "no",
5428  SetConfigOption("transaction_deferrable", "no",
5430 
5431  /*
5432  * For historical reasons, some GUC parameters can receive defaults from
5433  * environment variables. Process those settings.
5434  */
5436 }
void build_guc_variables(void)
Definition: guc.c:5124
static void InitializeGUCOptionsFromEnvironment(void)
Definition: guc.c:5448
void pg_timezone_initialize(void)
Definition: pgtz.c:361
static int num_guc_variables
Definition: guc.c:4861
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:7879
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:5494
static struct config_generic ** guc_variables
Definition: guc.c:4858
int i
static bool reporting_enabled
Definition: guc.c:4869
static bool guc_dirty
Definition: guc.c:4867

◆ NewGUCNestLevel()

◆ parse_int()

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

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

6628 {
6629  /*
6630  * We assume here that double is wide enough to represent any integer
6631  * value with adequate precision.
6632  */
6633  double val;
6634  char *endptr;
6635 
6636  /* To suppress compiler warnings, always set output params */
6637  if (result)
6638  *result = 0;
6639  if (hintmsg)
6640  *hintmsg = NULL;
6641 
6642  /*
6643  * Try to parse as an integer (allowing octal or hex input). If the
6644  * conversion stops at a decimal point or 'e', or overflows, re-parse as
6645  * float. This should work fine as long as we have no unit names starting
6646  * with 'e'. If we ever do, the test could be extended to check for a
6647  * sign or digit after 'e', but for now that's unnecessary.
6648  */
6649  errno = 0;
6650  val = strtol(value, &endptr, 0);
6651  if (*endptr == '.' || *endptr == 'e' || *endptr == 'E' ||
6652  errno == ERANGE)
6653  {
6654  errno = 0;
6655  val = strtod(value, &endptr);
6656  }
6657 
6658  if (endptr == value || errno == ERANGE)
6659  return false; /* no HINT for these cases */
6660 
6661  /* reject NaN (infinities will fail range check below) */
6662  if (isnan(val))
6663  return false; /* treat same as syntax error; no HINT */
6664 
6665  /* allow whitespace between number and unit */
6666  while (isspace((unsigned char) *endptr))
6667  endptr++;
6668 
6669  /* Handle possible unit */
6670  if (*endptr != '\0')
6671  {
6672  if ((flags & GUC_UNIT) == 0)
6673  return false; /* this setting does not accept a unit */
6674 
6675  if (!convert_to_base_unit(val,
6676  endptr, (flags & GUC_UNIT),
6677  &val))
6678  {
6679  /* invalid unit, or garbage after the unit; set hint and fail. */
6680  if (hintmsg)
6681  {
6682  if (flags & GUC_UNIT_MEMORY)
6683  *hintmsg = memory_units_hint;
6684  else
6685  *hintmsg = time_units_hint;
6686  }
6687  return false;
6688  }
6689  }
6690 
6691  /* Round to int, then check for overflow */
6692  val = rint(val);
6693 
6694  if (val > INT_MAX || val < INT_MIN)
6695  {
6696  if (hintmsg)
6697  *hintmsg = gettext_noop("Value exceeds integer range.");
6698  return false;
6699  }
6700 
6701  if (result)
6702  *result = (int) val;
6703  return true;
6704 }
static struct @144 value
#define gettext_noop(x)
Definition: c.h:1185
#define GUC_UNIT
Definition: guc.h:233
static const char * time_units_hint
Definition: guc.c:873
static bool convert_to_base_unit(double value, const char *unit, int base_unit, double *base_value)
Definition: guc.c:6427
long val
Definition: informix.c:664
static const char * memory_units_hint
Definition: guc.c:836
#define GUC_UNIT_MEMORY
Definition: guc.h:224

◆ parse_real()

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

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

6718 {
6719  double val;
6720  char *endptr;
6721 
6722  /* To suppress compiler warnings, always set output params */
6723  if (result)
6724  *result = 0;
6725  if (hintmsg)
6726  *hintmsg = NULL;
6727 
6728  errno = 0;
6729  val = strtod(value, &endptr);
6730 
6731  if (endptr == value || errno == ERANGE)
6732  return false; /* no HINT for these cases */
6733 
6734  /* reject NaN (infinities will fail range checks later) */
6735  if (isnan(val))
6736  return false; /* treat same as syntax error; no HINT */
6737 
6738  /* allow whitespace between number and unit */
6739  while (isspace((unsigned char) *endptr))
6740  endptr++;
6741 
6742  /* Handle possible unit */
6743  if (*endptr != '\0')
6744  {
6745  if ((flags & GUC_UNIT) == 0)
6746  return false; /* this setting does not accept a unit */
6747 
6748  if (!convert_to_base_unit(val,
6749  endptr, (flags & GUC_UNIT),
6750  &val))
6751  {
6752  /* invalid unit, or garbage after the unit; set hint and fail. */
6753  if (hintmsg)
6754  {
6755  if (flags & GUC_UNIT_MEMORY)
6756  *hintmsg = memory_units_hint;
6757  else
6758  *hintmsg = time_units_hint;
6759  }
6760  return false;
6761  }
6762  }
6763 
6764  if (result)
6765  *result = val;
6766  return true;
6767 }
static struct @144 value
#define GUC_UNIT
Definition: guc.h:233
static const char * time_units_hint
Definition: guc.c:873
static bool convert_to_base_unit(double value, const char *unit, int base_unit, double *base_value)
Definition: guc.c:6427
long val
Definition: informix.c:664
static const char * memory_units_hint
Definition: guc.c:836
#define GUC_UNIT_MEMORY
Definition: guc.h:224

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

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

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

10695 {
10696  size_t equal_pos;
10697  char *cp;
10698 
10699  AssertArg(string);
10700  AssertArg(name);
10701  AssertArg(value);
10702 
10703  equal_pos = strcspn(string, "=");
10704 
10705  if (string[equal_pos] == '=')
10706  {
10707  *name = guc_malloc(FATAL, equal_pos + 1);
10708  strlcpy(*name, string, equal_pos + 1);
10709 
10710  *value = guc_strdup(FATAL, &string[equal_pos + 1]);
10711  }
10712  else
10713  {
10714  /* no equal sign in string */
10715  *name = guc_strdup(FATAL, string);
10716  *value = NULL;
10717  }
10718 
10719  for (cp = *name; *cp; cp++)
10720  if (*cp == '-')
10721  *cp = '_';
10722 }
static struct @144 value
static char * guc_strdup(int elevel, const char *src)
Definition: guc.c:4933
#define FATAL
Definition: elog.h:54
#define AssertArg(condition)
Definition: c.h:794
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:4901

◆ ProcessConfigFile()

◆ ProcessGUCArray()

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

Definition at line 10732 of file guc.c.

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

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

10734 {
10735  int i;
10736 
10737  Assert(array != NULL);
10738  Assert(ARR_ELEMTYPE(array) == TEXTOID);
10739  Assert(ARR_NDIM(array) == 1);
10740  Assert(ARR_LBOUND(array)[0] == 1);
10741 
10742  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
10743  {
10744  Datum d;
10745  bool isnull;
10746  char *s;
10747  char *name;
10748  char *value;
10749 
10750  d = array_ref(array, 1, &i,
10751  -1 /* varlenarray */ ,
10752  -1 /* TEXT's typlen */ ,
10753  false /* TEXT's typbyval */ ,
10754  TYPALIGN_INT /* TEXT's typalign */ ,
10755  &isnull);
10756 
10757  if (isnull)
10758  continue;
10759 
10760  s = TextDatumGetCString(d);
10761 
10762  ParseLongOption(s, &name, &value);
10763  if (!value)
10764  {
10765  ereport(WARNING,
10766  (errcode(ERRCODE_SYNTAX_ERROR),
10767  errmsg("could not parse setting for parameter \"%s\"",
10768  name)));
10769  free(name);
10770  continue;
10771  }
10772 
10773  (void) set_config_option(name, value,
10774  context, source,
10775  action, true, 0, false);
10776 
10777  free(name);
10778  if (value)
10779  free(value);
10780  pfree(s);
10781  }
10782 }
void ParseLongOption(const char *string, char **name, char **value)
Definition: guc.c:10694
static struct @144 value
int errcode(int sqlerrcode)
Definition: elog.c:704
#define ARR_LBOUND(a)
Definition: array.h:289
void pfree(void *pointer)
Definition: mcxt.c:1057
#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:367
#define ereport(elevel,...)
Definition: elog.h:155
#define free(a)
Definition: header.h:65
#define Assert(condition)
Definition: c.h:792
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:915
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:7083
#define ARR_ELEMTYPE(a)
Definition: array.h:285
GucContext context
Definition: guc_tables.h:150

◆ ReportChangedGUCOptions()

void ReportChangedGUCOptions ( void  )

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

6342 {
6343  /* Quick exit if not (yet) enabled */
6344  if (!reporting_enabled)
6345  return;
6346 
6347  /*
6348  * Since in_hot_standby isn't actually changed by normal GUC actions, we
6349  * need a hack to check whether a new value needs to be reported to the
6350  * client. For speed, we rely on the assumption that it can never
6351  * transition from false to true.
6352  */
6354  {
6355  struct config_generic *record;
6356 
6357  record = find_option("in_hot_standby", false, ERROR);
6358  Assert(record != NULL);
6359  record->status |= GUC_NEEDS_REPORT;
6360  report_needed = true;
6361  in_hot_standby = false;
6362  }
6363 
6364  /* Quick exit if no values have been changed */
6365  if (!report_needed)
6366  return;
6367 
6368  /* Transmit new values of interesting variables */
6369  for (int i = 0; i < num_guc_variables; i++)
6370  {
6371  struct config_generic *conf = guc_variables[i];
6372 
6373  if ((conf->flags & GUC_REPORT) && (conf->status & GUC_NEEDS_REPORT))
6374  ReportGUCOption(conf);
6375  }
6376 
6377  report_needed = false;
6378 }
static bool report_needed
Definition: guc.c:4871
static bool in_hot_standby
Definition: guc.c:615
bool RecoveryInProgress(void)
Definition: xlog.c:8148
#define ERROR
Definition: elog.h:45
static int num_guc_variables
Definition: guc.c:4861
#define GUC_REPORT
Definition: guc.h:209
static struct config_generic ** guc_variables
Definition: guc.c:4858
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:5297
#define Assert(condition)
Definition: c.h:792
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:6387
static bool reporting_enabled
Definition: guc.c:4869
#define GUC_NEEDS_REPORT
Definition: guc_tables.h:178

◆ ResetAllOptions()

void ResetAllOptions ( void  )

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

5791 {
5792  int i;
5793 
5794  for (i = 0; i < num_guc_variables; i++)
5795  {
5796  struct config_generic *gconf = guc_variables[i];
5797 
5798  /* Don't reset non-SET-able values */
5799  if (gconf->context != PGC_SUSET &&
5800  gconf->context != PGC_USERSET)
5801  continue;
5802  /* Don't reset if special exclusion from RESET ALL */
5803  if (gconf->flags & GUC_NO_RESET_ALL)
5804  continue;
5805  /* No need to reset if wasn't SET */
5806  if (gconf->source <= PGC_S_OVERRIDE)
5807  continue;
5808 
5809  /* Save old value to support transaction abort */
5811 
5812  switch (gconf->vartype)
5813  {
5814  case PGC_BOOL:
5815  {
5816  struct config_bool *conf = (struct config_bool *) gconf;
5817 
5818  if (conf->assign_hook)
5819  conf->assign_hook(conf->reset_val,
5820  conf->reset_extra);
5821  *conf->variable = conf->reset_val;
5822  set_extra_field(&conf->gen, &conf->gen.extra,
5823  conf->reset_extra);
5824  break;
5825  }
5826  case PGC_INT:
5827  {
5828  struct config_int *conf = (struct config_int *) gconf;
5829 
5830  if (conf->assign_hook)
5831  conf->assign_hook(conf->reset_val,
5832  conf->reset_extra);
5833  *conf->variable = conf->reset_val;
5834  set_extra_field(&conf->gen, &conf->gen.extra,
5835  conf->reset_extra);
5836  break;
5837  }
5838  case PGC_REAL:
5839  {
5840  struct config_real *conf = (struct config_real *) gconf;
5841 
5842  if (conf->assign_hook)
5843  conf->assign_hook(conf->reset_val,
5844  conf->reset_extra);
5845  *conf->variable = conf->reset_val;
5846  set_extra_field(&conf->gen, &conf->gen.extra,
5847  conf->reset_extra);
5848  break;
5849  }
5850  case PGC_STRING:
5851  {
5852  struct config_string *conf = (struct config_string *) gconf;
5853 
5854  if (conf->assign_hook)
5855  conf->assign_hook(conf->reset_val,
5856  conf->reset_extra);
5857  set_string_field(conf, conf->variable, conf->reset_val);
5858  set_extra_field(&conf->gen, &conf->gen.extra,
5859  conf->reset_extra);
5860  break;
5861  }
5862  case PGC_ENUM:
5863  {
5864  struct config_enum *conf = (struct config_enum *) gconf;
5865 
5866  if (conf->assign_hook)
5867  conf->assign_hook(conf->reset_val,
5868  conf->reset_extra);
5869  *conf->variable = conf->reset_val;
5870  set_extra_field(&conf->gen, &conf->gen.extra,
5871  conf->reset_extra);
5872  break;
5873  }
5874  }
5875 
5876  gconf->source = gconf->reset_source;
5877  gconf->scontext = gconf->reset_scontext;
5878 
5879  if (gconf->flags & GUC_REPORT)
5880  {
5881  gconf->status |= GUC_NEEDS_REPORT;
5882  report_needed = true;
5883  }
5884  }
5885 }
GucSource source
Definition: guc_tables.h:158
void * reset_extra
Definition: guc_tables.h:210
static bool report_needed
Definition: guc.c:4871
GucRealAssignHook assign_hook
Definition: guc_tables.h:222
double reset_val
Definition: guc_tables.h:225
#define GUC_NO_RESET_ALL
Definition: guc.h:208
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:5893
int * variable
Definition: guc_tables.h:201
int * variable
Definition: guc_tables.h:247
static int num_guc_variables
Definition: guc.c:4861
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:5034
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:209
double * variable
Definition: guc_tables.h:217
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4973
static struct config_generic ** guc_variables
Definition: guc.c:4858
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 10620 of file guc.c.

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

Referenced by ParallelWorkerMain().

10621 {
10622  char *varname,
10623  *varvalue,
10624  *varsourcefile;
10625  int varsourceline;
10626  GucSource varsource;
10627  GucContext varscontext;
10628  char *srcptr = (char *) gucstate;
10629  char *srcend;
10630  Size len;
10631  int i;
10632  ErrorContextCallback error_context_callback;
10633 
10634  /* See comment at can_skip_gucvar(). */
10635  for (i = 0; i < num_guc_variables; i++)
10636  if (!can_skip_gucvar(guc_variables[i]))
10638 
10639  /* First item is the length of the subsequent data */
10640  memcpy(&len, gucstate, sizeof(len));
10641 
10642  srcptr += sizeof(len);
10643  srcend = srcptr + len;
10644 
10645  /* If the GUC value check fails, we want errors to show useful context. */
10646  error_context_callback.callback = guc_restore_error_context_callback;
10647  error_context_callback.previous = error_context_stack;
10648  error_context_callback.arg = NULL;
10649  error_context_stack = &error_context_callback;
10650 
10651  while (srcptr < srcend)
10652  {
10653  int result;
10654  char *error_context_name_and_value[2];
10655 
10656  varname = read_gucstate(&srcptr, srcend);
10657  varvalue = read_gucstate(&srcptr, srcend);
10658  varsourcefile = read_gucstate(&srcptr, srcend);
10659  if (varsourcefile[0])
10660  read_gucstate_binary(&srcptr, srcend,
10661  &varsourceline, sizeof(varsourceline));
10662  else
10663  varsourceline = 0;
10664  read_gucstate_binary(&srcptr, srcend,
10665  &varsource, sizeof(varsource));
10666  read_gucstate_binary(&srcptr, srcend,
10667  &varscontext, sizeof(varscontext));
10668 
10669  error_context_name_and_value[0] = varname;
10670  error_context_name_and_value[1] = varvalue;
10671  error_context_callback.arg = &error_context_name_and_value[0];
10672  result = set_config_option(varname, varvalue, varscontext, varsource,
10673  GUC_ACTION_SET, true, ERROR, true);
10674  if (result <= 0)
10675  ereport(ERROR,
10676  (errcode(ERRCODE_INTERNAL_ERROR),
10677  errmsg("parameter \"%s\" could not be set", varname)));
10678  if (varsourcefile[0])
10679  set_config_sourcefile(varname, varsourcefile, varsourceline);
10680  error_context_callback.arg = NULL;
10681  }
10682 
10683  error_context_stack = error_context_callback.previous;
10684 }
GucContext
Definition: guc.h:68
static void static void set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
Definition: guc.c:7845
static void read_gucstate_binary(char **srcptr, char *srcend, void *dest, Size size)
Definition: guc.c:10590
int errcode(int sqlerrcode)
Definition: elog.c:704
void(* callback)(void *arg)
Definition: elog.h:243
struct ErrorContextCallback * previous
Definition: elog.h:242
GucSource
Definition: guc.h:105
ErrorContextCallback * error_context_stack
Definition: elog.c:93
#define ERROR
Definition: elog.h:45
static int num_guc_variables
Definition: guc.c:4861
static bool can_skip_gucvar(struct config_generic *gconf)
Definition: guc.c:10286
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:5494
static void guc_restore_error_context_callback(void *arg)
Definition: guc.c:10604
static struct config_generic ** guc_variables
Definition: guc.c:4858
static char * read_gucstate(char **srcptr, char *srcend)
Definition: guc.c:10567
#define ereport(elevel,...)
Definition: elog.h:155
size_t Size
Definition: c.h:528
int errmsg(const char *fmt,...)
Definition: elog.c:915
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:7083

◆ SelectConfigFiles()

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

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

5616 {
5617  char *configdir;
5618  char *fname;
5619  struct stat stat_buf;
5620 
5621  /* configdir is -D option, or $PGDATA if no -D */
5622  if (userDoption)
5623  configdir = make_absolute_path(userDoption);
5624  else
5625  configdir = make_absolute_path(getenv("PGDATA"));
5626 
5627  if (configdir && stat(configdir, &stat_buf) != 0)
5628  {
5629  write_stderr("%s: could not access directory \"%s\": %s\n",
5630  progname,
5631  configdir,
5632  strerror(errno));
5633  if (errno == ENOENT)
5634  write_stderr("Run initdb or pg_basebackup to initialize a PostgreSQL data directory.\n");
5635  return false;
5636  }
5637 
5638  /*
5639  * Find the configuration file: if config_file was specified on the
5640  * command line, use it, else use configdir/postgresql.conf. In any case
5641  * ensure the result is an absolute path, so that it will be interpreted
5642  * the same way by future backends.
5643  */
5644  if (ConfigFileName)
5646  else if (configdir)
5647  {
5648  fname = guc_malloc(FATAL,
5649  strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
5650  sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
5651  }
5652  else
5653  {
5654  write_stderr("%s does not know where to find the server configuration file.\n"
5655  "You must specify the --config-file or -D invocation "
5656  "option or set the PGDATA environment variable.\n",
5657  progname);
5658  return false;
5659  }
5660 
5661  /*
5662  * Set the ConfigFileName GUC variable to its final value, ensuring that
5663  * it can't be overridden later.
5664  */
5665  SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
5666  free(fname);
5667 
5668  /*
5669  * Now read the config file for the first time.
5670  */
5671  if (stat(ConfigFileName, &stat_buf) != 0)
5672  {
5673  write_stderr("%s: could not access the server configuration file \"%s\": %s\n",
5674  progname, ConfigFileName, strerror(errno));
5675  free(configdir);
5676  return false;
5677  }
5678 
5679  /*
5680  * Read the configuration file for the first time. This time only the
5681  * data_directory parameter is picked up to determine the data directory,
5682  * so that we can read the PG_AUTOCONF_FILENAME file next time.
5683  */
5685 
5686  /*
5687  * If the data_directory GUC variable has been set, use that as DataDir;
5688  * otherwise use configdir if set; else punt.
5689  *
5690  * Note: SetDataDir will copy and absolute-ize its argument, so we don't
5691  * have to.
5692  */
5693  if (data_directory)
5695  else if (configdir)
5696  SetDataDir(configdir);
5697  else
5698  {
5699  write_stderr("%s does not know where to find the database system data.\n"
5700  "This can be specified as \"data_directory\" in \"%s\", "
5701  "or by the -D invocation option, or by the "
5702  "PGDATA environment variable.\n",
5704  return false;
5705  }
5706 
5707  /*
5708  * Reflect the final DataDir value back into the data_directory GUC var.
5709  * (If you are wondering why we don't just make them a single variable,
5710  * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
5711  * child backends specially. XXX is that still true? Given that we now
5712  * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
5713  * DataDir in advance.)
5714  */
5716 
5717  /*
5718  * Now read the config file a second time, allowing any settings in the
5719  * PG_AUTOCONF_FILENAME file to take effect. (This is pretty ugly, but
5720  * since we have to determine the DataDir before we can find the autoconf
5721  * file, the alternatives seem worse.)
5722  */
5724 
5725  /*
5726  * If timezone_abbreviations wasn't set in the configuration file, install
5727  * the default value. We do it this way because we can't safely install a
5728  * "real" value until my_exec_path is set, which may not have happened
5729  * when InitializeGUCOptions runs, so the bootstrap default value cannot
5730  * be the real desired default.
5731  */
5733 
5734  /*
5735  * Figure out where pg_hba.conf is, and make sure the path is absolute.
5736  */
5737  if (HbaFileName)
5739  else if (configdir)
5740  {
5741  fname = guc_malloc(FATAL,
5742  strlen(configdir) + strlen(HBA_FILENAME) + 2);
5743  sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
5744  }
5745  else
5746  {
5747  write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
5748  "This can be specified as \"hba_file\" in \"%s\", "
5749  "or by the -D invocation option, or by the "
5750  "PGDATA environment variable.\n",
5752  return false;
5753  }
5754  SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
5755  free(fname);
5756 
5757  /*
5758  * Likewise for pg_ident.conf.
5759  */
5760  if (IdentFileName)
5762  else if (configdir)
5763  {
5764  fname = guc_malloc(FATAL,
5765  strlen(configdir) + strlen(IDENT_FILENAME) + 2);
5766  sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
5767  }
5768  else
5769  {
5770  write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
5771  "This can be specified as \"ident_file\" in \"%s\", "
5772  "or by the -D invocation option, or by the "
5773  "PGDATA environment variable.\n",
5775  return false;
5776  }
5777  SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
5778  free(fname);
5779 
5780  free(configdir);
5781 
5782  return true;
5783 }
char * make_absolute_path(const char *path)
Definition: path.c:608
void ProcessConfigFile(GucContext context)
void SetDataDir(const char *dir)
Definition: miscinit.c:395
char * ConfigFileName
Definition: guc.c:558
static void pg_timezone_abbrev_initialize(void)
Definition: guc.c:11584
#define CONFIG_FILENAME
Definition: guc.c:110
#define write_stderr(str)
Definition: parallel.c:186
const char * progname
Definition: pg_standby.c:36
char * HbaFileName
Definition: guc.c:559
#define sprintf
Definition: port.h:217
#define HBA_FILENAME
Definition: guc.c:111
struct stat stat_buf
Definition: pg_standby.c:100
#define FATAL
Definition: elog.h:54
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:7879
char * IdentFileName
Definition: guc.c:560
#define IDENT_FILENAME
Definition: guc.c:112
#define free(a)
Definition: header.h:65
#define strerror
Definition: port.h:228
static const char * userDoption
Definition: postgres.c:158
char * DataDir
Definition: globals.c:63
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4901
static char * data_directory
Definition: guc.c:604
#define stat
Definition: win32_port.h:275

◆ SerializeGUCState()

void SerializeGUCState ( Size  maxsize,
char *  start_address 
)

Definition at line 10540 of file guc.c.

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

Referenced by InitializeParallelDSM().

10541 {
10542  char *curptr;
10543  Size actual_size;
10544  Size bytes_left;
10545  int i;
10546 
10547  /* Reserve space for saving the actual size of the guc state */
10548  Assert(maxsize > sizeof(actual_size));
10549  curptr = start_address + sizeof(actual_size);
10550  bytes_left = maxsize - sizeof(actual_size);
10551 
10552  for (i = 0; i < num_guc_variables; i++)
10553  serialize_variable(&curptr, &bytes_left, guc_variables[i]);
10554 
10555  /* Store actual size without assuming alignment of start_address. */
10556  actual_size = maxsize - bytes_left - sizeof(actual_size);
10557  memcpy(start_address, &actual_size, sizeof(actual_size));
10558 }
static void serialize_variable(char **destptr, Size *maxbytes, struct config_generic *gconf)
Definition: guc.c:10466
static int num_guc_variables
Definition: guc.c:4861
static struct config_generic ** guc_variables
Definition: guc.c:4858
#define Assert(condition)
Definition: c.h:792
size_t Size
Definition: c.h:528
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 7083 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().

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