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 <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
#include "access/commit_ts.h"
#include "access/gin.h"
#include "access/rmgr.h"
#include "access/tableam.h"
#include "access/toast_compression.h"
#include "access/transam.h"
#include "access/twophase.h"
#include "access/xact.h"
#include "access/xlog_internal.h"
#include "access/xlogprefetch.h"
#include "catalog/namespace.h"
#include "catalog/pg_authid.h"
#include "catalog/storage.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/acl.h"
#include "utils/backend_status.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/inval.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 bool check_maintenance_io_concurrency (int *newval, void **extra, GucSource source)
 
static bool check_huge_page_size (int *newval, void **extra, GucSource source)
 
static bool check_client_connection_check_interval (int *newval, void **extra, GucSource source)
 
static void assign_maintenance_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 const char * show_in_hot_standby (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)
 
 StaticAssertDecl (lengthof(bytea_output_options)==(BYTEA_OUTPUT_HEX+2), "array length mismatch")
 
 StaticAssertDecl (lengthof(intervalstyle_options)==(INTSTYLE_ISO_8601+2), "array length mismatch")
 
 StaticAssertDecl (lengthof(log_error_verbosity_options)==(PGERROR_VERBOSE+2), "array length mismatch")
 
 StaticAssertDecl (lengthof(log_statement_options)==(LOGSTMT_ALL+2), "array length mismatch")
 
 StaticAssertDecl (lengthof(session_replication_role_options)==(SESSION_REPLICATION_ROLE_LOCAL+2), "array length mismatch")
 
 StaticAssertDecl (lengthof(track_function_options)==(TRACK_FUNC_ALL+2), "array length mismatch")
 
 StaticAssertDecl (lengthof(xmlbinary_options)==(XMLBINARY_HEX+2), "array length mismatch")
 
 StaticAssertDecl (lengthof(xmloption_options)==(XMLOPTION_CONTENT+2), "array length mismatch")
 
 StaticAssertDecl (lengthof(ssl_protocol_versions_info)==(PG_TLS1_3_VERSION+2), "array length mismatch")
 
 StaticAssertDecl (lengthof(GucContext_Names)==(PGC_USERSET+1), "array length mismatch")
 
 StaticAssertDecl (lengthof(GucSource_Names)==(PGC_S_SESSION+1), "array length mismatch")
 
 StaticAssertDecl (lengthof(config_group_names)==(DEVELOPER_OPTIONS+2), "array length mismatch")
 
 StaticAssertDecl (lengthof(config_type_names)==(PGC_ENUM+1), "array length mismatch")
 
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 bool valid_custom_variable_name (const char *name)
 
static struct config_genericadd_placeholder_variable (const char *name, int elevel)
 
static struct config_genericfind_option (const char *name, bool create_placeholders, bool skip_errors, 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)
 
void ReportChangedGUCOptions (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 ignore_invalid_pages
 
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 recovery_init_sync_method_options []
 
static struct config_enum_entry shared_memory_options []
 
static struct config_enum_entry default_toast_compression_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 compute_query_id = false
 
bool log_duration = false
 
bool Debug_print_plan = false
 
bool Debug_print_parse = false
 
bool Debug_print_rewritten = false
 
bool Debug_pretty_print = true
 
bool log_parser_stats = false
 
bool log_planner_stats = false
 
bool log_executor_stats = false
 
bool log_statement_stats = false
 
bool log_btree_build_stats = false
 
char * event_source
 
bool row_security
 
bool check_function_bodies = true
 
bool default_with_oids = false
 
bool session_auth_is_superuser
 
int log_min_error_statement = ERROR
 
int log_min_messages = WARNING
 
int client_min_messages = NOTICE
 
int log_min_duration_sample = -1
 
int log_min_duration_statement = -1
 
int log_parameter_max_length = -1
 
int log_parameter_max_length_on_error = 0
 
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
 
int huge_page_size
 
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 bool in_hot_standby
 
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 size_guc_variables
 
static bool guc_dirty
 
static bool reporting_enabled
 
static bool report_needed
 
static int GUCNestLevel = 0
 

Macro Definition Documentation

◆ CONFIG_FILENAME

#define CONFIG_FILENAME   "postgresql.conf"

Definition at line 116 of file guc.c.

Referenced by SelectConfigFiles().

◆ HBA_FILENAME

#define HBA_FILENAME   "pg_hba.conf"

Definition at line 117 of file guc.c.

Referenced by SelectConfigFiles().

◆ IDENT_FILENAME

#define IDENT_FILENAME   "pg_ident.conf"

Definition at line 118 of file guc.c.

Referenced by SelectConfigFiles().

◆ MAX_UNIT_LEN

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

Definition at line 843 of file guc.c.

Referenced by convert_to_base_unit().

◆ newval [1/5]

◆ newval [2/5]

#define newval   (newval_union.intval)

◆ newval [3/5]

#define newval   (newval_union.realval)

◆ newval [4/5]

#define newval   (newval_union.stringval)

◆ newval [5/5]

#define newval   (newval_union.enumval)

◆ NUM_PG_FILE_SETTINGS_ATTS

#define NUM_PG_FILE_SETTINGS_ATTS   7

Referenced by show_all_file_settings().

◆ NUM_PG_SETTINGS_ATTS

#define NUM_PG_SETTINGS_ATTS   17

Definition at line 9875 of file guc.c.

Referenced by show_all_settings().

◆ PG_KRB_SRVTAB

#define PG_KRB_SRVTAB   ""

Definition at line 113 of file guc.c.

◆ REALTYPE_PRECISION

#define REALTYPE_PRECISION   17

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

10122 {
10123  char buffer[256];
10124  const char *val;
10125 
10126  switch (record->vartype)
10127  {
10128  case PGC_BOOL:
10129  {
10130  struct config_bool *conf = (struct config_bool *) record;
10131 
10132  if (conf->show_hook)
10133  val = conf->show_hook();
10134  else
10135  val = *conf->variable ? "on" : "off";
10136  }
10137  break;
10138 
10139  case PGC_INT:
10140  {
10141  struct config_int *conf = (struct config_int *) record;
10142 
10143  if (conf->show_hook)
10144  val = conf->show_hook();
10145  else
10146  {
10147  /*
10148  * Use int64 arithmetic to avoid overflows in units
10149  * conversion.
10150  */
10151  int64 result = *conf->variable;
10152  const char *unit;
10153 
10154  if (use_units && result > 0 && (record->flags & GUC_UNIT))
10156  record->flags & GUC_UNIT,
10157  &result, &unit);
10158  else
10159  unit = "";
10160 
10161  snprintf(buffer, sizeof(buffer), INT64_FORMAT "%s",
10162  result, unit);
10163  val = buffer;
10164  }
10165  }
10166  break;
10167 
10168  case PGC_REAL:
10169  {
10170  struct config_real *conf = (struct config_real *) record;
10171 
10172  if (conf->show_hook)
10173  val = conf->show_hook();
10174  else
10175  {
10176  double result = *conf->variable;
10177  const char *unit;
10178 
10179  if (use_units && result > 0 && (record->flags & GUC_UNIT))
10181  record->flags & GUC_UNIT,
10182  &result, &unit);
10183  else
10184  unit = "";
10185 
10186  snprintf(buffer, sizeof(buffer), "%g%s",
10187  result, unit);
10188  val = buffer;
10189  }
10190  }
10191  break;
10192 
10193  case PGC_STRING:
10194  {
10195  struct config_string *conf = (struct config_string *) record;
10196 
10197  if (conf->show_hook)
10198  val = conf->show_hook();
10199  else if (*conf->variable && **conf->variable)
10200  val = *conf->variable;
10201  else
10202  val = "";
10203  }
10204  break;
10205 
10206  case PGC_ENUM:
10207  {
10208  struct config_enum *conf = (struct config_enum *) record;
10209 
10210  if (conf->show_hook)
10211  val = conf->show_hook();
10212  else
10213  val = config_enum_lookup_by_value(conf, *conf->variable);
10214  }
10215  break;
10216 
10217  default:
10218  /* just to keep compiler quiet */
10219  val = "???";
10220  break;
10221  }
10222 
10223  return pstrdup(val);
10224 }
char ** variable
Definition: guc_tables.h:233
char * pstrdup(const char *in)
Definition: mcxt.c:1299
bool * variable
Definition: guc_tables.h:187
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:7004
#define GUC_UNIT
Definition: guc.h:232
GucShowHook show_hook
Definition: guc_tables.h:207
int * variable
Definition: guc_tables.h:201
int * variable
Definition: guc_tables.h:247
static void convert_real_from_base_unit(double base_value, int base_unit, double *value, const char **unit)
Definition: guc.c:6752
GucShowHook show_hook
Definition: guc_tables.h:237
GucShowHook show_hook
Definition: guc_tables.h:223
double * variable
Definition: guc_tables.h:217
enum config_type vartype
Definition: guc_tables.h:156
GucShowHook show_hook
Definition: guc_tables.h:252
GucShowHook show_hook
Definition: guc_tables.h:191
#define INT64_FORMAT
Definition: c.h:483
static void convert_int_from_base_unit(int64 base_value, int base_unit, int64 *value, const char **unit)
Definition: guc.c:6710
#define snprintf
Definition: port.h:216
long val
Definition: informix.c:664

◆ add_guc_variable()

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

Definition at line 5369 of file guc.c.

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

Referenced by add_placeholder_variable(), and define_custom_variable().

5370 {
5372  {
5373  /*
5374  * Increase the vector by 25%
5375  */
5376  int size_vars = size_guc_variables + size_guc_variables / 4;
5377  struct config_generic **guc_vars;
5378 
5379  if (size_vars == 0)
5380  {
5381  size_vars = 100;
5382  guc_vars = (struct config_generic **)
5383  guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
5384  }
5385  else
5386  {
5387  guc_vars = (struct config_generic **)
5388  guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
5389  }
5390 
5391  if (guc_vars == NULL)
5392  return false; /* out of memory */
5393 
5394  guc_variables = guc_vars;
5395  size_guc_variables = size_vars;
5396  }
5399  sizeof(struct config_generic *), guc_var_compare);
5400  return true;
5401 }
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:5573
static int num_guc_variables
Definition: guc.c:5019
static void * guc_realloc(int elevel, void *old, size_t size)
Definition: guc.c:5075
static struct config_generic ** guc_variables
Definition: guc.c:5016
static int size_guc_variables
Definition: guc.c:5022
static int elevel
Definition: vacuumlazy.c:400
#define qsort(a, b, c, d)
Definition: port.h:504
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:5059

◆ add_placeholder_variable()

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

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

5447 {
5448  size_t sz = sizeof(struct config_string) + sizeof(char *);
5449  struct config_string *var;
5450  struct config_generic *gen;
5451 
5452  var = (struct config_string *) guc_malloc(elevel, sz);
5453  if (var == NULL)
5454  return NULL;
5455  memset(var, 0, sz);
5456  gen = &var->gen;
5457 
5458  gen->name = guc_strdup(elevel, name);
5459  if (gen->name == NULL)
5460  {
5461  free(var);
5462  return NULL;
5463  }
5464 
5465  gen->context = PGC_USERSET;
5466  gen->group = CUSTOM_OPTIONS;
5467  gen->short_desc = "GUC placeholder variable";
5469  gen->vartype = PGC_STRING;
5470 
5471  /*
5472  * The char* is allocated at the end of the struct since we have no
5473  * 'static' place to point to. Note that the current value, as well as
5474  * the boot and reset values, start out NULL.
5475  */
5476  var->variable = (char **) (var + 1);
5477 
5478  if (!add_guc_variable((struct config_generic *) var, elevel))
5479  {
5480  free(unconstify(char *, gen->name));
5481  free(var);
5482  return NULL;
5483  }
5484 
5485  return gen;
5486 }
char ** variable
Definition: guc_tables.h:233
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:5091
#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:1243
static int elevel
Definition: vacuumlazy.c:400
struct config_generic gen
Definition: guc_tables.h:231
#define free(a)
Definition: header.h:65
#define GUC_CUSTOM_PLACEHOLDER
Definition: guc.h:211
const char * name
Definition: encode.c:515
enum config_group group
Definition: guc_tables.h:151
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:5059
GucContext context
Definition: guc_tables.h:150
static bool add_guc_variable(struct config_generic *var, int elevel)
Definition: guc.c:5369

◆ AlterSystemSetConfigFile()

void AlterSystemSetConfigFile ( AlterSystemStmt altersysstmt)

Definition at line 8505 of file guc.c.

References AllocateFile(), Assert, 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().

