PostgreSQL Source Code  git master
guc.c File Reference
#include "postgres.h"
#include <ctype.h>
#include <float.h>
#include <math.h>
#include <limits.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
#include "access/commit_ts.h"
#include "access/gin.h"
#include "access/rmgr.h"
#include "access/tableam.h"
#include "access/toast_compression.h"
#include "access/transam.h"
#include "access/twophase.h"
#include "access/xact.h"
#include "access/xlog_internal.h"
#include "access/xlogprefetcher.h"
#include "access/xlogrecovery.h"
#include "catalog/namespace.h"
#include "catalog/objectaccess.h"
#include "catalog/pg_authid.h"
#include "catalog/pg_parameter_acl.h"
#include "catalog/storage.h"
#include "commands/async.h"
#include "commands/prepare.h"
#include "commands/tablespace.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/startup.h"
#include "postmaster/syslogger.h"
#include "postmaster/walwriter.h"
#include "replication/logicallauncher.h"
#include "replication/reorderbuffer.h"
#include "replication/slot.h"
#include "replication/syncrep.h"
#include "replication/walreceiver.h"
#include "replication/walsender.h"
#include "storage/bufmgr.h"
#include "storage/dsm_impl.h"
#include "storage/fd.h"
#include "storage/large_object.h"
#include "storage/pg_shmem.h"
#include "storage/predicate.h"
#include "storage/proc.h"
#include "storage/standby.h"
#include "tcop/tcopprot.h"
#include "tsearch/ts_cache.h"
#include "utils/acl.h"
#include "utils/backend_status.h"
#include "utils/builtins.h"
#include "utils/bytea.h"
#include "utils/guc_tables.h"
#include "utils/memutils.h"
#include "utils/pg_locale.h"
#include "utils/pg_lsn.h"
#include "utils/plancache.h"
#include "utils/portal.h"
#include "utils/ps_status.h"
#include "utils/queryjumble.h"
#include "utils/rls.h"
#include "utils/snapmgr.h"
#include "utils/tzparser.h"
#include "utils/inval.h"
#include "utils/varlena.h"
#include "utils/xml.h"
#include "guc-file.c"
Include dependency graph for guc.c:

Go to the source code of this file.

Data Structures

struct  unit_conversion
 

Macros

#define PG_KRB_SRVTAB   ""
 
#define CONFIG_FILENAME   "postgresql.conf"
 
#define HBA_FILENAME   "pg_hba.conf"
 
#define IDENT_FILENAME   "pg_ident.conf"
 
#define REALTYPE_PRECISION   17
 
#define MAX_UNIT_LEN   3 /* length of longest recognized unit string */
 
#define newval   (newval_union.boolval)
 
#define newval   (newval_union.intval)
 
#define newval   (newval_union.realval)
 
#define newval   (newval_union.stringval)
 
#define newval   (newval_union.enumval)
 
#define MAX_GUC_FLAGS   5
 
#define NUM_PG_SETTINGS_ATTS   17
 
#define NUM_PG_FILE_SETTINGS_ATTS   7
 

Functions

static void do_serialize (char **destptr, Size *maxbytes, const char *fmt,...) pg_attribute_printf(3
 
static void static void set_config_sourcefile (const char *name, char *sourcefile, int sourceline)
 
static bool call_bool_check_hook (struct config_bool *conf, bool *newval, void **extra, GucSource source, int elevel)
 
static bool call_int_check_hook (struct config_int *conf, int *newval, void **extra, GucSource source, int elevel)
 
static bool call_real_check_hook (struct config_real *conf, double *newval, void **extra, GucSource source, int elevel)
 
static bool call_string_check_hook (struct config_string *conf, char **newval, void **extra, GucSource source, int elevel)
 
static bool call_enum_check_hook (struct config_enum *conf, int *newval, void **extra, GucSource source, int elevel)
 
static bool check_log_destination (char **newval, void **extra, GucSource source)
 
static void assign_log_destination (const char *newval, void *extra)
 
static bool check_wal_consistency_checking (char **newval, void **extra, GucSource source)
 
static void assign_wal_consistency_checking (const char *newval, void *extra)
 
static void assign_syslog_facility (int newval, void *extra)
 
static void assign_syslog_ident (const char *newval, void *extra)
 
static void assign_session_replication_role (int newval, void *extra)
 
static bool check_temp_buffers (int *newval, void **extra, GucSource source)
 
static bool check_bonjour (bool *newval, void **extra, GucSource source)
 
static bool check_ssl (bool *newval, void **extra, GucSource source)
 
static bool check_stage_log_stats (bool *newval, void **extra, GucSource source)
 
static bool check_log_stats (bool *newval, void **extra, GucSource source)
 
static bool check_canonical_path (char **newval, void **extra, GucSource source)
 
static bool check_timezone_abbreviations (char **newval, void **extra, GucSource source)
 
static void assign_timezone_abbreviations (const char *newval, void *extra)
 
static void pg_timezone_abbrev_initialize (void)
 
static const char * show_archive_command (void)
 
static void assign_tcp_keepalives_idle (int newval, void *extra)
 
static void assign_tcp_keepalives_interval (int newval, void *extra)
 
static void assign_tcp_keepalives_count (int newval, void *extra)
 
static void assign_tcp_user_timeout (int newval, void *extra)
 
static const char * show_tcp_keepalives_idle (void)
 
static const char * show_tcp_keepalives_interval (void)
 
static const char * show_tcp_keepalives_count (void)
 
static const char * show_tcp_user_timeout (void)
 
static bool check_maxconnections (int *newval, void **extra, GucSource source)
 
static bool check_max_worker_processes (int *newval, void **extra, GucSource source)
 
static bool check_autovacuum_max_workers (int *newval, void **extra, GucSource source)
 
static bool check_max_wal_senders (int *newval, void **extra, GucSource source)
 
static bool check_autovacuum_work_mem (int *newval, void **extra, GucSource source)
 
static bool check_effective_io_concurrency (int *newval, void **extra, GucSource source)
 
static bool check_maintenance_io_concurrency (int *newval, void **extra, GucSource source)
 
static bool check_huge_page_size (int *newval, void **extra, GucSource source)
 
static bool check_client_connection_check_interval (int *newval, void **extra, GucSource source)
 
static void assign_maintenance_io_concurrency (int newval, void *extra)
 
static bool check_application_name (char **newval, void **extra, GucSource source)
 
static void assign_application_name (const char *newval, void *extra)
 
static bool check_cluster_name (char **newval, void **extra, GucSource source)
 
static const char * show_unix_socket_permissions (void)
 
static const char * show_log_file_mode (void)
 
static const char * show_data_directory_mode (void)
 
static const char * show_in_hot_standby (void)
 
static bool check_backtrace_functions (char **newval, void **extra, GucSource source)
 
static void assign_backtrace_functions (const char *newval, void *extra)
 
static bool check_recovery_target_timeline (char **newval, void **extra, GucSource source)
 
static void assign_recovery_target_timeline (const char *newval, void *extra)
 
static bool check_recovery_target (char **newval, void **extra, GucSource source)
 
static void assign_recovery_target (const char *newval, void *extra)
 
static bool check_recovery_target_xid (char **newval, void **extra, GucSource source)
 
static void assign_recovery_target_xid (const char *newval, void *extra)
 
static bool check_recovery_target_time (char **newval, void **extra, GucSource source)
 
static void assign_recovery_target_time (const char *newval, void *extra)
 
static bool check_recovery_target_name (char **newval, void **extra, GucSource source)
 
static void assign_recovery_target_name (const char *newval, void *extra)
 
static bool check_recovery_target_lsn (char **newval, void **extra, GucSource source)
 
static void assign_recovery_target_lsn (const char *newval, void *extra)
 
static bool check_primary_slot_name (char **newval, void **extra, GucSource source)
 
static bool check_default_with_oids (bool *newval, void **extra, GucSource source)
 
static ConfigVariableProcessConfigFileInternal (GucContext context, bool applySettings, int elevel)
 
 StaticAssertDecl (lengthof(bytea_output_options)==(BYTEA_OUTPUT_HEX+2), "array length mismatch")
 
 StaticAssertDecl (lengthof(intervalstyle_options)==(INTSTYLE_ISO_8601+2), "array length mismatch")
 
 StaticAssertDecl (lengthof(log_error_verbosity_options)==(PGERROR_VERBOSE+2), "array length mismatch")
 
 StaticAssertDecl (lengthof(log_statement_options)==(LOGSTMT_ALL+2), "array length mismatch")
 
 StaticAssertDecl (lengthof(session_replication_role_options)==(SESSION_REPLICATION_ROLE_LOCAL+2), "array length mismatch")
 
 StaticAssertDecl (lengthof(track_function_options)==(TRACK_FUNC_ALL+2), "array length mismatch")
 
 StaticAssertDecl (lengthof(stats_fetch_consistency)==(PGSTAT_FETCH_CONSISTENCY_SNAPSHOT+2), "array length mismatch")
 
 StaticAssertDecl (lengthof(xmlbinary_options)==(XMLBINARY_HEX+2), "array length mismatch")
 
 StaticAssertDecl (lengthof(xmloption_options)==(XMLOPTION_CONTENT+2), "array length mismatch")
 
 StaticAssertDecl (lengthof(ssl_protocol_versions_info)==(PG_TLS1_3_VERSION+2), "array length mismatch")
 
 StaticAssertDecl (lengthof(GucContext_Names)==(PGC_USERSET+1), "array length mismatch")
 
 StaticAssertDecl (lengthof(GucSource_Names)==(PGC_S_SESSION+1), "array length mismatch")
 
 StaticAssertDecl (lengthof(config_group_names)==(DEVELOPER_OPTIONS+2), "array length mismatch")
 
 StaticAssertDecl (lengthof(config_type_names)==(PGC_ENUM+1), "array length mismatch")
 
static int guc_var_compare (const void *a, const void *b)
 
static int guc_name_compare (const char *namea, const char *nameb)
 
static void InitializeGUCOptionsFromEnvironment (void)
 
static void InitializeOneGUCOption (struct config_generic *gconf)
 
static void push_old_value (struct config_generic *gconf, GucAction action)
 
static void ReportGUCOption (struct config_generic *record)
 
static void reapply_stacked_values (struct config_generic *variable, struct config_string *pHolder, GucStack *stack, const char *curvalue, GucContext curscontext, GucSource cursource)
 
static void ShowGUCConfigOption (const char *name, DestReceiver *dest)
 
static void ShowAllGUCConfig (DestReceiver *dest)
 
static char * _ShowOption (struct config_generic *record, bool use_units)
 
static bool validate_option_array_item (const char *name, const char *value, bool skipIfNoPermissions)
 
static void write_auto_conf_file (int fd, const char *filename, ConfigVariable *head_p)
 
static void replace_auto_config_value (ConfigVariable **head_p, ConfigVariable **tail_p, const char *name, const char *value)
 
static void * guc_malloc (int elevel, size_t size)
 
static void * guc_realloc (int elevel, void *old, size_t size)
 
static char * guc_strdup (int elevel, const char *src)
 
static bool string_field_used (struct config_string *conf, char *strval)
 
static void set_string_field (struct config_string *conf, char **field, char *newval)
 
static bool extra_field_used (struct config_generic *gconf, void *extra)
 
static void set_extra_field (struct config_generic *gconf, void **field, void *newval)
 
static void set_stack_value (struct config_generic *gconf, config_var_value *val)
 
static void discard_stack_value (struct config_generic *gconf, config_var_value *val)
 
struct config_generic ** get_guc_variables (void)
 
void build_guc_variables (void)
 
static bool add_guc_variable (struct config_generic *var, int elevel)
 
static bool valid_custom_variable_name (const char *name)
 
static struct config_genericadd_placeholder_variable (const char *name, int elevel)
 
static struct config_genericfind_option (const char *name, bool create_placeholders, bool skip_errors, int elevel)
 
char * convert_GUC_name_for_parameter_acl (const char *name)
 
bool check_GUC_name_for_parameter_acl (const char *name)
 
void InitializeGUCOptions (void)
 
void InitializeWalConsistencyChecking (void)
 
bool SelectConfigFiles (const char *userDoption, const char *progname)
 
void ResetAllOptions (void)
 
void AtStart_GUC (void)
 
int NewGUCNestLevel (void)
 
void AtEOXact_GUC (bool isCommit, int nestLevel)
 
void BeginReportingGUCOptions (void)
 
void ReportChangedGUCOptions (void)
 
static bool convert_to_base_unit (double value, const char *unit, int base_unit, double *base_value)
 
static void convert_int_from_base_unit (int64 base_value, int base_unit, int64 *value, const char **unit)
 
static void convert_real_from_base_unit (double base_value, int base_unit, double *value, const char **unit)
 
static const char * get_config_unit_name (int flags)
 
bool parse_int (const char *value, int *result, int flags, const char **hintmsg)
 
bool parse_real (const char *value, double *result, int flags, const char **hintmsg)
 
const char * config_enum_lookup_by_value (struct config_enum *record, int val)
 
bool config_enum_lookup_by_name (struct config_enum *record, const char *value, int *retval)
 
static char * config_enum_get_options (struct config_enum *record, const char *prefix, const char *suffix, const char *separator)
 
static bool parse_and_validate_value (struct config_generic *record, const char *name, const char *value, GucSource source, int elevel, union config_var_val *newval, void **newextra)
 
int set_config_option (const char *name, const char *value, GucContext context, GucSource source, GucAction action, bool changeVal, int elevel, bool is_reload)
 
void SetConfigOption (const char *name, const char *value, GucContext context, GucSource source)
 
const char * GetConfigOption (const char *name, bool missing_ok, bool restrict_privileged)
 
const char * GetConfigOptionResetString (const char *name)
 
int GetConfigOptionFlags (const char *name, bool missing_ok)
 
static char * flatten_set_variable_args (const char *name, List *args)
 
void AlterSystemSetConfigFile (AlterSystemStmt *altersysstmt)
 
void ExecSetVariableStmt (VariableSetStmt *stmt, bool isTopLevel)
 
char * ExtractSetVariableArgs (VariableSetStmt *stmt)
 
void SetPGVariable (const char *name, List *args, bool is_local)
 
Datum set_config_by_name (PG_FUNCTION_ARGS)
 
static struct config_genericinit_custom_variable (const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
 
static void define_custom_variable (struct config_generic *variable)
 
void DefineCustomBoolVariable (const char *name, const char *short_desc, const char *long_desc, bool *valueAddr, bool bootValue, GucContext context, int flags, GucBoolCheckHook check_hook, GucBoolAssignHook assign_hook, GucShowHook show_hook)
 
void DefineCustomIntVariable (const char *name, const char *short_desc, const char *long_desc, int *valueAddr, int bootValue, int minValue, int maxValue, GucContext context, int flags, GucIntCheckHook check_hook, GucIntAssignHook assign_hook, GucShowHook show_hook)
 
void DefineCustomRealVariable (const char *name, const char *short_desc, const char *long_desc, double *valueAddr, double bootValue, double minValue, double maxValue, GucContext context, int flags, GucRealCheckHook check_hook, GucRealAssignHook assign_hook, GucShowHook show_hook)
 
void DefineCustomStringVariable (const char *name, const char *short_desc, const char *long_desc, char **valueAddr, const char *bootValue, GucContext context, int flags, GucStringCheckHook check_hook, GucStringAssignHook assign_hook, GucShowHook show_hook)
 
void DefineCustomEnumVariable (const char *name, const char *short_desc, const char *long_desc, int *valueAddr, int bootValue, const struct config_enum_entry *options, GucContext context, int flags, GucEnumCheckHook check_hook, GucEnumAssignHook assign_hook, GucShowHook show_hook)
 
void MarkGUCPrefixReserved (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)
 
Datum pg_settings_get_flags (PG_FUNCTION_ARGS)
 
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 () error_multiple_recovery_targets(void)
 

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
 
static Listreserved_class_prefix = NIL
 
char * GUC_check_errmsg_string
 
char * GUC_check_errdetail_string
 
char * GUC_check_errhint_string
 
static int syslog_facility = 0
 
static bool check_wal_consistency_checking_deferred = false
 
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 stats_fetch_consistency []
 
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 compute_query_id_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 recovery_prefetch_options []
 
static const struct config_enum_entry force_parallel_mode_options []
 
static const struct config_enum_entry plan_cache_mode_options []
 
static const struct config_enum_entry password_encryption_options []
 
const struct config_enum_entry ssl_protocol_versions_info []
 
static struct config_enum_entry recovery_init_sync_method_options []
 
static struct config_enum_entry shared_memory_options []
 
static struct config_enum_entry default_toast_compression_options []
 
static const struct config_enum_entry wal_compression_options []
 
const struct config_enum_entry wal_level_options []
 
const struct config_enum_entry archive_mode_options []
 
const struct config_enum_entry recovery_target_action_options []
 
const struct config_enum_entry sync_method_options []
 
const struct config_enum_entry dynamic_shared_memory_options []
 
bool 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 shared_memory_size_mb
 
static int shared_memory_size_in_huge_pages
 
static int wal_block_size
 
static bool data_checksums
 
static bool integer_datetimes
 
static bool assert_enabled
 
static bool in_hot_standby
 
static char * recovery_target_timeline_string
 
static char * recovery_target_string
 
static char * recovery_target_xid_string
 
static char * recovery_target_name_string
 
static char * recovery_target_lsn_string
 
char * role_string
 
const char *const GucContext_Names []
 
const char *const GucSource_Names []
 
const char *const config_group_names []
 
const char *const config_type_names []
 
static const char * memory_units_hint = gettext_noop("Valid units for this parameter are \"B\", \"kB\", \"MB\", \"GB\", and \"TB\".")
 
static const unit_conversion memory_unit_conversion_table []
 
static const char * time_units_hint = gettext_noop("Valid units for this parameter are \"us\", \"ms\", \"s\", \"min\", \"h\", and \"d\".")
 
static const unit_conversion time_unit_conversion_table []
 
static struct config_bool ConfigureNamesBool []
 
static struct config_int ConfigureNamesInt []
 
static struct config_real ConfigureNamesReal []
 
static struct config_string ConfigureNamesString []
 
static struct config_enum ConfigureNamesEnum []
 
static const char *const map_old_guc_names []
 
static struct config_generic ** guc_variables
 
static int num_guc_variables
 
static int size_guc_variables
 
static bool guc_dirty
 
static bool reporting_enabled
 
static bool report_needed
 
static int GUCNestLevel = 0
 

Macro Definition Documentation

◆ CONFIG_FILENAME

#define CONFIG_FILENAME   "postgresql.conf"

Definition at line 122 of file guc.c.

◆ HBA_FILENAME

#define HBA_FILENAME   "pg_hba.conf"

Definition at line 123 of file guc.c.

◆ IDENT_FILENAME

#define IDENT_FILENAME   "pg_ident.conf"

Definition at line 124 of file guc.c.

◆ MAX_GUC_FLAGS

#define MAX_GUC_FLAGS   5

◆ MAX_UNIT_LEN

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

Definition at line 900 of file guc.c.

◆ 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

◆ NUM_PG_SETTINGS_ATTS

#define NUM_PG_SETTINGS_ATTS   17

Definition at line 10259 of file guc.c.

◆ PG_KRB_SRVTAB

#define PG_KRB_SRVTAB   ""

Definition at line 119 of file guc.c.

◆ REALTYPE_PRECISION

#define REALTYPE_PRECISION   17

Definition at line 135 of file guc.c.

Function Documentation

◆ _ShowOption()

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

Definition at line 10462 of file guc.c.

10463 {
10464  char buffer[256];
10465  const char *val;
10466 
10467  switch (record->vartype)
10468  {
10469  case PGC_BOOL:
10470  {
10471  struct config_bool *conf = (struct config_bool *) record;
10472 
10473  if (conf->show_hook)
10474  val = conf->show_hook();
10475  else
10476  val = *conf->variable ? "on" : "off";
10477  }
10478  break;
10479 
10480  case PGC_INT:
10481  {
10482  struct config_int *conf = (struct config_int *) record;
10483 
10484  if (conf->show_hook)
10485  val = conf->show_hook();
10486  else
10487  {
10488  /*
10489  * Use int64 arithmetic to avoid overflows in units
10490  * conversion.
10491  */
10492  int64 result = *conf->variable;
10493  const char *unit;
10494 
10495  if (use_units && result > 0 && (record->flags & GUC_UNIT))
10497  record->flags & GUC_UNIT,
10498  &result, &unit);
10499  else
10500  unit = "";
10501 
10502  snprintf(buffer, sizeof(buffer), INT64_FORMAT "%s",
10503  result, unit);
10504  val = buffer;
10505  }
10506  }
10507  break;
10508 
10509  case PGC_REAL:
10510  {
10511  struct config_real *conf = (struct config_real *) record;
10512 
10513  if (conf->show_hook)
10514  val = conf->show_hook();
10515  else
10516  {
10517  double result = *conf->variable;
10518  const char *unit;
10519 
10520  if (use_units && result > 0 && (record->flags & GUC_UNIT))
10522  record->flags & GUC_UNIT,
10523  &result, &unit);
10524  else
10525  unit = "";
10526 
10527  snprintf(buffer, sizeof(buffer), "%g%s",
10528  result, unit);
10529  val = buffer;
10530  }
10531  }
10532  break;
10533 
10534  case PGC_STRING:
10535  {
10536  struct config_string *conf = (struct config_string *) record;
10537 
10538  if (conf->show_hook)
10539  val = conf->show_hook();
10540  else if (*conf->variable && **conf->variable)
10541  val = *conf->variable;
10542  else
10543  val = "";
10544  }
10545  break;
10546 
10547  case PGC_ENUM:
10548  {
10549  struct config_enum *conf = (struct config_enum *) record;
10550 
10551  if (conf->show_hook)
10552  val = conf->show_hook();
10553  else
10554  val = config_enum_lookup_by_value(conf, *conf->variable);
10555  }
10556  break;
10557 
10558  default:
10559  /* just to keep compiler quiet */
10560  val = "???";
10561  break;
10562  }
10563 
10564  return pstrdup(val);
10565 }
#define INT64_FORMAT
Definition: c.h:494
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:7254
static void convert_int_from_base_unit(int64 base_value, int base_unit, int64 *value, const char **unit)
Definition: guc.c:6960
static void convert_real_from_base_unit(double base_value, int base_unit, double *value, const char **unit)
Definition: guc.c:7002
#define GUC_UNIT
Definition: guc.h:241
@ PGC_BOOL
Definition: guc_tables.h:24
@ PGC_STRING
Definition: guc_tables.h:27
@ PGC_ENUM
Definition: guc_tables.h:28
@ PGC_REAL
Definition: guc_tables.h:26
@ PGC_INT
Definition: guc_tables.h:25
long val
Definition: informix.c:664
char * pstrdup(const char *in)
Definition: mcxt.c:1305
#define snprintf
Definition: port.h:225
bool * variable
Definition: guc_tables.h:180
GucShowHook show_hook
Definition: guc_tables.h:184
int * variable
Definition: guc_tables.h:240
GucShowHook show_hook
Definition: guc_tables.h:245
enum config_type vartype
Definition: guc_tables.h:149
int * variable
Definition: guc_tables.h:194
GucShowHook show_hook
Definition: guc_tables.h:200
double * variable
Definition: guc_tables.h:210
GucShowHook show_hook
Definition: guc_tables.h:216
GucShowHook show_hook
Definition: guc_tables.h:230
char ** variable
Definition: guc_tables.h:226

