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

Go to the source code of this file.

Data Structures

struct  unit_conversion
 

Macros

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

Functions

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

Variables

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

Macro Definition Documentation

#define CONFIG_FILENAME   "postgresql.conf"

Definition at line 96 of file guc.c.

Referenced by SelectConfigFiles().

#define HBA_FILENAME   "pg_hba.conf"

Definition at line 97 of file guc.c.

Referenced by SelectConfigFiles().

#define IDENT_FILENAME   "pg_ident.conf"

Definition at line 98 of file guc.c.

Referenced by SelectConfigFiles().

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

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

Referenced by show_all_settings().

#define PG_KRB_SRVTAB   ""

Definition at line 93 of file guc.c.

#define REALTYPE_PRECISION   17

Definition at line 109 of file guc.c.

Referenced by estimate_variable_size(), and serialize_variable().

Function Documentation

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

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

8609 {
8610  char buffer[256];
8611  const char *val;
8612 
8613  switch (record->vartype)
8614  {
8615  case PGC_BOOL:
8616  {
8617  struct config_bool *conf = (struct config_bool *) record;
8618 
8619  if (conf->show_hook)
8620  val = (*conf->show_hook) ();
8621  else
8622  val = *conf->variable ? "on" : "off";
8623  }
8624  break;
8625 
8626  case PGC_INT:
8627  {
8628  struct config_int *conf = (struct config_int *) record;
8629 
8630  if (conf->show_hook)
8631  val = (*conf->show_hook) ();
8632  else
8633  {
8634  /*
8635  * Use int64 arithmetic to avoid overflows in units
8636  * conversion.
8637  */
8638  int64 result = *conf->variable;
8639  const char *unit;
8640 
8641  if (use_units && result > 0 && (record->flags & GUC_UNIT))
8642  {
8643  convert_from_base_unit(result, record->flags & GUC_UNIT,
8644  &result, &unit);
8645  }
8646  else
8647  unit = "";
8648 
8649  snprintf(buffer, sizeof(buffer), INT64_FORMAT "%s",
8650  result, unit);
8651  val = buffer;
8652  }
8653  }
8654  break;
8655 
8656  case PGC_REAL:
8657  {
8658  struct config_real *conf = (struct config_real *) record;
8659 
8660  if (conf->show_hook)
8661  val = (*conf->show_hook) ();
8662  else
8663  {
8664  snprintf(buffer, sizeof(buffer), "%g",
8665  *conf->variable);
8666  val = buffer;
8667  }
8668  }
8669  break;
8670 
8671  case PGC_STRING:
8672  {
8673  struct config_string *conf = (struct config_string *) record;
8674 
8675  if (conf->show_hook)
8676  val = (*conf->show_hook) ();
8677  else if (*conf->variable && **conf->variable)
8678  val = *conf->variable;
8679  else
8680  val = "";
8681  }
8682  break;
8683 
8684  case PGC_ENUM:
8685  {
8686  struct config_enum *conf = (struct config_enum *) record;
8687 
8688  if (conf->show_hook)
8689  val = (*conf->show_hook) ();
8690  else
8691  val = config_enum_lookup_by_value(conf, *conf->variable);
8692  }
8693  break;
8694 
8695  default:
8696  /* just to keep compiler quiet */
8697  val = "???";
8698  break;
8699  }
8700 
8701  return pstrdup(val);
8702 }
char ** variable
Definition: guc_tables.h:226
char * pstrdup(const char *in)
Definition: mcxt.c:1077
bool * variable
Definition: guc_tables.h:180
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5596
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:200
int * variable
Definition: guc_tables.h:194
int * variable
Definition: guc_tables.h:240
GucShowHook show_hook
Definition: guc_tables.h:230
GucShowHook show_hook
Definition: guc_tables.h:216
double * variable
Definition: guc_tables.h:210
enum config_type vartype
Definition: guc_tables.h:152
GucShowHook show_hook
Definition: guc_tables.h:245
GucShowHook show_hook
Definition: guc_tables.h:184
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:5424
long val
Definition: informix.c:689
static bool add_guc_variable ( struct config_generic var,
int  elevel 
)
static

Definition at line 4265 of file guc.c.

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

Referenced by add_placeholder_variable(), and define_custom_variable().

4266 {
4268  {
4269  /*
4270  * Increase the vector by 25%
4271  */
4272  int size_vars = size_guc_variables + size_guc_variables / 4;
4273  struct config_generic **guc_vars;
4274 
4275  if (size_vars == 0)
4276  {
4277  size_vars = 100;
4278  guc_vars = (struct config_generic **)
4279  guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
4280  }
4281  else
4282  {
4283  guc_vars = (struct config_generic **)
4284  guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
4285  }
4286 
4287  if (guc_vars == NULL)
4288  return false; /* out of memory */
4289 
4290  guc_variables = guc_vars;
4291  size_guc_variables = size_vars;
4292  }
4295  sizeof(struct config_generic *), guc_var_compare);
4296  return true;
4297 }
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:4400
static int num_guc_variables
Definition: guc.c:3917
static void * guc_realloc(int elevel, void *old, size_t size)
Definition: guc.c:3971
static struct config_generic ** guc_variables
Definition: guc.c:3914
static int size_guc_variables
Definition: guc.c:3920
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:3955
static struct config_generic* add_placeholder_variable ( const char *  name,
int  elevel 
)
static

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

4304 {
4305  size_t sz = sizeof(struct config_string) + sizeof(char *);
4306  struct config_string *var;
4307  struct config_generic *gen;
4308 
4309  var = (struct config_string *) guc_malloc(elevel, sz);
4310  if (var == NULL)
4311  return NULL;
4312  memset(var, 0, sz);
4313  gen = &var->gen;
4314 
4315  gen->name = guc_strdup(elevel, name);
4316  if (gen->name == NULL)
4317  {
4318  free(var);
4319  return NULL;
4320  }
4321 
4322  gen->context = PGC_USERSET;
4323  gen->group = CUSTOM_OPTIONS;
4324  gen->short_desc = "GUC placeholder variable";
4326  gen->vartype = PGC_STRING;
4327 
4328  /*
4329  * The char* is allocated at the end of the struct since we have no
4330  * 'static' place to point to. Note that the current value, as well as
4331  * the boot and reset values, start out NULL.
4332  */
4333  var->variable = (char **) (var + 1);
4334 
4335  if (!add_guc_variable((struct config_generic *) var, elevel))
4336  {
4337  free((void *) gen->name);
4338  free(var);
4339  return NULL;
4340  }
4341 
4342  return gen;
4343 }
char ** variable
Definition: guc_tables.h:226
const char * name
Definition: guc_tables.h:145
const char * short_desc
Definition: guc_tables.h:148
static char * guc_strdup(int elevel, const char *src)
Definition: guc.c:3987
#define GUC_NO_SHOW_ALL
Definition: guc.h:206
#define GUC_NOT_IN_SAMPLE
Definition: guc.h:209
enum config_type vartype
Definition: guc_tables.h:152
static int elevel
Definition: vacuumlazy.c:137
struct config_generic gen
Definition: guc_tables.h:224
#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:147
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:3955
GucContext context
Definition: guc_tables.h:146
static bool add_guc_variable(struct config_generic *var, int elevel)
Definition: guc.c:4265
void AlterSystemSetConfigFile ( AlterSystemStmt altersysstmt)

Definition at line 7046 of file guc.c.

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

Referenced by standard_ProcessUtility().

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

Definition at line 10438 of file guc.c.

References pgstat_report_appname().

10439 {
10440  /* Update the pg_stat_activity view */
10442 }
void pgstat_report_appname(const char *appname)
Definition: pgstat.c:2975
#define newval
static void assign_effective_io_concurrency ( int  newval,
void *  extra 
)
static

