guc_tables.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /*-------------------------------------------------------------------------
  2. *
  3. * guc_tables.h
  4. * Declarations of tables used by GUC.
  5. *
  6. * See src/backend/utils/misc/README for design notes.
  7. *
  8. * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
  9. *
  10. * src/include/utils/guc_tables.h
  11. *
  12. *-------------------------------------------------------------------------
  13. */
  14. #ifndef GUC_TABLES_H
  15. #define GUC_TABLES_H 1
  16. #include "utils/guc.h"
  17. /*
  18. * GUC supports these types of variables:
  19. */
  20. enum config_type
  21. {
  22. PGC_BOOL,
  23. PGC_INT,
  24. PGC_REAL,
  25. PGC_STRING,
  26. PGC_ENUM
  27. };
  28. union config_var_val
  29. {
  30. bool boolval;
  31. int intval;
  32. double realval;
  33. char *stringval;
  34. int enumval;
  35. };
  36. /*
  37. * The actual value of a GUC variable can include a malloc'd opaque struct
  38. * "extra", which is created by its check_hook and used by its assign_hook.
  39. */
  40. typedef struct config_var_value
  41. {
  42. union config_var_val val;
  43. void *extra;
  44. } config_var_value;
  45. /*
  46. * Groupings to help organize all the run-time options for display.
  47. * Be sure this agrees with the way the options are categorized in config.sgml!
  48. */
  49. enum config_group
  50. {
  51. UNGROUPED, /* use for options not shown in pg_settings */
  52. FILE_LOCATIONS,
  53. CONN_AUTH_SETTINGS,
  54. CONN_AUTH_AUTH,
  55. CONN_AUTH_SSL,
  56. RESOURCES_MEM,
  57. RESOURCES_DISK,
  58. RESOURCES_KERNEL,
  59. RESOURCES_VACUUM_DELAY,
  60. RESOURCES_BGWRITER,
  61. RESOURCES_ASYNCHRONOUS,
  62. WAL_SETTINGS,
  63. WAL_CHECKPOINTS,
  64. WAL_ARCHIVING,
  65. WAL_RECOVERY,
  66. WAL_ARCHIVE_RECOVERY,
  67. WAL_RECOVERY_TARGET,
  68. REPLICATION_SENDING,
  69. REPLICATION_PRIMARY,
  70. REPLICATION_STANDBY,
  71. REPLICATION_SUBSCRIBERS,
  72. QUERY_TUNING_METHOD,
  73. QUERY_TUNING_COST,
  74. QUERY_TUNING_GEQO,
  75. QUERY_TUNING_OTHER,
  76. LOGGING_WHERE,
  77. LOGGING_WHEN,
  78. LOGGING_WHAT,
  79. PROCESS_TITLE,
  80. STATS_MONITORING,
  81. STATS_CUMULATIVE,
  82. AUTOVACUUM,
  83. CLIENT_CONN_STATEMENT,
  84. CLIENT_CONN_LOCALE,
  85. CLIENT_CONN_PRELOAD,
  86. CLIENT_CONN_OTHER,
  87. LOCK_MANAGEMENT,
  88. COMPAT_OPTIONS_PREVIOUS,
  89. COMPAT_OPTIONS_CLIENT,
  90. ERROR_HANDLING_OPTIONS,
  91. PRESET_OPTIONS,
  92. CUSTOM_OPTIONS,
  93. DEVELOPER_OPTIONS
  94. };
  95. /*
  96. * Stack entry for saving the state a variable had prior to an uncommitted
  97. * transactional change
  98. */
  99. typedef enum
  100. {
  101. /* This is almost GucAction, but we need a fourth state for SET+LOCAL */
  102. GUC_SAVE, /* entry caused by function SET option */
  103. GUC_SET, /* entry caused by plain SET command */
  104. GUC_LOCAL, /* entry caused by SET LOCAL command */
  105. GUC_SET_LOCAL /* entry caused by SET then SET LOCAL */
  106. } GucStackState;
  107. typedef struct guc_stack
  108. {
  109. struct guc_stack *prev; /* previous stack item, if any */
  110. int nest_level; /* nesting depth at which we made entry */
  111. GucStackState state; /* see enum above */
  112. GucSource source; /* source of the prior value */
  113. /* masked value's source must be PGC_S_SESSION, so no need to store it */
  114. GucContext scontext; /* context that set the prior value */
  115. GucContext masked_scontext; /* context that set the masked value */
  116. Oid srole; /* role that set the prior value */
  117. Oid masked_srole; /* role that set the masked value */
  118. config_var_value prior; /* previous value of variable */
  119. config_var_value masked; /* SET value in a GUC_SET_LOCAL entry */
  120. } GucStack;
  121. /*
  122. * Generic fields applicable to all types of variables
  123. *
  124. * The short description should be less than 80 chars in length. Some
  125. * applications may use the long description as well, and will append
  126. * it to the short description. (separated by a newline or '. ')
  127. *
  128. * srole is the role that set the current value, or BOOTSTRAP_SUPERUSERID
  129. * if the value came from an internal source or the config file. Similarly
  130. * for reset_srole (which is usually BOOTSTRAP_SUPERUSERID, but not always).
  131. *
  132. * Note that sourcefile/sourceline are kept here, and not pushed into stacked
  133. * values, although in principle they belong with some stacked value if the
  134. * active value is session- or transaction-local. This is to avoid bloating
  135. * stack entries. We know they are only relevant when source == PGC_S_FILE.
  136. */
  137. struct config_generic
  138. {
  139. /* constant fields, must be set correctly in initial value: */
  140. const char *name; /* name of variable - MUST BE FIRST */
  141. GucContext context; /* context required to set the variable */
  142. enum config_group group; /* to help organize variables by function */
  143. const char *short_desc; /* short desc. of this variable's purpose */
  144. const char *long_desc; /* long desc. of this variable's purpose */
  145. int flags; /* flag bits, see guc.h */
  146. /* variable fields, initialized at runtime: */
  147. enum config_type vartype; /* type of variable (set only at startup) */
  148. int status; /* status bits, see below */
  149. GucSource source; /* source of the current actual value */
  150. GucSource reset_source; /* source of the reset_value */
  151. GucContext scontext; /* context that set the current value */
  152. GucContext reset_scontext; /* context that set the reset value */
  153. Oid srole; /* role that set the current value */
  154. Oid reset_srole; /* role that set the reset value */
  155. GucStack *stack; /* stacked prior values */
  156. void *extra; /* "extra" pointer for current actual value */
  157. char *last_reported; /* if variable is GUC_REPORT, value last sent
  158. * to client (NULL if not yet sent) */
  159. char *sourcefile; /* file current setting is from (NULL if not
  160. * set in config file) */
  161. int sourceline; /* line in source file */
  162. };
  163. /* bit values in status field */
  164. #define GUC_IS_IN_FILE 0x0001 /* found it in config file */
  165. /*
  166. * Caution: the GUC_IS_IN_FILE bit is transient state for ProcessConfigFile.
  167. * Do not assume that its value represents useful information elsewhere.
  168. */
  169. #define GUC_PENDING_RESTART 0x0002 /* changed value cannot be applied yet */
  170. #define GUC_NEEDS_REPORT 0x0004 /* new value must be reported to client */
  171. /* GUC records for specific variable types */
  172. struct config_bool
  173. {
  174. struct config_generic gen;
  175. /* constant fields, must be set correctly in initial value: */
  176. bool *variable;
  177. bool boot_val;
  178. GucBoolCheckHook check_hook;
  179. GucBoolAssignHook assign_hook;
  180. GucShowHook show_hook;
  181. /* variable fields, initialized at runtime: */
  182. bool reset_val;
  183. void *reset_extra;
  184. };
  185. struct config_int
  186. {
  187. struct config_generic gen;
  188. /* constant fields, must be set correctly in initial value: */
  189. int *variable;
  190. int boot_val;
  191. int min;
  192. int max;
  193. GucIntCheckHook check_hook;
  194. GucIntAssignHook assign_hook;
  195. GucShowHook show_hook;
  196. /* variable fields, initialized at runtime: */
  197. int reset_val;
  198. void *reset_extra;
  199. };
  200. struct config_real
  201. {
  202. struct config_generic gen;
  203. /* constant fields, must be set correctly in initial value: */
  204. double *variable;
  205. double boot_val;
  206. double min;
  207. double max;
  208. GucRealCheckHook check_hook;
  209. GucRealAssignHook assign_hook;
  210. GucShowHook show_hook;
  211. /* variable fields, initialized at runtime: */
  212. double reset_val;
  213. void *reset_extra;
  214. };
  215. struct config_string
  216. {
  217. struct config_generic gen;
  218. /* constant fields, must be set correctly in initial value: */
  219. char **variable;
  220. const char *boot_val;
  221. GucStringCheckHook check_hook;
  222. GucStringAssignHook assign_hook;
  223. GucShowHook show_hook;
  224. /* variable fields, initialized at runtime: */
  225. char *reset_val;
  226. void *reset_extra;
  227. };
  228. struct config_enum
  229. {
  230. struct config_generic gen;
  231. /* constant fields, must be set correctly in initial value: */
  232. int *variable;
  233. int boot_val;
  234. const struct config_enum_entry *options;
  235. GucEnumCheckHook check_hook;
  236. GucEnumAssignHook assign_hook;
  237. GucShowHook show_hook;
  238. /* variable fields, initialized at runtime: */
  239. int reset_val;
  240. void *reset_extra;
  241. };
  242. /* constant tables corresponding to enums above and in guc.h */
  243. extern PGDLLIMPORT const char *const config_group_names[];
  244. extern PGDLLIMPORT const char *const config_type_names[];
  245. extern PGDLLIMPORT const char *const GucContext_Names[];
  246. extern PGDLLIMPORT const char *const GucSource_Names[];
  247. /* get the current set of variables */
  248. extern struct config_generic **get_guc_variables(void);
  249. extern void build_guc_variables(void);
  250. /* search in enum options */
  251. extern const char *config_enum_lookup_by_value(struct config_enum *record, int val);
  252. extern bool config_enum_lookup_by_name(struct config_enum *record,
  253. const char *value, int *retval);
  254. extern struct config_generic **get_explain_guc_options(int *num);
  255. #endif /* GUC_TABLES_H */