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/transam.h"
#include "access/twophase.h"
#include "access/xact.h"
#include "access/xlog_internal.h"
#include "catalog/namespace.h"
#include "catalog/pg_authid.h"
#include "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/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 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 struct config_genericadd_placeholder_variable (const char *name, int elevel)
 
static struct config_genericfind_option (const char *name, bool create_placeholders, int elevel)
 
void InitializeGUCOptions (void)
 
bool SelectConfigFiles (const char *userDoption, const char *progname)
 
void ResetAllOptions (void)
 
void AtStart_GUC (void)
 
int NewGUCNestLevel (void)
 
void AtEOXact_GUC (bool isCommit, int nestLevel)
 
void BeginReportingGUCOptions (void)
 
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 shared_memory_options []
 
const struct config_enum_entry wal_level_options []
 
const struct config_enum_entry archive_mode_options []
 
const struct config_enum_entry recovery_target_action_options []
 
const struct config_enum_entry sync_method_options []
 
const struct config_enum_entry dynamic_shared_memory_options []
 
bool log_duration = false
 
bool 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 110 of file guc.c.

Referenced by SelectConfigFiles().

◆ HBA_FILENAME

#define HBA_FILENAME   "pg_hba.conf"

Definition at line 111 of file guc.c.

Referenced by SelectConfigFiles().

◆ IDENT_FILENAME

#define IDENT_FILENAME   "pg_ident.conf"

Definition at line 112 of file guc.c.

Referenced by SelectConfigFiles().

◆ MAX_UNIT_LEN

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

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

Referenced by show_all_settings().

◆ PG_KRB_SRVTAB

#define PG_KRB_SRVTAB   ""

Definition at line 107 of file guc.c.

◆ REALTYPE_PRECISION

#define REALTYPE_PRECISION   17

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

References AllocateFile(), Assert, config_enum_lookup_by_value(), convert_int_from_base_unit(), convert_real_from_base_unit(), elevel, elog, ereport, errcode_for_file_access(), errmsg(), ERROR, FATAL, find_option(), config_generic::flags, fprintf, free, FreeFile(), GUC_ACTION_SET, guc_malloc(), guc_realloc(), GUC_UNIT, i, INT64_FORMAT, IsInitProcessingMode, LOG, config_generic::name, num_guc_variables, PGC_BOOL, PGC_ENUM, PGC_INT, PGC_POSTMASTER, PGC_REAL, PGC_S_DEFAULT, PGC_SIGHUP, PGC_STRING, pstrdup(), config_generic::scontext, set_config_option(), set_config_sourcefile(), config_bool::show_hook, config_int::show_hook, config_real::show_hook, config_string::show_hook, config_enum::show_hook, snprintf, config_generic::source, config_generic::sourcefile, config_generic::sourceline, generate_unaccent_rules::str, val, config_bool::variable, config_int::variable, config_real::variable, config_string::variable, config_enum::variable, and config_generic::vartype.

Referenced by GetConfigOptionByName(), GetConfigOptionByNum(), ReportGUCOption(), and ShowAllGUCConfig().

9926 {
9927  char buffer[256];
9928  const char *val;
9929 
9930  switch (record->vartype)
9931  {
9932  case PGC_BOOL:
9933  {
9934  struct config_bool *conf = (struct config_bool *) record;
9935 
9936  if (conf->show_hook)
9937  val = conf->show_hook();
9938  else
9939  val = *conf->variable ? "on" : "off";
9940  }
9941  break;
9942 
9943  case PGC_INT:
9944  {
9945  struct config_int *conf = (struct config_int *) record;
9946 
9947  if (conf->show_hook)
9948  val = conf->show_hook();
9949  else
9950  {
9951  /*
9952  * Use int64 arithmetic to avoid overflows in units
9953  * conversion.
9954  */
9955  int64 result = *conf->variable;
9956  const char *unit;
9957 
9958  if (use_units && result > 0 && (record->flags & GUC_UNIT))
9960  record->flags & GUC_UNIT,
9961  &result, &unit);
9962  else
9963  unit = "";
9964 
9965  snprintf(buffer, sizeof(buffer), INT64_FORMAT "%s",
9966  result, unit);
9967  val = buffer;
9968  }
9969  }
9970  break;
9971 
9972  case PGC_REAL:
9973  {
9974  struct config_real *conf = (struct config_real *) record;
9975 
9976  if (conf->show_hook)
9977  val = conf->show_hook();
9978  else
9979  {
9980  double result = *conf->variable;
9981  const char *unit;
9982 
9983  if (use_units && result > 0 && (record->flags & GUC_UNIT))
9985  record->flags & GUC_UNIT,
9986  &result, &unit);
9987  else
9988  unit = "";
9989 
9990  snprintf(buffer, sizeof(buffer), "%g%s",
9991  result, unit);
9992  val = buffer;
9993  }
9994  }
9995  break;
9996 
9997  case PGC_STRING:
9998  {
9999  struct config_string *conf = (struct config_string *) record;
10000 
10001  if (conf->show_hook)
10002  val = conf->show_hook();
10003  else if (*conf->variable && **conf->variable)
10004  val = *conf->variable;
10005  else
10006  val = "";
10007  }
10008  break;
10009 
10010  case PGC_ENUM:
10011  {
10012  struct config_enum *conf = (struct config_enum *) record;
10013 
10014  if (conf->show_hook)
10015  val = conf->show_hook();
10016  else
10017  val = config_enum_lookup_by_value(conf, *conf->variable);
10018  }
10019  break;
10020 
10021  default:
10022  /* just to keep compiler quiet */
10023  val = "???";
10024  break;
10025  }
10026 
10027  return pstrdup(val);
10028 }
char ** variable
Definition: guc_tables.h:233
char * pstrdup(const char *in)
Definition: mcxt.c:1187
bool * variable
Definition: guc_tables.h:187
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:6779
#define GUC_UNIT
Definition: guc.h:233
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:6527
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:471
static void convert_int_from_base_unit(int64 base_value, int base_unit, int64 *value, const char **unit)
Definition: guc.c:6485
#define snprintf
Definition: port.h:215
long val
Definition: informix.c:664

◆ add_guc_variable()

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

Definition at line 5211 of file guc.c.

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

Referenced by add_placeholder_variable(), and define_custom_variable().

5212 {
5214  {
5215  /*
5216  * Increase the vector by 25%
5217  */
5218  int size_vars = size_guc_variables + size_guc_variables / 4;
5219  struct config_generic **guc_vars;
5220 
5221  if (size_vars == 0)
5222  {
5223  size_vars = 100;
5224  guc_vars = (struct config_generic **)
5225  guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
5226  }
5227  else
5228  {
5229  guc_vars = (struct config_generic **)
5230  guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
5231  }
5232 
5233  if (guc_vars == NULL)
5234  return false; /* out of memory */
5235 
5236  guc_variables = guc_vars;
5237  size_guc_variables = size_vars;
5238  }
5241  sizeof(struct config_generic *), guc_var_compare);
5242  return true;
5243 }
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:5346
static int num_guc_variables
Definition: guc.c:4861
static void * guc_realloc(int elevel, void *old, size_t size)
Definition: guc.c:4917
static struct config_generic ** guc_variables
Definition: guc.c:4858
static int size_guc_variables
Definition: guc.c:4864
static int elevel
Definition: vacuumlazy.c:333
#define qsort(a, b, c, d)
Definition: port.h:503
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4901

◆ add_placeholder_variable()

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

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

5250 {
5251  size_t sz = sizeof(struct config_string) + sizeof(char *);
5252  struct config_string *var;
5253  struct config_generic *gen;
5254 
5255  var = (struct config_string *) guc_malloc(elevel, sz);
5256  if (var == NULL)
5257  return NULL;
5258  memset(var, 0, sz);
5259  gen = &var->gen;
5260 
5261  gen->name = guc_strdup(elevel, name);
5262  if (gen->name == NULL)
5263  {
5264  free(var);
5265  return NULL;
5266  }
5267 
5268  gen->context = PGC_USERSET;
5269  gen->group = CUSTOM_OPTIONS;
5270  gen->short_desc = "GUC placeholder variable";
5272  gen->vartype = PGC_STRING;
5273 
5274  /*
5275  * The char* is allocated at the end of the struct since we have no
5276  * 'static' place to point to. Note that the current value, as well as
5277  * the boot and reset values, start out NULL.
5278  */
5279  var->variable = (char **) (var + 1);
5280 
5281  if (!add_guc_variable((struct config_generic *) var, elevel))
5282  {
5283  free(unconstify(char *, gen->name));
5284  free(var);
5285  return NULL;
5286  }
5287 
5288  return gen;
5289 }
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:4933
#define GUC_NO_SHOW_ALL
Definition: guc.h:207
#define GUC_NOT_IN_SAMPLE
Definition: guc.h:210
enum config_type vartype
Definition: guc_tables.h:156
#define unconstify(underlying_type, expr)
Definition: c.h:1231
static int elevel
Definition: vacuumlazy.c:333
struct config_generic gen
Definition: guc_tables.h:231
#define free(a)
Definition: header.h:65
#define GUC_CUSTOM_PLACEHOLDER
Definition: guc.h:212
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:4901
GucContext context
Definition: guc_tables.h:150
static bool add_guc_variable(struct config_generic *var, int elevel)
Definition: guc.c:5211

◆ AlterSystemSetConfigFile()

void AlterSystemSetConfigFile ( AlterSystemStmt altersysstmt)

Definition at line 8298 of file guc.c.

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

Referenced by standard_ProcessUtility().

