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/tableam.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/trigger.h"
#include "commands/user.h"
#include "commands/vacuum.h"
#include "commands/variable.h"
#include "common/string.h"
#include "funcapi.h"
#include "jit/jit.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/optimizer.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/reorderbuffer.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/fd.h"
#include "storage/large_object.h"
#include "storage/pg_shmem.h"
#include "storage/predicate.h"
#include "storage/proc.h"
#include "storage/standby.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/pg_lsn.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 void assign_tcp_user_timeout (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 const char * show_tcp_user_timeout (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_max_wal_senders (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 const char * show_data_directory_mode (void)
 
static bool check_backtrace_functions (char **newval, void **extra, GucSource source)
 
static void assign_backtrace_functions (const char *newval, void *extra)
 
static bool check_recovery_target_timeline (char **newval, void **extra, GucSource source)
 
static void assign_recovery_target_timeline (const char *newval, void *extra)
 
static bool check_recovery_target (char **newval, void **extra, GucSource source)
 
static void assign_recovery_target (const char *newval, void *extra)
 
static bool check_recovery_target_xid (char **newval, void **extra, GucSource source)
 
static void assign_recovery_target_xid (const char *newval, void *extra)
 
static bool check_recovery_target_time (char **newval, void **extra, GucSource source)
 
static void assign_recovery_target_time (const char *newval, void *extra)
 
static bool check_recovery_target_name (char **newval, void **extra, GucSource source)
 
static void assign_recovery_target_name (const char *newval, void *extra)
 
static bool check_recovery_target_lsn (char **newval, void **extra, GucSource source)
 
static void assign_recovery_target_lsn (const char *newval, void *extra)
 
static bool check_primary_slot_name (char **newval, void **extra, GucSource source)
 
static bool check_default_with_oids (bool *newval, void **extra, GucSource source)
 
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 (double value, const char *unit, int base_unit, double *base_value)
 
static void convert_int_from_base_unit (int64 base_value, int base_unit, int64 *value, const char **unit)
 
static void convert_real_from_base_unit (double base_value, int base_unit, double *value, const char **unit)
 
static const char * get_config_unit_name (int flags)
 
bool parse_int (const char *value, int *result, int flags, const char **hintmsg)
 
bool parse_real (const char *value, double *result, int flags, const char **hintmsg)
 
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_privileged)
 
const char * GetConfigOptionResetString (const char *name)
 
int GetConfigOptionFlags (const char *name, bool missing_ok)
 
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)
 
struct config_generic ** get_explain_guc_options (int *num)
 
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)
 
static void guc_restore_error_context_callback (void *arg)
 
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)
 
static void pg_attribute_noreturn ()
 

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 plan_cache_mode_options []
 
static const struct config_enum_entry password_encryption_options []
 
const struct config_enum_entry ssl_protocol_versions_info []
 
static struct config_enum_entry shared_memory_options []
 
const struct config_enum_entry wal_level_options []
 
const struct config_enum_entry archive_mode_options []
 
const struct config_enum_entry recovery_target_action_options []
 
const struct config_enum_entry sync_method_options []
 
const struct config_enum_entry dynamic_shared_memory_options []
 
bool log_duration = false
 
bool log_parameters_on_error = 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_sample = -1
 
int log_min_duration_statement = -1
 
int log_temp_files = -1
 
double log_statement_sample_rate = 1.0
 
double log_xact_sample_rate = 0
 
int trace_recovery_messages = LOG
 
char * backtrace_functions
 
char * backtrace_symbol_list
 
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 tcp_user_timeout
 
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 * 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
 
static char * recovery_target_timeline_string
 
static char * recovery_target_string
 
static char * recovery_target_xid_string
 
static char * recovery_target_name_string
 
static char * recovery_target_lsn_string
 
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 \"B\", \"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 \"us\", \"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 num_guc_explain_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 104 of file guc.c.

Referenced by SelectConfigFiles().

◆ HBA_FILENAME

#define HBA_FILENAME   "pg_hba.conf"

Definition at line 105 of file guc.c.

Referenced by SelectConfigFiles().

◆ IDENT_FILENAME

#define IDENT_FILENAME   "pg_ident.conf"

Definition at line 106 of file guc.c.

Referenced by SelectConfigFiles().

◆ MAX_UNIT_LEN

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

Definition at line 776 of file guc.c.

Referenced by convert_to_base_unit().

◆ newval [1/5]

#define newval   (newval_union.boolval)

◆ 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 9363 of file guc.c.

Referenced by show_all_settings().

◆ PG_KRB_SRVTAB

#define PG_KRB_SRVTAB   ""

Definition at line 101 of file guc.c.

◆ REALTYPE_PRECISION

#define REALTYPE_PRECISION   17

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

References AllocateFile(), Assert, config_enum_lookup_by_value(), convert_int_from_base_unit(), convert_real_from_base_unit(), elevel, elog, ereport, errcode_for_file_access(), errmsg(), ERROR, FATAL, find_option(), config_generic::flags, fprintf, 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().

9610 {
9611  char buffer[256];
9612  const char *val;
9613 
9614  switch (record->vartype)
9615  {
9616  case PGC_BOOL:
9617  {
9618  struct config_bool *conf = (struct config_bool *) record;
9619 
9620  if (conf->show_hook)
9621  val = conf->show_hook();
9622  else
9623  val = *conf->variable ? "on" : "off";
9624  }
9625  break;
9626 
9627  case PGC_INT:
9628  {
9629  struct config_int *conf = (struct config_int *) record;
9630 
9631  if (conf->show_hook)
9632  val = conf->show_hook();
9633  else
9634  {
9635  /*
9636  * Use int64 arithmetic to avoid overflows in units
9637  * conversion.
9638  */
9639  int64 result = *conf->variable;
9640  const char *unit;
9641 
9642  if (use_units && result > 0 && (record->flags & GUC_UNIT))
9644  record->flags & GUC_UNIT,
9645  &result, &unit);
9646  else
9647  unit = "";
9648 
9649  snprintf(buffer, sizeof(buffer), INT64_FORMAT "%s",
9650  result, unit);
9651  val = buffer;
9652  }
9653  }
9654  break;
9655 
9656  case PGC_REAL:
9657  {
9658  struct config_real *conf = (struct config_real *) record;
9659 
9660  if (conf->show_hook)
9661  val = conf->show_hook();
9662  else
9663  {
9664  double result = *conf->variable;
9665  const char *unit;
9666 
9667  if (use_units && result > 0 && (record->flags & GUC_UNIT))
9669  record->flags & GUC_UNIT,
9670  &result, &unit);
9671  else
9672  unit = "";
9673 
9674  snprintf(buffer, sizeof(buffer), "%g%s",
9675  result, unit);
9676  val = buffer;
9677  }
9678  }
9679  break;
9680 
9681  case PGC_STRING:
9682  {
9683  struct config_string *conf = (struct config_string *) record;
9684 
9685  if (conf->show_hook)
9686  val = conf->show_hook();
9687  else if (*conf->variable && **conf->variable)
9688  val = *conf->variable;
9689  else
9690  val = "";
9691  }
9692  break;
9693 
9694  case PGC_ENUM:
9695  {
9696  struct config_enum *conf = (struct config_enum *) record;
9697 
9698  if (conf->show_hook)
9699  val = conf->show_hook();
9700  else
9701  val = config_enum_lookup_by_value(conf, *conf->variable);
9702  }
9703  break;
9704 
9705  default:
9706  /* just to keep compiler quiet */
9707  val = "???";
9708  break;
9709  }
9710 
9711  return pstrdup(val);
9712 }
char ** variable
Definition: guc_tables.h:230
char * pstrdup(const char *in)
Definition: mcxt.c:1186
bool * variable
Definition: guc_tables.h:184
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:6490
#define GUC_UNIT
Definition: guc.h:232
GucShowHook show_hook
Definition: guc_tables.h:204
int * variable
Definition: guc_tables.h:198
int * variable
Definition: guc_tables.h:244
static void convert_real_from_base_unit(double base_value, int base_unit, double *value, const char **unit)
Definition: guc.c:6238
GucShowHook show_hook
Definition: guc_tables.h:234
GucShowHook show_hook
Definition: guc_tables.h:220
double * variable
Definition: guc_tables.h:214
enum config_type vartype
Definition: guc_tables.h:156
GucShowHook show_hook
Definition: guc_tables.h:249
GucShowHook show_hook
Definition: guc_tables.h:188
#define INT64_FORMAT
Definition: c.h:401
static void convert_int_from_base_unit(int64 base_value, int base_unit, int64 *value, const char **unit)
Definition: guc.c:6196
#define snprintf
Definition: port.h:192
long val
Definition: informix.c:664

◆ add_guc_variable()

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

Definition at line 5008 of file guc.c.

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

Referenced by add_placeholder_variable(), and define_custom_variable().

5009 {
5011  {
5012  /*
5013  * Increase the vector by 25%
5014  */
5015  int size_vars = size_guc_variables + size_guc_variables / 4;
5016  struct config_generic **guc_vars;
5017 
5018  if (size_vars == 0)
5019  {
5020  size_vars = 100;
5021  guc_vars = (struct config_generic **)
5022  guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
5023  }
5024  else
5025  {
5026  guc_vars = (struct config_generic **)
5027  guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
5028  }
5029 
5030  if (guc_vars == NULL)
5031  return false; /* out of memory */
5032 
5033  guc_variables = guc_vars;
5034  size_guc_variables = size_vars;
5035  }
5038  sizeof(struct config_generic *), guc_var_compare);
5039  return true;
5040 }
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:5143
static int num_guc_variables
Definition: guc.c:4640
static void * guc_realloc(int elevel, void *old, size_t size)
Definition: guc.c:4697
static struct config_generic ** guc_variables
Definition: guc.c:4637
static int size_guc_variables
Definition: guc.c:4646
static int elevel
Definition: vacuumlazy.c:143
#define qsort(a, b, c, d)
Definition: port.h:491
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4681

◆ add_placeholder_variable()

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

Definition at line 5046 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, unconstify, config_string::variable, and config_generic::vartype.

Referenced by find_option().

5047 {
5048  size_t sz = sizeof(struct config_string) + sizeof(char *);
5049  struct config_string *var;
5050  struct config_generic *gen;
5051 
5052  var = (struct config_string *) guc_malloc(elevel, sz);
5053  if (var == NULL)
5054  return NULL;
5055  memset(var, 0, sz);
5056  gen = &var->gen;
5057 
5058  gen->name = guc_strdup(elevel, name);
5059  if (gen->name == NULL)
5060  {
5061  free(var);
5062  return NULL;
5063  }
5064 
5065  gen->context = PGC_USERSET;
5066  gen->group = CUSTOM_OPTIONS;
5067  gen->short_desc = "GUC placeholder variable";
5069  gen->vartype = PGC_STRING;
5070 
5071  /*
5072  * The char* is allocated at the end of the struct since we have no
5073  * 'static' place to point to. Note that the current value, as well as
5074  * the boot and reset values, start out NULL.
5075  */
5076  var->variable = (char **) (var + 1);
5077 
5078  if (!add_guc_variable((struct config_generic *) var, elevel))
5079  {
5080  free(unconstify(char *, gen->name));
5081  free(var);
5082  return NULL;
5083  }
5084 
5085  return gen;
5086 }
char ** variable
Definition: guc_tables.h:230
const char * name
Definition: guc_tables.h:149
const char * short_desc
Definition: guc_tables.h:152
static char * guc_strdup(int elevel, const char *src)
Definition: guc.c:4713
#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:156
#define unconstify(underlying_type, expr)
Definition: c.h:1193
static int elevel
Definition: vacuumlazy.c:143
struct config_generic gen
Definition: guc_tables.h:228
#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:151
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4681
GucContext context
Definition: guc_tables.h:150
static bool add_guc_variable(struct config_generic *var, int elevel)
Definition: guc.c:5008

◆ AlterSystemSetConfigFile()

void AlterSystemSetConfigFile ( AlterSystemStmt altersysstmt)

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