References config_enum_lookup_by_value(), convert_int_from_base_unit(), convert_real_from_base_unit(), config_generic::flags, GUC_UNIT, INT64_FORMAT, PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_STRING, pstrdup(), config_bool::show_hook, config_int::show_hook, config_real::show_hook, config_string::show_hook, config_enum::show_hook, snprintf, 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().

◆ add_guc_variable()

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

Definition at line 5499 of file guc.c.

5500 {
5502  {
5503  /*
5504  * Increase the vector by 25%
5505  */
5506  int size_vars = size_guc_variables + size_guc_variables / 4;
5507  struct config_generic **guc_vars;
5508 
5509  if (size_vars == 0)
5510  {
5511  size_vars = 100;
5512  guc_vars = (struct config_generic **)
5513  guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
5514  }
5515  else
5516  {
5517  guc_vars = (struct config_generic **)
5518  guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
5519  }
5520 
5521  if (guc_vars == NULL)
5522  return false; /* out of memory */
5523 
5524  guc_variables = guc_vars;
5525  size_guc_variables = size_vars;
5526  }
5529  sizeof(struct config_generic *), guc_var_compare);
5530  return true;
5531 }
static struct config_generic ** guc_variables
Definition: guc.c:5147
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:5190
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:5730
static int num_guc_variables
Definition: guc.c:5150
static int size_guc_variables
Definition: guc.c:5153
static void * guc_realloc(int elevel, void *old, size_t size)
Definition: guc.c:5206
#define qsort(a, b, c, d)
Definition: port.h:495

References guc_malloc(), guc_realloc(), guc_var_compare(), guc_variables, num_guc_variables, qsort, and size_guc_variables.

Referenced by add_placeholder_variable(), and define_custom_variable().

◆ add_placeholder_variable()

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

Definition at line 5577 of file guc.c.

5578 {
5579  size_t sz = sizeof(struct config_string) + sizeof(char *);
5580  struct config_string *var;
5581  struct config_generic *gen;
5582 
5583  var = (struct config_string *) guc_malloc(elevel, sz);
5584  if (var == NULL)
5585  return NULL;
5586  memset(var, 0, sz);
5587  gen = &var->gen;
5588 
5589  gen->name = guc_strdup(elevel, name);
5590  if (gen->name == NULL)
5591  {
5592  free(var);
5593  return NULL;
5594  }
5595 
5596  gen->context = PGC_USERSET;
5598  gen->short_desc = "GUC placeholder variable";
5600  gen->vartype = PGC_STRING;
5601 
5602  /*
5603  * The char* is allocated at the end of the struct since we have no
5604  * 'static' place to point to. Note that the current value, as well as
5605  * the boot and reset values, start out NULL.
5606  */
5607  var->variable = (char **) (var + 1);
5608 
5609  if (!add_guc_variable((struct config_generic *) var, elevel))
5610  {
5611  free(unconstify(char *, gen->name));
5612  free(var);
5613  return NULL;
5614  }
5615 
5616  return gen;
5617 }
#define unconstify(underlying_type, expr)
Definition: c.h:1251
const char * name
Definition: encode.c:561
static bool add_guc_variable(struct config_generic *var, int elevel)
Definition: guc.c:5499
static char * guc_strdup(int elevel, const char *src)
Definition: guc.c:5222
#define GUC_CUSTOM_PLACEHOLDER
Definition: guc.h:215
#define GUC_NO_SHOW_ALL
Definition: guc.h:210
@ PGC_USERSET
Definition: guc.h:76
#define GUC_NOT_IN_SAMPLE
Definition: guc.h:213
@ CUSTOM_OPTIONS
Definition: guc_tables.h:97
#define free(a)
Definition: header.h:65
enum config_group group
Definition: guc_tables.h:144
GucContext context
Definition: guc_tables.h:143
const char * name
Definition: guc_tables.h:142
const char * short_desc
Definition: guc_tables.h:145
struct config_generic gen
Definition: guc_tables.h:224

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(), name, config_generic::name, PGC_STRING, PGC_USERSET, config_generic::short_desc, unconstify, config_string::variable, and config_generic::vartype.

Referenced by find_option().

◆ AlterSystemSetConfigFile()

void AlterSystemSetConfigFile ( AlterSystemStmt altersysstmt)

Definition at line 8775 of file guc.c.

8776 {
8777  char *name;
8778  char *value;
8779  bool resetall = false;
8780  ConfigVariable *head = NULL;
8781  ConfigVariable *tail = NULL;
8782  volatile int Tmpfd;
8783  char AutoConfFileName[MAXPGPATH];
8784  char AutoConfTmpFileName[MAXPGPATH];
8785 
8786  /*
8787  * Extract statement arguments
8788  */
8789  name = altersysstmt->setstmt->name;
8790 
8791  switch (altersysstmt->setstmt->kind)
8792  {
8793  case VAR_SET_VALUE:
8794  value = ExtractSetVariableArgs(altersysstmt->setstmt);
8795  break;
8796 
8797  case VAR_SET_DEFAULT:
8798  case VAR_RESET:
8799  value = NULL;
8800  break;
8801 
8802  case VAR_RESET_ALL:
8803  value = NULL;
8804  resetall = true;
8805  break;
8806 
8807  default:
8808  elog(ERROR, "unrecognized alter system stmt type: %d",
8809  altersysstmt->setstmt->kind);
8810  break;
8811  }
8812 
8813  /*
8814  * Check permission to run ALTER SYSTEM on the target variable
8815  */
8816  if (!superuser())
8817  {
8818  if (resetall)
8819  ereport(ERROR,
8820  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
8821  errmsg("permission denied to perform ALTER SYSTEM RESET ALL")));
8822  else
8823  {
8824  AclResult aclresult;
8825 
8826  aclresult = pg_parameter_aclcheck(name, GetUserId(),
8828  if (aclresult != ACLCHECK_OK)
8829  ereport(ERROR,
8830  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
8831  errmsg("permission denied to set parameter \"%s\"",
8832  name)));
8833  }
8834  }
8835 
8836  /*
8837  * Unless it's RESET_ALL, validate the target variable and value
8838  */
8839  if (!resetall)
8840  {
8841  struct config_generic *record;
8842 
8843  record = find_option(name, false, false, ERROR);
8844  Assert(record != NULL);
8845 
8846  /*
8847  * Don't allow parameters that can't be set in configuration files to
8848  * be set in PG_AUTOCONF_FILENAME file.
8849  */
8850  if ((record->context == PGC_INTERNAL) ||
8851  (record->flags & GUC_DISALLOW_IN_FILE) ||
8852  (record->flags & GUC_DISALLOW_IN_AUTO_FILE))
8853  ereport(ERROR,
8854  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
8855  errmsg("parameter \"%s\" cannot be changed",
8856  name)));
8857 
8858  /*
8859  * If a value is specified, verify that it's sane.
8860  */
8861  if (value)
8862  {
8863  union config_var_val newval;
8864  void *newextra = NULL;
8865 
8866  /* Check that it's acceptable for the indicated parameter */
8867  if (!parse_and_validate_value(record, name, value,
8868  PGC_S_FILE, ERROR,
8869  &newval, &newextra))
8870  ereport(ERROR,
8871  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8872  errmsg("invalid value for parameter \"%s\": \"%s\"",
8873  name, value)));
8874 
8875  if (record->vartype == PGC_STRING && newval.stringval != NULL)
8876  free(newval.stringval);
8877  free(newextra);
8878 
8879  /*
8880  * We must also reject values containing newlines, because the
8881  * grammar for config files doesn't support embedded newlines in
8882  * string literals.
8883  */
8884  if (strchr(value, '\n'))
8885  ereport(ERROR,
8886  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8887  errmsg("parameter value for ALTER SYSTEM must not contain a newline")));
8888  }
8889  }
8890 
8891  /*
8892  * PG_AUTOCONF_FILENAME and its corresponding temporary file are always in
8893  * the data directory, so we can reference them by simple relative paths.
8894  */
8895  snprintf(AutoConfFileName, sizeof(AutoConfFileName), "%s",
8897  snprintf(AutoConfTmpFileName, sizeof(AutoConfTmpFileName), "%s.%s",
8898  AutoConfFileName,
8899  "tmp");
8900 
8901  /*
8902  * Only one backend is allowed to operate on PG_AUTOCONF_FILENAME at a
8903  * time. Use AutoFileLock to ensure that. We must hold the lock while
8904  * reading the old file contents.
8905  */
8906  LWLockAcquire(AutoFileLock, LW_EXCLUSIVE);
8907 
8908  /*
8909  * If we're going to reset everything, then no need to open or parse the
8910  * old file. We'll just write out an empty list.
8911  */
8912  if (!resetall)
8913  {
8914  struct stat st;
8915 
8916  if (stat(AutoConfFileName, &st) == 0)
8917  {
8918  /* open old file PG_AUTOCONF_FILENAME */
8919  FILE *infile;
8920 
8921  infile = AllocateFile(AutoConfFileName, "r");
8922  if (infile == NULL)
8923  ereport(ERROR,
8925  errmsg("could not open file \"%s\": %m",
8926  AutoConfFileName)));
8927 
8928  /* parse it */
8929  if (!ParseConfigFp(infile, AutoConfFileName, 0, LOG, &head, &tail))
8930  ereport(ERROR,
8931  (errcode(ERRCODE_CONFIG_FILE_ERROR),
8932  errmsg("could not parse contents of file \"%s\"",
8933  AutoConfFileName)));
8934 
8935  FreeFile(infile);
8936  }
8937 
8938  /*
8939  * Now, replace any existing entry with the new value, or add it if
8940  * not present.
8941  */
8942  replace_auto_config_value(&head, &tail, name, value);
8943  }
8944 
8945  /*
8946  * Invoke the post-alter hook for setting this GUC variable. GUCs
8947  * typically do not have corresponding entries in pg_parameter_acl, so we
8948  * call the hook using the name rather than a potentially-non-existent
8949  * OID. Nonetheless, we pass ParameterAclRelationId so that this call
8950  * context can be distinguished from others. (Note that "name" will be
8951  * NULL in the RESET ALL case.)
8952  *
8953  * We do this here rather than at the end, because ALTER SYSTEM is not
8954  * transactional. If the hook aborts our transaction, it will be cleaner
8955  * to do so before we touch any files.
8956  */
8957  InvokeObjectPostAlterHookArgStr(ParameterAclRelationId, name,
8959  altersysstmt->setstmt->kind,
8960  false);
8961 
8962  /*
8963  * To ensure crash safety, first write the new file data to a temp file,
8964  * then atomically rename it into place.
8965  *
8966  * If there is a temp file left over due to a previous crash, it's okay to
8967  * truncate and reuse it.
8968  */
8969  Tmpfd = BasicOpenFile(AutoConfTmpFileName,
8970  O_CREAT | O_RDWR | O_TRUNC);
8971  if (Tmpfd < 0)
8972  ereport(ERROR,
8974  errmsg("could not open file \"%s\": %m",
8975  AutoConfTmpFileName)));
8976 
8977  /*
8978  * Use a TRY block to clean up the file if we fail. Since we need a TRY
8979  * block anyway, OK to use BasicOpenFile rather than OpenTransientFile.
8980  */
8981  PG_TRY();
8982  {
8983  /* Write and sync the new contents to the temporary file */
8984  write_auto_conf_file(Tmpfd, AutoConfTmpFileName, head);
8985 
8986  /* Close before renaming; may be required on some platforms */
8987  close(Tmpfd);
8988  Tmpfd = -1;
8989 
8990  /*
8991  * As the rename is atomic operation, if any problem occurs after this
8992  * at worst it can lose the parameters set by last ALTER SYSTEM
8993  * command.
8994  */
8995  durable_rename(AutoConfTmpFileName, AutoConfFileName, ERROR);
8996  }
8997  PG_CATCH();
8998  {
8999  /* Close file first, else unlink might fail on some platforms */
9000  if (Tmpfd >= 0)
9001  close(Tmpfd);
9002 
9003  /* Unlink, but ignore any error */
9004  (void) unlink(AutoConfTmpFileName);
9005 
9006  PG_RE_THROW();
9007  }
9008  PG_END_TRY();
9009 
9010  FreeConfigVariables(head);
9011 
9012  LWLockRelease(AutoFileLock);
9013 }
AclResult
Definition: acl.h:181
@ ACLCHECK_OK
Definition: acl.h:182
AclResult pg_parameter_aclcheck(const char *name, Oid roleid, AclMode mode)
Definition: aclchk.c:5046
int errcode_for_file_access(void)
Definition: elog.c:716
int errcode(int sqlerrcode)
Definition: elog.c:693
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define LOG
Definition: elog.h:25
#define PG_RE_THROW()
Definition: elog.h:340
#define PG_END_TRY()
Definition: elog.h:324
#define PG_TRY()
Definition: elog.h:299
#define ERROR
Definition: elog.h:33
#define PG_CATCH()
Definition: elog.h:309
#define ereport(elevel,...)
Definition: elog.h:143
FILE * AllocateFile(const char *name, const char *mode)
Definition: fd.c:2461
int durable_rename(const char *oldfile, const char *newfile, int elevel)
Definition: fd.c:699
int BasicOpenFile(const char *fileName, int fileFlags)
Definition: fd.c:1071
int FreeFile(FILE *file)
Definition: fd.c:2660
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:7361
#define newval
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
Definition: guc.c:9146
static void write_auto_conf_file(int fd, const char *filename, ConfigVariable *head_p)
Definition: guc.c:8637
static struct config_generic * find_option(const char *name, bool create_placeholders, bool skip_errors, int elevel)
Definition: guc.c:5635
static void replace_auto_config_value(ConfigVariable **head_p, ConfigVariable **tail_p, const char *name, const char *value)
Definition: guc.c:8705
#define PG_AUTOCONF_FILENAME
Definition: guc.h:34
void FreeConfigVariables(ConfigVariable *list)
bool ParseConfigFp(FILE *fp, const char *config_file, int depth, int elevel, ConfigVariable **head_p, ConfigVariable **tail_p)
#define GUC_DISALLOW_IN_FILE
Definition: guc.h:214
@ PGC_S_FILE
Definition: guc.h:113
#define GUC_DISALLOW_IN_AUTO_FILE
Definition: guc.h:219
@ PGC_INTERNAL
Definition: guc.h:70
static struct @151 value
#define close(a)
Definition: win32.h:12
Assert(fmt[strlen(fmt) - 1] !='\n')
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1196
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1800
@ LW_EXCLUSIVE
Definition: lwlock.h:104
Oid GetUserId(void)
Definition: miscinit.c:491
#define InvokeObjectPostAlterHookArgStr(classId, objectName, subId, auxiliaryId, is_internal)
Definition: objectaccess.h:245
@ VAR_SET_DEFAULT
Definition: parsenodes.h:2491
@ VAR_RESET
Definition: parsenodes.h:2494
@ VAR_SET_VALUE
Definition: parsenodes.h:2490
@ VAR_RESET_ALL
Definition: parsenodes.h:2495
#define ACL_ALTER_SYSTEM
Definition: parsenodes.h:95
#define MAXPGPATH
VariableSetStmt * setstmt
Definition: parsenodes.h:3689
VariableSetKind kind
Definition: parsenodes.h:2501
bool superuser(void)
Definition: superuser.c:46
#define stat
Definition: win32_port.h:283
static void infile(const char *filename)
Definition: zic.c:1241

