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 "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 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)
 
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 97 of file guc.c.

Referenced by SelectConfigFiles().

◆ HBA_FILENAME

#define HBA_FILENAME   "pg_hba.conf"

Definition at line 98 of file guc.c.

Referenced by SelectConfigFiles().

◆ IDENT_FILENAME

#define IDENT_FILENAME   "pg_ident.conf"

Definition at line 99 of file guc.c.

Referenced by SelectConfigFiles().

◆ MAX_UNIT_LEN

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

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

Referenced by show_all_settings().

◆ PG_KRB_SRVTAB

#define PG_KRB_SRVTAB   ""

Definition at line 94 of file guc.c.

◆ REALTYPE_PRECISION

#define REALTYPE_PRECISION   17

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

8684 {
8685  char buffer[256];
8686  const char *val;
8687 
8688  switch (record->vartype)
8689  {
8690  case PGC_BOOL:
8691  {
8692  struct config_bool *conf = (struct config_bool *) record;
8693 
8694  if (conf->show_hook)
8695  val = conf->show_hook();
8696  else
8697  val = *conf->variable ? "on" : "off";
8698  }
8699  break;
8700 
8701  case PGC_INT:
8702  {
8703  struct config_int *conf = (struct config_int *) record;
8704 
8705  if (conf->show_hook)
8706  val = conf->show_hook();
8707  else
8708  {
8709  /*
8710  * Use int64 arithmetic to avoid overflows in units
8711  * conversion.
8712  */
8713  int64 result = *conf->variable;
8714  const char *unit;
8715 
8716  if (use_units && result > 0 && (record->flags & GUC_UNIT))
8717  {
8718  convert_from_base_unit(result, record->flags & GUC_UNIT,
8719  &result, &unit);
8720  }
8721  else
8722  unit = "";
8723 
8724  snprintf(buffer, sizeof(buffer), INT64_FORMAT "%s",
8725  result, unit);
8726  val = buffer;
8727  }
8728  }
8729  break;
8730 
8731  case PGC_REAL:
8732  {
8733  struct config_real *conf = (struct config_real *) record;
8734 
8735  if (conf->show_hook)
8736  val = conf->show_hook();
8737  else
8738  {
8739  snprintf(buffer, sizeof(buffer), "%g",
8740  *conf->variable);
8741  val = buffer;
8742  }
8743  }
8744  break;
8745 
8746  case PGC_STRING:
8747  {
8748  struct config_string *conf = (struct config_string *) record;
8749 
8750  if (conf->show_hook)
8751  val = conf->show_hook();
8752  else if (*conf->variable && **conf->variable)
8753  val = *conf->variable;
8754  else
8755  val = "";
8756  }
8757  break;
8758 
8759  case PGC_ENUM:
8760  {
8761  struct config_enum *conf = (struct config_enum *) record;
8762 
8763  if (conf->show_hook)
8764  val = conf->show_hook();
8765  else
8766  val = config_enum_lookup_by_value(conf, *conf->variable);
8767  }
8768  break;
8769 
8770  default:
8771  /* just to keep compiler quiet */
8772  val = "???";
8773  break;
8774  }
8775 
8776  return pstrdup(val);
8777 }
char ** variable
Definition: guc_tables.h:228
char * pstrdup(const char *in)
Definition: mcxt.c:1063
bool * variable
Definition: guc_tables.h:182
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5665
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:356
static void convert_from_base_unit(int64 base_value, int base_unit, int64 *value, const char **unit)
Definition: guc.c:5493
long val
Definition: informix.c:689

◆ add_guc_variable()

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

Definition at line 4334 of file guc.c.

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

Referenced by add_placeholder_variable(), and define_custom_variable().

4335 {
4337  {
4338  /*
4339  * Increase the vector by 25%
4340  */
4341  int size_vars = size_guc_variables + size_guc_variables / 4;
4342  struct config_generic **guc_vars;
4343 
4344  if (size_vars == 0)
4345  {
4346  size_vars = 100;
4347  guc_vars = (struct config_generic **)
4348  guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
4349  }
4350  else
4351  {
4352  guc_vars = (struct config_generic **)
4353  guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
4354  }
4355 
4356  if (guc_vars == NULL)
4357  return false; /* out of memory */
4358 
4359  guc_variables = guc_vars;
4360  size_guc_variables = size_vars;
4361  }
4364  sizeof(struct config_generic *), guc_var_compare);
4365  return true;
4366 }
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:4469
static int num_guc_variables
Definition: guc.c:3986
static void * guc_realloc(int elevel, void *old, size_t size)
Definition: guc.c:4040
static struct config_generic ** guc_variables
Definition: guc.c:3983
static int size_guc_variables
Definition: guc.c:3989
static int elevel
Definition: vacuumlazy.c:136
#define qsort(a, b, c, d)
Definition: port.h:408
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4024

◆ add_placeholder_variable()

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

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

4373 {
4374  size_t sz = sizeof(struct config_string) + sizeof(char *);
4375  struct config_string *var;
4376  struct config_generic *gen;
4377 
4378  var = (struct config_string *) guc_malloc(elevel, sz);
4379  if (var == NULL)
4380  return NULL;
4381  memset(var, 0, sz);
4382  gen = &var->gen;
4383 
4384  gen->name = guc_strdup(elevel, name);
4385  if (gen->name == NULL)
4386  {
4387  free(var);
4388  return NULL;
4389  }
4390 
4391  gen->context = PGC_USERSET;
4392  gen->group = CUSTOM_OPTIONS;
4393  gen->short_desc = "GUC placeholder variable";
4395  gen->vartype = PGC_STRING;
4396 
4397  /*
4398  * The char* is allocated at the end of the struct since we have no
4399  * 'static' place to point to. Note that the current value, as well as
4400  * the boot and reset values, start out NULL.
4401  */
4402  var->variable = (char **) (var + 1);
4403 
4404  if (!add_guc_variable((struct config_generic *) var, elevel))
4405  {
4406  free((void *) gen->name);
4407  free(var);
4408  return NULL;
4409  }
4410 
4411  return gen;
4412 }
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:4056
#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:136
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:4024
GucContext context
Definition: guc_tables.h:148
static bool add_guc_variable(struct config_generic *var, int elevel)
Definition: guc.c:4334

◆ AlterSystemSetConfigFile()

void AlterSystemSetConfigFile ( AlterSystemStmt altersysstmt)

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

7119 {
7120  char *name;
7121  char *value;
7122  bool resetall = false;
7123  ConfigVariable *head = NULL;
7124  ConfigVariable *tail = NULL;
7125  volatile int Tmpfd;
7126  char AutoConfFileName[MAXPGPATH];
7127  char AutoConfTmpFileName[MAXPGPATH];
7128 
7129  if (!superuser())
7130  ereport(ERROR,
7131  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7132  (errmsg("must be superuser to execute ALTER SYSTEM command"))));
7133 
7134  /*
7135  * Extract statement arguments
7136  */
7137  name = altersysstmt->setstmt->name;
7138 
7139  switch (altersysstmt->setstmt->kind)
7140  {
7141  case VAR_SET_VALUE:
7142  value = ExtractSetVariableArgs(altersysstmt->setstmt);
7143  break;
7144 
7145  case VAR_SET_DEFAULT:
7146  case VAR_RESET:
7147  value = NULL;
7148  break;
7149 
7150  case VAR_RESET_ALL:
7151  value = NULL;
7152  resetall = true;
7153  break;
7154 
7155  default:
7156  elog(ERROR, "unrecognized alter system stmt type: %d",
7157  altersysstmt->setstmt->kind);
7158  break;
7159  }
7160 
7161  /*
7162  * Unless it's RESET_ALL, validate the target variable and value
7163  */
7164  if (!resetall)
7165  {
7166  struct config_generic *record;
7167 
7168  record = find_option(name, false, ERROR);
7169  if (record == NULL)
7170  ereport(ERROR,
7171  (errcode(ERRCODE_UNDEFINED_OBJECT),
7172  errmsg("unrecognized configuration parameter \"%s\"",
7173  name)));
7174 
7175  /*
7176  * Don't allow parameters that can't be set in configuration files to
7177  * be set in PG_AUTOCONF_FILENAME file.
7178  */
7179  if ((record->context == PGC_INTERNAL) ||
7180  (record->flags & GUC_DISALLOW_IN_FILE) ||
7181  (record->flags & GUC_DISALLOW_IN_AUTO_FILE))
7182  ereport(ERROR,
7183  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
7184  errmsg("parameter \"%s\" cannot be changed",
7185  name)));
7186 
7187  /*
7188  * If a value is specified, verify that it's sane.
7189  */
7190  if (value)
7191  {
7192  union config_var_val newval;
7193  void *newextra = NULL;
7194 
7195  /* Check that it's acceptable for the indicated parameter */
7196  if (!parse_and_validate_value(record, name, value,
7197  PGC_S_FILE, ERROR,
7198  &newval, &newextra))
7199  ereport(ERROR,
7200  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7201  errmsg("invalid value for parameter \"%s\": \"%s\"",
7202  name, value)));
7203 
7204  if (record->vartype == PGC_STRING && newval.stringval != NULL)
7205  free(newval.stringval);
7206  if (newextra)
7207  free(newextra);
7208 
7209  /*
7210  * We must also reject values containing newlines, because the
7211  * grammar for config files doesn't support embedded newlines in
7212  * string literals.
7213  */
7214  if (strchr(value, '\n'))
7215  ereport(ERROR,
7216  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7217  errmsg("parameter value for ALTER SYSTEM must not contain a newline")));
7218  }
7219  }
7220 
7221  /*
7222  * PG_AUTOCONF_FILENAME and its corresponding temporary file are always in
7223  * the data directory, so we can reference them by simple relative paths.
7224  */
7225  snprintf(AutoConfFileName, sizeof(AutoConfFileName), "%s",
7227  snprintf(AutoConfTmpFileName, sizeof(AutoConfTmpFileName), "%s.%s",
7228  AutoConfFileName,
7229  "tmp");
7230 
7231  /*
7232  * Only one backend is allowed to operate on PG_AUTOCONF_FILENAME at a
7233  * time. Use AutoFileLock to ensure that. We must hold the lock while
7234  * reading the old file contents.
7235  */
7236  LWLockAcquire(AutoFileLock, LW_EXCLUSIVE);
7237 
7238  /*
7239  * If we're going to reset everything, then no need to open or parse the
7240  * old file. We'll just write out an empty list.
7241  */
7242  if (!resetall)
7243  {
7244  struct stat st;
7245 
7246  if (stat(AutoConfFileName, &st) == 0)
7247  {
7248  /* open old file PG_AUTOCONF_FILENAME */
7249  FILE *infile;
7250 
7251  infile = AllocateFile(AutoConfFileName, "r");
7252  if (infile == NULL)
7253  ereport(ERROR,
7255  errmsg("could not open file \"%s\": %m",
7256  AutoConfFileName)));
7257 
7258  /* parse it */
7259  if (!ParseConfigFp(infile, AutoConfFileName, 0, LOG, &head, &tail))
7260  ereport(ERROR,
7261  (errcode(ERRCODE_CONFIG_FILE_ERROR),
7262  errmsg("could not parse contents of file \"%s\"",
7263  AutoConfFileName)));
7264 
7265  FreeFile(infile);
7266  }
7267 
7268  /*
7269  * Now, replace any existing entry with the new value, or add it if
7270  * not present.
7271  */
7272  replace_auto_config_value(&head, &tail, name, value);
7273  }
7274 
7275  /*
7276  * To ensure crash safety, first write the new file data to a temp file,
7277  * then atomically rename it into place.
7278  *
7279  * If there is a temp file left over due to a previous crash, it's okay to
7280  * truncate and reuse it.
7281  */
7282  Tmpfd = BasicOpenFile(AutoConfTmpFileName,
7283  O_CREAT | O_RDWR | O_TRUNC);
7284  if (Tmpfd < 0)
7285  ereport(ERROR,
7287  errmsg("could not open file \"%s\": %m",
7288  AutoConfTmpFileName)));
7289 
7290  /*
7291  * Use a TRY block to clean up the file if we fail. Since we need a TRY
7292  * block anyway, OK to use BasicOpenFile rather than OpenTransientFile.
7293  */
7294  PG_TRY();
7295  {
7296  /* Write and sync the new contents to the temporary file */
7297  write_auto_conf_file(Tmpfd, AutoConfTmpFileName, head);
7298 
7299  /* Close before renaming; may be required on some platforms */
7300  close(Tmpfd);
7301  Tmpfd = -1;
7302 
7303  /*
7304  * As the rename is atomic operation, if any problem occurs after this
7305  * at worst it can lose the parameters set by last ALTER SYSTEM
7306  * command.
7307  */
7308  durable_rename(AutoConfTmpFileName, AutoConfFileName, ERROR);
7309  }
7310  PG_CATCH();
7311  {
7312  /* Close file first, else unlink might fail on some platforms */
7313  if (Tmpfd >= 0)
7314  close(Tmpfd);
7315 
7316  /* Unlink, but ignore any error */
7317  (void) unlink(AutoConfTmpFileName);
7318 
7319  PG_RE_THROW();
7320  }
7321  PG_END_TRY();
7322 
7323  FreeConfigVariables(head);
7324 
7325  LWLockRelease(AutoFileLock);
7326 }
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:5772
static struct @130 value
VariableSetKind kind
Definition: parsenodes.h:1981
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:1724
#define ERROR
Definition: elog.h:43
#define MAXPGPATH
VariableSetStmt * setstmt
Definition: parsenodes.h:3098
int errcode_for_file_access(void)
Definition: elog.c:598
FILE * AllocateFile(const char *name, const char *mode)
Definition: fd.c:2353
#define ereport(elevel, rest)
Definition: elog.h:122
int durable_rename(const char *oldfile, const char *newfile, int elevel)
Definition: fd.c:608
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 void write_auto_conf_file(int fd, const char *filename, ConfigVariable *head_p)
Definition: guc.c:6977
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:4420
#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:1120
#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:939
int FreeFile(FILE *file)
Definition: fd.c:2545
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:7045
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:7456
#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 10506 of file guc.c.

