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

Go to the source code of this file.

Data Structures

struct  ConfigVariable
 
struct  config_enum_entry
 

Macros

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

Typedefs

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

Enumerations

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

Functions

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

Variables

bool log_duration
 
bool log_parameters_on_error
 
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
 
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:144
char * format_elog_string(const char *fmt,...)
Definition: elog.c:1500
void pre_format_elog_string(int errnumber, const char *domain)
Definition: elog.c:1491

Definition at line 418 of file guc.h.

Referenced by check_max_stack_depth(), check_ssl_max_protocol_version(), check_ssl_min_protocol_version(), 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 build_guc_variables(), and get_explain_guc_options().

◆ GUC_IS_NAME

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

Definition at line 213 of file guc.h.

Referenced by parse_and_validate_value().

◆ GUC_LIST_INPUT

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

Definition at line 204 of file guc.h.

Referenced by _PG_init(), and flatten_set_variable_args().

◆ GUC_LIST_QUOTE

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

Definition at line 205 of file guc.h.

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

◆ GUC_NO_RESET_ALL

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

Definition at line 207 of file guc.h.

Referenced by ResetAllOptions().

◆ GUC_NO_SHOW_ALL

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

◆ GUC_NOT_IN_SAMPLE

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

Definition at line 209 of file guc.h.

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

◆ GUC_NOT_WHILE_SEC_REST

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

Definition at line 214 of file guc.h.

Referenced by set_config_option().

◆ GUC_QUALIFIER_SEPARATOR

#define GUC_QUALIFIER_SEPARATOR   '.'

Definition at line 199 of file guc.h.

Referenced by EmitWarningsOnPlaceholders(), and find_option().

◆ GUC_REPORT

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

◆ GUC_SUPERUSER_ONLY

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

◆ GUC_UNIT

#define GUC_UNIT   (GUC_UNIT_MEMORY | GUC_UNIT_TIME)

Definition at line 232 of file guc.h.

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

◆ GUC_UNIT_BLOCKS

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

Definition at line 219 of file guc.h.

Referenced by get_config_unit_name().

◆ GUC_UNIT_BYTE

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

Definition at line 222 of file guc.h.

Referenced by get_config_unit_name().

◆ GUC_UNIT_KB

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

Definition at line 218 of file guc.h.

Referenced by get_config_unit_name().

◆ GUC_UNIT_MB

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

Definition at line 221 of file guc.h.

Referenced by get_config_unit_name().

◆ GUC_UNIT_MEMORY

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

◆ GUC_UNIT_MIN

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

Definition at line 227 of file guc.h.

Referenced by get_config_unit_name().

◆ GUC_UNIT_MS

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

Definition at line 225 of file guc.h.

Referenced by _PG_init(), and get_config_unit_name().

◆ GUC_UNIT_S

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

Definition at line 226 of file guc.h.

Referenced by _PG_init(), and get_config_unit_name().

◆ GUC_UNIT_TIME

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

Definition at line 228 of file guc.h.

Referenced by get_config_unit_name().

◆ GUC_UNIT_XBLOCKS

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

Definition at line 220 of file guc.h.

Referenced by get_config_unit_name().

◆ MAX_KILOBYTES

#define MAX_KILOBYTES   (INT_MAX / 1024)

Definition at line 26 of file guc.h.

◆ PG_AUTOCONF_FILENAME

#define PG_AUTOCONF_FILENAME   "postgresql.auto.conf"

Definition at line 34 of file guc.h.

Referenced by AlterSystemSetConfigFile().

Typedef Documentation

◆ ConfigVariable

◆ GucBoolAssignHook

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

Definition at line 180 of file guc.h.

◆ GucBoolCheckHook

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

Definition at line 174 of file guc.h.

◆ GucEnumAssignHook

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

Definition at line 184 of file guc.h.

◆ GucEnumCheckHook

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

Definition at line 178 of file guc.h.

◆ GucIntAssignHook

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

Definition at line 181 of file guc.h.

◆ GucIntCheckHook

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

Definition at line 175 of file guc.h.

◆ GucRealAssignHook

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

Definition at line 182 of file guc.h.

◆ GucRealCheckHook

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

Definition at line 176 of file guc.h.

◆ GucShowHook

typedef const char*(* GucShowHook) (void)

Definition at line 186 of file guc.h.

◆ GucStringAssignHook

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

Definition at line 183 of file guc.h.

◆ GucStringCheckHook

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

Definition at line 177 of file guc.h.

Enumeration Type Documentation

◆ GucAction

enum GucAction
Enumerator
GUC_ACTION_SET 
GUC_ACTION_LOCAL 
GUC_ACTION_SAVE 

Definition at line 191 of file guc.h.

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

◆ GucContext

enum GucContext
Enumerator
PGC_INTERNAL 
PGC_POSTMASTER 
PGC_SIGHUP 
PGC_SU_BACKEND 
PGC_BACKEND 
PGC_SUSET 
PGC_USERSET 

Definition at line 68 of file guc.h.

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

◆ GucSource

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

Definition at line 105 of file guc.h.

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

Function Documentation

◆ AlterSystemSetConfigFile()

void AlterSystemSetConfigFile ( AlterSystemStmt altersysstmt)

Definition at line 7982 of file guc.c.

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

Referenced by standard_ProcessUtility().

7983 {
7984  char *name;
7985  char *value;
7986  bool resetall = false;
7987  ConfigVariable *head = NULL;
7988  ConfigVariable *tail = NULL;
7989  volatile int Tmpfd;
7990  char AutoConfFileName[MAXPGPATH];
7991  char AutoConfTmpFileName[MAXPGPATH];
7992 
7993  if (!superuser())
7994  ereport(ERROR,
7995  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7996  (errmsg("must be superuser to execute ALTER SYSTEM command"))));
7997 
7998  /*
7999  * Extract statement arguments
8000  */
8001  name = altersysstmt->setstmt->name;
8002 
8003  switch (altersysstmt->setstmt->kind)
8004  {
8005  case VAR_SET_VALUE:
8006  value = ExtractSetVariableArgs(altersysstmt->setstmt);
8007  break;
8008 
8009  case VAR_SET_DEFAULT:
8010  case VAR_RESET:
8011  value = NULL;
8012  break;
8013 
8014  case VAR_RESET_ALL:
8015  value = NULL;
8016  resetall = true;
8017  break;
8018 
8019  default:
8020  elog(ERROR, "unrecognized alter system stmt type: %d",
8021  altersysstmt->setstmt->kind);
8022  break;
8023  }
8024 
8025  /*
8026  * Unless it's RESET_ALL, validate the target variable and value
8027  */
8028  if (!resetall)
8029  {
8030  struct config_generic *record;
8031 
8032  record = find_option(name, false, ERROR);
8033  if (record == NULL)
8034  ereport(ERROR,
8035  (errcode(ERRCODE_UNDEFINED_OBJECT),
8036  errmsg("unrecognized configuration parameter \"%s\"",
8037  name)));
8038 
8039  /*
8040  * Don't allow parameters that can't be set in configuration files to
8041  * be set in PG_AUTOCONF_FILENAME file.
8042  */
8043  if ((record->context == PGC_INTERNAL) ||
8044  (record->flags & GUC_DISALLOW_IN_FILE) ||
8045  (record->flags & GUC_DISALLOW_IN_AUTO_FILE))
8046  ereport(ERROR,
8047  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
8048  errmsg("parameter \"%s\" cannot be changed",
8049  name)));
8050 
8051  /*
8052  * If a value is specified, verify that it's sane.
8053  */
8054  if (value)
8055  {
8056  union config_var_val newval;
8057  void *newextra = NULL;
8058 
8059  /* Check that it's acceptable for the indicated parameter */
8060  if (!parse_and_validate_value(record, name, value,
8061  PGC_S_FILE, ERROR,
8062  &newval, &newextra))
8063  ereport(ERROR,
8064  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8065  errmsg("invalid value for parameter \"%s\": \"%s\"",
8066  name, value)));
8067 
8068  if (record->vartype == PGC_STRING && newval.stringval != NULL)
8069  free(newval.stringval);
8070  if (newextra)
8071  free(newextra);
8072 
8073  /*
8074  * We must also reject values containing newlines, because the
8075  * grammar for config files doesn't support embedded newlines in
8076  * string literals.
8077  */
8078  if (strchr(value, '\n'))
8079  ereport(ERROR,
8080  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8081  errmsg("parameter value for ALTER SYSTEM must not contain a newline")));
8082  }
8083  }
8084 
8085  /*
8086  * PG_AUTOCONF_FILENAME and its corresponding temporary file are always in
8087  * the data directory, so we can reference them by simple relative paths.
8088  */
8089  snprintf(AutoConfFileName, sizeof(AutoConfFileName), "%s",
8091  snprintf(AutoConfTmpFileName, sizeof(AutoConfTmpFileName), "%s.%s",
8092  AutoConfFileName,
8093  "tmp");
8094 
8095  /*
8096  * Only one backend is allowed to operate on PG_AUTOCONF_FILENAME at a
8097  * time. Use AutoFileLock to ensure that. We must hold the lock while
8098  * reading the old file contents.
8099  */
8100  LWLockAcquire(AutoFileLock, LW_EXCLUSIVE);
8101 
8102  /*
8103  * If we're going to reset everything, then no need to open or parse the
8104  * old file. We'll just write out an empty list.
8105  */
8106  if (!resetall)
8107  {
8108  struct stat st;
8109 
8110  if (stat(AutoConfFileName, &st) == 0)
8111  {
8112  /* open old file PG_AUTOCONF_FILENAME */
8113  FILE *infile;
8114 
8115  infile = AllocateFile(AutoConfFileName, "r");
8116  if (infile == NULL)
8117  ereport(ERROR,
8119  errmsg("could not open file \"%s\": %m",
8120  AutoConfFileName)));
8121 
8122  /* parse it */
8123  if (!ParseConfigFp(infile, AutoConfFileName, 0, LOG, &head, &tail))
8124  ereport(ERROR,
8125  (errcode(ERRCODE_CONFIG_FILE_ERROR),
8126  errmsg("could not parse contents of file \"%s\"",
8127  AutoConfFileName)));
8128 
8129  FreeFile(infile);
8130  }
8131 
8132  /*
8133  * Now, replace any existing entry with the new value, or add it if
8134  * not present.
8135  */
8136  replace_auto_config_value(&head, &tail, name, value);
8137  }
8138 
8139  /*
8140  * To ensure crash safety, first write the new file data to a temp file,
8141  * then atomically rename it into place.
8142  *
8143  * If there is a temp file left over due to a previous crash, it's okay to
8144  * truncate and reuse it.
8145  */
8146  Tmpfd = BasicOpenFile(AutoConfTmpFileName,
8147  O_CREAT | O_RDWR | O_TRUNC);
8148  if (Tmpfd < 0)
8149  ereport(ERROR,
8151  errmsg("could not open file \"%s\": %m",
8152  AutoConfTmpFileName)));
8153 
8154  /*
8155  * Use a TRY block to clean up the file if we fail. Since we need a TRY
8156  * block anyway, OK to use BasicOpenFile rather than OpenTransientFile.
8157  */
8158  PG_TRY();
8159  {
8160  /* Write and sync the new contents to the temporary file */
8161  write_auto_conf_file(Tmpfd, AutoConfTmpFileName, head);
8162 
8163  /* Close before renaming; may be required on some platforms */
8164  close(Tmpfd);
8165  Tmpfd = -1;
8166 
8167  /*
8168  * As the rename is atomic operation, if any problem occurs after this
8169  * at worst it can lose the parameters set by last ALTER SYSTEM
8170  * command.
8171  */
8172  durable_rename(AutoConfTmpFileName, AutoConfFileName, ERROR);
8173  }
8174  PG_CATCH();
8175  {
8176  /* Close file first, else unlink might fail on some platforms */
8177  if (Tmpfd >= 0)
8178  close(Tmpfd);
8179 
8180  /* Unlink, but ignore any error */
8181  (void) unlink(AutoConfTmpFileName);
8182 
8183  PG_RE_THROW();
8184  }
8185  PG_END_TRY();
8186 
8187  FreeConfigVariables(head);
8188 
8189  LWLockRelease(AutoFileLock);
8190 }
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:6601
VariableSetKind kind
Definition: parsenodes.h:2039
static struct @145 value
int errcode(int sqlerrcode)
Definition: elog.c:608
bool superuser(void)
Definition: superuser.c:46
#define LOG
Definition: elog.h:26
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1726
#define ERROR
Definition: elog.h:43
#define MAXPGPATH
VariableSetStmt * setstmt
Definition: parsenodes.h:3178
int errcode_for_file_access(void)
Definition: elog.c:631
FILE * AllocateFile(const char *name, const char *mode)
Definition: fd.c:2242
#define ereport(elevel, rest)
Definition: elog.h:141
int durable_rename(const char *oldfile, const char *newfile, int elevel)
Definition: fd.c:643
enum config_type vartype
Definition: guc_tables.h:156
#define stat(a, b)
Definition: win32_port.h:255
#define GUC_DISALLOW_IN_FILE
Definition: guc.h:210
static void write_auto_conf_file(int fd, const char *filename, ConfigVariable *head_p)
Definition: guc.c:7844
static void infile(const char *filename)
Definition: zic.c:1233
#define free(a)
Definition: header.h:65
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:5098
#define PG_CATCH()
Definition: elog.h:332
#define newval
#define PG_AUTOCONF_FILENAME
Definition: guc.h:34
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1122
#define PG_RE_THROW()
Definition: elog.h:363
const char * name
Definition: encode.c:521
#define GUC_DISALLOW_IN_AUTO_FILE
Definition: guc.h:215
int BasicOpenFile(const char *fileName, int fileFlags)
Definition: fd.c:981
int FreeFile(FILE *file)
Definition: fd.c:2441
int errmsg(const char *fmt,...)
Definition: elog.c:822
bool ParseConfigFp(FILE *fp, const char *config_file, int depth, int elevel, ConfigVariable **head_p, ConfigVariable **tail_p)
#define elog(elevel,...)
Definition: elog.h:228
static void replace_auto_config_value(ConfigVariable **head_p, ConfigVariable **tail_p, const char *name, const char *value)
Definition: guc.c:7912
void FreeConfigVariables(ConfigVariable *list)
#define close(a)
Definition: win32.h:12
#define PG_TRY()
Definition: elog.h:322
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
Definition: guc.c:8320
#define snprintf
Definition: port.h:192
#define PG_END_TRY()
Definition: elog.h:347
GucContext context
Definition: guc_tables.h:150

◆ assign_search_path()

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

Definition at line 4231 of file namespace.c.

References baseSearchPathValid.

4232 {
4233  /*
4234  * We mark the path as needing recomputation, but don't do anything until
4235  * it's needed. This avoids trying to do database access during GUC
4236  * initialization, or outside a transaction.
4237  */
4238  baseSearchPathValid = false;
4239 }
static bool baseSearchPathValid
Definition: namespace.c:152

