PostgreSQL Source Code  git master
guc.c File Reference
#include "postgres.h"
#include <ctype.h>
#include <float.h>
#include <math.h>
#include <limits.h>
#include <unistd.h>
#include <sys/stat.h>
#include "access/commit_ts.h"
#include "access/gin.h"
#include "access/rmgr.h"
#include "access/tableam.h"
#include "access/transam.h"
#include "access/twophase.h"
#include "access/xact.h"
#include "access/xlog_internal.h"
#include "catalog/namespace.h"
#include "catalog/pg_authid.h"
#include "commands/async.h"
#include "commands/prepare.h"
#include "commands/user.h"
#include "commands/vacuum.h"
#include "commands/variable.h"
#include "commands/trigger.h"
#include "common/string.h"
#include "funcapi.h"
#include "jit/jit.h"
#include "libpq/auth.h"
#include "libpq/libpq.h"
#include "libpq/pqformat.h"
#include "miscadmin.h"
#include "optimizer/cost.h"
#include "optimizer/geqo.h"
#include "optimizer/optimizer.h"
#include "optimizer/paths.h"
#include "optimizer/planmain.h"
#include "parser/parse_expr.h"
#include "parser/parse_type.h"
#include "parser/parser.h"
#include "parser/scansup.h"
#include "pgstat.h"
#include "postmaster/autovacuum.h"
#include "postmaster/bgworker_internals.h"
#include "postmaster/bgwriter.h"
#include "postmaster/postmaster.h"
#include "postmaster/syslogger.h"
#include "postmaster/walwriter.h"
#include "replication/logicallauncher.h"
#include "replication/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/standby.h"
#include "storage/fd.h"
#include "storage/large_object.h"
#include "storage/pg_shmem.h"
#include "storage/proc.h"
#include "storage/predicate.h"
#include "tcop/tcopprot.h"
#include "tsearch/ts_cache.h"
#include "utils/builtins.h"
#include "utils/bytea.h"
#include "utils/guc_tables.h"
#include "utils/memutils.h"
#include "utils/pg_locale.h"
#include "utils/pg_lsn.h"
#include "utils/plancache.h"
#include "utils/portal.h"
#include "utils/ps_status.h"
#include "utils/rls.h"
#include "utils/snapmgr.h"
#include "utils/tzparser.h"
#include "utils/varlena.h"
#include "utils/xml.h"
#include "guc-file.c"
Include dependency graph for guc.c:

Go to the source code of this file.

Data Structures

struct  unit_conversion
 

Macros

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

Functions

static void do_serialize (char **destptr, Size *maxbytes, const char *fmt,...) pg_attribute_printf(3
 
static void static void set_config_sourcefile (const char *name, char *sourcefile, int sourceline)
 
static bool call_bool_check_hook (struct config_bool *conf, bool *newval, void **extra, GucSource source, int elevel)
 
static bool call_int_check_hook (struct config_int *conf, int *newval, void **extra, GucSource source, int elevel)
 
static bool call_real_check_hook (struct config_real *conf, double *newval, void **extra, GucSource source, int elevel)
 
static bool call_string_check_hook (struct config_string *conf, char **newval, void **extra, GucSource source, int elevel)
 
static bool call_enum_check_hook (struct config_enum *conf, int *newval, void **extra, GucSource source, int elevel)
 
static bool check_log_destination (char **newval, void **extra, GucSource source)
 
static void assign_log_destination (const char *newval, void *extra)
 
static bool check_wal_consistency_checking (char **newval, void **extra, GucSource source)
 
static void assign_wal_consistency_checking (const char *newval, void *extra)
 
static void assign_syslog_facility (int newval, void *extra)
 
static void assign_syslog_ident (const char *newval, void *extra)
 
static void assign_session_replication_role (int newval, void *extra)
 
static bool check_temp_buffers (int *newval, void **extra, GucSource source)
 
static bool check_bonjour (bool *newval, void **extra, GucSource source)
 
static bool check_ssl (bool *newval, void **extra, GucSource source)
 
static bool check_stage_log_stats (bool *newval, void **extra, GucSource source)
 
static bool check_log_stats (bool *newval, void **extra, GucSource source)
 
static bool check_canonical_path (char **newval, void **extra, GucSource source)
 
static bool check_timezone_abbreviations (char **newval, void **extra, GucSource source)
 
static void assign_timezone_abbreviations (const char *newval, void *extra)
 
static void pg_timezone_abbrev_initialize (void)
 
static const char * show_archive_command (void)
 
static void assign_tcp_keepalives_idle (int newval, void *extra)
 
static void assign_tcp_keepalives_interval (int newval, void *extra)
 
static void assign_tcp_keepalives_count (int newval, void *extra)
 
static void assign_tcp_user_timeout (int newval, void *extra)
 
static const char * show_tcp_keepalives_idle (void)
 
static const char * show_tcp_keepalives_interval (void)
 
static const char * show_tcp_keepalives_count (void)
 
static const char * show_tcp_user_timeout (void)
 
static bool check_maxconnections (int *newval, void **extra, GucSource source)
 
static bool check_max_worker_processes (int *newval, void **extra, GucSource source)
 
static bool check_autovacuum_max_workers (int *newval, void **extra, GucSource source)
 
static bool check_max_wal_senders (int *newval, void **extra, GucSource source)
 
static bool check_autovacuum_work_mem (int *newval, void **extra, GucSource source)
 
static bool check_effective_io_concurrency (int *newval, void **extra, GucSource source)
 
static void assign_effective_io_concurrency (int newval, void *extra)
 
static void assign_pgstat_temp_directory (const char *newval, void *extra)
 
static bool check_application_name (char **newval, void **extra, GucSource source)
 
static void assign_application_name (const char *newval, void *extra)
 
static bool check_cluster_name (char **newval, void **extra, GucSource source)
 
static const char * show_unix_socket_permissions (void)
 
static const char * show_log_file_mode (void)
 
static const char * show_data_directory_mode (void)
 
static bool check_recovery_target_timeline (char **newval, void **extra, GucSource source)
 
static void assign_recovery_target_timeline (const char *newval, void *extra)
 
static bool check_recovery_target (char **newval, void **extra, GucSource source)
 
static void assign_recovery_target (const char *newval, void *extra)
 
static bool check_recovery_target_xid (char **newval, void **extra, GucSource source)
 
static void assign_recovery_target_xid (const char *newval, void *extra)
 
static bool check_recovery_target_time (char **newval, void **extra, GucSource source)
 
static void assign_recovery_target_time (const char *newval, void *extra)
 
static bool check_recovery_target_name (char **newval, void **extra, GucSource source)
 
static void assign_recovery_target_name (const char *newval, void *extra)
 
static bool check_recovery_target_lsn (char **newval, void **extra, GucSource source)
 
static void assign_recovery_target_lsn (const char *newval, void *extra)
 
static bool check_primary_slot_name (char **newval, void **extra, GucSource source)
 
static bool check_default_with_oids (bool *newval, void **extra, GucSource source)
 
static ConfigVariableProcessConfigFileInternal (GucContext context, bool applySettings, int elevel)
 
static int guc_var_compare (const void *a, const void *b)
 
static int guc_name_compare (const char *namea, const char *nameb)
 
static void InitializeGUCOptionsFromEnvironment (void)
 
static void InitializeOneGUCOption (struct config_generic *gconf)
 
static void push_old_value (struct config_generic *gconf, GucAction action)
 
static void ReportGUCOption (struct config_generic *record)
 
static void reapply_stacked_values (struct config_generic *variable, struct config_string *pHolder, GucStack *stack, const char *curvalue, GucContext curscontext, GucSource cursource)
 
static void ShowGUCConfigOption (const char *name, DestReceiver *dest)
 
static void ShowAllGUCConfig (DestReceiver *dest)
 
static char * _ShowOption (struct config_generic *record, bool use_units)
 
static bool validate_option_array_item (const char *name, const char *value, bool skipIfNoPermissions)
 
static void write_auto_conf_file (int fd, const char *filename, ConfigVariable *head_p)
 
static void replace_auto_config_value (ConfigVariable **head_p, ConfigVariable **tail_p, const char *name, const char *value)
 
static void * guc_malloc (int elevel, size_t size)
 
static void * guc_realloc (int elevel, void *old, size_t size)
 
static char * guc_strdup (int elevel, const char *src)
 
static bool string_field_used (struct config_string *conf, char *strval)
 
static void set_string_field (struct config_string *conf, char **field, char *newval)
 
static bool extra_field_used (struct config_generic *gconf, void *extra)
 
static void set_extra_field (struct config_generic *gconf, void **field, void *newval)
 
static void set_stack_value (struct config_generic *gconf, config_var_value *val)
 
static void discard_stack_value (struct config_generic *gconf, config_var_value *val)
 
struct config_generic ** get_guc_variables (void)
 
void build_guc_variables (void)
 
static bool add_guc_variable (struct config_generic *var, int elevel)
 
static struct config_genericadd_placeholder_variable (const char *name, int elevel)
 
static struct config_genericfind_option (const char *name, bool create_placeholders, int elevel)
 
void InitializeGUCOptions (void)
 
bool SelectConfigFiles (const char *userDoption, const char *progname)
 
void ResetAllOptions (void)
 
void AtStart_GUC (void)
 
int NewGUCNestLevel (void)
 
void AtEOXact_GUC (bool isCommit, int nestLevel)
 
void BeginReportingGUCOptions (void)
 
static bool convert_to_base_unit (double value, const char *unit, int base_unit, double *base_value)
 
static void convert_int_from_base_unit (int64 base_value, int base_unit, int64 *value, const char **unit)
 
static void convert_real_from_base_unit (double base_value, int base_unit, double *value, const char **unit)
 
static const char * get_config_unit_name (int flags)
 
bool parse_int (const char *value, int *result, int flags, const char **hintmsg)
 
bool parse_real (const char *value, double *result, int flags, const char **hintmsg)
 
const char * config_enum_lookup_by_value (struct config_enum *record, int val)
 
bool config_enum_lookup_by_name (struct config_enum *record, const char *value, int *retval)
 
static char * config_enum_get_options (struct config_enum *record, const char *prefix, const char *suffix, const char *separator)
 
static bool parse_and_validate_value (struct config_generic *record, const char *name, const char *value, GucSource source, int elevel, union config_var_val *newval, void **newextra)
 
int set_config_option (const char *name, const char *value, GucContext context, GucSource source, GucAction action, bool changeVal, int elevel, bool is_reload)
 
void SetConfigOption (const char *name, const char *value, GucContext context, GucSource source)
 
const char * GetConfigOption (const char *name, bool missing_ok, bool restrict_privileged)
 
const char * GetConfigOptionResetString (const char *name)
 
int GetConfigOptionFlags (const char *name, bool missing_ok)
 
static char * flatten_set_variable_args (const char *name, List *args)
 
void AlterSystemSetConfigFile (AlterSystemStmt *altersysstmt)
 
void ExecSetVariableStmt (VariableSetStmt *stmt, bool isTopLevel)
 
char * ExtractSetVariableArgs (VariableSetStmt *stmt)
 
void SetPGVariable (const char *name, List *args, bool is_local)
 
Datum set_config_by_name (PG_FUNCTION_ARGS)
 
static struct config_genericinit_custom_variable (const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
 
static void define_custom_variable (struct config_generic *variable)
 
void DefineCustomBoolVariable (const char *name, const char *short_desc, const char *long_desc, bool *valueAddr, bool bootValue, GucContext context, int flags, GucBoolCheckHook check_hook, GucBoolAssignHook assign_hook, GucShowHook show_hook)
 
void DefineCustomIntVariable (const char *name, const char *short_desc, const char *long_desc, int *valueAddr, int bootValue, int minValue, int maxValue, GucContext context, int flags, GucIntCheckHook check_hook, GucIntAssignHook assign_hook, GucShowHook show_hook)
 
void DefineCustomRealVariable (const char *name, const char *short_desc, const char *long_desc, double *valueAddr, double bootValue, double minValue, double maxValue, GucContext context, int flags, GucRealCheckHook check_hook, GucRealAssignHook assign_hook, GucShowHook show_hook)
 
void DefineCustomStringVariable (const char *name, const char *short_desc, const char *long_desc, char **valueAddr, const char *bootValue, GucContext context, int flags, GucStringCheckHook check_hook, GucStringAssignHook assign_hook, GucShowHook show_hook)
 
void DefineCustomEnumVariable (const char *name, const char *short_desc, const char *long_desc, int *valueAddr, int bootValue, const struct config_enum_entry *options, GucContext context, int flags, GucEnumCheckHook check_hook, GucEnumAssignHook assign_hook, GucShowHook show_hook)
 
void EmitWarningsOnPlaceholders (const char *className)
 
void GetPGVariable (const char *name, DestReceiver *dest)
 
TupleDesc GetPGVariableResultDesc (const char *name)
 
struct config_generic ** get_explain_guc_options (int *num)
 
char * GetConfigOptionByName (const char *name, const char **varname, bool missing_ok)
 
void GetConfigOptionByNum (int varnum, const char **values, bool *noshow)
 
int GetNumConfigOptions (void)
 
Datum show_config_by_name (PG_FUNCTION_ARGS)
 
Datum show_config_by_name_missing_ok (PG_FUNCTION_ARGS)
 
Datum show_all_settings (PG_FUNCTION_ARGS)
 
Datum show_all_file_settings (PG_FUNCTION_ARGS)
 
static bool can_skip_gucvar (struct config_generic *gconf)
 
static Size estimate_variable_size (struct config_generic *gconf)
 
Size EstimateGUCStateSpace (void)
 
static void do_serialize_binary (char **destptr, Size *maxbytes, void *val, Size valsize)
 
static void serialize_variable (char **destptr, Size *maxbytes, struct config_generic *gconf)
 
void SerializeGUCState (Size maxsize, char *start_address)
 
static char * read_gucstate (char **srcptr, char *srcend)
 
static void read_gucstate_binary (char **srcptr, char *srcend, void *dest, Size size)
 
static void guc_restore_error_context_callback (void *arg)
 
void RestoreGUCState (void *gucstate)
 
void ParseLongOption (const char *string, char **name, char **value)
 
void ProcessGUCArray (ArrayType *array, GucContext context, GucSource source, GucAction action)
 
ArrayTypeGUCArrayAdd (ArrayType *array, const char *name, const char *value)
 
ArrayTypeGUCArrayDelete (ArrayType *array, const char *name)
 
ArrayTypeGUCArrayReset (ArrayType *array)
 
void GUC_check_errcode (int sqlerrcode)
 
static void pg_attribute_noreturn ()
 

Variables

bool Log_disconnections
 
int CommitDelay
 
int CommitSiblings
 
char * default_tablespace
 
char * temp_tablespaces
 
bool ignore_checksum_failure
 
bool synchronize_seqscans
 
static int GUC_check_errcode_value
 
char * GUC_check_errmsg_string
 
char * GUC_check_errdetail_string
 
char * GUC_check_errhint_string
 
static int syslog_facility = 0
 
static const struct config_enum_entry bytea_output_options []
 
static const struct config_enum_entry client_message_level_options []
 
static const struct config_enum_entry server_message_level_options []
 
static const struct config_enum_entry intervalstyle_options []
 
static const struct config_enum_entry log_error_verbosity_options []
 
static const struct config_enum_entry log_statement_options []
 
static const struct config_enum_entry isolation_level_options []
 
static const struct config_enum_entry session_replication_role_options []
 
static const struct config_enum_entry syslog_facility_options []
 
static const struct config_enum_entry track_function_options []
 
static const struct config_enum_entry xmlbinary_options []
 
static const struct config_enum_entry xmloption_options []
 
static const struct config_enum_entry backslash_quote_options []
 
static const struct config_enum_entry constraint_exclusion_options []
 
static const struct config_enum_entry synchronous_commit_options []
 
static const struct config_enum_entry huge_pages_options []
 
static const struct config_enum_entry force_parallel_mode_options []
 
static const struct config_enum_entry plan_cache_mode_options []
 
static const struct config_enum_entry password_encryption_options []
 
const struct config_enum_entry ssl_protocol_versions_info []
 
static struct config_enum_entry shared_memory_options []
 
const struct config_enum_entry wal_level_options []
 
const struct config_enum_entry archive_mode_options []
 
const struct config_enum_entry recovery_target_action_options []
 
const struct config_enum_entry sync_method_options []
 
const struct config_enum_entry dynamic_shared_memory_options []
 
bool log_duration = false
 
bool 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_statement = -1
 
int log_temp_files = -1
 
double log_xact_sample_rate = 0
 
int trace_recovery_messages = LOG
 
int temp_file_limit = -1
 
int num_temp_buffers = 1024
 
char * cluster_name = ""
 
char * ConfigFileName
 
char * HbaFileName
 
char * IdentFileName
 
char * external_pid_file
 
char * pgstat_temp_directory
 
char * application_name
 
int tcp_keepalives_idle
 
int tcp_keepalives_interval
 
int tcp_keepalives_count
 
int tcp_user_timeout
 
int ssl_renegotiation_limit
 
int huge_pages
 
static char * syslog_ident_str
 
static double phony_random_seed
 
static char * client_encoding_string
 
static char * datestyle_string
 
static char * locale_collate
 
static char * locale_ctype
 
static char * server_encoding_string
 
static char * server_version_string
 
static int server_version_num
 
static char * timezone_string
 
static char * log_timezone_string
 
static char * timezone_abbreviations_string
 
static char * data_directory
 
static char * session_authorization_string
 
static int max_function_args
 
static int max_index_keys
 
static int max_identifier_length
 
static int block_size
 
static int segment_size
 
static int wal_block_size
 
static bool data_checksums
 
static bool integer_datetimes
 
static bool assert_enabled
 
static char * recovery_target_timeline_string
 
static char * recovery_target_string
 
static char * recovery_target_xid_string
 
static char * recovery_target_name_string
 
static char * recovery_target_lsn_string
 
char * role_string
 
const char *const GucContext_Names []
 
const char *const GucSource_Names []
 
const char *const config_group_names []
 
const char *const config_type_names []
 
static const char * memory_units_hint = gettext_noop("Valid units for this parameter are \"B\", \"kB\", \"MB\", \"GB\", and \"TB\".")
 
static const unit_conversion memory_unit_conversion_table []
 
static const char * time_units_hint = gettext_noop("Valid units for this parameter are \"us\", \"ms\", \"s\", \"min\", \"h\", and \"d\".")
 
static const unit_conversion time_unit_conversion_table []
 
static struct config_bool ConfigureNamesBool []
 
static struct config_int ConfigureNamesInt []
 
static struct config_real ConfigureNamesReal []
 
static struct config_string ConfigureNamesString []
 
static struct config_enum ConfigureNamesEnum []
 
static const char *const map_old_guc_names []
 
static struct config_generic ** guc_variables
 
static int num_guc_variables
 
static int num_guc_explain_variables
 
static int size_guc_variables
 
static bool guc_dirty
 
static bool reporting_enabled
 
static int GUCNestLevel = 0
 

Macro Definition Documentation

◆ CONFIG_FILENAME

#define CONFIG_FILENAME   "postgresql.conf"

Definition at line 103 of file guc.c.

Referenced by SelectConfigFiles().

◆ HBA_FILENAME

#define HBA_FILENAME   "pg_hba.conf"

Definition at line 104 of file guc.c.

Referenced by SelectConfigFiles().

◆ IDENT_FILENAME

#define IDENT_FILENAME   "pg_ident.conf"

Definition at line 105 of file guc.c.

Referenced by SelectConfigFiles().

◆ MAX_UNIT_LEN

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

Definition at line 768 of file guc.c.

Referenced by convert_to_base_unit().

◆ newval [1/5]

#define newval   (newval_union.boolval)

◆ newval [2/5]

#define newval   (newval_union.intval)

◆ newval [3/5]

#define newval   (newval_union.realval)

◆ newval [4/5]

#define newval   (newval_union.stringval)

◆ newval [5/5]

#define newval   (newval_union.enumval)

◆ NUM_PG_FILE_SETTINGS_ATTS

#define NUM_PG_FILE_SETTINGS_ATTS   7

Referenced by show_all_file_settings().

◆ NUM_PG_SETTINGS_ATTS

#define NUM_PG_SETTINGS_ATTS   17

Definition at line 9291 of file guc.c.

Referenced by show_all_settings().

◆ PG_KRB_SRVTAB

#define PG_KRB_SRVTAB   ""

Definition at line 100 of file guc.c.

◆ REALTYPE_PRECISION

#define REALTYPE_PRECISION   17

Definition at line 116 of file guc.c.

Referenced by estimate_variable_size(), and serialize_variable().

Function Documentation

◆ _ShowOption()

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

Definition at line 9538 of file guc.c.

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

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

9539 {
9540  char buffer[256];
9541  const char *val;
9542 
9543  switch (record->vartype)
9544  {
9545  case PGC_BOOL:
9546  {
9547  struct config_bool *conf = (struct config_bool *) record;
9548 
9549  if (conf->show_hook)
9550  val = conf->show_hook();
9551  else
9552  val = *conf->variable ? "on" : "off";
9553  }
9554  break;
9555 
9556  case PGC_INT:
9557  {
9558  struct config_int *conf = (struct config_int *) record;
9559 
9560  if (conf->show_hook)
9561  val = conf->show_hook();
9562  else
9563  {
9564  /*
9565  * Use int64 arithmetic to avoid overflows in units
9566  * conversion.
9567  */
9568  int64 result = *conf->variable;
9569  const char *unit;
9570 
9571  if (use_units && result > 0 && (record->flags & GUC_UNIT))
9573  record->flags & GUC_UNIT,
9574  &result, &unit);
9575  else
9576  unit = "";
9577 
9578  snprintf(buffer, sizeof(buffer), INT64_FORMAT "%s",
9579  result, unit);
9580  val = buffer;
9581  }
9582  }
9583  break;
9584 
9585  case PGC_REAL:
9586  {
9587  struct config_real *conf = (struct config_real *) record;
9588 
9589  if (conf->show_hook)
9590  val = conf->show_hook();
9591  else
9592  {
9593  double result = *conf->variable;
9594  const char *unit;
9595 
9596  if (use_units && result > 0 && (record->flags & GUC_UNIT))
9598  record->flags & GUC_UNIT,
9599  &result, &unit);
9600  else
9601  unit = "";
9602 
9603  snprintf(buffer, sizeof(buffer), "%g%s",
9604  result, unit);
9605  val = buffer;
9606  }
9607  }
9608  break;
9609 
9610  case PGC_STRING:
9611  {
9612  struct config_string *conf = (struct config_string *) record;
9613 
9614  if (conf->show_hook)
9615  val = conf->show_hook();
9616  else if (*conf->variable && **conf->variable)
9617  val = *conf->variable;
9618  else
9619  val = "";
9620  }
9621  break;
9622 
9623  case PGC_ENUM:
9624  {
9625  struct config_enum *conf = (struct config_enum *) record;
9626 
9627  if (conf->show_hook)
9628  val = conf->show_hook();
9629  else
9630  val = config_enum_lookup_by_value(conf, *conf->variable);
9631  }
9632  break;
9633 
9634  default:
9635  /* just to keep compiler quiet */
9636  val = "???";
9637  break;
9638  }
9639 
9640  return pstrdup(val);
9641 }
char ** variable
Definition: guc_tables.h:230
char * pstrdup(const char *in)
Definition: mcxt.c:1186
bool * variable
Definition: guc_tables.h:184
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:6418
#define GUC_UNIT
Definition: guc.h:232
GucShowHook show_hook
Definition: guc_tables.h:204
int * variable
Definition: guc_tables.h:198
int * variable
Definition: guc_tables.h:244
static void convert_real_from_base_unit(double base_value, int base_unit, double *value, const char **unit)
Definition: guc.c:6166
GucShowHook show_hook
Definition: guc_tables.h:234
GucShowHook show_hook
Definition: guc_tables.h:220
double * variable
Definition: guc_tables.h:214
enum config_type vartype
Definition: guc_tables.h:156
GucShowHook show_hook
Definition: guc_tables.h:249
GucShowHook show_hook
Definition: guc_tables.h:188
#define INT64_FORMAT
Definition: c.h:400
static void convert_int_from_base_unit(int64 base_value, int base_unit, int64 *value, const char **unit)
Definition: guc.c:6124
#define snprintf
Definition: port.h:192
long val
Definition: informix.c:684