References pgstat_report_appname().

10507 {
10508  /* Update the pg_stat_activity view */
10510 }
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 10454 of file guc.c.

References target_prefetch_pages.

10455 {
10456 #ifdef USE_PREFETCH
10457  target_prefetch_pages = *((int *) extra);
10458 #endif /* USE_PREFETCH */
10459 }
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 10142 of file guc.c.

References Log_destination.

10143 {
10144  Log_destination = *((int *) extra);
10145 }
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 10462 of file guc.c.

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

10463 {
10464  /* check_canonical_path already canonicalized newval for us */
10465  char *dname;
10466  char *tname;
10467  char *fname;
10468 
10469  /* directory */
10470  dname = guc_malloc(ERROR, strlen(newval) + 1); /* runtime dir */
10471  sprintf(dname, "%s", newval);
10472 
10473  /* global stats */
10474  tname = guc_malloc(ERROR, strlen(newval) + 12); /* /global.tmp */
10475  sprintf(tname, "%s/global.tmp", newval);
10476  fname = guc_malloc(ERROR, strlen(newval) + 13); /* /global.stat */
10477  sprintf(fname, "%s/global.stat", newval);
10478 
10481  pgstat_stat_directory = dname;
10482  if (pgstat_stat_tmpname)
10484  pgstat_stat_tmpname = tname;
10487  pgstat_stat_filename = fname;
10488 }
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:4024

◆ assign_session_replication_role()

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

Definition at line 10168 of file guc.c.

References ResetPlanCache(), and SessionReplicationRole.

10169 {
10170  /*
10171  * Must flush the plan cache when changing replication role; but don't
10172  * flush unnecessarily.
10173  */
10175  ResetPlanCache();
10176 }
int SessionReplicationRole
Definition: trigger.c:65
void ResetPlanCache(void)
Definition: plancache.c:1860
#define newval

◆ assign_syslog_facility()

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

Definition at line 10148 of file guc.c.

10149 {
10150 #ifdef HAVE_SYSLOG
10151  set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
10152  newval);
10153 #endif
10154  /* Without syslog support, just ignore it */
10155 }
static char * syslog_ident_str
Definition: guc.c:495
#define newval

◆ assign_syslog_ident()

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

Definition at line 10158 of file guc.c.

10159 {
10160 #ifdef HAVE_SYSLOG
10161  set_syslog_parameters(newval, syslog_facility);
10162 #endif
10163  /* Without syslog support, it will always be set to "none", so ignore */
10164 }
static int syslog_facility
Definition: guc.c:160
#define newval

◆ assign_tcp_keepalives_count()

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

Definition at line 10367 of file guc.c.

References MyProcPort, and pq_setkeepalivescount().

10368 {
10369  /* See comments in assign_tcp_keepalives_idle */
10371 }
struct Port * MyProcPort
Definition: globals.c:41
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 10323 of file guc.c.

References MyProcPort, and pq_setkeepalivesidle().

10324 {
10325  /*
10326  * The kernel API provides no way to test a value without setting it; and
10327  * once we set it we might fail to unset it. So there seems little point
10328  * in fully implementing the check-then-assign GUC API for these
10329  * variables. Instead we just do the assignment on demand. pqcomm.c
10330  * reports any problems via elog(LOG).
10331  *
10332  * This approach means that the GUC value might have little to do with the
10333  * actual kernel value, so we use a show_hook that retrieves the kernel
10334  * value rather than trusting GUC's copy.
10335  */
10337 }
struct Port * MyProcPort
Definition: globals.c:41
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 10350 of file guc.c.

References MyProcPort, and pq_setkeepalivesinterval().

10351 {
10352  /* See comments in assign_tcp_keepalives_idle */
10354 }
struct Port * MyProcPort
Definition: globals.c:41
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 10287 of file guc.c.

References InstallTimeZoneAbbrevs().

10288 {
10289  /* Do nothing for the boot_val default of NULL */
10290  if (!extra)
10291  return;
10292 
10294 }
void InstallTimeZoneAbbrevs(TimeZoneAbbrevTable *tbl)
Definition: datetime.c:4603

◆ assign_wal_consistency_checking()

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

Definition at line 10079 of file guc.c.

References wal_consistency_checking.

10080 {
10081  wal_consistency_checking = (bool *) extra;
10082 }
bool * wal_consistency_checking
Definition: xlog.c:101

◆ AtEOXact_GUC()

void AtEOXact_GUC ( bool  isCommit,
int  nestLevel 
)

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

