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 "catalog/pg_authid.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_internals.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 97 of file guc.c.

Referenced by SelectConfigFiles().

#define HBA_FILENAME   "pg_hba.conf"

Definition at line 98 of file guc.c.

Referenced by SelectConfigFiles().

#define IDENT_FILENAME   "pg_ident.conf"

Definition at line 99 of file guc.c.

Referenced by SelectConfigFiles().

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

Definition at line 702 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 8390 of file guc.c.

Referenced by show_all_settings().

#define PG_KRB_SRVTAB   ""

Definition at line 94 of file guc.c.

#define REALTYPE_PRECISION   17

Definition at line 110 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 8637 of file guc.c.

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

8638 {
8639  char buffer[256];
8640  const char *val;
8641 
8642  switch (record->vartype)
8643  {
8644  case PGC_BOOL:
8645  {
8646  struct config_bool *conf = (struct config_bool *) record;
8647 
8648  if (conf->show_hook)
8649  val = (*conf->show_hook) ();
8650  else
8651  val = *conf->variable ? "on" : "off";
8652  }
8653  break;
8654 
8655  case PGC_INT:
8656  {
8657  struct config_int *conf = (struct config_int *) record;
8658 
8659  if (conf->show_hook)
8660  val = (*conf->show_hook) ();
8661  else
8662  {
8663  /*
8664  * Use int64 arithmetic to avoid overflows in units
8665  * conversion.
8666  */
8667  int64 result = *conf->variable;
8668  const char *unit;
8669 
8670  if (use_units && result > 0 && (record->flags & GUC_UNIT))
8671  {
8672  convert_from_base_unit(result, record->flags & GUC_UNIT,
8673  &result, &unit);
8674  }
8675  else
8676  unit = "";
8677 
8678  snprintf(buffer, sizeof(buffer), INT64_FORMAT "%s",
8679  result, unit);
8680  val = buffer;
8681  }
8682  }
8683  break;
8684 
8685  case PGC_REAL:
8686  {
8687  struct config_real *conf = (struct config_real *) record;
8688 
8689  if (conf->show_hook)
8690  val = (*conf->show_hook) ();
8691  else
8692  {
8693  snprintf(buffer, sizeof(buffer), "%g",
8694  *conf->variable);
8695  val = buffer;
8696  }
8697  }
8698  break;
8699 
8700  case PGC_STRING:
8701  {
8702  struct config_string *conf = (struct config_string *) record;
8703 
8704  if (conf->show_hook)
8705  val = (*conf->show_hook) ();
8706  else if (*conf->variable && **conf->variable)
8707  val = *conf->variable;
8708  else
8709  val = "";
8710  }
8711  break;
8712 
8713  case PGC_ENUM:
8714  {
8715  struct config_enum *conf = (struct config_enum *) record;
8716 
8717  if (conf->show_hook)
8718  val = (*conf->show_hook) ();
8719  else
8720  val = config_enum_lookup_by_value(conf, *conf->variable);
8721  }
8722  break;
8723 
8724  default:
8725  /* just to keep compiler quiet */
8726  val = "???";
8727  break;
8728  }
8729 
8730  return pstrdup(val);
8731 }
char ** variable
Definition: guc_tables.h:227
char * pstrdup(const char *in)
Definition: mcxt.c:1077
bool * variable
Definition: guc_tables.h:181
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5621
return result
Definition: formatting.c:1618
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:201
int * variable
Definition: guc_tables.h:195
int * variable
Definition: guc_tables.h:241
GucShowHook show_hook
Definition: guc_tables.h:231
GucShowHook show_hook
Definition: guc_tables.h:217
double * variable
Definition: guc_tables.h:211
enum config_type vartype
Definition: guc_tables.h:153
GucShowHook show_hook
Definition: guc_tables.h:246
GucShowHook show_hook
Definition: guc_tables.h:185
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:207
#define INT64_FORMAT
Definition: c.h:315
static void convert_from_base_unit(int64 base_value, int base_unit, int64 *value, const char **unit)
Definition: guc.c:5449
long val
Definition: informix.c:689
static bool add_guc_variable ( struct config_generic var,
int  elevel 
)
static

Definition at line 4290 of file guc.c.

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

Referenced by add_placeholder_variable(), and define_custom_variable().

4291 {
4293  {
4294  /*
4295  * Increase the vector by 25%
4296  */
4297  int size_vars = size_guc_variables + size_guc_variables / 4;
4298  struct config_generic **guc_vars;
4299 
4300  if (size_vars == 0)
4301  {
4302  size_vars = 100;
4303  guc_vars = (struct config_generic **)
4304  guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
4305  }
4306  else
4307  {
4308  guc_vars = (struct config_generic **)
4309  guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
4310  }
4311 
4312  if (guc_vars == NULL)
4313  return false; /* out of memory */
4314 
4315  guc_variables = guc_vars;
4316  size_guc_variables = size_vars;
4317  }
4320  sizeof(struct config_generic *), guc_var_compare);
4321  return true;
4322 }
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:4425
static int num_guc_variables
Definition: guc.c:3942
static void * guc_realloc(int elevel, void *old, size_t size)
Definition: guc.c:3996
static struct config_generic ** guc_variables
Definition: guc.c:3939
static int size_guc_variables
Definition: guc.c:3945
static int elevel
Definition: vacuumlazy.c:137
#define NULL
Definition: c.h:229
#define qsort(a, b, c, d)
Definition: port.h:440
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:3980
static struct config_generic* add_placeholder_variable ( const char *  name,
int  elevel 
)
static

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

4329 {
4330  size_t sz = sizeof(struct config_string) + sizeof(char *);
4331  struct config_string *var;
4332  struct config_generic *gen;
4333 
4334  var = (struct config_string *) guc_malloc(elevel, sz);
4335  if (var == NULL)
4336  return NULL;
4337  memset(var, 0, sz);
4338  gen = &var->gen;
4339 
4340  gen->name = guc_strdup(elevel, name);
4341  if (gen->name == NULL)
4342  {
4343  free(var);
4344  return NULL;
4345  }
4346 
4347  gen->context = PGC_USERSET;
4348  gen->group = CUSTOM_OPTIONS;
4349  gen->short_desc = "GUC placeholder variable";
4351  gen->vartype = PGC_STRING;
4352 
4353  /*
4354  * The char* is allocated at the end of the struct since we have no
4355  * 'static' place to point to. Note that the current value, as well as
4356  * the boot and reset values, start out NULL.
4357  */
4358  var->variable = (char **) (var + 1);
4359 
4360  if (!add_guc_variable((struct config_generic *) var, elevel))
4361  {
4362  free((void *) gen->name);
4363  free(var);
4364  return NULL;
4365  }
4366 
4367  return gen;
4368 }
char ** variable
Definition: guc_tables.h:227
const char * name
Definition: guc_tables.h:146
const char * short_desc
Definition: guc_tables.h:149
static char * guc_strdup(int elevel, const char *src)
Definition: guc.c:4012
#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:153
static int elevel
Definition: vacuumlazy.c:137
struct config_generic gen
Definition: guc_tables.h:225
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
#define GUC_CUSTOM_PLACEHOLDER
Definition: guc.h:211
const char * name
Definition: encode.c:521
enum config_group group
Definition: guc_tables.h:148
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:3980
GucContext context
Definition: guc_tables.h:147
static bool add_guc_variable(struct config_generic *var, int elevel)
Definition: guc.c:4290
void AlterSystemSetConfigFile ( AlterSystemStmt altersysstmt)

Definition at line 7074 of file guc.c.

References AllocateFile(), BasicOpenFile(), close, config_generic::context, durable_rename(), elog, ereport, errcode(), errcode_for_file_access(), errmsg(), ERROR, ExtractSetVariableArgs(), find_option(), config_generic::flags, free, FreeConfigVariables(), FreeFile(), GUC_DISALLOW_IN_AUTO_FILE, GUC_DISALLOW_IN_FILE, infile(), VariableSetStmt::kind, LOG, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MAXPGPATH, name, VariableSetStmt::name, NULL, parse_and_validate_value(), ParseConfigFp(), PG_AUTOCONF_FILENAME, PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, PGC_INTERNAL, PGC_S_FILE, PGC_STRING, replace_auto_config_value(), AlterSystemStmt::setstmt, snprintf(), config_var_val::stringval, superuser(), unlink(), value, VAR_RESET, VAR_RESET_ALL, VAR_SET_DEFAULT, VAR_SET_VALUE, config_generic::vartype, and write_auto_conf_file().

Referenced by standard_ProcessUtility().

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

Definition at line 10467 of file guc.c.

References pgstat_report_appname().

10468 {
10469  /* Update the pg_stat_activity view */
10471 }
void pgstat_report_appname(const char *appname)
Definition: pgstat.c:3127
#define newval
static void assign_effective_io_concurrency ( int  newval,
void *  extra 
)
static

Definition at line 10415 of file guc.c.

References target_prefetch_pages.

10416 {
10417 #ifdef USE_PREFETCH
10418  target_prefetch_pages = *((int *) extra);
10419 #endif /* USE_PREFETCH */
10420 }
int target_prefetch_pages
Definition: bufmgr.c:129
static void assign_log_destination ( const char *  newval,
void *  extra 
)
static

Definition at line 10103 of file guc.c.

References Log_destination.

10104 {
10105  Log_destination = *((int *) extra);
10106 }
int Log_destination
Definition: elog.c:106
static void assign_pgstat_temp_directory ( const char *  newval,
void *  extra 
)
static

Definition at line 10423 of file guc.c.

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

10424 {
10425  /* check_canonical_path already canonicalized newval for us */
10426  char *dname;
10427  char *tname;
10428  char *fname;
10429 
10430  /* directory */
10431  dname = guc_malloc(ERROR, strlen(newval) + 1); /* runtime dir */
10432  sprintf(dname, "%s", newval);
10433 
10434  /* global stats */
10435  tname = guc_malloc(ERROR, strlen(newval) + 12); /* /global.tmp */
10436  sprintf(tname, "%s/global.tmp", newval);
10437  fname = guc_malloc(ERROR, strlen(newval) + 13); /* /global.stat */
10438  sprintf(fname, "%s/global.stat", newval);
10439 
10442  pgstat_stat_directory = dname;
10443  if (pgstat_stat_tmpname)
10445  pgstat_stat_tmpname = tname;
10448  pgstat_stat_filename = fname;
10449 }
char * pgstat_stat_filename
Definition: pgstat.c:132
#define ERROR
Definition: elog.h:43
char * pgstat_stat_directory
Definition: pgstat.c:131
#define free(a)
Definition: header.h:65
#define newval
char * pgstat_stat_tmpname
Definition: pgstat.c:133
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:3980
static void assign_session_replication_role ( int  newval,
void *  extra 
)
static