◆ add_guc_variable()

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

Definition at line 4936 of file guc.c.

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

Referenced by add_placeholder_variable(), and define_custom_variable().

4937 {
4939  {
4940  /*
4941  * Increase the vector by 25%
4942  */
4943  int size_vars = size_guc_variables + size_guc_variables / 4;
4944  struct config_generic **guc_vars;
4945 
4946  if (size_vars == 0)
4947  {
4948  size_vars = 100;
4949  guc_vars = (struct config_generic **)
4950  guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
4951  }
4952  else
4953  {
4954  guc_vars = (struct config_generic **)
4955  guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
4956  }
4957 
4958  if (guc_vars == NULL)
4959  return false; /* out of memory */
4960 
4961  guc_variables = guc_vars;
4962  size_guc_variables = size_vars;
4963  }
4966  sizeof(struct config_generic *), guc_var_compare);
4967  return true;
4968 }
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:5071
static int num_guc_variables
Definition: guc.c:4568
static void * guc_realloc(int elevel, void *old, size_t size)
Definition: guc.c:4625
static struct config_generic ** guc_variables
Definition: guc.c:4565
static int size_guc_variables
Definition: guc.c:4574
static int elevel
Definition: vacuumlazy.c:143
#define qsort(a, b, c, d)
Definition: port.h:492
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4609

◆ add_placeholder_variable()

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

Definition at line 4974 of file guc.c.

References add_guc_variable(), config_generic::context, CUSTOM_OPTIONS, config_generic::flags, free, config_string::gen, config_generic::group, GUC_CUSTOM_PLACEHOLDER, guc_malloc(), GUC_NO_SHOW_ALL, GUC_NOT_IN_SAMPLE, guc_strdup(), config_generic::name, PGC_STRING, PGC_USERSET, config_generic::short_desc, unconstify, config_string::variable, and config_generic::vartype.

Referenced by find_option().

4975 {
4976  size_t sz = sizeof(struct config_string) + sizeof(char *);
4977  struct config_string *var;
4978  struct config_generic *gen;
4979 
4980  var = (struct config_string *) guc_malloc(elevel, sz);
4981  if (var == NULL)
4982  return NULL;
4983  memset(var, 0, sz);
4984  gen = &var->gen;
4985 
4986  gen->name = guc_strdup(elevel, name);
4987  if (gen->name == NULL)
4988  {
4989  free(var);
4990  return NULL;
4991  }
4992 
4993  gen->context = PGC_USERSET;
4994  gen->group = CUSTOM_OPTIONS;
4995  gen->short_desc = "GUC placeholder variable";
4997  gen->vartype = PGC_STRING;
4998 
4999  /*
5000  * The char* is allocated at the end of the struct since we have no
5001  * 'static' place to point to. Note that the current value, as well as
5002  * the boot and reset values, start out NULL.
5003  */
5004  var->variable = (char **) (var + 1);
5005 
5006  if (!add_guc_variable((struct config_generic *) var, elevel))
5007  {
5008  free(unconstify(char *, gen->name));
5009  free(var);
5010  return NULL;
5011  }
5012 
5013  return gen;
5014 }
char ** variable
Definition: guc_tables.h:230
const char * name
Definition: guc_tables.h:149
const char * short_desc
Definition: guc_tables.h:152
static char * guc_strdup(int elevel, const char *src)
Definition: guc.c:4641
#define GUC_NO_SHOW_ALL
Definition: guc.h:206
#define GUC_NOT_IN_SAMPLE
Definition: guc.h:209
enum config_type vartype
Definition: guc_tables.h:156
#define unconstify(underlying_type, expr)
Definition: c.h:1163
static int elevel
Definition: vacuumlazy.c:143
struct config_generic gen
Definition: guc_tables.h:228
#define free(a)
Definition: header.h:65
#define GUC_CUSTOM_PLACEHOLDER
Definition: guc.h:211
const char * name
Definition: encode.c:521
enum config_group group
Definition: guc_tables.h:151
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4609
GucContext context
Definition: guc_tables.h:150
static bool add_guc_variable(struct config_generic *var, int elevel)
Definition: guc.c:4936

◆ AlterSystemSetConfigFile()

void AlterSystemSetConfigFile ( AlterSystemStmt altersysstmt)

Definition at line 7906 of file guc.c.

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

Referenced by standard_ProcessUtility().

7907 {
7908  char *name;
7909  char *value;
7910  bool resetall = false;
7911  ConfigVariable *head = NULL;
7912  ConfigVariable *tail = NULL;
7913  volatile int Tmpfd;
7914  char AutoConfFileName[MAXPGPATH];
7915  char AutoConfTmpFileName[MAXPGPATH];
7916 
7917  if (!superuser())
7918  ereport(ERROR,
7919  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7920  (errmsg("must be superuser to execute ALTER SYSTEM command"))));
7921 
7922  /*
7923  * Extract statement arguments
7924  */
7925  name = altersysstmt->setstmt->name;
7926 
7927  switch (altersysstmt->setstmt->kind)
7928  {
7929  case VAR_SET_VALUE:
7930  value = ExtractSetVariableArgs(altersysstmt->setstmt);
7931  break;
7932 
7933  case VAR_SET_DEFAULT:
7934  case VAR_RESET:
7935  value = NULL;
7936  break;
7937 
7938  case VAR_RESET_ALL:
7939  value = NULL;
7940  resetall = true;
7941  break;
7942 
7943  default:
7944  elog(ERROR, "unrecognized alter system stmt type: %d",
7945  altersysstmt->setstmt->kind);
7946  break;
7947  }
7948 
7949  /*
7950  * Unless it's RESET_ALL, validate the target variable and value
7951  */
7952  if (!resetall)
7953  {
7954  struct config_generic *record;
7955 
7956  record = find_option(name, false, ERROR);
7957  if (record == NULL)
7958  ereport(ERROR,
7959  (errcode(ERRCODE_UNDEFINED_OBJECT),
7960  errmsg("unrecognized configuration parameter \"%s\"",
7961  name)));
7962 
7963  /*
7964  * Don't allow parameters that can't be set in configuration files to
7965  * be set in PG_AUTOCONF_FILENAME file.
7966  */
7967  if ((record->context == PGC_INTERNAL) ||
7968  (record->flags & GUC_DISALLOW_IN_FILE) ||
7969  (record->flags & GUC_DISALLOW_IN_AUTO_FILE))
7970  ereport(ERROR,
7971  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
7972  errmsg("parameter \"%s\" cannot be changed",
7973  name)));
7974 
7975  /*
7976  * If a value is specified, verify that it's sane.
7977  */
7978  if (value)
7979  {
7980  union config_var_val newval;
7981  void *newextra = NULL;
7982 
7983  /* Check that it's acceptable for the indicated parameter */
7984  if (!parse_and_validate_value(record, name, value,
7985  PGC_S_FILE, ERROR,
7986  &newval, &newextra))
7987  ereport(ERROR,
7988  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7989  errmsg("invalid value for parameter \"%s\": \"%s\"",
7990  name, value)));
7991 
7992  if (record->vartype == PGC_STRING && newval.stringval != NULL)
7993  free(newval.stringval);
7994  if (newextra)
7995  free(newextra);
7996 
7997  /*
7998  * We must also reject values containing newlines, because the
7999  * grammar for config files doesn't support embedded newlines in
8000  * string literals.
8001  */
8002  if (strchr(value, '\n'))
8003  ereport(ERROR,
8004  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8005  errmsg("parameter value for ALTER SYSTEM must not contain a newline")));
8006  }
8007  }
8008 
8009  /*
8010  * PG_AUTOCONF_FILENAME and its corresponding temporary file are always in
8011  * the data directory, so we can reference them by simple relative paths.
8012  */
8013  snprintf(AutoConfFileName, sizeof(AutoConfFileName), "%s",
8015  snprintf(AutoConfTmpFileName, sizeof(AutoConfTmpFileName), "%s.%s",
8016  AutoConfFileName,
8017  "tmp");
8018 
8019  /*
8020  * Only one backend is allowed to operate on PG_AUTOCONF_FILENAME at a
8021  * time. Use AutoFileLock to ensure that. We must hold the lock while
8022  * reading the old file contents.
8023  */
8024  LWLockAcquire(AutoFileLock, LW_EXCLUSIVE);
8025 
8026  /*
8027  * If we're going to reset everything, then no need to open or parse the
8028  * old file. We'll just write out an empty list.
8029  */
8030  if (!resetall)
8031  {
8032  struct stat st;
8033 
8034  if (stat(AutoConfFileName, &st) == 0)
8035  {
8036  /* open old file PG_AUTOCONF_FILENAME */
8037  FILE *infile;
8038 
8039  infile = AllocateFile(AutoConfFileName, "r");
8040  if (infile == NULL)
8041  ereport(ERROR,
8043  errmsg("could not open file \"%s\": %m",
8044  AutoConfFileName)));
8045 
8046  /* parse it */
8047  if (!ParseConfigFp(infile, AutoConfFileName, 0, LOG, &head, &tail))
8048  ereport(ERROR,
8049  (errcode(ERRCODE_CONFIG_FILE_ERROR),
8050  errmsg("could not parse contents of file \"%s\"",
8051  AutoConfFileName)));
8052 
8053  FreeFile(infile);
8054  }
8055 
8056  /*
8057  * Now, replace any existing entry with the new value, or add it if
8058  * not present.
8059  */
8060  replace_auto_config_value(&head, &tail, name, value);
8061  }
8062 
8063  /*
8064  * To ensure crash safety, first write the new file data to a temp file,
8065  * then atomically rename it into place.
8066  *
8067  * If there is a temp file left over due to a previous crash, it's okay to
8068  * truncate and reuse it.
8069  */
8070  Tmpfd = BasicOpenFile(AutoConfTmpFileName,
8071  O_CREAT | O_RDWR | O_TRUNC);
8072  if (Tmpfd < 0)
8073  ereport(ERROR,
8075  errmsg("could not open file \"%s\": %m",
8076  AutoConfTmpFileName)));
8077 
8078  /*
8079  * Use a TRY block to clean up the file if we fail. Since we need a TRY
8080  * block anyway, OK to use BasicOpenFile rather than OpenTransientFile.
8081  */
8082  PG_TRY();
8083  {
8084  /* Write and sync the new contents to the temporary file */
8085  write_auto_conf_file(Tmpfd, AutoConfTmpFileName, head);
8086 
8087  /* Close before renaming; may be required on some platforms */
8088  close(Tmpfd);
8089  Tmpfd = -1;
8090 
8091  /*
8092  * As the rename is atomic operation, if any problem occurs after this
8093  * at worst it can lose the parameters set by last ALTER SYSTEM
8094  * command.
8095  */
8096  durable_rename(AutoConfTmpFileName, AutoConfFileName, ERROR);
8097  }
8098  PG_CATCH();
8099  {
8100  /* Close file first, else unlink might fail on some platforms */
8101  if (Tmpfd >= 0)
8102  close(Tmpfd);
8103 
8104  /* Unlink, but ignore any error */
8105  (void) unlink(AutoConfTmpFileName);
8106 
8107  PG_RE_THROW();
8108  }
8109  PG_END_TRY();
8110 
8111  FreeConfigVariables(head);
8112 
8113  LWLockRelease(AutoFileLock);
8114 }
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:6525
VariableSetKind kind
Definition: parsenodes.h:2019
static struct @145 value
int errcode(int sqlerrcode)
Definition: elog.c:570
bool superuser(void)
Definition: superuser.c:47
#define LOG
Definition: elog.h:26
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1726
#define ERROR
Definition: elog.h:43
#define MAXPGPATH
VariableSetStmt * setstmt
Definition: parsenodes.h:3157
int errcode_for_file_access(void)
Definition: elog.c:593
FILE * AllocateFile(const char *name, const char *mode)
Definition: fd.c:2205
#define ereport(elevel, rest)
Definition: elog.h:141
int durable_rename(const char *oldfile, const char *newfile, int elevel)
Definition: fd.c:606
enum config_type vartype
Definition: guc_tables.h:156
#define stat(a, b)
Definition: win32_port.h:255
#define GUC_DISALLOW_IN_FILE
Definition: guc.h:210
static void write_auto_conf_file(int fd, const char *filename, ConfigVariable *head_p)
Definition: guc.c:7768
static void infile(const char *filename)
Definition: zic.c:1233
#define free(a)
Definition: header.h:65
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:5022
#define PG_CATCH()
Definition: elog.h:310
#define newval
#define PG_AUTOCONF_FILENAME
Definition: guc.h:34
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1122
#define PG_RE_THROW()
Definition: elog.h:331
const char * name
Definition: encode.c:521
#define GUC_DISALLOW_IN_AUTO_FILE
Definition: guc.h:215
int BasicOpenFile(const char *fileName, int fileFlags)
Definition: fd.c:944
int FreeFile(FILE *file)
Definition: fd.c:2404
int errmsg(const char *fmt,...)
Definition: elog.c:784
bool ParseConfigFp(FILE *fp, const char *config_file, int depth, int elevel, ConfigVariable **head_p, ConfigVariable **tail_p)
#define elog(elevel,...)
Definition: elog.h:226
static void replace_auto_config_value(ConfigVariable **head_p, ConfigVariable **tail_p, const char *name, const char *value)
Definition: guc.c:7836
void FreeConfigVariables(ConfigVariable *list)
#define close(a)
Definition: win32.h:12
#define PG_TRY()
Definition: elog.h:301
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
Definition: guc.c:8244
#define snprintf
Definition: port.h:192
#define PG_END_TRY()
Definition: elog.h:317
GucContext context
Definition: guc_tables.h:150

