PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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_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_superuser)
 
const char * GetConfigOptionResetString (const char *name)
 
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 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 *setstmt)
 
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 default_with_oids
 
int log_min_error_statement
 
int log_min_messages
 
int client_min_messages
 
int log_min_duration_statement
 
int log_temp_files
 
int temp_file_limit
 
int num_temp_buffers
 
char * cluster_name
 
char * ConfigFileName
 
char * HbaFileName
 
char * IdentFileName
 
char * external_pid_file
 
char * application_name
 
int tcp_keepalives_idle
 
int tcp_keepalives_interval
 
int tcp_keepalives_count
 
PGDLLIMPORT char * GUC_check_errmsg_string
 
PGDLLIMPORT char * GUC_check_errdetail_string
 
PGDLLIMPORT char * GUC_check_errhint_string
 

Macro Definition Documentation

#define GUC_check_errhint
Value:
#define TEXTDOMAIN
Definition: elog.h:125
PGDLLIMPORT char * GUC_check_errhint_string
Definition: guc.c:133
char * format_elog_string(const char *fmt,...)
Definition: elog.c:1413
void pre_format_elog_string(int errnumber, const char *domain)
Definition: elog.c:1404

Definition at line 412 of file guc.h.

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

#define GUC_check_errmsg
#define GUC_CUSTOM_PLACEHOLDER   0x0080 /* placeholder for custom variable */
#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().

#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().

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

Definition at line 213 of file guc.h.

Referenced by parse_and_validate_value().

#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().

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

Definition at line 205 of file guc.h.

Referenced by flatten_set_variable_args().

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

Definition at line 207 of file guc.h.

Referenced by ResetAllOptions().

#define GUC_NO_SHOW_ALL   0x0004 /* exclude from SHOW ALL */
#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().

#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().

#define GUC_QUALIFIER_SEPARATOR   '.'

Definition at line 199 of file guc.h.

Referenced by EmitWarningsOnPlaceholders(), and find_option().

#define GUC_REPORT   0x0010 /* auto-report changes to client */
#define GUC_SUPERUSER_ONLY   0x0100 /* show only to superusers */
#define GUC_UNIT   (GUC_UNIT_MEMORY | GUC_UNIT_TIME)

Definition at line 230 of file guc.h.

Referenced by _ShowOption(), and parse_int().

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

Definition at line 219 of file guc.h.

Referenced by GetConfigOptionByNum().

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

Definition at line 222 of file guc.h.

Referenced by GetConfigOptionByNum().

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

Definition at line 218 of file guc.h.

Referenced by GetConfigOptionByNum().

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

Definition at line 221 of file guc.h.

Referenced by GetConfigOptionByNum().

#define GUC_UNIT_MEMORY   0xF000 /* mask for size-related units */
#define GUC_UNIT_MIN   0x30000 /* value is in minutes */

Definition at line 227 of file guc.h.

Referenced by GetConfigOptionByNum().

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

Definition at line 225 of file guc.h.

Referenced by _PG_init(), GetConfigOptionByNum(), and readRecoveryCommandFile().

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

Definition at line 226 of file guc.h.

Referenced by _PG_init(), and GetConfigOptionByNum().

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

Definition at line 228 of file guc.h.

Referenced by GetConfigOptionByNum().

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

Definition at line 220 of file guc.h.

Referenced by GetConfigOptionByNum().

#define MAX_KILOBYTES   (INT_MAX / 1024)

Definition at line 26 of file guc.h.

#define PG_AUTOCONF_FILENAME   "postgresql.auto.conf"

Definition at line 34 of file guc.h.

Referenced by AlterSystemSetConfigFile().

Typedef Documentation

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

Definition at line 180 of file guc.h.

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

Definition at line 174 of file guc.h.

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

Definition at line 184 of file guc.h.

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

Definition at line 178 of file guc.h.

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

Definition at line 181 of file guc.h.

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

Definition at line 175 of file guc.h.

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

Definition at line 182 of file guc.h.

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

Definition at line 176 of file guc.h.

typedef const char*(* GucShowHook)(void)

Definition at line 186 of file guc.h.

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

Definition at line 183 of file guc.h.

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

Definition at line 177 of file guc.h.

Enumeration Type Documentation

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
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
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

void AlterSystemSetConfigFile ( AlterSystemStmt setstmt)

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

7080 {
7081  char *name;
7082  char *value;
7083  bool resetall = false;
7084  ConfigVariable *head = NULL;
7085  ConfigVariable *tail = NULL;
7086  volatile int Tmpfd;
7087  char AutoConfFileName[MAXPGPATH];
7088  char AutoConfTmpFileName[MAXPGPATH];
7089 
7090  if (!superuser())
7091  ereport(ERROR,
7092  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7093  (errmsg("must be superuser to execute ALTER SYSTEM command"))));
7094 
7095  /*
7096  * Extract statement arguments
7097  */
7098  name = altersysstmt->setstmt->name;
7099 
7100  switch (altersysstmt->setstmt->kind)
7101  {
7102  case VAR_SET_VALUE:
7103  value = ExtractSetVariableArgs(altersysstmt->setstmt);
7104  break;
7105 
7106  case VAR_SET_DEFAULT:
7107  case VAR_RESET:
7108  value = NULL;
7109  break;
7110 
7111  case VAR_RESET_ALL:
7112  value = NULL;
7113  resetall = true;
7114  break;
7115 
7116  default:
7117  elog(ERROR, "unrecognized alter system stmt type: %d",
7118  altersysstmt->setstmt->kind);
7119  break;
7120  }
7121 
7122  /*
7123  * Unless it's RESET_ALL, validate the target variable and value
7124  */
7125  if (!resetall)
7126  {
7127  struct config_generic *record;
7128 
7129  record = find_option(name, false, ERROR);
7130  if (record == NULL)
7131  ereport(ERROR,
7132  (errcode(ERRCODE_UNDEFINED_OBJECT),
7133  errmsg("unrecognized configuration parameter \"%s\"",
7134  name)));
7135 
7136  /*
7137  * Don't allow parameters that can't be set in configuration files to
7138  * be set in PG_AUTOCONF_FILENAME file.
7139  */
7140  if ((record->context == PGC_INTERNAL) ||
7141  (record->flags & GUC_DISALLOW_IN_FILE) ||
7142  (record->flags & GUC_DISALLOW_IN_AUTO_FILE))
7143  ereport(ERROR,
7144  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
7145  errmsg("parameter \"%s\" cannot be changed",
7146  name)));
7147 
7148  /*
7149  * If a value is specified, verify that it's sane.
7150  */
7151  if (value)
7152  {
7153  union config_var_val newval;
7154  void *newextra = NULL;
7155 
7156  /* Check that it's acceptable for the indicated parameter */
7157  if (!parse_and_validate_value(record, name, value,
7158  PGC_S_FILE, ERROR,
7159  &newval, &newextra))
7160  ereport(ERROR,
7161  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7162  errmsg("invalid value for parameter \"%s\": \"%s\"",
7163  name, value)));
7164 
7165  if (record->vartype == PGC_STRING && newval.stringval != NULL)
7166  free(newval.stringval);
7167  if (newextra)
7168  free(newextra);
7169 
7170  /*
7171  * We must also reject values containing newlines, because the
7172  * grammar for config files doesn't support embedded newlines in
7173  * string literals.
7174  */
7175  if (strchr(value, '\n'))
7176  ereport(ERROR,
7177  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7178  errmsg("parameter value for ALTER SYSTEM must not contain a newline")));
7179  }
7180  }
7181 
7182  /*
7183  * PG_AUTOCONF_FILENAME and its corresponding temporary file are always in
7184  * the data directory, so we can reference them by simple relative paths.
7185  */
7186  snprintf(AutoConfFileName, sizeof(AutoConfFileName), "%s",
7188  snprintf(AutoConfTmpFileName, sizeof(AutoConfTmpFileName), "%s.%s",
7189  AutoConfFileName,
7190  "tmp");
7191 
7192  /*
7193  * Only one backend is allowed to operate on PG_AUTOCONF_FILENAME at a
7194  * time. Use AutoFileLock to ensure that. We must hold the lock while
7195  * reading the old file contents.
7196  */
7197  LWLockAcquire(AutoFileLock, LW_EXCLUSIVE);
7198 
7199  /*
7200  * If we're going to reset everything, then no need to open or parse the
7201  * old file. We'll just write out an empty list.
7202  */
7203  if (!resetall)
7204  {
7205  struct stat st;
7206 
7207  if (stat(AutoConfFileName, &st) == 0)
7208  {
7209  /* open old file PG_AUTOCONF_FILENAME */
7210  FILE *infile;
7211 
7212  infile = AllocateFile(AutoConfFileName, "r");
7213  if (infile == NULL)
7214  ereport(ERROR,
7216  errmsg("could not open file \"%s\": %m",
7217  AutoConfFileName)));
7218 
7219  /* parse it */
7220  if (!ParseConfigFp(infile, AutoConfFileName, 0, LOG, &head, &tail))
7221  ereport(ERROR,
7222  (errcode(ERRCODE_CONFIG_FILE_ERROR),
7223  errmsg("could not parse contents of file \"%s\"",
7224  AutoConfFileName)));
7225 
7226  FreeFile(infile);
7227  }
7228 
7229  /*
7230  * Now, replace any existing entry with the new value, or add it if
7231  * not present.
7232  */
7233  replace_auto_config_value(&head, &tail, name, value);
7234  }
7235 
7236  /*
7237  * To ensure crash safety, first write the new file data to a temp file,
7238  * then atomically rename it into place.
7239  *
7240  * If there is a temp file left over due to a previous crash, it's okay to
7241  * truncate and reuse it.
7242  */
7243  Tmpfd = BasicOpenFile(AutoConfTmpFileName,
7244  O_CREAT | O_RDWR | O_TRUNC);
7245  if (Tmpfd < 0)
7246  ereport(ERROR,
7248  errmsg("could not open file \"%s\": %m",
7249  AutoConfTmpFileName)));
7250 
7251  /*
7252  * Use a TRY block to clean up the file if we fail. Since we need a TRY
7253  * block anyway, OK to use BasicOpenFile rather than OpenTransientFile.
7254  */
7255  PG_TRY();
7256  {
7257  /* Write and sync the new contents to the temporary file */
7258  write_auto_conf_file(Tmpfd, AutoConfTmpFileName, head);
7259 
7260  /* Close before renaming; may be required on some platforms */
7261  close(Tmpfd);
7262  Tmpfd = -1;
7263 
7264  /*
7265  * As the rename is atomic operation, if any problem occurs after this
7266  * at worst it can lose the parameters set by last ALTER SYSTEM
7267  * command.
7268  */
7269  durable_rename(AutoConfTmpFileName, AutoConfFileName, ERROR);
7270  }
7271  PG_CATCH();
7272  {
7273  /* Close file first, else unlink might fail on some platforms */
7274  if (Tmpfd >= 0)
7275  close(Tmpfd);
7276 
7277  /* Unlink, but ignore any error */
7278  (void) unlink(AutoConfTmpFileName);
7279 
7280  PG_RE_THROW();
7281  }
7282  PG_END_TRY();
7283 
7284  FreeConfigVariables(head);
7285 
7286  LWLockRelease(AutoFileLock);
7287 }
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:5733
int errcode(int sqlerrcode)
Definition: elog.c:575
bool superuser(void)
Definition: superuser.c:47
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define LOG
Definition: elog.h:26
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1721
#define ERROR
Definition: elog.h:43
#define MAXPGPATH
static struct @121 value
int errcode_for_file_access(void)
Definition: elog.c:598
FILE * AllocateFile(const char *name, const char *mode)
Definition: fd.c:2117
#define ereport(elevel, rest)
Definition: elog.h:122
int durable_rename(const char *oldfile, const char *newfile, int elevel)
Definition: fd.c:598
enum config_type vartype
Definition: guc_tables.h:153
#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:6938
static void infile(const char *filename)
Definition: zic.c:1159
#define free(a)
Definition: header.h:65
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4381
#define PG_CATCH()
Definition: elog.h:293
#define newval
#define PG_AUTOCONF_FILENAME
Definition: guc.h:34
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1117
#define PG_RE_THROW()
Definition: elog.h:314
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:929
int FreeFile(FILE *file)
Definition: fd.c:2309
int errmsg(const char *fmt,...)
Definition: elog.c:797
bool ParseConfigFp(FILE *fp, const char *config_file, int depth, int elevel, ConfigVariable **head_p, ConfigVariable **tail_p)
static void replace_auto_config_value(ConfigVariable **head_p, ConfigVariable **tail_p, const char *name, const char *value)
Definition: guc.c:7006
void FreeConfigVariables(ConfigVariable *list)
#define elog
Definition: elog.h:219
#define close(a)
Definition: win32.h:12
#define PG_TRY()
Definition: elog.h:284
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
Definition: guc.c:7417
#define PG_END_TRY()
Definition: elog.h:300
GucContext context
Definition: guc_tables.h:147
void assign_search_path ( const char *  newval,
void *  extra 
)

Definition at line 4094 of file namespace.c.

References baseSearchPathValid.

4095 {
4096  /*
4097  * We mark the path as needing recomputation, but don't do anything until
4098  * it's needed. This avoids trying to do database access during GUC
4099  * initialization, or outside a transaction.
4100  */
4101  baseSearchPathValid = false;
4102 }
static bool baseSearchPathValid
Definition: namespace.c:153
void assign_temp_tablespaces ( const char *  newval,
void *  extra 
)

Definition at line 1262 of file tablespace.c.

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

1263 {
1264  temp_tablespaces_extra *myextra = (temp_tablespaces_extra *) extra;
1265 
1266  /*
1267  * If check_temp_tablespaces was executed inside a transaction, then pass
1268  * the list it made to fd.c. Otherwise, clear fd.c's list; we must be
1269  * still outside a transaction, or else restoring during transaction exit,
1270  * and in either case we can just let the next PrepareTempTablespaces call
1271  * make things sane.
1272  */
1273  if (myextra)
1274  SetTempTablespaces(myextra->tblSpcs, myextra->numSpcs);
1275  else
1276  SetTempTablespaces(NULL, 0);
1277 }
Oid tblSpcs[FLEXIBLE_ARRAY_MEMBER]
Definition: tablespace.c:1152
void SetTempTablespaces(Oid *tableSpaces, int numSpaces)
Definition: fd.c:2557
void assign_xlog_sync_method ( int  new_sync_method,
void *  extra 
)

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