8506 {
8507  char *name;
8508  char *value;
8509  bool resetall = false;
8510  ConfigVariable *head = NULL;
8511  ConfigVariable *tail = NULL;
8512  volatile int Tmpfd;
8513  char AutoConfFileName[MAXPGPATH];
8514  char AutoConfTmpFileName[MAXPGPATH];
8515 
8516  if (!superuser())
8517  ereport(ERROR,
8518  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
8519  errmsg("must be superuser to execute ALTER SYSTEM command")));
8520 
8521  /*
8522  * Extract statement arguments
8523  */
8524  name = altersysstmt->setstmt->name;
8525 
8526  switch (altersysstmt->setstmt->kind)
8527  {
8528  case VAR_SET_VALUE:
8529  value = ExtractSetVariableArgs(altersysstmt->setstmt);
8530  break;
8531 
8532  case VAR_SET_DEFAULT:
8533  case VAR_RESET:
8534  value = NULL;
8535  break;
8536 
8537  case VAR_RESET_ALL:
8538  value = NULL;
8539  resetall = true;
8540  break;
8541 
8542  default:
8543  elog(ERROR, "unrecognized alter system stmt type: %d",
8544  altersysstmt->setstmt->kind);
8545  break;
8546  }
8547 
8548  /*
8549  * Unless it's RESET_ALL, validate the target variable and value
8550  */
8551  if (!resetall)
8552  {
8553  struct config_generic *record;
8554 
8555  record = find_option(name, false, false, ERROR);
8556  Assert(record != NULL);
8557 
8558  /*
8559  * Don't allow parameters that can't be set in configuration files to
8560  * be set in PG_AUTOCONF_FILENAME file.
8561  */
8562  if ((record->context == PGC_INTERNAL) ||
8563  (record->flags & GUC_DISALLOW_IN_FILE) ||
8564  (record->flags & GUC_DISALLOW_IN_AUTO_FILE))
8565  ereport(ERROR,
8566  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
8567  errmsg("parameter \"%s\" cannot be changed",
8568  name)));
8569 
8570  /*
8571  * If a value is specified, verify that it's sane.
8572  */
8573  if (value)
8574  {
8575  union config_var_val newval;
8576  void *newextra = NULL;
8577 
8578  /* Check that it's acceptable for the indicated parameter */
8579  if (!parse_and_validate_value(record, name, value,
8580  PGC_S_FILE, ERROR,
8581  &newval, &newextra))
8582  ereport(ERROR,
8583  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8584  errmsg("invalid value for parameter \"%s\": \"%s\"",
8585  name, value)));
8586 
8587  if (record->vartype == PGC_STRING && newval.stringval != NULL)
8588  free(newval.stringval);
8589  if (newextra)
8590  free(newextra);
8591 
8592  /*
8593  * We must also reject values containing newlines, because the
8594  * grammar for config files doesn't support embedded newlines in
8595  * string literals.
8596  */
8597  if (strchr(value, '\n'))
8598  ereport(ERROR,
8599  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8600  errmsg("parameter value for ALTER SYSTEM must not contain a newline")));
8601  }
8602  }
8603 
8604  /*
8605  * PG_AUTOCONF_FILENAME and its corresponding temporary file are always in
8606  * the data directory, so we can reference them by simple relative paths.
8607  */
8608  snprintf(AutoConfFileName, sizeof(AutoConfFileName), "%s",
8610  snprintf(AutoConfTmpFileName, sizeof(AutoConfTmpFileName), "%s.%s",
8611  AutoConfFileName,
8612  "tmp");
8613 
8614  /*
8615  * Only one backend is allowed to operate on PG_AUTOCONF_FILENAME at a
8616  * time. Use AutoFileLock to ensure that. We must hold the lock while
8617  * reading the old file contents.
8618  */
8619  LWLockAcquire(AutoFileLock, LW_EXCLUSIVE);
8620 
8621  /*
8622  * If we're going to reset everything, then no need to open or parse the
8623  * old file. We'll just write out an empty list.
8624  */
8625  if (!resetall)
8626  {
8627  struct stat st;
8628 
8629  if (stat(AutoConfFileName, &st) == 0)
8630  {
8631  /* open old file PG_AUTOCONF_FILENAME */
8632  FILE *infile;
8633 
8634  infile = AllocateFile(AutoConfFileName, "r");
8635  if (infile == NULL)
8636  ereport(ERROR,
8638  errmsg("could not open file \"%s\": %m",
8639  AutoConfFileName)));
8640 
8641  /* parse it */
8642  if (!ParseConfigFp(infile, AutoConfFileName, 0, LOG, &head, &tail))
8643  ereport(ERROR,
8644  (errcode(ERRCODE_CONFIG_FILE_ERROR),
8645  errmsg("could not parse contents of file \"%s\"",
8646  AutoConfFileName)));
8647 
8648  FreeFile(infile);
8649  }
8650 
8651  /*
8652  * Now, replace any existing entry with the new value, or add it if
8653  * not present.
8654  */
8655  replace_auto_config_value(&head, &tail, name, value);
8656  }
8657 
8658  /*
8659  * To ensure crash safety, first write the new file data to a temp file,
8660  * then atomically rename it into place.
8661  *
8662  * If there is a temp file left over due to a previous crash, it's okay to
8663  * truncate and reuse it.
8664  */
8665  Tmpfd = BasicOpenFile(AutoConfTmpFileName,
8666  O_CREAT | O_RDWR | O_TRUNC);
8667  if (Tmpfd < 0)
8668  ereport(ERROR,
8670  errmsg("could not open file \"%s\": %m",
8671  AutoConfTmpFileName)));
8672 
8673  /*
8674  * Use a TRY block to clean up the file if we fail. Since we need a TRY
8675  * block anyway, OK to use BasicOpenFile rather than OpenTransientFile.
8676  */
8677  PG_TRY();
8678  {
8679  /* Write and sync the new contents to the temporary file */
8680  write_auto_conf_file(Tmpfd, AutoConfTmpFileName, head);
8681 
8682  /* Close before renaming; may be required on some platforms */
8683  close(Tmpfd);
8684  Tmpfd = -1;
8685 
8686  /*
8687  * As the rename is atomic operation, if any problem occurs after this
8688  * at worst it can lose the parameters set by last ALTER SYSTEM
8689  * command.
8690  */
8691  durable_rename(AutoConfTmpFileName, AutoConfFileName, ERROR);
8692  }
8693  PG_CATCH();
8694  {
8695  /* Close file first, else unlink might fail on some platforms */
8696  if (Tmpfd >= 0)
8697  close(Tmpfd);
8698 
8699  /* Unlink, but ignore any error */
8700  (void) unlink(AutoConfTmpFileName);
8701 
8702  PG_RE_THROW();
8703  }
8704  PG_END_TRY();
8705 
8706  FreeConfigVariables(head);
8707 
8708  LWLockRelease(AutoFileLock);
8709 }
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:7111
VariableSetKind kind
Definition: parsenodes.h:2120
static struct @142 value
int errcode(int sqlerrcode)
Definition: elog.c:698
bool superuser(void)
Definition: superuser.c:46
#define LOG
Definition: elog.h:26
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1805
#define ERROR
Definition: elog.h:46
#define MAXPGPATH
VariableSetStmt * setstmt
Definition: parsenodes.h:3291
int errcode_for_file_access(void)
Definition: elog.c:721
FILE * AllocateFile(const char *name, const char *mode)
Definition: fd.c:2373
int durable_rename(const char *oldfile, const char *newfile, int elevel)
Definition: fd.c:692
static struct config_generic * find_option(const char *name, bool create_placeholders, bool skip_errors, int elevel)
Definition: guc.c:5504
enum config_type vartype
Definition: guc_tables.h:156
#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:8367
#define ereport(elevel,...)
Definition: elog.h:157
static void infile(const char *filename)
Definition: zic.c:1241
#define free(a)
Definition: header.h:65
#define PG_CATCH()
Definition: elog.h:323
#define Assert(condition)
Definition: c.h:804
#define newval
#define PG_AUTOCONF_FILENAME
Definition: guc.h:34
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1203
#define PG_RE_THROW()
Definition: elog.h:354
const char * name
Definition: encode.c:515
#define GUC_DISALLOW_IN_AUTO_FILE
Definition: guc.h:215
int BasicOpenFile(const char *fileName, int fileFlags)
Definition: fd.c:1033
int FreeFile(FILE *file)
Definition: fd.c:2572
int errmsg(const char *fmt,...)
Definition: elog.c:909
bool ParseConfigFp(FILE *fp, const char *config_file, int depth, int elevel, ConfigVariable **head_p, ConfigVariable **tail_p)
#define elog(elevel,...)
Definition: elog.h:232
static void replace_auto_config_value(ConfigVariable **head_p, ConfigVariable **tail_p, const char *name, const char *value)
Definition: guc.c:8435
void FreeConfigVariables(ConfigVariable *list)
#define close(a)
Definition: win32.h:12
#define PG_TRY()
Definition: elog.h:313
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
Definition: guc.c:8839
#define snprintf
Definition: port.h:216
#define PG_END_TRY()
Definition: elog.h:338
#define stat
Definition: win32_port.h:275
GucContext context
Definition: guc_tables.h:150

◆ assign_application_name()

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

Definition at line 12164 of file guc.c.

References pgstat_report_appname().

12165 {
12166  /* Update the pg_stat_activity view */
12168 }
void pgstat_report_appname(const char *appname)
#define newval

◆ assign_backtrace_functions()

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

Definition at line 12283 of file guc.c.

12284 {
12285  backtrace_symbol_list = (char *) extra;
12286 }
char * backtrace_symbol_list
Definition: guc.c:576

◆ assign_log_destination()

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

Definition at line 11739 of file guc.c.

References Log_destination.

11740 {
11741  Log_destination = *((int *) extra);
11742 }
int Log_destination
Definition: elog.c:111

◆ assign_maintenance_io_concurrency()

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

Definition at line 12112 of file guc.c.

References AmStartupProcess, maintenance_io_concurrency, newval, and XLogPrefetchReconfigure().

12113 {
12114 #ifdef USE_PREFETCH
12115  /*
12116  * Reconfigure recovery prefetching, because a setting it depends on
12117  * changed.
12118  */
12120  if (AmStartupProcess())
12122 #endif
12123 }
#define AmStartupProcess()
Definition: miscadmin.h:433
int maintenance_io_concurrency
Definition: bufmgr.c:150
#define newval
void XLogPrefetchReconfigure(void)
Definition: xlogprefetch.c:222

◆ assign_pgstat_temp_directory()

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

Definition at line 12126 of file guc.c.

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

12127 {
12128  /* check_canonical_path already canonicalized newval for us */
12129  char *dname;
12130  char *tname;
12131  char *fname;
12132 
12133  /* directory */
12134  dname = guc_malloc(ERROR, strlen(newval) + 1); /* runtime dir */
12135  sprintf(dname, "%s", newval);
12136 
12137  /* global stats */
12138  tname = guc_malloc(ERROR, strlen(newval) + 12); /* /global.tmp */
12139  sprintf(tname, "%s/global.tmp", newval);
12140  fname = guc_malloc(ERROR, strlen(newval) + 13); /* /global.stat */
12141  sprintf(fname, "%s/global.stat", newval);
12142 
12145  pgstat_stat_directory = dname;
12146  if (pgstat_stat_tmpname)
12148  pgstat_stat_tmpname = tname;
12151  pgstat_stat_filename = fname;
12152 }
#define sprintf
Definition: port.h:218
char * pgstat_stat_filename
Definition: pgstat.c:123
#define ERROR
Definition: elog.h:46
char * pgstat_stat_directory
Definition: pgstat.c:122
#define free(a)
Definition: header.h:65
#define newval
char * pgstat_stat_tmpname
Definition: pgstat.c:124
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:5059

◆ assign_recovery_target()

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

Definition at line 12362 of file guc.c.

References RECOVERY_TARGET_IMMEDIATE, RECOVERY_TARGET_UNSET, and recoveryTarget.

12363 {
12366  error_multiple_recovery_targets();
12367 
12368  if (newval && strcmp(newval, "") != 0)
12370  else
12372 }
#define newval
RecoveryTargetType recoveryTarget
Definition: xlog.c:287

◆ assign_recovery_target_lsn()

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

Definition at line 12530 of file guc.c.

References RECOVERY_TARGET_LSN, RECOVERY_TARGET_UNSET, recoveryTarget, and recoveryTargetLSN.

12531 {
12534  error_multiple_recovery_targets();
12535 
12536  if (newval && strcmp(newval, "") != 0)
12537  {
12539  recoveryTargetLSN = *((XLogRecPtr *) extra);
12540  }
12541  else
12543 }
XLogRecPtr recoveryTargetLSN
Definition: xlog.c:294
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define newval
RecoveryTargetType recoveryTarget
Definition: xlog.c:287

◆ assign_recovery_target_name()

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

Definition at line 12494 of file guc.c.

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

12495 {
12498  error_multiple_recovery_targets();
12499 
12500  if (newval && strcmp(newval, "") != 0)
12501  {
12504  }
12505  else
12507 }
const char * recoveryTargetName
Definition: xlog.c:293
#define newval
RecoveryTargetType recoveryTarget
Definition: xlog.c:287

◆ assign_recovery_target_time()

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

Definition at line 12468 of file guc.c.

References RECOVERY_TARGET_TIME, RECOVERY_TARGET_UNSET, and recoveryTarget.

12469 {
12472  error_multiple_recovery_targets();
12473 
12474  if (newval && strcmp(newval, "") != 0)
12476  else
12478 }
#define newval
RecoveryTargetType recoveryTarget
Definition: xlog.c:287

◆ assign_recovery_target_timeline()

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

Definition at line 12319 of file guc.c.

References RECOVERY_TARGET_TIMELINE_NUMERIC, recoveryTargetTimeLineGoal, and recoveryTargetTLIRequested.

12320 {
12323  recoveryTargetTLIRequested = (TimeLineID) strtoul(newval, NULL, 0);
12324  else
12326 }
TimeLineID recoveryTargetTLIRequested
Definition: xlog.c:344
uint32 TimeLineID
Definition: xlogdefs.h:59
RecoveryTargetTimeLineGoal
Definition: xlog.h:93
RecoveryTargetTimeLineGoal recoveryTargetTimeLineGoal
Definition: xlog.c:343
#define newval

◆ assign_recovery_target_xid()

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

Definition at line 12395 of file guc.c.

References RECOVERY_TARGET_UNSET, RECOVERY_TARGET_XID, recoveryTarget, and recoveryTargetXid.

12396 {
12399  error_multiple_recovery_targets();
12400 
12401  if (newval && strcmp(newval, "") != 0)
12402  {
12404  recoveryTargetXid = *((TransactionId *) extra);
12405  }
12406  else
12408 }
uint32 TransactionId
Definition: c.h:587
TransactionId recoveryTargetXid
Definition: xlog.c:290
#define newval
RecoveryTargetType recoveryTarget
Definition: xlog.c:287

◆ assign_session_replication_role()

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

