codekingpro/portable-devtools
115k
1/*--------------------------------------------------------------------2 * guc.h3 *4 * External declarations pertaining to Grand Unified Configuration.5 *6 * Copyright (c) 2000-2023, PostgreSQL Global Development Group7 * Written by Peter Eisentraut <peter_e@gmx.net>.8 *9 * src/include/utils/guc.h10 *--------------------------------------------------------------------11 */12#ifndef GUC_H13#define GUC_H14 15#include "nodes/parsenodes.h"16#include "tcop/dest.h"17#include "utils/array.h"18 19 20/* upper limit for GUC variables measured in kilobytes of memory */21/* note that various places assume the byte size fits in a "long" variable */22#if SIZEOF_SIZE_T > 4 && SIZEOF_LONG > 423#define MAX_KILOBYTES INT_MAX24#else25#define MAX_KILOBYTES (INT_MAX / 1024)26#endif27 28/*29 * Automatic configuration file name for ALTER SYSTEM.30 * This file will be used to store values of configuration parameters31 * set by ALTER SYSTEM command.32 */33#define PG_AUTOCONF_FILENAME "postgresql.auto.conf"34 35/*36 * Certain options can only be set at certain times. The rules are37 * like this:38 *39 * INTERNAL options cannot be set by the user at all, but only through40 * internal processes ("server_version" is an example). These are GUC41 * variables only so they can be shown by SHOW, etc.42 *43 * POSTMASTER options can only be set when the postmaster starts,44 * either from the configuration file or the command line.45 *46 * SIGHUP options can only be set at postmaster startup or by changing47 * the configuration file and sending the HUP signal to the postmaster48 * or a backend process. (Notice that the signal receipt will not be49 * evaluated immediately. The postmaster and the backend check it at a50 * certain point in their main loop. It's safer to wait than to read a51 * file asynchronously.)52 *53 * BACKEND and SU_BACKEND options can only be set at postmaster startup,54 * from the configuration file, or by client request in the connection55 * startup packet (e.g., from libpq's PGOPTIONS variable). SU_BACKEND56 * options can be set from the startup packet only when the user is a57 * superuser. Furthermore, an already-started backend will ignore changes58 * to such an option in the configuration file. The idea is that these59 * options are fixed for a given backend once it's started, but they can60 * vary across backends.61 *62 * SUSET options can be set at postmaster startup, with the SIGHUP63 * mechanism, or from the startup packet or SQL if you're a superuser.64 *65 * USERSET options can be set by anyone any time.66 */67typedef enum68{69 PGC_INTERNAL,70 PGC_POSTMASTER,71 PGC_SIGHUP,72 PGC_SU_BACKEND,73 PGC_BACKEND,74 PGC_SUSET,75 PGC_USERSET76} GucContext;77 78/*79 * The following type records the source of the current setting. A80 * new setting can only take effect if the previous setting had the81 * same or lower level. (E.g, changing the config file doesn't82 * override the postmaster command line.) Tracking the source allows us83 * to process sources in any convenient order without affecting results.84 * Sources <= PGC_S_OVERRIDE will set the default used by RESET, as well85 * as the current value.86 *87 * PGC_S_INTERACTIVE isn't actually a source value, but is the88 * dividing line between "interactive" and "non-interactive" sources for89 * error reporting purposes.90 *91 * PGC_S_TEST is used when testing values to be used later. For example,92 * ALTER DATABASE/ROLE tests proposed per-database or per-user defaults this93 * way, and CREATE FUNCTION tests proposed function SET clauses this way.94 * This is an interactive case, but it needs its own source value because95 * some assign hooks need to make different validity checks in this case.96 * In particular, references to nonexistent database objects generally97 * shouldn't throw hard errors in this case, at most NOTICEs, since the98 * objects might exist by the time the setting is used for real.99 *100 * When setting the value of a non-compile-time-constant PGC_INTERNAL option,101 * source == PGC_S_DYNAMIC_DEFAULT should typically be used so that the value102 * will show as "default" in pg_settings. If there is a specific reason not103 * to want that, use source == PGC_S_OVERRIDE.104 *105 * NB: see GucSource_Names in guc.c if you change this.106 */107typedef enum108{109 PGC_S_DEFAULT, /* hard-wired default ("boot_val") */110 PGC_S_DYNAMIC_DEFAULT, /* default computed during initialization */111 PGC_S_ENV_VAR, /* postmaster environment variable */112 PGC_S_FILE, /* postgresql.conf */113 PGC_S_ARGV, /* postmaster command line */114 PGC_S_GLOBAL, /* global in-database setting */115 PGC_S_DATABASE, /* per-database setting */116 PGC_S_USER, /* per-user setting */117 PGC_S_DATABASE_USER, /* per-user-and-database setting */118 PGC_S_CLIENT, /* from client connection request */119 PGC_S_OVERRIDE, /* special case to forcibly set default */120 PGC_S_INTERACTIVE, /* dividing line for error reporting */121 PGC_S_TEST, /* test per-database or per-user setting */122 PGC_S_SESSION /* SET command */123} GucSource;124 125/*126 * Parsing the configuration file(s) will return a list of name-value pairs127 * with source location info. We also abuse this data structure to carry128 * error reports about the config files. An entry reporting an error will129 * have errmsg != NULL, and might have NULLs for name, value, and/or filename.130 *131 * If "ignore" is true, don't attempt to apply the item (it might be an error132 * report, or an item we determined to be duplicate). "applied" is set true133 * if we successfully applied, or could have applied, the setting.134 */135typedef struct ConfigVariable136{137 char *name;138 char *value;139 char *errmsg;140 char *filename;141 int sourceline;142 bool ignore;143 bool applied;144 struct ConfigVariable *next;145} ConfigVariable;146 147extern bool ParseConfigFile(const char *config_file, bool strict,148 const char *calling_file, int calling_lineno,149 int depth, int elevel,150 ConfigVariable **head_p, ConfigVariable **tail_p);151extern bool ParseConfigFp(FILE *fp, const char *config_file,152 int depth, int elevel,153 ConfigVariable **head_p, ConfigVariable **tail_p);154extern bool ParseConfigDirectory(const char *includedir,155 const char *calling_file, int calling_lineno,156 int depth, int elevel,157 ConfigVariable **head_p,158 ConfigVariable **tail_p);159extern void FreeConfigVariables(ConfigVariable *list);160extern char *DeescapeQuotedString(const char *s);161 162/*163 * The possible values of an enum variable are specified by an array of164 * name-value pairs. The "hidden" flag means the value is accepted but165 * won't be displayed when guc.c is asked for a list of acceptable values.166 */167struct config_enum_entry168{169 const char *name;170 int val;171 bool hidden;172};173 174/*175 * Signatures for per-variable check/assign/show hook functions176 */177typedef bool (*GucBoolCheckHook) (bool *newval, void **extra, GucSource source);178typedef bool (*GucIntCheckHook) (int *newval, void **extra, GucSource source);179typedef bool (*GucRealCheckHook) (double *newval, void **extra, GucSource source);180typedef bool (*GucStringCheckHook) (char **newval, void **extra, GucSource source);181typedef bool (*GucEnumCheckHook) (int *newval, void **extra, GucSource source);182 183typedef void (*GucBoolAssignHook) (bool newval, void *extra);184typedef void (*GucIntAssignHook) (int newval, void *extra);185typedef void (*GucRealAssignHook) (double newval, void *extra);186typedef void (*GucStringAssignHook) (const char *newval, void *extra);187typedef void (*GucEnumAssignHook) (int newval, void *extra);188 189typedef const char *(*GucShowHook) (void);190 191/*192 * Miscellaneous193 */194typedef enum195{196 /* Types of set_config_option actions */197 GUC_ACTION_SET, /* regular SET command */198 GUC_ACTION_LOCAL, /* SET LOCAL command */199 GUC_ACTION_SAVE /* function SET option, or temp assignment */200} GucAction;201 202#define GUC_QUALIFIER_SEPARATOR '.'203 204/*205 * Bit values in "flags" of a GUC variable. Note that these don't appear206 * on disk, so we can reassign their values freely.207 */208#define GUC_LIST_INPUT 0x000001 /* input can be list format */209#define GUC_LIST_QUOTE 0x000002 /* double-quote list elements */210#define GUC_NO_SHOW_ALL 0x000004 /* exclude from SHOW ALL */211#define GUC_NO_RESET 0x000008 /* disallow RESET and SAVE */212#define GUC_NO_RESET_ALL 0x000010 /* exclude from RESET ALL */213#define GUC_EXPLAIN 0x000020 /* include in EXPLAIN */214#define GUC_REPORT 0x000040 /* auto-report changes to client */215#define GUC_NOT_IN_SAMPLE 0x000080 /* not in postgresql.conf.sample */216#define GUC_DISALLOW_IN_FILE 0x000100 /* can't set in postgresql.conf */217#define GUC_CUSTOM_PLACEHOLDER 0x000200 /* placeholder for custom variable */218#define GUC_SUPERUSER_ONLY 0x000400 /* show only to superusers */219#define GUC_IS_NAME 0x000800 /* limit string to NAMEDATALEN-1 */220#define GUC_NOT_WHILE_SEC_REST 0x001000 /* can't set if security restricted */221#define GUC_DISALLOW_IN_AUTO_FILE \222 0x002000 /* can't set in PG_AUTOCONF_FILENAME */223#define GUC_RUNTIME_COMPUTED 0x004000 /* delay processing in 'postgres -C' */224 225#define GUC_UNIT_KB 0x01000000 /* value is in kilobytes */226#define GUC_UNIT_BLOCKS 0x02000000 /* value is in blocks */227#define GUC_UNIT_XBLOCKS 0x03000000 /* value is in xlog blocks */228#define GUC_UNIT_MB 0x04000000 /* value is in megabytes */229#define GUC_UNIT_BYTE 0x05000000 /* value is in bytes */230#define GUC_UNIT_MEMORY 0x0F000000 /* mask for size-related units */231 232#define GUC_UNIT_MS 0x10000000 /* value is in milliseconds */233#define GUC_UNIT_S 0x20000000 /* value is in seconds */234#define GUC_UNIT_MIN 0x30000000 /* value is in minutes */235#define GUC_UNIT_TIME 0x70000000 /* mask for time-related units */236 237#define GUC_UNIT (GUC_UNIT_MEMORY | GUC_UNIT_TIME)238 239 240/* GUC vars that are actually defined in guc_tables.c, rather than elsewhere */241extern PGDLLIMPORT bool Debug_print_plan;242extern PGDLLIMPORT bool Debug_print_parse;243extern PGDLLIMPORT bool Debug_print_rewritten;244extern PGDLLIMPORT bool Debug_pretty_print;245 246extern PGDLLIMPORT bool log_parser_stats;247extern PGDLLIMPORT bool log_planner_stats;248extern PGDLLIMPORT bool log_executor_stats;249extern PGDLLIMPORT bool log_statement_stats;250extern PGDLLIMPORT bool log_btree_build_stats;251 252extern PGDLLIMPORT bool check_function_bodies;253extern PGDLLIMPORT bool session_auth_is_superuser;254 255extern PGDLLIMPORT bool log_duration;256extern PGDLLIMPORT int log_parameter_max_length;257extern PGDLLIMPORT int log_parameter_max_length_on_error;258extern PGDLLIMPORT int log_min_error_statement;259extern PGDLLIMPORT int log_min_messages;260extern PGDLLIMPORT int client_min_messages;261extern PGDLLIMPORT int log_min_duration_sample;262extern PGDLLIMPORT int log_min_duration_statement;263extern PGDLLIMPORT int log_temp_files;264extern PGDLLIMPORT double log_statement_sample_rate;265extern PGDLLIMPORT double log_xact_sample_rate;266extern PGDLLIMPORT char *backtrace_functions;267 268extern PGDLLIMPORT int temp_file_limit;269 270extern PGDLLIMPORT int num_temp_buffers;271 272extern PGDLLIMPORT char *cluster_name;273extern PGDLLIMPORT char *ConfigFileName;274extern PGDLLIMPORT char *HbaFileName;275extern PGDLLIMPORT char *IdentFileName;276extern PGDLLIMPORT char *external_pid_file;277 278extern PGDLLIMPORT char *application_name;279 280extern PGDLLIMPORT int tcp_keepalives_idle;281extern PGDLLIMPORT int tcp_keepalives_interval;282extern PGDLLIMPORT int tcp_keepalives_count;283extern PGDLLIMPORT int tcp_user_timeout;284 285#ifdef TRACE_SORT286extern PGDLLIMPORT bool trace_sort;287#endif288 289/*290 * Functions exported by guc.c291 */292extern void SetConfigOption(const char *name, const char *value,293 GucContext context, GucSource source);294 295extern void DefineCustomBoolVariable(const char *name,296 const char *short_desc,297 const char *long_desc,298 bool *valueAddr,299 bool bootValue,300 GucContext context,301 int flags,302 GucBoolCheckHook check_hook,303 GucBoolAssignHook assign_hook,304 GucShowHook show_hook) pg_attribute_nonnull(1, 4);305 306extern void DefineCustomIntVariable(const char *name,307 const char *short_desc,308 const char *long_desc,309 int *valueAddr,310 int bootValue,311 int minValue,312 int maxValue,313 GucContext context,314 int flags,315 GucIntCheckHook check_hook,316 GucIntAssignHook assign_hook,317 GucShowHook show_hook) pg_attribute_nonnull(1, 4);318 319extern void DefineCustomRealVariable(const char *name,320 const char *short_desc,321 const char *long_desc,322 double *valueAddr,323 double bootValue,324 double minValue,325 double maxValue,326 GucContext context,327 int flags,328 GucRealCheckHook check_hook,329 GucRealAssignHook assign_hook,330 GucShowHook show_hook) pg_attribute_nonnull(1, 4);331 332extern void DefineCustomStringVariable(const char *name,333 const char *short_desc,334 const char *long_desc,335 char **valueAddr,336 const char *bootValue,337 GucContext context,338 int flags,339 GucStringCheckHook check_hook,340 GucStringAssignHook assign_hook,341 GucShowHook show_hook) pg_attribute_nonnull(1, 4);342 343extern void DefineCustomEnumVariable(const char *name,344 const char *short_desc,345 const char *long_desc,346 int *valueAddr,347 int bootValue,348 const struct config_enum_entry *options,349 GucContext context,350 int flags,351 GucEnumCheckHook check_hook,352 GucEnumAssignHook assign_hook,353 GucShowHook show_hook) pg_attribute_nonnull(1, 4);354 355extern void MarkGUCPrefixReserved(const char *className);356 357/* old name for MarkGUCPrefixReserved, for backwards compatibility: */358#define EmitWarningsOnPlaceholders(className) MarkGUCPrefixReserved(className)359 360extern const char *GetConfigOption(const char *name, bool missing_ok,361 bool restrict_privileged);362extern const char *GetConfigOptionResetString(const char *name);363extern int GetConfigOptionFlags(const char *name, bool missing_ok);364extern void ProcessConfigFile(GucContext context);365extern char *convert_GUC_name_for_parameter_acl(const char *name);366extern bool check_GUC_name_for_parameter_acl(const char *name);367extern void InitializeGUCOptions(void);368extern bool SelectConfigFiles(const char *userDoption, const char *progname);369extern void ResetAllOptions(void);370extern void AtStart_GUC(void);371extern int NewGUCNestLevel(void);372extern void AtEOXact_GUC(bool isCommit, int nestLevel);373extern void BeginReportingGUCOptions(void);374extern void ReportChangedGUCOptions(void);375extern void ParseLongOption(const char *string, char **name, char **value);376extern const char *get_config_unit_name(int flags);377extern bool parse_int(const char *value, int *result, int flags,378 const char **hintmsg);379extern bool parse_real(const char *value, double *result, int flags,380 const char **hintmsg);381extern int set_config_option(const char *name, const char *value,382 GucContext context, GucSource source,383 GucAction action, bool changeVal, int elevel,384 bool is_reload);385extern int set_config_option_ext(const char *name, const char *value,386 GucContext context, GucSource source,387 Oid srole,388 GucAction action, bool changeVal, int elevel,389 bool is_reload);390extern void AlterSystemSetConfigFile(AlterSystemStmt *altersysstmt);391extern char *GetConfigOptionByName(const char *name, const char **varname,392 bool missing_ok);393 394extern void ProcessGUCArray(ArrayType *array,395 GucContext context, GucSource source, GucAction action);396extern ArrayType *GUCArrayAdd(ArrayType *array, const char *name, const char *value);397extern ArrayType *GUCArrayDelete(ArrayType *array, const char *name);398extern ArrayType *GUCArrayReset(ArrayType *array);399 400extern void *guc_malloc(int elevel, size_t size);401extern pg_nodiscard void *guc_realloc(int elevel, void *old, size_t size);402extern char *guc_strdup(int elevel, const char *src);403extern void guc_free(void *ptr);404 405#ifdef EXEC_BACKEND406extern void write_nondefault_variables(GucContext context);407extern void read_nondefault_variables(void);408#endif409 410/* GUC serialization */411extern Size EstimateGUCStateSpace(void);412extern void SerializeGUCState(Size maxsize, char *start_address);413extern void RestoreGUCState(void *gucstate);414 415/* Functions exported by guc_funcs.c */416extern void ExecSetVariableStmt(VariableSetStmt *stmt, bool isTopLevel);417extern char *ExtractSetVariableArgs(VariableSetStmt *stmt);418extern void SetPGVariable(const char *name, List *args, bool is_local);419extern void GetPGVariable(const char *name, DestReceiver *dest);420extern TupleDesc GetPGVariableResultDesc(const char *name);421 422/* Support for messages reported from GUC check hooks */423 424extern PGDLLIMPORT char *GUC_check_errmsg_string;425extern PGDLLIMPORT char *GUC_check_errdetail_string;426extern PGDLLIMPORT char *GUC_check_errhint_string;427 428extern void GUC_check_errcode(int sqlerrcode);429 430#define GUC_check_errmsg \431 pre_format_elog_string(errno, TEXTDOMAIN), \432 GUC_check_errmsg_string = format_elog_string433 434#define GUC_check_errdetail \435 pre_format_elog_string(errno, TEXTDOMAIN), \436 GUC_check_errdetail_string = format_elog_string437 438#define GUC_check_errhint \439 pre_format_elog_string(errno, TEXTDOMAIN), \440 GUC_check_errhint_string = format_elog_string441 442#endif /* GUC_H */443 