7979 {
7980  char *name;
7981  char *value;
7982  bool resetall = false;
7983  ConfigVariable *head = NULL;
7984  ConfigVariable *tail = NULL;
7985  volatile int Tmpfd;
7986  char AutoConfFileName[MAXPGPATH];
7987  char AutoConfTmpFileName[MAXPGPATH];
7988 
7989  if (!superuser())
7990  ereport(ERROR,
7991  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7992  (errmsg("must be superuser to execute ALTER SYSTEM command"))));
7993 
7994  /*
7995  * Extract statement arguments
7996  */
7997  name = altersysstmt->setstmt->name;
7998 
7999  switch (altersysstmt->setstmt->kind)
8000  {
8001  case VAR_SET_VALUE:
8002  value = ExtractSetVariableArgs(altersysstmt->setstmt);
8003  break;
8004 
8005  case VAR_SET_DEFAULT:
8006  case VAR_RESET:
8007  value = NULL;
8008  break;
8009 
8010  case VAR_RESET_ALL:
8011  value = NULL;
8012  resetall = true;
8013  break;
8014 
8015  default:
8016  elog(ERROR, "unrecognized alter system stmt type: %d",
8017  altersysstmt->setstmt->kind);
8018  break;
8019  }
8020 
8021  /*
8022  * Unless it's RESET_ALL, validate the target variable and value
8023  */
8024  if (!resetall)
8025  {
8026  struct config_generic *record;
8027 
8028  record = find_option(name, false, ERROR);
8029  if (record == NULL)
8030  ereport(ERROR,
8031  (errcode(ERRCODE_UNDEFINED_OBJECT),
8032  errmsg("unrecognized configuration parameter \"%s\"",
8033  name)));
8034 
8035  /*
8036  * Don't allow parameters that can't be set in configuration files to
8037  * be set in PG_AUTOCONF_FILENAME file.
8038  */
8039  if ((record->context == PGC_INTERNAL) ||
8040  (record->flags & GUC_DISALLOW_IN_FILE) ||
8041  (record->flags & GUC_DISALLOW_IN_AUTO_FILE))
8042  ereport(ERROR,
8043  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
8044  errmsg("parameter \"%s\" cannot be changed",
8045  name)));
8046 
8047  /*
8048  * If a value is specified, verify that it's sane.
8049  */
8050  if (value)
8051  {
8052  union config_var_val newval;
8053  void *newextra = NULL;
8054 
8055  /* Check that it's acceptable for the indicated parameter */
8056  if (!parse_and_validate_value(record, name, value,
8057  PGC_S_FILE, ERROR,
8058  &newval, &newextra))
8059  ereport(ERROR,
8060  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8061  errmsg("invalid value for parameter \"%s\": \"%s\"",
8062  name, value)));
8063 
8064  if (record->vartype == PGC_STRING && newval.stringval != NULL)
8065  free(newval.stringval);
8066  if (newextra)
8067  free(newextra);
8068 
8069  /*
8070  * We must also reject values containing newlines, because the
8071  * grammar for config files doesn't support embedded newlines in
8072  * string literals.
8073  */
8074  if (strchr(value, '\n'))
8075  ereport(ERROR,
8076  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8077  errmsg("parameter value for ALTER SYSTEM must not contain a newline")));
8078  }
8079  }
8080 
8081  /*
8082  * PG_AUTOCONF_FILENAME and its corresponding temporary file are always in
8083  * the data directory, so we can reference them by simple relative paths.
8084  */
8085  snprintf(AutoConfFileName, sizeof(AutoConfFileName), "%s",
8087  snprintf(AutoConfTmpFileName, sizeof(AutoConfTmpFileName), "%s.%s",
8088  AutoConfFileName,
8089  "tmp");
8090 
8091  /*
8092  * Only one backend is allowed to operate on PG_AUTOCONF_FILENAME at a
8093  * time. Use AutoFileLock to ensure that. We must hold the lock while
8094  * reading the old file contents.
8095  */
8096  LWLockAcquire(AutoFileLock, LW_EXCLUSIVE);
8097 
8098  /*
8099  * If we're going to reset everything, then no need to open or parse the
8100  * old file. We'll just write out an empty list.
8101  */
8102  if (!resetall)
8103  {
8104  struct stat st;
8105 
8106  if (stat(AutoConfFileName, &st) == 0)
8107  {
8108  /* open old file PG_AUTOCONF_FILENAME */
8109  FILE *infile;
8110 
8111  infile = AllocateFile(AutoConfFileName, "r");
8112  if (infile == NULL)
8113  ereport(ERROR,
8115  errmsg("could not open file \"%s\": %m",
8116  AutoConfFileName)));
8117 
8118  /* parse it */
8119  if (!ParseConfigFp(infile, AutoConfFileName, 0, LOG, &head, &tail))
8120  ereport(ERROR,
8121  (errcode(ERRCODE_CONFIG_FILE_ERROR),
8122  errmsg("could not parse contents of file \"%s\"",
8123  AutoConfFileName)));
8124 
8125  FreeFile(infile);
8126  }
8127 
8128  /*
8129  * Now, replace any existing entry with the new value, or add it if
8130  * not present.
8131  */
8132  replace_auto_config_value(&head, &tail, name, value);
8133  }
8134 
8135  /*
8136  * To ensure crash safety, first write the new file data to a temp file,
8137  * then atomically rename it into place.
8138  *
8139  * If there is a temp file left over due to a previous crash, it's okay to
8140  * truncate and reuse it.
8141  */
8142  Tmpfd = BasicOpenFile(AutoConfTmpFileName,
8143  O_CREAT | O_RDWR | O_TRUNC);
8144  if (Tmpfd < 0)
8145  ereport(ERROR,
8147  errmsg("could not open file \"%s\": %m",
8148  AutoConfTmpFileName)));
8149 
8150  /*
8151  * Use a TRY block to clean up the file if we fail. Since we need a TRY
8152  * block anyway, OK to use BasicOpenFile rather than OpenTransientFile.
8153  */
8154  PG_TRY();
8155  {
8156  /* Write and sync the new contents to the temporary file */
8157  write_auto_conf_file(Tmpfd, AutoConfTmpFileName, head);
8158 
8159  /* Close before renaming; may be required on some platforms */
8160  close(Tmpfd);
8161  Tmpfd = -1;
8162 
8163  /*
8164  * As the rename is atomic operation, if any problem occurs after this
8165  * at worst it can lose the parameters set by last ALTER SYSTEM
8166  * command.
8167  */
8168  durable_rename(AutoConfTmpFileName, AutoConfFileName, ERROR);
8169  }
8170  PG_CATCH();
8171  {
8172  /* Close file first, else unlink might fail on some platforms */
8173  if (Tmpfd >= 0)
8174  close(Tmpfd);
8175 
8176  /* Unlink, but ignore any error */
8177  (void) unlink(AutoConfTmpFileName);
8178 
8179  PG_RE_THROW();
8180  }
8181  PG_END_TRY();
8182 
8183  FreeConfigVariables(head);
8184 
8185  LWLockRelease(AutoFileLock);
8186 }
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:6597
VariableSetKind kind
Definition: parsenodes.h:2039
static struct @145 value
int errcode(int sqlerrcode)
Definition: elog.c:608
bool superuser(void)
Definition: superuser.c:46
#define LOG
Definition: elog.h:26
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1726
#define ERROR
Definition: elog.h:43
#define MAXPGPATH
VariableSetStmt * setstmt
Definition: parsenodes.h:3178
int errcode_for_file_access(void)
Definition: elog.c:631
FILE * AllocateFile(const char *name, const char *mode)
Definition: fd.c:2242
#define ereport(elevel, rest)
Definition: elog.h:141
int durable_rename(const char *oldfile, const char *newfile, int elevel)
Definition: fd.c:643
enum config_type vartype
Definition: guc_tables.h:156
#define stat(a, b)
Definition: win32_port.h:255
#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:7840
static void infile(const char *filename)
Definition: zic.c:1233
#define free(a)
Definition: header.h:65
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:5094
#define PG_CATCH()
Definition: elog.h:332
#define newval
#define PG_AUTOCONF_FILENAME
Definition: guc.h:34
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1122
#define PG_RE_THROW()
Definition: elog.h:363
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:981
int FreeFile(FILE *file)
Definition: fd.c:2441
int errmsg(const char *fmt,...)
Definition: elog.c:822
bool ParseConfigFp(FILE *fp, const char *config_file, int depth, int elevel, ConfigVariable **head_p, ConfigVariable **tail_p)
#define elog(elevel,...)
Definition: elog.h:228
static void replace_auto_config_value(ConfigVariable **head_p, ConfigVariable **tail_p, const char *name, const char *value)
Definition: guc.c:7908
void FreeConfigVariables(ConfigVariable *list)
#define close(a)
Definition: win32.h:12
#define PG_TRY()
Definition: elog.h:322
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
Definition: guc.c:8316
#define snprintf
Definition: port.h:192
#define PG_END_TRY()
Definition: elog.h:347
GucContext context
Definition: guc_tables.h:150

◆ assign_application_name()

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

Definition at line 11494 of file guc.c.

References pgstat_report_appname().

11495 {
11496  /* Update the pg_stat_activity view */
11498 }
void pgstat_report_appname(const char *appname)
Definition: pgstat.c:3287
#define newval

◆ assign_backtrace_functions()

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

Definition at line 11601 of file guc.c.

11602 {
11603  backtrace_symbol_list = (char *) extra;
11604 }
char * backtrace_symbol_list
Definition: guc.c:523

◆ assign_effective_io_concurrency()

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

Definition at line 11448 of file guc.c.

References target_prefetch_pages.

11449 {
11450 #ifdef USE_PREFETCH
11451  target_prefetch_pages = *((int *) extra);
11452 #endif /* USE_PREFETCH */
11453 }
int target_prefetch_pages
Definition: bufmgr.c:130

◆ assign_log_destination()

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

Definition at line 11103 of file guc.c.

References Log_destination.

11104 {
11105  Log_destination = *((int *) extra);
11106 }
int Log_destination
Definition: elog.c:109

◆ assign_pgstat_temp_directory()

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

Definition at line 11456 of file guc.c.

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

11457 {
11458  /* check_canonical_path already canonicalized newval for us */
11459  char *dname;
11460  char *tname;
11461  char *fname;
11462 
11463  /* directory */
11464  dname = guc_malloc(ERROR, strlen(newval) + 1); /* runtime dir */
11465  sprintf(dname, "%s", newval);
11466 
11467  /* global stats */
11468  tname = guc_malloc(ERROR, strlen(newval) + 12); /* /global.tmp */
11469  sprintf(tname, "%s/global.tmp", newval);
11470  fname = guc_malloc(ERROR, strlen(newval) + 13); /* /global.stat */
11471  sprintf(fname, "%s/global.stat", newval);
11472 
11475  pgstat_stat_directory = dname;
11476  if (pgstat_stat_tmpname)
11478  pgstat_stat_tmpname = tname;
11481  pgstat_stat_filename = fname;
11482 }
#define sprintf
Definition: port.h:194
char * pgstat_stat_filename
Definition: pgstat.c:134
#define ERROR
Definition: elog.h:43
char * pgstat_stat_directory
Definition: pgstat.c:133
#define free(a)
Definition: header.h:65
#define newval
char * pgstat_stat_tmpname
Definition: pgstat.c:135
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4681

◆ assign_recovery_target()

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

Definition at line 11680 of file guc.c.

References RECOVERY_TARGET_IMMEDIATE, RECOVERY_TARGET_UNSET, and recoveryTarget.

11681 {
11684  error_multiple_recovery_targets();
11685 
11686  if (newval && strcmp(newval, "") != 0)
11688  else
11690 }
#define newval
RecoveryTargetType recoveryTarget
Definition: xlog.c:271

◆ assign_recovery_target_lsn()

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

Definition at line 11848 of file guc.c.

References RECOVERY_TARGET_LSN, RECOVERY_TARGET_UNSET, recoveryTarget, and recoveryTargetLSN.

11849 {
11852  error_multiple_recovery_targets();
11853 
11854  if (newval && strcmp(newval, "") != 0)
11855  {
11857  recoveryTargetLSN = *((XLogRecPtr *) extra);
11858  }
11859  else
11861 }
XLogRecPtr recoveryTargetLSN
Definition: xlog.c:278
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define newval
RecoveryTargetType recoveryTarget
Definition: xlog.c:271

◆ assign_recovery_target_name()

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

Definition at line 11812 of file guc.c.

References newval, RECOVERY_TARGET_NAME, RECOVERY_TARGET_UNSET, recoveryTarget, and recoveryTargetName.

11813 {
11816  error_multiple_recovery_targets();
11817 
11818  if (newval && strcmp(newval, "") != 0)
11819  {
11822  }
11823  else
11825 }
const char * recoveryTargetName
Definition: xlog.c:277
#define newval
RecoveryTargetType recoveryTarget
Definition: xlog.c:271

◆ assign_recovery_target_time()

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

Definition at line 11786 of file guc.c.

References RECOVERY_TARGET_TIME, RECOVERY_TARGET_UNSET, and recoveryTarget.

11787 {
11790  error_multiple_recovery_targets();
11791 
11792  if (newval && strcmp(newval, "") != 0)
11794  else
11796 }
#define newval
RecoveryTargetType recoveryTarget
Definition: xlog.c:271

◆ assign_recovery_target_timeline()

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

Definition at line 11637 of file guc.c.

References RECOVERY_TARGET_TIMELINE_NUMERIC, recoveryTargetTimeLineGoal, and recoveryTargetTLIRequested.

11638 {
11641  recoveryTargetTLIRequested = (TimeLineID) strtoul(newval, NULL, 0);
11642  else
11644 }
TimeLineID recoveryTargetTLIRequested
Definition: xlog.c:330
uint32 TimeLineID
Definition: xlogdefs.h:52
RecoveryTargetTimeLineGoal
Definition: xlog.h:93
RecoveryTargetTimeLineGoal recoveryTargetTimeLineGoal
Definition: xlog.c:329
#define newval

◆ assign_recovery_target_xid()

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

Definition at line 11713 of file guc.c.

References RECOVERY_TARGET_UNSET, RECOVERY_TARGET_XID, recoveryTarget, and recoveryTargetXid.

11714 {
11717  error_multiple_recovery_targets();
11718 
11719  if (newval && strcmp(newval, "") != 0)
11720  {
11722  recoveryTargetXid = *((TransactionId *) extra);
11723  }
11724  else
11726 }
uint32 TransactionId
Definition: c.h:514
TransactionId recoveryTargetXid
Definition: xlog.c:274
#define newval
RecoveryTargetType recoveryTarget
Definition: xlog.c:271

◆ assign_session_replication_role()

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

Definition at line 11129 of file guc.c.

References ResetPlanCache(), and SessionReplicationRole.

11130 {
11131  /*
11132  * Must flush the plan cache when changing replication role; but don't
11133  * flush unnecessarily.
11134  */
11136  ResetPlanCache();
11137 }
int SessionReplicationRole
Definition: trigger.c:67
void ResetPlanCache(void)
Definition: plancache.c:1966
#define newval

◆ assign_syslog_facility()

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

Definition at line 11109 of file guc.c.

11110 {
11111 #ifdef HAVE_SYSLOG
11112  set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
11113  newval);
11114 #endif
11115  /* Without syslog support, just ignore it */
11116 }
static char * syslog_ident_str
Definition: guc.c:563
#define newval

◆ assign_syslog_ident()

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

Definition at line 11119 of file guc.c.

11120 {
11121 #ifdef HAVE_SYSLOG
11122  set_syslog_parameters(newval, syslog_facility);
11123 #endif
11124  /* Without syslog support, it will always be set to "none", so ignore */
11125 }
static int syslog_facility
Definition: guc.c:167
#define newval

◆ assign_tcp_keepalives_count()

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

Definition at line 11328 of file guc.c.

References MyProcPort, and pq_setkeepalivescount().

11329 {
11330  /* See comments in assign_tcp_keepalives_idle */
11332 }
struct Port * MyProcPort
Definition: globals.c:43
int pq_setkeepalivescount(int count, Port *port)
Definition: pqcomm.c:1889
#define newval

◆ assign_tcp_keepalives_idle()

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

Definition at line 11284 of file guc.c.

References MyProcPort, and pq_setkeepalivesidle().

