guc.c 77.2 KB
Newer Older
1 2 3 4 5
/*--------------------------------------------------------------------
 * guc.c
 *
 * Support for grand unified configuration scheme, including SET
 * command, configuration file, and command line options.
6
 * See src/backend/utils/misc/README for more information.
7 8
 *
 *
9
 * Copyright 2000-2003 by PostgreSQL Global Development Group
10
 * Written by Peter Eisentraut <peter_e@gmx.net>.
11 12
 *
 * IDENTIFICATION
13
 *	  $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.126 2003/05/27 17:55:50 momjian Exp $
14
 *
15 16 17 18 19 20 21 22 23 24 25 26
 *--------------------------------------------------------------------
 */

#include "postgres.h"

#include <errno.h>
#include <float.h>
#include <limits.h>
#include <unistd.h>

#include "utils/guc.h"

27
#include "access/xlog.h"
28
#include "catalog/namespace.h"
29
#include "catalog/pg_type.h"
30
#include "commands/async.h"
31
#include "commands/variable.h"
32
#include "commands/vacuum.h"
33
#include "executor/executor.h"
34
#include "fmgr.h"
35
#include "funcapi.h"
36
#include "libpq/auth.h"
37
#include "libpq/pqcomm.h"
38
#include "libpq/pqformat.h"
39
#include "mb/pg_wchar.h"
40 41 42 43
#include "miscadmin.h"
#include "optimizer/cost.h"
#include "optimizer/geqo.h"
#include "optimizer/paths.h"
44
#include "optimizer/prep.h"
45
#include "parser/parse_expr.h"
46
#include "storage/fd.h"
47 48
#include "storage/freespace.h"
#include "storage/lock.h"
49 50
#include "storage/proc.h"
#include "tcop/tcopprot.h"
51 52
#include "utils/array.h"
#include "utils/builtins.h"
53
#include "utils/datetime.h"
54
#include "utils/elog.h"
55
#include "utils/pg_locale.h"
56
#include "pgstat.h"
57 58


59 60 61 62
#ifndef PG_KRB_SRVTAB
#define PG_KRB_SRVTAB ""
#endif

B
Bruce Momjian 已提交
63 64 65
#ifdef EXEC_BACKEND
#define CONFIG_EXEC_PARAMS "global/config_exec_params"
#endif
66 67

/* XXX these should appear in other modules' header files */
68
extern bool Log_connections;
69 70
extern int	PreAuthDelay;
extern int	AuthenticationTimeout;
B
Bruce Momjian 已提交
71 72 73
extern int	CheckPointTimeout;
extern int	CommitDelay;
extern int	CommitSiblings;
74
extern char *preload_libraries_string;
75

T
Tatsuo Ishii 已提交
76
#ifdef HAVE_SYSLOG
77
extern char *Syslog_facility;
78
extern char *Syslog_ident;
79

80
static const char *assign_facility(const char *facility,
B
Bruce Momjian 已提交
81
				bool doit, bool interactive);
82
#endif
83

84 85 86 87 88 89 90 91
static const char *assign_defaultxactisolevel(const char *newval,
						   bool doit, bool interactive);
static const char *assign_log_min_messages(const char *newval,
						   bool doit, bool interactive);
static const char *assign_client_min_messages(const char *newval,
						   bool doit, bool interactive);
static const char *assign_min_error_statement(const char *newval, bool doit,
						   bool interactive);
92
static const char *assign_msglvl(int *var, const char *newval,
B
Bruce Momjian 已提交
93
			  bool doit, bool interactive);
94
static bool assign_phony_autocommit(bool newval, bool doit, bool interactive);
95

96

97 98 99
/*
 * Debugging options
 */
100
#ifdef USE_ASSERT_CHECKING
B
Bruce Momjian 已提交
101
bool		assert_enabled = true;
102
#endif
B
Rename:  
Bruce Momjian 已提交
103 104
bool		log_statement = false;
bool		log_duration = false;
B
Bruce Momjian 已提交
105 106 107 108
bool		Debug_print_plan = false;
bool		Debug_print_parse = false;
bool		Debug_print_rewritten = false;
bool		Debug_pretty_print = false;
109
bool		Explain_pretty_print = true;
110

B
Rename:  
Bruce Momjian 已提交
111 112 113 114
bool		log_parser_stats = false;
bool		log_planner_stats = false;
bool		log_executor_stats = false;
bool		log_statement_stats = false;		/* this is sort of all
B
Bruce Momjian 已提交
115
												 * three above together */
116
bool		log_btree_build_stats = false;
117

B
Bruce Momjian 已提交
118
bool		SQL_inheritance = true;
119

120 121
bool		Australian_timezones = false;

122
bool		Password_encryption = true;
123

124
int			log_min_error_statement = PANIC;
125
int			log_min_messages = NOTICE;
126
int			client_min_messages = NOTICE;
127 128


129 130 131 132 133
/*
 * These variables are all dummies that don't do anything, except in some
 * cases provide the value for SHOW to display.  The real state is elsewhere
 * and is kept in sync by assign_hooks.
 */
134 135 136
static char *log_min_error_statement_str;
static char *log_min_messages_str;
static char *client_min_messages_str;
137
static bool phony_autocommit;
138 139 140 141
static double phony_random_seed;
static char *client_encoding_string;
static char *datestyle_string;
static char *default_iso_level_string;
142 143
static char *locale_collate;
static char *locale_ctype;
144
static char *regex_flavor_string;
145
static char *server_encoding_string;
146
static char *server_version_string;
147 148 149 150
static char *session_authorization_string;
static char *timezone_string;
static char *XactIsoLevel_string;

151

152 153
/*
 * Declarations for GUC tables
154 155
 *
 * See src/backend/utils/misc/README for design notes.
156
 */
157 158
enum config_type
{
159 160 161 162
	PGC_BOOL,
	PGC_INT,
	PGC_REAL,
	PGC_STRING
163 164
};

165
/* Generic fields applicable to all types of variables */
166 167
struct config_generic
{
168 169 170 171 172 173 174 175
	/* 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 */
	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 */
B
Bruce Momjian 已提交
176 177
	GucSource	session_source; /* source of the session_value */
	GucSource	tentative_source;		/* source of the tentative_value */
178
	GucSource	source;			/* source of the current actual value */
179 180
};

181
/* bit values in flags field */
B
Bruce Momjian 已提交
182 183 184 185
#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 */
186
#define GUC_REPORT			0x0010		/* auto-report changes to client */
187 188

/* bit values in status field */
B
Bruce Momjian 已提交
189 190
#define GUC_HAVE_TENTATIVE	0x0001		/* tentative value is defined */
#define GUC_HAVE_LOCAL		0x0002		/* a SET LOCAL has been executed */
191 192 193


/* GUC records for specific variable types */
194 195 196

struct config_bool
{
197 198 199
	struct config_generic gen;
	/* these fields must be set correctly in initial value: */
	/* (all but reset_val are constants) */
B
Bruce Momjian 已提交
200
	bool	   *variable;
201 202 203 204 205 206
	bool		reset_val;
	bool		(*assign_hook) (bool newval, bool doit, bool interactive);
	const char *(*show_hook) (void);
	/* variable fields, initialized at runtime: */
	bool		session_val;
	bool		tentative_val;
207 208 209 210
};

struct config_int
{
211 212 213
	struct config_generic gen;
	/* these fields must be set correctly in initial value: */
	/* (all but reset_val are constants) */
B
Bruce Momjian 已提交
214
	int		   *variable;
215
	int			reset_val;
B
Bruce Momjian 已提交
216 217
	int			min;
	int			max;
218 219 220 221 222
	bool		(*assign_hook) (int newval, bool doit, bool interactive);
	const char *(*show_hook) (void);
	/* variable fields, initialized at runtime: */
	int			session_val;
	int			tentative_val;
223 224 225 226
};

struct config_real
{
227 228 229
	struct config_generic gen;
	/* these fields must be set correctly in initial value: */
	/* (all but reset_val are constants) */
B
Bruce Momjian 已提交
230
	double	   *variable;
231
	double		reset_val;
B
Bruce Momjian 已提交
232 233
	double		min;
	double		max;
234 235 236 237 238
	bool		(*assign_hook) (double newval, bool doit, bool interactive);
	const char *(*show_hook) (void);
	/* variable fields, initialized at runtime: */
	double		session_val;
	double		tentative_val;
239 240 241 242
};

struct config_string
{
243 244 245
	struct config_generic gen;
	/* these fields must be set correctly in initial value: */
	/* (all are constants) */
B
Bruce Momjian 已提交
246
	char	  **variable;
247 248 249 250 251 252 253
	const char *boot_val;
	const char *(*assign_hook) (const char *newval, bool doit, bool interactive);
	const char *(*show_hook) (void);
	/* variable fields, initialized at runtime: */
	char	   *reset_val;
	char	   *session_val;
	char	   *tentative_val;
254 255
};

256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
/* Macros for freeing malloc'd pointers only if appropriate to do so */
/* Some of these tests are probably redundant, but be safe ... */
#define SET_STRING_VARIABLE(rec, newval) \
	do { \
		if (*(rec)->variable && \
			*(rec)->variable != (rec)->reset_val && \
			*(rec)->variable != (rec)->session_val && \
			*(rec)->variable != (rec)->tentative_val) \
			free(*(rec)->variable); \
		*(rec)->variable = (newval); \
	} while (0)
#define SET_STRING_RESET_VAL(rec, newval) \
	do { \
		if ((rec)->reset_val && \
			(rec)->reset_val != *(rec)->variable && \
			(rec)->reset_val != (rec)->session_val && \
			(rec)->reset_val != (rec)->tentative_val) \
			free((rec)->reset_val); \
		(rec)->reset_val = (newval); \
	} while (0)
#define SET_STRING_SESSION_VAL(rec, newval) \
	do { \
		if ((rec)->session_val && \
			(rec)->session_val != *(rec)->variable && \
			(rec)->session_val != (rec)->reset_val && \
			(rec)->session_val != (rec)->tentative_val) \
			free((rec)->session_val); \
		(rec)->session_val = (newval); \
	} while (0)
#define SET_STRING_TENTATIVE_VAL(rec, newval) \
	do { \
		if ((rec)->tentative_val && \
			(rec)->tentative_val != *(rec)->variable && \
			(rec)->tentative_val != (rec)->reset_val && \
			(rec)->tentative_val != (rec)->session_val) \
			free((rec)->tentative_val); \
		(rec)->tentative_val = (newval); \
	} while (0)


296

297 298 299 300 301 302 303 304 305 306 307 308 309 310
/*
 * TO ADD AN OPTION:
 *
 * 1. Declare a global variable of type bool, int, double, or char*
 * and make use of it.
 *
 * 2. Decide at what times it's safe to set the option. See guc.h for
 * details.
 *
 * 3. Decide on a name, a default value, upper and lower bounds (if
 * applicable), etc.
 *
 * 4. Add a record below.
 *
311
 * 5. Add it to src/backend/utils/misc/postgresql.conf.sample.
312
 *
313
 * 6. Add it to src/bin/psql/tab-complete.c, if it's a USERSET option.
314
 *
315
 * 7. Don't forget to document the option.
316 317
 */

318

319
/******** option records follow ********/
320 321

static struct config_bool
B
Bruce Momjian 已提交
322
			ConfigureNamesBool[] =
