guc.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. /*--------------------------------------------------------------------
  2. * guc.h
  3. *
  4. * External declarations pertaining to backend/utils/misc/guc.c and
  5. * backend/utils/misc/guc-file.l
  6. *
  7. * Copyright (c) 2000-2022, PostgreSQL Global Development Group
  8. * Written by Peter Eisentraut <[email protected]>.
  9. *
  10. * src/include/utils/guc.h
  11. *--------------------------------------------------------------------
  12. */
  13. #ifndef GUC_H
  14. #define GUC_H
  15. #include "nodes/parsenodes.h"
  16. #include "tcop/dest.h"
  17. #include "utils/array.h"
  18. /* upper limit for GUC variables measured in kilobytes of memory */
  19. /* note that various places assume the byte size fits in a "long" variable */
  20. #if SIZEOF_SIZE_T > 4 && SIZEOF_LONG > 4
  21. #define MAX_KILOBYTES INT_MAX
  22. #else
  23. #define MAX_KILOBYTES (INT_MAX / 1024)
  24. #endif
  25. /*
  26. * Automatic configuration file name for ALTER SYSTEM.
  27. * This file will be used to store values of configuration parameters
  28. * set by ALTER SYSTEM command.
  29. */
  30. #define PG_AUTOCONF_FILENAME "postgresql.auto.conf"
  31. /*
  32. * Certain options can only be set at certain times. The rules are
  33. * like this:
  34. *
  35. * INTERNAL options cannot be set by the user at all, but only through
  36. * internal processes ("server_version" is an example). These are GUC
  37. * variables only so they can be shown by SHOW, etc.
  38. *
  39. * POSTMASTER options can only be set when the postmaster starts,
  40. * either from the configuration file or the command line.
  41. *
  42. * SIGHUP options can only be set at postmaster startup or by changing
  43. * the configuration file and sending the HUP signal to the postmaster
  44. * or a backend process. (Notice that the signal receipt will not be
  45. * evaluated immediately. The postmaster and the backend check it at a
  46. * certain point in their main loop. It's safer to wait than to read a
  47. * file asynchronously.)
  48. *
  49. * BACKEND and SU_BACKEND options can only be set at postmaster startup,
  50. * from the configuration file, or by client request in the connection
  51. * startup packet (e.g., from libpq's PGOPTIONS variable). SU_BACKEND
  52. * options can be set from the startup packet only when the user is a
  53. * superuser. Furthermore, an already-started backend will ignore changes
  54. * to such an option in the configuration file. The idea is that these
  55. * options are fixed for a given backend once it's started, but they can
  56. * vary across backends.
  57. *
  58. * SUSET options can be set at postmaster startup, with the SIGHUP
  59. * mechanism, or from the startup packet or SQL if you're a superuser.
  60. *
  61. * USERSET options can be set by anyone any time.
  62. */
  63. typedef enum
  64. {
  65. PGC_INTERNAL,
  66. PGC_POSTMASTER,
  67. PGC_SIGHUP,
  68. PGC_SU_BACKEND,
  69. PGC_BACKEND,
  70. PGC_SUSET,
  71. PGC_USERSET
  72. } GucContext;
  73. /*
  74. * The following type records the source of the current setting. A
  75. * new setting can only take effect if the previous setting had the
  76. * same or lower level. (E.g, changing the config file doesn't
  77. * override the postmaster command line.) Tracking the source allows us
  78. * to process sources in any convenient order without affecting results.
  79. * Sources <= PGC_S_OVERRIDE will set the default used by RESET, as well
  80. * as the current value.
  81. *
  82. * PGC_S_INTERACTIVE isn't actually a source value, but is the
  83. * dividing line between "interactive" and "non-interactive" sources for
  84. * error reporting purposes.
  85. *
  86. * PGC_S_TEST is used when testing values to be used later. For example,
  87. * ALTER DATABASE/ROLE tests proposed per-database or per-user defaults this
  88. * way, and CREATE FUNCTION tests proposed function SET clauses this way.
  89. * This is an interactive case, but it needs its own source value because
  90. * some assign hooks need to make different validity checks in this case.
  91. * In particular, references to nonexistent database objects generally
  92. * shouldn't throw hard errors in this case, at most NOTICEs, since the
  93. * objects might exist by the time the setting is used for real.
  94. *
  95. * When setting the value of a non-compile-time-constant PGC_INTERNAL option,
  96. * source == PGC_S_DYNAMIC_DEFAULT should typically be used so that the value
  97. * will show as "default" in pg_settings. If there is a specific reason not
  98. * to want that, use source == PGC_S_OVERRIDE.
  99. *
  100. * NB: see GucSource_Names in guc.c if you change this.
  101. */
  102. typedef enum
  103. {
  104. PGC_S_DEFAULT, /* hard-wired default ("boot_val") */
  105. PGC_S_DYNAMIC_DEFAULT, /* default computed during initialization */
  106. PGC_S_ENV_VAR, /* postmaster environment variable */
  107. PGC_S_FILE, /* postgresql.conf */
  108. PGC_S_ARGV, /* postmaster command line */
  109. PGC_S_GLOBAL, /* global in-database setting */
  110. PGC_S_DATABASE, /* per-database setting */
  111. PGC_S_USER, /* per-user setting */
  112. PGC_S_DATABASE_USER, /* per-user-and-database setting */
  113. PGC_S_CLIENT, /* from client connection request */
  114. PGC_S_OVERRIDE, /* special case to forcibly set default */
  115. PGC_S_INTERACTIVE, /* dividing line for error reporting */
  116. PGC_S_TEST, /* test per-database or per-user setting */
  117. PGC_S_SESSION /* SET command */
  118. } GucSource;
  119. /*
  120. * Parsing the configuration file(s) will return a list of name-value pairs
  121. * with source location info. We also abuse this data structure to carry
  122. * error reports about the config files. An entry reporting an error will
  123. * have errmsg != NULL, and might have NULLs for name, value, and/or filename.
  124. *
  125. * If "ignore" is true, don't attempt to apply the item (it might be an error
  126. * report, or an item we determined to be duplicate). "applied" is set true
  127. * if we successfully applied, or could have applied, the setting.
  128. */
  129. typedef struct ConfigVariable
  130. {
  131. char *name;
  132. char *value;
  133. char *errmsg;
  134. char *filename;
  135. int sourceline;
  136. bool ignore;
  137. bool applied;
  138. struct ConfigVariable *next;
  139. } ConfigVariable;
  140. extern bool ParseConfigFile(const char *config_file, bool strict,
  141. const char *calling_file, int calling_lineno,
  142. int depth, int elevel,
  143. ConfigVariable **head_p, ConfigVariable **tail_p);
  144. extern bool ParseConfigFp(FILE *fp, const char *config_file,
  145. int depth, int elevel,
  146. ConfigVariable **head_p, ConfigVariable **tail_p);
  147. extern bool ParseConfigDirectory(const char *includedir,
  148. const char *calling_file, int calling_lineno,
  149. int depth, int elevel,
  150. ConfigVariable **head_p,
  151. ConfigVariable **tail_p);
  152. extern void FreeConfigVariables(ConfigVariable *list);
  153. extern char *DeescapeQuotedString(const char *s);
  154. /*
  155. * The possible values of an enum variable are specified by an array of
  156. * name-value pairs. The "hidden" flag means the value is accepted but
  157. * won't be displayed when guc.c is asked for a list of acceptable values.
  158. */
  159. struct config_enum_entry
  160. {
  161. const char *name;
  162. int val;
  163. bool hidden;
  164. };
  165. /*
  166. * Signatures for per-variable check/assign/show hook functions
  167. */
  168. typedef bool (*GucBoolCheckHook) (bool *newval, void **extra, GucSource source);
  169. typedef bool (*GucIntCheckHook) (int *newval, void **extra, GucSource source);
  170. typedef bool (*GucRealCheckHook) (double *newval, void **extra, GucSource source);
  171. typedef bool (*GucStringCheckHook) (char **newval, void **extra, GucSource source);
  172. typedef bool (*GucEnumCheckHook) (int *newval, void **extra, GucSource source);
  173. typedef void (*GucBoolAssignHook) (bool newval, void *extra);
  174. typedef void (*GucIntAssignHook) (int newval, void *extra);
  175. typedef void (*GucRealAssignHook) (double newval, void *extra);
  176. typedef void (*GucStringAssignHook) (const char *newval, void *extra);
  177. typedef void (*GucEnumAssignHook) (int newval, void *extra);
  178. typedef const char *(*GucShowHook) (void);
  179. /*
  180. * Miscellaneous
  181. */
  182. typedef enum
  183. {
  184. /* Types of set_config_option actions */
  185. GUC_ACTION_SET, /* regular SET command */
  186. GUC_ACTION_LOCAL, /* SET LOCAL command */
  187. GUC_ACTION_SAVE /* function SET option, or temp assignment */
  188. } GucAction;
  189. #define GUC_QUALIFIER_SEPARATOR '.'
  190. /*
  191. * bit values in "flags" of a GUC variable
  192. */
  193. #define GUC_LIST_INPUT 0x0001 /* input can be list format */
  194. #define GUC_LIST_QUOTE 0x0002 /* double-quote list elements */
  195. #define GUC_NO_SHOW_ALL 0x0004 /* exclude from SHOW ALL */
  196. #define GUC_NO_RESET_ALL 0x0008 /* exclude from RESET ALL */
  197. #define GUC_REPORT 0x0010 /* auto-report changes to client */
  198. #define GUC_NOT_IN_SAMPLE 0x0020 /* not in postgresql.conf.sample */
  199. #define GUC_DISALLOW_IN_FILE 0x0040 /* can't set in postgresql.conf */
  200. #define GUC_CUSTOM_PLACEHOLDER 0x0080 /* placeholder for custom variable */
  201. #define GUC_SUPERUSER_ONLY 0x0100 /* show only to superusers */
  202. #define GUC_IS_NAME 0x0200 /* limit string to NAMEDATALEN-1 */
  203. #define GUC_NOT_WHILE_SEC_REST 0x0400 /* can't set if security restricted */
  204. #define GUC_DISALLOW_IN_AUTO_FILE 0x0800 /* can't set in
  205. * PG_AUTOCONF_FILENAME */
  206. #define GUC_UNIT_KB 0x1000 /* value is in kilobytes */
  207. #define GUC_UNIT_BLOCKS 0x2000 /* value is in blocks */
  208. #define GUC_UNIT_XBLOCKS 0x3000 /* value is in xlog blocks */
  209. #define GUC_UNIT_MB 0x4000 /* value is in megabytes */
  210. #define GUC_UNIT_BYTE 0x8000 /* value is in bytes */
  211. #define GUC_UNIT_MEMORY 0xF000 /* mask for size-related units */
  212. #define GUC_UNIT_MS 0x10000 /* value is in milliseconds */
  213. #define GUC_UNIT_S 0x20000 /* value is in seconds */
  214. #define GUC_UNIT_MIN 0x30000 /* value is in minutes */
  215. #define GUC_UNIT_TIME 0xF0000 /* mask for time-related units */
  216. #define GUC_EXPLAIN 0x100000 /* include in explain */
  217. /*
  218. * GUC_RUNTIME_COMPUTED is intended for runtime-computed GUCs that are only
  219. * available via 'postgres -C' if the server is not running.
  220. */
  221. #define GUC_RUNTIME_COMPUTED 0x200000
  222. #define GUC_UNIT (GUC_UNIT_MEMORY | GUC_UNIT_TIME)
  223. /* GUC vars that are actually declared in guc.c, rather than elsewhere */
  224. extern PGDLLIMPORT bool Debug_print_plan;
  225. extern PGDLLIMPORT bool Debug_print_parse;
  226. extern PGDLLIMPORT bool Debug_print_rewritten;
  227. extern PGDLLIMPORT bool Debug_pretty_print;
  228. extern PGDLLIMPORT bool log_parser_stats;
  229. extern PGDLLIMPORT bool log_planner_stats;
  230. extern PGDLLIMPORT bool log_executor_stats;
  231. extern PGDLLIMPORT bool log_statement_stats;
  232. extern PGDLLIMPORT bool log_btree_build_stats;
  233. extern PGDLLIMPORT bool check_function_bodies;
  234. extern PGDLLIMPORT bool session_auth_is_superuser;
  235. extern PGDLLIMPORT bool log_duration;
  236. extern PGDLLIMPORT int log_parameter_max_length;
  237. extern PGDLLIMPORT int log_parameter_max_length_on_error;
  238. extern PGDLLIMPORT int log_min_error_statement;
  239. extern PGDLLIMPORT int log_min_messages;
  240. extern PGDLLIMPORT int client_min_messages;
  241. extern PGDLLIMPORT int log_min_duration_sample;
  242. extern PGDLLIMPORT int log_min_duration_statement;
  243. extern PGDLLIMPORT int log_temp_files;
  244. extern PGDLLIMPORT double log_statement_sample_rate;
  245. extern PGDLLIMPORT double log_xact_sample_rate;
  246. extern PGDLLIMPORT char *backtrace_functions;
  247. extern PGDLLIMPORT char *backtrace_symbol_list;
  248. extern PGDLLIMPORT int temp_file_limit;
  249. extern PGDLLIMPORT int num_temp_buffers;
  250. extern PGDLLIMPORT char *cluster_name;
  251. extern PGDLLIMPORT char *ConfigFileName;
  252. extern PGDLLIMPORT char *HbaFileName;
  253. extern PGDLLIMPORT char *IdentFileName;
  254. extern PGDLLIMPORT char *external_pid_file;
  255. extern PGDLLIMPORT char *application_name;
  256. extern PGDLLIMPORT int tcp_keepalives_idle;
  257. extern PGDLLIMPORT int tcp_keepalives_interval;
  258. extern PGDLLIMPORT int tcp_keepalives_count;
  259. extern PGDLLIMPORT int tcp_user_timeout;
  260. #ifdef TRACE_SORT
  261. extern PGDLLIMPORT bool trace_sort;
  262. #endif
  263. /*
  264. * Functions exported by guc.c
  265. */
  266. extern void SetConfigOption(const char *name, const char *value,
  267. GucContext context, GucSource source);
  268. extern void DefineCustomBoolVariable(const char *name,
  269. const char *short_desc,
  270. const char *long_desc,
  271. bool *valueAddr,
  272. bool bootValue,
  273. GucContext context,
  274. int flags,
  275. GucBoolCheckHook check_hook,
  276. GucBoolAssignHook assign_hook,
  277. GucShowHook show_hook);
  278. extern void DefineCustomIntVariable(const char *name,
  279. const char *short_desc,
  280. const char *long_desc,
  281. int *valueAddr,
  282. int bootValue,
  283. int minValue,
  284. int maxValue,
  285. GucContext context,
  286. int flags,
  287. GucIntCheckHook check_hook,
  288. GucIntAssignHook assign_hook,
  289. GucShowHook show_hook);
  290. extern void DefineCustomRealVariable(const char *name,
  291. const char *short_desc,
  292. const char *long_desc,
  293. double *valueAddr,
  294. double bootValue,
  295. double minValue,
  296. double maxValue,
  297. GucContext context,
  298. int flags,
  299. GucRealCheckHook check_hook,
  300. GucRealAssignHook assign_hook,
  301. GucShowHook show_hook);
  302. extern void DefineCustomStringVariable(const char *name,
  303. const char *short_desc,
  304. const char *long_desc,
  305. char **valueAddr,
  306. const char *bootValue,
  307. GucContext context,
  308. int flags,
  309. GucStringCheckHook check_hook,
  310. GucStringAssignHook assign_hook,
  311. GucShowHook show_hook);
  312. extern void DefineCustomEnumVariable(const char *name,
  313. const char *short_desc,
  314. const char *long_desc,
  315. int *valueAddr,
  316. int bootValue,
  317. const struct config_enum_entry *options,
  318. GucContext context,
  319. int flags,
  320. GucEnumCheckHook check_hook,
  321. GucEnumAssignHook assign_hook,
  322. GucShowHook show_hook);
  323. extern void MarkGUCPrefixReserved(const char *className);
  324. /* old name for MarkGUCPrefixReserved, for backwards compatibility: */
  325. #define EmitWarningsOnPlaceholders(className) MarkGUCPrefixReserved(className)
  326. extern const char *GetConfigOption(const char *name, bool missing_ok,
  327. bool restrict_privileged);
  328. extern const char *GetConfigOptionResetString(const char *name);
  329. extern int GetConfigOptionFlags(const char *name, bool missing_ok);
  330. extern void ProcessConfigFile(GucContext context);
  331. extern char *convert_GUC_name_for_parameter_acl(const char *name);
  332. extern bool check_GUC_name_for_parameter_acl(const char *name);
  333. extern void InitializeGUCOptions(void);
  334. extern void InitializeWalConsistencyChecking(void);
  335. extern bool SelectConfigFiles(const char *userDoption, const char *progname);
  336. extern void ResetAllOptions(void);
  337. extern void AtStart_GUC(void);
  338. extern int NewGUCNestLevel(void);
  339. extern void AtEOXact_GUC(bool isCommit, int nestLevel);
  340. extern void BeginReportingGUCOptions(void);
  341. extern void ReportChangedGUCOptions(void);
  342. extern void ParseLongOption(const char *string, char **name, char **value);
  343. extern bool parse_int(const char *value, int *result, int flags,
  344. const char **hintmsg);
  345. extern bool parse_real(const char *value, double *result, int flags,
  346. const char **hintmsg);
  347. extern int set_config_option(const char *name, const char *value,
  348. GucContext context, GucSource source,
  349. GucAction action, bool changeVal, int elevel,
  350. bool is_reload);
  351. extern int set_config_option_ext(const char *name, const char *value,
  352. GucContext context, GucSource source,
  353. Oid srole,
  354. GucAction action, bool changeVal, int elevel,
  355. bool is_reload);
  356. extern void AlterSystemSetConfigFile(AlterSystemStmt *altersysstmt);
  357. extern char *GetConfigOptionByName(const char *name, const char **varname,
  358. bool missing_ok);
  359. extern void GetConfigOptionByNum(int varnum, const char **values, bool *noshow);
  360. extern int GetNumConfigOptions(void);
  361. extern void SetPGVariable(const char *name, List *args, bool is_local);
  362. extern void GetPGVariable(const char *name, DestReceiver *dest);
  363. extern TupleDesc GetPGVariableResultDesc(const char *name);
  364. extern void ExecSetVariableStmt(VariableSetStmt *stmt, bool isTopLevel);
  365. extern char *ExtractSetVariableArgs(VariableSetStmt *stmt);
  366. extern void ProcessGUCArray(ArrayType *array,
  367. GucContext context, GucSource source, GucAction action);
  368. extern ArrayType *GUCArrayAdd(ArrayType *array, const char *name, const char *value);
  369. extern ArrayType *GUCArrayDelete(ArrayType *array, const char *name);
  370. extern ArrayType *GUCArrayReset(ArrayType *array);
  371. #ifdef EXEC_BACKEND
  372. extern void write_nondefault_variables(GucContext context);
  373. extern void read_nondefault_variables(void);
  374. #endif
  375. /* GUC serialization */
  376. extern Size EstimateGUCStateSpace(void);
  377. extern void SerializeGUCState(Size maxsize, char *start_address);
  378. extern void RestoreGUCState(void *gucstate);
  379. /* Support for messages reported from GUC check hooks */
  380. extern PGDLLIMPORT char *GUC_check_errmsg_string;
  381. extern PGDLLIMPORT char *GUC_check_errdetail_string;
  382. extern PGDLLIMPORT char *GUC_check_errhint_string;
  383. extern void GUC_check_errcode(int sqlerrcode);
  384. #define GUC_check_errmsg \
  385. pre_format_elog_string(errno, TEXTDOMAIN), \
  386. GUC_check_errmsg_string = format_elog_string
  387. #define GUC_check_errdetail \
  388. pre_format_elog_string(errno, TEXTDOMAIN), \
  389. GUC_check_errdetail_string = format_elog_string
  390. #define GUC_check_errhint \
  391. pre_format_elog_string(errno, TEXTDOMAIN), \
  392. GUC_check_errhint_string = format_elog_string
  393. /*
  394. * The following functions are not in guc.c, but are declared here to avoid
  395. * having to include guc.h in some widely used headers that it really doesn't
  396. * belong in.
  397. */
  398. /* in commands/tablespace.c */
  399. extern bool check_default_tablespace(char **newval, void **extra, GucSource source);
  400. extern bool check_temp_tablespaces(char **newval, void **extra, GucSource source);
  401. extern void assign_temp_tablespaces(const char *newval, void *extra);
  402. /* in catalog/namespace.c */
  403. extern bool check_search_path(char **newval, void **extra, GucSource source);
  404. extern void assign_search_path(const char *newval, void *extra);
  405. /* in access/transam/xlog.c */
  406. extern bool check_wal_buffers(int *newval, void **extra, GucSource source);
  407. extern void assign_xlog_sync_method(int new_sync_method, void *extra);
  408. /* in access/transam/xlogprefetcher.c */
  409. extern bool check_recovery_prefetch(int *new_value, void **extra, GucSource source);
  410. extern void assign_recovery_prefetch(int new_value, void *extra);
  411. #endif /* GUC_H */