11285 {
11286  /*
11287  * The kernel API provides no way to test a value without setting it; and
11288  * once we set it we might fail to unset it. So there seems little point
11289  * in fully implementing the check-then-assign GUC API for these
11290  * variables. Instead we just do the assignment on demand. pqcomm.c
11291  * reports any problems via elog(LOG).
11292  *
11293  * This approach means that the GUC value might have little to do with the
11294  * actual kernel value, so we use a show_hook that retrieves the kernel
11295  * value rather than trusting GUC's copy.
11296  */
11298 }
struct Port * MyProcPort
Definition: globals.c:43
int pq_setkeepalivesidle(int idle, Port *port)
Definition: pqcomm.c:1731
#define newval

◆ assign_tcp_keepalives_interval()

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

Definition at line 11311 of file guc.c.

References MyProcPort, and pq_setkeepalivesinterval().

11312 {
11313  /* See comments in assign_tcp_keepalives_idle */
11315 }
struct Port * MyProcPort
Definition: globals.c:43
int pq_setkeepalivesinterval(int interval, Port *port)
Definition: pqcomm.c:1813
#define newval

◆ assign_tcp_user_timeout()

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

Definition at line 11345 of file guc.c.

References MyProcPort, and pq_settcpusertimeout().

11346 {
11347  /* See comments in assign_tcp_keepalives_idle */
11349 }
struct Port * MyProcPort
Definition: globals.c:43
#define newval
int pq_settcpusertimeout(int timeout, Port *port)
Definition: pqcomm.c:1961

◆ assign_timezone_abbreviations()

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

Definition at line 11248 of file guc.c.

References InstallTimeZoneAbbrevs().

11249 {
11250  /* Do nothing for the boot_val default of NULL */
11251  if (!extra)
11252  return;
11253 
11255 }
void InstallTimeZoneAbbrevs(TimeZoneAbbrevTable *tbl)
Definition: datetime.c:4581

◆ assign_wal_consistency_checking()

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

Definition at line 11040 of file guc.c.

References wal_consistency_checking.

11041 {
11042  wal_consistency_checking = (bool *) extra;
11043 }
bool * wal_consistency_checking
Definition: xlog.c:98

◆ AtEOXact_GUC()

void AtEOXact_GUC ( bool  isCommit,
int  nestLevel 
)

Definition at line 5801 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(), DefineIndex(), do_analyze_rel(), ExecCreateTableAs(), ExecRefreshMatView(), execute_extension_script(), fmgr_security_definer(), index_build(), PrepareTransaction(), ProcedureCreate(), reset_transmission_modes(), restoreLocalGucs(), RI_Initial_Check(), RI_PartitionRemove_Check(), vacuum_rel(), and validate_index().

5802 {
5803  bool still_dirty;
5804  int i;
5805 
5806  /*
5807  * Note: it's possible to get here with GUCNestLevel == nestLevel-1 during
5808  * abort, if there is a failure during transaction start before
5809  * AtStart_GUC is called.
5810  */
5811  Assert(nestLevel > 0 &&
5812  (nestLevel <= GUCNestLevel ||
5813  (nestLevel == GUCNestLevel + 1 && !isCommit)));
5814 
5815  /* Quick exit if nothing's changed in this transaction */
5816  if (!guc_dirty)
5817  {
5818  GUCNestLevel = nestLevel - 1;
5819  return;
5820  }
5821 
5822  still_dirty = false;
5823  for (i = 0; i < num_guc_variables; i++)
5824  {
5825  struct config_generic *gconf = guc_variables[i];
5826  GucStack *stack;
5827 
5828  /*
5829  * Process and pop each stack entry within the nest level. To simplify
5830  * fmgr_security_definer() and other places that use GUC_ACTION_SAVE,
5831  * we allow failure exit from code that uses a local nest level to be
5832  * recovered at the surrounding transaction or subtransaction abort;
5833  * so there could be more than one stack entry to pop.
5834  */
5835  while ((stack = gconf->stack) != NULL &&
5836  stack->nest_level >= nestLevel)
5837  {
5838  GucStack *prev = stack->prev;
5839  bool restorePrior = false;
5840  bool restoreMasked = false;
5841  bool changed;
5842 
5843  /*
5844  * In this next bit, if we don't set either restorePrior or
5845  * restoreMasked, we must "discard" any unwanted fields of the
5846  * stack entries to avoid leaking memory. If we do set one of
5847  * those flags, unused fields will be cleaned up after restoring.
5848  */
5849  if (!isCommit) /* if abort, always restore prior value */
5850  restorePrior = true;
5851  else if (stack->state == GUC_SAVE)
5852  restorePrior = true;
5853  else if (stack->nest_level == 1)
5854  {
5855  /* transaction commit */
5856  if (stack->state == GUC_SET_LOCAL)
5857  restoreMasked = true;
5858  else if (stack->state == GUC_SET)
5859  {
5860  /* we keep the current active value */
5861  discard_stack_value(gconf, &stack->prior);
5862  }
5863  else /* must be GUC_LOCAL */
5864  restorePrior = true;
5865  }
5866  else if (prev == NULL ||
5867  prev->nest_level < stack->nest_level - 1)
5868  {
5869  /* decrement entry's level and do not pop it */
5870  stack->nest_level--;
5871  continue;
5872  }
5873  else
5874  {
5875  /*
5876  * We have to merge this stack entry into prev. See README for
5877  * discussion of this bit.
5878  */
5879  switch (stack->state)
5880  {
5881  case GUC_SAVE:
5882  Assert(false); /* can't get here */
5883  break;
5884 
5885  case GUC_SET:
5886  /* next level always becomes SET */
5887  discard_stack_value(gconf, &stack->prior);
5888  if (prev->state == GUC_SET_LOCAL)
5889  discard_stack_value(gconf, &prev->masked);
5890  prev->state = GUC_SET;
5891  break;
5892 
5893  case GUC_LOCAL:
5894  if (prev->state == GUC_SET)
5895  {
5896  /* LOCAL migrates down */
5897  prev->masked_scontext = stack->scontext;
5898  prev->masked = stack->prior;
5899  prev->state = GUC_SET_LOCAL;
5900  }
5901  else
5902  {
5903  /* else just forget this stack level */
5904  discard_stack_value(gconf, &stack->prior);
5905  }
5906  break;
5907 
5908  case GUC_SET_LOCAL:
5909  /* prior state at this level no longer wanted */
5910  discard_stack_value(gconf, &stack->prior);
5911  /* copy down the masked state */
5912  prev->masked_scontext = stack->masked_scontext;
5913  if (prev->state == GUC_SET_LOCAL)
5914  discard_stack_value(gconf, &prev->masked);
5915  prev->masked = stack->masked;
5916  prev->state = GUC_SET_LOCAL;
5917  break;
5918  }
5919  }
5920 
5921  changed = false;
5922 
5923  if (restorePrior || restoreMasked)
5924  {
5925  /* Perform appropriate restoration of the stacked value */
5926  config_var_value newvalue;
5927  GucSource newsource;
5928  GucContext newscontext;
5929 
5930  if (restoreMasked)
5931  {
5932  newvalue = stack->masked;
5933  newsource = PGC_S_SESSION;
5934  newscontext = stack->masked_scontext;
5935  }
5936  else
5937  {
5938  newvalue = stack->prior;
5939  newsource = stack->source;
5940  newscontext = stack->scontext;
5941  }
5942 
5943  switch (gconf->vartype)
5944  {
5945  case PGC_BOOL:
5946  {
5947  struct config_bool *conf = (struct config_bool *) gconf;
5948  bool newval = newvalue.val.boolval;
5949  void *newextra = newvalue.extra;
5950 
5951  if (*conf->variable != newval ||
5952  conf->gen.extra != newextra)
5953  {
5954  if (conf->assign_hook)
5955  conf->assign_hook(newval, newextra);
5956  *conf->variable = newval;
5957  set_extra_field(&conf->gen, &conf->gen.extra,
5958  newextra);
5959  changed = true;
5960  }
5961  break;
5962  }
5963  case PGC_INT:
5964  {
5965  struct config_int *conf = (struct config_int *) gconf;
5966  int newval = newvalue.val.intval;
5967  void *newextra = newvalue.extra;
5968 
5969  if (*conf->variable != newval ||
5970  conf->gen.extra != newextra)
5971  {
5972  if (conf->assign_hook)
5973  conf->assign_hook(newval, newextra);
5974  *conf->variable = newval;
5975  set_extra_field(&conf->gen, &conf->gen.extra,
5976  newextra);
5977  changed = true;
5978  }
5979  break;
5980  }
5981  case PGC_REAL:
5982  {
5983  struct config_real *conf = (struct config_real *) gconf;
5984  double newval = newvalue.val.realval;
5985  void *newextra = newvalue.extra;
5986 
5987  if (*conf->variable != newval ||
5988  conf->gen.extra != newextra)
5989  {
5990  if (conf->assign_hook)
5991  conf->assign_hook(newval, newextra);
5992  *conf->variable = newval;
5993  set_extra_field(&conf->gen, &conf->gen.extra,
5994  newextra);
5995  changed = true;
5996  }
5997  break;
5998  }
5999  case PGC_STRING:
6000  {
6001  struct config_string *conf = (struct config_string *) gconf;
6002  char *newval = newvalue.val.stringval;
6003  void *newextra = newvalue.extra;
6004 
6005  if (*conf->variable != newval ||
6006  conf->gen.extra != newextra)
6007  {
6008  if (conf->assign_hook)
6009  conf->assign_hook(newval, newextra);
6010  set_string_field(conf, conf->variable, newval);
6011  set_extra_field(&conf->gen, &conf->gen.extra,
6012  newextra);
6013  changed = true;
6014  }
6015 
6016  /*
6017  * Release stacked values if not used anymore. We
6018  * could use discard_stack_value() here, but since
6019  * we have type-specific code anyway, might as
6020  * well inline it.
6021  */
6022  set_string_field(conf, &stack->prior.val.stringval, NULL);
6023  set_string_field(conf, &stack->masked.val.stringval, NULL);
6024  break;
6025  }
6026  case PGC_ENUM:
6027  {
6028  struct config_enum *conf = (struct config_enum *) gconf;
6029  int newval = newvalue.val.enumval;
6030  void *newextra = newvalue.extra;
6031 
6032  if (*conf->variable != newval ||
6033  conf->gen.extra != newextra)
6034  {
6035  if (conf->assign_hook)
6036  conf->assign_hook(newval, newextra);
6037  *conf->variable = newval;
6038  set_extra_field(&conf->gen, &conf->gen.extra,
6039  newextra);
6040  changed = true;
6041  }
6042  break;
6043  }
6044  }
6045 
6046  /*
6047  * Release stacked extra values if not used anymore.
6048  */
6049  set_extra_field(gconf, &(stack->prior.extra), NULL);
6050  set_extra_field(gconf, &(stack->masked.extra), NULL);
6051 
6052  /* And restore source information */
6053  gconf->source = newsource;
6054  gconf->scontext = newscontext;
6055  }
6056 
6057  /* Finish popping the state stack */
6058  gconf->stack = prev;
6059  pfree(stack);
6060 
6061  /* Report new value if we changed it */
6062  if (changed && (gconf->flags & GUC_REPORT))
6063  ReportGUCOption(gconf);
6064  } /* end of stack-popping loop */
6065 
6066  if (stack != NULL)
6067  still_dirty = true;
6068  }
6069 
6070  /* If there are no remaining stack entries, we can reset guc_dirty */
6071  guc_dirty = still_dirty;
6072 
6073  /* Update nesting level */
6074  GUCNestLevel = nestLevel - 1;
6075 }
struct guc_stack * prev
Definition: guc_tables.h:123
GucSource source
Definition: guc_tables.h:158
GucContext
Definition: guc.h:68
union config_var_val val
Definition: guc_tables.h:46
int nest_level
Definition: guc_tables.h:124
GucRealAssignHook assign_hook
Definition: guc_tables.h:219
char ** variable
Definition: guc_tables.h:230
static int GUCNestLevel
Definition: guc.c:4653
bool * variable
Definition: guc_tables.h:184
GucEnumAssignHook assign_hook
Definition: guc_tables.h:248
GucBoolAssignHook assign_hook
Definition: guc_tables.h:187
config_var_value masked
Definition: guc_tables.h:131
GucContext scontext
Definition: guc_tables.h:160
GucIntAssignHook assign_hook
Definition: guc_tables.h:203
GucSource
Definition: guc.h:105
int * variable
Definition: guc_tables.h:198
int * variable
Definition: guc_tables.h:244
void pfree(void *pointer)
Definition: mcxt.c:1056
static int num_guc_variables
Definition: guc.c:4640
static void discard_stack_value(struct config_generic *gconf, config_var_value *val)
Definition: guc.c:4868
GucSource source
Definition: guc_tables.h:126
static void set_extra_field(struct config_generic *gconf, void **field, void *newval)
Definition: guc.c:4814
struct config_generic gen
Definition: guc_tables.h:182
struct config_generic gen
Definition: guc_tables.h:196
GucContext masked_scontext
Definition: guc_tables.h:129
#define GUC_REPORT
Definition: guc.h:208
double * variable
Definition: guc_tables.h:214
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4753
static struct config_generic ** guc_variables
Definition: guc.c:4637
enum config_type vartype
Definition: guc_tables.h:156
GucContext scontext
Definition: guc_tables.h:128
struct config_generic gen
Definition: guc_tables.h:242
struct config_generic gen
Definition: guc_tables.h:228
GucStackState state
Definition: guc_tables.h:125
GucStringAssignHook assign_hook
Definition: guc_tables.h:233
#define Assert(condition)
Definition: c.h:739
#define newval
char * stringval
Definition: guc_tables.h:36
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:6111
GucStack * stack
Definition: guc_tables.h:162
double realval
Definition: guc_tables.h:35
static bool guc_dirty
Definition: guc.c:4649
config_var_value prior
Definition: guc_tables.h:130
struct config_generic gen
Definition: guc_tables.h:212

◆ AtStart_GUC()

void AtStart_GUC ( void  )

Definition at line 5767 of file guc.c.

References elog, and WARNING.

Referenced by StartTransaction().