8299 {
8300  char *name;
8301  char *value;
8302  bool resetall = false;
8303  ConfigVariable *head = NULL;
8304  ConfigVariable *tail = NULL;
8305  volatile int Tmpfd;
8306  char AutoConfFileName[MAXPGPATH];
8307  char AutoConfTmpFileName[MAXPGPATH];
8308 
8309  if (!superuser())
8310  ereport(ERROR,
8311  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
8312  errmsg("must be superuser to execute ALTER SYSTEM command")));
8313 
8314  /*
8315  * Extract statement arguments
8316  */
8317  name = altersysstmt->setstmt->name;
8318 
8319  switch (altersysstmt->setstmt->kind)
8320  {
8321  case VAR_SET_VALUE:
8322  value = ExtractSetVariableArgs(altersysstmt->setstmt);
8323  break;
8324 
8325  case VAR_SET_DEFAULT:
8326  case VAR_RESET:
8327  value = NULL;
8328  break;
8329 
8330  case VAR_RESET_ALL:
8331  value = NULL;
8332  resetall = true;
8333  break;
8334 
8335  default:
8336  elog(ERROR, "unrecognized alter system stmt type: %d",
8337  altersysstmt->setstmt->kind);
8338  break;
8339  }
8340 
8341  /*
8342  * Unless it's RESET_ALL, validate the target variable and value
8343  */
8344  if (!resetall)
8345  {
8346  struct config_generic *record;
8347 
8348  record = find_option(name, false, ERROR);
8349  if (record == NULL)
8350  ereport(ERROR,
8351  (errcode(ERRCODE_UNDEFINED_OBJECT),
8352  errmsg("unrecognized configuration parameter \"%s\"",
8353  name)));
8354 
8355  /*
8356  * Don't allow parameters that can't be set in configuration files to
8357  * be set in PG_AUTOCONF_FILENAME file.
8358  */
8359  if ((record->context == PGC_INTERNAL) ||
8360  (record->flags & GUC_DISALLOW_IN_FILE) ||
8361  (record->flags & GUC_DISALLOW_IN_AUTO_FILE))
8362  ereport(ERROR,
8363  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
8364  errmsg("parameter \"%s\" cannot be changed",
8365  name)));
8366 
8367  /*
8368  * If a value is specified, verify that it's sane.
8369  */
8370  if (value)
8371  {
8372  union config_var_val newval;
8373  void *newextra = NULL;
8374 
8375  /* Check that it's acceptable for the indicated parameter */
8376  if (!parse_and_validate_value(record, name, value,
8377  PGC_S_FILE, ERROR,
8378  &newval, &newextra))
8379  ereport(ERROR,
8380  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8381  errmsg("invalid value for parameter \"%s\": \"%s\"",
8382  name, value)));
8383 
8384  if (record->vartype == PGC_STRING && newval.stringval != NULL)
8385  free(newval.stringval);
8386  if (newextra)
8387  free(newextra);
8388 
8389  /*
8390  * We must also reject values containing newlines, because the
8391  * grammar for config files doesn't support embedded newlines in
8392  * string literals.
8393  */
8394  if (strchr(value, '\n'))
8395  ereport(ERROR,
8396  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8397  errmsg("parameter value for ALTER SYSTEM must not contain a newline")));
8398  }
8399  }
8400 
8401  /*
8402  * PG_AUTOCONF_FILENAME and its corresponding temporary file are always in
8403  * the data directory, so we can reference them by simple relative paths.
8404  */
8405  snprintf(AutoConfFileName, sizeof(AutoConfFileName), "%s",
8407  snprintf(AutoConfTmpFileName, sizeof(AutoConfTmpFileName), "%s.%s",
8408  AutoConfFileName,
8409  "tmp");
8410 
8411  /*
8412  * Only one backend is allowed to operate on PG_AUTOCONF_FILENAME at a
8413  * time. Use AutoFileLock to ensure that. We must hold the lock while
8414  * reading the old file contents.
8415  */
8416  LWLockAcquire(AutoFileLock, LW_EXCLUSIVE);
8417 
8418  /*
8419  * If we're going to reset everything, then no need to open or parse the
8420  * old file. We'll just write out an empty list.
8421  */
8422  if (!resetall)
8423  {
8424  struct stat st;
8425 
8426  if (stat(AutoConfFileName, &st) == 0)
8427  {
8428  /* open old file PG_AUTOCONF_FILENAME */
8429  FILE *infile;
8430 
8431  infile = AllocateFile(AutoConfFileName, "r");
8432  if (infile == NULL)
8433  ereport(ERROR,
8435  errmsg("could not open file \"%s\": %m",
8436  AutoConfFileName)));
8437 
8438  /* parse it */
8439  if (!ParseConfigFp(infile, AutoConfFileName, 0, LOG, &head, &tail))
8440  ereport(ERROR,
8441  (errcode(ERRCODE_CONFIG_FILE_ERROR),
8442  errmsg("could not parse contents of file \"%s\"",
8443  AutoConfFileName)));
8444 
8445  FreeFile(infile);
8446  }
8447 
8448  /*
8449  * Now, replace any existing entry with the new value, or add it if
8450  * not present.
8451  */
8452  replace_auto_config_value(&head, &tail, name, value);
8453  }
8454 
8455  /*
8456  * To ensure crash safety, first write the new file data to a temp file,
8457  * then atomically rename it into place.
8458  *
8459  * If there is a temp file left over due to a previous crash, it's okay to
8460  * truncate and reuse it.
8461  */
8462  Tmpfd = BasicOpenFile(AutoConfTmpFileName,
8463  O_CREAT | O_RDWR | O_TRUNC);
8464  if (Tmpfd < 0)
8465  ereport(ERROR,
8467  errmsg("could not open file \"%s\": %m",
8468  AutoConfTmpFileName)));
8469 
8470  /*
8471  * Use a TRY block to clean up the file if we fail. Since we need a TRY
8472  * block anyway, OK to use BasicOpenFile rather than OpenTransientFile.
8473  */
8474  PG_TRY();
8475  {
8476  /* Write and sync the new contents to the temporary file */
8477  write_auto_conf_file(Tmpfd, AutoConfTmpFileName, head);
8478 
8479  /* Close before renaming; may be required on some platforms */
8480  close(Tmpfd);
8481  Tmpfd = -1;
8482 
8483  /*
8484  * As the rename is atomic operation, if any problem occurs after this
8485  * at worst it can lose the parameters set by last ALTER SYSTEM
8486  * command.
8487  */
8488  durable_rename(AutoConfTmpFileName, AutoConfFileName, ERROR);
8489  }
8490  PG_CATCH();
8491  {
8492  /* Close file first, else unlink might fail on some platforms */
8493  if (Tmpfd >= 0)
8494  close(Tmpfd);
8495 
8496  /* Unlink, but ignore any error */
8497  (void) unlink(AutoConfTmpFileName);
8498 
8499  PG_RE_THROW();
8500  }
8501  PG_END_TRY();
8502 
8503  FreeConfigVariables(head);
8504 
8505  LWLockRelease(AutoFileLock);
8506 }
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:6886
VariableSetKind kind
Definition: parsenodes.h:2058
static struct @144 value
int errcode(int sqlerrcode)
Definition: elog.c:704
bool superuser(void)
Definition: superuser.c:46
#define LOG
Definition: elog.h:26
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1810
#define ERROR
Definition: elog.h:45
#define MAXPGPATH
VariableSetStmt * setstmt
Definition: parsenodes.h:3211
int errcode_for_file_access(void)
Definition: elog.c:727
FILE * AllocateFile(const char *name, const char *mode)
Definition: fd.c:2354
int durable_rename(const char *oldfile, const char *newfile, int elevel)
Definition: fd.c:687
enum config_type vartype
Definition: guc_tables.h:156
#define GUC_DISALLOW_IN_FILE
Definition: guc.h:211
static void write_auto_conf_file(int fd, const char *filename, ConfigVariable *head_p)
Definition: guc.c:8160
#define ereport(elevel,...)
Definition: elog.h:155
static void infile(const char *filename)
Definition: zic.c:1241
#define free(a)
Definition: header.h:65
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:5297
#define PG_CATCH()
Definition: elog.h:319
#define newval
#define PG_AUTOCONF_FILENAME
Definition: guc.h:34
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1206
#define PG_RE_THROW()
Definition: elog.h:350
const char * name
Definition: encode.c:515
#define GUC_DISALLOW_IN_AUTO_FILE
Definition: guc.h:216
int BasicOpenFile(const char *fileName, int fileFlags)
Definition: fd.c:1014
int FreeFile(FILE *file)
Definition: fd.c:2553
int errmsg(const char *fmt,...)
Definition: elog.c:915
bool ParseConfigFp(FILE *fp, const char *config_file, int depth, int elevel, ConfigVariable **head_p, ConfigVariable **tail_p)
#define elog(elevel,...)
Definition: elog.h:228
static void replace_auto_config_value(ConfigVariable **head_p, ConfigVariable **tail_p, const char *name, const char *value)
Definition: guc.c:8228
void FreeConfigVariables(ConfigVariable *list)
#define close(a)
Definition: win32.h:12
#define PG_TRY()
Definition: elog.h:309
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
Definition: guc.c:8636
#define snprintf
Definition: port.h:215
#define PG_END_TRY()
Definition: elog.h:334
#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 11815 of file guc.c.

References pgstat_report_appname().

11816 {
11817  /* Update the pg_stat_activity view */
11819 }
void pgstat_report_appname(const char *appname)
Definition: pgstat.c:3552
#define newval

◆ assign_backtrace_functions()

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

Definition at line 11934 of file guc.c.

11935 {
11936  backtrace_symbol_list = (char *) extra;
11937 }
char * backtrace_symbol_list
Definition: guc.c:551

◆ assign_log_destination()

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

Definition at line 11419 of file guc.c.

References Log_destination.

11420 {
11421  Log_destination = *((int *) extra);
11422 }
int Log_destination
Definition: elog.c:111

◆ assign_pgstat_temp_directory()

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

Definition at line 11777 of file guc.c.

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

11778 {
11779  /* check_canonical_path already canonicalized newval for us */
11780  char *dname;
11781  char *tname;
11782  char *fname;
11783 
11784  /* directory */
11785  dname = guc_malloc(ERROR, strlen(newval) + 1); /* runtime dir */
11786  sprintf(dname, "%s", newval);
11787 
11788  /* global stats */
11789  tname = guc_malloc(ERROR, strlen(newval) + 12); /* /global.tmp */
11790  sprintf(tname, "%s/global.tmp", newval);
11791  fname = guc_malloc(ERROR, strlen(newval) + 13); /* /global.stat */
11792  sprintf(fname, "%s/global.stat", newval);
11793 
11796  pgstat_stat_directory = dname;
11797  if (pgstat_stat_tmpname)
11799  pgstat_stat_tmpname = tname;
11802  pgstat_stat_filename = fname;
11803 }
#define sprintf
Definition: port.h:217
char * pgstat_stat_filename
Definition: pgstat.c:136
#define ERROR
Definition: elog.h:45
char * pgstat_stat_directory
Definition: pgstat.c:135
#define free(a)
Definition: header.h:65
#define newval
char * pgstat_stat_tmpname
Definition: pgstat.c:137
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4901

◆ assign_recovery_target()

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

Definition at line 12013 of file guc.c.

References RECOVERY_TARGET_IMMEDIATE, RECOVERY_TARGET_UNSET, and recoveryTarget.

12014 {
12017  error_multiple_recovery_targets();
12018 
12019  if (newval && strcmp(newval, "") != 0)
12021  else
12023 }
#define newval
RecoveryTargetType recoveryTarget
Definition: xlog.c:284

◆ assign_recovery_target_lsn()

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

Definition at line 12181 of file guc.c.

References RECOVERY_TARGET_LSN, RECOVERY_TARGET_UNSET, recoveryTarget, and recoveryTargetLSN.

12182 {
12185  error_multiple_recovery_targets();
12186 
12187  if (newval && strcmp(newval, "") != 0)
12188  {
12190  recoveryTargetLSN = *((XLogRecPtr *) extra);
12191  }
12192  else
12194 }
XLogRecPtr recoveryTargetLSN
Definition: xlog.c:291
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define newval
RecoveryTargetType recoveryTarget
Definition: xlog.c:284

◆ assign_recovery_target_name()

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

Definition at line 12145 of file guc.c.

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

12146 {
12149  error_multiple_recovery_targets();
12150 
12151  if (newval && strcmp(newval, "") != 0)
12152  {
12155  }
12156  else
12158 }
const char * recoveryTargetName
Definition: xlog.c:290
#define newval
RecoveryTargetType recoveryTarget
Definition: xlog.c:284

◆ assign_recovery_target_time()

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

Definition at line 12119 of file guc.c.

References RECOVERY_TARGET_TIME, RECOVERY_TARGET_UNSET, and recoveryTarget.

12120 {
12123  error_multiple_recovery_targets();
12124 
12125  if (newval && strcmp(newval, "") != 0)
12127  else
12129 }
#define newval
RecoveryTargetType recoveryTarget
Definition: xlog.c:284

◆ assign_recovery_target_timeline()

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

Definition at line 11970 of file guc.c.

References RECOVERY_TARGET_TIMELINE_NUMERIC, recoveryTargetTimeLineGoal, and recoveryTargetTLIRequested.

11971 {
11974  recoveryTargetTLIRequested = (TimeLineID) strtoul(newval, NULL, 0);
11975  else
11977 }
TimeLineID recoveryTargetTLIRequested
Definition: xlog.c:341
uint32 TimeLineID
Definition: xlogdefs.h:52
RecoveryTargetTimeLineGoal
Definition: xlog.h:93
RecoveryTargetTimeLineGoal recoveryTargetTimeLineGoal
Definition: xlog.c:340
#define newval

◆ assign_recovery_target_xid()

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

Definition at line 12046 of file guc.c.

References RECOVERY_TARGET_UNSET, RECOVERY_TARGET_XID, recoveryTarget, and recoveryTargetXid.

12047 {
12050  error_multiple_recovery_targets();
12051 
12052  if (newval && strcmp(newval, "") != 0)
12053  {
12055  recoveryTargetXid = *((TransactionId *) extra);
12056  }
12057  else
12059 }
uint32 TransactionId
Definition: c.h:575
TransactionId recoveryTargetXid
Definition: xlog.c:287
#define newval
RecoveryTargetType recoveryTarget
Definition: xlog.c:284

◆ assign_session_replication_role()

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

Definition at line 11445 of file guc.c.

References ResetPlanCache(), and SessionReplicationRole.

11446 {
11447  /*
11448  * Must flush the plan cache when changing replication role; but don't
11449  * flush unnecessarily.
11450  */
11452  ResetPlanCache();
11453 }
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 11425 of file guc.c.

11426 {
11427 #ifdef HAVE_SYSLOG
11428  set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
11429  newval);
11430 #endif
11431  /* Without syslog support, just ignore it */
11432 }
static char * syslog_ident_str
Definition: guc.c:592
#define newval

◆ assign_syslog_ident()

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

Definition at line 11435 of file guc.c.

11436 {
11437 #ifdef HAVE_SYSLOG
11438  set_syslog_parameters(newval, syslog_facility);
11439 #endif
11440  /* Without syslog support, it will always be set to "none", so ignore */
11441 }
static int syslog_facility
Definition: guc.c:174
#define newval

