guc.h 14.1 KB
Newer Older
1
/*--------------------------------------------------------------------
2 3 4 5 6
 * guc.h
 *
 * External declarations pertaining to backend/utils/misc/guc.c and
 * backend/utils/misc/guc-file.l
 *
B
Bruce Momjian 已提交
7
 * Copyright (c) 2000-2014, PostgreSQL Global Development Group
8 9
 * Written by Peter Eisentraut <peter_e@gmx.net>.
 *
10
 * src/include/utils/guc.h
11
 *--------------------------------------------------------------------
12 13 14 15
 */
#ifndef GUC_H
#define GUC_H

16
#include "nodes/parsenodes.h"
17
#include "tcop/dest.h"
18 19
#include "utils/array.h"

20

21 22 23 24 25 26 27
/*
 * Automatic configuration file name for ALTER SYSTEM.
 * This file will be used to store values of configuration parameters
 * set by ALTER SYSTEM command.
 */
#define PG_AUTOCONF_FILENAME		"postgresql.auto.conf"

28
/*
29 30 31
 * Certain options can only be set at certain times. The rules are
 * like this:
 *
32 33 34 35
 * INTERNAL options cannot be set by the user at all, but only through
 * internal processes ("server_version" is an example).  These are GUC
 * variables only so they can be shown by SHOW, etc.
 *
36 37 38 39 40
 * POSTMASTER options can only be set when the postmaster starts,
 * either from the configuration file or the command line.
 *
 * SIGHUP options can only be set at postmaster startup or by changing
 * the configuration file and sending the HUP signal to the postmaster
41 42 43 44
 * or a backend process. (Notice that the signal receipt will not be
 * evaluated immediately. The postmaster and the backend check it at a
 * certain point in their main loop. It's safer to wait than to read a
 * file asynchronously.)
45
 *
46
 * BACKEND options can only be set at postmaster startup, from the
47 48 49
 * configuration file, or by client request in the connection startup
 * packet (e.g., from libpq's PGOPTIONS variable).  Furthermore, an
 * already-started backend will ignore changes to such an option in the
B
Bruce Momjian 已提交
50
 * configuration file.  The idea is that these options are fixed for a
51
 * given backend once it's started, but they can vary across backends.
52 53
 *
 * SUSET options can be set at postmaster startup, with the SIGHUP
54
 * mechanism, or from SQL if you're a superuser.
55 56
 *
 * USERSET options can be set by anyone any time.
57
 */
B
Bruce Momjian 已提交
58 59
typedef enum
{
60 61 62 63 64 65
	PGC_INTERNAL,
	PGC_POSTMASTER,
	PGC_SIGHUP,
	PGC_BACKEND,
	PGC_SUSET,
	PGC_USERSET
66 67
} GucContext;

68 69 70 71
/*
 * The following type records the source of the current setting.  A
 * new setting can only take effect if the previous setting had the
 * same or lower level.  (E.g, changing the config file doesn't
72 73 74
 * override the postmaster command line.)  Tracking the source allows us
 * to process sources in any convenient order without affecting results.
 * Sources <= PGC_S_OVERRIDE will set the default used by RESET, as well
75 76
 * as the current value.  Note that source == PGC_S_OVERRIDE should be
 * used when setting a PGC_INTERNAL option.
77
 *
78
 * PGC_S_INTERACTIVE isn't actually a source value, but is the
79 80 81
 * dividing line between "interactive" and "non-interactive" sources for
 * error reporting purposes.
 *
82 83 84 85 86 87 88 89 90
 * PGC_S_TEST is used when testing values to be used later ("doit" will always
 * be false, so this never gets stored as the actual source of any value).
 * For example, ALTER DATABASE/ROLE tests proposed per-database or per-user
 * defaults this way, and CREATE FUNCTION tests proposed function SET clauses
 * this way.  This is an interactive case, but it needs its own source value
 * because some assign hooks need to make different validity checks in this
 * case.  In particular, references to nonexistent database objects generally
 * shouldn't throw hard errors in this case, at most NOTICEs, since the
 * objects might exist by the time the setting is used for real.
91 92
 *
 * NB: see GucSource_Names in guc.c if you change this.
93 94 95
 */
