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_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 7969 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().

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

10090 {
10091  if (sync_method != new_sync_method)
10092  {
10093  /*
10094  * To ensure that no blocks escape unsynced, force an fsync on the
10095  * currently open log segment (if any). Also, if the open flag is
10096  * changing, close the log file so it will be reopened (with new flag
10097  * bit) at next use.
10098  */
10099  if (openLogFile >= 0)
10100  {
10102  if (pg_fsync(openLogFile) != 0)
10103  {
10104  char xlogfname[MAXFNAMELEN];
10105  int save_errno;
10106 
10107  save_errno = errno;
10110  errno = save_errno;
10111  ereport(PANIC,
10113  errmsg("could not fsync file \"%s\": %m", xlogfname)));
10114  }
10115 
10117  if (get_sync_bit(sync_method) != get_sync_bit(new_sync_method))
10118  XLogFileClose();
10119  }
10120  }
10121 }
int wal_segment_size
Definition: xlog.c:112
static int get_sync_bit(int method)
Definition: xlog.c:10033
#define PANIC
Definition: elog.h:53
static XLogSegNo openLogSegNo
Definition: xlog.c:780
static void XLogFileClose(void)
Definition: xlog.c:3786
int errcode_for_file_access(void)
Definition: elog.c:631
static void pgstat_report_wait_end(void)
Definition: pgstat.h:1342
#define ereport(elevel, rest)
Definition: elog.h:141
#define MAXFNAMELEN
static int openLogFile
Definition: xlog.c:779
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:1318
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 5792 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().

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

References elog, and WARNING.

Referenced by StartTransaction().

5759 {
5760  /*
5761  * The nest level should be 0 between transactions; if it isn't, somebody
5762  * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
5763  * throw a warning but make no other effort to clean up.
5764  */
5765  if (GUCNestLevel != 0)
5766  elog(WARNING, "GUC nest level = %d at transaction start",
5767  GUCNestLevel);
5768  GUCNestLevel = 1;
5769 }
static int GUCNestLevel
Definition: guc.c:4644
#define WARNING
Definition: elog.h:40
#define elog(elevel,...)
Definition: elog.h:228

◆ BeginReportingGUCOptions()

void BeginReportingGUCOptions ( void  )

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