◆ assign_tcp_keepalives_count()

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

Definition at line 11644 of file guc.c.

References MyProcPort, and pq_setkeepalivescount().

11645 {
11646  /* See comments in assign_tcp_keepalives_idle */
11648 }
struct Port * MyProcPort
Definition: globals.c:44
int pq_setkeepalivescount(int count, Port *port)
Definition: pqcomm.c:1895
#define newval

◆ assign_tcp_keepalives_idle()

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

Definition at line 11600 of file guc.c.

References MyProcPort, and pq_setkeepalivesidle().

11601 {
11602  /*
11603  * The kernel API provides no way to test a value without setting it; and
11604  * once we set it we might fail to unset it. So there seems little point
11605  * in fully implementing the check-then-assign GUC API for these
11606  * variables. Instead we just do the assignment on demand. pqcomm.c
11607  * reports any problems via ereport(LOG).
11608  *
11609  * This approach means that the GUC value might have little to do with the
11610  * actual kernel value, so we use a show_hook that retrieves the kernel
11611  * value rather than trusting GUC's copy.
11612  */
11614 }
struct Port * MyProcPort
Definition: globals.c:44
int pq_setkeepalivesidle(int idle, Port *port)
Definition: pqcomm.c:1731
#define newval

◆ assign_tcp_keepalives_interval()

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

Definition at line 11627 of file guc.c.

References MyProcPort, and pq_setkeepalivesinterval().

11628 {
11629  /* See comments in assign_tcp_keepalives_idle */
11631 }
struct Port * MyProcPort
Definition: globals.c:44
int pq_setkeepalivesinterval(int interval, Port *port)
Definition: pqcomm.c:1816
#define newval

◆ assign_tcp_user_timeout()

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

Definition at line 11661 of file guc.c.

References MyProcPort, and pq_settcpusertimeout().

11662 {
11663  /* See comments in assign_tcp_keepalives_idle */
11665 }
struct Port * MyProcPort
Definition: globals.c:44
#define newval
int pq_settcpusertimeout(int timeout, Port *port)
Definition: pqcomm.c:1970

◆ assign_timezone_abbreviations()

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

Definition at line 11564 of file guc.c.

References InstallTimeZoneAbbrevs().

11565 {
11566  /* Do nothing for the boot_val default of NULL */
11567  if (!extra)
11568  return;
11569 
11571 }
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 11356 of file guc.c.

References wal_consistency_checking.

11357 {
11358  wal_consistency_checking = (bool *) extra;
11359 }
bool * wal_consistency_checking
Definition: xlog.c:103

◆ AtEOXact_GUC()

void AtEOXact_GUC ( bool  isCommit,
int  nestLevel 
)

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

6009 {
6010  bool still_dirty;
6011  int i;
6012 
6013  /*
6014  * Note: it's possible to get here with GUCNestLevel == nestLevel-1 during
6015  * abort, if there is a failure during transaction start before
6016  * AtStart_GUC is called.
6017  */
6018  Assert(nestLevel > 0 &&
6019  (nestLevel <= GUCNestLevel ||
6020  (nestLevel == GUCNestLevel + 1 && !isCommit)));
6021 
6022  /* Quick exit if nothing's changed in this transaction */
6023  if (!guc_dirty)
6024  {
6025  GUCNestLevel = nestLevel - 1;
6026  return;
6027  }
6028 
6029  still_dirty = false;
6030  for (i = 0; i < num_guc_variables; i++)
6031  {
6032  struct config_generic *gconf = guc_variables[i];
6033  GucStack *stack;
6034 
6035  /*
6036  * Process and pop each stack entry within the nest level. To simplify
6037  * fmgr_security_definer() and other places that use GUC_ACTION_SAVE,
6038  * we allow failure exit from code that uses a local nest level to be
6039  * recovered at the surrounding transaction or subtransaction abort;
6040  * so there could be more than one stack entry to pop.
6041  */
6042  while ((stack = gconf->stack) != NULL &&
6043  stack->nest_level >= nestLevel)
6044  {
6045  GucStack *prev = stack->prev;
6046  bool restorePrior = false;
6047  bool restoreMasked = false;
6048  bool changed;
6049 
6050  /*
6051  * In this next bit, if we don't set either restorePrior or
6052  * restoreMasked, we must "discard" any unwanted fields of the
6053  * stack entries to avoid leaking memory. If we do set one of
6054  * those flags, unused fields will be cleaned up after restoring.
6055  */
6056  if (!isCommit) /* if abort, always restore prior value */
6057  restorePrior = true;
6058  else if (stack->state == GUC_SAVE)
6059  restorePrior = true;
6060  else if (stack->nest_level == 1)
6061  {
6062  /* transaction commit */
6063  if (stack->state == GUC_SET_LOCAL)
6064  restoreMasked = true;
6065  else if (stack->state == GUC_SET)
6066  {
6067  /* we keep the current active value */
6068  discard_stack_value(gconf, &stack->prior);
6069  }
6070  else /* must be GUC_LOCAL */
6071  restorePrior = true;
6072  }
6073  else if (prev == NULL ||
6074  prev->nest_level < stack->nest_level - 1)
6075  {
6076  /* decrement entry's level and do not pop it */
6077  stack->nest_level--;
6078  continue;
6079  }
6080  else
6081  {
6082  /*
6083  * We have to merge this stack entry into prev. See README for
6084  * discussion of this bit.
6085  */
6086  switch (stack->state)
6087  {
6088  case GUC_SAVE:
6089  Assert(false); /* can't get here */
6090  break;
6091 
6092  case GUC_SET:
6093  /* next level always becomes SET */
6094  discard_stack_value(gconf, &stack->prior);
6095  if (prev->state == GUC_SET_LOCAL)
6096  discard_stack_value(gconf, &prev->masked);
6097  prev->state = GUC_SET;
6098  break;
6099 
6100  case GUC_LOCAL:
6101  if (prev->state == GUC_SET)
6102  {
6103  /* LOCAL migrates down */
6104  prev->masked_scontext = stack->scontext;
6105  prev->masked = stack->prior;
6106  prev->state = GUC_SET_LOCAL;
6107  }
6108  else
6109  {
6110  /* else just forget this stack level */
6111  discard_stack_value(gconf, &stack->prior);
6112  }
6113  break;
6114 
6115  case GUC_SET_LOCAL:
6116  /* prior state at this level no longer wanted */
6117  discard_stack_value(gconf, &stack->prior);
6118  /* copy down the masked state */
6119  prev->masked_scontext = stack->masked_scontext;
6120  if (prev->state == GUC_SET_LOCAL)
6121  discard_stack_value(gconf, &prev->masked);
6122  prev->masked = stack->masked;
6123  prev->state = GUC_SET_LOCAL;
6124  break;
6125  }
6126  }
6127 
6128  changed = false;
6129 
6130  if (restorePrior || restoreMasked)
6131  {
6132  /* Perform appropriate restoration of the stacked value */
6133  config_var_value newvalue;
6134  GucSource newsource;
6135  GucContext newscontext;
6136 
6137  if (restoreMasked)
6138  {
6139  newvalue = stack->masked;
6140  newsource = PGC_S_SESSION;
6141  newscontext = stack->masked_scontext;
6142  }
6143  else
6144  {
6145  newvalue = stack->prior;
6146  newsource = stack->source;
6147  newscontext = stack->scontext;
6148  }
6149 
6150  switch (gconf->vartype)
6151  {
6152  case PGC_BOOL:
6153  {
6154  struct config_bool *conf = (struct config_bool *) gconf;
6155  bool newval = newvalue.val.boolval;
6156  void *newextra = newvalue.extra;
6157 
6158  if (*conf->variable != newval ||
6159  conf->gen.extra != newextra)
6160  {
6161  if (conf->assign_hook)
6162  conf->assign_hook(newval, newextra);
6163  *conf->variable = newval;
6164  set_extra_field(&conf->gen, &conf->gen.extra,
6165  newextra);
6166  changed = true;
6167  }
6168  break;
6169  }
6170  case PGC_INT:
6171  {
6172  struct config_int *conf = (struct config_int *) gconf;
6173  int newval = newvalue.val.intval;
6174  void *newextra = newvalue.extra;
6175 
6176  if (*conf->variable != newval ||
6177  conf->gen.extra != newextra)
6178  {
6179  if (conf->assign_hook)
6180  conf->assign_hook(newval, newextra);
6181  *conf->variable = newval;
6182  set_extra_field(&conf->gen, &conf->gen.extra,
6183  newextra);
6184  changed = true;
6185  }
6186  break;
6187  }
6188  case PGC_REAL:
6189  {
6190  struct config_real *conf = (struct config_real *) gconf;
6191  double newval = newvalue.val.realval;
6192  void *newextra = newvalue.extra;
6193 
6194  if (*conf->variable != newval ||
6195  conf->gen.extra != newextra)
6196  {
6197  if (conf->assign_hook)
6198  conf->assign_hook(newval, newextra);
6199  *conf->variable = newval;
6200  set_extra_field(&conf->gen, &conf->gen.extra,
6201  newextra);
6202  changed = true;
6203  }
6204  break;
6205  }
6206  case PGC_STRING:
6207  {
6208  struct config_string *conf = (struct config_string *) gconf;
6209  char *newval = newvalue.val.stringval;
6210  void *newextra = newvalue.extra;
6211 
6212  if (*conf->variable != newval ||
6213  conf->gen.extra != newextra)
6214  {
6215  if (conf->assign_hook)
6216  conf->assign_hook(newval, newextra);
6217  set_string_field(conf, conf->variable, newval);
6218  set_extra_field(&conf->gen, &conf->gen.extra,
6219  newextra);
6220  changed = true;
6221  }
6222 
6223  /*
6224  * Release stacked values if not used anymore. We
6225  * could use discard_stack_value() here, but since
6226  * we have type-specific code anyway, might as
6227  * well inline it.
6228  */
6229  set_string_field(conf, &stack->prior.val.stringval, NULL);
6230  set_string_field(conf, &stack->masked.val.stringval, NULL);
6231  break;
6232  }
6233  case PGC_ENUM:
6234  {
6235  struct config_enum *conf = (struct config_enum *) gconf;
6236  int newval = newvalue.val.enumval;
6237  void *newextra = newvalue.extra;
6238 
6239  if (*conf->variable != newval ||
6240  conf->gen.extra != newextra)
6241  {
6242  if (conf->assign_hook)
6243  conf->assign_hook(newval, newextra);
6244  *conf->variable = newval;
6245  set_extra_field(&conf->gen, &conf->gen.extra,
6246  newextra);
6247  changed = true;
6248  }
6249  break;
6250  }
6251  }
6252 
6253  /*
6254  * Release stacked extra values if not used anymore.
6255  */
6256  set_extra_field(gconf, &(stack->prior.extra), NULL);
6257  set_extra_field(gconf, &(stack->masked.extra), NULL);
6258 
6259  /* And restore source information */
6260  gconf->source = newsource;
6261  gconf->scontext = newscontext;
6262  }
6263 
6264  /* Finish popping the state stack */
6265  gconf->stack = prev;
6266  pfree(stack);
6267 
6268  /* Report new value if we changed it */
6269  if (changed && (gconf->flags & GUC_REPORT))
6270  {
6271  gconf->status |= GUC_NEEDS_REPORT;
6272  report_needed = true;
6273  }
6274  } /* end of stack-popping loop */
6275 
6276  if (stack != NULL)
6277  still_dirty = true;
6278  }
6279 
6280  /* If there are no remaining stack entries, we can reset guc_dirty */
6281  guc_dirty = still_dirty;
6282 
6283  /* Update nesting level */
6284  GUCNestLevel = nestLevel - 1;
6285 }
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:4871
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:4873
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:105
int * variable
Definition: guc_tables.h:201
int * variable
Definition: guc_tables.h:247
void pfree(void *pointer)
Definition: mcxt.c:1057
static int num_guc_variables
Definition: guc.c:4861
static void discard_stack_value(struct config_generic *gconf, config_var_value *val)
Definition: guc.c:5088
GucSource source
Definition: guc_tables.h:126
static void set_extra_field(struct config_generic *gconf, void **field, void *newval)
Definition: guc.c:5034
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:209
double * variable
Definition: guc_tables.h:217
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4973
static struct config_generic ** guc_variables
Definition: guc.c:4858
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:792
#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:4867
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 5974 of file guc.c.