References ACL_ALTER_SYSTEM, ACLCHECK_OK, AllocateFile(), Assert(), BasicOpenFile(), close, config_generic::context, durable_rename(), elog(), ereport, errcode(), errcode_for_file_access(), errmsg(), ERROR, ExtractSetVariableArgs(), find_option(), config_generic::flags, free, FreeConfigVariables(), FreeFile(), GetUserId(), GUC_DISALLOW_IN_AUTO_FILE, GUC_DISALLOW_IN_FILE, infile(), InvokeObjectPostAlterHookArgStr, VariableSetStmt::kind, LOG, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MAXPGPATH, name, VariableSetStmt::name, newval, parse_and_validate_value(), ParseConfigFp(), PG_AUTOCONF_FILENAME, PG_CATCH, PG_END_TRY, pg_parameter_aclcheck(), PG_RE_THROW, PG_TRY, PGC_INTERNAL, PGC_S_FILE, PGC_STRING, replace_auto_config_value(), AlterSystemStmt::setstmt, snprintf, stat, 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().

◆ assign_application_name()

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

Definition at line 12489 of file guc.c.

12490 {
12491  /* Update the pg_stat_activity view */
12493 }
void pgstat_report_appname(const char *appname)

References newval, and pgstat_report_appname().

◆ assign_backtrace_functions()

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

Definition at line 12608 of file guc.c.

12609 {
12610  backtrace_symbol_list = (char *) extra;
12611 }
char * backtrace_symbol_list
Definition: guc.c:647

References backtrace_symbol_list, and config_generic::extra.

◆ assign_log_destination()

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

Definition at line 12096 of file guc.c.

12097 {
12098  Log_destination = *((int *) extra);
12099 }
int Log_destination
Definition: elog.c:111

References config_generic::extra, and Log_destination.

◆ assign_maintenance_io_concurrency()

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

Definition at line 12466 of file guc.c.

12467 {
12468 #ifdef USE_PREFETCH
12469  /*
12470  * Reconfigure recovery prefetching, because a setting it depends on
12471  * changed.
12472  */
12474  if (AmStartupProcess())
12476 #endif
12477 }
int maintenance_io_concurrency
Definition: bufmgr.c:152
#define AmStartupProcess()
Definition: miscadmin.h:444
void XLogPrefetchReconfigure(void)

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

◆ assign_recovery_target()

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

Definition at line 12687 of file guc.c.

12688 {
12691  error_multiple_recovery_targets();
12692 
12693  if (newval && strcmp(newval, "") != 0)
12695  else
12697 }
RecoveryTargetType recoveryTarget
Definition: xlogrecovery.c:81
@ RECOVERY_TARGET_IMMEDIATE
Definition: xlogrecovery.h:30
@ RECOVERY_TARGET_UNSET
Definition: xlogrecovery.h:25

References newval, RECOVERY_TARGET_IMMEDIATE, RECOVERY_TARGET_UNSET, and recoveryTarget.

◆ assign_recovery_target_lsn()

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

Definition at line 12855 of file guc.c.

12856 {
12859  error_multiple_recovery_targets();
12860 
12861  if (newval && strcmp(newval, "") != 0)
12862  {
12864  recoveryTargetLSN = *((XLogRecPtr *) extra);
12865  }
12866  else
12868 }
uint64 XLogRecPtr
Definition: xlogdefs.h:21
XLogRecPtr recoveryTargetLSN
Definition: xlogrecovery.c:88
@ RECOVERY_TARGET_LSN
Definition: xlogrecovery.h:29

References newval, RECOVERY_TARGET_LSN, RECOVERY_TARGET_UNSET, recoveryTarget, and recoveryTargetLSN.

◆ assign_recovery_target_name()

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

Definition at line 12819 of file guc.c.

12820 {
12823  error_multiple_recovery_targets();
12824 
12825  if (newval && strcmp(newval, "") != 0)
12826  {
12829  }
12830  else
12832 }
const char * recoveryTargetName
Definition: xlogrecovery.c:87
@ RECOVERY_TARGET_NAME
Definition: xlogrecovery.h:28

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

◆ assign_recovery_target_time()

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

Definition at line 12793 of file guc.c.

12794 {
12797  error_multiple_recovery_targets();
12798 
12799  if (newval && strcmp(newval, "") != 0)
12801  else
12803 }
@ RECOVERY_TARGET_TIME
Definition: xlogrecovery.h:27

References newval, RECOVERY_TARGET_TIME, RECOVERY_TARGET_UNSET, and recoveryTarget.

◆ assign_recovery_target_timeline()

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

Definition at line 12644 of file guc.c.

12645 {
12648  recoveryTargetTLIRequested = (TimeLineID) strtoul(newval, NULL, 0);
12649  else
12651 }
uint32 TimeLineID
Definition: xlogdefs.h:59
RecoveryTargetTimeLineGoal recoveryTargetTimeLineGoal
Definition: xlogrecovery.c:117
TimeLineID recoveryTargetTLIRequested
Definition: xlogrecovery.c:118
RecoveryTargetTimeLineGoal
Definition: xlogrecovery.h:37
@ RECOVERY_TARGET_TIMELINE_NUMERIC
Definition: xlogrecovery.h:40

References config_generic::extra, newval, RECOVERY_TARGET_TIMELINE_NUMERIC, recoveryTargetTimeLineGoal, and recoveryTargetTLIRequested.

◆ assign_recovery_target_xid()

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

Definition at line 12720 of file guc.c.

12721 {
12724  error_multiple_recovery_targets();
12725 
12726  if (newval && strcmp(newval, "") != 0)
12727  {
12729  recoveryTargetXid = *((TransactionId *) extra);
12730  }
12731  else
12733 }
uint32 TransactionId
Definition: c.h:598
TransactionId recoveryTargetXid
Definition: xlogrecovery.c:84
@ RECOVERY_TARGET_XID
Definition: xlogrecovery.h:26

References config_generic::extra, newval, RECOVERY_TARGET_UNSET, RECOVERY_TARGET_XID, recoveryTarget, and recoveryTargetXid.

◆ assign_session_replication_role()

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

Definition at line 12122 of file guc.c.

12123 {
12124  /*
12125  * Must flush the plan cache when changing replication role; but don't
12126  * flush unnecessarily.
12127  */
12129  ResetPlanCache();
12130 }
void ResetPlanCache(void)
Definition: plancache.c:2149
int SessionReplicationRole
Definition: trigger.c:68

References newval, ResetPlanCache(), and SessionReplicationRole.

◆ assign_syslog_facility()

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

Definition at line 12102 of file guc.c.

12103 {
12104 #ifdef HAVE_SYSLOG
12105  set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
12106  newval);
12107 #endif
12108  /* Without syslog support, just ignore it */
12109 }
static char * syslog_ident_str
Definition: guc.c:688

References newval, and syslog_ident_str.

◆ assign_syslog_ident()

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

Definition at line 12112 of file guc.c.

12113 {
12114 #ifdef HAVE_SYSLOG
12115  set_syslog_parameters(newval, syslog_facility);
12116 #endif
12117  /* Without syslog support, it will always be set to "none", so ignore */
12118 }
static int syslog_facility
Definition: guc.c:188

References newval, and syslog_facility.

◆ assign_tcp_keepalives_count()

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

Definition at line 12322 of file guc.c.

12323 {
12324  /* See comments in assign_tcp_keepalives_idle */
12326 }
struct Port * MyProcPort
Definition: globals.c:47
int pq_setkeepalivescount(int count, Port *port)
Definition: pqcomm.c:1822

References MyProcPort, newval, and pq_setkeepalivescount().

◆ assign_tcp_keepalives_idle()

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

Definition at line 12278 of file guc.c.

12279 {
12280  /*
12281  * The kernel API provides no way to test a value without setting it; and
12282  * once we set it we might fail to unset it. So there seems little point
12283  * in fully implementing the check-then-assign GUC API for these
12284  * variables. Instead we just do the assignment on demand. pqcomm.c
12285  * reports any problems via ereport(LOG).
12286  *
12287  * This approach means that the GUC value might have little to do with the
12288  * actual kernel value, so we use a show_hook that retrieves the kernel
12289  * value rather than trusting GUC's copy.
12290  */
12292 }
int pq_setkeepalivesidle(int idle, Port *port)
Definition: pqcomm.c:1658

References MyProcPort, newval, and pq_setkeepalivesidle().

◆ assign_tcp_keepalives_interval()

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

Definition at line 12305 of file guc.c.

12306 {
12307  /* See comments in assign_tcp_keepalives_idle */
12309 }
int pq_setkeepalivesinterval(int interval, Port *port)
Definition: pqcomm.c:1743

References MyProcPort, newval, and pq_setkeepalivesinterval().

◆ assign_tcp_user_timeout()

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

Definition at line 12339 of file guc.c.

12340 {
12341  /* See comments in assign_tcp_keepalives_idle */
12343 }
int pq_settcpusertimeout(int timeout, Port *port)
Definition: pqcomm.c:1897

References MyProcPort, newval, and pq_settcpusertimeout().

◆ assign_timezone_abbreviations()

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

Definition at line 12242 of file guc.c.

12243 {
12244  /* Do nothing for the boot_val default of NULL */
12245  if (!extra)
12246  return;
12247 
12249 }
void InstallTimeZoneAbbrevs(TimeZoneAbbrevTable *tbl)
Definition: datetime.c:4873

References config_generic::extra, and InstallTimeZoneAbbrevs().

◆ assign_wal_consistency_checking()

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

Definition at line 12018 of file guc.c.

12019 {
12020  /*
12021  * If some checks were deferred, it's possible that the checks will fail
12022  * later during InitializeWalConsistencyChecking(). But in that case, the
12023  * postmaster will exit anyway, so it's safe to proceed with the
12024  * assignment.
12025  *
12026  * Any built-in resource managers specified are assigned immediately,
12027  * which affects WAL created before shared_preload_libraries are
12028  * processed. Any custom resource managers specified won't be assigned
12029  * until after shared_preload_libraries are processed, but that's OK
12030  * because WAL for a custom resource manager can't be written before the
12031  * module is loaded anyway.
12032  */
12033  wal_consistency_checking = extra;
12034 }
bool * wal_consistency_checking
Definition: xlog.c:127

References config_generic::extra, and wal_consistency_checking.

◆ AtEOXact_GUC()

void AtEOXact_GUC ( bool  isCommit,
int  nestLevel 
)

Definition at line 6489 of file guc.c.

