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 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_statement
 
int log_temp_files
 
double log_xact_sample_rate
 
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:1400
void pre_format_elog_string(int errnumber, const char *domain)
Definition: elog.c:1391

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

7907 {
7908  char *name;
7909  char *value;
7910  bool resetall = false;
7911  ConfigVariable *head = NULL;
7912  ConfigVariable *tail = NULL;
7913  volatile int Tmpfd;
7914  char AutoConfFileName[MAXPGPATH];
7915  char AutoConfTmpFileName[MAXPGPATH];
7916 
7917  if (!superuser())
7918  ereport(ERROR,
7919  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7920  (errmsg("must be superuser to execute ALTER SYSTEM command"))));
7921 
7922  /*
7923  * Extract statement arguments
7924  */
7925  name = altersysstmt->setstmt->name;
7926 
7927  switch (altersysstmt->setstmt->kind)
7928  {
7929  case VAR_SET_VALUE:
7930  value = ExtractSetVariableArgs(altersysstmt->setstmt);
7931  break;
7932 
7933  case VAR_SET_DEFAULT:
7934  case VAR_RESET:
7935  value = NULL;
7936  break;
7937 
7938  case VAR_RESET_ALL:
7939  value = NULL;
7940  resetall = true;
7941  break;
7942 
7943  default:
7944  elog(ERROR, "unrecognized alter system stmt type: %d",
7945  altersysstmt->setstmt->kind);
7946  break;
7947  }
7948 
7949  /*
7950  * Unless it's RESET_ALL, validate the target variable and value
7951  */
7952  if (!resetall)
7953  {
7954  struct config_generic *record;
7955 
7956  record = find_option(name, false, ERROR);
7957  if (record == NULL)
7958  ereport(ERROR,
7959  (errcode(ERRCODE_UNDEFINED_OBJECT),
7960  errmsg("unrecognized configuration parameter \"%s\"",
7961  name)));
7962 
7963  /*
7964  * Don't allow parameters that can't be set in configuration files to
7965  * be set in PG_AUTOCONF_FILENAME file.
7966  */
7967  if ((record->context == PGC_INTERNAL) ||
7968  (record->flags & GUC_DISALLOW_IN_FILE) ||
7969  (record->flags & GUC_DISALLOW_IN_AUTO_FILE))
7970  ereport(ERROR,
7971  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
7972  errmsg("parameter \"%s\" cannot be changed",
7973  name)));
7974 
7975  /*
7976  * If a value is specified, verify that it's sane.
7977  */
7978  if (value)
7979  {
7980  union config_var_val newval;
7981  void *newextra = NULL;
7982 
7983  /* Check that it's acceptable for the indicated parameter */
7984  if (!parse_and_validate_value(record, name, value,
7985  PGC_S_FILE, ERROR,
7986  &newval, &newextra))
7987  ereport(ERROR,
7988  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7989  errmsg("invalid value for parameter \"%s\": \"%s\"",
7990  name, value)));
7991 
7992  if (record->vartype == PGC_STRING && newval.stringval != NULL)
7993  free(newval.stringval);
7994  if (newextra)
7995  free(newextra);
7996 
7997  /*
7998  * We must also reject values containing newlines, because the
7999  * grammar for config files doesn't support embedded newlines in
8000  * string literals.
8001  */
8002  if (strchr(value, '\n'))
8003  ereport(ERROR,
8004  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8005  errmsg("parameter value for ALTER SYSTEM must not contain a newline")));
8006  }
8007  }
8008 
8009  /*
8010  * PG_AUTOCONF_FILENAME and its corresponding temporary file are always in
8011  * the data directory, so we can reference them by simple relative paths.
8012  */
8013  snprintf(AutoConfFileName, sizeof(AutoConfFileName), "%s",
8015  snprintf(AutoConfTmpFileName, sizeof(AutoConfTmpFileName), "%s.%s",
8016  AutoConfFileName,
8017  "tmp");
8018 
8019  /*
8020  * Only one backend is allowed to operate on PG_AUTOCONF_FILENAME at a
8021  * time. Use AutoFileLock to ensure that. We must hold the lock while
8022  * reading the old file contents.
8023  */
8024  LWLockAcquire(AutoFileLock, LW_EXCLUSIVE);
8025 
8026  /*
8027  * If we're going to reset everything, then no need to open or parse the
8028  * old file. We'll just write out an empty list.
8029  */
8030  if (!resetall)
8031  {
8032  struct stat st;
8033 
8034  if (stat(AutoConfFileName, &st) == 0)
8035  {
8036  /* open old file PG_AUTOCONF_FILENAME */
8037  FILE *infile;
8038 
8039  infile = AllocateFile(AutoConfFileName, "r");
8040  if (infile == NULL)
8041  ereport(ERROR,
8043  errmsg("could not open file \"%s\": %m",
8044  AutoConfFileName)));
8045 
8046  /* parse it */
8047  if (!ParseConfigFp(infile, AutoConfFileName, 0, LOG, &head, &tail))
8048  ereport(ERROR,
8049  (errcode(ERRCODE_CONFIG_FILE_ERROR),
8050  errmsg("could not parse contents of file \"%s\"",
8051  AutoConfFileName)));
8052 
8053  FreeFile(infile);
8054  }
8055 
8056  /*
8057  * Now, replace any existing entry with the new value, or add it if
8058  * not present.
8059  */
8060  replace_auto_config_value(&head, &tail, name, value);
8061  }
8062 
8063  /*
8064  * To ensure crash safety, first write the new file data to a temp file,
8065  * then atomically rename it into place.
8066  *
8067  * If there is a temp file left over due to a previous crash, it's okay to
8068  * truncate and reuse it.
8069  */
8070  Tmpfd = BasicOpenFile(AutoConfTmpFileName,
8071  O_CREAT | O_RDWR | O_TRUNC);
8072  if (Tmpfd < 0)
8073  ereport(ERROR,
8075  errmsg("could not open file \"%s\": %m",
8076  AutoConfTmpFileName)));
8077 
8078  /*
8079  * Use a TRY block to clean up the file if we fail. Since we need a TRY
8080  * block anyway, OK to use BasicOpenFile rather than OpenTransientFile.
8081  */
8082  PG_TRY();
8083  {
8084  /* Write and sync the new contents to the temporary file */
8085  write_auto_conf_file(Tmpfd, AutoConfTmpFileName, head);
8086 
8087  /* Close before renaming; may be required on some platforms */
8088  close(Tmpfd);
8089  Tmpfd = -1;
8090 
8091  /*
8092  * As the rename is atomic operation, if any problem occurs after this
8093  * at worst it can lose the parameters set by last ALTER SYSTEM
8094  * command.
8095  */
8096  durable_rename(AutoConfTmpFileName, AutoConfFileName, ERROR);
8097  }
8098  PG_CATCH();
8099  {
8100  /* Close file first, else unlink might fail on some platforms */
8101  if (Tmpfd >= 0)
8102  close(Tmpfd);
8103 
8104  /* Unlink, but ignore any error */
8105  (void) unlink(AutoConfTmpFileName);
8106 
8107  PG_RE_THROW();
8108  }
8109  PG_END_TRY();
8110 
8111  FreeConfigVariables(head);
8112 
8113  LWLockRelease(AutoFileLock);
8114 }
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:6525
VariableSetKind kind
Definition: parsenodes.h:2019
static struct @144 value
int errcode(int sqlerrcode)
Definition: elog.c:570
bool superuser(void)
Definition: superuser.c:47
#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:3145
int errcode_for_file_access(void)
Definition: elog.c:593
FILE * AllocateFile(const char *name, const char *mode)
Definition: fd.c:2207
#define ereport(elevel, rest)
Definition: elog.h:141
int durable_rename(const char *oldfile, const char *newfile, int elevel)
Definition: fd.c:608
enum config_type vartype
Definition: guc_tables.h:156
#define stat(a, b)
Definition: win32_port.h:264
#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:7768
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:5022
#define PG_CATCH()
Definition: elog.h:310
#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:331
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:946
int FreeFile(FILE *file)
Definition: fd.c:2406
int errmsg(const char *fmt,...)
Definition: elog.c:784
bool ParseConfigFp(FILE *fp, const char *config_file, int depth, int elevel, ConfigVariable **head_p, ConfigVariable **tail_p)
#define elog(elevel,...)
Definition: elog.h:226
static void replace_auto_config_value(ConfigVariable **head_p, ConfigVariable **tail_p, const char *name, const char *value)
Definition: guc.c:7836
void FreeConfigVariables(ConfigVariable *list)
#define close(a)
Definition: win32.h:12
#define PG_TRY()
Definition: elog.h:301
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
Definition: guc.c:8244
#define snprintf
Definition: port.h:192
#define PG_END_TRY()
Definition: elog.h:317
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 1299 of file tablespace.c.

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

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

◆ assign_xlog_sync_method()

void assign_xlog_sync_method ( int  new_sync_method,
void *  extra 
)

Definition at line 10052 of file xlog.c.

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