References elog, and WARNING.

Referenced by StartTransaction().

5975 {
5976  /*
5977  * The nest level should be 0 between transactions; if it isn't, somebody
5978  * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
5979  * throw a warning but make no other effort to clean up.
5980  */
5981  if (GUCNestLevel != 0)
5982  elog(WARNING, "GUC nest level = %d at transaction start",
5983  GUCNestLevel);
5984  GUCNestLevel = 1;
5985 }
static int GUCNestLevel
Definition: guc.c:4873
#define WARNING
Definition: elog.h:40
#define elog(elevel,...)
Definition: elog.h:228

◆ BeginReportingGUCOptions()

void BeginReportingGUCOptions ( void  )

Definition at line 6293 of file guc.c.

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

Referenced by PostgresMain().

6294 {
6295  int i;
6296 
6297  /*
6298  * Don't do anything unless talking to an interactive frontend of protocol
6299  * 3.0 or later.
6300  */
6301  if (whereToSendOutput != DestRemote ||
6303  return;
6304 
6305  reporting_enabled = true;
6306 
6307  /*
6308  * Hack for in_hot_standby: initialize with the value we're about to send.
6309  * (This could be out of date by the time we actually send it, in which
6310  * case the next ReportChangedGUCOptions call will send a duplicate
6311  * report.)
6312  */
6314 
6315  /* Transmit initial values of interesting variables */
6316  for (i = 0; i < num_guc_variables; i++)
6317  {
6318  struct config_generic *conf = guc_variables[i];
6319 
6320  if (conf->flags & GUC_REPORT)
6321  ReportGUCOption(conf);
6322  }
6323 
6324  report_needed = false;
6325 }
static bool report_needed
Definition: guc.c:4871
static bool in_hot_standby
Definition: guc.c:615
bool RecoveryInProgress(void)
Definition: xlog.c:8148
#define PG_PROTOCOL_MAJOR(v)
Definition: pqcomm.h:113
static int num_guc_variables
Definition: guc.c:4861
#define GUC_REPORT
Definition: guc.h:209
static struct config_generic ** guc_variables
Definition: guc.c:4858
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:6387
CommandDest whereToSendOutput
Definition: postgres.c:92
static bool reporting_enabled
Definition: guc.c:4869
ProtocolVersion FrontendProtocol
Definition: globals.c:28

◆ build_guc_variables()

void build_guc_variables ( void  )

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

5125 {
5126  int size_vars;
5127  int num_vars = 0;
5128  struct config_generic **guc_vars;
5129  int i;
5130 
5131  for (i = 0; ConfigureNamesBool[i].gen.name; i++)
5132  {
5133  struct config_bool *conf = &ConfigureNamesBool[i];
5134 
5135  /* Rather than requiring vartype to be filled in by hand, do this: */
5136  conf->gen.vartype = PGC_BOOL;
5137  num_vars++;
5138  }
5139 
5140  for (i = 0; ConfigureNamesInt[i].gen.name; i++)
5141  {
5142  struct config_int *conf = &ConfigureNamesInt[i];
5143 
5144  conf->gen.vartype = PGC_INT;
5145  num_vars++;
5146  }
5147 
5148  for (i = 0; ConfigureNamesReal[i].gen.name; i++)
5149  {
5150  struct config_real *conf = &ConfigureNamesReal[i];
5151 
5152  conf->gen.vartype = PGC_REAL;
5153  num_vars++;
5154  }
5155 
5156  for (i = 0; ConfigureNamesString[i].gen.name; i++)
5157  {
5158  struct config_string *conf = &ConfigureNamesString[i];
5159 
5160  conf->gen.vartype = PGC_STRING;
5161  num_vars++;
5162  }
5163 
5164  for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
5165  {
5166  struct config_enum *conf = &ConfigureNamesEnum[i];
5167 
5168  conf->gen.vartype = PGC_ENUM;
5169  num_vars++;
5170  }
5171 
5172  /*
5173  * Create table with 20% slack
5174  */
5175  size_vars = num_vars + num_vars / 4;
5176 
5177  guc_vars = (struct config_generic **)
5178  guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
5179 
5180  num_vars = 0;
5181 
5182  for (i = 0; ConfigureNamesBool[i].gen.name; i++)
5183  guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
5184 
5185  for (i = 0; ConfigureNamesInt[i].gen.name; i++)
5186  guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
5187 
5188  for (i = 0; ConfigureNamesReal[i].gen.name; i++)
5189  guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
5190 
5191  for (i = 0; ConfigureNamesString[i].gen.name; i++)
5192  guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
5193 
5194  for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
5195  guc_vars[num_vars++] = &ConfigureNamesEnum[i].gen;
5196 
5197  if (guc_variables)
5199  guc_variables = guc_vars;
5200  num_guc_variables = num_vars;
5201  size_guc_variables = size_vars;
5203  sizeof(struct config_generic *), guc_var_compare);
5204 }
static struct config_int ConfigureNamesInt[]
Definition: guc.c:2058
const char * name
Definition: guc_tables.h:149
static struct config_enum ConfigureNamesEnum[]
Definition: guc.c:4504
static struct config_bool ConfigureNamesBool[]
Definition: guc.c:931
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:5346
static int num_guc_variables
Definition: guc.c:4861
#define FATAL
Definition: elog.h:54
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:4858
enum config_type vartype
Definition: guc_tables.h:156
static int size_guc_variables
Definition: guc.c:4864
static struct config_real ConfigureNamesReal[]
Definition: guc.c:3455
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:3735
int i
#define qsort(a, b, c, d)
Definition: port.h:503
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4901
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 11106 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().

11108 {
11109  /* Quick success if no hook */
11110  if (!conf->check_hook)
11111  return true;
11112 
11113  /* Reset variables that might be set by hook */
11114  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
11115  GUC_check_errmsg_string = NULL;
11117  GUC_check_errhint_string = NULL;
11118 
11119  if (!conf->check_hook(newval, extra, source))
11120  {
11121  ereport(elevel,
11125  errmsg("invalid value for parameter \"%s\": %d",
11126  conf->gen.name, (int) *newval),
11130  errhint("%s", GUC_check_errhint_string) : 0));
11131  /* Flush any strings created in ErrorContext */
11132  FlushErrorState();
11133  return false;
11134  }
11135 
11136  return true;
11137 }
char * GUC_check_errhint_string
Definition: guc.c:147
int errhint(const char *fmt,...)
Definition: elog.c:1162
const char * name
Definition: guc_tables.h:149
int errcode(int sqlerrcode)
Definition: elog.c:704
static int GUC_check_errcode_value
Definition: guc.c:142
void FlushErrorState(void)
Definition: elog.c:1659
int errdetail_internal(const char *fmt,...)
Definition: elog.c:1075
struct config_generic gen
Definition: guc_tables.h:185
char * GUC_check_errdetail_string
Definition: guc.c:146
static int elevel
Definition: vacuumlazy.c:333
GucBoolCheckHook check_hook
Definition: guc_tables.h:189
#define ereport(elevel,...)
Definition: elog.h:155
int errmsg_internal(const char *fmt,...)
Definition: elog.c:1002
static rewind_source * source
Definition: pg_rewind.c:79
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:145
int errmsg(const char *fmt,...)
Definition: elog.c:915

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

11244 {
11245  /* Quick success if no hook */
11246  if (!conf->check_hook)
11247  return true;
11248 
11249  /* Reset variables that might be set by hook */
11250  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
11251  GUC_check_errmsg_string = NULL;
11253  GUC_check_errhint_string = NULL;
11254 
11255  if (!conf->check_hook(newval, extra, source))
11256  {
11257  ereport(elevel,
11261  errmsg("invalid value for parameter \"%s\": \"%s\"",
11262  conf->gen.name,
11267  errhint("%s", GUC_check_errhint_string) : 0));
11268  /* Flush any strings created in ErrorContext */
11269  FlushErrorState();
11270  return false;
11271  }
11272 
11273  return true;
11274 }
char * GUC_check_errhint_string
Definition: guc.c:147
GucEnumCheckHook check_hook
Definition: guc_tables.h:250
int errhint(const char *fmt,...)
Definition: elog.c:1162
const char * name
Definition: guc_tables.h:149
int errcode(int sqlerrcode)
Definition: elog.c:704
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:6779
static int GUC_check_errcode_value
Definition: guc.c:142
void FlushErrorState(void)
Definition: elog.c:1659
int errdetail_internal(const char *fmt,...)
Definition: elog.c:1075
char * GUC_check_errdetail_string
Definition: guc.c:146
static int elevel
Definition: vacuumlazy.c:333
struct config_generic gen
Definition: guc_tables.h:245
#define ereport(elevel,...)
Definition: elog.h:155
int errmsg_internal(const char *fmt,...)
Definition: elog.c:1002
static rewind_source * source
Definition: pg_rewind.c:79
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:145
int errmsg(const char *fmt,...)
Definition: elog.c:915

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

11142 {
11143  /* Quick success if no hook */
11144  if (!conf->check_hook)
11145  return true;
11146 
11147  /* Reset variables that might be set by hook */
11148  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
11149  GUC_check_errmsg_string = NULL;
11151  GUC_check_errhint_string = NULL;
11152 
11153  if (!conf->check_hook(newval, extra, source))
11154  {
11155  ereport(elevel,
11159  errmsg("invalid value for parameter \"%s\": %d",
11160  conf->gen.name, *newval),
11164  errhint("%s", GUC_check_errhint_string) : 0));
11165  /* Flush any strings created in ErrorContext */
11166  FlushErrorState();
11167  return false;
11168  }
11169 
11170  return true;
11171 }
char * GUC_check_errhint_string
Definition: guc.c:147
int errhint(const char *fmt,...)
Definition: elog.c:1162
const char * name
Definition: guc_tables.h:149
int errcode(int sqlerrcode)
Definition: elog.c:704
static int GUC_check_errcode_value
Definition: guc.c:142
GucIntCheckHook check_hook
Definition: guc_tables.h:205
void FlushErrorState(void)
Definition: elog.c:1659
int errdetail_internal(const char *fmt,...)
Definition: elog.c:1075
struct config_generic gen
Definition: guc_tables.h:199
char * GUC_check_errdetail_string
Definition: guc.c:146
static int elevel
Definition: vacuumlazy.c:333
#define ereport(elevel,...)
Definition: elog.h:155
int errmsg_internal(const char *fmt,...)
Definition: elog.c:1002
static rewind_source * source
Definition: pg_rewind.c:79
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:145
int errmsg(const char *fmt,...)
Definition: elog.c:915

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

11176 {
11177  /* Quick success if no hook */
11178  if (!conf->check_hook)
11179  return true;
11180 
11181  /* Reset variables that might be set by hook */
11182  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
11183  GUC_check_errmsg_string = NULL;
11185  GUC_check_errhint_string = NULL;
11186 
11187  if (!conf->check_hook(newval, extra, source))
11188  {
11189  ereport(elevel,
11193  errmsg("invalid value for parameter \"%s\": %g",
11194  conf->gen.name, *newval),
11198  errhint("%s", GUC_check_errhint_string) : 0));
11199  /* Flush any strings created in ErrorContext */
11200  FlushErrorState();
11201  return false;
11202  }
11203 
11204  return true;
11205 }
char * GUC_check_errhint_string
Definition: guc.c:147
int errhint(const char *fmt,...)
Definition: elog.c:1162
const char * name
Definition: guc_tables.h:149
int errcode(int sqlerrcode)
Definition: elog.c:704
static int GUC_check_errcode_value
Definition: guc.c:142
GucRealCheckHook check_hook
Definition: guc_tables.h:221
void FlushErrorState(void)
Definition: elog.c:1659
int errdetail_internal(const char *fmt,...)
Definition: elog.c:1075
char * GUC_check_errdetail_string
Definition: guc.c:146
static int elevel
Definition: vacuumlazy.c:333
#define ereport(elevel,...)
Definition: elog.h:155
int errmsg_internal(const char *fmt,...)
Definition: elog.c:1002
static rewind_source * source
Definition: pg_rewind.c:79
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:145
int errmsg(const char *fmt,...)
Definition: elog.c:915
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 11208 of file guc.c.

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

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