5128 {
5129  bool still_dirty;
5130  int i;
5131 
5132  /*
5133  * Note: it's possible to get here with GUCNestLevel == nestLevel-1 during
5134  * abort, if there is a failure during transaction start before
5135  * AtStart_GUC is called.
5136  */
5137  Assert(nestLevel > 0 &&
5138  (nestLevel <= GUCNestLevel ||
5139  (nestLevel == GUCNestLevel + 1 && !isCommit)));
5140 
5141  /* Quick exit if nothing's changed in this transaction */
5142  if (!guc_dirty)
5143  {
5144  GUCNestLevel = nestLevel - 1;
5145  return;
5146  }
5147 
5148  still_dirty = false;
5149  for (i = 0; i < num_guc_variables; i++)
5150  {
5151  struct config_generic *gconf = guc_variables[i];
5152  GucStack *stack;
5153 
5154  /*
5155  * Process and pop each stack entry within the nest level. To simplify
5156  * fmgr_security_definer() and other places that use GUC_ACTION_SAVE,
5157  * we allow failure exit from code that uses a local nest level to be
5158  * recovered at the surrounding transaction or subtransaction abort;
5159  * so there could be more than one stack entry to pop.
5160  */
5161  while ((stack = gconf->stack) != NULL &&
5162  stack->nest_level >= nestLevel)
5163  {
5164  GucStack *prev = stack->prev;
5165  bool restorePrior = false;
5166  bool restoreMasked = false;
5167  bool changed;
5168 
5169  /*
5170  * In this next bit, if we don't set either restorePrior or
5171  * restoreMasked, we must "discard" any unwanted fields of the
5172  * stack entries to avoid leaking memory. If we do set one of
5173  * those flags, unused fields will be cleaned up after restoring.
5174  */
5175  if (!isCommit) /* if abort, always restore prior value */
5176  restorePrior = true;
5177  else if (stack->state == GUC_SAVE)
5178  restorePrior = true;
5179  else if (stack->nest_level == 1)
5180  {
5181  /* transaction commit */
5182  if (stack->state == GUC_SET_LOCAL)
5183  restoreMasked = true;
5184  else if (stack->state == GUC_SET)
5185  {
5186  /* we keep the current active value */
5187  discard_stack_value(gconf, &stack->prior);
5188  }
5189  else /* must be GUC_LOCAL */
5190  restorePrior = true;
5191  }
5192  else if (prev == NULL ||
5193  prev->nest_level < stack->nest_level - 1)
5194  {
5195  /* decrement entry's level and do not pop it */
5196  stack->nest_level--;
5197  continue;
5198  }
5199  else
5200  {
5201  /*
5202  * We have to merge this stack entry into prev. See README for
5203  * discussion of this bit.
5204  */
5205  switch (stack->state)
5206  {
5207  case GUC_SAVE:
5208  Assert(false); /* can't get here */
5209 
5210  case GUC_SET:
5211  /* next level always becomes SET */
5212  discard_stack_value(gconf, &stack->prior);
5213  if (prev->state == GUC_SET_LOCAL)
5214  discard_stack_value(gconf, &prev->masked);
5215  prev->state = GUC_SET;
5216  break;
5217 
5218  case GUC_LOCAL:
5219  if (prev->state == GUC_SET)
5220  {
5221  /* LOCAL migrates down */
5222  prev->masked_scontext = stack->scontext;
5223  prev->masked = stack->prior;
5224  prev->state = GUC_SET_LOCAL;
5225  }
5226  else
5227  {
5228  /* else just forget this stack level */
5229  discard_stack_value(gconf, &stack->prior);
5230  }
5231  break;
5232 
5233  case GUC_SET_LOCAL:
5234  /* prior state at this level no longer wanted */
5235  discard_stack_value(gconf, &stack->prior);
5236  /* copy down the masked state */
5237  prev->masked_scontext = stack->masked_scontext;
5238  if (prev->state == GUC_SET_LOCAL)
5239  discard_stack_value(gconf, &prev->masked);
5240  prev->masked = stack->masked;
5241  prev->state = GUC_SET_LOCAL;
5242  break;
5243  }
5244  }
5245 
5246  changed = false;
5247 
5248  if (restorePrior || restoreMasked)
5249  {
5250  /* Perform appropriate restoration of the stacked value */
5251  config_var_value newvalue;
5252  GucSource newsource;
5253  GucContext newscontext;
5254 
5255  if (restoreMasked)
5256  {
5257  newvalue = stack->masked;
5258  newsource = PGC_S_SESSION;
5259  newscontext = stack->masked_scontext;
5260  }
5261  else
5262  {
5263  newvalue = stack->prior;
5264  newsource = stack->source;
5265  newscontext = stack->scontext;
5266  }
5267 
5268  switch (gconf->vartype)
5269  {
5270  case PGC_BOOL:
5271  {
5272  struct config_bool *conf = (struct config_bool *) gconf;
5273  bool newval = newvalue.val.boolval;
5274  void *newextra = newvalue.extra;
5275 
5276  if (*conf->variable != newval ||
5277  conf->gen.extra != newextra)
5278  {
5279  if (conf->assign_hook)
5280  conf->assign_hook(newval, newextra);
5281  *conf->variable = newval;
5282  set_extra_field(&conf->gen, &conf->gen.extra,
5283  newextra);
5284  changed = true;
5285  }
5286  break;
5287  }
5288  case PGC_INT:
5289  {
5290  struct config_int *conf = (struct config_int *) gconf;
5291  int newval = newvalue.val.intval;
5292  void *newextra = newvalue.extra;
5293 
5294  if (*conf->variable != newval ||
5295  conf->gen.extra != newextra)
5296  {
5297  if (conf->assign_hook)
5298  conf->assign_hook(newval, newextra);
5299  *conf->variable = newval;
5300  set_extra_field(&conf->gen, &conf->gen.extra,
5301  newextra);
5302  changed = true;
5303  }
5304  break;
5305  }
5306  case PGC_REAL:
5307  {
5308  struct config_real *conf = (struct config_real *) gconf;
5309  double newval = newvalue.val.realval;
5310  void *newextra = newvalue.extra;
5311 
5312  if (*conf->variable != newval ||
5313  conf->gen.extra != newextra)
5314  {
5315  if (conf->assign_hook)
5316  conf->assign_hook(newval, newextra);
5317  *conf->variable = newval;
5318  set_extra_field(&conf->gen, &conf->gen.extra,
5319  newextra);
5320  changed = true;
5321  }
5322  break;
5323  }
5324  case PGC_STRING:
5325  {
5326  struct config_string *conf = (struct config_string *) gconf;
5327  char *newval = newvalue.val.stringval;
5328  void *newextra = newvalue.extra;
5329 
5330  if (*conf->variable != newval ||
5331  conf->gen.extra != newextra)
5332  {
5333  if (conf->assign_hook)
5334  conf->assign_hook(newval, newextra);
5335  set_string_field(conf, conf->variable, newval);
5336  set_extra_field(&conf->gen, &conf->gen.extra,
5337  newextra);
5338  changed = true;
5339  }
5340 
5341  /*
5342  * Release stacked values if not used anymore. We
5343  * could use discard_stack_value() here, but since
5344  * we have type-specific code anyway, might as
5345  * well inline it.
5346  */
5347  set_string_field(conf, &stack->prior.val.stringval, NULL);
5348  set_string_field(conf, &stack->masked.val.stringval, NULL);
5349  break;
5350  }
5351  case PGC_ENUM:
5352  {
5353  struct config_enum *conf = (struct config_enum *) gconf;
5354  int newval = newvalue.val.enumval;
5355  void *newextra = newvalue.extra;
5356 
5357  if (*conf->variable != newval ||
5358  conf->gen.extra != newextra)
5359  {
5360  if (conf->assign_hook)
5361  conf->assign_hook(newval, newextra);
5362  *conf->variable = newval;
5363  set_extra_field(&conf->gen, &conf->gen.extra,
5364  newextra);
5365  changed = true;
5366  }
5367  break;
5368  }
5369  }
5370 
5371  /*
5372  * Release stacked extra values if not used anymore.
5373  */
5374  set_extra_field(gconf, &(stack->prior.extra), NULL);
5375  set_extra_field(gconf, &(stack->masked.extra), NULL);
5376 
5377  /* And restore source information */
5378  gconf->source = newsource;
5379  gconf->scontext = newscontext;
5380  }
5381 
5382  /* Finish popping the state stack */
5383  gconf->stack = prev;
5384  pfree(stack);
5385 
5386  /* Report new value if we changed it */
5387  if (changed && (gconf->flags & GUC_REPORT))
5388  ReportGUCOption(gconf);
5389  } /* end of stack-popping loop */
5390 
5391  if (stack != NULL)
5392  still_dirty = true;
5393  }
5394 
5395  /* If there are no remaining stack entries, we can reset guc_dirty */
5396  guc_dirty = still_dirty;
5397 
5398  /* Update nesting level */
5399  GUCNestLevel = nestLevel - 1;
5400 }
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:3996
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:936
static int num_guc_variables
Definition: guc.c:3986
static void discard_stack_value(struct config_generic *gconf, config_var_value *val)
Definition: guc.c:4211
GucSource source
Definition: guc_tables.h:124
static void set_extra_field(struct config_generic *gconf, void **field, void *newval)
Definition: guc.c:4157
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:4096
static struct config_generic ** guc_variables
Definition: guc.c:3983
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:688
#define newval
char * stringval
Definition: guc_tables.h:36
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:5436
GucStack * stack
Definition: guc_tables.h:160
double realval
Definition: guc_tables.h:35
static bool guc_dirty
Definition: guc.c:3992
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 5093 of file guc.c.

References elog, and WARNING.

Referenced by StartTransaction().

5094 {
5095  /*
5096  * The nest level should be 0 between transactions; if it isn't, somebody
5097  * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
5098  * throw a warning but make no other effort to clean up.
5099  */
5100  if (GUCNestLevel != 0)
5101  elog(WARNING, "GUC nest level = %d at transaction start",
5102  GUCNestLevel);
5103  GUCNestLevel = 1;
5104 }
static int GUCNestLevel
Definition: guc.c:3996
#define WARNING
Definition: elog.h:40
#define elog
Definition: elog.h:219

◆ BeginReportingGUCOptions()

void BeginReportingGUCOptions ( void  )

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

5409 {
5410  int i;
5411 
5412  /*
5413  * Don't do anything unless talking to an interactive frontend of protocol
5414  * 3.0 or later.
5415  */
5416  if (whereToSendOutput != DestRemote ||
5418  return;
5419 
5420  reporting_enabled = true;
5421 
5422  /* Transmit initial values of interesting variables */
5423  for (i = 0; i < num_guc_variables; i++)
5424  {
5425  struct config_generic *conf = guc_variables[i];
5426 
5427  if (conf->flags & GUC_REPORT)
5428  ReportGUCOption(conf);
5429  }
5430 }
#define PG_PROTOCOL_MAJOR(v)
Definition: pqcomm.h:104
static int num_guc_variables
Definition: guc.c:3986
#define GUC_REPORT
Definition: guc.h:208
static struct config_generic ** guc_variables
Definition: guc.c:3983
int i
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:5436
CommandDest whereToSendOutput
Definition: postgres.c:88
static bool reporting_enabled
Definition: guc.c:3994
ProtocolVersion FrontendProtocol
Definition: globals.c:27

◆ build_guc_variables()

void build_guc_variables ( void  )

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

4248 {
4249  int size_vars;
4250  int num_vars = 0;
4251  struct config_generic **guc_vars;
4252  int i;
4253 
4254  for (i = 0; ConfigureNamesBool[i].gen.name; i++)
4255  {
4256  struct config_bool *conf = &ConfigureNamesBool[i];
4257 
4258  /* Rather than requiring vartype to be filled in by hand, do this: */
4259  conf->gen.vartype = PGC_BOOL;
4260  num_vars++;
4261  }
4262 
4263  for (i = 0; ConfigureNamesInt[i].gen.name; i++)
4264  {
4265  struct config_int *conf = &ConfigureNamesInt[i];
4266 
4267  conf->gen.vartype = PGC_INT;
4268  num_vars++;
4269  }
4270 
4271  for (i = 0; ConfigureNamesReal[i].gen.name; i++)
4272  {
4273  struct config_real *conf = &ConfigureNamesReal[i];
4274 
4275  conf->gen.vartype = PGC_REAL;
4276  num_vars++;
4277  }
4278 
4279  for (i = 0; ConfigureNamesString[i].gen.name; i++)
4280  {
4281  struct config_string *conf = &ConfigureNamesString[i];
4282 
4283  conf->gen.vartype = PGC_STRING;
4284  num_vars++;
4285  }
4286 
4287  for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
4288  {
4289  struct config_enum *conf = &ConfigureNamesEnum[i];
4290 
4291  conf->gen.vartype = PGC_ENUM;
4292  num_vars++;
4293  }
4294 
4295  /*
4296  * Create table with 20% slack
4297  */
4298  size_vars = num_vars + num_vars / 4;
4299 
4300  guc_vars = (struct config_generic **)
4301  guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
4302 
4303  num_vars = 0;
4304 
4305  for (i = 0; ConfigureNamesBool[i].gen.name; i++)
4306  guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
4307 
4308  for (i = 0; ConfigureNamesInt[i].gen.name; i++)
4309  guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
4310 
4311  for (i = 0; ConfigureNamesReal[i].gen.name; i++)
4312  guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
4313 
4314  for (i = 0; ConfigureNamesString[i].gen.name; i++)
4315  guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
4316 
4317  for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
4318  guc_vars[num_vars++] = &ConfigureNamesEnum[i].gen;
4319 
4320  if (guc_variables)
4322  guc_variables = guc_vars;
4323  num_guc_variables = num_vars;
4324  size_guc_variables = size_vars;
4326  sizeof(struct config_generic *), guc_var_compare);
4327 }
static struct config_int ConfigureNamesInt[]
Definition: guc.c:1715
const char * name
Definition: guc_tables.h:147
static struct config_enum ConfigureNamesEnum[]
Definition: guc.c:3697
static struct config_bool ConfigureNamesBool[]
Definition: guc.c:806
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:4469
static int num_guc_variables
Definition: guc.c:3986
#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:3983
enum config_type vartype
Definition: guc_tables.h:154
static int size_guc_variables
Definition: guc.c:3989
static struct config_real ConfigureNamesReal[]
Definition: guc.c:2932
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:3093
int i
#define qsort(a, b, c, d)
Definition: port.h:408
static void * guc_malloc(int elevel, size_t size)
Definition: guc.c:4024
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 9829 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().

9831 {
9832  /* Quick success if no hook */
9833  if (!conf->check_hook)
9834  return true;
9835 
9836  /* Reset variables that might be set by hook */
9837  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
9838  GUC_check_errmsg_string = NULL;
9840  GUC_check_errhint_string = NULL;
9841 
9842  if (!conf->check_hook(newval, extra, source))
9843  {
9844  ereport(elevel,
9848  errmsg("invalid value for parameter \"%s\": %d",
9849  conf->gen.name, (int) *newval),
9853  errhint("%s", GUC_check_errhint_string) : 0));
9854  /* Flush any strings created in ErrorContext */
9855  FlushErrorState();
9856  return false;
9857  }
9858 
9859  return true;
9860 }
char * GUC_check_errhint_string
Definition: guc.c:133
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:128
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:132
#define ereport(elevel, rest)
Definition: elog.h:122
static int elevel
Definition: vacuumlazy.c:136
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:131
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 9965 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().