10053 {
10054  if (sync_method != new_sync_method)
10055  {
10056  /*
10057  * To ensure that no blocks escape unsynced, force an fsync on the
10058  * currently open log segment (if any). Also, if the open flag is
10059  * changing, close the log file so it will be reopened (with new flag
10060  * bit) at next use.
10061  */
10062  if (openLogFile >= 0)
10063  {
10065  if (pg_fsync(openLogFile) != 0)
10066  ereport(PANIC,
10068  errmsg("could not fsync file \"%s\": %m",
10071  if (get_sync_bit(sync_method) != get_sync_bit(new_sync_method))
10072  XLogFileClose();
10073  }
10074  }
10075 }
static int get_sync_bit(int method)
Definition: xlog.c:9996
#define PANIC
Definition: elog.h:53
static XLogSegNo openLogSegNo
Definition: xlog.c:780
static void XLogFileClose(void)
Definition: xlog.c:3779
char * XLogFileNameP(TimeLineID tli, XLogSegNo segno)
Definition: xlog.c:10130
int errcode_for_file_access(void)
Definition: elog.c:593
static void pgstat_report_wait_end(void)
Definition: pgstat.h:1342
#define ereport(elevel, rest)
Definition: elog.h:141
static int openLogFile
Definition: xlog.c:779
TimeLineID ThisTimeLineID
Definition: xlog.c:187
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:784
int pg_fsync(int fd)
Definition: fd.c:333

◆ AtEOXact_GUC()

void AtEOXact_GUC ( bool  isCommit,
int  nestLevel 
)

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

5730 {
5731  bool still_dirty;
5732  int i;
5733 
5734  /*
5735  * Note: it's possible to get here with GUCNestLevel == nestLevel-1 during
5736  * abort, if there is a failure during transaction start before
5737  * AtStart_GUC is called.
5738  */
5739  Assert(nestLevel > 0 &&
5740  (nestLevel <= GUCNestLevel ||
5741  (nestLevel == GUCNestLevel + 1 && !isCommit)));
5742 
5743  /* Quick exit if nothing's changed in this transaction */
5744  if (!guc_dirty)
5745  {
5746  GUCNestLevel = nestLevel - 1;
5747  return;
5748  }
5749 
5750  still_dirty = false;
5751  for (i = 0; i < num_guc_variables; i++)
5752  {
5753  struct config_generic *gconf = guc_variables[i];
5754  GucStack *stack;
5755 
5756  /*
5757  * Process and pop each stack entry within the nest level. To simplify
5758  * fmgr_security_definer() and other places that use GUC_ACTION_SAVE,
5759  * we allow failure exit from code that uses a local nest level to be
5760  * recovered at the surrounding transaction or subtransaction abort;
5761  * so there could be more than one stack entry to pop.
5762  */
5763  while ((stack = gconf->stack) != NULL &&
5764  stack->nest_level >= nestLevel)
5765  {
5766  GucStack *prev = stack->prev;
5767  bool restorePrior = false;
5768  bool restoreMasked = false;
5769  bool changed;
5770 
5771  /*
5772  * In this next bit, if we don't set either restorePrior or
5773  * restoreMasked, we must "discard" any unwanted fields of the
5774  * stack entries to avoid leaking memory. If we do set one of
5775  * those flags, unused fields will be cleaned up after restoring.
5776  */
5777  if (!isCommit) /* if abort, always restore prior value */
5778  restorePrior = true;
5779  else if (stack->state == GUC_SAVE)
5780  restorePrior = true;
5781  else if (stack->nest_level == 1)
5782  {
5783  /* transaction commit */
5784  if (stack->state == GUC_SET_LOCAL)
5785  restoreMasked = true;
5786  else if (stack->state == GUC_SET)
5787  {
5788  /* we keep the current active value */
5789  discard_stack_value(gconf, &stack->prior);
5790  }
5791  else /* must be GUC_LOCAL */
5792  restorePrior = true;
5793  }
5794  else if (prev == NULL ||
5795  prev->nest_level < stack->nest_level - 1)
5796  {
5797  /* decrement entry's level and do not pop it */
5798  stack->nest_level--;
5799  continue;
5800  }
5801  else
5802  {
5803  /*
5804  * We have to merge this stack entry into prev. See README for
5805  * discussion of this bit.
5806  */
5807  switch (stack->state)
5808  {
5809  case GUC_SAVE:
5810  Assert(false); /* can't get here */
5811  break;
5812 
5813  case GUC_SET:
5814  /* next level always becomes SET */
5815  discard_stack_value(gconf, &stack->prior);
5816  if (prev->state == GUC_SET_LOCAL)
5817  discard_stack_value(gconf, &prev->masked);
5818  prev->state = GUC_SET;
5819  break;
5820 
5821  case GUC_LOCAL:
5822  if (prev->state == GUC_SET)
5823  {
5824  /* LOCAL migrates down */
5825  prev->masked_scontext = stack->scontext;
5826  prev->masked = stack->prior;
5827  prev->state = GUC_SET_LOCAL;
5828  }
5829  else
5830  {
5831  /* else just forget this stack level */
5832  discard_stack_value(gconf, &stack->prior);
5833  }
5834  break;
5835 
5836  case GUC_SET_LOCAL:
5837  /* prior state at this level no longer wanted */
5838  discard_stack_value(gconf, &stack->prior);
5839  /* copy down the masked state */
5840  prev->masked_scontext = stack->masked_scontext;
5841  if (prev->state == GUC_SET_LOCAL)
5842  discard_stack_value(gconf, &prev->masked);
5843  prev->masked = stack->masked;
5844  prev->state = GUC_SET_LOCAL;
5845  break;
5846  }
5847  }
5848 
5849  changed = false;
5850 
5851  if (restorePrior || restoreMasked)
5852  {
5853  /* Perform appropriate restoration of the stacked value */
5854  config_var_value newvalue;
5855  GucSource newsource;
5856  GucContext newscontext;
5857 
5858  if (restoreMasked)
5859  {
5860  newvalue = stack->masked;
5861  newsource = PGC_S_SESSION;
5862  newscontext = stack->masked_scontext;
5863  }
5864  else
5865  {
5866  newvalue = stack->prior;
5867  newsource = stack->source;
5868  newscontext = stack->scontext;
5869  }
5870 
5871  switch (gconf->vartype)
5872  {
5873  case PGC_BOOL:
5874  {
5875  struct config_bool *conf = (struct config_bool *) gconf;
5876  bool newval = newvalue.val.boolval;
5877  void *newextra = newvalue.extra;
5878 
5879  if (*conf->variable != newval ||
5880  conf->gen.extra != newextra)
5881  {
5882  if (conf->assign_hook)
5883  conf->assign_hook(newval, newextra);
5884  *conf->variable = newval;
5885  set_extra_field(&conf->gen, &conf->gen.extra,
5886  newextra);
5887  changed = true;
5888  }
5889  break;
5890  }
5891  case PGC_INT:
5892  {
5893  struct config_int *conf = (struct config_int *) gconf;
5894  int newval = newvalue.val.intval;
5895  void *newextra = newvalue.extra;
5896 
5897  if (*conf->variable != newval ||
5898  conf->gen.extra != newextra)
5899  {
5900  if (conf->assign_hook)
5901  conf->assign_hook(newval, newextra);
5902  *conf->variable = newval;
5903  set_extra_field(&conf->gen, &conf->gen.extra,
5904  newextra);
5905  changed = true;
5906  }
5907  break;
5908  }
5909  case PGC_REAL:
5910  {
5911  struct config_real *conf = (struct config_real *) gconf;
5912  double newval = newvalue.val.realval;
5913  void *newextra = newvalue.extra;
5914 
5915  if (*conf->variable != newval ||
5916  conf->gen.extra != newextra)
5917  {
5918  if (conf->assign_hook)
5919  conf->assign_hook(newval, newextra);
5920  *conf->variable = newval;
5921  set_extra_field(&conf->gen, &conf->gen.extra,
5922  newextra);
5923  changed = true;
5924  }
5925  break;
5926  }
5927  case PGC_STRING:
5928  {
5929  struct config_string *conf = (struct config_string *) gconf;
5930  char *newval = newvalue.val.stringval;
5931  void *newextra = newvalue.extra;
5932 
5933  if (*conf->variable != newval ||
5934  conf->gen.extra != newextra)
5935  {
5936  if (conf->assign_hook)
5937  conf->assign_hook(newval, newextra);
5938  set_string_field(conf, conf->variable, newval);
5939  set_extra_field(&conf->gen, &conf->gen.extra,
5940  newextra);
5941  changed = true;
5942  }
5943 
5944  /*
5945  * Release stacked values if not used anymore. We
5946  * could use discard_stack_value() here, but since
5947  * we have type-specific code anyway, might as
5948  * well inline it.
5949  */
5950  set_string_field(conf, &stack->prior.val.stringval, NULL);
5951  set_string_field(conf, &stack->masked.val.stringval, NULL);
5952  break;
5953  }
5954  case PGC_ENUM:
5955  {
5956  struct config_enum *conf = (struct config_enum *) gconf;
5957  int newval = newvalue.val.enumval;
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  }
5973 
5974  /*
5975  * Release stacked extra values if not used anymore.
5976  */
5977  set_extra_field(gconf, &(stack->prior.extra), NULL);
5978  set_extra_field(gconf, &(stack->masked.extra), NULL);
5979 
5980  /* And restore source information */
5981  gconf->source = newsource;
5982  gconf->scontext = newscontext;
5983  }
5984 
5985  /* Finish popping the state stack */
5986  gconf->stack = prev;
5987  pfree(stack);
5988 
5989  /* Report new value if we changed it */
5990  if (changed && (gconf->flags & GUC_REPORT))
5991  ReportGUCOption(gconf);
5992  } /* end of stack-popping loop */
5993 
5994  if (stack != NULL)
5995  still_dirty = true;
5996  }
5997 
5998  /* If there are no remaining stack entries, we can reset guc_dirty */
5999  guc_dirty = still_dirty;
6000 
6001  /* Update nesting level */
6002  GUCNestLevel = nestLevel - 1;
6003 }
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:4581
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:1031
static int num_guc_variables
Definition: guc.c:4568
static void discard_stack_value(struct config_generic *gconf, config_var_value *val)
Definition: guc.c:4796
GucSource source
Definition: guc_tables.h:126
static void set_extra_field(struct config_generic *gconf, void **field, void *newval)
Definition: guc.c:4742
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:4681
static struct config_generic ** guc_variables
Definition: guc.c:4565
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:732
#define newval
char * stringval
Definition: guc_tables.h:36
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:6039
GucStack * stack
Definition: guc_tables.h:162
double realval
Definition: guc_tables.h:35
static bool guc_dirty
Definition: guc.c:4577
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 5695 of file guc.c.

References elog, and WARNING.

Referenced by StartTransaction().

5696 {
5697  /*
5698  * The nest level should be 0 between transactions; if it isn't, somebody
5699  * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
5700  * throw a warning but make no other effort to clean up.
5701  */
5702  if (GUCNestLevel != 0)
5703  elog(WARNING, "GUC nest level = %d at transaction start",
5704  GUCNestLevel);
5705  GUCNestLevel = 1;
5706 }
static int GUCNestLevel
Definition: guc.c:4581
#define WARNING
Definition: elog.h:40
#define elog(elevel,...)
Definition: elog.h:226

◆ BeginReportingGUCOptions()

void BeginReportingGUCOptions ( void  )

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

6012 {
6013  int i;
6014 
6015  /*
6016  * Don't do anything unless talking to an interactive frontend of protocol
6017  * 3.0 or later.
6018  */
6019  if (whereToSendOutput != DestRemote ||
6021  return;
6022 
6023  reporting_enabled = true;
6024 
6025  /* Transmit initial values of interesting variables */
6026  for (i = 0; i < num_guc_variables; i++)
6027  {
6028  struct config_generic *conf = guc_variables[i];
6029 
6030  if (conf->flags & GUC_REPORT)
6031  ReportGUCOption(conf);
6032  }
6033 }
#define PG_PROTOCOL_MAJOR(v)
Definition: pqcomm.h:104
static int num_guc_variables
Definition: guc.c:4568
#define GUC_REPORT
Definition: guc.h:208
static struct config_generic ** guc_variables
Definition: guc.c:4565
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:6039
CommandDest whereToSendOutput
Definition: postgres.c:90
static bool reporting_enabled
Definition: guc.c:4579
ProtocolVersion FrontendProtocol
Definition: globals.c:28

◆ check_default_tablespace()

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

Definition at line 1087 of file tablespace.c.

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

1088 {
1089  /*
1090  * If we aren't inside a transaction, or connected to a database, we
1091  * cannot do the catalog accesses necessary to verify the name. Must
1092  * accept the value on faith.
1093  */
1095  {
1096  if (**newval != '\0' &&
1098  {
1099  /*
1100  * When source == PGC_S_TEST, don't throw a hard error for a
1101  * nonexistent tablespace, only a NOTICE. See comments in guc.h.
1102  */
1103  if (source == PGC_S_TEST)
1104  {
1105  ereport(NOTICE,
1106  (errcode(ERRCODE_UNDEFINED_OBJECT),
1107  errmsg("tablespace \"%s\" does not exist",
1108  *newval)));
1109  }
1110  else
1111  {
1112  GUC_check_errdetail("Tablespace \"%s\" does not exist.",
1113  *newval);
1114  return false;
1115  }
1116  }
1117  }
1118 
1119  return true;
1120 }
Oid get_tablespace_oid(const char *tablespacename, bool missing_ok)
Definition: tablespace.c:1417
GucSource source
Definition: guc_tables.h:158
#define GUC_check_errdetail
Definition: guc.h:409
int errcode(int sqlerrcode)
Definition: elog.c:570
#define OidIsValid(objectId)
Definition: c.h:638
#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:356
int errmsg(const char *fmt,...)
Definition: elog.c:784

◆ 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:409
char * pstrdup(const char *in)
Definition: mcxt.c:1161
void pfree(void *pointer)
Definition: mcxt.c:1031
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3669
#define newval
void list_free(List *list)
Definition: list.c:1373
Definition: pg_list.h:50

◆ check_temp_tablespaces()

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

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

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

◆ check_wal_buffers()

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

Definition at line 4878 of file xlog.c.

References XLOGbuffers, and XLOGChooseNumBuffers().

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

8583 {
8584  struct config_bool *var;
8585 
8586  var = (struct config_bool *)
8587  init_custom_variable(name, short_desc, long_desc, context, flags,
8588  PGC_BOOL, sizeof(struct config_bool));
8589  var->variable = valueAddr;
8590  var->boot_val = bootValue;
8591  var->reset_val = bootValue;
8592  var->check_hook = check_hook;
8593  var->assign_hook = assign_hook;
8594  var->show_hook = show_hook;
8595  define_custom_variable(&var->gen);
8596 }
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:8332
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:8392

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

8695 {
8696  struct config_enum *var;
8697 
8698  var = (struct config_enum *)
8699  init_custom_variable(name, short_desc, long_desc, context, flags,
8700  PGC_ENUM, sizeof(struct config_enum));
8701  var->variable = valueAddr;
8702  var->boot_val = bootValue;
8703  var->reset_val = bootValue;
8704  var->options = options;
8705  var->check_hook = check_hook;
8706  var->assign_hook = assign_hook;
8707  var->show_hook = show_hook;
8708  define_custom_variable(&var->gen);
8709 }
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:8332
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:8392

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

8611 {
8612  struct config_int *var;
8613 
8614  var = (struct config_int *)
8615  init_custom_variable(name, short_desc, long_desc, context, flags,
8616  PGC_INT, sizeof(struct config_int));
8617  var->variable = valueAddr;
8618  var->boot_val = bootValue;
8619  var->reset_val = bootValue;
8620  var->min = minValue;
8621  var->max = maxValue;
8622  var->check_hook = check_hook;
8623  var->assign_hook = assign_hook;
8624  var->show_hook = show_hook;
8625  define_custom_variable(&var->gen);
8626 }
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:8332
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8392
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 8629 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().

8641 {
8642  struct config_real *var;
8643 
8644  var = (struct config_real *)
8645  init_custom_variable(name, short_desc, long_desc, context, flags,
8646  PGC_REAL, sizeof(struct config_real));
8647  var->variable = valueAddr;
8648  var->boot_val = bootValue;
8649  var->reset_val = bootValue;
8650  var->min = minValue;
8651  var->max = maxValue;
8652  var->check_hook = check_hook;
8653  var->assign_hook = assign_hook;
8654  var->show_hook = show_hook;
8655  define_custom_variable(&var->gen);
8656 }
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:8332
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:8392
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 8659 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().

8669 {
8670  struct config_string *var;
8671 
8672  var = (struct config_string *)
8673  init_custom_variable(name, short_desc, long_desc, context, flags,
8674  PGC_STRING, sizeof(struct config_string));
8675  var->variable = valueAddr;
8676  var->boot_val = bootValue;
8677  var->check_hook = check_hook;
8678  var->assign_hook = assign_hook;
8679  var->show_hook = show_hook;
8680  define_custom_variable(&var->gen);
8681 }
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:8332
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:8392

◆ EmitWarningsOnPlaceholders()

void EmitWarningsOnPlaceholders ( const char *  className)

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

8713 {
8714  int classLen = strlen(className);
8715  int i;
8716 
8717  for (i = 0; i < num_guc_variables; i++)
8718  {
8719  struct config_generic *var = guc_variables[i];
8720 
8721  if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
8722  strncmp(className, var->name, classLen) == 0 &&
8723  var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
8724  {
8725  ereport(WARNING,
8726  (errcode(ERRCODE_UNDEFINED_OBJECT),
8727  errmsg("unrecognized configuration parameter \"%s\"",
8728  var->name)));
8729  }
8730  }
8731 }
const char * name
Definition: guc_tables.h:149
int errcode(int sqlerrcode)
Definition: elog.c:570
#define GUC_QUALIFIER_SEPARATOR
Definition: guc.h:199
static int num_guc_variables
Definition: guc.c:4568
#define ereport(elevel, rest)
Definition: elog.h:141
static struct config_generic ** guc_variables
Definition: guc.c:4565
#define WARNING
Definition: elog.h:40
#define GUC_CUSTOM_PLACEHOLDER
Definition: guc.h:211
int errmsg(const char *fmt,...)
Definition: elog.c:784
int i

◆ EstimateGUCStateSpace()

Size EstimateGUCStateSpace ( void  )

Definition at line 10011 of file guc.c.

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

Referenced by InitializeParallelDSM().

10012 {
10013  Size size;
10014  int i;
10015 
10016  /* Add space reqd for saving the data size of the guc state */
10017  size = sizeof(Size);
10018 
10019  /* Add up the space needed for each GUC variable */
10020  for (i = 0; i < num_guc_variables; i++)
10021  size = add_size(size,
10023 
10024  return size;
10025 }
static int num_guc_variables
Definition: guc.c:4568
static struct config_generic ** guc_variables
Definition: guc.c:4565
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
size_t Size
Definition: c.h:466
static Size estimate_variable_size(struct config_generic *gconf)
Definition: guc.c:9913
int i

◆ ExecSetVariableStmt()

void ExecSetVariableStmt ( VariableSetStmt stmt,
bool  isTopLevel 
)

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

8121 {
8123 
8124  /*
8125  * Workers synchronize these parameters at the start of the parallel
8126  * operation; then, we block SET during the operation.
8127  */
8128  if (IsInParallelMode())
8129  ereport(ERROR,
8130  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
8131  errmsg("cannot set parameters during a parallel operation")));
8132 
8133  switch (stmt->kind)
8134  {
8135  case VAR_SET_VALUE:
8136  case VAR_SET_CURRENT:
8137  if (stmt->is_local)
8138  WarnNoTransactionBlock(isTopLevel, "SET LOCAL");
8139  (void) set_config_option(stmt->name,
8140  ExtractSetVariableArgs(stmt),
8142  PGC_S_SESSION,
8143  action, true, 0, false);
8144  break;
8145  case VAR_SET_MULTI:
8146 
8147  /*
8148  * Special-case SQL syntaxes. The TRANSACTION and SESSION
8149  * CHARACTERISTICS cases effectively set more than one variable
8150  * per statement. TRANSACTION SNAPSHOT only takes one argument,
8151  * but we put it here anyway since it's a special case and not
8152  * related to any GUC variable.
8153  */
8154  if (strcmp(stmt->name, "TRANSACTION") == 0)
8155  {
8156  ListCell *head;
8157 
8158  WarnNoTransactionBlock(isTopLevel, "SET TRANSACTION");
8159 
8160  foreach(head, stmt->args)
8161  {
8162  DefElem *item = (DefElem *) lfirst(head);
8163 
8164  if (strcmp(item->defname, "transaction_isolation") == 0)
8165  SetPGVariable("transaction_isolation",
8166  list_make1(item->arg), stmt->is_local);
8167  else if (strcmp(item->defname, "transaction_read_only") == 0)
8168  SetPGVariable("transaction_read_only",
8169  list_make1(item->arg), stmt->is_local);
8170  else if (strcmp(item->defname, "transaction_deferrable") == 0)
8171  SetPGVariable("transaction_deferrable",
8172  list_make1(item->arg), stmt->is_local);
8173  else
8174  elog(ERROR, "unexpected SET TRANSACTION element: %s",
8175  item->defname);
8176  }
8177  }
8178  else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
8179  {
8180  ListCell *head;
8181 
8182  foreach(head, stmt->args)
8183  {
8184  DefElem *item = (DefElem *) lfirst(head);
8185 
8186  if (strcmp(item->defname, "transaction_isolation") == 0)
8187  SetPGVariable("default_transaction_isolation",
8188  list_make1(item->arg), stmt->is_local);
8189  else if (strcmp(item->defname, "transaction_read_only") == 0)
8190  SetPGVariable("default_transaction_read_only",
8191  list_make1(item->arg), stmt->is_local);
8192  else if (strcmp(item->defname, "transaction_deferrable") == 0)
8193  SetPGVariable("default_transaction_deferrable",
8194  list_make1(item->arg), stmt->is_local);
8195  else
8196  elog(ERROR, "unexpected SET SESSION element: %s",
8197  item->defname);
8198  }
8199  }
8200  else if (strcmp(stmt->name, "TRANSACTION SNAPSHOT") == 0)
8201  {
8202  A_Const *con = linitial_node(A_Const, stmt->args);
8203 
8204  if (stmt->is_local)
8205  ereport(ERROR,
8206  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8207  errmsg("SET LOCAL TRANSACTION SNAPSHOT is not implemented")));
8208 
8209  WarnNoTransactionBlock(isTopLevel, "SET TRANSACTION");
8210  Assert(nodeTag(&con->val) == T_String);
8211  ImportSnapshot(strVal(&con->val));
8212  }
8213  else
8214  elog(ERROR, "unexpected SET MULTI element: %s",
8215  stmt->name);
8216  break;
8217  case VAR_SET_DEFAULT:
8218  if (stmt->is_local)
8219  WarnNoTransactionBlock(isTopLevel, "SET LOCAL");
8220  /* fall through */
8221  case VAR_RESET:
8222  if (strcmp(stmt->name, "transaction_isolation") == 0)
8223  WarnNoTransactionBlock(isTopLevel, "RESET TRANSACTION");
8224 
8225  (void) set_config_option(stmt->name,
8226  NULL,
8228  PGC_S_SESSION,
8229  action, true, 0, false);
8230  break;
8231  case VAR_RESET_ALL:
8232  ResetAllOptions();
8233  break;
8234  }
8235 }
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:3388
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:570
bool superuser(void)
Definition: superuser.c:47
#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:994
#define ERROR
Definition: elog.h:43
Definition: guc.h:75
void ResetAllOptions(void)
Definition: guc.c:5514
#define ereport(elevel, rest)
Definition: elog.h:141
Node * arg
Definition: parsenodes.h:731
#define Assert(condition)
Definition: c.h:732
#define lfirst(lc)
Definition: pg_list.h:190
#define nodeTag(nodeptr)
Definition: nodes.h:529
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define elog(elevel,...)
Definition: elog.h:226
char * defname
Definition: parsenodes.h:730
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
Definition: guc.c:8244
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:6722
void SetPGVariable(const char *name, List *args, bool is_local)
Definition: guc.c:8264

◆ ExtractSetVariableArgs()

char* ExtractSetVariableArgs ( VariableSetStmt stmt)

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

8245 {
8246  switch (stmt->kind)
8247  {
8248  case VAR_SET_VALUE:
8249  return flatten_set_variable_args(stmt->name, stmt->args);
8250  case VAR_SET_CURRENT:
8251  return GetConfigOptionByName(stmt->name, NULL, false);
8252  default:
8253  return NULL;
8254  }
8255 }
VariableSetKind kind
Definition: parsenodes.h:2019
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:8977
static char * flatten_set_variable_args(const char *name, List *args)
Definition: guc.c:7646

◆ FreeConfigVariables()

void FreeConfigVariables ( ConfigVariable list)

◆ GetConfigOption()

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

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

7512 {
7513  struct config_generic *record;
7514  static char buffer[256];
7515 
7516  record = find_option(name, false, ERROR);
7517  if (record == NULL)
7518  {
7519  if (missing_ok)
7520  return NULL;
7521  ereport(ERROR,
7522  (errcode(ERRCODE_UNDEFINED_OBJECT),
7523  errmsg("unrecognized configuration parameter \"%s\"",
7524  name)));
7525  }
7526  if (restrict_privileged &&
7527  (record->flags & GUC_SUPERUSER_ONLY) &&
7528  !is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
7529  ereport(ERROR,
7530  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7531  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
7532  name)));
7533 
7534  switch (record->vartype)
7535  {
7536  case PGC_BOOL:
7537  return *((struct config_bool *) record)->variable ? "on" : "off";
7538 
7539  case PGC_INT:
7540  snprintf(buffer, sizeof(buffer), "%d",
7541  *((struct config_int *) record)->variable);
7542  return buffer;
7543 
7544  case PGC_REAL:
7545  snprintf(buffer, sizeof(buffer), "%g",
7546  *((struct config_real *) record)->variable);
7547  return buffer;
7548 
7549  case PGC_STRING:
7550  return *((struct config_string *) record)->variable;
7551 
7552  case PGC_ENUM:
7553  return config_enum_lookup_by_value((struct config_enum *) record,
7554  *((struct config_enum *) record)->variable);
7555  }
7556  return NULL;
7557 }
Oid GetUserId(void)
Definition: miscinit.c:380
int errcode(int sqlerrcode)
Definition: elog.c:570
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:6418
#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:4932
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:5022
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define snprintf
Definition: port.h:192

◆ GetConfigOptionByName()

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

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

8978 {
8979  struct config_generic *record;
8980 
8981  record = find_option(name, false, ERROR);
8982  if (record == NULL)
8983  {
8984  if (missing_ok)
8985  {
8986  if (varname)
8987  *varname = NULL;
8988  return NULL;
8989  }
8990 
8991  ereport(ERROR,
8992  (errcode(ERRCODE_UNDEFINED_OBJECT),
8993  errmsg("unrecognized configuration parameter \"%s\"", name)));
8994  }
8995 
8996  if ((record->flags & GUC_SUPERUSER_ONLY) &&
8997  !is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
8998  ereport(ERROR,
8999  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
9000  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
9001  name)));
9002 
9003  if (varname)
9004  *varname = record->name;
9005 
9006  return _ShowOption(record, true);
9007 }
static char * _ShowOption(struct config_generic *record, bool use_units)
Definition: guc.c:9538
Oid GetUserId(void)
Definition: miscinit.c:380
const char * name
Definition: guc_tables.h:149
int errcode(int sqlerrcode)
Definition: elog.c:570
#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:4932
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:5022
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:784

◆ GetConfigOptionByNum()

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

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

9015 {
9016  char buffer[256];
9017  struct config_generic *conf;
9018 
9019  /* check requested variable number valid */
9020  Assert((varnum >= 0) && (varnum < num_guc_variables));
9021 
9022  conf = guc_variables[varnum];
9023 
9024  if (noshow)
9025  {
9026  if ((conf->flags & GUC_NO_SHOW_ALL) ||
9027  ((conf->flags & GUC_SUPERUSER_ONLY) &&
9028  !is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS)))
9029  *noshow = true;
9030  else
9031  *noshow = false;
9032  }
9033 
9034  /* first get the generic attributes */
9035 
9036  /* name */
9037  values[0] = conf->name;
9038 
9039  /* setting: use _ShowOption in order to avoid duplicating the logic */
9040  values[1] = _ShowOption(conf, false);
9041 
9042  /* unit, if any (NULL is fine) */
9043  values[2] = get_config_unit_name(conf->flags);
9044 
9045  /* group */
9046  values[3] = _(config_group_names[conf->group]);
9047 
9048  /* short_desc */
9049  values[4] = _(conf->short_desc);
9050 
9051  /* extra_desc */
9052  values[5] = _(conf->long_desc);
9053 
9054  /* context */
9055  values[6] = GucContext_Names[conf->context];
9056 
9057  /* vartype */
9058  values[7] = config_type_names[conf->vartype];
9059 
9060  /* source */
9061  values[8] = GucSource_Names[conf->source];
9062 
9063  /* now get the type specific attributes */
9064  switch (conf->vartype)
9065  {
9066  case PGC_BOOL:
9067  {
9068  struct config_bool *lconf = (struct config_bool *) conf;
9069 
9070  /* min_val */
9071  values[9] = NULL;
9072 
9073  /* max_val */
9074  values[10] = NULL;
9075 
9076  /* enumvals */
9077  values[11] = NULL;
9078 
9079  /* boot_val */
9080  values[12] = pstrdup(lconf->boot_val ? "on" : "off");
9081 
9082  /* reset_val */
9083  values[13] = pstrdup(lconf->reset_val ? "on" : "off");
9084  }
9085  break;
9086 
9087  case PGC_INT:
9088  {
9089  struct config_int *lconf = (struct config_int *) conf;
9090 
9091  /* min_val */
9092  snprintf(buffer, sizeof(buffer), "%d", lconf->min);
9093  values[9] = pstrdup(buffer);
9094 
9095  /* max_val */
9096  snprintf(buffer, sizeof(buffer), "%d", lconf->max);
9097  values[10] = pstrdup(buffer);
9098 
9099  /* enumvals */
9100  values[11] = NULL;
9101 
9102  /* boot_val */
9103  snprintf(buffer, sizeof(buffer), "%d", lconf->boot_val);
9104  values[12] = pstrdup(buffer);
9105 
9106  /* reset_val */
9107  snprintf(buffer, sizeof(buffer), "%d", lconf->reset_val);
9108  values[13] = pstrdup(buffer);
9109  }
9110  break;
9111 
9112  case PGC_REAL:
9113  {
9114  struct config_real *lconf = (struct config_real *) conf;
9115 
9116  /* min_val */
9117  snprintf(buffer, sizeof(buffer), "%g", lconf->min);
9118  values[9] = pstrdup(buffer);
9119 
9120  /* max_val */
9121  snprintf(buffer, sizeof(buffer), "%g", lconf->max);
9122  values[10] = pstrdup(buffer);
9123 
9124  /* enumvals */
9125  values[11] = NULL;
9126 
9127  /* boot_val */
9128  snprintf(buffer, sizeof(buffer), "%g", lconf->boot_val);
9129  values[12] = pstrdup(buffer);
9130 
9131  /* reset_val */
9132  snprintf(buffer, sizeof(buffer), "%g", lconf->reset_val);
9133  values[13] = pstrdup(buffer);
9134  }
9135  break;
9136 
9137  case PGC_STRING:
9138  {
9139  struct config_string *lconf = (struct config_string *) conf;
9140 
9141  /* min_val */
9142  values[9] = NULL;
9143 
9144  /* max_val */
9145  values[10] = NULL;
9146 
9147  /* enumvals */
9148  values[11] = NULL;
9149 
9150  /* boot_val */
9151  if (lconf->boot_val == NULL)
9152  values[12] = NULL;
9153  else
9154  values[12] = pstrdup(lconf->boot_val);
9155 
9156  /* reset_val */
9157  if (lconf->reset_val == NULL)
9158  values[13] = NULL;
9159  else
9160  values[13] = pstrdup(lconf->reset_val);
9161  }
9162  break;
9163 
9164  case PGC_ENUM:
9165  {
9166  struct config_enum *lconf = (struct config_enum *) conf;
9167 
9168  /* min_val */
9169  values[9] = NULL;
9170 
9171  /* max_val */
9172  values[10] = NULL;
9173 
9174  /* enumvals */
9175 
9176  /*
9177  * NOTE! enumvals with double quotes in them are not
9178  * supported!
9179  */
9180  values[11] = config_enum_get_options((struct config_enum *) conf,
9181  "{\"", "\"}", "\",\"");
9182 
9183  /* boot_val */
9185  lconf->boot_val));
9186 
9187  /* reset_val */
9189  lconf->reset_val));
9190  }
9191  break;
9192 
9193  default:
9194  {
9195  /*
9196  * should never get here, but in case we do, set 'em to NULL
9197  */
9198 
9199  /* min_val */
9200  values[9] = NULL;
9201 
9202  /* max_val */
9203  values[10] = NULL;
9204 
9205  /* enumvals */
9206  values[11] = NULL;
9207 
9208  /* boot_val */
9209  values[12] = NULL;
9210 
9211  /* reset_val */
9212  values[13] = NULL;
9213  }
9214  break;
9215  }
9216 
9217  /*
9218  * If the setting came from a config file, set the source location. For
9219  * security reasons, we don't show source file/line number for
9220  * insufficiently-privileged users.
9221  */
9222  if (conf->source == PGC_S_FILE &&
9223  is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
9224  {
9225  values[14] = conf->sourcefile;
9226  snprintf(buffer, sizeof(buffer), "%d", conf->sourceline);
9227  values[15] = pstrdup(buffer);
9228  }
9229  else
9230  {
9231  values[14] = NULL;
9232  values[15] = NULL;
9233  }
9234 
9235  values[16] = (conf->status & GUC_PENDING_RESTART) ? "t" : "f";
9236 }
GucSource source
Definition: guc_tables.h:158
static char * _ShowOption(struct config_generic *record, bool use_units)
Definition: guc.c:9538
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:744
char * pstrdup(const char *in)
Definition: mcxt.c:1161
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:6418
#define GUC_NO_SHOW_ALL
Definition: guc.h:206
const char *const GucContext_Names[]
Definition: guc.c:594
const char *const config_group_names[]
Definition: guc.c:631
static int num_guc_variables
Definition: guc.c:4568
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:6209
static struct config_generic ** guc_variables
Definition: guc.c:4565
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:4932
char * reset_val
Definition: guc_tables.h:236
double boot_val
Definition: guc_tables.h:215
#define Assert(condition)
Definition: c.h:732
#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:610
#define snprintf
Definition: port.h:192
#define _(x)
Definition: elog.c:84
static char * config_enum_get_options(struct config_enum *record, const char *prefix, const char *suffix, const char *separator)
Definition: guc.c:6467
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 7616 of file guc.c.

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

