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_RUNTIME_COMPUTED   0x200000
 
#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:160
char * format_elog_string(const char *fmt,...)
Definition: elog.c:1476
void pre_format_elog_string(int errnumber, const char *domain)
Definition: elog.c:1467

Definition at line 426 of file guc.h.

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

◆ GUC_check_errmsg

#define GUC_check_errmsg

◆ GUC_CUSTOM_PLACEHOLDER

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

◆ GUC_DISALLOW_IN_AUTO_FILE

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

Definition at line 215 of file guc.h.

Referenced by AlterSystemSetConfigFile().

◆ GUC_DISALLOW_IN_FILE

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

Definition at line 210 of file guc.h.

Referenced by AlterSystemSetConfigFile(), and displayStruct().

◆ GUC_EXPLAIN

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

Definition at line 230 of file guc.h.

Referenced by get_explain_guc_options().

◆ GUC_IS_NAME

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

Definition at line 213 of file guc.h.

Referenced by parse_and_validate_value().

◆ GUC_LIST_INPUT

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

Definition at line 204 of file guc.h.

Referenced by _PG_init(), and flatten_set_variable_args().

◆ GUC_LIST_QUOTE

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

Definition at line 205 of file guc.h.

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

◆ GUC_NO_RESET_ALL

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

Definition at line 207 of file guc.h.

Referenced by ResetAllOptions().

◆ GUC_NO_SHOW_ALL

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

◆ GUC_NOT_IN_SAMPLE

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

Definition at line 209 of file guc.h.

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

◆ GUC_NOT_WHILE_SEC_REST

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

Definition at line 214 of file guc.h.

Referenced by set_config_option().

◆ GUC_QUALIFIER_SEPARATOR

#define GUC_QUALIFIER_SEPARATOR   '.'

Definition at line 199 of file guc.h.

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

◆ GUC_REPORT

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

◆ GUC_RUNTIME_COMPUTED

#define GUC_RUNTIME_COMPUTED   0x200000

Definition at line 236 of file guc.h.

Referenced by PostmasterMain().

◆ 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 238 of file guc.h.

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

◆ GUC_UNIT_BLOCKS

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

Definition at line 219 of file guc.h.

Referenced by get_config_unit_name().

◆ GUC_UNIT_BYTE

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

Definition at line 222 of file guc.h.

Referenced by get_config_unit_name().

◆ GUC_UNIT_KB

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

Definition at line 218 of file guc.h.

Referenced by get_config_unit_name().

◆ GUC_UNIT_MB

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

Definition at line 221 of file guc.h.

Referenced by get_config_unit_name().

◆ GUC_UNIT_MEMORY

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

◆ GUC_UNIT_MIN

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

Definition at line 227 of file guc.h.

Referenced by get_config_unit_name().

◆ GUC_UNIT_MS

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

Definition at line 225 of file guc.h.

Referenced by _PG_init(), and get_config_unit_name().

◆ GUC_UNIT_S

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

Definition at line 226 of file guc.h.

Referenced by _PG_init(), and get_config_unit_name().

◆ GUC_UNIT_TIME

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

Definition at line 228 of file guc.h.

Referenced by get_config_unit_name().

◆ GUC_UNIT_XBLOCKS

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

Definition at line 220 of file guc.h.

Referenced by get_config_unit_name().

◆ MAX_KILOBYTES

#define MAX_KILOBYTES   (INT_MAX / 1024)

Definition at line 26 of file guc.h.

◆ PG_AUTOCONF_FILENAME

#define PG_AUTOCONF_FILENAME   "postgresql.auto.conf"

Definition at line 34 of file guc.h.

Referenced by AlterSystemSetConfigFile().

Typedef Documentation

◆ ConfigVariable

◆ GucBoolAssignHook

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

Definition at line 180 of file guc.h.

◆ GucBoolCheckHook

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

Definition at line 174 of file guc.h.

◆ GucEnumAssignHook

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

Definition at line 184 of file guc.h.

◆ GucEnumCheckHook

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

Definition at line 178 of file guc.h.

◆ GucIntAssignHook

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