◆ assign_application_name()

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

Definition at line 11423 of file guc.c.

References pgstat_report_appname().

11424 {
11425  /* Update the pg_stat_activity view */
11427 }
void pgstat_report_appname(const char *appname)
Definition: pgstat.c:3294
#define newval

◆ assign_effective_io_concurrency()

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

Definition at line 11377 of file guc.c.

References target_prefetch_pages.

11378 {
11379 #ifdef USE_PREFETCH
11380  target_prefetch_pages = *((int *) extra);
11381 #endif /* USE_PREFETCH */
11382 }
int target_prefetch_pages
Definition: bufmgr.c:130

◆ assign_log_destination()

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

Definition at line 11032 of file guc.c.

References Log_destination.

11033 {
11034  Log_destination = *((int *) extra);
11035 }
int Log_destination
Definition: elog.c:106

◆ assign_pgstat_temp_directory()

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

Definition at line 11385 of file guc.c.

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

11386 {
11387  /* check_canonical_path already canonicalized newval for us */
11388  char *dname;
11389  char *tname;
11390  char *fname;
11391 
11392  /* directory */
11393  dname = guc_malloc(ERROR, strlen(newval) + 1); /* runtime dir */
11394  sprintf(dname, "%s", newval);
11395 
11396  /* global stats */
11397  tname = guc_malloc(ERROR, strlen(newval) + 12); /* /global.tmp */
11398  sprintf(tname, "%s/global.tmp", newval);
11399  fname = guc_malloc(ERROR, strlen(newval) + 13); /* /global.stat */
11400  sprintf(fname, "%s/global.stat", newval);
11401 
11404  pgstat_stat_directory = dname;
11405  if (pgstat_stat_tmpname)
11407  pgstat_stat_tmpname = tname;
11410  pgstat_stat_filename = fname;
11411 }
#define sprintf
Definition: port.h:194
char * pgstat_stat_filename
Definition: pgstat.c:135
#define ERROR
Definition: elog.h:43
char * pgstat_stat_directory
Definition: pgstat.c:134
#define free(a)
Definition: header.h:65
#define newval
char * pgstat_stat_tmpname
Definition: pgstat.c:136
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4609

◆ assign_recovery_target()

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

Definition at line 11539 of file guc.c.

References RECOVERY_TARGET_IMMEDIATE, RECOVERY_TARGET_UNSET, and recoveryTarget.

11540 {
11543  error_multiple_recovery_targets();
11544 
11545  if (newval && strcmp(newval, "") != 0)
11547  else
11549 }
#define newval
RecoveryTargetType recoveryTarget
Definition: xlog.c:271

◆ assign_recovery_target_lsn()

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

Definition at line 11707 of file guc.c.

References RECOVERY_TARGET_LSN, RECOVERY_TARGET_UNSET, recoveryTarget, and recoveryTargetLSN.

11708 {
11711  error_multiple_recovery_targets();
11712 
11713  if (newval && strcmp(newval, "") != 0)
11714  {
11716  recoveryTargetLSN = *((XLogRecPtr *) extra);
11717  }
11718  else
11720 }
XLogRecPtr recoveryTargetLSN
Definition: xlog.c:278
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define newval
RecoveryTargetType recoveryTarget
Definition: xlog.c:271

◆ assign_recovery_target_name()

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

Definition at line 11671 of file guc.c.

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

11672 {
11675  error_multiple_recovery_targets();
11676 
11677  if (newval && strcmp(newval, "") != 0)
11678  {
11681  }
11682  else
11684 }
const char * recoveryTargetName
Definition: xlog.c:277
#define newval
RecoveryTargetType recoveryTarget
Definition: xlog.c:271

◆ assign_recovery_target_time()

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

Definition at line 11645 of file guc.c.

References RECOVERY_TARGET_TIME, RECOVERY_TARGET_UNSET, and recoveryTarget.

11646 {
11649  error_multiple_recovery_targets();
11650 
11651  if (newval && strcmp(newval, "") != 0)
11653  else
11655 }
#define newval
RecoveryTargetType recoveryTarget
Definition: xlog.c:271

◆ assign_recovery_target_timeline()

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

Definition at line 11496 of file guc.c.

References RECOVERY_TARGET_TIMELINE_NUMERIC, recoveryTargetTimeLineGoal, and recoveryTargetTLIRequested.

11497 {
11500  recoveryTargetTLIRequested = (TimeLineID) strtoul(newval, NULL, 0);
11501  else
11503 }
TimeLineID recoveryTargetTLIRequested
Definition: xlog.c:331
uint32 TimeLineID
Definition: xlogdefs.h:52
RecoveryTargetTimeLineGoal
Definition: xlog.h:93
RecoveryTargetTimeLineGoal recoveryTargetTimeLineGoal
Definition: xlog.c:330
#define newval

◆ assign_recovery_target_xid()

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

Definition at line 11572 of file guc.c.

References RECOVERY_TARGET_UNSET, RECOVERY_TARGET_XID, recoveryTarget, and recoveryTargetXid.

11573 {
11576  error_multiple_recovery_targets();
11577 
11578  if (newval && strcmp(newval, "") != 0)
11579  {
11581  recoveryTargetXid = *((TransactionId *) extra);
11582  }
11583  else
11585 }
uint32 TransactionId
Definition: c.h:507
TransactionId recoveryTargetXid
Definition: xlog.c:274
#define newval
RecoveryTargetType recoveryTarget
Definition: xlog.c:271

◆ assign_session_replication_role()

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

Definition at line 11058 of file guc.c.

References ResetPlanCache(), and SessionReplicationRole.

11059 {
11060  /*
11061  * Must flush the plan cache when changing replication role; but don't
11062  * flush unnecessarily.
11063  */
11065  ResetPlanCache();
11066 }
int SessionReplicationRole
Definition: trigger.c:67
void ResetPlanCache(void)
Definition: plancache.c:1966
#define newval

◆ assign_syslog_facility()

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

Definition at line 11038 of file guc.c.

11039 {
11040 #ifdef HAVE_SYSLOG
11041  set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
11042  newval);
11043 #endif
11044  /* Without syslog support, just ignore it */
11045 }
static char * syslog_ident_str
Definition: guc.c:555
#define newval

◆ assign_syslog_ident()

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

Definition at line 11048 of file guc.c.

11049 {
11050 #ifdef HAVE_SYSLOG
11051  set_syslog_parameters(newval, syslog_facility);
11052 #endif
11053  /* Without syslog support, it will always be set to "none", so ignore */
11054 }
static int syslog_facility
Definition: guc.c:166
#define newval

◆ assign_tcp_keepalives_count()

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

Definition at line 11257 of file guc.c.

References MyProcPort, and pq_setkeepalivescount().

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

◆ assign_tcp_keepalives_idle()

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

Definition at line 11213 of file guc.c.

References MyProcPort, and pq_setkeepalivesidle().

11214 {
11215  /*
11216  * The kernel API provides no way to test a value without setting it; and
11217  * once we set it we might fail to unset it. So there seems little point
11218  * in fully implementing the check-then-assign GUC API for these
11219  * variables. Instead we just do the assignment on demand. pqcomm.c
11220  * reports any problems via elog(LOG).
11221  *
11222  * This approach means that the GUC value might have little to do with the
11223  * actual kernel value, so we use a show_hook that retrieves the kernel
11224  * value rather than trusting GUC's copy.
11225  */
11227 }
struct Port * MyProcPort
Definition: globals.c:43
int pq_setkeepalivesidle(int idle, Port *port)
Definition: pqcomm.c:1731
#define newval

◆ assign_tcp_keepalives_interval()

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

Definition at line 11240 of file guc.c.

References MyProcPort, and pq_setkeepalivesinterval().

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

◆ assign_tcp_user_timeout()

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

Definition at line 11274 of file guc.c.

References MyProcPort, and pq_settcpusertimeout().

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

◆ assign_timezone_abbreviations()

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

Definition at line 11177 of file guc.c.

References InstallTimeZoneAbbrevs().

11178 {
11179  /* Do nothing for the boot_val default of NULL */
11180  if (!extra)
11181  return;
11182 
11184 }
void InstallTimeZoneAbbrevs(TimeZoneAbbrevTable *tbl)
Definition: datetime.c:4584

◆ assign_wal_consistency_checking()

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

Definition at line 10969 of file guc.c.

References wal_consistency_checking.

10970 {
10971  wal_consistency_checking = (bool *) extra;
10972 }
bool * wal_consistency_checking
Definition: xlog.c:98

◆ AtEOXact_GUC()

void AtEOXact_GUC ( bool  isCommit,
int  nestLevel 
)

Definition at line 5729 of file guc.c.

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

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