9967 {
9968  /* Quick success if no hook */
9969  if (!conf->check_hook)
9970  return true;
9971 
9972  /* Reset variables that might be set by hook */
9973  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
9974  GUC_check_errmsg_string = NULL;
9976  GUC_check_errhint_string = NULL;
9977 
9978  if (!conf->check_hook(newval, extra, source))
9979  {
9980  ereport(elevel,
9984  errmsg("invalid value for parameter \"%s\": \"%s\"",
9985  conf->gen.name,
9990  errhint("%s", GUC_check_errhint_string) : 0));
9991  /* Flush any strings created in ErrorContext */
9992  FlushErrorState();
9993  return false;
9994  }
9995 
9996  return true;
9997 }
char * GUC_check_errhint_string
Definition: guc.c:133
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:5665
static int GUC_check_errcode_value
Definition: guc.c:128
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:132
#define ereport(elevel, rest)
Definition: elog.h:122
static int elevel
Definition: vacuumlazy.c:136
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:131
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 9863 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().

9865 {
9866  /* Quick success if no hook */
9867  if (!conf->check_hook)
9868  return true;
9869 
9870  /* Reset variables that might be set by hook */
9871  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
9872  GUC_check_errmsg_string = NULL;
9874  GUC_check_errhint_string = NULL;
9875 
9876  if (!conf->check_hook(newval, extra, source))
9877  {
9878  ereport(elevel,
9882  errmsg("invalid value for parameter \"%s\": %d",
9883  conf->gen.name, *newval),
9887  errhint("%s", GUC_check_errhint_string) : 0));
9888  /* Flush any strings created in ErrorContext */
9889  FlushErrorState();
9890  return false;
9891  }
9892 
9893  return true;
9894 }
char * GUC_check_errhint_string
Definition: guc.c:133
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:128
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:132
#define ereport(elevel, rest)
Definition: elog.h:122
static int elevel
Definition: vacuumlazy.c:136
int errmsg_internal(const char *fmt,...)
Definition: elog.c:827
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:131
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 9897 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().

9899 {
9900  /* Quick success if no hook */
9901  if (!conf->check_hook)
9902  return true;
9903 
9904  /* Reset variables that might be set by hook */
9905  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
9906  GUC_check_errmsg_string = NULL;
9908  GUC_check_errhint_string = NULL;
9909 
9910  if (!conf->check_hook(newval, extra, source))
9911  {
9912  ereport(elevel,
9916  errmsg("invalid value for parameter \"%s\": %g",
9917  conf->gen.name, *newval),
9921  errhint("%s", GUC_check_errhint_string) : 0));
9922  /* Flush any strings created in ErrorContext */
9923  FlushErrorState();
9924  return false;
9925  }
9926 
9927  return true;
9928 }
char * GUC_check_errhint_string
Definition: guc.c:133
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:128
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:132
#define ereport(elevel, rest)
Definition: elog.h:122
static int elevel
Definition: vacuumlazy.c:136
int errmsg_internal(const char *fmt,...)
Definition: elog.c:827
#define newval
char * GUC_check_errmsg_string
Definition: guc.c:131
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 9931 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().

9933 {
9934  /* Quick success if no hook */
9935  if (!conf->check_hook)
9936  return true;
9937 
9938  /* Reset variables that might be set by hook */
9939  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
9940  GUC_check_errmsg_string = NULL;
9942  GUC_check_errhint_string = NULL;
9943 
9944  if (!conf->check_hook(newval, extra, source))
9945  {
9946  ereport(elevel,
9950  errmsg("invalid value for parameter \"%s\": \"%s\"",
9951  conf->gen.name, *newval ? *newval : ""),
9955  errhint("%s", GUC_check_errhint_string) : 0));
9956  /* Flush any strings created in ErrorContext */
9957  FlushErrorState();
9958  return false;
9959  }
9960 
9961  return true;
9962 }
char * GUC_check_errhint_string
Definition: guc.c:133
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:128
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:132
#define ereport(elevel, rest)
Definition: elog.h:122
static int elevel
Definition: vacuumlazy.c:136
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:131
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 9035 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().

9036 {
9037  return gconf->context == PGC_POSTMASTER ||
9038  gconf->context == PGC_INTERNAL || gconf->source == PGC_S_DEFAULT ||
9039  strcmp(gconf->name, "role") == 0;
9040 }
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 10491 of file guc.c.

10492 {
10493  /* Only allow clean ASCII chars in the application name */
10494  char *p;
10495 
10496  for (p = *newval; *p; p++)
10497  {
10498  if (*p < 32 || *p > 126)
10499  *p = '?';
10500  }
10501 
10502  return true;
10503 }
#define newval

◆ check_autovacuum_max_workers()

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

Definition at line 10393 of file guc.c.

References MAX_BACKENDS, max_worker_processes, and MaxConnections.

10394 {
10396  return false;
10397  return true;
10398 }
#define MAX_BACKENDS
Definition: postmaster.h:75
int MaxConnections
Definition: globals.c:124
#define newval
int max_worker_processes
Definition: globals.c:125

◆ check_autovacuum_work_mem()

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

Definition at line 10401 of file guc.c.

10402 {
10403  /*
10404  * -1 indicates fallback.
10405  *
10406  * If we haven't yet changed the boot_val default of -1, just let it be.
10407  * Autovacuum will look to maintenance_work_mem instead.
10408  */
10409  if (*newval == -1)
10410  return true;
10411 
10412  /*
10413  * We clamp manually-set values to at least 1MB. Since
10414  * maintenance_work_mem is always set to at least this value, do the same
10415  * here.
10416  */
10417  if (*newval < 1024)
10418  *newval = 1024;
10419 
10420  return true;
10421 }
#define newval

◆ check_bonjour()

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

Definition at line 10193 of file guc.c.

References GUC_check_errmsg.

10194 {
10195 #ifndef USE_BONJOUR
10196  if (*newval)
10197  {
10198  GUC_check_errmsg("Bonjour is not supported by this build");
10199  return false;
10200  }
10201 #endif
10202  return true;
10203 }
#define GUC_check_errmsg
Definition: guc.h:405
#define newval

◆ check_canonical_path()

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

Definition at line 10244 of file guc.c.

References canonicalize_path().

10245 {
10246  /*
10247  * Since canonicalize_path never enlarges the string, we can just modify
10248  * newval in-place. But watch out for NULL, which is the default value
10249  * for external_pid_file.
10250  */
10251  if (*newval)
10253  return true;
10254 }
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 10513 of file guc.c.

10514 {
10515  /* Only allow clean ASCII chars in the cluster name */
10516  char *p;
10517 
10518  for (p = *newval; *p; p++)
10519  {
10520  if (*p < 32 || *p > 126)
10521  *p = '?';
10522  }
10523 
10524  return true;
10525 }
#define newval

◆ check_effective_io_concurrency()

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

Definition at line 10432 of file guc.c.

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

10433 {
10434 #ifdef USE_PREFETCH
10435  double new_prefetch_pages;
10436 
10437  if (ComputeIoConcurrency(*newval, &new_prefetch_pages))
10438  {
10439  int *myextra = (int *) guc_malloc(ERROR, sizeof(int));
10440 
10441  *myextra = (int) rint(new_prefetch_pages);
10442  *extra = (void *) myextra;
10443 
10444  return true;
10445  }
10446  else
10447  return false;
10448 #else
10449  return true;
10450 #endif /* USE_PREFETCH */
10451 }
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:4024

◆ check_log_destination()

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

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

10086 {
10087  char *rawstring;
10088  List *elemlist;
10089  ListCell *l;
10090  int newlogdest = 0;
10091  int *myextra;
10092 
10093  /* Need a modifiable copy of string */
10094  rawstring = pstrdup(*newval);
10095 
10096  /* Parse string into list of identifiers */
10097  if (!SplitIdentifierString(rawstring, ',', &elemlist))
10098  {
10099  /* syntax error in list */
10100  GUC_check_errdetail("List syntax is invalid.");
10101  pfree(rawstring);
10102  list_free(elemlist);
10103  return false;
10104  }
10105 
10106  foreach(l, elemlist)
10107  {
10108  char *tok = (char *) lfirst(l);
10109 
10110  if (pg_strcasecmp(tok, "stderr") == 0)
10111  newlogdest |= LOG_DESTINATION_STDERR;
10112  else if (pg_strcasecmp(tok, "csvlog") == 0)
10113  newlogdest |= LOG_DESTINATION_CSVLOG;
10114 #ifdef HAVE_SYSLOG
10115  else if (pg_strcasecmp(tok, "syslog") == 0)
10116  newlogdest |= LOG_DESTINATION_SYSLOG;
10117 #endif
10118 #ifdef WIN32
10119  else if (pg_strcasecmp(tok, "eventlog") == 0)
10120  newlogdest |= LOG_DESTINATION_EVENTLOG;
10121 #endif
10122  else
10123  {
10124  GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
10125  pfree(rawstring);
10126  list_free(elemlist);
10127  return false;
10128  }
10129  }
10130 
10131  pfree(rawstring);
10132  list_free(elemlist);
10133 
10134  myextra = (int *) guc_malloc(ERROR, sizeof(int));
10135  *myextra = newlogdest;
10136  *extra = (void *) myextra;
10137 
10138  return true;
10139 }
#define LOG_DESTINATION_EVENTLOG
Definition: elog.h:397
#define GUC_check_errdetail
Definition: guc.h:409
char * pstrdup(const char *in)
Definition: mcxt.c:1063
#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:936
#define ERROR
Definition: elog.h:43
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3262
#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:4024
Definition: pg_list.h:45

◆ check_log_stats()

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

Definition at line 10230 of file guc.c.

References GUC_check_errdetail.

