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/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 "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/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/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 const char * show_tcp_keepalives_idle (void)
 
static const char * show_tcp_keepalives_interval (void)
 
static const char * show_tcp_keepalives_count (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_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 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 (int64 value, const char *unit, int base_unit, int64 *base_value)
 
static void convert_from_base_unit (int64 base_value, int base_unit, int64 *value, const char **unit)
 
bool parse_int (const char *value, int *result, int flags, const char **hintmsg)
 
bool parse_real (const char *value, double *result)
 
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_superuser)
 
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)
 
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)
 
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)
 

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 password_encryption_options []
 
const struct config_enum_entry wal_level_options []
 
const struct config_enum_entry archive_mode_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
 
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 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 * XactIsoLevel_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
 
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 \"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 \"ms\", \"s\", \"min\", \"h\", and \"d\".")
 
static const unit_conversion time_unit_conversion_table []
 
static struct config_bool ConfigureNamesBool []
 
static struct config_int ConfigureNamesInt []
 
static struct config_real ConfigureNamesReal []
 
static struct config_string ConfigureNamesString []
 
static struct config_enum ConfigureNamesEnum []
 
static const char *const map_old_guc_names []
 
static struct config_generic ** guc_variables
 
static int num_guc_variables
 
static int size_guc_variables
 
static bool guc_dirty
 
static bool reporting_enabled
 
static int GUCNestLevel = 0
 

Macro Definition Documentation

◆ CONFIG_FILENAME

#define CONFIG_FILENAME   "postgresql.conf"

Definition at line 98 of file guc.c.

Referenced by SelectConfigFiles().

◆ HBA_FILENAME

#define HBA_FILENAME   "pg_hba.conf"

Definition at line 99 of file guc.c.

Referenced by SelectConfigFiles().

◆ IDENT_FILENAME

#define IDENT_FILENAME   "pg_ident.conf"

Definition at line 100 of file guc.c.

Referenced by SelectConfigFiles().

◆ MAX_UNIT_LEN

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

Definition at line 701 of file guc.c.

Referenced by parse_int().

◆ newval [1/5]

◆ newval [2/5]

#define newval   (newval_union.intval)

◆ newval [3/5]

#define newval   (newval_union.realval)

◆ newval [4/5]

#define newval   (newval_union.stringval)

◆ newval [5/5]

#define newval   (newval_union.enumval)

◆ NUM_PG_FILE_SETTINGS_ATTS

#define NUM_PG_FILE_SETTINGS_ATTS   7

Referenced by show_all_file_settings().

◆ NUM_PG_SETTINGS_ATTS

#define NUM_PG_SETTINGS_ATTS   17

Definition at line 8641 of file guc.c.

Referenced by show_all_settings().

◆ PG_KRB_SRVTAB

#define PG_KRB_SRVTAB   ""

Definition at line 95 of file guc.c.

◆ REALTYPE_PRECISION

#define REALTYPE_PRECISION   17

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

References AllocateFile(), Assert, buffer, config_enum_lookup_by_value(), convert_from_base_unit(), elevel, elog, ereport, errcode_for_file_access(), errmsg(), ERROR, FATAL, find_option(), config_generic::flags, 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().

8889 {
8890  char buffer[256];
8891  const char *val;
8892 
8893  switch (record->vartype)
8894  {
8895  case PGC_BOOL:
8896  {
8897  struct config_bool *conf = (struct config_bool *) record;
8898 
8899  if (conf->show_hook)
8900  val = conf->show_hook();
8901  else
8902  val = *conf->variable ? "on" : "off";
8903  }
8904  break;
8905 
8906  case PGC_INT:
8907  {
8908  struct config_int *conf = (struct config_int *) record;
8909 
8910  if (conf->show_hook)
8911  val = conf->show_hook();
8912  else
8913  {
8914  /*
8915  * Use int64 arithmetic to avoid overflows in units
8916  * conversion.
8917  */
8918  int64 result = *conf->variable;
8919  const char *unit;
8920 
8921  if (use_units && result > 0 && (record->flags & GUC_UNIT))
8922  {
8923  convert_from_base_unit(result, record->flags & GUC_UNIT,
8924  &result, &unit);
8925  }
8926  else
8927  unit = "";
8928 
8929  snprintf(buffer, sizeof(buffer), INT64_FORMAT "%s",
8930  result, unit);
8931  val = buffer;
8932  }
8933  }
8934  break;
8935 
8936  case PGC_REAL:
8937  {
8938  struct config_real *conf = (struct config_real *) record;
8939 
8940  if (conf->show_hook)
8941  val = conf->show_hook();
8942  else
8943  {
8944  snprintf(buffer, sizeof(buffer), "%g",
8945  *conf->variable);
8946  val = buffer;
8947  }
8948  }
8949  break;
8950 
8951  case PGC_STRING:
8952  {
8953  struct config_string *conf = (struct config_string *) record;
8954 
8955  if (conf->show_hook)
8956  val = conf->show_hook();
8957  else if (*conf->variable && **conf->variable)
8958  val = *conf->variable;
8959  else
8960  val = "";
8961  }
8962  break;
8963 
8964  case PGC_ENUM:
8965  {
8966  struct config_enum *conf = (struct config_enum *) record;
8967 
8968  if (conf->show_hook)
8969  val = conf->show_hook();
8970  else
8971  val = config_enum_lookup_by_value(conf, *conf->variable);
8972  }
8973  break;
8974 
8975  default:
8976  /* just to keep compiler quiet */
8977  val = "???";
8978  break;
8979  }
8980 
8981  return pstrdup(val);
8982 }
char ** variable
Definition: guc_tables.h:228
char * pstrdup(const char *in)
Definition: mcxt.c:1161
bool * variable
Definition: guc_tables.h:182
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5837
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define GUC_UNIT
Definition: guc.h:230
GucShowHook show_hook
Definition: guc_tables.h:202
int * variable
Definition: guc_tables.h:196
int * variable
Definition: guc_tables.h:242
GucShowHook show_hook
Definition: guc_tables.h:232
GucShowHook show_hook
Definition: guc_tables.h:218
double * variable
Definition: guc_tables.h:212
enum config_type vartype
Definition: guc_tables.h:154
GucShowHook show_hook
Definition: guc_tables.h:247
GucShowHook show_hook
Definition: guc_tables.h:186
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:215
#define INT64_FORMAT
Definition: c.h:367
static void convert_from_base_unit(int64 base_value, int base_unit, int64 *value, const char **unit)
Definition: guc.c:5665
long val
Definition: informix.c:689

◆ add_guc_variable()

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

Definition at line 4506 of file guc.c.

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

Referenced by add_placeholder_variable(), and define_custom_variable().

4507 {
4509  {
4510  /*
4511  * Increase the vector by 25%
4512  */
4513  int size_vars = size_guc_variables + size_guc_variables / 4;
4514  struct config_generic **guc_vars;
4515 
4516  if (size_vars == 0)
4517  {
4518  size_vars = 100;
4519  guc_vars = (struct config_generic **)
4520  guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
4521  }
4522  else
4523  {
4524  guc_vars = (struct config_generic **)
4525  guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
4526  }
4527 
4528  if (guc_vars == NULL)
4529  return false; /* out of memory */
4530 
4531  guc_variables = guc_vars;
4532  size_guc_variables = size_vars;
4533  }
4536  sizeof(struct config_generic *), guc_var_compare);
4537  return true;
4538 }
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:4641
static int num_guc_variables
Definition: guc.c:4158
static void * guc_realloc(int elevel, void *old, size_t size)
Definition: guc.c:4212
static struct config_generic ** guc_variables
Definition: guc.c:4155
static int size_guc_variables
Definition: guc.c:4161
static int elevel
Definition: vacuumlazy.c:144
#define qsort(a, b, c, d)
Definition: port.h:421
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4196

◆ add_placeholder_variable()

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

Definition at line 4544 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, config_string::variable, and config_generic::vartype.

Referenced by find_option().

4545 {
4546  size_t sz = sizeof(struct config_string) + sizeof(char *);
4547  struct config_string *var;
4548  struct config_generic *gen;
4549 
4550  var = (struct config_string *) guc_malloc(elevel, sz);
4551  if (var == NULL)
4552  return NULL;
4553  memset(var, 0, sz);
4554  gen = &var->gen;
4555 
4556  gen->name = guc_strdup(elevel, name);
4557  if (gen->name == NULL)
4558  {
4559  free(var);
4560  return NULL;
4561  }
4562 
4563  gen->context = PGC_USERSET;
4564  gen->group = CUSTOM_OPTIONS;
4565  gen->short_desc = "GUC placeholder variable";
4567  gen->vartype = PGC_STRING;
4568 
4569  /*
4570  * The char* is allocated at the end of the struct since we have no
4571  * 'static' place to point to. Note that the current value, as well as
4572  * the boot and reset values, start out NULL.
4573  */
4574  var->variable = (char **) (var + 1);
4575 
4576  if (!add_guc_variable((struct config_generic *) var, elevel))
4577  {
4578  free((void *) gen->name);
4579  free(var);
4580  return NULL;
4581  }
4582 
4583  return gen;
4584 }
char ** variable
Definition: guc_tables.h:228
const char * name
Definition: guc_tables.h:147
const char * short_desc
Definition: guc_tables.h:150
static char * guc_strdup(int elevel, const char *src)
Definition: guc.c:4228
#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:154
static int elevel
Definition: vacuumlazy.c:144
struct config_generic gen
Definition: guc_tables.h:226
#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:149
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4196
GucContext context
Definition: guc_tables.h:148
static bool add_guc_variable(struct config_generic *var, int elevel)
Definition: guc.c:4506

◆ AlterSystemSetConfigFile()

void AlterSystemSetConfigFile ( AlterSystemStmt altersysstmt)

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