Definition at line 11765 of file guc.c.

References ResetPlanCache(), and SessionReplicationRole.

11766 {
11767  /*
11768  * Must flush the plan cache when changing replication role; but don't
11769  * flush unnecessarily.
11770  */
11772  ResetPlanCache();
11773 }
int SessionReplicationRole
Definition: trigger.c:68
void ResetPlanCache(void)
Definition: plancache.c:2149
#define newval

◆ assign_syslog_facility()

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

Definition at line 11745 of file guc.c.

11746 {
11747 #ifdef HAVE_SYSLOG
11748  set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
11749  newval);
11750 #endif
11751  /* Without syslog support, just ignore it */
11752 }
static char * syslog_ident_str
Definition: guc.c:617
#define newval

◆ assign_syslog_ident()

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

Definition at line 11755 of file guc.c.

11756 {
11757 #ifdef HAVE_SYSLOG
11758  set_syslog_parameters(newval, syslog_facility);
11759 #endif
11760  /* Without syslog support, it will always be set to "none", so ignore */
11761 }
static int syslog_facility
Definition: guc.c:180
#define newval

◆ assign_tcp_keepalives_count()

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

Definition at line 11965 of file guc.c.

References MyProcPort, and pq_setkeepalivescount().

11966 {
11967  /* See comments in assign_tcp_keepalives_idle */
11969 }
struct Port * MyProcPort
Definition: globals.c:46
int pq_setkeepalivescount(int count, Port *port)
Definition: pqcomm.c:1809
#define newval

◆ assign_tcp_keepalives_idle()

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

Definition at line 11921 of file guc.c.

References MyProcPort, and pq_setkeepalivesidle().

11922 {
11923  /*
11924  * The kernel API provides no way to test a value without setting it; and
11925  * once we set it we might fail to unset it. So there seems little point
11926  * in fully implementing the check-then-assign GUC API for these
11927  * variables. Instead we just do the assignment on demand. pqcomm.c
11928  * reports any problems via ereport(LOG).
11929  *
11930  * This approach means that the GUC value might have little to do with the
11931  * actual kernel value, so we use a show_hook that retrieves the kernel
11932  * value rather than trusting GUC's copy.
11933  */
11935 }
struct Port * MyProcPort
Definition: globals.c:46
int pq_setkeepalivesidle(int idle, Port *port)
Definition: pqcomm.c:1645
#define newval

◆ assign_tcp_keepalives_interval()

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

Definition at line 11948 of file guc.c.

References MyProcPort, and pq_setkeepalivesinterval().

11949 {
11950  /* See comments in assign_tcp_keepalives_idle */
11952 }
struct Port * MyProcPort
Definition: globals.c:46
int pq_setkeepalivesinterval(int interval, Port *port)
Definition: pqcomm.c:1730
#define newval

◆ assign_tcp_user_timeout()

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

Definition at line 11982 of file guc.c.

References MyProcPort, and pq_settcpusertimeout().

11983 {
11984  /* See comments in assign_tcp_keepalives_idle */
11986 }
struct Port * MyProcPort
Definition: globals.c:46
#define newval
int pq_settcpusertimeout(int timeout, Port *port)
Definition: pqcomm.c:1884

◆ assign_timezone_abbreviations()

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

Definition at line 11885 of file guc.c.

References InstallTimeZoneAbbrevs().

11886 {
11887  /* Do nothing for the boot_val default of NULL */
11888  if (!extra)
11889  return;
11890 
11892 }
void InstallTimeZoneAbbrevs(TimeZoneAbbrevTable *tbl)
Definition: datetime.c:4614

◆ assign_wal_consistency_checking()

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

Definition at line 11676 of file guc.c.

References wal_consistency_checking.

11677 {
11678  wal_consistency_checking = (bool *) extra;
11679 }
bool * wal_consistency_checking
Definition: xlog.c:104

◆ AtEOXact_GUC()

void AtEOXact_GUC ( bool  isCommit,
int  nestLevel 
)

Definition at line 6235 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_NEEDS_REPORT, 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, 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_generic::status, 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().

6236 {
6237  bool still_dirty;
6238  int i;
6239 
6240  /*
6241  * Note: it's possible to get here with GUCNestLevel == nestLevel-1 during
6242  * abort, if there is a failure during transaction start before
6243  * AtStart_GUC is called.
6244  */
6245  Assert(nestLevel > 0 &&
6246  (nestLevel <= GUCNestLevel ||
6247  (nestLevel == GUCNestLevel + 1 && !isCommit)));
6248 
6249  /* Quick exit if nothing's changed in this transaction */
6250  if (!guc_dirty)
6251  {
6252  GUCNestLevel = nestLevel - 1;
6253  return;
6254  }
6255 
6256  still_dirty = false;
6257  for (i = 0; i < num_guc_variables; i++)
6258  {
6259  struct config_generic *gconf = guc_variables[i];
6260  GucStack *stack;
6261 
6262  /*
6263  * Process and pop each stack entry within the nest level. To simplify
6264  * fmgr_security_definer() and other places that use GUC_ACTION_SAVE,
6265  * we allow failure exit from code that uses a local nest level to be
6266  * recovered at the surrounding transaction or subtransaction abort;
6267  * so there could be more than one stack entry to pop.
6268  */
6269  while ((stack = gconf->stack) != NULL &&
6270  stack->nest_level >= nestLevel)
6271  {
6272  GucStack *prev = stack->prev;
6273  bool restorePrior = false;
6274  bool restoreMasked = false;
6275  bool changed;
6276 
6277  /*
6278  * In this next bit, if we don't set either restorePrior or
6279  * restoreMasked, we must "discard" any unwanted fields of the
6280  * stack entries to avoid leaking memory. If we do set one of
6281  * those flags, unused fields will be cleaned up after restoring.
6282  */
6283  if (!isCommit) /* if abort, always restore prior value */
6284  restorePrior = true;
6285  else if (stack->state == GUC_SAVE)
6286  restorePrior = true;
6287  else if (stack->nest_level == 1)
6288  {
6289  /* transaction commit */
6290  if (stack->state == GUC_SET_LOCAL)
6291  restoreMasked = true;
6292  else if (stack->state == GUC_SET)
6293  {
6294  /* we keep the current active value */
6295  discard_stack_value(gconf, &stack->prior);
6296  }
6297  else /* must be GUC_LOCAL */
6298  restorePrior = true;
6299  }
6300  else if (prev == NULL ||
6301  prev->nest_level < stack->nest_level - 1)
6302  {
6303  /* decrement entry's level and do not pop it */
6304  stack->nest_level--;
6305  continue;
6306  }
6307  else
6308  {
6309  /*
6310  * We have to merge this stack entry into prev. See README for
6311  * discussion of this bit.
6312  */
6313  switch (stack->state)
6314  {
6315  case GUC_SAVE:
6316  Assert(false); /* can't get here */
6317  break;
6318 
6319  case GUC_SET:
6320  /* next level always becomes SET */
6321  discard_stack_value(gconf, &stack->prior);
6322  if (prev->state == GUC_SET_LOCAL)
6323  discard_stack_value(gconf, &prev->masked);
6324  prev->state = GUC_SET;
6325  break;
6326 
6327  case GUC_LOCAL:
6328  if (prev->state == GUC_SET)
6329  {
6330  /* LOCAL migrates down */
6331  prev->masked_scontext = stack->scontext;
6332  prev->masked = stack->prior;
6333  prev->state = GUC_SET_LOCAL;
6334  }
6335  else
6336  {
6337  /* else just forget this stack level */
6338  discard_stack_value(gconf, &stack->prior);
6339  }
6340  break;
6341 
6342  case GUC_SET_LOCAL:
6343  /* prior state at this level no longer wanted */
6344  discard_stack_value(gconf, &stack->prior);
6345  /* copy down the masked state */
6346  prev->masked_scontext = stack->masked_scontext;
6347  if (prev->state == GUC_SET_LOCAL)
6348  discard_stack_value(gconf, &prev->masked);
6349  prev->masked = stack->masked;
6350  prev->state = GUC_SET_LOCAL;
6351  break;
6352  }
6353  }
6354 
6355  changed = false;
6356 
6357  if (restorePrior || restoreMasked)
6358  {
6359  /* Perform appropriate restoration of the stacked value */
6360  config_var_value newvalue;
6361  GucSource newsource;
6362  GucContext newscontext;
6363 
6364  if (restoreMasked)
6365  {
6366  newvalue = stack->masked;
6367  newsource = PGC_S_SESSION;
6368  newscontext = stack->masked_scontext;
6369  }
6370  else
6371  {
6372  newvalue = stack->prior;
6373  newsource = stack->source;
6374  newscontext = stack->scontext;
6375  }
6376 
6377  switch (gconf->vartype)
6378  {
6379  case PGC_BOOL:
6380  {
6381  struct config_bool *conf = (struct config_bool *) gconf;
6382  bool newval = newvalue.val.boolval;
6383  void *newextra = newvalue.extra;
6384 
6385  if (*conf->variable != newval ||
6386  conf->gen.extra != newextra)
6387  {
6388  if (conf->assign_hook)
6389  conf->assign_hook(newval, newextra);
6390  *conf->variable = newval;
6391  set_extra_field(&conf->gen, &conf->gen.extra,
6392  newextra);
6393  changed = true;
6394  }
6395  break;
6396  }
6397  case PGC_INT:
6398  {
6399  struct config_int *conf = (struct config_int *) gconf;
6400  int newval = newvalue.val.intval;
6401  void *newextra = newvalue.extra;
6402 
6403  if (*conf->variable != newval ||
6404  conf->gen.extra != newextra)
6405  {
6406  if (conf->assign_hook)
6407  conf->assign_hook(newval, newextra);
6408  *conf->variable = newval;
6409  set_extra_field(&conf->gen, &conf->gen.extra,
6410  newextra);
6411  changed = true;
6412  }
6413  break;
6414  }
6415  case PGC_REAL:
6416  {
6417  struct config_real *conf = (struct config_real *) gconf;
6418  double newval = newvalue.val.realval;
6419  void *newextra = newvalue.extra;
6420 
6421  if (*conf->variable != newval ||
6422  conf->gen.extra != newextra)
6423  {
6424  if (conf->assign_hook)
6425  conf->assign_hook(newval, newextra);
6426  *conf->variable = newval;
6427  set_extra_field(&conf->gen, &conf->gen.extra,
6428  newextra);
6429  changed = true;
6430  }
6431  break;
6432  }
6433  case PGC_STRING:
6434  {
6435  struct config_string *conf = (struct config_string *) gconf;
6436  char *newval = newvalue.val.stringval;
6437  void *newextra = newvalue.extra;
6438 
6439  if (*conf->variable != newval ||
6440  conf->gen.extra != newextra)
6441  {
6442  if (conf->assign_hook)
6443  conf->assign_hook(newval, newextra);
6444  set_string_field(conf, conf->variable, newval);
6445  set_extra_field(&conf->gen, &conf->gen.extra,
6446  newextra);
6447  changed = true;
6448  }
6449 
6450  /*
6451  * Release stacked values if not used anymore. We
6452  * could use discard_stack_value() here, but since
6453  * we have type-specific code anyway, might as
6454  * well inline it.
6455  */
6456  set_string_field(conf, &stack->prior.val.stringval, NULL);
6457  set_string_field(conf, &stack->masked.val.stringval, NULL);
6458  break;
6459  }
6460  case PGC_ENUM:
6461  {
6462  struct config_enum *conf = (struct config_enum *) gconf;
6463  int newval = newvalue.val.enumval;
6464  void *newextra = newvalue.extra;
6465 
6466  if (*conf->variable != newval ||
6467  conf->gen.extra != newextra)
6468  {
6469  if (conf->assign_hook)
6470  conf->assign_hook(newval, newextra);
6471  *conf->variable = newval;
6472  set_extra_field(&conf->gen, &conf->gen.extra,
6473  newextra);
6474  changed = true;
6475  }
6476  break;
6477  }
6478  }
6479 
6480  /*
6481  * Release stacked extra values if not used anymore.
6482  */
6483  set_extra_field(gconf, &(stack->prior.extra), NULL);
6484  set_extra_field(gconf, &(stack->masked.extra), NULL);
6485 
6486  /* And restore source information */
6487  gconf->source = newsource;
6488  gconf->scontext = newscontext;
6489  }
6490 
6491  /* Finish popping the state stack */
6492  gconf->stack = prev;
6493  pfree(stack);
6494 
6495  /* Report new value if we changed it */
6496  if (changed && (gconf->flags & GUC_REPORT))
6497  {
6498  gconf->status |= GUC_NEEDS_REPORT;
6499  report_needed = true;
6500  }
6501  } /* end of stack-popping loop */
6502 
6503  if (stack != NULL)
6504  still_dirty = true;
6505  }
6506 
6507  /* If there are no remaining stack entries, we can reset guc_dirty */
6508  guc_dirty = still_dirty;
6509 
6510  /* Update nesting level */
6511  GUCNestLevel = nestLevel - 1;
6512 }
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
static bool report_needed
Definition: guc.c:5029
int nest_level
Definition: guc_tables.h:124
GucRealAssignHook assign_hook
Definition: guc_tables.h:222
char ** variable
Definition: guc_tables.h:233
static int GUCNestLevel
Definition: guc.c:5031
bool * variable
Definition: guc_tables.h:187
GucEnumAssignHook assign_hook
Definition: guc_tables.h:251
GucBoolAssignHook assign_hook
Definition: guc_tables.h:190
config_var_value masked
Definition: guc_tables.h:131
GucContext scontext
Definition: guc_tables.h:160
GucIntAssignHook assign_hook
Definition: guc_tables.h:206
GucSource
Definition: guc.h:104
int * variable
Definition: guc_tables.h:201
int * variable
Definition: guc_tables.h:247
void pfree(void *pointer)
Definition: mcxt.c:1169
static int num_guc_variables
Definition: guc.c:5019
static void discard_stack_value(struct config_generic *gconf, config_var_value *val)
Definition: guc.c:5246
GucSource source
Definition: guc_tables.h:126
static void set_extra_field(struct config_generic *gconf, void **field, void *newval)
Definition: guc.c:5192
struct config_generic gen
Definition: guc_tables.h:185
struct config_generic gen
Definition: guc_tables.h:199
GucContext masked_scontext
Definition: guc_tables.h:129
#define GUC_REPORT
Definition: guc.h:208
double * variable
Definition: guc_tables.h:217
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:5131
static struct config_generic ** guc_variables
Definition: guc.c:5016
enum config_type vartype
Definition: guc_tables.h:156
GucContext scontext
Definition: guc_tables.h:128
struct config_generic gen
Definition: guc_tables.h:245
struct config_generic gen
Definition: guc_tables.h:231
GucStackState state
Definition: guc_tables.h:125
GucStringAssignHook assign_hook
Definition: guc_tables.h:236
#define Assert(condition)
Definition: c.h:804
#define newval
char * stringval
Definition: guc_tables.h:36
int i
GucStack * stack
Definition: guc_tables.h:162
double realval
Definition: guc_tables.h:35
static bool guc_dirty
Definition: guc.c:5025
config_var_value prior
Definition: guc_tables.h:130
#define GUC_NEEDS_REPORT
Definition: guc_tables.h:178
struct config_generic gen
Definition: guc_tables.h:215

