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

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

References baseSearchPathValid.

3945 {
3946  /*
3947  * We mark the path as needing recomputation, but don't do anything until
3948  * it's needed. This avoids trying to do database access during GUC
3949  * initialization, or outside a transaction.
3950  */
3951  baseSearchPathValid = false;
3952 }
static bool baseSearchPathValid
Definition: namespace.c:152
void assign_temp_tablespaces ( const char *  newval,
void *  extra 
)

Definition at line 1263 of file tablespace.c.

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

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

Definition at line 9966 of file xlog.c.

References ereport, errcode_for_file_access(), errmsg(), get_sync_bit(), openLogFile, openLogSegNo, PANIC, pg_fsync(), sync_method, ThisTimeLineID, XLogFileClose(), and XLogFileNameP().

9967 {
9968  if (sync_method != new_sync_method)
9969  {
9970  /*
9971  * To ensure that no blocks escape unsynced, force an fsync on the
9972  * currently open log segment (if any). Also, if the open flag is
9973  * changing, close the log file so it will be reopened (with new flag
9974  * bit) at next use.
9975  */
9976  if (openLogFile >= 0)
9977  {
9978  if (pg_fsync(openLogFile) != 0)
9979  ereport(PANIC,
9981  errmsg("could not fsync log segment %s: %m",
9983  if (get_sync_bit(sync_method) != get_sync_bit(new_sync_method))
9984  XLogFileClose();
9985  }
9986  }
9987 }
static int get_sync_bit(int method)
Definition: xlog.c:9910
#define PANIC
Definition: elog.h:53
static XLogSegNo openLogSegNo
Definition: xlog.c:762
static void XLogFileClose(void)
Definition: xlog.c:3683
char * XLogFileNameP(TimeLineID tli, XLogSegNo segno)
Definition: xlog.c:10040
int errcode_for_file_access(void)
Definition: elog.c:598
#define ereport(elevel, rest)
Definition: elog.h:122
static int openLogFile
Definition: xlog.c:761
TimeLineID ThisTimeLineID
Definition: xlog.c:178
int sync_method
Definition: xlog.c:102
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 5036 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().

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

References elog, and WARNING.

Referenced by StartTransaction().

5003 {
5004  /*
5005  * The nest level should be 0 between transactions; if it isn't, somebody
5006  * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
5007  * throw a warning but make no other effort to clean up.
5008  */
5009  if (GUCNestLevel != 0)
5010  elog(WARNING, "GUC nest level = %d at transaction start",
5011  GUCNestLevel);
5012  GUCNestLevel = 1;
5013 }
static int GUCNestLevel
Definition: guc.c:3905
#define WARNING
Definition: elog.h:40
#define elog
Definition: elog.h:219
void BeginReportingGUCOptions ( void  )

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

5318 {
5319  int i;
5320 
5321  /*
5322  * Don't do anything unless talking to an interactive frontend of protocol
5323  * 3.0 or later.
5324  */
5325  if (whereToSendOutput != DestRemote ||
5327  return;
5328 
5329  reporting_enabled = true;
5330 
5331  /* Transmit initial values of interesting variables */
5332  for (i = 0; i < num_guc_variables; i++)
5333  {
5334  struct config_generic *conf = guc_variables[i];
5335 
5336  if (conf->flags & GUC_REPORT)
5337  ReportGUCOption(conf);
5338  }
5339 }
#define PG_PROTOCOL_MAJOR(v)
Definition: pqcomm.h:104
static int num_guc_variables
Definition: guc.c:3895
#define GUC_REPORT
Definition: guc.h:208
static struct config_generic ** guc_variables
Definition: guc.c:3892
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:5345
CommandDest whereToSendOutput
Definition: postgres.c:86
static bool reporting_enabled
Definition: guc.c:3903
ProtocolVersion FrontendProtocol
Definition: globals.c:27
bool check_default_tablespace ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 1063 of file tablespace.c.

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

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

Definition at line 3910 of file namespace.c.

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

3911 {
3912  char *rawname;
3913  List *namelist;
3914 
3915  /* Need a modifiable copy of string */
3916  rawname = pstrdup(*newval);
3917 
3918  /* Parse string into list of identifiers */
3919  if (!SplitIdentifierString(rawname, ',', &namelist))
3920  {
3921  /* syntax error in name list */
3922  GUC_check_errdetail("List syntax is invalid.");
3923  pfree(rawname);
3924  list_free(namelist);
3925  return false;
3926  }
3927 
3928  /*
3929  * We used to try to check that the named schemas exist, but there are
3930  * many valid use-cases for having search_path settings that include
3931  * schemas that don't exist; and often, we are not inside a transaction
3932  * here and so can't consult the system catalogs anyway. So now, the only
3933  * requirement is syntactic validity of the identifier list.
3934  */
3935 
3936  pfree(rawname);
3937  list_free(namelist);
3938 
3939  return true;
3940 }
#define GUC_check_errdetail
Definition: guc.h:407
char * pstrdup(const char *in)
Definition: mcxt.c:1165
void pfree(void *pointer)
Definition: mcxt.c:992
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3129
#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 1158 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.

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

Definition at line 4727 of file xlog.c.

References XLOGbuffers, and XLOGChooseNumBuffers().

4728 {
4729  /*
4730  * -1 indicates a request for auto-tune.
4731  */
4732  if (*newval == -1)
4733  {
4734  /*
4735  * If we haven't yet changed the boot_val default of -1, just let it
4736  * be. We'll fix it when XLOGShmemSize is called.
4737  */
4738  if (XLOGbuffers == -1)
4739  return true;
4740 
4741  /* Otherwise, substitute the auto-tune value */
4743  }
4744 
4745  /*
4746  * We clamp manually-set values to at least 4 blocks. Prior to PostgreSQL
4747  * 9.1, a minimum of 4 was enforced by guc.c, but since that is no longer
4748  * the case, we just silently treat such values as a request for the
4749  * minimum. (We could throw an error instead, but that doesn't seem very
4750  * helpful.)
4751  */
4752  if (*newval < 4)
4753  *newval = 4;
4754 
4755  return true;
4756 }
static int XLOGChooseNumBuffers(void)
Definition: xlog.c:4711
#define newval
int XLOGbuffers
Definition: xlog.c:91
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 7683 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().

7693 {
7694  struct config_bool *var;
7695 
7696  var = (struct config_bool *)
7697  init_custom_variable(name, short_desc, long_desc, context, flags,
7698  PGC_BOOL, sizeof(struct config_bool));
7699  var->variable = valueAddr;
7700  var->boot_val = bootValue;
7701  var->reset_val = bootValue;
7702  var->check_hook = check_hook;
7703  var->assign_hook = assign_hook;
7704  var->show_hook = show_hook;
7705  define_custom_variable(&var->gen);
7706 }
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:7451
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:7502
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 7794 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().

7805 {
7806  struct config_enum *var;
7807 
7808  var = (struct config_enum *)
7809  init_custom_variable(name, short_desc, long_desc, context, flags,
7810  PGC_ENUM, sizeof(struct config_enum));
7811  var->variable = valueAddr;
7812  var->boot_val = bootValue;
7813  var->reset_val = bootValue;
7814  var->options = options;
7815  var->check_hook = check_hook;
7816  var->assign_hook = assign_hook;
7817  var->show_hook = show_hook;
7818  define_custom_variable(&var->gen);
7819 }
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:7451
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:7502
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 7709 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().

7721 {
7722  struct config_int *var;
7723 
7724  var = (struct config_int *)
7725  init_custom_variable(name, short_desc, long_desc, context, flags,
7726  PGC_INT, sizeof(struct config_int));
7727  var->variable = valueAddr;
7728  var->boot_val = bootValue;
7729  var->reset_val = bootValue;
7730  var->min = minValue;
7731  var->max = maxValue;
7732  var->check_hook = check_hook;
7733  var->assign_hook = assign_hook;
7734  var->show_hook = show_hook;
7735  define_custom_variable(&var->gen);
7736 }
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:7451
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7502
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 7739 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().

7751 {
7752  struct config_real *var;
7753 
7754  var = (struct config_real *)
7755  init_custom_variable(name, short_desc, long_desc, context, flags,
7756  PGC_REAL, sizeof(struct config_real));
7757  var->variable = valueAddr;
7758  var->boot_val = bootValue;
7759  var->reset_val = bootValue;
7760  var->min = minValue;
7761  var->max = maxValue;
7762  var->check_hook = check_hook;
7763  var->assign_hook = assign_hook;
7764  var->show_hook = show_hook;
7765  define_custom_variable(&var->gen);
7766 }
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:7451
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:7502
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 7769 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().

7779 {
7780  struct config_string *var;
7781 
7782  var = (struct config_string *)
7783  init_custom_variable(name, short_desc, long_desc, context, flags,
7784  PGC_STRING, sizeof(struct config_string));
7785  var->variable = valueAddr;
7786  var->boot_val = bootValue;
7787  var->check_hook = check_hook;
7788  var->assign_hook = assign_hook;
7789  var->show_hook = show_hook;
7790  define_custom_variable(&var->gen);
7791 }
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:7451
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:7502
void EmitWarningsOnPlaceholders ( const char *  className)

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

7823 {
7824  int classLen = strlen(className);
7825  int i;
7826 
7827  for (i = 0; i < num_guc_variables; i++)
7828  {
7829  struct config_generic *var = guc_variables[i];
7830 
7831  if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
7832  strncmp(className, var->name, classLen) == 0 &&
7833  var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
7834  {
7835  ereport(WARNING,
7836  (errcode(ERRCODE_UNDEFINED_OBJECT),
7837  errmsg("unrecognized configuration parameter \"%s\"",
7838  var->name)));
7839  }
7840  }
7841 }
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:3895
#define ereport(elevel, rest)
Definition: elog.h:122
static struct config_generic ** guc_variables
Definition: guc.c:3892
#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 9044 of file guc.c.

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

Referenced by InitializeParallelDSM().

9045 {
9046  Size size;
9047  int i;
9048 
9049  /* Add space reqd for saving the data size of the guc state */
9050  size = sizeof(Size);
9051 
9052  /* Add up the space needed for each GUC variable */
9053  for (i = 0; i < num_guc_variables; i++)
9054  size = add_size(size,
9056 
9057  return size;
9058 }
static int num_guc_variables
Definition: guc.c:3895
static struct config_generic ** guc_variables
Definition: guc.c:3892
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
size_t Size
Definition: c.h:353
static Size estimate_variable_size(struct config_generic *gconf)
Definition: guc.c:8946
int i
void ExecSetVariableStmt ( VariableSetStmt stmt,
bool  isTopLevel 
)

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

7240 {
7242 
7243  /*
7244  * Workers synchronize these parameters at the start of the parallel
7245  * operation; then, we block SET during the operation.
7246  */
7247  if (IsInParallelMode())
7248  ereport(ERROR,
7249  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
7250  errmsg("cannot set parameters during a parallel operation")));
7251 
7252  switch (stmt->kind)
7253  {
7254  case VAR_SET_VALUE:
7255  case VAR_SET_CURRENT:
7256  if (stmt->is_local)
7257  WarnNoTransactionChain(isTopLevel, "SET LOCAL");
7258  (void) set_config_option(stmt->name,
7259  ExtractSetVariableArgs(stmt),
7261  PGC_S_SESSION,
7262  action, true, 0, false);
7263  break;
7264  case VAR_SET_MULTI:
7265 
7266  /*
7267  * Special-case SQL syntaxes. The TRANSACTION and SESSION
7268  * CHARACTERISTICS cases effectively set more than one variable
7269  * per statement. TRANSACTION SNAPSHOT only takes one argument,
7270  * but we put it here anyway since it's a special case and not
7271  * related to any GUC variable.
7272  */
7273  if (strcmp(stmt->name, "TRANSACTION") == 0)
7274  {
7275  ListCell *head;
7276 
7277  WarnNoTransactionChain(isTopLevel, "SET TRANSACTION");
7278 
7279  foreach(head, stmt->args)
7280  {
7281  DefElem *item = (DefElem *) lfirst(head);
7282 
7283  if (strcmp(item->defname, "transaction_isolation") == 0)
7284  SetPGVariable("transaction_isolation",
7285  list_make1(item->arg), stmt->is_local);
7286  else if (strcmp(item->defname, "transaction_read_only") == 0)
7287  SetPGVariable("transaction_read_only",
7288  list_make1(item->arg), stmt->is_local);
7289  else if (strcmp(item->defname, "transaction_deferrable") == 0)
7290  SetPGVariable("transaction_deferrable",
7291  list_make1(item->arg), stmt->is_local);
7292  else
7293  elog(ERROR, "unexpected SET TRANSACTION element: %s",
7294  item->defname);
7295  }
7296  }
7297  else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
7298  {
7299  ListCell *head;
7300 
7301  foreach(head, stmt->args)
7302  {
7303  DefElem *item = (DefElem *) lfirst(head);
7304 
7305  if (strcmp(item->defname, "transaction_isolation") == 0)
7306  SetPGVariable("default_transaction_isolation",
7307  list_make1(item->arg), stmt->is_local);
7308  else if (strcmp(item->defname, "transaction_read_only") == 0)
7309  SetPGVariable("default_transaction_read_only",
7310  list_make1(item->arg), stmt->is_local);
7311  else if (strcmp(item->defname, "transaction_deferrable") == 0)
7312  SetPGVariable("default_transaction_deferrable",
7313  list_make1(item->arg), stmt->is_local);
7314  else
7315  elog(ERROR, "unexpected SET SESSION element: %s",
7316  item->defname);
7317  }
7318  }
7319  else if (strcmp(stmt->name, "TRANSACTION SNAPSHOT") == 0)
7320  {
7321  A_Const *con = castNode(A_Const, linitial(stmt->args));
7322 
7323  if (stmt->is_local)
7324  ereport(ERROR,
7325  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7326  errmsg("SET LOCAL TRANSACTION SNAPSHOT is not implemented")));
7327 
7328  WarnNoTransactionChain(isTopLevel, "SET TRANSACTION");
7329  Assert(nodeTag(&con->val) == T_String);
7330  ImportSnapshot(strVal(&con->val));
7331  }
7332  else
7333  elog(ERROR, "unexpected SET MULTI element: %s",
7334  stmt->name);
7335  break;
7336  case VAR_SET_DEFAULT:
7337  if (stmt->is_local)
7338  WarnNoTransactionChain(isTopLevel, "SET LOCAL");
7339  /* fall through */
7340  case VAR_RESET:
7341  if (strcmp(stmt->name, "transaction_isolation") == 0)
7342  WarnNoTransactionChain(isTopLevel, "RESET TRANSACTION");
7343 
7344  (void) set_config_option(stmt->name,
7345  NULL,
7347  PGC_S_SESSION,
7348  action, true, 0, false);
7349  break;
7350  case VAR_RESET_ALL:
7351  ResetAllOptions();
7352  break;
7353  }
7354 }
void ImportSnapshot(const char *idstr)
Definition: snapmgr.c:1386
VariableSetKind kind
Definition: parsenodes.h:1864
#define castNode(_type_, nodeptr)
Definition: nodes.h:577
#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:912
#define linitial(l)
Definition: pg_list.h:110
#define ERROR
Definition: elog.h:43
Definition: guc.h:75
void ResetAllOptions(void)
Definition: guc.c:4821
#define ereport(elevel, rest)
Definition: elog.h:122
Node * arg
Definition: parsenodes.h:676
void WarnNoTransactionChain(bool isTopLevel, const char *stmtType)
Definition: xact.c:3200
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
#define lfirst(lc)
Definition: pg_list.h:106
#define nodeTag(nodeptr)
Definition: nodes.h:513
int errmsg(const char *fmt,...)
Definition: elog.c:797
char * defname
Definition: parsenodes.h:675
#define elog
Definition: elog.h:219
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
Definition: guc.c:7363
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:5865
void SetPGVariable(const char *name, List *args, bool is_local)
Definition: guc.c:7383
char* ExtractSetVariableArgs ( VariableSetStmt stmt)

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

7364 {
7365  switch (stmt->kind)
7366  {
7367  case VAR_SET_VALUE:
7368  return flatten_set_variable_args(stmt->name, stmt->args);
7369  case VAR_SET_CURRENT:
7370  return GetConfigOptionByName(stmt->name, NULL, false);
7371  default:
7372  return NULL;
7373  }
7374 }
VariableSetKind kind
Definition: parsenodes.h:1864
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:7989
#define NULL
Definition: c.h:226
static char * flatten_set_variable_args(const char *name, List *args)
Definition: guc.c:6761
const char* GetConfigOption ( const char *  name,
bool  missing_ok,
bool  restrict_superuser 
)

Definition at line 6653 of file guc.c.

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

6654 {
6655  struct config_generic *record;
6656  static char buffer[256];
6657 
6658  record = find_option(name, false, ERROR);
6659  if (record == NULL)
6660  {
6661  if (missing_ok)
6662  return NULL;
6663  ereport(ERROR,
6664  (errcode(ERRCODE_UNDEFINED_OBJECT),
6665  errmsg("unrecognized configuration parameter \"%s\"",
6666  name)));
6667  }
6668  if (restrict_superuser &&
6669  (record->flags & GUC_SUPERUSER_ONLY) &&
6670  !superuser())
6671  ereport(ERROR,
6672  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6673  errmsg("must be superuser to examine \"%s\"", name)));
6674 
6675  switch (record->vartype)
6676  {
6677  case PGC_BOOL:
6678  return *((struct config_bool *) record)->variable ? "on" : "off";
6679 
6680  case PGC_INT:
6681  snprintf(buffer, sizeof(buffer), "%d",
6682  *((struct config_int *) record)->variable);
6683  return buffer;
6684 
6685  case PGC_REAL:
6686  snprintf(buffer, sizeof(buffer), "%g",
6687  *((struct config_real *) record)->variable);
6688  return buffer;
6689 
6690  case PGC_STRING:
6691  return *((struct config_string *) record)->variable;
6692 
6693  case PGC_ENUM:
6694  return config_enum_lookup_by_value((struct config_enum *) record,
6695  *((struct config_enum *) record)->variable);
6696  }
6697  return NULL;
6698 }
int errcode(int sqlerrcode)
Definition: elog.c:575
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5574
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:4329
#define NULL
Definition: c.h:226
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 7989 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().

7990 {
7991  struct config_generic *record;
7992 
7993  record = find_option(name, false, ERROR);
7994  if (record == NULL)
7995  {
7996  if (missing_ok)
7997  {
7998  if (varname)
7999  *varname = NULL;
8000  return NULL;
8001  }
8002 
8003  ereport(ERROR,
8004  (errcode(ERRCODE_UNDEFINED_OBJECT),
8005  errmsg("unrecognized configuration parameter \"%s\"", name)));
8006  }
8007 
8008  if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
8009  ereport(ERROR,
8010  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
8011  errmsg("must be superuser to examine \"%s\"", name)));
8012 
8013  if (varname)
8014  *varname = record->name;
8015 
8016  return _ShowOption(record, true);
8017 }
static char * _ShowOption(struct config_generic *record, bool use_units)
Definition: guc.c:8586
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:4329
#define NULL
Definition: c.h:226
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 8024 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, 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().

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

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