10140 {
10141  if (sync_method != new_sync_method)
10142  {
10143  /*
10144  * To ensure that no blocks escape unsynced, force an fsync on the
10145  * currently open log segment (if any). Also, if the open flag is
10146  * changing, close the log file so it will be reopened (with new flag
10147  * bit) at next use.
10148  */
10149  if (openLogFile >= 0)
10150  {
10152  if (pg_fsync(openLogFile) != 0)
10153  ereport(PANIC,
10155  errmsg("could not fsync log segment %s: %m",
10158  if (get_sync_bit(sync_method) != get_sync_bit(new_sync_method))
10159  XLogFileClose();
10160  }
10161  }
10162 }
static int get_sync_bit(int method)
Definition: xlog.c:10083
#define PANIC
Definition: elog.h:53
static XLogSegNo openLogSegNo
Definition: xlog.c:775
static void XLogFileClose(void)
Definition: xlog.c:3717
char * XLogFileNameP(TimeLineID tli, XLogSegNo segno)
Definition: xlog.c:10215
int errcode_for_file_access(void)
Definition: elog.c:598
static void pgstat_report_wait_end(void)
Definition: pgstat.h:1244
#define ereport(elevel, rest)
Definition: elog.h:122
static int openLogFile
Definition: xlog.c:774
TimeLineID ThisTimeLineID
Definition: xlog.c:181
static void pgstat_report_wait_start(uint32 wait_event_info)
Definition: pgstat.h:1220
int sync_method
Definition: xlog.c:103
int errmsg(const char *fmt,...)
Definition: elog.c:797
int pg_fsync(int fd)
Definition: fd.c:338
void AtEOXact_GUC ( bool  isCommit,
int  nestLevel 
)

Definition at line 5088 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(), do_analyze_rel(), ExecCreateTableAs(), ExecRefreshMatView(), execute_extension_script(), fmgr_security_definer(), index_build(), PrepareTransaction(), ProcedureCreate(), reset_transmission_modes(), restoreLocalGucs(), RI_Initial_Check(), vacuum_rel(), and validate_index().

5089 {
5090  bool still_dirty;
5091  int i;
5092 
5093  /*
5094  * Note: it's possible to get here with GUCNestLevel == nestLevel-1 during
5095  * abort, if there is a failure during transaction start before
5096  * AtStart_GUC is called.
5097  */
5098  Assert(nestLevel > 0 &&
5099  (nestLevel <= GUCNestLevel ||
5100  (nestLevel == GUCNestLevel + 1 && !isCommit)));
5101 
5102  /* Quick exit if nothing's changed in this transaction */
5103  if (!guc_dirty)
5104  {
5105  GUCNestLevel = nestLevel - 1;
5106  return;
5107  }
5108 
5109  still_dirty = false;
5110  for (i = 0; i < num_guc_variables; i++)
5111  {
5112  struct config_generic *gconf = guc_variables[i];
5113  GucStack *stack;
5114 
5115  /*
5116  * Process and pop each stack entry within the nest level. To simplify
5117  * fmgr_security_definer() and other places that use GUC_ACTION_SAVE,
5118  * we allow failure exit from code that uses a local nest level to be
5119  * recovered at the surrounding transaction or subtransaction abort;
5120  * so there could be more than one stack entry to pop.
5121  */
5122  while ((stack = gconf->stack) != NULL &&
5123  stack->nest_level >= nestLevel)
5124  {
5125  GucStack *prev = stack->prev;
5126  bool restorePrior = false;
5127  bool restoreMasked = false;
5128  bool changed;
5129 
5130  /*
5131  * In this next bit, if we don't set either restorePrior or
5132  * restoreMasked, we must "discard" any unwanted fields of the
5133  * stack entries to avoid leaking memory. If we do set one of
5134  * those flags, unused fields will be cleaned up after restoring.
5135  */
5136  if (!isCommit) /* if abort, always restore prior value */
5137  restorePrior = true;
5138  else if (stack->state == GUC_SAVE)
5139  restorePrior = true;
5140  else if (stack->nest_level == 1)
5141  {
5142  /* transaction commit */
5143  if (stack->state == GUC_SET_LOCAL)
5144  restoreMasked = true;
5145  else if (stack->state == GUC_SET)
5146  {
5147  /* we keep the current active value */
5148  discard_stack_value(gconf, &stack->prior);
5149  }
5150  else /* must be GUC_LOCAL */
5151  restorePrior = true;
5152  }
5153  else if (prev == NULL ||
5154  prev->nest_level < stack->nest_level - 1)
5155  {
5156  /* decrement entry's level and do not pop it */
5157  stack->nest_level--;
5158  continue;
5159  }
5160  else
5161  {
5162  /*
5163  * We have to merge this stack entry into prev. See README for
5164  * discussion of this bit.
5165  */
5166  switch (stack->state)
5167  {
5168  case GUC_SAVE:
5169  Assert(false); /* can't get here */
5170 
5171  case GUC_SET:
5172  /* next level always becomes SET */
5173  discard_stack_value(gconf, &stack->prior);
5174  if (prev->state == GUC_SET_LOCAL)
5175  discard_stack_value(gconf, &prev->masked);
5176  prev->state = GUC_SET;
5177  break;
5178 
5179  case GUC_LOCAL:
5180  if (prev->state == GUC_SET)
5181  {
5182  /* LOCAL migrates down */
5183  prev->masked_scontext = stack->scontext;
5184  prev->masked = stack->prior;
5185  prev->state = GUC_SET_LOCAL;
5186  }
5187  else
5188  {
5189  /* else just forget this stack level */
5190  discard_stack_value(gconf, &stack->prior);
5191  }
5192  break;
5193 
5194  case GUC_SET_LOCAL:
5195  /* prior state at this level no longer wanted */
5196  discard_stack_value(gconf, &stack->prior);
5197  /* copy down the masked state */
5198  prev->masked_scontext = stack->masked_scontext;
5199  if (prev->state == GUC_SET_LOCAL)
5200  discard_stack_value(gconf, &prev->masked);
5201  prev->masked = stack->masked;
5202  prev->state = GUC_SET_LOCAL;
5203  break;
5204  }
5205  }
5206 
5207  changed = false;
5208 
5209  if (restorePrior || restoreMasked)
5210  {
5211  /* Perform appropriate restoration of the stacked value */
5212  config_var_value newvalue;
5213  GucSource newsource;
5214  GucContext newscontext;
5215 
5216  if (restoreMasked)
5217  {
5218  newvalue = stack->masked;
5219  newsource = PGC_S_SESSION;
5220  newscontext = stack->masked_scontext;
5221  }
5222  else
5223  {
5224  newvalue = stack->prior;
5225  newsource = stack->source;
5226  newscontext = stack->scontext;
5227  }
5228 
5229  switch (gconf->vartype)
5230  {
5231  case PGC_BOOL:
5232  {
5233  struct config_bool *conf = (struct config_bool *) gconf;
5234  bool newval = newvalue.val.boolval;
5235  void *newextra = newvalue.extra;
5236 
5237  if (*conf->variable != newval ||
5238  conf->gen.extra != newextra)
5239  {
5240  if (conf->assign_hook)
5241  conf->assign_hook(newval, newextra);
5242  *conf->variable = newval;
5243  set_extra_field(&conf->gen, &conf->gen.extra,
5244  newextra);
5245  changed = true;
5246  }
5247  break;
5248  }
5249  case PGC_INT:
5250  {
5251  struct config_int *conf = (struct config_int *) gconf;
5252  int newval = newvalue.val.intval;
5253  void *newextra = newvalue.extra;
5254 
5255  if (*conf->variable != newval ||
5256  conf->gen.extra != newextra)
5257  {
5258  if (conf->assign_hook)
5259  conf->assign_hook(newval, newextra);
5260  *conf->variable = newval;
5261  set_extra_field(&conf->gen, &conf->gen.extra,
5262  newextra);
5263  changed = true;
5264  }
5265  break;
5266  }
5267  case PGC_REAL:
5268  {
5269  struct config_real *conf = (struct config_real *) gconf;
5270  double newval = newvalue.val.realval;
5271  void *newextra = newvalue.extra;
5272 
5273  if (*conf->variable != newval ||
5274  conf->gen.extra != newextra)
5275  {
5276  if (conf->assign_hook)
5277  conf->assign_hook(newval, newextra);
5278  *conf->variable = newval;
5279  set_extra_field(&conf->gen, &conf->gen.extra,
5280  newextra);
5281  changed = true;
5282  }
5283  break;
5284  }
5285  case PGC_STRING:
5286  {
5287  struct config_string *conf = (struct config_string *) gconf;
5288  char *newval = newvalue.val.stringval;
5289  void *newextra = newvalue.extra;
5290 
5291  if (*conf->variable != newval ||
5292  conf->gen.extra != newextra)
5293  {
5294  if (conf->assign_hook)
5295  conf->assign_hook(newval, newextra);
5296  set_string_field(conf, conf->variable, newval);
5297  set_extra_field(&conf->gen, &conf->gen.extra,
5298  newextra);
5299  changed = true;
5300  }
5301 
5302  /*
5303  * Release stacked values if not used anymore. We
5304  * could use discard_stack_value() here, but since
5305  * we have type-specific code anyway, might as
5306  * well inline it.
5307  */
5308  set_string_field(conf, &stack->prior.val.stringval, NULL);
5309  set_string_field(conf, &stack->masked.val.stringval, NULL);
5310  break;
5311  }
5312  case PGC_ENUM:
5313  {
5314  struct config_enum *conf = (struct config_enum *) gconf;
5315  int newval = newvalue.val.enumval;
5316  void *newextra = newvalue.extra;
5317 
5318  if (*conf->variable != newval ||
5319  conf->gen.extra != newextra)
5320  {
5321  if (conf->assign_hook)
5322  conf->assign_hook(newval, newextra);
5323  *conf->variable = newval;
5324  set_extra_field(&conf->gen, &conf->gen.extra,
5325  newextra);
5326  changed = true;
5327  }
5328  break;
5329  }
5330  }
5331 
5332  /*
5333  * Release stacked extra values if not used anymore.
5334  */
5335  set_extra_field(gconf, &(stack->prior.extra), NULL);
5336  set_extra_field(gconf, &(stack->masked.extra), NULL);
5337 
5338  /* And restore source information */
5339  gconf->source = newsource;
5340  gconf->scontext = newscontext;
5341  }
5342 
5343  /* Finish popping the state stack */
5344  gconf->stack = prev;
5345  pfree(stack);
5346 
5347  /* Report new value if we changed it */
5348  if (changed && (gconf->flags & GUC_REPORT))
5349  ReportGUCOption(gconf);
5350  } /* end of stack-popping loop */
5351 
5352  if (stack != NULL)
5353  still_dirty = true;
5354  }
5355 
5356  /* If there are no remaining stack entries, we can reset guc_dirty */
5357  guc_dirty = still_dirty;
5358 
5359  /* Update nesting level */
5360  GUCNestLevel = nestLevel - 1;
5361 }
struct guc_stack * prev
Definition: guc_tables.h:120
GucSource source
Definition: guc_tables.h:155
GucContext
Definition: guc.h:68
union config_var_val val
Definition: guc_tables.h:46
int nest_level
Definition: guc_tables.h:121
GucRealAssignHook assign_hook
Definition: guc_tables.h:216
char ** variable
Definition: guc_tables.h:227
static int GUCNestLevel
Definition: guc.c:3957
bool * variable
Definition: guc_tables.h:181
GucEnumAssignHook assign_hook
Definition: guc_tables.h:245
GucBoolAssignHook assign_hook
Definition: guc_tables.h:184
config_var_value masked
Definition: guc_tables.h:128
GucContext scontext
Definition: guc_tables.h:157
GucIntAssignHook assign_hook
Definition: guc_tables.h:200
GucSource
Definition: guc.h:105
int * variable
Definition: guc_tables.h:195
int * variable
Definition: guc_tables.h:241
void pfree(void *pointer)
Definition: mcxt.c:949
static int num_guc_variables
Definition: guc.c:3947
static void discard_stack_value(struct config_generic *gconf, config_var_value *val)
Definition: guc.c:4172
GucSource source
Definition: guc_tables.h:123
static void set_extra_field(struct config_generic *gconf, void **field, void *newval)
Definition: guc.c:4118
struct config_generic gen
Definition: guc_tables.h:179
struct config_generic gen
Definition: guc_tables.h:193
GucContext masked_scontext
Definition: guc_tables.h:126
#define GUC_REPORT
Definition: guc.h:208
double * variable
Definition: guc_tables.h:211
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4057
static struct config_generic ** guc_variables
Definition: guc.c:3944
enum config_type vartype
Definition: guc_tables.h:153
GucContext scontext
Definition: guc_tables.h:125
struct config_generic gen
Definition: guc_tables.h:239
struct config_generic gen
Definition: guc_tables.h:225
GucStackState state
Definition: guc_tables.h:122
GucStringAssignHook assign_hook
Definition: guc_tables.h:230
#define Assert(condition)
Definition: c.h:681
#define newval
char * stringval
Definition: guc_tables.h:36
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:5397
GucStack * stack
Definition: guc_tables.h:159
double realval
Definition: guc_tables.h:35
static bool guc_dirty
Definition: guc.c:3953
config_var_value prior
Definition: guc_tables.h:127
struct config_generic gen
Definition: guc_tables.h:209
void AtStart_GUC ( void  )

Definition at line 5054 of file guc.c.

References elog, and WARNING.

Referenced by StartTransaction().

5055 {
5056  /*
5057  * The nest level should be 0 between transactions; if it isn't, somebody
5058  * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
5059  * throw a warning but make no other effort to clean up.
5060  */
5061  if (GUCNestLevel != 0)
5062  elog(WARNING, "GUC nest level = %d at transaction start",
5063  GUCNestLevel);
5064  GUCNestLevel = 1;
5065 }
static int GUCNestLevel
Definition: guc.c:3957
#define WARNING
Definition: elog.h:40
#define elog
Definition: elog.h:219
void BeginReportingGUCOptions ( void  )

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

5370 {
5371  int i;
5372 
5373  /*
5374  * Don't do anything unless talking to an interactive frontend of protocol
5375  * 3.0 or later.
5376  */
5377  if (whereToSendOutput != DestRemote ||
5379  return;
5380 
5381  reporting_enabled = true;
5382 
5383  /* Transmit initial values of interesting variables */
5384  for (i = 0; i < num_guc_variables; i++)
5385  {
5386  struct config_generic *conf = guc_variables[i];
5387 
5388  if (conf->flags & GUC_REPORT)
5389  ReportGUCOption(conf);
5390  }
5391 }
#define PG_PROTOCOL_MAJOR(v)
Definition: pqcomm.h:104
static int num_guc_variables
Definition: guc.c:3947
#define GUC_REPORT
Definition: guc.h:208
static struct config_generic ** guc_variables
Definition: guc.c:3944
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:5397
CommandDest whereToSendOutput
Definition: postgres.c:88
static bool reporting_enabled
Definition: guc.c:3955
ProtocolVersion FrontendProtocol
Definition: globals.c:27
bool check_default_tablespace ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 1062 of file tablespace.c.

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

1063 {
1064  /*
1065  * If we aren't inside a transaction, we cannot do database access so
1066  * cannot verify the name. Must accept the value on faith.
1067  */
1068  if (IsTransactionState())
1069  {
1070  if (**newval != '\0' &&
1072  {
1073  /*
1074  * When source == PGC_S_TEST, don't throw a hard error for a
1075  * nonexistent tablespace, only a NOTICE. See comments in guc.h.
1076  */
1077  if (source == PGC_S_TEST)
1078  {
1079  ereport(NOTICE,
1080  (errcode(ERRCODE_UNDEFINED_OBJECT),
1081  errmsg("tablespace \"%s\" does not exist",
1082  *newval)));
1083  }
1084  else
1085  {
1086  GUC_check_errdetail("Tablespace \"%s\" does not exist.",
1087  *newval);
1088  return false;
1089  }
1090  }
1091  }
1092 
1093  return true;
1094 }
Oid get_tablespace_oid(const char *tablespacename, bool missing_ok)
Definition: tablespace.c:1380
GucSource source
Definition: guc_tables.h:155
#define GUC_check_errdetail
Definition: guc.h:408
int errcode(int sqlerrcode)
Definition: elog.c:575
#define OidIsValid(objectId)
Definition: c.h:532
#define ereport(elevel, rest)
Definition: elog.h:122
#define NOTICE
Definition: elog.h:37
#define newval
bool IsTransactionState(void)
Definition: xact.c:351
int errmsg(const char *fmt,...)
Definition: elog.c:797
bool check_search_path ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 4060 of file namespace.c.

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

4061 {
4062  char *rawname;
4063  List *namelist;
4064 
4065  /* Need a modifiable copy of string */
4066  rawname = pstrdup(*newval);
4067 
4068  /* Parse string into list of identifiers */
4069  if (!SplitIdentifierString(rawname, ',', &namelist))
4070  {
4071  /* syntax error in name list */
4072  GUC_check_errdetail("List syntax is invalid.");
4073  pfree(rawname);
4074  list_free(namelist);
4075  return false;
4076  }
4077 
4078  /*
4079  * We used to try to check that the named schemas exist, but there are
4080  * many valid use-cases for having search_path settings that include
4081  * schemas that don't exist; and often, we are not inside a transaction
4082  * here and so can't consult the system catalogs anyway. So now, the only
4083  * requirement is syntactic validity of the identifier list.
4084  */
4085 
4086  pfree(rawname);
4087  list_free(namelist);
4088 
4089  return true;
4090 }
#define GUC_check_errdetail
Definition: guc.h:408
char * pstrdup(const char *in)
Definition: mcxt.c:1076
void pfree(void *pointer)
Definition: mcxt.c:949
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3264
#define newval
void list_free(List *list)
Definition: list.c:1133
Definition: pg_list.h:45
bool check_temp_tablespaces ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 1157 of file tablespace.c.

References ACL_CREATE, ACL_KIND_TABLESPACE, aclcheck_error(), ACLCHECK_OK, ereport, errcode(), errmsg(), get_tablespace_oid(), GetUserId(), GUC_check_errdetail, InvalidOid, IsTransactionState(), lfirst, list_free(), list_length(), malloc, MyDatabaseTableSpace, NOTICE, temp_tablespaces_extra::numSpcs, offsetof, palloc(), pfree(), pg_tablespace_aclcheck(), PGC_S_INTERACTIVE, PGC_S_TEST, pstrdup(), SplitIdentifierString(), and temp_tablespaces_extra::tblSpcs.

1158 {
1159  char *rawname;
1160  List *namelist;
1161 
1162  /* Need a modifiable copy of string */
1163  rawname = pstrdup(*newval);
1164 
1165  /* Parse string into list of identifiers */
1166  if (!SplitIdentifierString(rawname, ',', &namelist))
1167  {
1168  /* syntax error in name list */
1169  GUC_check_errdetail("List syntax is invalid.");
1170  pfree(rawname);
1171  list_free(namelist);
1172  return false;
1173  }
1174 
1175  /*
1176  * If we aren't inside a transaction, we cannot do database access so
1177  * cannot verify the individual names. Must accept the list on faith.
1178  * Fortunately, there's then also no need to pass the data to fd.c.
1179  */
1180  if (IsTransactionState())
1181  {
1182  temp_tablespaces_extra *myextra;
1183  Oid *tblSpcs;
1184  int numSpcs;
1185  ListCell *l;
1186 
1187  /* temporary workspace until we are done verifying the list */
1188  tblSpcs = (Oid *) palloc(list_length(namelist) * sizeof(Oid));
1189  numSpcs = 0;
1190  foreach(l, namelist)
1191  {
1192  char *curname = (char *) lfirst(l);
1193  Oid curoid;
1194  AclResult aclresult;
1195 
1196  /* Allow an empty string (signifying database default) */
1197  if (curname[0] == '\0')
1198  {
1199  tblSpcs[numSpcs++] = InvalidOid;
1200  continue;
1201  }
1202 
1203  /*
1204  * In an interactive SET command, we ereport for bad info. When
1205  * source == PGC_S_TEST, don't throw a hard error for a
1206  * nonexistent tablespace, only a NOTICE. See comments in guc.h.
1207  */
1208  curoid = get_tablespace_oid(curname, source <= PGC_S_TEST);
1209  if (curoid == InvalidOid)
1210  {
1211  if (source == PGC_S_TEST)
1212  ereport(NOTICE,
1213  (errcode(ERRCODE_UNDEFINED_OBJECT),
1214  errmsg("tablespace \"%s\" does not exist",
1215  curname)));
1216  continue;
1217  }
1218 
1219  /*
1220  * Allow explicit specification of database's default tablespace
1221  * in temp_tablespaces without triggering permissions checks.
1222  */
1223  if (curoid == MyDatabaseTableSpace)
1224  {
1225  tblSpcs[numSpcs++] = InvalidOid;
1226  continue;
1227  }
1228 
1229  /* Check permissions, similarly complaining only if interactive */
1230  aclresult = pg_tablespace_aclcheck(curoid, GetUserId(),
1231  ACL_CREATE);
1232  if (aclresult != ACLCHECK_OK)
1233  {
1234  if (source >= PGC_S_INTERACTIVE)
1235  aclcheck_error(aclresult, ACL_KIND_TABLESPACE, curname);
1236  continue;
1237  }
1238 
1239  tblSpcs[numSpcs++] = curoid;
1240  }
1241 
1242  /* Now prepare an "extra" struct for assign_temp_tablespaces */
1243  myextra = malloc(offsetof(temp_tablespaces_extra, tblSpcs) +
1244  numSpcs * sizeof(Oid));
1245  if (!myextra)
1246  return false;
1247  myextra->numSpcs = numSpcs;
1248  memcpy(myextra->tblSpcs, tblSpcs, numSpcs * sizeof(Oid));
1249  *extra = (void *) myextra;
1250 
1251  pfree(tblSpcs);
1252  }
1253 
1254  pfree(rawname);
1255  list_free(namelist);
1256 
1257  return true;
1258 }
Oid get_tablespace_oid(const char *tablespacename, bool missing_ok)
Definition: tablespace.c:1380
GucSource source
Definition: guc_tables.h:155
AclResult pg_tablespace_aclcheck(Oid spc_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4496
Oid GetUserId(void)
Definition: miscinit.c:284
#define GUC_check_errdetail
Definition: guc.h:408
char * pstrdup(const char *in)
Definition: mcxt.c:1076
int errcode(int sqlerrcode)
Definition: elog.c:575
unsigned int Oid
Definition: postgres_ext.h:31
Oid MyDatabaseTableSpace
Definition: globals.c:79
#define malloc(a)
Definition: header.h:50
void pfree(void *pointer)
Definition: mcxt.c:949
#define ACL_CREATE
Definition: parsenodes.h:82
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3264
void aclcheck_error(AclResult aclerr, AclObjectKind objectkind, const char *objectname)
Definition: aclchk.c:3399
Oid tblSpcs[FLEXIBLE_ARRAY_MEMBER]
Definition: tablespace.c:1152
#define ereport(elevel, rest)
Definition: elog.h:122
AclResult
Definition: acl.h:178
#define InvalidOid
Definition: postgres_ext.h:36
#define NOTICE
Definition: elog.h:37
#define lfirst(lc)
Definition: pg_list.h:106
static int list_length(const List *l)
Definition: pg_list.h:89
#define newval
bool IsTransactionState(void)
Definition: xact.c:351
void * palloc(Size size)
Definition: mcxt.c:848
int errmsg(const char *fmt,...)
Definition: elog.c:797
void list_free(List *list)
Definition: list.c:1133
Definition: pg_list.h:45
#define offsetof(type, field)
Definition: c.h:549
bool check_wal_buffers ( int *  newval,
void **  extra,
GucSource  source 
)

Definition at line 4804 of file xlog.c.

References XLOGbuffers, and XLOGChooseNumBuffers().

4805 {
4806  /*
4807  * -1 indicates a request for auto-tune.
4808  */
4809  if (*newval == -1)
4810  {
4811  /*
4812  * If we haven't yet changed the boot_val default of -1, just let it
4813  * be. We'll fix it when XLOGShmemSize is called.
4814  */
4815  if (XLOGbuffers == -1)
4816  return true;
4817 
4818  /* Otherwise, substitute the auto-tune value */
4820  }
4821 
4822  /*
4823  * We clamp manually-set values to at least 4 blocks. Prior to PostgreSQL
4824  * 9.1, a minimum of 4 was enforced by guc.c, but since that is no longer
4825  * the case, we just silently treat such values as a request for the
4826  * minimum. (We could throw an error instead, but that doesn't seem very
4827  * helpful.)
4828  */
4829  if (*newval < 4)
4830  *newval = 4;
4831 
4832  return true;
4833 }
static int XLOGChooseNumBuffers(void)
Definition: xlog.c:4788
#define newval
int XLOGbuffers
Definition: xlog.c:92
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 7737 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().

7747 {
7748  struct config_bool *var;
7749 
7750  var = (struct config_bool *)
7751  init_custom_variable(name, short_desc, long_desc, context, flags,
7752  PGC_BOOL, sizeof(struct config_bool));
7753  var->variable = valueAddr;
7754  var->boot_val = bootValue;
7755  var->reset_val = bootValue;
7756  var->check_hook = check_hook;
7757  var->assign_hook = assign_hook;
7758  var->show_hook = show_hook;
7759  define_custom_variable(&var->gen);
7760 }
bool * variable
Definition: guc_tables.h:181
GucBoolAssignHook assign_hook
Definition: guc_tables.h:184
bool boot_val
Definition: guc_tables.h:182
struct config_generic gen
Definition: guc_tables.h:179
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:7505
GucBoolCheckHook check_hook
Definition: guc_tables.h:183
GucShowHook show_hook
Definition: guc_tables.h:185
const char * name
Definition: encode.c:521
bool reset_val
Definition: guc_tables.h:187
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7556
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 7848 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().

7859 {
7860  struct config_enum *var;
7861 
7862  var = (struct config_enum *)
7863  init_custom_variable(name, short_desc, long_desc, context, flags,
7864  PGC_ENUM, sizeof(struct config_enum));
7865  var->variable = valueAddr;
7866  var->boot_val = bootValue;
7867  var->reset_val = bootValue;
7868  var->options = options;
7869  var->check_hook = check_hook;
7870  var->assign_hook = assign_hook;
7871  var->show_hook = show_hook;
7872  define_custom_variable(&var->gen);
7873 }
GucEnumCheckHook check_hook
Definition: guc_tables.h:244
GucEnumAssignHook assign_hook
Definition: guc_tables.h:245
int * variable
Definition: guc_tables.h:241
const struct config_enum_entry * options
Definition: guc_tables.h:243
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:7505
GucShowHook show_hook
Definition: guc_tables.h:246
struct config_generic gen
Definition: guc_tables.h:239
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7556
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 7763 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().

7775 {
7776  struct config_int *var;
7777 
7778  var = (struct config_int *)
7779  init_custom_variable(name, short_desc, long_desc, context, flags,
7780  PGC_INT, sizeof(struct config_int));
7781  var->variable = valueAddr;
7782  var->boot_val = bootValue;
7783  var->reset_val = bootValue;
7784  var->min = minValue;
7785  var->max = maxValue;
7786  var->check_hook = check_hook;
7787  var->assign_hook = assign_hook;
7788  var->show_hook = show_hook;
7789  define_custom_variable(&var->gen);
7790 }
int boot_val
Definition: guc_tables.h:196
GucIntAssignHook assign_hook
Definition: guc_tables.h:200
GucIntCheckHook check_hook
Definition: guc_tables.h:199
GucShowHook show_hook
Definition: guc_tables.h:201
int * variable
Definition: guc_tables.h:195
struct config_generic gen
Definition: guc_tables.h:193
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:7505
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7556
int reset_val
Definition: guc_tables.h:203
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 7793 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().

7805 {
7806  struct config_real *var;
7807 
7808  var = (struct config_real *)
7809  init_custom_variable(name, short_desc, long_desc, context, flags,
7810  PGC_REAL, sizeof(struct config_real));
7811  var->variable = valueAddr;
7812  var->boot_val = bootValue;
7813  var->reset_val = bootValue;
7814  var->min = minValue;
7815  var->max = maxValue;
7816  var->check_hook = check_hook;
7817  var->assign_hook = assign_hook;
7818  var->show_hook = show_hook;
7819  define_custom_variable(&var->gen);
7820 }
GucRealAssignHook assign_hook
Definition: guc_tables.h:216
double reset_val
Definition: guc_tables.h:219
GucRealCheckHook check_hook
Definition: guc_tables.h:215
GucShowHook show_hook
Definition: guc_tables.h:217
double * variable
Definition: guc_tables.h:211
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:7505
double max
Definition: guc_tables.h:214
double boot_val
Definition: guc_tables.h:212
const char * name
Definition: encode.c:521
double min
Definition: guc_tables.h:213
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7556
struct config_generic gen
Definition: guc_tables.h:209
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 7823 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().

7833 {
7834  struct config_string *var;
7835 
7836  var = (struct config_string *)
7837  init_custom_variable(name, short_desc, long_desc, context, flags,
7838  PGC_STRING, sizeof(struct config_string));
7839  var->variable = valueAddr;
7840  var->boot_val = bootValue;
7841  var->check_hook = check_hook;
7842  var->assign_hook = assign_hook;
7843  var->show_hook = show_hook;
7844  define_custom_variable(&var->gen);
7845 }
char ** variable
Definition: guc_tables.h:227
GucStringCheckHook check_hook
Definition: guc_tables.h:229
const char * boot_val
Definition: guc_tables.h:228
GucShowHook show_hook
Definition: guc_tables.h:231
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:7505
struct config_generic gen
Definition: guc_tables.h:225
GucStringAssignHook assign_hook
Definition: guc_tables.h:230
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7556
void EmitWarningsOnPlaceholders ( const char *  className)

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

7877 {
7878  int classLen = strlen(className);
7879  int i;
7880 
7881  for (i = 0; i < num_guc_variables; i++)
7882  {
7883  struct config_generic *var = guc_variables[i];
7884 
7885  if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
7886  strncmp(className, var->name, classLen) == 0 &&
7887  var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
7888  {
7889  ereport(WARNING,
7890  (errcode(ERRCODE_UNDEFINED_OBJECT),
7891  errmsg("unrecognized configuration parameter \"%s\"",
7892  var->name)));
7893  }
7894  }
7895 }
const char * name
Definition: guc_tables.h:146
int errcode(int sqlerrcode)
Definition: elog.c:575
#define GUC_QUALIFIER_SEPARATOR
Definition: guc.h:199
static int num_guc_variables
Definition: guc.c:3947
#define ereport(elevel, rest)
Definition: elog.h:122
static struct config_generic ** guc_variables
Definition: guc.c:3944
#define WARNING
Definition: elog.h:40
#define GUC_CUSTOM_PLACEHOLDER
Definition: guc.h:211
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
Size EstimateGUCStateSpace ( void  )

Definition at line 9102 of file guc.c.

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

Referenced by InitializeParallelDSM().

9103 {
9104  Size size;
9105  int i;
9106 
9107  /* Add space reqd for saving the data size of the guc state */
9108  size = sizeof(Size);
9109 
9110  /* Add up the space needed for each GUC variable */
9111  for (i = 0; i < num_guc_variables; i++)
9112  size = add_size(size,
9114 
9115  return size;
9116 }
static int num_guc_variables
Definition: guc.c:3947
static struct config_generic ** guc_variables
Definition: guc.c:3944
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
size_t Size
Definition: c.h:350
static Size estimate_variable_size(struct config_generic *gconf)
Definition: guc.c:9004
int i
void ExecSetVariableStmt ( VariableSetStmt stmt,
bool  isTopLevel 
)

Definition at line 7293 of file guc.c.

References 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 WarnNoTransactionChain().

Referenced by standard_ProcessUtility().

7294 {
7296 
7297  /*
7298  * Workers synchronize these parameters at the start of the parallel
7299  * operation; then, we block SET during the operation.
7300  */
7301  if (IsInParallelMode())
7302  ereport(ERROR,
7303  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
7304  errmsg("cannot set parameters during a parallel operation")));
7305 
7306  switch (stmt->kind)
7307  {
7308  case VAR_SET_VALUE:
7309  case VAR_SET_CURRENT:
7310  if (stmt->is_local)
7311  WarnNoTransactionChain(isTopLevel, "SET LOCAL");
7312  (void) set_config_option(stmt->name,
7313  ExtractSetVariableArgs(stmt),
7315  PGC_S_SESSION,
7316  action, true, 0, false);
7317  break;
7318  case VAR_SET_MULTI:
7319 
7320  /*
7321  * Special-case SQL syntaxes. The TRANSACTION and SESSION
7322  * CHARACTERISTICS cases effectively set more than one variable
7323  * per statement. TRANSACTION SNAPSHOT only takes one argument,
7324  * but we put it here anyway since it's a special case and not
7325  * related to any GUC variable.
7326  */
7327  if (strcmp(stmt->name, "TRANSACTION") == 0)
7328  {
7329  ListCell *head;
7330 
7331  WarnNoTransactionChain(isTopLevel, "SET TRANSACTION");
7332 
7333  foreach(head, stmt->args)
7334  {
7335  DefElem *item = (DefElem *) lfirst(head);
7336 
7337  if (strcmp(item->defname, "transaction_isolation") == 0)
7338  SetPGVariable("transaction_isolation",
7339  list_make1(item->arg), stmt->is_local);
7340  else if (strcmp(item->defname, "transaction_read_only") == 0)
7341  SetPGVariable("transaction_read_only",
7342  list_make1(item->arg), stmt->is_local);
7343  else if (strcmp(item->defname, "transaction_deferrable") == 0)
7344  SetPGVariable("transaction_deferrable",
7345  list_make1(item->arg), stmt->is_local);
7346  else
7347  elog(ERROR, "unexpected SET TRANSACTION element: %s",
7348  item->defname);
7349  }
7350  }
7351  else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
7352  {
7353  ListCell *head;
7354 
7355  foreach(head, stmt->args)
7356  {
7357  DefElem *item = (DefElem *) lfirst(head);
7358 
7359  if (strcmp(item->defname, "transaction_isolation") == 0)
7360  SetPGVariable("default_transaction_isolation",
7361  list_make1(item->arg), stmt->is_local);
7362  else if (strcmp(item->defname, "transaction_read_only") == 0)
7363  SetPGVariable("default_transaction_read_only",
7364  list_make1(item->arg), stmt->is_local);
7365  else if (strcmp(item->defname, "transaction_deferrable") == 0)
7366  SetPGVariable("default_transaction_deferrable",
7367  list_make1(item->arg), stmt->is_local);
7368  else
7369  elog(ERROR, "unexpected SET SESSION element: %s",
7370  item->defname);
7371  }
7372  }
7373  else if (strcmp(stmt->name, "TRANSACTION SNAPSHOT") == 0)
7374  {
7375  A_Const *con = linitial_node(A_Const, stmt->args);
7376 
7377  if (stmt->is_local)
7378  ereport(ERROR,
7379  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7380  errmsg("SET LOCAL TRANSACTION SNAPSHOT is not implemented")));
7381 
7382  WarnNoTransactionChain(isTopLevel, "SET TRANSACTION");
7383  Assert(nodeTag(&con->val) == T_String);
7384  ImportSnapshot(strVal(&con->val));
7385  }
7386  else
7387  elog(ERROR, "unexpected SET MULTI element: %s",
7388  stmt->name);
7389  break;
7390  case VAR_SET_DEFAULT:
7391  if (stmt->is_local)
7392  WarnNoTransactionChain(isTopLevel, "SET LOCAL");
7393  /* fall through */
7394  case VAR_RESET:
7395  if (strcmp(stmt->name, "transaction_isolation") == 0)
7396  WarnNoTransactionChain(isTopLevel, "RESET TRANSACTION");
7397 
7398  (void) set_config_option(stmt->name,
7399  NULL,
7401  PGC_S_SESSION,
7402  action, true, 0, false);
7403  break;
7404  case VAR_RESET_ALL:
7405  ResetAllOptions();
7406  break;
7407  }
7408 }
void ImportSnapshot(const char *idstr)
Definition: snapmgr.c:1430
VariableSetKind kind
Definition: parsenodes.h:1973
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:575
bool superuser(void)
Definition: superuser.c:47
#define linitial_node(type, l)
Definition: pg_list.h:114
GucAction
Definition: guc.h:191
#define list_make1(x1)
Definition: pg_list.h:139
bool IsInParallelMode(void)
Definition: xact.c:906
#define ERROR
Definition: elog.h:43
Definition: guc.h:75
void ResetAllOptions(void)
Definition: guc.c:4873
#define ereport(elevel, rest)
Definition: elog.h:122
Node * arg
Definition: parsenodes.h:720
void WarnNoTransactionChain(bool isTopLevel, const char *stmtType)
Definition: xact.c:3200
#define Assert(condition)
Definition: c.h:681
#define lfirst(lc)
Definition: pg_list.h:106
#define nodeTag(nodeptr)
Definition: nodes.h:515
int errmsg(const char *fmt,...)
Definition: elog.c:797
char * defname
Definition: parsenodes.h:719
#define elog
Definition: elog.h:219
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
Definition: guc.c:7417
Value val
Definition: parsenodes.h:287
int set_config_option(const char *name, const char *value, GucContext context, GucSource source, GucAction action, bool changeVal, int elevel, bool is_reload)
Definition: guc.c:5917
void SetPGVariable(const char *name, List *args, bool is_local)
Definition: guc.c:7437
char* ExtractSetVariableArgs ( VariableSetStmt stmt)

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

7418 {
7419  switch (stmt->kind)
7420  {
7421  case VAR_SET_VALUE:
7422  return flatten_set_variable_args(stmt->name, stmt->args);
7423  case VAR_SET_CURRENT:
7424  return GetConfigOptionByName(stmt->name, NULL, false);
7425  default:
7426  return NULL;
7427  }
7428 }
VariableSetKind kind
Definition: parsenodes.h:1973
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:8043
static char * flatten_set_variable_args(const char *name, List *args)
Definition: guc.c:6816
const char* GetConfigOption ( const char *  name,
bool  missing_ok,
bool  restrict_superuser 
)

Definition at line 6705 of file guc.c.

References buffer, config_enum_lookup_by_value(), DEFAULT_ROLE_READ_ALL_SETTINGS, 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(), and PostmasterMain().

6706 {
6707  struct config_generic *record;
6708  static char buffer[256];
6709 
6710  record = find_option(name, false, ERROR);
6711  if (record == NULL)
6712  {
6713  if (missing_ok)
6714  return NULL;
6715  ereport(ERROR,
6716  (errcode(ERRCODE_UNDEFINED_OBJECT),
6717  errmsg("unrecognized configuration parameter \"%s\"",
6718  name)));
6719  }
6720  if (restrict_superuser &&
6721  (record->flags & GUC_SUPERUSER_ONLY) &&
6723  ereport(ERROR,
6724  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6725  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
6726  name)));
6727 
6728  switch (record->vartype)
6729  {
6730  case PGC_BOOL:
6731  return *((struct config_bool *) record)->variable ? "on" : "off";
6732 
6733  case PGC_INT:
6734  snprintf(buffer, sizeof(buffer), "%d",
6735  *((struct config_int *) record)->variable);
6736  return buffer;
6737 
6738  case PGC_REAL:
6739  snprintf(buffer, sizeof(buffer), "%g",
6740  *((struct config_real *) record)->variable);
6741  return buffer;
6742 
6743  case PGC_STRING:
6744  return *((struct config_string *) record)->variable;
6745 
6746  case PGC_ENUM:
6747  return config_enum_lookup_by_value((struct config_enum *) record,
6748  *((struct config_enum *) record)->variable);
6749  }
6750  return NULL;
6751 }
Oid GetUserId(void)
Definition: miscinit.c:284
int errcode(int sqlerrcode)
Definition: elog.c:575
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5626
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
enum config_type vartype
Definition: guc_tables.h:153
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4854
#define DEFAULT_ROLE_READ_ALL_SETTINGS
Definition: pg_authid.h:106
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4381
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:214
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797
char* GetConfigOptionByName ( const char *  name,
const char **  varname,
bool  missing_ok 
)

Definition at line 8043 of file guc.c.

References _ShowOption(), DEFAULT_ROLE_READ_ALL_SETTINGS, ereport, errcode(), errmsg(), ERROR, find_option(), config_generic::flags, GetUserId(), GUC_SUPERUSER_ONLY, is_member_of_role(), and config_generic::name.

Referenced by ExtractSetVariableArgs(), GetPGVariableResultDesc(), set_config_by_name(), show_config_by_name(), show_config_by_name_missing_ok(), and ShowGUCConfigOption().

8044 {
8045  struct config_generic *record;
8046 
8047  record = find_option(name, false, ERROR);
8048  if (record == NULL)
8049  {
8050  if (missing_ok)
8051  {
8052  if (varname)
8053  *varname = NULL;
8054  return NULL;
8055  }
8056 
8057  ereport(ERROR,
8058  (errcode(ERRCODE_UNDEFINED_OBJECT),
8059  errmsg("unrecognized configuration parameter \"%s\"", name)));
8060  }
8061 
8062  if ((record->flags & GUC_SUPERUSER_ONLY) &&
8064  ereport(ERROR,
8065  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
8066  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
8067  name)));
8068 
8069  if (varname)
8070  *varname = record->name;
8071 
8072  return _ShowOption(record, true);
8073 }
static char * _ShowOption(struct config_generic *record, bool use_units)
Definition: guc.c:8644
Oid GetUserId(void)
Definition: miscinit.c:284
const char * name
Definition: guc_tables.h:146
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4854
#define DEFAULT_ROLE_READ_ALL_SETTINGS
Definition: pg_authid.h:106
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4381
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797
void GetConfigOptionByNum ( int  varnum,
const char **  values,
bool noshow 
)

Definition at line 8080 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, buffer, config_enum_get_options(), config_enum_lookup_by_value(), config_generic::context, DEFAULT_ROLE_READ_ALL_SETTINGS, elog, ERROR, config_generic::flags, GetUserId(), config_generic::group, GUC_NO_SHOW_ALL, GUC_PENDING_RESTART, GUC_SUPERUSER_ONLY, GUC_UNIT_BLOCKS, GUC_UNIT_BYTE, GUC_UNIT_KB, GUC_UNIT_MB, GUC_UNIT_MEMORY, GUC_UNIT_MIN, GUC_UNIT_MS, GUC_UNIT_S, GUC_UNIT_TIME, GUC_UNIT_XBLOCKS, 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, superuser(), and config_generic::vartype.

Referenced by show_all_settings().

8081 {
8082  char buffer[256];
8083  struct config_generic *conf;
8084 
8085  /* check requested variable number valid */
8086  Assert((varnum >= 0) && (varnum < num_guc_variables));
8087 
8088  conf = guc_variables[varnum];
8089 
8090  if (noshow)
8091  {
8092  if ((conf->flags & GUC_NO_SHOW_ALL) ||
8093  ((conf->flags & GUC_SUPERUSER_ONLY) &&
8095  *noshow = true;
8096  else
8097  *noshow = false;
8098  }
8099 
8100  /* first get the generic attributes */
8101 
8102  /* name */
8103  values[0] = conf->name;
8104 
8105  /* setting : use _ShowOption in order to avoid duplicating the logic */
8106  values[1] = _ShowOption(conf, false);
8107 
8108  /* unit */
8109  if (conf->vartype == PGC_INT)
8110  {
8111  switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
8112  {
8113  case GUC_UNIT_BYTE:
8114  values[2] = "B";
8115  break;
8116  case GUC_UNIT_KB:
8117  values[2] = "kB";
8118  break;
8119  case GUC_UNIT_MB:
8120  values[2] = "MB";
8121  break;
8122  case GUC_UNIT_BLOCKS:
8123  snprintf(buffer, sizeof(buffer), "%dkB", BLCKSZ / 1024);
8124  values[2] = pstrdup(buffer);
8125  break;
8126  case GUC_UNIT_XBLOCKS:
8127  snprintf(buffer, sizeof(buffer), "%dkB", XLOG_BLCKSZ / 1024);
8128  values[2] = pstrdup(buffer);
8129  break;
8130  case GUC_UNIT_MS:
8131  values[2] = "ms";
8132  break;
8133  case GUC_UNIT_S:
8134  values[2] = "s";
8135  break;
8136  case GUC_UNIT_MIN:
8137  values[2] = "min";
8138  break;
8139  case 0:
8140  values[2] = NULL;
8141  break;
8142  default:
8143  elog(ERROR, "unrecognized GUC units value: %d",
8144  conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME));
8145  values[2] = NULL;
8146  break;
8147  }
8148  }
8149  else
8150  values[2] = NULL;
8151 
8152  /* group */
8153  values[3] = config_group_names[conf->group];
8154 
8155  /* short_desc */
8156  values[4] = conf->short_desc;
8157 
8158  /* extra_desc */
8159  values[5] = conf->long_desc;
8160 
8161  /* context */
8162  values[6] = GucContext_Names[conf->context];
8163 
8164  /* vartype */
8165  values[7] = config_type_names[conf->vartype];
8166 
8167  /* source */
8168  values[8] = GucSource_Names[conf->source];
8169 
8170  /* now get the type specific attributes */
8171  switch (conf->vartype)
8172  {
8173  case PGC_BOOL:
8174  {
8175  struct config_bool *lconf = (struct config_bool *) conf;
8176 
8177  /* min_val */
8178  values[9] = NULL;
8179 
8180  /* max_val */
8181  values[10] = NULL;
8182 
8183  /* enumvals */
8184  values[11] = NULL;
8185 
8186  /* boot_val */
8187  values[12] = pstrdup(lconf->boot_val ? "on" : "off");
8188 
8189  /* reset_val */
8190  values[13] = pstrdup(lconf->reset_val ? "on" : "off");
8191  }
8192  break;
8193 
8194  case PGC_INT:
8195  {
8196  struct config_int *lconf = (struct config_int *) conf;
8197 
8198  /* min_val */
8199  snprintf(buffer, sizeof(buffer), "%d", lconf->min);
8200  values[9] = pstrdup(buffer);
8201 
8202  /* max_val */
8203  snprintf(buffer, sizeof(buffer), "%d", lconf->max);
8204  values[10] = pstrdup(buffer);
8205 
8206  /* enumvals */
8207  values[11] = NULL;
8208 
8209  /* boot_val */
8210  snprintf(buffer, sizeof(buffer), "%d", lconf->boot_val);
8211  values[12] = pstrdup(buffer);
8212 
8213  /* reset_val */
8214  snprintf(buffer, sizeof(buffer), "%d", lconf->reset_val);
8215  values[13] = pstrdup(buffer);
8216  }
8217  break;
8218 
8219  case PGC_REAL:
8220  {
8221  struct config_real *lconf = (struct config_real *) conf;
8222 
8223  /* min_val */
8224  snprintf(buffer, sizeof(buffer), "%g", lconf->min);
8225  values[9] = pstrdup(buffer);
8226 
8227  /* max_val */
8228  snprintf(buffer, sizeof(buffer), "%g", lconf->max);
8229  values[10] = pstrdup(buffer);
8230 
8231  /* enumvals */
8232  values[11] = NULL;
8233 
8234  /* boot_val */
8235  snprintf(buffer, sizeof(buffer), "%g", lconf->boot_val);
8236  values[12] = pstrdup(buffer);
8237 
8238  /* reset_val */
8239  snprintf(buffer, sizeof(buffer), "%g", lconf->reset_val);
8240  values[13] = pstrdup(buffer);
8241  }
8242  break;
8243 
8244  case PGC_STRING:
8245  {
8246  struct config_string *lconf = (struct config_string *) conf;
8247 
8248  /* min_val */
8249  values[9] = NULL;
8250 
8251  /* max_val */
8252  values[10] = NULL;
8253 
8254  /* enumvals */
8255  values[11] = NULL;
8256 
8257  /* boot_val */
8258  if (lconf->boot_val == NULL)
8259  values[12] = NULL;
8260  else
8261  values[12] = pstrdup(lconf->boot_val);
8262 
8263  /* reset_val */
8264  if (lconf->reset_val == NULL)
8265  values[13] = NULL;
8266  else
8267  values[13] = pstrdup(lconf->reset_val);
8268  }
8269  break;
8270 
8271  case PGC_ENUM:
8272  {
8273  struct config_enum *lconf = (struct config_enum *) conf;
8274 
8275  /* min_val */
8276  values[9] = NULL;
8277 
8278  /* max_val */
8279  values[10] = NULL;
8280 
8281  /* enumvals */
8282 
8283  /*
8284  * NOTE! enumvals with double quotes in them are not
8285  * supported!
8286  */
8287  values[11] = config_enum_get_options((struct config_enum *) conf,
8288  "{\"", "\"}", "\",\"");
8289 
8290  /* boot_val */
8292  lconf->boot_val));
8293 
8294  /* reset_val */
8296  lconf->reset_val));
8297  }
8298  break;
8299 
8300  default:
8301  {
8302  /*
8303  * should never get here, but in case we do, set 'em to NULL
8304  */
8305 
8306  /* min_val */
8307  values[9] = NULL;
8308 
8309  /* max_val */
8310  values[10] = NULL;
8311 
8312  /* enumvals */
8313  values[11] = NULL;
8314 
8315  /* boot_val */
8316  values[12] = NULL;
8317 
8318  /* reset_val */
8319  values[13] = NULL;
8320  }
8321  break;
8322  }
8323 
8324  /*
8325  * If the setting came from a config file, set the source location. For
8326  * security reasons, we don't show source file/line number for
8327  * non-superusers.
8328  */
8329  if (conf->source == PGC_S_FILE && superuser())
8330  {
8331  values[14] = conf->sourcefile;
8332  snprintf(buffer, sizeof(buffer), "%d", conf->sourceline);
8333  values[15] = pstrdup(buffer);
8334  }
8335  else
8336  {
8337  values[14] = NULL;
8338  values[15] = NULL;
8339  }
8340 
8341  values[16] = (conf->status & GUC_PENDING_RESTART) ? "t" : "f";
8342 }
GucSource source
Definition: guc_tables.h:155
static char * _ShowOption(struct config_generic *record, bool use_units)
Definition: guc.c:8644
const char * long_desc
Definition: guc_tables.h:150
double reset_val
Definition: guc_tables.h:219
Oid GetUserId(void)
Definition: miscinit.c:284
const char * name
Definition: guc_tables.h:146
const char *const config_type_names[]
Definition: guc.c:673
char * pstrdup(const char *in)
Definition: mcxt.c:1076
const char * short_desc
Definition: guc_tables.h:149
int boot_val
Definition: guc_tables.h:196
const char * boot_val
Definition: guc_tables.h:228
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5626
bool superuser(void)
Definition: superuser.c:47
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define GUC_UNIT_KB
Definition: guc.h:218
#define GUC_UNIT_BLOCKS
Definition: guc.h:219
#define GUC_NO_SHOW_ALL
Definition: guc.h:206
const char *const GucContext_Names[]
Definition: guc.c:529
#define GUC_UNIT_MIN
Definition: guc.h:227
const char *const config_group_names[]
Definition: guc.c:566
#define ERROR
Definition: elog.h:43
#define GUC_UNIT_XBLOCKS
Definition: guc.h:220
#define GUC_UNIT_BYTE
Definition: guc.h:222
static int num_guc_variables
Definition: guc.c:3947
#define GUC_UNIT_S
Definition: guc.h:226
char * sourcefile
Definition: guc_tables.h:161
bool boot_val
Definition: guc_tables.h:182
static struct config_generic ** guc_variables
Definition: guc.c:3944
enum config_type vartype
Definition: guc_tables.h:153
#define GUC_UNIT_TIME
Definition: guc.h:228
double max
Definition: guc_tables.h:214
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4854
#define DEFAULT_ROLE_READ_ALL_SETTINGS
Definition: pg_authid.h:106
char * reset_val
Definition: guc_tables.h:233
double boot_val
Definition: guc_tables.h:212
#define Assert(condition)
Definition: c.h:681
#define GUC_UNIT_MB
Definition: guc.h:221
#define GUC_PENDING_RESTART
Definition: guc_tables.h:172
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:214
double min
Definition: guc_tables.h:213
static Datum values[MAXATTR]
Definition: bootstrap.c:164
enum config_group group
Definition: guc_tables.h:148
#define elog
Definition: elog.h:219
bool reset_val
Definition: guc_tables.h:187
const char *const GucSource_Names[]
Definition: guc.c:545
static char * config_enum_get_options(struct config_enum *record, const char *prefix, const char *suffix, const char *separator)
Definition: guc.c:5675
#define GUC_UNIT_MS
Definition: guc.h:225
GucContext context
Definition: guc_tables.h:147
#define GUC_UNIT_MEMORY
Definition: guc.h:223
int reset_val
Definition: guc_tables.h:203
const char* GetConfigOptionResetString ( const char *  name)