5768 {
5769  /*
5770  * The nest level should be 0 between transactions; if it isn't, somebody
5771  * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
5772  * throw a warning but make no other effort to clean up.
5773  */
5774  if (GUCNestLevel != 0)
5775  elog(WARNING, "GUC nest level = %d at transaction start",
5776  GUCNestLevel);
5777  GUCNestLevel = 1;
5778 }
static int GUCNestLevel
Definition: guc.c:4653
#define WARNING
Definition: elog.h:40
#define elog(elevel,...)
Definition: elog.h:228

◆ BeginReportingGUCOptions()

void BeginReportingGUCOptions ( void  )

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

6084 {
6085  int i;
6086 
6087  /*
6088  * Don't do anything unless talking to an interactive frontend of protocol
6089  * 3.0 or later.
6090  */
6091  if (whereToSendOutput != DestRemote ||
6093  return;
6094 
6095  reporting_enabled = true;
6096 
6097  /* Transmit initial values of interesting variables */
6098  for (i = 0; i < num_guc_variables; i++)
6099  {
6100  struct config_generic *conf = guc_variables[i];
6101 
6102  if (conf->flags & GUC_REPORT)
6103  ReportGUCOption(conf);
6104  }
6105 }
#define PG_PROTOCOL_MAJOR(v)
Definition: pqcomm.h:104
static int num_guc_variables
Definition: guc.c:4640
#define GUC_REPORT
Definition: guc.h:208
static struct config_generic ** guc_variables
Definition: guc.c:4637
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:6111
CommandDest whereToSendOutput
Definition: postgres.c:91
static bool reporting_enabled
Definition: guc.c:4651
ProtocolVersion FrontendProtocol
Definition: globals.c:28

◆ build_guc_variables()

void build_guc_variables ( void  )

Definition at line 4904 of file guc.c.

References FATAL, config_generic::flags, free, config_bool::gen, config_int::gen, config_real::gen, config_string::gen, config_enum::gen, GUC_EXPLAIN, 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().

4905 {
4906  int size_vars;
4907  int num_vars = 0;
4908  int num_explain_vars = 0;
4909  struct config_generic **guc_vars;
4910  int i;
4911 
4912  for (i = 0; ConfigureNamesBool[i].gen.name; i++)
4913  {
4914  struct config_bool *conf = &ConfigureNamesBool[i];
4915 
4916  /* Rather than requiring vartype to be filled in by hand, do this: */
4917  conf->gen.vartype = PGC_BOOL;
4918  num_vars++;
4919 
4920  if (conf->gen.flags & GUC_EXPLAIN)
4921  num_explain_vars++;
4922  }
4923 
4924  for (i = 0; ConfigureNamesInt[i].gen.name; i++)
4925  {
4926  struct config_int *conf = &ConfigureNamesInt[i];
4927 
4928  conf->gen.vartype = PGC_INT;
4929  num_vars++;
4930 
4931  if (conf->gen.flags & GUC_EXPLAIN)
4932  num_explain_vars++;
4933  }
4934 
4935  for (i = 0; ConfigureNamesReal[i].gen.name; i++)
4936  {
4937  struct config_real *conf = &ConfigureNamesReal[i];
4938 
4939  conf->gen.vartype = PGC_REAL;
4940  num_vars++;
4941 
4942  if (conf->gen.flags & GUC_EXPLAIN)
4943  num_explain_vars++;
4944  }
4945 
4946  for (i = 0; ConfigureNamesString[i].gen.name; i++)
4947  {
4948  struct config_string *conf = &ConfigureNamesString[i];
4949 
4950  conf->gen.vartype = PGC_STRING;
4951  num_vars++;
4952 
4953  if (conf->gen.flags & GUC_EXPLAIN)
4954  num_explain_vars++;
4955  }
4956 
4957  for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
4958  {
4959  struct config_enum *conf = &ConfigureNamesEnum[i];
4960 
4961  conf->gen.vartype = PGC_ENUM;
4962  num_vars++;
4963 
4964  if (conf->gen.flags & GUC_EXPLAIN)
4965  num_explain_vars++;
4966  }
4967 
4968  /*
4969  * Create table with 20% slack
4970  */
4971  size_vars = num_vars + num_vars / 4;
4972 
4973  guc_vars = (struct config_generic **)
4974  guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
4975 
4976  num_vars = 0;
4977 
4978  for (i = 0; ConfigureNamesBool[i].gen.name; i++)
4979  guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
4980 
4981  for (i = 0; ConfigureNamesInt[i].gen.name; i++)
4982  guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
4983 
4984  for (i = 0; ConfigureNamesReal[i].gen.name; i++)
4985  guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
4986 
4987  for (i = 0; ConfigureNamesString[i].gen.name; i++)
4988  guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
4989 
4990  for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
4991  guc_vars[num_vars++] = &ConfigureNamesEnum[i].gen;
4992 
4993  if (guc_variables)
4995  guc_variables = guc_vars;
4996  num_guc_variables = num_vars;
4997  num_guc_explain_variables = num_explain_vars;
4998  size_guc_variables = size_vars;
5000  sizeof(struct config_generic *), guc_var_compare);
5001 }
static struct config_int ConfigureNamesInt[]
Definition: guc.c:1988
const char * name
Definition: guc_tables.h:149
static struct config_enum ConfigureNamesEnum[]
Definition: guc.c:4281
static struct config_bool ConfigureNamesBool[]
Definition: guc.c:889
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:5143
static int num_guc_variables
Definition: guc.c:4640
#define FATAL
Definition: elog.h:52
struct config_generic gen
Definition: guc_tables.h:182
struct config_generic gen
Definition: guc_tables.h:196
#define GUC_EXPLAIN
Definition: guc.h:230
static struct config_generic ** guc_variables
Definition: guc.c:4637
enum config_type vartype
Definition: guc_tables.h:156
static int size_guc_variables
Definition: guc.c:4646
static struct config_real ConfigureNamesReal[]
Definition: guc.c:3255
struct config_generic gen
Definition: guc_tables.h:242
struct config_generic gen
Definition: guc_tables.h:228
#define free(a)
Definition: header.h:65
static int num_guc_explain_variables
Definition: guc.c:4643
static struct config_string ConfigureNamesString[]
Definition: guc.c:3513
int i
#define qsort(a, b, c, d)
Definition: port.h:491
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4681
struct config_generic gen
Definition: guc_tables.h:212

◆ 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 10790 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().

10792 {
10793  /* Quick success if no hook */
10794  if (!conf->check_hook)
10795  return true;
10796 
10797  /* Reset variables that might be set by hook */
10798  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
10799  GUC_check_errmsg_string = NULL;
10801  GUC_check_errhint_string = NULL;
10802 
10803  if (!conf->check_hook(newval, extra, source))
10804  {
10805  ereport(elevel,
10809  errmsg("invalid value for parameter \"%s\": %d",
10810  conf->gen.name, (int) *newval),
10814  errhint("%s", GUC_check_errhint_string) : 0));
10815  /* Flush any strings created in ErrorContext */
10816  FlushErrorState();
10817  return false;
10818  }
10819 
10820  return true;
10821 }
char * GUC_check_errhint_string
Definition: guc.c:140
GucSource source
Definition: guc_tables.h:158
int errhint(const char *fmt,...)
Definition: elog.c:1069
const char * name
Definition: guc_tables.h:149
int errcode(int sqlerrcode)
Definition: elog.c:608
static int GUC_check_errcode_value
Definition: guc.c:135
void FlushErrorState(void)
Definition: elog.c:1678
int errdetail_internal(const char *fmt,...)
Definition: elog.c:982
struct config_generic gen
Definition: guc_tables.h:182
char * GUC_check_errdetail_string
Definition: guc.c:139
#define ereport(elevel, rest)
Definition: elog.h:141
static int elevel
Definition: vacuumlazy.c:143
GucBoolCheckHook check_hook
Definition: guc_tables.h:186
int errmsg_internal(const char *fmt,...)
Definition: elog.c:909
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:138
int errmsg(const char *fmt,...)
Definition: elog.c:822

◆ 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 10926 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().

10928 {
10929  /* Quick success if no hook */
10930  if (!conf->check_hook)
10931  return true;
10932 
10933  /* Reset variables that might be set by hook */
10934  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
10935  GUC_check_errmsg_string = NULL;
10937  GUC_check_errhint_string = NULL;
10938 
10939  if (!conf->check_hook(newval, extra, source))
10940  {
10941  ereport(elevel,
10945  errmsg("invalid value for parameter \"%s\": \"%s\"",
10946  conf->gen.name,
10951  errhint("%s", GUC_check_errhint_string) : 0));
10952  /* Flush any strings created in ErrorContext */
10953  FlushErrorState();
10954  return false;
10955  }
10956 
10957  return true;
10958 }
char * GUC_check_errhint_string
Definition: guc.c:140
GucSource source
Definition: guc_tables.h:158
GucEnumCheckHook check_hook
Definition: guc_tables.h:247
int errhint(const char *fmt,...)
Definition: elog.c:1069
const char * name
Definition: guc_tables.h:149
int errcode(int sqlerrcode)
Definition: elog.c:608
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:6490
static int GUC_check_errcode_value
Definition: guc.c:135
void FlushErrorState(void)
Definition: elog.c:1678
int errdetail_internal(const char *fmt,...)
Definition: elog.c:982
char * GUC_check_errdetail_string
Definition: guc.c:139
#define ereport(elevel, rest)
Definition: elog.h:141
static int elevel
Definition: vacuumlazy.c:143
struct config_generic gen
Definition: guc_tables.h:242
int errmsg_internal(const char *fmt,...)
Definition: elog.c:909
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:138
int errmsg(const char *fmt,...)
Definition: elog.c:822

◆ 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 10824 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().

10826 {
10827  /* Quick success if no hook */
10828  if (!conf->check_hook)
10829  return true;
10830 
10831  /* Reset variables that might be set by hook */
10832  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
10833  GUC_check_errmsg_string = NULL;
10835  GUC_check_errhint_string = NULL;
10836 
10837  if (!conf->check_hook(newval, extra, source))
10838  {
10839  ereport(elevel,
10843  errmsg("invalid value for parameter \"%s\": %d",
10844  conf->gen.name, *newval),
10848  errhint("%s", GUC_check_errhint_string) : 0));
10849  /* Flush any strings created in ErrorContext */
10850  FlushErrorState();
10851  return false;
10852  }
10853 
10854  return true;
10855 }
char * GUC_check_errhint_string
Definition: guc.c:140
GucSource source
Definition: guc_tables.h:158
int errhint(const char *fmt,...)
Definition: elog.c:1069
const char * name
Definition: guc_tables.h:149
int errcode(int sqlerrcode)
Definition: elog.c:608
static int GUC_check_errcode_value
Definition: guc.c:135
GucIntCheckHook check_hook
Definition: guc_tables.h:202
void FlushErrorState(void)
Definition: elog.c:1678
int errdetail_internal(const char *fmt,...)
Definition: elog.c:982
struct config_generic gen
Definition: guc_tables.h:196
char * GUC_check_errdetail_string
Definition: guc.c:139
#define ereport(elevel, rest)
Definition: elog.h:141
static int elevel
Definition: vacuumlazy.c:143
int errmsg_internal(const char *fmt,...)
Definition: elog.c:909
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:138
int errmsg(const char *fmt,...)
Definition: elog.c:822

◆ 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 10858 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().

10860 {
10861  /* Quick success if no hook */
10862  if (!conf->check_hook)
10863  return true;
10864 
10865  /* Reset variables that might be set by hook */
10866  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
10867  GUC_check_errmsg_string = NULL;
10869  GUC_check_errhint_string = NULL;
10870 
10871  if (!conf->check_hook(newval, extra, source))
10872  {
10873  ereport(elevel,
10877  errmsg("invalid value for parameter \"%s\": %g",
10878  conf->gen.name, *newval),
10882  errhint("%s", GUC_check_errhint_string) : 0));
10883  /* Flush any strings created in ErrorContext */
10884  FlushErrorState();
10885  return false;
10886  }
10887 
10888  return true;
10889 }
char * GUC_check_errhint_string
Definition: guc.c:140
GucSource source
Definition: guc_tables.h:158
int errhint(const char *fmt,...)
Definition: elog.c:1069
const char * name
Definition: guc_tables.h:149
int errcode(int sqlerrcode)
Definition: elog.c:608
static int GUC_check_errcode_value
Definition: guc.c:135
GucRealCheckHook check_hook
Definition: guc_tables.h:218
void FlushErrorState(void)
Definition: elog.c:1678
int errdetail_internal(const char *fmt,...)
Definition: elog.c:982
char * GUC_check_errdetail_string
Definition: guc.c:139
#define ereport(elevel, rest)
Definition: elog.h:141
static int elevel
Definition: vacuumlazy.c:143
int errmsg_internal(const char *fmt,...)
Definition: elog.c:909
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:138
int errmsg(const char *fmt,...)
Definition: elog.c:822
struct config_generic gen
Definition: guc_tables.h:212

◆ 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 10892 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().

10894 {
10895  /* Quick success if no hook */
10896  if (!conf->check_hook)
10897  return true;
10898 
10899  /* Reset variables that might be set by hook */
10900  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
10901  GUC_check_errmsg_string = NULL;
10903  GUC_check_errhint_string = NULL;
10904 
10905  if (!conf->check_hook(newval, extra, source))
10906  {
10907  ereport(elevel,
10911  errmsg("invalid value for parameter \"%s\": \"%s\"",
10912  conf->gen.name, *newval ? *newval : ""),
10916  errhint("%s", GUC_check_errhint_string) : 0));
10917  /* Flush any strings created in ErrorContext */
10918  FlushErrorState();
10919  return false;
10920  }
10921 
10922  return true;
10923 }
char * GUC_check_errhint_string
Definition: guc.c:140
GucSource source
Definition: guc_tables.h:158
int errhint(const char *fmt,...)
Definition: elog.c:1069
const char * name
Definition: guc_tables.h:149
GucStringCheckHook check_hook
Definition: guc_tables.h:232
int errcode(int sqlerrcode)
Definition: elog.c:608
static int GUC_check_errcode_value
Definition: guc.c:135
void FlushErrorState(void)
Definition: elog.c:1678
int errdetail_internal(const char *fmt,...)
Definition: elog.c:982
char * GUC_check_errdetail_string
Definition: guc.c:139
#define ereport(elevel, rest)
Definition: elog.h:141
static int elevel
Definition: vacuumlazy.c:143
struct config_generic gen
Definition: guc_tables.h:228
int errmsg_internal(const char *fmt,...)
Definition: elog.c:909
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:138
int errmsg(const char *fmt,...)
Definition: elog.c:822