6075 {
6076  int i;
6077 
6078  /*
6079  * Don't do anything unless talking to an interactive frontend of protocol
6080  * 3.0 or later.
6081  */
6082  if (whereToSendOutput != DestRemote ||
6084  return;
6085 
6086  reporting_enabled = true;
6087 
6088  /* Transmit initial values of interesting variables */
6089  for (i = 0; i < num_guc_variables; i++)
6090  {
6091  struct config_generic *conf = guc_variables[i];
6092 
6093  if (conf->flags & GUC_REPORT)
6094  ReportGUCOption(conf);
6095  }
6096 }
#define PG_PROTOCOL_MAJOR(v)
Definition: pqcomm.h:104
static int num_guc_variables
Definition: guc.c:4631
#define GUC_REPORT
Definition: guc.h:208
static struct config_generic ** guc_variables
Definition: guc.c:4628
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:6102
CommandDest whereToSendOutput
Definition: postgres.c:90
static bool reporting_enabled
Definition: guc.c:4642
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 4875 of file xlog.c.

References XLOGbuffers, and XLOGChooseNumBuffers().

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

8646 {
8647  struct config_bool *var;
8648 
8649  var = (struct config_bool *)
8650  init_custom_variable(name, short_desc, long_desc, context, flags,
8651  PGC_BOOL, sizeof(struct config_bool));
8652  var->variable = valueAddr;
8653  var->boot_val = bootValue;
8654  var->reset_val = bootValue;
8655  var->check_hook = check_hook;
8656  var->assign_hook = assign_hook;
8657  var->show_hook = show_hook;
8658  define_custom_variable(&var->gen);
8659 }
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:8395
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:8455

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

8758 {
8759  struct config_enum *var;
8760 
8761  var = (struct config_enum *)
8762  init_custom_variable(name, short_desc, long_desc, context, flags,
8763  PGC_ENUM, sizeof(struct config_enum));
8764  var->variable = valueAddr;
8765  var->boot_val = bootValue;
8766  var->reset_val = bootValue;
8767  var->options = options;
8768  var->check_hook = check_hook;
8769  var->assign_hook = assign_hook;
8770  var->show_hook = show_hook;
8771  define_custom_variable(&var->gen);
8772 }
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:8395
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:8455

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

8674 {
8675  struct config_int *var;
8676 
8677  var = (struct config_int *)
8678  init_custom_variable(name, short_desc, long_desc, context, flags,
8679  PGC_INT, sizeof(struct config_int));
8680  var->variable = valueAddr;
8681  var->boot_val = bootValue;
8682  var->reset_val = bootValue;
8683  var->min = minValue;
8684  var->max = maxValue;
8685  var->check_hook = check_hook;
8686  var->assign_hook = assign_hook;
8687  var->show_hook = show_hook;
8688  define_custom_variable(&var->gen);
8689 }
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:8395
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8455
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 8692 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().

8704 {
8705  struct config_real *var;
8706 
8707  var = (struct config_real *)
8708  init_custom_variable(name, short_desc, long_desc, context, flags,
8709  PGC_REAL, sizeof(struct config_real));
8710  var->variable = valueAddr;
8711  var->boot_val = bootValue;
8712  var->reset_val = bootValue;
8713  var->min = minValue;
8714  var->max = maxValue;
8715  var->check_hook = check_hook;
8716  var->assign_hook = assign_hook;
8717  var->show_hook = show_hook;
8718  define_custom_variable(&var->gen);
8719 }
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:8395
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:8455
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 8722 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().

8732 {
8733  struct config_string *var;
8734 
8735  var = (struct config_string *)
8736  init_custom_variable(name, short_desc, long_desc, context, flags,
8737  PGC_STRING, sizeof(struct config_string));
8738  var->variable = valueAddr;
8739  var->boot_val = bootValue;
8740  var->check_hook = check_hook;
8741  var->assign_hook = assign_hook;
8742  var->show_hook = show_hook;
8743  define_custom_variable(&var->gen);
8744 }
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:8395
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:8455

◆ EmitWarningsOnPlaceholders()

void EmitWarningsOnPlaceholders ( const char *  className)

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

8776 {
8777  int classLen = strlen(className);
8778  int i;
8779 
8780  for (i = 0; i < num_guc_variables; i++)
8781  {
8782  struct config_generic *var = guc_variables[i];
8783 
8784  if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
8785  strncmp(className, var->name, classLen) == 0 &&
8786  var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
8787  {
8788  ereport(WARNING,
8789  (errcode(ERRCODE_UNDEFINED_OBJECT),
8790  errmsg("unrecognized configuration parameter \"%s\"",
8791  var->name)));
8792  }
8793  }
8794 }
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:4631
#define ereport(elevel, rest)
Definition: elog.h:141
static struct config_generic ** guc_variables
Definition: guc.c:4628
#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 10074 of file guc.c.

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

Referenced by InitializeParallelDSM().

10075 {
10076  Size size;
10077  int i;
10078 
10079  /* Add space reqd for saving the data size of the guc state */
10080  size = sizeof(Size);
10081 
10082  /* Add up the space needed for each GUC variable */
10083  for (i = 0; i < num_guc_variables; i++)
10084  size = add_size(size,
10086 
10087  return size;
10088 }
static int num_guc_variables
Definition: guc.c:4631
static struct config_generic ** guc_variables
Definition: guc.c:4628
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
size_t Size
Definition: c.h:467
static Size estimate_variable_size(struct config_generic *gconf)
Definition: guc.c:9976
int i

◆ ExecSetVariableStmt()

void ExecSetVariableStmt ( VariableSetStmt stmt,
bool  isTopLevel 
)

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

8184 {
8186 
8187  /*
8188  * Workers synchronize these parameters at the start of the parallel
8189  * operation; then, we block SET during the operation.
8190  */
8191  if (IsInParallelMode())
8192  ereport(ERROR,
8193  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
8194  errmsg("cannot set parameters during a parallel operation")));
8195 
8196  switch (stmt->kind)
8197  {
8198  case VAR_SET_VALUE:
8199  case VAR_SET_CURRENT:
8200  if (stmt->is_local)
8201  WarnNoTransactionBlock(isTopLevel, "SET LOCAL");
8202  (void) set_config_option(stmt->name,
8203  ExtractSetVariableArgs(stmt),
8205  PGC_S_SESSION,
8206  action, true, 0, false);
8207  break;
8208  case VAR_SET_MULTI:
8209 
8210  /*
8211  * Special-case SQL syntaxes. The TRANSACTION and SESSION
8212  * CHARACTERISTICS cases effectively set more than one variable
8213  * per statement. TRANSACTION SNAPSHOT only takes one argument,
8214  * but we put it here anyway since it's a special case and not
8215  * related to any GUC variable.
8216  */
8217  if (strcmp(stmt->name, "TRANSACTION") == 0)
8218  {
8219  ListCell *head;
8220 
8221  WarnNoTransactionBlock(isTopLevel, "SET TRANSACTION");
8222 
8223  foreach(head, stmt->args)
8224  {
8225  DefElem *item = (DefElem *) lfirst(head);
8226 
8227  if (strcmp(item->defname, "transaction_isolation") == 0)
8228  SetPGVariable("transaction_isolation",
8229  list_make1(item->arg), stmt->is_local);
8230  else if (strcmp(item->defname, "transaction_read_only") == 0)
8231  SetPGVariable("transaction_read_only",
8232  list_make1(item->arg), stmt->is_local);
8233  else if (strcmp(item->defname, "transaction_deferrable") == 0)
8234  SetPGVariable("transaction_deferrable",
8235  list_make1(item->arg), stmt->is_local);
8236  else
8237  elog(ERROR, "unexpected SET TRANSACTION element: %s",
8238  item->defname);
8239  }
8240  }
8241  else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
8242  {
8243  ListCell *head;
8244 
8245  foreach(head, stmt->args)
8246  {
8247  DefElem *item = (DefElem *) lfirst(head);
8248 
8249  if (strcmp(item->defname, "transaction_isolation") == 0)
8250  SetPGVariable("default_transaction_isolation",
8251  list_make1(item->arg), stmt->is_local);
8252  else if (strcmp(item->defname, "transaction_read_only") == 0)
8253  SetPGVariable("default_transaction_read_only",
8254  list_make1(item->arg), stmt->is_local);
8255  else if (strcmp(item->defname, "transaction_deferrable") == 0)
8256  SetPGVariable("default_transaction_deferrable",
8257  list_make1(item->arg), stmt->is_local);
8258  else
8259  elog(ERROR, "unexpected SET SESSION element: %s",
8260  item->defname);
8261  }
8262  }
8263  else if (strcmp(stmt->name, "TRANSACTION SNAPSHOT") == 0)
8264  {
8265  A_Const *con = linitial_node(A_Const, stmt->args);
8266 
8267  if (stmt->is_local)
8268  ereport(ERROR,
8269  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8270  errmsg("SET LOCAL TRANSACTION SNAPSHOT is not implemented")));
8271 
8272  WarnNoTransactionBlock(isTopLevel, "SET TRANSACTION");
8273  Assert(nodeTag(&con->val) == T_String);
8274  ImportSnapshot(strVal(&con->val));
8275  }
8276  else
8277  elog(ERROR, "unexpected SET MULTI element: %s",
8278  stmt->name);
8279  break;
8280  case VAR_SET_DEFAULT:
8281  if (stmt->is_local)
8282  WarnNoTransactionBlock(isTopLevel, "SET LOCAL");
8283  /* fall through */
8284  case VAR_RESET:
8285  if (strcmp(stmt->name, "transaction_isolation") == 0)
8286  WarnNoTransactionBlock(isTopLevel, "RESET TRANSACTION");
8287 
8288  (void) set_config_option(stmt->name,
8289  NULL,
8291  PGC_S_SESSION,
8292  action, true, 0, false);
8293  break;
8294  case VAR_RESET_ALL:
8295  ResetAllOptions();
8296  break;
8297  }
8298 }
void ImportSnapshot(const char *idstr)
Definition: snapmgr.c:1462
VariableSetKind kind
Definition: parsenodes.h:2019
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:5577
#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:8307
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:6785
void SetPGVariable(const char *name, List *args, bool is_local)
Definition: guc.c:8327