5730 {
5731  bool still_dirty;
5732  int i;
5733 
5734  /*
5735  * Note: it's possible to get here with GUCNestLevel == nestLevel-1 during
5736  * abort, if there is a failure during transaction start before
5737  * AtStart_GUC is called.
5738  */
5739  Assert(nestLevel > 0 &&
5740  (nestLevel <= GUCNestLevel ||
5741  (nestLevel == GUCNestLevel + 1 && !isCommit)));
5742 
5743  /* Quick exit if nothing's changed in this transaction */
5744  if (!guc_dirty)
5745  {
5746  GUCNestLevel = nestLevel - 1;
5747  return;
5748  }
5749 
5750  still_dirty = false;
5751  for (i = 0; i < num_guc_variables; i++)
5752  {
5753  struct config_generic *gconf = guc_variables[i];
5754  GucStack *stack;
5755 
5756  /*
5757  * Process and pop each stack entry within the nest level. To simplify
5758  * fmgr_security_definer() and other places that use GUC_ACTION_SAVE,
5759  * we allow failure exit from code that uses a local nest level to be
5760  * recovered at the surrounding transaction or subtransaction abort;
5761  * so there could be more than one stack entry to pop.
5762  */
5763  while ((stack = gconf->stack) != NULL &&
5764  stack->nest_level >= nestLevel)
5765  {
5766  GucStack *prev = stack->prev;
5767  bool restorePrior = false;
5768  bool restoreMasked = false;
5769  bool changed;
5770 
5771  /*
5772  * In this next bit, if we don't set either restorePrior or
5773  * restoreMasked, we must "discard" any unwanted fields of the
5774  * stack entries to avoid leaking memory. If we do set one of
5775  * those flags, unused fields will be cleaned up after restoring.
5776  */
5777  if (!isCommit) /* if abort, always restore prior value */
5778  restorePrior = true;
5779  else if (stack->state == GUC_SAVE)
5780  restorePrior = true;
5781  else if (stack->nest_level == 1)
5782  {
5783  /* transaction commit */
5784  if (stack->state == GUC_SET_LOCAL)
5785  restoreMasked = true;
5786  else if (stack->state == GUC_SET)
5787  {
5788  /* we keep the current active value */
5789  discard_stack_value(gconf, &stack->prior);
5790  }
5791  else /* must be GUC_LOCAL */
5792  restorePrior = true;
5793  }
5794  else if (prev == NULL ||
5795  prev->nest_level < stack->nest_level - 1)
5796  {
5797  /* decrement entry's level and do not pop it */
5798  stack->nest_level--;
5799  continue;
5800  }
5801  else
5802  {
5803  /*
5804  * We have to merge this stack entry into prev. See README for
5805  * discussion of this bit.
5806  */
5807  switch (stack->state)
5808  {
5809  case GUC_SAVE:
5810  Assert(false); /* can't get here */
5811  break;
5812 
5813  case GUC_SET:
5814  /* next level always becomes SET */
5815  discard_stack_value(gconf, &stack->prior);
5816  if (prev->state == GUC_SET_LOCAL)
5817  discard_stack_value(gconf, &prev->masked);
5818  prev->state = GUC_SET;
5819  break;
5820 
5821  case GUC_LOCAL:
5822  if (prev->state == GUC_SET)
5823  {
5824  /* LOCAL migrates down */
5825  prev->masked_scontext = stack->scontext;
5826  prev->masked = stack->prior;
5827  prev->state = GUC_SET_LOCAL;
5828  }
5829  else
5830  {
5831  /* else just forget this stack level */
5832  discard_stack_value(gconf, &stack->prior);
5833  }
5834  break;
5835 
5836  case GUC_SET_LOCAL:
5837  /* prior state at this level no longer wanted */
5838  discard_stack_value(gconf, &stack->prior);
5839  /* copy down the masked state */
5840  prev->masked_scontext = stack->masked_scontext;
5841  if (prev->state == GUC_SET_LOCAL)
5842  discard_stack_value(gconf, &prev->masked);
5843  prev->masked = stack->masked;
5844  prev->state = GUC_SET_LOCAL;
5845  break;
5846  }
5847  }
5848 
5849  changed = false;
5850 
5851  if (restorePrior || restoreMasked)
5852  {
5853  /* Perform appropriate restoration of the stacked value */
5854  config_var_value newvalue;
5855  GucSource newsource;
5856  GucContext newscontext;
5857 
5858  if (restoreMasked)
5859  {
5860  newvalue = stack->masked;
5861  newsource = PGC_S_SESSION;
5862  newscontext = stack->masked_scontext;
5863  }
5864  else
5865  {
5866  newvalue = stack->prior;
5867  newsource = stack->source;
5868  newscontext = stack->scontext;
5869  }
5870 
5871  switch (gconf->vartype)
5872  {
5873  case PGC_BOOL:
5874  {
5875  struct config_bool *conf = (struct config_bool *) gconf;
5876  bool newval = newvalue.val.boolval;
5877  void *newextra = newvalue.extra;
5878 
5879  if (*conf->variable != newval ||
5880  conf->gen.extra != newextra)
5881  {
5882  if (conf->assign_hook)
5883  conf->assign_hook(newval, newextra);
5884  *conf->variable = newval;
5885  set_extra_field(&conf->gen, &conf->gen.extra,
5886  newextra);
5887  changed = true;
5888  }
5889  break;
5890  }
5891  case PGC_INT:
5892  {
5893  struct config_int *conf = (struct config_int *) gconf;
5894  int newval = newvalue.val.intval;
5895  void *newextra = newvalue.extra;
5896 
5897  if (*conf->variable != newval ||
5898  conf->gen.extra != newextra)
5899  {
5900  if (conf->assign_hook)
5901  conf->assign_hook(newval, newextra);
5902  *conf->variable = newval;
5903  set_extra_field(&conf->gen, &conf->gen.extra,
5904  newextra);
5905  changed = true;
5906  }
5907  break;
5908  }
5909  case PGC_REAL:
5910  {
5911  struct config_real *conf = (struct config_real *) gconf;
5912  double newval = newvalue.val.realval;
5913  void *newextra = newvalue.extra;
5914 
5915  if (*conf->variable != newval ||
5916  conf->gen.extra != newextra)
5917  {
5918  if (conf->assign_hook)
5919  conf->assign_hook(newval, newextra);
5920  *conf->variable = newval;
5921  set_extra_field(&conf->gen, &conf->gen.extra,
5922  newextra);
5923  changed = true;
5924  }
5925  break;
5926  }
5927  case PGC_STRING:
5928  {
5929  struct config_string *conf = (struct config_string *) gconf;
5930  char *newval = newvalue.val.stringval;
5931  void *newextra = newvalue.extra;
5932 
5933  if (*conf->variable != newval ||
5934  conf->gen.extra != newextra)
5935  {
5936  if (conf->assign_hook)
5937  conf->assign_hook(newval, newextra);
5938  set_string_field(conf, conf->variable, newval);
5939  set_extra_field(&conf->gen, &conf->gen.extra,
5940  newextra);
5941  changed = true;
5942  }
5943 
5944  /*
5945  * Release stacked values if not used anymore. We
5946  * could use discard_stack_value() here, but since
5947  * we have type-specific code anyway, might as
5948  * well inline it.
5949  */
5950  set_string_field(conf, &stack->prior.val.stringval, NULL);
5951  set_string_field(conf, &stack->masked.val.stringval, NULL);
5952  break;
5953  }
5954  case PGC_ENUM:
5955  {
5956  struct config_enum *conf = (struct config_enum *) gconf;
5957  int newval = newvalue.val.enumval;
5958  void *newextra = newvalue.extra;
5959 
5960  if (*conf->variable != newval ||
5961  conf->gen.extra != newextra)
5962  {
5963  if (conf->assign_hook)
5964  conf->assign_hook(newval, newextra);
5965  *conf->variable = newval;
5966  set_extra_field(&conf->gen, &conf->gen.extra,
5967  newextra);
5968  changed = true;
5969  }
5970  break;
5971  }
5972  }
5973 
5974  /*
5975  * Release stacked extra values if not used anymore.
5976  */
5977  set_extra_field(gconf, &(stack->prior.extra), NULL);
5978  set_extra_field(gconf, &(stack->masked.extra), NULL);
5979 
5980  /* And restore source information */
5981  gconf->source = newsource;
5982  gconf->scontext = newscontext;
5983  }
5984 
5985  /* Finish popping the state stack */
5986  gconf->stack = prev;
5987  pfree(stack);
5988 
5989  /* Report new value if we changed it */
5990  if (changed && (gconf->flags & GUC_REPORT))
5991  ReportGUCOption(gconf);
5992  } /* end of stack-popping loop */
5993 
5994  if (stack != NULL)
5995  still_dirty = true;
5996  }
5997 
5998  /* If there are no remaining stack entries, we can reset guc_dirty */
5999  guc_dirty = still_dirty;
6000 
6001  /* Update nesting level */
6002  GUCNestLevel = nestLevel - 1;
6003 }
struct guc_stack * prev
Definition: guc_tables.h:123
GucSource source
Definition: guc_tables.h:158
GucContext
Definition: guc.h:68
union config_var_val val
Definition: guc_tables.h:46
int nest_level
Definition: guc_tables.h:124
GucRealAssignHook assign_hook
Definition: guc_tables.h:219
char ** variable
Definition: guc_tables.h:230
static int GUCNestLevel
Definition: guc.c:4581
bool * variable
Definition: guc_tables.h:184
GucEnumAssignHook assign_hook
Definition: guc_tables.h:248
GucBoolAssignHook assign_hook
Definition: guc_tables.h:187
config_var_value masked
Definition: guc_tables.h:131
GucContext scontext
Definition: guc_tables.h:160
GucIntAssignHook assign_hook
Definition: guc_tables.h:203
GucSource
Definition: guc.h:105
int * variable
Definition: guc_tables.h:198
int * variable
Definition: guc_tables.h:244
void pfree(void *pointer)
Definition: mcxt.c:1056
static int num_guc_variables
Definition: guc.c:4568
static void discard_stack_value(struct config_generic *gconf, config_var_value *val)
Definition: guc.c:4796
GucSource source
Definition: guc_tables.h:126
static void set_extra_field(struct config_generic *gconf, void **field, void *newval)
Definition: guc.c:4742
struct config_generic gen
Definition: guc_tables.h:182
struct config_generic gen
Definition: guc_tables.h:196
GucContext masked_scontext
Definition: guc_tables.h:129
#define GUC_REPORT
Definition: guc.h:208
double * variable
Definition: guc_tables.h:214
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4681
static struct config_generic ** guc_variables
Definition: guc.c:4565
enum config_type vartype
Definition: guc_tables.h:156
GucContext scontext
Definition: guc_tables.h:128
struct config_generic gen
Definition: guc_tables.h:242
struct config_generic gen
Definition: guc_tables.h:228
GucStackState state
Definition: guc_tables.h:125
GucStringAssignHook assign_hook
Definition: guc_tables.h:233
#define Assert(condition)
Definition: c.h:732
#define newval
char * stringval
Definition: guc_tables.h:36
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:6039
GucStack * stack
Definition: guc_tables.h:162
double realval
Definition: guc_tables.h:35
static bool guc_dirty
Definition: guc.c:4577
config_var_value prior
Definition: guc_tables.h:130
struct config_generic gen
Definition: guc_tables.h:212

◆ AtStart_GUC()

void AtStart_GUC ( void  )

Definition at line 5695 of file guc.c.

References elog, and WARNING.

Referenced by StartTransaction().

5696 {
5697  /*
5698  * The nest level should be 0 between transactions; if it isn't, somebody
5699  * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
5700  * throw a warning but make no other effort to clean up.
5701  */
5702  if (GUCNestLevel != 0)
5703  elog(WARNING, "GUC nest level = %d at transaction start",
5704  GUCNestLevel);
5705  GUCNestLevel = 1;
5706 }
static int GUCNestLevel
Definition: guc.c:4581
#define WARNING
Definition: elog.h:40
#define elog(elevel,...)
Definition: elog.h:226

◆ BeginReportingGUCOptions()

void BeginReportingGUCOptions ( void  )

Definition at line 6011 of file guc.c.

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

Referenced by PostgresMain().

6012 {
6013  int i;
6014 
6015  /*
6016  * Don't do anything unless talking to an interactive frontend of protocol
6017  * 3.0 or later.
6018  */
6019  if (whereToSendOutput != DestRemote ||
6021  return;
6022 
6023  reporting_enabled = true;
6024 
6025  /* Transmit initial values of interesting variables */
6026  for (i = 0; i < num_guc_variables; i++)
6027  {
6028  struct config_generic *conf = guc_variables[i];
6029 
6030  if (conf->flags & GUC_REPORT)
6031  ReportGUCOption(conf);
6032  }
6033 }
#define PG_PROTOCOL_MAJOR(v)
Definition: pqcomm.h:104
static int num_guc_variables
Definition: guc.c:4568
#define GUC_REPORT
Definition: guc.h:208
static struct config_generic ** guc_variables
Definition: guc.c:4565
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:6039
CommandDest whereToSendOutput
Definition: postgres.c:90
static bool reporting_enabled
Definition: guc.c:4579
ProtocolVersion FrontendProtocol
Definition: globals.c:28

◆ build_guc_variables()

void build_guc_variables ( void  )

Definition at line 4832 of file guc.c.

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

Referenced by GucInfoMain(), and InitializeGUCOptions().

4833 {
4834  int size_vars;
4835  int num_vars = 0;
4836  int num_explain_vars = 0;
4837  struct config_generic **guc_vars;
4838  int i;
4839 
4840  for (i = 0; ConfigureNamesBool[i].gen.name; i++)
4841  {
4842  struct config_bool *conf = &ConfigureNamesBool[i];
4843 
4844  /* Rather than requiring vartype to be filled in by hand, do this: */
4845  conf->gen.vartype = PGC_BOOL;
4846  num_vars++;
4847 
4848  if (conf->gen.flags & GUC_EXPLAIN)
4849  num_explain_vars++;
4850  }
4851 
4852  for (i = 0; ConfigureNamesInt[i].gen.name; i++)
4853  {
4854  struct config_int *conf = &ConfigureNamesInt[i];
4855 
4856  conf->gen.vartype = PGC_INT;
4857  num_vars++;
4858 
4859  if (conf->gen.flags & GUC_EXPLAIN)
4860  num_explain_vars++;
4861  }
4862 
4863  for (i = 0; ConfigureNamesReal[i].gen.name; i++)
4864  {
4865  struct config_real *conf = &ConfigureNamesReal[i];
4866 
4867  conf->gen.vartype = PGC_REAL;
4868  num_vars++;
4869 
4870  if (conf->gen.flags & GUC_EXPLAIN)
4871  num_explain_vars++;
4872  }
4873 
4874  for (i = 0; ConfigureNamesString[i].gen.name; i++)
4875  {
4876  struct config_string *conf = &ConfigureNamesString[i];
4877 
4878  conf->gen.vartype = PGC_STRING;
4879  num_vars++;
4880 
4881  if (conf->gen.flags & GUC_EXPLAIN)
4882  num_explain_vars++;
4883  }
4884 
4885  for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
4886  {
4887  struct config_enum *conf = &ConfigureNamesEnum[i];
4888 
4889  conf->gen.vartype = PGC_ENUM;
4890  num_vars++;
4891 
4892  if (conf->gen.flags & GUC_EXPLAIN)
4893  num_explain_vars++;
4894  }
4895 
4896  /*
4897  * Create table with 20% slack
4898  */
4899  size_vars = num_vars + num_vars / 4;
4900 
4901  guc_vars = (struct config_generic **)
4902  guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
4903 
4904  num_vars = 0;
4905 
4906  for (i = 0; ConfigureNamesBool[i].gen.name; i++)
4907  guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
4908 
4909  for (i = 0; ConfigureNamesInt[i].gen.name; i++)
4910  guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
4911 
4912  for (i = 0; ConfigureNamesReal[i].gen.name; i++)
4913  guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
4914 
4915  for (i = 0; ConfigureNamesString[i].gen.name; i++)
4916  guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
4917 
4918  for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
4919  guc_vars[num_vars++] = &ConfigureNamesEnum[i].gen;
4920 
4921  if (guc_variables)
4923  guc_variables = guc_vars;
4924  num_guc_variables = num_vars;
4925  num_guc_explain_variables = num_explain_vars;
4926  size_guc_variables = size_vars;
4928  sizeof(struct config_generic *), guc_var_compare);
4929 }
static struct config_int ConfigureNamesInt[]
Definition: guc.c:1962
const char * name
Definition: guc_tables.h:149
static struct config_enum ConfigureNamesEnum[]
Definition: guc.c:4209
static struct config_bool ConfigureNamesBool[]
Definition: guc.c:881
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:5071
static int num_guc_variables
Definition: guc.c:4568
#define FATAL
Definition: elog.h:52
struct config_generic gen
Definition: guc_tables.h:182
struct config_generic gen
Definition: guc_tables.h:196
#define GUC_EXPLAIN
Definition: guc.h:230
static struct config_generic ** guc_variables
Definition: guc.c:4565
enum config_type vartype
Definition: guc_tables.h:156
static int size_guc_variables
Definition: guc.c:4574
static struct config_real ConfigureNamesReal[]
Definition: guc.c:3204
struct config_generic gen
Definition: guc_tables.h:242
struct config_generic gen
Definition: guc_tables.h:228
#define free(a)
Definition: header.h:65
static int num_guc_explain_variables
Definition: guc.c:4571
static struct config_string ConfigureNamesString[]
Definition: guc.c:3452
int i
#define qsort(a, b, c, d)
Definition: port.h:492
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4609
struct config_generic gen
Definition: guc_tables.h:212

◆ call_bool_check_hook()

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

Definition at line 10719 of file guc.c.

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

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

10721 {
10722  /* Quick success if no hook */
10723  if (!conf->check_hook)
10724  return true;
10725 
10726  /* Reset variables that might be set by hook */
10727  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
10728  GUC_check_errmsg_string = NULL;
10730  GUC_check_errhint_string = NULL;
10731 
10732  if (!conf->check_hook(newval, extra, source))
10733  {
10734  ereport(elevel,
10738  errmsg("invalid value for parameter \"%s\": %d",
10739  conf->gen.name, (int) *newval),
10743  errhint("%s", GUC_check_errhint_string) : 0));
10744  /* Flush any strings created in ErrorContext */
10745  FlushErrorState();
10746  return false;
10747  }
10748 
10749  return true;
10750 }
char * GUC_check_errhint_string
Definition: guc.c:139
GucSource source
Definition: guc_tables.h:158
int errhint(const char *fmt,...)
Definition: elog.c:974
const char * name
Definition: guc_tables.h:149
int errcode(int sqlerrcode)
Definition: elog.c:570
static int GUC_check_errcode_value
Definition: guc.c:134
void FlushErrorState(void)
Definition: elog.c:1574
int errdetail_internal(const char *fmt,...)
Definition: elog.c:887
struct config_generic gen
Definition: guc_tables.h:182
char * GUC_check_errdetail_string
Definition: guc.c:138
#define ereport(elevel, rest)
Definition: elog.h:141
static int elevel
Definition: vacuumlazy.c:143
GucBoolCheckHook check_hook
Definition: guc_tables.h:186
int errmsg_internal(const char *fmt,...)
Definition: elog.c:814
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:137
int errmsg(const char *fmt,...)
Definition: elog.c:784

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

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

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

10857 {
10858  /* Quick success if no hook */
10859  if (!conf->check_hook)
10860  return true;
10861 
10862  /* Reset variables that might be set by hook */
10863  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
10864  GUC_check_errmsg_string = NULL;
10866  GUC_check_errhint_string = NULL;
10867 
10868  if (!conf->check_hook(newval, extra, source))
10869  {
10870  ereport(elevel,
10874  errmsg("invalid value for parameter \"%s\": \"%s\"",
10875  conf->gen.name,
10880  errhint("%s", GUC_check_errhint_string) : 0));
10881  /* Flush any strings created in ErrorContext */
10882  FlushErrorState();
10883  return false;
10884  }
10885 
10886  return true;
10887 }
char * GUC_check_errhint_string
Definition: guc.c:139
GucSource source
Definition: guc_tables.h:158
GucEnumCheckHook check_hook
Definition: guc_tables.h:247
int errhint(const char *fmt,...)
Definition: elog.c:974
const char * name
Definition: guc_tables.h:149
int errcode(int sqlerrcode)
Definition: elog.c:570
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:6418
static int GUC_check_errcode_value
Definition: guc.c:134
void FlushErrorState(void)
Definition: elog.c:1574
int errdetail_internal(const char *fmt,...)
Definition: elog.c:887
char * GUC_check_errdetail_string
Definition: guc.c:138
#define ereport(elevel, rest)
Definition: elog.h:141
static int elevel
Definition: vacuumlazy.c:143
struct config_generic gen
Definition: guc_tables.h:242
int errmsg_internal(const char *fmt,...)
Definition: elog.c:814
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:137
int errmsg(const char *fmt,...)
Definition: elog.c:784

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

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

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

