gooderp18绿色标准版
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

438 lines
16KB

  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-2019, 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_MB 0x4000 /* value is in megabytes */
  206. #define GUC_UNIT_BYTE 0x8000 /* value is in bytes */
  207. #define GUC_UNIT_MEMORY 0xF000 /* mask for size-related units */
  208. #define GUC_UNIT_MS 0x10000 /* value is in milliseconds */
  209. #define GUC_UNIT_S 0x20000 /* value is in seconds */
  210. #define GUC_UNIT_MIN 0x30000 /* value is in minutes */
  211. #define GUC_UNIT_TIME 0xF0000 /* mask for time-related units */
  212. #define GUC_EXPLAIN 0x100000 /* include in explain */
  213. #define GUC_UNIT (GUC_UNIT_MEMORY | GUC_UNIT_TIME)
  214. /* GUC vars that are actually declared in guc.c, rather than elsewhere */
  215. extern bool log_duration;
  216. extern bool Debug_print_plan;
  217. extern bool Debug_print_parse;
  218. extern bool Debug_print_rewritten;
  219. extern bool Debug_pretty_print;
  220. extern bool log_parser_stats;
  221. extern bool log_planner_stats;
  222. extern bool log_executor_stats;
  223. extern bool log_statement_stats;
  224. extern bool log_btree_build_stats;
  225. extern PGDLLIMPORT bool check_function_bodies;
  226. extern bool session_auth_is_superuser;
  227. extern int log_min_error_statement;
  228. extern PGDLLIMPORT int log_min_messages;
  229. extern PGDLLIMPORT int client_min_messages;
  230. extern int log_min_duration_statement;
  231. extern int log_temp_files;
  232. extern double log_xact_sample_rate;
  233. extern int temp_file_limit;
  234. extern int num_temp_buffers;
  235. extern char *cluster_name;
  236. extern PGDLLIMPORT char *ConfigFileName;
  237. extern char *HbaFileName;
  238. extern char *IdentFileName;
  239. extern char *external_pid_file;
  240. extern PGDLLIMPORT char *application_name;
  241. extern int tcp_keepalives_idle;
  242. extern int tcp_keepalives_interval;
  243. extern int tcp_keepalives_count;
  244. extern int tcp_user_timeout;
  245. #ifdef TRACE_SORT
  246. extern bool trace_sort;
  247. #endif
  248. /*
  249. * Functions exported by guc.c
  250. */
  251. extern void SetConfigOption(const char *name, const char *value,
  252. GucContext context, GucSource source);
  253. extern void DefineCustomBoolVariable(const char *name,
  254. const char *short_desc,
  255. const char *long_desc,
  256. bool *valueAddr,
  257. bool bootValue,
  258. GucContext context,
  259. int flags,
  260. GucBoolCheckHook check_hook,
  261. GucBoolAssignHook assign_hook,
  262. GucShowHook show_hook);
  263. extern void DefineCustomIntVariable(const char *name,
  264. const char *short_desc,
  265. const char *long_desc,
  266. int *valueAddr,
  267. int bootValue,
  268. int minValue,
  269. int maxValue,
  270. GucContext context,
  271. int flags,
  272. GucIntCheckHook check_hook,
  273. GucIntAssignHook assign_hook,
  274. GucShowHook show_hook);
  275. extern void DefineCustomRealVariable(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(const char *name,
  288. const char *short_desc,
  289. const char *long_desc,
  290. char **valueAddr,
  291. const char *bootValue,
  292. GucContext context,
  293. int flags,
  294. GucStringCheckHook check_hook,
  295. GucStringAssignHook assign_hook,
  296. GucShowHook show_hook);
  297. extern void DefineCustomEnumVariable(const char *name,
  298. const char *short_desc,
  299. const char *long_desc,
  300. int *valueAddr,
  301. int bootValue,
  302. const struct config_enum_entry *options,
  303. GucContext context,
  304. int flags,
  305. GucEnumCheckHook check_hook,
  306. GucEnumAssignHook assign_hook,
  307. GucShowHook show_hook);
  308. extern void EmitWarningsOnPlaceholders(const char *className);
  309. extern const char *GetConfigOption(const char *name, bool missing_ok,
  310. bool restrict_privileged);
  311. extern const char *GetConfigOptionResetString(const char *name);
  312. extern int GetConfigOptionFlags(const char *name, bool missing_ok);
  313. extern void ProcessConfigFile(GucContext context);
  314. extern void InitializeGUCOptions(void);
  315. extern bool SelectConfigFiles(const char *userDoption, const char *progname);
  316. extern void ResetAllOptions(void);
  317. extern void AtStart_GUC(void);
  318. extern int NewGUCNestLevel(void);
  319. extern void AtEOXact_GUC(bool isCommit, int nestLevel);
  320. extern void BeginReportingGUCOptions(void);
  321. extern void ParseLongOption(const char *string, char **name, char **value);
  322. extern bool parse_int(const char *value, int *result, int flags,
  323. const char **hintmsg);
  324. extern bool parse_real(const char *value, double *result, int flags,
  325. const char **hintmsg);
  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 */
上海开阖软件有限公司 沪ICP备12045867号-1