6490 {
6491  bool still_dirty;
6492  int i;
6493 
6494  /*
6495  * Note: it's possible to get here with GUCNestLevel == nestLevel-1 during
6496  * abort, if there is a failure during transaction start before
6497  * AtStart_GUC is called.
6498  */
6499  Assert(nestLevel > 0 &&
6500  (nestLevel <= GUCNestLevel ||
6501  (nestLevel == GUCNestLevel + 1 && !isCommit)));
6502 
6503  /* Quick exit if nothing's changed in this transaction */
6504  if (!guc_dirty)
6505  {
6506  GUCNestLevel = nestLevel - 1;
6507  return;
6508  }
6509 
6510  still_dirty = false;
6511  for (i = 0; i < num_guc_variables; i++)
6512  {
6513  struct config_generic *gconf = guc_variables[i];
6514  GucStack *stack;
6515 
6516  /*
6517  * Process and pop each stack entry within the nest level. To simplify
6518  * fmgr_security_definer() and other places that use GUC_ACTION_SAVE,
6519  * we allow failure exit from code that uses a local nest level to be
6520  * recovered at the surrounding transaction or subtransaction abort;
6521  * so there could be more than one stack entry to pop.
6522  */
6523  while ((stack = gconf->stack) != NULL &&
6524  stack->nest_level >= nestLevel)
6525  {
6526  GucStack *prev = stack->prev;
6527  bool restorePrior = false;
6528  bool restoreMasked = false;
6529  bool changed;
6530 
6531  /*
6532  * In this next bit, if we don't set either restorePrior or
6533  * restoreMasked, we must "discard" any unwanted fields of the
6534  * stack entries to avoid leaking memory. If we do set one of
6535  * those flags, unused fields will be cleaned up after restoring.
6536  */
6537  if (!isCommit) /* if abort, always restore prior value */
6538  restorePrior = true;
6539  else if (stack->state == GUC_SAVE)
6540  restorePrior = true;
6541  else if (stack->nest_level == 1)
6542  {
6543  /* transaction commit */
6544  if (stack->state == GUC_SET_LOCAL)
6545  restoreMasked = true;
6546  else if (stack->state == GUC_SET)
6547  {
6548  /* we keep the current active value */
6549  discard_stack_value(gconf, &stack->prior);
6550  }
6551  else /* must be GUC_LOCAL */
6552  restorePrior = true;
6553  }
6554  else if (prev == NULL ||
6555  prev->nest_level < stack->nest_level - 1)
6556  {
6557  /* decrement entry's level and do not pop it */
6558  stack->nest_level--;
6559  continue;
6560  }
6561  else
6562  {
6563  /*
6564  * We have to merge this stack entry into prev. See README for
6565  * discussion of this bit.
6566  */
6567  switch (stack->state)
6568  {
6569  case GUC_SAVE:
6570  Assert(false); /* can't get here */
6571  break;
6572 
6573  case GUC_SET:
6574  /* next level always becomes SET */
6575  discard_stack_value(gconf, &stack->prior);
6576  if (prev->state == GUC_SET_LOCAL)
6577  discard_stack_value(gconf, &prev->masked);
6578  prev->state = GUC_SET;
6579  break;
6580 
6581  case GUC_LOCAL:
6582  if (prev->state == GUC_SET)
6583  {
6584  /* LOCAL migrates down */
6585  prev->masked_scontext = stack->scontext;
6586  prev->masked = stack->prior;
6587  prev->state = GUC_SET_LOCAL;
6588  }
6589  else
6590  {
6591  /* else just forget this stack level */
6592  discard_stack_value(gconf, &stack->prior);
6593  }
6594  break;
6595 
6596  case GUC_SET_LOCAL:
6597  /* prior state at this level no longer wanted */
6598  discard_stack_value(gconf, &stack->prior);
6599  /* copy down the masked state */
6601  if (prev->state == GUC_SET_LOCAL)
6602  discard_stack_value(gconf, &prev->masked);
6603  prev->masked = stack->masked;
6604  prev->state = GUC_SET_LOCAL;
6605  break;
6606  }
6607  }
6608 
6609  changed = false;
6610 
6611  if (restorePrior || restoreMasked)
6612  {
6613  /* Perform appropriate restoration of the stacked value */
6614  config_var_value newvalue;
6615  GucSource newsource;
6616  GucContext newscontext;
6617 
6618  if (restoreMasked)
6619  {
6620  newvalue = stack->masked;
6621  newsource = PGC_S_SESSION;
6622  newscontext = stack->masked_scontext;
6623  }
6624  else
6625  {
6626  newvalue = stack->prior;
6627  newsource = stack->source;
6628  newscontext = stack->scontext;
6629  }
6630 
6631  switch (gconf->vartype)
6632  {
6633  case PGC_BOOL:
6634  {
6635  struct config_bool *conf = (struct config_bool *) gconf;
6636  bool newval = newvalue.val.boolval;
6637  void *newextra = newvalue.extra;
6638 
6639  if (*conf->variable != newval ||
6640  conf->gen.extra != newextra)
6641  {
6642  if (conf->assign_hook)
6643  conf->assign_hook(newval, newextra);
6644  *conf->variable = newval;
6645  set_extra_field(&conf->gen, &conf->gen.extra,
6646  newextra);
6647  changed = true;
6648  }
6649  break;
6650  }
6651  case PGC_INT:
6652  {
6653  struct config_int *conf = (struct config_int *) gconf;
6654  int newval = newvalue.val.intval;
6655  void *newextra = newvalue.extra;
6656 
6657  if (*conf->variable != newval ||
6658  conf->gen.extra != newextra)
6659  {
6660  if (conf->assign_hook)
6661  conf->assign_hook(newval, newextra);
6662  *conf->variable = newval;
6663  set_extra_field(&conf->gen, &conf->gen.extra,
6664  newextra);
6665  changed = true;
6666  }
6667  break;
6668  }
6669  case PGC_REAL:
6670  {
6671  struct config_real *conf = (struct config_real *) gconf;
6672  double newval = newvalue.val.realval;
6673  void *newextra = newvalue.extra;
6674 
6675  if (*conf->variable != newval ||
6676  conf->gen.extra != newextra)
6677  {
6678  if (conf->assign_hook)
6679  conf->assign_hook(newval, newextra);
6680  *conf->variable = newval;
6681  set_extra_field(&conf->gen, &conf->gen.extra,
6682  newextra);
6683  changed = true;
6684  }
6685  break;
6686  }
6687  case PGC_STRING:
6688  {
6689  struct config_string *conf = (struct config_string *) gconf;
6690  char *newval = newvalue.val.stringval;
6691  void *newextra = newvalue.extra;
6692 
6693  if (*conf->variable != newval ||
6694  conf->gen.extra != newextra)
6695  {
6696  if (conf->assign_hook)
6697  conf->assign_hook(newval, newextra);
6698  set_string_field(conf, conf->variable, newval);
6699  set_extra_field(&conf->gen, &conf->gen.extra,
6700  newextra);
6701  changed = true;
6702  }
6703 
6704  /*
6705  * Release stacked values if not used anymore. We
6706  * could use discard_stack_value() here, but since
6707  * we have type-specific code anyway, might as
6708  * well inline it.
6709  */
6710  set_string_field(conf, &stack->prior.val.stringval, NULL);
6711  set_string_field(conf, &stack->masked.val.stringval, NULL);
6712  break;
6713  }
6714  case PGC_ENUM:
6715  {
6716  struct config_enum *conf = (struct config_enum *) gconf;
6717  int newval = newvalue.val.enumval;
6718  void *newextra = newvalue.extra;
6719 
6720  if (*conf->variable != newval ||
6721  conf->gen.extra != newextra)
6722  {
6723  if (conf->assign_hook)
6724  conf->assign_hook(newval, newextra);
6725  *conf->variable = newval;
6726  set_extra_field(&conf->gen, &conf->gen.extra,
6727  newextra);
6728  changed = true;
6729  }
6730  break;
6731  }
6732  }
6733 
6734  /*
6735  * Release stacked extra values if not used anymore.
6736  */
6737  set_extra_field(gconf, &(stack->prior.extra), NULL);
6738  set_extra_field(gconf, &(stack->masked.extra), NULL);
6739 
6740  /* And restore source information */
6741  gconf->source = newsource;
6742  gconf->scontext = newscontext;
6743  }
6744 
6745  /* Finish popping the state stack */
6746  gconf->stack = prev;
6747  pfree(stack);
6748 
6749  /* Report new value if we changed it */
6750  if (changed && (gconf->flags & GUC_REPORT))
6751  {
6752  gconf->status |= GUC_NEEDS_REPORT;
6753  report_needed = true;
6754  }
6755  } /* end of stack-popping loop */
6756 
6757  if (stack != NULL)
6758  still_dirty = true;
6759  }
6760 
6761  /* If there are no remaining stack entries, we can reset guc_dirty */
6762  guc_dirty = still_dirty;
6763 
6764  /* Update nesting level */
6765  GUCNestLevel = nestLevel - 1;
6766 }
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:5262
static bool report_needed
Definition: guc.c:5160
static int GUCNestLevel
Definition: guc.c:5162
static void discard_stack_value(struct config_generic *gconf, config_var_value *val)
Definition: guc.c:5377
static bool guc_dirty
Definition: guc.c:5156
static void set_extra_field(struct config_generic *gconf, void **field, void *newval)
Definition: guc.c:5323
GucSource
Definition: guc.h:109
@ PGC_S_SESSION
Definition: guc.h:123
GucContext
Definition: guc.h:69
#define GUC_REPORT
Definition: guc.h:212
@ GUC_SET_LOCAL
Definition: guc_tables.h:111
@ GUC_SET
Definition: guc_tables.h:109
@ GUC_SAVE
Definition: guc_tables.h:108
@ GUC_LOCAL
Definition: guc_tables.h:110
#define GUC_NEEDS_REPORT
Definition: guc_tables.h:171
int i
Definition: isn.c:73
void pfree(void *pointer)
Definition: mcxt.c:1175
struct config_generic gen
Definition: guc_tables.h:178
GucBoolAssignHook assign_hook
Definition: guc_tables.h:183
GucEnumAssignHook assign_hook
Definition: guc_tables.h:244
struct config_generic gen
Definition: guc_tables.h:238
GucContext scontext
Definition: guc_tables.h:153
GucStack * stack
Definition: guc_tables.h:155
GucSource source
Definition: guc_tables.h:151
GucIntAssignHook assign_hook
Definition: guc_tables.h:199
struct config_generic gen
Definition: guc_tables.h:192
GucRealAssignHook assign_hook
Definition: guc_tables.h:215
struct config_generic gen
Definition: guc_tables.h:208
GucStringAssignHook assign_hook
Definition: guc_tables.h:229
union config_var_val val
Definition: guc_tables.h:46
struct guc_stack * prev
Definition: guc_tables.h:116
int nest_level
Definition: guc_tables.h:117
config_var_value masked
Definition: guc_tables.h:124
config_var_value prior
Definition: guc_tables.h:123
GucContext scontext
Definition: guc_tables.h:121
GucStackState state
Definition: guc_tables.h:118
GucSource source
Definition: guc_tables.h:119
GucContext masked_scontext
Definition: guc_tables.h:122
double realval
Definition: guc_tables.h:35
char * stringval
Definition: guc_tables.h:36

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_dirty, GUC_LOCAL, GUC_NEEDS_REPORT, GUC_REPORT, GUC_SAVE, GUC_SET, GUC_SET_LOCAL, guc_variables, GUCNestLevel, 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, report_needed, guc_stack::scontext, config_generic::scontext, set_extra_field(), set_string_field(), guc_stack::source, config_generic::source, config_generic::stack, guc_stack::state, config_generic::status, config_var_val::stringval, config_var_value::val, config_bool::variable, config_int::variable, config_real::variable, config_string::variable, config_enum::variable, and config_generic::vartype.

Referenced by AbortSubTransaction(), AbortTransaction(), brin_summarize_range(), bt_index_check_internal(), cluster_rel(), CommitSubTransaction(), CommitTransaction(), ComputeIndexAttrs(), DefineIndex(), do_analyze_rel(), ExecCreateTableAs(), ExecRefreshMatView(), execute_extension_script(), fmgr_security_definer(), index_build(), index_concurrently_build(), PrepareTransaction(), ProcedureCreate(), reindex_index(), ReindexRelationConcurrently(), reset_transmission_modes(), restoreLocalGucs(), RI_Initial_Check(), RI_PartitionRemove_Check(), vacuum_rel(), and validate_index().

◆ AtStart_GUC()

void AtStart_GUC ( void  )

Definition at line 6455 of file guc.c.

6456 {
6457  /*
6458  * The nest level should be 0 between transactions; if it isn't, somebody
6459  * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
6460  * throw a warning but make no other effort to clean up.
6461  */
6462  if (GUCNestLevel != 0)
6463  elog(WARNING, "GUC nest level = %d at transaction start",
6464  GUCNestLevel);
6465  GUCNestLevel = 1;
6466 }
#define WARNING
Definition: elog.h:30

References elog(), GUCNestLevel, and WARNING.

Referenced by StartTransaction().

◆ BeginReportingGUCOptions()

void BeginReportingGUCOptions ( void  )

Definition at line 6774 of file guc.c.

6775 {
6776  int i;
6777 
6778  /*
6779  * Don't do anything unless talking to an interactive frontend.
6780  */
6782  return;
6783 
6784  reporting_enabled = true;
6785 
6786  /*
6787  * Hack for in_hot_standby: set the GUC value true if appropriate. This
6788  * is kind of an ugly place to do it, but there's few better options.
6789  *
6790  * (This could be out of date by the time we actually send it, in which
6791  * case the next ReportChangedGUCOptions call will send a duplicate
6792  * report.)
6793  */
6794  if (RecoveryInProgress())
6795  SetConfigOption("in_hot_standby", "true",
6797 
6798  /* Transmit initial values of interesting variables */
6799  for (i = 0; i < num_guc_variables; i++)
6800  {
6801  struct config_generic *conf = guc_variables[i];
6802 
6803  if (conf->flags & GUC_REPORT)
6804  ReportGUCOption(conf);
6805  }
6806 
6807  report_needed = false;
6808 }
@ DestRemote
Definition: dest.h:91
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:6863
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:8373
static bool reporting_enabled
Definition: guc.c:5158
@ PGC_S_OVERRIDE
Definition: guc.h:120
CommandDest whereToSendOutput
Definition: postgres.c:92
bool RecoveryInProgress(void)
Definition: xlog.c:5762

References DestRemote, config_generic::flags, GUC_REPORT, guc_variables, i, num_guc_variables, PGC_INTERNAL, PGC_S_OVERRIDE, RecoveryInProgress(), report_needed, ReportGUCOption(), reporting_enabled, SetConfigOption(), and whereToSendOutput.

Referenced by PostgresMain().

◆ build_guc_variables()

void build_guc_variables ( void  )

Definition at line 5413 of file guc.c.

5414 {
5415  int size_vars;
5416  int num_vars = 0;
5417  struct config_generic **guc_vars;
5418  int i;
5419 
5420  for (i = 0; ConfigureNamesBool[i].gen.name; i++)
5421  {
5422  struct config_bool *conf = &ConfigureNamesBool[i];
5423 
5424  /* Rather than requiring vartype to be filled in by hand, do this: */
5425  conf->gen.vartype = PGC_BOOL;
5426  num_vars++;
5427  }
5428 
5429  for (i = 0; ConfigureNamesInt[i].gen.name; i++)
5430  {
5431  struct config_int *conf = &ConfigureNamesInt[i];
5432 
5433  conf->gen.vartype = PGC_INT;
5434  num_vars++;
5435  }
5436 
5437  for (i = 0; ConfigureNamesReal[i].gen.name; i++)
5438  {
5439  struct config_real *conf = &ConfigureNamesReal[i];
5440 
5441  conf->gen.vartype = PGC_REAL;
5442  num_vars++;
5443  }
5444 
5445  for (i = 0; ConfigureNamesString[i].gen.name; i++)
5446  {
5447  struct config_string *conf = &ConfigureNamesString[i];
5448 
5449  conf->gen.vartype = PGC_STRING;
5450  num_vars++;
5451  }
5452 
5453  for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
5454  {
5455  struct config_enum *conf = &ConfigureNamesEnum[i];
5456 
5457  conf->gen.vartype = PGC_ENUM;
5458  num_vars++;
5459  }
5460 
5461  /*
5462  * Create table with 20% slack
5463  */
5464  size_vars = num_vars + num_vars / 4;
5465 
5466  guc_vars = (struct config_generic **)
5467  guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
5468 
5469  num_vars = 0;
5470 
5471  for (i = 0; ConfigureNamesBool[i].gen.name; i++)
5472  guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
5473 
5474  for (i = 0; ConfigureNamesInt[i].gen.name; i++)
5475  guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
5476 
5477  for (i = 0; ConfigureNamesReal[i].gen.name; i++)
5478  guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
5479 
5480  for (i = 0; ConfigureNamesString[i].gen.name; i++)
5481  guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
5482 
5483  for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
5484  guc_vars[num_vars++] = &ConfigureNamesEnum[i].gen;
5485 
5487  guc_variables = guc_vars;
5488  num_guc_variables = num_vars;
5489  size_guc_variables = size_vars;
5491  sizeof(struct config_generic *), guc_var_compare);
5492 }
#define FATAL
Definition: elog.h:35
static struct config_string ConfigureNamesString[]
Definition: guc.c:3953
static struct config_int ConfigureNamesInt[]
Definition: guc.c:2192
static struct config_bool ConfigureNamesBool[]
Definition: guc.c:1013
static struct config_real ConfigureNamesReal[]
Definition: guc.c:3672
static struct config_enum ConfigureNamesEnum[]
Definition: guc.c:4731

References ConfigureNamesBool, ConfigureNamesEnum, ConfigureNamesInt, ConfigureNamesReal, ConfigureNamesString, FATAL, free, config_bool::gen, config_int::gen, config_real::gen, config_string::gen, config_enum::gen, guc_malloc(), guc_var_compare(), guc_variables, i, config_generic::name, num_guc_variables, PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_STRING, qsort, size_guc_variables, and config_generic::vartype.

Referenced by GucInfoMain(), and InitializeGUCOptions().

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

11743 {
11744  /* Quick success if no hook */
11745  if (!conf->check_hook)
11746  return true;
11747 
11748  /* Reset variables that might be set by hook */
11749  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
11750  GUC_check_errmsg_string = NULL;
11752  GUC_check_errhint_string = NULL;
11753 
11754  if (!conf->check_hook(newval, extra, source))
11755  {
11756  ereport(elevel,
11760  errmsg("invalid value for parameter \"%s\": %d",
11761  conf->gen.name, (int) *newval),
11765  errhint("%s", GUC_check_errhint_string) : 0));
11766  /* Flush any strings created in ErrorContext */
11767  FlushErrorState();
11768  return false;
11769  }
11770 
11771  return true;
11772 }
int errmsg_internal(const char *fmt,...)
Definition: elog.c:991
int errdetail_internal(const char *fmt,...)
Definition: elog.c:1064
void FlushErrorState(void)
Definition: elog.c:1649
int errhint(const char *fmt,...)
Definition: elog.c:1151
char * GUC_check_errhint_string
Definition: guc.c:161
char * GUC_check_errmsg_string
Definition: guc.c:159
static int GUC_check_errcode_value
Definition: guc.c:154
char * GUC_check_errdetail_string
Definition: guc.c:160
static rewind_source * source
Definition: pg_rewind.c:81
GucBoolCheckHook check_hook
Definition: guc_tables.h:182

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

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

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

11895 {
11896  /* Quick success if no hook */
11897  if (!conf->check_hook)
11898  return true;
11899 
11900  /* Reset variables that might be set by hook */
11901  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
11902  GUC_check_errmsg_string = NULL;
11904  GUC_check_errhint_string = NULL;
11905 
11906  if (!conf->check_hook(newval, extra, source))
11907  {
11908  ereport(elevel,
11912  errmsg("invalid value for parameter \"%s\": \"%s\"",
11913  conf->gen.name,
11918  errhint("%s", GUC_check_errhint_string) : 0));
11919  /* Flush any strings created in ErrorContext */
11920  FlushErrorState();
11921  return false;
11922  }
11923 
11924  return true;
11925 }
GucEnumCheckHook check_hook
Definition: guc_tables.h:243

References config_enum::check_hook, config_enum_lookup_by_value(), ereport, errcode(), errdetail_internal(), errhint(), errmsg(), errmsg_internal(), config_generic::extra, FlushErrorState(), config_enum::gen, GUC_check_errcode_value, GUC_check_errdetail_string, GUC_check_errhint_string, GUC_check_errmsg_string, config_generic::name, newval, and source.

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

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