6709 {
6710  struct config_generic *record;
6711  static char buffer[256];
6712 
6713  record = find_option(name, false, ERROR);
6714  if (record == NULL)
6715  ereport(ERROR,
6716  (errcode(ERRCODE_UNDEFINED_OBJECT),
6717  errmsg("unrecognized configuration parameter \"%s\"", name)));
6718  if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
6719  ereport(ERROR,
6720  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6721  errmsg("must be superuser to examine \"%s\"", name)));
6722 
6723  switch (record->vartype)
6724  {
6725  case PGC_BOOL:
6726  return ((struct config_bool *) record)->reset_val ? "on" : "off";
6727 
6728  case PGC_INT:
6729  snprintf(buffer, sizeof(buffer), "%d",
6730  ((struct config_int *) record)->reset_val);
6731  return buffer;
6732 
6733  case PGC_REAL:
6734  snprintf(buffer, sizeof(buffer), "%g",
6735  ((struct config_real *) record)->reset_val);
6736  return buffer;
6737 
6738  case PGC_STRING:
6739  return ((struct config_string *) record)->reset_val;
6740 
6741  case PGC_ENUM:
6742  return config_enum_lookup_by_value((struct config_enum *) record,
6743  ((struct config_enum *) record)->reset_val);
6744  }
6745  return NULL;
6746 }
int errcode(int sqlerrcode)
Definition: elog.c:575
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5574
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:4329
#define NULL
Definition: c.h:226
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797
int GetNumConfigOptions ( void  )

