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