323
{
324
	{
B
Bruce Momjian 已提交
325
		{"enable_seqscan", PGC_USERSET}, &enable_seqscan,
326
		true, NULL, NULL
327
	},
328
	{
B
Bruce Momjian 已提交
329
		{"enable_indexscan", PGC_USERSET}, &enable_indexscan,
330
		true, NULL, NULL
331 332
	},
	{
B
Bruce Momjian 已提交
333
		{"enable_tidscan", PGC_USERSET}, &enable_tidscan,
334
		true, NULL, NULL
335 336
	},
	{
B
Bruce Momjian 已提交
337
		{"enable_sort", PGC_USERSET}, &enable_sort,
338
		true, NULL, NULL
339
	},
340 341 342 343
	{
		{"enable_hashagg", PGC_USERSET}, &enable_hashagg,
		true, NULL, NULL
	},
344
	{
B
Bruce Momjian 已提交
345
		{"enable_nestloop", PGC_USERSET}, &enable_nestloop,
346
		true, NULL, NULL
347 348
	},
	{
B
Bruce Momjian 已提交
349
		{"enable_mergejoin", PGC_USERSET}, &enable_mergejoin,
350
		true, NULL, NULL
351 352
	},
	{
B
Bruce Momjian 已提交
353
		{"enable_hashjoin", PGC_USERSET}, &enable_hashjoin,
354
		true, NULL, NULL
355 356
	},
	{
B
Bruce Momjian 已提交
357
		{"geqo", PGC_USERSET}, &enable_geqo,
358
		true, NULL, NULL
359 360 361
	},

	{
B
Bruce Momjian 已提交
362
		{"tcpip_socket", PGC_POSTMASTER}, &NetServer,
363
		false, NULL, NULL
364 365
	},
	{
B
Bruce Momjian 已提交
366
		{"ssl", PGC_POSTMASTER}, &EnableSSL,
367
		false, NULL, NULL
368 369
	},
	{
B
Bruce Momjian 已提交
370
		{"fsync", PGC_SIGHUP}, &enableFsync,
371
		true, NULL, NULL
372
	},
373 374 375 376
	{
		{"zero_damaged_pages", PGC_SUSET}, &zero_damaged_pages,
		false, NULL, NULL
	},
377
	{
B
Bruce Momjian 已提交
378
		{"silent_mode", PGC_POSTMASTER}, &SilentMode,
379
		false, NULL, NULL
380 381 382
	},

	{
B
Bruce Momjian 已提交
383
		{"log_connections", PGC_BACKEND}, &Log_connections,
384
		false, NULL, NULL
385 386
	},
	{
B
Bruce Momjian 已提交
387
		{"log_timestamp", PGC_SIGHUP}, &Log_timestamp,
388
		false, NULL, NULL
389 390
	},
	{
B
Bruce Momjian 已提交
391
		{"log_pid", PGC_SIGHUP}, &Log_pid,
392
		false, NULL, NULL
393
	},
394

395
#ifdef USE_ASSERT_CHECKING
396
	{
B
Bruce Momjian 已提交
397
		{"debug_assertions", PGC_USERSET}, &assert_enabled,
398
		true, NULL, NULL
399
	},
400 401
#endif

402
	{
403
		{"log_statement", PGC_SUSET}, &log_statement,
404 405 406
		false, NULL, NULL
	},
	{
407
		{"log_duration", PGC_SUSET}, &log_duration,
408
		false, NULL, NULL
409 410
	},
	{
B
Bruce Momjian 已提交
411
		{"debug_print_parse", PGC_USERSET}, &Debug_print_parse,
412
		false, NULL, NULL
413 414
	},
	{
B
Bruce Momjian 已提交
415
		{"debug_print_rewritten", PGC_USERSET}, &Debug_print_rewritten,
416
		false, NULL, NULL
417 418
	},
	{
B
Bruce Momjian 已提交
419
		{"debug_print_plan", PGC_USERSET}, &Debug_print_plan,
420
		false, NULL, NULL
421 422
	},
	{
B
Bruce Momjian 已提交
423
		{"debug_pretty_print", PGC_USERSET}, &Debug_pretty_print,
424
		false, NULL, NULL
425
	},
426

427
	{
428
		{"log_parser_stats", PGC_SUSET}, &log_parser_stats,
429
		false, NULL, NULL
430 431
	},
	{
432
		{"log_planner_stats", PGC_SUSET}, &log_planner_stats,
433
		false, NULL, NULL
434 435
	},
	{
436
		{"log_executor_stats", PGC_SUSET}, &log_executor_stats,
437
		false, NULL, NULL
438 439
	},
	{
440
		{"log_statement_stats", PGC_SUSET}, &log_statement_stats,
441
		false, NULL, NULL
442
	},
443
#ifdef BTREE_BUILD_STATS
444
	{
445
		{"log_btree_build_stats", PGC_SUSET}, &log_btree_build_stats,
446
		false, NULL, NULL
447
	},
448 449
#endif

450
	{
B
Bruce Momjian 已提交
451
		{"explain_pretty_print", PGC_USERSET}, &Explain_pretty_print,
452
		true, NULL, NULL
453 454
	},

455
	{
B
Bruce Momjian 已提交
456
		{"stats_start_collector", PGC_POSTMASTER}, &pgstat_collect_startcollector,
457
		true, NULL, NULL
458 459
	},
	{
B
Bruce Momjian 已提交
460
		{"stats_reset_on_server_start", PGC_POSTMASTER}, &pgstat_collect_resetonpmstart,
461
		true, NULL, NULL
462 463
	},
	{
B
Bruce Momjian 已提交
464
		{"stats_command_string", PGC_SUSET}, &pgstat_collect_querystring,
465
		false, NULL, NULL
466 467
	},
	{
B
Bruce Momjian 已提交
468
		{"stats_row_level", PGC_SUSET}, &pgstat_collect_tuplelevel,
469
		false, NULL, NULL
470 471
	},
	{
B
Bruce Momjian 已提交
472
		{"stats_block_level", PGC_SUSET}, &pgstat_collect_blocklevel,
473
		false, NULL, NULL
474
	},
475

476
	{
B
Bruce Momjian 已提交
477
		{"trace_notify", PGC_USERSET}, &Trace_notify,
478
		false, NULL, NULL
479
	},
480 481

#ifdef LOCK_DEBUG
482
	{
B
Bruce Momjian 已提交
483
		{"trace_locks", PGC_SUSET}, &Trace_locks,
484
		false, NULL, NULL
485 486
	},
	{
B
Bruce Momjian 已提交
487
		{"trace_userlocks", PGC_SUSET}, &Trace_userlocks,
488
		false, NULL, NULL
489 490
	},
	{
B
Bruce Momjian 已提交
491
		{"trace_lwlocks", PGC_SUSET}, &Trace_lwlocks,
492
		false, NULL, NULL
493 494
	},
	{
B
Bruce Momjian 已提交
495
		{"debug_deadlocks", PGC_SUSET}, &Debug_deadlocks,
496
		false, NULL, NULL
497
	},
498 499
#endif

500
	{
501
		{"log_hostname", PGC_SIGHUP}, &log_hostname,
502
		false, NULL, NULL
503 504
	},
	{
505
		{"log_source_port", PGC_SIGHUP}, &LogSourcePort,
506
		false, NULL, NULL
507
	},
508

509
	{
B
Bruce Momjian 已提交
510
		{"sql_inheritance", PGC_USERSET}, &SQL_inheritance,
511
		true, NULL, NULL
512 513
	},
	{
B
Bruce Momjian 已提交
514
		{"australian_timezones", PGC_USERSET}, &Australian_timezones,
515
		false, ClearDateCache, NULL
516 517
	},
	{
B
Bruce Momjian 已提交
518
		{"password_encryption", PGC_USERSET}, &Password_encryption,
519
		true, NULL, NULL
520 521
	},
	{
B
Bruce Momjian 已提交
522
		{"transform_null_equals", PGC_USERSET}, &Transform_null_equals,
523
		false, NULL, NULL
524
	},
525
	{
B
Bruce Momjian 已提交
526
		{"db_user_namespace", PGC_SIGHUP}, &Db_user_namespace,
527 528
		false, NULL, NULL
	},
529
	{
530 531 532 533 534 535
		/*
		 * This var doesn't do anything; it's just here so that we won't
		 * choke on SET AUTOCOMMIT TO ON from 7.3-vintage clients.
		 */
		{"autocommit", PGC_USERSET, GUC_NO_SHOW_ALL}, &phony_autocommit,
		true, assign_phony_autocommit, NULL
536
	},
537 538 539 540 541 542 543 544
	{
		{"default_transaction_read_only", PGC_USERSET}, &DefaultXactReadOnly,
		false, NULL, NULL
	},
	{
		{"transaction_read_only", PGC_USERSET, GUC_NO_RESET_ALL}, &XactReadOnly,
		false, NULL, NULL
	},
545

546
	{
B
Bruce Momjian 已提交
547
		{NULL, 0}, NULL, false, NULL, NULL
548
	}
549 550 551 552
};


static struct config_int
B
Bruce Momjian 已提交
553
			ConfigureNamesInt[] =
554
{
555
	{
B
Bruce Momjian 已提交
556
		{"default_statistics_target", PGC_USERSET}, &default_statistics_target,
557 558
		10, 1, 1000, NULL, NULL
	},
559
	{
560 561 562 563 564 565 566 567 568 569
		{"from_collapse_limit", PGC_USERSET}, &from_collapse_limit,
		8, 1, INT_MAX, NULL, NULL
	},
	{
		{"join_collapse_limit", PGC_USERSET}, &join_collapse_limit,
		8, 1, INT_MAX, NULL, NULL
	},
	{
		{"geqo_threshold", PGC_USERSET}, &geqo_threshold,
		11, 2, INT_MAX, NULL, NULL
570
	},
571
	{
B
Bruce Momjian 已提交
572
		{"geqo_pool_size", PGC_USERSET}, &Geqo_pool_size,
573
		DEFAULT_GEQO_POOL_SIZE, 0, MAX_GEQO_POOL_SIZE, NULL, NULL
574 575
	},
	{
B
Bruce Momjian 已提交
576
		{"geqo_effort", PGC_USERSET}, &Geqo_effort,
577
		1, 1, INT_MAX, NULL, NULL
578 579
	},
	{
B
Bruce Momjian 已提交
580
		{"geqo_generations", PGC_USERSET}, &Geqo_generations,
581
		0, 0, INT_MAX, NULL, NULL
582 583
	},
	{
B
Bruce Momjian 已提交
584
		{"geqo_random_seed", PGC_USERSET}, &Geqo_random_seed,
585
		-1, INT_MIN, INT_MAX, NULL, NULL
586 587 588
	},

	{
589
		{"deadlock_timeout", PGC_SIGHUP}, &DeadlockTimeout,
590
		1000, 0, INT_MAX, NULL, NULL
591
	},
592

T
Tatsuo Ishii 已提交
593
#ifdef HAVE_SYSLOG
594
	{
B
Bruce Momjian 已提交
595
		{"syslog", PGC_SIGHUP}, &Use_syslog,
596
		0, 0, 2, NULL, NULL
597
	},
598 599 600
#endif

	/*
B
Bruce Momjian 已提交
601 602
	 * Note: There is some postprocessing done in PostmasterMain() to make
	 * sure the buffers are at least twice the number of backends, so the
603 604 605
	 * constraints here are partially unused. Similarly, the superuser
	 * reserved number is checked to ensure it is less than the max
	 * backends number.
606
	 */
607
	{
B
Bruce Momjian 已提交
608
		{"max_connections", PGC_POSTMASTER}, &MaxBackends,
609
		DEF_MAXBACKENDS, 1, INT_MAX, NULL, NULL
610
	},
611

612
	{
B
Bruce Momjian 已提交
613
		{"superuser_reserved_connections", PGC_POSTMASTER}, &ReservedBackends,
614 615 616
		2, 0, INT_MAX, NULL, NULL
	},

617
	{
B
Bruce Momjian 已提交
618
		{"shared_buffers", PGC_POSTMASTER}, &NBuffers,
619
		DEF_NBUFFERS, 16, INT_MAX, NULL, NULL
620
	},
621

622
	{
B
Bruce Momjian 已提交
623
		{"port", PGC_POSTMASTER}, &PostPortNumber,
624
		DEF_PGPORT, 1, 65535, NULL, NULL
625
	},
626

627
	{
B
Bruce Momjian 已提交
628
		{"unix_socket_permissions", PGC_POSTMASTER}, &Unix_socket_permissions,
629
		0777, 0000, 0777, NULL, NULL
630
	},
631

632
	{
B
Bruce Momjian 已提交
633
		{"sort_mem", PGC_USERSET}, &SortMem,
634
		1024, 8 * BLCKSZ / 1024, INT_MAX, NULL, NULL
635
	},
636

637
	{
B
Bruce Momjian 已提交
638
		{"vacuum_mem", PGC_USERSET}, &VacuumMem,
639
		8192, 1024, INT_MAX, NULL, NULL
640
	},
641

642
	{
B
Bruce Momjian 已提交
643
		{"max_files_per_process", PGC_BACKEND}, &max_files_per_process,
644
		1000, 25, INT_MAX, NULL, NULL
645
	},
646

647
#ifdef LOCK_DEBUG
648
	{
B
Bruce Momjian 已提交
649
		{"trace_lock_oidmin", PGC_SUSET}, &Trace_lock_oidmin,
650
		BootstrapObjectIdData, 1, INT_MAX, NULL, NULL
651 652
	},
	{
B
Bruce Momjian 已提交
653
		{"trace_lock_table", PGC_SUSET}, &Trace_lock_table,
654
		0, 0, INT_MAX, NULL, NULL
655
	},
656
#endif
657
	{
B
Bruce Momjian 已提交
658
		{"max_expr_depth", PGC_USERSET}, &max_expr_depth,
659
		DEFAULT_MAX_EXPR_DEPTH, 10, INT_MAX, NULL, NULL
660
	},
661

662
	{
B
Bruce Momjian 已提交
663
		{"statement_timeout", PGC_USERSET}, &StatementTimeout,
664 665 666
		0, 0, INT_MAX, NULL, NULL
	},

667
	{
B
Bruce Momjian 已提交
668
		{"max_fsm_relations", PGC_POSTMASTER}, &MaxFSMRelations,
669
		1000, 100, INT_MAX, NULL, NULL
670 671
	},
	{
B
Bruce Momjian 已提交
672
		{"max_fsm_pages", PGC_POSTMASTER}, &MaxFSMPages,
673
		20000, 1000, INT_MAX, NULL, NULL
674
	},
675

676
	{
B
Bruce Momjian 已提交
677
		{"max_locks_per_transaction", PGC_POSTMASTER}, &max_locks_per_xact,
678
		64, 10, INT_MAX, NULL, NULL
679
	},
680

681
	{
B
Bruce Momjian 已提交
682
		{"authentication_timeout", PGC_SIGHUP}, &AuthenticationTimeout,
683
		60, 1, 600, NULL, NULL
684
	},
685

686
	{
B
Bruce Momjian 已提交
687
		{"pre_auth_delay", PGC_SIGHUP}, &PreAuthDelay,
688
		0, 0, 60, NULL, NULL
689
	},
690

691
	{
B
Bruce Momjian 已提交
692
		{"checkpoint_segments", PGC_SIGHUP}, &CheckPointSegments,
693
		3, 1, INT_MAX, NULL, NULL
694
	},
T
Tom Lane 已提交
695

696
	{
B
Bruce Momjian 已提交
697
		{"checkpoint_timeout", PGC_SIGHUP}, &CheckPointTimeout,
698
		300, 30, 3600, NULL, NULL
699
	},
V
Vadim B. Mikheev 已提交
700

701 702 703 704 705
	{
		{"checkpoint_warning", PGC_SIGHUP}, &CheckPointWarning,
		30, 0, INT_MAX, NULL, NULL
	},

706
	{
B
Bruce Momjian 已提交
707
		{"wal_buffers", PGC_POSTMASTER}, &XLOGbuffers,
708
		8, 4, INT_MAX, NULL, NULL
709
	},
V
Vadim B. Mikheev 已提交
710

711
	{
B
Bruce Momjian 已提交
712
		{"wal_debug", PGC_SUSET}, &XLOG_DEBUG,
713
		0, 0, 16, NULL, NULL
714
	},
V
Vadim B. Mikheev 已提交
715

716
	{
B
Bruce Momjian 已提交
717
		{"commit_delay", PGC_USERSET}, &CommitDelay,
718
		0, 0, 100000, NULL, NULL
719
	},
V
Vadim B. Mikheev 已提交
720

721
	{
B
Bruce Momjian 已提交
722
		{"commit_siblings", PGC_USERSET}, &CommitSiblings,
723
		5, 1, 1000, NULL, NULL
724
	},
725

726 727 728 729 730
	{
		{"extra_float_digits", PGC_USERSET}, &extra_float_digits,
		0, -15, 2, NULL, NULL
	},

731
	{
B
Bruce Momjian 已提交
732
		{NULL, 0}, NULL, 0, 0, 0, NULL, NULL
733
	}
734 735 736 737
};


static struct config_real
B
Bruce Momjian 已提交
738
			ConfigureNamesReal[] =
