PostgreSQL Source Code  git master
guc.c File Reference
#include "postgres.h"
#include <ctype.h>
#include <float.h>
#include <math.h>
#include <limits.h>
#include <unistd.h>
#include <sys/stat.h>
#include "access/commit_ts.h"
#include "access/gin.h"
#include "access/rmgr.h"
#include "access/transam.h"
#include "access/twophase.h"
#include "access/xact.h"
#include "access/xlog_internal.h"
#include "catalog/namespace.h"
#include "catalog/pg_authid.h"
#include "commands/async.h"
#include "commands/prepare.h"
#include "commands/user.h"
#include "commands/vacuum.h"
#include "commands/variable.h"
#include "commands/trigger.h"
#include "funcapi.h"
#include "libpq/auth.h"
#include "libpq/libpq.h"
#include "libpq/pqformat.h"
#include "miscadmin.h"
#include "optimizer/cost.h"
#include "optimizer/geqo.h"
#include "optimizer/paths.h"
#include "optimizer/planmain.h"
#include "parser/parse_expr.h"
#include "parser/parse_type.h"
#include "parser/parser.h"
#include "parser/scansup.h"
#include "pgstat.h"
#include "postmaster/autovacuum.h"
#include "postmaster/bgworker_internals.h"
#include "postmaster/bgwriter.h"
#include "postmaster/postmaster.h"
#include "postmaster/syslogger.h"
#include "postmaster/walwriter.h"
#include "replication/logicallauncher.h"
#include "replication/slot.h"
#include "replication/syncrep.h"
#include "replication/walreceiver.h"
#include "replication/walsender.h"
#include "storage/bufmgr.h"
#include "storage/dsm_impl.h"
#include "storage/standby.h"
#include "storage/fd.h"
#include "storage/large_object.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
 
bool session_auth_is_superuser
 
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 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 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

◆ CONFIG_FILENAME

#define CONFIG_FILENAME   "postgresql.conf"

Definition at line 97 of file guc.c.

Referenced by SelectConfigFiles().

◆ HBA_FILENAME

#define HBA_FILENAME   "pg_hba.conf"

Definition at line 98 of file guc.c.

Referenced by SelectConfigFiles().

◆ IDENT_FILENAME

#define IDENT_FILENAME   "pg_ident.conf"

Definition at line 99 of file guc.c.

Referenced by SelectConfigFiles().

◆ MAX_UNIT_LEN

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

Definition at line 697 of file guc.c.

Referenced by parse_int().

◆ newval [1/5]

◆ newval [2/5]

#define newval   (newval_union.intval)

◆ newval [3/5]

#define newval   (newval_union.realval)

◆ newval [4/5]

#define newval   (newval_union.stringval)

◆ newval [5/5]

#define newval   (newval_union.enumval)

◆ NUM_PG_FILE_SETTINGS_ATTS

#define NUM_PG_FILE_SETTINGS_ATTS   7

Referenced by show_all_file_settings().

◆ NUM_PG_SETTINGS_ATTS

#define NUM_PG_SETTINGS_ATTS   17

Definition at line 8416 of file guc.c.

Referenced by show_all_settings().

◆ PG_KRB_SRVTAB

#define PG_KRB_SRVTAB   ""

Definition at line 94 of file guc.c.

◆ REALTYPE_PRECISION

#define REALTYPE_PRECISION   17

Definition at line 110 of file guc.c.

Referenced by estimate_variable_size(), and serialize_variable().

Function Documentation

◆ _ShowOption()

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

Definition at line 8663 of file guc.c.

References AllocateFile(), Assert, buffer, config_enum_lookup_by_value(), convert_from_base_unit(), elevel, elog, ereport, errcode_for_file_access(), errmsg(), ERROR, FATAL, find_option(), config_generic::flags, free, FreeFile(), GUC_ACTION_SET, guc_malloc(), guc_realloc(), GUC_UNIT, i, INT64_FORMAT, IsInitProcessingMode, LOG, config_generic::name, num_guc_variables, PGC_BOOL, PGC_ENUM, PGC_INT, PGC_POSTMASTER, PGC_REAL, PGC_S_DEFAULT, PGC_SIGHUP, PGC_STRING, pstrdup(), config_generic::scontext, set_config_option(), set_config_sourcefile(), config_bool::show_hook, config_int::show_hook, config_real::show_hook, config_string::show_hook, config_enum::show_hook, snprintf(), config_generic::source, config_generic::sourcefile, config_generic::sourceline, generate_unaccent_rules::str, 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().

8664 {
8665  char buffer[256];
8666  const char *val;
8667 
8668  switch (record->vartype)
8669  {
8670  case PGC_BOOL:
8671  {
8672  struct config_bool *conf = (struct config_bool *) record;
8673 
8674  if (conf->show_hook)
8675  val = conf->show_hook();
8676  else
8677  val = *conf->variable ? "on" : "off";
8678  }
8679  break;
8680 
8681  case PGC_INT:
8682  {
8683  struct config_int *conf = (struct config_int *) record;
8684 
8685  if (conf->show_hook)
8686  val = conf->show_hook();
8687  else
8688  {
8689  /*
8690  * Use int64 arithmetic to avoid overflows in units
8691  * conversion.
8692  */
8693  int64 result = *conf->variable;
8694  const char *unit;
8695 
8696  if (use_units && result > 0 && (record->flags & GUC_UNIT))
8697  {
8698  convert_from_base_unit(result, record->flags & GUC_UNIT,
8699  &result, &unit);
8700  }
8701  else
8702  unit = "";
8703 
8704  snprintf(buffer, sizeof(buffer), INT64_FORMAT "%s",
8705  result, unit);
8706  val = buffer;
8707  }
8708  }
8709  break;
8710 
8711  case PGC_REAL:
8712  {
8713  struct config_real *conf = (struct config_real *) record;
8714 
8715  if (conf->show_hook)
8716  val = conf->show_hook();
8717  else
8718  {
8719  snprintf(buffer, sizeof(buffer), "%g",
8720  *conf->variable);
8721  val = buffer;
8722  }
8723  }
8724  break;
8725 
8726  case PGC_STRING:
8727  {
8728  struct config_string *conf = (struct config_string *) record;
8729 
8730  if (conf->show_hook)
8731  val = conf->show_hook();
8732  else if (*conf->variable && **conf->variable)
8733  val = *conf->variable;
8734  else
8735  val = "";
8736  }
8737  break;
8738 
8739  case PGC_ENUM:
8740  {
8741  struct config_enum *conf = (struct config_enum *) record;
8742 
8743  if (conf->show_hook)
8744  val = conf->show_hook();
8745  else
8746  val = config_enum_lookup_by_value(conf, *conf->variable);
8747  }
8748  break;
8749 
8750  default:
8751  /* just to keep compiler quiet */
8752  val = "???";
8753  break;
8754  }
8755 
8756  return pstrdup(val);
8757 }
char ** variable
Definition: guc_tables.h:227
char * pstrdup(const char *in)
Definition: mcxt.c:1076
bool * variable
Definition: guc_tables.h:181
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5645
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define GUC_UNIT
Definition: guc.h:230
GucShowHook show_hook
Definition: guc_tables.h:201
int * variable
Definition: guc_tables.h:195
int * variable
Definition: guc_tables.h:241
GucShowHook show_hook
Definition: guc_tables.h:231
GucShowHook show_hook
Definition: guc_tables.h:217
double * variable
Definition: guc_tables.h:211
enum config_type vartype
Definition: guc_tables.h:153
GucShowHook show_hook
Definition: guc_tables.h:246
GucShowHook show_hook
Definition: guc_tables.h:185
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:214
#define INT64_FORMAT
Definition: c.h:338
static void convert_from_base_unit(int64 base_value, int base_unit, int64 *value, const char **unit)
Definition: guc.c:5473
long val
Definition: informix.c:689

◆ add_guc_variable()

static bool add_guc_variable ( struct config_generic var,
int  elevel 
)
static

Definition at line 4314 of file guc.c.

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

Referenced by add_placeholder_variable(), and define_custom_variable().

4315 {
4317  {
4318  /*
4319  * Increase the vector by 25%
4320  */
4321  int size_vars = size_guc_variables + size_guc_variables / 4;
4322  struct config_generic **guc_vars;
4323 
4324  if (size_vars == 0)
4325  {
4326  size_vars = 100;
4327  guc_vars = (struct config_generic **)
4328  guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
4329  }
4330  else
4331  {
4332  guc_vars = (struct config_generic **)
4333  guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
4334  }
4335 
4336  if (guc_vars == NULL)
4337  return false; /* out of memory */
4338 
4339  guc_variables = guc_vars;
4340  size_guc_variables = size_vars;
4341  }
4344  sizeof(struct config_generic *), guc_var_compare);
4345  return true;
4346 }
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:4449
static int num_guc_variables
Definition: guc.c:3966
static void * guc_realloc(int elevel, void *old, size_t size)
Definition: guc.c:4020
static struct config_generic ** guc_variables
Definition: guc.c:3963
static int size_guc_variables
Definition: guc.c:3969
static int elevel
Definition: vacuumlazy.c:136
#define qsort(a, b, c, d)
Definition: port.h:408
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4004

◆ add_placeholder_variable()

static struct config_generic* add_placeholder_variable ( const char *  name,
int  elevel 
)
static

Definition at line 4352 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, PGC_STRING, PGC_USERSET, config_generic::short_desc, config_string::variable, and config_generic::vartype.

Referenced by find_option().

4353 {
4354  size_t sz = sizeof(struct config_string) + sizeof(char *);
4355  struct config_string *var;
4356  struct config_generic *gen;
4357 
4358  var = (struct config_string *) guc_malloc(elevel, sz);
4359  if (var == NULL)
4360  return NULL;
4361  memset(var, 0, sz);
4362  gen = &var->gen;
4363 
4364  gen->name = guc_strdup(elevel, name);
4365  if (gen->name == NULL)
4366  {
4367  free(var);
4368  return NULL;
4369  }
4370 
4371  gen->context = PGC_USERSET;
4372  gen->group = CUSTOM_OPTIONS;
4373  gen->short_desc = "GUC placeholder variable";
4375  gen->vartype = PGC_STRING;
4376 
4377  /*
4378  * The char* is allocated at the end of the struct since we have no
4379  * 'static' place to point to. Note that the current value, as well as
4380  * the boot and reset values, start out NULL.
4381  */
4382  var->variable = (char **) (var + 1);
4383 
4384  if (!add_guc_variable((struct config_generic *) var, elevel))
4385  {
4386  free((void *) gen->name);
4387  free(var);
4388  return NULL;
4389  }
4390 
4391  return gen;
4392 }
char ** variable
Definition: guc_tables.h:227
const char * name
Definition: guc_tables.h:146
const char * short_desc
Definition: guc_tables.h:149
static char * guc_strdup(int elevel, const char *src)
Definition: guc.c:4036
#define GUC_NO_SHOW_ALL
Definition: guc.h:206
#define GUC_NOT_IN_SAMPLE
Definition: guc.h:209
enum config_type vartype
Definition: guc_tables.h:153
static int elevel
Definition: vacuumlazy.c:136
struct config_generic gen
Definition: guc_tables.h:225
#define free(a)
Definition: header.h:65
#define GUC_CUSTOM_PLACEHOLDER
Definition: guc.h:211
const char * name
Definition: encode.c:521
enum config_group group
Definition: guc_tables.h:148
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4004
GucContext context
Definition: guc_tables.h:147
static bool add_guc_variable(struct config_generic *var, int elevel)
Definition: guc.c:4314