Definition at line 8290 of file guc.c.

References num_guc_variables.

Referenced by GucInfoMain(), and show_all_settings().

8291 {
8292  return num_guc_variables;
8293 }
static int num_guc_variables
Definition: guc.c:3895
void GetPGVariable ( const char *  name,
DestReceiver dest 
)

Definition at line 7848 of file guc.c.

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

Referenced by exec_replication_command(), and standard_ProcessUtility().

7849 {
7850  if (guc_name_compare(name, "all") == 0)
7851  ShowAllGUCConfig(dest);
7852  else
7853  ShowGUCConfigOption(name, dest);
7854 }
static void ShowGUCConfigOption(const char *name, DestReceiver *dest)
Definition: guc.c:7892
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:4390
static void ShowAllGUCConfig(DestReceiver *dest)
Definition: guc.c:7920
const char * name
Definition: encode.c:521
TupleDesc GetPGVariableResultDesc ( const char *  name)

Definition at line 7857 of file guc.c.

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

Referenced by UtilityTupleDescriptor().

7858 {
7859  TupleDesc tupdesc;
7860 
7861  if (guc_name_compare(name, "all") == 0)
7862  {
7863  /* need a tuple descriptor representing three TEXT columns */
7864  tupdesc = CreateTemplateTupleDesc(3, false);
7865  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
7866  TEXTOID, -1, 0);
7867  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
7868  TEXTOID, -1, 0);
7869  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
7870  TEXTOID, -1, 0);
7871  }
7872  else
7873  {
7874  const char *varname;
7875 
7876  /* Get the canonical spelling of name */
7877  (void) GetConfigOptionByName(name, &varname, false);
7878 
7879  /* need a tuple descriptor representing a single TEXT column */
7880  tupdesc = CreateTemplateTupleDesc(1, false);
7881  TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
7882  TEXTOID, -1, 0);
7883  }
7884  return tupdesc;
7885 }
#define TEXTOID
Definition: pg_type.h:324
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:4390
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:7989
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 9726 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().

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

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

