PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
guc.c File Reference
#include "postgres.h"
#include <ctype.h>
#include <float.h>
#include <math.h>
#include <limits.h>
#include <unistd.h>
#include <sys/stat.h>
#include "access/commit_ts.h"
#include "access/gin.h"
#include "access/rmgr.h"
#include "access/transam.h"
#include "access/twophase.h"
#include "access/xact.h"
#include "access/xlog_internal.h"
#include "catalog/namespace.h"
#include "commands/async.h"
#include "commands/prepare.h"
#include "commands/user.h"
#include "commands/vacuum.h"
#include "commands/variable.h"
#include "commands/trigger.h"
#include "funcapi.h"
#include "libpq/auth.h"
#include "libpq/be-fsstubs.h"
#include "libpq/libpq.h"
#include "libpq/pqformat.h"
#include "miscadmin.h"
#include "optimizer/cost.h"
#include "optimizer/geqo.h"
#include "optimizer/paths.h"
#include "optimizer/planmain.h"
#include "parser/parse_expr.h"
#include "parser/parse_type.h"
#include "parser/parser.h"
#include "parser/scansup.h"
#include "pgstat.h"
#include "postmaster/autovacuum.h"
#include "postmaster/bgworker.h"
#include "postmaster/bgwriter.h"
#include "postmaster/postmaster.h"
#include "postmaster/syslogger.h"
#include "postmaster/walwriter.h"
#include "replication/logicallauncher.h"
#include "replication/slot.h"
#include "replication/syncrep.h"
#include "replication/walreceiver.h"
#include "replication/walsender.h"
#include "storage/bufmgr.h"
#include "storage/dsm_impl.h"
#include "storage/standby.h"
#include "storage/fd.h"
#include "storage/pg_shmem.h"
#include "storage/proc.h"
#include "storage/predicate.h"
#include "tcop/tcopprot.h"
#include "tsearch/ts_cache.h"
#include "utils/builtins.h"
#include "utils/bytea.h"
#include "utils/guc_tables.h"
#include "utils/memutils.h"
#include "utils/pg_locale.h"
#include "utils/plancache.h"
#include "utils/portal.h"
#include "utils/ps_status.h"
#include "utils/rls.h"
#include "utils/snapmgr.h"
#include "utils/tzparser.h"
#include "utils/varlena.h"
#include "utils/xml.h"
#include "guc-file.c"
Include dependency graph for guc.c:

Go to the source code of this file.

Data Structures

struct  unit_conversion
 

Macros

#define PG_KRB_SRVTAB   ""
 
#define CONFIG_FILENAME   "postgresql.conf"
 
#define HBA_FILENAME   "pg_hba.conf"
 
#define IDENT_FILENAME   "pg_ident.conf"
 
#define REALTYPE_PRECISION   17
 
#define MAX_UNIT_LEN   3 /* length of longest recognized unit string */
 
#define newval   (newval_union.boolval)
 
#define newval   (newval_union.intval)
 
#define newval   (newval_union.realval)
 
#define newval   (newval_union.stringval)
 
#define newval   (newval_union.enumval)
 
#define NUM_PG_SETTINGS_ATTS   17
 
#define NUM_PG_FILE_SETTINGS_ATTS   7
 

Functions

static void do_serialize (char **destptr, Size *maxbytes, const char *fmt,...) pg_attribute_printf(3
 
static void static void set_config_sourcefile (const char *name, char *sourcefile, int sourceline)
 
static bool call_bool_check_hook (struct config_bool *conf, bool *newval, void **extra, GucSource source, int elevel)
 
static bool call_int_check_hook (struct config_int *conf, int *newval, void **extra, GucSource source, int elevel)
 
static bool call_real_check_hook (struct config_real *conf, double *newval, void **extra, GucSource source, int elevel)
 
static bool call_string_check_hook (struct config_string *conf, char **newval, void **extra, GucSource source, int elevel)
 
static bool call_enum_check_hook (struct config_enum *conf, int *newval, void **extra, GucSource source, int elevel)
 
static bool check_log_destination (char **newval, void **extra, GucSource source)
 
static void assign_log_destination (const char *newval, void *extra)
 
static bool check_wal_consistency_checking (char **newval, void **extra, GucSource source)
 
static void assign_wal_consistency_checking (const char *newval, void *extra)
 
static void assign_syslog_facility (int newval, void *extra)
 
static void assign_syslog_ident (const char *newval, void *extra)
 
static void assign_session_replication_role (int newval, void *extra)
 
static bool check_temp_buffers (int *newval, void **extra, GucSource source)
 
static bool check_bonjour (bool *newval, void **extra, GucSource source)
 
static bool check_ssl (bool *newval, void **extra, GucSource source)
 
static bool check_stage_log_stats (bool *newval, void **extra, GucSource source)
 
static bool check_log_stats (bool *newval, void **extra, GucSource source)
 
static bool check_canonical_path (char **newval, void **extra, GucSource source)
 
static bool check_timezone_abbreviations (char **newval, void **extra, GucSource source)
 
static void assign_timezone_abbreviations (const char *newval, void *extra)
 
static void pg_timezone_abbrev_initialize (void)
 
static const char * show_archive_command (void)
 
static void assign_tcp_keepalives_idle (int newval, void *extra)
 
static void assign_tcp_keepalives_interval (int newval, void *extra)
 
static void assign_tcp_keepalives_count (int newval, void *extra)
 
static const char * show_tcp_keepalives_idle (void)
 
static const char * show_tcp_keepalives_interval (void)
 
static const char * show_tcp_keepalives_count (void)
 
static bool check_maxconnections (int *newval, void **extra, GucSource source)
 
static bool check_max_worker_processes (int *newval, void **extra, GucSource source)
 
static bool check_autovacuum_max_workers (int *newval, void **extra, GucSource source)
 
static bool check_autovacuum_work_mem (int *newval, void **extra, GucSource source)
 
static bool check_effective_io_concurrency (int *newval, void **extra, GucSource source)
 
static void assign_effective_io_concurrency (int newval, void *extra)
 
static void assign_pgstat_temp_directory (const char *newval, void *extra)
 
static bool check_application_name (char **newval, void **extra, GucSource source)
 
static void assign_application_name (const char *newval, void *extra)
 
static bool check_cluster_name (char **newval, void **extra, GucSource source)
 
static const char * show_unix_socket_permissions (void)
 
static const char * show_log_file_mode (void)
 
static ConfigVariableProcessConfigFileInternal (GucContext context, bool applySettings, int elevel)
 
static int guc_var_compare (const void *a, const void *b)
 
static int guc_name_compare (const char *namea, const char *nameb)
 
static void InitializeGUCOptionsFromEnvironment (void)
 
static void InitializeOneGUCOption (struct config_generic *gconf)
 
static void push_old_value (struct config_generic *gconf, GucAction action)
 
static void ReportGUCOption (struct config_generic *record)
 
static void reapply_stacked_values (struct config_generic *variable, struct config_string *pHolder, GucStack *stack, const char *curvalue, GucContext curscontext, GucSource cursource)
 
static void ShowGUCConfigOption (const char *name, DestReceiver *dest)
 
static void ShowAllGUCConfig (DestReceiver *dest)
 
static char * _ShowOption (struct config_generic *record, bool use_units)
 
static bool validate_option_array_item (const char *name, const char *value, bool skipIfNoPermissions)
 
static void write_auto_conf_file (int fd, const char *filename, ConfigVariable *head_p)
 
static void replace_auto_config_value (ConfigVariable **head_p, ConfigVariable **tail_p, const char *name, const char *value)
 
static void * guc_malloc (int elevel, size_t size)
 
static void * guc_realloc (int elevel, void *old, size_t size)
 
static char * guc_strdup (int elevel, const char *src)
 
static bool string_field_used (struct config_string *conf, char *strval)
 
static void set_string_field (struct config_string *conf, char **field, char *newval)
 
static bool extra_field_used (struct config_generic *gconf, void *extra)
 
static void set_extra_field (struct config_generic *gconf, void **field, void *newval)
 
static void set_stack_value (struct config_generic *gconf, config_var_value *val)
 
static void discard_stack_value (struct config_generic *gconf, config_var_value *val)
 
struct config_generic ** get_guc_variables (void)
 
void build_guc_variables (void)
 
static bool add_guc_variable (struct config_generic *var, int elevel)
 
static struct config_genericadd_placeholder_variable (const char *name, int elevel)
 
static struct config_genericfind_option (const char *name, bool create_placeholders, int elevel)
 
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)
 
static bool convert_to_base_unit (int64 value, const char *unit, int base_unit, int64 *base_value)
 
static void convert_from_base_unit (int64 base_value, int base_unit, int64 *value, const char **unit)
 
bool parse_int (const char *value, int *result, int flags, const char **hintmsg)
 
bool parse_real (const char *value, double *result)
 
const char * config_enum_lookup_by_value (struct config_enum *record, int val)
 
bool config_enum_lookup_by_name (struct config_enum *record, const char *value, int *retval)
 
static char * config_enum_get_options (struct config_enum *record, const char *prefix, const char *suffix, const char *separator)
 
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)
 
int set_config_option (const char *name, const char *value, GucContext context, GucSource source, GucAction action, bool changeVal, int elevel, bool is_reload)
 
void SetConfigOption (const char *name, const char *value, GucContext context, GucSource source)
 
const char * GetConfigOption (const char *name, bool missing_ok, bool restrict_superuser)
 
const char * GetConfigOptionResetString (const char *name)
 
static char * flatten_set_variable_args (const char *name, List *args)
 
void AlterSystemSetConfigFile (AlterSystemStmt *altersysstmt)
 
void ExecSetVariableStmt (VariableSetStmt *stmt, bool isTopLevel)
 
char * ExtractSetVariableArgs (VariableSetStmt *stmt)
 
void SetPGVariable (const char *name, List *args, bool is_local)
 
Datum set_config_by_name (PG_FUNCTION_ARGS)
 
static struct config_genericinit_custom_variable (const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
 
static void define_custom_variable (struct config_generic *variable)
 
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)
 
void GetPGVariable (const char *name, DestReceiver *dest)
 
TupleDesc GetPGVariableResultDesc (const char *name)
 
char * GetConfigOptionByName (const char *name, const char **varname, bool missing_ok)
 
void GetConfigOptionByNum (int varnum, const char **values, bool *noshow)
 
int GetNumConfigOptions (void)
 
Datum show_config_by_name (PG_FUNCTION_ARGS)
 
Datum show_config_by_name_missing_ok (PG_FUNCTION_ARGS)
 
Datum show_all_settings (PG_FUNCTION_ARGS)
 
Datum show_all_file_settings (PG_FUNCTION_ARGS)
 
static bool can_skip_gucvar (struct config_generic *gconf)
 
static Size estimate_variable_size (struct config_generic *gconf)
 
Size EstimateGUCStateSpace (void)
 
static void do_serialize_binary (char **destptr, Size *maxbytes, void *val, Size valsize)
 
static void serialize_variable (char **destptr, Size *maxbytes, struct config_generic *gconf)
 
void SerializeGUCState (Size maxsize, char *start_address)
 
static char * read_gucstate (char **srcptr, char *srcend)
 
static void read_gucstate_binary (char **srcptr, char *srcend, void *dest, Size size)
 
void RestoreGUCState (void *gucstate)
 
void ParseLongOption (const char *string, char **name, char **value)
 
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)
 
void GUC_check_errcode (int sqlerrcode)
 

Variables

bool Log_disconnections
 
int CommitDelay
 
int CommitSiblings
 
char * default_tablespace
 
char * temp_tablespaces
 
