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-2008, PostgreSQL Global Development Group
10 * Written by Peter Eisentraut <peter_e@gmx.net>.
13 * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.466 2008/08/15 08:37:40 mha Exp $
15 *--------------------------------------------------------------------
28 #include "access/gin.h"
29 #include "access/transam.h"
30 #include "access/twophase.h"
31 #include "access/xact.h"
32 #include "catalog/namespace.h"
33 #include "commands/async.h"
34 #include "commands/prepare.h"
35 #include "commands/vacuum.h"
36 #include "commands/variable.h"
37 #include "commands/trigger.h"
39 #include "libpq/auth.h"
40 #include "libpq/pqformat.h"
41 #include "miscadmin.h"
42 #include "optimizer/cost.h"
43 #include "optimizer/geqo.h"
44 #include "optimizer/paths.h"
45 #include "optimizer/planmain.h"
46 #include "parser/gramparse.h"
47 #include "parser/parse_expr.h"
48 #include "parser/parse_relation.h"
49 #include "parser/parse_type.h"
50 #include "parser/scansup.h"
52 #include "postmaster/autovacuum.h"
53 #include "postmaster/bgwriter.h"
54 #include "postmaster/postmaster.h"
55 #include "postmaster/syslogger.h"
56 #include "postmaster/walwriter.h"
57 #include "regex/regex.h"
58 #include "storage/bufmgr.h"
59 #include "storage/fd.h"
60 #include "storage/freespace.h"
61 #include "tcop/tcopprot.h"
62 #include "tsearch/ts_cache.h"
63 #include "utils/builtins.h"
64 #include "utils/guc_tables.h"
65 #include "utils/memutils.h"
66 #include "utils/pg_locale.h"
67 #include "utils/plancache.h"
68 #include "utils/portal.h"
69 #include "utils/ps_status.h"
70 #include "utils/tzparser.h"
71 #include "utils/xml.h"
74 #define PG_KRB_SRVTAB ""
77 #define PG_KRB_SRVNAM ""
80 #define CONFIG_FILENAME "postgresql.conf"
81 #define HBA_FILENAME "pg_hba.conf"
82 #define IDENT_FILENAME "pg_ident.conf"
85 #define CONFIG_EXEC_PARAMS "global/config_exec_params"
86 #define CONFIG_EXEC_PARAMS_NEW "global/config_exec_params.new"
89 /* upper limit for GUC variables measured in kilobytes of memory */
91 #define MAX_KILOBYTES INT_MAX
93 #define MAX_KILOBYTES (INT_MAX / 1024)
96 #define KB_PER_MB (1024)
97 #define KB_PER_GB (1024*1024)
101 #define MS_PER_MIN (1000 * 60)
103 #define S_PER_H (60 * 60)
104 #define MS_PER_H (1000 * 60 * 60)
105 #define MIN_PER_D (60 * 24)
106 #define S_PER_D (60 * 60 * 24)
107 #define MS_PER_D (1000 * 60 * 60 * 24)
109 /* XXX these should appear in other modules' header files */
110 extern bool Log_disconnections;
111 extern int CommitDelay;
112 extern int CommitSiblings;
113 extern char *default_tablespace;
114 extern char *temp_tablespaces;
115 extern bool synchronize_seqscans;
116 extern bool fullPageWrites;
119 extern bool trace_sort;
121 #ifdef TRACE_SYNCSCAN
122 extern bool trace_syncscan;
124 #ifdef DEBUG_BOUNDED_SORT
125 extern bool optimize_bounded_sort;
129 extern char *SSLCipherSuites;
133 static const char *assign_log_destination(const char *value,
134 bool doit, GucSource source);
137 static int syslog_facility = LOG_LOCAL0;
139 static bool assign_syslog_facility(int newval,
140 bool doit, GucSource source);
141 static const char *assign_syslog_ident(const char *ident,
142 bool doit, GucSource source);
145 static bool assign_session_replication_role(int newval, bool doit,
147 static const char *show_num_temp_buffers(void);
148 static bool assign_phony_autocommit(bool newval, bool doit, GucSource source);
149 static const char *assign_custom_variable_classes(const char *newval, bool doit,
151 static bool assign_debug_assertions(bool newval, bool doit, GucSource source);
152 static bool assign_ssl(bool newval, bool doit, GucSource source);
153 static bool assign_stage_log_stats(bool newval, bool doit, GucSource source);
154 static bool assign_log_stats(bool newval, bool doit, GucSource source);
155 static bool assign_transaction_read_only(bool newval, bool doit, GucSource source);
156 static const char *assign_canonical_path(const char *newval, bool doit, GucSource source);
157 static const char *assign_timezone_abbreviations(const char *newval, bool doit, GucSource source);
158 static const char *show_archive_command(void);
159 static bool assign_tcp_keepalives_idle(int newval, bool doit, GucSource source);
160 static bool assign_tcp_keepalives_interval(int newval, bool doit, GucSource source);
161 static bool assign_tcp_keepalives_count(int newval, bool doit, GucSource source);
162 static const char *show_tcp_keepalives_idle(void);
163 static const char *show_tcp_keepalives_interval(void);
164 static const char *show_tcp_keepalives_count(void);
165 static bool assign_autovacuum_max_workers(int newval, bool doit, GucSource source);
166 static bool assign_maxconnections(int newval, bool doit, GucSource source);
167 static const char *assign_pgstat_temp_directory(const char *newval, bool doit, GucSource source);
169 static char *config_enum_get_options(struct config_enum *record,
170 const char *prefix, const char *suffix);
174 * Options for enum values defined in this module.
178 * We have different sets for client and server message level options because
179 * they sort slightly different (see "log" level)
181 static const struct config_enum_entry client_message_level_options[] = {
182 {"debug", DEBUG2, true},
183 {"debug5", DEBUG5, false},
184 {"debug4", DEBUG4, false},
185 {"debug3", DEBUG3, false},
186 {"debug2", DEBUG2, false},
187 {"debug1", DEBUG1, false},
189 {"info", INFO, true},
190 {"notice", NOTICE, false},
191 {"warning", WARNING, false},
192 {"error", ERROR, false},
193 {"fatal", FATAL, true},
194 {"panic", PANIC, true},
198 static const struct config_enum_entry server_message_level_options[] = {
199 {"debug", DEBUG2, true},
200 {"debug5", DEBUG5, false},
201 {"debug4", DEBUG4, false},
202 {"debug3", DEBUG3, false},
203 {"debug2", DEBUG2, false},
204 {"debug1", DEBUG1, false},
205 {"info", INFO, false},
206 {"notice", NOTICE, false},
207 {"warning", WARNING, false},
208 {"error", ERROR, false},
210 {"fatal", FATAL, false},
211 {"panic", PANIC, false},
215 static const struct config_enum_entry log_error_verbosity_options[] = {
216 {"terse", PGERROR_TERSE, false},
217 {"default", PGERROR_DEFAULT, false},
218 {"verbose", PGERROR_VERBOSE, false},
222 static const struct config_enum_entry log_statement_options[] = {
223 {"none", LOGSTMT_NONE, false},
224 {"ddl", LOGSTMT_DDL, false},
225 {"mod", LOGSTMT_MOD, false},
226 {"all", LOGSTMT_ALL, false},
230 static const struct config_enum_entry regex_flavor_options[] = {
231 {"advanced", REG_ADVANCED, false},
232 {"extended", REG_EXTENDED, false},
233 {"basic", REG_BASIC, false},
237 static const struct config_enum_entry isolation_level_options[] = {
238 {"serializable", XACT_SERIALIZABLE, false},
239 {"repeatable read", XACT_REPEATABLE_READ, false},
240 {"read committed", XACT_READ_COMMITTED, false},
241 {"read uncommitted", XACT_READ_UNCOMMITTED, false},
245 static const struct config_enum_entry session_replication_role_options[] = {
246 {"origin", SESSION_REPLICATION_ROLE_ORIGIN, false},
247 {"replica", SESSION_REPLICATION_ROLE_REPLICA, false},
248 {"local", SESSION_REPLICATION_ROLE_LOCAL, false},
253 static const struct config_enum_entry syslog_facility_options[] = {
254 {"local0", LOG_LOCAL0, false},
255 {"local1", LOG_LOCAL1, false},
256 {"local2", LOG_LOCAL2, false},
257 {"local3", LOG_LOCAL3, false},
258 {"local4", LOG_LOCAL4, false},
259 {"local5", LOG_LOCAL5, false},
260 {"local6", LOG_LOCAL6, false},
261 {"local7", LOG_LOCAL7, false},
266 static const struct config_enum_entry track_function_options[] = {
267 {"none", TRACK_FUNC_OFF, false},
268 {"pl", TRACK_FUNC_PL, false},
269 {"all", TRACK_FUNC_ALL, false},
273 static const struct config_enum_entry xmlbinary_options[] = {
274 {"base64", XMLBINARY_BASE64, false},
275 {"hex", XMLBINARY_HEX, false},
279 static const struct config_enum_entry xmloption_options[] = {
280 {"content", XMLOPTION_CONTENT, false},
281 {"document", XMLOPTION_DOCUMENT, false},
286 * Although only "on", "off", and "safe_encoding" are documented, we
287 * accept all the likely variants of "on" and "off".
289 static const struct config_enum_entry backslash_quote_options[] = {
290 {"safe_encoding", BACKSLASH_QUOTE_SAFE_ENCODING, false},
291 {"on", BACKSLASH_QUOTE_ON, false},
292 {"off", BACKSLASH_QUOTE_OFF, false},
293 {"true", BACKSLASH_QUOTE_ON, true},
294 {"false", BACKSLASH_QUOTE_OFF, true},
295 {"yes", BACKSLASH_QUOTE_ON, true},
296 {"no", BACKSLASH_QUOTE_OFF, true},
297 {"1", BACKSLASH_QUOTE_ON, true},
298 {"0", BACKSLASH_QUOTE_OFF, true},
303 * Options for enum values stored in other modules
305 extern const struct config_enum_entry sync_method_options[];
308 * GUC option variables that are exported from this module
310 #ifdef USE_ASSERT_CHECKING
311 bool assert_enabled = true;
313 bool assert_enabled = false;
315 bool log_duration = false;
316 bool Debug_print_plan = false;
317 bool Debug_print_parse = false;
318 bool Debug_print_rewritten = false;
319 bool Debug_pretty_print = false;
321 bool log_parser_stats = false;
322 bool log_planner_stats = false;
323 bool log_executor_stats = false;
324 bool log_statement_stats = false; /* this is sort of all three
326 bool log_btree_build_stats = false;
328 bool check_function_bodies = true;
329 bool default_with_oids = false;
330 bool SQL_inheritance = true;
332 bool Password_encryption = true;
334 int log_min_error_statement = ERROR;
335 int log_min_messages = WARNING;
336 int client_min_messages = NOTICE;
337 int log_min_duration_statement = -1;
338 int log_temp_files = -1;
340 int num_temp_buffers = 1000;
342 char *ConfigFileName;
345 char *external_pid_file;
347 char *pgstat_temp_directory;
349 int tcp_keepalives_idle;
350 int tcp_keepalives_interval;
351 int tcp_keepalives_count;
354 * These variables are all dummies that don't do anything, except in some
355 * cases provide the value for SHOW to display. The real state is elsewhere
356 * and is kept in sync by assign_hooks.
358 static char *log_destination_string;
361 static char *syslog_ident_str;
363 static bool phony_autocommit;
364 static bool session_auth_is_superuser;
365 static double phony_random_seed;
366 static char *client_encoding_string;
367 static char *datestyle_string;
368 static char *locale_collate;
369 static char *locale_ctype;
370 static char *server_encoding_string;
371 static char *server_version_string;
372 static int server_version_num;
373 static char *timezone_string;
374 static char *log_timezone_string;
375 static char *timezone_abbreviations_string;
376 static char *XactIsoLevel_string;
377 static char *data_directory;
378 static char *custom_variable_classes;
379 static int max_function_args;
380 static int max_index_keys;
381 static int max_identifier_length;
382 static int block_size;
383 static int segment_size;
384 static int wal_block_size;
385 static int wal_segment_size;
386 static bool integer_datetimes;
388 /* should be static, but commands/variable.c needs to get at these */
390 char *session_authorization_string;
394 * Displayable names for context types (enum GucContext)
396 * Note: these strings are deliberately not localized.
398 const char *const GucContext_Names[] =
400 /* PGC_INTERNAL */ "internal",
401 /* PGC_POSTMASTER */ "postmaster",
402 /* PGC_SIGHUP */ "sighup",
403 /* PGC_BACKEND */ "backend",
404 /* PGC_SUSET */ "superuser",
405 /* PGC_USERSET */ "user"
409 * Displayable names for source types (enum GucSource)
411 * Note: these strings are deliberately not localized.
413 const char *const GucSource_Names[] =
415 /* PGC_S_DEFAULT */ "default",
416 /* PGC_S_ENV_VAR */ "environment variable",
417 /* PGC_S_FILE */ "configuration file",
418 /* PGC_S_ARGV */ "command line",
419 /* PGC_S_DATABASE */ "database",
420 /* PGC_S_USER */ "user",
421 /* PGC_S_CLIENT */ "client",
422 /* PGC_S_OVERRIDE */ "override",
423 /* PGC_S_INTERACTIVE */ "interactive",
424 /* PGC_S_TEST */ "test",
425 /* PGC_S_SESSION */ "session"
429 * Displayable names for the groupings defined in enum config_group
431 const char *const config_group_names[] =
434 gettext_noop("Ungrouped"),
436 gettext_noop("File Locations"),
438 gettext_noop("Connections and Authentication"),
439 /* CONN_AUTH_SETTINGS */
440 gettext_noop("Connections and Authentication / Connection Settings"),
441 /* CONN_AUTH_SECURITY */
442 gettext_noop("Connections and Authentication / Security and Authentication"),
444 gettext_noop("Resource Usage"),
446 gettext_noop("Resource Usage / Memory"),
448 gettext_noop("Resource Usage / Free Space Map"),
449 /* RESOURCES_KERNEL */
450 gettext_noop("Resource Usage / Kernel Resources"),
452 gettext_noop("Write-Ahead Log"),
454 gettext_noop("Write-Ahead Log / Settings"),
455 /* WAL_CHECKPOINTS */
456 gettext_noop("Write-Ahead Log / Checkpoints"),
458 gettext_noop("Query Tuning"),
459 /* QUERY_TUNING_METHOD */
460 gettext_noop("Query Tuning / Planner Method Configuration"),
461 /* QUERY_TUNING_COST */
462 gettext_noop("Query Tuning / Planner Cost Constants"),
463 /* QUERY_TUNING_GEQO */
464 gettext_noop("Query Tuning / Genetic Query Optimizer"),
465 /* QUERY_TUNING_OTHER */
466 gettext_noop("Query Tuning / Other Planner Options"),
468 gettext_noop("Reporting and Logging"),
470 gettext_noop("Reporting and Logging / Where to Log"),
472 gettext_noop("Reporting and Logging / When to Log"),
474 gettext_noop("Reporting and Logging / What to Log"),
476 gettext_noop("Statistics"),
477 /* STATS_MONITORING */
478 gettext_noop("Statistics / Monitoring"),
479 /* STATS_COLLECTOR */
480 gettext_noop("Statistics / Query and Index Statistics Collector"),
482 gettext_noop("Autovacuum"),
484 gettext_noop("Client Connection Defaults"),
485 /* CLIENT_CONN_STATEMENT */
486 gettext_noop("Client Connection Defaults / Statement Behavior"),
487 /* CLIENT_CONN_LOCALE */
488 gettext_noop("Client Connection Defaults / Locale and Formatting"),
489 /* CLIENT_CONN_OTHER */
490 gettext_noop("Client Connection Defaults / Other Defaults"),
491 /* LOCK_MANAGEMENT */
492 gettext_noop("Lock Management"),
494 gettext_noop("Version and Platform Compatibility"),
495 /* COMPAT_OPTIONS_PREVIOUS */
496 gettext_noop("Version and Platform Compatibility / Previous PostgreSQL Versions"),
497 /* COMPAT_OPTIONS_CLIENT */
498 gettext_noop("Version and Platform Compatibility / Other Platforms and Clients"),
500 gettext_noop("Preset Options"),
502 gettext_noop("Customized Options"),
503 /* DEVELOPER_OPTIONS */
504 gettext_noop("Developer Options"),
505 /* help_config wants this array to be null-terminated */
510 * Displayable names for GUC variable types (enum config_type)
512 * Note: these strings are deliberately not localized.
514 const char *const config_type_names[] =
516 /* PGC_BOOL */ "bool",
517 /* PGC_INT */ "integer",
518 /* PGC_REAL */ "real",
519 /* PGC_STRING */ "string",
520 /* PGC_ENUM */ "enum"
525 * Contents of GUC tables
527 * See src/backend/utils/misc/README for design notes.
531 * 1. Declare a global variable of type bool, int, double, or char*
532 * and make use of it.
534 * 2. Decide at what times it's safe to set the option. See guc.h for
537 * 3. Decide on a name, a default value, upper and lower bounds (if
540 * 4. Add a record below.
542 * 5. Add it to src/backend/utils/misc/postgresql.conf.sample, if
545 * 6. Don't forget to document the option (at least in config.sgml).
547 * 7. If it's a new GUC_LIST option you must edit pg_dumpall.c to ensure
548 * it is not single quoted at dump time.
552 /******** option records follow ********/
554 static struct config_bool ConfigureNamesBool[] =
557 {"enable_seqscan", PGC_USERSET, QUERY_TUNING_METHOD,
558 gettext_noop("Enables the planner's use of sequential-scan plans."),
565 {"enable_indexscan", PGC_USERSET, QUERY_TUNING_METHOD,
566 gettext_noop("Enables the planner's use of index-scan plans."),
573 {"enable_bitmapscan", PGC_USERSET, QUERY_TUNING_METHOD,
574 gettext_noop("Enables the planner's use of bitmap-scan plans."),
581 {"enable_tidscan", PGC_USERSET, QUERY_TUNING_METHOD,
582 gettext_noop("Enables the planner's use of TID scan plans."),
589 {"enable_sort", PGC_USERSET, QUERY_TUNING_METHOD,
590 gettext_noop("Enables the planner's use of explicit sort steps."),
597 {"enable_hashagg", PGC_USERSET, QUERY_TUNING_METHOD,
598 gettext_noop("Enables the planner's use of hashed aggregation plans."),
605 {"enable_nestloop", PGC_USERSET, QUERY_TUNING_METHOD,
606 gettext_noop("Enables the planner's use of nested-loop join plans."),
613 {"enable_mergejoin", PGC_USERSET, QUERY_TUNING_METHOD,
614 gettext_noop("Enables the planner's use of merge join plans."),
621 {"enable_hashjoin", PGC_USERSET, QUERY_TUNING_METHOD,
622 gettext_noop("Enables the planner's use of hash join plans."),
629 {"constraint_exclusion", PGC_USERSET, QUERY_TUNING_OTHER,
630 gettext_noop("Enables the planner to use constraints to optimize queries."),
631 gettext_noop("Child table scans will be skipped if their "
632 "constraints guarantee that no rows match the query.")
634 &constraint_exclusion,
638 {"geqo", PGC_USERSET, QUERY_TUNING_GEQO,
639 gettext_noop("Enables genetic query optimization."),
640 gettext_noop("This algorithm attempts to do planning without "
641 "exhaustive searching.")
647 /* Not for general use --- used by SET SESSION AUTHORIZATION */
648 {"is_superuser", PGC_INTERNAL, UNGROUPED,
649 gettext_noop("Shows whether the current user is a superuser."),
651 GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
653 &session_auth_is_superuser,
657 {"ssl", PGC_POSTMASTER, CONN_AUTH_SECURITY,
658 gettext_noop("Enables SSL connections."),
662 false, assign_ssl, NULL
665 {"fsync", PGC_SIGHUP, WAL_SETTINGS,
666 gettext_noop("Forces synchronization of updates to disk."),
667 gettext_noop("The server will use the fsync() system call in several places to make "
668 "sure that updates are physically written to disk. This insures "
669 "that a database cluster will recover to a consistent state after "
670 "an operating system or hardware crash.")
676 {"synchronous_commit", PGC_USERSET, WAL_SETTINGS,
677 gettext_noop("Sets immediate fsync at commit."),
684 {"zero_damaged_pages", PGC_SUSET, DEVELOPER_OPTIONS,
685 gettext_noop("Continues processing past damaged page headers."),
686 gettext_noop("Detection of a damaged page header normally causes PostgreSQL to "
687 "report an error, aborting the current transaction. Setting "
688 "zero_damaged_pages to true causes the system to instead report a "
689 "warning, zero out the damaged page, and continue processing. This "
690 "behavior will destroy data, namely all the rows on the damaged page."),
697 {"full_page_writes", PGC_SIGHUP, WAL_SETTINGS,
698 gettext_noop("Writes full pages to WAL when first modified after a checkpoint."),
699 gettext_noop("A page write in process during an operating system crash might be "
700 "only partially written to disk. During recovery, the row changes "
701 "stored in WAL are not enough to recover. This option writes "
702 "pages when first modified after a checkpoint to WAL so full recovery "
709 {"silent_mode", PGC_POSTMASTER, LOGGING_WHEN,
710 gettext_noop("Runs the server silently."),
711 gettext_noop("If this parameter is set, the server will automatically run in the "
712 "background and any controlling terminals are dissociated.")
718 {"log_checkpoints", PGC_SIGHUP, LOGGING_WHAT,
719 gettext_noop("Logs each checkpoint."),
726 {"log_connections", PGC_BACKEND, LOGGING_WHAT,
727 gettext_noop("Logs each successful connection."),
734 {"log_disconnections", PGC_BACKEND, LOGGING_WHAT,
735 gettext_noop("Logs end of a session, including duration."),
742 {"debug_assertions", PGC_USERSET, DEVELOPER_OPTIONS,
743 gettext_noop("Turns on various assertion checks."),
744 gettext_noop("This is a debugging aid."),
748 #ifdef USE_ASSERT_CHECKING
753 assign_debug_assertions, NULL
756 /* currently undocumented, so don't show in SHOW ALL */
757 {"exit_on_error", PGC_USERSET, UNGROUPED,
758 gettext_noop("No description available."),
760 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
766 {"log_duration", PGC_SUSET, LOGGING_WHAT,
767 gettext_noop("Logs the duration of each completed SQL statement."),
774 {"debug_print_parse", PGC_USERSET, LOGGING_WHAT,
775 gettext_noop("Prints the parse tree to the server log."),
782 {"debug_print_rewritten", PGC_USERSET, LOGGING_WHAT,
783 gettext_noop("Prints the parse tree after rewriting to server log."),
786 &Debug_print_rewritten,
790 {"debug_print_plan", PGC_USERSET, LOGGING_WHAT,
791 gettext_noop("Prints the execution plan to server log."),
798 {"debug_pretty_print", PGC_USERSET, LOGGING_WHAT,
799 gettext_noop("Indents parse and plan tree displays."),
806 {"log_parser_stats", PGC_SUSET, STATS_MONITORING,
807 gettext_noop("Writes parser performance statistics to the server log."),
811 false, assign_stage_log_stats, NULL
814 {"log_planner_stats", PGC_SUSET, STATS_MONITORING,
815 gettext_noop("Writes planner performance statistics to the server log."),
819 false, assign_stage_log_stats, NULL
822 {"log_executor_stats", PGC_SUSET, STATS_MONITORING,
823 gettext_noop("Writes executor performance statistics to the server log."),
827 false, assign_stage_log_stats, NULL
830 {"log_statement_stats", PGC_SUSET, STATS_MONITORING,
831 gettext_noop("Writes cumulative performance statistics to the server log."),
834 &log_statement_stats,
835 false, assign_log_stats, NULL
837 #ifdef BTREE_BUILD_STATS
839 {"log_btree_build_stats", PGC_SUSET, DEVELOPER_OPTIONS,
840 gettext_noop("No description available."),
844 &log_btree_build_stats,
850 {"track_activities", PGC_SUSET, STATS_COLLECTOR,
851 gettext_noop("Collects information about executing commands."),
852 gettext_noop("Enables the collection of information on the currently "
853 "executing command of each session, along with "
854 "the time at which that command began execution.")
856 &pgstat_track_activities,
860 {"track_counts", PGC_SUSET, STATS_COLLECTOR,
861 gettext_noop("Collects statistics on database activity."),
864 &pgstat_track_counts,
869 {"update_process_title", PGC_SUSET, STATS_COLLECTOR,
870 gettext_noop("Updates the process title to show the active SQL command."),
871 gettext_noop("Enables updating of the process title every time a new SQL command is received by the server.")
873 &update_process_title,
878 {"autovacuum", PGC_SIGHUP, AUTOVACUUM,
879 gettext_noop("Starts the autovacuum subprocess."),
882 &autovacuum_start_daemon,
887 {"trace_notify", PGC_USERSET, DEVELOPER_OPTIONS,
888 gettext_noop("Generates debugging output for LISTEN and NOTIFY."),
898 {"trace_locks", PGC_SUSET, DEVELOPER_OPTIONS,
899 gettext_noop("No description available."),
907 {"trace_userlocks", PGC_SUSET, DEVELOPER_OPTIONS,
908 gettext_noop("No description available."),
916 {"trace_lwlocks", PGC_SUSET, DEVELOPER_OPTIONS,
917 gettext_noop("No description available."),
925 {"debug_deadlocks", PGC_SUSET, DEVELOPER_OPTIONS,
926 gettext_noop("No description available."),
936 {"log_lock_waits", PGC_SUSET, LOGGING_WHAT,
937 gettext_noop("Logs long lock waits."),
945 {"log_hostname", PGC_SIGHUP, LOGGING_WHAT,
946 gettext_noop("Logs the host name in the connection logs."),
947 gettext_noop("By default, connection logs only show the IP address "
948 "of the connecting host. If you want them to show the host name you "
949 "can turn this on, but depending on your host name resolution "
950 "setup it might impose a non-negligible performance penalty.")
956 {"sql_inheritance", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
957 gettext_noop("Causes subtables to be included by default in various commands."),
964 {"password_encryption", PGC_USERSET, CONN_AUTH_SECURITY,
965 gettext_noop("Encrypt passwords."),
966 gettext_noop("When a password is specified in CREATE USER or "
967 "ALTER USER without writing either ENCRYPTED or UNENCRYPTED, "
968 "this parameter determines whether the password is to be encrypted.")
970 &Password_encryption,
974 {"transform_null_equals", PGC_USERSET, COMPAT_OPTIONS_CLIENT,
975 gettext_noop("Treats \"expr=NULL\" as \"expr IS NULL\"."),
976 gettext_noop("When turned on, expressions of the form expr = NULL "
977 "(or NULL = expr) are treated as expr IS NULL, that is, they "
978 "return true if expr evaluates to the null value, and false "
979 "otherwise. The correct behavior of expr = NULL is to always "
980 "return null (unknown).")
982 &Transform_null_equals,
986 {"db_user_namespace", PGC_SIGHUP, CONN_AUTH_SECURITY,
987 gettext_noop("Enables per-database user names."),
994 /* only here for backwards compatibility */
995 {"autocommit", PGC_USERSET, CLIENT_CONN_STATEMENT,
996 gettext_noop("This parameter doesn't do anything."),
997 gettext_noop("It's just here so that we won't choke on SET AUTOCOMMIT TO ON from 7.3-vintage clients."),
998 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
1001 true, assign_phony_autocommit, NULL
1004 {"default_transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
1005 gettext_noop("Sets the default read-only status of new transactions."),
1008 &DefaultXactReadOnly,
1012 {"transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
1013 gettext_noop("Sets the current transaction's read-only status."),
1015 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1018 false, assign_transaction_read_only, NULL
1021 {"add_missing_from", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1022 gettext_noop("Automatically adds missing table references to FROM clauses."),
1029 {"check_function_bodies", PGC_USERSET, CLIENT_CONN_STATEMENT,
1030 gettext_noop("Check function bodies during CREATE FUNCTION."),
1033 &check_function_bodies,
1037 {"array_nulls", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1038 gettext_noop("Enable input of NULL elements in arrays."),
1039 gettext_noop("When turned on, unquoted NULL in an array input "
1040 "value means a null value; "
1041 "otherwise it is taken literally.")
1047 {"default_with_oids", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1048 gettext_noop("Create new tables with OIDs by default."),
1055 {"logging_collector", PGC_POSTMASTER, LOGGING_WHERE,
1056 gettext_noop("Start a subprocess to capture stderr output and/or csvlogs into log files."),
1063 {"log_truncate_on_rotation", PGC_SIGHUP, LOGGING_WHERE,
1064 gettext_noop("Truncate existing log files of same name during log rotation."),
1067 &Log_truncate_on_rotation,
1073 {"trace_sort", PGC_USERSET, DEVELOPER_OPTIONS,
1074 gettext_noop("Emit information about resource usage in sorting."),
1083 #ifdef TRACE_SYNCSCAN
1084 /* this is undocumented because not exposed in a standard build */
1086 {"trace_syncscan", PGC_USERSET, DEVELOPER_OPTIONS,
1087 gettext_noop("Generate debugging output for synchronized scanning."),
1096 #ifdef DEBUG_BOUNDED_SORT
1097 /* this is undocumented because not exposed in a standard build */
1100 "optimize_bounded_sort", PGC_USERSET, QUERY_TUNING_METHOD,
1101 gettext_noop("Enable bounded sorting using heap sort."),
1105 &optimize_bounded_sort,
1112 {"wal_debug", PGC_SUSET, DEVELOPER_OPTIONS,
1113 gettext_noop("Emit WAL-related debugging output."),
1123 {"integer_datetimes", PGC_INTERNAL, PRESET_OPTIONS,
1124 gettext_noop("Datetimes are integer based."),
1126 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1129 #ifdef HAVE_INT64_TIMESTAMP
1137 {"krb_caseins_users", PGC_POSTMASTER, CONN_AUTH_SECURITY,
1138 gettext_noop("Sets whether Kerberos and GSSAPI user names should be treated as case-insensitive."),
1141 &pg_krb_caseins_users,
1146 {"escape_string_warning", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1147 gettext_noop("Warn about backslash escapes in ordinary string literals."),
1150 &escape_string_warning,
1155 {"standard_conforming_strings", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1156 gettext_noop("Causes '...' strings to treat backslashes literally."),
1160 &standard_conforming_strings,
1165 {"synchronize_seqscans", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1166 gettext_noop("Enable synchronized sequential scans."),
1169 &synchronize_seqscans,
1174 {"archive_mode", PGC_POSTMASTER, WAL_SETTINGS,
1175 gettext_noop("Allows archiving of WAL files using archive_command."),
1183 {"allow_system_table_mods", PGC_POSTMASTER, DEVELOPER_OPTIONS,
1184 gettext_noop("Allows modifications of the structure of system tables."),
1188 &allowSystemTableMods,
1193 {"ignore_system_indexes", PGC_BACKEND, DEVELOPER_OPTIONS,
1194 gettext_noop("Disables reading from system indexes."),
1195 gettext_noop("It does not prevent updating the indexes, so it is safe "
1196 "to use. The worst consequence is slowness."),
1199 &IgnoreSystemIndexes,
1203 /* End-of-list marker */
1205 {NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL
1210 static struct config_int ConfigureNamesInt[] =
1213 {"archive_timeout", PGC_SIGHUP, WAL_SETTINGS,
1214 gettext_noop("Forces a switch to the next xlog file if a "
1215 "new file has not been started within N seconds."),
1219 &XLogArchiveTimeout,
1220 0, 0, INT_MAX, NULL, NULL
1223 {"post_auth_delay", PGC_BACKEND, DEVELOPER_OPTIONS,
1224 gettext_noop("Waits N seconds on connection startup after authentication."),
1225 gettext_noop("This allows attaching a debugger to the process."),
1226 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1229 0, 0, INT_MAX, NULL, NULL
1232 {"default_statistics_target", PGC_USERSET, QUERY_TUNING_OTHER,
1233 gettext_noop("Sets the default statistics target."),
1234 gettext_noop("This applies to table columns that have not had a "
1235 "column-specific target set via ALTER TABLE SET STATISTICS.")
1237 &default_statistics_target,
1238 10, 1, 1000, NULL, NULL
1241 {"from_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1242 gettext_noop("Sets the FROM-list size beyond which subqueries "
1243 "are not collapsed."),
1244 gettext_noop("The planner will merge subqueries into upper "
1245 "queries if the resulting FROM list would have no more than "
1248 &from_collapse_limit,
1249 8, 1, INT_MAX, NULL, NULL
1252 {"join_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1253 gettext_noop("Sets the FROM-list size beyond which JOIN "
1254 "constructs are not flattened."),
1255 gettext_noop("The planner will flatten explicit JOIN "
1256 "constructs into lists of FROM items whenever a "
1257 "list of no more than this many items would result.")
1259 &join_collapse_limit,
1260 8, 1, INT_MAX, NULL, NULL
1263 {"geqo_threshold", PGC_USERSET, QUERY_TUNING_GEQO,
1264 gettext_noop("Sets the threshold of FROM items beyond which GEQO is used."),
1268 12, 2, INT_MAX, NULL, NULL
1271 {"geqo_effort", PGC_USERSET, QUERY_TUNING_GEQO,
1272 gettext_noop("GEQO: effort is used to set the default for other GEQO parameters."),
1276 DEFAULT_GEQO_EFFORT, MIN_GEQO_EFFORT, MAX_GEQO_EFFORT, NULL, NULL
1279 {"geqo_pool_size", PGC_USERSET, QUERY_TUNING_GEQO,
1280 gettext_noop("GEQO: number of individuals in the population."),
1281 gettext_noop("Zero selects a suitable default value.")
1284 0, 0, INT_MAX, NULL, NULL
1287 {"geqo_generations", PGC_USERSET, QUERY_TUNING_GEQO,
1288 gettext_noop("GEQO: number of iterations of the algorithm."),
1289 gettext_noop("Zero selects a suitable default value.")
1292 0, 0, INT_MAX, NULL, NULL
1296 /* This is PGC_SIGHUP so all backends have the same value. */
1297 {"deadlock_timeout", PGC_SIGHUP, LOCK_MANAGEMENT,
1298 gettext_noop("Sets the time to wait on a lock before checking for deadlock."),
1303 1000, 1, INT_MAX / 1000, NULL, NULL
1307 * Note: MaxBackends is limited to INT_MAX/4 because some places compute
1308 * 4*MaxBackends without any overflow check. This check is made in
1309 * assign_maxconnections, since MaxBackends is computed as MaxConnections
1310 * plus autovacuum_max_workers.
1312 * Likewise we have to limit NBuffers to INT_MAX/2.
1315 {"max_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1316 gettext_noop("Sets the maximum number of concurrent connections."),
1320 100, 1, INT_MAX / 4, assign_maxconnections, NULL
1324 {"superuser_reserved_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1325 gettext_noop("Sets the number of connection slots reserved for superusers."),
1329 3, 0, INT_MAX / 4, NULL, NULL
1333 {"shared_buffers", PGC_POSTMASTER, RESOURCES_MEM,
1334 gettext_noop("Sets the number of shared memory buffers used by the server."),
1339 1024, 16, INT_MAX / 2, NULL, NULL
1343 {"temp_buffers", PGC_USERSET, RESOURCES_MEM,
1344 gettext_noop("Sets the maximum number of temporary buffers used by each session."),
1349 1024, 100, INT_MAX / 2, NULL, show_num_temp_buffers
1353 {"port", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1354 gettext_noop("Sets the TCP port the server listens on."),
1358 DEF_PGPORT, 1, 65535, NULL, NULL
1362 {"unix_socket_permissions", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1363 gettext_noop("Sets the access permissions of the Unix-domain socket."),
1364 gettext_noop("Unix-domain sockets use the usual Unix file system "
1365 "permission set. The parameter value is expected to be a numeric mode "
1366 "specification in the form accepted by the chmod and umask system "
1367 "calls. (To use the customary octal format the number must start with "
1370 &Unix_socket_permissions,
1371 0777, 0000, 0777, NULL, NULL
1375 {"work_mem", PGC_USERSET, RESOURCES_MEM,
1376 gettext_noop("Sets the maximum memory to be used for query workspaces."),
1377 gettext_noop("This much memory can be used by each internal "
1378 "sort operation and hash table before switching to "
1379 "temporary disk files."),
1383 1024, 64, MAX_KILOBYTES, NULL, NULL
1387 {"maintenance_work_mem", PGC_USERSET, RESOURCES_MEM,
1388 gettext_noop("Sets the maximum memory to be used for maintenance operations."),
1389 gettext_noop("This includes operations such as VACUUM and CREATE INDEX."),
1392 &maintenance_work_mem,
1393 16384, 1024, MAX_KILOBYTES, NULL, NULL
1397 {"max_stack_depth", PGC_SUSET, RESOURCES_MEM,
1398 gettext_noop("Sets the maximum stack depth, in kilobytes."),
1403 100, 100, MAX_KILOBYTES, assign_max_stack_depth, NULL
1407 {"vacuum_cost_page_hit", PGC_USERSET, RESOURCES,
1408 gettext_noop("Vacuum cost for a page found in the buffer cache."),
1412 1, 0, 10000, NULL, NULL
1416 {"vacuum_cost_page_miss", PGC_USERSET, RESOURCES,
1417 gettext_noop("Vacuum cost for a page not found in the buffer cache."),
1420 &VacuumCostPageMiss,
1421 10, 0, 10000, NULL, NULL
1425 {"vacuum_cost_page_dirty", PGC_USERSET, RESOURCES,
1426 gettext_noop("Vacuum cost for a page dirtied by vacuum."),
1429 &VacuumCostPageDirty,
1430 20, 0, 10000, NULL, NULL
1434 {"vacuum_cost_limit", PGC_USERSET, RESOURCES,
1435 gettext_noop("Vacuum cost amount available before napping."),
1439 200, 1, 10000, NULL, NULL
1443 {"vacuum_cost_delay", PGC_USERSET, RESOURCES,
1444 gettext_noop("Vacuum cost delay in milliseconds."),
1449 0, 0, 1000, NULL, NULL
1453 {"autovacuum_vacuum_cost_delay", PGC_SIGHUP, AUTOVACUUM,
1454 gettext_noop("Vacuum cost delay in milliseconds, for autovacuum."),
1458 &autovacuum_vac_cost_delay,
1459 20, -1, 1000, NULL, NULL
1463 {"autovacuum_vacuum_cost_limit", PGC_SIGHUP, AUTOVACUUM,
1464 gettext_noop("Vacuum cost amount available before napping, for autovacuum."),
1467 &autovacuum_vac_cost_limit,
1468 -1, -1, 10000, NULL, NULL
1472 {"max_files_per_process", PGC_POSTMASTER, RESOURCES_KERNEL,
1473 gettext_noop("Sets the maximum number of simultaneously open files for each server process."),
1476 &max_files_per_process,
1477 1000, 25, INT_MAX, NULL, NULL
1481 {"max_prepared_transactions", PGC_POSTMASTER, RESOURCES,
1482 gettext_noop("Sets the maximum number of simultaneously prepared transactions."),
1485 &max_prepared_xacts,
1486 5, 0, INT_MAX, NULL, NULL
1491 {"trace_lock_oidmin", PGC_SUSET, DEVELOPER_OPTIONS,
1492 gettext_noop("No description available."),
1497 FirstNormalObjectId, 0, INT_MAX, NULL, NULL
1500 {"trace_lock_table", PGC_SUSET, DEVELOPER_OPTIONS,
1501 gettext_noop("No description available."),
1506 0, 0, INT_MAX, NULL, NULL
1511 {"statement_timeout", PGC_USERSET, CLIENT_CONN_STATEMENT,
1512 gettext_noop("Sets the maximum allowed duration of any statement."),
1513 gettext_noop("A value of 0 turns off the timeout."),
1517 0, 0, INT_MAX, NULL, NULL
1521 {"vacuum_freeze_min_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1522 gettext_noop("Minimum age at which VACUUM should freeze a table row."),
1525 &vacuum_freeze_min_age,
1526 100000000, 0, 1000000000, NULL, NULL
1530 {"max_fsm_relations", PGC_POSTMASTER, RESOURCES_FSM,
1531 gettext_noop("Sets the maximum number of tables and indexes for which free space is tracked."),
1535 1000, 100, INT_MAX, NULL, NULL
1538 {"max_fsm_pages", PGC_POSTMASTER, RESOURCES_FSM,
1539 gettext_noop("Sets the maximum number of disk pages for which free space is tracked."),
1543 20000, 1000, INT_MAX, NULL, NULL
1547 {"max_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
1548 gettext_noop("Sets the maximum number of locks per transaction."),
1549 gettext_noop("The shared lock table is sized on the assumption that "
1550 "at most max_locks_per_transaction * max_connections distinct "
1551 "objects will need to be locked at any one time.")
1553 &max_locks_per_xact,
1554 64, 10, INT_MAX, NULL, NULL
1558 {"authentication_timeout", PGC_SIGHUP, CONN_AUTH_SECURITY,
1559 gettext_noop("Sets the maximum allowed time to complete client authentication."),
1563 &AuthenticationTimeout,
1564 60, 1, 600, NULL, NULL
1568 /* Not for general use */
1569 {"pre_auth_delay", PGC_SIGHUP, DEVELOPER_OPTIONS,
1570 gettext_noop("Waits N seconds on connection startup before authentication."),
1571 gettext_noop("This allows attaching a debugger to the process."),
1572 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1575 0, 0, 60, NULL, NULL
1579 {"checkpoint_segments", PGC_SIGHUP, WAL_CHECKPOINTS,
1580 gettext_noop("Sets the maximum distance in log segments between automatic WAL checkpoints."),
1583 &CheckPointSegments,
1584 3, 1, INT_MAX, NULL, NULL
1588 {"checkpoint_timeout", PGC_SIGHUP, WAL_CHECKPOINTS,
1589 gettext_noop("Sets the maximum time between automatic WAL checkpoints."),
1594 300, 30, 3600, NULL, NULL
1598 {"checkpoint_warning", PGC_SIGHUP, WAL_CHECKPOINTS,
1599 gettext_noop("Enables warnings if checkpoint segments are filled more "
1600 "frequently than this."),
1601 gettext_noop("Write a message to the server log if checkpoints "
1602 "caused by the filling of checkpoint segment files happens more "
1603 "frequently than this number of seconds. Zero turns off the warning."),
1607 30, 0, INT_MAX, NULL, NULL
1611 {"wal_buffers", PGC_POSTMASTER, WAL_SETTINGS,
1612 gettext_noop("Sets the number of disk-page buffers in shared memory for WAL."),
1617 8, 4, INT_MAX, NULL, NULL
1621 {"wal_writer_delay", PGC_SIGHUP, WAL_SETTINGS,
1622 gettext_noop("WAL writer sleep time between WAL flushes."),
1627 200, 1, 10000, NULL, NULL
1631 {"commit_delay", PGC_USERSET, WAL_SETTINGS,
1632 gettext_noop("Sets the delay in microseconds between transaction commit and "
1633 "flushing WAL to disk."),
1637 0, 0, 100000, NULL, NULL
1641 {"commit_siblings", PGC_USERSET, WAL_SETTINGS,
1642 gettext_noop("Sets the minimum concurrent open transactions before performing "
1647 5, 1, 1000, NULL, NULL
1651 {"extra_float_digits", PGC_USERSET, CLIENT_CONN_LOCALE,
1652 gettext_noop("Sets the number of digits displayed for floating-point values."),
1653 gettext_noop("This affects real, double precision, and geometric data types. "
1654 "The parameter value is added to the standard number of digits "
1655 "(FLT_DIG or DBL_DIG as appropriate).")
1657 &extra_float_digits,
1658 0, -15, 2, NULL, NULL
1662 {"log_min_duration_statement", PGC_SUSET, LOGGING_WHEN,
1663 gettext_noop("Sets the minimum execution time above which "
1664 "statements will be logged."),
1665 gettext_noop("Zero prints all queries. -1 turns this feature off."),
1668 &log_min_duration_statement,
1669 -1, -1, INT_MAX / 1000, NULL, NULL
1673 {"log_autovacuum_min_duration", PGC_SIGHUP, LOGGING_WHAT,
1674 gettext_noop("Sets the minimum execution time above which "
1675 "autovacuum actions will be logged."),
1676 gettext_noop("Zero prints all actions. -1 turns autovacuum logging off."),
1679 &Log_autovacuum_min_duration,
1680 -1, -1, INT_MAX / 1000, NULL, NULL
1684 {"bgwriter_delay", PGC_SIGHUP, RESOURCES,
1685 gettext_noop("Background writer sleep time between rounds."),
1690 200, 10, 10000, NULL, NULL
1694 {"bgwriter_lru_maxpages", PGC_SIGHUP, RESOURCES,
1695 gettext_noop("Background writer maximum number of LRU pages to flush per round."),
1698 &bgwriter_lru_maxpages,
1699 100, 0, 1000, NULL, NULL
1703 {"log_rotation_age", PGC_SIGHUP, LOGGING_WHERE,
1704 gettext_noop("Automatic log file rotation will occur after N minutes."),
1709 HOURS_PER_DAY * MINS_PER_HOUR, 0, INT_MAX / MINS_PER_HOUR, NULL, NULL
1713 {"log_rotation_size", PGC_SIGHUP, LOGGING_WHERE,
1714 gettext_noop("Automatic log file rotation will occur after N kilobytes."),
1719 10 * 1024, 0, INT_MAX / 1024, NULL, NULL
1723 {"max_function_args", PGC_INTERNAL, PRESET_OPTIONS,
1724 gettext_noop("Shows the maximum number of function arguments."),
1726 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1729 FUNC_MAX_ARGS, FUNC_MAX_ARGS, FUNC_MAX_ARGS, NULL, NULL
1733 {"max_index_keys", PGC_INTERNAL, PRESET_OPTIONS,
1734 gettext_noop("Shows the maximum number of index keys."),
1736 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1739 INDEX_MAX_KEYS, INDEX_MAX_KEYS, INDEX_MAX_KEYS, NULL, NULL
1743 {"max_identifier_length", PGC_INTERNAL, PRESET_OPTIONS,
1744 gettext_noop("Shows the maximum identifier length."),
1746 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1748 &max_identifier_length,
1749 NAMEDATALEN - 1, NAMEDATALEN - 1, NAMEDATALEN - 1, NULL, NULL
1753 {"block_size", PGC_INTERNAL, PRESET_OPTIONS,
1754 gettext_noop("Shows the size of a disk block."),
1756 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1759 BLCKSZ, BLCKSZ, BLCKSZ, NULL, NULL
1763 {"segment_size", PGC_INTERNAL, PRESET_OPTIONS,
1764 gettext_noop("Shows the number of pages per disk file."),
1766 GUC_UNIT_BLOCKS | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1769 RELSEG_SIZE, RELSEG_SIZE, RELSEG_SIZE, NULL, NULL
1773 {"wal_block_size", PGC_INTERNAL, PRESET_OPTIONS,
1774 gettext_noop("Shows the block size in the write ahead log."),
1776 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1779 XLOG_BLCKSZ, XLOG_BLCKSZ, XLOG_BLCKSZ, NULL, NULL
1783 {"wal_segment_size", PGC_INTERNAL, PRESET_OPTIONS,
1784 gettext_noop("Shows the number of pages per write ahead log segment."),
1786 GUC_UNIT_XBLOCKS | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1789 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
1790 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
1791 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
1796 {"autovacuum_naptime", PGC_SIGHUP, AUTOVACUUM,
1797 gettext_noop("Time to sleep between autovacuum runs."),
1801 &autovacuum_naptime,
1802 60, 1, INT_MAX / 1000, NULL, NULL
1805 {"autovacuum_vacuum_threshold", PGC_SIGHUP, AUTOVACUUM,
1806 gettext_noop("Minimum number of tuple updates or deletes prior to vacuum."),
1809 &autovacuum_vac_thresh,
1810 50, 0, INT_MAX, NULL, NULL
1813 {"autovacuum_analyze_threshold", PGC_SIGHUP, AUTOVACUUM,
1814 gettext_noop("Minimum number of tuple inserts, updates or deletes prior to analyze."),
1817 &autovacuum_anl_thresh,
1818 50, 0, INT_MAX, NULL, NULL
1821 /* see varsup.c for why this is PGC_POSTMASTER not PGC_SIGHUP */
1822 {"autovacuum_freeze_max_age", PGC_POSTMASTER, AUTOVACUUM,
1823 gettext_noop("Age at which to autovacuum a table to prevent transaction ID wraparound."),
1826 &autovacuum_freeze_max_age,
1827 200000000, 100000000, 2000000000, NULL, NULL
1830 /* see max_connections */
1831 {"autovacuum_max_workers", PGC_POSTMASTER, AUTOVACUUM,
1832 gettext_noop("Sets the maximum number of simultaneously running autovacuum worker processes."),
1835 &autovacuum_max_workers,
1836 3, 1, INT_MAX / 4, assign_autovacuum_max_workers, NULL
1840 {"tcp_keepalives_idle", PGC_USERSET, CLIENT_CONN_OTHER,
1841 gettext_noop("Time between issuing TCP keepalives."),
1842 gettext_noop("A value of 0 uses the system default."),
1845 &tcp_keepalives_idle,
1846 0, 0, INT_MAX, assign_tcp_keepalives_idle, show_tcp_keepalives_idle
1850 {"tcp_keepalives_interval", PGC_USERSET, CLIENT_CONN_OTHER,
1851 gettext_noop("Time between TCP keepalive retransmits."),
1852 gettext_noop("A value of 0 uses the system default."),
1855 &tcp_keepalives_interval,
1856 0, 0, INT_MAX, assign_tcp_keepalives_interval, show_tcp_keepalives_interval
1860 {"tcp_keepalives_count", PGC_USERSET, CLIENT_CONN_OTHER,
1861 gettext_noop("Maximum number of TCP keepalive retransmits."),
1862 gettext_noop("This controls the number of consecutive keepalive retransmits that can be "
1863 "lost before a connection is considered dead. A value of 0 uses the "
1866 &tcp_keepalives_count,
1867 0, 0, INT_MAX, assign_tcp_keepalives_count, show_tcp_keepalives_count
1871 {"gin_fuzzy_search_limit", PGC_USERSET, CLIENT_CONN_OTHER,
1872 gettext_noop("Sets the maximum allowed result for exact search by GIN."),
1876 &GinFuzzySearchLimit,
1877 0, 0, INT_MAX, NULL, NULL
1881 {"effective_cache_size", PGC_USERSET, QUERY_TUNING_COST,
1882 gettext_noop("Sets the planner's assumption about the size of the disk cache."),
1883 gettext_noop("That is, the portion of the kernel's disk cache that "
1884 "will be used for PostgreSQL data files. This is measured in disk "
1885 "pages, which are normally 8 kB each."),
1888 &effective_cache_size,
1889 DEFAULT_EFFECTIVE_CACHE_SIZE, 1, INT_MAX, NULL, NULL
1893 /* Can't be set in postgresql.conf */
1894 {"server_version_num", PGC_INTERNAL, PRESET_OPTIONS,
1895 gettext_noop("Shows the server version as an integer."),
1897 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1899 &server_version_num,
1900 PG_VERSION_NUM, PG_VERSION_NUM, PG_VERSION_NUM, NULL, NULL
1904 {"log_temp_files", PGC_USERSET, LOGGING_WHAT,
1905 gettext_noop("Log the use of temporary files larger than this number of kilobytes."),
1906 gettext_noop("Zero logs all files. The default is -1 (turning this feature off)."),
1910 -1, -1, INT_MAX, NULL, NULL
1914 {"track_activity_query_size", PGC_POSTMASTER, RESOURCES_MEM,
1915 gettext_noop("Sets the size reserved for pg_stat_activity.current_query, in bytes."),
1918 &pgstat_track_activity_query_size,
1919 1024, 100, 102400, NULL, NULL
1922 /* End-of-list marker */
1924 {NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL
1929 static struct config_real ConfigureNamesReal[] =
1932 {"seq_page_cost", PGC_USERSET, QUERY_TUNING_COST,
1933 gettext_noop("Sets the planner's estimate of the cost of a "
1934 "sequentially fetched disk page."),
1938 DEFAULT_SEQ_PAGE_COST, 0, DBL_MAX, NULL, NULL
1941 {"random_page_cost", PGC_USERSET, QUERY_TUNING_COST,
1942 gettext_noop("Sets the planner's estimate of the cost of a "
1943 "nonsequentially fetched disk page."),
1947 DEFAULT_RANDOM_PAGE_COST, 0, DBL_MAX, NULL, NULL
1950 {"cpu_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
1951 gettext_noop("Sets the planner's estimate of the cost of "
1952 "processing each tuple (row)."),
1956 DEFAULT_CPU_TUPLE_COST, 0, DBL_MAX, NULL, NULL
1959 {"cpu_index_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
1960 gettext_noop("Sets the planner's estimate of the cost of "
1961 "processing each index entry during an index scan."),
1964 &cpu_index_tuple_cost,
1965 DEFAULT_CPU_INDEX_TUPLE_COST, 0, DBL_MAX, NULL, NULL
1968 {"cpu_operator_cost", PGC_USERSET, QUERY_TUNING_COST,
1969 gettext_noop("Sets the planner's estimate of the cost of "
1970 "processing each operator or function call."),
1974 DEFAULT_CPU_OPERATOR_COST, 0, DBL_MAX, NULL, NULL
1978 {"cursor_tuple_fraction", PGC_USERSET, QUERY_TUNING_OTHER,
1979 gettext_noop("Sets the planner's estimate of the fraction of "
1980 "a cursor's rows that will be retrieved."),
1983 &cursor_tuple_fraction,
1984 DEFAULT_CURSOR_TUPLE_FRACTION, 0.0, 1.0, NULL, NULL
1988 {"geqo_selection_bias", PGC_USERSET, QUERY_TUNING_GEQO,
1989 gettext_noop("GEQO: selective pressure within the population."),
1992 &Geqo_selection_bias,
1993 DEFAULT_GEQO_SELECTION_BIAS, MIN_GEQO_SELECTION_BIAS,
1994 MAX_GEQO_SELECTION_BIAS, NULL, NULL
1998 {"bgwriter_lru_multiplier", PGC_SIGHUP, RESOURCES,
1999 gettext_noop("Multiple of the average buffer usage to free per round."),
2002 &bgwriter_lru_multiplier,
2003 2.0, 0.0, 10.0, NULL, NULL
2007 {"seed", PGC_USERSET, UNGROUPED,
2008 gettext_noop("Sets the seed for random-number generation."),
2010 GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2013 0.0, -1.0, 1.0, assign_random_seed, show_random_seed
2017 {"autovacuum_vacuum_scale_factor", PGC_SIGHUP, AUTOVACUUM,
2018 gettext_noop("Number of tuple updates or deletes prior to vacuum as a fraction of reltuples."),
2021 &autovacuum_vac_scale,
2022 0.2, 0.0, 100.0, NULL, NULL
2025 {"autovacuum_analyze_scale_factor", PGC_SIGHUP, AUTOVACUUM,
2026 gettext_noop("Number of tuple inserts, updates or deletes prior to analyze as a fraction of reltuples."),
2029 &autovacuum_anl_scale,
2030 0.1, 0.0, 100.0, NULL, NULL
2034 {"checkpoint_completion_target", PGC_SIGHUP, WAL_CHECKPOINTS,
2035 gettext_noop("Time spent flushing dirty buffers during checkpoint, as fraction of checkpoint interval."),
2038 &CheckPointCompletionTarget,
2039 0.5, 0.0, 1.0, NULL, NULL
2042 /* End-of-list marker */
2044 {NULL, 0, 0, NULL, NULL}, NULL, 0.0, 0.0, 0.0, NULL, NULL
2049 static struct config_string ConfigureNamesString[] =
2052 {"archive_command", PGC_SIGHUP, WAL_SETTINGS,
2053 gettext_noop("Sets the shell command that will be called to archive a WAL file."),
2056 &XLogArchiveCommand,
2057 "", NULL, show_archive_command
2061 {"client_encoding", PGC_USERSET, CLIENT_CONN_LOCALE,
2062 gettext_noop("Sets the client's character set encoding."),
2064 GUC_IS_NAME | GUC_REPORT
2066 &client_encoding_string,
2067 "SQL_ASCII", assign_client_encoding, NULL
2071 {"log_line_prefix", PGC_SIGHUP, LOGGING_WHAT,
2072 gettext_noop("Controls information prefixed to each log line."),
2073 gettext_noop("If blank, no prefix is used.")
2080 {"log_timezone", PGC_SIGHUP, LOGGING_WHAT,
2081 gettext_noop("Sets the time zone to use in log messages."),
2084 &log_timezone_string,
2085 "UNKNOWN", assign_log_timezone, show_log_timezone
2089 {"DateStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
2090 gettext_noop("Sets the display format for date and time values."),
2091 gettext_noop("Also controls interpretation of ambiguous "
2093 GUC_LIST_INPUT | GUC_REPORT
2096 "ISO, MDY", assign_datestyle, NULL
2100 {"default_tablespace", PGC_USERSET, CLIENT_CONN_STATEMENT,
2101 gettext_noop("Sets the default tablespace to create tables and indexes in."),
2102 gettext_noop("An empty string selects the database's default tablespace."),
2105 &default_tablespace,
2106 "", assign_default_tablespace, NULL
2110 {"temp_tablespaces", PGC_USERSET, CLIENT_CONN_STATEMENT,
2111 gettext_noop("Sets the tablespace(s) to use for temporary tables and sort files."),
2113 GUC_LIST_INPUT | GUC_LIST_QUOTE
2116 "", assign_temp_tablespaces, NULL
2120 {"dynamic_library_path", PGC_SUSET, CLIENT_CONN_OTHER,
2121 gettext_noop("Sets the path for dynamically loadable modules."),
2122 gettext_noop("If a dynamically loadable module needs to be opened and "
2123 "the specified name does not have a directory component (i.e., the "
2124 "name does not contain a slash), the system will search this path for "
2125 "the specified file."),
2128 &Dynamic_library_path,
2129 "$libdir", NULL, NULL
2133 {"krb_realm", PGC_POSTMASTER, CONN_AUTH_SECURITY,
2134 gettext_noop("Sets realm to match Kerberos and GSSAPI users against."),
2143 {"krb_server_keyfile", PGC_POSTMASTER, CONN_AUTH_SECURITY,
2144 gettext_noop("Sets the location of the Kerberos server key file."),
2148 &pg_krb_server_keyfile,
2149 PG_KRB_SRVTAB, NULL, NULL
2153 {"krb_srvname", PGC_POSTMASTER, CONN_AUTH_SECURITY,
2154 gettext_noop("Sets the name of the Kerberos service."),
2158 PG_KRB_SRVNAM, NULL, NULL
2162 {"krb_server_hostname", PGC_POSTMASTER, CONN_AUTH_SECURITY,
2163 gettext_noop("Sets the hostname of the Kerberos server."),
2166 &pg_krb_server_hostname,
2171 {"bonjour_name", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2172 gettext_noop("Sets the Bonjour broadcast service name."),
2179 /* See main.c about why defaults for LC_foo are not all alike */
2182 {"lc_collate", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2183 gettext_noop("Shows the collation order locale."),
2185 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2192 {"lc_ctype", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2193 gettext_noop("Shows the character classification and case conversion locale."),
2195 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2202 {"lc_messages", PGC_SUSET, CLIENT_CONN_LOCALE,
2203 gettext_noop("Sets the language in which messages are displayed."),
2207 "", locale_messages_assign, NULL
2211 {"lc_monetary", PGC_USERSET, CLIENT_CONN_LOCALE,
2212 gettext_noop("Sets the locale for formatting monetary amounts."),
2216 "C", locale_monetary_assign, NULL
2220 {"lc_numeric", PGC_USERSET, CLIENT_CONN_LOCALE,
2221 gettext_noop("Sets the locale for formatting numbers."),
2225 "C", locale_numeric_assign, NULL
2229 {"lc_time", PGC_USERSET, CLIENT_CONN_LOCALE,
2230 gettext_noop("Sets the locale for formatting date and time values."),
2234 "C", locale_time_assign, NULL
2238 {"shared_preload_libraries", PGC_POSTMASTER, RESOURCES_KERNEL,
2239 gettext_noop("Lists shared libraries to preload into server."),
2241 GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
2243 &shared_preload_libraries_string,
2248 {"local_preload_libraries", PGC_BACKEND, CLIENT_CONN_OTHER,
2249 gettext_noop("Lists shared libraries to preload into each backend."),
2251 GUC_LIST_INPUT | GUC_LIST_QUOTE
2253 &local_preload_libraries_string,
2258 {"search_path", PGC_USERSET, CLIENT_CONN_STATEMENT,
2259 gettext_noop("Sets the schema search order for names that are not schema-qualified."),
2261 GUC_LIST_INPUT | GUC_LIST_QUOTE
2263 &namespace_search_path,
2264 "\"$user\",public", assign_search_path, NULL
2268 /* Can't be set in postgresql.conf */
2269 {"server_encoding", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2270 gettext_noop("Sets the server (database) character set encoding."),
2272 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2274 &server_encoding_string,
2275 "SQL_ASCII", NULL, NULL
2279 /* Can't be set in postgresql.conf */
2280 {"server_version", PGC_INTERNAL, PRESET_OPTIONS,
2281 gettext_noop("Shows the server version."),
2283 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2285 &server_version_string,
2286 PG_VERSION, NULL, NULL
2290 /* Not for general use --- used by SET ROLE */
2291 {"role", PGC_USERSET, UNGROUPED,
2292 gettext_noop("Sets the current role."),
2294 GUC_IS_NAME | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2297 "none", assign_role, show_role
2301 /* Not for general use --- used by SET SESSION AUTHORIZATION */
2302 {"session_authorization", PGC_USERSET, UNGROUPED,
2303 gettext_noop("Sets the session user name."),
2305 GUC_IS_NAME | GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2307 &session_authorization_string,
2308 NULL, assign_session_authorization, show_session_authorization
2312 {"log_destination", PGC_SIGHUP, LOGGING_WHERE,
2313 gettext_noop("Sets the destination for server log output."),
2314 gettext_noop("Valid values are combinations of \"stderr\", "
2315 "\"syslog\", \"csvlog\", and \"eventlog\", "
2316 "depending on the platform."),
2319 &log_destination_string,
2320 "stderr", assign_log_destination, NULL
2323 {"log_directory", PGC_SIGHUP, LOGGING_WHERE,
2324 gettext_noop("Sets the destination directory for log files."),
2325 gettext_noop("Can be specified as relative to the data directory "
2326 "or as absolute path."),
2330 "pg_log", assign_canonical_path, NULL
2333 {"log_filename", PGC_SIGHUP, LOGGING_WHERE,
2334 gettext_noop("Sets the file name pattern for log files."),
2339 "postgresql-%Y-%m-%d_%H%M%S.log", NULL, NULL
2344 {"syslog_ident", PGC_SIGHUP, LOGGING_WHERE,
2345 gettext_noop("Sets the program name used to identify PostgreSQL "
2346 "messages in syslog."),
2350 "postgres", assign_syslog_ident, NULL
2355 {"TimeZone", PGC_USERSET, CLIENT_CONN_LOCALE,
2356 gettext_noop("Sets the time zone for displaying and interpreting time stamps."),
2361 "UNKNOWN", assign_timezone, show_timezone
2364 {"timezone_abbreviations", PGC_USERSET, CLIENT_CONN_LOCALE,
2365 gettext_noop("Selects a file of time zone abbreviations."),
2368 &timezone_abbreviations_string,
2369 "UNKNOWN", assign_timezone_abbreviations, NULL
2373 {"transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
2374 gettext_noop("Sets the current transaction's isolation level."),
2376 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2378 &XactIsoLevel_string,
2379 NULL, assign_XactIsoLevel, show_XactIsoLevel
2383 {"unix_socket_group", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2384 gettext_noop("Sets the owning group of the Unix-domain socket."),
2385 gettext_noop("The owning user of the socket is always the user "
2386 "that starts the server.")
2393 {"unix_socket_directory", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2394 gettext_noop("Sets the directory where the Unix-domain socket will be created."),
2399 "", assign_canonical_path, NULL
2403 {"listen_addresses", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2404 gettext_noop("Sets the host name or IP address(es) to listen to."),
2409 "localhost", NULL, NULL
2413 {"custom_variable_classes", PGC_SIGHUP, CUSTOM_OPTIONS,
2414 gettext_noop("Sets the list of known custom variable classes."),
2416 GUC_LIST_INPUT | GUC_LIST_QUOTE
2418 &custom_variable_classes,
2419 NULL, assign_custom_variable_classes, NULL
2423 {"data_directory", PGC_POSTMASTER, FILE_LOCATIONS,
2424 gettext_noop("Sets the server's data directory."),
2433 {"config_file", PGC_POSTMASTER, FILE_LOCATIONS,
2434 gettext_noop("Sets the server's main configuration file."),
2436 GUC_DISALLOW_IN_FILE | GUC_SUPERUSER_ONLY
2443 {"hba_file", PGC_POSTMASTER, FILE_LOCATIONS,
2444 gettext_noop("Sets the server's \"hba\" configuration file."),
2453 {"ident_file", PGC_POSTMASTER, FILE_LOCATIONS,
2454 gettext_noop("Sets the server's \"ident\" configuration file."),
2463 {"external_pid_file", PGC_POSTMASTER, FILE_LOCATIONS,
2464 gettext_noop("Writes the postmaster PID to the specified file."),
2469 NULL, assign_canonical_path, NULL
2473 {"stats_temp_directory", PGC_POSTMASTER, STATS_COLLECTOR,
2474 gettext_noop("Writes temporary statistics files to the specified directory."),
2478 &pgstat_temp_directory,
2479 "pg_stat_tmp", assign_pgstat_temp_directory, NULL
2483 {"default_text_search_config", PGC_USERSET, CLIENT_CONN_LOCALE,
2484 gettext_noop("Sets default text search configuration."),
2488 "pg_catalog.simple", assignTSCurrentConfig, NULL
2493 {"ssl_ciphers", PGC_POSTMASTER, CONN_AUTH_SECURITY,
2494 gettext_noop("Sets the list of allowed SSL ciphers."),
2499 "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH", NULL, NULL
2501 #endif /* USE_SSL */
2503 /* End-of-list marker */
2505 {NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL
2510 static struct config_enum ConfigureNamesEnum[] =
2513 {"backslash_quote", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
2514 gettext_noop("Sets whether \"\\'\" is allowed in string literals."),
2518 BACKSLASH_QUOTE_SAFE_ENCODING, backslash_quote_options, NULL, NULL
2522 {"client_min_messages", PGC_USERSET, LOGGING_WHEN,
2523 gettext_noop("Sets the message levels that are sent to the client."),
2524 gettext_noop("Each level includes all the levels that follow it. The later"
2525 " the level, the fewer messages are sent.")
2527 &client_min_messages,
2528 NOTICE, client_message_level_options, NULL, NULL
2532 {"default_transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
2533 gettext_noop("Sets the transaction isolation level of each new transaction."),
2536 &DefaultXactIsoLevel,
2537 XACT_READ_COMMITTED, isolation_level_options, NULL, NULL
2541 {"log_error_verbosity", PGC_SUSET, LOGGING_WHEN,
2542 gettext_noop("Sets the verbosity of logged messages."),
2545 &Log_error_verbosity,
2546 PGERROR_DEFAULT, log_error_verbosity_options, NULL, NULL
2550 {"log_min_messages", PGC_SUSET, LOGGING_WHEN,
2551 gettext_noop("Sets the message levels that are logged."),
2552 gettext_noop("Each level includes all the levels that follow it. The later"
2553 " the level, the fewer messages are sent.")
2556 WARNING, server_message_level_options, NULL, NULL
2560 {"log_min_error_statement", PGC_SUSET, LOGGING_WHEN,
2561 gettext_noop("Causes all statements generating error at or above this level to be logged."),
2562 gettext_noop("Each level includes all the levels that follow it. The later"
2563 " the level, the fewer messages are sent.")
2565 &log_min_error_statement,
2566 ERROR, server_message_level_options, NULL, NULL
2570 {"log_statement", PGC_SUSET, LOGGING_WHAT,
2571 gettext_noop("Sets the type of statements logged."),
2575 LOGSTMT_NONE, log_statement_options, NULL, NULL
2580 {"syslog_facility", PGC_SIGHUP, LOGGING_WHERE,
2581 gettext_noop("Sets the syslog \"facility\" to be used when syslog enabled."),
2585 LOG_LOCAL0, syslog_facility_options, assign_syslog_facility, NULL
2590 {"regex_flavor", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
2591 gettext_noop("Sets the regular expression \"flavor\"."),
2595 REG_ADVANCED, regex_flavor_options, NULL, NULL
2599 {"session_replication_role", PGC_SUSET, CLIENT_CONN_STATEMENT,
2600 gettext_noop("Sets the session's behavior for triggers and rewrite rules."),
2603 &SessionReplicationRole,
2604 SESSION_REPLICATION_ROLE_ORIGIN, session_replication_role_options,
2605 assign_session_replication_role, NULL
2609 {"track_functions", PGC_SUSET, STATS_COLLECTOR,
2610 gettext_noop("Collects function-level statistics on database activity."),
2613 &pgstat_track_functions,
2614 TRACK_FUNC_OFF, track_function_options, NULL, NULL
2618 {"wal_sync_method", PGC_SIGHUP, WAL_SETTINGS,
2619 gettext_noop("Selects the method used for forcing WAL updates to disk."),
2623 DEFAULT_SYNC_METHOD, sync_method_options,
2624 assign_xlog_sync_method, NULL
2628 {"xmlbinary", PGC_USERSET, CLIENT_CONN_STATEMENT,
2629 gettext_noop("Sets how binary values are to be encoded in XML."),
2633 XMLBINARY_BASE64, xmlbinary_options, NULL, NULL
2637 {"xmloption", PGC_USERSET, CLIENT_CONN_STATEMENT,
2638 gettext_noop("Sets whether XML data in implicit parsing and serialization "
2639 "operations is to be considered as documents or content fragments."),
2643 XMLOPTION_CONTENT, xmloption_options, NULL, NULL
2647 /* End-of-list marker */
2649 {NULL, 0, 0, NULL, NULL}, NULL, 0, NULL, NULL, NULL
2653 /******** end of options list ********/
2657 * To allow continued support of obsolete names for GUC variables, we apply
2658 * the following mappings to any unrecognized name. Note that an old name
2659 * should be mapped to a new one only if the new variable has very similar
2660 * semantics to the old.
2662 static const char *const map_old_guc_names[] = {
2663 "sort_mem", "work_mem",
2664 "vacuum_mem", "maintenance_work_mem",
2670 * Actual lookup of variables is done through this single, sorted array.
2672 static struct config_generic **guc_variables;
2674 /* Current number of variables contained in the vector */
2675 static int num_guc_variables;
2677 /* Vector capacity */
2678 static int size_guc_variables;
2681 static bool guc_dirty; /* TRUE if need to do commit/abort work */
2683 static bool reporting_enabled; /* TRUE to enable GUC_REPORT */
2685 static int GUCNestLevel = 0; /* 1 when in main transaction */
2688 static int guc_var_compare(const void *a, const void *b);
2689 static int guc_name_compare(const char *namea, const char *nameb);
2690 static void push_old_value(struct config_generic * gconf, GucAction action);
2691 static void ReportGUCOption(struct config_generic * record);
2692 static void ShowGUCConfigOption(const char *name, DestReceiver *dest);
2693 static void ShowAllGUCConfig(DestReceiver *dest);
2694 static char *_ShowOption(struct config_generic * record, bool use_units);
2695 static bool is_newvalue_equal(struct config_generic * record, const char *newvalue);
2699 * Some infrastructure for checking malloc/strdup/realloc calls
2702 guc_malloc(int elevel, size_t size)
2706 data = malloc(size);
2709 (errcode(ERRCODE_OUT_OF_MEMORY),
2710 errmsg("out of memory")));
2715 guc_realloc(int elevel, void *old, size_t size)
2719 data = realloc(old, size);
2722 (errcode(ERRCODE_OUT_OF_MEMORY),
2723 errmsg("out of memory")));
2728 guc_strdup(int elevel, const char *src)
2735 (errcode(ERRCODE_OUT_OF_MEMORY),
2736 errmsg("out of memory")));
2742 * Support for assigning to a field of a string GUC item. Free the prior
2743 * value if it's not referenced anywhere else in the item (including stacked
2747 set_string_field(struct config_string * conf, char **field, char *newval)
2749 char *oldval = *field;
2752 /* Do the assignment */
2755 /* Exit if any duplicate references, or if old value was NULL anyway */
2756 if (oldval == NULL ||
2757 oldval == *(conf->variable) ||
2758 oldval == conf->reset_val ||
2759 oldval == conf->boot_val)
2761 for (stack = conf->gen.stack; stack; stack = stack->prev)
2763 if (oldval == stack->prior.stringval ||
2764 oldval == stack->masked.stringval)
2768 /* Not used anymore, so free it */
2773 * Detect whether strval is referenced anywhere in a GUC string item
2776 string_field_used(struct config_string * conf, char *strval)
2780 if (strval == *(conf->variable) ||
2781 strval == conf->reset_val ||
2782 strval == conf->boot_val)
2784 for (stack = conf->gen.stack; stack; stack = stack->prev)
2786 if (strval == stack->prior.stringval ||
2787 strval == stack->masked.stringval)
2794 * Support for copying a variable's active value into a stack entry
2797 set_stack_value(struct config_generic * gconf, union config_var_value * val)
2799 switch (gconf->vartype)
2803 *((struct config_bool *) gconf)->variable;
2807 *((struct config_int *) gconf)->variable;
2811 *((struct config_real *) gconf)->variable;
2814 /* we assume stringval is NULL if not valid */
2815 set_string_field((struct config_string *) gconf,
2817 *((struct config_string *) gconf)->variable);
2821 *((struct config_enum *) gconf)->variable;
2827 * Support for discarding a no-longer-needed value in a stack entry
2830 discard_stack_value(struct config_generic * gconf, union config_var_value * val)
2832 switch (gconf->vartype)
2838 /* no need to do anything */
2841 set_string_field((struct config_string *) gconf,
2850 * Fetch the sorted array pointer (exported for help_config.c's use ONLY)
2852 struct config_generic **
2853 get_guc_variables(void)
2855 return guc_variables;
2860 * Build the sorted array. This is split out so that it could be
2861 * re-executed after startup (eg, we could allow loadable modules to
2862 * add vars, and then we'd need to re-sort).
2865 build_guc_variables(void)
2869 struct config_generic **guc_vars;
2872 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
2874 struct config_bool *conf = &ConfigureNamesBool[i];
2876 /* Rather than requiring vartype to be filled in by hand, do this: */
2877 conf->gen.vartype = PGC_BOOL;
2881 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
2883 struct config_int *conf = &ConfigureNamesInt[i];
2885 conf->gen.vartype = PGC_INT;
2889 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
2891 struct config_real *conf = &ConfigureNamesReal[i];
2893 conf->gen.vartype = PGC_REAL;
2897 for (i = 0; ConfigureNamesString[i].gen.name; i++)
2899 struct config_string *conf = &ConfigureNamesString[i];
2901 conf->gen.vartype = PGC_STRING;
2905 for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
2907 struct config_enum *conf = &ConfigureNamesEnum[i];
2909 conf->gen.vartype = PGC_ENUM;
2914 * Create table with 20% slack
2916 size_vars = num_vars + num_vars / 4;
2918 guc_vars = (struct config_generic **)
2919 guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
2923 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
2924 guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
2926 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
2927 guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
2929 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
2930 guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
2932 for (i = 0; ConfigureNamesString[i].gen.name; i++)
2933 guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
2935 for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
2936 guc_vars[num_vars++] = &ConfigureNamesEnum[i].gen;
2939 free(guc_variables);
2940 guc_variables = guc_vars;
2941 num_guc_variables = num_vars;
2942 size_guc_variables = size_vars;
2943 qsort((void *) guc_variables, num_guc_variables,
2944 sizeof(struct config_generic *), guc_var_compare);
2948 * Add a new GUC variable to the list of known variables. The
2949 * list is expanded if needed.
2952 add_guc_variable(struct config_generic * var, int elevel)
2954 if (num_guc_variables + 1 >= size_guc_variables)
2957 * Increase the vector by 25%
2959 int size_vars = size_guc_variables + size_guc_variables / 4;
2960 struct config_generic **guc_vars;
2965 guc_vars = (struct config_generic **)
2966 guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
2970 guc_vars = (struct config_generic **)
2971 guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
2974 if (guc_vars == NULL)
2975 return false; /* out of memory */
2977 guc_variables = guc_vars;
2978 size_guc_variables = size_vars;
2980 guc_variables[num_guc_variables++] = var;
2981 qsort((void *) guc_variables, num_guc_variables,
2982 sizeof(struct config_generic *), guc_var_compare);
2987 * Create and add a placeholder variable. It's presumed to belong
2988 * to a valid custom variable class at this point.
2990 static struct config_generic *
2991 add_placeholder_variable(const char *name, int elevel)
2993 size_t sz = sizeof(struct config_string) + sizeof(char *);
2994 struct config_string *var;
2995 struct config_generic *gen;
2997 var = (struct config_string *) guc_malloc(elevel, sz);
3003 gen->name = guc_strdup(elevel, name);
3004 if (gen->name == NULL)
3010 gen->context = PGC_USERSET;
3011 gen->group = CUSTOM_OPTIONS;
3012 gen->short_desc = "GUC placeholder variable";
3013 gen->flags = GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_CUSTOM_PLACEHOLDER;
3014 gen->vartype = PGC_STRING;
3017 * The char* is allocated at the end of the struct since we have no
3018 * 'static' place to point to. Note that the current value, as well as
3019 * the boot and reset values, start out NULL.
3021 var->variable = (char **) (var + 1);
3023 if (!add_guc_variable((struct config_generic *) var, elevel))
3025 free((void *) gen->name);
3034 * Detect whether the portion of "name" before dotPos matches any custom
3035 * variable class name listed in custom_var_classes. The latter must be
3036 * formatted the way that assign_custom_variable_classes does it, ie,
3037 * no whitespace. NULL is valid for custom_var_classes.
3040 is_custom_class(const char *name, int dotPos, const char *custom_var_classes)
3042 bool result = false;
3043 const char *ccs = custom_var_classes;
3047 const char *start = ccs;
3053 if (c == '\0' || c == ',')
3055 if (dotPos == ccs - start && strncmp(start, name, dotPos) == 0)
3070 * Look up option NAME. If it exists, return a pointer to its record,
3071 * else return NULL. If create_placeholders is TRUE, we'll create a
3072 * placeholder record for a valid-looking custom variable name.
3074 static struct config_generic *
3075 find_option(const char *name, bool create_placeholders, int elevel)
3077 const char **key = &name;
3078 struct config_generic **res;
3084 * By equating const char ** with struct config_generic *, we are assuming
3085 * the name field is first in config_generic.
3087 res = (struct config_generic **) bsearch((void *) &key,
3088 (void *) guc_variables,
3090 sizeof(struct config_generic *),
3096 * See if the name is an obsolete name for a variable. We assume that the
3097 * set of supported old names is short enough that a brute-force search is
3100 for (i = 0; map_old_guc_names[i] != NULL; i += 2)
3102 if (guc_name_compare(name, map_old_guc_names[i]) == 0)
3103 return find_option(map_old_guc_names[i + 1], false, elevel);
3106 if (create_placeholders)
3109 * Check if the name is qualified, and if so, check if the qualifier
3110 * matches any custom variable class. If so, add a placeholder.
3112 const char *dot = strchr(name, GUC_QUALIFIER_SEPARATOR);
3115 is_custom_class(name, dot - name, custom_variable_classes))
3116 return add_placeholder_variable(name, elevel);
3125 * comparator for qsorting and bsearching guc_variables array
3128 guc_var_compare(const void *a, const void *b)
3130 struct config_generic *confa = *(struct config_generic **) a;
3131 struct config_generic *confb = *(struct config_generic **) b;
3133 return guc_name_compare(confa->name, confb->name);
3137 * the bare comparison function for GUC names
3140 guc_name_compare(const char *namea, const char *nameb)
3143 * The temptation to use strcasecmp() here must be resisted, because the
3144 * array ordering has to remain stable across setlocale() calls. So, build
3145 * our own with a simple ASCII-only downcasing.
3147 while (*namea && *nameb)
3149 char cha = *namea++;
3150 char chb = *nameb++;
3152 if (cha >= 'A' && cha <= 'Z')
3154 if (chb >= 'A' && chb <= 'Z')
3160 return 1; /* a is longer */
3162 return -1; /* b is longer */
3168 * Initialize GUC options during program startup.
3170 * Note that we cannot read the config file yet, since we have not yet
3171 * processed command-line switches.
3174 InitializeGUCOptions(void)
3181 * Before log_line_prefix could possibly receive a nonempty setting, make
3182 * sure that timezone processing is minimally alive (see elog.c).
3184 pg_timezone_pre_initialize();
3187 * Build sorted array of all GUC variables.
3189 build_guc_variables();
3192 * Load all variables with their compiled-in defaults, and initialize
3193 * status fields as needed.
3195 for (i = 0; i < num_guc_variables; i++)
3197 struct config_generic *gconf = guc_variables[i];
3200 gconf->reset_source = PGC_S_DEFAULT;
3201 gconf->source = PGC_S_DEFAULT;
3202 gconf->stack = NULL;
3204 switch (gconf->vartype)
3208 struct config_bool *conf = (struct config_bool *) gconf;
3210 if (conf->assign_hook)
3211 if (!(*conf->assign_hook) (conf->boot_val, true,
3213 elog(FATAL, "failed to initialize %s to %d",
3214 conf->gen.name, (int) conf->boot_val);
3215 *conf->variable = conf->reset_val = conf->boot_val;
3220 struct config_int *conf = (struct config_int *) gconf;
3222 Assert(conf->boot_val >= conf->min);
3223 Assert(conf->boot_val <= conf->max);
3224 if (conf->assign_hook)
3225 if (!(*conf->assign_hook) (conf->boot_val, true,
3227 elog(FATAL, "failed to initialize %s to %d",
3228 conf->gen.name, conf->boot_val);
3229 *conf->variable = conf->reset_val = conf->boot_val;
3234 struct config_real *conf = (struct config_real *) gconf;
3236 Assert(conf->boot_val >= conf->min);
3237 Assert(conf->boot_val <= conf->max);
3238 if (conf->assign_hook)
3239 if (!(*conf->assign_hook) (conf->boot_val, true,
3241 elog(FATAL, "failed to initialize %s to %g",
3242 conf->gen.name, conf->boot_val);
3243 *conf->variable = conf->reset_val = conf->boot_val;
3248 struct config_string *conf = (struct config_string *) gconf;
3251 *conf->variable = NULL;
3252 conf->reset_val = NULL;
3254 if (conf->boot_val == NULL)
3256 /* leave the value NULL, do not call assign hook */
3260 str = guc_strdup(FATAL, conf->boot_val);
3261 conf->reset_val = str;
3263 if (conf->assign_hook)
3267 newstr = (*conf->assign_hook) (str, true,
3271 elog(FATAL, "failed to initialize %s to \"%s\"",
3272 conf->gen.name, str);
3274 else if (newstr != str)
3279 * See notes in set_config_option about casting
3281 str = (char *) newstr;
3282 conf->reset_val = str;
3285 *conf->variable = str;
3290 struct config_enum *conf = (struct config_enum *) gconf;
3292 if (conf->assign_hook)
3293 if (!(*conf->assign_hook) (conf->boot_val, true,
3295 elog(FATAL, "failed to initialize %s to %s",
3297 config_enum_lookup_by_value(conf, conf->boot_val));
3298 *conf->variable = conf->reset_val = conf->boot_val;
3306 reporting_enabled = false;
3309 * Prevent any attempt to override the transaction modes from
3310 * non-interactive sources.
3312 SetConfigOption("transaction_isolation", "default",
3313 PGC_POSTMASTER, PGC_S_OVERRIDE);
3314 SetConfigOption("transaction_read_only", "no",
3315 PGC_POSTMASTER, PGC_S_OVERRIDE);
3318 * For historical reasons, some GUC parameters can receive defaults from
3319 * environment variables. Process those settings. NB: if you add or
3320 * remove anything here, see also ProcessConfigFile().
3323 env = getenv("PGPORT");
3325 SetConfigOption("port", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3327 env = getenv("PGDATESTYLE");
3329 SetConfigOption("datestyle", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3331 env = getenv("PGCLIENTENCODING");
3333 SetConfigOption("client_encoding", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3336 * rlimit isn't exactly an "environment variable", but it behaves about
3337 * the same. If we can identify the platform stack depth rlimit, increase
3338 * default stack depth setting up to whatever is safe (but at most 2MB).
3340 stack_rlimit = get_stack_depth_rlimit();
3341 if (stack_rlimit > 0)
3343 int new_limit = (stack_rlimit - STACK_DEPTH_SLOP) / 1024L;
3345 if (new_limit > 100)
3349 new_limit = Min(new_limit, 2048);
3350 sprintf(limbuf, "%d", new_limit);
3351 SetConfigOption("max_stack_depth", limbuf,
3352 PGC_POSTMASTER, PGC_S_ENV_VAR);
3359 * Select the configuration files and data directory to be used, and
3360 * do the initial read of postgresql.conf.
3362 * This is called after processing command-line switches.
3363 * userDoption is the -D switch value if any (NULL if unspecified).
3364 * progname is just for use in error messages.
3366 * Returns true on success; on failure, prints a suitable error message
3367 * to stderr and returns false.
3370 SelectConfigFiles(const char *userDoption, const char *progname)
3374 struct stat stat_buf;
3376 /* configdir is -D option, or $PGDATA if no -D */
3378 configdir = make_absolute_path(userDoption);
3380 configdir = make_absolute_path(getenv("PGDATA"));
3383 * Find the configuration file: if config_file was specified on the
3384 * command line, use it, else use configdir/postgresql.conf. In any case
3385 * ensure the result is an absolute path, so that it will be interpreted
3386 * the same way by future backends.
3389 fname = make_absolute_path(ConfigFileName);
3392 fname = guc_malloc(FATAL,
3393 strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
3394 sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
3398 write_stderr("%s does not know where to find the server configuration file.\n"
3399 "You must specify the --config-file or -D invocation "
3400 "option or set the PGDATA environment variable.\n",
3406 * Set the ConfigFileName GUC variable to its final value, ensuring that
3407 * it can't be overridden later.
3409 SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
3413 * Now read the config file for the first time.
3415 if (stat(ConfigFileName, &stat_buf) != 0)
3417 write_stderr("%s cannot access the server configuration file \"%s\": %s\n",
3418 progname, ConfigFileName, strerror(errno));
3422 ProcessConfigFile(PGC_POSTMASTER);
3425 * If the data_directory GUC variable has been set, use that as DataDir;
3426 * otherwise use configdir if set; else punt.
3428 * Note: SetDataDir will copy and absolute-ize its argument, so we don't
3432 SetDataDir(data_directory);
3434 SetDataDir(configdir);
3437 write_stderr("%s does not know where to find the database system data.\n"
3438 "This can be specified as \"data_directory\" in \"%s\", "
3439 "or by the -D invocation option, or by the "
3440 "PGDATA environment variable.\n",
3441 progname, ConfigFileName);
3446 * Reflect the final DataDir value back into the data_directory GUC var.
3447 * (If you are wondering why we don't just make them a single variable,
3448 * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
3449 * child backends specially. XXX is that still true? Given that we now
3450 * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
3451 * DataDir in advance.)
3453 SetConfigOption("data_directory", DataDir, PGC_POSTMASTER, PGC_S_OVERRIDE);
3456 * Figure out where pg_hba.conf is, and make sure the path is absolute.
3459 fname = make_absolute_path(HbaFileName);
3462 fname = guc_malloc(FATAL,
3463 strlen(configdir) + strlen(HBA_FILENAME) + 2);
3464 sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
3468 write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
3469 "This can be specified as \"hba_file\" in \"%s\", "
3470 "or by the -D invocation option, or by the "
3471 "PGDATA environment variable.\n",
3472 progname, ConfigFileName);
3475 SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
3479 * Likewise for pg_ident.conf.
3482 fname = make_absolute_path(IdentFileName);
3485 fname = guc_malloc(FATAL,
3486 strlen(configdir) + strlen(IDENT_FILENAME) + 2);
3487 sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
3491 write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
3492 "This can be specified as \"ident_file\" in \"%s\", "
3493 "or by the -D invocation option, or by the "
3494 "PGDATA environment variable.\n",
3495 progname, ConfigFileName);
3498 SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
3508 * Reset all options to their saved default values (implements RESET ALL)
3511 ResetAllOptions(void)
3515 for (i = 0; i < num_guc_variables; i++)
3517 struct config_generic *gconf = guc_variables[i];
3519 /* Don't reset non-SET-able values */
3520 if (gconf->context != PGC_SUSET &&
3521 gconf->context != PGC_USERSET)
3523 /* Don't reset if special exclusion from RESET ALL */
3524 if (gconf->flags & GUC_NO_RESET_ALL)
3526 /* No need to reset if wasn't SET */
3527 if (gconf->source <= PGC_S_OVERRIDE)
3530 /* Save old value to support transaction abort */
3531 push_old_value(gconf, GUC_ACTION_SET);
3533 switch (gconf->vartype)
3537 struct config_bool *conf = (struct config_bool *) gconf;
3539 if (conf->assign_hook)
3540 if (!(*conf->assign_hook) (conf->reset_val, true,
3542 elog(ERROR, "failed to reset %s", conf->gen.name);
3543 *conf->variable = conf->reset_val;
3544 conf->gen.source = conf->gen.reset_source;
3549 struct config_int *conf = (struct config_int *) gconf;
3551 if (conf->assign_hook)
3552 if (!(*conf->assign_hook) (conf->reset_val, true,
3554 elog(ERROR, "failed to reset %s", conf->gen.name);
3555 *conf->variable = conf->reset_val;
3556 conf->gen.source = conf->gen.reset_source;
3561 struct config_real *conf = (struct config_real *) gconf;
3563 if (conf->assign_hook)
3564 if (!(*conf->assign_hook) (conf->reset_val, true,
3566 elog(ERROR, "failed to reset %s", conf->gen.name);
3567 *conf->variable = conf->reset_val;
3568 conf->gen.source = conf->gen.reset_source;
3573 struct config_string *conf = (struct config_string *) gconf;
3576 /* We need not strdup here */
3577 str = conf->reset_val;
3579 if (conf->assign_hook && str)
3583 newstr = (*conf->assign_hook) (str, true,
3586 elog(ERROR, "failed to reset %s", conf->gen.name);
3587 else if (newstr != str)
3590 * See notes in set_config_option about casting
3592 str = (char *) newstr;
3596 set_string_field(conf, conf->variable, str);
3597 conf->gen.source = conf->gen.reset_source;
3602 struct config_enum *conf = (struct config_enum *) gconf;
3604 if (conf->assign_hook)
3605 if (!(*conf->assign_hook) (conf->reset_val, true,
3607 elog(ERROR, "failed to reset %s", conf->gen.name);
3608 *conf->variable = conf->reset_val;
3609 conf->gen.source = conf->gen.reset_source;
3614 if (gconf->flags & GUC_REPORT)
3615 ReportGUCOption(gconf);
3622 * Push previous state during transactional assignment to a GUC variable.
3625 push_old_value(struct config_generic * gconf, GucAction action)
3629 /* If we're not inside a nest level, do nothing */
3630 if (GUCNestLevel == 0)
3633 /* Do we already have a stack entry of the current nest level? */
3634 stack = gconf->stack;
3635 if (stack && stack->nest_level >= GUCNestLevel)
3637 /* Yes, so adjust its state if necessary */
3638 Assert(stack->nest_level == GUCNestLevel);
3641 case GUC_ACTION_SET:
3642 /* SET overrides any prior action at same nest level */
3643 if (stack->state == GUC_SET_LOCAL)
3645 /* must discard old masked value */
3646 discard_stack_value(gconf, &stack->masked);
3648 stack->state = GUC_SET;
3650 case GUC_ACTION_LOCAL:
3651 if (stack->state == GUC_SET)
3653 /* SET followed by SET LOCAL, remember SET's value */
3654 set_stack_value(gconf, &stack->masked);
3655 stack->state = GUC_SET_LOCAL;
3657 /* in all other cases, no change to stack entry */
3659 case GUC_ACTION_SAVE:
3660 /* Could only have a prior SAVE of same variable */
3661 Assert(stack->state == GUC_SAVE);
3664 Assert(guc_dirty); /* must be set already */
3669 * Push a new stack entry
3671 * We keep all the stack entries in TopTransactionContext for simplicity.
3673 stack = (GucStack *) MemoryContextAllocZero(TopTransactionContext,
3676 stack->prev = gconf->stack;
3677 stack->nest_level = GUCNestLevel;
3680 case GUC_ACTION_SET:
3681 stack->state = GUC_SET;
3683 case GUC_ACTION_LOCAL:
3684 stack->state = GUC_LOCAL;
3686 case GUC_ACTION_SAVE:
3687 stack->state = GUC_SAVE;
3690 stack->source = gconf->source;
3691 set_stack_value(gconf, &stack->prior);
3693 gconf->stack = stack;
3695 /* Ensure we remember to pop at end of xact */
3701 * Do GUC processing at main transaction start.
3707 * The nest level should be 0 between transactions; if it isn't, somebody
3708 * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
3709 * throw a warning but make no other effort to clean up.
3711 if (GUCNestLevel != 0)
3712 elog(WARNING, "GUC nest level = %d at transaction start",
3718 * Enter a new nesting level for GUC values. This is called at subtransaction
3719 * start and when entering a function that has proconfig settings. NOTE that
3720 * we must not risk error here, else subtransaction start will be unhappy.
3723 NewGUCNestLevel(void)
3725 return ++GUCNestLevel;
3729 * Do GUC processing at transaction or subtransaction commit or abort, or
3730 * when exiting a function that has proconfig settings. (The name is thus
3731 * a bit of a misnomer; perhaps it should be ExitGUCNestLevel or some such.)
3732 * During abort, we discard all GUC settings that were applied at nesting
3733 * levels >= nestLevel. nestLevel == 1 corresponds to the main transaction.
3736 AtEOXact_GUC(bool isCommit, int nestLevel)
3741 Assert(nestLevel > 0 && nestLevel <= GUCNestLevel);
3743 /* Quick exit if nothing's changed in this transaction */
3746 GUCNestLevel = nestLevel - 1;
3750 still_dirty = false;
3751 for (i = 0; i < num_guc_variables; i++)
3753 struct config_generic *gconf = guc_variables[i];
3757 * Process and pop each stack entry within the nest level. To
3758 * simplify fmgr_security_definer(), we allow failure exit from a
3759 * function-with-SET-options to be recovered at the surrounding
3760 * transaction or subtransaction abort; so there could be more than
3761 * one stack entry to pop.
3763 while ((stack = gconf->stack) != NULL &&
3764 stack->nest_level >= nestLevel)
3766 GucStack *prev = stack->prev;
3767 bool restorePrior = false;
3768 bool restoreMasked = false;
3772 * In this next bit, if we don't set either restorePrior or
3773 * restoreMasked, we must "discard" any unwanted fields of the
3774 * stack entries to avoid leaking memory. If we do set one of
3775 * those flags, unused fields will be cleaned up after restoring.
3777 if (!isCommit) /* if abort, always restore prior value */
3778 restorePrior = true;
3779 else if (stack->state == GUC_SAVE)
3780 restorePrior = true;
3781 else if (stack->nest_level == 1)
3783 /* transaction commit */
3784 if (stack->state == GUC_SET_LOCAL)
3785 restoreMasked = true;
3786 else if (stack->state == GUC_SET)
3788 /* we keep the current active value */
3789 discard_stack_value(gconf, &stack->prior);
3791 else /* must be GUC_LOCAL */
3792 restorePrior = true;
3794 else if (prev == NULL ||
3795 prev->nest_level < stack->nest_level - 1)
3797 /* decrement entry's level and do not pop it */
3798 stack->nest_level--;
3804 * We have to merge this stack entry into prev. See README for
3805 * discussion of this bit.
3807 switch (stack->state)
3810 Assert(false); /* can't get here */
3813 /* next level always becomes SET */
3814 discard_stack_value(gconf, &stack->prior);
3815 if (prev->state == GUC_SET_LOCAL)
3816 discard_stack_value(gconf, &prev->masked);
3817 prev->state = GUC_SET;
3821 if (prev->state == GUC_SET)
3823 /* LOCAL migrates down */
3824 prev->masked = stack->prior;
3825 prev->state = GUC_SET_LOCAL;
3829 /* else just forget this stack level */
3830 discard_stack_value(gconf, &stack->prior);
3835 /* prior state at this level no longer wanted */
3836 discard_stack_value(gconf, &stack->prior);
3837 /* copy down the masked state */
3838 if (prev->state == GUC_SET_LOCAL)
3839 discard_stack_value(gconf, &prev->masked);
3840 prev->masked = stack->masked;
3841 prev->state = GUC_SET_LOCAL;
3848 if (restorePrior || restoreMasked)
3850 /* Perform appropriate restoration of the stacked value */
3851 union config_var_value newvalue;
3852 GucSource newsource;
3856 newvalue = stack->masked;
3857 newsource = PGC_S_SESSION;
3861 newvalue = stack->prior;
3862 newsource = stack->source;
3865 switch (gconf->vartype)
3869 struct config_bool *conf = (struct config_bool *) gconf;
3870 bool newval = newvalue.boolval;
3872 if (*conf->variable != newval)
3874 if (conf->assign_hook)
3875 if (!(*conf->assign_hook) (newval,
3876 true, PGC_S_OVERRIDE))
3877 elog(LOG, "failed to commit %s",
3879 *conf->variable = newval;
3886 struct config_int *conf = (struct config_int *) gconf;
3887 int newval = newvalue.intval;
3889 if (*conf->variable != newval)
3891 if (conf->assign_hook)
3892 if (!(*conf->assign_hook) (newval,
3893 true, PGC_S_OVERRIDE))
3894 elog(LOG, "failed to commit %s",
3896 *conf->variable = newval;
3903 struct config_real *conf = (struct config_real *) gconf;
3904 double newval = newvalue.realval;
3906 if (*conf->variable != newval)
3908 if (conf->assign_hook)
3909 if (!(*conf->assign_hook) (newval,
3910 true, PGC_S_OVERRIDE))
3911 elog(LOG, "failed to commit %s",
3913 *conf->variable = newval;
3920 struct config_string *conf = (struct config_string *) gconf;
3921 char *newval = newvalue.stringval;
3923 if (*conf->variable != newval)
3925 if (conf->assign_hook && newval)
3929 newstr = (*conf->assign_hook) (newval, true,
3932 elog(LOG, "failed to commit %s",
3934 else if (newstr != newval)
3937 * If newval should now be freed,
3938 * it'll be taken care of below.
3940 * See notes in set_config_option
3943 newval = (char *) newstr;
3947 set_string_field(conf, conf->variable, newval);
3952 * Release stacked values if not used anymore. We
3953 * could use discard_stack_value() here, but since
3954 * we have type-specific code anyway, might as
3957 set_string_field(conf, &stack->prior.stringval, NULL);
3958 set_string_field(conf, &stack->masked.stringval, NULL);
3963 struct config_enum *conf = (struct config_enum *) gconf;
3964 int newval = newvalue.enumval;
3966 if (*conf->variable != newval)
3968 if (conf->assign_hook)
3969 if (!(*conf->assign_hook) (newval,
3970 true, PGC_S_OVERRIDE))
3971 elog(LOG, "failed to commit %s",
3973 *conf->variable = newval;
3980 gconf->source = newsource;
3983 /* Finish popping the state stack */
3984 gconf->stack = prev;
3987 /* Report new value if we changed it */
3988 if (changed && (gconf->flags & GUC_REPORT))
3989 ReportGUCOption(gconf);
3990 } /* end of stack-popping loop */
3996 /* If there are no remaining stack entries, we can reset guc_dirty */
3997 guc_dirty = still_dirty;
3999 /* Update nesting level */
4000 GUCNestLevel = nestLevel - 1;
4005 * Start up automatic reporting of changes to variables marked GUC_REPORT.
4006 * This is executed at completion of backend startup.
4009 BeginReportingGUCOptions(void)
4014 * Don't do anything unless talking to an interactive frontend of protocol
4017 if (whereToSendOutput != DestRemote ||
4018 PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
4021 reporting_enabled = true;
4023 /* Transmit initial values of interesting variables */
4024 for (i = 0; i < num_guc_variables; i++)
4026 struct config_generic *conf = guc_variables[i];
4028 if (conf->flags & GUC_REPORT)
4029 ReportGUCOption(conf);
4034 * ReportGUCOption: if appropriate, transmit option value to frontend
4037 ReportGUCOption(struct config_generic * record)
4039 if (reporting_enabled && (record->flags & GUC_REPORT))
4041 char *val = _ShowOption(record, false);
4042 StringInfoData msgbuf;
4044 pq_beginmessage(&msgbuf, 'S');
4045 pq_sendstring(&msgbuf, record->name);
4046 pq_sendstring(&msgbuf, val);
4047 pq_endmessage(&msgbuf);
4055 * Try to interpret value as boolean value. Valid values are: true,
4056 * false, yes, no, on, off, 1, 0; as well as unique prefixes thereof.
4057 * If the string parses okay, return true, else false.
4058 * If okay and result is not NULL, return the value in *result.
4061 parse_bool(const char *value, bool *result)
4063 size_t len = strlen(value);
4065 if (pg_strncasecmp(value, "true", len) == 0)
4070 else if (pg_strncasecmp(value, "false", len) == 0)
4076 else if (pg_strncasecmp(value, "yes", len) == 0)
4081 else if (pg_strncasecmp(value, "no", len) == 0)
4087 /* 'o' is not unique enough */
4088 else if (pg_strncasecmp(value, "on", (len > 2 ? len : 2)) == 0)
4093 else if (pg_strncasecmp(value, "off", (len > 2 ? len : 2)) == 0)
4099 else if (pg_strcasecmp(value, "1") == 0)
4104 else if (pg_strcasecmp(value, "0") == 0)
4113 *result = false; /* suppress compiler warning */
4122 * Try to parse value as an integer. The accepted formats are the
4123 * usual decimal, octal, or hexadecimal formats, optionally followed by
4124 * a unit name if "flags" indicates a unit is allowed.
4126 * If the string parses okay, return true, else false.
4127 * If okay and result is not NULL, return the value in *result.
4128 * If not okay and hintmsg is not NULL, *hintmsg is set to a suitable
4129 * HINT message, or NULL if no hint provided.
4132 parse_int(const char *value, int *result, int flags, const char **hintmsg)
4137 /* To suppress compiler warnings, always set output params */
4143 /* We assume here that int64 is at least as wide as long */
4145 val = strtol(value, &endptr, 0);
4147 if (endptr == value)
4148 return false; /* no HINT for integer syntax error */
4150 if (errno == ERANGE || val != (int64) ((int32) val))
4153 *hintmsg = gettext_noop("Value exceeds integer range.");
4157 /* allow whitespace between integer and unit */
4158 while (isspace((unsigned char) *endptr))
4161 /* Handle possible unit */
4162 if (*endptr != '\0')
4165 * Note: the multiple-switch coding technique here is a bit tedious,
4166 * but seems necessary to avoid intermediate-value overflows.
4168 * If INT64_IS_BUSTED (ie, it's really int32) we will fail to detect
4169 * overflow due to units conversion, but there are few enough such
4170 * machines that it does not seem worth trying to be smarter.
4172 if (flags & GUC_UNIT_MEMORY)
4174 /* Set hint for use if no match or trailing garbage */
4176 *hintmsg = gettext_noop("Valid units for this parameter are \"kB\", \"MB\", and \"GB\".");
4178 #if BLCKSZ < 1024 || BLCKSZ > (1024*1024)
4179 #error BLCKSZ must be between 1KB and 1MB
4181 #if XLOG_BLCKSZ < 1024 || XLOG_BLCKSZ > (1024*1024)
4182 #error XLOG_BLCKSZ must be between 1KB and 1MB
4185 if (strncmp(endptr, "kB", 2) == 0)
4188 switch (flags & GUC_UNIT_MEMORY)
4190 case GUC_UNIT_BLOCKS:
4191 val /= (BLCKSZ / 1024);
4193 case GUC_UNIT_XBLOCKS:
4194 val /= (XLOG_BLCKSZ / 1024);
4198 else if (strncmp(endptr, "MB", 2) == 0)
4201 switch (flags & GUC_UNIT_MEMORY)
4206 case GUC_UNIT_BLOCKS:
4207 val *= KB_PER_MB / (BLCKSZ / 1024);
4209 case GUC_UNIT_XBLOCKS:
4210 val *= KB_PER_MB / (XLOG_BLCKSZ / 1024);
4214 else if (strncmp(endptr, "GB", 2) == 0)
4217 switch (flags & GUC_UNIT_MEMORY)
4222 case GUC_UNIT_BLOCKS:
4223 val *= KB_PER_GB / (BLCKSZ / 1024);
4225 case GUC_UNIT_XBLOCKS:
4226 val *= KB_PER_GB / (XLOG_BLCKSZ / 1024);
4231 else if (flags & GUC_UNIT_TIME)
4233 /* Set hint for use if no match or trailing garbage */
4235 *hintmsg = gettext_noop("Valid units for this parameter are \"ms\", \"s\", \"min\", \"h\", and \"d\".");
4237 if (strncmp(endptr, "ms", 2) == 0)
4240 switch (flags & GUC_UNIT_TIME)
4250 else if (strncmp(endptr, "s", 1) == 0)
4253 switch (flags & GUC_UNIT_TIME)
4263 else if (strncmp(endptr, "min", 3) == 0)
4266 switch (flags & GUC_UNIT_TIME)
4276 else if (strncmp(endptr, "h", 1) == 0)
4279 switch (flags & GUC_UNIT_TIME)
4292 else if (strncmp(endptr, "d", 1) == 0)
4295 switch (flags & GUC_UNIT_TIME)
4310 /* allow whitespace after unit */
4311 while (isspace((unsigned char) *endptr))
4314 if (*endptr != '\0')
4315 return false; /* appropriate hint, if any, already set */
4317 /* Check for overflow due to units conversion */
4318 if (val != (int64) ((int32) val))
4321 *hintmsg = gettext_noop("Value exceeds integer range.");
4327 *result = (int) val;
4334 * Try to parse value as a floating point number in the usual format.
4335 * If the string parses okay, return true, else false.
4336 * If okay and result is not NULL, return the value in *result.
4339 parse_real(const char *value, double *result)
4345 *result = 0; /* suppress compiler warning */
4348 val = strtod(value, &endptr);
4349 if (endptr == value || errno == ERANGE)
4352 /* allow whitespace after number */
4353 while (isspace((unsigned char) *endptr))
4355 if (*endptr != '\0')
4365 * Lookup the name for an enum option with the selected value.
4366 * Should only ever be called with known-valid values, so throws
4367 * an elog(ERROR) if the enum option is not found.
4369 * The returned string is a pointer to static data and not
4370 * allocated for modification.
4373 config_enum_lookup_by_value(struct config_enum *record, int val)
4375 const struct config_enum_entry *entry = record->options;
4376 while (entry && entry->name)
4378 if (entry->val == val)
4382 elog(ERROR, "could not find enum option %d for %s",
4383 val, record->gen.name);
4384 return NULL; /* silence compiler */
4389 * Lookup the value for an enum option with the selected name
4390 * (case-insensitive).
4391 * If the enum option is found, sets the retval value and returns
4392 * true. If it's not found, return FALSE and retval is set to 0.
4396 config_enum_lookup_by_name(struct config_enum *record, const char *value, int *retval)
4398 const struct config_enum_entry *entry = record->options;
4401 *retval = 0; /* suppress compiler warning */
4403 while (entry && entry->name)
4405 if (pg_strcasecmp(value, entry->name) == 0)
4407 *retval = entry->val;
4417 * Return a list of all available options for an enum, excluding
4418 * hidden ones, separated by ", " (comma-space).
4419 * If prefix is non-NULL, it is added before the first enum value.
4420 * If suffix is non-NULL, it is added to the end of the string.
4423 config_enum_get_options(struct config_enum *record, const char *prefix, const char *suffix)
4425 const struct config_enum_entry *entry = record->options;
4429 if (!entry || !entry->name)
4430 return NULL; /* Should not happen */
4432 while (entry && entry->name)
4435 len += strlen(entry->name) + 2; /* string and ", " */
4440 hintmsg = palloc(len + strlen(prefix) + strlen(suffix) + 2);
4442 strcpy(hintmsg, prefix);
4444 entry = record->options;
4445 while (entry && entry->name)
4449 strcat(hintmsg, entry->name);
4450 strcat(hintmsg, ", ");
4456 len = strlen(hintmsg);
4459 * All the entries may have been hidden, leaving the string empty
4460 * if no prefix was given. This indicates a broken GUC setup, since
4461 * there is no use for an enum without any values, so we just check
4462 * to make sure we don't write to invalid memory instead of actually
4463 * trying to do something smart with it.
4466 /* Replace final comma/space */
4467 hintmsg[len-2] = '\0';
4469 strcat(hintmsg, suffix);
4476 * Call a GucStringAssignHook function, being careful to free the
4477 * "newval" string if the hook ereports.
4479 * This is split out of set_config_option just to avoid the "volatile"
4480 * qualifiers that would otherwise have to be plastered all over.
4483 call_string_assign_hook(GucStringAssignHook assign_hook,
4484 char *newval, bool doit, GucSource source)
4490 result = (*assign_hook) (newval, doit, source);
4504 * Sets option `name' to given value. The value should be a string
4505 * which is going to be parsed and converted to the appropriate data
4506 * type. The context and source parameters indicate in which context this
4507 * function is being called so it can apply the access restrictions
4510 * If value is NULL, set the option to its default value (normally the
4511 * reset_val, but if source == PGC_S_DEFAULT we instead use the boot_val).
4513 * action indicates whether to set the value globally in the session, locally
4514 * to the current top transaction, or just for the duration of a function call.
4516 * If changeVal is false then don't really set the option but do all
4517 * the checks to see if it would work.
4519 * If there is an error (non-existing option, invalid value) then an
4520 * ereport(ERROR) is thrown *unless* this is called in a context where we
4521 * don't want to ereport (currently, startup or SIGHUP config file reread).
4522 * In that case we write a suitable error message via ereport(LOG) and
4523 * return false. This is working around the deficiencies in the ereport
4524 * mechanism, so don't blame me. In all other cases, the function
4525 * returns true, including cases where the input is valid but we chose
4526 * not to apply it because of context or source-priority considerations.
4528 * See also SetConfigOption for an external interface.
4531 set_config_option(const char *name, const char *value,
4532 GucContext context, GucSource source,
4533 GucAction action, bool changeVal)
4535 struct config_generic *record;
4539 if (context == PGC_SIGHUP || source == PGC_S_DEFAULT)
4542 * To avoid cluttering the log, only the postmaster bleats loudly
4543 * about problems with the config file.
4545 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
4547 else if (source == PGC_S_DATABASE || source == PGC_S_USER)
4552 record = find_option(name, true, elevel);
4556 (errcode(ERRCODE_UNDEFINED_OBJECT),
4557 errmsg("unrecognized configuration parameter \"%s\"", name)));
4562 * If source is postgresql.conf, mark the found record with
4563 * GUC_IS_IN_FILE. This is for the convenience of ProcessConfigFile. Note
4564 * that we do it even if changeVal is false, since ProcessConfigFile wants
4565 * the marking to occur during its testing pass.
4567 if (source == PGC_S_FILE)
4568 record->status |= GUC_IS_IN_FILE;
4571 * Check if the option can be set at this time. See guc.h for the precise
4572 * rules. Note that we don't want to throw errors if we're in the SIGHUP
4573 * context. In that case we just ignore the attempt and return true.
4575 switch (record->context)
4578 if (context == PGC_SIGHUP)
4580 if (context != PGC_INTERNAL)
4583 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4584 errmsg("parameter \"%s\" cannot be changed",
4589 case PGC_POSTMASTER:
4590 if (context == PGC_SIGHUP)
4593 * We are reading a PGC_POSTMASTER var from postgresql.conf.
4594 * We can't change the setting, so give a warning if the DBA
4595 * tries to change it. (Throwing an error would be more
4596 * consistent, but seems overly rigid.)
4598 if (changeVal && !is_newvalue_equal(record, value))
4600 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4601 errmsg("parameter \"%s\" cannot be changed after server start; configuration file change ignored",
4605 if (context != PGC_POSTMASTER)
4608 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4609 errmsg("parameter \"%s\" cannot be changed after server start",
4615 if (context != PGC_SIGHUP && context != PGC_POSTMASTER)
4618 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4619 errmsg("parameter \"%s\" cannot be changed now",
4625 * Hmm, the idea of the SIGHUP context is "ought to be global, but
4626 * can be changed after postmaster start". But there's nothing
4627 * that prevents a crafty administrator from sending SIGHUP
4628 * signals to individual backends only.
4632 if (context == PGC_SIGHUP)
4635 * If a PGC_BACKEND parameter is changed in the config file,
4636 * we want to accept the new value in the postmaster (whence
4637 * it will propagate to subsequently-started backends), but
4638 * ignore it in existing backends. This is a tad klugy, but
4639 * necessary because we don't re-read the config file during
4642 if (IsUnderPostmaster)
4645 else if (context != PGC_BACKEND && context != PGC_POSTMASTER)
4648 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4649 errmsg("parameter \"%s\" cannot be set after connection start",
4655 if (context == PGC_USERSET || context == PGC_BACKEND)
4658 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4659 errmsg("permission denied to set parameter \"%s\"",
4670 * Should we set reset/stacked values? (If so, the behavior is not
4671 * transactional.) This is done either when we get a default value from
4672 * the database's/user's/client's default settings or when we reset a
4673 * value to its default.
4675 makeDefault = changeVal && (source <= PGC_S_OVERRIDE) &&
4676 ((value != NULL) || source == PGC_S_DEFAULT);
4679 * Ignore attempted set if overridden by previously processed setting.
4680 * However, if changeVal is false then plow ahead anyway since we are
4681 * trying to find out if the value is potentially good, not actually use
4682 * it. Also keep going if makeDefault is true, since we may want to set
4683 * the reset/stacked values even if we can't set the variable itself.
4685 if (record->source > source)
4687 if (changeVal && !makeDefault)
4689 elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
4697 * Evaluate value and set variable.
4699 switch (record->vartype)
4703 struct config_bool *conf = (struct config_bool *) record;
4708 if (!parse_bool(value, &newval))
4711 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4712 errmsg("parameter \"%s\" requires a Boolean value",
4717 else if (source == PGC_S_DEFAULT)
4718 newval = conf->boot_val;
4721 newval = conf->reset_val;
4722 source = conf->gen.reset_source;
4725 /* Save old value to support transaction abort */
4726 if (changeVal && !makeDefault)
4727 push_old_value(&conf->gen, action);
4729 if (conf->assign_hook)
4730 if (!(*conf->assign_hook) (newval, changeVal, source))
4733 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4734 errmsg("invalid value for parameter \"%s\": %d",
4735 name, (int) newval)));
4741 *conf->variable = newval;
4742 conf->gen.source = source;
4748 if (conf->gen.reset_source <= source)
4750 conf->reset_val = newval;
4751 conf->gen.reset_source = source;
4753 for (stack = conf->gen.stack; stack; stack = stack->prev)
4755 if (stack->source <= source)
4757 stack->prior.boolval = newval;
4758 stack->source = source;
4767 struct config_int *conf = (struct config_int *) record;
4772 const char *hintmsg;
4774 if (!parse_int(value, &newval, conf->gen.flags, &hintmsg))
4777 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4778 errmsg("invalid value for parameter \"%s\": \"%s\"",
4780 hintmsg ? errhint(hintmsg) : 0));
4783 if (newval < conf->min || newval > conf->max)
4786 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4787 errmsg("%d is outside the valid range for parameter \"%s\" (%d .. %d)",
4788 newval, name, conf->min, conf->max)));
4792 else if (source == PGC_S_DEFAULT)
4793 newval = conf->boot_val;
4796 newval = conf->reset_val;
4797 source = conf->gen.reset_source;
4800 /* Save old value to support transaction abort */
4801 if (changeVal && !makeDefault)
4802 push_old_value(&conf->gen, action);
4804 if (conf->assign_hook)
4805 if (!(*conf->assign_hook) (newval, changeVal, source))
4808 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4809 errmsg("invalid value for parameter \"%s\": %d",
4816 *conf->variable = newval;
4817 conf->gen.source = source;
4823 if (conf->gen.reset_source <= source)
4825 conf->reset_val = newval;
4826 conf->gen.reset_source = source;
4828 for (stack = conf->gen.stack; stack; stack = stack->prev)
4830 if (stack->source <= source)
4832 stack->prior.intval = newval;
4833 stack->source = source;
4842 struct config_real *conf = (struct config_real *) record;
4847 if (!parse_real(value, &newval))
4850 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4851 errmsg("parameter \"%s\" requires a numeric value",
4855 if (newval < conf->min || newval > conf->max)
4858 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4859 errmsg("%g is outside the valid range for parameter \"%s\" (%g .. %g)",
4860 newval, name, conf->min, conf->max)));
4864 else if (source == PGC_S_DEFAULT)
4865 newval = conf->boot_val;
4868 newval = conf->reset_val;
4869 source = conf->gen.reset_source;
4872 /* Save old value to support transaction abort */
4873 if (changeVal && !makeDefault)
4874 push_old_value(&conf->gen, action);
4876 if (conf->assign_hook)
4877 if (!(*conf->assign_hook) (newval, changeVal, source))
4880 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4881 errmsg("invalid value for parameter \"%s\": %g",
4888 *conf->variable = newval;
4889 conf->gen.source = source;
4895 if (conf->gen.reset_source <= source)
4897 conf->reset_val = newval;
4898 conf->gen.reset_source = source;
4900 for (stack = conf->gen.stack; stack; stack = stack->prev)
4902 if (stack->source <= source)
4904 stack->prior.realval = newval;
4905 stack->source = source;
4914 struct config_string *conf = (struct config_string *) record;
4919 newval = guc_strdup(elevel, value);
4924 * The only sort of "parsing" check we need to do is apply
4925 * truncation if GUC_IS_NAME.
4927 if (conf->gen.flags & GUC_IS_NAME)
4928 truncate_identifier(newval, strlen(newval), true);
4930 else if (source == PGC_S_DEFAULT)
4932 if (conf->boot_val == NULL)
4936 newval = guc_strdup(elevel, conf->boot_val);
4944 * We could possibly avoid strdup here, but easier to make
4945 * this case work the same as the normal assignment case;
4946 * note the possible free of newval below.
4948 if (conf->reset_val == NULL)
4952 newval = guc_strdup(elevel, conf->reset_val);
4956 source = conf->gen.reset_source;
4959 /* Save old value to support transaction abort */
4960 if (changeVal && !makeDefault)
4961 push_old_value(&conf->gen, action);
4963 if (conf->assign_hook && newval)
4965 const char *hookresult;
4968 * If the hook ereports, we have to make sure we free
4969 * newval, else it will be a permanent memory leak.
4971 hookresult = call_string_assign_hook(conf->assign_hook,
4975 if (hookresult == NULL)
4979 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4980 errmsg("invalid value for parameter \"%s\": \"%s\"",
4981 name, value ? value : "")));
4984 else if (hookresult != newval)
4989 * Having to cast away const here is annoying, but the
4990 * alternative is to declare assign_hooks as returning
4991 * char*, which would mean they'd have to cast away
4992 * const, or as both taking and returning char*, which
4993 * doesn't seem attractive either --- we don't want
4994 * them to scribble on the passed str.
4996 newval = (char *) hookresult;
5002 set_string_field(conf, conf->variable, newval);
5003 conf->gen.source = source;
5009 if (conf->gen.reset_source <= source)
5011 set_string_field(conf, &conf->reset_val, newval);
5012 conf->gen.reset_source = source;
5014 for (stack = conf->gen.stack; stack; stack = stack->prev)
5016 if (stack->source <= source)
5018 set_string_field(conf, &stack->prior.stringval,
5020 stack->source = source;
5024 /* Perhaps we didn't install newval anywhere */
5025 if (newval && !string_field_used(conf, newval))
5031 struct config_enum *conf = (struct config_enum *) record;
5036 if (!config_enum_lookup_by_name(conf, value, &newval))
5038 char *hintmsg = config_enum_get_options(conf, "Available values: ", ".");
5041 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5042 errmsg("invalid value for parameter \"%s\": \"%s\"",
5044 hintmsg ? errhint(hintmsg) : 0));
5051 else if (source == PGC_S_DEFAULT)
5052 newval = conf->boot_val;
5055 newval = conf->reset_val;
5056 source = conf->gen.reset_source;
5059 /* Save old value to support transaction abort */
5060 if (changeVal && !makeDefault)
5061 push_old_value(&conf->gen, action);
5063 if (conf->assign_hook)
5064 if (!(*conf->assign_hook) (newval, changeVal, source))
5067 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5068 errmsg("invalid value for parameter \"%s\": \"%s\"",
5070 config_enum_lookup_by_value(conf, newval))));
5076 *conf->variable = newval;
5077 conf->gen.source = source;
5083 if (conf->gen.reset_source <= source)
5085 conf->reset_val = newval;
5086 conf->gen.reset_source = source;
5088 for (stack = conf->gen.stack; stack; stack = stack->prev)
5090 if (stack->source <= source)
5092 stack->prior.enumval = newval;
5093 stack->source = source;
5101 if (changeVal && (record->flags & GUC_REPORT))
5102 ReportGUCOption(record);
5109 * Set a config option to the given value. See also set_config_option,
5110 * this is just the wrapper to be called from outside GUC. NB: this
5111 * is used only for non-transactional operations.
5114 SetConfigOption(const char *name, const char *value,
5115 GucContext context, GucSource source)
5117 (void) set_config_option(name, value, context, source,
5118 GUC_ACTION_SET, true);
5124 * Fetch the current value of the option `name'. If the option doesn't exist,
5125 * throw an ereport and don't return.
5127 * The string is *not* allocated for modification and is really only
5128 * valid until the next call to configuration related functions.
5131 GetConfigOption(const char *name)
5133 struct config_generic *record;
5134 static char buffer[256];
5136 record = find_option(name, false, ERROR);
5139 (errcode(ERRCODE_UNDEFINED_OBJECT),
5140 errmsg("unrecognized configuration parameter \"%s\"", name)));
5141 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
5143 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5144 errmsg("must be superuser to examine \"%s\"", name)));
5146 switch (record->vartype)
5149 return *((struct config_bool *) record)->variable ? "on" : "off";
5152 snprintf(buffer, sizeof(buffer), "%d",
5153 *((struct config_int *) record)->variable);
5157 snprintf(buffer, sizeof(buffer), "%g",
5158 *((struct config_real *) record)->variable);
5162 return *((struct config_string *) record)->variable;
5165 return config_enum_lookup_by_value((struct config_enum *) record,
5166 *((struct config_enum *) record)->variable);
5172 * Get the RESET value associated with the given option.
5174 * Note: this is not re-entrant, due to use of static result buffer;
5175 * not to mention that a string variable could have its reset_val changed.
5176 * Beware of assuming the result value is good for very long.
5179 GetConfigOptionResetString(const char *name)
5181 struct config_generic *record;
5182 static char buffer[256];
5184 record = find_option(name, false, ERROR);
5187 (errcode(ERRCODE_UNDEFINED_OBJECT),
5188 errmsg("unrecognized configuration parameter \"%s\"", name)));
5189 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
5191 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5192 errmsg("must be superuser to examine \"%s\"", name)));
5194 switch (record->vartype)
5197 return ((struct config_bool *) record)->reset_val ? "on" : "off";
5200 snprintf(buffer, sizeof(buffer), "%d",
5201 ((struct config_int *) record)->reset_val);
5205 snprintf(buffer, sizeof(buffer), "%g",
5206 ((struct config_real *) record)->reset_val);
5210 return ((struct config_string *) record)->reset_val;
5213 return config_enum_lookup_by_value((struct config_enum *) record,
5214 ((struct config_enum *) record)->reset_val);
5220 * Detect whether the given configuration option can only be set by
5224 IsSuperuserConfigOption(const char *name)
5226 struct config_generic *record;
5228 record = find_option(name, false, ERROR);
5229 /* On an unrecognized name, don't error, just return false. */
5232 return (record->context == PGC_SUSET);
5237 * GUC_complaint_elevel
5238 * Get the ereport error level to use in an assign_hook's error report.
5240 * This should be used by assign hooks that want to emit a custom error
5241 * report (in addition to the generic "invalid value for option FOO" that
5242 * guc.c will provide). Note that the result might be ERROR or a lower
5243 * level, so the caller must be prepared for control to return from ereport,
5244 * or not. If control does return, return false/NULL from the hook function.
5246 * At some point it'd be nice to replace this with a mechanism that allows
5247 * the custom message to become the DETAIL line of guc.c's generic message.
5250 GUC_complaint_elevel(GucSource source)
5254 if (source == PGC_S_FILE)
5257 * To avoid cluttering the log, only the postmaster bleats loudly
5258 * about problems with the config file.
5260 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
5262 else if (source == PGC_S_OVERRIDE)
5265 * If we're a postmaster child, this is probably "undo" during
5266 * transaction abort, so we don't want to clutter the log. There's
5267 * a small chance of a real problem with an OVERRIDE setting,
5268 * though, so suppressing the message entirely wouldn't be desirable.
5270 elevel = IsUnderPostmaster ? DEBUG5 : LOG;
5272 else if (source < PGC_S_INTERACTIVE)
5282 * flatten_set_variable_args
5283 * Given a parsenode List as emitted by the grammar for SET,
5284 * convert to the flat string representation used by GUC.
5286 * We need to be told the name of the variable the args are for, because
5287 * the flattening rules vary (ugh).
5289 * The result is NULL if args is NIL (ie, SET ... TO DEFAULT), otherwise
5290 * a palloc'd string.
5293 flatten_set_variable_args(const char *name, List *args)
5295 struct config_generic *record;
5300 /* Fast path if just DEFAULT */
5304 /* Else get flags for the variable */
5305 record = find_option(name, true, ERROR);
5308 (errcode(ERRCODE_UNDEFINED_OBJECT),
5309 errmsg("unrecognized configuration parameter \"%s\"", name)));
5311 flags = record->flags;
5313 /* Complain if list input and non-list variable */
5314 if ((flags & GUC_LIST_INPUT) == 0 &&
5315 list_length(args) != 1)
5317 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5318 errmsg("SET %s takes only one argument", name)));
5320 initStringInfo(&buf);
5323 * Each list member may be a plain A_Const node, or an A_Const within a
5324 * TypeCast; the latter case is supported only for ConstInterval
5325 * arguments (for SET TIME ZONE).
5329 Node *arg = (Node *) lfirst(l);
5331 TypeName *typename = NULL;
5334 if (l != list_head(args))
5335 appendStringInfo(&buf, ", ");
5337 if (IsA(arg, TypeCast))
5339 TypeCast *tc = (TypeCast *) arg;
5342 typename = tc->typename;
5345 if (!IsA(arg, A_Const))
5346 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
5347 con = (A_Const *) arg;
5349 switch (nodeTag(&con->val))
5352 appendStringInfo(&buf, "%ld", intVal(&con->val));
5355 /* represented as a string, so just copy it */
5356 appendStringInfoString(&buf, strVal(&con->val));
5359 val = strVal(&con->val);
5360 if (typename != NULL)
5363 * Must be a ConstInterval argument for TIME ZONE. Coerce
5364 * to interval and back to normalize the value and account
5372 typoid = typenameTypeId(NULL, typename, &typmod);
5373 Assert(typoid == INTERVALOID);
5376 DirectFunctionCall3(interval_in,
5377 CStringGetDatum(val),
5378 ObjectIdGetDatum(InvalidOid),
5379 Int32GetDatum(typmod));
5382 DatumGetCString(DirectFunctionCall1(interval_out,
5384 appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
5389 * Plain string literal or identifier. For quote mode,
5390 * quote it if it's not a vanilla identifier.
5392 if (flags & GUC_LIST_QUOTE)
5393 appendStringInfoString(&buf, quote_identifier(val));
5395 appendStringInfoString(&buf, val);
5399 elog(ERROR, "unrecognized node type: %d",
5400 (int) nodeTag(&con->val));
5413 ExecSetVariableStmt(VariableSetStmt *stmt)
5415 GucAction action = stmt->is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET;
5420 case VAR_SET_CURRENT:
5421 set_config_option(stmt->name,
5422 ExtractSetVariableArgs(stmt),
5423 (superuser() ? PGC_SUSET : PGC_USERSET),
5431 * Special case for special SQL syntax that effectively sets more
5432 * than one variable per statement.
5434 if (strcmp(stmt->name, "TRANSACTION") == 0)
5438 foreach(head, stmt->args)
5440 DefElem *item = (DefElem *) lfirst(head);
5442 if (strcmp(item->defname, "transaction_isolation") == 0)
5443 SetPGVariable("transaction_isolation",
5444 list_make1(item->arg), stmt->is_local);
5445 else if (strcmp(item->defname, "transaction_read_only") == 0)
5446 SetPGVariable("transaction_read_only",
5447 list_make1(item->arg), stmt->is_local);
5449 elog(ERROR, "unexpected SET TRANSACTION element: %s",
5453 else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
5457 foreach(head, stmt->args)
5459 DefElem *item = (DefElem *) lfirst(head);
5461 if (strcmp(item->defname, "transaction_isolation") == 0)
5462 SetPGVariable("default_transaction_isolation",
5463 list_make1(item->arg), stmt->is_local);
5464 else if (strcmp(item->defname, "transaction_read_only") == 0)
5465 SetPGVariable("default_transaction_read_only",
5466 list_make1(item->arg), stmt->is_local);
5468 elog(ERROR, "unexpected SET SESSION element: %s",
5473 elog(ERROR, "unexpected SET MULTI element: %s",
5476 case VAR_SET_DEFAULT:
5478 set_config_option(stmt->name,
5480 (superuser() ? PGC_SUSET : PGC_USERSET),
5492 * Get the value to assign for a VariableSetStmt, or NULL if it's RESET.
5493 * The result is palloc'd.
5495 * This is exported for use by actions such as ALTER ROLE SET.
5498 ExtractSetVariableArgs(VariableSetStmt *stmt)
5503 return flatten_set_variable_args(stmt->name, stmt->args);
5504 case VAR_SET_CURRENT:
5505 return GetConfigOptionByName(stmt->name, NULL);
5512 * SetPGVariable - SET command exported as an easily-C-callable function.
5514 * This provides access to SET TO value, as well as SET TO DEFAULT (expressed
5515 * by passing args == NIL), but not SET FROM CURRENT functionality.
5518 SetPGVariable(const char *name, List *args, bool is_local)
5520 char *argstring = flatten_set_variable_args(name, args);
5522 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
5523 set_config_option(name,
5525 (superuser() ? PGC_SUSET : PGC_USERSET),
5527 is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET,
5532 * SET command wrapped as a SQL callable function.
5535 set_config_by_name(PG_FUNCTION_ARGS)
5542 if (PG_ARGISNULL(0))
5544 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
5545 errmsg("SET requires parameter name")));
5547 /* Get the GUC variable name */
5548 name = TextDatumGetCString(PG_GETARG_DATUM(0));
5550 /* Get the desired value or set to NULL for a reset request */
5551 if (PG_ARGISNULL(1))
5554 value = TextDatumGetCString(PG_GETARG_DATUM(1));
5557 * Get the desired state of is_local. Default to false if provided value
5560 if (PG_ARGISNULL(2))
5563 is_local = PG_GETARG_BOOL(2);
5565 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
5566 set_config_option(name,
5568 (superuser() ? PGC_SUSET : PGC_USERSET),
5570 is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET,
5573 /* get the new current value */
5574 new_value = GetConfigOptionByName(name, NULL);
5576 /* Convert return string to text */
5577 PG_RETURN_TEXT_P(cstring_to_text(new_value));
5582 * Common code for DefineCustomXXXVariable subroutines: allocate the
5583 * new variable's config struct and fill in generic fields.
5585 static struct config_generic *
5586 init_custom_variable(const char *name,
5587 const char *short_desc,
5588 const char *long_desc,
5590 enum config_type type,
5593 struct config_generic *gen;
5595 gen = (struct config_generic *) guc_malloc(ERROR, sz);
5598 gen->name = guc_strdup(ERROR, name);
5599 gen->context = context;
5600 gen->group = CUSTOM_OPTIONS;
5601 gen->short_desc = short_desc;
5602 gen->long_desc = long_desc;
5603 gen->vartype = type;
5609 * Common code for DefineCustomXXXVariable subroutines: insert the new
5610 * variable into the GUC variable array, replacing any placeholder.
5613 define_custom_variable(struct config_generic * variable)
5615 const char *name = variable->name;
5616 const char **nameAddr = &name;
5618 struct config_string *pHolder;
5619 struct config_generic **res;
5621 res = (struct config_generic **) bsearch((void *) &nameAddr,
5622 (void *) guc_variables,
5624 sizeof(struct config_generic *),
5628 /* No placeholder to replace, so just add it */
5629 add_guc_variable(variable, ERROR);
5634 * This better be a placeholder
5636 if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
5638 (errcode(ERRCODE_INTERNAL_ERROR),
5639 errmsg("attempt to redefine parameter \"%s\"", name)));
5641 Assert((*res)->vartype == PGC_STRING);
5642 pHolder = (struct config_string *) (*res);
5645 * Replace the placeholder. We aren't changing the name, so no re-sorting
5651 * Assign the string value stored in the placeholder to the real variable.
5653 * XXX this is not really good enough --- it should be a nontransactional
5654 * assignment, since we don't want it to roll back if the current xact
5657 value = *pHolder->variable;
5660 set_config_option(name, value,
5661 pHolder->gen.context, pHolder->gen.source,
5662 GUC_ACTION_SET, true);
5665 * Free up as much as we conveniently can of the placeholder structure
5666 * (this neglects any stack items...)
5668 set_string_field(pHolder, pHolder->variable, NULL);
5669 set_string_field(pHolder, &pHolder->reset_val, NULL);
5675 DefineCustomBoolVariable(const char *name,
5676 const char *short_desc,
5677 const char *long_desc,
5680 GucBoolAssignHook assign_hook,
5681 GucShowHook show_hook)
5683 struct config_bool *var;
5685 var = (struct config_bool *)
5686 init_custom_variable(name, short_desc, long_desc, context,
5687 PGC_BOOL, sizeof(struct config_bool));
5688 var->variable = valueAddr;
5689 var->boot_val = *valueAddr;
5690 var->reset_val = *valueAddr;
5691 var->assign_hook = assign_hook;
5692 var->show_hook = show_hook;
5693 define_custom_variable(&var->gen);
5697 DefineCustomIntVariable(const char *name,
5698 const char *short_desc,
5699 const char *long_desc,
5704 GucIntAssignHook assign_hook,
5705 GucShowHook show_hook)
5707 struct config_int *var;
5709 var = (struct config_int *)
5710 init_custom_variable(name, short_desc, long_desc, context,
5711 PGC_INT, sizeof(struct config_int));
5712 var->variable = valueAddr;
5713 var->boot_val = *valueAddr;
5714 var->reset_val = *valueAddr;
5715 var->min = minValue;
5716 var->max = maxValue;
5717 var->assign_hook = assign_hook;
5718 var->show_hook = show_hook;
5719 define_custom_variable(&var->gen);
5723 DefineCustomRealVariable(const char *name,
5724 const char *short_desc,
5725 const char *long_desc,
5730 GucRealAssignHook assign_hook,
5731 GucShowHook show_hook)
5733 struct config_real *var;
5735 var = (struct config_real *)
5736 init_custom_variable(name, short_desc, long_desc, context,
5737 PGC_REAL, sizeof(struct config_real));
5738 var->variable = valueAddr;
5739 var->boot_val = *valueAddr;
5740 var->reset_val = *valueAddr;
5741 var->min = minValue;
5742 var->max = maxValue;
5743 var->assign_hook = assign_hook;
5744 var->show_hook = show_hook;
5745 define_custom_variable(&var->gen);
5749 DefineCustomStringVariable(const char *name,
5750 const char *short_desc,
5751 const char *long_desc,
5754 GucStringAssignHook assign_hook,
5755 GucShowHook show_hook)
5757 struct config_string *var;
5759 var = (struct config_string *)
5760 init_custom_variable(name, short_desc, long_desc, context,
5761 PGC_STRING, sizeof(struct config_string));
5762 var->variable = valueAddr;
5763 var->boot_val = *valueAddr;
5764 /* we could probably do without strdup, but keep it like normal case */
5766 var->reset_val = guc_strdup(ERROR, var->boot_val);
5767 var->assign_hook = assign_hook;
5768 var->show_hook = show_hook;
5769 define_custom_variable(&var->gen);
5773 DefineCustomEnumVariable(const char *name,
5774 const char *short_desc,
5775 const char *long_desc,
5777 const struct config_enum_entry *options,
5779 GucEnumAssignHook assign_hook,
5780 GucShowHook show_hook)
5782 struct config_enum *var;
5784 var = (struct config_enum *)
5785 init_custom_variable(name, short_desc, long_desc, context,
5786 PGC_ENUM, sizeof(struct config_enum));
5787 var->variable = valueAddr;
5788 var->boot_val = *valueAddr;
5789 var->reset_val = *valueAddr;
5790 var->options = options;
5791 var->assign_hook = assign_hook;
5792 var->show_hook = show_hook;
5793 define_custom_variable(&var->gen);
5797 EmitWarningsOnPlaceholders(const char *className)
5799 struct config_generic **vars = guc_variables;
5800 struct config_generic **last = vars + num_guc_variables;
5802 int nameLen = strlen(className);
5806 struct config_generic *var = *vars++;
5808 if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
5809 strncmp(className, var->name, nameLen) == 0 &&
5810 var->name[nameLen] == GUC_QUALIFIER_SEPARATOR)
5813 (errcode(ERRCODE_UNDEFINED_OBJECT),
5814 errmsg("unrecognized configuration parameter \"%s\"", var->name)));
5824 GetPGVariable(const char *name, DestReceiver *dest)
5826 if (guc_name_compare(name, "all") == 0)
5827 ShowAllGUCConfig(dest);
5829 ShowGUCConfigOption(name, dest);
5833 GetPGVariableResultDesc(const char *name)
5837 if (guc_name_compare(name, "all") == 0)
5839 /* need a tuple descriptor representing three TEXT columns */
5840 tupdesc = CreateTemplateTupleDesc(3, false);
5841 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
5843 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
5845 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
5851 const char *varname;
5853 /* Get the canonical spelling of name */
5854 (void) GetConfigOptionByName(name, &varname);
5856 /* need a tuple descriptor representing a single TEXT column */
5857 tupdesc = CreateTemplateTupleDesc(1, false);
5858 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
5869 ShowGUCConfigOption(const char *name, DestReceiver *dest)
5871 TupOutputState *tstate;
5873 const char *varname;
5876 /* Get the value and canonical spelling of name */
5877 value = GetConfigOptionByName(name, &varname);
5879 /* need a tuple descriptor representing a single TEXT column */
5880 tupdesc = CreateTemplateTupleDesc(1, false);
5881 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
5884 /* prepare for projection of tuples */
5885 tstate = begin_tup_output_tupdesc(dest, tupdesc);
5888 do_text_output_oneline(tstate, value);
5890 end_tup_output(tstate);
5897 ShowAllGUCConfig(DestReceiver *dest)
5899 bool am_superuser = superuser();
5901 TupOutputState *tstate;
5905 /* need a tuple descriptor representing three TEXT columns */
5906 tupdesc = CreateTemplateTupleDesc(3, false);
5907 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
5909 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
5911 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
5915 /* prepare for projection of tuples */
5916 tstate = begin_tup_output_tupdesc(dest, tupdesc);
5918 for (i = 0; i < num_guc_variables; i++)
5920 struct config_generic *conf = guc_variables[i];
5922 if ((conf->flags & GUC_NO_SHOW_ALL) ||
5923 ((conf->flags & GUC_SUPERUSER_ONLY) && !am_superuser))
5926 /* assign to the values array */
5927 values[0] = (char *) conf->name;
5928 values[1] = _ShowOption(conf, true);
5929 values[2] = (char *) conf->short_desc;
5931 /* send it to dest */
5932 do_tup_output(tstate, values);
5935 if (values[1] != NULL)
5939 end_tup_output(tstate);
5943 * Return GUC variable value by name; optionally return canonical
5944 * form of name. Return value is palloc'd.
5947 GetConfigOptionByName(const char *name, const char **varname)
5949 struct config_generic *record;
5951 record = find_option(name, false, ERROR);
5954 (errcode(ERRCODE_UNDEFINED_OBJECT),
5955 errmsg("unrecognized configuration parameter \"%s\"", name)));
5956 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
5958 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5959 errmsg("must be superuser to examine \"%s\"", name)));
5962 *varname = record->name;
5964 return _ShowOption(record, true);
5968 * Return GUC variable value by variable number; optionally return canonical
5969 * form of name. Return value is palloc'd.
5972 GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
5975 struct config_generic *conf;
5977 /* check requested variable number valid */
5978 Assert((varnum >= 0) && (varnum < num_guc_variables));
5980 conf = guc_variables[varnum];
5984 if ((conf->flags & GUC_NO_SHOW_ALL) ||
5985 ((conf->flags & GUC_SUPERUSER_ONLY) && !superuser()))
5991 /* first get the generic attributes */
5994 values[0] = conf->name;
5996 /* setting : use _ShowOption in order to avoid duplicating the logic */
5997 values[1] = _ShowOption(conf, false);
6000 if (conf->vartype == PGC_INT)
6004 switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
6009 case GUC_UNIT_BLOCKS:
6010 snprintf(buf, sizeof(buf), "%dkB", BLCKSZ / 1024);
6013 case GUC_UNIT_XBLOCKS:
6014 snprintf(buf, sizeof(buf), "%dkB", XLOG_BLCKSZ / 1024);
6035 values[3] = config_group_names[conf->group];
6038 values[4] = conf->short_desc;
6041 values[5] = conf->long_desc;
6044 values[6] = GucContext_Names[conf->context];
6047 values[7] = config_type_names[conf->vartype];
6050 values[8] = GucSource_Names[conf->source];
6052 /* now get the type specifc attributes */
6053 switch (conf->vartype)
6070 struct config_int *lconf = (struct config_int *) conf;
6073 snprintf(buffer, sizeof(buffer), "%d", lconf->min);
6074 values[9] = pstrdup(buffer);
6077 snprintf(buffer, sizeof(buffer), "%d", lconf->max);
6078 values[10] = pstrdup(buffer);
6087 struct config_real *lconf = (struct config_real *) conf;
6090 snprintf(buffer, sizeof(buffer), "%g", lconf->min);
6091 values[9] = pstrdup(buffer);
6094 snprintf(buffer, sizeof(buffer), "%g", lconf->max);
6095 values[10] = pstrdup(buffer);
6124 values[11] = config_enum_get_options((struct config_enum *) conf, "", "");
6131 * should never get here, but in case we do, set 'em to NULL
6148 * Return the total number of GUC variables
6151 GetNumConfigOptions(void)
6153 return num_guc_variables;
6157 * show_config_by_name - equiv to SHOW X command but implemented as
6161 show_config_by_name(PG_FUNCTION_ARGS)
6166 /* Get the GUC variable name */
6167 varname = TextDatumGetCString(PG_GETARG_DATUM(0));
6170 varval = GetConfigOptionByName(varname, NULL);
6172 /* Convert to text */
6173 PG_RETURN_TEXT_P(cstring_to_text(varval));
6177 * show_all_settings - equiv to SHOW ALL command but implemented as
6180 #define NUM_PG_SETTINGS_ATTS 12
6183 show_all_settings(PG_FUNCTION_ARGS)
6185 FuncCallContext *funcctx;
6189 AttInMetadata *attinmeta;
6190 MemoryContext oldcontext;
6192 /* stuff done only on the first call of the function */
6193 if (SRF_IS_FIRSTCALL())
6195 /* create a function context for cross-call persistence */
6196 funcctx = SRF_FIRSTCALL_INIT();
6199 * switch to memory context appropriate for multiple function calls
6201 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
6204 * need a tuple descriptor representing NUM_PG_SETTINGS_ATTS columns
6205 * of the appropriate types
6207 tupdesc = CreateTemplateTupleDesc(NUM_PG_SETTINGS_ATTS, false);
6208 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
6210 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
6212 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "unit",
6214 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "category",
6216 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "short_desc",
6218 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "extra_desc",
6220 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "context",
6222 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "vartype",
6224 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "source",
6226 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "min_val",
6228 TupleDescInitEntry(tupdesc, (AttrNumber) 11, "max_val",
6230 TupleDescInitEntry(tupdesc, (AttrNumber) 12, "enumvals",
6234 * Generate attribute metadata needed later to produce tuples from raw
6237 attinmeta = TupleDescGetAttInMetadata(tupdesc);
6238 funcctx->attinmeta = attinmeta;
6240 /* total number of tuples to be returned */
6241 funcctx->max_calls = GetNumConfigOptions();
6243 MemoryContextSwitchTo(oldcontext);
6246 /* stuff done on every call of the function */
6247 funcctx = SRF_PERCALL_SETUP();
6249 call_cntr = funcctx->call_cntr;
6250 max_calls = funcctx->max_calls;
6251 attinmeta = funcctx->attinmeta;
6253 if (call_cntr < max_calls) /* do when there is more left to send */
6255 char *values[NUM_PG_SETTINGS_ATTS];
6261 * Get the next visible GUC variable name and value
6265 GetConfigOptionByNum(call_cntr, (const char **) values, &noshow);
6268 /* bump the counter and get the next config setting */
6269 call_cntr = ++funcctx->call_cntr;
6271 /* make sure we haven't gone too far now */
6272 if (call_cntr >= max_calls)
6273 SRF_RETURN_DONE(funcctx);
6278 tuple = BuildTupleFromCStrings(attinmeta, values);
6280 /* make the tuple into a datum */
6281 result = HeapTupleGetDatum(tuple);
6283 SRF_RETURN_NEXT(funcctx, result);
6287 /* do when there is no more left */
6288 SRF_RETURN_DONE(funcctx);
6293 _ShowOption(struct config_generic * record, bool use_units)
6298 switch (record->vartype)
6302 struct config_bool *conf = (struct config_bool *) record;
6304 if (conf->show_hook)
6305 val = (*conf->show_hook) ();
6307 val = *conf->variable ? "on" : "off";
6313 struct config_int *conf = (struct config_int *) record;
6315 if (conf->show_hook)
6316 val = (*conf->show_hook) ();
6320 * Use int64 arithmetic to avoid overflows in units
6321 * conversion. If INT64_IS_BUSTED we might overflow
6322 * anyway and print bogus answers, but there are few
6323 * enough such machines that it doesn't seem worth
6326 int64 result = *conf->variable;
6329 if (use_units && result > 0 &&
6330 (record->flags & GUC_UNIT_MEMORY))
6332 switch (record->flags & GUC_UNIT_MEMORY)
6334 case GUC_UNIT_BLOCKS:
6335 result *= BLCKSZ / 1024;
6337 case GUC_UNIT_XBLOCKS:
6338 result *= XLOG_BLCKSZ / 1024;
6342 if (result % KB_PER_GB == 0)
6344 result /= KB_PER_GB;
6347 else if (result % KB_PER_MB == 0)
6349 result /= KB_PER_MB;
6357 else if (use_units && result > 0 &&
6358 (record->flags & GUC_UNIT_TIME))
6360 switch (record->flags & GUC_UNIT_TIME)
6366 result *= MS_PER_MIN;
6370 if (result % MS_PER_D == 0)
6375 else if (result % MS_PER_H == 0)
6380 else if (result % MS_PER_MIN == 0)
6382 result /= MS_PER_MIN;
6385 else if (result % MS_PER_S == 0)
6398 snprintf(buffer, sizeof(buffer), INT64_FORMAT "%s",
6407 struct config_real *conf = (struct config_real *) record;
6409 if (conf->show_hook)
6410 val = (*conf->show_hook) ();
6413 snprintf(buffer, sizeof(buffer), "%g",
6422 struct config_string *conf = (struct config_string *) record;
6424 if (conf->show_hook)
6425 val = (*conf->show_hook) ();
6426 else if (*conf->variable && **conf->variable)
6427 val = *conf->variable;
6435 struct config_enum *conf = (struct config_enum *) record;
6438 val = (*conf->show_hook) ();
6440 val = config_enum_lookup_by_value(conf, *conf->variable);
6445 /* just to keep compiler quiet */
6450 return pstrdup(val);
6455 * Attempt (badly) to detect if a proposed new GUC setting is the same
6456 * as the current value.
6458 * XXX this does not really work because it doesn't account for the
6459 * effects of canonicalization of string values by assign_hooks.
6462 is_newvalue_equal(struct config_generic * record, const char *newvalue)
6464 /* newvalue == NULL isn't supported */
6465 Assert(newvalue != NULL);
6467 switch (record->vartype)
6471 struct config_bool *conf = (struct config_bool *) record;
6474 return parse_bool(newvalue, &newval)
6475 && *conf->variable == newval;
6479 struct config_int *conf = (struct config_int *) record;
6482 return parse_int(newvalue, &newval, record->flags, NULL)
6483 && *conf->variable == newval;
6487 struct config_real *conf = (struct config_real *) record;
6490 return parse_real(newvalue, &newval)
6491 && *conf->variable == newval;
6495 struct config_string *conf = (struct config_string *) record;
6497 return *conf->variable != NULL &&
6498 strcmp(*conf->variable, newvalue) == 0;
6503 struct config_enum *conf = (struct config_enum *) record;
6506 return config_enum_lookup_by_name(conf, newvalue, &newval)
6507 && *conf->variable == newval;
6518 * This routine dumps out all non-default GUC options into a binary
6519 * file that is read by all exec'ed backends. The format is:
6521 * variable name, string, null terminated
6522 * variable value, string, null terminated
6523 * variable source, integer
6526 write_nondefault_variables(GucContext context)
6532 Assert(context == PGC_POSTMASTER || context == PGC_SIGHUP);
6534 elevel = (context == PGC_SIGHUP) ? LOG : ERROR;
6539 fp = AllocateFile(CONFIG_EXEC_PARAMS_NEW, "w");
6543 (errcode_for_file_access(),
6544 errmsg("could not write to file \"%s\": %m",
6545 CONFIG_EXEC_PARAMS_NEW)));
6549 for (i = 0; i < num_guc_variables; i++)
6551 struct config_generic *gconf = guc_variables[i];
6553 if (gconf->source != PGC_S_DEFAULT)
6555 fprintf(fp, "%s", gconf->name);
6558 switch (gconf->vartype)
6562 struct config_bool *conf = (struct config_bool *) gconf;
6564 if (*conf->variable == 0)
6565 fprintf(fp, "false");
6567 fprintf(fp, "true");
6573 struct config_int *conf = (struct config_int *) gconf;
6575 fprintf(fp, "%d", *conf->variable);
6581 struct config_real *conf = (struct config_real *) gconf;
6583 /* Could lose precision here? */
6584 fprintf(fp, "%f", *conf->variable);
6590 struct config_string *conf = (struct config_string *) gconf;
6592 fprintf(fp, "%s", *conf->variable);
6598 struct config_enum *conf = (struct config_enum *) gconf;
6600 fprintf(fp, "%s", config_enum_lookup_by_value(conf, *conf->variable));
6607 fwrite(&gconf->source, sizeof(gconf->source), 1, fp);
6614 (errcode_for_file_access(),
6615 errmsg("could not write to file \"%s\": %m",
6616 CONFIG_EXEC_PARAMS_NEW)));
6621 * Put new file in place. This could delay on Win32, but we don't hold
6622 * any exclusive locks.
6624 rename(CONFIG_EXEC_PARAMS_NEW, CONFIG_EXEC_PARAMS);
6629 * Read string, including null byte from file
6631 * Return NULL on EOF and nothing read
6634 read_string_with_null(FILE *fp)
6643 if ((ch = fgetc(fp)) == EOF)
6648 elog(FATAL, "invalid format of exec config params file");
6651 str = guc_malloc(FATAL, maxlen);
6652 else if (i == maxlen)
6653 str = guc_realloc(FATAL, str, maxlen *= 2);
6662 * This routine loads a previous postmaster dump of its non-default
6666 read_nondefault_variables(void)
6676 fp = AllocateFile(CONFIG_EXEC_PARAMS, "r");
6679 /* File not found is fine */
6680 if (errno != ENOENT)
6682 (errcode_for_file_access(),
6683 errmsg("could not read from file \"%s\": %m",
6684 CONFIG_EXEC_PARAMS)));
6690 struct config_generic *record;
6692 if ((varname = read_string_with_null(fp)) == NULL)
6695 if ((record = find_option(varname, true, FATAL)) == NULL)
6696 elog(FATAL, "failed to locate variable %s in exec config params file", varname);
6697 if ((varvalue = read_string_with_null(fp)) == NULL)
6698 elog(FATAL, "invalid format of exec config params file");
6699 if (fread(&varsource, sizeof(varsource), 1, fp) == 0)
6700 elog(FATAL, "invalid format of exec config params file");
6702 (void) set_config_option(varname, varvalue, record->context,
6703 varsource, GUC_ACTION_SET, true);
6710 #endif /* EXEC_BACKEND */
6714 * A little "long argument" simulation, although not quite GNU
6715 * compliant. Takes a string of the form "some-option=some value" and
6716 * returns name = "some_option" and value = "some value" in malloc'ed
6717 * storage. Note that '-' is converted to '_' in the option name. If
6718 * there is no '=' in the input string then value will be NULL.
6721 ParseLongOption(const char *string, char **name, char **value)
6730 equal_pos = strcspn(string, "=");
6732 if (string[equal_pos] == '=')
6734 *name = guc_malloc(FATAL, equal_pos + 1);
6735 strlcpy(*name, string, equal_pos + 1);
6737 *value = guc_strdup(FATAL, &string[equal_pos + 1]);
6741 /* no equal sign in string */
6742 *name = guc_strdup(FATAL, string);
6746 for (cp = *name; *cp; cp++)
6753 * Handle options fetched from pg_database.datconfig, pg_authid.rolconfig,
6754 * pg_proc.proconfig, etc. Caller must specify proper context/source/action.
6756 * The array parameter must be an array of TEXT (it must not be NULL).
6759 ProcessGUCArray(ArrayType *array,
6760 GucContext context, GucSource source, GucAction action)
6764 Assert(array != NULL);
6765 Assert(ARR_ELEMTYPE(array) == TEXTOID);
6766 Assert(ARR_NDIM(array) == 1);
6767 Assert(ARR_LBOUND(array)[0] == 1);
6769 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
6777 d = array_ref(array, 1, &i,
6778 -1 /* varlenarray */ ,
6779 -1 /* TEXT's typlen */ ,
6780 false /* TEXT's typbyval */ ,
6781 'i' /* TEXT's typalign */ ,
6787 s = TextDatumGetCString(d);
6789 ParseLongOption(s, &name, &value);
6793 (errcode(ERRCODE_SYNTAX_ERROR),
6794 errmsg("could not parse setting for parameter \"%s\"",
6800 (void) set_config_option(name, value, context, source, action, true);
6810 * Add an entry to an option array. The array parameter may be NULL
6811 * to indicate the current table entry is NULL.
6814 GUCArrayAdd(ArrayType *array, const char *name, const char *value)
6816 const char *varname;
6824 /* test if the option is valid */
6825 set_config_option(name, value,
6826 superuser() ? PGC_SUSET : PGC_USERSET,
6827 PGC_S_TEST, GUC_ACTION_SET, false);
6829 /* convert name to canonical spelling, so we can use plain strcmp */
6830 (void) GetConfigOptionByName(name, &varname);
6833 newval = palloc(strlen(name) + 1 + strlen(value) + 1);
6834 sprintf(newval, "%s=%s", name, value);
6835 datum = CStringGetTextDatum(newval);
6843 Assert(ARR_ELEMTYPE(array) == TEXTOID);
6844 Assert(ARR_NDIM(array) == 1);
6845 Assert(ARR_LBOUND(array)[0] == 1);
6847 index = ARR_DIMS(array)[0] + 1; /* add after end */
6849 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
6854 d = array_ref(array, 1, &i,
6855 -1 /* varlenarray */ ,
6856 -1 /* TEXT's typlen */ ,
6857 false /* TEXT's typbyval */ ,
6858 'i' /* TEXT's typalign */ ,
6862 current = TextDatumGetCString(d);
6863 if (strncmp(current, newval, strlen(name) + 1) == 0)
6870 a = array_set(array, 1, &index,
6873 -1 /* varlena array */ ,
6874 -1 /* TEXT's typlen */ ,
6875 false /* TEXT's typbyval */ ,
6876 'i' /* TEXT's typalign */ );
6879 a = construct_array(&datum, 1,
6888 * Delete an entry from an option array. The array parameter may be NULL
6889 * to indicate the current table entry is NULL. Also, if the return value
6890 * is NULL then a null should be stored.
6893 GUCArrayDelete(ArrayType *array, const char *name)
6895 const char *varname;
6896 ArrayType *newarray;
6902 /* test if the option is valid */
6903 set_config_option(name, NULL,
6904 superuser() ? PGC_SUSET : PGC_USERSET,
6905 PGC_S_TEST, GUC_ACTION_SET, false);
6907 /* convert name to canonical spelling, so we can use plain strcmp */
6908 (void) GetConfigOptionByName(name, &varname);
6911 /* if array is currently null, then surely nothing to delete */
6918 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
6924 d = array_ref(array, 1, &i,
6925 -1 /* varlenarray */ ,
6926 -1 /* TEXT's typlen */ ,
6927 false /* TEXT's typbyval */ ,
6928 'i' /* TEXT's typalign */ ,
6932 val = TextDatumGetCString(d);
6934 /* ignore entry if it's what we want to delete */
6935 if (strncmp(val, name, strlen(name)) == 0
6936 && val[strlen(name)] == '=')
6939 /* else add it to the output array */
6942 newarray = array_set(newarray, 1, &index,
6945 -1 /* varlenarray */ ,
6946 -1 /* TEXT's typlen */ ,
6947 false /* TEXT's typbyval */ ,
6948 'i' /* TEXT's typalign */ );
6951 newarray = construct_array(&d, 1,
6963 * assign_hook and show_hook subroutines
6967 assign_log_destination(const char *value, bool doit, GucSource source)
6974 /* Need a modifiable copy of string */
6975 rawstring = pstrdup(value);
6977 /* Parse string into list of identifiers */
6978 if (!SplitIdentifierString(rawstring, ',', &elemlist))
6980 /* syntax error in list */
6982 list_free(elemlist);
6983 ereport(GUC_complaint_elevel(source),
6984 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6985 errmsg("invalid list syntax for parameter \"log_destination\"")));
6989 foreach(l, elemlist)
6991 char *tok = (char *) lfirst(l);
6993 if (pg_strcasecmp(tok, "stderr") == 0)
6994 newlogdest |= LOG_DESTINATION_STDERR;
6995 else if (pg_strcasecmp(tok, "csvlog") == 0)
6996 newlogdest |= LOG_DESTINATION_CSVLOG;
6998 else if (pg_strcasecmp(tok, "syslog") == 0)
6999 newlogdest |= LOG_DESTINATION_SYSLOG;
7002 else if (pg_strcasecmp(tok, "eventlog") == 0)
7003 newlogdest |= LOG_DESTINATION_EVENTLOG;
7007 ereport(GUC_complaint_elevel(source),
7008 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7009 errmsg("unrecognized \"log_destination\" key word: \"%s\"",
7012 list_free(elemlist);
7018 Log_destination = newlogdest;
7021 list_free(elemlist);
7029 assign_syslog_facility(int newval, bool doit, GucSource source)
7032 set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
7039 assign_syslog_ident(const char *ident, bool doit, GucSource source)
7042 set_syslog_parameters(ident, syslog_facility);
7046 #endif /* HAVE_SYSLOG */
7050 assign_session_replication_role(int newval, bool doit, GucSource source)
7053 * Must flush the plan cache when changing replication role; but don't
7054 * flush unnecessarily.
7056 if (doit && SessionReplicationRole != newval)
7065 show_num_temp_buffers(void)
7068 * We show the GUC var until local buffers have been initialized, and
7069 * NLocBuffer afterwards.
7071 static char nbuf[32];
7073 sprintf(nbuf, "%d", NLocBuffer ? NLocBuffer : num_temp_buffers);
7078 assign_phony_autocommit(bool newval, bool doit, GucSource source)
7082 ereport(GUC_complaint_elevel(source),
7083 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7084 errmsg("SET AUTOCOMMIT TO OFF is no longer supported")));
7091 assign_custom_variable_classes(const char *newval, bool doit, GucSource source)
7094 * Check syntax. newval must be a comma separated list of identifiers.
7095 * Whitespace is allowed but removed from the result.
7097 bool hasSpaceAfterToken = false;
7098 const char *cp = newval;
7103 initStringInfo(&buf);
7104 while ((c = *cp++) != '\0')
7106 if (isspace((unsigned char) c))
7109 hasSpaceAfterToken = true;
7115 if (symLen > 0) /* terminate identifier */
7117 appendStringInfoChar(&buf, ',');
7120 hasSpaceAfterToken = false;
7124 if (hasSpaceAfterToken || !isalnum((unsigned char) c))
7127 * Syntax error due to token following space after token or non
7128 * alpha numeric character
7133 appendStringInfoChar(&buf, c);
7137 /* Remove stray ',' at end */
7138 if (symLen == 0 && buf.len > 0)
7139 buf.data[--buf.len] = '\0';
7141 /* GUC wants the result malloc'd */
7142 newval = guc_strdup(LOG, buf.data);
7149 assign_debug_assertions(bool newval, bool doit, GucSource source)
7151 #ifndef USE_ASSERT_CHECKING
7154 ereport(GUC_complaint_elevel(source),
7155 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7156 errmsg("assertion checking is not supported by this build")));
7164 assign_ssl(bool newval, bool doit, GucSource source)
7169 ereport(GUC_complaint_elevel(source),
7170 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7171 errmsg("SSL is not supported by this build")));
7179 assign_stage_log_stats(bool newval, bool doit, GucSource source)
7181 if (newval && log_statement_stats)
7183 ereport(GUC_complaint_elevel(source),
7184 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7185 errmsg("cannot enable parameter when \"log_statement_stats\" is true")));
7186 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
7187 if (source != PGC_S_OVERRIDE)
7194 assign_log_stats(bool newval, bool doit, GucSource source)
7197 (log_parser_stats || log_planner_stats || log_executor_stats))
7199 ereport(GUC_complaint_elevel(source),
7200 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7201 errmsg("cannot enable \"log_statement_stats\" when "
7202 "\"log_parser_stats\", \"log_planner_stats\", "
7203 "or \"log_executor_stats\" is true")));
7204 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
7205 if (source != PGC_S_OVERRIDE)
7212 assign_transaction_read_only(bool newval, bool doit, GucSource source)
7214 /* Can't go to r/w mode inside a r/o transaction */
7215 if (newval == false && XactReadOnly && IsSubTransaction())
7217 ereport(GUC_complaint_elevel(source),
7218 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7219 errmsg("cannot set transaction read-write mode inside a read-only transaction")));
7220 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
7221 if (source != PGC_S_OVERRIDE)
7228 assign_canonical_path(const char *newval, bool doit, GucSource source)
7232 char *canon_val = guc_strdup(ERROR, newval);
7234 canonicalize_path(canon_val);
7242 assign_timezone_abbreviations(const char *newval, bool doit, GucSource source)
7245 * The powerup value shown above for timezone_abbreviations is "UNKNOWN".
7246 * When we see this we just do nothing. If this value isn't overridden
7247 * from the config file then pg_timezone_abbrev_initialize() will
7248 * eventually replace it with "Default". This hack has two purposes: to
7249 * avoid wasting cycles loading values that might soon be overridden from
7250 * the config file, and to avoid trying to read the timezone abbrev files
7251 * during InitializeGUCOptions(). The latter doesn't work in an
7252 * EXEC_BACKEND subprocess because my_exec_path hasn't been set yet and so
7253 * we can't locate PGSHAREDIR. (Essentially the same hack is used to
7254 * delay initializing TimeZone ... if we have any more, we should try to
7255 * clean up and centralize this mechanism ...)
7257 if (strcmp(newval, "UNKNOWN") == 0)
7262 /* Loading abbrev file is expensive, so only do it when value changes */
7263 if (timezone_abbreviations_string == NULL ||
7264 strcmp(timezone_abbreviations_string, newval) != 0)
7269 * If reading config file, only the postmaster should bleat loudly
7270 * about problems. Otherwise, it's just this one process doing it,
7271 * and we use WARNING message level.
7273 if (source == PGC_S_FILE)
7274 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
7277 if (!load_tzoffsets(newval, doit, elevel))
7284 * pg_timezone_abbrev_initialize --- set default value if not done already
7286 * This is called after initial loading of postgresql.conf. If no
7287 * timezone_abbreviations setting was found therein, select default.
7290 pg_timezone_abbrev_initialize(void)
7292 if (strcmp(timezone_abbreviations_string, "UNKNOWN") == 0)
7294 SetConfigOption("timezone_abbreviations", "Default",
7295 PGC_POSTMASTER, PGC_S_ARGV);
7300 show_archive_command(void)
7302 if (XLogArchiveMode)
7303 return XLogArchiveCommand;
7305 return "(disabled)";
7309 assign_tcp_keepalives_idle(int newval, bool doit, GucSource source)
7312 return (pq_setkeepalivesidle(newval, MyProcPort) == STATUS_OK);
7318 show_tcp_keepalives_idle(void)
7320 static char nbuf[16];
7322 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesidle(MyProcPort));
7327 assign_tcp_keepalives_interval(int newval, bool doit, GucSource source)
7330 return (pq_setkeepalivesinterval(newval, MyProcPort) == STATUS_OK);
7336 show_tcp_keepalives_interval(void)
7338 static char nbuf[16];
7340 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesinterval(MyProcPort));
7345 assign_tcp_keepalives_count(int newval, bool doit, GucSource source)
7348 return (pq_setkeepalivescount(newval, MyProcPort) == STATUS_OK);
7354 show_tcp_keepalives_count(void)
7356 static char nbuf[16];
7358 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivescount(MyProcPort));
7363 assign_maxconnections(int newval, bool doit, GucSource source)
7365 if (newval + autovacuum_max_workers > INT_MAX / 4)
7369 MaxBackends = newval + autovacuum_max_workers;
7375 assign_autovacuum_max_workers(int newval, bool doit, GucSource source)
7377 if (newval + MaxConnections > INT_MAX / 4)
7381 MaxBackends = newval + MaxConnections;
7387 assign_pgstat_temp_directory(const char *newval, bool doit, GucSource source)
7391 if (pgstat_stat_tmpname)
7392 free(pgstat_stat_tmpname);
7393 if (pgstat_stat_filename)
7394 free(pgstat_stat_filename);
7396 pgstat_stat_tmpname = guc_malloc(FATAL, strlen(newval) + 12); /* /pgstat.tmp */
7397 pgstat_stat_filename = guc_malloc(FATAL, strlen(newval) + 13); /* /pgstat.stat */
7399 sprintf(pgstat_stat_tmpname, "%s/pgstat.tmp", newval);
7400 sprintf(pgstat_stat_filename, "%s/pgstat.stat", newval);
7406 #include "guc-file.c"