Header And Logo

PostgreSQL
| The world's most advanced open source database.

guc.h

Go to the documentation of this file.
00001 /*--------------------------------------------------------------------
00002  * guc.h
00003  *
00004  * External declarations pertaining to backend/utils/misc/guc.c and
00005  * backend/utils/misc/guc-file.l
00006  *
00007  * Copyright (c) 2000-2013, PostgreSQL Global Development Group
00008  * Written by Peter Eisentraut <[email protected]>.
00009  *
00010  * src/include/utils/guc.h
00011  *--------------------------------------------------------------------
00012  */
00013 #ifndef GUC_H
00014 #define GUC_H
00015 
00016 #include "nodes/parsenodes.h"
00017 #include "tcop/dest.h"
00018 #include "utils/array.h"
00019 
00020 
00021 /*
00022  * Certain options can only be set at certain times. The rules are
00023  * like this:
00024  *
00025  * INTERNAL options cannot be set by the user at all, but only through
00026  * internal processes ("server_version" is an example).  These are GUC
00027  * variables only so they can be shown by SHOW, etc.
00028  *
00029  * POSTMASTER options can only be set when the postmaster starts,
00030  * either from the configuration file or the command line.
00031  *
00032  * SIGHUP options can only be set at postmaster startup or by changing
00033  * the configuration file and sending the HUP signal to the postmaster
00034  * or a backend process. (Notice that the signal receipt will not be
00035  * evaluated immediately. The postmaster and the backend check it at a
00036  * certain point in their main loop. It's safer to wait than to read a
00037  * file asynchronously.)
00038  *
00039  * BACKEND options can only be set at postmaster startup, from the
00040  * configuration file, or by client request in the connection startup
00041  * packet (e.g., from libpq's PGOPTIONS variable).  Furthermore, an
00042  * already-started backend will ignore changes to such an option in the
00043  * configuration file.  The idea is that these options are fixed for a
00044  * given backend once it's started, but they can vary across backends.
00045  *
00046  * SUSET options can be set at postmaster startup, with the SIGHUP
00047  * mechanism, or from SQL if you're a superuser.
00048  *
00049  * USERSET options can be set by anyone any time.
00050  */
00051 typedef enum
00052 {
00053     PGC_INTERNAL,
00054     PGC_POSTMASTER,
00055     PGC_SIGHUP,
00056     PGC_BACKEND,
00057     PGC_SUSET,
00058     PGC_USERSET
00059 } GucContext;
00060 
00061 /*
00062  * The following type records the source of the current setting.  A
00063  * new setting can only take effect if the previous setting had the
00064  * same or lower level.  (E.g, changing the config file doesn't
00065  * override the postmaster command line.)  Tracking the source allows us
00066  * to process sources in any convenient order without affecting results.
00067  * Sources <= PGC_S_OVERRIDE will set the default used by RESET, as well
00068  * as the current value.  Note that source == PGC_S_OVERRIDE should be
00069  * used when setting a PGC_INTERNAL option.
00070  *
00071  * PGC_S_INTERACTIVE isn't actually a source value, but is the
00072  * dividing line between "interactive" and "non-interactive" sources for
00073  * error reporting purposes.
00074  *
00075  * PGC_S_TEST is used when testing values to be stored as per-database or
00076  * per-user defaults ("doit" will always be false, so this never gets stored
00077  * as the actual source of any value).  This is an interactive case, but
00078  * it needs its own source value because some assign hooks need to make
00079  * different validity checks in this case.
00080  *
00081  * NB: see GucSource_Names in guc.c if you change this.
00082  */
00083 typedef enum
00084 {
00085     PGC_S_DEFAULT,              /* hard-wired default ("boot_val") */
00086     PGC_S_DYNAMIC_DEFAULT,      /* default computed during initialization */
00087     PGC_S_ENV_VAR,              /* postmaster environment variable */
00088     PGC_S_FILE,                 /* postgresql.conf */
00089     PGC_S_ARGV,                 /* postmaster command line */
00090     PGC_S_GLOBAL,               /* global in-database setting */
00091     PGC_S_DATABASE,             /* per-database setting */
00092     PGC_S_USER,                 /* per-user setting */
00093     PGC_S_DATABASE_USER,        /* per-user-and-database setting */
00094     PGC_S_CLIENT,               /* from client connection request */
00095     PGC_S_OVERRIDE,             /* special case to forcibly set default */
00096     PGC_S_INTERACTIVE,          /* dividing line for error reporting */
00097     PGC_S_TEST,                 /* test per-database or per-user setting */
00098     PGC_S_SESSION               /* SET command */
00099 } GucSource;
00100 
00101 /*
00102  * Parsing the configuration file will return a list of name-value pairs
00103  * with source location info.
00104  */
00105 typedef struct ConfigVariable
00106 {
00107     char       *name;
00108     char       *value;
00109     char       *filename;
00110     int         sourceline;
00111     struct ConfigVariable *next;
00112 } ConfigVariable;
00113 
00114 extern bool ParseConfigFile(const char *config_file, const char *calling_file,
00115                 bool strict, int depth, int elevel,
00116                 ConfigVariable **head_p, ConfigVariable **tail_p);
00117 extern bool ParseConfigFp(FILE *fp, const char *config_file,
00118               int depth, int elevel,
00119               ConfigVariable **head_p, ConfigVariable **tail_p);
00120 extern bool ParseConfigDirectory(const char *includedir,
00121                      const char *calling_file,
00122                      int depth, int elevel,
00123                      ConfigVariable **head_p,
00124                      ConfigVariable **tail_p);
00125 extern void FreeConfigVariables(ConfigVariable *list);
00126 
00127 /*
00128  * The possible values of an enum variable are specified by an array of
00129  * name-value pairs.  The "hidden" flag means the value is accepted but
00130  * won't be displayed when guc.c is asked for a list of acceptable values.
00131  */
00132 struct config_enum_entry
00133 {
00134     const char *name;
00135     int         val;
00136     bool        hidden;
00137 };
00138 
00139 /*
00140  * Signatures for per-variable check/assign/show hook functions
00141  */
00142 typedef bool (*GucBoolCheckHook) (bool *newval, void **extra, GucSource source);
00143 typedef bool (*GucIntCheckHook) (int *newval, void **extra, GucSource source);
00144 typedef bool (*GucRealCheckHook) (double *newval, void **extra, GucSource source);
00145 typedef bool (*GucStringCheckHook) (char **newval, void **extra, GucSource source);
00146 typedef bool (*GucEnumCheckHook) (int *newval, void **extra, GucSource source);
00147 
00148 typedef void (*GucBoolAssignHook) (bool newval, void *extra);
00149 typedef void (*GucIntAssignHook) (int newval, void *extra);
00150 typedef void (*GucRealAssignHook) (double newval, void *extra);
00151 typedef void (*GucStringAssignHook) (const char *newval, void *extra);
00152 typedef void (*GucEnumAssignHook) (int newval, void *extra);
00153 
00154 typedef const char *(*GucShowHook) (void);
00155 
00156 /*
00157  * Miscellaneous
00158  */
00159 typedef enum
00160 {
00161     /* Types of set_config_option actions */
00162     GUC_ACTION_SET,             /* regular SET command */
00163     GUC_ACTION_LOCAL,           /* SET LOCAL command */
00164     GUC_ACTION_SAVE             /* function SET option, or temp assignment */
00165 } GucAction;
00166 
00167 #define GUC_QUALIFIER_SEPARATOR '.'
00168 
00169 /*
00170  * bit values in "flags" of a GUC variable
00171  */
00172 #define GUC_LIST_INPUT          0x0001  /* input can be list format */
00173 #define GUC_LIST_QUOTE          0x0002  /* double-quote list elements */
00174 #define GUC_NO_SHOW_ALL         0x0004  /* exclude from SHOW ALL */
00175 #define GUC_NO_RESET_ALL        0x0008  /* exclude from RESET ALL */
00176 #define GUC_REPORT              0x0010  /* auto-report changes to client */
00177 #define GUC_NOT_IN_SAMPLE       0x0020  /* not in postgresql.conf.sample */
00178 #define GUC_DISALLOW_IN_FILE    0x0040  /* can't set in postgresql.conf */
00179 #define GUC_CUSTOM_PLACEHOLDER  0x0080  /* placeholder for custom variable */
00180 #define GUC_SUPERUSER_ONLY      0x0100  /* show only to superusers */
00181 #define GUC_IS_NAME             0x0200  /* limit string to NAMEDATALEN-1 */
00182 
00183 #define GUC_UNIT_KB             0x0400  /* value is in kilobytes */
00184 #define GUC_UNIT_BLOCKS         0x0800  /* value is in blocks */
00185 #define GUC_UNIT_XBLOCKS        0x0C00  /* value is in xlog blocks */
00186 #define GUC_UNIT_MEMORY         0x0C00  /* mask for KB, BLOCKS, XBLOCKS */
00187 
00188 #define GUC_UNIT_MS             0x1000  /* value is in milliseconds */
00189 #define GUC_UNIT_S              0x2000  /* value is in seconds */
00190 #define GUC_UNIT_MIN            0x4000  /* value is in minutes */
00191 #define GUC_UNIT_TIME           0x7000  /* mask for MS, S, MIN */
00192 
00193 #define GUC_NOT_WHILE_SEC_REST  0x8000  /* can't set if security restricted */
00194 
00195 /* GUC vars that are actually declared in guc.c, rather than elsewhere */
00196 extern bool log_duration;
00197 extern bool Debug_print_plan;
00198 extern bool Debug_print_parse;
00199 extern bool Debug_print_rewritten;
00200 extern bool Debug_pretty_print;
00201 
00202 extern bool log_parser_stats;
00203 extern bool log_planner_stats;
00204 extern bool log_executor_stats;
00205 extern bool log_statement_stats;
00206 extern bool log_btree_build_stats;
00207 
00208 extern PGDLLIMPORT bool check_function_bodies;
00209 extern bool default_with_oids;
00210 extern bool SQL_inheritance;
00211 
00212 extern int  log_min_error_statement;
00213 extern int  log_min_messages;
00214 extern int  client_min_messages;
00215 extern int  log_min_duration_statement;
00216 extern int  log_temp_files;
00217 
00218 extern int  temp_file_limit;
00219 
00220 extern int  num_temp_buffers;
00221 
00222 extern char *data_directory;
00223 extern char *ConfigFileName;
00224 extern char *HbaFileName;
00225 extern char *IdentFileName;
00226 extern char *external_pid_file;
00227 
00228 extern char *application_name;
00229 
00230 extern int  tcp_keepalives_idle;
00231 extern int  tcp_keepalives_interval;
00232 extern int  tcp_keepalives_count;
00233 
00234 /*
00235  * Functions exported by guc.c
00236  */
00237 extern void SetConfigOption(const char *name, const char *value,
00238                 GucContext context, GucSource source);
00239 
00240 extern void DefineCustomBoolVariable(
00241                          const char *name,
00242                          const char *short_desc,
00243                          const char *long_desc,
00244                          bool *valueAddr,
00245                          bool bootValue,
00246                          GucContext context,
00247                          int flags,
00248                          GucBoolCheckHook check_hook,
00249                          GucBoolAssignHook assign_hook,
00250                          GucShowHook show_hook);
00251 
00252 extern void DefineCustomIntVariable(
00253                         const char *name,
00254                         const char *short_desc,
00255                         const char *long_desc,
00256                         int *valueAddr,
00257                         int bootValue,
00258                         int minValue,
00259                         int maxValue,
00260                         GucContext context,
00261                         int flags,
00262                         GucIntCheckHook check_hook,
00263                         GucIntAssignHook assign_hook,
00264                         GucShowHook show_hook);
00265 
00266 extern void DefineCustomRealVariable(
00267                          const char *name,
00268                          const char *short_desc,
00269                          const char *long_desc,
00270                          double *valueAddr,
00271                          double bootValue,
00272                          double minValue,
00273                          double maxValue,
00274                          GucContext context,
00275                          int flags,
00276                          GucRealCheckHook check_hook,
00277                          GucRealAssignHook assign_hook,
00278                          GucShowHook show_hook);
00279 
00280 extern void DefineCustomStringVariable(
00281                            const char *name,
00282                            const char *short_desc,
00283                            const char *long_desc,
00284                            char **valueAddr,
00285                            const char *bootValue,
00286                            GucContext context,
00287                            int flags,
00288                            GucStringCheckHook check_hook,
00289                            GucStringAssignHook assign_hook,
00290                            GucShowHook show_hook);
00291 
00292 extern void DefineCustomEnumVariable(
00293                          const char *name,
00294                          const char *short_desc,
00295                          const char *long_desc,
00296                          int *valueAddr,
00297                          int bootValue,
00298                          const struct config_enum_entry * options,
00299                          GucContext context,
00300                          int flags,
00301                          GucEnumCheckHook check_hook,
00302                          GucEnumAssignHook assign_hook,
00303                          GucShowHook show_hook);
00304 
00305 extern void EmitWarningsOnPlaceholders(const char *className);
00306 
00307 extern const char *GetConfigOption(const char *name, bool missing_ok,
00308                 bool restrict_superuser);
00309 extern const char *GetConfigOptionResetString(const char *name);
00310 extern void ProcessConfigFile(GucContext context);
00311 extern void InitializeGUCOptions(void);
00312 extern bool SelectConfigFiles(const char *userDoption, const char *progname);
00313 extern void ResetAllOptions(void);
00314 extern void AtStart_GUC(void);
00315 extern int  NewGUCNestLevel(void);
00316 extern void AtEOXact_GUC(bool isCommit, int nestLevel);
00317 extern void BeginReportingGUCOptions(void);
00318 extern void ParseLongOption(const char *string, char **name, char **value);
00319 extern bool parse_int(const char *value, int *result, int flags,
00320           const char **hintmsg);
00321 extern bool parse_real(const char *value, double *result);
00322 extern int set_config_option(const char *name, const char *value,
00323                   GucContext context, GucSource source,
00324                   GucAction action, bool changeVal, int elevel);
00325 extern char *GetConfigOptionByName(const char *name, const char **varname);
00326 extern void GetConfigOptionByNum(int varnum, const char **values, bool *noshow);
00327 extern int  GetNumConfigOptions(void);
00328 
00329 extern void SetPGVariable(const char *name, List *args, bool is_local);
00330 extern void GetPGVariable(const char *name, DestReceiver *dest);
00331 extern TupleDesc GetPGVariableResultDesc(const char *name);
00332 
00333 extern void ExecSetVariableStmt(VariableSetStmt *stmt);
00334 extern char *ExtractSetVariableArgs(VariableSetStmt *stmt);
00335 
00336 extern void ProcessGUCArray(ArrayType *array,
00337                 GucContext context, GucSource source, GucAction action);
00338 extern ArrayType *GUCArrayAdd(ArrayType *array, const char *name, const char *value);
00339 extern ArrayType *GUCArrayDelete(ArrayType *array, const char *name);
00340 extern ArrayType *GUCArrayReset(ArrayType *array);
00341 
00342 #ifdef EXEC_BACKEND
00343 extern void write_nondefault_variables(GucContext context);
00344 extern void read_nondefault_variables(void);
00345 #endif
00346 
00347 /* Support for messages reported from GUC check hooks */
00348 
00349 extern PGDLLIMPORT char *GUC_check_errmsg_string;
00350 extern PGDLLIMPORT char *GUC_check_errdetail_string;
00351 extern PGDLLIMPORT char *GUC_check_errhint_string;
00352 
00353 extern void GUC_check_errcode(int sqlerrcode);
00354 
00355 #define GUC_check_errmsg \
00356     pre_format_elog_string(errno, TEXTDOMAIN), \
00357     GUC_check_errmsg_string = format_elog_string
00358 
00359 #define GUC_check_errdetail \
00360     pre_format_elog_string(errno, TEXTDOMAIN), \
00361     GUC_check_errdetail_string = format_elog_string
00362 
00363 #define GUC_check_errhint \
00364     pre_format_elog_string(errno, TEXTDOMAIN), \
00365     GUC_check_errhint_string = format_elog_string
00366 
00367 
00368 /*
00369  * The following functions are not in guc.c, but are declared here to avoid
00370  * having to include guc.h in some widely used headers that it really doesn't
00371  * belong in.
00372  */
00373 
00374 /* in commands/tablespace.c */
00375 extern bool check_default_tablespace(char **newval, void **extra, GucSource source);
00376 extern bool check_temp_tablespaces(char **newval, void **extra, GucSource source);
00377 extern void assign_temp_tablespaces(const char *newval, void *extra);
00378 
00379 /* in catalog/namespace.c */
00380 extern bool check_search_path(char **newval, void **extra, GucSource source);
00381 extern void assign_search_path(const char *newval, void *extra);
00382 
00383 /* in access/transam/xlog.c */
00384 extern bool check_wal_buffers(int *newval, void **extra, GucSource source);
00385 extern void assign_xlog_sync_method(int new_sync_method, void *extra);
00386 
00387 #endif   /* GUC_H */