◆ assign_temp_tablespaces()

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

Definition at line 1298 of file tablespace.c.

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

1299 {
1300  temp_tablespaces_extra *myextra = (temp_tablespaces_extra *) extra;
1301 
1302  /*
1303  * If check_temp_tablespaces was executed inside a transaction, then pass
1304  * the list it made to fd.c. Otherwise, clear fd.c's list; we must be
1305  * still outside a transaction, or else restoring during transaction exit,
1306  * and in either case we can just let the next PrepareTempTablespaces call
1307  * make things sane.
1308  */
1309  if (myextra)
1310  SetTempTablespaces(myextra->tblSpcs, myextra->numSpcs);
1311  else
1312  SetTempTablespaces(NULL, 0);
1313 }
Oid tblSpcs[FLEXIBLE_ARRAY_MEMBER]
Definition: tablespace.c:1187
void SetTempTablespaces(Oid *tableSpaces, int numSpaces)
Definition: fd.c:2706

◆ assign_xlog_sync_method()

void assign_xlog_sync_method ( int  new_sync_method,
void *  extra 
)

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

10085 {
10086  if (sync_method != new_sync_method)
10087  {
10088  /*
10089  * To ensure that no blocks escape unsynced, force an fsync on the
10090  * currently open log segment (if any). Also, if the open flag is
10091  * changing, close the log file so it will be reopened (with new flag
10092  * bit) at next use.
10093  */
10094  if (openLogFile >= 0)
10095  {
10097  if (pg_fsync(openLogFile) != 0)
10098  {
10099  char xlogfname[MAXFNAMELEN];
10100  int save_errno;
10101 
10102  save_errno = errno;
10105  errno = save_errno;
10106  ereport(PANIC,
10108  errmsg("could not fsync file \"%s\": %m", xlogfname)));
10109  }
10110 
10112  if (get_sync_bit(sync_method) != get_sync_bit(new_sync_method))
10113  XLogFileClose();
10114  }
10115  }
10116 }
int wal_segment_size
Definition: xlog.c:112
static int get_sync_bit(int method)
Definition: xlog.c:10028
#define PANIC
Definition: elog.h:53
static XLogSegNo openLogSegNo
Definition: xlog.c:779
static void XLogFileClose(void)
Definition: xlog.c:3785
int errcode_for_file_access(void)
Definition: elog.c:631
static void pgstat_report_wait_end(void)
Definition: pgstat.h:1344
#define ereport(elevel, rest)
Definition: elog.h:141
#define MAXFNAMELEN
static int openLogFile
Definition: xlog.c:778
TimeLineID ThisTimeLineID
Definition: xlog.c:187
#define XLogFileName(fname, tli, logSegNo, wal_segsz_bytes)
static void pgstat_report_wait_start(uint32 wait_event_info)
Definition: pgstat.h:1320
int sync_method
Definition: xlog.c:102
int errmsg(const char *fmt,...)
Definition: elog.c:822
int pg_fsync(int fd)
Definition: fd.c:330

◆ AtEOXact_GUC()

void AtEOXact_GUC ( bool  isCommit,
int  nestLevel 
)

Definition at line 5805 of file guc.c.

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

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

5806 {
5807  bool still_dirty;
5808  int i;
5809 
5810  /*
5811  * Note: it's possible to get here with GUCNestLevel == nestLevel-1 during
5812  * abort, if there is a failure during transaction start before
5813  * AtStart_GUC is called.
5814  */
5815  Assert(nestLevel > 0 &&
5816  (nestLevel <= GUCNestLevel ||
5817  (nestLevel == GUCNestLevel + 1 && !isCommit)));
5818 
5819  /* Quick exit if nothing's changed in this transaction */
5820  if (!guc_dirty)
5821  {
5822  GUCNestLevel = nestLevel - 1;
5823  return;
5824  }
5825 
5826  still_dirty = false;
5827  for (i = 0; i < num_guc_variables; i++)
5828  {
5829  struct config_generic *gconf = guc_variables[i];
5830  GucStack *stack;
5831 
5832  /*
5833  * Process and pop each stack entry within the nest level. To simplify
5834  * fmgr_security_definer() and other places that use GUC_ACTION_SAVE,
5835  * we allow failure exit from code that uses a local nest level to be
5836  * recovered at the surrounding transaction or subtransaction abort;
5837  * so there could be more than one stack entry to pop.
5838  */
5839  while ((stack = gconf->stack) != NULL &&
5840  stack->nest_level >= nestLevel)
5841  {
5842  GucStack *prev = stack->prev;
5843  bool restorePrior = false;
5844  bool restoreMasked = false;
5845  bool changed;
5846 
5847  /*
5848  * In this next bit, if we don't set either restorePrior or
5849  * restoreMasked, we must "discard" any unwanted fields of the
5850  * stack entries to avoid leaking memory. If we do set one of
5851  * those flags, unused fields will be cleaned up after restoring.
5852  */
5853  if (!isCommit) /* if abort, always restore prior value */
5854  restorePrior = true;
5855  else if (stack->state == GUC_SAVE)
5856  restorePrior = true;
5857  else if (stack->nest_level == 1)
5858  {
5859  /* transaction commit */
5860  if (stack->state == GUC_SET_LOCAL)
5861  restoreMasked = true;
5862  else if (stack->state == GUC_SET)
5863  {
5864  /* we keep the current active value */
5865  discard_stack_value(gconf, &stack->prior);
5866  }
5867  else /* must be GUC_LOCAL */
5868  restorePrior = true;
5869  }
5870  else if (prev == NULL ||
5871  prev->nest_level < stack->nest_level - 1)
5872  {
5873  /* decrement entry's level and do not pop it */
5874  stack->nest_level--;
5875  continue;
5876  }
5877  else
5878  {
5879  /*
5880  * We have to merge this stack entry into prev. See README for
5881  * discussion of this bit.
5882  */
5883  switch (stack->state)
5884  {
5885  case GUC_SAVE:
5886  Assert(false); /* can't get here */
5887  break;
5888 
5889  case GUC_SET:
5890  /* next level always becomes SET */
5891  discard_stack_value(gconf, &stack->prior);
5892  if (prev->state == GUC_SET_LOCAL)
5893  discard_stack_value(gconf, &prev->masked);
5894  prev->state = GUC_SET;
5895  break;
5896 
5897  case GUC_LOCAL:
5898  if (prev->state == GUC_SET)
5899  {
5900  /* LOCAL migrates down */
5901  prev->masked_scontext = stack->scontext;
5902  prev->masked = stack->prior;
5903  prev->state = GUC_SET_LOCAL;
5904  }
5905  else
5906  {
5907  /* else just forget this stack level */
5908  discard_stack_value(gconf, &stack->prior);
5909  }
5910  break;
5911 
5912  case GUC_SET_LOCAL:
5913  /* prior state at this level no longer wanted */
5914  discard_stack_value(gconf, &stack->prior);
5915  /* copy down the masked state */
5916  prev->masked_scontext = stack->masked_scontext;
5917  if (prev->state == GUC_SET_LOCAL)
5918  discard_stack_value(gconf, &prev->masked);
5919  prev->masked = stack->masked;
5920  prev->state = GUC_SET_LOCAL;
5921  break;
5922  }
5923  }
5924 
5925  changed = false;
5926 
5927  if (restorePrior || restoreMasked)
5928  {
5929  /* Perform appropriate restoration of the stacked value */
5930  config_var_value newvalue;
5931  GucSource newsource;
5932  GucContext newscontext;
5933 
5934  if (restoreMasked)
5935  {
5936  newvalue = stack->masked;
5937  newsource = PGC_S_SESSION;
5938  newscontext = stack->masked_scontext;
5939  }
5940  else
5941  {
5942  newvalue = stack->prior;
5943  newsource = stack->source;
5944  newscontext = stack->scontext;
5945  }
5946 
5947  switch (gconf->vartype)
5948  {
5949  case PGC_BOOL:
5950  {
5951  struct config_bool *conf = (struct config_bool *) gconf;
5952  bool newval = newvalue.val.boolval;
5953  void *newextra = newvalue.extra;
5954 
5955  if (*conf->variable != newval ||
5956  conf->gen.extra != newextra)
5957  {
5958  if (conf->assign_hook)
5959  conf->assign_hook(newval, newextra);
5960  *conf->variable = newval;
5961  set_extra_field(&conf->gen, &conf->gen.extra,
5962  newextra);
5963  changed = true;
5964  }
5965  break;
5966  }
5967  case PGC_INT:
5968  {
5969  struct config_int *conf = (struct config_int *) gconf;
5970  int newval = newvalue.val.intval;
5971  void *newextra = newvalue.extra;
5972 
5973  if (*conf->variable != newval ||
5974  conf->gen.extra != newextra)
5975  {
5976  if (conf->assign_hook)
5977  conf->assign_hook(newval, newextra);
5978  *conf->variable = newval;
5979  set_extra_field(&conf->gen, &conf->gen.extra,
5980  newextra);
5981  changed = true;
5982  }
5983  break;
5984  }
5985  case PGC_REAL:
5986  {
5987  struct config_real *conf = (struct config_real *) gconf;
5988  double newval = newvalue.val.realval;
5989  void *newextra = newvalue.extra;
5990 
5991  if (*conf->variable != newval ||
5992  conf->gen.extra != newextra)
5993  {
5994  if (conf->assign_hook)
5995  conf->assign_hook(newval, newextra);
5996  *conf->variable = newval;
5997  set_extra_field(&conf->gen, &conf->gen.extra,
5998  newextra);
5999  changed = true;
6000  }
6001  break;
6002  }
6003  case PGC_STRING:
6004  {
6005  struct config_string *conf = (struct config_string *) gconf;
6006  char *newval = newvalue.val.stringval;
6007  void *newextra = newvalue.extra;
6008 
6009  if (*conf->variable != newval ||
6010  conf->gen.extra != newextra)
6011  {
6012  if (conf->assign_hook)
6013  conf->assign_hook(newval, newextra);
6014  set_string_field(conf, conf->variable, newval);
6015  set_extra_field(&conf->gen, &conf->gen.extra,
6016  newextra);
6017  changed = true;
6018  }
6019 
6020  /*
6021  * Release stacked values if not used anymore. We
6022  * could use discard_stack_value() here, but since
6023  * we have type-specific code anyway, might as
6024  * well inline it.
6025  */
6026  set_string_field(conf, &stack->prior.val.stringval, NULL);
6027  set_string_field(conf, &stack->masked.val.stringval, NULL);
6028  break;
6029  }
6030  case PGC_ENUM:
6031  {
6032  struct config_enum *conf = (struct config_enum *) gconf;
6033  int newval = newvalue.val.enumval;
6034  void *newextra = newvalue.extra;
6035 
6036  if (*conf->variable != newval ||
6037  conf->gen.extra != newextra)
6038  {
6039  if (conf->assign_hook)
6040  conf->assign_hook(newval, newextra);
6041  *conf->variable = newval;
6042  set_extra_field(&conf->gen, &conf->gen.extra,
6043  newextra);
6044  changed = true;
6045  }
6046  break;
6047  }
6048  }
6049 
6050  /*
6051  * Release stacked extra values if not used anymore.
6052  */
6053  set_extra_field(gconf, &(stack->prior.extra), NULL);
6054  set_extra_field(gconf, &(stack->masked.extra), NULL);
6055 
6056  /* And restore source information */
6057  gconf->source = newsource;
6058  gconf->scontext = newscontext;
6059  }
6060 
6061  /* Finish popping the state stack */
6062  gconf->stack = prev;
6063  pfree(stack);
6064 
6065  /* Report new value if we changed it */
6066  if (changed && (gconf->flags & GUC_REPORT))
6067  ReportGUCOption(gconf);
6068  } /* end of stack-popping loop */
6069 
6070  if (stack != NULL)
6071  still_dirty = true;
6072  }
6073 
6074  /* If there are no remaining stack entries, we can reset guc_dirty */
6075  guc_dirty = still_dirty;
6076 
6077  /* Update nesting level */
6078  GUCNestLevel = nestLevel - 1;
6079 }
struct guc_stack * prev
Definition: guc_tables.h:123
GucSource source
Definition: guc_tables.h:158
GucContext
Definition: guc.h:68
union config_var_val val
Definition: guc_tables.h:46
int nest_level
Definition: guc_tables.h:124
GucRealAssignHook assign_hook
Definition: guc_tables.h:219
char ** variable
Definition: guc_tables.h:230
static int GUCNestLevel
Definition: guc.c:4657
bool * variable
Definition: guc_tables.h:184
GucEnumAssignHook assign_hook
Definition: guc_tables.h:248
GucBoolAssignHook assign_hook
Definition: guc_tables.h:187
config_var_value masked
Definition: guc_tables.h:131
GucContext scontext
Definition: guc_tables.h:160
GucIntAssignHook assign_hook
Definition: guc_tables.h:203
GucSource
Definition: guc.h:105
int * variable
Definition: guc_tables.h:198
int * variable
Definition: guc_tables.h:244
void pfree(void *pointer)
Definition: mcxt.c:1056
static int num_guc_variables
Definition: guc.c:4644
static void discard_stack_value(struct config_generic *gconf, config_var_value *val)
Definition: guc.c:4872
GucSource source
Definition: guc_tables.h:126
static void set_extra_field(struct config_generic *gconf, void **field, void *newval)
Definition: guc.c:4818
struct config_generic gen
Definition: guc_tables.h:182
struct config_generic gen
Definition: guc_tables.h:196
GucContext masked_scontext
Definition: guc_tables.h:129
#define GUC_REPORT
Definition: guc.h:208
double * variable
Definition: guc_tables.h:214
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4757
static struct config_generic ** guc_variables
Definition: guc.c:4641
enum config_type vartype
Definition: guc_tables.h:156
GucContext scontext
Definition: guc_tables.h:128
struct config_generic gen
Definition: guc_tables.h:242
struct config_generic gen
Definition: guc_tables.h:228
GucStackState state
Definition: guc_tables.h:125
GucStringAssignHook assign_hook
Definition: guc_tables.h:233
#define Assert(condition)
Definition: c.h:739
#define newval
char * stringval
Definition: guc_tables.h:36
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:6115
GucStack * stack
Definition: guc_tables.h:162
double realval
Definition: guc_tables.h:35
static bool guc_dirty
Definition: guc.c:4653
config_var_value prior
Definition: guc_tables.h:130
struct config_generic gen
Definition: guc_tables.h:212

◆ AtStart_GUC()

void AtStart_GUC ( void  )

Definition at line 5771 of file guc.c.

References elog, and WARNING.

Referenced by StartTransaction().

5772 {
5773  /*
5774  * The nest level should be 0 between transactions; if it isn't, somebody
5775  * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
5776  * throw a warning but make no other effort to clean up.
5777  */
5778  if (GUCNestLevel != 0)
5779  elog(WARNING, "GUC nest level = %d at transaction start",
5780  GUCNestLevel);
5781  GUCNestLevel = 1;
5782 }
static int GUCNestLevel
Definition: guc.c:4657
#define WARNING
Definition: elog.h:40
#define elog(elevel,...)
Definition: elog.h:228