7315 {
7316  char *name;
7317  char *value;
7318  bool resetall = false;
7319  ConfigVariable *head = NULL;
7320  ConfigVariable *tail = NULL;
7321  volatile int Tmpfd;
7322  char AutoConfFileName[MAXPGPATH];
7323  char AutoConfTmpFileName[MAXPGPATH];
7324 
7325  if (!superuser())
7326  ereport(ERROR,
7327  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7328  (errmsg("must be superuser to execute ALTER SYSTEM command"))));
7329 
7330  /*
7331  * Extract statement arguments
7332  */
7333  name = altersysstmt->setstmt->name;
7334 
7335  switch (altersysstmt->setstmt->kind)
7336  {
7337  case VAR_SET_VALUE:
7338  value = ExtractSetVariableArgs(altersysstmt->setstmt);
7339  break;
7340 
7341  case VAR_SET_DEFAULT:
7342  case VAR_RESET:
7343  value = NULL;
7344  break;
7345 
7346  case VAR_RESET_ALL:
7347  value = NULL;
7348  resetall = true;
7349  break;
7350 
7351  default:
7352  elog(ERROR, "unrecognized alter system stmt type: %d",
7353  altersysstmt->setstmt->kind);
7354  break;
7355  }
7356 
7357  /*
7358  * Unless it's RESET_ALL, validate the target variable and value
7359  */
7360  if (!resetall)
7361  {
7362  struct config_generic *record;
7363 
7364  record = find_option(name, false, ERROR);
7365  if (record == NULL)
7366  ereport(ERROR,
7367  (errcode(ERRCODE_UNDEFINED_OBJECT),
7368  errmsg("unrecognized configuration parameter \"%s\"",
7369  name)));
7370 
7371  /*
7372  * Don't allow parameters that can't be set in configuration files to
7373  * be set in PG_AUTOCONF_FILENAME file.
7374  */
7375  if ((record->context == PGC_INTERNAL) ||
7376  (record->flags & GUC_DISALLOW_IN_FILE) ||
7377  (record->flags & GUC_DISALLOW_IN_AUTO_FILE))
7378  ereport(ERROR,
7379  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
7380  errmsg("parameter \"%s\" cannot be changed",
7381  name)));
7382 
7383  /*
7384  * If a value is specified, verify that it's sane.
7385  */
7386  if (value)
7387  {
7388  union config_var_val newval;
7389  void *newextra = NULL;
7390 
7391  /* Check that it's acceptable for the indicated parameter */
7392  if (!parse_and_validate_value(record, name, value,
7393  PGC_S_FILE, ERROR,
7394  &newval, &newextra))
7395  ereport(ERROR,
7396  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7397  errmsg("invalid value for parameter \"%s\": \"%s\"",
7398  name, value)));
7399 
7400  if (record->vartype == PGC_STRING && newval.stringval != NULL)
7401  free(newval.stringval);
7402  if (newextra)
7403  free(newextra);
7404 
7405  /*
7406  * We must also reject values containing newlines, because the
7407  * grammar for config files doesn't support embedded newlines in
7408  * string literals.
7409  */
7410  if (strchr(value, '\n'))
7411  ereport(ERROR,
7412  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7413  errmsg("parameter value for ALTER SYSTEM must not contain a newline")));
7414  }
7415  }
7416 
7417  /*
7418  * PG_AUTOCONF_FILENAME and its corresponding temporary file are always in
7419  * the data directory, so we can reference them by simple relative paths.
7420  */
7421  snprintf(AutoConfFileName, sizeof(AutoConfFileName), "%s",
7423  snprintf(AutoConfTmpFileName, sizeof(AutoConfTmpFileName), "%s.%s",
7424  AutoConfFileName,
7425  "tmp");
7426 
7427  /*
7428  * Only one backend is allowed to operate on PG_AUTOCONF_FILENAME at a
7429  * time. Use AutoFileLock to ensure that. We must hold the lock while
7430  * reading the old file contents.
7431  */
7432  LWLockAcquire(AutoFileLock, LW_EXCLUSIVE);
7433 
7434  /*
7435  * If we're going to reset everything, then no need to open or parse the
7436  * old file. We'll just write out an empty list.
7437  */
7438  if (!resetall)
7439  {
7440  struct stat st;
7441 
7442  if (stat(AutoConfFileName, &st) == 0)
7443  {
7444  /* open old file PG_AUTOCONF_FILENAME */
7445  FILE *infile;
7446 
7447  infile = AllocateFile(AutoConfFileName, "r");
7448  if (infile == NULL)
7449  ereport(ERROR,
7451  errmsg("could not open file \"%s\": %m",
7452  AutoConfFileName)));
7453 
7454  /* parse it */
7455  if (!ParseConfigFp(infile, AutoConfFileName, 0, LOG, &head, &tail))
7456  ereport(ERROR,
7457  (errcode(ERRCODE_CONFIG_FILE_ERROR),
7458  errmsg("could not parse contents of file \"%s\"",
7459  AutoConfFileName)));
7460 
7461  FreeFile(infile);
7462  }
7463 
7464  /*
7465  * Now, replace any existing entry with the new value, or add it if
7466  * not present.
7467  */
7468  replace_auto_config_value(&head, &tail, name, value);
7469  }
7470 
7471  /*
7472  * To ensure crash safety, first write the new file data to a temp file,
7473  * then atomically rename it into place.
7474  *
7475  * If there is a temp file left over due to a previous crash, it's okay to
7476  * truncate and reuse it.
7477  */
7478  Tmpfd = BasicOpenFile(AutoConfTmpFileName,
7479  O_CREAT | O_RDWR | O_TRUNC);
7480  if (Tmpfd < 0)
7481  ereport(ERROR,
7483  errmsg("could not open file \"%s\": %m",
7484  AutoConfTmpFileName)));
7485 
7486  /*
7487  * Use a TRY block to clean up the file if we fail. Since we need a TRY
7488  * block anyway, OK to use BasicOpenFile rather than OpenTransientFile.
7489  */
7490  PG_TRY();
7491  {
7492  /* Write and sync the new contents to the temporary file */
7493  write_auto_conf_file(Tmpfd, AutoConfTmpFileName, head);
7494 
7495  /* Close before renaming; may be required on some platforms */
7496  close(Tmpfd);
7497  Tmpfd = -1;
7498 
7499  /*
7500  * As the rename is atomic operation, if any problem occurs after this
7501  * at worst it can lose the parameters set by last ALTER SYSTEM
7502  * command.
7503  */
7504  durable_rename(AutoConfTmpFileName, AutoConfFileName, ERROR);
7505  }
7506  PG_CATCH();
7507  {
7508  /* Close file first, else unlink might fail on some platforms */
7509  if (Tmpfd >= 0)
7510  close(Tmpfd);
7511 
7512  /* Unlink, but ignore any error */
7513  (void) unlink(AutoConfTmpFileName);
7514 
7515  PG_RE_THROW();
7516  }
7517  PG_END_TRY();
7518 
7519  FreeConfigVariables(head);
7520 
7521  LWLockRelease(AutoFileLock);
7522 }
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:5944
VariableSetKind kind
Definition: parsenodes.h:1984
int errcode(int sqlerrcode)
Definition: elog.c:575
bool superuser(void)
Definition: superuser.c:47
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define LOG
Definition: elog.h:26
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1725
#define ERROR
Definition: elog.h:43
#define MAXPGPATH
VariableSetStmt * setstmt
Definition: parsenodes.h:3108
int errcode_for_file_access(void)
Definition: elog.c:598
FILE * AllocateFile(const char *name, const char *mode)
Definition: fd.c:2346
#define ereport(elevel, rest)
Definition: elog.h:122
int durable_rename(const char *oldfile, const char *newfile, int elevel)
Definition: fd.c:601
enum config_type vartype
Definition: guc_tables.h:154
#define stat(a, b)
Definition: win32_port.h:266
#define GUC_DISALLOW_IN_FILE
Definition: guc.h:210
static struct @131 value
static void write_auto_conf_file(int fd, const char *filename, ConfigVariable *head_p)
Definition: guc.c:7173
static void infile(const char *filename)
Definition: zic.c:1159
#define free(a)
Definition: header.h:65
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4592
#define PG_CATCH()
Definition: elog.h:293
#define newval
#define PG_AUTOCONF_FILENAME
Definition: guc.h:34
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1121
#define PG_RE_THROW()
Definition: elog.h:314
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:932
int FreeFile(FILE *file)
Definition: fd.c:2538
int errmsg(const char *fmt,...)
Definition: elog.c:797
bool ParseConfigFp(FILE *fp, const char *config_file, int depth, int elevel, ConfigVariable **head_p, ConfigVariable **tail_p)
static void replace_auto_config_value(ConfigVariable **head_p, ConfigVariable **tail_p, const char *name, const char *value)
Definition: guc.c:7241
void FreeConfigVariables(ConfigVariable *list)
#define elog
Definition: elog.h:219
#define close(a)
Definition: win32.h:12
#define PG_TRY()
Definition: elog.h:284
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
Definition: guc.c:7652
#define PG_END_TRY()
Definition: elog.h:300
GucContext context
Definition: guc_tables.h:148

◆ assign_application_name()

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

Definition at line 10711 of file guc.c.

References pgstat_report_appname().

10712 {
10713  /* Update the pg_stat_activity view */
10715 }
void pgstat_report_appname(const char *appname)
Definition: pgstat.c:3167
#define newval

◆ assign_effective_io_concurrency()

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

Definition at line 10659 of file guc.c.

References target_prefetch_pages.

10660 {
10661 #ifdef USE_PREFETCH
10662  target_prefetch_pages = *((int *) extra);
10663 #endif /* USE_PREFETCH */
10664 }
int target_prefetch_pages
Definition: bufmgr.c:129

◆ assign_log_destination()

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

Definition at line 10347 of file guc.c.

References Log_destination.

10348 {
10349  Log_destination = *((int *) extra);
10350 }
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 10667 of file guc.c.

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

10668 {
10669  /* check_canonical_path already canonicalized newval for us */
10670  char *dname;
10671  char *tname;
10672  char *fname;
10673 
10674  /* directory */
10675  dname = guc_malloc(ERROR, strlen(newval) + 1); /* runtime dir */
10676  sprintf(dname, "%s", newval);
10677 
10678  /* global stats */
10679  tname = guc_malloc(ERROR, strlen(newval) + 12); /* /global.tmp */
10680  sprintf(tname, "%s/global.tmp", newval);
10681  fname = guc_malloc(ERROR, strlen(newval) + 13); /* /global.stat */
10682  sprintf(fname, "%s/global.stat", newval);
10683 
10686  pgstat_stat_directory = dname;
10687  if (pgstat_stat_tmpname)
10689  pgstat_stat_tmpname = tname;
10692  pgstat_stat_filename = fname;
10693 }
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:4196

◆ assign_session_replication_role()

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

Definition at line 10373 of file guc.c.

References ResetPlanCache(), and SessionReplicationRole.

10374 {
10375  /*
10376  * Must flush the plan cache when changing replication role; but don't
10377  * flush unnecessarily.
10378  */
10380  ResetPlanCache();
10381 }
int SessionReplicationRole
Definition: trigger.c:66
void ResetPlanCache(void)
Definition: plancache.c:1863
#define newval

◆ assign_syslog_facility()

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

Definition at line 10353 of file guc.c.

10354 {
10355 #ifdef HAVE_SYSLOG
10356  set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
10357  newval);
10358 #endif
10359  /* Without syslog support, just ignore it */
10360 }
static char * syslog_ident_str
Definition: guc.c:497
#define newval

◆ assign_syslog_ident()

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

Definition at line 10363 of file guc.c.

10364 {
10365 #ifdef HAVE_SYSLOG
10366  set_syslog_parameters(newval, syslog_facility);
10367 #endif
10368  /* Without syslog support, it will always be set to "none", so ignore */
10369 }
static int syslog_facility
Definition: guc.c:161
#define newval

◆ assign_tcp_keepalives_count()

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

Definition at line 10572 of file guc.c.

References MyProcPort, and pq_setkeepalivescount().

10573 {
10574  /* See comments in assign_tcp_keepalives_idle */
10576 }
struct Port * MyProcPort
Definition: globals.c:44
int pq_setkeepalivescount(int count, Port *port)
Definition: pqcomm.c:1888
#define newval

◆ assign_tcp_keepalives_idle()

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

Definition at line 10528 of file guc.c.

References MyProcPort, and pq_setkeepalivesidle().

10529 {
10530  /*
10531  * The kernel API provides no way to test a value without setting it; and
10532  * once we set it we might fail to unset it. So there seems little point
10533  * in fully implementing the check-then-assign GUC API for these
10534  * variables. Instead we just do the assignment on demand. pqcomm.c
10535  * reports any problems via elog(LOG).
10536  *
10537  * This approach means that the GUC value might have little to do with the
10538  * actual kernel value, so we use a show_hook that retrieves the kernel
10539  * value rather than trusting GUC's copy.
10540  */
10542 }
struct Port * MyProcPort
Definition: globals.c:44
int pq_setkeepalivesidle(int idle, Port *port)
Definition: pqcomm.c:1730
#define newval

◆ assign_tcp_keepalives_interval()

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

Definition at line 10555 of file guc.c.

References MyProcPort, and pq_setkeepalivesinterval().

10556 {
10557  /* See comments in assign_tcp_keepalives_idle */
10559 }
struct Port * MyProcPort
Definition: globals.c:44
int pq_setkeepalivesinterval(int interval, Port *port)
Definition: pqcomm.c:1812
#define newval

◆ assign_timezone_abbreviations()

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

Definition at line 10492 of file guc.c.

References InstallTimeZoneAbbrevs().

10493 {
10494  /* Do nothing for the boot_val default of NULL */
10495  if (!extra)
10496  return;
10497 
10499 }
void InstallTimeZoneAbbrevs(TimeZoneAbbrevTable *tbl)
Definition: datetime.c:4587

◆ assign_wal_consistency_checking()

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

Definition at line 10284 of file guc.c.

References wal_consistency_checking.

10285 {
10286  wal_consistency_checking = (bool *) extra;
10287 }
bool * wal_consistency_checking
Definition: xlog.c:101

◆ AtEOXact_GUC()

void AtEOXact_GUC ( bool  isCommit,
int  nestLevel 
)

Definition at line 5299 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(), do_analyze_rel(), ExecCreateTableAs(), ExecRefreshMatView(), execute_extension_script(), fmgr_security_definer(), index_build(), PrepareTransaction(), ProcedureCreate(), reset_transmission_modes(), restoreLocalGucs(), RI_Initial_Check(), vacuum_rel(), and validate_index().