◆ AtStart_GUC()

void AtStart_GUC ( void  )

Definition at line 6201 of file guc.c.

References elog, and WARNING.

Referenced by StartTransaction().

6202 {
6203  /*
6204  * The nest level should be 0 between transactions; if it isn't, somebody
6205  * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
6206  * throw a warning but make no other effort to clean up.
6207  */
6208  if (GUCNestLevel != 0)
6209  elog(WARNING, "GUC nest level = %d at transaction start",
6210  GUCNestLevel);
6211  GUCNestLevel = 1;
6212 }
static int GUCNestLevel
Definition: guc.c:5031
#define WARNING
Definition: elog.h:40
#define elog(elevel,...)
Definition: elog.h:232

◆ BeginReportingGUCOptions()

void BeginReportingGUCOptions ( void  )

Definition at line 6520 of file guc.c.

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

Referenced by PostgresMain().

6521 {
6522  int i;
6523 
6524  /*
6525  * Don't do anything unless talking to an interactive frontend.
6526  */
6528  return;
6529 
6530  reporting_enabled = true;
6531 
6532  /*
6533  * Hack for in_hot_standby: initialize with the value we're about to send.
6534  * (This could be out of date by the time we actually send it, in which
6535  * case the next ReportChangedGUCOptions call will send a duplicate
6536  * report.)
6537  */
6539 
6540  /* Transmit initial values of interesting variables */
6541  for (i = 0; i < num_guc_variables; i++)
6542  {
6543  struct config_generic *conf = guc_variables[i];
6544 
6545  if (conf->flags & GUC_REPORT)
6546  ReportGUCOption(conf);
6547  }
6548 
6549  report_needed = false;
6550 }
static bool report_needed
Definition: guc.c:5029
static bool in_hot_standby
Definition: guc.c:640
bool RecoveryInProgress(void)
Definition: xlog.c:8237
static int num_guc_variables
Definition: guc.c:5019
#define GUC_REPORT
Definition: guc.h:208
static struct config_generic ** guc_variables
Definition: guc.c:5016
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:6612
CommandDest whereToSendOutput
Definition: postgres.c:92
static bool reporting_enabled
Definition: guc.c:5027

◆ build_guc_variables()

void build_guc_variables ( void  )

Definition at line 5282 of file guc.c.

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

Referenced by GucInfoMain(), and InitializeGUCOptions().

5283 {
5284  int size_vars;
5285  int num_vars = 0;
5286  struct config_generic **guc_vars;
5287  int i;
5288 
5289  for (i = 0; ConfigureNamesBool[i].gen.name; i++)
5290  {
5291  struct config_bool *conf = &ConfigureNamesBool[i];
5292 
5293  /* Rather than requiring vartype to be filled in by hand, do this: */
5294  conf->gen.vartype = PGC_BOOL;
5295  num_vars++;
5296  }
5297 
5298  for (i = 0; ConfigureNamesInt[i].gen.name; i++)
5299  {
5300  struct config_int *conf = &ConfigureNamesInt[i];
5301 
5302  conf->gen.vartype = PGC_INT;
5303  num_vars++;
5304  }
5305 
5306  for (i = 0; ConfigureNamesReal[i].gen.name; i++)
5307  {
5308  struct config_real *conf = &ConfigureNamesReal[i];
5309 
5310  conf->gen.vartype = PGC_REAL;
5311  num_vars++;
5312  }
5313 
5314  for (i = 0; ConfigureNamesString[i].gen.name; i++)
5315  {
5316  struct config_string *conf = &ConfigureNamesString[i];
5317 
5318  conf->gen.vartype = PGC_STRING;
5319  num_vars++;
5320  }
5321 
5322  for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
5323  {
5324  struct config_enum *conf = &ConfigureNamesEnum[i];
5325 
5326  conf->gen.vartype = PGC_ENUM;
5327  num_vars++;
5328  }
5329 
5330  /*
5331  * Create table with 20% slack
5332  */
5333  size_vars = num_vars + num_vars / 4;
5334 
5335  guc_vars = (struct config_generic **)
5336  guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
5337 
5338  num_vars = 0;
5339 
5340  for (i = 0; ConfigureNamesBool[i].gen.name; i++)
5341  guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
5342 
5343  for (i = 0; ConfigureNamesInt[i].gen.name; i++)
5344  guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
5345 
5346  for (i = 0; ConfigureNamesReal[i].gen.name; i++)
5347  guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
5348 
5349  for (i = 0; ConfigureNamesString[i].gen.name; i++)
5350  guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
5351 
5352  for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
5353  guc_vars[num_vars++] = &ConfigureNamesEnum[i].gen;
5354 
5355  if (guc_variables)
5357  guc_variables = guc_vars;
5358  num_guc_variables = num_vars;
5359  size_guc_variables = size_vars;
5361  sizeof(struct config_generic *), guc_var_compare);
5362 }
static struct config_int ConfigureNamesInt[]
Definition: guc.c:2152
const char * name
Definition: guc_tables.h:149
static struct config_enum ConfigureNamesEnum[]
Definition: guc.c:4642
static struct config_bool ConfigureNamesBool[]
Definition: guc.c:956
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:5573
static int num_guc_variables
Definition: guc.c:5019
#define FATAL
Definition: elog.h:49
struct config_generic gen
Definition: guc_tables.h:185
struct config_generic gen
Definition: guc_tables.h:199
static struct config_generic ** guc_variables
Definition: guc.c:5016
enum config_type vartype
Definition: guc_tables.h:156
static int size_guc_variables
Definition: guc.c:5022
static struct config_real ConfigureNamesReal[]
Definition: guc.c:3593
struct config_generic gen
Definition: guc_tables.h:245
struct config_generic gen
Definition: guc_tables.h:231
#define free(a)
Definition: header.h:65
static struct config_string ConfigureNamesString[]
Definition: guc.c:3863
int i
#define qsort(a, b, c, d)
Definition: port.h:504
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:5059
struct config_generic gen
Definition: guc_tables.h:215

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

11412 {
11413  /* Quick success if no hook */
11414  if (!conf->check_hook)
11415  return true;
11416 
11417  /* Reset variables that might be set by hook */
11418  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
11419  GUC_check_errmsg_string = NULL;
11421  GUC_check_errhint_string = NULL;
11422 
11423  if (!conf->check_hook(newval, extra, source))
11424  {
11425  ereport(elevel,
11429  errmsg("invalid value for parameter \"%s\": %d",
11430  conf->gen.name, (int) *newval),
11434  errhint("%s", GUC_check_errhint_string) : 0));
11435  /* Flush any strings created in ErrorContext */
11436  FlushErrorState();
11437  return false;
11438  }
11439 
11440  return true;
11441 }
char * GUC_check_errhint_string
Definition: guc.c:153
int errhint(const char *fmt,...)
Definition: elog.c:1156
const char * name
Definition: guc_tables.h:149
int errcode(int sqlerrcode)
Definition: elog.c:698
static int GUC_check_errcode_value
Definition: guc.c:148
void FlushErrorState(void)
Definition: elog.c:1654
int errdetail_internal(const char *fmt,...)
Definition: elog.c:1069
struct config_generic gen
Definition: guc_tables.h:185
char * GUC_check_errdetail_string
Definition: guc.c:152
static int elevel
Definition: vacuumlazy.c:400
GucBoolCheckHook check_hook
Definition: guc_tables.h:189
#define ereport(elevel,...)
Definition: elog.h:157
int errmsg_internal(const char *fmt,...)
Definition: elog.c:996
static rewind_source * source
Definition: pg_rewind.c:79
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:151
int errmsg(const char *fmt,...)
Definition: elog.c:909

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

11564 {
11565  /* Quick success if no hook */
11566  if (!conf->check_hook)
11567  return true;
11568 
11569  /* Reset variables that might be set by hook */
11570  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
11571  GUC_check_errmsg_string = NULL;
11573  GUC_check_errhint_string = NULL;
11574 
11575  if (!conf->check_hook(newval, extra, source))
11576  {
11577  ereport(elevel,
11581  errmsg("invalid value for parameter \"%s\": \"%s\"",
11582  conf->gen.name,
11587  errhint("%s", GUC_check_errhint_string) : 0));
11588  /* Flush any strings created in ErrorContext */
11589  FlushErrorState();
11590  return false;
11591  }
11592 
11593  return true;
11594 }
char * GUC_check_errhint_string
Definition: guc.c:153
GucEnumCheckHook check_hook
Definition: guc_tables.h:250
int errhint(const char *fmt,...)
Definition: elog.c:1156
const char * name
Definition: guc_tables.h:149
int errcode(int sqlerrcode)
Definition: elog.c:698
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:7004
static int GUC_check_errcode_value
Definition: guc.c:148
void FlushErrorState(void)
Definition: elog.c:1654
int errdetail_internal(const char *fmt,...)
Definition: elog.c:1069
char * GUC_check_errdetail_string
Definition: guc.c:152
static int elevel
Definition: vacuumlazy.c:400
struct config_generic gen
Definition: guc_tables.h:245
#define ereport(elevel,...)
Definition: elog.h:157
int errmsg_internal(const char *fmt,...)
Definition: elog.c:996
static rewind_source * source
Definition: pg_rewind.c:79
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:151
int errmsg(const char *fmt,...)
Definition: elog.c:909

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

11446 {
11447  /* Quick success if no hook */
11448  if (!conf->check_hook)
11449  return true;
11450 
11451  /* Reset variables that might be set by hook */
11452  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
11453  GUC_check_errmsg_string = NULL;
11455  GUC_check_errhint_string = NULL;
11456 
11457  if (!conf->check_hook(newval, extra, source))
11458  {
11459  ereport(elevel,
11463  errmsg("invalid value for parameter \"%s\": %d",
11464  conf->gen.name, *newval),
11468  errhint("%s", GUC_check_errhint_string) : 0));
11469  /* Flush any strings created in ErrorContext */
11470  FlushErrorState();
11471  return false;
11472  }
11473 
11474  return true;
11475 }
char * GUC_check_errhint_string
Definition: guc.c:153
int errhint(const char *fmt,...)
Definition: elog.c:1156
const char * name
Definition: guc_tables.h:149
int errcode(int sqlerrcode)
Definition: elog.c:698
static int GUC_check_errcode_value
Definition: guc.c:148
GucIntCheckHook check_hook
Definition: guc_tables.h:205
void FlushErrorState(void)
Definition: elog.c:1654
int errdetail_internal(const char *fmt,...)
Definition: elog.c:1069
struct config_generic gen
Definition: guc_tables.h:199
char * GUC_check_errdetail_string
Definition: guc.c:152
static int elevel
Definition: vacuumlazy.c:400
#define ereport(elevel,...)
Definition: elog.h:157
int errmsg_internal(const char *fmt,...)
Definition: elog.c:996
static rewind_source * source
Definition: pg_rewind.c:79
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:151
int errmsg(const char *fmt,...)
Definition: elog.c:909

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

11480 {
11481  /* Quick success if no hook */
11482  if (!conf->check_hook)
11483  return true;
11484 
11485  /* Reset variables that might be set by hook */
11486  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
11487  GUC_check_errmsg_string = NULL;
11489  GUC_check_errhint_string = NULL;
11490 
11491  if (!conf->check_hook(newval, extra, source))
11492  {
11493  ereport(elevel,
11497  errmsg("invalid value for parameter \"%s\": %g",
11498  conf->gen.name, *newval),
11502  errhint("%s", GUC_check_errhint_string) : 0));
11503  /* Flush any strings created in ErrorContext */
11504  FlushErrorState();
11505  return false;
11506  }
11507 
11508  return true;
11509 }
char * GUC_check_errhint_string
Definition: guc.c:153
int errhint(const char *fmt,...)
Definition: elog.c:1156
const char * name
Definition: guc_tables.h:149
int errcode(int sqlerrcode)
Definition: elog.c:698
static int GUC_check_errcode_value
Definition: guc.c:148
GucRealCheckHook check_hook
Definition: guc_tables.h:221
void FlushErrorState(void)
Definition: elog.c:1654
int errdetail_internal(const char *fmt,...)
Definition: elog.c:1069
char * GUC_check_errdetail_string
Definition: guc.c:152
static int elevel
Definition: vacuumlazy.c:400
#define ereport(elevel,...)
Definition: elog.h:157
int errmsg_internal(const char *fmt,...)
Definition: elog.c:996
static rewind_source * source
Definition: pg_rewind.c:79
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:151
int errmsg(const char *fmt,...)
Definition: elog.c:909
struct config_generic gen
Definition: guc_tables.h:215

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