Definition at line 6761 of file guc.c.

References buffer, config_enum_lookup_by_value(), DEFAULT_ROLE_READ_ALL_SETTINGS, 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().

6762 {
6763  struct config_generic *record;
6764  static char buffer[256];
6765 
6766  record = find_option(name, false, ERROR);
6767  if (record == NULL)
6768  ereport(ERROR,
6769  (errcode(ERRCODE_UNDEFINED_OBJECT),
6770  errmsg("unrecognized configuration parameter \"%s\"", name)));
6771  if ((record->flags & GUC_SUPERUSER_ONLY) &&
6773  ereport(ERROR,
6774  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6775  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
6776  name)));
6777 
6778  switch (record->vartype)
6779  {
6780  case PGC_BOOL:
6781  return ((struct config_bool *) record)->reset_val ? "on" : "off";
6782 
6783  case PGC_INT:
6784  snprintf(buffer, sizeof(buffer), "%d",
6785  ((struct config_int *) record)->reset_val);
6786  return buffer;
6787 
6788  case PGC_REAL:
6789  snprintf(buffer, sizeof(buffer), "%g",
6790  ((struct config_real *) record)->reset_val);
6791  return buffer;
6792 
6793  case PGC_STRING:
6794  return ((struct config_string *) record)->reset_val;
6795 
6796  case PGC_ENUM:
6797  return config_enum_lookup_by_value((struct config_enum *) record,
6798  ((struct config_enum *) record)->reset_val);
6799  }
6800  return NULL;
6801 }
Oid GetUserId(void)
Definition: miscinit.c:284
int errcode(int sqlerrcode)
Definition: elog.c:575
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5626
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
enum config_type vartype
Definition: guc_tables.h:153
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4854
#define DEFAULT_ROLE_READ_ALL_SETTINGS
Definition: pg_authid.h:106
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4381
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:214
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797
int GetNumConfigOptions ( void  )