◆ ExtractSetVariableArgs()

char* ExtractSetVariableArgs ( VariableSetStmt stmt)

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

8308 {
8309  switch (stmt->kind)
8310  {
8311  case VAR_SET_VALUE:
8312  return flatten_set_variable_args(stmt->name, stmt->args);
8313  case VAR_SET_CURRENT:
8314  return GetConfigOptionByName(stmt->name, NULL, false);
8315  default:
8316  return NULL;
8317  }
8318 }
VariableSetKind kind
Definition: parsenodes.h:2019
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:9040
static char * flatten_set_variable_args(const char *name, List *args)
Definition: guc.c:7709

◆ FreeConfigVariables()

void FreeConfigVariables ( ConfigVariable list)

◆ GetConfigOption()

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

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

7575 {
7576  struct config_generic *record;
7577  static char buffer[256];
7578 
7579  record = find_option(name, false, ERROR);
7580  if (record == NULL)
7581  {
7582  if (missing_ok)
7583  return NULL;
7584  ereport(ERROR,
7585  (errcode(ERRCODE_UNDEFINED_OBJECT),
7586  errmsg("unrecognized configuration parameter \"%s\"",
7587  name)));
7588  }
7589  if (restrict_privileged &&
7590  (record->flags & GUC_SUPERUSER_ONLY) &&
7591  !is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
7592  ereport(ERROR,
7593  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7594  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
7595  name)));
7596 
7597  switch (record->vartype)
7598  {
7599  case PGC_BOOL:
7600  return *((struct config_bool *) record)->variable ? "on" : "off";
7601 
7602  case PGC_INT:
7603  snprintf(buffer, sizeof(buffer), "%d",
7604  *((struct config_int *) record)->variable);
7605  return buffer;
7606 
7607  case PGC_REAL:
7608  snprintf(buffer, sizeof(buffer), "%g",
7609  *((struct config_real *) record)->variable);
7610  return buffer;
7611 
7612  case PGC_STRING:
7613  return *((struct config_string *) record)->variable;
7614 
7615  case PGC_ENUM:
7616  return config_enum_lookup_by_value((struct config_enum *) record,
7617  *((struct config_enum *) record)->variable);
7618  }
7619  return NULL;
7620 }
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:6481
#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:5085
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 9040 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().

9041 {
9042  struct config_generic *record;
9043 
9044  record = find_option(name, false, ERROR);
9045  if (record == NULL)
9046  {
9047  if (missing_ok)
9048  {
9049  if (varname)
9050  *varname = NULL;
9051  return NULL;
9052  }
9053 
9054  ereport(ERROR,
9055  (errcode(ERRCODE_UNDEFINED_OBJECT),
9056  errmsg("unrecognized configuration parameter \"%s\"", name)));
9057  }
9058 
9059  if ((record->flags & GUC_SUPERUSER_ONLY) &&
9060  !is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
9061  ereport(ERROR,
9062  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
9063  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
9064  name)));
9065 
9066  if (varname)
9067  *varname = record->name;
9068 
9069  return _ShowOption(record, true);
9070 }
static char * _ShowOption(struct config_generic *record, bool use_units)
Definition: guc.c:9601
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:5085
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 9077 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().