◆ BeginReportingGUCOptions()

void BeginReportingGUCOptions ( void  )

Definition at line 6087 of file guc.c.

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

Referenced by PostgresMain().

6088 {
6089  int i;
6090 
6091  /*
6092  * Don't do anything unless talking to an interactive frontend of protocol
6093  * 3.0 or later.
6094  */
6095  if (whereToSendOutput != DestRemote ||
6097  return;
6098 
6099  reporting_enabled = true;
6100 
6101  /* Transmit initial values of interesting variables */
6102  for (i = 0; i < num_guc_variables; i++)
6103  {
6104  struct config_generic *conf = guc_variables[i];
6105 
6106  if (conf->flags & GUC_REPORT)
6107  ReportGUCOption(conf);
6108  }
6109 }
#define PG_PROTOCOL_MAJOR(v)
Definition: pqcomm.h:104
static int num_guc_variables
Definition: guc.c:4644
#define GUC_REPORT
Definition: guc.h:208
static struct config_generic ** guc_variables
Definition: guc.c:4641
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:6115
CommandDest whereToSendOutput
Definition: postgres.c:91
static bool reporting_enabled
Definition: guc.c:4655
ProtocolVersion FrontendProtocol
Definition: globals.c:28

◆ check_default_tablespace()

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

Definition at line 1086 of file tablespace.c.

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

1087 {
1088  /*
1089  * If we aren't inside a transaction, or connected to a database, we
1090  * cannot do the catalog accesses necessary to verify the name. Must
1091  * accept the value on faith.
1092  */
1094  {
1095  if (**newval != '\0' &&
1097  {
1098  /*
1099  * When source == PGC_S_TEST, don't throw a hard error for a
1100  * nonexistent tablespace, only a NOTICE. See comments in guc.h.
1101  */
1102  if (source == PGC_S_TEST)
1103  {
1104  ereport(NOTICE,
1105  (errcode(ERRCODE_UNDEFINED_OBJECT),
1106  errmsg("tablespace \"%s\" does not exist",
1107  *newval)));
1108  }
1109  else
1110  {
1111  GUC_check_errdetail("Tablespace \"%s\" does not exist.",
1112  *newval);
1113  return false;
1114  }
1115  }
1116  }
1117 
1118  return true;
1119 }
Oid get_tablespace_oid(const char *tablespacename, bool missing_ok)
Definition: tablespace.c:1416
GucSource source
Definition: guc_tables.h:158
#define GUC_check_errdetail
Definition: guc.h:414
int errcode(int sqlerrcode)
Definition: elog.c:608
#define OidIsValid(objectId)
Definition: c.h:645
#define ereport(elevel, rest)
Definition: elog.h:141
Oid MyDatabaseId
Definition: globals.c:85
#define InvalidOid
Definition: postgres_ext.h:36
#define NOTICE
Definition: elog.h:37
#define newval
bool IsTransactionState(void)
Definition: xact.c:355
int errmsg(const char *fmt,...)
Definition: elog.c:822

◆ check_search_path()

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

Definition at line 4197 of file namespace.c.

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

4198 {
4199  char *rawname;
4200  List *namelist;
4201 
4202  /* Need a modifiable copy of string */
4203  rawname = pstrdup(*newval);
4204 
4205  /* Parse string into list of identifiers */
4206  if (!SplitIdentifierString(rawname, ',', &namelist))
4207  {
4208  /* syntax error in name list */
4209  GUC_check_errdetail("List syntax is invalid.");
4210  pfree(rawname);
4211  list_free(namelist);
4212  return false;
4213  }
4214 
4215  /*
4216  * We used to try to check that the named schemas exist, but there are
4217  * many valid use-cases for having search_path settings that include
4218  * schemas that don't exist; and often, we are not inside a transaction
4219  * here and so can't consult the system catalogs anyway. So now, the only
4220  * requirement is syntactic validity of the identifier list.
4221  */
4222 
4223  pfree(rawname);
4224  list_free(namelist);
4225 
4226  return true;
4227 }
#define GUC_check_errdetail
Definition: guc.h:414
char * pstrdup(const char *in)
Definition: mcxt.c:1186
void pfree(void *pointer)
Definition: mcxt.c:1056
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3652
#define newval
void list_free(List *list)
Definition: list.c:1377
Definition: pg_list.h:50

◆ check_temp_tablespaces()

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

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

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

◆ check_wal_buffers()

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

Definition at line 4874 of file xlog.c.

References XLOGbuffers, and XLOGChooseNumBuffers().

4875 {
4876  /*
4877  * -1 indicates a request for auto-tune.
4878  */
4879  if (*newval == -1)
4880  {
4881  /*
4882  * If we haven't yet changed the boot_val default of -1, just let it
4883  * be. We'll fix it when XLOGShmemSize is called.
4884  */
4885  if (XLOGbuffers == -1)
4886  return true;
4887 
4888  /* Otherwise, substitute the auto-tune value */
4890  }
4891 
4892  /*
4893  * We clamp manually-set values to at least 4 blocks. Prior to PostgreSQL
4894  * 9.1, a minimum of 4 was enforced by guc.c, but since that is no longer
4895  * the case, we just silently treat such values as a request for the
4896  * minimum. (We could throw an error instead, but that doesn't seem very
4897  * helpful.)
4898  */
4899  if (*newval < 4)
4900  *newval = 4;
4901 
4902  return true;
4903 }
static int XLOGChooseNumBuffers(void)
Definition: xlog.c:4858
#define newval
int XLOGbuffers
Definition: xlog.c:89

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

8659 {
8660  struct config_bool *var;
8661 
8662  var = (struct config_bool *)
8663  init_custom_variable(name, short_desc, long_desc, context, flags,
8664  PGC_BOOL, sizeof(struct config_bool));
8665  var->variable = valueAddr;
8666  var->boot_val = bootValue;
8667  var->reset_val = bootValue;
8668  var->check_hook = check_hook;
8669  var->assign_hook = assign_hook;
8670  var->show_hook = show_hook;
8671  define_custom_variable(&var->gen);
8672 }
bool * variable
Definition: guc_tables.h:184
GucBoolAssignHook assign_hook
Definition: guc_tables.h:187
bool boot_val
Definition: guc_tables.h:185
struct config_generic gen
Definition: guc_tables.h:182
static struct config_generic * init_custom_variable(const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
Definition: guc.c:8408
GucBoolCheckHook check_hook
Definition: guc_tables.h:186
GucShowHook show_hook
Definition: guc_tables.h:188
const char * name
Definition: encode.c:521
bool reset_val
Definition: guc_tables.h:190
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8468

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

8771 {
8772  struct config_enum *var;
8773 
8774  var = (struct config_enum *)
8775  init_custom_variable(name, short_desc, long_desc, context, flags,
8776  PGC_ENUM, sizeof(struct config_enum));
8777  var->variable = valueAddr;
8778  var->boot_val = bootValue;
8779  var->reset_val = bootValue;
8780  var->options = options;
8781  var->check_hook = check_hook;
8782  var->assign_hook = assign_hook;
8783  var->show_hook = show_hook;
8784  define_custom_variable(&var->gen);
8785 }
GucEnumCheckHook check_hook
Definition: guc_tables.h:247
GucEnumAssignHook assign_hook
Definition: guc_tables.h:248
int * variable
Definition: guc_tables.h:244
const struct config_enum_entry * options
Definition: guc_tables.h:246
static char ** options
static struct config_generic * init_custom_variable(const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
Definition: guc.c:8408
GucShowHook show_hook
Definition: guc_tables.h:249
struct config_generic gen
Definition: guc_tables.h:242
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8468

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

8687 {
8688  struct config_int *var;
8689 
8690  var = (struct config_int *)
8691  init_custom_variable(name, short_desc, long_desc, context, flags,
8692  PGC_INT, sizeof(struct config_int));
8693  var->variable = valueAddr;
8694  var->boot_val = bootValue;
8695  var->reset_val = bootValue;
8696  var->min = minValue;
8697  var->max = maxValue;
8698  var->check_hook = check_hook;
8699  var->assign_hook = assign_hook;
8700  var->show_hook = show_hook;
8701  define_custom_variable(&var->gen);
8702 }
int boot_val
Definition: guc_tables.h:199
GucIntAssignHook assign_hook
Definition: guc_tables.h:203
GucIntCheckHook check_hook
Definition: guc_tables.h:202
GucShowHook show_hook
Definition: guc_tables.h:204
int * variable
Definition: guc_tables.h:198
struct config_generic gen
Definition: guc_tables.h:196
static struct config_generic * init_custom_variable(const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
Definition: guc.c:8408
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8468
int reset_val
Definition: guc_tables.h:206

◆ DefineCustomRealVariable()

void DefineCustomRealVariable ( const char *  name,
const char *  short_desc,
const char *  long_desc,
double *  valueAddr,
double  bootValue,
double  minValue,
double  maxValue,
GucContext  context,
int  flags,
GucRealCheckHook  check_hook,
GucRealAssignHook  assign_hook,
GucShowHook  show_hook 
)

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

8717 {
8718  struct config_real *var;
8719 
8720  var = (struct config_real *)
8721  init_custom_variable(name, short_desc, long_desc, context, flags,
8722  PGC_REAL, sizeof(struct config_real));
8723  var->variable = valueAddr;
8724  var->boot_val = bootValue;
8725  var->reset_val = bootValue;
8726  var->min = minValue;
8727  var->max = maxValue;
8728  var->check_hook = check_hook;
8729  var->assign_hook = assign_hook;
8730  var->show_hook = show_hook;
8731  define_custom_variable(&var->gen);
8732 }
GucRealAssignHook assign_hook
Definition: guc_tables.h:219
double reset_val
Definition: guc_tables.h:222
GucRealCheckHook check_hook
Definition: guc_tables.h:218
GucShowHook show_hook
Definition: guc_tables.h:220
double * variable
Definition: guc_tables.h:214
static struct config_generic * init_custom_variable(const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
Definition: guc.c:8408
double max
Definition: guc_tables.h:217
double boot_val
Definition: guc_tables.h:215
const char * name
Definition: encode.c:521
double min
Definition: guc_tables.h:216
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8468
struct config_generic gen
Definition: guc_tables.h:212

◆ DefineCustomStringVariable()

void DefineCustomStringVariable ( const char *  name,
const char *  short_desc,
const char *  long_desc,
char **  valueAddr,
const char *  bootValue,
GucContext  context,
int  flags,
GucStringCheckHook  check_hook,
GucStringAssignHook  assign_hook,
GucShowHook  show_hook 
)

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

8745 {
8746  struct config_string *var;
8747 
8748  var = (struct config_string *)
8749  init_custom_variable(name, short_desc, long_desc, context, flags,
8750  PGC_STRING, sizeof(struct config_string));
8751  var->variable = valueAddr;
8752  var->boot_val = bootValue;
8753  var->check_hook = check_hook;
8754  var->assign_hook = assign_hook;
8755  var->show_hook = show_hook;
8756  define_custom_variable(&var->gen);
8757 }
char ** variable
Definition: guc_tables.h:230
GucStringCheckHook check_hook
Definition: guc_tables.h:232
const char * boot_val
Definition: guc_tables.h:231
GucShowHook show_hook
Definition: guc_tables.h:234
static struct config_generic * init_custom_variable(const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
Definition: guc.c:8408
struct config_generic gen
Definition: guc_tables.h:228
GucStringAssignHook assign_hook
Definition: guc_tables.h:233
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8468

◆ EmitWarningsOnPlaceholders()

void EmitWarningsOnPlaceholders ( const char *  className)

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

8789 {
8790  int classLen = strlen(className);
8791  int i;
8792 
8793  for (i = 0; i < num_guc_variables; i++)
8794  {
8795  struct config_generic *var = guc_variables[i];
8796 
8797  if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
8798  strncmp(className, var->name, classLen) == 0 &&
8799  var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
8800  {
8801  ereport(WARNING,
8802  (errcode(ERRCODE_UNDEFINED_OBJECT),
8803  errmsg("unrecognized configuration parameter \"%s\"",
8804  var->name)));
8805  }
8806  }
8807 }
const char * name
Definition: guc_tables.h:149
int errcode(int sqlerrcode)
Definition: elog.c:608
#define GUC_QUALIFIER_SEPARATOR
Definition: guc.h:199
static int num_guc_variables
Definition: guc.c:4644
#define ereport(elevel, rest)
Definition: elog.h:141
static struct config_generic ** guc_variables
Definition: guc.c:4641
#define WARNING
Definition: elog.h:40
#define GUC_CUSTOM_PLACEHOLDER
Definition: guc.h:211
int errmsg(const char *fmt,...)
Definition: elog.c:822
int i

◆ EstimateGUCStateSpace()

Size EstimateGUCStateSpace ( void  )

Definition at line 10086 of file guc.c.

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

Referenced by InitializeParallelDSM().

10087 {
10088  Size size;
10089  int i;
10090 
10091  /* Add space reqd for saving the data size of the guc state */
10092  size = sizeof(Size);
10093 
10094  /* Add up the space needed for each GUC variable */
10095  for (i = 0; i < num_guc_variables; i++)
10096  size = add_size(size,
10098 
10099  return size;
10100 }
static int num_guc_variables
Definition: guc.c:4644
static struct config_generic ** guc_variables
Definition: guc.c:4641
Size add_size(Size s1, Size s2)
Definition: shmem.c:498
size_t Size
Definition: c.h:467
static Size estimate_variable_size(struct config_generic *gconf)
Definition: guc.c:9988
int i

◆ ExecSetVariableStmt()

void ExecSetVariableStmt ( VariableSetStmt stmt,
bool  isTopLevel 
)

Definition at line 8196 of file guc.c.

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

Referenced by standard_ProcessUtility().

8197 {
8199 
8200  /*
8201  * Workers synchronize these parameters at the start of the parallel
8202  * operation; then, we block SET during the operation.
8203  */
8204  if (IsInParallelMode())
8205  ereport(ERROR,
8206  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
8207  errmsg("cannot set parameters during a parallel operation")));
8208 
8209  switch (stmt->kind)
8210  {
8211  case VAR_SET_VALUE:
8212  case VAR_SET_CURRENT:
8213  if (stmt->is_local)
8214  WarnNoTransactionBlock(isTopLevel, "SET LOCAL");
8215  (void) set_config_option(stmt->name,
8216  ExtractSetVariableArgs(stmt),
8218  PGC_S_SESSION,
8219  action, true, 0, false);
8220  break;
8221  case VAR_SET_MULTI:
8222 
8223  /*
8224  * Special-case SQL syntaxes. The TRANSACTION and SESSION
8225  * CHARACTERISTICS cases effectively set more than one variable
8226  * per statement. TRANSACTION SNAPSHOT only takes one argument,
8227  * but we put it here anyway since it's a special case and not
8228  * related to any GUC variable.
8229  */
8230  if (strcmp(stmt->name, "TRANSACTION") == 0)
8231  {
8232  ListCell *head;
8233 
8234  WarnNoTransactionBlock(isTopLevel, "SET TRANSACTION");
8235 
8236  foreach(head, stmt->args)
8237  {
8238  DefElem *item = (DefElem *) lfirst(head);
8239 
8240  if (strcmp(item->defname, "transaction_isolation") == 0)
8241  SetPGVariable("transaction_isolation",
8242  list_make1(item->arg), stmt->is_local);
8243  else if (strcmp(item->defname, "transaction_read_only") == 0)
8244  SetPGVariable("transaction_read_only",
8245  list_make1(item->arg), stmt->is_local);
8246  else if (strcmp(item->defname, "transaction_deferrable") == 0)
8247  SetPGVariable("transaction_deferrable",
8248  list_make1(item->arg), stmt->is_local);
8249  else
8250  elog(ERROR, "unexpected SET TRANSACTION element: %s",
8251  item->defname);
8252  }
8253  }
8254  else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
8255  {
8256  ListCell *head;
8257 
8258  foreach(head, stmt->args)
8259  {
8260  DefElem *item = (DefElem *) lfirst(head);
8261 
8262  if (strcmp(item->defname, "transaction_isolation") == 0)
8263  SetPGVariable("default_transaction_isolation",
8264  list_make1(item->arg), stmt->is_local);
8265  else if (strcmp(item->defname, "transaction_read_only") == 0)
8266  SetPGVariable("default_transaction_read_only",
8267  list_make1(item->arg), stmt->is_local);
8268  else if (strcmp(item->defname, "transaction_deferrable") == 0)
8269  SetPGVariable("default_transaction_deferrable",
8270  list_make1(item->arg), stmt->is_local);
8271  else
8272  elog(ERROR, "unexpected SET SESSION element: %s",
8273  item->defname);
8274  }
8275  }
8276  else if (strcmp(stmt->name, "TRANSACTION SNAPSHOT") == 0)
8277  {
8278  A_Const *con = linitial_node(A_Const, stmt->args);
8279 
8280  if (stmt->is_local)
8281  ereport(ERROR,
8282  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8283  errmsg("SET LOCAL TRANSACTION SNAPSHOT is not implemented")));
8284 
8285  WarnNoTransactionBlock(isTopLevel, "SET TRANSACTION");
8286  Assert(nodeTag(&con->val) == T_String);
8287  ImportSnapshot(strVal(&con->val));
8288  }
8289  else
8290  elog(ERROR, "unexpected SET MULTI element: %s",
8291  stmt->name);
8292  break;
8293  case VAR_SET_DEFAULT:
8294  if (stmt->is_local)
8295  WarnNoTransactionBlock(isTopLevel, "SET LOCAL");
8296  /* fall through */
8297  case VAR_RESET:
8298  if (strcmp(stmt->name, "transaction_isolation") == 0)
8299  WarnNoTransactionBlock(isTopLevel, "RESET TRANSACTION");
8300 
8301  (void) set_config_option(stmt->name,
8302  NULL,
8304  PGC_S_SESSION,
8305  action, true, 0, false);
8306  break;
8307  case VAR_RESET_ALL:
8308  ResetAllOptions();
8309  break;
8310  }
8311 }
void ImportSnapshot(const char *idstr)
Definition: snapmgr.c:1462
VariableSetKind kind
Definition: parsenodes.h:2039
void WarnNoTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3391
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:608
bool superuser(void)
Definition: superuser.c:46
#define linitial_node(type, l)
Definition: pg_list.h:198
GucAction
Definition: guc.h:191
#define list_make1(x1)
Definition: pg_list.h:227
bool IsInParallelMode(void)
Definition: xact.c:996
#define ERROR
Definition: elog.h:43
Definition: guc.h:75
void ResetAllOptions(void)
Definition: guc.c:5590
#define ereport(elevel, rest)
Definition: elog.h:141
Node * arg
Definition: parsenodes.h:731
#define Assert(condition)
Definition: c.h:739
#define lfirst(lc)
Definition: pg_list.h:190
#define nodeTag(nodeptr)
Definition: nodes.h:530
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define elog(elevel,...)
Definition: elog.h:228
char * defname
Definition: parsenodes.h:730
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
Definition: guc.c:8320
Value val
Definition: parsenodes.h:288
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:6798
void SetPGVariable(const char *name, List *args, bool is_local)
Definition: guc.c:8340

◆ ExtractSetVariableArgs()

char* ExtractSetVariableArgs ( VariableSetStmt stmt)

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

8321 {
8322  switch (stmt->kind)
8323  {
8324  case VAR_SET_VALUE:
8325  return flatten_set_variable_args(stmt->name, stmt->args);
8326  case VAR_SET_CURRENT:
8327  return GetConfigOptionByName(stmt->name, NULL, false);
8328  default:
8329  return NULL;
8330  }
8331 }
VariableSetKind kind
Definition: parsenodes.h:2039
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:9053
static char * flatten_set_variable_args(const char *name, List *args)
Definition: guc.c:7722

◆ FreeConfigVariables()

void FreeConfigVariables ( ConfigVariable list)

◆ GetConfigOption()

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

Definition at line 7587 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(), PostmasterMain(), and ssl_protocol_version_to_openssl().

7588 {
7589  struct config_generic *record;
7590  static char buffer[256];
7591 
7592  record = find_option(name, false, ERROR);
7593  if (record == NULL)
7594  {
7595  if (missing_ok)
7596  return NULL;
7597  ereport(ERROR,
7598  (errcode(ERRCODE_UNDEFINED_OBJECT),
7599  errmsg("unrecognized configuration parameter \"%s\"",
7600  name)));
7601  }
7602  if (restrict_privileged &&
7603  (record->flags & GUC_SUPERUSER_ONLY) &&
7604  !is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
7605  ereport(ERROR,
7606  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7607  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
7608  name)));
7609 
7610  switch (record->vartype)
7611  {
7612  case PGC_BOOL:
7613  return *((struct config_bool *) record)->variable ? "on" : "off";
7614 
7615  case PGC_INT:
7616  snprintf(buffer, sizeof(buffer), "%d",
7617  *((struct config_int *) record)->variable);
7618  return buffer;
7619 
7620  case PGC_REAL:
7621  snprintf(buffer, sizeof(buffer), "%g",
7622  *((struct config_real *) record)->variable);
7623  return buffer;
7624 
7625  case PGC_STRING:
7626  return *((struct config_string *) record)->variable;
7627 
7628  case PGC_ENUM:
7629  return config_enum_lookup_by_value((struct config_enum *) record,
7630  *((struct config_enum *) record)->variable);
7631  }
7632  return NULL;
7633 }
Oid GetUserId(void)
Definition: miscinit.c:380
int errcode(int sqlerrcode)
Definition: elog.c:608
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:6494
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
enum config_type vartype
Definition: guc_tables.h:156
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4924
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:5098
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define snprintf
Definition: port.h:192

◆ GetConfigOptionByName()

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

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

9054 {
9055  struct config_generic *record;
9056 
9057  record = find_option(name, false, ERROR);
9058  if (record == NULL)
9059  {
9060  if (missing_ok)
9061  {
9062  if (varname)
9063  *varname = NULL;
9064  return NULL;
9065  }
9066 
9067  ereport(ERROR,
9068  (errcode(ERRCODE_UNDEFINED_OBJECT),
9069  errmsg("unrecognized configuration parameter \"%s\"", name)));
9070  }
9071 
9072  if ((record->flags & GUC_SUPERUSER_ONLY) &&
9073  !is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
9074  ereport(ERROR,
9075  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
9076  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
9077  name)));
9078 
9079  if (varname)
9080  *varname = record->name;
9081 
9082  return _ShowOption(record, true);
9083 }
static char * _ShowOption(struct config_generic *record, bool use_units)
Definition: guc.c:9613
Oid GetUserId(void)
Definition: miscinit.c:380
const char * name
Definition: guc_tables.h:149
int errcode(int sqlerrcode)
Definition: elog.c:608
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4924
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:5098
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:822

◆ GetConfigOptionByNum()

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

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

9091 {
9092  char buffer[256];
9093  struct config_generic *conf;
9094 
9095  /* check requested variable number valid */
9096  Assert((varnum >= 0) && (varnum < num_guc_variables));
9097 
9098  conf = guc_variables[varnum];
9099 
9100  if (noshow)
9101  {
9102  if ((conf->flags & GUC_NO_SHOW_ALL) ||
9103  ((conf->flags & GUC_SUPERUSER_ONLY) &&
9104  !is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS)))
9105  *noshow = true;
9106  else
9107  *noshow = false;
9108  }
9109 
9110  /* first get the generic attributes */
9111 
9112  /* name */
9113  values[0] = conf->name;
9114 
9115  /* setting: use _ShowOption in order to avoid duplicating the logic */
9116  values[1] = _ShowOption(conf, false);
9117 
9118  /* unit, if any (NULL is fine) */
9119  values[2] = get_config_unit_name(conf->flags);
9120 
9121  /* group */
9122  values[3] = _(config_group_names[conf->group]);
9123 
9124  /* short_desc */
9125  values[4] = _(conf->short_desc);
9126 
9127  /* extra_desc */
9128  values[5] = _(conf->long_desc);
9129 
9130  /* context */
9131  values[6] = GucContext_Names[conf->context];
9132 
9133  /* vartype */
9134  values[7] = config_type_names[conf->vartype];
9135 
9136  /* source */
9137  values[8] = GucSource_Names[conf->source];
9138 
9139  /* now get the type specific attributes */
9140  switch (conf->vartype)
9141  {
9142  case PGC_BOOL:
9143  {
9144  struct config_bool *lconf = (struct config_bool *) conf;
9145 
9146  /* min_val */
9147  values[9] = NULL;
9148 
9149  /* max_val */
9150  values[10] = NULL;
9151 
9152  /* enumvals */
9153  values[11] = NULL;
9154 
9155  /* boot_val */
9156  values[12] = pstrdup(lconf->boot_val ? "on" : "off");
9157 
9158  /* reset_val */
9159  values[13] = pstrdup(lconf->reset_val ? "on" : "off");
9160  }
9161  break;
9162 
9163  case PGC_INT:
9164  {
9165  struct config_int *lconf = (struct config_int *) conf;
9166 
9167  /* min_val */
9168  snprintf(buffer, sizeof(buffer), "%d", lconf->min);
9169  values[9] = pstrdup(buffer);
9170 
9171  /* max_val */
9172  snprintf(buffer, sizeof(buffer), "%d", lconf->max);
9173  values[10] = pstrdup(buffer);
9174 
9175  /* enumvals */
9176  values[11] = NULL;
9177 
9178  /* boot_val */
9179  snprintf(buffer, sizeof(buffer), "%d", lconf->boot_val);
9180  values[12] = pstrdup(buffer);
9181 
9182  /* reset_val */
9183  snprintf(buffer, sizeof(buffer), "%d", lconf->reset_val);
9184  values[13] = pstrdup(buffer);
9185  }
9186  break;
9187 
9188  case PGC_REAL:
9189  {
9190  struct config_real *lconf = (struct config_real *) conf;
9191 
9192  /* min_val */
9193  snprintf(buffer, sizeof(buffer), "%g", lconf->min);
9194  values[9] = pstrdup(buffer);
9195 
9196  /* max_val */
9197  snprintf(buffer, sizeof(buffer), "%g", lconf->max);
9198  values[10] = pstrdup(buffer);
9199 
9200  /* enumvals */
9201  values[11] = NULL;
9202 
9203  /* boot_val */
9204  snprintf(buffer, sizeof(buffer), "%g", lconf->boot_val);
9205  values[12] = pstrdup(buffer);
9206 
9207  /* reset_val */
9208  snprintf(buffer, sizeof(buffer), "%g", lconf->reset_val);
9209  values[13] = pstrdup(buffer);
9210  }
9211  break;
9212 
9213  case PGC_STRING:
9214  {
9215  struct config_string *lconf = (struct config_string *) conf;
9216 
9217  /* min_val */
9218  values[9] = NULL;
9219 
9220  /* max_val */
9221  values[10] = NULL;
9222 
9223  /* enumvals */
9224  values[11] = NULL;
9225 
9226  /* boot_val */
9227  if (lconf->boot_val == NULL)
9228  values[12] = NULL;
9229  else
9230  values[12] = pstrdup(lconf->boot_val);
9231 
9232  /* reset_val */
9233  if (lconf->reset_val == NULL)
9234  values[13] = NULL;
9235  else
9236  values[13] = pstrdup(lconf->reset_val);
9237  }
9238  break;
9239 
9240  case PGC_ENUM:
9241  {
9242  struct config_enum *lconf = (struct config_enum *) conf;
9243 
9244  /* min_val */
9245  values[9] = NULL;
9246 
9247  /* max_val */
9248  values[10] = NULL;
9249 
9250  /* enumvals */
9251 
9252  /*
9253  * NOTE! enumvals with double quotes in them are not
9254  * supported!
9255  */
9256  values[11] = config_enum_get_options((struct config_enum *) conf,
9257  "{\"", "\"}", "\",\"");
9258 
9259  /* boot_val */
9261  lconf->boot_val));
9262 
9263  /* reset_val */
9265  lconf->reset_val));
9266  }
9267  break;
9268 
9269  default:
9270  {
9271  /*
9272  * should never get here, but in case we do, set 'em to NULL
9273  */
9274 
9275  /* min_val */
9276  values[9] = NULL;
9277 
9278  /* max_val */
9279  values[10] = NULL;
9280 
9281  /* enumvals */
9282  values[11] = NULL;
9283 
9284  /* boot_val */
9285  values[12] = NULL;
9286 
9287  /* reset_val */
9288  values[13] = NULL;
9289  }
9290  break;
9291  }
9292 
9293  /*
9294  * If the setting came from a config file, set the source location. For
9295  * security reasons, we don't show source file/line number for
9296  * insufficiently-privileged users.
9297  */
9298  if (conf->source == PGC_S_FILE &&
9299  is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
9300  {
9301  values[14] = conf->sourcefile;
9302  snprintf(buffer, sizeof(buffer), "%d", conf->sourceline);
9303  values[15] = pstrdup(buffer);
9304  }
9305  else
9306  {
9307  values[14] = NULL;
9308  values[15] = NULL;
9309  }
9310 
9311  values[16] = (conf->status & GUC_PENDING_RESTART) ? "t" : "f";
9312 }
GucSource source
Definition: guc_tables.h:158
static char * _ShowOption(struct config_generic *record, bool use_units)
Definition: guc.c:9613
const char * long_desc
Definition: guc_tables.h:153
double reset_val
Definition: guc_tables.h:222
Oid GetUserId(void)
Definition: miscinit.c:380
const char * name
Definition: guc_tables.h:149
const char *const config_type_names[]
Definition: guc.c:756
char * pstrdup(const char *in)
Definition: mcxt.c:1186
const char * short_desc
Definition: guc_tables.h:152
int boot_val
Definition: guc_tables.h:199
const char * boot_val
Definition: guc_tables.h:231
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:6494
#define GUC_NO_SHOW_ALL
Definition: guc.h:206
const char *const GucContext_Names[]
Definition: guc.c:606
const char *const config_group_names[]
Definition: guc.c:643
static int num_guc_variables
Definition: guc.c:4644
char * sourcefile
Definition: guc_tables.h:164
bool boot_val
Definition: guc_tables.h:185
static const char * get_config_unit_name(int flags)
Definition: guc.c:6285
static struct config_generic ** guc_variables
Definition: guc.c:4641
enum config_type vartype
Definition: guc_tables.h:156
double max
Definition: guc_tables.h:217
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4924
char * reset_val
Definition: guc_tables.h:236
double boot_val
Definition: guc_tables.h:215
#define Assert(condition)
Definition: c.h:739
#define GUC_PENDING_RESTART
Definition: guc_tables.h:175
double min
Definition: guc_tables.h:216
static Datum values[MAXATTR]
Definition: bootstrap.c:167
enum config_group group
Definition: guc_tables.h:151
bool reset_val
Definition: guc_tables.h:190
const char *const GucSource_Names[]
Definition: guc.c:622
#define snprintf
Definition: port.h:192
#define _(x)
Definition: elog.c:87
static char * config_enum_get_options(struct config_enum *record, const char *prefix, const char *suffix, const char *separator)
Definition: guc.c:6543
GucContext context
Definition: guc_tables.h:150
int reset_val
Definition: guc_tables.h:206