Definition at line 10386 of file guc.c.

References target_prefetch_pages.

10387 {
10388 #ifdef USE_PREFETCH
10389  target_prefetch_pages = *((int *) extra);
10390 #endif /* USE_PREFETCH */
10391 }
int target_prefetch_pages
Definition: bufmgr.c:129
static void assign_log_destination ( const char *  newval,
void *  extra 
)
static

Definition at line 10074 of file guc.c.

References Log_destination.

10075 {
10076  Log_destination = *((int *) extra);
10077 }
int Log_destination
Definition: elog.c:106
static void assign_pgstat_temp_directory ( const char *  newval,
void *  extra 
)
static

Definition at line 10394 of file guc.c.

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

10395 {
10396  /* check_canonical_path already canonicalized newval for us */
10397  char *dname;
10398  char *tname;
10399  char *fname;
10400 
10401  /* directory */
10402  dname = guc_malloc(ERROR, strlen(newval) + 1); /* runtime dir */
10403  sprintf(dname, "%s", newval);
10404 
10405  /* global stats */
10406  tname = guc_malloc(ERROR, strlen(newval) + 12); /* /global.tmp */
10407  sprintf(tname, "%s/global.tmp", newval);
10408  fname = guc_malloc(ERROR, strlen(newval) + 13); /* /global.stat */
10409  sprintf(fname, "%s/global.stat", newval);
10410 
10413  pgstat_stat_directory = dname;
10414  if (pgstat_stat_tmpname)
10416  pgstat_stat_tmpname = tname;
10419  pgstat_stat_filename = fname;
10420 }
char * pgstat_stat_filename
Definition: pgstat.c:119
#define ERROR
Definition: elog.h:43
char * pgstat_stat_directory
Definition: pgstat.c:118
#define free(a)
Definition: header.h:65
#define newval
char * pgstat_stat_tmpname
Definition: pgstat.c:120
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:3955
static void assign_session_replication_role ( int  newval,
void *  extra 
)
static

Definition at line 10100 of file guc.c.

References ResetPlanCache(), and SessionReplicationRole.

10101 {
10102  /*
10103  * Must flush the plan cache when changing replication role; but don't
10104  * flush unnecessarily.
10105  */
10107  ResetPlanCache();
10108 }
int SessionReplicationRole
Definition: trigger.c:64
void ResetPlanCache(void)
Definition: plancache.c:1855
#define newval
static void assign_syslog_facility ( int  newval,
void *  extra 
)
static

Definition at line 10080 of file guc.c.

10081 {
10082 #ifdef HAVE_SYSLOG
10083  set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
10084  newval);
10085 #endif
10086  /* Without syslog support, just ignore it */
10087 }
static char * syslog_ident_str
Definition: guc.c:497
#define newval
static void assign_syslog_ident ( const char *  newval,
void *  extra 
)
static

Definition at line 10090 of file guc.c.

10091 {
10092 #ifdef HAVE_SYSLOG
10093  set_syslog_parameters(newval, syslog_facility);
10094 #endif
10095  /* Without syslog support, it will always be set to "none", so ignore */
10096 }
static int syslog_facility
Definition: guc.c:159
#define newval
static void assign_tcp_keepalives_count ( int  newval,
void *  extra 
)
static

Definition at line 10299 of file guc.c.

References MyProcPort, and pq_setkeepalivescount().

10300 {
10301  /* See comments in assign_tcp_keepalives_idle */
10303 }
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 10255 of file guc.c.

References MyProcPort, and pq_setkeepalivesidle().

10256 {
10257  /*
10258  * The kernel API provides no way to test a value without setting it; and
10259  * once we set it we might fail to unset it. So there seems little point
10260  * in fully implementing the check-then-assign GUC API for these
10261  * variables. Instead we just do the assignment on demand. pqcomm.c
10262  * reports any problems via elog(LOG).
10263  *
10264  * This approach means that the GUC value might have little to do with the
10265  * actual kernel value, so we use a show_hook that retrieves the kernel
10266  * value rather than trusting GUC's copy.
10267  */
10269 }
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 10282 of file guc.c.

References MyProcPort, and pq_setkeepalivesinterval().

10283 {
10284  /* See comments in assign_tcp_keepalives_idle */
10286 }
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 10219 of file guc.c.

References InstallTimeZoneAbbrevs().

10220 {
10221  /* Do nothing for the boot_val default of NULL */
10222  if (!extra)
10223  return;
10224 
10226 }
void InstallTimeZoneAbbrevs(TimeZoneAbbrevTable *tbl)
Definition: datetime.c:4603
static void assign_wal_consistency_checking ( const char *  newval,
void *  extra 
)
static

Definition at line 10011 of file guc.c.

References wal_consistency_checking.

10012 {
10013  wal_consistency_checking = (bool *) extra;
10014 }
bool * wal_consistency_checking
Definition: xlog.c:101
void AtEOXact_GUC ( bool  isCommit,
int  nestLevel 
)

Definition at line 5058 of file guc.c.

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

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

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

Definition at line 5024 of file guc.c.

References elog, and WARNING.

Referenced by StartTransaction().

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

Definition at line 5339 of file guc.c.

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

Referenced by PostgresMain().

5340 {
5341  int i;
5342 
5343  /*
5344  * Don't do anything unless talking to an interactive frontend of protocol
5345  * 3.0 or later.
5346  */
5347  if (whereToSendOutput != DestRemote ||
5349  return;
5350 
5351  reporting_enabled = true;
5352 
5353  /* Transmit initial values of interesting variables */
5354  for (i = 0; i < num_guc_variables; i++)
5355  {
5356  struct config_generic *conf = guc_variables[i];
5357 
5358  if (conf->flags & GUC_REPORT)
5359  ReportGUCOption(conf);
5360  }
5361 }
#define PG_PROTOCOL_MAJOR(v)
Definition: pqcomm.h:104
static int num_guc_variables
Definition: guc.c:3917
#define GUC_REPORT
Definition: guc.h:208
static struct config_generic ** guc_variables
Definition: guc.c:3914
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:5367
CommandDest whereToSendOutput
Definition: postgres.c:86
static bool reporting_enabled
Definition: guc.c:3925
ProtocolVersion FrontendProtocol
Definition: globals.c:27
void build_guc_variables ( void  )

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

4179 {
4180  int size_vars;
4181  int num_vars = 0;
4182  struct config_generic **guc_vars;
4183  int i;
4184 
4185  for (i = 0; ConfigureNamesBool[i].gen.name; i++)
4186  {
4187  struct config_bool *conf = &ConfigureNamesBool[i];
4188 
4189  /* Rather than requiring vartype to be filled in by hand, do this: */
4190  conf->gen.vartype = PGC_BOOL;
4191  num_vars++;
4192  }
4193 
4194  for (i = 0; ConfigureNamesInt[i].gen.name; i++)
4195  {
4196  struct config_int *conf = &ConfigureNamesInt[i];
4197 
4198  conf->gen.vartype = PGC_INT;
4199  num_vars++;
4200  }
4201 
4202  for (i = 0; ConfigureNamesReal[i].gen.name; i++)
4203  {
4204  struct config_real *conf = &ConfigureNamesReal[i];
4205 
4206  conf->gen.vartype = PGC_REAL;
4207  num_vars++;
4208  }
4209 
4210  for (i = 0; ConfigureNamesString[i].gen.name; i++)
4211  {
4212  struct config_string *conf = &ConfigureNamesString[i];
4213 
4214  conf->gen.vartype = PGC_STRING;
4215  num_vars++;
4216  }
4217 
4218  for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
4219  {
4220  struct config_enum *conf = &ConfigureNamesEnum[i];
4221 
4222  conf->gen.vartype = PGC_ENUM;
4223  num_vars++;
4224  }
4225 
4226  /*
4227  * Create table with 20% slack
4228  */
4229  size_vars = num_vars + num_vars / 4;
4230 
4231  guc_vars = (struct config_generic **)
4232  guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
4233 
4234  num_vars = 0;
4235 
4236  for (i = 0; ConfigureNamesBool[i].gen.name; i++)
4237  guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
4238 
4239  for (i = 0; ConfigureNamesInt[i].gen.name; i++)
4240  guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
4241 
4242  for (i = 0; ConfigureNamesReal[i].gen.name; i++)
4243  guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
4244 
4245  for (i = 0; ConfigureNamesString[i].gen.name; i++)
4246  guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
4247 
4248  for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
4249  guc_vars[num_vars++] = &ConfigureNamesEnum[i].gen;
4250 
4251  if (guc_variables)
4253  guc_variables = guc_vars;
4254  num_guc_variables = num_vars;
4255  size_guc_variables = size_vars;
4257  sizeof(struct config_generic *), guc_var_compare);
4258 }
static struct config_int ConfigureNamesInt[]
Definition: guc.c:1677
const char * name
Definition: guc_tables.h:145
static struct config_enum ConfigureNamesEnum[]
Definition: guc.c:3628
static struct config_bool ConfigureNamesBool[]
Definition: guc.c:804
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:4400
static int num_guc_variables
Definition: guc.c:3917
#define FATAL
Definition: elog.h:52
struct config_generic gen
Definition: guc_tables.h:178
struct config_generic gen
Definition: guc_tables.h:192
static struct config_generic ** guc_variables
Definition: guc.c:3914
enum config_type vartype
Definition: guc_tables.h:152
static int size_guc_variables
Definition: guc.c:3920
static struct config_real ConfigureNamesReal[]
Definition: guc.c:2874
struct config_generic gen
Definition: guc_tables.h:238
struct config_generic gen
Definition: guc_tables.h:224
#define free(a)
Definition: header.h:65
static struct config_string ConfigureNamesString[]
Definition: guc.c:3035
int i
#define qsort(a, b, c, d)
Definition: port.h:440
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:3955
struct config_generic gen
Definition: guc_tables.h:208
static bool call_bool_check_hook ( struct config_bool conf,
bool newval,
void **  extra,
GucSource  source,
int  elevel 
)
static

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