References config_string::check_hook, ereport, errcode(), errdetail_internal(), errhint(), errmsg(), errmsg_internal(), FlushErrorState(), free, config_string::gen, GUC_check_errcode_value, GUC_check_errdetail_string, GUC_check_errhint_string, GUC_check_errmsg_string, config_generic::name, PG_CATCH, PG_END_TRY, PG_RE_THROW, and PG_TRY.

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

11514 {
11515  volatile bool result = true;
11516 
11517  /* Quick success if no hook */
11518  if (!conf->check_hook)
11519  return true;
11520 
11521  /*
11522  * If elevel is ERROR, or if the check_hook itself throws an elog
11523  * (undesirable, but not always avoidable), make sure we don't leak the
11524  * already-malloc'd newval string.
11525  */
11526  PG_TRY();
11527  {
11528  /* Reset variables that might be set by hook */
11529  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
11530  GUC_check_errmsg_string = NULL;
11532  GUC_check_errhint_string = NULL;
11533 
11534  if (!conf->check_hook(newval, extra, source))
11535  {
11536  ereport(elevel,
11540  errmsg("invalid value for parameter \"%s\": \"%s\"",
11541  conf->gen.name, *newval ? *newval : ""),
11545  errhint("%s", GUC_check_errhint_string) : 0));
11546  /* Flush any strings created in ErrorContext */
11547  FlushErrorState();
11548  result = false;
11549  }
11550  }
11551  PG_CATCH();
11552  {
11553  free(*newval);
11554  PG_RE_THROW();
11555  }
11556  PG_END_TRY();
11557 
11558  return result;
11559 }
char * GUC_check_errhint_string
Definition: guc.c:153
int errhint(const char *fmt,...)
Definition: elog.c:1156
const char * name
Definition: guc_tables.h:149
GucStringCheckHook check_hook
Definition: guc_tables.h:235
int errcode(int sqlerrcode)
Definition: elog.c:698
static int GUC_check_errcode_value
Definition: guc.c:148
void FlushErrorState(void)
Definition: elog.c:1654
int errdetail_internal(const char *fmt,...)
Definition: elog.c:1069
char * GUC_check_errdetail_string
Definition: guc.c:152
static int elevel
Definition: vacuumlazy.c:400
#define ereport(elevel,...)
Definition: elog.h:157
struct config_generic gen
Definition: guc_tables.h:231
#define free(a)
Definition: header.h:65
int errmsg_internal(const char *fmt,...)
Definition: elog.c:996
#define PG_CATCH()
Definition: elog.h:323
static rewind_source * source
Definition: pg_rewind.c:79
#define newval
#define PG_RE_THROW()
Definition: elog.h:354
char * GUC_check_errmsg_string
Definition: guc.c:151
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define PG_TRY()
Definition: elog.h:313
#define PG_END_TRY()
Definition: elog.h:338

◆ can_skip_gucvar()

static bool can_skip_gucvar ( struct config_generic gconf)
static

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

10464 {
10465  /*
10466  * We can skip GUCs that are guaranteed to have the same values in leaders
10467  * and workers. (Note it is critical that the leader and worker have the
10468  * same idea of which GUCs fall into this category. It's okay to consider
10469  * context and name for this purpose, since those are unchanging
10470  * properties of a GUC.)
10471  *
10472  * PGC_POSTMASTER variables always have the same value in every child of a
10473  * particular postmaster, so the worker will certainly have the right
10474  * value already. Likewise, PGC_INTERNAL variables are set by special
10475  * mechanisms (if indeed they aren't compile-time constants). So we may
10476  * always skip these.
10477  *
10478  * Role must be handled specially because its current value can be an
10479  * invalid value (for instance, if someone dropped the role since we set
10480  * it). So if we tried to serialize it normally, we might get a failure.
10481  * We skip it here, and use another mechanism to ensure the worker has the
10482  * right value.
10483  *
10484  * For all other GUCs, we skip if the GUC has its compiled-in default
10485  * value (i.e., source == PGC_S_DEFAULT). On the leader side, this means
10486  * we don't send GUCs that have their default values, which typically
10487  * saves lots of work. On the worker side, this means we don't need to
10488  * reset the GUC to default because it already has that value. See
10489  * comments in RestoreGUCState for more info.
10490  */
10491  return gconf->context == PGC_POSTMASTER ||
10492  gconf->context == PGC_INTERNAL || gconf->source == PGC_S_DEFAULT ||
10493  strcmp(gconf->name, "role") == 0;
10494 }
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 12155 of file guc.c.

References pg_clean_ascii().

12156 {
12157  /* Only allow clean ASCII chars in the application name */
12159 
12160  return true;
12161 }
#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 12008 of file guc.c.

References MAX_BACKENDS, max_wal_senders, max_worker_processes, and MaxConnections.