bool ignore_checksum_failure
 
bool synchronize_seqscans
 
static int GUC_check_errcode_value
 
char * GUC_check_errmsg_string
 
char * GUC_check_errdetail_string
 
char * GUC_check_errhint_string
 
static int syslog_facility = 0
 
static const struct
config_enum_entry 
bytea_output_options []
 
static const struct
config_enum_entry 
client_message_level_options []
 
static const struct
config_enum_entry 
server_message_level_options []
 
static const struct
config_enum_entry 
intervalstyle_options []
 
static const struct
config_enum_entry 
log_error_verbosity_options []
 
static const struct
config_enum_entry 
log_statement_options []
 
static const struct
config_enum_entry 
isolation_level_options []
 
static const struct
config_enum_entry 
session_replication_role_options []
 
static const struct
config_enum_entry 
syslog_facility_options []
 
static const struct
config_enum_entry 
track_function_options []
 
static const struct
config_enum_entry 
xmlbinary_options []
 
static const struct
config_enum_entry 
xmloption_options []
 
static const struct
config_enum_entry 
backslash_quote_options []
 
static const struct
config_enum_entry 
constraint_exclusion_options []
 
static const struct
config_enum_entry 
synchronous_commit_options []
 
static const struct
config_enum_entry 
huge_pages_options []
 
static const struct
config_enum_entry 
force_parallel_mode_options []
 
static const struct
config_enum_entry 
password_encryption_options []
 
const struct config_enum_entry wal_level_options []
 
const struct config_enum_entry archive_mode_options []
 
const struct config_enum_entry sync_method_options []
 
const struct config_enum_entry dynamic_shared_memory_options []
 
bool log_duration = false
 
bool Debug_print_plan = false
 
bool Debug_print_parse = false
 
bool Debug_print_rewritten = false
 
bool Debug_pretty_print = true
 
bool log_parser_stats = false
 
bool log_planner_stats = false
 
bool log_executor_stats = false
 
bool log_statement_stats = false
 
bool log_btree_build_stats = false
 
char * event_source
 
bool row_security
 
bool check_function_bodies = true
 
bool default_with_oids = false
 
int log_min_error_statement = ERROR
 
int log_min_messages = WARNING
 
int client_min_messages = NOTICE
 
int log_min_duration_statement = -1
 
int log_temp_files = -1
 
int trace_recovery_messages = LOG
 
int temp_file_limit = -1
 
int num_temp_buffers = 1024
 
char * cluster_name = ""
 
char * ConfigFileName
 
char * HbaFileName
 
char * IdentFileName
 
char * external_pid_file
 
char * pgstat_temp_directory
 
char * application_name
 
int tcp_keepalives_idle
 
int tcp_keepalives_interval
 
int tcp_keepalives_count
 
int ssl_renegotiation_limit
 
int huge_pages
 
static char * syslog_ident_str
 
static bool session_auth_is_superuser
 
static double phony_random_seed
 
static char * client_encoding_string
 
static char * datestyle_string
 
static char * locale_collate
 
static char * locale_ctype
 
static char * server_encoding_string
 
static char * server_version_string
 
static int server_version_num
 
static char * timezone_string
 
static char * log_timezone_string
 
static char * timezone_abbreviations_string
 
static char * XactIsoLevel_string
 
static char * data_directory
 
static char * session_authorization_string
 
static int max_function_args
 
static int max_index_keys
 
static int max_identifier_length
 
static int block_size
 
static int segment_size
 
static int wal_block_size
 
static bool data_checksums
 
static int wal_segment_size
 
static bool integer_datetimes
 
static bool assert_enabled
 
char * role_string
 
const char *const GucContext_Names []
 
const char *const GucSource_Names []
 
const char *const config_group_names []
 
const char *const config_type_names []
 
static const char * memory_units_hint = gettext_noop("Valid units for this parameter are \"kB\", \"MB\", \"GB\", and \"TB\".")
 
static const unit_conversion memory_unit_conversion_table []
 
static const char * time_units_hint = gettext_noop("Valid units for this parameter are \"ms\", \"s\", \"min\", \"h\", and \"d\".")
 
static const unit_conversion time_unit_conversion_table []
 
static struct config_bool ConfigureNamesBool []
 
static struct config_int ConfigureNamesInt []
 
static struct config_real ConfigureNamesReal []
 
static struct config_string ConfigureNamesString []
 
static struct config_enum ConfigureNamesEnum []
 
static const char *const map_old_guc_names []
 
static struct config_generic ** guc_variables
 
static int num_guc_variables
 
static int size_guc_variables
 
static bool guc_dirty
 
static bool reporting_enabled
 
static int GUCNestLevel = 0
 

Macro Definition Documentation

#define CONFIG_FILENAME   "postgresql.conf"

Definition at line 96 of file guc.c.

Referenced by SelectConfigFiles().

#define HBA_FILENAME   "pg_hba.conf"

Definition at line 97 of file guc.c.

Referenced by SelectConfigFiles().

#define IDENT_FILENAME   "pg_ident.conf"

Definition at line 98 of file guc.c.

Referenced by SelectConfigFiles().

#define MAX_UNIT_LEN   3 /* length of longest recognized unit string */

Definition at line 698 of file guc.c.

Referenced by parse_int().

#define newval   (newval_union.intval)
#define newval   (newval_union.realval)
#define newval   (newval_union.stringval)
#define newval   (newval_union.enumval)
#define NUM_PG_FILE_SETTINGS_ATTS   7

Referenced by show_all_file_settings().

#define NUM_PG_SETTINGS_ATTS   17

Definition at line 8339 of file guc.c.

Referenced by show_all_settings().

#define PG_KRB_SRVTAB   ""

Definition at line 93 of file guc.c.

#define REALTYPE_PRECISION   17

Definition at line 109 of file guc.c.

Referenced by estimate_variable_size(), and serialize_variable().

Function Documentation

static char * _ShowOption ( struct config_generic record,
bool  use_units 
)
static

Definition at line 8586 of file guc.c.

References config_enum_lookup_by_value(), convert_from_base_unit(), config_generic::flags, GUC_UNIT, INT64_FORMAT, PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_STRING, pstrdup(), config_bool::show_hook, config_int::show_hook, config_real::show_hook, config_string::show_hook, config_enum::show_hook, snprintf(), val, config_bool::variable, config_int::variable, config_real::variable, config_string::variable, config_enum::variable, and config_generic::vartype.

Referenced by GetConfigOptionByName(), GetConfigOptionByNum(), ReportGUCOption(), and ShowAllGUCConfig().

8587 {
8588  char buffer[256];
8589  const char *val;
8590 
8591  switch (record->vartype)
8592  {
8593  case PGC_BOOL:
8594  {
8595  struct config_bool *conf = (struct config_bool *) record;
8596 
8597  if (conf->show_hook)
8598  val = (*conf->show_hook) ();
8599  else
8600  val = *conf->variable ? "on" : "off";
8601  }
8602  break;
8603 
8604  case PGC_INT:
8605  {
8606  struct config_int *conf = (struct config_int *) record;
8607 
8608  if (conf->show_hook)
8609  val = (*conf->show_hook) ();
8610  else
8611  {
8612  /*
8613  * Use int64 arithmetic to avoid overflows in units
8614  * conversion.
8615  */
8616  int64 result = *conf->variable;
8617  const char *unit;
8618 
8619  if (use_units && result > 0 && (record->flags & GUC_UNIT))
8620  {
8621  convert_from_base_unit(result, record->flags & GUC_UNIT,
8622  &result, &unit);
8623  }
8624  else
8625  unit = "";
8626 
8627  snprintf(buffer, sizeof(buffer), INT64_FORMAT "%s",
8628  result, unit);
8629  val = buffer;
8630  }
8631  }
8632  break;
8633 
8634  case PGC_REAL:
8635  {
8636  struct config_real *conf = (struct config_real *) record;
8637 
8638  if (conf->show_hook)
8639  val = (*conf->show_hook) ();
8640  else
8641  {
8642  snprintf(buffer, sizeof(buffer), "%g",
8643  *conf->variable);
8644  val = buffer;
8645  }
8646  }
8647  break;
8648 
8649  case PGC_STRING:
8650  {
8651  struct config_string *conf = (struct config_string *) record;
8652 
8653  if (conf->show_hook)
8654  val = (*conf->show_hook) ();
8655  else if (*conf->variable && **conf->variable)
8656  val = *conf->variable;
8657  else
8658  val = "";
8659  }
8660  break;
8661 
8662  case PGC_ENUM:
8663  {
8664  struct config_enum *conf = (struct config_enum *) record;
8665 
8666  if (conf->show_hook)
8667  val = (*conf->show_hook) ();
8668  else
8669  val = config_enum_lookup_by_value(conf, *conf->variable);
8670  }
8671  break;
8672 
8673  default:
8674  /* just to keep compiler quiet */
8675  val = "???";
8676  break;
8677  }
8678 
8679  return pstrdup(val);
8680 }
char ** variable
Definition: guc_tables.h:226
char * pstrdup(const char *in)
Definition: mcxt.c:1165
bool * variable
Definition: guc_tables.h:180
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5574
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define GUC_UNIT
Definition: guc.h:229
GucShowHook show_hook
Definition: guc_tables.h:200
int * variable
Definition: guc_tables.h:194
int * variable
Definition: guc_tables.h:240
GucShowHook show_hook
Definition: guc_tables.h:230
GucShowHook show_hook
Definition: guc_tables.h:216
double * variable
Definition: guc_tables.h:210
enum config_type vartype
Definition: guc_tables.h:152
GucShowHook show_hook
Definition: guc_tables.h:245
GucShowHook show_hook
Definition: guc_tables.h:184
#define INT64_FORMAT
Definition: c.h:312
static void convert_from_base_unit(int64 base_value, int base_unit, int64 *value, const char **unit)
Definition: guc.c:5402
long val
Definition: informix.c:689
static bool add_guc_variable ( struct config_generic var,
int  elevel 
)
static

Definition at line 4243 of file guc.c.

References guc_malloc(), guc_realloc(), guc_var_compare(), NULL, and qsort.

Referenced by add_placeholder_variable(), and define_custom_variable().

4244 {
4246  {
4247  /*
4248  * Increase the vector by 25%
4249  */
4250  int size_vars = size_guc_variables + size_guc_variables / 4;
4251  struct config_generic **guc_vars;
4252 
4253  if (size_vars == 0)
4254  {
4255  size_vars = 100;
4256  guc_vars = (struct config_generic **)
4257  guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
4258  }
4259  else
4260  {
4261  guc_vars = (struct config_generic **)
4262  guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
4263  }
4264 
4265  if (guc_vars == NULL)
4266  return false; /* out of memory */
4267 
4268  guc_variables = guc_vars;
4269  size_guc_variables = size_vars;
4270  }
4273  sizeof(struct config_generic *), guc_var_compare);
4274  return true;
4275 }
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:4378
static int num_guc_variables
Definition: guc.c:3895
static void * guc_realloc(int elevel, void *old, size_t size)
Definition: guc.c:3949
static struct config_generic ** guc_variables
Definition: guc.c:3892
static int size_guc_variables
Definition: guc.c:3898
static int elevel
Definition: vacuumlazy.c:136
#define NULL
Definition: c.h:226
#define qsort(a, b, c, d)
Definition: port.h:440
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:3933
static struct config_generic* add_placeholder_variable ( const char *  name,
int  elevel 
)
static

Definition at line 4281 of file guc.c.