9763 {
9764  /* Quick success if no hook */
9765  if (!conf->check_hook)
9766  return true;
9767 
9768  /* Reset variables that might be set by hook */
9769  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
9773 
9774  if (!(*conf->check_hook) (newval, extra, source))
9775  {
9776  ereport(elevel,
9780  errmsg("invalid value for parameter \"%s\": %d",
9781  conf->gen.name, (int) *newval),
9785  errhint("%s", GUC_check_errhint_string) : 0));
9786  /* Flush any strings created in ErrorContext */
9787  FlushErrorState();
9788  return false;
9789  }
9790 
9791  return true;
9792 }
char * GUC_check_errhint_string
Definition: guc.c:132
GucSource source
Definition: guc_tables.h:154
int errhint(const char *fmt,...)
Definition: elog.c:987
const char * name
Definition: guc_tables.h:145
int errcode(int sqlerrcode)
Definition: elog.c:575
static int GUC_check_errcode_value
Definition: guc.c:127
void FlushErrorState(void)
Definition: elog.c:1587
int errdetail_internal(const char *fmt,...)
Definition: elog.c:900
struct config_generic gen
Definition: guc_tables.h:178
char * GUC_check_errdetail_string
Definition: guc.c:131
#define ereport(elevel, rest)
Definition: elog.h:122
static int elevel
Definition: vacuumlazy.c:137
GucBoolCheckHook check_hook
Definition: guc_tables.h:182
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:130
int errmsg(const char *fmt,...)
Definition: elog.c:797
static bool call_enum_check_hook ( struct config_enum conf,
int *  newval,
void **  extra,
GucSource  source,
int  elevel 
)
static

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

9899 {
9900  /* Quick success if no hook */
9901  if (!conf->check_hook)
9902  return true;
9903 
9904  /* Reset variables that might be set by hook */
9905  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
9909 
9910  if (!(*conf->check_hook) (newval, extra, source))
9911  {
9912  ereport(elevel,
9916  errmsg("invalid value for parameter \"%s\": \"%s\"",
9917  conf->gen.name,
9922  errhint("%s", GUC_check_errhint_string) : 0));
9923  /* Flush any strings created in ErrorContext */
9924  FlushErrorState();
9925  return false;
9926  }
9927 
9928  return true;
9929 }
char * GUC_check_errhint_string
Definition: guc.c:132
GucSource source
Definition: guc_tables.h:154
GucEnumCheckHook check_hook
Definition: guc_tables.h:243
int errhint(const char *fmt,...)
Definition: elog.c:987
const char * name
Definition: guc_tables.h:145
int errcode(int sqlerrcode)
Definition: elog.c:575
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5596
static int GUC_check_errcode_value
Definition: guc.c:127
void FlushErrorState(void)
Definition: elog.c:1587
int errdetail_internal(const char *fmt,...)
Definition: elog.c:900
char * GUC_check_errdetail_string
Definition: guc.c:131
#define ereport(elevel, rest)
Definition: elog.h:122
static int elevel
Definition: vacuumlazy.c:137
struct config_generic gen
Definition: guc_tables.h:238
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:130
int errmsg(const char *fmt,...)
Definition: elog.c:797
static bool call_int_check_hook ( struct config_int conf,
int *  newval,
void **  extra,
GucSource  source,
int  elevel 
)
static

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

9797 {
9798  /* Quick success if no hook */
9799  if (!conf->check_hook)
9800  return true;
9801 
9802  /* Reset variables that might be set by hook */
9803  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
9807 
9808  if (!(*conf->check_hook) (newval, extra, source))
9809  {
9810  ereport(elevel,
9814  errmsg("invalid value for parameter \"%s\": %d",
9815  conf->gen.name, *newval),
9819  errhint("%s", GUC_check_errhint_string) : 0));
9820  /* Flush any strings created in ErrorContext */
9821  FlushErrorState();
9822  return false;
9823  }
9824 
9825  return true;
9826 }
char * GUC_check_errhint_string
Definition: guc.c:132
GucSource source
Definition: guc_tables.h:154
int errhint(const char *fmt,...)
Definition: elog.c:987
const char * name
Definition: guc_tables.h:145
int errcode(int sqlerrcode)
Definition: elog.c:575
static int GUC_check_errcode_value
Definition: guc.c:127
GucIntCheckHook check_hook
Definition: guc_tables.h:198
void FlushErrorState(void)
Definition: elog.c:1587
int errdetail_internal(const char *fmt,...)
Definition: elog.c:900
struct config_generic gen
Definition: guc_tables.h:192
char * GUC_check_errdetail_string
Definition: guc.c:131
#define ereport(elevel, rest)
Definition: elog.h:122
static int elevel
Definition: vacuumlazy.c: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:130
int errmsg(const char *fmt,...)
Definition: elog.c:797
static bool call_real_check_hook ( struct config_real conf,
double *  newval,
void **  extra,
GucSource  source,
int  elevel 
)
static

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

