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_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 411 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 229 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_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 226 of file guc.h.

Referenced by GetConfigOptionByNum().

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

Definition at line 224 of file guc.h.

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

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

Definition at line 225 of file guc.h.

Referenced by _PG_init(), and GetConfigOptionByNum().

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

Definition at line 227 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 7081 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, NULL, 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(), unlink(), value, VAR_RESET, VAR_RESET_ALL, VAR_SET_DEFAULT, VAR_SET_VALUE, config_generic::vartype, and write_auto_conf_file().

Referenced by standard_ProcessUtility().

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

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

10061 {
10062  if (sync_method != new_sync_method)
10063  {
10064  /*
10065  * To ensure that no blocks escape unsynced, force an fsync on the
10066  * currently open log segment (if any). Also, if the open flag is
10067  * changing, close the log file so it will be reopened (with new flag
10068  * bit) at next use.
10069  */
10070  if (openLogFile >= 0)
10071  {
10073  if (pg_fsync(openLogFile) != 0)
10074  ereport(PANIC,
10076  errmsg("could not fsync log segment %s: %m",
10079  if (get_sync_bit(sync_method) != get_sync_bit(new_sync_method))
10080  XLogFileClose();
10081  }
10082  }
10083 }
static int get_sync_bit(int method)
Definition: xlog.c:10004
#define PANIC
Definition: elog.h:53
static XLogSegNo openLogSegNo
Definition: xlog.c:771
static void XLogFileClose(void)
Definition: xlog.c:3705
char * XLogFileNameP(TimeLineID tli, XLogSegNo segno)
Definition: xlog.c:10136
int errcode_for_file_access(void)
Definition: elog.c:598
static void pgstat_report_wait_end(void)
Definition: pgstat.h:1235
#define ereport(elevel, rest)
Definition: elog.h:122
static int openLogFile
Definition: xlog.c:770
TimeLineID ThisTimeLineID
Definition: xlog.c:179
static void pgstat_report_wait_start(uint32 wait_event_info)
Definition: pgstat.h:1211
int sync_method
Definition: xlog.c:103
int errmsg(const char *fmt,...)
Definition: elog.c:797
int pg_fsync(int fd)
Definition: fd.c:333
void AtEOXact_GUC ( bool  isCommit,
int  nestLevel 
)

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

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

References elog, and WARNING.

Referenced by StartTransaction().

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

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

5372 {
5373  int i;
5374 
5375  /*
5376  * Don't do anything unless talking to an interactive frontend of protocol
5377  * 3.0 or later.
5378  */
5379  if (whereToSendOutput != DestRemote ||
5381  return;
5382 
5383  reporting_enabled = true;
5384 
5385  /* Transmit initial values of interesting variables */
5386  for (i = 0; i < num_guc_variables; i++)
5387  {
5388  struct config_generic *conf = guc_variables[i];
5389 
5390  if (conf->flags & GUC_REPORT)
5391  ReportGUCOption(conf);
5392  }
5393 }
#define PG_PROTOCOL_MAJOR(v)
Definition: pqcomm.h:104
static int num_guc_variables
Definition: guc.c:3949
#define GUC_REPORT
Definition: guc.h:208
static struct config_generic ** guc_variables
Definition: guc.c:3946
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:5399
CommandDest whereToSendOutput
Definition: postgres.c:88
static bool reporting_enabled
Definition: guc.c:3957
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:407
int errcode(int sqlerrcode)
Definition: elog.c:575
#define OidIsValid(objectId)
Definition: c.h:538
#define ereport(elevel, rest)
Definition: elog.h:122
#define NOTICE
Definition: elog.h:37
#define newval
bool IsTransactionState(void)
Definition: xact.c:350
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:407
char * pstrdup(const char *in)
Definition: mcxt.c:1077
void pfree(void *pointer)
Definition: mcxt.c:950
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3260
#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:407
char * pstrdup(const char *in)
Definition: mcxt.c:1077
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:950
#define ACL_CREATE
Definition: parsenodes.h:82
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3260
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:170
#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:350
void * palloc(Size size)
Definition: mcxt.c:849
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:555
bool check_wal_buffers ( int *  newval,
void **  extra,
GucSource  source 
)

Definition at line 4771 of file xlog.c.

References XLOGbuffers, and XLOGChooseNumBuffers().

4772 {
4773  /*
4774  * -1 indicates a request for auto-tune.
4775  */
4776  if (*newval == -1)
4777  {
4778  /*
4779  * If we haven't yet changed the boot_val default of -1, just let it
4780  * be. We'll fix it when XLOGShmemSize is called.
4781  */
4782  if (XLOGbuffers == -1)
4783  return true;
4784 
4785  /* Otherwise, substitute the auto-tune value */
4787  }
4788 
4789  /*
4790  * We clamp manually-set values to at least 4 blocks. Prior to PostgreSQL
4791  * 9.1, a minimum of 4 was enforced by guc.c, but since that is no longer
4792  * the case, we just silently treat such values as a request for the
4793  * minimum. (We could throw an error instead, but that doesn't seem very
4794  * helpful.)
4795  */
4796  if (*newval < 4)
4797  *newval = 4;
4798 
4799  return true;
4800 }
static int XLOGChooseNumBuffers(void)
Definition: xlog.c:4755
#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 7740 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().

7750 {
7751  struct config_bool *var;
7752 
7753  var = (struct config_bool *)
7754  init_custom_variable(name, short_desc, long_desc, context, flags,
7755  PGC_BOOL, sizeof(struct config_bool));
7756  var->variable = valueAddr;
7757  var->boot_val = bootValue;
7758  var->reset_val = bootValue;
7759  var->check_hook = check_hook;
7760  var->assign_hook = assign_hook;
7761  var->show_hook = show_hook;
7762  define_custom_variable(&var->gen);
7763 }
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:7508
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:7559
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 7851 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().

7862 {
7863  struct config_enum *var;
7864 
7865  var = (struct config_enum *)
7866  init_custom_variable(name, short_desc, long_desc, context, flags,
7867  PGC_ENUM, sizeof(struct config_enum));
7868  var->variable = valueAddr;
7869  var->boot_val = bootValue;
7870  var->reset_val = bootValue;
7871  var->options = options;
7872  var->check_hook = check_hook;
7873  var->assign_hook = assign_hook;
7874  var->show_hook = show_hook;
7875  define_custom_variable(&var->gen);
7876 }
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:7508
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:7559
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 7766 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().

7778 {
7779  struct config_int *var;
7780 
7781  var = (struct config_int *)
7782  init_custom_variable(name, short_desc, long_desc, context, flags,
7783  PGC_INT, sizeof(struct config_int));
7784  var->variable = valueAddr;
7785  var->boot_val = bootValue;
7786  var->reset_val = bootValue;
7787  var->min = minValue;
7788  var->max = maxValue;
7789  var->check_hook = check_hook;
7790  var->assign_hook = assign_hook;
7791  var->show_hook = show_hook;
7792  define_custom_variable(&var->gen);
7793 }
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:7508
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7559
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 7796 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().

7808 {
7809  struct config_real *var;
7810 
7811  var = (struct config_real *)
7812  init_custom_variable(name, short_desc, long_desc, context, flags,
7813  PGC_REAL, sizeof(struct config_real));
7814  var->variable = valueAddr;
7815  var->boot_val = bootValue;
7816  var->reset_val = bootValue;
7817  var->min = minValue;
7818  var->max = maxValue;
7819  var->check_hook = check_hook;
7820  var->assign_hook = assign_hook;
7821  var->show_hook = show_hook;
7822  define_custom_variable(&var->gen);
7823 }
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:7508
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:7559
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 7826 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().

7836 {
7837  struct config_string *var;
7838 
7839  var = (struct config_string *)
7840  init_custom_variable(name, short_desc, long_desc, context, flags,
7841  PGC_STRING, sizeof(struct config_string));
7842  var->variable = valueAddr;
7843  var->boot_val = bootValue;
7844  var->check_hook = check_hook;
7845  var->assign_hook = assign_hook;
7846  var->show_hook = show_hook;
7847  define_custom_variable(&var->gen);
7848 }
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:7508
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:7559
void EmitWarningsOnPlaceholders ( const char *  className)

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

7880 {
7881  int classLen = strlen(className);
7882  int i;
7883 
7884  for (i = 0; i < num_guc_variables; i++)
7885  {
7886  struct config_generic *var = guc_variables[i];
7887 
7888  if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
7889  strncmp(className, var->name, classLen) == 0 &&
7890  var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
7891  {
7892  ereport(WARNING,
7893  (errcode(ERRCODE_UNDEFINED_OBJECT),
7894  errmsg("unrecognized configuration parameter \"%s\"",
7895  var->name)));
7896  }
7897  }
7898 }
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:3949
#define ereport(elevel, rest)
Definition: elog.h:122
static struct config_generic ** guc_variables
Definition: guc.c:3946
#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:3949
static struct config_generic ** guc_variables
Definition: guc.c:3946
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
size_t Size
Definition: c.h:356
static Size estimate_variable_size(struct config_generic *gconf)
Definition: guc.c:9004
int i
void ExecSetVariableStmt ( VariableSetStmt stmt,
bool  isTopLevel 
)

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

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

Definition at line 7420 of file guc.c.

References VariableSetStmt::args, flatten_set_variable_args(), GetConfigOptionByName(), VariableSetStmt::kind, VariableSetStmt::name, NULL, VAR_SET_CURRENT, and VAR_SET_VALUE.

Referenced by AlterSetting(), AlterSystemSetConfigFile(), ExecSetVariableStmt(), and update_proconfig_value().

7421 {
7422  switch (stmt->kind)
7423  {
7424  case VAR_SET_VALUE:
7425  return flatten_set_variable_args(stmt->name, stmt->args);
7426  case VAR_SET_CURRENT:
7427  return GetConfigOptionByName(stmt->name, NULL, false);
7428  default:
7429  return NULL;
7430  }
7431 }
VariableSetKind kind
Definition: parsenodes.h:1965
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:8046
#define NULL
Definition: c.h:229
static char * flatten_set_variable_args(const char *name, List *args)
Definition: guc.c:6818
const char* GetConfigOption ( const char *  name,
bool  missing_ok,
bool  restrict_superuser 
)

Definition at line 6707 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(), NULL, PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_STRING, snprintf(), and config_generic::vartype.

Referenced by applyRemoteGucs(), and PostmasterMain().

6708 {
6709  struct config_generic *record;
6710  static char buffer[256];
6711 
6712  record = find_option(name, false, ERROR);
6713  if (record == NULL)
6714  {
6715  if (missing_ok)
6716  return NULL;
6717  ereport(ERROR,
6718  (errcode(ERRCODE_UNDEFINED_OBJECT),
6719  errmsg("unrecognized configuration parameter \"%s\"",
6720  name)));
6721  }
6722  if (restrict_superuser &&
6723  (record->flags & GUC_SUPERUSER_ONLY) &&
6725  ereport(ERROR,
6726  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6727  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
6728  name)));
6729 
6730  switch (record->vartype)
6731  {
6732  case PGC_BOOL:
6733  return *((struct config_bool *) record)->variable ? "on" : "off";
6734 
6735  case PGC_INT:
6736  snprintf(buffer, sizeof(buffer), "%d",
6737  *((struct config_int *) record)->variable);
6738  return buffer;
6739 
6740  case PGC_REAL:
6741  snprintf(buffer, sizeof(buffer), "%g",
6742  *((struct config_real *) record)->variable);
6743  return buffer;
6744 
6745  case PGC_STRING:
6746  return *((struct config_string *) record)->variable;
6747 
6748  case PGC_ENUM:
6749  return config_enum_lookup_by_value((struct config_enum *) record,
6750  *((struct config_enum *) record)->variable);
6751  }
6752  return NULL;
6753 }
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:5628
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:4837
#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:4383
#define NULL
Definition: c.h:229
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 8046 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(), config_generic::name, and NULL.

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

8047 {
8048  struct config_generic *record;
8049 
8050  record = find_option(name, false, ERROR);
8051  if (record == NULL)
8052  {
8053  if (missing_ok)
8054  {
8055  if (varname)
8056  *varname = NULL;
8057  return NULL;
8058  }
8059 
8060  ereport(ERROR,
8061  (errcode(ERRCODE_UNDEFINED_OBJECT),
8062  errmsg("unrecognized configuration parameter \"%s\"", name)));
8063  }
8064 
8065  if ((record->flags & GUC_SUPERUSER_ONLY) &&
8067  ereport(ERROR,
8068  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
8069  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
8070  name)));
8071 
8072  if (varname)
8073  *varname = record->name;
8074 
8075  return _ShowOption(record, true);
8076 }
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:4837
#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:4383
#define NULL
Definition: c.h:229
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 8083 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_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, NULL, 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().

8084 {
8085  char buffer[256];
8086  struct config_generic *conf;
8087 
8088  /* check requested variable number valid */
8089  Assert((varnum >= 0) && (varnum < num_guc_variables));
8090 
8091  conf = guc_variables[varnum];
8092 
8093  if (noshow)
8094  {
8095  if ((conf->flags & GUC_NO_SHOW_ALL) ||
8096  ((conf->flags & GUC_SUPERUSER_ONLY) &&
8098  *noshow = true;
8099  else
8100  *noshow = false;
8101  }
8102 
8103  /* first get the generic attributes */
8104 
8105  /* name */
8106  values[0] = conf->name;
8107 
8108  /* setting : use _ShowOption in order to avoid duplicating the logic */
8109  values[1] = _ShowOption(conf, false);
8110 
8111  /* unit */
8112  if (conf->vartype == PGC_INT)
8113  {
8114  switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
8115  {
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:674
char * pstrdup(const char *in)
Definition: mcxt.c:1077
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:5628
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:530
#define GUC_UNIT_MIN
Definition: guc.h:226
const char *const config_group_names[]
Definition: guc.c:567
#define ERROR
Definition: elog.h:43
#define GUC_UNIT_XBLOCKS
Definition: guc.h:220
static int num_guc_variables
Definition: guc.c:3949
#define GUC_UNIT_S
Definition: guc.h:225
char * sourcefile
Definition: guc_tables.h:161
bool boot_val
Definition: guc_tables.h:182
static struct config_generic ** guc_variables
Definition: guc.c:3946
enum config_type vartype
Definition: guc_tables.h:153
#define GUC_UNIT_TIME
Definition: guc.h:227
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:4837
#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 NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:676
#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:163
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:546
static char * config_enum_get_options(struct config_enum *record, const char *prefix, const char *suffix, const char *separator)
Definition: guc.c:5677
#define GUC_UNIT_MS
Definition: guc.h:224
GucContext context
Definition: guc_tables.h:147
#define GUC_UNIT_MEMORY
Definition: guc.h:222
int reset_val
Definition: guc_tables.h:203
const char* GetConfigOptionResetString ( const char *  name)

Definition at line 6763 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(), NULL, PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_STRING, snprintf(), and config_generic::vartype.

Referenced by check_datestyle().

6764 {
6765  struct config_generic *record;
6766  static char buffer[256];
6767 
6768  record = find_option(name, false, ERROR);
6769  if (record == NULL)
6770  ereport(ERROR,
6771  (errcode(ERRCODE_UNDEFINED_OBJECT),
6772  errmsg("unrecognized configuration parameter \"%s\"", name)));
6773  if ((record->flags & GUC_SUPERUSER_ONLY) &&
6775  ereport(ERROR,
6776  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6777  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
6778  name)));
6779 
6780  switch (record->vartype)
6781  {
6782  case PGC_BOOL:
6783  return ((struct config_bool *) record)->reset_val ? "on" : "off";
6784 
6785  case PGC_INT:
6786  snprintf(buffer, sizeof(buffer), "%d",
6787  ((struct config_int *) record)->reset_val);
6788  return buffer;
6789 
6790  case PGC_REAL:
6791  snprintf(buffer, sizeof(buffer), "%g",
6792  ((struct config_real *) record)->reset_val);
6793  return buffer;
6794 
6795  case PGC_STRING:
6796  return ((struct config_string *) record)->reset_val;
6797 
6798  case PGC_ENUM:
6799  return config_enum_lookup_by_value((struct config_enum *) record,
6800  ((struct config_enum *) record)->reset_val);
6801  }
6802  return NULL;
6803 }
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:5628
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:4837
#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:4383
#define NULL
Definition: c.h:229
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:3949
void GetPGVariable ( const char *  name,
DestReceiver dest 
)

Definition at line 7905 of file guc.c.

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

Referenced by exec_replication_command(), and standard_ProcessUtility().

7906 {
7907  if (guc_name_compare(name, "all") == 0)
7908  ShowAllGUCConfig(dest);
7909  else
7910  ShowGUCConfigOption(name, dest);
7911 }
static void ShowGUCConfigOption(const char *name, DestReceiver *dest)
Definition: guc.c:7949
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:4444
static void ShowAllGUCConfig(DestReceiver *dest)
Definition: guc.c:7977
const char * name
Definition: encode.c:521
TupleDesc GetPGVariableResultDesc ( const char *  name)

Definition at line 7914 of file guc.c.

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

Referenced by UtilityTupleDescriptor().

7915 {
7916  TupleDesc tupdesc;
7917 
7918  if (guc_name_compare(name, "all") == 0)
7919  {
7920  /* need a tuple descriptor representing three TEXT columns */
7921  tupdesc = CreateTemplateTupleDesc(3, false);
7922  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
7923  TEXTOID, -1, 0);
7924  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
7925  TEXTOID, -1, 0);
7926  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
7927  TEXTOID, -1, 0);
7928  }
7929  else
7930  {
7931  const char *varname;
7932 
7933  /* Get the canonical spelling of name */
7934  (void) GetConfigOptionByName(name, &varname, false);
7935 
7936  /* need a tuple descriptor representing a single TEXT column */
7937  tupdesc = CreateTemplateTupleDesc(1, false);
7938  TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
7939  TEXTOID, -1, 0);
7940  }
7941  return tupdesc;
7942 }
#define TEXTOID
Definition: pg_type.h:324
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:4444
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:8046
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:489
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:3306
ArrayType * array_set(ArrayType *array, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3080
#define ARR_LBOUND(a)
Definition: array.h:277
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:275
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:3063
#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:4383
#define Assert(condition)
Definition: c.h:676
#define newval
#define ARR_NDIM(a)
Definition: array.h:271
const char * name
Definition: encode.c:521
int i
#define CStringGetTextDatum(s)
Definition: builtins.h:91
#define ARR_ELEMTYPE(a)
Definition: array.h:273
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, NULL, 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:3306
ArrayType * array_set(ArrayType *array, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3080
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:275
Datum array_ref(ArrayType *array, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:3063
#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:4383
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:676
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, NULL, 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:3306
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:3080
Definition: type.h:89
void pfree(void *pointer)
Definition: mcxt.c:950
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:275
Datum array_ref(ArrayType *array, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:3063
#define TextDatumGetCString(d)
Definition: builtins.h:92
uintptr_t Datum
Definition: postgres.h:372
#define NULL
Definition: c.h:229
int i
long val
Definition: informix.c:689
void InitializeGUCOptions ( void  )

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

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

Definition at line 5508 of file guc.c.

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

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

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

Definition at line 5594 of file guc.c.

References val.

Referenced by parse_and_validate_value(), and parse_one_reloption().

5595 {
5596  double val;
5597  char *endptr;
5598 
5599  if (result)
5600  *result = 0; /* suppress compiler warning */
5601 
5602  errno = 0;
5603  val = strtod(value, &endptr);
5604  if (endptr == value || errno == ERANGE)
5605  return false;
5606 
5607  /* allow whitespace after number */
5608  while (isspace((unsigned char) *endptr))
5609  endptr++;
5610  if (*endptr != '\0')
5611  return false;
5612 
5613  if (result)
5614  *result = val;
5615  return true;
5616 }
return result
Definition: formatting.c:1633
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(), NULL, 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:4019
#define FATAL
Definition: elog.h:52
static struct @121 value
#define AssertArg(condition)
Definition: c.h:678
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
#define NULL
Definition: c.h:229
const char * name
Definition: encode.c:521
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:3987
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, NULL, 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:277
void pfree(void *pointer)
Definition: mcxt.c:950
#define ARR_DIMS(a)
Definition: array.h:275
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:3063
#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 NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:676
#define ARR_NDIM(a)
Definition: array.h:271
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:5919
#define ARR_ELEMTYPE(a)
Definition: array.h:273
GucContext context
Definition: guc_tables.h:147
void ResetAllOptions ( void  )

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

4876 {
4877  int i;
4878 
4879  for (i = 0; i < num_guc_variables; i++)
4880  {
4881  struct config_generic *gconf = guc_variables[i];
4882 
4883  /* Don't reset non-SET-able values */
4884  if (gconf->context != PGC_SUSET &&
4885  gconf->context != PGC_USERSET)
4886  continue;
4887  /* Don't reset if special exclusion from RESET ALL */
4888  if (gconf->flags & GUC_NO_RESET_ALL)
4889  continue;
4890  /* No need to reset if wasn't SET */
4891  if (gconf->source <= PGC_S_OVERRIDE)
4892  continue;
4893 
4894  /* Save old value to support transaction abort */
4896 
4897  switch (gconf->vartype)
4898  {
4899  case PGC_BOOL:
4900  {
4901  struct config_bool *conf = (struct config_bool *) gconf;
4902 
4903  if (conf->assign_hook)
4904  (*conf->assign_hook) (conf->reset_val,
4905  conf->reset_extra);
4906  *conf->variable = conf->reset_val;
4907  set_extra_field(&conf->gen, &conf->gen.extra,
4908  conf->reset_extra);
4909  break;
4910  }
4911  case PGC_INT:
4912  {
4913  struct config_int *conf = (struct config_int *) gconf;
4914 
4915  if (conf->assign_hook)
4916  (*conf->assign_hook) (conf->reset_val,
4917  conf->reset_extra);
4918  *conf->variable = conf->reset_val;
4919  set_extra_field(&conf->gen, &conf->gen.extra,
4920  conf->reset_extra);
4921  break;
4922  }
4923  case PGC_REAL:
4924  {
4925  struct config_real *conf = (struct config_real *) gconf;
4926 
4927  if (conf->assign_hook)
4928  (*conf->assign_hook) (conf->reset_val,
4929  conf->reset_extra);
4930  *conf->variable = conf->reset_val;
4931  set_extra_field(&conf->gen, &conf->gen.extra,
4932  conf->reset_extra);
4933  break;
4934  }
4935  case PGC_STRING:
4936  {
4937  struct config_string *conf = (struct config_string *) gconf;
4938 
4939  if (conf->assign_hook)
4940  (*conf->assign_hook) (conf->reset_val,
4941  conf->reset_extra);
4942  set_string_field(conf, conf->variable, conf->reset_val);
4943  set_extra_field(&conf->gen, &conf->gen.extra,
4944  conf->reset_extra);
4945  break;
4946  }
4947  case PGC_ENUM:
4948  {
4949  struct config_enum *conf = (struct config_enum *) gconf;
4950 
4951  if (conf->assign_hook)
4952  (*conf->assign_hook) (conf->reset_val,
4953  conf->reset_extra);
4954  *conf->variable = conf->reset_val;
4955  set_extra_field(&conf->gen, &conf->gen.extra,
4956  conf->reset_extra);
4957  break;
4958  }
4959  }
4960 
4961  gconf->source = gconf->reset_source;
4962  gconf->scontext = gconf->reset_scontext;
4963 
4964  if (gconf->flags & GUC_REPORT)
4965  ReportGUCOption(gconf);
4966  }
4967 }
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:4975
int * variable
Definition: guc_tables.h:195
int * variable
Definition: guc_tables.h:241
static int num_guc_variables
Definition: guc.c:3949
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:4120
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:4059
static struct config_generic ** guc_variables
Definition: guc.c:3946
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:5399
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(), result, 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:6649
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
return result
Definition: formatting.c:1633
GucSource
Definition: guc.h:105
#define ERROR
Definition: elog.h:43
static int num_guc_variables
Definition: guc.c:3949
static bool can_skip_gucvar(struct config_generic *gconf)
Definition: guc.c:8991
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:4580
#define ereport(elevel, rest)
Definition: elog.h:122
static struct config_generic ** guc_variables
Definition: guc.c:3946
static char * read_gucstate(char **srcptr, char *srcend)
Definition: guc.c:9289
size_t Size
Definition: c.h:356
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:5919
bool SelectConfigFiles ( const char *  userDoption,
const char *  progname 
)

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

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

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