typedef enum
{
96 97
	PGC_S_DEFAULT,				/* hard-wired default ("boot_val") */
	PGC_S_DYNAMIC_DEFAULT,		/* default computed during initialization */
98 99 100
	PGC_S_ENV_VAR,				/* postmaster environment variable */
	PGC_S_FILE,					/* postgresql.conf */
	PGC_S_ARGV,					/* postmaster command line */
101
	PGC_S_GLOBAL,				/* global in-database setting */
102 103
	PGC_S_DATABASE,				/* per-database setting */
	PGC_S_USER,					/* per-user setting */
104
	PGC_S_DATABASE_USER,		/* per-user-and-database setting */
105 106
	PGC_S_CLIENT,				/* from client connection request */
	PGC_S_OVERRIDE,				/* special case to forcibly set default */
107 108
	PGC_S_INTERACTIVE,			/* dividing line for error reporting */
	PGC_S_TEST,					/* test per-database or per-user setting */
109
	PGC_S_SESSION				/* SET command */
110
} GucSource;
111

112
/*
113 114
 * Parsing the configuration file will return a list of name-value pairs
 * with source location info.
115 116 117
 */
typedef struct ConfigVariable
{
118 119
	char	   *name;
	char	   *value;
120 121
	char	   *filename;
	int			sourceline;
122
	struct ConfigVariable *next;
123 124 125
} ConfigVariable;

extern bool ParseConfigFile(const char *config_file, const char *calling_file,
126
				bool strict, int depth, int elevel,
127 128 129 130
				ConfigVariable **head_p, ConfigVariable **tail_p);
extern bool ParseConfigFp(FILE *fp, const char *config_file,
			  int depth, int elevel,
			  ConfigVariable **head_p, ConfigVariable **tail_p);
131 132 133 134 135
extern bool ParseConfigDirectory(const char *includedir,
					 const char *calling_file,
					 int depth, int elevel,
					 ConfigVariable **head_p,
					 ConfigVariable **tail_p);
136 137
extern void FreeConfigVariables(ConfigVariable *list);

138
/*
139 140 141
 * The possible values of an enum variable are specified by an array of
 * name-value pairs.  The "hidden" flag means the value is accepted but
 * won't be displayed when guc.c is asked for a list of acceptable values.
142 143 144 145
 */
struct config_enum_entry
{
	const char *name;
146
	int			val;
147
	bool		hidden;
148 149
};

150 151 152 153 154 155 156 157 158 159 160 161 162 163
/*
 * Signatures for per-variable check/assign/show hook functions
 */
typedef bool (*GucBoolCheckHook) (bool *newval, void **extra, GucSource source);
typedef bool (*GucIntCheckHook) (int *newval, void **extra, GucSource source);
typedef bool (*GucRealCheckHook) (double *newval, void **extra, GucSource source);
typedef bool (*GucStringCheckHook) (char **newval, void **extra, GucSource source);
typedef bool (*GucEnumCheckHook) (int *newval, void **extra, GucSource source);

typedef void (*GucBoolAssignHook) (bool newval, void *extra);
typedef void (*GucIntAssignHook) (int newval, void *extra);
typedef void (*GucRealAssignHook) (double newval, void *extra);
typedef void (*GucStringAssignHook) (const char *newval, void *extra);
typedef void (*GucEnumAssignHook) (int newval, void *extra);
164

B
Bruce Momjian 已提交
165
typedef const char *(*GucShowHook) (void);
166

167 168 169
/*
 * Miscellaneous
 */
170 171 172 173 174
typedef enum
{
	/* Types of set_config_option actions */
	GUC_ACTION_SET,				/* regular SET command */
	GUC_ACTION_LOCAL,			/* SET LOCAL command */
175
	GUC_ACTION_SAVE				/* function SET option, or temp assignment */
176
} GucAction;
177

178 179
#define GUC_QUALIFIER_SEPARATOR '.'

180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
/*
 * bit values in "flags" of a GUC variable
 */
#define GUC_LIST_INPUT			0x0001	/* input can be list format */
#define GUC_LIST_QUOTE			0x0002	/* double-quote list elements */
#define GUC_NO_SHOW_ALL			0x0004	/* exclude from SHOW ALL */
#define GUC_NO_RESET_ALL		0x0008	/* exclude from RESET ALL */
#define GUC_REPORT				0x0010	/* auto-report changes to client */
#define GUC_NOT_IN_SAMPLE		0x0020	/* not in postgresql.conf.sample */
#define GUC_DISALLOW_IN_FILE	0x0040	/* can't set in postgresql.conf */
#define GUC_CUSTOM_PLACEHOLDER	0x0080	/* placeholder for custom variable */
#define GUC_SUPERUSER_ONLY		0x0100	/* show only to superusers */
#define GUC_IS_NAME				0x0200	/* limit string to NAMEDATALEN-1 */

