guc.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  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-2016, PostgreSQL Global Development Group
  8. * Written by Peter Eisentraut <peter_e@gmx.net>.
  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. Note that source == PGC_S_OVERRIDE should be
  81. * used when setting a PGC_INTERNAL option.
  82. *
  83. * PGC_S_INTERACTIVE isn't actually a source value, but is the
  84. * dividing line between "interactive" and "non-interactive" sources for
  85. * error reporting purposes.
  86. *
  87. * PGC_S_TEST is used when testing values to be used later ("doit" will always
  88. * be false, so this never gets stored as the actual source of any value).
  89. * For example, ALTER DATABASE/ROLE tests proposed per-database or per-user
  90. * defaults this way, and CREATE FUNCTION tests proposed function SET clauses
  91. * this way. This is an interactive case, but it needs its own source value
  92. * because some assign hooks need to make different validity checks in this
  93. * case. In particular, references to nonexistent database objects generally
  94. * shouldn't throw hard errors in this case, at most NOTICEs, since the
  95. * objects might exist by the time the setting is used for real.
  96. *
  97. * NB: see GucSource_Names in guc.c if you change this.
  98. */
  99. typedef enum
  100. {
  101. PGC_S_DEFAULT, /* hard-wired default ("boot_val") */
  102. PGC_S_DYNAMIC_DEFAULT, /* default computed during initialization */
  103. PGC_S_ENV_VAR, /* postmaster environment variable */
  104. PGC_S_FILE, /* postgresql.conf */
  105. PGC_S_ARGV, /* postmaster command line */
  106. PGC_S_GLOBAL, /* global in-database setting */
  107. PGC_S_DATABASE, /* per-database setting */
  108. PGC_S_USER, /* per-user setting */
  109. PGC_S_DATABASE_USER, /* per-user-and-database setting */
  110. PGC_S_CLIENT, /* from client connection request */
  111. PGC_S_OVERRIDE, /* special case to forcibly set default */
  112. PGC_S_INTERACTIVE, /* dividing line for error reporting */
  113. PGC_S_TEST, /* test per-database or per-user setting */
  114. PGC_S_SESSION /* SET command */
  115. } GucSource;
  116. /*
  117. * Parsing the configuration file(s) will return a list of name-value pairs
  118. * with source location info. We also abuse this data structure to carry
  119. * error reports about the config files. An entry reporting an error will
  120. * have errmsg != NULL, and might have NULLs for name, value, and/or filename.
  121. *
  122. * If "ignore" is true, don't attempt to apply the item (it might be an error
  123. * report, or an item we determined to be duplicate). "applied" is set true
  124. * if we successfully applied, or could have applied, the setting.
  125. */
  126. typedef struct ConfigVariable
  127. {
  128. char *name;
  129. char *value;
  130. char *errmsg;
  131. char *filename;
  132. int sourceline;
  133. bool ignore;
  134. bool applied;
  135. struct ConfigVariable *next;
  136. } ConfigVariable;
  137. extern bool ParseConfigFile(const char *config_file, bool strict,
  138. const char *calling_file, int calling_lineno,
  139. int depth, int elevel,
  140. ConfigVariable **head_p, ConfigVariable **tail_p);
  141. extern bool ParseConfigFp(FILE *fp, const char *config_file,
  142. int depth, int elevel,
  143. ConfigVariable **head_p, ConfigVariable **tail_p);
  144. extern bool ParseConfigDirectory(const char *includedir,
  145. const char *calling_file, int calling_lineno,
  146. int depth, int elevel,
  147. ConfigVariable **head_p,
  148. ConfigVariable **tail_p);
  149. extern void FreeConfigVariables(ConfigVariable *list);
  150. /*
  151. * The possible values of an enum variable are specified by an array of
  152. * name-value pairs. The "hidden" flag means the value is accepted but
  153. * won't be displayed when guc.c is asked for a list of acceptable values.
  154. */
  155. struct config_enum_entry
  156. {
  157. const char *name;
  158. int val;
  159. bool hidden;
  160. };
  161. /*
  162. * Signatures for per-variable check/assign/show hook functions
  163. */
  164. typedef bool (*GucBoolCheckHook) (bool *newval, void **extra, GucSource source);
  165. typedef bool (*GucIntCheckHook) (int *newval, void **extra, GucSource source);
  166. typedef bool (*GucRealCheckHook) (double *newval, void **extra, GucSource source);
  167. typedef bool (*GucStringCheckHook) (char **newval, void **extra, GucSource source);
  168. typedef bool (*GucEnumCheckHook) (int *newval, void **extra, GucSource source);
  169. typedef void (*GucBoolAssignHook) (bool newval, void *extra);
  170. typedef void (*GucIntAssignHook) (int newval, void *extra);
  171. typedef void (*GucRealAssignHook) (double newval, void *extra);
  172. typedef void (*GucStringAssignHook) (const char *newval, void *extra);
  173. typedef void (*GucEnumAssignHook) (int newval, void *extra);
  174. typedef const char *(*GucShowHook) (void);
  175. /*
  176. * Miscellaneous
  177. */
  178. typedef enum
  179. {
  180. /* Types of set_config_option actions */
  181. GUC_ACTION_SET, /* regular SET command */
  182. GUC_ACTION_LOCAL, /* SET LOCAL command */
  183. GUC_ACTION_SAVE /* function SET option, or temp assignment */
  184. } GucAction;
  185. #define GUC_QUALIFIER_SEPARATOR '.'
  186. /*
  187. * bit values in "flags" of a GUC variable
  188. */
  189. #define GUC_LIST_INPUT 0x0001 /* input can be list format */
  190. #define GUC_LIST_QUOTE 0x0002 /* double-quote list elements */
  191. #define GUC_NO_SHOW_ALL 0x0004 /* exclude from SHOW ALL */
  192. #define GUC_NO_RESET_ALL 0x0008 /* exclude from RESET ALL */
  193. #define GUC_REPORT 0x0010 /* auto-report changes to client */
  194. #define GUC_NOT_IN_SAMPLE 0x0020 /* not in postgresql.conf.sample */
  195. #define GUC_DISALLOW_IN_FILE 0x0040 /* can't set in postgresql.conf */
  196. #define GUC_CUSTOM_PLACEHOLDER 0x0080 /* placeholder for custom variable */
  197. #define GUC_SUPERUSER_ONLY 0x0100 /* show only to superusers */
  198. #define GUC_IS_NAME 0x0200 /* limit string to NAMEDATALEN-1 */
  199. #define GUC_NOT_WHILE_SEC_REST 0x0400 /* can't set if security restricted */
  200. #define GUC_DISALLOW_IN_AUTO_FILE 0x0800 /* can't set in
  201. * PG_AUTOCONF_FILENAME */
  202. #define GUC_UNIT_KB 0x1000 /* value is in kilobytes */
  203. #define GUC_UNIT_BLOCKS 0x2000 /* value is in blocks */
  204. #define GUC_UNIT_XBLOCKS 0x3000 /* value is in xlog blocks */
  205. #define GUC_UNIT_XSEGS 0x4000 /* value is in xlog segments */
  206. #define GUC_UNIT_MEMORY 0xF000 /* mask for size-related units */
  207. #define GUC_UNIT_MS 0x10000 /* value is in milliseconds */
  208. #define GUC_UNIT_S 0x20000 /* value is in seconds */
  209. #define GUC_UNIT_MIN 0x30000 /* value is in minutes */
  210. #define GUC_UNIT_TIME 0xF0000 /* mask for time-related units */
  211. #define GUC_UNIT (GUC_UNIT_MEMORY | GUC_UNIT_TIME)
  212. /* GUC vars that are actually declared in guc.c, rather than elsewhere */
  213. extern bool log_duration;
  214. extern bool Debug_print_plan;
  215. extern bool Debug_print_parse;
  216. extern bool Debug_print_rewritten;
  217. extern bool Debug_pretty_print;
  218. extern bool log_parser_stats;
  219. extern bool log_planner_stats;
  220. extern bool log_executor_stats;
  221. extern bool log_statement_stats;
  222. extern bool log_btree_build_stats;
  223. extern PGDLLIMPORT bool check_function_bodies;
  224. extern bool default_with_oids;
  225. extern bool SQL_inheritance;
  226. extern int log_min_error_statement;
  227. extern int log_min_messages;
  228. extern int client_min_messages;
  229. extern int log_min_duration_statement;
  230. extern int log_temp_files;
  231. extern int temp_file_limit;
  232. extern int num_temp_buffers;
  233. extern char *cluster_name;
  234. extern char *ConfigFileName;
  235. extern char *HbaFileName;
  236. extern char *IdentFileName;
  237. extern char *external_pid_file;
  238. extern char *application_name;
  239. extern int tcp_keepalives_idle;
  240. extern int tcp_keepalives_interval;
  241. extern int tcp_keepalives_count;
  242. #ifdef TRACE_SORT
  243. extern bool trace_sort;
  244. #endif
  245. /*
  246. * Functions exported by guc.c
  247. */
  248. extern void SetConfigOption(const char *name, const char *value,
  249. GucContext context, GucSource source);
  250. extern void DefineCustomBoolVariable(
  251. const char *name,
  252. const char *short_desc,
  253. const char *long_desc,
  254. bool *valueAddr,
  255. bool bootValue,
  256. GucContext context,
  257. int flags,
  258. GucBoolCheckHook check_hook,
  259. GucBoolAssignHook assign_hook,
  260. GucShowHook show_hook);
  261. extern void DefineCustomIntVariable(
  262. const char *name,
  263. const char *short_desc,
  264. const char *long_desc,
  265. int *valueAddr,
  266. int bootValue,
  267. int minValue,
  268. int maxValue,
  269. GucContext context,
  270. int flags,
  271. GucIntCheckHook check_hook,
  272. GucIntAssignHook assign_hook,
  273. GucShowHook show_hook);
  274. extern void DefineCustomRealVariable(
  275. const char *name,
  276. const char *short_desc,
  277. const char *long_desc,
  278. double *valueAddr,
  279. double bootValue,
  280. double minValue,
  281. double maxValue,
  282. GucContext context,
  283. int flags,
  284. GucRealCheckHook check_hook,
  285. GucRealAssignHook assign_hook,
  286. GucShowHook show_hook);
  287. extern void DefineCustomStringVariable(
  288. const char *name,
  289. const char *short_desc,
  290. const char *long_desc,
  291. char **valueAddr,
  292. const char *bootValue,
  293. GucContext context,
  294. int flags,
  295. GucStringCheckHook check_hook,
  296. GucStringAssignHook assign_hook,
  297. GucShowHook show_hook);
  298. extern void DefineCustomEnumVariable(
  299. const char *name,
  300. const char *short_desc,
  301. const char *long_desc,
  302. int *valueAddr,
  303. int bootValue,
  304. const struct config_enum_entry * options,
  305. GucContext context,
  306. int flags,
  307. GucEnumCheckHook check_hook,
  308. GucEnumAssignHook assign_hook,
  309. GucShowHook show_hook);
  310. extern void EmitWarningsOnPlaceholders(const char *className);
  311. extern const char *GetConfigOption(const char *name, bool missing_ok,
  312. bool restrict_superuser);
  313. extern const char *GetConfigOptionResetString(const char *name);
  314. extern void ProcessConfigFile(GucContext context);
  315. extern void InitializeGUCOptions(void);
  316. extern bool SelectConfigFiles(const char *userDoption, const char *progname);
  317. extern void ResetAllOptions(void);
  318. extern void AtStart_GUC(void);
  319. extern int NewGUCNestLevel(void);
  320. extern void AtEOXact_GUC(bool isCommit, int nestLevel);
  321. extern void BeginReportingGUCOptions(void);
  322. extern void ParseLongOption(const char *string, char **name, char **value);
  323. extern bool parse_int(const char *value, int *result, int flags,
  324. const char **hintmsg);
  325. extern bool parse_real(const char *value, double *result);
  326. extern int set_config_option(const char *name, const char *value,
  327. GucContext context, GucSource source,
  328. GucAction action, bool changeVal, int elevel,
  329. bool is_reload);
  330. extern void AlterSystemSetConfigFile(AlterSystemStmt *setstmt);
  331. extern char *GetConfigOptionByName(const char *name, const char **varname,
  332. bool missing_ok);
  333. extern void GetConfigOptionByNum(int varnum, const char **values, bool *noshow);
  334. extern int GetNumConfigOptions(void);
  335. extern void SetPGVariable(const char *name, List *args, bool is_local);
  336. extern void GetPGVariable(const char *name, DestReceiver *dest);
  337. extern TupleDesc GetPGVariableResultDesc(const char *name);
  338. extern void ExecSetVariableStmt(VariableSetStmt *stmt, bool isTopLevel);
  339. extern char *ExtractSetVariableArgs(VariableSetStmt *stmt);
  340. extern void ProcessGUCArray(ArrayType *array,
  341. GucContext context, GucSource source, GucAction action);
  342. extern ArrayType *GUCArrayAdd(ArrayType *array, const char *name, const char *value);
  343. extern ArrayType *GUCArrayDelete(ArrayType *array, const char *name);
  344. extern ArrayType *GUCArrayReset(ArrayType *array);
  345. #ifdef EXEC_BACKEND
  346. extern void write_nondefault_variables(GucContext context);
  347. extern void read_nondefault_variables(void);
  348. #endif
  349. /* GUC serialization */
  350. extern Size EstimateGUCStateSpace(void);
  351. extern void SerializeGUCState(Size maxsize, char *start_address);
  352. extern void RestoreGUCState(void *gucstate);
  353. /* Support for messages reported from GUC check hooks */
  354. extern PGDLLIMPORT char *GUC_check_errmsg_string;
  355. extern PGDLLIMPORT char *GUC_check_errdetail_string;
  356. extern PGDLLIMPORT char *GUC_check_errhint_string;
  357. extern void GUC_check_errcode(int sqlerrcode);
  358. #define GUC_check_errmsg \
  359. pre_format_elog_string(errno, TEXTDOMAIN), \
  360. GUC_check_errmsg_string = format_elog_string
  361. #define GUC_check_errdetail \
  362. pre_format_elog_string(errno, TEXTDOMAIN), \
  363. GUC_check_errdetail_string = format_elog_string
  364. #define GUC_check_errhint \
  365. pre_format_elog_string(errno, TEXTDOMAIN), \
  366. GUC_check_errhint_string = format_elog_string
  367. /*
  368. * The following functions are not in guc.c, but are declared here to avoid
  369. * having to include guc.h in some widely used headers that it really doesn't
  370. * belong in.
  371. */
  372. /* in commands/tablespace.c */
  373. extern bool check_default_tablespace(char **newval, void **extra, GucSource source);
  374. extern bool check_temp_tablespaces(char **newval, void **extra, GucSource source);
  375. extern void assign_temp_tablespaces(const char *newval, void *extra);
  376. /* in catalog/namespace.c */
  377. extern bool check_search_path(char **newval, void **extra, GucSource source);
  378. extern void assign_search_path(const char *newval, void *extra);
  379. /* in access/transam/xlog.c */
  380. extern bool check_wal_buffers(int *newval, void **extra, GucSource source);
  381. extern void assign_xlog_sync_method(int new_sync_method, void *extra);
  382. #endif /* GUC_H */