References add_guc_variable(), config_generic::context, CUSTOM_OPTIONS, config_generic::flags, free, config_string::gen, config_generic::group, GUC_CUSTOM_PLACEHOLDER, guc_malloc(), GUC_NO_SHOW_ALL, GUC_NOT_IN_SAMPLE, guc_strdup(), config_generic::name, NULL, PGC_STRING, PGC_USERSET, config_generic::short_desc, config_string::variable, and config_generic::vartype.

Referenced by find_option().

4282 {
4283  size_t sz = sizeof(struct config_string) + sizeof(char *);
4284  struct config_string *var;
4285  struct config_generic *gen;
4286 
4287  var = (struct config_string *) guc_malloc(elevel, sz);
4288  if (var == NULL)
4289  return NULL;
4290  memset(var, 0, sz);
4291  gen = &var->gen;
4292 
4293  gen->name = guc_strdup(elevel, name);
4294  if (gen->name == NULL)
4295  {
4296  free(var);
4297  return NULL;
4298  }
4299 
4300  gen->context = PGC_USERSET;
4301  gen->group = CUSTOM_OPTIONS;
4302  gen->short_desc = "GUC placeholder variable";
4304  gen->vartype = PGC_STRING;
4305 
4306  /*
4307  * The char* is allocated at the end of the struct since we have no
4308  * 'static' place to point to. Note that the current value, as well as
4309  * the boot and reset values, start out NULL.
4310  */
4311  var->variable = (char **) (var + 1);
4312 
4313  if (!add_guc_variable((struct config_generic *) var, elevel))
4314  {
4315  free((void *) gen->name);
4316  free(var);
4317  return NULL;
4318  }
4319 
4320  return gen;
4321 }
char ** variable
Definition: guc_tables.h:226
const char * name
Definition: guc_tables.h:145
const char * short_desc
Definition: guc_tables.h:148
static char * guc_strdup(int elevel, const char *src)
Definition: guc.c:3965
#define GUC_NO_SHOW_ALL
Definition: guc.h:206
#define GUC_NOT_IN_SAMPLE
Definition: guc.h:209
enum config_type vartype
Definition: guc_tables.h:152
static int elevel
Definition: vacuumlazy.c:136
struct config_generic gen
Definition: guc_tables.h:224
#define free(a)
Definition: header.h:60
#define NULL
Definition: c.h:226
#define GUC_CUSTOM_PLACEHOLDER
Definition: guc.h:211
const char * name
Definition: encode.c:521
enum config_group group
Definition: guc_tables.h:147
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:3933
GucContext context
Definition: guc_tables.h:146
static bool add_guc_variable(struct config_generic *var, int elevel)
Definition: guc.c:4243
void AlterSystemSetConfigFile ( AlterSystemStmt altersysstmt)

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
VariableSetKind kind
Definition: parsenodes.h:1864
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
VariableSetStmt * setstmt
Definition: parsenodes.h:2946
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
static void assign_application_name ( const char *  newval,
void *  extra 
)
static

Definition at line 10416 of file guc.c.

References pgstat_report_appname().

10417 {
10418  /* Update the pg_stat_activity view */
10420 }
void pgstat_report_appname(const char *appname)
Definition: pgstat.c:2974
#define newval
static void assign_effective_io_concurrency ( int  newval,
void *  extra 
)
static

Definition at line 10364 of file guc.c.

References target_prefetch_pages.

10365 {
10366 #ifdef USE_PREFETCH
10367  target_prefetch_pages = *((int *) extra);
10368 #endif /* USE_PREFETCH */
10369 }
int target_prefetch_pages
Definition: bufmgr.c:129
static void assign_log_destination ( const char *  newval,
void *  extra 
)
static

Definition at line 10052 of file guc.c.

References Log_destination.

10053 {
10054  Log_destination = *((int *) extra);
10055 }
int Log_destination
Definition: elog.c:106
static void assign_pgstat_temp_directory ( const char *  newval,
void *  extra 
)
static

Definition at line 10372 of file guc.c.

References ERROR, free, guc_malloc(), pgstat_stat_directory, pgstat_stat_filename, and pgstat_stat_tmpname.

10373 {
10374  /* check_canonical_path already canonicalized newval for us */
10375  char *dname;
10376  char *tname;
10377  char *fname;
10378 
10379  /* directory */
10380  dname = guc_malloc(ERROR, strlen(newval) + 1); /* runtime dir */
10381  sprintf(dname, "%s", newval);
10382 
10383  /* global stats */
10384  tname = guc_malloc(ERROR, strlen(newval) + 12); /* /global.tmp */
10385  sprintf(tname, "%s/global.tmp", newval);
10386  fname = guc_malloc(ERROR, strlen(newval) + 13); /* /global.stat */
10387  sprintf(fname, "%s/global.stat", newval);
10388 
10391  pgstat_stat_directory = dname;
10392  if (pgstat_stat_tmpname)
10394  pgstat_stat_tmpname = tname;
10397  pgstat_stat_filename = fname;
10398 }
char * pgstat_stat_filename
Definition: pgstat.c:119
#define ERROR
Definition: elog.h:43
char * pgstat_stat_directory
Definition: pgstat.c:118
#define free(a)
Definition: header.h:60
#define newval
char * pgstat_stat_tmpname
Definition: pgstat.c:120
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:3933
static void assign_session_replication_role ( int  newval,
void *  extra 
)
static

Definition at line 10078 of file guc.c.

References ResetPlanCache(), and SessionReplicationRole.

10079 {
10080  /*
10081  * Must flush the plan cache when changing replication role; but don't
10082  * flush unnecessarily.
10083  */
10085  ResetPlanCache();
10086 }
int SessionReplicationRole
Definition: trigger.c:64
void ResetPlanCache(void)
Definition: plancache.c:1854
#define newval
static void assign_syslog_facility ( int  newval,
void *  extra 
)
static

Definition at line 10058 of file guc.c.

10059 {
10060 #ifdef HAVE_SYSLOG
10061  set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
10062  newval);
10063 #endif
10064  /* Without syslog support, just ignore it */
10065 }
static char * syslog_ident_str
Definition: guc.c:496
#define newval
static void assign_syslog_ident ( const char *  newval,
void *  extra 
)
static

Definition at line 10068 of file guc.c.

10069 {
10070 #ifdef HAVE_SYSLOG
10071  set_syslog_parameters(newval, syslog_facility);
10072 #endif
10073  /* Without syslog support, it will always be set to "none", so ignore */
10074 }
static int syslog_facility
Definition: guc.c:159
#define newval
static void assign_tcp_keepalives_count ( int  newval,
void *  extra 
)
static

Definition at line 10277 of file guc.c.

References MyProcPort, and pq_setkeepalivescount().

10278 {
10279  /* See comments in assign_tcp_keepalives_idle */
10281 }
struct Port * MyProcPort
Definition: globals.c:40
int pq_setkeepalivescount(int count, Port *port)
Definition: pqcomm.c:1852
#define newval
static void assign_tcp_keepalives_idle ( int  newval,
void *  extra 
)
static

Definition at line 10233 of file guc.c.

References MyProcPort, and pq_setkeepalivesidle().

10234 {
10235  /*
10236  * The kernel API provides no way to test a value without setting it; and
10237  * once we set it we might fail to unset it. So there seems little point
10238  * in fully implementing the check-then-assign GUC API for these
10239  * variables. Instead we just do the assignment on demand. pqcomm.c
10240  * reports any problems via elog(LOG).
10241  *
10242  * This approach means that the GUC value might have little to do with the
10243  * actual kernel value, so we use a show_hook that retrieves the kernel
10244  * value rather than trusting GUC's copy.
10245  */
10247 }
struct Port * MyProcPort
Definition: globals.c:40
int pq_setkeepalivesidle(int idle, Port *port)
Definition: pqcomm.c:1687
#define newval
static void assign_tcp_keepalives_interval ( int  newval,
void *  extra 
)
static

Definition at line 10260 of file guc.c.

References MyProcPort, and pq_setkeepalivesinterval().

10261 {
10262  /* See comments in assign_tcp_keepalives_idle */
10264 }
struct Port * MyProcPort
Definition: globals.c:40
int pq_setkeepalivesinterval(int interval, Port *port)
Definition: pqcomm.c:1776
#define newval
static void assign_timezone_abbreviations ( const char *  newval,
void *  extra 
)
static

Definition at line 10197 of file guc.c.

References InstallTimeZoneAbbrevs().

10198 {
10199  /* Do nothing for the boot_val default of NULL */
10200  if (!extra)
10201  return;
10202 
10204 }
void InstallTimeZoneAbbrevs(TimeZoneAbbrevTable *tbl)
Definition: datetime.c:4603
static void assign_wal_consistency_checking ( const char *  newval,
void *  extra 
)
static

Definition at line 9989 of file guc.c.

References wal_consistency_checking.

9990 {
9991  wal_consistency_checking = (bool *) extra;
9992 }
bool * wal_consistency_checking
Definition: xlog.c:100
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
void build_guc_variables ( void  )

Definition at line 4156 of file guc.c.

References FATAL, free, config_bool::gen, config_int::gen, config_real::gen, config_string::gen, config_enum::gen, guc_malloc(), guc_var_compare(), i, config_generic::name, PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_STRING, qsort, and config_generic::vartype.

Referenced by GucInfoMain(), and InitializeGUCOptions().

4157 {
4158  int size_vars;
4159  int num_vars = 0;
4160  struct config_generic **guc_vars;
4161  int i;
4162 
4163  for (i = 0; ConfigureNamesBool[i].gen.name; i++)
4164  {
4165  struct config_bool *conf = &ConfigureNamesBool[i];
4166 
4167  /* Rather than requiring vartype to be filled in by hand, do this: */
4168  conf->gen.vartype = PGC_BOOL;
4169  num_vars++;
4170  }
4171 
4172  for (i = 0; ConfigureNamesInt[i].gen.name; i++)
4173  {
4174  struct config_int *conf = &ConfigureNamesInt[i];
4175 
4176  conf->gen.vartype = PGC_INT;
4177  num_vars++;
4178  }
4179 
4180  for (i = 0; ConfigureNamesReal[i].gen.name; i++)
4181  {
4182  struct config_real *conf = &ConfigureNamesReal[i];
4183 
4184  conf->gen.vartype = PGC_REAL;
4185  num_vars++;
4186  }
4187 
4188  for (i = 0; ConfigureNamesString[i].gen.name; i++)
4189  {
4190  struct config_string *conf = &ConfigureNamesString[i];
4191 
4192  conf->gen.vartype = PGC_STRING;
4193  num_vars++;
4194  }
4195 
4196  for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
4197  {
4198  struct config_enum *conf = &ConfigureNamesEnum[i];
4199 
4200  conf->gen.vartype = PGC_ENUM;
4201  num_vars++;
4202  }
4203 
4204  /*
4205  * Create table with 20% slack
4206  */
4207  size_vars = num_vars + num_vars / 4;
4208 
4209  guc_vars = (struct config_generic **)
4210  guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
4211 
4212  num_vars = 0;
4213 
4214  for (i = 0; ConfigureNamesBool[i].gen.name; i++)
4215  guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
4216 
4217  for (i = 0; ConfigureNamesInt[i].gen.name; i++)
4218  guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
4219 
4220  for (i = 0; ConfigureNamesReal[i].gen.name; i++)
4221  guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
4222 
4223  for (i = 0; ConfigureNamesString[i].gen.name; i++)
4224  guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
4225 
4226  for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
4227  guc_vars[num_vars++] = &ConfigureNamesEnum[i].gen;
4228 
4229  if (guc_variables)
4231  guc_variables = guc_vars;
4232  num_guc_variables = num_vars;
4233  size_guc_variables = size_vars;
4235  sizeof(struct config_generic *), guc_var_compare);
4236 }
static struct config_int ConfigureNamesInt[]
Definition: guc.c:1667
const char * name
Definition: guc_tables.h:145
static struct config_enum ConfigureNamesEnum[]
Definition: guc.c:3606
static struct config_bool ConfigureNamesBool[]
Definition: guc.c:803
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:4378
static int num_guc_variables
Definition: guc.c:3895
#define FATAL
Definition: elog.h:52
struct config_generic gen
Definition: guc_tables.h:178
struct config_generic gen
Definition: guc_tables.h:192
static struct config_generic ** guc_variables
Definition: guc.c:3892
enum config_type vartype
Definition: guc_tables.h:152
static int size_guc_variables
Definition: guc.c:3898
static struct config_real ConfigureNamesReal[]
Definition: guc.c:2852
struct config_generic gen
Definition: guc_tables.h:238
struct config_generic gen
Definition: guc_tables.h:224
#define free(a)
Definition: header.h:60
static struct config_string ConfigureNamesString[]
Definition: guc.c:3013
int i
#define qsort(a, b, c, d)
Definition: port.h:440
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:3933
struct config_generic gen
Definition: guc_tables.h:208
static bool call_bool_check_hook ( struct config_bool conf,
bool newval,
void **  extra,
GucSource  source,
int  elevel 
)
static