739
{
740
	{
B
Bruce Momjian 已提交
741
		{"effective_cache_size", PGC_USERSET}, &effective_cache_size,
742
		DEFAULT_EFFECTIVE_CACHE_SIZE, 0, DBL_MAX, NULL, NULL
743
	},
744
	{
B
Bruce Momjian 已提交
745
		{"random_page_cost", PGC_USERSET}, &random_page_cost,
746
		DEFAULT_RANDOM_PAGE_COST, 0, DBL_MAX, NULL, NULL
747 748
	},
	{
B
Bruce Momjian 已提交
749
		{"cpu_tuple_cost", PGC_USERSET}, &cpu_tuple_cost,
750
		DEFAULT_CPU_TUPLE_COST, 0, DBL_MAX, NULL, NULL
751 752
	},
	{
B
Bruce Momjian 已提交
753
		{"cpu_index_tuple_cost", PGC_USERSET}, &cpu_index_tuple_cost,
754
		DEFAULT_CPU_INDEX_TUPLE_COST, 0, DBL_MAX, NULL, NULL
755 756
	},
	{
B
Bruce Momjian 已提交
757
		{"cpu_operator_cost", PGC_USERSET}, &cpu_operator_cost,
758
		DEFAULT_CPU_OPERATOR_COST, 0, DBL_MAX, NULL, NULL
759 760 761
	},

	{
B
Bruce Momjian 已提交
762
		{"geqo_selection_bias", PGC_USERSET}, &Geqo_selection_bias,
763 764
		DEFAULT_GEQO_SELECTION_BIAS, MIN_GEQO_SELECTION_BIAS,
		MAX_GEQO_SELECTION_BIAS, NULL, NULL
765 766 767
	},

	{
B
Bruce Momjian 已提交
768
		{"seed", PGC_USERSET, GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL},
769 770 771 772 773
		&phony_random_seed,
		0.5, 0.0, 1.0, assign_random_seed, show_random_seed
	},

	{
B
Bruce Momjian 已提交
774
		{NULL, 0}, NULL, 0.0, 0.0, 0.0, NULL, NULL
775
	}
776 777 778 779
};


static struct config_string
B
Bruce Momjian 已提交
780
			ConfigureNamesString[] =
781
{
782
	{
783 784
		{"client_encoding", PGC_USERSET, GUC_REPORT},
		&client_encoding_string,
785
		"SQL_ASCII", assign_client_encoding, NULL
786 787
	},

788
	{
B
Bruce Momjian 已提交
789
		{"client_min_messages", PGC_USERSET}, &client_min_messages_str,
790
		"notice", assign_client_min_messages, NULL
791
	},
792

793
	{
794
		{"log_min_error_statement", PGC_SUSET}, &log_min_error_statement_str,
795
		"panic", assign_min_error_statement, NULL
796 797
	},

798
	{
799 800
		{"DateStyle", PGC_USERSET, GUC_LIST_INPUT | GUC_REPORT},
		&datestyle_string,
801
		"ISO, US", assign_datestyle, show_datestyle
802
	},
803

804
	{
B
Bruce Momjian 已提交
805
		{"default_transaction_isolation", PGC_USERSET}, &default_iso_level_string,
806
		"read committed", assign_defaultxactisolevel, NULL
807 808
	},

809
	{
B
Bruce Momjian 已提交
810
		{"dynamic_library_path", PGC_SUSET}, &Dynamic_library_path,
811 812 813 814
		"$libdir", NULL, NULL
	},

	{
B
Bruce Momjian 已提交
815
		{"krb_server_keyfile", PGC_POSTMASTER}, &pg_krb_server_keyfile,
816
		PG_KRB_SRVTAB, NULL, NULL
817
	},
818

819 820
	/* See main.c about why defaults for LC_foo are not all alike */

821 822 823 824 825 826 827 828 829 830
	{
		{"lc_collate", PGC_INTERNAL}, &locale_collate,
		"C", NULL, NULL
	},

	{
		{"lc_ctype", PGC_INTERNAL}, &locale_ctype,
		"C", NULL, NULL
	},

831
	{
B
Bruce Momjian 已提交
832
		{"lc_messages", PGC_SUSET}, &locale_messages,
833 834 835 836
		"", locale_messages_assign, NULL
	},

	{
B
Bruce Momjian 已提交
837
		{"lc_monetary", PGC_USERSET}, &locale_monetary,
838
		"C", locale_monetary_assign, NULL
839 840 841
	},

	{
B
Bruce Momjian 已提交
842
		{"lc_numeric", PGC_USERSET}, &locale_numeric,
843
		"C", locale_numeric_assign, NULL
844 845 846
	},

	{
B
Bruce Momjian 已提交
847
		{"lc_time", PGC_USERSET}, &locale_time,
848
		"C", locale_time_assign, NULL
849 850
	},

851 852 853 854 855 856
	{
		{"preload_libraries", PGC_POSTMASTER, GUC_LIST_INPUT | GUC_LIST_QUOTE},
		&preload_libraries_string,
		"", NULL, NULL
	},

857 858 859 860 861
	{
		{"regex_flavor", PGC_USERSET}, &regex_flavor_string,
		"advanced", assign_regex_flavor, NULL
	},

862
	{
B
Bruce Momjian 已提交
863
		{"search_path", PGC_USERSET, GUC_LIST_INPUT | GUC_LIST_QUOTE},
864 865
		&namespace_search_path,
		"$user,public", assign_search_path, NULL
866 867 868
	},

	{
869 870 871 872 873 874 875 876 877
		{"server_encoding", PGC_INTERNAL, GUC_REPORT},
		&server_encoding_string,
		"SQL_ASCII", NULL, NULL
	},

	{
		{"server_version", PGC_INTERNAL, GUC_REPORT},
		&server_version_string,
		PG_VERSION, NULL, NULL
878 879 880
	},

	{
881
		{"log_min_messages", PGC_SUSET}, &log_min_messages_str,
882
		"notice", assign_log_min_messages, NULL
883 884
	},

885
	{
B
Bruce Momjian 已提交
886
		{"session_authorization", PGC_USERSET, GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL},
887 888
		&session_authorization_string,
		NULL, assign_session_authorization, show_session_authorization
889 890
	},

T
Tatsuo Ishii 已提交
891
#ifdef HAVE_SYSLOG
892
	{
B
Bruce Momjian 已提交
893
		{"syslog_facility", PGC_POSTMASTER}, &Syslog_facility,
894
		"LOCAL0", assign_facility, NULL
895 896
	},
	{
B
Bruce Momjian 已提交
897
		{"syslog_ident", PGC_POSTMASTER}, &Syslog_ident,
898
		"postgres", NULL, NULL
899
	},
900
#endif
901

902
	{
B
Bruce Momjian 已提交
903
		{"TimeZone", PGC_USERSET}, &timezone_string,
904 905 906 907
		"UNKNOWN", assign_timezone, show_timezone
	},

	{
908
		{"transaction_isolation", PGC_USERSET, GUC_NO_RESET_ALL},
909 910 911 912 913
		&XactIsoLevel_string,
		NULL, assign_XactIsoLevel, show_XactIsoLevel
	},

	{
B
Bruce Momjian 已提交
914
		{"unix_socket_group", PGC_POSTMASTER}, &Unix_socket_group,
915
		"", NULL, NULL
916
	},
917

918
	{
B
Bruce Momjian 已提交
919
		{"unix_socket_directory", PGC_POSTMASTER}, &UnixSocketDir,
920
		"", NULL, NULL
921
	},
922

923
	{
B
Bruce Momjian 已提交
924
		{"virtual_host", PGC_POSTMASTER}, &VirtualHost,
925
		"", NULL, NULL
926
	},
927

928
	{
B
Bruce Momjian 已提交
929
		{"wal_sync_method", PGC_SIGHUP}, &XLOG_sync_method,
930
		XLOG_sync_method_default, assign_xlog_sync_method, NULL
931
	},
932

933
	{
B
Bruce Momjian 已提交
934
		{NULL, 0}, NULL, NULL, NULL, NULL
935
	}
936 937 938 939 940 941
};

/******** end of options list ********/


/*
942
 * Actual lookup of variables is done through this single, sorted array.
943
 */
944
static struct config_generic **guc_variables;
B
Bruce Momjian 已提交
945
static int	num_guc_variables;
946

947
static bool guc_dirty;			/* TRUE if need to do commit/abort work */
948

949 950
static bool reporting_enabled;	/* TRUE to enable GUC_REPORT */

B
Bruce Momjian 已提交
951
static char *guc_string_workspace;		/* for avoiding memory leaks */
952

953

B
Bruce Momjian 已提交
954
static int	guc_var_compare(const void *a, const void *b);
955
static void ReportGUCOption(struct config_generic *record);
B
Bruce Momjian 已提交
956
static char *_ShowOption(struct config_generic * record);
957 958 959


/*
B
Bruce Momjian 已提交
960
 * Build the sorted array.	This is split out so that it could be
961 962
 * re-executed after startup (eg, we could allow loadable modules to
 * add vars, and then we'd need to re-sort).
963
 */
964 965
static void
build_guc_variables(void)
966
{
967 968
	int			num_vars = 0;
	struct config_generic **guc_vars;
B
Bruce Momjian 已提交
969
	int			i;
970

971
	for (i = 0; ConfigureNamesBool[i].gen.name; i++)
972 973 974
	{
		struct config_bool *conf = &ConfigureNamesBool[i];

975 976 977
		/* Rather than requiring vartype to be filled in by hand, do this: */
		conf->gen.vartype = PGC_BOOL;
		num_vars++;
978
	}
979

980
	for (i = 0; ConfigureNamesInt[i].gen.name; i++)
981 982 983
	{
		struct config_int *conf = &ConfigureNamesInt[i];

984 985
		conf->gen.vartype = PGC_INT;
		num_vars++;
986
	}
987

988
	for (i = 0; ConfigureNamesReal[i].gen.name; i++)
989 990 991
	{
		struct config_real *conf = &ConfigureNamesReal[i];

992 993
		conf->gen.vartype = PGC_REAL;
		num_vars++;
994
	}
995

996
	for (i = 0; ConfigureNamesString[i].gen.name; i++)
997
	{
998
		struct config_string *conf = &ConfigureNamesString[i];
999

1000 1001
		conf->gen.vartype = PGC_STRING;
		num_vars++;
1002 1003
	}

1004 1005 1006 1007
	guc_vars = (struct config_generic **)
		malloc(num_vars * sizeof(struct config_generic *));
	if (!guc_vars)
		elog(PANIC, "out of memory");
1008

1009
	num_vars = 0;
1010

1011
	for (i = 0; ConfigureNamesBool[i].gen.name; i++)
B
Bruce Momjian 已提交
1012
		guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
1013

1014
	for (i = 0; ConfigureNamesInt[i].gen.name; i++)
B
Bruce Momjian 已提交
1015
		guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
1016

1017
	for (i = 0; ConfigureNamesReal[i].gen.name; i++)
B
Bruce Momjian 已提交
1018
		guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
1019

1020
	for (i = 0; ConfigureNamesString[i].gen.name; i++)
B
Bruce Momjian 已提交
1021
		guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
1022

1023 1024
	qsort((void *) guc_vars, num_vars, sizeof(struct config_generic *),
		  guc_var_compare);
1025

1026 1027 1028 1029
	if (guc_variables)
		free(guc_variables);
	guc_variables = guc_vars;
	num_guc_variables = num_vars;
1030 1031 1032 1033
}


/*
1034 1035
 * Look up option NAME. If it exists, return a pointer to its record,
 * else return NULL.
1036
 */
1037 1038
static struct config_generic *
find_option(const char *name)
1039
{
1040 1041
	const char **key = &name;
	struct config_generic **res;
1042

1043
	Assert(name);
1044

1045 1046 1047 1048
	/*
	 * by equating const char ** with struct config_generic *, we are
	 * assuming the name field is first in config_generic.
	 */
B
Bruce Momjian 已提交
1049 1050 1051 1052 1053
	res = (struct config_generic **) bsearch((void *) &key,
											 (void *) guc_variables,
											 num_guc_variables,
										 sizeof(struct config_generic *),
											 guc_var_compare);
1054 1055 1056 1057
	if (res)
		return *res;
	return NULL;
}
1058 1059 1060


/*
1061
 * comparator for qsorting and bsearching guc_variables array
1062
 */
1063 1064
static int
guc_var_compare(const void *a, const void *b)
1065
{
1066 1067
	struct config_generic *confa = *(struct config_generic **) a;
	struct config_generic *confb = *(struct config_generic **) b;
1068 1069
	const char *namea;
	const char *nameb;
1070

1071 1072 1073
	/*
	 * The temptation to use strcasecmp() here must be resisted, because
	 * the array ordering has to remain stable across setlocale() calls.
1074
	 * So, build our own with a simple ASCII-only downcasing.
1075
	 */
1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088
	namea = confa->name;
	nameb = confb->name;
	while (*namea && *nameb)
	{
		char		cha = *namea++;
		char		chb = *nameb++;

		if (cha >= 'A' && cha <= 'Z')
			cha += 'a' - 'A';
		if (chb >= 'A' && chb <= 'Z')
			chb += 'a' - 'A';
		if (cha != chb)
			return cha - chb;
1089
	}
1090 1091 1092 1093 1094
	if (*namea)
		return 1;				/* a is longer */
	if (*nameb)
		return -1;				/* b is longer */
	return 0;
1095
}
1096 1097 1098


/*
1099
 * Initialize GUC options during program startup.
1100
 */