10231 {
10232  if (*newval &&
10234  {
10235  GUC_check_errdetail("Cannot enable \"log_statement_stats\" when "
10236  "\"log_parser_stats\", \"log_planner_stats\", "
10237  "or \"log_executor_stats\" is true.");
10238  return false;
10239  }
10240  return true;
10241 }
bool log_parser_stats
Definition: guc.c:438
#define GUC_check_errdetail
Definition: guc.h:409
#define newval
bool log_executor_stats
Definition: guc.c:440
bool log_planner_stats
Definition: guc.c:439

◆ check_max_worker_processes()

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

Definition at line 10424 of file guc.c.

References autovacuum_max_workers, MAX_BACKENDS, and MaxConnections.

10425 {
10427  return false;
10428  return true;
10429 }
#define MAX_BACKENDS
Definition: postmaster.h:75
int MaxConnections
Definition: globals.c:124
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 10384 of file guc.c.

References autovacuum_max_workers, MAX_BACKENDS, and max_worker_processes.

10385 {
10386  if (*newval + autovacuum_max_workers + 1 +
10388  return false;
10389  return true;
10390 }
#define MAX_BACKENDS
Definition: postmaster.h:75
int autovacuum_max_workers
Definition: autovacuum.c:114
#define newval
int max_worker_processes
Definition: globals.c:125

◆ check_ssl()

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

Definition at line 10206 of file guc.c.

References GUC_check_errmsg.

10207 {
10208 #ifndef USE_SSL
10209  if (*newval)
10210  {
10211  GUC_check_errmsg("SSL is not supported by this build");
10212  return false;
10213  }
10214 #endif
10215  return true;
10216 }
#define GUC_check_errmsg
Definition: guc.h:405
#define newval

◆ check_stage_log_stats()

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

Definition at line 10219 of file guc.c.

References GUC_check_errdetail.

10220 {
10221  if (*newval && log_statement_stats)
10222  {
10223  GUC_check_errdetail("Cannot enable parameter when \"log_statement_stats\" is true.");
10224  return false;
10225  }
10226  return true;
10227 }
bool log_statement_stats
Definition: guc.c:441
#define GUC_check_errdetail
Definition: guc.h:409
#define newval

◆ check_temp_buffers()

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

Definition at line 10179 of file guc.c.

References GUC_check_errdetail, and NLocBuffer.

10180 {
10181  /*
10182  * Once local buffers have been initialized, it's too late to change this.
10183  */
10184  if (NLocBuffer && NLocBuffer != *newval)
10185  {
10186  GUC_check_errdetail("\"temp_buffers\" cannot be changed after any temporary tables have been accessed in the session.");
10187  return false;
10188  }
10189  return true;
10190 }
#define GUC_check_errdetail
Definition: guc.h:409
int NLocBuffer
Definition: localbuf.c:41
#define newval

◆ check_timezone_abbreviations()

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

Definition at line 10257 of file guc.c.

References Assert, load_tzoffsets(), and PGC_S_DEFAULT.

10258 {
10259  /*
10260  * The boot_val given above for timezone_abbreviations is NULL. When we
10261  * see this we just do nothing. If this value isn't overridden from the
10262  * config file then pg_timezone_abbrev_initialize() will eventually
10263  * replace it with "Default". This hack has two purposes: to avoid
10264  * wasting cycles loading values that might soon be overridden from the
10265  * config file, and to avoid trying to read the timezone abbrev files
10266  * during InitializeGUCOptions(). The latter doesn't work in an
10267  * EXEC_BACKEND subprocess because my_exec_path hasn't been set yet and so
10268  * we can't locate PGSHAREDIR.
10269  */
10270  if (*newval == NULL)
10271  {
10273  return true;
10274  }
10275 
10276  /* OK, load the file and produce a malloc'd TimeZoneAbbrevTable */
10278 
10279  /* tzparser.c returns NULL on failure, reporting via GUC_check_errmsg */
10280  if (!*extra)
10281  return false;
10282 
10283  return true;
10284 }
GucSource source
Definition: guc_tables.h:156
TimeZoneAbbrevTable * load_tzoffsets(const char *filename)
Definition: tzparser.c:438
#define Assert(condition)
Definition: c.h:688
#define newval

◆ check_wal_consistency_checking()

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

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

10006 {
10007  char *rawstring;
10008  List *elemlist;
10009  ListCell *l;
10010  bool newwalconsistency[RM_MAX_ID + 1];
10011 
10012  /* Initialize the array */
10013  MemSet(newwalconsistency, 0, (RM_MAX_ID + 1) * sizeof(bool));
10014 
10015  /* Need a modifiable copy of string */
10016  rawstring = pstrdup(*newval);
10017 
10018  /* Parse string into list of identifiers */
10019  if (!SplitIdentifierString(rawstring, ',', &elemlist))
10020  {
10021  /* syntax error in list */
10022  GUC_check_errdetail("List syntax is invalid.");
10023  pfree(rawstring);
10024  list_free(elemlist);
10025  return false;
10026  }
10027 
10028  foreach(l, elemlist)
10029  {
10030  char *tok = (char *) lfirst(l);
10031  bool found = false;
10032  RmgrId rmid;
10033 
10034  /* Check for 'all'. */
10035  if (pg_strcasecmp(tok, "all") == 0)
10036  {
10037  for (rmid = 0; rmid <= RM_MAX_ID; rmid++)
10038  if (RmgrTable[rmid].rm_mask != NULL)
10039  newwalconsistency[rmid] = true;
10040  found = true;
10041  }
10042  else
10043  {
10044  /*
10045  * Check if the token matches with any individual resource
10046  * manager.
10047  */
10048  for (rmid = 0; rmid <= RM_MAX_ID; rmid++)
10049  {
10050  if (pg_strcasecmp(tok, RmgrTable[rmid].rm_name) == 0 &&
10051  RmgrTable[rmid].rm_mask != NULL)
10052  {
10053  newwalconsistency[rmid] = true;
10054  found = true;
10055  }
10056  }
10057  }
10058 
10059  /* If a valid resource manager is found, check for the next one. */
10060  if (!found)
10061  {
10062  GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
10063  pfree(rawstring);
10064  list_free(elemlist);
10065  return false;
10066  }
10067  }
10068 
10069  pfree(rawstring);
10070  list_free(elemlist);
10071 
10072  /* assign new value */
10073  *extra = guc_malloc(ERROR, (RM_MAX_ID + 1) * sizeof(bool));
10074  memcpy(*extra, newwalconsistency, (RM_MAX_ID + 1) * sizeof(bool));
10075  return true;
10076 }
#define GUC_check_errdetail
Definition: guc.h:409
char * pstrdup(const char *in)
Definition: mcxt.c:1063
const RmgrData RmgrTable[RM_MAX_ID+1]
Definition: rmgr.c:36
#define MemSet(start, val, len)
Definition: c.h:897
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
void pfree(void *pointer)
Definition: mcxt.c:936
#define ERROR
Definition: elog.h:43
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3262
#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:4024
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 5714 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().

5716 {
5717  const struct config_enum_entry *entry;
5718  StringInfoData retstr;
5719  int seplen;
5720 
5721  initStringInfo(&retstr);
5722  appendStringInfoString(&retstr, prefix);
5723 
5724  seplen = strlen(separator);
5725  for (entry = record->options; entry && entry->name; entry++)
5726  {
5727  if (!entry->hidden)
5728  {
5729  appendStringInfoString(&retstr, entry->name);
5730  appendBinaryStringInfo(&retstr, separator, seplen);
5731  }
5732  }
5733 
5734  /*
5735  * All the entries may have been hidden, leaving the string empty if no
5736  * prefix was given. This indicates a broken GUC setup, since there is no
5737  * use for an enum without any values, so we just check to make sure we
5738  * don't write to invalid memory instead of actually trying to do
5739  * something smart with it.
5740  */
5741  if (retstr.len >= seplen)
5742  {
5743  /* Replace final separator */
5744  retstr.data[retstr.len - seplen] = '\0';
5745  retstr.len -= seplen;
5746  }
5747 
5748  appendStringInfoString(&retstr, suffix);
5749 
5750  return retstr.data;
5751 }
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 5688 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().

5690 {
5691  const struct config_enum_entry *entry;
5692 
5693  for (entry = record->options; entry && entry->name; entry++)
5694  {
5695  if (pg_strcasecmp(value, entry->name) == 0)
5696  {
5697  *retval = entry->val;
5698  return true;
5699  }
5700  }
5701 
5702  *retval = 0;
5703  return false;
5704 }
static struct @130 value
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
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 5665 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().

5666 {
5667  const struct config_enum_entry *entry;
5668 
5669  for (entry = record->options; entry && entry->name; entry++)
5670  {
5671  if (entry->val == val)
5672  return entry->name;
5673  }
5674 
5675  elog(ERROR, "could not find enum option %d for %s",
5676  val, record->gen.name);
5677  return NULL; /* silence compiler */
5678 }
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 5493 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().

5495 {
5496  const unit_conversion *table;
5497  int i;
5498 
5499  *unit = NULL;
5500 
5501  if (base_unit & GUC_UNIT_MEMORY)
5503  else
5505 
5506  for (i = 0; *table[i].unit; i++)
5507  {
5508  if (base_unit == table[i].base_unit)
5509  {
5510  /*
5511  * Accept the first conversion that divides the value evenly. We
5512  * assume that the conversions for each base unit are ordered from
5513  * greatest unit to the smallest!
5514  */
5515  if (table[i].multiplier < 0)
5516  {
5517  *value = base_value * (-table[i].multiplier);
5518  *unit = table[i].unit;
5519  break;
5520  }
5521  else if (base_value % table[i].multiplier == 0)
5522  {
5523  *value = base_value / table[i].multiplier;
5524  *unit = table[i].unit;
5525  break;
5526  }
5527  }
5528  }
5529 
5530  Assert(*unit != NULL);
5531 }
static const unit_conversion time_unit_conversion_table[]
Definition: guc.c:753
static const unit_conversion memory_unit_conversion_table[]
Definition: guc.c:721
static struct @130 value
#define Assert(condition)
Definition: c.h:688
int i
char unit[MAX_UNIT_LEN+1]
Definition: guc.c:703
#define GUC_UNIT_MEMORY
Definition: guc.h:223
int multiplier
Definition: guc.c:706

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

5462 {
5463  const unit_conversion *table;
5464  int i;
5465 
5466  if (base_unit & GUC_UNIT_MEMORY)
5468  else
5470 
5471  for (i = 0; *table[i].unit; i++)
5472  {
5473  if (base_unit == table[i].base_unit &&
5474  strcmp(unit, table[i].unit) == 0)
5475  {
5476  if (table[i].multiplier < 0)
5477  *base_value = value / (-table[i].multiplier);
5478  else
5479  *base_value = value * table[i].multiplier;
5480  return true;
5481  }
5482  }
5483  return false;
5484 }
static const unit_conversion time_unit_conversion_table[]
Definition: guc.c:753
static const unit_conversion memory_unit_conversion_table[]
Definition: guc.c:721
static struct @130 value
int i
char unit[MAX_UNIT_LEN+1]
Definition: guc.c:703
#define GUC_UNIT_MEMORY
Definition: guc.h:223
int multiplier
Definition: guc.c:706

◆ define_custom_variable()

static void define_custom_variable ( struct config_generic variable)
static

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

7596 {
7597  const char *name = variable->name;
7598  const char **nameAddr = &name;
7599  struct config_string *pHolder;
7600  struct config_generic **res;
7601 
7602  /*
7603  * See if there's a placeholder by the same name.
7604  */
7605  res = (struct config_generic **) bsearch((void *) &nameAddr,
7606  (void *) guc_variables,
7608  sizeof(struct config_generic *),
7609  guc_var_compare);
7610  if (res == NULL)
7611  {
7612  /*
7613  * No placeholder to replace, so we can just add it ... but first,
7614  * make sure it's initialized to its default value.
7615  */
7616  InitializeOneGUCOption(variable);
7617  add_guc_variable(variable, ERROR);
7618  return;
7619  }
7620 
7621  /*
7622  * This better be a placeholder
7623  */
7624  if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
7625  ereport(ERROR,
7626  (errcode(ERRCODE_INTERNAL_ERROR),
7627  errmsg("attempt to redefine parameter \"%s\"", name)));
7628 
7629  Assert((*res)->vartype == PGC_STRING);
7630  pHolder = (struct config_string *) (*res);
7631 
7632  /*
7633  * First, set the variable to its default value. We must do this even
7634  * though we intend to immediately apply a new value, since it's possible
7635  * that the new value is invalid.
7636  */
7637  InitializeOneGUCOption(variable);
7638 
7639  /*
7640  * Replace the placeholder. We aren't changing the name, so no re-sorting
7641  * is necessary
7642  */
7643  *res = variable;
7644 
7645  /*
7646  * Assign the string value(s) stored in the placeholder to the real
7647  * variable. Essentially, we need to duplicate all the active and stacked
7648  * values, but with appropriate validation and datatype adjustment.
7649  *
7650  * If an assignment fails, we report a WARNING and keep going. We don't
7651  * want to throw ERROR for bad values, because it'd bollix the add-on
7652  * module that's presumably halfway through getting loaded. In such cases
7653  * the default or previous state will become active instead.
7654  */
7655 
7656  /* First, apply the reset value if any */
7657  if (pHolder->reset_val)
7658  (void) set_config_option(name, pHolder->reset_val,
7659  pHolder->gen.reset_scontext,
7660  pHolder->gen.reset_source,
7661  GUC_ACTION_SET, true, WARNING, false);
7662  /* That should not have resulted in stacking anything */
7663  Assert(variable->stack == NULL);
7664 
7665  /* Now, apply current and stacked values, in the order they were stacked */
7666  reapply_stacked_values(variable, pHolder, pHolder->gen.stack,
7667  *(pHolder->variable),
7668  pHolder->gen.scontext, pHolder->gen.source);
7669 
7670  /* Also copy over any saved source-location information */
7671  if (pHolder->gen.sourcefile)
7672  set_config_sourcefile(name, pHolder->gen.sourcefile,
7673  pHolder->gen.sourceline);
7674 
7675  /*
7676  * Free up as much as we conveniently can of the placeholder structure.
7677  * (This neglects any stack items, so it's possible for some memory to be
7678  * leaked. Since this can only happen once per session per variable, it
7679  * doesn't seem worth spending much code on.)
7680  */
7681  set_string_field(pHolder, pHolder->variable, NULL);
7682  set_string_field(pHolder, &pHolder->reset_val, NULL);
7683 
7684  free(pHolder);
7685 }
GucSource source
Definition: guc_tables.h:156
static void static void set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
Definition: guc.c:6686
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:7695
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:4469
#define ERROR
Definition: elog.h:43
static int num_guc_variables
Definition: guc.c:3986
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:4617
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4096
#define ereport(elevel, rest)
Definition: elog.h:122
static struct config_generic ** guc_variables
Definition: guc.c:3983
#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:688
#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:5956
static bool add_guc_variable(struct config_generic *var, int elevel)
Definition: guc.c:4334
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 7776 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().

7786 {
7787  struct config_bool *var;
7788 
7789  var = (struct config_bool *)
7790  init_custom_variable(name, short_desc, long_desc, context, flags,
7791  PGC_BOOL, sizeof(struct config_bool));
7792  var->variable = valueAddr;
7793  var->boot_val = bootValue;
7794  var->reset_val = bootValue;
7795  var->check_hook = check_hook;
7796  var->assign_hook = assign_hook;
7797  var->show_hook = show_hook;
7798  define_custom_variable(&var->gen);
7799 }
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:7544
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:7595

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

7898 {
7899  struct config_enum *var;
7900 
7901  var = (struct config_enum *)
7902  init_custom_variable(name, short_desc, long_desc, context, flags,
7903  PGC_ENUM, sizeof(struct config_enum));
7904  var->variable = valueAddr;
7905  var->boot_val = bootValue;
7906  var->reset_val = bootValue;
7907  var->options = options;
7908  var->check_hook = check_hook;
7909  var->assign_hook = assign_hook;
7910  var->show_hook = show_hook;
7911  define_custom_variable(&var->gen);
7912 }
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:7544
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:7595

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

7814 {
7815  struct config_int *var;
7816 
7817  var = (struct config_int *)
7818  init_custom_variable(name, short_desc, long_desc, context, flags,
7819  PGC_INT, sizeof(struct config_int));
7820  var->variable = valueAddr;
7821  var->boot_val = bootValue;
7822  var->reset_val = bootValue;
7823  var->min = minValue;
7824  var->max = maxValue;
7825  var->check_hook = check_hook;
7826  var->assign_hook = assign_hook;
7827  var->show_hook = show_hook;
7828  define_custom_variable(&var->gen);
7829 }
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:7544
const char * name
Definition: encode.c:521
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:7595
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 7832 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().

7844 {
7845  struct config_real *var;
7846 
7847  var = (struct config_real *)
7848  init_custom_variable(name, short_desc, long_desc, context, flags,
7849  PGC_REAL, sizeof(struct config_real));
7850  var->variable = valueAddr;
7851  var->boot_val = bootValue;
7852  var->reset_val = bootValue;
7853  var->min = minValue;
7854  var->max = maxValue;
7855  var->check_hook = check_hook;
7856  var->assign_hook = assign_hook;
7857  var->show_hook = show_hook;
7858  define_custom_variable(&var->gen);
7859 }
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:7544
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:7595
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 7862 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().

7872 {
7873  struct config_string *var;
7874 
7875  var = (struct config_string *)
7876  init_custom_variable(name, short_desc, long_desc, context, flags,
7877  PGC_STRING, sizeof(struct config_string));
7878  var->variable = valueAddr;
7879  var->boot_val = bootValue;
7880  var->check_hook = check_hook;
7881  var->assign_hook = assign_hook;
7882  var->show_hook = show_hook;
7883  define_custom_variable(&var->gen);
7884 }
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:7544
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:7595

◆ discard_stack_value()

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

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

4212 {
4213  switch (gconf->vartype)
4214  {
4215  case PGC_BOOL:
4216  case PGC_INT:
4217  case PGC_REAL:
4218  case PGC_ENUM:
4219  /* no need to do anything */
4220  break;
4221  case PGC_STRING:
4222  set_string_field((struct config_string *) gconf,
4223  &(val->val.stringval),
4224  NULL);
4225  break;
4226  }
4227  set_extra_field(gconf, &(val->extra), NULL);
4228 }
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:4157
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:4096
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 9170 of file guc.c.

References elog, ERROR, and vsnprintf().

Referenced by serialize_variable().

9171 {
9172  va_list vargs;
9173  int n;
9174 
9175  if (*maxbytes <= 0)
9176  elog(ERROR, "not enough space to serialize GUC state");
9177 
9178  va_start(vargs, fmt);
9179  n = vsnprintf(*destptr, *maxbytes, fmt, vargs);
9180  va_end(vargs);
9181 
9182  /*
9183  * Cater to portability hazards in the vsnprintf() return value just like
9184  * appendPQExpBufferVA() does. Note that this requires an extra byte of
9185  * slack at the end of the buffer. Since serialize_variable() ends with a
9186  * do_serialize_binary() rather than a do_serialize(), we'll always have
9187  * that slack; estimate_variable_size() need not add a byte for it.
9188  */
9189  if (n < 0 || n >= *maxbytes - 1)
9190  {
9191  if (n < 0 && errno != 0 && errno != ENOMEM)
9192  /* Shouldn't happen. Better show errno description. */
9193  elog(ERROR, "vsnprintf failed: %m");
9194  else
9195  elog(ERROR, "not enough space to serialize GUC state");
9196  }
9197 
9198  /* Shift the destptr ahead of the null terminator */
9199  *destptr += n + 1;
9200  *maxbytes -= n + 1;
9201 }
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 9205 of file guc.c.

References elog, and ERROR.

Referenced by serialize_variable().

9206 {
9207  if (valsize > *maxbytes)
9208  elog(ERROR, "not enough space to serialize GUC state");
9209 
9210  memcpy(*destptr, val, valsize);
9211  *destptr += valsize;
9212  *maxbytes -= valsize;
9213 }
#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 7915 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().

7916 {
7917  int classLen = strlen(className);
7918  int i;
7919 
7920  for (i = 0; i < num_guc_variables; i++)
7921  {
7922  struct config_generic *var = guc_variables[i];
7923 
7924  if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
7925  strncmp(className, var->name, classLen) == 0 &&
7926  var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
7927  {
7928  ereport(WARNING,
7929  (errcode(ERRCODE_UNDEFINED_OBJECT),
7930  errmsg("unrecognized configuration parameter \"%s\"",
7931  var->name)));
7932  }
7933  }
7934 }
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:3986
#define ereport(elevel, rest)
Definition: elog.h:122
static struct config_generic ** guc_variables
Definition: guc.c:3983
#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 9049 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().

9050 {
9051  Size size;
9052  Size valsize = 0;
9053 
9054  if (can_skip_gucvar(gconf))
9055  return 0;
9056 
9057  /* Name, plus trailing zero byte. */
9058  size = strlen(gconf->name) + 1;
9059 
9060  /* Get the maximum display length of the GUC value. */
9061  switch (gconf->vartype)
9062  {
9063  case PGC_BOOL:
9064  {
9065  valsize = 5; /* max(strlen('true'), strlen('false')) */
9066  }
9067  break;
9068 
9069  case PGC_INT:
9070  {
9071  struct config_int *conf = (struct config_int *) gconf;
9072 
9073  /*
9074  * Instead of getting the exact display length, use max
9075  * length. Also reduce the max length for typical ranges of
9076  * small values. Maximum value is 2147483647, i.e. 10 chars.
9077  * Include one byte for sign.
9078  */
9079  if (Abs(*conf->variable) < 1000)
9080  valsize = 3 + 1;
9081  else
9082  valsize = 10 + 1;
9083  }
9084  break;
9085 
9086  case PGC_REAL:
9087  {
9088  /*
9089  * We are going to print it with %e with REALTYPE_PRECISION
9090  * fractional digits. Account for sign, leading digit,
9091  * decimal point, and exponent with up to 3 digits. E.g.
9092  * -3.99329042340000021e+110
9093  */
9094  valsize = 1 + 1 + 1 + REALTYPE_PRECISION + 5;
9095  }
9096  break;
9097 
9098  case PGC_STRING:
9099  {
9100  struct config_string *conf = (struct config_string *) gconf;
9101 
9102  /*
9103  * If the value is NULL, we transmit it as an empty string.
9104  * Although this is not physically the same value, GUC
9105  * generally treats a NULL the same as empty string.
9106  */
9107  if (*conf->variable)
9108  valsize = strlen(*conf->variable);
9109  else
9110  valsize = 0;
9111  }
9112  break;
9113 
9114  case PGC_ENUM:
9115  {
9116  struct config_enum *conf = (struct config_enum *) gconf;
9117 
9118  valsize = strlen(config_enum_lookup_by_value(conf, *conf->variable));
9119  }
9120  break;
9121  }
9122 
9123  /* Allow space for terminating zero-byte for value */
9124  size = add_size(size, valsize + 1);
9125 
9126  if (gconf->sourcefile)
9127  size = add_size(size, strlen(gconf->sourcefile));
9128 
9129  /* Allow space for terminating zero-byte for sourcefile */
9130  size = add_size(size, 1);
9131 
9132  /* Include line whenever file is nonempty. */
9133  if (gconf->sourcefile && gconf->sourcefile[0])
9134  size = add_size(size, sizeof(gconf->sourceline));
9135 
9136  size = add_size(size, sizeof(gconf->source));
9137  size = add_size(size, sizeof(gconf->scontext));
9138 
9139  return size;
9140 }
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:5665
GucContext scontext
Definition: guc_tables.h:158
#define Abs(x)
Definition: c.h:852
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:9035
#define REALTYPE_PRECISION
Definition: guc.c:110
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:422

◆ EstimateGUCStateSpace()

Size EstimateGUCStateSpace ( void  )

Definition at line 9147 of file guc.c.

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

Referenced by InitializeParallelDSM().

9148 {
9149  Size size;
9150  int i;
9151 
9152  /* Add space reqd for saving the data size of the guc state */
9153  size = sizeof(Size);
9154 
9155  /* Add up the space needed for each GUC variable */
9156  for (i = 0; i < num_guc_variables; i++)
9157  size = add_size(size,
9159 
9160  return size;
9161 }
static int num_guc_variables
Definition: guc.c:3986
static struct config_generic ** guc_variables
Definition: guc.c:3983
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
size_t Size
Definition: c.h:422
static Size estimate_variable_size(struct config_generic *gconf)
Definition: guc.c:9049
int i

◆ ExecSetVariableStmt()

void ExecSetVariableStmt ( VariableSetStmt stmt,
bool  isTopLevel 
)

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

Referenced by standard_ProcessUtility().

7333 {
7335 
7336  /*
7337  * Workers synchronize these parameters at the start of the parallel
7338  * operation; then, we block SET during the operation.
7339  */
7340  if (IsInParallelMode())
7341  ereport(ERROR,
7342  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
7343  errmsg("cannot set parameters during a parallel operation")));
7344 
7345  switch (stmt->kind)
7346  {
7347  case VAR_SET_VALUE:
7348  case VAR_SET_CURRENT:
7349  if (stmt->is_local)
7350  WarnNoTransactionChain(isTopLevel, "SET LOCAL");
7351  (void) set_config_option(stmt->name,
7352  ExtractSetVariableArgs(stmt),
7354  PGC_S_SESSION,
7355  action, true, 0, false);
7356  break;
7357  case VAR_SET_MULTI:
7358 
7359  /*
7360  * Special-case SQL syntaxes. The TRANSACTION and SESSION
7361  * CHARACTERISTICS cases effectively set more than one variable
7362  * per statement. TRANSACTION SNAPSHOT only takes one argument,
7363  * but we put it here anyway since it's a special case and not
7364  * related to any GUC variable.
7365  */
7366  if (strcmp(stmt->name, "TRANSACTION") == 0)
7367  {
7368  ListCell *head;
7369 
7370  WarnNoTransactionChain(isTopLevel, "SET TRANSACTION");
7371 
7372  foreach(head, stmt->args)
7373  {
7374  DefElem *item = (DefElem *) lfirst(head);
7375 
7376  if (strcmp(item->defname, "transaction_isolation") == 0)
7377  SetPGVariable("transaction_isolation",
7378  list_make1(item->arg), stmt->is_local);
7379  else if (strcmp(item->defname, "transaction_read_only") == 0)
7380  SetPGVariable("transaction_read_only",
7381  list_make1(item->arg), stmt->is_local);
7382  else if (strcmp(item->defname, "transaction_deferrable") == 0)
7383  SetPGVariable("transaction_deferrable",
7384  list_make1(item->arg), stmt->is_local);
7385  else
7386  elog(ERROR, "unexpected SET TRANSACTION element: %s",
7387  item->defname);
7388  }
7389  }
7390  else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
7391  {
7392  ListCell *head;
7393 
7394  foreach(head, stmt->args)
7395  {
7396  DefElem *item = (DefElem *) lfirst(head);
7397 
7398  if (strcmp(item->defname, "transaction_isolation") == 0)
7399  SetPGVariable("default_transaction_isolation",
7400  list_make1(item->arg), stmt->is_local);
7401  else if (strcmp(item->defname, "transaction_read_only") == 0)
7402  SetPGVariable("default_transaction_read_only",
7403  list_make1(item->arg), stmt->is_local);
7404  else if (strcmp(item->defname, "transaction_deferrable") == 0)
7405  SetPGVariable("default_transaction_deferrable",
7406  list_make1(item->arg), stmt->is_local);
7407  else
7408  elog(ERROR, "unexpected SET SESSION element: %s",
7409  item->defname);
7410  }
7411  }
7412  else if (strcmp(stmt->name, "TRANSACTION SNAPSHOT") == 0)
7413  {
7414  A_Const *con = linitial_node(A_Const, stmt->args);
7415 
7416  if (stmt->is_local)
7417  ereport(ERROR,
7418  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7419  errmsg("SET LOCAL TRANSACTION SNAPSHOT is not implemented")));
7420 
7421  WarnNoTransactionChain(isTopLevel, "SET TRANSACTION");
7422  Assert(nodeTag(&con->val) == T_String);
7423  ImportSnapshot(strVal(&con->val));
7424  }
7425  else
7426  elog(ERROR, "unexpected SET MULTI element: %s",
7427  stmt->name);
7428  break;
7429  case VAR_SET_DEFAULT:
7430  if (stmt->is_local)
7431  WarnNoTransactionChain(isTopLevel, "SET LOCAL");
7432  /* fall through */
7433  case VAR_RESET:
7434  if (strcmp(stmt->name, "transaction_isolation") == 0)
7435  WarnNoTransactionChain(isTopLevel, "RESET TRANSACTION");
7436 
7437  (void) set_config_option(stmt->name,
7438  NULL,
7440  PGC_S_SESSION,
7441  action, true, 0, false);
7442  break;
7443  case VAR_RESET_ALL:
7444  ResetAllOptions();
7445  break;
7446  }
7447 }
void ImportSnapshot(const char *idstr)
Definition: snapmgr.c:1430
VariableSetKind kind
Definition: parsenodes.h:1981
#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:906
#define ERROR
Definition: elog.h:43
Definition: guc.h:75
void ResetAllOptions(void)
Definition: guc.c:4912
#define ereport(elevel, rest)
Definition: elog.h:122
Node * arg
Definition: parsenodes.h:728
void WarnNoTransactionChain(bool isTopLevel, const char *stmtType)
Definition: xact.c:3201
#define Assert(condition)
Definition: c.h:688
#define lfirst(lc)
Definition: pg_list.h:106
#define nodeTag(nodeptr)
Definition: nodes.h:518
int errmsg(const char *fmt,...)
Definition: elog.c:797
char * defname
Definition: parsenodes.h:727
#define elog
Definition: elog.h:219
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
Definition: guc.c:7456
Value val
Definition: parsenodes.h:287
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:5956
void SetPGVariable(const char *name, List *args, bool is_local)
Definition: guc.c:7476

◆ extra_field_used()

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

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

4113 {
4114  GucStack *stack;
4115 
4116  if (extra == gconf->extra)
4117  return true;
4118  switch (gconf->vartype)
4119  {
4120  case PGC_BOOL:
4121  if (extra == ((struct config_bool *) gconf)->reset_extra)
4122  return true;
4123  break;
4124  case PGC_INT:
4125  if (extra == ((struct config_int *) gconf)->reset_extra)
4126  return true;
4127  break;
4128  case PGC_REAL:
4129  if (extra == ((struct config_real *) gconf)->reset_extra)
4130  return true;
4131  break;
4132  case PGC_STRING:
4133  if (extra == ((struct config_string *) gconf)->reset_extra)
4134  return true;
4135  break;
4136  case PGC_ENUM:
4137  if (extra == ((struct config_enum *) gconf)->reset_extra)
4138  return true;
4139  break;
4140  }
4141  for (stack = gconf->stack; stack; stack = stack->prev)
4142  {
4143  if (extra == stack->prior.extra ||
4144  extra == stack->masked.extra)
4145  return true;
4146  }
4147 
4148  return false;
4149 }
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 7456 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().

7457 {
7458  switch (stmt->kind)
7459  {
7460  case VAR_SET_VALUE:
7461  return flatten_set_variable_args(stmt->name, stmt->args);
7462  case VAR_SET_CURRENT:
7463  return GetConfigOptionByName(stmt->name, NULL, false);
7464  default:
7465  return NULL;
7466  }
7467 }
VariableSetKind kind
Definition: parsenodes.h:1981
char * GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
Definition: guc.c:8082
static char * flatten_set_variable_args(const char *name, List *args)
Definition: guc.c:6855

◆ find_option()

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

Definition at line 4420 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(), GetConfigOptionResetString(), GUCArrayAdd(), GUCArrayDelete(), set_config_option(), set_config_sourcefile(), and validate_option_array_item().

4421 {
4422  const char **key = &name;
4423  struct config_generic **res;
4424  int i;
4425 
4426  Assert(name);
4427 
4428  /*
4429  * By equating const char ** with struct config_generic *, we are assuming
4430  * the name field is first in config_generic.
4431  */
4432  res = (struct config_generic **) bsearch((void *) &key,
4433  (void *) guc_variables,
4435  sizeof(struct config_generic *),
4436  guc_var_compare);
4437  if (res)
4438  return *res;
4439 
4440  /*
4441  * See if the name is an obsolete name for a variable. We assume that the
4442  * set of supported old names is short enough that a brute-force search is
4443  * the best way.
4444  */
4445  for (i = 0; map_old_guc_names[i] != NULL; i += 2)
4446  {
4447  if (guc_name_compare(name, map_old_guc_names[i]) == 0)
4448  return find_option(map_old_guc_names[i + 1], false, elevel);
4449  }
4450 
4451  if (create_placeholders)
4452  {
4453  /*
4454  * Check if the name is qualified, and if so, add a placeholder.
4455  */
4456  if (strchr(name, GUC_QUALIFIER_SEPARATOR) != NULL)
4458  }
4459 
4460  /* Unknown name */
4461  return NULL;
4462 }
#define GUC_QUALIFIER_SEPARATOR
Definition: guc.h:199
static int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:4481
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:4469
static int num_guc_variables
Definition: guc.c:3986
static struct config_generic ** guc_variables
Definition: guc.c:3983
static int elevel
Definition: vacuumlazy.c:136
static const char *const map_old_guc_names[]
Definition: guc.c:3973
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4420
#define Assert(condition)
Definition: c.h:688
const char * name
Definition: encode.c:521
static struct config_generic * add_placeholder_variable(const char *name, int elevel)
Definition: guc.c:4372
int i

◆ flatten_set_variable_args()

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

Definition at line 6855 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(), INTERVALOID, 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().

6856 {
6857  struct config_generic *record;
6858  int flags;
6860  ListCell *l;
6861 
6862  /* Fast path if just DEFAULT */
6863  if (args == NIL)
6864  return NULL;
6865 
6866  /*
6867  * Get flags for the variable; if it's not known, use default flags.
6868  * (Caller might throw error later, but not our business to do so here.)
6869  */
6870  record = find_option(name, false, WARNING);
6871  if (record)
6872  flags = record->flags;
6873  else
6874  flags = 0;
6875 
6876  /* Complain if list input and non-list variable */
6877  if ((flags & GUC_LIST_INPUT) == 0 &&
6878  list_length(args) != 1)
6879  ereport(ERROR,
6880  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6881  errmsg("SET %s takes only one argument", name)));
6882 
6883  initStringInfo(&buf);
6884 
6885  /*
6886  * Each list member may be a plain A_Const node, or an A_Const within a
6887  * TypeCast; the latter case is supported only for ConstInterval arguments
6888  * (for SET TIME ZONE).
6889  */
6890  foreach(l, args)
6891  {
6892  Node *arg = (Node *) lfirst(l);
6893  char *val;
6894  TypeName *typeName = NULL;
6895  A_Const *con;
6896 
6897  if (l != list_head(args))
6898  appendStringInfoString(&buf, ", ");
6899 
6900  if (IsA(arg, TypeCast))
6901  {
6902  TypeCast *tc = (TypeCast *) arg;
6903 
6904  arg = tc->arg;
6905  typeName = tc->typeName;
6906  }
6907 
6908  if (!IsA(arg, A_Const))
6909  elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
6910  con = (A_Const *) arg;
6911 
6912  switch (nodeTag(&con->val))
6913  {
6914  case T_Integer:
6915  appendStringInfo(&buf, "%ld", intVal(&con->val));
6916  break;
6917  case T_Float:
6918  /* represented as a string, so just copy it */
6919  appendStringInfoString(&buf, strVal(&con->val));
6920  break;
6921  case T_String:
6922  val = strVal(&con->val);
6923  if (typeName != NULL)
6924  {
6925  /*
6926  * Must be a ConstInterval argument for TIME ZONE. Coerce
6927  * to interval and back to normalize the value and account
6928  * for any typmod.
6929  */
6930  Oid typoid;
6931  int32 typmod;
6932  Datum interval;
6933  char *intervalout;
6934 
6935  typenameTypeIdAndMod(NULL, typeName, &typoid, &typmod);
6936  Assert(typoid == INTERVALOID);
6937 
6938  interval =
6940  CStringGetDatum(val),
6942  Int32GetDatum(typmod));
6943 
6944  intervalout =
6946  interval));
6947  appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
6948  }
6949  else
6950  {
6951  /*
6952  * Plain string literal or identifier. For quote mode,
6953  * quote it if it's not a vanilla identifier.
6954  */
6955  if (flags & GUC_LIST_QUOTE)
6957  else
6958  appendStringInfoString(&buf, val);
6959  }
6960  break;
6961  default:
6962  elog(ERROR, "unrecognized node type: %d",
6963  (int) nodeTag(&con->val));
6964  break;
6965  }
6966  }
6967 
6968  return buf.data;
6969 }
#define NIL
Definition: pg_list.h:69
#define IsA(nodeptr, _type_)
Definition: nodes.h:564
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:10435
Datum interval_in(PG_FUNCTION_ARGS)
Definition: timestamp.c:876
#define GUC_LIST_QUOTE
Definition: guc.h:205
Definition: nodes.h:513
#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:585
unsigned int Oid
Definition: postgres_ext.h:31
signed int int32
Definition: c.h:302
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
#define INTERVALOID
Definition: pg_type.h:529
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:589
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:298
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:4420
#define Assert(condition)
Definition: c.h:688
#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:518
Definition: nodes.h:284
#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:287
long val
Definition: informix.c:689
#define GUC_LIST_INPUT
Definition: guc.h:204
Node * arg
Definition: parsenodes.h:297