9078 {
9079  char buffer[256];
9080  struct config_generic *conf;
9081 
9082  /* check requested variable number valid */
9083  Assert((varnum >= 0) && (varnum < num_guc_variables));
9084 
9085  conf = guc_variables[varnum];
9086 
9087  if (noshow)
9088  {
9089  if ((conf->flags & GUC_NO_SHOW_ALL) ||
9090  ((conf->flags & GUC_SUPERUSER_ONLY) &&
9091  !is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS)))
9092  *noshow = true;
9093  else
9094  *noshow = false;
9095  }
9096 
9097  /* first get the generic attributes */
9098 
9099  /* name */
9100  values[0] = conf->name;
9101 
9102  /* setting: use _ShowOption in order to avoid duplicating the logic */
9103  values[1] = _ShowOption(conf, false);
9104 
9105  /* unit, if any (NULL is fine) */
9106  values[2] = get_config_unit_name(conf->flags);
9107 
9108  /* group */
9109  values[3] = _(config_group_names[conf->group]);
9110 
9111  /* short_desc */
9112  values[4] = _(conf->short_desc);
9113 
9114  /* extra_desc */
9115  values[5] = _(conf->long_desc);
9116 
9117  /* context */
9118  values[6] = GucContext_Names[conf->context];
9119 
9120  /* vartype */
9121  values[7] = config_type_names[conf->vartype];
9122 
9123  /* source */
9124  values[8] = GucSource_Names[conf->source];
9125 
9126  /* now get the type specific attributes */
9127  switch (conf->vartype)
9128  {
9129  case PGC_BOOL:
9130  {
9131  struct config_bool *lconf = (struct config_bool *) conf;
9132 
9133  /* min_val */
9134  values[9] = NULL;
9135 
9136  /* max_val */
9137  values[10] = NULL;
9138 
9139  /* enumvals */
9140  values[11] = NULL;
9141 
9142  /* boot_val */
9143  values[12] = pstrdup(lconf->boot_val ? "on" : "off");
9144 
9145  /* reset_val */
9146  values[13] = pstrdup(lconf->reset_val ? "on" : "off");
9147  }
9148  break;
9149 
9150  case PGC_INT:
9151  {
9152  struct config_int *lconf = (struct config_int *) conf;
9153 
9154  /* min_val */
9155  snprintf(buffer, sizeof(buffer), "%d", lconf->min);
9156  values[9] = pstrdup(buffer);
9157 
9158  /* max_val */
9159  snprintf(buffer, sizeof(buffer), "%d", lconf->max);
9160  values[10] = pstrdup(buffer);
9161 
9162  /* enumvals */
9163  values[11] = NULL;
9164 
9165  /* boot_val */
9166  snprintf(buffer, sizeof(buffer), "%d", lconf->boot_val);
9167  values[12] = pstrdup(buffer);
9168 
9169  /* reset_val */
9170  snprintf(buffer, sizeof(buffer), "%d", lconf->reset_val);
9171  values[13] = pstrdup(buffer);
9172  }
9173  break;
9174 
9175  case PGC_REAL:
9176  {
9177  struct config_real *lconf = (struct config_real *) conf;
9178 
9179  /* min_val */
9180  snprintf(buffer, sizeof(buffer), "%g", lconf->min);
9181  values[9] = pstrdup(buffer);
9182 
9183  /* max_val */
9184  snprintf(buffer, sizeof(buffer), "%g", lconf->max);
9185  values[10] = pstrdup(buffer);
9186 
9187  /* enumvals */
9188  values[11] = NULL;
9189 
9190  /* boot_val */
9191  snprintf(buffer, sizeof(buffer), "%g", lconf->boot_val);
9192  values[12] = pstrdup(buffer);
9193 
9194  /* reset_val */
9195  snprintf(buffer, sizeof(buffer), "%g", lconf->reset_val);
9196  values[13] = pstrdup(buffer);
9197  }
9198  break;
9199 
9200  case PGC_STRING:
9201  {
9202  struct config_string *lconf = (struct config_string *) conf;
9203 
9204  /* min_val */
9205  values[9] = NULL;
9206 
9207  /* max_val */
9208  values[10] = NULL;
9209 
9210  /* enumvals */
9211  values[11] = NULL;
9212 
9213  /* boot_val */
9214  if (lconf->boot_val == NULL)
9215  values[12] = NULL;
9216  else
9217  values[12] = pstrdup(lconf->boot_val);
9218 
9219  /* reset_val */
9220  if (lconf->reset_val == NULL)
9221  values[13] = NULL;
9222  else
9223  values[13] = pstrdup(lconf->reset_val);
9224  }
9225  break;
9226 
9227  case PGC_ENUM:
9228  {
9229  struct config_enum *lconf = (struct config_enum *) conf;
9230 
9231  /* min_val */
9232  values[9] = NULL;
9233 
9234  /* max_val */
9235  values[10] = NULL;
9236 
9237  /* enumvals */
9238 
9239  /*
9240  * NOTE! enumvals with double quotes in them are not
9241  * supported!
9242  */
9243  values[11] = config_enum_get_options((struct config_enum *) conf,
9244  "{\"", "\"}", "\",\"");
9245 
9246  /* boot_val */
9248  lconf->boot_val));
9249 
9250  /* reset_val */
9252  lconf->reset_val));
9253  }
9254  break;
9255 
9256  default:
9257  {
9258  /*
9259  * should never get here, but in case we do, set 'em to NULL
9260  */
9261 
9262  /* min_val */
9263  values[9] = NULL;
9264 
9265  /* max_val */
9266  values[10] = NULL;
9267 
9268  /* enumvals */
9269  values[11] = NULL;
9270 
9271  /* boot_val */
9272  values[12] = NULL;
9273 
9274  /* reset_val */
9275  values[13] = NULL;
9276  }
9277  break;
9278  }
9279 
9280  /*
9281  * If the setting came from a config file, set the source location. For
9282  * security reasons, we don't show source file/line number for
9283  * insufficiently-privileged users.
9284  */
9285  if (conf->source == PGC_S_FILE &&
9286  is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
9287  {
9288  values[14] = conf->sourcefile;
9289  snprintf(buffer, sizeof(buffer), "%d", conf->sourceline);
9290  values[15] = pstrdup(buffer);
9291  }
9292  else
9293  {
9294  values[14] = NULL;
9295  values[15] = NULL;
9296  }
9297 
9298  values[16] = (conf->status & GUC_PENDING_RESTART) ? "t" : "f";
9299 }
GucSource source
Definition: guc_tables.h:158
static char * _ShowOption(struct config_generic *record, bool use_units)
Definition: guc.c:9601
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:752
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:6481
#define GUC_NO_SHOW_ALL
Definition: guc.h:206
const char *const GucContext_Names[]
Definition: guc.c:602
const char *const config_group_names[]
Definition: guc.c:639
static int num_guc_variables
Definition: guc.c:4631
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:6272
static struct config_generic ** guc_variables
Definition: guc.c:4628
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:618
#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:6530
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 7679 of file guc.c.

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

Referenced by pg_get_functiondef().

7680 {
7681  struct config_generic *record;
7682 
7683  record = find_option(name, false, WARNING);
7684  if (record == NULL)
7685  {
7686  if (missing_ok)
7687  return 0;
7688  ereport(ERROR,
7689  (errcode(ERRCODE_UNDEFINED_OBJECT),
7690  errmsg("unrecognized configuration parameter \"%s\"",
7691  name)));
7692  }
7693  return record->flags;
7694 }
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:5085
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 7630 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().

7631 {
7632  struct config_generic *record;
7633  static char buffer[256];
7634 
7635  record = find_option(name, false, ERROR);
7636  if (record == NULL)
7637  ereport(ERROR,
7638  (errcode(ERRCODE_UNDEFINED_OBJECT),
7639  errmsg("unrecognized configuration parameter \"%s\"", name)));
7640  if ((record->flags & GUC_SUPERUSER_ONLY) &&
7641  !is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
7642  ereport(ERROR,
7643  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7644  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
7645  name)));
7646 
7647  switch (record->vartype)
7648  {
7649  case PGC_BOOL:
7650  return ((struct config_bool *) record)->reset_val ? "on" : "off";
7651 
7652  case PGC_INT:
7653  snprintf(buffer, sizeof(buffer), "%d",
7654  ((struct config_int *) record)->reset_val);
7655  return buffer;
7656 
7657  case PGC_REAL:
7658  snprintf(buffer, sizeof(buffer), "%g",
7659  ((struct config_real *) record)->reset_val);
7660  return buffer;
7661 
7662  case PGC_STRING:
7663  return ((struct config_string *) record)->reset_val;
7664 
7665  case PGC_ENUM:
7666  return config_enum_lookup_by_value((struct config_enum *) record,
7667  ((struct config_enum *) record)->reset_val);
7668  }
7669  return NULL;
7670 }
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:6481
#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:5085
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 9305 of file guc.c.

References num_guc_variables.

Referenced by GucInfoMain(), and show_all_settings().

9306 {
9307  return num_guc_variables;
9308 }
static int num_guc_variables
Definition: guc.c:4631

◆ GetPGVariable()

void GetPGVariable ( const char *  name,
DestReceiver dest 
)

Definition at line 8801 of file guc.c.

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