11777 {
11778  /* Quick success if no hook */
11779  if (!conf->check_hook)
11780  return true;
11781 
11782  /* Reset variables that might be set by hook */
11783  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
11784  GUC_check_errmsg_string = NULL;
11786  GUC_check_errhint_string = NULL;
11787 
11788  if (!conf->check_hook(newval, extra, source))
11789  {
11790  ereport(elevel,
11794  errmsg("invalid value for parameter \"%s\": %d",
11795  conf->gen.name, *newval),
11799  errhint("%s", GUC_check_errhint_string) : 0));
11800  /* Flush any strings created in ErrorContext */
11801  FlushErrorState();
11802  return false;
11803  }
11804 
11805  return true;
11806 }
GucIntCheckHook check_hook
Definition: guc_tables.h:198

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

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

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

11811 {
11812  /* Quick success if no hook */
11813  if (!conf->check_hook)
11814  return true;
11815 
11816  /* Reset variables that might be set by hook */
11817  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
11818  GUC_check_errmsg_string = NULL;
11820  GUC_check_errhint_string = NULL;
11821 
11822  if (!conf->check_hook(newval, extra, source))
11823  {
11824  ereport(elevel,
11828  errmsg("invalid value for parameter \"%s\": %g",
11829  conf->gen.name, *newval),
11833  errhint("%s", GUC_check_errhint_string) : 0));
11834  /* Flush any strings created in ErrorContext */
11835  FlushErrorState();
11836  return false;
11837  }
11838 
11839  return true;
11840 }
GucRealCheckHook check_hook
Definition: guc_tables.h:214

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

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

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

11845 {
11846  volatile bool result = true;
11847 
11848  /* Quick success if no hook */
11849  if (!conf->check_hook)
11850  return true;
11851 
11852  /*
11853  * If elevel is ERROR, or if the check_hook itself throws an elog
11854  * (undesirable, but not always avoidable), make sure we don't leak the
11855  * already-malloc'd newval string.
11856  */
11857  PG_TRY();
11858  {
11859  /* Reset variables that might be set by hook */
11860  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
11861  GUC_check_errmsg_string = NULL;
11863  GUC_check_errhint_string = NULL;
11864 
11865  if (!conf->check_hook(newval, extra, source))
11866  {
11867  ereport(elevel,
11871  errmsg("invalid value for parameter \"%s\": \"%s\"",
11872  conf->gen.name, *newval ? *newval : ""),
11876  errhint("%s", GUC_check_errhint_string) : 0));
11877  /* Flush any strings created in ErrorContext */
11878  FlushErrorState();
11879  result = false;
11880  }
11881  }
11882  PG_CATCH();
11883  {
11884  free(*newval);
11885  PG_RE_THROW();
11886  }
11887  PG_END_TRY();
11888 
11889  return result;
11890 }
GucStringCheckHook check_hook
Definition: guc_tables.h:228

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

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

◆ can_skip_gucvar()

static bool can_skip_gucvar ( struct config_generic gconf)
static

Definition at line 10804 of file guc.c.

10805 {
10806  /*
10807  * We can skip GUCs that are guaranteed to have the same values in leaders
10808  * and workers. (Note it is critical that the leader and worker have the
10809  * same idea of which GUCs fall into this category. It's okay to consider
10810  * context and name for this purpose, since those are unchanging
10811  * properties of a GUC.)
10812  *
10813  * PGC_POSTMASTER variables always have the same value in every child of a
10814  * particular postmaster, so the worker will certainly have the right
10815  * value already. Likewise, PGC_INTERNAL variables are set by special
10816  * mechanisms (if indeed they aren't compile-time constants). So we may
10817  * always skip these.
10818  *
10819  * Role must be handled specially because its current value can be an
10820  * invalid value (for instance, if someone dropped the role since we set
10821  * it). So if we tried to serialize it normally, we might get a failure.
10822  * We skip it here, and use another mechanism to ensure the worker has the
10823  * right value.
10824  *
10825  * For all other GUCs, we skip if the GUC has its compiled-in default
10826  * value (i.e., source == PGC_S_DEFAULT). On the leader side, this means
10827  * we don't send GUCs that have their default values, which typically
10828  * saves lots of work. On the worker side, this means we don't need to
10829  * reset the GUC to default because it already has that value. See
10830  * comments in RestoreGUCState for more info.
10831  */
10832  return gconf->context == PGC_POSTMASTER ||
10833  gconf->context == PGC_INTERNAL || gconf->source == PGC_S_DEFAULT ||
10834  strcmp(gconf->name, "role") == 0;
10835 }
@ PGC_S_DEFAULT
Definition: guc.h:110
@ PGC_POSTMASTER
Definition: guc.h:71

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

◆ check_application_name()

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

Definition at line 12480 of file guc.c.

12481 {
12482  /* Only allow clean ASCII chars in the application name */
12484 
12485  return true;
12486 }
void pg_clean_ascii(char *str)
Definition: string.c:82

References newval, and pg_clean_ascii().

◆ check_autovacuum_max_workers()

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

Definition at line 12365 of file guc.c.