Definition at line 9739 of file guc.c.

References config_bool::check_hook, ereport, errcode(), errdetail_internal(), errhint(), errmsg(), errmsg_internal(), FlushErrorState(), config_bool::gen, GUC_check_errcode_value, GUC_check_errdetail_string, GUC_check_errhint_string, GUC_check_errmsg_string, config_generic::name, and NULL.

Referenced by InitializeOneGUCOption(), parse_and_validate_value(), and set_config_option().

9741 {
9742  /* Quick success if no hook */
9743  if (!conf->check_hook)
9744  return true;
9745 
9746  /* Reset variables that might be set by hook */
9747  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
9751 
9752  if (!(*conf->check_hook) (newval, extra, source))
9753  {
9754  ereport(elevel,
9758  errmsg("invalid value for parameter \"%s\": %d",
9759  conf->gen.name, (int) *newval),
9763  errhint("%s", GUC_check_errhint_string) : 0));
9764  /* Flush any strings created in ErrorContext */
9765  FlushErrorState();
9766  return false;
9767  }
9768 
9769  return true;
9770 }
char * GUC_check_errhint_string
Definition: guc.c:132
GucSource source
Definition: guc_tables.h:154
int errhint(const char *fmt,...)
Definition: elog.c:987
const char * name
Definition: guc_tables.h:145
int errcode(int sqlerrcode)
Definition: elog.c:575
static int GUC_check_errcode_value
Definition: guc.c:127
void FlushErrorState(void)
Definition: elog.c:1587
int errdetail_internal(const char *fmt,...)
Definition: elog.c:900
struct config_generic gen
Definition: guc_tables.h:178
char * GUC_check_errdetail_string
Definition: guc.c:131
#define ereport(elevel, rest)
Definition: elog.h:122
static int elevel
Definition: vacuumlazy.c:136
GucBoolCheckHook check_hook
Definition: guc_tables.h:182
int errmsg_internal(const char *fmt,...)
Definition: elog.c:827
#define NULL
Definition: c.h:226
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:130
int errmsg(const char *fmt,...)
Definition: elog.c:797
static bool call_enum_check_hook ( struct config_enum conf,
int *  newval,
void **  extra,
GucSource  source,
int  elevel 
)
static

Definition at line 9875 of file guc.c.

References config_enum::check_hook, config_enum_lookup_by_value(), ereport, errcode(), errdetail_internal(), errhint(), errmsg(), errmsg_internal(), FlushErrorState(), config_enum::gen, GUC_check_errcode_value, GUC_check_errdetail_string, GUC_check_errhint_string, GUC_check_errmsg_string, config_generic::name, and NULL.

Referenced by InitializeOneGUCOption(), parse_and_validate_value(), and set_config_option().

9877 {
9878  /* Quick success if no hook */
9879  if (!conf->check_hook)
9880  return true;
9881 
9882  /* Reset variables that might be set by hook */
9883  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
9887 
9888  if (!(*conf->check_hook) (newval, extra, source))
9889  {
9890  ereport(elevel,
9894  errmsg("invalid value for parameter \"%s\": \"%s\"",
9895  conf->gen.name,
9900  errhint("%s", GUC_check_errhint_string) : 0));
9901  /* Flush any strings created in ErrorContext */
9902  FlushErrorState();
9903  return false;
9904  }
9905 
9906  return true;
9907 }
char * GUC_check_errhint_string
Definition: guc.c:132
GucSource source
Definition: guc_tables.h:154
GucEnumCheckHook check_hook
Definition: guc_tables.h:243
int errhint(const char *fmt,...)
Definition: elog.c:987
const char * name
Definition: guc_tables.h:145
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
static int GUC_check_errcode_value
Definition: guc.c:127
void FlushErrorState(void)
Definition: elog.c:1587
int errdetail_internal(const char *fmt,...)
Definition: elog.c:900
char * GUC_check_errdetail_string
Definition: guc.c:131
#define ereport(elevel, rest)
Definition: elog.h:122
static int elevel
Definition: vacuumlazy.c:136
struct config_generic gen
Definition: guc_tables.h:238
int errmsg_internal(const char *fmt,...)
Definition: elog.c:827
#define NULL
Definition: c.h:226
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:130
int errmsg(const char *fmt,...)
Definition: elog.c:797
static bool call_int_check_hook ( struct config_int conf,
int *  newval,
void **  extra,
GucSource  source,
int  elevel 
)
static

Definition at line 9773 of file guc.c.

References config_int::check_hook, ereport, errcode(), errdetail_internal(), errhint(), errmsg(), errmsg_internal(), FlushErrorState(), config_int::gen, GUC_check_errcode_value, GUC_check_errdetail_string, GUC_check_errhint_string, GUC_check_errmsg_string, config_generic::name, and NULL.

Referenced by InitializeOneGUCOption(), parse_and_validate_value(), and set_config_option().

9775 {
9776  /* Quick success if no hook */
9777  if (!conf->check_hook)
9778  return true;
9779 
9780  /* Reset variables that might be set by hook */
9781  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
9785 
9786  if (!(*conf->check_hook) (newval, extra, source))
9787  {
9788  ereport(elevel,
9792  errmsg("invalid value for parameter \"%s\": %d",
9793  conf->gen.name, *newval),
9797  errhint("%s", GUC_check_errhint_string) : 0));
9798  /* Flush any strings created in ErrorContext */
9799  FlushErrorState();
9800  return false;
9801  }
9802 
9803  return true;
9804 }
char * GUC_check_errhint_string
Definition: guc.c:132
GucSource source
Definition: guc_tables.h:154
int errhint(const char *fmt,...)
Definition: elog.c:987
const char * name
Definition: guc_tables.h:145
int errcode(int sqlerrcode)
Definition: elog.c:575
static int GUC_check_errcode_value
Definition: guc.c:127
GucIntCheckHook check_hook
Definition: guc_tables.h:198
void FlushErrorState(void)
Definition: elog.c:1587
int errdetail_internal(const char *fmt,...)
Definition: elog.c:900
struct config_generic gen
Definition: guc_tables.h:192
char * GUC_check_errdetail_string
Definition: guc.c:131
#define ereport(elevel, rest)
Definition: elog.h:122
static int elevel
Definition: vacuumlazy.c:136
int errmsg_internal(const char *fmt,...)
Definition: elog.c:827
#define NULL
Definition: c.h:226
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:130
int errmsg(const char *fmt,...)
Definition: elog.c:797
static bool call_real_check_hook ( struct config_real conf,
double *  newval,
void **  extra,
GucSource  source,
int  elevel 
)
static

Definition at line 9807 of file guc.c.

References config_real::check_hook, ereport, errcode(), errdetail_internal(), errhint(), errmsg(), errmsg_internal(), FlushErrorState(), config_real::gen, GUC_check_errcode_value, GUC_check_errdetail_string, GUC_check_errhint_string, GUC_check_errmsg_string, config_generic::name, and NULL.

Referenced by InitializeOneGUCOption(), parse_and_validate_value(), and set_config_option().

9809 {
9810  /* Quick success if no hook */
9811  if (!conf->check_hook)
9812  return true;
9813 
9814  /* Reset variables that might be set by hook */
9815  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
9819 
9820  if (!(*conf->check_hook) (newval, extra, source))
9821  {
9822  ereport(elevel,
9826  errmsg("invalid value for parameter \"%s\": %g",
9827  conf->gen.name, *newval),
9831  errhint("%s", GUC_check_errhint_string) : 0));
9832  /* Flush any strings created in ErrorContext */
9833  FlushErrorState();
9834  return false;
9835  }
9836 
9837  return true;
9838 }
char * GUC_check_errhint_string
Definition: guc.c:132
GucSource source
Definition: guc_tables.h:154
int errhint(const char *fmt,...)
Definition: elog.c:987
const char * name
Definition: guc_tables.h:145
int errcode(int sqlerrcode)
Definition: elog.c:575
static int GUC_check_errcode_value
Definition: guc.c:127
GucRealCheckHook check_hook
Definition: guc_tables.h:214
void FlushErrorState(void)
Definition: elog.c:1587
int errdetail_internal(const char *fmt,...)
Definition: elog.c:900
char * GUC_check_errdetail_string
Definition: guc.c:131
#define ereport(elevel, rest)
Definition: elog.h:122
static int elevel
Definition: vacuumlazy.c:136
int errmsg_internal(const char *fmt,...)
Definition: elog.c:827
#define NULL
Definition: c.h:226
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:130
int errmsg(const char *fmt,...)
Definition: elog.c:797
struct config_generic gen
Definition: guc_tables.h:208
static bool call_string_check_hook ( struct config_string conf,
char **  newval,
void **  extra,
GucSource  source,
int  elevel 
)
static

Definition at line 9841 of file guc.c.

References config_string::check_hook, ereport, errcode(), errdetail_internal(), errhint(), errmsg(), errmsg_internal(), FlushErrorState(), config_string::gen, GUC_check_errcode_value, GUC_check_errdetail_string, GUC_check_errhint_string, GUC_check_errmsg_string, config_generic::name, and NULL.

Referenced by InitializeOneGUCOption(), parse_and_validate_value(), and set_config_option().

9843 {
9844  /* Quick success if no hook */
9845  if (!conf->check_hook)
9846  return true;
9847 
9848  /* Reset variables that might be set by hook */
9849  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
9853 
9854  if (!(*conf->check_hook) (newval, extra, source))
9855  {
9856  ereport(elevel,
9860  errmsg("invalid value for parameter \"%s\": \"%s\"",
9861  conf->gen.name, *newval ? *newval : ""),
9865  errhint("%s", GUC_check_errhint_string) : 0));
9866  /* Flush any strings created in ErrorContext */
9867  FlushErrorState();
9868  return false;
9869  }
9870 
9871  return true;
9872 }
char * GUC_check_errhint_string
Definition: guc.c:132
GucSource source
Definition: guc_tables.h:154
int errhint(const char *fmt,...)
Definition: elog.c:987
const char * name
Definition: guc_tables.h:145
GucStringCheckHook check_hook
Definition: guc_tables.h:228
int errcode(int sqlerrcode)
Definition: elog.c:575
static int GUC_check_errcode_value
Definition: guc.c:127
void FlushErrorState(void)
Definition: elog.c:1587
int errdetail_internal(const char *fmt,...)
Definition: elog.c:900
char * GUC_check_errdetail_string
Definition: guc.c:131
#define ereport(elevel, rest)
Definition: elog.h:122
static int elevel
Definition: vacuumlazy.c:136
struct config_generic gen
Definition: guc_tables.h:224
int errmsg_internal(const char *fmt,...)
Definition: elog.c:827
#define NULL
Definition: c.h:226
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:130
int errmsg(const char *fmt,...)
Definition: elog.c:797
static bool can_skip_gucvar ( struct config_generic gconf)
static