5300 {
5301  bool still_dirty;
5302  int i;
5303 
5304  /*
5305  * Note: it's possible to get here with GUCNestLevel == nestLevel-1 during
5306  * abort, if there is a failure during transaction start before
5307  * AtStart_GUC is called.
5308  */
5309  Assert(nestLevel > 0 &&
5310  (nestLevel <= GUCNestLevel ||
5311  (nestLevel == GUCNestLevel + 1 && !isCommit)));
5312 
5313  /* Quick exit if nothing's changed in this transaction */
5314  if (!guc_dirty)
5315  {
5316  GUCNestLevel = nestLevel - 1;
5317  return;
5318  }
5319 
5320  still_dirty = false;
5321  for (i = 0; i < num_guc_variables; i++)
5322  {
5323  struct config_generic *gconf = guc_variables[i];
5324  GucStack *stack;
5325 
5326  /*
5327  * Process and pop each stack entry within the nest level. To simplify
5328  * fmgr_security_definer() and other places that use GUC_ACTION_SAVE,
5329  * we allow failure exit from code that uses a local nest level to be
5330  * recovered at the surrounding transaction or subtransaction abort;
5331  * so there could be more than one stack entry to pop.
5332  */
5333  while ((stack = gconf->stack) != NULL &&
5334  stack->nest_level >= nestLevel)
5335  {
5336  GucStack *prev = stack->prev;
5337  bool restorePrior = false;
5338  bool restoreMasked = false;
5339  bool changed;
5340 
5341  /*
5342  * In this next bit, if we don't set either restorePrior or
5343  * restoreMasked, we must "discard" any unwanted fields of the
5344  * stack entries to avoid leaking memory. If we do set one of
5345  * those flags, unused fields will be cleaned up after restoring.
5346  */
5347  if (!isCommit) /* if abort, always restore prior value */
5348  restorePrior = true;
5349  else if (stack->state == GUC_SAVE)
5350  restorePrior = true;
5351  else if (stack->nest_level == 1)
5352  {
5353  /* transaction commit */
5354  if (stack->state == GUC_SET_LOCAL)
5355  restoreMasked = true;
5356  else if (stack->state == GUC_SET)
5357  {
5358  /* we keep the current active value */
5359  discard_stack_value(gconf, &stack->prior);
5360  }
5361  else /* must be GUC_LOCAL */
5362  restorePrior = true;
5363  }
5364  else if (prev == NULL ||
5365  prev->nest_level < stack->nest_level - 1)
5366  {
5367  /* decrement entry's level and do not pop it */
5368  stack->nest_level--;
5369  continue;
5370  }
5371  else
5372  {
5373  /*
5374  * We have to merge this stack entry into prev. See README for
5375  * discussion of this bit.
5376  */
5377  switch (stack->state)
5378  {
5379  case GUC_SAVE:
5380  Assert(false); /* can't get here */
5381 
5382  case GUC_SET:
5383  /* next level always becomes SET */
5384  discard_stack_value(gconf, &stack->prior);
5385  if (prev->state == GUC_SET_LOCAL)
5386  discard_stack_value(gconf, &prev->masked);
5387  prev->state = GUC_SET;
5388  break;
5389 
5390  case GUC_LOCAL:
5391  if (prev->state == GUC_SET)
5392  {
5393  /* LOCAL migrates down */
5394  prev->masked_scontext = stack->scontext;
5395  prev->masked = stack->prior;
5396  prev->state = GUC_SET_LOCAL;
5397  }
5398  else
5399  {
5400  /* else just forget this stack level */
5401  discard_stack_value(gconf, &stack->prior);
5402  }
5403  break;
5404 
5405  case GUC_SET_LOCAL:
5406  /* prior state at this level no longer wanted */
5407  discard_stack_value(gconf, &stack->prior);
5408  /* copy down the masked state */
5409  prev->masked_scontext = stack->masked_scontext;
5410  if (prev->state == GUC_SET_LOCAL)
5411  discard_stack_value(gconf, &prev->masked);
5412  prev->masked = stack->masked;
5413  prev->state = GUC_SET_LOCAL;
5414  break;
5415  }
5416  }
5417 
5418  changed = false;
5419 
5420  if (restorePrior || restoreMasked)
5421  {
5422  /* Perform appropriate restoration of the stacked value */
5423  config_var_value newvalue;
5424  GucSource newsource;
5425  GucContext newscontext;
5426 
5427  if (restoreMasked)
5428  {
5429  newvalue = stack->masked;
5430  newsource = PGC_S_SESSION;
5431  newscontext = stack->masked_scontext;
5432  }
5433  else
5434  {
5435  newvalue = stack->prior;
5436  newsource = stack->source;
5437  newscontext = stack->scontext;
5438  }
5439 
5440  switch (gconf->vartype)
5441  {
5442  case PGC_BOOL:
5443  {
5444  struct config_bool *conf = (struct config_bool *) gconf;
5445  bool newval = newvalue.val.boolval;
5446  void *newextra = newvalue.extra;
5447 
5448  if (*conf->variable != newval ||
5449  conf->gen.extra != newextra)
5450  {
5451  if (conf->assign_hook)
5452  conf->assign_hook(newval, newextra);
5453  *conf->variable = newval;
5454  set_extra_field(&conf->gen, &conf->gen.extra,
5455  newextra);
5456  changed = true;
5457  }
5458  break;
5459  }
5460  case PGC_INT:
5461  {
5462  struct config_int *conf = (struct config_int *) gconf;
5463  int newval = newvalue.val.intval;
5464  void *newextra = newvalue.extra;
5465 
5466  if (*conf->variable != newval ||
5467  conf->gen.extra != newextra)
5468  {
5469  if (conf->assign_hook)
5470  conf->assign_hook(newval, newextra);
5471  *conf->variable = newval;
5472  set_extra_field(&conf->gen, &conf->gen.extra,
5473  newextra);
5474  changed = true;
5475  }
5476  break;
5477  }
5478  case PGC_REAL:
5479  {
5480  struct config_real *conf = (struct config_real *) gconf;
5481  double newval = newvalue.val.realval;
5482  void *newextra = newvalue.extra;
5483 
5484  if (*conf->variable != newval ||
5485  conf->gen.extra != newextra)
5486  {
5487  if (conf->assign_hook)
5488  conf->assign_hook(newval, newextra);
5489  *conf->variable = newval;
5490  set_extra_field(&conf->gen, &conf->gen.extra,
5491  newextra);
5492  changed = true;
5493  }
5494  break;
5495  }
5496  case PGC_STRING:
5497  {
5498  struct config_string *conf = (struct config_string *) gconf;
5499  char *newval = newvalue.val.stringval;
5500  void *newextra = newvalue.extra;
5501 
5502  if (*conf->variable != newval ||
5503  conf->gen.extra != newextra)
5504  {
5505  if (conf->assign_hook)
5506  conf->assign_hook(newval, newextra);
5507  set_string_field(conf, conf->variable, newval);
5508  set_extra_field(&conf->gen, &conf->gen.extra,
5509  newextra);
5510  changed = true;
5511  }
5512 
5513  /*
5514  * Release stacked values if not used anymore. We
5515  * could use discard_stack_value() here, but since
5516  * we have type-specific code anyway, might as
5517  * well inline it.
5518  */
5519  set_string_field(conf, &stack->prior.val.stringval, NULL);
5520  set_string_field(conf, &stack->masked.val.stringval, NULL);
5521  break;
5522  }
5523  case PGC_ENUM:
5524  {
5525  struct config_enum *conf = (struct config_enum *) gconf;
5526  int newval = newvalue.val.enumval;
5527  void *newextra = newvalue.extra;
5528 
5529  if (*conf->variable != newval ||
5530  conf->gen.extra != newextra)
5531  {
5532  if (conf->assign_hook)
5533  conf->assign_hook(newval, newextra);
5534  *conf->variable = newval;
5535  set_extra_field(&conf->gen, &conf->gen.extra,
5536  newextra);
5537  changed = true;
5538  }
5539  break;
5540  }
5541  }
5542 
5543  /*
5544  * Release stacked extra values if not used anymore.
5545  */
5546  set_extra_field(gconf, &(stack->prior.extra), NULL);
5547  set_extra_field(gconf, &(stack->masked.extra), NULL);
5548 
5549  /* And restore source information */
5550  gconf->source = newsource;
5551  gconf->scontext = newscontext;
5552  }
5553 
5554  /* Finish popping the state stack */
5555  gconf->stack = prev;
5556  pfree(stack);
5557 
5558  /* Report new value if we changed it */
5559  if (changed && (gconf->flags & GUC_REPORT))
5560  ReportGUCOption(gconf);
5561  } /* end of stack-popping loop */
5562 
5563  if (stack != NULL)
5564  still_dirty = true;
5565  }
5566 
5567  /* If there are no remaining stack entries, we can reset guc_dirty */
5568  guc_dirty = still_dirty;
5569 
5570  /* Update nesting level */
5571  GUCNestLevel = nestLevel - 1;
5572 }
struct guc_stack * prev
Definition: guc_tables.h:121
GucSource source
Definition: guc_tables.h:156
GucContext
Definition: guc.h:68
union config_var_val val
Definition: guc_tables.h:46
int nest_level
Definition: guc_tables.h:122
GucRealAssignHook assign_hook
Definition: guc_tables.h:217
char ** variable
Definition: guc_tables.h:228
static int GUCNestLevel
Definition: guc.c:4168
bool * variable
Definition: guc_tables.h:182
GucEnumAssignHook assign_hook
Definition: guc_tables.h:246
GucBoolAssignHook assign_hook
Definition: guc_tables.h:185
config_var_value masked
Definition: guc_tables.h:129
GucContext scontext
Definition: guc_tables.h:158
GucIntAssignHook assign_hook
Definition: guc_tables.h:201
GucSource
Definition: guc.h:105
int * variable
Definition: guc_tables.h:196
int * variable
Definition: guc_tables.h:242
void pfree(void *pointer)
Definition: mcxt.c:1031
static int num_guc_variables
Definition: guc.c:4158
static void discard_stack_value(struct config_generic *gconf, config_var_value *val)
Definition: guc.c:4383
GucSource source
Definition: guc_tables.h:124
static void set_extra_field(struct config_generic *gconf, void **field, void *newval)
Definition: guc.c:4329
struct config_generic gen
Definition: guc_tables.h:180
struct config_generic gen
Definition: guc_tables.h:194
GucContext masked_scontext
Definition: guc_tables.h:127
#define GUC_REPORT
Definition: guc.h:208
double * variable
Definition: guc_tables.h:212
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4268
static struct config_generic ** guc_variables
Definition: guc.c:4155
enum config_type vartype
Definition: guc_tables.h:154
GucContext scontext
Definition: guc_tables.h:126
struct config_generic gen
Definition: guc_tables.h:240
struct config_generic gen
Definition: guc_tables.h:226
GucStackState state
Definition: guc_tables.h:123
GucStringAssignHook assign_hook
Definition: guc_tables.h:231
#define Assert(condition)
Definition: c.h:699
#define newval
char * stringval
Definition: guc_tables.h:36
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:5608
GucStack * stack
Definition: guc_tables.h:160
double realval
Definition: guc_tables.h:35
static bool guc_dirty
Definition: guc.c:4164
config_var_value prior
Definition: guc_tables.h:128
struct config_generic gen
Definition: guc_tables.h:210

◆ AtStart_GUC()

void AtStart_GUC ( void  )

Definition at line 5265 of file guc.c.

References elog, and WARNING.

Referenced by StartTransaction().

5266 {
5267  /*
5268  * The nest level should be 0 between transactions; if it isn't, somebody
5269  * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
5270  * throw a warning but make no other effort to clean up.
5271  */
5272  if (GUCNestLevel != 0)
5273  elog(WARNING, "GUC nest level = %d at transaction start",
5274  GUCNestLevel);
5275  GUCNestLevel = 1;
5276 }
static int GUCNestLevel
Definition: guc.c:4168
#define WARNING
Definition: elog.h:40
#define elog
Definition: elog.h:219

◆ BeginReportingGUCOptions()

void BeginReportingGUCOptions ( void  )

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

5581 {
5582  int i;
5583 
5584  /*
5585  * Don't do anything unless talking to an interactive frontend of protocol
5586  * 3.0 or later.
5587  */
5588  if (whereToSendOutput != DestRemote ||
5590  return;
5591 
5592  reporting_enabled = true;
5593 
5594  /* Transmit initial values of interesting variables */
5595  for (i = 0; i < num_guc_variables; i++)
5596  {
5597  struct config_generic *conf = guc_variables[i];
5598 
5599  if (conf->flags & GUC_REPORT)
5600  ReportGUCOption(conf);
5601  }
5602 }
#define PG_PROTOCOL_MAJOR(v)
Definition: pqcomm.h:104
static int num_guc_variables
Definition: guc.c:4158
#define GUC_REPORT
Definition: guc.h:208
static struct config_generic ** guc_variables
Definition: guc.c:4155
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:5608
CommandDest whereToSendOutput
Definition: postgres.c:89
static bool reporting_enabled
Definition: guc.c:4166
ProtocolVersion FrontendProtocol
Definition: globals.c:30

◆ build_guc_variables()

void build_guc_variables ( void  )

Definition at line 4419 of file guc.c.

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

Referenced by GucInfoMain(), and InitializeGUCOptions().

4420 {
4421  int size_vars;
4422  int num_vars = 0;
4423  struct config_generic **guc_vars;
4424  int i;
4425 
4426  for (i = 0; ConfigureNamesBool[i].gen.name; i++)
4427  {
4428  struct config_bool *conf = &ConfigureNamesBool[i];
4429 
4430  /* Rather than requiring vartype to be filled in by hand, do this: */
4431  conf->gen.vartype = PGC_BOOL;
4432  num_vars++;
4433  }
4434 
4435  for (i = 0; ConfigureNamesInt[i].gen.name; i++)
4436  {
4437  struct config_int *conf = &ConfigureNamesInt[i];
4438 
4439  conf->gen.vartype = PGC_INT;
4440  num_vars++;
4441  }
4442 
4443  for (i = 0; ConfigureNamesReal[i].gen.name; i++)
4444  {
4445  struct config_real *conf = &ConfigureNamesReal[i];
4446 
4447  conf->gen.vartype = PGC_REAL;
4448  num_vars++;
4449  }
4450 
4451  for (i = 0; ConfigureNamesString[i].gen.name; i++)
4452  {
4453  struct config_string *conf = &ConfigureNamesString[i];
4454 
4455  conf->gen.vartype = PGC_STRING;
4456  num_vars++;
4457  }
4458 
4459  for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
4460  {
4461  struct config_enum *conf = &ConfigureNamesEnum[i];
4462 
4463  conf->gen.vartype = PGC_ENUM;
4464  num_vars++;
4465  }
4466 
4467  /*
4468  * Create table with 20% slack
4469  */
4470  size_vars = num_vars + num_vars / 4;
4471 
4472  guc_vars = (struct config_generic **)
4473  guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
4474 
4475  num_vars = 0;
4476 
4477  for (i = 0; ConfigureNamesBool[i].gen.name; i++)
4478  guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
4479 
4480  for (i = 0; ConfigureNamesInt[i].gen.name; i++)
4481  guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
4482 
4483  for (i = 0; ConfigureNamesReal[i].gen.name; i++)
4484  guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
4485 
4486  for (i = 0; ConfigureNamesString[i].gen.name; i++)
4487  guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
4488 
4489  for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
4490  guc_vars[num_vars++] = &ConfigureNamesEnum[i].gen;
4491 
4492  if (guc_variables)
4494  guc_variables = guc_vars;
4495  num_guc_variables = num_vars;
4496  size_guc_variables = size_vars;
4498  sizeof(struct config_generic *), guc_var_compare);
4499 }
static struct config_int ConfigureNamesInt[]
Definition: guc.c:1810
const char * name
Definition: guc_tables.h:147
static struct config_enum ConfigureNamesEnum[]
Definition: guc.c:3869
static struct config_bool ConfigureNamesBool[]
Definition: guc.c:808
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:4641
static int num_guc_variables
Definition: guc.c:4158
#define FATAL
Definition: elog.h:52
struct config_generic gen
Definition: guc_tables.h:180
struct config_generic gen
Definition: guc_tables.h:194
static struct config_generic ** guc_variables
Definition: guc.c:4155
enum config_type vartype
Definition: guc_tables.h:154
static int size_guc_variables
Definition: guc.c:4161
static struct config_real ConfigureNamesReal[]
Definition: guc.c:3043
struct config_generic gen
Definition: guc_tables.h:240
struct config_generic gen
Definition: guc_tables.h:226
#define free(a)
Definition: header.h:65
static struct config_string ConfigureNamesString[]
Definition: guc.c:3244
int i
#define qsort(a, b, c, d)
Definition: port.h:421
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4196
struct config_generic gen
Definition: guc_tables.h:210

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

10036 {
10037  /* Quick success if no hook */
10038  if (!conf->check_hook)
10039  return true;
10040 
10041  /* Reset variables that might be set by hook */
10042  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
10043  GUC_check_errmsg_string = NULL;
10045  GUC_check_errhint_string = NULL;
10046 
10047  if (!conf->check_hook(newval, extra, source))
10048  {
10049  ereport(elevel,
10053  errmsg("invalid value for parameter \"%s\": %d",
10054  conf->gen.name, (int) *newval),
10058  errhint("%s", GUC_check_errhint_string) : 0));
10059  /* Flush any strings created in ErrorContext */
10060  FlushErrorState();
10061  return false;
10062  }
10063 
10064  return true;
10065 }
char * GUC_check_errhint_string
Definition: guc.c:134
GucSource source
Definition: guc_tables.h:156
int errhint(const char *fmt,...)
Definition: elog.c:987
const char * name
Definition: guc_tables.h:147
int errcode(int sqlerrcode)
Definition: elog.c:575
static int GUC_check_errcode_value
Definition: guc.c:129
void FlushErrorState(void)
Definition: elog.c:1587
int errdetail_internal(const char *fmt,...)
Definition: elog.c:900
struct config_generic gen
Definition: guc_tables.h:180
char * GUC_check_errdetail_string
Definition: guc.c:133
#define ereport(elevel, rest)
Definition: elog.h:122
static int elevel
Definition: vacuumlazy.c:144
GucBoolCheckHook check_hook
Definition: guc_tables.h:184
int errmsg_internal(const char *fmt,...)
Definition: elog.c:827
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:132
int errmsg(const char *fmt,...)
Definition: elog.c:797

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