Definition at line 181 of file guc.h.

◆ GucIntCheckHook

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

Definition at line 175 of file guc.h.

◆ GucRealAssignHook

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

Definition at line 182 of file guc.h.

◆ GucRealCheckHook

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

Definition at line 176 of file guc.h.

◆ GucShowHook

typedef const char*(* GucShowHook) (void)

Definition at line 186 of file guc.h.

◆ GucStringAssignHook

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

Definition at line 183 of file guc.h.

◆ GucStringCheckHook

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

Definition at line 177 of file guc.h.

Enumeration Type Documentation

◆ GucAction

enum GucAction
Enumerator
GUC_ACTION_SET 
GUC_ACTION_LOCAL 
GUC_ACTION_SAVE 

Definition at line 191 of file guc.h.

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

◆ GucContext

enum GucContext
Enumerator
PGC_INTERNAL 
PGC_POSTMASTER 
PGC_SIGHUP 
PGC_SU_BACKEND 
PGC_BACKEND 
PGC_SUSET 
PGC_USERSET 

Definition at line 68 of file guc.h.

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

◆ GucSource

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

Definition at line 104 of file guc.h.

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

Function Documentation

◆ AlterSystemSetConfigFile()

void AlterSystemSetConfigFile ( AlterSystemStmt altersysstmt)

Definition at line 8500 of file guc.c.

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

Referenced by standard_ProcessUtility().

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

◆ assign_search_path()

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

Definition at line 4353 of file namespace.c.

References baseSearchPathValid.

4354 {
4355  /*
4356  * We mark the path as needing recomputation, but don't do anything until
4357  * it's needed. This avoids trying to do database access during GUC
4358  * initialization, or outside a transaction.
4359  */
4360  baseSearchPathValid = false;
4361 }
static bool baseSearchPathValid
Definition: namespace.c:160

◆ assign_temp_tablespaces()

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

Definition at line 1307 of file tablespace.c.

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

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

◆ assign_xlog_sync_method()

void assign_xlog_sync_method ( int  new_sync_method,
void *  extra 
)

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

10603 {
10604  if (sync_method != new_sync_method)
10605  {
10606  /*
10607  * To ensure that no blocks escape unsynced, force an fsync on the
10608  * currently open log segment (if any). Also, if the open flag is
10609  * changing, close the log file so it will be reopened (with new flag
10610  * bit) at next use.
10611  */
10612  if (openLogFile >= 0)
10613  {
10615  if (pg_fsync(openLogFile) != 0)
10616  {
10617  char xlogfname[MAXFNAMELEN];
10618  int save_errno;
10619 
10620  save_errno = errno;
10623  errno = save_errno;
10624  ereport(PANIC,
10626  errmsg("could not fsync file \"%s\": %m", xlogfname)));
10627  }
10628 
10630  if (get_sync_bit(sync_method) != get_sync_bit(new_sync_method))
10631  XLogFileClose();
10632  }
10633  }
10634 }
static void pgstat_report_wait_end(void)
Definition: wait_event.h:278
int wal_segment_size
Definition: xlog.c:119
static int get_sync_bit(int method)
Definition: xlog.c:10546
#define PANIC
Definition: elog.h:50
static XLogSegNo openLogSegNo
Definition: xlog.c:799
static void XLogFileClose(void)
Definition: xlog.c:3884
int errcode_for_file_access(void)
Definition: elog.c:721
static void pgstat_report_wait_start(uint32 wait_event_info)
Definition: wait_event.h:262
#define MAXFNAMELEN
static int openLogFile
Definition: xlog.c:798
TimeLineID ThisTimeLineID
Definition: xlog.c:194
#define ereport(elevel,...)
Definition: elog.h:157
#define XLogFileName(fname, tli, logSegNo, wal_segsz_bytes)
int sync_method
Definition: xlog.c:107
int errmsg(const char *fmt,...)
Definition: elog.c:909
int pg_fsync(int fd)
Definition: fd.c:357

◆ AtEOXact_GUC()

void AtEOXact_GUC ( bool  isCommit,
int  nestLevel 
)

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

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