◆ get_guc_variables()

struct config_generic** get_guc_variables ( void  )

Definition at line 4235 of file guc.c.

References guc_variables.

Referenced by GucInfoMain().

4236 {
4237  return guc_variables;
4238 }
static struct config_generic ** guc_variables
Definition: guc.c:3983

◆ GetConfigOption()

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

Definition at line 6744 of file guc.c.

References buffer, config_enum_lookup_by_value(), DEFAULT_ROLE_READ_ALL_SETTINGS, 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().

6745 {
6746  struct config_generic *record;
6747  static char buffer[256];
6748 
6749  record = find_option(name, false, ERROR);
6750  if (record == NULL)
6751  {
6752  if (missing_ok)
6753  return NULL;
6754  ereport(ERROR,
6755  (errcode(ERRCODE_UNDEFINED_OBJECT),
6756  errmsg("unrecognized configuration parameter \"%s\"",
6757  name)));
6758  }
6759  if (restrict_superuser &&
6760  (record->flags & GUC_SUPERUSER_ONLY) &&
6762  ereport(ERROR,
6763  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6764  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
6765  name)));
6766 
6767  switch (record->vartype)
6768  {
6769  case PGC_BOOL:
6770  return *((struct config_bool *) record)->variable ? "on" : "off";
6771 
6772  case PGC_INT:
6773  snprintf(buffer, sizeof(buffer), "%d",
6774  *((struct config_int *) record)->variable);
6775  return buffer;
6776 
6777  case PGC_REAL:
6778  snprintf(buffer, sizeof(buffer), "%g",
6779  *((struct config_real *) record)->variable);
6780  return buffer;
6781 
6782  case PGC_STRING:
6783  return *((struct config_string *) record)->variable;
6784 
6785  case PGC_ENUM:
6786  return config_enum_lookup_by_value((struct config_enum *) record,
6787  *((struct config_enum *) record)->variable);
6788  }
6789  return NULL;
6790 }
Oid GetUserId(void)
Definition: miscinit.c:284
int errcode(int sqlerrcode)
Definition: elog.c:575
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5665
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
#define DEFAULT_ROLE_READ_ALL_SETTINGS
Definition: pg_authid.h:106
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4420
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 8082 of file guc.c.