#define GUC_UNIT_KB				0x0400	/* value is in kilobytes */
#define GUC_UNIT_BLOCKS			0x0800	/* value is in blocks */
#define GUC_UNIT_XBLOCKS		0x0C00	/* value is in xlog blocks */
#define GUC_UNIT_MEMORY			0x0C00	/* mask for KB, BLOCKS, XBLOCKS */

#define GUC_UNIT_MS				0x1000	/* value is in milliseconds */
#define GUC_UNIT_S				0x2000	/* value is in seconds */
#define GUC_UNIT_MIN			0x4000	/* value is in minutes */
#define GUC_UNIT_TIME			0x7000	/* mask for MS, S, MIN */

204
#define GUC_NOT_WHILE_SEC_REST	0x8000	/* can't set if security restricted */
205
#define GUC_DISALLOW_IN_AUTO_FILE	0x00010000	/* can't set in PG_AUTOCONF_FILENAME */
206

207 208 209 210 211 212 213 214 215 216 217 218 219
/* GUC vars that are actually declared in guc.c, rather than elsewhere */
extern bool log_duration;
extern bool Debug_print_plan;
extern bool Debug_print_parse;
extern bool Debug_print_rewritten;
extern bool Debug_pretty_print;

extern bool log_parser_stats;
extern bool log_planner_stats;
extern bool log_executor_stats;
extern bool log_statement_stats;
extern bool log_btree_build_stats;

220
extern PGDLLIMPORT bool check_function_bodies;
221
extern bool default_with_oids;
222
extern bool SQL_inheritance;
223

224 225 226
extern int	log_min_error_statement;
extern int	log_min_messages;
extern int	client_min_messages;
227
extern int	log_min_duration_statement;
228
extern int	log_temp_files;
229

230 231
extern int	temp_file_limit;

232 233
extern int	num_temp_buffers;

234
extern char *data_directory;
235
extern char *ConfigFileName;
236 237 238
extern char *HbaFileName;
extern char *IdentFileName;
extern char *external_pid_file;
239

240 241
extern char *application_name;

B
Bruce Momjian 已提交
242 243 244
extern int	tcp_keepalives_idle;
extern int	tcp_keepalives_interval;
extern int	tcp_keepalives_count;
245

246 247 248
/*
 * Functions exported by guc.c
 */
249
extern void SetConfigOption(const char *name, const char *value,
250
				GucContext context, GucSource source);
251 252

extern void DefineCustomBoolVariable(
B
Bruce Momjian 已提交
253 254 255 256
						 const char *name,
						 const char *short_desc,
						 const char *long_desc,
						 bool *valueAddr,
257
						 bool bootValue,
B
Bruce Momjian 已提交
258
						 GucContext context,
259
						 int flags,
260
						 GucBoolCheckHook check_hook,
B
Bruce Momjian 已提交
261 262
						 GucBoolAssignHook assign_hook,
						 GucShowHook show_hook);
263 264

extern void DefineCustomIntVariable(
B
Bruce Momjian 已提交
265 266 267 268
						const char *name,
						const char *short_desc,
						const char *long_desc,
						int *valueAddr,
269
						int bootValue,
270 271
						int minValue,
						int maxValue,
B
Bruce Momjian 已提交
272
						GucContext context,
273
						int flags,
274
						GucIntCheckHook check_hook,
B
Bruce Momjian 已提交
275 276
						GucIntAssignHook assign_hook,
						GucShowHook show_hook);
277 278

extern void DefineCustomRealVariable(
B
Bruce Momjian 已提交
279 280 281 282
						 const char *name,
						 const char *short_desc,
						 const char *long_desc,
						 double *valueAddr,
283
						 double bootValue,
284 285
						 double minValue,
						 double maxValue,
B
Bruce Momjian 已提交
286
						 GucContext context,
287
						 int flags,
288
						 GucRealCheckHook check_hook,
B
Bruce Momjian 已提交
289 290
						 GucRealAssignHook assign_hook,
						 GucShowHook show_hook);
291 292

extern void DefineCustomStringVariable(
B
Bruce Momjian 已提交
293 294 295 296
						   const char *name,
						   const char *short_desc,
						   const char *long_desc,
						   char **valueAddr,
297
						   const char *bootValue,
B
Bruce Momjian 已提交
298
						   GucContext context,
299
						   int flags,
300
						   GucStringCheckHook check_hook,
B
Bruce Momjian 已提交
301 302
						   GucStringAssignHook assign_hook,
						   GucShowHook show_hook);
303

