guc_tables.h 6.9 KB
Newer Older
1 2 3 4 5 6 7
/*-------------------------------------------------------------------------
 *
 * guc_tables.h
 *		Declarations of tables used by GUC.
 *
 * See src/backend/utils/misc/README for design notes.
 *
B
Bruce Momjian 已提交
8
 * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
9
 *
10
 *	  src/include/utils/guc_tables.h
11 12 13
 *
 *-------------------------------------------------------------------------
 */
14 15 16
#ifndef GUC_TABLES_H
#define GUC_TABLES_H 1

17 18
#include "utils/guc.h"

19 20 21 22 23 24 25 26
/*
 * GUC supports these types of variables:
 */
enum config_type
{
	PGC_BOOL,
	PGC_INT,
	PGC_REAL,
27 28
	PGC_STRING,
	PGC_ENUM
29 30
};

31
union config_var_val
32 33 34 35 36
{
	bool		boolval;
	int			intval;
	double		realval;
	char	   *stringval;
37 38 39
	int			enumval;
};

40 41 42 43 44 45 46 47 48 49
/*
 * The actual value of a GUC variable can include a malloc'd opaque struct
 * "extra", which is created by its check_hook and used by its assign_hook.
 */
typedef struct config_var_value
{
	union config_var_val val;
	void	   *extra;
} config_var_value;

50
/*
51
 * Groupings to help organize all the run-time options for display
52 53 54 55
 */
enum config_group
{
	UNGROUPED,
56
	FILE_LOCATIONS,
57 58 59 60 61
	CONN_AUTH,
	CONN_AUTH_SETTINGS,
	CONN_AUTH_SECURITY,
	RESOURCES,
	RESOURCES_MEM,
62
	RESOURCES_DISK,
63
	RESOURCES_KERNEL,
64 65 66
	RESOURCES_VACUUM_DELAY,
	RESOURCES_BGWRITER,
	RESOURCES_ASYNCHRONOUS,
67 68 69
	WAL,
	WAL_SETTINGS,
	WAL_CHECKPOINTS,
70
	WAL_ARCHIVING,
71 72 73
	REPLICATION,
	REPLICATION_MASTER,
	REPLICATION_STANDBY,
74 75 76 77 78 79
	QUERY_TUNING,
	QUERY_TUNING_METHOD,
	QUERY_TUNING_COST,
	QUERY_TUNING_GEQO,
	QUERY_TUNING_OTHER,
	LOGGING,
80
	LOGGING_WHERE,
81 82 83 84 85
	LOGGING_WHEN,
	LOGGING_WHAT,
	STATS,
	STATS_MONITORING,
	STATS_COLLECTOR,
86
	AUTOVACUUM,
87 88 89 90 91 92 93 94
	CLIENT_CONN,
	CLIENT_CONN_STATEMENT,
	CLIENT_CONN_LOCALE,
	CLIENT_CONN_OTHER,
	LOCK_MANAGEMENT,
	COMPAT_OPTIONS,
	COMPAT_OPTIONS_PREVIOUS,
	COMPAT_OPTIONS_CLIENT,
R
Robert Haas 已提交
95
	ERROR_HANDLING_OPTIONS,
96 97 98
	PRESET_OPTIONS,
	CUSTOM_OPTIONS,
	DEVELOPER_OPTIONS
99 100 101
};

/*
102 103
 * Stack entry for saving the state a variable had prior to an uncommitted
 * transactional change
104
 */
105 106 107 108 109 110 111
typedef enum
{
	/* This is almost GucAction, but we need a fourth state for SET+LOCAL */
	GUC_SAVE,					/* entry caused by function SET option */
	GUC_SET,					/* entry caused by plain SET command */
	GUC_LOCAL,					/* entry caused by SET LOCAL command */
	GUC_SET_LOCAL				/* entry caused by SET then SET LOCAL */
112
} GucStackState;
113

114
typedef struct guc_stack
115
{
116
	struct guc_stack *prev;		/* previous stack item, if any */
117 118 119
	int			nest_level;		/* nesting depth at which we made entry */
	GucStackState state;		/* see enum above */
	GucSource	source;			/* source of the prior value */
120 121
	config_var_value prior;		/* previous value of variable */
	config_var_value masked;	/* SET value in a GUC_SET_LOCAL entry */
122
	/* masked value's source must be PGC_S_SESSION, so no need to store it */
123
} GucStack;
124 125 126 127 128

/*
 * Generic fields applicable to all types of variables
 *
 * The short description should be less than 80 chars in length. Some
B
Bruce Momjian 已提交
129 130
 * applications may use the long description as well, and will append
 * it to the short description. (separated by a newline or '. ')
131 132 133 134 135
 *
 * Note that sourcefile/sourceline are kept here, and not pushed into stacked
 * values, although in principle they belong with some stacked value if the
 * active value is session- or transaction-local.  This is to avoid bloating
 * stack entries.  We know they are only relevant when source == PGC_S_FILE.
136 137 138 139 140 141
 */