References _ShowOption(), DEFAULT_ROLE_READ_ALL_SETTINGS, 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().

8083 {
8084  struct config_generic *record;
8085 
8086  record = find_option(name, false, ERROR);
8087  if (record == NULL)
8088  {
8089  if (missing_ok)
8090  {
8091  if (varname)
8092  *varname = NULL;
8093  return NULL;
8094  }
8095 
8096  ereport(ERROR,
8097  (errcode(ERRCODE_UNDEFINED_OBJECT),
8098  errmsg("unrecognized configuration parameter \"%s\"", name)));
8099  }
8100 
8101  if ((record->flags & GUC_SUPERUSER_ONLY) &&
8103  ereport(ERROR,
8104  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
8105  errmsg("must be superuser or a member of pg_read_all_settings to examine \"%s\"",
8106  name)));
8107 
8108  if (varname)
8109  *varname = record->name;
8110 
8111  return _ShowOption(record, true);
8112 }
static char * _ShowOption(struct config_generic *record, bool use_units)
Definition: guc.c:8683
Oid GetUserId(void)
Definition: miscinit.c:284
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
#define DEFAULT_ROLE_READ_ALL_SETTINGS
Definition: pg_authid.h:106
static struct config_generic * find_option(const char *name, bool create_placeholders, int elevel)
Definition: guc.c:4420
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 8119 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, DEFAULT_ROLE_READ_ALL_SETTINGS, 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().