Definition at line 8348 of file guc.c.

References num_guc_variables.

Referenced by GucInfoMain(), and show_all_settings().

8349 {
8350  return num_guc_variables;
8351 }
static int num_guc_variables
Definition: guc.c:3947
void GetPGVariable ( const char *  name,
DestReceiver dest 
)

Definition at line 7902 of file guc.c.

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

Referenced by exec_replication_command(), and standard_ProcessUtility().

7903 {
7904  if (guc_name_compare(name, "all") == 0)
7905  ShowAllGUCConfig(dest);
7906  else
7907  ShowGUCConfigOption(name, dest);
7908 }
static void ShowGUCConfigOption(const char *name, DestReceiver *dest)
Definition: guc.c:7946
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:4442
static void ShowAllGUCConfig(DestReceiver *dest)
Definition: guc.c:7974
const char * name
Definition: encode.c:521
TupleDesc GetPGVariableResultDesc ( const char *  name)

Definition at line 7911 of file guc.c.

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

Referenced by UtilityTupleDescriptor().

7912 {
7913  TupleDesc tupdesc;
7914 
7915  if (guc_name_compare(name, "all") == 0)
7916  {
7917  /* need a tuple descriptor representing three TEXT columns */
7918  tupdesc = CreateTemplateTupleDesc(3, false);
7919  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
7920  TEXTOID, -1, 0);
7921  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
7922  TEXTOID, -1, 0);
7923  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
7924  TEXTOID, -1, 0);
7925  }
7926  else
7927  {
7928  const char *varname;
7929 
7930  /* Get the canonical spelling of name */
7931  (void) GetConfigOptionByName(name, &varname, false);
7932 
7933  /* need a tuple descriptor representing a single TEXT column */
7934  tupdesc = CreateTemplateTupleDesc(1, false);
7935  TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
7936  TEXTOID, -1, 0);
7937  }
7938  return tupdesc;
7939 }
#define TEXTOID
Definition: pg_type.h:324
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:4442
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:8043
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:505
TupleDesc CreateTemplateTupleDesc(int natts, bool hasoid)
Definition: tupdesc.c:43
const char * name
Definition: encode.c:521
int16 AttrNumber
Definition: attnum.h:21
void GUC_check_errcode ( int  sqlerrcode)

