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/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 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)
 
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 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 int GUCNestLevel = 0
 

Macro Definition Documentation

◆ CONFIG_FILENAME

#define CONFIG_FILENAME   "postgresql.conf"

Definition at line 109 of file guc.c.

Referenced by SelectConfigFiles().

◆ HBA_FILENAME

#define HBA_FILENAME   "pg_hba.conf"

Definition at line 110 of file guc.c.

Referenced by SelectConfigFiles().

◆ IDENT_FILENAME

#define IDENT_FILENAME   "pg_ident.conf"

Definition at line 111 of file guc.c.

Referenced by SelectConfigFiles().

◆ MAX_UNIT_LEN

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

Definition at line 815 of file guc.c.

Referenced by convert_to_base_unit().

◆ newval [1/5]

#define newval   (newval_union.boolval)

◆ newval [2/5]

#define newval   (newval_union.intval)

◆ newval [3/5]

#define newval   (newval_union.realval)

◆ newval [4/5]

#define newval   (newval_union.stringval)

◆ newval [5/5]

#define newval   (newval_union.enumval)

◆ NUM_PG_FILE_SETTINGS_ATTS

#define NUM_PG_FILE_SETTINGS_ATTS   7

Referenced by show_all_file_settings().

◆ NUM_PG_SETTINGS_ATTS

#define NUM_PG_SETTINGS_ATTS   17

Definition at line 9514 of file guc.c.

Referenced by show_all_settings().

◆ PG_KRB_SRVTAB

#define PG_KRB_SRVTAB   ""

Definition at line 106 of file guc.c.

◆ REALTYPE_PRECISION

#define REALTYPE_PRECISION   17

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

9761 {
9762  char buffer[256];
9763  const char *val;
9764 
9765  switch (record->vartype)
9766  {
9767  case PGC_BOOL:
9768  {
9769  struct config_bool *conf = (struct config_bool *) record;
9770 
9771  if (conf->show_hook)
9772  val = conf->show_hook();
9773  else
9774  val = *conf->variable ? "on" : "off";
9775  }
9776  break;
9777 
9778  case PGC_INT:
9779  {
9780  struct config_int *conf = (struct config_int *) record;
9781 
9782  if (conf->show_hook)
9783  val = conf->show_hook();
9784  else
9785  {
9786  /*
9787  * Use int64 arithmetic to avoid overflows in units
9788  * conversion.
9789  */
9790  int64 result = *conf->variable;
9791  const char *unit;
9792 
9793  if (use_units && result > 0 && (record->flags & GUC_UNIT))
9795  record->flags & GUC_UNIT,
9796  &result, &unit);
9797  else
9798  unit = "";
9799 
9800  snprintf(buffer, sizeof(buffer), INT64_FORMAT "%s",
9801  result, unit);
9802  val = buffer;
9803  }
9804  }
9805  break;
9806 
9807  case PGC_REAL:
9808  {
9809  struct config_real *conf = (struct config_real *) record;
9810 
9811  if (conf->show_hook)
9812  val = conf->show_hook();
9813  else
9814  {
9815  double result = *conf->variable;
9816  const char *unit;
9817 
9818  if (use_units && result > 0 && (record->flags & GUC_UNIT))
9820  record->flags & GUC_UNIT,
9821  &result, &unit);
9822  else
9823  unit = "";
9824 
9825  snprintf(buffer, sizeof(buffer), "%g%s",
9826  result, unit);
9827  val = buffer;
9828  }
9829  }
9830  break;
9831 
9832  case PGC_STRING:
9833  {
9834  struct config_string *conf = (struct config_string *) record;
9835 
9836  if (conf->show_hook)
9837  val = conf->show_hook();
9838  else if (*conf->variable && **conf->variable)
9839  val = *conf->variable;
9840  else
9841  val = "";
9842  }
9843  break;
9844 
9845  case PGC_ENUM:
9846  {
9847  struct config_enum *conf = (struct config_enum *) record;
9848 
9849  if (conf->show_hook)
9850  val = conf->show_hook();
9851  else
9852  val = config_enum_lookup_by_value(conf, *conf->variable);
9853  }
9854  break;
9855 
9856  default:
9857  /* just to keep compiler quiet */
9858  val = "???";
9859  break;
9860  }
9861 
9862  return pstrdup(val);
9863 }
char ** variable
Definition: guc_tables.h:230
char * pstrdup(const char *in)
Definition: mcxt.c:1186
bool * variable
Definition: guc_tables.h:184
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:6645
#define GUC_UNIT
Definition: guc.h:232
GucShowHook show_hook
Definition: guc_tables.h:204
int * variable
Definition: guc_tables.h:198
int * variable
Definition: guc_tables.h:244
static void convert_real_from_base_unit(double base_value, int base_unit, double *value, const char **unit)
Definition: guc.c:6393
GucShowHook show_hook
Definition: guc_tables.h:234
GucShowHook show_hook
Definition: guc_tables.h:220
double * variable
Definition: guc_tables.h:214
enum config_type vartype
Definition: guc_tables.h:156
GucShowHook show_hook
Definition: guc_tables.h:249
GucShowHook show_hook
Definition: guc_tables.h:188
#define INT64_FORMAT
Definition: c.h:416
static void convert_int_from_base_unit(int64 base_value, int base_unit, int64 *value, const char **unit)
Definition: guc.c:6351
#define snprintf
Definition: port.h:193
long val
Definition: informix.c:664

◆ add_guc_variable()

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

Definition at line 5163 of file guc.c.

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

Referenced by add_placeholder_variable(), and define_custom_variable().

5164 {
5166  {
5167  /*
5168  * Increase the vector by 25%
5169  */
5170  int size_vars = size_guc_variables + size_guc_variables / 4;
5171  struct config_generic **guc_vars;
5172 
5173  if (size_vars == 0)
5174  {
5175  size_vars = 100;
5176  guc_vars = (struct config_generic **)
5177  guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
5178  }
5179  else
5180  {
5181  guc_vars = (struct config_generic **)
5182  guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
5183  }
5184 
5185  if (guc_vars == NULL)
5186  return false; /* out of memory */
5187 
5188  guc_variables = guc_vars;
5189  size_guc_variables = size_vars;
5190  }
5193  sizeof(struct config_generic *), guc_var_compare);
5194  return true;
5195 }
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:5298
static int num_guc_variables
Definition: guc.c:4815
static void * guc_realloc(int elevel, void *old, size_t size)
Definition: guc.c:4869
static struct config_generic ** guc_variables
Definition: guc.c:4812
static int size_guc_variables
Definition: guc.c:4818
static int elevel
Definition: vacuumlazy.c:330
#define qsort(a, b, c, d)
Definition: port.h:479
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4853

◆ add_placeholder_variable()

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

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

5202 {
5203  size_t sz = sizeof(struct config_string) + sizeof(char *);
5204  struct config_string *var;
5205  struct config_generic *gen;
5206 
5207  var = (struct config_string *) guc_malloc(elevel, sz);
5208  if (var == NULL)
5209  return NULL;
5210  memset(var, 0, sz);
5211  gen = &var->gen;
5212 
5213  gen->name = guc_strdup(elevel, name);
5214  if (gen->name == NULL)
5215  {
5216  free(var);
5217  return NULL;
5218  }
5219 
5220  gen->context = PGC_USERSET;
5221  gen->group = CUSTOM_OPTIONS;
5222  gen->short_desc = "GUC placeholder variable";
5224  gen->vartype = PGC_STRING;
5225 
5226  /*
5227  * The char* is allocated at the end of the struct since we have no
5228  * 'static' place to point to. Note that the current value, as well as
5229  * the boot and reset values, start out NULL.
5230  */
5231  var->variable = (char **) (var + 1);
5232 
5233  if (!add_guc_variable((struct config_generic *) var, elevel))
5234  {
5235  free(unconstify(char *, gen->name));
5236  free(var);
5237  return NULL;
5238  }
5239 
5240  return gen;
5241 }
char ** variable
Definition: guc_tables.h:230
const char * name
Definition: guc_tables.h:149
const char * short_desc
Definition: guc_tables.h:152
static char * guc_strdup(int elevel, const char *src)
Definition: guc.c:4885
#define GUC_NO_SHOW_ALL
Definition: guc.h:206
#define GUC_NOT_IN_SAMPLE
Definition: guc.h:209
enum config_type vartype
Definition: guc_tables.h:156
#define unconstify(underlying_type, expr)
Definition: c.h:1183
static int elevel
Definition: vacuumlazy.c:330
struct config_generic gen
Definition: guc_tables.h:228
#define free(a)
Definition: header.h:65
#define GUC_CUSTOM_PLACEHOLDER
Definition: guc.h:211
const char * name
Definition: encode.c:561
enum config_group group
Definition: guc_tables.h:151
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4853
GucContext context
Definition: guc_tables.h:150
static bool add_guc_variable(struct config_generic *var, int elevel)
Definition: guc.c:5163

◆ AlterSystemSetConfigFile()

void AlterSystemSetConfigFile ( AlterSystemStmt altersysstmt)

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