struct config_generic
{
	/* constant fields, must be set correctly in initial value: */
	const char *name;			/* name of variable - MUST BE FIRST */
	GucContext	context;		/* context required to set the variable */
B
Bruce Momjian 已提交
142 143 144
	enum config_group group;	/* to help organize variables by function */
	const char *short_desc;		/* short desc. of this variable's purpose */
	const char *long_desc;		/* long desc. of this variable's purpose */
145 146 147 148 149 150
	int			flags;			/* flag bits, see below */
	/* variable fields, initialized at runtime: */
	enum config_type vartype;	/* type of variable (set only at startup) */
	int			status;			/* status bits, see below */
	GucSource	reset_source;	/* source of the reset_value */
	GucSource	source;			/* source of the current actual value */
151
	GucStack   *stack;			/* stacked prior values */
152 153
	void	   *extra;			/* "extra" pointer for current actual value */
	char	   *sourcefile;		/* file current setting is from (NULL if not
154
								 * file) */
155
	int			sourceline;		/* line in source file */
156 157
};

158
/* bit values in flags field are defined in guc.h */
159

160
/* bit values in status field */
161
#define GUC_IS_IN_FILE		0x0001		/* found it in config file */
162 163 164 165
/*
 * Caution: the GUC_IS_IN_FILE bit is transient state for ProcessConfigFile.
 * Do not assume that its value represents useful information elsewhere.
 */
166

167 168 169 170 171 172

/* GUC records for specific variable types */

struct config_bool
{
	struct config_generic gen;
173
	/* constant fields, must be set correctly in initial value: */
174
	bool	   *variable;
175
	bool		boot_val;
176
	GucBoolCheckHook check_hook;
177 178
	GucBoolAssignHook assign_hook;
	GucShowHook show_hook;
179
	/* variable fields, initialized at runtime: */
180
	bool		reset_val;
181
	void	   *reset_extra;
182 183 184 185 186
};

struct config_int
{
	struct config_generic gen;
187
	/* constant fields, must be set correctly in initial value: */
188
	int		   *variable;
189
	int			boot_val;
190 191
	int			min;
	int			max;
192
	GucIntCheckHook check_hook;
193 194
	GucIntAssignHook assign_hook;
	GucShowHook show_hook;
195
	/* variable fields, initialized at runtime: */
196
	int			reset_val;
197
	void	   *reset_extra;
198 199 200 201 202
};

struct config_real
{
	struct config_generic gen;
203
	/* constant fields, must be set correctly in initial value: */
204
	double	   *variable;
205
	double		boot_val;
206 207
	double		min;
	double		max;
208
	GucRealCheckHook check_hook;
209 210
	GucRealAssignHook assign_hook;
	GucShowHook show_hook;
211
	/* variable fields, initialized at runtime: */
212
	double		reset_val;
213
	void	   *reset_extra;
214 215 216 217 218
};

struct config_string
{
	struct config_generic gen;
219
	/* constant fields, must be set correctly in initial value: */
220 221
	char	  **variable;
	const char *boot_val;
222
	GucStringCheckHook check_hook;
223 224
	GucStringAssignHook assign_hook;
	GucShowHook show_hook;
225 226
	/* variable fields, initialized at runtime: */
	char	   *reset_val;
227
	void	   *reset_extra;
228 229
};

230 231 232 233 234 235 236
struct config_enum
{
	struct config_generic gen;
	/* constant fields, must be set correctly in initial value: */
	int		   *variable;
	int			boot_val;
	const struct config_enum_entry *options;
237
	GucEnumCheckHook check_hook;
238 239 240 241
	GucEnumAssignHook assign_hook;
	GucShowHook show_hook;
	/* variable fields, initialized at runtime: */
	int			reset_val;
242
	void	   *reset_extra;
243 244
};

245
/* constant tables corresponding to enums above and in guc.h */
B
Bruce Momjian 已提交
246 247 248 249
extern const char *const config_group_names[];
extern const char *const config_type_names[];
extern const char *const GucContext_Names[];
extern const char *const GucSource_Names[];
250

251 252
/* get the current set of variables */
extern struct config_generic **get_guc_variables(void);
253 254 255

extern void build_guc_variables(void);

256
/* search in enum options */
257 258 259
extern const char *config_enum_lookup_by_value(struct config_enum * record, int val);
extern bool config_enum_lookup_by_name(struct config_enum * record,
						   const char *value, int *retval);
260 261


B
Bruce Momjian 已提交
262
#endif   /* GUC_TABLES_H */