1101 1102
void
InitializeGUCOptions(void)
1103
{
1104 1105
	int			i;
	char	   *env;
1106

1107 1108 1109 1110
	/*
	 * Build sorted array of all GUC variables.
	 */
	build_guc_variables();
1111

1112
	/*
1113 1114 1115 1116 1117 1118
	 * Load all variables with their compiled-in defaults, and initialize
	 * status fields as needed.
	 *
	 * Note: any errors here are reported with plain ol' printf, since we
	 * shouldn't assume that elog will work before we've initialized its
	 * config variables.  An error here would be unexpected anyway...
1119
	 */
1120
	for (i = 0; i < num_guc_variables; i++)
1121
	{
1122
		struct config_generic *gconf = guc_variables[i];
1123

1124 1125 1126 1127 1128 1129 1130 1131 1132
		gconf->status = 0;
		gconf->reset_source = PGC_S_DEFAULT;
		gconf->session_source = PGC_S_DEFAULT;
		gconf->tentative_source = PGC_S_DEFAULT;
		gconf->source = PGC_S_DEFAULT;

		switch (gconf->vartype)
		{
			case PGC_BOOL:
B
Bruce Momjian 已提交
1133 1134
				{
					struct config_bool *conf = (struct config_bool *) gconf;
1135

B
Bruce Momjian 已提交
1136 1137 1138 1139 1140 1141 1142 1143
					if (conf->assign_hook)
						if (!(*conf->assign_hook) (conf->reset_val, true, false))
							fprintf(stderr, "Failed to initialize %s to %d\n",
								  conf->gen.name, (int) conf->reset_val);
					*conf->variable = conf->reset_val;
					conf->session_val = conf->reset_val;
					break;
				}
1144
			case PGC_INT:
B
Bruce Momjian 已提交
1145 1146
				{
					struct config_int *conf = (struct config_int *) gconf;
1147

B
Bruce Momjian 已提交
1148 1149 1150 1151 1152 1153 1154 1155 1156 1157
					Assert(conf->reset_val >= conf->min);
					Assert(conf->reset_val <= conf->max);
					if (conf->assign_hook)
						if (!(*conf->assign_hook) (conf->reset_val, true, false))
							fprintf(stderr, "Failed to initialize %s to %d\n",
									conf->gen.name, conf->reset_val);
					*conf->variable = conf->reset_val;
					conf->session_val = conf->reset_val;
					break;
				}
1158 1159
			case PGC_REAL:
				{
B
Bruce Momjian 已提交
1160 1161 1162 1163 1164 1165 1166 1167 1168 1169
					struct config_real *conf = (struct config_real *) gconf;

					Assert(conf->reset_val >= conf->min);
					Assert(conf->reset_val <= conf->max);
					if (conf->assign_hook)
						if (!(*conf->assign_hook) (conf->reset_val, true, false))
							fprintf(stderr, "Failed to initialize %s to %g\n",
									conf->gen.name, conf->reset_val);
					*conf->variable = conf->reset_val;
					conf->session_val = conf->reset_val;
1170 1171
					break;
				}
B
Bruce Momjian 已提交
1172
			case PGC_STRING:
1173
				{
B
Bruce Momjian 已提交
1174 1175 1176 1177 1178 1179 1180
					struct config_string *conf = (struct config_string *) gconf;
					char	   *str;

					*conf->variable = NULL;
					conf->reset_val = NULL;
					conf->session_val = NULL;
					conf->tentative_val = NULL;
1181

B
Bruce Momjian 已提交
1182
					if (conf->boot_val == NULL)
1183
					{
B
Bruce Momjian 已提交
1184 1185
						/* Cannot set value yet */
						break;
1186
					}
B
Bruce Momjian 已提交
1187 1188 1189 1190 1191 1192 1193

					str = strdup(conf->boot_val);
					if (str == NULL)
						elog(PANIC, "out of memory");
					conf->reset_val = str;

					if (conf->assign_hook)
1194
					{
B
Bruce Momjian 已提交
1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213
						const char *newstr;

						newstr = (*conf->assign_hook) (str, true, false);
						if (newstr == NULL)
						{
							fprintf(stderr, "Failed to initialize %s to '%s'\n",
									conf->gen.name, str);
						}
						else if (newstr != str)
						{
							free(str);

							/*
							 * See notes in set_config_option about
							 * casting
							 */
							str = (char *) newstr;
							conf->reset_val = str;
						}
1214
					}
B
Bruce Momjian 已提交
1215 1216 1217
					*conf->variable = str;
					conf->session_val = str;
					break;
1218 1219 1220 1221 1222 1223
				}
		}
	}

	guc_dirty = false;

1224 1225
	reporting_enabled = false;

1226 1227 1228
	guc_string_workspace = NULL;

	/*
1229
	 * Prevent any attempt to override the transaction modes from
1230 1231
	 * non-interactive sources.
	 */
1232 1233 1234
	SetConfigOption("transaction_isolation", "default",
					PGC_POSTMASTER, PGC_S_OVERRIDE);
	SetConfigOption("transaction_read_only", "no",
1235 1236 1237 1238
					PGC_POSTMASTER, PGC_S_OVERRIDE);

	/*
	 * For historical reasons, some GUC parameters can receive defaults
B
Bruce Momjian 已提交
1239
	 * from environment variables.	Process those settings.
1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284
	 */

	env = getenv("PGPORT");
	if (env != NULL)
		SetConfigOption("port", env, PGC_POSTMASTER, PGC_S_ENV_VAR);

	env = getenv("PGDATESTYLE");
	if (env != NULL)
		SetConfigOption("datestyle", env, PGC_POSTMASTER, PGC_S_ENV_VAR);

	env = getenv("TZ");
	if (env != NULL)
		SetConfigOption("timezone", env, PGC_POSTMASTER, PGC_S_ENV_VAR);

	env = getenv("PGCLIENTENCODING");
	if (env != NULL)
		SetConfigOption("client_encoding", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
}


/*
 * Reset all options to their saved default values (implements RESET ALL)
 */
void
ResetAllOptions(void)
{
	int			i;

	for (i = 0; i < num_guc_variables; i++)
	{
		struct config_generic *gconf = guc_variables[i];

		/* Don't reset non-SET-able values */
		if (gconf->context != PGC_SUSET && gconf->context != PGC_USERSET)
			continue;
		/* Don't reset if special exclusion from RESET ALL */
		if (gconf->flags & GUC_NO_RESET_ALL)
			continue;
		/* No need to reset if wasn't SET */
		if (gconf->source <= PGC_S_OVERRIDE)
			continue;

		switch (gconf->vartype)
		{
			case PGC_BOOL:
B
Bruce Momjian 已提交
1285 1286
				{
					struct config_bool *conf = (struct config_bool *) gconf;
1287

B
Bruce Momjian 已提交
1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298
					if (conf->assign_hook)
						if (!(*conf->assign_hook) (conf->reset_val, true, true))
							elog(ERROR, "Failed to reset %s", conf->gen.name);
					*conf->variable = conf->reset_val;
					conf->tentative_val = conf->reset_val;
					conf->gen.source = conf->gen.reset_source;
					conf->gen.tentative_source = conf->gen.reset_source;
					conf->gen.status |= GUC_HAVE_TENTATIVE;
					guc_dirty = true;
					break;
				}
1299
			case PGC_INT:
B
Bruce Momjian 已提交
1300 1301
				{
					struct config_int *conf = (struct config_int *) gconf;
1302

B
Bruce Momjian 已提交
1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313
					if (conf->assign_hook)
						if (!(*conf->assign_hook) (conf->reset_val, true, true))
							elog(ERROR, "Failed to reset %s", conf->gen.name);
					*conf->variable = conf->reset_val;
					conf->tentative_val = conf->reset_val;
					conf->gen.source = conf->gen.reset_source;
					conf->gen.tentative_source = conf->gen.reset_source;
					conf->gen.status |= GUC_HAVE_TENTATIVE;
					guc_dirty = true;
					break;
				}
1314 1315
			case PGC_REAL:
				{
B
Bruce Momjian 已提交
1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326
					struct config_real *conf = (struct config_real *) gconf;

					if (conf->assign_hook)
						if (!(*conf->assign_hook) (conf->reset_val, true, true))
							elog(ERROR, "Failed to reset %s", conf->gen.name);
					*conf->variable = conf->reset_val;
					conf->tentative_val = conf->reset_val;
					conf->gen.source = conf->gen.reset_source;
					conf->gen.tentative_source = conf->gen.reset_source;
					conf->gen.status |= GUC_HAVE_TENTATIVE;
					guc_dirty = true;
1327 1328
					break;
				}
B
Bruce Momjian 已提交
1329 1330 1331 1332
			case PGC_STRING:
				{
					struct config_string *conf = (struct config_string *) gconf;
					char	   *str;
1333

B
Bruce Momjian 已提交
1334 1335 1336 1337 1338
					if (conf->reset_val == NULL)
					{
						/* Nothing to reset to, as yet; so do nothing */
						break;
					}
1339

B
Bruce Momjian 已提交
1340 1341
					/* We need not strdup here */
					str = conf->reset_val;
1342

B
Bruce Momjian 已提交
1343
					if (conf->assign_hook)
1344
					{
B
Bruce Momjian 已提交
1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357
						const char *newstr;

						newstr = (*conf->assign_hook) (str, true, true);
						if (newstr == NULL)
							elog(ERROR, "Failed to reset %s", conf->gen.name);
						else if (newstr != str)
						{
							/*
							 * See notes in set_config_option about
							 * casting
							 */
							str = (char *) newstr;
						}
1358 1359
					}

B
Bruce Momjian 已提交
1360 1361 1362 1363 1364 1365 1366 1367
					SET_STRING_VARIABLE(conf, str);
					SET_STRING_TENTATIVE_VAL(conf, str);
					conf->gen.source = conf->gen.reset_source;
					conf->gen.tentative_source = conf->gen.reset_source;
					conf->gen.status |= GUC_HAVE_TENTATIVE;
					guc_dirty = true;
					break;
				}
1368
		}
1369 1370 1371

		if (gconf->flags & GUC_REPORT)
			ReportGUCOption(gconf);
1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397
	}
}


/*
 * Do GUC processing at transaction commit or abort.
 */
void
AtEOXact_GUC(bool isCommit)
{
	int			i;

	/* Quick exit if nothing's changed in this transaction */
	if (!guc_dirty)
		return;

	/* Prevent memory leak if elog during an assign_hook */
	if (guc_string_workspace)
	{
		free(guc_string_workspace);
		guc_string_workspace = NULL;
	}

	for (i = 0; i < num_guc_variables; i++)
	{
		struct config_generic *gconf = guc_variables[i];
1398
		bool	changed;
1399 1400 1401 1402 1403

		/* Skip if nothing's happened to this var in this transaction */
		if (gconf->status == 0)
			continue;

1404 1405
		changed = false;

1406 1407 1408 1409
		switch (gconf->vartype)
		{
			case PGC_BOOL:
				{
B
Bruce Momjian 已提交
1410
					struct config_bool *conf = (struct config_bool *) gconf;
1411

B
Bruce Momjian 已提交
1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424
					if (isCommit && (conf->gen.status & GUC_HAVE_TENTATIVE))
					{
						conf->session_val = conf->tentative_val;
						conf->gen.session_source = conf->gen.tentative_source;
					}

					if (*conf->variable != conf->session_val)
					{
						if (conf->assign_hook)
							if (!(*conf->assign_hook) (conf->session_val,
													   true, false))
								elog(LOG, "Failed to commit %s", conf->gen.name);
						*conf->variable = conf->session_val;
1425
						changed = true;
B
Bruce Momjian 已提交
1426 1427 1428 1429
					}
					conf->gen.source = conf->gen.session_source;
					conf->gen.status = 0;
					break;
1430 1431 1432
				}
			case PGC_INT:
				{
B
Bruce Momjian 已提交
1433
					struct config_int *conf = (struct config_int *) gconf;
1434

B
Bruce Momjian 已提交
1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447
					if (isCommit && (conf->gen.status & GUC_HAVE_TENTATIVE))
					{
						conf->session_val = conf->tentative_val;
						conf->gen.session_source = conf->gen.tentative_source;
					}

					if (*conf->variable != conf->session_val)
					{
						if (conf->assign_hook)
							if (!(*conf->assign_hook) (conf->session_val,
													   true, false))
								elog(LOG, "Failed to commit %s", conf->gen.name);
						*conf->variable = conf->session_val;
1448
						changed = true;
B
Bruce Momjian 已提交
1449 1450 1451 1452
					}
					conf->gen.source = conf->gen.session_source;
					conf->gen.status = 0;
					break;
1453 1454 1455
				}
			case PGC_REAL:
				{
B
Bruce Momjian 已提交
1456
					struct config_real *conf = (struct config_real *) gconf;
1457

B
Bruce Momjian 已提交
1458 1459 1460 1461 1462
					if (isCommit && (conf->gen.status & GUC_HAVE_TENTATIVE))
					{
						conf->session_val = conf->tentative_val;
						conf->gen.session_source = conf->gen.tentative_source;
					}
1463

B
Bruce Momjian 已提交
1464 1465 1466 1467 1468 1469 1470
					if (*conf->variable != conf->session_val)
					{
						if (conf->assign_hook)
							if (!(*conf->assign_hook) (conf->session_val,
													   true, false))
								elog(LOG, "Failed to commit %s", conf->gen.name);
						*conf->variable = conf->session_val;
1471
						changed = true;
B
Bruce Momjian 已提交
1472 1473 1474 1475
					}
					conf->gen.source = conf->gen.session_source;
					conf->gen.status = 0;
					break;
1476
				}
B
Bruce Momjian 已提交
1477
			case PGC_STRING:
1478
				{
B
Bruce Momjian 已提交
1479
					struct config_string *conf = (struct config_string *) gconf;
1480

B
Bruce Momjian 已提交
1481 1482 1483 1484 1485 1486 1487 1488
					if (isCommit && (conf->gen.status & GUC_HAVE_TENTATIVE))
					{
						SET_STRING_SESSION_VAL(conf, conf->tentative_val);
						conf->gen.session_source = conf->gen.tentative_source;
						conf->tentative_val = NULL;		/* transfer ownership */
					}
					else
						SET_STRING_TENTATIVE_VAL(conf, NULL);
1489

B
Bruce Momjian 已提交
1490
					if (*conf->variable != conf->session_val)
1491
					{
B
Bruce Momjian 已提交
1492
						char	   *str = conf->session_val;
1493

B
Bruce Momjian 已提交
1494
						if (conf->assign_hook)
1495
						{
B
Bruce Momjian 已提交
1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509
							const char *newstr;

							newstr = (*conf->assign_hook) (str, true, false);
							if (newstr == NULL)
								elog(LOG, "Failed to commit %s", conf->gen.name);
							else if (newstr != str)
							{
								/*
								 * See notes in set_config_option about
								 * casting
								 */
								str = (char *) newstr;
								SET_STRING_SESSION_VAL(conf, str);
							}
1510 1511
						}

B
Bruce Momjian 已提交
1512
						SET_STRING_VARIABLE(conf, str);
1513
						changed = true;
B
Bruce Momjian 已提交
1514 1515 1516 1517
					}
					conf->gen.source = conf->gen.session_source;
					conf->gen.status = 0;
					break;
1518 1519
				}
		}
1520 1521 1522

		if (changed && (gconf->flags & GUC_REPORT))
			ReportGUCOption(gconf);
1523 1524 1525 1526 1527 1528
	}

	guc_dirty = false;
}


1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578
/*
 * Start up automatic reporting of changes to variables marked GUC_REPORT.
 * This is executed at completion of backend startup.
 */
void
BeginReportingGUCOptions(void)
{
	int			i;

	/*
	 * Don't do anything unless talking to an interactive frontend of
	 * protocol 3.0 or later.
	 */
	if (whereToSendOutput != Remote ||
		PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
		return;

	reporting_enabled = true;

	/* Transmit initial values of interesting variables */
	for (i = 0; i < num_guc_variables; i++)
	{
		struct config_generic *conf = guc_variables[i];

		if (conf->flags & GUC_REPORT)
			ReportGUCOption(conf);
	}
}

/*
 * ReportGUCOption: if appropriate, transmit option value to frontend
 */
static void
ReportGUCOption(struct config_generic *record)
{
	if (reporting_enabled && (record->flags & GUC_REPORT))
	{
		char	*val = _ShowOption(record);
		StringInfoData msgbuf;

		pq_beginmessage(&msgbuf, 'S');
		pq_sendstring(&msgbuf, record->name);
		pq_sendstring(&msgbuf, val);
		pq_endmessage(&msgbuf);

		pfree(val);
	}
}


1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723
/*
 * Try to interpret value as boolean value.  Valid values are: true,
 * false, yes, no, on, off, 1, 0.  If the string parses okay, return
 * true, else false.  If result is not NULL, return the parsing result
 * there.
 */
static bool
parse_bool(const char *value, bool *result)
{
	size_t		len = strlen(value);

	if (strncasecmp(value, "true", len) == 0)
	{
		if (result)
			*result = true;
	}
	else if (strncasecmp(value, "false", len) == 0)
	{
		if (result)
			*result = false;
	}

	else if (strncasecmp(value, "yes", len) == 0)
	{
		if (result)
			*result = true;
	}
	else if (strncasecmp(value, "no", len) == 0)
	{
		if (result)
			*result = false;
	}

	else if (strcasecmp(value, "on") == 0)
	{
		if (result)
			*result = true;
	}
	else if (strcasecmp(value, "off") == 0)
	{
		if (result)
			*result = false;
	}

	else if (strcasecmp(value, "1") == 0)
	{
		if (result)
			*result = true;
	}
	else if (strcasecmp(value, "0") == 0)
	{
		if (result)
			*result = false;
	}

	else
		return false;
	return true;
}



/*
 * Try to parse value as an integer.  The accepted formats are the
 * usual decimal, octal, or hexadecimal formats.  If the string parses
 * okay, return true, else false.  If result is not NULL, return the
 * value there.
 */
static bool
parse_int(const char *value, int *result)
{
	long		val;
	char	   *endptr;

	errno = 0;
	val = strtol(value, &endptr, 0);
	if (endptr == value || *endptr != '\0' || errno == ERANGE
#ifdef HAVE_LONG_INT_64
	/* if long > 32 bits, check for overflow of int4 */
		|| val != (long) ((int32) val)
#endif
		)
		return false;
	if (result)
		*result = (int) val;
	return true;
}



/*
 * Try to parse value as a floating point constant in the usual
 * format.	If the value parsed okay return true, else false.  If
 * result is not NULL, return the semantic value there.
 */
static bool
parse_real(const char *value, double *result)
{
	double		val;
	char	   *endptr;

	errno = 0;
	val = strtod(value, &endptr);
	if (endptr == value || *endptr != '\0' || errno == ERANGE)
		return false;
	if (result)
		*result = val;
	return true;
}



/*
 * Sets option `name' to given value. The value should be a string
 * which is going to be parsed and converted to the appropriate data
 * type.  The context and source parameters indicate in which context this
 * function is being called so it can apply the access restrictions
 * properly.
 *
 * If value is NULL, set the option to its default value. If the
 * parameter DoIt is false then don't really set the option but do all
 * the checks to see if it would work.
 *
 * If there is an error (non-existing option, invalid value) then an
 * elog(ERROR) is thrown *unless* this is called in a context where we
 * don't want to elog (currently, startup or SIGHUP config file reread).
 * In that case we write a suitable error message via elog(DEBUG) and
 * return false. This is working around the deficiencies in the elog
 * mechanism, so don't blame me.  In all other cases, the function
 * returns true, including cases where the input is valid but we chose
 * not to apply it because of context or source-priority considerations.
 *
 * See also SetConfigOption for an external interface.
 */
bool
set_config_option(const char *name, const char *value,
				  GucContext context, GucSource source,
				  bool isLocal, bool DoIt)
{
	struct config_generic *record;
	int			elevel;
	bool		interactive;
	bool		makeDefault;

	if (context == PGC_SIGHUP || source == PGC_S_DEFAULT)
1724
		elevel = DEBUG2;
1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744
	else if (source == PGC_S_DATABASE || source == PGC_S_USER)
		elevel = INFO;
	else
		elevel = ERROR;

	record = find_option(name);
	if (record == NULL)
	{
		elog(elevel, "'%s' is not a valid option name", name);
		return false;
	}

	/*
	 * Check if the option can be set at this time. See guc.h for the
	 * precise rules. Note that we don't want to throw errors if we're in
	 * the SIGHUP context. In that case we just ignore the attempt and
	 * return true.
	 */
	switch (record->context)
	{
1745 1746 1747 1748 1749 1750 1751 1752 1753 1754
		case PGC_INTERNAL:
			if (context == PGC_SIGHUP)
				return true;
			if (context != PGC_INTERNAL)
			{
				elog(elevel, "'%s' cannot be changed",
					 name);
				return false;
			}
			break;
1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804
		case PGC_POSTMASTER:
			if (context == PGC_SIGHUP)
				return true;
			if (context != PGC_POSTMASTER)
			{
				elog(elevel, "'%s' cannot be changed after server start",
					 name);
				return false;
			}
			break;
		case PGC_SIGHUP:
			if (context != PGC_SIGHUP && context != PGC_POSTMASTER)
			{
				elog(elevel, "'%s' cannot be changed now", name);
				return false;
			}

			/*
			 * Hmm, the idea of the SIGHUP context is "ought to be global,
			 * but can be changed after postmaster start". But there's
			 * nothing that prevents a crafty administrator from sending
			 * SIGHUP signals to individual backends only.
			 */
			break;
		case PGC_BACKEND:
			if (context == PGC_SIGHUP)
			{
				/*
				 * If a PGC_BACKEND parameter is changed in the config
				 * file, we want to accept the new value in the postmaster
				 * (whence it will propagate to subsequently-started
				 * backends), but ignore it in existing backends.  This is
				 * a tad klugy, but necessary because we don't re-read the
				 * config file during backend start.
				 */
				if (IsUnderPostmaster)
					return true;
			}
			else if (context != PGC_BACKEND && context != PGC_POSTMASTER)
			{
				elog(elevel, "'%s' cannot be set after connection start",
					 name);
				return false;
			}
			break;
		case PGC_SUSET:
			if (context == PGC_USERSET || context == PGC_BACKEND)
			{
				elog(elevel, "'%s': permission denied", name);
				return false;
1805 1806 1807 1808 1809
			}
			break;
		case PGC_USERSET:
			/* always okay */
			break;
1810
	}
1811

1812
	/* Should we report errors interactively? */
1813
	interactive = (source >= PGC_S_SESSION);
B
Bruce Momjian 已提交
1814

1815
	/*
B
Bruce Momjian 已提交
1816
	 * Should we set reset/session values?	(If so, the behavior is not
1817 1818 1819
	 * transactional.)
	 */
	makeDefault = DoIt && (source <= PGC_S_OVERRIDE) && (value != NULL);
1820 1821 1822

	/*
	 * Ignore attempted set if overridden by previously processed setting.
B
Bruce Momjian 已提交
1823 1824 1825 1826 1827
	 * However, if DoIt is false then plow ahead anyway since we are
	 * trying to find out if the value is potentially good, not actually
	 * use it. Also keep going if makeDefault is true, since we may want
	 * to set the reset/session values even if we can't set the variable
	 * itself.
1828 1829 1830 1831 1832
	 */
	if (record->source > source)
	{
		if (DoIt && !makeDefault)
		{
1833
			elog(DEBUG3, "%s: setting ignored because previous source is higher priority",
1834 1835 1836 1837 1838 1839
				 name);
			return true;
		}
		DoIt = false;			/* we won't change the variable itself */
	}

1840 1841 1842
	/*
	 * Evaluate value and set variable
	 */
1843
	switch (record->vartype)
1844 1845 1846
	{
		case PGC_BOOL:
			{
B
Bruce Momjian 已提交
1847
				struct config_bool *conf = (struct config_bool *) record;
1848
				bool		newval;
B
Bruce Momjian 已提交
1849 1850

				if (value)
1851
				{
1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863
					if (!parse_bool(value, &newval))
					{
						elog(elevel, "option '%s' requires a boolean value",
							 name);
						return false;
					}
				}
				else
				{
					newval = conf->reset_val;
					source = conf->gen.reset_source;
				}
B
Bruce Momjian 已提交
1864

1865 1866
				if (conf->assign_hook)
					if (!(*conf->assign_hook) (newval, DoIt, interactive))
B
Bruce Momjian 已提交
1867
					{
1868 1869
						elog(elevel, "invalid value for option '%s': %d",
							 name, (int) newval);
B
Bruce Momjian 已提交
1870 1871
						return false;
					}
1872 1873 1874

				if (DoIt || makeDefault)
				{
B
Bruce Momjian 已提交
1875
					if (DoIt)
1876
					{
1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903
						*conf->variable = newval;
						conf->gen.source = source;
					}
					if (makeDefault)
					{
						if (conf->gen.reset_source <= source)
						{
							conf->reset_val = newval;
							conf->gen.reset_source = source;
						}
						if (conf->gen.session_source <= source)
						{
							conf->session_val = newval;
							conf->gen.session_source = source;
						}
					}
					else if (isLocal)
					{
						conf->gen.status |= GUC_HAVE_LOCAL;
						guc_dirty = true;
					}
					else
					{
						conf->tentative_val = newval;
						conf->gen.tentative_source = source;
						conf->gen.status |= GUC_HAVE_TENTATIVE;
						guc_dirty = true;
1904
					}
1905
				}
B
Bruce Momjian 已提交
1906
				break;
1907
			}
1908 1909

		case PGC_INT:
1910
			{
B
Bruce Momjian 已提交
1911
				struct config_int *conf = (struct config_int *) record;
1912
				int			newval;
1913

B
Bruce Momjian 已提交
1914
				if (value)
1915
				{
1916
					if (!parse_int(value, &newval))
B
Bruce Momjian 已提交
1917
					{
1918 1919
						elog(elevel, "option '%s' expects an integer value",
							 name);
B
Bruce Momjian 已提交
1920 1921
						return false;
					}
1922
					if (newval < conf->min || newval > conf->max)
B
Bruce Momjian 已提交
1923 1924 1925
					{
						elog(elevel, "option '%s' value %d is outside"
							 " of permissible range [%d .. %d]",
1926
							 name, newval, conf->min, conf->max);
B
Bruce Momjian 已提交
1927 1928
						return false;
					}
1929 1930 1931 1932 1933 1934 1935 1936 1937
				}
				else
				{
					newval = conf->reset_val;
					source = conf->gen.reset_source;
				}

				if (conf->assign_hook)
					if (!(*conf->assign_hook) (newval, DoIt, interactive))
1938 1939
					{
						elog(elevel, "invalid value for option '%s': %d",
1940
							 name, newval);
1941 1942
						return false;
					}
1943 1944 1945

				if (DoIt || makeDefault)
				{
B
Bruce Momjian 已提交
1946
					if (DoIt)
1947
					{
1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974
						*conf->variable = newval;
						conf->gen.source = source;
					}
					if (makeDefault)
					{
						if (conf->gen.reset_source <= source)
						{
							conf->reset_val = newval;
							conf->gen.reset_source = source;
						}
						if (conf->gen.session_source <= source)
						{
							conf->session_val = newval;
							conf->gen.session_source = source;
						}
					}
					else if (isLocal)
					{
						conf->gen.status |= GUC_HAVE_LOCAL;
						guc_dirty = true;
					}
					else
					{
						conf->tentative_val = newval;
						conf->gen.tentative_source = source;
						conf->gen.status |= GUC_HAVE_TENTATIVE;
						guc_dirty = true;
1975
					}
1976
				}
B
Bruce Momjian 已提交
1977
				break;
1978
			}
1979 1980

		case PGC_REAL:
1981
			{
B
Bruce Momjian 已提交
1982
				struct config_real *conf = (struct config_real *) record;
1983
				double		newval;
1984

B
Bruce Momjian 已提交
1985
				if (value)
1986
				{
1987
					if (!parse_real(value, &newval))
B
Bruce Momjian 已提交
1988
					{
1989 1990
						elog(elevel, "option '%s' expects a real number",
							 name);
B
Bruce Momjian 已提交
1991 1992
						return false;
					}
1993
					if (newval < conf->min || newval > conf->max)
B
Bruce Momjian 已提交
1994 1995 1996
					{
						elog(elevel, "option '%s' value %g is outside"
							 " of permissible range [%g .. %g]",
1997
							 name, newval, conf->min, conf->max);
B
Bruce Momjian 已提交
1998 1999
						return false;
					}
2000 2001 2002 2003 2004 2005 2006 2007 2008
				}
				else
				{
					newval = conf->reset_val;
					source = conf->gen.reset_source;
				}

				if (conf->assign_hook)
					if (!(*conf->assign_hook) (newval, DoIt, interactive))
2009 2010
					{
						elog(elevel, "invalid value for option '%s': %g",
2011
							 name, newval);
2012 2013
						return false;
					}
2014 2015 2016

				if (DoIt || makeDefault)
				{
B
Bruce Momjian 已提交
2017
					if (DoIt)
2018
					{
2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045
						*conf->variable = newval;
						conf->gen.source = source;
					}
					if (makeDefault)
					{
						if (conf->gen.reset_source <= source)
						{
							conf->reset_val = newval;
							conf->gen.reset_source = source;
						}
						if (conf->gen.session_source <= source)
						{
							conf->session_val = newval;
							conf->gen.session_source = source;
						}
					}
					else if (isLocal)
					{
						conf->gen.status |= GUC_HAVE_LOCAL;
						guc_dirty = true;
					}
					else
					{
						conf->tentative_val = newval;
						conf->gen.tentative_source = source;
						conf->gen.status |= GUC_HAVE_TENTATIVE;
						guc_dirty = true;
2046
					}
2047
				}
B
Bruce Momjian 已提交
2048
				break;
2049
			}
2050 2051 2052

		case PGC_STRING:
			{
B
Bruce Momjian 已提交
2053
				struct config_string *conf = (struct config_string *) record;
2054
				char	   *newval;
B
Bruce Momjian 已提交
2055 2056

				if (value)
2057
				{
2058 2059 2060 2061 2062 2063 2064 2065 2066
					newval = strdup(value);
					if (newval == NULL)
					{
						elog(elevel, "out of memory");
						return false;
					}
				}
				else if (conf->reset_val)
				{
2067 2068
					/*
					 * We could possibly avoid strdup here, but easier to
B
Bruce Momjian 已提交
2069 2070
					 * make this case work the same as the normal
					 * assignment case.
2071
					 */
2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095
					newval = strdup(conf->reset_val);
					if (newval == NULL)
					{
						elog(elevel, "out of memory");
						return false;
					}
					source = conf->gen.reset_source;
				}
				else
				{
					/* Nothing to reset to, as yet; so do nothing */
					break;
				}

				/*
				 * Remember string in workspace, so that we can free it
				 * and avoid a permanent memory leak if hook elogs.
				 */
				if (guc_string_workspace)
					free(guc_string_workspace);
				guc_string_workspace = newval;

				if (conf->assign_hook)
				{
B
Bruce Momjian 已提交
2096
					const char *hookresult;
2097 2098 2099 2100 2101

					hookresult = (*conf->assign_hook) (newval,
													   DoIt, interactive);
					guc_string_workspace = NULL;
					if (hookresult == NULL)
B
Bruce Momjian 已提交
2102
					{
2103
						free(newval);
2104
						elog(elevel, "invalid value for option '%s': '%s'",
2105
							 name, value ? value : "");
B
Bruce Momjian 已提交
2106 2107
						return false;
					}
2108
					else if (hookresult != newval)
B
Bruce Momjian 已提交
2109
					{
2110
						free(newval);
B
Bruce Momjian 已提交
2111

2112
						/*
B
Bruce Momjian 已提交
2113 2114 2115 2116 2117 2118 2119
						 * Having to cast away const here is annoying, but
						 * the alternative is to declare assign_hooks as
						 * returning char*, which would mean they'd have
						 * to cast away const, or as both taking and
						 * returning char*, which doesn't seem attractive
						 * either --- we don't want them to scribble on
						 * the passed str.
2120 2121 2122 2123 2124 2125
						 */
						newval = (char *) hookresult;
					}
				}

				guc_string_workspace = NULL;
B
Bruce Momjian 已提交
2126

2127 2128 2129 2130 2131 2132 2133 2134 2135 2136
				if (DoIt || makeDefault)
				{
					if (DoIt)
					{
						SET_STRING_VARIABLE(conf, newval);
						conf->gen.source = source;
					}
					if (makeDefault)
					{
						if (conf->gen.reset_source <= source)
B
Bruce Momjian 已提交
2137
						{
2138 2139
							SET_STRING_RESET_VAL(conf, newval);
							conf->gen.reset_source = source;
B
Bruce Momjian 已提交
2140
						}
2141
						if (conf->gen.session_source <= source)
2142
						{
2143 2144
							SET_STRING_SESSION_VAL(conf, newval);
							conf->gen.session_source = source;
2145
						}
2146 2147 2148 2149 2150
						/* Perhaps we didn't install newval anywhere */
						if (newval != *conf->variable &&
							newval != conf->session_val &&
							newval != conf->reset_val)
							free(newval);
B
Bruce Momjian 已提交
2151
					}
2152
					else if (isLocal)
2153
					{
2154 2155
						conf->gen.status |= GUC_HAVE_LOCAL;
						guc_dirty = true;
2156
					}
2157
					else
2158
					{
2159 2160 2161 2162
						SET_STRING_TENTATIVE_VAL(conf, newval);
						conf->gen.tentative_source = source;
						conf->gen.status |= GUC_HAVE_TENTATIVE;
						guc_dirty = true;
2163
					}
2164 2165 2166
				}
				else
					free(newval);
B
Bruce Momjian 已提交
2167
				break;
2168
			}
2169
	}
2170

2171 2172 2173
	if (DoIt && (record->flags & GUC_REPORT))
			ReportGUCOption(record);

2174 2175 2176 2177 2178 2179 2180
	return true;
}



/*
 * Set a config option to the given value. See also set_config_option,
B
Bruce Momjian 已提交
2181
 * this is just the wrapper to be called from outside GUC.	NB: this
2182
 * is used only for non-transactional operations.
2183 2184
 */
void
2185
SetConfigOption(const char *name, const char *value,
2186
				GucContext context, GucSource source)
2187
{
2188
	(void) set_config_option(name, value, context, source, false, true);
2189 2190 2191 2192 2193
}



/*
2194 2195
 * Fetch the current value of the option `name'. If the option doesn't exist,
 * throw an elog and don't return.
2196 2197 2198 2199 2200
 *
 * The string is *not* allocated for modification and is really only
 * valid until the next call to configuration related functions.
 */
const char *
B
Bruce Momjian 已提交
2201
GetConfigOption(const char *name)
2202
{
B
Bruce Momjian 已提交
2203
	struct config_generic *record;
2204 2205
	static char buffer[256];

2206 2207
	record = find_option(name);
	if (record == NULL)
2208
		elog(ERROR, "Option '%s' is not recognized", name);
2209

2210
	switch (record->vartype)
2211 2212
	{
		case PGC_BOOL:
B
Bruce Momjian 已提交
2213
			return *((struct config_bool *) record)->variable ? "on" : "off";
2214

2215
		case PGC_INT:
2216 2217
			snprintf(buffer, sizeof(buffer), "%d",
					 *((struct config_int *) record)->variable);
2218 2219
			return buffer;

2220
		case PGC_REAL:
2221 2222
			snprintf(buffer, sizeof(buffer), "%g",
					 *((struct config_real *) record)->variable);
2223 2224 2225
			return buffer;

		case PGC_STRING:
B
Bruce Momjian 已提交
2226
			return *((struct config_string *) record)->variable;
2227 2228 2229
	}
	return NULL;
}
2230

2231 2232 2233 2234 2235
/*
 * Get the RESET value associated with the given option.
 */
const char *
GetConfigOptionResetString(const char *name)
2236
{
2237 2238
	struct config_generic *record;
	static char buffer[256];
2239

2240 2241 2242 2243 2244
	record = find_option(name);
	if (record == NULL)
		elog(ERROR, "Option '%s' is not recognized", name);

	switch (record->vartype)
2245 2246
	{
		case PGC_BOOL:
2247
			return ((struct config_bool *) record)->reset_val ? "on" : "off";
2248

2249
		case PGC_INT:
2250
			snprintf(buffer, sizeof(buffer), "%d",
2251 2252
					 ((struct config_int *) record)->reset_val);
			return buffer;
2253 2254

		case PGC_REAL:
2255
			snprintf(buffer, sizeof(buffer), "%g",
2256 2257
					 ((struct config_real *) record)->reset_val);
			return buffer;
2258 2259

		case PGC_STRING:
2260 2261 2262 2263
			return ((struct config_string *) record)->reset_val;
	}
	return NULL;
}
2264

2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283


/*
 * flatten_set_variable_args
 *		Given a parsenode List as emitted by the grammar for SET,
 *		convert to the flat string representation used by GUC.
 *
 * We need to be told the name of the variable the args are for, because
 * the flattening rules vary (ugh).
 *
 * The result is NULL if input is NIL (ie, SET ... TO DEFAULT), otherwise
 * a palloc'd string.
 */
char *
flatten_set_variable_args(const char *name, List *args)
{
	struct config_generic *record;
	int			flags;
	StringInfoData buf;
B
Bruce Momjian 已提交
2284
	List	   *l;
2285

2286 2287 2288 2289
	/*
	 * Fast path if just DEFAULT.  We do not check the variable name in
	 * this case --- necessary for RESET ALL to work correctly.
	 */
2290 2291 2292
	if (args == NIL)
		return NULL;

2293
	/* Else get flags for the variable */
2294 2295
	record = find_option(name);
	if (record == NULL)
2296 2297 2298
		elog(ERROR, "'%s' is not a valid option name", name);

	flags = record->flags;
2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335

	/* Complain if list input and non-list variable */
	if ((flags & GUC_LIST_INPUT) == 0 &&
		lnext(args) != NIL)
		elog(ERROR, "SET %s takes only one argument", name);

	initStringInfo(&buf);

	foreach(l, args)
	{
		A_Const    *arg = (A_Const *) lfirst(l);
		char	   *val;

		if (l != args)
			appendStringInfo(&buf, ", ");

		if (!IsA(arg, A_Const))
			elog(ERROR, "flatten_set_variable_args: unexpected input");

		switch (nodeTag(&arg->val))
		{
			case T_Integer:
				appendStringInfo(&buf, "%ld", intVal(&arg->val));
				break;
			case T_Float:
				/* represented as a string, so just copy it */
				appendStringInfo(&buf, "%s", strVal(&arg->val));
				break;
			case T_String:
				val = strVal(&arg->val);
				if (arg->typename != NULL)
				{
					/*
					 * Must be a ConstInterval argument for TIME ZONE.
					 * Coerce to interval and back to normalize the value
					 * and account for any typmod.
					 */
B
Bruce Momjian 已提交
2336 2337
					Datum		interval;
					char	   *intervalout;
2338 2339 2340 2341 2342

					interval =
						DirectFunctionCall3(interval_in,
											CStringGetDatum(val),
											ObjectIdGetDatum(InvalidOid),
B
Bruce Momjian 已提交
2343
								   Int32GetDatum(arg->typename->typmod));
2344 2345 2346 2347

					intervalout =
						DatumGetCString(DirectFunctionCall3(interval_out,
															interval,
B
Bruce Momjian 已提交
2348 2349
											ObjectIdGetDatum(InvalidOid),
													 Int32GetDatum(-1)));
2350 2351 2352 2353 2354
					appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
				}
				else
				{
					/*
B
Bruce Momjian 已提交
2355 2356
					 * Plain string literal or identifier.	For quote
					 * mode, quote it if it's not a vanilla identifier.
2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367
					 */
					if (flags & GUC_LIST_QUOTE)
						appendStringInfo(&buf, "%s", quote_identifier(val));
					else
						appendStringInfo(&buf, "%s", val);
				}
				break;
			default:
				elog(ERROR, "flatten_set_variable_args: unexpected input");
				break;
		}
2368
	}
2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390

	return buf.data;
}


/*
 * SET command
 */
void
SetPGVariable(const char *name, List *args, bool is_local)
{
	char	   *argstring = flatten_set_variable_args(name, args);

	/* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
	set_config_option(name,
					  argstring,
					  (superuser() ? PGC_SUSET : PGC_USERSET),
					  PGC_S_SESSION,
					  is_local,
					  true);
}

2391 2392 2393 2394 2395 2396
/*
 * SET command wrapped as a SQL callable function.
 */
Datum
set_config_by_name(PG_FUNCTION_ARGS)
{
B
Bruce Momjian 已提交
2397 2398 2399 2400 2401
	char	   *name;
	char	   *value;
	char	   *new_value;
	bool		is_local;
	text	   *result_text;
2402 2403 2404 2405 2406

	if (PG_ARGISNULL(0))
		elog(ERROR, "SET variable name is required");

	/* Get the GUC variable name */
2407
	name = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(0)));
2408 2409 2410 2411 2412

	/* Get the desired value or set to NULL for a reset request */
	if (PG_ARGISNULL(1))
		value = NULL;
	else
2413
		value = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(1)));