8134 {
8135  char *name;
8136  char *value;
8137  bool resetall = false;
8138  ConfigVariable *head = NULL;
8139  ConfigVariable *tail = NULL;
8140  volatile int Tmpfd;
8141  char AutoConfFileName[MAXPGPATH];
8142  char AutoConfTmpFileName[MAXPGPATH];
8143 
8144  if (!superuser())
8145  ereport(ERROR,
8146  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
8147  errmsg("must be superuser to execute ALTER SYSTEM command")));
8148 
8149  /*
8150  * Extract statement arguments
8151  */
8152  name = altersysstmt->setstmt->name;
8153 
8154  switch (altersysstmt->setstmt->kind)
8155  {
8156  case VAR_SET_VALUE:
8157  value = ExtractSetVariableArgs(altersysstmt->setstmt);
8158  break;
8159 
8160  case VAR_SET_DEFAULT:
8161  case VAR_RESET:
8162  value = NULL;
8163  break;
8164 
8165  case VAR_RESET_ALL:
8166  value = NULL;
8167  resetall = true;
8168  break;
8169 
8170  default:
8171  elog(ERROR, "unrecognized alter system stmt type: %d",
8172  altersysstmt->setstmt->kind);
8173  break;
8174  }
8175 
8176  /*
8177  * Unless it's RESET_ALL, validate the target variable and value
8178  */
8179  if (!resetall)
8180  {
8181  struct config_generic *record;
8182 
8183  record = find_option(name, false, ERROR);
8184  if (record == NULL)
8185  ereport(ERROR,
8186  (errcode(ERRCODE_UNDEFINED_OBJECT),
8187  errmsg("unrecognized configuration parameter \"%s\"",
8188  name)));
8189 
8190  /*
8191  * Don't allow parameters that can't be set in configuration files to
8192  * be set in PG_AUTOCONF_FILENAME file.
8193  */
8194  if ((record->context == PGC_INTERNAL) ||
8195  (record->flags & GUC_DISALLOW_IN_FILE) ||
8196  (record->flags & GUC_DISALLOW_IN_AUTO_FILE))
8197  ereport(ERROR,
8198  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
8199  errmsg("parameter \"%s\" cannot be changed",
8200  name)));
8201 
8202  /*
8203  * If a value is specified, verify that it's sane.
8204  */
8205  if (value)
8206  {
8207  union config_var_val newval;
8208  void *newextra = NULL;
8209 
8210  /* Check that it's acceptable for the indicated parameter */
8211  if (!parse_and_validate_value(record, name, value,
8212  PGC_S_FILE, ERROR,
8213  &newval, &newextra))
8214  ereport(ERROR,
8215  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8216  errmsg("invalid value for parameter \"%s\": \"%s\"",
8217  name, value)));
8218 
8219  if (record->vartype == PGC_STRING && newval.stringval != NULL)
8220  free(newval.stringval);
8221  if (newextra)
8222  free(newextra);
8223 
8224  /*
8225  * We must also reject values containing newlines, because the
8226  * grammar for config files doesn't support embedded newlines in
8227  * string literals.
8228  */
8229  if (strchr(value, '\n'))
8230  ereport(ERROR,
8231  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8232  errmsg("parameter value for ALTER SYSTEM must not contain a newline")));
8233  }
8234  }
8235 
8236  /*
8237  * PG_AUTOCONF_FILENAME and its corresponding temporary file are always in
8238  * the data directory, so we can reference them by simple relative paths.
8239  */
8240  snprintf(AutoConfFileName, sizeof(AutoConfFileName), "%s",
8242  snprintf(AutoConfTmpFileName, sizeof(AutoConfTmpFileName), "%s.%s",
8243  AutoConfFileName,
8244  "tmp");
8245 
8246  /*
8247  * Only one backend is allowed to operate on PG_AUTOCONF_FILENAME at a
8248  * time. Use AutoFileLock to ensure that. We must hold the lock while
8249  * reading the old file contents.
8250  */
8251  LWLockAcquire(AutoFileLock, LW_EXCLUSIVE);
8252 
8253  /*
8254  * If we're going to reset everything, then no need to open or parse the
8255  * old file. We'll just write out an empty list.
8256  */
8257  if (!resetall)
8258  {
8259  struct stat st;
8260 
8261  if (stat(AutoConfFileName, &st) == 0)
8262  {
8263  /* open old file PG_AUTOCONF_FILENAME */
8264  FILE *infile;
8265 
8266  infile = AllocateFile(AutoConfFileName, "r");
8267  if (infile == NULL)
8268  ereport(ERROR,
8270  errmsg("could not open file \"%s\": %m",
8271  AutoConfFileName)));
8272 
8273  /* parse it */
8274  if (!ParseConfigFp(infile, AutoConfFileName, 0, LOG, &head, &tail))
8275  ereport(ERROR,
8276  (errcode(ERRCODE_CONFIG_FILE_ERROR),
8277  errmsg("could not parse contents of file \"%s\"",
8278  AutoConfFileName)));
8279 
8280  FreeFile(infile);
8281  }
8282 
8283  /*
8284  * Now, replace any existing entry with the new value, or add it if
8285  * not present.
8286  */
8287  replace_auto_config_value(&head, &tail, name, value);
8288  }
8289 
8290  /*
8291  * To ensure crash safety, first write the new file data to a temp file,
8292  * then atomically rename it into place.
8293  *
8294  * If there is a temp file left over due to a previous crash, it's okay to
8295  * truncate and reuse it.
8296  */
8297  Tmpfd = BasicOpenFile(AutoConfTmpFileName,
8298  O_CREAT | O_RDWR | O_TRUNC);
8299  if (Tmpfd < 0)
8300  ereport(ERROR,
8302  errmsg("could not open file \"%s\": %m",
8303  AutoConfTmpFileName)));
8304 
8305  /*
8306  * Use a TRY block to clean up the file if we fail. Since we need a TRY
8307  * block anyway, OK to use BasicOpenFile rather than OpenTransientFile.
8308  */
8309  PG_TRY();
8310  {
8311  /* Write and sync the new contents to the temporary file */
8312  write_auto_conf_file(Tmpfd, AutoConfTmpFileName, head);
8313 
8314  /* Close before renaming; may be required on some platforms */
8315  close(Tmpfd);
8316  Tmpfd = -1;
8317 
8318  /*
8319  * As the rename is atomic operation, if any problem occurs after this
8320  * at worst it can lose the parameters set by last ALTER SYSTEM
8321  * command.
8322  */
8323  durable_rename(AutoConfTmpFileName, AutoConfFileName, ERROR);
8324  }
8325  PG_CATCH();
8326  {
8327  /* Close file first, else unlink might fail on some platforms */
8328  if (Tmpfd >= 0)
8329  close(Tmpfd);
8330 
8331  /* Unlink, but ignore any error */
8332  (void) unlink(AutoConfTmpFileName);
8333 
8334  PG_RE_THROW();
8335  }
8336  PG_END_TRY();
8337 
8338  FreeConfigVariables(head);
8339 
8340  LWLockRelease(AutoFileLock);
8341 }
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:6752
VariableSetKind kind
Definition: parsenodes.h:2042
int errcode(int sqlerrcode)
Definition: elog.c:610
bool superuser(void)
Definition: superuser.c:46
#define LOG
Definition: elog.h:26
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1812
#define ERROR
Definition: elog.h:43
#define MAXPGPATH
VariableSetStmt * setstmt
Definition: parsenodes.h:3194
int errcode_for_file_access(void)
Definition: elog.c:633
FILE * AllocateFile(const char *name, const char *mode)
Definition: fd.c:2322
int durable_rename(const char *oldfile, const char *newfile, int elevel)
Definition: fd.c:658
enum config_type vartype
Definition: guc_tables.h:156
#define stat(a, b)
Definition: win32_port.h:255
#define GUC_DISALLOW_IN_FILE
Definition: guc.h:210
static void write_auto_conf_file(int fd, const char *filename, ConfigVariable *head_p)
Definition: guc.c:7995
static struct @143 value
#define ereport(elevel,...)
Definition: elog.h:144
static void infile(const char *filename)
Definition: zic.c:1245
#define free(a)
Definition: header.h:65
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:5249
#define PG_CATCH()
Definition: elog.h:305
#define newval
#define PG_AUTOCONF_FILENAME
Definition: guc.h:34
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1208
#define PG_RE_THROW()
Definition: elog.h:336
const char * name
Definition: encode.c:561
#define GUC_DISALLOW_IN_AUTO_FILE
Definition: guc.h:215
int BasicOpenFile(const char *fileName, int fileFlags)
Definition: fd.c:985
int FreeFile(FILE *file)
Definition: fd.c:2521
int errmsg(const char *fmt,...)
Definition: elog.c:824
bool ParseConfigFp(FILE *fp, const char *config_file, int depth, int elevel, ConfigVariable **head_p, ConfigVariable **tail_p)
#define elog(elevel,...)
Definition: elog.h:214
static void replace_auto_config_value(ConfigVariable **head_p, ConfigVariable **tail_p, const char *name, const char *value)
Definition: guc.c:8063
void FreeConfigVariables(ConfigVariable *list)
#define close(a)
Definition: win32.h:12
#define PG_TRY()
Definition: elog.h:295
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
Definition: guc.c:8471
#define snprintf
Definition: port.h:193
#define PG_END_TRY()
Definition: elog.h:320
GucContext context
Definition: guc_tables.h:150

◆ assign_application_name()

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

Definition at line 11650 of file guc.c.

References pgstat_report_appname().

11651 {
11652  /* Update the pg_stat_activity view */
11654 }
void pgstat_report_appname(const char *appname)
Definition: pgstat.c:3305
#define newval

◆ assign_backtrace_functions()

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

Definition at line 11757 of file guc.c.

11758 {
11759  backtrace_symbol_list = (char *) extra;
11760 }
char * backtrace_symbol_list
Definition: guc.c:549

◆ assign_log_destination()

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

Definition at line 11254 of file guc.c.

References Log_destination.

11255 {
11256  Log_destination = *((int *) extra);
11257 }
int Log_destination
Definition: elog.c:110

◆ assign_pgstat_temp_directory()

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

Definition at line 11612 of file guc.c.

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

11613 {
11614  /* check_canonical_path already canonicalized newval for us */
11615  char *dname;
11616  char *tname;
11617  char *fname;
11618 
11619  /* directory */
11620  dname = guc_malloc(ERROR, strlen(newval) + 1); /* runtime dir */
11621  sprintf(dname, "%s", newval);
11622 
11623  /* global stats */
11624  tname = guc_malloc(ERROR, strlen(newval) + 12); /* /global.tmp */
11625  sprintf(tname, "%s/global.tmp", newval);
11626  fname = guc_malloc(ERROR, strlen(newval) + 13); /* /global.stat */
11627  sprintf(fname, "%s/global.stat", newval);
11628 
11631  pgstat_stat_directory = dname;
11632  if (pgstat_stat_tmpname)
11634  pgstat_stat_tmpname = tname;
11637  pgstat_stat_filename = fname;
11638 }
#define sprintf
Definition: port.h:195
char * pgstat_stat_filename
Definition: pgstat.c:134
#define ERROR
Definition: elog.h:43
char * pgstat_stat_directory
Definition: pgstat.c:133
#define free(a)
Definition: header.h:65
#define newval
char * pgstat_stat_tmpname
Definition: pgstat.c:135
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4853

◆ assign_recovery_target()

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

Definition at line 11836 of file guc.c.

References RECOVERY_TARGET_IMMEDIATE, RECOVERY_TARGET_UNSET, and recoveryTarget.

11837 {
11840  error_multiple_recovery_targets();
11841 
11842  if (newval && strcmp(newval, "") != 0)
11844  else
11846 }
#define newval
RecoveryTargetType recoveryTarget
Definition: xlog.c:282

◆ assign_recovery_target_lsn()

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

Definition at line 12004 of file guc.c.

References RECOVERY_TARGET_LSN, RECOVERY_TARGET_UNSET, recoveryTarget, and recoveryTargetLSN.

12005 {
12008  error_multiple_recovery_targets();
12009 
12010  if (newval && strcmp(newval, "") != 0)
12011  {
12013  recoveryTargetLSN = *((XLogRecPtr *) extra);
12014  }
12015  else
12017 }
XLogRecPtr recoveryTargetLSN
Definition: xlog.c:289
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define newval
RecoveryTargetType recoveryTarget
Definition: xlog.c:282

◆ assign_recovery_target_name()

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

Definition at line 11968 of file guc.c.

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

11969 {
11972  error_multiple_recovery_targets();
11973 
11974  if (newval && strcmp(newval, "") != 0)
11975  {
11978  }
11979  else
11981 }
const char * recoveryTargetName
Definition: xlog.c:288
#define newval
RecoveryTargetType recoveryTarget
Definition: xlog.c:282

◆ assign_recovery_target_time()

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

Definition at line 11942 of file guc.c.

References RECOVERY_TARGET_TIME, RECOVERY_TARGET_UNSET, and recoveryTarget.

11943 {
11946  error_multiple_recovery_targets();
11947 
11948  if (newval && strcmp(newval, "") != 0)
11950  else
11952 }
#define newval
RecoveryTargetType recoveryTarget
Definition: xlog.c:282

◆ assign_recovery_target_timeline()

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

Definition at line 11793 of file guc.c.

References RECOVERY_TARGET_TIMELINE_NUMERIC, recoveryTargetTimeLineGoal, and recoveryTargetTLIRequested.

11794 {
11797  recoveryTargetTLIRequested = (TimeLineID) strtoul(newval, NULL, 0);
11798  else
11800 }
TimeLineID recoveryTargetTLIRequested
Definition: xlog.c:339
uint32 TimeLineID
Definition: xlogdefs.h:52
RecoveryTargetTimeLineGoal
Definition: xlog.h:93
RecoveryTargetTimeLineGoal recoveryTargetTimeLineGoal
Definition: xlog.c:338
#define newval

◆ assign_recovery_target_xid()

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

Definition at line 11869 of file guc.c.

References RECOVERY_TARGET_UNSET, RECOVERY_TARGET_XID, recoveryTarget, and recoveryTargetXid.

11870 {
11873  error_multiple_recovery_targets();
11874 
11875  if (newval && strcmp(newval, "") != 0)
11876  {
11878  recoveryTargetXid = *((TransactionId *) extra);
11879  }
11880  else
11882 }
uint32 TransactionId
Definition: c.h:520
TransactionId recoveryTargetXid
Definition: xlog.c:285
#define newval
RecoveryTargetType recoveryTarget
Definition: xlog.c:282

◆ assign_session_replication_role()

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

Definition at line 11280 of file guc.c.

References ResetPlanCache(), and SessionReplicationRole.

11281 {
11282  /*
11283  * Must flush the plan cache when changing replication role; but don't
11284  * flush unnecessarily.
11285  */
11287  ResetPlanCache();
11288 }
int SessionReplicationRole
Definition: trigger.c:67
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 11260 of file guc.c.

11261 {
11262 #ifdef HAVE_SYSLOG
11263  set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
11264  newval);
11265 #endif
11266  /* Without syslog support, just ignore it */
11267 }
static char * syslog_ident_str
Definition: guc.c:590
#define newval

◆ assign_syslog_ident()

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

Definition at line 11270 of file guc.c.

11271 {
11272 #ifdef HAVE_SYSLOG
11273  set_syslog_parameters(newval, syslog_facility);
11274 #endif
11275  /* Without syslog support, it will always be set to "none", so ignore */
11276 }
static int syslog_facility
Definition: guc.c:173
#define newval

◆ assign_tcp_keepalives_count()

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

Definition at line 11479 of file guc.c.

References MyProcPort, and pq_setkeepalivescount().

11480 {
11481  /* See comments in assign_tcp_keepalives_idle */
11483 }
struct Port * MyProcPort
Definition: globals.c:43
int pq_setkeepalivescount(int count, Port *port)
Definition: pqcomm.c:1875
#define newval

◆ assign_tcp_keepalives_idle()

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

Definition at line 11435 of file guc.c.

References MyProcPort, and pq_setkeepalivesidle().

11436 {
11437  /*
11438  * The kernel API provides no way to test a value without setting it; and
11439  * once we set it we might fail to unset it. So there seems little point
11440  * in fully implementing the check-then-assign GUC API for these
11441  * variables. Instead we just do the assignment on demand. pqcomm.c
11442  * reports any problems via elog(LOG).
11443  *
11444  * This approach means that the GUC value might have little to do with the
11445  * actual kernel value, so we use a show_hook that retrieves the kernel
11446  * value rather than trusting GUC's copy.
11447  */
11449 }
struct Port * MyProcPort
Definition: globals.c:43
int pq_setkeepalivesidle(int idle, Port *port)
Definition: pqcomm.c:1717
#define newval

◆ assign_tcp_keepalives_interval()

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

Definition at line 11462 of file guc.c.

References MyProcPort, and pq_setkeepalivesinterval().

11463 {
11464  /* See comments in assign_tcp_keepalives_idle */
11466 }
struct Port * MyProcPort
Definition: globals.c:43
int pq_setkeepalivesinterval(int interval, Port *port)
Definition: pqcomm.c:1799
#define newval

◆ assign_tcp_user_timeout()

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

Definition at line 11496 of file guc.c.

References MyProcPort, and pq_settcpusertimeout().

11497 {
11498  /* See comments in assign_tcp_keepalives_idle */
11500 }
struct Port * MyProcPort
Definition: globals.c:43
#define newval
int pq_settcpusertimeout(int timeout, Port *port)
Definition: pqcomm.c:1947

◆ assign_timezone_abbreviations()

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

Definition at line 11399 of file guc.c.

References InstallTimeZoneAbbrevs().