10172 {
10173  /* Quick success if no hook */
10174  if (!conf->check_hook)
10175  return true;
10176 
10177  /* Reset variables that might be set by hook */
10178  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
10179  GUC_check_errmsg_string = NULL;
10181  GUC_check_errhint_string = NULL;
10182 
10183  if (!conf->check_hook(newval, extra, source))
10184  {
10185  ereport(elevel,
10189  errmsg("invalid value for parameter \"%s\": \"%s\"",
10190  conf->gen.name,
10195  errhint("%s", GUC_check_errhint_string) : 0));
10196  /* Flush any strings created in ErrorContext */
10197  FlushErrorState();
10198  return false;
10199  }
10200 
10201  return true;
10202 }
char * GUC_check_errhint_string
Definition: guc.c:134
GucSource source
Definition: guc_tables.h:156
GucEnumCheckHook check_hook
Definition: guc_tables.h:245
int errhint(const char *fmt,...)
Definition: elog.c:987
const char * name
Definition: guc_tables.h:147
int errcode(int sqlerrcode)
Definition: elog.c:575
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5837
static int GUC_check_errcode_value
Definition: guc.c:129
void FlushErrorState(void)
Definition: elog.c:1587
int errdetail_internal(const char *fmt,...)
Definition: elog.c:900
char * GUC_check_errdetail_string
Definition: guc.c:133
#define ereport(elevel, rest)
Definition: elog.h:122
static int elevel
Definition: vacuumlazy.c:144
struct config_generic gen
Definition: guc_tables.h:240
int errmsg_internal(const char *fmt,...)
Definition: elog.c:827
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:132
int errmsg(const char *fmt,...)
Definition: elog.c:797

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

10070 {
10071  /* Quick success if no hook */
10072  if (!conf->check_hook)
10073  return true;
10074 
10075  /* Reset variables that might be set by hook */
10076  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
10077  GUC_check_errmsg_string = NULL;
10079  GUC_check_errhint_string = NULL;
10080 
10081  if (!conf->check_hook(newval, extra, source))
10082  {
10083  ereport(elevel,
10087  errmsg("invalid value for parameter \"%s\": %d",
10088  conf->gen.name, *newval),
10092  errhint("%s", GUC_check_errhint_string) : 0));
10093  /* Flush any strings created in ErrorContext */
10094  FlushErrorState();
10095  return false;
10096  }
10097 
10098  return true;
10099 }
char * GUC_check_errhint_string
Definition: guc.c:134
GucSource source
Definition: guc_tables.h:156
int errhint(const char *fmt,...)
Definition: elog.c:987
const char * name
Definition: guc_tables.h:147
int errcode(int sqlerrcode)
Definition: elog.c:575
static int GUC_check_errcode_value
Definition: guc.c:129
GucIntCheckHook check_hook
Definition: guc_tables.h:200
void FlushErrorState(void)
Definition: elog.c:1587
int errdetail_internal(const char *fmt,...)
Definition: elog.c:900
struct config_generic gen
Definition: guc_tables.h:194
char * GUC_check_errdetail_string
Definition: guc.c:133
#define ereport(elevel, rest)
Definition: elog.h:122
static int elevel
Definition: vacuumlazy.c:144
int errmsg_internal(const char *fmt,...)
Definition: elog.c:827
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:132
int errmsg(const char *fmt,...)
Definition: elog.c:797

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

10104 {
10105  /* Quick success if no hook */
10106  if (!conf->check_hook)
10107  return true;
10108 
10109  /* Reset variables that might be set by hook */
10110  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
10111  GUC_check_errmsg_string = NULL;
10113  GUC_check_errhint_string = NULL;
10114 
10115  if (!conf->check_hook(newval, extra, source))
10116  {
10117  ereport(elevel,
10121  errmsg("invalid value for parameter \"%s\": %g",
10122  conf->gen.name, *newval),
10126  errhint("%s", GUC_check_errhint_string) : 0));
10127  /* Flush any strings created in ErrorContext */
10128  FlushErrorState();
10129  return false;
10130  }
10131 
10132  return true;
10133 }
char * GUC_check_errhint_string
Definition: guc.c:134
GucSource source
Definition: guc_tables.h:156
int errhint(const char *fmt,...)
Definition: elog.c:987
const char * name
Definition: guc_tables.h:147
int errcode(int sqlerrcode)
Definition: elog.c:575
static int GUC_check_errcode_value
Definition: guc.c:129
GucRealCheckHook check_hook
Definition: guc_tables.h:216
void FlushErrorState(void)
Definition: elog.c:1587
int errdetail_internal(const char *fmt,...)
Definition: elog.c:900
char * GUC_check_errdetail_string
Definition: guc.c:133
#define ereport(elevel, rest)
Definition: elog.h:122
static int elevel
Definition: vacuumlazy.c:144
int errmsg_internal(const char *fmt,...)
Definition: elog.c:827
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:132
int errmsg(const char *fmt,...)
Definition: elog.c:797
struct config_generic gen
Definition: guc_tables.h:210

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

10138 {
10139  /* Quick success if no hook */
10140  if (!conf->check_hook)
10141  return true;
10142 
10143  /* Reset variables that might be set by hook */
10144  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
10145  GUC_check_errmsg_string = NULL;
10147  GUC_check_errhint_string = NULL;
10148 
10149  if (!conf->check_hook(newval, extra, source))
10150  {
10151  ereport(elevel,
10155  errmsg("invalid value for parameter \"%s\": \"%s\"",
10156  conf->gen.name, *newval ? *newval : ""),
10160  errhint("%s", GUC_check_errhint_string) : 0));
10161  /* Flush any strings created in ErrorContext */
10162  FlushErrorState();
10163  return false;
10164  }
10165 
10166  return true;
10167 }
char * GUC_check_errhint_string
Definition: guc.c:134
GucSource source
Definition: guc_tables.h:156
int errhint(const char *fmt,...)
Definition: elog.c:987
const char * name
Definition: guc_tables.h:147
GucStringCheckHook check_hook
Definition: guc_tables.h:230
int errcode(int sqlerrcode)
Definition: elog.c:575
static int GUC_check_errcode_value
Definition: guc.c:129
void FlushErrorState(void)
Definition: elog.c:1587
int errdetail_internal(const char *fmt,...)
Definition: elog.c:900
char * GUC_check_errdetail_string
Definition: guc.c:133
#define ereport(elevel, rest)
Definition: elog.h:122
static int elevel
Definition: vacuumlazy.c:144
struct config_generic gen
Definition: guc_tables.h:226
int errmsg_internal(const char *fmt,...)
Definition: elog.c:827
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:132
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ can_skip_gucvar()

static bool can_skip_gucvar ( struct config_generic gconf)
static

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

9241 {
9242  return gconf->context == PGC_POSTMASTER ||
9243  gconf->context == PGC_INTERNAL || gconf->source == PGC_S_DEFAULT ||
9244  strcmp(gconf->name, "role") == 0;
9245 }
GucSource source
Definition: guc_tables.h:156
const char * name
Definition: guc_tables.h:147
GucContext context
Definition: guc_tables.h:148

◆ check_application_name()

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

Definition at line 10696 of file guc.c.

10697 {
10698  /* Only allow clean ASCII chars in the application name */
10699  char *p;
10700 
10701  for (p = *newval; *p; p++)
10702  {
10703  if (*p < 32 || *p > 126)
10704  *p = '?';
10705  }
10706 
10707  return true;
10708 }
#define newval

◆ check_autovacuum_max_workers()

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

Definition at line 10598 of file guc.c.

References MAX_BACKENDS, max_worker_processes, and MaxConnections.

10599 {
10601  return false;
10602  return true;
10603 }
#define MAX_BACKENDS
Definition: postmaster.h:75
int MaxConnections
Definition: globals.c:133
#define newval
int max_worker_processes
Definition: globals.c:134

◆ check_autovacuum_work_mem()

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

Definition at line 10606 of file guc.c.

10607 {
10608  /*
10609  * -1 indicates fallback.
10610  *
10611  * If we haven't yet changed the boot_val default of -1, just let it be.
10612  * Autovacuum will look to maintenance_work_mem instead.
10613  */
10614  if (*newval == -1)
10615  return true;
10616 
10617  /*
10618  * We clamp manually-set values to at least 1MB. Since
10619  * maintenance_work_mem is always set to at least this value, do the same
10620  * here.
10621  */
10622  if (*newval < 1024)
10623  *newval = 1024;
10624 
10625  return true;
10626 }
#define newval

◆ check_bonjour()

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

Definition at line 10398 of file guc.c.

References GUC_check_errmsg.

10399 {
10400 #ifndef USE_BONJOUR
10401  if (*newval)
10402  {
10403  GUC_check_errmsg("Bonjour is not supported by this build");
10404  return false;
10405  }
10406 #endif
10407  return true;
10408 }
#define GUC_check_errmsg
Definition: guc.h:406
#define newval

◆ check_canonical_path()

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

Definition at line 10449 of file guc.c.

References canonicalize_path().

10450 {
10451  /*
10452  * Since canonicalize_path never enlarges the string, we can just modify
10453  * newval in-place. But watch out for NULL, which is the default value
10454  * for external_pid_file.
10455  */
10456  if (*newval)
10458  return true;
10459 }
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 10718 of file guc.c.

10719 {
10720  /* Only allow clean ASCII chars in the cluster name */
10721  char *p;
10722 
10723  for (p = *newval; *p; p++)
10724  {
10725  if (*p < 32 || *p > 126)
10726  *p = '?';
10727  }
10728 
10729  return true;
10730 }
#define newval

◆ check_effective_io_concurrency()

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

Definition at line 10637 of file guc.c.

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

10638 {
10639 #ifdef USE_PREFETCH
10640  double new_prefetch_pages;
10641 
10642  if (ComputeIoConcurrency(*newval, &new_prefetch_pages))
10643  {
10644  int *myextra = (int *) guc_malloc(ERROR, sizeof(int));
10645 
10646  *myextra = (int) rint(new_prefetch_pages);
10647  *extra = (void *) myextra;
10648 
10649  return true;
10650  }
10651  else
10652  return false;
10653 #else
10654  return true;
10655 #endif /* USE_PREFETCH */
10656 }
bool ComputeIoConcurrency(int io_concurrency, double *target)
Definition: bufmgr.c:467
#define ERROR
Definition: elog.h:43
double rint(double x)
Definition: rint.c:22
#define newval
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4196

◆ check_log_destination()

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

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

10291 {
10292  char *rawstring;
10293  List *elemlist;
10294  ListCell *l;
10295  int newlogdest = 0;
10296  int *myextra;
10297 
10298  /* Need a modifiable copy of string */
10299  rawstring = pstrdup(*newval);
10300 
10301  /* Parse string into list of identifiers */
10302  if (!SplitIdentifierString(rawstring, ',', &elemlist))
10303  {
10304  /* syntax error in list */
10305  GUC_check_errdetail("List syntax is invalid.");
10306  pfree(rawstring);
10307  list_free(elemlist);
10308  return false;
10309  }
10310 
10311  foreach(l, elemlist)
10312  {
10313  char *tok = (char *) lfirst(l);
10314 
10315  if (pg_strcasecmp(tok, "stderr") == 0)
10316  newlogdest |= LOG_DESTINATION_STDERR;
10317  else if (pg_strcasecmp(tok, "csvlog") == 0)
10318  newlogdest |= LOG_DESTINATION_CSVLOG;
10319 #ifdef HAVE_SYSLOG
10320  else if (pg_strcasecmp(tok, "syslog") == 0)
10321  newlogdest |= LOG_DESTINATION_SYSLOG;
10322 #endif
10323 #ifdef WIN32
10324  else if (pg_strcasecmp(tok, "eventlog") == 0)
10325  newlogdest |= LOG_DESTINATION_EVENTLOG;
10326 #endif
10327  else
10328  {
10329  GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
10330  pfree(rawstring);
10331  list_free(elemlist);
10332  return false;
10333  }
10334  }
10335 
10336  pfree(rawstring);
10337  list_free(elemlist);
10338 
10339  myextra = (int *) guc_malloc(ERROR, sizeof(int));
10340  *myextra = newlogdest;
10341  *extra = (void *) myextra;
10342 
10343  return true;
10344 }
#define LOG_DESTINATION_EVENTLOG
Definition: elog.h:397
#define GUC_check_errdetail
Definition: guc.h:410
char * pstrdup(const char *in)
Definition: mcxt.c:1161
#define LOG_DESTINATION_SYSLOG
Definition: elog.h:396
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
void pfree(void *pointer)
Definition: mcxt.c:1031
#define ERROR
Definition: elog.h:43
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3290
#define LOG_DESTINATION_CSVLOG
Definition: elog.h:398
#define LOG_DESTINATION_STDERR
Definition: elog.h:395
#define lfirst(lc)
Definition: pg_list.h:106
#define newval
void list_free(List *list)
Definition: list.c:1133
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4196
Definition: pg_list.h:45

◆ check_log_stats()

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

Definition at line 10435 of file guc.c.

References GUC_check_errdetail.