◆ GetConfigOptionFlags()

int GetConfigOptionFlags ( const char *  name,
bool  missing_ok 
)

Definition at line 7692 of file guc.c.

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

Referenced by pg_get_functiondef().

7693 {
7694  struct config_generic *record;
7695 
7696  record = find_option(name, false, WARNING);
7697  if (record == NULL)
7698  {
7699  if (missing_ok)
7700  return 0;
7701  ereport(ERROR,
7702  (errcode(ERRCODE_UNDEFINED_OBJECT),
7703  errmsg("unrecognized configuration parameter \"%s\"",
7704  name)));
7705  }
7706  return record->flags;
7707 }
int errcode(int sqlerrcode)
Definition: elog.c:608
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
#define WARNING
Definition: elog.h:40
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:5098
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:822

◆ GetConfigOptionResetString()

const char* GetConfigOptionResetString ( const char *  name)

Definition at line 7643 of file guc.c.

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

Referenced by check_datestyle().

7644 {
7645  struct config_generic *record;
7646  static char buffer[256];
7647 
7648  record = find_option(name, false, ERROR);
7649  if (record == NULL)
7650  ereport(ERROR,
7651  (errcode(ERRCODE_UNDEFINED_OBJECT),
7652  errmsg("unrecognized configuration parameter \"%s\"", name)));
7653  if ((record->flags & GUC_SUPERUSER_ONLY) &&
7654  !is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
7655  ereport(ERROR,
7656  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7657  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
7658  name)));
7659 
7660  switch (record->vartype)
7661  {
7662  case PGC_BOOL:
7663  return ((struct config_bool *) record)->reset_val ? "on" : "off";
7664 
7665  case PGC_INT:
7666  snprintf(buffer, sizeof(buffer), "%d",
7667  ((struct config_int *) record)->reset_val);
7668  return buffer;
7669 
7670  case PGC_REAL:
7671  snprintf(buffer, sizeof(buffer), "%g",
7672  ((struct config_real *) record)->reset_val);
7673  return buffer;
7674 
7675  case PGC_STRING:
7676  return ((struct config_string *) record)->reset_val;
7677 
7678  case PGC_ENUM:
7679  return config_enum_lookup_by_value((struct config_enum *) record,
7680  ((struct config_enum *) record)->reset_val);
7681  }
7682  return NULL;
7683 }
Oid GetUserId(void)
Definition: miscinit.c:380
int errcode(int sqlerrcode)
Definition: elog.c:608
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:6494
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
enum config_type vartype
Definition: guc_tables.h:156
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4924
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:5098
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define snprintf
Definition: port.h:192