Referenced by pg_get_functiondef().

7617 {
7618  struct config_generic *record;
7619 
7620  record = find_option(name, false, WARNING);
7621  if (record == NULL)
7622  {
7623  if (missing_ok)
7624  return 0;
7625  ereport(ERROR,
7626  (errcode(ERRCODE_UNDEFINED_OBJECT),
7627  errmsg("unrecognized configuration parameter \"%s\"",
7628  name)));
7629  }
7630  return record->flags;
7631 }
int errcode(int sqlerrcode)
Definition: elog.c:570
#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:5022
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:784

◆ GetConfigOptionResetString()

const char* GetConfigOptionResetString ( const char *  name)

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

7568 {
7569  struct config_generic *record;
7570  static char buffer[256];
7571 
7572  record = find_option(name, false, ERROR);
7573  if (record == NULL)
7574  ereport(ERROR,
7575  (errcode(ERRCODE_UNDEFINED_OBJECT),
7576  errmsg("unrecognized configuration parameter \"%s\"", name)));
7577  if ((record->flags & GUC_SUPERUSER_ONLY) &&
7578  !is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
7579  ereport(ERROR,
7580  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7581  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
7582  name)));
7583 
7584  switch (record->vartype)
7585  {
7586  case PGC_BOOL:
7587  return ((struct config_bool *) record)->reset_val ? "on" : "off";
7588 
7589  case PGC_INT:
7590  snprintf(buffer, sizeof(buffer), "%d",
7591  ((struct config_int *) record)->reset_val);
7592  return buffer;
7593 
7594  case PGC_REAL:
7595  snprintf(buffer, sizeof(buffer), "%g",
7596  ((struct config_real *) record)->reset_val);
7597  return buffer;
7598 
7599  case PGC_STRING:
7600  return ((struct config_string *) record)->reset_val;
7601 
7602  case PGC_ENUM:
7603  return config_enum_lookup_by_value((struct config_enum *) record,
7604  ((struct config_enum *) record)->reset_val);
7605  }
7606  return NULL;
7607 }
Oid GetUserId(void)
Definition: miscinit.c:380
int errcode(int sqlerrcode)
Definition: elog.c:570
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:6418
#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:4932
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:5022
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define snprintf
Definition: port.h:192