10436 {
10437  if (*newval &&
10439  {
10440  GUC_check_errdetail("Cannot enable \"log_statement_stats\" when "
10441  "\"log_parser_stats\", \"log_planner_stats\", "
10442  "or \"log_executor_stats\" is true.");
10443  return false;
10444  }
10445  return true;
10446 }
bool log_parser_stats
Definition: guc.c:440
#define GUC_check_errdetail
Definition: guc.h:410
#define newval
bool log_executor_stats
Definition: guc.c:442
bool log_planner_stats
Definition: guc.c:441

◆ check_max_worker_processes()

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

Definition at line 10629 of file guc.c.

References autovacuum_max_workers, MAX_BACKENDS, and MaxConnections.

10630 {
10632  return false;
10633  return true;
10634 }
#define MAX_BACKENDS
Definition: postmaster.h:75
int MaxConnections
Definition: globals.c:133
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 10589 of file guc.c.

References autovacuum_max_workers, MAX_BACKENDS, and max_worker_processes.

10590 {
10591  if (*newval + autovacuum_max_workers + 1 +
10593  return false;
10594  return true;
10595 }
#define MAX_BACKENDS
Definition: postmaster.h:75
int autovacuum_max_workers
Definition: autovacuum.c:114
#define newval
int max_worker_processes
Definition: globals.c:134

◆ check_ssl()

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

Definition at line 10411 of file guc.c.

References GUC_check_errmsg.

10412 {
10413 #ifndef USE_SSL
10414  if (*newval)
10415  {
10416  GUC_check_errmsg("SSL is not supported by this build");
10417  return false;
10418  }
10419 #endif
10420  return true;
10421 }
#define GUC_check_errmsg
Definition: guc.h:406
#define newval

◆ check_stage_log_stats()

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

Definition at line 10424 of file guc.c.

References GUC_check_errdetail.

10425 {
10426  if (*newval && log_statement_stats)
10427  {
10428  GUC_check_errdetail("Cannot enable parameter when \"log_statement_stats\" is true.");
10429  return false;
10430  }
10431  return true;
10432 }
bool log_statement_stats
Definition: guc.c:443
#define GUC_check_errdetail
Definition: guc.h:410
#define newval

◆ check_temp_buffers()

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

Definition at line 10384 of file guc.c.

References GUC_check_errdetail, and NLocBuffer.

10385 {
10386  /*
10387  * Once local buffers have been initialized, it's too late to change this.
10388  */
10389  if (NLocBuffer && NLocBuffer != *newval)
10390  {
10391  GUC_check_errdetail("\"temp_buffers\" cannot be changed after any temporary tables have been accessed in the session.");
10392  return false;
10393  }
10394  return true;
10395 }
#define GUC_check_errdetail
Definition: guc.h:410
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 10462 of file guc.c.

References Assert, load_tzoffsets(), and PGC_S_DEFAULT.

10463 {
10464  /*
10465  * The boot_val given above for timezone_abbreviations is NULL. When we
10466  * see this we just do nothing. If this value isn't overridden from the
10467  * config file then pg_timezone_abbrev_initialize() will eventually
10468  * replace it with "Default". This hack has two purposes: to avoid
10469  * wasting cycles loading values that might soon be overridden from the
10470  * config file, and to avoid trying to read the timezone abbrev files
10471  * during InitializeGUCOptions(). The latter doesn't work in an
10472  * EXEC_BACKEND subprocess because my_exec_path hasn't been set yet and so
10473  * we can't locate PGSHAREDIR.
10474  */
10475  if (*newval == NULL)
10476  {
10478  return true;
10479  }
10480 
10481  /* OK, load the file and produce a malloc'd TimeZoneAbbrevTable */
10483 
10484  /* tzparser.c returns NULL on failure, reporting via GUC_check_errmsg */
10485  if (!*extra)
10486  return false;
10487 
10488  return true;
10489 }
GucSource source
Definition: guc_tables.h:156
TimeZoneAbbrevTable * load_tzoffsets(const char *filename)
Definition: tzparser.c:438
#define Assert(condition)
Definition: c.h:699
#define newval

◆ check_wal_consistency_checking()

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

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

10211 {
10212  char *rawstring;
10213  List *elemlist;
10214  ListCell *l;
10215  bool newwalconsistency[RM_MAX_ID + 1];
10216 
10217  /* Initialize the array */
10218  MemSet(newwalconsistency, 0, (RM_MAX_ID + 1) * sizeof(bool));
10219 
10220  /* Need a modifiable copy of string */
10221  rawstring = pstrdup(*newval);
10222 
10223  /* Parse string into list of identifiers */
10224  if (!SplitIdentifierString(rawstring, ',', &elemlist))
10225  {
10226  /* syntax error in list */
10227  GUC_check_errdetail("List syntax is invalid.");
10228  pfree(rawstring);
10229  list_free(elemlist);
10230  return false;
10231  }
10232 
10233  foreach(l, elemlist)
10234  {
10235  char *tok = (char *) lfirst(l);
10236  bool found = false;
10237  RmgrId rmid;
10238 
10239  /* Check for 'all'. */
10240  if (pg_strcasecmp(tok, "all") == 0)
10241  {
10242  for (rmid = 0; rmid <= RM_MAX_ID; rmid++)
10243  if (RmgrTable[rmid].rm_mask != NULL)
10244  newwalconsistency[rmid] = true;
10245  found = true;
10246  }
10247  else
10248  {
10249  /*
10250  * Check if the token matches with any individual resource
10251  * manager.
10252  */
10253  for (rmid = 0; rmid <= RM_MAX_ID; rmid++)
10254  {
10255  if (pg_strcasecmp(tok, RmgrTable[rmid].rm_name) == 0 &&
10256  RmgrTable[rmid].rm_mask != NULL)
10257  {
10258  newwalconsistency[rmid] = true;
10259  found = true;
10260  }
10261  }
10262  }
10263 
10264  /* If a valid resource manager is found, check for the next one. */
10265  if (!found)
10266  {
10267  GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
10268  pfree(rawstring);
10269  list_free(elemlist);
10270  return false;
10271  }
10272  }
10273 
10274  pfree(rawstring);
10275  list_free(elemlist);
10276 
10277  /* assign new value */
10278  *extra = guc_malloc(ERROR, (RM_MAX_ID + 1) * sizeof(bool));
10279  memcpy(*extra, newwalconsistency, (RM_MAX_ID + 1) * sizeof(bool));
10280  return true;
10281 }
#define GUC_check_errdetail
Definition: guc.h:410
char * pstrdup(const char *in)
Definition: mcxt.c:1161
const RmgrData RmgrTable[RM_MAX_ID+1]
Definition: rmgr.c:36
#define MemSet(start, val, len)
Definition: c.h:908
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
void pfree(void *pointer)
Definition: mcxt.c:1031
#define ERROR
Definition: elog.h:43
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3290
#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:106
#define newval
void list_free(List *list)
Definition: list.c:1133
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4196
Definition: pg_list.h:45

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

5888 {
5889  const struct config_enum_entry *entry;
5890  StringInfoData retstr;
5891  int seplen;
5892 
5893  initStringInfo(&retstr);
5894  appendStringInfoString(&retstr, prefix);
5895 
5896  seplen = strlen(separator);
5897  for (entry = record->options; entry && entry->name; entry++)
5898  {
5899  if (!entry->hidden)
5900  {
5901  appendStringInfoString(&retstr, entry->name);
5902  appendBinaryStringInfo(&retstr, separator, seplen);
5903  }
5904  }
5905 
5906  /*
5907  * All the entries may have been hidden, leaving the string empty if no
5908  * prefix was given. This indicates a broken GUC setup, since there is no
5909  * use for an enum without any values, so we just check to make sure we
5910  * don't write to invalid memory instead of actually trying to do
5911  * something smart with it.
5912  */
5913  if (retstr.len >= seplen)
5914  {
5915  /* Replace final separator */
5916  retstr.data[retstr.len - seplen] = '\0';
5917  retstr.len -= seplen;
5918  }
5919 
5920  appendStringInfoString(&retstr, suffix);
5921 
5922  return retstr.data;
5923 }
Definition: guc.h:164
const struct config_enum_entry * options
Definition: guc_tables.h:244
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:157
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:208
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 5860 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().

5862 {
5863  const struct config_enum_entry *entry;
5864 
5865  for (entry = record->options; entry && entry->name; entry++)
5866  {
5867  if (pg_strcasecmp(value, entry->name) == 0)
5868  {
5869  *retval = entry->val;
5870  return true;
5871  }
5872  }
5873 
5874  *retval = 0;
5875  return false;
5876 }
Definition: guc.h:164
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
const struct config_enum_entry * options
Definition: guc_tables.h:244
int val
Definition: guc.h:167
static struct @131 value
const char * name
Definition: guc.h:166

◆ config_enum_lookup_by_value()

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

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

5838 {
5839  const struct config_enum_entry *entry;
5840 
5841  for (entry = record->options; entry && entry->name; entry++)
5842  {
5843  if (entry->val == val)
5844  return entry->name;
5845  }
5846 
5847  elog(ERROR, "could not find enum option %d for %s",
5848  val, record->gen.name);
5849  return NULL; /* silence compiler */
5850 }
Definition: guc.h:164
const char * name
Definition: guc_tables.h:147
#define ERROR
Definition: elog.h:43
const struct config_enum_entry * options
Definition: guc_tables.h:244
int val
Definition: guc.h:167
struct config_generic gen
Definition: guc_tables.h:240
const char * name
Definition: guc.h:166
#define elog
Definition: elog.h:219
long val
Definition: informix.c:689

◆ convert_from_base_unit()

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

Definition at line 5665 of file guc.c.

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

Referenced by _ShowOption().

5667 {
5668  const unit_conversion *table;
5669  int i;
5670 
5671  *unit = NULL;
5672 
5673  if (base_unit & GUC_UNIT_MEMORY)
5675  else
5677 
5678  for (i = 0; *table[i].unit; i++)
5679  {
5680  if (base_unit == table[i].base_unit)
5681  {
5682  /*
5683  * Accept the first conversion that divides the value evenly. We
5684  * assume that the conversions for each base unit are ordered from
5685  * greatest unit to the smallest!
5686  */
5687  if (table[i].multiplier < 0)
5688  {
5689  *value = base_value * (-table[i].multiplier);
5690  *unit = table[i].unit;
5691  break;
5692  }
5693  else if (base_value % table[i].multiplier == 0)
5694  {
5695  *value = base_value / table[i].multiplier;
5696  *unit = table[i].unit;
5697  break;
5698  }
5699  }
5700  }
5701 
5702  Assert(*unit != NULL);
5703 }
static const unit_conversion time_unit_conversion_table[]
Definition: guc.c:755
static const unit_conversion memory_unit_conversion_table[]
Definition: guc.c:723
static struct @131 value
#define Assert(condition)
Definition: c.h:699
int i
char unit[MAX_UNIT_LEN+1]
Definition: guc.c:705
#define GUC_UNIT_MEMORY
Definition: guc.h:223
int multiplier
Definition: guc.c:708

◆ convert_to_base_unit()

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

Definition at line 5632 of file guc.c.

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

Referenced by parse_int().

5634 {
5635  const unit_conversion *table;
5636  int i;
5637 
5638  if (base_unit & GUC_UNIT_MEMORY)
5640  else
5642 
5643  for (i = 0; *table[i].unit; i++)
5644  {
5645  if (base_unit == table[i].base_unit &&
5646  strcmp(unit, table[i].unit) == 0)
5647  {
5648  if (table[i].multiplier < 0)
5649  *base_value = value / (-table[i].multiplier);
5650  else
5651  *base_value = value * table[i].multiplier;
5652  return true;
5653  }
5654  }
5655  return false;
5656 }
static const unit_conversion time_unit_conversion_table[]
Definition: guc.c:755
static const unit_conversion memory_unit_conversion_table[]
Definition: guc.c:723
static struct @131 value
int i
char unit[MAX_UNIT_LEN+1]
Definition: guc.c:705
#define GUC_UNIT_MEMORY
Definition: guc.h:223
int multiplier
Definition: guc.c:708

◆ define_custom_variable()

static void define_custom_variable ( struct config_generic variable)
static

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

7801 {
7802  const char *name = variable->name;
7803  const char **nameAddr = &name;
7804  struct config_string *pHolder;
7805  struct config_generic **res;
7806 
7807  /*
7808  * See if there's a placeholder by the same name.
7809  */
7810  res = (struct config_generic **) bsearch((void *) &nameAddr,
7811  (void *) guc_variables,
7813  sizeof(struct config_generic *),
7814  guc_var_compare);
7815  if (res == NULL)
7816  {
7817  /*
7818  * No placeholder to replace, so we can just add it ... but first,
7819  * make sure it's initialized to its default value.
7820  */
7821  InitializeOneGUCOption(variable);
7822  add_guc_variable(variable, ERROR);
7823  return;
7824  }
7825 
7826  /*
7827  * This better be a placeholder
7828  */
7829  if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
7830  ereport(ERROR,
7831  (errcode(ERRCODE_INTERNAL_ERROR),
7832  errmsg("attempt to redefine parameter \"%s\"", name)));
7833 
7834  Assert((*res)->vartype == PGC_STRING);
7835  pHolder = (struct config_string *) (*res);
7836 
7837  /*
7838  * First, set the variable to its default value. We must do this even
7839  * though we intend to immediately apply a new value, since it's possible
7840  * that the new value is invalid.
7841  */
7842  InitializeOneGUCOption(variable);
7843 
7844  /*
7845  * Replace the placeholder. We aren't changing the name, so no re-sorting
7846  * is necessary
7847  */
7848  *res = variable;
7849 
7850  /*
7851  * Assign the string value(s) stored in the placeholder to the real
7852  * variable. Essentially, we need to duplicate all the active and stacked
7853  * values, but with appropriate validation and datatype adjustment.
7854  *
7855  * If an assignment fails, we report a WARNING and keep going. We don't
7856  * want to throw ERROR for bad values, because it'd bollix the add-on
7857  * module that's presumably halfway through getting loaded. In such cases
7858  * the default or previous state will become active instead.
7859  */
7860 
7861  /* First, apply the reset value if any */
7862  if (pHolder->reset_val)
7863  (void) set_config_option(name, pHolder->reset_val,
7864  pHolder->gen.reset_scontext,
7865  pHolder->gen.reset_source,
7866  GUC_ACTION_SET, true, WARNING, false);
7867  /* That should not have resulted in stacking anything */
7868  Assert(variable->stack == NULL);
7869 
7870  /* Now, apply current and stacked values, in the order they were stacked */
7871  reapply_stacked_values(variable, pHolder, pHolder->gen.stack,
7872  *(pHolder->variable),
7873  pHolder->gen.scontext, pHolder->gen.source);
7874 
7875  /* Also copy over any saved source-location information */
7876  if (pHolder->gen.sourcefile)
7877  set_config_sourcefile(name, pHolder->gen.sourcefile,
7878  pHolder->gen.sourceline);
7879 
7880  /*
7881  * Free up as much as we conveniently can of the placeholder structure.
7882  * (This neglects any stack items, so it's possible for some memory to be
7883  * leaked. Since this can only happen once per session per variable, it
7884  * doesn't seem worth spending much code on.)
7885  */
7886  set_string_field(pHolder, pHolder->variable, NULL);
7887  set_string_field(pHolder, &pHolder->reset_val, NULL);
7888 
7889  free(pHolder);
7890 }
GucSource source
Definition: guc_tables.h:156
static void static void set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
Definition: guc.c:6858
char ** variable
Definition: guc_tables.h:228
const char * name
Definition: guc_tables.h:147
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:7900
int errcode(int sqlerrcode)
Definition: elog.c:575
GucContext scontext
Definition: guc_tables.h:158
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:4641
#define ERROR
Definition: elog.h:43
static int num_guc_variables
Definition: guc.c:4158
char * sourcefile
Definition: guc_tables.h:162
GucSource reset_source
Definition: guc_tables.h:157
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:4789
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4268
#define ereport(elevel, rest)
Definition: elog.h:122
static struct config_generic ** guc_variables
Definition: guc.c:4155
#define WARNING
Definition: elog.h:40
struct config_generic gen
Definition: guc_tables.h:226
#define free(a)
Definition: header.h:65
char * reset_val
Definition: guc_tables.h:234
#define Assert(condition)
Definition: c.h:699
#define GUC_CUSTOM_PLACEHOLDER
Definition: guc.h:211
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797
GucStack * stack
Definition: guc_tables.h:160
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:6128
static bool add_guc_variable(struct config_generic *var, int elevel)
Definition: guc.c:4506
GucContext reset_scontext
Definition: guc_tables.h:159

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

7991 {
7992  struct config_bool *var;
7993 
7994  var = (struct config_bool *)
7995  init_custom_variable(name, short_desc, long_desc, context, flags,
7996  PGC_BOOL, sizeof(struct config_bool));
7997  var->variable = valueAddr;
7998  var->boot_val = bootValue;
7999  var->reset_val = bootValue;
8000  var->check_hook = check_hook;
8001  var->assign_hook = assign_hook;
8002  var->show_hook = show_hook;
8003  define_custom_variable(&var->gen);
8004 }
bool * variable
Definition: guc_tables.h:182
GucBoolAssignHook assign_hook
Definition: guc_tables.h:185
bool boot_val
Definition: guc_tables.h:183
struct config_generic gen
Definition: guc_tables.h:180
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:7740
GucBoolCheckHook check_hook
Definition: guc_tables.h:184
GucShowHook show_hook
Definition: guc_tables.h:186
const char * name
Definition: encode.c:521
bool reset_val
Definition: guc_tables.h:188
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7800

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

8103 {
8104  struct config_enum *var;
8105 
8106  var = (struct config_enum *)
8107  init_custom_variable(name, short_desc, long_desc, context, flags,
8108  PGC_ENUM, sizeof(struct config_enum));
8109  var->variable = valueAddr;
8110  var->boot_val = bootValue;
8111  var->reset_val = bootValue;
8112  var->options = options;
8113  var->check_hook = check_hook;
8114  var->assign_hook = assign_hook;
8115  var->show_hook = show_hook;
8116  define_custom_variable(&var->gen);
8117 }
GucEnumCheckHook check_hook
Definition: guc_tables.h:245
GucEnumAssignHook assign_hook
Definition: guc_tables.h:246
int * variable
Definition: guc_tables.h:242
const struct config_enum_entry * options
Definition: guc_tables.h:244
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:7740
GucShowHook show_hook
Definition: guc_tables.h:247
struct config_generic gen
Definition: guc_tables.h:240
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7800

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

8019 {
8020  struct config_int *var;
8021 
8022  var = (struct config_int *)
8023  init_custom_variable(name, short_desc, long_desc, context, flags,
8024  PGC_INT, sizeof(struct config_int));
8025  var->variable = valueAddr;
8026  var->boot_val = bootValue;
8027  var->reset_val = bootValue;
8028  var->min = minValue;
8029  var->max = maxValue;
8030  var->check_hook = check_hook;
8031  var->assign_hook = assign_hook;
8032  var->show_hook = show_hook;
8033  define_custom_variable(&var->gen);
8034 }
int boot_val
Definition: guc_tables.h:197
GucIntAssignHook assign_hook
Definition: guc_tables.h:201
GucIntCheckHook check_hook
Definition: guc_tables.h:200
GucShowHook show_hook
Definition: guc_tables.h:202
int * variable
Definition: guc_tables.h:196
struct config_generic gen
Definition: guc_tables.h:194
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:7740
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7800
int reset_val
Definition: guc_tables.h:204

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

8049 {
8050  struct config_real *var;
8051 
8052  var = (struct config_real *)
8053  init_custom_variable(name, short_desc, long_desc, context, flags,
8054  PGC_REAL, sizeof(struct config_real));
8055  var->variable = valueAddr;
8056  var->boot_val = bootValue;
8057  var->reset_val = bootValue;
8058  var->min = minValue;
8059  var->max = maxValue;
8060  var->check_hook = check_hook;
8061  var->assign_hook = assign_hook;
8062  var->show_hook = show_hook;
8063  define_custom_variable(&var->gen);
8064 }
GucRealAssignHook assign_hook
Definition: guc_tables.h:217
double reset_val
Definition: guc_tables.h:220
GucRealCheckHook check_hook
Definition: guc_tables.h:216
GucShowHook show_hook
Definition: guc_tables.h:218
double * variable
Definition: guc_tables.h:212
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:7740
double max
Definition: guc_tables.h:215
double boot_val
Definition: guc_tables.h:213
const char * name
Definition: encode.c:521
double min
Definition: guc_tables.h:214
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7800
struct config_generic gen
Definition: guc_tables.h:210

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

8077 {
8078  struct config_string *var;
8079 
8080  var = (struct config_string *)
8081  init_custom_variable(name, short_desc, long_desc, context, flags,
8082  PGC_STRING, sizeof(struct config_string));
8083  var->variable = valueAddr;
8084  var->boot_val = bootValue;
8085  var->check_hook = check_hook;
8086  var->assign_hook = assign_hook;
8087  var->show_hook = show_hook;
8088  define_custom_variable(&var->gen);
8089 }
char ** variable
Definition: guc_tables.h:228
GucStringCheckHook check_hook
Definition: guc_tables.h:230
const char * boot_val
Definition: guc_tables.h:229
GucShowHook show_hook
Definition: guc_tables.h:232
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:7740
struct config_generic gen
Definition: guc_tables.h:226
GucStringAssignHook assign_hook
Definition: guc_tables.h:231
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7800

◆ discard_stack_value()

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

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

4384 {
4385  switch (gconf->vartype)
4386  {
4387  case PGC_BOOL:
4388  case PGC_INT:
4389  case PGC_REAL:
4390  case PGC_ENUM:
4391  /* no need to do anything */
4392  break;
4393  case PGC_STRING:
4394  set_string_field((struct config_string *) gconf,
4395  &(val->val.stringval),
4396  NULL);
4397  break;
4398  }
4399  set_extra_field(gconf, &(val->extra), NULL);
4400 }
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:4329
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4268
enum config_type vartype
Definition: guc_tables.h:154
char * stringval
Definition: guc_tables.h:36

◆ do_serialize()

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

Definition at line 9375 of file guc.c.

References elog, ERROR, and vsnprintf().

Referenced by serialize_variable().

9376 {
9377  va_list vargs;
9378  int n;
9379 
9380  if (*maxbytes <= 0)
9381  elog(ERROR, "not enough space to serialize GUC state");
9382 
9383  va_start(vargs, fmt);
9384  n = vsnprintf(*destptr, *maxbytes, fmt, vargs);
9385  va_end(vargs);
9386 
9387  /*
9388  * Cater to portability hazards in the vsnprintf() return value just like
9389  * appendPQExpBufferVA() does. Note that this requires an extra byte of
9390  * slack at the end of the buffer. Since serialize_variable() ends with a
9391  * do_serialize_binary() rather than a do_serialize(), we'll always have
9392  * that slack; estimate_variable_size() need not add a byte for it.
9393  */
9394  if (n < 0 || n >= *maxbytes - 1)
9395  {
9396  if (n < 0 && errno != 0 && errno != ENOMEM)
9397  /* Shouldn't happen. Better show errno description. */
9398  elog(ERROR, "vsnprintf failed: %m");
9399  else
9400  elog(ERROR, "not enough space to serialize GUC state");
9401  }
9402 
9403  /* Shift the destptr ahead of the null terminator */
9404  *destptr += n + 1;
9405  *maxbytes -= n + 1;
9406 }
int int vsnprintf(char *str, size_t count, const char *fmt, va_list args)
#define ERROR
Definition: elog.h:43
#define elog
Definition: elog.h:219

◆ do_serialize_binary()

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

Definition at line 9410 of file guc.c.

References elog, and ERROR.

Referenced by serialize_variable().

9411 {
9412  if (valsize > *maxbytes)
9413  elog(ERROR, "not enough space to serialize GUC state");
9414 
9415  memcpy(*destptr, val, valsize);
9416  *destptr += valsize;
9417  *maxbytes -= valsize;
9418 }
#define ERROR
Definition: elog.h:43
#define elog
Definition: elog.h:219
long val
Definition: informix.c:689

◆ EmitWarningsOnPlaceholders()

void EmitWarningsOnPlaceholders ( const char *  className)

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

8121 {
8122  int classLen = strlen(className);
8123  int i;
8124 
8125  for (i = 0; i < num_guc_variables; i++)
8126  {
8127  struct config_generic *var = guc_variables[i];
8128 
8129  if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
8130  strncmp(className, var->name, classLen) == 0 &&
8131  var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
8132  {
8133  ereport(WARNING,
8134  (errcode(ERRCODE_UNDEFINED_OBJECT),
8135  errmsg("unrecognized configuration parameter \"%s\"",
8136  var->name)));
8137  }
8138  }
8139 }
const char * name
Definition: guc_tables.h:147
int errcode(int sqlerrcode)
Definition: elog.c:575
#define GUC_QUALIFIER_SEPARATOR
Definition: guc.h:199
static int num_guc_variables
Definition: guc.c:4158
#define ereport(elevel, rest)
Definition: elog.h:122
static struct config_generic ** guc_variables
Definition: guc.c:4155
#define WARNING
Definition: elog.h:40
#define GUC_CUSTOM_PLACEHOLDER
Definition: guc.h:211
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i

◆ estimate_variable_size()

static Size estimate_variable_size ( struct config_generic gconf)
static

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

9255 {
9256  Size size;
9257  Size valsize = 0;
9258 
9259  if (can_skip_gucvar(gconf))
9260  return 0;
9261 
9262  /* Name, plus trailing zero byte. */
9263  size = strlen(gconf->name) + 1;
9264 
9265  /* Get the maximum display length of the GUC value. */
9266  switch (gconf->vartype)
9267  {
9268  case PGC_BOOL:
9269  {
9270  valsize = 5; /* max(strlen('true'), strlen('false')) */
9271  }
9272  break;
9273 
9274  case PGC_INT:
9275  {
9276  struct config_int *conf = (struct config_int *) gconf;
9277 
9278  /*
9279  * Instead of getting the exact display length, use max
9280  * length. Also reduce the max length for typical ranges of
9281  * small values. Maximum value is 2147483647, i.e. 10 chars.
9282  * Include one byte for sign.
9283  */
9284  if (Abs(*conf->variable) < 1000)
9285  valsize = 3 + 1;
9286  else
9287  valsize = 10 + 1;
9288  }
9289  break;
9290 
9291  case PGC_REAL:
9292  {
9293  /*
9294  * We are going to print it with %e with REALTYPE_PRECISION
9295  * fractional digits. Account for sign, leading digit,
9296  * decimal point, and exponent with up to 3 digits. E.g.
9297  * -3.99329042340000021e+110
9298  */
9299  valsize = 1 + 1 + 1 + REALTYPE_PRECISION + 5;
9300  }
9301  break;
9302 
9303  case PGC_STRING:
9304  {
9305  struct config_string *conf = (struct config_string *) gconf;
9306 
9307  /*
9308  * If the value is NULL, we transmit it as an empty string.
9309  * Although this is not physically the same value, GUC
9310  * generally treats a NULL the same as empty string.
9311  */
9312  if (*conf->variable)
9313  valsize = strlen(*conf->variable);
9314  else
9315  valsize = 0;
9316  }
9317  break;
9318 
9319  case PGC_ENUM:
9320  {
9321  struct config_enum *conf = (struct config_enum *) gconf;
9322 
9323  valsize = strlen(config_enum_lookup_by_value(conf, *conf->variable));
9324  }
9325  break;
9326  }
9327 
9328  /* Allow space for terminating zero-byte for value */
9329  size = add_size(size, valsize + 1);
9330 
9331  if (gconf->sourcefile)
9332  size = add_size(size, strlen(gconf->sourcefile));
9333 
9334  /* Allow space for terminating zero-byte for sourcefile */
9335  size = add_size(size, 1);
9336 
9337  /* Include line whenever file is nonempty. */
9338  if (gconf->sourcefile && gconf->sourcefile[0])
9339  size = add_size(size, sizeof(gconf->sourceline));
9340 
9341  size = add_size(size, sizeof(gconf->source));
9342  size = add_size(size, sizeof(gconf->scontext));
9343 
9344  return size;
9345 }
GucSource source
Definition: guc_tables.h:156
char ** variable
Definition: guc_tables.h:228
const char * name
Definition: guc_tables.h:147
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5837
GucContext scontext
Definition: guc_tables.h:158
#define Abs(x)
Definition: c.h:863
int * variable
Definition: guc_tables.h:196
int * variable
Definition: guc_tables.h:242
char * sourcefile
Definition: guc_tables.h:162
static bool can_skip_gucvar(struct config_generic *gconf)
Definition: guc.c:9240
#define REALTYPE_PRECISION
Definition: guc.c:111
enum config_type vartype
Definition: guc_tables.h:154
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
size_t Size
Definition: c.h:433

◆ EstimateGUCStateSpace()

Size EstimateGUCStateSpace ( void  )

Definition at line 9352 of file guc.c.

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

Referenced by InitializeParallelDSM().

9353 {
9354  Size size;
9355  int i;
9356 
9357  /* Add space reqd for saving the data size of the guc state */
9358  size = sizeof(Size);
9359 
9360  /* Add up the space needed for each GUC variable */
9361  for (i = 0; i < num_guc_variables; i++)
9362  size = add_size(size,
9364 
9365  return size;
9366 }
static int num_guc_variables
Definition: guc.c:4158
static struct config_generic ** guc_variables
Definition: guc.c:4155
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
size_t Size
Definition: c.h:433
static Size estimate_variable_size(struct config_generic *gconf)
Definition: guc.c:9254
int i

◆ ExecSetVariableStmt()

void ExecSetVariableStmt ( VariableSetStmt stmt,
bool  isTopLevel 
)

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

7529 {
7531 
7532  /*
7533  * Workers synchronize these parameters at the start of the parallel
7534  * operation; then, we block SET during the operation.
7535  */
7536  if (IsInParallelMode())
7537  ereport(ERROR,
7538  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
7539  errmsg("cannot set parameters during a parallel operation")));
7540 
7541  switch (stmt->kind)
7542  {
7543  case VAR_SET_VALUE:
7544  case VAR_SET_CURRENT:
7545  if (stmt->is_local)
7546  WarnNoTransactionBlock(isTopLevel, "SET LOCAL");
7547  (void) set_config_option(stmt->name,
7548  ExtractSetVariableArgs(stmt),
7550  PGC_S_SESSION,
7551  action, true, 0, false);
7552  break;
7553  case VAR_SET_MULTI:
7554 
7555  /*
7556  * Special-case SQL syntaxes. The TRANSACTION and SESSION
7557  * CHARACTERISTICS cases effectively set more than one variable
7558  * per statement. TRANSACTION SNAPSHOT only takes one argument,
7559  * but we put it here anyway since it's a special case and not
7560  * related to any GUC variable.
7561  */
7562  if (strcmp(stmt->name, "TRANSACTION") == 0)
7563  {
7564  ListCell *head;
7565 
7566  WarnNoTransactionBlock(isTopLevel, "SET TRANSACTION");
7567 
7568  foreach(head, stmt->args)
7569  {
7570  DefElem *item = (DefElem *) lfirst(head);
7571 
7572  if (strcmp(item->defname, "transaction_isolation") == 0)
7573  SetPGVariable("transaction_isolation",
7574  list_make1(item->arg), stmt->is_local);
7575  else if (strcmp(item->defname, "transaction_read_only") == 0)
7576  SetPGVariable("transaction_read_only",
7577  list_make1(item->arg), stmt->is_local);
7578  else if (strcmp(item->defname, "transaction_deferrable") == 0)
7579  SetPGVariable("transaction_deferrable",
7580  list_make1(item->arg), stmt->is_local);
7581  else
7582  elog(ERROR, "unexpected SET TRANSACTION element: %s",
7583  item->defname);
7584  }
7585  }
7586  else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
7587  {
7588  ListCell *head;
7589 
7590  foreach(head, stmt->args)
7591  {
7592  DefElem *item = (DefElem *) lfirst(head);
7593 
7594  if (strcmp(item->defname, "transaction_isolation") == 0)
7595  SetPGVariable("default_transaction_isolation",
7596  list_make1(item->arg), stmt->is_local);
7597  else if (strcmp(item->defname, "transaction_read_only") == 0)
7598  SetPGVariable("default_transaction_read_only",
7599  list_make1(item->arg), stmt->is_local);
7600  else if (strcmp(item->defname, "transaction_deferrable") == 0)
7601  SetPGVariable("default_transaction_deferrable",
7602  list_make1(item->arg), stmt->is_local);
7603  else
7604  elog(ERROR, "unexpected SET SESSION element: %s",
7605  item->defname);
7606  }
7607  }
7608  else if (strcmp(stmt->name, "TRANSACTION SNAPSHOT") == 0)
7609  {
7610  A_Const *con = linitial_node(A_Const, stmt->args);
7611 
7612  if (stmt->is_local)
7613  ereport(ERROR,
7614  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7615  errmsg("SET LOCAL TRANSACTION SNAPSHOT is not implemented")));
7616 
7617  WarnNoTransactionBlock(isTopLevel, "SET TRANSACTION");
7618  Assert(nodeTag(&con->val) == T_String);
7619  ImportSnapshot(strVal(&con->val));
7620  }
7621  else
7622  elog(ERROR, "unexpected SET MULTI element: %s",
7623  stmt->name);
7624  break;
7625  case VAR_SET_DEFAULT:
7626  if (stmt->is_local)
7627  WarnNoTransactionBlock(isTopLevel, "SET LOCAL");
7628  /* fall through */
7629  case VAR_RESET:
7630  if (strcmp(stmt->name, "transaction_isolation") == 0)
7631  WarnNoTransactionBlock(isTopLevel, "RESET TRANSACTION");
7632 
7633  (void) set_config_option(stmt->name,
7634  NULL,
7636  PGC_S_SESSION,
7637  action, true, 0, false);
7638  break;
7639  case VAR_RESET_ALL:
7640  ResetAllOptions();
7641  break;
7642  }
7643 }
void ImportSnapshot(const char *idstr)
Definition: snapmgr.c:1430
VariableSetKind kind
Definition: parsenodes.h:1984
void WarnNoTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3213
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:575
bool superuser(void)
Definition: superuser.c:47
#define linitial_node(type, l)
Definition: pg_list.h:114
GucAction
Definition: guc.h:191
#define list_make1(x1)
Definition: pg_list.h:139
bool IsInParallelMode(void)
Definition: xact.c:905
#define ERROR
Definition: elog.h:43
Definition: guc.h:75
void ResetAllOptions(void)
Definition: guc.c:5084
#define ereport(elevel, rest)
Definition: elog.h:122
Node * arg
Definition: parsenodes.h:731
#define Assert(condition)
Definition: c.h:699
#define lfirst(lc)
Definition: pg_list.h:106
#define nodeTag(nodeptr)
Definition: nodes.h:522
int errmsg(const char *fmt,...)
Definition: elog.c:797
char * defname
Definition: parsenodes.h:730
#define elog
Definition: elog.h:219
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
Definition: guc.c:7652
Value val
Definition: parsenodes.h:289
int set_config_option(const char *name, const char *value, GucContext context, GucSource source, GucAction action, bool changeVal, int elevel, bool is_reload)
Definition: guc.c:6128
void SetPGVariable(const char *name, List *args, bool is_local)
Definition: guc.c:7672

◆ extra_field_used()

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

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

4285 {
4286  GucStack *stack;
4287 
4288  if (extra == gconf->extra)
4289  return true;
4290  switch (gconf->vartype)
4291  {
4292  case PGC_BOOL:
4293  if (extra == ((struct config_bool *) gconf)->reset_extra)
4294  return true;
4295  break;
4296  case PGC_INT:
4297  if (extra == ((struct config_int *) gconf)->reset_extra)
4298  return true;
4299  break;
4300  case PGC_REAL:
4301  if (extra == ((struct config_real *) gconf)->reset_extra)
4302  return true;
4303  break;
4304  case PGC_STRING:
4305  if (extra == ((struct config_string *) gconf)->reset_extra)
4306  return true;
4307  break;
4308  case PGC_ENUM:
4309  if (extra == ((struct config_enum *) gconf)->reset_extra)
4310  return true;
4311  break;
4312  }
4313  for (stack = gconf->stack; stack; stack = stack->prev)
4314  {
4315  if (extra == stack->prior.extra ||
4316  extra == stack->masked.extra)
4317  return true;
4318  }
4319 
4320  return false;
4321 }
struct guc_stack * prev
Definition: guc_tables.h:121
config_var_value masked
Definition: guc_tables.h:129
void * reset_extra
Definition: guc_tables.h:250
enum config_type vartype
Definition: guc_tables.h:154
config_var_value prior
Definition: guc_tables.h:128

◆ ExtractSetVariableArgs()

char* ExtractSetVariableArgs ( VariableSetStmt stmt)

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

7653 {
7654  switch (stmt->kind)
7655  {
7656  case VAR_SET_VALUE:
7657  return flatten_set_variable_args(stmt->name, stmt->args);
7658  case VAR_SET_CURRENT:
7659  return GetConfigOptionByName(stmt->name, NULL, false);
7660  default:
7661  return NULL;
7662  }
7663 }
VariableSetKind kind
Definition: parsenodes.h:1984
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:8287
static char * flatten_set_variable_args(const char *name, List *args)
Definition: guc.c:7051

◆ find_option()

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

Definition at line 4592 of file guc.c.

References add_placeholder_variable(), Assert, guc_name_compare(), GUC_QUALIFIER_SEPARATOR, guc_var_compare(), i, and name.

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

4593 {
4594  const char **key = &name;
4595  struct config_generic **res;
4596  int i;
4597 
4598  Assert(name);
4599 
4600  /*
4601  * By equating const char ** with struct config_generic *, we are assuming
4602  * the name field is first in config_generic.
4603  */
4604  res = (struct config_generic **) bsearch((void *) &key,
4605  (void *) guc_variables,
4607  sizeof(struct config_generic *),
4608  guc_var_compare);
4609  if (res)
4610  return *res;
4611 
4612  /*
4613  * See if the name is an obsolete name for a variable. We assume that the
4614  * set of supported old names is short enough that a brute-force search is
4615  * the best way.
4616  */
4617  for (i = 0; map_old_guc_names[i] != NULL; i += 2)
4618  {
4619  if (guc_name_compare(name, map_old_guc_names[i]) == 0)
4620  return find_option(map_old_guc_names[i + 1], false, elevel);
4621  }
4622 
4623  if (create_placeholders)
4624  {
4625  /*
4626  * Check if the name is qualified, and if so, add a placeholder.
4627  */
4628  if (strchr(name, GUC_QUALIFIER_SEPARATOR) != NULL)
4630  }
4631 
4632  /* Unknown name */
4633  return NULL;
4634 }
#define GUC_QUALIFIER_SEPARATOR
Definition: guc.h:199
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:4653
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:4641
static int num_guc_variables
Definition: guc.c:4158
static struct config_generic ** guc_variables
Definition: guc.c:4155
static int elevel
Definition: vacuumlazy.c:144
static const char *const map_old_guc_names[]
Definition: guc.c:4145
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4592
#define Assert(condition)
Definition: c.h:699
const char * name
Definition: encode.c:521
static struct config_generic * add_placeholder_variable(const char *name, int elevel)
Definition: guc.c:4544
int i

◆ flatten_set_variable_args()

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

Definition at line 7051 of file guc.c.

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

Referenced by ExtractSetVariableArgs(), and SetPGVariable().

7052 {
7053  struct config_generic *record;
7054  int flags;
7056  ListCell *l;
7057 
7058  /* Fast path if just DEFAULT */
7059  if (args == NIL)
7060  return NULL;
7061 
7062  /*
7063  * Get flags for the variable; if it's not known, use default flags.
7064  * (Caller might throw error later, but not our business to do so here.)
7065  */
7066  record = find_option(name, false, WARNING);
7067  if (record)
7068  flags = record->flags;
7069  else
7070  flags = 0;
7071 
7072  /* Complain if list input and non-list variable */
7073  if ((flags & GUC_LIST_INPUT) == 0 &&
7074  list_length(args) != 1)
7075  ereport(ERROR,
7076  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7077  errmsg("SET %s takes only one argument", name)));
7078 
7079  initStringInfo(&buf);
7080 
7081  /*
7082  * Each list member may be a plain A_Const node, or an A_Const within a
7083  * TypeCast; the latter case is supported only for ConstInterval arguments
7084  * (for SET TIME ZONE).
7085  */
7086  foreach(l, args)
7087  {
7088  Node *arg = (Node *) lfirst(l);
7089  char *val;
7090  TypeName *typeName = NULL;
7091  A_Const *con;
7092 
7093  if (l != list_head(args))
7094  appendStringInfoString(&buf, ", ");
7095 
7096  if (IsA(arg, TypeCast))
7097  {
7098  TypeCast *tc = (TypeCast *) arg;
7099 
7100  arg = tc->arg;
7101  typeName = tc->typeName;
7102  }
7103 
7104  if (!IsA(arg, A_Const))
7105  elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
7106  con = (A_Const *) arg;
7107 
7108  switch (nodeTag(&con->val))
7109  {
7110  case T_Integer:
7111  appendStringInfo(&buf, "%d", intVal(&con->val));
7112  break;
7113  case T_Float:
7114  /* represented as a string, so just copy it */
7115  appendStringInfoString(&buf, strVal(&con->val));
7116  break;
7117  case T_String:
7118  val = strVal(&con->val);
7119  if (typeName != NULL)
7120  {
7121  /*
7122  * Must be a ConstInterval argument for TIME ZONE. Coerce
7123  * to interval and back to normalize the value and account
7124  * for any typmod.
7125  */
7126  Oid typoid;
7127  int32 typmod;
7128  Datum interval;
7129  char *intervalout;
7130 
7131  typenameTypeIdAndMod(NULL, typeName, &typoid, &typmod);
7132  Assert(typoid == INTERVALOID);
7133 
7134  interval =
7136  CStringGetDatum(val),
7138  Int32GetDatum(typmod));
7139 
7140  intervalout =
7142  interval));
7143  appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
7144  }
7145  else
7146  {
7147  /*
7148  * Plain string literal or identifier. For quote mode,
7149  * quote it if it's not a vanilla identifier.
7150  */
7151  if (flags & GUC_LIST_QUOTE)
7153  else
7154  appendStringInfoString(&buf, val);
7155  }
7156  break;
7157  default:
7158  elog(ERROR, "unrecognized node type: %d",
7159  (int) nodeTag(&con->val));
7160  break;
7161  }
7162  }
7163 
7164  return buf.data;
7165 }
#define NIL
Definition: pg_list.h:69
#define IsA(nodeptr, _type_)
Definition: nodes.h:568
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:10488
Datum interval_in(PG_FUNCTION_ARGS)
Definition: timestamp.c:876
#define GUC_LIST_QUOTE
Definition: guc.h:205
Definition: nodes.h:517
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:575
Datum interval_out(PG_FUNCTION_ARGS)
Definition: timestamp.c:958
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:590
unsigned int Oid
Definition: postgres_ext.h:31
signed int int32
Definition: c.h:313
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:78
#define ObjectIdGetDatum(X)
Definition: postgres.h:490
#define ERROR
Definition: elog.h:43
#define DatumGetCString(X)
Definition: postgres.h:549
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:157
static char * buf
Definition: pg_test_fsync.c:67
#define CStringGetDatum(X)
Definition: postgres.h:561
static ListCell * list_head(const List *l)
Definition: pg_list.h:77
#define ereport(elevel, rest)
Definition: elog.h:122
#define DirectFunctionCall3(func, arg1, arg2, arg3)
Definition: fmgr.h:594
void initStringInfo(StringInfo str)
Definition: stringinfo.c:46
#define WARNING
Definition: elog.h:40
uintptr_t Datum
Definition: postgres.h:365
TypeName * typeName
Definition: parsenodes.h:300
void typenameTypeIdAndMod(ParseState *pstate, const TypeName *typeName, Oid *typeid_p, int32 *typmod_p)
Definition: parse_type.c:293
#define InvalidOid
Definition: postgres_ext.h:36
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4592
#define Assert(condition)
Definition: c.h:699
#define lfirst(lc)
Definition: pg_list.h:106
static int list_length(const List *l)
Definition: pg_list.h:89
const char * name
Definition: encode.c:521
#define nodeTag(nodeptr)
Definition: nodes.h:522
Definition: nodes.h:288
#define Int32GetDatum(X)
Definition: postgres.h:462
#define intVal(v)
Definition: value.h:52
int errmsg(const char *fmt,...)
Definition: elog.c:797
void * arg
#define elog
Definition: elog.h:219
Value val
Definition: parsenodes.h:289
long val
Definition: informix.c:689
#define GUC_LIST_INPUT
Definition: guc.h:204
Node * arg
Definition: parsenodes.h:299