◆ GetNumConfigOptions()

int GetNumConfigOptions ( void  )

Definition at line 9318 of file guc.c.

References num_guc_variables.

Referenced by GucInfoMain(), and show_all_settings().

9319 {
9320  return num_guc_variables;
9321 }
static int num_guc_variables
Definition: guc.c:4644

◆ GetPGVariable()

void GetPGVariable ( const char *  name,
DestReceiver dest 
)

Definition at line 8814 of file guc.c.

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

Referenced by exec_replication_command(), and standard_ProcessUtility().

8815 {
8816  if (guc_name_compare(name, "all") == 0)
8817  ShowAllGUCConfig(dest);
8818  else
8819  ShowGUCConfigOption(name, dest);
8820 }
static void ShowGUCConfigOption(const char *name, DestReceiver *dest)
Definition: guc.c:8858
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:5159
static void ShowAllGUCConfig(DestReceiver *dest)
Definition: guc.c:8886
const char * name
Definition: encode.c:521

◆ GetPGVariableResultDesc()

TupleDesc GetPGVariableResultDesc ( const char *  name)

Definition at line 8823 of file guc.c.

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

Referenced by UtilityTupleDescriptor().

8824 {
8825  TupleDesc tupdesc;
8826 
8827  if (guc_name_compare(name, "all") == 0)
8828  {
8829  /* need a tuple descriptor representing three TEXT columns */
8830  tupdesc = CreateTemplateTupleDesc(3);
8831  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
8832  TEXTOID, -1, 0);
8833  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
8834  TEXTOID, -1, 0);
8835  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
8836  TEXTOID, -1, 0);
8837  }
8838  else
8839  {
8840  const char *varname;
8841 
8842  /* Get the canonical spelling of name */
8843  (void) GetConfigOptionByName(name, &varname, false);
8844 
8845  /* need a tuple descriptor representing a single TEXT column */
8846  tupdesc = CreateTemplateTupleDesc(1);
8847  TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
8848  TEXTOID, -1, 0);
8849  }
8850  return tupdesc;
8851 }
TupleDesc CreateTemplateTupleDesc(int natts)
Definition: tupdesc.c:44
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:5159
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:9053
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:603
const char * name
Definition: encode.c:521
int16 AttrNumber
Definition: attnum.h:21

◆ GUC_check_errcode()

◆ GUCArrayAdd()

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

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