10755 {
10756  /* Quick success if no hook */
10757  if (!conf->check_hook)
10758  return true;
10759 
10760  /* Reset variables that might be set by hook */
10761  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
10762  GUC_check_errmsg_string = NULL;
10764  GUC_check_errhint_string = NULL;
10765 
10766  if (!conf->check_hook(newval, extra, source))
10767  {
10768  ereport(elevel,
10772  errmsg("invalid value for parameter \"%s\": %d",
10773  conf->gen.name, *newval),
10777  errhint("%s", GUC_check_errhint_string) : 0));
10778  /* Flush any strings created in ErrorContext */
10779  FlushErrorState();
10780  return false;
10781  }
10782 
10783  return true;
10784 }
char * GUC_check_errhint_string
Definition: guc.c:139
GucSource source
Definition: guc_tables.h:158
int errhint(const char *fmt,...)
Definition: elog.c:974
const char * name
Definition: guc_tables.h:149
int errcode(int sqlerrcode)
Definition: elog.c:570
static int GUC_check_errcode_value
Definition: guc.c:134
GucIntCheckHook check_hook
Definition: guc_tables.h:202
void FlushErrorState(void)
Definition: elog.c:1574
int errdetail_internal(const char *fmt,...)
Definition: elog.c:887
struct config_generic gen
Definition: guc_tables.h:196
char * GUC_check_errdetail_string
Definition: guc.c:138
#define ereport(elevel, rest)
Definition: elog.h:141
static int elevel
Definition: vacuumlazy.c:143
int errmsg_internal(const char *fmt,...)
Definition: elog.c:814
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:137
int errmsg(const char *fmt,...)
Definition: elog.c:784

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

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

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

10789 {
10790  /* Quick success if no hook */
10791  if (!conf->check_hook)
10792  return true;
10793 
10794  /* Reset variables that might be set by hook */
10795  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
10796  GUC_check_errmsg_string = NULL;
10798  GUC_check_errhint_string = NULL;
10799 
10800  if (!conf->check_hook(newval, extra, source))
10801  {
10802  ereport(elevel,
10806  errmsg("invalid value for parameter \"%s\": %g",
10807  conf->gen.name, *newval),
10811  errhint("%s", GUC_check_errhint_string) : 0));
10812  /* Flush any strings created in ErrorContext */
10813  FlushErrorState();
10814  return false;
10815  }
10816 
10817  return true;
10818 }
char * GUC_check_errhint_string
Definition: guc.c:139
GucSource source
Definition: guc_tables.h:158
int errhint(const char *fmt,...)
Definition: elog.c:974
const char * name
Definition: guc_tables.h:149
int errcode(int sqlerrcode)
Definition: elog.c:570
static int GUC_check_errcode_value
Definition: guc.c:134
GucRealCheckHook check_hook
Definition: guc_tables.h:218
void FlushErrorState(void)
Definition: elog.c:1574
int errdetail_internal(const char *fmt,...)
Definition: elog.c:887
char * GUC_check_errdetail_string
Definition: guc.c:138
#define ereport(elevel, rest)
Definition: elog.h:141
static int elevel
Definition: vacuumlazy.c:143
int errmsg_internal(const char *fmt,...)
Definition: elog.c:814
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:137
int errmsg(const char *fmt,...)
Definition: elog.c:784
struct config_generic gen
Definition: guc_tables.h:212

◆ call_string_check_hook()

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

Definition at line 10821 of file guc.c.

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

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

10823 {
10824  /* Quick success if no hook */
10825  if (!conf->check_hook)
10826  return true;
10827 
10828  /* Reset variables that might be set by hook */
10829  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
10830  GUC_check_errmsg_string = NULL;
10832  GUC_check_errhint_string = NULL;
10833 
10834  if (!conf->check_hook(newval, extra, source))
10835  {
10836  ereport(elevel,
10840  errmsg("invalid value for parameter \"%s\": \"%s\"",
10841  conf->gen.name, *newval ? *newval : ""),
10845  errhint("%s", GUC_check_errhint_string) : 0));
10846  /* Flush any strings created in ErrorContext */
10847  FlushErrorState();
10848  return false;
10849  }
10850 
10851  return true;
10852 }
char * GUC_check_errhint_string
Definition: guc.c:139
GucSource source
Definition: guc_tables.h:158
int errhint(const char *fmt,...)
Definition: elog.c:974
const char * name
Definition: guc_tables.h:149
GucStringCheckHook check_hook
Definition: guc_tables.h:232
int errcode(int sqlerrcode)
Definition: elog.c:570
static int GUC_check_errcode_value
Definition: guc.c:134
void FlushErrorState(void)
Definition: elog.c:1574
int errdetail_internal(const char *fmt,...)
Definition: elog.c:887
char * GUC_check_errdetail_string
Definition: guc.c:138
#define ereport(elevel, rest)
Definition: elog.h:141
static int elevel
Definition: vacuumlazy.c:143
struct config_generic gen
Definition: guc_tables.h:228
int errmsg_internal(const char *fmt,...)
Definition: elog.c:814
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:137
int errmsg(const char *fmt,...)
Definition: elog.c:784

◆ can_skip_gucvar()

static bool can_skip_gucvar ( struct config_generic gconf)
static

Definition at line 9899 of file guc.c.

References config_generic::context, config_generic::name, PGC_INTERNAL, PGC_POSTMASTER, PGC_S_DEFAULT, and config_generic::source.

Referenced by estimate_variable_size(), RestoreGUCState(), and serialize_variable().

9900 {
9901  return gconf->context == PGC_POSTMASTER ||
9902  gconf->context == PGC_INTERNAL || gconf->source == PGC_S_DEFAULT ||
9903  strcmp(gconf->name, "role") == 0;
9904 }
GucSource source
Definition: guc_tables.h:158
const char * name
Definition: guc_tables.h:149
GucContext context
Definition: guc_tables.h:150

◆ check_application_name()

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

Definition at line 11414 of file guc.c.

References pg_clean_ascii().

11415 {
11416  /* Only allow clean ASCII chars in the application name */
11418 
11419  return true;
11420 }
#define newval
void pg_clean_ascii(char *str)
Definition: string.c:82

◆ check_autovacuum_max_workers()

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

Definition at line 11300 of file guc.c.

References MAX_BACKENDS, max_wal_senders, max_worker_processes, and MaxConnections.

