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-2010, PostgreSQL Global Development Group
10 * Written by Peter Eisentraut <peter_e@gmx.net>.
13 * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.541 2010/02/17 04:19:40 tgl Exp $
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/pqformat.h"
43 #include "miscadmin.h"
44 #include "optimizer/cost.h"
45 #include "optimizer/geqo.h"
46 #include "optimizer/paths.h"
47 #include "optimizer/planmain.h"
48 #include "parser/parse_expr.h"
49 #include "parser/parse_type.h"
50 #include "parser/parser.h"
51 #include "parser/scansup.h"
53 #include "postmaster/autovacuum.h"
54 #include "postmaster/bgwriter.h"
55 #include "postmaster/postmaster.h"
56 #include "postmaster/syslogger.h"
57 #include "postmaster/walwriter.h"
58 #include "replication/walsender.h"
59 #include "storage/bufmgr.h"
60 #include "storage/fd.h"
61 #include "tcop/tcopprot.h"
62 #include "tsearch/ts_cache.h"
63 #include "utils/builtins.h"
64 #include "utils/bytea.h"
65 #include "utils/guc_tables.h"
66 #include "utils/memutils.h"
67 #include "utils/pg_locale.h"
68 #include "utils/plancache.h"
69 #include "utils/portal.h"
70 #include "utils/ps_status.h"
71 #include "utils/tzparser.h"
72 #include "utils/xml.h"
75 #define PG_KRB_SRVTAB ""
78 #define PG_KRB_SRVNAM ""
81 #define CONFIG_FILENAME "postgresql.conf"
82 #define HBA_FILENAME "pg_hba.conf"
83 #define IDENT_FILENAME "pg_ident.conf"
86 #define CONFIG_EXEC_PARAMS "global/config_exec_params"
87 #define CONFIG_EXEC_PARAMS_NEW "global/config_exec_params.new"
90 /* upper limit for GUC variables measured in kilobytes of memory */
91 /* note that various places assume the byte size fits in a "long" variable */
92 #if SIZEOF_SIZE_T > 4 && SIZEOF_LONG > 4
93 #define MAX_KILOBYTES INT_MAX
95 #define MAX_KILOBYTES (INT_MAX / 1024)
98 #define KB_PER_MB (1024)
99 #define KB_PER_GB (1024*1024)
101 #define MS_PER_S 1000
103 #define MS_PER_MIN (1000 * 60)
105 #define S_PER_H (60 * 60)
106 #define MS_PER_H (1000 * 60 * 60)
107 #define MIN_PER_D (60 * 24)
108 #define S_PER_D (60 * 60 * 24)
109 #define MS_PER_D (1000 * 60 * 60 * 24)
111 /* XXX these should appear in other modules' header files */
112 extern bool Log_disconnections;
113 extern int CommitDelay;
114 extern int CommitSiblings;
115 extern char *default_tablespace;
116 extern char *temp_tablespaces;
117 extern bool synchronize_seqscans;
118 extern bool fullPageWrites;
119 extern int vacuum_defer_cleanup_age;
121 int trace_recovery_messages = LOG;
124 extern bool trace_sort;
126 #ifdef TRACE_SYNCSCAN
127 extern bool trace_syncscan;
129 #ifdef DEBUG_BOUNDED_SORT
130 extern bool optimize_bounded_sort;
134 extern char *SSLCipherSuites;
137 static void set_config_sourcefile(const char *name, char *sourcefile,
140 static const char *assign_log_destination(const char *value,
141 bool doit, GucSource source);
144 static int syslog_facility = LOG_LOCAL0;
146 static bool assign_syslog_facility(int newval,
147 bool doit, GucSource source);
148 static const char *assign_syslog_ident(const char *ident,
149 bool doit, GucSource source);
152 static bool assign_session_replication_role(int newval, bool doit,
154 static const char *show_num_temp_buffers(void);
155 static bool assign_phony_autocommit(bool newval, bool doit, GucSource source);
156 static const char *assign_custom_variable_classes(const char *newval, bool doit,
158 static bool assign_debug_assertions(bool newval, bool doit, GucSource source);
159 static bool assign_bonjour(bool newval, bool doit, GucSource source);
160 static bool assign_ssl(bool newval, bool doit, GucSource source);
161 static bool assign_stage_log_stats(bool newval, bool doit, GucSource source);
162 static bool assign_log_stats(bool newval, bool doit, GucSource source);
163 static bool assign_transaction_read_only(bool newval, bool doit, GucSource source);
164 static const char *assign_canonical_path(const char *newval, bool doit, GucSource source);
165 static const char *assign_timezone_abbreviations(const char *newval, bool doit, GucSource source);
166 static const char *show_archive_command(void);
167 static bool assign_tcp_keepalives_idle(int newval, bool doit, GucSource source);
168 static bool assign_tcp_keepalives_interval(int newval, bool doit, GucSource source);
169 static bool assign_tcp_keepalives_count(int newval, bool doit, GucSource source);
170 static const char *show_tcp_keepalives_idle(void);
171 static const char *show_tcp_keepalives_interval(void);
172 static const char *show_tcp_keepalives_count(void);
173 static bool assign_maxconnections(int newval, bool doit, GucSource source);
174 static bool assign_autovacuum_max_workers(int newval, bool doit, GucSource source);
175 static bool assign_effective_io_concurrency(int newval, bool doit, GucSource source);
176 static const char *assign_pgstat_temp_directory(const char *newval, bool doit, GucSource source);
177 static const char *assign_application_name(const char *newval, bool doit, GucSource source);
179 static char *config_enum_get_options(struct config_enum * record,
180 const char *prefix, const char *suffix,
181 const char *separator);
185 * Options for enum values defined in this module.
187 * NOTE! Option values may not contain double quotes!
190 static const struct config_enum_entry bytea_output_options[] = {
191 {"escape", BYTEA_OUTPUT_ESCAPE, false},
192 {"hex", BYTEA_OUTPUT_HEX, false},
197 * We have different sets for client and server message level options because
198 * they sort slightly different (see "log" level)
200 static const struct config_enum_entry client_message_level_options[] = {
201 {"debug", DEBUG2, true},
202 {"debug5", DEBUG5, false},
203 {"debug4", DEBUG4, false},
204 {"debug3", DEBUG3, false},
205 {"debug2", DEBUG2, false},
206 {"debug1", DEBUG1, false},
208 {"info", INFO, true},
209 {"notice", NOTICE, false},
210 {"warning", WARNING, false},
211 {"error", ERROR, false},
212 {"fatal", FATAL, true},
213 {"panic", PANIC, true},
217 static const struct config_enum_entry server_message_level_options[] = {
218 {"debug", DEBUG2, true},
219 {"debug5", DEBUG5, false},
220 {"debug4", DEBUG4, false},
221 {"debug3", DEBUG3, false},
222 {"debug2", DEBUG2, false},
223 {"debug1", DEBUG1, false},
224 {"info", INFO, false},
225 {"notice", NOTICE, false},
226 {"warning", WARNING, false},
227 {"error", ERROR, false},
229 {"fatal", FATAL, false},
230 {"panic", PANIC, false},
234 static const struct config_enum_entry intervalstyle_options[] = {
235 {"postgres", INTSTYLE_POSTGRES, false},
236 {"postgres_verbose", INTSTYLE_POSTGRES_VERBOSE, false},
237 {"sql_standard", INTSTYLE_SQL_STANDARD, false},
238 {"iso_8601", INTSTYLE_ISO_8601, false},
242 static const struct config_enum_entry log_error_verbosity_options[] = {
243 {"terse", PGERROR_TERSE, false},
244 {"default", PGERROR_DEFAULT, false},
245 {"verbose", PGERROR_VERBOSE, false},
249 static const struct config_enum_entry log_statement_options[] = {
250 {"none", LOGSTMT_NONE, false},
251 {"ddl", LOGSTMT_DDL, false},
252 {"mod", LOGSTMT_MOD, false},
253 {"all", LOGSTMT_ALL, false},
257 static const struct config_enum_entry isolation_level_options[] = {
258 {"serializable", XACT_SERIALIZABLE, false},
259 {"repeatable read", XACT_REPEATABLE_READ, false},
260 {"read committed", XACT_READ_COMMITTED, false},
261 {"read uncommitted", XACT_READ_UNCOMMITTED, false},
265 static const struct config_enum_entry session_replication_role_options[] = {
266 {"origin", SESSION_REPLICATION_ROLE_ORIGIN, false},
267 {"replica", SESSION_REPLICATION_ROLE_REPLICA, false},
268 {"local", SESSION_REPLICATION_ROLE_LOCAL, false},
273 static const struct config_enum_entry syslog_facility_options[] = {
274 {"local0", LOG_LOCAL0, false},
275 {"local1", LOG_LOCAL1, false},
276 {"local2", LOG_LOCAL2, false},
277 {"local3", LOG_LOCAL3, false},
278 {"local4", LOG_LOCAL4, false},
279 {"local5", LOG_LOCAL5, false},
280 {"local6", LOG_LOCAL6, false},
281 {"local7", LOG_LOCAL7, false},
286 static const struct config_enum_entry track_function_options[] = {
287 {"none", TRACK_FUNC_OFF, false},
288 {"pl", TRACK_FUNC_PL, false},
289 {"all", TRACK_FUNC_ALL, false},
293 static const struct config_enum_entry xmlbinary_options[] = {
294 {"base64", XMLBINARY_BASE64, false},
295 {"hex", XMLBINARY_HEX, false},
299 static const struct config_enum_entry xmloption_options[] = {
300 {"content", XMLOPTION_CONTENT, false},
301 {"document", XMLOPTION_DOCUMENT, false},
306 * Although only "on", "off", and "safe_encoding" are documented, we
307 * accept all the likely variants of "on" and "off".
309 static const struct config_enum_entry backslash_quote_options[] = {
310 {"safe_encoding", BACKSLASH_QUOTE_SAFE_ENCODING, false},
311 {"on", BACKSLASH_QUOTE_ON, false},
312 {"off", BACKSLASH_QUOTE_OFF, false},
313 {"true", BACKSLASH_QUOTE_ON, true},
314 {"false", BACKSLASH_QUOTE_OFF, true},
315 {"yes", BACKSLASH_QUOTE_ON, true},
316 {"no", BACKSLASH_QUOTE_OFF, true},
317 {"1", BACKSLASH_QUOTE_ON, true},
318 {"0", BACKSLASH_QUOTE_OFF, true},
323 * Although only "on", "off", and "partition" are documented, we
324 * accept all the likely variants of "on" and "off".
326 static const struct config_enum_entry constraint_exclusion_options[] = {
327 {"partition", CONSTRAINT_EXCLUSION_PARTITION, false},
328 {"on", CONSTRAINT_EXCLUSION_ON, false},
329 {"off", CONSTRAINT_EXCLUSION_OFF, false},
330 {"true", CONSTRAINT_EXCLUSION_ON, true},
331 {"false", CONSTRAINT_EXCLUSION_OFF, true},
332 {"yes", CONSTRAINT_EXCLUSION_ON, true},
333 {"no", CONSTRAINT_EXCLUSION_OFF, true},
334 {"1", CONSTRAINT_EXCLUSION_ON, true},
335 {"0", CONSTRAINT_EXCLUSION_OFF, true},
340 * Options for enum values stored in other modules
342 extern const struct config_enum_entry sync_method_options[];
345 * GUC option variables that are exported from this module
347 #ifdef USE_ASSERT_CHECKING
348 bool assert_enabled = true;
350 bool assert_enabled = false;
352 bool log_duration = false;
353 bool Debug_print_plan = false;
354 bool Debug_print_parse = false;
355 bool Debug_print_rewritten = false;
356 bool Debug_pretty_print = true;
358 bool log_parser_stats = false;
359 bool log_planner_stats = false;
360 bool log_executor_stats = false;
361 bool log_statement_stats = false; /* this is sort of all three
363 bool log_btree_build_stats = false;
365 bool check_function_bodies = true;
366 bool default_with_oids = false;
367 bool SQL_inheritance = true;
369 bool Password_encryption = true;
371 int log_min_error_statement = ERROR;
372 int log_min_messages = WARNING;
373 int client_min_messages = NOTICE;
374 int log_min_duration_statement = -1;
375 int log_temp_files = -1;
377 int num_temp_buffers = 1000;
379 char *ConfigFileName;
382 char *external_pid_file;
384 char *pgstat_temp_directory;
386 char *application_name;
388 int tcp_keepalives_idle;
389 int tcp_keepalives_interval;
390 int tcp_keepalives_count;
393 * These variables are all dummies that don't do anything, except in some
394 * cases provide the value for SHOW to display. The real state is elsewhere
395 * and is kept in sync by assign_hooks.
397 static char *log_destination_string;
400 static char *syslog_ident_str;
402 static bool phony_autocommit;
403 static bool session_auth_is_superuser;
404 static double phony_random_seed;
405 static char *client_encoding_string;
406 static char *datestyle_string;
407 static char *locale_collate;
408 static char *locale_ctype;
409 static char *server_encoding_string;
410 static char *server_version_string;
411 static int server_version_num;
412 static char *timezone_string;
413 static char *log_timezone_string;
414 static char *timezone_abbreviations_string;
415 static char *XactIsoLevel_string;
416 static char *data_directory;
417 static char *custom_variable_classes;
418 static int max_function_args;
419 static int max_index_keys;
420 static int max_identifier_length;
421 static int block_size;
422 static int segment_size;
423 static int wal_block_size;
424 static int wal_segment_size;
425 static bool integer_datetimes;
426 static int effective_io_concurrency;
428 /* should be static, but commands/variable.c needs to get at these */
430 char *session_authorization_string;
434 * Displayable names for context types (enum GucContext)
436 * Note: these strings are deliberately not localized.
438 const char *const GucContext_Names[] =
440 /* PGC_INTERNAL */ "internal",
441 /* PGC_POSTMASTER */ "postmaster",
442 /* PGC_SIGHUP */ "sighup",
443 /* PGC_BACKEND */ "backend",
444 /* PGC_SUSET */ "superuser",
445 /* PGC_USERSET */ "user"
449 * Displayable names for source types (enum GucSource)
451 * Note: these strings are deliberately not localized.
453 const char *const GucSource_Names[] =
455 /* PGC_S_DEFAULT */ "default",
456 /* PGC_S_ENV_VAR */ "environment variable",
457 /* PGC_S_FILE */ "configuration file",
458 /* PGC_S_ARGV */ "command line",
459 /* PGC_S_DATABASE */ "database",
460 /* PGC_S_USER */ "user",
461 /* PGC_S_DATABASE_USER */ "database user",
462 /* PGC_S_CLIENT */ "client",
463 /* PGC_S_OVERRIDE */ "override",
464 /* PGC_S_INTERACTIVE */ "interactive",
465 /* PGC_S_TEST */ "test",
466 /* PGC_S_SESSION */ "session"
470 * Displayable names for the groupings defined in enum config_group
472 const char *const config_group_names[] =
475 gettext_noop("Ungrouped"),
477 gettext_noop("File Locations"),
479 gettext_noop("Connections and Authentication"),
480 /* CONN_AUTH_SETTINGS */
481 gettext_noop("Connections and Authentication / Connection Settings"),
482 /* CONN_AUTH_SECURITY */
483 gettext_noop("Connections and Authentication / Security and Authentication"),
485 gettext_noop("Resource Usage"),
487 gettext_noop("Resource Usage / Memory"),
488 /* RESOURCES_KERNEL */
489 gettext_noop("Resource Usage / Kernel Resources"),
491 gettext_noop("Write-Ahead Log"),
493 gettext_noop("Write-Ahead Log / Settings"),
494 /* WAL_CHECKPOINTS */
495 gettext_noop("Write-Ahead Log / Checkpoints"),
496 /* WAL_REPLICATION */
497 gettext_noop("Write-Ahead Log / Replication"),
499 gettext_noop("Query Tuning"),
500 /* QUERY_TUNING_METHOD */
501 gettext_noop("Query Tuning / Planner Method Configuration"),
502 /* QUERY_TUNING_COST */
503 gettext_noop("Query Tuning / Planner Cost Constants"),
504 /* QUERY_TUNING_GEQO */
505 gettext_noop("Query Tuning / Genetic Query Optimizer"),
506 /* QUERY_TUNING_OTHER */
507 gettext_noop("Query Tuning / Other Planner Options"),
509 gettext_noop("Reporting and Logging"),
511 gettext_noop("Reporting and Logging / Where to Log"),
513 gettext_noop("Reporting and Logging / When to Log"),
515 gettext_noop("Reporting and Logging / What to Log"),
517 gettext_noop("Statistics"),
518 /* STATS_MONITORING */
519 gettext_noop("Statistics / Monitoring"),
520 /* STATS_COLLECTOR */
521 gettext_noop("Statistics / Query and Index Statistics Collector"),
523 gettext_noop("Autovacuum"),
525 gettext_noop("Client Connection Defaults"),
526 /* CLIENT_CONN_STATEMENT */
527 gettext_noop("Client Connection Defaults / Statement Behavior"),
528 /* CLIENT_CONN_LOCALE */
529 gettext_noop("Client Connection Defaults / Locale and Formatting"),
530 /* CLIENT_CONN_OTHER */
531 gettext_noop("Client Connection Defaults / Other Defaults"),
532 /* LOCK_MANAGEMENT */
533 gettext_noop("Lock Management"),
535 gettext_noop("Version and Platform Compatibility"),
536 /* COMPAT_OPTIONS_PREVIOUS */
537 gettext_noop("Version and Platform Compatibility / Previous PostgreSQL Versions"),
538 /* COMPAT_OPTIONS_CLIENT */
539 gettext_noop("Version and Platform Compatibility / Other Platforms and Clients"),
541 gettext_noop("Preset Options"),
543 gettext_noop("Customized Options"),
544 /* DEVELOPER_OPTIONS */
545 gettext_noop("Developer Options"),
546 /* help_config wants this array to be null-terminated */
551 * Displayable names for GUC variable types (enum config_type)
553 * Note: these strings are deliberately not localized.
555 const char *const config_type_names[] =
557 /* PGC_BOOL */ "bool",
558 /* PGC_INT */ "integer",
559 /* PGC_REAL */ "real",
560 /* PGC_STRING */ "string",
561 /* PGC_ENUM */ "enum"
566 * Contents of GUC tables
568 * See src/backend/utils/misc/README for design notes.
572 * 1. Declare a global variable of type bool, int, double, or char*
573 * and make use of it.
575 * 2. Decide at what times it's safe to set the option. See guc.h for
578 * 3. Decide on a name, a default value, upper and lower bounds (if
581 * 4. Add a record below.
583 * 5. Add it to src/backend/utils/misc/postgresql.conf.sample, if
586 * 6. Don't forget to document the option (at least in config.sgml).
588 * 7. If it's a new GUC_LIST option you must edit pg_dumpall.c to ensure
589 * it is not single quoted at dump time.
593 /******** option records follow ********/
595 static struct config_bool ConfigureNamesBool[] =
598 {"enable_seqscan", PGC_USERSET, QUERY_TUNING_METHOD,
599 gettext_noop("Enables the planner's use of sequential-scan plans."),
606 {"enable_indexscan", PGC_USERSET, QUERY_TUNING_METHOD,
607 gettext_noop("Enables the planner's use of index-scan plans."),
614 {"enable_bitmapscan", PGC_USERSET, QUERY_TUNING_METHOD,
615 gettext_noop("Enables the planner's use of bitmap-scan plans."),
622 {"enable_tidscan", PGC_USERSET, QUERY_TUNING_METHOD,
623 gettext_noop("Enables the planner's use of TID scan plans."),
630 {"enable_sort", PGC_USERSET, QUERY_TUNING_METHOD,
631 gettext_noop("Enables the planner's use of explicit sort steps."),
638 {"enable_hashagg", PGC_USERSET, QUERY_TUNING_METHOD,
639 gettext_noop("Enables the planner's use of hashed aggregation plans."),
646 {"enable_nestloop", PGC_USERSET, QUERY_TUNING_METHOD,
647 gettext_noop("Enables the planner's use of nested-loop join plans."),
654 {"enable_mergejoin", PGC_USERSET, QUERY_TUNING_METHOD,
655 gettext_noop("Enables the planner's use of merge join plans."),
662 {"enable_hashjoin", PGC_USERSET, QUERY_TUNING_METHOD,
663 gettext_noop("Enables the planner's use of hash join plans."),
670 {"geqo", PGC_USERSET, QUERY_TUNING_GEQO,
671 gettext_noop("Enables genetic query optimization."),
672 gettext_noop("This algorithm attempts to do planning without "
673 "exhaustive searching.")
679 /* Not for general use --- used by SET SESSION AUTHORIZATION */
680 {"is_superuser", PGC_INTERNAL, UNGROUPED,
681 gettext_noop("Shows whether the current user is a superuser."),
683 GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
685 &session_auth_is_superuser,
689 {"bonjour", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
690 gettext_noop("Enables advertising the server via Bonjour."),
694 false, assign_bonjour, NULL
697 {"ssl", PGC_POSTMASTER, CONN_AUTH_SECURITY,
698 gettext_noop("Enables SSL connections."),
702 false, assign_ssl, NULL
705 {"fsync", PGC_SIGHUP, WAL_SETTINGS,
706 gettext_noop("Forces synchronization of updates to disk."),
707 gettext_noop("The server will use the fsync() system call in several places to make "
708 "sure that updates are physically written to disk. This insures "
709 "that a database cluster will recover to a consistent state after "
710 "an operating system or hardware crash.")
716 {"synchronous_commit", PGC_USERSET, WAL_SETTINGS,
717 gettext_noop("Sets immediate fsync at commit."),
724 {"zero_damaged_pages", PGC_SUSET, DEVELOPER_OPTIONS,
725 gettext_noop("Continues processing past damaged page headers."),
726 gettext_noop("Detection of a damaged page header normally causes PostgreSQL to "
727 "report an error, aborting the current transaction. Setting "
728 "zero_damaged_pages to true causes the system to instead report a "
729 "warning, zero out the damaged page, and continue processing. This "
730 "behavior will destroy data, namely all the rows on the damaged page."),
737 {"full_page_writes", PGC_SIGHUP, WAL_SETTINGS,
738 gettext_noop("Writes full pages to WAL when first modified after a checkpoint."),
739 gettext_noop("A page write in process during an operating system crash might be "
740 "only partially written to disk. During recovery, the row changes "
741 "stored in WAL are not enough to recover. This option writes "
742 "pages when first modified after a checkpoint to WAL so full recovery "
749 {"silent_mode", PGC_POSTMASTER, LOGGING_WHERE,
750 gettext_noop("Runs the server silently."),
751 gettext_noop("If this parameter is set, the server will automatically run in the "
752 "background and any controlling terminals are dissociated.")
758 {"log_checkpoints", PGC_SIGHUP, LOGGING_WHAT,
759 gettext_noop("Logs each checkpoint."),
766 {"log_connections", PGC_BACKEND, LOGGING_WHAT,
767 gettext_noop("Logs each successful connection."),
774 {"log_disconnections", PGC_BACKEND, LOGGING_WHAT,
775 gettext_noop("Logs end of a session, including duration."),
782 {"debug_assertions", PGC_USERSET, DEVELOPER_OPTIONS,
783 gettext_noop("Turns on various assertion checks."),
784 gettext_noop("This is a debugging aid."),
788 #ifdef USE_ASSERT_CHECKING
793 assign_debug_assertions, NULL
796 /* currently undocumented, so don't show in SHOW ALL */
797 {"exit_on_error", PGC_USERSET, UNGROUPED,
798 gettext_noop("No description available."),
800 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
806 {"log_duration", PGC_SUSET, LOGGING_WHAT,
807 gettext_noop("Logs the duration of each completed SQL statement."),
814 {"debug_print_parse", PGC_USERSET, LOGGING_WHAT,
815 gettext_noop("Logs each query's parse tree."),
822 {"debug_print_rewritten", PGC_USERSET, LOGGING_WHAT,
823 gettext_noop("Logs each query's rewritten parse tree."),
826 &Debug_print_rewritten,
830 {"debug_print_plan", PGC_USERSET, LOGGING_WHAT,
831 gettext_noop("Logs each query's execution plan."),
838 {"debug_pretty_print", PGC_USERSET, LOGGING_WHAT,
839 gettext_noop("Indents parse and plan tree displays."),
846 {"log_parser_stats", PGC_SUSET, STATS_MONITORING,
847 gettext_noop("Writes parser performance statistics to the server log."),
851 false, assign_stage_log_stats, NULL
854 {"log_planner_stats", PGC_SUSET, STATS_MONITORING,
855 gettext_noop("Writes planner performance statistics to the server log."),
859 false, assign_stage_log_stats, NULL
862 {"log_executor_stats", PGC_SUSET, STATS_MONITORING,
863 gettext_noop("Writes executor performance statistics to the server log."),
867 false, assign_stage_log_stats, NULL
870 {"log_statement_stats", PGC_SUSET, STATS_MONITORING,
871 gettext_noop("Writes cumulative performance statistics to the server log."),
874 &log_statement_stats,
875 false, assign_log_stats, NULL
877 #ifdef BTREE_BUILD_STATS
879 {"log_btree_build_stats", PGC_SUSET, DEVELOPER_OPTIONS,
880 gettext_noop("No description available."),
884 &log_btree_build_stats,
890 {"track_activities", PGC_SUSET, STATS_COLLECTOR,
891 gettext_noop("Collects information about executing commands."),
892 gettext_noop("Enables the collection of information on the currently "
893 "executing command of each session, along with "
894 "the time at which that command began execution.")
896 &pgstat_track_activities,
900 {"track_counts", PGC_SUSET, STATS_COLLECTOR,
901 gettext_noop("Collects statistics on database activity."),
904 &pgstat_track_counts,
909 {"update_process_title", PGC_SUSET, STATS_COLLECTOR,
910 gettext_noop("Updates the process title to show the active SQL command."),
911 gettext_noop("Enables updating of the process title every time a new SQL command is received by the server.")
913 &update_process_title,
918 {"autovacuum", PGC_SIGHUP, AUTOVACUUM,
919 gettext_noop("Starts the autovacuum subprocess."),
922 &autovacuum_start_daemon,
927 {"trace_notify", PGC_USERSET, DEVELOPER_OPTIONS,
928 gettext_noop("Generates debugging output for LISTEN and NOTIFY."),
938 {"trace_locks", PGC_SUSET, DEVELOPER_OPTIONS,
939 gettext_noop("No description available."),
947 {"trace_userlocks", PGC_SUSET, DEVELOPER_OPTIONS,
948 gettext_noop("No description available."),
956 {"trace_lwlocks", PGC_SUSET, DEVELOPER_OPTIONS,
957 gettext_noop("No description available."),
965 {"debug_deadlocks", PGC_SUSET, DEVELOPER_OPTIONS,
966 gettext_noop("No description available."),
976 {"log_lock_waits", PGC_SUSET, LOGGING_WHAT,
977 gettext_noop("Logs long lock waits."),
985 {"log_hostname", PGC_SIGHUP, LOGGING_WHAT,
986 gettext_noop("Logs the host name in the connection logs."),
987 gettext_noop("By default, connection logs only show the IP address "
988 "of the connecting host. If you want them to show the host name you "
989 "can turn this on, but depending on your host name resolution "
990 "setup it might impose a non-negligible performance penalty.")
996 {"sql_inheritance", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
997 gettext_noop("Causes subtables to be included by default in various commands."),
1004 {"password_encryption", PGC_USERSET, CONN_AUTH_SECURITY,
1005 gettext_noop("Encrypt passwords."),
1006 gettext_noop("When a password is specified in CREATE USER or "
1007 "ALTER USER without writing either ENCRYPTED or UNENCRYPTED, "
1008 "this parameter determines whether the password is to be encrypted.")
1010 &Password_encryption,
1014 {"transform_null_equals", PGC_USERSET, COMPAT_OPTIONS_CLIENT,
1015 gettext_noop("Treats \"expr=NULL\" as \"expr IS NULL\"."),
1016 gettext_noop("When turned on, expressions of the form expr = NULL "
1017 "(or NULL = expr) are treated as expr IS NULL, that is, they "
1018 "return true if expr evaluates to the null value, and false "
1019 "otherwise. The correct behavior of expr = NULL is to always "
1020 "return null (unknown).")
1022 &Transform_null_equals,
1026 {"db_user_namespace", PGC_SIGHUP, CONN_AUTH_SECURITY,
1027 gettext_noop("Enables per-database user names."),
1034 /* only here for backwards compatibility */
1035 {"autocommit", PGC_USERSET, CLIENT_CONN_STATEMENT,
1036 gettext_noop("This parameter doesn't do anything."),
1037 gettext_noop("It's just here so that we won't choke on SET AUTOCOMMIT TO ON from 7.3-vintage clients."),
1038 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
1041 true, assign_phony_autocommit, NULL
1044 {"default_transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
1045 gettext_noop("Sets the default read-only status of new transactions."),
1048 &DefaultXactReadOnly,
1052 {"transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
1053 gettext_noop("Sets the current transaction's read-only status."),
1055 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1058 false, assign_transaction_read_only, NULL
1061 {"check_function_bodies", PGC_USERSET, CLIENT_CONN_STATEMENT,
1062 gettext_noop("Check function bodies during CREATE FUNCTION."),
1065 &check_function_bodies,
1069 {"array_nulls", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1070 gettext_noop("Enable input of NULL elements in arrays."),
1071 gettext_noop("When turned on, unquoted NULL in an array input "
1072 "value means a null value; "
1073 "otherwise it is taken literally.")
1079 {"default_with_oids", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1080 gettext_noop("Create new tables with OIDs by default."),
1087 {"logging_collector", PGC_POSTMASTER, LOGGING_WHERE,
1088 gettext_noop("Start a subprocess to capture stderr output and/or csvlogs into log files."),
1095 {"log_truncate_on_rotation", PGC_SIGHUP, LOGGING_WHERE,
1096 gettext_noop("Truncate existing log files of same name during log rotation."),
1099 &Log_truncate_on_rotation,
1105 {"trace_sort", PGC_USERSET, DEVELOPER_OPTIONS,
1106 gettext_noop("Emit information about resource usage in sorting."),
1115 #ifdef TRACE_SYNCSCAN
1116 /* this is undocumented because not exposed in a standard build */
1118 {"trace_syncscan", PGC_USERSET, DEVELOPER_OPTIONS,
1119 gettext_noop("Generate debugging output for synchronized scanning."),
1128 #ifdef DEBUG_BOUNDED_SORT
1129 /* this is undocumented because not exposed in a standard build */
1132 "optimize_bounded_sort", PGC_USERSET, QUERY_TUNING_METHOD,
1133 gettext_noop("Enable bounded sorting using heap sort."),
1137 &optimize_bounded_sort,
1144 {"wal_debug", PGC_SUSET, DEVELOPER_OPTIONS,
1145 gettext_noop("Emit WAL-related debugging output."),
1155 {"integer_datetimes", PGC_INTERNAL, PRESET_OPTIONS,
1156 gettext_noop("Datetimes are integer based."),
1158 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1161 #ifdef HAVE_INT64_TIMESTAMP
1169 {"krb_caseins_users", PGC_SIGHUP, CONN_AUTH_SECURITY,
1170 gettext_noop("Sets whether Kerberos and GSSAPI user names should be treated as case-insensitive."),
1173 &pg_krb_caseins_users,
1178 {"escape_string_warning", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1179 gettext_noop("Warn about backslash escapes in ordinary string literals."),
1182 &escape_string_warning,
1187 {"standard_conforming_strings", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1188 gettext_noop("Causes '...' strings to treat backslashes literally."),
1192 &standard_conforming_strings,
1197 {"synchronize_seqscans", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1198 gettext_noop("Enable synchronized sequential scans."),
1201 &synchronize_seqscans,
1206 {"archive_mode", PGC_POSTMASTER, WAL_SETTINGS,
1207 gettext_noop("Allows archiving of WAL files using archive_command."),
1215 {"recovery_connections", PGC_POSTMASTER, WAL_SETTINGS,
1216 gettext_noop("During recovery, allows connections and queries. "
1217 " During normal running, causes additional info to be written"
1218 " to WAL to enable hot standby mode on WAL standby nodes."),
1221 &XLogRequestRecoveryConnections,
1226 {"allow_system_table_mods", PGC_POSTMASTER, DEVELOPER_OPTIONS,
1227 gettext_noop("Allows modifications of the structure of system tables."),
1231 &allowSystemTableMods,
1236 {"ignore_system_indexes", PGC_BACKEND, DEVELOPER_OPTIONS,
1237 gettext_noop("Disables reading from system indexes."),
1238 gettext_noop("It does not prevent updating the indexes, so it is safe "
1239 "to use. The worst consequence is slowness."),
1242 &IgnoreSystemIndexes,
1247 {"lo_compat_privileges", PGC_SUSET, COMPAT_OPTIONS_PREVIOUS,
1248 gettext_noop("Enables backward compatibility mode for privilege checks on large objects"),
1249 gettext_noop("Skips privilege checks when reading or modifying large objects, "
1250 "for compatibility with PostgreSQL releases prior to 9.0.")
1252 &lo_compat_privileges,
1256 /* End-of-list marker */
1258 {NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL
1263 static struct config_int ConfigureNamesInt[] =
1266 {"archive_timeout", PGC_SIGHUP, WAL_SETTINGS,
1267 gettext_noop("Forces a switch to the next xlog file if a "
1268 "new file has not been started within N seconds."),
1272 &XLogArchiveTimeout,
1273 0, 0, INT_MAX, NULL, NULL
1276 {"post_auth_delay", PGC_BACKEND, DEVELOPER_OPTIONS,
1277 gettext_noop("Waits N seconds on connection startup after authentication."),
1278 gettext_noop("This allows attaching a debugger to the process."),
1279 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1282 0, 0, INT_MAX, NULL, NULL
1285 {"default_statistics_target", PGC_USERSET, QUERY_TUNING_OTHER,
1286 gettext_noop("Sets the default statistics target."),
1287 gettext_noop("This applies to table columns that have not had a "
1288 "column-specific target set via ALTER TABLE SET STATISTICS.")
1290 &default_statistics_target,
1291 100, 1, 10000, NULL, NULL
1294 {"from_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1295 gettext_noop("Sets the FROM-list size beyond which subqueries "
1296 "are not collapsed."),
1297 gettext_noop("The planner will merge subqueries into upper "
1298 "queries if the resulting FROM list would have no more than "
1301 &from_collapse_limit,
1302 8, 1, INT_MAX, NULL, NULL
1305 {"join_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1306 gettext_noop("Sets the FROM-list size beyond which JOIN "
1307 "constructs are not flattened."),
1308 gettext_noop("The planner will flatten explicit JOIN "
1309 "constructs into lists of FROM items whenever a "
1310 "list of no more than this many items would result.")
1312 &join_collapse_limit,
1313 8, 1, INT_MAX, NULL, NULL
1316 {"geqo_threshold", PGC_USERSET, QUERY_TUNING_GEQO,
1317 gettext_noop("Sets the threshold of FROM items beyond which GEQO is used."),
1321 12, 2, INT_MAX, NULL, NULL
1324 {"geqo_effort", PGC_USERSET, QUERY_TUNING_GEQO,
1325 gettext_noop("GEQO: effort is used to set the default for other GEQO parameters."),
1329 DEFAULT_GEQO_EFFORT, MIN_GEQO_EFFORT, MAX_GEQO_EFFORT, NULL, NULL
1332 {"geqo_pool_size", PGC_USERSET, QUERY_TUNING_GEQO,
1333 gettext_noop("GEQO: number of individuals in the population."),
1334 gettext_noop("Zero selects a suitable default value.")
1337 0, 0, INT_MAX, NULL, NULL
1340 {"geqo_generations", PGC_USERSET, QUERY_TUNING_GEQO,
1341 gettext_noop("GEQO: number of iterations of the algorithm."),
1342 gettext_noop("Zero selects a suitable default value.")
1345 0, 0, INT_MAX, NULL, NULL
1349 /* This is PGC_SIGHUP so all backends have the same value. */
1350 {"deadlock_timeout", PGC_SIGHUP, LOCK_MANAGEMENT,
1351 gettext_noop("Sets the time to wait on a lock before checking for deadlock."),
1356 1000, 1, INT_MAX / 1000, NULL, NULL
1360 * Note: MaxBackends is limited to INT_MAX/4 because some places compute
1361 * 4*MaxBackends without any overflow check. This check is made in
1362 * assign_maxconnections, since MaxBackends is computed as MaxConnections
1363 * plus autovacuum_max_workers plus one (for the autovacuum launcher).
1365 * Likewise we have to limit NBuffers to INT_MAX/2.
1367 * See also CheckRequiredParameterValues() if this parameter changes
1370 {"max_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1371 gettext_noop("Sets the maximum number of concurrent connections."),
1375 100, 1, INT_MAX / 4, assign_maxconnections, NULL
1379 {"max_standby_delay", PGC_SIGHUP, WAL_SETTINGS,
1380 gettext_noop("Sets the maximum delay to avoid conflict processing on Hot Standby servers."),
1384 30, -1, INT_MAX, NULL, NULL
1388 {"superuser_reserved_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1389 gettext_noop("Sets the number of connection slots reserved for superusers."),
1393 3, 0, INT_MAX / 4, NULL, NULL
1397 {"shared_buffers", PGC_POSTMASTER, RESOURCES_MEM,
1398 gettext_noop("Sets the number of shared memory buffers used by the server."),
1403 1024, 16, INT_MAX / 2, NULL, NULL
1407 {"temp_buffers", PGC_USERSET, RESOURCES_MEM,
1408 gettext_noop("Sets the maximum number of temporary buffers used by each session."),
1413 1024, 100, INT_MAX / 2, NULL, show_num_temp_buffers
1417 {"port", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1418 gettext_noop("Sets the TCP port the server listens on."),
1422 DEF_PGPORT, 1, 65535, NULL, NULL
1426 {"unix_socket_permissions", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1427 gettext_noop("Sets the access permissions of the Unix-domain socket."),
1428 gettext_noop("Unix-domain sockets use the usual Unix file system "
1429 "permission set. The parameter value is expected to be a numeric mode "
1430 "specification in the form accepted by the chmod and umask system "
1431 "calls. (To use the customary octal format the number must start with "
1434 &Unix_socket_permissions,
1435 0777, 0000, 0777, NULL, NULL
1439 {"work_mem", PGC_USERSET, RESOURCES_MEM,
1440 gettext_noop("Sets the maximum memory to be used for query workspaces."),
1441 gettext_noop("This much memory can be used by each internal "
1442 "sort operation and hash table before switching to "
1443 "temporary disk files."),
1447 1024, 64, MAX_KILOBYTES, NULL, NULL
1451 {"maintenance_work_mem", PGC_USERSET, RESOURCES_MEM,
1452 gettext_noop("Sets the maximum memory to be used for maintenance operations."),
1453 gettext_noop("This includes operations such as VACUUM and CREATE INDEX."),
1456 &maintenance_work_mem,
1457 16384, 1024, MAX_KILOBYTES, NULL, NULL
1461 {"max_stack_depth", PGC_SUSET, RESOURCES_MEM,
1462 gettext_noop("Sets the maximum stack depth, in kilobytes."),
1467 100, 100, MAX_KILOBYTES, assign_max_stack_depth, NULL
1471 {"vacuum_cost_page_hit", PGC_USERSET, RESOURCES,
1472 gettext_noop("Vacuum cost for a page found in the buffer cache."),
1476 1, 0, 10000, NULL, NULL
1480 {"vacuum_cost_page_miss", PGC_USERSET, RESOURCES,
1481 gettext_noop("Vacuum cost for a page not found in the buffer cache."),
1484 &VacuumCostPageMiss,
1485 10, 0, 10000, NULL, NULL
1489 {"vacuum_cost_page_dirty", PGC_USERSET, RESOURCES,
1490 gettext_noop("Vacuum cost for a page dirtied by vacuum."),
1493 &VacuumCostPageDirty,
1494 20, 0, 10000, NULL, NULL
1498 {"vacuum_cost_limit", PGC_USERSET, RESOURCES,
1499 gettext_noop("Vacuum cost amount available before napping."),
1503 200, 1, 10000, NULL, NULL
1507 {"vacuum_cost_delay", PGC_USERSET, RESOURCES,
1508 gettext_noop("Vacuum cost delay in milliseconds."),
1513 0, 0, 100, NULL, NULL
1517 {"autovacuum_vacuum_cost_delay", PGC_SIGHUP, AUTOVACUUM,
1518 gettext_noop("Vacuum cost delay in milliseconds, for autovacuum."),
1522 &autovacuum_vac_cost_delay,
1523 20, -1, 100, NULL, NULL
1527 {"autovacuum_vacuum_cost_limit", PGC_SIGHUP, AUTOVACUUM,
1528 gettext_noop("Vacuum cost amount available before napping, for autovacuum."),
1531 &autovacuum_vac_cost_limit,
1532 -1, -1, 10000, NULL, NULL
1536 {"max_files_per_process", PGC_POSTMASTER, RESOURCES_KERNEL,
1537 gettext_noop("Sets the maximum number of simultaneously open files for each server process."),
1540 &max_files_per_process,
1541 1000, 25, INT_MAX, NULL, NULL
1545 * See also CheckRequiredParameterValues() if this parameter changes
1548 {"max_prepared_transactions", PGC_POSTMASTER, RESOURCES,
1549 gettext_noop("Sets the maximum number of simultaneously prepared transactions."),
1552 &max_prepared_xacts,
1553 0, 0, INT_MAX / 4, NULL, NULL
1558 {"trace_lock_oidmin", PGC_SUSET, DEVELOPER_OPTIONS,
1559 gettext_noop("No description available."),
1564 FirstNormalObjectId, 0, INT_MAX, NULL, NULL
1567 {"trace_lock_table", PGC_SUSET, DEVELOPER_OPTIONS,
1568 gettext_noop("No description available."),
1573 0, 0, INT_MAX, NULL, NULL
1578 {"statement_timeout", PGC_USERSET, CLIENT_CONN_STATEMENT,
1579 gettext_noop("Sets the maximum allowed duration of any statement."),
1580 gettext_noop("A value of 0 turns off the timeout."),
1584 0, 0, INT_MAX, NULL, NULL
1588 {"vacuum_freeze_min_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1589 gettext_noop("Minimum age at which VACUUM should freeze a table row."),
1592 &vacuum_freeze_min_age,
1593 50000000, 0, 1000000000, NULL, NULL
1597 {"vacuum_freeze_table_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1598 gettext_noop("Age at which VACUUM should scan whole table to freeze tuples."),
1601 &vacuum_freeze_table_age,
1602 150000000, 0, 2000000000, NULL, NULL
1606 {"vacuum_defer_cleanup_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1607 gettext_noop("Age by which VACUUM and HOT cleanup should be deferred, if any."),
1610 &vacuum_defer_cleanup_age,
1611 0, 0, 1000000, NULL, NULL
1615 * See also CheckRequiredParameterValues() if this parameter changes
1618 {"max_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
1619 gettext_noop("Sets the maximum number of locks per transaction."),
1620 gettext_noop("The shared lock table is sized on the assumption that "
1621 "at most max_locks_per_transaction * max_connections distinct "
1622 "objects will need to be locked at any one time.")
1624 &max_locks_per_xact,
1625 64, 10, INT_MAX, NULL, NULL
1629 {"authentication_timeout", PGC_SIGHUP, CONN_AUTH_SECURITY,
1630 gettext_noop("Sets the maximum allowed time to complete client authentication."),
1634 &AuthenticationTimeout,
1635 60, 1, 600, NULL, NULL
1639 /* Not for general use */
1640 {"pre_auth_delay", PGC_SIGHUP, DEVELOPER_OPTIONS,
1641 gettext_noop("Waits N seconds on connection startup before authentication."),
1642 gettext_noop("This allows attaching a debugger to the process."),
1643 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1646 0, 0, 60, NULL, NULL
1650 {"checkpoint_segments", PGC_SIGHUP, WAL_CHECKPOINTS,
1651 gettext_noop("Sets the maximum distance in log segments between automatic WAL checkpoints."),
1654 &CheckPointSegments,
1655 3, 1, INT_MAX, NULL, NULL
1659 {"checkpoint_timeout", PGC_SIGHUP, WAL_CHECKPOINTS,
1660 gettext_noop("Sets the maximum time between automatic WAL checkpoints."),
1665 300, 30, 3600, NULL, NULL
1669 {"checkpoint_warning", PGC_SIGHUP, WAL_CHECKPOINTS,
1670 gettext_noop("Enables warnings if checkpoint segments are filled more "
1671 "frequently than this."),
1672 gettext_noop("Write a message to the server log if checkpoints "
1673 "caused by the filling of checkpoint segment files happens more "
1674 "frequently than this number of seconds. Zero turns off the warning."),
1678 30, 0, INT_MAX, NULL, NULL
1682 {"wal_buffers", PGC_POSTMASTER, WAL_SETTINGS,
1683 gettext_noop("Sets the number of disk-page buffers in shared memory for WAL."),
1688 8, 4, INT_MAX, NULL, NULL
1692 {"wal_writer_delay", PGC_SIGHUP, WAL_SETTINGS,
1693 gettext_noop("WAL writer sleep time between WAL flushes."),
1698 200, 1, 10000, NULL, NULL
1702 /* see max_connections */
1703 {"max_wal_senders", PGC_POSTMASTER, WAL_REPLICATION,
1704 gettext_noop("Sets the maximum number of simultaneously running WAL sender processes."),
1708 0, 0, INT_MAX / 4, NULL, NULL
1712 {"wal_sender_delay", PGC_SIGHUP, WAL_REPLICATION,
1713 gettext_noop("WAL sender sleep time between WAL replications."),
1718 200, 1, 10000, NULL, NULL
1722 {"commit_delay", PGC_USERSET, WAL_SETTINGS,
1723 gettext_noop("Sets the delay in microseconds between transaction commit and "
1724 "flushing WAL to disk."),
1728 0, 0, 100000, NULL, NULL
1732 {"commit_siblings", PGC_USERSET, WAL_SETTINGS,
1733 gettext_noop("Sets the minimum concurrent open transactions before performing "
1738 5, 1, 1000, NULL, NULL
1742 {"extra_float_digits", PGC_USERSET, CLIENT_CONN_LOCALE,
1743 gettext_noop("Sets the number of digits displayed for floating-point values."),
1744 gettext_noop("This affects real, double precision, and geometric data types. "
1745 "The parameter value is added to the standard number of digits "
1746 "(FLT_DIG or DBL_DIG as appropriate).")
1748 &extra_float_digits,
1749 0, -15, 3, NULL, NULL
1753 {"log_min_duration_statement", PGC_SUSET, LOGGING_WHEN,
1754 gettext_noop("Sets the minimum execution time above which "
1755 "statements will be logged."),
1756 gettext_noop("Zero prints all queries. -1 turns this feature off."),
1759 &log_min_duration_statement,
1760 -1, -1, INT_MAX / 1000, NULL, NULL
1764 {"log_autovacuum_min_duration", PGC_SIGHUP, LOGGING_WHAT,
1765 gettext_noop("Sets the minimum execution time above which "
1766 "autovacuum actions will be logged."),
1767 gettext_noop("Zero prints all actions. -1 turns autovacuum logging off."),
1770 &Log_autovacuum_min_duration,
1771 -1, -1, INT_MAX / 1000, NULL, NULL
1775 {"bgwriter_delay", PGC_SIGHUP, RESOURCES,
1776 gettext_noop("Background writer sleep time between rounds."),
1781 200, 10, 10000, NULL, NULL
1785 {"bgwriter_lru_maxpages", PGC_SIGHUP, RESOURCES,
1786 gettext_noop("Background writer maximum number of LRU pages to flush per round."),
1789 &bgwriter_lru_maxpages,
1790 100, 0, 1000, NULL, NULL
1794 {"effective_io_concurrency",
1801 gettext_noop("Number of simultaneous requests that can be handled efficiently by the disk subsystem."),
1802 gettext_noop("For RAID arrays, this should be approximately the number of drive spindles in the array.")
1804 &effective_io_concurrency,
1810 assign_effective_io_concurrency, NULL
1814 {"log_rotation_age", PGC_SIGHUP, LOGGING_WHERE,
1815 gettext_noop("Automatic log file rotation will occur after N minutes."),
1820 HOURS_PER_DAY * MINS_PER_HOUR, 0, INT_MAX / MINS_PER_HOUR, NULL, NULL
1824 {"log_rotation_size", PGC_SIGHUP, LOGGING_WHERE,
1825 gettext_noop("Automatic log file rotation will occur after N kilobytes."),
1830 10 * 1024, 0, INT_MAX / 1024, NULL, NULL
1834 {"max_function_args", PGC_INTERNAL, PRESET_OPTIONS,
1835 gettext_noop("Shows the maximum number of function arguments."),
1837 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1840 FUNC_MAX_ARGS, FUNC_MAX_ARGS, FUNC_MAX_ARGS, NULL, NULL
1844 {"max_index_keys", PGC_INTERNAL, PRESET_OPTIONS,
1845 gettext_noop("Shows the maximum number of index keys."),
1847 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1850 INDEX_MAX_KEYS, INDEX_MAX_KEYS, INDEX_MAX_KEYS, NULL, NULL
1854 {"max_identifier_length", PGC_INTERNAL, PRESET_OPTIONS,
1855 gettext_noop("Shows the maximum identifier length."),
1857 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1859 &max_identifier_length,
1860 NAMEDATALEN - 1, NAMEDATALEN - 1, NAMEDATALEN - 1, NULL, NULL
1864 {"block_size", PGC_INTERNAL, PRESET_OPTIONS,
1865 gettext_noop("Shows the size of a disk block."),
1867 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1870 BLCKSZ, BLCKSZ, BLCKSZ, NULL, NULL
1874 {"segment_size", PGC_INTERNAL, PRESET_OPTIONS,
1875 gettext_noop("Shows the number of pages per disk file."),
1877 GUC_UNIT_BLOCKS | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1880 RELSEG_SIZE, RELSEG_SIZE, RELSEG_SIZE, NULL, NULL
1884 {"wal_block_size", PGC_INTERNAL, PRESET_OPTIONS,
1885 gettext_noop("Shows the block size in the write ahead log."),
1887 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1890 XLOG_BLCKSZ, XLOG_BLCKSZ, XLOG_BLCKSZ, NULL, NULL
1894 {"wal_segment_size", PGC_INTERNAL, PRESET_OPTIONS,
1895 gettext_noop("Shows the number of pages per write ahead log segment."),
1897 GUC_UNIT_XBLOCKS | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1900 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
1901 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
1902 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
1907 {"autovacuum_naptime", PGC_SIGHUP, AUTOVACUUM,
1908 gettext_noop("Time to sleep between autovacuum runs."),
1912 &autovacuum_naptime,
1913 60, 1, INT_MAX / 1000, NULL, NULL
1916 {"autovacuum_vacuum_threshold", PGC_SIGHUP, AUTOVACUUM,
1917 gettext_noop("Minimum number of tuple updates or deletes prior to vacuum."),
1920 &autovacuum_vac_thresh,
1921 50, 0, INT_MAX, NULL, NULL
1924 {"autovacuum_analyze_threshold", PGC_SIGHUP, AUTOVACUUM,
1925 gettext_noop("Minimum number of tuple inserts, updates or deletes prior to analyze."),
1928 &autovacuum_anl_thresh,
1929 50, 0, INT_MAX, NULL, NULL
1932 /* see varsup.c for why this is PGC_POSTMASTER not PGC_SIGHUP */
1933 {"autovacuum_freeze_max_age", PGC_POSTMASTER, AUTOVACUUM,
1934 gettext_noop("Age at which to autovacuum a table to prevent transaction ID wraparound."),
1937 &autovacuum_freeze_max_age,
1938 /* see pg_resetxlog if you change the upper-limit value */
1939 200000000, 100000000, 2000000000, NULL, NULL
1942 /* see max_connections */
1943 {"autovacuum_max_workers", PGC_POSTMASTER, AUTOVACUUM,
1944 gettext_noop("Sets the maximum number of simultaneously running autovacuum worker processes."),
1947 &autovacuum_max_workers,
1948 3, 1, INT_MAX / 4, assign_autovacuum_max_workers, NULL
1952 {"tcp_keepalives_idle", PGC_USERSET, CLIENT_CONN_OTHER,
1953 gettext_noop("Time between issuing TCP keepalives."),
1954 gettext_noop("A value of 0 uses the system default."),
1957 &tcp_keepalives_idle,
1958 0, 0, INT_MAX, assign_tcp_keepalives_idle, show_tcp_keepalives_idle
1962 {"tcp_keepalives_interval", PGC_USERSET, CLIENT_CONN_OTHER,
1963 gettext_noop("Time between TCP keepalive retransmits."),
1964 gettext_noop("A value of 0 uses the system default."),
1967 &tcp_keepalives_interval,
1968 0, 0, INT_MAX, assign_tcp_keepalives_interval, show_tcp_keepalives_interval
1972 {"tcp_keepalives_count", PGC_USERSET, CLIENT_CONN_OTHER,
1973 gettext_noop("Maximum number of TCP keepalive retransmits."),
1974 gettext_noop("This controls the number of consecutive keepalive retransmits that can be "
1975 "lost before a connection is considered dead. A value of 0 uses the "
1978 &tcp_keepalives_count,
1979 0, 0, INT_MAX, assign_tcp_keepalives_count, show_tcp_keepalives_count
1983 {"gin_fuzzy_search_limit", PGC_USERSET, CLIENT_CONN_OTHER,
1984 gettext_noop("Sets the maximum allowed result for exact search by GIN."),
1988 &GinFuzzySearchLimit,
1989 0, 0, INT_MAX, NULL, NULL
1993 {"effective_cache_size", PGC_USERSET, QUERY_TUNING_COST,
1994 gettext_noop("Sets the planner's assumption about the size of the disk cache."),
1995 gettext_noop("That is, the portion of the kernel's disk cache that "
1996 "will be used for PostgreSQL data files. This is measured in disk "
1997 "pages, which are normally 8 kB each."),
2000 &effective_cache_size,
2001 DEFAULT_EFFECTIVE_CACHE_SIZE, 1, INT_MAX, NULL, NULL
2005 /* Can't be set in postgresql.conf */
2006 {"server_version_num", PGC_INTERNAL, PRESET_OPTIONS,
2007 gettext_noop("Shows the server version as an integer."),
2009 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2011 &server_version_num,
2012 PG_VERSION_NUM, PG_VERSION_NUM, PG_VERSION_NUM, NULL, NULL
2016 {"log_temp_files", PGC_SUSET, LOGGING_WHAT,
2017 gettext_noop("Log the use of temporary files larger than this number of kilobytes."),
2018 gettext_noop("Zero logs all files. The default is -1 (turning this feature off)."),
2022 -1, -1, INT_MAX, NULL, NULL
2026 {"track_activity_query_size", PGC_POSTMASTER, RESOURCES_MEM,
2027 gettext_noop("Sets the size reserved for pg_stat_activity.current_query, in bytes."),
2030 &pgstat_track_activity_query_size,
2031 1024, 100, 102400, NULL, NULL
2034 /* End-of-list marker */
2036 {NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL
2041 static struct config_real ConfigureNamesReal[] =
2044 {"seq_page_cost", PGC_USERSET, QUERY_TUNING_COST,
2045 gettext_noop("Sets the planner's estimate of the cost of a "
2046 "sequentially fetched disk page."),
2050 DEFAULT_SEQ_PAGE_COST, 0, DBL_MAX, NULL, NULL
2053 {"random_page_cost", PGC_USERSET, QUERY_TUNING_COST,
2054 gettext_noop("Sets the planner's estimate of the cost of a "
2055 "nonsequentially fetched disk page."),
2059 DEFAULT_RANDOM_PAGE_COST, 0, DBL_MAX, NULL, NULL
2062 {"cpu_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
2063 gettext_noop("Sets the planner's estimate of the cost of "
2064 "processing each tuple (row)."),
2068 DEFAULT_CPU_TUPLE_COST, 0, DBL_MAX, NULL, NULL
2071 {"cpu_index_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
2072 gettext_noop("Sets the planner's estimate of the cost of "
2073 "processing each index entry during an index scan."),
2076 &cpu_index_tuple_cost,
2077 DEFAULT_CPU_INDEX_TUPLE_COST, 0, DBL_MAX, NULL, NULL
2080 {"cpu_operator_cost", PGC_USERSET, QUERY_TUNING_COST,
2081 gettext_noop("Sets the planner's estimate of the cost of "
2082 "processing each operator or function call."),
2086 DEFAULT_CPU_OPERATOR_COST, 0, DBL_MAX, NULL, NULL
2090 {"cursor_tuple_fraction", PGC_USERSET, QUERY_TUNING_OTHER,
2091 gettext_noop("Sets the planner's estimate of the fraction of "
2092 "a cursor's rows that will be retrieved."),
2095 &cursor_tuple_fraction,
2096 DEFAULT_CURSOR_TUPLE_FRACTION, 0.0, 1.0, NULL, NULL
2100 {"geqo_selection_bias", PGC_USERSET, QUERY_TUNING_GEQO,
2101 gettext_noop("GEQO: selective pressure within the population."),
2104 &Geqo_selection_bias,
2105 DEFAULT_GEQO_SELECTION_BIAS, MIN_GEQO_SELECTION_BIAS,
2106 MAX_GEQO_SELECTION_BIAS, NULL, NULL
2109 {"geqo_seed", PGC_USERSET, QUERY_TUNING_GEQO,
2110 gettext_noop("GEQO: seed for random path selection."),
2114 0.0, 0.0, 1.0, NULL, NULL
2118 {"bgwriter_lru_multiplier", PGC_SIGHUP, RESOURCES,
2119 gettext_noop("Multiple of the average buffer usage to free per round."),
2122 &bgwriter_lru_multiplier,
2123 2.0, 0.0, 10.0, NULL, NULL
2127 {"seed", PGC_USERSET, UNGROUPED,
2128 gettext_noop("Sets the seed for random-number generation."),
2130 GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2133 0.0, -1.0, 1.0, assign_random_seed, show_random_seed
2137 {"autovacuum_vacuum_scale_factor", PGC_SIGHUP, AUTOVACUUM,
2138 gettext_noop("Number of tuple updates or deletes prior to vacuum as a fraction of reltuples."),
2141 &autovacuum_vac_scale,
2142 0.2, 0.0, 100.0, NULL, NULL
2145 {"autovacuum_analyze_scale_factor", PGC_SIGHUP, AUTOVACUUM,
2146 gettext_noop("Number of tuple inserts, updates or deletes prior to analyze as a fraction of reltuples."),
2149 &autovacuum_anl_scale,
2150 0.1, 0.0, 100.0, NULL, NULL
2154 {"checkpoint_completion_target", PGC_SIGHUP, WAL_CHECKPOINTS,
2155 gettext_noop("Time spent flushing dirty buffers during checkpoint, as fraction of checkpoint interval."),
2158 &CheckPointCompletionTarget,
2159 0.5, 0.0, 1.0, NULL, NULL
2162 /* End-of-list marker */
2164 {NULL, 0, 0, NULL, NULL}, NULL, 0.0, 0.0, 0.0, NULL, NULL
2169 static struct config_string ConfigureNamesString[] =
2172 {"archive_command", PGC_SIGHUP, WAL_SETTINGS,
2173 gettext_noop("Sets the shell command that will be called to archive a WAL file."),
2176 &XLogArchiveCommand,
2177 "", NULL, show_archive_command
2181 {"client_encoding", PGC_USERSET, CLIENT_CONN_LOCALE,
2182 gettext_noop("Sets the client's character set encoding."),
2184 GUC_IS_NAME | GUC_REPORT
2186 &client_encoding_string,
2187 "SQL_ASCII", assign_client_encoding, NULL
2191 {"log_line_prefix", PGC_SIGHUP, LOGGING_WHAT,
2192 gettext_noop("Controls information prefixed to each log line."),
2193 gettext_noop("If blank, no prefix is used.")
2200 {"log_timezone", PGC_SIGHUP, LOGGING_WHAT,
2201 gettext_noop("Sets the time zone to use in log messages."),
2204 &log_timezone_string,
2205 "UNKNOWN", assign_log_timezone, show_log_timezone
2209 {"DateStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
2210 gettext_noop("Sets the display format for date and time values."),
2211 gettext_noop("Also controls interpretation of ambiguous "
2213 GUC_LIST_INPUT | GUC_REPORT
2216 "ISO, MDY", assign_datestyle, NULL
2220 {"default_tablespace", PGC_USERSET, CLIENT_CONN_STATEMENT,
2221 gettext_noop("Sets the default tablespace to create tables and indexes in."),
2222 gettext_noop("An empty string selects the database's default tablespace."),
2225 &default_tablespace,
2226 "", assign_default_tablespace, NULL
2230 {"temp_tablespaces", PGC_USERSET, CLIENT_CONN_STATEMENT,
2231 gettext_noop("Sets the tablespace(s) to use for temporary tables and sort files."),
2233 GUC_LIST_INPUT | GUC_LIST_QUOTE
2236 "", assign_temp_tablespaces, NULL
2240 {"dynamic_library_path", PGC_SUSET, CLIENT_CONN_OTHER,
2241 gettext_noop("Sets the path for dynamically loadable modules."),
2242 gettext_noop("If a dynamically loadable module needs to be opened and "
2243 "the specified name does not have a directory component (i.e., the "
2244 "name does not contain a slash), the system will search this path for "
2245 "the specified file."),
2248 &Dynamic_library_path,
2249 "$libdir", NULL, NULL
2253 {"krb_server_keyfile", PGC_SIGHUP, CONN_AUTH_SECURITY,
2254 gettext_noop("Sets the location of the Kerberos server key file."),
2258 &pg_krb_server_keyfile,
2259 PG_KRB_SRVTAB, NULL, NULL
2263 {"krb_srvname", PGC_SIGHUP, CONN_AUTH_SECURITY,
2264 gettext_noop("Sets the name of the Kerberos service."),
2268 PG_KRB_SRVNAM, NULL, NULL
2272 {"bonjour_name", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2273 gettext_noop("Sets the Bonjour service name."),
2280 /* See main.c about why defaults for LC_foo are not all alike */
2283 {"lc_collate", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2284 gettext_noop("Shows the collation order locale."),
2286 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2293 {"lc_ctype", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2294 gettext_noop("Shows the character classification and case conversion locale."),
2296 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2303 {"lc_messages", PGC_SUSET, CLIENT_CONN_LOCALE,
2304 gettext_noop("Sets the language in which messages are displayed."),
2308 "", locale_messages_assign, NULL
2312 {"lc_monetary", PGC_USERSET, CLIENT_CONN_LOCALE,
2313 gettext_noop("Sets the locale for formatting monetary amounts."),
2317 "C", locale_monetary_assign, NULL
2321 {"lc_numeric", PGC_USERSET, CLIENT_CONN_LOCALE,
2322 gettext_noop("Sets the locale for formatting numbers."),
2326 "C", locale_numeric_assign, NULL
2330 {"lc_time", PGC_USERSET, CLIENT_CONN_LOCALE,
2331 gettext_noop("Sets the locale for formatting date and time values."),
2335 "C", locale_time_assign, NULL
2339 {"shared_preload_libraries", PGC_POSTMASTER, RESOURCES_KERNEL,
2340 gettext_noop("Lists shared libraries to preload into server."),
2342 GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
2344 &shared_preload_libraries_string,
2349 {"local_preload_libraries", PGC_BACKEND, CLIENT_CONN_OTHER,
2350 gettext_noop("Lists shared libraries to preload into each backend."),
2352 GUC_LIST_INPUT | GUC_LIST_QUOTE
2354 &local_preload_libraries_string,
2359 {"search_path", PGC_USERSET, CLIENT_CONN_STATEMENT,
2360 gettext_noop("Sets the schema search order for names that are not schema-qualified."),
2362 GUC_LIST_INPUT | GUC_LIST_QUOTE
2364 &namespace_search_path,
2365 "\"$user\",public", assign_search_path, NULL
2369 /* Can't be set in postgresql.conf */
2370 {"server_encoding", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2371 gettext_noop("Sets the server (database) character set encoding."),
2373 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2375 &server_encoding_string,
2376 "SQL_ASCII", NULL, NULL
2380 /* Can't be set in postgresql.conf */
2381 {"server_version", PGC_INTERNAL, PRESET_OPTIONS,
2382 gettext_noop("Shows the server version."),
2384 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2386 &server_version_string,
2387 PG_VERSION, NULL, NULL
2391 /* Not for general use --- used by SET ROLE */
2392 {"role", PGC_USERSET, UNGROUPED,
2393 gettext_noop("Sets the current role."),
2395 GUC_IS_NAME | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_NOT_WHILE_SEC_REST
2398 "none", assign_role, show_role
2402 /* Not for general use --- used by SET SESSION AUTHORIZATION */
2403 {"session_authorization", PGC_USERSET, UNGROUPED,
2404 gettext_noop("Sets the session user name."),
2406 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
2408 &session_authorization_string,
2409 NULL, assign_session_authorization, show_session_authorization
2413 {"log_destination", PGC_SIGHUP, LOGGING_WHERE,
2414 gettext_noop("Sets the destination for server log output."),
2415 gettext_noop("Valid values are combinations of \"stderr\", "
2416 "\"syslog\", \"csvlog\", and \"eventlog\", "
2417 "depending on the platform."),
2420 &log_destination_string,
2421 "stderr", assign_log_destination, NULL
2424 {"log_directory", PGC_SIGHUP, LOGGING_WHERE,
2425 gettext_noop("Sets the destination directory for log files."),
2426 gettext_noop("Can be specified as relative to the data directory "
2427 "or as absolute path."),
2431 "pg_log", assign_canonical_path, NULL
2434 {"log_filename", PGC_SIGHUP, LOGGING_WHERE,
2435 gettext_noop("Sets the file name pattern for log files."),
2440 "postgresql-%Y-%m-%d_%H%M%S.log", NULL, NULL
2445 {"syslog_ident", PGC_SIGHUP, LOGGING_WHERE,
2446 gettext_noop("Sets the program name used to identify PostgreSQL "
2447 "messages in syslog."),
2451 "postgres", assign_syslog_ident, NULL
2456 {"TimeZone", PGC_USERSET, CLIENT_CONN_LOCALE,
2457 gettext_noop("Sets the time zone for displaying and interpreting time stamps."),
2462 "UNKNOWN", assign_timezone, show_timezone
2465 {"timezone_abbreviations", PGC_USERSET, CLIENT_CONN_LOCALE,
2466 gettext_noop("Selects a file of time zone abbreviations."),
2469 &timezone_abbreviations_string,
2470 "UNKNOWN", assign_timezone_abbreviations, NULL
2474 {"transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
2475 gettext_noop("Sets the current transaction's isolation level."),
2477 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2479 &XactIsoLevel_string,
2480 NULL, assign_XactIsoLevel, show_XactIsoLevel
2484 {"unix_socket_group", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2485 gettext_noop("Sets the owning group of the Unix-domain socket."),
2486 gettext_noop("The owning user of the socket is always the user "
2487 "that starts the server.")
2494 {"unix_socket_directory", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2495 gettext_noop("Sets the directory where the Unix-domain socket will be created."),
2500 "", assign_canonical_path, NULL
2504 {"listen_addresses", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2505 gettext_noop("Sets the host name or IP address(es) to listen to."),
2510 "localhost", NULL, NULL
2514 {"custom_variable_classes", PGC_SIGHUP, CUSTOM_OPTIONS,
2515 gettext_noop("Sets the list of known custom variable classes."),
2517 GUC_LIST_INPUT | GUC_LIST_QUOTE
2519 &custom_variable_classes,
2520 NULL, assign_custom_variable_classes, NULL
2524 {"data_directory", PGC_POSTMASTER, FILE_LOCATIONS,
2525 gettext_noop("Sets the server's data directory."),
2534 {"config_file", PGC_POSTMASTER, FILE_LOCATIONS,
2535 gettext_noop("Sets the server's main configuration file."),
2537 GUC_DISALLOW_IN_FILE | GUC_SUPERUSER_ONLY
2544 {"hba_file", PGC_POSTMASTER, FILE_LOCATIONS,
2545 gettext_noop("Sets the server's \"hba\" configuration file."),
2554 {"ident_file", PGC_POSTMASTER, FILE_LOCATIONS,
2555 gettext_noop("Sets the server's \"ident\" configuration file."),
2564 {"external_pid_file", PGC_POSTMASTER, FILE_LOCATIONS,
2565 gettext_noop("Writes the postmaster PID to the specified file."),
2570 NULL, assign_canonical_path, NULL
2574 {"stats_temp_directory", PGC_SIGHUP, STATS_COLLECTOR,
2575 gettext_noop("Writes temporary statistics files to the specified directory."),
2579 &pgstat_temp_directory,
2580 "pg_stat_tmp", assign_pgstat_temp_directory, NULL
2584 {"default_text_search_config", PGC_USERSET, CLIENT_CONN_LOCALE,
2585 gettext_noop("Sets default text search configuration."),
2589 "pg_catalog.simple", assignTSCurrentConfig, NULL
2594 {"ssl_ciphers", PGC_POSTMASTER, CONN_AUTH_SECURITY,
2595 gettext_noop("Sets the list of allowed SSL ciphers."),
2600 "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH", NULL, NULL
2602 #endif /* USE_SSL */
2605 {"application_name", PGC_USERSET, LOGGING,
2606 gettext_noop("Sets the application name to be reported in statistics and logs."),
2608 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE
2611 "", assign_application_name, NULL
2614 /* End-of-list marker */
2616 {NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL
2621 static struct config_enum ConfigureNamesEnum[] =
2624 {"backslash_quote", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
2625 gettext_noop("Sets whether \"\\'\" is allowed in string literals."),
2629 BACKSLASH_QUOTE_SAFE_ENCODING, backslash_quote_options, NULL, NULL
2633 {"bytea_output", PGC_USERSET, CLIENT_CONN_STATEMENT,
2634 gettext_noop("Sets the output format for bytea."),
2638 BYTEA_OUTPUT_HEX, bytea_output_options, NULL, NULL
2642 {"client_min_messages", PGC_USERSET, LOGGING_WHEN,
2643 gettext_noop("Sets the message levels that are sent to the client."),
2644 gettext_noop("Each level includes all the levels that follow it. The later"
2645 " the level, the fewer messages are sent.")
2647 &client_min_messages,
2648 NOTICE, client_message_level_options, NULL, NULL
2652 {"constraint_exclusion", PGC_USERSET, QUERY_TUNING_OTHER,
2653 gettext_noop("Enables the planner to use constraints to optimize queries."),
2654 gettext_noop("Table scans will be skipped if their constraints"
2655 " guarantee that no rows match the query.")
2657 &constraint_exclusion,
2658 CONSTRAINT_EXCLUSION_PARTITION, constraint_exclusion_options,
2663 {"default_transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
2664 gettext_noop("Sets the transaction isolation level of each new transaction."),
2667 &DefaultXactIsoLevel,
2668 XACT_READ_COMMITTED, isolation_level_options, NULL, NULL
2672 {"IntervalStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
2673 gettext_noop("Sets the display format for interval values."),
2678 INTSTYLE_POSTGRES, intervalstyle_options, NULL, NULL
2682 {"log_error_verbosity", PGC_SUSET, LOGGING_WHAT,
2683 gettext_noop("Sets the verbosity of logged messages."),
2686 &Log_error_verbosity,
2687 PGERROR_DEFAULT, log_error_verbosity_options, NULL, NULL
2691 {"log_min_messages", PGC_SUSET, LOGGING_WHEN,
2692 gettext_noop("Sets the message levels that are logged."),
2693 gettext_noop("Each level includes all the levels that follow it. The later"
2694 " the level, the fewer messages are sent.")
2697 WARNING, server_message_level_options, NULL, NULL
2701 {"log_min_error_statement", PGC_SUSET, LOGGING_WHEN,
2702 gettext_noop("Causes all statements generating error at or above this level to be logged."),
2703 gettext_noop("Each level includes all the levels that follow it. The later"
2704 " the level, the fewer messages are sent.")
2706 &log_min_error_statement,
2707 ERROR, server_message_level_options, NULL, NULL
2711 {"log_statement", PGC_SUSET, LOGGING_WHAT,
2712 gettext_noop("Sets the type of statements logged."),
2716 LOGSTMT_NONE, log_statement_options, NULL, NULL
2721 {"syslog_facility", PGC_SIGHUP, LOGGING_WHERE,
2722 gettext_noop("Sets the syslog \"facility\" to be used when syslog enabled."),
2726 LOG_LOCAL0, syslog_facility_options, assign_syslog_facility, NULL
2731 {"session_replication_role", PGC_SUSET, CLIENT_CONN_STATEMENT,
2732 gettext_noop("Sets the session's behavior for triggers and rewrite rules."),
2735 &SessionReplicationRole,
2736 SESSION_REPLICATION_ROLE_ORIGIN, session_replication_role_options,
2737 assign_session_replication_role, NULL
2741 {"trace_recovery_messages", PGC_SUSET, LOGGING_WHEN,
2742 gettext_noop("Sets the message levels that are logged during recovery."),
2743 gettext_noop("Each level includes all the levels that follow it. The later"
2744 " the level, the fewer messages are sent.")
2746 &trace_recovery_messages,
2747 DEBUG1, server_message_level_options, NULL, NULL
2751 {"track_functions", PGC_SUSET, STATS_COLLECTOR,
2752 gettext_noop("Collects function-level statistics on database activity."),
2755 &pgstat_track_functions,
2756 TRACK_FUNC_OFF, track_function_options, NULL, NULL
2760 {"wal_sync_method", PGC_SIGHUP, WAL_SETTINGS,
2761 gettext_noop("Selects the method used for forcing WAL updates to disk."),
2765 DEFAULT_SYNC_METHOD, sync_method_options,
2766 assign_xlog_sync_method, NULL
2770 {"xmlbinary", PGC_USERSET, CLIENT_CONN_STATEMENT,
2771 gettext_noop("Sets how binary values are to be encoded in XML."),
2775 XMLBINARY_BASE64, xmlbinary_options, NULL, NULL
2779 {"xmloption", PGC_USERSET, CLIENT_CONN_STATEMENT,
2780 gettext_noop("Sets whether XML data in implicit parsing and serialization "
2781 "operations is to be considered as documents or content fragments."),
2785 XMLOPTION_CONTENT, xmloption_options, NULL, NULL
2789 /* End-of-list marker */
2791 {NULL, 0, 0, NULL, NULL}, NULL, 0, NULL, NULL, NULL
2795 /******** end of options list ********/
2799 * To allow continued support of obsolete names for GUC variables, we apply
2800 * the following mappings to any unrecognized name. Note that an old name
2801 * should be mapped to a new one only if the new variable has very similar
2802 * semantics to the old.
2804 static const char *const map_old_guc_names[] = {
2805 "sort_mem", "work_mem",
2806 "vacuum_mem", "maintenance_work_mem",
2812 * Actual lookup of variables is done through this single, sorted array.
2814 static struct config_generic **guc_variables;
2816 /* Current number of variables contained in the vector */
2817 static int num_guc_variables;
2819 /* Vector capacity */
2820 static int size_guc_variables;
2823 static bool guc_dirty; /* TRUE if need to do commit/abort work */
2825 static bool reporting_enabled; /* TRUE to enable GUC_REPORT */
2827 static int GUCNestLevel = 0; /* 1 when in main transaction */
2830 static int guc_var_compare(const void *a, const void *b);
2831 static int guc_name_compare(const char *namea, const char *nameb);
2832 static void InitializeOneGUCOption(struct config_generic * gconf);
2833 static void push_old_value(struct config_generic * gconf, GucAction action);
2834 static void ReportGUCOption(struct config_generic * record);
2835 static void ShowGUCConfigOption(const char *name, DestReceiver *dest);
2836 static void ShowAllGUCConfig(DestReceiver *dest);
2837 static char *_ShowOption(struct config_generic * record, bool use_units);
2838 static bool is_newvalue_equal(struct config_generic * record, const char *newvalue);
2842 * Some infrastructure for checking malloc/strdup/realloc calls
2845 guc_malloc(int elevel, size_t size)
2849 data = malloc(size);
2852 (errcode(ERRCODE_OUT_OF_MEMORY),
2853 errmsg("out of memory")));
2858 guc_realloc(int elevel, void *old, size_t size)
2862 data = realloc(old, size);
2865 (errcode(ERRCODE_OUT_OF_MEMORY),
2866 errmsg("out of memory")));
2871 guc_strdup(int elevel, const char *src)
2878 (errcode(ERRCODE_OUT_OF_MEMORY),
2879 errmsg("out of memory")));
2885 * Support for assigning to a field of a string GUC item. Free the prior
2886 * value if it's not referenced anywhere else in the item (including stacked
2890 set_string_field(struct config_string * conf, char **field, char *newval)
2892 char *oldval = *field;
2895 /* Do the assignment */
2898 /* Exit if any duplicate references, or if old value was NULL anyway */
2899 if (oldval == NULL ||
2900 oldval == *(conf->variable) ||
2901 oldval == conf->reset_val ||
2902 oldval == conf->boot_val)
2904 for (stack = conf->gen.stack; stack; stack = stack->prev)
2906 if (oldval == stack->prior.stringval ||
2907 oldval == stack->masked.stringval)
2911 /* Not used anymore, so free it */
2916 * Detect whether strval is referenced anywhere in a GUC string item
2919 string_field_used(struct config_string * conf, char *strval)
2923 if (strval == *(conf->variable) ||
2924 strval == conf->reset_val ||
2925 strval == conf->boot_val)
2927 for (stack = conf->gen.stack; stack; stack = stack->prev)
2929 if (strval == stack->prior.stringval ||
2930 strval == stack->masked.stringval)
2937 * Support for copying a variable's active value into a stack entry
2940 set_stack_value(struct config_generic * gconf, union config_var_value * val)
2942 switch (gconf->vartype)
2946 *((struct config_bool *) gconf)->variable;
2950 *((struct config_int *) gconf)->variable;
2954 *((struct config_real *) gconf)->variable;
2957 /* we assume stringval is NULL if not valid */
2958 set_string_field((struct config_string *) gconf,
2960 *((struct config_string *) gconf)->variable);
2964 *((struct config_enum *) gconf)->variable;
2970 * Support for discarding a no-longer-needed value in a stack entry
2973 discard_stack_value(struct config_generic * gconf, union config_var_value * val)
2975 switch (gconf->vartype)
2981 /* no need to do anything */
2984 set_string_field((struct config_string *) gconf,
2993 * Fetch the sorted array pointer (exported for help_config.c's use ONLY)
2995 struct config_generic **
2996 get_guc_variables(void)
2998 return guc_variables;
3003 * Build the sorted array. This is split out so that it could be
3004 * re-executed after startup (eg, we could allow loadable modules to
3005 * add vars, and then we'd need to re-sort).
3008 build_guc_variables(void)
3012 struct config_generic **guc_vars;
3015 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
3017 struct config_bool *conf = &ConfigureNamesBool[i];
3019 /* Rather than requiring vartype to be filled in by hand, do this: */
3020 conf->gen.vartype = PGC_BOOL;
3024 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
3026 struct config_int *conf = &ConfigureNamesInt[i];
3028 conf->gen.vartype = PGC_INT;
3032 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
3034 struct config_real *conf = &ConfigureNamesReal[i];
3036 conf->gen.vartype = PGC_REAL;
3040 for (i = 0; ConfigureNamesString[i].gen.name; i++)
3042 struct config_string *conf = &ConfigureNamesString[i];
3044 conf->gen.vartype = PGC_STRING;
3048 for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
3050 struct config_enum *conf = &ConfigureNamesEnum[i];
3052 conf->gen.vartype = PGC_ENUM;
3057 * Create table with 20% slack
3059 size_vars = num_vars + num_vars / 4;
3061 guc_vars = (struct config_generic **)
3062 guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
3066 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
3067 guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
3069 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
3070 guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
3072 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
3073 guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
3075 for (i = 0; ConfigureNamesString[i].gen.name; i++)
3076 guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
3078 for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
3079 guc_vars[num_vars++] = &ConfigureNamesEnum[i].gen;
3082 free(guc_variables);
3083 guc_variables = guc_vars;
3084 num_guc_variables = num_vars;
3085 size_guc_variables = size_vars;
3086 qsort((void *) guc_variables, num_guc_variables,
3087 sizeof(struct config_generic *), guc_var_compare);
3091 * Add a new GUC variable to the list of known variables. The
3092 * list is expanded if needed.
3095 add_guc_variable(struct config_generic * var, int elevel)
3097 if (num_guc_variables + 1 >= size_guc_variables)
3100 * Increase the vector by 25%
3102 int size_vars = size_guc_variables + size_guc_variables / 4;
3103 struct config_generic **guc_vars;
3108 guc_vars = (struct config_generic **)
3109 guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
3113 guc_vars = (struct config_generic **)
3114 guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
3117 if (guc_vars == NULL)
3118 return false; /* out of memory */
3120 guc_variables = guc_vars;
3121 size_guc_variables = size_vars;
3123 guc_variables[num_guc_variables++] = var;
3124 qsort((void *) guc_variables, num_guc_variables,
3125 sizeof(struct config_generic *), guc_var_compare);
3130 * Create and add a placeholder variable. It's presumed to belong
3131 * to a valid custom variable class at this point.
3133 static struct config_generic *
3134 add_placeholder_variable(const char *name, int elevel)
3136 size_t sz = sizeof(struct config_string) + sizeof(char *);
3137 struct config_string *var;
3138 struct config_generic *gen;
3140 var = (struct config_string *) guc_malloc(elevel, sz);
3146 gen->name = guc_strdup(elevel, name);
3147 if (gen->name == NULL)
3153 gen->context = PGC_USERSET;
3154 gen->group = CUSTOM_OPTIONS;
3155 gen->short_desc = "GUC placeholder variable";
3156 gen->flags = GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_CUSTOM_PLACEHOLDER;
3157 gen->vartype = PGC_STRING;
3160 * The char* is allocated at the end of the struct since we have no
3161 * 'static' place to point to. Note that the current value, as well as
3162 * the boot and reset values, start out NULL.
3164 var->variable = (char **) (var + 1);
3166 if (!add_guc_variable((struct config_generic *) var, elevel))
3168 free((void *) gen->name);
3177 * Detect whether the portion of "name" before dotPos matches any custom
3178 * variable class name listed in custom_var_classes. The latter must be
3179 * formatted the way that assign_custom_variable_classes does it, ie,
3180 * no whitespace. NULL is valid for custom_var_classes.
3183 is_custom_class(const char *name, int dotPos, const char *custom_var_classes)
3185 bool result = false;
3186 const char *ccs = custom_var_classes;
3190 const char *start = ccs;
3196 if (c == '\0' || c == ',')
3198 if (dotPos == ccs - start && strncmp(start, name, dotPos) == 0)
3213 * Look up option NAME. If it exists, return a pointer to its record,
3214 * else return NULL. If create_placeholders is TRUE, we'll create a
3215 * placeholder record for a valid-looking custom variable name.
3217 static struct config_generic *
3218 find_option(const char *name, bool create_placeholders, int elevel)
3220 const char **key = &name;
3221 struct config_generic **res;
3227 * By equating const char ** with struct config_generic *, we are assuming
3228 * the name field is first in config_generic.
3230 res = (struct config_generic **) bsearch((void *) &key,
3231 (void *) guc_variables,
3233 sizeof(struct config_generic *),
3239 * See if the name is an obsolete name for a variable. We assume that the
3240 * set of supported old names is short enough that a brute-force search is
3243 for (i = 0; map_old_guc_names[i] != NULL; i += 2)
3245 if (guc_name_compare(name, map_old_guc_names[i]) == 0)
3246 return find_option(map_old_guc_names[i + 1], false, elevel);
3249 if (create_placeholders)
3252 * Check if the name is qualified, and if so, check if the qualifier
3253 * matches any custom variable class. If so, add a placeholder.
3255 const char *dot = strchr(name, GUC_QUALIFIER_SEPARATOR);
3258 is_custom_class(name, dot - name, custom_variable_classes))
3259 return add_placeholder_variable(name, elevel);
3268 * comparator for qsorting and bsearching guc_variables array
3271 guc_var_compare(const void *a, const void *b)
3273 struct config_generic *confa = *(struct config_generic **) a;
3274 struct config_generic *confb = *(struct config_generic **) b;
3276 return guc_name_compare(confa->name, confb->name);
3280 * the bare comparison function for GUC names
3283 guc_name_compare(const char *namea, const char *nameb)
3286 * The temptation to use strcasecmp() here must be resisted, because the
3287 * array ordering has to remain stable across setlocale() calls. So, build
3288 * our own with a simple ASCII-only downcasing.
3290 while (*namea && *nameb)
3292 char cha = *namea++;
3293 char chb = *nameb++;
3295 if (cha >= 'A' && cha <= 'Z')
3297 if (chb >= 'A' && chb <= 'Z')
3303 return 1; /* a is longer */
3305 return -1; /* b is longer */
3311 * Initialize GUC options during program startup.
3313 * Note that we cannot read the config file yet, since we have not yet
3314 * processed command-line switches.
3317 InitializeGUCOptions(void)
3324 * Before log_line_prefix could possibly receive a nonempty setting, make
3325 * sure that timezone processing is minimally alive (see elog.c).
3327 pg_timezone_pre_initialize();
3330 * Build sorted array of all GUC variables.
3332 build_guc_variables();
3335 * Load all variables with their compiled-in defaults, and initialize
3336 * status fields as needed.
3338 for (i = 0; i < num_guc_variables; i++)
3340 InitializeOneGUCOption(guc_variables[i]);
3345 reporting_enabled = false;
3348 * Prevent any attempt to override the transaction modes from
3349 * non-interactive sources.
3351 SetConfigOption("transaction_isolation", "default",
3352 PGC_POSTMASTER, PGC_S_OVERRIDE);
3353 SetConfigOption("transaction_read_only", "no",
3354 PGC_POSTMASTER, PGC_S_OVERRIDE);
3357 * For historical reasons, some GUC parameters can receive defaults from
3358 * environment variables. Process those settings. NB: if you add or
3359 * remove anything here, see also ProcessConfigFile().
3362 env = getenv("PGPORT");
3364 SetConfigOption("port", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3366 env = getenv("PGDATESTYLE");
3368 SetConfigOption("datestyle", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3370 env = getenv("PGCLIENTENCODING");
3372 SetConfigOption("client_encoding", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3375 * rlimit isn't exactly an "environment variable", but it behaves about
3376 * the same. If we can identify the platform stack depth rlimit, increase
3377 * default stack depth setting up to whatever is safe (but at most 2MB).
3379 stack_rlimit = get_stack_depth_rlimit();
3380 if (stack_rlimit > 0)
3382 int new_limit = (stack_rlimit - STACK_DEPTH_SLOP) / 1024L;
3384 if (new_limit > 100)
3388 new_limit = Min(new_limit, 2048);
3389 sprintf(limbuf, "%d", new_limit);
3390 SetConfigOption("max_stack_depth", limbuf,
3391 PGC_POSTMASTER, PGC_S_ENV_VAR);
3397 * Initialize one GUC option variable to its compiled-in default.
3400 InitializeOneGUCOption(struct config_generic * gconf)
3403 gconf->reset_source = PGC_S_DEFAULT;
3404 gconf->source = PGC_S_DEFAULT;
3405 gconf->stack = NULL;
3406 gconf->sourcefile = NULL;
3407 gconf->sourceline = 0;
3409 switch (gconf->vartype)
3413 struct config_bool *conf = (struct config_bool *) gconf;
3415 if (conf->assign_hook)
3416 if (!(*conf->assign_hook) (conf->boot_val, true,
3418 elog(FATAL, "failed to initialize %s to %d",
3419 conf->gen.name, (int) conf->boot_val);
3420 *conf->variable = conf->reset_val = conf->boot_val;
3425 struct config_int *conf = (struct config_int *) gconf;
3427 Assert(conf->boot_val >= conf->min);
3428 Assert(conf->boot_val <= conf->max);
3429 if (conf->assign_hook)
3430 if (!(*conf->assign_hook) (conf->boot_val, true,
3432 elog(FATAL, "failed to initialize %s to %d",
3433 conf->gen.name, conf->boot_val);
3434 *conf->variable = conf->reset_val = conf->boot_val;
3439 struct config_real *conf = (struct config_real *) gconf;
3441 Assert(conf->boot_val >= conf->min);
3442 Assert(conf->boot_val <= conf->max);
3443 if (conf->assign_hook)
3444 if (!(*conf->assign_hook) (conf->boot_val, true,
3446 elog(FATAL, "failed to initialize %s to %g",
3447 conf->gen.name, conf->boot_val);
3448 *conf->variable = conf->reset_val = conf->boot_val;
3453 struct config_string *conf = (struct config_string *) gconf;
3456 *conf->variable = NULL;
3457 conf->reset_val = NULL;
3459 if (conf->boot_val == NULL)
3461 /* leave the value NULL, do not call assign hook */
3465 str = guc_strdup(FATAL, conf->boot_val);
3466 conf->reset_val = str;
3468 if (conf->assign_hook)
3472 newstr = (*conf->assign_hook) (str, true,
3476 elog(FATAL, "failed to initialize %s to \"%s\"",
3477 conf->gen.name, str);
3479 else if (newstr != str)
3484 * See notes in set_config_option about casting
3486 str = (char *) newstr;
3487 conf->reset_val = str;
3490 *conf->variable = str;
3495 struct config_enum *conf = (struct config_enum *) gconf;
3497 if (conf->assign_hook)
3498 if (!(*conf->assign_hook) (conf->boot_val, true,
3500 elog(FATAL, "failed to initialize %s to %s",
3502 config_enum_lookup_by_value(conf, conf->boot_val));
3503 *conf->variable = conf->reset_val = conf->boot_val;
3511 * Select the configuration files and data directory to be used, and
3512 * do the initial read of postgresql.conf.
3514 * This is called after processing command-line switches.
3515 * userDoption is the -D switch value if any (NULL if unspecified).
3516 * progname is just for use in error messages.
3518 * Returns true on success; on failure, prints a suitable error message
3519 * to stderr and returns false.
3522 SelectConfigFiles(const char *userDoption, const char *progname)
3526 struct stat stat_buf;
3528 /* configdir is -D option, or $PGDATA if no -D */
3530 configdir = make_absolute_path(userDoption);
3532 configdir = make_absolute_path(getenv("PGDATA"));
3535 * Find the configuration file: if config_file was specified on the
3536 * command line, use it, else use configdir/postgresql.conf. In any case
3537 * ensure the result is an absolute path, so that it will be interpreted
3538 * the same way by future backends.
3541 fname = make_absolute_path(ConfigFileName);
3544 fname = guc_malloc(FATAL,
3545 strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
3546 sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
3550 write_stderr("%s does not know where to find the server configuration file.\n"
3551 "You must specify the --config-file or -D invocation "
3552 "option or set the PGDATA environment variable.\n",
3558 * Set the ConfigFileName GUC variable to its final value, ensuring that
3559 * it can't be overridden later.
3561 SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
3565 * Now read the config file for the first time.
3567 if (stat(ConfigFileName, &stat_buf) != 0)
3569 write_stderr("%s cannot access the server configuration file \"%s\": %s\n",
3570 progname, ConfigFileName, strerror(errno));
3574 ProcessConfigFile(PGC_POSTMASTER);
3577 * If the data_directory GUC variable has been set, use that as DataDir;
3578 * otherwise use configdir if set; else punt.
3580 * Note: SetDataDir will copy and absolute-ize its argument, so we don't
3584 SetDataDir(data_directory);
3586 SetDataDir(configdir);
3589 write_stderr("%s does not know where to find the database system data.\n"
3590 "This can be specified as \"data_directory\" in \"%s\", "
3591 "or by the -D invocation option, or by the "
3592 "PGDATA environment variable.\n",
3593 progname, ConfigFileName);
3598 * Reflect the final DataDir value back into the data_directory GUC var.
3599 * (If you are wondering why we don't just make them a single variable,
3600 * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
3601 * child backends specially. XXX is that still true? Given that we now
3602 * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
3603 * DataDir in advance.)
3605 SetConfigOption("data_directory", DataDir, PGC_POSTMASTER, PGC_S_OVERRIDE);
3608 * Figure out where pg_hba.conf is, and make sure the path is absolute.
3611 fname = make_absolute_path(HbaFileName);
3614 fname = guc_malloc(FATAL,
3615 strlen(configdir) + strlen(HBA_FILENAME) + 2);
3616 sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
3620 write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
3621 "This can be specified as \"hba_file\" in \"%s\", "
3622 "or by the -D invocation option, or by the "
3623 "PGDATA environment variable.\n",
3624 progname, ConfigFileName);
3627 SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
3631 * Likewise for pg_ident.conf.
3634 fname = make_absolute_path(IdentFileName);
3637 fname = guc_malloc(FATAL,
3638 strlen(configdir) + strlen(IDENT_FILENAME) + 2);
3639 sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
3643 write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
3644 "This can be specified as \"ident_file\" in \"%s\", "
3645 "or by the -D invocation option, or by the "
3646 "PGDATA environment variable.\n",
3647 progname, ConfigFileName);
3650 SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
3660 * Reset all options to their saved default values (implements RESET ALL)
3663 ResetAllOptions(void)
3667 for (i = 0; i < num_guc_variables; i++)
3669 struct config_generic *gconf = guc_variables[i];
3671 /* Don't reset non-SET-able values */
3672 if (gconf->context != PGC_SUSET &&
3673 gconf->context != PGC_USERSET)
3675 /* Don't reset if special exclusion from RESET ALL */
3676 if (gconf->flags & GUC_NO_RESET_ALL)
3678 /* No need to reset if wasn't SET */
3679 if (gconf->source <= PGC_S_OVERRIDE)
3682 /* Save old value to support transaction abort */
3683 push_old_value(gconf, GUC_ACTION_SET);
3685 switch (gconf->vartype)
3689 struct config_bool *conf = (struct config_bool *) gconf;
3691 if (conf->assign_hook)
3692 if (!(*conf->assign_hook) (conf->reset_val, true,
3694 elog(ERROR, "failed to reset %s to %d",
3695 conf->gen.name, (int) conf->reset_val);
3696 *conf->variable = conf->reset_val;
3701 struct config_int *conf = (struct config_int *) gconf;
3703 if (conf->assign_hook)
3704 if (!(*conf->assign_hook) (conf->reset_val, true,
3706 elog(ERROR, "failed to reset %s to %d",
3707 conf->gen.name, conf->reset_val);
3708 *conf->variable = conf->reset_val;
3713 struct config_real *conf = (struct config_real *) gconf;
3715 if (conf->assign_hook)
3716 if (!(*conf->assign_hook) (conf->reset_val, true,
3718 elog(ERROR, "failed to reset %s to %g",
3719 conf->gen.name, conf->reset_val);
3720 *conf->variable = conf->reset_val;
3725 struct config_string *conf = (struct config_string *) gconf;
3728 /* We need not strdup here */
3729 str = conf->reset_val;
3731 if (conf->assign_hook && str)
3735 newstr = (*conf->assign_hook) (str, true,
3738 elog(ERROR, "failed to reset %s to \"%s\"",
3739 conf->gen.name, str);
3740 else if (newstr != str)
3743 * See notes in set_config_option about casting
3745 str = (char *) newstr;
3749 set_string_field(conf, conf->variable, str);
3754 struct config_enum *conf = (struct config_enum *) gconf;
3756 if (conf->assign_hook)
3757 if (!(*conf->assign_hook) (conf->reset_val, true,
3759 elog(ERROR, "failed to reset %s to %s",
3761 config_enum_lookup_by_value(conf, conf->reset_val));
3762 *conf->variable = conf->reset_val;
3767 gconf->source = gconf->reset_source;
3769 if (gconf->flags & GUC_REPORT)
3770 ReportGUCOption(gconf);
3777 * Push previous state during transactional assignment to a GUC variable.
3780 push_old_value(struct config_generic * gconf, GucAction action)
3784 /* If we're not inside a nest level, do nothing */
3785 if (GUCNestLevel == 0)
3788 /* Do we already have a stack entry of the current nest level? */
3789 stack = gconf->stack;
3790 if (stack && stack->nest_level >= GUCNestLevel)
3792 /* Yes, so adjust its state if necessary */
3793 Assert(stack->nest_level == GUCNestLevel);
3796 case GUC_ACTION_SET:
3797 /* SET overrides any prior action at same nest level */
3798 if (stack->state == GUC_SET_LOCAL)
3800 /* must discard old masked value */
3801 discard_stack_value(gconf, &stack->masked);
3803 stack->state = GUC_SET;
3805 case GUC_ACTION_LOCAL:
3806 if (stack->state == GUC_SET)
3808 /* SET followed by SET LOCAL, remember SET's value */
3809 set_stack_value(gconf, &stack->masked);
3810 stack->state = GUC_SET_LOCAL;
3812 /* in all other cases, no change to stack entry */
3814 case GUC_ACTION_SAVE:
3815 /* Could only have a prior SAVE of same variable */
3816 Assert(stack->state == GUC_SAVE);
3819 Assert(guc_dirty); /* must be set already */
3824 * Push a new stack entry
3826 * We keep all the stack entries in TopTransactionContext for simplicity.
3828 stack = (GucStack *) MemoryContextAllocZero(TopTransactionContext,
3831 stack->prev = gconf->stack;
3832 stack->nest_level = GUCNestLevel;
3835 case GUC_ACTION_SET:
3836 stack->state = GUC_SET;
3838 case GUC_ACTION_LOCAL:
3839 stack->state = GUC_LOCAL;
3841 case GUC_ACTION_SAVE:
3842 stack->state = GUC_SAVE;
3845 stack->source = gconf->source;
3846 set_stack_value(gconf, &stack->prior);
3848 gconf->stack = stack;
3850 /* Ensure we remember to pop at end of xact */
3856 * Do GUC processing at main transaction start.
3862 * The nest level should be 0 between transactions; if it isn't, somebody
3863 * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
3864 * throw a warning but make no other effort to clean up.
3866 if (GUCNestLevel != 0)
3867 elog(WARNING, "GUC nest level = %d at transaction start",
3873 * Enter a new nesting level for GUC values. This is called at subtransaction
3874 * start and when entering a function that has proconfig settings. NOTE that
3875 * we must not risk error here, else subtransaction start will be unhappy.
3878 NewGUCNestLevel(void)
3880 return ++GUCNestLevel;
3884 * Do GUC processing at transaction or subtransaction commit or abort, or
3885 * when exiting a function that has proconfig settings. (The name is thus
3886 * a bit of a misnomer; perhaps it should be ExitGUCNestLevel or some such.)
3887 * During abort, we discard all GUC settings that were applied at nesting
3888 * levels >= nestLevel. nestLevel == 1 corresponds to the main transaction.
3891 AtEOXact_GUC(bool isCommit, int nestLevel)
3897 * Note: it's possible to get here with GUCNestLevel == nestLevel-1 during
3898 * abort, if there is a failure during transaction start before
3899 * AtStart_GUC is called.
3901 Assert(nestLevel > 0 &&
3902 (nestLevel <= GUCNestLevel ||
3903 (nestLevel == GUCNestLevel + 1 && !isCommit)));
3905 /* Quick exit if nothing's changed in this transaction */
3908 GUCNestLevel = nestLevel - 1;
3912 still_dirty = false;
3913 for (i = 0; i < num_guc_variables; i++)
3915 struct config_generic *gconf = guc_variables[i];
3919 * Process and pop each stack entry within the nest level. To
3920 * simplify fmgr_security_definer(), we allow failure exit from a
3921 * function-with-SET-options to be recovered at the surrounding
3922 * transaction or subtransaction abort; so there could be more than
3923 * one stack entry to pop.
3925 while ((stack = gconf->stack) != NULL &&
3926 stack->nest_level >= nestLevel)
3928 GucStack *prev = stack->prev;
3929 bool restorePrior = false;
3930 bool restoreMasked = false;
3934 * In this next bit, if we don't set either restorePrior or
3935 * restoreMasked, we must "discard" any unwanted fields of the
3936 * stack entries to avoid leaking memory. If we do set one of
3937 * those flags, unused fields will be cleaned up after restoring.
3939 if (!isCommit) /* if abort, always restore prior value */
3940 restorePrior = true;
3941 else if (stack->state == GUC_SAVE)
3942 restorePrior = true;
3943 else if (stack->nest_level == 1)
3945 /* transaction commit */
3946 if (stack->state == GUC_SET_LOCAL)
3947 restoreMasked = true;
3948 else if (stack->state == GUC_SET)
3950 /* we keep the current active value */
3951 discard_stack_value(gconf, &stack->prior);
3953 else /* must be GUC_LOCAL */
3954 restorePrior = true;
3956 else if (prev == NULL ||
3957 prev->nest_level < stack->nest_level - 1)
3959 /* decrement entry's level and do not pop it */
3960 stack->nest_level--;
3966 * We have to merge this stack entry into prev. See README for
3967 * discussion of this bit.
3969 switch (stack->state)
3972 Assert(false); /* can't get here */
3975 /* next level always becomes SET */
3976 discard_stack_value(gconf, &stack->prior);
3977 if (prev->state == GUC_SET_LOCAL)
3978 discard_stack_value(gconf, &prev->masked);
3979 prev->state = GUC_SET;
3983 if (prev->state == GUC_SET)
3985 /* LOCAL migrates down */
3986 prev->masked = stack->prior;
3987 prev->state = GUC_SET_LOCAL;
3991 /* else just forget this stack level */
3992 discard_stack_value(gconf, &stack->prior);
3997 /* prior state at this level no longer wanted */
3998 discard_stack_value(gconf, &stack->prior);
3999 /* copy down the masked state */
4000 if (prev->state == GUC_SET_LOCAL)
4001 discard_stack_value(gconf, &prev->masked);
4002 prev->masked = stack->masked;
4003 prev->state = GUC_SET_LOCAL;
4010 if (restorePrior || restoreMasked)
4012 /* Perform appropriate restoration of the stacked value */
4013 union config_var_value newvalue;
4014 GucSource newsource;
4018 newvalue = stack->masked;
4019 newsource = PGC_S_SESSION;
4023 newvalue = stack->prior;
4024 newsource = stack->source;
4027 switch (gconf->vartype)
4031 struct config_bool *conf = (struct config_bool *) gconf;
4032 bool newval = newvalue.boolval;
4034 if (*conf->variable != newval)
4036 if (conf->assign_hook)
4037 if (!(*conf->assign_hook) (newval,
4038 true, PGC_S_OVERRIDE))
4039 elog(LOG, "failed to commit %s as %d",
4040 conf->gen.name, (int) newval);
4041 *conf->variable = newval;
4048 struct config_int *conf = (struct config_int *) gconf;
4049 int newval = newvalue.intval;
4051 if (*conf->variable != newval)
4053 if (conf->assign_hook)
4054 if (!(*conf->assign_hook) (newval,
4055 true, PGC_S_OVERRIDE))
4056 elog(LOG, "failed to commit %s as %d",
4057 conf->gen.name, newval);
4058 *conf->variable = newval;
4065 struct config_real *conf = (struct config_real *) gconf;
4066 double newval = newvalue.realval;
4068 if (*conf->variable != newval)
4070 if (conf->assign_hook)
4071 if (!(*conf->assign_hook) (newval,
4072 true, PGC_S_OVERRIDE))
4073 elog(LOG, "failed to commit %s as %g",
4074 conf->gen.name, newval);
4075 *conf->variable = newval;
4082 struct config_string *conf = (struct config_string *) gconf;
4083 char *newval = newvalue.stringval;
4085 if (*conf->variable != newval)
4087 if (conf->assign_hook && newval)
4091 newstr = (*conf->assign_hook) (newval, true,
4094 elog(LOG, "failed to commit %s as \"%s\"",
4095 conf->gen.name, newval);
4096 else if (newstr != newval)
4099 * If newval should now be freed,
4100 * it'll be taken care of below.
4102 * See notes in set_config_option
4105 newval = (char *) newstr;
4109 set_string_field(conf, conf->variable, newval);
4114 * Release stacked values if not used anymore. We
4115 * could use discard_stack_value() here, but since
4116 * we have type-specific code anyway, might as
4119 set_string_field(conf, &stack->prior.stringval, NULL);
4120 set_string_field(conf, &stack->masked.stringval, NULL);
4125 struct config_enum *conf = (struct config_enum *) gconf;
4126 int newval = newvalue.enumval;
4128 if (*conf->variable != newval)
4130 if (conf->assign_hook)
4131 if (!(*conf->assign_hook) (newval,
4132 true, PGC_S_OVERRIDE))
4133 elog(LOG, "failed to commit %s as %s",
4135 config_enum_lookup_by_value(conf, newval));
4136 *conf->variable = newval;
4143 gconf->source = newsource;
4146 /* Finish popping the state stack */
4147 gconf->stack = prev;
4150 /* Report new value if we changed it */
4151 if (changed && (gconf->flags & GUC_REPORT))
4152 ReportGUCOption(gconf);
4153 } /* end of stack-popping loop */
4159 /* If there are no remaining stack entries, we can reset guc_dirty */
4160 guc_dirty = still_dirty;
4162 /* Update nesting level */
4163 GUCNestLevel = nestLevel - 1;
4168 * Start up automatic reporting of changes to variables marked GUC_REPORT.
4169 * This is executed at completion of backend startup.
4172 BeginReportingGUCOptions(void)
4177 * Don't do anything unless talking to an interactive frontend of protocol
4180 if (whereToSendOutput != DestRemote ||
4181 PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
4184 reporting_enabled = true;
4186 /* Transmit initial values of interesting variables */
4187 for (i = 0; i < num_guc_variables; i++)
4189 struct config_generic *conf = guc_variables[i];
4191 if (conf->flags & GUC_REPORT)
4192 ReportGUCOption(conf);
4197 * ReportGUCOption: if appropriate, transmit option value to frontend
4200 ReportGUCOption(struct config_generic * record)
4202 if (reporting_enabled && (record->flags & GUC_REPORT))
4204 char *val = _ShowOption(record, false);
4205 StringInfoData msgbuf;
4207 pq_beginmessage(&msgbuf, 'S');
4208 pq_sendstring(&msgbuf, record->name);
4209 pq_sendstring(&msgbuf, val);
4210 pq_endmessage(&msgbuf);
4217 * Try to parse value as an integer. The accepted formats are the
4218 * usual decimal, octal, or hexadecimal formats, optionally followed by
4219 * a unit name if "flags" indicates a unit is allowed.
4221 * If the string parses okay, return true, else false.
4222 * If okay and result is not NULL, return the value in *result.
4223 * If not okay and hintmsg is not NULL, *hintmsg is set to a suitable
4224 * HINT message, or NULL if no hint provided.
4227 parse_int(const char *value, int *result, int flags, const char **hintmsg)
4232 /* To suppress compiler warnings, always set output params */
4238 /* We assume here that int64 is at least as wide as long */
4240 val = strtol(value, &endptr, 0);
4242 if (endptr == value)
4243 return false; /* no HINT for integer syntax error */
4245 if (errno == ERANGE || val != (int64) ((int32) val))
4248 *hintmsg = gettext_noop("Value exceeds integer range.");
4252 /* allow whitespace between integer and unit */
4253 while (isspace((unsigned char) *endptr))
4256 /* Handle possible unit */
4257 if (*endptr != '\0')
4260 * Note: the multiple-switch coding technique here is a bit tedious,
4261 * but seems necessary to avoid intermediate-value overflows.
4263 if (flags & GUC_UNIT_MEMORY)
4265 /* Set hint for use if no match or trailing garbage */
4267 *hintmsg = gettext_noop("Valid units for this parameter are \"kB\", \"MB\", and \"GB\".");
4269 #if BLCKSZ < 1024 || BLCKSZ > (1024*1024)
4270 #error BLCKSZ must be between 1KB and 1MB
4272 #if XLOG_BLCKSZ < 1024 || XLOG_BLCKSZ > (1024*1024)
4273 #error XLOG_BLCKSZ must be between 1KB and 1MB
4276 if (strncmp(endptr, "kB", 2) == 0)
4279 switch (flags & GUC_UNIT_MEMORY)
4281 case GUC_UNIT_BLOCKS:
4282 val /= (BLCKSZ / 1024);
4284 case GUC_UNIT_XBLOCKS:
4285 val /= (XLOG_BLCKSZ / 1024);
4289 else if (strncmp(endptr, "MB", 2) == 0)
4292 switch (flags & GUC_UNIT_MEMORY)
4297 case GUC_UNIT_BLOCKS:
4298 val *= KB_PER_MB / (BLCKSZ / 1024);
4300 case GUC_UNIT_XBLOCKS:
4301 val *= KB_PER_MB / (XLOG_BLCKSZ / 1024);
4305 else if (strncmp(endptr, "GB", 2) == 0)
4308 switch (flags & GUC_UNIT_MEMORY)
4313 case GUC_UNIT_BLOCKS:
4314 val *= KB_PER_GB / (BLCKSZ / 1024);
4316 case GUC_UNIT_XBLOCKS:
4317 val *= KB_PER_GB / (XLOG_BLCKSZ / 1024);
4322 else if (flags & GUC_UNIT_TIME)
4324 /* Set hint for use if no match or trailing garbage */
4326 *hintmsg = gettext_noop("Valid units for this parameter are \"ms\", \"s\", \"min\", \"h\", and \"d\".");
4328 if (strncmp(endptr, "ms", 2) == 0)
4331 switch (flags & GUC_UNIT_TIME)
4341 else if (strncmp(endptr, "s", 1) == 0)
4344 switch (flags & GUC_UNIT_TIME)
4354 else if (strncmp(endptr, "min", 3) == 0)
4357 switch (flags & GUC_UNIT_TIME)
4367 else if (strncmp(endptr, "h", 1) == 0)
4370 switch (flags & GUC_UNIT_TIME)
4383 else if (strncmp(endptr, "d", 1) == 0)
4386 switch (flags & GUC_UNIT_TIME)
4401 /* allow whitespace after unit */
4402 while (isspace((unsigned char) *endptr))
4405 if (*endptr != '\0')
4406 return false; /* appropriate hint, if any, already set */
4408 /* Check for overflow due to units conversion */
4409 if (val != (int64) ((int32) val))
4412 *hintmsg = gettext_noop("Value exceeds integer range.");
4418 *result = (int) val;
4425 * Try to parse value as a floating point number in the usual format.
4426 * If the string parses okay, return true, else false.
4427 * If okay and result is not NULL, return the value in *result.
4430 parse_real(const char *value, double *result)
4436 *result = 0; /* suppress compiler warning */
4439 val = strtod(value, &endptr);
4440 if (endptr == value || errno == ERANGE)
4443 /* allow whitespace after number */
4444 while (isspace((unsigned char) *endptr))
4446 if (*endptr != '\0')
4456 * Lookup the name for an enum option with the selected value.
4457 * Should only ever be called with known-valid values, so throws
4458 * an elog(ERROR) if the enum option is not found.
4460 * The returned string is a pointer to static data and not
4461 * allocated for modification.
4464 config_enum_lookup_by_value(struct config_enum * record, int val)
4466 const struct config_enum_entry *entry;
4468 for (entry = record->options; entry && entry->name; entry++)
4470 if (entry->val == val)
4474 elog(ERROR, "could not find enum option %d for %s",
4475 val, record->gen.name);
4476 return NULL; /* silence compiler */
4481 * Lookup the value for an enum option with the selected name
4482 * (case-insensitive).
4483 * If the enum option is found, sets the retval value and returns
4484 * true. If it's not found, return FALSE and retval is set to 0.
4487 config_enum_lookup_by_name(struct config_enum * record, const char *value,
4490 const struct config_enum_entry *entry;
4492 for (entry = record->options; entry && entry->name; entry++)
4494 if (pg_strcasecmp(value, entry->name) == 0)
4496 *retval = entry->val;
4507 * Return a list of all available options for an enum, excluding
4508 * hidden ones, separated by the given separator.
4509 * If prefix is non-NULL, it is added before the first enum value.
4510 * If suffix is non-NULL, it is added to the end of the string.
4513 config_enum_get_options(struct config_enum * record, const char *prefix,
4514 const char *suffix, const char *separator)
4516 const struct config_enum_entry *entry;
4517 StringInfoData retstr;
4520 initStringInfo(&retstr);
4521 appendStringInfoString(&retstr, prefix);
4523 seplen = strlen(separator);
4524 for (entry = record->options; entry && entry->name; entry++)
4528 appendStringInfoString(&retstr, entry->name);
4529 appendBinaryStringInfo(&retstr, separator, seplen);
4534 * All the entries may have been hidden, leaving the string empty if no
4535 * prefix was given. This indicates a broken GUC setup, since there is no
4536 * use for an enum without any values, so we just check to make sure we
4537 * don't write to invalid memory instead of actually trying to do
4538 * something smart with it.
4540 if (retstr.len >= seplen)
4542 /* Replace final separator */
4543 retstr.data[retstr.len - seplen] = '\0';
4544 retstr.len -= seplen;
4547 appendStringInfoString(&retstr, suffix);
4553 * Call a GucStringAssignHook function, being careful to free the
4554 * "newval" string if the hook ereports.
4556 * This is split out of set_config_option just to avoid the "volatile"
4557 * qualifiers that would otherwise have to be plastered all over.
4560 call_string_assign_hook(GucStringAssignHook assign_hook,
4561 char *newval, bool doit, GucSource source)
4567 result = (*assign_hook) (newval, doit, source);
4581 * Sets option `name' to given value. The value should be a string
4582 * which is going to be parsed and converted to the appropriate data
4583 * type. The context and source parameters indicate in which context this
4584 * function is being called so it can apply the access restrictions
4587 * If value is NULL, set the option to its default value (normally the
4588 * reset_val, but if source == PGC_S_DEFAULT we instead use the boot_val).
4590 * action indicates whether to set the value globally in the session, locally
4591 * to the current top transaction, or just for the duration of a function call.
4593 * If changeVal is false then don't really set the option but do all
4594 * the checks to see if it would work.
4596 * If there is an error (non-existing option, invalid value) then an
4597 * ereport(ERROR) is thrown *unless* this is called in a context where we
4598 * don't want to ereport (currently, startup or SIGHUP config file reread).
4599 * In that case we write a suitable error message via ereport(LOG) and
4600 * return false. This is working around the deficiencies in the ereport
4601 * mechanism, so don't blame me. In all other cases, the function
4602 * returns true, including cases where the input is valid but we chose
4603 * not to apply it because of context or source-priority considerations.
4605 * See also SetConfigOption for an external interface.
4608 set_config_option(const char *name, const char *value,
4609 GucContext context, GucSource source,
4610 GucAction action, bool changeVal)
4612 struct config_generic *record;
4616 if (context == PGC_SIGHUP || source == PGC_S_DEFAULT)
4619 * To avoid cluttering the log, only the postmaster bleats loudly
4620 * about problems with the config file.
4622 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
4624 else if (source == PGC_S_DATABASE || source == PGC_S_USER ||
4625 source == PGC_S_DATABASE_USER)
4630 record = find_option(name, true, elevel);
4634 (errcode(ERRCODE_UNDEFINED_OBJECT),
4635 errmsg("unrecognized configuration parameter \"%s\"", name)));
4640 * If source is postgresql.conf, mark the found record with
4641 * GUC_IS_IN_FILE. This is for the convenience of ProcessConfigFile. Note
4642 * that we do it even if changeVal is false, since ProcessConfigFile wants
4643 * the marking to occur during its testing pass.
4645 if (source == PGC_S_FILE)
4646 record->status |= GUC_IS_IN_FILE;
4649 * Check if the option can be set at this time. See guc.h for the precise
4650 * rules. Note that we don't want to throw errors if we're in the SIGHUP
4651 * context. In that case we just ignore the attempt and return true.
4653 switch (record->context)
4656 if (context == PGC_SIGHUP)
4658 if (context != PGC_INTERNAL)
4661 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4662 errmsg("parameter \"%s\" cannot be changed",
4667 case PGC_POSTMASTER:
4668 if (context == PGC_SIGHUP)
4671 * We are reading a PGC_POSTMASTER var from postgresql.conf.
4672 * We can't change the setting, so give a warning if the DBA
4673 * tries to change it. (Throwing an error would be more
4674 * consistent, but seems overly rigid.)
4676 if (changeVal && !is_newvalue_equal(record, value))
4678 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4679 errmsg("parameter \"%s\" cannot be changed without restarting the server",
4683 if (context != PGC_POSTMASTER)
4686 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4687 errmsg("parameter \"%s\" cannot be changed without restarting the server",
4693 if (context != PGC_SIGHUP && context != PGC_POSTMASTER)
4696 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4697 errmsg("parameter \"%s\" cannot be changed now",
4703 * Hmm, the idea of the SIGHUP context is "ought to be global, but
4704 * can be changed after postmaster start". But there's nothing
4705 * that prevents a crafty administrator from sending SIGHUP
4706 * signals to individual backends only.
4710 if (context == PGC_SIGHUP)
4713 * If a PGC_BACKEND parameter is changed in the config file,
4714 * we want to accept the new value in the postmaster (whence
4715 * it will propagate to subsequently-started backends), but
4716 * ignore it in existing backends. This is a tad klugy, but
4717 * necessary because we don't re-read the config file during
4720 if (IsUnderPostmaster)
4723 else if (context != PGC_POSTMASTER && context != PGC_BACKEND &&
4724 source != PGC_S_CLIENT)
4727 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4728 errmsg("parameter \"%s\" cannot be set after connection start",
4734 if (context == PGC_USERSET || context == PGC_BACKEND)
4737 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4738 errmsg("permission denied to set parameter \"%s\"",
4749 * Disallow changing GUC_NOT_WHILE_SEC_REST values if we are inside a
4750 * security restriction context. We can reject this regardless of
4751 * the GUC context or source, mainly because sources that it might be
4752 * reasonable to override for won't be seen while inside a function.
4754 * Note: variables marked GUC_NOT_WHILE_SEC_REST should usually be marked
4755 * GUC_NO_RESET_ALL as well, because ResetAllOptions() doesn't check this.
4756 * An exception might be made if the reset value is assumed to be "safe".
4758 * Note: this flag is currently used for "session_authorization" and
4759 * "role". We need to prohibit changing these inside a local userid
4760 * context because when we exit it, GUC won't be notified, leaving things
4761 * out of sync. (This could be fixed by forcing a new GUC nesting level,
4762 * but that would change behavior in possibly-undesirable ways.) Also,
4763 * we prohibit changing these in a security-restricted operation because
4764 * otherwise RESET could be used to regain the session user's privileges.
4766 if (record->flags & GUC_NOT_WHILE_SEC_REST)
4768 if (InLocalUserIdChange())
4771 * Phrasing of this error message is historical, but it's the
4775 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4776 errmsg("cannot set parameter \"%s\" within security-definer function",
4780 if (InSecurityRestrictedOperation())
4783 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4784 errmsg("cannot set parameter \"%s\" within security-restricted operation",
4791 * Should we set reset/stacked values? (If so, the behavior is not
4792 * transactional.) This is done either when we get a default value from
4793 * the database's/user's/client's default settings or when we reset a
4794 * value to its default.
4796 makeDefault = changeVal && (source <= PGC_S_OVERRIDE) &&
4797 ((value != NULL) || source == PGC_S_DEFAULT);
4800 * Ignore attempted set if overridden by previously processed setting.
4801 * However, if changeVal is false then plow ahead anyway since we are
4802 * trying to find out if the value is potentially good, not actually use
4803 * it. Also keep going if makeDefault is true, since we may want to set
4804 * the reset/stacked values even if we can't set the variable itself.
4806 if (record->source > source)
4808 if (changeVal && !makeDefault)
4810 elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
4818 * Evaluate value and set variable.
4820 switch (record->vartype)
4824 struct config_bool *conf = (struct config_bool *) record;
4829 if (!parse_bool(value, &newval))
4832 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4833 errmsg("parameter \"%s\" requires a Boolean value",
4838 else if (source == PGC_S_DEFAULT)
4839 newval = conf->boot_val;
4842 newval = conf->reset_val;
4843 source = conf->gen.reset_source;
4846 /* Save old value to support transaction abort */
4847 if (changeVal && !makeDefault)
4848 push_old_value(&conf->gen, action);
4850 if (conf->assign_hook)
4851 if (!(*conf->assign_hook) (newval, changeVal, source))
4854 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4855 errmsg("invalid value for parameter \"%s\": %d",
4856 name, (int) newval)));
4862 *conf->variable = newval;
4863 conf->gen.source = source;
4869 if (conf->gen.reset_source <= source)
4871 conf->reset_val = newval;
4872 conf->gen.reset_source = source;
4874 for (stack = conf->gen.stack; stack; stack = stack->prev)
4876 if (stack->source <= source)
4878 stack->prior.boolval = newval;
4879 stack->source = source;
4888 struct config_int *conf = (struct config_int *) record;
4893 const char *hintmsg;
4895 if (!parse_int(value, &newval, conf->gen.flags, &hintmsg))
4898 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4899 errmsg("invalid value for parameter \"%s\": \"%s\"",
4901 hintmsg ? errhint("%s", _(hintmsg)) : 0));
4904 if (newval < conf->min || newval > conf->max)
4907 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4908 errmsg("%d is outside the valid range for parameter \"%s\" (%d .. %d)",
4909 newval, name, conf->min, conf->max)));
4913 else if (source == PGC_S_DEFAULT)
4914 newval = conf->boot_val;
4917 newval = conf->reset_val;
4918 source = conf->gen.reset_source;
4921 /* Save old value to support transaction abort */
4922 if (changeVal && !makeDefault)
4923 push_old_value(&conf->gen, action);
4925 if (conf->assign_hook)
4926 if (!(*conf->assign_hook) (newval, changeVal, source))
4929 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4930 errmsg("invalid value for parameter \"%s\": %d",
4937 *conf->variable = newval;
4938 conf->gen.source = source;
4944 if (conf->gen.reset_source <= source)
4946 conf->reset_val = newval;
4947 conf->gen.reset_source = source;
4949 for (stack = conf->gen.stack; stack; stack = stack->prev)
4951 if (stack->source <= source)
4953 stack->prior.intval = newval;
4954 stack->source = source;
4963 struct config_real *conf = (struct config_real *) record;
4968 if (!parse_real(value, &newval))
4971 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4972 errmsg("parameter \"%s\" requires a numeric value",
4976 if (newval < conf->min || newval > conf->max)
4979 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4980 errmsg("%g is outside the valid range for parameter \"%s\" (%g .. %g)",
4981 newval, name, conf->min, conf->max)));
4985 else if (source == PGC_S_DEFAULT)
4986 newval = conf->boot_val;
4989 newval = conf->reset_val;
4990 source = conf->gen.reset_source;
4993 /* Save old value to support transaction abort */
4994 if (changeVal && !makeDefault)
4995 push_old_value(&conf->gen, action);
4997 if (conf->assign_hook)
4998 if (!(*conf->assign_hook) (newval, changeVal, source))
5001 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5002 errmsg("invalid value for parameter \"%s\": %g",
5009 *conf->variable = newval;
5010 conf->gen.source = source;
5016 if (conf->gen.reset_source <= source)
5018 conf->reset_val = newval;
5019 conf->gen.reset_source = source;
5021 for (stack = conf->gen.stack; stack; stack = stack->prev)
5023 if (stack->source <= source)
5025 stack->prior.realval = newval;
5026 stack->source = source;
5035 struct config_string *conf = (struct config_string *) record;
5040 newval = guc_strdup(elevel, value);
5045 * The only sort of "parsing" check we need to do is apply
5046 * truncation if GUC_IS_NAME.
5048 if (conf->gen.flags & GUC_IS_NAME)
5049 truncate_identifier(newval, strlen(newval), true);
5051 else if (source == PGC_S_DEFAULT)
5053 if (conf->boot_val == NULL)
5057 newval = guc_strdup(elevel, conf->boot_val);
5065 * We could possibly avoid strdup here, but easier to make
5066 * this case work the same as the normal assignment case;
5067 * note the possible free of newval below.
5069 if (conf->reset_val == NULL)
5073 newval = guc_strdup(elevel, conf->reset_val);
5077 source = conf->gen.reset_source;
5080 /* Save old value to support transaction abort */
5081 if (changeVal && !makeDefault)
5082 push_old_value(&conf->gen, action);
5084 if (conf->assign_hook && newval)
5086 const char *hookresult;
5089 * If the hook ereports, we have to make sure we free
5090 * newval, else it will be a permanent memory leak.
5092 hookresult = call_string_assign_hook(conf->assign_hook,
5096 if (hookresult == NULL)
5100 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5101 errmsg("invalid value for parameter \"%s\": \"%s\"",
5102 name, value ? value : "")));
5105 else if (hookresult != newval)
5110 * Having to cast away const here is annoying, but the
5111 * alternative is to declare assign_hooks as returning
5112 * char*, which would mean they'd have to cast away
5113 * const, or as both taking and returning char*, which
5114 * doesn't seem attractive either --- we don't want
5115 * them to scribble on the passed str.
5117 newval = (char *) hookresult;
5123 set_string_field(conf, conf->variable, newval);
5124 conf->gen.source = source;
5130 if (conf->gen.reset_source <= source)
5132 set_string_field(conf, &conf->reset_val, newval);
5133 conf->gen.reset_source = source;
5135 for (stack = conf->gen.stack; stack; stack = stack->prev)
5137 if (stack->source <= source)
5139 set_string_field(conf, &stack->prior.stringval,
5141 stack->source = source;
5145 /* Perhaps we didn't install newval anywhere */
5146 if (newval && !string_field_used(conf, newval))
5152 struct config_enum *conf = (struct config_enum *) record;
5157 if (!config_enum_lookup_by_name(conf, value, &newval))
5161 hintmsg = config_enum_get_options(conf,
5162 "Available values: ",
5166 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5167 errmsg("invalid value for parameter \"%s\": \"%s\"",
5169 hintmsg ? errhint("%s", _(hintmsg)) : 0));
5176 else if (source == PGC_S_DEFAULT)
5177 newval = conf->boot_val;
5180 newval = conf->reset_val;
5181 source = conf->gen.reset_source;
5184 /* Save old value to support transaction abort */
5185 if (changeVal && !makeDefault)
5186 push_old_value(&conf->gen, action);
5188 if (conf->assign_hook)
5189 if (!(*conf->assign_hook) (newval, changeVal, source))
5192 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5193 errmsg("invalid value for parameter \"%s\": \"%s\"",
5195 config_enum_lookup_by_value(conf, newval))));
5201 *conf->variable = newval;
5202 conf->gen.source = source;
5208 if (conf->gen.reset_source <= source)
5210 conf->reset_val = newval;
5211 conf->gen.reset_source = source;
5213 for (stack = conf->gen.stack; stack; stack = stack->prev)
5215 if (stack->source <= source)
5217 stack->prior.enumval = newval;
5218 stack->source = source;
5226 if (changeVal && (record->flags & GUC_REPORT))
5227 ReportGUCOption(record);
5234 * Set the fields for source file and line number the setting came from.
5237 set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
5239 struct config_generic *record;
5243 * To avoid cluttering the log, only the postmaster bleats loudly about
5244 * problems with the config file.
5246 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
5248 record = find_option(name, true, elevel);
5249 /* should not happen */
5251 elog(ERROR, "unrecognized configuration parameter \"%s\"", name);
5253 sourcefile = guc_strdup(elevel, sourcefile);
5254 if (record->sourcefile)
5255 free(record->sourcefile);
5256 record->sourcefile = sourcefile;
5257 record->sourceline = sourceline;
5261 * Set a config option to the given value. See also set_config_option,
5262 * this is just the wrapper to be called from outside GUC. NB: this
5263 * is used only for non-transactional operations.
5265 * Note: there is no support here for setting source file/line, as it
5266 * is currently not needed.
5269 SetConfigOption(const char *name, const char *value,
5270 GucContext context, GucSource source)
5272 (void) set_config_option(name, value, context, source,
5273 GUC_ACTION_SET, true);
5279 * Fetch the current value of the option `name'. If the option doesn't exist,
5280 * throw an ereport and don't return.
5282 * If restrict_superuser is true, we also enforce that only superusers can
5283 * see GUC_SUPERUSER_ONLY variables. This should only be passed as true
5284 * in user-driven calls.
5286 * The string is *not* allocated for modification and is really only
5287 * valid until the next call to configuration related functions.
5290 GetConfigOption(const char *name, bool restrict_superuser)
5292 struct config_generic *record;
5293 static char buffer[256];
5295 record = find_option(name, false, ERROR);
5298 (errcode(ERRCODE_UNDEFINED_OBJECT),
5299 errmsg("unrecognized configuration parameter \"%s\"", name)));
5300 if (restrict_superuser &&
5301 (record->flags & GUC_SUPERUSER_ONLY) &&
5304 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5305 errmsg("must be superuser to examine \"%s\"", name)));
5307 switch (record->vartype)
5310 return *((struct config_bool *) record)->variable ? "on" : "off";
5313 snprintf(buffer, sizeof(buffer), "%d",
5314 *((struct config_int *) record)->variable);
5318 snprintf(buffer, sizeof(buffer), "%g",
5319 *((struct config_real *) record)->variable);
5323 return *((struct config_string *) record)->variable;
5326 return config_enum_lookup_by_value((struct config_enum *) record,
5327 *((struct config_enum *) record)->variable);
5333 * Get the RESET value associated with the given option.
5335 * Note: this is not re-entrant, due to use of static result buffer;
5336 * not to mention that a string variable could have its reset_val changed.
5337 * Beware of assuming the result value is good for very long.
5340 GetConfigOptionResetString(const char *name)
5342 struct config_generic *record;
5343 static char buffer[256];
5345 record = find_option(name, false, ERROR);
5348 (errcode(ERRCODE_UNDEFINED_OBJECT),
5349 errmsg("unrecognized configuration parameter \"%s\"", name)));
5350 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
5352 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5353 errmsg("must be superuser to examine \"%s\"", name)));
5355 switch (record->vartype)
5358 return ((struct config_bool *) record)->reset_val ? "on" : "off";
5361 snprintf(buffer, sizeof(buffer), "%d",
5362 ((struct config_int *) record)->reset_val);
5366 snprintf(buffer, sizeof(buffer), "%g",
5367 ((struct config_real *) record)->reset_val);
5371 return ((struct config_string *) record)->reset_val;
5374 return config_enum_lookup_by_value((struct config_enum *) record,
5375 ((struct config_enum *) record)->reset_val);
5382 * GUC_complaint_elevel
5383 * Get the ereport error level to use in an assign_hook's error report.
5385 * This should be used by assign hooks that want to emit a custom error
5386 * report (in addition to the generic "invalid value for option FOO" that
5387 * guc.c will provide). Note that the result might be ERROR or a lower
5388 * level, so the caller must be prepared for control to return from ereport,
5389 * or not. If control does return, return false/NULL from the hook function.
5391 * At some point it'd be nice to replace this with a mechanism that allows
5392 * the custom message to become the DETAIL line of guc.c's generic message.
5395 GUC_complaint_elevel(GucSource source)
5399 if (source == PGC_S_FILE)
5402 * To avoid cluttering the log, only the postmaster bleats loudly
5403 * about problems with the config file.
5405 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
5407 else if (source == PGC_S_OVERRIDE)
5410 * If we're a postmaster child, this is probably "undo" during
5411 * transaction abort, so we don't want to clutter the log. There's a
5412 * small chance of a real problem with an OVERRIDE setting, though, so
5413 * suppressing the message entirely wouldn't be desirable.
5415 elevel = IsUnderPostmaster ? DEBUG5 : LOG;
5417 else if (source < PGC_S_INTERACTIVE)
5427 * flatten_set_variable_args
5428 * Given a parsenode List as emitted by the grammar for SET,
5429 * convert to the flat string representation used by GUC.
5431 * We need to be told the name of the variable the args are for, because
5432 * the flattening rules vary (ugh).
5434 * The result is NULL if args is NIL (ie, SET ... TO DEFAULT), otherwise
5435 * a palloc'd string.
5438 flatten_set_variable_args(const char *name, List *args)
5440 struct config_generic *record;
5445 /* Fast path if just DEFAULT */
5449 /* Else get flags for the variable */
5450 record = find_option(name, true, ERROR);
5453 (errcode(ERRCODE_UNDEFINED_OBJECT),
5454 errmsg("unrecognized configuration parameter \"%s\"", name)));
5456 flags = record->flags;
5458 /* Complain if list input and non-list variable */
5459 if ((flags & GUC_LIST_INPUT) == 0 &&
5460 list_length(args) != 1)
5462 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5463 errmsg("SET %s takes only one argument", name)));
5465 initStringInfo(&buf);
5468 * Each list member may be a plain A_Const node, or an A_Const within a
5469 * TypeCast; the latter case is supported only for ConstInterval arguments
5470 * (for SET TIME ZONE).
5474 Node *arg = (Node *) lfirst(l);
5476 TypeName *typeName = NULL;
5479 if (l != list_head(args))
5480 appendStringInfo(&buf, ", ");
5482 if (IsA(arg, TypeCast))
5484 TypeCast *tc = (TypeCast *) arg;
5487 typeName = tc->typeName;
5490 if (!IsA(arg, A_Const))
5491 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
5492 con = (A_Const *) arg;
5494 switch (nodeTag(&con->val))
5497 appendStringInfo(&buf, "%ld", intVal(&con->val));
5500 /* represented as a string, so just copy it */
5501 appendStringInfoString(&buf, strVal(&con->val));
5504 val = strVal(&con->val);
5505 if (typeName != NULL)
5508 * Must be a ConstInterval argument for TIME ZONE. Coerce
5509 * to interval and back to normalize the value and account
5517 typoid = typenameTypeId(NULL, typeName, &typmod);
5518 Assert(typoid == INTERVALOID);
5521 DirectFunctionCall3(interval_in,
5522 CStringGetDatum(val),
5523 ObjectIdGetDatum(InvalidOid),
5524 Int32GetDatum(typmod));
5527 DatumGetCString(DirectFunctionCall1(interval_out,
5529 appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
5534 * Plain string literal or identifier. For quote mode,
5535 * quote it if it's not a vanilla identifier.
5537 if (flags & GUC_LIST_QUOTE)
5538 appendStringInfoString(&buf, quote_identifier(val));
5540 appendStringInfoString(&buf, val);
5544 elog(ERROR, "unrecognized node type: %d",
5545 (int) nodeTag(&con->val));
5558 ExecSetVariableStmt(VariableSetStmt *stmt)
5560 GucAction action = stmt->is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET;
5565 case VAR_SET_CURRENT:
5566 set_config_option(stmt->name,
5567 ExtractSetVariableArgs(stmt),
5568 (superuser() ? PGC_SUSET : PGC_USERSET),
5576 * Special case for special SQL syntax that effectively sets more
5577 * than one variable per statement.
5579 if (strcmp(stmt->name, "TRANSACTION") == 0)
5583 foreach(head, stmt->args)
5585 DefElem *item = (DefElem *) lfirst(head);
5587 if (strcmp(item->defname, "transaction_isolation") == 0)
5588 SetPGVariable("transaction_isolation",
5589 list_make1(item->arg), stmt->is_local);
5590 else if (strcmp(item->defname, "transaction_read_only") == 0)
5591 SetPGVariable("transaction_read_only",
5592 list_make1(item->arg), stmt->is_local);
5594 elog(ERROR, "unexpected SET TRANSACTION element: %s",
5598 else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
5602 foreach(head, stmt->args)
5604 DefElem *item = (DefElem *) lfirst(head);
5606 if (strcmp(item->defname, "transaction_isolation") == 0)
5607 SetPGVariable("default_transaction_isolation",
5608 list_make1(item->arg), stmt->is_local);
5609 else if (strcmp(item->defname, "transaction_read_only") == 0)
5610 SetPGVariable("default_transaction_read_only",
5611 list_make1(item->arg), stmt->is_local);
5613 elog(ERROR, "unexpected SET SESSION element: %s",
5618 elog(ERROR, "unexpected SET MULTI element: %s",
5621 case VAR_SET_DEFAULT:
5623 set_config_option(stmt->name,
5625 (superuser() ? PGC_SUSET : PGC_USERSET),
5637 * Get the value to assign for a VariableSetStmt, or NULL if it's RESET.
5638 * The result is palloc'd.
5640 * This is exported for use by actions such as ALTER ROLE SET.
5643 ExtractSetVariableArgs(VariableSetStmt *stmt)
5648 return flatten_set_variable_args(stmt->name, stmt->args);
5649 case VAR_SET_CURRENT:
5650 return GetConfigOptionByName(stmt->name, NULL);
5657 * SetPGVariable - SET command exported as an easily-C-callable function.
5659 * This provides access to SET TO value, as well as SET TO DEFAULT (expressed
5660 * by passing args == NIL), but not SET FROM CURRENT functionality.
5663 SetPGVariable(const char *name, List *args, bool is_local)
5665 char *argstring = flatten_set_variable_args(name, args);
5667 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
5668 set_config_option(name,
5670 (superuser() ? PGC_SUSET : PGC_USERSET),
5672 is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET,
5677 * SET command wrapped as a SQL callable function.
5680 set_config_by_name(PG_FUNCTION_ARGS)
5687 if (PG_ARGISNULL(0))
5689 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
5690 errmsg("SET requires parameter name")));
5692 /* Get the GUC variable name */
5693 name = TextDatumGetCString(PG_GETARG_DATUM(0));
5695 /* Get the desired value or set to NULL for a reset request */
5696 if (PG_ARGISNULL(1))
5699 value = TextDatumGetCString(PG_GETARG_DATUM(1));
5702 * Get the desired state of is_local. Default to false if provided value
5705 if (PG_ARGISNULL(2))
5708 is_local = PG_GETARG_BOOL(2);
5710 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
5711 set_config_option(name,
5713 (superuser() ? PGC_SUSET : PGC_USERSET),
5715 is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET,
5718 /* get the new current value */
5719 new_value = GetConfigOptionByName(name, NULL);
5721 /* Convert return string to text */
5722 PG_RETURN_TEXT_P(cstring_to_text(new_value));
5727 * Common code for DefineCustomXXXVariable subroutines: allocate the
5728 * new variable's config struct and fill in generic fields.
5730 static struct config_generic *
5731 init_custom_variable(const char *name,
5732 const char *short_desc,
5733 const char *long_desc,
5736 enum config_type type,
5739 struct config_generic *gen;
5742 * Only allow custom PGC_POSTMASTER variables to be created during shared
5743 * library preload; any later than that, we can't ensure that the value
5744 * doesn't change after startup. This is a fatal elog if it happens; just
5745 * erroring out isn't safe because we don't know what the calling loadable
5746 * module might already have hooked into.
5748 if (context == PGC_POSTMASTER &&
5749 !process_shared_preload_libraries_in_progress)
5750 elog(FATAL, "cannot create PGC_POSTMASTER variables after startup");
5752 gen = (struct config_generic *) guc_malloc(ERROR, sz);
5755 gen->name = guc_strdup(ERROR, name);
5756 gen->context = context;
5757 gen->group = CUSTOM_OPTIONS;
5758 gen->short_desc = short_desc;
5759 gen->long_desc = long_desc;
5761 gen->vartype = type;
5767 * Common code for DefineCustomXXXVariable subroutines: insert the new
5768 * variable into the GUC variable array, replacing any placeholder.
5771 define_custom_variable(struct config_generic * variable)
5773 const char *name = variable->name;
5774 const char **nameAddr = &name;
5776 struct config_string *pHolder;
5777 GucContext phcontext;
5778 struct config_generic **res;
5781 * See if there's a placeholder by the same name.
5783 res = (struct config_generic **) bsearch((void *) &nameAddr,
5784 (void *) guc_variables,
5786 sizeof(struct config_generic *),
5791 * No placeholder to replace, so we can just add it ... but first,
5792 * make sure it's initialized to its default value.
5794 InitializeOneGUCOption(variable);
5795 add_guc_variable(variable, ERROR);
5800 * This better be a placeholder
5802 if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
5804 (errcode(ERRCODE_INTERNAL_ERROR),
5805 errmsg("attempt to redefine parameter \"%s\"", name)));
5807 Assert((*res)->vartype == PGC_STRING);
5808 pHolder = (struct config_string *) (*res);
5811 * First, set the variable to its default value. We must do this even
5812 * though we intend to immediately apply a new value, since it's possible
5813 * that the new value is invalid.
5815 InitializeOneGUCOption(variable);
5818 * Replace the placeholder. We aren't changing the name, so no re-sorting
5824 * Infer context for assignment based on source of existing value. We
5825 * can't tell this with exact accuracy, but we can at least do something
5826 * reasonable in typical cases.
5828 switch (pHolder->gen.source)
5836 * If we got past the check in init_custom_variable, we can safely
5837 * assume that any existing value for a PGC_POSTMASTER variable
5838 * was set in postmaster context.
5840 if (variable->context == PGC_POSTMASTER)
5841 phcontext = PGC_POSTMASTER;
5843 phcontext = PGC_SIGHUP;
5845 case PGC_S_DATABASE:
5847 case PGC_S_DATABASE_USER:
5851 phcontext = PGC_USERSET;
5856 * Assign the string value stored in the placeholder to the real variable.
5858 * XXX this is not really good enough --- it should be a nontransactional
5859 * assignment, since we don't want it to roll back if the current xact
5860 * fails later. (Or do we?)
5862 value = *pHolder->variable;
5866 if (set_config_option(name, value,
5867 phcontext, pHolder->gen.source,
5868 GUC_ACTION_SET, true))
5870 /* Also copy over any saved source-location information */
5871 if (pHolder->gen.sourcefile)
5872 set_config_sourcefile(name, pHolder->gen.sourcefile,
5873 pHolder->gen.sourceline);
5878 * Free up as much as we conveniently can of the placeholder structure
5879 * (this neglects any stack items...)
5881 set_string_field(pHolder, pHolder->variable, NULL);
5882 set_string_field(pHolder, &pHolder->reset_val, NULL);
5888 DefineCustomBoolVariable(const char *name,
5889 const char *short_desc,
5890 const char *long_desc,
5895 GucBoolAssignHook assign_hook,
5896 GucShowHook show_hook)
5898 struct config_bool *var;
5900 var = (struct config_bool *)
5901 init_custom_variable(name, short_desc, long_desc, context, flags,
5902 PGC_BOOL, sizeof(struct config_bool));
5903 var->variable = valueAddr;
5904 var->boot_val = bootValue;
5905 var->reset_val = bootValue;
5906 var->assign_hook = assign_hook;
5907 var->show_hook = show_hook;
5908 define_custom_variable(&var->gen);
5912 DefineCustomIntVariable(const char *name,
5913 const char *short_desc,
5914 const char *long_desc,
5921 GucIntAssignHook assign_hook,
5922 GucShowHook show_hook)
5924 struct config_int *var;
5926 var = (struct config_int *)
5927 init_custom_variable(name, short_desc, long_desc, context, flags,
5928 PGC_INT, sizeof(struct config_int));
5929 var->variable = valueAddr;
5930 var->boot_val = bootValue;
5931 var->reset_val = bootValue;
5932 var->min = minValue;
5933 var->max = maxValue;
5934 var->assign_hook = assign_hook;
5935 var->show_hook = show_hook;
5936 define_custom_variable(&var->gen);
5940 DefineCustomRealVariable(const char *name,
5941 const char *short_desc,
5942 const char *long_desc,
5949 GucRealAssignHook assign_hook,
5950 GucShowHook show_hook)
5952 struct config_real *var;
5954 var = (struct config_real *)
5955 init_custom_variable(name, short_desc, long_desc, context, flags,
5956 PGC_REAL, sizeof(struct config_real));
5957 var->variable = valueAddr;
5958 var->boot_val = bootValue;
5959 var->reset_val = bootValue;
5960 var->min = minValue;
5961 var->max = maxValue;
5962 var->assign_hook = assign_hook;
5963 var->show_hook = show_hook;
5964 define_custom_variable(&var->gen);
5968 DefineCustomStringVariable(const char *name,
5969 const char *short_desc,
5970 const char *long_desc,
5972 const char *bootValue,
5975 GucStringAssignHook assign_hook,
5976 GucShowHook show_hook)
5978 struct config_string *var;
5980 var = (struct config_string *)
5981 init_custom_variable(name, short_desc, long_desc, context, flags,
5982 PGC_STRING, sizeof(struct config_string));
5983 var->variable = valueAddr;
5984 var->boot_val = bootValue;
5985 /* we could probably do without strdup, but keep it like normal case */
5987 var->reset_val = guc_strdup(ERROR, var->boot_val);
5988 var->assign_hook = assign_hook;
5989 var->show_hook = show_hook;
5990 define_custom_variable(&var->gen);
5994 DefineCustomEnumVariable(const char *name,
5995 const char *short_desc,
5996 const char *long_desc,
5999 const struct config_enum_entry * options,
6002 GucEnumAssignHook assign_hook,
6003 GucShowHook show_hook)
6005 struct config_enum *var;
6007 var = (struct config_enum *)
6008 init_custom_variable(name, short_desc, long_desc, context, flags,
6009 PGC_ENUM, sizeof(struct config_enum));
6010 var->variable = valueAddr;
6011 var->boot_val = bootValue;
6012 var->reset_val = bootValue;
6013 var->options = options;
6014 var->assign_hook = assign_hook;
6015 var->show_hook = show_hook;
6016 define_custom_variable(&var->gen);
6020 EmitWarningsOnPlaceholders(const char *className)
6022 int classLen = strlen(className);
6025 for (i = 0; i < num_guc_variables; i++)
6027 struct config_generic *var = guc_variables[i];
6029 if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
6030 strncmp(className, var->name, classLen) == 0 &&
6031 var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
6034 (errcode(ERRCODE_UNDEFINED_OBJECT),
6035 errmsg("unrecognized configuration parameter \"%s\"",
6046 GetPGVariable(const char *name, DestReceiver *dest)
6048 if (guc_name_compare(name, "all") == 0)
6049 ShowAllGUCConfig(dest);
6051 ShowGUCConfigOption(name, dest);
6055 GetPGVariableResultDesc(const char *name)
6059 if (guc_name_compare(name, "all") == 0)
6061 /* need a tuple descriptor representing three TEXT columns */
6062 tupdesc = CreateTemplateTupleDesc(3, false);
6063 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
6065 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
6067 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
6072 const char *varname;
6074 /* Get the canonical spelling of name */
6075 (void) GetConfigOptionByName(name, &varname);
6077 /* need a tuple descriptor representing a single TEXT column */
6078 tupdesc = CreateTemplateTupleDesc(1, false);
6079 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
6090 ShowGUCConfigOption(const char *name, DestReceiver *dest)
6092 TupOutputState *tstate;
6094 const char *varname;
6097 /* Get the value and canonical spelling of name */
6098 value = GetConfigOptionByName(name, &varname);
6100 /* need a tuple descriptor representing a single TEXT column */
6101 tupdesc = CreateTemplateTupleDesc(1, false);
6102 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
6105 /* prepare for projection of tuples */
6106 tstate = begin_tup_output_tupdesc(dest, tupdesc);
6109 do_text_output_oneline(tstate, value);
6111 end_tup_output(tstate);
6118 ShowAllGUCConfig(DestReceiver *dest)
6120 bool am_superuser = superuser();
6122 TupOutputState *tstate;
6125 bool isnull[3] = { false, false, false };
6127 /* need a tuple descriptor representing three TEXT columns */
6128 tupdesc = CreateTemplateTupleDesc(3, false);
6129 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
6131 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
6133 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
6136 /* prepare for projection of tuples */
6137 tstate = begin_tup_output_tupdesc(dest, tupdesc);
6139 for (i = 0; i < num_guc_variables; i++)
6141 struct config_generic *conf = guc_variables[i];
6144 if ((conf->flags & GUC_NO_SHOW_ALL) ||
6145 ((conf->flags & GUC_SUPERUSER_ONLY) && !am_superuser))
6148 /* assign to the values array */
6149 values[0] = PointerGetDatum(cstring_to_text(conf->name));
6151 setting = _ShowOption(conf, true);
6154 values[1] = PointerGetDatum(cstring_to_text(setting));
6159 values[1] = PointerGetDatum(NULL);
6163 values[2] = PointerGetDatum(cstring_to_text(conf->short_desc));
6165 /* send it to dest */
6166 do_tup_output(tstate, values, isnull);
6169 pfree(DatumGetPointer(values[0]));
6173 pfree(DatumGetPointer(values[1]));
6175 pfree(DatumGetPointer(values[2]));
6178 end_tup_output(tstate);
6182 * Return GUC variable value by name; optionally return canonical
6183 * form of name. Return value is palloc'd.
6186 GetConfigOptionByName(const char *name, const char **varname)
6188 struct config_generic *record;
6190 record = find_option(name, false, ERROR);
6193 (errcode(ERRCODE_UNDEFINED_OBJECT),
6194 errmsg("unrecognized configuration parameter \"%s\"", name)));
6195 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
6197 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6198 errmsg("must be superuser to examine \"%s\"", name)));
6201 *varname = record->name;
6203 return _ShowOption(record, true);
6207 * Return GUC variable value by variable number; optionally return canonical
6208 * form of name. Return value is palloc'd.
6211 GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
6214 struct config_generic *conf;
6216 /* check requested variable number valid */
6217 Assert((varnum >= 0) && (varnum < num_guc_variables));
6219 conf = guc_variables[varnum];
6223 if ((conf->flags & GUC_NO_SHOW_ALL) ||
6224 ((conf->flags & GUC_SUPERUSER_ONLY) && !superuser()))
6230 /* first get the generic attributes */
6233 values[0] = conf->name;
6235 /* setting : use _ShowOption in order to avoid duplicating the logic */
6236 values[1] = _ShowOption(conf, false);
6239 if (conf->vartype == PGC_INT)
6243 switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
6248 case GUC_UNIT_BLOCKS:
6249 snprintf(buf, sizeof(buf), "%dkB", BLCKSZ / 1024);
6252 case GUC_UNIT_XBLOCKS:
6253 snprintf(buf, sizeof(buf), "%dkB", XLOG_BLCKSZ / 1024);
6274 values[3] = config_group_names[conf->group];
6277 values[4] = conf->short_desc;
6280 values[5] = conf->long_desc;
6283 values[6] = GucContext_Names[conf->context];
6286 values[7] = config_type_names[conf->vartype];
6289 values[8] = GucSource_Names[conf->source];
6291 /* now get the type specifc attributes */
6292 switch (conf->vartype)
6296 struct config_bool *lconf = (struct config_bool *) conf;
6308 values[12] = pstrdup(lconf->boot_val ? "on" : "off");
6311 values[13] = pstrdup(lconf->reset_val ? "on" : "off");
6317 struct config_int *lconf = (struct config_int *) conf;
6320 snprintf(buffer, sizeof(buffer), "%d", lconf->min);
6321 values[9] = pstrdup(buffer);
6324 snprintf(buffer, sizeof(buffer), "%d", lconf->max);
6325 values[10] = pstrdup(buffer);
6331 snprintf(buffer, sizeof(buffer), "%d", lconf->boot_val);
6332 values[12] = pstrdup(buffer);
6335 snprintf(buffer, sizeof(buffer), "%d", lconf->reset_val);
6336 values[13] = pstrdup(buffer);
6342 struct config_real *lconf = (struct config_real *) conf;
6345 snprintf(buffer, sizeof(buffer), "%g", lconf->min);
6346 values[9] = pstrdup(buffer);
6349 snprintf(buffer, sizeof(buffer), "%g", lconf->max);
6350 values[10] = pstrdup(buffer);
6356 snprintf(buffer, sizeof(buffer), "%g", lconf->boot_val);
6357 values[12] = pstrdup(buffer);
6360 snprintf(buffer, sizeof(buffer), "%g", lconf->reset_val);
6361 values[13] = pstrdup(buffer);
6367 struct config_string *lconf = (struct config_string *) conf;
6379 if (lconf->boot_val == NULL)
6382 values[12] = pstrdup(lconf->boot_val);
6385 if (lconf->reset_val == NULL)
6388 values[13] = pstrdup(lconf->reset_val);
6394 struct config_enum *lconf = (struct config_enum *) conf;
6405 * NOTE! enumvals with double quotes in them are not
6408 values[11] = config_enum_get_options((struct config_enum *) conf,
6409 "{\"", "\"}", "\",\"");
6412 values[12] = pstrdup(config_enum_lookup_by_value(lconf,
6416 values[13] = pstrdup(config_enum_lookup_by_value(lconf,
6424 * should never get here, but in case we do, set 'em to NULL
6446 * If the setting came from a config file, set the source location. For
6447 * security reasons, we don't show source file/line number for
6450 if (conf->source == PGC_S_FILE && superuser())
6452 values[14] = conf->sourcefile;
6453 snprintf(buffer, sizeof(buffer), "%d", conf->sourceline);
6454 values[15] = pstrdup(buffer);
6464 * Return the total number of GUC variables
6467 GetNumConfigOptions(void)
6469 return num_guc_variables;
6473 * show_config_by_name - equiv to SHOW X command but implemented as
6477 show_config_by_name(PG_FUNCTION_ARGS)
6482 /* Get the GUC variable name */
6483 varname = TextDatumGetCString(PG_GETARG_DATUM(0));
6486 varval = GetConfigOptionByName(varname, NULL);
6488 /* Convert to text */
6489 PG_RETURN_TEXT_P(cstring_to_text(varval));
6493 * show_all_settings - equiv to SHOW ALL command but implemented as
6496 #define NUM_PG_SETTINGS_ATTS 16
6499 show_all_settings(PG_FUNCTION_ARGS)
6501 FuncCallContext *funcctx;
6505 AttInMetadata *attinmeta;
6506 MemoryContext oldcontext;
6508 /* stuff done only on the first call of the function */
6509 if (SRF_IS_FIRSTCALL())
6511 /* create a function context for cross-call persistence */
6512 funcctx = SRF_FIRSTCALL_INIT();
6515 * switch to memory context appropriate for multiple function calls
6517 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
6520 * need a tuple descriptor representing NUM_PG_SETTINGS_ATTS columns
6521 * of the appropriate types
6523 tupdesc = CreateTemplateTupleDesc(NUM_PG_SETTINGS_ATTS, false);
6524 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
6526 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
6528 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "unit",
6530 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "category",
6532 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "short_desc",
6534 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "extra_desc",
6536 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "context",
6538 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "vartype",
6540 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "source",
6542 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "min_val",
6544 TupleDescInitEntry(tupdesc, (AttrNumber) 11, "max_val",
6546 TupleDescInitEntry(tupdesc, (AttrNumber) 12, "enumvals",
6547 TEXTARRAYOID, -1, 0);
6548 TupleDescInitEntry(tupdesc, (AttrNumber) 13, "boot_val",
6550 TupleDescInitEntry(tupdesc, (AttrNumber) 14, "reset_val",
6552 TupleDescInitEntry(tupdesc, (AttrNumber) 15, "sourcefile",
6554 TupleDescInitEntry(tupdesc, (AttrNumber) 16, "sourceline",
6558 * Generate attribute metadata needed later to produce tuples from raw
6561 attinmeta = TupleDescGetAttInMetadata(tupdesc);
6562 funcctx->attinmeta = attinmeta;
6564 /* total number of tuples to be returned */
6565 funcctx->max_calls = GetNumConfigOptions();
6567 MemoryContextSwitchTo(oldcontext);
6570 /* stuff done on every call of the function */
6571 funcctx = SRF_PERCALL_SETUP();
6573 call_cntr = funcctx->call_cntr;
6574 max_calls = funcctx->max_calls;
6575 attinmeta = funcctx->attinmeta;
6577 if (call_cntr < max_calls) /* do when there is more left to send */
6579 char *values[NUM_PG_SETTINGS_ATTS];
6585 * Get the next visible GUC variable name and value
6589 GetConfigOptionByNum(call_cntr, (const char **) values, &noshow);
6592 /* bump the counter and get the next config setting */
6593 call_cntr = ++funcctx->call_cntr;
6595 /* make sure we haven't gone too far now */
6596 if (call_cntr >= max_calls)
6597 SRF_RETURN_DONE(funcctx);
6602 tuple = BuildTupleFromCStrings(attinmeta, values);
6604 /* make the tuple into a datum */
6605 result = HeapTupleGetDatum(tuple);
6607 SRF_RETURN_NEXT(funcctx, result);
6611 /* do when there is no more left */
6612 SRF_RETURN_DONE(funcctx);
6617 _ShowOption(struct config_generic * record, bool use_units)
6622 switch (record->vartype)
6626 struct config_bool *conf = (struct config_bool *) record;
6628 if (conf->show_hook)
6629 val = (*conf->show_hook) ();
6631 val = *conf->variable ? "on" : "off";
6637 struct config_int *conf = (struct config_int *) record;
6639 if (conf->show_hook)
6640 val = (*conf->show_hook) ();
6644 * Use int64 arithmetic to avoid overflows in units
6647 int64 result = *conf->variable;
6650 if (use_units && result > 0 &&
6651 (record->flags & GUC_UNIT_MEMORY))
6653 switch (record->flags & GUC_UNIT_MEMORY)
6655 case GUC_UNIT_BLOCKS:
6656 result *= BLCKSZ / 1024;
6658 case GUC_UNIT_XBLOCKS:
6659 result *= XLOG_BLCKSZ / 1024;
6663 if (result % KB_PER_GB == 0)
6665 result /= KB_PER_GB;
6668 else if (result % KB_PER_MB == 0)
6670 result /= KB_PER_MB;
6678 else if (use_units && result > 0 &&
6679 (record->flags & GUC_UNIT_TIME))
6681 switch (record->flags & GUC_UNIT_TIME)
6687 result *= MS_PER_MIN;
6691 if (result % MS_PER_D == 0)
6696 else if (result % MS_PER_H == 0)
6701 else if (result % MS_PER_MIN == 0)
6703 result /= MS_PER_MIN;
6706 else if (result % MS_PER_S == 0)
6719 snprintf(buffer, sizeof(buffer), INT64_FORMAT "%s",
6728 struct config_real *conf = (struct config_real *) record;
6730 if (conf->show_hook)
6731 val = (*conf->show_hook) ();
6734 snprintf(buffer, sizeof(buffer), "%g",
6743 struct config_string *conf = (struct config_string *) record;
6745 if (conf->show_hook)
6746 val = (*conf->show_hook) ();
6747 else if (*conf->variable && **conf->variable)
6748 val = *conf->variable;
6756 struct config_enum *conf = (struct config_enum *) record;
6758 if (conf->show_hook)
6759 val = (*conf->show_hook) ();
6761 val = config_enum_lookup_by_value(conf, *conf->variable);
6766 /* just to keep compiler quiet */
6771 return pstrdup(val);
6776 * Attempt (badly) to detect if a proposed new GUC setting is the same
6777 * as the current value.
6779 * XXX this does not really work because it doesn't account for the
6780 * effects of canonicalization of string values by assign_hooks.
6783 is_newvalue_equal(struct config_generic * record, const char *newvalue)
6785 /* newvalue == NULL isn't supported */
6786 Assert(newvalue != NULL);
6788 switch (record->vartype)
6792 struct config_bool *conf = (struct config_bool *) record;
6795 return parse_bool(newvalue, &newval)
6796 && *conf->variable == newval;
6800 struct config_int *conf = (struct config_int *) record;
6803 return parse_int(newvalue, &newval, record->flags, NULL)
6804 && *conf->variable == newval;
6808 struct config_real *conf = (struct config_real *) record;
6811 return parse_real(newvalue, &newval)
6812 && *conf->variable == newval;
6816 struct config_string *conf = (struct config_string *) record;
6818 return *conf->variable != NULL &&
6819 strcmp(*conf->variable, newvalue) == 0;
6824 struct config_enum *conf = (struct config_enum *) record;
6827 return config_enum_lookup_by_name(conf, newvalue, &newval) &&
6828 *conf->variable == newval;
6839 * These routines dump out all non-default GUC options into a binary
6840 * file that is read by all exec'ed backends. The format is:
6842 * variable name, string, null terminated
6843 * variable value, string, null terminated
6844 * variable source, integer
6847 write_one_nondefault_variable(FILE *fp, struct config_generic * gconf)
6849 if (gconf->source == PGC_S_DEFAULT)
6852 fprintf(fp, "%s", gconf->name);
6855 switch (gconf->vartype)
6859 struct config_bool *conf = (struct config_bool *) gconf;
6861 if (*conf->variable)
6862 fprintf(fp, "true");
6864 fprintf(fp, "false");
6870 struct config_int *conf = (struct config_int *) gconf;
6872 fprintf(fp, "%d", *conf->variable);
6878 struct config_real *conf = (struct config_real *) gconf;
6880 /* Could lose precision here? */
6881 fprintf(fp, "%f", *conf->variable);
6887 struct config_string *conf = (struct config_string *) gconf;
6889 fprintf(fp, "%s", *conf->variable);
6895 struct config_enum *conf = (struct config_enum *) gconf;
6898 config_enum_lookup_by_value(conf, *conf->variable));
6905 fwrite(&gconf->source, sizeof(gconf->source), 1, fp);
6909 write_nondefault_variables(GucContext context)
6913 struct config_generic *cvc_conf;
6916 Assert(context == PGC_POSTMASTER || context == PGC_SIGHUP);
6918 elevel = (context == PGC_SIGHUP) ? LOG : ERROR;
6923 fp = AllocateFile(CONFIG_EXEC_PARAMS_NEW, "w");
6927 (errcode_for_file_access(),
6928 errmsg("could not write to file \"%s\": %m",
6929 CONFIG_EXEC_PARAMS_NEW)));
6934 * custom_variable_classes must be written out first; otherwise we might
6935 * reject custom variable values while reading the file.
6937 cvc_conf = find_option("custom_variable_classes", false, ERROR);
6939 write_one_nondefault_variable(fp, cvc_conf);
6941 for (i = 0; i < num_guc_variables; i++)
6943 struct config_generic *gconf = guc_variables[i];
6945 if (gconf != cvc_conf)
6946 write_one_nondefault_variable(fp, gconf);
6952 (errcode_for_file_access(),
6953 errmsg("could not write to file \"%s\": %m",
6954 CONFIG_EXEC_PARAMS_NEW)));
6959 * Put new file in place. This could delay on Win32, but we don't hold
6960 * any exclusive locks.
6962 rename(CONFIG_EXEC_PARAMS_NEW, CONFIG_EXEC_PARAMS);
6967 * Read string, including null byte from file
6969 * Return NULL on EOF and nothing read
6972 read_string_with_null(FILE *fp)
6981 if ((ch = fgetc(fp)) == EOF)
6986 elog(FATAL, "invalid format of exec config params file");
6989 str = guc_malloc(FATAL, maxlen);
6990 else if (i == maxlen)
6991 str = guc_realloc(FATAL, str, maxlen *= 2);
7000 * This routine loads a previous postmaster dump of its non-default
7004 read_nondefault_variables(void)
7014 fp = AllocateFile(CONFIG_EXEC_PARAMS, "r");
7017 /* File not found is fine */
7018 if (errno != ENOENT)
7020 (errcode_for_file_access(),
7021 errmsg("could not read from file \"%s\": %m",
7022 CONFIG_EXEC_PARAMS)));
7028 struct config_generic *record;
7030 if ((varname = read_string_with_null(fp)) == NULL)
7033 if ((record = find_option(varname, true, FATAL)) == NULL)
7034 elog(FATAL, "failed to locate variable %s in exec config params file", varname);
7035 if ((varvalue = read_string_with_null(fp)) == NULL)
7036 elog(FATAL, "invalid format of exec config params file");
7037 if (fread(&varsource, sizeof(varsource), 1, fp) == 0)
7038 elog(FATAL, "invalid format of exec config params file");
7040 (void) set_config_option(varname, varvalue, record->context,
7041 varsource, GUC_ACTION_SET, true);
7048 #endif /* EXEC_BACKEND */
7052 * A little "long argument" simulation, although not quite GNU
7053 * compliant. Takes a string of the form "some-option=some value" and
7054 * returns name = "some_option" and value = "some value" in malloc'ed
7055 * storage. Note that '-' is converted to '_' in the option name. If
7056 * there is no '=' in the input string then value will be NULL.
7059 ParseLongOption(const char *string, char **name, char **value)
7068 equal_pos = strcspn(string, "=");
7070 if (string[equal_pos] == '=')
7072 *name = guc_malloc(FATAL, equal_pos + 1);
7073 strlcpy(*name, string, equal_pos + 1);
7075 *value = guc_strdup(FATAL, &string[equal_pos + 1]);
7079 /* no equal sign in string */
7080 *name = guc_strdup(FATAL, string);
7084 for (cp = *name; *cp; cp++)
7091 * Handle options fetched from pg_database.datconfig, pg_authid.rolconfig,
7092 * pg_proc.proconfig, etc. Caller must specify proper context/source/action.
7094 * The array parameter must be an array of TEXT (it must not be NULL).
7097 ProcessGUCArray(ArrayType *array,
7098 GucContext context, GucSource source, GucAction action)
7102 Assert(array != NULL);
7103 Assert(ARR_ELEMTYPE(array) == TEXTOID);
7104 Assert(ARR_NDIM(array) == 1);
7105 Assert(ARR_LBOUND(array)[0] == 1);
7107 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
7115 d = array_ref(array, 1, &i,
7116 -1 /* varlenarray */ ,
7117 -1 /* TEXT's typlen */ ,
7118 false /* TEXT's typbyval */ ,
7119 'i' /* TEXT's typalign */ ,
7125 s = TextDatumGetCString(d);
7127 ParseLongOption(s, &name, &value);
7131 (errcode(ERRCODE_SYNTAX_ERROR),
7132 errmsg("could not parse setting for parameter \"%s\"",
7138 (void) set_config_option(name, value, context, source, action, true);
7148 * Add an entry to an option array. The array parameter may be NULL
7149 * to indicate the current table entry is NULL.
7152 GUCArrayAdd(ArrayType *array, const char *name, const char *value)
7154 const char *varname;
7162 /* test if the option is valid */
7163 set_config_option(name, value,
7164 superuser() ? PGC_SUSET : PGC_USERSET,
7165 PGC_S_TEST, GUC_ACTION_SET, false);
7167 /* convert name to canonical spelling, so we can use plain strcmp */
7168 (void) GetConfigOptionByName(name, &varname);
7171 newval = palloc(strlen(name) + 1 + strlen(value) + 1);
7172 sprintf(newval, "%s=%s", name, value);
7173 datum = CStringGetTextDatum(newval);
7181 Assert(ARR_ELEMTYPE(array) == TEXTOID);
7182 Assert(ARR_NDIM(array) == 1);
7183 Assert(ARR_LBOUND(array)[0] == 1);
7185 index = ARR_DIMS(array)[0] + 1; /* add after end */
7187 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
7192 d = array_ref(array, 1, &i,
7193 -1 /* varlenarray */ ,
7194 -1 /* TEXT's typlen */ ,
7195 false /* TEXT's typbyval */ ,
7196 'i' /* TEXT's typalign */ ,
7200 current = TextDatumGetCString(d);
7201 if (strncmp(current, newval, strlen(name) + 1) == 0)
7208 a = array_set(array, 1, &index,
7211 -1 /* varlena array */ ,
7212 -1 /* TEXT's typlen */ ,
7213 false /* TEXT's typbyval */ ,
7214 'i' /* TEXT's typalign */ );
7217 a = construct_array(&datum, 1,
7226 * Delete an entry from an option array. The array parameter may be NULL
7227 * to indicate the current table entry is NULL. Also, if the return value
7228 * is NULL then a null should be stored.
7231 GUCArrayDelete(ArrayType *array, const char *name)
7233 const char *varname;
7234 ArrayType *newarray;
7240 /* test if the option is valid */
7241 set_config_option(name, NULL,
7242 superuser() ? PGC_SUSET : PGC_USERSET,
7243 PGC_S_TEST, GUC_ACTION_SET, false);
7245 /* convert name to canonical spelling, so we can use plain strcmp */
7246 (void) GetConfigOptionByName(name, &varname);
7249 /* if array is currently null, then surely nothing to delete */
7256 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
7262 d = array_ref(array, 1, &i,
7263 -1 /* varlenarray */ ,
7264 -1 /* TEXT's typlen */ ,
7265 false /* TEXT's typbyval */ ,
7266 'i' /* TEXT's typalign */ ,
7270 val = TextDatumGetCString(d);
7272 /* ignore entry if it's what we want to delete */
7273 if (strncmp(val, name, strlen(name)) == 0
7274 && val[strlen(name)] == '=')
7277 /* else add it to the output array */
7280 newarray = array_set(newarray, 1, &index,
7283 -1 /* varlenarray */ ,
7284 -1 /* TEXT's typlen */ ,
7285 false /* TEXT's typbyval */ ,
7286 'i' /* TEXT's typalign */ );
7289 newarray = construct_array(&d, 1,
7301 * assign_hook and show_hook subroutines
7305 assign_log_destination(const char *value, bool doit, GucSource source)
7312 /* Need a modifiable copy of string */
7313 rawstring = pstrdup(value);
7315 /* Parse string into list of identifiers */
7316 if (!SplitIdentifierString(rawstring, ',', &elemlist))
7318 /* syntax error in list */
7320 list_free(elemlist);
7321 ereport(GUC_complaint_elevel(source),
7322 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7323 errmsg("invalid list syntax for parameter \"log_destination\"")));
7327 foreach(l, elemlist)
7329 char *tok = (char *) lfirst(l);
7331 if (pg_strcasecmp(tok, "stderr") == 0)
7332 newlogdest |= LOG_DESTINATION_STDERR;
7333 else if (pg_strcasecmp(tok, "csvlog") == 0)
7334 newlogdest |= LOG_DESTINATION_CSVLOG;
7336 else if (pg_strcasecmp(tok, "syslog") == 0)
7337 newlogdest |= LOG_DESTINATION_SYSLOG;
7340 else if (pg_strcasecmp(tok, "eventlog") == 0)
7341 newlogdest |= LOG_DESTINATION_EVENTLOG;
7345 ereport(GUC_complaint_elevel(source),
7346 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7347 errmsg("unrecognized \"log_destination\" key word: \"%s\"",
7350 list_free(elemlist);
7356 Log_destination = newlogdest;
7359 list_free(elemlist);
7367 assign_syslog_facility(int newval, bool doit, GucSource source)
7370 set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
7377 assign_syslog_ident(const char *ident, bool doit, GucSource source)
7380 set_syslog_parameters(ident, syslog_facility);
7384 #endif /* HAVE_SYSLOG */
7388 assign_session_replication_role(int newval, bool doit, GucSource source)
7391 * Must flush the plan cache when changing replication role; but don't
7392 * flush unnecessarily.
7394 if (doit && SessionReplicationRole != newval)
7403 show_num_temp_buffers(void)
7406 * We show the GUC var until local buffers have been initialized, and
7407 * NLocBuffer afterwards.
7409 static char nbuf[32];
7411 sprintf(nbuf, "%d", NLocBuffer ? NLocBuffer : num_temp_buffers);
7416 assign_phony_autocommit(bool newval, bool doit, GucSource source)
7420 ereport(GUC_complaint_elevel(source),
7421 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7422 errmsg("SET AUTOCOMMIT TO OFF is no longer supported")));
7429 assign_custom_variable_classes(const char *newval, bool doit, GucSource source)
7432 * Check syntax. newval must be a comma separated list of identifiers.
7433 * Whitespace is allowed but removed from the result.
7435 bool hasSpaceAfterToken = false;
7436 const char *cp = newval;
7441 initStringInfo(&buf);
7442 while ((c = *cp++) != '\0')
7444 if (isspace((unsigned char) c))
7447 hasSpaceAfterToken = true;
7453 if (symLen > 0) /* terminate identifier */
7455 appendStringInfoChar(&buf, ',');
7458 hasSpaceAfterToken = false;
7462 if (hasSpaceAfterToken || !(isalnum((unsigned char) c) || c == '_'))
7465 * Syntax error due to token following space after token or
7466 * non-identifier character
7471 appendStringInfoChar(&buf, c);
7475 /* Remove stray ',' at end */
7476 if (symLen == 0 && buf.len > 0)
7477 buf.data[--buf.len] = '\0';
7479 /* GUC wants the result malloc'd */
7480 newval = guc_strdup(LOG, buf.data);
7487 assign_debug_assertions(bool newval, bool doit, GucSource source)
7489 #ifndef USE_ASSERT_CHECKING
7492 ereport(GUC_complaint_elevel(source),
7493 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7494 errmsg("assertion checking is not supported by this build")));
7502 assign_bonjour(bool newval, bool doit, GucSource source)
7507 ereport(GUC_complaint_elevel(source),
7508 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7509 errmsg("Bonjour is not supported by this build")));
7517 assign_ssl(bool newval, bool doit, GucSource source)
7522 ereport(GUC_complaint_elevel(source),
7523 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7524 errmsg("SSL is not supported by this build")));
7532 assign_stage_log_stats(bool newval, bool doit, GucSource source)
7534 if (newval && log_statement_stats)
7536 ereport(GUC_complaint_elevel(source),
7537 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7538 errmsg("cannot enable parameter when \"log_statement_stats\" is true")));
7539 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
7540 if (source != PGC_S_OVERRIDE)
7547 assign_log_stats(bool newval, bool doit, GucSource source)
7550 (log_parser_stats || log_planner_stats || log_executor_stats))
7552 ereport(GUC_complaint_elevel(source),
7553 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7554 errmsg("cannot enable \"log_statement_stats\" when "
7555 "\"log_parser_stats\", \"log_planner_stats\", "
7556 "or \"log_executor_stats\" is true")));
7557 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
7558 if (source != PGC_S_OVERRIDE)
7565 assign_transaction_read_only(bool newval, bool doit, GucSource source)
7567 /* Can't go to r/w mode inside a r/o transaction */
7568 if (newval == false && XactReadOnly && IsSubTransaction())
7570 ereport(GUC_complaint_elevel(source),
7571 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7572 errmsg("cannot set transaction read-write mode inside a read-only transaction")));
7573 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
7574 if (source != PGC_S_OVERRIDE)
7578 /* Can't go to r/w mode while recovery is still active */
7579 if (newval == false && XactReadOnly && RecoveryInProgress())
7581 ereport(GUC_complaint_elevel(source),
7582 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7583 errmsg("cannot set transaction read-write mode during recovery")));
7584 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
7585 if (source != PGC_S_OVERRIDE)
7593 assign_canonical_path(const char *newval, bool doit, GucSource source)
7597 char *canon_val = guc_strdup(ERROR, newval);
7599 canonicalize_path(canon_val);
7607 assign_timezone_abbreviations(const char *newval, bool doit, GucSource source)
7610 * The powerup value shown above for timezone_abbreviations is "UNKNOWN".
7611 * When we see this we just do nothing. If this value isn't overridden
7612 * from the config file then pg_timezone_abbrev_initialize() will
7613 * eventually replace it with "Default". This hack has two purposes: to
7614 * avoid wasting cycles loading values that might soon be overridden from
7615 * the config file, and to avoid trying to read the timezone abbrev files
7616 * during InitializeGUCOptions(). The latter doesn't work in an
7617 * EXEC_BACKEND subprocess because my_exec_path hasn't been set yet and so
7618 * we can't locate PGSHAREDIR. (Essentially the same hack is used to
7619 * delay initializing TimeZone ... if we have any more, we should try to
7620 * clean up and centralize this mechanism ...)
7622 if (strcmp(newval, "UNKNOWN") == 0)
7627 /* Loading abbrev file is expensive, so only do it when value changes */
7628 if (timezone_abbreviations_string == NULL ||
7629 strcmp(timezone_abbreviations_string, newval) != 0)
7634 * If reading config file, only the postmaster should bleat loudly
7635 * about problems. Otherwise, it's just this one process doing it,
7636 * and we use WARNING message level.
7638 if (source == PGC_S_FILE)
7639 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
7642 if (!load_tzoffsets(newval, doit, elevel))
7649 * pg_timezone_abbrev_initialize --- set default value if not done already
7651 * This is called after initial loading of postgresql.conf. If no
7652 * timezone_abbreviations setting was found therein, select default.
7655 pg_timezone_abbrev_initialize(void)
7657 if (strcmp(timezone_abbreviations_string, "UNKNOWN") == 0)
7659 SetConfigOption("timezone_abbreviations", "Default",
7660 PGC_POSTMASTER, PGC_S_ARGV);
7665 show_archive_command(void)
7667 if (XLogArchiveMode)
7668 return XLogArchiveCommand;
7670 return "(disabled)";
7674 assign_tcp_keepalives_idle(int newval, bool doit, GucSource source)
7677 return (pq_setkeepalivesidle(newval, MyProcPort) == STATUS_OK);
7683 show_tcp_keepalives_idle(void)
7685 static char nbuf[16];
7687 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesidle(MyProcPort));
7692 assign_tcp_keepalives_interval(int newval, bool doit, GucSource source)
7695 return (pq_setkeepalivesinterval(newval, MyProcPort) == STATUS_OK);
7701 show_tcp_keepalives_interval(void)
7703 static char nbuf[16];
7705 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesinterval(MyProcPort));
7710 assign_tcp_keepalives_count(int newval, bool doit, GucSource source)
7713 return (pq_setkeepalivescount(newval, MyProcPort) == STATUS_OK);
7719 show_tcp_keepalives_count(void)
7721 static char nbuf[16];
7723 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivescount(MyProcPort));
7728 assign_maxconnections(int newval, bool doit, GucSource source)
7730 if (newval + autovacuum_max_workers + 1 > INT_MAX / 4)
7734 MaxBackends = newval + autovacuum_max_workers + 1;
7740 assign_autovacuum_max_workers(int newval, bool doit, GucSource source)
7742 if (MaxConnections + newval + 1 > INT_MAX / 4)
7746 MaxBackends = MaxConnections + newval + 1;
7752 assign_effective_io_concurrency(int newval, bool doit, GucSource source)
7755 double new_prefetch_pages = 0.0;
7759 * The user-visible GUC parameter is the number of drives (spindles),
7760 * which we need to translate to a number-of-pages-to-prefetch target.
7762 * The expected number of prefetch pages needed to keep N drives busy is:
7764 * drives | I/O requests
7765 * -------+----------------
7768 * 3 | 3/1 + 3/2 + 3/3 = 5 1/2
7769 * 4 | 4/1 + 4/2 + 4/3 + 4/4 = 8 1/3
7772 * This is called the "coupon collector problem" and H(n) is called the
7773 * harmonic series. This could be approximated by n * ln(n), but for
7774 * reasonable numbers of drives we might as well just compute the series.
7776 * Alternatively we could set the target to the number of pages necessary
7777 * so that the expected number of active spindles is some arbitrary
7778 * percentage of the total. This sounds the same but is actually slightly
7779 * different. The result ends up being ln(1-P)/ln((n-1)/n) where P is
7780 * that desired fraction.
7782 * Experimental results show that both of these formulas aren't aggressive
7783 * enough, but we don't really have any better proposals.
7785 * Note that if newval = 0 (disabled), we must set target = 0.
7789 for (i = 1; i <= newval; i++)
7790 new_prefetch_pages += (double) newval / (double) i;
7792 /* This range check shouldn't fail, but let's be paranoid */
7793 if (new_prefetch_pages >= 0.0 && new_prefetch_pages < (double) INT_MAX)
7796 target_prefetch_pages = (int) rint(new_prefetch_pages);
7803 #endif /* USE_PREFETCH */
7807 assign_pgstat_temp_directory(const char *newval, bool doit, GucSource source)
7811 char *canon_val = guc_strdup(ERROR, newval);
7815 canonicalize_path(canon_val);
7817 tname = guc_malloc(ERROR, strlen(canon_val) + 12); /* /pgstat.tmp */
7818 sprintf(tname, "%s/pgstat.tmp", canon_val);
7819 fname = guc_malloc(ERROR, strlen(canon_val) + 13); /* /pgstat.stat */
7820 sprintf(fname, "%s/pgstat.stat", canon_val);
7822 if (pgstat_stat_tmpname)
7823 free(pgstat_stat_tmpname);
7824 pgstat_stat_tmpname = tname;
7825 if (pgstat_stat_filename)
7826 free(pgstat_stat_filename);
7827 pgstat_stat_filename = fname;
7836 assign_application_name(const char *newval, bool doit, GucSource source)
7840 /* Only allow clean ASCII chars in the application name */
7841 char *repval = guc_strdup(ERROR, newval);
7844 for (p = repval; *p; p++)
7846 if (*p < 32 || *p > 126)
7850 /* Update the pg_stat_activity view */
7851 pgstat_report_appname(repval);
7859 #include "guc-file.c"