2414 2415

	/*
B
Bruce Momjian 已提交
2416 2417
	 * Get the desired state of is_local. Default to false if provided
	 * value is NULL
2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432
	 */
	if (PG_ARGISNULL(2))
		is_local = false;
	else
		is_local = PG_GETARG_BOOL(2);

	/* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
	set_config_option(name,
					  value,
					  (superuser() ? PGC_SUSET : PGC_USERSET),
					  PGC_S_SESSION,
					  is_local,
					  true);

	/* get the new current value */
2433
	new_value = GetConfigOptionByName(name, NULL);
2434 2435 2436 2437 2438 2439 2440 2441

	/* Convert return string to text */
	result_text = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(new_value)));

	/* return it */
	PG_RETURN_TEXT_P(result_text);
}

2442 2443 2444 2445
/*
 * SHOW command
 */
void
2446
GetPGVariable(const char *name, DestReceiver *dest)
2447 2448
{
	if (strcasecmp(name, "all") == 0)
2449
		ShowAllGUCConfig(dest);
2450
	else
2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480
		ShowGUCConfigOption(name, dest);
}

TupleDesc
GetPGVariableResultDesc(const char *name)
{
	TupleDesc	tupdesc;

	if (strcasecmp(name, "all") == 0)
	{
		/* need a tuple descriptor representing two TEXT columns */
		tupdesc = CreateTemplateTupleDesc(2, false);
		TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
						   TEXTOID, -1, 0, false);
		TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
						   TEXTOID, -1, 0, false);
	}
	else
	{
		const char *varname;

		/* Get the canonical spelling of name */
		(void) GetConfigOptionByName(name, &varname);

		/* need a tuple descriptor representing a single TEXT column */
		tupdesc = CreateTemplateTupleDesc(1, false);
		TupleDescInitEntry(tupdesc, (AttrNumber) 1, (char *) varname,
						   TEXTOID, -1, 0, false);
	}
	return tupdesc;
