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