]> granicus.if.org Git - postgresql/blob - src/include/utils/guc.h
Some cleanups of enum-guc code, per comments from Tom.
[postgresql] / src / include / utils / guc.h
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-2008, PostgreSQL Global Development Group
8  * Written by Peter Eisentraut <peter_e@gmx.net>.
9  *
10  * $PostgreSQL: pgsql/src/include/utils/guc.h,v 1.92 2008/03/16 16:42:44 mha Exp $
11  *--------------------------------------------------------------------
12  */
13 #ifndef GUC_H
14 #define GUC_H
15
16 #include "nodes/parsenodes.h"
17 #include "tcop/dest.h"
18 #include "utils/array.h"
19
20
21 /*
22  * Certain options can only be set at certain times. The rules are
23  * like this:
24  *
25  * INTERNAL options cannot be set by the user at all, but only through
26  * internal processes ("server_version" is an example).  These are GUC
27  * variables only so they can be shown by SHOW, etc.
28  *
29  * POSTMASTER options can only be set when the postmaster starts,
30  * either from the configuration file or the command line.
31  *
32  * SIGHUP options can only be set at postmaster startup or by changing
33  * the configuration file and sending the HUP signal to the postmaster
34  * or a backend process. (Notice that the signal receipt will not be
35  * evaluated immediately. The postmaster and the backend check it at a
36  * certain point in their main loop. It's safer to wait than to read a
37  * file asynchronously.)
38  *
39  * BACKEND options can only be set at postmaster startup, from the
40  * configuration file, or by client request in the connection startup
41  * packet (e.g., from libpq's PGOPTIONS variable).  Furthermore, an
42  * already-started backend will ignore changes to such an option in the
43  * configuration file.  The idea is that these options are fixed for a
44  * given backend once it's started, but they can vary across backends.
45  *
46  * SUSET options can be set at postmaster startup, with the SIGHUP
47  * mechanism, or from SQL if you're a superuser.
48  *
49  * USERSET options can be set by anyone any time.
50  */
51 typedef enum
52 {
53         PGC_INTERNAL,
54         PGC_POSTMASTER,
55         PGC_SIGHUP,
56         PGC_BACKEND,
57         PGC_SUSET,
58         PGC_USERSET
59 } GucContext;
60
61 /*
62  * The following type records the source of the current setting.  A
63  * new setting can only take effect if the previous setting had the
64  * same or lower level.  (E.g, changing the config file doesn't
65  * override the postmaster command line.)  Tracking the source allows us
66  * to process sources in any convenient order without affecting results.
67  * Sources <= PGC_S_OVERRIDE will set the default used by RESET, as well
68  * as the current value.  Note that source == PGC_S_OVERRIDE should be
69  * used when setting a PGC_INTERNAL option.
70  *
71  * PGC_S_INTERACTIVE isn't actually a source value, but is the
72  * dividing line between "interactive" and "non-interactive" sources for
73  * error reporting purposes.
74  *
75  * PGC_S_TEST is used when testing values to be stored as per-database or
76  * per-user defaults ("doit" will always be false, so this never gets stored
77  * as the actual source of any value).  This is an interactive case, but
78  * it needs its own source value because some assign hooks need to make
79  * different validity checks in this case.
80  */
81 typedef enum
82 {
83         PGC_S_DEFAULT,                          /* wired-in default */
84         PGC_S_ENV_VAR,                          /* postmaster environment variable */
85         PGC_S_FILE,                                     /* postgresql.conf */
86         PGC_S_ARGV,                                     /* postmaster command line */
87         PGC_S_DATABASE,                         /* per-database setting */
88         PGC_S_USER,                                     /* per-user setting */
89         PGC_S_CLIENT,                           /* from client connection request */
90         PGC_S_OVERRIDE,                         /* special case to forcibly set default */
91         PGC_S_INTERACTIVE,                      /* dividing line for error reporting */
92         PGC_S_TEST,                                     /* test per-database or per-user setting */
93         PGC_S_SESSION                           /* SET command */
94 } GucSource;
95
96 /*
97  * Enum values are made up of an array of name-value pairs
98  */
99 struct config_enum_entry
100 {
101         const char *name;
102         int         val;
103 };
104
105
106 typedef const char *(*GucStringAssignHook) (const char *newval, bool doit, GucSource source);
107 typedef bool (*GucBoolAssignHook) (bool newval, bool doit, GucSource source);
108 typedef bool (*GucIntAssignHook) (int newval, bool doit, GucSource source);
109 typedef bool (*GucRealAssignHook) (double newval, bool doit, GucSource source);
110 typedef bool (*GucEnumAssignHook) (int newval, bool doit, GucSource source);
111
112 typedef const char *(*GucShowHook) (void);
113
114 typedef enum
115 {
116         /* Types of set_config_option actions */
117         GUC_ACTION_SET,                         /* regular SET command */
118         GUC_ACTION_LOCAL,                       /* SET LOCAL command */
119         GUC_ACTION_SAVE                         /* function SET option */
120 } GucAction;
121
122 #define GUC_QUALIFIER_SEPARATOR '.'
123
124 /* GUC vars that are actually declared in guc.c, rather than elsewhere */
125 extern bool log_duration;
126 extern bool Debug_print_plan;
127 extern bool Debug_print_parse;
128 extern bool Debug_print_rewritten;
129 extern bool Debug_pretty_print;
130 extern bool Explain_pretty_print;
131
132 extern bool log_parser_stats;
133 extern bool log_planner_stats;
134 extern bool log_executor_stats;
135 extern bool log_statement_stats;
136 extern bool log_btree_build_stats;
137
138 extern PGDLLIMPORT bool check_function_bodies;
139 extern bool default_with_oids;
140 extern bool SQL_inheritance;
141
142 extern int      log_min_error_statement;
143 extern int      log_min_messages;
144 extern int      client_min_messages;
145 extern int      log_min_duration_statement;
146 extern int      log_temp_files;
147
148 extern int      num_temp_buffers;
149
150 extern char *ConfigFileName;
151 extern char *HbaFileName;
152 extern char *IdentFileName;
153 extern char *external_pid_file;
154
155 extern int      tcp_keepalives_idle;
156 extern int      tcp_keepalives_interval;
157 extern int      tcp_keepalives_count;
158
159 extern void SetConfigOption(const char *name, const char *value,
160                                 GucContext context, GucSource source);
161
162 extern void DefineCustomBoolVariable(
163                                                  const char *name,
164                                                  const char *short_desc,
165                                                  const char *long_desc,
166                                                  bool *valueAddr,
167                                                  GucContext context,
168                                                  GucBoolAssignHook assign_hook,
169                                                  GucShowHook show_hook);
170
171 extern void DefineCustomIntVariable(
172                                                 const char *name,
173                                                 const char *short_desc,
174                                                 const char *long_desc,
175                                                 int *valueAddr,
176                                                 int minValue,
177                                                 int maxValue,
178                                                 GucContext context,
179                                                 GucIntAssignHook assign_hook,
180                                                 GucShowHook show_hook);
181
182 extern void DefineCustomRealVariable(
183                                                  const char *name,
184                                                  const char *short_desc,
185                                                  const char *long_desc,
186                                                  double *valueAddr,
187                                                  double minValue,
188                                                  double maxValue,
189                                                  GucContext context,
190                                                  GucRealAssignHook assign_hook,
191                                                  GucShowHook show_hook);
192
193 extern void DefineCustomStringVariable(
194                                                    const char *name,
195                                                    const char *short_desc,
196                                                    const char *long_desc,
197                                                    char **valueAddr,
198                                                    GucContext context,
199                                                    GucStringAssignHook assign_hook,
200                                                    GucShowHook show_hook);
201
202 extern void DefineCustomEnumVariable(
203                                                    const char *name,
204                                                    const char *short_desc,
205                                                    const char *long_desc,
206                                                    int *valueAddr,
207                                                    const struct config_enum_entry *options,
208                                                    GucContext context,
209                                                    GucEnumAssignHook assign_hook,
210                                                    GucShowHook show_hook);
211
212 extern void EmitWarningsOnPlaceholders(const char *className);
213
214 extern const char *GetConfigOption(const char *name);
215 extern const char *GetConfigOptionResetString(const char *name);
216 extern bool IsSuperuserConfigOption(const char *name);
217 extern void ProcessConfigFile(GucContext context);
218 extern void InitializeGUCOptions(void);
219 extern bool SelectConfigFiles(const char *userDoption, const char *progname);
220 extern void ResetAllOptions(void);
221 extern void AtStart_GUC(void);
222 extern int      NewGUCNestLevel(void);
223 extern void AtEOXact_GUC(bool isCommit, int nestLevel);
224 extern void BeginReportingGUCOptions(void);
225 extern void ParseLongOption(const char *string, char **name, char **value);
226 extern bool set_config_option(const char *name, const char *value,
227                                   GucContext context, GucSource source,
228                                   GucAction action, bool changeVal);
229 extern char *GetConfigOptionByName(const char *name, const char **varname);
230 extern void GetConfigOptionByNum(int varnum, const char **values, bool *noshow);
231 extern int      GetNumConfigOptions(void);
232
233 extern void SetPGVariable(const char *name, List *args, bool is_local);
234 extern void GetPGVariable(const char *name, DestReceiver *dest);
235 extern TupleDesc GetPGVariableResultDesc(const char *name);
236
237 extern void ExecSetVariableStmt(VariableSetStmt *stmt);
238 extern char *ExtractSetVariableArgs(VariableSetStmt *stmt);
239
240 extern void ProcessGUCArray(ArrayType *array,
241                                 GucContext context, GucSource source, GucAction action);
242 extern ArrayType *GUCArrayAdd(ArrayType *array, const char *name, const char *value);
243 extern ArrayType *GUCArrayDelete(ArrayType *array, const char *name);
244
245 extern int      GUC_complaint_elevel(GucSource source);
246
247 extern void pg_timezone_abbrev_initialize(void);
248
249 #ifdef EXEC_BACKEND
250 extern void write_nondefault_variables(GucContext context);
251 extern void read_nondefault_variables(void);
252 #endif
253
254 /*
255  * The following functions are not in guc.c, but are declared here to avoid
256  * having to include guc.h in some widely used headers that it really doesn't
257  * belong in.
258  */
259
260 /* in commands/tablespace.c */
261 extern const char *assign_default_tablespace(const char *newval,
262                                                   bool doit, GucSource source);
263 extern const char *assign_temp_tablespaces(const char *newval,
264                                                 bool doit, GucSource source);
265
266 /* in utils/adt/regexp.c */
267 extern const char *assign_regex_flavor(const char *value,
268                                         bool doit, GucSource source);
269
270 /* in catalog/namespace.c */
271 extern const char *assign_search_path(const char *newval,
272                                    bool doit, GucSource source);
273
274 /* in access/transam/xlog.c */
275 extern const char *assign_xlog_sync_method(const char *method,
276                                                 bool doit, GucSource source);
277
278 #endif   /* GUC_H */