◆ GetNumConfigOptions()

int GetNumConfigOptions ( void  )

Definition at line 9242 of file guc.c.

References num_guc_variables.

Referenced by GucInfoMain(), and show_all_settings().

9243 {
9244  return num_guc_variables;
9245 }
static int num_guc_variables
Definition: guc.c:4568

◆ GetPGVariable()

void GetPGVariable ( const char *  name,
DestReceiver dest 
)

Definition at line 8738 of file guc.c.

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

Referenced by exec_replication_command(), and standard_ProcessUtility().

8739 {
8740  if (guc_name_compare(name, "all") == 0)
8741  ShowAllGUCConfig(dest);
8742  else
8743  ShowGUCConfigOption(name, dest);
8744 }
static void ShowGUCConfigOption(const char *name, DestReceiver *dest)
Definition: guc.c:8782
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:5083
static void ShowAllGUCConfig(DestReceiver *dest)
Definition: guc.c:8810
const char * name
Definition: encode.c:521

◆ GetPGVariableResultDesc()

TupleDesc GetPGVariableResultDesc ( const char *  name)

Definition at line 8747 of file guc.c.

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

Referenced by UtilityTupleDescriptor().

8748 {
8749  TupleDesc tupdesc;
8750 
8751  if (guc_name_compare(name, "all") == 0)
8752  {
8753  /* need a tuple descriptor representing three TEXT columns */
8754  tupdesc = CreateTemplateTupleDesc(3);
8755  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
8756  TEXTOID, -1, 0);
8757  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
8758  TEXTOID, -1, 0);
8759  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
8760  TEXTOID, -1, 0);
8761  }
8762  else
8763  {
8764  const char *varname;
8765 
8766  /* Get the canonical spelling of name */
8767  (void) GetConfigOptionByName(name, &varname, false);
8768 
8769  /* need a tuple descriptor representing a single TEXT column */
8770  tupdesc = CreateTemplateTupleDesc(1);
8771  TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
8772  TEXTOID, -1, 0);
8773  }
8774  return tupdesc;
8775 }
TupleDesc CreateTemplateTupleDesc(int natts)
Definition: tupdesc.c:44
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:5083
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:8977
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 10374 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().

