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_XSEGS   0x4000 /* value is in xlog segments */
 
#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:132
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_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 GUC_UNIT_XSEGS   0x4000 /* value is in xlog segments */

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

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

Definition at line 4000 of file namespace.c.

References baseSearchPathValid.

4001 {
4002  /*
4003  * We mark the path as needing recomputation, but don't do anything until
4004  * it's needed. This avoids trying to do database access during GUC
4005  * initialization, or outside a transaction.
4006  */
4007  baseSearchPathValid = false;
4008 }
static bool baseSearchPathValid
Definition: namespace.c:152
void assign_temp_tablespaces ( const char *  newval,
void *  extra 
)

Definition at line 1262 of file tablespace.c.

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

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

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

10034 {
10035  if (sync_method != new_sync_method)
10036  {
10037  /*
10038  * To ensure that no blocks escape unsynced, force an fsync on the
10039  * currently open log segment (if any). Also, if the open flag is
10040  * changing, close the log file so it will be reopened (with new flag
10041  * bit) at next use.
10042  */
10043  if (openLogFile >= 0)
10044  {
10046  if (pg_fsync(openLogFile) != 0)
10047  ereport(PANIC,
10049  errmsg("could not fsync log segment %s: %m",
10052  if (get_sync_bit(sync_method) != get_sync_bit(new_sync_method))
10053  XLogFileClose();
10054  }
10055  }
10056 }
static int get_sync_bit(int method)
Definition: xlog.c:9977
#define PANIC
Definition: elog.h:53
static XLogSegNo openLogSegNo
Definition: xlog.c:769
static void XLogFileClose(void)
Definition: xlog.c:3702
char * XLogFileNameP(TimeLineID tli, XLogSegNo segno)
Definition: xlog.c:10109
int errcode_for_file_access(void)
Definition: elog.c:598
static void pgstat_report_wait_end(void)
Definition: pgstat.h:1205
#define ereport(elevel, rest)
Definition: elog.h:122
static int openLogFile
Definition: xlog.c:768
TimeLineID ThisTimeLineID
Definition: xlog.c:179
static void pgstat_report_wait_start(uint32 wait_event_info)
Definition: pgstat.h:1181
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 5058 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().

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

Definition at line 5024 of file guc.c.

References elog, and WARNING.

Referenced by StartTransaction().

5025 {
5026  /*
5027  * The nest level should be 0 between transactions; if it isn't, somebody
5028  * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
5029  * throw a warning but make no other effort to clean up.
5030  */
5031  if (GUCNestLevel != 0)
5032  elog(WARNING, "GUC nest level = %d at transaction start",
5033  GUCNestLevel);
5034  GUCNestLevel = 1;
5035 }
static int GUCNestLevel
Definition: guc.c:3927
#define WARNING
Definition: elog.h:40
#define elog
Definition: elog.h:219
void BeginReportingGUCOptions ( void  )

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

5340 {
5341  int i;
5342 
5343  /*
5344  * Don't do anything unless talking to an interactive frontend of protocol
5345  * 3.0 or later.
5346  */
5347  if (whereToSendOutput != DestRemote ||
5349  return;
5350 
5351  reporting_enabled = true;
5352 
5353  /* Transmit initial values of interesting variables */
5354  for (i = 0; i < num_guc_variables; i++)
5355  {
5356  struct config_generic *conf = guc_variables[i];
5357 
5358  if (conf->flags & GUC_REPORT)
5359  ReportGUCOption(conf);
5360  }
5361 }
#define PG_PROTOCOL_MAJOR(v)
Definition: pqcomm.h:104
static int num_guc_variables
Definition: guc.c:3917
#define GUC_REPORT
Definition: guc.h:208
static struct config_generic ** guc_variables
Definition: guc.c:3914
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:5367
CommandDest whereToSendOutput
Definition: postgres.c:86
static bool reporting_enabled
Definition: guc.c:3925
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:154
#define GUC_check_errdetail
Definition: guc.h:407
int errcode(int sqlerrcode)
Definition: elog.c:575
#define OidIsValid(objectId)
Definition: c.h:538
#define ereport(elevel, rest)
Definition: elog.h:122
#define NOTICE
Definition: elog.h:37
#define newval
bool IsTransactionState(void)
Definition: xact.c:350
int errmsg(const char *fmt,...)
Definition: elog.c:797
bool check_search_path ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 3966 of file namespace.c.

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

3967 {
3968  char *rawname;
3969  List *namelist;
3970 
3971  /* Need a modifiable copy of string */
3972  rawname = pstrdup(*newval);
3973 
3974  /* Parse string into list of identifiers */
3975  if (!SplitIdentifierString(rawname, ',', &namelist))
3976  {
3977  /* syntax error in name list */
3978  GUC_check_errdetail("List syntax is invalid.");
3979  pfree(rawname);
3980  list_free(namelist);
3981  return false;
3982  }
3983 
3984  /*
3985  * We used to try to check that the named schemas exist, but there are
3986  * many valid use-cases for having search_path settings that include
3987  * schemas that don't exist; and often, we are not inside a transaction
3988  * here and so can't consult the system catalogs anyway. So now, the only
3989  * requirement is syntactic validity of the identifier list.
3990  */
3991 
3992  pfree(rawname);
3993  list_free(namelist);
3994 
3995  return true;
3996 }
#define GUC_check_errdetail
Definition: guc.h:407
char * pstrdup(const char *in)
Definition: mcxt.c:1077
void pfree(void *pointer)
Definition: mcxt.c:950
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3240
#define newval
void list_free(List *list)
Definition: list.c:1133
Definition: pg_list.h:45
bool check_temp_tablespaces ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 1157 of file tablespace.c.

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

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

References XLOGbuffers, and XLOGChooseNumBuffers().

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

7715 {
7716  struct config_bool *var;
7717 
7718  var = (struct config_bool *)
7719  init_custom_variable(name, short_desc, long_desc, context, flags,
7720  PGC_BOOL, sizeof(struct config_bool));
7721  var->variable = valueAddr;
7722  var->boot_val = bootValue;
7723  var->reset_val = bootValue;
7724  var->check_hook = check_hook;
7725  var->assign_hook = assign_hook;
7726  var->show_hook = show_hook;
7727  define_custom_variable(&var->gen);
7728 }
bool * variable
Definition: guc_tables.h:180
GucBoolAssignHook assign_hook
Definition: guc_tables.h:183
bool boot_val
Definition: guc_tables.h:181
struct config_generic gen
Definition: guc_tables.h:178
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:7473
GucBoolCheckHook check_hook
Definition: guc_tables.h:182
GucShowHook show_hook
Definition: guc_tables.h:184
const char * name
Definition: encode.c:521
bool reset_val
Definition: guc_tables.h:186
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7524
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 7816 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().

7827 {
7828  struct config_enum *var;
7829 
7830  var = (struct config_enum *)
7831  init_custom_variable(name, short_desc, long_desc, context, flags,
7832  PGC_ENUM, sizeof(struct config_enum));
7833  var->variable = valueAddr;
7834  var->boot_val = bootValue;
7835  var->reset_val = bootValue;
7836  var->options = options;
7837  var->check_hook = check_hook;
7838  var->assign_hook = assign_hook;
7839  var->show_hook = show_hook;
7840  define_custom_variable(&var->gen);
7841 }
GucEnumCheckHook check_hook
Definition: guc_tables.h:243
GucEnumAssignHook assign_hook
Definition: guc_tables.h:244
int * variable
Definition: guc_tables.h:240
const struct config_enum_entry * options
Definition: guc_tables.h:242
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:7473
GucShowHook show_hook
Definition: guc_tables.h:245
struct config_generic gen
Definition: guc_tables.h:238
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7524
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 7731 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().

7743 {
7744  struct config_int *var;
7745 
7746  var = (struct config_int *)
7747  init_custom_variable(name, short_desc, long_desc, context, flags,
7748  PGC_INT, sizeof(struct config_int));
7749  var->variable = valueAddr;
7750  var->boot_val = bootValue;
7751  var->reset_val = bootValue;
7752  var->min = minValue;
7753  var->max = maxValue;
7754  var->check_hook = check_hook;
7755  var->assign_hook = assign_hook;
7756  var->show_hook = show_hook;
7757  define_custom_variable(&var->gen);
7758 }
int boot_val
Definition: guc_tables.h:195
GucIntAssignHook assign_hook
Definition: guc_tables.h:199
GucIntCheckHook check_hook
Definition: guc_tables.h:198
GucShowHook show_hook
Definition: guc_tables.h:200
int * variable
Definition: guc_tables.h:194
struct config_generic gen
Definition: guc_tables.h:192
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:7473
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7524
int reset_val
Definition: guc_tables.h:202
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 7761 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().

7773 {
7774  struct config_real *var;
7775 
7776  var = (struct config_real *)
7777  init_custom_variable(name, short_desc, long_desc, context, flags,
7778  PGC_REAL, sizeof(struct config_real));
7779  var->variable = valueAddr;
7780  var->boot_val = bootValue;
7781  var->reset_val = bootValue;
7782  var->min = minValue;
7783  var->max = maxValue;
7784  var->check_hook = check_hook;
7785  var->assign_hook = assign_hook;
7786  var->show_hook = show_hook;
7787  define_custom_variable(&var->gen);
7788 }
GucRealAssignHook assign_hook
Definition: guc_tables.h:215
double reset_val
Definition: guc_tables.h:218
GucRealCheckHook check_hook
Definition: guc_tables.h:214
GucShowHook show_hook
Definition: guc_tables.h:216
double * variable
Definition: guc_tables.h:210
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:7473
double max
Definition: guc_tables.h:213
double boot_val
Definition: guc_tables.h:211
const char * name
Definition: encode.c:521
double min
Definition: guc_tables.h:212
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7524
struct config_generic gen
Definition: guc_tables.h:208
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 7791 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().

7801 {
7802  struct config_string *var;
7803 
7804  var = (struct config_string *)
7805  init_custom_variable(name, short_desc, long_desc, context, flags,
7806  PGC_STRING, sizeof(struct config_string));
7807  var->variable = valueAddr;
7808  var->boot_val = bootValue;
7809  var->check_hook = check_hook;
7810  var->assign_hook = assign_hook;
7811  var->show_hook = show_hook;
7812  define_custom_variable(&var->gen);
7813 }
char ** variable
Definition: guc_tables.h:226
GucStringCheckHook check_hook
Definition: guc_tables.h:228
const char * boot_val
Definition: guc_tables.h:227
GucShowHook show_hook
Definition: guc_tables.h:230
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:7473
struct config_generic gen
Definition: guc_tables.h:224
GucStringAssignHook assign_hook
Definition: guc_tables.h:229
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7524
void EmitWarningsOnPlaceholders ( const char *  className)

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

7845 {
7846  int classLen = strlen(className);
7847  int i;
7848 
7849  for (i = 0; i < num_guc_variables; i++)
7850  {
7851  struct config_generic *var = guc_variables[i];
7852 
7853  if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
7854  strncmp(className, var->name, classLen) == 0 &&
7855  var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
7856  {
7857  ereport(WARNING,
7858  (errcode(ERRCODE_UNDEFINED_OBJECT),
7859  errmsg("unrecognized configuration parameter \"%s\"",
7860  var->name)));
7861  }
7862  }
7863 }
const char * name
Definition: guc_tables.h:145
int errcode(int sqlerrcode)
Definition: elog.c:575
#define GUC_QUALIFIER_SEPARATOR
Definition: guc.h:199
static int num_guc_variables
Definition: guc.c:3917
#define ereport(elevel, rest)
Definition: elog.h:122
static struct config_generic ** guc_variables
Definition: guc.c:3914
#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 9066 of file guc.c.

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

Referenced by InitializeParallelDSM().

9067 {
9068  Size size;
9069  int i;
9070 
9071  /* Add space reqd for saving the data size of the guc state */
9072  size = sizeof(Size);
9073 
9074  /* Add up the space needed for each GUC variable */
9075  for (i = 0; i < num_guc_variables; i++)
9076  size = add_size(size,
9078 
9079  return size;
9080 }
static int num_guc_variables
Definition: guc.c:3917
static struct config_generic ** guc_variables
Definition: guc.c:3914
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:8968
int i
void ExecSetVariableStmt ( VariableSetStmt stmt,
bool  isTopLevel 
)

Definition at line 7261 of file guc.c.

References DefElem::arg, VariableSetStmt::args, Assert, castNode, DefElem::defname, elog, ereport, errcode(), errmsg(), ERROR, ExtractSetVariableArgs(), GUC_ACTION_LOCAL, GUC_ACTION_SET, ImportSnapshot(), VariableSetStmt::is_local, IsInParallelMode(), VariableSetStmt::kind, lfirst, linitial, 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().

7262 {
7264 
7265  /*
7266  * Workers synchronize these parameters at the start of the parallel
7267  * operation; then, we block SET during the operation.
7268  */
7269  if (IsInParallelMode())
7270  ereport(ERROR,
7271  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
7272  errmsg("cannot set parameters during a parallel operation")));
7273 
7274  switch (stmt->kind)
7275  {
7276  case VAR_SET_VALUE:
7277  case VAR_SET_CURRENT:
7278  if (stmt->is_local)
7279  WarnNoTransactionChain(isTopLevel, "SET LOCAL");
7280  (void) set_config_option(stmt->name,
7281  ExtractSetVariableArgs(stmt),
7283  PGC_S_SESSION,
7284  action, true, 0, false);
7285  break;
7286  case VAR_SET_MULTI:
7287 
7288  /*
7289  * Special-case SQL syntaxes. The TRANSACTION and SESSION
7290  * CHARACTERISTICS cases effectively set more than one variable
7291  * per statement. TRANSACTION SNAPSHOT only takes one argument,
7292  * but we put it here anyway since it's a special case and not
7293  * related to any GUC variable.
7294  */
7295  if (strcmp(stmt->name, "TRANSACTION") == 0)
7296  {
7297  ListCell *head;
7298 
7299  WarnNoTransactionChain(isTopLevel, "SET TRANSACTION");
7300 
7301  foreach(head, stmt->args)
7302  {
7303  DefElem *item = (DefElem *) lfirst(head);
7304 
7305  if (strcmp(item->defname, "transaction_isolation") == 0)
7306  SetPGVariable("transaction_isolation",
7307  list_make1(item->arg), stmt->is_local);
7308  else if (strcmp(item->defname, "transaction_read_only") == 0)
7309  SetPGVariable("transaction_read_only",
7310  list_make1(item->arg), stmt->is_local);
7311  else if (strcmp(item->defname, "transaction_deferrable") == 0)
7312  SetPGVariable("transaction_deferrable",
7313  list_make1(item->arg), stmt->is_local);
7314  else
7315  elog(ERROR, "unexpected SET TRANSACTION element: %s",
7316  item->defname);
7317  }
7318  }
7319  else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
7320  {
7321  ListCell *head;
7322 
7323  foreach(head, stmt->args)
7324  {
7325  DefElem *item = (DefElem *) lfirst(head);
7326 
7327  if (strcmp(item->defname, "transaction_isolation") == 0)
7328  SetPGVariable("default_transaction_isolation",
7329  list_make1(item->arg), stmt->is_local);
7330  else if (strcmp(item->defname, "transaction_read_only") == 0)
7331  SetPGVariable("default_transaction_read_only",
7332  list_make1(item->arg), stmt->is_local);
7333  else if (strcmp(item->defname, "transaction_deferrable") == 0)
7334  SetPGVariable("default_transaction_deferrable",
7335  list_make1(item->arg), stmt->is_local);
7336  else
7337  elog(ERROR, "unexpected SET SESSION element: %s",
7338  item->defname);
7339  }
7340  }
7341  else if (strcmp(stmt->name, "TRANSACTION SNAPSHOT") == 0)
7342  {
7343  A_Const *con = castNode(A_Const, linitial(stmt->args));
7344 
7345  if (stmt->is_local)
7346  ereport(ERROR,
7347  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7348  errmsg("SET LOCAL TRANSACTION SNAPSHOT is not implemented")));
7349 
7350  WarnNoTransactionChain(isTopLevel, "SET TRANSACTION");
7351  Assert(nodeTag(&con->val) == T_String);
7352  ImportSnapshot(strVal(&con->val));
7353  }
7354  else
7355  elog(ERROR, "unexpected SET MULTI element: %s",
7356  stmt->name);
7357  break;
7358  case VAR_SET_DEFAULT:
7359  if (stmt->is_local)
7360  WarnNoTransactionChain(isTopLevel, "SET LOCAL");
7361  /* fall through */
7362  case VAR_RESET:
7363  if (strcmp(stmt->name, "transaction_isolation") == 0)
7364  WarnNoTransactionChain(isTopLevel, "RESET TRANSACTION");
7365 
7366  (void) set_config_option(stmt->name,
7367  NULL,
7369  PGC_S_SESSION,
7370  action, true, 0, false);
7371  break;
7372  case VAR_RESET_ALL:
7373  ResetAllOptions();
7374  break;
7375  }
7376 }
void ImportSnapshot(const char *idstr)
Definition: snapmgr.c:1386
VariableSetKind kind
Definition: parsenodes.h:1918
#define castNode(_type_, nodeptr)
Definition: nodes.h:591
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:575
bool superuser(void)
Definition: superuser.c:47
GucAction
Definition: guc.h:191
#define list_make1(x1)
Definition: pg_list.h:133
bool IsInParallelMode(void)
Definition: xact.c:913
#define linitial(l)
Definition: pg_list.h:110
#define ERROR
Definition: elog.h:43
Definition: guc.h:75
void ResetAllOptions(void)
Definition: guc.c:4843
#define ereport(elevel, rest)
Definition: elog.h:122
Node * arg
Definition: parsenodes.h:709
void WarnNoTransactionChain(bool isTopLevel, const char *stmtType)
Definition: xact.c:3202
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#define lfirst(lc)
Definition: pg_list.h:106
#define nodeTag(nodeptr)
Definition: nodes.h:527
int errmsg(const char *fmt,...)
Definition: elog.c:797
char * defname
Definition: parsenodes.h:708
#define elog
Definition: elog.h:219
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
Definition: guc.c:7385
Value val
Definition: parsenodes.h:279
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:5887
void SetPGVariable(const char *name, List *args, bool is_local)
Definition: guc.c:7405
char* ExtractSetVariableArgs ( VariableSetStmt stmt)

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

7386 {
7387  switch (stmt->kind)
7388  {
7389  case VAR_SET_VALUE:
7390  return flatten_set_variable_args(stmt->name, stmt->args);
7391  case VAR_SET_CURRENT:
7392  return GetConfigOptionByName(stmt->name, NULL, false);
7393  default:
7394  return NULL;
7395  }
7396 }
VariableSetKind kind
Definition: parsenodes.h:1918
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:8011
#define NULL
Definition: c.h:229
static char * flatten_set_variable_args(const char *name, List *args)
Definition: guc.c:6783
const char* GetConfigOption ( const char *  name,
bool  missing_ok,
bool  restrict_superuser 
)

Definition at line 6675 of file guc.c.

References buffer, config_enum_lookup_by_value(), ereport, errcode(), errmsg(), ERROR, find_option(), config_generic::flags, GUC_SUPERUSER_ONLY, NULL, PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_STRING, snprintf(), superuser(), and config_generic::vartype.

Referenced by applyRemoteGucs(), and PostmasterMain().

6676 {
6677  struct config_generic *record;
6678  static char buffer[256];
6679 
6680  record = find_option(name, false, ERROR);
6681  if (record == NULL)
6682  {
6683  if (missing_ok)
6684  return NULL;
6685  ereport(ERROR,
6686  (errcode(ERRCODE_UNDEFINED_OBJECT),
6687  errmsg("unrecognized configuration parameter \"%s\"",
6688  name)));
6689  }
6690  if (restrict_superuser &&
6691  (record->flags & GUC_SUPERUSER_ONLY) &&
6692  !superuser())
6693  ereport(ERROR,
6694  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6695  errmsg("must be superuser to examine \"%s\"", name)));
6696 
6697  switch (record->vartype)
6698  {
6699  case PGC_BOOL:
6700  return *((struct config_bool *) record)->variable ? "on" : "off";
6701 
6702  case PGC_INT:
6703  snprintf(buffer, sizeof(buffer), "%d",
6704  *((struct config_int *) record)->variable);
6705  return buffer;
6706 
6707  case PGC_REAL:
6708  snprintf(buffer, sizeof(buffer), "%g",
6709  *((struct config_real *) record)->variable);
6710  return buffer;
6711 
6712  case PGC_STRING:
6713  return *((struct config_string *) record)->variable;
6714 
6715  case PGC_ENUM:
6716  return config_enum_lookup_by_value((struct config_enum *) record,
6717  *((struct config_enum *) record)->variable);
6718  }
6719  return NULL;
6720 }
int errcode(int sqlerrcode)
Definition: elog.c:575
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5596
bool superuser(void)
Definition: superuser.c:47
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:152
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4351
#define NULL
Definition: c.h:229
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:207
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797
char* GetConfigOptionByName ( const char *  name,
const char **  varname,
bool  missing_ok 
)

Definition at line 8011 of file guc.c.

References _ShowOption(), ereport, errcode(), errmsg(), ERROR, find_option(), config_generic::flags, GUC_SUPERUSER_ONLY, config_generic::name, NULL, and superuser().

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

8012 {
8013  struct config_generic *record;
8014 
8015  record = find_option(name, false, ERROR);
8016  if (record == NULL)
8017  {
8018  if (missing_ok)
8019  {
8020  if (varname)
8021  *varname = NULL;
8022  return NULL;
8023  }
8024 
8025  ereport(ERROR,
8026  (errcode(ERRCODE_UNDEFINED_OBJECT),
8027  errmsg("unrecognized configuration parameter \"%s\"", name)));
8028  }
8029 
8030  if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
8031  ereport(ERROR,
8032  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
8033  errmsg("must be superuser to examine \"%s\"", name)));
8034 
8035  if (varname)
8036  *varname = record->name;
8037 
8038  return _ShowOption(record, true);
8039 }
static char * _ShowOption(struct config_generic *record, bool use_units)
Definition: guc.c:8608
const char * name
Definition: guc_tables.h:145
int errcode(int sqlerrcode)
Definition: elog.c:575
bool superuser(void)
Definition: superuser.c:47
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4351
#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 8046 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, elog, ERROR, config_generic::flags, config_generic::group, GUC_NO_SHOW_ALL, GUC_PENDING_RESTART, GUC_SUPERUSER_ONLY, GUC_UNIT_BLOCKS, GUC_UNIT_KB, GUC_UNIT_MEMORY, GUC_UNIT_MIN, GUC_UNIT_MS, GUC_UNIT_S, GUC_UNIT_TIME, GUC_UNIT_XBLOCKS, GUC_UNIT_XSEGS, 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().