9831 {
9832  /* Quick success if no hook */
9833  if (!conf->check_hook)
9834  return true;
9835 
9836  /* Reset variables that might be set by hook */
9837  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
9841 
9842  if (!(*conf->check_hook) (newval, extra, source))
9843  {
9844  ereport(elevel,
9848  errmsg("invalid value for parameter \"%s\": %g",
9849  conf->gen.name, *newval),
9853  errhint("%s", GUC_check_errhint_string) : 0));
9854  /* Flush any strings created in ErrorContext */
9855  FlushErrorState();
9856  return false;
9857  }
9858 
9859  return true;
9860 }
char * GUC_check_errhint_string
Definition: guc.c:132
GucSource source
Definition: guc_tables.h:154
int errhint(const char *fmt,...)
Definition: elog.c:987
const char * name
Definition: guc_tables.h:145
int errcode(int sqlerrcode)
Definition: elog.c:575
static int GUC_check_errcode_value
Definition: guc.c:127
GucRealCheckHook check_hook
Definition: guc_tables.h:214
void FlushErrorState(void)
Definition: elog.c:1587
int errdetail_internal(const char *fmt,...)
Definition: elog.c:900
char * GUC_check_errdetail_string
Definition: guc.c:131
#define ereport(elevel, rest)
Definition: elog.h:122
static int elevel
Definition: vacuumlazy.c: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:130
int errmsg(const char *fmt,...)
Definition: elog.c:797
struct config_generic gen
Definition: guc_tables.h:208
static bool call_string_check_hook ( struct config_string conf,
char **  newval,
void **  extra,
GucSource  source,
int  elevel 
)
static

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

9865 {
9866  /* Quick success if no hook */
9867  if (!conf->check_hook)
9868  return true;
9869 
9870  /* Reset variables that might be set by hook */
9871  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
9875 
9876  if (!(*conf->check_hook) (newval, extra, source))
9877  {
9878  ereport(elevel,
9882  errmsg("invalid value for parameter \"%s\": \"%s\"",
9883  conf->gen.name, *newval ? *newval : ""),
9887  errhint("%s", GUC_check_errhint_string) : 0));
9888  /* Flush any strings created in ErrorContext */
9889  FlushErrorState();
9890  return false;
9891  }
9892 
9893  return true;
9894 }
char * GUC_check_errhint_string
Definition: guc.c:132
GucSource source
Definition: guc_tables.h:154
int errhint(const char *fmt,...)
Definition: elog.c:987
const char * name
Definition: guc_tables.h:145
GucStringCheckHook check_hook
Definition: guc_tables.h:228
int errcode(int sqlerrcode)
Definition: elog.c:575
static int GUC_check_errcode_value
Definition: guc.c:127
void FlushErrorState(void)
Definition: elog.c:1587
int errdetail_internal(const char *fmt,...)
Definition: elog.c:900
char * GUC_check_errdetail_string
Definition: guc.c:131
#define ereport(elevel, rest)
Definition: elog.h:122
static int elevel
Definition: vacuumlazy.c:137
struct config_generic gen
Definition: guc_tables.h:224
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:130
int errmsg(const char *fmt,...)
Definition: elog.c:797
static bool can_skip_gucvar ( struct config_generic gconf)
static

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

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

Definition at line 10423 of file guc.c.

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

Definition at line 10325 of file guc.c.

References MAX_BACKENDS, max_worker_processes, and MaxConnections.

10326 {
10328  return false;
10329  return true;
10330 }
#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 10333 of file guc.c.

