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

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

References baseSearchPathValid.

4068 {
4069  /*
4070  * We mark the path as needing recomputation, but don't do anything until
4071  * it's needed. This avoids trying to do database access during GUC
4072  * initialization, or outside a transaction.
4073  */
4074  baseSearchPathValid = false;
4075 }
static bool baseSearchPathValid
Definition: namespace.c:153
void assign_temp_tablespaces ( const char *  newval,
void *  extra 
)

Definition at line 1262 of file tablespace.c.

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

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

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

10055 {
10056  if (sync_method != new_sync_method)
10057  {
10058  /*
10059  * To ensure that no blocks escape unsynced, force an fsync on the
10060  * currently open log segment (if any). Also, if the open flag is
10061  * changing, close the log file so it will be reopened (with new flag
10062  * bit) at next use.
10063  */
10064  if (openLogFile >= 0)
10065  {
10067  if (pg_fsync(openLogFile) != 0)
10068  ereport(PANIC,
10070  errmsg("could not fsync log segment %s: %m",
10073  if (get_sync_bit(sync_method) != get_sync_bit(new_sync_method))
10074  XLogFileClose();
10075  }
10076  }
10077 }
static int get_sync_bit(int method)
Definition: xlog.c:9998
#define PANIC
Definition: elog.h:53
static XLogSegNo openLogSegNo
Definition: xlog.c:771
static void XLogFileClose(void)
Definition: xlog.c:3705
char * XLogFileNameP(TimeLineID tli, XLogSegNo segno)
Definition: xlog.c:10130
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:770
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 5079 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().

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

References elog, and WARNING.

Referenced by StartTransaction().

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

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

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

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

4034 {
4035  char *rawname;
4036  List *namelist;
4037 
4038  /* Need a modifiable copy of string */
4039  rawname = pstrdup(*newval);
4040 
4041  /* Parse string into list of identifiers */
4042  if (!SplitIdentifierString(rawname, ',', &namelist))
4043  {
4044  /* syntax error in name list */
4045  GUC_check_errdetail("List syntax is invalid.");
4046  pfree(rawname);
4047  list_free(namelist);
4048  return false;
4049  }
4050 
4051  /*
4052  * We used to try to check that the named schemas exist, but there are
4053  * many valid use-cases for having search_path settings that include
4054  * schemas that don't exist; and often, we are not inside a transaction
4055  * here and so can't consult the system catalogs anyway. So now, the only
4056  * requirement is syntactic validity of the identifier list.
4057  */
4058 
4059  pfree(rawname);
4060  list_free(namelist);
4061 
4062  return true;
4063 }
#define GUC_check_errdetail
Definition: guc.h:407
char * pstrdup(const char *in)
Definition: mcxt.c:1077
void pfree(void *pointer)
Definition: mcxt.c:950
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3260
#define newval
void list_free(List *list)
Definition: list.c:1133
Definition: pg_list.h:45
bool check_temp_tablespaces ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 1157 of file tablespace.c.

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

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

Definition at line 4765 of file xlog.c.

References XLOGbuffers, and XLOGChooseNumBuffers().

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

7739 {
7740  struct config_bool *var;
7741 
7742  var = (struct config_bool *)
7743  init_custom_variable(name, short_desc, long_desc, context, flags,
7744  PGC_BOOL, sizeof(struct config_bool));
7745  var->variable = valueAddr;
7746  var->boot_val = bootValue;
7747  var->reset_val = bootValue;
7748  var->check_hook = check_hook;
7749  var->assign_hook = assign_hook;
7750  var->show_hook = show_hook;
7751  define_custom_variable(&var->gen);
7752 }
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:7497
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:7548
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 7840 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().

7851 {
7852  struct config_enum *var;
7853 
7854  var = (struct config_enum *)
7855  init_custom_variable(name, short_desc, long_desc, context, flags,
7856  PGC_ENUM, sizeof(struct config_enum));
7857  var->variable = valueAddr;
7858  var->boot_val = bootValue;
7859  var->reset_val = bootValue;
7860  var->options = options;
7861  var->check_hook = check_hook;
7862  var->assign_hook = assign_hook;
7863  var->show_hook = show_hook;
7864  define_custom_variable(&var->gen);
7865 }
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:7497
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:7548
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 7755 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().

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

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

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

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

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

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

Referenced by InitializeParallelDSM().

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

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

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

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

7410 {
7411  switch (stmt->kind)
7412  {
7413  case VAR_SET_VALUE:
7414  return flatten_set_variable_args(stmt->name, stmt->args);
7415  case VAR_SET_CURRENT:
7416  return GetConfigOptionByName(stmt->name, NULL, false);
7417  default:
7418  return NULL;
7419  }
7420 }
VariableSetKind kind
Definition: parsenodes.h:1957
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:8035
#define NULL
Definition: c.h:229
static char * flatten_set_variable_args(const char *name, List *args)
Definition: guc.c:6807
const char* GetConfigOption ( const char *  name,
bool  missing_ok,
bool  restrict_superuser 
)

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

6697 {
6698  struct config_generic *record;
6699  static char buffer[256];
6700 
6701  record = find_option(name, false, ERROR);
6702  if (record == NULL)
6703  {
6704  if (missing_ok)
6705  return NULL;
6706  ereport(ERROR,
6707  (errcode(ERRCODE_UNDEFINED_OBJECT),
6708  errmsg("unrecognized configuration parameter \"%s\"",
6709  name)));
6710  }
6711  if (restrict_superuser &&
6712  (record->flags & GUC_SUPERUSER_ONLY) &&
6714  ereport(ERROR,
6715  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6716  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
6717  name)));
6718 
6719  switch (record->vartype)
6720  {
6721  case PGC_BOOL:
6722  return *((struct config_bool *) record)->variable ? "on" : "off";
6723 
6724  case PGC_INT:
6725  snprintf(buffer, sizeof(buffer), "%d",
6726  *((struct config_int *) record)->variable);
6727  return buffer;
6728 
6729  case PGC_REAL:
6730  snprintf(buffer, sizeof(buffer), "%g",
6731  *((struct config_real *) record)->variable);
6732  return buffer;
6733 
6734  case PGC_STRING:
6735  return *((struct config_string *) record)->variable;
6736 
6737  case PGC_ENUM:
6738  return config_enum_lookup_by_value((struct config_enum *) record,
6739  *((struct config_enum *) record)->variable);
6740  }
6741  return NULL;
6742 }
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:5617
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
enum config_type vartype
Definition: guc_tables.h:153
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4837
#define DEFAULT_ROLE_READ_ALL_SETTINGS
Definition: pg_authid.h:106
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4372
#define NULL
Definition: c.h:229
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:214
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797
char* GetConfigOptionByName ( const char *  name,
const char **  varname,
bool  missing_ok 
)

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

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

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

6753 {
6754  struct config_generic *record;
6755  static char buffer[256];
6756 
6757  record = find_option(name, false, ERROR);
6758  if (record == NULL)
6759  ereport(ERROR,
6760  (errcode(ERRCODE_UNDEFINED_OBJECT),
6761  errmsg("unrecognized configuration parameter \"%s\"", name)));
6762  if ((record->flags & GUC_SUPERUSER_ONLY) &&
6764  ereport(ERROR,
6765  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6766  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
6767  name)));
6768 
6769  switch (record->vartype)
6770  {
6771  case PGC_BOOL:
6772  return ((struct config_bool *) record)->reset_val ? "on" : "off";
6773 
6774  case PGC_INT:
6775  snprintf(buffer, sizeof(buffer), "%d",
6776  ((struct config_int *) record)->reset_val);
6777  return buffer;
6778 
6779  case PGC_REAL:
6780  snprintf(buffer, sizeof(buffer), "%g",
6781  ((struct config_real *) record)->reset_val);
6782  return buffer;
6783 
6784  case PGC_STRING:
6785  return ((struct config_string *) record)->reset_val;
6786 
6787  case PGC_ENUM:
6788  return config_enum_lookup_by_value((struct config_enum *) record,
6789  ((struct config_enum *) record)->reset_val);
6790  }
6791  return NULL;
6792 }
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:5617
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
enum config_type vartype
Definition: guc_tables.h:153
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4837
#define DEFAULT_ROLE_READ_ALL_SETTINGS
Definition: pg_authid.h:106
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4372
#define NULL
Definition: c.h:229
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:214
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797
int GetNumConfigOptions ( void  )