11400 {
11401  /* Do nothing for the boot_val default of NULL */
11402  if (!extra)
11403  return;
11404 
11406 }
void InstallTimeZoneAbbrevs(TimeZoneAbbrevTable *tbl)
Definition: datetime.c:4569

◆ assign_wal_consistency_checking()

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

Definition at line 11191 of file guc.c.

References wal_consistency_checking.

11192 {
11193  wal_consistency_checking = (bool *) extra;
11194 }
bool * wal_consistency_checking
Definition: xlog.c:101

◆ AtEOXact_GUC()

void AtEOXact_GUC ( bool  isCommit,
int  nestLevel 
)

Definition at line 5956 of file guc.c.

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

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

5957 {
5958  bool still_dirty;
5959  int i;
5960 
5961  /*
5962  * Note: it's possible to get here with GUCNestLevel == nestLevel-1 during
5963  * abort, if there is a failure during transaction start before
5964  * AtStart_GUC is called.
5965  */
5966  Assert(nestLevel > 0 &&
5967  (nestLevel <= GUCNestLevel ||
5968  (nestLevel == GUCNestLevel + 1 && !isCommit)));
5969 
5970  /* Quick exit if nothing's changed in this transaction */
5971  if (!guc_dirty)
5972  {
5973  GUCNestLevel = nestLevel - 1;
5974  return;
5975  }
5976 
5977  still_dirty = false;
5978  for (i = 0; i < num_guc_variables; i++)
5979  {
5980  struct config_generic *gconf = guc_variables[i];
5981  GucStack *stack;
5982 
5983  /*
5984  * Process and pop each stack entry within the nest level. To simplify
5985  * fmgr_security_definer() and other places that use GUC_ACTION_SAVE,
5986  * we allow failure exit from code that uses a local nest level to be
5987  * recovered at the surrounding transaction or subtransaction abort;
5988  * so there could be more than one stack entry to pop.
5989  */
5990  while ((stack = gconf->stack) != NULL &&
5991  stack->nest_level >= nestLevel)
5992  {
5993  GucStack *prev = stack->prev;
5994  bool restorePrior = false;
5995  bool restoreMasked = false;
5996  bool changed;
5997 
5998  /*
5999  * In this next bit, if we don't set either restorePrior or
6000  * restoreMasked, we must "discard" any unwanted fields of the
6001  * stack entries to avoid leaking memory. If we do set one of
6002  * those flags, unused fields will be cleaned up after restoring.
6003  */
6004  if (!isCommit) /* if abort, always restore prior value */
6005  restorePrior = true;
6006  else if (stack->state == GUC_SAVE)
6007  restorePrior = true;
6008  else if (stack->nest_level == 1)
6009  {
6010  /* transaction commit */
6011  if (stack->state == GUC_SET_LOCAL)
6012  restoreMasked = true;
6013  else if (stack->state == GUC_SET)
6014  {
6015  /* we keep the current active value */
6016  discard_stack_value(gconf, &stack->prior);
6017  }
6018  else /* must be GUC_LOCAL */
6019  restorePrior = true;
6020  }
6021  else if (prev == NULL ||
6022  prev->nest_level < stack->nest_level - 1)
6023  {
6024  /* decrement entry's level and do not pop it */
6025  stack->nest_level--;
6026  continue;
6027  }
6028  else
6029  {
6030  /*
6031  * We have to merge this stack entry into prev. See README for
6032  * discussion of this bit.
6033  */
6034  switch (stack->state)
6035  {
6036  case GUC_SAVE:
6037  Assert(false); /* can't get here */
6038  break;
6039 
6040  case GUC_SET:
6041  /* next level always becomes SET */
6042  discard_stack_value(gconf, &stack->prior);
6043  if (prev->state == GUC_SET_LOCAL)
6044  discard_stack_value(gconf, &prev->masked);
6045  prev->state = GUC_SET;
6046  break;
6047 
6048  case GUC_LOCAL:
6049  if (prev->state == GUC_SET)
6050  {
6051  /* LOCAL migrates down */
6052  prev->masked_scontext = stack->scontext;
6053  prev->masked = stack->prior;
6054  prev->state = GUC_SET_LOCAL;
6055  }
6056  else
6057  {
6058  /* else just forget this stack level */
6059  discard_stack_value(gconf, &stack->prior);
6060  }
6061  break;
6062 
6063  case GUC_SET_LOCAL:
6064  /* prior state at this level no longer wanted */
6065  discard_stack_value(gconf, &stack->prior);
6066  /* copy down the masked state */
6067  prev->masked_scontext = stack->masked_scontext;
6068  if (prev->state == GUC_SET_LOCAL)
6069  discard_stack_value(gconf, &prev->masked);
6070  prev->masked = stack->masked;
6071  prev->state = GUC_SET_LOCAL;
6072  break;
6073  }
6074  }
6075 
6076  changed = false;
6077 
6078  if (restorePrior || restoreMasked)
6079  {
6080  /* Perform appropriate restoration of the stacked value */
6081  config_var_value newvalue;
6082  GucSource newsource;
6083  GucContext newscontext;
6084 
6085  if (restoreMasked)
6086  {
6087  newvalue = stack->masked;
6088  newsource = PGC_S_SESSION;
6089  newscontext = stack->masked_scontext;
6090  }
6091  else
6092  {
6093  newvalue = stack->prior;
6094  newsource = stack->source;
6095  newscontext = stack->scontext;
6096  }
6097 
6098  switch (gconf->vartype)
6099  {
6100  case PGC_BOOL:
6101  {
6102  struct config_bool *conf = (struct config_bool *) gconf;
6103  bool newval = newvalue.val.boolval;
6104  void *newextra = newvalue.extra;
6105 
6106  if (*conf->variable != newval ||
6107  conf->gen.extra != newextra)
6108  {
6109  if (conf->assign_hook)
6110  conf->assign_hook(newval, newextra);
6111  *conf->variable = newval;
6112  set_extra_field(&conf->gen, &conf->gen.extra,
6113  newextra);
6114  changed = true;
6115  }
6116  break;
6117  }
6118  case PGC_INT:
6119  {
6120  struct config_int *conf = (struct config_int *) gconf;
6121  int newval = newvalue.val.intval;
6122  void *newextra = newvalue.extra;
6123 
6124  if (*conf->variable != newval ||
6125  conf->gen.extra != newextra)
6126  {
6127  if (conf->assign_hook)
6128  conf->assign_hook(newval, newextra);
6129  *conf->variable = newval;
6130  set_extra_field(&conf->gen, &conf->gen.extra,
6131  newextra);
6132  changed = true;
6133  }
6134  break;
6135  }
6136  case PGC_REAL:
6137  {
6138  struct config_real *conf = (struct config_real *) gconf;
6139  double newval = newvalue.val.realval;
6140  void *newextra = newvalue.extra;
6141 
6142  if (*conf->variable != newval ||
6143  conf->gen.extra != newextra)
6144  {
6145  if (conf->assign_hook)
6146  conf->assign_hook(newval, newextra);
6147  *conf->variable = newval;
6148  set_extra_field(&conf->gen, &conf->gen.extra,
6149  newextra);
6150  changed = true;
6151  }
6152  break;
6153  }
6154  case PGC_STRING:
6155  {
6156  struct config_string *conf = (struct config_string *) gconf;
6157  char *newval = newvalue.val.stringval;
6158  void *newextra = newvalue.extra;
6159 
6160  if (*conf->variable != newval ||
6161  conf->gen.extra != newextra)
6162  {
6163  if (conf->assign_hook)
6164  conf->assign_hook(newval, newextra);
6165  set_string_field(conf, conf->variable, newval);
6166  set_extra_field(&conf->gen, &conf->gen.extra,
6167  newextra);
6168  changed = true;
6169  }
6170 
6171  /*
6172  * Release stacked values if not used anymore. We
6173  * could use discard_stack_value() here, but since
6174  * we have type-specific code anyway, might as
6175  * well inline it.
6176  */
6177  set_string_field(conf, &stack->prior.val.stringval, NULL);
6178  set_string_field(conf, &stack->masked.val.stringval, NULL);
6179  break;
6180  }
6181  case PGC_ENUM:
6182  {
6183  struct config_enum *conf = (struct config_enum *) gconf;
6184  int newval = newvalue.val.enumval;
6185  void *newextra = newvalue.extra;
6186 
6187  if (*conf->variable != newval ||
6188  conf->gen.extra != newextra)
6189  {
6190  if (conf->assign_hook)
6191  conf->assign_hook(newval, newextra);
6192  *conf->variable = newval;
6193  set_extra_field(&conf->gen, &conf->gen.extra,
6194  newextra);
6195  changed = true;
6196  }
6197  break;
6198  }
6199  }
6200 
6201  /*
6202  * Release stacked extra values if not used anymore.
6203  */
6204  set_extra_field(gconf, &(stack->prior.extra), NULL);
6205  set_extra_field(gconf, &(stack->masked.extra), NULL);
6206 
6207  /* And restore source information */
6208  gconf->source = newsource;
6209  gconf->scontext = newscontext;
6210  }
6211 
6212  /* Finish popping the state stack */
6213  gconf->stack = prev;
6214  pfree(stack);
6215 
6216  /* Report new value if we changed it */
6217  if (changed && (gconf->flags & GUC_REPORT))
6218  ReportGUCOption(gconf);
6219  } /* end of stack-popping loop */
6220 
6221  if (stack != NULL)
6222  still_dirty = true;
6223  }
6224 
6225  /* If there are no remaining stack entries, we can reset guc_dirty */
6226  guc_dirty = still_dirty;
6227 
6228  /* Update nesting level */
6229  GUCNestLevel = nestLevel - 1;
6230 }
struct guc_stack * prev
Definition: guc_tables.h:123
GucSource source
Definition: guc_tables.h:158
GucContext
Definition: guc.h:68
union config_var_val val
Definition: guc_tables.h:46
int nest_level
Definition: guc_tables.h:124
GucRealAssignHook assign_hook
Definition: guc_tables.h:219
char ** variable
Definition: guc_tables.h:230
static int GUCNestLevel
Definition: guc.c:4825
bool * variable
Definition: guc_tables.h:184
GucEnumAssignHook assign_hook
Definition: guc_tables.h:248
GucBoolAssignHook assign_hook
Definition: guc_tables.h:187
config_var_value masked
Definition: guc_tables.h:131
GucContext scontext
Definition: guc_tables.h:160
GucIntAssignHook assign_hook
Definition: guc_tables.h:203
GucSource
Definition: guc.h:105
int * variable
Definition: guc_tables.h:198
int * variable
Definition: guc_tables.h:244
void pfree(void *pointer)
Definition: mcxt.c:1056
static int num_guc_variables
Definition: guc.c:4815
static void discard_stack_value(struct config_generic *gconf, config_var_value *val)
Definition: guc.c:5040
GucSource source
Definition: guc_tables.h:126
static void set_extra_field(struct config_generic *gconf, void **field, void *newval)
Definition: guc.c:4986
struct config_generic gen
Definition: guc_tables.h:182
struct config_generic gen
Definition: guc_tables.h:196
GucContext masked_scontext
Definition: guc_tables.h:129
#define GUC_REPORT
Definition: guc.h:208
double * variable
Definition: guc_tables.h:214
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4925
static struct config_generic ** guc_variables
Definition: guc.c:4812
enum config_type vartype
Definition: guc_tables.h:156
GucContext scontext
Definition: guc_tables.h:128
struct config_generic gen
Definition: guc_tables.h:242
struct config_generic gen
Definition: guc_tables.h:228
GucStackState state
Definition: guc_tables.h:125
GucStringAssignHook assign_hook
Definition: guc_tables.h:233
#define Assert(condition)
Definition: c.h:745
#define newval
char * stringval
Definition: guc_tables.h:36
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:6266
GucStack * stack
Definition: guc_tables.h:162
double realval
Definition: guc_tables.h:35
static bool guc_dirty
Definition: guc.c:4821
config_var_value prior
Definition: guc_tables.h:130
struct config_generic gen
Definition: guc_tables.h:212

◆ AtStart_GUC()

void AtStart_GUC ( void  )

Definition at line 5922 of file guc.c.

References elog, and WARNING.

Referenced by StartTransaction().

5923 {
5924  /*
5925  * The nest level should be 0 between transactions; if it isn't, somebody
5926  * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
5927  * throw a warning but make no other effort to clean up.
5928  */
5929  if (GUCNestLevel != 0)
5930  elog(WARNING, "GUC nest level = %d at transaction start",
5931  GUCNestLevel);
5932  GUCNestLevel = 1;
5933 }
static int GUCNestLevel
Definition: guc.c:4825
#define WARNING
Definition: elog.h:40
#define elog(elevel,...)
Definition: elog.h:214

◆ BeginReportingGUCOptions()

void BeginReportingGUCOptions ( void  )

Definition at line 6238 of file guc.c.

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

Referenced by PostgresMain().