8047 {
8048  char buffer[256];
8049  struct config_generic *conf;
8050 
8051  /* check requested variable number valid */
8052  Assert((varnum >= 0) && (varnum < num_guc_variables));
8053 
8054  conf = guc_variables[varnum];
8055 
8056  if (noshow)
8057  {
8058  if ((conf->flags & GUC_NO_SHOW_ALL) ||
8059  ((conf->flags & GUC_SUPERUSER_ONLY) && !superuser()))
8060  *noshow = true;
8061  else
8062  *noshow = false;
8063  }
8064 
8065  /* first get the generic attributes */
8066 
8067  /* name */
8068  values[0] = conf->name;
8069 
8070  /* setting : use _ShowOption in order to avoid duplicating the logic */
8071  values[1] = _ShowOption(conf, false);
8072 
8073  /* unit */
8074  if (conf->vartype == PGC_INT)
8075  {
8076  switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
8077  {
8078  case GUC_UNIT_KB:
8079  values[2] = "kB";
8080  break;
8081  case GUC_UNIT_BLOCKS:
8082  snprintf(buffer, sizeof(buffer), "%dkB", BLCKSZ / 1024);
8083  values[2] = pstrdup(buffer);
8084  break;
8085  case GUC_UNIT_XBLOCKS:
8086  snprintf(buffer, sizeof(buffer), "%dkB", XLOG_BLCKSZ / 1024);
8087  values[2] = pstrdup(buffer);
8088  break;
8089  case GUC_UNIT_XSEGS:
8090  snprintf(buffer, sizeof(buffer), "%dMB",
8091  XLOG_SEG_SIZE / (1024 * 1024));
8092  values[2] = pstrdup(buffer);
8093  break;
8094  case GUC_UNIT_MS:
8095  values[2] = "ms";
8096  break;
8097  case GUC_UNIT_S:
8098  values[2] = "s";
8099  break;
8100  case GUC_UNIT_MIN:
8101  values[2] = "min";
8102  break;
8103  case 0:
8104  values[2] = NULL;
8105  break;
8106  default:
8107  elog(ERROR, "unrecognized GUC units value: %d",
8108  conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME));
8109  values[2] = NULL;
8110  break;
8111  }
8112  }
8113  else
8114  values[2] = NULL;
8115 
8116  /* group */
8117  values[3] = config_group_names[conf->group];
8118 
8119  /* short_desc */
8120  values[4] = conf->short_desc;
8121 
8122  /* extra_desc */
8123  values[5] = conf->long_desc;
8124 
8125  /* context */
8126  values[6] = GucContext_Names[conf->context];
8127 
8128  /* vartype */
8129  values[7] = config_type_names[conf->vartype];
8130 
8131  /* source */
8132  values[8] = GucSource_Names[conf->source];
8133 
8134  /* now get the type specific attributes */
8135  switch (conf->vartype)
8136  {
8137  case PGC_BOOL:
8138  {
8139  struct config_bool *lconf = (struct config_bool *) conf;
8140 
8141  /* min_val */
8142  values[9] = NULL;
8143 
8144  /* max_val */
8145  values[10] = NULL;
8146 
8147  /* enumvals */
8148  values[11] = NULL;
8149 
8150  /* boot_val */
8151  values[12] = pstrdup(lconf->boot_val ? "on" : "off");
8152 
8153  /* reset_val */
8154  values[13] = pstrdup(lconf->reset_val ? "on" : "off");
8155  }
8156  break;
8157 
8158  case PGC_INT:
8159  {
8160  struct config_int *lconf = (struct config_int *) conf;
8161 
8162  /* min_val */
8163  snprintf(buffer, sizeof(buffer), "%d", lconf->min);
8164  values[9] = pstrdup(buffer);
8165 
8166  /* max_val */
8167  snprintf(buffer, sizeof(buffer), "%d", lconf->max);
8168  values[10] = pstrdup(buffer);
8169 
8170  /* enumvals */
8171  values[11] = NULL;
8172 
8173  /* boot_val */
8174  snprintf(buffer, sizeof(buffer), "%d", lconf->boot_val);
8175  values[12] = pstrdup(buffer);
8176 
8177  /* reset_val */
8178  snprintf(buffer, sizeof(buffer), "%d", lconf->reset_val);
8179  values[13] = pstrdup(buffer);
8180  }
8181  break;
8182 
8183  case PGC_REAL:
8184  {
8185  struct config_real *lconf = (struct config_real *) conf;
8186 
8187  /* min_val */
8188  snprintf(buffer, sizeof(buffer), "%g", lconf->min);
8189  values[9] = pstrdup(buffer);
8190 
8191  /* max_val */
8192  snprintf(buffer, sizeof(buffer), "%g", lconf->max);
8193  values[10] = pstrdup(buffer);
8194 
8195  /* enumvals */
8196  values[11] = NULL;
8197 
8198  /* boot_val */
8199  snprintf(buffer, sizeof(buffer), "%g", lconf->boot_val);
8200  values[12] = pstrdup(buffer);
8201 
8202  /* reset_val */
8203  snprintf(buffer, sizeof(buffer), "%g", lconf->reset_val);
8204  values[13] = pstrdup(buffer);
8205  }
8206  break;
8207 
8208  case PGC_STRING:
8209  {
8210  struct config_string *lconf = (struct config_string *) conf;
8211 
8212  /* min_val */
8213  values[9] = NULL;
8214 
8215  /* max_val */
8216  values[10] = NULL;
8217 
8218  /* enumvals */
8219  values[11] = NULL;
8220 
8221  /* boot_val */
8222  if (lconf->boot_val == NULL)
8223  values[12] = NULL;
8224  else
8225  values[12] = pstrdup(lconf->boot_val);
8226 
8227  /* reset_val */
8228  if (lconf->reset_val == NULL)
8229  values[13] = NULL;
8230  else
8231  values[13] = pstrdup(lconf->reset_val);
8232  }
8233  break;
8234 
8235  case PGC_ENUM:
8236  {
8237  struct config_enum *lconf = (struct config_enum *) conf;
8238 
8239  /* min_val */
8240  values[9] = NULL;
8241 
8242  /* max_val */
8243  values[10] = NULL;
8244 
8245  /* enumvals */
8246 
8247  /*
8248  * NOTE! enumvals with double quotes in them are not
8249  * supported!
8250  */
8251  values[11] = config_enum_get_options((struct config_enum *) conf,
8252  "{\"", "\"}", "\",\"");
8253 
8254  /* boot_val */
8256  lconf->boot_val));
8257 
8258  /* reset_val */
8260  lconf->reset_val));
8261  }
8262  break;
8263 
8264  default:
8265  {
8266  /*
8267  * should never get here, but in case we do, set 'em to NULL
8268  */
8269 
8270  /* min_val */
8271  values[9] = NULL;
8272 
8273  /* max_val */
8274  values[10] = NULL;
8275 
8276  /* enumvals */
8277  values[11] = NULL;
8278 
8279  /* boot_val */
8280  values[12] = NULL;
8281 
8282  /* reset_val */
8283  values[13] = NULL;
8284  }
8285  break;
8286  }
8287 
8288  /*
8289  * If the setting came from a config file, set the source location. For
8290  * security reasons, we don't show source file/line number for
8291  * non-superusers.
8292  */
8293  if (conf->source == PGC_S_FILE && superuser())
8294  {
8295  values[14] = conf->sourcefile;
8296  snprintf(buffer, sizeof(buffer), "%d", conf->sourceline);
8297  values[15] = pstrdup(buffer);
8298  }
8299  else
8300  {
8301  values[14] = NULL;
8302  values[15] = NULL;
8303  }
8304 
8305  values[16] = (conf->status & GUC_PENDING_RESTART) ? "t" : "f";
8306 }
GucSource source
Definition: guc_tables.h:154
static char * _ShowOption(struct config_generic *record, bool use_units)
Definition: guc.c:8608
const char * long_desc
Definition: guc_tables.h:149
double reset_val
Definition: guc_tables.h:218
const char * name
Definition: guc_tables.h:145
const char *const config_type_names[]
Definition: guc.c:675
char * pstrdup(const char *in)
Definition: mcxt.c:1077
const char * short_desc
Definition: guc_tables.h:148
int boot_val
Definition: guc_tables.h:195
const char * boot_val
Definition: guc_tables.h:227
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5596
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:533
#define GUC_UNIT_MIN
Definition: guc.h:226
const char *const config_group_names[]
Definition: guc.c:570
#define ERROR
Definition: elog.h:43
#define GUC_UNIT_XBLOCKS
Definition: guc.h:220
static int num_guc_variables
Definition: guc.c:3917
#define GUC_UNIT_S
Definition: guc.h:225
char * sourcefile
Definition: guc_tables.h:160
bool boot_val
Definition: guc_tables.h:181
static struct config_generic ** guc_variables
Definition: guc.c:3914
enum config_type vartype
Definition: guc_tables.h:152
#define GUC_UNIT_TIME
Definition: guc.h:227
double max
Definition: guc_tables.h:213
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
char * reset_val
Definition: guc_tables.h:232
double boot_val
Definition: guc_tables.h:211
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#define GUC_PENDING_RESTART
Definition: guc_tables.h:171
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:207
double min
Definition: guc_tables.h:212
#define GUC_UNIT_XSEGS
Definition: guc.h:221
static Datum values[MAXATTR]
Definition: bootstrap.c:162
enum config_group group
Definition: guc_tables.h:147
#define elog
Definition: elog.h:219
bool reset_val
Definition: guc_tables.h:186
const char *const GucSource_Names[]
Definition: guc.c:549
static char * config_enum_get_options(struct config_enum *record, const char *prefix, const char *suffix, const char *separator)
Definition: guc.c:5645
#define GUC_UNIT_MS
Definition: guc.h:224
GucContext context
Definition: guc_tables.h:146
#define GUC_UNIT_MEMORY
Definition: guc.h:222
int reset_val
Definition: guc_tables.h:202
const char* GetConfigOptionResetString ( const char *  name)