◆ AtStart_GUC()

void AtStart_GUC ( void  )

Definition at line 6196 of file guc.c.

References elog, and WARNING.

Referenced by StartTransaction().

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

◆ BeginReportingGUCOptions()

void BeginReportingGUCOptions ( void  )

Definition at line 6515 of file guc.c.

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

Referenced by PostgresMain().

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

◆ check_default_tablespace()

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

Definition at line 1092 of file tablespace.c.

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

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

◆ check_search_path()

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

Definition at line 4319 of file namespace.c.

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

4320 {
4321  char *rawname;
4322  List *namelist;
4323 
4324  /* Need a modifiable copy of string */
4325  rawname = pstrdup(*newval);
4326 
4327  /* Parse string into list of identifiers */
4328  if (!SplitIdentifierString(rawname, ',', &namelist))
4329  {
4330  /* syntax error in name list */
4331  GUC_check_errdetail("List syntax is invalid.");
4332  pfree(rawname);
4333  list_free(namelist);
4334  return false;
4335  }
4336 
4337  /*
4338  * We used to try to check that the named schemas exist, but there are
4339  * many valid use-cases for having search_path settings that include
4340  * schemas that don't exist; and often, we are not inside a transaction
4341  * here and so can't consult the system catalogs anyway. So now, the only
4342  * requirement is syntactic validity of the identifier list.
4343  */
4344 
4345  pfree(rawname);
4346  list_free(namelist);
4347 
4348  return true;
4349 }
#define GUC_check_errdetail
Definition: guc.h:422
char * pstrdup(const char *in)
Definition: mcxt.c:1299
void pfree(void *pointer)
Definition: mcxt.c:1169
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3746
#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 1199 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.

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

◆ check_wal_buffers()

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

Definition at line 5034 of file xlog.c.

References XLOGbuffers, and XLOGChooseNumBuffers().

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

9172 {
9173  struct config_bool *var;
9174 
9175  var = (struct config_bool *)
9176  init_custom_variable(name, short_desc, long_desc, context, flags,
9177  PGC_BOOL, sizeof(struct config_bool));
9178  var->variable = valueAddr;
9179  var->boot_val = bootValue;
9180  var->reset_val = bootValue;
9181  var->check_hook = check_hook;
9182  var->assign_hook = assign_hook;
9183  var->show_hook = show_hook;
9184  define_custom_variable(&var->gen);
9185 }
bool * variable
Definition: guc_tables.h:179
GucBoolAssignHook assign_hook
Definition: guc_tables.h:182
bool boot_val
Definition: guc_tables.h:180
struct config_generic gen
Definition: guc_tables.h:177
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:8921
GucBoolCheckHook check_hook
Definition: guc_tables.h:181
GucShowHook show_hook
Definition: guc_tables.h:183
const char * name
Definition: encode.c:561
bool reset_val
Definition: guc_tables.h:185
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8981

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

9284 {
9285  struct config_enum *var;
9286 
9287  var = (struct config_enum *)
9288  init_custom_variable(name, short_desc, long_desc, context, flags,
9289  PGC_ENUM, sizeof(struct config_enum));
9290  var->variable = valueAddr;
9291  var->boot_val = bootValue;
9292  var->reset_val = bootValue;
9293  var->options = options;
9294  var->check_hook = check_hook;
9295  var->assign_hook = assign_hook;
9296  var->show_hook = show_hook;
9297  define_custom_variable(&var->gen);
9298 }
GucEnumCheckHook check_hook
Definition: guc_tables.h:242
GucEnumAssignHook assign_hook
Definition: guc_tables.h:243
int * variable
Definition: guc_tables.h:239
const struct config_enum_entry * options
Definition: guc_tables.h:241
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:8921
GucShowHook show_hook
Definition: guc_tables.h:244
struct config_generic gen
Definition: guc_tables.h:237
const char * name
Definition: encode.c:561
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8981

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