6239 {
6240  int i;
6241 
6242  /*
6243  * Don't do anything unless talking to an interactive frontend of protocol
6244  * 3.0 or later.
6245  */
6246  if (whereToSendOutput != DestRemote ||
6248  return;
6249 
6250  reporting_enabled = true;
6251 
6252  /* Transmit initial values of interesting variables */
6253  for (i = 0; i < num_guc_variables; i++)
6254  {
6255  struct config_generic *conf = guc_variables[i];
6256 
6257  if (conf->flags & GUC_REPORT)
6258  ReportGUCOption(conf);
6259  }
6260 }
#define PG_PROTOCOL_MAJOR(v)
Definition: pqcomm.h:104
static int num_guc_variables
Definition: guc.c:4815
#define GUC_REPORT
Definition: guc.h:208
static struct config_generic ** guc_variables
Definition: guc.c:4812
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:6266
CommandDest whereToSendOutput
Definition: postgres.c:91
static bool reporting_enabled
Definition: guc.c:4823
ProtocolVersion FrontendProtocol
Definition: globals.c:28

◆ build_guc_variables()

void build_guc_variables ( void  )

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

5077 {
5078  int size_vars;
5079  int num_vars = 0;
5080  struct config_generic **guc_vars;
5081  int i;
5082 
5083  for (i = 0; ConfigureNamesBool[i].gen.name; i++)
5084  {
5085  struct config_bool *conf = &ConfigureNamesBool[i];
5086 
5087  /* Rather than requiring vartype to be filled in by hand, do this: */
5088  conf->gen.vartype = PGC_BOOL;
5089  num_vars++;
5090  }
5091 
5092  for (i = 0; ConfigureNamesInt[i].gen.name; i++)
5093  {
5094  struct config_int *conf = &ConfigureNamesInt[i];
5095 
5096  conf->gen.vartype = PGC_INT;
5097  num_vars++;
5098  }
5099 
5100  for (i = 0; ConfigureNamesReal[i].gen.name; i++)
5101  {
5102  struct config_real *conf = &ConfigureNamesReal[i];
5103 
5104  conf->gen.vartype = PGC_REAL;
5105  num_vars++;
5106  }
5107 
5108  for (i = 0; ConfigureNamesString[i].gen.name; i++)
5109  {
5110  struct config_string *conf = &ConfigureNamesString[i];
5111 
5112  conf->gen.vartype = PGC_STRING;
5113  num_vars++;
5114  }
5115 
5116  for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
5117  {
5118  struct config_enum *conf = &ConfigureNamesEnum[i];
5119 
5120  conf->gen.vartype = PGC_ENUM;
5121  num_vars++;
5122  }
5123 
5124  /*
5125  * Create table with 20% slack
5126  */
5127  size_vars = num_vars + num_vars / 4;
5128 
5129  guc_vars = (struct config_generic **)
5130  guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
5131 
5132  num_vars = 0;
5133 
5134  for (i = 0; ConfigureNamesBool[i].gen.name; i++)
5135  guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
5136 
5137  for (i = 0; ConfigureNamesInt[i].gen.name; i++)
5138  guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
5139 
5140  for (i = 0; ConfigureNamesReal[i].gen.name; i++)
5141  guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
5142 
5143  for (i = 0; ConfigureNamesString[i].gen.name; i++)
5144  guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
5145 
5146  for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
5147  guc_vars[num_vars++] = &ConfigureNamesEnum[i].gen;
5148 
5149  if (guc_variables)
5151  guc_variables = guc_vars;
5152  num_guc_variables = num_vars;
5153  size_guc_variables = size_vars;
5155  sizeof(struct config_generic *), guc_var_compare);
5156 }
static struct config_int ConfigureNamesInt[]
Definition: guc.c:2046
const char * name
Definition: guc_tables.h:149
static struct config_enum ConfigureNamesEnum[]
Definition: guc.c:4458
static struct config_bool ConfigureNamesBool[]
Definition: guc.c:928
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:5298
static int num_guc_variables
Definition: guc.c:4815
#define FATAL
Definition: elog.h:52
struct config_generic gen
Definition: guc_tables.h:182
struct config_generic gen
Definition: guc_tables.h:196
static struct config_generic ** guc_variables
Definition: guc.c:4812
enum config_type vartype
Definition: guc_tables.h:156
static int size_guc_variables
Definition: guc.c:4818
static struct config_real ConfigureNamesReal[]
Definition: guc.c:3409
struct config_generic gen
Definition: guc_tables.h:242
struct config_generic gen
Definition: guc_tables.h:228
#define free(a)
Definition: header.h:65
static struct config_string ConfigureNamesString[]
Definition: guc.c:3689
int i
#define qsort(a, b, c, d)
Definition: port.h:479
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4853
struct config_generic gen
Definition: guc_tables.h:212

◆ call_bool_check_hook()

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

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

10943 {
10944  /* Quick success if no hook */
10945  if (!conf->check_hook)
10946  return true;
10947 
10948  /* Reset variables that might be set by hook */
10949  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
10950  GUC_check_errmsg_string = NULL;
10952  GUC_check_errhint_string = NULL;
10953 
10954  if (!conf->check_hook(newval, extra, source))
10955  {
10956  ereport(elevel,
10960  errmsg("invalid value for parameter \"%s\": %d",
10961  conf->gen.name, (int) *newval),
10965  errhint("%s", GUC_check_errhint_string) : 0));
10966  /* Flush any strings created in ErrorContext */
10967  FlushErrorState();
10968  return false;
10969  }
10970 
10971  return true;
10972 }
char * GUC_check_errhint_string
Definition: guc.c:146
GucSource source
Definition: guc_tables.h:158
int errhint(const char *fmt,...)
Definition: elog.c:1071
const char * name
Definition: guc_tables.h:149
int errcode(int sqlerrcode)
Definition: elog.c:610
static int GUC_check_errcode_value
Definition: guc.c:141
void FlushErrorState(void)
Definition: elog.c:1568
int errdetail_internal(const char *fmt,...)
Definition: elog.c:984
struct config_generic gen
Definition: guc_tables.h:182
char * GUC_check_errdetail_string
Definition: guc.c:145
static int elevel
Definition: vacuumlazy.c:330
GucBoolCheckHook check_hook
Definition: guc_tables.h:186
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg_internal(const char *fmt,...)
Definition: elog.c:911
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:144
int errmsg(const char *fmt,...)
Definition: elog.c:824

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

11079 {
11080  /* Quick success if no hook */
11081  if (!conf->check_hook)
11082  return true;
11083 
11084  /* Reset variables that might be set by hook */
11085  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
11086  GUC_check_errmsg_string = NULL;
11088  GUC_check_errhint_string = NULL;
11089 
11090  if (!conf->check_hook(newval, extra, source))
11091  {
11092  ereport(elevel,
11096  errmsg("invalid value for parameter \"%s\": \"%s\"",
11097  conf->gen.name,
11102  errhint("%s", GUC_check_errhint_string) : 0));
11103  /* Flush any strings created in ErrorContext */
11104  FlushErrorState();
11105  return false;
11106  }
11107 
11108  return true;
11109 }
char * GUC_check_errhint_string
Definition: guc.c:146
GucSource source
Definition: guc_tables.h:158
GucEnumCheckHook check_hook
Definition: guc_tables.h:247
int errhint(const char *fmt,...)
Definition: elog.c:1071
const char * name
Definition: guc_tables.h:149
int errcode(int sqlerrcode)
Definition: elog.c:610
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:6645
static int GUC_check_errcode_value
Definition: guc.c:141
void FlushErrorState(void)
Definition: elog.c:1568
int errdetail_internal(const char *fmt,...)
Definition: elog.c:984
char * GUC_check_errdetail_string
Definition: guc.c:145
static int elevel
Definition: vacuumlazy.c:330
struct config_generic gen
Definition: guc_tables.h:242
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg_internal(const char *fmt,...)
Definition: elog.c:911
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:144
int errmsg(const char *fmt,...)
Definition: elog.c:824

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

10977 {
10978  /* Quick success if no hook */
10979  if (!conf->check_hook)
10980  return true;
10981 
10982  /* Reset variables that might be set by hook */
10983  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
10984  GUC_check_errmsg_string = NULL;
10986  GUC_check_errhint_string = NULL;
10987 
10988  if (!conf->check_hook(newval, extra, source))
10989  {
10990  ereport(elevel,
10994  errmsg("invalid value for parameter \"%s\": %d",
10995  conf->gen.name, *newval),
10999  errhint("%s", GUC_check_errhint_string) : 0));
11000  /* Flush any strings created in ErrorContext */
11001  FlushErrorState();
11002  return false;
11003  }
11004 
11005  return true;
11006 }
char * GUC_check_errhint_string
Definition: guc.c:146
GucSource source
Definition: guc_tables.h:158
int errhint(const char *fmt,...)
Definition: elog.c:1071
const char * name
Definition: guc_tables.h:149
int errcode(int sqlerrcode)
Definition: elog.c:610
static int GUC_check_errcode_value
Definition: guc.c:141
GucIntCheckHook check_hook
Definition: guc_tables.h:202
void FlushErrorState(void)
Definition: elog.c:1568
int errdetail_internal(const char *fmt,...)
Definition: elog.c:984
struct config_generic gen
Definition: guc_tables.h:196
char * GUC_check_errdetail_string
Definition: guc.c:145
static int elevel
Definition: vacuumlazy.c:330
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg_internal(const char *fmt,...)
Definition: elog.c:911
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:144
int errmsg(const char *fmt,...)
Definition: elog.c:824

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

11011 {
11012  /* Quick success if no hook */
11013  if (!conf->check_hook)
11014  return true;
11015 
11016  /* Reset variables that might be set by hook */
11017  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
11018  GUC_check_errmsg_string = NULL;
11020  GUC_check_errhint_string = NULL;
11021 
11022  if (!conf->check_hook(newval, extra, source))
11023  {
11024  ereport(elevel,
11028  errmsg("invalid value for parameter \"%s\": %g",
11029  conf->gen.name, *newval),
11033  errhint("%s", GUC_check_errhint_string) : 0));
11034  /* Flush any strings created in ErrorContext */
11035  FlushErrorState();
11036  return false;
11037  }
11038 
11039  return true;
11040 }
char * GUC_check_errhint_string
Definition: guc.c:146
GucSource source
Definition: guc_tables.h:158
int errhint(const char *fmt,...)
Definition: elog.c:1071
const char * name
Definition: guc_tables.h:149
int errcode(int sqlerrcode)
Definition: elog.c:610
static int GUC_check_errcode_value
Definition: guc.c:141
GucRealCheckHook check_hook
Definition: guc_tables.h:218
void FlushErrorState(void)
Definition: elog.c:1568
int errdetail_internal(const char *fmt,...)
Definition: elog.c:984
char * GUC_check_errdetail_string
Definition: guc.c:145
static int elevel
Definition: vacuumlazy.c:330
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg_internal(const char *fmt,...)
Definition: elog.c:911
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
struct config_generic gen
Definition: guc_tables.h:212

◆ call_string_check_hook()

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

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

11045 {
11046  /* Quick success if no hook */
11047  if (!conf->check_hook)
11048  return true;
11049 
11050  /* Reset variables that might be set by hook */
11051  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
11052  GUC_check_errmsg_string = NULL;
11054  GUC_check_errhint_string = NULL;
11055 
11056  if (!conf->check_hook(newval, extra, source))
11057  {
11058  ereport(elevel,
11062  errmsg("invalid value for parameter \"%s\": \"%s\"",
11063  conf->gen.name, *newval ? *newval : ""),
11067  errhint("%s", GUC_check_errhint_string) : 0));
11068  /* Flush any strings created in ErrorContext */
11069  FlushErrorState();
11070  return false;
11071  }
11072 
11073  return true;
11074 }
char * GUC_check_errhint_string
Definition: guc.c:146
GucSource source
Definition: guc_tables.h:158
int errhint(const char *fmt,...)
Definition: elog.c:1071
const char * name
Definition: guc_tables.h:149
GucStringCheckHook check_hook
Definition: guc_tables.h:232
int errcode(int sqlerrcode)
Definition: elog.c:610
static int GUC_check_errcode_value
Definition: guc.c:141
void FlushErrorState(void)
Definition: elog.c:1568
int errdetail_internal(const char *fmt,...)
Definition: elog.c:984
char * GUC_check_errdetail_string
Definition: guc.c:145
static int elevel
Definition: vacuumlazy.c:330
#define ereport(elevel,...)
Definition: elog.h:144
struct config_generic gen
Definition: guc_tables.h:228
int errmsg_internal(const char *fmt,...)
Definition: elog.c:911
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:144
int errmsg(const char *fmt,...)
Definition: elog.c:824

◆ can_skip_gucvar()

static bool can_skip_gucvar ( struct config_generic gconf)
static

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

10122 {
10123  return gconf->context == PGC_POSTMASTER ||
10124  gconf->context == PGC_INTERNAL || gconf->source == PGC_S_DEFAULT ||
10125  strcmp(gconf->name, "role") == 0;
10126 }
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 11641 of file guc.c.

References pg_clean_ascii().

11642 {
11643  /* Only allow clean ASCII chars in the application name */
11645 
11646  return true;
11647 }
#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 11522 of file guc.c.

References MAX_BACKENDS, max_wal_senders, max_worker_processes, and MaxConnections.