Definition at line 6730 of file guc.c.

References buffer, config_enum_lookup_by_value(), ereport, errcode(), errmsg(), ERROR, find_option(), config_generic::flags, GUC_SUPERUSER_ONLY, NULL, PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_STRING, snprintf(), superuser(), and config_generic::vartype.

Referenced by check_datestyle().

6731 {
6732  struct config_generic *record;
6733  static char buffer[256];
6734 
6735  record = find_option(name, false, ERROR);
6736  if (record == NULL)
6737  ereport(ERROR,
6738  (errcode(ERRCODE_UNDEFINED_OBJECT),
6739  errmsg("unrecognized configuration parameter \"%s\"", name)));
6740  if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
6741  ereport(ERROR,
6742  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6743  errmsg("must be superuser to examine \"%s\"", name)));
6744 
6745  switch (record->vartype)
6746  {
6747  case PGC_BOOL:
6748  return ((struct config_bool *) record)->reset_val ? "on" : "off";
6749 
6750  case PGC_INT:
6751  snprintf(buffer, sizeof(buffer), "%d",
6752  ((struct config_int *) record)->reset_val);
6753  return buffer;
6754 
6755  case PGC_REAL:
6756  snprintf(buffer, sizeof(buffer), "%g",
6757  ((struct config_real *) record)->reset_val);
6758  return buffer;
6759 
6760  case PGC_STRING:
6761  return ((struct config_string *) record)->reset_val;
6762 
6763  case PGC_ENUM:
6764  return config_enum_lookup_by_value((struct config_enum *) record,
6765  ((struct config_enum *) record)->reset_val);
6766  }
6767  return NULL;
6768 }
int errcode(int sqlerrcode)
Definition: elog.c:575
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5596
bool superuser(void)
Definition: superuser.c:47
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:152
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4351
#define NULL
Definition: c.h:229
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:207
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797
int GetNumConfigOptions ( void  )

