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.483 2008/12/13 19:13:44 tgl 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 "tcop/tcopprot.h"
61 #include "tsearch/ts_cache.h"
62 #include "utils/builtins.h"
63 #include "utils/guc_tables.h"
64 #include "utils/memutils.h"
65 #include "utils/pg_locale.h"
66 #include "utils/plancache.h"
67 #include "utils/portal.h"
68 #include "utils/ps_status.h"
69 #include "utils/tzparser.h"
70 #include "utils/xml.h"
73 #define PG_KRB_SRVTAB ""
76 #define PG_KRB_SRVNAM ""
79 #define CONFIG_FILENAME "postgresql.conf"
80 #define HBA_FILENAME "pg_hba.conf"
81 #define IDENT_FILENAME "pg_ident.conf"
84 #define CONFIG_EXEC_PARAMS "global/config_exec_params"
85 #define CONFIG_EXEC_PARAMS_NEW "global/config_exec_params.new"
88 /* upper limit for GUC variables measured in kilobytes of memory */
90 #define MAX_KILOBYTES INT_MAX
92 #define MAX_KILOBYTES (INT_MAX / 1024)
95 #define KB_PER_MB (1024)
96 #define KB_PER_GB (1024*1024)
100 #define MS_PER_MIN (1000 * 60)
102 #define S_PER_H (60 * 60)
103 #define MS_PER_H (1000 * 60 * 60)
104 #define MIN_PER_D (60 * 24)
105 #define S_PER_D (60 * 60 * 24)
106 #define MS_PER_D (1000 * 60 * 60 * 24)
108 /* XXX these should appear in other modules' header files */
109 extern bool Log_disconnections;
110 extern int CommitDelay;
111 extern int CommitSiblings;
112 extern char *default_tablespace;
113 extern char *temp_tablespaces;
114 extern bool synchronize_seqscans;
115 extern bool fullPageWrites;
118 extern bool trace_sort;
120 #ifdef TRACE_SYNCSCAN
121 extern bool trace_syncscan;
123 #ifdef DEBUG_BOUNDED_SORT
124 extern bool optimize_bounded_sort;
128 extern char *SSLCipherSuites;
131 static void set_config_sourcefile(const char *name, char *sourcefile,
134 static const char *assign_log_destination(const char *value,
135 bool doit, GucSource source);
138 static int syslog_facility = LOG_LOCAL0;
140 static bool assign_syslog_facility(int newval,
141 bool doit, GucSource source);
142 static const char *assign_syslog_ident(const char *ident,
143 bool doit, GucSource source);
146 static bool assign_session_replication_role(int newval, bool doit,
148 static const char *show_num_temp_buffers(void);
149 static bool assign_phony_autocommit(bool newval, bool doit, GucSource source);
150 static const char *assign_custom_variable_classes(const char *newval, bool doit,
152 static bool assign_debug_assertions(bool newval, bool doit, GucSource source);
153 static bool assign_ssl(bool newval, bool doit, GucSource source);
154 static bool assign_stage_log_stats(bool newval, bool doit, GucSource source);
155 static bool assign_log_stats(bool newval, bool doit, GucSource source);
156 static bool assign_transaction_read_only(bool newval, bool doit, GucSource source);
157 static const char *assign_canonical_path(const char *newval, bool doit, GucSource source);
158 static const char *assign_timezone_abbreviations(const char *newval, bool doit, GucSource source);
159 static const char *show_archive_command(void);
160 static bool assign_tcp_keepalives_idle(int newval, bool doit, GucSource source);
161 static bool assign_tcp_keepalives_interval(int newval, bool doit, GucSource source);
162 static bool assign_tcp_keepalives_count(int newval, bool doit, GucSource source);
163 static const char *show_tcp_keepalives_idle(void);
164 static const char *show_tcp_keepalives_interval(void);
165 static const char *show_tcp_keepalives_count(void);
166 static bool assign_autovacuum_max_workers(int newval, bool doit, GucSource source);
167 static bool assign_maxconnections(int newval, bool doit, GucSource source);
168 static const char *assign_pgstat_temp_directory(const char *newval, bool doit, GucSource source);
170 static char *config_enum_get_options(struct config_enum *record,
171 const char *prefix, const char *suffix,
172 const char *separator);
176 * Options for enum values defined in this module.
178 * NOTE! Option values may not contain double quotes!
182 * We have different sets for client and server message level options because
183 * they sort slightly different (see "log" level)
185 static const struct config_enum_entry client_message_level_options[] = {
186 {"debug", DEBUG2, true},
187 {"debug5", DEBUG5, false},
188 {"debug4", DEBUG4, false},
189 {"debug3", DEBUG3, false},
190 {"debug2", DEBUG2, false},
191 {"debug1", DEBUG1, false},
193 {"info", INFO, true},
194 {"notice", NOTICE, false},
195 {"warning", WARNING, false},
196 {"error", ERROR, false},
197 {"fatal", FATAL, true},
198 {"panic", PANIC, true},
202 static const struct config_enum_entry server_message_level_options[] = {
203 {"debug", DEBUG2, true},
204 {"debug5", DEBUG5, false},
205 {"debug4", DEBUG4, false},
206 {"debug3", DEBUG3, false},
207 {"debug2", DEBUG2, false},
208 {"debug1", DEBUG1, false},
209 {"info", INFO, false},
210 {"notice", NOTICE, false},
211 {"warning", WARNING, false},
212 {"error", ERROR, false},
214 {"fatal", FATAL, false},
215 {"panic", PANIC, false},
219 static const struct config_enum_entry intervalstyle_options[] = {
220 {"postgres", INTSTYLE_POSTGRES, false},
221 {"postgres_verbose", INTSTYLE_POSTGRES_VERBOSE, false},
222 {"sql_standard", INTSTYLE_SQL_STANDARD, false},
223 {"iso_8601", INTSTYLE_ISO_8601, false},
227 static const struct config_enum_entry log_error_verbosity_options[] = {
228 {"terse", PGERROR_TERSE, false},
229 {"default", PGERROR_DEFAULT, false},
230 {"verbose", PGERROR_VERBOSE, false},
234 static const struct config_enum_entry log_statement_options[] = {
235 {"none", LOGSTMT_NONE, false},
236 {"ddl", LOGSTMT_DDL, false},
237 {"mod", LOGSTMT_MOD, false},
238 {"all", LOGSTMT_ALL, false},
242 static const struct config_enum_entry regex_flavor_options[] = {
243 {"advanced", REG_ADVANCED, false},
244 {"extended", REG_EXTENDED, false},
245 {"basic", REG_BASIC, false},
249 static const struct config_enum_entry isolation_level_options[] = {
250 {"serializable", XACT_SERIALIZABLE, false},
251 {"repeatable read", XACT_REPEATABLE_READ, false},
252 {"read committed", XACT_READ_COMMITTED, false},
253 {"read uncommitted", XACT_READ_UNCOMMITTED, false},
257 static const struct config_enum_entry session_replication_role_options[] = {
258 {"origin", SESSION_REPLICATION_ROLE_ORIGIN, false},
259 {"replica", SESSION_REPLICATION_ROLE_REPLICA, false},
260 {"local", SESSION_REPLICATION_ROLE_LOCAL, false},
265 static const struct config_enum_entry syslog_facility_options[] = {
266 {"local0", LOG_LOCAL0, false},
267 {"local1", LOG_LOCAL1, false},
268 {"local2", LOG_LOCAL2, false},
269 {"local3", LOG_LOCAL3, false},
270 {"local4", LOG_LOCAL4, false},
271 {"local5", LOG_LOCAL5, false},
272 {"local6", LOG_LOCAL6, false},
273 {"local7", LOG_LOCAL7, false},
278 static const struct config_enum_entry track_function_options[] = {
279 {"none", TRACK_FUNC_OFF, false},
280 {"pl", TRACK_FUNC_PL, false},
281 {"all", TRACK_FUNC_ALL, false},
285 static const struct config_enum_entry xmlbinary_options[] = {
286 {"base64", XMLBINARY_BASE64, false},
287 {"hex", XMLBINARY_HEX, false},
291 static const struct config_enum_entry xmloption_options[] = {
292 {"content", XMLOPTION_CONTENT, false},
293 {"document", XMLOPTION_DOCUMENT, false},
298 * Although only "on", "off", and "safe_encoding" are documented, we
299 * accept all the likely variants of "on" and "off".
301 static const struct config_enum_entry backslash_quote_options[] = {
302 {"safe_encoding", BACKSLASH_QUOTE_SAFE_ENCODING, false},
303 {"on", BACKSLASH_QUOTE_ON, false},
304 {"off", BACKSLASH_QUOTE_OFF, false},
305 {"true", BACKSLASH_QUOTE_ON, true},
306 {"false", BACKSLASH_QUOTE_OFF, true},
307 {"yes", BACKSLASH_QUOTE_ON, true},
308 {"no", BACKSLASH_QUOTE_OFF, true},
309 {"1", BACKSLASH_QUOTE_ON, true},
310 {"0", BACKSLASH_QUOTE_OFF, true},
315 * Options for enum values stored in other modules
317 extern const struct config_enum_entry sync_method_options[];
320 * GUC option variables that are exported from this module
322 #ifdef USE_ASSERT_CHECKING
323 bool assert_enabled = true;
325 bool assert_enabled = false;
327 bool log_duration = false;
328 bool Debug_print_plan = false;
329 bool Debug_print_parse = false;
330 bool Debug_print_rewritten = false;
331 bool Debug_pretty_print = true;
333 bool log_parser_stats = false;
334 bool log_planner_stats = false;
335 bool log_executor_stats = false;
336 bool log_statement_stats = false; /* this is sort of all three
338 bool log_btree_build_stats = false;
340 bool check_function_bodies = true;
341 bool default_with_oids = false;
342 bool SQL_inheritance = true;
344 bool Password_encryption = true;
346 int log_min_error_statement = ERROR;
347 int log_min_messages = WARNING;
348 int client_min_messages = NOTICE;
349 int log_min_duration_statement = -1;
350 int log_temp_files = -1;
352 int num_temp_buffers = 1000;
354 char *ConfigFileName;
357 char *external_pid_file;
359 char *pgstat_temp_directory;
361 int tcp_keepalives_idle;
362 int tcp_keepalives_interval;
363 int tcp_keepalives_count;
366 * These variables are all dummies that don't do anything, except in some
367 * cases provide the value for SHOW to display. The real state is elsewhere
368 * and is kept in sync by assign_hooks.
370 static char *log_destination_string;
373 static char *syslog_ident_str;
375 static bool phony_autocommit;
376 static bool session_auth_is_superuser;
377 static double phony_random_seed;
378 static char *client_encoding_string;
379 static char *datestyle_string;
380 static char *locale_collate;
381 static char *locale_ctype;
382 static char *server_encoding_string;
383 static char *server_version_string;
384 static int server_version_num;
385 static char *timezone_string;
386 static char *log_timezone_string;
387 static char *timezone_abbreviations_string;
388 static char *XactIsoLevel_string;
389 static char *data_directory;
390 static char *custom_variable_classes;
391 static int max_function_args;
392 static int max_index_keys;
393 static int max_identifier_length;
394 static int block_size;
395 static int segment_size;
396 static int wal_block_size;
397 static int wal_segment_size;
398 static bool integer_datetimes;
400 /* should be static, but commands/variable.c needs to get at these */
402 char *session_authorization_string;
406 * Displayable names for context types (enum GucContext)
408 * Note: these strings are deliberately not localized.
410 const char *const GucContext_Names[] =
412 /* PGC_INTERNAL */ "internal",
413 /* PGC_POSTMASTER */ "postmaster",
414 /* PGC_SIGHUP */ "sighup",
415 /* PGC_BACKEND */ "backend",
416 /* PGC_SUSET */ "superuser",
417 /* PGC_USERSET */ "user"
421 * Displayable names for source types (enum GucSource)
423 * Note: these strings are deliberately not localized.
425 const char *const GucSource_Names[] =
427 /* PGC_S_DEFAULT */ "default",
428 /* PGC_S_ENV_VAR */ "environment variable",
429 /* PGC_S_FILE */ "configuration file",
430 /* PGC_S_ARGV */ "command line",
431 /* PGC_S_DATABASE */ "database",
432 /* PGC_S_USER */ "user",
433 /* PGC_S_CLIENT */ "client",
434 /* PGC_S_OVERRIDE */ "override",
435 /* PGC_S_INTERACTIVE */ "interactive",
436 /* PGC_S_TEST */ "test",
437 /* PGC_S_SESSION */ "session"
441 * Displayable names for the groupings defined in enum config_group
443 const char *const config_group_names[] =
446 gettext_noop("Ungrouped"),
448 gettext_noop("File Locations"),
450 gettext_noop("Connections and Authentication"),
451 /* CONN_AUTH_SETTINGS */
452 gettext_noop("Connections and Authentication / Connection Settings"),
453 /* CONN_AUTH_SECURITY */
454 gettext_noop("Connections and Authentication / Security and Authentication"),
456 gettext_noop("Resource Usage"),
458 gettext_noop("Resource Usage / Memory"),
459 /* RESOURCES_KERNEL */
460 gettext_noop("Resource Usage / Kernel Resources"),
462 gettext_noop("Write-Ahead Log"),
464 gettext_noop("Write-Ahead Log / Settings"),
465 /* WAL_CHECKPOINTS */
466 gettext_noop("Write-Ahead Log / Checkpoints"),
468 gettext_noop("Query Tuning"),
469 /* QUERY_TUNING_METHOD */
470 gettext_noop("Query Tuning / Planner Method Configuration"),
471 /* QUERY_TUNING_COST */
472 gettext_noop("Query Tuning / Planner Cost Constants"),
473 /* QUERY_TUNING_GEQO */
474 gettext_noop("Query Tuning / Genetic Query Optimizer"),
475 /* QUERY_TUNING_OTHER */
476 gettext_noop("Query Tuning / Other Planner Options"),
478 gettext_noop("Reporting and Logging"),
480 gettext_noop("Reporting and Logging / Where to Log"),
482 gettext_noop("Reporting and Logging / When to Log"),
484 gettext_noop("Reporting and Logging / What to Log"),
486 gettext_noop("Statistics"),
487 /* STATS_MONITORING */
488 gettext_noop("Statistics / Monitoring"),
489 /* STATS_COLLECTOR */
490 gettext_noop("Statistics / Query and Index Statistics Collector"),
492 gettext_noop("Autovacuum"),
494 gettext_noop("Client Connection Defaults"),
495 /* CLIENT_CONN_STATEMENT */
496 gettext_noop("Client Connection Defaults / Statement Behavior"),
497 /* CLIENT_CONN_LOCALE */
498 gettext_noop("Client Connection Defaults / Locale and Formatting"),
499 /* CLIENT_CONN_OTHER */
500 gettext_noop("Client Connection Defaults / Other Defaults"),
501 /* LOCK_MANAGEMENT */
502 gettext_noop("Lock Management"),
504 gettext_noop("Version and Platform Compatibility"),
505 /* COMPAT_OPTIONS_PREVIOUS */
506 gettext_noop("Version and Platform Compatibility / Previous PostgreSQL Versions"),
507 /* COMPAT_OPTIONS_CLIENT */
508 gettext_noop("Version and Platform Compatibility / Other Platforms and Clients"),
510 gettext_noop("Preset Options"),
512 gettext_noop("Customized Options"),
513 /* DEVELOPER_OPTIONS */
514 gettext_noop("Developer Options"),
515 /* help_config wants this array to be null-terminated */
520 * Displayable names for GUC variable types (enum config_type)
522 * Note: these strings are deliberately not localized.
524 const char *const config_type_names[] =
526 /* PGC_BOOL */ "bool",
527 /* PGC_INT */ "integer",
528 /* PGC_REAL */ "real",
529 /* PGC_STRING */ "string",
530 /* PGC_ENUM */ "enum"
535 * Contents of GUC tables
537 * See src/backend/utils/misc/README for design notes.
541 * 1. Declare a global variable of type bool, int, double, or char*
542 * and make use of it.
544 * 2. Decide at what times it's safe to set the option. See guc.h for
547 * 3. Decide on a name, a default value, upper and lower bounds (if
550 * 4. Add a record below.
552 * 5. Add it to src/backend/utils/misc/postgresql.conf.sample, if
555 * 6. Don't forget to document the option (at least in config.sgml).
557 * 7. If it's a new GUC_LIST option you must edit pg_dumpall.c to ensure
558 * it is not single quoted at dump time.
562 /******** option records follow ********/
564 static struct config_bool ConfigureNamesBool[] =
567 {"enable_seqscan", PGC_USERSET, QUERY_TUNING_METHOD,
568 gettext_noop("Enables the planner's use of sequential-scan plans."),
575 {"enable_indexscan", PGC_USERSET, QUERY_TUNING_METHOD,
576 gettext_noop("Enables the planner's use of index-scan plans."),
583 {"enable_bitmapscan", PGC_USERSET, QUERY_TUNING_METHOD,
584 gettext_noop("Enables the planner's use of bitmap-scan plans."),
591 {"enable_tidscan", PGC_USERSET, QUERY_TUNING_METHOD,
592 gettext_noop("Enables the planner's use of TID scan plans."),
599 {"enable_sort", PGC_USERSET, QUERY_TUNING_METHOD,
600 gettext_noop("Enables the planner's use of explicit sort steps."),
607 {"enable_hashagg", PGC_USERSET, QUERY_TUNING_METHOD,
608 gettext_noop("Enables the planner's use of hashed aggregation plans."),
615 {"enable_nestloop", PGC_USERSET, QUERY_TUNING_METHOD,
616 gettext_noop("Enables the planner's use of nested-loop join plans."),
623 {"enable_mergejoin", PGC_USERSET, QUERY_TUNING_METHOD,
624 gettext_noop("Enables the planner's use of merge join plans."),
631 {"enable_hashjoin", PGC_USERSET, QUERY_TUNING_METHOD,
632 gettext_noop("Enables the planner's use of hash join plans."),
639 {"constraint_exclusion", PGC_USERSET, QUERY_TUNING_OTHER,
640 gettext_noop("Enables the planner to use constraints to optimize queries."),
641 gettext_noop("Child table scans will be skipped if their "
642 "constraints guarantee that no rows match the query.")
644 &constraint_exclusion,
648 {"geqo", PGC_USERSET, QUERY_TUNING_GEQO,
649 gettext_noop("Enables genetic query optimization."),
650 gettext_noop("This algorithm attempts to do planning without "
651 "exhaustive searching.")
657 /* Not for general use --- used by SET SESSION AUTHORIZATION */
658 {"is_superuser", PGC_INTERNAL, UNGROUPED,
659 gettext_noop("Shows whether the current user is a superuser."),
661 GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
663 &session_auth_is_superuser,
667 {"ssl", PGC_POSTMASTER, CONN_AUTH_SECURITY,
668 gettext_noop("Enables SSL connections."),
672 false, assign_ssl, NULL
675 {"fsync", PGC_SIGHUP, WAL_SETTINGS,
676 gettext_noop("Forces synchronization of updates to disk."),
677 gettext_noop("The server will use the fsync() system call in several places to make "
678 "sure that updates are physically written to disk. This insures "
679 "that a database cluster will recover to a consistent state after "
680 "an operating system or hardware crash.")
686 {"synchronous_commit", PGC_USERSET, WAL_SETTINGS,
687 gettext_noop("Sets immediate fsync at commit."),
694 {"zero_damaged_pages", PGC_SUSET, DEVELOPER_OPTIONS,
695 gettext_noop("Continues processing past damaged page headers."),
696 gettext_noop("Detection of a damaged page header normally causes PostgreSQL to "
697 "report an error, aborting the current transaction. Setting "
698 "zero_damaged_pages to true causes the system to instead report a "
699 "warning, zero out the damaged page, and continue processing. This "
700 "behavior will destroy data, namely all the rows on the damaged page."),
707 {"full_page_writes", PGC_SIGHUP, WAL_SETTINGS,
708 gettext_noop("Writes full pages to WAL when first modified after a checkpoint."),
709 gettext_noop("A page write in process during an operating system crash might be "
710 "only partially written to disk. During recovery, the row changes "
711 "stored in WAL are not enough to recover. This option writes "
712 "pages when first modified after a checkpoint to WAL so full recovery "
719 {"silent_mode", PGC_POSTMASTER, LOGGING_WHEN,
720 gettext_noop("Runs the server silently."),
721 gettext_noop("If this parameter is set, the server will automatically run in the "
722 "background and any controlling terminals are dissociated.")
728 {"log_checkpoints", PGC_SIGHUP, LOGGING_WHAT,
729 gettext_noop("Logs each checkpoint."),
736 {"log_connections", PGC_BACKEND, LOGGING_WHAT,
737 gettext_noop("Logs each successful connection."),
744 {"log_disconnections", PGC_BACKEND, LOGGING_WHAT,
745 gettext_noop("Logs end of a session, including duration."),
752 {"debug_assertions", PGC_USERSET, DEVELOPER_OPTIONS,
753 gettext_noop("Turns on various assertion checks."),
754 gettext_noop("This is a debugging aid."),
758 #ifdef USE_ASSERT_CHECKING
763 assign_debug_assertions, NULL
766 /* currently undocumented, so don't show in SHOW ALL */
767 {"exit_on_error", PGC_USERSET, UNGROUPED,
768 gettext_noop("No description available."),
770 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
776 {"log_duration", PGC_SUSET, LOGGING_WHAT,
777 gettext_noop("Logs the duration of each completed SQL statement."),
784 {"debug_print_parse", PGC_USERSET, LOGGING_WHAT,
785 gettext_noop("Logs each query's parse tree."),
792 {"debug_print_rewritten", PGC_USERSET, LOGGING_WHAT,
793 gettext_noop("Logs each query's rewritten parse tree."),
796 &Debug_print_rewritten,
800 {"debug_print_plan", PGC_USERSET, LOGGING_WHAT,
801 gettext_noop("Logs each query's execution plan."),
808 {"debug_pretty_print", PGC_USERSET, LOGGING_WHAT,
809 gettext_noop("Indents parse and plan tree displays."),
816 {"log_parser_stats", PGC_SUSET, STATS_MONITORING,
817 gettext_noop("Writes parser performance statistics to the server log."),
821 false, assign_stage_log_stats, NULL
824 {"log_planner_stats", PGC_SUSET, STATS_MONITORING,
825 gettext_noop("Writes planner performance statistics to the server log."),
829 false, assign_stage_log_stats, NULL
832 {"log_executor_stats", PGC_SUSET, STATS_MONITORING,
833 gettext_noop("Writes executor performance statistics to the server log."),
837 false, assign_stage_log_stats, NULL
840 {"log_statement_stats", PGC_SUSET, STATS_MONITORING,
841 gettext_noop("Writes cumulative performance statistics to the server log."),
844 &log_statement_stats,
845 false, assign_log_stats, NULL
847 #ifdef BTREE_BUILD_STATS
849 {"log_btree_build_stats", PGC_SUSET, DEVELOPER_OPTIONS,
850 gettext_noop("No description available."),
854 &log_btree_build_stats,
860 {"track_activities", PGC_SUSET, STATS_COLLECTOR,
861 gettext_noop("Collects information about executing commands."),
862 gettext_noop("Enables the collection of information on the currently "
863 "executing command of each session, along with "
864 "the time at which that command began execution.")
866 &pgstat_track_activities,
870 {"track_counts", PGC_SUSET, STATS_COLLECTOR,
871 gettext_noop("Collects statistics on database activity."),
874 &pgstat_track_counts,
879 {"update_process_title", PGC_SUSET, STATS_COLLECTOR,
880 gettext_noop("Updates the process title to show the active SQL command."),
881 gettext_noop("Enables updating of the process title every time a new SQL command is received by the server.")
883 &update_process_title,
888 {"autovacuum", PGC_SIGHUP, AUTOVACUUM,
889 gettext_noop("Starts the autovacuum subprocess."),
892 &autovacuum_start_daemon,
897 {"trace_notify", PGC_USERSET, DEVELOPER_OPTIONS,
898 gettext_noop("Generates debugging output for LISTEN and NOTIFY."),
908 {"trace_locks", PGC_SUSET, DEVELOPER_OPTIONS,
909 gettext_noop("No description available."),
917 {"trace_userlocks", PGC_SUSET, DEVELOPER_OPTIONS,
918 gettext_noop("No description available."),
926 {"trace_lwlocks", PGC_SUSET, DEVELOPER_OPTIONS,
927 gettext_noop("No description available."),
935 {"debug_deadlocks", PGC_SUSET, DEVELOPER_OPTIONS,
936 gettext_noop("No description available."),
946 {"log_lock_waits", PGC_SUSET, LOGGING_WHAT,
947 gettext_noop("Logs long lock waits."),
955 {"log_hostname", PGC_SIGHUP, LOGGING_WHAT,
956 gettext_noop("Logs the host name in the connection logs."),
957 gettext_noop("By default, connection logs only show the IP address "
958 "of the connecting host. If you want them to show the host name you "
959 "can turn this on, but depending on your host name resolution "
960 "setup it might impose a non-negligible performance penalty.")
966 {"sql_inheritance", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
967 gettext_noop("Causes subtables to be included by default in various commands."),
974 {"password_encryption", PGC_USERSET, CONN_AUTH_SECURITY,
975 gettext_noop("Encrypt passwords."),
976 gettext_noop("When a password is specified in CREATE USER or "
977 "ALTER USER without writing either ENCRYPTED or UNENCRYPTED, "
978 "this parameter determines whether the password is to be encrypted.")
980 &Password_encryption,
984 {"transform_null_equals", PGC_USERSET, COMPAT_OPTIONS_CLIENT,
985 gettext_noop("Treats \"expr=NULL\" as \"expr IS NULL\"."),
986 gettext_noop("When turned on, expressions of the form expr = NULL "
987 "(or NULL = expr) are treated as expr IS NULL, that is, they "
988 "return true if expr evaluates to the null value, and false "
989 "otherwise. The correct behavior of expr = NULL is to always "
990 "return null (unknown).")
992 &Transform_null_equals,
996 {"db_user_namespace", PGC_SIGHUP, CONN_AUTH_SECURITY,
997 gettext_noop("Enables per-database user names."),
1004 /* only here for backwards compatibility */
1005 {"autocommit", PGC_USERSET, CLIENT_CONN_STATEMENT,
1006 gettext_noop("This parameter doesn't do anything."),
1007 gettext_noop("It's just here so that we won't choke on SET AUTOCOMMIT TO ON from 7.3-vintage clients."),
1008 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
1011 true, assign_phony_autocommit, NULL
1014 {"default_transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
1015 gettext_noop("Sets the default read-only status of new transactions."),
1018 &DefaultXactReadOnly,
1022 {"transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
1023 gettext_noop("Sets the current transaction's read-only status."),
1025 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1028 false, assign_transaction_read_only, NULL
1031 {"add_missing_from", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1032 gettext_noop("Automatically adds missing table references to FROM clauses."),
1039 {"check_function_bodies", PGC_USERSET, CLIENT_CONN_STATEMENT,
1040 gettext_noop("Check function bodies during CREATE FUNCTION."),
1043 &check_function_bodies,
1047 {"array_nulls", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1048 gettext_noop("Enable input of NULL elements in arrays."),
1049 gettext_noop("When turned on, unquoted NULL in an array input "
1050 "value means a null value; "
1051 "otherwise it is taken literally.")
1057 {"default_with_oids", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1058 gettext_noop("Create new tables with OIDs by default."),
1065 {"logging_collector", PGC_POSTMASTER, LOGGING_WHERE,
1066 gettext_noop("Start a subprocess to capture stderr output and/or csvlogs into log files."),
1073 {"log_truncate_on_rotation", PGC_SIGHUP, LOGGING_WHERE,
1074 gettext_noop("Truncate existing log files of same name during log rotation."),
1077 &Log_truncate_on_rotation,
1083 {"trace_sort", PGC_USERSET, DEVELOPER_OPTIONS,
1084 gettext_noop("Emit information about resource usage in sorting."),
1093 #ifdef TRACE_SYNCSCAN
1094 /* this is undocumented because not exposed in a standard build */
1096 {"trace_syncscan", PGC_USERSET, DEVELOPER_OPTIONS,
1097 gettext_noop("Generate debugging output for synchronized scanning."),
1106 #ifdef DEBUG_BOUNDED_SORT
1107 /* this is undocumented because not exposed in a standard build */
1110 "optimize_bounded_sort", PGC_USERSET, QUERY_TUNING_METHOD,
1111 gettext_noop("Enable bounded sorting using heap sort."),
1115 &optimize_bounded_sort,
1122 {"wal_debug", PGC_SUSET, DEVELOPER_OPTIONS,
1123 gettext_noop("Emit WAL-related debugging output."),
1133 {"integer_datetimes", PGC_INTERNAL, PRESET_OPTIONS,
1134 gettext_noop("Datetimes are integer based."),
1136 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1139 #ifdef HAVE_INT64_TIMESTAMP
1147 {"krb_caseins_users", PGC_POSTMASTER, CONN_AUTH_SECURITY,
1148 gettext_noop("Sets whether Kerberos and GSSAPI user names should be treated as case-insensitive."),
1151 &pg_krb_caseins_users,
1156 {"escape_string_warning", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1157 gettext_noop("Warn about backslash escapes in ordinary string literals."),
1160 &escape_string_warning,
1165 {"standard_conforming_strings", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1166 gettext_noop("Causes '...' strings to treat backslashes literally."),
1170 &standard_conforming_strings,
1175 {"synchronize_seqscans", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1176 gettext_noop("Enable synchronized sequential scans."),
1179 &synchronize_seqscans,
1184 {"archive_mode", PGC_POSTMASTER, WAL_SETTINGS,
1185 gettext_noop("Allows archiving of WAL files using archive_command."),
1193 {"allow_system_table_mods", PGC_POSTMASTER, DEVELOPER_OPTIONS,
1194 gettext_noop("Allows modifications of the structure of system tables."),
1198 &allowSystemTableMods,
1203 {"ignore_system_indexes", PGC_BACKEND, DEVELOPER_OPTIONS,
1204 gettext_noop("Disables reading from system indexes."),
1205 gettext_noop("It does not prevent updating the indexes, so it is safe "
1206 "to use. The worst consequence is slowness."),
1209 &IgnoreSystemIndexes,
1213 /* End-of-list marker */
1215 {NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL
1220 static struct config_int ConfigureNamesInt[] =
1223 {"archive_timeout", PGC_SIGHUP, WAL_SETTINGS,
1224 gettext_noop("Forces a switch to the next xlog file if a "
1225 "new file has not been started within N seconds."),
1229 &XLogArchiveTimeout,
1230 0, 0, INT_MAX, NULL, NULL
1233 {"post_auth_delay", PGC_BACKEND, DEVELOPER_OPTIONS,
1234 gettext_noop("Waits N seconds on connection startup after authentication."),
1235 gettext_noop("This allows attaching a debugger to the process."),
1236 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1239 0, 0, INT_MAX, NULL, NULL
1242 {"default_statistics_target", PGC_USERSET, QUERY_TUNING_OTHER,
1243 gettext_noop("Sets the default statistics target."),
1244 gettext_noop("This applies to table columns that have not had a "
1245 "column-specific target set via ALTER TABLE SET STATISTICS.")
1247 &default_statistics_target,
1248 100, 1, 10000, NULL, NULL
1251 {"from_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1252 gettext_noop("Sets the FROM-list size beyond which subqueries "
1253 "are not collapsed."),
1254 gettext_noop("The planner will merge subqueries into upper "
1255 "queries if the resulting FROM list would have no more than "
1258 &from_collapse_limit,
1259 8, 1, INT_MAX, NULL, NULL
1262 {"join_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1263 gettext_noop("Sets the FROM-list size beyond which JOIN "
1264 "constructs are not flattened."),
1265 gettext_noop("The planner will flatten explicit JOIN "
1266 "constructs into lists of FROM items whenever a "
1267 "list of no more than this many items would result.")
1269 &join_collapse_limit,
1270 8, 1, INT_MAX, NULL, NULL
1273 {"geqo_threshold", PGC_USERSET, QUERY_TUNING_GEQO,
1274 gettext_noop("Sets the threshold of FROM items beyond which GEQO is used."),
1278 12, 2, INT_MAX, NULL, NULL
1281 {"geqo_effort", PGC_USERSET, QUERY_TUNING_GEQO,
1282 gettext_noop("GEQO: effort is used to set the default for other GEQO parameters."),
1286 DEFAULT_GEQO_EFFORT, MIN_GEQO_EFFORT, MAX_GEQO_EFFORT, NULL, NULL
1289 {"geqo_pool_size", PGC_USERSET, QUERY_TUNING_GEQO,
1290 gettext_noop("GEQO: number of individuals in the population."),
1291 gettext_noop("Zero selects a suitable default value.")
1294 0, 0, INT_MAX, NULL, NULL
1297 {"geqo_generations", PGC_USERSET, QUERY_TUNING_GEQO,
1298 gettext_noop("GEQO: number of iterations of the algorithm."),
1299 gettext_noop("Zero selects a suitable default value.")
1302 0, 0, INT_MAX, NULL, NULL
1306 /* This is PGC_SIGHUP so all backends have the same value. */
1307 {"deadlock_timeout", PGC_SIGHUP, LOCK_MANAGEMENT,
1308 gettext_noop("Sets the time to wait on a lock before checking for deadlock."),
1313 1000, 1, INT_MAX / 1000, NULL, NULL
1317 * Note: MaxBackends is limited to INT_MAX/4 because some places compute
1318 * 4*MaxBackends without any overflow check. This check is made in
1319 * assign_maxconnections, since MaxBackends is computed as MaxConnections
1320 * plus autovacuum_max_workers.
1322 * Likewise we have to limit NBuffers to INT_MAX/2.
1325 {"max_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1326 gettext_noop("Sets the maximum number of concurrent connections."),
1330 100, 1, INT_MAX / 4, assign_maxconnections, NULL
1334 {"superuser_reserved_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1335 gettext_noop("Sets the number of connection slots reserved for superusers."),
1339 3, 0, INT_MAX / 4, NULL, NULL
1343 {"shared_buffers", PGC_POSTMASTER, RESOURCES_MEM,
1344 gettext_noop("Sets the number of shared memory buffers used by the server."),
1349 1024, 16, INT_MAX / 2, NULL, NULL
1353 {"temp_buffers", PGC_USERSET, RESOURCES_MEM,
1354 gettext_noop("Sets the maximum number of temporary buffers used by each session."),
1359 1024, 100, INT_MAX / 2, NULL, show_num_temp_buffers
1363 {"port", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1364 gettext_noop("Sets the TCP port the server listens on."),
1368 DEF_PGPORT, 1, 65535, NULL, NULL
1372 {"unix_socket_permissions", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1373 gettext_noop("Sets the access permissions of the Unix-domain socket."),
1374 gettext_noop("Unix-domain sockets use the usual Unix file system "
1375 "permission set. The parameter value is expected to be a numeric mode "
1376 "specification in the form accepted by the chmod and umask system "
1377 "calls. (To use the customary octal format the number must start with "
1380 &Unix_socket_permissions,
1381 0777, 0000, 0777, NULL, NULL
1385 {"work_mem", PGC_USERSET, RESOURCES_MEM,
1386 gettext_noop("Sets the maximum memory to be used for query workspaces."),
1387 gettext_noop("This much memory can be used by each internal "
1388 "sort operation and hash table before switching to "
1389 "temporary disk files."),
1393 1024, 64, MAX_KILOBYTES, NULL, NULL
1397 {"maintenance_work_mem", PGC_USERSET, RESOURCES_MEM,
1398 gettext_noop("Sets the maximum memory to be used for maintenance operations."),
1399 gettext_noop("This includes operations such as VACUUM and CREATE INDEX."),
1402 &maintenance_work_mem,
1403 16384, 1024, MAX_KILOBYTES, NULL, NULL
1407 {"max_stack_depth", PGC_SUSET, RESOURCES_MEM,
1408 gettext_noop("Sets the maximum stack depth, in kilobytes."),
1413 100, 100, MAX_KILOBYTES, assign_max_stack_depth, NULL
1417 {"vacuum_cost_page_hit", PGC_USERSET, RESOURCES,
1418 gettext_noop("Vacuum cost for a page found in the buffer cache."),
1422 1, 0, 10000, NULL, NULL
1426 {"vacuum_cost_page_miss", PGC_USERSET, RESOURCES,
1427 gettext_noop("Vacuum cost for a page not found in the buffer cache."),
1430 &VacuumCostPageMiss,
1431 10, 0, 10000, NULL, NULL
1435 {"vacuum_cost_page_dirty", PGC_USERSET, RESOURCES,
1436 gettext_noop("Vacuum cost for a page dirtied by vacuum."),
1439 &VacuumCostPageDirty,
1440 20, 0, 10000, NULL, NULL
1444 {"vacuum_cost_limit", PGC_USERSET, RESOURCES,
1445 gettext_noop("Vacuum cost amount available before napping."),
1449 200, 1, 10000, NULL, NULL
1453 {"vacuum_cost_delay", PGC_USERSET, RESOURCES,
1454 gettext_noop("Vacuum cost delay in milliseconds."),
1459 0, 0, 1000, NULL, NULL
1463 {"autovacuum_vacuum_cost_delay", PGC_SIGHUP, AUTOVACUUM,
1464 gettext_noop("Vacuum cost delay in milliseconds, for autovacuum."),
1468 &autovacuum_vac_cost_delay,
1469 20, -1, 1000, NULL, NULL
1473 {"autovacuum_vacuum_cost_limit", PGC_SIGHUP, AUTOVACUUM,
1474 gettext_noop("Vacuum cost amount available before napping, for autovacuum."),
1477 &autovacuum_vac_cost_limit,
1478 -1, -1, 10000, NULL, NULL
1482 {"max_files_per_process", PGC_POSTMASTER, RESOURCES_KERNEL,
1483 gettext_noop("Sets the maximum number of simultaneously open files for each server process."),
1486 &max_files_per_process,
1487 1000, 25, INT_MAX, NULL, NULL
1491 {"max_prepared_transactions", PGC_POSTMASTER, RESOURCES,
1492 gettext_noop("Sets the maximum number of simultaneously prepared transactions."),
1495 &max_prepared_xacts,
1496 5, 0, INT_MAX, NULL, NULL
1501 {"trace_lock_oidmin", PGC_SUSET, DEVELOPER_OPTIONS,
1502 gettext_noop("No description available."),
1507 FirstNormalObjectId, 0, INT_MAX, NULL, NULL
1510 {"trace_lock_table", PGC_SUSET, DEVELOPER_OPTIONS,
1511 gettext_noop("No description available."),
1516 0, 0, INT_MAX, NULL, NULL
1521 {"statement_timeout", PGC_USERSET, CLIENT_CONN_STATEMENT,
1522 gettext_noop("Sets the maximum allowed duration of any statement."),
1523 gettext_noop("A value of 0 turns off the timeout."),
1527 0, 0, INT_MAX, NULL, NULL
1531 {"vacuum_freeze_min_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1532 gettext_noop("Minimum age at which VACUUM should freeze a table row."),
1535 &vacuum_freeze_min_age,
1536 100000000, 0, 1000000000, NULL, NULL
1540 {"max_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
1541 gettext_noop("Sets the maximum number of locks per transaction."),
1542 gettext_noop("The shared lock table is sized on the assumption that "
1543 "at most max_locks_per_transaction * max_connections distinct "
1544 "objects will need to be locked at any one time.")
1546 &max_locks_per_xact,
1547 64, 10, INT_MAX, NULL, NULL
1551 {"authentication_timeout", PGC_SIGHUP, CONN_AUTH_SECURITY,
1552 gettext_noop("Sets the maximum allowed time to complete client authentication."),
1556 &AuthenticationTimeout,
1557 60, 1, 600, NULL, NULL
1561 /* Not for general use */
1562 {"pre_auth_delay", PGC_SIGHUP, DEVELOPER_OPTIONS,
1563 gettext_noop("Waits N seconds on connection startup before authentication."),
1564 gettext_noop("This allows attaching a debugger to the process."),
1565 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1568 0, 0, 60, NULL, NULL
1572 {"checkpoint_segments", PGC_SIGHUP, WAL_CHECKPOINTS,
1573 gettext_noop("Sets the maximum distance in log segments between automatic WAL checkpoints."),
1576 &CheckPointSegments,
1577 3, 1, INT_MAX, NULL, NULL
1581 {"checkpoint_timeout", PGC_SIGHUP, WAL_CHECKPOINTS,
1582 gettext_noop("Sets the maximum time between automatic WAL checkpoints."),
1587 300, 30, 3600, NULL, NULL
1591 {"checkpoint_warning", PGC_SIGHUP, WAL_CHECKPOINTS,
1592 gettext_noop("Enables warnings if checkpoint segments are filled more "
1593 "frequently than this."),
1594 gettext_noop("Write a message to the server log if checkpoints "
1595 "caused by the filling of checkpoint segment files happens more "
1596 "frequently than this number of seconds. Zero turns off the warning."),
1600 30, 0, INT_MAX, NULL, NULL
1604 {"wal_buffers", PGC_POSTMASTER, WAL_SETTINGS,
1605 gettext_noop("Sets the number of disk-page buffers in shared memory for WAL."),
1610 8, 4, INT_MAX, NULL, NULL
1614 {"wal_writer_delay", PGC_SIGHUP, WAL_SETTINGS,
1615 gettext_noop("WAL writer sleep time between WAL flushes."),
1620 200, 1, 10000, NULL, NULL
1624 {"commit_delay", PGC_USERSET, WAL_SETTINGS,
1625 gettext_noop("Sets the delay in microseconds between transaction commit and "
1626 "flushing WAL to disk."),
1630 0, 0, 100000, NULL, NULL
1634 {"commit_siblings", PGC_USERSET, WAL_SETTINGS,
1635 gettext_noop("Sets the minimum concurrent open transactions before performing "
1640 5, 1, 1000, NULL, NULL
1644 {"extra_float_digits", PGC_USERSET, CLIENT_CONN_LOCALE,
1645 gettext_noop("Sets the number of digits displayed for floating-point values."),
1646 gettext_noop("This affects real, double precision, and geometric data types. "
1647 "The parameter value is added to the standard number of digits "
1648 "(FLT_DIG or DBL_DIG as appropriate).")
1650 &extra_float_digits,
1651 0, -15, 2, NULL, NULL
1655 {"log_min_duration_statement", PGC_SUSET, LOGGING_WHEN,
1656 gettext_noop("Sets the minimum execution time above which "
1657 "statements will be logged."),
1658 gettext_noop("Zero prints all queries. -1 turns this feature off."),
1661 &log_min_duration_statement,
1662 -1, -1, INT_MAX / 1000, NULL, NULL
1666 {"log_autovacuum_min_duration", PGC_SIGHUP, LOGGING_WHAT,
1667 gettext_noop("Sets the minimum execution time above which "
1668 "autovacuum actions will be logged."),
1669 gettext_noop("Zero prints all actions. -1 turns autovacuum logging off."),
1672 &Log_autovacuum_min_duration,
1673 -1, -1, INT_MAX / 1000, NULL, NULL
1677 {"bgwriter_delay", PGC_SIGHUP, RESOURCES,
1678 gettext_noop("Background writer sleep time between rounds."),
1683 200, 10, 10000, NULL, NULL
1687 {"bgwriter_lru_maxpages", PGC_SIGHUP, RESOURCES,
1688 gettext_noop("Background writer maximum number of LRU pages to flush per round."),
1691 &bgwriter_lru_maxpages,
1692 100, 0, 1000, NULL, NULL
1696 {"log_rotation_age", PGC_SIGHUP, LOGGING_WHERE,
1697 gettext_noop("Automatic log file rotation will occur after N minutes."),
1702 HOURS_PER_DAY * MINS_PER_HOUR, 0, INT_MAX / MINS_PER_HOUR, NULL, NULL
1706 {"log_rotation_size", PGC_SIGHUP, LOGGING_WHERE,
1707 gettext_noop("Automatic log file rotation will occur after N kilobytes."),
1712 10 * 1024, 0, INT_MAX / 1024, NULL, NULL
1716 {"max_function_args", PGC_INTERNAL, PRESET_OPTIONS,
1717 gettext_noop("Shows the maximum number of function arguments."),
1719 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1722 FUNC_MAX_ARGS, FUNC_MAX_ARGS, FUNC_MAX_ARGS, NULL, NULL
1726 {"max_index_keys", PGC_INTERNAL, PRESET_OPTIONS,
1727 gettext_noop("Shows the maximum number of index keys."),
1729 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1732 INDEX_MAX_KEYS, INDEX_MAX_KEYS, INDEX_MAX_KEYS, NULL, NULL
1736 {"max_identifier_length", PGC_INTERNAL, PRESET_OPTIONS,
1737 gettext_noop("Shows the maximum identifier length."),
1739 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1741 &max_identifier_length,
1742 NAMEDATALEN - 1, NAMEDATALEN - 1, NAMEDATALEN - 1, NULL, NULL
1746 {"block_size", PGC_INTERNAL, PRESET_OPTIONS,
1747 gettext_noop("Shows the size of a disk block."),
1749 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1752 BLCKSZ, BLCKSZ, BLCKSZ, NULL, NULL
1756 {"segment_size", PGC_INTERNAL, PRESET_OPTIONS,
1757 gettext_noop("Shows the number of pages per disk file."),
1759 GUC_UNIT_BLOCKS | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1762 RELSEG_SIZE, RELSEG_SIZE, RELSEG_SIZE, NULL, NULL
1766 {"wal_block_size", PGC_INTERNAL, PRESET_OPTIONS,
1767 gettext_noop("Shows the block size in the write ahead log."),
1769 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1772 XLOG_BLCKSZ, XLOG_BLCKSZ, XLOG_BLCKSZ, NULL, NULL
1776 {"wal_segment_size", PGC_INTERNAL, PRESET_OPTIONS,
1777 gettext_noop("Shows the number of pages per write ahead log segment."),
1779 GUC_UNIT_XBLOCKS | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1782 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
1783 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
1784 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
1789 {"autovacuum_naptime", PGC_SIGHUP, AUTOVACUUM,
1790 gettext_noop("Time to sleep between autovacuum runs."),
1794 &autovacuum_naptime,
1795 60, 1, INT_MAX / 1000, NULL, NULL
1798 {"autovacuum_vacuum_threshold", PGC_SIGHUP, AUTOVACUUM,
1799 gettext_noop("Minimum number of tuple updates or deletes prior to vacuum."),
1802 &autovacuum_vac_thresh,
1803 50, 0, INT_MAX, NULL, NULL
1806 {"autovacuum_analyze_threshold", PGC_SIGHUP, AUTOVACUUM,
1807 gettext_noop("Minimum number of tuple inserts, updates or deletes prior to analyze."),
1810 &autovacuum_anl_thresh,
1811 50, 0, INT_MAX, NULL, NULL
1814 /* see varsup.c for why this is PGC_POSTMASTER not PGC_SIGHUP */
1815 {"autovacuum_freeze_max_age", PGC_POSTMASTER, AUTOVACUUM,
1816 gettext_noop("Age at which to autovacuum a table to prevent transaction ID wraparound."),
1819 &autovacuum_freeze_max_age,
1820 200000000, 100000000, 2000000000, NULL, NULL
1823 /* see max_connections */
1824 {"autovacuum_max_workers", PGC_POSTMASTER, AUTOVACUUM,
1825 gettext_noop("Sets the maximum number of simultaneously running autovacuum worker processes."),
1828 &autovacuum_max_workers,
1829 3, 1, INT_MAX / 4, assign_autovacuum_max_workers, NULL
1833 {"tcp_keepalives_idle", PGC_USERSET, CLIENT_CONN_OTHER,
1834 gettext_noop("Time between issuing TCP keepalives."),
1835 gettext_noop("A value of 0 uses the system default."),
1838 &tcp_keepalives_idle,
1839 0, 0, INT_MAX, assign_tcp_keepalives_idle, show_tcp_keepalives_idle
1843 {"tcp_keepalives_interval", PGC_USERSET, CLIENT_CONN_OTHER,
1844 gettext_noop("Time between TCP keepalive retransmits."),
1845 gettext_noop("A value of 0 uses the system default."),
1848 &tcp_keepalives_interval,
1849 0, 0, INT_MAX, assign_tcp_keepalives_interval, show_tcp_keepalives_interval
1853 {"tcp_keepalives_count", PGC_USERSET, CLIENT_CONN_OTHER,
1854 gettext_noop("Maximum number of TCP keepalive retransmits."),
1855 gettext_noop("This controls the number of consecutive keepalive retransmits that can be "
1856 "lost before a connection is considered dead. A value of 0 uses the "
1859 &tcp_keepalives_count,
1860 0, 0, INT_MAX, assign_tcp_keepalives_count, show_tcp_keepalives_count
1864 {"gin_fuzzy_search_limit", PGC_USERSET, CLIENT_CONN_OTHER,
1865 gettext_noop("Sets the maximum allowed result for exact search by GIN."),
1869 &GinFuzzySearchLimit,
1870 0, 0, INT_MAX, NULL, NULL
1874 {"effective_cache_size", PGC_USERSET, QUERY_TUNING_COST,
1875 gettext_noop("Sets the planner's assumption about the size of the disk cache."),
1876 gettext_noop("That is, the portion of the kernel's disk cache that "
1877 "will be used for PostgreSQL data files. This is measured in disk "
1878 "pages, which are normally 8 kB each."),
1881 &effective_cache_size,
1882 DEFAULT_EFFECTIVE_CACHE_SIZE, 1, INT_MAX, NULL, NULL
1886 /* Can't be set in postgresql.conf */
1887 {"server_version_num", PGC_INTERNAL, PRESET_OPTIONS,
1888 gettext_noop("Shows the server version as an integer."),
1890 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1892 &server_version_num,
1893 PG_VERSION_NUM, PG_VERSION_NUM, PG_VERSION_NUM, NULL, NULL
1897 {"log_temp_files", PGC_SUSET, LOGGING_WHAT,
1898 gettext_noop("Log the use of temporary files larger than this number of kilobytes."),
1899 gettext_noop("Zero logs all files. The default is -1 (turning this feature off)."),
1903 -1, -1, INT_MAX, NULL, NULL
1907 {"track_activity_query_size", PGC_POSTMASTER, RESOURCES_MEM,
1908 gettext_noop("Sets the size reserved for pg_stat_activity.current_query, in bytes."),
1911 &pgstat_track_activity_query_size,
1912 1024, 100, 102400, NULL, NULL
1915 /* End-of-list marker */
1917 {NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL
1922 static struct config_real ConfigureNamesReal[] =
1925 {"seq_page_cost", PGC_USERSET, QUERY_TUNING_COST,
1926 gettext_noop("Sets the planner's estimate of the cost of a "
1927 "sequentially fetched disk page."),
1931 DEFAULT_SEQ_PAGE_COST, 0, DBL_MAX, NULL, NULL
1934 {"random_page_cost", PGC_USERSET, QUERY_TUNING_COST,
1935 gettext_noop("Sets the planner's estimate of the cost of a "
1936 "nonsequentially fetched disk page."),
1940 DEFAULT_RANDOM_PAGE_COST, 0, DBL_MAX, NULL, NULL
1943 {"cpu_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
1944 gettext_noop("Sets the planner's estimate of the cost of "
1945 "processing each tuple (row)."),
1949 DEFAULT_CPU_TUPLE_COST, 0, DBL_MAX, NULL, NULL
1952 {"cpu_index_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
1953 gettext_noop("Sets the planner's estimate of the cost of "
1954 "processing each index entry during an index scan."),
1957 &cpu_index_tuple_cost,
1958 DEFAULT_CPU_INDEX_TUPLE_COST, 0, DBL_MAX, NULL, NULL
1961 {"cpu_operator_cost", PGC_USERSET, QUERY_TUNING_COST,
1962 gettext_noop("Sets the planner's estimate of the cost of "
1963 "processing each operator or function call."),
1967 DEFAULT_CPU_OPERATOR_COST, 0, DBL_MAX, NULL, NULL
1971 {"cursor_tuple_fraction", PGC_USERSET, QUERY_TUNING_OTHER,
1972 gettext_noop("Sets the planner's estimate of the fraction of "
1973 "a cursor's rows that will be retrieved."),
1976 &cursor_tuple_fraction,
1977 DEFAULT_CURSOR_TUPLE_FRACTION, 0.0, 1.0, NULL, NULL
1981 {"geqo_selection_bias", PGC_USERSET, QUERY_TUNING_GEQO,
1982 gettext_noop("GEQO: selective pressure within the population."),
1985 &Geqo_selection_bias,
1986 DEFAULT_GEQO_SELECTION_BIAS, MIN_GEQO_SELECTION_BIAS,
1987 MAX_GEQO_SELECTION_BIAS, NULL, NULL
1991 {"bgwriter_lru_multiplier", PGC_SIGHUP, RESOURCES,
1992 gettext_noop("Multiple of the average buffer usage to free per round."),
1995 &bgwriter_lru_multiplier,
1996 2.0, 0.0, 10.0, NULL, NULL
2000 {"seed", PGC_USERSET, UNGROUPED,
2001 gettext_noop("Sets the seed for random-number generation."),
2003 GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2006 0.0, -1.0, 1.0, assign_random_seed, show_random_seed
2010 {"autovacuum_vacuum_scale_factor", PGC_SIGHUP, AUTOVACUUM,
2011 gettext_noop("Number of tuple updates or deletes prior to vacuum as a fraction of reltuples."),
2014 &autovacuum_vac_scale,
2015 0.2, 0.0, 100.0, NULL, NULL
2018 {"autovacuum_analyze_scale_factor", PGC_SIGHUP, AUTOVACUUM,
2019 gettext_noop("Number of tuple inserts, updates or deletes prior to analyze as a fraction of reltuples."),
2022 &autovacuum_anl_scale,
2023 0.1, 0.0, 100.0, NULL, NULL
2027 {"checkpoint_completion_target", PGC_SIGHUP, WAL_CHECKPOINTS,
2028 gettext_noop("Time spent flushing dirty buffers during checkpoint, as fraction of checkpoint interval."),
2031 &CheckPointCompletionTarget,
2032 0.5, 0.0, 1.0, NULL, NULL
2035 /* End-of-list marker */
2037 {NULL, 0, 0, NULL, NULL}, NULL, 0.0, 0.0, 0.0, NULL, NULL
2042 static struct config_string ConfigureNamesString[] =
2045 {"archive_command", PGC_SIGHUP, WAL_SETTINGS,
2046 gettext_noop("Sets the shell command that will be called to archive a WAL file."),
2049 &XLogArchiveCommand,
2050 "", NULL, show_archive_command
2054 {"client_encoding", PGC_USERSET, CLIENT_CONN_LOCALE,
2055 gettext_noop("Sets the client's character set encoding."),
2057 GUC_IS_NAME | GUC_REPORT
2059 &client_encoding_string,
2060 "SQL_ASCII", assign_client_encoding, NULL
2064 {"log_line_prefix", PGC_SIGHUP, LOGGING_WHAT,
2065 gettext_noop("Controls information prefixed to each log line."),
2066 gettext_noop("If blank, no prefix is used.")
2073 {"log_timezone", PGC_SIGHUP, LOGGING_WHAT,
2074 gettext_noop("Sets the time zone to use in log messages."),
2077 &log_timezone_string,
2078 "UNKNOWN", assign_log_timezone, show_log_timezone
2082 {"DateStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
2083 gettext_noop("Sets the display format for date and time values."),
2084 gettext_noop("Also controls interpretation of ambiguous "
2086 GUC_LIST_INPUT | GUC_REPORT
2089 "ISO, MDY", assign_datestyle, NULL
2093 {"default_tablespace", PGC_USERSET, CLIENT_CONN_STATEMENT,
2094 gettext_noop("Sets the default tablespace to create tables and indexes in."),
2095 gettext_noop("An empty string selects the database's default tablespace."),
2098 &default_tablespace,
2099 "", assign_default_tablespace, NULL
2103 {"temp_tablespaces", PGC_USERSET, CLIENT_CONN_STATEMENT,
2104 gettext_noop("Sets the tablespace(s) to use for temporary tables and sort files."),
2106 GUC_LIST_INPUT | GUC_LIST_QUOTE
2109 "", assign_temp_tablespaces, NULL
2113 {"dynamic_library_path", PGC_SUSET, CLIENT_CONN_OTHER,
2114 gettext_noop("Sets the path for dynamically loadable modules."),
2115 gettext_noop("If a dynamically loadable module needs to be opened and "
2116 "the specified name does not have a directory component (i.e., the "
2117 "name does not contain a slash), the system will search this path for "
2118 "the specified file."),
2121 &Dynamic_library_path,
2122 "$libdir", NULL, NULL
2126 {"krb_realm", PGC_POSTMASTER, CONN_AUTH_SECURITY,
2127 gettext_noop("Sets realm to match Kerberos and GSSAPI users against."),
2136 {"krb_server_keyfile", PGC_POSTMASTER, CONN_AUTH_SECURITY,
2137 gettext_noop("Sets the location of the Kerberos server key file."),
2141 &pg_krb_server_keyfile,
2142 PG_KRB_SRVTAB, NULL, NULL
2146 {"krb_srvname", PGC_POSTMASTER, CONN_AUTH_SECURITY,
2147 gettext_noop("Sets the name of the Kerberos service."),
2151 PG_KRB_SRVNAM, NULL, NULL
2155 {"krb_server_hostname", PGC_POSTMASTER, CONN_AUTH_SECURITY,
2156 gettext_noop("Sets the hostname of the Kerberos server."),
2159 &pg_krb_server_hostname,
2164 {"bonjour_name", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2165 gettext_noop("Sets the Bonjour broadcast service name."),
2172 /* See main.c about why defaults for LC_foo are not all alike */
2175 {"lc_collate", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2176 gettext_noop("Shows the collation order locale."),
2178 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2185 {"lc_ctype", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2186 gettext_noop("Shows the character classification and case conversion locale."),
2188 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2195 {"lc_messages", PGC_SUSET, CLIENT_CONN_LOCALE,
2196 gettext_noop("Sets the language in which messages are displayed."),
2200 "", locale_messages_assign, NULL
2204 {"lc_monetary", PGC_USERSET, CLIENT_CONN_LOCALE,
2205 gettext_noop("Sets the locale for formatting monetary amounts."),
2209 "C", locale_monetary_assign, NULL
2213 {"lc_numeric", PGC_USERSET, CLIENT_CONN_LOCALE,
2214 gettext_noop("Sets the locale for formatting numbers."),
2218 "C", locale_numeric_assign, NULL
2222 {"lc_time", PGC_USERSET, CLIENT_CONN_LOCALE,
2223 gettext_noop("Sets the locale for formatting date and time values."),
2227 "C", locale_time_assign, NULL
2231 {"shared_preload_libraries", PGC_POSTMASTER, RESOURCES_KERNEL,
2232 gettext_noop("Lists shared libraries to preload into server."),
2234 GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
2236 &shared_preload_libraries_string,
2241 {"local_preload_libraries", PGC_BACKEND, CLIENT_CONN_OTHER,
2242 gettext_noop("Lists shared libraries to preload into each backend."),
2244 GUC_LIST_INPUT | GUC_LIST_QUOTE
2246 &local_preload_libraries_string,
2251 {"search_path", PGC_USERSET, CLIENT_CONN_STATEMENT,
2252 gettext_noop("Sets the schema search order for names that are not schema-qualified."),
2254 GUC_LIST_INPUT | GUC_LIST_QUOTE
2256 &namespace_search_path,
2257 "\"$user\",public", assign_search_path, NULL
2261 /* Can't be set in postgresql.conf */
2262 {"server_encoding", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2263 gettext_noop("Sets the server (database) character set encoding."),
2265 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2267 &server_encoding_string,
2268 "SQL_ASCII", NULL, NULL
2272 /* Can't be set in postgresql.conf */
2273 {"server_version", PGC_INTERNAL, PRESET_OPTIONS,
2274 gettext_noop("Shows the server version."),
2276 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2278 &server_version_string,
2279 PG_VERSION, NULL, NULL
2283 /* Not for general use --- used by SET ROLE */
2284 {"role", PGC_USERSET, UNGROUPED,
2285 gettext_noop("Sets the current role."),
2287 GUC_IS_NAME | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2290 "none", assign_role, show_role
2294 /* Not for general use --- used by SET SESSION AUTHORIZATION */
2295 {"session_authorization", PGC_USERSET, UNGROUPED,
2296 gettext_noop("Sets the session user name."),
2298 GUC_IS_NAME | GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2300 &session_authorization_string,
2301 NULL, assign_session_authorization, show_session_authorization
2305 {"log_destination", PGC_SIGHUP, LOGGING_WHERE,
2306 gettext_noop("Sets the destination for server log output."),
2307 gettext_noop("Valid values are combinations of \"stderr\", "
2308 "\"syslog\", \"csvlog\", and \"eventlog\", "
2309 "depending on the platform."),
2312 &log_destination_string,
2313 "stderr", assign_log_destination, NULL
2316 {"log_directory", PGC_SIGHUP, LOGGING_WHERE,
2317 gettext_noop("Sets the destination directory for log files."),
2318 gettext_noop("Can be specified as relative to the data directory "
2319 "or as absolute path."),
2323 "pg_log", assign_canonical_path, NULL
2326 {"log_filename", PGC_SIGHUP, LOGGING_WHERE,
2327 gettext_noop("Sets the file name pattern for log files."),
2332 "postgresql-%Y-%m-%d_%H%M%S.log", NULL, NULL
2337 {"syslog_ident", PGC_SIGHUP, LOGGING_WHERE,
2338 gettext_noop("Sets the program name used to identify PostgreSQL "
2339 "messages in syslog."),
2343 "postgres", assign_syslog_ident, NULL
2348 {"TimeZone", PGC_USERSET, CLIENT_CONN_LOCALE,
2349 gettext_noop("Sets the time zone for displaying and interpreting time stamps."),
2354 "UNKNOWN", assign_timezone, show_timezone
2357 {"timezone_abbreviations", PGC_USERSET, CLIENT_CONN_LOCALE,
2358 gettext_noop("Selects a file of time zone abbreviations."),
2361 &timezone_abbreviations_string,
2362 "UNKNOWN", assign_timezone_abbreviations, NULL
2366 {"transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
2367 gettext_noop("Sets the current transaction's isolation level."),
2369 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2371 &XactIsoLevel_string,
2372 NULL, assign_XactIsoLevel, show_XactIsoLevel
2376 {"unix_socket_group", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2377 gettext_noop("Sets the owning group of the Unix-domain socket."),
2378 gettext_noop("The owning user of the socket is always the user "
2379 "that starts the server.")
2386 {"unix_socket_directory", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2387 gettext_noop("Sets the directory where the Unix-domain socket will be created."),
2392 "", assign_canonical_path, NULL
2396 {"listen_addresses", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2397 gettext_noop("Sets the host name or IP address(es) to listen to."),
2402 "localhost", NULL, NULL
2406 {"custom_variable_classes", PGC_SIGHUP, CUSTOM_OPTIONS,
2407 gettext_noop("Sets the list of known custom variable classes."),
2409 GUC_LIST_INPUT | GUC_LIST_QUOTE
2411 &custom_variable_classes,
2412 NULL, assign_custom_variable_classes, NULL
2416 {"data_directory", PGC_POSTMASTER, FILE_LOCATIONS,
2417 gettext_noop("Sets the server's data directory."),
2426 {"config_file", PGC_POSTMASTER, FILE_LOCATIONS,
2427 gettext_noop("Sets the server's main configuration file."),
2429 GUC_DISALLOW_IN_FILE | GUC_SUPERUSER_ONLY
2436 {"hba_file", PGC_POSTMASTER, FILE_LOCATIONS,
2437 gettext_noop("Sets the server's \"hba\" configuration file."),
2446 {"ident_file", PGC_POSTMASTER, FILE_LOCATIONS,
2447 gettext_noop("Sets the server's \"ident\" configuration file."),
2456 {"external_pid_file", PGC_POSTMASTER, FILE_LOCATIONS,
2457 gettext_noop("Writes the postmaster PID to the specified file."),
2462 NULL, assign_canonical_path, NULL
2466 {"stats_temp_directory", PGC_SIGHUP, STATS_COLLECTOR,
2467 gettext_noop("Writes temporary statistics files to the specified directory."),
2471 &pgstat_temp_directory,
2472 "pg_stat_tmp", assign_pgstat_temp_directory, NULL
2476 {"default_text_search_config", PGC_USERSET, CLIENT_CONN_LOCALE,
2477 gettext_noop("Sets default text search configuration."),
2481 "pg_catalog.simple", assignTSCurrentConfig, NULL
2486 {"ssl_ciphers", PGC_POSTMASTER, CONN_AUTH_SECURITY,
2487 gettext_noop("Sets the list of allowed SSL ciphers."),
2492 "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH", NULL, NULL
2494 #endif /* USE_SSL */
2496 /* End-of-list marker */
2498 {NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL
2503 static struct config_enum ConfigureNamesEnum[] =
2506 {"backslash_quote", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
2507 gettext_noop("Sets whether \"\\'\" is allowed in string literals."),
2511 BACKSLASH_QUOTE_SAFE_ENCODING, backslash_quote_options, NULL, NULL
2515 {"client_min_messages", PGC_USERSET, LOGGING_WHEN,
2516 gettext_noop("Sets the message levels that are sent to the client."),
2517 gettext_noop("Each level includes all the levels that follow it. The later"
2518 " the level, the fewer messages are sent.")
2520 &client_min_messages,
2521 NOTICE, client_message_level_options, NULL, NULL
2525 {"default_transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
2526 gettext_noop("Sets the transaction isolation level of each new transaction."),
2529 &DefaultXactIsoLevel,
2530 XACT_READ_COMMITTED, isolation_level_options, NULL, NULL
2534 {"IntervalStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
2535 gettext_noop("Sets the display format for interval values."),
2540 INTSTYLE_POSTGRES, intervalstyle_options, NULL, NULL
2544 {"log_error_verbosity", PGC_SUSET, LOGGING_WHEN,
2545 gettext_noop("Sets the verbosity of logged messages."),
2548 &Log_error_verbosity,
2549 PGERROR_DEFAULT, log_error_verbosity_options, NULL, NULL
2553 {"log_min_messages", PGC_SUSET, LOGGING_WHEN,
2554 gettext_noop("Sets the message levels that are logged."),
2555 gettext_noop("Each level includes all the levels that follow it. The later"
2556 " the level, the fewer messages are sent.")
2559 WARNING, server_message_level_options, NULL, NULL
2563 {"log_min_error_statement", PGC_SUSET, LOGGING_WHEN,
2564 gettext_noop("Causes all statements generating error at or above this level to be logged."),
2565 gettext_noop("Each level includes all the levels that follow it. The later"
2566 " the level, the fewer messages are sent.")
2568 &log_min_error_statement,
2569 ERROR, server_message_level_options, NULL, NULL
2573 {"log_statement", PGC_SUSET, LOGGING_WHAT,
2574 gettext_noop("Sets the type of statements logged."),
2578 LOGSTMT_NONE, log_statement_options, NULL, NULL
2583 {"syslog_facility", PGC_SIGHUP, LOGGING_WHERE,
2584 gettext_noop("Sets the syslog \"facility\" to be used when syslog enabled."),
2588 LOG_LOCAL0, syslog_facility_options, assign_syslog_facility, NULL
2593 {"regex_flavor", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
2594 gettext_noop("Sets the regular expression \"flavor\"."),
2598 REG_ADVANCED, regex_flavor_options, NULL, NULL
2602 {"session_replication_role", PGC_SUSET, CLIENT_CONN_STATEMENT,
2603 gettext_noop("Sets the session's behavior for triggers and rewrite rules."),
2606 &SessionReplicationRole,
2607 SESSION_REPLICATION_ROLE_ORIGIN, session_replication_role_options,
2608 assign_session_replication_role, NULL
2612 {"track_functions", PGC_SUSET, STATS_COLLECTOR,
2613 gettext_noop("Collects function-level statistics on database activity."),
2616 &pgstat_track_functions,
2617 TRACK_FUNC_OFF, track_function_options, NULL, NULL
2621 {"wal_sync_method", PGC_SIGHUP, WAL_SETTINGS,
2622 gettext_noop("Selects the method used for forcing WAL updates to disk."),
2626 DEFAULT_SYNC_METHOD, sync_method_options,
2627 assign_xlog_sync_method, NULL
2631 {"xmlbinary", PGC_USERSET, CLIENT_CONN_STATEMENT,
2632 gettext_noop("Sets how binary values are to be encoded in XML."),
2636 XMLBINARY_BASE64, xmlbinary_options, NULL, NULL
2640 {"xmloption", PGC_USERSET, CLIENT_CONN_STATEMENT,
2641 gettext_noop("Sets whether XML data in implicit parsing and serialization "
2642 "operations is to be considered as documents or content fragments."),
2646 XMLOPTION_CONTENT, xmloption_options, NULL, NULL
2650 /* End-of-list marker */
2652 {NULL, 0, 0, NULL, NULL}, NULL, 0, NULL, NULL, NULL
2656 /******** end of options list ********/
2660 * To allow continued support of obsolete names for GUC variables, we apply
2661 * the following mappings to any unrecognized name. Note that an old name
2662 * should be mapped to a new one only if the new variable has very similar
2663 * semantics to the old.
2665 static const char *const map_old_guc_names[] = {
2666 "sort_mem", "work_mem",
2667 "vacuum_mem", "maintenance_work_mem",
2673 * Actual lookup of variables is done through this single, sorted array.
2675 static struct config_generic **guc_variables;
2677 /* Current number of variables contained in the vector */
2678 static int num_guc_variables;
2680 /* Vector capacity */
2681 static int size_guc_variables;
2684 static bool guc_dirty; /* TRUE if need to do commit/abort work */
2686 static bool reporting_enabled; /* TRUE to enable GUC_REPORT */
2688 static int GUCNestLevel = 0; /* 1 when in main transaction */
2691 static int guc_var_compare(const void *a, const void *b);
2692 static int guc_name_compare(const char *namea, const char *nameb);
2693 static void InitializeOneGUCOption(struct config_generic *gconf);
2694 static void push_old_value(struct config_generic * gconf, GucAction action);
2695 static void ReportGUCOption(struct config_generic * record);
2696 static void ShowGUCConfigOption(const char *name, DestReceiver *dest);
2697 static void ShowAllGUCConfig(DestReceiver *dest);
2698 static char *_ShowOption(struct config_generic * record, bool use_units);
2699 static bool is_newvalue_equal(struct config_generic * record, const char *newvalue);
2703 * Some infrastructure for checking malloc/strdup/realloc calls
2706 guc_malloc(int elevel, size_t size)
2710 data = malloc(size);
2713 (errcode(ERRCODE_OUT_OF_MEMORY),
2714 errmsg("out of memory")));
2719 guc_realloc(int elevel, void *old, size_t size)
2723 data = realloc(old, size);
2726 (errcode(ERRCODE_OUT_OF_MEMORY),
2727 errmsg("out of memory")));
2732 guc_strdup(int elevel, const char *src)
2739 (errcode(ERRCODE_OUT_OF_MEMORY),
2740 errmsg("out of memory")));
2746 * Support for assigning to a field of a string GUC item. Free the prior
2747 * value if it's not referenced anywhere else in the item (including stacked
2751 set_string_field(struct config_string * conf, char **field, char *newval)
2753 char *oldval = *field;
2756 /* Do the assignment */
2759 /* Exit if any duplicate references, or if old value was NULL anyway */
2760 if (oldval == NULL ||
2761 oldval == *(conf->variable) ||
2762 oldval == conf->reset_val ||
2763 oldval == conf->boot_val)
2765 for (stack = conf->gen.stack; stack; stack = stack->prev)
2767 if (oldval == stack->prior.stringval ||
2768 oldval == stack->masked.stringval)
2772 /* Not used anymore, so free it */
2777 * Detect whether strval is referenced anywhere in a GUC string item
2780 string_field_used(struct config_string * conf, char *strval)
2784 if (strval == *(conf->variable) ||
2785 strval == conf->reset_val ||
2786 strval == conf->boot_val)
2788 for (stack = conf->gen.stack; stack; stack = stack->prev)
2790 if (strval == stack->prior.stringval ||
2791 strval == stack->masked.stringval)
2798 * Support for copying a variable's active value into a stack entry
2801 set_stack_value(struct config_generic * gconf, union config_var_value * val)
2803 switch (gconf->vartype)
2807 *((struct config_bool *) gconf)->variable;
2811 *((struct config_int *) gconf)->variable;
2815 *((struct config_real *) gconf)->variable;
2818 /* we assume stringval is NULL if not valid */
2819 set_string_field((struct config_string *) gconf,
2821 *((struct config_string *) gconf)->variable);
2825 *((struct config_enum *) gconf)->variable;
2831 * Support for discarding a no-longer-needed value in a stack entry
2834 discard_stack_value(struct config_generic * gconf, union config_var_value * val)
2836 switch (gconf->vartype)
2842 /* no need to do anything */
2845 set_string_field((struct config_string *) gconf,
2854 * Fetch the sorted array pointer (exported for help_config.c's use ONLY)
2856 struct config_generic **
2857 get_guc_variables(void)
2859 return guc_variables;
2864 * Build the sorted array. This is split out so that it could be
2865 * re-executed after startup (eg, we could allow loadable modules to
2866 * add vars, and then we'd need to re-sort).
2869 build_guc_variables(void)
2873 struct config_generic **guc_vars;
2876 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
2878 struct config_bool *conf = &ConfigureNamesBool[i];
2880 /* Rather than requiring vartype to be filled in by hand, do this: */
2881 conf->gen.vartype = PGC_BOOL;
2885 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
2887 struct config_int *conf = &ConfigureNamesInt[i];
2889 conf->gen.vartype = PGC_INT;
2893 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
2895 struct config_real *conf = &ConfigureNamesReal[i];
2897 conf->gen.vartype = PGC_REAL;
2901 for (i = 0; ConfigureNamesString[i].gen.name; i++)
2903 struct config_string *conf = &ConfigureNamesString[i];
2905 conf->gen.vartype = PGC_STRING;
2909 for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
2911 struct config_enum *conf = &ConfigureNamesEnum[i];
2913 conf->gen.vartype = PGC_ENUM;
2918 * Create table with 20% slack
2920 size_vars = num_vars + num_vars / 4;
2922 guc_vars = (struct config_generic **)
2923 guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
2927 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
2928 guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
2930 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
2931 guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
2933 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
2934 guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
2936 for (i = 0; ConfigureNamesString[i].gen.name; i++)
2937 guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
2939 for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
2940 guc_vars[num_vars++] = &ConfigureNamesEnum[i].gen;
2943 free(guc_variables);
2944 guc_variables = guc_vars;
2945 num_guc_variables = num_vars;
2946 size_guc_variables = size_vars;
2947 qsort((void *) guc_variables, num_guc_variables,
2948 sizeof(struct config_generic *), guc_var_compare);
2952 * Add a new GUC variable to the list of known variables. The
2953 * list is expanded if needed.
2956 add_guc_variable(struct config_generic * var, int elevel)
2958 if (num_guc_variables + 1 >= size_guc_variables)
2961 * Increase the vector by 25%
2963 int size_vars = size_guc_variables + size_guc_variables / 4;
2964 struct config_generic **guc_vars;
2969 guc_vars = (struct config_generic **)
2970 guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
2974 guc_vars = (struct config_generic **)
2975 guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
2978 if (guc_vars == NULL)
2979 return false; /* out of memory */
2981 guc_variables = guc_vars;
2982 size_guc_variables = size_vars;
2984 guc_variables[num_guc_variables++] = var;
2985 qsort((void *) guc_variables, num_guc_variables,
2986 sizeof(struct config_generic *), guc_var_compare);
2991 * Create and add a placeholder variable. It's presumed to belong
2992 * to a valid custom variable class at this point.
2994 static struct config_generic *
2995 add_placeholder_variable(const char *name, int elevel)
2997 size_t sz = sizeof(struct config_string) + sizeof(char *);
2998 struct config_string *var;
2999 struct config_generic *gen;
3001 var = (struct config_string *) guc_malloc(elevel, sz);
3007 gen->name = guc_strdup(elevel, name);
3008 if (gen->name == NULL)
3014 gen->context = PGC_USERSET;
3015 gen->group = CUSTOM_OPTIONS;
3016 gen->short_desc = "GUC placeholder variable";
3017 gen->flags = GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_CUSTOM_PLACEHOLDER;
3018 gen->vartype = PGC_STRING;
3021 * The char* is allocated at the end of the struct since we have no
3022 * 'static' place to point to. Note that the current value, as well as
3023 * the boot and reset values, start out NULL.
3025 var->variable = (char **) (var + 1);
3027 if (!add_guc_variable((struct config_generic *) var, elevel))
3029 free((void *) gen->name);
3038 * Detect whether the portion of "name" before dotPos matches any custom
3039 * variable class name listed in custom_var_classes. The latter must be
3040 * formatted the way that assign_custom_variable_classes does it, ie,
3041 * no whitespace. NULL is valid for custom_var_classes.
3044 is_custom_class(const char *name, int dotPos, const char *custom_var_classes)
3046 bool result = false;
3047 const char *ccs = custom_var_classes;
3051 const char *start = ccs;
3057 if (c == '\0' || c == ',')
3059 if (dotPos == ccs - start && strncmp(start, name, dotPos) == 0)
3074 * Look up option NAME. If it exists, return a pointer to its record,
3075 * else return NULL. If create_placeholders is TRUE, we'll create a
3076 * placeholder record for a valid-looking custom variable name.
3078 static struct config_generic *
3079 find_option(const char *name, bool create_placeholders, int elevel)
3081 const char **key = &name;
3082 struct config_generic **res;
3088 * By equating const char ** with struct config_generic *, we are assuming
3089 * the name field is first in config_generic.
3091 res = (struct config_generic **) bsearch((void *) &key,
3092 (void *) guc_variables,
3094 sizeof(struct config_generic *),
3100 * See if the name is an obsolete name for a variable. We assume that the
3101 * set of supported old names is short enough that a brute-force search is
3104 for (i = 0; map_old_guc_names[i] != NULL; i += 2)
3106 if (guc_name_compare(name, map_old_guc_names[i]) == 0)
3107 return find_option(map_old_guc_names[i + 1], false, elevel);
3110 if (create_placeholders)
3113 * Check if the name is qualified, and if so, check if the qualifier
3114 * matches any custom variable class. If so, add a placeholder.
3116 const char *dot = strchr(name, GUC_QUALIFIER_SEPARATOR);
3119 is_custom_class(name, dot - name, custom_variable_classes))
3120 return add_placeholder_variable(name, elevel);
3129 * comparator for qsorting and bsearching guc_variables array
3132 guc_var_compare(const void *a, const void *b)
3134 struct config_generic *confa = *(struct config_generic **) a;
3135 struct config_generic *confb = *(struct config_generic **) b;
3137 return guc_name_compare(confa->name, confb->name);
3141 * the bare comparison function for GUC names
3144 guc_name_compare(const char *namea, const char *nameb)
3147 * The temptation to use strcasecmp() here must be resisted, because the
3148 * array ordering has to remain stable across setlocale() calls. So, build
3149 * our own with a simple ASCII-only downcasing.
3151 while (*namea && *nameb)
3153 char cha = *namea++;
3154 char chb = *nameb++;
3156 if (cha >= 'A' && cha <= 'Z')
3158 if (chb >= 'A' && chb <= 'Z')
3164 return 1; /* a is longer */
3166 return -1; /* b is longer */
3172 * Initialize GUC options during program startup.
3174 * Note that we cannot read the config file yet, since we have not yet
3175 * processed command-line switches.
3178 InitializeGUCOptions(void)
3185 * Before log_line_prefix could possibly receive a nonempty setting, make
3186 * sure that timezone processing is minimally alive (see elog.c).
3188 pg_timezone_pre_initialize();
3191 * Build sorted array of all GUC variables.
3193 build_guc_variables();
3196 * Load all variables with their compiled-in defaults, and initialize
3197 * status fields as needed.
3199 for (i = 0; i < num_guc_variables; i++)
3201 InitializeOneGUCOption(guc_variables[i]);
3206 reporting_enabled = false;
3209 * Prevent any attempt to override the transaction modes from
3210 * non-interactive sources.
3212 SetConfigOption("transaction_isolation", "default",
3213 PGC_POSTMASTER, PGC_S_OVERRIDE);
3214 SetConfigOption("transaction_read_only", "no",
3215 PGC_POSTMASTER, PGC_S_OVERRIDE);
3218 * For historical reasons, some GUC parameters can receive defaults from
3219 * environment variables. Process those settings. NB: if you add or
3220 * remove anything here, see also ProcessConfigFile().
3223 env = getenv("PGPORT");
3225 SetConfigOption("port", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3227 env = getenv("PGDATESTYLE");
3229 SetConfigOption("datestyle", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3231 env = getenv("PGCLIENTENCODING");
3233 SetConfigOption("client_encoding", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3236 * rlimit isn't exactly an "environment variable", but it behaves about
3237 * the same. If we can identify the platform stack depth rlimit, increase
3238 * default stack depth setting up to whatever is safe (but at most 2MB).
3240 stack_rlimit = get_stack_depth_rlimit();
3241 if (stack_rlimit > 0)
3243 int new_limit = (stack_rlimit - STACK_DEPTH_SLOP) / 1024L;
3245 if (new_limit > 100)
3249 new_limit = Min(new_limit, 2048);
3250 sprintf(limbuf, "%d", new_limit);
3251 SetConfigOption("max_stack_depth", limbuf,
3252 PGC_POSTMASTER, PGC_S_ENV_VAR);
3258 * Initialize one GUC option variable to its compiled-in default.
3261 InitializeOneGUCOption(struct config_generic *gconf)
3264 gconf->reset_source = PGC_S_DEFAULT;
3265 gconf->source = PGC_S_DEFAULT;
3266 gconf->stack = NULL;
3267 gconf->sourcefile = NULL;
3268 gconf->sourceline = 0;
3270 switch (gconf->vartype)
3274 struct config_bool *conf = (struct config_bool *) gconf;
3276 if (conf->assign_hook)
3277 if (!(*conf->assign_hook) (conf->boot_val, true,
3279 elog(FATAL, "failed to initialize %s to %d",
3280 conf->gen.name, (int) conf->boot_val);
3281 *conf->variable = conf->reset_val = conf->boot_val;
3286 struct config_int *conf = (struct config_int *) gconf;
3288 Assert(conf->boot_val >= conf->min);
3289 Assert(conf->boot_val <= conf->max);
3290 if (conf->assign_hook)
3291 if (!(*conf->assign_hook) (conf->boot_val, true,
3293 elog(FATAL, "failed to initialize %s to %d",
3294 conf->gen.name, conf->boot_val);
3295 *conf->variable = conf->reset_val = conf->boot_val;
3300 struct config_real *conf = (struct config_real *) gconf;
3302 Assert(conf->boot_val >= conf->min);
3303 Assert(conf->boot_val <= conf->max);
3304 if (conf->assign_hook)
3305 if (!(*conf->assign_hook) (conf->boot_val, true,
3307 elog(FATAL, "failed to initialize %s to %g",
3308 conf->gen.name, conf->boot_val);
3309 *conf->variable = conf->reset_val = conf->boot_val;
3314 struct config_string *conf = (struct config_string *) gconf;
3317 *conf->variable = NULL;
3318 conf->reset_val = NULL;
3320 if (conf->boot_val == NULL)
3322 /* leave the value NULL, do not call assign hook */
3326 str = guc_strdup(FATAL, conf->boot_val);
3327 conf->reset_val = str;
3329 if (conf->assign_hook)
3333 newstr = (*conf->assign_hook) (str, true,
3337 elog(FATAL, "failed to initialize %s to \"%s\"",
3338 conf->gen.name, str);
3340 else if (newstr != str)
3345 * See notes in set_config_option about casting
3347 str = (char *) newstr;
3348 conf->reset_val = str;
3351 *conf->variable = str;
3356 struct config_enum *conf = (struct config_enum *) gconf;
3358 if (conf->assign_hook)
3359 if (!(*conf->assign_hook) (conf->boot_val, true,
3361 elog(FATAL, "failed to initialize %s to %s",
3363 config_enum_lookup_by_value(conf, conf->boot_val));
3364 *conf->variable = conf->reset_val = conf->boot_val;
3372 * Select the configuration files and data directory to be used, and
3373 * do the initial read of postgresql.conf.
3375 * This is called after processing command-line switches.
3376 * userDoption is the -D switch value if any (NULL if unspecified).
3377 * progname is just for use in error messages.
3379 * Returns true on success; on failure, prints a suitable error message
3380 * to stderr and returns false.
3383 SelectConfigFiles(const char *userDoption, const char *progname)
3387 struct stat stat_buf;
3389 /* configdir is -D option, or $PGDATA if no -D */
3391 configdir = make_absolute_path(userDoption);
3393 configdir = make_absolute_path(getenv("PGDATA"));
3396 * Find the configuration file: if config_file was specified on the
3397 * command line, use it, else use configdir/postgresql.conf. In any case
3398 * ensure the result is an absolute path, so that it will be interpreted
3399 * the same way by future backends.
3402 fname = make_absolute_path(ConfigFileName);
3405 fname = guc_malloc(FATAL,
3406 strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
3407 sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
3411 write_stderr("%s does not know where to find the server configuration file.\n"
3412 "You must specify the --config-file or -D invocation "
3413 "option or set the PGDATA environment variable.\n",
3419 * Set the ConfigFileName GUC variable to its final value, ensuring that
3420 * it can't be overridden later.
3422 SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
3426 * Now read the config file for the first time.
3428 if (stat(ConfigFileName, &stat_buf) != 0)
3430 write_stderr("%s cannot access the server configuration file \"%s\": %s\n",
3431 progname, ConfigFileName, strerror(errno));
3435 ProcessConfigFile(PGC_POSTMASTER);
3438 * If the data_directory GUC variable has been set, use that as DataDir;
3439 * otherwise use configdir if set; else punt.
3441 * Note: SetDataDir will copy and absolute-ize its argument, so we don't
3445 SetDataDir(data_directory);
3447 SetDataDir(configdir);
3450 write_stderr("%s does not know where to find the database system data.\n"
3451 "This can be specified as \"data_directory\" in \"%s\", "
3452 "or by the -D invocation option, or by the "
3453 "PGDATA environment variable.\n",
3454 progname, ConfigFileName);
3459 * Reflect the final DataDir value back into the data_directory GUC var.
3460 * (If you are wondering why we don't just make them a single variable,
3461 * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
3462 * child backends specially. XXX is that still true? Given that we now
3463 * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
3464 * DataDir in advance.)
3466 SetConfigOption("data_directory", DataDir, PGC_POSTMASTER, PGC_S_OVERRIDE);
3469 * Figure out where pg_hba.conf is, and make sure the path is absolute.
3472 fname = make_absolute_path(HbaFileName);
3475 fname = guc_malloc(FATAL,
3476 strlen(configdir) + strlen(HBA_FILENAME) + 2);
3477 sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
3481 write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
3482 "This can be specified as \"hba_file\" in \"%s\", "
3483 "or by the -D invocation option, or by the "
3484 "PGDATA environment variable.\n",
3485 progname, ConfigFileName);
3488 SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
3492 * Likewise for pg_ident.conf.
3495 fname = make_absolute_path(IdentFileName);
3498 fname = guc_malloc(FATAL,
3499 strlen(configdir) + strlen(IDENT_FILENAME) + 2);
3500 sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
3504 write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
3505 "This can be specified as \"ident_file\" in \"%s\", "
3506 "or by the -D invocation option, or by the "
3507 "PGDATA environment variable.\n",
3508 progname, ConfigFileName);
3511 SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
3521 * Reset all options to their saved default values (implements RESET ALL)
3524 ResetAllOptions(void)
3528 for (i = 0; i < num_guc_variables; i++)
3530 struct config_generic *gconf = guc_variables[i];
3532 /* Don't reset non-SET-able values */
3533 if (gconf->context != PGC_SUSET &&
3534 gconf->context != PGC_USERSET)
3536 /* Don't reset if special exclusion from RESET ALL */
3537 if (gconf->flags & GUC_NO_RESET_ALL)
3539 /* No need to reset if wasn't SET */
3540 if (gconf->source <= PGC_S_OVERRIDE)
3543 /* Save old value to support transaction abort */
3544 push_old_value(gconf, GUC_ACTION_SET);
3546 switch (gconf->vartype)
3550 struct config_bool *conf = (struct config_bool *) gconf;
3552 if (conf->assign_hook)
3553 if (!(*conf->assign_hook) (conf->reset_val, true,
3555 elog(ERROR, "failed to reset %s", conf->gen.name);
3556 *conf->variable = conf->reset_val;
3561 struct config_int *conf = (struct config_int *) 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;
3572 struct config_real *conf = (struct config_real *) gconf;
3574 if (conf->assign_hook)
3575 if (!(*conf->assign_hook) (conf->reset_val, true,
3577 elog(ERROR, "failed to reset %s", conf->gen.name);
3578 *conf->variable = conf->reset_val;
3583 struct config_string *conf = (struct config_string *) gconf;
3586 /* We need not strdup here */
3587 str = conf->reset_val;
3589 if (conf->assign_hook && str)
3593 newstr = (*conf->assign_hook) (str, true,
3596 elog(ERROR, "failed to reset %s", conf->gen.name);
3597 else if (newstr != str)
3600 * See notes in set_config_option about casting
3602 str = (char *) newstr;
3606 set_string_field(conf, conf->variable, str);
3611 struct config_enum *conf = (struct config_enum *) gconf;
3613 if (conf->assign_hook)
3614 if (!(*conf->assign_hook) (conf->reset_val, true,
3616 elog(ERROR, "failed to reset %s", conf->gen.name);
3617 *conf->variable = conf->reset_val;
3622 gconf->source = gconf->reset_source;
3624 if (gconf->flags & GUC_REPORT)
3625 ReportGUCOption(gconf);
3632 * Push previous state during transactional assignment to a GUC variable.
3635 push_old_value(struct config_generic * gconf, GucAction action)
3639 /* If we're not inside a nest level, do nothing */
3640 if (GUCNestLevel == 0)
3643 /* Do we already have a stack entry of the current nest level? */
3644 stack = gconf->stack;
3645 if (stack && stack->nest_level >= GUCNestLevel)
3647 /* Yes, so adjust its state if necessary */
3648 Assert(stack->nest_level == GUCNestLevel);
3651 case GUC_ACTION_SET:
3652 /* SET overrides any prior action at same nest level */
3653 if (stack->state == GUC_SET_LOCAL)
3655 /* must discard old masked value */
3656 discard_stack_value(gconf, &stack->masked);
3658 stack->state = GUC_SET;
3660 case GUC_ACTION_LOCAL:
3661 if (stack->state == GUC_SET)
3663 /* SET followed by SET LOCAL, remember SET's value */
3664 set_stack_value(gconf, &stack->masked);
3665 stack->state = GUC_SET_LOCAL;
3667 /* in all other cases, no change to stack entry */
3669 case GUC_ACTION_SAVE:
3670 /* Could only have a prior SAVE of same variable */
3671 Assert(stack->state == GUC_SAVE);
3674 Assert(guc_dirty); /* must be set already */
3679 * Push a new stack entry
3681 * We keep all the stack entries in TopTransactionContext for simplicity.
3683 stack = (GucStack *) MemoryContextAllocZero(TopTransactionContext,
3686 stack->prev = gconf->stack;
3687 stack->nest_level = GUCNestLevel;
3690 case GUC_ACTION_SET:
3691 stack->state = GUC_SET;
3693 case GUC_ACTION_LOCAL:
3694 stack->state = GUC_LOCAL;
3696 case GUC_ACTION_SAVE:
3697 stack->state = GUC_SAVE;
3700 stack->source = gconf->source;
3701 set_stack_value(gconf, &stack->prior);
3703 gconf->stack = stack;
3705 /* Ensure we remember to pop at end of xact */
3711 * Do GUC processing at main transaction start.
3717 * The nest level should be 0 between transactions; if it isn't, somebody
3718 * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
3719 * throw a warning but make no other effort to clean up.
3721 if (GUCNestLevel != 0)
3722 elog(WARNING, "GUC nest level = %d at transaction start",
3728 * Enter a new nesting level for GUC values. This is called at subtransaction
3729 * start and when entering a function that has proconfig settings. NOTE that
3730 * we must not risk error here, else subtransaction start will be unhappy.
3733 NewGUCNestLevel(void)
3735 return ++GUCNestLevel;
3739 * Do GUC processing at transaction or subtransaction commit or abort, or
3740 * when exiting a function that has proconfig settings. (The name is thus
3741 * a bit of a misnomer; perhaps it should be ExitGUCNestLevel or some such.)
3742 * During abort, we discard all GUC settings that were applied at nesting
3743 * levels >= nestLevel. nestLevel == 1 corresponds to the main transaction.
3746 AtEOXact_GUC(bool isCommit, int nestLevel)
3751 Assert(nestLevel > 0 && nestLevel <= GUCNestLevel);
3753 /* Quick exit if nothing's changed in this transaction */
3756 GUCNestLevel = nestLevel - 1;
3760 still_dirty = false;
3761 for (i = 0; i < num_guc_variables; i++)
3763 struct config_generic *gconf = guc_variables[i];
3767 * Process and pop each stack entry within the nest level. To
3768 * simplify fmgr_security_definer(), we allow failure exit from a
3769 * function-with-SET-options to be recovered at the surrounding
3770 * transaction or subtransaction abort; so there could be more than
3771 * one stack entry to pop.
3773 while ((stack = gconf->stack) != NULL &&
3774 stack->nest_level >= nestLevel)
3776 GucStack *prev = stack->prev;
3777 bool restorePrior = false;
3778 bool restoreMasked = false;
3782 * In this next bit, if we don't set either restorePrior or
3783 * restoreMasked, we must "discard" any unwanted fields of the
3784 * stack entries to avoid leaking memory. If we do set one of
3785 * those flags, unused fields will be cleaned up after restoring.
3787 if (!isCommit) /* if abort, always restore prior value */
3788 restorePrior = true;
3789 else if (stack->state == GUC_SAVE)
3790 restorePrior = true;
3791 else if (stack->nest_level == 1)
3793 /* transaction commit */
3794 if (stack->state == GUC_SET_LOCAL)
3795 restoreMasked = true;
3796 else if (stack->state == GUC_SET)
3798 /* we keep the current active value */
3799 discard_stack_value(gconf, &stack->prior);
3801 else /* must be GUC_LOCAL */
3802 restorePrior = true;
3804 else if (prev == NULL ||
3805 prev->nest_level < stack->nest_level - 1)
3807 /* decrement entry's level and do not pop it */
3808 stack->nest_level--;
3814 * We have to merge this stack entry into prev. See README for
3815 * discussion of this bit.
3817 switch (stack->state)
3820 Assert(false); /* can't get here */
3823 /* next level always becomes SET */
3824 discard_stack_value(gconf, &stack->prior);
3825 if (prev->state == GUC_SET_LOCAL)
3826 discard_stack_value(gconf, &prev->masked);
3827 prev->state = GUC_SET;
3831 if (prev->state == GUC_SET)
3833 /* LOCAL migrates down */
3834 prev->masked = stack->prior;
3835 prev->state = GUC_SET_LOCAL;
3839 /* else just forget this stack level */
3840 discard_stack_value(gconf, &stack->prior);
3845 /* prior state at this level no longer wanted */
3846 discard_stack_value(gconf, &stack->prior);
3847 /* copy down the masked state */
3848 if (prev->state == GUC_SET_LOCAL)
3849 discard_stack_value(gconf, &prev->masked);
3850 prev->masked = stack->masked;
3851 prev->state = GUC_SET_LOCAL;
3858 if (restorePrior || restoreMasked)
3860 /* Perform appropriate restoration of the stacked value */
3861 union config_var_value newvalue;
3862 GucSource newsource;
3866 newvalue = stack->masked;
3867 newsource = PGC_S_SESSION;
3871 newvalue = stack->prior;
3872 newsource = stack->source;
3875 switch (gconf->vartype)
3879 struct config_bool *conf = (struct config_bool *) gconf;
3880 bool newval = newvalue.boolval;
3882 if (*conf->variable != newval)
3884 if (conf->assign_hook)
3885 if (!(*conf->assign_hook) (newval,
3886 true, PGC_S_OVERRIDE))
3887 elog(LOG, "failed to commit %s",
3889 *conf->variable = newval;
3896 struct config_int *conf = (struct config_int *) gconf;
3897 int newval = newvalue.intval;
3899 if (*conf->variable != newval)
3901 if (conf->assign_hook)
3902 if (!(*conf->assign_hook) (newval,
3903 true, PGC_S_OVERRIDE))
3904 elog(LOG, "failed to commit %s",
3906 *conf->variable = newval;
3913 struct config_real *conf = (struct config_real *) gconf;
3914 double newval = newvalue.realval;
3916 if (*conf->variable != newval)
3918 if (conf->assign_hook)
3919 if (!(*conf->assign_hook) (newval,
3920 true, PGC_S_OVERRIDE))
3921 elog(LOG, "failed to commit %s",
3923 *conf->variable = newval;
3930 struct config_string *conf = (struct config_string *) gconf;
3931 char *newval = newvalue.stringval;
3933 if (*conf->variable != newval)
3935 if (conf->assign_hook && newval)
3939 newstr = (*conf->assign_hook) (newval, true,
3942 elog(LOG, "failed to commit %s",
3944 else if (newstr != newval)
3947 * If newval should now be freed,
3948 * it'll be taken care of below.
3950 * See notes in set_config_option
3953 newval = (char *) newstr;
3957 set_string_field(conf, conf->variable, newval);
3962 * Release stacked values if not used anymore. We
3963 * could use discard_stack_value() here, but since
3964 * we have type-specific code anyway, might as
3967 set_string_field(conf, &stack->prior.stringval, NULL);
3968 set_string_field(conf, &stack->masked.stringval, NULL);
3973 struct config_enum *conf = (struct config_enum *) gconf;
3974 int newval = newvalue.enumval;
3976 if (*conf->variable != newval)
3978 if (conf->assign_hook)
3979 if (!(*conf->assign_hook) (newval,
3980 true, PGC_S_OVERRIDE))
3981 elog(LOG, "failed to commit %s",
3983 *conf->variable = newval;
3990 gconf->source = newsource;
3993 /* Finish popping the state stack */
3994 gconf->stack = prev;
3997 /* Report new value if we changed it */
3998 if (changed && (gconf->flags & GUC_REPORT))
3999 ReportGUCOption(gconf);
4000 } /* end of stack-popping loop */
4006 /* If there are no remaining stack entries, we can reset guc_dirty */
4007 guc_dirty = still_dirty;
4009 /* Update nesting level */
4010 GUCNestLevel = nestLevel - 1;
4015 * Start up automatic reporting of changes to variables marked GUC_REPORT.
4016 * This is executed at completion of backend startup.
4019 BeginReportingGUCOptions(void)
4024 * Don't do anything unless talking to an interactive frontend of protocol
4027 if (whereToSendOutput != DestRemote ||
4028 PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
4031 reporting_enabled = true;
4033 /* Transmit initial values of interesting variables */
4034 for (i = 0; i < num_guc_variables; i++)
4036 struct config_generic *conf = guc_variables[i];
4038 if (conf->flags & GUC_REPORT)
4039 ReportGUCOption(conf);
4044 * ReportGUCOption: if appropriate, transmit option value to frontend
4047 ReportGUCOption(struct config_generic * record)
4049 if (reporting_enabled && (record->flags & GUC_REPORT))
4051 char *val = _ShowOption(record, false);
4052 StringInfoData msgbuf;
4054 pq_beginmessage(&msgbuf, 'S');
4055 pq_sendstring(&msgbuf, record->name);
4056 pq_sendstring(&msgbuf, val);
4057 pq_endmessage(&msgbuf);
4065 * Try to interpret value as boolean value. Valid values are: true,
4066 * false, yes, no, on, off, 1, 0; as well as unique prefixes thereof.
4067 * If the string parses okay, return true, else false.
4068 * If okay and result is not NULL, return the value in *result.
4071 parse_bool(const char *value, bool *result)
4073 size_t len = strlen(value);
4075 if (pg_strncasecmp(value, "true", len) == 0)
4080 else if (pg_strncasecmp(value, "false", len) == 0)
4086 else if (pg_strncasecmp(value, "yes", len) == 0)
4091 else if (pg_strncasecmp(value, "no", len) == 0)
4097 /* 'o' is not unique enough */
4098 else if (pg_strncasecmp(value, "on", (len > 2 ? len : 2)) == 0)
4103 else if (pg_strncasecmp(value, "off", (len > 2 ? len : 2)) == 0)
4109 else if (pg_strcasecmp(value, "1") == 0)
4114 else if (pg_strcasecmp(value, "0") == 0)
4123 *result = false; /* suppress compiler warning */
4132 * Try to parse value as an integer. The accepted formats are the
4133 * usual decimal, octal, or hexadecimal formats, optionally followed by
4134 * a unit name if "flags" indicates a unit is allowed.
4136 * If the string parses okay, return true, else false.
4137 * If okay and result is not NULL, return the value in *result.
4138 * If not okay and hintmsg is not NULL, *hintmsg is set to a suitable
4139 * HINT message, or NULL if no hint provided.
4142 parse_int(const char *value, int *result, int flags, const char **hintmsg)
4147 /* To suppress compiler warnings, always set output params */
4153 /* We assume here that int64 is at least as wide as long */
4155 val = strtol(value, &endptr, 0);
4157 if (endptr == value)
4158 return false; /* no HINT for integer syntax error */
4160 if (errno == ERANGE || val != (int64) ((int32) val))
4163 *hintmsg = gettext_noop("Value exceeds integer range.");
4167 /* allow whitespace between integer and unit */
4168 while (isspace((unsigned char) *endptr))
4171 /* Handle possible unit */
4172 if (*endptr != '\0')
4175 * Note: the multiple-switch coding technique here is a bit tedious,
4176 * but seems necessary to avoid intermediate-value overflows.
4178 * If INT64_IS_BUSTED (ie, it's really int32) we will fail to detect
4179 * overflow due to units conversion, but there are few enough such
4180 * machines that it does not seem worth trying to be smarter.
4182 if (flags & GUC_UNIT_MEMORY)
4184 /* Set hint for use if no match or trailing garbage */
4186 *hintmsg = gettext_noop("Valid units for this parameter are \"kB\", \"MB\", and \"GB\".");
4188 #if BLCKSZ < 1024 || BLCKSZ > (1024*1024)
4189 #error BLCKSZ must be between 1KB and 1MB
4191 #if XLOG_BLCKSZ < 1024 || XLOG_BLCKSZ > (1024*1024)
4192 #error XLOG_BLCKSZ must be between 1KB and 1MB
4195 if (strncmp(endptr, "kB", 2) == 0)
4198 switch (flags & GUC_UNIT_MEMORY)
4200 case GUC_UNIT_BLOCKS:
4201 val /= (BLCKSZ / 1024);
4203 case GUC_UNIT_XBLOCKS:
4204 val /= (XLOG_BLCKSZ / 1024);
4208 else if (strncmp(endptr, "MB", 2) == 0)
4211 switch (flags & GUC_UNIT_MEMORY)
4216 case GUC_UNIT_BLOCKS:
4217 val *= KB_PER_MB / (BLCKSZ / 1024);
4219 case GUC_UNIT_XBLOCKS:
4220 val *= KB_PER_MB / (XLOG_BLCKSZ / 1024);
4224 else if (strncmp(endptr, "GB", 2) == 0)
4227 switch (flags & GUC_UNIT_MEMORY)
4232 case GUC_UNIT_BLOCKS:
4233 val *= KB_PER_GB / (BLCKSZ / 1024);
4235 case GUC_UNIT_XBLOCKS:
4236 val *= KB_PER_GB / (XLOG_BLCKSZ / 1024);
4241 else if (flags & GUC_UNIT_TIME)
4243 /* Set hint for use if no match or trailing garbage */
4245 *hintmsg = gettext_noop("Valid units for this parameter are \"ms\", \"s\", \"min\", \"h\", and \"d\".");
4247 if (strncmp(endptr, "ms", 2) == 0)
4250 switch (flags & GUC_UNIT_TIME)
4260 else if (strncmp(endptr, "s", 1) == 0)
4263 switch (flags & GUC_UNIT_TIME)
4273 else if (strncmp(endptr, "min", 3) == 0)
4276 switch (flags & GUC_UNIT_TIME)
4286 else if (strncmp(endptr, "h", 1) == 0)
4289 switch (flags & GUC_UNIT_TIME)
4302 else if (strncmp(endptr, "d", 1) == 0)
4305 switch (flags & GUC_UNIT_TIME)
4320 /* allow whitespace after unit */
4321 while (isspace((unsigned char) *endptr))
4324 if (*endptr != '\0')
4325 return false; /* appropriate hint, if any, already set */
4327 /* Check for overflow due to units conversion */
4328 if (val != (int64) ((int32) val))
4331 *hintmsg = gettext_noop("Value exceeds integer range.");
4337 *result = (int) val;
4344 * Try to parse value as a floating point number in the usual format.
4345 * If the string parses okay, return true, else false.
4346 * If okay and result is not NULL, return the value in *result.
4349 parse_real(const char *value, double *result)
4355 *result = 0; /* suppress compiler warning */
4358 val = strtod(value, &endptr);
4359 if (endptr == value || errno == ERANGE)
4362 /* allow whitespace after number */
4363 while (isspace((unsigned char) *endptr))
4365 if (*endptr != '\0')
4375 * Lookup the name for an enum option with the selected value.
4376 * Should only ever be called with known-valid values, so throws
4377 * an elog(ERROR) if the enum option is not found.
4379 * The returned string is a pointer to static data and not
4380 * allocated for modification.
4383 config_enum_lookup_by_value(struct config_enum *record, int val)
4385 const struct config_enum_entry *entry;
4387 for (entry = record->options; entry && entry->name; entry++)
4389 if (entry->val == val)
4393 elog(ERROR, "could not find enum option %d for %s",
4394 val, record->gen.name);
4395 return NULL; /* silence compiler */
4400 * Lookup the value for an enum option with the selected name
4401 * (case-insensitive).
4402 * If the enum option is found, sets the retval value and returns
4403 * true. If it's not found, return FALSE and retval is set to 0.
4406 config_enum_lookup_by_name(struct config_enum *record, const char *value,
4409 const struct config_enum_entry *entry;
4411 for (entry = record->options; entry && entry->name; entry++)
4413 if (pg_strcasecmp(value, entry->name) == 0)
4415 *retval = entry->val;
4426 * Return a list of all available options for an enum, excluding
4427 * hidden ones, separated by the given separator.
4428 * If prefix is non-NULL, it is added before the first enum value.
4429 * If suffix is non-NULL, it is added to the end of the string.
4432 config_enum_get_options(struct config_enum *record, const char *prefix,
4433 const char *suffix, const char *separator)
4435 const struct config_enum_entry *entry;
4436 StringInfoData retstr;
4439 initStringInfo(&retstr);
4440 appendStringInfoString(&retstr, prefix);
4442 seplen = strlen(separator);
4443 for (entry = record->options; entry && entry->name; entry++)
4447 appendStringInfoString(&retstr, entry->name);
4448 appendBinaryStringInfo(&retstr, separator, seplen);
4453 * All the entries may have been hidden, leaving the string empty
4454 * if no prefix was given. This indicates a broken GUC setup, since
4455 * there is no use for an enum without any values, so we just check
4456 * to make sure we don't write to invalid memory instead of actually
4457 * trying to do something smart with it.
4459 if (retstr.len >= seplen)
4461 /* Replace final separator */
4462 retstr.data[retstr.len - seplen] = '\0';
4463 retstr.len -= seplen;
4466 appendStringInfoString(&retstr, suffix);
4472 * Call a GucStringAssignHook function, being careful to free the
4473 * "newval" string if the hook ereports.
4475 * This is split out of set_config_option just to avoid the "volatile"
4476 * qualifiers that would otherwise have to be plastered all over.
4479 call_string_assign_hook(GucStringAssignHook assign_hook,
4480 char *newval, bool doit, GucSource source)
4486 result = (*assign_hook) (newval, doit, source);
4500 * Sets option `name' to given value. The value should be a string
4501 * which is going to be parsed and converted to the appropriate data
4502 * type. The context and source parameters indicate in which context this
4503 * function is being called so it can apply the access restrictions
4506 * If value is NULL, set the option to its default value (normally the
4507 * reset_val, but if source == PGC_S_DEFAULT we instead use the boot_val).
4509 * action indicates whether to set the value globally in the session, locally
4510 * to the current top transaction, or just for the duration of a function call.
4512 * If changeVal is false then don't really set the option but do all
4513 * the checks to see if it would work.
4515 * If there is an error (non-existing option, invalid value) then an
4516 * ereport(ERROR) is thrown *unless* this is called in a context where we
4517 * don't want to ereport (currently, startup or SIGHUP config file reread).
4518 * In that case we write a suitable error message via ereport(LOG) and
4519 * return false. This is working around the deficiencies in the ereport
4520 * mechanism, so don't blame me. In all other cases, the function
4521 * returns true, including cases where the input is valid but we chose
4522 * not to apply it because of context or source-priority considerations.
4524 * See also SetConfigOption for an external interface.
4527 set_config_option(const char *name, const char *value,
4528 GucContext context, GucSource source,
4529 GucAction action, bool changeVal)
4531 struct config_generic *record;
4535 if (context == PGC_SIGHUP || source == PGC_S_DEFAULT)
4538 * To avoid cluttering the log, only the postmaster bleats loudly
4539 * about problems with the config file.
4541 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
4543 else if (source == PGC_S_DATABASE || source == PGC_S_USER)
4548 record = find_option(name, true, elevel);
4552 (errcode(ERRCODE_UNDEFINED_OBJECT),
4553 errmsg("unrecognized configuration parameter \"%s\"", name)));
4558 * If source is postgresql.conf, mark the found record with
4559 * GUC_IS_IN_FILE. This is for the convenience of ProcessConfigFile. Note
4560 * that we do it even if changeVal is false, since ProcessConfigFile wants
4561 * the marking to occur during its testing pass.
4563 if (source == PGC_S_FILE)
4564 record->status |= GUC_IS_IN_FILE;
4567 * Check if the option can be set at this time. See guc.h for the precise
4568 * rules. Note that we don't want to throw errors if we're in the SIGHUP
4569 * context. In that case we just ignore the attempt and return true.
4571 switch (record->context)
4574 if (context == PGC_SIGHUP)
4576 if (context != PGC_INTERNAL)
4579 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4580 errmsg("parameter \"%s\" cannot be changed",
4585 case PGC_POSTMASTER:
4586 if (context == PGC_SIGHUP)
4589 * We are reading a PGC_POSTMASTER var from postgresql.conf.
4590 * We can't change the setting, so give a warning if the DBA
4591 * tries to change it. (Throwing an error would be more
4592 * consistent, but seems overly rigid.)
4594 if (changeVal && !is_newvalue_equal(record, value))
4596 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4597 errmsg("attempted change of parameter \"%s\" ignored",
4599 errdetail("This parameter cannot be changed after server start.")));
4602 if (context != PGC_POSTMASTER)
4605 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4606 errmsg("attempted change of parameter \"%s\" ignored",
4608 errdetail("This parameter cannot be changed after server start.")));
4613 if (context != PGC_SIGHUP && context != PGC_POSTMASTER)
4616 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4617 errmsg("parameter \"%s\" cannot be changed now",
4623 * Hmm, the idea of the SIGHUP context is "ought to be global, but
4624 * can be changed after postmaster start". But there's nothing
4625 * that prevents a crafty administrator from sending SIGHUP
4626 * signals to individual backends only.
4630 if (context == PGC_SIGHUP)
4633 * If a PGC_BACKEND parameter is changed in the config file,
4634 * we want to accept the new value in the postmaster (whence
4635 * it will propagate to subsequently-started backends), but
4636 * ignore it in existing backends. This is a tad klugy, but
4637 * necessary because we don't re-read the config file during
4640 if (IsUnderPostmaster)
4643 else if (context != PGC_BACKEND && context != PGC_POSTMASTER)
4646 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4647 errmsg("parameter \"%s\" cannot be set after connection start",
4653 if (context == PGC_USERSET || context == PGC_BACKEND)
4656 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4657 errmsg("permission denied to set parameter \"%s\"",
4668 * Should we set reset/stacked values? (If so, the behavior is not
4669 * transactional.) This is done either when we get a default value from
4670 * the database's/user's/client's default settings or when we reset a
4671 * value to its default.
4673 makeDefault = changeVal && (source <= PGC_S_OVERRIDE) &&
4674 ((value != NULL) || source == PGC_S_DEFAULT);
4677 * Ignore attempted set if overridden by previously processed setting.
4678 * However, if changeVal is false then plow ahead anyway since we are
4679 * trying to find out if the value is potentially good, not actually use
4680 * it. Also keep going if makeDefault is true, since we may want to set
4681 * the reset/stacked values even if we can't set the variable itself.
4683 if (record->source > source)
4685 if (changeVal && !makeDefault)
4687 elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
4695 * Evaluate value and set variable.
4697 switch (record->vartype)
4701 struct config_bool *conf = (struct config_bool *) record;
4706 if (!parse_bool(value, &newval))
4709 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4710 errmsg("parameter \"%s\" requires a Boolean value",
4715 else if (source == PGC_S_DEFAULT)
4716 newval = conf->boot_val;
4719 newval = conf->reset_val;
4720 source = conf->gen.reset_source;
4723 /* Save old value to support transaction abort */
4724 if (changeVal && !makeDefault)
4725 push_old_value(&conf->gen, action);
4727 if (conf->assign_hook)
4728 if (!(*conf->assign_hook) (newval, changeVal, source))
4731 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4732 errmsg("invalid value for parameter \"%s\": %d",
4733 name, (int) newval)));
4739 *conf->variable = newval;
4740 conf->gen.source = source;
4746 if (conf->gen.reset_source <= source)
4748 conf->reset_val = newval;
4749 conf->gen.reset_source = source;
4751 for (stack = conf->gen.stack; stack; stack = stack->prev)
4753 if (stack->source <= source)
4755 stack->prior.boolval = newval;
4756 stack->source = source;
4765 struct config_int *conf = (struct config_int *) record;
4770 const char *hintmsg;
4772 if (!parse_int(value, &newval, conf->gen.flags, &hintmsg))
4775 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4776 errmsg("invalid value for parameter \"%s\": \"%s\"",
4778 hintmsg ? errhint("%s", hintmsg) : 0));
4781 if (newval < conf->min || newval > conf->max)
4784 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4785 errmsg("%d is outside the valid range for parameter \"%s\" (%d .. %d)",
4786 newval, name, conf->min, conf->max)));
4790 else if (source == PGC_S_DEFAULT)
4791 newval = conf->boot_val;
4794 newval = conf->reset_val;
4795 source = conf->gen.reset_source;
4798 /* Save old value to support transaction abort */
4799 if (changeVal && !makeDefault)
4800 push_old_value(&conf->gen, action);
4802 if (conf->assign_hook)
4803 if (!(*conf->assign_hook) (newval, changeVal, source))
4806 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4807 errmsg("invalid value for parameter \"%s\": %d",
4814 *conf->variable = newval;
4815 conf->gen.source = source;
4821 if (conf->gen.reset_source <= source)
4823 conf->reset_val = newval;
4824 conf->gen.reset_source = source;
4826 for (stack = conf->gen.stack; stack; stack = stack->prev)
4828 if (stack->source <= source)
4830 stack->prior.intval = newval;
4831 stack->source = source;
4840 struct config_real *conf = (struct config_real *) record;
4845 if (!parse_real(value, &newval))
4848 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4849 errmsg("parameter \"%s\" requires a numeric value",
4853 if (newval < conf->min || newval > conf->max)
4856 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4857 errmsg("%g is outside the valid range for parameter \"%s\" (%g .. %g)",
4858 newval, name, conf->min, conf->max)));
4862 else if (source == PGC_S_DEFAULT)
4863 newval = conf->boot_val;
4866 newval = conf->reset_val;
4867 source = conf->gen.reset_source;
4870 /* Save old value to support transaction abort */
4871 if (changeVal && !makeDefault)
4872 push_old_value(&conf->gen, action);
4874 if (conf->assign_hook)
4875 if (!(*conf->assign_hook) (newval, changeVal, source))
4878 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4879 errmsg("invalid value for parameter \"%s\": %g",
4886 *conf->variable = newval;
4887 conf->gen.source = source;
4893 if (conf->gen.reset_source <= source)
4895 conf->reset_val = newval;
4896 conf->gen.reset_source = source;
4898 for (stack = conf->gen.stack; stack; stack = stack->prev)
4900 if (stack->source <= source)
4902 stack->prior.realval = newval;
4903 stack->source = source;
4912 struct config_string *conf = (struct config_string *) record;
4917 newval = guc_strdup(elevel, value);
4922 * The only sort of "parsing" check we need to do is apply
4923 * truncation if GUC_IS_NAME.
4925 if (conf->gen.flags & GUC_IS_NAME)
4926 truncate_identifier(newval, strlen(newval), true);
4928 else if (source == PGC_S_DEFAULT)
4930 if (conf->boot_val == NULL)
4934 newval = guc_strdup(elevel, conf->boot_val);
4942 * We could possibly avoid strdup here, but easier to make
4943 * this case work the same as the normal assignment case;
4944 * note the possible free of newval below.
4946 if (conf->reset_val == NULL)
4950 newval = guc_strdup(elevel, conf->reset_val);
4954 source = conf->gen.reset_source;
4957 /* Save old value to support transaction abort */
4958 if (changeVal && !makeDefault)
4959 push_old_value(&conf->gen, action);
4961 if (conf->assign_hook && newval)
4963 const char *hookresult;
4966 * If the hook ereports, we have to make sure we free
4967 * newval, else it will be a permanent memory leak.
4969 hookresult = call_string_assign_hook(conf->assign_hook,
4973 if (hookresult == NULL)
4977 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4978 errmsg("invalid value for parameter \"%s\": \"%s\"",
4979 name, value ? value : "")));
4982 else if (hookresult != newval)
4987 * Having to cast away const here is annoying, but the
4988 * alternative is to declare assign_hooks as returning
4989 * char*, which would mean they'd have to cast away
4990 * const, or as both taking and returning char*, which
4991 * doesn't seem attractive either --- we don't want
4992 * them to scribble on the passed str.
4994 newval = (char *) hookresult;
5000 set_string_field(conf, conf->variable, newval);
5001 conf->gen.source = source;
5007 if (conf->gen.reset_source <= source)
5009 set_string_field(conf, &conf->reset_val, newval);
5010 conf->gen.reset_source = source;
5012 for (stack = conf->gen.stack; stack; stack = stack->prev)
5014 if (stack->source <= source)
5016 set_string_field(conf, &stack->prior.stringval,
5018 stack->source = source;
5022 /* Perhaps we didn't install newval anywhere */
5023 if (newval && !string_field_used(conf, newval))
5029 struct config_enum *conf = (struct config_enum *) record;
5034 if (!config_enum_lookup_by_name(conf, value, &newval))
5038 hintmsg = config_enum_get_options(conf,
5039 "Available values: ",
5043 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5044 errmsg("invalid value for parameter \"%s\": \"%s\"",
5046 hintmsg ? errhint("%s", hintmsg) : 0));
5053 else if (source == PGC_S_DEFAULT)
5054 newval = conf->boot_val;
5057 newval = conf->reset_val;
5058 source = conf->gen.reset_source;
5061 /* Save old value to support transaction abort */
5062 if (changeVal && !makeDefault)
5063 push_old_value(&conf->gen, action);
5065 if (conf->assign_hook)
5066 if (!(*conf->assign_hook) (newval, changeVal, source))
5069 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5070 errmsg("invalid value for parameter \"%s\": \"%s\"",
5072 config_enum_lookup_by_value(conf, newval))));
5078 *conf->variable = newval;
5079 conf->gen.source = source;
5085 if (conf->gen.reset_source <= source)
5087 conf->reset_val = newval;
5088 conf->gen.reset_source = source;
5090 for (stack = conf->gen.stack; stack; stack = stack->prev)
5092 if (stack->source <= source)
5094 stack->prior.enumval = newval;
5095 stack->source = source;
5103 if (changeVal && (record->flags & GUC_REPORT))
5104 ReportGUCOption(record);
5111 * Set the fields for source file and line number the setting came from.
5114 set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
5116 struct config_generic *record;
5120 * To avoid cluttering the log, only the postmaster bleats loudly
5121 * about problems with the config file.
5123 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
5125 record = find_option(name, true, elevel);
5126 /* should not happen */
5128 elog(ERROR, "unrecognized configuration parameter \"%s\"", name);
5130 sourcefile = guc_strdup(elevel, sourcefile);
5131 if (record->sourcefile)
5132 free(record->sourcefile);
5133 record->sourcefile = sourcefile;
5134 record->sourceline = sourceline;
5138 * Set a config option to the given value. See also set_config_option,
5139 * this is just the wrapper to be called from outside GUC. NB: this
5140 * is used only for non-transactional operations.
5142 * Note: there is no support here for setting source file/line, as it
5143 * is currently not needed.
5146 SetConfigOption(const char *name, const char *value,
5147 GucContext context, GucSource source)
5149 (void) set_config_option(name, value, context, source,
5150 GUC_ACTION_SET, true);
5156 * Fetch the current value of the option `name'. If the option doesn't exist,
5157 * throw an ereport and don't return.
5159 * The string is *not* allocated for modification and is really only
5160 * valid until the next call to configuration related functions.
5163 GetConfigOption(const char *name)
5165 struct config_generic *record;
5166 static char buffer[256];
5168 record = find_option(name, false, ERROR);
5171 (errcode(ERRCODE_UNDEFINED_OBJECT),
5172 errmsg("unrecognized configuration parameter \"%s\"", name)));
5173 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
5175 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5176 errmsg("must be superuser to examine \"%s\"", name)));
5178 switch (record->vartype)
5181 return *((struct config_bool *) record)->variable ? "on" : "off";
5184 snprintf(buffer, sizeof(buffer), "%d",
5185 *((struct config_int *) record)->variable);
5189 snprintf(buffer, sizeof(buffer), "%g",
5190 *((struct config_real *) record)->variable);
5194 return *((struct config_string *) record)->variable;
5197 return config_enum_lookup_by_value((struct config_enum *) record,
5198 *((struct config_enum *) record)->variable);
5204 * Get the RESET value associated with the given option.
5206 * Note: this is not re-entrant, due to use of static result buffer;
5207 * not to mention that a string variable could have its reset_val changed.
5208 * Beware of assuming the result value is good for very long.
5211 GetConfigOptionResetString(const char *name)
5213 struct config_generic *record;
5214 static char buffer[256];
5216 record = find_option(name, false, ERROR);
5219 (errcode(ERRCODE_UNDEFINED_OBJECT),
5220 errmsg("unrecognized configuration parameter \"%s\"", name)));
5221 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
5223 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5224 errmsg("must be superuser to examine \"%s\"", name)));
5226 switch (record->vartype)
5229 return ((struct config_bool *) record)->reset_val ? "on" : "off";
5232 snprintf(buffer, sizeof(buffer), "%d",
5233 ((struct config_int *) record)->reset_val);
5237 snprintf(buffer, sizeof(buffer), "%g",
5238 ((struct config_real *) record)->reset_val);
5242 return ((struct config_string *) record)->reset_val;
5245 return config_enum_lookup_by_value((struct config_enum *) record,
5246 ((struct config_enum *) record)->reset_val);
5252 * Detect whether the given configuration option can only be set by
5256 IsSuperuserConfigOption(const char *name)
5258 struct config_generic *record;
5260 record = find_option(name, false, ERROR);
5261 /* On an unrecognized name, don't error, just return false. */
5264 return (record->context == PGC_SUSET);
5269 * GUC_complaint_elevel
5270 * Get the ereport error level to use in an assign_hook's error report.
5272 * This should be used by assign hooks that want to emit a custom error
5273 * report (in addition to the generic "invalid value for option FOO" that
5274 * guc.c will provide). Note that the result might be ERROR or a lower
5275 * level, so the caller must be prepared for control to return from ereport,
5276 * or not. If control does return, return false/NULL from the hook function.
5278 * At some point it'd be nice to replace this with a mechanism that allows
5279 * the custom message to become the DETAIL line of guc.c's generic message.
5282 GUC_complaint_elevel(GucSource source)
5286 if (source == PGC_S_FILE)
5289 * To avoid cluttering the log, only the postmaster bleats loudly
5290 * about problems with the config file.
5292 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
5294 else if (source == PGC_S_OVERRIDE)
5297 * If we're a postmaster child, this is probably "undo" during
5298 * transaction abort, so we don't want to clutter the log. There's
5299 * a small chance of a real problem with an OVERRIDE setting,
5300 * though, so suppressing the message entirely wouldn't be desirable.
5302 elevel = IsUnderPostmaster ? DEBUG5 : LOG;
5304 else if (source < PGC_S_INTERACTIVE)
5314 * flatten_set_variable_args
5315 * Given a parsenode List as emitted by the grammar for SET,
5316 * convert to the flat string representation used by GUC.
5318 * We need to be told the name of the variable the args are for, because
5319 * the flattening rules vary (ugh).
5321 * The result is NULL if args is NIL (ie, SET ... TO DEFAULT), otherwise
5322 * a palloc'd string.
5325 flatten_set_variable_args(const char *name, List *args)
5327 struct config_generic *record;
5332 /* Fast path if just DEFAULT */
5336 /* Else get flags for the variable */
5337 record = find_option(name, true, ERROR);
5340 (errcode(ERRCODE_UNDEFINED_OBJECT),
5341 errmsg("unrecognized configuration parameter \"%s\"", name)));
5343 flags = record->flags;
5345 /* Complain if list input and non-list variable */
5346 if ((flags & GUC_LIST_INPUT) == 0 &&
5347 list_length(args) != 1)
5349 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5350 errmsg("SET %s takes only one argument", name)));
5352 initStringInfo(&buf);
5355 * Each list member may be a plain A_Const node, or an A_Const within a
5356 * TypeCast; the latter case is supported only for ConstInterval
5357 * arguments (for SET TIME ZONE).
5361 Node *arg = (Node *) lfirst(l);
5363 TypeName *typename = NULL;
5366 if (l != list_head(args))
5367 appendStringInfo(&buf, ", ");
5369 if (IsA(arg, TypeCast))
5371 TypeCast *tc = (TypeCast *) arg;
5374 typename = tc->typename;
5377 if (!IsA(arg, A_Const))
5378 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
5379 con = (A_Const *) arg;
5381 switch (nodeTag(&con->val))
5384 appendStringInfo(&buf, "%ld", intVal(&con->val));
5387 /* represented as a string, so just copy it */
5388 appendStringInfoString(&buf, strVal(&con->val));
5391 val = strVal(&con->val);
5392 if (typename != NULL)
5395 * Must be a ConstInterval argument for TIME ZONE. Coerce
5396 * to interval and back to normalize the value and account
5404 typoid = typenameTypeId(NULL, typename, &typmod);
5405 Assert(typoid == INTERVALOID);
5408 DirectFunctionCall3(interval_in,
5409 CStringGetDatum(val),
5410 ObjectIdGetDatum(InvalidOid),
5411 Int32GetDatum(typmod));
5414 DatumGetCString(DirectFunctionCall1(interval_out,
5416 appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
5421 * Plain string literal or identifier. For quote mode,
5422 * quote it if it's not a vanilla identifier.
5424 if (flags & GUC_LIST_QUOTE)
5425 appendStringInfoString(&buf, quote_identifier(val));
5427 appendStringInfoString(&buf, val);
5431 elog(ERROR, "unrecognized node type: %d",
5432 (int) nodeTag(&con->val));
5445 ExecSetVariableStmt(VariableSetStmt *stmt)
5447 GucAction action = stmt->is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET;
5452 case VAR_SET_CURRENT:
5453 set_config_option(stmt->name,
5454 ExtractSetVariableArgs(stmt),
5455 (superuser() ? PGC_SUSET : PGC_USERSET),
5463 * Special case for special SQL syntax that effectively sets more
5464 * than one variable per statement.
5466 if (strcmp(stmt->name, "TRANSACTION") == 0)
5470 foreach(head, stmt->args)
5472 DefElem *item = (DefElem *) lfirst(head);
5474 if (strcmp(item->defname, "transaction_isolation") == 0)
5475 SetPGVariable("transaction_isolation",
5476 list_make1(item->arg), stmt->is_local);
5477 else if (strcmp(item->defname, "transaction_read_only") == 0)
5478 SetPGVariable("transaction_read_only",
5479 list_make1(item->arg), stmt->is_local);
5481 elog(ERROR, "unexpected SET TRANSACTION element: %s",
5485 else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
5489 foreach(head, stmt->args)
5491 DefElem *item = (DefElem *) lfirst(head);
5493 if (strcmp(item->defname, "transaction_isolation") == 0)
5494 SetPGVariable("default_transaction_isolation",
5495 list_make1(item->arg), stmt->is_local);
5496 else if (strcmp(item->defname, "transaction_read_only") == 0)
5497 SetPGVariable("default_transaction_read_only",
5498 list_make1(item->arg), stmt->is_local);
5500 elog(ERROR, "unexpected SET SESSION element: %s",
5505 elog(ERROR, "unexpected SET MULTI element: %s",
5508 case VAR_SET_DEFAULT:
5510 set_config_option(stmt->name,
5512 (superuser() ? PGC_SUSET : PGC_USERSET),
5524 * Get the value to assign for a VariableSetStmt, or NULL if it's RESET.
5525 * The result is palloc'd.
5527 * This is exported for use by actions such as ALTER ROLE SET.
5530 ExtractSetVariableArgs(VariableSetStmt *stmt)
5535 return flatten_set_variable_args(stmt->name, stmt->args);
5536 case VAR_SET_CURRENT:
5537 return GetConfigOptionByName(stmt->name, NULL);
5544 * SetPGVariable - SET command exported as an easily-C-callable function.
5546 * This provides access to SET TO value, as well as SET TO DEFAULT (expressed
5547 * by passing args == NIL), but not SET FROM CURRENT functionality.
5550 SetPGVariable(const char *name, List *args, bool is_local)
5552 char *argstring = flatten_set_variable_args(name, args);
5554 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
5555 set_config_option(name,
5557 (superuser() ? PGC_SUSET : PGC_USERSET),
5559 is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET,
5564 * SET command wrapped as a SQL callable function.
5567 set_config_by_name(PG_FUNCTION_ARGS)
5574 if (PG_ARGISNULL(0))
5576 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
5577 errmsg("SET requires parameter name")));
5579 /* Get the GUC variable name */
5580 name = TextDatumGetCString(PG_GETARG_DATUM(0));
5582 /* Get the desired value or set to NULL for a reset request */
5583 if (PG_ARGISNULL(1))
5586 value = TextDatumGetCString(PG_GETARG_DATUM(1));
5589 * Get the desired state of is_local. Default to false if provided value
5592 if (PG_ARGISNULL(2))
5595 is_local = PG_GETARG_BOOL(2);
5597 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
5598 set_config_option(name,
5600 (superuser() ? PGC_SUSET : PGC_USERSET),
5602 is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET,
5605 /* get the new current value */
5606 new_value = GetConfigOptionByName(name, NULL);
5608 /* Convert return string to text */
5609 PG_RETURN_TEXT_P(cstring_to_text(new_value));
5614 * Common code for DefineCustomXXXVariable subroutines: allocate the
5615 * new variable's config struct and fill in generic fields.
5617 static struct config_generic *
5618 init_custom_variable(const char *name,
5619 const char *short_desc,
5620 const char *long_desc,
5623 enum config_type type,
5626 struct config_generic *gen;
5628 gen = (struct config_generic *) guc_malloc(ERROR, sz);
5631 gen->name = guc_strdup(ERROR, name);
5632 gen->context = context;
5633 gen->group = CUSTOM_OPTIONS;
5634 gen->short_desc = short_desc;
5635 gen->long_desc = long_desc;
5637 gen->vartype = type;
5643 * Common code for DefineCustomXXXVariable subroutines: insert the new
5644 * variable into the GUC variable array, replacing any placeholder.
5647 define_custom_variable(struct config_generic * variable)
5649 const char *name = variable->name;
5650 const char **nameAddr = &name;
5652 struct config_string *pHolder;
5653 GucContext phcontext;
5654 struct config_generic **res;
5657 * See if there's a placeholder by the same name.
5659 res = (struct config_generic **) bsearch((void *) &nameAddr,
5660 (void *) guc_variables,
5662 sizeof(struct config_generic *),
5667 * No placeholder to replace, so we can just add it ... but first,
5668 * make sure it's initialized to its default value.
5670 InitializeOneGUCOption(variable);
5671 add_guc_variable(variable, ERROR);
5676 * This better be a placeholder
5678 if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
5680 (errcode(ERRCODE_INTERNAL_ERROR),
5681 errmsg("attempt to redefine parameter \"%s\"", name)));
5683 Assert((*res)->vartype == PGC_STRING);
5684 pHolder = (struct config_string *) (*res);
5687 * First, set the variable to its default value. We must do this even
5688 * though we intend to immediately apply a new value, since it's possible
5689 * that the new value is invalid.
5691 InitializeOneGUCOption(variable);
5694 * Replace the placeholder. We aren't changing the name, so no re-sorting
5700 * Infer context for assignment based on source of existing value.
5701 * We can't tell this with exact accuracy, but we can at least do
5702 * something reasonable in typical cases.
5704 switch (pHolder->gen.source)
5710 phcontext = PGC_SIGHUP;
5712 case PGC_S_DATABASE:
5717 phcontext = PGC_USERSET;
5722 * Assign the string value stored in the placeholder to the real variable.
5724 * XXX this is not really good enough --- it should be a nontransactional
5725 * assignment, since we don't want it to roll back if the current xact
5726 * fails later. (Or do we?)
5728 value = *pHolder->variable;
5731 set_config_option(name, value,
5732 phcontext, pHolder->gen.source,
5733 GUC_ACTION_SET, true);
5736 * Free up as much as we conveniently can of the placeholder structure
5737 * (this neglects any stack items...)
5739 set_string_field(pHolder, pHolder->variable, NULL);
5740 set_string_field(pHolder, &pHolder->reset_val, NULL);
5746 DefineCustomBoolVariable(const char *name,
5747 const char *short_desc,
5748 const char *long_desc,
5753 GucBoolAssignHook assign_hook,
5754 GucShowHook show_hook)
5756 struct config_bool *var;
5758 var = (struct config_bool *)
5759 init_custom_variable(name, short_desc, long_desc, context, flags,
5760 PGC_BOOL, sizeof(struct config_bool));
5761 var->variable = valueAddr;
5762 var->boot_val = bootValue;
5763 var->reset_val = bootValue;
5764 var->assign_hook = assign_hook;
5765 var->show_hook = show_hook;
5766 define_custom_variable(&var->gen);
5770 DefineCustomIntVariable(const char *name,
5771 const char *short_desc,
5772 const char *long_desc,
5779 GucIntAssignHook assign_hook,
5780 GucShowHook show_hook)
5782 struct config_int *var;
5784 var = (struct config_int *)
5785 init_custom_variable(name, short_desc, long_desc, context, flags,
5786 PGC_INT, sizeof(struct config_int));
5787 var->variable = valueAddr;
5788 var->boot_val = bootValue;
5789 var->reset_val = bootValue;
5790 var->min = minValue;
5791 var->max = maxValue;
5792 var->assign_hook = assign_hook;
5793 var->show_hook = show_hook;
5794 define_custom_variable(&var->gen);
5798 DefineCustomRealVariable(const char *name,
5799 const char *short_desc,
5800 const char *long_desc,
5807 GucRealAssignHook assign_hook,
5808 GucShowHook show_hook)
5810 struct config_real *var;
5812 var = (struct config_real *)
5813 init_custom_variable(name, short_desc, long_desc, context, flags,
5814 PGC_REAL, sizeof(struct config_real));
5815 var->variable = valueAddr;
5816 var->boot_val = bootValue;
5817 var->reset_val = bootValue;
5818 var->min = minValue;
5819 var->max = maxValue;
5820 var->assign_hook = assign_hook;
5821 var->show_hook = show_hook;
5822 define_custom_variable(&var->gen);
5826 DefineCustomStringVariable(const char *name,
5827 const char *short_desc,
5828 const char *long_desc,
5830 const char *bootValue,
5833 GucStringAssignHook assign_hook,
5834 GucShowHook show_hook)
5836 struct config_string *var;
5838 var = (struct config_string *)
5839 init_custom_variable(name, short_desc, long_desc, context, flags,
5840 PGC_STRING, sizeof(struct config_string));
5841 var->variable = valueAddr;
5842 var->boot_val = bootValue;
5843 /* we could probably do without strdup, but keep it like normal case */
5845 var->reset_val = guc_strdup(ERROR, var->boot_val);
5846 var->assign_hook = assign_hook;
5847 var->show_hook = show_hook;
5848 define_custom_variable(&var->gen);
5852 DefineCustomEnumVariable(const char *name,
5853 const char *short_desc,
5854 const char *long_desc,
5857 const struct config_enum_entry *options,
5860 GucEnumAssignHook assign_hook,
5861 GucShowHook show_hook)
5863 struct config_enum *var;
5865 var = (struct config_enum *)
5866 init_custom_variable(name, short_desc, long_desc, context, flags,
5867 PGC_ENUM, sizeof(struct config_enum));
5868 var->variable = valueAddr;
5869 var->boot_val = bootValue;
5870 var->reset_val = bootValue;
5871 var->options = options;
5872 var->assign_hook = assign_hook;
5873 var->show_hook = show_hook;
5874 define_custom_variable(&var->gen);
5878 EmitWarningsOnPlaceholders(const char *className)
5880 struct config_generic **vars = guc_variables;
5881 struct config_generic **last = vars + num_guc_variables;
5883 int nameLen = strlen(className);
5887 struct config_generic *var = *vars++;
5889 if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
5890 strncmp(className, var->name, nameLen) == 0 &&
5891 var->name[nameLen] == GUC_QUALIFIER_SEPARATOR)
5894 (errcode(ERRCODE_UNDEFINED_OBJECT),
5895 errmsg("unrecognized configuration parameter \"%s\"", var->name)));
5905 GetPGVariable(const char *name, DestReceiver *dest)
5907 if (guc_name_compare(name, "all") == 0)
5908 ShowAllGUCConfig(dest);
5910 ShowGUCConfigOption(name, dest);
5914 GetPGVariableResultDesc(const char *name)
5918 if (guc_name_compare(name, "all") == 0)
5920 /* need a tuple descriptor representing three TEXT columns */
5921 tupdesc = CreateTemplateTupleDesc(3, false);
5922 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
5924 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
5926 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
5932 const char *varname;
5934 /* Get the canonical spelling of name */
5935 (void) GetConfigOptionByName(name, &varname);
5937 /* need a tuple descriptor representing a single TEXT column */
5938 tupdesc = CreateTemplateTupleDesc(1, false);
5939 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
5950 ShowGUCConfigOption(const char *name, DestReceiver *dest)
5952 TupOutputState *tstate;
5954 const char *varname;
5957 /* Get the value and canonical spelling of name */
5958 value = GetConfigOptionByName(name, &varname);
5960 /* need a tuple descriptor representing a single TEXT column */
5961 tupdesc = CreateTemplateTupleDesc(1, false);
5962 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
5965 /* prepare for projection of tuples */
5966 tstate = begin_tup_output_tupdesc(dest, tupdesc);
5969 do_text_output_oneline(tstate, value);
5971 end_tup_output(tstate);
5978 ShowAllGUCConfig(DestReceiver *dest)
5980 bool am_superuser = superuser();
5982 TupOutputState *tstate;
5986 /* need a tuple descriptor representing three TEXT columns */
5987 tupdesc = CreateTemplateTupleDesc(3, false);
5988 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
5990 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
5992 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
5996 /* prepare for projection of tuples */
5997 tstate = begin_tup_output_tupdesc(dest, tupdesc);
5999 for (i = 0; i < num_guc_variables; i++)
6001 struct config_generic *conf = guc_variables[i];
6003 if ((conf->flags & GUC_NO_SHOW_ALL) ||
6004 ((conf->flags & GUC_SUPERUSER_ONLY) && !am_superuser))
6007 /* assign to the values array */
6008 values[0] = (char *) conf->name;
6009 values[1] = _ShowOption(conf, true);
6010 values[2] = (char *) conf->short_desc;
6012 /* send it to dest */
6013 do_tup_output(tstate, values);
6016 if (values[1] != NULL)
6020 end_tup_output(tstate);
6024 * Return GUC variable value by name; optionally return canonical
6025 * form of name. Return value is palloc'd.
6028 GetConfigOptionByName(const char *name, const char **varname)
6030 struct config_generic *record;
6032 record = find_option(name, false, ERROR);
6035 (errcode(ERRCODE_UNDEFINED_OBJECT),
6036 errmsg("unrecognized configuration parameter \"%s\"", name)));
6037 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
6039 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6040 errmsg("must be superuser to examine \"%s\"", name)));
6043 *varname = record->name;
6045 return _ShowOption(record, true);
6049 * Return GUC variable value by variable number; optionally return canonical
6050 * form of name. Return value is palloc'd.
6053 GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
6056 struct config_generic *conf;
6058 /* check requested variable number valid */
6059 Assert((varnum >= 0) && (varnum < num_guc_variables));
6061 conf = guc_variables[varnum];
6065 if ((conf->flags & GUC_NO_SHOW_ALL) ||
6066 ((conf->flags & GUC_SUPERUSER_ONLY) && !superuser()))
6072 /* first get the generic attributes */
6075 values[0] = conf->name;
6077 /* setting : use _ShowOption in order to avoid duplicating the logic */
6078 values[1] = _ShowOption(conf, false);
6081 if (conf->vartype == PGC_INT)
6085 switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
6090 case GUC_UNIT_BLOCKS:
6091 snprintf(buf, sizeof(buf), "%dkB", BLCKSZ / 1024);
6094 case GUC_UNIT_XBLOCKS:
6095 snprintf(buf, sizeof(buf), "%dkB", XLOG_BLCKSZ / 1024);
6116 values[3] = config_group_names[conf->group];
6119 values[4] = conf->short_desc;
6122 values[5] = conf->long_desc;
6125 values[6] = GucContext_Names[conf->context];
6128 values[7] = config_type_names[conf->vartype];
6131 values[8] = GucSource_Names[conf->source];
6133 /* now get the type specifc attributes */
6134 switch (conf->vartype)
6138 struct config_bool *lconf = (struct config_bool *) conf;
6150 values[12] = pstrdup(lconf->boot_val ? "on" : "off");
6153 values[13] = pstrdup(lconf->reset_val ? "on" : "off");
6159 struct config_int *lconf = (struct config_int *) conf;
6162 snprintf(buffer, sizeof(buffer), "%d", lconf->min);
6163 values[9] = pstrdup(buffer);
6166 snprintf(buffer, sizeof(buffer), "%d", lconf->max);
6167 values[10] = pstrdup(buffer);
6173 snprintf(buffer, sizeof(buffer), "%d", lconf->boot_val);
6174 values[12] = pstrdup(buffer);
6177 snprintf(buffer, sizeof(buffer), "%d", lconf->reset_val);
6178 values[13] = pstrdup(buffer);
6184 struct config_real *lconf = (struct config_real *) conf;
6187 snprintf(buffer, sizeof(buffer), "%g", lconf->min);
6188 values[9] = pstrdup(buffer);
6191 snprintf(buffer, sizeof(buffer), "%g", lconf->max);
6192 values[10] = pstrdup(buffer);
6198 snprintf(buffer, sizeof(buffer), "%g", lconf->boot_val);
6199 values[12] = pstrdup(buffer);
6202 snprintf(buffer, sizeof(buffer), "%g", lconf->reset_val);
6203 values[13] = pstrdup(buffer);
6209 struct config_string *lconf = (struct config_string *) conf;
6221 if (lconf->boot_val == NULL)
6224 values[12] = pstrdup(lconf->boot_val);
6227 if (lconf->reset_val == NULL)
6230 values[13] = pstrdup(lconf->reset_val);
6236 struct config_enum *lconf = (struct config_enum *) conf;
6245 /* NOTE! enumvals with double quotes in them are not supported! */
6246 values[11] = config_enum_get_options((struct config_enum *) conf,
6247 "{\"", "\"}", "\",\"");
6250 values[12] = pstrdup(config_enum_lookup_by_value(lconf,
6254 values[13] = pstrdup(config_enum_lookup_by_value(lconf,
6262 * should never get here, but in case we do, set 'em to NULL
6284 * If the setting came from a config file, set the source location.
6285 * For security reasons, we don't show source file/line number for
6288 if (conf->source == PGC_S_FILE && superuser())
6290 values[14] = conf->sourcefile;
6291 snprintf(buffer, sizeof(buffer), "%d", conf->sourceline);
6292 values[15] = pstrdup(buffer);
6302 * Return the total number of GUC variables
6305 GetNumConfigOptions(void)
6307 return num_guc_variables;
6311 * show_config_by_name - equiv to SHOW X command but implemented as
6315 show_config_by_name(PG_FUNCTION_ARGS)
6320 /* Get the GUC variable name */
6321 varname = TextDatumGetCString(PG_GETARG_DATUM(0));
6324 varval = GetConfigOptionByName(varname, NULL);
6326 /* Convert to text */
6327 PG_RETURN_TEXT_P(cstring_to_text(varval));
6331 * show_all_settings - equiv to SHOW ALL command but implemented as
6334 #define NUM_PG_SETTINGS_ATTS 16
6337 show_all_settings(PG_FUNCTION_ARGS)
6339 FuncCallContext *funcctx;
6343 AttInMetadata *attinmeta;
6344 MemoryContext oldcontext;
6346 /* stuff done only on the first call of the function */
6347 if (SRF_IS_FIRSTCALL())
6349 /* create a function context for cross-call persistence */
6350 funcctx = SRF_FIRSTCALL_INIT();
6353 * switch to memory context appropriate for multiple function calls
6355 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
6358 * need a tuple descriptor representing NUM_PG_SETTINGS_ATTS columns
6359 * of the appropriate types
6361 tupdesc = CreateTemplateTupleDesc(NUM_PG_SETTINGS_ATTS, false);
6362 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
6364 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
6366 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "unit",
6368 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "category",
6370 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "short_desc",
6372 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "extra_desc",
6374 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "context",
6376 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "vartype",
6378 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "source",
6380 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "min_val",
6382 TupleDescInitEntry(tupdesc, (AttrNumber) 11, "max_val",
6384 TupleDescInitEntry(tupdesc, (AttrNumber) 12, "enumvals",
6385 TEXTARRAYOID, -1, 0);
6386 TupleDescInitEntry(tupdesc, (AttrNumber) 13, "boot_val",
6388 TupleDescInitEntry(tupdesc, (AttrNumber) 14, "reset_val",
6390 TupleDescInitEntry(tupdesc, (AttrNumber) 15, "sourcefile",
6392 TupleDescInitEntry(tupdesc, (AttrNumber) 16, "sourceline",
6396 * Generate attribute metadata needed later to produce tuples from raw
6399 attinmeta = TupleDescGetAttInMetadata(tupdesc);
6400 funcctx->attinmeta = attinmeta;
6402 /* total number of tuples to be returned */
6403 funcctx->max_calls = GetNumConfigOptions();
6405 MemoryContextSwitchTo(oldcontext);
6408 /* stuff done on every call of the function */
6409 funcctx = SRF_PERCALL_SETUP();
6411 call_cntr = funcctx->call_cntr;
6412 max_calls = funcctx->max_calls;
6413 attinmeta = funcctx->attinmeta;
6415 if (call_cntr < max_calls) /* do when there is more left to send */
6417 char *values[NUM_PG_SETTINGS_ATTS];
6423 * Get the next visible GUC variable name and value
6427 GetConfigOptionByNum(call_cntr, (const char **) values, &noshow);
6430 /* bump the counter and get the next config setting */
6431 call_cntr = ++funcctx->call_cntr;
6433 /* make sure we haven't gone too far now */
6434 if (call_cntr >= max_calls)
6435 SRF_RETURN_DONE(funcctx);
6440 tuple = BuildTupleFromCStrings(attinmeta, values);
6442 /* make the tuple into a datum */
6443 result = HeapTupleGetDatum(tuple);
6445 SRF_RETURN_NEXT(funcctx, result);
6449 /* do when there is no more left */
6450 SRF_RETURN_DONE(funcctx);
6455 _ShowOption(struct config_generic * record, bool use_units)
6460 switch (record->vartype)
6464 struct config_bool *conf = (struct config_bool *) record;
6466 if (conf->show_hook)
6467 val = (*conf->show_hook) ();
6469 val = *conf->variable ? "on" : "off";
6475 struct config_int *conf = (struct config_int *) record;
6477 if (conf->show_hook)
6478 val = (*conf->show_hook) ();
6482 * Use int64 arithmetic to avoid overflows in units
6483 * conversion. If INT64_IS_BUSTED we might overflow
6484 * anyway and print bogus answers, but there are few
6485 * enough such machines that it doesn't seem worth
6488 int64 result = *conf->variable;
6491 if (use_units && result > 0 &&
6492 (record->flags & GUC_UNIT_MEMORY))
6494 switch (record->flags & GUC_UNIT_MEMORY)
6496 case GUC_UNIT_BLOCKS:
6497 result *= BLCKSZ / 1024;
6499 case GUC_UNIT_XBLOCKS:
6500 result *= XLOG_BLCKSZ / 1024;
6504 if (result % KB_PER_GB == 0)
6506 result /= KB_PER_GB;
6509 else if (result % KB_PER_MB == 0)
6511 result /= KB_PER_MB;
6519 else if (use_units && result > 0 &&
6520 (record->flags & GUC_UNIT_TIME))
6522 switch (record->flags & GUC_UNIT_TIME)
6528 result *= MS_PER_MIN;
6532 if (result % MS_PER_D == 0)
6537 else if (result % MS_PER_H == 0)
6542 else if (result % MS_PER_MIN == 0)
6544 result /= MS_PER_MIN;
6547 else if (result % MS_PER_S == 0)
6560 snprintf(buffer, sizeof(buffer), INT64_FORMAT "%s",
6569 struct config_real *conf = (struct config_real *) record;
6571 if (conf->show_hook)
6572 val = (*conf->show_hook) ();
6575 snprintf(buffer, sizeof(buffer), "%g",
6584 struct config_string *conf = (struct config_string *) record;
6586 if (conf->show_hook)
6587 val = (*conf->show_hook) ();
6588 else if (*conf->variable && **conf->variable)
6589 val = *conf->variable;
6597 struct config_enum *conf = (struct config_enum *) record;
6600 val = (*conf->show_hook) ();
6602 val = config_enum_lookup_by_value(conf, *conf->variable);
6607 /* just to keep compiler quiet */
6612 return pstrdup(val);
6617 * Attempt (badly) to detect if a proposed new GUC setting is the same
6618 * as the current value.
6620 * XXX this does not really work because it doesn't account for the
6621 * effects of canonicalization of string values by assign_hooks.
6624 is_newvalue_equal(struct config_generic * record, const char *newvalue)
6626 /* newvalue == NULL isn't supported */
6627 Assert(newvalue != NULL);
6629 switch (record->vartype)
6633 struct config_bool *conf = (struct config_bool *) record;
6636 return parse_bool(newvalue, &newval)
6637 && *conf->variable == newval;
6641 struct config_int *conf = (struct config_int *) record;
6644 return parse_int(newvalue, &newval, record->flags, NULL)
6645 && *conf->variable == newval;
6649 struct config_real *conf = (struct config_real *) record;
6652 return parse_real(newvalue, &newval)
6653 && *conf->variable == newval;
6657 struct config_string *conf = (struct config_string *) record;
6659 return *conf->variable != NULL &&
6660 strcmp(*conf->variable, newvalue) == 0;
6665 struct config_enum *conf = (struct config_enum *) record;
6668 return config_enum_lookup_by_name(conf, newvalue, &newval) &&
6669 *conf->variable == newval;
6680 * This routine dumps out all non-default GUC options into a binary
6681 * file that is read by all exec'ed backends. The format is:
6683 * variable name, string, null terminated
6684 * variable value, string, null terminated
6685 * variable source, integer
6688 write_nondefault_variables(GucContext context)
6694 Assert(context == PGC_POSTMASTER || context == PGC_SIGHUP);
6696 elevel = (context == PGC_SIGHUP) ? LOG : ERROR;
6701 fp = AllocateFile(CONFIG_EXEC_PARAMS_NEW, "w");
6705 (errcode_for_file_access(),
6706 errmsg("could not write to file \"%s\": %m",
6707 CONFIG_EXEC_PARAMS_NEW)));
6711 for (i = 0; i < num_guc_variables; i++)
6713 struct config_generic *gconf = guc_variables[i];
6715 if (gconf->source != PGC_S_DEFAULT)
6717 fprintf(fp, "%s", gconf->name);
6720 switch (gconf->vartype)
6724 struct config_bool *conf = (struct config_bool *) gconf;
6726 if (*conf->variable == 0)
6727 fprintf(fp, "false");
6729 fprintf(fp, "true");
6735 struct config_int *conf = (struct config_int *) gconf;
6737 fprintf(fp, "%d", *conf->variable);
6743 struct config_real *conf = (struct config_real *) gconf;
6745 /* Could lose precision here? */
6746 fprintf(fp, "%f", *conf->variable);
6752 struct config_string *conf = (struct config_string *) gconf;
6754 fprintf(fp, "%s", *conf->variable);
6760 struct config_enum *conf = (struct config_enum *) gconf;
6762 fprintf(fp, "%s", config_enum_lookup_by_value(conf, *conf->variable));
6769 fwrite(&gconf->source, sizeof(gconf->source), 1, fp);
6776 (errcode_for_file_access(),
6777 errmsg("could not write to file \"%s\": %m",
6778 CONFIG_EXEC_PARAMS_NEW)));
6783 * Put new file in place. This could delay on Win32, but we don't hold
6784 * any exclusive locks.
6786 rename(CONFIG_EXEC_PARAMS_NEW, CONFIG_EXEC_PARAMS);
6791 * Read string, including null byte from file
6793 * Return NULL on EOF and nothing read
6796 read_string_with_null(FILE *fp)
6805 if ((ch = fgetc(fp)) == EOF)
6810 elog(FATAL, "invalid format of exec config params file");
6813 str = guc_malloc(FATAL, maxlen);
6814 else if (i == maxlen)
6815 str = guc_realloc(FATAL, str, maxlen *= 2);
6824 * This routine loads a previous postmaster dump of its non-default
6828 read_nondefault_variables(void)
6838 fp = AllocateFile(CONFIG_EXEC_PARAMS, "r");
6841 /* File not found is fine */
6842 if (errno != ENOENT)
6844 (errcode_for_file_access(),
6845 errmsg("could not read from file \"%s\": %m",
6846 CONFIG_EXEC_PARAMS)));
6852 struct config_generic *record;
6854 if ((varname = read_string_with_null(fp)) == NULL)
6857 if ((record = find_option(varname, true, FATAL)) == NULL)
6858 elog(FATAL, "failed to locate variable %s in exec config params file", varname);
6859 if ((varvalue = read_string_with_null(fp)) == NULL)
6860 elog(FATAL, "invalid format of exec config params file");
6861 if (fread(&varsource, sizeof(varsource), 1, fp) == 0)
6862 elog(FATAL, "invalid format of exec config params file");
6864 (void) set_config_option(varname, varvalue, record->context,
6865 varsource, GUC_ACTION_SET, true);
6872 #endif /* EXEC_BACKEND */
6876 * A little "long argument" simulation, although not quite GNU
6877 * compliant. Takes a string of the form "some-option=some value" and
6878 * returns name = "some_option" and value = "some value" in malloc'ed
6879 * storage. Note that '-' is converted to '_' in the option name. If
6880 * there is no '=' in the input string then value will be NULL.
6883 ParseLongOption(const char *string, char **name, char **value)
6892 equal_pos = strcspn(string, "=");
6894 if (string[equal_pos] == '=')
6896 *name = guc_malloc(FATAL, equal_pos + 1);
6897 strlcpy(*name, string, equal_pos + 1);
6899 *value = guc_strdup(FATAL, &string[equal_pos + 1]);
6903 /* no equal sign in string */
6904 *name = guc_strdup(FATAL, string);
6908 for (cp = *name; *cp; cp++)
6915 * Handle options fetched from pg_database.datconfig, pg_authid.rolconfig,
6916 * pg_proc.proconfig, etc. Caller must specify proper context/source/action.
6918 * The array parameter must be an array of TEXT (it must not be NULL).
6921 ProcessGUCArray(ArrayType *array,
6922 GucContext context, GucSource source, GucAction action)
6926 Assert(array != NULL);
6927 Assert(ARR_ELEMTYPE(array) == TEXTOID);
6928 Assert(ARR_NDIM(array) == 1);
6929 Assert(ARR_LBOUND(array)[0] == 1);
6931 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
6939 d = array_ref(array, 1, &i,
6940 -1 /* varlenarray */ ,
6941 -1 /* TEXT's typlen */ ,
6942 false /* TEXT's typbyval */ ,
6943 'i' /* TEXT's typalign */ ,
6949 s = TextDatumGetCString(d);
6951 ParseLongOption(s, &name, &value);
6955 (errcode(ERRCODE_SYNTAX_ERROR),
6956 errmsg("could not parse setting for parameter \"%s\"",
6962 (void) set_config_option(name, value, context, source, action, true);
6972 * Add an entry to an option array. The array parameter may be NULL
6973 * to indicate the current table entry is NULL.
6976 GUCArrayAdd(ArrayType *array, const char *name, const char *value)
6978 const char *varname;
6986 /* test if the option is valid */
6987 set_config_option(name, value,
6988 superuser() ? PGC_SUSET : PGC_USERSET,
6989 PGC_S_TEST, GUC_ACTION_SET, false);
6991 /* convert name to canonical spelling, so we can use plain strcmp */
6992 (void) GetConfigOptionByName(name, &varname);
6995 newval = palloc(strlen(name) + 1 + strlen(value) + 1);
6996 sprintf(newval, "%s=%s", name, value);
6997 datum = CStringGetTextDatum(newval);
7005 Assert(ARR_ELEMTYPE(array) == TEXTOID);
7006 Assert(ARR_NDIM(array) == 1);
7007 Assert(ARR_LBOUND(array)[0] == 1);
7009 index = ARR_DIMS(array)[0] + 1; /* add after end */
7011 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
7016 d = array_ref(array, 1, &i,
7017 -1 /* varlenarray */ ,
7018 -1 /* TEXT's typlen */ ,
7019 false /* TEXT's typbyval */ ,
7020 'i' /* TEXT's typalign */ ,
7024 current = TextDatumGetCString(d);
7025 if (strncmp(current, newval, strlen(name) + 1) == 0)
7032 a = array_set(array, 1, &index,
7035 -1 /* varlena array */ ,
7036 -1 /* TEXT's typlen */ ,
7037 false /* TEXT's typbyval */ ,
7038 'i' /* TEXT's typalign */ );
7041 a = construct_array(&datum, 1,
7050 * Delete an entry from an option array. The array parameter may be NULL
7051 * to indicate the current table entry is NULL. Also, if the return value
7052 * is NULL then a null should be stored.
7055 GUCArrayDelete(ArrayType *array, const char *name)
7057 const char *varname;
7058 ArrayType *newarray;
7064 /* test if the option is valid */
7065 set_config_option(name, NULL,
7066 superuser() ? PGC_SUSET : PGC_USERSET,
7067 PGC_S_TEST, GUC_ACTION_SET, false);
7069 /* convert name to canonical spelling, so we can use plain strcmp */
7070 (void) GetConfigOptionByName(name, &varname);
7073 /* if array is currently null, then surely nothing to delete */
7080 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
7086 d = array_ref(array, 1, &i,
7087 -1 /* varlenarray */ ,
7088 -1 /* TEXT's typlen */ ,
7089 false /* TEXT's typbyval */ ,
7090 'i' /* TEXT's typalign */ ,
7094 val = TextDatumGetCString(d);
7096 /* ignore entry if it's what we want to delete */
7097 if (strncmp(val, name, strlen(name)) == 0
7098 && val[strlen(name)] == '=')
7101 /* else add it to the output array */
7104 newarray = array_set(newarray, 1, &index,
7107 -1 /* varlenarray */ ,
7108 -1 /* TEXT's typlen */ ,
7109 false /* TEXT's typbyval */ ,
7110 'i' /* TEXT's typalign */ );
7113 newarray = construct_array(&d, 1,
7125 * assign_hook and show_hook subroutines
7129 assign_log_destination(const char *value, bool doit, GucSource source)
7136 /* Need a modifiable copy of string */
7137 rawstring = pstrdup(value);
7139 /* Parse string into list of identifiers */
7140 if (!SplitIdentifierString(rawstring, ',', &elemlist))
7142 /* syntax error in list */
7144 list_free(elemlist);
7145 ereport(GUC_complaint_elevel(source),
7146 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7147 errmsg("invalid list syntax for parameter \"log_destination\"")));
7151 foreach(l, elemlist)
7153 char *tok = (char *) lfirst(l);
7155 if (pg_strcasecmp(tok, "stderr") == 0)
7156 newlogdest |= LOG_DESTINATION_STDERR;
7157 else if (pg_strcasecmp(tok, "csvlog") == 0)
7158 newlogdest |= LOG_DESTINATION_CSVLOG;
7160 else if (pg_strcasecmp(tok, "syslog") == 0)
7161 newlogdest |= LOG_DESTINATION_SYSLOG;
7164 else if (pg_strcasecmp(tok, "eventlog") == 0)
7165 newlogdest |= LOG_DESTINATION_EVENTLOG;
7169 ereport(GUC_complaint_elevel(source),
7170 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7171 errmsg("unrecognized \"log_destination\" key word: \"%s\"",
7174 list_free(elemlist);
7180 Log_destination = newlogdest;
7183 list_free(elemlist);
7191 assign_syslog_facility(int newval, bool doit, GucSource source)
7194 set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
7201 assign_syslog_ident(const char *ident, bool doit, GucSource source)
7204 set_syslog_parameters(ident, syslog_facility);
7208 #endif /* HAVE_SYSLOG */
7212 assign_session_replication_role(int newval, bool doit, GucSource source)
7215 * Must flush the plan cache when changing replication role; but don't
7216 * flush unnecessarily.
7218 if (doit && SessionReplicationRole != newval)
7227 show_num_temp_buffers(void)
7230 * We show the GUC var until local buffers have been initialized, and
7231 * NLocBuffer afterwards.
7233 static char nbuf[32];
7235 sprintf(nbuf, "%d", NLocBuffer ? NLocBuffer : num_temp_buffers);
7240 assign_phony_autocommit(bool newval, bool doit, GucSource source)
7244 ereport(GUC_complaint_elevel(source),
7245 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7246 errmsg("SET AUTOCOMMIT TO OFF is no longer supported")));
7253 assign_custom_variable_classes(const char *newval, bool doit, GucSource source)
7256 * Check syntax. newval must be a comma separated list of identifiers.
7257 * Whitespace is allowed but removed from the result.
7259 bool hasSpaceAfterToken = false;
7260 const char *cp = newval;
7265 initStringInfo(&buf);
7266 while ((c = *cp++) != '\0')
7268 if (isspace((unsigned char) c))
7271 hasSpaceAfterToken = true;
7277 if (symLen > 0) /* terminate identifier */
7279 appendStringInfoChar(&buf, ',');
7282 hasSpaceAfterToken = false;
7286 if (hasSpaceAfterToken || !isalnum((unsigned char) c))
7289 * Syntax error due to token following space after token or non
7290 * alpha numeric character
7295 appendStringInfoChar(&buf, c);
7299 /* Remove stray ',' at end */
7300 if (symLen == 0 && buf.len > 0)
7301 buf.data[--buf.len] = '\0';
7303 /* GUC wants the result malloc'd */
7304 newval = guc_strdup(LOG, buf.data);
7311 assign_debug_assertions(bool newval, bool doit, GucSource source)
7313 #ifndef USE_ASSERT_CHECKING
7316 ereport(GUC_complaint_elevel(source),
7317 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7318 errmsg("assertion checking is not supported by this build")));
7326 assign_ssl(bool newval, bool doit, GucSource source)
7331 ereport(GUC_complaint_elevel(source),
7332 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7333 errmsg("SSL is not supported by this build")));
7341 assign_stage_log_stats(bool newval, bool doit, GucSource source)
7343 if (newval && log_statement_stats)
7345 ereport(GUC_complaint_elevel(source),
7346 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7347 errmsg("cannot enable parameter when \"log_statement_stats\" is true")));
7348 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
7349 if (source != PGC_S_OVERRIDE)
7356 assign_log_stats(bool newval, bool doit, GucSource source)
7359 (log_parser_stats || log_planner_stats || log_executor_stats))
7361 ereport(GUC_complaint_elevel(source),
7362 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7363 errmsg("cannot enable \"log_statement_stats\" when "
7364 "\"log_parser_stats\", \"log_planner_stats\", "
7365 "or \"log_executor_stats\" is true")));
7366 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
7367 if (source != PGC_S_OVERRIDE)
7374 assign_transaction_read_only(bool newval, bool doit, GucSource source)
7376 /* Can't go to r/w mode inside a r/o transaction */
7377 if (newval == false && XactReadOnly && IsSubTransaction())
7379 ereport(GUC_complaint_elevel(source),
7380 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7381 errmsg("cannot set transaction read-write mode inside a read-only transaction")));
7382 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
7383 if (source != PGC_S_OVERRIDE)
7390 assign_canonical_path(const char *newval, bool doit, GucSource source)
7394 char *canon_val = guc_strdup(ERROR, newval);
7396 canonicalize_path(canon_val);
7404 assign_timezone_abbreviations(const char *newval, bool doit, GucSource source)
7407 * The powerup value shown above for timezone_abbreviations is "UNKNOWN".
7408 * When we see this we just do nothing. If this value isn't overridden
7409 * from the config file then pg_timezone_abbrev_initialize() will
7410 * eventually replace it with "Default". This hack has two purposes: to
7411 * avoid wasting cycles loading values that might soon be overridden from
7412 * the config file, and to avoid trying to read the timezone abbrev files
7413 * during InitializeGUCOptions(). The latter doesn't work in an
7414 * EXEC_BACKEND subprocess because my_exec_path hasn't been set yet and so
7415 * we can't locate PGSHAREDIR. (Essentially the same hack is used to
7416 * delay initializing TimeZone ... if we have any more, we should try to
7417 * clean up and centralize this mechanism ...)
7419 if (strcmp(newval, "UNKNOWN") == 0)
7424 /* Loading abbrev file is expensive, so only do it when value changes */
7425 if (timezone_abbreviations_string == NULL ||
7426 strcmp(timezone_abbreviations_string, newval) != 0)
7431 * If reading config file, only the postmaster should bleat loudly
7432 * about problems. Otherwise, it's just this one process doing it,
7433 * and we use WARNING message level.
7435 if (source == PGC_S_FILE)
7436 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
7439 if (!load_tzoffsets(newval, doit, elevel))
7446 * pg_timezone_abbrev_initialize --- set default value if not done already
7448 * This is called after initial loading of postgresql.conf. If no
7449 * timezone_abbreviations setting was found therein, select default.
7452 pg_timezone_abbrev_initialize(void)
7454 if (strcmp(timezone_abbreviations_string, "UNKNOWN") == 0)
7456 SetConfigOption("timezone_abbreviations", "Default",
7457 PGC_POSTMASTER, PGC_S_ARGV);
7462 show_archive_command(void)
7464 if (XLogArchiveMode)
7465 return XLogArchiveCommand;
7467 return "(disabled)";
7471 assign_tcp_keepalives_idle(int newval, bool doit, GucSource source)
7474 return (pq_setkeepalivesidle(newval, MyProcPort) == STATUS_OK);
7480 show_tcp_keepalives_idle(void)
7482 static char nbuf[16];
7484 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesidle(MyProcPort));
7489 assign_tcp_keepalives_interval(int newval, bool doit, GucSource source)
7492 return (pq_setkeepalivesinterval(newval, MyProcPort) == STATUS_OK);
7498 show_tcp_keepalives_interval(void)
7500 static char nbuf[16];
7502 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesinterval(MyProcPort));
7507 assign_tcp_keepalives_count(int newval, bool doit, GucSource source)
7510 return (pq_setkeepalivescount(newval, MyProcPort) == STATUS_OK);
7516 show_tcp_keepalives_count(void)
7518 static char nbuf[16];
7520 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivescount(MyProcPort));
7525 assign_maxconnections(int newval, bool doit, GucSource source)
7527 if (newval + autovacuum_max_workers > INT_MAX / 4)
7531 MaxBackends = newval + autovacuum_max_workers;
7537 assign_autovacuum_max_workers(int newval, bool doit, GucSource source)
7539 if (newval + MaxConnections > INT_MAX / 4)
7543 MaxBackends = newval + MaxConnections;
7549 assign_pgstat_temp_directory(const char *newval, bool doit, GucSource source)
7553 if (pgstat_stat_tmpname)
7554 free(pgstat_stat_tmpname);
7555 if (pgstat_stat_filename)
7556 free(pgstat_stat_filename);
7558 pgstat_stat_tmpname = guc_malloc(FATAL, strlen(newval) + 12); /* /pgstat.tmp */
7559 pgstat_stat_filename = guc_malloc(FATAL, strlen(newval) + 13); /* /pgstat.stat */
7561 sprintf(pgstat_stat_tmpname, "%s/pgstat.tmp", newval);
7562 sprintf(pgstat_stat_filename, "%s/pgstat.stat", newval);
7568 #include "guc-file.c"