]> granicus.if.org Git - postgresql/blob - src/include/utils/guc.h
Revert exporting of internal GUC variable "data_directory".
[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-2015, PostgreSQL Global Development Group
8  * Written by Peter Eisentraut <peter_e@gmx.net>.
9  *
10  * src/include/utils/guc.h
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 /* upper limit for GUC variables measured in kilobytes of memory */
22 /* note that various places assume the byte size fits in a "long" variable */
23 #if SIZEOF_SIZE_T > 4 && SIZEOF_LONG > 4
24 #define MAX_KILOBYTES   INT_MAX
25 #else
26 #define MAX_KILOBYTES   (INT_MAX / 1024)
27 #endif
28
29 /*
30  * Automatic configuration file name for ALTER SYSTEM.
31  * This file will be used to store values of configuration parameters
32  * set by ALTER SYSTEM command.
33  */
34 #define PG_AUTOCONF_FILENAME            "postgresql.auto.conf"
35
36 /*
37  * Certain options can only be set at certain times. The rules are
38  * like this:
39  *
40  * INTERNAL options cannot be set by the user at all, but only through
41  * internal processes ("server_version" is an example).  These are GUC
42  * variables only so they can be shown by SHOW, etc.
43  *
44  * POSTMASTER options can only be set when the postmaster starts,
45  * either from the configuration file or the command line.
46  *
47  * SIGHUP options can only be set at postmaster startup or by changing
48  * the configuration file and sending the HUP signal to the postmaster
49  * or a backend process. (Notice that the signal receipt will not be
50  * evaluated immediately. The postmaster and the backend check it at a
51  * certain point in their main loop. It's safer to wait than to read a
52  * file asynchronously.)
53  *
54  * BACKEND and SU_BACKEND options can only be set at postmaster startup,
55  * from the configuration file, or by client request in the connection
56  * startup packet (e.g., from libpq's PGOPTIONS variable).  SU_BACKEND
57  * options can be set from the startup packet only when the user is a
58  * superuser.  Furthermore, an already-started backend will ignore changes
59  * to such an option in the configuration file.  The idea is that these
60  * options are fixed for a given backend once it's started, but they can
61  * vary across backends.
62  *
63  * SUSET options can be set at postmaster startup, with the SIGHUP
64  * mechanism, or from the startup packet or SQL if you're a superuser.
65  *
66  * USERSET options can be set by anyone any time.
67  */
68 typedef enum
69 {
70         PGC_INTERNAL,
71         PGC_POSTMASTER,
72         PGC_SIGHUP,
73         PGC_SU_BACKEND,
74         PGC_BACKEND,
75         PGC_SUSET,
76         PGC_USERSET
77 } GucContext;
78
79 /*
80  * The following type records the source of the current setting.  A
81  * new setting can only take effect if the previous setting had the
82  * same or lower level.  (E.g, changing the config file doesn't
83  * override the postmaster command line.)  Tracking the source allows us
84  * to process sources in any convenient order without affecting results.
85  * Sources <= PGC_S_OVERRIDE will set the default used by RESET, as well
86  * as the current value.  Note that source == PGC_S_OVERRIDE should be
87  * used when setting a PGC_INTERNAL option.
88  *
89  * PGC_S_INTERACTIVE isn't actually a source value, but is the
90  * dividing line between "interactive" and "non-interactive" sources for
91  * error reporting purposes.
92  *
93  * PGC_S_TEST is used when testing values to be used later ("doit" will always
94  * be false, so this never gets stored as the actual source of any value).
95  * For example, ALTER DATABASE/ROLE tests proposed per-database or per-user
96  * defaults this way, and CREATE FUNCTION tests proposed function SET clauses
97  * this way.  This is an interactive case, but it needs its own source value
98  * because some assign hooks need to make different validity checks in this
99  * case.  In particular, references to nonexistent database objects generally
100  * shouldn't throw hard errors in this case, at most NOTICEs, since the
101  * objects might exist by the time the setting is used for real.
102  *
103  * NB: see GucSource_Names in guc.c if you change this.
104  */
105 typedef enum
106 {
107         PGC_S_DEFAULT,                          /* hard-wired default ("boot_val") */
108         PGC_S_DYNAMIC_DEFAULT,          /* default computed during initialization */
109         PGC_S_ENV_VAR,                          /* postmaster environment variable */
110         PGC_S_FILE,                                     /* postgresql.conf */
111         PGC_S_ARGV,                                     /* postmaster command line */
112         PGC_S_GLOBAL,                           /* global in-database setting */
113         PGC_S_DATABASE,                         /* per-database setting */
114         PGC_S_USER,                                     /* per-user setting */
115         PGC_S_DATABASE_USER,            /* per-user-and-database setting */
116         PGC_S_CLIENT,                           /* from client connection request */
117         PGC_S_OVERRIDE,                         /* special case to forcibly set default */
118         PGC_S_INTERACTIVE,                      /* dividing line for error reporting */
119         PGC_S_TEST,                                     /* test per-database or per-user setting */
120         PGC_S_SESSION                           /* SET command */
121 } GucSource;
122
123 /*
124  * Parsing the configuration file will return a list of name-value pairs
125  * with source location info.
126  */
127 typedef struct ConfigVariable
128 {
129         char       *name;
130         char       *value;
131         char       *filename;
132         int                     sourceline;
133         struct ConfigVariable *next;
134 } ConfigVariable;
135
136 extern bool ParseConfigFile(const char *config_file, const char *calling_file,
137                                 bool strict, int depth, int elevel,
138                                 ConfigVariable **head_p, ConfigVariable **tail_p);
139 extern bool ParseConfigFp(FILE *fp, const char *config_file,
140                           int depth, int elevel,
141                           ConfigVariable **head_p, ConfigVariable **tail_p);
142 extern bool ParseConfigDirectory(const char *includedir,
143                                          const char *calling_file,
144                                          int depth, int elevel,
145                                          ConfigVariable **head_p,
146                                          ConfigVariable **tail_p);
147 extern void FreeConfigVariables(ConfigVariable *list);
148
149 /*
150  * The possible values of an enum variable are specified by an array of
151  * name-value pairs.  The "hidden" flag means the value is accepted but
152  * won't be displayed when guc.c is asked for a list of acceptable values.
153  */
154 struct config_enum_entry
155 {
156         const char *name;
157         int                     val;
158         bool            hidden;
159 };
160
161 /*
162  * Signatures for per-variable check/assign/show hook functions
163  */
164 typedef bool (*GucBoolCheckHook) (bool *newval, void **extra, GucSource source);
165 typedef bool (*GucIntCheckHook) (int *newval, void **extra, GucSource source);
166 typedef bool (*GucRealCheckHook) (double *newval, void **extra, GucSource source);
167 typedef bool (*GucStringCheckHook) (char **newval, void **extra, GucSource source);
168 typedef bool (*GucEnumCheckHook) (int *newval, void **extra, GucSource source);
169
170 typedef void (*GucBoolAssignHook) (bool newval, void *extra);
171 typedef void (*GucIntAssignHook) (int newval, void *extra);
172 typedef void (*GucRealAssignHook) (double newval, void *extra);
173 typedef void (*GucStringAssignHook) (const char *newval, void *extra);
174 typedef void (*GucEnumAssignHook) (int newval, void *extra);
175
176 typedef const char *(*GucShowHook) (void);
177
178 /*
179  * Miscellaneous
180  */
181 typedef enum
182 {
183         /* Types of set_config_option actions */
184         GUC_ACTION_SET,                         /* regular SET command */
185         GUC_ACTION_LOCAL,                       /* SET LOCAL command */
186         GUC_ACTION_SAVE                         /* function SET option, or temp assignment */
187 } GucAction;
188
189 #define GUC_QUALIFIER_SEPARATOR '.'
190
191 /*
192  * bit values in "flags" of a GUC variable
193  */
194 #define GUC_LIST_INPUT                  0x0001  /* input can be list format */
195 #define GUC_LIST_QUOTE                  0x0002  /* double-quote list elements */
196 #define GUC_NO_SHOW_ALL                 0x0004  /* exclude from SHOW ALL */
197 #define GUC_NO_RESET_ALL                0x0008  /* exclude from RESET ALL */
198 #define GUC_REPORT                              0x0010  /* auto-report changes to client */
199 #define GUC_NOT_IN_SAMPLE               0x0020  /* not in postgresql.conf.sample */
200 #define GUC_DISALLOW_IN_FILE    0x0040  /* can't set in postgresql.conf */
201 #define GUC_CUSTOM_PLACEHOLDER  0x0080  /* placeholder for custom variable */
202 #define GUC_SUPERUSER_ONLY              0x0100  /* show only to superusers */
203 #define GUC_IS_NAME                             0x0200  /* limit string to NAMEDATALEN-1 */
204 #define GUC_NOT_WHILE_SEC_REST  0x0400  /* can't set if security restricted */
205 #define GUC_DISALLOW_IN_AUTO_FILE 0x0800                /* can't set in
206                                                                                                  * PG_AUTOCONF_FILENAME */
207
208 #define GUC_UNIT_KB                             0x1000  /* value is in kilobytes */
209 #define GUC_UNIT_BLOCKS                 0x2000  /* value is in blocks */
210 #define GUC_UNIT_XBLOCKS                0x3000  /* value is in xlog blocks */
211 #define GUC_UNIT_XSEGS                  0x4000  /* value is in xlog segments */
212 #define GUC_UNIT_MEMORY                 0xF000  /* mask for KB, BLOCKS, XBLOCKS */
213
214 #define GUC_UNIT_MS                        0x10000      /* value is in milliseconds */
215 #define GUC_UNIT_S                         0x20000      /* value is in seconds */
216 #define GUC_UNIT_MIN               0x30000      /* value is in minutes */
217 #define GUC_UNIT_TIME              0xF0000      /* mask for MS, S, MIN */
218
219 #define GUC_UNIT                                (GUC_UNIT_MEMORY | GUC_UNIT_TIME)
220
221
222 /* GUC vars that are actually declared in guc.c, rather than elsewhere */
223 extern bool log_duration;
224 extern bool Debug_print_plan;
225 extern bool Debug_print_parse;
226 extern bool Debug_print_rewritten;
227 extern bool Debug_pretty_print;
228
229 extern bool log_parser_stats;
230 extern bool log_planner_stats;
231 extern bool log_executor_stats;
232 extern bool log_statement_stats;
233 extern bool log_btree_build_stats;
234
235 extern PGDLLIMPORT bool check_function_bodies;
236 extern bool default_with_oids;
237 extern bool SQL_inheritance;
238
239 extern int      log_min_error_statement;
240 extern int      log_min_messages;
241 extern int      client_min_messages;
242 extern int      log_min_duration_statement;
243 extern int      log_temp_files;
244
245 extern int      temp_file_limit;
246
247 extern int      num_temp_buffers;
248
249 extern char *cluster_name;
250 extern char *ConfigFileName;
251 extern char *HbaFileName;
252 extern char *IdentFileName;
253 extern char *external_pid_file;
254
255 extern char *application_name;
256
257 extern int      tcp_keepalives_idle;
258 extern int      tcp_keepalives_interval;
259 extern int      tcp_keepalives_count;
260
261 #ifdef TRACE_SORT
262 extern bool trace_sort;
263 #endif
264
265 /*
266  * Functions exported by guc.c
267  */
268 extern void SetConfigOption(const char *name, const char *value,
269                                 GucContext context, GucSource source);
270
271 extern void DefineCustomBoolVariable(
272                                                  const char *name,
273                                                  const char *short_desc,
274                                                  const char *long_desc,
275                                                  bool *valueAddr,
276                                                  bool bootValue,
277                                                  GucContext context,
278                                                  int flags,
279                                                  GucBoolCheckHook check_hook,
280                                                  GucBoolAssignHook assign_hook,
281                                                  GucShowHook show_hook);
282
283 extern void DefineCustomIntVariable(
284                                                 const char *name,
285                                                 const char *short_desc,
286                                                 const char *long_desc,
287                                                 int *valueAddr,
288                                                 int bootValue,
289                                                 int minValue,
290                                                 int maxValue,
291                                                 GucContext context,
292                                                 int flags,
293                                                 GucIntCheckHook check_hook,
294                                                 GucIntAssignHook assign_hook,
295                                                 GucShowHook show_hook);
296
297 extern void DefineCustomRealVariable(
298                                                  const char *name,
299                                                  const char *short_desc,
300                                                  const char *long_desc,
301                                                  double *valueAddr,
302                                                  double bootValue,
303                                                  double minValue,
304                                                  double maxValue,
305                                                  GucContext context,
306                                                  int flags,
307                                                  GucRealCheckHook check_hook,
308                                                  GucRealAssignHook assign_hook,
309                                                  GucShowHook show_hook);
310
311 extern void DefineCustomStringVariable(
312                                                    const char *name,
313                                                    const char *short_desc,
314                                                    const char *long_desc,
315                                                    char **valueAddr,
316                                                    const char *bootValue,
317                                                    GucContext context,
318                                                    int flags,
319                                                    GucStringCheckHook check_hook,
320                                                    GucStringAssignHook assign_hook,
321                                                    GucShowHook show_hook);
322
323 extern void DefineCustomEnumVariable(
324                                                  const char *name,
325                                                  const char *short_desc,
326                                                  const char *long_desc,
327                                                  int *valueAddr,
328                                                  int bootValue,
329                                                  const struct config_enum_entry * options,
330                                                  GucContext context,
331                                                  int flags,
332                                                  GucEnumCheckHook check_hook,
333                                                  GucEnumAssignHook assign_hook,
334                                                  GucShowHook show_hook);
335
336 extern void EmitWarningsOnPlaceholders(const char *className);
337
338 extern const char *GetConfigOption(const char *name, bool missing_ok,
339                                 bool restrict_superuser);
340 extern const char *GetConfigOptionResetString(const char *name);
341 extern void ProcessConfigFile(GucContext context);
342 extern void InitializeGUCOptions(void);
343 extern bool SelectConfigFiles(const char *userDoption, const char *progname);
344 extern void ResetAllOptions(void);
345 extern void AtStart_GUC(void);
346 extern int      NewGUCNestLevel(void);
347 extern void AtEOXact_GUC(bool isCommit, int nestLevel);
348 extern void BeginReportingGUCOptions(void);
349 extern void ParseLongOption(const char *string, char **name, char **value);
350 extern bool parse_int(const char *value, int *result, int flags,
351                   const char **hintmsg);
352 extern bool parse_real(const char *value, double *result);
353 extern int set_config_option(const char *name, const char *value,
354                                   GucContext context, GucSource source,
355                                   GucAction action, bool changeVal, int elevel,
356                                   bool is_reload);
357 extern void AlterSystemSetConfigFile(AlterSystemStmt *setstmt);
358 extern char *GetConfigOptionByName(const char *name, const char **varname);
359 extern void GetConfigOptionByNum(int varnum, const char **values, bool *noshow);
360 extern int      GetNumConfigOptions(void);
361
362 extern void SetPGVariable(const char *name, List *args, bool is_local);
363 extern void GetPGVariable(const char *name, DestReceiver *dest);
364 extern TupleDesc GetPGVariableResultDesc(const char *name);
365
366 extern void ExecSetVariableStmt(VariableSetStmt *stmt, bool isTopLevel);
367 extern char *ExtractSetVariableArgs(VariableSetStmt *stmt);
368
369 extern void ProcessGUCArray(ArrayType *array,
370                                 GucContext context, GucSource source, GucAction action);
371 extern ArrayType *GUCArrayAdd(ArrayType *array, const char *name, const char *value);
372 extern ArrayType *GUCArrayDelete(ArrayType *array, const char *name);
373 extern ArrayType *GUCArrayReset(ArrayType *array);
374
375 #ifdef EXEC_BACKEND
376 extern void write_nondefault_variables(GucContext context);
377 extern void read_nondefault_variables(void);
378 #endif
379
380 /* GUC serialization */
381 extern Size EstimateGUCStateSpace(void);
382 extern void SerializeGUCState(Size maxsize, char *start_address);
383 extern void RestoreGUCState(void *gucstate);
384
385 /* Support for messages reported from GUC check hooks */
386
387 extern PGDLLIMPORT char *GUC_check_errmsg_string;
388 extern PGDLLIMPORT char *GUC_check_errdetail_string;
389 extern PGDLLIMPORT char *GUC_check_errhint_string;
390
391 extern void GUC_check_errcode(int sqlerrcode);
392
393 #define GUC_check_errmsg \
394         pre_format_elog_string(errno, TEXTDOMAIN), \
395         GUC_check_errmsg_string = format_elog_string
396
397 #define GUC_check_errdetail \
398         pre_format_elog_string(errno, TEXTDOMAIN), \
399         GUC_check_errdetail_string = format_elog_string
400
401 #define GUC_check_errhint \
402         pre_format_elog_string(errno, TEXTDOMAIN), \
403         GUC_check_errhint_string = format_elog_string
404
405
406 /*
407  * The following functions are not in guc.c, but are declared here to avoid
408  * having to include guc.h in some widely used headers that it really doesn't
409  * belong in.
410  */
411
412 /* in commands/tablespace.c */
413 extern bool check_default_tablespace(char **newval, void **extra, GucSource source);
414 extern bool check_temp_tablespaces(char **newval, void **extra, GucSource source);
415 extern void assign_temp_tablespaces(const char *newval, void *extra);
416
417 /* in catalog/namespace.c */
418 extern bool check_search_path(char **newval, void **extra, GucSource source);
419 extern void assign_search_path(const char *newval, void *extra);
420
421 /* in access/transam/xlog.c */
422 extern bool check_wal_buffers(int *newval, void **extra, GucSource source);
423 extern void assign_xlog_sync_method(int new_sync_method, void *extra);
424
425 #endif   /* GUC_H */