10375 {
10376  struct config_generic *record;
10377  Datum datum;
10378  char *newval;
10379  ArrayType *a;
10380 
10381  Assert(name);
10382  Assert(value);
10383 
10384  /* test if the option is valid and we're allowed to set it */
10385  (void) validate_option_array_item(name, value, false);
10386 
10387  /* normalize name (converts obsolete GUC names to modern spellings) */
10388  record = find_option(name, false, WARNING);
10389  if (record)
10390  name = record->name;
10391 
10392  /* build new item for array */
10393  newval = psprintf("%s=%s", name, value);
10394  datum = CStringGetTextDatum(newval);
10395 
10396  if (array)
10397  {
10398  int index;
10399  bool isnull;
10400  int i;
10401 
10402  Assert(ARR_ELEMTYPE(array) == TEXTOID);
10403  Assert(ARR_NDIM(array) == 1);
10404  Assert(ARR_LBOUND(array)[0] == 1);
10405 
10406  index = ARR_DIMS(array)[0] + 1; /* add after end */
10407 
10408  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
10409  {
10410  Datum d;
10411  char *current;
10412 
10413  d = array_ref(array, 1, &i,
10414  -1 /* varlenarray */ ,
10415  -1 /* TEXT's typlen */ ,
10416  false /* TEXT's typbyval */ ,
10417  'i' /* TEXT's typalign */ ,
10418  &isnull);
10419  if (isnull)
10420  continue;
10421  current = TextDatumGetCString(d);
10422 
10423  /* check for match up through and including '=' */
10424  if (strncmp(current, newval, strlen(name) + 1) == 0)
10425  {
10426  index = i;
10427  break;
10428  }
10429  }
10430 
10431  a = array_set(array, 1, &index,
10432  datum,
10433  false,
10434  -1 /* varlena array */ ,
10435  -1 /* TEXT's typlen */ ,
10436  false /* TEXT's typbyval */ ,
10437  'i' /* TEXT's typalign */ );
10438  }
10439  else
10440  a = construct_array(&datum, 1,
10441  TEXTOID,
10442  -1, false, 'i');
10443 
10444  return a;
10445 }
const char * name
Definition: guc_tables.h:149
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
static struct @144 value
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c: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
#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:10600
#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:5022
#define Assert(condition)
Definition: c.h:732
#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 10454 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().