◆ AlterSystemSetConfigFile()

void AlterSystemSetConfigFile ( AlterSystemStmt altersysstmt)

Definition at line 7098 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, 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(), stat, config_var_val::stringval, superuser(), value, VAR_RESET, VAR_RESET_ALL, VAR_SET_DEFAULT, VAR_SET_VALUE, config_generic::vartype, and write_auto_conf_file().

Referenced by standard_ProcessUtility().

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

◆ assign_application_name()

static void assign_application_name ( const char *  newval,
void *  extra 
)
static

Definition at line 10486 of file guc.c.

References pgstat_report_appname().

10487 {
10488  /* Update the pg_stat_activity view */
10490 }
void pgstat_report_appname(const char *appname)
Definition: pgstat.c:3167
#define newval

◆ assign_effective_io_concurrency()

static void assign_effective_io_concurrency ( int  newval,
void *  extra 
)
static

Definition at line 10434 of file guc.c.

References target_prefetch_pages.

10435 {
10436 #ifdef USE_PREFETCH
10437  target_prefetch_pages = *((int *) extra);
10438 #endif /* USE_PREFETCH */
10439 }
int target_prefetch_pages
Definition: bufmgr.c:129

◆ assign_log_destination()

static void assign_log_destination ( const char *  newval,
void *  extra 
)
static

Definition at line 10122 of file guc.c.

References Log_destination.

10123 {
10124  Log_destination = *((int *) extra);
10125 }
int Log_destination
Definition: elog.c:106

◆ assign_pgstat_temp_directory()

static void assign_pgstat_temp_directory ( const char *  newval,
void *  extra 
)
static

Definition at line 10442 of file guc.c.

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

10443 {
10444  /* check_canonical_path already canonicalized newval for us */
10445  char *dname;
10446  char *tname;
10447  char *fname;
10448 
10449  /* directory */
10450  dname = guc_malloc(ERROR, strlen(newval) + 1); /* runtime dir */
10451  sprintf(dname, "%s", newval);
10452 
10453  /* global stats */
10454  tname = guc_malloc(ERROR, strlen(newval) + 12); /* /global.tmp */
10455  sprintf(tname, "%s/global.tmp", newval);
10456  fname = guc_malloc(ERROR, strlen(newval) + 13); /* /global.stat */
10457  sprintf(fname, "%s/global.stat", newval);
10458 
10461  pgstat_stat_directory = dname;
10462  if (pgstat_stat_tmpname)
10464  pgstat_stat_tmpname = tname;
10467  pgstat_stat_filename = fname;
10468 }
char * pgstat_stat_filename
Definition: pgstat.c:135
#define ERROR
Definition: elog.h:43
char * pgstat_stat_directory
Definition: pgstat.c:134
#define free(a)
Definition: header.h:65
#define newval
char * pgstat_stat_tmpname
Definition: pgstat.c:136
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4004

◆ assign_session_replication_role()

static void assign_session_replication_role ( int  newval,
void *  extra 
)
static

Definition at line 10148 of file guc.c.

References ResetPlanCache(), and SessionReplicationRole.

10149 {
10150  /*
10151  * Must flush the plan cache when changing replication role; but don't
10152  * flush unnecessarily.
10153  */
10155  ResetPlanCache();
10156 }
int SessionReplicationRole
Definition: trigger.c:65
void ResetPlanCache(void)
Definition: plancache.c:1860
#define newval

◆ assign_syslog_facility()

static void assign_syslog_facility ( int  newval,
void *  extra 
)
static

Definition at line 10128 of file guc.c.

10129 {
10130 #ifdef HAVE_SYSLOG
10131  set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
10132  newval);
10133 #endif
10134  /* Without syslog support, just ignore it */
10135 }
static char * syslog_ident_str
Definition: guc.c:495
#define newval

◆ assign_syslog_ident()

static void assign_syslog_ident ( const char *  newval,
void *  extra 
)
static

Definition at line 10138 of file guc.c.

10139 {
10140 #ifdef HAVE_SYSLOG
10141  set_syslog_parameters(newval, syslog_facility);
10142 #endif
10143  /* Without syslog support, it will always be set to "none", so ignore */
10144 }
static int syslog_facility
Definition: guc.c:160
#define newval

◆ assign_tcp_keepalives_count()

static void assign_tcp_keepalives_count ( int  newval,
void *  extra 
)
static

Definition at line 10347 of file guc.c.

References MyProcPort, and pq_setkeepalivescount().

10348 {
10349  /* See comments in assign_tcp_keepalives_idle */
10351 }
struct Port * MyProcPort
Definition: globals.c:41
int pq_setkeepalivescount(int count, Port *port)
Definition: pqcomm.c:1888
#define newval

◆ assign_tcp_keepalives_idle()

static void assign_tcp_keepalives_idle ( int  newval,
void *  extra 
)
static

Definition at line 10303 of file guc.c.

References MyProcPort, and pq_setkeepalivesidle().

10304 {
10305  /*
10306  * The kernel API provides no way to test a value without setting it; and
10307  * once we set it we might fail to unset it. So there seems little point
10308  * in fully implementing the check-then-assign GUC API for these
10309  * variables. Instead we just do the assignment on demand. pqcomm.c
10310  * reports any problems via elog(LOG).
10311  *
10312  * This approach means that the GUC value might have little to do with the
10313  * actual kernel value, so we use a show_hook that retrieves the kernel
10314  * value rather than trusting GUC's copy.
10315  */
10317 }
struct Port * MyProcPort
Definition: globals.c:41
int pq_setkeepalivesidle(int idle, Port *port)
Definition: pqcomm.c:1730
#define newval

◆ assign_tcp_keepalives_interval()

static void assign_tcp_keepalives_interval ( int  newval,
void *  extra 
)
static

Definition at line 10330 of file guc.c.

References MyProcPort, and pq_setkeepalivesinterval().

10331 {
10332  /* See comments in assign_tcp_keepalives_idle */
10334 }
struct Port * MyProcPort
Definition: globals.c:41
int pq_setkeepalivesinterval(int interval, Port *port)
Definition: pqcomm.c:1812
#define newval

◆ assign_timezone_abbreviations()

static void assign_timezone_abbreviations ( const char *  newval,
void *  extra 
)
static

Definition at line 10267 of file guc.c.

References InstallTimeZoneAbbrevs().

10268 {
10269  /* Do nothing for the boot_val default of NULL */
10270  if (!extra)
10271  return;
10272 
10274 }
void InstallTimeZoneAbbrevs(TimeZoneAbbrevTable *tbl)
Definition: datetime.c:4603

◆ assign_wal_consistency_checking()

static void assign_wal_consistency_checking ( const char *  newval,
void *  extra 
)
static

Definition at line 10059 of file guc.c.

References wal_consistency_checking.

10060 {
10061  wal_consistency_checking = (bool *) extra;
10062 }
bool * wal_consistency_checking
Definition: xlog.c:101

◆ AtEOXact_GUC()

void AtEOXact_GUC ( bool  isCommit,
int  nestLevel 
)

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

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

◆ AtStart_GUC()

void AtStart_GUC ( void  )

Definition at line 5073 of file guc.c.

References elog, and WARNING.

Referenced by StartTransaction().

5074 {
5075  /*
5076  * The nest level should be 0 between transactions; if it isn't, somebody
5077  * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
5078  * throw a warning but make no other effort to clean up.
5079  */
5080  if (GUCNestLevel != 0)
5081  elog(WARNING, "GUC nest level = %d at transaction start",
5082  GUCNestLevel);
5083  GUCNestLevel = 1;
5084 }
static int GUCNestLevel
Definition: guc.c:3976
#define WARNING
Definition: elog.h:40
#define elog
Definition: elog.h:219

◆ BeginReportingGUCOptions()

void BeginReportingGUCOptions ( void  )

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

5389 {
5390  int i;
5391 
5392  /*
5393  * Don't do anything unless talking to an interactive frontend of protocol
5394  * 3.0 or later.
5395  */
5396  if (whereToSendOutput != DestRemote ||
5398  return;
5399 
5400  reporting_enabled = true;
5401 
5402  /* Transmit initial values of interesting variables */
5403  for (i = 0; i < num_guc_variables; i++)
5404  {
5405  struct config_generic *conf = guc_variables[i];
5406 
5407  if (conf->flags & GUC_REPORT)
5408  ReportGUCOption(conf);
5409  }
5410 }
#define PG_PROTOCOL_MAJOR(v)
Definition: pqcomm.h:104
static int num_guc_variables
Definition: guc.c:3966
#define GUC_REPORT
Definition: guc.h:208
static struct config_generic ** guc_variables
Definition: guc.c:3963
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:5416
CommandDest whereToSendOutput
Definition: postgres.c:88
static bool reporting_enabled
Definition: guc.c:3974
ProtocolVersion FrontendProtocol
Definition: globals.c:27

◆ build_guc_variables()

void build_guc_variables ( void  )

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

4228 {
4229  int size_vars;
4230  int num_vars = 0;
4231  struct config_generic **guc_vars;
4232  int i;
4233 
4234  for (i = 0; ConfigureNamesBool[i].gen.name; i++)
4235  {
4236  struct config_bool *conf = &ConfigureNamesBool[i];
4237 
4238  /* Rather than requiring vartype to be filled in by hand, do this: */
4239  conf->gen.vartype = PGC_BOOL;
4240  num_vars++;
4241  }
4242 
4243  for (i = 0; ConfigureNamesInt[i].gen.name; i++)
4244  {
4245  struct config_int *conf = &ConfigureNamesInt[i];
4246 
4247  conf->gen.vartype = PGC_INT;
4248  num_vars++;
4249  }
4250 
4251  for (i = 0; ConfigureNamesReal[i].gen.name; i++)
4252  {
4253  struct config_real *conf = &ConfigureNamesReal[i];
4254 
4255  conf->gen.vartype = PGC_REAL;
4256  num_vars++;
4257  }
4258 
4259  for (i = 0; ConfigureNamesString[i].gen.name; i++)
4260  {
4261  struct config_string *conf = &ConfigureNamesString[i];
4262 
4263  conf->gen.vartype = PGC_STRING;
4264  num_vars++;
4265  }
4266 
4267  for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
4268  {
4269  struct config_enum *conf = &ConfigureNamesEnum[i];
4270 
4271  conf->gen.vartype = PGC_ENUM;
4272  num_vars++;
4273  }
4274 
4275  /*
4276  * Create table with 20% slack
4277  */
4278  size_vars = num_vars + num_vars / 4;
4279 
4280  guc_vars = (struct config_generic **)
4281  guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
4282 
4283  num_vars = 0;
4284 
4285  for (i = 0; ConfigureNamesBool[i].gen.name; i++)
4286  guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
4287 
4288  for (i = 0; ConfigureNamesInt[i].gen.name; i++)
4289  guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
4290 
4291  for (i = 0; ConfigureNamesReal[i].gen.name; i++)
4292  guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
4293 
4294  for (i = 0; ConfigureNamesString[i].gen.name; i++)
4295  guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
4296 
4297  for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
4298  guc_vars[num_vars++] = &ConfigureNamesEnum[i].gen;
4299 
4300  if (guc_variables)
4302  guc_variables = guc_vars;
4303  num_guc_variables = num_vars;
4304  size_guc_variables = size_vars;
4306  sizeof(struct config_generic *), guc_var_compare);
4307 }
static struct config_int ConfigureNamesInt[]
Definition: guc.c:1705
const char * name
Definition: guc_tables.h:146
static struct config_enum ConfigureNamesEnum[]
Definition: guc.c:3677
static struct config_bool ConfigureNamesBool[]
Definition: guc.c:804
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:4449
static int num_guc_variables
Definition: guc.c:3966
#define FATAL
Definition: elog.h:52
struct config_generic gen
Definition: guc_tables.h:179
struct config_generic gen
Definition: guc_tables.h:193
static struct config_generic ** guc_variables
Definition: guc.c:3963
enum config_type vartype
Definition: guc_tables.h:153
static int size_guc_variables
Definition: guc.c:3969
static struct config_real ConfigureNamesReal[]
Definition: guc.c:2912
struct config_generic gen
Definition: guc_tables.h:239
struct config_generic gen
Definition: guc_tables.h:225
#define free(a)
Definition: header.h:65
static struct config_string ConfigureNamesString[]
Definition: guc.c:3073
int i
#define qsort(a, b, c, d)
Definition: port.h:408
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4004
struct config_generic gen
Definition: guc_tables.h:209