11210 {
11211  /* Quick success if no hook */
11212  if (!conf->check_hook)
11213  return true;
11214 
11215  /* Reset variables that might be set by hook */
11216  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
11217  GUC_check_errmsg_string = NULL;
11219  GUC_check_errhint_string = NULL;
11220 
11221  if (!conf->check_hook(newval, extra, source))
11222  {
11223  ereport(elevel,
11227  errmsg("invalid value for parameter \"%s\": \"%s\"",
11228  conf->gen.name, *newval ? *newval : ""),
11232  errhint("%s", GUC_check_errhint_string) : 0));
11233  /* Flush any strings created in ErrorContext */
11234  FlushErrorState();
11235  return false;
11236  }
11237 
11238  return true;
11239 }
char * GUC_check_errhint_string
Definition: guc.c:147
int errhint(const char *fmt,...)
Definition: elog.c:1162
const char * name
Definition: guc_tables.h:149
GucStringCheckHook check_hook
Definition: guc_tables.h:235
int errcode(int sqlerrcode)
Definition: elog.c:704
static int GUC_check_errcode_value
Definition: guc.c:142
void FlushErrorState(void)
Definition: elog.c:1659
int errdetail_internal(const char *fmt,...)
Definition: elog.c:1075
char * GUC_check_errdetail_string
Definition: guc.c:146
static int elevel
Definition: vacuumlazy.c:333
#define ereport(elevel,...)
Definition: elog.h:155
struct config_generic gen
Definition: guc_tables.h:231
int errmsg_internal(const char *fmt,...)
Definition: elog.c:1002
static rewind_source * source
Definition: pg_rewind.c:79
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:145
int errmsg(const char *fmt,...)
Definition: elog.c:915

◆ can_skip_gucvar()

static bool can_skip_gucvar ( struct config_generic gconf)
static

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

10287 {
10288  return gconf->context == PGC_POSTMASTER ||
10289  gconf->context == PGC_INTERNAL || gconf->source == PGC_S_DEFAULT ||
10290  strcmp(gconf->name, "role") == 0;
10291 }
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 11806 of file guc.c.

References pg_clean_ascii().

11807 {
11808  /* Only allow clean ASCII chars in the application name */
11810 
11811  return true;
11812 }
#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 11687 of file guc.c.

References MAX_BACKENDS, max_wal_senders, max_worker_processes, and MaxConnections.