Definition at line 10129 of file guc.c.

References ResetPlanCache(), and SessionReplicationRole.

10130 {
10131  /*
10132  * Must flush the plan cache when changing replication role; but don't
10133  * flush unnecessarily.
10134  */
10136  ResetPlanCache();
10137 }
int SessionReplicationRole
Definition: trigger.c:64
void ResetPlanCache(void)
Definition: plancache.c:1860
#define newval
static void assign_syslog_facility ( int  newval,
void *  extra 
)
static

Definition at line 10109 of file guc.c.

10110 {
10111 #ifdef HAVE_SYSLOG
10112  set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
10113  newval);
10114 #endif
10115  /* Without syslog support, just ignore it */
10116 }
static char * syslog_ident_str
Definition: guc.c:498
#define newval
static void assign_syslog_ident ( const char *  newval,
void *  extra 
)
static

Definition at line 10119 of file guc.c.

10120 {
10121 #ifdef HAVE_SYSLOG
10122  set_syslog_parameters(newval, syslog_facility);
10123 #endif
10124  /* Without syslog support, it will always be set to "none", so ignore */
10125 }
static int syslog_facility
Definition: guc.c:160
#define newval
static void assign_tcp_keepalives_count ( int  newval,
void *  extra 
)
static

Definition at line 10328 of file guc.c.

References MyProcPort, and pq_setkeepalivescount().

10329 {
10330  /* See comments in assign_tcp_keepalives_idle */
10332 }
struct Port * MyProcPort
Definition: globals.c:40
int pq_setkeepalivescount(int count, Port *port)
Definition: pqcomm.c:1886
#define newval
static void assign_tcp_keepalives_idle ( int  newval,
void *  extra 
)
static

Definition at line 10284 of file guc.c.

References MyProcPort, and pq_setkeepalivesidle().

10285 {
10286  /*
10287  * The kernel API provides no way to test a value without setting it; and
10288  * once we set it we might fail to unset it. So there seems little point
10289  * in fully implementing the check-then-assign GUC API for these
10290  * variables. Instead we just do the assignment on demand. pqcomm.c
10291  * reports any problems via elog(LOG).
10292  *
10293  * This approach means that the GUC value might have little to do with the
10294  * actual kernel value, so we use a show_hook that retrieves the kernel
10295  * value rather than trusting GUC's copy.
10296  */
10298 }
struct Port * MyProcPort
Definition: globals.c:40
int pq_setkeepalivesidle(int idle, Port *port)
Definition: pqcomm.c:1721
#define newval
static void assign_tcp_keepalives_interval ( int  newval,
void *  extra 
)
static

Definition at line 10311 of file guc.c.

References MyProcPort, and pq_setkeepalivesinterval().

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

Definition at line 10248 of file guc.c.

References InstallTimeZoneAbbrevs().

10249 {
10250  /* Do nothing for the boot_val default of NULL */
10251  if (!extra)
10252  return;
10253 
10255 }
void InstallTimeZoneAbbrevs(TimeZoneAbbrevTable *tbl)
Definition: datetime.c:4603
static void assign_wal_consistency_checking ( const char *  newval,
void *  extra 
)
static

Definition at line 10040 of file guc.c.

References wal_consistency_checking.

10041 {
10042  wal_consistency_checking = (bool *) extra;
10043 }
bool * wal_consistency_checking
Definition: xlog.c:101
void AtEOXact_GUC ( bool  isCommit,
int  nestLevel 
)

Definition at line 5083 of file guc.c.

References Assert, config_bool::assign_hook, config_int::assign_hook, config_real::assign_hook, config_string::assign_hook, config_enum::assign_hook, config_var_val::boolval, discard_stack_value(), config_var_val::enumval, config_var_value::extra, config_generic::extra, config_generic::flags, config_bool::gen, config_int::gen, config_real::gen, config_string::gen, config_enum::gen, GUC_LOCAL, GUC_REPORT, GUC_SAVE, GUC_SET, GUC_SET_LOCAL, i, config_var_val::intval, guc_stack::masked, guc_stack::masked_scontext, guc_stack::nest_level, newval, NULL, num_guc_variables, pfree(), PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_S_SESSION, PGC_STRING, guc_stack::prev, guc_stack::prior, config_var_val::realval, ReportGUCOption(), guc_stack::scontext, config_generic::scontext, set_extra_field(), set_string_field(), guc_stack::source, config_generic::source, config_generic::stack, guc_stack::state, config_var_val::stringval, config_var_value::val, config_bool::variable, config_int::variable, config_real::variable, config_string::variable, config_enum::variable, and config_generic::vartype.

Referenced by AbortSubTransaction(), AbortTransaction(), CommitSubTransaction(), CommitTransaction(), do_analyze_rel(), ExecCreateTableAs(), ExecRefreshMatView(), execute_extension_script(), fmgr_security_definer(), index_build(), PrepareTransaction(), ProcedureCreate(), reset_transmission_modes(), restoreLocalGucs(), RI_Initial_Check(), vacuum_rel(), and validate_index().

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

Definition at line 5049 of file guc.c.

References elog, and WARNING.

Referenced by StartTransaction().

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

Definition at line 5364 of file guc.c.

References DestRemote, config_generic::flags, FrontendProtocol, GUC_REPORT, i, num_guc_variables, PG_PROTOCOL_MAJOR, ReportGUCOption(), and whereToSendOutput.

Referenced by PostgresMain().

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

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

4204 {
4205  int size_vars;
4206  int num_vars = 0;
4207  struct config_generic **guc_vars;
4208  int i;
4209 
4210  for (i = 0; ConfigureNamesBool[i].gen.name; i++)
4211  {
4212  struct config_bool *conf = &ConfigureNamesBool[i];
4213 
4214  /* Rather than requiring vartype to be filled in by hand, do this: */
4215  conf->gen.vartype = PGC_BOOL;
4216  num_vars++;
4217  }
4218 
4219  for (i = 0; ConfigureNamesInt[i].gen.name; i++)
4220  {
4221  struct config_int *conf = &ConfigureNamesInt[i];
4222 
4223  conf->gen.vartype = PGC_INT;
4224  num_vars++;
4225  }
4226 
4227  for (i = 0; ConfigureNamesReal[i].gen.name; i++)
4228  {
4229  struct config_real *conf = &ConfigureNamesReal[i];
4230 
4231  conf->gen.vartype = PGC_REAL;
4232  num_vars++;
4233  }
4234 
4235  for (i = 0; ConfigureNamesString[i].gen.name; i++)
4236  {
4237  struct config_string *conf = &ConfigureNamesString[i];
4238 
4239  conf->gen.vartype = PGC_STRING;
4240  num_vars++;
4241  }
4242 
4243  for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
4244  {
4245  struct config_enum *conf = &ConfigureNamesEnum[i];
4246 
4247  conf->gen.vartype = PGC_ENUM;
4248  num_vars++;
4249  }
4250 
4251  /*
4252  * Create table with 20% slack
4253  */
4254  size_vars = num_vars + num_vars / 4;
4255 
4256  guc_vars = (struct config_generic **)
4257  guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
4258 
4259  num_vars = 0;
4260 
4261  for (i = 0; ConfigureNamesBool[i].gen.name; i++)
4262  guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
4263 
4264  for (i = 0; ConfigureNamesInt[i].gen.name; i++)
4265  guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
4266 
4267  for (i = 0; ConfigureNamesReal[i].gen.name; i++)
4268  guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
4269 
4270  for (i = 0; ConfigureNamesString[i].gen.name; i++)
4271  guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
4272 
4273  for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
4274  guc_vars[num_vars++] = &ConfigureNamesEnum[i].gen;
4275 
4276  if (guc_variables)
4278  guc_variables = guc_vars;
4279  num_guc_variables = num_vars;
4280  size_guc_variables = size_vars;
4282  sizeof(struct config_generic *), guc_var_compare);
4283 }
static struct config_int ConfigureNamesInt[]
Definition: guc.c:1680
const char * name
Definition: guc_tables.h:146
static struct config_enum ConfigureNamesEnum[]
Definition: guc.c:3653
static struct config_bool ConfigureNamesBool[]
Definition: guc.c:807
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:4425
static int num_guc_variables
Definition: guc.c:3942
#define FATAL
Definition: elog.h:52
struct config_generic gen
Definition: guc_tables.h:179
struct config_generic gen
Definition: guc_tables.h:193
static struct config_generic ** guc_variables
Definition: guc.c:3939
enum config_type vartype
Definition: guc_tables.h:153
static int size_guc_variables
Definition: guc.c:3945
static struct config_real ConfigureNamesReal[]
Definition: guc.c:2899
struct config_generic gen
Definition: guc_tables.h:239
struct config_generic gen
Definition: guc_tables.h:225
#define free(a)
Definition: header.h:65
static struct config_string ConfigureNamesString[]
Definition: guc.c:3060
int i
#define qsort(a, b, c, d)
Definition: port.h:440
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:3980
struct config_generic gen
Definition: guc_tables.h:209
static bool call_bool_check_hook ( struct config_bool conf,
bool newval,
void **  extra,
GucSource  source,
int  elevel 
)
static

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

9792 {
9793  /* Quick success if no hook */
9794  if (!conf->check_hook)
9795  return true;
9796 
9797  /* Reset variables that might be set by hook */
9798  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
9802 
9803  if (!(*conf->check_hook) (newval, extra, source))
9804  {
9805  ereport(elevel,
9809  errmsg("invalid value for parameter \"%s\": %d",
9810  conf->gen.name, (int) *newval),
9814  errhint("%s", GUC_check_errhint_string) : 0));
9815  /* Flush any strings created in ErrorContext */
9816  FlushErrorState();
9817  return false;
9818  }
9819 
9820  return true;
9821 }
char * GUC_check_errhint_string
Definition: guc.c:133
GucSource source
Definition: guc_tables.h:155
int errhint(const char *fmt,...)
Definition: elog.c:987
const char * name
Definition: guc_tables.h:146
int errcode(int sqlerrcode)
Definition: elog.c:575
static int GUC_check_errcode_value
Definition: guc.c:128
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:179
char * GUC_check_errdetail_string
Definition: guc.c:132
#define ereport(elevel, rest)
Definition: elog.h:122
static int elevel
Definition: vacuumlazy.c:137
GucBoolCheckHook check_hook
Definition: guc_tables.h:183
int errmsg_internal(const char *fmt,...)
Definition: elog.c:827
#define NULL
Definition: c.h:229
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:131
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 9926 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().