Definition at line 9784 of file guc.c.

References GUC_check_errcode_value.

Referenced by check_client_encoding(), check_role(), check_synchronous_standby_names(), check_transaction_deferrable(), check_transaction_read_only(), and check_XactIsoLevel().

9785 {
9786  GUC_check_errcode_value = sqlerrcode;
9787 }
static int GUC_check_errcode_value
Definition: guc.c:128
ArrayType* GUCArrayAdd ( ArrayType array,
const char *  name,
const char *  value 
)

Definition at line 9481 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, TEXTOID, validate_option_array_item(), and WARNING.

Referenced by AlterSetting(), and update_proconfig_value().

9482 {
9483  struct config_generic *record;
9484  Datum datum;
9485  char *newval;
9486  ArrayType *a;
9487 
9488  Assert(name);
9489  Assert(value);
9490 
9491  /* test if the option is valid and we're allowed to set it */
9492  (void) validate_option_array_item(name, value, false);
9493 
9494  /* normalize name (converts obsolete GUC names to modern spellings) */
9495  record = find_option(name, false, WARNING);
9496  if (record)
9497  name = record->name;
9498 
9499  /* build new item for array */
9500  newval = psprintf("%s=%s", name, value);
9501  datum = CStringGetTextDatum(newval);
9502 
9503  if (array)
9504  {
9505  int index;
9506  bool isnull;
9507  int i;
9508 
9509  Assert(ARR_ELEMTYPE(array) == TEXTOID);
9510  Assert(ARR_NDIM(array) == 1);
9511  Assert(ARR_LBOUND(array)[0] == 1);
9512 
9513  index = ARR_DIMS(array)[0] + 1; /* add after end */
9514 
9515  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9516  {
9517  Datum d;
9518  char *current;
9519 
9520  d = array_ref(array, 1, &i,
9521  -1 /* varlenarray */ ,
9522  -1 /* TEXT's typlen */ ,
9523  false /* TEXT's typbyval */ ,
9524  'i' /* TEXT's typalign */ ,
9525  &isnull);
9526  if (isnull)
9527  continue;
9528  current = TextDatumGetCString(d);
9529 
9530  /* check for match up through and including '=' */
9531  if (strncmp(current, newval, strlen(name) + 1) == 0)
9532  {
9533  index = i;
9534  break;
9535  }
9536  }
9537 
9538  a = array_set(array, 1, &index,
9539  datum,
9540  false,
9541  -1 /* varlena array */ ,
9542  -1 /* TEXT's typlen */ ,
9543  false /* TEXT's typbyval */ ,
9544  'i' /* TEXT's typalign */ );
9545  }
9546  else
9547  a = construct_array(&datum, 1,
9548  TEXTOID,
9549  -1, false, 'i');
9550 
9551  return a;
9552 }
const char * name
Definition: guc_tables.h:146
#define TEXTOID
Definition: pg_type.h:324
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3279
ArrayType * array_set(ArrayType *array, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3081
#define ARR_LBOUND(a)
Definition: array.h:281
Definition: type.h:89
static bool validate_option_array_item(const char *name, const char *value, bool skipIfNoPermissions)
Definition: guc.c:9707
#define ARR_DIMS(a)
Definition: array.h:279
static struct @121 value
Datum array_ref(ArrayType *array, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:3064
#define WARNING
Definition: elog.h:40
#define TextDatumGetCString(d)
Definition: builtins.h:92
uintptr_t Datum
Definition: postgres.h:372
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4381
#define Assert(condition)
Definition: c.h:681
#define newval
#define ARR_NDIM(a)
Definition: array.h:275
const char * name
Definition: encode.c:521
int i
#define CStringGetTextDatum(s)
Definition: builtins.h:91
#define ARR_ELEMTYPE(a)
Definition: array.h:277
ArrayType* GUCArrayDelete ( ArrayType array,
const char *  name 
)

Definition at line 9561 of file guc.c.

References ARR_DIMS, array_ref(), array_set(), Assert, construct_array(), find_option(), i, config_generic::name, TextDatumGetCString, TEXTOID, val, validate_option_array_item(), and WARNING.

Referenced by AlterSetting(), and update_proconfig_value().

9562 {
9563  struct config_generic *record;
9564  ArrayType *newarray;
9565  int i;
9566  int index;
9567 
9568  Assert(name);
9569 
9570  /* test if the option is valid and we're allowed to set it */
9571  (void) validate_option_array_item(name, NULL, false);
9572 
9573  /* normalize name (converts obsolete GUC names to modern spellings) */
9574  record = find_option(name, false, WARNING);
9575  if (record)
9576  name = record->name;
9577 
9578  /* if array is currently null, then surely nothing to delete */
9579  if (!array)
9580  return NULL;
9581 
9582  newarray = NULL;
9583  index = 1;
9584 
9585  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9586  {
9587  Datum d;
9588  char *val;
9589  bool isnull;
9590 
9591  d = array_ref(array, 1, &i,
9592  -1 /* varlenarray */ ,
9593  -1 /* TEXT's typlen */ ,
9594  false /* TEXT's typbyval */ ,
9595  'i' /* TEXT's typalign */ ,
9596  &isnull);
9597  if (isnull)
9598  continue;
9599  val = TextDatumGetCString(d);
9600 
9601  /* ignore entry if it's what we want to delete */
9602  if (strncmp(val, name, strlen(name)) == 0
9603  && val[strlen(name)] == '=')
9604  continue;
9605 
9606  /* else add it to the output array */
9607  if (newarray)
9608  newarray = array_set(newarray, 1, &index,
9609  d,
9610  false,
9611  -1 /* varlenarray */ ,
9612  -1 /* TEXT's typlen */ ,
9613  false /* TEXT's typbyval */ ,
9614  'i' /* TEXT's typalign */ );
9615  else
9616  newarray = construct_array(&d, 1,
9617  TEXTOID,
9618  -1, false, 'i');
9619 
9620  index++;
9621  }
9622 
9623  return newarray;
9624 }
const char * name
Definition: guc_tables.h:146
#define TEXTOID
Definition: pg_type.h:324
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3279
ArrayType * array_set(ArrayType *array, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3081
Definition: type.h:89
static bool validate_option_array_item(const char *name, const char *value, bool skipIfNoPermissions)
Definition: guc.c:9707
#define ARR_DIMS(a)
Definition: array.h:279
Datum array_ref(ArrayType *array, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:3064
#define WARNING
Definition: elog.h:40
#define TextDatumGetCString(d)
Definition: builtins.h:92
uintptr_t Datum
Definition: postgres.h:372
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4381
#define Assert(condition)
Definition: c.h:681
const char * name
Definition: encode.c:521
int i
long val
Definition: informix.c:689
ArrayType* GUCArrayReset ( ArrayType array)

Definition at line 9633 of file guc.c.

References ARR_DIMS, array_ref(), array_set(), construct_array(), i, pfree(), superuser(), TextDatumGetCString, TEXTOID, val, and validate_option_array_item().

Referenced by AlterSetting().

9634 {
9635  ArrayType *newarray;
9636  int i;
9637  int index;
9638 
9639  /* if array is currently null, nothing to do */
9640  if (!array)
9641  return NULL;
9642 
9643  /* if we're superuser, we can delete everything, so just do it */
9644  if (superuser())
9645  return NULL;
9646 
9647  newarray = NULL;
9648  index = 1;
9649 
9650  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9651  {
9652  Datum d;
9653  char *val;
9654  char *eqsgn;
9655  bool isnull;
9656 
9657  d = array_ref(array, 1, &i,
9658  -1 /* varlenarray */ ,
9659  -1 /* TEXT's typlen */ ,
9660  false /* TEXT's typbyval */ ,
9661  'i' /* TEXT's typalign */ ,
9662  &isnull);
9663  if (isnull)
9664  continue;
9665  val = TextDatumGetCString(d);
9666 
9667  eqsgn = strchr(val, '=');
9668  *eqsgn = '\0';
9669 
9670  /* skip if we have permission to delete it */
9671  if (validate_option_array_item(val, NULL, true))
9672  continue;
9673 
9674  /* else add it to the output array */
9675  if (newarray)
9676  newarray = array_set(newarray, 1, &index,
9677  d,
9678  false,
9679  -1 /* varlenarray */ ,
9680  -1 /* TEXT's typlen */ ,
9681  false /* TEXT's typbyval */ ,
9682  'i' /* TEXT's typalign */ );
9683  else
9684  newarray = construct_array(&d, 1,
9685  TEXTOID,
9686  -1, false, 'i');
9687 
9688  index++;
9689  pfree(val);
9690  }
9691 
9692  return newarray;
9693 }
#define TEXTOID
Definition: pg_type.h:324
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3279
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:3081
Definition: type.h:89
void pfree(void *pointer)
Definition: mcxt.c:949
static bool validate_option_array_item(const char *name, const char *value, bool skipIfNoPermissions)
Definition: guc.c:9707
#define ARR_DIMS(a)
Definition: array.h:279
Datum array_ref(ArrayType *array, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:3064
#define TextDatumGetCString(d)
Definition: builtins.h:92
uintptr_t Datum
Definition: postgres.h:372
int i
long val
Definition: informix.c:689
void InitializeGUCOptions ( void  )

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

4477 {
4478  int i;
4479 
4480  /*
4481  * Before log_line_prefix could possibly receive a nonempty setting, make
4482  * sure that timezone processing is minimally alive (see elog.c).
4483  */
4485 
4486  /*
4487  * Build sorted array of all GUC variables.
4488  */
4490 
4491  /*
4492  * Load all variables with their compiled-in defaults, and initialize
4493  * status fields as needed.
4494  */
4495  for (i = 0; i < num_guc_variables; i++)
4496  {
4498  }
4499 
4500  guc_dirty = false;
4501 
4502  reporting_enabled = false;
4503 
4504  /*
4505  * Prevent any attempt to override the transaction modes from
4506  * non-interactive sources.
4507  */
4508  SetConfigOption("transaction_isolation", "default",
4510  SetConfigOption("transaction_read_only", "no",
4512  SetConfigOption("transaction_deferrable", "no",
4514 
4515  /*
4516  * For historical reasons, some GUC parameters can receive defaults from
4517  * environment variables. Process those settings.
4518  */
4520 }
void build_guc_variables(void)
Definition: guc.c:4208
static void InitializeGUCOptionsFromEnvironment(void)
Definition: guc.c:4532
void pg_timezone_initialize(void)
Definition: pgtz.c:370
static int num_guc_variables
Definition: guc.c:3947
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:6681
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:4578
static struct config_generic ** guc_variables
Definition: guc.c:3944
int i
static bool reporting_enabled
Definition: guc.c:3955
static bool guc_dirty
Definition: guc.c:3953
bool parse_int ( const char *  value,
int *  result,
int  flags,
const char **  hintmsg 
)

Definition at line 5506 of file guc.c.

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

Referenced by parse_and_validate_value(), parse_one_reloption(), and readRecoveryCommandFile().

5507 {
5508  int64 val;
5509  char *endptr;
5510 
5511  /* To suppress compiler warnings, always set output params */
5512  if (result)
5513  *result = 0;
5514  if (hintmsg)
5515  *hintmsg = NULL;
5516 
5517  /* We assume here that int64 is at least as wide as long */
5518  errno = 0;
5519  val = strtol(value, &endptr, 0);
5520 
5521  if (endptr == value)
5522  return false; /* no HINT for integer syntax error */
5523 
5524  if (errno == ERANGE || val != (int64) ((int32) val))
5525  {
5526  if (hintmsg)
5527  *hintmsg = gettext_noop("Value exceeds integer range.");
5528  return false;
5529  }
5530 
5531  /* allow whitespace between integer and unit */
5532  while (isspace((unsigned char) *endptr))
5533  endptr++;
5534 
5535  /* Handle possible unit */
5536  if (*endptr != '\0')
5537  {
5538  char unit[MAX_UNIT_LEN + 1];
5539  int unitlen;
5540  bool converted = false;
5541 
5542  if ((flags & GUC_UNIT) == 0)
5543  return false; /* this setting does not accept a unit */
5544 
5545  unitlen = 0;
5546  while (*endptr != '\0' && !isspace((unsigned char) *endptr) &&
5547  unitlen < MAX_UNIT_LEN)
5548  unit[unitlen++] = *(endptr++);
5549  unit[unitlen] = '\0';
5550  /* allow whitespace after unit */
5551  while (isspace((unsigned char) *endptr))
5552  endptr++;
5553 
5554  if (*endptr == '\0')
5555  converted = convert_to_base_unit(val, unit, (flags & GUC_UNIT),
5556  &val);
5557  if (!converted)
5558  {
5559  /* invalid unit, or garbage after the unit; set hint and fail. */
5560  if (hintmsg)
5561  {
5562  if (flags & GUC_UNIT_MEMORY)
5563  *hintmsg = memory_units_hint;
5564  else
5565  *hintmsg = time_units_hint;
5566  }
5567  return false;
5568  }
5569 
5570  /* Check for overflow due to units conversion */
5571  if (val != (int64) ((int32) val))
5572  {
5573  if (hintmsg)
5574  *hintmsg = gettext_noop("Value exceeds integer range.");
5575  return false;
5576  }
5577  }
5578 
5579  if (result)
5580  *result = (int) val;
5581  return true;
5582 }
#define MAX_UNIT_LEN
Definition: guc.c:697
#define gettext_noop(x)
Definition: c.h:139
#define GUC_UNIT
Definition: guc.h:230
signed int int32
Definition: c.h:246
static struct @121 value
static const char * time_units_hint
Definition: guc.c:749
static bool convert_to_base_unit(int64 value, const char *unit, int base_unit, int64 *base_value)
Definition: guc.c:5421
long val
Definition: informix.c:689
static const char * memory_units_hint
Definition: guc.c:717
#define GUC_UNIT_MEMORY
Definition: guc.h:223
bool parse_real ( const char *  value,
double *  result 
)

Definition at line 5592 of file guc.c.

References val.

Referenced by parse_and_validate_value(), and parse_one_reloption().

5593 {
5594  double val;
5595  char *endptr;
5596 
5597  if (result)
5598  *result = 0; /* suppress compiler warning */
5599 
5600  errno = 0;
5601  val = strtod(value, &endptr);
5602  if (endptr == value || errno == ERANGE)
5603  return false;
5604 
5605  /* allow whitespace after number */
5606  while (isspace((unsigned char) *endptr))
5607  endptr++;
5608  if (*endptr != '\0')
5609  return false;
5610 
5611  if (result)
5612  *result = val;
5613  return true;
5614 }
static struct @121 value
long val
Definition: informix.c:689
bool ParseConfigDirectory ( const char *  includedir,
const char *  calling_file,
int  calling_lineno,
int  depth,
int  elevel,
ConfigVariable **  head_p,
ConfigVariable **  tail_p 
)
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 
)
void ParseLongOption ( const char *  string,
char **  name,
char **  value 
)

Definition at line 9385 of file guc.c.

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

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

9386 {
9387  size_t equal_pos;
9388  char *cp;
9389 
9390  AssertArg(string);
9391  AssertArg(name);
9392  AssertArg(value);
9393 
9394  equal_pos = strcspn(string, "=");
9395 
9396  if (string[equal_pos] == '=')
9397  {
9398  *name = guc_malloc(FATAL, equal_pos + 1);
9399  strlcpy(*name, string, equal_pos + 1);
9400 
9401  *value = guc_strdup(FATAL, &string[equal_pos + 1]);
9402  }
9403  else
9404  {
9405  /* no equal sign in string */
9406  *name = guc_strdup(FATAL, string);
9407  *value = NULL;
9408  }
9409 
9410  for (cp = *name; *cp; cp++)
9411  if (*cp == '-')
9412  *cp = '_';
9413 }
static char * guc_strdup(int elevel, const char *src)
Definition: guc.c:4017
#define FATAL
Definition: elog.h:52
static struct @121 value
#define AssertArg(condition)
Definition: c.h:683
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:3985
void ProcessGUCArray ( ArrayType array,
GucContext  context,
GucSource  source,
GucAction  action 
)

Definition at line 9423 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, TEXTOID, value, and WARNING.

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

9425 {
9426  int i;
9427 
9428  Assert(array != NULL);
9429  Assert(ARR_ELEMTYPE(array) == TEXTOID);
9430  Assert(ARR_NDIM(array) == 1);
9431  Assert(ARR_LBOUND(array)[0] == 1);
9432 
9433  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9434  {
9435  Datum d;
9436  bool isnull;
9437  char *s;
9438  char *name;
9439  char *value;
9440 
9441  d = array_ref(array, 1, &i,
9442  -1 /* varlenarray */ ,
9443  -1 /* TEXT's typlen */ ,
9444  false /* TEXT's typbyval */ ,
9445  'i' /* TEXT's typalign */ ,
9446  &isnull);
9447 
9448  if (isnull)
9449  continue;
9450 
9451  s = TextDatumGetCString(d);
9452 
9453  ParseLongOption(s, &name, &value);
9454  if (!value)
9455  {
9456  ereport(WARNING,
9457  (errcode(ERRCODE_SYNTAX_ERROR),
9458  errmsg("could not parse setting for parameter \"%s\"",
9459  name)));
9460  free(name);
9461  continue;
9462  }
9463 
9464  (void) set_config_option(name, value,
9465  context, source,
9466  action, true, 0, false);
9467 
9468  free(name);
9469  if (value)
9470  free(value);
9471  pfree(s);
9472  }
9473 }
GucSource source
Definition: guc_tables.h:155
#define TEXTOID
Definition: pg_type.h:324
void ParseLongOption(const char *string, char **name, char **value)
Definition: guc.c:9385
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ARR_LBOUND(a)
Definition: array.h:281
void pfree(void *pointer)
Definition: mcxt.c:949
#define ARR_DIMS(a)
Definition: array.h:279
static struct @121 value
#define ereport(elevel, rest)
Definition: elog.h:122
Datum array_ref(ArrayType *array, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:3064
#define WARNING
Definition: elog.h:40
#define TextDatumGetCString(d)
Definition: builtins.h:92
uintptr_t Datum
Definition: postgres.h:372
#define free(a)
Definition: header.h:65
#define Assert(condition)
Definition: c.h:681
#define ARR_NDIM(a)
Definition: array.h:275
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797
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:5917
#define ARR_ELEMTYPE(a)
Definition: array.h:277
GucContext context
Definition: guc_tables.h:147
void ResetAllOptions ( void  )

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

4874 {
4875  int i;
4876 
4877  for (i = 0; i < num_guc_variables; i++)
4878  {
4879  struct config_generic *gconf = guc_variables[i];
4880 
4881  /* Don't reset non-SET-able values */
4882  if (gconf->context != PGC_SUSET &&
4883  gconf->context != PGC_USERSET)
4884  continue;
4885  /* Don't reset if special exclusion from RESET ALL */
4886  if (gconf->flags & GUC_NO_RESET_ALL)
4887  continue;
4888  /* No need to reset if wasn't SET */
4889  if (gconf->source <= PGC_S_OVERRIDE)
4890  continue;
4891 
4892  /* Save old value to support transaction abort */
4894 
4895  switch (gconf->vartype)
4896  {
4897  case PGC_BOOL:
4898  {
4899  struct config_bool *conf = (struct config_bool *) gconf;
4900 
4901  if (conf->assign_hook)
4902  conf->assign_hook(conf->reset_val,
4903  conf->reset_extra);
4904  *conf->variable = conf->reset_val;
4905  set_extra_field(&conf->gen, &conf->gen.extra,
4906  conf->reset_extra);
4907  break;
4908  }
4909  case PGC_INT:
4910  {
4911  struct config_int *conf = (struct config_int *) gconf;
4912 
4913  if (conf->assign_hook)
4914  conf->assign_hook(conf->reset_val,
4915  conf->reset_extra);
4916  *conf->variable = conf->reset_val;
4917  set_extra_field(&conf->gen, &conf->gen.extra,
4918  conf->reset_extra);
4919  break;
4920  }
4921  case PGC_REAL:
4922  {
4923  struct config_real *conf = (struct config_real *) gconf;
4924 
4925  if (conf->assign_hook)
4926  conf->assign_hook(conf->reset_val,
4927  conf->reset_extra);
4928  *conf->variable = conf->reset_val;
4929  set_extra_field(&conf->gen, &conf->gen.extra,
4930  conf->reset_extra);
4931  break;
4932  }
4933  case PGC_STRING:
4934  {
4935  struct config_string *conf = (struct config_string *) gconf;
4936 
4937  if (conf->assign_hook)
4938  conf->assign_hook(conf->reset_val,
4939  conf->reset_extra);
4940  set_string_field(conf, conf->variable, conf->reset_val);
4941  set_extra_field(&conf->gen, &conf->gen.extra,
4942  conf->reset_extra);
4943  break;
4944  }
4945  case PGC_ENUM:
4946  {
4947  struct config_enum *conf = (struct config_enum *) gconf;
4948 
4949  if (conf->assign_hook)
4950  conf->assign_hook(conf->reset_val,
4951  conf->reset_extra);
4952  *conf->variable = conf->reset_val;
4953  set_extra_field(&conf->gen, &conf->gen.extra,
4954  conf->reset_extra);
4955  break;
4956  }
4957  }
4958 
4959  gconf->source = gconf->reset_source;
4960  gconf->scontext = gconf->reset_scontext;
4961 
4962  if (gconf->flags & GUC_REPORT)
4963  ReportGUCOption(gconf);
4964  }
4965 }
GucSource source
Definition: guc_tables.h:155
void * reset_extra
Definition: guc_tables.h:204
GucRealAssignHook assign_hook
Definition: guc_tables.h:216
double reset_val
Definition: guc_tables.h:219
#define GUC_NO_RESET_ALL
Definition: guc.h:207
char ** variable
Definition: guc_tables.h:227
bool * variable
Definition: guc_tables.h:181
GucEnumAssignHook assign_hook
Definition: guc_tables.h:245
GucBoolAssignHook assign_hook
Definition: guc_tables.h:184
GucContext scontext
Definition: guc_tables.h:157
GucIntAssignHook assign_hook
Definition: guc_tables.h:200
static void push_old_value(struct config_generic *gconf, GucAction action)
Definition: guc.c:4973
int * variable
Definition: guc_tables.h:195
int * variable
Definition: guc_tables.h:241
static int num_guc_variables
Definition: guc.c:3947
void * reset_extra
Definition: guc_tables.h:249
Definition: guc.h:75
static void set_extra_field(struct config_generic *gconf, void **field, void *newval)
Definition: guc.c:4118
GucSource reset_source
Definition: guc_tables.h:156
struct config_generic gen
Definition: guc_tables.h:179
struct config_generic gen
Definition: guc_tables.h:193
#define GUC_REPORT
Definition: guc.h:208
double * variable
Definition: guc_tables.h:211
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4057
static struct config_generic ** guc_variables
Definition: guc.c:3944
enum config_type vartype
Definition: guc_tables.h:153
void * reset_extra
Definition: guc_tables.h:220
struct config_generic gen
Definition: guc_tables.h:239
struct config_generic gen
Definition: guc_tables.h:225
char * reset_val
Definition: guc_tables.h:233
GucStringAssignHook assign_hook
Definition: guc_tables.h:230
void * reset_extra
Definition: guc_tables.h:234
void * reset_extra
Definition: guc_tables.h:188
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:5397
bool reset_val
Definition: guc_tables.h:187
GucContext context
Definition: guc_tables.h:147
struct config_generic gen
Definition: guc_tables.h:209
GucContext reset_scontext
Definition: guc_tables.h:158
int reset_val
Definition: guc_tables.h:203
void RestoreGUCState ( void *  gucstate)

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

9328 {
9329  char *varname,
9330  *varvalue,
9331  *varsourcefile;
9332  int varsourceline;
9333  GucSource varsource;
9334  GucContext varscontext;
9335  char *srcptr = (char *) gucstate;
9336  char *srcend;
9337  Size len;
9338  int i;
9339 
9340  /* See comment at can_skip_gucvar(). */
9341  for (i = 0; i < num_guc_variables; i++)
9342  if (!can_skip_gucvar(guc_variables[i]))
9344 
9345  /* First item is the length of the subsequent data */
9346  memcpy(&len, gucstate, sizeof(len));
9347 
9348  srcptr += sizeof(len);
9349  srcend = srcptr + len;
9350 
9351  while (srcptr < srcend)
9352  {
9353  int result;
9354 
9355  varname = read_gucstate(&srcptr, srcend);
9356  varvalue = read_gucstate(&srcptr, srcend);
9357  varsourcefile = read_gucstate(&srcptr, srcend);
9358  if (varsourcefile[0])
9359  read_gucstate_binary(&srcptr, srcend,
9360  &varsourceline, sizeof(varsourceline));
9361  read_gucstate_binary(&srcptr, srcend,
9362  &varsource, sizeof(varsource));
9363  read_gucstate_binary(&srcptr, srcend,
9364  &varscontext, sizeof(varscontext));
9365 
9366  result = set_config_option(varname, varvalue, varscontext, varsource,
9367  GUC_ACTION_SET, true, ERROR, true);
9368  if (result <= 0)
9369  ereport(ERROR,
9370  (errcode(ERRCODE_INTERNAL_ERROR),
9371  errmsg("parameter \"%s\" could not be set", varname)));
9372  if (varsourcefile[0])
9373  set_config_sourcefile(varname, varsourcefile, varsourceline);
9374  }
9375 }
GucContext
Definition: guc.h:68
static void static void set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
Definition: guc.c:6647
static void read_gucstate_binary(char **srcptr, char *srcend, void *dest, Size size)
Definition: guc.c:9312
int errcode(int sqlerrcode)
Definition: elog.c:575
GucSource
Definition: guc.h:105
#define ERROR
Definition: elog.h:43
static int num_guc_variables
Definition: guc.c:3947
static bool can_skip_gucvar(struct config_generic *gconf)
Definition: guc.c:8991
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:4578
#define ereport(elevel, rest)
Definition: elog.h:122
static struct config_generic ** guc_variables
Definition: guc.c:3944
static char * read_gucstate(char **srcptr, char *srcend)
Definition: guc.c:9289
size_t Size
Definition: c.h:350
int errmsg(const char *fmt,...)
Definition: elog.c:797
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:5917
bool SelectConfigFiles ( const char *  userDoption,
const char *  progname 
)

Definition at line 4698 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(), strerror(), and write_stderr.

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

4699 {
4700  char *configdir;
4701  char *fname;
4702  struct stat stat_buf;
4703 
4704  /* configdir is -D option, or $PGDATA if no -D */
4705  if (userDoption)
4706  configdir = make_absolute_path(userDoption);
4707  else
4708  configdir = make_absolute_path(getenv("PGDATA"));
4709 
4710  if (configdir && stat(configdir, &stat_buf) != 0)
4711  {
4712  write_stderr("%s: could not access directory \"%s\": %s\n",
4713  progname,
4714  configdir,
4715  strerror(errno));
4716  if (errno == ENOENT)
4717  write_stderr("Run initdb or pg_basebackup to initialize a PostgreSQL data directory.\n");
4718  return false;
4719  }
4720 
4721  /*
4722  * Find the configuration file: if config_file was specified on the
4723  * command line, use it, else use configdir/postgresql.conf. In any case
4724  * ensure the result is an absolute path, so that it will be interpreted
4725  * the same way by future backends.
4726  */
4727  if (ConfigFileName)
4729  else if (configdir)
4730  {
4731  fname = guc_malloc(FATAL,
4732  strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
4733  sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
4734  }
4735  else
4736  {
4737  write_stderr("%s does not know where to find the server configuration file.\n"
4738  "You must specify the --config-file or -D invocation "
4739  "option or set the PGDATA environment variable.\n",
4740  progname);
4741  return false;
4742  }
4743 
4744  /*
4745  * Set the ConfigFileName GUC variable to its final value, ensuring that
4746  * it can't be overridden later.
4747  */
4748  SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4749  free(fname);
4750 
4751  /*
4752  * Now read the config file for the first time.
4753  */
4754  if (stat(ConfigFileName, &stat_buf) != 0)
4755  {
4756  write_stderr("%s: could not access the server configuration file \"%s\": %s\n",
4757  progname, ConfigFileName, strerror(errno));
4758  free(configdir);
4759  return false;
4760  }
4761 
4762  /*
4763  * Read the configuration file for the first time. This time only the
4764  * data_directory parameter is picked up to determine the data directory,
4765  * so that we can read the PG_AUTOCONF_FILENAME file next time.
4766  */
4768 
4769  /*
4770  * If the data_directory GUC variable has been set, use that as DataDir;
4771  * otherwise use configdir if set; else punt.
4772  *
4773  * Note: SetDataDir will copy and absolute-ize its argument, so we don't
4774  * have to.
4775  */
4776  if (data_directory)
4778  else if (configdir)
4779  SetDataDir(configdir);
4780  else
4781  {
4782  write_stderr("%s does not know where to find the database system data.\n"
4783  "This can be specified as \"data_directory\" in \"%s\", "
4784  "or by the -D invocation option, or by the "
4785  "PGDATA environment variable.\n",
4787  return false;
4788  }
4789 
4790  /*
4791  * Reflect the final DataDir value back into the data_directory GUC var.
4792  * (If you are wondering why we don't just make them a single variable,
4793  * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
4794  * child backends specially. XXX is that still true? Given that we now
4795  * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
4796  * DataDir in advance.)
4797  */
4799 
4800  /*
4801  * Now read the config file a second time, allowing any settings in the
4802  * PG_AUTOCONF_FILENAME file to take effect. (This is pretty ugly, but
4803  * since we have to determine the DataDir before we can find the autoconf
4804  * file, the alternatives seem worse.)
4805  */
4807 
4808  /*
4809  * If timezone_abbreviations wasn't set in the configuration file, install
4810  * the default value. We do it this way because we can't safely install a
4811  * "real" value until my_exec_path is set, which may not have happened
4812  * when InitializeGUCOptions runs, so the bootstrap default value cannot
4813  * be the real desired default.
4814  */
4816 
4817  /*
4818  * Figure out where pg_hba.conf is, and make sure the path is absolute.
4819  */
4820  if (HbaFileName)
4822  else if (configdir)
4823  {
4824  fname = guc_malloc(FATAL,
4825  strlen(configdir) + strlen(HBA_FILENAME) + 2);
4826  sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
4827  }
4828  else
4829  {
4830  write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
4831  "This can be specified as \"hba_file\" in \"%s\", "
4832  "or by the -D invocation option, or by the "
4833  "PGDATA environment variable.\n",
4835  return false;
4836  }
4837  SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4838  free(fname);
4839 
4840  /*
4841  * Likewise for pg_ident.conf.
4842  */
4843  if (IdentFileName)
4845  else if (configdir)
4846  {
4847  fname = guc_malloc(FATAL,
4848  strlen(configdir) + strlen(IDENT_FILENAME) + 2);
4849  sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
4850  }
4851  else
4852  {
4853  write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
4854  "This can be specified as \"ident_file\" in \"%s\", "
4855  "or by the -D invocation option, or by the "
4856  "PGDATA environment variable.\n",
4858  return false;
4859  }
4860  SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4861  free(fname);
4862 
4863  free(configdir);
4864 
4865  return true;
4866 }
char * make_absolute_path(const char *path)
Definition: path.c:608
void ProcessConfigFile(GucContext context)
void SetDataDir(const char *dir)
Definition: miscinit.c:95
char * ConfigFileName
Definition: guc.c:462
static void pg_timezone_abbrev_initialize(void)
Definition: guc.c:10275
#define CONFIG_FILENAME
Definition: guc.c:97
#define write_stderr(str)
Definition: parallel.c:182
const char * progname
Definition: pg_standby.c:37
char * HbaFileName
Definition: guc.c:463
#define HBA_FILENAME
Definition: guc.c:98
struct stat stat_buf
Definition: pg_standby.c:103
#define FATAL
Definition: elog.h:52
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:6681
char * IdentFileName
Definition: guc.c:464
#define IDENT_FILENAME
Definition: guc.c:99
#define free(a)
Definition: header.h:65
static const char * userDoption
Definition: postgres.c:159
const char * strerror(int errnum)
Definition: strerror.c:19
char * DataDir
Definition: globals.c:60
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:3985
static char * data_directory
Definition: guc.c:508
void SerializeGUCState ( Size  maxsize,
char *  start_address 
)

Definition at line 9249 of file guc.c.

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

Referenced by InitializeParallelDSM().

9250 {
9251  char *curptr;
9252  Size actual_size;
9253  Size bytes_left;
9254  int i;
9255  int i_role = -1;
9256 
9257  /* Reserve space for saving the actual size of the guc state */
9258  Assert(maxsize > sizeof(actual_size));
9259  curptr = start_address + sizeof(actual_size);
9260  bytes_left = maxsize - sizeof(actual_size);
9261 
9262  for (i = 0; i < num_guc_variables; i++)
9263  {
9264  /*
9265  * It's pretty ugly, but we've got to force "role" to be initialized
9266  * after "session_authorization"; otherwise, the latter will override
9267  * the former.
9268  */
9269  if (strcmp(guc_variables[i]->name, "role") == 0)
9270  i_role = i;
9271  else
9272  serialize_variable(&curptr, &bytes_left, guc_variables[i]);
9273  }
9274  if (i_role >= 0)
9275  serialize_variable(&curptr, &bytes_left, guc_variables[i_role]);
9276 
9277  /* Store actual size without assuming alignment of start_address. */
9278  actual_size = maxsize - bytes_left - sizeof(actual_size);
9279  memcpy(start_address, &actual_size, sizeof(actual_size));
9280 }
static void serialize_variable(char **destptr, Size *maxbytes, struct config_generic *gconf)
Definition: guc.c:9175
static int num_guc_variables
Definition: guc.c:3947
static struct config_generic ** guc_variables
Definition: guc.c:3944
#define Assert(condition)
Definition: c.h:681
size_t Size
Definition: c.h:350
const char * name
Definition: encode.c:521
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 at line 5917 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 applyRemoteGucs(), define_custom_variable(), ExecSetVariableStmt(), execute_extension_script(), parse_subscription_options(), ProcessGUCArray(), reapply_stacked_values(), RestoreGUCState(), RI_Initial_Check(), set_config_by_name(), set_transmission_modes(), SetConfigOption(), SetPGVariable(), and validate_option_array_item().

5921 {
5922  struct config_generic *record;
5923  union config_var_val newval_union;
5924  void *newextra = NULL;
5925  bool prohibitValueChange = false;
5926  bool makeDefault;
5927 
5928  if (elevel == 0)
5929  {
5930  if (source == PGC_S_DEFAULT || source == PGC_S_FILE)
5931  {
5932  /*
5933  * To avoid cluttering the log, only the postmaster bleats loudly
5934  * about problems with the config file.
5935  */
5937  }
5938  else if (source == PGC_S_GLOBAL ||
5939  source == PGC_S_DATABASE ||
5940  source == PGC_S_USER ||
5941  source == PGC_S_DATABASE_USER)
5942  elevel = WARNING;
5943  else
5944  elevel = ERROR;
5945  }
5946 
5947  /*
5948  * GUC_ACTION_SAVE changes are acceptable during a parallel operation,
5949  * because the current worker will also pop the change. We're probably
5950  * dealing with a function having a proconfig entry. Only the function's
5951  * body should observe the change, and peer workers do not share in the
5952  * execution of a function call started by this worker.
5953  *
5954  * Other changes might need to affect other workers, so forbid them.
5955  */
5956  if (IsInParallelMode() && changeVal && action != GUC_ACTION_SAVE)
5957  ereport(elevel,
5958  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
5959  errmsg("cannot set parameters during a parallel operation")));
5960 
5961  record = find_option(name, true, elevel);
5962  if (record == NULL)
5963  {
5964  ereport(elevel,
5965  (errcode(ERRCODE_UNDEFINED_OBJECT),
5966  errmsg("unrecognized configuration parameter \"%s\"", name)));
5967  return 0;
5968  }
5969 
5970  /*
5971  * Check if the option can be set at this time. See guc.h for the precise
5972  * rules.
5973  */
5974  switch (record->context)
5975  {
5976  case PGC_INTERNAL:
5977  if (context != PGC_INTERNAL)
5978  {
5979  ereport(elevel,
5980  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5981  errmsg("parameter \"%s\" cannot be changed",
5982  name)));
5983  return 0;
5984  }
5985  break;
5986  case PGC_POSTMASTER:
5987  if (context == PGC_SIGHUP)
5988  {
5989  /*
5990  * We are re-reading a PGC_POSTMASTER variable from
5991  * postgresql.conf. We can't change the setting, so we should
5992  * give a warning if the DBA tries to change it. However,
5993  * because of variant formats, canonicalization by check
5994  * hooks, etc, we can't just compare the given string directly
5995  * to what's stored. Set a flag to check below after we have
5996  * the final storable value.
5997  */
5998  prohibitValueChange = true;
5999  }
6000  else if (context != PGC_POSTMASTER)
6001  {
6002  ereport(elevel,
6003  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6004  errmsg("parameter \"%s\" cannot be changed without restarting the server",
6005  name)));
6006  return 0;
6007  }
6008  break;
6009  case PGC_SIGHUP:
6010  if (context != PGC_SIGHUP && context != PGC_POSTMASTER)
6011  {
6012  ereport(elevel,
6013  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6014  errmsg("parameter \"%s\" cannot be changed now",
6015  name)));
6016  return 0;
6017  }
6018 
6019  /*
6020  * Hmm, the idea of the SIGHUP context is "ought to be global, but
6021  * can be changed after postmaster start". But there's nothing
6022  * that prevents a crafty administrator from sending SIGHUP
6023  * signals to individual backends only.
6024  */
6025  break;
6026  case PGC_SU_BACKEND:
6027  /* Reject if we're connecting but user is not superuser */
6028  if (context == PGC_BACKEND)
6029  {
6030  ereport(elevel,
6031  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6032  errmsg("permission denied to set parameter \"%s\"",
6033  name)));
6034  return 0;
6035  }
6036  /* FALL THRU to process the same as PGC_BACKEND */
6037  case PGC_BACKEND:
6038  if (context == PGC_SIGHUP)
6039  {
6040  /*
6041  * If a PGC_BACKEND or PGC_SU_BACKEND parameter is changed in
6042  * the config file, we want to accept the new value in the
6043  * postmaster (whence it will propagate to
6044  * subsequently-started backends), but ignore it in existing
6045  * backends. This is a tad klugy, but necessary because we
6046  * don't re-read the config file during backend start.
6047  *
6048  * In EXEC_BACKEND builds, this works differently: we load all
6049  * non-default settings from the CONFIG_EXEC_PARAMS file
6050  * during backend start. In that case we must accept
6051  * PGC_SIGHUP settings, so as to have the same value as if
6052  * we'd forked from the postmaster. This can also happen when
6053  * using RestoreGUCState() within a background worker that
6054  * needs to have the same settings as the user backend that
6055  * started it. is_reload will be true when either situation
6056  * applies.
6057  */
6058  if (IsUnderPostmaster && !is_reload)
6059  return -1;
6060  }
6061  else if (context != PGC_POSTMASTER &&
6062  context != PGC_BACKEND &&
6063  context != PGC_SU_BACKEND &&
6064  source != PGC_S_CLIENT)
6065  {
6066  ereport(elevel,
6067  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6068  errmsg("parameter \"%s\" cannot be set after connection start",
6069  name)));
6070  return 0;
6071  }
6072  break;
6073  case PGC_SUSET:
6074  if (context == PGC_USERSET || context == PGC_BACKEND)
6075  {
6076  ereport(elevel,
6077  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6078  errmsg("permission denied to set parameter \"%s\"",
6079  name)));
6080  return 0;
6081  }
6082  break;
6083  case PGC_USERSET:
6084  /* always okay */
6085  break;
6086  }
6087 
6088  /*
6089  * Disallow changing GUC_NOT_WHILE_SEC_REST values if we are inside a
6090  * security restriction context. We can reject this regardless of the GUC
6091  * context or source, mainly because sources that it might be reasonable
6092  * to override for won't be seen while inside a function.
6093  *
6094  * Note: variables marked GUC_NOT_WHILE_SEC_REST should usually be marked
6095  * GUC_NO_RESET_ALL as well, because ResetAllOptions() doesn't check this.
6096  * An exception might be made if the reset value is assumed to be "safe".
6097  *
6098  * Note: this flag is currently used for "session_authorization" and
6099  * "role". We need to prohibit changing these inside a local userid
6100  * context because when we exit it, GUC won't be notified, leaving things
6101  * out of sync. (This could be fixed by forcing a new GUC nesting level,
6102  * but that would change behavior in possibly-undesirable ways.) Also, we
6103  * prohibit changing these in a security-restricted operation because
6104  * otherwise RESET could be used to regain the session user's privileges.
6105  */
6106  if (record->flags & GUC_NOT_WHILE_SEC_REST)
6107  {
6108  if (InLocalUserIdChange())
6109  {
6110  /*
6111  * Phrasing of this error message is historical, but it's the most
6112  * common case.
6113  */
6114  ereport(elevel,
6115  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6116  errmsg("cannot set parameter \"%s\" within security-definer function",
6117  name)));
6118  return 0;
6119  }
6121  {
6122  ereport(elevel,
6123  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6124  errmsg("cannot set parameter \"%s\" within security-restricted operation",
6125  name)));
6126  return 0;
6127  }
6128  }
6129 
6130  /*
6131  * Should we set reset/stacked values? (If so, the behavior is not
6132  * transactional.) This is done either when we get a default value from
6133  * the database's/user's/client's default settings or when we reset a
6134  * value to its default.
6135  */
6136  makeDefault = changeVal && (source <= PGC_S_OVERRIDE) &&
6137  ((value != NULL) || source == PGC_S_DEFAULT);
6138 
6139  /*
6140  * Ignore attempted set if overridden by previously processed setting.
6141  * However, if changeVal is false then plow ahead anyway since we are
6142  * trying to find out if the value is potentially good, not actually use
6143  * it. Also keep going if makeDefault is true, since we may want to set
6144  * the reset/stacked values even if we can't set the variable itself.
6145  */
6146  if (record->source > source)
6147  {
6148  if (changeVal && !makeDefault)
6149  {
6150  elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
6151  name);
6152  return -1;
6153  }
6154  changeVal = false;
6155  }
6156 
6157  /*
6158  * Evaluate value and set variable.
6159  */
6160  switch (record->vartype)
6161  {
6162  case PGC_BOOL:
6163  {
6164  struct config_bool *conf = (struct config_bool *) record;
6165 
6166 #define newval (newval_union.boolval)
6167 
6168  if (value)
6169  {
6170  if (!parse_and_validate_value(record, name, value,
6171  source, elevel,
6172  &newval_union, &newextra))
6173  return 0;
6174  }
6175  else if (source == PGC_S_DEFAULT)
6176  {
6177  newval = conf->boot_val;
6178  if (!call_bool_check_hook(conf, &newval, &newextra,
6179  source, elevel))
6180  return 0;
6181  }
6182  else
6183  {
6184  newval = conf->reset_val;
6185  newextra = conf->reset_extra;
6186  source = conf->gen.reset_source;
6187  context = conf->gen.reset_scontext;
6188  }
6189 
6190  if (prohibitValueChange)
6191  {
6192  if (*conf->variable != newval)
6193  {
6194  record->status |= GUC_PENDING_RESTART;
6195  ereport(elevel,
6196  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6197  errmsg("parameter \"%s\" cannot be changed without restarting the server",
6198  name)));
6199  return 0;
6200  }
6201  record->status &= ~GUC_PENDING_RESTART;
6202  return -1;
6203  }
6204 
6205  if (changeVal)
6206  {
6207  /* Save old value to support transaction abort */
6208  if (!makeDefault)
6209  push_old_value(&conf->gen, action);
6210 
6211  if (conf->assign_hook)
6212  conf->assign_hook(newval, newextra);
6213  *conf->variable = newval;
6214  set_extra_field(&conf->gen, &conf->gen.extra,
6215  newextra);
6216  conf->gen.source = source;
6217  conf->gen.scontext = context;
6218  }
6219  if (makeDefault)
6220  {
6221  GucStack *stack;
6222 
6223  if (conf->gen.reset_source <= source)
6224  {
6225  conf->reset_val = newval;
6226  set_extra_field(&conf->gen, &conf->reset_extra,
6227  newextra);
6228  conf->gen.reset_source = source;
6229  conf->gen.reset_scontext = context;
6230  }
6231  for (stack = conf->gen.stack; stack; stack = stack->prev)
6232  {
6233  if (stack->source <= source)
6234  {
6235  stack->prior.val.boolval = newval;
6236  set_extra_field(&conf->gen, &stack->prior.extra,
6237  newextra);
6238  stack->source = source;
6239  stack->scontext = context;
6240  }
6241  }
6242  }
6243 
6244  /* Perhaps we didn't install newextra anywhere */
6245  if (newextra && !extra_field_used(&conf->gen, newextra))
6246  free(newextra);
6247  break;
6248 
6249 #undef newval
6250  }
6251 
6252  case PGC_INT:
6253  {
6254  struct config_int *conf = (struct config_int *) record;
6255 
6256 #define newval (newval_union.intval)
6257 
6258  if (value)
6259  {
6260  if (!parse_and_validate_value(record, name, value,
6261  source, elevel,
6262  &newval_union, &newextra))
6263  return 0;
6264  }
6265  else if (source == PGC_S_DEFAULT)
6266  {
6267  newval = conf->boot_val;
6268  if (!call_int_check_hook(conf, &newval, &newextra,
6269  source, elevel))
6270  return 0;
6271  }
6272  else
6273  {
6274  newval = conf->reset_val;
6275  newextra = conf->reset_extra;
6276  source = conf->gen.reset_source;
6277  context = conf->gen.reset_scontext;
6278  }
6279 
6280  if (prohibitValueChange)
6281  {
6282  if (*conf->variable != newval)
6283  {
6284  record->status |= GUC_PENDING_RESTART;
6285  ereport(elevel,
6286  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6287  errmsg("parameter \"%s\" cannot be changed without restarting the server",
6288  name)));
6289  return 0;
6290  }
6291  record->status &= ~GUC_PENDING_RESTART;
6292  return -1;
6293  }
6294 
6295  if (changeVal)
6296  {
6297  /* Save old value to support transaction abort */
6298  if (!makeDefault)
6299  push_old_value(&conf->gen, action);
6300 
6301  if (conf->assign_hook)
6302  conf->assign_hook(newval, newextra);
6303  *conf->variable = newval;
6304  set_extra_field(&conf->gen, &conf->gen.extra,
6305  newextra);
6306  conf->gen.source = source;
6307  conf->gen.scontext = context;
6308  }
6309  if (makeDefault)
6310  {
6311  GucStack *stack;
6312 
6313  if (conf->gen.reset_source <= source)
6314  {
6315  conf->reset_val = newval;
6316  set_extra_field(&conf->gen, &conf->reset_extra,
6317  newextra);
6318  conf->gen.reset_source = source;
6319  conf->gen.reset_scontext = context;
6320  }
6321  for (stack = conf->gen.stack; stack; stack = stack->prev)
6322  {
6323  if (stack->source <= source)
6324  {
6325  stack->prior.val.intval = newval;
6326  set_extra_field(&conf->gen, &stack->prior.extra,
6327  newextra);
6328  stack->source = source;
6329  stack->scontext = context;
6330  }
6331  }
6332  }
6333 
6334  /* Perhaps we didn't install newextra anywhere */
6335  if (newextra && !extra_field_used(&conf->gen, newextra))
6336  free(newextra);
6337  break;
6338 
6339 #undef newval
6340  }
6341 
6342  case PGC_REAL:
6343  {
6344  struct config_real *conf = (struct config_real *) record;
6345 
6346 #define newval (newval_union.realval)
6347 
6348  if (value)
6349  {
6350  if (!parse_and_validate_value(record, name, value,
6351  source, elevel,
6352  &newval_union, &newextra))
6353  return 0;
6354  }
6355  else if (source == PGC_S_DEFAULT)
6356  {
6357  newval = conf->boot_val;
6358  if (!call_real_check_hook(conf, &newval, &newextra,
6359  source, elevel))
6360  return 0;
6361  }
6362  else
6363  {
6364  newval = conf->reset_val;
6365  newextra = conf->reset_extra;
6366  source = conf->gen.reset_source;
6367  context = conf->gen.reset_scontext;
6368  }
6369 
6370  if (prohibitValueChange)
6371  {
6372  if (*conf->variable != newval)
6373  {
6374  record->status |= GUC_PENDING_RESTART;
6375  ereport(elevel,
6376  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6377  errmsg("parameter \"%s\" cannot be changed without restarting the server",
6378  name)));
6379  return 0;
6380  }
6381  record->status &= ~GUC_PENDING_RESTART;
6382  return -1;
6383  }
6384 
6385  if (changeVal)
6386  {
6387  /* Save old value to support transaction abort */
6388  if (!makeDefault)
6389  push_old_value(&conf->gen, action);
6390 
6391  if (conf->assign_hook)
6392  conf->assign_hook(newval, newextra);
6393  *conf->variable = newval;
6394  set_extra_field(&conf->gen, &conf->gen.extra,
6395  newextra);
6396  conf->gen.source = source;
6397  conf->gen.scontext = context;
6398  }
6399  if (makeDefault)
6400  {
6401  GucStack *stack;
6402 
6403  if (conf->gen.reset_source <= source)
6404  {
6405  conf->reset_val = newval;
6406  set_extra_field(&conf->gen, &conf->reset_extra,
6407  newextra);
6408  conf->gen.reset_source = source;
6409  conf->gen.reset_scontext = context;
6410  }
6411  for (stack = conf->gen.stack; stack; stack = stack->prev)
6412  {
6413  if (stack->source <= source)
6414  {
6415  stack->prior.val.realval = newval;
6416  set_extra_field(&conf->gen, &stack->prior.extra,
6417  newextra);
6418  stack->source = source;
6419  stack->scontext = context;
6420  }
6421  }
6422  }
6423 
6424  /* Perhaps we didn't install newextra anywhere */
6425  if (newextra && !extra_field_used(&conf->gen, newextra))
6426  free(newextra);
6427  break;
6428 
6429 #undef newval
6430  }
6431 
6432  case PGC_STRING:
6433  {
6434  struct config_string *conf = (struct config_string *) record;
6435 
6436 #define newval (newval_union.stringval)
6437 
6438  if (value)
6439  {
6440  if (!parse_and_validate_value(record, name, value,
6441  source, elevel,
6442  &newval_union, &newextra))
6443  return 0;
6444  }
6445  else if (source == PGC_S_DEFAULT)
6446  {
6447  /* non-NULL boot_val must always get strdup'd */
6448  if (conf->boot_val != NULL)
6449  {
6450  newval = guc_strdup(elevel, conf->boot_val);
6451  if (newval == NULL)
6452  return 0;
6453  }
6454  else
6455  newval = NULL;
6456 
6457  if (!call_string_check_hook(conf, &newval, &newextra,
6458  source, elevel))
6459  {
6460  free(newval);
6461  return 0;
6462  }
6463  }
6464  else
6465  {
6466  /*
6467  * strdup not needed, since reset_val is already under
6468  * guc.c's control
6469  */
6470  newval = conf->reset_val;
6471  newextra = conf->reset_extra;
6472  source = conf->gen.reset_source;
6473  context = conf->gen.reset_scontext;
6474  }
6475 
6476  if (prohibitValueChange)
6477  {
6478  /* newval shouldn't be NULL, so we're a bit sloppy here */
6479  if (*conf->variable == NULL || newval == NULL ||
6480  strcmp(*conf->variable, newval) != 0)
6481  {
6482  record->status |= GUC_PENDING_RESTART;
6483  ereport(elevel,
6484  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6485  errmsg("parameter \"%s\" cannot be changed without restarting the server",
6486  name)));
6487  return 0;
6488  }
6489  record->status &= ~GUC_PENDING_RESTART;
6490  return -1;
6491  }
6492 
6493  if (changeVal)
6494  {
6495  /* Save old value to support transaction abort */
6496  if (!makeDefault)
6497  push_old_value(&conf->gen, action);
6498 
6499  if (conf->assign_hook)
6500  conf->assign_hook(newval, newextra);
6501  set_string_field(conf, conf->variable, newval);
6502  set_extra_field(&conf->gen, &conf->gen.extra,
6503  newextra);
6504  conf->gen.source = source;
6505  conf->gen.scontext = context;
6506  }
6507 
6508  if (makeDefault)
6509  {
6510  GucStack *stack;
6511 
6512  if (conf->gen.reset_source <= source)
6513  {
6514  set_string_field(conf, &conf->reset_val, newval);
6515  set_extra_field(&conf->gen, &conf->reset_extra,
6516  newextra);
6517  conf->gen.reset_source = source;
6518  conf->gen.reset_scontext = context;
6519  }
6520  for (stack = conf->gen.stack; stack; stack = stack->prev)
6521  {
6522  if (stack->source <= source)
6523  {
6524  set_string_field(conf, &stack->prior.val.stringval,
6525  newval);
6526  set_extra_field(&conf->gen, &stack->prior.extra,
6527  newextra);
6528  stack->source = source;
6529  stack->scontext = context;
6530  }
6531  }
6532  }
6533 
6534  /* Perhaps we didn't install newval anywhere */
6535  if (newval && !string_field_used(conf, newval))
6536  free(newval);
6537  /* Perhaps we didn't install newextra anywhere */
6538  if (newextra && !extra_field_used(&conf->gen, newextra))
6539  free(newextra);
6540  break;
6541 
6542 #undef newval
6543  }
6544 
6545  case PGC_ENUM:
6546  {
6547  struct config_enum *conf = (struct config_enum *) record;
6548 
6549 #define newval (newval_union.enumval)
6550 
6551  if (value)
6552  {
6553  if (!parse_and_validate_value(record, name, value,
6554  source, elevel,
6555  &newval_union, &newextra))
6556  return 0;
6557  }
6558  else if (source == PGC_S_DEFAULT)
6559  {
6560  newval = conf->boot_val;
6561  if (!call_enum_check_hook(conf, &newval, &newextra,
6562  source, elevel))
6563  return 0;
6564  }
6565  else
6566  {
6567  newval = conf->reset_val;
6568  newextra = conf->reset_extra;
6569  source = conf->gen.reset_source;
6570  context = conf->gen.reset_scontext;
6571  }
6572 
6573  if (prohibitValueChange)
6574  {
6575  if (*conf->variable != newval)
6576  {
6577  record->status |= GUC_PENDING_RESTART;
6578  ereport(elevel,
6579  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6580  errmsg("parameter \"%s\" cannot be changed without restarting the server",
6581  name)));
6582  return 0;
6583  }
6584  record->status &= ~GUC_PENDING_RESTART;
6585  return -1;
6586  }
6587 
6588  if (changeVal)
6589  {
6590  /* Save old value to support transaction abort */
6591  if (!makeDefault)
6592  push_old_value(&conf->gen, action);
6593 
6594  if (conf->assign_hook)
6595  conf->assign_hook(newval, newextra);
6596  *conf->variable = newval;
6597  set_extra_field(&conf->gen, &conf->gen.extra,
6598  newextra);
6599  conf->gen.source = source;
6600  conf->gen.scontext = context;
6601  }
6602  if (makeDefault)
6603  {
6604  GucStack *stack;
6605 
6606  if (conf->gen.reset_source <= source)
6607  {
6608  conf->reset_val = newval;
6609  set_extra_field(&conf->gen, &conf->reset_extra,
6610  newextra);
6611  conf->gen.reset_source = source;
6612  conf->gen.reset_scontext = context;
6613  }
6614  for (stack = conf->gen.stack; stack; stack = stack->prev)
6615  {
6616  if (stack->source <= source)
6617  {
6618  stack->prior.val.enumval = newval;
6619  set_extra_field(&conf->gen, &stack->prior.extra,
6620  newextra);
6621  stack->source = source;
6622  stack->scontext = context;
6623  }
6624  }
6625  }
6626 
6627  /* Perhaps we didn't install newextra anywhere */
6628  if (newextra && !extra_field_used(&conf->