Referenced by exec_replication_command(), and standard_ProcessUtility().

8802 {
8803  if (guc_name_compare(name, "all") == 0)
8804  ShowAllGUCConfig(dest);
8805  else
8806  ShowGUCConfigOption(name, dest);
8807 }
static void ShowGUCConfigOption(const char *name, DestReceiver *dest)
Definition: guc.c:8845
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:5146
static void ShowAllGUCConfig(DestReceiver *dest)
Definition: guc.c:8873
const char * name
Definition: encode.c:521

◆ GetPGVariableResultDesc()

TupleDesc GetPGVariableResultDesc ( const char *  name)

Definition at line 8810 of file guc.c.

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

Referenced by UtilityTupleDescriptor().

8811 {
8812  TupleDesc tupdesc;
8813 
8814  if (guc_name_compare(name, "all") == 0)
8815  {
8816  /* need a tuple descriptor representing three TEXT columns */
8817  tupdesc = CreateTemplateTupleDesc(3);
8818  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
8819  TEXTOID, -1, 0);
8820  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
8821  TEXTOID, -1, 0);
8822  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
8823  TEXTOID, -1, 0);
8824  }
8825  else
8826  {
8827  const char *varname;
8828 
8829  /* Get the canonical spelling of name */
8830  (void) GetConfigOptionByName(name, &varname, false);
8831 
8832  /* need a tuple descriptor representing a single TEXT column */
8833  tupdesc = CreateTemplateTupleDesc(1);
8834  TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
8835  TEXTOID, -1, 0);
8836  }
8837  return tupdesc;
8838 }
TupleDesc CreateTemplateTupleDesc(int natts)
Definition: tupdesc.c:44
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:5146
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:9040
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()

void GUC_check_errcode ( int  sqlerrcode)

◆ GUCArrayAdd()

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

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

10467 {
10468  struct config_generic *record;
10469  Datum datum;
10470  char *newval;
10471  ArrayType *a;
10472 
10473  Assert(name);
10474  Assert(value);
10475 
10476  /* test if the option is valid and we're allowed to set it */
10477  (void) validate_option_array_item(name, value, false);
10478 
10479  /* normalize name (converts obsolete GUC names to modern spellings) */
10480  record = find_option(name, false, WARNING);
10481  if (record)
10482  name = record->name;
10483 
10484  /* build new item for array */
10485  newval = psprintf("%s=%s", name, value);
10486  datum = CStringGetTextDatum(newval);
10487 
10488  if (array)
10489  {
10490  int index;
10491  bool isnull;
10492  int i;
10493 
10494  Assert(ARR_ELEMTYPE(array) == TEXTOID);
10495  Assert(ARR_NDIM(array) == 1);
10496  Assert(ARR_LBOUND(array)[0] == 1);
10497 
10498  index = ARR_DIMS(array)[0] + 1; /* add after end */
10499 
10500  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
10501  {
10502  Datum d;
10503  char *current;
10504 
10505  d = array_ref(array, 1, &i,
10506  -1 /* varlenarray */ ,
10507  -1 /* TEXT's typlen */ ,
10508  false /* TEXT's typbyval */ ,
10509  'i' /* TEXT's typalign */ ,
10510  &isnull);
10511  if (isnull)
10512  continue;
10513  current = TextDatumGetCString(d);
10514 
10515  /* check for match up through and including '=' */
10516  if (strncmp(current, newval, strlen(name) + 1) == 0)
10517  {
10518  index = i;
10519  break;
10520  }
10521  }
10522 
10523  a = array_set(array, 1, &index,
10524  datum,
10525  false,
10526  -1 /* varlena array */ ,
10527  -1 /* TEXT's typlen */ ,
10528  false /* TEXT's typbyval */ ,
10529  'i' /* TEXT's typalign */ );
10530  }
10531  else
10532  a = construct_array(&datum, 1,
10533  TEXTOID,
10534  -1, false, 'i');
10535 
10536  return a;
10537 }
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:10692
#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:5085
#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 10546 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().

10547 {
10548  struct config_generic *record;
10549  ArrayType *newarray;
10550  int i;
10551  int index;
10552 
10553  Assert(name);
10554 
10555  /* test if the option is valid and we're allowed to set it */
10556  (void) validate_option_array_item(name, NULL, false);
10557 
10558  /* normalize name (converts obsolete GUC names to modern spellings) */
10559  record = find_option(name, false, WARNING);
10560  if (record)
10561  name = record->name;
10562 
10563  /* if array is currently null, then surely nothing to delete */
10564  if (!array)
10565  return NULL;
10566 
10567  newarray = NULL;
10568  index = 1;
10569 
10570  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
10571  {
10572  Datum d;
10573  char *val;
10574  bool isnull;
10575 
10576  d = array_ref(array, 1, &i,
10577  -1 /* varlenarray */ ,
10578  -1 /* TEXT's typlen */ ,
10579  false /* TEXT's typbyval */ ,
10580  'i' /* TEXT's typalign */ ,
10581  &isnull);
10582  if (isnull)
10583  continue;
10584  val = TextDatumGetCString(d);
10585 
10586  /* ignore entry if it's what we want to delete */
10587  if (strncmp(val, name, strlen(name)) == 0
10588  && val[strlen(name)] == '=')
10589  continue;
10590 
10591  /* else add it to the output array */
10592  if (newarray)
10593  newarray = array_set(newarray, 1, &index,
10594  d,
10595  false,
10596  -1 /* varlenarray */ ,
10597  -1 /* TEXT's typlen */ ,
10598  false /* TEXT's typbyval */ ,
10599  'i' /* TEXT's typalign */ );
10600  else
10601  newarray = construct_array(&d, 1,
10602  TEXTOID,
10603  -1, false, 'i');
10604 
10605  index++;
10606  }
10607 
10608  return newarray;
10609 }
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:10692
#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:5085
#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 10618 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().