2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504
}

/*
 * RESET command
 */
void
ResetPGVariable(const char *name)
{
	if (strcasecmp(name, "all") == 0)
		ResetAllOptions();
	else
		set_config_option(name,
						  NULL,
						  (superuser() ? PGC_SUSET : PGC_USERSET),
						  PGC_S_SESSION,
						  false,
						  true);
}


/*
 * SHOW command
 */
void
2505
ShowGUCConfigOption(const char *name, DestReceiver *dest)
2506
{
2507
	TupOutputState *tstate;
B
Bruce Momjian 已提交
2508 2509 2510
	TupleDesc	tupdesc;
	const char *varname;
	char	   *value;
2511

2512 2513 2514
	/* Get the value and canonical spelling of name */
	value = GetConfigOptionByName(name, &varname);

2515
	/* need a tuple descriptor representing a single TEXT column */
2516
	tupdesc = CreateTemplateTupleDesc(1, false);
2517
	TupleDescInitEntry(tupdesc, (AttrNumber) 1, (char *) varname,
2518
					   TEXTOID, -1, 0, false);
2519

2520 2521 2522 2523
	/* prepare for projection of tuples */
	tstate = begin_tup_output_tupdesc(dest, tupdesc);

	/* Send it */
2524
	do_text_output_oneline(tstate, value);
2525 2526

	end_tup_output(tstate);
2527 2528
}

