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

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

References baseSearchPathValid.

4001 {
4002  /*
4003  * We mark the path as needing recomputation, but don't do anything until
4004  * it's needed. This avoids trying to do database access during GUC
4005  * initialization, or outside a transaction.
4006  */
4007  baseSearchPathValid = false;
4008 }
static bool baseSearchPathValid
Definition: namespace.c:152
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 10044 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().

10045 {
10046  if (sync_method != new_sync_method)
10047  {
10048  /*
10049  * To ensure that no blocks escape unsynced, force an fsync on the
10050  * currently open log segment (if any). Also, if the open flag is
10051  * changing, close the log file so it will be reopened (with new flag
10052  * bit) at next use.
10053  */
10054  if (openLogFile >= 0)
10055  {
10057  if (pg_fsync(openLogFile) != 0)
10058  ereport(PANIC,
10060  errmsg("could not fsync log segment %s: %m",
10063  if (get_sync_bit(sync_method) != get_sync_bit(new_sync_method))
10064  XLogFileClose();
10065  }
10066  }
10067 }
static int get_sync_bit(int method)
Definition: xlog.c:9988
#define PANIC
Definition: elog.h:53
static XLogSegNo openLogSegNo
Definition: xlog.c:773
static void XLogFileClose(void)
Definition: xlog.c:3706
char * XLogFileNameP(TimeLineID tli, XLogSegNo segno)
Definition: xlog.c:10120
int errcode_for_file_access(void)
Definition: elog.c:598
static void pgstat_report_wait_end(void)
Definition: pgstat.h:1232
#define ereport(elevel, rest)
Definition: elog.h:122
static int openLogFile
Definition: xlog.c:772
TimeLineID ThisTimeLineID
Definition: xlog.c:179
static void pgstat_report_wait_start(uint32 wait_event_info)
Definition: pgstat.h:1208
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 5083 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().

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

References elog, and WARNING.

Referenced by StartTransaction().

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

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

5365 {
5366  int i;
5367 
5368  /*
5369  * Don't do anything unless talking to an interactive frontend of protocol
5370  * 3.0 or later.
5371  */
5372  if (whereToSendOutput != DestRemote ||
5374  return;
5375 
5376  reporting_enabled = true;
5377 
5378  /* Transmit initial values of interesting variables */
5379  for (i = 0; i < num_guc_variables; i++)
5380  {
5381  struct config_generic *conf = guc_variables[i];
5382 
5383  if (conf->flags & GUC_REPORT)
5384  ReportGUCOption(conf);
5385  }
5386 }
#define PG_PROTOCOL_MAJOR(v)
Definition: pqcomm.h:104
static int num_guc_variables
Definition: guc.c:3942
#define GUC_REPORT
Definition: guc.h:208
static struct config_generic ** guc_variables
Definition: guc.c:3939
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:5392
CommandDest whereToSendOutput
Definition: postgres.c:86
static bool reporting_enabled
Definition: guc.c:3950
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 3966 of file namespace.c.

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

3967 {
3968  char *rawname;
3969  List *namelist;
3970 
3971  /* Need a modifiable copy of string */
3972  rawname = pstrdup(*newval);
3973 
3974  /* Parse string into list of identifiers */
3975  if (!SplitIdentifierString(rawname, ',', &namelist))
3976  {
3977  /* syntax error in name list */
3978  GUC_check_errdetail("List syntax is invalid.");
3979  pfree(rawname);
3980  list_free(namelist);
3981  return false;
3982  }
3983 
3984  /*
3985  * We used to try to check that the named schemas exist, but there are
3986  * many valid use-cases for having search_path settings that include
3987  * schemas that don't exist; and often, we are not inside a transaction
3988  * here and so can't consult the system catalogs anyway. So now, the only
3989  * requirement is syntactic validity of the identifier list.
3990  */
3991 
3992  pfree(rawname);
3993  list_free(namelist);
3994 
3995  return true;
3996 }
#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:3240
#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:283
#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:78
#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:3240
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 4767 of file xlog.c.

References XLOGbuffers, and XLOGChooseNumBuffers().

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

7743 {
7744  struct config_bool *var;
7745 
7746  var = (struct config_bool *)
7747  init_custom_variable(name, short_desc, long_desc, context, flags,
7748  PGC_BOOL, sizeof(struct config_bool));
7749  var->variable = valueAddr;
7750  var->boot_val = bootValue;
7751  var->reset_val = bootValue;
7752  var->check_hook = check_hook;
7753  var->assign_hook = assign_hook;
7754  var->show_hook = show_hook;
7755  define_custom_variable(&var->gen);
7756 }
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:7501
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:7552
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 7844 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().

7855 {
7856  struct config_enum *var;
7857 
7858  var = (struct config_enum *)
7859  init_custom_variable(name, short_desc, long_desc, context, flags,
7860  PGC_ENUM, sizeof(struct config_enum));
7861  var->variable = valueAddr;
7862  var->boot_val = bootValue;
7863  var->reset_val = bootValue;
7864  var->options = options;
7865  var->check_hook = check_hook;
7866  var->assign_hook = assign_hook;
7867  var->show_hook = show_hook;
7868  define_custom_variable(&var->gen);
7869 }
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:7501
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:7552
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 7759 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().

7771 {
7772  struct config_int *var;
7773 
7774  var = (struct config_int *)
7775  init_custom_variable(name, short_desc, long_desc, context, flags,
7776  PGC_INT, sizeof(struct config_int));
7777  var->variable = valueAddr;
7778  var->boot_val = bootValue;
7779  var->reset_val = bootValue;
7780  var->min = minValue;
7781  var->max = maxValue;
7782  var->check_hook = check_hook;
7783  var->assign_hook = assign_hook;
7784  var->show_hook = show_hook;
7785  define_custom_variable(&var->gen);
7786 }
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:7501
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7552
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 7789 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().

7801 {
7802  struct config_real *var;
7803 
7804  var = (struct config_real *)
7805  init_custom_variable(name, short_desc, long_desc, context, flags,
7806  PGC_REAL, sizeof(struct config_real));
7807  var->variable = valueAddr;
7808  var->boot_val = bootValue;
7809  var->reset_val = bootValue;
7810  var->min = minValue;
7811  var->max = maxValue;
7812  var->check_hook = check_hook;
7813  var->assign_hook = assign_hook;
7814  var->show_hook = show_hook;
7815  define_custom_variable(&var->gen);
7816 }
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:7501
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:7552
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 7819 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().

7829 {
7830  struct config_string *var;
7831 
7832  var = (struct config_string *)
7833  init_custom_variable(name, short_desc, long_desc, context, flags,
7834  PGC_STRING, sizeof(struct config_string));
7835  var->variable = valueAddr;
7836  var->boot_val = bootValue;
7837  var->check_hook = check_hook;
7838  var->assign_hook = assign_hook;
7839  var->show_hook = show_hook;
7840  define_custom_variable(&var->gen);
7841 }
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:7501
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:7552
void EmitWarningsOnPlaceholders ( const char *  className)

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

7873 {
7874  int classLen = strlen(className);
7875  int i;
7876 
7877  for (i = 0; i < num_guc_variables; i++)
7878  {
7879  struct config_generic *var = guc_variables[i];
7880 
7881  if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
7882  strncmp(className, var->name, classLen) == 0 &&
7883  var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
7884  {
7885  ereport(WARNING,
7886  (errcode(ERRCODE_UNDEFINED_OBJECT),
7887  errmsg("unrecognized configuration parameter \"%s\"",
7888  var->name)));
7889  }
7890  }
7891 }
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:3942
#define ereport(elevel, rest)
Definition: elog.h:122
static struct config_generic ** guc_variables
Definition: guc.c:3939
#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 9095 of file guc.c.

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

Referenced by InitializeParallelDSM().

9096 {
9097  Size size;
9098  int i;
9099 
9100  /* Add space reqd for saving the data size of the guc state */
9101  size = sizeof(Size);
9102 
9103  /* Add up the space needed for each GUC variable */
9104  for (i = 0; i < num_guc_variables; i++)
9105  size = add_size(size,
9107 
9108  return size;
9109 }
static int num_guc_variables
Definition: guc.c:3942
static struct config_generic ** guc_variables
Definition: guc.c:3939
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:8997
int i
void ExecSetVariableStmt ( VariableSetStmt stmt,
bool  isTopLevel 
)

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

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

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

7414 {
7415  switch (stmt->kind)
7416  {
7417  case VAR_SET_VALUE:
7418  return flatten_set_variable_args(stmt->name, stmt->args);
7419  case VAR_SET_CURRENT:
7420  return GetConfigOptionByName(stmt->name, NULL, false);
7421  default:
7422  return NULL;
7423  }
7424 }
VariableSetKind kind
Definition: parsenodes.h:1938
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:8039
#define NULL
Definition: c.h:229
static char * flatten_set_variable_args(const char *name, List *args)
Definition: guc.c:6811
const char* GetConfigOption ( const char *  name,
bool  missing_ok,
bool  restrict_superuser 
)

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

6701 {
6702  struct config_generic *record;
6703  static char buffer[256];
6704 
6705  record = find_option(name, false, ERROR);
6706  if (record == NULL)
6707  {
6708  if (missing_ok)
6709  return NULL;
6710  ereport(ERROR,
6711  (errcode(ERRCODE_UNDEFINED_OBJECT),
6712  errmsg("unrecognized configuration parameter \"%s\"",
6713  name)));
6714  }
6715  if (restrict_superuser &&
6716  (record->flags & GUC_SUPERUSER_ONLY) &&
6718  ereport(ERROR,
6719  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6720  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
6721  name)));
6722 
6723  switch (record->vartype)
6724  {
6725  case PGC_BOOL:
6726  return *((struct config_bool *) record)->variable ? "on" : "off";
6727 
6728  case PGC_INT:
6729  snprintf(buffer, sizeof(buffer), "%d",
6730  *((struct config_int *) record)->variable);
6731  return buffer;
6732 
6733  case PGC_REAL:
6734  snprintf(buffer, sizeof(buffer), "%g",
6735  *((struct config_real *) record)->variable);
6736  return buffer;
6737 
6738  case PGC_STRING:
6739  return *((struct config_string *) record)->variable;
6740 
6741  case PGC_ENUM:
6742  return config_enum_lookup_by_value((struct config_enum *) record,
6743  *((struct config_enum *) record)->variable);
6744  }
6745  return NULL;
6746 }
Oid GetUserId(void)
Definition: miscinit.c:283
int errcode(int sqlerrcode)
Definition: elog.c:575
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5621
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:111
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4376
#define NULL
Definition: c.h:229
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:207
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 8039 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().

8040 {
8041  struct config_generic *record;
8042 
8043  record = find_option(name, false, ERROR);
8044  if (record == NULL)
8045  {
8046  if (missing_ok)
8047  {
8048  if (varname)
8049  *varname = NULL;
8050  return NULL;
8051  }
8052 
8053  ereport(ERROR,
8054  (errcode(ERRCODE_UNDEFINED_OBJECT),
8055  errmsg("unrecognized configuration parameter \"%s\"", name)));
8056  }
8057 
8058  if ((record->flags & GUC_SUPERUSER_ONLY) &&
8060  ereport(ERROR,
8061  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
8062  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
8063  name)));
8064 
8065  if (varname)
8066  *varname = record->name;
8067 
8068  return _ShowOption(record, true);
8069 }
static char * _ShowOption(struct config_generic *record, bool use_units)
Definition: guc.c:8637
Oid GetUserId(void)
Definition: miscinit.c:283
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:111
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4376
#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 8076 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().

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

6757 {
6758  struct config_generic *record;
6759  static char buffer[256];
6760 
6761  record = find_option(name, false, ERROR);
6762  if (record == NULL)
6763  ereport(ERROR,
6764  (errcode(ERRCODE_UNDEFINED_OBJECT),
6765  errmsg("unrecognized configuration parameter \"%s\"", name)));
6766  if ((record->flags & GUC_SUPERUSER_ONLY) &&
6768  ereport(ERROR,
6769  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6770  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
6771  name)));
6772 
6773  switch (record->vartype)
6774  {
6775  case PGC_BOOL:
6776  return ((struct config_bool *) record)->reset_val ? "on" : "off";
6777 
6778  case PGC_INT:
6779  snprintf(buffer, sizeof(buffer), "%d",
6780  ((struct config_int *) record)->reset_val);
6781  return buffer;
6782 
6783  case PGC_REAL:
6784  snprintf(buffer, sizeof(buffer), "%g",
6785  ((struct config_real *) record)->reset_val);
6786  return buffer;
6787 
6788  case PGC_STRING:
6789  return ((struct config_string *) record)->reset_val;
6790 
6791  case PGC_ENUM:
6792  return config_enum_lookup_by_value((struct config_enum *) record,
6793  ((struct config_enum *) record)->reset_val);
6794  }
6795  return NULL;
6796 }
Oid GetUserId(void)
Definition: miscinit.c:283
int errcode(int sqlerrcode)
Definition: elog.c:575
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5621
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:111
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4376
#define NULL
Definition: c.h:229
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:207
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797
int GetNumConfigOptions ( void  )

Definition at line 8341 of file guc.c.

References num_guc_variables.

Referenced by GucInfoMain(), and show_all_settings().

8342 {
8343  return num_guc_variables;
8344 }
static int num_guc_variables
Definition: guc.c:3942
void GetPGVariable ( const char *  name,
DestReceiver dest 
)

Definition at line 7898 of file guc.c.

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

Referenced by exec_replication_command(), and standard_ProcessUtility().

7899 {
7900  if (guc_name_compare(name, "all") == 0)
7901  ShowAllGUCConfig(dest);
7902  else
7903  ShowGUCConfigOption(name, dest);
7904 }
static void ShowGUCConfigOption(const char *name, DestReceiver *dest)
Definition: guc.c:7942
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:4437
static void ShowAllGUCConfig(DestReceiver *dest)
Definition: guc.c:7970
const char * name
Definition: encode.c:521
TupleDesc GetPGVariableResultDesc ( const char *  name)

Definition at line 7907 of file guc.c.

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

Referenced by UtilityTupleDescriptor().

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

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

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

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

9475 {
9476  struct config_generic *record;
9477  Datum datum;
9478  char *newval;
9479  ArrayType *a;
9480 
9481  Assert(name);
9482  Assert(value);
9483 
9484  /* test if the option is valid and we're allowed to set it */
9485  (void) validate_option_array_item(name, value, false);
9486 
9487  /* normalize name (converts obsolete GUC names to modern spellings) */
9488  record = find_option(name, false, WARNING);
9489  if (record)
9490  name = record->name;
9491 
9492  /* build new item for array */
9493  newval = psprintf("%s=%s", name, value);
9494  datum = CStringGetTextDatum(newval);
9495 
9496  if (array)
9497  {
9498  int index;
9499  bool isnull;
9500  int i;
9501 
9502  Assert(ARR_ELEMTYPE(array) == TEXTOID);
9503  Assert(ARR_NDIM(array) == 1);
9504  Assert(ARR_LBOUND(array)[0] == 1);
9505 
9506  index = ARR_DIMS(array)[0] + 1; /* add after end */
9507 
9508  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9509  {
9510  Datum d;
9511  char *current;
9512 
9513  d = array_ref(array, 1, &i,
9514  -1 /* varlenarray */ ,
9515  -1 /* TEXT's typlen */ ,
9516  false /* TEXT's typbyval */ ,
9517  'i' /* TEXT's typalign */ ,
9518  &isnull);
9519  if (isnull)
9520  continue;
9521  current = TextDatumGetCString(d);
9522 
9523  /* check for match up through and including '=' */
9524  if (strncmp(current, newval, strlen(name) + 1) == 0)
9525  {
9526  index = i;
9527  break;
9528  }
9529  }
9530 
9531  a = array_set(array, 1, &index,
9532  datum,
9533  false,
9534  -1 /* varlena array */ ,
9535  -1 /* TEXT's typlen */ ,
9536  false /* TEXT's typbyval */ ,
9537  'i' /* TEXT's typalign */ );
9538  }
9539  else
9540  a = construct_array(&datum, 1,
9541  TEXTOID,
9542  -1, false, 'i');
9543 
9544  return a;
9545 }
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:90
static bool validate_option_array_item(const char *name, const char *value, bool skipIfNoPermissions)
Definition: guc.c:9700
#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:4376
#define Assert(condition)
Definition: c.h:675
#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
static struct @121 value
#define ARR_ELEMTYPE(a)
Definition: array.h:273
ArrayType* GUCArrayDelete ( ArrayType array,
const char *  name 
)

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

9555 {
9556  struct config_generic *record;
9557  ArrayType *newarray;
9558  int i;
9559  int index;
9560 
9561  Assert(name);
9562 
9563  /* test if the option is valid and we're allowed to set it */
9564  (void) validate_option_array_item(name, NULL, false);
9565 
9566  /* normalize name (converts obsolete GUC names to modern spellings) */
9567  record = find_option(name, false, WARNING);
9568  if (record)
9569  name = record->name;
9570 
9571  /* if array is currently null, then surely nothing to delete */
9572  if (!array)
9573  return NULL;
9574 
9575  newarray = NULL;
9576  index = 1;
9577 
9578  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9579  {
9580  Datum d;
9581  char *val;
9582  bool isnull;
9583 
9584  d = array_ref(array, 1, &i,
9585  -1 /* varlenarray */ ,
9586  -1 /* TEXT's typlen */ ,
9587  false /* TEXT's typbyval */ ,
9588  'i' /* TEXT's typalign */ ,
9589  &isnull);
9590  if (isnull)
9591  continue;
9592  val = TextDatumGetCString(d);
9593 
9594  /* ignore entry if it's what we want to delete */
9595  if (strncmp(val, name, strlen(name)) == 0
9596  && val[strlen(name)] == '=')
9597  continue;
9598 
9599  /* else add it to the output array */
9600  if (newarray)
9601  newarray = array_set(newarray, 1, &index,
9602  d,
9603  false,
9604  -1 /* varlenarray */ ,
9605  -1 /* TEXT's typlen */ ,
9606  false /* TEXT's typbyval */ ,
9607  'i' /* TEXT's typalign */ );
9608  else
9609  newarray = construct_array(&d, 1,
9610  TEXTOID,
9611  -1, false, 'i');
9612 
9613  index++;
9614  }
9615 
9616  return newarray;
9617 }
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:90
static bool validate_option_array_item(const char *name, const char *value, bool skipIfNoPermissions)
Definition: guc.c:9700
#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:4376
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
const char * name
Definition: encode.c:521
int i
long val
Definition: informix.c:689
ArrayType* GUCArrayReset ( ArrayType array)

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

9627 {
9628  ArrayType *newarray;
9629  int i;
9630  int index;
9631 
9632  /* if array is currently null, nothing to do */
9633  if (!array)
9634  return NULL;
9635 
9636  /* if we're superuser, we can delete everything, so just do it */
9637  if (superuser())
9638  return NULL;
9639 
9640  newarray = NULL;
9641  index = 1;
9642 
9643  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9644  {
9645  Datum d;
9646  char *val;
9647  char *eqsgn;
9648  bool isnull;
9649 
9650  d = array_ref(array, 1, &i,
9651  -1 /* varlenarray */ ,
9652  -1 /* TEXT's typlen */ ,
9653  false /* TEXT's typbyval */ ,
9654  'i' /* TEXT's typalign */ ,
9655  &isnull);
9656  if (isnull)
9657  continue;
9658  val = TextDatumGetCString(d);
9659 
9660  eqsgn = strchr(val, '=');
9661  *eqsgn = '\0';
9662 
9663  /* skip if we have permission to delete it */
9664  if (validate_option_array_item(val, NULL, true))
9665  continue;
9666 
9667  /* else add it to the output array */
9668  if (newarray)
9669  newarray = array_set(newarray, 1, &index,
9670  d,
9671  false,
9672  -1 /* varlenarray */ ,
9673  -1 /* TEXT's typlen */ ,
9674  false /* TEXT's typbyval */ ,
9675  'i' /* TEXT's typalign */ );
9676  else
9677  newarray = construct_array(&d, 1,
9678  TEXTOID,
9679  -1, false, 'i');
9680 
9681  index++;
9682  pfree(val);
9683  }
9684 
9685  return newarray;
9686 }
#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:90
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:9700
#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 4471 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().

4472 {
4473  int i;
4474 
4475  /*
4476  * Before log_line_prefix could possibly receive a nonempty setting, make
4477  * sure that timezone processing is minimally alive (see elog.c).
4478  */
4480 
4481  /*
4482  * Build sorted array of all GUC variables.
4483  */
4485 
4486  /*
4487  * Load all variables with their compiled-in defaults, and initialize
4488  * status fields as needed.
4489  */
4490  for (i = 0; i < num_guc_variables; i++)
4491  {
4493  }
4494 
4495  guc_dirty = false;
4496 
4497  reporting_enabled = false;
4498 
4499  /*
4500  * Prevent any attempt to override the transaction modes from
4501  * non-interactive sources.
4502  */
4503  SetConfigOption("transaction_isolation", "default",
4505  SetConfigOption("transaction_read_only", "no",
4507  SetConfigOption("transaction_deferrable", "no",
4509 
4510  /*
4511  * For historical reasons, some GUC parameters can receive defaults from
4512  * environment variables. Process those settings.
4513  */
4515 }
void build_guc_variables(void)
Definition: guc.c:4203
static void InitializeGUCOptionsFromEnvironment(void)
Definition: guc.c:4527
void pg_timezone_initialize(void)
Definition: pgtz.c:345
static int num_guc_variables
Definition: guc.c:3942
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:6676
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:4573
static struct config_generic ** guc_variables
Definition: guc.c:3939
int i
static bool reporting_enabled
Definition: guc.c:3950
static bool guc_dirty
Definition: guc.c:3948
bool parse_int ( const char *  value,
int *  result,
int  flags,
const char **  hintmsg 
)

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

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

Definition at line 5587 of file guc.c.

References val.

Referenced by parse_and_validate_value(), and parse_one_reloption().

5588 {
5589  double val;
5590  char *endptr;
5591 
5592  if (result)
5593  *result = 0; /* suppress compiler warning */
5594 
5595  errno = 0;
5596  val = strtod(value, &endptr);
5597  if (endptr == value || errno == ERANGE)
5598  return false;
5599 
5600  /* allow whitespace after number */
5601  while (isspace((unsigned char) *endptr))
5602  endptr++;
5603  if (*endptr != '\0')
5604  return false;
5605 
5606  if (result)
5607  *result = val;
5608  return true;
5609 }
return result
Definition: formatting.c:1618
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 9378 of file guc.c.

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

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

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

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

9418 {
9419  int i;
9420 
9421  Assert(array != NULL);
9422  Assert(ARR_ELEMTYPE(array) == TEXTOID);
9423  Assert(ARR_NDIM(array) == 1);
9424  Assert(ARR_LBOUND(array)[0] == 1);
9425 
9426  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9427  {
9428  Datum d;
9429  bool isnull;
9430  char *s;
9431  char *name;
9432  char *value;
9433 
9434  d = array_ref(array, 1, &i,
9435  -1 /* varlenarray */ ,
9436  -1 /* TEXT's typlen */ ,
9437  false /* TEXT's typbyval */ ,
9438  'i' /* TEXT's typalign */ ,
9439  &isnull);
9440 
9441  if (isnull)
9442  continue;
9443 
9444  s = TextDatumGetCString(d);
9445 
9446  ParseLongOption(s, &name, &value);
9447  if (!value)
9448  {
9449  ereport(WARNING,
9450  (errcode(ERRCODE_SYNTAX_ERROR),
9451  errmsg("could not parse setting for parameter \"%s\"",
9452  name)));
9453  free(name);
9454  continue;
9455  }
9456 
9457  (void) set_config_option(name, value,
9458  context, source,
9459  action, true, 0, false);
9460 
9461  free(name);
9462  if (value)
9463  free(value);
9464  pfree(s);
9465  }
9466 }
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:9378
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
#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:675
#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
static struct @121 value
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:5912
#define ARR_ELEMTYPE(a)
Definition: array.h:273
GucContext context
Definition: guc_tables.h:147
void ResetAllOptions ( void  )

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

4869 {
4870  int i;
4871 
4872  for (i = 0; i < num_guc_variables; i++)
4873  {
4874  struct config_generic *gconf = guc_variables[i];
4875 
4876  /* Don't reset non-SET-able values */
4877  if (gconf->context != PGC_SUSET &&
4878  gconf->context != PGC_USERSET)
4879  continue;
4880  /* Don't reset if special exclusion from RESET ALL */
4881  if (gconf->flags & GUC_NO_RESET_ALL)
4882  continue;
4883  /* No need to reset if wasn't SET */
4884  if (gconf->source <= PGC_S_OVERRIDE)
4885  continue;
4886 
4887  /* Save old value to support transaction abort */
4889 
4890  switch (gconf->vartype)
4891  {
4892  case PGC_BOOL:
4893  {
4894  struct config_bool *conf = (struct config_bool *) gconf;
4895 
4896  if (conf->assign_hook)
4897  (*conf->assign_hook) (conf->reset_val,
4898  conf->reset_extra);
4899  *conf->variable = conf->reset_val;
4900  set_extra_field(&conf->gen, &conf->gen.extra,
4901  conf->reset_extra);
4902  break;
4903  }
4904  case PGC_INT:
4905  {
4906  struct config_int *conf = (struct config_int *) gconf;
4907 
4908  if (conf->assign_hook)
4909  (*conf->assign_hook) (conf->reset_val,
4910  conf->reset_extra);
4911  *conf->variable = conf->reset_val;
4912  set_extra_field(&conf->gen, &conf->gen.extra,
4913  conf->reset_extra);
4914  break;
4915  }
4916  case PGC_REAL:
4917  {
4918  struct config_real *conf = (struct config_real *) gconf;
4919 
4920  if (conf->assign_hook)
4921  (*conf->assign_hook) (conf->reset_val,
4922  conf->reset_extra);
4923  *conf->variable = conf->reset_val;
4924  set_extra_field(&conf->gen, &conf->gen.extra,
4925  conf->reset_extra);
4926  break;
4927  }
4928  case PGC_STRING:
4929  {
4930  struct config_string *conf = (struct config_string *) gconf;
4931 
4932  if (conf->assign_hook)
4933  (*conf->assign_hook) (conf->reset_val,
4934  conf->reset_extra);
4935  set_string_field(conf, conf->variable, conf->reset_val);
4936  set_extra_field(&conf->gen, &conf->gen.extra,
4937  conf->reset_extra);
4938  break;
4939  }
4940  case PGC_ENUM:
4941  {
4942  struct config_enum *conf = (struct config_enum *) gconf;
4943 
4944  if (conf->assign_hook)
4945  (*conf->assign_hook) (conf->reset_val,
4946  conf->reset_extra);
4947  *conf->variable = conf->reset_val;
4948  set_extra_field(&conf->gen, &conf->gen.extra,
4949  conf->reset_extra);
4950  break;
4951  }
4952  }
4953 
4954  gconf->source = gconf->reset_source;
4955  gconf->scontext = gconf->reset_scontext;
4956 
4957  if (gconf->flags & GUC_REPORT)
4958  ReportGUCOption(gconf);
4959  }
4960 }
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:4968
int * variable
Definition: guc_tables.h:195
int * variable
Definition: guc_tables.h:241
static int num_guc_variables
Definition: guc.c:3942
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:4113
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:4052
static struct config_generic ** guc_variables
Definition: guc.c:3939
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:5392
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 9320 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().

9321 {
9322  char *varname,
9323  *varvalue,
9324  *varsourcefile;
9325  int varsourceline;
9326  GucSource varsource;
9327  GucContext varscontext;
9328  char *srcptr = (char *) gucstate;
9329  char *srcend;
9330  Size len;
9331  int i;
9332 
9333  /* See comment at can_skip_gucvar(). */
9334  for (i = 0; i < num_guc_variables; i++)
9335  if (!can_skip_gucvar(guc_variables[i]))
9337 
9338  /* First item is the length of the subsequent data */
9339  memcpy(&len, gucstate, sizeof(len));
9340 
9341  srcptr += sizeof(len);
9342  srcend = srcptr + len;
9343 
9344  while (srcptr < srcend)
9345  {
9346  int result;
9347 
9348  varname = read_gucstate(&srcptr, srcend);
9349  varvalue = read_gucstate(&srcptr, srcend);
9350  varsourcefile = read_gucstate(&srcptr, srcend);
9351  if (varsourcefile[0])
9352  read_gucstate_binary(&srcptr, srcend,
9353  &varsourceline, sizeof(varsourceline));
9354  read_gucstate_binary(&srcptr, srcend,
9355  &varsource, sizeof(varsource));
9356  read_gucstate_binary(&srcptr, srcend,
9357  &varscontext, sizeof(varscontext));
9358 
9359  result = set_config_option(varname, varvalue, varscontext, varsource,
9360  GUC_ACTION_SET, true, ERROR, true);
9361  if (result <= 0)
9362  ereport(ERROR,
9363  (errcode(ERRCODE_INTERNAL_ERROR),
9364  errmsg("parameter \"%s\" could not be set", varname)));
9365  if (varsourcefile[0])
9366  set_config_sourcefile(varname, varsourcefile, varsourceline);
9367  }
9368 }
GucContext
Definition: guc.h:68
static void static void set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
Definition: guc.c:6642
static void read_gucstate_binary(char **srcptr, char *srcend, void *dest, Size size)
Definition: guc.c:9305
int errcode(int sqlerrcode)
Definition: elog.c:575
return result
Definition: formatting.c:1618
GucSource
Definition: guc.h:105
#define ERROR
Definition: elog.h:43
static int num_guc_variables
Definition: guc.c:3942
static bool can_skip_gucvar(struct config_generic *gconf)
Definition: guc.c:8984
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:4573
#define ereport(elevel, rest)
Definition: elog.h:122
static struct config_generic ** guc_variables
Definition: guc.c:3939
static char * read_gucstate(char **srcptr, char *srcend)
Definition: guc.c:9282
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:5912
bool SelectConfigFiles ( const char *  userDoption,
const char *  progname 
)

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

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

Definition at line 9242 of file guc.c.

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

Referenced by InitializeParallelDSM().

9243 {
9244  char *curptr;
9245  Size actual_size;
9246  Size bytes_left;
9247  int i;
9248  int i_role = -1;
9249 
9250  /* Reserve space for saving the actual size of the guc state */
9251  Assert(maxsize > sizeof(actual_size));
9252  curptr = start_address + sizeof(actual_size);
9253  bytes_left = maxsize - sizeof(actual_size);
9254 
9255  for (i = 0; i < num_guc_variables; i++)
9256  {
9257  /*
9258  * It's pretty ugly, but we've got to force "role" to be initialized
9259  * after "session_authorization"; otherwise, the latter will override
9260  * the former.
9261  */
9262  if (strcmp(guc_variables[i]->name, "role") == 0)
9263  i_role = i;
9264  else
9265  serialize_variable(&curptr, &bytes_left, guc_variables[i]);
9266  }
9267  if (i_role >= 0)
9268  serialize_variable(&curptr, &bytes_left, guc_variables[i_role]);
9269 
9270  /* Store actual size without assuming alignment of start_address. */
9271  actual_size = maxsize - bytes_left - sizeof(actual_size);
9272  memcpy(start_address, &actual_size, sizeof(actual_size));
9273 }
static void serialize_variable(char **destptr, Size *maxbytes, struct config_generic *gconf)
Definition: guc.c:9168
static int num_guc_variables
Definition: guc.c:3942
static struct config_generic ** guc_variables
Definition: guc.c:3939
#define Assert(condition)
Definition: c.h:675
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 5912 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().

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