10619 {
10620  ArrayType *newarray;
10621  int i;
10622  int index;
10623 
10624  /* if array is currently null, nothing to do */
10625  if (!array)
10626  return NULL;
10627 
10628  /* if we're superuser, we can delete everything, so just do it */
10629  if (superuser())
10630  return NULL;
10631 
10632  newarray = NULL;
10633  index = 1;
10634 
10635  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
10636  {
10637  Datum d;
10638  char *val;
10639  char *eqsgn;
10640  bool isnull;
10641 
10642  d = array_ref(array, 1, &i,
10643  -1 /* varlenarray */ ,
10644  -1 /* TEXT's typlen */ ,
10645  false /* TEXT's typbyval */ ,
10646  'i' /* TEXT's typalign */ ,
10647  &isnull);
10648  if (isnull)
10649  continue;
10650  val = TextDatumGetCString(d);
10651 
10652  eqsgn = strchr(val, '=');
10653  *eqsgn = '\0';
10654 
10655  /* skip if we have permission to delete it */
10656  if (validate_option_array_item(val, NULL, true))
10657  continue;
10658 
10659  /* else add it to the output array */
10660  if (newarray)
10661  newarray = array_set(newarray, 1, &index,
10662  d,
10663  false,
10664  -1 /* varlenarray */ ,
10665  -1 /* TEXT's typlen */ ,
10666  false /* TEXT's typbyval */ ,
10667  'i' /* TEXT's typalign */ );
10668  else
10669  newarray = construct_array(&d, 1,
10670  TEXTOID,
10671  -1, false, 'i');
10672 
10673  index++;
10674  pfree(val);
10675  }
10676 
10677  return newarray;
10678 }
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:10692
#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 5180 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().