9200 {
9201  struct config_int *var;
9202 
9203  var = (struct config_int *)
9204  init_custom_variable(name, short_desc, long_desc, context, flags,
9205  PGC_INT, sizeof(struct config_int));
9206  var->variable = valueAddr;
9207  var->boot_val = bootValue;
9208  var->reset_val = bootValue;
9209  var->min = minValue;
9210  var->max = maxValue;
9211  var->check_hook = check_hook;
9212  var->assign_hook = assign_hook;
9213  var->show_hook = show_hook;
9214  define_custom_variable(&var->gen);
9215 }
int boot_val
Definition: guc_tables.h:194
GucIntAssignHook assign_hook
Definition: guc_tables.h:198
GucIntCheckHook check_hook
Definition: guc_tables.h:197
GucShowHook show_hook
Definition: guc_tables.h:199
int * variable
Definition: guc_tables.h:193
struct config_generic gen
Definition: guc_tables.h:191
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:8921
const char * name
Definition: encode.c:561
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8981
int reset_val
Definition: guc_tables.h:201

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

9230 {
9231  struct config_real *var;
9232 
9233  var = (struct config_real *)
9234  init_custom_variable(name, short_desc, long_desc, context, flags,
9235  PGC_REAL, sizeof(struct config_real));
9236  var->variable = valueAddr;
9237  var->boot_val = bootValue;
9238  var->reset_val = bootValue;
9239  var->min = minValue;
9240  var->max = maxValue;
9241  var->check_hook = check_hook;
9242  var->assign_hook = assign_hook;
9243  var->show_hook = show_hook;
9244  define_custom_variable(&var->gen);
9245 }
GucRealAssignHook assign_hook
Definition: guc_tables.h:214
double reset_val
Definition: guc_tables.h:217
GucRealCheckHook check_hook
Definition: guc_tables.h:213
GucShowHook show_hook
Definition: guc_tables.h:215
double * variable
Definition: guc_tables.h:209
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:8921
double max
Definition: guc_tables.h:212
double boot_val
Definition: guc_tables.h:210
const char * name
Definition: encode.c:561
double min
Definition: guc_tables.h:211
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8981
struct config_generic gen
Definition: guc_tables.h:207

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

9258 {
9259  struct config_string *var;
9260 
9261  var = (struct config_string *)
9262  init_custom_variable(name, short_desc, long_desc, context, flags,
9263  PGC_STRING, sizeof(struct config_string));
9264  var->variable = valueAddr;
9265  var->boot_val = bootValue;
9266  var->check_hook = check_hook;
9267  var->assign_hook = assign_hook;
9268  var->show_hook = show_hook;
9269  define_custom_variable(&var->gen);
9270 }
char ** variable
Definition: guc_tables.h:225
GucStringCheckHook check_hook
Definition: guc_tables.h:227
const char * boot_val
Definition: guc_tables.h:226
GucShowHook show_hook
Definition: guc_tables.h:229
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:8921
struct config_generic gen
Definition: guc_tables.h:223
GucStringAssignHook assign_hook
Definition: guc_tables.h:228
const char * name
Definition: encode.c:561
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8981

◆ EmitWarningsOnPlaceholders()

void EmitWarningsOnPlaceholders ( const char *  className)

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

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

◆ EstimateGUCStateSpace()

Size EstimateGUCStateSpace ( void  )

Definition at line 10596 of file guc.c.

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

Referenced by InitializeParallelDSM().