10334 {
10335  /*
10336  * -1 indicates fallback.
10337  *
10338  * If we haven't yet changed the boot_val default of -1, just let it be.
10339  * Autovacuum will look to maintenance_work_mem instead.
10340  */
10341  if (*newval == -1)
10342  return true;
10343 
10344  /*
10345  * We clamp manually-set values to at least 1MB. Since
10346  * maintenance_work_mem is always set to at least this value, do the same
10347  * here.
10348  */
10349  if (*newval < 1024)
10350  *newval = 1024;
10351 
10352  return true;
10353 }
#define newval
static bool check_bonjour ( bool newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10125 of file guc.c.

References GUC_check_errmsg.

10126 {
10127 #ifndef USE_BONJOUR
10128  if (*newval)
10129  {
10130  GUC_check_errmsg("Bonjour is not supported by this build");
10131  return false;
10132  }
10133 #endif
10134  return true;
10135 }
#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 10176 of file guc.c.

References canonicalize_path().

10177 {
10178  /*
10179  * Since canonicalize_path never enlarges the string, we can just modify
10180  * newval in-place. But watch out for NULL, which is the default value
10181  * for external_pid_file.
10182  */
10183  if (*newval)
10185  return true;
10186 }
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 10445 of file guc.c.

10446 {
10447  /* Only allow clean ASCII chars in the cluster name */
10448  char *p;
10449 
10450  for (p = *newval; *p; p++)
10451  {
10452  if (*p < 32 || *p > 126)
10453  *p = '?';
10454  }
10455 
10456  return true;
10457 }
#define newval
static bool check_effective_io_concurrency ( int *  newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10364 of file guc.c.

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

10365 {
10366 #ifdef USE_PREFETCH
10367  double new_prefetch_pages;
10368 
10369  if (ComputeIoConcurrency(*newval, &new_prefetch_pages))
10370  {
10371  int *myextra = (int *) guc_malloc(ERROR, sizeof(int));
10372 
10373  *myextra = (int) rint(new_prefetch_pages);
10374  *extra = (void *) myextra;
10375 
10376  return true;
10377  }
10378  else
10379  return false;
10380 #else
10381  return true;
10382 #endif /* USE_PREFETCH */
10383 }
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:3955
static bool check_log_destination ( char **  newval,
void **  extra,
GucSource  source 
)
static

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

10018 {
10019  char *rawstring;
10020  List *elemlist;
10021  ListCell *l;
10022  int newlogdest = 0;
10023  int *myextra;
10024 
10025  /* Need a modifiable copy of string */
10026  rawstring = pstrdup(*newval);
10027 
10028  /* Parse string into list of identifiers */
10029  if (!SplitIdentifierString(rawstring, ',', &elemlist))
10030  {
10031  /* syntax error in list */
10032  GUC_check_errdetail("List syntax is invalid.");
10033  pfree(rawstring);
10034  list_free(elemlist);
10035  return false;
10036  }
10037 
10038  foreach(l, elemlist)
10039  {
10040  char *tok = (char *) lfirst(l);
10041 
10042  if (pg_strcasecmp(tok, "stderr") == 0)
10043  newlogdest |= LOG_DESTINATION_STDERR;
10044  else if (pg_strcasecmp(tok, "csvlog") == 0)
10045  newlogdest |= LOG_DESTINATION_CSVLOG;
10046 #ifdef HAVE_SYSLOG
10047  else if (pg_strcasecmp(tok, "syslog") == 0)
10048  newlogdest |= LOG_DESTINATION_SYSLOG;
10049 #endif
10050 #ifdef WIN32
10051  else if (pg_strcasecmp(tok, "eventlog") == 0)
10052  newlogdest |= LOG_DESTINATION_EVENTLOG;
10053 #endif
10054  else
10055  {
10056  GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
10057  pfree(rawstring);
10058  list_free(elemlist);
10059  return false;
10060  }
10061  }
10062 
10063  pfree(rawstring);
10064  list_free(elemlist);
10065 
10066  myextra = (int *) guc_malloc(ERROR, sizeof(int));
10067  *myextra = newlogdest;
10068  *extra = (void *) myextra;
10069 
10070  return true;
10071 }
#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:3955
Definition: pg_list.h:45
static bool check_log_stats ( bool newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10162 of file guc.c.

References GUC_check_errdetail.

10163 {
10164  if (*newval &&
10166  {
10167  GUC_check_errdetail("Cannot enable \"log_statement_stats\" when "
10168  "\"log_parser_stats\", \"log_planner_stats\", "
10169  "or \"log_executor_stats\" is true.");
10170  return false;
10171  }
10172  return true;
10173 }
bool log_parser_stats
Definition: guc.c:441
#define GUC_check_errdetail
Definition: guc.h:407
#define newval
bool log_executor_stats
Definition: guc.c:443
bool log_planner_stats
Definition: guc.c:442
static bool check_max_worker_processes ( int *  newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10356 of file guc.c.

References autovacuum_max_workers, MAX_BACKENDS, and MaxConnections.

10357 {
10359  return false;
10360  return true;
10361 }
#define MAX_BACKENDS
Definition: postmaster.h:75
int MaxConnections
Definition: globals.c:123
int autovacuum_max_workers
Definition: autovacuum.c:111
#define newval
static bool check_maxconnections ( int *  newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10316 of file guc.c.

References autovacuum_max_workers, MAX_BACKENDS, and max_worker_processes.

10317 {
10318  if (*newval + autovacuum_max_workers + 1 +
10320  return false;
10321  return true;
10322 }
#define MAX_BACKENDS
Definition: postmaster.h:75
int autovacuum_max_workers
Definition: autovacuum.c:111
#define newval
int max_worker_processes
Definition: globals.c:124
static bool check_ssl ( bool newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10138 of file guc.c.

References GUC_check_errmsg.

10139 {
10140 #ifndef USE_SSL
10141  if (*newval)
10142  {
10143  GUC_check_errmsg("SSL is not supported by this build");
10144  return false;
10145  }
10146 #endif
10147  return true;
10148 }
#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 10151 of file guc.c.

References GUC_check_errdetail.

10152 {
10153  if (*newval && log_statement_stats)
10154  {
10155  GUC_check_errdetail("Cannot enable parameter when \"log_statement_stats\" is true.");
10156  return false;
10157  }
10158  return true;
10159 }
bool log_statement_stats
Definition: guc.c:444
#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 10111 of file guc.c.

References GUC_check_errdetail, and NLocBuffer.

10112 {
10113  /*
10114  * Once local buffers have been initialized, it's too late to change this.
10115  */
10116  if (NLocBuffer && NLocBuffer != *newval)
10117  {
10118  GUC_check_errdetail("\"temp_buffers\" cannot be changed after any temporary tables have been accessed in the session.");
10119  return false;
10120  }
10121  return true;
10122 }
#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 10189 of file guc.c.

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

10190 {
10191  /*
10192  * The boot_val given above for timezone_abbreviations is NULL. When we
10193  * see this we just do nothing. If this value isn't overridden from the
10194  * config file then pg_timezone_abbrev_initialize() will eventually
10195  * replace it with "Default". This hack has two purposes: to avoid
10196  * wasting cycles loading values that might soon be overridden from the
10197  * config file, and to avoid trying to read the timezone abbrev files
10198  * during InitializeGUCOptions(). The latter doesn't work in an
10199  * EXEC_BACKEND subprocess because my_exec_path hasn't been set yet and so
10200  * we can't locate PGSHAREDIR.
10201  */
10202  if (*newval == NULL)
10203  {
10205  return true;
10206  }
10207 
10208  /* OK, load the file and produce a malloc'd TimeZoneAbbrevTable */
10210 
10211  /* tzparser.c returns NULL on failure, reporting via GUC_check_errmsg */
10212  if (!*extra)
10213  return false;
10214 
10215  return true;
10216 }
GucSource source
Definition: guc_tables.h:154
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 9937 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().

9938 {
9939  char *rawstring;
9940  List *elemlist;
9941  ListCell *l;
9942  bool newwalconsistency[RM_MAX_ID + 1];
9943 
9944  /* Initialize the array */
9945  MemSet(newwalconsistency, 0, (RM_MAX_ID + 1) * sizeof(bool));
9946 
9947  /* Need a modifiable copy of string */
9948  rawstring = pstrdup(*newval);
9949 
9950  /* Parse string into list of identifiers */
9951  if (!SplitIdentifierString(rawstring, ',', &elemlist))
9952  {
9953  /* syntax error in list */
9954  GUC_check_errdetail("List syntax is invalid.");
9955  pfree(rawstring);
9956  list_free(elemlist);
9957  return false;
9958  }
9959 
9960  foreach(l, elemlist)
9961  {
9962  char *tok = (char *) lfirst(l);
9963  bool found = false;
9964  RmgrId rmid;
9965 
9966  /* Check for 'all'. */
9967  if (pg_strcasecmp(tok, "all") == 0)
9968  {
9969  for (rmid = 0; rmid <= RM_MAX_ID; rmid++)
9970  if (RmgrTable[rmid].rm_mask != NULL)
9971  newwalconsistency[rmid] = true;
9972  found = true;
9973  }
9974  else
9975  {
9976  /*
9977  * Check if the token matches with any individual resource
9978  * manager.
9979  */
9980  for (rmid = 0; rmid <= RM_MAX_ID; rmid++)
9981  {
9982  if (pg_strcasecmp(tok, RmgrTable[rmid].rm_name) == 0 &&
9983  RmgrTable[rmid].rm_mask != NULL)
9984  {
9985  newwalconsistency[rmid] = true;
9986  found = true;
9987  }
9988  }
9989  }
9990 
9991  /* If a valid resource manager is found, check for the next one. */
9992  if (!found)
9993  {
9994  GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
9995  pfree(rawstring);
9996  list_free(elemlist);
9997  return false;
9998  }
9999  }
10000 
10001  pfree(rawstring);
10002  list_free(elemlist);
10003 
10004  /* assign new value */
10005  *extra = guc_malloc(ERROR, (RM_MAX_ID + 1) * sizeof(bool));
10006  memcpy(*extra, newwalconsistency, (RM_MAX_ID + 1) * sizeof(bool));
10007  return true;
10008 }
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:3955
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 5645 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().

5647 {
5648  const struct config_enum_entry *entry;
5649  StringInfoData retstr;
5650  int seplen;
5651 
5652  initStringInfo(&retstr);
5653  appendStringInfoString(&retstr, prefix);
5654 
5655  seplen = strlen(separator);
5656  for (entry = record->options; entry && entry->name; entry++)
5657  {
5658  if (!entry->hidden)
5659  {
5660  appendStringInfoString(&retstr, entry->name);
5661  appendBinaryStringInfo(&retstr, separator, seplen);
5662  }
5663  }
5664 
5665  /*
5666  * All the entries may have been hidden, leaving the string empty if no
5667  * prefix was given. This indicates a broken GUC setup, since there is no
5668  * use for an enum without any values, so we just check to make sure we
5669  * don't write to invalid memory instead of actually trying to do
5670  * something smart with it.
5671  */
5672  if (retstr.len >= seplen)
5673  {
5674  /* Replace final separator */
5675  retstr.data[retstr.len - seplen] = '\0';
5676  retstr.len -= seplen;
5677  }
5678 
5679  appendStringInfoString(&retstr, suffix);
5680 
5681  return retstr.data;
5682 }
Definition: guc.h:164
const struct config_enum_entry * options
Definition: guc_tables.h:242
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:189
void initStringInfo(StringInfo str)
Definition: stringinfo.c:65
const char * name
Definition: guc.h:166
void appendBinaryStringInfo(StringInfo str, const char *data, int datalen)
Definition: stringinfo.c:240
bool hidden
Definition: guc.h:168
bool config_enum_lookup_by_name ( struct config_enum record,
const char *  value,
int *  retval 
)

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

5621 {
5622  const struct config_enum_entry *entry;
5623 
5624  for (entry = record->options; entry && entry->name; entry++)
5625  {
5626  if (pg_strcasecmp(value, entry->name) == 0)
5627  {
5628  *retval = entry->val;
5629  return TRUE;
5630  }
5631  }
5632 
5633  *retval = 0;
5634  return FALSE;
5635 }
static struct @78 value
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:242
int val
Definition: guc.h:167
const char * name
Definition: guc.h:166
#define TRUE
Definition: c.h:217
const char* config_enum_lookup_by_value ( struct config_enum record,
int  val 
)

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

5597 {
5598  const struct config_enum_entry *entry;
5599 
5600  for (entry = record->options; entry && entry->name; entry++)
5601  {
5602  if (entry->val == val)
5603  return entry->name;
5604  }
5605 
5606  elog(ERROR, "could not find enum option %d for %s",
5607  val, record->gen.name);
5608  return NULL; /* silence compiler */
5609 }
Definition: guc.h:164
const char * name
Definition: guc_tables.h:145
#define ERROR
Definition: elog.h:43
const struct config_enum_entry * options
Definition: guc_tables.h:242
int val
Definition: guc.h:167
struct config_generic gen
Definition: guc_tables.h:238
#define NULL
Definition: c.h: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 5424 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().

5426 {
5427  const unit_conversion *table;
5428  int i;
5429 
5430  *unit = NULL;
5431 
5432  if (base_unit & GUC_UNIT_MEMORY)
5434  else
5436 
5437  for (i = 0; *table[i].unit; i++)
5438  {
5439  if (base_unit == table[i].base_unit)
5440  {
5441  /*
5442  * Accept the first conversion that divides the value evenly. We
5443  * assume that the conversions for each base unit are ordered from
5444  * greatest unit to the smallest!
5445  */
5446  if (table[i].multiplier < 0)
5447  {
5448  *value = base_value * (-table[i].multiplier);
5449  *unit = table[i].unit;
5450  break;
5451  }
5452  else if (base_value % table[i].multiplier == 0)
5453  {
5454  *value = base_value / table[i].multiplier;
5455  *unit = table[i].unit;
5456  break;
5457  }
5458  }
5459  }
5460 
5461  Assert(*unit != NULL);
5462 }
static const unit_conversion time_unit_conversion_table[]
Definition: guc.c:751
static const unit_conversion memory_unit_conversion_table[]
Definition: guc.c:724
static struct @78 value
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
int i
char unit[MAX_UNIT_LEN+1]
Definition: guc.c:703
#define GUC_UNIT_MEMORY
Definition: guc.h:222
int multiplier
Definition: guc.c:706
static bool convert_to_base_unit ( int64  value,
const char *  unit,
int  base_unit,
int64 *  base_value 
)
static

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

5393 {
5394  const unit_conversion *table;
5395  int i;
5396 
5397  if (base_unit & GUC_UNIT_MEMORY)
5399  else
5401 
5402  for (i = 0; *table[i].unit; i++)
5403  {
5404  if (base_unit == table[i].base_unit &&
5405  strcmp(unit, table[i].unit) == 0)
5406  {
5407  if (table[i].multiplier < 0)
5408  *base_value = value / (-table[i].multiplier);
5409  else
5410  *base_value = value * table[i].multiplier;
5411  return true;
5412  }
5413  }
5414  return false;
5415 }
static const unit_conversion time_unit_conversion_table[]
Definition: guc.c:751
static const unit_conversion memory_unit_conversion_table[]
Definition: guc.c:724
static struct @78 value
int i
char unit[MAX_UNIT_LEN+1]
Definition: guc.c:703
#define GUC_UNIT_MEMORY
Definition: guc.h:222
int multiplier
Definition: guc.c:706
static void define_custom_variable ( struct config_generic variable)
static

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

7525 {
7526  const char *name = variable->name;
7527  const char **nameAddr = &name;
7528  struct config_string *pHolder;
7529  struct config_generic **res;
7530 
7531  /*
7532  * See if there's a placeholder by the same name.
7533  */
7534  res = (struct config_generic **) bsearch((void *) &nameAddr,
7535  (void *) guc_variables,
7537  sizeof(struct config_generic *),
7538  guc_var_compare);
7539  if (res == NULL)
7540  {
7541  /*
7542  * No placeholder to replace, so we can just add it ... but first,
7543  * make sure it's initialized to its default value.
7544  */
7545  InitializeOneGUCOption(variable);
7546  add_guc_variable(variable, ERROR);
7547  return;
7548  }
7549 
7550  /*
7551  * This better be a placeholder
7552  */
7553  if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
7554  ereport(ERROR,
7555  (errcode(ERRCODE_INTERNAL_ERROR),
7556  errmsg("attempt to redefine parameter \"%s\"", name)));
7557 
7558  Assert((*res)->vartype == PGC_STRING);
7559  pHolder = (struct config_string *) (*res);
7560 
7561  /*
7562  * First, set the variable to its default value. We must do this even
7563  * though we intend to immediately apply a new value, since it's possible
7564  * that the new value is invalid.
7565  */
7566  InitializeOneGUCOption(variable);
7567 
7568  /*
7569  * Replace the placeholder. We aren't changing the name, so no re-sorting
7570  * is necessary
7571  */
7572  *res = variable;
7573 
7574  /*
7575  * Assign the string value(s) stored in the placeholder to the real
7576  * variable. Essentially, we need to duplicate all the active and stacked
7577  * values, but with appropriate validation and datatype adjustment.
7578  *
7579  * If an assignment fails, we report a WARNING and keep going. We don't
7580  * want to throw ERROR for bad values, because it'd bollix the add-on
7581  * module that's presumably halfway through getting loaded. In such cases
7582  * the default or previous state will become active instead.
7583  */
7584 
7585  /* First, apply the reset value if any */
7586  if (pHolder->reset_val)
7587  (void) set_config_option(name, pHolder->reset_val,
7588  pHolder->gen.reset_scontext,
7589  pHolder->gen.reset_source,
7590  GUC_ACTION_SET, true, WARNING, false);
7591  /* That should not have resulted in stacking anything */
7592  Assert(variable->stack == NULL);
7593 
7594  /* Now, apply current and stacked values, in the order they were stacked */
7595  reapply_stacked_values(variable, pHolder, pHolder->gen.stack,
7596  *(pHolder->variable),
7597  pHolder->gen.scontext, pHolder->gen.source);
7598 
7599  /* Also copy over any saved source-location information */
7600  if (pHolder->gen.sourcefile)
7601  set_config_sourcefile(name, pHolder->gen.sourcefile,
7602  pHolder->gen.sourceline);
7603 
7604  /*
7605  * Free up as much as we conveniently can of the placeholder structure.
7606  * (This neglects any stack items, so it's possible for some memory to be
7607  * leaked. Since this can only happen once per session per variable, it
7608  * doesn't seem worth spending much code on.)
7609  */
7610  set_string_field(pHolder, pHolder->variable, NULL);
7611  set_string_field(pHolder, &pHolder->reset_val, NULL);
7612 
7613  free(pHolder);
7614 }
GucSource source
Definition: guc_tables.h:154
static void static void set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
Definition: guc.c:6617
char ** variable
Definition: guc_tables.h:226
const char * name
Definition: guc_tables.h:145
static void reapply_stacked_values(struct config_generic *variable, struct config_string *pHolder, GucStack *stack, const char *curvalue, GucContext curscontext, GucSource cursource)
Definition: guc.c:7624
int errcode(int sqlerrcode)
Definition: elog.c:575
GucContext scontext
Definition: guc_tables.h:156
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:4400
#define ERROR
Definition: elog.h:43
static int num_guc_variables
Definition: guc.c:3917
char * sourcefile
Definition: guc_tables.h:160
GucSource reset_source
Definition: guc_tables.h:155
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:4548
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4027
#define ereport(elevel, rest)
Definition: elog.h:122
static struct config_generic ** guc_variables
Definition: guc.c:3914
#define WARNING
Definition: elog.h:40
struct config_generic gen
Definition: guc_tables.h:224
#define free(a)
Definition: header.h:65
char * reset_val
Definition: guc_tables.h:232
#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:158
int set_config_option(const char *name, const char *value, GucContext context, GucSource source, GucAction action, bool changeVal, int elevel, bool is_reload)
Definition: guc.c:5887
static bool add_guc_variable(struct config_generic *var, int elevel)
Definition: guc.c:4265
GucContext reset_scontext
Definition: guc_tables.h:157
void DefineCustomBoolVariable ( const char *  name,
const char *  short_desc,
const char *  long_desc,
bool valueAddr,
bool  bootValue,
GucContext  context,
int  flags,
GucBoolCheckHook  check_hook,
GucBoolAssignHook  assign_hook,
GucShowHook  show_hook 
)

Definition at line 7705 of file guc.c.

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

Referenced by _PG_init().

7715 {
7716  struct config_bool *var;
7717 
7718  var = (struct config_bool *)
7719  init_custom_variable(name, short_desc, long_desc, context, flags,
7720  PGC_BOOL, sizeof(struct config_bool));
7721  var->variable = valueAddr;
7722  var->boot_val = bootValue;
7723  var->reset_val = bootValue;
7724  var->check_hook = check_hook;
7725  var->assign_hook = assign_hook;
7726  var->show_hook = show_hook;
7727  define_custom_variable(&var->gen);
7728 }
bool * variable
Definition: guc_tables.h:180
GucBoolAssignHook assign_hook
Definition: guc_tables.h:183
bool boot_val
Definition: guc_tables.h:181
struct config_generic gen
Definition: guc_tables.h:178
static struct config_generic * init_custom_variable(const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
Definition: guc.c:7473
GucBoolCheckHook check_hook
Definition: guc_tables.h:182
GucShowHook show_hook
Definition: guc_tables.h:184
const char * name
Definition: encode.c:521
bool reset_val
Definition: guc_tables.h:186
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7524
void DefineCustomEnumVariable ( const char *  name,
const char *  short_desc,
const char *  long_desc,
int *  valueAddr,
int  bootValue,
const struct config_enum_entry options,
GucContext  context,
int  flags,
GucEnumCheckHook  check_hook,
GucEnumAssignHook  assign_hook,
GucShowHook  show_hook 
)

Definition at line 7816 of file guc.c.

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

Referenced by _PG_init().

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

Definition at line 7731 of file guc.c.

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

Referenced by _PG_init().

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

Definition at line 7761 of file guc.c.

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

Referenced by _PG_init().

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

Definition at line 7791 of file guc.c.

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

Referenced by _PG_init().

7801 {
7802  struct config_string *var;
7803 
7804  var = (struct config_string *)
7805  init_custom_variable(name, short_desc, long_desc, context, flags,
7806  PGC_STRING, sizeof(struct config_string));
7807  var->variable = valueAddr;
7808  var->boot_val = bootValue;
7809  var->check_hook = check_hook;
7810  var->assign_hook = assign_hook;
7811  var->show_hook = show_hook;
7812  define_custom_variable(&var->gen);
7813 }
char ** variable
Definition: guc_tables.h:226
GucStringCheckHook check_hook
Definition: guc_tables.h:228
const char * boot_val
Definition: guc_tables.h:227
GucShowHook show_hook
Definition: guc_tables.h:230
static struct config_generic * init_custom_variable(const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
Definition: guc.c:7473
struct config_generic gen
Definition: guc_tables.h:224
GucStringAssignHook assign_hook
Definition: guc_tables.h:229
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7524
static void discard_stack_value ( struct config_generic gconf,
config_var_value val 
)
static

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

4143 {
4144  switch (gconf->vartype)
4145  {
4146  case PGC_BOOL:
4147  case PGC_INT:
4148  case PGC_REAL:
4149  case PGC_ENUM:
4150  /* no need to do anything */
4151  break;
4152  case PGC_STRING:
4153  set_string_field((struct config_string *) gconf,
4154  &(val->val.stringval),
4155  NULL);
4156  break;
4157  }
4158  set_extra_field(gconf, &(val->extra), NULL);
4159 }
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:4088
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4027
enum config_type vartype
Definition: guc_tables.h:152
#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 9089 of file guc.c.

References elog, ERROR, and vsnprintf().

Referenced by serialize_variable().

9090 {
9091  va_list vargs;
9092  int n;
9093 
9094  if (*maxbytes <= 0)
9095  elog(ERROR, "not enough space to serialize GUC state");
9096 
9097  va_start(vargs, fmt);
9098  n = vsnprintf(*destptr, *maxbytes, fmt, vargs);
9099  va_end(vargs);
9100 
9101  /*
9102  * Cater to portability hazards in the vsnprintf() return value just like
9103  * appendPQExpBufferVA() does. Note that this requires an extra byte of
9104  * slack at the end of the buffer. Since serialize_variable() ends with a
9105  * do_serialize_binary() rather than a do_serialize(), we'll always have
9106  * that slack; estimate_variable_size() need not add a byte for it.
9107  */
9108  if (n < 0 || n >= *maxbytes - 1)
9109  {
9110  if (n < 0 && errno != 0 && errno != ENOMEM)
9111  /* Shouldn't happen. Better show errno description. */
9112  elog(ERROR, "vsnprintf failed: %m");
9113  else
9114  elog(ERROR, "not enough space to serialize GUC state");
9115  }
9116 
9117  /* Shift the destptr ahead of the null terminator */
9118  *destptr += n + 1;
9119  *maxbytes -= n + 1;
9120 }
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 9124 of file guc.c.

References elog, and ERROR.

Referenced by serialize_variable().

9125 {
9126  if (valsize > *maxbytes)
9127  elog(ERROR, "not enough space to serialize GUC state");
9128 
9129  memcpy(*destptr, val, valsize);
9130  *destptr += valsize;
9131  *maxbytes -= valsize;
9132 }
#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 7844 of file guc.c.

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

Referenced by _PG_init().

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

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

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

Definition at line 9066 of file guc.c.

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

Referenced by InitializeParallelDSM().

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

Definition at line 7261 of file guc.c.

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

Referenced by standard_ProcessUtility().

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

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

4044 {
4045  GucStack *stack;
4046 
4047  if (extra == gconf->extra)
4048  return true;
4049  switch (gconf->vartype)
4050  {
4051  case PGC_BOOL:
4052  if (extra == ((struct config_bool *) gconf)->reset_extra)
4053  return true;
4054  break;
4055  case PGC_INT:
4056  if (extra == ((struct config_int *) gconf)->reset_extra)
4057  return true;
4058  break;
4059  case PGC_REAL:
4060  if (extra == ((struct config_real *) gconf)->reset_extra)
4061  return true;
4062  break;
4063  case PGC_STRING:
4064  if (extra == ((struct config_string *) gconf)->reset_extra)
4065  return true;
4066  break;
4067  case PGC_ENUM:
4068  if (extra == ((struct config_enum *) gconf)->reset_extra)
4069  return true;
4070  break;
4071  }
4072  for (stack = gconf->stack; stack; stack = stack->prev)
4073  {
4074  if (extra == stack->prior.extra ||
4075  extra == stack->masked.extra)
4076  return true;
4077  }
4078 
4079  return false;
4080 }
struct guc_stack * prev
Definition: guc_tables.h:119
config_var_value masked
Definition: guc_tables.h:127
void * reset_extra
Definition: guc_tables.h:248
enum config_type vartype
Definition: guc_tables.h:152
GucStack * stack
Definition: guc_tables.h:158
config_var_value prior
Definition: guc_tables.h:126
char* ExtractSetVariableArgs ( VariableSetStmt stmt)

Definition at line 7385 of file guc.c.

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

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

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

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

4352 {
4353  const char **key = &name;
4354  struct config_generic **res;
4355  int i;
4356 
4357  Assert(name);
4358 
4359  /*
4360  * By equating const char ** with struct config_generic *, we are assuming
4361  * the name field is first in config_generic.
4362  */
4363  res = (struct config_generic **) bsearch((void *) &key,
4364  (void *) guc_variables,
4366  sizeof(struct config_generic *),
4367  guc_var_compare);
4368  if (res)
4369  return *res;
4370 
4371  /*
4372  * See if the name is an obsolete name for a variable. We assume that the
4373  * set of supported old names is short enough that a brute-force search is
4374  * the best way.
4375  */
4376  for (i = 0; map_old_guc_names[i] != NULL; i += 2)
4377  {
4378  if (guc_name_compare(name, map_old_guc_names[i]) == 0)
4379  return find_option(map_old_guc_names[i + 1], false, elevel);
4380  }
4381 
4382  if (create_placeholders)
4383  {
4384  /*
4385  * Check if the name is qualified, and if so, add a placeholder.
4386  */
4387  if (strchr(name, GUC_QUALIFIER_SEPARATOR) != NULL)
4389  }
4390 
4391  /* Unknown name */
4392  return NULL;
4393 }
#define GUC_QUALIFIER_SEPARATOR
Definition: guc.h:199
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:4412
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:4400
static int num_guc_variables
Definition: guc.c:3917
static struct config_generic ** guc_variables
Definition: guc.c:3914
static int elevel
Definition: vacuumlazy.c:137
static const char *const map_old_guc_names[]
Definition: guc.c:3904
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4351
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
const char * name
Definition: encode.c:521
static struct config_generic * add_placeholder_variable(const char *name, int elevel)
Definition: guc.c:4303
int i
static char* flatten_set_variable_args ( const char *  name,
List args 
)
static

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

6784 {
6785  struct config_generic *record;
6786  int flags;
6788  ListCell *l;
6789 
6790  /* Fast path if just DEFAULT */
6791  if (args == NIL)
6792  return NULL;
6793 
6794  /*
6795  * Get flags for the variable; if it's not known, use default flags.
6796  * (Caller might throw error later, but not our business to do so here.)
6797  */
6798  record = find_option(name, false, WARNING);
6799  if (record)
6800  flags = record->flags;
6801  else
6802  flags = 0;
6803 
6804  /* Complain if list input and non-list variable */
6805  if ((flags & GUC_LIST_INPUT) == 0 &&
6806  list_length(args) != 1)
6807  ereport(ERROR,
6808  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6809  errmsg("SET %s takes only one argument", name)));
6810 
6811  initStringInfo(&buf);
6812 
6813  /*
6814  * Each list member may be a plain A_Const node, or an A_Const within a
6815  * TypeCast; the latter case is supported only for ConstInterval arguments
6816  * (for SET TIME ZONE).
6817  */
6818  foreach(l, args)
6819  {
6820  Node *arg = (Node *) lfirst(l);
6821  char *val;
6822  TypeName *typeName = NULL;
6823  A_Const *con;
6824 
6825  if (l != list_head(args))
6826  appendStringInfoString(&buf, ", ");
6827 
6828  if (IsA(arg, TypeCast))
6829  {
6830  TypeCast *tc = (TypeCast *) arg;
6831 
6832  arg = tc->arg;
6833  typeName = tc->typeName;
6834  }
6835 
6836  if (!IsA(arg, A_Const))
6837  elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
6838  con = (A_Const *) arg;
6839 
6840  switch (nodeTag(&con->val))
6841  {
6842  case T_Integer:
6843  appendStringInfo(&buf, "%ld", intVal(&con->val));
6844  break;
6845  case T_Float:
6846  /* represented as a string, so just copy it */
6847  appendStringInfoString(&buf, strVal(&con->val));
6848  break;
6849  case T_String:
6850  val = strVal(&con->val);
6851  if (typeName != NULL)
6852  {
6853  /*
6854  * Must be a ConstInterval argument for TIME ZONE. Coerce
6855  * to interval and back to normalize the value and account
6856  * for any typmod.
6857  */
6858  Oid typoid;
6859  int32 typmod;
6860  Datum interval;
6861  char *intervalout;
6862 
6863  typenameTypeIdAndMod(NULL, typeName, &typoid, &typmod);
6864  Assert(typoid == INTERVALOID);
6865 
6866  interval =
6868  CStringGetDatum(val),
6870  Int32GetDatum(typmod));
6871 
6872  intervalout =
6874  interval));
6875  appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
6876  }
6877  else
6878  {
6879  /*
6880  * Plain string literal or identifier. For quote mode,
6881  * quote it if it's not a vanilla identifier.
6882  */
6883  if (flags & GUC_LIST_QUOTE)
6885  else
6886  appendStringInfoString(&buf, val);
6887  }
6888  break;
6889  default:
6890  elog(ERROR, "unrecognized node type: %d",
6891  (int) nodeTag(&con->val));
6892  break;
6893  }
6894  }
6895 
6896  return buf.data;
6897 }
#define NIL
Definition: pg_list.h:69
#define IsA(nodeptr, _type_)
Definition: nodes.h:573
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:10195
Datum interval_in(PG_FUNCTION_ARGS)
Definition: timestamp.c:875
#define GUC_LIST_QUOTE
Definition: guc.h:205
Definition: nodes.h:522
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:575
Datum interval_out(PG_FUNCTION_ARGS)
Definition: timestamp.c:957
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:576
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:65
#define CStringGetDatum(X)
Definition: postgres.h:584
#define INTERVALOID
Definition: pg_type.h:525
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:580
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:290
void typenameTypeIdAndMod(ParseState *pstate, const TypeName *typeName, Oid *typeid_p, int32 *typmod_p)
Definition: parse_type.c:293
#define InvalidOid
Definition: postgres_ext.h:36
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4351
#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:527
Definition: nodes.h:296
#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:279
long val
Definition: informix.c:689
#define GUC_LIST_INPUT
Definition: guc.h:204
Node * arg
Definition: parsenodes.h:289
struct config_generic** get_guc_variables ( void  )

Definition at line 4166 of file guc.c.

References guc_variables.

Referenced by GucInfoMain().

4167 {
4168  return guc_variables;
4169 }
static struct config_generic ** guc_variables
Definition: guc.c:3914
const char* GetConfigOption ( const char *  name,
bool  missing_ok,
bool  restrict_superuser 
)

Definition at line 6675 of file guc.c.

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

Referenced by applyRemoteGucs(), and PostmasterMain().

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

Definition at line 8011 of file guc.c.

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

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

8012 {
8013  struct config_generic *record;
8014 
8015  record = find_option(name, false, ERROR);
8016  if (record == NULL)
8017  {
8018  if (missing_ok)
8019  {
8020  if (varname)
8021  *varname = NULL;
8022  return NULL;
8023  }
8024 
8025  ereport(ERROR,
8026  (errcode(ERRCODE_UNDEFINED_OBJECT),
8027  errmsg("unrecognized configuration parameter \"%s\"", name)));
8028  }
8029 
8030  if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
8031  ereport(ERROR,
8032  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
8033  errmsg("must be superuser to examine \"%s\"", name)));
8034 
8035  if (varname)
8036  *varname = record->name;
8037 
8038  return _ShowOption(record, true);
8039 }
static char * _ShowOption(struct config_generic *record, bool use_units)
Definition: guc.c:8608
const char * name
Definition: guc_tables.h:145
int errcode(int sqlerrcode)
Definition: elog.c:575
bool superuser(void)
Definition: superuser.c:47
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4351
#define NULL
Definition: c.h:229
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797
void GetConfigOptionByNum ( int  varnum,
const char **  values,
bool noshow 
)

Definition at line 8046 of file guc.c.

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

Referenced by show_all_settings().

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