8120 {
8121  char buffer[256];
8122  struct config_generic *conf;
8123 
8124  /* check requested variable number valid */
8125  Assert((varnum >= 0) && (varnum < num_guc_variables));
8126 
8127  conf = guc_variables[varnum];
8128 
8129  if (noshow)
8130  {
8131  if ((conf->flags & GUC_NO_SHOW_ALL) ||
8132  ((conf->flags & GUC_SUPERUSER_ONLY) &&
8134  *noshow = true;
8135  else
8136  *noshow = false;
8137  }
8138 
8139  /* first get the generic attributes */
8140 
8141  /* name */
8142  values[0] = conf->name;
8143 
8144  /* setting : use _ShowOption in order to avoid duplicating the logic */
8145  values[1] = _ShowOption(conf, false);
8146 
8147  /* unit */
8148  if (conf->vartype == PGC_INT)
8149  {
8150  switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
8151  {
8152  case GUC_UNIT_BYTE:
8153  values[2] = "B";
8154  break;
8155  case GUC_UNIT_KB:
8156  values[2] = "kB";
8157  break;
8158  case GUC_UNIT_MB:
8159  values[2] = "MB";
8160  break;
8161  case GUC_UNIT_BLOCKS:
8162  snprintf(buffer, sizeof(buffer), "%dkB", BLCKSZ / 1024);
8163  values[2] = pstrdup(buffer);
8164  break;
8165  case GUC_UNIT_XBLOCKS:
8166  snprintf(buffer, sizeof(buffer), "%dkB", XLOG_BLCKSZ / 1024);
8167  values[2] = pstrdup(buffer);
8168  break;
8169  case GUC_UNIT_MS:
8170  values[2] = "ms";
8171  break;
8172  case GUC_UNIT_S:
8173  values[2] = "s";
8174  break;
8175  case GUC_UNIT_MIN:
8176  values[2] = "min";
8177  break;
8178  case 0:
8179  values[2] = NULL;
8180  break;
8181  default:
8182  elog(ERROR, "unrecognized GUC units value: %d",
8183  conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME));
8184  values[2] = NULL;
8185  break;
8186  }
8187  }
8188  else
8189  values[2] = NULL;
8190 
8191  /* group */
8192  values[3] = config_group_names[conf->group];
8193 
8194  /* short_desc */
8195  values[4] = conf->short_desc;
8196 
8197  /* extra_desc */
8198  values[5] = conf->long_desc;
8199 
8200  /* context */
8201  values[6] = GucContext_Names[conf->context];
8202 
8203  /* vartype */
8204  values[7] = config_type_names[conf->vartype];
8205 
8206  /* source */
8207  values[8] = GucSource_Names[conf->source];
8208 
8209  /* now get the type specific attributes */
8210  switch (conf->vartype)
8211  {
8212  case PGC_BOOL:
8213  {
8214  struct config_bool *lconf = (struct config_bool *) conf;
8215 
8216  /* min_val */
8217  values[9] = NULL;
8218 
8219  /* max_val */
8220  values[10] = NULL;
8221 
8222  /* enumvals */
8223  values[11] = NULL;
8224 
8225  /* boot_val */
8226  values[12] = pstrdup(lconf->boot_val ? "on" : "off");
8227 
8228  /* reset_val */
8229  values[13] = pstrdup(lconf->reset_val ? "on" : "off");
8230  }
8231  break;
8232 
8233  case PGC_INT:
8234  {
8235  struct config_int *lconf = (struct config_int *) conf;
8236 
8237  /* min_val */
8238  snprintf(buffer, sizeof(buffer), "%d", lconf->min);
8239  values[9] = pstrdup(buffer);
8240 
8241  /* max_val */
8242  snprintf(buffer, sizeof(buffer), "%d", lconf->max);
8243  values[10] = pstrdup(buffer);
8244 
8245  /* enumvals */
8246  values[11] = NULL;
8247 
8248  /* boot_val */
8249  snprintf(buffer, sizeof(buffer), "%d", lconf->boot_val);
8250  values[12] = pstrdup(buffer);
8251 
8252  /* reset_val */
8253  snprintf(buffer, sizeof(buffer), "%d", lconf->reset_val);
8254  values[13] = pstrdup(buffer);
8255  }
8256  break;
8257 
8258  case PGC_REAL:
8259  {
8260  struct config_real *lconf = (struct config_real *) conf;
8261 
8262  /* min_val */
8263  snprintf(buffer, sizeof(buffer), "%g", lconf->min);
8264  values[9] = pstrdup(buffer);
8265 
8266  /* max_val */
8267  snprintf(buffer, sizeof(buffer), "%g", lconf->max);
8268  values[10] = pstrdup(buffer);
8269 
8270  /* enumvals */
8271  values[11] = NULL;
8272 
8273  /* boot_val */
8274  snprintf(buffer, sizeof(buffer), "%g", lconf->boot_val);
8275  values[12] = pstrdup(buffer);
8276 
8277  /* reset_val */
8278  snprintf(buffer, sizeof(buffer), "%g", lconf->reset_val);
8279  values[13] = pstrdup(buffer);
8280  }
8281  break;
8282 
8283  case PGC_STRING:
8284  {
8285  struct config_string *lconf = (struct config_string *) conf;
8286 
8287  /* min_val */
8288  values[9] = NULL;
8289 
8290  /* max_val */
8291  values[10] = NULL;
8292 
8293  /* enumvals */
8294  values[11] = NULL;
8295 
8296  /* boot_val */
8297  if (lconf->boot_val == NULL)
8298  values[12] = NULL;
8299  else
8300  values[12] = pstrdup(lconf->boot_val);
8301 
8302  /* reset_val */
8303  if (lconf->reset_val == NULL)
8304  values[13] = NULL;
8305  else
8306  values[13] = pstrdup(lconf->reset_val);
8307  }
8308  break;
8309 
8310  case PGC_ENUM:
8311  {
8312  struct config_enum *lconf = (struct config_enum *) conf;
8313 
8314  /* min_val */
8315  values[9] = NULL;
8316 
8317  /* max_val */
8318  values[10] = NULL;
8319 
8320  /* enumvals */
8321 
8322  /*
8323  * NOTE! enumvals with double quotes in them are not
8324  * supported!
8325  */
8326  values[11] = config_enum_get_options((struct config_enum *) conf,
8327  "{\"", "\"}", "\",\"");
8328 
8329  /* boot_val */
8331  lconf->boot_val));
8332 
8333  /* reset_val */
8335  lconf->reset_val));
8336  }
8337  break;