9928 {
9929  /* Quick success if no hook */
9930  if (!conf->check_hook)
9931  return true;
9932 
9933  /* Reset variables that might be set by hook */
9934  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
9938 
9939  if (!(*conf->check_hook) (newval, extra, source))
9940  {
9941  ereport(elevel,
9945  errmsg("invalid value for parameter \"%s\": \"%s\"",
9946  conf->gen.name,
9951  errhint("%s", GUC_check_errhint_string) : 0));
9952  /* Flush any strings created in ErrorContext */
9953  FlushErrorState();
9954  return false;
9955  }
9956 
9957  return true;
9958 }
char * GUC_check_errhint_string
Definition: guc.c:133
GucSource source
Definition: guc_tables.h:155
GucEnumCheckHook check_hook
Definition: guc_tables.h:244
int errhint(const char *fmt,...)
Definition: elog.c:987
const char * name
Definition: guc_tables.h:146
int errcode(int sqlerrcode)
Definition: elog.c:575
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5621
static int GUC_check_errcode_value
Definition: guc.c:128
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:132
#define ereport(elevel, rest)
Definition: elog.h:122
static int elevel
Definition: vacuumlazy.c:137
struct config_generic gen
Definition: guc_tables.h:239
int errmsg_internal(const char *fmt,...)
Definition: elog.c:827
#define NULL
Definition: c.h:229
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:131
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 9824 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().

9826 {
9827  /* Quick success if no hook */
9828  if (!conf->check_hook)
9829  return true;
9830 
9831  /* Reset variables that might be set by hook */
9832  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
9836 
9837  if (!(*conf->check_hook) (newval, extra, source))
9838  {
9839  ereport(elevel,
9843  errmsg("invalid value for parameter \"%s\": %d",
9844  conf->gen.name, *newval),
9848  errhint("%s", GUC_check_errhint_string) : 0));
9849  /* Flush any strings created in ErrorContext */
9850  FlushErrorState();
9851  return false;
9852  }
9853 
9854  return true;
9855 }
char * GUC_check_errhint_string
Definition: guc.c:133
GucSource source
Definition: guc_tables.h:155
int errhint(const char *fmt,...)
Definition: elog.c:987
const char * name
Definition: guc_tables.h:146
int errcode(int sqlerrcode)
Definition: elog.c:575
static int GUC_check_errcode_value
Definition: guc.c:128
GucIntCheckHook check_hook
Definition: guc_tables.h:199
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:193
char * GUC_check_errdetail_string
Definition: guc.c:132
#define ereport(elevel, rest)
Definition: elog.h:122
static int elevel
Definition: vacuumlazy.c:137
int errmsg_internal(const char *fmt,...)
Definition: elog.c:827
#define NULL
Definition: c.h:229
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:131
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 9858 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().

9860 {
9861  /* Quick success if no hook */
9862  if (!conf->check_hook)
9863  return true;
9864 
9865  /* Reset variables that might be set by hook */
9866  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
9870 
9871  if (!(*conf->check_hook) (newval, extra, source))
9872  {
9873  ereport(elevel,
9877  errmsg("invalid value for parameter \"%s\": %g",
9878  conf->gen.name, *newval),
9882  errhint("%s", GUC_check_errhint_string) : 0));
9883  /* Flush any strings created in ErrorContext */
9884  FlushErrorState();
9885  return false;
9886  }
9887 
9888  return true;
9889 }
char * GUC_check_errhint_string
Definition: guc.c:133
GucSource source
Definition: guc_tables.h:155
int errhint(const char *fmt,...)
Definition: elog.c:987
const char * name
Definition: guc_tables.h:146
int errcode(int sqlerrcode)
Definition: elog.c:575
static int GUC_check_errcode_value
Definition: guc.c:128
GucRealCheckHook check_hook
Definition: guc_tables.h:215
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:132
#define ereport(elevel, rest)
Definition: elog.h:122
static int elevel
Definition: vacuumlazy.c:137
int errmsg_internal(const char *fmt,...)
Definition: elog.c:827
#define NULL
Definition: c.h:229
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:131
int errmsg(const char *fmt,...)
Definition: elog.c:797
struct config_generic gen
Definition: guc_tables.h:209
static bool call_string_check_hook ( struct config_string conf,
char **  newval,
void **  extra,
GucSource  source,
int  elevel 
)
static

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

9894 {
9895  /* Quick success if no hook */
9896  if (!conf->check_hook)
9897  return true;
9898 
9899  /* Reset variables that might be set by hook */
9900  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
9904 
9905  if (!(*conf->check_hook) (newval, extra, source))
9906  {
9907  ereport(elevel,
9911  errmsg("invalid value for parameter \"%s\": \"%s\"",
9912  conf->gen.name, *newval ? *newval : ""),
9916  errhint("%s", GUC_check_errhint_string) : 0));
9917  /* Flush any strings created in ErrorContext */
9918  FlushErrorState();
9919  return false;
9920  }
9921 
9922  return true;
9923 }
char * GUC_check_errhint_string
Definition: guc.c:133
GucSource source
Definition: guc_tables.h:155
int errhint(const char *fmt,...)
Definition: elog.c:987
const char * name
Definition: guc_tables.h:146
GucStringCheckHook check_hook
Definition: guc_tables.h:229
int errcode(int sqlerrcode)
Definition: elog.c:575
static int GUC_check_errcode_value
Definition: guc.c:128
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:132
#define ereport(elevel, rest)
Definition: elog.h:122
static int elevel
Definition: vacuumlazy.c:137
struct config_generic gen
Definition: guc_tables.h:225
int errmsg_internal(const char *fmt,...)
Definition: elog.c:827
#define NULL
Definition: c.h:229
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:131
int errmsg(const char *fmt,...)
Definition: elog.c:797
static bool can_skip_gucvar ( struct config_generic gconf)
static

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