11523 {
11524  if (MaxConnections + *newval + 1 +
11526  return false;
11527  return true;
11528 }
#define MAX_BACKENDS
Definition: postmaster.h:75
int max_wal_senders
Definition: walsender.c:121
int MaxConnections
Definition: globals.c:133
#define newval
int max_worker_processes
Definition: globals.c:134

◆ check_autovacuum_work_mem()

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

Definition at line 11540 of file guc.c.

11541 {
11542  /*
11543  * -1 indicates fallback.
11544  *
11545  * If we haven't yet changed the boot_val default of -1, just let it be.
11546  * Autovacuum will look to maintenance_work_mem instead.
11547  */
11548  if (*newval == -1)
11549  return true;
11550 
11551  /*
11552  * We clamp manually-set values to at least 1MB. Since
11553  * maintenance_work_mem is always set to at least this value, do the same
11554  * here.
11555  */
11556  if (*newval < 1024)
11557  *newval = 1024;
11558 
11559  return true;
11560 }
#define newval

◆ check_backtrace_functions()

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

Definition at line 11701 of file guc.c.

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

11702 {
11703  int newvallen = strlen(*newval);
11704  char *someval;
11705  int validlen;
11706  int i;
11707  int j;
11708 
11709  /*
11710  * Allow characters that can be C identifiers and commas as separators, as
11711  * well as some whitespace for readability.
11712  */
11713  validlen = strspn(*newval,
11714  "0123456789_"
11715  "abcdefghijklmnopqrstuvwxyz"
11716  "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
11717  ", \n\t");
11718  if (validlen != newvallen)
11719  {
11720  GUC_check_errdetail("invalid character");
11721  return false;
11722  }
11723 
11724  if (*newval[0] == '\0')
11725  {
11726  *extra = NULL;
11727  return true;
11728  }
11729 
11730  /*
11731  * Allocate space for the output and create the copy. We could discount
11732  * whitespace chars to save some memory, but it doesn't seem worth the
11733  * trouble.
11734  */
11735  someval = guc_malloc(ERROR, newvallen + 1 + 1);
11736  for (i = 0, j = 0; i < newvallen; i++)
11737  {
11738  if ((*newval)[i] == ',')
11739  someval[j++] = '\0'; /* next item */
11740  else if ((*newval)[i] == ' ' ||
11741  (*newval)[i] == '\n' ||
11742  (*newval)[i] == '\t')
11743  ; /* ignore these */
11744  else
11745  someval[j++] = (*newval)[i]; /* copy anything else */
11746  }
11747 
11748  /* two \0s end the setting */
11749  someval[j] = '\0';
11750  someval[j + 1] = '\0';
11751 
11752  *extra = someval;
11753  return true;
11754 }
#define GUC_check_errdetail
Definition: guc.h:415
#define ERROR
Definition: elog.h:43
#define newval
int i
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4853

◆ check_bonjour()

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

Definition at line 11305 of file guc.c.

References GUC_check_errmsg.

11306 {
11307 #ifndef USE_BONJOUR
11308  if (*newval)
11309  {
11310  GUC_check_errmsg("Bonjour is not supported by this build");
11311  return false;
11312  }
11313 #endif
11314  return true;
11315 }
#define GUC_check_errmsg
Definition: guc.h:411
#define newval

◆ check_canonical_path()

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

Definition at line 11356 of file guc.c.

References canonicalize_path().

11357 {
11358  /*
11359  * Since canonicalize_path never enlarges the string, we can just modify
11360  * newval in-place. But watch out for NULL, which is the default value
11361  * for external_pid_file.
11362  */
11363  if (*newval)
11365  return true;
11366 }
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 11657 of file guc.c.

References pg_clean_ascii().

11658 {
11659  /* Only allow clean ASCII chars in the cluster name */
11661 
11662  return true;
11663 }
#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 12030 of file guc.c.

References GUC_check_errcode(), and GUC_check_errmsg.

12031 {
12032  if (*newval)
12033  {
12034  /* check the GUC's definition for an explanation */
12035  GUC_check_errcode(ERRCODE_FEATURE_NOT_SUPPORTED);
12036  GUC_check_errmsg("tables declared WITH OIDS are not supported");
12037 
12038  return false;
12039  }
12040 
12041  return true;
12042 }
#define GUC_check_errmsg
Definition: guc.h:411
void GUC_check_errcode(int sqlerrcode)
Definition: guc.c:10928
#define newval

◆ check_effective_io_concurrency()

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

Definition at line 11572 of file guc.c.

References GUC_check_errdetail.

11573 {
11574 #ifndef USE_PREFETCH
11575  if (*newval != 0)
11576  {
11577  GUC_check_errdetail("effective_io_concurrency must be set to 0 on platforms that lack posix_fadvise().");
11578  return false;
11579  }
11580 #endif /* USE_PREFETCH */
11581  return true;
11582 }
#define GUC_check_errdetail
Definition: guc.h:415
#define newval

◆ check_huge_page_size()

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

Definition at line 11598 of file guc.c.

References GUC_check_errdetail.

11599 {
11600 #if !(defined(MAP_HUGE_MASK) && defined(MAP_HUGE_SHIFT))
11601  /* Recent enough Linux only, for now. See GetHugePageSize(). */
11602  if (*newval != 0)
11603  {
11604  GUC_check_errdetail("huge_page_size must be 0 on this platform.");
11605  return false;
11606  }
11607 #endif
11608  return true;
11609 }
#define GUC_check_errdetail
Definition: guc.h:415
#define newval

◆ check_log_destination()

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

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

11198 {
11199  char *rawstring;
11200  List *elemlist;
11201  ListCell *l;
11202  int newlogdest = 0;
11203  int *myextra;
11204 
11205  /* Need a modifiable copy of string */
11206  rawstring = pstrdup(*newval);
11207 
11208  /* Parse string into list of identifiers */
11209  if (!SplitIdentifierString(rawstring, ',', &elemlist))
11210  {
11211  /* syntax error in list */
11212  GUC_check_errdetail("List syntax is invalid.");
11213  pfree(rawstring);
11214  list_free(elemlist);
11215  return false;
11216  }
11217 
11218  foreach(l, elemlist)
11219  {
11220  char *tok = (char *) lfirst(l);
11221 
11222  if (pg_strcasecmp(tok, "stderr") == 0)
11223  newlogdest |= LOG_DESTINATION_STDERR;
11224  else if (pg_strcasecmp(tok, "csvlog") == 0)
11225  newlogdest |= LOG_DESTINATION_CSVLOG;
11226 #ifdef HAVE_SYSLOG
11227  else if (pg_strcasecmp(tok, "syslog") == 0)
11228  newlogdest |= LOG_DESTINATION_SYSLOG;
11229 #endif
11230 #ifdef WIN32
11231  else if (pg_strcasecmp(tok, "eventlog") == 0)
11232  newlogdest |= LOG_DESTINATION_EVENTLOG;
11233 #endif
11234  else
11235  {
11236  GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
11237  pfree(rawstring);
11238  list_free(elemlist);
11239  return false;
11240  }
11241  }
11242 
11243  pfree(rawstring);
11244  list_free(elemlist);
11245 
11246  myextra = (int *) guc_malloc(ERROR, sizeof(int));
11247  *myextra = newlogdest;
11248  *extra = (void *) myextra;
11249 
11250  return true;
11251 }
#define LOG_DESTINATION_EVENTLOG
Definition: elog.h:420
#define GUC_check_errdetail
Definition: guc.h:415
char * pstrdup(const char *in)
Definition: mcxt.c:1186
#define LOG_DESTINATION_SYSLOG
Definition: elog.h:419
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
void pfree(void *pointer)
Definition: mcxt.c:1056
#define ERROR
Definition: elog.h:43
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3686
#define LOG_DESTINATION_CSVLOG
Definition: elog.h:421
#define LOG_DESTINATION_STDERR
Definition: elog.h:418
#define lfirst(lc)
Definition: pg_list.h:190
#define newval
void list_free(List *list)
Definition: list.c:1376
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4853
Definition: pg_list.h:50

◆ check_log_stats()

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

Definition at line 11342 of file guc.c.

References GUC_check_errdetail.

11343 {
11344  if (*newval &&
11346  {
11347  GUC_check_errdetail("Cannot enable \"log_statement_stats\" when "
11348  "\"log_parser_stats\", \"log_planner_stats\", "
11349  "or \"log_executor_stats\" is true.");
11350  return false;
11351  }
11352  return true;
11353 }
bool log_parser_stats
Definition: guc.c:519
#define GUC_check_errdetail
Definition: guc.h:415
#define newval
bool log_executor_stats
Definition: guc.c:521
bool log_planner_stats
Definition: guc.c:520

◆ check_maintenance_io_concurrency()

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

Definition at line 11585 of file guc.c.

References GUC_check_errdetail.

11586 {
11587 #ifndef USE_PREFETCH
11588  if (*newval != 0)
11589  {
11590  GUC_check_errdetail("maintenance_io_concurrency must be set to 0 on platforms that lack posix_fadvise().");
11591  return false;
11592  }
11593 #endif /* USE_PREFETCH */
11594  return true;
11595 }
#define GUC_check_errdetail
Definition: guc.h:415
#define newval

◆ check_max_wal_senders()

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

Definition at line 11531 of file guc.c.

References autovacuum_max_workers, MAX_BACKENDS, max_worker_processes, and MaxConnections.

11532 {
11535  return false;
11536  return true;
11537 }
#define MAX_BACKENDS
Definition: postmaster.h:75
int MaxConnections
Definition: globals.c:133
int autovacuum_max_workers
Definition: autovacuum.c:115
#define newval
int max_worker_processes
Definition: globals.c:134

◆ check_max_worker_processes()

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

Definition at line 11563 of file guc.c.

References autovacuum_max_workers, MAX_BACKENDS, max_wal_senders, and MaxConnections.

11564 {
11567  return false;
11568  return true;
11569 }
#define MAX_BACKENDS
Definition: postmaster.h:75
int max_wal_senders
Definition: walsender.c:121
int MaxConnections
Definition: globals.c:133
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 11513 of file guc.c.

References autovacuum_max_workers, MAX_BACKENDS, max_wal_senders, and max_worker_processes.

11514 {
11515  if (*newval + autovacuum_max_workers + 1 +
11517  return false;
11518  return true;
11519 }
#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:134

◆ check_primary_slot_name()

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

Definition at line 12020 of file guc.c.

References ReplicationSlotValidateName(), and WARNING.

12021 {
12022  if (*newval && strcmp(*newval, "") != 0 &&
12024  return false;
12025 
12026  return true;
12027 }
bool ReplicationSlotValidateName(const char *name, int elevel)
Definition: slot.c:175
#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 11825 of file guc.c.

References GUC_check_errdetail.

11826 {
11827  if (strcmp(*newval, "immediate") != 0 && strcmp(*newval, "") != 0)
11828  {
11829  GUC_check_errdetail("The only allowed value is \"immediate\".");
11830  return false;
11831  }
11832  return true;
11833 }
#define GUC_check_errdetail
Definition: guc.h:415
#define newval

◆ check_recovery_target_lsn()

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

Definition at line 11984 of file guc.c.

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

11985 {
11986  if (strcmp(*newval, "") != 0)
11987  {
11988  XLogRecPtr lsn;
11989  XLogRecPtr *myextra;
11990  bool have_error = false;
11991 
11992  lsn = pg_lsn_in_internal(*newval, &have_error);
11993  if (have_error)
11994  return false;
11995 
11996  myextra = (XLogRecPtr *) guc_malloc(ERROR, sizeof(XLogRecPtr));
11997  *myextra = lsn;
11998  *extra = (void *) myextra;
11999  }
12000  return true;
12001 }
#define ERROR
Definition: elog.h:43
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:4853

◆ check_recovery_target_name()

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

Definition at line 11955 of file guc.c.

References GUC_check_errdetail, and MAXFNAMELEN.

11956 {
11957  /* Use the value of newval directly */
11958  if (strlen(*newval) >= MAXFNAMELEN)
11959  {
11960  GUC_check_errdetail("%s is too long (maximum %d characters).",
11961  "recovery_target_name", MAXFNAMELEN - 1);
11962  return false;
11963  }
11964  return true;
11965 }
#define GUC_check_errdetail
Definition: guc.h:415
#define MAXFNAMELEN
#define newval

◆ check_recovery_target_time()

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

Definition at line 11892 of file guc.c.

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

11893 {
11894  if (strcmp(*newval, "") != 0)
11895  {
11896  /* reject some special values */
11897  if (strcmp(*newval, "now") == 0 ||
11898  strcmp(*newval, "today") == 0 ||
11899  strcmp(*newval, "tomorrow") == 0 ||
11900  strcmp(*newval, "yesterday") == 0)
11901  {
11902  return false;
11903  }
11904 
11905  /*
11906  * parse timestamp value (see also timestamptz_in())
11907  */
11908  {
11909  char *str = *newval;
11910  fsec_t fsec;
11911  struct pg_tm tt,
11912  *tm = &tt;
11913  int tz;
11914  int dtype;
11915  int nf;
11916  int dterr;
11917  char *field[MAXDATEFIELDS];
11918  int ftype[MAXDATEFIELDS];
11919  char workbuf[MAXDATELEN + MAXDATEFIELDS];
11921 
11922  dterr = ParseDateTime(str, workbuf, sizeof(workbuf),
11923  field, ftype, MAXDATEFIELDS, &nf);
11924  if (dterr == 0)
11925  dterr = DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tz);
11926  if (dterr != 0)
11927  return false;
11928  if (dtype != DTK_DATE)
11929  return false;
11930 
11931  if (tm2timestamp(tm, fsec, &tz, &timestamp) != 0)
11932  {
11933  GUC_check_errdetail("timestamp out of range: \"%s\"", str);
11934  return false;
11935  }
11936  }
11937  }
11938  return true;
11939 }
#define MAXDATELEN
Definition: datetime.h:201
#define GUC_check_errdetail
Definition: guc.h:415
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:758
int32 fsec_t
Definition: timestamp.h:41
int tm2timestamp(struct pg_tm *tm, fsec_t fsec, int *tzp, Timestamp *result)
Definition: timestamp.c:1880
#define MAXDATEFIELDS
Definition: datetime.h:203
#define newval
int ParseDateTime(const char *timestr, char *workbuf, size_t buflen, char **field, int *ftype, int maxfields, int *numfields)
Definition: datetime.c:537
#define DTK_DATE
Definition: datetime.h:145

◆ check_recovery_target_timeline()

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

Definition at line 11763 of file guc.c.

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

11764 {
11766  RecoveryTargetTimeLineGoal *myextra;
11767 
11768  if (strcmp(*newval, "current") == 0)
11770  else if (strcmp(*newval, "latest") == 0)
11772  else
11773  {
11775 
11776  errno = 0;
11777  strtoul(*newval, NULL, 0);
11778  if (errno == EINVAL || errno == ERANGE)
11779  {
11780  GUC_check_errdetail("recovery_target_timeline is not a valid number.");
11781  return false;
11782  }
11783  }
11784 
11786  *myextra = rttg;
11787  *extra = (void *) myextra;
11788 
11789  return true;
11790 }
#define GUC_check_errdetail
Definition: guc.h:415
RecoveryTargetTimeLineGoal
Definition: xlog.h:93
#define ERROR
Definition: elog.h:43
#define newval
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4853

◆ check_recovery_target_xid()

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

Definition at line 11849 of file guc.c.

References ERROR, and guc_malloc().

11850 {
11851  if (strcmp(*newval, "") != 0)
11852  {
11853  TransactionId xid;
11854  TransactionId *myextra;
11855 
11856  errno = 0;
11857  xid = (TransactionId) strtoul(*newval, NULL, 0);
11858  if (errno == EINVAL || errno == ERANGE)
11859  return false;
11860 
11861  myextra = (TransactionId *) guc_malloc(ERROR, sizeof(TransactionId));
11862  *myextra = xid;
11863  *extra = (void *) myextra;
11864  }
11865  return true;
11866 }
uint32 TransactionId
Definition: c.h:520
#define ERROR
Definition: elog.h:43
#define newval
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4853

◆ check_ssl()

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

Definition at line 11318 of file guc.c.

References GUC_check_errmsg.

11319 {
11320 #ifndef USE_SSL
11321  if (*newval)
11322  {
11323  GUC_check_errmsg("SSL is not supported by this build");
11324  return false;
11325  }
11326 #endif
11327  return true;
11328 }
#define GUC_check_errmsg
Definition: guc.h:411
#define newval

◆ check_stage_log_stats()

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

Definition at line 11331 of file guc.c.

References GUC_check_errdetail.

11332 {
11333  if (*newval && log_statement_stats)
11334  {
11335  GUC_check_errdetail("Cannot enable parameter when \"log_statement_stats\" is true.");
11336  return false;
11337  }
11338  return true;
11339 }
bool log_statement_stats
Definition: guc.c:522
#define GUC_check_errdetail
Definition: guc.h:415
#define newval

◆ check_temp_buffers()

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

Definition at line 11291 of file guc.c.

References GUC_check_errdetail, and NLocBuffer.

11292 {
11293  /*
11294  * Once local buffers have been initialized, it's too late to change this.
11295  */
11296  if (NLocBuffer && NLocBuffer != *newval)
11297  {
11298  GUC_check_errdetail("\"temp_buffers\" cannot be changed after any temporary tables have been accessed in the session.");
11299  return false;
11300  }
11301  return true;
11302 }
#define GUC_check_errdetail
Definition: guc.h:415
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 11369 of file guc.c.

References Assert, load_tzoffsets(), and PGC_S_DEFAULT.

11370 {
11371  /*
11372  * The boot_val given above for timezone_abbreviations is NULL. When we
11373  * see this we just do nothing. If this value isn't overridden from the
11374  * config file then pg_timezone_abbrev_initialize() will eventually
11375  * replace it with "Default". This hack has two purposes: to avoid
11376  * wasting cycles loading values that might soon be overridden from the
11377  * config file, and to avoid trying to read the timezone abbrev files
11378  * during InitializeGUCOptions(). The latter doesn't work in an
11379  * EXEC_BACKEND subprocess because my_exec_path hasn't been set yet and so
11380  * we can't locate PGSHAREDIR.
11381  */
11382  if (*newval == NULL)
11383  {
11384  Assert(source == PGC_S_DEFAULT);
11385  return true;
11386  }
11387 
11388  /* OK, load the file and produce a malloc'd TimeZoneAbbrevTable */
11389  *extra = load_tzoffsets(*newval);
11390 
11391  /* tzparser.c returns NULL on failure, reporting via GUC_check_errmsg */
11392  if (!*extra)
11393  return false;
11394 
11395  return true;
11396 }
TimeZoneAbbrevTable * load_tzoffsets(const char *filename)
Definition: tzparser.c:437
#define Assert(condition)
Definition: c.h:745
#define newval

◆ check_wal_consistency_checking()

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

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

11118 {
11119  char *rawstring;
11120  List *elemlist;
11121  ListCell *l;
11122  bool newwalconsistency[RM_MAX_ID + 1];
11123 
11124  /* Initialize the array */
11125  MemSet(newwalconsistency, 0, (RM_MAX_ID + 1) * sizeof(bool));
11126 
11127  /* Need a modifiable copy of string */
11128  rawstring = pstrdup(*newval);
11129 
11130  /* Parse string into list of identifiers */
11131  if (!SplitIdentifierString(rawstring, ',', &elemlist))
11132  {
11133  /* syntax error in list */
11134  GUC_check_errdetail("List syntax is invalid.");
11135  pfree(rawstring);
11136  list_free(elemlist);
11137  return false;
11138  }
11139 
11140  foreach(l, elemlist)
11141  {
11142  char *tok = (char *) lfirst(l);
11143  bool found = false;
11144  RmgrId rmid;
11145 
11146  /* Check for 'all'. */
11147  if (pg_strcasecmp(tok, "all") == 0)
11148  {
11149  for (rmid = 0; rmid <= RM_MAX_ID; rmid++)
11150  if (RmgrTable[rmid].rm_mask != NULL)
11151  newwalconsistency[rmid] = true;
11152  found = true;
11153  }
11154  else
11155  {
11156  /*
11157  * Check if the token matches with any individual resource
11158  * manager.
11159  */
11160  for (rmid = 0; rmid <= RM_MAX_ID; rmid++)
11161  {
11162  if (pg_strcasecmp(tok, RmgrTable[rmid].rm_name) == 0 &&
11163  RmgrTable[rmid].rm_mask != NULL)
11164  {
11165  newwalconsistency[rmid] = true;
11166  found = true;
11167  }
11168  }
11169  }
11170 
11171  /* If a valid resource manager is found, check for the next one. */
11172  if (!found)
11173  {
11174  GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
11175  pfree(rawstring);
11176  list_free(elemlist);
11177  return false;
11178  }
11179  }
11180 
11181  pfree(rawstring);
11182  list_free(elemlist);
11183 
11184  /* assign new value */
11185  *extra = guc_malloc(ERROR, (RM_MAX_ID + 1) * sizeof(bool));
11186  memcpy(*extra, newwalconsistency, (RM_MAX_ID + 1) * sizeof(bool));
11187  return true;
11188 }
#define GUC_check_errdetail
Definition: guc.h:415
char * pstrdup(const char *in)
Definition: mcxt.c:1186
const RmgrData RmgrTable[RM_MAX_ID+1]
Definition: rmgr.c:36
#define MemSet(start, val, len)
Definition: c.h:949
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
void pfree(void *pointer)
Definition: mcxt.c:1056
#define ERROR
Definition: elog.h:43
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3686
#define RM_MAX_ID
Definition: rmgr.h:33
void(* rm_mask)(char *pagedata, BlockNumber blkno)
uint8 RmgrId
Definition: rmgr.h:11
#define lfirst(lc)
Definition: pg_list.h:190
#define newval
void list_free(List *list)
Definition: list.c:1376
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4853
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 6694 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().

6696 {
6697  const struct config_enum_entry *entry;
6698  StringInfoData retstr;
6699  int seplen;
6700 
6701  initStringInfo(&retstr);
6702  appendStringInfoString(&retstr, prefix);
6703 
6704  seplen = strlen(separator);
6705  for (entry = record->options; entry && entry->name; entry++)
6706  {
6707  if (!entry->hidden)
6708  {
6709  appendStringInfoString(&retstr, entry->name);
6710  appendBinaryStringInfo(&retstr, separator, seplen);
6711  }
6712  }
6713 
6714  /*
6715  * All the entries may have been hidden, leaving the string empty if no
6716  * prefix was given. This indicates a broken GUC setup, since there is no
6717  * use for an enum without any values, so we just check to make sure we
6718  * don't write to invalid memory instead of actually trying to do
6719  * something smart with it.
6720  */
6721  if (retstr.len >= seplen)
6722  {
6723  /* Replace final separator */
6724  retstr.data[retstr.len - seplen] = '\0';
6725  retstr.len -= seplen;
6726  }
6727 
6728  appendStringInfoString(&retstr, suffix);
6729 
6730  return retstr.data;
6731 }
Definition: guc.h:164
const struct config_enum_entry * options
Definition: guc_tables.h:246
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
const char * name
Definition: guc.h:166
void appendBinaryStringInfo(StringInfo str, const char *data, int datalen)
Definition: stringinfo.c:227
bool hidden
Definition: guc.h:168

◆ config_enum_lookup_by_name()

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

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

6670 {
6671  const struct config_enum_entry *entry;
6672 
6673  for (entry = record->options; entry && entry->name; entry++)
6674  {
6675  if (pg_strcasecmp(value, entry->name) == 0)
6676  {
6677  *retval = entry->val;
6678  return true;
6679  }
6680  }
6681 
6682  *retval = 0;
6683  return false;
6684 }
Definition: guc.h:164
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
const struct config_enum_entry * options
Definition: guc_tables.h:246
int val
Definition: guc.h:167
static struct @143 value
const char * name
Definition: guc.h:166

◆ config_enum_lookup_by_value()

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

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

6646 {
6647  const struct config_enum_entry *entry;
6648 
6649  for (entry = record->options; entry && entry->name; entry++)
6650  {
6651  if (entry->val == val)
6652  return entry->name;
6653  }
6654 
6655  elog(ERROR, "could not find enum option %d for %s",
6656  val, record->gen.name);
6657  return NULL; /* silence compiler */
6658 }
Definition: guc.h:164
const char * name
Definition: guc_tables.h:149
#define ERROR
Definition: elog.h:43
const struct config_enum_entry * options
Definition: guc_tables.h:246
int val
Definition: guc.h:167
struct config_generic gen
Definition: guc_tables.h:242
const char * name
Definition: guc.h:166
#define elog(elevel,...)
Definition: elog.h:214
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 6351 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().

6353 {
6354  const unit_conversion *table;
6355  int i;
6356 
6357  *unit = NULL;
6358 
6359  if (base_unit & GUC_UNIT_MEMORY)
6361  else
6363 
6364  for (i = 0; *table[i].unit; i++)
6365  {
6366  if (base_unit == table[i].base_unit)
6367  {
6368  /*
6369  * Accept the first conversion that divides the value evenly. We
6370  * assume that the conversions for each base unit are ordered from
6371  * greatest unit to the smallest!
6372  */
6373  if (table[i].multiplier <= 1.0 ||
6374  base_value % (int64) table[i].multiplier == 0)
6375  {
6376  *value = (int64) rint(base_value / table[i].multiplier);
6377  *unit = table[i].unit;
6378  break;
6379  }
6380  }
6381  }
6382 
6383  Assert(*unit != NULL);
6384 }
static const unit_conversion time_unit_conversion_table[]
Definition: guc.c:872
static const unit_conversion memory_unit_conversion_table[]
Definition: guc.c:835
static struct @143 value
#define Assert(condition)
Definition: c.h:745
int i
char unit[MAX_UNIT_LEN+1]
Definition: guc.c:819
#define GUC_UNIT_MEMORY
Definition: guc.h:223

◆ convert_real_from_base_unit()

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

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

6395 {
6396  const unit_conversion *table;
6397  int i;
6398 
6399  *unit = NULL;
6400 
6401  if (base_unit & GUC_UNIT_MEMORY)
6403  else
6405 
6406  for (i = 0; *table[i].unit; i++)
6407  {
6408  if (base_unit == table[i].base_unit)
6409  {
6410  /*
6411  * Accept the first conversion that divides the value evenly; or
6412  * if there is none, use the smallest (last) target unit.
6413  *
6414  * What we actually care about here is whether snprintf with "%g"
6415  * will print the value as an integer, so the obvious test of
6416  * "*value == rint(*value)" is too strict; roundoff error might
6417  * make us choose an unreasonably small unit. As a compromise,
6418  * accept a divisor that is within 1e-8 of producing an integer.
6419  */
6420  *value = base_value / table[i].multiplier;
6421  *unit = table[i].unit;
6422  if (*value > 0 &&
6423  fabs((rint(*value) / *value) - 1.0) <= 1e-8)
6424  break;
6425  }
6426  }
6427 
6428  Assert(*unit != NULL);
6429 }
static const unit_conversion time_unit_conversion_table[]
Definition: guc.c:872
static const unit_conversion memory_unit_conversion_table[]
Definition: guc.c:835
static struct @143 value
#define Assert(condition)
Definition: c.h:745
double multiplier
Definition: guc.c:822
e
Definition: preproc-init.c:82
int i
char unit[MAX_UNIT_LEN+1]
Definition: guc.c:819
#define GUC_UNIT_MEMORY
Definition: guc.h:223

◆ convert_to_base_unit()

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

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

6295 {
6296  char unitstr[MAX_UNIT_LEN + 1];
6297  int unitlen;
6298  const unit_conversion *table;
6299  int i;
6300 
6301  /* extract unit string to compare to table entries */
6302  unitlen = 0;
6303  while (*unit != '\0' && !isspace((unsigned char) *unit) &&
6304  unitlen < MAX_UNIT_LEN)
6305  unitstr[unitlen++] = *(unit++);
6306  unitstr[unitlen] = '\0';
6307  /* allow whitespace after unit */
6308  while (isspace((unsigned char) *unit))
6309  unit++;
6310  if (*unit != '\0')
6311  return false; /* unit too long, or garbage after it */
6312 
6313  /* now search the appropriate table */
6314  if (base_unit & GUC_UNIT_MEMORY)
6316  else
6318 
6319  for (i = 0; *table[i].unit; i++)
6320  {
6321  if (base_unit == table[i].base_unit &&
6322  strcmp(unitstr, table[i].unit) == 0)
6323  {
6324  double cvalue = value * table[i].multiplier;
6325 
6326  /*
6327  * If the user gave a fractional value such as "30.1GB", round it
6328  * off to the nearest multiple of the next smaller unit, if there
6329  * is one.
6330  */
6331  if (*table[i + 1].unit &&
6332  base_unit == table[i + 1].base_unit)
6333  cvalue = rint(cvalue / table[i + 1].multiplier) *
6334  table[i + 1].multiplier;
6335 
6336  *base_value = cvalue;
6337  return true;
6338  }
6339  }
6340  return false;
6341 }
static const unit_conversion time_unit_conversion_table[]
Definition: guc.c:872
static const unit_conversion memory_unit_conversion_table[]
Definition: guc.c:835
#define MAX_UNIT_LEN
Definition: guc.c:815
static struct @143 value
double multiplier
Definition: guc.c:822
int i
char unit[MAX_UNIT_LEN+1]
Definition: guc.c:819
#define GUC_UNIT_MEMORY
Definition: guc.h:223

◆ define_custom_variable()

static void define_custom_variable ( struct config_generic variable)
static

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

8620 {
8621  const char *name = variable->name;
8622  const char **nameAddr = &name;
8623  struct config_string *pHolder;
8624  struct config_generic **res;
8625 
8626  /*
8627  * See if there's a placeholder by the same name.
8628  */
8629  res = (struct config_generic **) bsearch((void *) &nameAddr,
8630  (void *) guc_variables,
8632  sizeof(struct config_generic *),
8633  guc_var_compare);
8634  if (res == NULL)
8635  {
8636  /*
8637  * No placeholder to replace, so we can just add it ... but first,
8638  * make sure it's initialized to its default value.
8639  */
8640  InitializeOneGUCOption(variable);
8641  add_guc_variable(variable, ERROR);
8642  return;
8643  }
8644 
8645  /*
8646  * This better be a placeholder
8647  */
8648  if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
8649  ereport(ERROR,
8650  (errcode(ERRCODE_INTERNAL_ERROR),
8651  errmsg("attempt to redefine parameter \"%s\"", name)));
8652 
8653  Assert((*res)->vartype == PGC_STRING);
8654  pHolder = (struct config_string *) (*res);
8655 
8656  /*
8657  * First, set the variable to its default value. We must do this even
8658  * though we intend to immediately apply a new value, since it's possible
8659  * that the new value is invalid.
8660  */
8661  InitializeOneGUCOption(variable);
8662 
8663  /*
8664  * Replace the placeholder. We aren't changing the name, so no re-sorting
8665  * is necessary
8666  */
8667  *res = variable;
8668 
8669  /*
8670  * Assign the string value(s) stored in the placeholder to the real
8671  * variable. Essentially, we need to duplicate all the active and stacked
8672  * values, but with appropriate validation and datatype adjustment.
8673  *
8674  * If an assignment fails, we report a WARNING and keep going. We don't
8675  * want to throw ERROR for bad values, because it'd bollix the add-on
8676  * module that's presumably halfway through getting loaded. In such cases
8677  * the default or previous state will become active instead.
8678  */
8679 
8680  /* First, apply the reset value if any */
8681  if (pHolder->reset_val)
8682  (void) set_config_option(name, pHolder->reset_val,
8683  pHolder->gen.reset_scontext,
8684  pHolder->gen.reset_source,
8685  GUC_ACTION_SET, true, WARNING, false);
8686  /* That should not have resulted in stacking anything */
8687  Assert(variable->stack == NULL);
8688 
8689  /* Now, apply current and stacked values, in the order they were stacked */
8690  reapply_stacked_values(variable, pHolder, pHolder->gen.stack,
8691  *(pHolder->variable),
8692  pHolder->gen.scontext, pHolder->gen.source);
8693 
8694  /* Also copy over any saved source-location information */
8695  if (pHolder->gen.sourcefile)
8696  set_config_sourcefile(name, pHolder->gen.sourcefile,
8697  pHolder->gen.sourceline);
8698 
8699  /*
8700  * Free up as much as we conveniently can of the placeholder structure.
8701  * (This neglects any stack items, so it's possible for some memory to be
8702  * leaked. Since this can only happen once per session per variable, it
8703  * doesn't seem worth spending much code on.)
8704  */
8705  set_string_field(pHolder, pHolder->variable, NULL);
8706  set_string_field(pHolder, &pHolder->reset_val, NULL);
8707 
8708  free(pHolder);
8709 }
GucSource source
Definition: guc_tables.h:158
static void static void set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
Definition: guc.c:7680
char ** variable
Definition: guc_tables.h:230
const char * name
Definition: guc_tables.h:149
static void reapply_stacked_values(struct config_generic *variable, struct config_string *pHolder, GucStack *stack, const char *curvalue, GucContext curscontext, GucSource cursource)
Definition: guc.c:8719
int errcode(int sqlerrcode)
Definition: elog.c:610
GucContext scontext
Definition: guc_tables.h:160
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:5298
#define ERROR
Definition: elog.h:43
static int num_guc_variables
Definition: guc.c:4815
char * sourcefile
Definition: guc_tables.h:164
GucSource reset_source
Definition: guc_tables.h:159
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:5446
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4925
static struct config_generic ** guc_variables
Definition: guc.c:4812
#define WARNING
Definition: elog.h:40
#define ereport(elevel,...)
Definition: elog.h:144
struct config_generic gen
Definition: guc_tables.h:228
#define free(a)
Definition: header.h:65
char * reset_val
Definition: guc_tables.h:236
#define Assert(condition)
Definition: c.h:745
#define GUC_CUSTOM_PLACEHOLDER
Definition: guc.h:211
const char * name
Definition: encode.c:561
int errmsg(const char *fmt,...)
Definition: elog.c:824
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:6949
static bool add_guc_variable(struct config_generic *var, int elevel)
Definition: guc.c:5163
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 8800 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().

8810 {
8811  struct config_bool *var;
8812 
8813  var = (struct config_bool *)
8814  init_custom_variable(name, short_desc, long_desc, context, flags,
8815  PGC_BOOL, sizeof(struct config_bool));
8816  var->variable = valueAddr;
8817  var->boot_val = bootValue;
8818  var->reset_val = bootValue;
8819  var->check_hook = check_hook;
8820  var->assign_hook = assign_hook;
8821  var->show_hook = show_hook;
8822  define_custom_variable(&var->gen);
8823 }
bool * variable
Definition: guc_tables.h:184
GucBoolAssignHook assign_hook
Definition: guc_tables.h:187
bool boot_val
Definition: guc_tables.h:185
struct config_generic gen
Definition: guc_tables.h:182
static struct config_generic * init_custom_variable(const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
Definition: guc.c:8559
GucBoolCheckHook check_hook
Definition: guc_tables.h:186
GucShowHook show_hook
Definition: guc_tables.h:188
const char * name
Definition: encode.c:561
bool reset_val
Definition: guc_tables.h:190
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8619

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

8922 {
8923  struct config_enum *var;
8924 
8925  var = (struct config_enum *)
8926  init_custom_variable(name, short_desc, long_desc, context, flags,
8927  PGC_ENUM, sizeof(struct config_enum));
8928  var->variable = valueAddr;
8929  var->boot_val = bootValue;
8930  var->reset_val = bootValue;
8931  var->options = options;
8932  var->check_hook = check_hook;
8933  var->assign_hook = assign_hook;
8934  var->show_hook = show_hook;
8935  define_custom_variable(&var->gen);
8936 }
GucEnumCheckHook check_hook
Definition: guc_tables.h:247
GucEnumAssignHook assign_hook
Definition: guc_tables.h:248
int * variable
Definition: guc_tables.h:244
const struct config_enum_entry * options
Definition: guc_tables.h:246
static char ** options
static struct config_generic * init_custom_variable(const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
Definition: guc.c:8559
GucShowHook show_hook
Definition: guc_tables.h:249
struct config_generic gen
Definition: guc_tables.h:242
const char * name
Definition: encode.c:561
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8619

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

8838 {
8839  struct config_int *var;
8840 
8841  var = (struct config_int *)
8842  init_custom_variable(name, short_desc, long_desc, context, flags,
8843  PGC_INT, sizeof(struct config_int));
8844  var->variable = valueAddr;
8845  var->boot_val = bootValue;
8846  var->reset_val = bootValue;
8847  var->min = minValue;
8848  var->max = maxValue;
8849  var->check_hook = check_hook;
8850  var->assign_hook = assign_hook;
8851  var->show_hook = show_hook;
8852  define_custom_variable(&var->gen);
8853 }
int boot_val
Definition: guc_tables.h:199
GucIntAssignHook assign_hook
Definition: guc_tables.h:203
GucIntCheckHook check_hook
Definition: guc_tables.h:202
GucShowHook show_hook
Definition: guc_tables.h:204
int * variable
Definition: guc_tables.h:198
struct config_generic gen
Definition: guc_tables.h:196
static struct config_generic * init_custom_variable(const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
Definition: guc.c:8559
const char * name
Definition: encode.c:561
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8619
int reset_val
Definition: guc_tables.h:206

◆ DefineCustomRealVariable()

void DefineCustomRealVariable ( const char *  name,
const char *  short_desc,
const char *  long_desc,
double *  valueAddr,
double  bootValue,
double  minValue,
double  maxValue,
GucContext  context,
int  flags,
GucRealCheckHook  check_hook,
GucRealAssignHook  assign_hook,
GucShowHook  show_hook 
)

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

8868 {
8869  struct config_real *var;
8870 
8871  var = (struct config_real *)
8872  init_custom_variable(name, short_desc, long_desc, context, flags,
8873  PGC_REAL, sizeof(struct config_real));
8874  var->variable = valueAddr;
8875  var->boot_val = bootValue;
8876  var->reset_val = bootValue;
8877  var->min = minValue;
8878  var->max = maxValue;
8879  var->check_hook = check_hook;
8880  var->assign_hook = assign_hook;
8881  var->show_hook = show_hook;
8882  define_custom_variable(&var->gen);
8883 }
GucRealAssignHook assign_hook
Definition: guc_tables.h:219
double reset_val
Definition: guc_tables.h:222
GucRealCheckHook check_hook
Definition: guc_tables.h:218
GucShowHook show_hook
Definition: guc_tables.h:220
double * variable
Definition: guc_tables.h:214
static struct config_generic * init_custom_variable(const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
Definition: guc.c:8559
double max
Definition: guc_tables.h:217
double boot_val
Definition: guc_tables.h:215
const char * name
Definition: encode.c:561
double min
Definition: guc_tables.h:216
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8619
struct config_generic gen
Definition: guc_tables.h:212

◆ DefineCustomStringVariable()

void DefineCustomStringVariable ( const char *  name,
const char *  short_desc,
const char *  long_desc,
char **  valueAddr,
const char *  bootValue,
GucContext  context,
int  flags,
GucStringCheckHook  check_hook,
GucStringAssignHook  assign_hook,
GucShowHook  show_hook 
)

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

8896 {
8897  struct config_string *var;
8898 
8899  var = (struct config_string *)
8900  init_custom_variable(name, short_desc, long_desc, context, flags,
8901  PGC_STRING, sizeof(struct config_string));
8902  var->variable = valueAddr;
8903  var->boot_val = bootValue;
8904  var->check_hook = check_hook;
8905  var->assign_hook = assign_hook;
8906  var->show_hook = show_hook;
8907  define_custom_variable(&var->gen);
8908 }
char ** variable
Definition: guc_tables.h:230
GucStringCheckHook check_hook
Definition: guc_tables.h:232
const char * boot_val
Definition: guc_tables.h:231
GucShowHook show_hook
Definition: guc_tables.h:234
static struct config_generic * init_custom_variable(const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
Definition: guc.c:8559
struct config_generic gen
Definition: guc_tables.h:228
GucStringAssignHook assign_hook
Definition: guc_tables.h:233
const char * name
Definition: encode.c:561
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8619

◆ discard_stack_value()

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

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

5041 {
5042  switch (gconf->vartype)
5043  {
5044  case PGC_BOOL:
5045  case PGC_INT:
5046  case PGC_REAL:
5047  case PGC_ENUM:
5048  /* no need to do anything */
5049  break;
5050  case PGC_STRING:
5051  set_string_field((struct config_string *) gconf,
5052  &(val->val.stringval),
5053  NULL);
5054  break;
5055  }
5056  set_extra_field(gconf, &(val->extra), NULL);
5057 }
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:4986
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4925
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 10256 of file guc.c.

References elog, ERROR, and vsnprintf.

Referenced by serialize_variable().

10257 {
10258  va_list vargs;
10259  int n;
10260 
10261  if (*maxbytes <= 0)
10262  elog(ERROR, "not enough space to serialize GUC state");
10263 
10264  va_start(vargs, fmt);
10265  n = vsnprintf(*destptr, *maxbytes, fmt, vargs);
10266  va_end(vargs);
10267 
10268  if (n < 0)
10269  {
10270  /* Shouldn't happen. Better show errno description. */
10271  elog(ERROR, "vsnprintf failed: %m with format string \"%s\"", fmt);
10272  }
10273  if (n >= *maxbytes)
10274  {
10275  /* This shouldn't happen either, really. */
10276  elog(ERROR, "not enough space to serialize GUC state");
10277  }
10278 
10279  /* Shift the destptr ahead of the null terminator */
10280  *destptr += n + 1;
10281  *maxbytes -= n + 1;
10282 }
#define ERROR
Definition: elog.h:43
#define vsnprintf
Definition: port.h:192
#define elog(elevel,...)
Definition: elog.h:214

◆ do_serialize_binary()

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

Definition at line 10286 of file guc.c.

References elog, and ERROR.

Referenced by serialize_variable().

10287 {
10288  if (valsize > *maxbytes)
10289  elog(ERROR, "not enough space to serialize GUC state");
10290 
10291  memcpy(*destptr, val, valsize);
10292  *destptr += valsize;
10293  *maxbytes -= valsize;
10294 }
#define ERROR
Definition: elog.h:43
#define elog(elevel,...)
Definition: elog.h:214
long val
Definition: informix.c:664

◆ EmitWarningsOnPlaceholders()

void EmitWarningsOnPlaceholders ( const char *  className)

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

8940 {
8941  int classLen = strlen(className);
8942  int i;
8943 
8944  for (i = 0; i < num_guc_variables; i++)
8945  {
8946  struct config_generic *var = guc_variables[i];
8947 
8948  if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
8949  strncmp(className, var->name, classLen) == 0 &&
8950  var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
8951  {
8952  ereport(WARNING,
8953  (errcode(ERRCODE_UNDEFINED_OBJECT),
8954  errmsg("unrecognized configuration parameter \"%s\"",
8955  var->name)));
8956  }
8957  }
8958 }
const char * name
Definition: guc_tables.h:149
int errcode(int sqlerrcode)
Definition: elog.c:610
#define GUC_QUALIFIER_SEPARATOR
Definition: guc.h:199
static int num_guc_variables
Definition: guc.c:4815
static struct config_generic ** guc_variables
Definition: guc.c:4812
#define WARNING
Definition: elog.h:40
#define ereport(elevel,...)
Definition: elog.h:144
#define GUC_CUSTOM_PLACEHOLDER
Definition: guc.h:211
int errmsg(const char *fmt,...)
Definition: elog.c:824
int i

◆ estimate_variable_size()

static Size estimate_variable_size ( struct config_generic gconf)
static

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

10136 {
10137  Size size;
10138  Size valsize = 0;
10139 
10140  if (can_skip_gucvar(gconf))
10141  return 0;
10142 
10143  /* Name, plus trailing zero byte. */
10144  size = strlen(gconf->name) + 1;
10145 
10146  /* Get the maximum display length of the GUC value. */
10147  switch (gconf->vartype)
10148  {
10149  case PGC_BOOL:
10150  {
10151  valsize = 5; /* max(strlen('true'), strlen('false')) */
10152  }
10153  break;
10154 
10155  case PGC_INT:
10156  {
10157  struct config_int *conf = (struct config_int *) gconf;
10158 
10159  /*
10160  * Instead of getting the exact display length, use max
10161  * length. Also reduce the max length for typical ranges of
10162  * small values. Maximum value is 2147483647, i.e. 10 chars.
10163  * Include one byte for sign.
10164  */
10165  if (Abs(*conf->variable) < 1000)
10166  valsize = 3 + 1;
10167  else
10168  valsize = 10 + 1;
10169  }
10170  break;
10171 
10172  case PGC_REAL:
10173  {
10174  /*
10175  * We are going to print it with %e with REALTYPE_PRECISION
10176  * fractional digits. Account for sign, leading digit,
10177  * decimal point, and exponent with up to 3 digits. E.g.
10178  * -3.99329042340000021e+110
10179  */
10180  valsize = 1 + 1 + 1 + REALTYPE_PRECISION + 5;
10181  }
10182  break;
10183 
10184  case PGC_STRING:
10185  {
10186  struct config_string *conf = (struct config_string *) gconf;
10187 
10188  /*
10189  * If the value is NULL, we transmit it as an empty string.
10190  * Although this is not physically the same value, GUC
10191  * generally treats a NULL the same as empty string.
10192  */
10193  if (*conf->variable)
10194  valsize = strlen(*conf->variable);
10195  else
10196  valsize = 0;
10197  }
10198  break;
10199 
10200  case PGC_ENUM:
10201  {
10202  struct config_enum *conf = (struct config_enum *) gconf;
10203 
10204  valsize = strlen(config_enum_lookup_by_value(conf, *conf->variable));
10205  }
10206  break;
10207  }
10208 
10209  /* Allow space for terminating zero-byte for value */
10210  size = add_size(size, valsize + 1);
10211 
10212  if (gconf->sourcefile)
10213  size = add_size(size, strlen(gconf->sourcefile));
10214 
10215  /* Allow space for terminating zero-byte for sourcefile */
10216  size = add_size(size, 1);
10217 
10218  /* Include line whenever file is nonempty. */
10219  if (gconf->sourcefile && gconf->sourcefile[0])
10220  size = add_size(size, sizeof(gconf->sourceline));
10221 
10222  size = add_size(size, sizeof(gconf->source));
10223  size = add_size(size, sizeof(gconf->scontext));
10224 
10225  return size;
10226 }
GucSource source
Definition: guc_tables.h:158
char ** variable
Definition: guc_tables.h:230
const char * name
Definition: guc_tables.h:149
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:6645
GucContext scontext
Definition: guc_tables.h:160
#define Abs(x)
Definition: c.h:933
int * variable
Definition: guc_tables.h:198
int * variable
Definition: guc_tables.h:244
char * sourcefile
Definition: guc_tables.h:164
static bool can_skip_gucvar(struct config_generic *gconf)
Definition: guc.c:10121
#define REALTYPE_PRECISION
Definition: guc.c:122
enum config_type vartype
Definition: guc_tables.h:156
Size add_size(Size s1, Size s2)
Definition: shmem.c:498
size_t Size
Definition: c.h:473

◆ EstimateGUCStateSpace()

Size EstimateGUCStateSpace ( void  )

Definition at line 10233 of file guc.c.

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

Referenced by InitializeParallelDSM().

10234 {
10235  Size size;
10236  int i;
10237 
10238  /* Add space reqd for saving the data size of the guc state */
10239  size = sizeof(Size);
10240 
10241  /* Add up the space needed for each GUC variable */
10242  for (i = 0; i < num_guc_variables; i++)
10243  size = add_size(size,
10245 
10246  return size;
10247 }
static int num_guc_variables
Definition: guc.c:4815
static struct config_generic ** guc_variables
Definition: guc.c:4812
Size add_size(Size s1, Size s2)
Definition: shmem.c:498
size_t Size
Definition: c.h:473
static Size estimate_variable_size(struct config_generic *gconf)
Definition: guc.c:10135
int i

◆ ExecSetVariableStmt()

void ExecSetVariableStmt ( VariableSetStmt stmt,
bool  isTopLevel 
)

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

8348 {
8350 
8351  /*
8352  * Workers synchronize these parameters at the start of the parallel
8353  * operation; then, we block SET during the operation.
8354  */
8355  if (IsInParallelMode())
8356  ereport(ERROR,
8357  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
8358  errmsg("cannot set parameters during a parallel operation")));
8359 
8360  switch (stmt->kind)
8361  {
8362  case VAR_SET_VALUE:
8363  case VAR_SET_CURRENT:
8364  if (stmt->is_local)
8365  WarnNoTransactionBlock(isTopLevel, "SET LOCAL");
8366  (void) set_config_option(stmt->name,
8367  ExtractSetVariableArgs(stmt),
8369  PGC_S_SESSION,
8370  action, true, 0, false);
8371  break;
8372  case VAR_SET_MULTI:
8373 
8374  /*
8375  * Special-case SQL syntaxes. The TRANSACTION and SESSION
8376  * CHARACTERISTICS cases effectively set more than one variable
8377  * per statement. TRANSACTION SNAPSHOT only takes one argument,
8378  * but we put it here anyway since it's a special case and not
8379  * related to any GUC variable.
8380  */
8381  if (strcmp(stmt->name, "TRANSACTION") == 0)
8382  {
8383  ListCell *head;
8384 
8385  WarnNoTransactionBlock(isTopLevel, "SET TRANSACTION");
8386 
8387  foreach(head, stmt->args)
8388  {
8389  DefElem *item = (DefElem *) lfirst(head);
8390 
8391  if (strcmp(item->defname, "transaction_isolation") == 0)
8392  SetPGVariable("transaction_isolation",
8393  list_make1(item->arg), stmt->is_local);
8394  else if (strcmp(item->defname, "transaction_read_only") == 0)
8395  SetPGVariable("transaction_read_only",
8396  list_make1(item->arg), stmt->is_local);
8397  else if (strcmp(item->defname, "transaction_deferrable") == 0)
8398  SetPGVariable("transaction_deferrable",
8399  list_make1(item->arg), stmt->is_local);
8400  else
8401  elog(ERROR, "unexpected SET TRANSACTION element: %s",
8402  item->defname);
8403  }
8404  }
8405  else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
8406  {
8407  ListCell *head;
8408 
8409  foreach(head, stmt->args)
8410  {
8411  DefElem *item = (DefElem *) lfirst(head);
8412 
8413  if (strcmp(item->defname, "transaction_isolation") == 0)
8414  SetPGVariable("default_transaction_isolation",
8415  list_make1(item->arg), stmt->is_local);
8416  else if (strcmp(item->defname, "transaction_read_only") == 0)
8417  SetPGVariable("default_transaction_read_only",
8418  list_make1(item->arg), stmt->is_local);
8419  else if (strcmp(item->defname, "transaction_deferrable") == 0)
8420  SetPGVariable("default_transaction_deferrable",
8421  list_make1(item->arg), stmt->is_local);
8422  else
8423  elog(ERROR, "unexpected SET SESSION element: %s",
8424  item->defname);
8425  }
8426  }
8427  else if (strcmp(stmt->name, "TRANSACTION SNAPSHOT") == 0)
8428  {
8429  A_Const *con = linitial_node(A_Const, stmt->args);
8430 
8431  if (stmt->is_local)
8432  ereport(ERROR,
8433  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8434  errmsg("SET LOCAL TRANSACTION SNAPSHOT is not implemented")));
8435 
8436  WarnNoTransactionBlock(isTopLevel, "SET TRANSACTION");
8437  Assert(nodeTag(&con->val) == T_String);
8438  ImportSnapshot(strVal(&con->val));
8439  }
8440  else
8441  elog(ERROR, "unexpected SET MULTI element: %s",
8442  stmt->name);
8443  break;
8444  case VAR_SET_DEFAULT:
8445  if (stmt->is_local)
8446  WarnNoTransactionBlock(isTopLevel, "SET LOCAL");
8447  /* fall through */
8448  case VAR_RESET:
8449  if (strcmp(stmt->name, "transaction_isolation") == 0)
8450  WarnNoTransactionBlock(isTopLevel, "RESET TRANSACTION");
8451 
8452  (void) set_config_option(stmt->name,
8453  NULL,
8455  PGC_S_SESSION,
8456  action, true, 0, false);
8457  break;
8458  case VAR_RESET_ALL:
8459  ResetAllOptions();
8460  break;
8461  }
8462 }
void ImportSnapshot(const char *idstr)
Definition: snapmgr.c:1462
VariableSetKind kind
Definition: parsenodes.h:2042
void WarnNoTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3440
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:610
bool superuser(void)
Definition: superuser.c:46
#define linitial_node(type, l)
Definition: pg_list.h:198
GucAction
Definition: guc.h:191
#define list_make1(x1)
Definition: pg_list.h:227
bool IsInParallelMode(void)
Definition: xact.c:1012
#define ERROR
Definition: elog.h:43
Definition: guc.h:75
void ResetAllOptions(void)
Definition: guc.c:5741
Node * arg
Definition: parsenodes.h:733
#define ereport(elevel,...)
Definition: elog.h:144
#define Assert(condition)
Definition: c.h:745
#define lfirst(lc)
Definition: pg_list.h:190
#define nodeTag(nodeptr)
Definition: nodes.h:534
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214
char * defname
Definition: parsenodes.h:732
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
Definition: guc.c:8471
Value val
Definition: parsenodes.h:289
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:6949
void SetPGVariable(const char *name, List *args, bool is_local)
Definition: guc.c:8491

◆ extra_field_used()

static bool extra_field_used ( struct config_generic gconf,