2529 2530 2531
/*
 * SHOW ALL command
 */
2532
void
2533
ShowAllGUCConfig(DestReceiver *dest)
2534 2535
{
	int			i;
2536
	TupOutputState *tstate;
B
Bruce Momjian 已提交
2537 2538
	TupleDesc	tupdesc;
	char	   *values[2];
2539 2540

	/* need a tuple descriptor representing two TEXT columns */
2541
	tupdesc = CreateTemplateTupleDesc(2, false);
2542 2543 2544 2545 2546 2547 2548
	TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
					   TEXTOID, -1, 0, false);
	TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
					   TEXTOID, -1, 0, false);

	/* prepare for projection of tuples */
	tstate = begin_tup_output_tupdesc(dest, tupdesc);
2549

2550 2551
	for (i = 0; i < num_guc_variables; i++)
	{
2552 2553 2554 2555
		struct config_generic *conf = guc_variables[i];

		if (conf->flags & GUC_NO_SHOW_ALL)
			continue;
2556 2557

		/* assign to the values array */
2558 2559
		values[0] = (char *) conf->name;
		values[1] = _ShowOption(conf);
2560 2561 2562

		/* send it to dest */
		do_tup_output(tstate, values);
2563

2564 2565 2566
		/* clean up */
		if (values[1] != NULL)
			pfree(values[1]);
2567
	}
2568 2569

	end_tup_output(tstate);
2570
}
2571

2572
/*
2573 2574
 * Return GUC variable value by name; optionally return canonical
 * form of name.  Return value is palloc'd.
2575 2576
 */
char *
2577
GetConfigOptionByName(const char *name, const char **varname)
2578 2579 2580 2581 2582 2583 2584
{
	struct config_generic *record;

	record = find_option(name);
	if (record == NULL)
		elog(ERROR, "Option '%s' is not recognized", name);

2585 2586 2587
	if (varname)
		*varname = record->name;

2588 2589 2590 2591
	return _ShowOption(record);
}

/*
2592 2593
 * Return GUC variable value by variable number; optionally return canonical
 * form of name.  Return value is palloc'd.
2594 2595
 */
char *
2596
GetConfigOptionByNum(int varnum, const char **varname, bool *noshow)
2597
{
2598 2599 2600 2601 2602 2603
	struct config_generic *conf;

	/* check requested variable number valid */
	Assert((varnum >= 0) && (varnum < num_guc_variables));

	conf = guc_variables[varnum];
2604

2605 2606
	if (varname)
		*varname = conf->name;
2607

2608 2609 2610
	if (noshow)
		*noshow = (conf->flags & GUC_NO_SHOW_ALL) ? true : false;

2611
	return _ShowOption(conf);
2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629
}

/*
 * Return the total number of GUC variables
 */
int
GetNumConfigOptions(void)
{
	return num_guc_variables;
}

/*
 * show_config_by_name - equiv to SHOW X command but implemented as
 * a function.
 */
Datum
show_config_by_name(PG_FUNCTION_ARGS)
{
B
Bruce Momjian 已提交
2630 2631 2632
	char	   *varname;
	char	   *varval;
	text	   *result_text;
2633 2634

	/* Get the GUC variable name */
2635
	varname = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(0)));
2636 2637

	/* Get the value */
2638
	varval = GetConfigOptionByName(varname, NULL);
2639 2640 2641 2642 2643 2644 2645 2646

	/* Convert to text */
	result_text = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(varval)));

	/* return it */
	PG_RETURN_TEXT_P(result_text);
}

2647 2648 2649 2650 2651 2652 2653
/*
 * show_all_settings - equiv to SHOW ALL command but implemented as
 * a Table Function.
 */
Datum
show_all_settings(PG_FUNCTION_ARGS)
{
B
Bruce Momjian 已提交
2654 2655 2656 2657 2658 2659 2660
	FuncCallContext *funcctx;
	TupleDesc	tupdesc;
	int			call_cntr;
	int			max_calls;
	TupleTableSlot *slot;
	AttInMetadata *attinmeta;
	MemoryContext oldcontext;
2661 2662

	/* stuff done only on the first call of the function */
B
Bruce Momjian 已提交
2663 2664
	if (SRF_IS_FIRSTCALL())
	{
2665
		/* create a function context for cross-call persistence */
B
Bruce Momjian 已提交
2666
		funcctx = SRF_FIRSTCALL_INIT();
2667

B
Bruce Momjian 已提交
2668 2669 2670 2671
		/*
		 * switch to memory context appropriate for multiple function
		 * calls
		 */
2672 2673
		oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);

2674
		/* need a tuple descriptor representing two TEXT columns */
2675
		tupdesc = CreateTemplateTupleDesc(2, false);
2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687
		TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
						   TEXTOID, -1, 0, false);
		TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
						   TEXTOID, -1, 0, false);

		/* allocate a slot for a tuple with this tupdesc */
		slot = TupleDescGetSlot(tupdesc);

		/* assign slot to function context */
		funcctx->slot = slot;

		/*
B
Bruce Momjian 已提交
2688 2689
		 * Generate attribute metadata needed later to produce tuples from
		 * raw C strings
2690 2691 2692 2693 2694 2695
		 */
		attinmeta = TupleDescGetAttInMetadata(tupdesc);
		funcctx->attinmeta = attinmeta;

		/* total number of tuples to be returned */
		funcctx->max_calls = GetNumConfigOptions();
2696 2697

		MemoryContextSwitchTo(oldcontext);
B
Bruce Momjian 已提交
2698
	}
2699 2700

	/* stuff done on every call of the function */
B
Bruce Momjian 已提交
2701
	funcctx = SRF_PERCALL_SETUP();
2702 2703 2704 2705 2706 2707

	call_cntr = funcctx->call_cntr;
	max_calls = funcctx->max_calls;
	slot = funcctx->slot;
	attinmeta = funcctx->attinmeta;

B
Bruce Momjian 已提交
2708 2709
	if (call_cntr < max_calls)	/* do when there is more left to send */
	{
2710
		char	   *values[2];
2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721
		char	   *varname;
		char	   *varval;
		bool		noshow;
		HeapTuple	tuple;
		Datum		result;

		/*
		 * Get the next visible GUC variable name and value
		 */
		do
		{
2722 2723 2724
			varval = GetConfigOptionByNum(call_cntr,
										  (const char **) &varname,
										  &noshow);
2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735
			if (noshow)
			{
				/* varval is a palloc'd copy, so free it */
				if (varval != NULL)
					pfree(varval);

				/* bump the counter and get the next config setting */
				call_cntr = ++funcctx->call_cntr;

				/* make sure we haven't gone too far now */
				if (call_cntr >= max_calls)
B
Bruce Momjian 已提交
2736
					SRF_RETURN_DONE(funcctx);
2737 2738 2739 2740
			}
		} while (noshow);

		/*
B
Bruce Momjian 已提交
2741 2742 2743
		 * Prepare a values array for storage in our slot. This should be
		 * an array of C strings which will be processed later by the
		 * appropriate "in" functions.
2744
		 */
2745 2746
		values[0] = varname;
		values[1] = varval;
2747 2748 2749 2750 2751 2752 2753 2754 2755

		/* build a tuple */
		tuple = BuildTupleFromCStrings(attinmeta, values);

		/* make the tuple into a datum */
		result = TupleGetDatum(slot, tuple);

		/* Clean up */
		if (varval != NULL)
2756
			pfree(varval);
2757

B
Bruce Momjian 已提交
2758 2759 2760
		SRF_RETURN_NEXT(funcctx, result);
	}
	else
2761 2762
	{
		/* do when there is no more left */
B
Bruce Momjian 已提交
2763
		SRF_RETURN_DONE(funcctx);
2764
	}
2765 2766
}

2767
static char *
B
Bruce Momjian 已提交
2768
_ShowOption(struct config_generic * record)
2769 2770 2771
{
	char		buffer[256];
	const char *val;
2772

2773 2774 2775 2776 2777
	switch (record->vartype)
	{
		case PGC_BOOL:
			{
				struct config_bool *conf = (struct config_bool *) record;
2778

2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818
				if (conf->show_hook)
					val = (*conf->show_hook) ();
				else
					val = *conf->variable ? "on" : "off";
			}
			break;

		case PGC_INT:
			{
				struct config_int *conf = (struct config_int *) record;

				if (conf->show_hook)
					val = (*conf->show_hook) ();
				else
				{
					snprintf(buffer, sizeof(buffer), "%d",
							 *conf->variable);
					val = buffer;
				}
			}
			break;

		case PGC_REAL:
			{
				struct config_real *conf = (struct config_real *) record;

				if (conf->show_hook)
					val = (*conf->show_hook) ();
				else
				{
					snprintf(buffer, sizeof(buffer), "%g",
							 *conf->variable);
					val = buffer;
				}
			}
			break;

		case PGC_STRING:
			{
				struct config_string *conf = (struct config_string *) record;
2819

2820 2821 2822 2823 2824 2825 2826 2827
				if (conf->show_hook)
					val = (*conf->show_hook) ();
				else if (*conf->variable && **conf->variable)
					val = *conf->variable;
				else
					val = "unset";
			}
			break;
2828

2829 2830 2831 2832 2833
		default:
			/* just to keep compiler quiet */
			val = "???";
			break;
	}
2834

2835
	return pstrdup(val);
2836
}
2837 2838


B
Bruce Momjian 已提交
2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857
#ifdef EXEC_BACKEND
/*
 *	This routine dumps out all non-default GUC options into a binary
 *	file that is read by all exec'ed backends.  The format is:
 *
 *		variable name, string, null terminated
 *		variable value, string, null terminated
 *		variable source, integer
 */
void
write_nondefault_variables(GucContext context)
{
	int i;
	char *new_filename, *filename;
	int elevel;
	FILE *fp;

	Assert(context == PGC_POSTMASTER || context == PGC_SIGHUP);
	Assert(DataDir);
2858
	elevel = (context == PGC_SIGHUP) ? DEBUG4 : ERROR;
B
Bruce Momjian 已提交
2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036

	/*
	 * Open file
	 */
	new_filename = malloc(strlen(DataDir) + strlen(CONFIG_EXEC_PARAMS) +
							strlen(".new") + 2);
	filename = malloc(strlen(DataDir) + strlen(CONFIG_EXEC_PARAMS) + 2);
	if (new_filename == NULL || filename == NULL)
	{
		elog(elevel, "out of memory");
		return;
	}
	sprintf(new_filename, "%s/" CONFIG_EXEC_PARAMS ".new", DataDir);
	sprintf(filename, "%s/" CONFIG_EXEC_PARAMS, DataDir);

    fp = AllocateFile(new_filename, "w");
    if (!fp)
    {
 		free(new_filename);
		free(filename);
		elog(elevel, "could not write exec config params file `"
					CONFIG_EXEC_PARAMS "': %s", strerror(errno));
		return;
	}

	for (i = 0; i < num_guc_variables; i++)
	{
		struct config_generic *gconf = guc_variables[i];

		if (gconf->source != PGC_S_DEFAULT)
		{
			fprintf(fp, "%s", gconf->name);
			fputc(0, fp);

			switch (gconf->vartype)
			{
				case PGC_BOOL:
					{
						struct config_bool *conf = (struct config_bool *) gconf;

						if (*conf->variable == 0)
							fprintf(fp, "false");
						else
							fprintf(fp, "true");
					}
					break;

				case PGC_INT:
					{
						struct config_int *conf = (struct config_int *) gconf;

						fprintf(fp, "%d", *conf->variable);
					}
					break;

				case PGC_REAL:
					{
						struct config_real *conf = (struct config_real *) gconf;

						/* Could lose precision here? */
						fprintf(fp, "%f", *conf->variable);
					}
					break;

				case PGC_STRING:
					{
						struct config_string *conf = (struct config_string *) gconf;

						fprintf(fp, "%s", *conf->variable);
					}
					break;
			}

			fputc(0, fp);

			fwrite(&gconf->source, sizeof(gconf->source), 1, fp);
		}
	}

	FreeFile(fp);
	/* Put new file in place, this could delay on Win32 */
	rename(new_filename, filename);
	free(new_filename);
	free(filename);
	return;
}


/*
 *	Read string, including null byte from file
 *
 *	Return NULL on EOF and nothing read
 */
static char *
read_string_with_null(FILE *fp)
{
	int i = 0, ch, maxlen = 256;
	char *str = NULL;

	do
	{
		if ((ch = fgetc(fp)) == EOF)
		{
			if (i == 0)
				return NULL;
			else
				elog(FATAL, "Invalid format of exec config params file");
		}
		if (i == 0)
			str = malloc(maxlen);
		else if (i == maxlen)
			str = realloc(str, maxlen *= 2);
		str[i++] = ch;
	} while (ch != 0);

	return str;
}


/*
 *	This routine loads a previous postmaster dump of its non-default
 *	settings.
 */
void
read_nondefault_variables(void)
{
	char *filename;
	FILE *fp;
	char *varname, *varvalue;
	int varsource;

	Assert(DataDir);

	/*
	 * Open file
	 */
	filename = malloc(strlen(DataDir) + strlen(CONFIG_EXEC_PARAMS) + 2);
	if (filename == NULL)
	{
		elog(ERROR, "out of memory");
		return;
	}
	sprintf(filename, "%s/" CONFIG_EXEC_PARAMS, DataDir);

    fp = AllocateFile(filename, "r");
    if (!fp)
    {
		free(filename);
        /* File not found is fine */
        if (errno != ENOENT)
            elog(FATAL, "could not read exec config params file `"
					CONFIG_EXEC_PARAMS "': %s", strerror(errno));
		return;
    }

    while (1)
	{
		if ((varname = read_string_with_null(fp)) == NULL)
			break;

		if ((varvalue = read_string_with_null(fp)) == NULL)
			elog(FATAL, "Invalid format of exec config params file");
 		if (fread(&varsource, sizeof(varsource), 1, fp) == 0)
			elog(FATAL, "Invalid format of exec config params file");

		(void) set_config_option(varname, varvalue, PGC_POSTMASTER,
				varsource, false, true);
		free(varname);
		free(varvalue);
	}

	FreeFile(fp);
	free(filename);
	return;
}
#endif