◆ call_bool_check_hook()

static bool call_bool_check_hook ( struct config_bool conf,
bool newval,
void **  extra,
GucSource  source,
int  elevel 
)
static

Definition at line 9809 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, and config_generic::name.

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

9811 {
9812  /* Quick success if no hook */
9813  if (!conf->check_hook)
9814  return true;
9815 
9816  /* Reset variables that might be set by hook */
9817  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
9818  GUC_check_errmsg_string = NULL;
9820  GUC_check_errhint_string = NULL;
9821 
9822  if (!conf->check_hook(newval, extra, source))
9823  {
9824  ereport(elevel,
9828  errmsg("invalid value for parameter \"%s\": %d",
9829  conf->gen.name, (int) *newval),
9833  errhint("%s", GUC_check_errhint_string) : 0));
9834  /* Flush any strings created in ErrorContext */
9835  FlushErrorState();
9836  return false;
9837  }
9838 
9839  return true;
9840 }
char * GUC_check_errhint_string
Definition: guc.c:133
GucSource source
Definition: guc_tables.h:155
int errhint(const char *fmt,...)
Definition: elog.c:987
const char * name
Definition: guc_tables.h:146
int errcode(int sqlerrcode)
Definition: elog.c:575
static int GUC_check_errcode_value
Definition: guc.c:128
void FlushErrorState(void)
Definition: elog.c:1587
int errdetail_internal(const char *fmt,...)
Definition: elog.c:900
struct config_generic gen
Definition: guc_tables.h:179
char * GUC_check_errdetail_string
Definition: guc.c:132
#define ereport(elevel, rest)
Definition: elog.h:122
static int elevel
Definition: vacuumlazy.c:136
GucBoolCheckHook check_hook
Definition: guc_tables.h:183
int errmsg_internal(const char *fmt,...)
Definition: elog.c:827
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:131
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ call_enum_check_hook()

static bool call_enum_check_hook ( struct config_enum conf,
int *  newval,
void **  extra,
GucSource  source,
int  elevel 
)
static

Definition at line 9945 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, and config_generic::name.

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

9947 {
9948  /* Quick success if no hook */
9949  if (!conf->check_hook)
9950  return true;
9951 
9952  /* Reset variables that might be set by hook */
9953  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
9954  GUC_check_errmsg_string = NULL;
9956  GUC_check_errhint_string = NULL;
9957 
9958  if (!conf->check_hook(newval, extra, source))
9959  {
9960  ereport(elevel,
9964  errmsg("invalid value for parameter \"%s\": \"%s\"",
9965  conf->gen.name,
9970  errhint("%s", GUC_check_errhint_string) : 0));
9971  /* Flush any strings created in ErrorContext */
9972  FlushErrorState();
9973  return false;
9974  }
9975 
9976  return true;
9977 }
char * GUC_check_errhint_string
Definition: guc.c:133
GucSource source
Definition: guc_tables.h:155
GucEnumCheckHook check_hook
Definition: guc_tables.h:244
int errhint(const char *fmt,...)
Definition: elog.c:987
const char * name
Definition: guc_tables.h:146
int errcode(int sqlerrcode)
Definition: elog.c:575
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5645
static int GUC_check_errcode_value
Definition: guc.c:128
void FlushErrorState(void)
Definition: elog.c:1587
int errdetail_internal(const char *fmt,...)
Definition: elog.c:900
char * GUC_check_errdetail_string
Definition: guc.c:132
#define ereport(elevel, rest)
Definition: elog.h:122
static int elevel
Definition: vacuumlazy.c:136
struct config_generic gen
Definition: guc_tables.h:239
int errmsg_internal(const char *fmt,...)
Definition: elog.c:827
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:131
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ call_int_check_hook()

static bool call_int_check_hook ( struct config_int conf,
int *  newval,
void **  extra,
GucSource  source,
int  elevel 
)
static

Definition at line 9843 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, and config_generic::name.

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

9845 {
9846  /* Quick success if no hook */
9847  if (!conf->check_hook)
9848  return true;
9849 
9850  /* Reset variables that might be set by hook */
9851  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
9852  GUC_check_errmsg_string = NULL;
9854  GUC_check_errhint_string = NULL;
9855 
9856  if (!conf->check_hook(newval, extra, source))
9857  {
9858  ereport(elevel,
9862  errmsg("invalid value for parameter \"%s\": %d",
9863  conf->gen.name, *newval),
9867  errhint("%s", GUC_check_errhint_string) : 0));
9868  /* Flush any strings created in ErrorContext */
9869  FlushErrorState();
9870  return false;
9871  }
9872 
9873  return true;
9874 }
char * GUC_check_errhint_string
Definition: guc.c:133
GucSource source
Definition: guc_tables.h:155
int errhint(const char *fmt,...)
Definition: elog.c:987
const char * name
Definition: guc_tables.h:146
int errcode(int sqlerrcode)
Definition: elog.c:575
static int GUC_check_errcode_value
Definition: guc.c:128
GucIntCheckHook check_hook
Definition: guc_tables.h:199
void FlushErrorState(void)
Definition: elog.c:1587
int errdetail_internal(const char *fmt,...)
Definition: elog.c:900
struct config_generic gen
Definition: guc_tables.h:193
char * GUC_check_errdetail_string
Definition: guc.c:132
#define ereport(elevel, rest)
Definition: elog.h:122
static int elevel
Definition: vacuumlazy.c:136
int errmsg_internal(const char *fmt,...)
Definition: elog.c:827
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:131
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ call_real_check_hook()

static bool call_real_check_hook ( struct config_real conf,
double *  newval,
void **  extra,
GucSource  source,
int  elevel 
)
static

Definition at line 9877 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, and config_generic::name.

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

9879 {
9880  /* Quick success if no hook */
9881  if (!conf->check_hook)
9882  return true;
9883 
9884  /* Reset variables that might be set by hook */
9885  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
9886  GUC_check_errmsg_string = NULL;
9888  GUC_check_errhint_string = NULL;
9889 
9890  if (!conf->check_hook(newval, extra, source))
9891  {
9892  ereport(elevel,
9896  errmsg("invalid value for parameter \"%s\": %g",
9897  conf->gen.name, *newval),
9901  errhint("%s", GUC_check_errhint_string) : 0));
9902  /* Flush any strings created in ErrorContext */
9903  FlushErrorState();
9904  return false;
9905  }
9906 
9907  return true;
9908 }
char * GUC_check_errhint_string
Definition: guc.c:133
GucSource source
Definition: guc_tables.h:155
int errhint(const char *fmt,...)
Definition: elog.c:987
const char * name
Definition: guc_tables.h:146
int errcode(int sqlerrcode)
Definition: elog.c:575
static int GUC_check_errcode_value
Definition: guc.c:128
GucRealCheckHook check_hook
Definition: guc_tables.h:215
void FlushErrorState(void)
Definition: elog.c:1587
int errdetail_internal(const char *fmt,...)
Definition: elog.c:900
char * GUC_check_errdetail_string
Definition: guc.c:132
#define ereport(elevel, rest)
Definition: elog.h:122
static int elevel
Definition: vacuumlazy.c:136
int errmsg_internal(const char *fmt,...)
Definition: elog.c:827
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:131
int errmsg(const char *fmt,...)
Definition: elog.c:797
struct config_generic gen
Definition: guc_tables.h:209

◆ call_string_check_hook()

static bool call_string_check_hook ( struct config_string conf,
char **  newval,
void **  extra,
GucSource  source,
int  elevel 
)
static

Definition at line 9911 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, and config_generic::name.

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

9913 {
9914  /* Quick success if no hook */
9915  if (!conf->check_hook)
9916  return true;
9917 
9918  /* Reset variables that might be set by hook */
9919  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
9920  GUC_check_errmsg_string = NULL;
9922  GUC_check_errhint_string = NULL;
9923 
9924  if (!conf->check_hook(newval, extra, source))
9925  {
9926  ereport(elevel,
9930  errmsg("invalid value for parameter \"%s\": \"%s\"",
9931  conf->gen.name, *newval ? *newval : ""),
9935  errhint("%s", GUC_check_errhint_string) : 0));
9936  /* Flush any strings created in ErrorContext */
9937  FlushErrorState();
9938  return false;
9939  }
9940 
9941  return true;
9942 }
char * GUC_check_errhint_string
Definition: guc.c:133
GucSource source
Definition: guc_tables.h:155
int errhint(const char *fmt,...)
Definition: elog.c:987
const char * name
Definition: guc_tables.h:146
GucStringCheckHook check_hook
Definition: guc_tables.h:229
int errcode(int sqlerrcode)
Definition: elog.c:575
static int GUC_check_errcode_value
Definition: guc.c:128
void FlushErrorState(void)
Definition: elog.c:1587
int errdetail_internal(const char *fmt,...)
Definition: elog.c:900
char * GUC_check_errdetail_string
Definition: guc.c:132
#define ereport(elevel, rest)
Definition: elog.h:122
static int elevel
Definition: vacuumlazy.c:136
struct config_generic gen
Definition: guc_tables.h:225
int errmsg_internal(const char *fmt,...)
Definition: elog.c:827
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:131
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ can_skip_gucvar()

static bool can_skip_gucvar ( struct config_generic gconf)
static

Definition at line 9015 of file guc.c.

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

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

9016 {
9017  return gconf->context == PGC_POSTMASTER ||
9018  gconf->context == PGC_INTERNAL || gconf->source == PGC_S_DEFAULT ||
9019  strcmp(gconf->name, "role") == 0;
9020 }
GucSource source
Definition: guc_tables.h:155
const char * name
Definition: guc_tables.h:146
GucContext context
Definition: guc_tables.h:147

◆ check_application_name()