11301 {
11302  if (MaxConnections + *newval + 1 +
11304  return false;
11305  return true;
11306 }
#define MAX_BACKENDS
Definition: postmaster.h:75
int max_wal_senders
Definition: walsender.c:120
int MaxConnections
Definition: globals.c:132
#define newval
int max_worker_processes
Definition: globals.c:133

◆ check_autovacuum_work_mem()

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

Definition at line 11318 of file guc.c.

11319 {
11320  /*
11321  * -1 indicates fallback.
11322  *
11323  * If we haven't yet changed the boot_val default of -1, just let it be.
11324  * Autovacuum will look to maintenance_work_mem instead.
11325  */
11326  if (*newval == -1)
11327  return true;
11328 
11329  /*
11330  * We clamp manually-set values to at least 1MB. Since
11331  * maintenance_work_mem is always set to at least this value, do the same
11332  * here.
11333  */
11334  if (*newval < 1024)
11335  *newval = 1024;
11336 
11337  return true;
11338 }
#define newval

◆ check_bonjour()

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

Definition at line 11083 of file guc.c.

References GUC_check_errmsg.

11084 {
11085 #ifndef USE_BONJOUR
11086  if (*newval)
11087  {
11088  GUC_check_errmsg("Bonjour is not supported by this build");
11089  return false;
11090  }
11091 #endif
11092  return true;
11093 }
#define GUC_check_errmsg
Definition: guc.h:405
#define newval

◆ check_canonical_path()

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

Definition at line 11134 of file guc.c.

References canonicalize_path().

11135 {
11136  /*
11137  * Since canonicalize_path never enlarges the string, we can just modify
11138  * newval in-place. But watch out for NULL, which is the default value
11139  * for external_pid_file.
11140  */
11141  if (*newval)
11143  return true;
11144 }
void canonicalize_path(char *path)
Definition: path.c:254
#define newval

◆ check_cluster_name()

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

Definition at line 11430 of file guc.c.

References pg_clean_ascii().

11431 {
11432  /* Only allow clean ASCII chars in the cluster name */
11434 
11435  return true;
11436 }
#define newval
void pg_clean_ascii(char *str)
Definition: string.c:82

◆ check_default_with_oids()

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

Definition at line 11733 of file guc.c.

References GUC_check_errcode(), and GUC_check_errmsg.

11734 {
11735  if (*newval)
11736  {
11737  /* check the GUC's definition for an explanation */
11738  GUC_check_errcode(ERRCODE_FEATURE_NOT_SUPPORTED);
11739  GUC_check_errmsg("tables declared WITH OIDS are not supported");
11740 
11741  return false;
11742  }
11743 
11744  return true;
11745 }
#define GUC_check_errmsg
Definition: guc.h:405
void GUC_check_errcode(int sqlerrcode)
Definition: guc.c:10706
#define newval

◆ check_effective_io_concurrency()

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

Definition at line 11350 of file guc.c.

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

11351 {
11352 #ifdef USE_PREFETCH
11353  double new_prefetch_pages;
11354 
11355  if (ComputeIoConcurrency(*newval, &new_prefetch_pages))
11356  {
11357  int *myextra = (int *) guc_malloc(ERROR, sizeof(int));
11358 
11359  *myextra = (int) rint(new_prefetch_pages);
11360  *extra = (void *) myextra;
11361 
11362  return true;
11363  }
11364  else
11365  return false;
11366 #else
11367  if (*newval != 0)
11368  {
11369  GUC_check_errdetail("effective_io_concurrency must be set to 0 on platforms that lack posix_fadvise().");
11370  return false;
11371  }
11372  return true;
11373 #endif /* USE_PREFETCH */
11374 }
#define GUC_check_errdetail
Definition: guc.h:409
bool ComputeIoConcurrency(int io_concurrency, double *target)
Definition: bufmgr.c:469
#define ERROR
Definition: elog.h:43
double rint(double x)
Definition: rint.c:21
#define newval
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4609

◆ check_log_destination()

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

Definition at line 10975 of file guc.c.

References ERROR, GUC_check_errdetail, guc_malloc(), lfirst, list_free(), LOG_DESTINATION_CSVLOG, LOG_DESTINATION_EVENTLOG, LOG_DESTINATION_STDERR, LOG_DESTINATION_SYSLOG, pfree(), pg_strcasecmp(), pstrdup(), and SplitIdentifierString().

10976 {
10977  char *rawstring;
10978  List *elemlist;
10979  ListCell *l;
10980  int newlogdest = 0;
10981  int *myextra;
10982 
10983  /* Need a modifiable copy of string */
10984  rawstring = pstrdup(*newval);
10985 
10986  /* Parse string into list of identifiers */
10987  if (!SplitIdentifierString(rawstring, ',', &elemlist))
10988  {
10989  /* syntax error in list */
10990  GUC_check_errdetail("List syntax is invalid.");
10991  pfree(rawstring);
10992  list_free(elemlist);
10993  return false;
10994  }
10995 
10996  foreach(l, elemlist)
10997  {
10998  char *tok = (char *) lfirst(l);
10999 
11000  if (pg_strcasecmp(tok, "stderr") == 0)
11001  newlogdest |= LOG_DESTINATION_STDERR;
11002  else if (pg_strcasecmp(tok, "csvlog") == 0)
11003  newlogdest |= LOG_DESTINATION_CSVLOG;
11004 #ifdef HAVE_SYSLOG
11005  else if (pg_strcasecmp(tok, "syslog") == 0)
11006  newlogdest |= LOG_DESTINATION_SYSLOG;
11007 #endif
11008 #ifdef WIN32
11009  else if (pg_strcasecmp(tok, "eventlog") == 0)
11010  newlogdest |= LOG_DESTINATION_EVENTLOG;
11011 #endif
11012  else
11013  {
11014  GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
11015  pfree(rawstring);
11016  list_free(elemlist);
11017  return false;
11018  }
11019  }
11020 
11021  pfree(rawstring);
11022  list_free(elemlist);
11023 
11024  myextra = (int *) guc_malloc(ERROR, sizeof(int));
11025  *myextra = newlogdest;
11026  *extra = (void *) myextra;
11027 
11028  return true;
11029 }
#define LOG_DESTINATION_EVENTLOG
Definition: elog.h:414
#define GUC_check_errdetail
Definition: guc.h:409
char * pstrdup(const char *in)
Definition: mcxt.c:1186
#define LOG_DESTINATION_SYSLOG
Definition: elog.h:413
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
void pfree(void *pointer)
Definition: mcxt.c:1056
#define ERROR
Definition: elog.h:43
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3644
#define LOG_DESTINATION_CSVLOG
Definition: elog.h:415
#define LOG_DESTINATION_STDERR
Definition: elog.h:412
#define lfirst(lc)
Definition: pg_list.h:190
#define newval
void list_free(List *list)
Definition: list.c:1377
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4609
Definition: pg_list.h:50

◆ check_log_stats()

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

Definition at line 11120 of file guc.c.

References GUC_check_errdetail.

11121 {
11122  if (*newval &&
11124  {
11125  GUC_check_errdetail("Cannot enable \"log_statement_stats\" when "
11126  "\"log_parser_stats\", \"log_planner_stats\", "
11127  "or \"log_executor_stats\" is true.");
11128  return false;
11129  }
11130  return true;
11131 }
bool log_parser_stats
Definition: guc.c:491
#define GUC_check_errdetail
Definition: guc.h:409
#define newval
bool log_executor_stats
Definition: guc.c:493
bool log_planner_stats
Definition: guc.c:492

◆ check_max_wal_senders()

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

Definition at line 11309 of file guc.c.

References autovacuum_max_workers, MAX_BACKENDS, max_worker_processes, and MaxConnections.

11310 {
11313  return false;
11314  return true;
11315 }
#define MAX_BACKENDS
Definition: postmaster.h:75
int MaxConnections
Definition: globals.c:132
int autovacuum_max_workers
Definition: autovacuum.c:114
#define newval
int max_worker_processes
Definition: globals.c:133

◆ check_max_worker_processes()

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

Definition at line 11341 of file guc.c.

References autovacuum_max_workers, MAX_BACKENDS, max_wal_senders, and MaxConnections.

11342 {
11345  return false;
11346  return true;
11347 }
#define MAX_BACKENDS
Definition: postmaster.h:75
int max_wal_senders
Definition: walsender.c:120
int MaxConnections
Definition: globals.c:132
int autovacuum_max_workers
Definition: autovacuum.c:114
#define newval

◆ check_maxconnections()

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

Definition at line 11291 of file guc.c.

References autovacuum_max_workers, MAX_BACKENDS, max_wal_senders, and max_worker_processes.

11292 {
11293  if (*newval + autovacuum_max_workers + 1 +
11295  return false;
11296  return true;
11297 }
#define MAX_BACKENDS
Definition: postmaster.h:75
int max_wal_senders
Definition: walsender.c:120
int autovacuum_max_workers
Definition: autovacuum.c:114
#define newval
int max_worker_processes
Definition: globals.c:133

◆ check_primary_slot_name()

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

Definition at line 11723 of file guc.c.

References ReplicationSlotValidateName(), and WARNING.

11724 {
11725  if (*newval && strcmp(*newval, "") != 0 &&
11727  return false;
11728 
11729  return true;
11730 }
bool ReplicationSlotValidateName(const char *name, int elevel)
Definition: slot.c:174
#define WARNING
Definition: elog.h:40
#define newval

◆ check_recovery_target()

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

Definition at line 11528 of file guc.c.

References GUC_check_errdetail.

11529 {
11530  if (strcmp(*newval, "immediate") != 0 && strcmp(*newval, "") != 0)
11531  {
11532  GUC_check_errdetail("The only allowed value is \"immediate\".");
11533  return false;
11534  }
11535  return true;
11536 }
#define GUC_check_errdetail
Definition: guc.h:409
#define newval

◆ check_recovery_target_lsn()

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

Definition at line 11687 of file guc.c.

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

11688 {
11689  if (strcmp(*newval, "") != 0)
11690  {
11691  XLogRecPtr lsn;
11692  XLogRecPtr *myextra;
11693  bool have_error = false;
11694 
11695  lsn = pg_lsn_in_internal(*newval, &have_error);
11696  if (have_error)
11697  return false;
11698 
11699  myextra = (XLogRecPtr *) guc_malloc(ERROR, sizeof(XLogRecPtr));
11700  *myextra = lsn;
11701  *extra = (void *) myextra;
11702  }
11703  return true;
11704 }
#define ERROR
Definition: elog.h:43
XLogRecPtr pg_lsn_in_internal(const char *str, bool *have_error)
Definition: pg_lsn.c:29
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define newval
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4609

◆ check_recovery_target_name()

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

Definition at line 11658 of file guc.c.

References GUC_check_errdetail, and MAXFNAMELEN.

11659 {
11660  /* Use the value of newval directly */
11661  if (strlen(*newval) >= MAXFNAMELEN)
11662  {
11663  GUC_check_errdetail("%s is too long (maximum %d characters).",
11664  "recovery_target_name", MAXFNAMELEN - 1);
11665  return false;
11666  }
11667  return true;
11668 }
#define GUC_check_errdetail
Definition: guc.h:409
#define MAXFNAMELEN
#define newval

◆ check_recovery_target_time()

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

Definition at line 11595 of file guc.c.

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

11596 {
11597  if (strcmp(*newval, "") != 0)
11598  {
11599  /* reject some special values */
11600  if (strcmp(*newval, "now") == 0 ||
11601  strcmp(*newval, "today") == 0 ||
11602  strcmp(*newval, "tomorrow") == 0 ||
11603  strcmp(*newval, "yesterday") == 0)
11604  {
11605  return false;
11606  }
11607 
11608  /*
11609  * parse timestamp value (see also timestamptz_in())
11610  */
11611  {
11612  char *str = *newval;
11613  fsec_t fsec;
11614  struct pg_tm tt,
11615  *tm = &tt;
11616  int tz;
11617  int dtype;
11618  int nf;
11619  int dterr;
11620  char *field[MAXDATEFIELDS];
11621  int ftype[MAXDATEFIELDS];
11622  char workbuf[MAXDATELEN + MAXDATEFIELDS];
11624 
11625  dterr = ParseDateTime(str, workbuf, sizeof(workbuf),
11626  field, ftype, MAXDATEFIELDS, &nf);
11627  if (dterr == 0)
11628  dterr = DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tz);
11629  if (dterr != 0)
11630  return false;
11631  if (dtype != DTK_DATE)
11632  return false;
11633 
11634  if (tm2timestamp(tm, fsec, &tz, &timestamp) != 0)
11635  {
11636  GUC_check_errdetail("timestamp out of range: \"%s\"", str);
11637  return false;
11638  }
11639  }
11640  }
11641  return true;
11642 }
#define MAXDATELEN
Definition: datetime.h:201
#define GUC_check_errdetail
Definition: guc.h:409
int64 timestamp
int64 TimestampTz
Definition: timestamp.h:39
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:108
int DecodeDateTime(char **field, int *ftype, int nf, int *dtype, struct pg_tm *tm, fsec_t *fsec, int *tzp)
Definition: datetime.c:761
int32 fsec_t
Definition: timestamp.h:41
int tm2timestamp(struct pg_tm *tm, fsec_t fsec, int *tzp, Timestamp *result)
Definition: timestamp.c:1887
#define MAXDATEFIELDS
Definition: datetime.h:203
#define newval
int ParseDateTime(const char *timestr, char *workbuf, size_t buflen, char **field, int *ftype, int maxfields, int *numfields)
Definition: datetime.c:540
#define DTK_DATE
Definition: datetime.h:145

◆ check_recovery_target_timeline()

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

Definition at line 11466 of file guc.c.

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

11467 {
11469  RecoveryTargetTimeLineGoal *myextra;
11470 
11471  if (strcmp(*newval, "current") == 0)
11473  else if (strcmp(*newval, "latest") == 0)
11475  else
11476  {
11478 
11479  errno = 0;
11480  strtoul(*newval, NULL, 0);
11481  if (errno == EINVAL || errno == ERANGE)
11482  {
11483  GUC_check_errdetail("recovery_target_timeline is not a valid number.");
11484  return false;
11485  }
11486  }
11487 
11489  *myextra = rttg;
11490  *extra = (void *) myextra;
11491 
11492  return true;
11493 }
#define GUC_check_errdetail
Definition: guc.h:409
RecoveryTargetTimeLineGoal
Definition: xlog.h:93
#define ERROR
Definition: elog.h:43
#define newval
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4609

◆ check_recovery_target_xid()

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

Definition at line 11552 of file guc.c.

References ERROR, and guc_malloc().

11553 {
11554  if (strcmp(*newval, "") != 0)
11555  {
11556  TransactionId xid;
11557  TransactionId *myextra;
11558 
11559  errno = 0;
11560  xid = (TransactionId) strtoul(*newval, NULL, 0);
11561  if (errno == EINVAL || errno == ERANGE)
11562  return false;
11563 
11564  myextra = (TransactionId *) guc_malloc(ERROR, sizeof(TransactionId));
11565  *myextra = xid;
11566  *extra = (void *) myextra;
11567  }
11568  return true;
11569 }
uint32 TransactionId
Definition: c.h:507
#define ERROR
Definition: elog.h:43
#define newval
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4609

◆ check_ssl()

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

Definition at line 11096 of file guc.c.

References GUC_check_errmsg.

11097 {
11098 #ifndef USE_SSL
11099  if (*newval)
11100  {
11101  GUC_check_errmsg("SSL is not supported by this build");
11102  return false;
11103  }
11104 #endif
11105  return true;
11106 }
#define GUC_check_errmsg
Definition: guc.h:405
#define newval

◆ check_stage_log_stats()

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

Definition at line 11109 of file guc.c.

References GUC_check_errdetail.

11110 {
11111  if (*newval && log_statement_stats)
11112  {
11113  GUC_check_errdetail("Cannot enable parameter when \"log_statement_stats\" is true.");
11114  return false;
11115  }
11116  return true;
11117 }
bool log_statement_stats
Definition: guc.c:494
#define GUC_check_errdetail
Definition: guc.h:409
#define newval

◆ check_temp_buffers()

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

Definition at line 11069 of file guc.c.

References GUC_check_errdetail, and NLocBuffer.

11070 {
11071  /*
11072  * Once local buffers have been initialized, it's too late to change this.
11073  */
11074  if (NLocBuffer && NLocBuffer != *newval)
11075  {
11076  GUC_check_errdetail("\"temp_buffers\" cannot be changed after any temporary tables have been accessed in the session.");
11077  return false;
11078  }
11079  return true;
11080 }
#define GUC_check_errdetail
Definition: guc.h:409
int NLocBuffer
Definition: localbuf.c:41
#define newval

◆ check_timezone_abbreviations()

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

Definition at line 11147 of file guc.c.

References Assert, load_tzoffsets(), and PGC_S_DEFAULT.

11148 {
11149  /*
11150  * The boot_val given above for timezone_abbreviations is NULL. When we
11151  * see this we just do nothing. If this value isn't overridden from the
11152  * config file then pg_timezone_abbrev_initialize() will eventually
11153  * replace it with "Default". This hack has two purposes: to avoid
11154  * wasting cycles loading values that might soon be overridden from the
11155  * config file, and to avoid trying to read the timezone abbrev files
11156  * during InitializeGUCOptions(). The latter doesn't work in an
11157  * EXEC_BACKEND subprocess because my_exec_path hasn't been set yet and so
11158  * we can't locate PGSHAREDIR.
11159  */
11160  if (*newval == NULL)
11161  {
11162  Assert(source == PGC_S_DEFAULT);
11163  return true;
11164  }
11165 
11166  /* OK, load the file and produce a malloc'd TimeZoneAbbrevTable */
11167  *extra = load_tzoffsets(*newval);
11168 
11169  /* tzparser.c returns NULL on failure, reporting via GUC_check_errmsg */
11170  if (!*extra)
11171  return false;
11172 
11173  return true;
11174 }
TimeZoneAbbrevTable * load_tzoffsets(const char *filename)
Definition: tzparser.c:437
#define Assert(condition)
Definition: c.h:732
#define newval

◆ check_wal_consistency_checking()

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

Definition at line 10895 of file guc.c.

References ERROR, GUC_check_errdetail, guc_malloc(), lfirst, list_free(), MemSet, pfree(), pg_strcasecmp(), pstrdup(), RmgrData::rm_mask, RM_MAX_ID, RmgrTable, and SplitIdentifierString().

10896 {
10897  char *rawstring;
10898  List *elemlist;
10899  ListCell *l;
10900  bool newwalconsistency[RM_MAX_ID + 1];
10901 
10902  /* Initialize the array */
10903  MemSet(newwalconsistency, 0, (RM_MAX_ID + 1) * sizeof(bool));
10904 
10905  /* Need a modifiable copy of string */
10906  rawstring = pstrdup(*newval);
10907 
10908  /* Parse string into list of identifiers */
10909  if (!SplitIdentifierString(rawstring, ',', &elemlist))
10910  {
10911  /* syntax error in list */
10912  GUC_check_errdetail("List syntax is invalid.");
10913  pfree(rawstring);
10914  list_free(elemlist);
10915  return false;
10916  }
10917 
10918  foreach(l, elemlist)
10919  {
10920  char *tok = (char *) lfirst(l);
10921  bool found = false;
10922  RmgrId rmid;
10923 
10924  /* Check for 'all'. */
10925  if (pg_strcasecmp(tok, "all") == 0)
10926  {
10927  for (rmid = 0; rmid <= RM_MAX_ID; rmid++)
10928  if (RmgrTable[rmid].rm_mask != NULL)
10929  newwalconsistency[rmid] = true;
10930  found = true;
10931  }
10932  else
10933  {
10934  /*
10935  * Check if the token matches with any individual resource
10936  * manager.
10937  */
10938  for (rmid = 0; rmid <= RM_MAX_ID; rmid++)
10939  {
10940  if (pg_strcasecmp(tok, RmgrTable[rmid].rm_name) == 0 &&
10941  RmgrTable[rmid].rm_mask != NULL)
10942  {
10943  newwalconsistency[rmid] = true;
10944  found = true;
10945  }
10946  }
10947  }
10948 
10949  /* If a valid resource manager is found, check for the next one. */
10950  if (!found)
10951  {
10952  GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
10953  pfree(rawstring);
10954  list_free(elemlist);
10955  return false;
10956  }
10957  }
10958 
10959  pfree(rawstring);
10960  list_free(elemlist);
10961 
10962  /* assign new value */
10963  *extra = guc_malloc(ERROR, (RM_MAX_ID + 1) * sizeof(bool));
10964  memcpy(*extra, newwalconsistency, (RM_MAX_ID + 1) * sizeof(bool));
10965  return true;
10966 }
#define GUC_check_errdetail
Definition: guc.h:409
char * pstrdup(const char *in)
Definition: mcxt.c:1186
const RmgrData RmgrTable[RM_MAX_ID+1]
Definition: rmgr.c:36
#define MemSet(start, val, len)
Definition: c.h:955
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
void pfree(void *pointer)
Definition: mcxt.c:1056
#define ERROR
Definition: elog.h:43
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3644
#define RM_MAX_ID
Definition: rmgr.h:33
void(* rm_mask)(char *pagedata, BlockNumber blkno)
uint8 RmgrId
Definition: rmgr.h:11
#define lfirst(lc)
Definition: pg_list.h:190
#define newval
void list_free(List *list)
Definition: list.c:1377
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4609
Definition: pg_list.h:50

◆ config_enum_get_options()

static char* config_enum_get_options ( struct config_enum record,
const char *  prefix,
const char *  suffix,
const char *  separator 
)
static

Definition at line 6467 of file guc.c.

References appendBinaryStringInfo(), appendStringInfoString(), StringInfoData::data, config_enum_entry::hidden, initStringInfo(), StringInfoData::len, config_enum_entry::name, and config_enum::options.

Referenced by GetConfigOptionByNum(), and parse_and_validate_value().

6469 {
6470  const struct config_enum_entry *entry;
6471  StringInfoData retstr;
6472  int seplen;
6473 
6474  initStringInfo(&retstr);
6475  appendStringInfoString(&retstr, prefix);
6476 
6477  seplen = strlen(separator);
6478  for (entry = record->options; entry && entry->name; entry++)
6479  {
6480  if (!entry->hidden)
6481  {
6482  appendStringInfoString(&retstr, entry->name);
6483  appendBinaryStringInfo(&retstr, separator, seplen);
6484  }
6485  }
6486 
6487  /*
6488  * All the entries may have been hidden, leaving the string empty if no
6489  * prefix was given. This indicates a broken GUC setup, since there is no
6490  * use for an enum without any values, so we just check to make sure we
6491  * don't write to invalid memory instead of actually trying to do
6492  * something smart with it.
6493  */
6494  if (retstr.len >= seplen)
6495  {
6496  /* Replace final separator */
6497  retstr.data[retstr.len - seplen] = '\0';
6498  retstr.len -= seplen;
6499  }
6500 
6501  appendStringInfoString(&retstr, suffix);
6502 
6503  return retstr.data;
6504 }
Definition: guc.h:164
const struct config_enum_entry * options
Definition: guc_tables.h:246
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:163
void initStringInfo(StringInfo str)
Definition: stringinfo.c:46
const char * name
Definition: guc.h:166
void appendBinaryStringInfo(StringInfo str, const char *data, int datalen)
Definition: stringinfo.c:214
bool hidden
Definition: guc.h:168

◆ config_enum_lookup_by_name()

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

Definition at line 6441 of file guc.c.

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

Referenced by parse_and_validate_value().

6443 {
6444  const struct config_enum_entry *entry;
6445 
6446  for (entry = record->options; entry && entry->name; entry++)
6447  {
6448  if (pg_strcasecmp(value, entry->name) == 0)
6449  {
6450  *retval = entry->val;
6451  return true;
6452  }
6453  }
6454 
6455  *retval = 0;
6456  return false;
6457 }
Definition: guc.h:164
static struct @145 value
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
const struct config_enum_entry * options
Definition: guc_tables.h:246
int val
Definition: guc.h:167
const char * name
Definition: guc.h:166

◆ config_enum_lookup_by_value()

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

Definition at line 6418 of file guc.c.

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

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

6419 {
6420  const struct config_enum_entry *entry;
6421 
6422  for (entry = record->options; entry && entry->name; entry++)
6423  {
6424  if (entry->val == val)
6425  return entry->name;
6426  }
6427 
6428  elog(ERROR, "could not find enum option %d for %s",
6429  val, record->gen.name);
6430  return NULL; /* silence compiler */
6431 }
Definition: guc.h:164
const char * name
Definition: guc_tables.h:149
#define ERROR
Definition: elog.h:43
const struct config_enum_entry * options
Definition: guc_tables.h:246
int val
Definition: guc.h:167
struct config_generic gen
Definition: guc_tables.h:242
const char * name
Definition: guc.h:166
#define elog(elevel,...)
Definition: elog.h:226
long val
Definition: informix.c:684

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

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

Referenced by _ShowOption().

6126 {
6127  const unit_conversion *table;
6128  int i;
6129 
6130  *unit = NULL;
6131 
6132  if (base_unit & GUC_UNIT_MEMORY)
6134  else
6136 
6137  for (i = 0; *table[i].unit; i++)
6138  {
6139  if (base_unit == table[i].base_unit)
6140  {
6141  /*
6142  * Accept the first conversion that divides the value evenly. We
6143  * assume that the conversions for each base unit are ordered from
6144  * greatest unit to the smallest!
6145  */
6146  if (table[i].multiplier <= 1.0 ||
6147  base_value % (int64) table[i].multiplier == 0)
6148  {
6149  *value = (int64) rint(base_value / table[i].multiplier);
6150  *unit = table[i].unit;
6151  break;
6152  }
6153  }
6154  }
6155 
6156  Assert(*unit != NULL);
6157 }
static const unit_conversion time_unit_conversion_table[]
Definition: guc.c:825
static const unit_conversion memory_unit_conversion_table[]
Definition: guc.c:788
static struct @145 value
double rint(double x)
Definition: rint.c:21
#define Assert(condition)
Definition: c.h:732
int i
char unit[MAX_UNIT_LEN+1]
Definition: guc.c:772
#define GUC_UNIT_MEMORY
Definition: guc.h:223

◆ convert_real_from_base_unit()

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

Definition at line 6166 of file guc.c.

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

Referenced by _ShowOption().

6168 {
6169  const unit_conversion *table;
6170  int i;
6171 
6172  *unit = NULL;
6173 
6174  if (base_unit & GUC_UNIT_MEMORY)
6176  else
6178 
6179  for (i = 0; *table[i].unit; i++)
6180  {
6181  if (base_unit == table[i].base_unit)
6182  {
6183  /*
6184  * Accept the first conversion that divides the value evenly; or
6185  * if there is none, use the smallest (last) target unit.
6186  *
6187  * What we actually care about here is whether snprintf with "%g"
6188  * will print the value as an integer, so the obvious test of
6189  * "*value == rint(*value)" is too strict; roundoff error might
6190  * make us choose an unreasonably small unit. As a compromise,
6191  * accept a divisor that is within 1e-8 of producing an integer.
6192  */
6193  *value = base_value / table[i].multiplier;
6194  *unit = table[i].unit;
6195  if (*value > 0 &&
6196  fabs((rint(*value) / *value) - 1.0) <= 1e-8)
6197  break;
6198  }
6199  }
6200 
6201  Assert(*unit != NULL);
6202 }
static const unit_conversion time_unit_conversion_table[]
Definition: guc.c:825
static const unit_conversion memory_unit_conversion_table[]
Definition: guc.c:788
static struct @145 value
double rint(double x)
Definition: rint.c:21
#define Assert(condition)
Definition: c.h:732
double multiplier
Definition: guc.c:775
e
Definition: preproc-init.c:82
int i
char unit[MAX_UNIT_LEN+1]
Definition: guc.c:772
#define GUC_UNIT_MEMORY
Definition: guc.h:223

◆ convert_to_base_unit()

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

Definition at line 6066 of file guc.c.

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

Referenced by parse_int(), and parse_real().

6068 {
6069  char unitstr[MAX_UNIT_LEN + 1];
6070  int unitlen;
6071  const unit_conversion *table;
6072  int i;
6073 
6074  /* extract unit string to compare to table entries */
6075  unitlen = 0;
6076  while (*unit != '\0' && !isspace((unsigned char) *unit) &&
6077  unitlen < MAX_UNIT_LEN)
6078  unitstr[unitlen++] = *(unit++);
6079  unitstr[unitlen] = '\0';
6080  /* allow whitespace after unit */
6081  while (isspace((unsigned char) *unit))
6082  unit++;
6083  if (*unit != '\0')
6084  return false; /* unit too long, or garbage after it */
6085 
6086  /* now search the appropriate table */
6087  if (base_unit & GUC_UNIT_MEMORY)
6089  else
6091 
6092  for (i = 0; *table[i].unit; i++)
6093  {
6094  if (base_unit == table[i].base_unit &&
6095  strcmp(unitstr, table[i].unit) == 0)
6096  {
6097  double cvalue = value * table[i].multiplier;
6098 
6099  /*
6100  * If the user gave a fractional value such as "30.1GB", round it
6101  * off to the nearest multiple of the next smaller unit, if there
6102  * is one.
6103  */
6104  if (*table[i + 1].unit &&
6105  base_unit == table[i + 1].base_unit)
6106  cvalue = rint(cvalue / table[i + 1].multiplier) *
6107  table[i + 1].multiplier;
6108 
6109  *base_value = cvalue;
6110  return true;
6111  }
6112  }
6113  return false;
6114 }
static const unit_conversion time_unit_conversion_table[]
Definition: guc.c:825
static const unit_conversion memory_unit_conversion_table[]
Definition: guc.c:788
#define MAX_UNIT_LEN
Definition: guc.c:768
static struct @145 value
double rint(double x)
Definition: rint.c:21
double multiplier
Definition: guc.c:775
int i
char unit[MAX_UNIT_LEN+1]
Definition: guc.c:772
#define GUC_UNIT_MEMORY
Definition: guc.h:223

◆ define_custom_variable()

static void define_custom_variable ( struct config_generic variable)
static

Definition at line 8392 of file guc.c.

References add_guc_variable(), Assert, ereport, errcode(), errmsg(), ERROR, free, config_string::gen, GUC_ACTION_SET, GUC_CUSTOM_PLACEHOLDER, guc_var_compare(), InitializeOneGUCOption(), config_generic::name, name, PGC_STRING, reapply_stacked_values(), config_generic::reset_scontext, config_generic::reset_source, config_string::reset_val, config_generic::scontext, set_config_option(), set_config_sourcefile(), set_string_field(), config_generic::source, config_generic::sourcefile, config_generic::sourceline, config_generic::stack, config_string::variable, and WARNING.

Referenced by DefineCustomBoolVariable(), DefineCustomEnumVariable(), DefineCustomIntVariable(), DefineCustomRealVariable(), and DefineCustomStringVariable().

8393 {
8394  const char *name = variable->name;
8395  const char **nameAddr = &name;
8396  struct config_string *pHolder;
8397  struct config_generic **res;
8398 
8399  /*
8400  * See if there's a placeholder by the same name.
8401  */
8402  res = (struct config_generic **) bsearch((void *) &nameAddr,
8403  (void *) guc_variables,
8405  sizeof(struct config_generic *),
8406  guc_var_compare);
8407  if (res == NULL)
8408  {
8409  /*
8410  * No placeholder to replace, so we can just add it ... but first,
8411  * make sure it's initialized to its default value.
8412  */
8413  InitializeOneGUCOption(variable);
8414  add_guc_variable(variable, ERROR);
8415  return;
8416  }
8417 
8418  /*
8419  * This better be a placeholder
8420  */
8421  if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
8422  ereport(ERROR,
8423  (errcode(ERRCODE_INTERNAL_ERROR),
8424  errmsg("attempt to redefine parameter \"%s\"", name)));
8425 
8426  Assert((*res)->vartype == PGC_STRING);
8427  pHolder = (struct config_string *) (*res);
8428 
8429  /*
8430  * First, set the variable to its default value. We must do this even
8431  * though we intend to immediately apply a new value, since it's possible
8432  * that the new value is invalid.
8433  */
8434  InitializeOneGUCOption(variable);
8435 
8436  /*
8437  * Replace the placeholder. We aren't changing the name, so no re-sorting
8438  * is necessary
8439  */
8440  *res = variable;
8441 
8442  /*
8443  * Assign the string value(s) stored in the placeholder to the real
8444  * variable. Essentially, we need to duplicate all the active and stacked
8445  * values, but with appropriate validation and datatype adjustment.
8446  *
8447  * If an assignment fails, we report a WARNING and keep going. We don't
8448  * want to throw ERROR for bad values, because it'd bollix the add-on
8449  * module that's presumably halfway through getting loaded. In such cases
8450  * the default or previous state will become active instead.
8451  */
8452 
8453  /* First, apply the reset value if any */
8454  if (pHolder->reset_val)
8455  (void) set_config_option(name, pHolder->reset_val,
8456  pHolder->gen.reset_scontext,
8457  pHolder->gen.reset_source,
8458  GUC_ACTION_SET, true, WARNING, false);
8459  /* That should not have resulted in stacking anything */
8460  Assert(variable->stack == NULL);
8461 
8462  /* Now, apply current and stacked values, in the order they were stacked */
8463  reapply_stacked_values(variable, pHolder, pHolder->gen.stack,
8464  *(pHolder->variable),
8465  pHolder->gen.scontext, pHolder->gen.source);
8466 
8467  /* Also copy over any saved source-location information */
8468  if (pHolder->gen.sourcefile)
8469  set_config_sourcefile(name, pHolder->gen.sourcefile,
8470  pHolder->gen.sourceline);
8471 
8472  /*
8473  * Free up as much as we conveniently can of the placeholder structure.
8474  * (This neglects any stack items, so it's possible for some memory to be
8475  * leaked. Since this can only happen once per session per variable, it
8476  * doesn't seem worth spending much code on.)
8477  */
8478  set_string_field(pHolder, pHolder->variable, NULL);
8479  set_string_field(pHolder, &pHolder->reset_val, NULL);
8480 
8481  free(pHolder);
8482 }
GucSource source
Definition: guc_tables.h:158
static void static void set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
Definition: guc.c:7453
char ** variable
Definition: guc_tables.h:230
const char * name
Definition: guc_tables.h:149
static void reapply_stacked_values(struct config_generic *variable, struct config_string *pHolder, GucStack *stack, const char *curvalue, GucContext curscontext, GucSource cursource)
Definition: guc.c:8492
int errcode(int sqlerrcode)
Definition: elog.c:570
GucContext scontext
Definition: guc_tables.h:160
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:5071
#define ERROR
Definition: elog.h:43
static int num_guc_variables
Definition: guc.c:4568
char * sourcefile
Definition: guc_tables.h:164
GucSource reset_source
Definition: guc_tables.h:159
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:5219
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4681
#define ereport(elevel, rest)
Definition: elog.h:141
static struct config_generic ** guc_variables
Definition: guc.c:4565
#define WARNING
Definition: elog.h:40
struct config_generic gen
Definition: guc_tables.h:228
#define free(a)
Definition: header.h:65
char * reset_val
Definition: guc_tables.h:236
#define Assert(condition)
Definition: c.h:732
#define GUC_CUSTOM_PLACEHOLDER
Definition: guc.h:211
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:784
GucStack * stack
Definition: guc_tables.h:162
int set_config_option(const char *name, const char *value, GucContext context, GucSource source, GucAction action, bool changeVal, int elevel, bool is_reload)
Definition: guc.c:6722
static bool add_guc_variable(struct config_generic *var, int elevel)
Definition: guc.c:4936
GucContext reset_scontext
Definition: guc_tables.h:161

◆ DefineCustomBoolVariable()

void DefineCustomBoolVariable ( const char *  name,
const char *  short_desc,
const char *  long_desc,
bool valueAddr,
bool  bootValue,
GucContext  context,
int  flags,
GucBoolCheckHook  check_hook,
GucBoolAssignHook  assign_hook,
GucShowHook  show_hook 
)

Definition at line 8573 of file guc.c.

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

Referenced by _PG_init().

8583 {
8584  struct config_bool *var;
8585 
8586  var = (struct config_bool *)
8587  init_custom_variable(name, short_desc, long_desc, context, flags,
8588  PGC_BOOL, sizeof(struct config_bool));
8589  var->variable = valueAddr;
8590  var->boot_val = bootValue;
8591  var->reset_val = bootValue;
8592  var->check_hook = check_hook;
8593  var->assign_hook = assign_hook;
8594  var->show_hook = show_hook;
8595  define_custom_variable(&var->gen);
8596 }
bool * variable
Definition: guc_tables.h:184
GucBoolAssignHook assign_hook
Definition: guc_tables.h:187
bool boot_val
Definition: guc_tables.h:185
struct config_generic gen
Definition: guc_tables.h:182
static struct config_generic * init_custom_variable(const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
Definition: guc.c:8332
GucBoolCheckHook check_hook
Definition: guc_tables.h:186
GucShowHook show_hook
Definition: guc_tables.h:188
const char * name
Definition: encode.c:521
bool reset_val
Definition: guc_tables.h:190
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8392

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

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

Referenced by _PG_init().

8695 {
8696  struct config_enum *var;
8697 
8698  var = (struct config_enum *)
8699  init_custom_variable(name, short_desc, long_desc, context, flags,
8700  PGC_ENUM, sizeof(struct config_enum));
8701  var->variable = valueAddr;
8702  var->boot_val = bootValue;
8703  var->reset_val = bootValue;
8704  var->options = options;
8705  var->check_hook = check_hook;
8706  var->assign_hook = assign_hook;
8707  var->show_hook = show_hook;
8708  define_custom_variable(&var->gen);
8709 }
GucEnumCheckHook check_hook
Definition: guc_tables.h:247
GucEnumAssignHook assign_hook
Definition: guc_tables.h:248
int * variable
Definition: guc_tables.h:244
const struct config_enum_entry * options
Definition: guc_tables.h:246
static char ** options
static struct config_generic * init_custom_variable(const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
Definition: guc.c:8332
GucShowHook show_hook
Definition: guc_tables.h:249
struct config_generic gen
Definition: guc_tables.h:242
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8392

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

References config_int::assign_hook, config_int::boot_val, config_int::check_hook, define_custom_variable(), config_int::gen, init_custom_variable(), config_int::max, config_int::min, PGC_INT, config_int::reset_val, config_int::show_hook, and config_int::variable.

Referenced by _PG_init().

8611 {
8612  struct config_int *var;
8613 
8614  var = (struct config_int *)
8615  init_custom_variable(name, short_desc, long_desc, context, flags,
8616  PGC_INT, sizeof(struct config_int));
8617  var->variable = valueAddr;
8618  var->boot_val = bootValue;
8619  var->reset_val = bootValue;
8620  var->min = minValue;
8621  var->max = maxValue;
8622  var->check_hook = check_hook;
8623  var->assign_hook = assign_hook;
8624  var->show_hook = show_hook;
8625  define_custom_variable(&var->gen);
8626 }
int boot_val
Definition: guc_tables.h:199
GucIntAssignHook assign_hook
Definition: guc_tables.h:203
GucIntCheckHook check_hook
Definition: guc_tables.h:202
GucShowHook show_hook
Definition: guc_tables.h:204
int * variable
Definition: guc_tables.h:198
struct config_generic gen
Definition: guc_tables.h:196
static struct config_generic * init_custom_variable(const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
Definition: guc.c:8332
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8392
int reset_val
Definition: guc_tables.h:206

◆ DefineCustomRealVariable()

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

Definition at line 8629 of file guc.c.

References config_real::assign_hook, config_real::boot_val, config_real::check_hook, define_custom_variable(), config_real::gen, init_custom_variable(), config_real::max, config_real::min, PGC_REAL, config_real::reset_val, config_real::show_hook, and config_real::variable.

Referenced by _PG_init().

8641 {
8642  struct config_real *var;
8643 
8644  var = (struct config_real *)
8645  init_custom_variable(name, short_desc, long_desc, context, flags,
8646  PGC_REAL, sizeof(struct config_real));
8647  var->variable = valueAddr;
8648  var->boot_val = bootValue;
8649  var->reset_val = bootValue;
8650  var->min = minValue;
8651  var->max = maxValue;
8652  var->check_hook = check_hook;
8653  var->assign_hook = assign_hook;
8654  var->show_hook = show_hook;
8655  define_custom_variable(&var->gen);
8656 }
GucRealAssignHook assign_hook
Definition: guc_tables.h:219
double reset_val
Definition: guc_tables.h:222
GucRealCheckHook check_hook
Definition: guc_tables.h:218
GucShowHook show_hook
Definition: guc_tables.h:220
double * variable
Definition: guc_tables.h:214
static struct config_generic * init_custom_variable(const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
Definition: guc.c:8332
double max
Definition: guc_tables.h:217
double boot_val
Definition: guc_tables.h:215
const char * name
Definition: encode.c:521
double min
Definition: guc_tables.h:216
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8392
struct config_generic gen
Definition: guc_tables.h:212

◆ DefineCustomStringVariable()

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

Definition at line 8659 of file guc.c.

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

Referenced by _PG_init().

8669 {
8670  struct config_string *var;
8671 
8672  var = (struct config_string *)
8673  init_custom_variable(name, short_desc, long_desc, context, flags,
8674  PGC_STRING, sizeof(struct config_string));
8675  var->variable = valueAddr;
8676  var->boot_val = bootValue;
8677  var->check_hook = check_hook;
8678  var->assign_hook = assign_hook;
8679  var->show_hook = show_hook;
8680  define_custom_variable(&var->gen);
8681 }
char ** variable
Definition: guc_tables.h:230
GucStringCheckHook check_hook
Definition: guc_tables.h:232
const char * boot_val
Definition: guc_tables.h:231
GucShowHook show_hook
Definition: guc_tables.h:234
static struct config_generic * init_custom_variable(const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
Definition: guc.c:8332
struct config_generic gen
Definition: guc_tables.h:228
GucStringAssignHook assign_hook
Definition: guc_tables.h:233
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:8392

◆ discard_stack_value()

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

Definition at line 4796 of file guc.c.

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

Referenced by AtEOXact_GUC(), and push_old_value().

4797 {
4798  switch (gconf->vartype)
4799  {
4800  case PGC_BOOL:
4801  case PGC_INT:
4802  case PGC_REAL:
4803  case PGC_ENUM:
4804  /* no need to do anything */
4805  break;
4806  case PGC_STRING:
4807  set_string_field((struct config_string *) gconf,
4808  &(val->val.stringval),
4809  NULL);
4810  break;
4811  }
4812  set_extra_field(gconf, &(val->extra), NULL);
4813 }
union config_var_val val
Definition: guc_tables.h:46
static void set_extra_field(struct config_generic *gconf, void **field, void *newval)
Definition: guc.c:4742
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4681
enum config_type vartype
Definition: guc_tables.h:156
char * stringval
Definition: guc_tables.h:36

◆ do_serialize()

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

Definition at line 10034 of file guc.c.

References elog, ERROR, and vsnprintf.

Referenced by serialize_variable().

10035 {
10036  va_list vargs;
10037  int n;
10038 
10039  if (*maxbytes <= 0)
10040  elog(ERROR, "not enough space to serialize GUC state");
10041 
10042  va_start(vargs, fmt);
10043  n = vsnprintf(*destptr, *maxbytes, fmt, vargs);
10044  va_end(vargs);
10045 
10046  if (n < 0)
10047  {
10048  /* Shouldn't happen. Better show errno description. */
10049  elog(ERROR, "vsnprintf failed: %m with format string \"%s\"", fmt);
10050  }
10051  if (n >= *maxbytes)
10052  {
10053  /* This shouldn't happen either, really. */
10054  elog(ERROR, "not enough space to serialize GUC state");
10055  }
10056 
10057  /* Shift the destptr ahead of the null terminator */
10058  *destptr += n + 1;
10059  *maxbytes -= n + 1;
10060 }
#define ERROR
Definition: elog.h:43
#define vsnprintf
Definition: port.h:191
#define elog(elevel,...)
Definition: elog.h:226

◆ do_serialize_binary()

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

Definition at line 10064 of file guc.c.

References elog, and ERROR.

Referenced by serialize_variable().

10065 {
10066  if (valsize > *maxbytes)
10067  elog(ERROR, "not enough space to serialize GUC state");
10068 
10069  memcpy(*destptr, val, valsize);
10070  *destptr += valsize;
10071  *maxbytes -= valsize;
10072 }
#define ERROR
Definition: elog.h:43
#define elog(elevel,...)
Definition: elog.h:226
long val
Definition: informix.c:684

◆ EmitWarningsOnPlaceholders()

void EmitWarningsOnPlaceholders ( const char *  className)

Definition at line 8712 of file guc.c.

References ereport, errcode(), errmsg(), config_generic::flags, GUC_CUSTOM_PLACEHOLDER, GUC_QUALIFIER_SEPARATOR, i, config_generic::name, num_guc_variables, and WARNING.

Referenced by _PG_init().

8713 {
8714  int classLen = strlen(className);
8715  int i;
8716 
8717  for (i = 0; i < num_guc_variables; i++)
8718  {
8719  struct config_generic *var = guc_variables[i];
8720 
8721  if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
8722  strncmp(className, var->name, classLen) == 0 &&
8723  var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
8724  {
8725  ereport(WARNING,
8726  (errcode(ERRCODE_UNDEFINED_OBJECT),
8727  errmsg("unrecognized configuration parameter \"%s\"",
8728  var->name)));
8729  }
8730  }
8731 }
const char * name
Definition: guc_tables.h:149
int errcode(int sqlerrcode)
Definition: elog.c:570
#define GUC_QUALIFIER_SEPARATOR
Definition: guc.h:199
static int num_guc_variables
Definition: guc.c:4568
#define ereport(elevel, rest)
Definition: elog.h:141
static struct config_generic ** guc_variables
Definition: guc.c:4565
#define WARNING
Definition: elog.h:40
#define GUC_CUSTOM_PLACEHOLDER
Definition: guc.h:211
int errmsg(const char *fmt,...)
Definition: elog.c:784
int i

◆ estimate_variable_size()

static Size estimate_variable_size ( struct config_generic gconf)
static

Definition at line 9913 of file guc.c.

References Abs, add_size(), can_skip_gucvar(), config_enum_lookup_by_value(), config_generic::name, PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_STRING, REALTYPE_PRECISION, config_generic::scontext, config_generic::source, config_generic::sourcefile, config_generic::sourceline, config_int::variable, config_string::variable, config_enum::variable, and config_generic::vartype.

Referenced by EstimateGUCStateSpace().

9914 {
9915  Size size;
9916  Size valsize = 0;
9917 
9918  if (can_skip_gucvar(gconf))
9919  return 0;
9920 
9921  /* Name, plus trailing zero byte. */
9922  size = strlen(gconf->name) + 1;
9923 
9924  /* Get the maximum display length of the GUC value. */
9925  switch (gconf->vartype)
9926  {
9927  case PGC_BOOL:
9928  {
9929  valsize = 5; /* max(strlen('true'), strlen('false')) */
9930  }
9931  break;
9932 
9933  case PGC_INT:
9934  {
9935  struct config_int *conf = (struct config_int *) gconf;
9936 
9937  /*
9938  * Instead of getting the exact display length, use max
9939  * length. Also reduce the max length for typical ranges of
9940  * small values. Maximum value is 2147483647, i.e. 10 chars.
9941  * Include one byte for sign.
9942  */
9943  if (Abs(*conf->variable) < 1000)
9944  valsize = 3 + 1;
9945  else
9946  valsize = 10 + 1;
9947  }
9948  break;
9949 
9950  case PGC_REAL:
9951  {
9952  /*
9953  * We are going to print it with %e with REALTYPE_PRECISION
9954  * fractional digits. Account for sign, leading digit,
9955  * decimal point, and exponent with up to 3 digits. E.g.
9956  * -3.99329042340000021e+110
9957  */
9958  valsize = 1 + 1 + 1 + REALTYPE_PRECISION + 5;
9959  }
9960  break;
9961 
9962  case PGC_STRING:
9963  {
9964  struct config_string *conf = (struct config_string *) gconf;
9965 
9966  /*
9967  * If the value is NULL, we transmit it as an empty string.
9968  * Although this is not physically the same value, GUC
9969  * generally treats a NULL the same as empty string.
9970  */
9971  if (*conf->variable)
9972  valsize = strlen(*conf->variable);
9973  else
9974  valsize = 0;
9975  }
9976  break;
9977 
9978  case PGC_ENUM:
9979  {
9980  struct config_enum *conf = (struct config_enum *) gconf;
9981 
9982  valsize = strlen(config_enum_lookup_by_value(conf, *conf->variable));
9983  }
9984  break;
9985  }
9986 
9987  /* Allow space for terminating zero-byte for value */
9988  size = add_size(size, valsize + 1);
9989 
9990  if (gconf->sourcefile)
9991  size = add_size(size, strlen(gconf->sourcefile));
9992 
9993  /* Allow space for terminating zero-byte for sourcefile */
9994  size = add_size(size, 1);
9995 
9996  /* Include line whenever file is nonempty. */
9997  if (gconf->sourcefile && gconf->sourcefile[0])
9998  size = add_size(size, sizeof(gconf->sourceline));
9999 
10000  size = add_size(size, sizeof(gconf->source));
10001  size = add_size(size, sizeof(gconf->scontext));
10002 
10003  return size;
10004 }
GucSource source
Definition: guc_tables.h:158
char ** variable
Definition: guc_tables.h:230
const char * name
Definition: guc_tables.h:149
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:6418
GucContext scontext
Definition: guc_tables.h:160
#define Abs(x)
Definition: c.h:910
int * variable
Definition: guc_tables.h:198
int * variable
Definition: guc_tables.h:244
char * sourcefile
Definition: guc_tables.h:164
static bool can_skip_gucvar(struct config_generic *gconf)
Definition: guc.c:9899
#define REALTYPE_PRECISION
Definition: guc.c:116
enum config_type vartype
Definition: guc_tables.h:156
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
size_t Size
Definition: c.h:466

◆ EstimateGUCStateSpace()

Size EstimateGUCStateSpace ( void  )

Definition at line 10011 of file guc.c.

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

Referenced by InitializeParallelDSM().

10012 {
10013  Size size;
10014  int i;
10015 
10016  /* Add space reqd for saving the data size of the guc state */
10017  size = sizeof(Size);
10018 
10019  /* Add up the space needed for each GUC variable */
10020  for (i = 0; i < num_guc_variables; i++)
10021  size = add_size(size,
10023 
10024  return size;
10025 }
static int num_guc_variables
Definition: guc.c:4568
static struct config_generic ** guc_variables
Definition: guc.c:4565
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
size_t Size
Definition: c.h:466
static Size estimate_variable_size(struct config_generic *gconf)
Definition: guc.c:9913
int i

◆ ExecSetVariableStmt()

void ExecSetVariableStmt ( VariableSetStmt stmt,
bool  isTopLevel 
)

Definition at line 8120 of file guc.c.

References generate_unaccent_rules::action, DefElem::arg, VariableSetStmt::args, Assert, DefElem::defname, elog, ereport, errcode(), errmsg(), ERROR, ExtractSetVariableArgs(), GUC_ACTION_LOCAL, GUC_ACTION_SET, ImportSnapshot(), VariableSetStmt::is_local, IsInParallelMode(), VariableSetStmt::kind, lfirst, linitial_node, list_make1, VariableSetStmt::name, nodeTag, PGC_S_SESSION, PGC_SUSET, PGC_USERSET, ResetAllOptions(), set_config_option(), SetPGVariable(), strVal, superuser(), T_String, A_Const::val, VAR_RESET, VAR_RESET_ALL, VAR_SET_CURRENT, VAR_SET_DEFAULT, VAR_SET_MULTI, VAR_SET_VALUE, and WarnNoTransactionBlock().

Referenced by standard_ProcessUtility().

8121 {
8123 
8124  /*
8125  * Workers synchronize these parameters at the start of the parallel
8126  * operation; then, we block SET during the operation.
8127  */
8128  if (IsInParallelMode())
8129  ereport(ERROR,
8130  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
8131  errmsg("cannot set parameters during a parallel operation")));
8132 
8133  switch (stmt->kind)
8134  {
8135  case VAR_SET_VALUE:
8136  case VAR_SET_CURRENT:
8137  if (stmt->is_local)
8138  WarnNoTransactionBlock(isTopLevel, "SET LOCAL");
8139  (void) set_config_option(stmt->name,
8140  ExtractSetVariableArgs(stmt),
8142  PGC_S_SESSION,
8143  action, true, 0, false);
8144  break;
8145  case VAR_SET_MULTI:
8146 
8147  /*
8148  * Special-case SQL syntaxes. The TRANSACTION and SESSION
8149  * CHARACTERISTICS cases effectively set more than one variable
8150  * per statement. TRANSACTION SNAPSHOT only takes one argument,
8151  * but we put it here anyway since it's a special case and not
8152  * related to any GUC variable.
8153  */
8154  if (strcmp(stmt->name, "TRANSACTION") == 0)
8155  {
8156  ListCell *head;
8157 
8158  WarnNoTransactionBlock(isTopLevel, "SET TRANSACTION");
8159 
8160  foreach(head, stmt->args)
8161  {
8162  DefElem *item = (DefElem *) lfirst(head);
8163 
8164  if (strcmp(item->defname, "transaction_isolation") == 0)
8165  SetPGVariable("transaction_isolation",
8166  list_make1(item->arg), stmt->is_local);
8167  else if (strcmp(item->defname, "transaction_read_only") == 0)
8168  SetPGVariable("transaction_read_only",
8169  list_make1(item->arg), stmt->is_local);
8170  else if (strcmp(item->defname, "transaction_deferrable") == 0)
8171  SetPGVariable("transaction_deferrable",
8172  list_make1(item->arg), stmt->is_local);
8173  else
8174  elog(ERROR, "unexpected SET TRANSACTION element: %s",
8175  item->defname);
8176  }
8177  }
8178  else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
8179  {
8180  ListCell *head;
8181 
8182  foreach(head, stmt->args)
8183  {
8184  DefElem *item = (DefElem *) lfirst(head);
8185 
8186  if (strcmp(item->defname, "transaction_isolation") == 0)
8187  SetPGVariable("default_transaction_isolation",
8188  list_make1(item->arg), stmt->is_local);
8189  else if (strcmp(item->defname, "transaction_read_only") == 0)
8190  SetPGVariable("default_transaction_read_only",
8191  list_make1(item->arg), stmt->is_local);
8192  else if (strcmp(item->defname, "transaction_deferrable") == 0)
8193  SetPGVariable("default_transaction_deferrable",
8194  list_make1(item->arg), stmt->is_local);
8195  else
8196  elog(ERROR, "unexpected SET SESSION element: %s",
8197  item->defname);
8198  }
8199  }
8200  else if (strcmp(stmt->name, "TRANSACTION SNAPSHOT") == 0)
8201  {
8202  A_Const *con = linitial_node(A_Const, stmt->args);
8203 
8204  if (stmt->is_local)
8205  ereport(ERROR,
8206  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8207  errmsg("SET LOCAL TRANSACTION SNAPSHOT is not implemented")));
8208 
8209  WarnNoTransactionBlock(isTopLevel, "SET TRANSACTION");
8210  Assert(nodeTag(&con->val) == T_String);
8211  ImportSnapshot(strVal(&con->val));
8212  }
8213  else
8214  elog(ERROR, "unexpected SET MULTI element: %s",
8215  stmt->name);
8216  break;
8217  case VAR_SET_DEFAULT:
8218  if (stmt->is_local)
8219  WarnNoTransactionBlock(isTopLevel, "SET LOCAL");
8220  /* fall through */
8221  case VAR_RESET:
8222  if (strcmp(stmt->name, "transaction_isolation") == 0)
8223  WarnNoTransactionBlock(isTopLevel, "RESET TRANSACTION");
8224 
8225  (void) set_config_option(stmt->name,
8226  NULL,
8228  PGC_S_SESSION,
8229  action, true, 0, false);
8230  break;
8231  case VAR_RESET_ALL:
8232  ResetAllOptions();
8233  break;
8234  }
8235 }
void ImportSnapshot(const char *idstr)
Definition: snapmgr.c:1462
VariableSetKind kind
Definition: parsenodes.h:2019
void WarnNoTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3388
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:570
bool superuser(void)
Definition: superuser.c:47
#define linitial_node(type, l)
Definition: pg_list.h:198
GucAction
Definition: guc.h:191
#define list_make1(x1)
Definition: pg_list.h:227
bool IsInParallelMode(void)
Definition: xact.c:994
#define ERROR
Definition: elog.h:43
Definition: guc.h:75
void ResetAllOptions(void)
Definition: guc.c:5514
#define ereport(elevel, rest)
Definition: elog.h:141
Node * arg
Definition: parsenodes.h:731
#define Assert(condition)
Definition: c.h:732
#define lfirst(lc)
Definition: pg_list.h:190
#define nodeTag(nodeptr)
Definition: nodes.h:530
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define elog(elevel,...)
Definition: elog.h:226
char * defname
Definition: parsenodes.h:730
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
Definition: guc.c:8244
Value val
Definition: parsenodes.h:288
int set_config_option(const char *name, const char *value, GucContext context, GucSource source, GucAction action, bool changeVal, int elevel, bool is_reload)
Definition: guc.c:6722
void SetPGVariable(const char *name, List *args, bool is_local)
Definition: guc.c:8264

◆ extra_field_used()

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

Definition at line 4697 of file guc.c.

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

Referenced by set_config_option(), and set_extra_field().

4698 {
4699  GucStack *stack;
4700 
4701  if (extra == gconf->extra)
4702  return true;
4703  switch (gconf->vartype)
4704  {
4705  case PGC_BOOL:
4706  if (extra == ((struct config_bool *) gconf)->reset_extra)
4707  return true;
4708  break;
4709  case PGC_INT:
4710  if (extra == ((struct config_int *) gconf)->reset_extra)
4711  return true;
4712  break;
4713  case PGC_REAL:
4714  if (extra == ((struct config_real *) gconf)->reset_extra)
4715  return true;
4716  break;
4717  case PGC_STRING:
4718  if (extra == ((struct config_string *) gconf)->reset_extra)
4719  return true;
4720  break;
4721  case PGC_ENUM:
4722  if (extra == ((struct config_enum *) gconf)->reset_extra)
4723  return true;
4724  break;
4725  }
4726  for (stack = gconf->stack; stack; stack = stack->prev)
4727  {
4728  if (extra == stack->prior.extra ||
4729  extra == stack->masked.extra)
4730  return true;
4731  }
4732 
4733  return false;
4734 }
struct guc_stack * prev
Definition: guc_tables.h:123
config_var_value masked
Definition: guc_tables.h:131
void * reset_extra
Definition: guc_tables.h:252
enum config_type vartype
Definition: guc_tables.h:156
config_var_value prior
Definition: guc_tables.h:130

◆ ExtractSetVariableArgs()

char* ExtractSetVariableArgs ( VariableSetStmt stmt)

Definition at line 8244 of file guc.c.

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

8245 {
8246  switch (stmt->kind)
8247  {
8248  case VAR_SET_VALUE:
8249  return flatten_set_variable_args(stmt->name, stmt->args);
8250  case VAR_SET_CURRENT:
8251  return GetConfigOptionByName(stmt->name, NULL, false);
8252  default:
8253  return NULL;
8254  }
8255 }
VariableSetKind kind
Definition: parsenodes.h:2019
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:8977
static char * flatten_set_variable_args(const char *name, List *args)
Definition: guc.c:7646

◆ find_option()