◆ get_guc_variables()

struct config_generic** get_guc_variables ( void  )

Definition at line 4407 of file guc.c.

References guc_variables.

Referenced by GucInfoMain().

4408 {
4409  return guc_variables;
4410 }
static struct config_generic ** guc_variables
Definition: guc.c:4155

◆ GetConfigOption()

const char* GetConfigOption ( const char *  name,
bool  missing_ok,
bool  restrict_superuser 
)

Definition at line 6916 of file guc.c.

References buffer, config_enum_lookup_by_value(), ereport, errcode(), errmsg(), ERROR, find_option(), config_generic::flags, GetUserId(), GUC_SUPERUSER_ONLY, is_member_of_role(), PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_STRING, snprintf(), and config_generic::vartype.

Referenced by applyRemoteGucs(), and PostmasterMain().

6917 {
6918  struct config_generic *record;
6919  static char buffer[256];
6920 
6921  record = find_option(name, false, ERROR);
6922  if (record == NULL)
6923  {
6924  if (missing_ok)
6925  return NULL;
6926  ereport(ERROR,
6927  (errcode(ERRCODE_UNDEFINED_OBJECT),
6928  errmsg("unrecognized configuration parameter \"%s\"",
6929  name)));
6930  }
6931  if (restrict_superuser &&
6932  (record->flags & GUC_SUPERUSER_ONLY) &&
6933  !is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
6934  ereport(ERROR,
6935  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6936  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
6937  name)));
6938 
6939  switch (record->vartype)
6940  {
6941  case PGC_BOOL:
6942  return *((struct config_bool *) record)->variable ? "on" : "off";
6943 
6944  case PGC_INT:
6945  snprintf(buffer, sizeof(buffer), "%d",
6946  *((struct config_int *) record)->variable);
6947  return buffer;
6948 
6949  case PGC_REAL:
6950  snprintf(buffer, sizeof(buffer), "%g",
6951  *((struct config_real *) record)->variable);
6952  return buffer;
6953 
6954  case PGC_STRING:
6955  return *((struct config_string *) record)->variable;
6956 
6957  case PGC_ENUM:
6958  return config_enum_lookup_by_value((struct config_enum *) record,
6959  *((struct config_enum *) record)->variable);
6960  }
6961  return NULL;
6962 }
Oid GetUserId(void)
Definition: miscinit.c:379
int errcode(int sqlerrcode)
Definition: elog.c:575
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5837
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
enum config_type vartype
Definition: guc_tables.h:154
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4857
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4592
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:215
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ GetConfigOptionByName()