Definition at line 8312 of file guc.c.

References num_guc_variables.

Referenced by GucInfoMain(), and show_all_settings().

8313 {
8314  return num_guc_variables;
8315 }
static int num_guc_variables
Definition: guc.c:3917
void GetPGVariable ( const char *  name,
DestReceiver dest 
)

Definition at line 7870 of file guc.c.

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

Referenced by exec_replication_command(), and standard_ProcessUtility().

7871 {
7872  if (guc_name_compare(name, "all") == 0)
7873  ShowAllGUCConfig(dest);
7874  else
7875  ShowGUCConfigOption(name, dest);
7876 }
static void ShowGUCConfigOption(const char *name, DestReceiver *dest)
Definition: guc.c:7914
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:4412
static void ShowAllGUCConfig(DestReceiver *dest)
Definition: guc.c:7942
const char * name
Definition: encode.c:521
TupleDesc GetPGVariableResultDesc ( const char *  name)

Definition at line 7879 of file guc.c.

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

Referenced by UtilityTupleDescriptor().

7880 {
7881  TupleDesc tupdesc;
7882 
7883  if (guc_name_compare(name, "all") == 0)
7884  {
7885  /* need a tuple descriptor representing three TEXT columns */
7886  tupdesc = CreateTemplateTupleDesc(3, false);
7887  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
7888  TEXTOID, -1, 0);
7889  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
7890  TEXTOID, -1, 0);
7891  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
7892  TEXTOID, -1, 0);
7893  }
7894  else
7895  {
7896  const char *varname;
7897 
7898  /* Get the canonical spelling of name */
7899  (void) GetConfigOptionByName(name, &varname, false);
7900 
7901  /* need a tuple descriptor representing a single TEXT column */
7902  tupdesc = CreateTemplateTupleDesc(1, false);
7903  TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
7904  TEXTOID, -1, 0);
7905  }
7906  return tupdesc;
7907 }
#define TEXTOID
Definition: pg_type.h:324
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:4412
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:8011
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:493
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 9748 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().