10455 {
10456  struct config_generic *record;
10457  ArrayType *newarray;
10458  int i;
10459  int index;
10460 
10461  Assert(name);
10462 
10463  /* test if the option is valid and we're allowed to set it */
10464  (void) validate_option_array_item(name, NULL, false);
10465 
10466  /* normalize name (converts obsolete GUC names to modern spellings) */
10467  record = find_option(name, false, WARNING);
10468  if (record)
10469  name = record->name;
10470 
10471  /* if array is currently null, then surely nothing to delete */
10472  if (!array)
10473  return NULL;
10474 
10475  newarray = NULL;
10476  index = 1;
10477 
10478  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
10479  {
10480  Datum d;
10481  char *val;
10482  bool isnull;
10483 
10484  d = array_ref(array, 1, &i,
10485  -1 /* varlenarray */ ,
10486  -1 /* TEXT's typlen */ ,
10487  false /* TEXT's typbyval */ ,
10488  'i' /* TEXT's typalign */ ,
10489  &isnull);
10490  if (isnull)
10491  continue;
10492  val = TextDatumGetCString(d);
10493 
10494  /* ignore entry if it's what we want to delete */
10495  if (strncmp(val, name, strlen(name)) == 0
10496  && val[strlen(name)] == '=')
10497  continue;
10498 
10499  /* else add it to the output array */
10500  if (newarray)
10501  newarray = array_set(newarray, 1, &index,
10502  d,
10503  false,
10504  -1 /* varlenarray */ ,
10505  -1 /* TEXT's typlen */ ,
10506  false /* TEXT's typbyval */ ,
10507  'i' /* TEXT's typalign */ );
10508  else
10509  newarray = construct_array(&d, 1,
10510  TEXTOID,
10511  -1, false, 'i');
10512 
10513  index++;
10514  }
10515 
10516  return newarray;
10517 }
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:10600
#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:5022
#define Assert(condition)
Definition: c.h:732
const char * name
Definition: encode.c:521
int i
long val
Definition: informix.c:684

◆ GUCArrayReset()

ArrayType* GUCArrayReset ( ArrayType array)

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

10527 {
10528  ArrayType *newarray;
10529  int i;
10530  int index;
10531 
10532  /* if array is currently null, nothing to do */
10533  if (!array)
10534  return NULL;
10535 
10536  /* if we're superuser, we can delete everything, so just do it */
10537  if (superuser())
10538  return NULL;
10539 
10540  newarray = NULL;
10541  index = 1;
10542 
10543  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
10544  {
10545  Datum d;
10546  char *val;
10547  char *eqsgn;
10548  bool isnull;
10549 
10550  d = array_ref(array, 1, &i,
10551  -1 /* varlenarray */ ,
10552  -1 /* TEXT's typlen */ ,
10553  false /* TEXT's typbyval */ ,
10554  'i' /* TEXT's typalign */ ,
10555  &isnull);
10556  if (isnull)
10557  continue;
10558  val = TextDatumGetCString(d);
10559 
10560  eqsgn = strchr(val, '=');
10561  *eqsgn = '\0';
10562 
10563  /* skip if we have permission to delete it */
10564  if (validate_option_array_item(val, NULL, true))
10565  continue;
10566 
10567  /* else add it to the output array */
10568  if (newarray)
10569  newarray = array_set(newarray, 1, &index,
10570  d,
10571  false,
10572  -1 /* varlenarray */ ,
10573  -1 /* TEXT's typlen */ ,
10574  false /* TEXT's typbyval */ ,
10575  'i' /* TEXT's typalign */ );
10576  else
10577  newarray = construct_array(&d, 1,
10578  TEXTOID,
10579  -1, false, 'i');
10580 
10581  index++;
10582  pfree(val);
10583  }
10584 
10585  return newarray;
10586 }
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:47
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:1031
static bool validate_option_array_item(const char *name, const char *value, bool skipIfNoPermissions)
Definition: guc.c:10600
#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:684

◆ InitializeGUCOptions()

void InitializeGUCOptions ( void  )

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