char* GetConfigOptionByName ( const char *  name,
const char **  varname,
bool  missing_ok 
)

Definition at line 8287 of file guc.c.

References _ShowOption(), ereport, errcode(), errmsg(), ERROR, find_option(), config_generic::flags, GetUserId(), GUC_SUPERUSER_ONLY, is_member_of_role(), and config_generic::name.

Referenced by ExtractSetVariableArgs(), GetPGVariableResultDesc(), set_config_by_name(), show_config_by_name(), show_config_by_name_missing_ok(), and ShowGUCConfigOption().

8288 {
8289  struct config_generic *record;
8290 
8291  record = find_option(name, false, ERROR);
8292  if (record == NULL)
8293  {
8294  if (missing_ok)
8295  {
8296  if (varname)
8297  *varname = NULL;
8298  return NULL;
8299  }
8300 
8301  ereport(ERROR,
8302  (errcode(ERRCODE_UNDEFINED_OBJECT),
8303  errmsg("unrecognized configuration parameter \"%s\"", name)));
8304  }
8305 
8306  if ((record->flags & GUC_SUPERUSER_ONLY) &&
8307  !is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
8308  ereport(ERROR,
8309  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
8310  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
8311  name)));
8312 
8313  if (varname)
8314  *varname = record->name;
8315 
8316  return _ShowOption(record, true);
8317 }
static char * _ShowOption(struct config_generic *record, bool use_units)
Definition: guc.c:8888
Oid GetUserId(void)
Definition: miscinit.c:379
const char * name
Definition: guc_tables.h:147
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define GUC_SUPERUSER_ONLY
Definition: guc.h:212
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4857
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4592
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ GetConfigOptionByNum()