11688 {
11689  if (MaxConnections + *newval + 1 +
11691  return false;
11692  return true;
11693 }
#define MAX_BACKENDS
Definition: postmaster.h:75
int max_wal_senders
Definition: walsender.c:121
int MaxConnections
Definition: globals.c:134
#define newval
int max_worker_processes
Definition: globals.c:135

◆ check_autovacuum_work_mem()

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

Definition at line 11705 of file guc.c.

11706 {
11707  /*
11708  * -1 indicates fallback.
11709  *
11710  * If we haven't yet changed the boot_val default of -1, just let it be.
11711  * Autovacuum will look to maintenance_work_mem instead.
11712  */
11713  if (*newval == -1)
11714  return true;
11715 
11716  /*
11717  * We clamp manually-set values to at least 1MB. Since
11718  * maintenance_work_mem is always set to at least this value, do the same
11719  * here.
11720  */
11721  if (*newval < 1024)
11722  *newval = 1024;
11723 
11724  return true;
11725 }
#define newval

◆ check_backtrace_functions()

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

Definition at line 11878 of file guc.c.

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

11879 {
11880  int newvallen = strlen(*newval);
11881  char *someval;
11882  int validlen;
11883  int i;
11884  int j;
11885 
11886  /*
11887  * Allow characters that can be C identifiers and commas as separators, as
11888  * well as some whitespace for readability.
11889  */
11890  validlen = strspn(*newval,
11891  "0123456789_"
11892  "abcdefghijklmnopqrstuvwxyz"
11893  "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
11894  ", \n\t");
11895  if (validlen != newvallen)
11896  {
11897  GUC_check_errdetail("invalid character");
11898  return false;
11899  }
11900 
11901  if (*newval[0] == '\0')
11902  {
11903  *extra = NULL;
11904  return true;
11905  }
11906 
11907  /*
11908  * Allocate space for the output and create the copy. We could discount
11909  * whitespace chars to save some memory, but it doesn't seem worth the
11910  * trouble.
11911  */
11912  someval = guc_malloc(ERROR, newvallen + 1 + 1);
11913  for (i = 0, j = 0; i < newvallen; i++)
11914  {
11915  if ((*newval)[i] == ',')
11916  someval[j++] = '\0'; /* next item */
11917  else if ((*newval)[i] == ' ' ||
11918  (*newval)[i] == '\n' ||
11919  (*newval)[i] == '\t')
11920  ; /* ignore these */
11921  else
11922  someval[j++] = (*newval)[i]; /* copy anything else */
11923  }
11924 
11925  /* two \0s end the setting */
11926  someval[j] = '\0';
11927  someval[j + 1] = '\0';
11928 
11929  *extra = someval;
11930  return true;
11931 }
#define GUC_check_errdetail
Definition: guc.h:417
#define ERROR
Definition: elog.h:45
#define newval
int i
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4901

◆ check_bonjour()

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

Definition at line 11470 of file guc.c.

References GUC_check_errmsg.

11471 {
11472 #ifndef USE_BONJOUR
11473  if (*newval)
11474  {
11475  GUC_check_errmsg("Bonjour is not supported by this build");
11476  return false;
11477  }
11478 #endif
11479  return true;
11480 }
#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 11521 of file guc.c.

References canonicalize_path().

11522 {
11523  /*
11524  * Since canonicalize_path never enlarges the string, we can just modify
11525  * newval in-place. But watch out for NULL, which is the default value
11526  * for external_pid_file.
11527  */
11528  if (*newval)
11530  return true;
11531 }
void canonicalize_path(char *path)
Definition: path.c:254
#define newval

◆ check_cluster_name()

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

Definition at line 11822 of file guc.c.

References pg_clean_ascii().

11823 {
11824  /* Only allow clean ASCII chars in the cluster name */
11826 
11827  return true;
11828 }
#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 12207 of file guc.c.

References GUC_check_errcode(), and GUC_check_errmsg.

12208 {
12209  if (*newval)
12210  {
12211  /* check the GUC's definition for an explanation */
12212  GUC_check_errcode(ERRCODE_FEATURE_NOT_SUPPORTED);
12213  GUC_check_errmsg("tables declared WITH OIDS are not supported");
12214 
12215  return false;
12216  }
12217 
12218  return true;
12219 }
#define GUC_check_errmsg
Definition: guc.h:413
void GUC_check_errcode(int sqlerrcode)
Definition: guc.c:11093
#define newval

◆ check_effective_io_concurrency()

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

Definition at line 11737 of file guc.c.

References GUC_check_errdetail.

11738 {
11739 #ifndef USE_PREFETCH
11740  if (*newval != 0)
11741  {
11742  GUC_check_errdetail("effective_io_concurrency must be set to 0 on platforms that lack posix_fadvise().");
11743  return false;
11744  }
11745 #endif /* USE_PREFETCH */
11746  return true;
11747 }
#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 11763 of file guc.c.

References GUC_check_errdetail.

11764 {
11765 #if !(defined(MAP_HUGE_MASK) && defined(MAP_HUGE_SHIFT))
11766  /* Recent enough Linux only, for now. See GetHugePageSize(). */
11767  if (*newval != 0)
11768  {
11769  GUC_check_errdetail("huge_page_size must be 0 on this platform.");
11770  return false;
11771  }
11772 #endif
11773  return true;
11774 }
#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 11362 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().

11363 {
11364  char *rawstring;
11365  List *elemlist;
11366  ListCell *l;
11367  int newlogdest = 0;
11368  int *myextra;
11369 
11370  /* Need a modifiable copy of string */
11371  rawstring = pstrdup(*newval);
11372 
11373  /* Parse string into list of identifiers */
11374  if (!SplitIdentifierString(rawstring, ',', &elemlist))
11375  {
11376  /* syntax error in list */
11377  GUC_check_errdetail("List syntax is invalid.");
11378  pfree(rawstring);
11379  list_free(elemlist);
11380  return false;
11381  }
11382 
11383  foreach(l, elemlist)
11384  {
11385  char *tok = (char *) lfirst(l);
11386 
11387  if (pg_strcasecmp(tok, "stderr") == 0)
11388  newlogdest |= LOG_DESTINATION_STDERR;
11389  else if (pg_strcasecmp(tok, "csvlog") == 0)
11390  newlogdest |= LOG_DESTINATION_CSVLOG;
11391 #ifdef HAVE_SYSLOG
11392  else if (pg_strcasecmp(tok, "syslog") == 0)
11393  newlogdest |= LOG_DESTINATION_SYSLOG;
11394 #endif
11395 #ifdef WIN32
11396  else if (pg_strcasecmp(tok, "eventlog") == 0)
11397  newlogdest |= LOG_DESTINATION_EVENTLOG;
11398 #endif
11399  else
11400  {
11401  GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
11402  pfree(rawstring);
11403  list_free(elemlist);
11404  return false;
11405  }
11406  }
11407 
11408  pfree(rawstring);
11409  list_free(elemlist);
11410 
11411  myextra = (int *) guc_malloc(ERROR, sizeof(int));
11412  *myextra = newlogdest;
11413  *extra = (void *) myextra;
11414 
11415  return true;
11416 }
#define LOG_DESTINATION_EVENTLOG
Definition: elog.h:434
#define GUC_check_errdetail
Definition: guc.h:417
char * pstrdup(const char *in)
Definition: mcxt.c:1187
#define LOG_DESTINATION_SYSLOG
Definition: elog.h:433
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
void pfree(void *pointer)
Definition: mcxt.c:1057
#define ERROR
Definition: elog.h:45
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3741
#define LOG_DESTINATION_CSVLOG
Definition: elog.h:435
#define LOG_DESTINATION_STDERR
Definition: elog.h:432
#define lfirst(lc)
Definition: pg_list.h:169
#define newval
void list_free(List *list)
Definition: list.c:1376
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4901
Definition: pg_list.h:50

◆ check_log_stats()

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

Definition at line 11507 of file guc.c.

References GUC_check_errdetail.

11508 {
11509  if (*newval &&
11511  {
11512  GUC_check_errdetail("Cannot enable \"log_statement_stats\" when "
11513  "\"log_parser_stats\", \"log_planner_stats\", "
11514  "or \"log_executor_stats\" is true.");
11515  return false;
11516  }
11517  return true;
11518 }
bool log_parser_stats
Definition: guc.c:521
#define GUC_check_errdetail
Definition: guc.h:417
#define newval
bool log_executor_stats
Definition: guc.c:523
bool log_planner_stats
Definition: guc.c:522

◆ check_maintenance_io_concurrency()

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

Definition at line 11750 of file guc.c.

References GUC_check_errdetail.

11751 {
11752 #ifndef USE_PREFETCH
11753  if (*newval != 0)
11754  {
11755  GUC_check_errdetail("maintenance_io_concurrency must be set to 0 on platforms that lack posix_fadvise().");
11756  return false;
11757  }
11758 #endif /* USE_PREFETCH */
11759  return true;
11760 }
#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 11696 of file guc.c.

References autovacuum_max_workers, MAX_BACKENDS, max_worker_processes, and MaxConnections.

11697 {
11700  return false;
11701  return true;
11702 }
#define MAX_BACKENDS
Definition: postmaster.h:75
int MaxConnections
Definition: globals.c:134
int autovacuum_max_workers
Definition: autovacuum.c:115
#define newval
int max_worker_processes
Definition: globals.c:135

◆ check_max_worker_processes()

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

Definition at line 11728 of file guc.c.

References autovacuum_max_workers, MAX_BACKENDS, max_wal_senders, and MaxConnections.

11729 {
11732  return false;
11733  return true;
11734 }
#define MAX_BACKENDS
Definition: postmaster.h:75
int max_wal_senders
Definition: walsender.c:121
int MaxConnections
Definition: globals.c:134
int autovacuum_max_workers
Definition: autovacuum.c:115
#define newval

◆ check_maxconnections()

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

Definition at line 11678 of file guc.c.

References autovacuum_max_workers, MAX_BACKENDS, max_wal_senders, and max_worker_processes.

11679 {
11680  if (*newval + autovacuum_max_workers + 1 +
11682  return false;
11683  return true;
11684 }
#define MAX_BACKENDS
Definition: postmaster.h:75
int max_wal_senders
Definition: walsender.c:121
int autovacuum_max_workers
Definition: autovacuum.c:115
#define newval
int max_worker_processes
Definition: globals.c:135

◆ check_primary_slot_name()

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

Definition at line 12197 of file guc.c.

References ReplicationSlotValidateName(), and WARNING.

12198 {
12199  if (*newval && strcmp(*newval, "") != 0 &&
12201  return false;
12202 
12203  return true;
12204 }
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 12002 of file guc.c.

References GUC_check_errdetail.

12003 {
12004  if (strcmp(*newval, "immediate") != 0 && strcmp(*newval, "") != 0)
12005  {
12006  GUC_check_errdetail("The only allowed value is \"immediate\".");
12007  return false;
12008  }
12009  return true;
12010 }
#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 12161 of file guc.c.

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

12162 {
12163  if (strcmp(*newval, "") != 0)
12164  {
12165  XLogRecPtr lsn;
12166  XLogRecPtr *myextra;
12167  bool have_error = false;
12168 
12169  lsn = pg_lsn_in_internal(*newval, &have_error);
12170  if (have_error)
12171  return false;
12172 
12173  myextra = (XLogRecPtr *) guc_malloc(ERROR, sizeof(XLogRecPtr));
12174  *myextra = lsn;
12175  *extra = (void *) myextra;
12176  }
12177  return true;
12178 }
#define ERROR
Definition: elog.h:45
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:4901

◆ check_recovery_target_name()

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

Definition at line 12132 of file guc.c.

References GUC_check_errdetail, and MAXFNAMELEN.

12133 {
12134  /* Use the value of newval directly */
12135  if (strlen(*newval) >= MAXFNAMELEN)
12136  {
12137  GUC_check_errdetail("%s is too long (maximum %d characters).",
12138  "recovery_target_name", MAXFNAMELEN - 1);
12139  return false;
12140  }
12141  return true;
12142 }
#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 12069 of file guc.c.

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

12070 {
12071  if (strcmp(*newval, "") != 0)
12072  {
12073  /* reject some special values */
12074  if (strcmp(*newval, "now") == 0 ||
12075  strcmp(*newval, "today") == 0 ||
12076  strcmp(*newval, "tomorrow") == 0 ||
12077  strcmp(*newval, "yesterday") == 0)
12078  {
12079  return false;
12080  }
12081 
12082  /*
12083  * parse timestamp value (see also timestamptz_in())
12084  */
12085  {
12086  char *str = *newval;
12087  fsec_t fsec;
12088  struct pg_tm tt,
12089  *tm = &tt;
12090  int tz;
12091  int dtype;
12092  int nf;
12093  int dterr;
12094  char *field[MAXDATEFIELDS];
12095  int ftype[MAXDATEFIELDS];
12096  char workbuf[MAXDATELEN + MAXDATEFIELDS];
12098 
12099  dterr = ParseDateTime(str, workbuf, sizeof(workbuf),
12100  field, ftype, MAXDATEFIELDS, &nf);
12101  if (dterr == 0)
12102  dterr = DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tz);
12103  if (dterr != 0)
12104  return false;
12105  if (dtype != DTK_DATE)
12106  return false;
12107 
12108  if (tm2timestamp(tm, fsec, &tz, &timestamp) != 0)
12109  {
12110  GUC_check_errdetail("timestamp out of range: \"%s\"", str);
12111  return false;
12112  }
12113  }
12114  }
12115  return true;
12116 }
#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:1916
#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 11940 of file guc.c.

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

11941 {
11943  RecoveryTargetTimeLineGoal *myextra;
11944 
11945  if (strcmp(*newval, "current") == 0)
11947  else if (strcmp(*newval, "latest") == 0)
11949  else
11950  {
11952 
11953  errno = 0;
11954  strtoul(*newval, NULL, 0);
11955  if (errno == EINVAL || errno == ERANGE)
11956  {
11957  GUC_check_errdetail("recovery_target_timeline is not a valid number.");
11958  return false;
11959  }
11960  }
11961 
11963  *myextra = rttg;
11964  *extra = (void *) myextra;
11965 
11966  return true;
11967 }
#define GUC_check_errdetail
Definition: guc.h:417
RecoveryTargetTimeLineGoal
Definition: xlog.h:93
#define ERROR
Definition: elog.h:45
#define newval
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4901

◆ check_recovery_target_xid()

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

Definition at line 12026 of file guc.c.

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

12027 {
12028  if (strcmp(*newval, "") != 0)
12029  {
12030  TransactionId xid;
12031  TransactionId *myextra;
12032 
12033  errno = 0;
12034  xid = (TransactionId) pg_strtouint64(*newval, NULL, 0);
12035  if (errno == EINVAL || errno == ERANGE)
12036  return false;
12037 
12038  myextra = (TransactionId *) guc_malloc(ERROR, sizeof(TransactionId));
12039  *myextra = xid;
12040  *extra = (void *) myextra;
12041  }
12042  return true;
12043 }
uint32 TransactionId
Definition: c.h:575
#define ERROR
Definition: elog.h:45
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:4901

◆ check_ssl()

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

Definition at line 11483 of file guc.c.

References GUC_check_errmsg.

11484 {
11485 #ifndef USE_SSL
11486  if (*newval)
11487  {
11488  GUC_check_errmsg("SSL is not supported by this build");
11489  return false;
11490  }
11491 #endif
11492  return true;
11493 }
#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 11496 of file guc.c.

References GUC_check_errdetail.

11497 {
11498  if (*newval && log_statement_stats)
11499  {
11500  GUC_check_errdetail("Cannot enable parameter when \"log_statement_stats\" is true.");
11501  return false;
11502  }
11503  return true;
11504 }
bool log_statement_stats
Definition: guc.c:524
#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 11456 of file guc.c.

References GUC_check_errdetail, and NLocBuffer.

11457 {
11458  /*
11459  * Once local buffers have been initialized, it's too late to change this.
11460  */
11461  if (NLocBuffer && NLocBuffer != *newval)
11462  {
11463  GUC_check_errdetail("\"temp_buffers\" cannot be changed after any temporary tables have been accessed in the session.");
11464  return false;
11465  }
11466  return true;
11467 }
#define GUC_check_errdetail
Definition: guc.h:417
int NLocBuffer
Definition: localbuf.c:41
#define newval

◆ check_timezone_abbreviations()

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

Definition at line 11534 of file guc.c.

References Assert, load_tzoffsets(), and PGC_S_DEFAULT.

11535 {
11536  /*
11537  * The boot_val given above for timezone_abbreviations is NULL. When we
11538  * see this we just do nothing. If this value isn't overridden from the
11539  * config file then pg_timezone_abbrev_initialize() will eventually
11540  * replace it with "Default". This hack has two purposes: to avoid
11541  * wasting cycles loading values that might soon be overridden from the
11542  * config file, and to avoid trying to read the timezone abbrev files
11543  * during InitializeGUCOptions(). The latter doesn't work in an
11544  * EXEC_BACKEND subprocess because my_exec_path hasn't been set yet and so
11545  * we can't locate PGSHAREDIR.
11546  */
11547  if (*newval == NULL)
11548  {
11550  return true;
11551  }
11552 
11553  /* OK, load the file and produce a malloc'd TimeZoneAbbrevTable */
11554  *extra = load_tzoffsets(*newval);
11555 
11556  /* tzparser.c returns NULL on failure, reporting via GUC_check_errmsg */
11557  if (!*extra)
11558  return false;
11559 
11560  return true;
11561 }
TimeZoneAbbrevTable * load_tzoffsets(const char *filename)
Definition: tzparser.c:437
#define Assert(condition)
Definition: c.h:792
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 11282 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().

11283 {
11284  char *rawstring;
11285  List *elemlist;
11286  ListCell *l;
11287  bool newwalconsistency[RM_MAX_ID + 1];
11288 
11289  /* Initialize the array */
11290  MemSet(newwalconsistency, 0, (RM_MAX_ID + 1) * sizeof(bool));
11291 
11292  /* Need a modifiable copy of string */
11293  rawstring = pstrdup(*newval);
11294 
11295  /* Parse string into list of identifiers */
11296  if (!SplitIdentifierString(rawstring, ',', &elemlist))
11297  {
11298  /* syntax error in list */
11299  GUC_check_errdetail("List syntax is invalid.");
11300  pfree(rawstring);
11301  list_free(elemlist);
11302  return false;
11303  }
11304 
11305  foreach(l, elemlist)
11306  {
11307  char *tok = (char *) lfirst(l);
11308  bool found = false;
11309  RmgrId rmid;
11310 
11311  /* Check for 'all'. */
11312  if (pg_strcasecmp(tok, "all") == 0)
11313  {
11314  for (rmid = 0; rmid <= RM_MAX_ID; rmid++)
11315  if (RmgrTable[rmid].rm_mask != NULL)
11316  newwalconsistency[rmid] = true;
11317  found = true;
11318  }
11319  else
11320  {
11321  /*
11322  * Check if the token matches with any individual resource
11323  * manager.
11324  */
11325  for (rmid = 0; rmid <= RM_MAX_ID; rmid++)
11326  {
11327  if (pg_strcasecmp(tok, RmgrTable[rmid].rm_name) == 0 &&
11328  RmgrTable[rmid].rm_mask != NULL)
11329  {
11330  newwalconsistency[rmid] = true;
11331  found = true;
11332  }
11333  }
11334  }
11335 
11336  /* If a valid resource manager is found, check for the next one. */
11337  if (!found)
11338  {
11339  GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
11340  pfree(rawstring);
11341  list_free(elemlist);
11342  return false;
11343  }
11344  }
11345 
11346  pfree(rawstring);
11347  list_free(elemlist);
11348 
11349  /* assign new value */
11350  *extra = guc_malloc(ERROR, (RM_MAX_ID + 1) * sizeof(bool));
11351  memcpy(*extra, newwalconsistency, (RM_MAX_ID + 1) * sizeof(bool));
11352  return true;
11353 }
#define GUC_check_errdetail
Definition: guc.h:417
char * pstrdup(const char *in)
Definition: mcxt.c:1187
const RmgrData RmgrTable[RM_MAX_ID+1]
Definition: rmgr.c:36
#define MemSet(start, val, len)
Definition: c.h:996
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
void pfree(void *pointer)
Definition: mcxt.c:1057
#define ERROR
Definition: elog.h:45
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3741
#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:1376
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4901
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 6828 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().

6830 {
6831  const struct config_enum_entry *entry;
6832  StringInfoData retstr;
6833  int seplen;
6834 
6835  initStringInfo(&retstr);
6836  appendStringInfoString(&retstr, prefix);
6837 
6838  seplen = strlen(separator);
6839  for (entry = record->options; entry && entry->name; entry++)
6840  {
6841  if (!entry->hidden)
6842  {
6843  appendStringInfoString(&retstr, entry->name);
6844  appendBinaryStringInfo(&retstr, separator, seplen);
6845  }
6846  }
6847 
6848  /*
6849  * All the entries may have been hidden, leaving the string empty if no
6850  * prefix was given. This indicates a broken GUC setup, since there is no
6851  * use for an enum without any values, so we just check to make sure we
6852  * don't write to invalid memory instead of actually trying to do
6853  * something smart with it.
6854  */
6855  if (retstr.len >= seplen)
6856  {
6857  /* Replace final separator */
6858  retstr.data[retstr.len - seplen] = '\0';
6859  retstr.len -= seplen;
6860  }
6861 
6862  appendStringInfoString(&retstr, suffix);
6863 
6864  return retstr.data;
6865 }
Definition: guc.h:165
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:167
void appendBinaryStringInfo(StringInfo str, const char *data, int datalen)
Definition: stringinfo.c:227
bool hidden
Definition: guc.h:169

◆ config_enum_lookup_by_name()

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

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

6804 {
6805  const struct config_enum_entry *entry;
6806 
6807  for (entry = record->options; entry && entry->name; entry++)
6808  {
6809  if (pg_strcasecmp(value, entry->name) == 0)
6810  {
6811  *retval = entry->val;
6812  return true;
6813  }
6814  }
6815 
6816  *retval = 0;
6817  return false;
6818 }
Definition: guc.h:165
static struct @144 value
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:168
const char * name
Definition: guc.h:167

◆ config_enum_lookup_by_value()

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

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

6780 {
6781  const struct config_enum_entry *entry;
6782 
6783  for (entry = record->options; entry && entry->name; entry++)
6784  {
6785  if (entry->val == val)
6786  return entry->name;
6787  }
6788 
6789  elog(ERROR, "could not find enum option %d for %s",
6790  val, record->gen.name);
6791  return NULL; /* silence compiler */
6792 }
Definition: guc.h:165
const char * name
Definition: guc_tables.h:149
#define ERROR
Definition: elog.h:45
const struct config_enum_entry * options
Definition: guc_tables.h:249
int val
Definition: guc.h:168
struct config_generic gen
Definition: guc_tables.h:245
const char * name
Definition: guc.h:167
#define elog(elevel,...)
Definition: elog.h:228
long val
Definition: informix.c:664

◆ convert_int_from_base_unit()

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

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

6487 {
6488  const unit_conversion *table;
6489  int i;
6490 
6491  *unit = NULL;
6492 
6493  if (base_unit & GUC_UNIT_MEMORY)
6495  else
6497 
6498  for (i = 0; *table[i].unit; i++)
6499  {
6500  if (base_unit == table[i].base_unit)
6501  {
6502  /*
6503  * Accept the first conversion that divides the value evenly. We
6504  * assume that the conversions for each base unit are ordered from
6505  * greatest unit to the smallest!
6506  */
6507  if (table[i].multiplier <= 1.0 ||
6508  base_value % (int64) table[i].multiplier == 0)
6509  {
6510  *value = (int64) rint(base_value / table[i].multiplier);
6511  *unit = table[i].unit;
6512  break;
6513  }
6514  }
6515  }
6516 
6517  Assert(*unit != NULL);
6518 }
static const unit_conversion time_unit_conversion_table[]
Definition: guc.c:875
static const unit_conversion memory_unit_conversion_table[]
Definition: guc.c:838
static struct @144 value
#define Assert(condition)
Definition: c.h:792
int i
char unit[MAX_UNIT_LEN+1]
Definition: guc.c:822
#define GUC_UNIT_MEMORY
Definition: guc.h:224

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

6529 {
6530  const unit_conversion *table;
6531  int i;
6532 
6533  *unit = NULL;
6534 
6535  if (base_unit & GUC_UNIT_MEMORY)
6537  else
6539 
6540  for (i = 0; *table[i].unit; i++)
6541  {
6542  if (base_unit == table[i].base_unit)
6543  {
6544  /*
6545  * Accept the first conversion that divides the value evenly; or
6546  * if there is none, use the smallest (last) target unit.
6547  *
6548  * What we actually care about here is whether snprintf with "%g"
6549  * will print the value as an integer, so the obvious test of
6550  * "*value == rint(*value)" is too strict; roundoff error might
6551  * make us choose an unreasonably small unit. As a compromise,
6552  * accept a divisor that is within 1e-8 of producing an integer.
6553  */
6554  *value = base_value / table[i].multiplier;
6555  *unit = table[i].unit;
6556  if (*value > 0 &&
6557  fabs((rint(*value) / *value) - 1.0) <= 1e-8)
6558  break;
6559  }
6560  }
6561 
6562  Assert(*unit != NULL);
6563 }
static const unit_conversion time_unit_conversion_table[]
Definition: guc.c:875
static const unit_conversion memory_unit_conversion_table[]
Definition: guc.c:838
static struct @144 value
#define Assert(condition)
Definition: c.h:792
double multiplier
Definition: guc.c:825
e
Definition: preproc-init.c:82
int i
char unit[MAX_UNIT_LEN+1]
Definition: guc.c:822
#define GUC_UNIT_MEMORY
Definition: guc.h:224

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

6429 {
6430  char unitstr[MAX_UNIT_LEN + 1];
6431  int unitlen;
6432  const unit_conversion *table;
6433  int i;
6434 
6435  /* extract unit string to compare to table entries */
6436  unitlen = 0;
6437  while (*unit != '\0' && !isspace((unsigned char) *unit) &&
6438  unitlen < MAX_UNIT_LEN)
6439  unitstr[unitlen++] = *(unit++);
6440  unitstr[unitlen] = '\0';
6441  /* allow whitespace after unit */
6442  while (isspace((unsigned char) *unit))
6443  unit++;
6444  if (*unit != '\0')
6445  return false; /* unit too long, or garbage after it */
6446 
6447  /* now search the appropriate table */
6448  if (base_unit & GUC_UNIT_MEMORY)
6450  else
6452 
6453  for (i = 0; *table[i].unit; i++)
6454  {
6455  if (base_unit == table[i].base_unit &&
6456  strcmp(unitstr, table[i].unit) == 0)
6457  {
6458  double cvalue = value * table[i].multiplier;
6459 
6460  /*
6461  * If the user gave a fractional value such as "30.1GB", round it
6462  * off to the nearest multiple of the next smaller unit, if there
6463  * is one.
6464  */
6465  if (*table[i + 1].unit &&
6466  base_unit == table[i + 1].base_unit)
6467  cvalue = rint(cvalue / table[i + 1].multiplier) *
6468  table[i + 1].multiplier;
6469 
6470  *base_value = cvalue;
6471  return true;
6472  }
6473  }
6474  return false;
6475 }
static const unit_conversion time_unit_conversion_table[]
Definition: guc.c:875
static const unit_conversion memory_unit_conversion_table[]
Definition: guc.c:838
#define MAX_UNIT_LEN
Definition: guc.c:818
static struct @144 value
double multiplier
Definition: guc.c:825
int i
char unit[MAX_UNIT_LEN+1]
Definition: guc.c:822
#define GUC_UNIT_MEMORY
Definition: guc.h:224

◆ define_custom_variable()

static void define_custom_variable ( struct config_generic variable)
static

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

8785 {
8786  const char *name = variable->name;
8787  const char **nameAddr = &name;
8788  struct config_string *pHolder;
8789  struct config_generic **res;
8790 
8791  /*
8792  * See if there's a placeholder by the same name.
8793  */
8794  res = (struct config_generic **) bsearch((void *) &nameAddr,
8795  (void *) guc_variables,
8797  sizeof(struct config_generic *),
8798  guc_var_compare);
8799  if (res == NULL)
8800  {
8801  /*
8802  * No placeholder to replace, so we can just add it ... but first,
8803  * make sure it's initialized to its default value.
8804  */
8805  InitializeOneGUCOption(variable);
8806  add_guc_variable(variable, ERROR);
8807  return;
8808  }
8809 
8810  /*
8811  * This better be a placeholder
8812  */
8813  if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
8814  ereport(ERROR,
8815  (errcode(ERRCODE_INTERNAL_ERROR),
8816  errmsg("attempt to redefine parameter \"%s\"", name)));
8817 
8818  Assert((*res)->vartype == PGC_STRING);
8819  pHolder = (struct config_string *) (*res);
8820 
8821  /*
8822  * First, set the variable to its default value. We must do this even
8823  * though we intend to immediately apply a new value, since it's possible
8824  * that the new value is invalid.
8825  */
8826  InitializeOneGUCOption(variable);
8827 
8828  /*
8829  * Replace the placeholder. We aren't changing the name, so no re-sorting
8830  * is necessary
8831  */
8832  *res = variable;
8833 
8834  /*
8835  * Assign the string value(s) stored in the placeholder to the real
8836  * variable. Essentially, we need to duplicate all the active and stacked
8837  * values, but with appropriate validation and datatype adjustment.
8838  *
8839  * If an assignment fails, we report a WARNING and keep going. We don't
8840  * want to throw ERROR for bad values, because it'd bollix the add-on
8841  * module that's presumably halfway through getting loaded. In such cases
8842  * the default or previous state will become active instead.
8843  */
8844 
8845  /* First, apply the reset value if any */
8846  if (pHolder->reset_val)
8847  (void) set_config_option(name, pHolder->reset_val,
8848  pHolder->gen.reset_scontext,
8849  pHolder->gen.reset_source,
8850  GUC_ACTION_SET, true, WARNING, false);
8851  /* That should not have resulted in stacking anything */
8852  Assert(variable->stack == NULL);
8853 
8854  /* Now, apply current and stacked values, in the order they were stacked */
8855  reapply_stacked_values(variable, pHolder, pHolder->gen.stack,
8856  *(pHolder->variable),
8857  pHolder->gen.scontext, pHolder->gen.source);
8858 
8859  /* Also copy over any saved source-location information */
8860  if (pHolder->gen.sourcefile)
8861  set_config_sourcefile(name, pHolder->gen.sourcefile,
8862  pHolder->gen.sourceline);
8863 
8864  /*
8865  * Free up as much as we conveniently can of the placeholder structure.
8866  * (This neglects any stack items, so it's possible for some memory to be
8867  * leaked. Since this can only happen once per session per variable, it
8868  * doesn't seem worth spending much code on.)
8869  */
8870  set_string_field(pHolder, pHolder->variable, NULL);
8871  set_string_field(pHolder, &pHolder->reset_val, NULL);
8872 
8873  free(pHolder);
8874 }
GucSource source
Definition: guc_tables.h:158
static void static void set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
Definition: guc.c:7845
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:8884
int errcode(int sqlerrcode)
Definition: elog.c:704
GucContext scontext
Definition: guc_tables.h:160
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:5346
#define ERROR
Definition: elog.h:45
static int num_guc_variables
Definition: guc.c:4861
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:5494
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4973
static struct config_generic ** guc_variables
Definition: guc.c:4858
#define WARNING
Definition: elog.h:40
#define ereport(elevel,...)
Definition: elog.h:155
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:792
#define GUC_CUSTOM_PLACEHOLDER
Definition: guc.h:212
const char * name
Definition: encode.c:515
int errmsg(const char *fmt,...)
Definition: elog.c:915
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:7083
static bool add_guc_variable(struct config_generic *var, int elevel)
Definition: guc.c:5211
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 8965 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().

8975 {
8976  struct config_bool *var;
8977 
8978  var = (struct config_bool *)
8979  init_custom_variable(name, short_desc, long_desc, context, flags,
8980  PGC_BOOL, sizeof(struct config_bool));
8981  var->variable = valueAddr;
8982  var->boot_val = bootValue;
8983  var->reset_val = bootValue;
8984  var->check_hook = check_hook;
8985  var->assign_hook = assign_hook;
8986  var->show_hook = show_hook;
8987  define_custom_variable(&var->gen);
8988 }
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:8724
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:8784

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

9087 {
9088  struct config_enum *var;
9089 
9090  var = (struct config_enum *)
9091  init_custom_variable(name, short_desc, long_desc, context, flags,
9092  PGC_ENUM, sizeof(struct config_enum));
9093  var->variable = valueAddr;
9094  var->boot_val = bootValue;
9095  var->reset_val = bootValue;
9096  var->options = options;
9097  var->check_hook = check_hook;
9098  var->assign_hook = assign_hook;
9099  var->show_hook = show_hook;
9100  define_custom_variable(&var->gen);
9101 }
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:8724
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:8784

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

9003 {
9004  struct config_int *var;
9005 
9006  var = (struct config_int *)
9007  init_custom_variable(name, short_desc, long_desc, context, flags,
9008  PGC_INT, sizeof(struct config_int));
9009  var->variable = valueAddr;
9010  var->boot_val = bootValue;
9011  var->reset_val = bootValue;
9012  var->min = minValue;
9013  var->max = maxValue;
9014  var->check_hook = check_hook;
9015  var->assign_hook = assign_hook;
9016  var->show_hook = show_hook;
9017  define_custom_variable(&var->gen);
9018 }
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:8724
const char * name
Definition: encode.c:515
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8784
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 9021 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().

9033 {
9034  struct config_real *var;
9035 
9036  var = (struct config_real *)
9037  init_custom_variable(name, short_desc, long_desc, context, flags,
9038  PGC_REAL, sizeof(struct config_real));
9039  var->variable = valueAddr;
9040  var->boot_val = bootValue;
9041  var->reset_val = bootValue;
9042  var->min = minValue;
9043  var->max = maxValue;
9044  var->check_hook = check_hook;
9045  var->assign_hook = assign_hook;
9046  var->show_hook = show_hook;
9047  define_custom_variable(&var->gen);
9048 }
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:8724
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:8784
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 9051 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().

9061 {
9062  struct config_string *var;
9063 
9064  var = (struct config_string *)
9065  init_custom_variable(name, short_desc, long_desc, context, flags,
9066  PGC_STRING, sizeof(struct config_string));
9067  var->variable = valueAddr;
9068  var->boot_val = bootValue;
9069  var->check_hook = check_hook;
9070  var->assign_hook = assign_hook;
9071  var->show_hook = show_hook;
9072  define_custom_variable(&var->gen);
9073 }
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:8724
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:8784

◆ discard_stack_value()

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

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

5089 {
5090  switch (gconf->vartype)
5091  {
5092  case PGC_BOOL:
5093  case PGC_INT:
5094  case PGC_REAL:
5095  case PGC_ENUM:
5096  /* no need to do anything */
5097  break;
5098  case PGC_STRING:
5099  set_string_field((struct config_string *) gconf,
5100  &(val->val.stringval),
5101  NULL);
5102  break;
5103  }
5104  set_extra_field(gconf, &(val->extra), NULL);
5105 }
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:5034
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4973
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 10421 of file guc.c.

References elog, ERROR, and vsnprintf.

Referenced by serialize_variable().

10422 {
10423  va_list vargs;
10424  int n;
10425 
10426  if (*maxbytes <= 0)
10427  elog(ERROR, "not enough space to serialize GUC state");
10428 
10429  va_start(vargs, fmt);
10430  n = vsnprintf(*destptr, *maxbytes, fmt, vargs);
10431  va_end(vargs);
10432 
10433  if (n < 0)
10434  {
10435  /* Shouldn't happen. Better show errno description. */
10436  elog(ERROR, "vsnprintf failed: %m with format string \"%s\"", fmt);
10437  }
10438  if (n >= *maxbytes)
10439  {
10440  /* This shouldn't happen either, really. */
10441  elog(ERROR, "not enough space to serialize GUC state");
10442  }
10443 
10444  /* Shift the destptr ahead of the null terminator */
10445  *destptr += n + 1;
10446  *maxbytes -= n + 1;
10447 }
#define ERROR
Definition: elog.h:45
#define vsnprintf
Definition: port.h:214
#define elog(elevel,...)
Definition: elog.h:228

◆ do_serialize_binary()

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

Definition at line 10451 of file guc.c.

References elog, and ERROR.

Referenced by serialize_variable().

10452 {
10453  if (valsize > *maxbytes)
10454  elog(ERROR, "not enough space to serialize GUC state");
10455 
10456  memcpy(*destptr, val, valsize);
10457  *destptr += valsize;
10458  *maxbytes -= valsize;
10459 }
#define ERROR
Definition: elog.h:45
#define elog(elevel,...)
Definition: elog.h:228
long val
Definition: informix.c:664

◆ EmitWarningsOnPlaceholders()

void EmitWarningsOnPlaceholders ( const char *  className)

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

9105 {
9106  int classLen = strlen(className);
9107  int i;
9108 
9109  for (i = 0; i < num_guc_variables; i++)
9110  {
9111  struct config_generic *var = guc_variables[i];
9112 
9113  if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
9114  strncmp(className, var->name, classLen) == 0 &&
9115  var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
9116  {
9117  ereport(WARNING,
9118  (errcode(ERRCODE_UNDEFINED_OBJECT),
9119  errmsg("unrecognized configuration parameter \"%s\"",
9120  var->name)));
9121  }
9122  }
9123 }
const char * name
Definition: guc_tables.h:149
int errcode(int sqlerrcode)
Definition: elog.c:704
#define GUC_QUALIFIER_SEPARATOR
Definition: guc.h:200
static int num_guc_variables
Definition: guc.c:4861
static struct config_generic ** guc_variables
Definition: guc.c:4858
#define WARNING
Definition: elog.h:40
#define ereport(elevel,...)
Definition: elog.h:155
#define GUC_CUSTOM_PLACEHOLDER
Definition: guc.h:212
int errmsg(const char *fmt,...)
Definition: elog.c:915
int i

◆ estimate_variable_size()

static Size estimate_variable_size ( struct config_generic gconf)
static

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

10301 {
10302  Size size;
10303  Size valsize = 0;
10304 
10305  if (can_skip_gucvar(gconf))
10306  return 0;
10307 
10308  /* Name, plus trailing zero byte. */
10309  size = strlen(gconf->name) + 1;
10310 
10311  /* Get the maximum display length of the GUC value. */
10312  switch (gconf->vartype)
10313  {
10314  case PGC_BOOL:
10315  {
10316  valsize = 5; /* max(strlen('true'), strlen('false')) */
10317  }
10318  break;
10319 
10320  case PGC_INT:
10321  {
10322  struct config_int *conf = (struct config_int *) gconf;
10323 
10324  /*
10325  * Instead of getting the exact display length, use max
10326  * length. Also reduce the max length for typical ranges of
10327  * small values. Maximum value is 2147483647, i.e. 10 chars.
10328  * Include one byte for sign.
10329  */
10330  if (Abs(*conf->variable) < 1000)
10331  valsize = 3 + 1;
10332  else
10333  valsize = 10 + 1;
10334  }
10335  break;
10336 
10337  case PGC_REAL:
10338  {
10339  /*
10340  * We are going to print it with %e with REALTYPE_PRECISION
10341  * fractional digits. Account for sign, leading digit,
10342  * decimal point, and exponent with up to 3 digits. E.g.
10343  * -3.99329042340000021e+110
10344  */
10345  valsize = 1 + 1 + 1 + REALTYPE_PRECISION + 5;
10346  }
10347  break;
10348 
10349  case PGC_STRING:
10350  {
10351  struct config_string *conf = (struct config_string *) gconf;
10352 
10353  /*
10354  * If the value is NULL, we transmit it as an empty string.
10355  * Although this is not physically the same value, GUC
10356  * generally treats a NULL the same as empty string.
10357  */
10358  if (*conf->variable)
10359  valsize = strlen(*conf->variable);
10360  else
10361  valsize = 0;
10362  }
10363  break;
10364 
10365  case PGC_ENUM:
10366  {
10367  struct config_enum *conf = (struct config_enum *) gconf;
10368 
10369  valsize = strlen(config_enum_lookup_by_value(conf, *conf->variable));
10370  }
10371  break;
10372  }
10373 
10374  /* Allow space for terminating zero-byte for value */
10375  size = add_size(size, valsize + 1);
10376 
10377  if (gconf->sourcefile)
10378  size = add_size(size, strlen(gconf->sourcefile));
10379 
10380  /* Allow space for terminating zero-byte for sourcefile */
10381  size = add_size(size, 1);
10382 
10383  /* Include line whenever file is nonempty. */
10384  if (gconf->sourcefile && gconf->sourcefile[0])
10385  size = add_size(size, sizeof(gconf->sourceline));
10386 
10387  size = add_size(size, sizeof(gconf->source));
10388  size = add_size(size, sizeof(gconf->scontext));
10389 
10390  return size;
10391 }
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:6779
GucContext scontext
Definition: guc_tables.h:160
#define Abs(x)
Definition: c.h:980
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:10286
#define REALTYPE_PRECISION
Definition: guc.c:123
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:528

◆ EstimateGUCStateSpace()

Size EstimateGUCStateSpace ( void  )

Definition at line 10398 of file guc.c.

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

Referenced by InitializeParallelDSM().

10399 {
10400  Size size;
10401  int i;
10402 
10403  /* Add space reqd for saving the data size of the guc state */
10404  size = sizeof(Size);
10405 
10406  /* Add up the space needed for each GUC variable */
10407  for (i = 0; i < num_guc_variables; i++)
10408  size = add_size(size,
10410 
10411  return size;
10412 }
static int num_guc_variables
Definition: guc.c:4861
static struct config_generic ** guc_variables
Definition: guc.c:4858
Size add_size(Size s1, Size s2)
Definition: shmem.c:502
size_t Size
Definition: c.h:528
static Size estimate_variable_size(struct config_generic *gconf)
Definition: guc.c:10300
int i

◆ ExecSetVariableStmt()

void ExecSetVariableStmt ( VariableSetStmt stmt,
bool  isTopLevel 
)

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

8513 {
8515 
8516  /*
8517  * Workers synchronize these parameters at the start of the parallel
8518  * operation; then, we block SET during the operation.
8519  */
8520  if (IsInParallelMode())
8521  ereport(ERROR,
8522  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
8523  errmsg("cannot set parameters during a parallel operation")));
8524 
8525  switch (stmt->kind)
8526  {
8527  case VAR_SET_VALUE:
8528  case VAR_SET_CURRENT:
8529  if (stmt->is_local)
8530  WarnNoTransactionBlock(isTopLevel, "SET LOCAL");
8531  (void) set_config_option(stmt->name,
8532  ExtractSetVariableArgs(stmt),
8534  PGC_S_SESSION,
8535  action, true, 0, false);
8536  break;
8537  case VAR_SET_MULTI:
8538 
8539  /*
8540  * Special-case SQL syntaxes. The TRANSACTION and SESSION
8541  * CHARACTERISTICS cases effectively set more than one variable
8542  * per statement. TRANSACTION SNAPSHOT only takes one argument,
8543  * but we put it here anyway since it's a special case and not
8544  * related to any GUC variable.
8545  */
8546  if (strcmp(stmt->name, "TRANSACTION") == 0)
8547  {
8548  ListCell *head;
8549 
8550  WarnNoTransactionBlock(isTopLevel, "SET TRANSACTION");
8551 
8552  foreach(head, stmt->args)
8553  {
8554  DefElem *item = (DefElem *) lfirst(head);
8555 
8556  if (strcmp(item->defname, "transaction_isolation") == 0)
8557  SetPGVariable("transaction_isolation",
8558  list_make1(item->arg), stmt->is_local);
8559  else if (strcmp(item->defname, "transaction_read_only") == 0)
8560  SetPGVariable("transaction_read_only",
8561  list_make1(item->arg), stmt->is_local);
8562  else if (strcmp(item->defname, "transaction_deferrable") == 0)
8563  SetPGVariable("transaction_deferrable",
8564  list_make1(item->arg), stmt->is_local);
8565  else
8566  elog(ERROR, "unexpected SET TRANSACTION element: %s",
8567  item->defname);
8568  }
8569  }
8570  else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
8571  {
8572  ListCell *head;
8573 
8574  foreach(head, stmt->args)
8575  {
8576  DefElem *item = (DefElem *) lfirst(head);
8577 
8578  if (strcmp(item->defname, "transaction_isolation") == 0)
8579  SetPGVariable("default_transaction_isolation",
8580  list_make1(item->arg), stmt->is_local);
8581  else if (strcmp(item->defname, "transaction_read_only") == 0)
8582  SetPGVariable("default_transaction_read_only",
8583  list_make1(item->arg), stmt->is_local);
8584  else if (strcmp(item->defname, "transaction_deferrable") == 0)
8585  SetPGVariable("default_transaction_deferrable",
8586  list_make1(item->arg), stmt->is_local);
8587  else
8588  elog(ERROR, "unexpected SET SESSION element: %s",
8589  item->defname);
8590  }
8591  }
8592  else if (strcmp(stmt->name, "TRANSACTION SNAPSHOT") == 0)
8593  {
8594  A_Const *con = linitial_node(A_Const, stmt->args);
8595 
8596  if (stmt->is_local)
8597  ereport(ERROR,
8598  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8599  errmsg("SET LOCAL TRANSACTION SNAPSHOT is not implemented")));
8600 
8601  WarnNoTransactionBlock(isTopLevel, "SET TRANSACTION");
8602  Assert(nodeTag(&con->val) == T_String);
8603  ImportSnapshot(strVal(&con->val));
8604  }
8605  else
8606  elog(ERROR, "unexpected SET MULTI element: %s",
8607  stmt->name);
8608  break;
8609  case VAR_SET_DEFAULT:
8610  if (stmt->is_local)
8611  WarnNoTransactionBlock(isTopLevel, "SET LOCAL");
8612  /* fall through */
8613  case VAR_RESET:
8614  if (strcmp(stmt->name, "transaction_isolation") == 0)
8615  WarnNoTransactionBlock(isTopLevel, "RESET TRANSACTION");
8616 
8617  (void) set_config_option(stmt->name,
8618  NULL,
8620  PGC_S_SESSION,
8621  action, true, 0, false);
8622  break;
8623  case VAR_RESET_ALL:
8624  ResetAllOptions();
8625  break;
8626  }
8627 }
void ImportSnapshot(const char *idstr)
Definition: snapmgr.c:1377
VariableSetKind kind
Definition: parsenodes.h:2058
void WarnNoTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3441
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:704
bool superuser(void)
Definition: superuser.c:46
#define linitial_node(type, l)
Definition: pg_list.h:177
GucAction
Definition: guc.h:192
#define list_make1(x1)
Definition: pg_list.h:206