◆ can_skip_gucvar()

static bool can_skip_gucvar ( struct config_generic gconf)
static

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

9971 {
9972  return gconf->context == PGC_POSTMASTER ||
9973  gconf->context == PGC_INTERNAL || gconf->source == PGC_S_DEFAULT ||
9974  strcmp(gconf->name, "role") == 0;
9975 }
GucSource source
Definition: guc_tables.h:158
const char * name
Definition: guc_tables.h:149
GucContext context
Definition: guc_tables.h:150

◆ check_application_name()

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

Definition at line 11485 of file guc.c.

References pg_clean_ascii().

11486 {
11487  /* Only allow clean ASCII chars in the application name */
11489 
11490  return true;
11491 }
#define newval
void pg_clean_ascii(char *str)
Definition: string.c:82

◆ check_autovacuum_max_workers()

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

Definition at line 11371 of file guc.c.

References MAX_BACKENDS, max_wal_senders, max_worker_processes, and MaxConnections.

11372 {
11373  if (MaxConnections + *newval + 1 +
11375  return false;
11376  return true;
11377 }
#define MAX_BACKENDS
Definition: postmaster.h:75
int max_wal_senders
Definition: walsender.c:121
int MaxConnections
Definition: globals.c:132
#define newval
int max_worker_processes
Definition: globals.c:133

◆ check_autovacuum_work_mem()

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

Definition at line 11389 of file guc.c.

11390 {
11391  /*
11392  * -1 indicates fallback.
11393  *
11394  * If we haven't yet changed the boot_val default of -1, just let it be.
11395  * Autovacuum will look to maintenance_work_mem instead.
11396  */
11397  if (*newval == -1)
11398  return true;
11399 
11400  /*
11401  * We clamp manually-set values to at least 1MB. Since
11402  * maintenance_work_mem is always set to at least this value, do the same
11403  * here.
11404  */
11405  if (*newval < 1024)
11406  *newval = 1024;
11407 
11408  return true;
11409 }
#define newval

◆ check_backtrace_functions()

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

Definition at line 11545 of file guc.c.

References ERROR, GUC_check_errdetail, guc_malloc(), and i.

11546 {
11547  int newvallen = strlen(*newval);
11548  char *someval;
11549  int validlen;
11550  int i;
11551  int j;
11552 
11553  /*
11554  * Allow characters that can be C identifiers and commas as separators, as
11555  * well as some whitespace for readability.
11556  */
11557  validlen = strspn(*newval,
11558  "0123456789_"
11559  "abcdefghijklmnopqrstuvwxyz"
11560  "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
11561  ", \n\t");
11562  if (validlen != newvallen)
11563  {
11564  GUC_check_errdetail("invalid character");
11565  return false;
11566  }
11567 
11568  if (*newval[0] == '\0')
11569  {
11570  *extra = NULL;
11571  return true;
11572  }
11573 
11574  /*
11575  * Allocate space for the output and create the copy. We could discount
11576  * whitespace chars to save some memory, but it doesn't seem worth the
11577  * trouble.
11578  */
11579  someval = guc_malloc(ERROR, newvallen + 1 + 1);
11580  for (i = 0, j = 0; i < newvallen; i++)
11581  {
11582  if ((*newval)[i] == ',')
11583  someval[j++] = '\0'; /* next item */
11584  else if ((*newval)[i] == ' ' ||
11585  (*newval)[i] == '\n' ||
11586  (*newval)[i] == '\t')
11587  ; /* ignore these */
11588  else
11589  someval[j++] = (*newval)[i]; /* copy anything else */
11590  }
11591 
11592  /* two \0s end the setting */
11593  someval[j] = '\0';
11594  someval[j + 1] = '\0';
11595 
11596  *extra = someval;
11597  return true;
11598 }
#define GUC_check_errdetail
Definition: guc.h:414
#define ERROR
Definition: elog.h:43
#define newval
int i
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4681

◆ check_bonjour()

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

Definition at line 11154 of file guc.c.

References GUC_check_errmsg.

11155 {
11156 #ifndef USE_BONJOUR
11157  if (*newval)
11158  {
11159  GUC_check_errmsg("Bonjour is not supported by this build");
11160  return false;
11161  }
11162 #endif
11163  return true;
11164 }
#define GUC_check_errmsg
Definition: guc.h:410
#define newval

◆ check_canonical_path()

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

Definition at line 11205 of file guc.c.

References canonicalize_path().

11206 {
11207  /*
11208  * Since canonicalize_path never enlarges the string, we can just modify
11209  * newval in-place. But watch out for NULL, which is the default value
11210  * for external_pid_file.
11211  */
11212  if (*newval)
11214  return true;
11215 }
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 11501 of file guc.c.

References pg_clean_ascii().

11502 {
11503  /* Only allow clean ASCII chars in the cluster name */
11505 
11506  return true;
11507 }
#define newval
void pg_clean_ascii(char *str)
Definition: string.c:82

◆ check_default_with_oids()

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

Definition at line 11874 of file guc.c.

References GUC_check_errcode(), and GUC_check_errmsg.

11875 {
11876  if (*newval)
11877  {
11878  /* check the GUC's definition for an explanation */
11879  GUC_check_errcode(ERRCODE_FEATURE_NOT_SUPPORTED);
11880  GUC_check_errmsg("tables declared WITH OIDS are not supported");
11881 
11882  return false;
11883  }
11884 
11885  return true;
11886 }
#define GUC_check_errmsg
Definition: guc.h:410
void GUC_check_errcode(int sqlerrcode)
Definition: guc.c:10777
#define newval

◆ check_effective_io_concurrency()

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

Definition at line 11421 of file guc.c.

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

11422 {
11423 #ifdef USE_PREFETCH
11424  double new_prefetch_pages;
11425 
11426  if (ComputeIoConcurrency(*newval, &new_prefetch_pages))
11427  {
11428  int *myextra = (int *) guc_malloc(ERROR, sizeof(int));
11429 
11430  *myextra = (int) rint(new_prefetch_pages);
11431  *extra = (void *) myextra;
11432 
11433  return true;
11434  }
11435  else
11436  return false;
11437 #else
11438  if (*newval != 0)
11439  {
11440  GUC_check_errdetail("effective_io_concurrency must be set to 0 on platforms that lack posix_fadvise().");
11441  return false;
11442  }
11443  return true;
11444 #endif /* USE_PREFETCH */
11445 }
#define GUC_check_errdetail
Definition: guc.h:414
bool ComputeIoConcurrency(int io_concurrency, double *target)
Definition: bufmgr.c:469
#define ERROR
Definition: elog.h:43
double rint(double x)
Definition: rint.c:21
#define newval
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4681

◆ check_log_destination()

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

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

11047 {
11048  char *rawstring;
11049  List *elemlist;
11050  ListCell *l;
11051  int newlogdest = 0;
11052  int *myextra;
11053 
11054  /* Need a modifiable copy of string */
11055  rawstring = pstrdup(*newval);
11056 
11057  /* Parse string into list of identifiers */
11058  if (!SplitIdentifierString(rawstring, ',', &elemlist))
11059  {
11060  /* syntax error in list */
11061  GUC_check_errdetail("List syntax is invalid.");
11062  pfree(rawstring);
11063  list_free(elemlist);
11064  return false;
11065  }
11066 
11067  foreach(l, elemlist)
11068  {
11069  char *tok = (char *) lfirst(l);
11070 
11071  if (pg_strcasecmp(tok, "stderr") == 0)
11072  newlogdest |= LOG_DESTINATION_STDERR;
11073  else if (pg_strcasecmp(tok, "csvlog") == 0)
11074  newlogdest |= LOG_DESTINATION_CSVLOG;
11075 #ifdef HAVE_SYSLOG
11076  else if (pg_strcasecmp(tok, "syslog") == 0)
11077  newlogdest |= LOG_DESTINATION_SYSLOG;
11078 #endif
11079 #ifdef WIN32
11080  else if (pg_strcasecmp(tok, "eventlog") == 0)
11081  newlogdest |= LOG_DESTINATION_EVENTLOG;
11082 #endif
11083  else
11084  {
11085  GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
11086  pfree(rawstring);
11087  list_free(elemlist);
11088  return false;
11089  }
11090  }
11091 
11092  pfree(rawstring);
11093  list_free(elemlist);
11094 
11095  myextra = (int *) guc_malloc(ERROR, sizeof(int));
11096  *myextra = newlogdest;
11097  *extra = (void *) myextra;
11098 
11099  return true;
11100 }
#define LOG_DESTINATION_EVENTLOG
Definition: elog.h:447
#define GUC_check_errdetail
Definition: guc.h:414
char * pstrdup(const char *in)
Definition: mcxt.c:1186
#define LOG_DESTINATION_SYSLOG
Definition: elog.h:446
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
void pfree(void *pointer)
Definition: mcxt.c:1056
#define ERROR
Definition: elog.h:43
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3652
#define LOG_DESTINATION_CSVLOG
Definition: elog.h:448
#define LOG_DESTINATION_STDERR
Definition: elog.h:445
#define lfirst(lc)
Definition: pg_list.h:190
#define newval
void list_free(List *list)
Definition: list.c:1377
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4681
Definition: pg_list.h:50

◆ check_log_stats()

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

Definition at line 11191 of file guc.c.

References GUC_check_errdetail.

11192 {
11193  if (*newval &&
11195  {
11196  GUC_check_errdetail("Cannot enable \"log_statement_stats\" when "
11197  "\"log_parser_stats\", \"log_planner_stats\", "
11198  "or \"log_executor_stats\" is true.");
11199  return false;
11200  }
11201  return true;
11202 }
bool log_parser_stats
Definition: guc.c:495
#define GUC_check_errdetail
Definition: guc.h:414
#define newval
bool log_executor_stats
Definition: guc.c:497
bool log_planner_stats
Definition: guc.c:496

◆ check_max_wal_senders()

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

Definition at line 11380 of file guc.c.

References autovacuum_max_workers, MAX_BACKENDS, max_worker_processes, and MaxConnections.

11381 {
11384  return false;
11385  return true;
11386 }
#define MAX_BACKENDS
Definition: postmaster.h:75
int MaxConnections
Definition: globals.c:132
int autovacuum_max_workers
Definition: autovacuum.c:115
#define newval
int max_worker_processes
Definition: globals.c:133

◆ check_max_worker_processes()

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

Definition at line 11412 of file guc.c.

References autovacuum_max_workers, MAX_BACKENDS, max_wal_senders, and MaxConnections.

11413 {
11416  return false;
11417  return true;
11418 }
#define MAX_BACKENDS
Definition: postmaster.h:75
int max_wal_senders
Definition: walsender.c:121
int MaxConnections
Definition: globals.c:132
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 11362 of file guc.c.

References autovacuum_max_workers, MAX_BACKENDS, max_wal_senders, and max_worker_processes.

11363 {
11364  if (*newval + autovacuum_max_workers + 1 +
11366  return false;
11367  return true;
11368 }
#define MAX_BACKENDS
Definition: postmaster.h:75
int max_wal_senders
Definition: walsender.c:121
int autovacuum_max_workers
Definition: autovacuum.c:115
#define newval
int max_worker_processes
Definition: globals.c:133

◆ check_primary_slot_name()

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

Definition at line 11864 of file guc.c.

References ReplicationSlotValidateName(), and WARNING.

11865 {
11866  if (*newval && strcmp(*newval, "") != 0 &&
11868  return false;
11869 
11870  return true;
11871 }
bool ReplicationSlotValidateName(const char *name, int elevel)
Definition: slot.c:174
#define WARNING
Definition: elog.h:40
#define newval

◆ check_recovery_target()

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

Definition at line 11669 of file guc.c.

References GUC_check_errdetail.

11670 {
11671  if (strcmp(*newval, "immediate") != 0 && strcmp(*newval, "") != 0)
11672  {
11673  GUC_check_errdetail("The only allowed value is \"immediate\".");
11674  return false;
11675  }
11676  return true;
11677 }
#define GUC_check_errdetail
Definition: guc.h:414
#define newval

◆ check_recovery_target_lsn()

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

Definition at line 11828 of file guc.c.

References ERROR, guc_malloc(), and pg_lsn_in_internal().

11829 {
11830  if (strcmp(*newval, "") != 0)
11831  {
11832  XLogRecPtr lsn;
11833  XLogRecPtr *myextra;
11834  bool have_error = false;
11835 
11836  lsn = pg_lsn_in_internal(*newval, &have_error);
11837  if (have_error)
11838  return false;
11839 
11840  myextra = (XLogRecPtr *) guc_malloc(ERROR, sizeof(XLogRecPtr));
11841  *myextra = lsn;
11842  *extra = (void *) myextra;
11843  }
11844  return true;
11845 }
#define ERROR
Definition: elog.h:43
XLogRecPtr pg_lsn_in_internal(const char *str, bool *have_error)
Definition: pg_lsn.c:29
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define newval
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4681

◆ check_recovery_target_name()

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

Definition at line 11799 of file guc.c.

References GUC_check_errdetail, and MAXFNAMELEN.

11800 {
11801  /* Use the value of newval directly */
11802  if (strlen(*newval) >= MAXFNAMELEN)
11803  {
11804  GUC_check_errdetail("%s is too long (maximum %d characters).",
11805  "recovery_target_name", MAXFNAMELEN - 1);
11806  return false;
11807  }
11808  return true;
11809 }
#define GUC_check_errdetail
Definition: guc.h:414
#define MAXFNAMELEN
#define newval

◆ check_recovery_target_time()

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

Definition at line 11736 of file guc.c.

References DecodeDateTime(), DTK_DATE, GUC_check_errdetail, MAXDATEFIELDS, MAXDATELEN, newval, ParseDateTime(), generate_unaccent_rules::str, tm, and tm2timestamp().

11737 {
11738  if (strcmp(*newval, "") != 0)
11739  {
11740  /* reject some special values */
11741  if (strcmp(*newval, "now") == 0 ||
11742  strcmp(*newval, "today") == 0 ||
11743  strcmp(*newval, "tomorrow") == 0 ||
11744  strcmp(*newval, "yesterday") == 0)
11745  {
11746  return false;
11747  }
11748 
11749  /*
11750  * parse timestamp value (see also timestamptz_in())
11751  */
11752  {
11753  char *str = *newval;
11754  fsec_t fsec;
11755  struct pg_tm tt,
11756  *tm = &tt;
11757  int tz;
11758  int dtype;
11759  int nf;
11760  int dterr;
11761  char *field[MAXDATEFIELDS];
11762  int ftype[MAXDATEFIELDS];
11763  char workbuf[MAXDATELEN + MAXDATEFIELDS];
11765 
11766  dterr = ParseDateTime(str, workbuf, sizeof(workbuf),
11767  field, ftype, MAXDATEFIELDS, &nf);
11768  if (dterr == 0)
11769  dterr = DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tz);
11770  if (dterr != 0)
11771  return false;
11772  if (dtype != DTK_DATE)
11773  return false;
11774 
11775  if (tm2timestamp(tm, fsec, &tz, &timestamp) != 0)
11776  {
11777  GUC_check_errdetail("timestamp out of range: \"%s\"", str);
11778  return false;
11779  }
11780  }
11781  }
11782  return true;
11783 }
#define MAXDATELEN
Definition: datetime.h:201
#define GUC_check_errdetail
Definition: guc.h:414
int64 timestamp
int64 TimestampTz
Definition: timestamp.h:39
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:108
int DecodeDateTime(char **field, int *ftype, int nf, int *dtype, struct pg_tm *tm, fsec_t *fsec, int *tzp)
Definition: datetime.c:758
int32 fsec_t
Definition: timestamp.h:41
int tm2timestamp(struct pg_tm *tm, fsec_t fsec, int *tzp, Timestamp *result)
Definition: timestamp.c:1887
#define MAXDATEFIELDS
Definition: datetime.h:203
#define newval
int ParseDateTime(const char *timestr, char *workbuf, size_t buflen, char **field, int *ftype, int maxfields, int *numfields)
Definition: datetime.c:537
#define DTK_DATE
Definition: datetime.h:145

◆ check_recovery_target_timeline()

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

Definition at line 11607 of file guc.c.

References ERROR, GUC_check_errdetail, guc_malloc(), RECOVERY_TARGET_TIMELINE_CONTROLFILE, RECOVERY_TARGET_TIMELINE_LATEST, and RECOVERY_TARGET_TIMELINE_NUMERIC.

11608 {
11610  RecoveryTargetTimeLineGoal *myextra;
11611 
11612  if (strcmp(*newval, "current") == 0)
11614  else if (strcmp(*newval, "latest") == 0)
11616  else
11617  {
11619 
11620  errno = 0;
11621  strtoul(*newval, NULL, 0);
11622  if (errno == EINVAL || errno == ERANGE)
11623  {
11624  GUC_check_errdetail("recovery_target_timeline is not a valid number.");
11625  return false;
11626  }
11627  }
11628 
11630  *myextra = rttg;
11631  *extra = (void *) myextra;
11632 
11633  return true;
11634 }
#define GUC_check_errdetail
Definition: guc.h:414
RecoveryTargetTimeLineGoal
Definition: xlog.h:93
#define ERROR
Definition: elog.h:43
#define newval
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4681

◆ check_recovery_target_xid()

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

Definition at line 11693 of file guc.c.

References ERROR, and guc_malloc().

11694 {
11695  if (strcmp(*newval, "") != 0)
11696  {
11697  TransactionId xid;
11698  TransactionId *myextra;
11699 
11700  errno = 0;
11701  xid = (TransactionId) strtoul(*newval, NULL, 0);
11702  if (errno == EINVAL || errno == ERANGE)
11703  return false;
11704 
11705  myextra = (TransactionId *) guc_malloc(ERROR, sizeof(TransactionId));
11706  *myextra = xid;
11707  *extra = (void *) myextra;
11708  }
11709  return true;
11710 }
uint32 TransactionId
Definition: c.h:514
#define ERROR
Definition: elog.h:43
#define newval
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4681

◆ check_ssl()

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

Definition at line 11167 of file guc.c.

References GUC_check_errmsg.

11168 {
11169 #ifndef USE_SSL
11170  if (*newval)
11171  {
11172  GUC_check_errmsg("SSL is not supported by this build");
11173  return false;
11174  }
11175 #endif
11176  return true;
11177 }
#define GUC_check_errmsg
Definition: guc.h:410
#define newval

◆ check_stage_log_stats()

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

Definition at line 11180 of file guc.c.

References GUC_check_errdetail.

11181 {
11182  if (*newval && log_statement_stats)
11183  {
11184  GUC_check_errdetail("Cannot enable parameter when \"log_statement_stats\" is true.");
11185  return false;
11186  }
11187  return true;
11188 }
bool log_statement_stats
Definition: guc.c:498
#define GUC_check_errdetail
Definition: guc.h:414
#define newval

◆ check_temp_buffers()

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

Definition at line 11140 of file guc.c.

References GUC_check_errdetail, and NLocBuffer.

11141 {
11142  /*
11143  * Once local buffers have been initialized, it's too late to change this.
11144  */
11145  if (NLocBuffer && NLocBuffer != *newval)
11146  {
11147  GUC_check_errdetail("\"temp_buffers\" cannot be changed after any temporary tables have been accessed in the session.");
11148  return false;
11149  }
11150  return true;
11151 }
#define GUC_check_errdetail
Definition: guc.h:414
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 11218 of file guc.c.

References Assert, load_tzoffsets(), and PGC_S_DEFAULT.

11219 {
11220  /*
11221  * The boot_val given above for timezone_abbreviations is NULL. When we
11222  * see this we just do nothing. If this value isn't overridden from the
11223  * config file then pg_timezone_abbrev_initialize() will eventually
11224  * replace it with "Default". This hack has two purposes: to avoid
11225  * wasting cycles loading values that might soon be overridden from the
11226  * config file, and to avoid trying to read the timezone abbrev files
11227  * during InitializeGUCOptions(). The latter doesn't work in an
11228  * EXEC_BACKEND subprocess because my_exec_path hasn't been set yet and so
11229  * we can't locate PGSHAREDIR.
11230  */
11231  if (*newval == NULL)
11232  {
11233  Assert(source == PGC_S_DEFAULT);
11234  return true;
11235  }
11236 
11237  /* OK, load the file and produce a malloc'd TimeZoneAbbrevTable */
11238  *extra = load_tzoffsets(*newval);
11239 
11240  /* tzparser.c returns NULL on failure, reporting via GUC_check_errmsg */
11241  if (!*extra)
11242  return false;
11243 
11244  return true;
11245 }
TimeZoneAbbrevTable * load_tzoffsets(const char *filename)
Definition: tzparser.c:437
#define Assert(condition)
Definition: c.h:739
#define newval

◆ check_wal_consistency_checking()

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

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

10967 {
10968  char *rawstring;
10969  List *elemlist;
10970  ListCell *l;
10971  bool newwalconsistency[RM_MAX_ID + 1];
10972 
10973  /* Initialize the array */
10974  MemSet(newwalconsistency, 0, (RM_MAX_ID + 1) * sizeof(bool));
10975 
10976  /* Need a modifiable copy of string */
10977  rawstring = pstrdup(*newval);
10978 
10979  /* Parse string into list of identifiers */
10980  if (!SplitIdentifierString(rawstring, ',', &elemlist))
10981  {
10982  /* syntax error in list */
10983  GUC_check_errdetail("List syntax is invalid.");
10984  pfree(rawstring);
10985  list_free(elemlist);
10986  return false;
10987  }
10988 
10989  foreach(l, elemlist)
10990  {
10991  char *tok = (char *) lfirst(l);
10992  bool found = false;
10993  RmgrId rmid;
10994 
10995  /* Check for 'all'. */
10996  if (pg_strcasecmp(tok, "all") == 0)
10997  {
10998  for (rmid = 0; rmid <= RM_MAX_ID; rmid++)
10999  if (RmgrTable[rmid].rm_mask != NULL)
11000  newwalconsistency[rmid] = true;
11001  found = true;
11002  }
11003  else
11004  {
11005  /*
11006  * Check if the token matches with any individual resource
11007  * manager.
11008  */
11009  for (rmid = 0; rmid <= RM_MAX_ID; rmid++)
11010  {
11011  if (pg_strcasecmp(tok, RmgrTable[rmid].rm_name) == 0 &&
11012  RmgrTable[rmid].rm_mask != NULL)
11013  {
11014  newwalconsistency[rmid] = true;
11015  found = true;
11016  }
11017  }
11018  }
11019 
11020  /* If a valid resource manager is found, check for the next one. */
11021  if (!found)
11022  {
11023  GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
11024  pfree(rawstring);
11025  list_free(elemlist);
11026  return false;
11027  }
11028  }
11029 
11030  pfree(rawstring);
11031  list_free(elemlist);
11032 
11033  /* assign new value */
11034  *extra = guc_malloc(ERROR, (RM_MAX_ID + 1) * sizeof(bool));
11035  memcpy(*extra, newwalconsistency, (RM_MAX_ID + 1) * sizeof(bool));
11036  return true;
11037 }
#define GUC_check_errdetail
Definition: guc.h:414
char * pstrdup(const char *in)
Definition: mcxt.c:1186
const RmgrData RmgrTable[RM_MAX_ID+1]
Definition: rmgr.c:36
#define MemSet(start, val, len)
Definition: c.h:962
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
void pfree(void *pointer)
Definition: mcxt.c:1056
#define ERROR
Definition: elog.h:43
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3652
#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:190
#define newval
void list_free(List *list)
Definition: list.c:1377
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4681
Definition: pg_list.h:50

◆ 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 6539 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().

6541 {
6542  const struct config_enum_entry *entry;
6543  StringInfoData retstr;
6544  int seplen;
6545 
6546  initStringInfo(&retstr);
6547  appendStringInfoString(&retstr, prefix);
6548 
6549  seplen = strlen(separator);
6550  for (entry = record->options; entry && entry->name; entry++)
6551  {
6552  if (!entry->hidden)
6553  {
6554  appendStringInfoString(&retstr, entry->name);
6555  appendBinaryStringInfo(&retstr, separator, seplen);
6556  }
6557  }
6558 
6559  /*
6560  * All the entries may have been hidden, leaving the string empty if no
6561  * prefix was given. This indicates a broken GUC setup, since there is no
6562  * use for an enum without any values, so we just check to make sure we
6563  * don't write to invalid memory instead of actually trying to do
6564  * something smart with it.
6565  */
6566  if (retstr.len >= seplen)
6567  {
6568  /* Replace final separator */
6569  retstr.data[retstr.len - seplen] = '\0';
6570  retstr.len -= seplen;
6571  }
6572 
6573  appendStringInfoString(&retstr, suffix);
6574 
6575  return retstr.data;
6576 }
Definition: guc.h:164
const struct config_enum_entry * options
Definition: guc_tables.h:246
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
const char * name
Definition: guc.h:166
void appendBinaryStringInfo(StringInfo str, const char *data, int datalen)
Definition: stringinfo.c:227
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 6513 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().

6515 {
6516  const struct config_enum_entry *entry;
6517 
6518  for (entry = record->options; entry && entry->name; entry++)
6519  {
6520  if (pg_strcasecmp(value, entry->name) == 0)
6521  {
6522  *retval = entry->val;
6523  return true;
6524  }
6525  }
6526 
6527  *retval = 0;
6528  return false;
6529 }
Definition: guc.h:164
static struct @145 value
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
const struct config_enum_entry * options
Definition: guc_tables.h:246
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 6490 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().

6491 {
6492  const struct config_enum_entry *entry;
6493 
6494  for (entry = record->options; entry && entry->name; entry++)
6495  {
6496  if (entry->val == val)
6497  return entry->name;
6498  }
6499 
6500  elog(ERROR, "could not find enum option %d for %s",
6501  val, record->gen.name);
6502  return NULL; /* silence compiler */
6503 }
Definition: guc.h:164
const char * name
Definition: guc_tables.h:149
#define ERROR
Definition: elog.h:43
const struct config_enum_entry * options
Definition: guc_tables.h:246
int val
Definition: guc.h:167
struct config_generic gen
Definition: guc_tables.h:242
const char * name
Definition: guc.h:166
#define elog(elevel,...)
Definition: elog.h:228
long val
Definition: informix.c:664

◆ convert_int_from_base_unit()

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

Definition at line 6196 of file guc.c.

References Assert, GUC_UNIT_MEMORY, i, memory_unit_conversion_table, rint(), time_unit_conversion_table, and unit_conversion::unit.

Referenced by _ShowOption().

6198 {
6199  const unit_conversion *table;
6200  int i;
6201 
6202  *unit = NULL;
6203 
6204  if (base_unit & GUC_UNIT_MEMORY)
6206  else
6208 
6209  for (i = 0; *table[i].unit; i++)
6210  {
6211  if (base_unit == table[i].base_unit)
6212  {
6213  /*
6214  * Accept the first conversion that divides the value evenly. We
6215  * assume that the conversions for each base unit are ordered from
6216  * greatest unit to the smallest!
6217  */
6218  if (table[i].multiplier <= 1.0 ||
6219  base_value % (int64) table[i].multiplier == 0)
6220  {
6221  *value = (int64) rint(base_value / table[i].multiplier);
6222  *unit = table[i].unit;
6223  break;
6224  }
6225  }
6226  }
6227 
6228  Assert(*unit != NULL);
6229 }
static const unit_conversion time_unit_conversion_table[]
Definition: guc.c:833
static const unit_conversion memory_unit_conversion_table[]
Definition: guc.c:796
static struct @145 value
double rint(double x)
Definition: rint.c:21
#define Assert(condition)
Definition: c.h:739
int i
char unit[MAX_UNIT_LEN+1]
Definition: guc.c:780
#define GUC_UNIT_MEMORY
Definition: guc.h:223

◆ convert_real_from_base_unit()

static void convert_real_from_base_unit ( double  base_value,
int  base_unit,
double *  value,
const char **  unit 
)
static

Definition at line 6238 of file guc.c.

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

Referenced by _ShowOption().

6240 {
6241  const unit_conversion *table;
6242  int i;
6243 
6244  *unit = NULL;
6245 
6246  if (base_unit & GUC_UNIT_MEMORY)
6248  else
6250 
6251  for (i = 0; *table[i].unit; i++)
6252  {
6253  if (base_unit == table[i].base_unit)
6254  {
6255  /*
6256  * Accept the first conversion that divides the value evenly; or
6257  * if there is none, use the smallest (last) target unit.
6258  *
6259  * What we actually care about here is whether snprintf with "%g"
6260  * will print the value as an integer, so the obvious test of
6261  * "*value == rint(*value)" is too strict; roundoff error might
6262  * make us choose an unreasonably small unit. As a compromise,
6263  * accept a divisor that is within 1e-8 of producing an integer.
6264  */
6265  *value = base_value / table[i].multiplier;
6266  *unit = table[i].unit;
6267  if (*value > 0 &&
6268  fabs((rint(*value) / *value) - 1.0) <= 1e-8)
6269  break;
6270  }
6271  }
6272 
6273  Assert(*unit != NULL);
6274 }
static const unit_conversion time_unit_conversion_table[]
Definition: guc.c:833
static const unit_conversion memory_unit_conversion_table[]
Definition: guc.c:796
static struct @145 value
double rint(double x)
Definition: rint.c:21
#define Assert(condition)
Definition: c.h:739
double multiplier
Definition: guc.c:783
e
Definition: preproc-init.c:82
int i
char unit[MAX_UNIT_LEN+1]
Definition: guc.c:780
#define GUC_UNIT_MEMORY
Definition: guc.h:223

◆ convert_to_base_unit()

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

Definition at line 6138 of file guc.c.

References GUC_UNIT_MEMORY, i, MAX_UNIT_LEN, memory_unit_conversion_table, unit_conversion::multiplier, rint(), time_unit_conversion_table, and unit_conversion::unit.

Referenced by parse_int(), and parse_real().

6140 {
6141  char unitstr[MAX_UNIT_LEN + 1];
6142  int unitlen;
6143  const unit_conversion *table;
6144  int i;
6145 
6146  /* extract unit string to compare to table entries */
6147  unitlen = 0;
6148  while (*unit != '\0' && !isspace((unsigned char) *unit) &&
6149  unitlen < MAX_UNIT_LEN)
6150  unitstr[unitlen++] = *(unit++);
6151  unitstr[unitlen] = '\0';
6152  /* allow whitespace after unit */
6153  while (isspace((unsigned char) *unit))
6154  unit++;
6155  if (*unit != '\0')
6156  return false; /* unit too long, or garbage after it */
6157 
6158  /* now search the appropriate table */
6159  if (base_unit & GUC_UNIT_MEMORY)
6161  else
6163 
6164  for (i = 0; *table[i].unit; i++)
6165  {
6166  if (base_unit == table[i].base_unit &&
6167  strcmp(unitstr, table[i].unit) == 0)
6168  {
6169  double cvalue = value * table[i].multiplier;
6170 
6171  /*
6172  * If the user gave a fractional value such as "30.1GB", round it
6173  * off to the nearest multiple of the next smaller unit, if there
6174  * is one.
6175  */
6176  if (*table[i + 1].unit &&
6177  base_unit == table[i + 1].base_unit)
6178  cvalue = rint(cvalue / table[i + 1].multiplier) *
6179  table[i + 1].multiplier;
6180 
6181  *base_value = cvalue;
6182  return true;
6183  }
6184  }
6185  return false;
6186 }
static const unit_conversion time_unit_conversion_table[]
Definition: guc.c:833
static const unit_conversion memory_unit_conversion_table[]
Definition: guc.c:796
#define MAX_UNIT_LEN
Definition: guc.c:776
static struct @145 value
double rint(double x)
Definition: rint.c:21
double multiplier
Definition: guc.c:783
int i
char unit[MAX_UNIT_LEN+1]
Definition: guc.c:780
#define GUC_UNIT_MEMORY
Definition: guc.h:223

◆ define_custom_variable()

static void define_custom_variable ( struct config_generic variable)
static

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

8465 {
8466  const char *name = variable->name;
8467  const char **nameAddr = &name;
8468  struct config_string *pHolder;
8469  struct config_generic **res;
8470 
8471  /*
8472  * See if there's a placeholder by the same name.
8473  */
8474  res = (struct config_generic **) bsearch((void *) &nameAddr,
8475  (void *) guc_variables,
8477  sizeof(struct config_generic *),
8478  guc_var_compare);
8479  if (res == NULL)
8480  {
8481  /*
8482  * No placeholder to replace, so we can just add it ... but first,
8483  * make sure it's initialized to its default value.
8484  */
8485  InitializeOneGUCOption(variable);
8486  add_guc_variable(variable, ERROR);
8487  return;
8488  }
8489 
8490  /*
8491  * This better be a placeholder
8492  */
8493  if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
8494  ereport(ERROR,
8495  (errcode(ERRCODE_INTERNAL_ERROR),
8496  errmsg("attempt to redefine parameter \"%s\"", name)));
8497 
8498  Assert((*res)->vartype == PGC_STRING);
8499  pHolder = (struct config_string *) (*res);
8500 
8501  /*
8502  * First, set the variable to its default value. We must do this even
8503  * though we intend to immediately apply a new value, since it's possible
8504  * that the new value is invalid.
8505  */
8506  InitializeOneGUCOption(variable);
8507 
8508  /*
8509  * Replace the placeholder. We aren't changing the name, so no re-sorting
8510  * is necessary
8511  */
8512  *res = variable;
8513 
8514  /*
8515  * Assign the string value(s) stored in the placeholder to the real
8516  * variable. Essentially, we need to duplicate all the active and stacked
8517  * values, but with appropriate validation and datatype adjustment.
8518  *
8519  * If an assignment fails, we report a WARNING and keep going. We don't
8520  * want to throw ERROR for bad values, because it'd bollix the add-on
8521  * module that's presumably halfway through getting loaded. In such cases
8522  * the default or previous state will become active instead.
8523  */
8524 
8525  /* First, apply the reset value if any */
8526  if (pHolder->reset_val)
8527  (void) set_config_option(name, pHolder->reset_val,
8528  pHolder->gen.reset_scontext,
8529  pHolder->gen.reset_source,
8530  GUC_ACTION_SET, true, WARNING, false);
8531  /* That should not have resulted in stacking anything */
8532  Assert(variable->stack == NULL);
8533 
8534  /* Now, apply current and stacked values, in the order they were stacked */
8535  reapply_stacked_values(variable, pHolder, pHolder->gen.stack,
8536  *(pHolder->variable),
8537  pHolder->gen.scontext, pHolder->gen.source);
8538 
8539  /* Also copy over any saved source-location information */
8540  if (pHolder->gen.sourcefile)
8541  set_config_sourcefile(name, pHolder->gen.sourcefile,
8542  pHolder->gen.sourceline);
8543 
8544  /*
8545  * Free up as much as we conveniently can of the placeholder structure.
8546  * (This neglects any stack items, so it's possible for some memory to be
8547  * leaked. Since this can only happen once per session per variable, it
8548  * doesn't seem worth spending much code on.)
8549  */
8550  set_string_field(pHolder, pHolder->variable, NULL);
8551  set_string_field(pHolder, &pHolder->reset_val, NULL);
8552 
8553  free(pHolder);
8554 }
GucSource source
Definition: guc_tables.h:158
static void static void set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
Definition: guc.c:7525
char ** variable
Definition: guc_tables.h:230
const char * name
Definition: guc_tables.h:149
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:8564
int errcode(int sqlerrcode)
Definition: elog.c:608
GucContext scontext
Definition: guc_tables.h:160
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:5143
#define ERROR
Definition: elog.h:43
static int num_guc_variables
Definition: guc.c:4640
char * sourcefile
Definition: guc_tables.h:164
GucSource reset_source
Definition: guc_tables.h:159
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:5291
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4753
#define ereport(elevel, rest)
Definition: elog.h:141
static struct config_generic ** guc_variables
Definition: guc.c:4637
#define WARNING
Definition: elog.h:40
struct config_generic gen
Definition: guc_tables.h:228
#define free(a)
Definition: header.h:65
char * reset_val
Definition: guc_tables.h:236
#define Assert(condition)
Definition: c.h:739
#define GUC_CUSTOM_PLACEHOLDER
Definition: guc.h:211
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:822
GucStack * stack
Definition: guc_tables.h:162
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:6794
static bool add_guc_variable(struct config_generic *var, int elevel)
Definition: guc.c:5008
GucContext reset_scontext
Definition: guc_tables.h:161

◆ 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 8645 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().

8655 {
8656  struct config_bool *var;
8657 
8658  var = (struct config_bool *)
8659  init_custom_variable(name, short_desc, long_desc, context, flags,
8660  PGC_BOOL, sizeof(struct config_bool));
8661  var->variable = valueAddr;
8662  var->boot_val = bootValue;
8663  var->reset_val = bootValue;
8664  var->check_hook = check_hook;
8665  var->assign_hook = assign_hook;
8666  var->show_hook = show_hook;
8667  define_custom_variable(&var->gen);
8668 }
bool * variable
Definition: guc_tables.h:184
GucBoolAssignHook assign_hook
Definition: guc_tables.h:187
bool boot_val
Definition: guc_tables.h:185
struct config_generic gen
Definition: guc_tables.h:182
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:8404
GucBoolCheckHook check_hook
Definition: guc_tables.h:186
GucShowHook show_hook
Definition: guc_tables.h:188
const char * name
Definition: encode.c:521
bool reset_val
Definition: guc_tables.h:190
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8464

◆ 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 8756 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().

8767 {
8768  struct config_enum *var;
8769 
8770  var = (struct config_enum *)
8771  init_custom_variable(name, short_desc, long_desc, context, flags,
8772  PGC_ENUM, sizeof(struct config_enum));
8773  var->variable = valueAddr;
8774  var->boot_val = bootValue;
8775  var->reset_val = bootValue;
8776  var->options = options;
8777  var->check_hook = check_hook;
8778  var->assign_hook = assign_hook;
8779  var->show_hook = show_hook;
8780  define_custom_variable(&var->gen);
8781 }
GucEnumCheckHook check_hook
Definition: guc_tables.h:247
GucEnumAssignHook assign_hook
Definition: guc_tables.h:248
int * variable
Definition: guc_tables.h:244
const struct config_enum_entry * options
Definition: guc_tables.h:246
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:8404
GucShowHook show_hook
Definition: guc_tables.h:249
struct config_generic gen
Definition: guc_tables.h:242
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8464

◆ 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 8671 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().

8683 {
8684  struct config_int *var;
8685 
8686  var = (struct config_int *)
8687  init_custom_variable(name, short_desc, long_desc, context, flags,
8688  PGC_INT, sizeof(struct config_int));
8689  var->variable = valueAddr;
8690  var->boot_val = bootValue;
8691  var->reset_val = bootValue;
8692  var->min = minValue;
8693  var->max = maxValue;
8694  var->check_hook = check_hook;
8695  var->assign_hook = assign_hook;
8696  var->show_hook = show_hook;
8697  define_custom_variable(&var->gen);
8698 }
int boot_val
Definition: guc_tables.h:199
GucIntAssignHook assign_hook
Definition: guc_tables.h:203
GucIntCheckHook check_hook
Definition: guc_tables.h:202
GucShowHook show_hook
Definition: guc_tables.h:204
int * variable
Definition: guc_tables.h:198
struct config_generic gen
Definition: guc_tables.h:196
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:8404
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8464
int reset_val
Definition: guc_tables.h:206

◆ 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 8701 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().

8713 {
8714  struct config_real *var;
8715 
8716  var = (struct config_real *)
8717  init_custom_variable(name, short_desc, long_desc, context, flags,
8718  PGC_REAL, sizeof(struct config_real));
8719  var->variable = valueAddr;
8720  var->boot_val = bootValue;
8721  var->reset_val = bootValue;
8722  var->min = minValue;
8723  var->max = maxValue;
8724  var->check_hook = check_hook;
8725  var->assign_hook = assign_hook;
8726  var->show_hook = show_hook;
8727  define_custom_variable(&var->gen);
8728 }
GucRealAssignHook assign_hook
Definition: guc_tables.h:219
double reset_val
Definition: guc_tables.h:222
GucRealCheckHook check_hook
Definition: guc_tables.h:218
GucShowHook show_hook
Definition: guc_tables.h:220
double * variable
Definition: guc_tables.h:214
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:8404
double max
Definition: guc_tables.h:217
double boot_val
Definition: guc_tables.h:215
const char * name
Definition: encode.c:521
double min
Definition: guc_tables.h:216
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8464
struct config_generic gen
Definition: guc_tables.h:212

◆ 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 8731 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().

8741 {
8742  struct config_string *var;
8743 
8744  var = (struct config_string *)
8745  init_custom_variable(name, short_desc, long_desc, context, flags,
8746  PGC_STRING, sizeof(struct config_string));
8747  var->variable = valueAddr;
8748  var->boot_val = bootValue;
8749  var->check_hook = check_hook;
8750  var->assign_hook = assign_hook;
8751  var->show_hook = show_hook;
8752  define_custom_variable(&var->gen);
8753 }
char ** variable
Definition: guc_tables.h:230
GucStringCheckHook check_hook
Definition: guc_tables.h:232
const char * boot_val
Definition: guc_tables.h:231
GucShowHook show_hook
Definition: guc_tables.h:234
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:8404
struct config_generic gen
Definition: guc_tables.h:228
GucStringAssignHook assign_hook
Definition: guc_tables.h:233
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8464

◆ discard_stack_value()

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

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

4869 {
4870  switch (gconf->vartype)
4871  {
4872  case PGC_BOOL:
4873  case PGC_INT:
4874  case PGC_REAL:
4875  case PGC_ENUM:
4876  /* no need to do anything */
4877  break;
4878  case PGC_STRING:
4879  set_string_field((struct config_string *) gconf,
4880  &(val->val.stringval),
4881  NULL);
4882  break;
4883  }
4884  set_extra_field(gconf, &(val->extra), NULL);
4885 }
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:4814
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4753
enum config_type vartype
Definition: guc_tables.h:156
char * stringval
Definition: guc_tables.h:36

◆ do_serialize()

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

Definition at line 10105 of file guc.c.

References elog, ERROR, and vsnprintf.

Referenced by serialize_variable().

10106 {
10107  va_list vargs;
10108  int n;
10109 
10110  if (*maxbytes <= 0)
10111  elog(ERROR, "not enough space to serialize GUC state");
10112 
10113  va_start(vargs, fmt);
10114  n = vsnprintf(*destptr, *maxbytes, fmt, vargs);
10115  va_end(vargs);
10116 
10117  if (n < 0)
10118  {
10119  /* Shouldn't happen. Better show errno description. */
10120  elog(ERROR, "vsnprintf failed: %m with format string \"%s\"", fmt);
10121  }
10122  if (n >= *maxbytes)
10123  {
10124  /* This shouldn't happen either, really. */
10125  elog(ERROR, "not enough space to serialize GUC state");
10126  }
10127 
10128  /* Shift the destptr ahead of the null terminator */
10129  *destptr += n + 1;
10130  *maxbytes -= n + 1;
10131 }
#define ERROR
Definition: elog.h:43
#define vsnprintf
Definition: port.h:191
#define elog(elevel,...)
Definition: elog.h:228

◆ do_serialize_binary()

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

Definition at line 10135 of file guc.c.

References elog, and ERROR.

Referenced by serialize_variable().

10136 {
10137  if (valsize > *maxbytes)
10138  elog(ERROR, "not enough space to serialize GUC state");
10139 
10140  memcpy(*destptr, val, valsize);
10141  *destptr += valsize;
10142  *maxbytes -= valsize;
10143 }
#define ERROR
Definition: elog.h:43
#define elog(elevel,...)
Definition: elog.h:228
long val
Definition: informix.c:664

◆ EmitWarningsOnPlaceholders()

void EmitWarningsOnPlaceholders ( const char *  className)

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

8785 {
8786  int classLen = strlen(className);
8787  int i;
8788 
8789  for (i = 0; i < num_guc_variables; i++)
8790  {
8791  struct config_generic *var = guc_variables[i];
8792 
8793  if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
8794  strncmp(className, var->name, classLen) == 0 &&
8795  var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
8796  {
8797  ereport(WARNING,
8798  (errcode(ERRCODE_UNDEFINED_OBJECT),
8799  errmsg("unrecognized configuration parameter \"%s\"",
8800  var->name)));
8801  }
8802  }
8803 }
const char * name
Definition: guc_tables.h:149
int errcode(int sqlerrcode)
Definition: elog.c:608
#define GUC_QUALIFIER_SEPARATOR
Definition: guc.h:199
static int num_guc_variables
Definition: guc.c:4640
#define ereport(elevel, rest)
Definition: elog.h:141
static struct config_generic ** guc_variables
Definition: guc.c:4637
#define WARNING
Definition: elog.h:40
#define GUC_CUSTOM_PLACEHOLDER
Definition: guc.h:211
int errmsg(const char *fmt,...)
Definition: elog.c:822
int i

◆ estimate_variable_size()

static Size estimate_variable_size ( struct config_generic gconf)
static

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

9985 {
9986  Size size;
9987  Size valsize = 0;
9988 
9989  if (can_skip_gucvar(gconf))
9990  return 0;
9991 
9992  /* Name, plus trailing zero byte. */
9993  size = strlen(gconf->name) + 1;
9994 
9995  /* Get the maximum display length of the GUC value. */
9996  switch (gconf->vartype)
9997  {
9998  case PGC_BOOL:
9999  {
10000  valsize = 5; /* max(strlen('true'), strlen('false')) */
10001  }
10002  break;
10003 
10004  case PGC_INT:
10005  {
10006  struct config_int *conf = (struct config_int *) gconf;
10007 
10008  /*
10009  * Instead of getting the exact display length, use max
10010  * length. Also reduce the max length for typical ranges of
10011  * small values. Maximum value is 2147483647, i.e. 10 chars.
10012  * Include one byte for sign.
10013  */
10014  if (Abs(*conf->variable) < 1000)
10015  valsize = 3 + 1;
10016  else
10017  valsize = 10 + 1;
10018  }
10019  break;
10020 
10021  case PGC_REAL:
10022  {
10023  /*
10024  * We are going to print it with %e with REALTYPE_PRECISION
10025  * fractional digits. Account for sign, leading digit,
10026  * decimal point, and exponent with up to 3 digits. E.g.
10027  * -3.99329042340000021e+110
10028  */
10029  valsize = 1 + 1 + 1 + REALTYPE_PRECISION + 5;
10030  }
10031  break;
10032 
10033  case PGC_STRING:
10034  {
10035  struct config_string *conf = (struct config_string *) gconf;
10036 
10037  /*
10038  * If the value is NULL, we transmit it as an empty string.
10039  * Although this is not physically the same value, GUC
10040  * generally treats a NULL the same as empty string.
10041  */
10042  if (*conf->variable)
10043  valsize = strlen(*conf->variable);
10044  else
10045  valsize = 0;
10046  }
10047  break;
10048 
10049  case PGC_ENUM:
10050  {
10051  struct config_enum *conf = (struct config_enum *) gconf;
10052 
10053  valsize = strlen(config_enum_lookup_by_value(conf, *conf->variable));
10054  }
10055  break;
10056  }
10057 
10058  /* Allow space for terminating zero-byte for value */
10059  size = add_size(size, valsize + 1);
10060 
10061  if (gconf->sourcefile)
10062  size = add_size(size, strlen(gconf->sourcefile));
10063 
10064  /* Allow space for terminating zero-byte for sourcefile */
10065  size = add_size(size, 1);
10066 
10067  /* Include line whenever file is nonempty. */
10068  if (gconf->sourcefile && gconf->sourcefile[0])
10069  size = add_size(size, sizeof(gconf->sourceline));
10070 
10071  size = add_size(size, sizeof(gconf->source));
10072  size = add_size(size, sizeof(gconf->scontext));
10073 
10074  return size;
10075 }
GucSource source
Definition: guc_tables.h:158
char ** variable
Definition: guc_tables.h:230
const char * name
Definition: guc_tables.h:149
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:6490
GucContext scontext
Definition: guc_tables.h:160
#define Abs(x)
Definition: c.h:917
int * variable
Definition: guc_tables.h:198
int * variable
Definition: guc_tables.h:244
char * sourcefile
Definition: guc_tables.h:164
static bool can_skip_gucvar(struct config_generic *gconf)
Definition: guc.c:9970
#define REALTYPE_PRECISION
Definition: guc.c:117
enum config_type vartype
Definition: guc_tables.h:156
Size add_size(Size s1, Size s2)
Definition: shmem.c:498
size_t Size
Definition: c.h:467

◆ EstimateGUCStateSpace()

Size EstimateGUCStateSpace ( void  )

Definition at line 10082 of file guc.c.

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

Referenced by InitializeParallelDSM().

10083 {
10084  Size size;
10085  int i;
10086 
10087  /* Add space reqd for saving the data size of the guc state */
10088  size = sizeof(Size);
10089 
10090  /* Add up the space needed for each GUC variable */
10091  for (i = 0; i < num_guc_variables; i++)
10092  size = add_size(size,
10094 
10095  return size;
10096 }
static int num_guc_variables
Definition: guc.c:4640
static struct config_generic ** guc_variables
Definition: guc.c:4637
Size add_size(Size s1, Size s2)
Definition: shmem.c:498
size_t Size
Definition: c.h:467
static Size estimate_variable_size(struct config_generic *gconf)
Definition: guc.c:9984
int i

◆ ExecSetVariableStmt()

void ExecSetVariableStmt ( VariableSetStmt stmt,
bool  isTopLevel 
)

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

Referenced by standard_ProcessUtility().

8193 {
8195 
8196  /*
8197  * Workers synchronize these parameters at the start of the parallel
8198  * operation; then, we block SET during the operation.
8199  */
8200  if (IsInParallelMode())
8201  ereport(ERROR,
8202  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
8203  errmsg("cannot set parameters during a parallel operation")));
8204 
8205  switch (stmt->kind)
8206  {
8207  case VAR_SET_VALUE:
8208  case VAR_SET_CURRENT:
8209  if (stmt->is_local)
8210  WarnNoTransactionBlock(isTopLevel, "SET LOCAL");
8211  (void) set_config_option(stmt->name,
8212  ExtractSetVariableArgs(stmt),
8214  PGC_S_SESSION,
8215  action, true, 0, false);
8216  break;
8217  case VAR_SET_MULTI:
8218 
8219  /*
8220  * Special-case SQL syntaxes. The TRANSACTION and SESSION
8221  * CHARACTERISTICS cases effectively set more than one variable
8222  * per statement. TRANSACTION SNAPSHOT only takes one argument,
8223  * but we put it here anyway since it's a special case and not
8224  * related to any GUC variable.
8225  */
8226  if (strcmp(stmt->name, "TRANSACTION") == 0)
8227  {
8228  ListCell *head;
8229 
8230  WarnNoTransactionBlock(isTopLevel, "SET TRANSACTION");
8231 
8232  foreach(head, stmt->args)
8233  {
8234  DefElem *item = (DefElem *) lfirst(head);
8235 
8236  if (strcmp(item->defname, "transaction_isolation") == 0)
8237  SetPGVariable("transaction_isolation",
8238  list_make1(item->arg), stmt->is_local);
8239  else if (strcmp(item->defname, "transaction_read_only") == 0)
8240  SetPGVariable("transaction_read_only",
8241  list_make1(item->arg), stmt->is_local);
8242  else if (strcmp(item->defname, "transaction_deferrable") == 0)
8243  SetPGVariable("transaction_deferrable",
8244  list_make1(item->arg), stmt->is_local);
8245  else
8246  elog(ERROR, "unexpected SET TRANSACTION element: %s",
8247  item->defname);
8248  }
8249  }
8250  else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
8251  {
8252  ListCell *head;
8253 
8254  foreach(head, stmt->args)
8255  {
8256  DefElem *item = (DefElem *) lfirst(head);
8257 
8258  if (strcmp(item->defname, "transaction_isolation") == 0)
8259  SetPGVariable("default_transaction_isolation",
8260  list_make1(item->arg), stmt->is_local);
8261  else if (strcmp(item->defname, "transaction_read_only") == 0)
8262  SetPGVariable("default_transaction_read_only",
8263  list_make1(item->arg), stmt->is_local);
8264  else if (strcmp(item->defname, "transaction_deferrable") == 0)
8265  SetPGVariable("default_transaction_deferrable",
8266  list_make1(item->arg), stmt->is_local);
8267  else
8268  elog(ERROR, "unexpected SET SESSION element: %s",
8269  item->defname);
8270  }
8271  }
8272  else if (strcmp(stmt->name, "TRANSACTION SNAPSHOT") == 0)
8273  {
8274  A_Const *con = linitial_node(A_Const, stmt->args);
8275 
8276  if (stmt->is_local)
8277  ereport(ERROR,
8278  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8279  errmsg("SET LOCAL TRANSACTION SNAPSHOT is not implemented")));
8280 
8281  WarnNoTransactionBlock(isTopLevel, "SET TRANSACTION");
8282  Assert(nodeTag(&con->val) == T_String);
8283  ImportSnapshot(strVal(&con->val));
8284  }
8285  else
8286  elog(ERROR, "unexpected SET MULTI element: %s",
8287  stmt->name);
8288  break;
8289  case VAR_SET_DEFAULT:
8290  if (stmt->is_local)
8291  WarnNoTransactionBlock(isTopLevel, "SET LOCAL");
8292  /* fall through */
8293  case VAR_RESET:
8294  if (strcmp(stmt->name, "transaction_isolation") == 0)
8295  WarnNoTransactionBlock(isTopLevel, "RESET TRANSACTION");
8296 
8297  (void) set_config_option(stmt->name,
8298  NULL,
8300  PGC_S_SESSION,
8301  action, true, 0, false);
8302  break;
8303  case VAR_RESET_ALL:
8304  ResetAllOptions();
8305  break;
8306  }
8307 }
void ImportSnapshot(const char *idstr)
Definition: snapmgr.c:1462
VariableSetKind kind
Definition: parsenodes.h:2039
void WarnNoTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3391
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:608
bool superuser(void)
Definition: superuser.c:46
#define linitial_node(type, l)
Definition: pg_list.h:198
GucAction
Definition: guc.h:191
#define list_make1(x1)
Definition: pg_list.h:227
bool IsInParallelMode(void)
Definition: xact.c:996
#define ERROR
Definition: elog.h:43
Definition: guc.h:75
void ResetAllOptions(void)
Definition: guc.c:5586
#define ereport(elevel, rest)
Definition: elog.h:141
Node * arg
Definition: parsenodes.h:731
#define Assert(condition)
Definition: c.h:739
#define lfirst(lc)
Definition: pg_list.h:190
#define nodeTag(nodeptr)
Definition: nodes.h:530
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define elog(elevel,...)
Definition: elog.h:228
char * defname
Definition: parsenodes.h:730
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
Definition: guc.c:8316
Value val
Definition: parsenodes.h:288
int set_config_option(const char *name, const char *value, GucContext context, GucSource source, GucAction action, bool changeVal, int elevel, bool is_reload)
Definition: guc.c:6794
void SetPGVariable(const char *name, List *args, bool is_local)
Definition: guc.c:8336

◆ extra_field_used()

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

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

4770 {
4771  GucStack *stack;
4772 
4773  if (extra == gconf->extra)
4774  return true;
4775  switch (gconf->vartype)
4776  {
4777  case PGC_BOOL:
4778  if (extra == ((struct config_bool *) gconf)->reset_extra)
4779  return true;
4780  break;
4781  case PGC_INT:
4782  if (extra == ((struct config_int *) gconf)->reset_extra)
4783  return true;
4784  break;
4785  case PGC_REAL:
4786  if (extra == ((struct config_real *) gconf)->reset_extra)
4787  return true;
4788  break;
4789  case PGC_STRING:
4790  if (extra == ((struct config_string *) gconf)->reset_extra)
4791