10597 {
10598  Size size;
10599  int i;
10600 
10601  /* Add space reqd for saving the data size of the guc state */
10602  size = sizeof(Size);
10603 
10604  /* Add up the space needed for each GUC variable */
10605  for (i = 0; i < num_guc_variables; i++)
10606  size = add_size(size,
10608 
10609  return size;
10610 }
static int num_guc_variables
Definition: guc.c:5013
static struct config_generic ** guc_variables
Definition: guc.c:5010
Size add_size(Size s1, Size s2)
Definition: shmem.c:502
size_t Size
Definition: c.h:540
static Size estimate_variable_size(struct config_generic *gconf)
Definition: guc.c:10497
int i

◆ ExecSetVariableStmt()

void ExecSetVariableStmt ( VariableSetStmt stmt,
bool  isTopLevel 
)

Definition at line 8710 of file guc.c.

References generate_unaccent_rules::action, DefElem::arg, VariableSetStmt::args, 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, PGC_S_SESSION, PGC_SUSET, PGC_USERSET, ResetAllOptions(), set_config_option(), SetPGVariable(), strVal, superuser(), 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().

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

◆ ExtractSetVariableArgs()

char* ExtractSetVariableArgs ( VariableSetStmt stmt)

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

8834 {
8835  switch (stmt->kind)
8836  {
8837  case VAR_SET_VALUE:
8838  return flatten_set_variable_args(stmt->name, stmt->args);
8839  case VAR_SET_CURRENT:
8840  return GetConfigOptionByName(stmt->name, NULL, false);
8841  default:
8842  return NULL;
8843  }
8844 }
VariableSetKind kind
Definition: parsenodes.h:2153
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:9562
static char * flatten_set_variable_args(const char *name, List *args)
Definition: guc.c:8240

◆ FreeConfigVariables()

void FreeConfigVariables ( ConfigVariable list)

◆ GetConfigOption()

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

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

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

◆ GetConfigOptionByName()

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

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

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

◆ GetConfigOptionByNum()

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

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

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

◆ GetConfigOptionFlags()

int GetConfigOptionFlags ( const char *  name,
bool  missing_ok 
)

Definition at line 8217 of file guc.c.

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

Referenced by pg_get_functiondef(), and PostmasterMain().

8218 {
8219  struct config_generic *record;
8220 
8221  record = find_option(name, false, missing_ok, ERROR);
8222  if (record == NULL)
8223  return 0;
8224  return record->flags;
8225 }
#define ERROR
Definition: elog.h:46
static struct config_generic * find_option(const char *name, bool create_placeholders, bool skip_errors, int elevel)
Definition: guc.c:5499
const char * name
Definition: encode.c:561

◆ GetConfigOptionResetString()

const char* GetConfigOptionResetString ( const char *  name)

Definition at line 8171 of file guc.c.

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

Referenced by check_datestyle().

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

◆ GetNumConfigOptions()

int GetNumConfigOptions ( void  )

Definition at line 9820 of file guc.c.

References num_guc_variables.

Referenced by GucInfoMain(), and show_all_settings().

9821 {
9822  return num_guc_variables;
9823 }
static int num_guc_variables
Definition: guc.c:5013

◆ GetPGVariable()

void GetPGVariable ( const char *  name,
DestReceiver dest 
)

Definition at line 9327 of file guc.c.

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

Referenced by exec_replication_command(), and standard_ProcessUtility().

9328 {
9329  if (guc_name_compare(name, "all") == 0)
9330  ShowAllGUCConfig(dest);
9331  else
9332  ShowGUCConfigOption(name, dest);
9333 }
static void ShowGUCConfigOption(const char *name, DestReceiver *dest)
Definition: guc.c:9371
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:5580
static void ShowAllGUCConfig(DestReceiver *dest)
Definition: guc.c:9399
const char * name
Definition: encode.c:561

◆ GetPGVariableResultDesc()

TupleDesc GetPGVariableResultDesc ( const char *  name)

Definition at line 9336 of file guc.c.

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

Referenced by UtilityTupleDescriptor().

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

◆ GUC_check_errcode()

void GUC_check_errcode ( int  sqlerrcode)

◆ GUCArrayAdd()

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

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

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

◆ GUCArrayDelete()

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

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

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

◆ GUCArrayReset()

ArrayType* GUCArrayReset ( ArrayType array)

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

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

◆ InitializeGUCOptions()

void InitializeGUCOptions ( void  )

Definition at line 5614 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 BackendRun(), BootstrapModeMain(), PostgresMain(), and PostmasterMain().

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

◆ NewGUCNestLevel()

◆ parse_int()

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

Definition at line 6847 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 apply_server_options(), apply_table_options(), get_batch_size_option(), parse_and_validate_value(), parse_one_reloption(), postgres_fdw_validator(), and postgresAcquireSampleRowsFunc().

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

◆ parse_real()

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

Definition at line 6937 of file guc.c.

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

Referenced by apply_server_options(), parse_and_validate_value(), parse_one_reloption(), and postgres_fdw_validator().

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

◆ ParseConfigDirectory()

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

◆ ParseConfigFile()

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

◆ ParseConfigFp()

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

◆ ParseLongOption()

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

Definition at line 10990 of file guc.c.

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

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

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

◆ ProcessConfigFile()

◆ ProcessGUCArray()

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

Definition at line 11028 of file guc.c.

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

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

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

◆ ReportChangedGUCOptions()

void ReportChangedGUCOptions ( void  )

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

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

◆ ResetAllOptions()

void ResetAllOptions ( void  )

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

6013 {
6014  int i;
6015 
6016  for (i = 0; i < num_guc_variables; i++)
6017  {
6018  struct config_generic *gconf = guc_variables[i];
6019 
6020  /* Don't reset non-SET-able values */
6021  if (gconf->context != PGC_SUSET &&
6022  gconf->context != PGC_USERSET)
6023  continue;
6024  /* Don't reset if special exclusion from RESET ALL */
6025  if (gconf->flags & GUC_NO_RESET_ALL)
6026  continue;
6027  /* No need to reset if wasn't SET */
6028  if (gconf->source <= PGC_S_OVERRIDE)
6029  continue;
6030 
6031  /* Save old value to support transaction abort */
6033 
6034  switch (gconf->vartype)
6035  {
6036  case PGC_BOOL:
6037  {
6038  struct config_bool *conf = (struct config_bool *) gconf;
6039 
6040  if (conf->assign_hook)
6041  conf->assign_hook(conf->reset_val,
6042  conf->reset_extra);
6043  *conf->variable = conf->reset_val;
6044  set_extra_field(&conf->gen, &conf->gen.extra,
6045  conf->reset_extra);
6046  break;
6047  }
6048  case PGC_INT:
6049  {
6050  struct config_int *conf = (struct config_int *) gconf;
6051 
6052  if (conf->assign_hook)
6053  conf->assign_hook(conf->reset_val,
6054  conf->reset_extra);
6055  *conf->variable = conf->reset_val;
6056  set_extra_field(&conf->gen, &conf->gen.extra,
6057  conf->reset_extra);
6058  break;
6059  }
6060  case PGC_REAL:
6061  {
6062  struct config_real *conf = (struct config_real *) gconf;
6063 
6064  if (conf->assign_hook)
6065  conf->assign_hook(conf->reset_val,
6066  conf->reset_extra);
6067  *conf->variable = conf->reset_val;
6068  set_extra_field(&conf->gen, &conf->gen.extra,
6069  conf->reset_extra);
6070  break;
6071  }
6072  case PGC_STRING:
6073  {
6074  struct config_string *conf = (struct config_string *) gconf;
6075 
6076  if (conf->assign_hook)
6077  conf->assign_hook(conf->reset_val,
6078  conf->reset_extra);
6079  set_string_field(conf, conf->variable, conf->reset_val);
6080  set_extra_field(&conf->gen, &conf->gen.extra,
6081  conf->reset_extra);
6082  break;
6083  }
6084  case PGC_ENUM:
6085  {
6086  struct config_enum *conf = (struct config_enum *) gconf;
6087 
6088  if (conf->assign_hook)
6089  conf->assign_hook(conf->reset_val,
6090  conf->reset_extra);
6091  *conf->variable = conf->reset_val;
6092  set_extra_field(&conf->gen, &conf->gen.extra,
6093  conf->reset_extra);
6094  break;
6095  }
6096  }
6097 
6098  gconf->source = gconf->reset_source;
6099  gconf->scontext = gconf->reset_scontext;
6100 
6101  if (gconf->flags & GUC_REPORT)
6102  {
6103  gconf->status |= GUC_NEEDS_REPORT;
6104  report_needed = true;
6105  }
6106  }
6107 }
GucSource source
Definition: guc_tables.h:150
void * reset_extra
Definition: guc_tables.h:202
static bool report_needed
Definition: guc.c:5023
GucRealAssignHook assign_hook
Definition: guc_tables.h:214
double reset_val
Definition: guc_tables.h:217
#define GUC_NO_RESET_ALL
Definition: guc.h:207
char ** variable
Definition: guc_tables.h:225
bool * variable
Definition: guc_tables.h:179
GucEnumAssignHook assign_hook
Definition: guc_tables.h:243
GucBoolAssignHook assign_hook
Definition: guc_tables.h:182
GucContext scontext
Definition: guc_tables.h:152
GucIntAssignHook assign_hook
Definition: guc_tables.h:198
static void push_old_value(struct config_generic *gconf, GucAction action)
Definition: guc.c:6115
int * variable
Definition: guc_tables.h:193
int * variable
Definition: guc_tables.h:239
static int num_guc_variables
Definition: guc.c:5013
void * reset_extra
Definition: guc_tables.h:247
Definition: guc.h:75
static void set_extra_field(struct config_generic *gconf, void **field, void *newval)
Definition: guc.c:5186
GucSource reset_source
Definition: guc_tables.h:151
struct config_generic gen
Definition: guc_tables.h:177
struct config_generic gen
Definition: guc_tables.h:191
#define GUC_REPORT
Definition: guc.h:208
double * variable
Definition: guc_tables.h:209
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:5125
static struct config_generic ** guc_variables
Definition: guc.c:5010
enum config_type vartype
Definition: guc_tables.h:148
void * reset_extra
Definition: guc_tables.h:218
struct config_generic gen
Definition: guc_tables.h:237
struct config_generic gen
Definition: guc_tables.h:223
char * reset_val
Definition: guc_tables.h:231
GucStringAssignHook assign_hook
Definition: guc_tables.h:228
void * reset_extra
Definition: guc_tables.h:232
void * reset_extra
Definition: guc_tables.h:186
int i
bool reset_val
Definition: guc_tables.h:185
#define GUC_NEEDS_REPORT
Definition: guc_tables.h:170
GucContext context
Definition: guc_tables.h:142
struct config_generic gen
Definition: guc_tables.h:207
GucContext reset_scontext
Definition: guc_tables.h:153
int reset_val
Definition: guc_tables.h:201

◆ RestoreGUCState()

void RestoreGUCState ( void *  gucstate)

Definition at line 10825 of file guc.c.

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

Referenced by ParallelWorkerMain().

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

◆ SelectConfigFiles()

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

Definition at line 5837 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 BootstrapModeMain(), PostgresMain(), and PostmasterMain().

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

◆ SerializeGUCState()

void SerializeGUCState ( Size  maxsize,
char *  start_address 
)

Definition at line 10739 of file guc.c.

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

Referenced by InitializeParallelDSM().

10740 {
10741  char *curptr;
10742  Size actual_size;
10743  Size bytes_left;
10744  int i;
10745 
10746  /* Reserve space for saving the actual size of the guc state */
10747  Assert(maxsize > sizeof(actual_size));
10748  curptr = start_address + sizeof(actual_size);
10749  bytes_left = maxsize - sizeof(actual_size);
10750 
10751  for (i = 0; i < num_guc_variables; i++)
10752  serialize_variable(&curptr, &bytes_left, guc_variables[i]);
10753 
10754  /* Store actual size without assuming alignment of start_address. */
10755  actual_size = maxsize - bytes_left - sizeof(actual_size);
10756  memcpy(start_address, &actual_size, sizeof(actual_size));
10757 }
static void serialize_variable(char **destptr, Size *maxbytes, struct config_generic *gconf)
Definition: guc.c:10664
static int num_guc_variables
Definition: guc.c:5013
static struct config_generic ** guc_variables
Definition: guc.c:5010
#define Assert(condition)
Definition: c.h:804
size_t Size
Definition: c.h:540
int i

◆ set_config_option()

int set_config_option ( const char *  name,
const char *  value,
GucContext  context,
GucSource  source,
GucAction  action,
bool  changeVal,
int  elevel,
bool  is_reload 
)

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

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