9424 {
9425  struct config_generic *record;
9426  Datum datum;
9427  char *newval;
9428  ArrayType *a;
9429 
9430  Assert(name);
9431  Assert(value);
9432 
9433  /* test if the option is valid and we're allowed to set it */
9434  (void) validate_option_array_item(name, value, false);
9435 
9436  /* normalize name (converts obsolete GUC names to modern spellings) */
9437  record = find_option(name, false, WARNING);
9438  if (record)
9439  name = record->name;
9440 
9441  /* build new item for array */
9442  newval = psprintf("%s=%s", name, value);
9443  datum = CStringGetTextDatum(newval);
9444 
9445  if (array)
9446  {
9447  int index;
9448  bool isnull;
9449  int i;
9450 
9451  Assert(ARR_ELEMTYPE(array) == TEXTOID);
9452  Assert(ARR_NDIM(array) == 1);
9453  Assert(ARR_LBOUND(array)[0] == 1);
9454 
9455  index = ARR_DIMS(array)[0] + 1; /* add after end */
9456 
9457  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9458  {
9459  Datum d;
9460  char *current;
9461 
9462  d = array_ref(array, 1, &i,
9463  -1 /* varlenarray */ ,
9464  -1 /* TEXT's typlen */ ,
9465  false /* TEXT's typbyval */ ,
9466  'i' /* TEXT's typalign */ ,
9467  &isnull);
9468  if (isnull)
9469  continue;
9470  current = TextDatumGetCString(d);
9471 
9472  /* check for match up through and including '=' */
9473  if (strncmp(current, newval, strlen(name) + 1) == 0)
9474  {
9475  index = i;
9476  break;
9477  }
9478  }
9479 
9480  a = array_set(array, 1, &index,
9481  datum,
9482  false,
9483  -1 /* varlena array */ ,
9484  -1 /* TEXT's typlen */ ,
9485  false /* TEXT's typbyval */ ,
9486  'i' /* TEXT's typalign */ );
9487  }
9488  else
9489  a = construct_array(&datum, 1,
9490  TEXTOID,
9491  -1, false, 'i');
9492 
9493  return a;
9494 }
static struct @76 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:9649
#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:91
uintptr_t Datum
Definition: postgres.h:374
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4329
#define Assert(condition)
Definition: c.h:671
#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:90
#define ARR_ELEMTYPE(a)
Definition: array.h:273
ArrayType* GUCArrayDelete ( ArrayType array,
const char *  name 
)

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