3037 3038 3039 3040 3041 3042 3043 3044
/*
 * A little "long argument" simulation, although not quite GNU
 * compliant. Takes a string of the form "some-option=some value" and
 * returns name = "some_option" and value = "some value" in malloc'ed
 * storage. Note that '-' is converted to '_' in the option name. If
 * there is no '=' in the input string then value will be NULL.
 */
void
B
Bruce Momjian 已提交
3045
ParseLongOption(const char *string, char **name, char **value)
3046
{
B
Bruce Momjian 已提交
3047 3048
	size_t		equal_pos;
	char	   *cp;
3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067

	AssertArg(string);
	AssertArg(name);
	AssertArg(value);

	equal_pos = strcspn(string, "=");

	if (string[equal_pos] == '=')
	{
		*name = malloc(equal_pos + 1);
		if (!*name)
			elog(FATAL, "out of memory");
		strncpy(*name, string, equal_pos);
		(*name)[equal_pos] = '\0';

		*value = strdup(&string[equal_pos + 1]);
		if (!*value)
			elog(FATAL, "out of memory");
	}
B
Bruce Momjian 已提交
3068
	else
3069
	{
3070
		/* no equal sign in string */
3071 3072 3073 3074 3075 3076
		*name = strdup(string);
		if (!*name)
			elog(FATAL, "out of memory");
		*value = NULL;
	}

B
Bruce Momjian 已提交
3077
	for (cp = *name; *cp; cp++)
3078 3079 3080
		if (*cp == '-')
			*cp = '_';
}
3081 3082


3083 3084
/*
 * Handle options fetched from pg_database.datconfig or pg_shadow.useconfig.
3085
 * The array parameter must be an array of TEXT (it must not be NULL).
3086
 */
3087 3088 3089
void
ProcessGUCArray(ArrayType *array, GucSource source)
{
B
Bruce Momjian 已提交
3090
	int			i;
3091

3092
	Assert(array != NULL);
3093 3094 3095
	Assert(ARR_ELEMTYPE(array) == TEXTOID);
	Assert(ARR_NDIM(array) == 1);
	Assert(ARR_LBOUND(array)[0] == 1);
3096
	Assert(source == PGC_S_DATABASE || source == PGC_S_USER);
3097 3098 3099 3100 3101 3102 3103 3104 3105 3106

	for (i = 1; i <= ARR_DIMS(array)[0]; i++)
	{
		Datum		d;
		bool		isnull;
		char	   *s;
		char	   *name;
		char	   *value;

		d = array_ref(array, 1, &i,
B
Bruce Momjian 已提交
3107 3108 3109 3110
					  -1 /* varlenarray */ ,
					  -1 /* TEXT's typlen */ ,
					  false /* TEXT's typbyval */ ,
					  'i' /* TEXT's typalign */ ,
3111 3112 3113 3114 3115 3116
					  &isnull);

		if (isnull)
			continue;

		s = DatumGetCString(DirectFunctionCall1(textout, d));
3117

3118 3119 3120
		ParseLongOption(s, &name, &value);
		if (!value)
		{
3121
			elog(WARNING, "cannot parse setting \"%s\"", name);
3122
			free(name);
B
Bruce Momjian 已提交
3123
			continue;
3124 3125
		}

3126
		/*
B
Bruce Momjian 已提交
3127 3128
		 * We process all these options at SUSET level.  We assume that
		 * the right to insert an option into pg_database or pg_shadow was
3129 3130
		 * checked when it was inserted.
		 */
3131
		SetConfigOption(name, value, PGC_SUSET, source);
3132 3133 3134 3135

		free(name);
		if (value)
			free(value);
3136 3137 3138 3139
	}
}


3140 3141 3142 3143
/*
 * Add an entry to an option array.  The array parameter may be NULL
 * to indicate the current table entry is NULL.
 */
3144 3145 3146
ArrayType *
GUCArrayAdd(ArrayType *array, const char *name, const char *value)
{
3147
	const char *varname;
3148 3149 3150 3151 3152 3153 3154 3155 3156 3157
	Datum		datum;
	char	   *newval;
	ArrayType  *a;

	Assert(name);
	Assert(value);

	/* test if the option is valid */
	set_config_option(name, value,
					  superuser() ? PGC_SUSET : PGC_USERSET,
3158
					  PGC_S_SESSION, false, false);
3159

3160 3161 3162 3163
	/* convert name to canonical spelling, so we can use plain strcmp */
	(void) GetConfigOptionByName(name, &varname);
	name = varname;

3164 3165 3166
	newval = palloc(strlen(name) + 1 + strlen(value) + 1);
	sprintf(newval, "%s=%s", name, value);
	datum = DirectFunctionCall1(textin, CStringGetDatum(newval));
B
Bruce Momjian 已提交
3167

3168 3169
	if (array)
	{
B
Bruce Momjian 已提交
3170 3171 3172
		int			index;
		bool		isnull;
		int			i;
3173

3174 3175 3176 3177
		Assert(ARR_ELEMTYPE(array) == TEXTOID);
		Assert(ARR_NDIM(array) == 1);
		Assert(ARR_LBOUND(array)[0] == 1);

B
Bruce Momjian 已提交
3178
		index = ARR_DIMS(array)[0] + 1; /* add after end */
3179 3180 3181 3182 3183 3184 3185

		for (i = 1; i <= ARR_DIMS(array)[0]; i++)
		{
			Datum		d;
			char	   *current;

			d = array_ref(array, 1, &i,
B
Bruce Momjian 已提交
3186 3187 3188 3189
						  -1 /* varlenarray */ ,
						  -1 /* TEXT's typlen */ ,
						  false /* TEXT's typbyval */ ,
						  'i' /* TEXT's typalign */ ,
3190
						  &isnull);
3191 3192
			if (isnull)
				continue;
3193
			current = DatumGetCString(DirectFunctionCall1(textout, d));
B
Bruce Momjian 已提交
3194
			if (strncmp(current, newval, strlen(name) + 1) == 0)
3195 3196 3197 3198 3199 3200 3201
			{
				index = i;
				break;
			}
		}

		isnull = false;
3202 3203
		a = array_set(array, 1, &index,
					  datum,
B
Bruce Momjian 已提交
3204 3205 3206 3207
					  -1 /* varlenarray */ ,
					  -1 /* TEXT's typlen */ ,
					  false /* TEXT's typbyval */ ,
					  'i' /* TEXT's typalign */ ,
3208
					  &isnull);
3209 3210
	}
	else
3211 3212 3213
		a = construct_array(&datum, 1,
							TEXTOID,
							-1, false, 'i');
3214 3215 3216 3217 3218

	return a;
}


3219 3220 3221 3222 3223
/*
 * Delete an entry from an option array.  The array parameter may be NULL
 * to indicate the current table entry is NULL.  Also, if the return value
 * is NULL then a null should be stored.
 */
3224 3225 3226
ArrayType *
GUCArrayDelete(ArrayType *array, const char *name)
{
3227
	const char *varname;
B
Bruce Momjian 已提交
3228 3229 3230
	ArrayType  *newarray;
	int			i;
	int			index;
3231 3232 3233 3234 3235 3236

	Assert(name);

	/* test if the option is valid */
	set_config_option(name, NULL,
					  superuser() ? PGC_SUSET : PGC_USERSET,
3237
					  PGC_S_SESSION, false, false);
3238

3239 3240 3241 3242
	/* convert name to canonical spelling, so we can use plain strcmp */
	(void) GetConfigOptionByName(name, &varname);
	name = varname;

3243 3244 3245 3246 3247
	/* if array is currently null, then surely nothing to delete */
	if (!array)
		return NULL;

	newarray = NULL;
3248 3249 3250 3251 3252 3253 3254 3255 3256
	index = 1;

	for (i = 1; i <= ARR_DIMS(array)[0]; i++)
	{
		Datum		d;
		char	   *val;
		bool		isnull;

		d = array_ref(array, 1, &i,
B
Bruce Momjian 已提交
3257 3258 3259 3260
					  -1 /* varlenarray */ ,
					  -1 /* TEXT's typlen */ ,
					  false /* TEXT's typbyval */ ,
					  'i' /* TEXT's typalign */ ,
3261
					  &isnull);
3262 3263
		if (isnull)
			continue;
3264 3265
		val = DatumGetCString(DirectFunctionCall1(textout, d));

3266
		/* ignore entry if it's what we want to delete */
B
Bruce Momjian 已提交
3267
		if (strncmp(val, name, strlen(name)) == 0
3268 3269 3270
			&& val[strlen(name)] == '=')
			continue;

3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287
		/* else add it to the output array */
		if (newarray)
		{
			isnull = false;
			newarray = array_set(newarray, 1, &index,
								 d,
								 -1 /* varlenarray */ ,
								 -1 /* TEXT's typlen */ ,
								 false /* TEXT's typbyval */ ,
								 'i' /* TEXT's typalign */ ,
								 &isnull);
		}
		else
			newarray = construct_array(&d, 1,
									   TEXTOID,
									   -1, false, 'i');

3288 3289 3290 3291 3292
		index++;
	}

	return newarray;
}
3293

3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343

/*
 * assign_hook subroutines
 */

#ifdef HAVE_SYSLOG

static const char *
assign_facility(const char *facility, bool doit, bool interactive)
{
	if (strcasecmp(facility, "LOCAL0") == 0)
		return facility;
	if (strcasecmp(facility, "LOCAL1") == 0)
		return facility;
	if (strcasecmp(facility, "LOCAL2") == 0)
		return facility;
	if (strcasecmp(facility, "LOCAL3") == 0)
		return facility;
	if (strcasecmp(facility, "LOCAL4") == 0)
		return facility;
	if (strcasecmp(facility, "LOCAL5") == 0)
		return facility;
	if (strcasecmp(facility, "LOCAL6") == 0)
		return facility;
	if (strcasecmp(facility, "LOCAL7") == 0)
		return facility;
	return NULL;
}
#endif


static const char *
assign_defaultxactisolevel(const char *newval, bool doit, bool interactive)
{
	if (strcasecmp(newval, "serializable") == 0)
	{
		if (doit)
			DefaultXactIsoLevel = XACT_SERIALIZABLE;
	}
	else if (strcasecmp(newval, "read committed") == 0)
	{
		if (doit)
			DefaultXactIsoLevel = XACT_READ_COMMITTED;
	}
	else
		return NULL;
	return newval;
}

static const char *
3344
assign_log_min_messages(const char *newval,
3345 3346
						   bool doit, bool interactive)
{
3347
	return (assign_msglvl(&log_min_messages, newval, doit, interactive));
3348 3349
}

3350
static const char *
3351 3352 3353
assign_client_min_messages(const char *newval,
						   bool doit, bool interactive)
{
B
Bruce Momjian 已提交
3354
	return (assign_msglvl(&client_min_messages, newval, doit, interactive));
3355 3356
}

3357
static const char *
3358 3359
assign_min_error_statement(const char *newval, bool doit, bool interactive)
{
B
Bruce Momjian 已提交
3360
	return (assign_msglvl(&log_min_error_statement, newval, doit, interactive));
3361 3362 3363 3364 3365 3366
}

static const char *
assign_msglvl(int *var, const char *newval, bool doit, bool interactive)
{
	if (strcasecmp(newval, "debug") == 0)
B
Bruce Momjian 已提交
3367 3368
	{
		if (doit)
3369
			(*var) = DEBUG2;
B
Bruce Momjian 已提交
3370
	}
3371
	else if (strcasecmp(newval, "debug5") == 0)
B
Bruce Momjian 已提交
3372 3373 3374 3375
	{
		if (doit)
			(*var) = DEBUG5;
	}
3376
	else if (strcasecmp(newval, "debug4") == 0)
B
Bruce Momjian 已提交
3377 3378 3379 3380
	{
		if (doit)
			(*var) = DEBUG4;
	}
3381
	else if (strcasecmp(newval, "debug3") == 0)
B
Bruce Momjian 已提交
3382 3383 3384 3385
	{
		if (doit)
			(*var) = DEBUG3;
	}
3386
	else if (strcasecmp(newval, "debug2") == 0)
B
Bruce Momjian 已提交
3387 3388 3389 3390
	{
		if (doit)
			(*var) = DEBUG2;
	}
3391
	else if (strcasecmp(newval, "debug1") == 0)
B
Bruce Momjian 已提交
3392 3393 3394 3395
	{
		if (doit)
			(*var) = DEBUG1;
	}
3396
	else if (strcasecmp(newval, "log") == 0)
B
Bruce Momjian 已提交
3397 3398 3399 3400
	{
		if (doit)
			(*var) = LOG;
	}
3401
	else if (strcasecmp(newval, "info") == 0)
B
Bruce Momjian 已提交
3402 3403 3404 3405
	{
		if (doit)
			(*var) = INFO;
	}
3406
	else if (strcasecmp(newval, "notice") == 0)
B
Bruce Momjian 已提交
3407 3408 3409 3410
	{
		if (doit)
			(*var) = NOTICE;
	}
3411
	else if (strcasecmp(newval, "warning") == 0)
B
Bruce Momjian 已提交
3412 3413 3414 3415
	{
		if (doit)
			(*var) = WARNING;
	}
3416
	else if (strcasecmp(newval, "error") == 0)
B
Bruce Momjian 已提交
3417 3418 3419 3420
	{
		if (doit)
			(*var) = ERROR;
	}
3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431
	/* We allow FATAL/PANIC for client-side messages too. */
	else if (strcasecmp(newval, "fatal") == 0)
	{
		if (doit)
			(*var) = FATAL;
	}
	else if (strcasecmp(newval, "panic") == 0)
	{
		if (doit)
			(*var) = PANIC;
	}
3432 3433 3434 3435
	else
		return NULL;			/* fail */
	return newval;				/* OK */
}
3436

3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448
static bool
assign_phony_autocommit(bool newval, bool doit, bool interactive)
{
	if (!newval)
	{
		if (doit && interactive)
			elog(ERROR, "SET AUTOCOMMIT TO OFF is no longer supported");
		return false;
	}
	return true;
}

3449

3450
#include "guc-file.c"
B
Bruce Momjian 已提交
3451