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.549 2010/04/20 11:15:06 rhaas 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;
120 extern int ssl_renegotiation_limit;
122 int trace_recovery_messages = LOG;
125 extern bool trace_sort;
127 #ifdef TRACE_SYNCSCAN
128 extern bool trace_syncscan;
130 #ifdef DEBUG_BOUNDED_SORT
131 extern bool optimize_bounded_sort;
135 extern char *SSLCipherSuites;
138 static void set_config_sourcefile(const char *name, char *sourcefile,
141 static const char *assign_log_destination(const char *value,
142 bool doit, GucSource source);
145 static int syslog_facility = LOG_LOCAL0;
147 static bool assign_syslog_facility(int newval,
148 bool doit, GucSource source);
149 static const char *assign_syslog_ident(const char *ident,
150 bool doit, GucSource source);
153 static bool assign_session_replication_role(int newval, bool doit,
155 static const char *show_num_temp_buffers(void);
156 static bool assign_phony_autocommit(bool newval, bool doit, GucSource source);
157 static const char *assign_custom_variable_classes(const char *newval, bool doit,
159 static bool assign_debug_assertions(bool newval, bool doit, GucSource source);
160 static bool assign_bonjour(bool newval, bool doit, GucSource source);
161 static bool assign_ssl(bool newval, bool doit, GucSource source);
162 static bool assign_stage_log_stats(bool newval, bool doit, GucSource source);
163 static bool assign_log_stats(bool newval, bool doit, GucSource source);
164 static bool assign_transaction_read_only(bool newval, bool doit, GucSource source);
165 static const char *assign_canonical_path(const char *newval, bool doit, GucSource source);
166 static const char *assign_timezone_abbreviations(const char *newval, bool doit, GucSource source);
167 static const char *show_archive_command(void);
168 static bool assign_tcp_keepalives_idle(int newval, bool doit, GucSource source);
169 static bool assign_tcp_keepalives_interval(int newval, bool doit, GucSource source);
170 static bool assign_tcp_keepalives_count(int newval, bool doit, GucSource source);
171 static const char *show_tcp_keepalives_idle(void);
172 static const char *show_tcp_keepalives_interval(void);
173 static const char *show_tcp_keepalives_count(void);
174 static bool assign_maxconnections(int newval, bool doit, GucSource source);
175 static bool assign_autovacuum_max_workers(int newval, bool doit, GucSource source);
176 static bool assign_effective_io_concurrency(int newval, bool doit, GucSource source);
177 static const char *assign_pgstat_temp_directory(const char *newval, bool doit, GucSource source);
178 static const char *assign_application_name(const char *newval, bool doit, GucSource source);
180 static char *config_enum_get_options(struct config_enum * record,
181 const char *prefix, const char *suffix,
182 const char *separator);
186 * Options for enum values defined in this module.
188 * NOTE! Option values may not contain double quotes!
191 static const struct config_enum_entry bytea_output_options[] = {
192 {"escape", BYTEA_OUTPUT_ESCAPE, false},
193 {"hex", BYTEA_OUTPUT_HEX, false},
198 * We have different sets for client and server message level options because
199 * they sort slightly different (see "log" level)
201 static const struct config_enum_entry client_message_level_options[] = {
202 {"debug", DEBUG2, true},
203 {"debug5", DEBUG5, false},
204 {"debug4", DEBUG4, false},
205 {"debug3", DEBUG3, false},
206 {"debug2", DEBUG2, false},
207 {"debug1", DEBUG1, false},
209 {"info", INFO, true},
210 {"notice", NOTICE, false},
211 {"warning", WARNING, false},
212 {"error", ERROR, false},
213 {"fatal", FATAL, true},
214 {"panic", PANIC, true},
218 static const struct config_enum_entry server_message_level_options[] = {
219 {"debug", DEBUG2, true},
220 {"debug5", DEBUG5, false},
221 {"debug4", DEBUG4, false},
222 {"debug3", DEBUG3, false},
223 {"debug2", DEBUG2, false},
224 {"debug1", DEBUG1, false},
225 {"info", INFO, false},
226 {"notice", NOTICE, false},
227 {"warning", WARNING, false},
228 {"error", ERROR, false},
230 {"fatal", FATAL, false},
231 {"panic", PANIC, false},
235 static const struct config_enum_entry intervalstyle_options[] = {
236 {"postgres", INTSTYLE_POSTGRES, false},
237 {"postgres_verbose", INTSTYLE_POSTGRES_VERBOSE, false},
238 {"sql_standard", INTSTYLE_SQL_STANDARD, false},
239 {"iso_8601", INTSTYLE_ISO_8601, false},
243 static const struct config_enum_entry log_error_verbosity_options[] = {
244 {"terse", PGERROR_TERSE, false},
245 {"default", PGERROR_DEFAULT, false},
246 {"verbose", PGERROR_VERBOSE, false},
250 static const struct config_enum_entry log_statement_options[] = {
251 {"none", LOGSTMT_NONE, false},
252 {"ddl", LOGSTMT_DDL, false},
253 {"mod", LOGSTMT_MOD, false},
254 {"all", LOGSTMT_ALL, false},
258 static const struct config_enum_entry isolation_level_options[] = {
259 {"serializable", XACT_SERIALIZABLE, false},
260 {"repeatable read", XACT_REPEATABLE_READ, false},
261 {"read committed", XACT_READ_COMMITTED, false},
262 {"read uncommitted", XACT_READ_UNCOMMITTED, false},
266 static const struct config_enum_entry session_replication_role_options[] = {
267 {"origin", SESSION_REPLICATION_ROLE_ORIGIN, false},
268 {"replica", SESSION_REPLICATION_ROLE_REPLICA, false},
269 {"local", SESSION_REPLICATION_ROLE_LOCAL, false},
274 static const struct config_enum_entry syslog_facility_options[] = {
275 {"local0", LOG_LOCAL0, false},
276 {"local1", LOG_LOCAL1, false},
277 {"local2", LOG_LOCAL2, false},
278 {"local3", LOG_LOCAL3, false},
279 {"local4", LOG_LOCAL4, false},
280 {"local5", LOG_LOCAL5, false},
281 {"local6", LOG_LOCAL6, false},
282 {"local7", LOG_LOCAL7, false},
287 static const struct config_enum_entry track_function_options[] = {
288 {"none", TRACK_FUNC_OFF, false},
289 {"pl", TRACK_FUNC_PL, false},
290 {"all", TRACK_FUNC_ALL, false},
294 static const struct config_enum_entry xmlbinary_options[] = {
295 {"base64", XMLBINARY_BASE64, false},
296 {"hex", XMLBINARY_HEX, false},
300 static const struct config_enum_entry xmloption_options[] = {
301 {"content", XMLOPTION_CONTENT, false},
302 {"document", XMLOPTION_DOCUMENT, false},
307 * Although only "on", "off", and "safe_encoding" are documented, we
308 * accept all the likely variants of "on" and "off".
310 static const struct config_enum_entry backslash_quote_options[] = {
311 {"safe_encoding", BACKSLASH_QUOTE_SAFE_ENCODING, false},
312 {"on", BACKSLASH_QUOTE_ON, false},
313 {"off", BACKSLASH_QUOTE_OFF, false},
314 {"true", BACKSLASH_QUOTE_ON, true},
315 {"false", BACKSLASH_QUOTE_OFF, true},
316 {"yes", BACKSLASH_QUOTE_ON, true},
317 {"no", BACKSLASH_QUOTE_OFF, true},
318 {"1", BACKSLASH_QUOTE_ON, true},
319 {"0", BACKSLASH_QUOTE_OFF, true},
324 * Although only "on", "off", and "partition" are documented, we
325 * accept all the likely variants of "on" and "off".
327 static const struct config_enum_entry constraint_exclusion_options[] = {
328 {"partition", CONSTRAINT_EXCLUSION_PARTITION, false},
329 {"on", CONSTRAINT_EXCLUSION_ON, false},
330 {"off", CONSTRAINT_EXCLUSION_OFF, false},
331 {"true", CONSTRAINT_EXCLUSION_ON, true},
332 {"false", CONSTRAINT_EXCLUSION_OFF, true},
333 {"yes", CONSTRAINT_EXCLUSION_ON, true},
334 {"no", CONSTRAINT_EXCLUSION_OFF, true},
335 {"1", CONSTRAINT_EXCLUSION_ON, true},
336 {"0", CONSTRAINT_EXCLUSION_OFF, true},
341 * Options for enum values stored in other modules
343 extern const struct config_enum_entry sync_method_options[];
346 * GUC option variables that are exported from this module
348 #ifdef USE_ASSERT_CHECKING
349 bool assert_enabled = true;
351 bool assert_enabled = false;
353 bool log_duration = false;
354 bool Debug_print_plan = false;
355 bool Debug_print_parse = false;
356 bool Debug_print_rewritten = false;
357 bool Debug_pretty_print = true;
359 bool log_parser_stats = false;
360 bool log_planner_stats = false;
361 bool log_executor_stats = false;
362 bool log_statement_stats = false; /* this is sort of all three
364 bool log_btree_build_stats = false;
366 bool check_function_bodies = true;
367 bool default_with_oids = false;
368 bool SQL_inheritance = true;
370 bool Password_encryption = true;
372 int log_min_error_statement = ERROR;
373 int log_min_messages = WARNING;
374 int client_min_messages = NOTICE;
375 int log_min_duration_statement = -1;
376 int log_temp_files = -1;
378 int num_temp_buffers = 1000;
380 char *ConfigFileName;
383 char *external_pid_file;
385 char *pgstat_temp_directory;
387 char *application_name;
389 int tcp_keepalives_idle;
390 int tcp_keepalives_interval;
391 int tcp_keepalives_count;
394 * These variables are all dummies that don't do anything, except in some
395 * cases provide the value for SHOW to display. The real state is elsewhere
396 * and is kept in sync by assign_hooks.
398 static char *log_destination_string;
401 static char *syslog_ident_str;
403 static bool phony_autocommit;
404 static bool session_auth_is_superuser;
405 static double phony_random_seed;
406 static char *client_encoding_string;
407 static char *datestyle_string;
408 static char *locale_collate;
409 static char *locale_ctype;
410 static char *server_encoding_string;
411 static char *server_version_string;
412 static int server_version_num;
413 static char *timezone_string;
414 static char *log_timezone_string;
415 static char *timezone_abbreviations_string;
416 static char *XactIsoLevel_string;
417 static char *data_directory;
418 static char *custom_variable_classes;
419 static int max_function_args;
420 static int max_index_keys;
421 static int max_identifier_length;
422 static int block_size;
423 static int segment_size;
424 static int wal_block_size;
425 static int wal_segment_size;
426 static bool integer_datetimes;
427 static int effective_io_concurrency;
429 /* should be static, but commands/variable.c needs to get at these */
431 char *session_authorization_string;
435 * Displayable names for context types (enum GucContext)
437 * Note: these strings are deliberately not localized.
439 const char *const GucContext_Names[] =
441 /* PGC_INTERNAL */ "internal",
442 /* PGC_POSTMASTER */ "postmaster",
443 /* PGC_SIGHUP */ "sighup",
444 /* PGC_BACKEND */ "backend",
445 /* PGC_SUSET */ "superuser",
446 /* PGC_USERSET */ "user"
450 * Displayable names for source types (enum GucSource)
452 * Note: these strings are deliberately not localized.
454 const char *const GucSource_Names[] =
456 /* PGC_S_DEFAULT */ "default",
457 /* PGC_S_ENV_VAR */ "environment variable",
458 /* PGC_S_FILE */ "configuration file",
459 /* PGC_S_ARGV */ "command line",
460 /* PGC_S_DATABASE */ "database",
461 /* PGC_S_USER */ "user",
462 /* PGC_S_DATABASE_USER */ "database user",
463 /* PGC_S_CLIENT */ "client",
464 /* PGC_S_OVERRIDE */ "override",
465 /* PGC_S_INTERACTIVE */ "interactive",
466 /* PGC_S_TEST */ "test",
467 /* PGC_S_SESSION */ "session"
471 * Displayable names for the groupings defined in enum config_group
473 const char *const config_group_names[] =
476 gettext_noop("Ungrouped"),
478 gettext_noop("File Locations"),
480 gettext_noop("Connections and Authentication"),
481 /* CONN_AUTH_SETTINGS */
482 gettext_noop("Connections and Authentication / Connection Settings"),
483 /* CONN_AUTH_SECURITY */
484 gettext_noop("Connections and Authentication / Security and Authentication"),
486 gettext_noop("Resource Usage"),
488 gettext_noop("Resource Usage / Memory"),
489 /* RESOURCES_KERNEL */
490 gettext_noop("Resource Usage / Kernel Resources"),
492 gettext_noop("Write-Ahead Log"),
494 gettext_noop("Write-Ahead Log / Settings"),
495 /* WAL_CHECKPOINTS */
496 gettext_noop("Write-Ahead Log / Checkpoints"),
497 /* WAL_REPLICATION */
498 gettext_noop("Write-Ahead Log / Replication"),
500 gettext_noop("Query Tuning"),
501 /* QUERY_TUNING_METHOD */
502 gettext_noop("Query Tuning / Planner Method Configuration"),
503 /* QUERY_TUNING_COST */
504 gettext_noop("Query Tuning / Planner Cost Constants"),
505 /* QUERY_TUNING_GEQO */
506 gettext_noop("Query Tuning / Genetic Query Optimizer"),
507 /* QUERY_TUNING_OTHER */
508 gettext_noop("Query Tuning / Other Planner Options"),
510 gettext_noop("Reporting and Logging"),
512 gettext_noop("Reporting and Logging / Where to Log"),
514 gettext_noop("Reporting and Logging / When to Log"),
516 gettext_noop("Reporting and Logging / What to Log"),
518 gettext_noop("Statistics"),
519 /* STATS_MONITORING */
520 gettext_noop("Statistics / Monitoring"),
521 /* STATS_COLLECTOR */
522 gettext_noop("Statistics / Query and Index Statistics Collector"),
524 gettext_noop("Autovacuum"),
526 gettext_noop("Client Connection Defaults"),
527 /* CLIENT_CONN_STATEMENT */
528 gettext_noop("Client Connection Defaults / Statement Behavior"),
529 /* CLIENT_CONN_LOCALE */
530 gettext_noop("Client Connection Defaults / Locale and Formatting"),
531 /* CLIENT_CONN_OTHER */
532 gettext_noop("Client Connection Defaults / Other Defaults"),
533 /* LOCK_MANAGEMENT */
534 gettext_noop("Lock Management"),
536 gettext_noop("Version and Platform Compatibility"),
537 /* COMPAT_OPTIONS_PREVIOUS */
538 gettext_noop("Version and Platform Compatibility / Previous PostgreSQL Versions"),
539 /* COMPAT_OPTIONS_CLIENT */
540 gettext_noop("Version and Platform Compatibility / Other Platforms and Clients"),
542 gettext_noop("Preset Options"),
544 gettext_noop("Customized Options"),
545 /* DEVELOPER_OPTIONS */
546 gettext_noop("Developer Options"),
547 /* help_config wants this array to be null-terminated */
552 * Displayable names for GUC variable types (enum config_type)
554 * Note: these strings are deliberately not localized.
556 const char *const config_type_names[] =
558 /* PGC_BOOL */ "bool",
559 /* PGC_INT */ "integer",
560 /* PGC_REAL */ "real",
561 /* PGC_STRING */ "string",
562 /* PGC_ENUM */ "enum"
567 * Contents of GUC tables
569 * See src/backend/utils/misc/README for design notes.
573 * 1. Declare a global variable of type bool, int, double, or char*
574 * and make use of it.
576 * 2. Decide at what times it's safe to set the option. See guc.h for
579 * 3. Decide on a name, a default value, upper and lower bounds (if
582 * 4. Add a record below.
584 * 5. Add it to src/backend/utils/misc/postgresql.conf.sample, if
587 * 6. Don't forget to document the option (at least in config.sgml).
589 * 7. If it's a new GUC_LIST option you must edit pg_dumpall.c to ensure
590 * it is not single quoted at dump time.
594 /******** option records follow ********/
596 static struct config_bool ConfigureNamesBool[] =
599 {"enable_seqscan", PGC_USERSET, QUERY_TUNING_METHOD,
600 gettext_noop("Enables the planner's use of sequential-scan plans."),
607 {"enable_indexscan", PGC_USERSET, QUERY_TUNING_METHOD,
608 gettext_noop("Enables the planner's use of index-scan plans."),
615 {"enable_bitmapscan", PGC_USERSET, QUERY_TUNING_METHOD,
616 gettext_noop("Enables the planner's use of bitmap-scan plans."),
623 {"enable_tidscan", PGC_USERSET, QUERY_TUNING_METHOD,
624 gettext_noop("Enables the planner's use of TID scan plans."),
631 {"enable_sort", PGC_USERSET, QUERY_TUNING_METHOD,
632 gettext_noop("Enables the planner's use of explicit sort steps."),
639 {"enable_hashagg", PGC_USERSET, QUERY_TUNING_METHOD,
640 gettext_noop("Enables the planner's use of hashed aggregation plans."),
647 {"enable_material", PGC_USERSET, QUERY_TUNING_METHOD,
648 gettext_noop("Enables the planner's use of materialization."),
655 {"enable_nestloop", PGC_USERSET, QUERY_TUNING_METHOD,
656 gettext_noop("Enables the planner's use of nested-loop join plans."),
663 {"enable_mergejoin", PGC_USERSET, QUERY_TUNING_METHOD,
664 gettext_noop("Enables the planner's use of merge join plans."),
671 {"enable_hashjoin", PGC_USERSET, QUERY_TUNING_METHOD,
672 gettext_noop("Enables the planner's use of hash join plans."),
679 {"geqo", PGC_USERSET, QUERY_TUNING_GEQO,
680 gettext_noop("Enables genetic query optimization."),
681 gettext_noop("This algorithm attempts to do planning without "
682 "exhaustive searching.")
688 /* Not for general use --- used by SET SESSION AUTHORIZATION */
689 {"is_superuser", PGC_INTERNAL, UNGROUPED,
690 gettext_noop("Shows whether the current user is a superuser."),
692 GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
694 &session_auth_is_superuser,
698 {"bonjour", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
699 gettext_noop("Enables advertising the server via Bonjour."),
703 false, assign_bonjour, NULL
706 {"ssl", PGC_POSTMASTER, CONN_AUTH_SECURITY,
707 gettext_noop("Enables SSL connections."),
711 false, assign_ssl, NULL
714 {"fsync", PGC_SIGHUP, WAL_SETTINGS,
715 gettext_noop("Forces synchronization of updates to disk."),
716 gettext_noop("The server will use the fsync() system call in several places to make "
717 "sure that updates are physically written to disk. This insures "
718 "that a database cluster will recover to a consistent state after "
719 "an operating system or hardware crash.")
725 {"synchronous_commit", PGC_USERSET, WAL_SETTINGS,
726 gettext_noop("Sets immediate fsync at commit."),
733 {"zero_damaged_pages", PGC_SUSET, DEVELOPER_OPTIONS,
734 gettext_noop("Continues processing past damaged page headers."),
735 gettext_noop("Detection of a damaged page header normally causes PostgreSQL to "
736 "report an error, aborting the current transaction. Setting "
737 "zero_damaged_pages to true causes the system to instead report a "
738 "warning, zero out the damaged page, and continue processing. This "
739 "behavior will destroy data, namely all the rows on the damaged page."),
746 {"full_page_writes", PGC_SIGHUP, WAL_SETTINGS,
747 gettext_noop("Writes full pages to WAL when first modified after a checkpoint."),
748 gettext_noop("A page write in process during an operating system crash might be "
749 "only partially written to disk. During recovery, the row changes "
750 "stored in WAL are not enough to recover. This option writes "
751 "pages when first modified after a checkpoint to WAL so full recovery "
758 {"silent_mode", PGC_POSTMASTER, LOGGING_WHERE,
759 gettext_noop("Runs the server silently."),
760 gettext_noop("If this parameter is set, the server will automatically run in the "
761 "background and any controlling terminals are dissociated.")
767 {"log_checkpoints", PGC_SIGHUP, LOGGING_WHAT,
768 gettext_noop("Logs each checkpoint."),
775 {"log_connections", PGC_BACKEND, LOGGING_WHAT,
776 gettext_noop("Logs each successful connection."),
783 {"log_disconnections", PGC_BACKEND, LOGGING_WHAT,
784 gettext_noop("Logs end of a session, including duration."),
791 {"debug_assertions", PGC_USERSET, DEVELOPER_OPTIONS,
792 gettext_noop("Turns on various assertion checks."),
793 gettext_noop("This is a debugging aid."),
797 #ifdef USE_ASSERT_CHECKING
802 assign_debug_assertions, NULL
805 /* currently undocumented, so don't show in SHOW ALL */
806 {"exit_on_error", PGC_USERSET, UNGROUPED,
807 gettext_noop("No description available."),
809 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
815 {"log_duration", PGC_SUSET, LOGGING_WHAT,
816 gettext_noop("Logs the duration of each completed SQL statement."),
823 {"debug_print_parse", PGC_USERSET, LOGGING_WHAT,
824 gettext_noop("Logs each query's parse tree."),
831 {"debug_print_rewritten", PGC_USERSET, LOGGING_WHAT,
832 gettext_noop("Logs each query's rewritten parse tree."),
835 &Debug_print_rewritten,
839 {"debug_print_plan", PGC_USERSET, LOGGING_WHAT,
840 gettext_noop("Logs each query's execution plan."),
847 {"debug_pretty_print", PGC_USERSET, LOGGING_WHAT,
848 gettext_noop("Indents parse and plan tree displays."),
855 {"log_parser_stats", PGC_SUSET, STATS_MONITORING,
856 gettext_noop("Writes parser performance statistics to the server log."),
860 false, assign_stage_log_stats, NULL
863 {"log_planner_stats", PGC_SUSET, STATS_MONITORING,
864 gettext_noop("Writes planner performance statistics to the server log."),
868 false, assign_stage_log_stats, NULL
871 {"log_executor_stats", PGC_SUSET, STATS_MONITORING,
872 gettext_noop("Writes executor performance statistics to the server log."),
876 false, assign_stage_log_stats, NULL
879 {"log_statement_stats", PGC_SUSET, STATS_MONITORING,
880 gettext_noop("Writes cumulative performance statistics to the server log."),
883 &log_statement_stats,
884 false, assign_log_stats, NULL
886 #ifdef BTREE_BUILD_STATS
888 {"log_btree_build_stats", PGC_SUSET, DEVELOPER_OPTIONS,
889 gettext_noop("No description available."),
893 &log_btree_build_stats,
899 {"track_activities", PGC_SUSET, STATS_COLLECTOR,
900 gettext_noop("Collects information about executing commands."),
901 gettext_noop("Enables the collection of information on the currently "
902 "executing command of each session, along with "
903 "the time at which that command began execution.")
905 &pgstat_track_activities,
909 {"track_counts", PGC_SUSET, STATS_COLLECTOR,
910 gettext_noop("Collects statistics on database activity."),
913 &pgstat_track_counts,
918 {"update_process_title", PGC_SUSET, STATS_COLLECTOR,
919 gettext_noop("Updates the process title to show the active SQL command."),
920 gettext_noop("Enables updating of the process title every time a new SQL command is received by the server.")
922 &update_process_title,
927 {"autovacuum", PGC_SIGHUP, AUTOVACUUM,
928 gettext_noop("Starts the autovacuum subprocess."),
931 &autovacuum_start_daemon,
936 {"trace_notify", PGC_USERSET, DEVELOPER_OPTIONS,
937 gettext_noop("Generates debugging output for LISTEN and NOTIFY."),
947 {"trace_locks", PGC_SUSET, DEVELOPER_OPTIONS,
948 gettext_noop("No description available."),
956 {"trace_userlocks", PGC_SUSET, DEVELOPER_OPTIONS,
957 gettext_noop("No description available."),
965 {"trace_lwlocks", PGC_SUSET, DEVELOPER_OPTIONS,
966 gettext_noop("No description available."),
974 {"debug_deadlocks", PGC_SUSET, DEVELOPER_OPTIONS,
975 gettext_noop("No description available."),
985 {"log_lock_waits", PGC_SUSET, LOGGING_WHAT,
986 gettext_noop("Logs long lock waits."),
994 {"log_hostname", PGC_SIGHUP, LOGGING_WHAT,
995 gettext_noop("Logs the host name in the connection logs."),
996 gettext_noop("By default, connection logs only show the IP address "
997 "of the connecting host. If you want them to show the host name you "
998 "can turn this on, but depending on your host name resolution "
999 "setup it might impose a non-negligible performance penalty.")
1005 {"sql_inheritance", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1006 gettext_noop("Causes subtables to be included by default in various commands."),
1013 {"password_encryption", PGC_USERSET, CONN_AUTH_SECURITY,
1014 gettext_noop("Encrypt passwords."),
1015 gettext_noop("When a password is specified in CREATE USER or "
1016 "ALTER USER without writing either ENCRYPTED or UNENCRYPTED, "
1017 "this parameter determines whether the password is to be encrypted.")
1019 &Password_encryption,
1023 {"transform_null_equals", PGC_USERSET, COMPAT_OPTIONS_CLIENT,
1024 gettext_noop("Treats \"expr=NULL\" as \"expr IS NULL\"."),
1025 gettext_noop("When turned on, expressions of the form expr = NULL "
1026 "(or NULL = expr) are treated as expr IS NULL, that is, they "
1027 "return true if expr evaluates to the null value, and false "
1028 "otherwise. The correct behavior of expr = NULL is to always "
1029 "return null (unknown).")
1031 &Transform_null_equals,
1035 {"db_user_namespace", PGC_SIGHUP, CONN_AUTH_SECURITY,
1036 gettext_noop("Enables per-database user names."),
1043 /* only here for backwards compatibility */
1044 {"autocommit", PGC_USERSET, CLIENT_CONN_STATEMENT,
1045 gettext_noop("This parameter doesn't do anything."),
1046 gettext_noop("It's just here so that we won't choke on SET AUTOCOMMIT TO ON from 7.3-vintage clients."),
1047 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
1050 true, assign_phony_autocommit, NULL
1053 {"default_transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
1054 gettext_noop("Sets the default read-only status of new transactions."),
1057 &DefaultXactReadOnly,
1061 {"transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
1062 gettext_noop("Sets the current transaction's read-only status."),
1064 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1067 false, assign_transaction_read_only, NULL
1070 {"check_function_bodies", PGC_USERSET, CLIENT_CONN_STATEMENT,
1071 gettext_noop("Check function bodies during CREATE FUNCTION."),
1074 &check_function_bodies,
1078 {"array_nulls", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1079 gettext_noop("Enable input of NULL elements in arrays."),
1080 gettext_noop("When turned on, unquoted NULL in an array input "
1081 "value means a null value; "
1082 "otherwise it is taken literally.")
1088 {"default_with_oids", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1089 gettext_noop("Create new tables with OIDs by default."),
1096 {"logging_collector", PGC_POSTMASTER, LOGGING_WHERE,
1097 gettext_noop("Start a subprocess to capture stderr output and/or csvlogs into log files."),
1104 {"log_truncate_on_rotation", PGC_SIGHUP, LOGGING_WHERE,
1105 gettext_noop("Truncate existing log files of same name during log rotation."),
1108 &Log_truncate_on_rotation,
1114 {"trace_sort", PGC_USERSET, DEVELOPER_OPTIONS,
1115 gettext_noop("Emit information about resource usage in sorting."),
1124 #ifdef TRACE_SYNCSCAN
1125 /* this is undocumented because not exposed in a standard build */
1127 {"trace_syncscan", PGC_USERSET, DEVELOPER_OPTIONS,
1128 gettext_noop("Generate debugging output for synchronized scanning."),
1137 #ifdef DEBUG_BOUNDED_SORT
1138 /* this is undocumented because not exposed in a standard build */
1141 "optimize_bounded_sort", PGC_USERSET, QUERY_TUNING_METHOD,
1142 gettext_noop("Enable bounded sorting using heap sort."),
1146 &optimize_bounded_sort,
1153 {"wal_debug", PGC_SUSET, DEVELOPER_OPTIONS,
1154 gettext_noop("Emit WAL-related debugging output."),
1164 {"integer_datetimes", PGC_INTERNAL, PRESET_OPTIONS,
1165 gettext_noop("Datetimes are integer based."),
1167 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1170 #ifdef HAVE_INT64_TIMESTAMP
1178 {"krb_caseins_users", PGC_SIGHUP, CONN_AUTH_SECURITY,
1179 gettext_noop("Sets whether Kerberos and GSSAPI user names should be treated as case-insensitive."),
1182 &pg_krb_caseins_users,
1187 {"escape_string_warning", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1188 gettext_noop("Warn about backslash escapes in ordinary string literals."),
1191 &escape_string_warning,
1196 {"standard_conforming_strings", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1197 gettext_noop("Causes '...' strings to treat backslashes literally."),
1201 &standard_conforming_strings,
1206 {"synchronize_seqscans", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1207 gettext_noop("Enable synchronized sequential scans."),
1210 &synchronize_seqscans,
1215 {"archive_mode", PGC_POSTMASTER, WAL_SETTINGS,
1216 gettext_noop("Allows archiving of WAL files using archive_command."),
1224 {"recovery_connections", PGC_POSTMASTER, WAL_SETTINGS,
1225 gettext_noop("During recovery, allows connections and queries. "
1226 " During normal running, causes additional info to be written"
1227 " to WAL to enable hot standby mode on WAL standby nodes."),
1230 &XLogRequestRecoveryConnections,
1235 {"allow_system_table_mods", PGC_POSTMASTER, DEVELOPER_OPTIONS,
1236 gettext_noop("Allows modifications of the structure of system tables."),
1240 &allowSystemTableMods,
1245 {"ignore_system_indexes", PGC_BACKEND, DEVELOPER_OPTIONS,
1246 gettext_noop("Disables reading from system indexes."),
1247 gettext_noop("It does not prevent updating the indexes, so it is safe "
1248 "to use. The worst consequence is slowness."),
1251 &IgnoreSystemIndexes,
1256 {"lo_compat_privileges", PGC_SUSET, COMPAT_OPTIONS_PREVIOUS,
1257 gettext_noop("Enables backward compatibility mode for privilege checks on large objects."),
1258 gettext_noop("Skips privilege checks when reading or modifying large objects, "
1259 "for compatibility with PostgreSQL releases prior to 9.0.")
1261 &lo_compat_privileges,
1265 /* End-of-list marker */
1267 {NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL
1272 static struct config_int ConfigureNamesInt[] =
1275 {"archive_timeout", PGC_SIGHUP, WAL_SETTINGS,
1276 gettext_noop("Forces a switch to the next xlog file if a "
1277 "new file has not been started within N seconds."),
1281 &XLogArchiveTimeout,
1282 0, 0, INT_MAX, NULL, NULL
1285 {"post_auth_delay", PGC_BACKEND, DEVELOPER_OPTIONS,
1286 gettext_noop("Waits N seconds on connection startup after authentication."),
1287 gettext_noop("This allows attaching a debugger to the process."),
1288 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1291 0, 0, INT_MAX, NULL, NULL
1294 {"default_statistics_target", PGC_USERSET, QUERY_TUNING_OTHER,
1295 gettext_noop("Sets the default statistics target."),
1296 gettext_noop("This applies to table columns that have not had a "
1297 "column-specific target set via ALTER TABLE SET STATISTICS.")
1299 &default_statistics_target,
1300 100, 1, 10000, NULL, NULL
1303 {"from_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1304 gettext_noop("Sets the FROM-list size beyond which subqueries "
1305 "are not collapsed."),
1306 gettext_noop("The planner will merge subqueries into upper "
1307 "queries if the resulting FROM list would have no more than "
1310 &from_collapse_limit,
1311 8, 1, INT_MAX, NULL, NULL
1314 {"join_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1315 gettext_noop("Sets the FROM-list size beyond which JOIN "
1316 "constructs are not flattened."),
1317 gettext_noop("The planner will flatten explicit JOIN "
1318 "constructs into lists of FROM items whenever a "
1319 "list of no more than this many items would result.")
1321 &join_collapse_limit,
1322 8, 1, INT_MAX, NULL, NULL
1325 {"geqo_threshold", PGC_USERSET, QUERY_TUNING_GEQO,
1326 gettext_noop("Sets the threshold of FROM items beyond which GEQO is used."),
1330 12, 2, INT_MAX, NULL, NULL
1333 {"geqo_effort", PGC_USERSET, QUERY_TUNING_GEQO,
1334 gettext_noop("GEQO: effort is used to set the default for other GEQO parameters."),
1338 DEFAULT_GEQO_EFFORT, MIN_GEQO_EFFORT, MAX_GEQO_EFFORT, NULL, NULL
1341 {"geqo_pool_size", PGC_USERSET, QUERY_TUNING_GEQO,
1342 gettext_noop("GEQO: number of individuals in the population."),
1343 gettext_noop("Zero selects a suitable default value.")
1346 0, 0, INT_MAX, NULL, NULL
1349 {"geqo_generations", PGC_USERSET, QUERY_TUNING_GEQO,
1350 gettext_noop("GEQO: number of iterations of the algorithm."),
1351 gettext_noop("Zero selects a suitable default value.")
1354 0, 0, INT_MAX, NULL, NULL
1358 /* This is PGC_SIGHUP so all backends have the same value. */
1359 {"deadlock_timeout", PGC_SIGHUP, LOCK_MANAGEMENT,
1360 gettext_noop("Sets the time to wait on a lock before checking for deadlock."),
1365 1000, 1, INT_MAX / 1000, NULL, NULL
1369 * Note: MaxBackends is limited to INT_MAX/4 because some places compute
1370 * 4*MaxBackends without any overflow check. This check is made in
1371 * assign_maxconnections, since MaxBackends is computed as MaxConnections
1372 * plus autovacuum_max_workers plus one (for the autovacuum launcher).
1374 * Likewise we have to limit NBuffers to INT_MAX/2.
1376 * See also CheckRequiredParameterValues() if this parameter changes
1379 {"max_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1380 gettext_noop("Sets the maximum number of concurrent connections."),
1384 100, 1, INT_MAX / 4, assign_maxconnections, NULL
1388 {"max_standby_delay", PGC_SIGHUP, WAL_SETTINGS,
1389 gettext_noop("Sets the maximum delay to avoid conflict processing on hot standby servers."),
1393 30, -1, INT_MAX, NULL, NULL
1397 {"superuser_reserved_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1398 gettext_noop("Sets the number of connection slots reserved for superusers."),
1402 3, 0, INT_MAX / 4, NULL, NULL
1406 {"shared_buffers", PGC_POSTMASTER, RESOURCES_MEM,
1407 gettext_noop("Sets the number of shared memory buffers used by the server."),
1412 1024, 16, INT_MAX / 2, NULL, NULL
1416 {"temp_buffers", PGC_USERSET, RESOURCES_MEM,
1417 gettext_noop("Sets the maximum number of temporary buffers used by each session."),
1422 1024, 100, INT_MAX / 2, NULL, show_num_temp_buffers
1426 {"port", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1427 gettext_noop("Sets the TCP port the server listens on."),
1431 DEF_PGPORT, 1, 65535, NULL, NULL
1435 {"unix_socket_permissions", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1436 gettext_noop("Sets the access permissions of the Unix-domain socket."),
1437 gettext_noop("Unix-domain sockets use the usual Unix file system "
1438 "permission set. The parameter value is expected to be a numeric mode "
1439 "specification in the form accepted by the chmod and umask system "
1440 "calls. (To use the customary octal format the number must start with "
1443 &Unix_socket_permissions,
1444 0777, 0000, 0777, NULL, NULL
1448 {"work_mem", PGC_USERSET, RESOURCES_MEM,
1449 gettext_noop("Sets the maximum memory to be used for query workspaces."),
1450 gettext_noop("This much memory can be used by each internal "
1451 "sort operation and hash table before switching to "
1452 "temporary disk files."),
1456 1024, 64, MAX_KILOBYTES, NULL, NULL
1460 {"maintenance_work_mem", PGC_USERSET, RESOURCES_MEM,
1461 gettext_noop("Sets the maximum memory to be used for maintenance operations."),
1462 gettext_noop("This includes operations such as VACUUM and CREATE INDEX."),
1465 &maintenance_work_mem,
1466 16384, 1024, MAX_KILOBYTES, NULL, NULL
1470 {"max_stack_depth", PGC_SUSET, RESOURCES_MEM,
1471 gettext_noop("Sets the maximum stack depth, in kilobytes."),
1476 100, 100, MAX_KILOBYTES, assign_max_stack_depth, NULL
1480 {"vacuum_cost_page_hit", PGC_USERSET, RESOURCES,
1481 gettext_noop("Vacuum cost for a page found in the buffer cache."),
1485 1, 0, 10000, NULL, NULL
1489 {"vacuum_cost_page_miss", PGC_USERSET, RESOURCES,
1490 gettext_noop("Vacuum cost for a page not found in the buffer cache."),
1493 &VacuumCostPageMiss,
1494 10, 0, 10000, NULL, NULL
1498 {"vacuum_cost_page_dirty", PGC_USERSET, RESOURCES,
1499 gettext_noop("Vacuum cost for a page dirtied by vacuum."),
1502 &VacuumCostPageDirty,
1503 20, 0, 10000, NULL, NULL
1507 {"vacuum_cost_limit", PGC_USERSET, RESOURCES,
1508 gettext_noop("Vacuum cost amount available before napping."),
1512 200, 1, 10000, NULL, NULL
1516 {"vacuum_cost_delay", PGC_USERSET, RESOURCES,
1517 gettext_noop("Vacuum cost delay in milliseconds."),
1522 0, 0, 100, NULL, NULL
1526 {"autovacuum_vacuum_cost_delay", PGC_SIGHUP, AUTOVACUUM,
1527 gettext_noop("Vacuum cost delay in milliseconds, for autovacuum."),
1531 &autovacuum_vac_cost_delay,
1532 20, -1, 100, NULL, NULL
1536 {"autovacuum_vacuum_cost_limit", PGC_SIGHUP, AUTOVACUUM,
1537 gettext_noop("Vacuum cost amount available before napping, for autovacuum."),
1540 &autovacuum_vac_cost_limit,
1541 -1, -1, 10000, NULL, NULL
1545 {"max_files_per_process", PGC_POSTMASTER, RESOURCES_KERNEL,
1546 gettext_noop("Sets the maximum number of simultaneously open files for each server process."),
1549 &max_files_per_process,
1550 1000, 25, INT_MAX, NULL, NULL
1554 * See also CheckRequiredParameterValues() if this parameter changes
1557 {"max_prepared_transactions", PGC_POSTMASTER, RESOURCES,
1558 gettext_noop("Sets the maximum number of simultaneously prepared transactions."),
1561 &max_prepared_xacts,
1562 0, 0, INT_MAX / 4, NULL, NULL
1567 {"trace_lock_oidmin", PGC_SUSET, DEVELOPER_OPTIONS,
1568 gettext_noop("No description available."),
1573 FirstNormalObjectId, 0, INT_MAX, NULL, NULL
1576 {"trace_lock_table", PGC_SUSET, DEVELOPER_OPTIONS,
1577 gettext_noop("No description available."),
1582 0, 0, INT_MAX, NULL, NULL
1587 {"statement_timeout", PGC_USERSET, CLIENT_CONN_STATEMENT,
1588 gettext_noop("Sets the maximum allowed duration of any statement."),
1589 gettext_noop("A value of 0 turns off the timeout."),
1593 0, 0, INT_MAX, NULL, NULL
1597 {"vacuum_freeze_min_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1598 gettext_noop("Minimum age at which VACUUM should freeze a table row."),
1601 &vacuum_freeze_min_age,
1602 50000000, 0, 1000000000, NULL, NULL
1606 {"vacuum_freeze_table_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1607 gettext_noop("Age at which VACUUM should scan whole table to freeze tuples."),
1610 &vacuum_freeze_table_age,
1611 150000000, 0, 2000000000, NULL, NULL
1615 {"vacuum_defer_cleanup_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1616 gettext_noop("Age by which VACUUM and HOT cleanup should be deferred, if any."),
1619 &vacuum_defer_cleanup_age,
1620 0, 0, 1000000, NULL, NULL
1624 * See also CheckRequiredParameterValues() if this parameter changes
1627 {"max_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
1628 gettext_noop("Sets the maximum number of locks per transaction."),
1629 gettext_noop("The shared lock table is sized on the assumption that "
1630 "at most max_locks_per_transaction * max_connections distinct "
1631 "objects will need to be locked at any one time.")
1633 &max_locks_per_xact,
1634 64, 10, INT_MAX, NULL, NULL
1638 {"authentication_timeout", PGC_SIGHUP, CONN_AUTH_SECURITY,
1639 gettext_noop("Sets the maximum allowed time to complete client authentication."),
1643 &AuthenticationTimeout,
1644 60, 1, 600, NULL, NULL
1648 /* Not for general use */
1649 {"pre_auth_delay", PGC_SIGHUP, DEVELOPER_OPTIONS,
1650 gettext_noop("Waits N seconds on connection startup before authentication."),
1651 gettext_noop("This allows attaching a debugger to the process."),
1652 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1655 0, 0, 60, NULL, NULL
1659 {"wal_keep_segments", PGC_SIGHUP, WAL_CHECKPOINTS,
1660 gettext_noop("Sets the number of WAL files held for standby servers"),
1664 0, 0, INT_MAX, NULL, NULL
1668 {"checkpoint_segments", PGC_SIGHUP, WAL_CHECKPOINTS,
1669 gettext_noop("Sets the maximum distance in log segments between automatic WAL checkpoints."),
1672 &CheckPointSegments,
1673 3, 1, INT_MAX, NULL, NULL
1677 {"checkpoint_timeout", PGC_SIGHUP, WAL_CHECKPOINTS,
1678 gettext_noop("Sets the maximum time between automatic WAL checkpoints."),
1683 300, 30, 3600, NULL, NULL
1687 {"checkpoint_warning", PGC_SIGHUP, WAL_CHECKPOINTS,
1688 gettext_noop("Enables warnings if checkpoint segments are filled more "
1689 "frequently than this."),
1690 gettext_noop("Write a message to the server log if checkpoints "
1691 "caused by the filling of checkpoint segment files happens more "
1692 "frequently than this number of seconds. Zero turns off the warning."),
1696 30, 0, INT_MAX, NULL, NULL
1700 {"wal_buffers", PGC_POSTMASTER, WAL_SETTINGS,
1701 gettext_noop("Sets the number of disk-page buffers in shared memory for WAL."),
1706 8, 4, INT_MAX, NULL, NULL
1710 {"wal_writer_delay", PGC_SIGHUP, WAL_SETTINGS,
1711 gettext_noop("WAL writer sleep time between WAL flushes."),
1716 200, 1, 10000, NULL, NULL
1720 /* see max_connections */
1721 {"max_wal_senders", PGC_POSTMASTER, WAL_REPLICATION,
1722 gettext_noop("Sets the maximum number of simultaneously running WAL sender processes."),
1726 0, 0, INT_MAX / 4, NULL, NULL
1730 {"wal_sender_delay", PGC_SIGHUP, WAL_REPLICATION,
1731 gettext_noop("WAL sender sleep time between WAL replications."),
1736 200, 1, 10000, NULL, NULL
1740 {"commit_delay", PGC_USERSET, WAL_SETTINGS,
1741 gettext_noop("Sets the delay in microseconds between transaction commit and "
1742 "flushing WAL to disk."),
1746 0, 0, 100000, NULL, NULL
1750 {"commit_siblings", PGC_USERSET, WAL_SETTINGS,
1751 gettext_noop("Sets the minimum concurrent open transactions before performing "
1756 5, 1, 1000, NULL, NULL
1760 {"extra_float_digits", PGC_USERSET, CLIENT_CONN_LOCALE,
1761 gettext_noop("Sets the number of digits displayed for floating-point values."),
1762 gettext_noop("This affects real, double precision, and geometric data types. "
1763 "The parameter value is added to the standard number of digits "
1764 "(FLT_DIG or DBL_DIG as appropriate).")
1766 &extra_float_digits,
1767 0, -15, 3, NULL, NULL
1771 {"log_min_duration_statement", PGC_SUSET, LOGGING_WHEN,
1772 gettext_noop("Sets the minimum execution time above which "
1773 "statements will be logged."),
1774 gettext_noop("Zero prints all queries. -1 turns this feature off."),
1777 &log_min_duration_statement,
1778 -1, -1, INT_MAX / 1000, NULL, NULL
1782 {"log_autovacuum_min_duration", PGC_SIGHUP, LOGGING_WHAT,
1783 gettext_noop("Sets the minimum execution time above which "
1784 "autovacuum actions will be logged."),
1785 gettext_noop("Zero prints all actions. -1 turns autovacuum logging off."),
1788 &Log_autovacuum_min_duration,
1789 -1, -1, INT_MAX / 1000, NULL, NULL
1793 {"bgwriter_delay", PGC_SIGHUP, RESOURCES,
1794 gettext_noop("Background writer sleep time between rounds."),
1799 200, 10, 10000, NULL, NULL
1803 {"bgwriter_lru_maxpages", PGC_SIGHUP, RESOURCES,
1804 gettext_noop("Background writer maximum number of LRU pages to flush per round."),
1807 &bgwriter_lru_maxpages,
1808 100, 0, 1000, NULL, NULL
1812 {"effective_io_concurrency",
1819 gettext_noop("Number of simultaneous requests that can be handled efficiently by the disk subsystem."),
1820 gettext_noop("For RAID arrays, this should be approximately the number of drive spindles in the array.")
1822 &effective_io_concurrency,
1828 assign_effective_io_concurrency, NULL
1832 {"log_rotation_age", PGC_SIGHUP, LOGGING_WHERE,
1833 gettext_noop("Automatic log file rotation will occur after N minutes."),
1838 HOURS_PER_DAY * MINS_PER_HOUR, 0, INT_MAX / MINS_PER_HOUR, NULL, NULL
1842 {"log_rotation_size", PGC_SIGHUP, LOGGING_WHERE,
1843 gettext_noop("Automatic log file rotation will occur after N kilobytes."),
1848 10 * 1024, 0, INT_MAX / 1024, NULL, NULL
1852 {"max_function_args", PGC_INTERNAL, PRESET_OPTIONS,
1853 gettext_noop("Shows the maximum number of function arguments."),
1855 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1858 FUNC_MAX_ARGS, FUNC_MAX_ARGS, FUNC_MAX_ARGS, NULL, NULL
1862 {"max_index_keys", PGC_INTERNAL, PRESET_OPTIONS,
1863 gettext_noop("Shows the maximum number of index keys."),
1865 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1868 INDEX_MAX_KEYS, INDEX_MAX_KEYS, INDEX_MAX_KEYS, NULL, NULL
1872 {"max_identifier_length", PGC_INTERNAL, PRESET_OPTIONS,
1873 gettext_noop("Shows the maximum identifier length."),
1875 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1877 &max_identifier_length,
1878 NAMEDATALEN - 1, NAMEDATALEN - 1, NAMEDATALEN - 1, NULL, NULL
1882 {"block_size", PGC_INTERNAL, PRESET_OPTIONS,
1883 gettext_noop("Shows the size of a disk block."),
1885 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1888 BLCKSZ, BLCKSZ, BLCKSZ, NULL, NULL
1892 {"segment_size", PGC_INTERNAL, PRESET_OPTIONS,
1893 gettext_noop("Shows the number of pages per disk file."),
1895 GUC_UNIT_BLOCKS | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1898 RELSEG_SIZE, RELSEG_SIZE, RELSEG_SIZE, NULL, NULL
1902 {"wal_block_size", PGC_INTERNAL, PRESET_OPTIONS,
1903 gettext_noop("Shows the block size in the write ahead log."),
1905 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1908 XLOG_BLCKSZ, XLOG_BLCKSZ, XLOG_BLCKSZ, NULL, NULL
1912 {"wal_segment_size", PGC_INTERNAL, PRESET_OPTIONS,
1913 gettext_noop("Shows the number of pages per write ahead log segment."),
1915 GUC_UNIT_XBLOCKS | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1918 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
1919 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
1920 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
1925 {"autovacuum_naptime", PGC_SIGHUP, AUTOVACUUM,
1926 gettext_noop("Time to sleep between autovacuum runs."),
1930 &autovacuum_naptime,
1931 60, 1, INT_MAX / 1000, NULL, NULL
1934 {"autovacuum_vacuum_threshold", PGC_SIGHUP, AUTOVACUUM,
1935 gettext_noop("Minimum number of tuple updates or deletes prior to vacuum."),
1938 &autovacuum_vac_thresh,
1939 50, 0, INT_MAX, NULL, NULL
1942 {"autovacuum_analyze_threshold", PGC_SIGHUP, AUTOVACUUM,
1943 gettext_noop("Minimum number of tuple inserts, updates or deletes prior to analyze."),
1946 &autovacuum_anl_thresh,
1947 50, 0, INT_MAX, NULL, NULL
1950 /* see varsup.c for why this is PGC_POSTMASTER not PGC_SIGHUP */
1951 {"autovacuum_freeze_max_age", PGC_POSTMASTER, AUTOVACUUM,
1952 gettext_noop("Age at which to autovacuum a table to prevent transaction ID wraparound."),
1955 &autovacuum_freeze_max_age,
1956 /* see pg_resetxlog if you change the upper-limit value */
1957 200000000, 100000000, 2000000000, NULL, NULL
1960 /* see max_connections */
1961 {"autovacuum_max_workers", PGC_POSTMASTER, AUTOVACUUM,
1962 gettext_noop("Sets the maximum number of simultaneously running autovacuum worker processes."),
1965 &autovacuum_max_workers,
1966 3, 1, INT_MAX / 4, assign_autovacuum_max_workers, NULL
1970 {"tcp_keepalives_idle", PGC_USERSET, CLIENT_CONN_OTHER,
1971 gettext_noop("Time between issuing TCP keepalives."),
1972 gettext_noop("A value of 0 uses the system default."),
1975 &tcp_keepalives_idle,
1976 0, 0, INT_MAX, assign_tcp_keepalives_idle, show_tcp_keepalives_idle
1980 {"tcp_keepalives_interval", PGC_USERSET, CLIENT_CONN_OTHER,
1981 gettext_noop("Time between TCP keepalive retransmits."),
1982 gettext_noop("A value of 0 uses the system default."),
1985 &tcp_keepalives_interval,
1986 0, 0, INT_MAX, assign_tcp_keepalives_interval, show_tcp_keepalives_interval
1990 {"ssl_renegotiation_limit", PGC_USERSET, CONN_AUTH_SECURITY,
1991 gettext_noop("Set the amount of traffic to send and receive before renegotiating the encryption keys."),
1995 &ssl_renegotiation_limit,
1996 512 * 1024, 0, MAX_KILOBYTES, NULL, NULL
2000 {"tcp_keepalives_count", PGC_USERSET, CLIENT_CONN_OTHER,
2001 gettext_noop("Maximum number of TCP keepalive retransmits."),
2002 gettext_noop("This controls the number of consecutive keepalive retransmits that can be "
2003 "lost before a connection is considered dead. A value of 0 uses the "
2006 &tcp_keepalives_count,
2007 0, 0, INT_MAX, assign_tcp_keepalives_count, show_tcp_keepalives_count
2011 {"gin_fuzzy_search_limit", PGC_USERSET, CLIENT_CONN_OTHER,
2012 gettext_noop("Sets the maximum allowed result for exact search by GIN."),
2016 &GinFuzzySearchLimit,
2017 0, 0, INT_MAX, NULL, NULL
2021 {"effective_cache_size", PGC_USERSET, QUERY_TUNING_COST,
2022 gettext_noop("Sets the planner's assumption about the size of the disk cache."),
2023 gettext_noop("That is, the portion of the kernel's disk cache that "
2024 "will be used for PostgreSQL data files. This is measured in disk "
2025 "pages, which are normally 8 kB each."),
2028 &effective_cache_size,
2029 DEFAULT_EFFECTIVE_CACHE_SIZE, 1, INT_MAX, NULL, NULL
2033 /* Can't be set in postgresql.conf */
2034 {"server_version_num", PGC_INTERNAL, PRESET_OPTIONS,
2035 gettext_noop("Shows the server version as an integer."),
2037 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2039 &server_version_num,
2040 PG_VERSION_NUM, PG_VERSION_NUM, PG_VERSION_NUM, NULL, NULL
2044 {"log_temp_files", PGC_SUSET, LOGGING_WHAT,
2045 gettext_noop("Log the use of temporary files larger than this number of kilobytes."),
2046 gettext_noop("Zero logs all files. The default is -1 (turning this feature off)."),
2050 -1, -1, INT_MAX, NULL, NULL
2054 {"track_activity_query_size", PGC_POSTMASTER, RESOURCES_MEM,
2055 gettext_noop("Sets the size reserved for pg_stat_activity.current_query, in bytes."),
2058 &pgstat_track_activity_query_size,
2059 1024, 100, 102400, NULL, NULL
2062 /* End-of-list marker */
2064 {NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL
2069 static struct config_real ConfigureNamesReal[] =
2072 {"seq_page_cost", PGC_USERSET, QUERY_TUNING_COST,
2073 gettext_noop("Sets the planner's estimate of the cost of a "
2074 "sequentially fetched disk page."),
2078 DEFAULT_SEQ_PAGE_COST, 0, DBL_MAX, NULL, NULL
2081 {"random_page_cost", PGC_USERSET, QUERY_TUNING_COST,
2082 gettext_noop("Sets the planner's estimate of the cost of a "
2083 "nonsequentially fetched disk page."),
2087 DEFAULT_RANDOM_PAGE_COST, 0, DBL_MAX, NULL, NULL
2090 {"cpu_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
2091 gettext_noop("Sets the planner's estimate of the cost of "
2092 "processing each tuple (row)."),
2096 DEFAULT_CPU_TUPLE_COST, 0, DBL_MAX, NULL, NULL
2099 {"cpu_index_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
2100 gettext_noop("Sets the planner's estimate of the cost of "
2101 "processing each index entry during an index scan."),
2104 &cpu_index_tuple_cost,
2105 DEFAULT_CPU_INDEX_TUPLE_COST, 0, DBL_MAX, NULL, NULL
2108 {"cpu_operator_cost", PGC_USERSET, QUERY_TUNING_COST,
2109 gettext_noop("Sets the planner's estimate of the cost of "
2110 "processing each operator or function call."),
2114 DEFAULT_CPU_OPERATOR_COST, 0, DBL_MAX, NULL, NULL
2118 {"cursor_tuple_fraction", PGC_USERSET, QUERY_TUNING_OTHER,
2119 gettext_noop("Sets the planner's estimate of the fraction of "
2120 "a cursor's rows that will be retrieved."),
2123 &cursor_tuple_fraction,
2124 DEFAULT_CURSOR_TUPLE_FRACTION, 0.0, 1.0, NULL, NULL
2128 {"geqo_selection_bias", PGC_USERSET, QUERY_TUNING_GEQO,
2129 gettext_noop("GEQO: selective pressure within the population."),
2132 &Geqo_selection_bias,
2133 DEFAULT_GEQO_SELECTION_BIAS, MIN_GEQO_SELECTION_BIAS,
2134 MAX_GEQO_SELECTION_BIAS, NULL, NULL
2137 {"geqo_seed", PGC_USERSET, QUERY_TUNING_GEQO,
2138 gettext_noop("GEQO: seed for random path selection."),
2142 0.0, 0.0, 1.0, NULL, NULL
2146 {"bgwriter_lru_multiplier", PGC_SIGHUP, RESOURCES,
2147 gettext_noop("Multiple of the average buffer usage to free per round."),
2150 &bgwriter_lru_multiplier,
2151 2.0, 0.0, 10.0, NULL, NULL
2155 {"seed", PGC_USERSET, UNGROUPED,
2156 gettext_noop("Sets the seed for random-number generation."),
2158 GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2161 0.0, -1.0, 1.0, assign_random_seed, show_random_seed
2165 {"autovacuum_vacuum_scale_factor", PGC_SIGHUP, AUTOVACUUM,
2166 gettext_noop("Number of tuple updates or deletes prior to vacuum as a fraction of reltuples."),
2169 &autovacuum_vac_scale,
2170 0.2, 0.0, 100.0, NULL, NULL
2173 {"autovacuum_analyze_scale_factor", PGC_SIGHUP, AUTOVACUUM,
2174 gettext_noop("Number of tuple inserts, updates or deletes prior to analyze as a fraction of reltuples."),
2177 &autovacuum_anl_scale,
2178 0.1, 0.0, 100.0, NULL, NULL
2182 {"checkpoint_completion_target", PGC_SIGHUP, WAL_CHECKPOINTS,
2183 gettext_noop("Time spent flushing dirty buffers during checkpoint, as fraction of checkpoint interval."),
2186 &CheckPointCompletionTarget,
2187 0.5, 0.0, 1.0, NULL, NULL
2190 /* End-of-list marker */
2192 {NULL, 0, 0, NULL, NULL}, NULL, 0.0, 0.0, 0.0, NULL, NULL
2197 static struct config_string ConfigureNamesString[] =
2200 {"archive_command", PGC_SIGHUP, WAL_SETTINGS,
2201 gettext_noop("Sets the shell command that will be called to archive a WAL file."),
2204 &XLogArchiveCommand,
2205 "", NULL, show_archive_command
2209 {"client_encoding", PGC_USERSET, CLIENT_CONN_LOCALE,
2210 gettext_noop("Sets the client's character set encoding."),
2212 GUC_IS_NAME | GUC_REPORT
2214 &client_encoding_string,
2215 "SQL_ASCII", assign_client_encoding, NULL
2219 {"log_line_prefix", PGC_SIGHUP, LOGGING_WHAT,
2220 gettext_noop("Controls information prefixed to each log line."),
2221 gettext_noop("If blank, no prefix is used.")
2228 {"log_timezone", PGC_SIGHUP, LOGGING_WHAT,
2229 gettext_noop("Sets the time zone to use in log messages."),
2232 &log_timezone_string,
2233 "UNKNOWN", assign_log_timezone, show_log_timezone
2237 {"DateStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
2238 gettext_noop("Sets the display format for date and time values."),
2239 gettext_noop("Also controls interpretation of ambiguous "
2241 GUC_LIST_INPUT | GUC_REPORT
2244 "ISO, MDY", assign_datestyle, NULL
2248 {"default_tablespace", PGC_USERSET, CLIENT_CONN_STATEMENT,
2249 gettext_noop("Sets the default tablespace to create tables and indexes in."),
2250 gettext_noop("An empty string selects the database's default tablespace."),
2253 &default_tablespace,
2254 "", assign_default_tablespace, NULL
2258 {"temp_tablespaces", PGC_USERSET, CLIENT_CONN_STATEMENT,
2259 gettext_noop("Sets the tablespace(s) to use for temporary tables and sort files."),
2261 GUC_LIST_INPUT | GUC_LIST_QUOTE
2264 "", assign_temp_tablespaces, NULL
2268 {"dynamic_library_path", PGC_SUSET, CLIENT_CONN_OTHER,
2269 gettext_noop("Sets the path for dynamically loadable modules."),
2270 gettext_noop("If a dynamically loadable module needs to be opened and "
2271 "the specified name does not have a directory component (i.e., the "
2272 "name does not contain a slash), the system will search this path for "
2273 "the specified file."),
2276 &Dynamic_library_path,
2277 "$libdir", NULL, NULL
2281 {"krb_server_keyfile", PGC_SIGHUP, CONN_AUTH_SECURITY,
2282 gettext_noop("Sets the location of the Kerberos server key file."),
2286 &pg_krb_server_keyfile,
2287 PG_KRB_SRVTAB, NULL, NULL
2291 {"krb_srvname", PGC_SIGHUP, CONN_AUTH_SECURITY,
2292 gettext_noop("Sets the name of the Kerberos service."),
2296 PG_KRB_SRVNAM, NULL, NULL
2300 {"bonjour_name", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2301 gettext_noop("Sets the Bonjour service name."),
2308 /* See main.c about why defaults for LC_foo are not all alike */
2311 {"lc_collate", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2312 gettext_noop("Shows the collation order locale."),
2314 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2321 {"lc_ctype", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2322 gettext_noop("Shows the character classification and case conversion locale."),
2324 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2331 {"lc_messages", PGC_SUSET, CLIENT_CONN_LOCALE,
2332 gettext_noop("Sets the language in which messages are displayed."),
2336 "", locale_messages_assign, NULL
2340 {"lc_monetary", PGC_USERSET, CLIENT_CONN_LOCALE,
2341 gettext_noop("Sets the locale for formatting monetary amounts."),
2345 "C", locale_monetary_assign, NULL
2349 {"lc_numeric", PGC_USERSET, CLIENT_CONN_LOCALE,
2350 gettext_noop("Sets the locale for formatting numbers."),
2354 "C", locale_numeric_assign, NULL
2358 {"lc_time", PGC_USERSET, CLIENT_CONN_LOCALE,
2359 gettext_noop("Sets the locale for formatting date and time values."),
2363 "C", locale_time_assign, NULL
2367 {"shared_preload_libraries", PGC_POSTMASTER, RESOURCES_KERNEL,
2368 gettext_noop("Lists shared libraries to preload into server."),
2370 GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
2372 &shared_preload_libraries_string,
2377 {"local_preload_libraries", PGC_BACKEND, CLIENT_CONN_OTHER,
2378 gettext_noop("Lists shared libraries to preload into each backend."),
2380 GUC_LIST_INPUT | GUC_LIST_QUOTE
2382 &local_preload_libraries_string,
2387 {"search_path", PGC_USERSET, CLIENT_CONN_STATEMENT,
2388 gettext_noop("Sets the schema search order for names that are not schema-qualified."),
2390 GUC_LIST_INPUT | GUC_LIST_QUOTE
2392 &namespace_search_path,
2393 "\"$user\",public", assign_search_path, NULL
2397 /* Can't be set in postgresql.conf */
2398 {"server_encoding", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2399 gettext_noop("Sets the server (database) character set encoding."),
2401 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2403 &server_encoding_string,
2404 "SQL_ASCII", NULL, NULL
2408 /* Can't be set in postgresql.conf */
2409 {"server_version", PGC_INTERNAL, PRESET_OPTIONS,
2410 gettext_noop("Shows the server version."),
2412 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2414 &server_version_string,
2415 PG_VERSION, NULL, NULL
2419 /* Not for general use --- used by SET ROLE */
2420 {"role", PGC_USERSET, UNGROUPED,
2421 gettext_noop("Sets the current role."),
2423 GUC_IS_NAME | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_NOT_WHILE_SEC_REST
2426 "none", assign_role, show_role
2430 /* Not for general use --- used by SET SESSION AUTHORIZATION */
2431 {"session_authorization", PGC_USERSET, UNGROUPED,
2432 gettext_noop("Sets the session user name."),
2434 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
2436 &session_authorization_string,
2437 NULL, assign_session_authorization, show_session_authorization
2441 {"log_destination", PGC_SIGHUP, LOGGING_WHERE,
2442 gettext_noop("Sets the destination for server log output."),
2443 gettext_noop("Valid values are combinations of \"stderr\", "
2444 "\"syslog\", \"csvlog\", and \"eventlog\", "
2445 "depending on the platform."),
2448 &log_destination_string,
2449 "stderr", assign_log_destination, NULL
2452 {"log_directory", PGC_SIGHUP, LOGGING_WHERE,
2453 gettext_noop("Sets the destination directory for log files."),
2454 gettext_noop("Can be specified as relative to the data directory "
2455 "or as absolute path."),
2459 "pg_log", assign_canonical_path, NULL
2462 {"log_filename", PGC_SIGHUP, LOGGING_WHERE,
2463 gettext_noop("Sets the file name pattern for log files."),
2468 "postgresql-%Y-%m-%d_%H%M%S.log", NULL, NULL
2473 {"syslog_ident", PGC_SIGHUP, LOGGING_WHERE,
2474 gettext_noop("Sets the program name used to identify PostgreSQL "
2475 "messages in syslog."),
2479 "postgres", assign_syslog_ident, NULL
2484 {"TimeZone", PGC_USERSET, CLIENT_CONN_LOCALE,
2485 gettext_noop("Sets the time zone for displaying and interpreting time stamps."),
2490 "UNKNOWN", assign_timezone, show_timezone
2493 {"timezone_abbreviations", PGC_USERSET, CLIENT_CONN_LOCALE,
2494 gettext_noop("Selects a file of time zone abbreviations."),
2497 &timezone_abbreviations_string,
2498 "UNKNOWN", assign_timezone_abbreviations, NULL
2502 {"transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
2503 gettext_noop("Sets the current transaction's isolation level."),
2505 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2507 &XactIsoLevel_string,
2508 NULL, assign_XactIsoLevel, show_XactIsoLevel
2512 {"unix_socket_group", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2513 gettext_noop("Sets the owning group of the Unix-domain socket."),
2514 gettext_noop("The owning user of the socket is always the user "
2515 "that starts the server.")
2522 {"unix_socket_directory", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2523 gettext_noop("Sets the directory where the Unix-domain socket will be created."),
2528 "", assign_canonical_path, NULL
2532 {"listen_addresses", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2533 gettext_noop("Sets the host name or IP address(es) to listen to."),
2538 "localhost", NULL, NULL
2542 {"custom_variable_classes", PGC_SIGHUP, CUSTOM_OPTIONS,
2543 gettext_noop("Sets the list of known custom variable classes."),
2545 GUC_LIST_INPUT | GUC_LIST_QUOTE
2547 &custom_variable_classes,
2548 NULL, assign_custom_variable_classes, NULL
2552 {"data_directory", PGC_POSTMASTER, FILE_LOCATIONS,
2553 gettext_noop("Sets the server's data directory."),
2562 {"config_file", PGC_POSTMASTER, FILE_LOCATIONS,
2563 gettext_noop("Sets the server's main configuration file."),
2565 GUC_DISALLOW_IN_FILE | GUC_SUPERUSER_ONLY
2572 {"hba_file", PGC_POSTMASTER, FILE_LOCATIONS,
2573 gettext_noop("Sets the server's \"hba\" configuration file."),
2582 {"ident_file", PGC_POSTMASTER, FILE_LOCATIONS,
2583 gettext_noop("Sets the server's \"ident\" configuration file."),
2592 {"external_pid_file", PGC_POSTMASTER, FILE_LOCATIONS,
2593 gettext_noop("Writes the postmaster PID to the specified file."),
2598 NULL, assign_canonical_path, NULL
2602 {"stats_temp_directory", PGC_SIGHUP, STATS_COLLECTOR,
2603 gettext_noop("Writes temporary statistics files to the specified directory."),
2607 &pgstat_temp_directory,
2608 "pg_stat_tmp", assign_pgstat_temp_directory, NULL
2612 {"default_text_search_config", PGC_USERSET, CLIENT_CONN_LOCALE,
2613 gettext_noop("Sets default text search configuration."),
2617 "pg_catalog.simple", assignTSCurrentConfig, NULL
2622 {"ssl_ciphers", PGC_POSTMASTER, CONN_AUTH_SECURITY,
2623 gettext_noop("Sets the list of allowed SSL ciphers."),
2628 "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH", NULL, NULL
2630 #endif /* USE_SSL */
2633 {"application_name", PGC_USERSET, LOGGING,
2634 gettext_noop("Sets the application name to be reported in statistics and logs."),
2636 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE
2639 "", assign_application_name, NULL
2642 /* End-of-list marker */
2644 {NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL
2649 static struct config_enum ConfigureNamesEnum[] =
2652 {"backslash_quote", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
2653 gettext_noop("Sets whether \"\\'\" is allowed in string literals."),
2657 BACKSLASH_QUOTE_SAFE_ENCODING, backslash_quote_options, NULL, NULL
2661 {"bytea_output", PGC_USERSET, CLIENT_CONN_STATEMENT,
2662 gettext_noop("Sets the output format for bytea."),
2666 BYTEA_OUTPUT_HEX, bytea_output_options, NULL, NULL
2670 {"client_min_messages", PGC_USERSET, LOGGING_WHEN,
2671 gettext_noop("Sets the message levels that are sent to the client."),
2672 gettext_noop("Each level includes all the levels that follow it. The later"
2673 " the level, the fewer messages are sent.")
2675 &client_min_messages,
2676 NOTICE, client_message_level_options, NULL, NULL
2680 {"constraint_exclusion", PGC_USERSET, QUERY_TUNING_OTHER,
2681 gettext_noop("Enables the planner to use constraints to optimize queries."),
2682 gettext_noop("Table scans will be skipped if their constraints"
2683 " guarantee that no rows match the query.")
2685 &constraint_exclusion,
2686 CONSTRAINT_EXCLUSION_PARTITION, constraint_exclusion_options,
2691 {"default_transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
2692 gettext_noop("Sets the transaction isolation level of each new transaction."),
2695 &DefaultXactIsoLevel,
2696 XACT_READ_COMMITTED, isolation_level_options, NULL, NULL
2700 {"IntervalStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
2701 gettext_noop("Sets the display format for interval values."),
2706 INTSTYLE_POSTGRES, intervalstyle_options, NULL, NULL
2710 {"log_error_verbosity", PGC_SUSET, LOGGING_WHAT,
2711 gettext_noop("Sets the verbosity of logged messages."),
2714 &Log_error_verbosity,
2715 PGERROR_DEFAULT, log_error_verbosity_options, NULL, NULL
2719 {"log_min_messages", PGC_SUSET, LOGGING_WHEN,
2720 gettext_noop("Sets the message levels that are logged."),
2721 gettext_noop("Each level includes all the levels that follow it. The later"
2722 " the level, the fewer messages are sent.")
2725 WARNING, server_message_level_options, NULL, NULL
2729 {"log_min_error_statement", PGC_SUSET, LOGGING_WHEN,
2730 gettext_noop("Causes all statements generating error at or above this level to be logged."),
2731 gettext_noop("Each level includes all the levels that follow it. The later"
2732 " the level, the fewer messages are sent.")
2734 &log_min_error_statement,
2735 ERROR, server_message_level_options, NULL, NULL
2739 {"log_statement", PGC_SUSET, LOGGING_WHAT,
2740 gettext_noop("Sets the type of statements logged."),
2744 LOGSTMT_NONE, log_statement_options, NULL, NULL
2749 {"syslog_facility", PGC_SIGHUP, LOGGING_WHERE,
2750 gettext_noop("Sets the syslog \"facility\" to be used when syslog enabled."),
2754 LOG_LOCAL0, syslog_facility_options, assign_syslog_facility, NULL
2759 {"session_replication_role", PGC_SUSET, CLIENT_CONN_STATEMENT,
2760 gettext_noop("Sets the session's behavior for triggers and rewrite rules."),
2763 &SessionReplicationRole,
2764 SESSION_REPLICATION_ROLE_ORIGIN, session_replication_role_options,
2765 assign_session_replication_role, NULL
2769 {"trace_recovery_messages", PGC_SUSET, LOGGING_WHEN,
2770 gettext_noop("Sets the message levels that are logged during recovery."),
2771 gettext_noop("Each level includes all the levels that follow it. The later"
2772 " the level, the fewer messages are sent.")
2774 &trace_recovery_messages,
2775 DEBUG1, server_message_level_options, NULL, NULL
2779 {"track_functions", PGC_SUSET, STATS_COLLECTOR,
2780 gettext_noop("Collects function-level statistics on database activity."),
2783 &pgstat_track_functions,
2784 TRACK_FUNC_OFF, track_function_options, NULL, NULL
2788 {"wal_sync_method", PGC_SIGHUP, WAL_SETTINGS,
2789 gettext_noop("Selects the method used for forcing WAL updates to disk."),
2793 DEFAULT_SYNC_METHOD, sync_method_options,
2794 assign_xlog_sync_method, NULL
2798 {"xmlbinary", PGC_USERSET, CLIENT_CONN_STATEMENT,
2799 gettext_noop("Sets how binary values are to be encoded in XML."),
2803 XMLBINARY_BASE64, xmlbinary_options, NULL, NULL
2807 {"xmloption", PGC_USERSET, CLIENT_CONN_STATEMENT,
2808 gettext_noop("Sets whether XML data in implicit parsing and serialization "
2809 "operations is to be considered as documents or content fragments."),
2813 XMLOPTION_CONTENT, xmloption_options, NULL, NULL
2817 /* End-of-list marker */
2819 {NULL, 0, 0, NULL, NULL}, NULL, 0, NULL, NULL, NULL
2823 /******** end of options list ********/
2827 * To allow continued support of obsolete names for GUC variables, we apply
2828 * the following mappings to any unrecognized name. Note that an old name
2829 * should be mapped to a new one only if the new variable has very similar
2830 * semantics to the old.
2832 static const char *const map_old_guc_names[] = {
2833 "sort_mem", "work_mem",
2834 "vacuum_mem", "maintenance_work_mem",
2840 * Actual lookup of variables is done through this single, sorted array.
2842 static struct config_generic **guc_variables;
2844 /* Current number of variables contained in the vector */
2845 static int num_guc_variables;
2847 /* Vector capacity */
2848 static int size_guc_variables;
2851 static bool guc_dirty; /* TRUE if need to do commit/abort work */
2853 static bool reporting_enabled; /* TRUE to enable GUC_REPORT */
2855 static int GUCNestLevel = 0; /* 1 when in main transaction */
2858 static int guc_var_compare(const void *a, const void *b);
2859 static int guc_name_compare(const char *namea, const char *nameb);
2860 static void InitializeOneGUCOption(struct config_generic * gconf);
2861 static void push_old_value(struct config_generic * gconf, GucAction action);
2862 static void ReportGUCOption(struct config_generic * record);
2863 static void ShowGUCConfigOption(const char *name, DestReceiver *dest);
2864 static void ShowAllGUCConfig(DestReceiver *dest);
2865 static char *_ShowOption(struct config_generic * record, bool use_units);
2866 static bool is_newvalue_equal(struct config_generic * record, const char *newvalue);
2870 * Some infrastructure for checking malloc/strdup/realloc calls
2873 guc_malloc(int elevel, size_t size)
2877 data = malloc(size);
2880 (errcode(ERRCODE_OUT_OF_MEMORY),
2881 errmsg("out of memory")));
2886 guc_realloc(int elevel, void *old, size_t size)
2890 data = realloc(old, size);
2893 (errcode(ERRCODE_OUT_OF_MEMORY),
2894 errmsg("out of memory")));
2899 guc_strdup(int elevel, const char *src)
2906 (errcode(ERRCODE_OUT_OF_MEMORY),
2907 errmsg("out of memory")));
2913 * Support for assigning to a field of a string GUC item. Free the prior
2914 * value if it's not referenced anywhere else in the item (including stacked
2918 set_string_field(struct config_string * conf, char **field, char *newval)
2920 char *oldval = *field;
2923 /* Do the assignment */
2926 /* Exit if any duplicate references, or if old value was NULL anyway */
2927 if (oldval == NULL ||
2928 oldval == *(conf->variable) ||
2929 oldval == conf->reset_val ||
2930 oldval == conf->boot_val)
2932 for (stack = conf->gen.stack; stack; stack = stack->prev)
2934 if (oldval == stack->prior.stringval ||
2935 oldval == stack->masked.stringval)
2939 /* Not used anymore, so free it */
2944 * Detect whether strval is referenced anywhere in a GUC string item
2947 string_field_used(struct config_string * conf, char *strval)
2951 if (strval == *(conf->variable) ||
2952 strval == conf->reset_val ||
2953 strval == conf->boot_val)
2955 for (stack = conf->gen.stack; stack; stack = stack->prev)
2957 if (strval == stack->prior.stringval ||
2958 strval == stack->masked.stringval)
2965 * Support for copying a variable's active value into a stack entry
2968 set_stack_value(struct config_generic * gconf, union config_var_value * val)
2970 switch (gconf->vartype)
2974 *((struct config_bool *) gconf)->variable;
2978 *((struct config_int *) gconf)->variable;
2982 *((struct config_real *) gconf)->variable;
2985 /* we assume stringval is NULL if not valid */
2986 set_string_field((struct config_string *) gconf,
2988 *((struct config_string *) gconf)->variable);
2992 *((struct config_enum *) gconf)->variable;
2998 * Support for discarding a no-longer-needed value in a stack entry
3001 discard_stack_value(struct config_generic * gconf, union config_var_value * val)
3003 switch (gconf->vartype)
3009 /* no need to do anything */
3012 set_string_field((struct config_string *) gconf,
3021 * Fetch the sorted array pointer (exported for help_config.c's use ONLY)
3023 struct config_generic **
3024 get_guc_variables(void)
3026 return guc_variables;
3031 * Build the sorted array. This is split out so that it could be
3032 * re-executed after startup (eg, we could allow loadable modules to
3033 * add vars, and then we'd need to re-sort).
3036 build_guc_variables(void)
3040 struct config_generic **guc_vars;
3043 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
3045 struct config_bool *conf = &ConfigureNamesBool[i];
3047 /* Rather than requiring vartype to be filled in by hand, do this: */
3048 conf->gen.vartype = PGC_BOOL;
3052 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
3054 struct config_int *conf = &ConfigureNamesInt[i];
3056 conf->gen.vartype = PGC_INT;
3060 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
3062 struct config_real *conf = &ConfigureNamesReal[i];
3064 conf->gen.vartype = PGC_REAL;
3068 for (i = 0; ConfigureNamesString[i].gen.name; i++)
3070 struct config_string *conf = &ConfigureNamesString[i];
3072 conf->gen.vartype = PGC_STRING;
3076 for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
3078 struct config_enum *conf = &ConfigureNamesEnum[i];
3080 conf->gen.vartype = PGC_ENUM;
3085 * Create table with 20% slack
3087 size_vars = num_vars + num_vars / 4;
3089 guc_vars = (struct config_generic **)
3090 guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
3094 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
3095 guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
3097 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
3098 guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
3100 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
3101 guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
3103 for (i = 0; ConfigureNamesString[i].gen.name; i++)
3104 guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
3106 for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
3107 guc_vars[num_vars++] = &ConfigureNamesEnum[i].gen;
3110 free(guc_variables);
3111 guc_variables = guc_vars;
3112 num_guc_variables = num_vars;
3113 size_guc_variables = size_vars;
3114 qsort((void *) guc_variables, num_guc_variables,
3115 sizeof(struct config_generic *), guc_var_compare);
3119 * Add a new GUC variable to the list of known variables. The
3120 * list is expanded if needed.
3123 add_guc_variable(struct config_generic * var, int elevel)
3125 if (num_guc_variables + 1 >= size_guc_variables)
3128 * Increase the vector by 25%
3130 int size_vars = size_guc_variables + size_guc_variables / 4;
3131 struct config_generic **guc_vars;
3136 guc_vars = (struct config_generic **)
3137 guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
3141 guc_vars = (struct config_generic **)
3142 guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
3145 if (guc_vars == NULL)
3146 return false; /* out of memory */
3148 guc_variables = guc_vars;
3149 size_guc_variables = size_vars;
3151 guc_variables[num_guc_variables++] = var;
3152 qsort((void *) guc_variables, num_guc_variables,
3153 sizeof(struct config_generic *), guc_var_compare);
3158 * Create and add a placeholder variable. It's presumed to belong
3159 * to a valid custom variable class at this point.
3161 static struct config_generic *
3162 add_placeholder_variable(const char *name, int elevel)
3164 size_t sz = sizeof(struct config_string) + sizeof(char *);
3165 struct config_string *var;
3166 struct config_generic *gen;
3168 var = (struct config_string *) guc_malloc(elevel, sz);
3174 gen->name = guc_strdup(elevel, name);
3175 if (gen->name == NULL)
3181 gen->context = PGC_USERSET;
3182 gen->group = CUSTOM_OPTIONS;
3183 gen->short_desc = "GUC placeholder variable";
3184 gen->flags = GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_CUSTOM_PLACEHOLDER;
3185 gen->vartype = PGC_STRING;
3188 * The char* is allocated at the end of the struct since we have no
3189 * 'static' place to point to. Note that the current value, as well as
3190 * the boot and reset values, start out NULL.
3192 var->variable = (char **) (var + 1);
3194 if (!add_guc_variable((struct config_generic *) var, elevel))
3196 free((void *) gen->name);
3205 * Detect whether the portion of "name" before dotPos matches any custom
3206 * variable class name listed in custom_var_classes. The latter must be
3207 * formatted the way that assign_custom_variable_classes does it, ie,
3208 * no whitespace. NULL is valid for custom_var_classes.
3211 is_custom_class(const char *name, int dotPos, const char *custom_var_classes)
3213 bool result = false;
3214 const char *ccs = custom_var_classes;
3218 const char *start = ccs;
3224 if (c == '\0' || c == ',')
3226 if (dotPos == ccs - start && strncmp(start, name, dotPos) == 0)
3241 * Look up option NAME. If it exists, return a pointer to its record,
3242 * else return NULL. If create_placeholders is TRUE, we'll create a
3243 * placeholder record for a valid-looking custom variable name.
3245 static struct config_generic *
3246 find_option(const char *name, bool create_placeholders, int elevel)
3248 const char **key = &name;
3249 struct config_generic **res;
3255 * By equating const char ** with struct config_generic *, we are assuming
3256 * the name field is first in config_generic.
3258 res = (struct config_generic **) bsearch((void *) &key,
3259 (void *) guc_variables,
3261 sizeof(struct config_generic *),
3267 * See if the name is an obsolete name for a variable. We assume that the
3268 * set of supported old names is short enough that a brute-force search is
3271 for (i = 0; map_old_guc_names[i] != NULL; i += 2)
3273 if (guc_name_compare(name, map_old_guc_names[i]) == 0)
3274 return find_option(map_old_guc_names[i + 1], false, elevel);
3277 if (create_placeholders)
3280 * Check if the name is qualified, and if so, check if the qualifier
3281 * matches any custom variable class. If so, add a placeholder.
3283 const char *dot = strchr(name, GUC_QUALIFIER_SEPARATOR);
3286 is_custom_class(name, dot - name, custom_variable_classes))
3287 return add_placeholder_variable(name, elevel);
3296 * comparator for qsorting and bsearching guc_variables array
3299 guc_var_compare(const void *a, const void *b)
3301 struct config_generic *confa = *(struct config_generic **) a;
3302 struct config_generic *confb = *(struct config_generic **) b;
3304 return guc_name_compare(confa->name, confb->name);
3308 * the bare comparison function for GUC names
3311 guc_name_compare(const char *namea, const char *nameb)
3314 * The temptation to use strcasecmp() here must be resisted, because the
3315 * array ordering has to remain stable across setlocale() calls. So, build
3316 * our own with a simple ASCII-only downcasing.
3318 while (*namea && *nameb)
3320 char cha = *namea++;
3321 char chb = *nameb++;
3323 if (cha >= 'A' && cha <= 'Z')
3325 if (chb >= 'A' && chb <= 'Z')
3331 return 1; /* a is longer */
3333 return -1; /* b is longer */
3339 * Initialize GUC options during program startup.
3341 * Note that we cannot read the config file yet, since we have not yet
3342 * processed command-line switches.
3345 InitializeGUCOptions(void)
3352 * Before log_line_prefix could possibly receive a nonempty setting, make
3353 * sure that timezone processing is minimally alive (see elog.c).
3355 pg_timezone_pre_initialize();
3358 * Build sorted array of all GUC variables.
3360 build_guc_variables();
3363 * Load all variables with their compiled-in defaults, and initialize
3364 * status fields as needed.
3366 for (i = 0; i < num_guc_variables; i++)
3368 InitializeOneGUCOption(guc_variables[i]);
3373 reporting_enabled = false;
3376 * Prevent any attempt to override the transaction modes from
3377 * non-interactive sources.
3379 SetConfigOption("transaction_isolation", "default",
3380 PGC_POSTMASTER, PGC_S_OVERRIDE);
3381 SetConfigOption("transaction_read_only", "no",
3382 PGC_POSTMASTER, PGC_S_OVERRIDE);
3385 * For historical reasons, some GUC parameters can receive defaults from
3386 * environment variables. Process those settings. NB: if you add or
3387 * remove anything here, see also ProcessConfigFile().
3390 env = getenv("PGPORT");
3392 SetConfigOption("port", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3394 env = getenv("PGDATESTYLE");
3396 SetConfigOption("datestyle", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3398 env = getenv("PGCLIENTENCODING");
3400 SetConfigOption("client_encoding", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3403 * rlimit isn't exactly an "environment variable", but it behaves about
3404 * the same. If we can identify the platform stack depth rlimit, increase
3405 * default stack depth setting up to whatever is safe (but at most 2MB).
3407 stack_rlimit = get_stack_depth_rlimit();
3408 if (stack_rlimit > 0)
3410 int new_limit = (stack_rlimit - STACK_DEPTH_SLOP) / 1024L;
3412 if (new_limit > 100)
3416 new_limit = Min(new_limit, 2048);
3417 sprintf(limbuf, "%d", new_limit);
3418 SetConfigOption("max_stack_depth", limbuf,
3419 PGC_POSTMASTER, PGC_S_ENV_VAR);
3425 * Initialize one GUC option variable to its compiled-in default.
3428 InitializeOneGUCOption(struct config_generic * gconf)
3431 gconf->reset_source = PGC_S_DEFAULT;
3432 gconf->source = PGC_S_DEFAULT;
3433 gconf->stack = NULL;
3434 gconf->sourcefile = NULL;
3435 gconf->sourceline = 0;
3437 switch (gconf->vartype)
3441 struct config_bool *conf = (struct config_bool *) gconf;
3443 if (conf->assign_hook)
3444 if (!(*conf->assign_hook) (conf->boot_val, true,
3446 elog(FATAL, "failed to initialize %s to %d",
3447 conf->gen.name, (int) conf->boot_val);
3448 *conf->variable = conf->reset_val = conf->boot_val;
3453 struct config_int *conf = (struct config_int *) gconf;
3455 Assert(conf->boot_val >= conf->min);
3456 Assert(conf->boot_val <= conf->max);
3457 if (conf->assign_hook)
3458 if (!(*conf->assign_hook) (conf->boot_val, true,
3460 elog(FATAL, "failed to initialize %s to %d",
3461 conf->gen.name, conf->boot_val);
3462 *conf->variable = conf->reset_val = conf->boot_val;
3467 struct config_real *conf = (struct config_real *) gconf;
3469 Assert(conf->boot_val >= conf->min);
3470 Assert(conf->boot_val <= conf->max);
3471 if (conf->assign_hook)
3472 if (!(*conf->assign_hook) (conf->boot_val, true,
3474 elog(FATAL, "failed to initialize %s to %g",
3475 conf->gen.name, conf->boot_val);
3476 *conf->variable = conf->reset_val = conf->boot_val;
3481 struct config_string *conf = (struct config_string *) gconf;
3484 *conf->variable = NULL;
3485 conf->reset_val = NULL;
3487 if (conf->boot_val == NULL)
3489 /* leave the value NULL, do not call assign hook */
3493 str = guc_strdup(FATAL, conf->boot_val);
3494 conf->reset_val = str;
3496 if (conf->assign_hook)
3500 newstr = (*conf->assign_hook) (str, true,
3504 elog(FATAL, "failed to initialize %s to \"%s\"",
3505 conf->gen.name, str);
3507 else if (newstr != str)
3512 * See notes in set_config_option about casting
3514 str = (char *) newstr;
3515 conf->reset_val = str;
3518 *conf->variable = str;
3523 struct config_enum *conf = (struct config_enum *) gconf;
3525 if (conf->assign_hook)
3526 if (!(*conf->assign_hook) (conf->boot_val, true,
3528 elog(FATAL, "failed to initialize %s to %s",
3530 config_enum_lookup_by_value(conf, conf->boot_val));
3531 *conf->variable = conf->reset_val = conf->boot_val;
3539 * Select the configuration files and data directory to be used, and
3540 * do the initial read of postgresql.conf.
3542 * This is called after processing command-line switches.
3543 * userDoption is the -D switch value if any (NULL if unspecified).
3544 * progname is just for use in error messages.
3546 * Returns true on success; on failure, prints a suitable error message
3547 * to stderr and returns false.
3550 SelectConfigFiles(const char *userDoption, const char *progname)
3554 struct stat stat_buf;
3556 /* configdir is -D option, or $PGDATA if no -D */
3558 configdir = make_absolute_path(userDoption);
3560 configdir = make_absolute_path(getenv("PGDATA"));
3563 * Find the configuration file: if config_file was specified on the
3564 * command line, use it, else use configdir/postgresql.conf. In any case
3565 * ensure the result is an absolute path, so that it will be interpreted
3566 * the same way by future backends.
3569 fname = make_absolute_path(ConfigFileName);
3572 fname = guc_malloc(FATAL,
3573 strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
3574 sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
3578 write_stderr("%s does not know where to find the server configuration file.\n"
3579 "You must specify the --config-file or -D invocation "
3580 "option or set the PGDATA environment variable.\n",
3586 * Set the ConfigFileName GUC variable to its final value, ensuring that
3587 * it can't be overridden later.
3589 SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
3593 * Now read the config file for the first time.
3595 if (stat(ConfigFileName, &stat_buf) != 0)
3597 write_stderr("%s cannot access the server configuration file \"%s\": %s\n",
3598 progname, ConfigFileName, strerror(errno));
3602 ProcessConfigFile(PGC_POSTMASTER);
3605 * If the data_directory GUC variable has been set, use that as DataDir;
3606 * otherwise use configdir if set; else punt.
3608 * Note: SetDataDir will copy and absolute-ize its argument, so we don't
3612 SetDataDir(data_directory);
3614 SetDataDir(configdir);
3617 write_stderr("%s does not know where to find the database system data.\n"
3618 "This can be specified as \"data_directory\" in \"%s\", "
3619 "or by the -D invocation option, or by the "
3620 "PGDATA environment variable.\n",
3621 progname, ConfigFileName);
3626 * Reflect the final DataDir value back into the data_directory GUC var.
3627 * (If you are wondering why we don't just make them a single variable,
3628 * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
3629 * child backends specially. XXX is that still true? Given that we now
3630 * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
3631 * DataDir in advance.)
3633 SetConfigOption("data_directory", DataDir, PGC_POSTMASTER, PGC_S_OVERRIDE);
3636 * Figure out where pg_hba.conf is, and make sure the path is absolute.
3639 fname = make_absolute_path(HbaFileName);
3642 fname = guc_malloc(FATAL,
3643 strlen(configdir) + strlen(HBA_FILENAME) + 2);
3644 sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
3648 write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
3649 "This can be specified as \"hba_file\" in \"%s\", "
3650 "or by the -D invocation option, or by the "
3651 "PGDATA environment variable.\n",
3652 progname, ConfigFileName);
3655 SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
3659 * Likewise for pg_ident.conf.
3662 fname = make_absolute_path(IdentFileName);
3665 fname = guc_malloc(FATAL,
3666 strlen(configdir) + strlen(IDENT_FILENAME) + 2);
3667 sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
3671 write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
3672 "This can be specified as \"ident_file\" in \"%s\", "
3673 "or by the -D invocation option, or by the "
3674 "PGDATA environment variable.\n",
3675 progname, ConfigFileName);
3678 SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
3688 * Reset all options to their saved default values (implements RESET ALL)
3691 ResetAllOptions(void)
3695 for (i = 0; i < num_guc_variables; i++)
3697 struct config_generic *gconf = guc_variables[i];
3699 /* Don't reset non-SET-able values */
3700 if (gconf->context != PGC_SUSET &&
3701 gconf->context != PGC_USERSET)
3703 /* Don't reset if special exclusion from RESET ALL */
3704 if (gconf->flags & GUC_NO_RESET_ALL)
3706 /* No need to reset if wasn't SET */
3707 if (gconf->source <= PGC_S_OVERRIDE)
3710 /* Save old value to support transaction abort */
3711 push_old_value(gconf, GUC_ACTION_SET);
3713 switch (gconf->vartype)
3717 struct config_bool *conf = (struct config_bool *) gconf;
3719 if (conf->assign_hook)
3720 if (!(*conf->assign_hook) (conf->reset_val, true,
3722 elog(ERROR, "failed to reset %s to %d",
3723 conf->gen.name, (int) conf->reset_val);
3724 *conf->variable = conf->reset_val;
3729 struct config_int *conf = (struct config_int *) gconf;
3731 if (conf->assign_hook)
3732 if (!(*conf->assign_hook) (conf->reset_val, true,
3734 elog(ERROR, "failed to reset %s to %d",
3735 conf->gen.name, conf->reset_val);
3736 *conf->variable = conf->reset_val;
3741 struct config_real *conf = (struct config_real *) gconf;
3743 if (conf->assign_hook)
3744 if (!(*conf->assign_hook) (conf->reset_val, true,
3746 elog(ERROR, "failed to reset %s to %g",
3747 conf->gen.name, conf->reset_val);
3748 *conf->variable = conf->reset_val;
3753 struct config_string *conf = (struct config_string *) gconf;
3756 /* We need not strdup here */
3757 str = conf->reset_val;
3759 if (conf->assign_hook && str)
3763 newstr = (*conf->assign_hook) (str, true,
3766 elog(ERROR, "failed to reset %s to \"%s\"",
3767 conf->gen.name, str);
3768 else if (newstr != str)
3771 * See notes in set_config_option about casting
3773 str = (char *) newstr;
3777 set_string_field(conf, conf->variable, str);
3782 struct config_enum *conf = (struct config_enum *) gconf;
3784 if (conf->assign_hook)
3785 if (!(*conf->assign_hook) (conf->reset_val, true,
3787 elog(ERROR, "failed to reset %s to %s",
3789 config_enum_lookup_by_value(conf, conf->reset_val));
3790 *conf->variable = conf->reset_val;
3795 gconf->source = gconf->reset_source;
3797 if (gconf->flags & GUC_REPORT)
3798 ReportGUCOption(gconf);
3805 * Push previous state during transactional assignment to a GUC variable.
3808 push_old_value(struct config_generic * gconf, GucAction action)
3812 /* If we're not inside a nest level, do nothing */
3813 if (GUCNestLevel == 0)
3816 /* Do we already have a stack entry of the current nest level? */
3817 stack = gconf->stack;
3818 if (stack && stack->nest_level >= GUCNestLevel)
3820 /* Yes, so adjust its state if necessary */
3821 Assert(stack->nest_level == GUCNestLevel);
3824 case GUC_ACTION_SET:
3825 /* SET overrides any prior action at same nest level */
3826 if (stack->state == GUC_SET_LOCAL)
3828 /* must discard old masked value */
3829 discard_stack_value(gconf, &stack->masked);
3831 stack->state = GUC_SET;
3833 case GUC_ACTION_LOCAL:
3834 if (stack->state == GUC_SET)
3836 /* SET followed by SET LOCAL, remember SET's value */
3837 set_stack_value(gconf, &stack->masked);
3838 stack->state = GUC_SET_LOCAL;
3840 /* in all other cases, no change to stack entry */
3842 case GUC_ACTION_SAVE:
3843 /* Could only have a prior SAVE of same variable */
3844 Assert(stack->state == GUC_SAVE);
3847 Assert(guc_dirty); /* must be set already */
3852 * Push a new stack entry
3854 * We keep all the stack entries in TopTransactionContext for simplicity.
3856 stack = (GucStack *) MemoryContextAllocZero(TopTransactionContext,
3859 stack->prev = gconf->stack;
3860 stack->nest_level = GUCNestLevel;
3863 case GUC_ACTION_SET:
3864 stack->state = GUC_SET;
3866 case GUC_ACTION_LOCAL:
3867 stack->state = GUC_LOCAL;
3869 case GUC_ACTION_SAVE:
3870 stack->state = GUC_SAVE;
3873 stack->source = gconf->source;
3874 set_stack_value(gconf, &stack->prior);
3876 gconf->stack = stack;
3878 /* Ensure we remember to pop at end of xact */
3884 * Do GUC processing at main transaction start.
3890 * The nest level should be 0 between transactions; if it isn't, somebody
3891 * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
3892 * throw a warning but make no other effort to clean up.
3894 if (GUCNestLevel != 0)
3895 elog(WARNING, "GUC nest level = %d at transaction start",
3901 * Enter a new nesting level for GUC values. This is called at subtransaction
3902 * start and when entering a function that has proconfig settings. NOTE that
3903 * we must not risk error here, else subtransaction start will be unhappy.
3906 NewGUCNestLevel(void)
3908 return ++GUCNestLevel;
3912 * Do GUC processing at transaction or subtransaction commit or abort, or
3913 * when exiting a function that has proconfig settings. (The name is thus
3914 * a bit of a misnomer; perhaps it should be ExitGUCNestLevel or some such.)
3915 * During abort, we discard all GUC settings that were applied at nesting
3916 * levels >= nestLevel. nestLevel == 1 corresponds to the main transaction.
3919 AtEOXact_GUC(bool isCommit, int nestLevel)
3925 * Note: it's possible to get here with GUCNestLevel == nestLevel-1 during
3926 * abort, if there is a failure during transaction start before
3927 * AtStart_GUC is called.
3929 Assert(nestLevel > 0 &&
3930 (nestLevel <= GUCNestLevel ||
3931 (nestLevel == GUCNestLevel + 1 && !isCommit)));
3933 /* Quick exit if nothing's changed in this transaction */
3936 GUCNestLevel = nestLevel - 1;
3940 still_dirty = false;
3941 for (i = 0; i < num_guc_variables; i++)
3943 struct config_generic *gconf = guc_variables[i];
3947 * Process and pop each stack entry within the nest level. To
3948 * simplify fmgr_security_definer(), we allow failure exit from a
3949 * function-with-SET-options to be recovered at the surrounding
3950 * transaction or subtransaction abort; so there could be more than
3951 * one stack entry to pop.
3953 while ((stack = gconf->stack) != NULL &&
3954 stack->nest_level >= nestLevel)
3956 GucStack *prev = stack->prev;
3957 bool restorePrior = false;
3958 bool restoreMasked = false;
3962 * In this next bit, if we don't set either restorePrior or
3963 * restoreMasked, we must "discard" any unwanted fields of the
3964 * stack entries to avoid leaking memory. If we do set one of
3965 * those flags, unused fields will be cleaned up after restoring.
3967 if (!isCommit) /* if abort, always restore prior value */
3968 restorePrior = true;
3969 else if (stack->state == GUC_SAVE)
3970 restorePrior = true;
3971 else if (stack->nest_level == 1)
3973 /* transaction commit */
3974 if (stack->state == GUC_SET_LOCAL)
3975 restoreMasked = true;
3976 else if (stack->state == GUC_SET)
3978 /* we keep the current active value */
3979 discard_stack_value(gconf, &stack->prior);
3981 else /* must be GUC_LOCAL */
3982 restorePrior = true;
3984 else if (prev == NULL ||
3985 prev->nest_level < stack->nest_level - 1)
3987 /* decrement entry's level and do not pop it */
3988 stack->nest_level--;
3994 * We have to merge this stack entry into prev. See README for
3995 * discussion of this bit.
3997 switch (stack->state)
4000 Assert(false); /* can't get here */
4003 /* next level always becomes SET */
4004 discard_stack_value(gconf, &stack->prior);
4005 if (prev->state == GUC_SET_LOCAL)
4006 discard_stack_value(gconf, &prev->masked);
4007 prev->state = GUC_SET;
4011 if (prev->state == GUC_SET)
4013 /* LOCAL migrates down */
4014 prev->masked = stack->prior;
4015 prev->state = GUC_SET_LOCAL;
4019 /* else just forget this stack level */
4020 discard_stack_value(gconf, &stack->prior);
4025 /* prior state at this level no longer wanted */
4026 discard_stack_value(gconf, &stack->prior);
4027 /* copy down the masked state */
4028 if (prev->state == GUC_SET_LOCAL)
4029 discard_stack_value(gconf, &prev->masked);
4030 prev->masked = stack->masked;
4031 prev->state = GUC_SET_LOCAL;
4038 if (restorePrior || restoreMasked)
4040 /* Perform appropriate restoration of the stacked value */
4041 union config_var_value newvalue;
4042 GucSource newsource;
4046 newvalue = stack->masked;
4047 newsource = PGC_S_SESSION;
4051 newvalue = stack->prior;
4052 newsource = stack->source;
4055 switch (gconf->vartype)
4059 struct config_bool *conf = (struct config_bool *) gconf;
4060 bool newval = newvalue.boolval;
4062 if (*conf->variable != newval)
4064 if (conf->assign_hook)
4065 if (!(*conf->assign_hook) (newval,
4066 true, PGC_S_OVERRIDE))
4067 elog(LOG, "failed to commit %s as %d",
4068 conf->gen.name, (int) newval);
4069 *conf->variable = newval;
4076 struct config_int *conf = (struct config_int *) gconf;
4077 int newval = newvalue.intval;
4079 if (*conf->variable != newval)
4081 if (conf->assign_hook)
4082 if (!(*conf->assign_hook) (newval,
4083 true, PGC_S_OVERRIDE))
4084 elog(LOG, "failed to commit %s as %d",
4085 conf->gen.name, newval);
4086 *conf->variable = newval;
4093 struct config_real *conf = (struct config_real *) gconf;
4094 double newval = newvalue.realval;
4096 if (*conf->variable != newval)
4098 if (conf->assign_hook)
4099 if (!(*conf->assign_hook) (newval,
4100 true, PGC_S_OVERRIDE))
4101 elog(LOG, "failed to commit %s as %g",
4102 conf->gen.name, newval);
4103 *conf->variable = newval;
4110 struct config_string *conf = (struct config_string *) gconf;
4111 char *newval = newvalue.stringval;
4113 if (*conf->variable != newval)
4115 if (conf->assign_hook && newval)
4119 newstr = (*conf->assign_hook) (newval, true,
4122 elog(LOG, "failed to commit %s as \"%s\"",
4123 conf->gen.name, newval);
4124 else if (newstr != newval)
4127 * If newval should now be freed,
4128 * it'll be taken care of below.
4130 * See notes in set_config_option
4133 newval = (char *) newstr;
4137 set_string_field(conf, conf->variable, newval);
4142 * Release stacked values if not used anymore. We
4143 * could use discard_stack_value() here, but since
4144 * we have type-specific code anyway, might as
4147 set_string_field(conf, &stack->prior.stringval, NULL);
4148 set_string_field(conf, &stack->masked.stringval, NULL);
4153 struct config_enum *conf = (struct config_enum *) gconf;
4154 int newval = newvalue.enumval;
4156 if (*conf->variable != newval)
4158 if (conf->assign_hook)
4159 if (!(*conf->assign_hook) (newval,
4160 true, PGC_S_OVERRIDE))
4161 elog(LOG, "failed to commit %s as %s",
4163 config_enum_lookup_by_value(conf, newval));
4164 *conf->variable = newval;
4171 gconf->source = newsource;
4174 /* Finish popping the state stack */
4175 gconf->stack = prev;
4178 /* Report new value if we changed it */
4179 if (changed && (gconf->flags & GUC_REPORT))
4180 ReportGUCOption(gconf);
4181 } /* end of stack-popping loop */
4187 /* If there are no remaining stack entries, we can reset guc_dirty */
4188 guc_dirty = still_dirty;
4190 /* Update nesting level */
4191 GUCNestLevel = nestLevel - 1;
4196 * Start up automatic reporting of changes to variables marked GUC_REPORT.
4197 * This is executed at completion of backend startup.
4200 BeginReportingGUCOptions(void)
4205 * Don't do anything unless talking to an interactive frontend of protocol
4208 if (whereToSendOutput != DestRemote ||
4209 PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
4212 reporting_enabled = true;
4214 /* Transmit initial values of interesting variables */
4215 for (i = 0; i < num_guc_variables; i++)
4217 struct config_generic *conf = guc_variables[i];
4219 if (conf->flags & GUC_REPORT)
4220 ReportGUCOption(conf);
4225 * ReportGUCOption: if appropriate, transmit option value to frontend
4228 ReportGUCOption(struct config_generic * record)
4230 if (reporting_enabled && (record->flags & GUC_REPORT))
4232 char *val = _ShowOption(record, false);
4233 StringInfoData msgbuf;
4235 pq_beginmessage(&msgbuf, 'S');
4236 pq_sendstring(&msgbuf, record->name);
4237 pq_sendstring(&msgbuf, val);
4238 pq_endmessage(&msgbuf);
4245 * Try to parse value as an integer. The accepted formats are the
4246 * usual decimal, octal, or hexadecimal formats, optionally followed by
4247 * a unit name if "flags" indicates a unit is allowed.
4249 * If the string parses okay, return true, else false.
4250 * If okay and result is not NULL, return the value in *result.
4251 * If not okay and hintmsg is not NULL, *hintmsg is set to a suitable
4252 * HINT message, or NULL if no hint provided.
4255 parse_int(const char *value, int *result, int flags, const char **hintmsg)
4260 /* To suppress compiler warnings, always set output params */
4266 /* We assume here that int64 is at least as wide as long */
4268 val = strtol(value, &endptr, 0);
4270 if (endptr == value)
4271 return false; /* no HINT for integer syntax error */
4273 if (errno == ERANGE || val != (int64) ((int32) val))
4276 *hintmsg = gettext_noop("Value exceeds integer range.");
4280 /* allow whitespace between integer and unit */
4281 while (isspace((unsigned char) *endptr))
4284 /* Handle possible unit */
4285 if (*endptr != '\0')
4288 * Note: the multiple-switch coding technique here is a bit tedious,
4289 * but seems necessary to avoid intermediate-value overflows.
4291 if (flags & GUC_UNIT_MEMORY)
4293 /* Set hint for use if no match or trailing garbage */
4295 *hintmsg = gettext_noop("Valid units for this parameter are \"kB\", \"MB\", and \"GB\".");
4297 #if BLCKSZ < 1024 || BLCKSZ > (1024*1024)
4298 #error BLCKSZ must be between 1KB and 1MB
4300 #if XLOG_BLCKSZ < 1024 || XLOG_BLCKSZ > (1024*1024)
4301 #error XLOG_BLCKSZ must be between 1KB and 1MB
4304 if (strncmp(endptr, "kB", 2) == 0)
4307 switch (flags & GUC_UNIT_MEMORY)
4309 case GUC_UNIT_BLOCKS:
4310 val /= (BLCKSZ / 1024);
4312 case GUC_UNIT_XBLOCKS:
4313 val /= (XLOG_BLCKSZ / 1024);
4317 else if (strncmp(endptr, "MB", 2) == 0)
4320 switch (flags & GUC_UNIT_MEMORY)
4325 case GUC_UNIT_BLOCKS:
4326 val *= KB_PER_MB / (BLCKSZ / 1024);
4328 case GUC_UNIT_XBLOCKS:
4329 val *= KB_PER_MB / (XLOG_BLCKSZ / 1024);
4333 else if (strncmp(endptr, "GB", 2) == 0)
4336 switch (flags & GUC_UNIT_MEMORY)
4341 case GUC_UNIT_BLOCKS:
4342 val *= KB_PER_GB / (BLCKSZ / 1024);
4344 case GUC_UNIT_XBLOCKS:
4345 val *= KB_PER_GB / (XLOG_BLCKSZ / 1024);
4350 else if (flags & GUC_UNIT_TIME)
4352 /* Set hint for use if no match or trailing garbage */
4354 *hintmsg = gettext_noop("Valid units for this parameter are \"ms\", \"s\", \"min\", \"h\", and \"d\".");
4356 if (strncmp(endptr, "ms", 2) == 0)
4359 switch (flags & GUC_UNIT_TIME)
4369 else if (strncmp(endptr, "s", 1) == 0)
4372 switch (flags & GUC_UNIT_TIME)
4382 else if (strncmp(endptr, "min", 3) == 0)
4385 switch (flags & GUC_UNIT_TIME)
4395 else if (strncmp(endptr, "h", 1) == 0)
4398 switch (flags & GUC_UNIT_TIME)
4411 else if (strncmp(endptr, "d", 1) == 0)
4414 switch (flags & GUC_UNIT_TIME)
4429 /* allow whitespace after unit */
4430 while (isspace((unsigned char) *endptr))
4433 if (*endptr != '\0')
4434 return false; /* appropriate hint, if any, already set */
4436 /* Check for overflow due to units conversion */
4437 if (val != (int64) ((int32) val))
4440 *hintmsg = gettext_noop("Value exceeds integer range.");
4446 *result = (int) val;
4453 * Try to parse value as a floating point number in the usual format.
4454 * If the string parses okay, return true, else false.
4455 * If okay and result is not NULL, return the value in *result.
4458 parse_real(const char *value, double *result)
4464 *result = 0; /* suppress compiler warning */
4467 val = strtod(value, &endptr);
4468 if (endptr == value || errno == ERANGE)
4471 /* allow whitespace after number */
4472 while (isspace((unsigned char) *endptr))
4474 if (*endptr != '\0')
4484 * Lookup the name for an enum option with the selected value.
4485 * Should only ever be called with known-valid values, so throws
4486 * an elog(ERROR) if the enum option is not found.
4488 * The returned string is a pointer to static data and not
4489 * allocated for modification.
4492 config_enum_lookup_by_value(struct config_enum * record, int val)
4494 const struct config_enum_entry *entry;
4496 for (entry = record->options; entry && entry->name; entry++)
4498 if (entry->val == val)
4502 elog(ERROR, "could not find enum option %d for %s",
4503 val, record->gen.name);
4504 return NULL; /* silence compiler */
4509 * Lookup the value for an enum option with the selected name
4510 * (case-insensitive).
4511 * If the enum option is found, sets the retval value and returns
4512 * true. If it's not found, return FALSE and retval is set to 0.
4515 config_enum_lookup_by_name(struct config_enum * record, const char *value,
4518 const struct config_enum_entry *entry;
4520 for (entry = record->options; entry && entry->name; entry++)
4522 if (pg_strcasecmp(value, entry->name) == 0)
4524 *retval = entry->val;
4535 * Return a list of all available options for an enum, excluding
4536 * hidden ones, separated by the given separator.
4537 * If prefix is non-NULL, it is added before the first enum value.
4538 * If suffix is non-NULL, it is added to the end of the string.
4541 config_enum_get_options(struct config_enum * record, const char *prefix,
4542 const char *suffix, const char *separator)
4544 const struct config_enum_entry *entry;
4545 StringInfoData retstr;
4548 initStringInfo(&retstr);
4549 appendStringInfoString(&retstr, prefix);
4551 seplen = strlen(separator);
4552 for (entry = record->options; entry && entry->name; entry++)
4556 appendStringInfoString(&retstr, entry->name);
4557 appendBinaryStringInfo(&retstr, separator, seplen);
4562 * All the entries may have been hidden, leaving the string empty if no
4563 * prefix was given. This indicates a broken GUC setup, since there is no
4564 * use for an enum without any values, so we just check to make sure we
4565 * don't write to invalid memory instead of actually trying to do
4566 * something smart with it.
4568 if (retstr.len >= seplen)
4570 /* Replace final separator */
4571 retstr.data[retstr.len - seplen] = '\0';
4572 retstr.len -= seplen;
4575 appendStringInfoString(&retstr, suffix);
4581 * Call a GucStringAssignHook function, being careful to free the
4582 * "newval" string if the hook ereports.
4584 * This is split out of set_config_option just to avoid the "volatile"
4585 * qualifiers that would otherwise have to be plastered all over.
4588 call_string_assign_hook(GucStringAssignHook assign_hook,
4589 char *newval, bool doit, GucSource source)
4595 result = (*assign_hook) (newval, doit, source);
4609 * Sets option `name' to given value. The value should be a string
4610 * which is going to be parsed and converted to the appropriate data
4611 * type. The context and source parameters indicate in which context this
4612 * function is being called so it can apply the access restrictions
4615 * If value is NULL, set the option to its default value (normally the
4616 * reset_val, but if source == PGC_S_DEFAULT we instead use the boot_val).
4618 * action indicates whether to set the value globally in the session, locally
4619 * to the current top transaction, or just for the duration of a function call.
4621 * If changeVal is false then don't really set the option but do all
4622 * the checks to see if it would work.
4624 * If there is an error (non-existing option, invalid value) then an
4625 * ereport(ERROR) is thrown *unless* this is called in a context where we
4626 * don't want to ereport (currently, startup or SIGHUP config file reread).
4627 * In that case we write a suitable error message via ereport(LOG) and
4628 * return false. This is working around the deficiencies in the ereport
4629 * mechanism, so don't blame me. In all other cases, the function
4630 * returns true, including cases where the input is valid but we chose
4631 * not to apply it because of context or source-priority considerations.
4633 * See also SetConfigOption for an external interface.
4636 set_config_option(const char *name, const char *value,
4637 GucContext context, GucSource source,
4638 GucAction action, bool changeVal)
4640 struct config_generic *record;
4644 if (context == PGC_SIGHUP || source == PGC_S_DEFAULT)
4647 * To avoid cluttering the log, only the postmaster bleats loudly
4648 * about problems with the config file.
4650 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
4652 else if (source == PGC_S_DATABASE || source == PGC_S_USER ||
4653 source == PGC_S_DATABASE_USER)
4658 record = find_option(name, true, elevel);
4662 (errcode(ERRCODE_UNDEFINED_OBJECT),
4663 errmsg("unrecognized configuration parameter \"%s\"", name)));
4668 * If source is postgresql.conf, mark the found record with
4669 * GUC_IS_IN_FILE. This is for the convenience of ProcessConfigFile. Note
4670 * that we do it even if changeVal is false, since ProcessConfigFile wants
4671 * the marking to occur during its testing pass.
4673 if (source == PGC_S_FILE)
4674 record->status |= GUC_IS_IN_FILE;
4677 * Check if the option can be set at this time. See guc.h for the precise
4678 * rules. Note that we don't want to throw errors if we're in the SIGHUP
4679 * context. In that case we just ignore the attempt and return true.
4681 switch (record->context)
4684 if (context == PGC_SIGHUP)
4686 if (context != PGC_INTERNAL)
4689 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4690 errmsg("parameter \"%s\" cannot be changed",
4695 case PGC_POSTMASTER:
4696 if (context == PGC_SIGHUP)
4699 * We are reading a PGC_POSTMASTER var from postgresql.conf.
4700 * We can't change the setting, so give a warning if the DBA
4701 * tries to change it. (Throwing an error would be more
4702 * consistent, but seems overly rigid.)
4704 if (changeVal && !is_newvalue_equal(record, value))
4706 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4707 errmsg("parameter \"%s\" cannot be changed without restarting the server",
4711 if (context != PGC_POSTMASTER)
4714 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4715 errmsg("parameter \"%s\" cannot be changed without restarting the server",
4721 if (context != PGC_SIGHUP && context != PGC_POSTMASTER)
4724 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4725 errmsg("parameter \"%s\" cannot be changed now",
4731 * Hmm, the idea of the SIGHUP context is "ought to be global, but
4732 * can be changed after postmaster start". But there's nothing
4733 * that prevents a crafty administrator from sending SIGHUP
4734 * signals to individual backends only.
4738 if (context == PGC_SIGHUP)
4741 * If a PGC_BACKEND parameter is changed in the config file,
4742 * we want to accept the new value in the postmaster (whence
4743 * it will propagate to subsequently-started backends), but
4744 * ignore it in existing backends. This is a tad klugy, but
4745 * necessary because we don't re-read the config file during
4748 if (IsUnderPostmaster)
4751 else if (context != PGC_POSTMASTER && context != PGC_BACKEND &&
4752 source != PGC_S_CLIENT)
4755 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4756 errmsg("parameter \"%s\" cannot be set after connection start",
4762 if (context == PGC_USERSET || context == PGC_BACKEND)
4765 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4766 errmsg("permission denied to set parameter \"%s\"",
4777 * Disallow changing GUC_NOT_WHILE_SEC_REST values if we are inside a
4778 * security restriction context. We can reject this regardless of the GUC
4779 * context or source, mainly because sources that it might be reasonable
4780 * to override for won't be seen while inside a function.
4782 * Note: variables marked GUC_NOT_WHILE_SEC_REST should usually be marked
4783 * GUC_NO_RESET_ALL as well, because ResetAllOptions() doesn't check this.
4784 * An exception might be made if the reset value is assumed to be "safe".
4786 * Note: this flag is currently used for "session_authorization" and
4787 * "role". We need to prohibit changing these inside a local userid
4788 * context because when we exit it, GUC won't be notified, leaving things
4789 * out of sync. (This could be fixed by forcing a new GUC nesting level,
4790 * but that would change behavior in possibly-undesirable ways.) Also, we
4791 * prohibit changing these in a security-restricted operation because
4792 * otherwise RESET could be used to regain the session user's privileges.
4794 if (record->flags & GUC_NOT_WHILE_SEC_REST)
4796 if (InLocalUserIdChange())
4799 * Phrasing of this error message is historical, but it's the most
4803 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4804 errmsg("cannot set parameter \"%s\" within security-definer function",
4808 if (InSecurityRestrictedOperation())
4811 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4812 errmsg("cannot set parameter \"%s\" within security-restricted operation",
4819 * Should we set reset/stacked values? (If so, the behavior is not
4820 * transactional.) This is done either when we get a default value from
4821 * the database's/user's/client's default settings or when we reset a
4822 * value to its default.
4824 makeDefault = changeVal && (source <= PGC_S_OVERRIDE) &&
4825 ((value != NULL) || source == PGC_S_DEFAULT);
4828 * Ignore attempted set if overridden by previously processed setting.
4829 * However, if changeVal is false then plow ahead anyway since we are
4830 * trying to find out if the value is potentially good, not actually use
4831 * it. Also keep going if makeDefault is true, since we may want to set
4832 * the reset/stacked values even if we can't set the variable itself.
4834 if (record->source > source)
4836 if (changeVal && !makeDefault)
4838 elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
4846 * Evaluate value and set variable.
4848 switch (record->vartype)
4852 struct config_bool *conf = (struct config_bool *) record;
4857 if (!parse_bool(value, &newval))
4860 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4861 errmsg("parameter \"%s\" requires a Boolean value",
4866 else if (source == PGC_S_DEFAULT)
4867 newval = conf->boot_val;
4870 newval = conf->reset_val;
4871 source = conf->gen.reset_source;
4874 /* Save old value to support transaction abort */
4875 if (changeVal && !makeDefault)
4876 push_old_value(&conf->gen, action);
4878 if (conf->assign_hook)
4879 if (!(*conf->assign_hook) (newval, changeVal, source))
4882 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4883 errmsg("invalid value for parameter \"%s\": %d",
4884 name, (int) newval)));
4890 *conf->variable = newval;
4891 conf->gen.source = source;
4897 if (conf->gen.reset_source <= source)
4899 conf->reset_val = newval;
4900 conf->gen.reset_source = source;
4902 for (stack = conf->gen.stack; stack; stack = stack->prev)
4904 if (stack->source <= source)
4906 stack->prior.boolval = newval;
4907 stack->source = source;
4916 struct config_int *conf = (struct config_int *) record;
4921 const char *hintmsg;
4923 if (!parse_int(value, &newval, conf->gen.flags, &hintmsg))
4926 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4927 errmsg("invalid value for parameter \"%s\": \"%s\"",
4929 hintmsg ? errhint("%s", _(hintmsg)) : 0));
4932 if (newval < conf->min || newval > conf->max)
4935 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4936 errmsg("%d is outside the valid range for parameter \"%s\" (%d .. %d)",
4937 newval, name, conf->min, conf->max)));
4941 else if (source == PGC_S_DEFAULT)
4942 newval = conf->boot_val;
4945 newval = conf->reset_val;
4946 source = conf->gen.reset_source;
4949 /* Save old value to support transaction abort */
4950 if (changeVal && !makeDefault)
4951 push_old_value(&conf->gen, action);
4953 if (conf->assign_hook)
4954 if (!(*conf->assign_hook) (newval, changeVal, source))
4957 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4958 errmsg("invalid value for parameter \"%s\": %d",
4965 *conf->variable = newval;
4966 conf->gen.source = source;
4972 if (conf->gen.reset_source <= source)
4974 conf->reset_val = newval;
4975 conf->gen.reset_source = source;
4977 for (stack = conf->gen.stack; stack; stack = stack->prev)
4979 if (stack->source <= source)
4981 stack->prior.intval = newval;
4982 stack->source = source;
4991 struct config_real *conf = (struct config_real *) record;
4996 if (!parse_real(value, &newval))
4999 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5000 errmsg("parameter \"%s\" requires a numeric value",
5004 if (newval < conf->min || newval > conf->max)
5007 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5008 errmsg("%g is outside the valid range for parameter \"%s\" (%g .. %g)",
5009 newval, name, conf->min, conf->max)));
5013 else if (source == PGC_S_DEFAULT)
5014 newval = conf->boot_val;
5017 newval = conf->reset_val;
5018 source = conf->gen.reset_source;
5021 /* Save old value to support transaction abort */
5022 if (changeVal && !makeDefault)
5023 push_old_value(&conf->gen, action);
5025 if (conf->assign_hook)
5026 if (!(*conf->assign_hook) (newval, changeVal, source))
5029 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5030 errmsg("invalid value for parameter \"%s\": %g",
5037 *conf->variable = newval;
5038 conf->gen.source = source;
5044 if (conf->gen.reset_source <= source)
5046 conf->reset_val = newval;
5047 conf->gen.reset_source = source;
5049 for (stack = conf->gen.stack; stack; stack = stack->prev)
5051 if (stack->source <= source)
5053 stack->prior.realval = newval;
5054 stack->source = source;
5063 struct config_string *conf = (struct config_string *) record;
5068 newval = guc_strdup(elevel, value);
5073 * The only sort of "parsing" check we need to do is apply
5074 * truncation if GUC_IS_NAME.
5076 if (conf->gen.flags & GUC_IS_NAME)
5077 truncate_identifier(newval, strlen(newval), true);
5079 else if (source == PGC_S_DEFAULT)
5081 if (conf->boot_val == NULL)
5085 newval = guc_strdup(elevel, conf->boot_val);
5093 * We could possibly avoid strdup here, but easier to make
5094 * this case work the same as the normal assignment case;
5095 * note the possible free of newval below.
5097 if (conf->reset_val == NULL)
5101 newval = guc_strdup(elevel, conf->reset_val);
5105 source = conf->gen.reset_source;
5108 /* Save old value to support transaction abort */
5109 if (changeVal && !makeDefault)
5110 push_old_value(&conf->gen, action);
5112 if (conf->assign_hook && newval)
5114 const char *hookresult;
5117 * If the hook ereports, we have to make sure we free
5118 * newval, else it will be a permanent memory leak.
5120 hookresult = call_string_assign_hook(conf->assign_hook,
5124 if (hookresult == NULL)
5128 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5129 errmsg("invalid value for parameter \"%s\": \"%s\"",
5130 name, value ? value : "")));
5133 else if (hookresult != newval)
5138 * Having to cast away const here is annoying, but the
5139 * alternative is to declare assign_hooks as returning
5140 * char*, which would mean they'd have to cast away
5141 * const, or as both taking and returning char*, which
5142 * doesn't seem attractive either --- we don't want
5143 * them to scribble on the passed str.
5145 newval = (char *) hookresult;
5151 set_string_field(conf, conf->variable, newval);
5152 conf->gen.source = source;
5158 if (conf->gen.reset_source <= source)
5160 set_string_field(conf, &conf->reset_val, newval);
5161 conf->gen.reset_source = source;
5163 for (stack = conf->gen.stack; stack; stack = stack->prev)
5165 if (stack->source <= source)
5167 set_string_field(conf, &stack->prior.stringval,
5169 stack->source = source;
5173 /* Perhaps we didn't install newval anywhere */
5174 if (newval && !string_field_used(conf, newval))
5180 struct config_enum *conf = (struct config_enum *) record;
5185 if (!config_enum_lookup_by_name(conf, value, &newval))
5189 hintmsg = config_enum_get_options(conf,
5190 "Available values: ",
5194 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5195 errmsg("invalid value for parameter \"%s\": \"%s\"",
5197 hintmsg ? errhint("%s", _(hintmsg)) : 0));
5204 else if (source == PGC_S_DEFAULT)
5205 newval = conf->boot_val;
5208 newval = conf->reset_val;
5209 source = conf->gen.reset_source;
5212 /* Save old value to support transaction abort */
5213 if (changeVal && !makeDefault)
5214 push_old_value(&conf->gen, action);
5216 if (conf->assign_hook)
5217 if (!(*conf->assign_hook) (newval, changeVal, source))
5220 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5221 errmsg("invalid value for parameter \"%s\": \"%s\"",
5223 config_enum_lookup_by_value(conf, newval))));
5229 *conf->variable = newval;
5230 conf->gen.source = source;
5236 if (conf->gen.reset_source <= source)
5238 conf->reset_val = newval;
5239 conf->gen.reset_source = source;
5241 for (stack = conf->gen.stack; stack; stack = stack->prev)
5243 if (stack->source <= source)
5245 stack->prior.enumval = newval;
5246 stack->source = source;
5254 if (changeVal && (record->flags & GUC_REPORT))
5255 ReportGUCOption(record);
5262 * Set the fields for source file and line number the setting came from.
5265 set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
5267 struct config_generic *record;
5271 * To avoid cluttering the log, only the postmaster bleats loudly about
5272 * problems with the config file.
5274 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
5276 record = find_option(name, true, elevel);
5277 /* should not happen */
5279 elog(ERROR, "unrecognized configuration parameter \"%s\"", name);
5281 sourcefile = guc_strdup(elevel, sourcefile);
5282 if (record->sourcefile)
5283 free(record->sourcefile);
5284 record->sourcefile = sourcefile;
5285 record->sourceline = sourceline;
5289 * Set a config option to the given value. See also set_config_option,
5290 * this is just the wrapper to be called from outside GUC. NB: this
5291 * is used only for non-transactional operations.
5293 * Note: there is no support here for setting source file/line, as it
5294 * is currently not needed.
5297 SetConfigOption(const char *name, const char *value,
5298 GucContext context, GucSource source)
5300 (void) set_config_option(name, value, context, source,
5301 GUC_ACTION_SET, true);
5307 * Fetch the current value of the option `name'. If the option doesn't exist,
5308 * throw an ereport and don't return.
5310 * If restrict_superuser is true, we also enforce that only superusers can
5311 * see GUC_SUPERUSER_ONLY variables. This should only be passed as true
5312 * in user-driven calls.
5314 * The string is *not* allocated for modification and is really only
5315 * valid until the next call to configuration related functions.
5318 GetConfigOption(const char *name, bool restrict_superuser)
5320 struct config_generic *record;
5321 static char buffer[256];
5323 record = find_option(name, false, ERROR);
5326 (errcode(ERRCODE_UNDEFINED_OBJECT),
5327 errmsg("unrecognized configuration parameter \"%s\"", name)));
5328 if (restrict_superuser &&
5329 (record->flags & GUC_SUPERUSER_ONLY) &&
5332 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5333 errmsg("must be superuser to examine \"%s\"", name)));
5335 switch (record->vartype)
5338 return *((struct config_bool *) record)->variable ? "on" : "off";
5341 snprintf(buffer, sizeof(buffer), "%d",
5342 *((struct config_int *) record)->variable);
5346 snprintf(buffer, sizeof(buffer), "%g",
5347 *((struct config_real *) record)->variable);
5351 return *((struct config_string *) record)->variable;
5354 return config_enum_lookup_by_value((struct config_enum *) record,
5355 *((struct config_enum *) record)->variable);
5361 * Get the RESET value associated with the given option.
5363 * Note: this is not re-entrant, due to use of static result buffer;
5364 * not to mention that a string variable could have its reset_val changed.
5365 * Beware of assuming the result value is good for very long.
5368 GetConfigOptionResetString(const char *name)
5370 struct config_generic *record;
5371 static char buffer[256];
5373 record = find_option(name, false, ERROR);
5376 (errcode(ERRCODE_UNDEFINED_OBJECT),
5377 errmsg("unrecognized configuration parameter \"%s\"", name)));
5378 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
5380 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5381 errmsg("must be superuser to examine \"%s\"", name)));
5383 switch (record->vartype)
5386 return ((struct config_bool *) record)->reset_val ? "on" : "off";
5389 snprintf(buffer, sizeof(buffer), "%d",
5390 ((struct config_int *) record)->reset_val);
5394 snprintf(buffer, sizeof(buffer), "%g",
5395 ((struct config_real *) record)->reset_val);
5399 return ((struct config_string *) record)->reset_val;
5402 return config_enum_lookup_by_value((struct config_enum *) record,
5403 ((struct config_enum *) record)->reset_val);
5410 * GUC_complaint_elevel
5411 * Get the ereport error level to use in an assign_hook's error report.
5413 * This should be used by assign hooks that want to emit a custom error
5414 * report (in addition to the generic "invalid value for option FOO" that
5415 * guc.c will provide). Note that the result might be ERROR or a lower
5416 * level, so the caller must be prepared for control to return from ereport,
5417 * or not. If control does return, return false/NULL from the hook function.
5419 * At some point it'd be nice to replace this with a mechanism that allows
5420 * the custom message to become the DETAIL line of guc.c's generic message.
5423 GUC_complaint_elevel(GucSource source)
5427 if (source == PGC_S_FILE)
5430 * To avoid cluttering the log, only the postmaster bleats loudly
5431 * about problems with the config file.
5433 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
5435 else if (source == PGC_S_OVERRIDE)
5438 * If we're a postmaster child, this is probably "undo" during
5439 * transaction abort, so we don't want to clutter the log. There's a
5440 * small chance of a real problem with an OVERRIDE setting, though, so
5441 * suppressing the message entirely wouldn't be desirable.
5443 elevel = IsUnderPostmaster ? DEBUG5 : LOG;
5445 else if (source < PGC_S_INTERACTIVE)
5455 * flatten_set_variable_args
5456 * Given a parsenode List as emitted by the grammar for SET,
5457 * convert to the flat string representation used by GUC.
5459 * We need to be told the name of the variable the args are for, because
5460 * the flattening rules vary (ugh).
5462 * The result is NULL if args is NIL (ie, SET ... TO DEFAULT), otherwise
5463 * a palloc'd string.
5466 flatten_set_variable_args(const char *name, List *args)
5468 struct config_generic *record;
5473 /* Fast path if just DEFAULT */
5477 /* Else get flags for the variable */
5478 record = find_option(name, true, ERROR);
5481 (errcode(ERRCODE_UNDEFINED_OBJECT),
5482 errmsg("unrecognized configuration parameter \"%s\"", name)));
5484 flags = record->flags;
5486 /* Complain if list input and non-list variable */
5487 if ((flags & GUC_LIST_INPUT) == 0 &&
5488 list_length(args) != 1)
5490 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5491 errmsg("SET %s takes only one argument", name)));
5493 initStringInfo(&buf);
5496 * Each list member may be a plain A_Const node, or an A_Const within a
5497 * TypeCast; the latter case is supported only for ConstInterval arguments
5498 * (for SET TIME ZONE).
5502 Node *arg = (Node *) lfirst(l);
5504 TypeName *typeName = NULL;
5507 if (l != list_head(args))
5508 appendStringInfo(&buf, ", ");
5510 if (IsA(arg, TypeCast))
5512 TypeCast *tc = (TypeCast *) arg;
5515 typeName = tc->typeName;
5518 if (!IsA(arg, A_Const))
5519 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
5520 con = (A_Const *) arg;
5522 switch (nodeTag(&con->val))
5525 appendStringInfo(&buf, "%ld", intVal(&con->val));
5528 /* represented as a string, so just copy it */
5529 appendStringInfoString(&buf, strVal(&con->val));
5532 val = strVal(&con->val);
5533 if (typeName != NULL)
5536 * Must be a ConstInterval argument for TIME ZONE. Coerce
5537 * to interval and back to normalize the value and account
5545 typoid = typenameTypeId(NULL, typeName, &typmod);
5546 Assert(typoid == INTERVALOID);
5549 DirectFunctionCall3(interval_in,
5550 CStringGetDatum(val),
5551 ObjectIdGetDatum(InvalidOid),
5552 Int32GetDatum(typmod));
5555 DatumGetCString(DirectFunctionCall1(interval_out,
5557 appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
5562 * Plain string literal or identifier. For quote mode,
5563 * quote it if it's not a vanilla identifier.
5565 if (flags & GUC_LIST_QUOTE)
5566 appendStringInfoString(&buf, quote_identifier(val));
5568 appendStringInfoString(&buf, val);
5572 elog(ERROR, "unrecognized node type: %d",
5573 (int) nodeTag(&con->val));
5586 ExecSetVariableStmt(VariableSetStmt *stmt)
5588 GucAction action = stmt->is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET;
5593 case VAR_SET_CURRENT:
5594 set_config_option(stmt->name,
5595 ExtractSetVariableArgs(stmt),
5596 (superuser() ? PGC_SUSET : PGC_USERSET),
5604 * Special case for special SQL syntax that effectively sets more
5605 * than one variable per statement.
5607 if (strcmp(stmt->name, "TRANSACTION") == 0)
5611 foreach(head, stmt->args)
5613 DefElem *item = (DefElem *) lfirst(head);
5615 if (strcmp(item->defname, "transaction_isolation") == 0)
5616 SetPGVariable("transaction_isolation",
5617 list_make1(item->arg), stmt->is_local);
5618 else if (strcmp(item->defname, "transaction_read_only") == 0)
5619 SetPGVariable("transaction_read_only",
5620 list_make1(item->arg), stmt->is_local);
5622 elog(ERROR, "unexpected SET TRANSACTION element: %s",
5626 else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
5630 foreach(head, stmt->args)
5632 DefElem *item = (DefElem *) lfirst(head);
5634 if (strcmp(item->defname, "transaction_isolation") == 0)
5635 SetPGVariable("default_transaction_isolation",
5636 list_make1(item->arg), stmt->is_local);
5637 else if (strcmp(item->defname, "transaction_read_only") == 0)
5638 SetPGVariable("default_transaction_read_only",
5639 list_make1(item->arg), stmt->is_local);
5641 elog(ERROR, "unexpected SET SESSION element: %s",
5646 elog(ERROR, "unexpected SET MULTI element: %s",
5649 case VAR_SET_DEFAULT:
5651 set_config_option(stmt->name,
5653 (superuser() ? PGC_SUSET : PGC_USERSET),
5665 * Get the value to assign for a VariableSetStmt, or NULL if it's RESET.
5666 * The result is palloc'd.
5668 * This is exported for use by actions such as ALTER ROLE SET.
5671 ExtractSetVariableArgs(VariableSetStmt *stmt)
5676 return flatten_set_variable_args(stmt->name, stmt->args);
5677 case VAR_SET_CURRENT:
5678 return GetConfigOptionByName(stmt->name, NULL);
5685 * SetPGVariable - SET command exported as an easily-C-callable function.
5687 * This provides access to SET TO value, as well as SET TO DEFAULT (expressed
5688 * by passing args == NIL), but not SET FROM CURRENT functionality.
5691 SetPGVariable(const char *name, List *args, bool is_local)
5693 char *argstring = flatten_set_variable_args(name, args);
5695 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
5696 set_config_option(name,
5698 (superuser() ? PGC_SUSET : PGC_USERSET),
5700 is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET,
5705 * SET command wrapped as a SQL callable function.
5708 set_config_by_name(PG_FUNCTION_ARGS)
5715 if (PG_ARGISNULL(0))
5717 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
5718 errmsg("SET requires parameter name")));
5720 /* Get the GUC variable name */
5721 name = TextDatumGetCString(PG_GETARG_DATUM(0));
5723 /* Get the desired value or set to NULL for a reset request */
5724 if (PG_ARGISNULL(1))
5727 value = TextDatumGetCString(PG_GETARG_DATUM(1));
5730 * Get the desired state of is_local. Default to false if provided value
5733 if (PG_ARGISNULL(2))
5736 is_local = PG_GETARG_BOOL(2);
5738 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
5739 set_config_option(name,
5741 (superuser() ? PGC_SUSET : PGC_USERSET),
5743 is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET,
5746 /* get the new current value */
5747 new_value = GetConfigOptionByName(name, NULL);
5749 /* Convert return string to text */
5750 PG_RETURN_TEXT_P(cstring_to_text(new_value));
5755 * Common code for DefineCustomXXXVariable subroutines: allocate the
5756 * new variable's config struct and fill in generic fields.
5758 static struct config_generic *
5759 init_custom_variable(const char *name,
5760 const char *short_desc,
5761 const char *long_desc,
5764 enum config_type type,
5767 struct config_generic *gen;
5770 * Only allow custom PGC_POSTMASTER variables to be created during shared
5771 * library preload; any later than that, we can't ensure that the value
5772 * doesn't change after startup. This is a fatal elog if it happens; just
5773 * erroring out isn't safe because we don't know what the calling loadable
5774 * module might already have hooked into.
5776 if (context == PGC_POSTMASTER &&
5777 !process_shared_preload_libraries_in_progress)
5778 elog(FATAL, "cannot create PGC_POSTMASTER variables after startup");
5780 gen = (struct config_generic *) guc_malloc(ERROR, sz);
5783 gen->name = guc_strdup(ERROR, name);
5784 gen->context = context;
5785 gen->group = CUSTOM_OPTIONS;
5786 gen->short_desc = short_desc;
5787 gen->long_desc = long_desc;
5789 gen->vartype = type;
5795 * Common code for DefineCustomXXXVariable subroutines: insert the new
5796 * variable into the GUC variable array, replacing any placeholder.
5799 define_custom_variable(struct config_generic * variable)
5801 const char *name = variable->name;
5802 const char **nameAddr = &name;
5804 struct config_string *pHolder;
5805 GucContext phcontext;
5806 struct config_generic **res;
5809 * See if there's a placeholder by the same name.
5811 res = (struct config_generic **) bsearch((void *) &nameAddr,
5812 (void *) guc_variables,
5814 sizeof(struct config_generic *),
5819 * No placeholder to replace, so we can just add it ... but first,
5820 * make sure it's initialized to its default value.
5822 InitializeOneGUCOption(variable);
5823 add_guc_variable(variable, ERROR);
5828 * This better be a placeholder
5830 if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
5832 (errcode(ERRCODE_INTERNAL_ERROR),
5833 errmsg("attempt to redefine parameter \"%s\"", name)));
5835 Assert((*res)->vartype == PGC_STRING);
5836 pHolder = (struct config_string *) (*res);
5839 * First, set the variable to its default value. We must do this even
5840 * though we intend to immediately apply a new value, since it's possible
5841 * that the new value is invalid.
5843 InitializeOneGUCOption(variable);
5846 * Replace the placeholder. We aren't changing the name, so no re-sorting
5852 * Infer context for assignment based on source of existing value. We
5853 * can't tell this with exact accuracy, but we can at least do something
5854 * reasonable in typical cases.
5856 switch (pHolder->gen.source)
5864 * If we got past the check in init_custom_variable, we can safely
5865 * assume that any existing value for a PGC_POSTMASTER variable
5866 * was set in postmaster context.
5868 if (variable->context == PGC_POSTMASTER)
5869 phcontext = PGC_POSTMASTER;
5871 phcontext = PGC_SIGHUP;
5873 case PGC_S_DATABASE:
5875 case PGC_S_DATABASE_USER:
5879 phcontext = PGC_USERSET;
5884 * Assign the string value stored in the placeholder to the real variable.
5886 * XXX this is not really good enough --- it should be a nontransactional
5887 * assignment, since we don't want it to roll back if the current xact
5888 * fails later. (Or do we?)
5890 value = *pHolder->variable;
5894 if (set_config_option(name, value,
5895 phcontext, pHolder->gen.source,
5896 GUC_ACTION_SET, true))
5898 /* Also copy over any saved source-location information */
5899 if (pHolder->gen.sourcefile)
5900 set_config_sourcefile(name, pHolder->gen.sourcefile,
5901 pHolder->gen.sourceline);
5906 * Free up as much as we conveniently can of the placeholder structure
5907 * (this neglects any stack items...)
5909 set_string_field(pHolder, pHolder->variable, NULL);
5910 set_string_field(pHolder, &pHolder->reset_val, NULL);
5916 DefineCustomBoolVariable(const char *name,
5917 const char *short_desc,
5918 const char *long_desc,
5923 GucBoolAssignHook assign_hook,
5924 GucShowHook show_hook)
5926 struct config_bool *var;
5928 var = (struct config_bool *)
5929 init_custom_variable(name, short_desc, long_desc, context, flags,
5930 PGC_BOOL, sizeof(struct config_bool));
5931 var->variable = valueAddr;
5932 var->boot_val = bootValue;
5933 var->reset_val = bootValue;
5934 var->assign_hook = assign_hook;
5935 var->show_hook = show_hook;
5936 define_custom_variable(&var->gen);
5940 DefineCustomIntVariable(const char *name,
5941 const char *short_desc,
5942 const char *long_desc,
5949 GucIntAssignHook assign_hook,
5950 GucShowHook show_hook)
5952 struct config_int *var;
5954 var = (struct config_int *)
5955 init_custom_variable(name, short_desc, long_desc, context, flags,
5956 PGC_INT, sizeof(struct config_int));
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 DefineCustomRealVariable(const char *name,
5969 const char *short_desc,
5970 const char *long_desc,
5977 GucRealAssignHook assign_hook,
5978 GucShowHook show_hook)
5980 struct config_real *var;
5982 var = (struct config_real *)
5983 init_custom_variable(name, short_desc, long_desc, context, flags,
5984 PGC_REAL, sizeof(struct config_real));
5985 var->variable = valueAddr;
5986 var->boot_val = bootValue;
5987 var->reset_val = bootValue;
5988 var->min = minValue;
5989 var->max = maxValue;
5990 var->assign_hook = assign_hook;
5991 var->show_hook = show_hook;
5992 define_custom_variable(&var->gen);
5996 DefineCustomStringVariable(const char *name,
5997 const char *short_desc,
5998 const char *long_desc,
6000 const char *bootValue,
6003 GucStringAssignHook assign_hook,
6004 GucShowHook show_hook)
6006 struct config_string *var;
6008 var = (struct config_string *)
6009 init_custom_variable(name, short_desc, long_desc, context, flags,
6010 PGC_STRING, sizeof(struct config_string));
6011 var->variable = valueAddr;
6012 var->boot_val = bootValue;
6013 /* we could probably do without strdup, but keep it like normal case */
6015 var->reset_val = guc_strdup(ERROR, var->boot_val);
6016 var->assign_hook = assign_hook;
6017 var->show_hook = show_hook;
6018 define_custom_variable(&var->gen);
6022 DefineCustomEnumVariable(const char *name,
6023 const char *short_desc,
6024 const char *long_desc,
6027 const struct config_enum_entry * options,
6030 GucEnumAssignHook assign_hook,
6031 GucShowHook show_hook)
6033 struct config_enum *var;
6035 var = (struct config_enum *)
6036 init_custom_variable(name, short_desc, long_desc, context, flags,
6037 PGC_ENUM, sizeof(struct config_enum));
6038 var->variable = valueAddr;
6039 var->boot_val = bootValue;
6040 var->reset_val = bootValue;
6041 var->options = options;
6042 var->assign_hook = assign_hook;
6043 var->show_hook = show_hook;
6044 define_custom_variable(&var->gen);
6048 EmitWarningsOnPlaceholders(const char *className)
6050 int classLen = strlen(className);
6053 for (i = 0; i < num_guc_variables; i++)
6055 struct config_generic *var = guc_variables[i];
6057 if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
6058 strncmp(className, var->name, classLen) == 0 &&
6059 var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
6062 (errcode(ERRCODE_UNDEFINED_OBJECT),
6063 errmsg("unrecognized configuration parameter \"%s\"",
6074 GetPGVariable(const char *name, DestReceiver *dest)
6076 if (guc_name_compare(name, "all") == 0)
6077 ShowAllGUCConfig(dest);
6079 ShowGUCConfigOption(name, dest);
6083 GetPGVariableResultDesc(const char *name)
6087 if (guc_name_compare(name, "all") == 0)
6089 /* need a tuple descriptor representing three TEXT columns */
6090 tupdesc = CreateTemplateTupleDesc(3, false);
6091 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
6093 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
6095 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
6100 const char *varname;
6102 /* Get the canonical spelling of name */
6103 (void) GetConfigOptionByName(name, &varname);
6105 /* need a tuple descriptor representing a single TEXT column */
6106 tupdesc = CreateTemplateTupleDesc(1, false);
6107 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
6118 ShowGUCConfigOption(const char *name, DestReceiver *dest)
6120 TupOutputState *tstate;
6122 const char *varname;
6125 /* Get the value and canonical spelling of name */
6126 value = GetConfigOptionByName(name, &varname);
6128 /* need a tuple descriptor representing a single TEXT column */
6129 tupdesc = CreateTemplateTupleDesc(1, false);
6130 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
6133 /* prepare for projection of tuples */
6134 tstate = begin_tup_output_tupdesc(dest, tupdesc);
6137 do_text_output_oneline(tstate, value);
6139 end_tup_output(tstate);
6146 ShowAllGUCConfig(DestReceiver *dest)
6148 bool am_superuser = superuser();
6150 TupOutputState *tstate;
6153 bool isnull[3] = {false, false, false};
6155 /* need a tuple descriptor representing three TEXT columns */
6156 tupdesc = CreateTemplateTupleDesc(3, false);
6157 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
6159 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
6161 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
6164 /* prepare for projection of tuples */
6165 tstate = begin_tup_output_tupdesc(dest, tupdesc);
6167 for (i = 0; i < num_guc_variables; i++)
6169 struct config_generic *conf = guc_variables[i];
6172 if ((conf->flags & GUC_NO_SHOW_ALL) ||
6173 ((conf->flags & GUC_SUPERUSER_ONLY) && !am_superuser))
6176 /* assign to the values array */
6177 values[0] = PointerGetDatum(cstring_to_text(conf->name));
6179 setting = _ShowOption(conf, true);
6182 values[1] = PointerGetDatum(cstring_to_text(setting));
6187 values[1] = PointerGetDatum(NULL);
6191 values[2] = PointerGetDatum(cstring_to_text(conf->short_desc));
6193 /* send it to dest */
6194 do_tup_output(tstate, values, isnull);
6197 pfree(DatumGetPointer(values[0]));
6201 pfree(DatumGetPointer(values[1]));
6203 pfree(DatumGetPointer(values[2]));
6206 end_tup_output(tstate);
6210 * Return GUC variable value by name; optionally return canonical
6211 * form of name. Return value is palloc'd.
6214 GetConfigOptionByName(const char *name, const char **varname)
6216 struct config_generic *record;
6218 record = find_option(name, false, ERROR);
6221 (errcode(ERRCODE_UNDEFINED_OBJECT),
6222 errmsg("unrecognized configuration parameter \"%s\"", name)));
6223 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
6225 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6226 errmsg("must be superuser to examine \"%s\"", name)));
6229 *varname = record->name;
6231 return _ShowOption(record, true);
6235 * Return GUC variable value by variable number; optionally return canonical
6236 * form of name. Return value is palloc'd.
6239 GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
6242 struct config_generic *conf;
6244 /* check requested variable number valid */
6245 Assert((varnum >= 0) && (varnum < num_guc_variables));
6247 conf = guc_variables[varnum];
6251 if ((conf->flags & GUC_NO_SHOW_ALL) ||
6252 ((conf->flags & GUC_SUPERUSER_ONLY) && !superuser()))
6258 /* first get the generic attributes */
6261 values[0] = conf->name;
6263 /* setting : use _ShowOption in order to avoid duplicating the logic */
6264 values[1] = _ShowOption(conf, false);
6267 if (conf->vartype == PGC_INT)
6271 switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
6276 case GUC_UNIT_BLOCKS:
6277 snprintf(buf, sizeof(buf), "%dkB", BLCKSZ / 1024);
6280 case GUC_UNIT_XBLOCKS:
6281 snprintf(buf, sizeof(buf), "%dkB", XLOG_BLCKSZ / 1024);
6302 values[3] = config_group_names[conf->group];
6305 values[4] = conf->short_desc;
6308 values[5] = conf->long_desc;
6311 values[6] = GucContext_Names[conf->context];
6314 values[7] = config_type_names[conf->vartype];
6317 values[8] = GucSource_Names[conf->source];
6319 /* now get the type specifc attributes */
6320 switch (conf->vartype)
6324 struct config_bool *lconf = (struct config_bool *) conf;
6336 values[12] = pstrdup(lconf->boot_val ? "on" : "off");
6339 values[13] = pstrdup(lconf->reset_val ? "on" : "off");
6345 struct config_int *lconf = (struct config_int *) conf;
6348 snprintf(buffer, sizeof(buffer), "%d", lconf->min);
6349 values[9] = pstrdup(buffer);
6352 snprintf(buffer, sizeof(buffer), "%d", lconf->max);
6353 values[10] = pstrdup(buffer);
6359 snprintf(buffer, sizeof(buffer), "%d", lconf->boot_val);
6360 values[12] = pstrdup(buffer);
6363 snprintf(buffer, sizeof(buffer), "%d", lconf->reset_val);
6364 values[13] = pstrdup(buffer);
6370 struct config_real *lconf = (struct config_real *) conf;
6373 snprintf(buffer, sizeof(buffer), "%g", lconf->min);
6374 values[9] = pstrdup(buffer);
6377 snprintf(buffer, sizeof(buffer), "%g", lconf->max);
6378 values[10] = pstrdup(buffer);
6384 snprintf(buffer, sizeof(buffer), "%g", lconf->boot_val);
6385 values[12] = pstrdup(buffer);
6388 snprintf(buffer, sizeof(buffer), "%g", lconf->reset_val);
6389 values[13] = pstrdup(buffer);
6395 struct config_string *lconf = (struct config_string *) conf;
6407 if (lconf->boot_val == NULL)
6410 values[12] = pstrdup(lconf->boot_val);
6413 if (lconf->reset_val == NULL)
6416 values[13] = pstrdup(lconf->reset_val);
6422 struct config_enum *lconf = (struct config_enum *) conf;
6433 * NOTE! enumvals with double quotes in them are not
6436 values[11] = config_enum_get_options((struct config_enum *) conf,
6437 "{\"", "\"}", "\",\"");
6440 values[12] = pstrdup(config_enum_lookup_by_value(lconf,
6444 values[13] = pstrdup(config_enum_lookup_by_value(lconf,
6452 * should never get here, but in case we do, set 'em to NULL
6474 * If the setting came from a config file, set the source location. For
6475 * security reasons, we don't show source file/line number for
6478 if (conf->source == PGC_S_FILE && superuser())
6480 values[14] = conf->sourcefile;
6481 snprintf(buffer, sizeof(buffer), "%d", conf->sourceline);
6482 values[15] = pstrdup(buffer);
6492 * Return the total number of GUC variables
6495 GetNumConfigOptions(void)
6497 return num_guc_variables;
6501 * show_config_by_name - equiv to SHOW X command but implemented as
6505 show_config_by_name(PG_FUNCTION_ARGS)
6510 /* Get the GUC variable name */
6511 varname = TextDatumGetCString(PG_GETARG_DATUM(0));
6514 varval = GetConfigOptionByName(varname, NULL);
6516 /* Convert to text */
6517 PG_RETURN_TEXT_P(cstring_to_text(varval));
6521 * show_all_settings - equiv to SHOW ALL command but implemented as
6524 #define NUM_PG_SETTINGS_ATTS 16
6527 show_all_settings(PG_FUNCTION_ARGS)
6529 FuncCallContext *funcctx;
6533 AttInMetadata *attinmeta;
6534 MemoryContext oldcontext;
6536 /* stuff done only on the first call of the function */
6537 if (SRF_IS_FIRSTCALL())
6539 /* create a function context for cross-call persistence */
6540 funcctx = SRF_FIRSTCALL_INIT();
6543 * switch to memory context appropriate for multiple function calls
6545 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
6548 * need a tuple descriptor representing NUM_PG_SETTINGS_ATTS columns
6549 * of the appropriate types
6551 tupdesc = CreateTemplateTupleDesc(NUM_PG_SETTINGS_ATTS, false);
6552 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
6554 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
6556 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "unit",
6558 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "category",
6560 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "short_desc",
6562 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "extra_desc",
6564 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "context",
6566 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "vartype",
6568 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "source",
6570 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "min_val",
6572 TupleDescInitEntry(tupdesc, (AttrNumber) 11, "max_val",
6574 TupleDescInitEntry(tupdesc, (AttrNumber) 12, "enumvals",
6575 TEXTARRAYOID, -1, 0);
6576 TupleDescInitEntry(tupdesc, (AttrNumber) 13, "boot_val",
6578 TupleDescInitEntry(tupdesc, (AttrNumber) 14, "reset_val",
6580 TupleDescInitEntry(tupdesc, (AttrNumber) 15, "sourcefile",
6582 TupleDescInitEntry(tupdesc, (AttrNumber) 16, "sourceline",
6586 * Generate attribute metadata needed later to produce tuples from raw
6589 attinmeta = TupleDescGetAttInMetadata(tupdesc);
6590 funcctx->attinmeta = attinmeta;
6592 /* total number of tuples to be returned */
6593 funcctx->max_calls = GetNumConfigOptions();
6595 MemoryContextSwitchTo(oldcontext);
6598 /* stuff done on every call of the function */
6599 funcctx = SRF_PERCALL_SETUP();
6601 call_cntr = funcctx->call_cntr;
6602 max_calls = funcctx->max_calls;
6603 attinmeta = funcctx->attinmeta;
6605 if (call_cntr < max_calls) /* do when there is more left to send */
6607 char *values[NUM_PG_SETTINGS_ATTS];
6613 * Get the next visible GUC variable name and value
6617 GetConfigOptionByNum(call_cntr, (const char **) values, &noshow);
6620 /* bump the counter and get the next config setting */
6621 call_cntr = ++funcctx->call_cntr;
6623 /* make sure we haven't gone too far now */
6624 if (call_cntr >= max_calls)
6625 SRF_RETURN_DONE(funcctx);
6630 tuple = BuildTupleFromCStrings(attinmeta, values);
6632 /* make the tuple into a datum */
6633 result = HeapTupleGetDatum(tuple);
6635 SRF_RETURN_NEXT(funcctx, result);
6639 /* do when there is no more left */
6640 SRF_RETURN_DONE(funcctx);
6645 _ShowOption(struct config_generic * record, bool use_units)
6650 switch (record->vartype)
6654 struct config_bool *conf = (struct config_bool *) record;
6656 if (conf->show_hook)
6657 val = (*conf->show_hook) ();
6659 val = *conf->variable ? "on" : "off";
6665 struct config_int *conf = (struct config_int *) record;
6667 if (conf->show_hook)
6668 val = (*conf->show_hook) ();
6672 * Use int64 arithmetic to avoid overflows in units
6675 int64 result = *conf->variable;
6678 if (use_units && result > 0 &&
6679 (record->flags & GUC_UNIT_MEMORY))
6681 switch (record->flags & GUC_UNIT_MEMORY)
6683 case GUC_UNIT_BLOCKS:
6684 result *= BLCKSZ / 1024;
6686 case GUC_UNIT_XBLOCKS:
6687 result *= XLOG_BLCKSZ / 1024;
6691 if (result % KB_PER_GB == 0)
6693 result /= KB_PER_GB;
6696 else if (result % KB_PER_MB == 0)
6698 result /= KB_PER_MB;
6706 else if (use_units && result > 0 &&
6707 (record->flags & GUC_UNIT_TIME))
6709 switch (record->flags & GUC_UNIT_TIME)
6715 result *= MS_PER_MIN;
6719 if (result % MS_PER_D == 0)
6724 else if (result % MS_PER_H == 0)
6729 else if (result % MS_PER_MIN == 0)
6731 result /= MS_PER_MIN;
6734 else if (result % MS_PER_S == 0)
6747 snprintf(buffer, sizeof(buffer), INT64_FORMAT "%s",
6756 struct config_real *conf = (struct config_real *) record;
6758 if (conf->show_hook)
6759 val = (*conf->show_hook) ();
6762 snprintf(buffer, sizeof(buffer), "%g",
6771 struct config_string *conf = (struct config_string *) record;
6773 if (conf->show_hook)
6774 val = (*conf->show_hook) ();
6775 else if (*conf->variable && **conf->variable)
6776 val = *conf->variable;
6784 struct config_enum *conf = (struct config_enum *) record;
6786 if (conf->show_hook)
6787 val = (*conf->show_hook) ();
6789 val = config_enum_lookup_by_value(conf, *conf->variable);
6794 /* just to keep compiler quiet */
6799 return pstrdup(val);
6804 * Attempt (badly) to detect if a proposed new GUC setting is the same
6805 * as the current value.
6807 * XXX this does not really work because it doesn't account for the
6808 * effects of canonicalization of string values by assign_hooks.
6811 is_newvalue_equal(struct config_generic * record, const char *newvalue)
6813 /* newvalue == NULL isn't supported */
6814 Assert(newvalue != NULL);
6816 switch (record->vartype)
6820 struct config_bool *conf = (struct config_bool *) record;
6823 return parse_bool(newvalue, &newval)
6824 && *conf->variable == newval;
6828 struct config_int *conf = (struct config_int *) record;
6831 return parse_int(newvalue, &newval, record->flags, NULL)
6832 && *conf->variable == newval;
6836 struct config_real *conf = (struct config_real *) record;
6839 return parse_real(newvalue, &newval)
6840 && *conf->variable == newval;
6844 struct config_string *conf = (struct config_string *) record;
6846 return *conf->variable != NULL &&
6847 strcmp(*conf->variable, newvalue) == 0;
6852 struct config_enum *conf = (struct config_enum *) record;
6855 return config_enum_lookup_by_name(conf, newvalue, &newval) &&
6856 *conf->variable == newval;
6867 * These routines dump out all non-default GUC options into a binary
6868 * file that is read by all exec'ed backends. The format is:
6870 * variable name, string, null terminated
6871 * variable value, string, null terminated
6872 * variable source, integer
6875 write_one_nondefault_variable(FILE *fp, struct config_generic * gconf)
6877 if (gconf->source == PGC_S_DEFAULT)
6880 fprintf(fp, "%s", gconf->name);
6883 switch (gconf->vartype)
6887 struct config_bool *conf = (struct config_bool *) gconf;
6889 if (*conf->variable)
6890 fprintf(fp, "true");
6892 fprintf(fp, "false");
6898 struct config_int *conf = (struct config_int *) gconf;
6900 fprintf(fp, "%d", *conf->variable);
6906 struct config_real *conf = (struct config_real *) gconf;
6908 /* Could lose precision here? */
6909 fprintf(fp, "%f", *conf->variable);
6915 struct config_string *conf = (struct config_string *) gconf;
6917 fprintf(fp, "%s", *conf->variable);
6923 struct config_enum *conf = (struct config_enum *) gconf;
6926 config_enum_lookup_by_value(conf, *conf->variable));
6933 fwrite(&gconf->source, sizeof(gconf->source), 1, fp);
6937 write_nondefault_variables(GucContext context)
6941 struct config_generic *cvc_conf;
6944 Assert(context == PGC_POSTMASTER || context == PGC_SIGHUP);
6946 elevel = (context == PGC_SIGHUP) ? LOG : ERROR;
6951 fp = AllocateFile(CONFIG_EXEC_PARAMS_NEW, "w");
6955 (errcode_for_file_access(),
6956 errmsg("could not write to file \"%s\": %m",
6957 CONFIG_EXEC_PARAMS_NEW)));
6962 * custom_variable_classes must be written out first; otherwise we might
6963 * reject custom variable values while reading the file.
6965 cvc_conf = find_option("custom_variable_classes", false, ERROR);
6967 write_one_nondefault_variable(fp, cvc_conf);
6969 for (i = 0; i < num_guc_variables; i++)
6971 struct config_generic *gconf = guc_variables[i];
6973 if (gconf != cvc_conf)
6974 write_one_nondefault_variable(fp, gconf);
6980 (errcode_for_file_access(),
6981 errmsg("could not write to file \"%s\": %m",
6982 CONFIG_EXEC_PARAMS_NEW)));
6987 * Put new file in place. This could delay on Win32, but we don't hold
6988 * any exclusive locks.
6990 rename(CONFIG_EXEC_PARAMS_NEW, CONFIG_EXEC_PARAMS);
6995 * Read string, including null byte from file
6997 * Return NULL on EOF and nothing read
7000 read_string_with_null(FILE *fp)
7009 if ((ch = fgetc(fp)) == EOF)
7014 elog(FATAL, "invalid format of exec config params file");
7017 str = guc_malloc(FATAL, maxlen);
7018 else if (i == maxlen)
7019 str = guc_realloc(FATAL, str, maxlen *= 2);
7028 * This routine loads a previous postmaster dump of its non-default
7032 read_nondefault_variables(void)
7042 fp = AllocateFile(CONFIG_EXEC_PARAMS, "r");
7045 /* File not found is fine */
7046 if (errno != ENOENT)
7048 (errcode_for_file_access(),
7049 errmsg("could not read from file \"%s\": %m",
7050 CONFIG_EXEC_PARAMS)));
7056 struct config_generic *record;
7058 if ((varname = read_string_with_null(fp)) == NULL)
7061 if ((record = find_option(varname, true, FATAL)) == NULL)
7062 elog(FATAL, "failed to locate variable %s in exec config params file", varname);
7063 if ((varvalue = read_string_with_null(fp)) == NULL)
7064 elog(FATAL, "invalid format of exec config params file");
7065 if (fread(&varsource, sizeof(varsource), 1, fp) == 0)
7066 elog(FATAL, "invalid format of exec config params file");
7068 (void) set_config_option(varname, varvalue, record->context,
7069 varsource, GUC_ACTION_SET, true);
7076 #endif /* EXEC_BACKEND */
7080 * A little "long argument" simulation, although not quite GNU
7081 * compliant. Takes a string of the form "some-option=some value" and
7082 * returns name = "some_option" and value = "some value" in malloc'ed
7083 * storage. Note that '-' is converted to '_' in the option name. If
7084 * there is no '=' in the input string then value will be NULL.
7087 ParseLongOption(const char *string, char **name, char **value)
7096 equal_pos = strcspn(string, "=");
7098 if (string[equal_pos] == '=')
7100 *name = guc_malloc(FATAL, equal_pos + 1);
7101 strlcpy(*name, string, equal_pos + 1);
7103 *value = guc_strdup(FATAL, &string[equal_pos + 1]);
7107 /* no equal sign in string */
7108 *name = guc_strdup(FATAL, string);
7112 for (cp = *name; *cp; cp++)
7119 * Handle options fetched from pg_db_role_setting.setconfig,
7120 * pg_proc.proconfig, etc. Caller must specify proper context/source/action.
7122 * The array parameter must be an array of TEXT (it must not be NULL).
7125 ProcessGUCArray(ArrayType *array,
7126 GucContext context, GucSource source, GucAction action)
7130 Assert(array != NULL);
7131 Assert(ARR_ELEMTYPE(array) == TEXTOID);
7132 Assert(ARR_NDIM(array) == 1);
7133 Assert(ARR_LBOUND(array)[0] == 1);
7135 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
7143 d = array_ref(array, 1, &i,
7144 -1 /* varlenarray */ ,
7145 -1 /* TEXT's typlen */ ,
7146 false /* TEXT's typbyval */ ,
7147 'i' /* TEXT's typalign */ ,
7153 s = TextDatumGetCString(d);
7155 ParseLongOption(s, &name, &value);
7159 (errcode(ERRCODE_SYNTAX_ERROR),
7160 errmsg("could not parse setting for parameter \"%s\"",
7166 (void) set_config_option(name, value, context, source, action, true);
7177 * Add an entry to an option array. The array parameter may be NULL
7178 * to indicate the current table entry is NULL.
7181 GUCArrayAdd(ArrayType *array, const char *name, const char *value)
7183 const char *varname;
7191 /* test if the option is valid */
7192 set_config_option(name, value,
7193 superuser() ? PGC_SUSET : PGC_USERSET,
7194 PGC_S_TEST, GUC_ACTION_SET, false);
7196 /* convert name to canonical spelling, so we can use plain strcmp */
7197 (void) GetConfigOptionByName(name, &varname);
7200 newval = palloc(strlen(name) + 1 + strlen(value) + 1);
7201 sprintf(newval, "%s=%s", name, value);
7202 datum = CStringGetTextDatum(newval);
7210 Assert(ARR_ELEMTYPE(array) == TEXTOID);
7211 Assert(ARR_NDIM(array) == 1);
7212 Assert(ARR_LBOUND(array)[0] == 1);
7214 index = ARR_DIMS(array)[0] + 1; /* add after end */
7216 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
7221 d = array_ref(array, 1, &i,
7222 -1 /* varlenarray */ ,
7223 -1 /* TEXT's typlen */ ,
7224 false /* TEXT's typbyval */ ,
7225 'i' /* TEXT's typalign */ ,
7229 current = TextDatumGetCString(d);
7230 if (strncmp(current, newval, strlen(name) + 1) == 0)
7237 a = array_set(array, 1, &index,
7240 -1 /* varlena array */ ,
7241 -1 /* TEXT's typlen */ ,
7242 false /* TEXT's typbyval */ ,
7243 'i' /* TEXT's typalign */ );
7246 a = construct_array(&datum, 1,
7255 * Delete an entry from an option array. The array parameter may be NULL
7256 * to indicate the current table entry is NULL. Also, if the return value
7257 * is NULL then a null should be stored.
7260 GUCArrayDelete(ArrayType *array, const char *name)
7262 const char *varname;
7263 ArrayType *newarray;
7269 /* test if the option is valid */
7270 set_config_option(name, NULL,
7271 superuser() ? PGC_SUSET : PGC_USERSET,
7272 PGC_S_TEST, GUC_ACTION_SET, false);
7274 /* convert name to canonical spelling, so we can use plain strcmp */
7275 (void) GetConfigOptionByName(name, &varname);
7278 /* if array is currently null, then surely nothing to delete */
7285 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
7291 d = array_ref(array, 1, &i,
7292 -1 /* varlenarray */ ,
7293 -1 /* TEXT's typlen */ ,
7294 false /* TEXT's typbyval */ ,
7295 'i' /* TEXT's typalign */ ,
7299 val = TextDatumGetCString(d);
7301 /* ignore entry if it's what we want to delete */
7302 if (strncmp(val, name, strlen(name)) == 0
7303 && val[strlen(name)] == '=')
7307 /* else add it to the output array */
7310 newarray = array_set(newarray, 1, &index,
7313 -1 /* varlenarray */ ,
7314 -1 /* TEXT's typlen */ ,
7315 false /* TEXT's typbyval */ ,
7316 'i' /* TEXT's typalign */ );
7319 newarray = construct_array(&d, 1,
7330 * Given a GUC array, delete all settings from it that our permission
7331 * level allows: if superuser, delete them all; if regular user, only
7332 * those that are PGC_USERSET
7335 GUCArrayReset(ArrayType *array)
7337 ArrayType *newarray;
7341 /* if array is currently null, nothing to do */
7345 /* if we're superuser, we can delete everything */
7352 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
7358 struct config_generic *gconf;
7360 d = array_ref(array, 1, &i,
7361 -1 /* varlenarray */ ,
7362 -1 /* TEXT's typlen */ ,
7363 false /* TEXT's typbyval */ ,
7364 'i' /* TEXT's typalign */ ,
7369 val = TextDatumGetCString(d);
7371 eqsgn = strchr(val, '=');
7374 gconf = find_option(val, false, WARNING);
7378 /* note: superuser-ness was already checked above */
7379 /* skip entry if OK to delete */
7380 if (gconf->context == PGC_USERSET)
7383 /* XXX do we need to worry about database owner? */
7385 /* else add it to the output array */
7388 newarray = array_set(newarray, 1, &index,
7391 -1 /* varlenarray */ ,
7392 -1 /* TEXT's typlen */ ,
7393 false /* TEXT's typbyval */ ,
7394 'i' /* TEXT's typalign */ );
7397 newarray = construct_array(&d, 1,
7410 * assign_hook and show_hook subroutines
7414 assign_log_destination(const char *value, bool doit, GucSource source)
7421 /* Need a modifiable copy of string */
7422 rawstring = pstrdup(value);
7424 /* Parse string into list of identifiers */
7425 if (!SplitIdentifierString(rawstring, ',', &elemlist))
7427 /* syntax error in list */
7429 list_free(elemlist);
7430 ereport(GUC_complaint_elevel(source),
7431 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7432 errmsg("invalid list syntax for parameter \"log_destination\"")));
7436 foreach(l, elemlist)
7438 char *tok = (char *) lfirst(l);
7440 if (pg_strcasecmp(tok, "stderr") == 0)
7441 newlogdest |= LOG_DESTINATION_STDERR;
7442 else if (pg_strcasecmp(tok, "csvlog") == 0)
7443 newlogdest |= LOG_DESTINATION_CSVLOG;
7445 else if (pg_strcasecmp(tok, "syslog") == 0)
7446 newlogdest |= LOG_DESTINATION_SYSLOG;
7449 else if (pg_strcasecmp(tok, "eventlog") == 0)
7450 newlogdest |= LOG_DESTINATION_EVENTLOG;
7454 ereport(GUC_complaint_elevel(source),
7455 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7456 errmsg("unrecognized \"log_destination\" key word: \"%s\"",
7459 list_free(elemlist);
7465 Log_destination = newlogdest;
7468 list_free(elemlist);
7476 assign_syslog_facility(int newval, bool doit, GucSource source)
7479 set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
7486 assign_syslog_ident(const char *ident, bool doit, GucSource source)
7489 set_syslog_parameters(ident, syslog_facility);
7493 #endif /* HAVE_SYSLOG */
7497 assign_session_replication_role(int newval, bool doit, GucSource source)
7500 * Must flush the plan cache when changing replication role; but don't
7501 * flush unnecessarily.
7503 if (doit && SessionReplicationRole != newval)
7512 show_num_temp_buffers(void)
7515 * We show the GUC var until local buffers have been initialized, and
7516 * NLocBuffer afterwards.
7518 static char nbuf[32];
7520 sprintf(nbuf, "%d", NLocBuffer ? NLocBuffer : num_temp_buffers);
7525 assign_phony_autocommit(bool newval, bool doit, GucSource source)
7529 ereport(GUC_complaint_elevel(source),
7530 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7531 errmsg("SET AUTOCOMMIT TO OFF is no longer supported")));
7538 assign_custom_variable_classes(const char *newval, bool doit, GucSource source)
7541 * Check syntax. newval must be a comma separated list of identifiers.
7542 * Whitespace is allowed but removed from the result.
7544 bool hasSpaceAfterToken = false;
7545 const char *cp = newval;
7550 initStringInfo(&buf);
7551 while ((c = *cp++) != '\0')
7553 if (isspace((unsigned char) c))
7556 hasSpaceAfterToken = true;
7562 if (symLen > 0) /* terminate identifier */
7564 appendStringInfoChar(&buf, ',');
7567 hasSpaceAfterToken = false;
7571 if (hasSpaceAfterToken || !(isalnum((unsigned char) c) || c == '_'))
7574 * Syntax error due to token following space after token or
7575 * non-identifier character
7580 appendStringInfoChar(&buf, c);
7584 /* Remove stray ',' at end */
7585 if (symLen == 0 && buf.len > 0)
7586 buf.data[--buf.len] = '\0';
7588 /* GUC wants the result malloc'd */
7589 newval = guc_strdup(LOG, buf.data);
7596 assign_debug_assertions(bool newval, bool doit, GucSource source)
7598 #ifndef USE_ASSERT_CHECKING
7601 ereport(GUC_complaint_elevel(source),
7602 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7603 errmsg("assertion checking is not supported by this build")));
7611 assign_bonjour(bool newval, bool doit, GucSource source)
7616 ereport(GUC_complaint_elevel(source),
7617 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7618 errmsg("Bonjour is not supported by this build")));
7626 assign_ssl(bool newval, bool doit, GucSource source)
7631 ereport(GUC_complaint_elevel(source),
7632 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7633 errmsg("SSL is not supported by this build")));
7641 assign_stage_log_stats(bool newval, bool doit, GucSource source)
7643 if (newval && log_statement_stats)
7645 ereport(GUC_complaint_elevel(source),
7646 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7647 errmsg("cannot enable parameter when \"log_statement_stats\" is true")));
7648 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
7649 if (source != PGC_S_OVERRIDE)
7656 assign_log_stats(bool newval, bool doit, GucSource source)
7659 (log_parser_stats || log_planner_stats || log_executor_stats))
7661 ereport(GUC_complaint_elevel(source),
7662 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7663 errmsg("cannot enable \"log_statement_stats\" when "
7664 "\"log_parser_stats\", \"log_planner_stats\", "
7665 "or \"log_executor_stats\" is true")));
7666 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
7667 if (source != PGC_S_OVERRIDE)
7674 assign_transaction_read_only(bool newval, bool doit, GucSource source)
7676 /* Can't go to r/w mode inside a r/o transaction */
7677 if (newval == false && XactReadOnly && IsSubTransaction())
7679 ereport(GUC_complaint_elevel(source),
7680 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7681 errmsg("cannot set transaction read-write mode inside a read-only transaction")));
7682 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
7683 if (source != PGC_S_OVERRIDE)
7687 /* Can't go to r/w mode while recovery is still active */
7688 if (newval == false && XactReadOnly && RecoveryInProgress())
7690 ereport(GUC_complaint_elevel(source),
7691 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7692 errmsg("cannot set transaction read-write mode during recovery")));
7693 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
7694 if (source != PGC_S_OVERRIDE)
7702 assign_canonical_path(const char *newval, bool doit, GucSource source)
7706 char *canon_val = guc_strdup(ERROR, newval);
7708 canonicalize_path(canon_val);
7716 assign_timezone_abbreviations(const char *newval, bool doit, GucSource source)
7719 * The powerup value shown above for timezone_abbreviations is "UNKNOWN".
7720 * When we see this we just do nothing. If this value isn't overridden
7721 * from the config file then pg_timezone_abbrev_initialize() will
7722 * eventually replace it with "Default". This hack has two purposes: to
7723 * avoid wasting cycles loading values that might soon be overridden from
7724 * the config file, and to avoid trying to read the timezone abbrev files
7725 * during InitializeGUCOptions(). The latter doesn't work in an
7726 * EXEC_BACKEND subprocess because my_exec_path hasn't been set yet and so
7727 * we can't locate PGSHAREDIR. (Essentially the same hack is used to
7728 * delay initializing TimeZone ... if we have any more, we should try to
7729 * clean up and centralize this mechanism ...)
7731 if (strcmp(newval, "UNKNOWN") == 0)
7736 /* Loading abbrev file is expensive, so only do it when value changes */
7737 if (timezone_abbreviations_string == NULL ||
7738 strcmp(timezone_abbreviations_string, newval) != 0)
7743 * If reading config file, only the postmaster should bleat loudly
7744 * about problems. Otherwise, it's just this one process doing it,
7745 * and we use WARNING message level.
7747 if (source == PGC_S_FILE)
7748 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
7751 if (!load_tzoffsets(newval, doit, elevel))
7758 * pg_timezone_abbrev_initialize --- set default value if not done already
7760 * This is called after initial loading of postgresql.conf. If no
7761 * timezone_abbreviations setting was found therein, select default.
7764 pg_timezone_abbrev_initialize(void)
7766 if (strcmp(timezone_abbreviations_string, "UNKNOWN") == 0)
7768 SetConfigOption("timezone_abbreviations", "Default",
7769 PGC_POSTMASTER, PGC_S_ARGV);
7774 show_archive_command(void)
7776 if (XLogArchiveMode)
7777 return XLogArchiveCommand;
7779 return "(disabled)";
7783 assign_tcp_keepalives_idle(int newval, bool doit, GucSource source)
7786 return (pq_setkeepalivesidle(newval, MyProcPort) == STATUS_OK);
7792 show_tcp_keepalives_idle(void)
7794 static char nbuf[16];
7796 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesidle(MyProcPort));
7801 assign_tcp_keepalives_interval(int newval, bool doit, GucSource source)
7804 return (pq_setkeepalivesinterval(newval, MyProcPort) == STATUS_OK);
7810 show_tcp_keepalives_interval(void)
7812 static char nbuf[16];
7814 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesinterval(MyProcPort));
7819 assign_tcp_keepalives_count(int newval, bool doit, GucSource source)
7822 return (pq_setkeepalivescount(newval, MyProcPort) == STATUS_OK);
7828 show_tcp_keepalives_count(void)
7830 static char nbuf[16];
7832 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivescount(MyProcPort));
7837 assign_maxconnections(int newval, bool doit, GucSource source)
7839 if (newval + autovacuum_max_workers + 1 > INT_MAX / 4)
7843 MaxBackends = newval + autovacuum_max_workers + 1;
7849 assign_autovacuum_max_workers(int newval, bool doit, GucSource source)
7851 if (MaxConnections + newval + 1 > INT_MAX / 4)
7855 MaxBackends = MaxConnections + newval + 1;
7861 assign_effective_io_concurrency(int newval, bool doit, GucSource source)
7864 double new_prefetch_pages = 0.0;
7868 * The user-visible GUC parameter is the number of drives (spindles),
7869 * which we need to translate to a number-of-pages-to-prefetch target.
7871 * The expected number of prefetch pages needed to keep N drives busy is:
7873 * drives | I/O requests
7874 * -------+----------------
7877 * 3 | 3/1 + 3/2 + 3/3 = 5 1/2
7878 * 4 | 4/1 + 4/2 + 4/3 + 4/4 = 8 1/3
7881 * This is called the "coupon collector problem" and H(n) is called the
7882 * harmonic series. This could be approximated by n * ln(n), but for
7883 * reasonable numbers of drives we might as well just compute the series.
7885 * Alternatively we could set the target to the number of pages necessary
7886 * so that the expected number of active spindles is some arbitrary
7887 * percentage of the total. This sounds the same but is actually slightly
7888 * different. The result ends up being ln(1-P)/ln((n-1)/n) where P is
7889 * that desired fraction.
7891 * Experimental results show that both of these formulas aren't aggressive
7892 * enough, but we don't really have any better proposals.
7894 * Note that if newval = 0 (disabled), we must set target = 0.
7898 for (i = 1; i <= newval; i++)
7899 new_prefetch_pages += (double) newval / (double) i;
7901 /* This range check shouldn't fail, but let's be paranoid */
7902 if (new_prefetch_pages >= 0.0 && new_prefetch_pages < (double) INT_MAX)
7905 target_prefetch_pages = (int) rint(new_prefetch_pages);
7912 #endif /* USE_PREFETCH */
7916 assign_pgstat_temp_directory(const char *newval, bool doit, GucSource source)
7920 char *canon_val = guc_strdup(ERROR, newval);
7924 canonicalize_path(canon_val);
7926 tname = guc_malloc(ERROR, strlen(canon_val) + 12); /* /pgstat.tmp */
7927 sprintf(tname, "%s/pgstat.tmp", canon_val);
7928 fname = guc_malloc(ERROR, strlen(canon_val) + 13); /* /pgstat.stat */
7929 sprintf(fname, "%s/pgstat.stat", canon_val);
7931 if (pgstat_stat_tmpname)
7932 free(pgstat_stat_tmpname);
7933 pgstat_stat_tmpname = tname;
7934 if (pgstat_stat_filename)
7935 free(pgstat_stat_filename);
7936 pgstat_stat_filename = fname;
7945 assign_application_name(const char *newval, bool doit, GucSource source)
7949 /* Only allow clean ASCII chars in the application name */
7950 char *repval = guc_strdup(ERROR, newval);
7953 for (p = repval; *p; p++)
7955 if (*p < 32 || *p > 126)
7959 /* Update the pg_stat_activity view */
7960 pgstat_report_appname(repval);
7968 #include "guc-file.c"