9504 {
9505  struct config_generic *record;
9506  ArrayType *newarray;
9507  int i;
9508  int index;
9509 
9510  Assert(name);
9511 
9512  /* test if the option is valid and we're allowed to set it */
9513  (void) validate_option_array_item(name, NULL, false);
9514 
9515  /* normalize name (converts obsolete GUC names to modern spellings) */
9516  record = find_option(name, false, WARNING);
9517  if (record)
9518  name = record->name;
9519 
9520  /* if array is currently null, then surely nothing to delete */
9521  if (!array)
9522  return NULL;
9523 
9524  newarray = NULL;
9525  index = 1;
9526 
9527  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9528  {
9529  Datum d;
9530  char *val;
9531  bool isnull;
9532 
9533  d = array_ref(array, 1, &i,
9534  -1 /* varlenarray */ ,
9535  -1 /* TEXT's typlen */ ,
9536  false /* TEXT's typbyval */ ,
9537  'i' /* TEXT's typalign */ ,
9538  &isnull);
9539  if (isnull)
9540  continue;
9541  val = TextDatumGetCString(d);
9542 
9543  /* ignore entry if it's what we want to delete */
9544  if (strncmp(val, name, strlen(name)) == 0
9545  && val[strlen(name)] == '=')
9546  continue;
9547 
9548  /* else add it to the output array */
9549  if (newarray)
9550  newarray = array_set(newarray, 1, &index,
9551  d,
9552  false,
9553  -1 /* varlenarray */ ,
9554  -1 /* TEXT's typlen */ ,
9555  false /* TEXT's typbyval */ ,
9556  'i' /* TEXT's typalign */ );
9557  else
9558  newarray = construct_array(&d, 1,
9559  TEXTOID,
9560  -1, false, 'i');
9561 
9562  index++;
9563  }
9564 
9565  return newarray;
9566 }
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:9649
#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:91
uintptr_t Datum
Definition: postgres.h:374
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4329
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
const char * name
Definition: encode.c:521
int i
long val
Definition: informix.c:689
ArrayType* GUCArrayReset ( ArrayType array)

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

9576 {
9577  ArrayType *newarray;
9578  int i;
9579  int index;
9580 
9581  /* if array is currently null, nothing to do */
9582  if (!array)
9583  return NULL;
9584 
9585  /* if we're superuser, we can delete everything, so just do it */
9586  if (superuser())
9587  return NULL;
9588 
9589  newarray = NULL;
9590  index = 1;
9591 
9592  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9593  {
9594  Datum d;
9595  char *val;
9596  char *eqsgn;
9597  bool isnull;
9598 
9599  d = array_ref(array, 1, &i,
9600  -1 /* varlenarray */ ,
9601  -1 /* TEXT's typlen */ ,
9602  false /* TEXT's typbyval */ ,
9603  'i' /* TEXT's typalign */ ,
9604  &isnull);
9605  if (isnull)
9606  continue;
9607  val = TextDatumGetCString(d);
9608 
9609  eqsgn = strchr(val, '=');
9610  *eqsgn = '\0';
9611 
9612  /* skip if we have permission to delete it */
9613  if (validate_option_array_item(val, NULL, true))
9614  continue;
9615 
9616  /* else add it to the output array */
9617  if (newarray)
9618  newarray = array_set(newarray, 1, &index,
9619  d,
9620  false,
9621  -1 /* varlenarray */ ,
9622  -1 /* TEXT's typlen */ ,
9623  false /* TEXT's typbyval */ ,
9624  'i' /* TEXT's typalign */ );
9625  else
9626  newarray = construct_array(&d, 1,
9627  TEXTOID,
9628  -1, false, 'i');
9629 
9630  index++;
9631  pfree(val);
9632  }
9633 
9634  return newarray;
9635 }
#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:992
static bool validate_option_array_item(const char *name, const char *value, bool skipIfNoPermissions)
Definition: guc.c:9649
#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:91
uintptr_t Datum
Definition: postgres.h:374
#define NULL
Definition: c.h:226
int i
long val
Definition: informix.c:689
void InitializeGUCOptions ( void  )

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

