1 /*--------------------------------------------------------------------
4 * Support for grand unified configuration scheme, including SET
5 * command, configuration file, and command line options.
6 * See src/backend/utils/misc/README for more information.
9 * Copyright (c) 2000-2014, PostgreSQL Global Development Group
10 * Written by Peter Eisentraut <peter_e@gmx.net>.
13 * src/backend/utils/misc/guc.c
15 *--------------------------------------------------------------------
29 #include "access/gin.h"
30 #include "access/transam.h"
31 #include "access/twophase.h"
32 #include "access/xact.h"
33 #include "catalog/namespace.h"
34 #include "commands/async.h"
35 #include "commands/prepare.h"
36 #include "commands/vacuum.h"
37 #include "commands/variable.h"
38 #include "commands/trigger.h"
40 #include "libpq/auth.h"
41 #include "libpq/be-fsstubs.h"
42 #include "libpq/libpq.h"
43 #include "libpq/pqformat.h"
44 #include "miscadmin.h"
45 #include "optimizer/cost.h"
46 #include "optimizer/geqo.h"
47 #include "optimizer/paths.h"
48 #include "optimizer/planmain.h"
49 #include "parser/parse_expr.h"
50 #include "parser/parse_type.h"
51 #include "parser/parser.h"
52 #include "parser/scansup.h"
54 #include "postmaster/autovacuum.h"
55 #include "postmaster/bgworker.h"
56 #include "postmaster/bgwriter.h"
57 #include "postmaster/postmaster.h"
58 #include "postmaster/syslogger.h"
59 #include "postmaster/walwriter.h"
60 #include "replication/slot.h"
61 #include "replication/syncrep.h"
62 #include "replication/walreceiver.h"
63 #include "replication/walsender.h"
64 #include "storage/bufmgr.h"
65 #include "storage/dsm_impl.h"
66 #include "storage/standby.h"
67 #include "storage/fd.h"
68 #include "storage/pg_shmem.h"
69 #include "storage/proc.h"
70 #include "storage/predicate.h"
71 #include "tcop/tcopprot.h"
72 #include "tsearch/ts_cache.h"
73 #include "utils/builtins.h"
74 #include "utils/bytea.h"
75 #include "utils/guc_tables.h"
76 #include "utils/memutils.h"
77 #include "utils/pg_locale.h"
78 #include "utils/plancache.h"
79 #include "utils/portal.h"
80 #include "utils/ps_status.h"
81 #include "utils/snapmgr.h"
82 #include "utils/tzparser.h"
83 #include "utils/xml.h"
86 #define PG_KRB_SRVTAB ""
89 #define CONFIG_FILENAME "postgresql.conf"
90 #define HBA_FILENAME "pg_hba.conf"
91 #define IDENT_FILENAME "pg_ident.conf"
94 #define CONFIG_EXEC_PARAMS "global/config_exec_params"
95 #define CONFIG_EXEC_PARAMS_NEW "global/config_exec_params.new"
98 /* upper limit for GUC variables measured in kilobytes of memory */
99 /* note that various places assume the byte size fits in a "long" variable */
100 #if SIZEOF_SIZE_T > 4 && SIZEOF_LONG > 4
101 #define MAX_KILOBYTES INT_MAX
103 #define MAX_KILOBYTES (INT_MAX / 1024)
106 #define KB_PER_MB (1024)
107 #define KB_PER_GB (1024*1024)
108 #define KB_PER_TB (1024*1024*1024)
110 #define MS_PER_S 1000
112 #define MS_PER_MIN (1000 * 60)
114 #define S_PER_H (60 * 60)
115 #define MS_PER_H (1000 * 60 * 60)
116 #define MIN_PER_D (60 * 24)
117 #define S_PER_D (60 * 60 * 24)
118 #define MS_PER_D (1000 * 60 * 60 * 24)
120 /* XXX these should appear in other modules' header files */
121 extern bool Log_disconnections;
122 extern int CommitDelay;
123 extern int CommitSiblings;
124 extern char *default_tablespace;
125 extern char *temp_tablespaces;
126 extern bool ignore_checksum_failure;
127 extern bool synchronize_seqscans;
128 extern char *SSLCipherSuites;
129 extern char *SSLECDHCurve;
130 extern bool SSLPreferServerCiphers;
133 extern bool trace_sort;
135 #ifdef TRACE_SYNCSCAN
136 extern bool trace_syncscan;
138 #ifdef DEBUG_BOUNDED_SORT
139 extern bool optimize_bounded_sort;
142 static int GUC_check_errcode_value;
144 /* global variables for check hook support */
145 char *GUC_check_errmsg_string;
146 char *GUC_check_errdetail_string;
147 char *GUC_check_errhint_string;
150 static void set_config_sourcefile(const char *name, char *sourcefile,
152 static bool call_bool_check_hook(struct config_bool * conf, bool *newval,
153 void **extra, GucSource source, int elevel);
154 static bool call_int_check_hook(struct config_int * conf, int *newval,
155 void **extra, GucSource source, int elevel);
156 static bool call_real_check_hook(struct config_real * conf, double *newval,
157 void **extra, GucSource source, int elevel);
158 static bool call_string_check_hook(struct config_string * conf, char **newval,
159 void **extra, GucSource source, int elevel);
160 static bool call_enum_check_hook(struct config_enum * conf, int *newval,
161 void **extra, GucSource source, int elevel);
163 static bool check_log_destination(char **newval, void **extra, GucSource source);
164 static void assign_log_destination(const char *newval, void *extra);
167 static int syslog_facility = LOG_LOCAL0;
169 static int syslog_facility = 0;
172 static void assign_syslog_facility(int newval, void *extra);
173 static void assign_syslog_ident(const char *newval, void *extra);
174 static void assign_session_replication_role(int newval, void *extra);
175 static bool check_temp_buffers(int *newval, void **extra, GucSource source);
176 static bool check_phony_autocommit(bool *newval, void **extra, GucSource source);
177 static bool check_debug_assertions(bool *newval, void **extra, GucSource source);
178 static bool check_bonjour(bool *newval, void **extra, GucSource source);
179 static bool check_ssl(bool *newval, void **extra, GucSource source);
180 static bool check_stage_log_stats(bool *newval, void **extra, GucSource source);
181 static bool check_log_stats(bool *newval, void **extra, GucSource source);
182 static bool check_canonical_path(char **newval, void **extra, GucSource source);
183 static bool check_timezone_abbreviations(char **newval, void **extra, GucSource source);
184 static void assign_timezone_abbreviations(const char *newval, void *extra);
185 static void pg_timezone_abbrev_initialize(void);
186 static const char *show_archive_command(void);
187 static void assign_tcp_keepalives_idle(int newval, void *extra);
188 static void assign_tcp_keepalives_interval(int newval, void *extra);
189 static void assign_tcp_keepalives_count(int newval, void *extra);
190 static const char *show_tcp_keepalives_idle(void);
191 static const char *show_tcp_keepalives_interval(void);
192 static const char *show_tcp_keepalives_count(void);
193 static bool check_maxconnections(int *newval, void **extra, GucSource source);
194 static bool check_max_worker_processes(int *newval, void **extra, GucSource source);
195 static bool check_autovacuum_max_workers(int *newval, void **extra, GucSource source);
196 static bool check_autovacuum_work_mem(int *newval, void **extra, GucSource source);
197 static bool check_effective_io_concurrency(int *newval, void **extra, GucSource source);
198 static void assign_effective_io_concurrency(int newval, void *extra);
199 static void assign_pgstat_temp_directory(const char *newval, void *extra);
200 static bool check_application_name(char **newval, void **extra, GucSource source);
201 static void assign_application_name(const char *newval, void *extra);
202 static const char *show_unix_socket_permissions(void);
203 static const char *show_log_file_mode(void);
205 static char *config_enum_get_options(struct config_enum * record,
206 const char *prefix, const char *suffix,
207 const char *separator);
209 static bool validate_conf_option(struct config_generic * record,
210 const char *name, const char *value, GucSource source,
211 int elevel, bool freemem, void *newval, void **newextra);
215 * Options for enum values defined in this module.
217 * NOTE! Option values may not contain double quotes!
220 static const struct config_enum_entry bytea_output_options[] = {
221 {"escape", BYTEA_OUTPUT_ESCAPE, false},
222 {"hex", BYTEA_OUTPUT_HEX, false},
227 * We have different sets for client and server message level options because
228 * they sort slightly different (see "log" level)
230 static const struct config_enum_entry client_message_level_options[] = {
231 {"debug", DEBUG2, true},
232 {"debug5", DEBUG5, false},
233 {"debug4", DEBUG4, false},
234 {"debug3", DEBUG3, false},
235 {"debug2", DEBUG2, false},
236 {"debug1", DEBUG1, false},
238 {"info", INFO, true},
239 {"notice", NOTICE, false},
240 {"warning", WARNING, false},
241 {"error", ERROR, false},
242 {"fatal", FATAL, true},
243 {"panic", PANIC, true},
247 static const struct config_enum_entry server_message_level_options[] = {
248 {"debug", DEBUG2, true},
249 {"debug5", DEBUG5, false},
250 {"debug4", DEBUG4, false},
251 {"debug3", DEBUG3, false},
252 {"debug2", DEBUG2, false},
253 {"debug1", DEBUG1, false},
254 {"info", INFO, false},
255 {"notice", NOTICE, false},
256 {"warning", WARNING, false},
257 {"error", ERROR, false},
259 {"fatal", FATAL, false},
260 {"panic", PANIC, false},
264 static const struct config_enum_entry intervalstyle_options[] = {
265 {"postgres", INTSTYLE_POSTGRES, false},
266 {"postgres_verbose", INTSTYLE_POSTGRES_VERBOSE, false},
267 {"sql_standard", INTSTYLE_SQL_STANDARD, false},
268 {"iso_8601", INTSTYLE_ISO_8601, false},
272 static const struct config_enum_entry log_error_verbosity_options[] = {
273 {"terse", PGERROR_TERSE, false},
274 {"default", PGERROR_DEFAULT, false},
275 {"verbose", PGERROR_VERBOSE, false},
279 static const struct config_enum_entry log_statement_options[] = {
280 {"none", LOGSTMT_NONE, false},
281 {"ddl", LOGSTMT_DDL, false},
282 {"mod", LOGSTMT_MOD, false},
283 {"all", LOGSTMT_ALL, false},
287 static const struct config_enum_entry isolation_level_options[] = {
288 {"serializable", XACT_SERIALIZABLE, false},
289 {"repeatable read", XACT_REPEATABLE_READ, false},
290 {"read committed", XACT_READ_COMMITTED, false},
291 {"read uncommitted", XACT_READ_UNCOMMITTED, false},
295 static const struct config_enum_entry session_replication_role_options[] = {
296 {"origin", SESSION_REPLICATION_ROLE_ORIGIN, false},
297 {"replica", SESSION_REPLICATION_ROLE_REPLICA, false},
298 {"local", SESSION_REPLICATION_ROLE_LOCAL, false},
302 static const struct config_enum_entry syslog_facility_options[] = {
304 {"local0", LOG_LOCAL0, false},
305 {"local1", LOG_LOCAL1, false},
306 {"local2", LOG_LOCAL2, false},
307 {"local3", LOG_LOCAL3, false},
308 {"local4", LOG_LOCAL4, false},
309 {"local5", LOG_LOCAL5, false},
310 {"local6", LOG_LOCAL6, false},
311 {"local7", LOG_LOCAL7, false},
318 static const struct config_enum_entry track_function_options[] = {
319 {"none", TRACK_FUNC_OFF, false},
320 {"pl", TRACK_FUNC_PL, false},
321 {"all", TRACK_FUNC_ALL, false},
325 static const struct config_enum_entry xmlbinary_options[] = {
326 {"base64", XMLBINARY_BASE64, false},
327 {"hex", XMLBINARY_HEX, false},
331 static const struct config_enum_entry xmloption_options[] = {
332 {"content", XMLOPTION_CONTENT, false},
333 {"document", XMLOPTION_DOCUMENT, false},
338 * Although only "on", "off", and "safe_encoding" are documented, we
339 * accept all the likely variants of "on" and "off".
341 static const struct config_enum_entry backslash_quote_options[] = {
342 {"safe_encoding", BACKSLASH_QUOTE_SAFE_ENCODING, false},
343 {"on", BACKSLASH_QUOTE_ON, false},
344 {"off", BACKSLASH_QUOTE_OFF, false},
345 {"true", BACKSLASH_QUOTE_ON, true},
346 {"false", BACKSLASH_QUOTE_OFF, true},
347 {"yes", BACKSLASH_QUOTE_ON, true},
348 {"no", BACKSLASH_QUOTE_OFF, true},
349 {"1", BACKSLASH_QUOTE_ON, true},
350 {"0", BACKSLASH_QUOTE_OFF, true},
355 * Although only "on", "off", and "partition" are documented, we
356 * accept all the likely variants of "on" and "off".
358 static const struct config_enum_entry constraint_exclusion_options[] = {
359 {"partition", CONSTRAINT_EXCLUSION_PARTITION, false},
360 {"on", CONSTRAINT_EXCLUSION_ON, false},
361 {"off", CONSTRAINT_EXCLUSION_OFF, false},
362 {"true", CONSTRAINT_EXCLUSION_ON, true},
363 {"false", CONSTRAINT_EXCLUSION_OFF, true},
364 {"yes", CONSTRAINT_EXCLUSION_ON, true},
365 {"no", CONSTRAINT_EXCLUSION_OFF, true},
366 {"1", CONSTRAINT_EXCLUSION_ON, true},
367 {"0", CONSTRAINT_EXCLUSION_OFF, true},
372 * Although only "on", "off", "remote_write", and "local" are documented, we
373 * accept all the likely variants of "on" and "off".
375 static const struct config_enum_entry synchronous_commit_options[] = {
376 {"local", SYNCHRONOUS_COMMIT_LOCAL_FLUSH, false},
377 {"remote_write", SYNCHRONOUS_COMMIT_REMOTE_WRITE, false},
378 {"on", SYNCHRONOUS_COMMIT_ON, false},
379 {"off", SYNCHRONOUS_COMMIT_OFF, false},
380 {"true", SYNCHRONOUS_COMMIT_ON, true},
381 {"false", SYNCHRONOUS_COMMIT_OFF, true},
382 {"yes", SYNCHRONOUS_COMMIT_ON, true},
383 {"no", SYNCHRONOUS_COMMIT_OFF, true},
384 {"1", SYNCHRONOUS_COMMIT_ON, true},
385 {"0", SYNCHRONOUS_COMMIT_OFF, true},
390 * Although only "on", "off", "try" are documented, we accept all the likely
391 * variants of "on" and "off".
393 static const struct config_enum_entry huge_pages_options[] = {
394 {"off", HUGE_PAGES_OFF, false},
395 {"on", HUGE_PAGES_ON, false},
396 {"try", HUGE_PAGES_TRY, false},
397 {"true", HUGE_PAGES_ON, true},
398 {"false", HUGE_PAGES_OFF, true},
399 {"yes", HUGE_PAGES_ON, true},
400 {"no", HUGE_PAGES_OFF, true},
401 {"1", HUGE_PAGES_ON, true},
402 {"0", HUGE_PAGES_OFF, true},
407 * Options for enum values stored in other modules
409 extern const struct config_enum_entry wal_level_options[];
410 extern const struct config_enum_entry sync_method_options[];
411 extern const struct config_enum_entry dynamic_shared_memory_options[];
414 * GUC option variables that are exported from this module
416 #ifdef USE_ASSERT_CHECKING
417 bool assert_enabled = true;
419 bool assert_enabled = false;
421 bool log_duration = false;
422 bool Debug_print_plan = false;
423 bool Debug_print_parse = false;
424 bool Debug_print_rewritten = false;
425 bool Debug_pretty_print = true;
427 bool log_parser_stats = false;
428 bool log_planner_stats = false;
429 bool log_executor_stats = false;
430 bool log_statement_stats = false; /* this is sort of all three
432 bool log_btree_build_stats = false;
435 bool check_function_bodies = true;
436 bool default_with_oids = false;
437 bool SQL_inheritance = true;
439 bool Password_encryption = true;
441 int log_min_error_statement = ERROR;
442 int log_min_messages = WARNING;
443 int client_min_messages = NOTICE;
444 int log_min_duration_statement = -1;
445 int log_temp_files = -1;
446 int trace_recovery_messages = LOG;
448 int temp_file_limit = -1;
450 int num_temp_buffers = 1024;
452 char *data_directory;
453 char *ConfigFileName;
456 char *external_pid_file;
458 char *pgstat_temp_directory;
460 char *application_name;
462 int tcp_keepalives_idle;
463 int tcp_keepalives_interval;
464 int tcp_keepalives_count;
467 * This really belongs in pg_shmem.c, but is defined here so that it doesn't
468 * need to be duplicated in all the different implementations of pg_shmem.c.
473 * These variables are all dummies that don't do anything, except in some
474 * cases provide the value for SHOW to display. The real state is elsewhere
475 * and is kept in sync by assign_hooks.
477 static char *syslog_ident_str;
478 static bool phony_autocommit;
479 static bool session_auth_is_superuser;
480 static double phony_random_seed;
481 static char *client_encoding_string;
482 static char *datestyle_string;
483 static char *locale_collate;
484 static char *locale_ctype;
485 static char *server_encoding_string;
486 static char *server_version_string;
487 static int server_version_num;
488 static char *timezone_string;
489 static char *log_timezone_string;
490 static char *timezone_abbreviations_string;
491 static char *XactIsoLevel_string;
492 static char *session_authorization_string;
493 static int max_function_args;
494 static int max_index_keys;
495 static int max_identifier_length;
496 static int block_size;
497 static int segment_size;
498 static int wal_block_size;
499 static bool data_checksums;
500 static int wal_segment_size;
501 static bool integer_datetimes;
502 static int effective_io_concurrency;
504 /* should be static, but commands/variable.c needs to get at this */
509 * Displayable names for context types (enum GucContext)
511 * Note: these strings are deliberately not localized.
513 const char *const GucContext_Names[] =
515 /* PGC_INTERNAL */ "internal",
516 /* PGC_POSTMASTER */ "postmaster",
517 /* PGC_SIGHUP */ "sighup",
518 /* PGC_BACKEND */ "backend",
519 /* PGC_SUSET */ "superuser",
520 /* PGC_USERSET */ "user"
524 * Displayable names for source types (enum GucSource)
526 * Note: these strings are deliberately not localized.
528 const char *const GucSource_Names[] =
530 /* PGC_S_DEFAULT */ "default",
531 /* PGC_S_DYNAMIC_DEFAULT */ "default",
532 /* PGC_S_ENV_VAR */ "environment variable",
533 /* PGC_S_FILE */ "configuration file",
534 /* PGC_S_ARGV */ "command line",
535 /* PGC_S_GLOBAL */ "global",
536 /* PGC_S_DATABASE */ "database",
537 /* PGC_S_USER */ "user",
538 /* PGC_S_DATABASE_USER */ "database user",
539 /* PGC_S_CLIENT */ "client",
540 /* PGC_S_OVERRIDE */ "override",
541 /* PGC_S_INTERACTIVE */ "interactive",
542 /* PGC_S_TEST */ "test",
543 /* PGC_S_SESSION */ "session"
547 * Displayable names for the groupings defined in enum config_group
549 const char *const config_group_names[] =
552 gettext_noop("Ungrouped"),
554 gettext_noop("File Locations"),
556 gettext_noop("Connections and Authentication"),
557 /* CONN_AUTH_SETTINGS */
558 gettext_noop("Connections and Authentication / Connection Settings"),
559 /* CONN_AUTH_SECURITY */
560 gettext_noop("Connections and Authentication / Security and Authentication"),
562 gettext_noop("Resource Usage"),
564 gettext_noop("Resource Usage / Memory"),
566 gettext_noop("Resource Usage / Disk"),
567 /* RESOURCES_KERNEL */
568 gettext_noop("Resource Usage / Kernel Resources"),
569 /* RESOURCES_VACUUM_DELAY */
570 gettext_noop("Resource Usage / Cost-Based Vacuum Delay"),
571 /* RESOURCES_BGWRITER */
572 gettext_noop("Resource Usage / Background Writer"),
573 /* RESOURCES_ASYNCHRONOUS */
574 gettext_noop("Resource Usage / Asynchronous Behavior"),
576 gettext_noop("Write-Ahead Log"),
578 gettext_noop("Write-Ahead Log / Settings"),
579 /* WAL_CHECKPOINTS */
580 gettext_noop("Write-Ahead Log / Checkpoints"),
582 gettext_noop("Write-Ahead Log / Archiving"),
584 gettext_noop("Replication"),
585 /* REPLICATION_SENDING */
586 gettext_noop("Replication / Sending Servers"),
587 /* REPLICATION_MASTER */
588 gettext_noop("Replication / Master Server"),
589 /* REPLICATION_STANDBY */
590 gettext_noop("Replication / Standby Servers"),
592 gettext_noop("Query Tuning"),
593 /* QUERY_TUNING_METHOD */
594 gettext_noop("Query Tuning / Planner Method Configuration"),
595 /* QUERY_TUNING_COST */
596 gettext_noop("Query Tuning / Planner Cost Constants"),
597 /* QUERY_TUNING_GEQO */
598 gettext_noop("Query Tuning / Genetic Query Optimizer"),
599 /* QUERY_TUNING_OTHER */
600 gettext_noop("Query Tuning / Other Planner Options"),
602 gettext_noop("Reporting and Logging"),
604 gettext_noop("Reporting and Logging / Where to Log"),
606 gettext_noop("Reporting and Logging / When to Log"),
608 gettext_noop("Reporting and Logging / What to Log"),
610 gettext_noop("Statistics"),
611 /* STATS_MONITORING */
612 gettext_noop("Statistics / Monitoring"),
613 /* STATS_COLLECTOR */
614 gettext_noop("Statistics / Query and Index Statistics Collector"),
616 gettext_noop("Autovacuum"),
618 gettext_noop("Client Connection Defaults"),
619 /* CLIENT_CONN_STATEMENT */
620 gettext_noop("Client Connection Defaults / Statement Behavior"),
621 /* CLIENT_CONN_LOCALE */
622 gettext_noop("Client Connection Defaults / Locale and Formatting"),
623 /* CLIENT_CONN_PRELOAD */
624 gettext_noop("Client Connection Defaults / Shared Library Preloading"),
625 /* CLIENT_CONN_OTHER */
626 gettext_noop("Client Connection Defaults / Other Defaults"),
627 /* LOCK_MANAGEMENT */
628 gettext_noop("Lock Management"),
630 gettext_noop("Version and Platform Compatibility"),
631 /* COMPAT_OPTIONS_PREVIOUS */
632 gettext_noop("Version and Platform Compatibility / Previous PostgreSQL Versions"),
633 /* COMPAT_OPTIONS_CLIENT */
634 gettext_noop("Version and Platform Compatibility / Other Platforms and Clients"),
636 gettext_noop("Error Handling"),
638 gettext_noop("Preset Options"),
640 gettext_noop("Customized Options"),
641 /* DEVELOPER_OPTIONS */
642 gettext_noop("Developer Options"),
643 /* help_config wants this array to be null-terminated */
648 * Displayable names for GUC variable types (enum config_type)
650 * Note: these strings are deliberately not localized.
652 const char *const config_type_names[] =
654 /* PGC_BOOL */ "bool",
655 /* PGC_INT */ "integer",
656 /* PGC_REAL */ "real",
657 /* PGC_STRING */ "string",
658 /* PGC_ENUM */ "enum"
663 * Contents of GUC tables
665 * See src/backend/utils/misc/README for design notes.
669 * 1. Declare a global variable of type bool, int, double, or char*
670 * and make use of it.
672 * 2. Decide at what times it's safe to set the option. See guc.h for
675 * 3. Decide on a name, a default value, upper and lower bounds (if
678 * 4. Add a record below.
680 * 5. Add it to src/backend/utils/misc/postgresql.conf.sample, if
683 * 6. Don't forget to document the option (at least in config.sgml).
685 * 7. If it's a new GUC_LIST option you must edit pg_dumpall.c to ensure
686 * it is not single quoted at dump time.
690 /******** option records follow ********/
692 static struct config_bool ConfigureNamesBool[] =
695 {"enable_seqscan", PGC_USERSET, QUERY_TUNING_METHOD,
696 gettext_noop("Enables the planner's use of sequential-scan plans."),
704 {"enable_indexscan", PGC_USERSET, QUERY_TUNING_METHOD,
705 gettext_noop("Enables the planner's use of index-scan plans."),
713 {"enable_indexonlyscan", PGC_USERSET, QUERY_TUNING_METHOD,
714 gettext_noop("Enables the planner's use of index-only-scan plans."),
717 &enable_indexonlyscan,
722 {"enable_bitmapscan", PGC_USERSET, QUERY_TUNING_METHOD,
723 gettext_noop("Enables the planner's use of bitmap-scan plans."),
731 {"enable_tidscan", PGC_USERSET, QUERY_TUNING_METHOD,
732 gettext_noop("Enables the planner's use of TID scan plans."),
740 {"enable_sort", PGC_USERSET, QUERY_TUNING_METHOD,
741 gettext_noop("Enables the planner's use of explicit sort steps."),
749 {"enable_hashagg", PGC_USERSET, QUERY_TUNING_METHOD,
750 gettext_noop("Enables the planner's use of hashed aggregation plans."),
758 {"enable_material", PGC_USERSET, QUERY_TUNING_METHOD,
759 gettext_noop("Enables the planner's use of materialization."),
767 {"enable_nestloop", PGC_USERSET, QUERY_TUNING_METHOD,
768 gettext_noop("Enables the planner's use of nested-loop join plans."),
776 {"enable_mergejoin", PGC_USERSET, QUERY_TUNING_METHOD,
777 gettext_noop("Enables the planner's use of merge join plans."),
785 {"enable_hashjoin", PGC_USERSET, QUERY_TUNING_METHOD,
786 gettext_noop("Enables the planner's use of hash join plans."),
794 {"geqo", PGC_USERSET, QUERY_TUNING_GEQO,
795 gettext_noop("Enables genetic query optimization."),
796 gettext_noop("This algorithm attempts to do planning without "
797 "exhaustive searching.")
804 /* Not for general use --- used by SET SESSION AUTHORIZATION */
805 {"is_superuser", PGC_INTERNAL, UNGROUPED,
806 gettext_noop("Shows whether the current user is a superuser."),
808 GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
810 &session_auth_is_superuser,
815 {"bonjour", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
816 gettext_noop("Enables advertising the server via Bonjour."),
821 check_bonjour, NULL, NULL
824 {"ssl", PGC_POSTMASTER, CONN_AUTH_SECURITY,
825 gettext_noop("Enables SSL connections."),
830 check_ssl, NULL, NULL
833 {"ssl_prefer_server_ciphers", PGC_POSTMASTER, CONN_AUTH_SECURITY,
834 gettext_noop("Give priority to server ciphersuite order."),
837 &SSLPreferServerCiphers,
842 {"fsync", PGC_SIGHUP, WAL_SETTINGS,
843 gettext_noop("Forces synchronization of updates to disk."),
844 gettext_noop("The server will use the fsync() system call in several places to make "
845 "sure that updates are physically written to disk. This insures "
846 "that a database cluster will recover to a consistent state after "
847 "an operating system or hardware crash.")
854 {"ignore_checksum_failure", PGC_SUSET, DEVELOPER_OPTIONS,
855 gettext_noop("Continues processing after a checksum failure."),
856 gettext_noop("Detection of a checksum failure normally causes PostgreSQL to "
857 "report an error, aborting the current transaction. Setting "
858 "ignore_checksum_failure to true causes the system to ignore the failure "
859 "(but still report a warning), and continue processing. This "
860 "behavior could cause crashes or other serious problems. Only "
861 "has an effect if checksums are enabled."),
864 &ignore_checksum_failure,
869 {"zero_damaged_pages", PGC_SUSET, DEVELOPER_OPTIONS,
870 gettext_noop("Continues processing past damaged page headers."),
871 gettext_noop("Detection of a damaged page header normally causes PostgreSQL to "
872 "report an error, aborting the current transaction. Setting "
873 "zero_damaged_pages to true causes the system to instead report a "
874 "warning, zero out the damaged page, and continue processing. This "
875 "behavior will destroy data, namely all the rows on the damaged page."),
883 {"full_page_writes", PGC_SIGHUP, WAL_SETTINGS,
884 gettext_noop("Writes full pages to WAL when first modified after a checkpoint."),
885 gettext_noop("A page write in process during an operating system crash might be "
886 "only partially written to disk. During recovery, the row changes "
887 "stored in WAL are not enough to recover. This option writes "
888 "pages when first modified after a checkpoint to WAL so full recovery "
897 {"wal_log_hints", PGC_POSTMASTER, WAL_SETTINGS,
898 gettext_noop("Writes full pages to WAL when first modified after a checkpoint, even for a non-critical modifications"),
907 {"log_checkpoints", PGC_SIGHUP, LOGGING_WHAT,
908 gettext_noop("Logs each checkpoint."),
916 {"log_connections", PGC_BACKEND, LOGGING_WHAT,
917 gettext_noop("Logs each successful connection."),
925 {"log_disconnections", PGC_BACKEND, LOGGING_WHAT,
926 gettext_noop("Logs end of a session, including duration."),
934 {"debug_assertions", PGC_USERSET, DEVELOPER_OPTIONS,
935 gettext_noop("Turns on various assertion checks."),
936 gettext_noop("This is a debugging aid."),
940 #ifdef USE_ASSERT_CHECKING
945 check_debug_assertions, NULL, NULL
949 {"exit_on_error", PGC_USERSET, ERROR_HANDLING_OPTIONS,
950 gettext_noop("Terminate session on any error."),
958 {"restart_after_crash", PGC_SIGHUP, ERROR_HANDLING_OPTIONS,
959 gettext_noop("Reinitialize server after backend crash."),
962 &restart_after_crash,
968 {"log_duration", PGC_SUSET, LOGGING_WHAT,
969 gettext_noop("Logs the duration of each completed SQL statement."),
977 {"debug_print_parse", PGC_USERSET, LOGGING_WHAT,
978 gettext_noop("Logs each query's parse tree."),
986 {"debug_print_rewritten", PGC_USERSET, LOGGING_WHAT,
987 gettext_noop("Logs each query's rewritten parse tree."),
990 &Debug_print_rewritten,
995 {"debug_print_plan", PGC_USERSET, LOGGING_WHAT,
996 gettext_noop("Logs each query's execution plan."),
1004 {"debug_pretty_print", PGC_USERSET, LOGGING_WHAT,
1005 gettext_noop("Indents parse and plan tree displays."),
1008 &Debug_pretty_print,
1013 {"log_parser_stats", PGC_SUSET, STATS_MONITORING,
1014 gettext_noop("Writes parser performance statistics to the server log."),
1019 check_stage_log_stats, NULL, NULL
1022 {"log_planner_stats", PGC_SUSET, STATS_MONITORING,
1023 gettext_noop("Writes planner performance statistics to the server log."),
1028 check_stage_log_stats, NULL, NULL
1031 {"log_executor_stats", PGC_SUSET, STATS_MONITORING,
1032 gettext_noop("Writes executor performance statistics to the server log."),
1035 &log_executor_stats,
1037 check_stage_log_stats, NULL, NULL
1040 {"log_statement_stats", PGC_SUSET, STATS_MONITORING,
1041 gettext_noop("Writes cumulative performance statistics to the server log."),
1044 &log_statement_stats,
1046 check_log_stats, NULL, NULL
1048 #ifdef BTREE_BUILD_STATS
1050 {"log_btree_build_stats", PGC_SUSET, DEVELOPER_OPTIONS,
1051 gettext_noop("Logs system resource usage statistics (memory and CPU) on various B-tree operations."),
1055 &log_btree_build_stats,
1062 {"track_activities", PGC_SUSET, STATS_COLLECTOR,
1063 gettext_noop("Collects information about executing commands."),
1064 gettext_noop("Enables the collection of information on the currently "
1065 "executing command of each session, along with "
1066 "the time at which that command began execution.")
1068 &pgstat_track_activities,
1073 {"track_counts", PGC_SUSET, STATS_COLLECTOR,
1074 gettext_noop("Collects statistics on database activity."),
1077 &pgstat_track_counts,
1082 {"track_io_timing", PGC_SUSET, STATS_COLLECTOR,
1083 gettext_noop("Collects timing statistics for database I/O activity."),
1092 {"update_process_title", PGC_SUSET, STATS_COLLECTOR,
1093 gettext_noop("Updates the process title to show the active SQL command."),
1094 gettext_noop("Enables updating of the process title every time a new SQL command is received by the server.")
1096 &update_process_title,
1102 {"autovacuum", PGC_SIGHUP, AUTOVACUUM,
1103 gettext_noop("Starts the autovacuum subprocess."),
1106 &autovacuum_start_daemon,
1112 {"trace_notify", PGC_USERSET, DEVELOPER_OPTIONS,
1113 gettext_noop("Generates debugging output for LISTEN and NOTIFY."),
1124 {"trace_locks", PGC_SUSET, DEVELOPER_OPTIONS,
1125 gettext_noop("Emits information about lock usage."),
1134 {"trace_userlocks", PGC_SUSET, DEVELOPER_OPTIONS,
1135 gettext_noop("Emits information about user lock usage."),
1144 {"trace_lwlocks", PGC_SUSET, DEVELOPER_OPTIONS,
1145 gettext_noop("Emits information about lightweight lock usage."),
1154 {"debug_deadlocks", PGC_SUSET, DEVELOPER_OPTIONS,
1155 gettext_noop("Dumps information about all current locks when a deadlock timeout occurs."),
1166 {"log_lock_waits", PGC_SUSET, LOGGING_WHAT,
1167 gettext_noop("Logs long lock waits."),
1176 {"log_hostname", PGC_SIGHUP, LOGGING_WHAT,
1177 gettext_noop("Logs the host name in the connection logs."),
1178 gettext_noop("By default, connection logs only show the IP address "
1179 "of the connecting host. If you want them to show the host name you "
1180 "can turn this on, but depending on your host name resolution "
1181 "setup it might impose a non-negligible performance penalty.")
1188 {"sql_inheritance", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1189 gettext_noop("Causes subtables to be included by default in various commands."),
1197 {"password_encryption", PGC_USERSET, CONN_AUTH_SECURITY,
1198 gettext_noop("Encrypt passwords."),
1199 gettext_noop("When a password is specified in CREATE USER or "
1200 "ALTER USER without writing either ENCRYPTED or UNENCRYPTED, "
1201 "this parameter determines whether the password is to be encrypted.")
1203 &Password_encryption,
1208 {"transform_null_equals", PGC_USERSET, COMPAT_OPTIONS_CLIENT,
1209 gettext_noop("Treats \"expr=NULL\" as \"expr IS NULL\"."),
1210 gettext_noop("When turned on, expressions of the form expr = NULL "
1211 "(or NULL = expr) are treated as expr IS NULL, that is, they "
1212 "return true if expr evaluates to the null value, and false "
1213 "otherwise. The correct behavior of expr = NULL is to always "
1214 "return null (unknown).")
1216 &Transform_null_equals,
1221 {"db_user_namespace", PGC_SIGHUP, CONN_AUTH_SECURITY,
1222 gettext_noop("Enables per-database user names."),
1230 /* only here for backwards compatibility */
1231 {"autocommit", PGC_USERSET, CLIENT_CONN_STATEMENT,
1232 gettext_noop("This parameter doesn't do anything."),
1233 gettext_noop("It's just here so that we won't choke on SET AUTOCOMMIT TO ON from 7.3-vintage clients."),
1234 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
1238 check_phony_autocommit, NULL, NULL
1241 {"default_transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
1242 gettext_noop("Sets the default read-only status of new transactions."),
1245 &DefaultXactReadOnly,
1250 {"transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
1251 gettext_noop("Sets the current transaction's read-only status."),
1253 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1257 check_transaction_read_only, NULL, NULL
1260 {"default_transaction_deferrable", PGC_USERSET, CLIENT_CONN_STATEMENT,
1261 gettext_noop("Sets the default deferrable status of new transactions."),
1264 &DefaultXactDeferrable,
1269 {"transaction_deferrable", PGC_USERSET, CLIENT_CONN_STATEMENT,
1270 gettext_noop("Whether to defer a read-only serializable transaction until it can be executed with no possible serialization failures."),
1272 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1276 check_transaction_deferrable, NULL, NULL
1279 {"check_function_bodies", PGC_USERSET, CLIENT_CONN_STATEMENT,
1280 gettext_noop("Check function bodies during CREATE FUNCTION."),
1283 &check_function_bodies,
1288 {"array_nulls", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1289 gettext_noop("Enable input of NULL elements in arrays."),
1290 gettext_noop("When turned on, unquoted NULL in an array input "
1291 "value means a null value; "
1292 "otherwise it is taken literally.")
1299 {"default_with_oids", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1300 gettext_noop("Create new tables with OIDs by default."),
1308 {"logging_collector", PGC_POSTMASTER, LOGGING_WHERE,
1309 gettext_noop("Start a subprocess to capture stderr output and/or csvlogs into log files."),
1317 {"log_truncate_on_rotation", PGC_SIGHUP, LOGGING_WHERE,
1318 gettext_noop("Truncate existing log files of same name during log rotation."),
1321 &Log_truncate_on_rotation,
1328 {"trace_sort", PGC_USERSET, DEVELOPER_OPTIONS,
1329 gettext_noop("Emit information about resource usage in sorting."),
1339 #ifdef TRACE_SYNCSCAN
1340 /* this is undocumented because not exposed in a standard build */
1342 {"trace_syncscan", PGC_USERSET, DEVELOPER_OPTIONS,
1343 gettext_noop("Generate debugging output for synchronized scanning."),
1353 #ifdef DEBUG_BOUNDED_SORT
1354 /* this is undocumented because not exposed in a standard build */
1357 "optimize_bounded_sort", PGC_USERSET, QUERY_TUNING_METHOD,
1358 gettext_noop("Enable bounded sorting using heap sort."),
1362 &optimize_bounded_sort,
1370 {"wal_debug", PGC_SUSET, DEVELOPER_OPTIONS,
1371 gettext_noop("Emit WAL-related debugging output."),
1382 {"integer_datetimes", PGC_INTERNAL, PRESET_OPTIONS,
1383 gettext_noop("Datetimes are integer based."),
1385 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1388 #ifdef HAVE_INT64_TIMESTAMP
1397 {"krb_caseins_users", PGC_SIGHUP, CONN_AUTH_SECURITY,
1398 gettext_noop("Sets whether Kerberos and GSSAPI user names should be treated as case-insensitive."),
1401 &pg_krb_caseins_users,
1407 {"escape_string_warning", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1408 gettext_noop("Warn about backslash escapes in ordinary string literals."),
1411 &escape_string_warning,
1417 {"standard_conforming_strings", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1418 gettext_noop("Causes '...' strings to treat backslashes literally."),
1422 &standard_conforming_strings,
1428 {"synchronize_seqscans", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1429 gettext_noop("Enable synchronized sequential scans."),
1432 &synchronize_seqscans,
1438 {"archive_mode", PGC_POSTMASTER, WAL_ARCHIVING,
1439 gettext_noop("Allows archiving of WAL files using archive_command."),
1448 {"hot_standby", PGC_POSTMASTER, REPLICATION_STANDBY,
1449 gettext_noop("Allows connections and queries during recovery."),
1458 {"hot_standby_feedback", PGC_SIGHUP, REPLICATION_STANDBY,
1459 gettext_noop("Allows feedback from a hot standby to the primary that will avoid query conflicts."),
1462 &hot_standby_feedback,
1468 {"allow_system_table_mods", PGC_POSTMASTER, DEVELOPER_OPTIONS,
1469 gettext_noop("Allows modifications of the structure of system tables."),
1473 &allowSystemTableMods,
1479 {"ignore_system_indexes", PGC_BACKEND, DEVELOPER_OPTIONS,
1480 gettext_noop("Disables reading from system indexes."),
1481 gettext_noop("It does not prevent updating the indexes, so it is safe "
1482 "to use. The worst consequence is slowness."),
1485 &IgnoreSystemIndexes,
1491 {"lo_compat_privileges", PGC_SUSET, COMPAT_OPTIONS_PREVIOUS,
1492 gettext_noop("Enables backward compatibility mode for privilege checks on large objects."),
1493 gettext_noop("Skips privilege checks when reading or modifying large objects, "
1494 "for compatibility with PostgreSQL releases prior to 9.0.")
1496 &lo_compat_privileges,
1502 {"quote_all_identifiers", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1503 gettext_noop("When generating SQL fragments, quote all identifiers."),
1506 "e_all_identifiers,
1512 {"data_checksums", PGC_INTERNAL, PRESET_OPTIONS,
1513 gettext_noop("Shows whether data checksums are turned on for this cluster."),
1515 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1522 /* End-of-list marker */
1524 {NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL, NULL
1529 static struct config_int ConfigureNamesInt[] =
1532 {"archive_timeout", PGC_SIGHUP, WAL_ARCHIVING,
1533 gettext_noop("Forces a switch to the next xlog file if a "
1534 "new file has not been started within N seconds."),
1538 &XLogArchiveTimeout,
1543 {"post_auth_delay", PGC_BACKEND, DEVELOPER_OPTIONS,
1544 gettext_noop("Waits N seconds on connection startup after authentication."),
1545 gettext_noop("This allows attaching a debugger to the process."),
1546 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1549 0, 0, INT_MAX / 1000000,
1553 {"default_statistics_target", PGC_USERSET, QUERY_TUNING_OTHER,
1554 gettext_noop("Sets the default statistics target."),
1555 gettext_noop("This applies to table columns that have not had a "
1556 "column-specific target set via ALTER TABLE SET STATISTICS.")
1558 &default_statistics_target,
1563 {"from_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1564 gettext_noop("Sets the FROM-list size beyond which subqueries "
1565 "are not collapsed."),
1566 gettext_noop("The planner will merge subqueries into upper "
1567 "queries if the resulting FROM list would have no more than "
1570 &from_collapse_limit,
1575 {"join_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1576 gettext_noop("Sets the FROM-list size beyond which JOIN "
1577 "constructs are not flattened."),
1578 gettext_noop("The planner will flatten explicit JOIN "
1579 "constructs into lists of FROM items whenever a "
1580 "list of no more than this many items would result.")
1582 &join_collapse_limit,
1587 {"geqo_threshold", PGC_USERSET, QUERY_TUNING_GEQO,
1588 gettext_noop("Sets the threshold of FROM items beyond which GEQO is used."),
1596 {"geqo_effort", PGC_USERSET, QUERY_TUNING_GEQO,
1597 gettext_noop("GEQO: effort is used to set the default for other GEQO parameters."),
1601 DEFAULT_GEQO_EFFORT, MIN_GEQO_EFFORT, MAX_GEQO_EFFORT,
1605 {"geqo_pool_size", PGC_USERSET, QUERY_TUNING_GEQO,
1606 gettext_noop("GEQO: number of individuals in the population."),
1607 gettext_noop("Zero selects a suitable default value.")
1614 {"geqo_generations", PGC_USERSET, QUERY_TUNING_GEQO,
1615 gettext_noop("GEQO: number of iterations of the algorithm."),
1616 gettext_noop("Zero selects a suitable default value.")
1624 /* This is PGC_SUSET to prevent hiding from log_lock_waits. */
1625 {"deadlock_timeout", PGC_SUSET, LOCK_MANAGEMENT,
1626 gettext_noop("Sets the time to wait on a lock before checking for deadlock."),
1636 {"max_standby_archive_delay", PGC_SIGHUP, REPLICATION_STANDBY,
1637 gettext_noop("Sets the maximum delay before canceling queries when a hot standby server is processing archived WAL data."),
1641 &max_standby_archive_delay,
1642 30 * 1000, -1, INT_MAX,
1647 {"max_standby_streaming_delay", PGC_SIGHUP, REPLICATION_STANDBY,
1648 gettext_noop("Sets the maximum delay before canceling queries when a hot standby server is processing streamed WAL data."),
1652 &max_standby_streaming_delay,
1653 30 * 1000, -1, INT_MAX,
1658 {"wal_receiver_status_interval", PGC_SIGHUP, REPLICATION_STANDBY,
1659 gettext_noop("Sets the maximum interval between WAL receiver status reports to the primary."),
1663 &wal_receiver_status_interval,
1664 10, 0, INT_MAX / 1000,
1669 {"wal_receiver_timeout", PGC_SIGHUP, REPLICATION_STANDBY,
1670 gettext_noop("Sets the maximum wait time to receive data from the primary."),
1674 &wal_receiver_timeout,
1675 60 * 1000, 0, INT_MAX,
1680 {"max_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1681 gettext_noop("Sets the maximum number of concurrent connections."),
1685 100, 1, MAX_BACKENDS,
1686 check_maxconnections, NULL, NULL
1690 {"superuser_reserved_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1691 gettext_noop("Sets the number of connection slots reserved for superusers."),
1700 * We sometimes multiply the number of shared buffers by two without
1701 * checking for overflow, so we mustn't allow more than INT_MAX / 2.
1704 {"shared_buffers", PGC_POSTMASTER, RESOURCES_MEM,
1705 gettext_noop("Sets the number of shared memory buffers used by the server."),
1710 1024, 16, INT_MAX / 2,
1715 {"temp_buffers", PGC_USERSET, RESOURCES_MEM,
1716 gettext_noop("Sets the maximum number of temporary buffers used by each session."),
1721 1024, 100, INT_MAX / 2,
1722 check_temp_buffers, NULL, NULL
1726 {"port", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1727 gettext_noop("Sets the TCP port the server listens on."),
1731 DEF_PGPORT, 1, 65535,
1736 {"unix_socket_permissions", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1737 gettext_noop("Sets the access permissions of the Unix-domain socket."),
1738 gettext_noop("Unix-domain sockets use the usual Unix file system "
1739 "permission set. The parameter value is expected "
1740 "to be a numeric mode specification in the form "
1741 "accepted by the chmod and umask system calls. "
1742 "(To use the customary octal format the number must "
1743 "start with a 0 (zero).)")
1745 &Unix_socket_permissions,
1747 NULL, NULL, show_unix_socket_permissions
1751 {"log_file_mode", PGC_SIGHUP, LOGGING_WHERE,
1752 gettext_noop("Sets the file permissions for log files."),
1753 gettext_noop("The parameter value is expected "
1754 "to be a numeric mode specification in the form "
1755 "accepted by the chmod and umask system calls. "
1756 "(To use the customary octal format the number must "
1757 "start with a 0 (zero).)")
1761 NULL, NULL, show_log_file_mode
1765 {"work_mem", PGC_USERSET, RESOURCES_MEM,
1766 gettext_noop("Sets the maximum memory to be used for query workspaces."),
1767 gettext_noop("This much memory can be used by each internal "
1768 "sort operation and hash table before switching to "
1769 "temporary disk files."),
1773 4096, 64, MAX_KILOBYTES,
1778 {"maintenance_work_mem", PGC_USERSET, RESOURCES_MEM,
1779 gettext_noop("Sets the maximum memory to be used for maintenance operations."),
1780 gettext_noop("This includes operations such as VACUUM and CREATE INDEX."),
1783 &maintenance_work_mem,
1784 65536, 1024, MAX_KILOBYTES,
1789 * We use the hopefully-safely-small value of 100kB as the compiled-in
1790 * default for max_stack_depth. InitializeGUCOptions will increase it if
1791 * possible, depending on the actual platform-specific stack limit.
1794 {"max_stack_depth", PGC_SUSET, RESOURCES_MEM,
1795 gettext_noop("Sets the maximum stack depth, in kilobytes."),
1800 100, 100, MAX_KILOBYTES,
1801 check_max_stack_depth, assign_max_stack_depth, NULL
1805 {"temp_file_limit", PGC_SUSET, RESOURCES_DISK,
1806 gettext_noop("Limits the total size of all temporary files used by each session."),
1807 gettext_noop("-1 means no limit."),
1816 {"vacuum_cost_page_hit", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1817 gettext_noop("Vacuum cost for a page found in the buffer cache."),
1826 {"vacuum_cost_page_miss", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1827 gettext_noop("Vacuum cost for a page not found in the buffer cache."),
1830 &VacuumCostPageMiss,
1836 {"vacuum_cost_page_dirty", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1837 gettext_noop("Vacuum cost for a page dirtied by vacuum."),
1840 &VacuumCostPageDirty,
1846 {"vacuum_cost_limit", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1847 gettext_noop("Vacuum cost amount available before napping."),
1856 {"vacuum_cost_delay", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1857 gettext_noop("Vacuum cost delay in milliseconds."),
1867 {"autovacuum_vacuum_cost_delay", PGC_SIGHUP, AUTOVACUUM,
1868 gettext_noop("Vacuum cost delay in milliseconds, for autovacuum."),
1872 &autovacuum_vac_cost_delay,
1878 {"autovacuum_vacuum_cost_limit", PGC_SIGHUP, AUTOVACUUM,
1879 gettext_noop("Vacuum cost amount available before napping, for autovacuum."),
1882 &autovacuum_vac_cost_limit,
1888 {"max_files_per_process", PGC_POSTMASTER, RESOURCES_KERNEL,
1889 gettext_noop("Sets the maximum number of simultaneously open files for each server process."),
1892 &max_files_per_process,
1898 * See also CheckRequiredParameterValues() if this parameter changes
1901 {"max_prepared_transactions", PGC_POSTMASTER, RESOURCES_MEM,
1902 gettext_noop("Sets the maximum number of simultaneously prepared transactions."),
1905 &max_prepared_xacts,
1912 {"trace_lock_oidmin", PGC_SUSET, DEVELOPER_OPTIONS,
1913 gettext_noop("Sets the minimum OID of tables for tracking locks."),
1914 gettext_noop("Is used to avoid output on system tables."),
1918 FirstNormalObjectId, 0, INT_MAX,
1922 {"trace_lock_table", PGC_SUSET, DEVELOPER_OPTIONS,
1923 gettext_noop("Sets the OID of the table with unconditionally lock tracing."),
1934 {"statement_timeout", PGC_USERSET, CLIENT_CONN_STATEMENT,
1935 gettext_noop("Sets the maximum allowed duration of any statement."),
1936 gettext_noop("A value of 0 turns off the timeout."),
1945 {"lock_timeout", PGC_USERSET, CLIENT_CONN_STATEMENT,
1946 gettext_noop("Sets the maximum allowed duration of any wait for a lock."),
1947 gettext_noop("A value of 0 turns off the timeout."),
1956 {"vacuum_freeze_min_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1957 gettext_noop("Minimum age at which VACUUM should freeze a table row."),
1960 &vacuum_freeze_min_age,
1961 50000000, 0, 1000000000,
1966 {"vacuum_freeze_table_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1967 gettext_noop("Age at which VACUUM should scan whole table to freeze tuples."),
1970 &vacuum_freeze_table_age,
1971 150000000, 0, 2000000000,
1976 {"vacuum_multixact_freeze_min_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1977 gettext_noop("Minimum age at which VACUUM should freeze a MultiXactId in a table row."),
1980 &vacuum_multixact_freeze_min_age,
1981 5000000, 0, 1000000000,
1986 {"vacuum_multixact_freeze_table_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1987 gettext_noop("Multixact age at which VACUUM should scan whole table to freeze tuples."),
1990 &vacuum_multixact_freeze_table_age,
1991 150000000, 0, 2000000000,
1996 {"vacuum_defer_cleanup_age", PGC_SIGHUP, REPLICATION_MASTER,
1997 gettext_noop("Number of transactions by which VACUUM and HOT cleanup should be deferred, if any."),
2000 &vacuum_defer_cleanup_age,
2006 * See also CheckRequiredParameterValues() if this parameter changes
2009 {"max_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
2010 gettext_noop("Sets the maximum number of locks per transaction."),
2011 gettext_noop("The shared lock table is sized on the assumption that "
2012 "at most max_locks_per_transaction * max_connections distinct "
2013 "objects will need to be locked at any one time.")
2015 &max_locks_per_xact,
2021 {"max_pred_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
2022 gettext_noop("Sets the maximum number of predicate locks per transaction."),
2023 gettext_noop("The shared predicate lock table is sized on the assumption that "
2024 "at most max_pred_locks_per_transaction * max_connections distinct "
2025 "objects will need to be locked at any one time.")
2027 &max_predicate_locks_per_xact,
2033 {"authentication_timeout", PGC_SIGHUP, CONN_AUTH_SECURITY,
2034 gettext_noop("Sets the maximum allowed time to complete client authentication."),
2038 &AuthenticationTimeout,
2044 /* Not for general use */
2045 {"pre_auth_delay", PGC_SIGHUP, DEVELOPER_OPTIONS,
2046 gettext_noop("Waits N seconds on connection startup before authentication."),
2047 gettext_noop("This allows attaching a debugger to the process."),
2048 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
2056 {"wal_keep_segments", PGC_SIGHUP, REPLICATION_SENDING,
2057 gettext_noop("Sets the number of WAL files held for standby servers."),
2066 {"checkpoint_segments", PGC_SIGHUP, WAL_CHECKPOINTS,
2067 gettext_noop("Sets the maximum distance in log segments between automatic WAL checkpoints."),
2070 &CheckPointSegments,
2076 {"checkpoint_timeout", PGC_SIGHUP, WAL_CHECKPOINTS,
2077 gettext_noop("Sets the maximum time between automatic WAL checkpoints."),
2087 {"checkpoint_warning", PGC_SIGHUP, WAL_CHECKPOINTS,
2088 gettext_noop("Enables warnings if checkpoint segments are filled more "
2089 "frequently than this."),
2090 gettext_noop("Write a message to the server log if checkpoints "
2091 "caused by the filling of checkpoint segment files happens more "
2092 "frequently than this number of seconds. Zero turns off the warning."),
2101 {"wal_buffers", PGC_POSTMASTER, WAL_SETTINGS,
2102 gettext_noop("Sets the number of disk-page buffers in shared memory for WAL."),
2108 check_wal_buffers, NULL, NULL
2112 {"wal_writer_delay", PGC_SIGHUP, WAL_SETTINGS,
2113 gettext_noop("WAL writer sleep time between WAL flushes."),
2123 {"xloginsert_locks", PGC_POSTMASTER, WAL_SETTINGS,
2124 gettext_noop("Sets the number of locks used for concurrent xlog insertions."),
2128 &num_xloginsert_locks,
2134 /* see max_connections */
2135 {"max_wal_senders", PGC_POSTMASTER, REPLICATION_SENDING,
2136 gettext_noop("Sets the maximum number of simultaneously running WAL sender processes."),
2145 /* see max_connections */
2146 {"max_replication_slots", PGC_POSTMASTER, REPLICATION_SENDING,
2147 gettext_noop("Sets the maximum number of simultaneously defined replication slots."),
2150 &max_replication_slots,
2151 0, 0, MAX_BACKENDS /* XXX? */ ,
2156 {"wal_sender_timeout", PGC_SIGHUP, REPLICATION_SENDING,
2157 gettext_noop("Sets the maximum time to wait for WAL replication."),
2161 &wal_sender_timeout,
2162 60 * 1000, 0, INT_MAX,
2167 {"commit_delay", PGC_SUSET, WAL_SETTINGS,
2168 gettext_noop("Sets the delay in microseconds between transaction commit and "
2169 "flushing WAL to disk."),
2171 /* we have no microseconds designation, so can't supply units here */
2179 {"commit_siblings", PGC_USERSET, WAL_SETTINGS,
2180 gettext_noop("Sets the minimum concurrent open transactions before performing "
2190 {"extra_float_digits", PGC_USERSET, CLIENT_CONN_LOCALE,
2191 gettext_noop("Sets the number of digits displayed for floating-point values."),
2192 gettext_noop("This affects real, double precision, and geometric data types. "
2193 "The parameter value is added to the standard number of digits "
2194 "(FLT_DIG or DBL_DIG as appropriate).")
2196 &extra_float_digits,
2202 {"log_min_duration_statement", PGC_SUSET, LOGGING_WHEN,
2203 gettext_noop("Sets the minimum execution time above which "
2204 "statements will be logged."),
2205 gettext_noop("Zero prints all queries. -1 turns this feature off."),
2208 &log_min_duration_statement,
2214 {"log_autovacuum_min_duration", PGC_SIGHUP, LOGGING_WHAT,
2215 gettext_noop("Sets the minimum execution time above which "
2216 "autovacuum actions will be logged."),
2217 gettext_noop("Zero prints all actions. -1 turns autovacuum logging off."),
2220 &Log_autovacuum_min_duration,
2226 {"bgwriter_delay", PGC_SIGHUP, RESOURCES_BGWRITER,
2227 gettext_noop("Background writer sleep time between rounds."),
2237 {"bgwriter_lru_maxpages", PGC_SIGHUP, RESOURCES_BGWRITER,
2238 gettext_noop("Background writer maximum number of LRU pages to flush per round."),
2241 &bgwriter_lru_maxpages,
2247 {"effective_io_concurrency",
2253 RESOURCES_ASYNCHRONOUS,
2254 gettext_noop("Number of simultaneous requests that can be handled efficiently by the disk subsystem."),
2255 gettext_noop("For RAID arrays, this should be approximately the number of drive spindles in the array.")
2257 &effective_io_concurrency,
2263 check_effective_io_concurrency, assign_effective_io_concurrency, NULL
2267 {"max_worker_processes",
2269 RESOURCES_ASYNCHRONOUS,
2270 gettext_noop("Maximum number of concurrent worker processes."),
2273 &max_worker_processes,
2275 check_max_worker_processes, NULL, NULL
2279 {"log_rotation_age", PGC_SIGHUP, LOGGING_WHERE,
2280 gettext_noop("Automatic log file rotation will occur after N minutes."),
2285 HOURS_PER_DAY * MINS_PER_HOUR, 0, INT_MAX / SECS_PER_MINUTE,
2290 {"log_rotation_size", PGC_SIGHUP, LOGGING_WHERE,
2291 gettext_noop("Automatic log file rotation will occur after N kilobytes."),
2296 10 * 1024, 0, INT_MAX / 1024,
2301 {"max_function_args", PGC_INTERNAL, PRESET_OPTIONS,
2302 gettext_noop("Shows the maximum number of function arguments."),
2304 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2307 FUNC_MAX_ARGS, FUNC_MAX_ARGS, FUNC_MAX_ARGS,
2312 {"max_index_keys", PGC_INTERNAL, PRESET_OPTIONS,
2313 gettext_noop("Shows the maximum number of index keys."),
2315 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2318 INDEX_MAX_KEYS, INDEX_MAX_KEYS, INDEX_MAX_KEYS,
2323 {"max_identifier_length", PGC_INTERNAL, PRESET_OPTIONS,
2324 gettext_noop("Shows the maximum identifier length."),
2326 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2328 &max_identifier_length,
2329 NAMEDATALEN - 1, NAMEDATALEN - 1, NAMEDATALEN - 1,
2334 {"block_size", PGC_INTERNAL, PRESET_OPTIONS,
2335 gettext_noop("Shows the size of a disk block."),
2337 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2340 BLCKSZ, BLCKSZ, BLCKSZ,
2345 {"segment_size", PGC_INTERNAL, PRESET_OPTIONS,
2346 gettext_noop("Shows the number of pages per disk file."),
2348 GUC_UNIT_BLOCKS | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2351 RELSEG_SIZE, RELSEG_SIZE, RELSEG_SIZE,
2356 {"wal_block_size", PGC_INTERNAL, PRESET_OPTIONS,
2357 gettext_noop("Shows the block size in the write ahead log."),
2359 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2362 XLOG_BLCKSZ, XLOG_BLCKSZ, XLOG_BLCKSZ,
2367 {"wal_segment_size", PGC_INTERNAL, PRESET_OPTIONS,
2368 gettext_noop("Shows the number of pages per write ahead log segment."),
2370 GUC_UNIT_XBLOCKS | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2373 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
2374 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
2375 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
2380 {"autovacuum_naptime", PGC_SIGHUP, AUTOVACUUM,
2381 gettext_noop("Time to sleep between autovacuum runs."),
2385 &autovacuum_naptime,
2386 60, 1, INT_MAX / 1000,
2390 {"autovacuum_vacuum_threshold", PGC_SIGHUP, AUTOVACUUM,
2391 gettext_noop("Minimum number of tuple updates or deletes prior to vacuum."),
2394 &autovacuum_vac_thresh,
2399 {"autovacuum_analyze_threshold", PGC_SIGHUP, AUTOVACUUM,
2400 gettext_noop("Minimum number of tuple inserts, updates, or deletes prior to analyze."),
2403 &autovacuum_anl_thresh,
2408 /* see varsup.c for why this is PGC_POSTMASTER not PGC_SIGHUP */
2409 {"autovacuum_freeze_max_age", PGC_POSTMASTER, AUTOVACUUM,
2410 gettext_noop("Age at which to autovacuum a table to prevent transaction ID wraparound."),
2413 &autovacuum_freeze_max_age,
2414 /* see pg_resetxlog if you change the upper-limit value */
2415 200000000, 100000000, 2000000000,
2419 /* see varsup.c for why this is PGC_POSTMASTER not PGC_SIGHUP */
2420 {"autovacuum_multixact_freeze_max_age", PGC_POSTMASTER, AUTOVACUUM,
2421 gettext_noop("Multixact age at which to autovacuum a table to prevent multixact wraparound."),
2424 &autovacuum_multixact_freeze_max_age,
2425 400000000, 10000000, 2000000000,
2429 /* see max_connections */
2430 {"autovacuum_max_workers", PGC_POSTMASTER, AUTOVACUUM,
2431 gettext_noop("Sets the maximum number of simultaneously running autovacuum worker processes."),
2434 &autovacuum_max_workers,
2436 check_autovacuum_max_workers, NULL, NULL
2440 {"autovacuum_work_mem", PGC_SIGHUP, RESOURCES_MEM,
2441 gettext_noop("Sets the maximum memory to be used by each autovacuum worker process."),
2445 &autovacuum_work_mem,
2446 -1, -1, MAX_KILOBYTES,
2447 check_autovacuum_work_mem, NULL, NULL
2451 {"tcp_keepalives_idle", PGC_USERSET, CLIENT_CONN_OTHER,
2452 gettext_noop("Time between issuing TCP keepalives."),
2453 gettext_noop("A value of 0 uses the system default."),
2456 &tcp_keepalives_idle,
2458 NULL, assign_tcp_keepalives_idle, show_tcp_keepalives_idle
2462 {"tcp_keepalives_interval", PGC_USERSET, CLIENT_CONN_OTHER,
2463 gettext_noop("Time between TCP keepalive retransmits."),
2464 gettext_noop("A value of 0 uses the system default."),
2467 &tcp_keepalives_interval,
2469 NULL, assign_tcp_keepalives_interval, show_tcp_keepalives_interval
2473 {"ssl_renegotiation_limit", PGC_USERSET, CONN_AUTH_SECURITY,
2474 gettext_noop("Set the amount of traffic to send and receive before renegotiating the encryption keys."),
2478 &ssl_renegotiation_limit,
2479 512 * 1024, 0, MAX_KILOBYTES,
2484 {"tcp_keepalives_count", PGC_USERSET, CLIENT_CONN_OTHER,
2485 gettext_noop("Maximum number of TCP keepalive retransmits."),
2486 gettext_noop("This controls the number of consecutive keepalive retransmits that can be "
2487 "lost before a connection is considered dead. A value of 0 uses the "
2490 &tcp_keepalives_count,
2492 NULL, assign_tcp_keepalives_count, show_tcp_keepalives_count
2496 {"gin_fuzzy_search_limit", PGC_USERSET, CLIENT_CONN_OTHER,
2497 gettext_noop("Sets the maximum allowed result for exact search by GIN."),
2501 &GinFuzzySearchLimit,
2507 {"effective_cache_size", PGC_USERSET, QUERY_TUNING_COST,
2508 gettext_noop("Sets the planner's assumption about the size of the disk cache."),
2509 gettext_noop("That is, the portion of the kernel's disk cache that "
2510 "will be used for PostgreSQL data files. This is measured in disk "
2511 "pages, which are normally 8 kB each."),
2514 &effective_cache_size,
2516 check_effective_cache_size, NULL, NULL
2520 /* Can't be set in postgresql.conf */
2521 {"server_version_num", PGC_INTERNAL, PRESET_OPTIONS,
2522 gettext_noop("Shows the server version as an integer."),
2524 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2526 &server_version_num,
2527 PG_VERSION_NUM, PG_VERSION_NUM, PG_VERSION_NUM,
2532 {"log_temp_files", PGC_SUSET, LOGGING_WHAT,
2533 gettext_noop("Log the use of temporary files larger than this number of kilobytes."),
2534 gettext_noop("Zero logs all files. The default is -1 (turning this feature off)."),
2543 {"track_activity_query_size", PGC_POSTMASTER, RESOURCES_MEM,
2544 gettext_noop("Sets the size reserved for pg_stat_activity.query, in bytes."),
2548 * There is no _bytes_ unit, so the user can't supply units for
2552 &pgstat_track_activity_query_size,
2557 /* End-of-list marker */
2559 {NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL, NULL
2564 static struct config_real ConfigureNamesReal[] =
2567 {"seq_page_cost", PGC_USERSET, QUERY_TUNING_COST,
2568 gettext_noop("Sets the planner's estimate of the cost of a "
2569 "sequentially fetched disk page."),
2573 DEFAULT_SEQ_PAGE_COST, 0, DBL_MAX,
2577 {"random_page_cost", PGC_USERSET, QUERY_TUNING_COST,
2578 gettext_noop("Sets the planner's estimate of the cost of a "
2579 "nonsequentially fetched disk page."),
2583 DEFAULT_RANDOM_PAGE_COST, 0, DBL_MAX,
2587 {"cpu_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
2588 gettext_noop("Sets the planner's estimate of the cost of "
2589 "processing each tuple (row)."),
2593 DEFAULT_CPU_TUPLE_COST, 0, DBL_MAX,
2597 {"cpu_index_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
2598 gettext_noop("Sets the planner's estimate of the cost of "
2599 "processing each index entry during an index scan."),
2602 &cpu_index_tuple_cost,
2603 DEFAULT_CPU_INDEX_TUPLE_COST, 0, DBL_MAX,
2607 {"cpu_operator_cost", PGC_USERSET, QUERY_TUNING_COST,
2608 gettext_noop("Sets the planner's estimate of the cost of "
2609 "processing each operator or function call."),
2613 DEFAULT_CPU_OPERATOR_COST, 0, DBL_MAX,
2618 {"cursor_tuple_fraction", PGC_USERSET, QUERY_TUNING_OTHER,
2619 gettext_noop("Sets the planner's estimate of the fraction of "
2620 "a cursor's rows that will be retrieved."),
2623 &cursor_tuple_fraction,
2624 DEFAULT_CURSOR_TUPLE_FRACTION, 0.0, 1.0,
2629 {"geqo_selection_bias", PGC_USERSET, QUERY_TUNING_GEQO,
2630 gettext_noop("GEQO: selective pressure within the population."),
2633 &Geqo_selection_bias,
2634 DEFAULT_GEQO_SELECTION_BIAS,
2635 MIN_GEQO_SELECTION_BIAS, MAX_GEQO_SELECTION_BIAS,
2639 {"geqo_seed", PGC_USERSET, QUERY_TUNING_GEQO,
2640 gettext_noop("GEQO: seed for random path selection."),
2649 {"bgwriter_lru_multiplier", PGC_SIGHUP, RESOURCES_BGWRITER,
2650 gettext_noop("Multiple of the average buffer usage to free per round."),
2653 &bgwriter_lru_multiplier,
2659 {"seed", PGC_USERSET, UNGROUPED,
2660 gettext_noop("Sets the seed for random-number generation."),
2662 GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2666 check_random_seed, assign_random_seed, show_random_seed
2670 {"autovacuum_vacuum_scale_factor", PGC_SIGHUP, AUTOVACUUM,
2671 gettext_noop("Number of tuple updates or deletes prior to vacuum as a fraction of reltuples."),
2674 &autovacuum_vac_scale,
2679 {"autovacuum_analyze_scale_factor", PGC_SIGHUP, AUTOVACUUM,
2680 gettext_noop("Number of tuple inserts, updates, or deletes prior to analyze as a fraction of reltuples."),
2683 &autovacuum_anl_scale,
2689 {"checkpoint_completion_target", PGC_SIGHUP, WAL_CHECKPOINTS,
2690 gettext_noop("Time spent flushing dirty buffers during checkpoint, as fraction of checkpoint interval."),
2693 &CheckPointCompletionTarget,
2698 /* End-of-list marker */
2700 {NULL, 0, 0, NULL, NULL}, NULL, 0.0, 0.0, 0.0, NULL, NULL, NULL
2705 static struct config_string ConfigureNamesString[] =
2708 {"archive_command", PGC_SIGHUP, WAL_ARCHIVING,
2709 gettext_noop("Sets the shell command that will be called to archive a WAL file."),
2712 &XLogArchiveCommand,
2714 NULL, NULL, show_archive_command
2718 {"client_encoding", PGC_USERSET, CLIENT_CONN_LOCALE,
2719 gettext_noop("Sets the client's character set encoding."),
2721 GUC_IS_NAME | GUC_REPORT
2723 &client_encoding_string,
2725 check_client_encoding, assign_client_encoding, NULL
2729 {"log_line_prefix", PGC_SIGHUP, LOGGING_WHAT,
2730 gettext_noop("Controls information prefixed to each log line."),
2731 gettext_noop("If blank, no prefix is used.")
2739 {"log_timezone", PGC_SIGHUP, LOGGING_WHAT,
2740 gettext_noop("Sets the time zone to use in log messages."),
2743 &log_timezone_string,
2745 check_log_timezone, assign_log_timezone, show_log_timezone
2749 {"DateStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
2750 gettext_noop("Sets the display format for date and time values."),
2751 gettext_noop("Also controls interpretation of ambiguous "
2753 GUC_LIST_INPUT | GUC_REPORT
2757 check_datestyle, assign_datestyle, NULL
2761 {"default_tablespace", PGC_USERSET, CLIENT_CONN_STATEMENT,
2762 gettext_noop("Sets the default tablespace to create tables and indexes in."),
2763 gettext_noop("An empty string selects the database's default tablespace."),
2766 &default_tablespace,
2768 check_default_tablespace, NULL, NULL
2772 {"temp_tablespaces", PGC_USERSET, CLIENT_CONN_STATEMENT,
2773 gettext_noop("Sets the tablespace(s) to use for temporary tables and sort files."),
2775 GUC_LIST_INPUT | GUC_LIST_QUOTE
2779 check_temp_tablespaces, assign_temp_tablespaces, NULL
2783 {"dynamic_library_path", PGC_SUSET, CLIENT_CONN_OTHER,
2784 gettext_noop("Sets the path for dynamically loadable modules."),
2785 gettext_noop("If a dynamically loadable module needs to be opened and "
2786 "the specified name does not have a directory component (i.e., the "
2787 "name does not contain a slash), the system will search this path for "
2788 "the specified file."),
2791 &Dynamic_library_path,
2797 {"krb_server_keyfile", PGC_SIGHUP, CONN_AUTH_SECURITY,
2798 gettext_noop("Sets the location of the Kerberos server key file."),
2802 &pg_krb_server_keyfile,
2808 {"bonjour_name", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2809 gettext_noop("Sets the Bonjour service name."),
2817 /* See main.c about why defaults for LC_foo are not all alike */
2820 {"lc_collate", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2821 gettext_noop("Shows the collation order locale."),
2823 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2831 {"lc_ctype", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2832 gettext_noop("Shows the character classification and case conversion locale."),
2834 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2842 {"lc_messages", PGC_SUSET, CLIENT_CONN_LOCALE,
2843 gettext_noop("Sets the language in which messages are displayed."),
2848 check_locale_messages, assign_locale_messages, NULL
2852 {"lc_monetary", PGC_USERSET, CLIENT_CONN_LOCALE,
2853 gettext_noop("Sets the locale for formatting monetary amounts."),
2858 check_locale_monetary, assign_locale_monetary, NULL
2862 {"lc_numeric", PGC_USERSET, CLIENT_CONN_LOCALE,
2863 gettext_noop("Sets the locale for formatting numbers."),
2868 check_locale_numeric, assign_locale_numeric, NULL
2872 {"lc_time", PGC_USERSET, CLIENT_CONN_LOCALE,
2873 gettext_noop("Sets the locale for formatting date and time values."),
2878 check_locale_time, assign_locale_time, NULL
2882 {"session_preload_libraries", PGC_SUSET, CLIENT_CONN_PRELOAD,
2883 gettext_noop("Lists shared libraries to preload into each backend."),
2885 GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
2887 &session_preload_libraries_string,
2893 {"shared_preload_libraries", PGC_POSTMASTER, CLIENT_CONN_PRELOAD,
2894 gettext_noop("Lists shared libraries to preload into server."),
2896 GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
2898 &shared_preload_libraries_string,
2904 {"local_preload_libraries", PGC_BACKEND, CLIENT_CONN_PRELOAD,
2905 gettext_noop("Lists unprivileged shared libraries to preload into each backend."),
2907 GUC_LIST_INPUT | GUC_LIST_QUOTE
2909 &local_preload_libraries_string,
2915 {"search_path", PGC_USERSET, CLIENT_CONN_STATEMENT,
2916 gettext_noop("Sets the schema search order for names that are not schema-qualified."),
2918 GUC_LIST_INPUT | GUC_LIST_QUOTE
2920 &namespace_search_path,
2922 check_search_path, assign_search_path, NULL
2926 /* Can't be set in postgresql.conf */
2927 {"server_encoding", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2928 gettext_noop("Sets the server (database) character set encoding."),
2930 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2932 &server_encoding_string,
2938 /* Can't be set in postgresql.conf */
2939 {"server_version", PGC_INTERNAL, PRESET_OPTIONS,
2940 gettext_noop("Shows the server version."),
2942 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2944 &server_version_string,
2950 /* Not for general use --- used by SET ROLE */
2951 {"role", PGC_USERSET, UNGROUPED,
2952 gettext_noop("Sets the current role."),
2954 GUC_IS_NAME | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_NOT_WHILE_SEC_REST
2958 check_role, assign_role, show_role
2962 /* Not for general use --- used by SET SESSION AUTHORIZATION */
2963 {"session_authorization", PGC_USERSET, UNGROUPED,
2964 gettext_noop("Sets the session user name."),
2966 GUC_IS_NAME | GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_NOT_WHILE_SEC_REST
2968 &session_authorization_string,
2970 check_session_authorization, assign_session_authorization, NULL
2974 {"log_destination", PGC_SIGHUP, LOGGING_WHERE,
2975 gettext_noop("Sets the destination for server log output."),
2976 gettext_noop("Valid values are combinations of \"stderr\", "
2977 "\"syslog\", \"csvlog\", and \"eventlog\", "
2978 "depending on the platform."),
2981 &Log_destination_string,
2983 check_log_destination, assign_log_destination, NULL
2986 {"log_directory", PGC_SIGHUP, LOGGING_WHERE,
2987 gettext_noop("Sets the destination directory for log files."),
2988 gettext_noop("Can be specified as relative to the data directory "
2989 "or as absolute path."),
2994 check_canonical_path, NULL, NULL
2997 {"log_filename", PGC_SIGHUP, LOGGING_WHERE,
2998 gettext_noop("Sets the file name pattern for log files."),
3003 "postgresql-%Y-%m-%d_%H%M%S.log",
3008 {"syslog_ident", PGC_SIGHUP, LOGGING_WHERE,
3009 gettext_noop("Sets the program name used to identify PostgreSQL "
3010 "messages in syslog."),
3015 NULL, assign_syslog_ident, NULL
3019 {"event_source", PGC_POSTMASTER, LOGGING_WHERE,
3020 gettext_noop("Sets the application name used to identify "
3021 "PostgreSQL messages in the event log."),
3030 {"TimeZone", PGC_USERSET, CLIENT_CONN_LOCALE,
3031 gettext_noop("Sets the time zone for displaying and interpreting time stamps."),
3037 check_timezone, assign_timezone, show_timezone
3040 {"timezone_abbreviations", PGC_USERSET, CLIENT_CONN_LOCALE,
3041 gettext_noop("Selects a file of time zone abbreviations."),
3044 &timezone_abbreviations_string,
3046 check_timezone_abbreviations, assign_timezone_abbreviations, NULL
3050 {"transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
3051 gettext_noop("Sets the current transaction's isolation level."),
3053 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
3055 &XactIsoLevel_string,
3057 check_XactIsoLevel, assign_XactIsoLevel, show_XactIsoLevel
3061 {"unix_socket_group", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
3062 gettext_noop("Sets the owning group of the Unix-domain socket."),
3063 gettext_noop("The owning user of the socket is always the user "
3064 "that starts the server.")
3072 {"unix_socket_directories", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
3073 gettext_noop("Sets the directories where Unix-domain sockets will be created."),
3077 &Unix_socket_directories,
3078 #ifdef HAVE_UNIX_SOCKETS
3079 DEFAULT_PGSOCKET_DIR,
3087 {"listen_addresses", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
3088 gettext_noop("Sets the host name or IP address(es) to listen to."),
3098 {"data_directory", PGC_POSTMASTER, FILE_LOCATIONS,
3099 gettext_noop("Sets the server's data directory."),
3109 {"config_file", PGC_POSTMASTER, FILE_LOCATIONS,
3110 gettext_noop("Sets the server's main configuration file."),
3112 GUC_DISALLOW_IN_FILE | GUC_SUPERUSER_ONLY
3120 {"hba_file", PGC_POSTMASTER, FILE_LOCATIONS,
3121 gettext_noop("Sets the server's \"hba\" configuration file."),
3131 {"ident_file", PGC_POSTMASTER, FILE_LOCATIONS,
3132 gettext_noop("Sets the server's \"ident\" configuration file."),
3142 {"external_pid_file", PGC_POSTMASTER, FILE_LOCATIONS,
3143 gettext_noop("Writes the postmaster PID to the specified file."),
3149 check_canonical_path, NULL, NULL
3153 {"ssl_cert_file", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3154 gettext_noop("Location of the SSL server certificate file."),
3163 {"ssl_key_file", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3164 gettext_noop("Location of the SSL server private key file."),
3173 {"ssl_ca_file", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3174 gettext_noop("Location of the SSL certificate authority file."),
3183 {"ssl_crl_file", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3184 gettext_noop("Location of the SSL certificate revocation list file."),
3193 {"stats_temp_directory", PGC_SIGHUP, STATS_COLLECTOR,
3194 gettext_noop("Writes temporary statistics files to the specified directory."),
3198 &pgstat_temp_directory,
3200 check_canonical_path, assign_pgstat_temp_directory, NULL
3204 {"synchronous_standby_names", PGC_SIGHUP, REPLICATION_MASTER,
3205 gettext_noop("List of names of potential synchronous standbys."),
3209 &SyncRepStandbyNames,
3211 check_synchronous_standby_names, NULL, NULL
3215 {"default_text_search_config", PGC_USERSET, CLIENT_CONN_LOCALE,
3216 gettext_noop("Sets default text search configuration."),
3220 "pg_catalog.simple",
3221 check_TSCurrentConfig, assign_TSCurrentConfig, NULL
3225 {"ssl_ciphers", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3226 gettext_noop("Sets the list of allowed SSL ciphers."),
3232 "HIGH:MEDIUM:+3DES:!aNULL",
3240 {"ssl_ecdh_curve", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3241 gettext_noop("Sets the curve to use for ECDH."),
3255 {"application_name", PGC_USERSET, LOGGING_WHAT,
3256 gettext_noop("Sets the application name to be reported in statistics and logs."),
3258 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE
3262 check_application_name, assign_application_name, NULL
3265 /* End-of-list marker */
3267 {NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL, NULL
3272 static struct config_enum ConfigureNamesEnum[] =
3275 {"backslash_quote", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
3276 gettext_noop("Sets whether \"\\'\" is allowed in string literals."),
3280 BACKSLASH_QUOTE_SAFE_ENCODING, backslash_quote_options,
3285 {"bytea_output", PGC_USERSET, CLIENT_CONN_STATEMENT,
3286 gettext_noop("Sets the output format for bytea."),
3290 BYTEA_OUTPUT_HEX, bytea_output_options,
3295 {"client_min_messages", PGC_USERSET, LOGGING_WHEN,
3296 gettext_noop("Sets the message levels that are sent to the client."),
3297 gettext_noop("Each level includes all the levels that follow it. The later"
3298 " the level, the fewer messages are sent.")
3300 &client_min_messages,
3301 NOTICE, client_message_level_options,
3306 {"constraint_exclusion", PGC_USERSET, QUERY_TUNING_OTHER,
3307 gettext_noop("Enables the planner to use constraints to optimize queries."),
3308 gettext_noop("Table scans will be skipped if their constraints"
3309 " guarantee that no rows match the query.")
3311 &constraint_exclusion,
3312 CONSTRAINT_EXCLUSION_PARTITION, constraint_exclusion_options,
3317 {"default_transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
3318 gettext_noop("Sets the transaction isolation level of each new transaction."),
3321 &DefaultXactIsoLevel,
3322 XACT_READ_COMMITTED, isolation_level_options,
3327 {"IntervalStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
3328 gettext_noop("Sets the display format for interval values."),
3333 INTSTYLE_POSTGRES, intervalstyle_options,
3338 {"log_error_verbosity", PGC_SUSET, LOGGING_WHAT,
3339 gettext_noop("Sets the verbosity of logged messages."),
3342 &Log_error_verbosity,
3343 PGERROR_DEFAULT, log_error_verbosity_options,
3348 {"log_min_messages", PGC_SUSET, LOGGING_WHEN,
3349 gettext_noop("Sets the message levels that are logged."),
3350 gettext_noop("Each level includes all the levels that follow it. The later"
3351 " the level, the fewer messages are sent.")
3354 WARNING, server_message_level_options,
3359 {"log_min_error_statement", PGC_SUSET, LOGGING_WHEN,
3360 gettext_noop("Causes all statements generating error at or above this level to be logged."),
3361 gettext_noop("Each level includes all the levels that follow it. The later"
3362 " the level, the fewer messages are sent.")
3364 &log_min_error_statement,
3365 ERROR, server_message_level_options,
3370 {"log_statement", PGC_SUSET, LOGGING_WHAT,
3371 gettext_noop("Sets the type of statements logged."),
3375 LOGSTMT_NONE, log_statement_options,
3380 {"syslog_facility", PGC_SIGHUP, LOGGING_WHERE,
3381 gettext_noop("Sets the syslog \"facility\" to be used when syslog enabled."),
3390 syslog_facility_options,
3391 NULL, assign_syslog_facility, NULL
3395 {"session_replication_role", PGC_SUSET, CLIENT_CONN_STATEMENT,
3396 gettext_noop("Sets the session's behavior for triggers and rewrite rules."),
3399 &SessionReplicationRole,
3400 SESSION_REPLICATION_ROLE_ORIGIN, session_replication_role_options,
3401 NULL, assign_session_replication_role, NULL
3405 {"synchronous_commit", PGC_USERSET, WAL_SETTINGS,
3406 gettext_noop("Sets the current transaction's synchronization level."),
3409 &synchronous_commit,
3410 SYNCHRONOUS_COMMIT_ON, synchronous_commit_options,
3411 NULL, assign_synchronous_commit, NULL
3415 {"trace_recovery_messages", PGC_SIGHUP, DEVELOPER_OPTIONS,
3416 gettext_noop("Enables logging of recovery-related debugging information."),
3417 gettext_noop("Each level includes all the levels that follow it. The later"
3418 " the level, the fewer messages are sent.")
3420 &trace_recovery_messages,
3423 * client_message_level_options allows too many values, really, but
3424 * it's not worth having a separate options array for this.
3426 LOG, client_message_level_options,
3431 {"track_functions", PGC_SUSET, STATS_COLLECTOR,
3432 gettext_noop("Collects function-level statistics on database activity."),
3435 &pgstat_track_functions,
3436 TRACK_FUNC_OFF, track_function_options,
3441 {"wal_level", PGC_POSTMASTER, WAL_SETTINGS,
3442 gettext_noop("Set the level of information written to the WAL."),
3446 WAL_LEVEL_MINIMAL, wal_level_options,
3451 {"dynamic_shared_memory_type", PGC_POSTMASTER, RESOURCES_MEM,
3452 gettext_noop("Selects the dynamic shared memory implementation used."),
3455 &dynamic_shared_memory_type,
3456 DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE, dynamic_shared_memory_options,
3461 {"wal_sync_method", PGC_SIGHUP, WAL_SETTINGS,
3462 gettext_noop("Selects the method used for forcing WAL updates to disk."),
3466 DEFAULT_SYNC_METHOD, sync_method_options,
3467 NULL, assign_xlog_sync_method, NULL
3471 {"xmlbinary", PGC_USERSET, CLIENT_CONN_STATEMENT,
3472 gettext_noop("Sets how binary values are to be encoded in XML."),
3476 XMLBINARY_BASE64, xmlbinary_options,
3481 {"xmloption", PGC_USERSET, CLIENT_CONN_STATEMENT,
3482 gettext_noop("Sets whether XML data in implicit parsing and serialization "
3483 "operations is to be considered as documents or content fragments."),
3487 XMLOPTION_CONTENT, xmloption_options,
3492 {"huge_pages", PGC_POSTMASTER, RESOURCES_MEM,
3493 gettext_noop("Use of huge pages on Linux"),
3497 HUGE_PAGES_TRY, huge_pages_options,
3501 /* End-of-list marker */
3503 {NULL, 0, 0, NULL, NULL}, NULL, 0, NULL, NULL, NULL, NULL
3507 /******** end of options list ********/
3511 * To allow continued support of obsolete names for GUC variables, we apply
3512 * the following mappings to any unrecognized name. Note that an old name
3513 * should be mapped to a new one only if the new variable has very similar
3514 * semantics to the old.
3516 static const char *const map_old_guc_names[] = {
3517 "sort_mem", "work_mem",
3518 "vacuum_mem", "maintenance_work_mem",
3524 * Actual lookup of variables is done through this single, sorted array.
3526 static struct config_generic **guc_variables;
3528 /* Current number of variables contained in the vector */
3529 static int num_guc_variables;
3531 /* Vector capacity */
3532 static int size_guc_variables;
3535 static bool guc_dirty; /* TRUE if need to do commit/abort work */
3537 static bool reporting_enabled; /* TRUE to enable GUC_REPORT */
3539 static int GUCNestLevel = 0; /* 1 when in main transaction */
3542 static int guc_var_compare(const void *a, const void *b);
3543 static int guc_name_compare(const char *namea, const char *nameb);
3544 static void InitializeGUCOptionsFromEnvironment(void);
3545 static void InitializeOneGUCOption(struct config_generic * gconf);
3546 static void push_old_value(struct config_generic * gconf, GucAction action);
3547 static void ReportGUCOption(struct config_generic * record);
3548 static void reapply_stacked_values(struct config_generic * variable,
3549 struct config_string * pHolder,
3551 const char *curvalue,
3552 GucContext curscontext, GucSource cursource);
3553 static void ShowGUCConfigOption(const char *name, DestReceiver *dest);
3554 static void ShowAllGUCConfig(DestReceiver *dest);
3555 static char *_ShowOption(struct config_generic * record, bool use_units);
3556 static bool validate_option_array_item(const char *name, const char *value,
3557 bool skipIfNoPermissions);
3558 static void write_auto_conf_file(int fd, const char *filename, ConfigVariable **head_p);
3559 static void replace_auto_config_value(ConfigVariable **head_p, ConfigVariable **tail_p,
3560 char *config_file, char *name, char *value);
3564 * Some infrastructure for checking malloc/strdup/realloc calls
3567 guc_malloc(int elevel, size_t size)
3571 /* Avoid unportable behavior of malloc(0) */
3574 data = malloc(size);
3577 (errcode(ERRCODE_OUT_OF_MEMORY),
3578 errmsg("out of memory")));
3583 guc_realloc(int elevel, void *old, size_t size)
3587 /* Avoid unportable behavior of realloc(NULL, 0) */
3588 if (old == NULL && size == 0)
3590 data = realloc(old, size);
3593 (errcode(ERRCODE_OUT_OF_MEMORY),
3594 errmsg("out of memory")));
3599 guc_strdup(int elevel, const char *src)
3606 (errcode(ERRCODE_OUT_OF_MEMORY),
3607 errmsg("out of memory")));
3613 * Detect whether strval is referenced anywhere in a GUC string item
3616 string_field_used(struct config_string * conf, char *strval)
3620 if (strval == *(conf->variable) ||
3621 strval == conf->reset_val ||
3622 strval == conf->boot_val)
3624 for (stack = conf->gen.stack; stack; stack = stack->prev)
3626 if (strval == stack->prior.val.stringval ||
3627 strval == stack->masked.val.stringval)
3634 * Support for assigning to a field of a string GUC item. Free the prior
3635 * value if it's not referenced anywhere else in the item (including stacked
3639 set_string_field(struct config_string * conf, char **field, char *newval)
3641 char *oldval = *field;
3643 /* Do the assignment */
3646 /* Free old value if it's not NULL and isn't referenced anymore */
3647 if (oldval && !string_field_used(conf, oldval))
3652 * Detect whether an "extra" struct is referenced anywhere in a GUC item
3655 extra_field_used(struct config_generic * gconf, void *extra)
3659 if (extra == gconf->extra)
3661 switch (gconf->vartype)
3664 if (extra == ((struct config_bool *) gconf)->reset_extra)
3668 if (extra == ((struct config_int *) gconf)->reset_extra)
3672 if (extra == ((struct config_real *) gconf)->reset_extra)
3676 if (extra == ((struct config_string *) gconf)->reset_extra)
3680 if (extra == ((struct config_enum *) gconf)->reset_extra)
3684 for (stack = gconf->stack; stack; stack = stack->prev)
3686 if (extra == stack->prior.extra ||
3687 extra == stack->masked.extra)
3695 * Support for assigning to an "extra" field of a GUC item. Free the prior
3696 * value if it's not referenced anywhere else in the item (including stacked
3700 set_extra_field(struct config_generic * gconf, void **field, void *newval)
3702 void *oldval = *field;
3704 /* Do the assignment */
3707 /* Free old value if it's not NULL and isn't referenced anymore */
3708 if (oldval && !extra_field_used(gconf, oldval))
3713 * Support for copying a variable's active value into a stack entry.
3714 * The "extra" field associated with the active value is copied, too.
3716 * NB: be sure stringval and extra fields of a new stack entry are
3717 * initialized to NULL before this is used, else we'll try to free() them.
3720 set_stack_value(struct config_generic * gconf, config_var_value *val)
3722 switch (gconf->vartype)
3726 *((struct config_bool *) gconf)->variable;
3730 *((struct config_int *) gconf)->variable;
3734 *((struct config_real *) gconf)->variable;
3737 set_string_field((struct config_string *) gconf,
3738 &(val->val.stringval),
3739 *((struct config_string *) gconf)->variable);
3743 *((struct config_enum *) gconf)->variable;
3746 set_extra_field(gconf, &(val->extra), gconf->extra);
3750 * Support for discarding a no-longer-needed value in a stack entry.
3751 * The "extra" field associated with the stack entry is cleared, too.
3754 discard_stack_value(struct config_generic * gconf, config_var_value *val)
3756 switch (gconf->vartype)
3762 /* no need to do anything */
3765 set_string_field((struct config_string *) gconf,
3766 &(val->val.stringval),
3770 set_extra_field(gconf, &(val->extra), NULL);
3775 * Fetch the sorted array pointer (exported for help_config.c's use ONLY)
3777 struct config_generic **
3778 get_guc_variables(void)
3780 return guc_variables;
3785 * Build the sorted array. This is split out so that it could be
3786 * re-executed after startup (eg, we could allow loadable modules to
3787 * add vars, and then we'd need to re-sort).
3790 build_guc_variables(void)
3794 struct config_generic **guc_vars;
3797 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
3799 struct config_bool *conf = &ConfigureNamesBool[i];
3801 /* Rather than requiring vartype to be filled in by hand, do this: */
3802 conf->gen.vartype = PGC_BOOL;
3806 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
3808 struct config_int *conf = &ConfigureNamesInt[i];
3810 conf->gen.vartype = PGC_INT;
3814 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
3816 struct config_real *conf = &ConfigureNamesReal[i];
3818 conf->gen.vartype = PGC_REAL;
3822 for (i = 0; ConfigureNamesString[i].gen.name; i++)
3824 struct config_string *conf = &ConfigureNamesString[i];
3826 conf->gen.vartype = PGC_STRING;
3830 for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
3832 struct config_enum *conf = &ConfigureNamesEnum[i];
3834 conf->gen.vartype = PGC_ENUM;
3839 * Create table with 20% slack
3841 size_vars = num_vars + num_vars / 4;
3843 guc_vars = (struct config_generic **)
3844 guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
3848 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
3849 guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
3851 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
3852 guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
3854 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
3855 guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
3857 for (i = 0; ConfigureNamesString[i].gen.name; i++)
3858 guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
3860 for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
3861 guc_vars[num_vars++] = &ConfigureNamesEnum[i].gen;
3864 free(guc_variables);
3865 guc_variables = guc_vars;
3866 num_guc_variables = num_vars;
3867 size_guc_variables = size_vars;
3868 qsort((void *) guc_variables, num_guc_variables,
3869 sizeof(struct config_generic *), guc_var_compare);
3873 * Add a new GUC variable to the list of known variables. The
3874 * list is expanded if needed.
3877 add_guc_variable(struct config_generic * var, int elevel)
3879 if (num_guc_variables + 1 >= size_guc_variables)
3882 * Increase the vector by 25%
3884 int size_vars = size_guc_variables + size_guc_variables / 4;
3885 struct config_generic **guc_vars;
3890 guc_vars = (struct config_generic **)
3891 guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
3895 guc_vars = (struct config_generic **)
3896 guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
3899 if (guc_vars == NULL)
3900 return false; /* out of memory */
3902 guc_variables = guc_vars;
3903 size_guc_variables = size_vars;
3905 guc_variables[num_guc_variables++] = var;
3906 qsort((void *) guc_variables, num_guc_variables,
3907 sizeof(struct config_generic *), guc_var_compare);
3912 * Create and add a placeholder variable for a custom variable name.
3914 static struct config_generic *
3915 add_placeholder_variable(const char *name, int elevel)
3917 size_t sz = sizeof(struct config_string) + sizeof(char *);
3918 struct config_string *var;
3919 struct config_generic *gen;
3921 var = (struct config_string *) guc_malloc(elevel, sz);
3927 gen->name = guc_strdup(elevel, name);
3928 if (gen->name == NULL)
3934 gen->context = PGC_USERSET;
3935 gen->group = CUSTOM_OPTIONS;
3936 gen->short_desc = "GUC placeholder variable";
3937 gen->flags = GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_CUSTOM_PLACEHOLDER;
3938 gen->vartype = PGC_STRING;
3941 * The char* is allocated at the end of the struct since we have no
3942 * 'static' place to point to. Note that the current value, as well as
3943 * the boot and reset values, start out NULL.
3945 var->variable = (char **) (var + 1);
3947 if (!add_guc_variable((struct config_generic *) var, elevel))
3949 free((void *) gen->name);
3958 * Look up option NAME. If it exists, return a pointer to its record,
3959 * else return NULL. If create_placeholders is TRUE, we'll create a
3960 * placeholder record for a valid-looking custom variable name.
3962 static struct config_generic *
3963 find_option(const char *name, bool create_placeholders, int elevel)
3965 const char **key = &name;
3966 struct config_generic **res;
3972 * By equating const char ** with struct config_generic *, we are assuming
3973 * the name field is first in config_generic.
3975 res = (struct config_generic **) bsearch((void *) &key,
3976 (void *) guc_variables,
3978 sizeof(struct config_generic *),
3984 * See if the name is an obsolete name for a variable. We assume that the
3985 * set of supported old names is short enough that a brute-force search is
3988 for (i = 0; map_old_guc_names[i] != NULL; i += 2)
3990 if (guc_name_compare(name, map_old_guc_names[i]) == 0)
3991 return find_option(map_old_guc_names[i + 1], false, elevel);
3994 if (create_placeholders)
3997 * Check if the name is qualified, and if so, add a placeholder.
3999 if (strchr(name, GUC_QUALIFIER_SEPARATOR) != NULL)
4000 return add_placeholder_variable(name, elevel);
4009 * comparator for qsorting and bsearching guc_variables array
4012 guc_var_compare(const void *a, const void *b)
4014 const struct config_generic *confa = *(struct config_generic * const *) a;
4015 const struct config_generic *confb = *(struct config_generic * const *) b;
4017 return guc_name_compare(confa->name, confb->name);
4021 * the bare comparison function for GUC names
4024 guc_name_compare(const char *namea, const char *nameb)
4027 * The temptation to use strcasecmp() here must be resisted, because the
4028 * array ordering has to remain stable across setlocale() calls. So, build
4029 * our own with a simple ASCII-only downcasing.
4031 while (*namea && *nameb)
4033 char cha = *namea++;
4034 char chb = *nameb++;
4036 if (cha >= 'A' && cha <= 'Z')
4038 if (chb >= 'A' && chb <= 'Z')
4044 return 1; /* a is longer */
4046 return -1; /* b is longer */
4052 * Initialize GUC options during program startup.
4054 * Note that we cannot read the config file yet, since we have not yet
4055 * processed command-line switches.
4058 InitializeGUCOptions(void)
4063 * Before log_line_prefix could possibly receive a nonempty setting, make
4064 * sure that timezone processing is minimally alive (see elog.c).
4066 pg_timezone_initialize();
4069 * Build sorted array of all GUC variables.
4071 build_guc_variables();
4074 * Load all variables with their compiled-in defaults, and initialize
4075 * status fields as needed.
4077 for (i = 0; i < num_guc_variables; i++)
4079 InitializeOneGUCOption(guc_variables[i]);
4084 reporting_enabled = false;
4087 * Prevent any attempt to override the transaction modes from
4088 * non-interactive sources.
4090 SetConfigOption("transaction_isolation", "default",
4091 PGC_POSTMASTER, PGC_S_OVERRIDE);
4092 SetConfigOption("transaction_read_only", "no",
4093 PGC_POSTMASTER, PGC_S_OVERRIDE);
4094 SetConfigOption("transaction_deferrable", "no",
4095 PGC_POSTMASTER, PGC_S_OVERRIDE);
4098 * For historical reasons, some GUC parameters can receive defaults from
4099 * environment variables. Process those settings.
4101 InitializeGUCOptionsFromEnvironment();
4105 * Assign any GUC values that can come from the server's environment.
4107 * This is called from InitializeGUCOptions, and also from ProcessConfigFile
4108 * to deal with the possibility that a setting has been removed from
4109 * postgresql.conf and should now get a value from the environment.
4110 * (The latter is a kludge that should probably go away someday; if so,
4111 * fold this back into InitializeGUCOptions.)
4114 InitializeGUCOptionsFromEnvironment(void)
4119 env = getenv("PGPORT");
4121 SetConfigOption("port", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
4123 env = getenv("PGDATESTYLE");
4125 SetConfigOption("datestyle", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
4127 env = getenv("PGCLIENTENCODING");
4129 SetConfigOption("client_encoding", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
4132 * rlimit isn't exactly an "environment variable", but it behaves about
4133 * the same. If we can identify the platform stack depth rlimit, increase
4134 * default stack depth setting up to whatever is safe (but at most 2MB).
4136 stack_rlimit = get_stack_depth_rlimit();
4137 if (stack_rlimit > 0)
4139 long new_limit = (stack_rlimit - STACK_DEPTH_SLOP) / 1024L;
4141 if (new_limit > 100)
4145 new_limit = Min(new_limit, 2048);
4146 sprintf(limbuf, "%ld", new_limit);
4147 SetConfigOption("max_stack_depth", limbuf,
4148 PGC_POSTMASTER, PGC_S_ENV_VAR);
4154 * Initialize one GUC option variable to its compiled-in default.
4156 * Note: the reason for calling check_hooks is not that we think the boot_val
4157 * might fail, but that the hooks might wish to compute an "extra" struct.
4160 InitializeOneGUCOption(struct config_generic * gconf)
4163 gconf->source = PGC_S_DEFAULT;
4164 gconf->reset_source = PGC_S_DEFAULT;
4165 gconf->scontext = PGC_INTERNAL;
4166 gconf->reset_scontext = PGC_INTERNAL;
4167 gconf->stack = NULL;
4168 gconf->extra = NULL;
4169 gconf->sourcefile = NULL;
4170 gconf->sourceline = 0;
4172 switch (gconf->vartype)
4176 struct config_bool *conf = (struct config_bool *) gconf;
4177 bool newval = conf->boot_val;
4180 if (!call_bool_check_hook(conf, &newval, &extra,
4181 PGC_S_DEFAULT, LOG))
4182 elog(FATAL, "failed to initialize %s to %d",
4183 conf->gen.name, (int) newval);
4184 if (conf->assign_hook)
4185 (*conf->assign_hook) (newval, extra);
4186 *conf->variable = conf->reset_val = newval;
4187 conf->gen.extra = conf->reset_extra = extra;
4192 struct config_int *conf = (struct config_int *) gconf;
4193 int newval = conf->boot_val;
4196 Assert(newval >= conf->min);
4197 Assert(newval <= conf->max);
4198 if (!call_int_check_hook(conf, &newval, &extra,
4199 PGC_S_DEFAULT, LOG))
4200 elog(FATAL, "failed to initialize %s to %d",
4201 conf->gen.name, newval);
4202 if (conf->assign_hook)
4203 (*conf->assign_hook) (newval, extra);
4204 *conf->variable = conf->reset_val = newval;
4205 conf->gen.extra = conf->reset_extra = extra;
4210 struct config_real *conf = (struct config_real *) gconf;
4211 double newval = conf->boot_val;
4214 Assert(newval >= conf->min);
4215 Assert(newval <= conf->max);
4216 if (!call_real_check_hook(conf, &newval, &extra,
4217 PGC_S_DEFAULT, LOG))
4218 elog(FATAL, "failed to initialize %s to %g",
4219 conf->gen.name, newval);
4220 if (conf->assign_hook)
4221 (*conf->assign_hook) (newval, extra);
4222 *conf->variable = conf->reset_val = newval;
4223 conf->gen.extra = conf->reset_extra = extra;
4228 struct config_string *conf = (struct config_string *) gconf;
4232 /* non-NULL boot_val must always get strdup'd */
4233 if (conf->boot_val != NULL)
4234 newval = guc_strdup(FATAL, conf->boot_val);
4238 if (!call_string_check_hook(conf, &newval, &extra,
4239 PGC_S_DEFAULT, LOG))
4240 elog(FATAL, "failed to initialize %s to \"%s\"",
4241 conf->gen.name, newval ? newval : "");
4242 if (conf->assign_hook)
4243 (*conf->assign_hook) (newval, extra);
4244 *conf->variable = conf->reset_val = newval;
4245 conf->gen.extra = conf->reset_extra = extra;
4250 struct config_enum *conf = (struct config_enum *) gconf;
4251 int newval = conf->boot_val;
4254 if (!call_enum_check_hook(conf, &newval, &extra,
4255 PGC_S_DEFAULT, LOG))
4256 elog(FATAL, "failed to initialize %s to %d",
4257 conf->gen.name, newval);
4258 if (conf->assign_hook)
4259 (*conf->assign_hook) (newval, extra);
4260 *conf->variable = conf->reset_val = newval;
4261 conf->gen.extra = conf->reset_extra = extra;
4269 * Select the configuration files and data directory to be used, and
4270 * do the initial read of postgresql.conf.
4272 * This is called after processing command-line switches.
4273 * userDoption is the -D switch value if any (NULL if unspecified).
4274 * progname is just for use in error messages.
4276 * Returns true on success; on failure, prints a suitable error message
4277 * to stderr and returns false.
4280 SelectConfigFiles(const char *userDoption, const char *progname)
4284 struct stat stat_buf;
4286 /* configdir is -D option, or $PGDATA if no -D */
4288 configdir = make_absolute_path(userDoption);
4290 configdir = make_absolute_path(getenv("PGDATA"));
4293 * Find the configuration file: if config_file was specified on the
4294 * command line, use it, else use configdir/postgresql.conf. In any case
4295 * ensure the result is an absolute path, so that it will be interpreted
4296 * the same way by future backends.
4299 fname = make_absolute_path(ConfigFileName);
4302 fname = guc_malloc(FATAL,
4303 strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
4304 sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
4308 write_stderr("%s does not know where to find the server configuration file.\n"
4309 "You must specify the --config-file or -D invocation "
4310 "option or set the PGDATA environment variable.\n",
4316 * Set the ConfigFileName GUC variable to its final value, ensuring that
4317 * it can't be overridden later.
4319 SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4323 * Now read the config file for the first time.
4325 if (stat(ConfigFileName, &stat_buf) != 0)
4327 write_stderr("%s cannot access the server configuration file \"%s\": %s\n",
4328 progname, ConfigFileName, strerror(errno));
4333 ProcessConfigFile(PGC_POSTMASTER);
4336 * If the data_directory GUC variable has been set, use that as DataDir;
4337 * otherwise use configdir if set; else punt.
4339 * Note: SetDataDir will copy and absolute-ize its argument, so we don't
4343 SetDataDir(data_directory);
4345 SetDataDir(configdir);
4348 write_stderr("%s does not know where to find the database system data.\n"
4349 "This can be specified as \"data_directory\" in \"%s\", "
4350 "or by the -D invocation option, or by the "
4351 "PGDATA environment variable.\n",
4352 progname, ConfigFileName);
4357 * Reflect the final DataDir value back into the data_directory GUC var.
4358 * (If you are wondering why we don't just make them a single variable,
4359 * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
4360 * child backends specially. XXX is that still true? Given that we now
4361 * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
4362 * DataDir in advance.)
4364 SetConfigOption("data_directory", DataDir, PGC_POSTMASTER, PGC_S_OVERRIDE);
4367 * If timezone_abbreviations wasn't set in the configuration file, install
4368 * the default value. We do it this way because we can't safely install a
4369 * "real" value until my_exec_path is set, which may not have happened
4370 * when InitializeGUCOptions runs, so the bootstrap default value cannot
4371 * be the real desired default.
4373 pg_timezone_abbrev_initialize();
4375 /* Also install the correct value for effective_cache_size */
4376 set_default_effective_cache_size();
4379 * Figure out where pg_hba.conf is, and make sure the path is absolute.
4382 fname = make_absolute_path(HbaFileName);
4385 fname = guc_malloc(FATAL,
4386 strlen(configdir) + strlen(HBA_FILENAME) + 2);
4387 sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
4391 write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
4392 "This can be specified as \"hba_file\" in \"%s\", "
4393 "or by the -D invocation option, or by the "
4394 "PGDATA environment variable.\n",
4395 progname, ConfigFileName);
4398 SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4402 * Likewise for pg_ident.conf.
4405 fname = make_absolute_path(IdentFileName);
4408 fname = guc_malloc(FATAL,
4409 strlen(configdir) + strlen(IDENT_FILENAME) + 2);
4410 sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
4414 write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
4415 "This can be specified as \"ident_file\" in \"%s\", "
4416 "or by the -D invocation option, or by the "
4417 "PGDATA environment variable.\n",
4418 progname, ConfigFileName);
4421 SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4431 * Reset all options to their saved default values (implements RESET ALL)
4434 ResetAllOptions(void)
4438 for (i = 0; i < num_guc_variables; i++)
4440 struct config_generic *gconf = guc_variables[i];
4442 /* Don't reset non-SET-able values */
4443 if (gconf->context != PGC_SUSET &&
4444 gconf->context != PGC_USERSET)
4446 /* Don't reset if special exclusion from RESET ALL */
4447 if (gconf->flags & GUC_NO_RESET_ALL)
4449 /* No need to reset if wasn't SET */
4450 if (gconf->source <= PGC_S_OVERRIDE)
4453 /* Save old value to support transaction abort */
4454 push_old_value(gconf, GUC_ACTION_SET);
4456 switch (gconf->vartype)
4460 struct config_bool *conf = (struct config_bool *) gconf;
4462 if (conf->assign_hook)
4463 (*conf->assign_hook) (conf->reset_val,
4465 *conf->variable = conf->reset_val;
4466 set_extra_field(&conf->gen, &conf->gen.extra,
4472 struct config_int *conf = (struct config_int *) gconf;
4474 if (conf->assign_hook)
4475 (*conf->assign_hook) (conf->reset_val,
4477 *conf->variable = conf->reset_val;
4478 set_extra_field(&conf->gen, &conf->gen.extra,
4484 struct config_real *conf = (struct config_real *) gconf;
4486 if (conf->assign_hook)
4487 (*conf->assign_hook) (conf->reset_val,
4489 *conf->variable = conf->reset_val;
4490 set_extra_field(&conf->gen, &conf->gen.extra,
4496 struct config_string *conf = (struct config_string *) gconf;
4498 if (conf->assign_hook)
4499 (*conf->assign_hook) (conf->reset_val,
4501 set_string_field(conf, conf->variable, conf->reset_val);
4502 set_extra_field(&conf->gen, &conf->gen.extra,
4508 struct config_enum *conf = (struct config_enum *) gconf;
4510 if (conf->assign_hook)
4511 (*conf->assign_hook) (conf->reset_val,
4513 *conf->variable = conf->reset_val;
4514 set_extra_field(&conf->gen, &conf->gen.extra,
4520 gconf->source = gconf->reset_source;
4521 gconf->scontext = gconf->reset_scontext;
4523 if (gconf->flags & GUC_REPORT)
4524 ReportGUCOption(gconf);
4531 * Push previous state during transactional assignment to a GUC variable.
4534 push_old_value(struct config_generic * gconf, GucAction action)
4538 /* If we're not inside a nest level, do nothing */
4539 if (GUCNestLevel == 0)
4542 /* Do we already have a stack entry of the current nest level? */
4543 stack = gconf->stack;
4544 if (stack && stack->nest_level >= GUCNestLevel)
4546 /* Yes, so adjust its state if necessary */
4547 Assert(stack->nest_level == GUCNestLevel);
4550 case GUC_ACTION_SET:
4551 /* SET overrides any prior action at same nest level */
4552 if (stack->state == GUC_SET_LOCAL)
4554 /* must discard old masked value */
4555 discard_stack_value(gconf, &stack->masked);
4557 stack->state = GUC_SET;
4559 case GUC_ACTION_LOCAL:
4560 if (stack->state == GUC_SET)
4562 /* SET followed by SET LOCAL, remember SET's value */
4563 stack->masked_scontext = gconf->scontext;
4564 set_stack_value(gconf, &stack->masked);
4565 stack->state = GUC_SET_LOCAL;
4567 /* in all other cases, no change to stack entry */
4569 case GUC_ACTION_SAVE:
4570 /* Could only have a prior SAVE of same variable */
4571 Assert(stack->state == GUC_SAVE);
4574 Assert(guc_dirty); /* must be set already */
4579 * Push a new stack entry
4581 * We keep all the stack entries in TopTransactionContext for simplicity.
4583 stack = (GucStack *) MemoryContextAllocZero(TopTransactionContext,
4586 stack->prev = gconf->stack;
4587 stack->nest_level = GUCNestLevel;
4590 case GUC_ACTION_SET:
4591 stack->state = GUC_SET;
4593 case GUC_ACTION_LOCAL:
4594 stack->state = GUC_LOCAL;
4596 case GUC_ACTION_SAVE:
4597 stack->state = GUC_SAVE;
4600 stack->source = gconf->source;
4601 stack->scontext = gconf->scontext;
4602 set_stack_value(gconf, &stack->prior);
4604 gconf->stack = stack;
4606 /* Ensure we remember to pop at end of xact */
4612 * Do GUC processing at main transaction start.
4618 * The nest level should be 0 between transactions; if it isn't, somebody
4619 * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
4620 * throw a warning but make no other effort to clean up.
4622 if (GUCNestLevel != 0)
4623 elog(WARNING, "GUC nest level = %d at transaction start",
4629 * Enter a new nesting level for GUC values. This is called at subtransaction
4630 * start, and when entering a function that has proconfig settings, and in
4631 * some other places where we want to set GUC variables transiently.
4632 * NOTE we must not risk error here, else subtransaction start will be unhappy.
4635 NewGUCNestLevel(void)
4637 return ++GUCNestLevel;
4641 * Do GUC processing at transaction or subtransaction commit or abort, or
4642 * when exiting a function that has proconfig settings, or when undoing a
4643 * transient assignment to some GUC variables. (The name is thus a bit of
4644 * a misnomer; perhaps it should be ExitGUCNestLevel or some such.)
4645 * During abort, we discard all GUC settings that were applied at nesting
4646 * levels >= nestLevel. nestLevel == 1 corresponds to the main transaction.
4649 AtEOXact_GUC(bool isCommit, int nestLevel)
4655 * Note: it's possible to get here with GUCNestLevel == nestLevel-1 during
4656 * abort, if there is a failure during transaction start before
4657 * AtStart_GUC is called.
4659 Assert(nestLevel > 0 &&
4660 (nestLevel <= GUCNestLevel ||
4661 (nestLevel == GUCNestLevel + 1 && !isCommit)));
4663 /* Quick exit if nothing's changed in this transaction */
4666 GUCNestLevel = nestLevel - 1;
4670 still_dirty = false;
4671 for (i = 0; i < num_guc_variables; i++)
4673 struct config_generic *gconf = guc_variables[i];
4677 * Process and pop each stack entry within the nest level. To simplify
4678 * fmgr_security_definer() and other places that use GUC_ACTION_SAVE,
4679 * we allow failure exit from code that uses a local nest level to be
4680 * recovered at the surrounding transaction or subtransaction abort;
4681 * so there could be more than one stack entry to pop.
4683 while ((stack = gconf->stack) != NULL &&
4684 stack->nest_level >= nestLevel)
4686 GucStack *prev = stack->prev;
4687 bool restorePrior = false;
4688 bool restoreMasked = false;
4692 * In this next bit, if we don't set either restorePrior or
4693 * restoreMasked, we must "discard" any unwanted fields of the
4694 * stack entries to avoid leaking memory. If we do set one of
4695 * those flags, unused fields will be cleaned up after restoring.
4697 if (!isCommit) /* if abort, always restore prior value */
4698 restorePrior = true;
4699 else if (stack->state == GUC_SAVE)
4700 restorePrior = true;
4701 else if (stack->nest_level == 1)
4703 /* transaction commit */
4704 if (stack->state == GUC_SET_LOCAL)
4705 restoreMasked = true;
4706 else if (stack->state == GUC_SET)
4708 /* we keep the current active value */
4709 discard_stack_value(gconf, &stack->prior);
4711 else /* must be GUC_LOCAL */
4712 restorePrior = true;
4714 else if (prev == NULL ||
4715 prev->nest_level < stack->nest_level - 1)
4717 /* decrement entry's level and do not pop it */
4718 stack->nest_level--;
4724 * We have to merge this stack entry into prev. See README for
4725 * discussion of this bit.
4727 switch (stack->state)
4730 Assert(false); /* can't get here */
4733 /* next level always becomes SET */
4734 discard_stack_value(gconf, &stack->prior);
4735 if (prev->state == GUC_SET_LOCAL)
4736 discard_stack_value(gconf, &prev->masked);
4737 prev->state = GUC_SET;
4741 if (prev->state == GUC_SET)
4743 /* LOCAL migrates down */
4744 prev->masked_scontext = stack->scontext;
4745 prev->masked = stack->prior;
4746 prev->state = GUC_SET_LOCAL;
4750 /* else just forget this stack level */
4751 discard_stack_value(gconf, &stack->prior);
4756 /* prior state at this level no longer wanted */
4757 discard_stack_value(gconf, &stack->prior);
4758 /* copy down the masked state */
4759 prev->masked_scontext = stack->masked_scontext;
4760 if (prev->state == GUC_SET_LOCAL)
4761 discard_stack_value(gconf, &prev->masked);
4762 prev->masked = stack->masked;
4763 prev->state = GUC_SET_LOCAL;
4770 if (restorePrior || restoreMasked)
4772 /* Perform appropriate restoration of the stacked value */
4773 config_var_value newvalue;
4774 GucSource newsource;
4775 GucContext newscontext;
4779 newvalue = stack->masked;
4780 newsource = PGC_S_SESSION;
4781 newscontext = stack->masked_scontext;
4785 newvalue = stack->prior;
4786 newsource = stack->source;
4787 newscontext = stack->scontext;
4790 switch (gconf->vartype)
4794 struct config_bool *conf = (struct config_bool *) gconf;
4795 bool newval = newvalue.val.boolval;
4796 void *newextra = newvalue.extra;
4798 if (*conf->variable != newval ||
4799 conf->gen.extra != newextra)
4801 if (conf->assign_hook)
4802 (*conf->assign_hook) (newval, newextra);
4803 *conf->variable = newval;
4804 set_extra_field(&conf->gen, &conf->gen.extra,
4812 struct config_int *conf = (struct config_int *) gconf;
4813 int newval = newvalue.val.intval;
4814 void *newextra = newvalue.extra;
4816 if (*conf->variable != newval ||
4817 conf->gen.extra != newextra)
4819 if (conf->assign_hook)
4820 (*conf->assign_hook) (newval, newextra);
4821 *conf->variable = newval;
4822 set_extra_field(&conf->gen, &conf->gen.extra,
4830 struct config_real *conf = (struct config_real *) gconf;
4831 double newval = newvalue.val.realval;
4832 void *newextra = newvalue.extra;
4834 if (*conf->variable != newval ||
4835 conf->gen.extra != newextra)
4837 if (conf->assign_hook)
4838 (*conf->assign_hook) (newval, newextra);
4839 *conf->variable = newval;
4840 set_extra_field(&conf->gen, &conf->gen.extra,
4848 struct config_string *conf = (struct config_string *) gconf;
4849 char *newval = newvalue.val.stringval;
4850 void *newextra = newvalue.extra;
4852 if (*conf->variable != newval ||
4853 conf->gen.extra != newextra)
4855 if (conf->assign_hook)
4856 (*conf->assign_hook) (newval, newextra);
4857 set_string_field(conf, conf->variable, newval);
4858 set_extra_field(&conf->gen, &conf->gen.extra,
4864 * Release stacked values if not used anymore. We
4865 * could use discard_stack_value() here, but since
4866 * we have type-specific code anyway, might as
4869 set_string_field(conf, &stack->prior.val.stringval, NULL);
4870 set_string_field(conf, &stack->masked.val.stringval, NULL);
4875 struct config_enum *conf = (struct config_enum *) gconf;
4876 int newval = newvalue.val.enumval;
4877 void *newextra = newvalue.extra;
4879 if (*conf->variable != newval ||
4880 conf->gen.extra != newextra)
4882 if (conf->assign_hook)
4883 (*conf->assign_hook) (newval, newextra);
4884 *conf->variable = newval;
4885 set_extra_field(&conf->gen, &conf->gen.extra,
4894 * Release stacked extra values if not used anymore.
4896 set_extra_field(gconf, &(stack->prior.extra), NULL);
4897 set_extra_field(gconf, &(stack->masked.extra), NULL);
4899 /* And restore source information */
4900 gconf->source = newsource;
4901 gconf->scontext = newscontext;
4904 /* Finish popping the state stack */
4905 gconf->stack = prev;
4908 /* Report new value if we changed it */
4909 if (changed && (gconf->flags & GUC_REPORT))
4910 ReportGUCOption(gconf);
4911 } /* end of stack-popping loop */
4917 /* If there are no remaining stack entries, we can reset guc_dirty */
4918 guc_dirty = still_dirty;
4920 /* Update nesting level */
4921 GUCNestLevel = nestLevel - 1;
4926 * Start up automatic reporting of changes to variables marked GUC_REPORT.
4927 * This is executed at completion of backend startup.
4930 BeginReportingGUCOptions(void)
4935 * Don't do anything unless talking to an interactive frontend of protocol
4938 if (whereToSendOutput != DestRemote ||
4939 PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
4942 reporting_enabled = true;
4944 /* Transmit initial values of interesting variables */
4945 for (i = 0; i < num_guc_variables; i++)
4947 struct config_generic *conf = guc_variables[i];
4949 if (conf->flags & GUC_REPORT)
4950 ReportGUCOption(conf);
4955 * ReportGUCOption: if appropriate, transmit option value to frontend
4958 ReportGUCOption(struct config_generic * record)
4960 if (reporting_enabled && (record->flags & GUC_REPORT))
4962 char *val = _ShowOption(record, false);
4963 StringInfoData msgbuf;
4965 pq_beginmessage(&msgbuf, 'S');
4966 pq_sendstring(&msgbuf, record->name);
4967 pq_sendstring(&msgbuf, val);
4968 pq_endmessage(&msgbuf);
4975 * Try to parse value as an integer. The accepted formats are the
4976 * usual decimal, octal, or hexadecimal formats, optionally followed by
4977 * a unit name if "flags" indicates a unit is allowed.
4979 * If the string parses okay, return true, else false.
4980 * If okay and result is not NULL, return the value in *result.
4981 * If not okay and hintmsg is not NULL, *hintmsg is set to a suitable
4982 * HINT message, or NULL if no hint provided.
4985 parse_int(const char *value, int *result, int flags, const char **hintmsg)
4990 /* To suppress compiler warnings, always set output params */
4996 /* We assume here that int64 is at least as wide as long */
4998 val = strtol(value, &endptr, 0);
5000 if (endptr == value)
5001 return false; /* no HINT for integer syntax error */
5003 if (errno == ERANGE || val != (int64) ((int32) val))
5006 *hintmsg = gettext_noop("Value exceeds integer range.");
5010 /* allow whitespace between integer and unit */
5011 while (isspace((unsigned char) *endptr))
5014 /* Handle possible unit */
5015 if (*endptr != '\0')
5018 * Note: the multiple-switch coding technique here is a bit tedious,
5019 * but seems necessary to avoid intermediate-value overflows.
5021 if (flags & GUC_UNIT_MEMORY)
5023 /* Set hint for use if no match or trailing garbage */
5025 *hintmsg = gettext_noop("Valid units for this parameter are \"kB\", \"MB\", \"GB\", and \"TB\".");
5027 #if BLCKSZ < 1024 || BLCKSZ > (1024*1024)
5028 #error BLCKSZ must be between 1KB and 1MB
5030 #if XLOG_BLCKSZ < 1024 || XLOG_BLCKSZ > (1024*1024)
5031 #error XLOG_BLCKSZ must be between 1KB and 1MB
5034 if (strncmp(endptr, "kB", 2) == 0)
5037 switch (flags & GUC_UNIT_MEMORY)
5039 case GUC_UNIT_BLOCKS:
5040 val /= (BLCKSZ / 1024);
5042 case GUC_UNIT_XBLOCKS:
5043 val /= (XLOG_BLCKSZ / 1024);
5047 else if (strncmp(endptr, "MB", 2) == 0)
5050 switch (flags & GUC_UNIT_MEMORY)
5055 case GUC_UNIT_BLOCKS:
5056 val *= KB_PER_MB / (BLCKSZ / 1024);
5058 case GUC_UNIT_XBLOCKS:
5059 val *= KB_PER_MB / (XLOG_BLCKSZ / 1024);
5063 else if (strncmp(endptr, "GB", 2) == 0)
5066 switch (flags & GUC_UNIT_MEMORY)
5071 case GUC_UNIT_BLOCKS:
5072 val *= KB_PER_GB / (BLCKSZ / 1024);
5074 case GUC_UNIT_XBLOCKS:
5075 val *= KB_PER_GB / (XLOG_BLCKSZ / 1024);
5079 else if (strncmp(endptr, "TB", 2) == 0)
5082 switch (flags & GUC_UNIT_MEMORY)
5087 case GUC_UNIT_BLOCKS:
5088 val *= KB_PER_TB / (BLCKSZ / 1024);
5090 case GUC_UNIT_XBLOCKS:
5091 val *= KB_PER_TB / (XLOG_BLCKSZ / 1024);
5096 else if (flags & GUC_UNIT_TIME)
5098 /* Set hint for use if no match or trailing garbage */
5100 *hintmsg = gettext_noop("Valid units for this parameter are \"ms\", \"s\", \"min\", \"h\", and \"d\".");
5102 if (strncmp(endptr, "ms", 2) == 0)
5105 switch (flags & GUC_UNIT_TIME)
5115 else if (strncmp(endptr, "s", 1) == 0)
5118 switch (flags & GUC_UNIT_TIME)
5128 else if (strncmp(endptr, "min", 3) == 0)
5131 switch (flags & GUC_UNIT_TIME)
5141 else if (strncmp(endptr, "h", 1) == 0)
5144 switch (flags & GUC_UNIT_TIME)
5157 else if (strncmp(endptr, "d", 1) == 0)
5160 switch (flags & GUC_UNIT_TIME)
5175 /* allow whitespace after unit */
5176 while (isspace((unsigned char) *endptr))
5179 if (*endptr != '\0')
5180 return false; /* appropriate hint, if any, already set */
5182 /* Check for overflow due to units conversion */
5183 if (val != (int64) ((int32) val))
5186 *hintmsg = gettext_noop("Value exceeds integer range.");
5192 *result = (int) val;
5199 * Try to parse value as a floating point number in the usual format.
5200 * If the string parses okay, return true, else false.
5201 * If okay and result is not NULL, return the value in *result.
5204 parse_real(const char *value, double *result)
5210 *result = 0; /* suppress compiler warning */
5213 val = strtod(value, &endptr);
5214 if (endptr == value || errno == ERANGE)
5217 /* allow whitespace after number */
5218 while (isspace((unsigned char) *endptr))
5220 if (*endptr != '\0')
5230 * Lookup the name for an enum option with the selected value.
5231 * Should only ever be called with known-valid values, so throws
5232 * an elog(ERROR) if the enum option is not found.
5234 * The returned string is a pointer to static data and not
5235 * allocated for modification.
5238 config_enum_lookup_by_value(struct config_enum * record, int val)
5240 const struct config_enum_entry *entry;
5242 for (entry = record->options; entry && entry->name; entry++)
5244 if (entry->val == val)
5248 elog(ERROR, "could not find enum option %d for %s",
5249 val, record->gen.name);
5250 return NULL; /* silence compiler */
5255 * Lookup the value for an enum option with the selected name
5256 * (case-insensitive).
5257 * If the enum option is found, sets the retval value and returns
5258 * true. If it's not found, return FALSE and retval is set to 0.
5261 config_enum_lookup_by_name(struct config_enum * record, const char *value,
5264 const struct config_enum_entry *entry;
5266 for (entry = record->options; entry && entry->name; entry++)
5268 if (pg_strcasecmp(value, entry->name) == 0)
5270 *retval = entry->val;
5281 * Return a list of all available options for an enum, excluding
5282 * hidden ones, separated by the given separator.
5283 * If prefix is non-NULL, it is added before the first enum value.
5284 * If suffix is non-NULL, it is added to the end of the string.
5287 config_enum_get_options(struct config_enum * record, const char *prefix,
5288 const char *suffix, const char *separator)
5290 const struct config_enum_entry *entry;
5291 StringInfoData retstr;
5294 initStringInfo(&retstr);
5295 appendStringInfoString(&retstr, prefix);
5297 seplen = strlen(separator);
5298 for (entry = record->options; entry && entry->name; entry++)
5302 appendStringInfoString(&retstr, entry->name);
5303 appendBinaryStringInfo(&retstr, separator, seplen);
5308 * All the entries may have been hidden, leaving the string empty if no
5309 * prefix was given. This indicates a broken GUC setup, since there is no
5310 * use for an enum without any values, so we just check to make sure we
5311 * don't write to invalid memory instead of actually trying to do
5312 * something smart with it.
5314 if (retstr.len >= seplen)
5316 /* Replace final separator */
5317 retstr.data[retstr.len - seplen] = '\0';
5318 retstr.len -= seplen;
5321 appendStringInfoString(&retstr, suffix);
5327 * Validates configuration parameter and value, by calling check hook functions
5328 * depending on record's vartype. It validates if the parameter
5329 * value given is in range of expected predefined value for that parameter.
5331 * freemem - true indicates memory for newval and newextra will be
5332 * freed in this function, false indicates it will be freed
5335 * 1: the value is valid
5336 * 0: the name or value is invalid
5339 validate_conf_option(struct config_generic * record, const char *name,
5340 const char *value, GucSource source, int elevel,
5341 bool freemem, void *newval, void **newextra)
5344 * Validate the value for the passed record, to ensure it is in expected
5347 switch (record->vartype)
5352 struct config_bool *conf = (struct config_bool *) record;
5356 newval = &tmpnewval;
5360 if (!parse_bool(value, newval))
5363 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5364 errmsg("parameter \"%s\" requires a Boolean value",
5369 if (!call_bool_check_hook(conf, newval, newextra,
5373 if (*newextra && freemem)
5380 struct config_int *conf = (struct config_int *) record;
5384 newval = &tmpnewval;
5388 const char *hintmsg;
5390 if (!parse_int(value, newval, conf->gen.flags, &hintmsg))
5393 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5394 errmsg("invalid value for parameter \"%s\": \"%s\"",
5396 hintmsg ? errhint("%s", _(hintmsg)) : 0));
5400 if (*((int *) newval) < conf->min || *((int *) newval) > conf->max)
5403 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5404 errmsg("%d is outside the valid range for parameter \"%s\" (%d .. %d)",
5405 *((int *) newval), name, conf->min, conf->max)));
5409 if (!call_int_check_hook(conf, newval, newextra,
5413 if (*newextra && freemem)
5420 struct config_real *conf = (struct config_real *) record;
5424 newval = &tmpnewval;
5428 if (!parse_real(value, newval))
5431 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5432 errmsg("parameter \"%s\" requires a numeric value",
5437 if (*((double *) newval) < conf->min || *((double *) newval) > conf->max)
5440 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5441 errmsg("%g is outside the valid range for parameter \"%s\" (%g .. %g)",
5442 *((double *) newval), name, conf->min, conf->max)));
5446 if (!call_real_check_hook(conf, newval, newextra,
5450 if (*newextra && freemem)
5457 struct config_string *conf = (struct config_string *) record;
5459 char **tmpnewval = newval;
5462 tmpnewval = &tempPtr;
5467 * The value passed by the caller could be transient, so
5468 * we always strdup it.
5470 *tmpnewval = guc_strdup(elevel, value);
5471 if (*tmpnewval == NULL)
5475 * The only built-in "parsing" check we have is to apply
5476 * truncation if GUC_IS_NAME.
5478 if (conf->gen.flags & GUC_IS_NAME)
5479 truncate_identifier(*tmpnewval, strlen(*tmpnewval), true);
5481 if (!call_string_check_hook(conf, tmpnewval, newextra,
5488 /* Free the malloc'd data if any */
5491 if (*tmpnewval != NULL)
5493 if (*newextra != NULL)
5501 struct config_enum *conf = (struct config_enum *) record;
5505 newval = &tmpnewval;
5509 if (!config_enum_lookup_by_name(conf, value, newval))
5513 hintmsg = config_enum_get_options(conf,
5514 "Available values: ",
5518 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5519 errmsg("invalid value for parameter \"%s\": \"%s\"",
5521 hintmsg ? errhint("%s", _(hintmsg)) : 0));
5523 if (hintmsg != NULL)
5527 if (!call_enum_check_hook(conf, newval, newextra,
5531 if (*newextra && freemem)
5542 * Sets option `name' to given value.
5544 * The value should be a string, which will be parsed and converted to
5545 * the appropriate data type. The context and source parameters indicate
5546 * in which context this function is being called, so that it can apply the
5547 * access restrictions properly.
5549 * If value is NULL, set the option to its default value (normally the
5550 * reset_val, but if source == PGC_S_DEFAULT we instead use the boot_val).
5552 * action indicates whether to set the value globally in the session, locally
5553 * to the current top transaction, or just for the duration of a function call.
5555 * If changeVal is false then don't really set the option but do all
5556 * the checks to see if it would work.
5558 * elevel should normally be passed as zero, allowing this function to make
5559 * its standard choice of ereport level. However some callers need to be
5560 * able to override that choice; they should pass the ereport level to use.
5563 * +1: the value is valid and was successfully applied.
5564 * 0: the name or value is invalid (but see below).
5565 * -1: the value was not applied because of context, priority, or changeVal.
5567 * If there is an error (non-existing option, invalid value) then an
5568 * ereport(ERROR) is thrown *unless* this is called for a source for which
5569 * we don't want an ERROR (currently, those are defaults, the config file,
5570 * and per-database or per-user settings, as well as callers who specify
5571 * a less-than-ERROR elevel). In those cases we write a suitable error
5572 * message via ereport() and return 0.
5574 * See also SetConfigOption for an external interface.
5577 set_config_option(const char *name, const char *value,
5578 GucContext context, GucSource source,
5579 GucAction action, bool changeVal, int elevel)
5581 struct config_generic *record;
5582 bool prohibitValueChange = false;
5587 if (source == PGC_S_DEFAULT || source == PGC_S_FILE)
5590 * To avoid cluttering the log, only the postmaster bleats loudly
5591 * about problems with the config file.
5593 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
5595 else if (source == PGC_S_GLOBAL || source == PGC_S_DATABASE || source == PGC_S_USER ||
5596 source == PGC_S_DATABASE_USER)
5602 record = find_option(name, true, elevel);
5606 (errcode(ERRCODE_UNDEFINED_OBJECT),
5607 errmsg("unrecognized configuration parameter \"%s\"", name)));
5612 * Check if the option can be set at this time. See guc.h for the precise
5615 switch (record->context)
5618 if (context != PGC_INTERNAL)
5621 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5622 errmsg("parameter \"%s\" cannot be changed",
5627 case PGC_POSTMASTER:
5628 if (context == PGC_SIGHUP)
5631 * We are re-reading a PGC_POSTMASTER variable from
5632 * postgresql.conf. We can't change the setting, so we should
5633 * give a warning if the DBA tries to change it. However,
5634 * because of variant formats, canonicalization by check
5635 * hooks, etc, we can't just compare the given string directly
5636 * to what's stored. Set a flag to check below after we have
5637 * the final storable value.
5639 prohibitValueChange = true;
5641 else if (context != PGC_POSTMASTER)
5644 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5645 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5651 if (context != PGC_SIGHUP && context != PGC_POSTMASTER)
5654 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5655 errmsg("parameter \"%s\" cannot be changed now",
5661 * Hmm, the idea of the SIGHUP context is "ought to be global, but
5662 * can be changed after postmaster start". But there's nothing
5663 * that prevents a crafty administrator from sending SIGHUP
5664 * signals to individual backends only.
5668 if (context == PGC_SIGHUP)
5671 * If a PGC_BACKEND parameter is changed in the config file,
5672 * we want to accept the new value in the postmaster (whence
5673 * it will propagate to subsequently-started backends), but
5674 * ignore it in existing backends. This is a tad klugy, but
5675 * necessary because we don't re-read the config file during
5678 * In EXEC_BACKEND builds, this works differently: we load all
5679 * nondefault settings from the CONFIG_EXEC_PARAMS file during
5680 * backend start. In that case we must accept PGC_SIGHUP
5681 * settings, so as to have the same value as if we'd forked
5682 * from the postmaster. We detect this situation by checking
5683 * IsInitProcessingMode, which is a bit ugly, but it doesn't
5684 * seem worth passing down an explicit flag saying we're doing
5685 * read_nondefault_variables().
5688 if (IsUnderPostmaster && !IsInitProcessingMode())
5691 if (IsUnderPostmaster)
5695 else if (context != PGC_POSTMASTER && context != PGC_BACKEND &&
5696 source != PGC_S_CLIENT)
5699 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5700 errmsg("parameter \"%s\" cannot be set after connection start",
5706 if (context == PGC_USERSET || context == PGC_BACKEND)
5709 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5710 errmsg("permission denied to set parameter \"%s\"",
5721 * Disallow changing GUC_NOT_WHILE_SEC_REST values if we are inside a
5722 * security restriction context. We can reject this regardless of the GUC
5723 * context or source, mainly because sources that it might be reasonable
5724 * to override for won't be seen while inside a function.
5726 * Note: variables marked GUC_NOT_WHILE_SEC_REST should usually be marked
5727 * GUC_NO_RESET_ALL as well, because ResetAllOptions() doesn't check this.
5728 * An exception might be made if the reset value is assumed to be "safe".
5730 * Note: this flag is currently used for "session_authorization" and
5731 * "role". We need to prohibit changing these inside a local userid
5732 * context because when we exit it, GUC won't be notified, leaving things
5733 * out of sync. (This could be fixed by forcing a new GUC nesting level,
5734 * but that would change behavior in possibly-undesirable ways.) Also, we
5735 * prohibit changing these in a security-restricted operation because
5736 * otherwise RESET could be used to regain the session user's privileges.
5738 if (record->flags & GUC_NOT_WHILE_SEC_REST)
5740 if (InLocalUserIdChange())
5743 * Phrasing of this error message is historical, but it's the most
5747 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5748 errmsg("cannot set parameter \"%s\" within security-definer function",
5752 if (InSecurityRestrictedOperation())
5755 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5756 errmsg("cannot set parameter \"%s\" within security-restricted operation",
5763 * Should we set reset/stacked values? (If so, the behavior is not
5764 * transactional.) This is done either when we get a default value from
5765 * the database's/user's/client's default settings or when we reset a
5766 * value to its default.
5768 makeDefault = changeVal && (source <= PGC_S_OVERRIDE) &&
5769 ((value != NULL) || source == PGC_S_DEFAULT);
5772 * Ignore attempted set if overridden by previously processed setting.
5773 * However, if changeVal is false then plow ahead anyway since we are
5774 * trying to find out if the value is potentially good, not actually use
5775 * it. Also keep going if makeDefault is true, since we may want to set
5776 * the reset/stacked values even if we can't set the variable itself.
5778 if (record->source > source)
5780 if (changeVal && !makeDefault)
5782 elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
5790 * Evaluate value and set variable.
5792 switch (record->vartype)
5796 struct config_bool *conf = (struct config_bool *) record;
5798 void *newextra = NULL;
5802 if (!validate_conf_option(record, name, value, source,
5803 elevel, false, &newval,
5807 else if (source == PGC_S_DEFAULT)
5809 newval = conf->boot_val;
5810 if (!call_bool_check_hook(conf, &newval, &newextra,
5816 newval = conf->reset_val;
5817 newextra = conf->reset_extra;
5818 source = conf->gen.reset_source;
5819 context = conf->gen.reset_scontext;
5822 if (prohibitValueChange)
5824 if (*conf->variable != newval)
5827 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5828 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5837 /* Save old value to support transaction abort */
5839 push_old_value(&conf->gen, action);
5841 if (conf->assign_hook)
5842 (*conf->assign_hook) (newval, newextra);
5843 *conf->variable = newval;
5844 set_extra_field(&conf->gen, &conf->gen.extra,
5846 conf->gen.source = source;
5847 conf->gen.scontext = context;
5853 if (conf->gen.reset_source <= source)
5855 conf->reset_val = newval;
5856 set_extra_field(&conf->gen, &conf->reset_extra,
5858 conf->gen.reset_source = source;
5859 conf->gen.reset_scontext = context;
5861 for (stack = conf->gen.stack; stack; stack = stack->prev)
5863 if (stack->source <= source)
5865 stack->prior.val.boolval = newval;
5866 set_extra_field(&conf->gen, &stack->prior.extra,
5868 stack->source = source;
5869 stack->scontext = context;
5874 /* Perhaps we didn't install newextra anywhere */
5875 if (newextra && !extra_field_used(&conf->gen, newextra))
5882 struct config_int *conf = (struct config_int *) record;
5884 void *newextra = NULL;
5888 if (!validate_conf_option(record, name, value, source,
5889 elevel, false, &newval,
5893 else if (source == PGC_S_DEFAULT)
5895 newval = conf->boot_val;
5896 if (!call_int_check_hook(conf, &newval, &newextra,
5902 newval = conf->reset_val;
5903 newextra = conf->reset_extra;
5904 source = conf->gen.reset_source;
5905 context = conf->gen.reset_scontext;
5908 if (prohibitValueChange)
5910 if (*conf->variable != newval)
5913 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5914 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5923 /* Save old value to support transaction abort */
5925 push_old_value(&conf->gen, action);
5927 if (conf->assign_hook)
5928 (*conf->assign_hook) (newval, newextra);
5929 *conf->variable = newval;
5930 set_extra_field(&conf->gen, &conf->gen.extra,
5932 conf->gen.source = source;
5933 conf->gen.scontext = context;
5939 if (conf->gen.reset_source <= source)
5941 conf->reset_val = newval;
5942 set_extra_field(&conf->gen, &conf->reset_extra,
5944 conf->gen.reset_source = source;
5945 conf->gen.reset_scontext = context;
5947 for (stack = conf->gen.stack; stack; stack = stack->prev)
5949 if (stack->source <= source)
5951 stack->prior.val.intval = newval;
5952 set_extra_field(&conf->gen, &stack->prior.extra,
5954 stack->source = source;
5955 stack->scontext = context;
5960 /* Perhaps we didn't install newextra anywhere */
5961 if (newextra && !extra_field_used(&conf->gen, newextra))
5968 struct config_real *conf = (struct config_real *) record;
5970 void *newextra = NULL;
5974 if (!validate_conf_option(record, name, value, source,
5975 elevel, false, &newval,
5979 else if (source == PGC_S_DEFAULT)
5981 newval = conf->boot_val;
5982 if (!call_real_check_hook(conf, &newval, &newextra,
5988 newval = conf->reset_val;
5989 newextra = conf->reset_extra;
5990 source = conf->gen.reset_source;
5991 context = conf->gen.reset_scontext;
5994 if (prohibitValueChange)
5996 if (*conf->variable != newval)
5999 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6000 errmsg("parameter \"%s\" cannot be changed without restarting the server",
6009 /* Save old value to support transaction abort */
6011 push_old_value(&conf->gen, action);
6013 if (conf->assign_hook)
6014 (*conf->assign_hook) (newval, newextra);
6015 *conf->variable = newval;
6016 set_extra_field(&conf->gen, &conf->gen.extra,
6018 conf->gen.source = source;
6019 conf->gen.scontext = context;
6025 if (conf->gen.reset_source <= source)
6027 conf->reset_val = newval;
6028 set_extra_field(&conf->gen, &conf->reset_extra,
6030 conf->gen.reset_source = source;
6031 conf->gen.reset_scontext = context;
6033 for (stack = conf->gen.stack; stack; stack = stack->prev)
6035 if (stack->source <= source)
6037 stack->prior.val.realval = newval;
6038 set_extra_field(&conf->gen, &stack->prior.extra,
6040 stack->source = source;
6041 stack->scontext = context;
6046 /* Perhaps we didn't install newextra anywhere */
6047 if (newextra && !extra_field_used(&conf->gen, newextra))
6054 struct config_string *conf = (struct config_string *) record;
6056 void *newextra = NULL;
6060 if (!validate_conf_option(record, name, value, source,
6061 elevel, false, &newval,
6065 else if (source == PGC_S_DEFAULT)
6067 /* non-NULL boot_val must always get strdup'd */
6068 if (conf->boot_val != NULL)
6070 newval = guc_strdup(elevel, conf->boot_val);
6077 if (!call_string_check_hook(conf, &newval, &newextra,
6087 * strdup not needed, since reset_val is already under
6090 newval = conf->reset_val;
6091 newextra = conf->reset_extra;
6092 source = conf->gen.reset_source;
6093 context = conf->gen.reset_scontext;
6096 if (prohibitValueChange)
6098 /* newval shouldn't be NULL, so we're a bit sloppy here */
6099 if (*conf->variable == NULL || newval == NULL ||
6100 strcmp(*conf->variable, newval) != 0)
6103 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6104 errmsg("parameter \"%s\" cannot be changed without restarting the server",
6113 /* Save old value to support transaction abort */
6115 push_old_value(&conf->gen, action);
6117 if (conf->assign_hook)
6118 (*conf->assign_hook) (newval, newextra);
6119 set_string_field(conf, conf->variable, newval);
6120 set_extra_field(&conf->gen, &conf->gen.extra,
6122 conf->gen.source = source;
6123 conf->gen.scontext = context;
6130 if (conf->gen.reset_source <= source)
6132 set_string_field(conf, &conf->reset_val, newval);
6133 set_extra_field(&conf->gen, &conf->reset_extra,
6135 conf->gen.reset_source = source;
6136 conf->gen.reset_scontext = context;
6138 for (stack = conf->gen.stack; stack; stack = stack->prev)
6140 if (stack->source <= source)
6142 set_string_field(conf, &stack->prior.val.stringval,
6144 set_extra_field(&conf->gen, &stack->prior.extra,
6146 stack->source = source;
6147 stack->scontext = context;
6152 /* Perhaps we didn't install newval anywhere */
6153 if (newval && !string_field_used(conf, newval))
6155 /* Perhaps we didn't install newextra anywhere */
6156 if (newextra && !extra_field_used(&conf->gen, newextra))
6163 struct config_enum *conf = (struct config_enum *) record;
6165 void *newextra = NULL;
6169 if (!validate_conf_option(record, name, value, source,
6170 elevel, false, &newval,
6174 else if (source == PGC_S_DEFAULT)
6176 newval = conf->boot_val;
6177 if (!call_enum_check_hook(conf, &newval, &newextra,
6183 newval = conf->reset_val;
6184 newextra = conf->reset_extra;
6185 source = conf->gen.reset_source;
6186 context = conf->gen.reset_scontext;
6189 if (prohibitValueChange)
6191 if (*conf->variable != newval)
6194 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6195 errmsg("parameter \"%s\" cannot be changed without restarting the server",
6204 /* Save old value to support transaction abort */
6206 push_old_value(&conf->gen, action);
6208 if (conf->assign_hook)
6209 (*conf->assign_hook) (newval, newextra);
6210 *conf->variable = newval;
6211 set_extra_field(&conf->gen, &conf->gen.extra,
6213 conf->gen.source = source;
6214 conf->gen.scontext = context;
6220 if (conf->gen.reset_source <= source)
6222 conf->reset_val = newval;
6223 set_extra_field(&conf->gen, &conf->reset_extra,
6225 conf->gen.reset_source = source;
6226 conf->gen.reset_scontext = context;
6228 for (stack = conf->gen.stack; stack; stack = stack->prev)
6230 if (stack->source <= source)
6232 stack->prior.val.enumval = newval;
6233 set_extra_field(&conf->gen, &stack->prior.extra,
6235 stack->source = source;
6236 stack->scontext = context;
6241 /* Perhaps we didn't install newextra anywhere */
6242 if (newextra && !extra_field_used(&conf->gen, newextra))
6248 if (changeVal && (record->flags & GUC_REPORT))
6249 ReportGUCOption(record);
6251 return changeVal ? 1 : -1;
6256 * Set the fields for source file and line number the setting came from.
6259 set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
6261 struct config_generic *record;
6265 * To avoid cluttering the log, only the postmaster bleats loudly about
6266 * problems with the config file.
6268 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
6270 record = find_option(name, true, elevel);
6271 /* should not happen */
6273 elog(ERROR, "unrecognized configuration parameter \"%s\"", name);
6275 sourcefile = guc_strdup(elevel, sourcefile);
6276 if (record->sourcefile)
6277 free(record->sourcefile);
6278 record->sourcefile = sourcefile;
6279 record->sourceline = sourceline;
6283 * Set a config option to the given value.
6285 * See also set_config_option; this is just the wrapper to be called from
6286 * outside GUC. (This function should be used when possible, because its API
6287 * is more stable than set_config_option's.)
6289 * Note: there is no support here for setting source file/line, as it
6290 * is currently not needed.
6293 SetConfigOption(const char *name, const char *value,
6294 GucContext context, GucSource source)
6296 (void) set_config_option(name, value, context, source,
6297 GUC_ACTION_SET, true, 0);
6303 * Fetch the current value of the option `name', as a string.
6305 * If the option doesn't exist, return NULL if missing_ok is true (NOTE that
6306 * this cannot be distinguished from a string variable with a NULL value!),
6307 * otherwise throw an ereport and don't return.
6309 * If restrict_superuser is true, we also enforce that only superusers can
6310 * see GUC_SUPERUSER_ONLY variables. This should only be passed as true
6311 * in user-driven calls.
6313 * The string is *not* allocated for modification and is really only
6314 * valid until the next call to configuration related functions.
6317 GetConfigOption(const char *name, bool missing_ok, bool restrict_superuser)
6319 struct config_generic *record;
6320 static char buffer[256];
6322 record = find_option(name, false, ERROR);
6328 (errcode(ERRCODE_UNDEFINED_OBJECT),
6329 errmsg("unrecognized configuration parameter \"%s\"",
6332 if (restrict_superuser &&
6333 (record->flags & GUC_SUPERUSER_ONLY) &&
6336 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6337 errmsg("must be superuser to examine \"%s\"", name)));
6339 switch (record->vartype)
6342 return *((struct config_bool *) record)->variable ? "on" : "off";
6345 snprintf(buffer, sizeof(buffer), "%d",
6346 *((struct config_int *) record)->variable);
6350 snprintf(buffer, sizeof(buffer), "%g",
6351 *((struct config_real *) record)->variable);
6355 return *((struct config_string *) record)->variable;
6358 return config_enum_lookup_by_value((struct config_enum *) record,
6359 *((struct config_enum *) record)->variable);
6365 * Get the RESET value associated with the given option.
6367 * Note: this is not re-entrant, due to use of static result buffer;
6368 * not to mention that a string variable could have its reset_val changed.
6369 * Beware of assuming the result value is good for very long.
6372 GetConfigOptionResetString(const char *name)
6374 struct config_generic *record;
6375 static char buffer[256];
6377 record = find_option(name, false, ERROR);
6380 (errcode(ERRCODE_UNDEFINED_OBJECT),
6381 errmsg("unrecognized configuration parameter \"%s\"", name)));
6382 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
6384 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6385 errmsg("must be superuser to examine \"%s\"", name)));
6387 switch (record->vartype)
6390 return ((struct config_bool *) record)->reset_val ? "on" : "off";
6393 snprintf(buffer, sizeof(buffer), "%d",
6394 ((struct config_int *) record)->reset_val);
6398 snprintf(buffer, sizeof(buffer), "%g",
6399 ((struct config_real *) record)->reset_val);
6403 return ((struct config_string *) record)->reset_val;
6406 return config_enum_lookup_by_value((struct config_enum *) record,
6407 ((struct config_enum *) record)->reset_val);
6414 * flatten_set_variable_args
6415 * Given a parsenode List as emitted by the grammar for SET,
6416 * convert to the flat string representation used by GUC.
6418 * We need to be told the name of the variable the args are for, because
6419 * the flattening rules vary (ugh).
6421 * The result is NULL if args is NIL (ie, SET ... TO DEFAULT), otherwise
6422 * a palloc'd string.
6425 flatten_set_variable_args(const char *name, List *args)
6427 struct config_generic *record;
6432 /* Fast path if just DEFAULT */
6437 * Get flags for the variable; if it's not known, use default flags.
6438 * (Caller might throw error later, but not our business to do so here.)
6440 record = find_option(name, false, WARNING);
6442 flags = record->flags;
6446 /* Complain if list input and non-list variable */
6447 if ((flags & GUC_LIST_INPUT) == 0 &&
6448 list_length(args) != 1)
6450 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6451 errmsg("SET %s takes only one argument", name)));
6453 initStringInfo(&buf);
6456 * Each list member may be a plain A_Const node, or an A_Const within a
6457 * TypeCast; the latter case is supported only for ConstInterval arguments
6458 * (for SET TIME ZONE).
6462 Node *arg = (Node *) lfirst(l);
6464 TypeName *typeName = NULL;
6467 if (l != list_head(args))
6468 appendStringInfoString(&buf, ", ");
6470 if (IsA(arg, TypeCast))
6472 TypeCast *tc = (TypeCast *) arg;
6475 typeName = tc->typeName;
6478 if (!IsA(arg, A_Const))
6479 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
6480 con = (A_Const *) arg;
6482 switch (nodeTag(&con->val))
6485 appendStringInfo(&buf, "%ld", intVal(&con->val));
6488 /* represented as a string, so just copy it */
6489 appendStringInfoString(&buf, strVal(&con->val));
6492 val = strVal(&con->val);
6493 if (typeName != NULL)
6496 * Must be a ConstInterval argument for TIME ZONE. Coerce
6497 * to interval and back to normalize the value and account
6505 typenameTypeIdAndMod(NULL, typeName, &typoid, &typmod);
6506 Assert(typoid == INTERVALOID);
6509 DirectFunctionCall3(interval_in,
6510 CStringGetDatum(val),
6511 ObjectIdGetDatum(InvalidOid),
6512 Int32GetDatum(typmod));
6515 DatumGetCString(DirectFunctionCall1(interval_out,
6517 appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
6522 * Plain string literal or identifier. For quote mode,
6523 * quote it if it's not a vanilla identifier.
6525 if (flags & GUC_LIST_QUOTE)
6526 appendStringInfoString(&buf, quote_identifier(val));
6528 appendStringInfoString(&buf, val);
6532 elog(ERROR, "unrecognized node type: %d",
6533 (int) nodeTag(&con->val));
6542 * Write updated configuration parameter values into a temporary file.
6543 * This function traverses the list of parameters and quotes the string
6544 * values before writing them.
6547 write_auto_conf_file(int fd, const char *filename, ConfigVariable **head_p)
6549 ConfigVariable *item;
6552 initStringInfo(&buf);
6553 appendStringInfoString(&buf, "# Do not edit this file manually!\n");
6554 appendStringInfoString(&buf, "# It will be overwritten by ALTER SYSTEM command.\n");
6557 * write the file header message before contents, so that if there is no
6558 * item it can contain message
6560 if (write(fd, buf.data, buf.len) < 0)
6562 (errmsg("failed to write to \"%s\" file", filename)));
6563 resetStringInfo(&buf);
6566 * traverse the list of parameters, quote the string parameter and write
6567 * it to file. Once all parameters are written fsync the file.
6570 for (item = *head_p; item != NULL; item = item->next)
6574 appendStringInfoString(&buf, item->name);
6575 appendStringInfoString(&buf, " = ");
6577 appendStringInfoString(&buf, "\'");
6578 escaped = escape_single_quotes_ascii(item->value);
6579 appendStringInfoString(&buf, escaped);
6581 appendStringInfoString(&buf, "\'");
6583 appendStringInfoString(&buf, "\n");
6585 if (write(fd, buf.data, buf.len) < 0)
6587 (errmsg("failed to write to \"%s\" file", filename)));
6588 resetStringInfo(&buf);
6591 if (pg_fsync(fd) != 0)
6593 (errcode_for_file_access(),
6594 errmsg("could not fsync file \"%s\": %m", filename)));
6601 * This function takes list of all configuration parameters in
6602 * PG_AUTOCONF_FILENAME and parameter to be updated as input arguments and
6603 * replace the updated configuration parameter value in a list. If the
6604 * parameter to be updated is new then it is appended to the list of
6608 replace_auto_config_value(ConfigVariable **head_p, ConfigVariable **tail_p,
6610 char *name, char *value)
6612 ConfigVariable *item,
6615 if (*head_p != NULL)
6617 for (item = *head_p; item != NULL; item = item->next)
6619 if (strcmp(item->name, name) == 0)
6623 /* update the parameter value */
6624 item->value = pstrdup(value);
6627 /* delete the configuration parameter from list */
6628 if (*head_p == item)
6629 *head_p = item->next;
6631 prev->next = item->next;
6633 if (*tail_p == item)
6637 pfree(item->filename);
6649 item = palloc(sizeof *item);
6650 item->name = pstrdup(name);
6651 item->value = pstrdup(value);
6652 item->filename = pstrdup(config_file);
6655 if (*head_p == NULL)
6657 item->sourceline = 1;
6662 item->sourceline = (*tail_p)->sourceline + 1;
6663 (*tail_p)->next = item;
6673 * Persist the configuration parameter value.
6675 * This function takes all previous configuration parameters
6676 * set by ALTER SYSTEM command and the currently set ones
6677 * and write them all to the automatic configuration file.
6679 * The configuration parameters are written to a temporary
6680 * file then renamed to the final name.
6682 * An LWLock is used to serialize writing to the same file.
6684 * In case of an error, we leave the original automatic
6685 * configuration file (PG_AUTOCONF_FILENAME) intact.
6688 AlterSystemSetConfigFile(AlterSystemStmt *altersysstmt)
6694 struct config_generic *record;
6695 ConfigVariable *head = NULL;
6696 ConfigVariable *tail = NULL;
6697 char AutoConfFileName[MAXPGPATH];
6698 char AutoConfTmpFileName[MAXPGPATH];
6700 void *newextra = NULL;
6704 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6705 (errmsg("must be superuser to execute ALTER SYSTEM command"))));
6708 * Validate the name and arguments [value1, value2 ... ].
6710 name = altersysstmt->setstmt->name;
6712 switch (altersysstmt->setstmt->kind)
6715 value = ExtractSetVariableArgs(altersysstmt->setstmt);
6718 case VAR_SET_DEFAULT:
6722 elog(ERROR, "unrecognized alter system stmt type: %d",
6723 altersysstmt->setstmt->kind);
6727 record = find_option(name, false, LOG);
6730 (errcode(ERRCODE_UNDEFINED_OBJECT),
6731 errmsg("unrecognized configuration parameter \"%s\"", name)));
6733 if ((record->context == PGC_INTERNAL) ||
6734 (record->flags & GUC_DISALLOW_IN_FILE))
6736 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6737 errmsg("parameter \"%s\" cannot be changed",
6740 if (!validate_conf_option(record, name, value, PGC_S_FILE,
6744 (errmsg("invalid value for parameter \"%s\": \"%s\"", name, value)));
6748 * Use data directory as reference path for PG_AUTOCONF_FILENAME and its
6749 * corresponding temporary file.
6751 join_path_components(AutoConfFileName, data_directory, PG_AUTOCONF_FILENAME);
6752 canonicalize_path(AutoConfFileName);
6753 snprintf(AutoConfTmpFileName, sizeof(AutoConfTmpFileName), "%s.%s",
6758 * One backend is allowed to operate on file PG_AUTOCONF_FILENAME, to
6759 * ensure that we need to update the contents of the file with
6760 * AutoFileLock. To ensure crash safety, first the contents are written to
6761 * a temporary file which is then renameed to PG_AUTOCONF_FILENAME. In
6762 * case there exists a temp file from previous crash, that can be reused.
6765 LWLockAcquire(AutoFileLock, LW_EXCLUSIVE);
6767 Tmpfd = open(AutoConfTmpFileName, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
6770 (errcode_for_file_access(),
6771 errmsg("failed to open auto conf temp file \"%s\": %m ",
6772 AutoConfTmpFileName)));
6776 if (stat(AutoConfFileName, &st) == 0)
6778 /* open file PG_AUTOCONF_FILENAME */
6779 infile = AllocateFile(AutoConfFileName, "r");
6782 (errmsg("failed to open auto conf file \"%s\": %m ",
6783 AutoConfFileName)));
6786 ParseConfigFp(infile, AutoConfFileName, 0, LOG, &head, &tail);
6792 * replace with new value if the configuration parameter already
6793 * exists OR add it as a new cofiguration parameter in the file.
6795 replace_auto_config_value(&head, &tail, AutoConfFileName, name, value);
6797 /* Write and sync the new contents to the temporary file */
6798 write_auto_conf_file(Tmpfd, AutoConfTmpFileName, &head);
6804 * As the rename is atomic operation, if any problem occurs after this
6805 * at max it can loose the parameters set by last ALTER SYSTEM
6808 if (rename(AutoConfTmpFileName, AutoConfFileName) < 0)
6810 (errcode_for_file_access(),
6811 errmsg("could not rename file \"%s\" to \"%s\" : %m",
6812 AutoConfTmpFileName, AutoConfFileName)));
6819 unlink(AutoConfTmpFileName);
6820 FreeConfigVariables(head);
6825 FreeConfigVariables(head);
6826 LWLockRelease(AutoFileLock);
6834 ExecSetVariableStmt(VariableSetStmt *stmt, bool isTopLevel)
6836 GucAction action = stmt->is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET;
6841 case VAR_SET_CURRENT:
6843 WarnNoTransactionChain(isTopLevel, "SET LOCAL");
6844 (void) set_config_option(stmt->name,
6845 ExtractSetVariableArgs(stmt),
6846 (superuser() ? PGC_SUSET : PGC_USERSET),
6855 * Special-case SQL syntaxes. The TRANSACTION and SESSION
6856 * CHARACTERISTICS cases effectively set more than one variable
6857 * per statement. TRANSACTION SNAPSHOT only takes one argument,
6858 * but we put it here anyway since it's a special case and not
6859 * related to any GUC variable.
6861 if (strcmp(stmt->name, "TRANSACTION") == 0)
6865 WarnNoTransactionChain(isTopLevel, "SET TRANSACTION");
6867 foreach(head, stmt->args)
6869 DefElem *item = (DefElem *) lfirst(head);
6871 if (strcmp(item->defname, "transaction_isolation") == 0)
6872 SetPGVariable("transaction_isolation",
6873 list_make1(item->arg), stmt->is_local);
6874 else if (strcmp(item->defname, "transaction_read_only") == 0)
6875 SetPGVariable("transaction_read_only",
6876 list_make1(item->arg), stmt->is_local);
6877 else if (strcmp(item->defname, "transaction_deferrable") == 0)
6878 SetPGVariable("transaction_deferrable",
6879 list_make1(item->arg), stmt->is_local);
6881 elog(ERROR, "unexpected SET TRANSACTION element: %s",
6885 else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
6889 foreach(head, stmt->args)
6891 DefElem *item = (DefElem *) lfirst(head);
6893 if (strcmp(item->defname, "transaction_isolation") == 0)
6894 SetPGVariable("default_transaction_isolation",
6895 list_make1(item->arg), stmt->is_local);
6896 else if (strcmp(item->defname, "transaction_read_only") == 0)
6897 SetPGVariable("default_transaction_read_only",
6898 list_make1(item->arg), stmt->is_local);
6899 else if (strcmp(item->defname, "transaction_deferrable") == 0)
6900 SetPGVariable("default_transaction_deferrable",
6901 list_make1(item->arg), stmt->is_local);
6903 elog(ERROR, "unexpected SET SESSION element: %s",
6907 else if (strcmp(stmt->name, "TRANSACTION SNAPSHOT") == 0)
6909 A_Const *con = (A_Const *) linitial(stmt->args);
6913 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6914 errmsg("SET LOCAL TRANSACTION SNAPSHOT is not implemented")));
6916 WarnNoTransactionChain(isTopLevel, "SET TRANSACTION");
6917 Assert(IsA(con, A_Const));
6918 Assert(nodeTag(&con->val) == T_String);
6919 ImportSnapshot(strVal(&con->val));
6922 elog(ERROR, "unexpected SET MULTI element: %s",
6925 case VAR_SET_DEFAULT:
6927 WarnNoTransactionChain(isTopLevel, "SET LOCAL");
6930 if (strcmp(stmt->name, "transaction_isolation") == 0)
6931 WarnNoTransactionChain(isTopLevel, "RESET TRANSACTION");
6933 (void) set_config_option(stmt->name,
6935 (superuser() ? PGC_SUSET : PGC_USERSET),
6948 * Get the value to assign for a VariableSetStmt, or NULL if it's RESET.
6949 * The result is palloc'd.
6951 * This is exported for use by actions such as ALTER ROLE SET.
6954 ExtractSetVariableArgs(VariableSetStmt *stmt)
6959 return flatten_set_variable_args(stmt->name, stmt->args);
6960 case VAR_SET_CURRENT:
6961 return GetConfigOptionByName(stmt->name, NULL);
6968 * SetPGVariable - SET command exported as an easily-C-callable function.
6970 * This provides access to SET TO value, as well as SET TO DEFAULT (expressed
6971 * by passing args == NIL), but not SET FROM CURRENT functionality.
6974 SetPGVariable(const char *name, List *args, bool is_local)
6976 char *argstring = flatten_set_variable_args(name, args);
6978 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
6979 (void) set_config_option(name,
6981 (superuser() ? PGC_SUSET : PGC_USERSET),
6983 is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET,
6989 * SET command wrapped as a SQL callable function.
6992 set_config_by_name(PG_FUNCTION_ARGS)
6999 if (PG_ARGISNULL(0))
7001 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
7002 errmsg("SET requires parameter name")));
7004 /* Get the GUC variable name */
7005 name = TextDatumGetCString(PG_GETARG_DATUM(0));
7007 /* Get the desired value or set to NULL for a reset request */
7008 if (PG_ARGISNULL(1))
7011 value = TextDatumGetCString(PG_GETARG_DATUM(1));
7014 * Get the desired state of is_local. Default to false if provided value
7017 if (PG_ARGISNULL(2))
7020 is_local = PG_GETARG_BOOL(2);
7022 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
7023 (void) set_config_option(name,
7025 (superuser() ? PGC_SUSET : PGC_USERSET),
7027 is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET,
7031 /* get the new current value */
7032 new_value = GetConfigOptionByName(name, NULL);
7034 /* Convert return string to text */
7035 PG_RETURN_TEXT_P(cstring_to_text(new_value));
7040 * Common code for DefineCustomXXXVariable subroutines: allocate the
7041 * new variable's config struct and fill in generic fields.
7043 static struct config_generic *
7044 init_custom_variable(const char *name,
7045 const char *short_desc,
7046 const char *long_desc,
7049 enum config_type type,
7052 struct config_generic *gen;
7055 * Only allow custom PGC_POSTMASTER variables to be created during shared
7056 * library preload; any later than that, we can't ensure that the value
7057 * doesn't change after startup. This is a fatal elog if it happens; just
7058 * erroring out isn't safe because we don't know what the calling loadable
7059 * module might already have hooked into.
7061 if (context == PGC_POSTMASTER &&
7062 !process_shared_preload_libraries_in_progress)
7063 elog(FATAL, "cannot create PGC_POSTMASTER variables after startup");
7065 gen = (struct config_generic *) guc_malloc(ERROR, sz);
7068 gen->name = guc_strdup(ERROR, name);
7069 gen->context = context;
7070 gen->group = CUSTOM_OPTIONS;
7071 gen->short_desc = short_desc;
7072 gen->long_desc = long_desc;
7074 gen->vartype = type;
7080 * Common code for DefineCustomXXXVariable subroutines: insert the new
7081 * variable into the GUC variable array, replacing any placeholder.
7084 define_custom_variable(struct config_generic * variable)
7086 const char *name = variable->name;
7087 const char **nameAddr = &name;
7088 struct config_string *pHolder;
7089 struct config_generic **res;
7092 * See if there's a placeholder by the same name.
7094 res = (struct config_generic **) bsearch((void *) &nameAddr,
7095 (void *) guc_variables,
7097 sizeof(struct config_generic *),
7102 * No placeholder to replace, so we can just add it ... but first,
7103 * make sure it's initialized to its default value.
7105 InitializeOneGUCOption(variable);
7106 add_guc_variable(variable, ERROR);
7111 * This better be a placeholder
7113 if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
7115 (errcode(ERRCODE_INTERNAL_ERROR),
7116 errmsg("attempt to redefine parameter \"%s\"", name)));
7118 Assert((*res)->vartype == PGC_STRING);
7119 pHolder = (struct config_string *) (*res);
7122 * First, set the variable to its default value. We must do this even
7123 * though we intend to immediately apply a new value, since it's possible
7124 * that the new value is invalid.
7126 InitializeOneGUCOption(variable);
7129 * Replace the placeholder. We aren't changing the name, so no re-sorting
7135 * Assign the string value(s) stored in the placeholder to the real
7136 * variable. Essentially, we need to duplicate all the active and stacked
7137 * values, but with appropriate validation and datatype adjustment.
7139 * If an assignment fails, we report a WARNING and keep going. We don't
7140 * want to throw ERROR for bad values, because it'd bollix the add-on
7141 * module that's presumably halfway through getting loaded. In such cases
7142 * the default or previous state will become active instead.
7145 /* First, apply the reset value if any */
7146 if (pHolder->reset_val)
7147 (void) set_config_option(name, pHolder->reset_val,
7148 pHolder->gen.reset_scontext,
7149 pHolder->gen.reset_source,
7150 GUC_ACTION_SET, true, WARNING);
7151 /* That should not have resulted in stacking anything */
7152 Assert(variable->stack == NULL);
7154 /* Now, apply current and stacked values, in the order they were stacked */
7155 reapply_stacked_values(variable, pHolder, pHolder->gen.stack,
7156 *(pHolder->variable),
7157 pHolder->gen.scontext, pHolder->gen.source);
7159 /* Also copy over any saved source-location information */
7160 if (pHolder->gen.sourcefile)
7161 set_config_sourcefile(name, pHolder->gen.sourcefile,
7162 pHolder->gen.sourceline);
7165 * Free up as much as we conveniently can of the placeholder structure.
7166 * (This neglects any stack items, so it's possible for some memory to be
7167 * leaked. Since this can only happen once per session per variable, it
7168 * doesn't seem worth spending much code on.)
7170 set_string_field(pHolder, pHolder->variable, NULL);
7171 set_string_field(pHolder, &pHolder->reset_val, NULL);
7177 * Recursive subroutine for define_custom_variable: reapply non-reset values
7179 * We recurse so that the values are applied in the same order as originally.
7180 * At each recursion level, apply the upper-level value (passed in) in the
7181 * fashion implied by the stack entry.
7184 reapply_stacked_values(struct config_generic * variable,
7185 struct config_string * pHolder,
7187 const char *curvalue,
7188 GucContext curscontext, GucSource cursource)
7190 const char *name = variable->name;
7191 GucStack *oldvarstack = variable->stack;
7195 /* First, recurse, so that stack items are processed bottom to top */
7196 reapply_stacked_values(variable, pHolder, stack->prev,
7197 stack->prior.val.stringval,
7198 stack->scontext, stack->source);
7200 /* See how to apply the passed-in value */
7201 switch (stack->state)
7204 (void) set_config_option(name, curvalue,
7205 curscontext, cursource,
7206 GUC_ACTION_SAVE, true, WARNING);
7210 (void) set_config_option(name, curvalue,
7211 curscontext, cursource,
7212 GUC_ACTION_SET, true, WARNING);
7216 (void) set_config_option(name, curvalue,
7217 curscontext, cursource,
7218 GUC_ACTION_LOCAL, true, WARNING);
7222 /* first, apply the masked value as SET */
7223 (void) set_config_option(name, stack->masked.val.stringval,
7224 stack->masked_scontext, PGC_S_SESSION,
7225 GUC_ACTION_SET, true, WARNING);
7226 /* then apply the current value as LOCAL */
7227 (void) set_config_option(name, curvalue,
7228 curscontext, cursource,
7229 GUC_ACTION_LOCAL, true, WARNING);
7233 /* If we successfully made a stack entry, adjust its nest level */
7234 if (variable->stack != oldvarstack)
7235 variable->stack->nest_level = stack->nest_level;
7240 * We are at the end of the stack. If the active/previous value is
7241 * different from the reset value, it must represent a previously
7242 * committed session value. Apply it, and then drop the stack entry
7243 * that set_config_option will have created under the impression that
7244 * this is to be just a transactional assignment. (We leak the stack
7247 if (curvalue != pHolder->reset_val ||
7248 curscontext != pHolder->gen.reset_scontext ||
7249 cursource != pHolder->gen.reset_source)
7251 (void) set_config_option(name, curvalue,
7252 curscontext, cursource,
7253 GUC_ACTION_SET, true, WARNING);
7254 variable->stack = NULL;
7260 DefineCustomBoolVariable(const char *name,
7261 const char *short_desc,
7262 const char *long_desc,
7267 GucBoolCheckHook check_hook,
7268 GucBoolAssignHook assign_hook,
7269 GucShowHook show_hook)
7271 struct config_bool *var;
7273 var = (struct config_bool *)
7274 init_custom_variable(name, short_desc, long_desc, context, flags,
7275 PGC_BOOL, sizeof(struct config_bool));
7276 var->variable = valueAddr;
7277 var->boot_val = bootValue;
7278 var->reset_val = bootValue;
7279 var->check_hook = check_hook;
7280 var->assign_hook = assign_hook;
7281 var->show_hook = show_hook;
7282 define_custom_variable(&var->gen);
7286 DefineCustomIntVariable(const char *name,
7287 const char *short_desc,
7288 const char *long_desc,
7295 GucIntCheckHook check_hook,
7296 GucIntAssignHook assign_hook,
7297 GucShowHook show_hook)
7299 struct config_int *var;
7301 var = (struct config_int *)
7302 init_custom_variable(name, short_desc, long_desc, context, flags,
7303 PGC_INT, sizeof(struct config_int));
7304 var->variable = valueAddr;
7305 var->boot_val = bootValue;
7306 var->reset_val = bootValue;
7307 var->min = minValue;
7308 var->max = maxValue;
7309 var->check_hook = check_hook;
7310 var->assign_hook = assign_hook;
7311 var->show_hook = show_hook;
7312 define_custom_variable(&var->gen);
7316 DefineCustomRealVariable(const char *name,
7317 const char *short_desc,
7318 const char *long_desc,
7325 GucRealCheckHook check_hook,
7326 GucRealAssignHook assign_hook,
7327 GucShowHook show_hook)
7329 struct config_real *var;
7331 var = (struct config_real *)
7332 init_custom_variable(name, short_desc, long_desc, context, flags,
7333 PGC_REAL, sizeof(struct config_real));
7334 var->variable = valueAddr;
7335 var->boot_val = bootValue;
7336 var->reset_val = bootValue;
7337 var->min = minValue;
7338 var->max = maxValue;
7339 var->check_hook = check_hook;
7340 var->assign_hook = assign_hook;
7341 var->show_hook = show_hook;
7342 define_custom_variable(&var->gen);
7346 DefineCustomStringVariable(const char *name,
7347 const char *short_desc,
7348 const char *long_desc,
7350 const char *bootValue,
7353 GucStringCheckHook check_hook,
7354 GucStringAssignHook assign_hook,
7355 GucShowHook show_hook)
7357 struct config_string *var;
7359 var = (struct config_string *)
7360 init_custom_variable(name, short_desc, long_desc, context, flags,
7361 PGC_STRING, sizeof(struct config_string));
7362 var->variable = valueAddr;
7363 var->boot_val = bootValue;
7364 var->check_hook = check_hook;
7365 var->assign_hook = assign_hook;
7366 var->show_hook = show_hook;
7367 define_custom_variable(&var->gen);
7371 DefineCustomEnumVariable(const char *name,
7372 const char *short_desc,
7373 const char *long_desc,
7376 const struct config_enum_entry * options,
7379 GucEnumCheckHook check_hook,
7380 GucEnumAssignHook assign_hook,
7381 GucShowHook show_hook)
7383 struct config_enum *var;
7385 var = (struct config_enum *)
7386 init_custom_variable(name, short_desc, long_desc, context, flags,
7387 PGC_ENUM, sizeof(struct config_enum));
7388 var->variable = valueAddr;
7389 var->boot_val = bootValue;
7390 var->reset_val = bootValue;
7391 var->options = options;
7392 var->check_hook = check_hook;
7393 var->assign_hook = assign_hook;
7394 var->show_hook = show_hook;
7395 define_custom_variable(&var->gen);
7399 EmitWarningsOnPlaceholders(const char *className)
7401 int classLen = strlen(className);
7404 for (i = 0; i < num_guc_variables; i++)
7406 struct config_generic *var = guc_variables[i];
7408 if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
7409 strncmp(className, var->name, classLen) == 0 &&
7410 var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
7413 (errcode(ERRCODE_UNDEFINED_OBJECT),
7414 errmsg("unrecognized configuration parameter \"%s\"",
7425 GetPGVariable(const char *name, DestReceiver *dest)
7427 if (guc_name_compare(name, "all") == 0)
7428 ShowAllGUCConfig(dest);
7430 ShowGUCConfigOption(name, dest);
7434 GetPGVariableResultDesc(const char *name)
7438 if (guc_name_compare(name, "all") == 0)
7440 /* need a tuple descriptor representing three TEXT columns */
7441 tupdesc = CreateTemplateTupleDesc(3, false);
7442 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
7444 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
7446 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
7451 const char *varname;
7453 /* Get the canonical spelling of name */
7454 (void) GetConfigOptionByName(name, &varname);
7456 /* need a tuple descriptor representing a single TEXT column */
7457 tupdesc = CreateTemplateTupleDesc(1, false);
7458 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
7469 ShowGUCConfigOption(const char *name, DestReceiver *dest)
7471 TupOutputState *tstate;
7473 const char *varname;
7476 /* Get the value and canonical spelling of name */
7477 value = GetConfigOptionByName(name, &varname);
7479 /* need a tuple descriptor representing a single TEXT column */
7480 tupdesc = CreateTemplateTupleDesc(1, false);
7481 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
7484 /* prepare for projection of tuples */
7485 tstate = begin_tup_output_tupdesc(dest, tupdesc);
7488 do_text_output_oneline(tstate, value);
7490 end_tup_output(tstate);
7497 ShowAllGUCConfig(DestReceiver *dest)
7499 bool am_superuser = superuser();
7501 TupOutputState *tstate;
7504 bool isnull[3] = {false, false, false};
7506 /* need a tuple descriptor representing three TEXT columns */
7507 tupdesc = CreateTemplateTupleDesc(3, false);
7508 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
7510 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
7512 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
7515 /* prepare for projection of tuples */
7516 tstate = begin_tup_output_tupdesc(dest, tupdesc);
7518 for (i = 0; i < num_guc_variables; i++)
7520 struct config_generic *conf = guc_variables[i];
7523 if ((conf->flags & GUC_NO_SHOW_ALL) ||
7524 ((conf->flags & GUC_SUPERUSER_ONLY) && !am_superuser))
7527 /* assign to the values array */
7528 values[0] = PointerGetDatum(cstring_to_text(conf->name));
7530 setting = _ShowOption(conf, true);
7533 values[1] = PointerGetDatum(cstring_to_text(setting));
7538 values[1] = PointerGetDatum(NULL);
7542 values[2] = PointerGetDatum(cstring_to_text(conf->short_desc));
7544 /* send it to dest */
7545 do_tup_output(tstate, values, isnull);
7548 pfree(DatumGetPointer(values[0]));
7552 pfree(DatumGetPointer(values[1]));
7554 pfree(DatumGetPointer(values[2]));
7557 end_tup_output(tstate);
7561 * Return GUC variable value by name; optionally return canonical
7562 * form of name. Return value is palloc'd.
7565 GetConfigOptionByName(const char *name, const char **varname)
7567 struct config_generic *record;
7569 record = find_option(name, false, ERROR);
7572 (errcode(ERRCODE_UNDEFINED_OBJECT),
7573 errmsg("unrecognized configuration parameter \"%s\"", name)));
7574 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
7576 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7577 errmsg("must be superuser to examine \"%s\"", name)));
7580 *varname = record->name;
7582 return _ShowOption(record, true);
7586 * Return GUC variable value by variable number; optionally return canonical
7587 * form of name. Return value is palloc'd.
7590 GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
7593 struct config_generic *conf;
7595 /* check requested variable number valid */
7596 Assert((varnum >= 0) && (varnum < num_guc_variables));
7598 conf = guc_variables[varnum];
7602 if ((conf->flags & GUC_NO_SHOW_ALL) ||
7603 ((conf->flags & GUC_SUPERUSER_ONLY) && !superuser()))
7609 /* first get the generic attributes */
7612 values[0] = conf->name;
7614 /* setting : use _ShowOption in order to avoid duplicating the logic */
7615 values[1] = _ShowOption(conf, false);
7618 if (conf->vartype == PGC_INT)
7622 switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
7627 case GUC_UNIT_BLOCKS:
7628 snprintf(buf, sizeof(buf), "%dkB", BLCKSZ / 1024);
7631 case GUC_UNIT_XBLOCKS:
7632 snprintf(buf, sizeof(buf), "%dkB", XLOG_BLCKSZ / 1024);
7653 values[3] = config_group_names[conf->group];
7656 values[4] = conf->short_desc;
7659 values[5] = conf->long_desc;
7662 values[6] = GucContext_Names[conf->context];
7665 values[7] = config_type_names[conf->vartype];
7668 values[8] = GucSource_Names[conf->source];
7670 /* now get the type specifc attributes */
7671 switch (conf->vartype)
7675 struct config_bool *lconf = (struct config_bool *) conf;
7687 values[12] = pstrdup(lconf->boot_val ? "on" : "off");
7690 values[13] = pstrdup(lconf->reset_val ? "on" : "off");
7696 struct config_int *lconf = (struct config_int *) conf;
7699 snprintf(buffer, sizeof(buffer), "%d", lconf->min);
7700 values[9] = pstrdup(buffer);
7703 snprintf(buffer, sizeof(buffer), "%d", lconf->max);
7704 values[10] = pstrdup(buffer);
7710 snprintf(buffer, sizeof(buffer), "%d", lconf->boot_val);
7711 values[12] = pstrdup(buffer);
7714 snprintf(buffer, sizeof(buffer), "%d", lconf->reset_val);
7715 values[13] = pstrdup(buffer);
7721 struct config_real *lconf = (struct config_real *) conf;
7724 snprintf(buffer, sizeof(buffer), "%g", lconf->min);
7725 values[9] = pstrdup(buffer);
7728 snprintf(buffer, sizeof(buffer), "%g", lconf->max);
7729 values[10] = pstrdup(buffer);
7735 snprintf(buffer, sizeof(buffer), "%g", lconf->boot_val);
7736 values[12] = pstrdup(buffer);
7739 snprintf(buffer, sizeof(buffer), "%g", lconf->reset_val);
7740 values[13] = pstrdup(buffer);
7746 struct config_string *lconf = (struct config_string *) conf;
7758 if (lconf->boot_val == NULL)
7761 values[12] = pstrdup(lconf->boot_val);
7764 if (lconf->reset_val == NULL)
7767 values[13] = pstrdup(lconf->reset_val);
7773 struct config_enum *lconf = (struct config_enum *) conf;
7784 * NOTE! enumvals with double quotes in them are not
7787 values[11] = config_enum_get_options((struct config_enum *) conf,
7788 "{\"", "\"}", "\",\"");
7791 values[12] = pstrdup(config_enum_lookup_by_value(lconf,
7795 values[13] = pstrdup(config_enum_lookup_by_value(lconf,
7803 * should never get here, but in case we do, set 'em to NULL
7825 * If the setting came from a config file, set the source location. For
7826 * security reasons, we don't show source file/line number for
7829 if (conf->source == PGC_S_FILE && superuser())
7831 values[14] = conf->sourcefile;
7832 snprintf(buffer, sizeof(buffer), "%d", conf->sourceline);
7833 values[15] = pstrdup(buffer);
7843 * Return the total number of GUC variables
7846 GetNumConfigOptions(void)
7848 return num_guc_variables;
7852 * show_config_by_name - equiv to SHOW X command but implemented as
7856 show_config_by_name(PG_FUNCTION_ARGS)
7861 /* Get the GUC variable name */
7862 varname = TextDatumGetCString(PG_GETARG_DATUM(0));
7865 varval = GetConfigOptionByName(varname, NULL);
7867 /* Convert to text */
7868 PG_RETURN_TEXT_P(cstring_to_text(varval));
7872 * show_all_settings - equiv to SHOW ALL command but implemented as
7875 #define NUM_PG_SETTINGS_ATTS 16
7878 show_all_settings(PG_FUNCTION_ARGS)
7880 FuncCallContext *funcctx;
7884 AttInMetadata *attinmeta;
7885 MemoryContext oldcontext;
7887 /* stuff done only on the first call of the function */
7888 if (SRF_IS_FIRSTCALL())
7890 /* create a function context for cross-call persistence */
7891 funcctx = SRF_FIRSTCALL_INIT();
7894 * switch to memory context appropriate for multiple function calls
7896 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
7899 * need a tuple descriptor representing NUM_PG_SETTINGS_ATTS columns
7900 * of the appropriate types
7902 tupdesc = CreateTemplateTupleDesc(NUM_PG_SETTINGS_ATTS, false);
7903 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
7905 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
7907 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "unit",
7909 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "category",
7911 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "short_desc",
7913 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "extra_desc",
7915 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "context",
7917 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "vartype",
7919 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "source",
7921 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "min_val",
7923 TupleDescInitEntry(tupdesc, (AttrNumber) 11, "max_val",
7925 TupleDescInitEntry(tupdesc, (AttrNumber) 12, "enumvals",
7926 TEXTARRAYOID, -1, 0);
7927 TupleDescInitEntry(tupdesc, (AttrNumber) 13, "boot_val",
7929 TupleDescInitEntry(tupdesc, (AttrNumber) 14, "reset_val",
7931 TupleDescInitEntry(tupdesc, (AttrNumber) 15, "sourcefile",
7933 TupleDescInitEntry(tupdesc, (AttrNumber) 16, "sourceline",
7937 * Generate attribute metadata needed later to produce tuples from raw
7940 attinmeta = TupleDescGetAttInMetadata(tupdesc);
7941 funcctx->attinmeta = attinmeta;
7943 /* total number of tuples to be returned */
7944 funcctx->max_calls = GetNumConfigOptions();
7946 MemoryContextSwitchTo(oldcontext);
7949 /* stuff done on every call of the function */
7950 funcctx = SRF_PERCALL_SETUP();
7952 call_cntr = funcctx->call_cntr;
7953 max_calls = funcctx->max_calls;
7954 attinmeta = funcctx->attinmeta;
7956 if (call_cntr < max_calls) /* do when there is more left to send */
7958 char *values[NUM_PG_SETTINGS_ATTS];
7964 * Get the next visible GUC variable name and value
7968 GetConfigOptionByNum(call_cntr, (const char **) values, &noshow);
7971 /* bump the counter and get the next config setting */
7972 call_cntr = ++funcctx->call_cntr;
7974 /* make sure we haven't gone too far now */
7975 if (call_cntr >= max_calls)
7976 SRF_RETURN_DONE(funcctx);
7981 tuple = BuildTupleFromCStrings(attinmeta, values);
7983 /* make the tuple into a datum */
7984 result = HeapTupleGetDatum(tuple);
7986 SRF_RETURN_NEXT(funcctx, result);
7990 /* do when there is no more left */
7991 SRF_RETURN_DONE(funcctx);
7996 _ShowOption(struct config_generic * record, bool use_units)
8001 switch (record->vartype)
8005 struct config_bool *conf = (struct config_bool *) record;
8007 if (conf->show_hook)
8008 val = (*conf->show_hook) ();
8010 val = *conf->variable ? "on" : "off";
8016 struct config_int *conf = (struct config_int *) record;
8018 if (conf->show_hook)
8019 val = (*conf->show_hook) ();
8023 * Use int64 arithmetic to avoid overflows in units
8026 int64 result = *conf->variable;
8029 if (use_units && result > 0 &&
8030 (record->flags & GUC_UNIT_MEMORY))
8032 switch (record->flags & GUC_UNIT_MEMORY)
8034 case GUC_UNIT_BLOCKS:
8035 result *= BLCKSZ / 1024;
8037 case GUC_UNIT_XBLOCKS:
8038 result *= XLOG_BLCKSZ / 1024;
8042 if (result % KB_PER_TB == 0)
8044 result /= KB_PER_TB;
8047 else if (result % KB_PER_GB == 0)
8049 result /= KB_PER_GB;
8052 else if (result % KB_PER_MB == 0)
8054 result /= KB_PER_MB;
8062 else if (use_units && result > 0 &&
8063 (record->flags & GUC_UNIT_TIME))
8065 switch (record->flags & GUC_UNIT_TIME)
8071 result *= MS_PER_MIN;
8075 if (result % MS_PER_D == 0)
8080 else if (result % MS_PER_H == 0)
8085 else if (result % MS_PER_MIN == 0)
8087 result /= MS_PER_MIN;
8090 else if (result % MS_PER_S == 0)
8103 snprintf(buffer, sizeof(buffer), INT64_FORMAT "%s",
8112 struct config_real *conf = (struct config_real *) record;
8114 if (conf->show_hook)
8115 val = (*conf->show_hook) ();
8118 snprintf(buffer, sizeof(buffer), "%g",
8127 struct config_string *conf = (struct config_string *) record;
8129 if (conf->show_hook)
8130 val = (*conf->show_hook) ();
8131 else if (*conf->variable && **conf->variable)
8132 val = *conf->variable;
8140 struct config_enum *conf = (struct config_enum *) record;
8142 if (conf->show_hook)
8143 val = (*conf->show_hook) ();
8145 val = config_enum_lookup_by_value(conf, *conf->variable);
8150 /* just to keep compiler quiet */
8155 return pstrdup(val);
8162 * These routines dump out all non-default GUC options into a binary
8163 * file that is read by all exec'ed backends. The format is:
8165 * variable name, string, null terminated
8166 * variable value, string, null terminated
8167 * variable sourcefile, string, null terminated (empty if none)
8168 * variable sourceline, integer
8169 * variable source, integer
8170 * variable scontext, integer
8173 write_one_nondefault_variable(FILE *fp, struct config_generic * gconf)
8175 if (gconf->source == PGC_S_DEFAULT)
8178 fprintf(fp, "%s", gconf->name);
8181 switch (gconf->vartype)
8185 struct config_bool *conf = (struct config_bool *) gconf;
8187 if (*conf->variable)
8188 fprintf(fp, "true");
8190 fprintf(fp, "false");
8196 struct config_int *conf = (struct config_int *) gconf;
8198 fprintf(fp, "%d", *conf->variable);
8204 struct config_real *conf = (struct config_real *) gconf;
8206 fprintf(fp, "%.17g", *conf->variable);
8212 struct config_string *conf = (struct config_string *) gconf;
8214 fprintf(fp, "%s", *conf->variable);
8220 struct config_enum *conf = (struct config_enum *) gconf;
8223 config_enum_lookup_by_value(conf, *conf->variable));
8230 if (gconf->sourcefile)
8231 fprintf(fp, "%s", gconf->sourcefile);
8234 fwrite(&gconf->sourceline, 1, sizeof(gconf->sourceline), fp);
8235 fwrite(&gconf->source, 1, sizeof(gconf->source), fp);
8236 fwrite(&gconf->scontext, 1, sizeof(gconf->scontext), fp);
8240 write_nondefault_variables(GucContext context)
8246 Assert(context == PGC_POSTMASTER || context == PGC_SIGHUP);
8248 elevel = (context == PGC_SIGHUP) ? LOG : ERROR;
8253 fp = AllocateFile(CONFIG_EXEC_PARAMS_NEW, "w");
8257 (errcode_for_file_access(),
8258 errmsg("could not write to file \"%s\": %m",
8259 CONFIG_EXEC_PARAMS_NEW)));
8263 for (i = 0; i < num_guc_variables; i++)
8265 write_one_nondefault_variable(fp, guc_variables[i]);
8271 (errcode_for_file_access(),
8272 errmsg("could not write to file \"%s\": %m",
8273 CONFIG_EXEC_PARAMS_NEW)));
8278 * Put new file in place. This could delay on Win32, but we don't hold
8279 * any exclusive locks.
8281 rename(CONFIG_EXEC_PARAMS_NEW, CONFIG_EXEC_PARAMS);
8286 * Read string, including null byte from file
8288 * Return NULL on EOF and nothing read
8291 read_string_with_null(FILE *fp)
8300 if ((ch = fgetc(fp)) == EOF)
8305 elog(FATAL, "invalid format of exec config params file");
8308 str = guc_malloc(FATAL, maxlen);
8309 else if (i == maxlen)
8310 str = guc_realloc(FATAL, str, maxlen *= 2);
8319 * This routine loads a previous postmaster dump of its non-default
8323 read_nondefault_variables(void)
8330 GucSource varsource;
8331 GucContext varscontext;
8334 * Assert that PGC_BACKEND case in set_config_option() will do the right
8337 Assert(IsInitProcessingMode());
8342 fp = AllocateFile(CONFIG_EXEC_PARAMS, "r");
8345 /* File not found is fine */
8346 if (errno != ENOENT)
8348 (errcode_for_file_access(),
8349 errmsg("could not read from file \"%s\": %m",
8350 CONFIG_EXEC_PARAMS)));
8356 struct config_generic *record;
8358 if ((varname = read_string_with_null(fp)) == NULL)
8361 if ((record = find_option(varname, true, FATAL)) == NULL)
8362 elog(FATAL, "failed to locate variable \"%s\" in exec config params file", varname);
8364 if ((varvalue = read_string_with_null(fp)) == NULL)
8365 elog(FATAL, "invalid format of exec config params file");
8366 if ((varsourcefile = read_string_with_null(fp)) == NULL)
8367 elog(FATAL, "invalid format of exec config params file");
8368 if (fread(&varsourceline, 1, sizeof(varsourceline), fp) != sizeof(varsourceline))
8369 elog(FATAL, "invalid format of exec config params file");
8370 if (fread(&varsource, 1, sizeof(varsource), fp) != sizeof(varsource))
8371 elog(FATAL, "invalid format of exec config params file");
8372 if (fread(&varscontext, 1, sizeof(varscontext), fp) != sizeof(varscontext))
8373 elog(FATAL, "invalid format of exec config params file");
8375 (void) set_config_option(varname, varvalue,
8376 varscontext, varsource,
8377 GUC_ACTION_SET, true, 0);
8378 if (varsourcefile[0])
8379 set_config_sourcefile(varname, varsourcefile, varsourceline);
8383 free(varsourcefile);
8388 #endif /* EXEC_BACKEND */
8392 * A little "long argument" simulation, although not quite GNU
8393 * compliant. Takes a string of the form "some-option=some value" and
8394 * returns name = "some_option" and value = "some value" in malloc'ed
8395 * storage. Note that '-' is converted to '_' in the option name. If
8396 * there is no '=' in the input string then value will be NULL.
8399 ParseLongOption(const char *string, char **name, char **value)
8408 equal_pos = strcspn(string, "=");
8410 if (string[equal_pos] == '=')
8412 *name = guc_malloc(FATAL, equal_pos + 1);
8413 strlcpy(*name, string, equal_pos + 1);
8415 *value = guc_strdup(FATAL, &string[equal_pos + 1]);
8419 /* no equal sign in string */
8420 *name = guc_strdup(FATAL, string);
8424 for (cp = *name; *cp; cp++)
8431 * Handle options fetched from pg_db_role_setting.setconfig,
8432 * pg_proc.proconfig, etc. Caller must specify proper context/source/action.
8434 * The array parameter must be an array of TEXT (it must not be NULL).
8437 ProcessGUCArray(ArrayType *array,
8438 GucContext context, GucSource source, GucAction action)
8442 Assert(array != NULL);
8443 Assert(ARR_ELEMTYPE(array) == TEXTOID);
8444 Assert(ARR_NDIM(array) == 1);
8445 Assert(ARR_LBOUND(array)[0] == 1);
8447 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
8455 d = array_ref(array, 1, &i,
8456 -1 /* varlenarray */ ,
8457 -1 /* TEXT's typlen */ ,
8458 false /* TEXT's typbyval */ ,
8459 'i' /* TEXT's typalign */ ,
8465 s = TextDatumGetCString(d);
8467 ParseLongOption(s, &name, &value);
8471 (errcode(ERRCODE_SYNTAX_ERROR),
8472 errmsg("could not parse setting for parameter \"%s\"",
8478 (void) set_config_option(name, value,
8491 * Add an entry to an option array. The array parameter may be NULL
8492 * to indicate the current table entry is NULL.
8495 GUCArrayAdd(ArrayType *array, const char *name, const char *value)
8497 struct config_generic *record;
8505 /* test if the option is valid and we're allowed to set it */
8506 (void) validate_option_array_item(name, value, false);
8508 /* normalize name (converts obsolete GUC names to modern spellings) */
8509 record = find_option(name, false, WARNING);
8511 name = record->name;
8513 /* build new item for array */
8514 newval = psprintf("%s=%s", name, value);
8515 datum = CStringGetTextDatum(newval);
8523 Assert(ARR_ELEMTYPE(array) == TEXTOID);
8524 Assert(ARR_NDIM(array) == 1);
8525 Assert(ARR_LBOUND(array)[0] == 1);
8527 index = ARR_DIMS(array)[0] + 1; /* add after end */
8529 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
8534 d = array_ref(array, 1, &i,
8535 -1 /* varlenarray */ ,
8536 -1 /* TEXT's typlen */ ,
8537 false /* TEXT's typbyval */ ,
8538 'i' /* TEXT's typalign */ ,
8542 current = TextDatumGetCString(d);
8544 /* check for match up through and including '=' */
8545 if (strncmp(current, newval, strlen(name) + 1) == 0)
8552 a = array_set(array, 1, &index,
8555 -1 /* varlena array */ ,
8556 -1 /* TEXT's typlen */ ,
8557 false /* TEXT's typbyval */ ,
8558 'i' /* TEXT's typalign */ );
8561 a = construct_array(&datum, 1,
8570 * Delete an entry from an option array. The array parameter may be NULL
8571 * to indicate the current table entry is NULL. Also, if the return value
8572 * is NULL then a null should be stored.
8575 GUCArrayDelete(ArrayType *array, const char *name)
8577 struct config_generic *record;
8578 ArrayType *newarray;
8584 /* test if the option is valid and we're allowed to set it */
8585 (void) validate_option_array_item(name, NULL, false);
8587 /* normalize name (converts obsolete GUC names to modern spellings) */
8588 record = find_option(name, false, WARNING);
8590 name = record->name;
8592 /* if array is currently null, then surely nothing to delete */
8599 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
8605 d = array_ref(array, 1, &i,
8606 -1 /* varlenarray */ ,
8607 -1 /* TEXT's typlen */ ,
8608 false /* TEXT's typbyval */ ,
8609 'i' /* TEXT's typalign */ ,
8613 val = TextDatumGetCString(d);
8615 /* ignore entry if it's what we want to delete */
8616 if (strncmp(val, name, strlen(name)) == 0
8617 && val[strlen(name)] == '=')
8620 /* else add it to the output array */
8622 newarray = array_set(newarray, 1, &index,
8625 -1 /* varlenarray */ ,
8626 -1 /* TEXT's typlen */ ,
8627 false /* TEXT's typbyval */ ,
8628 'i' /* TEXT's typalign */ );
8630 newarray = construct_array(&d, 1,
8642 * Given a GUC array, delete all settings from it that our permission
8643 * level allows: if superuser, delete them all; if regular user, only
8644 * those that are PGC_USERSET
8647 GUCArrayReset(ArrayType *array)
8649 ArrayType *newarray;
8653 /* if array is currently null, nothing to do */
8657 /* if we're superuser, we can delete everything, so just do it */
8664 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
8671 d = array_ref(array, 1, &i,
8672 -1 /* varlenarray */ ,
8673 -1 /* TEXT's typlen */ ,
8674 false /* TEXT's typbyval */ ,
8675 'i' /* TEXT's typalign */ ,
8679 val = TextDatumGetCString(d);
8681 eqsgn = strchr(val, '=');
8684 /* skip if we have permission to delete it */
8685 if (validate_option_array_item(val, NULL, true))
8688 /* else add it to the output array */
8690 newarray = array_set(newarray, 1, &index,
8693 -1 /* varlenarray */ ,
8694 -1 /* TEXT's typlen */ ,
8695 false /* TEXT's typbyval */ ,
8696 'i' /* TEXT's typalign */ );
8698 newarray = construct_array(&d, 1,
8710 * Validate a proposed option setting for GUCArrayAdd/Delete/Reset.
8712 * name is the option name. value is the proposed value for the Add case,
8713 * or NULL for the Delete/Reset cases. If skipIfNoPermissions is true, it's
8714 * not an error to have no permissions to set the option.
8716 * Returns TRUE if OK, FALSE if skipIfNoPermissions is true and user does not
8717 * have permission to change this option (all other error cases result in an
8718 * error being thrown).
8721 validate_option_array_item(const char *name, const char *value,
8722 bool skipIfNoPermissions)
8725 struct config_generic *gconf;
8728 * There are three cases to consider:
8730 * name is a known GUC variable. Check the value normally, check
8731 * permissions normally (ie, allow if variable is USERSET, or if it's
8732 * SUSET and user is superuser).
8734 * name is not known, but exists or can be created as a placeholder (i.e.,
8735 * it has a prefixed name). We allow this case if you're a superuser,
8736 * otherwise not. Superusers are assumed to know what they're doing. We
8737 * can't allow it for other users, because when the placeholder is
8738 * resolved it might turn out to be a SUSET variable;
8739 * define_custom_variable assumes we checked that.
8741 * name is not known and can't be created as a placeholder. Throw error,
8742 * unless skipIfNoPermissions is true, in which case return FALSE.
8744 gconf = find_option(name, true, WARNING);
8747 /* not known, failed to make a placeholder */
8748 if (skipIfNoPermissions)
8751 (errcode(ERRCODE_UNDEFINED_OBJECT),
8752 errmsg("unrecognized configuration parameter \"%s\"",
8756 if (gconf->flags & GUC_CUSTOM_PLACEHOLDER)
8759 * We cannot do any meaningful check on the value, so only permissions
8760 * are useful to check.
8764 if (skipIfNoPermissions)
8767 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
8768 errmsg("permission denied to set parameter \"%s\"", name)));
8771 /* manual permissions check so we can avoid an error being thrown */
8772 if (gconf->context == PGC_USERSET)
8774 else if (gconf->context == PGC_SUSET && superuser())
8776 else if (skipIfNoPermissions)
8778 /* if a permissions error should be thrown, let set_config_option do it */
8780 /* test for permissions and valid option value */
8781 (void) set_config_option(name, value,
8782 superuser() ? PGC_SUSET : PGC_USERSET,
8783 PGC_S_TEST, GUC_ACTION_SET, false, 0);
8790 * Called by check_hooks that want to override the normal
8791 * ERRCODE_INVALID_PARAMETER_VALUE SQLSTATE for check hook failures.
8793 * Note that GUC_check_errmsg() etc are just macros that result in a direct
8794 * assignment to the associated variables. That is ugly, but forced by the
8795 * limitations of C's macro mechanisms.
8798 GUC_check_errcode(int sqlerrcode)
8800 GUC_check_errcode_value = sqlerrcode;
8805 * Convenience functions to manage calling a variable's check_hook.
8806 * These mostly take care of the protocol for letting check hooks supply
8807 * portions of the error report on failure.
8811 call_bool_check_hook(struct config_bool * conf, bool *newval, void **extra,
8812 GucSource source, int elevel)
8814 /* Quick success if no hook */
8815 if (!conf->check_hook)
8818 /* Reset variables that might be set by hook */
8819 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8820 GUC_check_errmsg_string = NULL;
8821 GUC_check_errdetail_string = NULL;
8822 GUC_check_errhint_string = NULL;
8824 if (!(*conf->check_hook) (newval, extra, source))
8827 (errcode(GUC_check_errcode_value),
8828 GUC_check_errmsg_string ?
8829 errmsg_internal("%s", GUC_check_errmsg_string) :
8830 errmsg("invalid value for parameter \"%s\": %d",
8831 conf->gen.name, (int) *newval),
8832 GUC_check_errdetail_string ?
8833 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
8834 GUC_check_errhint_string ?
8835 errhint("%s", GUC_check_errhint_string) : 0));
8836 /* Flush any strings created in ErrorContext */
8845 call_int_check_hook(struct config_int * conf, int *newval, void **extra,
8846 GucSource source, int elevel)
8848 /* Quick success if no hook */
8849 if (!conf->check_hook)
8852 /* Reset variables that might be set by hook */
8853 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8854 GUC_check_errmsg_string = NULL;
8855 GUC_check_errdetail_string = NULL;
8856 GUC_check_errhint_string = NULL;
8858 if (!(*conf->check_hook) (newval, extra, source))
8861 (errcode(GUC_check_errcode_value),
8862 GUC_check_errmsg_string ?
8863 errmsg_internal("%s", GUC_check_errmsg_string) :
8864 errmsg("invalid value for parameter \"%s\": %d",
8865 conf->gen.name, *newval),
8866 GUC_check_errdetail_string ?
8867 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
8868 GUC_check_errhint_string ?
8869 errhint("%s", GUC_check_errhint_string) : 0));
8870 /* Flush any strings created in ErrorContext */
8879 call_real_check_hook(struct config_real * conf, double *newval, void **extra,
8880 GucSource source, int elevel)
8882 /* Quick success if no hook */
8883 if (!conf->check_hook)
8886 /* Reset variables that might be set by hook */
8887 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8888 GUC_check_errmsg_string = NULL;
8889 GUC_check_errdetail_string = NULL;
8890 GUC_check_errhint_string = NULL;
8892 if (!(*conf->check_hook) (newval, extra, source))
8895 (errcode(GUC_check_errcode_value),
8896 GUC_check_errmsg_string ?
8897 errmsg_internal("%s", GUC_check_errmsg_string) :
8898 errmsg("invalid value for parameter \"%s\": %g",
8899 conf->gen.name, *newval),
8900 GUC_check_errdetail_string ?
8901 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
8902 GUC_check_errhint_string ?
8903 errhint("%s", GUC_check_errhint_string) : 0));
8904 /* Flush any strings created in ErrorContext */
8913 call_string_check_hook(struct config_string * conf, char **newval, void **extra,
8914 GucSource source, int elevel)
8916 /* Quick success if no hook */
8917 if (!conf->check_hook)
8920 /* Reset variables that might be set by hook */
8921 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8922 GUC_check_errmsg_string = NULL;
8923 GUC_check_errdetail_string = NULL;
8924 GUC_check_errhint_string = NULL;
8926 if (!(*conf->check_hook) (newval, extra, source))
8929 (errcode(GUC_check_errcode_value),
8930 GUC_check_errmsg_string ?
8931 errmsg_internal("%s", GUC_check_errmsg_string) :
8932 errmsg("invalid value for parameter \"%s\": \"%s\"",
8933 conf->gen.name, *newval ? *newval : ""),
8934 GUC_check_errdetail_string ?
8935 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
8936 GUC_check_errhint_string ?
8937 errhint("%s", GUC_check_errhint_string) : 0));
8938 /* Flush any strings created in ErrorContext */
8947 call_enum_check_hook(struct config_enum * conf, int *newval, void **extra,
8948 GucSource source, int elevel)
8950 /* Quick success if no hook */
8951 if (!conf->check_hook)
8954 /* Reset variables that might be set by hook */
8955 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8956 GUC_check_errmsg_string = NULL;
8957 GUC_check_errdetail_string = NULL;
8958 GUC_check_errhint_string = NULL;
8960 if (!(*conf->check_hook) (newval, extra, source))
8963 (errcode(GUC_check_errcode_value),
8964 GUC_check_errmsg_string ?
8965 errmsg_internal("%s", GUC_check_errmsg_string) :
8966 errmsg("invalid value for parameter \"%s\": \"%s\"",
8968 config_enum_lookup_by_value(conf, *newval)),
8969 GUC_check_errdetail_string ?
8970 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
8971 GUC_check_errhint_string ?
8972 errhint("%s", GUC_check_errhint_string) : 0));
8973 /* Flush any strings created in ErrorContext */
8983 * check_hook, assign_hook and show_hook subroutines
8987 check_log_destination(char **newval, void **extra, GucSource source)
8995 /* Need a modifiable copy of string */
8996 rawstring = pstrdup(*newval);
8998 /* Parse string into list of identifiers */
8999 if (!SplitIdentifierString(rawstring, ',', &elemlist))
9001 /* syntax error in list */
9002 GUC_check_errdetail("List syntax is invalid.");
9004 list_free(elemlist);
9008 foreach(l, elemlist)
9010 char *tok = (char *) lfirst(l);
9012 if (pg_strcasecmp(tok, "stderr") == 0)
9013 newlogdest |= LOG_DESTINATION_STDERR;
9014 else if (pg_strcasecmp(tok, "csvlog") == 0)
9015 newlogdest |= LOG_DESTINATION_CSVLOG;
9017 else if (pg_strcasecmp(tok, "syslog") == 0)
9018 newlogdest |= LOG_DESTINATION_SYSLOG;
9021 else if (pg_strcasecmp(tok, "eventlog") == 0)
9022 newlogdest |= LOG_DESTINATION_EVENTLOG;
9026 GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
9028 list_free(elemlist);
9034 list_free(elemlist);
9036 myextra = (int *) guc_malloc(ERROR, sizeof(int));
9037 *myextra = newlogdest;
9038 *extra = (void *) myextra;
9044 assign_log_destination(const char *newval, void *extra)
9046 Log_destination = *((int *) extra);
9050 assign_syslog_facility(int newval, void *extra)
9053 set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
9056 /* Without syslog support, just ignore it */
9060 assign_syslog_ident(const char *newval, void *extra)
9063 set_syslog_parameters(newval, syslog_facility);
9065 /* Without syslog support, it will always be set to "none", so ignore */
9070 assign_session_replication_role(int newval, void *extra)
9073 * Must flush the plan cache when changing replication role; but don't
9074 * flush unnecessarily.
9076 if (SessionReplicationRole != newval)
9081 check_temp_buffers(int *newval, void **extra, GucSource source)
9084 * Once local buffers have been initialized, it's too late to change this.
9086 if (NLocBuffer && NLocBuffer != *newval)
9088 GUC_check_errdetail("\"temp_buffers\" cannot be changed after any temporary tables have been accessed in the session.");
9095 check_phony_autocommit(bool *newval, void **extra, GucSource source)
9099 GUC_check_errcode(ERRCODE_FEATURE_NOT_SUPPORTED);
9100 GUC_check_errmsg("SET AUTOCOMMIT TO OFF is no longer supported");
9107 check_debug_assertions(bool *newval, void **extra, GucSource source)
9109 #ifndef USE_ASSERT_CHECKING
9112 GUC_check_errmsg("assertion checking is not supported by this build");
9120 check_bonjour(bool *newval, void **extra, GucSource source)
9125 GUC_check_errmsg("Bonjour is not supported by this build");
9133 check_ssl(bool *newval, void **extra, GucSource source)
9138 GUC_check_errmsg("SSL is not supported by this build");
9146 check_stage_log_stats(bool *newval, void **extra, GucSource source)
9148 if (*newval && log_statement_stats)
9150 GUC_check_errdetail("Cannot enable parameter when \"log_statement_stats\" is true.");
9157 check_log_stats(bool *newval, void **extra, GucSource source)
9160 (log_parser_stats || log_planner_stats || log_executor_stats))
9162 GUC_check_errdetail("Cannot enable \"log_statement_stats\" when "
9163 "\"log_parser_stats\", \"log_planner_stats\", "
9164 "or \"log_executor_stats\" is true.");
9171 check_canonical_path(char **newval, void **extra, GucSource source)
9174 * Since canonicalize_path never enlarges the string, we can just modify
9175 * newval in-place. But watch out for NULL, which is the default value
9176 * for external_pid_file.
9179 canonicalize_path(*newval);
9184 check_timezone_abbreviations(char **newval, void **extra, GucSource source)
9187 * The boot_val given above for timezone_abbreviations is NULL. When we
9188 * see this we just do nothing. If this value isn't overridden from the
9189 * config file then pg_timezone_abbrev_initialize() will eventually
9190 * replace it with "Default". This hack has two purposes: to avoid
9191 * wasting cycles loading values that might soon be overridden from the
9192 * config file, and to avoid trying to read the timezone abbrev files
9193 * during InitializeGUCOptions(). The latter doesn't work in an
9194 * EXEC_BACKEND subprocess because my_exec_path hasn't been set yet and so
9195 * we can't locate PGSHAREDIR.
9197 if (*newval == NULL)
9199 Assert(source == PGC_S_DEFAULT);
9203 /* OK, load the file and produce a malloc'd TimeZoneAbbrevTable */
9204 *extra = load_tzoffsets(*newval);
9206 /* tzparser.c returns NULL on failure, reporting via GUC_check_errmsg */
9214 assign_timezone_abbreviations(const char *newval, void *extra)
9216 /* Do nothing for the boot_val default of NULL */
9220 InstallTimeZoneAbbrevs((TimeZoneAbbrevTable *) extra);
9224 * pg_timezone_abbrev_initialize --- set default value if not done already
9226 * This is called after initial loading of postgresql.conf. If no
9227 * timezone_abbreviations setting was found therein, select default.
9228 * If a non-default value is already installed, nothing will happen.
9230 * This can also be called from ProcessConfigFile to establish the default
9231 * value after a postgresql.conf entry for it is removed.
9234 pg_timezone_abbrev_initialize(void)
9236 SetConfigOption("timezone_abbreviations", "Default",
9237 PGC_POSTMASTER, PGC_S_DYNAMIC_DEFAULT);
9241 show_archive_command(void)
9243 if (XLogArchivingActive())
9244 return XLogArchiveCommand;
9246 return "(disabled)";
9250 assign_tcp_keepalives_idle(int newval, void *extra)
9253 * The kernel API provides no way to test a value without setting it; and
9254 * once we set it we might fail to unset it. So there seems little point
9255 * in fully implementing the check-then-assign GUC API for these
9256 * variables. Instead we just do the assignment on demand. pqcomm.c
9257 * reports any problems via elog(LOG).
9259 * This approach means that the GUC value might have little to do with the
9260 * actual kernel value, so we use a show_hook that retrieves the kernel
9261 * value rather than trusting GUC's copy.
9263 (void) pq_setkeepalivesidle(newval, MyProcPort);
9267 show_tcp_keepalives_idle(void)
9269 /* See comments in assign_tcp_keepalives_idle */
9270 static char nbuf[16];
9272 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesidle(MyProcPort));
9277 assign_tcp_keepalives_interval(int newval, void *extra)
9279 /* See comments in assign_tcp_keepalives_idle */
9280 (void) pq_setkeepalivesinterval(newval, MyProcPort);
9284 show_tcp_keepalives_interval(void)
9286 /* See comments in assign_tcp_keepalives_idle */
9287 static char nbuf[16];
9289 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesinterval(MyProcPort));
9294 assign_tcp_keepalives_count(int newval, void *extra)
9296 /* See comments in assign_tcp_keepalives_idle */
9297 (void) pq_setkeepalivescount(newval, MyProcPort);
9301 show_tcp_keepalives_count(void)
9303 /* See comments in assign_tcp_keepalives_idle */
9304 static char nbuf[16];
9306 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivescount(MyProcPort));
9311 check_maxconnections(int *newval, void **extra, GucSource source)
9313 if (*newval + autovacuum_max_workers + 1 +
9314 max_worker_processes > MAX_BACKENDS)
9320 check_autovacuum_max_workers(int *newval, void **extra, GucSource source)
9322 if (MaxConnections + *newval + 1 + max_worker_processes > MAX_BACKENDS)
9328 check_autovacuum_work_mem(int *newval, void **extra, GucSource source)
9331 * -1 indicates fallback.
9333 * If we haven't yet changed the boot_val default of -1, just let it be.
9334 * Autovacuum will look to maintenance_work_mem instead.
9340 * We clamp manually-set values to at least 1MB. Since
9341 * maintenance_work_mem is always set to at least this value, do the same
9351 check_max_worker_processes(int *newval, void **extra, GucSource source)
9353 if (MaxConnections + autovacuum_max_workers + 1 + *newval > MAX_BACKENDS)
9359 check_effective_io_concurrency(int *newval, void **extra, GucSource source)
9362 double new_prefetch_pages = 0.0;
9366 * The user-visible GUC parameter is the number of drives (spindles),
9367 * which we need to translate to a number-of-pages-to-prefetch target.
9368 * The target value is stashed in *extra and then assigned to the actual
9369 * variable by assign_effective_io_concurrency.
9371 * The expected number of prefetch pages needed to keep N drives busy is:
9373 * drives | I/O requests
9374 * -------+----------------
9377 * 3 | 3/1 + 3/2 + 3/3 = 5 1/2
9378 * 4 | 4/1 + 4/2 + 4/3 + 4/4 = 8 1/3
9381 * This is called the "coupon collector problem" and H(n) is called the
9382 * harmonic series. This could be approximated by n * ln(n), but for
9383 * reasonable numbers of drives we might as well just compute the series.
9385 * Alternatively we could set the target to the number of pages necessary
9386 * so that the expected number of active spindles is some arbitrary
9387 * percentage of the total. This sounds the same but is actually slightly
9388 * different. The result ends up being ln(1-P)/ln((n-1)/n) where P is
9389 * that desired fraction.
9391 * Experimental results show that both of these formulas aren't aggressive
9392 * enough, but we don't really have any better proposals.
9394 * Note that if *newval = 0 (disabled), we must set target = 0.
9398 for (i = 1; i <= *newval; i++)
9399 new_prefetch_pages += (double) *newval / (double) i;
9401 /* This range check shouldn't fail, but let's be paranoid */
9402 if (new_prefetch_pages >= 0.0 && new_prefetch_pages < (double) INT_MAX)
9404 int *myextra = (int *) guc_malloc(ERROR, sizeof(int));
9406 *myextra = (int) rint(new_prefetch_pages);
9407 *extra = (void *) myextra;
9415 #endif /* USE_PREFETCH */
9419 assign_effective_io_concurrency(int newval, void *extra)
9422 target_prefetch_pages = *((int *) extra);
9423 #endif /* USE_PREFETCH */
9427 assign_pgstat_temp_directory(const char *newval, void *extra)
9429 /* check_canonical_path already canonicalized newval for us */
9435 dname = guc_malloc(ERROR, strlen(newval) + 1); /* runtime dir */
9436 sprintf(dname, "%s", newval);
9439 tname = guc_malloc(ERROR, strlen(newval) + 12); /* /global.tmp */
9440 sprintf(tname, "%s/global.tmp", newval);
9441 fname = guc_malloc(ERROR, strlen(newval) + 13); /* /global.stat */
9442 sprintf(fname, "%s/global.stat", newval);
9444 if (pgstat_stat_directory)
9445 free(pgstat_stat_directory);
9446 pgstat_stat_directory = dname;
9447 if (pgstat_stat_tmpname)
9448 free(pgstat_stat_tmpname);
9449 pgstat_stat_tmpname = tname;
9450 if (pgstat_stat_filename)
9451 free(pgstat_stat_filename);
9452 pgstat_stat_filename = fname;
9456 check_application_name(char **newval, void **extra, GucSource source)
9458 /* Only allow clean ASCII chars in the application name */
9461 for (p = *newval; *p; p++)
9463 if (*p < 32 || *p > 126)
9471 assign_application_name(const char *newval, void *extra)
9473 /* Update the pg_stat_activity view */
9474 pgstat_report_appname(newval);
9478 show_unix_socket_permissions(void)
9482 snprintf(buf, sizeof(buf), "%04o", Unix_socket_permissions);
9487 show_log_file_mode(void)
9491 snprintf(buf, sizeof(buf), "%04o", Log_file_mode);
9495 #include "guc-file.c"