void GetConfigOptionByNum ( int  varnum,
const char **  values,
bool noshow 
)

Definition at line 8324 of file guc.c.

References _ShowOption(), Assert, config_bool::boot_val, config_int::boot_val, config_real::boot_val, config_string::boot_val, config_enum::boot_val, buffer, config_enum_get_options(), config_enum_lookup_by_value(), config_generic::context, elog, ERROR, config_generic::flags, GetUserId(), config_generic::group, GUC_NO_SHOW_ALL, GUC_PENDING_RESTART, GUC_SUPERUSER_ONLY, GUC_UNIT_BLOCKS, GUC_UNIT_BYTE, GUC_UNIT_KB, GUC_UNIT_MB, GUC_UNIT_MEMORY, GUC_UNIT_MIN, GUC_UNIT_MS, GUC_UNIT_S, GUC_UNIT_TIME, GUC_UNIT_XBLOCKS, is_member_of_role(), config_generic::long_desc, config_int::max, config_real::max, config_int::min, config_real::min, config_generic::name, PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_S_FILE, PGC_STRING, pstrdup(), config_bool::reset_val, config_int::reset_val, config_real::reset_val, config_string::reset_val, config_enum::reset_val, config_generic::short_desc, snprintf(), config_generic::source, config_generic::sourcefile, config_generic::sourceline, config_generic::status, superuser(), and config_generic::vartype.

Referenced by show_all_settings().

8325 {
8326  char buffer[256];
8327  struct config_generic *conf;
8328 
8329  /* check requested variable number valid */
8330  Assert((varnum >= 0) && (varnum < num_guc_variables));
8331 
8332  conf = guc_variables[varnum];
8333 
8334  if (noshow)
8335  {
8336  if ((conf->flags & GUC_NO_SHOW_ALL) ||
8337  ((conf->flags & GUC_SUPERUSER_ONLY) &&
8338  !is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS)))
8339  *noshow = true;
8340  else
8341  *noshow = false;
8342  }
8343 
8344  /* first get the generic attributes */
8345 
8346  /* name */
8347  values[0] = conf->name;
8348 
8349  /* setting : use _ShowOption in order to avoid duplicating the logic */
8350  values[1] = _ShowOption(conf, false);
8351 
8352  /* unit */
8353  if (conf->vartype == PGC_INT)
8354  {
8355  switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
8356  {
8357  case GUC_UNIT_BYTE:
8358  values[2] = "B";
8359  break;
8360  case GUC_UNIT_KB:
8361  values[2] = "kB";
8362  break;
8363  case GUC_UNIT_MB:
8364  values[2] = "MB";
8365  break;
8366  case GUC_UNIT_BLOCKS:
8367  snprintf(buffer, sizeof(buffer), "%dkB", BLCKSZ / 1024);
8368  values[2] = pstrdup(buffer);
8369  break;
8370  case GUC_UNIT_XBLOCKS:
8371  snprintf(buffer, sizeof(buffer), "%dkB", XLOG_BLCKSZ / 1024);
8372  values[2] = pstrdup(buffer);
8373  break;
8374  case GUC_UNIT_MS:
8375  values[2] = "ms";
8376  break;
8377  case GUC_UNIT_S:
8378  values[2] = "s";
8379  break;
8380  case GUC_UNIT_MIN:
8381  values[2] = "min";
8382  break;
8383  case 0:
8384  values[2] = NULL;
8385  break;
8386  default:
8387  elog(ERROR, "unrecognized GUC units value: %d",
8388  conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME));
8389  values[2] = NULL;
8390  break;
8391  }
8392  }
8393  else
8394  values[2] = NULL;
8395 
8396  /* group */
8397  values[3] = config_group_names[conf->group];
8398 
8399  /* short_desc */
8400  values[4] = conf->short_desc;
8401 
8402  /* extra_desc */
8403  values[5] = conf->long_desc;
8404 
8405  /* context */
8406  values[6] = GucContext_Names[conf->context];
8407 
8408  /* vartype */
8409  values[7] = config_type_names[conf->vartype];
8410 
8411  /* source */
8412  values[8] = GucSource_Names[conf->source];
8413 
8414  /* now get the type specific attributes */
8415  switch (conf->vartype)
8416  {
8417  case PGC_BOOL:
8418  {
8419  struct config_bool *lconf = (struct config_bool *) conf;
8420 
8421  /* min_val */
8422  values[9] = NULL;
8423 
8424  /* max_val */
8425  values[10] = NULL;
8426 
8427  /* enumvals */
8428  values[11] = NULL;
8429 
8430  /* boot_val */
8431  values[12] = pstrdup(lconf->boot_val ? "on" : "off");
8432 
8433  /* reset_val */
8434  values[13] = pstrdup(lconf->reset_val ? "on" : "off");
8435  }
8436  break;
8437 
8438  case PGC_INT:
8439  {
8440  struct config_int *lconf = (struct config_int *) conf;
8441 
8442  /* min_val */
8443  snprintf(buffer, sizeof(buffer), "%d", lconf->min);
8444  values[9] = pstrdup(buffer);
8445 
8446  /* max_val */
8447  snprintf(buffer, sizeof(buffer), "%d", lconf->max);
8448  values[10] = pstrdup(buffer);
8449 
8450  /* enumvals */
8451  values[11] = NULL;
8452 
8453  /* boot_val */
8454  snprintf(buffer, sizeof(buffer), "%d", lconf->boot_val);
8455  values[12] = pstrdup(buffer);
8456 
8457  /* reset_val */
8458  snprintf(buffer, sizeof(buffer), "%d", lconf->reset_val);
8459  values[13] = pstrdup(buffer);
8460  }
8461  break;
8462 
8463  case PGC_REAL:
8464  {
8465  struct config_real *lconf = (struct config_real *) conf;
8466 
8467  /* min_val */
8468  snprintf(buffer, sizeof(buffer), "%g", lconf->min);
8469  values[9] = pstrdup(buffer);
8470 
8471  /* max_val */
8472  snprintf(buffer, sizeof(buffer), "%g", lconf->max);
8473  values[10] = pstrdup(buffer);
8474 
8475  /* enumvals */
8476  values[11] = NULL;
8477 
8478  /* boot_val */
8479  snprintf(buffer, sizeof(buffer), "%g", lconf->boot_val);
8480  values[12] = pstrdup(buffer);
8481 
8482  /* reset_val */
8483  snprintf(buffer, sizeof(buffer), "%g", lconf->reset_val);
8484  values[13] = pstrdup(buffer);
8485  }
8486  break;
8487 
8488  case PGC_STRING:
8489  {
8490  struct config_string *lconf = (struct config_string *) conf;
8491 
8492  /* min_val */
8493  values[9] = NULL;
8494 
8495  /* max_val */
8496  values[10] = NULL;
8497 
8498  /* enumvals */
8499  values[11] = NULL;
8500 
8501  /* boot_val */
8502  if (lconf->boot_val == NULL)
8503  values[12] = NULL;
8504  else
8505  values[12] = pstrdup(lconf->boot_val);
8506 
8507  /* reset_val */
8508  if (lconf->reset_val == NULL)
8509  values[13] = NULL;
8510  else
8511  values[13] = pstrdup(lconf->reset_val);
8512  }
8513  break;
8514 
8515  case PGC_ENUM:
8516  {
8517  struct config_enum *lconf = (struct config_enum *) conf;
8518 
8519  /* min_val */
8520  values[9] = NULL;
8521 
8522  /* max_val */
8523  values[10] = NULL;
8524 
8525  /* enumvals */
8526 
8527  /*
8528  * NOTE! enumvals with double quotes in them are not
8529  * supported!
8530  */
8531  values[11] = config_enum_get_options((struct config_enum *) conf,
8532  "{\"", "\"}", "\",\"");
8533 
8534  /* boot_val */
8536  lconf->boot_val));
8537 
8538  /* reset_val */
8540  lconf->reset_val));
8541  }
8542  break;
8543