4425 {
4426  int i;
4427 
4428  /*
4429  * Before log_line_prefix could possibly receive a nonempty setting, make
4430  * sure that timezone processing is minimally alive (see elog.c).
4431  */
4433 
4434  /*
4435  * Build sorted array of all GUC variables.
4436  */
4438 
4439  /*
4440  * Load all variables with their compiled-in defaults, and initialize
4441  * status fields as needed.
4442  */
4443  for (i = 0; i < num_guc_variables; i++)
4444  {
4446  }
4447 
4448  guc_dirty = false;
4449 
4450  reporting_enabled = false;
4451 
4452  /*
4453  * Prevent any attempt to override the transaction modes from
4454  * non-interactive sources.
4455  */
4456  SetConfigOption("transaction_isolation", "default",
4458  SetConfigOption("transaction_read_only", "no",
4460  SetConfigOption("transaction_deferrable", "no",
4462 
4463  /*
4464  * For historical reasons, some GUC parameters can receive defaults from
4465  * environment variables. Process those settings.
4466  */
4468 }
void build_guc_variables(void)
Definition: guc.c:4156
static void InitializeGUCOptionsFromEnvironment(void)
Definition: guc.c:4480
void pg_timezone_initialize(void)
Definition: pgtz.c:345
static int num_guc_variables
Definition: guc.c:3895
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:6629
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:4526
static struct config_generic ** guc_variables
Definition: guc.c:3892
int i
static bool reporting_enabled
Definition: guc.c:3903
static bool guc_dirty
Definition: guc.c:3901
bool parse_int ( const char *  value,
int *  result,
int  flags,
const char **  hintmsg 
)

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

5455 {
5456  int64 val;
5457  char *endptr;
5458 
5459  /* To suppress compiler warnings, always set output params */
5460  if (result)
5461  *result = 0;
5462  if (hintmsg)
5463  *hintmsg = NULL;
5464 
5465  /* We assume here that int64 is at least as wide as long */
5466  errno = 0;
5467  val = strtol(value, &endptr, 0);
5468 
5469  if (endptr == value)
5470  return false; /* no HINT for integer syntax error */
5471 
5472  if (errno == ERANGE || val != (int64) ((int32) val))
5473  {
5474  if (hintmsg)
5475  *hintmsg = gettext_noop("Value exceeds integer range.");
5476  return false;
5477  }
5478 
5479  /* allow whitespace between integer and unit */
5480  while (isspace((unsigned char) *endptr))
5481  endptr++;
5482 
5483  /* Handle possible unit */
5484  if (*endptr != '\0')
5485  {
5486  char unit[MAX_UNIT_LEN + 1];
5487  int unitlen;
5488  bool converted = false;
5489 
5490  if ((flags & GUC_UNIT) == 0)
5491  return false; /* this setting does not accept a unit */
5492 
5493  unitlen = 0;
5494  while (*endptr != '\0' && !isspace((unsigned char) *endptr) &&
5495  unitlen < MAX_UNIT_LEN)
5496  unit[unitlen++] = *(endptr++);
5497  unit[unitlen] = '\0';
5498  /* allow whitespace after unit */
5499  while (isspace((unsigned char) *endptr))
5500  endptr++;
5501 
5502  if (*endptr == '\0')
5503  converted = convert_to_base_unit(val, unit, (flags & GUC_UNIT),
5504  &val);
5505  if (!converted)
5506  {
5507  /* invalid unit, or garbage after the unit; set hint and fail. */
5508  if (hintmsg)
5509  {
5510  if (flags & GUC_UNIT_MEMORY)
5511  *hintmsg = memory_units_hint;
5512  else
5513  *hintmsg = time_units_hint;
5514  }
5515  return false;
5516  }
5517 
5518  /* Check for overflow due to units conversion */
5519  if (val != (int64) ((int32) val))
5520  {
5521  if (hintmsg)
5522  *hintmsg = gettext_noop("Value exceeds integer range.");
5523  return false;
5524  }
5525  }
5526 
5527  if (result)
5528  *result = (int) val;
5529  return true;
5530 }
static struct @76 value
#define MAX_UNIT_LEN
Definition: guc.c:698
#define gettext_noop(x)
Definition: c.h:139
#define GUC_UNIT
Definition: guc.h:229
signed int int32
Definition: c.h:253
static const char * time_units_hint
Definition: guc.c:748
static bool convert_to_base_unit(int64 value, const char *unit, int base_unit, int64 *base_value)
Definition: guc.c:5369
#define NULL
Definition: c.h:226
long val
Definition: informix.c:689
static const char * memory_units_hint
Definition: guc.c:721
#define GUC_UNIT_MEMORY
Definition: guc.h:222
bool parse_real ( const char *  value,
double *  result 
)

Definition at line 5540 of file guc.c.

References val.

Referenced by parse_and_validate_value(), and parse_one_reloption().

5541 {
5542  double val;
5543  char *endptr;
5544 
5545  if (result)
5546  *result = 0; /* suppress compiler warning */
5547 
5548  errno = 0;
5549  val = strtod(value, &endptr);
5550  if (endptr == value || errno == ERANGE)
5551  return false;
5552 
5553  /* allow whitespace after number */
5554  while (isspace((unsigned char) *endptr))
5555  endptr++;
5556  if (*endptr != '\0')
5557  return false;
5558 
5559  if (result)
5560  *result = val;
5561  return true;
5562 }
static struct @76 value
long val
Definition: informix.c:689
bool ParseConfigDirectory ( const char *  includedir,
const char *  calling_file,
int  calling_lineno,
int  depth,
int  elevel,
ConfigVariable **  head_p,
ConfigVariable **  tail_p 
)
bool ParseConfigFile ( const char *  config_file,
bool  strict,
const char *  calling_file,
int  calling_lineno,
int  depth,
int  elevel,
ConfigVariable **  head_p,
ConfigVariable **  tail_p 
)
bool ParseConfigFp ( FILE *  fp,
const char *  config_file,
int  depth,
int  elevel,
ConfigVariable **  head_p,
ConfigVariable **  tail_p 
)
void ParseLongOption ( const char *  string,
char **  name,
char **  value 
)

Definition at line 9327 of file guc.c.

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

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

9328 {
9329  size_t equal_pos;
9330  char *cp;
9331 
9332  AssertArg(string);
9333  AssertArg(name);
9334  AssertArg(value);
9335 
9336  equal_pos = strcspn(string, "=");
9337 
9338  if (string[equal_pos] == '=')
9339  {
9340  *name = guc_malloc(FATAL, equal_pos + 1);
9341  strlcpy(*name, string, equal_pos + 1);
9342 
9343  *value = guc_strdup(FATAL, &string[equal_pos + 1]);
9344  }
9345  else
9346  {
9347  /* no equal sign in string */
9348  *name = guc_strdup(FATAL, string);
9349  *value = NULL;
9350  }
9351 
9352  for (cp = *name; *cp; cp++)
9353  if (*cp == '-')
9354  *cp = '_';
9355 }
static struct @76 value
static char * guc_strdup(int elevel, const char *src)
Definition: guc.c:3965
#define FATAL
Definition: elog.h:52
#define AssertArg(condition)
Definition: c.h:673
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
#define NULL
Definition: c.h:226
const char * name
Definition: encode.c:521
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:3933
void ProcessGUCArray ( ArrayType array,
GucContext  context,
GucSource  source,
GucAction  action 
)

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

9367 {
9368  int i;
9369 
9370  Assert(array != NULL);
9371  Assert(ARR_ELEMTYPE(array) == TEXTOID);
9372  Assert(ARR_NDIM(array) == 1);
9373  Assert(ARR_LBOUND(array)[0] == 1);
9374 
9375  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9376  {
9377  Datum d;
9378  bool isnull;
9379  char *s;
9380  char *name;
9381  char *value;
9382 
9383  d = array_ref(array, 1, &i,
9384  -1 /* varlenarray */ ,
9385  -1 /* TEXT's typlen */ ,
9386  false /* TEXT's typbyval */ ,
9387  'i' /* TEXT's typalign */ ,
9388  &isnull);
9389 
9390  if (isnull)
9391  continue;
9392 
9393  s = TextDatumGetCString(d);
9394 
9395  ParseLongOption(s, &name, &value);
9396  if (!value)
9397  {
9398  ereport(WARNING,
9399  (errcode(ERRCODE_SYNTAX_ERROR),
9400  errmsg("could not parse setting for parameter \"%s\"",
9401  name)));
9402  free(name);
9403  continue;
9404  }
9405 
9406  (void) set_config_option(name, value,
9407  context, source,
9408  action, true, 0, false);
9409 
9410  free(name);
9411  if (value)
9412  free(value);
9413  pfree(s);
9414  }
9415 }
GucSource source
Definition: guc_tables.h:154
static struct @76 value
#define TEXTOID
Definition: pg_type.h:324
void ParseLongOption(const char *string, char **name, char **value)
Definition: guc.c:9327
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ARR_LBOUND(a)
Definition: array.h:277
void pfree(void *pointer)
Definition: mcxt.c:992
#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:91
uintptr_t Datum
Definition: postgres.h:374
#define free(a)
Definition: header.h:60
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
#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:5865
#define ARR_ELEMTYPE(a)
Definition: array.h:273
GucContext context
Definition: guc_tables.h:146
void ResetAllOptions ( void  )

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

4822 {
4823  int i;
4824 
4825  for (i = 0; i < num_guc_variables; i++)
4826  {
4827  struct config_generic *gconf = guc_variables[i];
4828 
4829  /* Don't reset non-SET-able values */
4830  if (gconf->context != PGC_SUSET &&
4831  gconf->context != PGC_USERSET)
4832  continue;
4833  /* Don't reset if special exclusion from RESET ALL */
4834  if (gconf->flags & GUC_NO_RESET_ALL)
4835  continue;
4836  /* No need to reset if wasn't SET */
4837  if (gconf->source <= PGC_S_OVERRIDE)
4838  continue;
4839 
4840  /* Save old value to support transaction abort */
4842 
4843  switch (gconf->vartype)
4844  {
4845  case PGC_BOOL:
4846  {
4847  struct config_bool *conf = (struct config_bool *) gconf;
4848 
4849  if (conf->assign_hook)
4850  (*conf->assign_hook) (conf->reset_val,
4851  conf->reset_extra);
4852  *conf->variable = conf->reset_val;
4853  set_extra_field(&conf->gen, &conf->gen.extra,
4854  conf->reset_extra);
4855  break;
4856  }
4857  case PGC_INT:
4858  {
4859  struct config_int *conf = (struct config_int *) gconf;
4860 
4861  if (conf->assign_hook)
4862  (*conf->assign_hook) (conf->reset_val,
4863  conf->reset_extra);
4864  *conf->variable = conf->reset_val;
4865  set_extra_field(&conf->gen, &conf->gen.extra,
4866  conf->reset_extra);
4867  break;
4868  }
4869  case PGC_REAL:
4870  {
4871  struct config_real *conf = (struct config_real *) gconf;
4872 
4873  if (conf->assign_hook)
4874  (*conf->assign_hook) (conf->reset_val,
4875  conf->reset_extra);
4876  *conf->variable = conf->reset_val;
4877  set_extra_field(&conf->gen, &conf->gen.extra,
4878  conf->reset_extra);
4879  break;
4880  }
4881  case PGC_STRING:
4882  {
4883  struct config_string *conf = (struct config_string *) gconf;
4884 
4885  if (conf->assign_hook)
4886  (*conf->assign_hook) (conf->reset_val,
4887  conf->reset_extra);
4888  set_string_field(conf, conf->variable, conf->reset_val);
4889  set_extra_field(&conf->gen, &conf->gen.extra,
4890  conf->reset_extra);
4891  break;
4892  }
4893  case PGC_ENUM:
4894  {
4895  struct config_enum *conf = (struct config_enum *) gconf;
4896 
4897  if (conf->assign_hook)
4898  (*conf->assign_hook) (conf->reset_val,
4899  conf->reset_extra);
4900  *conf->variable = conf->reset_val;
4901  set_extra_field(&conf->gen, &conf->gen.extra,
4902  conf->reset_extra);
4903  break;
4904  }
4905  }
4906 
4907  gconf->source = gconf->reset_source;
4908  gconf->scontext = gconf->reset_scontext;
4909 
4910  if (gconf->flags & GUC_REPORT)
4911  ReportGUCOption(gconf);
4912  }
4913 }
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:4921
int * variable
Definition: guc_tables.h:194
int * variable
Definition: guc_tables.h:240
static int num_guc_variables
Definition: guc.c:3895
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:4066
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:4005
static struct config_generic ** guc_variables
Definition: guc.c:3892
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:5345
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 9269 of file guc.c.

References can_skip_gucvar(), ereport, errcode(), errmsg(), ERROR, GUC_ACTION_SET, i, InitializeOneGUCOption(), num_guc_variables, read_gucstate(), read_gucstate_binary(), set_config_option(), and set_config_sourcefile().

Referenced by ParallelWorkerMain().

9270 {
9271  char *varname,
9272  *varvalue,
9273  *varsourcefile;
9274  int varsourceline;
9275  GucSource varsource;
9276  GucContext varscontext;
9277  char *srcptr = (char *) gucstate;
9278  char *srcend;
9279  Size len;
9280  int i;
9281 
9282  /* See comment at can_skip_gucvar(). */
9283  for (i = 0; i < num_guc_variables; i++)
9284  if (!can_skip_gucvar(guc_variables[i]))
9286 
9287  /* First item is the length of the subsequent data */
9288  memcpy(&len, gucstate, sizeof(len));
9289 
9290  srcptr += sizeof(len);
9291  srcend = srcptr + len;
9292 
9293  while (srcptr < srcend)
9294  {
9295  int result;
9296 
9297  varname = read_gucstate(&srcptr, srcend);
9298  varvalue = read_gucstate(&srcptr, srcend);
9299  varsourcefile = read_gucstate(&srcptr, srcend);
9300  if (varsourcefile[0])
9301  read_gucstate_binary(&srcptr, srcend,
9302  &varsourceline, sizeof(varsourceline));
9303  read_gucstate_binary(&srcptr, srcend,
9304  &varsource, sizeof(varsource));
9305  read_gucstate_binary(&srcptr, srcend,
9306  &varscontext, sizeof(varscontext));
9307 
9308  result = set_config_option(varname, varvalue, varscontext, varsource,
9309  GUC_ACTION_SET, true, ERROR, true);
9310  if (result <= 0)
9311  ereport(ERROR,
9312  (errcode(ERRCODE_INTERNAL_ERROR),
9313  errmsg("parameter \"%s\" could not be set", varname)));
9314  if (varsourcefile[0])
9315  set_config_sourcefile(varname, varsourcefile, varsourceline);
9316  }
9317 }
GucContext
Definition: guc.h:68
static void static void set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
Definition: guc.c:6595
static void read_gucstate_binary(char **srcptr, char *srcend, void *dest, Size size)
Definition: guc.c:9254
int errcode(int sqlerrcode)
Definition: elog.c:575
GucSource
Definition: guc.h:105
#define ERROR
Definition: elog.h:43
static int num_guc_variables
Definition: guc.c:3895
static bool can_skip_gucvar(struct config_generic *gconf)
Definition: guc.c:8933
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:4526
#define ereport(elevel, rest)
Definition: elog.h:122
static struct config_generic ** guc_variables
Definition: guc.c:3892
static char * read_gucstate(char **srcptr, char *srcend)
Definition: guc.c:9231
size_t Size
Definition: c.h:353
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:5865
bool SelectConfigFiles ( const char *  userDoption,
const char *  progname 
)

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

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

Definition at line 9191 of file guc.c.

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

Referenced by InitializeParallelDSM().

9192 {
9193  char *curptr;
9194  Size actual_size;
9195  Size bytes_left;
9196  int i;
9197  int i_role = -1;
9198 
9199  /* Reserve space for saving the actual size of the guc state */
9200  Assert(maxsize > sizeof(actual_size));
9201  curptr = start_address + sizeof(actual_size);
9202  bytes_left = maxsize - sizeof(actual_size);
9203 
9204  for (i = 0; i < num_guc_variables; i++)
9205  {
9206  /*
9207  * It's pretty ugly, but we've got to force "role" to be initialized
9208  * after "session_authorization"; otherwise, the latter will override
9209  * the former.
9210  */
9211  if (strcmp(guc_variables[i]->name, "role") == 0)
9212  i_role = i;
9213  else
9214  serialize_variable(&curptr, &bytes_left, guc_variables[i]);
9215  }
9216  if (i_role >= 0)
9217  serialize_variable(&curptr, &bytes_left, guc_variables[i_role]);
9218 
9219  /* Store actual size without assuming alignment of start_address. */
9220  actual_size = maxsize - bytes_left - sizeof(actual_size);
9221  memcpy(start_address, &actual_size, sizeof(actual_size));
9222 }
static void serialize_variable(char **destptr, Size *maxbytes, struct config_generic *gconf)
Definition: guc.c:9117
static int num_guc_variables
Definition: guc.c:3895
static struct config_generic ** guc_variables
Definition: guc.c:3892
#define Assert(condition)
Definition: c.h:671
size_t Size
Definition: c.h:353
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 5865 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().

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