static bool check_application_name ( char **  newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10471 of file guc.c.

10472 {
10473  /* Only allow clean ASCII chars in the application name */
10474  char *p;
10475 
10476  for (p = *newval; *p; p++)
10477  {
10478  if (*p < 32 || *p > 126)
10479  *p = '?';
10480  }
10481 
10482  return true;
10483 }
#define newval

◆ check_autovacuum_max_workers()

static bool check_autovacuum_max_workers ( int *  newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10373 of file guc.c.

References MAX_BACKENDS, max_worker_processes, and MaxConnections.

10374 {
10376  return false;
10377  return true;
10378 }
#define MAX_BACKENDS
Definition: postmaster.h:75
int MaxConnections
Definition: globals.c:123
#define newval
int max_worker_processes
Definition: globals.c:124

◆ check_autovacuum_work_mem()

static bool check_autovacuum_work_mem ( int *  newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10381 of file guc.c.

10382 {
10383  /*
10384  * -1 indicates fallback.
10385  *
10386  * If we haven't yet changed the boot_val default of -1, just let it be.
10387  * Autovacuum will look to maintenance_work_mem instead.
10388  */
10389  if (*newval == -1)
10390  return true;
10391 
10392  /*
10393  * We clamp manually-set values to at least 1MB. Since
10394  * maintenance_work_mem is always set to at least this value, do the same
10395  * here.
10396  */
10397  if (*newval < 1024)
10398  *newval = 1024;
10399 
10400  return true;
10401 }
#define newval

◆ check_bonjour()

static bool check_bonjour ( bool newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10173 of file guc.c.

References GUC_check_errmsg.

10174 {
10175 #ifndef USE_BONJOUR
10176  if (*newval)
10177  {
10178  GUC_check_errmsg("Bonjour is not supported by this build");
10179  return false;
10180  }
10181 #endif
10182  return true;
10183 }
#define GUC_check_errmsg
Definition: guc.h:405
#define newval

◆ check_canonical_path()

static bool check_canonical_path ( char **  newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10224 of file guc.c.

References canonicalize_path().

10225 {
10226  /*
10227  * Since canonicalize_path never enlarges the string, we can just modify
10228  * newval in-place. But watch out for NULL, which is the default value
10229  * for external_pid_file.
10230  */
10231  if (*newval)
10233  return true;
10234 }
void canonicalize_path(char *path)
Definition: path.c:254
#define newval

◆ check_cluster_name()

static bool check_cluster_name ( char **  newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10493 of file guc.c.

10494 {
10495  /* Only allow clean ASCII chars in the cluster name */
10496  char *p;
10497 
10498  for (p = *newval; *p; p++)
10499  {
10500  if (*p < 32 || *p > 126)
10501  *p = '?';
10502  }
10503 
10504  return true;
10505 }
#define newval

◆ check_effective_io_concurrency()

static bool check_effective_io_concurrency ( int *  newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10412 of file guc.c.

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

10413 {
10414 #ifdef USE_PREFETCH
10415  double new_prefetch_pages;
10416 
10417  if (ComputeIoConcurrency(*newval, &new_prefetch_pages))
10418  {
10419  int *myextra = (int *) guc_malloc(ERROR, sizeof(int));
10420 
10421  *myextra = (int) rint(new_prefetch_pages);
10422  *extra = (void *) myextra;
10423 
10424  return true;
10425  }
10426  else
10427  return false;
10428 #else
10429  return true;
10430 #endif /* USE_PREFETCH */
10431 }
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:4004

◆ check_log_destination()

static bool check_log_destination ( char **  newval,
void **  extra,
GucSource  source 
)
static

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

10066 {
10067  char *rawstring;
10068  List *elemlist;
10069  ListCell *l;
10070  int newlogdest = 0;
10071  int *myextra;
10072 
10073  /* Need a modifiable copy of string */
10074  rawstring = pstrdup(*newval);
10075 
10076  /* Parse string into list of identifiers */
10077  if (!SplitIdentifierString(rawstring, ',', &elemlist))
10078  {
10079  /* syntax error in list */
10080  GUC_check_errdetail("List syntax is invalid.");
10081  pfree(rawstring);
10082  list_free(elemlist);
10083  return false;
10084  }
10085 
10086  foreach(l, elemlist)
10087  {
10088  char *tok = (char *) lfirst(l);
10089 
10090  if (pg_strcasecmp(tok, "stderr") == 0)
10091  newlogdest |= LOG_DESTINATION_STDERR;
10092  else if (pg_strcasecmp(tok, "csvlog") == 0)
10093  newlogdest |= LOG_DESTINATION_CSVLOG;
10094 #ifdef HAVE_SYSLOG
10095  else if (pg_strcasecmp(tok, "syslog") == 0)
10096  newlogdest |= LOG_DESTINATION_SYSLOG;
10097 #endif
10098 #ifdef WIN32
10099  else if (pg_strcasecmp(tok, "eventlog") == 0)
10100  newlogdest |= LOG_DESTINATION_EVENTLOG;
10101 #endif
10102  else
10103  {
10104  GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
10105  pfree(rawstring);
10106  list_free(elemlist);
10107  return false;
10108  }
10109  }
10110 
10111  pfree(rawstring);
10112  list_free(elemlist);
10113 
10114  myextra = (int *) guc_malloc(ERROR, sizeof(int));
10115  *myextra = newlogdest;
10116  *extra = (void *) myextra;
10117 
10118  return true;
10119 }
#define LOG_DESTINATION_EVENTLOG
Definition: elog.h:397
#define GUC_check_errdetail
Definition: guc.h:409
char * pstrdup(const char *in)
Definition: mcxt.c:1076
#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:949
#define ERROR
Definition: elog.h:43
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3264
#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:4004
Definition: pg_list.h:45

◆ check_log_stats()

static bool check_log_stats ( bool newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10210 of file guc.c.

References GUC_check_errdetail.

10211 {
10212  if (*newval &&
10214  {
10215  GUC_check_errdetail("Cannot enable \"log_statement_stats\" when "
10216  "\"log_parser_stats\", \"log_planner_stats\", "
10217  "or \"log_executor_stats\" is true.");
10218  return false;
10219  }
10220  return true;
10221 }
bool log_parser_stats
Definition: guc.c:438
#define GUC_check_errdetail
Definition: guc.h:409
#define newval
bool log_executor_stats
Definition: guc.c:440
bool log_planner_stats
Definition: guc.c:439

◆ check_max_worker_processes()

static bool check_max_worker_processes ( int *  newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10404 of file guc.c.

References autovacuum_max_workers, MAX_BACKENDS, and MaxConnections.

10405 {
10407  return false;
10408  return true;
10409 }
#define MAX_BACKENDS
Definition: postmaster.h:75
int MaxConnections
Definition: globals.c:123
int autovacuum_max_workers
Definition: autovacuum.c:115
#define newval

◆ check_maxconnections()

static bool check_maxconnections ( int *  newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10364 of file guc.c.

References autovacuum_max_workers, MAX_BACKENDS, and max_worker_processes.

10365 {
10366  if (*newval + autovacuum_max_workers + 1 +
10368  return false;
10369  return true;
10370 }
#define MAX_BACKENDS
Definition: postmaster.h:75
int autovacuum_max_workers
Definition: autovacuum.c:115
#define newval
int max_worker_processes
Definition: globals.c:124

◆ check_ssl()

static bool check_ssl ( bool newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10186 of file guc.c.

References GUC_check_errmsg.

10187 {
10188 #ifndef USE_SSL
10189  if (*newval)
10190  {
10191  GUC_check_errmsg("SSL is not supported by this build");
10192  return false;
10193  }
10194 #endif
10195  return true;
10196 }
#define GUC_check_errmsg
Definition: guc.h:405
#define newval

◆ check_stage_log_stats()

static bool check_stage_log_stats ( bool newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10199 of file guc.c.

References GUC_check_errdetail.

10200 {
10201  if (*newval && log_statement_stats)
10202  {
10203  GUC_check_errdetail("Cannot enable parameter when \"log_statement_stats\" is true.");
10204  return false;
10205  }
10206  return true;
10207 }
bool log_statement_stats
Definition: guc.c:441
#define GUC_check_errdetail
Definition: guc.h:409
#define newval

◆ check_temp_buffers()

static bool check_temp_buffers ( int *  newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10159 of file guc.c.

References GUC_check_errdetail, and NLocBuffer.

10160 {
10161  /*
10162  * Once local buffers have been initialized, it's too late to change this.
10163  */
10164  if (NLocBuffer && NLocBuffer != *newval)
10165  {
10166  GUC_check_errdetail("\"temp_buffers\" cannot be changed after any temporary tables have been accessed in the session.");
10167  return false;
10168  }
10169  return true;
10170 }
#define GUC_check_errdetail
Definition: guc.h:409
int NLocBuffer
Definition: localbuf.c:41
#define newval

◆ check_timezone_abbreviations()

static bool check_timezone_abbreviations ( char **  newval,
void **  extra,
GucSource  source 
)
static

Definition at line 10237 of file guc.c.

References Assert, load_tzoffsets(), and PGC_S_DEFAULT.

10238 {
10239  /*
10240  * The boot_val given above for timezone_abbreviations is NULL. When we
10241  * see this we just do nothing. If this value isn't overridden from the
10242  * config file then pg_timezone_abbrev_initialize() will eventually
10243  * replace it with "Default". This hack has two purposes: to avoid
10244  * wasting cycles loading values that might soon be overridden from the
10245  * config file, and to avoid trying to read the timezone abbrev files
10246  * during InitializeGUCOptions(). The latter doesn't work in an
10247  * EXEC_BACKEND subprocess because my_exec_path hasn't been set yet and so
10248  * we can't locate PGSHAREDIR.
10249  */
10250  if (*newval == NULL)
10251  {
10253  return true;
10254  }
10255 
10256  /* OK, load the file and produce a malloc'd TimeZoneAbbrevTable */
10258 
10259  /* tzparser.c returns NULL on failure, reporting via GUC_check_errmsg */
10260  if (!*extra)
10261  return false;
10262 
10263  return true;
10264 }
GucSource source
Definition: guc_tables.h:155
TimeZoneAbbrevTable * load_tzoffsets(const char *filename)
Definition: tzparser.c:438
#define Assert(condition)
Definition: c.h:670
#define newval

◆ check_wal_consistency_checking()

static bool check_wal_consistency_checking ( char **  newval,
void **  extra,
GucSource  source 
)
static

Definition at line 9985 of file guc.c.

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

9986 {
9987  char *rawstring;
9988  List *elemlist;
9989  ListCell *l;
9990  bool newwalconsistency[RM_MAX_ID + 1];
9991 
9992  /* Initialize the array */
9993  MemSet(newwalconsistency, 0, (RM_MAX_ID + 1) * sizeof(bool));
9994 
9995  /* Need a modifiable copy of string */
9996  rawstring = pstrdup(*newval);
9997 
9998  /* Parse string into list of identifiers */
9999  if (!SplitIdentifierString(rawstring, ',', &elemlist))
10000  {
10001  /* syntax error in list */
10002  GUC_check_errdetail("List syntax is invalid.");
10003  pfree(rawstring);
10004  list_free(elemlist);
10005  return false;
10006  }
10007 
10008  foreach(l, elemlist)
10009  {
10010  char *tok = (char *) lfirst(l);
10011  bool found = false;
10012  RmgrId rmid;
10013 
10014  /* Check for 'all'. */
10015  if (pg_strcasecmp(tok, "all") == 0)
10016  {
10017  for (rmid = 0; rmid <= RM_MAX_ID; rmid++)
10018  if (RmgrTable[rmid].rm_mask != NULL)
10019  newwalconsistency[rmid] = true;
10020  found = true;
10021  }
10022  else
10023  {
10024  /*
10025  * Check if the token matches with any individual resource
10026  * manager.
10027  */
10028  for (rmid = 0; rmid <= RM_MAX_ID; rmid++)
10029  {
10030  if (pg_strcasecmp(tok, RmgrTable[rmid].rm_name) == 0 &&
10031  RmgrTable[rmid].rm_mask != NULL)
10032  {
10033  newwalconsistency[rmid] = true;
10034  found = true;
10035  }
10036  }
10037  }
10038 
10039  /* If a valid resource manager is found, check for the next one. */
10040  if (!found)
10041  {
10042  GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
10043  pfree(rawstring);
10044  list_free(elemlist);
10045  return false;
10046  }
10047  }
10048 
10049  pfree(rawstring);
10050  list_free(elemlist);
10051 
10052  /* assign new value */
10053  *extra = guc_malloc(ERROR, (RM_MAX_ID + 1) * sizeof(bool));
10054  memcpy(*extra, newwalconsistency, (RM_MAX_ID + 1) * sizeof(bool));
10055  return true;
10056 }
#define GUC_check_errdetail
Definition: guc.h:409
char * pstrdup(const char *in)
Definition: mcxt.c:1076
const RmgrData RmgrTable[RM_MAX_ID+1]
Definition: rmgr.c:36
#define MemSet(start, val, len)
Definition: c.h:853
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
void pfree(void *pointer)
Definition: mcxt.c:949
#define ERROR
Definition: elog.h:43
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3264
#define RM_MAX_ID
Definition: rmgr.h:33
void(* rm_mask)(char *pagedata, BlockNumber blkno)
uint8 RmgrId
Definition: rmgr.h:11
#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:4004
Definition: pg_list.h:45

◆ config_enum_get_options()

static char* config_enum_get_options ( struct config_enum record,
const char *  prefix,
const char *  suffix,
const char *  separator 
)
static

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

5696 {
5697  const struct config_enum_entry *entry;
5698  StringInfoData retstr;
5699  int seplen;
5700 
5701  initStringInfo(&retstr);
5702  appendStringInfoString(&retstr, prefix);
5703 
5704  seplen = strlen(separator);
5705  for (entry = record->options; entry && entry->name; entry++)
5706  {
5707  if (!entry->hidden)
5708  {
5709  appendStringInfoString(&retstr, entry->name);
5710  appendBinaryStringInfo(&retstr, separator, seplen);
5711  }
5712  }
5713 
5714  /*
5715  * All the entries may have been hidden, leaving the string empty if no
5716  * prefix was given. This indicates a broken GUC setup, since there is no
5717  * use for an enum without any values, so we just check to make sure we
5718  * don't write to invalid memory instead of actually trying to do
5719  * something smart with it.
5720  */
5721  if (retstr.len >= seplen)
5722  {
5723  /* Replace final separator */
5724  retstr.data[retstr.len - seplen] = '\0';
5725  retstr.len -= seplen;
5726  }
5727 
5728  appendStringInfoString(&retstr, suffix);
5729 
5730  return retstr.data;
5731 }
Definition: guc.h:164
const struct config_enum_entry * options
Definition: guc_tables.h:243
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:157
void initStringInfo(StringInfo str)
Definition: stringinfo.c:46
const char * name
Definition: guc.h:166
void appendBinaryStringInfo(StringInfo str, const char *data, int datalen)
Definition: stringinfo.c:208
bool hidden
Definition: guc.h:168

◆ config_enum_lookup_by_name()

bool config_enum_lookup_by_name ( struct config_enum record,
const char *  value,
int *  retval 
)

Definition at line 5668 of file guc.c.

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

Referenced by parse_and_validate_value().

5670 {
5671  const struct config_enum_entry *entry;
5672 
5673  for (entry = record->options; entry && entry->name; entry++)
5674  {
5675  if (pg_strcasecmp(value, entry->name) == 0)
5676  {
5677  *retval = entry->val;
5678  return true;
5679  }
5680  }
5681 
5682  *retval = 0;
5683  return false;
5684 }
Definition: guc.h:164
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
static struct @121 value
const struct config_enum_entry * options
Definition: guc_tables.h:243
int val
Definition: guc.h:167
const char * name
Definition: guc.h:166

◆ config_enum_lookup_by_value()

const char* config_enum_lookup_by_value ( struct config_enum record,
int  val 
)

Definition at line 5645 of file guc.c.

References elog, ERROR, config_enum::gen, config_generic::name, config_enum_entry::name, 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().

5646 {
5647  const struct config_enum_entry *entry;
5648 
5649  for (entry = record->options; entry && entry->name; entry++)
5650  {
5651  if (entry->val == val)
5652  return entry->name;
5653  }
5654 
5655  elog(ERROR, "could not find enum option %d for %s",
5656  val, record->gen.name);
5657  return NULL; /* silence compiler */
5658 }
Definition: guc.h:164
const char * name
Definition: guc_tables.h:146
#define ERROR
Definition: elog.h:43
const struct config_enum_entry * options
Definition: guc_tables.h:243
int val
Definition: guc.h:167
struct config_generic gen
Definition: guc_tables.h:239
const char * name
Definition: guc.h:166
#define elog
Definition: elog.h:219
long val
Definition: informix.c:689

◆ convert_from_base_unit()

static void convert_from_base_unit ( int64  base_value,
int  base_unit,
int64 *  value,
const char **  unit 
)
static

Definition at line 5473 of file guc.c.

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

Referenced by _ShowOption().

5475 {
5476  const unit_conversion *table;
5477  int i;
5478 
5479  *unit = NULL;
5480 
5481  if (base_unit & GUC_UNIT_MEMORY)
5483  else
5485 
5486  for (i = 0; *table[i].unit; i++)
5487  {
5488  if (base_unit == table[i].base_unit)
5489  {
5490  /*
5491  * Accept the first conversion that divides the value evenly. We
5492  * assume that the conversions for each base unit are ordered from
5493  * greatest unit to the smallest!
5494  */
5495  if (table[i].multiplier < 0)
5496  {
5497  *value = base_value * (-table[i].multiplier);
5498  *unit = table[i].unit;
5499  break;
5500  }
5501  else if (base_value % table[i].multiplier == 0)
5502  {
5503  *value = base_value / table[i].multiplier;
5504  *unit = table[i].unit;
5505  break;
5506  }
5507  }
5508  }
5509 
5510  Assert(*unit != NULL);
5511 }
static const unit_conversion time_unit_conversion_table[]
Definition: guc.c:751
static const unit_conversion memory_unit_conversion_table[]
Definition: guc.c:719
static struct @121 value
#define Assert(condition)
Definition: c.h:670
int i
char unit[MAX_UNIT_LEN+1]
Definition: guc.c:701
#define GUC_UNIT_MEMORY
Definition: guc.h:223
int multiplier
Definition: guc.c:704

◆ convert_to_base_unit()

static bool convert_to_base_unit ( int64  value,
const char *  unit,
int  base_unit,
int64 *  base_value 
)
static

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

5442 {
5443  const unit_conversion *table;
5444  int i;
5445 
5446  if (base_unit & GUC_UNIT_MEMORY)
5448  else
5450 
5451  for (i = 0; *table[i].unit; i++)
5452  {
5453  if (base_unit == table[i].base_unit &&
5454  strcmp(unit, table[i].unit) == 0)
5455  {
5456  if (table[i].multiplier < 0)
5457  *base_value = value / (-table[i].multiplier);
5458  else
5459  *base_value = value * table[i].multiplier;
5460  return true;
5461  }
5462  }
5463  return false;
5464 }
static const unit_conversion time_unit_conversion_table[]
Definition: guc.c:751
static const unit_conversion memory_unit_conversion_table[]
Definition: guc.c:719
static struct @121 value
int i
char unit[MAX_UNIT_LEN+1]
Definition: guc.c:701
#define GUC_UNIT_MEMORY
Definition: guc.h:223
int multiplier
Definition: guc.c:704

◆ define_custom_variable()

static void define_custom_variable ( struct config_generic variable)
static

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

7576 {
7577  const char *name = variable->name;
7578  const char **nameAddr = &name;
7579  struct config_string *pHolder;
7580  struct config_generic **res;
7581 
7582  /*
7583  * See if there's a placeholder by the same name.
7584  */
7585  res = (struct config_generic **) bsearch((void *) &nameAddr,
7586  (void *) guc_variables,
7588  sizeof(struct config_generic *),
7589  guc_var_compare);
7590  if (res == NULL)
7591  {
7592  /*
7593  * No placeholder to replace, so we can just add it ... but first,
7594  * make sure it's initialized to its default value.
7595  */
7596  InitializeOneGUCOption(variable);
7597  add_guc_variable(variable, ERROR);
7598  return;
7599  }
7600 
7601  /*
7602  * This better be a placeholder
7603  */
7604  if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
7605  ereport(ERROR,
7606  (errcode(ERRCODE_INTERNAL_ERROR),
7607  errmsg("attempt to redefine parameter \"%s\"", name)));
7608 
7609  Assert((*res)->vartype == PGC_STRING);
7610  pHolder = (struct config_string *) (*res);
7611 
7612  /*
7613  * First, set the variable to its default value. We must do this even
7614  * though we intend to immediately apply a new value, since it's possible
7615  * that the new value is invalid.
7616  */
7617  InitializeOneGUCOption(variable);
7618 
7619  /*
7620  * Replace the placeholder. We aren't changing the name, so no re-sorting
7621  * is necessary
7622  */
7623  *res = variable;
7624 
7625  /*
7626  * Assign the string value(s) stored in the placeholder to the real
7627  * variable. Essentially, we need to duplicate all the active and stacked
7628  * values, but with appropriate validation and datatype adjustment.
7629  *
7630  * If an assignment fails, we report a WARNING and keep going. We don't
7631  * want to throw ERROR for bad values, because it'd bollix the add-on
7632  * module that's presumably halfway through getting loaded. In such cases
7633  * the default or previous state will become active instead.
7634  */
7635 
7636  /* First, apply the reset value if any */
7637  if (pHolder->reset_val)
7638  (void) set_config_option(name, pHolder->reset_val,
7639  pHolder->gen.reset_scontext,
7640  pHolder->gen.reset_source,
7641  GUC_ACTION_SET, true, WARNING, false);
7642  /* That should not have resulted in stacking anything */
7643  Assert(variable->stack == NULL);
7644 
7645  /* Now, apply current and stacked values, in the order they were stacked */
7646  reapply_stacked_values(variable, pHolder, pHolder->gen.stack,
7647  *(pHolder->variable),
7648  pHolder->gen.scontext, pHolder->gen.source);
7649 
7650  /* Also copy over any saved source-location information */
7651  if (pHolder->gen.sourcefile)
7652  set_config_sourcefile(name, pHolder->gen.sourcefile,
7653  pHolder->gen.sourceline);
7654 
7655  /*
7656  * Free up as much as we conveniently can of the placeholder structure.
7657  * (This neglects any stack items, so it's possible for some memory to be
7658  * leaked. Since this can only happen once per session per variable, it
7659  * doesn't seem worth spending much code on.)
7660  */
7661  set_string_field(pHolder, pHolder->variable, NULL);
7662  set_string_field(pHolder, &pHolder->reset_val, NULL);
7663 
7664  free(pHolder);
7665 }
GucSource source
Definition: guc_tables.h:155
static void static void set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
Definition: guc.c:6666
char ** variable
Definition: guc_tables.h:227
const char * name
Definition: guc_tables.h:146
static void reapply_stacked_values(struct config_generic *variable, struct config_string *pHolder, GucStack *stack, const char *curvalue, GucContext curscontext, GucSource cursource)
Definition: guc.c:7675
int errcode(int sqlerrcode)
Definition: elog.c:575
GucContext scontext
Definition: guc_tables.h:157
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:4449
#define ERROR
Definition: elog.h:43
static int num_guc_variables
Definition: guc.c:3966
char * sourcefile
Definition: guc_tables.h:161
GucSource reset_source
Definition: guc_tables.h:156
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:4597
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4076
#define ereport(elevel, rest)
Definition: elog.h:122
static struct config_generic ** guc_variables
Definition: guc.c:3963
#define WARNING
Definition: elog.h:40
struct config_generic gen
Definition: guc_tables.h:225
#define free(a)
Definition: header.h:65
char * reset_val
Definition: guc_tables.h:233
#define Assert(condition)
Definition: c.h:670
#define GUC_CUSTOM_PLACEHOLDER
Definition: guc.h:211
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797
GucStack * stack
Definition: guc_tables.h:159
int set_config_option(const char *name, const char *value, GucContext context, GucSource source, GucAction action, bool changeVal, int elevel, bool is_reload)
Definition: guc.c:5936
static bool add_guc_variable(struct config_generic *var, int elevel)
Definition: guc.c:4314
GucContext reset_scontext
Definition: guc_tables.h:158

◆ DefineCustomBoolVariable()

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

7766 {
7767  struct config_bool *var;
7768 
7769  var = (struct config_bool *)
7770  init_custom_variable(name, short_desc, long_desc, context, flags,
7771  PGC_BOOL, sizeof(struct config_bool));
7772  var->variable = valueAddr;
7773  var->boot_val = bootValue;
7774  var->reset_val = bootValue;
7775  var->check_hook = check_hook;
7776  var->assign_hook = assign_hook;
7777  var->show_hook = show_hook;
7778  define_custom_variable(&var->gen);
7779 }
bool * variable
Definition: guc_tables.h:181
GucBoolAssignHook assign_hook
Definition: guc_tables.h:184
bool boot_val
Definition: guc_tables.h:182
struct config_generic gen
Definition: guc_tables.h:179
static struct config_generic * init_custom_variable(const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
Definition: guc.c:7524
GucBoolCheckHook check_hook
Definition: guc_tables.h:183
GucShowHook show_hook
Definition: guc_tables.h:185
const char * name
Definition: encode.c:521
bool reset_val
Definition: guc_tables.h:187
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7575

◆ DefineCustomEnumVariable()

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

7878 {
7879  struct config_enum *var;
7880 
7881  var = (struct config_enum *)
7882  init_custom_variable(name, short_desc, long_desc, context, flags,
7883  PGC_ENUM, sizeof(struct config_enum));
7884  var->variable = valueAddr;
7885  var->boot_val = bootValue;
7886  var->reset_val = bootValue;
7887  var->options = options;
7888  var->check_hook = check_hook;
7889  var->assign_hook = assign_hook;
7890  var->show_hook = show_hook;
7891  define_custom_variable(&var->gen);
7892 }
GucEnumCheckHook check_hook
Definition: guc_tables.h:244
GucEnumAssignHook assign_hook
Definition: guc_tables.h:245
int * variable
Definition: guc_tables.h:241
const struct config_enum_entry * options
Definition: guc_tables.h:243
static char ** options
static struct config_generic * init_custom_variable(const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
Definition: guc.c:7524
GucShowHook show_hook
Definition: guc_tables.h:246
struct config_generic gen
Definition: guc_tables.h:239
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7575

◆ DefineCustomIntVariable()

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

7794 {
7795  struct config_int *var;
7796 
7797  var = (struct config_int *)
7798  init_custom_variable(name, short_desc, long_desc, context, flags,
7799  PGC_INT, sizeof(struct config_int));
7800  var->variable = valueAddr;
7801  var->boot_val = bootValue;
7802  var->reset_val = bootValue;
7803  var->min = minValue;
7804  var->max = maxValue;
7805  var->check_hook = check_hook;
7806  var->assign_hook = assign_hook;
7807  var->show_hook = show_hook;
7808  define_custom_variable(&var->gen);
7809 }
int boot_val
Definition: guc_tables.h:196
GucIntAssignHook assign_hook
Definition: guc_tables.h:200
GucIntCheckHook check_hook
Definition: guc_tables.h:199
GucShowHook show_hook
Definition: guc_tables.h:201
int * variable
Definition: guc_tables.h:195
struct config_generic gen
Definition: guc_tables.h:193
static struct config_generic * init_custom_variable(const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
Definition: guc.c:7524
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7575
int reset_val
Definition: guc_tables.h:203

◆ DefineCustomRealVariable()

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

7824 {
7825  struct config_real *var;
7826 
7827  var = (struct config_real *)
7828  init_custom_variable(name, short_desc, long_desc, context, flags,
7829  PGC_REAL, sizeof(struct config_real));
7830  var->variable = valueAddr;
7831  var->boot_val = bootValue;
7832  var->reset_val = bootValue;
7833  var->min = minValue;
7834  var->max = maxValue;
7835  var->check_hook = check_hook;
7836  var->assign_hook = assign_hook;
7837  var->show_hook = show_hook;
7838  define_custom_variable(&var->gen);
7839 }
GucRealAssignHook assign_hook
Definition: guc_tables.h:216
double reset_val
Definition: guc_tables.h:219
GucRealCheckHook check_hook
Definition: guc_tables.h:215
GucShowHook show_hook
Definition: guc_tables.h:217
double * variable
Definition: guc_tables.h:211
static struct config_generic * init_custom_variable(const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
Definition: guc.c:7524
double max
Definition: guc_tables.h:214
double boot_val
Definition: guc_tables.h:212
const char * name
Definition: encode.c:521
double min
Definition: guc_tables.h:213
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7575
struct config_generic gen
Definition: guc_tables.h:209

◆ DefineCustomStringVariable()

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

7852 {
7853  struct config_string *var;
7854 
7855  var = (struct config_string *)
7856  init_custom_variable(name, short_desc, long_desc, context, flags,
7857  PGC_STRING, sizeof(struct config_string));
7858  var->variable = valueAddr;
7859  var->boot_val = bootValue;
7860  var->check_hook = check_hook;
7861  var->assign_hook = assign_hook;
7862  var->show_hook = show_hook;
7863  define_custom_variable(&var->gen);
7864 }
char ** variable
Definition: guc_tables.h:227
GucStringCheckHook check_hook
Definition: guc_tables.h:229
const char * boot_val
Definition: guc_tables.h:228
GucShowHook show_hook
Definition: guc_tables.h:231
static struct config_generic * init_custom_variable(const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
Definition: guc.c:7524
struct config_generic gen
Definition: guc_tables.h:225
GucStringAssignHook assign_hook
Definition: guc_tables.h:230
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7575

◆ discard_stack_value()

static void discard_stack_value ( struct config_generic gconf,
config_var_value val 
)
static

Definition at line 4191 of file guc.c.

References config_var_value::extra, 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().

4192 {
4193  switch (gconf->vartype)
4194  {
4195  case PGC_BOOL:
4196  case PGC_INT:
4197  case PGC_REAL:
4198  case PGC_ENUM:
4199  /* no need to do anything */
4200  break;
4201  case PGC_STRING:
4202  set_string_field((struct config_string *) gconf,
4203  &(val->val.stringval),
4204  NULL);
4205  break;
4206  }
4207  set_extra_field(gconf, &(val->extra), NULL);
4208 }
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:4137
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4076
enum config_type vartype
Definition: guc_tables.h:153
char * stringval
Definition: guc_tables.h:36

◆ do_serialize()

static void do_serialize ( char **  destptr,
Size maxbytes,
const char *  fmt,
  ... 
)
static

Definition at line 9150 of file guc.c.

References elog, ERROR, and vsnprintf().

Referenced by serialize_variable().

9151 {
9152  va_list vargs;
9153  int n;
9154 
9155  if (*maxbytes <= 0)
9156  elog(ERROR, "not enough space to serialize GUC state");
9157 
9158  va_start(vargs, fmt);
9159  n = vsnprintf(*destptr, *maxbytes, fmt, vargs);
9160  va_end(vargs);
9161 
9162  /*
9163  * Cater to portability hazards in the vsnprintf() return value just like
9164  * appendPQExpBufferVA() does. Note that this requires an extra byte of
9165  * slack at the end of the buffer. Since serialize_variable() ends with a
9166  * do_serialize_binary() rather than a do_serialize(), we'll always have
9167  * that slack; estimate_variable_size() need not add a byte for it.
9168  */
9169  if (n < 0 || n >= *maxbytes - 1)
9170  {
9171  if (n < 0 && errno != 0 && errno != ENOMEM)
9172  /* Shouldn't happen. Better show errno description. */
9173  elog(ERROR, "vsnprintf failed: %m");
9174  else
9175  elog(ERROR, "not enough space to serialize GUC state");
9176  }
9177 
9178  /* Shift the destptr ahead of the null terminator */
9179  *destptr += n + 1;
9180  *maxbytes -= n + 1;
9181 }
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

◆ do_serialize_binary()

static void do_serialize_binary ( char **  destptr,
Size maxbytes,
void *  val,
Size  valsize 
)
static

Definition at line 9185 of file guc.c.

References elog, and ERROR.

Referenced by serialize_variable().

9186 {
9187  if (valsize > *maxbytes)
9188  elog(ERROR, "not enough space to serialize GUC state");
9189 
9190  memcpy(*destptr, val, valsize);
9191  *destptr += valsize;
9192  *maxbytes -= valsize;
9193 }
#define ERROR
Definition: elog.h:43
#define elog
Definition: elog.h:219
long val
Definition: informix.c:689

◆ EmitWarningsOnPlaceholders()

void EmitWarningsOnPlaceholders ( const char *  className)

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

7896 {
7897  int classLen = strlen(className);
7898  int i;
7899 
7900  for (i = 0; i < num_guc_variables; i++)
7901  {
7902  struct config_generic *var = guc_variables[i];
7903 
7904  if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
7905  strncmp(className, var->name, classLen) == 0 &&
7906  var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
7907  {
7908  ereport(WARNING,
7909  (errcode(ERRCODE_UNDEFINED_OBJECT),
7910  errmsg("unrecognized configuration parameter \"%s\"",
7911  var->name)));
7912  }
7913  }
7914 }
const char * name
Definition: guc_tables.h:146
int errcode(int sqlerrcode)
Definition: elog.c:575
#define GUC_QUALIFIER_SEPARATOR
Definition: guc.h:199
static int num_guc_variables
Definition: guc.c:3966
#define ereport(elevel, rest)
Definition: elog.h:122
static struct config_generic ** guc_variables
Definition: guc.c:3963
#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

◆ estimate_variable_size()

static Size estimate_variable_size ( struct config_generic gconf)
static

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

9030 {
9031  Size size;
9032  Size valsize = 0;
9033 
9034  if (can_skip_gucvar(gconf))
9035  return 0;
9036 
9037  /* Name, plus trailing zero byte. */
9038  size = strlen(gconf->name) + 1;
9039 
9040  /* Get the maximum display length of the GUC value. */
9041  switch (gconf->vartype)
9042  {
9043  case PGC_BOOL:
9044  {
9045  valsize = 5; /* max(strlen('true'), strlen('false')) */
9046  }
9047  break;
9048 
9049  case PGC_INT:
9050  {
9051  struct config_int *conf = (struct config_int *) gconf;
9052 
9053  /*
9054  * Instead of getting the exact display length, use max
9055  * length. Also reduce the max length for typical ranges of
9056  * small values. Maximum value is 2147483647, i.e. 10 chars.
9057  * Include one byte for sign.
9058  */
9059  if (Abs(*conf->variable) < 1000)
9060  valsize = 3 + 1;
9061  else
9062  valsize = 10 + 1;
9063  }
9064  break;
9065 
9066  case PGC_REAL:
9067  {
9068  /*
9069  * We are going to print it with %e with REALTYPE_PRECISION
9070  * fractional digits. Account for sign, leading digit,
9071  * decimal point, and exponent with up to 3 digits. E.g.
9072  * -3.99329042340000021e+110
9073  */
9074  valsize = 1 + 1 + 1 + REALTYPE_PRECISION + 5;
9075  }
9076  break;
9077 
9078  case PGC_STRING:
9079  {
9080  struct config_string *conf = (struct config_string *) gconf;
9081 
9082  /*
9083  * If the value is NULL, we transmit it as an empty string.
9084  * Although this is not physically the same value, GUC
9085  * generally treats a NULL the same as empty string.
9086  */
9087  if (*conf->variable)
9088  valsize = strlen(*conf->variable);
9089  else
9090  valsize = 0;
9091  }
9092  break;
9093 
9094  case PGC_ENUM:
9095  {
9096  struct config_enum *conf = (struct config_enum *) gconf;
9097 
9098  valsize = strlen(config_enum_lookup_by_value(conf, *conf->variable));
9099  }
9100  break;
9101  }
9102 
9103  /* Allow space for terminating zero-byte for value */
9104  size = add_size(size, valsize + 1);
9105 
9106  if (gconf->sourcefile)
9107  size = add_size(size, strlen(gconf->sourcefile));
9108 
9109  /* Allow space for terminating zero-byte for sourcefile */
9110  size = add_size(size, 1);
9111 
9112  /* Include line whenever file is nonempty. */
9113  if (gconf->sourcefile && gconf->sourcefile[0])
9114  size = add_size(size, sizeof(gconf->sourceline));
9115 
9116  size = add_size(size, sizeof(gconf->source));
9117  size = add_size(size, sizeof(gconf->scontext));
9118 
9119  return size;
9120 }
GucSource source
Definition: guc_tables.h:155
char ** variable
Definition: guc_tables.h:227
const char * name
Definition: guc_tables.h:146
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5645
GucContext scontext
Definition: guc_tables.h:157
#define Abs(x)
Definition: c.h:808
int * variable
Definition: guc_tables.h:195
int * variable
Definition: guc_tables.h:241
char * sourcefile
Definition: guc_tables.h:161
static bool can_skip_gucvar(struct config_generic *gconf)
Definition: guc.c:9015
#define REALTYPE_PRECISION
Definition: guc.c:110
enum config_type vartype
Definition: guc_tables.h:153
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
size_t Size
Definition: c.h:404

◆ EstimateGUCStateSpace()

Size EstimateGUCStateSpace ( void  )

Definition at line 9127 of file guc.c.

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

Referenced by InitializeParallelDSM().

9128 {
9129  Size size;
9130  int i;
9131 
9132  /* Add space reqd for saving the data size of the guc state */
9133  size = sizeof(Size);
9134 
9135  /* Add up the space needed for each GUC variable */
9136  for (i = 0; i < num_guc_variables; i++)
9137  size = add_size(size,
9139 
9140  return size;
9141 }
static int num_guc_variables
Definition: guc.c:3966
static struct config_generic ** guc_variables
Definition: guc.c:3963
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
size_t Size
Definition: c.h:404
static Size estimate_variable_size(struct config_generic *gconf)
Definition: guc.c:9029
int i

◆ ExecSetVariableStmt()

void ExecSetVariableStmt ( VariableSetStmt stmt,
bool  isTopLevel 
)

Definition at line 7312 of file guc.c.

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

7313 {
7315 
7316  /*
7317  * Workers synchronize these parameters at the start of the parallel
7318  * operation; then, we block SET during the operation.
7319  */
7320  if (IsInParallelMode())
7321  ereport(ERROR,
7322  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
7323  errmsg("cannot set parameters during a parallel operation")));
7324 
7325  switch (stmt->kind)
7326  {
7327  case VAR_SET_VALUE:
7328  case VAR_SET_CURRENT:
7329  if (stmt->is_local)
7330  WarnNoTransactionChain(isTopLevel, "SET LOCAL");
7331  (void) set_config_option(stmt->name,
7332  ExtractSetVariableArgs(stmt),
7334  PGC_S_SESSION,
7335  action, true, 0, false);
7336  break;
7337  case VAR_SET_MULTI:
7338 
7339  /*
7340  * Special-case SQL syntaxes. The TRANSACTION and SESSION
7341  * CHARACTERISTICS cases effectively set more than one variable
7342  * per statement. TRANSACTION SNAPSHOT only takes one argument,
7343  * but we put it here anyway since it's a special case and not
7344  * related to any GUC variable.
7345  */
7346  if (strcmp(stmt->name, "TRANSACTION") == 0)
7347  {
7348  ListCell *head;
7349 
7350  WarnNoTransactionChain(isTopLevel, "SET TRANSACTION");
7351 
7352  foreach(head, stmt->args)
7353  {
7354  DefElem *item = (DefElem *) lfirst(head);
7355 
7356  if (strcmp(item->defname, "transaction_isolation") == 0)
7357  SetPGVariable("transaction_isolation",
7358  list_make1(item->arg), stmt->is_local);
7359  else if (strcmp(item->defname, "transaction_read_only") == 0)
7360  SetPGVariable("transaction_read_only",
7361  list_make1(item->arg), stmt->is_local);
7362  else if (strcmp(item->defname, "transaction_deferrable") == 0)
7363  SetPGVariable("transaction_deferrable",
7364  list_make1(item->arg), stmt->is_local);
7365  else
7366  elog(ERROR, "unexpected SET TRANSACTION element: %s",
7367  item->defname);
7368  }
7369  }
7370  else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
7371  {
7372  ListCell *head;
7373 
7374  foreach(head, stmt->args)
7375  {
7376  DefElem *item = (DefElem *) lfirst(head);
7377 
7378  if (strcmp(item->defname, "transaction_isolation") == 0)
7379  SetPGVariable("default_transaction_isolation",
7380  list_make1(item->arg), stmt->is_local);
7381  else if (strcmp(item->defname, "transaction_read_only") == 0)
7382  SetPGVariable("default_transaction_read_only",
7383  list_make1(item->arg), stmt->is_local);
7384  else if (strcmp(item->defname, "transaction_deferrable") == 0)
7385  SetPGVariable("default_transaction_deferrable",
7386  list_make1(item->arg), stmt->is_local);
7387  else
7388  elog(ERROR, "unexpected SET SESSION element: %s",
7389  item->defname);
7390  }
7391  }
7392  else if (strcmp(stmt->name, "TRANSACTION SNAPSHOT") == 0)
7393  {
7394  A_Const *con = linitial_node(A_Const, stmt->args);
7395 
7396  if (stmt->is_local)
7397  ereport(ERROR,
7398  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7399  errmsg("SET LOCAL TRANSACTION SNAPSHOT is not implemented")));
7400 
7401  WarnNoTransactionChain(isTopLevel, "SET TRANSACTION");
7402  Assert(nodeTag(&con->val) == T_String);
7403  ImportSnapshot(strVal(&con->val));
7404  }
7405  else
7406  elog(ERROR, "unexpected SET MULTI element: %s",
7407  stmt->name);
7408  break;
7409  case VAR_SET_DEFAULT:
7410  if (stmt->is_local)
7411  WarnNoTransactionChain(isTopLevel, "SET LOCAL");
7412  /* fall through */
7413  case VAR_RESET:
7414  if (strcmp(stmt->name, "transaction_isolation") == 0)
7415  WarnNoTransactionChain(isTopLevel, "RESET TRANSACTION");
7416 
7417  (void) set_config_option(stmt->name,
7418  NULL,
7420  PGC_S_SESSION,
7421  action, true, 0, false);
7422  break;
7423  case VAR_RESET_ALL:
7424  ResetAllOptions();
7425  break;
7426  }
7427 }
void ImportSnapshot(const char *idstr)
Definition: snapmgr.c:1430
VariableSetKind kind
Definition: parsenodes.h:1984
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:575
bool superuser(void)
Definition: superuser.c:47
#define linitial_node(type, l)
Definition: pg_list.h:114
GucAction
Definition: guc.h:191
#define list_make1(x1)
Definition: pg_list.h:139
bool IsInParallelMode(void)
Definition: xact.c:906
#define ERROR
Definition: elog.h:43
Definition: guc.h:75
void ResetAllOptions(void)
Definition: guc.c:4892
#define ereport(elevel, rest)
Definition: elog.h:122
Node * arg
Definition: parsenodes.h:720
void WarnNoTransactionChain(bool isTopLevel, const char *stmtType)
Definition: xact.c:3200
#define Assert(condition)
Definition: c.h:670
#define lfirst(lc)
Definition: pg_list.h:106
#define nodeTag(nodeptr)
Definition: nodes.h:517
int errmsg(const char *fmt,...)
Definition: elog.c:797
char * defname
Definition: parsenodes.h:719
#define elog
Definition: elog.h:219
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
Definition: guc.c:7436
Value val
Definition: parsenodes.h:287
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:5936
void SetPGVariable(const char *name, List *args, bool is_local)
Definition: guc.c:7456

◆ extra_field_used()

static bool extra_field_used ( struct config_generic gconf,
void *  extra 
)
static

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

4093 {
4094  GucStack *stack;
4095 
4096  if (extra == gconf->extra)
4097  return true;
4098  switch (gconf->vartype)
4099  {
4100  case PGC_BOOL:
4101  if (extra == ((struct config_bool *) gconf)->reset_extra)
4102  return true;
4103  break;
4104  case PGC_INT:
4105  if (extra == ((struct config_int *) gconf)->reset_extra)
4106  return true;
4107  break;
4108  case PGC_REAL:
4109  if (extra == ((struct config_real *) gconf)->reset_extra)
4110  return true;
4111  break;
4112  case PGC_STRING:
4113  if (extra == ((struct config_string *) gconf)->reset_extra)
4114  return true;
4115  break;
4116  case PGC_ENUM:
4117  if (extra == ((struct config_enum *) gconf)->reset_extra)
4118  return true;
4119  break;
4120  }
4121  for (stack = gconf->stack; stack; stack = stack->prev)
4122  {
4123  if (extra == stack->prior.extra ||
4124  extra == stack->masked.extra)
4125  return true;
4126  }
4127 
4128  return false;
4129 }
struct guc_stack * prev
Definition: guc_tables.h:120
config_var_value masked
Definition: guc_tables.h:128
void * reset_extra
Definition: guc_tables.h:249
enum config_type vartype
Definition: guc_tables.h:153
config_var_value prior
Definition: guc_tables.h:127

◆ ExtractSetVariableArgs()

char* ExtractSetVariableArgs ( VariableSetStmt stmt)

Definition at line 7436 of file guc.c.

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

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

7437 {
7438  switch (stmt->kind)
7439  {
7440  case VAR_SET_VALUE:
7441  return flatten_set_variable_args(stmt->name, stmt->args);
7442  case VAR_SET_CURRENT:
7443  return GetConfigOptionByName(stmt->name, NULL, false);
7444  default:
7445  return NULL;
7446  }
7447 }
VariableSetKind kind
Definition: parsenodes.h:1984
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:8062
static char * flatten_set_variable_args(const char *name, List *args)
Definition: guc.c:6835

◆ find_option()

static struct config_generic* find_option ( const char *  name,
bool  create_placeholders,
int  elevel 
)
static

Definition at line 4400 of file guc.c.

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

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

4401 {
4402  const char **key = &name;
4403  struct config_generic **res;
4404  int i;
4405 
4406  Assert(name);
4407 
4408  /*
4409  * By equating const char ** with struct config_generic *, we are assuming
4410  * the name field is first in config_generic.
4411  */
4412  res = (struct config_generic **) bsearch((void *) &key,
4413  (void *) guc_variables,
4415  sizeof(struct config_generic *),
4416  guc_var_compare);
4417  if (res)
4418  return *res;
4419 
4420  /*
4421  * See if the name is an obsolete name for a variable. We assume that the
4422  * set of supported old names is short enough that a brute-force search is
4423  * the best way.
4424  */
4425  for (i = 0; map_old_guc_names[i] != NULL; i += 2)
4426  {
4427  if (guc_name_compare(name, map_old_guc_names[i]) == 0)
4428  return find_option(map_old_guc_names[i + 1], false, elevel);
4429  }
4430 
4431  if (create_placeholders)
4432  {
4433  /*
4434  * Check if the name is qualified, and if so, add a placeholder.
4435  */
4436  if (strchr(name, GUC_QUALIFIER_SEPARATOR) != NULL)
4438  }
4439 
4440  /* Unknown name */
4441  return NULL;
4442 }
#define GUC_QUALIFIER_SEPARATOR
Definition: guc.h:199
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:4461
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:4449
static int num_guc_variables
Definition: guc.c:3966
static struct config_generic ** guc_variables
Definition: guc.c:3963
static int elevel
Definition: vacuumlazy.c:136
static const char *const map_old_guc_names[]
Definition: guc.c:3953
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4400
#define Assert(condition)
Definition: c.h:670
const char * name
Definition: encode.c:521
static struct config_generic * add_placeholder_variable(const char *name, int elevel)
Definition: guc.c:4352
int i

◆ flatten_set_variable_args()

static char* flatten_set_variable_args ( const char *  name,
List args 
)
static

Definition at line 6835 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, ObjectIdGetDatum, quote_identifier(), strVal, T_Float, T_Integer, T_String, TypeCast::typeName, typenameTypeIdAndMod(), A_Const::val, val, and WARNING.

Referenced by ExtractSetVariableArgs(), and SetPGVariable().

6836 {
6837  struct config_generic *record;
6838  int flags;
6840  ListCell *l;
6841 
6842  /* Fast path if just DEFAULT */
6843  if (args == NIL)
6844  return NULL;
6845 
6846  /*
6847  * Get flags for the variable; if it's not known, use default flags.
6848  * (Caller might throw error later, but not our business to do so here.)
6849  */
6850  record = find_option(name, false, WARNING);
6851  if (record)
6852  flags = record->flags;
6853  else
6854  flags = 0;
6855 
6856  /* Complain if list input and non-list variable */
6857  if ((flags & GUC_LIST_INPUT) == 0 &&
6858  list_length(args) != 1)
6859  ereport(ERROR,
6860  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6861  errmsg("SET %s takes only one argument", name)));
6862 
6863  initStringInfo(&buf);
6864 
6865  /*
6866  * Each list member may be a plain A_Const node, or an A_Const within a
6867  * TypeCast; the latter case is supported only for ConstInterval arguments
6868  * (for SET TIME ZONE).
6869  */
6870  foreach(l, args)
6871  {
6872  Node *arg = (Node *) lfirst(l);
6873  char *val;
6874  TypeName *typeName = NULL;
6875  A_Const *con;
6876 
6877  if (l != list_head(args))
6878  appendStringInfoString(&buf, ", ");
6879 
6880  if (IsA(arg, TypeCast))
6881  {
6882  TypeCast *tc = (TypeCast *) arg;
6883 
6884  arg = tc->arg;
6885  typeName = tc->typeName;
6886  }
6887 
6888  if (!IsA(arg, A_Const))
6889  elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
6890  con = (A_Const *) arg;
6891 
6892  switch (nodeTag(&con->val))
6893  {
6894  case T_Integer:
6895  appendStringInfo(&buf, "%ld", intVal(&con->val));
6896  break;
6897  case T_Float:
6898  /* represented as a string, so just copy it */
6899  appendStringInfoString(&buf, strVal(&con->val));
6900  break;
6901  case T_String:
6902  val = strVal(&con->val);
6903  if (typeName != NULL)
6904  {
6905  /*
6906  * Must be a ConstInterval argument for TIME ZONE. Coerce
6907  * to interval and back to normalize the value and account
6908  * for any typmod.
6909  */
6910  Oid typoid;
6911  int32 typmod;
6912  Datum interval;
6913  char *intervalout;
6914 
6915  typenameTypeIdAndMod(NULL, typeName, &typoid, &typmod);
6916  Assert(typoid == INTERVALOID);
6917 
6918  interval =
6920  CStringGetDatum(val),
6922  Int32GetDatum(typmod));
6923 
6924  intervalout =
6926  interval));
6927  appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
6928  }
6929  else
6930  {
6931  /*
6932  * Plain string literal or identifier. For quote mode,
6933  * quote it if it's not a vanilla identifier.
6934  */
6935  if (flags & GUC_LIST_QUOTE)
6937  else
6938  appendStringInfoString(&buf, val);
6939  }
6940  break;
6941  default:
6942  elog(ERROR, "unrecognized node type: %d",
6943  (int) nodeTag(&con->val));
6944  break;
6945  }
6946  }
6947 
6948  return buf.data;
6949 }
#define NIL
Definition: pg_list.h:69
#define IsA(nodeptr, _type_)
Definition: nodes.h:563
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:10412
Datum interval_in(PG_FUNCTION_ARGS)
Definition: timestamp.c:876
#define GUC_LIST_QUOTE
Definition: guc.h:205
Definition: nodes.h:512
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:575
Datum interval_out(PG_FUNCTION_ARGS)
Definition: timestamp.c:958
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:585
unsigned int Oid
Definition: postgres_ext.h:31
signed int int32
Definition: c.h:284
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:78
#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:157
static char * buf
Definition: pg_test_fsync.c:67
#define CStringGetDatum(X)
Definition: postgres.h:584
#define INTERVALOID
Definition: pg_type.h:529
static ListCell * list_head(const List *l)
Definition: pg_list.h:77
#define ereport(elevel, rest)
Definition: elog.h:122
#define DirectFunctionCall3(func, arg1, arg2, arg3)
Definition: fmgr.h:589
void initStringInfo(StringInfo str)
Definition: stringinfo.c:46
#define WARNING
Definition: elog.h:40
uintptr_t Datum
Definition: postgres.h:372
TypeName * typeName
Definition: parsenodes.h:298
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:4400
#define Assert(condition)
Definition: c.h:670
#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:517
Definition: nodes.h:284
#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:287
long val
Definition: informix.c:689
#define GUC_LIST_INPUT
Definition: guc.h:204
Node * arg
Definition: parsenodes.h:297

◆ get_guc_variables()

struct config_generic** get_guc_variables ( void  )

Definition at line 4215 of file guc.c.

References guc_variables.

Referenced by GucInfoMain().

4216 {
4217  return guc_variables;
4218 }
static struct config_generic ** guc_variables
Definition: guc.c:3963

◆ GetConfigOption()

const char* GetConfigOption ( const char *  name,
bool  missing_ok,
bool  restrict_superuser 
)

Definition at line 6724 of file guc.c.

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

Referenced by applyRemoteGucs(), and PostmasterMain().

6725 {
6726  struct config_generic *record;
6727  static char buffer[256];
6728 
6729  record = find_option(name, false, ERROR);
6730  if (record == NULL)
6731  {
6732  if (missing_ok)
6733  return NULL;
6734  ereport(ERROR,
6735  (errcode(ERRCODE_UNDEFINED_OBJECT),
6736  errmsg("unrecognized configuration parameter \"%s\"",
6737  name)));
6738  }
6739  if (restrict_superuser &&
6740  (record->flags & GUC_SUPERUSER_ONLY) &&
6742  ereport(ERROR,
6743  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6744  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
6745  name)));
6746 
6747  switch (record->vartype)
6748  {
6749  case PGC_BOOL:
6750  return *((struct config_bool *) record)->variable ? "on" : "off";
6751 
6752  case PGC_INT:
6753  snprintf(buffer, sizeof(buffer), "%d",
6754  *((struct config_int *) record)->variable);
6755  return buffer;
6756 
6757  case PGC_REAL:
6758  snprintf(buffer, sizeof(buffer), "%g",
6759  *((struct config_real *) record)->variable);
6760  return buffer;
6761 
6762  case PGC_STRING:
6763  return *((struct config_string *) record)->variable;
6764 
6765  case PGC_ENUM:
6766  return config_enum_lookup_by_value((struct config_enum *) record,
6767  *((struct config_enum *) record)->variable);
6768  }
6769  return NULL;
6770 }
Oid GetUserId(void)
Definition: miscinit.c:284
int errcode(int sqlerrcode)
Definition: elog.c:575
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5645
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
enum config_type vartype
Definition: guc_tables.h:153
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4857
#define DEFAULT_ROLE_READ_ALL_SETTINGS
Definition: pg_authid.h:106
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4400
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:214
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ GetConfigOptionByName()

char* GetConfigOptionByName ( const char *  name,
const char **  varname,
bool  missing_ok 
)

Definition at line 8062 of file guc.c.

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

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

8063 {
8064  struct config_generic *record;
8065 
8066  record = find_option(name, false, ERROR);
8067  if (record == NULL)
8068  {
8069  if (missing_ok)
8070  {
8071  if (varname)
8072  *varname = NULL;
8073  return NULL;
8074  }
8075 
8076  ereport(ERROR,
8077  (errcode(ERRCODE_UNDEFINED_OBJECT),
8078  errmsg("unrecognized configuration parameter \"%s\"", name)));
8079  }
8080 
8081  if ((record->flags & GUC_SUPERUSER_ONLY) &&
8083  ereport(ERROR,
8084  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
8085  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
8086  name)));
8087 
8088  if (varname)
8089  *varname = record->name;
8090 
8091  return _ShowOption(record, true);
8092 }
static char * _ShowOption(struct config_generic *record, bool use_units)
Definition: guc.c:8663
Oid GetUserId(void)
Definition: miscinit.c:284
const char * name
Definition: guc_tables.h:146
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4857
#define DEFAULT_ROLE_READ_ALL_SETTINGS
Definition: pg_authid.h:106
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4400
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ GetConfigOptionByNum()

void GetConfigOptionByNum ( int  varnum,
const char **  values,
bool noshow 
)

Definition at line 8099 of file guc.c.

References _ShowOption(), Assert, config_bool::boot_val, config_int::boot_val, config_real::boot_val, config_string::boot_val, config_enum::boot_val, buffer, config_enum_get_options(), config_enum_lookup_by_value(), config_generic::context, DEFAULT_ROLE_READ_ALL_SETTINGS, elog, ERROR, config_generic::flags, GetUserId(), config_generic::group, GUC_NO_SHOW_ALL, GUC_PENDING_RESTART, GUC_SUPERUSER_ONLY, GUC_UNIT_BLOCKS, GUC_UNIT_BYTE, GUC_UNIT_KB, GUC_UNIT_MB, GUC_UNIT_MEMORY, GUC_UNIT_MIN, GUC_UNIT_MS, GUC_UNIT_S, GUC_UNIT_TIME, GUC_UNIT_XBLOCKS, is_member_of_role(), config_generic::long_desc, config_int::max, config_real::max, config_int::min, config_real::min, config_generic::name, 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().

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