Definition at line 8933 of file guc.c.

References config_generic::context, PGC_INTERNAL, PGC_POSTMASTER, PGC_S_DEFAULT, and config_generic::source.

Referenced by estimate_variable_size(), RestoreGUCState(), and serialize_variable().

8934 {
8935  return gconf->context == PGC_POSTMASTER ||
8936  gconf->context == PGC_INTERNAL || gconf->source == PGC_S_DEFAULT;
8937 }
GucSource source
Definition: guc_tables.h:154
GucContext context
Definition: guc_tables.h:146
static bool check_application_name ( char **  newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10401 of file guc.c.

10402 {
10403  /* Only allow clean ASCII chars in the application name */
10404  char *p;
10405 
10406  for (p = *newval; *p; p++)
10407  {
10408  if (*p < 32 || *p > 126)
10409  *p = '?';
10410  }
10411 
10412  return true;
10413 }
#define newval
static bool check_autovacuum_max_workers ( int *  newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10303 of file guc.c.

References MAX_BACKENDS, max_worker_processes, and MaxConnections.

10304 {
10306  return false;
10307  return true;
10308 }
#define MAX_BACKENDS
Definition: postmaster.h:75
int MaxConnections
Definition: globals.c:123
#define newval
int max_worker_processes
Definition: globals.c:124
static bool check_autovacuum_work_mem ( int *  newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10311 of file guc.c.

10312 {
10313  /*
10314  * -1 indicates fallback.
10315  *
10316  * If we haven't yet changed the boot_val default of -1, just let it be.
10317  * Autovacuum will look to maintenance_work_mem instead.
10318  */
10319  if (*newval == -1)
10320  return true;
10321 
10322  /*
10323  * We clamp manually-set values to at least 1MB. Since
10324  * maintenance_work_mem is always set to at least this value, do the same
10325  * here.
10326  */
10327  if (*newval < 1024)
10328  *newval = 1024;
10329 
10330  return true;
10331 }
#define newval
static bool check_bonjour ( bool newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10103 of file guc.c.

References GUC_check_errmsg.

10104 {
10105 #ifndef USE_BONJOUR
10106  if (*newval)
10107  {
10108  GUC_check_errmsg("Bonjour is not supported by this build");
10109  return false;
10110  }
10111 #endif
10112  return true;
10113 }
#define GUC_check_errmsg
Definition: guc.h:403
#define newval
static bool check_canonical_path ( char **  newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10154 of file guc.c.

References canonicalize_path().

10155 {
10156  /*
10157  * Since canonicalize_path never enlarges the string, we can just modify
10158  * newval in-place. But watch out for NULL, which is the default value
10159  * for external_pid_file.
10160  */
10161  if (*newval)
10163  return true;
10164 }
void canonicalize_path(char *path)
Definition: path.c:254
#define newval
static bool check_cluster_name ( char **  newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10423 of file guc.c.

10424 {
10425  /* Only allow clean ASCII chars in the cluster name */
10426  char *p;
10427 
10428  for (p = *newval; *p; p++)
10429  {
10430  if (*p < 32 || *p > 126)
10431  *p = '?';
10432  }
10433 
10434  return true;
10435 }
#define newval
static bool check_effective_io_concurrency ( int *  newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10342 of file guc.c.

References ComputeIoConcurrency(), ERROR, guc_malloc(), and rint().

10343 {
10344 #ifdef USE_PREFETCH
10345  double new_prefetch_pages;
10346 
10347  if (ComputeIoConcurrency(*newval, &new_prefetch_pages))
10348  {
10349  int *myextra = (int *) guc_malloc(ERROR, sizeof(int));
10350 
10351  *myextra = (int) rint(new_prefetch_pages);
10352  *extra = (void *) myextra;
10353 
10354  return true;
10355  }
10356  else
10357  return false;
10358 #else
10359  return true;
10360 #endif /* USE_PREFETCH */
10361 }
bool ComputeIoConcurrency(int io_concurrency, double *target)
Definition: bufmgr.c:467
#define ERROR
Definition: elog.h:43
double rint(double x)
Definition: rint.c:22
#define newval
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:3933
static bool check_log_destination ( char **  newval,
void **  extra,
GucSource  source 
)
static

Definition at line 9995 of file guc.c.

References ERROR, GUC_check_errdetail, guc_malloc(), lfirst, list_free(), LOG_DESTINATION_CSVLOG, LOG_DESTINATION_EVENTLOG, LOG_DESTINATION_STDERR, LOG_DESTINATION_SYSLOG, pfree(), pg_strcasecmp(), pstrdup(), and SplitIdentifierString().

9996 {
9997  char *rawstring;
9998  List *elemlist;
9999  ListCell *l;
10000  int newlogdest = 0;
10001  int *myextra;
10002 
10003  /* Need a modifiable copy of string */
10004  rawstring = pstrdup(*newval);
10005 
10006  /* Parse string into list of identifiers */
10007  if (!SplitIdentifierString(rawstring, ',', &elemlist))
10008  {
10009  /* syntax error in list */
10010  GUC_check_errdetail("List syntax is invalid.");
10011  pfree(rawstring);
10012  list_free(elemlist);
10013  return false;
10014  }
10015 
10016  foreach(l, elemlist)
10017  {
10018  char *tok = (char *) lfirst(l);
10019 
10020  if (pg_strcasecmp(tok, "stderr") == 0)
10021  newlogdest |= LOG_DESTINATION_STDERR;
10022  else if (pg_strcasecmp(tok, "csvlog") == 0)
10023  newlogdest |= LOG_DESTINATION_CSVLOG;
10024 #ifdef HAVE_SYSLOG
10025  else if (pg_strcasecmp(tok, "syslog") == 0)
10026  newlogdest |= LOG_DESTINATION_SYSLOG;
10027 #endif
10028 #ifdef WIN32
10029  else if (pg_strcasecmp(tok, "eventlog") == 0)
10030  newlogdest |= LOG_DESTINATION_EVENTLOG;
10031 #endif
10032  else
10033  {
10034  GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
10035  pfree(rawstring);
10036  list_free(elemlist);
10037  return false;
10038  }
10039  }
10040 
10041  pfree(rawstring);
10042  list_free(elemlist);
10043 
10044  myextra = (int *) guc_malloc(ERROR, sizeof(int));
10045  *myextra = newlogdest;
10046  *extra = (void *) myextra;
10047 
10048  return true;
10049 }
#define LOG_DESTINATION_EVENTLOG
Definition: elog.h:397
#define GUC_check_errdetail
Definition: guc.h:407
char * pstrdup(const char *in)
Definition: mcxt.c:1165
#define LOG_DESTINATION_SYSLOG
Definition: elog.h:396
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
void pfree(void *pointer)
Definition: mcxt.c:992
#define ERROR
Definition: elog.h:43
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3129
#define LOG_DESTINATION_CSVLOG
Definition: elog.h:398
#define LOG_DESTINATION_STDERR
Definition: elog.h:395
#define lfirst(lc)
Definition: pg_list.h:106
#define newval
void list_free(List *list)
Definition: list.c:1133
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:3933
Definition: pg_list.h:45
static bool check_log_stats ( bool newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10140 of file guc.c.

References GUC_check_errdetail.

10141 {
10142  if (*newval &&
10144  {
10145  GUC_check_errdetail("Cannot enable \"log_statement_stats\" when "
10146  "\"log_parser_stats\", \"log_planner_stats\", "
10147  "or \"log_executor_stats\" is true.");
10148  return false;
10149  }
10150  return true;
10151 }
bool log_parser_stats
Definition: guc.c:440
#define GUC_check_errdetail
Definition: guc.h:407
#define newval
bool log_executor_stats
Definition: guc.c:442
bool log_planner_stats
Definition: guc.c:441
static bool check_max_worker_processes ( int *  newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10334 of file guc.c.

References autovacuum_max_workers, MAX_BACKENDS, and MaxConnections.

10335 {
10337  return false;
10338  return true;
10339 }
#define MAX_BACKENDS
Definition: postmaster.h:75
int MaxConnections
Definition: globals.c:123
int autovacuum_max_workers
Definition: autovacuum.c:112
#define newval
static bool check_maxconnections ( int *  newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10294 of file guc.c.

References autovacuum_max_workers, MAX_BACKENDS, and max_worker_processes.

10295 {
10296  if (*newval + autovacuum_max_workers + 1 +
10298  return false;
10299  return true;
10300 }
#define MAX_BACKENDS
Definition: postmaster.h:75
int autovacuum_max_workers
Definition: autovacuum.c:112
#define newval
int max_worker_processes
Definition: globals.c:124
static bool check_ssl ( bool newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10116 of file guc.c.

References GUC_check_errmsg.

10117 {
10118 #ifndef USE_SSL
10119  if (*newval)
10120  {
10121  GUC_check_errmsg("SSL is not supported by this build");
10122  return false;
10123  }
10124 #endif
10125  return true;
10126 }
#define GUC_check_errmsg
Definition: guc.h:403
#define newval
static bool check_stage_log_stats ( bool newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10129 of file guc.c.

References GUC_check_errdetail.

10130 {
10131  if (*newval && log_statement_stats)
10132  {
10133  GUC_check_errdetail("Cannot enable parameter when \"log_statement_stats\" is true.");
10134  return false;
10135  }
10136  return true;
10137 }
bool log_statement_stats
Definition: guc.c:443
#define GUC_check_errdetail
Definition: guc.h:407
#define newval
static bool check_temp_buffers ( int *  newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10089 of file guc.c.

References GUC_check_errdetail, and NLocBuffer.

10090 {
10091  /*
10092  * Once local buffers have been initialized, it's too late to change this.
10093  */
10094  if (NLocBuffer && NLocBuffer != *newval)
10095  {
10096  GUC_check_errdetail("\"temp_buffers\" cannot be changed after any temporary tables have been accessed in the session.");
10097  return false;
10098  }
10099  return true;
10100 }
#define GUC_check_errdetail
Definition: guc.h:407
int NLocBuffer
Definition: localbuf.c:41
#define newval
static bool check_timezone_abbreviations ( char **  newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10167 of file guc.c.

References Assert, load_tzoffsets(), NULL, and PGC_S_DEFAULT.

10168 {
10169  /*
10170  * The boot_val given above for timezone_abbreviations is NULL. When we
10171  * see this we just do nothing. If this value isn't overridden from the
10172  * config file then pg_timezone_abbrev_initialize() will eventually
10173  * replace it with "Default". This hack has two purposes: to avoid
10174  * wasting cycles loading values that might soon be overridden from the
10175  * config file, and to avoid trying to read the timezone abbrev files
10176  * during InitializeGUCOptions(). The latter doesn't work in an
10177  * EXEC_BACKEND subprocess because my_exec_path hasn't been set yet and so
10178  * we can't locate PGSHAREDIR.
10179  */
10180  if (*newval == NULL)
10181  {
10183  return true;
10184  }
10185 
10186  /* OK, load the file and produce a malloc'd TimeZoneAbbrevTable */
10188 
10189  /* tzparser.c returns NULL on failure, reporting via GUC_check_errmsg */
10190  if (!*extra)
10191  return false;
10192 
10193  return true;
10194 }
GucSource source
Definition: guc_tables.h:154
TimeZoneAbbrevTable * load_tzoffsets(const char *filename)
Definition: tzparser.c:438
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
#define newval
static bool check_wal_consistency_checking ( char **  newval,
void **  extra,
GucSource  source 
)
static

Definition at line 9915 of file guc.c.

References ERROR, GUC_check_errdetail, guc_malloc(), lfirst, list_free(), MemSet, NULL, pfree(), pg_strcasecmp(), pstrdup(), RmgrData::rm_mask, RM_MAX_ID, RmgrTable, and SplitIdentifierString().

9916 {
9917  char *rawstring;
9918  List *elemlist;
9919  ListCell *l;
9920  bool newwalconsistency[RM_MAX_ID + 1];
9921 
9922  /* Initialize the array */
9923  MemSet(newwalconsistency, 0, (RM_MAX_ID + 1) * sizeof(bool));
9924 
9925  /* Need a modifiable copy of string */
9926  rawstring = pstrdup(*newval);
9927 
9928  /* Parse string into list of identifiers */
9929  if (!SplitIdentifierString(rawstring, ',', &elemlist))
9930  {
9931  /* syntax error in list */
9932  GUC_check_errdetail("List syntax is invalid.");
9933  pfree(rawstring);
9934  list_free(elemlist);
9935  return false;
9936  }
9937 
9938  foreach(l, elemlist)
9939  {
9940  char *tok = (char *) lfirst(l);
9941  bool found = false;
9942  RmgrId rmid;
9943 
9944  /* Check for 'all'. */
9945  if (pg_strcasecmp(tok, "all") == 0)
9946  {
9947  for (rmid = 0; rmid <= RM_MAX_ID; rmid++)
9948  if (RmgrTable[rmid].rm_mask != NULL)
9949  newwalconsistency[rmid] = true;
9950  found = true;
9951  }
9952  else
9953  {
9954  /*
9955  * Check if the token matches with any individual resource
9956  * manager.
9957  */
9958  for (rmid = 0; rmid <= RM_MAX_ID; rmid++)
9959  {
9960  if (pg_strcasecmp(tok, RmgrTable[rmid].rm_name) == 0 &&
9961  RmgrTable[rmid].rm_mask != NULL)
9962  {
9963  newwalconsistency[rmid] = true;
9964  found = true;
9965  }
9966  }
9967  }
9968 
9969  /* If a valid resource manager is found, check for the next one. */
9970  if (!found)
9971  {
9972  GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
9973  pfree(rawstring);
9974  list_free(elemlist);
9975  return false;
9976  }
9977  }
9978 
9979  pfree(rawstring);
9980  list_free(elemlist);
9981 
9982  /* assign new value */
9983  *extra = guc_malloc(ERROR, (RM_MAX_ID + 1) * sizeof(bool));
9984  memcpy(*extra, newwalconsistency, (RM_MAX_ID + 1) * sizeof(bool));
9985  return true;
9986 }
void(* rm_mask)(char *pagedata, BlockNumber blkno)
#define GUC_check_errdetail
Definition: guc.h:407
char * pstrdup(const char *in)
Definition: mcxt.c:1165
const RmgrData RmgrTable[RM_MAX_ID+1]
Definition: rmgr.c:36
#define MemSet(start, val, len)
Definition: c.h:853
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
void pfree(void *pointer)
Definition: mcxt.c:992
#define ERROR
Definition: elog.h:43
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3129
#define RM_MAX_ID
Definition: rmgr.h:33
uint8 RmgrId
Definition: rmgr.h:11
#define NULL
Definition: c.h:226
#define lfirst(lc)
Definition: pg_list.h:106
#define newval
void list_free(List *list)
Definition: list.c:1133
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:3933
Definition: pg_list.h:45
static char* config_enum_get_options ( struct config_enum record,
const char *  prefix,
const char *  suffix,
const char *  separator 
)
static

Definition at line 5623 of file guc.c.

References appendBinaryStringInfo(), appendStringInfoString(), StringInfoData::data, config_enum_entry::hidden, initStringInfo(), StringInfoData::len, config_enum_entry::name, and config_enum::options.

Referenced by GetConfigOptionByNum(), and parse_and_validate_value().

5625 {
5626  const struct config_enum_entry *entry;
5627  StringInfoData retstr;
5628  int seplen;
5629 
5630  initStringInfo(&retstr);
5631  appendStringInfoString(&retstr, prefix);
5632 
5633  seplen = strlen(separator);
5634  for (entry = record->options; entry && entry->name; entry++)
5635  {
5636  if (!entry->hidden)
5637  {
5638  appendStringInfoString(&retstr, entry->name);
5639  appendBinaryStringInfo(&retstr, separator, seplen);
5640  }
5641  }
5642 
5643  /*
5644  * All the entries may have been hidden, leaving the string empty if no
5645  * prefix was given. This indicates a broken GUC setup, since there is no
5646  * use for an enum without any values, so we just check to make sure we
5647  * don't write to invalid memory instead of actually trying to do
5648  * something smart with it.
5649  */
5650  if (retstr.len >= seplen)
5651  {
5652  /* Replace final separator */
5653  retstr.data[retstr.len - seplen] = '\0';
5654  retstr.len -= seplen;
5655  }
5656 
5657  appendStringInfoString(&retstr, suffix);
5658 
5659  return retstr.data;
5660 }
Definition: guc.h:164
const struct config_enum_entry * options
Definition: guc_tables.h:242
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:189
void initStringInfo(StringInfo str)
Definition: stringinfo.c:65
const char * name
Definition: guc.h:166
void appendBinaryStringInfo(StringInfo str, const char *data, int datalen)
Definition: stringinfo.c:240
bool hidden
Definition: guc.h:168
bool config_enum_lookup_by_name ( struct config_enum record,
const char *  value,
int *  retval 
)

Definition at line 5597 of file guc.c.

References FALSE, config_enum_entry::name, config_enum::options, pg_strcasecmp(), TRUE, and config_enum_entry::val.

Referenced by parse_and_validate_value().

5599 {
5600  const struct config_enum_entry *entry;
5601 
5602  for (entry = record->options; entry && entry->name; entry++)
5603  {
5604  if (pg_strcasecmp(value, entry->name) == 0)
5605  {
5606  *retval = entry->val;
5607  return TRUE;
5608  }
5609  }
5610 
5611  *retval = 0;
5612  return FALSE;
5613 }
static struct @76 value
Definition: guc.h:164
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
#define FALSE
Definition: c.h:218
const struct config_enum_entry * options
Definition: guc_tables.h:242
int val
Definition: guc.h:167
const char * name
Definition: guc.h:166
#define TRUE
Definition: c.h:214
const char* config_enum_lookup_by_value ( struct config_enum record,
int  val 
)

Definition at line 5574 of file guc.c.

References elog, ERROR, config_enum::gen, config_generic::name, config_enum_entry::name, NULL, config_enum::options, and config_enum_entry::val.

Referenced by _ShowOption(), call_enum_check_hook(), estimate_variable_size(), GetConfigOption(), GetConfigOptionByNum(), GetConfigOptionResetString(), printMixedStruct(), and serialize_variable().

5575 {
5576  const struct config_enum_entry *entry;
5577 
5578  for (entry = record->options; entry && entry->name; entry++)
5579  {
5580  if (entry->val == val)
5581  return entry->name;
5582  }
5583 
5584  elog(ERROR, "could not find enum option %d for %s",
5585  val, record->gen.name);
5586  return NULL; /* silence compiler */
5587 }
Definition: guc.h:164
const char * name
Definition: guc_tables.h:145
#define ERROR
Definition: elog.h:43
const struct config_enum_entry * options
Definition: guc_tables.h:242
int val
Definition: guc.h:167
struct config_generic gen
Definition: guc_tables.h:238
#define NULL
Definition: c.h:226
const char * name
Definition: guc.h:166
#define elog
Definition: elog.h:219
long val
Definition: informix.c:689
static void convert_from_base_unit ( int64  base_value,
int  base_unit,
int64 *  value,
const char **  unit 
)
static

Definition at line 5402 of file guc.c.

References Assert, GUC_UNIT_MEMORY, i, memory_unit_conversion_table, unit_conversion::multiplier, NULL, time_unit_conversion_table, and unit_conversion::unit.

Referenced by _ShowOption().

5404 {
5405  const unit_conversion *table;
5406  int i;
5407 
5408  *unit = NULL;
5409 
5410  if (base_unit & GUC_UNIT_MEMORY)
5412  else
5414 
5415  for (i = 0; *table[i].unit; i++)
5416  {
5417  if (base_unit == table[i].base_unit)
5418  {
5419  /*
5420  * Accept the first conversion that divides the value evenly. We
5421  * assume that the conversions for each base unit are ordered from
5422  * greatest unit to the smallest!
5423  */
5424  if (table[i].multiplier < 0)
5425  {
5426  *value = base_value * (-table[i].multiplier);
5427  *unit = table[i].unit;
5428  break;
5429  }
5430  else if (base_value % table[i].multiplier == 0)
5431  {
5432  *value = base_value / table[i].multiplier;
5433  *unit = table[i].unit;
5434  break;
5435  }
5436  }
5437  }
5438 
5439  Assert(*unit != NULL);
5440 }
static struct @76 value
static const unit_conversion time_unit_conversion_table[]
Definition: guc.c:750
static const unit_conversion memory_unit_conversion_table[]
Definition: guc.c:723
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
int i
char unit[MAX_UNIT_LEN+1]
Definition: guc.c:702
#define GUC_UNIT_MEMORY
Definition: guc.h:222
int multiplier
Definition: guc.c:705
static bool convert_to_base_unit ( int64  value,
const char *  unit,
int  base_unit,
int64 *  base_value 
)
static

Definition at line 5369 of file guc.c.

References GUC_UNIT_MEMORY, i, memory_unit_conversion_table, unit_conversion::multiplier, time_unit_conversion_table, and unit_conversion::unit.

Referenced by parse_int().

5371 {
5372  const unit_conversion *table;
5373  int i;
5374 
5375  if (base_unit & GUC_UNIT_MEMORY)
5377  else
5379 
5380  for (i = 0; *table[i].unit; i++)
5381  {
5382  if (base_unit == table[i].base_unit &&
5383  strcmp(unit, table[i].unit) == 0)
5384  {
5385  if (table[i].multiplier < 0)
5386  *base_value = value / (-table[i].multiplier);
5387  else
5388  *base_value = value * table[i].multiplier;
5389  return true;
5390  }
5391  }
5392  return false;
5393 }
static struct @76 value
static const unit_conversion time_unit_conversion_table[]
Definition: guc.c:750
static const unit_conversion memory_unit_conversion_table[]
Definition: guc.c:723
int i
char unit[MAX_UNIT_LEN+1]
Definition: guc.c:702
#define GUC_UNIT_MEMORY
Definition: guc.h:222
int multiplier
Definition: guc.c:705
static void define_custom_variable ( struct config_generic variable)
static

Definition at line 7502 of file guc.c.

References add_guc_variable(), Assert, ereport, errcode(), errmsg(), ERROR, free, config_string::gen, GUC_ACTION_SET, GUC_CUSTOM_PLACEHOLDER, guc_var_compare(), InitializeOneGUCOption(), config_generic::name, name, NULL, PGC_STRING, reapply_stacked_values(), config_generic::reset_scontext, config_generic::reset_source, config_string::reset_val, config_generic::scontext, set_config_option(), set_config_sourcefile(), set_string_field(), config_generic::source, config_generic::sourcefile, config_generic::sourceline, config_generic::stack, config_string::variable, and WARNING.

Referenced by DefineCustomBoolVariable(), DefineCustomEnumVariable(), DefineCustomIntVariable(), DefineCustomRealVariable(), and DefineCustomStringVariable().

7503 {
7504  const char *name = variable->name;
7505  const char **nameAddr = &name;
7506  struct config_string *pHolder;
7507  struct config_generic **res;
7508 
7509  /*
7510  * See if there's a placeholder by the same name.
7511  */
7512  res = (struct config_generic **) bsearch((void *) &nameAddr,
7513  (void *) guc_variables,
7515  sizeof(struct config_generic *),
7516  guc_var_compare);
7517  if (res == NULL)
7518  {
7519  /*
7520  * No placeholder to replace, so we can just add it ... but first,
7521  * make sure it's initialized to its default value.
7522  */
7523  InitializeOneGUCOption(variable);
7524  add_guc_variable(variable, ERROR);
7525  return;
7526  }
7527 
7528  /*
7529  * This better be a placeholder
7530  */
7531  if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
7532  ereport(ERROR,
7533  (errcode(ERRCODE_INTERNAL_ERROR),
7534  errmsg("attempt to redefine parameter \"%s\"", name)));
7535 
7536  Assert((*res)->vartype == PGC_STRING);
7537  pHolder = (struct config_string *) (*res);
7538 
7539  /*
7540  * First, set the variable to its default value. We must do this even
7541  * though we intend to immediately apply a new value, since it's possible
7542  * that the new value is invalid.
7543  */
7544  InitializeOneGUCOption(variable);
7545 
7546  /*
7547  * Replace the placeholder. We aren't changing the name, so no re-sorting
7548  * is necessary
7549  */
7550  *res = variable;
7551 
7552  /*
7553  * Assign the string value(s) stored in the placeholder to the real
7554  * variable. Essentially, we need to duplicate all the active and stacked
7555  * values, but with appropriate validation and datatype adjustment.
7556  *
7557  * If an assignment fails, we report a WARNING and keep going. We don't
7558  * want to throw ERROR for bad values, because it'd bollix the add-on
7559  * module that's presumably halfway through getting loaded. In such cases
7560  * the default or previous state will become active instead.
7561  */
7562 
7563  /* First, apply the reset value if any */
7564  if (pHolder->reset_val)
7565  (void) set_config_option(name, pHolder->reset_val,
7566  pHolder->gen.reset_scontext,
7567  pHolder->gen.reset_source,
7568  GUC_ACTION_SET, true, WARNING, false);
7569  /* That should not have resulted in stacking anything */
7570  Assert(variable->stack == NULL);
7571 
7572  /* Now, apply current and stacked values, in the order they were stacked */
7573  reapply_stacked_values(variable, pHolder, pHolder->gen.stack,
7574  *(pHolder->variable),
7575  pHolder->gen.scontext, pHolder->gen.source);
7576 
7577  /* Also copy over any saved source-location information */
7578  if (pHolder->gen.sourcefile)
7579  set_config_sourcefile(name, pHolder->gen.sourcefile,
7580  pHolder->gen.sourceline);
7581 
7582  /*
7583  * Free up as much as we conveniently can of the placeholder structure.
7584  * (This neglects any stack items, so it's possible for some memory to be
7585  * leaked. Since this can only happen once per session per variable, it
7586  * doesn't seem worth spending much code on.)
7587  */
7588  set_string_field(pHolder, pHolder->variable, NULL);
7589  set_string_field(pHolder, &pHolder->reset_val, NULL);
7590 
7591  free(pHolder);
7592 }
GucSource source
Definition: guc_tables.h:154
static void static void set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
Definition: guc.c:6595
char ** variable
Definition: guc_tables.h:226
const char * name
Definition: guc_tables.h:145
static void reapply_stacked_values(struct config_generic *variable, struct config_string *pHolder, GucStack *stack, const char *curvalue, GucContext curscontext, GucSource cursource)
Definition: guc.c:7602
int errcode(int sqlerrcode)
Definition: elog.c:575
GucContext scontext
Definition: guc_tables.h:156
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:4378
#define ERROR
Definition: elog.h:43
static int num_guc_variables
Definition: guc.c:3895
char * sourcefile
Definition: guc_tables.h:160
GucSource reset_source
Definition: guc_tables.h:155
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:4526
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4005
#define ereport(elevel, rest)
Definition: elog.h:122
static struct config_generic ** guc_variables
Definition: guc.c:3892
#define WARNING
Definition: elog.h:40
struct config_generic gen
Definition: guc_tables.h:224
#define free(a)
Definition: header.h:60
char * reset_val
Definition: guc_tables.h:232
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
#define GUC_CUSTOM_PLACEHOLDER
Definition: guc.h:211
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797
GucStack * stack
Definition: guc_tables.h:158
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
static bool add_guc_variable(struct config_generic *var, int elevel)
Definition: guc.c:4243
GucContext reset_scontext
Definition: guc_tables.h:157
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
static void discard_stack_value ( struct config_generic gconf,
config_var_value val 
)
static

Definition at line 4120 of file guc.c.

References config_var_value::extra, NULL, PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_STRING, set_extra_field(), set_string_field(), config_var_val::stringval, config_var_value::val, and config_generic::vartype.

Referenced by AtEOXact_GUC(), and push_old_value().

4121 {
4122  switch (gconf->vartype)
4123  {
4124  case PGC_BOOL:
4125  case PGC_INT:
4126  case PGC_REAL:
4127  case PGC_ENUM:
4128  /* no need to do anything */
4129  break;
4130  case PGC_STRING:
4131  set_string_field((struct config_string *) gconf,
4132  &(val->val.stringval),
4133  NULL);
4134  break;
4135  }
4136  set_extra_field(gconf, &(val->extra), NULL);
4137 }
union config_var_val val
Definition: guc_tables.h:46
static void set_extra_field(struct config_generic *gconf, void **field, void *newval)
Definition: guc.c:4066
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4005
enum config_type vartype
Definition: guc_tables.h:152
#define NULL
Definition: c.h:226
char * stringval
Definition: guc_tables.h:36
static void do_serialize ( char **  destptr,
Size maxbytes,
const char *  fmt,
  ... 
)
static

Definition at line 9067 of file guc.c.

References elog, ERROR, and vsnprintf().

Referenced by serialize_variable().

9068 {
9069  va_list vargs;
9070  int n;
9071 
9072  if (*maxbytes <= 0)
9073  elog(ERROR, "not enough space to serialize GUC state");
9074 
9075  va_start(vargs, fmt);
9076  n = vsnprintf(*destptr, *maxbytes, fmt, vargs);
9077  va_end(vargs);
9078 
9079  /*
9080  * Cater to portability hazards in the vsnprintf() return value just like
9081  * appendPQExpBufferVA() does. Note that this requires an extra byte of
9082  * slack at the end of the buffer. Since serialize_variable() ends with a
9083  * do_serialize_binary() rather than a do_serialize(), we'll always have
9084  * that slack; estimate_variable_size() need not add a byte for it.
9085  */
9086  if (n < 0 || n >= *maxbytes - 1)
9087  {
9088  if (n < 0 && errno != 0 && errno != ENOMEM)
9089  /* Shouldn't happen. Better show errno description. */
9090  elog(ERROR, "vsnprintf failed: %m");
9091  else
9092  elog(ERROR, "not enough space to serialize GUC state");
9093  }
9094 
9095  /* Shift the destptr ahead of the null terminator */
9096  *destptr += n + 1;
9097  *maxbytes -= n + 1;
9098 }
int int vsnprintf(char *str, size_t count, const char *fmt, va_list args)
#define ERROR
Definition: elog.h:43
#define elog
Definition: elog.h:219
static void do_serialize_binary ( char **  destptr,
Size maxbytes,
void *  val,
Size  valsize 
)
static

Definition at line 9102 of file guc.c.

References elog, and ERROR.

Referenced by serialize_variable().

9103 {
9104  if (valsize > *maxbytes)
9105  elog(ERROR, "not enough space to serialize GUC state");
9106 
9107  memcpy(*destptr, val, valsize);
9108  *destptr += valsize;
9109  *maxbytes -= valsize;
9110 }
#define ERROR
Definition: elog.h:43
#define elog
Definition: elog.h:219
long val
Definition: informix.c:689
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
static Size estimate_variable_size ( struct config_generic gconf)
static

Definition at line 8946 of file guc.c.

References Abs, add_size(), can_skip_gucvar(), config_enum_lookup_by_value(), config_generic::name, PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_STRING, REALTYPE_PRECISION, config_generic::scontext, config_generic::source, config_generic::sourcefile, config_generic::sourceline, config_int::variable, config_string::variable, config_enum::variable, and config_generic::vartype.

Referenced by EstimateGUCStateSpace().

8947 {
8948  Size size;
8949  Size valsize = 0;
8950 
8951  if (can_skip_gucvar(gconf))
8952  return 0;
8953 
8954  /* Name, plus trailing zero byte. */
8955  size = strlen(gconf->name) + 1;
8956 
8957  /* Get the maximum display length of the GUC value. */
8958  switch (gconf->vartype)
8959  {
8960  case PGC_BOOL:
8961  {
8962  valsize = 5; /* max(strlen('true'), strlen('false')) */
8963  }
8964  break;
8965 
8966  case PGC_INT:
8967  {
8968  struct config_int *conf = (struct config_int *) gconf;
8969 
8970  /*
8971  * Instead of getting the exact display length, use max
8972  * length. Also reduce the max length for typical ranges of
8973  * small values. Maximum value is 2147483647, i.e. 10 chars.
8974  * Include one byte for sign.
8975  */
8976  if (Abs(*conf->variable) < 1000)
8977  valsize = 3 + 1;
8978  else
8979  valsize = 10 + 1;
8980  }
8981  break;
8982 
8983  case PGC_REAL:
8984  {
8985  /*
8986  * We are going to print it with %e with REALTYPE_PRECISION
8987  * fractional digits. Account for sign, leading digit,
8988  * decimal point, and exponent with up to 3 digits. E.g.
8989  * -3.99329042340000021e+110
8990  */
8991  valsize = 1 + 1 + 1 + REALTYPE_PRECISION + 5;
8992  }
8993  break;
8994 
8995  case PGC_STRING:
8996  {
8997  struct config_string *conf = (struct config_string *) gconf;
8998 
8999  /*
9000  * If the value is NULL, we transmit it as an empty string.
9001  * Although this is not physically the same value, GUC
9002  * generally treats a NULL the same as empty string.
9003  */
9004  if (*conf->variable)
9005  valsize = strlen(*conf->variable);
9006  else
9007  valsize = 0;
9008  }
9009  break;
9010 
9011  case PGC_ENUM:
9012  {
9013  struct config_enum *conf = (struct config_enum *) gconf;
9014 
9015  valsize = strlen(config_enum_lookup_by_value(conf, *conf->variable));
9016  }
9017  break;
9018  }
9019 
9020  /* Allow space for terminating zero-byte for value */
9021  size = add_size(size, valsize + 1);
9022 
9023  if (gconf->sourcefile)
9024  size = add_size(size, strlen(gconf->sourcefile));
9025 
9026  /* Allow space for terminating zero-byte for sourcefile */
9027  size = add_size(size, 1);
9028 
9029  /* Include line whenever file is nonempty. */
9030  if (gconf->sourcefile && gconf->sourcefile[0])
9031  size = add_size(size, sizeof(gconf->sourceline));
9032 
9033  size = add_size(size, sizeof(gconf->source));
9034  size = add_size(size, sizeof(gconf->scontext));
9035 
9036  return size;
9037 }
GucSource source
Definition: guc_tables.h:154
char ** variable
Definition: guc_tables.h:226
const char * name
Definition: guc_tables.h:145
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5574
GucContext scontext
Definition: guc_tables.h:156
#define Abs(x)
Definition: c.h:808
int * variable
Definition: guc_tables.h:194
int * variable
Definition: guc_tables.h:240
char * sourcefile
Definition: guc_tables.h:160
static bool can_skip_gucvar(struct config_generic *gconf)
Definition: guc.c:8933
#define REALTYPE_PRECISION
Definition: guc.c:109
enum config_type vartype
Definition: guc_tables.h:152
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
size_t Size
Definition: c.h:353
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
static bool extra_field_used ( struct config_generic gconf,
void *  extra 
)
static

Definition at line 4021 of file guc.c.

References config_var_value::extra, config_generic::extra, guc_stack::masked, PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_STRING, guc_stack::prev, guc_stack::prior, config_generic::stack, and config_generic::vartype.

Referenced by set_config_option(), and set_extra_field().

4022 {
4023  GucStack *stack;
4024 
4025  if (extra == gconf->extra)
4026  return true;
4027  switch (gconf->vartype)
4028  {
4029  case PGC_BOOL:
4030  if (extra == ((struct config_bool *) gconf)->reset_extra)
4031  return true;
4032  break;
4033  case PGC_INT:
4034  if (extra == ((struct config_int *) gconf)->reset_extra)
4035  return true;
4036  break;
4037  case PGC_REAL:
4038  if (extra == ((struct config_real *) gconf)->reset_extra)
4039  return true;
4040  break;
4041  case PGC_STRING:
4042  if (extra == ((struct config_string *) gconf)->reset_extra)
4043  return true;
4044  break;
4045  case PGC_ENUM:
4046  if (extra == ((struct config_enum *) gconf)->reset_extra)
4047  return true;
4048  break;
4049  }
4050  for (stack = gconf->stack; stack; stack = stack->prev)
4051  {
4052  if (extra == stack->prior.extra ||
4053  extra == stack->masked.extra)
4054  return true;
4055  }
4056 
4057  return false;
4058 }
struct guc_stack * prev
Definition: guc_tables.h:119
config_var_value masked
Definition: guc_tables.h:127
void * reset_extra
Definition: guc_tables.h:248
enum config_type vartype
Definition: guc_tables.h:152
GucStack * stack
Definition: guc_tables.h:158
config_var_value prior
Definition: guc_tables.h:126
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
static struct config_generic* find_option ( const char *  name,
bool  create_placeholders,
int  elevel 
)
static

Definition at line 4329 of file guc.c.

References add_placeholder_variable(), Assert, guc_name_compare(), GUC_QUALIFIER_SEPARATOR, guc_var_compare(), i, name, and NULL.

Referenced by AlterSystemSetConfigFile(), flatten_set_variable_args(), GetConfigOption(), GetConfigOptionByName(), GetConfigOptionResetString(), GUCArrayAdd(), GUCArrayDelete(), set_config_option(), set_config_sourcefile(), and validate_option_array_item().

4330 {
4331  const char **key = &name;
4332  struct config_generic **res;
4333  int i;
4334 
4335  Assert(name);
4336 
4337  /*
4338  * By equating const char ** with struct config_generic *, we are assuming
4339  * the name field is first in config_generic.
4340  */
4341  res = (struct config_generic **) bsearch((void *) &key,
4342  (void *) guc_variables,
4344  sizeof(struct config_generic *),
4345  guc_var_compare);
4346  if (res)
4347  return *res;
4348 
4349  /*
4350  * See if the name is an obsolete name for a variable. We assume that the
4351  * set of supported old names is short enough that a brute-force search is
4352  * the best way.
4353  */
4354  for (i = 0; map_old_guc_names[i] != NULL; i += 2)
4355  {
4356  if (guc_name_compare(name, map_old_guc_names[i]) == 0)
4357  return find_option(map_old_guc_names[i + 1], false, elevel);
4358  }
4359 
4360  if (create_placeholders)
4361  {
4362  /*
4363  * Check if the name is qualified, and if so, add a placeholder.
4364  */
4365  if (strchr(name, GUC_QUALIFIER_SEPARATOR) != NULL)
4367  }
4368 
4369  /* Unknown name */
4370  return NULL;
4371 }
#define GUC_QUALIFIER_SEPARATOR
Definition: guc.h:199
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:4390
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:4378
static int num_guc_variables
Definition: guc.c:3895
static struct config_generic ** guc_variables
Definition: guc.c:3892
static int elevel
Definition: vacuumlazy.c:136
static const char *const map_old_guc_names[]
Definition: guc.c:3882
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
static struct config_generic * add_placeholder_variable(const char *name, int elevel)
Definition: guc.c:4281
int i
static char* flatten_set_variable_args ( const char *  name,
List args 
)
static

Definition at line 6761 of file guc.c.

References appendStringInfo(), appendStringInfoString(), arg, TypeCast::arg, Assert, buf, CStringGetDatum, StringInfoData::data, DatumGetCString, DirectFunctionCall1, DirectFunctionCall3, elog, ereport, errcode(), errmsg(), ERROR, find_option(), config_generic::flags, GUC_LIST_INPUT, GUC_LIST_QUOTE, initStringInfo(), Int32GetDatum, interval_in(), interval_out(), INTERVALOID, intVal, InvalidOid, IsA, lfirst, list_head(), list_length(), NIL, nodeTag, NULL, ObjectIdGetDatum, quote_identifier(), strVal, T_Float, T_Integer, T_String, TypeCast::typeName, typenameTypeIdAndMod(), A_Const::val, val, and WARNING.

Referenced by ExtractSetVariableArgs(), and SetPGVariable().

6762 {
6763  struct config_generic *record;
6764  int flags;
6766  ListCell *l;
6767 
6768  /* Fast path if just DEFAULT */
6769  if (args == NIL)
6770  return NULL;
6771 
6772  /*
6773  * Get flags for the variable; if it's not known, use default flags.
6774  * (Caller might throw error later, but not our business to do so here.)
6775  */
6776  record = find_option(name, false, WARNING);
6777  if (record)
6778  flags = record->flags;
6779  else
6780  flags = 0;
6781 
6782  /* Complain if list input and non-list variable */
6783  if ((flags & GUC_LIST_INPUT) == 0 &&
6784  list_length(args) != 1)
6785  ereport(ERROR,
6786  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6787  errmsg("SET %s takes only one argument", name)));
6788 
6789  initStringInfo(&buf);
6790 
6791  /*
6792  * Each list member may be a plain A_Const node, or an A_Const within a
6793  * TypeCast; the latter case is supported only for ConstInterval arguments
6794  * (for SET TIME ZONE).
6795  */
6796  foreach(l, args)
6797  {
6798  Node *arg = (Node *) lfirst(l);
6799  char *val;
6800  TypeName *typeName = NULL;
6801  A_Const *con;
6802 
6803  if (l != list_head(args))
6804  appendStringInfoString(&buf, ", ");
6805 
6806  if (IsA(arg, TypeCast))
6807  {
6808  TypeCast *tc = (TypeCast *) arg;
6809 
6810  arg = tc->arg;
6811  typeName = tc->typeName;
6812  }
6813 
6814  if (!IsA(arg, A_Const))
6815  elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
6816  con = (A_Const *) arg;
6817 
6818  switch (nodeTag(&con->val))
6819  {
6820  case T_Integer:
6821  appendStringInfo(&buf, "%ld", intVal(&con->val));
6822  break;
6823  case T_Float:
6824  /* represented as a string, so just copy it */
6825  appendStringInfoString(&buf, strVal(&con->val));
6826  break;
6827  case T_String:
6828  val = strVal(&con->val);
6829  if (typeName != NULL)
6830  {
6831  /*
6832  * Must be a ConstInterval argument for TIME ZONE. Coerce
6833  * to interval and back to normalize the value and account
6834  * for any typmod.
6835  */
6836  Oid typoid;
6837  int32 typmod;
6838  Datum interval;
6839  char *intervalout;
6840 
6841  typenameTypeIdAndMod(NULL, typeName, &typoid, &typmod);
6842  Assert(typoid == INTERVALOID);
6843 
6844  interval =
6846  CStringGetDatum(val),
6848  Int32GetDatum(typmod));
6849 
6850  intervalout =
6852  interval));
6853  appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
6854  }
6855  else
6856  {
6857  /*
6858  * Plain string literal or identifier. For quote mode,
6859  * quote it if it's not a vanilla identifier.
6860  */
6861  if (flags & GUC_LIST_QUOTE)
6863  else
6864  appendStringInfoString(&buf, val);
6865  }
6866  break;
6867  default:
6868  elog(ERROR, "unrecognized node type: %d",
6869  (int) nodeTag(&con->val));
6870  break;
6871  }
6872  }
6873 
6874  return buf.data;
6875 }
#define NIL
Definition: pg_list.h:69
#define IsA(nodeptr, _type_)
Definition: nodes.h:559
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:9968
Datum interval_in(PG_FUNCTION_ARGS)
Definition: timestamp.c:875
#define GUC_LIST_QUOTE
Definition: guc.h:205
Definition: nodes.h:508
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:575
Datum interval_out(PG_FUNCTION_ARGS)
Definition: timestamp.c:957
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:555
unsigned int Oid
Definition: postgres_ext.h:31
signed int int32
Definition: c.h:253
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:110
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#define ERROR
Definition: elog.h:43
#define DatumGetCString(X)
Definition: postgres.h:574
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:189
static char * buf
Definition: pg_test_fsync.c:65
#define CStringGetDatum(X)
Definition: postgres.h:586
#define INTERVALOID
Definition: pg_type.h:517
static ListCell * list_head(const List *l)
Definition: pg_list.h:77
#define ereport(elevel, rest)
Definition: elog.h:122
#define DirectFunctionCall3(func, arg1, arg2, arg3)
Definition: fmgr.h:559
void initStringInfo(StringInfo str)
Definition: stringinfo.c:65
#define WARNING
Definition: elog.h:40
uintptr_t Datum
Definition: postgres.h:374
TypeName * typeName
Definition: parsenodes.h:290
void typenameTypeIdAndMod(ParseState *pstate, const TypeName *typeName, Oid *typeid_p, int32 *typmod_p)
Definition: parse_type.c:293
#define InvalidOid
Definition: postgres_ext.h:36
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
#define lfirst(lc)
Definition: pg_list.h:106
static int list_length(const List *l)
Definition: pg_list.h:89
const char * name
Definition: encode.c:521
#define nodeTag(nodeptr)
Definition: nodes.h:513
Definition: nodes.h:287
#define Int32GetDatum(X)
Definition: postgres.h:487
#define intVal(v)
Definition: value.h:52
int errmsg(const char *fmt,...)
Definition: elog.c:797
void * arg
#define elog
Definition: elog.h:219
Value val
Definition: parsenodes.h:279
long val
Definition: informix.c:689
#define GUC_LIST_INPUT
Definition: guc.h:204
Node * arg
Definition: parsenodes.h:289
struct config_generic** get_guc_variables ( void  )

Definition at line 4144 of file guc.c.

References guc_variables.

Referenced by GucInfoMain().

4145 {
4146  return guc_variables;
4147 }
static struct config_generic ** guc_variables
Definition: guc.c:3892
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