12009 {
12010  if (MaxConnections + *newval + 1 +
12012  return false;
12013  return true;
12014 }
#define MAX_BACKENDS
Definition: postmaster.h:76
int max_wal_senders
Definition: walsender.c:121
int MaxConnections
Definition: globals.c:136
#define newval
int max_worker_processes
Definition: globals.c:137

◆ check_autovacuum_work_mem()

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

Definition at line 12026 of file guc.c.

12027 {
12028  /*
12029  * -1 indicates fallback.
12030  *
12031  * If we haven't yet changed the boot_val default of -1, just let it be.
12032  * Autovacuum will look to maintenance_work_mem instead.
12033  */
12034  if (*newval == -1)
12035  return true;
12036 
12037  /*
12038  * We clamp manually-set values to at least 1MB. Since
12039  * maintenance_work_mem is always set to at least this value, do the same
12040  * here.
12041  */
12042  if (*newval < 1024)
12043  *newval = 1024;
12044 
12045  return true;
12046 }
#define newval

◆ check_backtrace_functions()

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

Definition at line 12227 of file guc.c.

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

12228 {
12229  int newvallen = strlen(*newval);
12230  char *someval;
12231  int validlen;
12232  int i;
12233  int j;
12234 
12235  /*
12236  * Allow characters that can be C identifiers and commas as separators, as
12237  * well as some whitespace for readability.
12238  */
12239  validlen = strspn(*newval,
12240  "0123456789_"
12241  "abcdefghijklmnopqrstuvwxyz"
12242  "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
12243  ", \n\t");
12244  if (validlen != newvallen)
12245  {
12246  GUC_check_errdetail("invalid character");
12247  return false;
12248  }
12249 
12250  if (*newval[0] == '\0')
12251  {
12252  *extra = NULL;
12253  return true;
12254  }
12255 
12256  /*
12257  * Allocate space for the output and create the copy. We could discount
12258  * whitespace chars to save some memory, but it doesn't seem worth the
12259  * trouble.
12260  */
12261  someval = guc_malloc(ERROR, newvallen + 1 + 1);
12262  for (i = 0, j = 0; i < newvallen; i++)
12263  {
12264  if ((*newval)[i] == ',')
12265  someval[j++] = '\0'; /* next item */
12266  else if ((*newval)[i] == ' ' ||
12267  (*newval)[i] == '\n' ||
12268  (*newval)[i] == '\t')
12269  ; /* ignore these */
12270  else
12271  someval[j++] = (*newval)[i]; /* copy anything else */
12272  }
12273 
12274  /* two \0s end the setting */
12275  someval[j] = '\0';
12276  someval[j + 1] = '\0';
12277 
12278  *extra = someval;
12279  return true;
12280 }
#define GUC_check_errdetail
Definition: guc.h:417
#define ERROR
Definition: elog.h:46
#define newval
int i
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:5059

◆ check_bonjour()

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

Definition at line 11791 of file guc.c.

References GUC_check_errmsg.

11792 {
11793 #ifndef USE_BONJOUR
11794  if (*newval)
11795  {
11796  GUC_check_errmsg("Bonjour is not supported by this build");
11797  return false;
11798  }
11799 #endif
11800  return true;
11801 }
#define GUC_check_errmsg
Definition: guc.h:413
#define newval

◆ check_canonical_path()

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

Definition at line 11842 of file guc.c.

References canonicalize_path().

11843 {
11844  /*
11845  * Since canonicalize_path never enlarges the string, we can just modify
11846  * newval in-place. But watch out for NULL, which is the default value
11847  * for external_pid_file.
11848  */
11849  if (*newval)
11851  return true;
11852 }
void canonicalize_path(char *path)
Definition: path.c:254
#define newval

◆ check_client_connection_check_interval()

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

Definition at line 12098 of file guc.c.

References GUC_check_errdetail.

12099 {
12100 #ifndef POLLRDHUP
12101  /* Linux only, for now. See pq_check_connection(). */
12102  if (*newval != 0)
12103  {
12104  GUC_check_errdetail("client_connection_check_interval must be set to 0 on platforms that lack POLLRDHUP.");
12105  return false;
12106  }
12107 #endif
12108  return true;
12109 }
#define GUC_check_errdetail
Definition: guc.h:417
#define newval

◆ check_cluster_name()

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

Definition at line 12171 of file guc.c.

References pg_clean_ascii().

12172 {
12173  /* Only allow clean ASCII chars in the cluster name */
12175 
12176  return true;
12177 }
#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 12556 of file guc.c.

References GUC_check_errcode(), and GUC_check_errmsg.

12557 {
12558  if (*newval)
12559  {
12560  /* check the GUC's definition for an explanation */
12561  GUC_check_errcode(ERRCODE_FEATURE_NOT_SUPPORTED);
12562  GUC_check_errmsg("tables declared WITH OIDS are not supported");
12563 
12564  return false;
12565  }
12566 
12567  return true;
12568 }
#define GUC_check_errmsg
Definition: guc.h:413
void GUC_check_errcode(int sqlerrcode)
Definition: guc.c:11397
#define newval

◆ check_effective_io_concurrency()

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

Definition at line 12058 of file guc.c.

References GUC_check_errdetail.

12059 {
12060 #ifndef USE_PREFETCH
12061  if (*newval != 0)
12062  {
12063  GUC_check_errdetail("effective_io_concurrency must be set to 0 on platforms that lack posix_fadvise().");
12064  return false;
12065  }
12066 #endif /* USE_PREFETCH */
12067  return true;
12068 }
#define GUC_check_errdetail
Definition: guc.h:417
#define newval

◆ check_huge_page_size()

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

Definition at line 12084 of file guc.c.

References GUC_check_errdetail.

12085 {
12086 #if !(defined(MAP_HUGE_MASK) && defined(MAP_HUGE_SHIFT))
12087  /* Recent enough Linux only, for now. See GetHugePageSize(). */
12088  if (*newval != 0)
12089  {
12090  GUC_check_errdetail("huge_page_size must be 0 on this platform.");
12091  return false;
12092  }
12093 #endif
12094  return true;
12095 }
#define GUC_check_errdetail
Definition: guc.h:417
#define newval

◆ check_log_destination()

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

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

11683 {
11684  char *rawstring;
11685  List *elemlist;
11686  ListCell *l;
11687  int newlogdest = 0;
11688  int *myextra;
11689 
11690  /* Need a modifiable copy of string */
11691  rawstring = pstrdup(*newval);
11692 
11693  /* Parse string into list of identifiers */
11694  if (!SplitIdentifierString(rawstring, ',', &elemlist))
11695  {
11696  /* syntax error in list */
11697  GUC_check_errdetail("List syntax is invalid.");
11698  pfree(rawstring);
11699  list_free(elemlist);
11700  return false;
11701  }
11702 
11703  foreach(l, elemlist)
11704  {
11705  char *tok = (char *) lfirst(l);
11706 
11707  if (pg_strcasecmp(tok, "stderr") == 0)
11708  newlogdest |= LOG_DESTINATION_STDERR;
11709  else if (pg_strcasecmp(tok, "csvlog") == 0)
11710  newlogdest |= LOG_DESTINATION_CSVLOG;
11711 #ifdef HAVE_SYSLOG
11712  else if (pg_strcasecmp(tok, "syslog") == 0)
11713  newlogdest |= LOG_DESTINATION_SYSLOG;
11714 #endif
11715 #ifdef WIN32
11716  else if (pg_strcasecmp(tok, "eventlog") == 0)
11717  newlogdest |= LOG_DESTINATION_EVENTLOG;
11718 #endif
11719  else
11720  {
11721  GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
11722  pfree(rawstring);
11723  list_free(elemlist);
11724  return false;
11725  }
11726  }
11727 
11728  pfree(rawstring);
11729  list_free(elemlist);
11730 
11731  myextra = (int *) guc_malloc(ERROR, sizeof(int));
11732  *myextra = newlogdest;
11733  *extra = (void *) myextra;
11734 
11735  return true;
11736 }
#define LOG_DESTINATION_EVENTLOG
Definition: elog.h:437
#define GUC_check_errdetail
Definition: guc.h:417
char * pstrdup(const char *in)
Definition: mcxt.c:1299
#define LOG_DESTINATION_SYSLOG
Definition: elog.h:436
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
void pfree(void *pointer)
Definition: mcxt.c:1169
#define ERROR
Definition: elog.h:46
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3753
#define LOG_DESTINATION_CSVLOG
Definition: elog.h:438
#define LOG_DESTINATION_STDERR
Definition: elog.h:435
#define lfirst(lc)
Definition: pg_list.h:169
#define newval
void list_free(List *list)
Definition: list.c:1391
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:5059
Definition: pg_list.h:50

◆ check_log_stats()

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

Definition at line 11828 of file guc.c.

References GUC_check_errdetail.

11829 {
11830  if (*newval &&
11832  {
11833  GUC_check_errdetail("Cannot enable \"log_statement_stats\" when "
11834  "\"log_parser_stats\", \"log_planner_stats\", "
11835  "or \"log_executor_stats\" is true.");
11836  return false;
11837  }
11838  return true;
11839 }
bool log_parser_stats
Definition: guc.c:546
#define GUC_check_errdetail
Definition: guc.h:417
#define newval
bool log_executor_stats
Definition: guc.c:548
bool log_planner_stats
Definition: guc.c:547

◆ check_maintenance_io_concurrency()

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

Definition at line 12071 of file guc.c.

References GUC_check_errdetail.

12072 {
12073 #ifndef USE_PREFETCH
12074  if (*newval != 0)
12075  {
12076  GUC_check_errdetail("maintenance_io_concurrency must be set to 0 on platforms that lack posix_fadvise().");
12077  return false;
12078  }
12079 #endif /* USE_PREFETCH */
12080  return true;
12081 }
#define GUC_check_errdetail
Definition: guc.h:417
#define newval

◆ check_max_wal_senders()

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

Definition at line 12017 of file guc.c.

References autovacuum_max_workers, MAX_BACKENDS, max_worker_processes, and MaxConnections.

12018 {
12021  return false;
12022  return true;
12023 }
#define MAX_BACKENDS
Definition: postmaster.h:76
int MaxConnections
Definition: globals.c:136
int autovacuum_max_workers
Definition: autovacuum.c:116
#define newval
int max_worker_processes
Definition: globals.c:137

◆ check_max_worker_processes()

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

Definition at line 12049 of file guc.c.

References autovacuum_max_workers, MAX_BACKENDS, max_wal_senders, and MaxConnections.

12050 {
12053  return false;
12054  return true;
12055 }
#define MAX_BACKENDS
Definition: postmaster.h:76
int max_wal_senders
Definition: walsender.c:121
int MaxConnections
Definition: globals.c:136
int autovacuum_max_workers
Definition: autovacuum.c:116
#define newval

◆ check_maxconnections()

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

Definition at line 11999 of file guc.c.

References autovacuum_max_workers, MAX_BACKENDS, max_wal_senders, and max_worker_processes.

12000 {
12001  if (*newval + autovacuum_max_workers + 1 +
12003  return false;
12004  return true;
12005 }
#define MAX_BACKENDS
Definition: postmaster.h:76
int max_wal_senders
Definition: walsender.c:121
int autovacuum_max_workers
Definition: autovacuum.c:116
#define newval
int max_worker_processes
Definition: globals.c:137

◆ check_primary_slot_name()

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

Definition at line 12546 of file guc.c.

References ReplicationSlotValidateName(), and WARNING.

12547 {
12548  if (*newval && strcmp(*newval, "") != 0 &&
12550  return false;
12551 
12552  return true;
12553 }
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 12351 of file guc.c.

References GUC_check_errdetail.

12352 {
12353  if (strcmp(*newval, "immediate") != 0 && strcmp(*newval, "") != 0)
12354  {
12355  GUC_check_errdetail("The only allowed value is \"immediate\".");
12356  return false;
12357  }
12358  return true;
12359 }
#define GUC_check_errdetail
Definition: guc.h:417
#define newval

◆ check_recovery_target_lsn()

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

Definition at line 12510 of file guc.c.

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

12511 {
12512  if (strcmp(*newval, "") != 0)
12513  {
12514  XLogRecPtr lsn;
12515  XLogRecPtr *myextra;
12516  bool have_error = false;
12517 
12518  lsn = pg_lsn_in_internal(*newval, &have_error);
12519  if (have_error)
12520  return false;
12521 
12522  myextra = (XLogRecPtr *) guc_malloc(ERROR, sizeof(XLogRecPtr));
12523  *myextra = lsn;
12524  *extra = (void *) myextra;
12525  }
12526  return true;
12527 }
#define ERROR
Definition: elog.h:46
XLogRecPtr pg_lsn_in_internal(const char *str, bool *have_error)
Definition: pg_lsn.c:30
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define newval
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:5059

◆ check_recovery_target_name()

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

Definition at line 12481 of file guc.c.

References GUC_check_errdetail, and MAXFNAMELEN.

12482 {
12483  /* Use the value of newval directly */
12484  if (strlen(*newval) >= MAXFNAMELEN)
12485  {
12486  GUC_check_errdetail("%s is too long (maximum %d characters).",
12487  "recovery_target_name", MAXFNAMELEN - 1);
12488  return false;
12489  }
12490  return true;
12491 }
#define GUC_check_errdetail
Definition: guc.h:417
#define MAXFNAMELEN
#define newval

◆ check_recovery_target_time()

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

Definition at line 12418 of file guc.c.

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

12419 {
12420  if (strcmp(*newval, "") != 0)
12421  {
12422  /* reject some special values */
12423  if (strcmp(*newval, "now") == 0 ||
12424  strcmp(*newval, "today") == 0 ||
12425  strcmp(*newval, "tomorrow") == 0 ||
12426  strcmp(*newval, "yesterday") == 0)
12427  {
12428  return false;
12429  }
12430 
12431  /*
12432  * parse timestamp value (see also timestamptz_in())
12433  */
12434  {
12435  char *str = *newval;
12436  fsec_t fsec;
12437  struct pg_tm tt,
12438  *tm = &tt;
12439  int tz;
12440  int dtype;
12441  int nf;
12442  int dterr;
12443  char *field[MAXDATEFIELDS];
12444  int ftype[MAXDATEFIELDS];
12445  char workbuf[MAXDATELEN + MAXDATEFIELDS];
12447 
12448  dterr = ParseDateTime(str, workbuf, sizeof(workbuf),
12449  field, ftype, MAXDATEFIELDS, &nf);
12450  if (dterr == 0)
12451  dterr = DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tz);
12452  if (dterr != 0)
12453  return false;
12454  if (dtype != DTK_DATE)
12455  return false;
12456 
12457  if (tm2timestamp(tm, fsec, &tz, &timestamp) != 0)
12458  {
12459  GUC_check_errdetail("timestamp out of range: \"%s\"", str);
12460  return false;
12461  }
12462  }
12463  }
12464  return true;
12465 }
#define MAXDATELEN
Definition: datetime.h:201
#define GUC_check_errdetail
Definition: guc.h:417
int64 timestamp
int64 TimestampTz
Definition: timestamp.h:39
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:102
int DecodeDateTime(char **field, int *ftype, int nf, int *dtype, struct pg_tm *tm, fsec_t *fsec, int *tzp)
Definition: datetime.c:803
int32 fsec_t
Definition: timestamp.h:41
int tm2timestamp(struct pg_tm *tm, fsec_t fsec, int *tzp, Timestamp *result)
Definition: timestamp.c:1918
#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:582
#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 12289 of file guc.c.

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

12290 {
12292  RecoveryTargetTimeLineGoal *myextra;
12293 
12294  if (strcmp(*newval, "current") == 0)
12296  else if (strcmp(*newval, "latest") == 0)
12298  else
12299  {
12301 
12302  errno = 0;
12303  strtoul(*newval, NULL, 0);
12304  if (errno == EINVAL || errno == ERANGE)
12305  {
12306  GUC_check_errdetail("recovery_target_timeline is not a valid number.");
12307  return false;
12308  }
12309  }
12310 
12312  *myextra = rttg;
12313  *extra = (void *) myextra;
12314 
12315  return true;
12316 }
#define GUC_check_errdetail
Definition: guc.h:417
RecoveryTargetTimeLineGoal
Definition: xlog.h:93
#define ERROR
Definition: elog.h:46
#define newval
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:5059

◆ check_recovery_target_xid()

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

Definition at line 12375 of file guc.c.

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

12376 {
12377  if (strcmp(*newval, "") != 0)
12378  {
12379  TransactionId xid;
12380  TransactionId *myextra;
12381 
12382  errno = 0;
12383  xid = (TransactionId) pg_strtouint64(*newval, NULL, 0);
12384  if (errno == EINVAL || errno == ERANGE)
12385  return false;
12386 
12387  myextra = (TransactionId *) guc_malloc(ERROR, sizeof(TransactionId));
12388  *myextra = xid;
12389  *extra = (void *) myextra;
12390  }
12391  return true;
12392 }
uint32 TransactionId
Definition: c.h:587
#define ERROR
Definition: elog.h:46
uint64 pg_strtouint64(const char *str, char **endptr, int base)
Definition: numutils.c:621
#define newval
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:5059

◆ check_ssl()

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

Definition at line 11804 of file guc.c.

References GUC_check_errmsg.

11805 {
11806 #ifndef USE_SSL
11807  if (*newval)
11808  {
11809  GUC_check_errmsg("SSL is not supported by this build");
11810  return false;
11811  }
11812 #endif
11813  return true;
11814 }
#define GUC_check_errmsg
Definition: guc.h:413
#define newval

◆ check_stage_log_stats()

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

Definition at line 11817 of file guc.c.

References GUC_check_errdetail.

11818 {
11819  if (*newval && log_statement_stats)
11820  {
11821  GUC_check_errdetail("Cannot enable parameter when \"log_statement_stats\" is true.");
11822  return false;
11823  }
11824  return true;
11825 }
bool log_statement_stats
Definition: guc.c:549
#define GUC_check_errdetail
Definition: guc.h:417
#define newval

◆ check_temp_buffers()

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

Definition at line 11776 of file guc.c.

References GUC_check_errdetail, NLocBuffer, and PGC_S_TEST.

11777 {
11778  /*
11779  * Once local buffers have been initialized, it's too late to change this.
11780  * However, if this is only a test call, allow it.
11781  */
11782  if (source != PGC_S_TEST && NLocBuffer && NLocBuffer != *newval)
11783  {
11784  GUC_check_errdetail("\"temp_buffers\" cannot be changed after any temporary tables have been accessed in the session.");
11785  return false;
11786  }
11787  return true;
11788 }
#define GUC_check_errdetail
Definition: guc.h:417
int NLocBuffer
Definition: localbuf.c:41
static rewind_source * source
Definition: pg_rewind.c:79
#define newval

◆ check_timezone_abbreviations()

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

Definition at line 11855 of file guc.c.

References Assert, load_tzoffsets(), and PGC_S_DEFAULT.

11856 {
11857  /*
11858  * The boot_val given above for timezone_abbreviations is NULL. When we
11859  * see this we just do nothing. If this value isn't overridden from the
11860  * config file then pg_timezone_abbrev_initialize() will eventually
11861  * replace it with "Default". This hack has two purposes: to avoid
11862  * wasting cycles loading values that might soon be overridden from the
11863  * config file, and to avoid trying to read the timezone abbrev files
11864  * during InitializeGUCOptions(). The latter doesn't work in an
11865  * EXEC_BACKEND subprocess because my_exec_path hasn't been set yet and so
11866  * we can't locate PGSHAREDIR.
11867  */
11868  if (*newval == NULL)
11869  {
11871  return true;
11872  }
11873 
11874  /* OK, load the file and produce a malloc'd TimeZoneAbbrevTable */
11875  *extra = load_tzoffsets(*newval);
11876 
11877  /* tzparser.c returns NULL on failure, reporting via GUC_check_errmsg */
11878  if (!*extra)
11879  return false;
11880 
11881  return true;
11882 }
TimeZoneAbbrevTable * load_tzoffsets(const char *filename)
Definition: tzparser.c:437
#define Assert(condition)
Definition: c.h:804
static rewind_source * source
Definition: pg_rewind.c:79
#define newval

◆ check_wal_consistency_checking()

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

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

11603 {
11604  char *rawstring;
11605  List *elemlist;
11606  ListCell *l;
11607  bool newwalconsistency[RM_MAX_ID + 1];
11608 
11609  /* Initialize the array */
11610  MemSet(newwalconsistency, 0, (RM_MAX_ID + 1) * sizeof(bool));
11611 
11612  /* Need a modifiable copy of string */
11613  rawstring = pstrdup(*newval);
11614 
11615  /* Parse string into list of identifiers */
11616  if (!SplitIdentifierString(rawstring, ',', &elemlist))
11617  {
11618  /* syntax error in list */
11619  GUC_check_errdetail("List syntax is invalid.");
11620  pfree(rawstring);
11621  list_free(elemlist);
11622  return false;
11623  }
11624 
11625  foreach(l, elemlist)
11626  {
11627  char *tok = (char *) lfirst(l);
11628  bool found = false;
11629  RmgrId rmid;
11630 
11631  /* Check for 'all'. */
11632  if (pg_strcasecmp(tok, "all") == 0)
11633  {
11634  for (rmid = 0; rmid <= RM_MAX_ID; rmid++)
11635  if (RmgrTable[rmid].rm_mask != NULL)
11636  newwalconsistency[rmid] = true;
11637  found = true;
11638  }
11639  else
11640  {
11641  /*
11642  * Check if the token matches with any individual resource
11643  * manager.
11644  */
11645  for (rmid = 0; rmid <= RM_MAX_ID; rmid++)
11646  {
11647  if (pg_strcasecmp(tok, RmgrTable[rmid].rm_name) == 0 &&
11648  RmgrTable[rmid].rm_mask != NULL)
11649  {
11650  newwalconsistency[rmid] = true;
11651  found = true;
11652  }
11653  }
11654  }
11655 
11656  /* If a valid resource manager is found, check for the next one. */
11657  if (!found)
11658  {
11659  GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
11660  pfree(rawstring);
11661  list_free(elemlist);
11662  return false;
11663  }
11664  }
11665 
11666  pfree(rawstring);
11667  list_free(elemlist);
11668 
11669  /* assign new value */
11670  *extra = guc_malloc(ERROR, (RM_MAX_ID + 1) * sizeof(bool));
11671  memcpy(*extra, newwalconsistency, (RM_MAX_ID + 1) * sizeof(bool));
11672  return true;
11673 }
#define GUC_check_errdetail
Definition: guc.h:417
char * pstrdup(const char *in)
Definition: mcxt.c:1299
const RmgrData RmgrTable[RM_MAX_ID+1]
Definition: rmgr.c:36
#define MemSet(start, val, len)
Definition: c.h:1008
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
void pfree(void *pointer)
Definition: mcxt.c:1169
#define ERROR
Definition: elog.h:46
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3753
#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:169
#define newval
void list_free(List *list)
Definition: list.c:1391
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:5059
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 7053 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().

7055 {
7056  const struct config_enum_entry *entry;
7057  StringInfoData retstr;
7058  int seplen;
7059 
7060  initStringInfo(&retstr);
7061  appendStringInfoString(&retstr, prefix);
7062 
7063  seplen = strlen(separator);
7064  for (entry = record->options; entry && entry->name; entry++)
7065  {
7066  if (!entry->hidden)
7067  {
7068  appendStringInfoString(&retstr, entry->name);
7069  appendBinaryStringInfo(&retstr, separator, seplen);
7070  }
7071  }
7072 
7073  /*
7074  * All the entries may have been hidden, leaving the string empty if no
7075  * prefix was given. This indicates a broken GUC setup, since there is no
7076  * use for an enum without any values, so we just check to make sure we
7077  * don't write to invalid memory instead of actually trying to do
7078  * something smart with it.
7079  */
7080  if (retstr.len >= seplen)
7081  {
7082  /* Replace final separator */
7083  retstr.data[retstr.len - seplen] = '\0';
7084  retstr.len -= seplen;
7085  }
7086 
7087  appendStringInfoString(&retstr, suffix);
7088 
7089  return retstr.data;
7090 }
Definition: guc.h:164
const struct config_enum_entry * options
Definition: guc_tables.h:249
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 7027 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().

7029 {
7030  const struct config_enum_entry *entry;
7031 
7032  for (entry = record->options; entry && entry->name; entry++)
7033  {
7034  if (pg_strcasecmp(value, entry->name) == 0)
7035  {
7036  *retval = entry->val;
7037  return true;
7038  }
7039  }
7040 
7041  *retval = 0;
7042  return false;
7043 }
static struct @142 value
Definition: guc.h:164
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
const struct config_enum_entry * options
Definition: guc_tables.h:249
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 7004 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().

7005 {
7006  const struct config_enum_entry *entry;
7007 
7008  for (entry = record->options; entry && entry->name; entry++)
7009  {
7010  if (entry->val == val)
7011  return entry->name;
7012  }
7013 
7014  elog(ERROR, "could not find enum option %d for %s",
7015  val, record->gen.name);
7016  return NULL; /* silence compiler */
7017 }
Definition: guc.h:164
const char * name
Definition: guc_tables.h:149
#define ERROR
Definition: elog.h:46
const struct config_enum_entry * options
Definition: guc_tables.h:249
int val
Definition: guc.h:167
struct config_generic gen
Definition: guc_tables.h:245
const char * name
Definition: guc.h:166
#define elog(elevel,...)
Definition: elog.h:232
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 6710 of file guc.c.

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

Referenced by _ShowOption().

6712 {
6713  const unit_conversion *table;
6714  int i;
6715 
6716  *unit = NULL;
6717 
6718  if (base_unit & GUC_UNIT_MEMORY)
6720  else
6722 
6723  for (i = 0; *table[i].unit; i++)
6724  {
6725  if (base_unit == table[i].base_unit)
6726  {
6727  /*
6728  * Accept the first conversion that divides the value evenly. We
6729  * assume that the conversions for each base unit are ordered from
6730  * greatest unit to the smallest!
6731  */
6732  if (table[i].multiplier <= 1.0 ||
6733  base_value % (int64) table[i].multiplier == 0)
6734  {
6735  *value = (int64) rint(base_value / table[i].multiplier);
6736  *unit = table[i].unit;
6737  break;
6738  }
6739  }
6740  }
6741 
6742  Assert(*unit != NULL);
6743 }
static const unit_conversion time_unit_conversion_table[]
Definition: guc.c:900
static const unit_conversion memory_unit_conversion_table[]
Definition: guc.c:863
static struct @142 value
#define Assert(condition)
Definition: c.h:804
int i
char unit[MAX_UNIT_LEN+1]
Definition: guc.c:847
#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 6752 of file guc.c.

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

Referenced by _ShowOption().

6754 {
6755  const unit_conversion *table;
6756  int i;
6757 
6758  *unit = NULL;
6759 
6760  if (base_unit & GUC_UNIT_MEMORY)
6762  else
6764 
6765  for (i = 0; *table[i].unit; i++)
6766  {
6767  if (base_unit == table[i].base_unit)
6768  {
6769  /*
6770  * Accept the first conversion that divides the value evenly; or
6771  * if there is none, use the smallest (last) target unit.
6772  *
6773  * What we actually care about here is whether snprintf with "%g"
6774  * will print the value as an integer, so the obvious test of
6775  * "*value == rint(*value)" is too strict; roundoff error might
6776  * make us choose an unreasonably small unit. As a compromise,
6777  * accept a divisor that is within 1e-8 of producing an integer.
6778  */
6779  *value = base_value / table[i].multiplier;
6780  *unit = table[i].unit;
6781  if (*value > 0 &&
6782  fabs((rint(*value) / *value) - 1.0) <= 1e-8)
6783  break;
6784  }
6785  }
6786 
6787  Assert(*unit != NULL);
6788 }
static const unit_conversion time_unit_conversion_table[]
Definition: guc.c:900
static const unit_conversion memory_unit_conversion_table[]
Definition: guc.c:863
static struct @142 value
#define Assert(condition)
Definition: c.h:804
double multiplier
Definition: guc.c:850
e
Definition: preproc-init.c:82
int i
char unit[MAX_UNIT_LEN+1]
Definition: guc.c:847
#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 6652 of file guc.c.

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

Referenced by parse_int(), and parse_real().

6654 {
6655  char unitstr[MAX_UNIT_LEN + 1];
6656  int unitlen;
6657  const unit_conversion *table;
6658  int i;
6659 
6660  /* extract unit string to compare to table entries */
6661  unitlen = 0;
6662  while (*unit != '\0' && !isspace((unsigned char) *unit) &&
6663  unitlen < MAX_UNIT_LEN)
6664  unitstr[unitlen++] = *(unit++);
6665  unitstr[unitlen] = '\0';
6666  /* allow whitespace after unit */
6667  while (isspace((unsigned char) *unit))
6668  unit++;
6669  if (*unit != '\0')
6670  return false; /* unit too long, or garbage after it */
6671 
6672  /* now search the appropriate table */
6673  if (base_unit & GUC_UNIT_MEMORY)
6675  else
6677 
6678  for (i = 0; *table[i].unit; i++)
6679  {
6680  if (base_unit == table[i].base_unit &&
6681  strcmp(unitstr, table[i].unit) == 0)
6682  {
6683  double cvalue = value * table[i].multiplier;
6684 
6685  /*
6686  * If the user gave a fractional value such as "30.1GB", round it
6687  * off to the nearest multiple of the next smaller unit, if there
6688  * is one.
6689  */
6690  if (*table[i + 1].unit &&
6691  base_unit == table[i + 1].base_unit)
6692  cvalue = rint(cvalue / table[i + 1].multiplier) *
6693  table[i + 1].multiplier;
6694 
6695  *base_value = cvalue;
6696  return true;
6697  }
6698  }
6699  return false;
6700 }
static const unit_conversion time_unit_conversion_table[]
Definition: guc.c:900
static const unit_conversion memory_unit_conversion_table[]
Definition: guc.c:863
static struct @142 value
#define MAX_UNIT_LEN
Definition: guc.c:843
double multiplier
Definition: guc.c:850
int i
char unit[MAX_UNIT_LEN+1]
Definition: guc.c:847
#define GUC_UNIT_MEMORY
Definition: guc.h:223

◆ define_custom_variable()

static void define_custom_variable ( struct config_generic variable)
static

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

8988 {
8989  const char *name = variable->name;
8990  const char **nameAddr = &name;
8991  struct config_string *pHolder;
8992  struct config_generic **res;
8993 
8994  /*
8995  * See if there's a placeholder by the same name.
8996  */
8997  res = (struct config_generic **) bsearch((void *) &nameAddr,
8998  (void *) guc_variables,
9000  sizeof(struct config_generic *),
9001  guc_var_compare);
9002  if (res == NULL)
9003  {
9004  /*
9005  * No placeholder to replace, so we can just add it ... but first,
9006  * make sure it's initialized to its default value.
9007  */
9008  InitializeOneGUCOption(variable);
9009  add_guc_variable(variable, ERROR);
9010  return;
9011  }
9012 
9013  /*
9014  * This better be a placeholder
9015  */
9016  if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
9017  ereport(ERROR,
9018  (errcode(ERRCODE_INTERNAL_ERROR),
9019  errmsg("attempt to redefine parameter \"%s\"", name)));
9020 
9021  Assert((*res)->vartype == PGC_STRING);
9022  pHolder = (struct config_string *) (*res);
9023 
9024  /*
9025  * First, set the variable to its default value. We must do this even
9026  * though we intend to immediately apply a new value, since it's possible
9027  * that the new value is invalid.
9028  */
9029  InitializeOneGUCOption(variable);
9030 
9031  /*
9032  * Replace the placeholder. We aren't changing the name, so no re-sorting
9033  * is necessary
9034  */
9035  *res = variable;
9036 
9037  /*
9038  * Assign the string value(s) stored in the placeholder to the real
9039  * variable. Essentially, we need to duplicate all the active and stacked
9040  * values, but with appropriate validation and datatype adjustment.
9041  *
9042  * If an assignment fails, we report a WARNING and keep going. We don't
9043  * want to throw ERROR for bad values, because it'd bollix the add-on
9044  * module that's presumably halfway through getting loaded. In such cases
9045  * the default or previous state will become active instead.
9046  */
9047 
9048  /* First, apply the reset value if any */
9049  if (pHolder->reset_val)
9050  (void) set_config_option(name, pHolder->reset_val,
9051  pHolder->gen.reset_scontext,
9052  pHolder->gen.reset_source,
9053  GUC_ACTION_SET, true, WARNING, false);
9054  /* That should not have resulted in stacking anything */
9055  Assert(variable->stack == NULL);
9056 
9057  /* Now, apply current and stacked values, in the order they were stacked */
9058  reapply_stacked_values(variable, pHolder, pHolder->gen.stack,
9059  *(pHolder->variable),
9060  pHolder->gen.scontext, pHolder->gen.source);
9061 
9062  /* Also copy over any saved source-location information */
9063  if (pHolder->gen.sourcefile)
9064  set_config_sourcefile(name, pHolder->gen.sourcefile,
9065  pHolder->gen.sourceline);
9066 
9067  /*
9068  * Free up as much as we conveniently can of the placeholder structure.
9069  * (This neglects any stack items, so it's possible for some memory to be
9070  * leaked. Since this can only happen once per session per variable, it
9071  * doesn't seem worth spending much code on.)
9072  */
9073  set_string_field(pHolder, pHolder->variable, NULL);
9074  set_string_field(pHolder, &pHolder->reset_val, NULL);
9075 
9076  free(pHolder);
9077 }
GucSource source
Definition: guc_tables.h:158
static void static void set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
Definition: guc.c:8069
char ** variable
Definition: guc_tables.h:233
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:9087
int errcode(int sqlerrcode)
Definition: elog.c:698
GucContext scontext
Definition: guc_tables.h:160
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:5573
#define ERROR
Definition: elog.h:46
static int num_guc_variables
Definition: guc.c:5019
char * sourcefile
Definition: guc_tables.h:166
GucSource reset_source
Definition: guc_tables.h:159
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:5721
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:5131
static struct config_generic ** guc_variables
Definition: guc.c:5016
#define WARNING
Definition: elog.h:40
#define ereport(elevel,...)
Definition: elog.h:157
struct config_generic gen
Definition: guc_tables.h:231
#define free(a)
Definition: header.h:65
char * reset_val
Definition: guc_tables.h:239
#define Assert(condition)
Definition: c.h:804
#define GUC_CUSTOM_PLACEHOLDER
Definition: guc.h:211
const char * name
Definition: encode.c:515
int errmsg(const char *fmt,...)
Definition: elog.c:909
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:7312
static bool add_guc_variable(struct config_generic *var, int elevel)
Definition: guc.c:5369
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 9168 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().

9178 {
9179  struct config_bool *var;
9180 
9181  var = (struct config_bool *)
9182  init_custom_variable(name, short_desc, long_desc, context, flags,
9183  PGC_BOOL, sizeof(struct config_bool));
9184  var->variable = valueAddr;
9185  var->boot_val = bootValue;
9186  var->reset_val = bootValue;
9187  var->check_hook = check_hook;
9188  var->assign_hook = assign_hook;
9189  var->show_hook = show_hook;
9190  define_custom_variable(&var->gen);
9191 }
bool * variable
Definition: guc_tables.h:187
GucBoolAssignHook assign_hook
Definition: guc_tables.h:190
bool boot_val
Definition: guc_tables.h:188
struct config_generic gen
Definition: guc_tables.h:185
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:8927
GucBoolCheckHook check_hook
Definition: guc_tables.h:189
GucShowHook show_hook
Definition: guc_tables.h:191
const char * name
Definition: encode.c:515
bool reset_val
Definition: guc_tables.h:193
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8987

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

9290 {
9291  struct config_enum *var;
9292 
9293  var = (struct config_enum *)
9294  init_custom_variable(name, short_desc, long_desc, context, flags,
9295  PGC_ENUM, sizeof(struct config_enum));
9296  var->variable = valueAddr;
9297  var->boot_val = bootValue;
9298  var->reset_val = bootValue;
9299  var->options = options;
9300  var->check_hook = check_hook;
9301  var->assign_hook = assign_hook;
9302  var->show_hook = show_hook;
9303  define_custom_variable(&var->gen);
9304 }
GucEnumCheckHook check_hook
Definition: guc_tables.h:250
GucEnumAssignHook assign_hook
Definition: guc_tables.h:251
int * variable
Definition: guc_tables.h:247
const struct config_enum_entry * options
Definition: guc_tables.h:249
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:8927
GucShowHook show_hook
Definition: guc_tables.h:252
struct config_generic gen
Definition: guc_tables.h:245
const char * name
Definition: encode.c:515
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8987

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

9206 {
9207  struct config_int *var;
9208 
9209  var = (struct config_int *)
9210  init_custom_variable(name, short_desc, long_desc, context, flags,
9211  PGC_INT, sizeof(struct config_int));
9212  var->variable = valueAddr;
9213  var->boot_val = bootValue;
9214  var->reset_val = bootValue;
9215  var->min = minValue;
9216  var->max = maxValue;
9217  var->check_hook = check_hook;
9218  var->assign_hook = assign_hook;
9219  var->show_hook = show_hook;
9220  define_custom_variable(&var->gen);
9221 }
int boot_val
Definition: guc_tables.h:202
GucIntAssignHook assign_hook
Definition: guc_tables.h:206
GucIntCheckHook check_hook
Definition: guc_tables.h:205
GucShowHook show_hook
Definition: guc_tables.h:207
int * variable
Definition: guc_tables.h:201
struct config_generic gen
Definition: guc_tables.h:199
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:8927
const char * name
Definition: encode.c:515
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8987
int reset_val
Definition: guc_tables.h:209

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

9236 {
9237  struct config_real *var;
9238 
9239  var = (struct config_real *)
9240  init_custom_variable(name, short_desc, long_desc, context, flags,
9241  PGC_REAL, sizeof(struct config_real));
9242  var->variable = valueAddr;
9243  var->boot_val = bootValue;
9244  var->reset_val = bootValue;
9245  var->min = minValue;
9246  var->max = maxValue;
9247  var->check_hook = check_hook;
9248  var->assign_hook = assign_hook;
9249  var->show_hook = show_hook;
9250  define_custom_variable(&var->gen);
9251 }
GucRealAssignHook assign_hook
Definition: guc_tables.h:222
double reset_val
Definition: guc_tables.h:225
GucRealCheckHook check_hook
Definition: guc_tables.h:221
GucShowHook show_hook
Definition: guc_tables.h:223
double * variable
Definition: guc_tables.h:217
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:8927
double max
Definition: guc_tables.h:220
double boot_val
Definition: guc_tables.h:218
const char * name
Definition: encode.c:515
double min
Definition: guc_tables.h:219
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8987
struct config_generic gen
Definition: guc_tables.h:215

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

9264 {
9265  struct config_string *var;
9266 
9267  var = (struct config_string *)
9268  init_custom_variable(name, short_desc, long_desc, context, flags,
9269  PGC_STRING, sizeof(struct config_string));
9270  var->variable = valueAddr;
9271  var->boot_val = bootValue;
9272  var->check_hook = check_hook;
9273  var->assign_hook = assign_hook;
9274  var->show_hook = show_hook;
9275  define_custom_variable(&var->gen);
9276 }
char ** variable
Definition: guc_tables.h:233
GucStringCheckHook check_hook
Definition: guc_tables.h:235
const char * boot_val
Definition: guc_tables.h:234
GucShowHook show_hook
Definition: guc_tables.h:237
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:8927
struct config_generic gen
Definition: guc_tables.h:231
GucStringAssignHook assign_hook
Definition: guc_tables.h:236
const char * name
Definition: encode.c:515
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8987

◆ discard_stack_value()

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

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

5247 {
5248  switch (gconf->vartype)
5249  {
5250  case PGC_BOOL:
5251  case PGC_INT:
5252  case PGC_REAL:
5253  case PGC_ENUM:
5254  /* no need to do anything */
5255  break;
5256  case PGC_STRING:
5257  set_string_field((struct config_string *) gconf,
5258  &(val->val.stringval),
5259  NULL);
5260  break;
5261  }
5262  set_extra_field(gconf, &(val->extra), NULL);
5263 }
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:5192
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:5131
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 10625 of file guc.c.

References elog, ERROR, and vsnprintf.

Referenced by serialize_variable().

10626 {
10627  va_list vargs;
10628  int n;
10629 
10630  if (*maxbytes <= 0)
10631  elog(ERROR, "not enough space to serialize GUC state");
10632 
10633  va_start(vargs, fmt);
10634  n = vsnprintf(*destptr, *maxbytes, fmt, vargs);
10635  va_end(vargs);
10636 
10637  if (n < 0)
10638  {
10639  /* Shouldn't happen. Better show errno description. */
10640  elog(ERROR, "vsnprintf failed: %m with format string \"%s\"", fmt);
10641  }
10642  if (n >= *maxbytes)
10643  {
10644  /* This shouldn't happen either, really. */
10645  elog(ERROR, "not enough space to serialize GUC state");
10646  }
10647 
10648  /* Shift the destptr ahead of the null terminator */
10649  *destptr += n + 1;
10650  *maxbytes -= n + 1;
10651 }
#define ERROR
Definition: elog.h:46
#define vsnprintf
Definition: port.h:215
#define elog(elevel,...)
Definition: elog.h:232

◆ do_serialize_binary()

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

Definition at line 10655 of file guc.c.

References elog, and ERROR.

Referenced by serialize_variable().

10656 {
10657  if (valsize > *maxbytes)
10658  elog(ERROR, "not enough space to serialize GUC state");
10659 
10660  memcpy(*destptr, val, valsize);
10661  *destptr += valsize;
10662  *maxbytes -= valsize;
10663 }
#define ERROR
Definition: elog.h:46
#define elog(elevel,...)
Definition: elog.h:232
long val
Definition: informix.c:664

◆ EmitWarningsOnPlaceholders()

void EmitWarningsOnPlaceholders ( const char *  className)

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

9308 {
9309  int classLen = strlen(className);
9310  int i;
9311 
9312  for (i = 0; i < num_guc_variables; i++)
9313  {
9314  struct config_generic *var = guc_variables[i];
9315 
9316  if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
9317  strncmp(className, var->name, classLen) == 0 &&
9318  var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
9319  {
9320  ereport(WARNING,
9321  (errcode(ERRCODE_UNDEFINED_OBJECT),
9322  errmsg("unrecognized configuration parameter \"%s\"",
9323  var->name)));
9324  }
9325  }
9326 }
const char * name
Definition: guc_tables.h:149
int errcode(int sqlerrcode)
Definition: elog.c:698
#define GUC_QUALIFIER_SEPARATOR
Definition: guc.h:199
static int num_guc_variables
Definition: guc.c:5019
static struct config_generic ** guc_variables
Definition: guc.c:5016
#define WARNING
Definition: elog.h:40
#define ereport(elevel,...)
Definition: elog.h:157
#define GUC_CUSTOM_PLACEHOLDER
Definition: guc.h:211
int errmsg(const char *fmt,...)
Definition: elog.c:909
int i

◆ estimate_variable_size()

static Size estimate_variable_size ( struct config_generic gconf)
static

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

10504 {
10505  Size size;
10506  Size valsize = 0;
10507 
10508  /* Skippable GUCs consume zero space. */
10509  if (can_skip_gucvar(gconf))
10510  return 0;
10511 
10512  /* Name, plus trailing zero byte. */
10513  size = strlen(gconf->name) + 1;
10514 
10515  /* Get the maximum display length of the GUC value. */
10516  switch (gconf->vartype)
10517  {
10518  case PGC_BOOL:
10519  {
10520  valsize = 5; /* max(strlen('true'), strlen('false')) */
10521  }
10522  break;
10523 
10524  case PGC_INT:
10525  {
10526  struct config_int *conf = (struct config_int *) gconf;
10527 
10528  /*
10529  * Instead of getting the exact display length, use max
10530  * length. Also reduce the max length for typical ranges of
10531  * small values. Maximum value is 2147483647, i.e. 10 chars.
10532  * Include one byte for sign.
10533  */
10534  if (Abs(*conf->variable) < 1000)
10535  valsize = 3 + 1;
10536  else
10537  valsize = 10 + 1;
10538  }
10539  break;
10540 
10541  case PGC_REAL:
10542  {
10543  /*
10544  * We are going to print it with %e with REALTYPE_PRECISION
10545  * fractional digits. Account for sign, leading digit,
10546  * decimal point, and exponent with up to 3 digits. E.g.
10547  * -3.99329042340000021e+110
10548  */
10549  valsize = 1 + 1 + 1 + REALTYPE_PRECISION + 5;
10550  }
10551  break;
10552 
10553  case PGC_STRING:
10554  {
10555  struct config_string *conf = (struct config_string *) gconf;
10556 
10557  /*
10558  * If the value is NULL, we transmit it as an empty string.
10559  * Although this is not physically the same value, GUC
10560  * generally treats a NULL the same as empty string.
10561  */
10562  if (*conf->variable)
10563  valsize = strlen(*conf->variable);
10564  else
10565  valsize = 0;
10566  }
10567  break;
10568 
10569  case PGC_ENUM:
10570  {
10571  struct config_enum *conf = (struct config_enum *) gconf;
10572 
10573  valsize = strlen(config_enum_lookup_by_value(conf, *conf->variable));
10574  }
10575  break;
10576  }
10577 
10578  /* Allow space for terminating zero-byte for value */
10579  size = add_size(size, valsize + 1);
10580 
10581  if (gconf->sourcefile)
10582  size = add_size(size, strlen(gconf->sourcefile));
10583 
10584  /* Allow space for terminating zero-byte for sourcefile */
10585  size = add_size(size, 1);
10586 
10587  /* Include line whenever file is nonempty. */
10588  if (gconf->sourcefile && gconf->sourcefile[0])
10589  size = add_size(size, sizeof(gconf->sourceline));
10590 
10591  size = add_size(size, sizeof(gconf->source));
10592  size = add_size(size, sizeof(gconf->scontext));
10593 
10594  return size;
10595 }
GucSource source
Definition: guc_tables.h:158
char ** variable
Definition: guc_tables.h:233
const char * name
Definition: guc_tables.h:149
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:7004
GucContext scontext
Definition: guc_tables.h:160
#define Abs(x)
Definition: c.h:992
int * variable
Definition: guc_tables.h:201
int * variable
Definition: guc_tables.h:247
char * sourcefile
Definition: guc_tables.h:166
static bool can_skip_gucvar(struct config_generic *gconf)
Definition: guc.c:10463
#define REALTYPE_PRECISION
Definition: guc.c:129
enum config_type vartype
Definition: guc_tables.h:156
Size add_size(Size s1, Size s2)
Definition: shmem.c:502
size_t Size
Definition: c.h:540

◆ EstimateGUCStateSpace()

Size EstimateGUCStateSpace ( void  )

Definition at line 10602 of file guc.c.

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

Referenced by InitializeParallelDSM().

10603 {
10604  Size size;
10605  int i;
10606 
10607  /* Add space reqd for saving the data size of the guc state */
10608  size = sizeof(Size);
10609 
10610  /* Add up the space needed for each GUC variable */
10611  for (i = 0; i < num_guc_variables; i++)
10612  size = add_size(size,
10614 
10615  return size;
10616 }
static int num_guc_variables
Definition: guc.c:5019
static struct config_generic ** guc_variables
Definition: guc.c:5016
Size add_size(Size s1, Size s2)
Definition: shmem.c:502
size_t Size
Definition: c.h:540
static Size estimate_variable_size(struct config_generic *gconf)
Definition: guc.c:10503
int i

◆ ExecSetVariableStmt()

void ExecSetVariableStmt ( VariableSetStmt stmt,
bool  isTopLevel 
)

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

8716 {
8718 
8719  /*
8720  * Workers synchronize these parameters at the start of the parallel
8721  * operation; then, we block SET during the operation.
8722  */
8723  if (IsInParallelMode())
8724  ereport(ERROR,
8725  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
8726  errmsg("cannot set parameters during a parallel operation")));
8727 
8728  switch (stmt->kind)
8729  {
8730  case VAR_SET_VALUE:
8731  case VAR_SET_CURRENT:
8732  if (stmt->is_local)
8733  WarnNoTransactionBlock(isTopLevel, "SET LOCAL");
8734  (void) set_config_option(stmt->name,
8735  ExtractSetVariableArgs(stmt),
8737  PGC_S_SESSION,
8738  action, true, 0, false);
8739  break;
8740  case VAR_SET_MULTI:
8741 
8742  /*
8743  * Special-case SQL syntaxes. The TRANSACTION and SESSION
8744  * CHARACTERISTICS cases effectively set more than one variable
8745  * per statement. TRANSACTION SNAPSHOT only takes one argument,
8746  * but we put it here anyway since it's a special case and not
8747  * related to any GUC variable.
8748  */
8749  if (strcmp(stmt->name, "TRANSACTION") == 0)
8750  {
8751  ListCell *head;
8752 
8753  WarnNoTransactionBlock(isTopLevel, "SET TRANSACTION");
8754 
8755  foreach(head, stmt->args)
8756  {
8757  DefElem *item = (DefElem *) lfirst(head);
8758 
8759  if (strcmp(item->defname, "transaction_isolation") == 0)
8760  SetPGVariable("transaction_isolation",
8761  list_make1(item->arg), stmt->is_local);
8762  else if (strcmp(item->defname, "transaction_read_only") == 0)
8763  SetPGVariable("transaction_read_only",
8764  list_make1(item->arg), stmt->is_local);
8765  else if (strcmp(item->defname, "transaction_deferrable") == 0)
8766  SetPGVariable("transaction_deferrable",
8767