5181 {
5182  int i;
5183 
5184  /*
5185  * Before log_line_prefix could possibly receive a nonempty setting, make
5186  * sure that timezone processing is minimally alive (see elog.c).
5187  */
5189 
5190  /*
5191  * Build sorted array of all GUC variables.
5192  */
5194 
5195  /*
5196  * Load all variables with their compiled-in defaults, and initialize
5197  * status fields as needed.
5198  */
5199  for (i = 0; i < num_guc_variables; i++)
5200  {
5202  }
5203 
5204  guc_dirty = false;
5205 
5206  reporting_enabled = false;
5207 
5208  /*
5209  * Prevent any attempt to override the transaction modes from
5210  * non-interactive sources.
5211  */
5212  SetConfigOption("transaction_isolation", "read committed",
5214  SetConfigOption("transaction_read_only", "no",
5216  SetConfigOption("transaction_deferrable", "no",
5218 
5219  /*
5220  * For historical reasons, some GUC parameters can receive defaults from
5221  * environment variables. Process those settings.
5222  */
5224 }
void build_guc_variables(void)
Definition: guc.c:4895
static void InitializeGUCOptionsFromEnvironment(void)
Definition: guc.c:5236
void pg_timezone_initialize(void)
Definition: pgtz.c:363
static int num_guc_variables
Definition: guc.c:4631
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:7550
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:5282
static struct config_generic ** guc_variables
Definition: guc.c:4628
int i
static bool reporting_enabled
Definition: guc.c:4642
static bool guc_dirty
Definition: guc.c:4640

◆ NewGUCNestLevel()

◆ parse_int()

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

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

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

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

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

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

10371 {
10372  size_t equal_pos;
10373  char *cp;
10374 
10375  AssertArg(string);
10376  AssertArg(name);
10377  AssertArg(value);
10378 
10379  equal_pos = strcspn(string, "=");
10380 
10381  if (string[equal_pos] == '=')
10382  {
10383  *name = guc_malloc(FATAL, equal_pos + 1);
10384  strlcpy(*name, string, equal_pos + 1);
10385 
10386  *value = guc_strdup(FATAL, &string[equal_pos + 1]);
10387  }
10388  else
10389  {
10390  /* no equal sign in string */
10391  *name = guc_strdup(FATAL, string);
10392  *value = NULL;
10393  }
10394 
10395  for (cp = *name; *cp; cp++)
10396  if (*cp == '-')
10397  *cp = '_';
10398 }
static struct @145 value
static char * guc_strdup(int elevel, const char *src)
Definition: guc.c:4704
#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:4672

◆ ProcessConfigFile()

◆ ProcessGUCArray()

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

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

10410 {
10411  int i;
10412 
10413  Assert(array != NULL);
10414  Assert(ARR_ELEMTYPE(array) == TEXTOID);
10415  Assert(ARR_NDIM(array) == 1);
10416  Assert(ARR_LBOUND(array)[0] == 1);
10417 
10418  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
10419  {
10420  Datum d;
10421  bool isnull;
10422  char *s;
10423  char *name;
10424  char *value;
10425 
10426  d = array_ref(array, 1, &i,
10427  -1 /* varlenarray */ ,
10428  -1 /* TEXT's typlen */ ,
10429  false /* TEXT's typbyval */ ,
10430  'i' /* TEXT's typalign */ ,
10431  &isnull);
10432 
10433  if (isnull)
10434  continue;
10435 
10436  s = TextDatumGetCString(d);
10437 
10438  ParseLongOption(s, &name, &value);
10439  if (!value)
10440  {
10441  ereport(WARNING,
10442  (errcode(ERRCODE_SYNTAX_ERROR),
10443  errmsg("could not parse setting for parameter \"%s\"",
10444  name)));
10445  free(name);
10446  continue;
10447  }
10448 
10449  (void) set_config_option(name, value,
10450  context, source,
10451  action, true, 0, false);
10452 
10453  free(name);
10454  if (value)
10455  free(value);
10456  pfree(s);
10457  }
10458 }
GucSource source
Definition: guc_tables.h:158
void ParseLongOption(const char *string, char **name, char **value)
Definition: guc.c:10370
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:6785
#define ARR_ELEMTYPE(a)
Definition: array.h:280
GucContext context
Definition: guc_tables.h:150

◆ ResetAllOptions()

void ResetAllOptions ( void  )

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

5578 {
5579  int i;
5580 
5581  for (i = 0; i < num_guc_variables; i++)
5582  {
5583  struct config_generic *gconf = guc_variables[i];
5584 
5585  /* Don't reset non-SET-able values */
5586  if (gconf->context != PGC_SUSET &&
5587  gconf->context != PGC_USERSET)
5588  continue;
5589  /* Don't reset if special exclusion from RESET ALL */
5590  if (gconf->flags & GUC_NO_RESET_ALL)
5591  continue;
5592  /* No need to reset if wasn't SET */
5593  if (gconf->source <= PGC_S_OVERRIDE)
5594  continue;
5595 
5596  /* Save old value to support transaction abort */
5598 
5599  switch (gconf->vartype)
5600  {
5601  case PGC_BOOL:
5602  {
5603  struct config_bool *conf = (struct config_bool *) gconf;
5604 
5605  if (conf->assign_hook)
5606  conf->assign_hook(conf->reset_val,
5607  conf->reset_extra);
5608  *conf->variable = conf->reset_val;
5609  set_extra_field(&conf->gen, &conf->gen.extra,
5610  conf->reset_extra);
5611  break;
5612  }
5613  case PGC_INT:
5614  {
5615  struct config_int *conf = (struct config_int *) gconf;
5616 
5617  if (conf->assign_hook)
5618  conf->assign_hook(conf->reset_val,
5619  conf->reset_extra);
5620  *conf->variable = conf->reset_val;
5621  set_extra_field(&conf->gen, &conf->gen.extra,
5622  conf->reset_extra);
5623  break;
5624  }
5625  case PGC_REAL:
5626  {
5627  struct config_real *conf = (struct config_real *) gconf;
5628 
5629  if (conf->assign_hook)
5630  conf->assign_hook(conf->reset_val,
5631  conf->reset_extra);
5632  *conf->variable = conf->reset_val;
5633  set_extra_field(&conf->gen, &conf->gen.extra,
5634  conf->reset_extra);
5635  break;
5636  }
5637  case PGC_STRING:
5638  {
5639  struct config_string *conf = (struct config_string *) gconf;
5640 
5641  if (conf->assign_hook)
5642  conf->assign_hook(conf->reset_val,
5643  conf->reset_extra);
5644  set_string_field(conf, conf->variable, conf->reset_val);
5645  set_extra_field(&conf->gen, &conf->gen.extra,
5646  conf->reset_extra);
5647  break;
5648  }
5649  case PGC_ENUM:
5650  {
5651  struct config_enum *conf = (struct config_enum *) gconf;
5652 
5653  if (conf->assign_hook)
5654  conf->assign_hook(conf->reset_val,
5655  conf->reset_extra);
5656  *conf->variable = conf->reset_val;
5657  set_extra_field(&conf->gen, &conf->gen.extra,
5658  conf->reset_extra);
5659  break;
5660  }
5661  }
5662 
5663  gconf->source = gconf->reset_source;
5664  gconf->scontext = gconf->reset_scontext;
5665 
5666  if (gconf->flags & GUC_REPORT)
5667  ReportGUCOption(gconf);
5668  }
5669 }
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:5677
int * variable
Definition: guc_tables.h:198
int * variable
Definition: guc_tables.h:244
static int num_guc_variables
Definition: guc.c:4631
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:4805
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:4744
static struct config_generic ** guc_variables
Definition: guc.c:4628
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:6102
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 10296 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().

10297 {
10298  char *varname,
10299  *varvalue,
10300  *varsourcefile;
10301  int varsourceline;
10302  GucSource varsource;
10303  GucContext varscontext;
10304  char *srcptr = (char *) gucstate;
10305  char *srcend;
10306  Size len;
10307  int i;
10308  ErrorContextCallback error_context_callback;
10309 
10310  /* See comment at can_skip_gucvar(). */
10311  for (i = 0; i < num_guc_variables; i++)
10312  if (!can_skip_gucvar(guc_variables[i]))
10314 
10315  /* First item is the length of the subsequent data */
10316  memcpy(&len, gucstate, sizeof(len));
10317 
10318  srcptr += sizeof(len);
10319  srcend = srcptr + len;
10320 
10321  /* If the GUC value check fails, we want errors to show useful context. */
10322  error_context_callback.callback = guc_restore_error_context_callback;
10323  error_context_callback.previous = error_context_stack;
10324  error_context_callback.arg = NULL;
10325  error_context_stack = &error_context_callback;
10326 
10327  while (srcptr < srcend)
10328  {
10329  int result;
10330  char *error_context_name_and_value[2];
10331 
10332  varname = read_gucstate(&srcptr, srcend);
10333  varvalue = read_gucstate(&srcptr, srcend);
10334  varsourcefile = read_gucstate(&srcptr, srcend);
10335  if (varsourcefile[0])
10336  read_gucstate_binary(&srcptr, srcend,
10337  &varsourceline, sizeof(varsourceline));
10338  else
10339  varsourceline = 0;
10340  read_gucstate_binary(&srcptr, srcend,
10341  &varsource, sizeof(varsource));
10342  read_gucstate_binary(&srcptr, srcend,
10343  &varscontext, sizeof(varscontext));
10344 
10345  error_context_name_and_value[0] = varname;
10346  error_context_name_and_value[1] = varvalue;
10347  error_context_callback.arg = &error_context_name_and_value[0];
10348  result = set_config_option(varname, varvalue, varscontext, varsource,
10349  GUC_ACTION_SET, true, ERROR, true);
10350  if (result <= 0)
10351  ereport(ERROR,
10352  (errcode(ERRCODE_INTERNAL_ERROR),
10353  errmsg("parameter \"%s\" could not be set", varname)));
10354  if (varsourcefile[0])
10355  set_config_sourcefile(varname, varsourcefile, varsourceline);
10356  error_context_callback.arg = NULL;
10357  }
10358 
10359  error_context_stack = error_context_callback.previous;
10360 }
GucContext
Definition: guc.h:68
static void static void set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
Definition: guc.c:7516
static void read_gucstate_binary(char **srcptr, char *srcend, void *dest, Size size)
Definition: guc.c:10266
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:4631
static bool can_skip_gucvar(struct config_generic *gconf)
Definition: guc.c:9962
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:5282
static void guc_restore_error_context_callback(void *arg)
Definition: guc.c:10280
#define ereport(elevel, rest)
Definition: elog.h:141
static struct config_generic ** guc_variables
Definition: guc.c:4628
static char * read_gucstate(char **srcptr, char *srcend)
Definition: guc.c:10243
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:6785

◆ SelectConfigFiles()

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

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

5403 {
5404  char *configdir;
5405  char *fname;
5406  struct stat stat_buf;
5407 
5408  /* configdir is -D option, or $PGDATA if no -D */
5409  if (userDoption)
5410  configdir = make_absolute_path(userDoption);
5411  else
5412  configdir = make_absolute_path(getenv("PGDATA"));
5413 
5414  if (configdir && stat(configdir, &stat_buf) != 0)
5415  {
5416  write_stderr("%s: could not access directory \"%s\": %s\n",
5417  progname,
5418  configdir,
5419  strerror(errno));
5420  if (errno == ENOENT)
5421  write_stderr("Run initdb or pg_basebackup to initialize a PostgreSQL data directory.\n");
5422  return false;
5423  }
5424 
5425  /*
5426  * Find the configuration file: if config_file was specified on the
5427  * command line, use it, else use configdir/postgresql.conf. In any case
5428  * ensure the result is an absolute path, so that it will be interpreted
5429  * the same way by future backends.
5430  */
5431  if (ConfigFileName)
5433  else if (configdir)
5434  {
5435  fname = guc_malloc(FATAL,
5436  strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
5437  sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
5438  }
5439  else
5440  {
5441  write_stderr("%s does not know where to find the server configuration file.\n"
5442  "You must specify the --config-file or -D invocation "
5443  "option or set the PGDATA environment variable.\n",
5444  progname);
5445  return false;
5446  }
5447 
5448  /*
5449  * Set the ConfigFileName GUC variable to its final value, ensuring that
5450  * it can't be overridden later.
5451  */
5452  SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
5453  free(fname);
5454 
5455  /*
5456  * Now read the config file for the first time.
5457  */
5458  if (stat(ConfigFileName, &stat_buf) != 0)
5459  {
5460  write_stderr("%s: could not access the server configuration file \"%s\": %s\n",
5461  progname, ConfigFileName, strerror(errno));
5462  free(configdir);
5463  return false;
5464  }
5465 
5466  /*
5467  * Read the configuration file for the first time. This time only the
5468  * data_directory parameter is picked up to determine the data directory,
5469  * so that we can read the PG_AUTOCONF_FILENAME file next time.
5470  */
5472 
5473  /*
5474  * If the data_directory GUC variable has been set, use that as DataDir;
5475  * otherwise use configdir if set; else punt.
5476  *
5477  * Note: SetDataDir will copy and absolute-ize its argument, so we don't
5478  * have to.
5479  */
5480  if (data_directory)
5482  else if (configdir)
5483  SetDataDir(configdir);
5484  else
5485  {
5486  write_stderr("%s does not know where to find the database system data.\n"
5487  "This can be specified as \"data_directory\" in \"%s\", "
5488  "or by the -D invocation option, or by the "
5489  "PGDATA environment variable.\n",
5491  return false;
5492  }
5493 
5494  /*
5495  * Reflect the final DataDir value back into the data_directory GUC var.
5496  * (If you are wondering why we don't just make them a single variable,
5497  * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
5498  * child backends specially. XXX is that still true? Given that we now
5499  * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
5500  * DataDir in advance.)
5501  */
5503 
5504  /*
5505  * Now read the config file a second time, allowing any settings in the
5506  * PG_AUTOCONF_FILENAME file to take effect. (This is pretty ugly, but
5507  * since we have to determine the DataDir before we can find the autoconf
5508  * file, the alternatives seem worse.)
5509  */
5511 
5512  /*
5513  * If timezone_abbreviations wasn't set in the configuration file, install
5514  * the default value. We do it this way because we can't safely install a
5515  * "real" value until my_exec_path is set, which may not have happened
5516  * when InitializeGUCOptions runs, so the bootstrap default value cannot
5517  * be the real desired default.
5518  */
5520 
5521  /*
5522  * Figure out where pg_hba.conf is, and make sure the path is absolute.
5523  */
5524  if (HbaFileName)
5526  else if (configdir)
5527  {
5528  fname = guc_malloc(FATAL,
5529  strlen(configdir) + strlen(HBA_FILENAME) + 2);
5530  sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
5531  }
5532  else
5533  {
5534  write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
5535  "This can be specified as \"hba_file\" in \"%s\", "
5536  "or by the -D invocation option, or by the "
5537  "PGDATA environment variable.\n",
5539  return false;
5540  }
5541  SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
5542  free(fname);
5543 
5544  /*
5545  * Likewise for pg_ident.conf.
5546  */
5547  if (IdentFileName)
5549  else if (configdir)
5550  {
5551  fname = guc_malloc(FATAL,
5552  strlen(configdir) + strlen(IDENT_FILENAME) + 2);
5553  sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
5554  }
5555  else
5556  {
5557  write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
5558  "This can be specified as \"ident_file\" in \"%s\", "
5559  "or by the -D invocation option, or by the "
5560  "PGDATA environment variable.\n",
5562  return false;
5563  }
5564  SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
5565  free(fname);
5566 
5567  free(configdir);
5568 
5569  return true;
5570 }
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:530
static void pg_timezone_abbrev_initialize(void)
Definition: guc.c:11260
#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:531
#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:7550
char * IdentFileName
Definition: guc.c:532
#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:156
char * DataDir
Definition: globals.c:62
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4672
static char * data_directory
Definition: guc.c:575

◆ SerializeGUCState()

void SerializeGUCState ( Size  maxsize,
char *  start_address 
)

Definition at line 10216 of file guc.c.

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

Referenced by InitializeParallelDSM().

10217 {
10218  char *curptr;
10219  Size actual_size;
10220  Size bytes_left;
10221  int i;
10222 
10223  /* Reserve space for saving the actual size of the guc state */
10224  Assert(maxsize > sizeof(actual_size));
10225  curptr = start_address + sizeof(actual_size);
10226  bytes_left = maxsize - sizeof(actual_size);
10227 
10228  for (i = 0; i < num_guc_variables; i++)
10229  serialize_variable(&curptr, &bytes_left, guc_variables[i]);
10230 
10231  /* Store actual size without assuming alignment of start_address. */
10232  actual_size = maxsize - bytes_left - sizeof(actual_size);
10233  memcpy(start_address, &actual_size, sizeof(actual_size));
10234 }
static void serialize_variable(char **destptr, Size *maxbytes, struct config_generic *gconf)
Definition: guc.c:10142
static int num_guc_variables
Definition: guc.c:4631
static struct config_generic ** guc_variables
Definition: guc.c:4628
#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 6785 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().

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