12366 {
12367  if (MaxConnections + *newval + 1 +
12369  return false;
12370  return true;
12371 }
int MaxConnections
Definition: globals.c:137
int max_worker_processes
Definition: globals.c:138
#define MAX_BACKENDS
Definition: postmaster.h:75
int max_wal_senders
Definition: walsender.c:122

References MAX_BACKENDS, max_wal_senders, max_worker_processes, MaxConnections, and newval.

◆ check_autovacuum_work_mem()

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

Definition at line 12383 of file guc.c.

12384 {
12385  /*
12386  * -1 indicates fallback.
12387  *
12388  * If we haven't yet changed the boot_val default of -1, just let it be.
12389  * Autovacuum will look to maintenance_work_mem instead.
12390  */
12391  if (*newval == -1)
12392  return true;
12393 
12394  /*
12395  * We clamp manually-set values to at least 1MB. Since
12396  * maintenance_work_mem is always set to at least this value, do the same
12397  * here.
12398  */
12399  if (*newval < 1024)
12400  *newval = 1024;
12401 
12402  return true;
12403 }

References newval.

◆ check_backtrace_functions()

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

Definition at line 12552 of file guc.c.

12553 {
12554  int newvallen = strlen(*newval);
12555  char *someval;
12556  int validlen;
12557  int i;
12558  int j;
12559 
12560  /*
12561  * Allow characters that can be C identifiers and commas as separators, as
12562  * well as some whitespace for readability.
12563  */
12564  validlen = strspn(*newval,
12565  "0123456789_"
12566  "abcdefghijklmnopqrstuvwxyz"
12567  "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
12568  ", \n\t");
12569  if (validlen != newvallen)
12570  {
12571  GUC_check_errdetail("invalid character");
12572  return false;
12573  }
12574 
12575  if (*newval[0] == '\0')
12576  {
12577  *extra = NULL;
12578  return true;
12579  }
12580 
12581  /*
12582  * Allocate space for the output and create the copy. We could discount
12583  * whitespace chars to save some memory, but it doesn't seem worth the
12584  * trouble.
12585  */
12586  someval = guc_malloc(ERROR, newvallen + 1 + 1);
12587  for (i = 0, j = 0; i < newvallen; i++)
12588  {
12589  if ((*newval)[i] == ',')
12590  someval[j++] = '\0'; /* next item */
12591  else if ((*newval)[i] == ' ' ||
12592  (*newval)[i] == '\n' ||
12593  (*newval)[i] == '\t')
12594  ; /* ignore these */
12595  else
12596  someval[j++] = (*newval)[i]; /* copy anything else */
12597  }
12598 
12599  /* two \0s end the setting */
12600  someval[j] = '\0';
12601  someval[j + 1] = '\0';
12602 
12603  *extra = someval;
12604  return true;
12605 }
#define GUC_check_errdetail
Definition: guc.h:431
int j
Definition: isn.c:74

References ERROR, config_generic::extra, GUC_check_errdetail, guc_malloc(), i, j, and newval.

◆ check_bonjour()

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

Definition at line 12148 of file guc.c.

12149 {
12150 #ifndef USE_BONJOUR
12151  if (*newval)
12152  {
12153  GUC_check_errmsg("Bonjour is not supported by this build");
12154  return false;
12155  }
12156 #endif
12157  return true;
12158 }
#define GUC_check_errmsg
Definition: guc.h:427

References GUC_check_errmsg, and newval.

◆ check_canonical_path()

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

Definition at line 12199 of file guc.c.

12200 {
12201  /*
12202  * Since canonicalize_path never enlarges the string, we can just modify
12203  * newval in-place. But watch out for NULL, which is the default value
12204  * for external_pid_file.
12205  */
12206  if (*newval)
12208  return true;
12209 }
void canonicalize_path(char *path)
Definition: path.c:264

References canonicalize_path(), and newval.

◆ check_client_connection_check_interval()

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

Definition at line 12455 of file guc.c.

12456 {
12457  if (!WaitEventSetCanReportClosed() && *newval != 0)
12458  {
12459  GUC_check_errdetail("client_connection_check_interval must be set to 0 on this platform");
12460  return false;
12461  }
12462  return true;
12463 }
bool WaitEventSetCanReportClosed(void)
Definition: latch.c:2091

References GUC_check_errdetail, newval, and WaitEventSetCanReportClosed().

◆ check_cluster_name()

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

Definition at line 12496 of file guc.c.

12497 {
12498  /* Only allow clean ASCII chars in the cluster name */
12500 
12501  return true;
12502 }

References newval, and pg_clean_ascii().

◆ check_default_with_oids()

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

Definition at line 12881 of file guc.c.

12882 {
12883  if (*newval)
12884  {
12885  /* check the GUC's definition for an explanation */
12886  GUC_check_errcode(ERRCODE_FEATURE_NOT_SUPPORTED);
12887  GUC_check_errmsg("tables declared WITH OIDS are not supported");
12888 
12889  return false;
12890  }
12891 
12892  return true;
12893 }
void GUC_check_errcode(int sqlerrcode)
Definition: guc.c:11728

References GUC_check_errcode(), GUC_check_errmsg, and newval.

◆ check_effective_io_concurrency()

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

Definition at line 12415 of file guc.c.

12416 {
12417 #ifndef USE_PREFETCH
12418  if (*newval != 0)
12419  {
12420  GUC_check_errdetail("effective_io_concurrency must be set to 0 on platforms that lack posix_fadvise().");
12421  return false;
12422  }
12423 #endif /* USE_PREFETCH */
12424  return true;
12425 }

References GUC_check_errdetail, and newval.

◆ check_GUC_name_for_parameter_acl()

bool check_GUC_name_for_parameter_acl ( const char *  name)

Definition at line 5816 of file guc.c.

5817 {
5818  /* OK if the GUC exists. */
5819  if (find_option(name, false, true, DEBUG1) != NULL)
5820  return true;
5821  /* Otherwise, it'd better be a valid custom GUC name. */
5823  return true;
5824  return false;
5825 }
#define DEBUG1
Definition: elog.h:24
static bool valid_custom_variable_name(const char *name)
Definition: guc.c:5541

References DEBUG1, find_option(), name, and valid_custom_variable_name().

Referenced by ParameterAclCreate().

◆ check_huge_page_size()

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

Definition at line 12441 of file guc.c.

12442 {
12443 #if !(defined(MAP_HUGE_MASK) && defined(MAP_HUGE_SHIFT))
12444  /* Recent enough Linux only, for now. See GetHugePageSize(). */
12445  if (*newval != 0)
12446  {
12447  GUC_check_errdetail("huge_page_size must be 0 on this platform.");
12448  return false;
12449  }
12450 #endif
12451  return true;
12452 }

References GUC_check_errdetail, and newval.

◆ check_log_destination()

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

Definition at line 12037 of file guc.c.

12038 {
12039  char *rawstring;
12040  List *elemlist;
12041  ListCell *l;
12042  int newlogdest = 0;
12043  int *myextra;
12044 
12045  /* Need a modifiable copy of string */
12046  rawstring = pstrdup(*newval);
12047 
12048  /* Parse string into list of identifiers */
12049  if (!SplitIdentifierString(rawstring, ',', &elemlist))
12050  {
12051  /* syntax error in list */
12052  GUC_check_errdetail("List syntax is invalid.");
12053  pfree(rawstring);
12054  list_free(elemlist);
12055  return false;
12056  }
12057 
12058  foreach(l, elemlist)
12059  {
12060  char *tok = (char *) lfirst(l);
12061 
12062  if (pg_strcasecmp(tok, "stderr") == 0)
12063  newlogdest |= LOG_DESTINATION_STDERR;
12064  else if (pg_strcasecmp(tok, "csvlog") == 0)
12065  newlogdest |= LOG_DESTINATION_CSVLOG;
12066  else if (pg_strcasecmp(tok, "jsonlog") == 0)
12067  newlogdest |= LOG_DESTINATION_JSONLOG;
12068 #ifdef HAVE_SYSLOG
12069  else if (pg_strcasecmp(tok, "syslog") == 0)
12070  newlogdest |= LOG_DESTINATION_SYSLOG;
12071 #endif
12072 #ifdef WIN32
12073  else if (pg_strcasecmp(tok, "eventlog") == 0)
12074  newlogdest |= LOG_DESTINATION_EVENTLOG;
12075 #endif
12076  else
12077  {
12078  GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
12079  pfree(rawstring);
12080  list_free(elemlist);
12081  return false;
12082  }
12083  }
12084 
12085  pfree(rawstring);
12086  list_free(elemlist);
12087 
12088  myextra = (int *) guc_malloc(ERROR, sizeof(int));
12089  *myextra = newlogdest;
12090  *extra = (void *) myextra;
12091 
12092  return true;
12093 }
#define LOG_DESTINATION_JSONLOG
Definition: elog.h:425
#define LOG_DESTINATION_SYSLOG
Definition: elog.h:422
#define LOG_DESTINATION_STDERR
Definition: elog.h:421
#define LOG_DESTINATION_EVENTLOG
Definition: elog.h:423
#define LOG_DESTINATION_CSVLOG
Definition: elog.h:424
void list_free(List *list)
Definition: list.c:1545
#define lfirst(lc)
Definition: pg_list.h:170
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
Definition: pg_list.h:52
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3715

References ERROR, config_generic::extra, GUC_check_errdetail, guc_malloc(), lfirst, list_free(), LOG_DESTINATION_CSVLOG, LOG_DESTINATION_EVENTLOG, LOG_DESTINATION_JSONLOG, LOG_DESTINATION_STDERR, LOG_DESTINATION_SYSLOG, newval, pfree(), pg_strcasecmp(), pstrdup(), and SplitIdentifierString().

◆ check_log_stats()

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

Definition at line 12185 of file guc.c.

12186 {
12187  if (*newval &&
12189  {
12190  GUC_check_errdetail("Cannot enable \"log_statement_stats\" when "
12191  "\"log_parser_stats\", \"log_planner_stats\", "
12192  "or \"log_executor_stats\" is true.");
12193  return false;
12194  }
12195  return true;
12196 }
bool log_parser_stats
Definition: guc.c:617
bool log_planner_stats
Definition: guc.c:618
bool log_executor_stats
Definition: guc.c:619

References GUC_check_errdetail, log_executor_stats, log_parser_stats, log_planner_stats, and newval.

◆ check_maintenance_io_concurrency()

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

Definition at line 12428 of file guc.c.

12429 {
12430 #ifndef USE_PREFETCH
12431  if (*newval != 0)
12432  {
12433  GUC_check_errdetail("maintenance_io_concurrency must be set to 0 on platforms that lack posix_fadvise().");
12434  return false;
12435  }
12436 #endif /* USE_PREFETCH */
12437  return true;
12438 }

References GUC_check_errdetail, and newval.

◆ check_max_wal_senders()

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

Definition at line 12374 of file guc.c.

12375 {
12378  return false;
12379  return true;
12380 }
int autovacuum_max_workers
Definition: autovacuum.c:116

References autovacuum_max_workers, MAX_BACKENDS, max_worker_processes, MaxConnections, and newval.

◆ check_max_worker_processes()

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

Definition at line 12406 of file guc.c.

12407 {
12410  return false;
12411  return true;
12412 }

References autovacuum_max_workers, MAX_BACKENDS, max_wal_senders, MaxConnections, and newval.

◆ check_maxconnections()

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

Definition at line 12356 of file guc.c.

12357 {
12358  if (*newval + autovacuum_max_workers + 1 +
12360  return false;
12361  return true;
12362 }

References autovacuum_max_workers, MAX_BACKENDS, max_wal_senders, max_worker_processes, and newval.

◆ check_primary_slot_name()

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

Definition at line 12871 of file guc.c.

12872 {
12873  if (*newval && strcmp(*newval, "") != 0 &&
12875  return false;
12876 
12877  return true;
12878 }
bool ReplicationSlotValidateName(const char *name, int elevel)
Definition: slot.c:201

References newval, ReplicationSlotValidateName(), and WARNING.

◆ check_recovery_target()

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

Definition at line 12676 of file guc.c.

12677 {
12678  if (strcmp(*newval, "immediate") != 0 && strcmp(*newval, "") != 0)
12679  {
12680  GUC_check_errdetail("The only allowed value is \"immediate\".");
12681  return false;
12682  }
12683  return true;
12684 }

References GUC_check_errdetail, and newval.

◆ check_recovery_target_lsn()

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

Definition at line 12835 of file guc.c.

12836 {
12837  if (strcmp(*newval, "") != 0)
12838  {
12839  XLogRecPtr lsn;
12840  XLogRecPtr *myextra;
12841  bool have_error = false;
12842 
12843  lsn = pg_lsn_in_internal(*newval, &have_error);
12844  if (have_error)
12845  return false;
12846 
12847  myextra = (XLogRecPtr *) guc_malloc(ERROR, sizeof(XLogRecPtr));
12848  *myextra = lsn;
12849  *extra = (void *) myextra;
12850  }
12851  return true;
12852 }
XLogRecPtr pg_lsn_in_internal(const char *str, bool *have_error)
Definition: pg_lsn.c:30

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

◆ check_recovery_target_name()

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

Definition at line 12806 of file guc.c.

12807 {
12808  /* Use the value of newval directly */
12809  if (strlen(*newval) >= MAXFNAMELEN)
12810  {
12811  GUC_check_errdetail("%s is too long (maximum %d characters).",
12812  "recovery_target_name", MAXFNAMELEN - 1);
12813  return false;
12814  }
12815  return true;
12816 }
#define MAXFNAMELEN

References GUC_check_errdetail, MAXFNAMELEN, and newval.

◆ check_recovery_target_time()

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

Definition at line 12743 of file guc.c.

12744 {
12745  if (strcmp(*newval, "") != 0)
12746  {
12747  /* reject some special values */
12748  if (strcmp(*newval, "now") == 0 ||
12749  strcmp(*newval, "today") == 0 ||
12750  strcmp(*newval, "tomorrow") == 0 ||
12751  strcmp(*newval, "yesterday") == 0)
12752  {
12753  return false;
12754  }
12755 
12756  /*
12757  * parse timestamp value (see also timestamptz_in())
12758  */
12759  {
12760  char *str = *newval;
12761  fsec_t fsec;
12762  struct pg_tm tt,
12763  *tm = &tt;
12764  int tz;
12765  int dtype;
12766  int nf;
12767  int dterr;
12768  char *field[MAXDATEFIELDS];
12769  int ftype[MAXDATEFIELDS];
12770  char workbuf[MAXDATELEN + MAXDATEFIELDS];
12772 
12773  dterr = ParseDateTime(str, workbuf, sizeof(workbuf),
12774  field, ftype, MAXDATEFIELDS, &nf);
12775  if (dterr == 0)
12776  dterr = DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tz);
12777  if (dterr != 0)
12778  return false;
12779  if (dtype != DTK_DATE)
12780  return false;
12781 
12782  if (tm2timestamp(tm, fsec, &tz, &timestamp) != 0)
12783  {
12784  GUC_check_errdetail("timestamp out of range: \"%s\"", str);
12785  return false;
12786  }
12787  }
12788  }
12789  return true;
12790 }
int ParseDateTime(const char *timestr, char *workbuf, size_t buflen, char **field, int *ftype, int maxfields, int *numfields)
Definition: datetime.c:752
int DecodeDateTime(char **field, int *ftype, int nf, int *dtype, struct pg_tm *tm, fsec_t *fsec, int *tzp)
Definition: datetime.c:973
int tm2timestamp(struct pg_tm *tm, fsec_t fsec, int *tzp, Timestamp *result)
Definition: timestamp.c:1912
int64 TimestampTz
Definition: timestamp.h:39
int32 fsec_t
Definition: timestamp.h:41
#define MAXDATEFIELDS
Definition: datetime.h:203
#define DTK_DATE
Definition: datetime.h:145
#define MAXDATELEN
Definition: datetime.h:201
static struct pg_tm tm
Definition: localtime.c:102
int64 timestamp
Definition: pgtime.h:35

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

◆ check_recovery_target_timeline()

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

Definition at line 12614 of file guc.c.

12615 {
12617  RecoveryTargetTimeLineGoal *myextra;
12618 
12619  if (strcmp(*newval, "current") == 0)
12621  else if (strcmp(*newval, "latest") == 0)
12623  else
12624  {
12626 
12627  errno = 0;
12628  strtoul(*newval, NULL, 0);
12629  if (errno == EINVAL || errno == ERANGE)
12630  {
12631  GUC_check_errdetail("recovery_target_timeline is not a valid number.");
12632  return false;
12633  }
12634  }
12635 
12637  *myextra = rttg;
12638  *extra = (void *) myextra;
12639 
12640  return true;
12641 }
@ RECOVERY_TARGET_TIMELINE_CONTROLFILE
Definition: xlogrecovery.h:38
@ RECOVERY_TARGET_TIMELINE_LATEST
Definition: xlogrecovery.h:39

References ERROR, config_generic::extra, GUC_check_errdetail, guc_malloc(), newval, RECOVERY_TARGET_TIMELINE_CONTROLFILE, RECOVERY_TARGET_TIMELINE_LATEST, and RECOVERY_TARGET_TIMELINE_NUMERIC.

◆ check_recovery_target_xid()

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

Definition at line 12700 of file guc.c.

12701 {
12702  if (strcmp(*newval, "") != 0)
12703  {
12704  TransactionId xid;
12705  TransactionId *myextra;
12706 
12707  errno = 0;
12708  xid = (TransactionId) strtou64(*newval, NULL, 0);
12709  if (errno == EINVAL || errno == ERANGE)
12710  return false;
12711 
12712  myextra = (TransactionId *) guc_malloc(ERROR, sizeof(TransactionId));
12713  *myextra = xid;
12714  *extra = (void *) myextra;
12715  }
12716  return true;
12717 }
#define strtou64(str, endptr, base)
Definition: c.h:1333

References ERROR, config_generic::extra, guc_malloc(), newval, and strtou64.

◆ check_ssl()

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

Definition at line 12161 of file guc.c.

12162 {
12163 #ifndef USE_SSL
12164  if (*newval)
12165  {
12166  GUC_check_errmsg("SSL is not supported by this build");
12167  return false;
12168  }
12169 #endif
12170  return true;
12171 }

References GUC_check_errmsg, and newval.

◆ check_stage_log_stats()

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

Definition at line 12174 of file guc.c.

12175 {
12176  if (*newval && log_statement_stats)
12177  {
12178  GUC_check_errdetail("Cannot enable parameter when \"log_statement_stats\" is true.");
12179  return false;
12180  }
12181  return true;
12182 }
bool log_statement_stats
Definition: guc.c:620

References GUC_check_errdetail, log_statement_stats, and newval.

◆ check_temp_buffers()

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

Definition at line 12133 of file guc.c.

12134 {
12135  /*
12136  * Once local buffers have been initialized, it's too late to change this.
12137  * However, if this is only a test call, allow it.
12138  */
12139  if (source != PGC_S_TEST && NLocBuffer && NLocBuffer != *newval)
12140  {
12141  GUC_check_errdetail("\"temp_buffers\" cannot be changed after any temporary tables have been accessed in the session.");
12142  return false;
12143  }
12144  return true;
12145 }
@ PGC_S_TEST
Definition: guc.h:122
int NLocBuffer
Definition: localbuf.c:41

References GUC_check_errdetail, newval, NLocBuffer, PGC_S_TEST, and source.

◆ check_timezone_abbreviations()

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

Definition at line 12212 of file guc.c.

12213 {
12214  /*
12215  * The boot_val given above for timezone_abbreviations is NULL. When we
12216  * see this we just do nothing. If this value isn't overridden from the
12217  * config file then pg_timezone_abbrev_initialize() will eventually
12218  * replace it with "Default". This hack has two purposes: to avoid
12219  * wasting cycles loading values that might soon be overridden from the
12220  * config file, and to avoid trying to read the timezone abbrev files
12221  * during InitializeGUCOptions(). The latter doesn't work in an
12222  * EXEC_BACKEND subprocess because my_exec_path hasn't been set yet and so
12223  * we can't locate PGSHAREDIR.
12224  */
12225  if (*newval == NULL)
12226  {
12228  return true;
12229  }
12230 
12231  /* OK, load the file and produce a malloc'd TimeZoneAbbrevTable */
12232  *extra = load_tzoffsets(*newval);
12233 
12234  /* tzparser.c returns NULL on failure, reporting via GUC_check_errmsg */
12235  if (!*extra)
12236  return false;
12237 
12238  return true;
12239 }
TimeZoneAbbrevTable * load_tzoffsets(const char *filename)
Definition: tzparser.c:446

References Assert(), config_generic::extra, load_tzoffsets(), newval, PGC_S_DEFAULT, and source.

◆ check_wal_consistency_checking()

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

Definition at line 11933 of file guc.c.

11934 {
11935  char *rawstring;
11936  List *elemlist;
11937  ListCell *l;
11938  bool newwalconsistency[RM_MAX_ID + 1];
11939 
11940  /* Initialize the array */
11941  MemSet(newwalconsistency, 0, (RM_MAX_ID + 1) * sizeof(bool));
11942 
11943  /* Need a modifiable copy of string */
11944  rawstring = pstrdup(*newval);
11945 
11946  /* Parse string into list of identifiers */
11947  if (!SplitIdentifierString(rawstring, ',', &elemlist))
11948  {
11949  /* syntax error in list */
11950  GUC_check_errdetail("List syntax is invalid.");
11951  pfree(rawstring);
11952  list_free(elemlist);
11953  return false;
11954  }
11955 
11956  foreach(l, elemlist)
11957  {
11958  char *tok = (char *) lfirst(l);
11959  bool found = false;
11960  int rmid;
11961 
11962  /* Check for 'all'. */
11963  if (pg_strcasecmp(tok, "all") == 0)
11964  {
11965  for (rmid = 0; rmid <= RM_MAX_ID; rmid++)
11966  if (RmgrIdExists(rmid) && GetRmgr(rmid).rm_mask != NULL)
11967  newwalconsistency[rmid] = true;
11968  found = true;
11969  }
11970  else
11971  {
11972  /*
11973  * Check if the token matches with any individual resource
11974  * manager.
11975  */
11976  for (rmid = 0; rmid <= RM_MAX_ID; rmid++)
11977  {
11978  if (RmgrIdExists(rmid) && GetRmgr(rmid).rm_mask != NULL &&
11979  pg_strcasecmp(tok, GetRmgr(rmid).rm_name) == 0)
11980  {
11981  newwalconsistency[rmid] = true;
11982  found = true;
11983  }
11984  }
11985  }
11986 
11987  /* If a valid resource manager is found, check for the next one. */
11988  if (!found)
11989  {
11990  /*
11991  * Perhaps it's a custom resource manager. If so, defer checking
11992  * until InitializeWalConsistencyChecking().
11993  */
11995  {
11997  }
11998  else
11999  {
12000  GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
12001  pfree(rawstring);
12002  list_free(elemlist);
12003  return false;
12004  }
12005  }
12006  }
12007 
12008  pfree(rawstring);
12009  list_free(elemlist);
12010 
12011  /* assign new value */
12012  *extra = guc_malloc(ERROR, (RM_MAX_ID + 1) * sizeof(bool));
12013  memcpy(*extra, newwalconsistency, (RM_MAX_ID + 1) * sizeof(bool));
12014  return true;
12015 }
#define MemSet(start, val, len)
Definition: c.h:1019
static bool check_wal_consistency_checking_deferred
Definition: guc.c:254
bool process_shared_preload_libraries_done
Definition: miscinit.c:1618
#define RM_MAX_ID
Definition: rmgr.h:33
void(* rm_mask)(char *pagedata, BlockNumber blkno)
static RmgrData GetRmgr(RmgrId rmid)
static bool RmgrIdExists(RmgrId rmid)

References check_wal_consistency_checking_deferred, ERROR, config_generic::extra, GetRmgr(), GUC_check_errdetail, guc_malloc(), lfirst, list_free(), MemSet, newval, pfree(), pg_strcasecmp(), process_shared_preload_libraries_done, pstrdup(), RmgrData::rm_mask, RM_MAX_ID, RmgrIdExists(), and SplitIdentifierString().

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

7305 {
7306  const struct config_enum_entry *entry;
7307  StringInfoData retstr;
7308  int seplen;
7309 
7310  initStringInfo(&retstr);
7311  appendStringInfoString(&retstr, prefix);
7312 
7313  seplen = strlen(separator);
7314  for (entry = record->options; entry && entry->name; entry++)
7315  {
7316  if (!entry->hidden)
7317  {
7318  appendStringInfoString(&retstr, entry->name);
7319  appendBinaryStringInfo(&retstr, separator, seplen);
7320  }
7321  }
7322 
7323  /*
7324  * All the entries may have been hidden, leaving the string empty if no
7325  * prefix was given. This indicates a broken GUC setup, since there is no
7326  * use for an enum without any values, so we just check to make sure we
7327  * don't write to invalid memory instead of actually trying to do
7328  * something smart with it.
7329  */
7330  if (retstr.len >= seplen)
7331  {
7332  /* Replace final separator */
7333  retstr.data[retstr.len - seplen] = '\0';
7334  retstr.len -= seplen;
7335  }
7336 
7337  appendStringInfoString(&retstr, suffix);
7338 
7339  return retstr.data;
7340 }
void appendBinaryStringInfo(StringInfo str, const char *data, int datalen)
Definition: stringinfo.c:227
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
Definition: guc.h:169
const char * name
Definition: guc.h:170
bool hidden
Definition: guc.h:172
const struct config_enum_entry * options
Definition: guc_tables.h:242

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

◆ config_enum_lookup_by_name()

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

Definition at line 7277 of file guc.c.

7279 {
7280  const struct config_enum_entry *entry;
7281 
7282  for (entry = record->options; entry && entry->name; entry++)
7283  {
7284  if (pg_strcasecmp(value, entry->name) == 0)
7285  {
7286  *retval = entry->val;
7287  return true;
7288  }
7289  }
7290 
7291  *retval = 0;
7292  return false;
7293 }
int val
Definition: guc.h:171

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

Referenced by parse_and_validate_value().

◆ config_enum_lookup_by_value()

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

Definition at line 7254 of file guc.c.

7255 {
7256  const struct config_enum_entry *entry;
7257 
7258  for (entry = record->options; entry && entry->name; entry++)
7259  {
7260  if (entry->val == val)
7261  return entry->name;
7262  }
7263 
7264  elog(ERROR, "could not find enum option %d for %s",
7265  val, record->gen.name);
7266  return NULL; /* silence compiler */
7267 }

References elog(), ERROR, config_enum::gen, config_enum_entry::name, config_generic::name, config_enum::options, config_enum_entry::val, and val.

Referenced by _ShowOption(), call_enum_check_hook(), estimate_variable_size(), GetConfigOption(), GetConfigOptionByNum(), GetConfigOptionResetString(), and serialize_variable().

◆ convert_GUC_name_for_parameter_acl()

char* convert_GUC_name_for_parameter_acl ( const char *  name)

Definition at line 5780 of file guc.c.

5781 {
5782  char *result;
5783 
5784  /* Apply old-GUC-name mapping. */
5785  for (int i = 0; map_old_guc_names[i] != NULL; i += 2)
5786  {
5788  {
5789  name = map_old_guc_names[i + 1];
5790  break;
5791  }
5792  }
5793 
5794  /* Apply case-folding that matches guc_name_compare(). */
5795  result = pstrdup(name);
5796  for (char *ptr = result; *ptr != '\0'; ptr++)
5797  {
5798  char ch = *ptr;
5799 
5800  if (ch >= 'A' && ch <= 'Z')
5801  {
5802  ch += 'a' - 'A';
5803  *ptr = ch;
5804  }
5805  }
5806 
5807  return result;
5808 }
static const char *const map_old_guc_names[]
Definition: guc.c:5137
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:5742

References guc_name_compare(), i, map_old_guc_names, name, and pstrdup().

Referenced by ParameterAclCreate(), ParameterAclLookup(), and pg_parameter_aclmask().

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

6962 {
6963  const unit_conversion *table;
6964  int i;
6965 
6966  *unit = NULL;
6967 
6968  if (base_unit & GUC_UNIT_MEMORY)
6970  else
6972 
6973  for (i = 0; *table[i].unit; i++)
6974  {
6975  if (base_unit == table[i].base_unit)
6976  {
6977  /*
6978  * Accept the first conversion that divides the value evenly. We
6979  * assume that the conversions for each base unit are ordered from
6980  * greatest unit to the smallest!
6981  */
6982  if (table[i].multiplier <= 1.0 ||
6983  base_value % (int64) table[i].multiplier == 0)
6984  {
6985  *value = (int64) rint(base_value / table[i].multiplier);
6986  *unit = table[i].unit;
6987  break;
6988  }
6989  }
6990  }
6991 
6992  Assert(*unit != NULL);
6993 }
static const unit_conversion memory_unit_conversion_table[]
Definition: guc.c:920
static const unit_conversion time_unit_conversion_table[]
Definition: guc.c:957
#define GUC_UNIT_MEMORY
Definition: guc.h:226
char unit[MAX_UNIT_LEN+1]
Definition: guc.c:904

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

Referenced by _ShowOption().

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

7004 {
7005  const unit_conversion *table;
7006  int i;
7007 
7008  *unit = NULL;
7009 
7010  if (base_unit & GUC_UNIT_MEMORY)
7012  else
7014 
7015  for (i = 0; *table[i].unit; i++)
7016  {
7017  if (base_unit == table[i].base_unit)
7018  {
7019  /*
7020  * Accept the first conversion that divides the value evenly; or
7021  * if there is none, use the smallest (last) target unit.
7022  *
7023  * What we actually care about here is whether snprintf with "%g"
7024  * will print the value as an integer, so the obvious test of
7025  * "*value == rint(*value)" is too strict; roundoff error might
7026  * make us choose an unreasonably small unit. As a compromise,
7027  * accept a divisor that is within 1e-8 of producing an integer.
7028  */
7029  *value = base_value / table[i].multiplier;
7030  *unit = table[i].unit;
7031  if (*value > 0 &&
7032  fabs((rint(*value) / *value) - 1.0) <= 1e-8)
7033  break;
7034  }
7035  }
7036 
7037  Assert(*unit != NULL);
7038 }
e
Definition: preproc-init.c:82
double multiplier
Definition: guc.c:907

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

Referenced by _ShowOption().

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

6904 {
6905  char unitstr[MAX_UNIT_LEN + 1];
6906  int unitlen;
6907  const unit_conversion *table;
6908  int i;
6909 
6910  /* extract unit string to compare to table entries */
6911  unitlen = 0;
6912  while (*unit != '\0' && !isspace((unsigned char) *unit) &&
6913  unitlen < MAX_UNIT_LEN)
6914  unitstr[unitlen++] = *(unit++);
6915  unitstr[unitlen] = '\0';
6916  /* allow whitespace after unit */
6917  while (isspace((unsigned char) *unit))
6918  unit++;
6919  if (*unit != '\0')
6920  return false; /* unit too long, or garbage after it */
6921 
6922  /* now search the appropriate table */
6923  if (base_unit & GUC_UNIT_MEMORY)
6925  else
6927 
6928  for (i = 0; *table[i].unit; i++)
6929  {
6930  if (base_unit == table[i].base_unit &&
6931  strcmp(unitstr, table[i].unit) == 0)
6932  {
6933  double cvalue = value * table[i].multiplier;
6934 
6935  /*
6936  * If the user gave a fractional value such as "30.1GB", round it
6937  * off to the nearest multiple of the next smaller unit, if there
6938  * is one.
6939  */
6940  if (*table[i + 1].unit &&
6941  base_unit == table[i + 1].base_unit)
6942  cvalue = rint(cvalue / table[i + 1].multiplier) *
6943  table[i + 1].multiplier;
6944 
6945  *base_value = cvalue;
6946  return true;
6947  }
6948  }
6949  return false;
6950 }
#define MAX_UNIT_LEN
Definition: guc.c:900

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

Referenced by parse_int(), and parse_real().

◆ define_custom_variable()

static void define_custom_variable ( struct config_generic variable)
static

Definition at line 9294 of file guc.c.

9295 {
9296  const char *name = variable->name;
9297  const char **nameAddr = &name;
9298  struct config_string *pHolder;
9299  struct config_generic **res;
9300 
9301  /*
9302  * See if there's a placeholder by the same name.
9303  */
9304  res = (struct config_generic **) bsearch((void *) &nameAddr,
9305  (void *) guc_variables,
9307  sizeof(struct config_generic *),
9308  guc_var_compare);
9309  if (res == NULL)
9310  {
9311  /*
9312  * No placeholder to replace, so we can just add it ... but first,
9313  * make sure it's initialized to its default value.
9314  */
9317  return;
9318  }
9319 
9320  /*
9321  * This better be a placeholder
9322  */
9323  if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
9324  ereport(ERROR,
9325  (errcode(ERRCODE_INTERNAL_ERROR),
9326  errmsg("attempt to redefine parameter \"%s\"", name)));
9327 
9328  Assert((*res)->vartype == PGC_STRING);
9329  pHolder = (struct config_string *) (*res);
9330 
9331  /*
9332  * First, set the variable to its default value. We must do this even
9333  * though we intend to immediately apply a new value, since it's possible
9334  * that the new value is invalid.
9335  */
9337 
9338  /*
9339  * Replace the placeholder. We aren't changing the name, so no re-sorting
9340  * is necessary
9341  */
9342  *res = variable;
9343 
9344  /*
9345  * Assign the string value(s) stored in the placeholder to the real
9346  * variable. Essentially, we need to duplicate all the active and stacked
9347  * values, but with appropriate validation and datatype adjustment.
9348  *
9349  * If an assignment fails, we report a WARNING and keep going. We don't
9350  * want to throw ERROR for bad values, because it'd bollix the add-on
9351  * module that's presumably halfway through getting loaded. In such cases
9352  * the default or previous state will become active instead.
9353  */
9354 
9355  /* First, apply the reset value if any */
9356  if (pHolder->reset_val)
9357  (void) set_config_option(name, pHolder->reset_val,
9358  pHolder->gen.reset_scontext,
9359  pHolder->gen.reset_source,
9360  GUC_ACTION_SET, true, WARNING, false);
9361  /* That should not have resulted in stacking anything */
9362  Assert(variable->stack == NULL);
9363 
9364  /* Now, apply current and stacked values, in the order they were stacked */
9365  reapply_stacked_values(variable, pHolder, pHolder->gen.stack,
9366  *(pHolder->variable),
9367  pHolder->gen.scontext, pHolder->gen.source);
9368 
9369  /* Also copy over any saved source-location information */
9370  if (pHolder->gen.sourcefile)
9372  pHolder->gen.sourceline);
9373 
9374  /*
9375  * Free up as much as we conveniently can of the placeholder structure.
9376  * (This neglects any stack items, so it's possible for some memory to be
9377  * leaked. Since this can only happen once per session per variable, it
9378  * doesn't seem worth spending much code on.)
9379  */
9380  set_string_field(pHolder, pHolder->variable, NULL);
9381  set_string_field(pHolder, &pHolder->reset_val, NULL);
9382 
9383  free(pHolder);
9384 }
static void static void set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
Definition: guc.c:8340
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:5975
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:9394
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:7562
@ GUC_ACTION_SET
Definition: guc.h:198
char * sourcefile
Definition: guc_tables.h:159
GucContext reset_scontext
Definition: guc_tables.h:154
GucSource reset_source
Definition: guc_tables.h:152
char * reset_val
Definition: guc_tables.h:232
char * name
Definition: type.h:172

References add_guc_variable(), Assert(), ereport, errcode(), errmsg(), ERROR, free, config_string::gen, GUC_ACTION_SET, GUC_CUSTOM_PLACEHOLDER, guc_var_compare(), guc_variables, InitializeOneGUCOption(), name, variable::name, num_guc_variables, PGC_STRING, reapply_stacked_values(), res, 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().

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

9488 {
9489  struct config_bool *var;
9490 
9491  var = (struct config_bool *)
9492  init_custom_variable(name, short_desc, long_desc, context, flags,
9493  PGC_BOOL, sizeof(struct config_bool));
9494  var->variable = valueAddr;
9495  var->boot_val = bootValue;
9496  var->reset_val = bootValue;
9497  var->check_hook = check_hook;
9498  var->assign_hook = assign_hook;
9499  var->show_hook = show_hook;
9500  define_custom_variable(&var->gen);
9501 }
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:9234
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:9294
bool reset_val
Definition: guc_tables.h:186
bool boot_val
Definition: guc_tables.h:181

References config_bool::assign_hook, config_bool::boot_val, config_bool::check_hook, define_custom_variable(), config_bool::gen, init_custom_variable(), name, PGC_BOOL, config_bool::reset_val, config_bool::show_hook, and config_bool::variable.

Referenced by _PG_init().

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

9600 {
9601  struct config_enum *var;
9602 
9603  var = (struct config_enum *)
9604  init_custom_variable(name, short_desc, long_desc, context, flags,
9605  PGC_ENUM, sizeof(struct config_enum));
9606  var->variable = valueAddr;
9607  var->boot_val = bootValue;
9608  var->reset_val = bootValue;
9609  var->options = options;
9610  var->check_hook = check_hook;
9611  var->assign_hook = assign_hook;
9612  var->show_hook = show_hook;
9613  define_custom_variable(&var->gen);
9614 }
static char ** options

References config_enum::assign_hook, config_enum::boot_val, config_enum::check_hook, define_custom_variable(), config_enum::gen, init_custom_variable(), name, options, config_enum::options, PGC_ENUM, config_enum::reset_val, config_enum::show_hook, and config_enum::variable.

Referenced by _PG_init().

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

9516 {
9517  struct config_int *var;
9518 
9519  var = (struct config_int *)
9520  init_custom_variable(name, short_desc, long_desc, context, flags,
9521  PGC_INT, sizeof(struct config_int));
9522  var->variable = valueAddr;
9523  var->boot_val = bootValue;
9524  var->reset_val = bootValue;
9525  var->min = minValue;
9526  var->max = maxValue;
9527  var->check_hook = check_hook;
9528  var->assign_hook = assign_hook;
9529  var->show_hook = show_hook;
9530  define_custom_variable(&var->gen);
9531 }
int reset_val
Definition: guc_tables.h:202
int boot_val
Definition: guc_tables.h:195

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, name, PGC_INT, config_int::reset_val, config_int::show_hook, and config_int::variable.

Referenced by _PG_init().

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

9546 {
9547  struct config_real *var;
9548 
9549  var = (struct config_real *)
9550  init_custom_variable(name, short_desc, long_desc, context, flags,
9551  PGC_REAL, sizeof(struct config_real));
9552  var->variable = valueAddr;
9553  var->boot_val = bootValue;
9554  var->reset_val = bootValue;
9555  var->min = minValue;
9556  var->max = maxValue;
9557  var->check_hook = check_hook;
9558  var->assign_hook = assign_hook;
9559  var->show_hook = show_hook;
9560  define_custom_variable(&var->gen);
9561 }
double boot_val
Definition: guc_tables.h:211
double reset_val
Definition: guc_tables.h:218
double min
Definition: guc_tables.h:212
double max
Definition: guc_tables.h:213

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, name, PGC_REAL, config_real::reset_val, config_real::show_hook, and config_real::variable.

Referenced by _PG_init().

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

9574 {
9575  struct config_string *var;
9576 
9577  var = (struct config_string *)
9578  init_custom_variable(name, short_desc, long_desc, context, flags,
9579  PGC_STRING, sizeof(struct config_string));
9580  var->variable = valueAddr;
9581  var->boot_val = bootValue;
9582  var->check_hook = check_hook;
9583  var->assign_hook = assign_hook;
9584  var->show_hook = show_hook;
9585  define_custom_variable(&var->gen);
9586 }
const char * boot_val
Definition: guc_tables.h:227

References config_string::assign_hook, config_string::boot_val, config_string::check_hook, define_custom_variable(), config_string::gen, init_custom_variable(), name, PGC_STRING, config_string::show_hook, and config_string::variable.

Referenced by _PG_init().

◆ discard_stack_value()

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

Definition at line 5377 of file guc.c.

5378 {
5379  switch (gconf->vartype)
5380  {
5381  case PGC_BOOL:
5382  case PGC_INT:
5383  case PGC_REAL:
5384  case PGC_ENUM:
5385  /* no need to do anything */
5386  break;
5387  case PGC_STRING:
5388  set_string_field((struct config_string *) gconf,
5389  &(val->val.stringval),
5390  NULL);
5391  break;
5392  }
5393  set_extra_field(gconf, &(val->extra), NULL);
5394 }

References PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_STRING, set_extra_field(), set_string_field(), val, and config_generic::vartype.

Referenced by AtEOXact_GUC(), and push_old_value().

◆ do_serialize()

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

Definition at line 10966 of file guc.c.

10967 {
10968  va_list vargs;
10969  int n;
10970 
10971  if (*maxbytes <= 0)
10972  elog(ERROR, "not enough space to serialize GUC state");
10973 
10974  va_start(vargs, fmt);
10975  n = vsnprintf(*destptr, *maxbytes, fmt, vargs);
10976  va_end(vargs);
10977 
10978  if (n < 0)
10979  {
10980  /* Shouldn't happen. Better show errno description. */
10981  elog(ERROR, "vsnprintf failed: %m with format string \"%s\"", fmt);
10982  }
10983  if (n >= *maxbytes)
10984  {
10985  /* This shouldn't happen either, really. */
10986  elog(ERROR, "not enough space to serialize GUC state");
10987  }
10988 
10989  /* Shift the destptr ahead of the null terminator */
10990  *destptr += n + 1;
10991  *maxbytes -= n + 1;
10992 }
va_end(args)
static void const char * fmt
va_start(args, fmt)
#define vsnprintf
Definition: port.h:224

References elog(), ERROR, fmt, va_end(), va_start(), and vsnprintf.

Referenced by serialize_variable().

◆ do_serialize_binary()

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

Definition at line 10996 of file guc.c.

10997 {
10998  if (valsize > *maxbytes)
10999  elog(ERROR, "not enough space to serialize GUC state");
11000 
11001  memcpy(*destptr, val, valsize);
11002  *destptr += valsize;
11003  *maxbytes -= valsize;
11004 }

References elog(), ERROR, and val.

Referenced by serialize_variable().

◆ estimate_variable_size()

static Size estimate_variable_size ( struct config_generic gconf)
static

Definition at line 10844 of file guc.c.

10845 {
10846  Size size;
10847  Size valsize = 0;
10848 
10849  /* Skippable GUCs consume zero space. */
10850  if (can_skip_gucvar(gconf))
10851  return 0;
10852 
10853  /* Name, plus trailing zero byte. */
10854  size = strlen(gconf->name) + 1;
10855 
10856  /* Get the maximum display length of the GUC value. */
10857  switch (gconf->vartype)
10858  {
10859  case PGC_BOOL:
10860  {
10861  valsize = 5; /* max(strlen('true'), strlen('false')) */
10862  }
10863  break;
10864 
10865  case PGC_INT:
10866  {
10867  struct config_int *conf = (struct config_int *) gconf;
10868 
10869  /*
10870  * Instead of getting the exact display length, use max
10871  * length. Also reduce the max length for typical ranges of
10872  * small values. Maximum value is 2147483647, i.e. 10 chars.
10873  * Include one byte for sign.
10874  */
10875  if (Abs(*conf->variable) < 1000)
10876  valsize = 3 + 1;
10877  else
10878  valsize = 10 + 1;
10879  }
10880  break;
10881 
10882  case PGC_REAL:
10883  {
10884  /*
10885  * We are going to print it with %e with REALTYPE_PRECISION
10886  * fractional digits. Account for sign, leading digit,
10887  * decimal point, and exponent with up to 3 digits. E.g.
10888  * -3.99329042340000021e+110
10889  */
10890  valsize = 1 + 1 + 1 + REALTYPE_PRECISION + 5;
10891  }
10892  break;
10893 
10894  case PGC_STRING:
10895  {
10896  struct config_string *conf = (struct config_string *) gconf;
10897 
10898  /*
10899  * If the value is NULL, we transmit it as an empty string.
10900  * Although this is not physically the same value, GUC
10901  * generally treats a NULL the same as empty string.
10902  */
10903  if (*conf->variable)
10904  valsize = strlen(*conf->variable);
10905  else
10906  valsize = 0;
10907  }
10908  break;
10909 
10910  case PGC_ENUM:
10911  {
10912  struct config_enum *conf = (struct config_enum *) gconf;
10913 
10914  valsize = strlen(config_enum_lookup_by_value(conf, *conf->variable));
10915  }
10916  break;
10917  }
10918 
10919  /* Allow space for terminating zero-byte for value */
10920  size = add_size(size, valsize + 1);
10921 
10922  if (gconf->sourcefile)
10923  size = add_size(size, strlen(gconf->sourcefile));
10924 
10925  /* Allow space for terminating zero-byte for sourcefile */
10926  size = add_size(size, 1);
10927 
10928  /* Include line whenever file is nonempty. */
10929  if (gconf->sourcefile && gconf->sourcefile[0])
10930  size = add_size(size, sizeof(gconf->sourceline));
10931 
10932  size = add_size(size, sizeof(gconf->source));
10933  size = add_size(size, sizeof(gconf->scontext));
10934 
10935  return size;
10936 }
#define Abs(x)
Definition: c.h:1003
size_t Size
Definition: c.h:551
static bool can_skip_gucvar(struct config_generic *gconf)
Definition: guc.c:10804
#define REALTYPE_PRECISION
Definition: guc.c:135
Size add_size(Size s1, Size s2)
Definition: shmem.c:502

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

◆ EstimateGUCStateSpace()

Size EstimateGUCStateSpace ( void  )

Definition at line 10943 of file guc.c.

10944 {
10945  Size size;
10946  int i;
10947 
10948  /* Add space reqd for saving the data size of the guc state */
10949  size = sizeof(Size);
10950 
10951  /* Add up the space needed for each GUC variable */
10952  for (i = 0; i < num_guc_variables; i++)
10953  size = add_size(size,
10955 
10956  return size;
10957 }
static Size estimate_variable_size(struct config_generic *gconf)
Definition: guc.c:10844

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

Referenced by InitializeParallelDSM().

◆ ExecSetVariableStmt()

void ExecSetVariableStmt ( VariableSetStmt stmt,
bool  isTopLevel 
)

Definition at line 9019 of file guc.c.

9020 {
9022 
9023  /*
9024  * Workers synchronize these parameters at the start of the parallel
9025  * operation; then, we block SET during the operation.
9026  */
9027  if (IsInParallelMode())
9028  ereport(ERROR,
9029  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
9030  errmsg("cannot set parameters during a parallel operation")));
9031 
9032  switch (stmt->kind)
9033  {
9034  case VAR_SET_VALUE:
9035  case VAR_SET_CURRENT:
9036  if (stmt->is_local)
9037  WarnNoTransactionBlock(isTopLevel, "SET LOCAL");
9038  (void) set_config_option(stmt->name,
9039  ExtractSetVariableArgs(stmt),
9041  PGC_S_SESSION,
9042  action, true, 0, false);
9043  break;
9044  case VAR_SET_MULTI:
9045 
9046  /*
9047  * Special-case SQL syntaxes. The TRANSACTION and SESSION
9048  * CHARACTERISTICS cases effectively set more than one variable
9049  * per statement. TRANSACTION SNAPSHOT only takes one argument,
9050  * but we put it here anyway since it's a special case and not
9051  * related to any GUC variable.
9052  */
9053  if (strcmp(stmt->name, "TRANSACTION") == 0)
9054  {
9055  ListCell *head;
9056 
9057  WarnNoTransactionBlock(isTopLevel, "SET TRANSACTION");
9058 
9059  foreach(head, stmt->args)
9060  {
9061  DefElem *item = (DefElem *) lfirst(head);
9062 
9063  if (strcmp(item->defname, "transaction_isolation") == 0)
9064  SetPGVariable("transaction_isolation",
9065  list_make1(item->arg), stmt->is_local);
9066  else if (strcmp(item->defname, "transaction_read_only") == 0)
9067  SetPGVariable("transaction_read_only",
9068  list_make1(item->arg), stmt->is_local);
9069  else if (strcmp(item->defname, "transaction_deferrable") == 0)
9070  SetPGVariable("transaction_deferrable",
9071  list_make1(item->arg), stmt->is_local);
9072  else
9073  elog(ERROR, "unexpected SET TRANSACTION element: %s",
9074  item->defname);
9075  }
9076  }
9077  else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
9078  {
9079  ListCell *head;
9080 
9081  foreach(head, stmt->args)
9082  {
9083  DefElem *item = (DefElem *) lfirst(head);
9084 
9085  if (strcmp(item->defname, "transaction_isolation") == 0)
9086  SetPGVariable("default_transaction_isolation",
9087  list_make1(item->arg), stmt->is_local);
9088  else if (strcmp(item->defname, "transaction_read_only") == 0)
9089  SetPGVariable("default_transaction_read_only",
9090  list_make1(item->arg), stmt->is_local);
9091  else if (strcmp(item->defname, "transaction_deferrable") == 0)
9092  SetPGVariable("default_transaction_deferrable",
9093  list_make1(item->arg), stmt->is_local);
9094  else
9095  elog(ERROR, "unexpected SET SESSION element: %s",
9096  item->defname);
9097  }
9098  }
9099  else if (strcmp(stmt->name, "TRANSACTION SNAPSHOT") == 0)
9100  {
9101  A_Const *con = linitial_node(A_Const, stmt->args);
9102 
9103  if (stmt->is_local)
9104  ereport(ERROR,
9105  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9106  errmsg("SET LOCAL TRANSACTION SNAPSHOT is not implemented")));
9107 
9108  WarnNoTransactionBlock(isTopLevel, "SET TRANSACTION");
9109  ImportSnapshot(strVal(&con->val));
9110  }
9111  else
9112  elog(ERROR, "unexpected SET MULTI element: %s",
9113  stmt->name);
9114  break;
9115  case VAR_SET_DEFAULT:
9116  if (stmt->is_local)
9117  WarnNoTransactionBlock(isTopLevel, "SET LOCAL");
9118  /* fall through */
9119  case VAR_RESET:
9120  if (strcmp(stmt->name, "transaction_isolation") == 0)
9121  WarnNoTransactionBlock(isTopLevel, "RESET TRANSACTION");
9122 
9123  (void) set_config_option(stmt->name,
9124  NULL,
9126  PGC_S_SESSION,
9127  action, true, 0, false);
9128  break;
9129  case VAR_RESET_ALL:
9130  ResetAllOptions();
9131  break;
9132  }
9133 
9134  /* Invoke the post-alter hook for setting this GUC variable, by name. */
9135  InvokeObjectPostAlterHookArgStr(ParameterAclRelationId, stmt->name,
9136  ACL_SET, stmt->kind, false);
9137 }
void ResetAllOptions(void)
Definition: guc.c:6271
void SetPGVariable(const char *name, List *args, bool is_local)
Definition: guc.c:9166
GucAction
Definition: guc.h:196
@ GUC_ACTION_LOCAL
Definition: guc.h:199
@ PGC_SUSET
Definition: guc.h:75
#define ACL_SET
Definition: parsenodes.h:94
@ VAR_SET_MULTI
Definition: parsenodes.h:2493
@ VAR_SET_CURRENT
Definition: parsenodes.h:2492
#define linitial_node(type, l)
Definition: pg_list.h:179
#define list_make1(x1)
Definition: pg_list.h:210
void ImportSnapshot(const char *idstr)
Definition: snapmgr.c:1394
union A_Const::ValUnion val
char * defname
Definition: parsenodes.h:766
Node * arg
Definition: parsenodes.h:767
#define strVal(v)
Definition: value.h:72
void WarnNoTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3522
bool IsInParallelMode(void)
Definition: xact.c:1065

References ACL_SET, generate_unaccent_rules::action, DefElem::arg, VariableSetStmt::args, DefElem::defname, elog(), ereport, errcode(), errmsg(), ERROR, ExtractSetVariableArgs(), GUC_ACTION_LOCAL, GUC_ACTION_SET, ImportSnapshot(), InvokeObjectPostAlterHookArgStr, VariableSetStmt::is_local, IsInParallelMode(), VariableSetStmt::kind, lfirst, linitial_node, list_make1, VariableSetStmt::name, PGC_S_SESSION, PGC_SUSET, PGC_USERSET, ResetAllOptions(), set_config_option(), SetPGVariable(), strVal, superuser(), 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().

◆ extra_field_used()

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

Definition at line 5278 of file guc.c.

5279 {
5280  GucStack *stack;
5281 
5282  if (extra == gconf->extra)
5283  return true;
5284  switch (gconf->vartype)
5285  {
5286  case PGC_BOOL:
5287  if (extra == ((struct config_bool *) gconf)->reset_extra)
5288  return true;
5289  break;
5290  case PGC_INT:
5291  if (extra == ((struct config_int *) gconf)->reset_extra)
5292  return true;
5293  break;
5294  case PGC_REAL:
5295  if (extra == ((struct config_real *) gconf)->reset_extra)
5296  return true;
5297  break;
5298  case PGC_STRING:
5299  if (extra == ((struct config_string *) gconf)->reset_extra)
5300  return true;
5301  break;
5302  case PGC_ENUM:
5303  if (extra == ((struct config_enum *) gconf)->reset_extra)
5304  return true;
5305  break;
5306  }
5307  for (stack = gconf->stack; stack; stack = stack->prev)
5308  {
5309  if (extra == stack->prior.extra ||
5310  extra == stack->masked.extra)
5311  return true;
5312  }
5313 
5314  return false;
5315 }

References config_var_value::extra, config_generic::extra, guc_stack::masked, PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_STRING, guc_stack::prev, guc_stack::prior, config_generic::stack, and config_generic::vartype.

Referenced by set_config_option(), and set_extra_field().

◆ ExtractSetVariableArgs()

char* ExtractSetVariableArgs ( VariableSetStmt stmt)

Definition at line 9146 of file guc.c.

9147 {
9148  switch (stmt->kind)
9149  {
9150  case VAR_SET_VALUE:
9151  return flatten_set_variable_args(stmt->name, stmt->args);
9152  case VAR_SET_CURRENT:
9153  return GetConfigOptionByName(stmt->name, NULL, false);
9154  default:
9155  return NULL;
9156  }
9157 }
static char * flatten_set_variable_args(const char *name, List *args)
Definition: guc.c:8515
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:9913

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

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

◆ find_option()

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

Definition at line 5635 of file guc.c.

5637 {
5638  const char **key = &name;
5639  struct config_generic **res;
5640  int i;
5641 
5642  Assert(name);
5643 
5644  /*
5645  * By equating const char ** with struct config_generic *, we are assuming
5646  * the name field is first in config_generic.
5647  */
5648  res = (struct config_generic **) bsearch((void *) &key,
5649  (void *) guc_variables,
5651  sizeof(struct config_generic *),
5652  guc_var_compare);
5653  if (res)
5654  return *res;
5655 
5656  /*
5657  * See if the name is an obsolete name for a variable. We assume that the
5658  * set of supported old names is short enough that a brute-force search is
5659  * the best way.
5660  */
5661  for (i = 0; map_old_guc_names[i] != NULL; i += 2)
5662  {
5664  return find_option(map_old_guc_names[i + 1], false,
5665  skip_errors, elevel);
5666  }
5667 
5668  if (create_placeholders)
5669  {
5670  /*
5671  * Check if the name is valid, and if so, add a placeholder. If it
5672  * doesn't contain a separator, don't assume that it was meant to be a
5673  * placeholder.
5674  */
5675  const char *sep = strchr(name, GUC_QUALIFIER_SEPARATOR);
5676 
5677  if (sep != NULL)
5678  {
5679  size_t classLen = sep - name;
5680  ListCell *lc;
5681 
5682  /* The name must be syntactically acceptable ... */
5684  {
5685  if (!skip_errors)
5686  ereport(elevel,
5687  (errcode(ERRCODE_INVALID_NAME),
5688  errmsg("invalid configuration parameter name \"%s\"",
5689  name),
5690  errdetail("Custom parameter names must be two or more simple identifiers separated by dots.")));
5691  return NULL;
5692  }
5693  /* ... and it must not match any previously-reserved prefix */
5694  foreach(lc, reserved_class_prefix)
5695  {
5696  const char *rcprefix = lfirst(lc);
5697 
5698  if (strlen(rcprefix) == classLen &&
5699  strncmp(name, rcprefix, classLen) == 0)
5700  {
5701  if (!skip_errors)
5702  ereport(elevel,
5703  (errcode(ERRCODE_INVALID_NAME),
5704  errmsg("invalid configuration parameter name \"%s\"",
5705  name),
5706  errdetail("\"%s\" is a reserved prefix.",
5707  rcprefix)));
5708  return NULL;
5709  }
5710  }
5711  /* OK, create it */
5712  return add_placeholder_variable(name, elevel);
5713  }
5714  }
5715 
5716  /* Unknown name */
5717  if (!skip_errors)
5718  ereport(elevel,
5719  (errcode(ERRCODE_UNDEFINED_OBJECT),
5720  errmsg("unrecognized configuration parameter \"%s\"",
5721  name)));
5722  return NULL;
5723 }
int errdetail(const char *fmt,...)
Definition: elog.c:1037
static List * reserved_class_prefix
Definition: guc.c:156
static struct config_generic * add_placeholder_variable(const char *name, int elevel)
Definition: guc.c:5577
#define GUC_QUALIFIER_SEPARATOR
Definition: guc.h:203

References add_placeholder_variable(), Assert(), ereport, errcode(), errdetail(), errmsg(), guc_name_compare(), GUC_QUALIFIER_SEPARATOR, guc_var_compare(), guc_variables, i, sort-test::key, lfirst, map_old_guc_names, name, num_guc_variables, res, reserved_class_prefix, and valid_custom_variable_name().

Referenced by AlterSystemSetConfigFile(), check_GUC_name_for_parameter_acl(), flatten_set_variable_args(), GetConfigOption(), GetConfigOptionByName(), GetConfigOptionFlags(), GetConfigOptionResetString(), GUCArrayAdd(), GUCArrayDelete(), InitializeWalConsistencyChecking(), pg_settings_get_flags(), set_config_option(), set_config_sourcefile(), and validate_option_array_item().

◆ flatten_set_variable_args()

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

Definition at line 8515 of file guc.c.

8516 {
8517  struct config_generic *record;
8518  int flags;
8520  ListCell *l;
8521 
8522  /* Fast path if just DEFAULT */
8523  if (args == NIL)
8524  return NULL;
8525 
8526  /*
8527  * Get flags for the variable; if it's not known, use default flags.
8528  * (Caller might throw error later, but not our business to do so here.)
8529  */
8530  record = find_option(name, false, true, WARNING);
8531  if (record)
8532  flags = record->flags;
8533  else
8534  flags = 0;
8535 
8536  /* Complain if list input and non-list variable */
8537  if ((flags & GUC_LIST_INPUT) == 0 &&
8538  list_length(args) != 1)
8539  ereport(ERROR,
8540  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8541  errmsg("SET %s takes only one argument", name)));
8542 
8543  initStringInfo(&buf);
8544 
8545  /*
8546  * Each list member may be a plain A_Const node, or an A_Const within a
8547  * TypeCast; the latter case is supported only for ConstInterval arguments
8548  * (for SET TIME ZONE).
8549  */
8550  foreach(l, args)
8551  {
8552  Node *arg = (Node *) lfirst(l);
8553  char *val;
8554  TypeName *typeName = NULL;
8555  A_Const *con;
8556 
8557  if (l != list_head(args))
8558  appendStringInfoString(&buf, ", ");
8559 
8560  if (IsA(arg, TypeCast))
8561  {
8562  TypeCast *tc = (TypeCast *) arg;
8563 
8564  arg = tc->arg;
8565  typeName = tc->typeName;
8566  }
8567 
8568  if (!IsA(arg, A_Const))
8569  elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
8570  con = (A_Const *) arg;
8571 
8572  switch (nodeTag(&con->val))
8573  {
8574  case T_Integer:
8575  appendStringInfo(&buf, "%d", intVal(&con->val));
8576  break;
8577  case T_Float:
8578  /* represented as a string, so just copy it */
8579  appendStringInfoString(&buf, castNode(Float, &con->val)->fval);
8580  break;
8581  case T_String:
8582  val = strVal(&con->val);
8583  if (typeName != NULL)
8584  {
8585  /*
8586  * Must be a ConstInterval argument for TIME ZONE. Coerce
8587  * to interval and back to normalize the value and account
8588  * for any typmod.
8589  */
8590  Oid typoid;
8591  int32 typmod;
8592  Datum interval;
8593  char *intervalout;
8594 
8595  typenameTypeIdAndMod(NULL, typeName, &typoid, &typmod);
8596  Assert(typoid == INTERVALOID);
8597 
8598  interval =
8602  Int32GetDatum(typmod));
8603 
8604  intervalout =
8606  interval));
8607  appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
8608  }
8609  else
8610  {
8611  /*
8612  * Plain string literal or identifier. For quote mode,
8613  * quote it if it's not a vanilla identifier.
8614  */
8615  if (flags & GUC_LIST_QUOTE)
8617  else
8619  }
8620  break;
8621  default:
8622  elog(ERROR, "unrecognized node type: %d",
8623  (int) nodeTag(&con->val));
8624  break;
8625  }
8626  }
8627 
8628  return buf.data;
8629 }
Datum interval_out(PG_FUNCTION_ARGS)
Definition: timestamp.c:955
Datum interval_in(PG_FUNCTION_ARGS)
Definition: timestamp.c:883
signed int int32
Definition: c.h:440
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:631
#define DirectFunctionCall3(func, arg1, arg2, arg3)
Definition: fmgr.h:635
#define GUC_LIST_QUOTE
Definition: guc.h:209
#define GUC_LIST_INPUT
Definition: guc.h:208
#define IsA(nodeptr, _type_)
Definition: nodes.h:625
#define nodeTag(nodeptr)
Definition: nodes.h:579
@ T_Float
Definition: nodes.h:309
@ T_String
Definition: nodes.h:311
@ T_Integer
Definition: nodes.h:308
#define castNode(_type_, nodeptr)
Definition: nodes.h:643
void typenameTypeIdAndMod(ParseState *pstate, const TypeName *typeName, Oid *typeid_p, int32 *typmod_p)
Definition: parse_type.c:310
void * arg
static int list_length(const List *l)
Definition: pg_list.h:150
#define NIL
Definition: pg_list.h:66
static ListCell * list_head(const List *l)
Definition: pg_list.h:126
static char * buf
Definition: pg_test_fsync.c:67
#define CStringGetDatum(X)
Definition: postgres.h:622
uintptr_t Datum
Definition: postgres.h:411
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define Int32GetDatum(X)
Definition: postgres.h:523
#define DatumGetCString(X)
Definition: postgres.h:610
#define InvalidOid
Definition: postgres_ext.h:36
unsigned int Oid
Definition: postgres_ext.h:31
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:12189
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
Definition: value.h:46
Definition: nodes.h:575
TypeName * typeName
Definition: parsenodes.h:329
Node * arg
Definition: parsenodes.h:328
#define intVal(v)
Definition: value.h:69