304
extern void DefineCustomEnumVariable(
305 306 307 308 309 310 311 312
						 const char *name,
						 const char *short_desc,
						 const char *long_desc,
						 int *valueAddr,
						 int bootValue,
						 const struct config_enum_entry * options,
						 GucContext context,
						 int flags,
313
						 GucEnumCheckHook check_hook,
314 315
						 GucEnumAssignHook assign_hook,
						 GucShowHook show_hook);
316

B
Bruce Momjian 已提交
317
extern void EmitWarningsOnPlaceholders(const char *className);
318

319 320
extern const char *GetConfigOption(const char *name, bool missing_ok,
				bool restrict_superuser);
321
extern const char *GetConfigOptionResetString(const char *name);
322
extern void ProcessConfigFile(GucContext context);
323
extern void InitializeGUCOptions(void);
324
extern bool SelectConfigFiles(const char *userDoption, const char *progname);
325
extern void ResetAllOptions(void);
326 327 328
extern void AtStart_GUC(void);
extern int	NewGUCNestLevel(void);
extern void AtEOXact_GUC(bool isCommit, int nestLevel);
329
extern void BeginReportingGUCOptions(void);
330
extern void ParseLongOption(const char *string, char **name, char **value);
331
extern bool parse_int(const char *value, int *result, int flags,
332
		  const char **hintmsg);
333
extern bool parse_real(const char *value, double *result);
334
extern int set_config_option(const char *name, const char *value,
B
Bruce Momjian 已提交
335
				  GucContext context, GucSource source,
336
				  GucAction action, bool changeVal, int elevel);
B
Bruce Momjian 已提交
337
extern void AlterSystemSetConfigFile(AlterSystemStmt *setstmt);
338
extern char *GetConfigOptionByName(const char *name, const char **varname);
339
extern void GetConfigOptionByNum(int varnum, const char **values, bool *noshow);
B
Bruce Momjian 已提交
340
extern int	GetNumConfigOptions(void);
341

342
extern void SetPGVariable(const char *name, List *args, bool is_local);
343 344
extern void GetPGVariable(const char *name, DestReceiver *dest);
extern TupleDesc GetPGVariableResultDesc(const char *name);
345

346
extern void ExecSetVariableStmt(VariableSetStmt *stmt, bool isTopLevel);
347
extern char *ExtractSetVariableArgs(VariableSetStmt *stmt);
348

349
extern void ProcessGUCArray(ArrayType *array,
350
				GucContext context, GucSource source, GucAction action);
351 352
extern ArrayType *GUCArrayAdd(ArrayType *array, const char *name, const char *value);
extern ArrayType *GUCArrayDelete(ArrayType *array, const char *name);
353
extern ArrayType *GUCArrayReset(ArrayType *array);
354

B
Bruce Momjian 已提交
355
#ifdef EXEC_BACKEND
356 357
extern void write_nondefault_variables(GucContext context);
extern void read_nondefault_variables(void);
B
Bruce Momjian 已提交
358 359
#endif

360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
/* Support for messages reported from GUC check hooks */

extern PGDLLIMPORT char *GUC_check_errmsg_string;
extern PGDLLIMPORT char *GUC_check_errdetail_string;
extern PGDLLIMPORT char *GUC_check_errhint_string;

extern void GUC_check_errcode(int sqlerrcode);

#define GUC_check_errmsg \
	pre_format_elog_string(errno, TEXTDOMAIN), \
	GUC_check_errmsg_string = format_elog_string

#define GUC_check_errdetail \
	pre_format_elog_string(errno, TEXTDOMAIN), \
	GUC_check_errdetail_string = format_elog_string

#define GUC_check_errhint \
	pre_format_elog_string(errno, TEXTDOMAIN), \
	GUC_check_errhint_string = format_elog_string


381 382 383 384 385 386
/*
 * The following functions are not in guc.c, but are declared here to avoid
 * having to include guc.h in some widely used headers that it really doesn't
 * belong in.
 */

387
/* in commands/tablespace.c */
388 389 390
extern bool check_default_tablespace(char **newval, void **extra, GucSource source);
extern bool check_temp_tablespaces(char **newval, void **extra, GucSource source);
extern void assign_temp_tablespaces(const char *newval, void *extra);
391

392
/* in catalog/namespace.c */
393 394
extern bool check_search_path(char **newval, void **extra, GucSource source);
extern void assign_search_path(const char *newval, void *extra);
B
Bruce Momjian 已提交
395

396
/* in access/transam/xlog.c */
397
extern bool check_wal_buffers(int *newval, void **extra, GucSource source);
398 399
extern void assign_xlog_sync_method(int new_sync_method, void *extra);

400
#endif   /* GUC_H */