Definition at line 8337 of file guc.c.

References num_guc_variables.

Referenced by GucInfoMain(), and show_all_settings().

8338 {
8339  return num_guc_variables;
8340 }
static int num_guc_variables
Definition: guc.c:3938
void GetPGVariable ( const char *  name,
DestReceiver dest 
)

Definition at line 7894 of file guc.c.

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

Referenced by exec_replication_command(), and standard_ProcessUtility().

7895 {
7896  if (guc_name_compare(name, "all") == 0)
7897  ShowAllGUCConfig(dest);
7898  else
7899  ShowGUCConfigOption(name, dest);
7900 }
static void ShowGUCConfigOption(const char *name, DestReceiver *dest)
Definition: guc.c:7938
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:4433
static void ShowAllGUCConfig(DestReceiver *dest)
Definition: guc.c:7966
const char * name
Definition: encode.c:521
TupleDesc GetPGVariableResultDesc ( const char *  name)

Definition at line 7903 of file guc.c.

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

Referenced by UtilityTupleDescriptor().

7904 {
7905  TupleDesc tupdesc;
7906 
7907  if (guc_name_compare(name, "all") == 0)
7908  {
7909  /* need a tuple descriptor representing three TEXT columns */
7910  tupdesc = CreateTemplateTupleDesc(3, false);
7911  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
7912  TEXTOID, -1, 0);
7913  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
7914  TEXTOID, -1, 0);
7915  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
7916  TEXTOID, -1, 0);
7917  }
7918  else
7919  {
7920  const char *varname;
7921 
7922  /* Get the canonical spelling of name */
7923  (void) GetConfigOptionByName(name, &varname, false);
7924 
7925  /* need a tuple descriptor representing a single TEXT column */
7926  tupdesc = CreateTemplateTupleDesc(1, false);
7927  TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
7928  TEXTOID, -1, 0);
7929  }
7930  return tupdesc;
7931 }
#define TEXTOID
Definition: pg_type.h:324
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:4433
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:8035
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 9773 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().

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

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

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

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