9749 {
9750  GUC_check_errcode_value = sqlerrcode;
9751 }
static int GUC_check_errcode_value
Definition: guc.c:127
ArrayType* GUCArrayAdd ( ArrayType array,
const char *  name,
const char *  value 
)

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

9446 {
9447  struct config_generic *record;
9448  Datum datum;
9449  char *newval;
9450  ArrayType *a;
9451 
9452  Assert(name);
9453  Assert(value);
9454 
9455  /* test if the option is valid and we're allowed to set it */
9456  (void) validate_option_array_item(name, value, false);
9457 
9458  /* normalize name (converts obsolete GUC names to modern spellings) */
9459  record = find_option(name, false, WARNING);
9460  if (record)
9461  name = record->name;
9462 
9463  /* build new item for array */
9464  newval = psprintf("%s=%s", name, value);
9465  datum = CStringGetTextDatum(newval);
9466 
9467  if (array)
9468  {
9469  int index;
9470  bool isnull;
9471  int i;
9472 
9473  Assert(ARR_ELEMTYPE(array) == TEXTOID);
9474  Assert(ARR_NDIM(array) == 1);
9475  Assert(ARR_LBOUND(array)[0] == 1);
9476 
9477  index = ARR_DIMS(array)[0] + 1; /* add after end */
9478 
9479  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9480  {
9481  Datum d;
9482  char *current;
9483 
9484  d = array_ref(array, 1, &i,
9485  -1 /* varlenarray */ ,
9486  -1 /* TEXT's typlen */ ,
9487  false /* TEXT's typbyval */ ,
9488  'i' /* TEXT's typalign */ ,
9489  &isnull);
9490  if (isnull)
9491  continue;
9492  current = TextDatumGetCString(d);
9493 
9494  /* check for match up through and including '=' */
9495  if (strncmp(current, newval, strlen(name) + 1) == 0)
9496  {
9497  index = i;
9498  break;
9499  }
9500  }
9501 
9502  a = array_set(array, 1, &index,
9503  datum,
9504  false,
9505  -1 /* varlena array */ ,
9506  -1 /* TEXT's typlen */ ,
9507  false /* TEXT's typbyval */ ,
9508  'i' /* TEXT's typalign */ );
9509  }
9510  else
9511  a = construct_array(&datum, 1,
9512  TEXTOID,
9513  -1, false, 'i');
9514 
9515  return a;
9516 }
static struct @78 value
const char * name
Definition: guc_tables.h:145
#define TEXTOID
Definition: pg_type.h:324
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3306
ArrayType * array_set(ArrayType *array, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3080
#define ARR_LBOUND(a)
Definition: array.h:277
Definition: type.h:90
static bool validate_option_array_item(const char *name, const char *value, bool skipIfNoPermissions)
Definition: guc.c:9671
#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:4351
#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 9525 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().

9526 {
9527  struct config_generic *record;
9528  ArrayType *newarray;
9529  int i;
9530  int index;
9531 
9532  Assert(name);
9533 
9534  /* test if the option is valid and we're allowed to set it */
9535  (void) validate_option_array_item(name, NULL, false);
9536 
9537  /* normalize name (converts obsolete GUC names to modern spellings) */
9538  record = find_option(name, false, WARNING);
9539  if (record)
9540  name = record->name;
9541 
9542  /* if array is currently null, then surely nothing to delete */
9543  if (!array)
9544  return NULL;
9545 
9546  newarray = NULL;
9547  index = 1;
9548 
9549  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9550  {
9551  Datum d;
9552  char *val;
9553  bool isnull;
9554 
9555  d = array_ref(array, 1, &i,
9556  -1 /* varlenarray */ ,
9557  -1 /* TEXT's typlen */ ,
9558  false /* TEXT's typbyval */ ,
9559  'i' /* TEXT's typalign */ ,
9560  &isnull);
9561  if (isnull)
9562  continue;
9563  val = TextDatumGetCString(d);
9564 
9565  /* ignore entry if it's what we want to delete */
9566  if (strncmp(val, name, strlen(name)) == 0
9567  && val[strlen(name)] == '=')
9568  continue;
9569 
9570  /* else add it to the output array */
9571  if (newarray)
9572  newarray = array_set(newarray, 1, &index,
9573  d,
9574  false,
9575  -1 /* varlenarray */ ,
9576  -1 /* TEXT's typlen */ ,
9577  false /* TEXT's typbyval */ ,
9578  'i' /* TEXT's typalign */ );
9579  else
9580  newarray = construct_array(&d, 1,
9581  TEXTOID,
9582  -1, false, 'i');
9583 
9584  index++;
9585  }
9586 
9587  return newarray;
9588 }
const char * name
Definition: guc_tables.h:145
#define TEXTOID
Definition: pg_type.h:324
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3306
ArrayType * array_set(ArrayType *array, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3080
Definition: type.h:90
static bool validate_option_array_item(const char *name, const char *value, bool skipIfNoPermissions)
Definition: guc.c:9671
#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:4351
#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 9597 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().

9598 {
9599  ArrayType *newarray;
9600  int i;
9601  int index;
9602 
9603  /* if array is currently null, nothing to do */
9604  if (!array)
9605  return NULL;
9606 
9607  /* if we're superuser, we can delete everything, so just do it */
9608  if (superuser())
9609  return NULL;
9610 
9611  newarray = NULL;
9612  index = 1;
9613 
9614  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9615  {
9616  Datum d;
9617  char *val;
9618  char *eqsgn;
9619  bool isnull;
9620 
9621  d = array_ref(array, 1, &i,
9622  -1 /* varlenarray */ ,
9623  -1 /* TEXT's typlen */ ,
9624  false /* TEXT's typbyval */ ,
9625  'i' /* TEXT's typalign */ ,
9626  &isnull);
9627  if (isnull)
9628  continue;
9629  val = TextDatumGetCString(d);
9630 
9631  eqsgn = strchr(val, '=');
9632  *eqsgn = '\0';
9633 
9634  /* skip if we have permission to delete it */
9635  if (validate_option_array_item(val, NULL, true))
9636  continue;
9637 
9638  /* else add it to the output array */
9639  if (newarray)
9640  newarray = array_set(newarray, 1, &index,
9641  d,
9642  false,
9643  -1 /* varlenarray */ ,
9644  -1 /* TEXT's typlen */ ,
9645  false /* TEXT's typbyval */ ,
9646  'i' /* TEXT's typalign */ );
9647  else
9648  newarray = construct_array(&d, 1,
9649  TEXTOID,
9650  -1, false, 'i');
9651 
9652  index++;
9653  pfree(val);
9654  }
9655 
9656  return newarray;
9657 }
#define TEXTOID
Definition: pg_type.h:324
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3306
bool superuser(void)
Definition: superuser.c:47
ArrayType * array_set(ArrayType *array, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3080
Definition: type.h:90
void pfree(void *pointer)
Definition: mcxt.c:950
static bool validate_option_array_item(const char *name, const char *value, bool skipIfNoPermissions)
Definition: guc.c:9671
#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 4446 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().

4447 {
4448  int i;
4449 
4450  /*
4451  * Before log_line_prefix could possibly receive a nonempty setting, make
4452  * sure that timezone processing is minimally alive (see elog.c).
4453  */
4455 
4456  /*
4457  * Build sorted array of all GUC variables.
4458  */
4460 
4461  /*
4462  * Load all variables with their compiled-in defaults, and initialize
4463  * status fields as needed.
4464  */
4465  for (i = 0; i < num_guc_variables; i++)
4466  {
4468  }
4469 
4470  guc_dirty = false;
4471 
4472  reporting_enabled = false;
4473 
4474  /*
4475  * Prevent any attempt to override the transaction modes from
4476  * non-interactive sources.
4477  */
4478  SetConfigOption("transaction_isolation", "default",
4480  SetConfigOption("transaction_read_only", "no",
4482  SetConfigOption("transaction_deferrable", "no",
4484 
4485  /*
4486  * For historical reasons, some GUC parameters can receive defaults from
4487  * environment variables. Process those settings.
4488  */
4490 }
void build_guc_variables(void)
Definition: guc.c:4178
static void InitializeGUCOptionsFromEnvironment(void)
Definition: guc.c:4502
void pg_timezone_initialize(void)
Definition: pgtz.c:345
static int num_guc_variables
Definition: guc.c:3917
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:6651
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:4548
static struct config_generic ** guc_variables
Definition: guc.c:3914
int i
static bool reporting_enabled
Definition: guc.c:3925
static bool guc_dirty
Definition: guc.c:3923
bool parse_int ( const char *  value,
int *  result,
int  flags,
const char **  hintmsg 
)

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

5477 {
5478  int64 val;
5479  char *endptr;
5480 
5481  /* To suppress compiler warnings, always set output params */
5482  if (result)
5483  *result = 0;
5484  if (hintmsg)
5485  *hintmsg = NULL;
5486 
5487  /* We assume here that int64 is at least as wide as long */
5488  errno = 0;
5489  val = strtol(value, &endptr, 0);
5490 
5491  if (endptr == value)
5492  return false; /* no HINT for integer syntax error */
5493 
5494  if (errno == ERANGE || val != (int64) ((int32) val))
5495  {
5496  if (hintmsg)
5497  *hintmsg = gettext_noop("Value exceeds integer range.");
5498  return false;
5499  }
5500 
5501  /* allow whitespace between integer and unit */
5502  while (isspace((unsigned char) *endptr))
5503  endptr++;
5504 
5505  /* Handle possible unit */
5506  if (*endptr != '\0')
5507  {
5508  char unit[MAX_UNIT_LEN + 1];
5509  int unitlen;
5510  bool converted = false;
5511 
5512  if ((flags & GUC_UNIT) == 0)
5513  return false; /* this setting does not accept a unit */
5514 
5515  unitlen = 0;
5516  while (*endptr != '\0' && !isspace((unsigned char) *endptr) &&
5517  unitlen < MAX_UNIT_LEN)
5518  unit[unitlen++] = *(endptr++);
5519  unit[unitlen] = '\0';
5520  /* allow whitespace after unit */
5521  while (isspace((unsigned char) *endptr))
5522  endptr++;
5523 
5524  if (*endptr == '\0')
5525  converted = convert_to_base_unit(val, unit, (flags & GUC_UNIT),
5526  &val);
5527  if (!converted)
5528  {
5529  /* invalid unit, or garbage after the unit; set hint and fail. */
5530  if (hintmsg)
5531  {
5532  if (flags & GUC_UNIT_MEMORY)
5533  *hintmsg = memory_units_hint;
5534  else
5535  *hintmsg = time_units_hint;
5536  }
5537  return false;
5538  }
5539 
5540  /* Check for overflow due to units conversion */
5541  if (val != (int64) ((int32) val))
5542  {
5543  if (hintmsg)
5544  *hintmsg = gettext_noop("Value exceeds integer range.");
5545  return false;
5546  }
5547  }
5548 
5549  if (result)
5550  *result = (int) val;
5551  return true;
5552 }
static struct @78 value
#define MAX_UNIT_LEN
Definition: guc.c:699
#define gettext_noop(x)
Definition: c.h:139
return result
Definition: formatting.c:1618
#define GUC_UNIT
Definition: guc.h:229
signed int int32
Definition: c.h:256
static const char * time_units_hint
Definition: guc.c:749
static bool convert_to_base_unit(int64 value, const char *unit, int base_unit, int64 *base_value)
Definition: guc.c:5391
#define NULL
Definition: c.h:229
long val
Definition: informix.c:689
static const char * memory_units_hint
Definition: guc.c:722
#define GUC_UNIT_MEMORY
Definition: guc.h:222
bool parse_real ( const char *  value,
double *  result 
)

Definition at line 5562 of file guc.c.

References val.

Referenced by parse_and_validate_value(), and parse_one_reloption().

5563 {
5564  double val;
5565  char *endptr;
5566 
5567  if (result)
5568  *result = 0; /* suppress compiler warning */
5569 
5570  errno = 0;
5571  val = strtod(value, &endptr);
5572  if (endptr == value || errno == ERANGE)
5573  return false;
5574 
5575  /* allow whitespace after number */
5576  while (isspace((unsigned char) *endptr))
5577  endptr++;
5578  if (*endptr != '\0')
5579  return false;
5580 
5581  if (result)
5582  *result = val;
5583  return true;
5584 }
static struct @78 value
return result
Definition: formatting.c:1618
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 9349 of file guc.c.

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

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

9350 {
9351  size_t equal_pos;
9352  char *cp;
9353 
9354  AssertArg(string);
9355  AssertArg(name);
9356  AssertArg(value);
9357 
9358  equal_pos = strcspn(string, "=");
9359 
9360  if (string[equal_pos] == '=')
9361  {
9362  *name = guc_malloc(FATAL, equal_pos + 1);
9363  strlcpy(*name, string, equal_pos + 1);
9364 
9365  *value = guc_strdup(FATAL, &string[equal_pos + 1]);
9366  }
9367  else
9368  {
9369  /* no equal sign in string */
9370  *name = guc_strdup(FATAL, string);
9371  *value = NULL;
9372  }
9373 
9374  for (cp = *name; *cp; cp++)
9375  if (*cp == '-')
9376  *cp = '_';
9377 }
static struct @78 value
static char * guc_strdup(int elevel, const char *src)
Definition: guc.c:3987
#define FATAL
Definition: elog.h:52
#define AssertArg(condition)
Definition: c.h:677
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
#define NULL
Definition: c.h:229
const char * name
Definition: encode.c:521
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:3955
void ProcessGUCArray ( ArrayType array,
GucContext  context,
GucSource  source,
GucAction  action 
)

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

9389 {
9390  int i;
9391 
9392  Assert(array != NULL);
9393  Assert(ARR_ELEMTYPE(array) == TEXTOID);
9394  Assert(ARR_NDIM(array) == 1);
9395  Assert(ARR_LBOUND(array)[0] == 1);
9396 
9397  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9398  {
9399  Datum d;
9400  bool isnull;
9401  char *s;
9402  char *name;
9403  char *value;
9404 
9405  d = array_ref(array, 1, &i,
9406  -1 /* varlenarray */ ,
9407  -1 /* TEXT's typlen */ ,
9408  false /* TEXT's typbyval */ ,
9409  'i' /* TEXT's typalign */ ,
9410  &isnull);
9411 
9412  if (isnull)
9413  continue;
9414 
9415  s = TextDatumGetCString(d);
9416 
9417  ParseLongOption(s, &name, &value);
9418  if (!value)
9419  {
9420  ereport(WARNING,
9421  (errcode(ERRCODE_SYNTAX_ERROR),
9422  errmsg("could not parse setting for parameter \"%s\"",
9423  name)));
9424  free(name);
9425  continue;
9426  }
9427 
9428  (void) set_config_option(name, value,
9429  context, source,
9430  action, true, 0, false);
9431 
9432  free(name);
9433  if (value)
9434  free(value);
9435  pfree(s);
9436  }
9437 }
GucSource source
Definition: guc_tables.h:154
static struct @78 value
#define TEXTOID
Definition: pg_type.h:324
void ParseLongOption(const char *string, char **name, char **value)
Definition: guc.c:9349
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ARR_LBOUND(a)
Definition: array.h:277
void pfree(void *pointer)
Definition: mcxt.c:950
#define ARR_DIMS(a)
Definition: array.h:275
#define ereport(elevel, rest)
Definition: elog.h:122
Datum array_ref(ArrayType *array, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:3063
#define WARNING
Definition: elog.h:40
#define TextDatumGetCString(d)
Definition: builtins.h:92
uintptr_t Datum
Definition: postgres.h:372
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#define ARR_NDIM(a)
Definition: array.h:271
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
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:5887
#define ARR_ELEMTYPE(a)
Definition: array.h:273
GucContext context
Definition: guc_tables.h:146
void ResetAllOptions ( void  )

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

4844 {
4845  int i;
4846 
4847  for (i = 0; i < num_guc_variables; i++)
4848  {
4849  struct config_generic *gconf = guc_variables[i];
4850 
4851  /* Don't reset non-SET-able values */
4852  if (gconf->context != PGC_SUSET &&
4853  gconf->context != PGC_USERSET)
4854  continue;
4855  /* Don't reset if special exclusion from RESET ALL */
4856  if (gconf->flags & GUC_NO_RESET_ALL)
4857  continue;
4858  /* No need to reset if wasn't SET */
4859  if (gconf->source <= PGC_S_OVERRIDE)
4860  continue;
4861 
4862  /* Save old value to support transaction abort */
4864 
4865  switch (gconf->vartype)
4866  {
4867  case PGC_BOOL:
4868  {
4869  struct config_bool *conf = (struct config_bool *) gconf;
4870 
4871  if (conf->assign_hook)
4872  (*conf->assign_hook) (conf->reset_val,
4873  conf->reset_extra);
4874  *conf->variable = conf->reset_val;
4875  set_extra_field(&conf->gen, &conf->gen.extra,
4876  conf->reset_extra);
4877  break;
4878  }
4879  case PGC_INT:
4880  {
4881  struct config_int *conf = (struct config_int *) gconf;
4882 
4883  if (conf->assign_hook)
4884  (*conf->assign_hook) (conf->reset_val,
4885  conf->reset_extra);
4886  *conf->variable = conf->reset_val;
4887  set_extra_field(&conf->gen, &conf->gen.extra,
4888  conf->reset_extra);
4889  break;
4890  }
4891  case PGC_REAL:
4892  {
4893  struct config_real *conf = (struct config_real *) gconf;
4894 
4895  if (conf->assign_hook)
4896  (*conf->assign_hook) (conf->reset_val,
4897  conf->reset_extra);
4898  *conf->variable = conf->reset_val;
4899  set_extra_field(&conf->gen, &conf->gen.extra,
4900  conf->reset_extra);
4901  break;
4902  }
4903  case PGC_STRING:
4904  {
4905  struct config_string *conf = (struct config_string *) gconf;
4906 
4907  if (conf->assign_hook)
4908  (*conf->assign_hook) (conf->reset_val,
4909  conf->reset_extra);
4910  set_string_field(conf, conf->variable, conf->reset_val);
4911  set_extra_field(&conf->gen, &conf->gen.extra,
4912  conf->reset_extra);
4913  break;
4914  }
4915  case PGC_ENUM:
4916  {
4917  struct config_enum *conf = (struct config_enum *) gconf;
4918 
4919  if (conf->assign_hook)
4920  (*conf->assign_hook) (conf->reset_val,
4921  conf->reset_extra);
4922  *conf->variable = conf->reset_val;
4923  set_extra_field(&conf->gen, &conf->gen.extra,
4924  conf->reset_extra);
4925  break;
4926  }
4927  }
4928 
4929  gconf->source = gconf->reset_source;
4930  gconf->scontext = gconf->reset_scontext;
4931 
4932  if (gconf->flags & GUC_REPORT)
4933  ReportGUCOption(gconf);
4934  }
4935 }
GucSource source
Definition: guc_tables.h:154
void * reset_extra
Definition: guc_tables.h:203
GucRealAssignHook assign_hook
Definition: guc_tables.h:215
double reset_val
Definition: guc_tables.h:218
#define GUC_NO_RESET_ALL
Definition: guc.h:207
char ** variable
Definition: guc_tables.h:226
bool * variable
Definition: guc_tables.h:180
GucEnumAssignHook assign_hook
Definition: guc_tables.h:244
GucBoolAssignHook assign_hook
Definition: guc_tables.h:183
GucContext scontext
Definition: guc_tables.h:156
GucIntAssignHook assign_hook
Definition: guc_tables.h:199
static void push_old_value(struct config_generic *gconf, GucAction action)
Definition: guc.c:4943
int * variable
Definition: guc_tables.h:194
int * variable
Definition: guc_tables.h:240
static int num_guc_variables
Definition: guc.c:3917
void * reset_extra
Definition: guc_tables.h:248
Definition: guc.h:75
static void set_extra_field(struct config_generic *gconf, void **field, void *newval)
Definition: guc.c:4088
GucSource reset_source
Definition: guc_tables.h:155
struct config_generic gen
Definition: guc_tables.h:178
struct config_generic gen
Definition: guc_tables.h:192
#define GUC_REPORT
Definition: guc.h:208
double * variable
Definition: guc_tables.h:210
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4027
static struct config_generic ** guc_variables
Definition: guc.c:3914
enum config_type vartype
Definition: guc_tables.h:152
void * reset_extra
Definition: guc_tables.h:219
struct config_generic gen
Definition: guc_tables.h:238
struct config_generic gen
Definition: guc_tables.h:224
char * reset_val
Definition: guc_tables.h:232
GucStringAssignHook assign_hook
Definition: guc_tables.h:229
void * reset_extra
Definition: guc_tables.h:233
void * reset_extra
Definition: guc_tables.h:187
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:5367
bool reset_val
Definition: guc_tables.h:186
GucContext context
Definition: guc_tables.h:146
struct config_generic gen
Definition: guc_tables.h:208
GucContext reset_scontext
Definition: guc_tables.h:157
int reset_val
Definition: guc_tables.h:202
void RestoreGUCState ( void *  gucstate)

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

9292 {
9293  char *varname,
9294  *varvalue,
9295  *varsourcefile;
9296  int varsourceline;
9297  GucSource varsource;
9298  GucContext varscontext;
9299  char *srcptr = (char *) gucstate;
9300  char *srcend;
9301  Size len;
9302  int i;
9303 
9304  /* See comment at can_skip_gucvar(). */
9305  for (i = 0; i < num_guc_variables; i++)
9306  if (!can_skip_gucvar(guc_variables[i]))
9308 
9309  /* First item is the length of the subsequent data */
9310  memcpy(&len, gucstate, sizeof(len));
9311 
9312  srcptr += sizeof(len);
9313  srcend = srcptr + len;
9314 
9315  while (srcptr < srcend)
9316  {
9317  int result;
9318 
9319  varname = read_gucstate(&srcptr, srcend);
9320  varvalue = read_gucstate(&srcptr, srcend);
9321  varsourcefile = read_gucstate(&srcptr, srcend);
9322  if (varsourcefile[0])
9323  read_gucstate_binary(&srcptr, srcend,
9324  &varsourceline, sizeof(varsourceline));
9325  read_gucstate_binary(&srcptr, srcend,
9326  &varsource, sizeof(varsource));
9327  read_gucstate_binary(&srcptr, srcend,
9328  &varscontext, sizeof(varscontext));
9329 
9330  result = set_config_option(varname, varvalue, varscontext, varsource,
9331  GUC_ACTION_SET, true, ERROR, true);
9332  if (result <= 0)
9333  ereport(ERROR,
9334  (errcode(ERRCODE_INTERNAL_ERROR),
9335  errmsg("parameter \"%s\" could not be set", varname)));
9336  if (varsourcefile[0])
9337  set_config_sourcefile(varname, varsourcefile, varsourceline);
9338  }
9339 }
GucContext
Definition: guc.h:68
static void static void set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
Definition: guc.c:6617
static void read_gucstate_binary(char **srcptr, char *srcend, void *dest, Size size)
Definition: guc.c:9276
int errcode(int sqlerrcode)
Definition: elog.c:575
return result
Definition: formatting.c:1618
GucSource
Definition: guc.h:105
#define ERROR
Definition: elog.h:43
static int num_guc_variables
Definition: guc.c:3917
static bool can_skip_gucvar(struct config_generic *gconf)
Definition: guc.c:8955
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:4548
#define ereport(elevel, rest)
Definition: elog.h:122
static struct config_generic ** guc_variables
Definition: guc.c:3914
static char * read_gucstate(char **srcptr, char *srcend)
Definition: guc.c:9253
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:5887
bool SelectConfigFiles ( const char *  userDoption,
const char *  progname 
)

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

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

Definition at line 9213 of file guc.c.

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

Referenced by InitializeParallelDSM().

9214 {
9215  char *curptr;
9216  Size actual_size;
9217  Size bytes_left;
9218  int i;
9219  int i_role = -1;
9220 
9221  /* Reserve space for saving the actual size of the guc state */
9222  Assert(maxsize > sizeof(actual_size));
9223  curptr = start_address + sizeof(actual_size);
9224  bytes_left = maxsize - sizeof(actual_size);
9225 
9226  for (i = 0; i < num_guc_variables; i++)
9227  {
9228  /*
9229  * It's pretty ugly, but we've got to force "role" to be initialized
9230  * after "session_authorization"; otherwise, the latter will override
9231  * the former.
9232  */
9233  if (strcmp(guc_variables[i]->name, "role") == 0)
9234  i_role = i;
9235  else
9236  serialize_variable(&curptr, &bytes_left, guc_variables[i]);
9237  }
9238  if (i_role >= 0)
9239  serialize_variable(&curptr, &bytes_left, guc_variables[i_role]);
9240 
9241  /* Store actual size without assuming alignment of start_address. */
9242  actual_size = maxsize - bytes_left - sizeof(actual_size);
9243  memcpy(start_address, &actual_size, sizeof(actual_size));
9244 }
static void serialize_variable(char **destptr, Size *maxbytes, struct config_generic *gconf)
Definition: guc.c:9139
static int num_guc_variables
Definition: guc.c:3917
static struct config_generic ** guc_variables
Definition: guc.c:3914
#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 5887 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(), ProcessGUCArray(), reapply_stacked_values(), RestoreGUCState(), RI_Initial_Check(), set_config_by_name(), set_transmission_modes(), SetConfigOption(), SetPGVariable(), and validate_option_array_item().

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