8985 {
8986  return gconf->context == PGC_POSTMASTER ||
8987  gconf->context == PGC_INTERNAL || gconf->source == PGC_S_DEFAULT;
8988 }
GucSource source
Definition: guc_tables.h:155
GucContext context
Definition: guc_tables.h:147
static bool check_application_name ( char **  newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10452 of file guc.c.

10453 {
10454  /* Only allow clean ASCII chars in the application name */
10455  char *p;
10456 
10457  for (p = *newval; *p; p++)
10458  {
10459  if (*p < 32 || *p > 126)
10460  *p = '?';
10461  }
10462 
10463  return true;
10464 }
#define newval
static bool check_autovacuum_max_workers ( int *  newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10354 of file guc.c.

References MAX_BACKENDS, max_worker_processes, and MaxConnections.

10355 {
10357  return false;
10358  return true;
10359 }
#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 10362 of file guc.c.

10363 {
10364  /*
10365  * -1 indicates fallback.
10366  *
10367  * If we haven't yet changed the boot_val default of -1, just let it be.
10368  * Autovacuum will look to maintenance_work_mem instead.
10369  */
10370  if (*newval == -1)
10371  return true;
10372 
10373  /*
10374  * We clamp manually-set values to at least 1MB. Since
10375  * maintenance_work_mem is always set to at least this value, do the same
10376  * here.
10377  */
10378  if (*newval < 1024)
10379  *newval = 1024;
10380 
10381  return true;
10382 }
#define newval
static bool check_bonjour ( bool newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10154 of file guc.c.

References GUC_check_errmsg.

10155 {
10156 #ifndef USE_BONJOUR
10157  if (*newval)
10158  {
10159  GUC_check_errmsg("Bonjour is not supported by this build");
10160  return false;
10161  }
10162 #endif
10163  return true;
10164 }
#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 10205 of file guc.c.

References canonicalize_path().

10206 {
10207  /*
10208  * Since canonicalize_path never enlarges the string, we can just modify
10209  * newval in-place. But watch out for NULL, which is the default value
10210  * for external_pid_file.
10211  */
10212  if (*newval)
10214  return true;
10215 }
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 10474 of file guc.c.

10475 {
10476  /* Only allow clean ASCII chars in the cluster name */
10477  char *p;
10478 
10479  for (p = *newval; *p; p++)
10480  {
10481  if (*p < 32 || *p > 126)
10482  *p = '?';
10483  }
10484 
10485  return true;
10486 }
#define newval
static bool check_effective_io_concurrency ( int *  newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10393 of file guc.c.

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

10394 {
10395 #ifdef USE_PREFETCH
10396  double new_prefetch_pages;
10397 
10398  if (ComputeIoConcurrency(*newval, &new_prefetch_pages))
10399  {
10400  int *myextra = (int *) guc_malloc(ERROR, sizeof(int));
10401 
10402  *myextra = (int) rint(new_prefetch_pages);
10403  *extra = (void *) myextra;
10404 
10405  return true;
10406  }
10407  else
10408  return false;
10409 #else
10410  return true;
10411 #endif /* USE_PREFETCH */
10412 }
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:3980
static bool check_log_destination ( char **  newval,
void **  extra,
GucSource  source 
)
static

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

10047 {
10048  char *rawstring;
10049  List *elemlist;
10050  ListCell *l;
10051  int newlogdest = 0;
10052  int *myextra;
10053 
10054  /* Need a modifiable copy of string */
10055  rawstring = pstrdup(*newval);
10056 
10057  /* Parse string into list of identifiers */
10058  if (!SplitIdentifierString(rawstring, ',', &elemlist))
10059  {
10060  /* syntax error in list */
10061  GUC_check_errdetail("List syntax is invalid.");
10062  pfree(rawstring);
10063  list_free(elemlist);
10064  return false;
10065  }
10066 
10067  foreach(l, elemlist)
10068  {
10069  char *tok = (char *) lfirst(l);
10070 
10071  if (pg_strcasecmp(tok, "stderr") == 0)
10072  newlogdest |= LOG_DESTINATION_STDERR;
10073  else if (pg_strcasecmp(tok, "csvlog") == 0)
10074  newlogdest |= LOG_DESTINATION_CSVLOG;
10075 #ifdef HAVE_SYSLOG
10076  else if (pg_strcasecmp(tok, "syslog") == 0)
10077  newlogdest |= LOG_DESTINATION_SYSLOG;
10078 #endif
10079 #ifdef WIN32
10080  else if (pg_strcasecmp(tok, "eventlog") == 0)
10081  newlogdest |= LOG_DESTINATION_EVENTLOG;
10082 #endif
10083  else
10084  {
10085  GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
10086  pfree(rawstring);
10087  list_free(elemlist);
10088  return false;
10089  }
10090  }
10091 
10092  pfree(rawstring);
10093  list_free(elemlist);
10094 
10095  myextra = (int *) guc_malloc(ERROR, sizeof(int));
10096  *myextra = newlogdest;
10097  *extra = (void *) myextra;
10098 
10099  return true;
10100 }
#define LOG_DESTINATION_EVENTLOG
Definition: elog.h:397
#define GUC_check_errdetail
Definition: guc.h:407
char * pstrdup(const char *in)
Definition: mcxt.c:1077
#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:950
#define ERROR
Definition: elog.h:43
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3240
#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:3980
Definition: pg_list.h:45
static bool check_log_stats ( bool newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10191 of file guc.c.

References GUC_check_errdetail.

10192 {
10193  if (*newval &&
10195  {
10196  GUC_check_errdetail("Cannot enable \"log_statement_stats\" when "
10197  "\"log_parser_stats\", \"log_planner_stats\", "
10198  "or \"log_executor_stats\" is true.");
10199  return false;
10200  }
10201  return true;
10202 }
bool log_parser_stats
Definition: guc.c:442
#define GUC_check_errdetail
Definition: guc.h:407
#define newval
bool log_executor_stats
Definition: guc.c:444
bool log_planner_stats
Definition: guc.c:443
static bool check_max_worker_processes ( int *  newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10385 of file guc.c.

References autovacuum_max_workers, MAX_BACKENDS, and MaxConnections.

10386 {
10388  return false;
10389  return true;
10390 }
#define MAX_BACKENDS
Definition: postmaster.h:75
int MaxConnections
Definition: globals.c:123
int autovacuum_max_workers
Definition: autovacuum.c:113
#define newval
static bool check_maxconnections ( int *  newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10345 of file guc.c.

References autovacuum_max_workers, MAX_BACKENDS, and max_worker_processes.

10346 {
10347  if (*newval + autovacuum_max_workers + 1 +
10349  return false;
10350  return true;
10351 }
#define MAX_BACKENDS
Definition: postmaster.h:75
int autovacuum_max_workers
Definition: autovacuum.c:113
#define newval
int max_worker_processes
Definition: globals.c:124
static bool check_ssl ( bool newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10167 of file guc.c.

References GUC_check_errmsg.

10168 {
10169 #ifndef USE_SSL
10170  if (*newval)
10171  {
10172  GUC_check_errmsg("SSL is not supported by this build");
10173  return false;
10174  }
10175 #endif
10176  return true;
10177 }
#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 10180 of file guc.c.

References GUC_check_errdetail.

10181 {
10182  if (*newval && log_statement_stats)
10183  {
10184  GUC_check_errdetail("Cannot enable parameter when \"log_statement_stats\" is true.");
10185  return false;
10186  }
10187  return true;
10188 }
bool log_statement_stats
Definition: guc.c:445
#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 10140 of file guc.c.

References GUC_check_errdetail, and NLocBuffer.

10141 {
10142  /*
10143  * Once local buffers have been initialized, it's too late to change this.
10144  */
10145  if (NLocBuffer && NLocBuffer != *newval)
10146  {
10147  GUC_check_errdetail("\"temp_buffers\" cannot be changed after any temporary tables have been accessed in the session.");
10148  return false;
10149  }
10150  return true;
10151 }
#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 10218 of file guc.c.

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

10219 {
10220  /*
10221  * The boot_val given above for timezone_abbreviations is NULL. When we
10222  * see this we just do nothing. If this value isn't overridden from the
10223  * config file then pg_timezone_abbrev_initialize() will eventually
10224  * replace it with "Default". This hack has two purposes: to avoid
10225  * wasting cycles loading values that might soon be overridden from the
10226  * config file, and to avoid trying to read the timezone abbrev files
10227  * during InitializeGUCOptions(). The latter doesn't work in an
10228  * EXEC_BACKEND subprocess because my_exec_path hasn't been set yet and so
10229  * we can't locate PGSHAREDIR.
10230  */
10231  if (*newval == NULL)
10232  {
10234  return true;
10235  }
10236 
10237  /* OK, load the file and produce a malloc'd TimeZoneAbbrevTable */
10239 
10240  /* tzparser.c returns NULL on failure, reporting via GUC_check_errmsg */
10241  if (!*extra)
10242  return false;
10243 
10244  return true;
10245 }
GucSource source
Definition: guc_tables.h:155
TimeZoneAbbrevTable * load_tzoffsets(const char *filename)
Definition: tzparser.c:438
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#define newval
static bool check_wal_consistency_checking ( char **  newval,
void **  extra,
GucSource  source 
)
static

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

9967 {
9968  char *rawstring;
9969  List *elemlist;
9970  ListCell *l;
9971  bool newwalconsistency[RM_MAX_ID + 1];
9972 
9973  /* Initialize the array */
9974  MemSet(newwalconsistency, 0, (RM_MAX_ID + 1) * sizeof(bool));
9975 
9976  /* Need a modifiable copy of string */
9977  rawstring = pstrdup(*newval);
9978 
9979  /* Parse string into list of identifiers */
9980  if (!SplitIdentifierString(rawstring, ',', &elemlist))
9981  {
9982  /* syntax error in list */
9983  GUC_check_errdetail("List syntax is invalid.");
9984  pfree(rawstring);
9985  list_free(elemlist);
9986  return false;
9987  }
9988 
9989  foreach(l, elemlist)
9990  {
9991  char *tok = (char *) lfirst(l);
9992  bool found = false;
9993  RmgrId rmid;
9994 
9995  /* Check for 'all'. */
9996  if (pg_strcasecmp(tok, "all") == 0)
9997  {
9998  for (rmid = 0; rmid <= RM_MAX_ID; rmid++)
9999  if (RmgrTable[rmid].rm_mask != NULL)
10000  newwalconsistency[rmid] = true;
10001  found = true;
10002  }
10003  else
10004  {
10005  /*
10006  * Check if the token matches with any individual resource
10007  * manager.
10008  */
10009  for (rmid = 0; rmid <= RM_MAX_ID; rmid++)
10010  {
10011  if (pg_strcasecmp(tok, RmgrTable[rmid].rm_name) == 0 &&
10012  RmgrTable[rmid].rm_mask != NULL)
10013  {
10014  newwalconsistency[rmid] = true;
10015  found = true;
10016  }
10017  }
10018  }
10019 
10020  /* If a valid resource manager is found, check for the next one. */
10021  if (!found)
10022  {
10023  GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
10024  pfree(rawstring);
10025  list_free(elemlist);
10026  return false;
10027  }
10028  }
10029 
10030  pfree(rawstring);
10031  list_free(elemlist);
10032 
10033  /* assign new value */
10034  *extra = guc_malloc(ERROR, (RM_MAX_ID + 1) * sizeof(bool));
10035  memcpy(*extra, newwalconsistency, (RM_MAX_ID + 1) * sizeof(bool));
10036  return true;
10037 }
void(* rm_mask)(char *pagedata, BlockNumber blkno)
#define GUC_check_errdetail
Definition: guc.h:407
char * pstrdup(const char *in)
Definition: mcxt.c:1077
const RmgrData RmgrTable[RM_MAX_ID+1]
Definition: rmgr.c:36
#define MemSet(start, val, len)
Definition: c.h:857
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
void pfree(void *pointer)
Definition: mcxt.c:950
#define ERROR
Definition: elog.h:43
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3240
#define RM_MAX_ID
Definition: rmgr.h:33
uint8 RmgrId
Definition: rmgr.h:11
#define NULL
Definition: c.h:229
#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:3980
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 5670 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().

5672 {
5673  const struct config_enum_entry *entry;
5674  StringInfoData retstr;
5675  int seplen;
5676 
5677  initStringInfo(&retstr);
5678  appendStringInfoString(&retstr, prefix);
5679 
5680  seplen = strlen(separator);
5681  for (entry = record->options; entry && entry->name; entry++)
5682  {
5683  if (!entry->hidden)
5684  {
5685  appendStringInfoString(&retstr, entry->name);
5686  appendBinaryStringInfo(&retstr, separator, seplen);
5687  }
5688  }
5689 
5690  /*
5691  * All the entries may have been hidden, leaving the string empty if no
5692  * prefix was given. This indicates a broken GUC setup, since there is no
5693  * use for an enum without any values, so we just check to make sure we
5694  * don't write to invalid memory instead of actually trying to do
5695  * something smart with it.
5696  */
5697  if (retstr.len >= seplen)
5698  {
5699  /* Replace final separator */
5700  retstr.data[retstr.len - seplen] = '\0';
5701  retstr.len -= seplen;
5702  }
5703 
5704  appendStringInfoString(&retstr, suffix);
5705 
5706  return retstr.data;
5707 }
Definition: guc.h:164
const struct config_enum_entry * options
Definition: guc_tables.h:243
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 5644 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().

5646 {
5647  const struct config_enum_entry *entry;
5648 
5649  for (entry = record->options; entry && entry->name; entry++)
5650  {
5651  if (pg_strcasecmp(value, entry->name) == 0)
5652  {
5653  *retval = entry->val;
5654  return TRUE;
5655  }
5656  }
5657 
5658  *retval = 0;
5659  return FALSE;
5660 }
Definition: guc.h:164
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
#define FALSE
Definition: c.h:221
const struct config_enum_entry * options
Definition: guc_tables.h:243
int val
Definition: guc.h:167
const char * name
Definition: guc.h:166
#define TRUE
Definition: c.h:217
static struct @121 value
const char* config_enum_lookup_by_value ( struct config_enum record,
int  val 
)

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

5622 {
5623  const struct config_enum_entry *entry;
5624 
5625  for (entry = record->options; entry && entry->name; entry++)
5626  {
5627  if (entry->val == val)
5628  return entry->name;
5629  }
5630 
5631  elog(ERROR, "could not find enum option %d for %s",
5632  val, record->gen.name);
5633  return NULL; /* silence compiler */
5634 }
Definition: guc.h:164
const char * name
Definition: guc_tables.h:146
#define ERROR
Definition: elog.h:43
const struct config_enum_entry * options
Definition: guc_tables.h:243
int val
Definition: guc.h:167
struct config_generic gen
Definition: guc_tables.h:239
#define NULL
Definition: c.h:229
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 5449 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().

5451 {
5452  const unit_conversion *table;
5453  int i;
5454 
5455  *unit = NULL;
5456 
5457  if (base_unit & GUC_UNIT_MEMORY)
5459  else
5461 
5462  for (i = 0; *table[i].unit; i++)
5463  {
5464  if (base_unit == table[i].base_unit)
5465  {
5466  /*
5467  * Accept the first conversion that divides the value evenly. We
5468  * assume that the conversions for each base unit are ordered from
5469  * greatest unit to the smallest!
5470  */
5471  if (table[i].multiplier < 0)
5472  {
5473  *value = base_value * (-table[i].multiplier);
5474  *unit = table[i].unit;
5475  break;
5476  }
5477  else if (base_value % table[i].multiplier == 0)
5478  {
5479  *value = base_value / table[i].multiplier;
5480  *unit = table[i].unit;
5481  break;
5482  }
5483  }
5484  }
5485 
5486  Assert(*unit != NULL);
5487 }
static const unit_conversion time_unit_conversion_table[]
Definition: guc.c:754
static const unit_conversion memory_unit_conversion_table[]
Definition: guc.c:727
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
int i
static struct @121 value
char unit[MAX_UNIT_LEN+1]
Definition: guc.c:706
#define GUC_UNIT_MEMORY
Definition: guc.h:222
int multiplier
Definition: guc.c:709
static bool convert_to_base_unit ( int64  value,
const char *  unit,
int  base_unit,
int64 *  base_value 
)
static

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

5418 {
5419  const unit_conversion *table;
5420  int i;
5421 
5422  if (base_unit & GUC_UNIT_MEMORY)
5424  else
5426 
5427  for (i = 0; *table[i].unit; i++)
5428  {
5429  if (base_unit == table[i].base_unit &&
5430  strcmp(unit, table[i].unit) == 0)
5431  {
5432  if (table[i].multiplier < 0)
5433  *base_value = value / (-table[i].multiplier);
5434  else
5435  *base_value = value * table[i].multiplier;
5436  return true;
5437  }
5438  }
5439  return false;
5440 }
static const unit_conversion time_unit_conversion_table[]
Definition: guc.c:754
static const unit_conversion memory_unit_conversion_table[]
Definition: guc.c:727
int i
static struct @121 value
char unit[MAX_UNIT_LEN+1]
Definition: guc.c:706
#define GUC_UNIT_MEMORY
Definition: guc.h:222
int multiplier
Definition: guc.c:709
static void define_custom_variable ( struct config_generic variable)
static

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

7553 {
7554  const char *name = variable->name;
7555  const char **nameAddr = &name;
7556  struct config_string *pHolder;
7557  struct config_generic **res;
7558 
7559  /*
7560  * See if there's a placeholder by the same name.
7561  */
7562  res = (struct config_generic **) bsearch((void *) &nameAddr,
7563  (void *) guc_variables,
7565  sizeof(struct config_generic *),
7566  guc_var_compare);
7567  if (res == NULL)
7568  {
7569  /*
7570  * No placeholder to replace, so we can just add it ... but first,
7571  * make sure it's initialized to its default value.
7572  */
7573  InitializeOneGUCOption(variable);
7574  add_guc_variable(variable, ERROR);
7575  return;
7576  }
7577 
7578  /*
7579  * This better be a placeholder
7580  */
7581  if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
7582  ereport(ERROR,
7583  (errcode(ERRCODE_INTERNAL_ERROR),
7584  errmsg("attempt to redefine parameter \"%s\"", name)));
7585 
7586  Assert((*res)->vartype == PGC_STRING);
7587  pHolder = (struct config_string *) (*res);
7588 
7589  /*
7590  * First, set the variable to its default value. We must do this even
7591  * though we intend to immediately apply a new value, since it's possible
7592  * that the new value is invalid.
7593  */
7594  InitializeOneGUCOption(variable);
7595 
7596  /*
7597  * Replace the placeholder. We aren't changing the name, so no re-sorting
7598  * is necessary
7599  */
7600  *res = variable;
7601 
7602  /*
7603  * Assign the string value(s) stored in the placeholder to the real
7604  * variable. Essentially, we need to duplicate all the active and stacked
7605  * values, but with appropriate validation and datatype adjustment.
7606  *
7607  * If an assignment fails, we report a WARNING and keep going. We don't
7608  * want to throw ERROR for bad values, because it'd bollix the add-on
7609  * module that's presumably halfway through getting loaded. In such cases
7610  * the default or previous state will become active instead.
7611  */
7612 
7613  /* First, apply the reset value if any */
7614  if (pHolder->reset_val)
7615  (void) set_config_option(name, pHolder->reset_val,
7616  pHolder->gen.reset_scontext,
7617  pHolder->gen.reset_source,
7618  GUC_ACTION_SET, true, WARNING, false);
7619  /* That should not have resulted in stacking anything */
7620  Assert(variable->stack == NULL);
7621 
7622  /* Now, apply current and stacked values, in the order they were stacked */
7623  reapply_stacked_values(variable, pHolder, pHolder->gen.stack,
7624  *(pHolder->variable),
7625  pHolder->gen.scontext, pHolder->gen.source);
7626 
7627  /* Also copy over any saved source-location information */
7628  if (pHolder->gen.sourcefile)
7629  set_config_sourcefile(name, pHolder->gen.sourcefile,
7630  pHolder->gen.sourceline);
7631 
7632  /*
7633  * Free up as much as we conveniently can of the placeholder structure.
7634  * (This neglects any stack items, so it's possible for some memory to be
7635  * leaked. Since this can only happen once per session per variable, it
7636  * doesn't seem worth spending much code on.)
7637  */
7638  set_string_field(pHolder, pHolder->variable, NULL);
7639  set_string_field(pHolder, &pHolder->reset_val, NULL);
7640 
7641  free(pHolder);
7642 }
GucSource source
Definition: guc_tables.h:155
static void static void set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
Definition: guc.c:6642
char ** variable
Definition: guc_tables.h:227
const char * name
Definition: guc_tables.h:146
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:7652
int errcode(int sqlerrcode)
Definition: elog.c:575
GucContext scontext
Definition: guc_tables.h:157
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:4425
#define ERROR
Definition: elog.h:43
static int num_guc_variables
Definition: guc.c:3942
char * sourcefile
Definition: guc_tables.h:161
GucSource reset_source
Definition: guc_tables.h:156
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:4573
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4052
#define ereport(elevel, rest)
Definition: elog.h:122
static struct config_generic ** guc_variables
Definition: guc.c:3939
#define WARNING
Definition: elog.h:40
struct config_generic gen
Definition: guc_tables.h:225
#define free(a)
Definition: header.h:65
char * reset_val
Definition: guc_tables.h:233
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#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:159
int set_config_option(const char *name, const char *value, GucContext context, GucSource source, GucAction action, bool changeVal, int elevel, bool is_reload)
Definition: guc.c:5912
static bool add_guc_variable(struct config_generic *var, int elevel)
Definition: guc.c:4290
GucContext reset_scontext
Definition: guc_tables.h:158
void DefineCustomBoolVariable ( const char *  name,
const char *  short_desc,
const char *  long_desc,
bool valueAddr,
bool  bootValue,
GucContext  context,
int  flags,
GucBoolCheckHook  check_hook,
GucBoolAssignHook  assign_hook,
GucShowHook  show_hook 
)

Definition at line 7733 of file guc.c.

References config_bool::assign_hook, config_bool::boot_val, config_bool::check_hook, define_custom_variable(), config_bool::gen, init_custom_variable(), PGC_BOOL, config_bool::reset_val, config_bool::show_hook, and config_bool::variable.

Referenced by _PG_init().

7743 {
7744  struct config_bool *var;
7745 
7746  var = (struct config_bool *)
7747  init_custom_variable(name, short_desc, long_desc, context, flags,
7748  PGC_BOOL, sizeof(struct config_bool));
7749  var->variable = valueAddr;
7750  var->boot_val = bootValue;
7751  var->reset_val = bootValue;
7752  var->check_hook = check_hook;
7753  var->assign_hook = assign_hook;
7754  var->show_hook = show_hook;
7755  define_custom_variable(&var->gen);
7756 }
bool * variable
Definition: guc_tables.h:181
GucBoolAssignHook assign_hook
Definition: guc_tables.h:184
bool boot_val
Definition: guc_tables.h:182
struct config_generic gen
Definition: guc_tables.h:179
static struct config_generic * init_custom_variable(const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
Definition: guc.c:7501
GucBoolCheckHook check_hook
Definition: guc_tables.h:183
GucShowHook show_hook
Definition: guc_tables.h:185
const char * name
Definition: encode.c:521
bool reset_val
Definition: guc_tables.h:187
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7552
void DefineCustomEnumVariable ( const char *  name,
const char *  short_desc,
const char *  long_desc,
int *  valueAddr,
int  bootValue,
const struct config_enum_entry options,
GucContext  context,
int  flags,
GucEnumCheckHook  check_hook,
GucEnumAssignHook  assign_hook,
GucShowHook  show_hook 
)

Definition at line 7844 of file guc.c.

References config_enum::assign_hook, config_enum::boot_val, config_enum::check_hook, define_custom_variable(), config_enum::gen, init_custom_variable(), options, config_enum::options, PGC_ENUM, config_enum::reset_val, config_enum::show_hook, and config_enum::variable.

Referenced by _PG_init().

7855 {
7856  struct config_enum *var;
7857 
7858  var = (struct config_enum *)
7859  init_custom_variable(name, short_desc, long_desc, context, flags,
7860  PGC_ENUM, sizeof(struct config_enum));
7861  var->variable = valueAddr;
7862  var->boot_val = bootValue;
7863  var->reset_val = bootValue;
7864  var->options = options;
7865  var->check_hook = check_hook;
7866  var->assign_hook = assign_hook;
7867  var->show_hook = show_hook;
7868  define_custom_variable(&var->gen);
7869 }
GucEnumCheckHook check_hook
Definition: guc_tables.h:244
GucEnumAssignHook assign_hook
Definition: guc_tables.h:245
int * variable
Definition: guc_tables.h:241
const struct config_enum_entry * options
Definition: guc_tables.h:243
static char ** options
static struct config_generic * init_custom_variable(const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
Definition: guc.c:7501
GucShowHook show_hook
Definition: guc_tables.h:246
struct config_generic gen
Definition: guc_tables.h:239
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7552
void DefineCustomIntVariable ( const char *  name,
const char *  short_desc,
const char *  long_desc,
int *  valueAddr,
int  bootValue,
int  minValue,
int  maxValue,
GucContext  context,
int  flags,
GucIntCheckHook  check_hook,
GucIntAssignHook  assign_hook,
GucShowHook  show_hook 
)

Definition at line 7759 of file guc.c.

References config_int::assign_hook, config_int::boot_val, config_int::check_hook, define_custom_variable(), config_int::gen, init_custom_variable(), config_int::max, config_int::min, PGC_INT, config_int::reset_val, config_int::show_hook, and config_int::variable.

Referenced by _PG_init().

7771 {
7772  struct config_int *var;
7773 
7774  var = (struct config_int *)
7775  init_custom_variable(name, short_desc, long_desc, context, flags,
7776  PGC_INT, sizeof(struct config_int));
7777  var->variable = valueAddr;
7778  var->boot_val = bootValue;
7779  var->reset_val = bootValue;
7780  var->min = minValue;
7781  var->max = maxValue;
7782  var->check_hook = check_hook;
7783  var->assign_hook = assign_hook;
7784  var->show_hook = show_hook;
7785  define_custom_variable(&var->gen);
7786 }
int boot_val
Definition: guc_tables.h:196
GucIntAssignHook assign_hook
Definition: guc_tables.h:200
GucIntCheckHook check_hook
Definition: guc_tables.h:199
GucShowHook show_hook
Definition: guc_tables.h:201
int * variable
Definition: guc_tables.h:195
struct config_generic gen
Definition: guc_tables.h:193
static struct config_generic * init_custom_variable(const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
Definition: guc.c:7501
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7552
int reset_val
Definition: guc_tables.h:203
void DefineCustomRealVariable ( const char *  name,
const char *  short_desc,
const char *  long_desc,
double *  valueAddr,
double  bootValue,
double  minValue,
double  maxValue,
GucContext  context,
int  flags,
GucRealCheckHook  check_hook,
GucRealAssignHook  assign_hook,
GucShowHook  show_hook 
)

Definition at line 7789 of file guc.c.

References config_real::assign_hook, config_real::boot_val, config_real::check_hook, define_custom_variable(), config_real::gen, init_custom_variable(), config_real::max, config_real::min, PGC_REAL, config_real::reset_val, config_real::show_hook, and config_real::variable.

Referenced by _PG_init().

7801 {
7802  struct config_real *var;
7803 
7804  var = (struct config_real *)
7805  init_custom_variable(name, short_desc, long_desc, context, flags,
7806  PGC_REAL, sizeof(struct config_real));
7807  var->variable = valueAddr;
7808  var->boot_val = bootValue;
7809  var->reset_val = bootValue;
7810  var->min = minValue;
7811  var->max = maxValue;
7812  var->check_hook = check_hook;
7813  var->assign_hook = assign_hook;
7814  var->show_hook = show_hook;
7815  define_custom_variable(&var->gen);
7816 }
GucRealAssignHook assign_hook
Definition: guc_tables.h:216
double reset_val
Definition: guc_tables.h:219
GucRealCheckHook check_hook
Definition: guc_tables.h:215
GucShowHook show_hook
Definition: guc_tables.h:217
double * variable
Definition: guc_tables.h:211
static struct config_generic * init_custom_variable(const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
Definition: guc.c:7501
double max
Definition: guc_tables.h:214
double boot_val
Definition: guc_tables.h:212
const char * name
Definition: encode.c:521
double min
Definition: guc_tables.h:213
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7552
struct config_generic gen
Definition: guc_tables.h:209
void DefineCustomStringVariable ( const char *  name,
const char *  short_desc,
const char *  long_desc,
char **  valueAddr,
const char *  bootValue,
GucContext  context,
int  flags,
GucStringCheckHook  check_hook,
GucStringAssignHook  assign_hook,
GucShowHook  show_hook 
)

Definition at line 7819 of file guc.c.

References config_string::assign_hook, config_string::boot_val, config_string::check_hook, define_custom_variable(), config_string::gen, init_custom_variable(), PGC_STRING, config_string::show_hook, and config_string::variable.

Referenced by _PG_init().

7829 {
7830  struct config_string *var;
7831 
7832  var = (struct config_string *)
7833  init_custom_variable(name, short_desc, long_desc, context, flags,
7834  PGC_STRING, sizeof(struct config_string));
7835  var->variable = valueAddr;
7836  var->boot_val = bootValue;
7837  var->check_hook = check_hook;
7838  var->assign_hook = assign_hook;
7839  var->show_hook = show_hook;
7840  define_custom_variable(&var->gen);
7841 }
char ** variable
Definition: guc_tables.h:227
GucStringCheckHook check_hook
Definition: guc_tables.h:229
const char * boot_val
Definition: guc_tables.h:228
GucShowHook show_hook
Definition: guc_tables.h:231
static struct config_generic * init_custom_variable(const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
Definition: guc.c:7501
struct config_generic gen
Definition: guc_tables.h:225
GucStringAssignHook assign_hook
Definition: guc_tables.h:230
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7552
static void discard_stack_value ( struct config_generic gconf,
config_var_value val 
)
static

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

4168 {
4169  switch (gconf->vartype)
4170  {
4171  case PGC_BOOL:
4172  case PGC_INT:
4173  case PGC_REAL:
4174  case PGC_ENUM:
4175  /* no need to do anything */
4176  break;
4177  case PGC_STRING:
4178  set_string_field((struct config_string *) gconf,
4179  &(val->val.stringval),
4180  NULL);
4181  break;
4182  }
4183  set_extra_field(gconf, &(val->extra), NULL);
4184 }
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:4113
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4052
enum config_type vartype
Definition: guc_tables.h:153
#define NULL
Definition: c.h:229
char * stringval
Definition: guc_tables.h:36
static void do_serialize ( char **  destptr,
Size maxbytes,
const char *  fmt,
  ... 
)
static

Definition at line 9118 of file guc.c.

References elog, ERROR, and vsnprintf().

Referenced by serialize_variable().

9119 {
9120  va_list vargs;
9121  int n;
9122 
9123  if (*maxbytes <= 0)
9124  elog(ERROR, "not enough space to serialize GUC state");
9125 
9126  va_start(vargs, fmt);
9127  n = vsnprintf(*destptr, *maxbytes, fmt, vargs);
9128  va_end(vargs);
9129 
9130  /*
9131  * Cater to portability hazards in the vsnprintf() return value just like
9132  * appendPQExpBufferVA() does. Note that this requires an extra byte of
9133  * slack at the end of the buffer. Since serialize_variable() ends with a
9134  * do_serialize_binary() rather than a do_serialize(), we'll always have
9135  * that slack; estimate_variable_size() need not add a byte for it.
9136  */
9137  if (n < 0 || n >= *maxbytes - 1)
9138  {
9139  if (n < 0 && errno != 0 && errno != ENOMEM)
9140  /* Shouldn't happen. Better show errno description. */
9141  elog(ERROR, "vsnprintf failed: %m");
9142  else
9143  elog(ERROR, "not enough space to serialize GUC state");
9144  }
9145 
9146  /* Shift the destptr ahead of the null terminator */
9147  *destptr += n + 1;
9148  *maxbytes -= n + 1;
9149 }
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 9153 of file guc.c.

References elog, and ERROR.

Referenced by serialize_variable().

9154 {
9155  if (valsize > *maxbytes)
9156  elog(ERROR, "not enough space to serialize GUC state");
9157 
9158  memcpy(*destptr, val, valsize);
9159  *destptr += valsize;
9160  *maxbytes -= valsize;
9161 }
#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 7872 of file guc.c.

References ereport, errcode(), errmsg(), config_generic::flags, GUC_CUSTOM_PLACEHOLDER, GUC_QUALIFIER_SEPARATOR, i, config_generic::name, num_guc_variables, and WARNING.

Referenced by _PG_init().

7873 {
7874  int classLen = strlen(className);
7875  int i;
7876 
7877  for (i = 0; i < num_guc_variables; i++)
7878  {
7879  struct config_generic *var = guc_variables[i];
7880 
7881  if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
7882  strncmp(className, var->name, classLen) == 0 &&
7883  var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
7884  {
7885  ereport(WARNING,
7886  (errcode(ERRCODE_UNDEFINED_OBJECT),
7887  errmsg("unrecognized configuration parameter \"%s\"",
7888  var->name)));
7889  }
7890  }
7891 }
const char * name
Definition: guc_tables.h:146
int errcode(int sqlerrcode)
Definition: elog.c:575
#define GUC_QUALIFIER_SEPARATOR
Definition: guc.h:199
static int num_guc_variables
Definition: guc.c:3942
#define ereport(elevel, rest)
Definition: elog.h:122
static struct config_generic ** guc_variables
Definition: guc.c:3939
#define WARNING
Definition: elog.h:40
#define GUC_CUSTOM_PLACEHOLDER
Definition: guc.h:211
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
static Size estimate_variable_size ( struct config_generic gconf)
static

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

8998 {
8999  Size size;
9000  Size valsize = 0;
9001 
9002  if (can_skip_gucvar(gconf))
9003  return 0;
9004 
9005  /* Name, plus trailing zero byte. */
9006  size = strlen(gconf->name) + 1;
9007 
9008  /* Get the maximum display length of the GUC value. */
9009  switch (gconf->vartype)
9010  {
9011  case PGC_BOOL:
9012  {
9013  valsize = 5; /* max(strlen('true'), strlen('false')) */
9014  }
9015  break;
9016 
9017  case PGC_INT:
9018  {
9019  struct config_int *conf = (struct config_int *) gconf;
9020 
9021  /*
9022  * Instead of getting the exact display length, use max
9023  * length. Also reduce the max length for typical ranges of
9024  * small values. Maximum value is 2147483647, i.e. 10 chars.
9025  * Include one byte for sign.
9026  */
9027  if (Abs(*conf->variable) < 1000)
9028  valsize = 3 + 1;
9029  else
9030  valsize = 10 + 1;
9031  }
9032  break;
9033 
9034  case PGC_REAL:
9035  {
9036  /*
9037  * We are going to print it with %e with REALTYPE_PRECISION
9038  * fractional digits. Account for sign, leading digit,
9039  * decimal point, and exponent with up to 3 digits. E.g.
9040  * -3.99329042340000021e+110
9041  */
9042  valsize = 1 + 1 + 1 + REALTYPE_PRECISION + 5;
9043  }
9044  break;
9045 
9046  case PGC_STRING:
9047  {
9048  struct config_string *conf = (struct config_string *) gconf;
9049 
9050  /*
9051  * If the value is NULL, we transmit it as an empty string.
9052  * Although this is not physically the same value, GUC
9053  * generally treats a NULL the same as empty string.
9054  */
9055  if (*conf->variable)
9056  valsize = strlen(*conf->variable);
9057  else
9058  valsize = 0;
9059  }
9060  break;
9061 
9062  case PGC_ENUM:
9063  {
9064  struct config_enum *conf = (struct config_enum *) gconf;
9065 
9066  valsize = strlen(config_enum_lookup_by_value(conf, *conf->variable));
9067  }
9068  break;
9069  }
9070 
9071  /* Allow space for terminating zero-byte for value */
9072  size = add_size(size, valsize + 1);
9073 
9074  if (gconf->sourcefile)
9075  size = add_size(size, strlen(gconf->sourcefile));
9076 
9077  /* Allow space for terminating zero-byte for sourcefile */
9078  size = add_size(size, 1);
9079 
9080  /* Include line whenever file is nonempty. */
9081  if (gconf->sourcefile && gconf->sourcefile[0])
9082  size = add_size(size, sizeof(gconf->sourceline));
9083 
9084  size = add_size(size, sizeof(gconf->source));
9085  size = add_size(size, sizeof(gconf->scontext));
9086 
9087  return size;
9088 }
GucSource source
Definition: guc_tables.h:155
char ** variable
Definition: guc_tables.h:227
const char * name
Definition: guc_tables.h:146
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5621
GucContext scontext
Definition: guc_tables.h:157
#define Abs(x)
Definition: c.h:812
int * variable
Definition: guc_tables.h:195
int * variable
Definition: guc_tables.h:241
char * sourcefile
Definition: guc_tables.h:161
static bool can_skip_gucvar(struct config_generic *gconf)
Definition: guc.c:8984
#define REALTYPE_PRECISION
Definition: guc.c:110
enum config_type vartype
Definition: guc_tables.h:153
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
size_t Size
Definition: c.h:356
Size EstimateGUCStateSpace ( void  )

Definition at line 9095 of file guc.c.

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

Referenced by InitializeParallelDSM().

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

Definition at line 7289 of file guc.c.

References DefElem::arg, VariableSetStmt::args, Assert, DefElem::defname, elog, ereport, errcode(), errmsg(), ERROR, ExtractSetVariableArgs(), GUC_ACTION_LOCAL, GUC_ACTION_SET, ImportSnapshot(), VariableSetStmt::is_local, IsInParallelMode(), VariableSetStmt::kind, lfirst, linitial_node, list_make1, VariableSetStmt::name, nodeTag, NULL, PGC_S_SESSION, PGC_SUSET, PGC_USERSET, ResetAllOptions(), set_config_option(), SetPGVariable(), strVal, superuser(), T_String, A_Const::val, VAR_RESET, VAR_RESET_ALL, VAR_SET_CURRENT, VAR_SET_DEFAULT, VAR_SET_MULTI, VAR_SET_VALUE, and WarnNoTransactionChain().

Referenced by standard_ProcessUtility().

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

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

4069 {
4070  GucStack *stack;
4071 
4072  if (extra == gconf->extra)
4073  return true;
4074  switch (gconf->vartype)
4075  {
4076  case PGC_BOOL:
4077  if (extra == ((struct config_bool *) gconf)->reset_extra)
4078  return true;
4079  break;
4080  case PGC_INT:
4081  if (extra == ((struct config_int *) gconf)->reset_extra)
4082  return true;
4083  break;
4084  case PGC_REAL:
4085  if (extra == ((struct config_real *) gconf)->reset_extra)
4086  return true;
4087  break;
4088  case PGC_STRING:
4089  if (extra == ((struct config_string *) gconf)->reset_extra)
4090  return true;
4091  break;
4092  case PGC_ENUM:
4093  if (extra == ((struct config_enum *) gconf)->reset_extra)
4094  return true;
4095  break;
4096  }
4097  for (stack = gconf->stack; stack; stack = stack->prev)
4098  {
4099  if (extra == stack->prior.extra ||
4100  extra == stack->masked.extra)
4101  return true;
4102  }
4103 
4104  return false;
4105 }
struct guc_stack * prev
Definition: guc_tables.h:120
config_var_value masked
Definition: guc_tables.h:128
void * reset_extra
Definition: guc_tables.h:249
enum config_type vartype
Definition: guc_tables.h:153
GucStack * stack
Definition: guc_tables.h:159
config_var_value prior
Definition: guc_tables.h:127
char* ExtractSetVariableArgs ( VariableSetStmt stmt)

Definition at line 7413 of file guc.c.

References VariableSetStmt::args, flatten_set_variable_args(), GetConfigOptionByName(), VariableSetStmt::kind, VariableSetStmt::name, NULL, VAR_SET_CURRENT, and VAR_SET_VALUE.

Referenced by AlterSetting(), AlterSystemSetConfigFile(), ExecSetVariableStmt(), and update_proconfig_value().

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

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

4377 {
4378  const char **key = &name;
4379  struct config_generic **res;
4380  int i;
4381 
4382  Assert(name);
4383 
4384  /*
4385  * By equating const char ** with struct config_generic *, we are assuming
4386  * the name field is first in config_generic.
4387  */
4388  res = (struct config_generic **) bsearch((void *) &key,
4389  (void *) guc_variables,
4391  sizeof(struct config_generic *),
4392  guc_var_compare);
4393  if (res)
4394  return *res;
4395 
4396  /*
4397  * See if the name is an obsolete name for a variable. We assume that the
4398  * set of supported old names is short enough that a brute-force search is
4399  * the best way.
4400  */
4401  for (i = 0; map_old_guc_names[i] != NULL; i += 2)
4402  {
4403  if (guc_name_compare(name, map_old_guc_names[i]) == 0)
4404  return find_option(map_old_guc_names[i + 1], false, elevel);
4405  }
4406 
4407  if (create_placeholders)
4408  {
4409  /*
4410  * Check if the name is qualified, and if so, add a placeholder.
4411  */
4412  if (strchr(name, GUC_QUALIFIER_SEPARATOR) != NULL)
4414  }
4415 
4416  /* Unknown name */
4417  return NULL;
4418 }
#define GUC_QUALIFIER_SEPARATOR
Definition: guc.h:199
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:4437
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:4425
static int num_guc_variables
Definition: guc.c:3942
static struct config_generic ** guc_variables
Definition: guc.c:3939
static int elevel
Definition: vacuumlazy.c:137
static const char *const map_old_guc_names[]
Definition: guc.c:3929
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4376
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
const char * name
Definition: encode.c:521
static struct config_generic * add_placeholder_variable(const char *name, int elevel)
Definition: guc.c:4328
int i
static char* flatten_set_variable_args ( const char *  name,
List args 
)
static

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

6812 {
6813  struct config_generic *record;
6814  int flags;
6816  ListCell *l;
6817 
6818  /* Fast path if just DEFAULT */
6819  if (args == NIL)
6820  return NULL;
6821 
6822  /*
6823  * Get flags for the variable; if it's not known, use default flags.
6824  * (Caller might throw error later, but not our business to do so here.)
6825  */
6826  record = find_option(name, false, WARNING);
6827  if (record)
6828  flags = record->flags;
6829  else
6830  flags = 0;
6831 
6832  /* Complain if list input and non-list variable */
6833  if ((flags & GUC_LIST_INPUT) == 0 &&
6834  list_length(args) != 1)
6835  ereport(ERROR,
6836  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6837  errmsg("SET %s takes only one argument", name)));
6838 
6839  initStringInfo(&buf);
6840 
6841  /*
6842  * Each list member may be a plain A_Const node, or an A_Const within a
6843  * TypeCast; the latter case is supported only for ConstInterval arguments
6844  * (for SET TIME ZONE).
6845  */
6846  foreach(l, args)
6847  {
6848  Node *arg = (Node *) lfirst(l);
6849  char *val;
6850  TypeName *typeName = NULL;
6851  A_Const *con;
6852 
6853  if (l != list_head(args))
6854  appendStringInfoString(&buf, ", ");
6855 
6856  if (IsA(arg, TypeCast))
6857  {
6858  TypeCast *tc = (TypeCast *) arg;
6859 
6860  arg = tc->arg;
6861  typeName = tc->typeName;
6862  }
6863 
6864  if (!IsA(arg, A_Const))
6865  elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
6866  con = (A_Const *) arg;
6867 
6868  switch (nodeTag(&con->val))
6869  {
6870  case T_Integer:
6871  appendStringInfo(&buf, "%ld", intVal(&con->val));
6872  break;
6873  case T_Float:
6874  /* represented as a string, so just copy it */
6875  appendStringInfoString(&buf, strVal(&con->val));
6876  break;
6877  case T_String:
6878  val = strVal(&con->val);
6879  if (typeName != NULL)
6880  {
6881  /*
6882  * Must be a ConstInterval argument for TIME ZONE. Coerce
6883  * to interval and back to normalize the value and account
6884  * for any typmod.
6885  */
6886  Oid typoid;
6887  int32 typmod;
6888  Datum interval;
6889  char *intervalout;
6890 
6891  typenameTypeIdAndMod(NULL, typeName, &typoid, &typmod);
6892  Assert(typoid == INTERVALOID);
6893 
6894  interval =
6896  CStringGetDatum(val),
6898  Int32GetDatum(typmod));
6899 
6900  intervalout =
6902  interval));
6903  appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
6904  }
6905  else
6906  {
6907  /*
6908  * Plain string literal or identifier. For quote mode,
6909  * quote it if it's not a vanilla identifier.
6910  */
6911  if (flags & GUC_LIST_QUOTE)
6913  else
6914  appendStringInfoString(&buf, val);
6915  }
6916  break;
6917  default:
6918  elog(ERROR, "unrecognized node type: %d",
6919  (int) nodeTag(&con->val));
6920  break;
6921  }
6922  }
6923 
6924  return buf.data;
6925 }
#define NIL
Definition: pg_list.h:69
#define IsA(nodeptr, _type_)
Definition: nodes.h:560
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:10254
Datum interval_in(PG_FUNCTION_ARGS)
Definition: timestamp.c:876
#define GUC_LIST_QUOTE
Definition: guc.h:205
Definition: nodes.h:509
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:575
Datum interval_out(PG_FUNCTION_ARGS)
Definition: timestamp.c:958
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:584
unsigned int Oid
Definition: postgres_ext.h:31
signed int int32
Definition: c.h:256
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:110
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
#define DatumGetCString(X)
Definition: postgres.h:572
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:189
static char * buf
Definition: pg_test_fsync.c:66
#define CStringGetDatum(X)
Definition: postgres.h:584
#define INTERVALOID
Definition: pg_type.h:529
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:588
void initStringInfo(StringInfo str)
Definition: stringinfo.c:65
#define WARNING
Definition: elog.h:40
uintptr_t Datum
Definition: postgres.h:372
TypeName * typeName
Definition: parsenodes.h:299
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:4376
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#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:514
Definition: nodes.h:283
#define Int32GetDatum(X)
Definition: postgres.h:485
#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:288
long val
Definition: informix.c:689
#define GUC_LIST_INPUT
Definition: guc.h:204
Node * arg
Definition: parsenodes.h:298
struct config_generic** get_guc_variables ( void  )

Definition at line 4191 of file guc.c.

References guc_variables.

Referenced by GucInfoMain().

4192 {
4193  return guc_variables;
4194 }
static struct config_generic ** guc_variables
Definition: guc.c:3939
const char* GetConfigOption ( const char *  name,
bool  missing_ok,
bool  restrict_superuser 
)

Definition at line 6700 of file guc.c.

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

Referenced by applyRemoteGucs(), and PostmasterMain().

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

Definition at line 8039 of file guc.c.

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

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

8040 {
8041  struct config_generic *record;
8042 
8043  record = find_option(name, false, ERROR);
8044  if (record == NULL)
8045  {
8046  if (missing_ok)
8047  {
8048  if (varname)
8049  *varname = NULL;
8050  return NULL;
8051  }
8052 
8053  ereport(ERROR,
8054  (errcode(ERRCODE_UNDEFINED_OBJECT),
8055  errmsg("unrecognized configuration parameter \"%s\"", name)));
8056  }
8057 
8058  if ((record->flags & GUC_SUPERUSER_ONLY) &&
8060  ereport(ERROR,
8061  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
8062  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
8063  name)));
8064 
8065  if (varname)
8066  *varname = record->name;
8067 
8068  return _ShowOption(record, true);
8069 }
static char * _ShowOption(struct config_generic *record, bool use_units)
Definition: guc.c:8637
Oid GetUserId(void)
Definition: miscinit.c:283
const char * name
Definition: guc_tables.h:146
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4837
#define DEFAULT_ROLE_READ_ALL_SETTINGS
Definition: pg_authid.h:111
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4376
#define NULL
Definition: c.h:229
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797
void GetConfigOptionByNum ( int  varnum,
const char **  values,
bool noshow 
)

Definition at line 8076 of file guc.c.

References _ShowOption(), Assert, config_bool::boot_val, config_int::boot_val, config_real::boot_val, config_string::boot_val, config_enum::boot_val, buffer, config_enum_get_options(), config_enum_lookup_by_value(), config_generic::context, DEFAULT_ROLE_READ_ALL_SETTINGS, elog, ERROR, config_generic::flags, GetUserId(), config_generic::group, GUC_NO_SHOW_ALL, GUC_PENDING_RESTART, GUC_SUPERUSER_ONLY, GUC_UNIT_BLOCKS, GUC_UNIT_KB, GUC_UNIT_MB, GUC_UNIT_MEMORY, GUC_UNIT_MIN, GUC_UNIT_MS, GUC_UNIT_S, GUC_UNIT_TIME, GUC_UNIT_XBLOCKS, is_member_of_role(), config_generic::long_desc, config_int::max, config_real::max, config_int::min, config_real::min, config_generic::name, NULL, PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_S_FILE, PGC_STRING, pstrdup(), config_bool::reset_val, config_int::reset_val, config_real::reset_val, config_string::reset_val, config_enum::reset_val, config_generic::short_desc, snprintf(), config_generic::source, config_generic::sourcefile, config_generic::sourceline, config_generic::status, superuser(), and config_generic::vartype.

Referenced by show_all_settings().

8077 {
8078  char buffer[256];
8079  struct config_generic *conf;
8080 
8081  /* check requested variable number valid */
8082  Assert((varnum >= 0) && (varnum < num_guc_variables));
8083 
8084  conf = guc_variables[varnum];
8085 
8086  if (noshow)
8087  {
8088  if ((conf->flags & GUC_NO_SHOW_ALL) ||
8089  ((conf->flags & GUC_SUPERUSER_ONLY) &&
8091  *noshow = true;
8092  else
8093  *noshow = false;
8094  }
8095 
8096  /* first get the generic attributes */
8097 
8098  /* name */
8099  values[0] = conf->name;
8100 
8101  /* setting : use _ShowOption in order to avoid duplicating the logic */
8102  values[1] = _ShowOption(conf, false);
8103 
8104  /* unit */
8105  if (conf->vartype == PGC_INT)
8106  {
8107  switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
8108  {
8109  case GUC_UNIT_KB:
8110  values[2] = "kB";
8111  break;
8112  case GUC_UNIT_MB:
8113  values[2] = "MB";
8114  break;
8115  case GUC_UNIT_BLOCKS:
8116  snprintf(buffer, sizeof(buffer), "%dkB", BLCKSZ / 1024);
8117  values[2] = pstrdup(buffer);
8118  break;
8119  case GUC_UNIT_XBLOCKS:
8120  snprintf(buffer, sizeof(buffer), "%dkB", XLOG_BLCKSZ / 1024);
8121  values[2] = pstrdup(buffer);
8122  break;
8123  case GUC_UNIT_MS:
8124  values[2] = "ms";
8125  break;
8126  case GUC_UNIT_S:
8127  values[2] = "s";
8128  break;
8129  case GUC_UNIT_MIN:
8130  values[2] = "min";
8131  break;
8132  case 0:
8133  values[2] = NULL;
8134  break;
8135  default:
8136  elog(ERROR, "unrecognized GUC units value: %d",
8137  conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME));
8138  values[2] = NULL;
8139  break;
8140  }
8141  }
8142  else
8143  values[2] = NULL;
8144 
8145  /* group */
8146  values[3] = config_group_names[conf->group];
8147 
8148  /* short_desc */
8149  values[4] = conf->short_desc;
8150 
8151  /* extra_desc */
8152  values[5] = conf->long_desc;
8153 
8154  /* context */
8155  values[6] = GucContext_Names[conf->context];
8156 
8157  /* vartype */
8158  values[7] = config_type_names[conf->vartype];
8159 
8160  /* source */
8161  values[8] = GucSource_Names[conf->source];
8162 
8163  /* now get the type specific attributes */
8164  switch (conf->vartype)
8165  {
8166  case PGC_BOOL:
8167  {
8168  struct config_bool *lconf = (struct config_bool *) conf;
8169 
8170  /* min_val */
8171  values[9] = NULL;
8172 
8173  /* max_val */
8174  values[10] = NULL;
8175 
8176  /* enumvals */
8177  values[11] = NULL;
8178 
8179  /* boot_val */
8180  values[12] = pstrdup(lconf->boot_val ? "on" : "off");
8181 
8182  /* reset_val */
8183  values[13] = pstrdup(lconf->reset_val ? "on" : "off");
8184  }
8185  break;
8186 
8187  case PGC_INT:
8188  {
8189  struct config_int *lconf = (struct config_int *) conf;
8190 
8191  /* min_val */
8192  snprintf(buffer, sizeof(buffer), "%d", lconf->min);
8193  values[9] = pstrdup(buffer);
8194 
8195  /* max_val */
8196  snprintf(buffer, sizeof(buffer), "%d", lconf->max);
8197  values[10] = pstrdup(buffer);
8198 
8199  /* enumvals */
8200  values[11] = NULL;
8201 
8202  /* boot_val */
8203  snprintf(buffer, sizeof(buffer), "%d", lconf->boot_val);
8204  values[12] = pstrdup(buffer);
8205 
8206  /* reset_val */
8207  snprintf(buffer, sizeof(buffer), "%d", lconf->reset_val);
8208  values[13] = pstrdup(buffer);
8209  }
8210  break;
8211 
8212  case PGC_REAL:
8213  {
8214  struct config_real *lconf = (struct config_real *) conf;
8215 
8216  /* min_val */
8217  snprintf(buffer, sizeof(buffer), "%g", lconf->min);
8218  values[9] = pstrdup(buffer);
8219 
8220  /* max_val */
8221  snprintf(buffer, sizeof(buffer), "%g", lconf->max);
8222  values[10] = pstrdup(buffer);
8223 
8224  /* enumvals */
8225  values[11] = NULL;
8226 
8227  /* boot_val */
8228  snprintf(buffer, sizeof(buffer), "%g", lconf->boot_val);
8229  values[12] = pstrdup(buffer);
8230 
8231  /* reset_val */
8232  snprintf(buffer, sizeof(buffer), "%g", lconf->reset_val);
8233  values[13] = pstrdup(buffer);
8234  }
8235  break;
8236 
8237  case PGC_STRING:
8238  {
8239  struct config_string *lconf = (struct config_string *) conf;
8240 
8241  /* min_val */
8242  values[9] = NULL;
8243 
8244  /* max_val */
8245  values[10] = NULL;
8246 
8247  /* enumvals */
8248  values[11] = NULL;
8249 
8250  /* boot_val */
8251  if (lconf->boot_val == NULL)
8252  values[12] = NULL;
8253  else
8254  values[12] = pstrdup(lconf->boot_val);
8255 
8256  /* reset_val */
8257  if (lconf->reset_val == NULL)
8258  values[13] = NULL;
8259  else
8260  values[13] = pstrdup(lconf->reset_val);
8261  }
8262  break;
8263 
8264  case PGC_ENUM:
8265  {
8266  struct config_enum *lconf = (struct config_enum *) conf;
8267 
8268  /* min_val */
8269  values[9] = NULL;
8270 
8271  /* max_val */
8272  values[10] = NULL;
8273 
8274  /* enumvals */
8275 
8276  /*
8277  * NOTE! enumvals with double quotes in them are not
8278  * supported!
8279  */
8280  values[11] = config_enum_get_options((struct config_enum *) conf,
8281  "{\"", "\"}", "\",\"");
8282 
8283  /* boot_val */
8284  values[12] =