9551 {
9552  struct config_generic *record;
9553  ArrayType *newarray;
9554  int i;
9555  int index;
9556 
9557  Assert(name);
9558 
9559  /* test if the option is valid and we're allowed to set it */
9560  (void) validate_option_array_item(name, NULL, false);
9561 
9562  /* normalize name (converts obsolete GUC names to modern spellings) */
9563  record = find_option(name, false, WARNING);
9564  if (record)
9565  name = record->name;
9566 
9567  /* if array is currently null, then surely nothing to delete */
9568  if (!array)
9569  return NULL;
9570 
9571  newarray = NULL;
9572  index = 1;
9573 
9574  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9575  {
9576  Datum d;
9577  char *val;
9578  bool isnull;
9579 
9580  d = array_ref(array, 1, &i,
9581  -1 /* varlenarray */ ,
9582  -1 /* TEXT's typlen */ ,
9583  false /* TEXT's typbyval */ ,
9584  'i' /* TEXT's typalign */ ,
9585  &isnull);
9586  if (isnull)
9587  continue;
9588  val = TextDatumGetCString(d);
9589 
9590  /* ignore entry if it's what we want to delete */
9591  if (strncmp(val, name, strlen(name)) == 0
9592  && val[strlen(name)] == '=')
9593  continue;
9594 
9595  /* else add it to the output array */
9596  if (newarray)
9597  newarray = array_set(newarray, 1, &index,
9598  d,
9599  false,
9600  -1 /* varlenarray */ ,
9601  -1 /* TEXT's typlen */ ,
9602  false /* TEXT's typbyval */ ,
9603  'i' /* TEXT's typalign */ );
9604  else
9605  newarray = construct_array(&d, 1,
9606  TEXTOID,
9607  -1, false, 'i');
9608 
9609  index++;
9610  }
9611 
9612  return newarray;
9613 }
const char * name
Definition: guc_tables.h:146
#define TEXTOID
Definition: pg_type.h:324
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3306
ArrayType * array_set(ArrayType *array, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3080
Definition: type.h:89
static bool validate_option_array_item(const char *name, const char *value, bool skipIfNoPermissions)
Definition: guc.c:9696
#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:4372
#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 9622 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().

9623 {
9624  ArrayType *newarray;
9625  int i;
9626  int index;
9627 
9628  /* if array is currently null, nothing to do */
9629  if (!array)
9630  return NULL;
9631 
9632  /* if we're superuser, we can delete everything, so just do it */
9633  if (superuser())
9634  return NULL;
9635 
9636  newarray = NULL;
9637  index = 1;
9638 
9639  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9640  {
9641  Datum d;
9642  char *val;
9643  char *eqsgn;
9644  bool isnull;
9645 
9646  d = array_ref(array, 1, &i,
9647  -1 /* varlenarray */ ,
9648  -1 /* TEXT's typlen */ ,
9649  false /* TEXT's typbyval */ ,
9650  'i' /* TEXT's typalign */ ,
9651  &isnull);
9652  if (isnull)
9653  continue;
9654  val = TextDatumGetCString(d);
9655 
9656  eqsgn = strchr(val, '=');
9657  *eqsgn = '\0';
9658 
9659  /* skip if we have permission to delete it */
9660  if (validate_option_array_item(val, NULL, true))
9661  continue;
9662 
9663  /* else add it to the output array */
9664  if (newarray)
9665  newarray = array_set(newarray, 1, &index,
9666  d,
9667  false,
9668  -1 /* varlenarray */ ,
9669  -1 /* TEXT's typlen */ ,
9670  false /* TEXT's typbyval */ ,
9671  'i' /* TEXT's typalign */ );
9672  else
9673  newarray = construct_array(&d, 1,
9674  TEXTOID,
9675  -1, false, 'i');
9676 
9677  index++;
9678  pfree(val);
9679  }
9680 
9681  return newarray;
9682 }
#define TEXTOID
Definition: pg_type.h:324
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3306
bool superuser(void)
Definition: superuser.c:47
ArrayType * array_set(ArrayType *array, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3080
Definition: type.h:89
void pfree(void *pointer)
Definition: mcxt.c:950
static bool validate_option_array_item(const char *name, const char *value, bool skipIfNoPermissions)
Definition: guc.c:9696
#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 4467 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().

4468 {
4469  int i;
4470 
4471  /*
4472  * Before log_line_prefix could possibly receive a nonempty setting, make
4473  * sure that timezone processing is minimally alive (see elog.c).
4474  */
4476 
4477  /*
4478  * Build sorted array of all GUC variables.
4479  */
4481 
4482  /*
4483  * Load all variables with their compiled-in defaults, and initialize
4484  * status fields as needed.
4485  */
4486  for (i = 0; i < num_guc_variables; i++)
4487  {
4489  }
4490 
4491  guc_dirty = false;
4492 
4493  reporting_enabled = false;
4494 
4495  /*
4496  * Prevent any attempt to override the transaction modes from
4497  * non-interactive sources.
4498  */
4499  SetConfigOption("transaction_isolation", "default",
4501  SetConfigOption("transaction_read_only", "no",
4503  SetConfigOption("transaction_deferrable", "no",
4505 
4506  /*
4507  * For historical reasons, some GUC parameters can receive defaults from
4508  * environment variables. Process those settings.
4509  */
4511 }
void build_guc_variables(void)
Definition: guc.c:4199
static void InitializeGUCOptionsFromEnvironment(void)
Definition: guc.c:4523
void pg_timezone_initialize(void)
Definition: pgtz.c:370
static int num_guc_variables
Definition: guc.c:3938
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:6672
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:4569
static struct config_generic ** guc_variables
Definition: guc.c:3935
int i
static bool reporting_enabled
Definition: guc.c:3946
static bool guc_dirty
Definition: guc.c:3944
bool parse_int ( const char *  value,
int *  result,
int  flags,
const char **  hintmsg 
)

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

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

Definition at line 5583 of file guc.c.

References val.

Referenced by parse_and_validate_value(), and parse_one_reloption().

5584 {
5585  double val;
5586  char *endptr;
5587 
5588  if (result)
5589  *result = 0; /* suppress compiler warning */
5590 
5591  errno = 0;
5592  val = strtod(value, &endptr);
5593  if (endptr == value || errno == ERANGE)
5594  return false;
5595 
5596  /* allow whitespace after number */
5597  while (isspace((unsigned char) *endptr))
5598  endptr++;
5599  if (*endptr != '\0')
5600  return false;
5601 
5602  if (result)
5603  *result = val;
5604  return true;
5605 }
return result
Definition: formatting.c:1633
static struct @121 value
long val
Definition: informix.c:689
bool ParseConfigDirectory ( const char *  includedir,
const char *  calling_file,
int  calling_lineno,
int  depth,
int  elevel,
ConfigVariable **  head_p,
ConfigVariable **  tail_p 
)
bool ParseConfigFile ( const char *  config_file,
bool  strict,
const char *  calling_file,
int  calling_lineno,
int  depth,
int  elevel,
ConfigVariable **  head_p,
ConfigVariable **  tail_p 
)
bool ParseConfigFp ( FILE *  fp,
const char *  config_file,
int  depth,
int  elevel,
ConfigVariable **  head_p,
ConfigVariable **  tail_p 
)
void ParseLongOption ( const char *  string,
char **  name,
char **  value 
)

Definition at line 9374 of file guc.c.

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

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

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

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

9414 {
9415  int i;
9416 
9417  Assert(array != NULL);
9418  Assert(ARR_ELEMTYPE(array) == TEXTOID);
9419  Assert(ARR_NDIM(array) == 1);
9420  Assert(ARR_LBOUND(array)[0] == 1);
9421 
9422  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9423  {
9424  Datum d;
9425  bool isnull;
9426  char *s;
9427  char *name;
9428  char *value;
9429 
9430  d = array_ref(array, 1, &i,
9431  -1 /* varlenarray */ ,
9432  -1 /* TEXT's typlen */ ,
9433  false /* TEXT's typbyval */ ,
9434  'i' /* TEXT's typalign */ ,
9435  &isnull);
9436 
9437  if (isnull)
9438  continue;
9439 
9440  s = TextDatumGetCString(d);
9441 
9442  ParseLongOption(s, &name, &value);
9443  if (!value)
9444  {
9445  ereport(WARNING,
9446  (errcode(ERRCODE_SYNTAX_ERROR),
9447  errmsg("could not parse setting for parameter \"%s\"",
9448  name)));
9449  free(name);
9450  continue;
9451  }
9452 
9453  (void) set_config_option(name, value,
9454  context, source,
9455  action, true, 0, false);
9456 
9457  free(name);
9458  if (value)
9459  free(value);
9460  pfree(s);
9461  }
9462 }
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:9374
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ARR_LBOUND(a)
Definition: array.h:277
void pfree(void *pointer)
Definition: mcxt.c:950
#define ARR_DIMS(a)
Definition: array.h:275
static struct @121 value
#define ereport(elevel, rest)
Definition: elog.h:122
Datum array_ref(ArrayType *array, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:3063
#define WARNING
Definition: elog.h:40
#define TextDatumGetCString(d)
Definition: builtins.h:92
uintptr_t Datum
Definition: postgres.h:372
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h: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
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:5908
#define ARR_ELEMTYPE(a)
Definition: array.h:273
GucContext context
Definition: guc_tables.h:147
void ResetAllOptions ( void  )

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

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

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

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

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

Definition at line 9238 of file guc.c.

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

Referenced by InitializeParallelDSM().

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

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