References appendStringInfo(), appendStringInfoString(), arg, TypeCast::arg, generate_unaccent_rules::args, Assert(), buf, castNode, CStringGetDatum, DatumGetCString, DirectFunctionCall1, DirectFunctionCall3, elog(), ereport, errcode(), errmsg(), ERROR, find_option(), config_generic::flags, GUC_LIST_INPUT, GUC_LIST_QUOTE, initStringInfo(), Int32GetDatum, interval_in(), interval_out(), intVal, InvalidOid, IsA, lfirst, list_head(), list_length(), name, NIL, nodeTag, ObjectIdGetDatum, quote_identifier(), strVal, T_Float, T_Integer, T_String, TypeCast::typeName, typenameTypeIdAndMod(), A_Const::val, val, and WARNING.

Referenced by ExtractSetVariableArgs(), and SetPGVariable().

◆ get_config_unit_name()

static const char* get_config_unit_name ( int  flags)
static

Definition at line 7045 of file guc.c.

7046 {
7047  switch (flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
7048  {
7049  case 0:
7050  return NULL; /* GUC has no units */
7051  case GUC_UNIT_BYTE:
7052  return "B";
7053  case GUC_UNIT_KB:
7054  return "kB";
7055  case GUC_UNIT_MB:
7056  return "MB";
7057  case GUC_UNIT_BLOCKS:
7058  {
7059  static char bbuf[8];
7060 
7061  /* initialize if first time through */
7062  if (bbuf[0] == '\0&#