10479 {
10480  struct config_generic *record;
10481  Datum datum;
10482  char *newval;
10483  ArrayType *a;
10484 
10485  Assert(name);
10486  Assert(value);
10487 
10488  /* test if the option is valid and we're allowed to set it */
10489  (void) validate_option_array_item(name, value, false);
10490 
10491  /* normalize name (converts obsolete GUC names to modern spellings) */
10492  record = find_option(name, false, WARNING);
10493  if (record)
10494  name = record->name;
10495 
10496  /* build new item for array */
10497  newval = psprintf("%s=%s", name, value);
10498  datum = CStringGetTextDatum(newval);
10499 
10500  if (array)
10501  {
10502  int index;
10503  bool isnull;
10504  int i;
10505 
10506  Assert(ARR_ELEMTYPE(array) == TEXTOID);
10507  Assert(ARR_NDIM(array) == 1);
10508  Assert(ARR_LBOUND(array)[0] == 1);
10509 
10510  index = ARR_DIMS(array)[0] + 1; /* add after end */
10511 
10512  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
10513  {
10514  Datum d;
10515  char *current;
10516 
10517  d = array_ref(array, 1, &i,
10518  -1 /* varlenarray */ ,
10519  -1 /* TEXT's typlen */ ,
10520  false /* TEXT's typbyval */ ,
10521  'i' /* TEXT's typalign */ ,
10522  &isnull);
10523  if (isnull)
10524  continue;
10525  current = TextDatumGetCString(d);
10526 
10527  /* check for match up through and including '=' */
10528  if (strncmp(current, newval, strlen(name) + 1) == 0)
10529  {
10530  index = i;
10531  break;
10532  }
10533  }
10534 
10535  a = array_set(array, 1, &index,
10536  datum,
10537  false,
10538  -1 /* varlena array */ ,
10539  -1 /* TEXT's typlen */ ,
10540  false /* TEXT's typbyval */ ,
10541  'i' /* TEXT's typalign */ );
10542  }
10543  else
10544  a = construct_array(&datum, 1,
10545  TEXTOID,
10546  -1, false, 'i');
10547 
10548  return a;
10549 }
const char * name
Definition: guc_tables.h:149
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3291
static struct @145 value
ArrayType * array_set(ArrayType *array, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3093
#define ARR_LBOUND(a)
Definition: array.h:284
Definition: type.h:89
static bool validate_option_array_item(const char *name, const char *value, bool skipIfNoPermissions)
Definition: guc.c:10704
#define ARR_DIMS(a)
Definition: array.h:282
Datum array_ref(ArrayType *array, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:3076
#define WARNING
Definition: elog.h:40
#define TextDatumGetCString(d)
Definition: builtins.h:84
uintptr_t Datum
Definition: postgres.h:367
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:5098
#define Assert(condition)
Definition: c.h:739
#define newval
#define ARR_NDIM(a)
Definition: array.h:278
const char * name
Definition: encode.c:521
int i
#define CStringGetTextDatum(s)
Definition: builtins.h:83
#define ARR_ELEMTYPE(a)
Definition: array.h:280

◆ GUCArrayDelete()

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

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

10559 {
10560  struct config_generic *record;
10561  ArrayType *newarray;
10562  int i;
10563  int index;
10564 
10565  Assert(name);
10566 
10567  /* test if the option is valid and we're allowed to set it */
10568  (void) validate_option_array_item(name, NULL, false);
10569 
10570  /* normalize name (converts obsolete GUC names to modern spellings) */
10571  record = find_option(name, false, WARNING);
10572  if (record)
10573  name = record->name;
10574 
10575  /* if array is currently null, then surely nothing to delete */
10576  if (!array)
10577  return NULL;
10578 
10579  newarray = NULL;
10580  index = 1;
10581 
10582  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
10583  {
10584  Datum d;
10585  char *val;
10586  bool isnull;
10587 
10588  d = array_ref(array, 1, &i,
10589  -1 /* varlenarray */ ,
10590  -1 /* TEXT's typlen */ ,
10591  false /* TEXT's typbyval */ ,
10592  'i' /* TEXT's typalign */ ,
10593  &isnull);
10594  if (isnull)
10595  continue;
10596  val = TextDatumGetCString(d);
10597 
10598  /* ignore entry if it's what we want to delete */
10599  if (strncmp(val, name, strlen(name)) == 0
10600  && val[strlen(name)] == '=')
10601  continue;
10602 
10603  /* else add it to the output array */
10604  if (newarray)
10605  newarray = array_set(newarray, 1, &index,
10606  d,
10607  false,
10608  -1 /* varlenarray */ ,
10609  -1 /* TEXT's typlen */ ,
10610  false /* TEXT's typbyval */ ,
10611  'i' /* TEXT's typalign */ );
10612  else
10613  newarray = construct_array(&d, 1,
10614  TEXTOID,
10615  -1, false, 'i');
10616 
10617  index++;
10618  }
10619 
10620  return newarray;
10621 }
const char * name
Definition: guc_tables.h:149
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3291
ArrayType * array_set(ArrayType *array, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3093
Definition: type.h:89
static bool validate_option_array_item(const char *name, const char *value, bool skipIfNoPermissions)
Definition: guc.c:10704
#define ARR_DIMS(a)
Definition: array.h:282
Datum array_ref(ArrayType *array, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:3076
#define WARNING
Definition: elog.h:40
#define TextDatumGetCString(d)
Definition: builtins.h:84
uintptr_t Datum
Definition: postgres.h:367
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:5098
#define Assert(condition)
Definition: c.h:739
const char * name
Definition: encode.c:521
int i
long val
Definition: informix.c:664

◆ GUCArrayReset()

ArrayType* GUCArrayReset ( ArrayType array)

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

10631 {
10632  ArrayType *newarray;
10633  int i;
10634  int index;
10635 
10636  /* if array is currently null, nothing to do */
10637  if (!array)
10638  return NULL;
10639 
10640  /* if we're superuser, we can delete everything, so just do it */
10641  if (superuser())
10642  return NULL;
10643 
10644  newarray = NULL;
10645  index = 1;
10646 
10647  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
10648  {
10649  Datum d;
10650  char *val;
10651  char *eqsgn;
10652  bool isnull;
10653 
10654  d = array_ref(array, 1, &i,
10655  -1 /* varlenarray */ ,
10656  -1 /* TEXT's typlen */ ,
10657  false /* TEXT's typbyval */ ,
10658  'i' /* TEXT's typalign */ ,
10659  &isnull);
10660  if (isnull)
10661  continue;
10662  val = TextDatumGetCString(d);
10663 
10664  eqsgn = strchr(val, '=');
10665  *eqsgn = '\0';
10666 
10667  /* skip if we have permission to delete it */
10668  if (validate_option_array_item(val, NULL, true))
10669  continue;
10670 
10671  /* else add it to the output array */
10672  if (newarray)
10673  newarray = array_set(newarray, 1, &index,
10674  d,
10675  false,
10676  -1 /* varlenarray */ ,
10677  -1 /* TEXT's typlen */ ,
10678  false /* TEXT's typbyval */ ,
10679  'i' /* TEXT's typalign */ );
10680  else
10681  newarray = construct_array(&d, 1,
10682  TEXTOID,
10683  -1, false, 'i');
10684 
10685  index++;
10686  pfree(val);
10687  }
10688 
10689  return newarray;
10690 }
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3291
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:3093
Definition: type.h:89
void pfree(void *pointer)
Definition: mcxt.c:1056
static bool validate_option_array_item(const char *name, const char *value, bool skipIfNoPermissions)
Definition: guc.c:10704
#define ARR_DIMS(a)
Definition: array.h:282
Datum array_ref(ArrayType *array, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:3076
#define TextDatumGetCString(d)
Definition: builtins.h:84
uintptr_t Datum
Definition: postgres.h:367
int i
long val
Definition: informix.c:664

◆ InitializeGUCOptions()

void InitializeGUCOptions ( void  )

Definition at line 5193 of file guc.c.

References build_guc_variables(), i, InitializeGUCOptionsFromEnvironment(), InitializeOneGUCOption(), num_guc_variables, pg_timezone_initialize(), PGC_POSTMASTER, PGC_S_OVERRIDE, and SetConfigOption().

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

5194 {
5195  int i;
5196 
5197  /*
5198  * Before log_line_prefix could possibly receive a nonempty setting, make
5199  * sure that timezone processing is minimally alive (see elog.c).
5200  */
5202 
5203  /*
5204  * Build sorted array of all GUC variables.
5205  */
5207 
5208  /*
5209  * Load all variables with their compiled-in defaults, and initialize
5210  * status fields as needed.
5211  */
5212  for (i = 0; i < num_guc_variables; i++)
5213  {
5215  }
5216 
5217  guc_dirty = false;
5218 
5219  reporting_enabled = false;
5220 
5221  /*
5222  * Prevent any attempt to override the transaction modes from
5223  * non-interactive sources.
5224  */
5225  SetConfigOption("transaction_isolation", "read committed",
5227  SetConfigOption("transaction_read_only", "no",
5229  SetConfigOption("transaction_deferrable", "no",
5231 
5232  /*
5233  * For historical reasons, some GUC parameters can receive defaults from
5234  * environment variables. Process those settings.
5235  */
5237 }
void build_guc_variables(void)
Definition: guc.c:4908
static void InitializeGUCOptionsFromEnvironment(void)
Definition: guc.c:5249
void pg_timezone_initialize(void)
Definition: pgtz.c:363
static int num_guc_variables
Definition: guc.c:4644
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:7563
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:5295
static struct config_generic ** guc_variables
Definition: guc.c:4641
int i
static bool reporting_enabled
Definition: guc.c:4655
static bool guc_dirty
Definition: guc.c:4653

◆ NewGUCNestLevel()

◆ parse_int()

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

Definition at line 6342 of file guc.c.

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

Referenced by parse_and_validate_value(), and parse_one_reloption().

6343 {
6344  /*
6345  * We assume here that double is wide enough to represent any integer
6346  * value with adequate precision.
6347  */
6348  double val;
6349  char *endptr;
6350 
6351  /* To suppress compiler warnings, always set output params */
6352  if (result)
6353  *result = 0;
6354  if (hintmsg)
6355  *hintmsg = NULL;
6356 
6357  /*
6358  * Try to parse as an integer (allowing octal or hex input). If the
6359  * conversion stops at a decimal point or 'e', or overflows, re-parse as
6360  * float. This should work fine as long as we have no unit names starting
6361  * with 'e'. If we ever do, the test could be extended to check for a
6362  * sign or digit after 'e', but for now that's unnecessary.
6363  */
6364  errno = 0;
6365  val = strtol(value, &endptr, 0);
6366  if (*endptr == '.' || *endptr == 'e' || *endptr == 'E' ||
6367  errno == ERANGE)
6368  {
6369  errno = 0;
6370  val = strtod(value, &endptr);
6371  }
6372 
6373  if (endptr == value || errno == ERANGE)
6374  return false; /* no HINT for these cases */
6375 
6376  /* reject NaN (infinities will fail range check below) */
6377  if (isnan(val))
6378  return false; /* treat same as syntax error; no HINT */
6379 
6380  /* allow whitespace between number and unit */
6381  while (isspace((unsigned char) *endptr))
6382  endptr++;
6383 
6384  /* Handle possible unit */
6385  if (*endptr != '\0')
6386  {
6387  if ((flags & GUC_UNIT) == 0)
6388  return false; /* this setting does not accept a unit */
6389 
6390  if (!convert_to_base_unit(val,
6391  endptr, (flags & GUC_UNIT),
6392  &val))
6393  {
6394  /* invalid unit, or garbage after the unit; set hint and fail. */
6395  if (hintmsg)
6396  {
6397  if (flags & GUC_UNIT_MEMORY)
6398  *hintmsg = memory_units_hint;
6399  else
6400  *hintmsg = time_units_hint;
6401  }
6402  return false;
6403  }
6404  }
6405 
6406  /* Round to int, then check for overflow */
6407  val = rint(val);
6408 
6409  if (val > INT_MAX || val < INT_MIN)
6410  {
6411  if (hintmsg)
6412  *hintmsg = gettext_noop("Value exceeds integer range.");
6413  return false;
6414  }
6415 
6416  if (result)
6417  *result = (int) val;
6418  return true;
6419 }
#define gettext_noop(x)
Definition: c.h:1147
static struct @145 value
#define GUC_UNIT
Definition: guc.h:232
double rint(double x)
Definition: rint.c:21
static const char * time_units_hint
Definition: guc.c:835
static bool convert_to_base_unit(double value, const char *unit, int base_unit, double *base_value)
Definition: guc.c:6142
long val
Definition: informix.c:664
static const char * memory_units_hint
Definition: guc.c:798
#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 6432 of file guc.c.

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

Referenced by parse_and_validate_value(), and parse_one_reloption().

6433 {
6434  double val;
6435  char *endptr;
6436 
6437  /* To suppress compiler warnings, always set output params */
6438  if (result)
6439  *result = 0;
6440  if (hintmsg)
6441  *hintmsg = NULL;
6442 
6443  errno = 0;
6444  val = strtod(value, &endptr);
6445 
6446  if (endptr == value || errno == ERANGE)
6447  return false; /* no HINT for these cases */
6448 
6449  /* reject NaN (infinities will fail range checks later) */
6450  if (isnan(val))
6451  return false; /* treat same as syntax error; no HINT */
6452 
6453  /* allow whitespace between number and unit */
6454  while (isspace((unsigned char) *endptr))
6455  endptr++;
6456 
6457  /* Handle possible unit */
6458  if (*endptr != '\0')
6459  {
6460  if ((flags & GUC_UNIT) == 0)
6461  return false; /* this setting does not accept a unit */
6462 
6463  if (!convert_to_base_unit(val,
6464  endptr, (flags & GUC_UNIT),
6465  &val))
6466  {
6467  /* invalid unit, or garbage after the unit; set hint and fail. */
6468  if (hintmsg)
6469  {
6470  if (flags & GUC_UNIT_MEMORY)
6471  *hintmsg = memory_units_hint;
6472  else
6473  *hintmsg = time_units_hint;
6474  }
6475  return false;
6476  }
6477  }
6478 
6479  if (result)
6480  *result = val;
6481  return true;
6482 }
static struct @145 value
#define GUC_UNIT
Definition: guc.h:232
static const char * time_units_hint
Definition: guc.c:835
static bool convert_to_base_unit(double value, const char *unit, int base_unit, double *base_value)
Definition: guc.c:6142
long val
Definition: informix.c:664
static const char * memory_units_hint
Definition: guc.c:798
#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 10382 of file guc.c.

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

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

10383 {
10384  size_t equal_pos;
10385  char *cp;
10386 
10387  AssertArg(string);
10388  AssertArg(name);
10389  AssertArg(value);
10390 
10391  equal_pos = strcspn(string, "=");
10392 
10393  if (string[equal_pos] == '=')
10394  {
10395  *name = guc_malloc(FATAL, equal_pos + 1);
10396  strlcpy(*name, string, equal_pos + 1);
10397 
10398  *value = guc_strdup(FATAL, &string[equal_pos + 1]);
10399  }
10400  else
10401  {
10402  /* no equal sign in string */
10403  *name = guc_strdup(FATAL, string);
10404  *value = NULL;
10405  }
10406 
10407  for (cp = *name; *cp; cp++)
10408  if (*cp == '-')
10409  *cp = '_';
10410 }
static struct @145 value
static char * guc_strdup(int elevel, const char *src)
Definition: guc.c:4717
#define FATAL
Definition: elog.h:52
#define AssertArg(condition)
Definition: c.h:741
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
const char * name
Definition: encode.c:521
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4685

◆ ProcessConfigFile()

◆ ProcessGUCArray()

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

Definition at line 10420 of file guc.c.

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

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

10422 {
10423  int i;
10424 
10425  Assert(array != NULL);
10426  Assert(ARR_ELEMTYPE(array) == TEXTOID);
10427  Assert(ARR_NDIM(array) == 1);
10428  Assert(ARR_LBOUND(array)[0] == 1);
10429 
10430  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
10431  {
10432  Datum d;
10433  bool isnull;
10434  char *s;
10435  char *name;
10436  char *value;
10437 
10438  d = array_ref(array, 1, &i,
10439  -1 /* varlenarray */ ,
10440  -1 /* TEXT's typlen */ ,
10441  false /* TEXT's typbyval */ ,
10442  'i' /* TEXT's typalign */ ,
10443  &isnull);
10444 
10445  if (isnull)
10446  continue;
10447 
10448  s = TextDatumGetCString(d);
10449 
10450  ParseLongOption(s, &name, &value);
10451  if (!value)
10452  {
10453  ereport(WARNING,
10454  (errcode(ERRCODE_SYNTAX_ERROR),
10455  errmsg("could not parse setting for parameter \"%s\"",
10456  name)));
10457  free(name);
10458  continue;
10459  }
10460 
10461  (void) set_config_option(name, value,
10462  context, source,
10463  action, true, 0, false);
10464 
10465  free(name);
10466  if (value)
10467  free(value);
10468  pfree(s);
10469  }
10470 }
GucSource source
Definition: guc_tables.h:158
void ParseLongOption(const char *string, char **name, char **value)
Definition: guc.c:10382
static struct @145 value
int errcode(int sqlerrcode)
Definition: elog.c:608
#define ARR_LBOUND(a)
Definition: array.h:284
void pfree(void *pointer)
Definition: mcxt.c:1056
#define ARR_DIMS(a)
Definition: array.h:282
#define ereport(elevel, rest)
Definition: elog.h:141
Datum array_ref(ArrayType *array, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:3076
#define WARNING
Definition: elog.h:40
#define TextDatumGetCString(d)
Definition: builtins.h:84
uintptr_t Datum
Definition: postgres.h:367
#define free(a)
Definition: header.h:65
#define Assert(condition)
Definition: c.h:739
#define ARR_NDIM(a)
Definition: array.h:278
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:822
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:6798
#define ARR_ELEMTYPE(a)
Definition: array.h:280
GucContext context
Definition: guc_tables.h:150

◆ ResetAllOptions()

void ResetAllOptions ( void  )

Definition at line 5590 of file guc.c.

References config_bool::assign_hook, config_int::assign_hook, config_real::assign_hook, config_string::assign_hook, config_enum::assign_hook, config_generic::context, config_generic::extra, config_generic::flags, config_bool::gen, config_int::gen, config_real::gen, config_string::gen, config_enum::gen, GUC_ACTION_SET, GUC_NO_RESET_ALL, GUC_REPORT, i, num_guc_variables, PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_S_OVERRIDE, PGC_STRING, PGC_SUSET, PGC_USERSET, push_old_value(), ReportGUCOption(), config_bool::reset_extra, config_int::reset_extra, config_real::reset_extra, config_string::reset_extra, config_enum::reset_extra, config_generic::reset_scontext, config_generic::reset_source, config_bool::reset_val, config_int::reset_val, config_real::reset_val, config_string::reset_val, config_enum::reset_val, config_generic::scontext, set_extra_field(), set_string_field(), config_generic::source, config_bool::variable, config_int::variable, config_real::variable, config_string::variable, config_enum::variable, and config_generic::vartype.

Referenced by DiscardAll(), and ExecSetVariableStmt().

5591 {
5592  int i;
5593 
5594  for (i = 0; i < num_guc_variables; i++)
5595  {
5596  struct config_generic *gconf = guc_variables[i];
5597 
5598  /* Don't reset non-SET-able values */
5599  if (gconf->context != PGC_SUSET &&
5600  gconf->context != PGC_USERSET)
5601  continue;
5602  /* Don't reset if special exclusion from RESET ALL */
5603  if (gconf->flags & GUC_NO_RESET_ALL)
5604  continue;
5605  /* No need to reset if wasn't SET */
5606  if (gconf->source <= PGC_S_OVERRIDE)
5607  continue;
5608 
5609  /* Save old value to support transaction abort */
5611 
5612  switch (gconf->vartype)
5613  {
5614  case PGC_BOOL:
5615  {
5616  struct config_bool *conf = (struct config_bool *) gconf;
5617 
5618  if (conf->assign_hook)
5619  conf->assign_hook(conf->reset_val,
5620  conf->reset_extra);
5621  *conf->variable = conf->reset_val;
5622  set_extra_field(&conf->gen, &conf->gen.extra,
5623  conf->reset_extra);
5624  break;
5625  }
5626  case PGC_INT:
5627  {
5628  struct config_int *conf = (struct config_int *) gconf;
5629 
5630  if (conf->assign_hook)
5631  conf->assign_hook(conf->reset_val,
5632  conf->reset_extra);
5633  *conf->variable = conf->reset_val;
5634  set_extra_field(&conf->gen, &conf->gen.extra,
5635  conf->reset_extra);
5636  break;
5637  }
5638  case PGC_REAL:
5639  {
5640  struct config_real *conf = (struct config_real *) gconf;
5641 
5642  if (conf->assign_hook)
5643  conf->assign_hook(conf->reset_val,
5644  conf->reset_extra);
5645  *conf->variable = conf->reset_val;
5646  set_extra_field(&conf->gen, &conf->gen.extra,
5647  conf->reset_extra);
5648  break;
5649  }
5650  case PGC_STRING:
5651  {
5652  struct config_string *conf = (struct config_string *) gconf;
5653 
5654  if (conf->assign_hook)
5655  conf->assign_hook(conf->reset_val,
5656  conf->reset_extra);
5657  set_string_field(conf, conf->variable, conf->reset_val);
5658  set_extra_field(&conf->gen, &conf->gen.extra,
5659  conf->reset_extra);
5660  break;
5661  }
5662  case PGC_ENUM:
5663  {
5664  struct config_enum *conf = (struct config_enum *) gconf;
5665 
5666  if (conf->assign_hook)
5667  conf->assign_hook(conf->reset_val,
5668  conf->reset_extra);
5669  *conf->variable = conf->reset_val;
5670  set_extra_field(&conf->gen, &conf->gen.extra,
5671  conf->reset_extra);
5672  break;
5673  }
5674  }
5675 
5676  gconf->source = gconf->reset_source;
5677  gconf->scontext = gconf->reset_scontext;
5678 
5679  if (gconf->flags & GUC_REPORT)
5680  ReportGUCOption(gconf);
5681  }
5682 }
GucSource source
Definition: guc_tables.h:158
void * reset_extra
Definition: guc_tables.h:207
GucRealAssignHook assign_hook
Definition: guc_tables.h:219
double reset_val
Definition: guc_tables.h:222
#define GUC_NO_RESET_ALL
Definition: guc.h:207
char ** variable
Definition: guc_tables.h:230
bool * variable
Definition: guc_tables.h:184
GucEnumAssignHook assign_hook
Definition: guc_tables.h:248
GucBoolAssignHook assign_hook
Definition: guc_tables.h:187
GucContext scontext
Definition: guc_tables.h:160
GucIntAssignHook assign_hook
Definition: guc_tables.h:203
static void push_old_value(struct config_generic *gconf, GucAction action)
Definition: guc.c:5690
int * variable
Definition: guc_tables.h:198
int * variable
Definition: guc_tables.h:244
static int num_guc_variables
Definition: guc.c:4644
void * reset_extra
Definition: guc_tables.h:252
Definition: guc.h:75
static void set_extra_field(struct config_generic *gconf, void **field, void *newval)
Definition: guc.c:4818
GucSource reset_source
Definition: guc_tables.h:159
struct config_generic gen
Definition: guc_tables.h:182
struct config_generic gen
Definition: guc_tables.h:196
#define GUC_REPORT
Definition: guc.h:208
double * variable
Definition: guc_tables.h:214
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4757
static struct config_generic ** guc_variables
Definition: guc.c:4641
enum config_type vartype
Definition: guc_tables.h:156
void * reset_extra
Definition: guc_tables.h:223
struct config_generic gen
Definition: guc_tables.h:242
struct config_generic gen
Definition: guc_tables.h:228
char * reset_val
Definition: guc_tables.h:236
GucStringAssignHook assign_hook
Definition: guc_tables.h:233
void * reset_extra
Definition: guc_tables.h:237
void * reset_extra
Definition: guc_tables.h:191
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:6115
bool reset_val
Definition: guc_tables.h:190
GucContext context
Definition: guc_tables.h:150
struct config_generic gen
Definition: guc_tables.h:212
GucContext reset_scontext
Definition: guc_tables.h:161
int reset_val
Definition: guc_tables.h:206

◆ RestoreGUCState()

void RestoreGUCState ( void *  gucstate)

Definition at line 10308 of file guc.c.

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

Referenced by ParallelWorkerMain().

10309 {
10310  char *varname,
10311  *varvalue,
10312  *varsourcefile;
10313  int varsourceline;
10314  GucSource varsource;
10315  GucContext varscontext;
10316  char *srcptr = (char *) gucstate;
10317  char *srcend;
10318  Size len;
10319  int i;
10320  ErrorContextCallback error_context_callback;
10321 
10322  /* See comment at can_skip_gucvar(). */
10323  for (i = 0; i < num_guc_variables; i++)
10324  if (!can_skip_gucvar(guc_variables[i]))
10326 
10327  /* First item is the length of the subsequent data */
10328  memcpy(&len, gucstate, sizeof(len));
10329 
10330  srcptr += sizeof(len);
10331  srcend = srcptr + len;
10332 
10333  /* If the GUC value check fails, we want errors to show useful context. */
10334  error_context_callback.callback = guc_restore_error_context_callback;
10335  error_context_callback.previous = error_context_stack;
10336  error_context_callback.arg = NULL;
10337  error_context_stack = &error_context_callback;
10338 
10339  while (srcptr < srcend)
10340  {
10341  int result;
10342  char *error_context_name_and_value[2];
10343 
10344  varname = read_gucstate(&srcptr, srcend);
10345  varvalue = read_gucstate(&srcptr, srcend);
10346  varsourcefile = read_gucstate(&srcptr, srcend);
10347  if (varsourcefile[0])
10348  read_gucstate_binary(&srcptr, srcend,
10349  &varsourceline, sizeof(varsourceline));
10350  else
10351  varsourceline = 0;
10352  read_gucstate_binary(&srcptr, srcend,
10353  &varsource, sizeof(varsource));
10354  read_gucstate_binary(&srcptr, srcend,
10355  &varscontext, sizeof(varscontext));
10356 
10357  error_context_name_and_value[0] = varname;
10358  error_context_name_and_value[1] = varvalue;
10359  error_context_callback.arg = &error_context_name_and_value[0];
10360  result = set_config_option(varname, varvalue, varscontext, varsource,
10361  GUC_ACTION_SET, true, ERROR, true);
10362  if (result <= 0)
10363  ereport(ERROR,
10364  (errcode(ERRCODE_INTERNAL_ERROR),
10365  errmsg("parameter \"%s\" could not be set", varname)));
10366  if (varsourcefile[0])
10367  set_config_sourcefile(varname, varsourcefile, varsourceline);
10368  error_context_callback.arg = NULL;
10369  }
10370 
10371  error_context_stack = error_context_callback.previous;
10372 }
GucContext
Definition: guc.h:68
static void static void set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
Definition: guc.c:7529
static void read_gucstate_binary(char **srcptr, char *srcend, void *dest, Size size)
Definition: guc.c:10278
int errcode(int sqlerrcode)
Definition: elog.c:608
void(* callback)(void *arg)
Definition: elog.h:256
struct ErrorContextCallback * previous
Definition: elog.h:255
GucSource
Definition: guc.h:105
ErrorContextCallback * error_context_stack
Definition: elog.c:91
#define ERROR
Definition: elog.h:43
static int num_guc_variables
Definition: guc.c:4644
static bool can_skip_gucvar(struct config_generic *gconf)
Definition: guc.c:9974
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:5295
static void guc_restore_error_context_callback(void *arg)
Definition: guc.c:10292
#define ereport(elevel, rest)
Definition: elog.h:141
static struct config_generic ** guc_variables
Definition: guc.c:4641
static char * read_gucstate(char **srcptr, char *srcend)
Definition: guc.c:10255
size_t Size
Definition: c.h:467
int errmsg(const char *fmt,...)
Definition: elog.c:822
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:6798

◆ SelectConfigFiles()

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

Definition at line 5415 of file guc.c.

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

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

5416 {
5417  char *configdir;
5418  char *fname;
5419  struct stat stat_buf;
5420 
5421  /* configdir is -D option, or $PGDATA if no -D */
5422  if (userDoption)
5423  configdir = make_absolute_path(userDoption);
5424  else
5425  configdir = make_absolute_path(getenv("PGDATA"));
5426 
5427  if (configdir && stat(configdir, &stat_buf) != 0)
5428  {
5429  write_stderr("%s: could not access directory \"%s\": %s\n",
5430  progname,
5431  configdir,
5432  strerror(errno));
5433  if (errno == ENOENT)
5434  write_stderr("Run initdb or pg_basebackup to initialize a PostgreSQL data directory.\n");
5435  return false;
5436  }
5437 
5438  /*
5439  * Find the configuration file: if config_file was specified on the
5440  * command line, use it, else use configdir/postgresql.conf. In any case
5441  * ensure the result is an absolute path, so that it will be interpreted
5442  * the same way by future backends.
5443  */
5444  if (ConfigFileName)
5446  else if (configdir)
5447  {
5448  fname = guc_malloc(FATAL,
5449  strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
5450  sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
5451  }
5452  else
5453  {
5454  write_stderr("%s does not know where to find the server configuration file.\n"
5455  "You must specify the --config-file or -D invocation "
5456  "option or set the PGDATA environment variable.\n",
5457  progname);
5458  return false;
5459  }
5460 
5461  /*
5462  * Set the ConfigFileName GUC variable to its final value, ensuring that
5463  * it can't be overridden later.
5464  */
5465  SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
5466  free(fname);
5467 
5468  /*
5469  * Now read the config file for the first time.
5470  */
5471  if (stat(ConfigFileName, &stat_buf) != 0)
5472  {
5473  write_stderr("%s: could not access the server configuration file \"%s\": %s\n",
5474  progname, ConfigFileName, strerror(errno));
5475  free(configdir);
5476  return false;
5477  }
5478 
5479  /*
5480  * Read the configuration file for the first time. This time only the
5481  * data_directory parameter is picked up to determine the data directory,
5482  * so that we can read the PG_AUTOCONF_FILENAME file next time.
5483  */
5485 
5486  /*
5487  * If the data_directory GUC variable has been set, use that as DataDir;
5488  * otherwise use configdir if set; else punt.
5489  *
5490  * Note: SetDataDir will copy and absolute-ize its argument, so we don't
5491  * have to.
5492  */
5493  if (data_directory)
5495  else if (configdir)
5496  SetDataDir(configdir);
5497  else
5498  {
5499  write_stderr("%s does not know where to find the database system data.\n"
5500  "This can be specified as \"data_directory\" in \"%s\", "
5501  "or by the -D invocation option, or by the "
5502  "PGDATA environment variable.\n",
5504  return false;
5505  }
5506 
5507  /*
5508  * Reflect the final DataDir value back into the data_directory GUC var.
5509  * (If you are wondering why we don't just make them a single variable,
5510  * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
5511  * child backends specially. XXX is that still true? Given that we now
5512  * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
5513  * DataDir in advance.)
5514  */
5516 
5517  /*
5518  * Now read the config file a second time, allowing any settings in the
5519  * PG_AUTOCONF_FILENAME file to take effect. (This is pretty ugly, but
5520  * since we have to determine the DataDir before we can find the autoconf
5521  * file, the alternatives seem worse.)
5522  */
5524 
5525  /*
5526  * If timezone_abbreviations wasn't set in the configuration file, install
5527  * the default value. We do it this way because we can't safely install a
5528  * "real" value until my_exec_path is set, which may not have happened
5529  * when InitializeGUCOptions runs, so the bootstrap default value cannot
5530  * be the real desired default.
5531  */
5533 
5534  /*
5535  * Figure out where pg_hba.conf is, and make sure the path is absolute.
5536  */
5537  if (HbaFileName)
5539  else if (configdir)
5540  {
5541  fname = guc_malloc(FATAL,
5542  strlen(configdir) + strlen(HBA_FILENAME) + 2);
5543  sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
5544  }
5545  else
5546  {
5547  write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
5548  "This can be specified as \"hba_file\" in \"%s\", "
5549  "or by the -D invocation option, or by the "
5550  "PGDATA environment variable.\n",
5552  return false;
5553  }
5554  SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
5555  free(fname);
5556 
5557  /*
5558  * Likewise for pg_ident.conf.
5559  */
5560  if (IdentFileName)
5562  else if (configdir)
5563  {
5564  fname = guc_malloc(FATAL,
5565  strlen(configdir) + strlen(IDENT_FILENAME) + 2);
5566  sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
5567  }
5568  else
5569  {
5570  write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
5571  "This can be specified as \"ident_file\" in \"%s\", "
5572  "or by the -D invocation option, or by the "
5573  "PGDATA environment variable.\n",
5575  return false;
5576  }
5577  SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
5578  free(fname);
5579 
5580  free(configdir);
5581 
5582  return true;
5583 }
char * make_absolute_path(const char *path)
Definition: path.c:608
void ProcessConfigFile(GucContext context)
void SetDataDir(const char *dir)
Definition: miscinit.c:192
char * ConfigFileName
Definition: guc.c:534
static void pg_timezone_abbrev_initialize(void)
Definition: guc.c:11272
#define CONFIG_FILENAME
Definition: guc.c:104
#define write_stderr(str)
Definition: parallel.c:181
const char * progname
Definition: pg_standby.c:36
char * HbaFileName
Definition: guc.c:535
#define sprintf
Definition: port.h:194
#define HBA_FILENAME
Definition: guc.c:105
struct stat stat_buf
Definition: pg_standby.c:100
#define FATAL
Definition: elog.h:52
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:7563
char * IdentFileName
Definition: guc.c:536
#define stat(a, b)
Definition: win32_port.h:255
#define IDENT_FILENAME
Definition: guc.c:106
#define free(a)
Definition: header.h:65
#define strerror
Definition: port.h:205
static const char * userDoption
Definition: postgres.c:157
char * DataDir
Definition: globals.c:62
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4685
static char * data_directory
Definition: guc.c:579

◆ SerializeGUCState()

void SerializeGUCState ( Size  maxsize,
char *  start_address 
)

Definition at line 10228 of file guc.c.

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

Referenced by InitializeParallelDSM().

10229 {
10230  char *curptr;
10231  Size actual_size;
10232  Size bytes_left;
10233  int i;
10234 
10235  /* Reserve space for saving the actual size of the guc state */
10236  Assert(maxsize > sizeof(actual_size));
10237  curptr = start_address + sizeof(actual_size);
10238  bytes_left = maxsize - sizeof(actual_size);
10239 
10240  for (i = 0; i < num_guc_variables; i++)
10241  serialize_variable(&curptr, &bytes_left, guc_variables[i]);
10242 
10243  /* Store actual size without assuming alignment of start_address. */
10244  actual_size = maxsize - bytes_left - sizeof(actual_size);
10245  memcpy(start_address, &actual_size, sizeof(actual_size));
10246 }
static void serialize_variable(char **destptr, Size *maxbytes, struct config_generic *gconf)
Definition: guc.c:10154
static int num_guc_variables
Definition: guc.c:4644
static struct config_generic ** guc_variables
Definition: guc.c:4641
#define Assert(condition)
Definition: c.h:739
size_t Size
Definition: c.h:467
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 6798 of file guc.c.

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

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

6802 {
6803  struct config_generic *record;
6804  union config_var_val newval_union;
6805  void *newextra = NULL;
6806  bool prohibitValueChange = false;
6807  bool makeDefault;
6808 
6809  if (elevel == 0)
6810  {
6811  if (source == PGC_S_DEFAULT || source == PGC_S_FILE)
6812  {
6813  /*
6814  * To avoid cluttering the log, only the postmaster bleats loudly
6815  * about problems with the config file.
6816  */
6818  }
6819  else if (source == PGC_S_GLOBAL ||
6820  source == PGC_S_DATABASE ||
6821  source == PGC_S_USER ||
6822  source == PGC_S_DATABASE_USER)
6823  elevel = WARNING;
6824  else
6825  elevel = ERROR;
6826  }
6827 
6828  /*
6829  * GUC_ACTION_SAVE changes are acceptable during a parallel operation,
6830  * because the current worker will also pop the change. We're probably
6831  * dealing with a function having a proconfig entry. Only the function's
6832  * body should observe the change, and peer workers do not share in the
6833  * execution of a function call started by this worker.
6834  *
6835  * Other changes might need to affect other workers, so forbid them.
6836  */
6837  if (IsInParallelMode() && changeVal && action != GUC_ACTION_SAVE)
6838  ereport(elevel,
6839  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
6840  errmsg("cannot set parameters during a parallel operation")));
6841 
6842  record = find_option(name, true, elevel);
6843  if (record == NULL)
6844  {
6845  ereport(elevel,
6846  (errcode(ERRCODE_UNDEFINED_OBJECT),
6847  errmsg("unrecognized configuration parameter \"%s\"", name)));
6848  return 0;
6849  }
6850 
6851  /*
6852  * Check if the option can be set at this time. See guc.h for the precise
6853  * rules.
6854  */
6855  switch (record->context)
6856  {
6857  case PGC_INTERNAL:
6858  if (context != PGC_INTERNAL)
6859  {
6860  ereport(elevel,
6861  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6862  errmsg("parameter \"%s\" cannot be changed",
6863  name)));
6864  return 0;
6865  }
6866  break;
6867  case PGC_POSTMASTER:
6868  if (context == PGC_SIGHUP)
6869  {
6870  /*
6871  * We are re-reading a PGC_POSTMASTER variable from
6872  * postgresql.conf. We can't change the setting, so we should
6873  * give a warning if the DBA tries to change it. However,
6874  * because of variant formats, canonicalization by check
6875  * hooks, etc, we can't just compare the given string directly
6876  * to what's stored. Set a flag to check below after we have
6877  * the final storable value.
6878  */
6879  prohibitValueChange = true;
6880  }
6881  else if (context != PGC_POSTMASTER)
6882  {
6883  ereport(elevel,
6884  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6885  errmsg("parameter \"%s\" cannot be changed without restarting the server",
6886  name)));
6887  return 0;
6888  }
6889  break;
6890  case PGC_SIGHUP:
6891  if (context != PGC_SIGHUP && context != PGC_POSTMASTER)
6892  {
6893  ereport(elevel,
6894  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6895  errmsg("parameter \"%s\" cannot be changed now",
6896  name)));
6897  return 0;
6898  }
6899 
6900  /*
6901  * Hmm, the idea of the SIGHUP context is "ought to be global, but
6902  * can be changed after postmaster start". But there's nothing
6903  * that prevents a crafty administrator from sending SIGHUP
6904  * signals to individual backends only.
6905  */
6906  break;
6907  case PGC_SU_BACKEND:
6908  /* Reject if we're connecting but user is not superuser */
6909  if (context == PGC_BACKEND)
6910  {
6911  ereport(elevel,
6912  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6913  errmsg("permission denied to set parameter \"%s\"",
6914  name)));
6915  return 0;
6916  }
6917  /* fall through to process the same as PGC_BACKEND */
6918  /* FALLTHROUGH */
6919  case PGC_BACKEND:
6920  if (context == PGC_SIGHUP)
6921  {
6922  /*
6923  * If a PGC_BACKEND or PGC_SU_BACKEND parameter is changed in
6924  * the config file, we want to accept the new value in the
6925  * postmaster (whence it will propagate to
6926  * subsequently-started backends), but ignore it in existing
6927  * backends. This is a tad klugy, but necessary because we
6928  * don't re-read the config file during backend start.
6929  *
6930  * In EXEC_BACKEND builds, this works differently: we load all
6931  * non-default settings from the CONFIG_EXEC_PARAMS file
6932  * during backend start. In that case we must accept
6933  * PGC_SIGHUP settings, so as to have the same value as if
6934  * we'd forked from the postmaster. This can also happen when
6935  * using RestoreGUCState() within a background worker that
6936  * needs to have the same settings as the user backend that
6937  * started it. is_reload will be true when either situation
6938  * applies.
6939  */
6940  if (IsUnderPostmaster && !is_reload)
6941  return -1;
6942  }
6943  else if (context != PGC_POSTMASTER &&
6944  context != PGC_BACKEND &&
6945  context != PGC_SU_BACKEND &&
6946  source != PGC_S_CLIENT)
6947  {
6948  ereport(elevel,
6949  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6950  errmsg("parameter \"%s\" cannot be set after connection start",
6951  name)));
6952  return 0;
6953  }
6954  break;
6955  case PGC_SUSET:
6956  if (context == PGC_USERSET || context == PGC_BACKEND)
6957  {
6958  ereport(elevel,
6959  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6960  errmsg("permission denied to set parameter \"%s\"",
6961  name)));
6962  return 0;
6963  }
6964  break;
6965  case PGC_USERSET:
6966  /* always okay */
6967  break;
6968  }
6969 
6970  /*
6971  * Disallow changing GUC_NOT_WHILE_SEC_REST values if we are inside a
6972  * security restriction context. We can reject this regardless of the GUC
6973  * context or source, mainly because sources that it might be reasonable
6974  * to override for won't be seen while inside a function.
6975  *
6976  * Note: variables marked GUC_NOT_WHILE_SEC_REST should usually be marked
6977  * GUC_NO_RESET_ALL as well, because ResetAllOptions() doesn't check this.
6978  * An exception might be made if the reset value is assumed to be "safe".
6979  *
6980  * Note: this flag is currently used for "session_authorization" and
6981  * "role". We need to prohibit changing these inside a local userid
6982  * context because when we exit it, GUC won't be notified, leaving things
6983  * out of sync. (This could be fixed by forcing a new GUC nesting level,
6984  * but that would change behavior in possibly-undesirable ways.) Also, we
6985  * prohibit changing these in a security-restricted operation because
6986  * otherwise RESET could be used to regain the session user's privileges.
6987  */
6988  if (record->flags & GUC_NOT_WHILE_SEC_REST)
6989  {
6990  if (InLocalUserIdChange())
6991  {
6992  /*
6993  * Phrasing of this error message is historical, but it's the most
6994  * common case.
6995  */
6996  ereport(elevel,
6997  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6998  errmsg("cannot set parameter \"%s\" within security-definer function",
6999  name)));
7000  return 0;
7001  }
7003  {
7004  ereport(elevel,
7005  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7006  errmsg("cannot set parameter \"%s\" within security-restricted operation",
7007  name)));
7008  return 0;
7009  }
7010  }
7011 
7012  /*
7013  * Should we set reset/stacked values? (If so, the behavior is not
7014  * transactional.) This is done either when we get a default value from
7015  * the database's/user's/client's default settings or when we reset a
7016  * value to its default.
7017  */
7018  makeDefault = changeVal && (source <= PGC_S_OVERRIDE) &&
7019  ((value != NULL) || source == PGC_S_DEFAULT);
7020 
7021  /*
7022  * Ignore attempted set if overridden by previously processed setting.
7023  * However, if changeVal is false then plow ahead anyway since we are
7024  * trying to find out if the value is potentially good, not actually use
7025  * it. Also keep going if makeDefault is true, since we may want to set
7026  * the reset/stacked values even if we can't set the variable itself.
7027  */
7028  if (record->source > source)
7029  {
7030  if (changeVal && !makeDefault)
7031  {
7032  elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
7033  name);
7034  return -1;
7035  }
7036  changeVal = false;
7037  }
7038 
7039  /*
7040  * Evaluate value and set variable.
7041  */
7042  switch (record->vartype)
7043  {
7044  case PGC_BOOL:
7045  {
7046  struct config_bool *conf = (struct config_bool *) record;
7047 
7048 #define newval (newval_union.boolval)
7049 
7050  if (value)
7051  {
7052  if (!parse_and_validate_value(record, name, value,
7053  source, elevel,
7054  &newval_union, &newextra))
7055  return 0;
7056  }
7057  else if (source == PGC_S_DEFAULT)
7058  {
7059  newval = conf->boot_val;
7060  if (!call_bool_check_hook(conf, &newval, &newextra,
7061  source, elevel))
7062  return 0;
7063  }
7064  else
7065  {
7066  newval = conf->reset_val;
7067  newextra = conf->reset_extra;
7068  source = conf->gen.reset_source;
7069  context = conf->gen.reset_scontext;
7070  }
7071 
7072  if (prohibitValueChange)
7073  {
7074  if (*conf->variable != newval)
7075  {
7076  record->status |= GUC_PENDING_RESTART;
7077  ereport(elevel,
7078  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
7079  errmsg("parameter \"%s\" cannot be changed without restarting the server",
7080  name)));
7081  return 0;
7082  }
7083  record->status &= ~GUC_PENDING_RESTART;
7084  return -1;
7085  }
7086 
7087  if (changeVal)
7088  {
7089  /* Save old value to support transaction abort */
7090  if (!makeDefault)
7091  push_old_value(&conf->gen, action);
7092 
7093  if (conf->assign_hook)
7094  conf->assign_hook(newval, newextra);
7095  *conf->variable = newval;
7096  set_extra_field(&conf->gen, &conf->gen.extra,
7097  newextra);
7098  conf->gen.source = source;
7099  conf->gen.scontext = context;
7100  }
7101  if (makeDefault)
7102  {
7103  GucStack *stack;
7104 
7105  if (conf->gen.reset_source <= source)
7106  {
7107  conf->reset_val = newval;
7108  set_extra_field(&conf->gen, &conf->reset_extra,
7109  newextra);
7110  conf->gen.reset_source = source;
7111  conf->gen.reset_scontext = context;
7112  }
7113  for (stack = conf->gen.stack; stack; stack = stack->prev)
7114  {
7115  if (stack->source <= source)
7116  {
7117  stack->prior.val.boolval = newval;
7118  set_extra_field(&conf->gen, &stack->prior.extra,
7119  newextra);
7120  stack->source = source;
7121  stack->scontext = context;
7122  }
7123  }
7124  }
7125 
7126  /* Perhaps we didn't install newextra anywhere */
7127  if (newextra && !extra_field_used(&conf->gen, newextra))
7128  free(newextra);
7129  break;
7130 
7131 #undef newval
7132  }
7133 
7134  case PGC_INT:
7135  {
7136  struct config_int *conf = (struct config_int *) record;
7137 
7138 #define newval (newval_union.intval)
7139 
7140  if (value)
7141  {
7142  if (!parse_and_validate_value(record, name, value,
7143  source, elevel,
7144  &newval_union, &newextra))
7145  return 0;
7146  }
7147  else if (source == PGC_S_DEFAULT)
7148  {
7149  newval = conf->boot_val;
7150  if (!call_int_check_hook(conf, &newval, &newextra,
7151  source, elevel))
7152  return 0;
7153  }
7154  else
7155  {
7156  newval = conf->reset_val;
7157  newextra = conf->reset_extra;
7158  source = conf->gen.reset_source;
7159  context = conf->gen.reset_scontext;
7160  }
7161 
7162  if (prohibitValueChange)
7163  {
7164  if (*conf->variable != newval)
7165  {
7166  record->status |= GUC_PENDING_RESTART;
7167  ereport(elevel,
7168  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
7169  errmsg("parameter \"%s\" cannot be changed without restarting the server",
7170  name)));
7171  return 0;
7172  }
7173  record->status &= ~GUC_PENDING_RESTART;
7174  return -1;
7175  }
7176 
7177  if (changeVal)
7178  {
7179  /* Save old value to support transaction abort */
7180  if (!makeDefault)
7181  push_old_value(&conf->gen, action);
7182 
7183  if (conf->assign_hook)
7184  conf->assign_hook(newval, newextra);
7185  *conf->variable = newval;
7186  set_extra_field(&conf->gen, &conf->gen.extra,
7187  newextra);
7188  conf->gen.source = source;
7189  conf->gen.scontext = context;
7190  }
7191  if (makeDefault)
7192  {
7193  GucStack *stack;
7194 
7195  if (conf->gen.reset_source <= source)
7196  {
7197  conf->reset_val = newval;
7198  set_extra_field(&conf->gen, &conf->reset_extra,
7199  newextra);
7200  conf->gen.reset_source = source;
7201  conf->gen.reset_scontext = context;
7202  }
7203  for (stack = conf->gen.stack; stack; stack = stack->prev)
7204  {
7205  if (stack->source <= source)
7206  {
7207  stack->prior.val.intval = newval;
7208  set_extra_field(&conf->gen, &stack->prior.extra,
7209  newextra);
7210  stack->source = source;
7211  stack->scontext = context;
7212  }
7213  }
7214  }
7215 
7216  /* Perhaps we didn't install newextra anywhere */
7217  if (newextra && !extra_field_used(&conf->gen, newextra))
7218  free(newextra);
7219  break;
7220 
7221 #undef newval
7222  }
7223 
7224  case PGC_REAL:
7225  {
7226  struct config_real *conf = (struct config_real *) record;
7227 
7228 #define newval (newval_union.realval)
7229 
7230  if (value)
7231  {
7232  if (!parse_and_validate_value(record, name, value,
7233  source, elevel,
7234  &newval_union, &newextra))
7235  return 0;
7236  }
7237  else if (source == PGC_S_DEFAULT)
7238  {
7239  newval = conf->boot_val;
7240  if (!call_real_check_hook(conf, &newval, &newextra,
7241  source, elevel))
7242  return 0;
7243  }
7244  else
7245  {
7246  newval = conf->reset_val;
7247  newextra = conf->reset_extra;
7248  source = conf->gen.reset_source;
7249  context = conf->gen.reset_scontext;
7250  }
7251 
7252  if (prohibitValueChange)
7253  {
7254  if (*conf->variable != newval)
7255  {
7256  record->status |= GUC_PENDING_RESTART;
7257  ereport(elevel,
7258  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
7259  errmsg("parameter \"%s\" cannot be changed without restarting the server",
7260  name)));
7261  return 0;
7262  }
7263  record->status &= ~GUC_PENDING_RESTART;
7264  return -1;
7265  }
7266 
7267  if (changeVal)
7268  {
7269  /* Save old value to support transaction abort */
7270  if (!makeDefault)
7271  push_old_value(&conf->gen, action);
7272 
7273  if (conf->assign_hook)
7274  conf->assign_hook(newval, newextra);
7275  *conf->variable = newval;
7276  set_extra_field(&conf->gen, &conf->gen.extra,
7277  newextra);
7278  conf->gen.source = source;
7279  conf->gen.scontext = context;
7280  }
7281  if (makeDefault)
7282  {
7283  GucStack *stack;
7284 
7285  if (conf->gen.reset_source <= source)
7286  {
7287  conf->reset_val = newval;
7288  set_extra_field(&conf->gen, &conf->reset_extra,
7289  newextra);
7290  conf->gen.reset_source = source;
7291  conf->gen.reset_scontext = context;
7292  }
7293  for (stack = conf->gen.stack; stack; stack = stack->prev)
7294  {
7295  if (stack->source <= source)
7296  {
7297  stack->prior.val.realval = newval;
7298  set_extra_field(&conf->gen, &stack->prior.extra,
7299  newextra);
7300  stack->source = source;
7301  stack->scontext = context;
7302  }
7303  }
7304  }
7305 
7306  /* Perhaps we didn't install newextra anywhere */
7307  if (newextra && !extra_field_used(&conf->gen, newextra))
7308  free(newextra);
7309  break;
7310 
7311 #undef newval
7312  }
7313 
7314  case PGC_STRING:
7315  {
7316  struct config_string *conf = (struct config_string *) record;
7317 
7318 #define newval (newval_union.stringval)
7319 
7320  if (value)
7321  {
7322  if (!parse_and_validate_value(record, name, value,
7323  source, elevel,
7324  &newval_union, &newextra))
7325  return 0;
7326  }
7327  else if (source == PGC_S_DEFAULT)
7328  {
7329  /* non-NULL boot_val must always get strdup'd */
7330  if (conf->boot_val != NULL)
7331  {
7332  newval = guc_strdup(elevel, conf->boot_val);
7333  if (newval == NULL)
7334  return 0;
7335  }
7336  else
7337  newval = NULL;
7338 
7339  if (!call_string_check_hook(conf, &newval, &newextra,
7340  source, elevel))
7341  {
7342  free(newval);
7343  return 0;
7344  }
7345  }
7346  else
7347  {
7348  /*
7349  * strdup not needed, since reset_val is already under
7350  * guc.c's control
7351  */
7352  newval = conf->reset_val;
7353  newextra = conf->reset_extra;
7354  source = conf->gen.reset_source;
7355  context = conf->gen.reset_scontext;
7356  }
7357 
7358  if (prohibitValueChange)
7359  {
7360  /* newval shouldn't be NULL, so we're a bit sloppy here */
7361  if (*conf->variable == NULL || newval == NULL ||
7362  strcmp(*conf->variable, newval) != 0)
7363  {
7364  record->status |= GUC_PENDING_RESTART;
7365