5118 {
5119  int i;
5120 
5121  /*
5122  * Before log_line_prefix could possibly receive a nonempty setting, make
5123  * sure that timezone processing is minimally alive (see elog.c).
5124  */
5126 
5127  /*
5128  * Build sorted array of all GUC variables.
5129  */
5131 
5132  /*
5133  * Load all variables with their compiled-in defaults, and initialize
5134  * status fields as needed.
5135  */
5136  for (i = 0; i < num_guc_variables; i++)
5137  {
5139  }
5140 
5141  guc_dirty = false;
5142 
5143  reporting_enabled = false;
5144 
5145  /*
5146  * Prevent any attempt to override the transaction modes from
5147  * non-interactive sources.
5148  */
5149  SetConfigOption("transaction_isolation", "read committed",
5151  SetConfigOption("transaction_read_only", "no",
5153  SetConfigOption("transaction_deferrable", "no",
5155 
5156  /*
5157  * For historical reasons, some GUC parameters can receive defaults from
5158  * environment variables. Process those settings.
5159  */
5161 }
void build_guc_variables(void)
Definition: guc.c:4832
static void InitializeGUCOptionsFromEnvironment(void)
Definition: guc.c:5173
void pg_timezone_initialize(void)
Definition: pgtz.c:363
static int num_guc_variables
Definition: guc.c:4568
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:7487
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:5219
static struct config_generic ** guc_variables
Definition: guc.c:4565
int i
static bool reporting_enabled
Definition: guc.c:4579
static bool guc_dirty
Definition: guc.c:4577

◆ NewGUCNestLevel()

◆ parse_int()

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

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

6267 {
6268  /*
6269  * We assume here that double is wide enough to represent any integer
6270  * value with adequate precision.
6271  */
6272  double val;
6273  char *endptr;
6274 
6275  /* To suppress compiler warnings, always set output params */
6276  if (result)
6277  *result = 0;
6278  if (hintmsg)
6279  *hintmsg = NULL;
6280 
6281  /*
6282  * Try to parse as an integer (allowing octal or hex input). If the
6283  * conversion stops at a decimal point or 'e', or overflows, re-parse as
6284  * float. This should work fine as long as we have no unit names starting
6285  * with 'e'. If we ever do, the test could be extended to check for a
6286  * sign or digit after 'e', but for now that's unnecessary.
6287  */
6288  errno = 0;
6289  val = strtol(value, &endptr, 0);
6290  if (*endptr == '.' || *endptr == 'e' || *endptr == 'E' ||
6291  errno == ERANGE)
6292  {
6293  errno = 0;
6294  val = strtod(value, &endptr);
6295  }
6296 
6297  if (endptr == value || errno == ERANGE)
6298  return false; /* no HINT for these cases */
6299 
6300  /* reject NaN (infinities will fail range check below) */
6301  if (isnan(val))
6302  return false; /* treat same as syntax error; no HINT */
6303 
6304  /* allow whitespace between number and unit */
6305  while (isspace((unsigned char) *endptr))
6306  endptr++;
6307 
6308  /* Handle possible unit */
6309  if (*endptr != '\0')
6310  {
6311  if ((flags & GUC_UNIT) == 0)
6312  return false; /* this setting does not accept a unit */
6313 
6314  if (!convert_to_base_unit(val,
6315  endptr, (flags & GUC_UNIT),
6316  &val))
6317  {
6318  /* invalid unit, or garbage after the unit; set hint and fail. */
6319  if (hintmsg)
6320  {
6321  if (flags & GUC_UNIT_MEMORY)
6322  *hintmsg = memory_units_hint;
6323  else
6324  *hintmsg = time_units_hint;
6325  }
6326  return false;
6327  }
6328  }
6329 
6330  /* Round to int, then check for overflow */
6331  val = rint(val);
6332 
6333  if (val > INT_MAX || val < INT_MIN)
6334  {
6335  if (hintmsg)
6336  *hintmsg = gettext_noop("Value exceeds integer range.");
6337  return false;
6338  }
6339 
6340  if (result)
6341  *result = (int) val;
6342  return true;
6343 }
static struct @144 value
#define gettext_noop(x)
Definition: c.h:1117
#define GUC_UNIT
Definition: guc.h:232
double rint(double x)
Definition: rint.c:21
static const char * time_units_hint
Definition: guc.c:823
static bool convert_to_base_unit(double value, const char *unit, int base_unit, double *base_value)
Definition: guc.c:6066
long val
Definition: informix.c:684
static const char * memory_units_hint
Definition: guc.c:786
#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 6356 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().

6357 {
6358  double val;
6359  char *endptr;
6360 
6361  /* To suppress compiler warnings, always set output params */
6362  if (result)
6363  *result = 0;
6364  if (hintmsg)
6365  *hintmsg = NULL;
6366 
6367  errno = 0;
6368  val = strtod(value, &endptr);
6369 
6370  if (endptr == value || errno == ERANGE)
6371  return false; /* no HINT for these cases */
6372 
6373  /* reject NaN (infinities will fail range checks later) */
6374  if (isnan(val))
6375  return false; /* treat same as syntax error; no HINT */
6376 
6377  /* allow whitespace between number and unit */
6378  while (isspace((unsigned char) *endptr))
6379  endptr++;
6380 
6381  /* Handle possible unit */
6382  if (*endptr != '\0')
6383  {
6384  if ((flags & GUC_UNIT) == 0)
6385  return false; /* this setting does not accept a unit */
6386 
6387  if (!convert_to_base_unit(val,
6388  endptr, (flags & GUC_UNIT),
6389  &val))
6390  {
6391  /* invalid unit, or garbage after the unit; set hint and fail. */
6392  if (hintmsg)
6393  {
6394  if (flags & GUC_UNIT_MEMORY)
6395  *hintmsg = memory_units_hint;
6396  else
6397  *hintmsg = time_units_hint;
6398  }
6399  return false;
6400  }
6401  }
6402 
6403  if (result)
6404  *result = val;
6405  return true;
6406 }
static struct @144 value
#define GUC_UNIT
Definition: guc.h:232
static const char * time_units_hint
Definition: guc.c:823
static bool convert_to_base_unit(double value, const char *unit, int base_unit, double *base_value)
Definition: guc.c:6066
long val
Definition: informix.c:684
static const char * memory_units_hint
Definition: guc.c:786
#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 10278 of file guc.c.

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

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

10279 {
10280  size_t equal_pos;
10281  char *cp;
10282 
10283  AssertArg(string);
10284  AssertArg(name);
10285  AssertArg(value);
10286 
10287  equal_pos = strcspn(string, "=");
10288 
10289  if (string[equal_pos] == '=')
10290  {
10291  *name = guc_malloc(FATAL, equal_pos + 1);
10292  strlcpy(*name, string, equal_pos + 1);
10293 
10294  *value = guc_strdup(FATAL, &string[equal_pos + 1]);
10295  }
10296  else
10297  {
10298  /* no equal sign in string */
10299  *name = guc_strdup(FATAL, string);
10300  *value = NULL;
10301  }
10302 
10303  for (cp = *name; *cp; cp++)
10304  if (*cp == '-')
10305  *cp = '_';
10306 }
static struct @144 value
static char * guc_strdup(int elevel, const char *src)
Definition: guc.c:4641
#define FATAL
Definition: elog.h:52
#define AssertArg(condition)
Definition: c.h:734
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:4609

◆ ProcessConfigFile()

◆ ProcessGUCArray()

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

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

10318 {
10319  int i;
10320 
10321  Assert(array != NULL);
10322  Assert(ARR_ELEMTYPE(array) == TEXTOID);
10323  Assert(ARR_NDIM(array) == 1);
10324  Assert(ARR_LBOUND(array)[0] == 1);
10325 
10326  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
10327  {
10328  Datum d;
10329  bool isnull;
10330  char *s;
10331  char *name;
10332  char *value;
10333 
10334  d = array_ref(array, 1, &i,
10335  -1 /* varlenarray */ ,
10336  -1 /* TEXT's typlen */ ,
10337  false /* TEXT's typbyval */ ,
10338  'i' /* TEXT's typalign */ ,
10339  &isnull);
10340 
10341  if (isnull)
10342  continue;
10343 
10344  s = TextDatumGetCString(d);
10345 
10346  ParseLongOption(s, &name, &value);
10347  if (!value)
10348  {
10349  ereport(WARNING,
10350  (errcode(ERRCODE_SYNTAX_ERROR),
10351  errmsg("could not parse setting for parameter \"%s\"",
10352  name)));
10353  free(name);
10354  continue;
10355  }
10356 
10357  (void) set_config_option(name, value,
10358  context, source,
10359  action, true, 0, false);
10360 
10361  free(name);
10362  if (value)
10363  free(value);
10364  pfree(s);
10365  }
10366 }
GucSource source
Definition: guc_tables.h:158
void ParseLongOption(const char *string, char **name, char **value)
Definition: guc.c:10278
static struct @144 value
int errcode(int sqlerrcode)
Definition: elog.c:570
#define ARR_LBOUND(a)
Definition: array.h:284
void pfree(void *pointer)
Definition: mcxt.c:1031
#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:732
#define ARR_NDIM(a)
Definition: array.h:278
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:784
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:6722
#define ARR_ELEMTYPE(a)
Definition: array.h:280
GucContext context
Definition: guc_tables.h:150

◆ ResetAllOptions()

void ResetAllOptions ( void  )

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

5515 {
5516  int i;
5517 
5518  for (i = 0; i < num_guc_variables; i++)
5519  {
5520  struct config_generic *gconf = guc_variables[i];
5521 
5522  /* Don't reset non-SET-able values */
5523  if (gconf->context != PGC_SUSET &&
5524  gconf->context != PGC_USERSET)
5525  continue;
5526  /* Don't reset if special exclusion from RESET ALL */
5527  if (gconf->flags & GUC_NO_RESET_ALL)
5528  continue;
5529  /* No need to reset if wasn't SET */
5530  if (gconf->source <= PGC_S_OVERRIDE)
5531  continue;
5532 
5533  /* Save old value to support transaction abort */
5535 
5536  switch (gconf->vartype)
5537  {
5538  case PGC_BOOL:
5539  {
5540  struct config_bool *conf = (struct config_bool *) gconf;
5541 
5542  if (conf->assign_hook)
5543  conf->assign_hook(conf->reset_val,
5544  conf->reset_extra);
5545  *conf->variable = conf->reset_val;
5546  set_extra_field(&conf->gen, &conf->gen.extra,
5547  conf->reset_extra);
5548  break;
5549  }
5550  case PGC_INT:
5551  {
5552  struct config_int *conf = (struct config_int *) gconf;
5553 
5554  if (conf->assign_hook)
5555  conf->assign_hook(conf->reset_val,
5556  conf->reset_extra);
5557  *conf->variable = conf->reset_val;
5558  set_extra_field(&conf->gen, &conf->gen.extra,
5559  conf->reset_extra);
5560  break;
5561  }
5562  case PGC_REAL:
5563  {
5564  struct config_real *conf = (struct config_real *) gconf;
5565 
5566  if (conf->assign_hook)
5567  conf->assign_hook(conf->reset_val,
5568  conf->reset_extra);
5569  *conf->variable = conf->reset_val;
5570  set_extra_field(&conf->gen, &conf->gen.extra,
5571  conf->reset_extra);
5572  break;
5573  }
5574  case PGC_STRING:
5575  {
5576  struct config_string *conf = (struct config_string *) gconf;
5577 
5578  if (conf->assign_hook)
5579  conf->assign_hook(conf->reset_val,
5580  conf->reset_extra);
5581  set_string_field(conf, conf->variable, conf->reset_val);
5582  set_extra_field(&conf->gen, &conf->gen.extra,
5583  conf->reset_extra);
5584  break;
5585  }
5586  case PGC_ENUM:
5587  {
5588  struct config_enum *conf = (struct config_enum *) gconf;
5589 
5590  if (conf->assign_hook)
5591  conf->assign_hook(conf->reset_val,
5592  conf->reset_extra);
5593  *conf->variable = conf->reset_val;
5594  set_extra_field(&conf->gen, &conf->gen.extra,
5595  conf->reset_extra);
5596  break;
5597  }
5598  }
5599 
5600  gconf->source = gconf->reset_source;
5601  gconf->scontext = gconf->reset_scontext;
5602 
5603  if (gconf->flags & GUC_REPORT)
5604  ReportGUCOption(gconf);
5605  }
5606 }
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:5614
int * variable
Definition: guc_tables.h:198
int * variable
Definition: guc_tables.h:244
static int num_guc_variables
Definition: guc.c:4568
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:4742
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:4681
static struct config_generic ** guc_variables
Definition: guc.c:4565
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:6039
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 10218 of file guc.c.

References can_skip_gucvar(), ereport, errcode(), errmsg(), ERROR, GUC_ACTION_SET, i, InitializeOneGUCOption(), num_guc_variables, read_gucstate(), read_gucstate_binary(), set_config_option(), and set_config_sourcefile().

Referenced by ParallelWorkerMain().

10219 {
10220  char *varname,
10221  *varvalue,
10222  *varsourcefile;
10223  int varsourceline;
10224  GucSource varsource;
10225  GucContext varscontext;
10226  char *srcptr = (char *) gucstate;
10227  char *srcend;
10228  Size len;
10229  int i;
10230 
10231  /* See comment at can_skip_gucvar(). */
10232  for (i = 0; i < num_guc_variables; i++)
10233  if (!can_skip_gucvar(guc_variables[i]))
10235 
10236  /* First item is the length of the subsequent data */
10237  memcpy(&len, gucstate, sizeof(len));
10238 
10239  srcptr += sizeof(len);
10240  srcend = srcptr + len;
10241 
10242  while (srcptr < srcend)
10243  {
10244  int result;
10245 
10246  varname = read_gucstate(&srcptr, srcend);
10247  varvalue = read_gucstate(&srcptr, srcend);
10248  varsourcefile = read_gucstate(&srcptr, srcend);
10249  if (varsourcefile[0])
10250  read_gucstate_binary(&srcptr, srcend,
10251  &varsourceline, sizeof(varsourceline));
10252  else
10253  varsourceline = 0;
10254  read_gucstate_binary(&srcptr, srcend,
10255  &varsource, sizeof(varsource));
10256  read_gucstate_binary(&srcptr, srcend,
10257  &varscontext, sizeof(varscontext));
10258 
10259  result = set_config_option(varname, varvalue, varscontext, varsource,
10260  GUC_ACTION_SET, true, ERROR, true);
10261  if (result <= 0)
10262  ereport(ERROR,
10263  (errcode(ERRCODE_INTERNAL_ERROR),
10264  errmsg("parameter \"%s\" could not be set", varname)));
10265  if (varsourcefile[0])
10266  set_config_sourcefile(varname, varsourcefile, varsourceline);
10267  }
10268 }
GucContext
Definition: guc.h:68
static void static void set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
Definition: guc.c:7453
static void read_gucstate_binary(char **srcptr, char *srcend, void *dest, Size size)
Definition: guc.c:10203
int errcode(int sqlerrcode)
Definition: elog.c:570
GucSource
Definition: guc.h:105
#define ERROR
Definition: elog.h:43
static int num_guc_variables
Definition: guc.c:4568
static bool can_skip_gucvar(struct config_generic *gconf)
Definition: guc.c:9899
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:5219
#define ereport(elevel, rest)
Definition: elog.h:141
static struct config_generic ** guc_variables
Definition: guc.c:4565
static char * read_gucstate(char **srcptr, char *srcend)
Definition: guc.c:10180
size_t Size
Definition: c.h:466
int errmsg(const char *fmt,...)
Definition: elog.c:784
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:6722

◆ SelectConfigFiles()

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

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

5340 {
5341  char *configdir;
5342  char *fname;
5343  struct stat stat_buf;
5344 
5345  /* configdir is -D option, or $PGDATA if no -D */
5346  if (userDoption)
5347  configdir = make_absolute_path(userDoption);
5348  else
5349  configdir = make_absolute_path(getenv("PGDATA"));
5350 
5351  if (configdir && stat(configdir, &stat_buf) != 0)
5352  {
5353  write_stderr("%s: could not access directory \"%s\": %s\n",
5354  progname,
5355  configdir,
5356  strerror(errno));
5357  if (errno == ENOENT)
5358  write_stderr("Run initdb or pg_basebackup to initialize a PostgreSQL data directory.\n");
5359  return false;
5360  }
5361 
5362  /*
5363  * Find the configuration file: if config_file was specified on the
5364  * command line, use it, else use configdir/postgresql.conf. In any case
5365  * ensure the result is an absolute path, so that it will be interpreted
5366  * the same way by future backends.
5367  */
5368  if (ConfigFileName)
5370  else if (configdir)
5371  {
5372  fname = guc_malloc(FATAL,
5373  strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
5374  sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
5375  }
5376  else
5377  {
5378  write_stderr("%s does not know where to find the server configuration file.\n"
5379  "You must specify the --config-file or -D invocation "
5380  "option or set the PGDATA environment variable.\n",
5381  progname);
5382  return false;
5383  }
5384 
5385  /*
5386  * Set the ConfigFileName GUC variable to its final value, ensuring that
5387  * it can't be overridden later.
5388  */
5389  SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
5390  free(fname);
5391 
5392  /*
5393  * Now read the config file for the first time.
5394  */
5395  if (stat(ConfigFileName, &stat_buf) != 0)
5396  {
5397  write_stderr("%s: could not access the server configuration file \"%s\": %s\n",
5398  progname, ConfigFileName, strerror(errno));
5399  free(configdir);
5400  return false;
5401  }
5402 
5403  /*
5404  * Read the configuration file for the first time. This time only the
5405  * data_directory parameter is picked up to determine the data directory,
5406  * so that we can read the PG_AUTOCONF_FILENAME file next time.
5407  */
5409 
5410  /*
5411  * If the data_directory GUC variable has been set, use that as DataDir;
5412  * otherwise use configdir if set; else punt.
5413  *
5414  * Note: SetDataDir will copy and absolute-ize its argument, so we don't
5415  * have to.
5416  */
5417  if (data_directory)
5419  else if (configdir)
5420  SetDataDir(configdir);
5421  else
5422  {
5423  write_stderr("%s does not know where to find the database system data.\n"
5424  "This can be specified as \"data_directory\" in \"%s\", "
5425  "or by the -D invocation option, or by the "
5426  "PGDATA environment variable.\n",
5428  return false;
5429  }
5430 
5431  /*
5432  * Reflect the final DataDir value back into the data_directory GUC var.
5433  * (If you are wondering why we don't just make them a single variable,
5434  * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
5435  * child backends specially. XXX is that still true? Given that we now
5436  * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
5437  * DataDir in advance.)
5438  */
5440 
5441  /*
5442  * Now read the config file a second time, allowing any settings in the
5443  * PG_AUTOCONF_FILENAME file to take effect. (This is pretty ugly, but
5444  * since we have to determine the DataDir before we can find the autoconf
5445  * file, the alternatives seem worse.)
5446  */
5448 
5449  /*
5450  * If timezone_abbreviations wasn't set in the configuration file, install
5451  * the default value. We do it this way because we can't safely install a
5452  * "real" value until my_exec_path is set, which may not have happened
5453  * when InitializeGUCOptions runs, so the bootstrap default value cannot
5454  * be the real desired default.
5455  */
5457 
5458  /*
5459  * Figure out where pg_hba.conf is, and make sure the path is absolute.
5460  */
5461  if (HbaFileName)
5463  else if (configdir)
5464  {
5465  fname = guc_malloc(FATAL,
5466  strlen(configdir) + strlen(HBA_FILENAME) + 2);
5467  sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
5468  }
5469  else
5470  {
5471  write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
5472  "This can be specified as \"hba_file\" in \"%s\", "
5473  "or by the -D invocation option, or by the "
5474  "PGDATA environment variable.\n",
5476  return false;
5477  }
5478  SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
5479  free(fname);
5480 
5481  /*
5482  * Likewise for pg_ident.conf.
5483  */
5484  if (IdentFileName)
5486  else if (configdir)
5487  {
5488  fname = guc_malloc(FATAL,
5489  strlen(configdir) + strlen(IDENT_FILENAME) + 2);
5490  sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
5491  }
5492  else
5493  {
5494  write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
5495  "This can be specified as \"ident_file\" in \"%s\", "
5496  "or by the -D invocation option, or by the "
5497  "PGDATA environment variable.\n",
5499  return false;
5500  }
5501  SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
5502  free(fname);
5503 
5504  free(configdir);
5505 
5506  return true;
5507 }
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:522
static void pg_timezone_abbrev_initialize(void)
Definition: guc.c:11168
#define CONFIG_FILENAME
Definition: guc.c:103
#define write_stderr(str)
Definition: parallel.c:182
const char * progname
Definition: pg_standby.c:37
char * HbaFileName
Definition: guc.c:523
#define sprintf
Definition: port.h:194
#define HBA_FILENAME
Definition: guc.c:104
struct stat stat_buf
Definition: pg_standby.c:101
#define FATAL
Definition: elog.h:52
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:7487
char * IdentFileName
Definition: guc.c:524
#define stat(a, b)
Definition: win32_port.h:264
#define IDENT_FILENAME
Definition: guc.c:105
#define free(a)
Definition: header.h:65
#define strerror
Definition: port.h:205
static const char * userDoption
Definition: postgres.c:161
char * DataDir
Definition: globals.c:62
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4609
static char * data_directory
Definition: guc.c:567

◆ SerializeGUCState()

void SerializeGUCState ( Size  maxsize,
char *  start_address 
)

Definition at line 10153 of file guc.c.

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

Referenced by InitializeParallelDSM().

10154 {
10155  char *curptr;
10156  Size actual_size;
10157  Size bytes_left;
10158  int i;
10159 
10160  /* Reserve space for saving the actual size of the guc state */
10161  Assert(maxsize > sizeof(actual_size));
10162  curptr = start_address + sizeof(actual_size);
10163  bytes_left = maxsize - sizeof(actual_size);
10164 
10165  for (i = 0; i < num_guc_variables; i++)
10166  serialize_variable(&curptr, &bytes_left, guc_variables[i]);
10167 
10168  /* Store actual size without assuming alignment of start_address. */
10169  actual_size = maxsize - bytes_left - sizeof(actual_size);
10170  memcpy(start_address, &actual_size, sizeof(actual_size));
10171 }
static void serialize_variable(char **destptr, Size *maxbytes, struct config_generic *gconf)
Definition: guc.c:10079
static int num_guc_variables
Definition: guc.c:4568
static struct config_generic ** guc_variables
Definition: guc.c:4565
#define Assert(condition)
Definition: c.h:732
size_t Size
Definition: c.h:466
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 6722 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().

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