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-2007, PostgreSQL Global Development Group
10 * Written by Peter Eisentraut <peter_e@gmx.net>.
13 * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.411 2007/08/08 16:00:46 tgl Exp $
15 *--------------------------------------------------------------------
29 #include "access/gin.h"
30 #include "access/transam.h"
31 #include "access/twophase.h"
32 #include "access/xact.h"
33 #include "catalog/namespace.h"
34 #include "commands/async.h"
35 #include "commands/prepare.h"
36 #include "commands/vacuum.h"
37 #include "commands/variable.h"
38 #include "commands/trigger.h"
40 #include "libpq/auth.h"
41 #include "libpq/pqformat.h"
42 #include "miscadmin.h"
43 #include "optimizer/cost.h"
44 #include "optimizer/geqo.h"
45 #include "optimizer/paths.h"
46 #include "optimizer/planmain.h"
47 #include "parser/gramparse.h"
48 #include "parser/parse_expr.h"
49 #include "parser/parse_relation.h"
50 #include "parser/parse_type.h"
51 #include "parser/scansup.h"
53 #include "postmaster/autovacuum.h"
54 #include "postmaster/bgwriter.h"
55 #include "postmaster/postmaster.h"
56 #include "postmaster/syslogger.h"
57 #include "postmaster/walwriter.h"
58 #include "storage/fd.h"
59 #include "storage/freespace.h"
60 #include "tcop/tcopprot.h"
61 #include "utils/builtins.h"
62 #include "utils/guc_tables.h"
63 #include "utils/memutils.h"
64 #include "utils/pg_locale.h"
65 #include "utils/plancache.h"
66 #include "utils/portal.h"
67 #include "utils/ps_status.h"
68 #include "utils/tzparser.h"
69 #include "utils/xml.h"
72 #define PG_KRB_SRVTAB ""
75 #define PG_KRB_SRVNAM ""
78 #define CONFIG_FILENAME "postgresql.conf"
79 #define HBA_FILENAME "pg_hba.conf"
80 #define IDENT_FILENAME "pg_ident.conf"
83 #define CONFIG_EXEC_PARAMS "global/config_exec_params"
84 #define CONFIG_EXEC_PARAMS_NEW "global/config_exec_params.new"
87 /* upper limit for GUC variables measured in kilobytes of memory */
89 #define MAX_KILOBYTES INT_MAX
91 #define MAX_KILOBYTES (INT_MAX / 1024)
94 #define KB_PER_MB (1024)
95 #define KB_PER_GB (1024*1024)
99 #define MS_PER_MIN (1000 * 60)
101 #define S_PER_H (60 * 60)
102 #define MS_PER_H (1000 * 60 * 60)
103 #define MIN_PER_D (60 * 24)
104 #define S_PER_D (60 * 60 * 24)
105 #define MS_PER_D (1000 * 60 * 60 * 24)
107 /* XXX these should appear in other modules' header files */
108 extern bool Log_disconnections;
109 extern int CommitDelay;
110 extern int CommitSiblings;
111 extern char *default_tablespace;
112 extern char *temp_tablespaces;
113 extern bool fullPageWrites;
116 extern bool trace_sort;
118 #ifdef TRACE_SYNCSCAN
119 extern bool trace_syncscan;
121 #ifdef DEBUG_BOUNDED_SORT
122 extern bool optimize_bounded_sort;
126 extern char *SSLCipherSuites;
130 static const char *assign_log_destination(const char *value,
131 bool doit, GucSource source);
134 static int syslog_facility = LOG_LOCAL0;
136 static const char *assign_syslog_facility(const char *facility,
137 bool doit, GucSource source);
138 static const char *assign_syslog_ident(const char *ident,
139 bool doit, GucSource source);
142 static const char *assign_defaultxactisolevel(const char *newval, bool doit,
144 static const char *assign_session_replication_role(const char *newval, bool doit,
146 static const char *assign_log_min_messages(const char *newval, bool doit,
148 static const char *assign_client_min_messages(const char *newval,
149 bool doit, GucSource source);
150 static const char *assign_min_error_statement(const char *newval, bool doit,
152 static const char *assign_msglvl(int *var, const char *newval, bool doit,
154 static const char *assign_log_error_verbosity(const char *newval, bool doit,
156 static const char *assign_log_statement(const char *newval, bool doit,
158 static const char *show_num_temp_buffers(void);
159 static bool assign_phony_autocommit(bool newval, bool doit, GucSource source);
160 static const char *assign_custom_variable_classes(const char *newval, bool doit,
162 static bool assign_debug_assertions(bool newval, bool doit, GucSource source);
163 static bool assign_ssl(bool newval, bool doit, GucSource source);
164 static bool assign_stage_log_stats(bool newval, bool doit, GucSource source);
165 static bool assign_log_stats(bool newval, bool doit, GucSource source);
166 static bool assign_transaction_read_only(bool newval, bool doit, GucSource source);
167 static const char *assign_canonical_path(const char *newval, bool doit, GucSource source);
168 static const char *assign_backslash_quote(const char *newval, bool doit, GucSource source);
169 static const char *assign_timezone_abbreviations(const char *newval, bool doit, GucSource source);
170 static const char *assign_xmlbinary(const char *newval, bool doit, GucSource source);
171 static const char *assign_xmloption(const char *newval, bool doit, GucSource source);
173 static bool assign_tcp_keepalives_idle(int newval, bool doit, GucSource source);
174 static bool assign_tcp_keepalives_interval(int newval, bool doit, GucSource source);
175 static bool assign_tcp_keepalives_count(int newval, bool doit, GucSource source);
176 static const char *show_tcp_keepalives_idle(void);
177 static const char *show_tcp_keepalives_interval(void);
178 static const char *show_tcp_keepalives_count(void);
179 static bool assign_autovacuum_max_workers(int newval, bool doit, GucSource source);
180 static bool assign_maxconnections(int newval, bool doit, GucSource source);
183 * GUC option variables that are exported from this module
185 #ifdef USE_ASSERT_CHECKING
186 bool assert_enabled = true;
188 bool assert_enabled = false;
190 bool log_duration = false;
191 bool Debug_print_plan = false;
192 bool Debug_print_parse = false;
193 bool Debug_print_rewritten = false;
194 bool Debug_pretty_print = false;
195 bool Explain_pretty_print = true;
197 bool log_parser_stats = false;
198 bool log_planner_stats = false;
199 bool log_executor_stats = false;
200 bool log_statement_stats = false; /* this is sort of all three
202 bool log_btree_build_stats = false;
204 bool check_function_bodies = true;
205 bool default_with_oids = false;
206 bool SQL_inheritance = true;
208 bool Password_encryption = true;
210 int log_min_error_statement = ERROR;
211 int log_min_messages = NOTICE;
212 int client_min_messages = NOTICE;
213 int log_min_duration_statement = -1;
214 int log_temp_files = -1;
216 int num_temp_buffers = 1000;
218 char *ConfigFileName;
221 char *external_pid_file;
223 int tcp_keepalives_idle;
224 int tcp_keepalives_interval;
225 int tcp_keepalives_count;
228 * These variables are all dummies that don't do anything, except in some
229 * cases provide the value for SHOW to display. The real state is elsewhere
230 * and is kept in sync by assign_hooks.
232 static char *client_min_messages_str;
233 static char *log_min_messages_str;
234 static char *log_error_verbosity_str;
235 static char *log_statement_str;
236 static char *log_min_error_statement_str;
237 static char *log_destination_string;
240 static char *syslog_facility_str;
241 static char *syslog_ident_str;
243 static bool phony_autocommit;
244 static bool session_auth_is_superuser;
245 static double phony_random_seed;
246 static char *backslash_quote_string;
247 static char *client_encoding_string;
248 static char *datestyle_string;
249 static char *default_iso_level_string;
250 static char *session_replication_role_string;
251 static char *locale_collate;
252 static char *locale_ctype;
253 static char *regex_flavor_string;
254 static char *server_encoding_string;
255 static char *server_version_string;
256 static int server_version_num;
257 static char *timezone_string;
258 static char *log_timezone_string;
259 static char *timezone_abbreviations_string;
260 static char *XactIsoLevel_string;
261 static char *data_directory;
262 static char *custom_variable_classes;
263 static char *xmlbinary_string;
264 static char *xmloption_string;
265 static int max_function_args;
266 static int max_index_keys;
267 static int max_identifier_length;
268 static int block_size;
269 static bool integer_datetimes;
271 /* should be static, but commands/variable.c needs to get at these */
273 char *session_authorization_string;
277 * Displayable names for context types (enum GucContext)
279 * Note: these strings are deliberately not localized.
281 const char *const GucContext_Names[] =
283 /* PGC_INTERNAL */ "internal",
284 /* PGC_POSTMASTER */ "postmaster",
285 /* PGC_SIGHUP */ "sighup",
286 /* PGC_BACKEND */ "backend",
287 /* PGC_SUSET */ "superuser",
288 /* PGC_USERSET */ "user"
292 * Displayable names for source types (enum GucSource)
294 * Note: these strings are deliberately not localized.
296 const char *const GucSource_Names[] =
298 /* PGC_S_DEFAULT */ "default",
299 /* PGC_S_ENV_VAR */ "environment variable",
300 /* PGC_S_FILE */ "configuration file",
301 /* PGC_S_ARGV */ "command line",
302 /* PGC_S_DATABASE */ "database",
303 /* PGC_S_USER */ "user",
304 /* PGC_S_CLIENT */ "client",
305 /* PGC_S_OVERRIDE */ "override",
306 /* PGC_S_INTERACTIVE */ "interactive",
307 /* PGC_S_TEST */ "test",
308 /* PGC_S_SESSION */ "session"
312 * Displayable names for the groupings defined in enum config_group
314 const char *const config_group_names[] =
317 gettext_noop("Ungrouped"),
319 gettext_noop("File Locations"),
321 gettext_noop("Connections and Authentication"),
322 /* CONN_AUTH_SETTINGS */
323 gettext_noop("Connections and Authentication / Connection Settings"),
324 /* CONN_AUTH_SECURITY */
325 gettext_noop("Connections and Authentication / Security and Authentication"),
327 gettext_noop("Resource Usage"),
329 gettext_noop("Resource Usage / Memory"),
331 gettext_noop("Resource Usage / Free Space Map"),
332 /* RESOURCES_KERNEL */
333 gettext_noop("Resource Usage / Kernel Resources"),
335 gettext_noop("Write-Ahead Log"),
337 gettext_noop("Write-Ahead Log / Settings"),
338 /* WAL_CHECKPOINTS */
339 gettext_noop("Write-Ahead Log / Checkpoints"),
341 gettext_noop("Query Tuning"),
342 /* QUERY_TUNING_METHOD */
343 gettext_noop("Query Tuning / Planner Method Configuration"),
344 /* QUERY_TUNING_COST */
345 gettext_noop("Query Tuning / Planner Cost Constants"),
346 /* QUERY_TUNING_GEQO */
347 gettext_noop("Query Tuning / Genetic Query Optimizer"),
348 /* QUERY_TUNING_OTHER */
349 gettext_noop("Query Tuning / Other Planner Options"),
351 gettext_noop("Reporting and Logging"),
353 gettext_noop("Reporting and Logging / Where to Log"),
355 gettext_noop("Reporting and Logging / When to Log"),
357 gettext_noop("Reporting and Logging / What to Log"),
359 gettext_noop("Statistics"),
360 /* STATS_MONITORING */
361 gettext_noop("Statistics / Monitoring"),
362 /* STATS_COLLECTOR */
363 gettext_noop("Statistics / Query and Index Statistics Collector"),
365 gettext_noop("Autovacuum"),
367 gettext_noop("Client Connection Defaults"),
368 /* CLIENT_CONN_STATEMENT */
369 gettext_noop("Client Connection Defaults / Statement Behavior"),
370 /* CLIENT_CONN_LOCALE */
371 gettext_noop("Client Connection Defaults / Locale and Formatting"),
372 /* CLIENT_CONN_OTHER */
373 gettext_noop("Client Connection Defaults / Other Defaults"),
374 /* LOCK_MANAGEMENT */
375 gettext_noop("Lock Management"),
377 gettext_noop("Version and Platform Compatibility"),
378 /* COMPAT_OPTIONS_PREVIOUS */
379 gettext_noop("Version and Platform Compatibility / Previous PostgreSQL Versions"),
380 /* COMPAT_OPTIONS_CLIENT */
381 gettext_noop("Version and Platform Compatibility / Other Platforms and Clients"),
383 gettext_noop("Preset Options"),
385 gettext_noop("Customized Options"),
386 /* DEVELOPER_OPTIONS */
387 gettext_noop("Developer Options"),
388 /* help_config wants this array to be null-terminated */
393 * Displayable names for GUC variable types (enum config_type)
395 * Note: these strings are deliberately not localized.
397 const char *const config_type_names[] =
399 /* PGC_BOOL */ "bool",
400 /* PGC_INT */ "integer",
401 /* PGC_REAL */ "real",
402 /* PGC_STRING */ "string"
407 * Contents of GUC tables
409 * See src/backend/utils/misc/README for design notes.
413 * 1. Declare a global variable of type bool, int, double, or char*
414 * and make use of it.
416 * 2. Decide at what times it's safe to set the option. See guc.h for
419 * 3. Decide on a name, a default value, upper and lower bounds (if
422 * 4. Add a record below.
424 * 5. Add it to src/backend/utils/misc/postgresql.conf.sample, if
427 * 6. Don't forget to document the option.
429 * 7. If it's a new GUC_LIST option you must edit pg_dumpall.c to ensure
430 * it is not single quoted at dump time.
434 /******** option records follow ********/
436 static struct config_bool ConfigureNamesBool[] =
439 {"enable_seqscan", PGC_USERSET, QUERY_TUNING_METHOD,
440 gettext_noop("Enables the planner's use of sequential-scan plans."),
447 {"enable_indexscan", PGC_USERSET, QUERY_TUNING_METHOD,
448 gettext_noop("Enables the planner's use of index-scan plans."),
455 {"enable_bitmapscan", PGC_USERSET, QUERY_TUNING_METHOD,
456 gettext_noop("Enables the planner's use of bitmap-scan plans."),
463 {"enable_tidscan", PGC_USERSET, QUERY_TUNING_METHOD,
464 gettext_noop("Enables the planner's use of TID scan plans."),
471 {"enable_sort", PGC_USERSET, QUERY_TUNING_METHOD,
472 gettext_noop("Enables the planner's use of explicit sort steps."),
479 {"enable_hashagg", PGC_USERSET, QUERY_TUNING_METHOD,
480 gettext_noop("Enables the planner's use of hashed aggregation plans."),
487 {"enable_nestloop", PGC_USERSET, QUERY_TUNING_METHOD,
488 gettext_noop("Enables the planner's use of nested-loop join plans."),
495 {"enable_mergejoin", PGC_USERSET, QUERY_TUNING_METHOD,
496 gettext_noop("Enables the planner's use of merge join plans."),
503 {"enable_hashjoin", PGC_USERSET, QUERY_TUNING_METHOD,
504 gettext_noop("Enables the planner's use of hash join plans."),
511 {"constraint_exclusion", PGC_USERSET, QUERY_TUNING_OTHER,
512 gettext_noop("Enables the planner to use constraints to optimize queries."),
513 gettext_noop("Child table scans will be skipped if their "
514 "constraints guarantee that no rows match the query.")
516 &constraint_exclusion,
520 {"geqo", PGC_USERSET, QUERY_TUNING_GEQO,
521 gettext_noop("Enables genetic query optimization."),
522 gettext_noop("This algorithm attempts to do planning without "
523 "exhaustive searching.")
529 /* Not for general use --- used by SET SESSION AUTHORIZATION */
530 {"is_superuser", PGC_INTERNAL, UNGROUPED,
531 gettext_noop("Shows whether the current user is a superuser."),
533 GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
535 &session_auth_is_superuser,
539 {"ssl", PGC_POSTMASTER, CONN_AUTH_SECURITY,
540 gettext_noop("Enables SSL connections."),
544 false, assign_ssl, NULL
547 {"fsync", PGC_SIGHUP, WAL_SETTINGS,
548 gettext_noop("Forces synchronization of updates to disk."),
549 gettext_noop("The server will use the fsync() system call in several places to make "
550 "sure that updates are physically written to disk. This insures "
551 "that a database cluster will recover to a consistent state after "
552 "an operating system or hardware crash.")
558 {"synchronous_commit", PGC_USERSET, WAL_SETTINGS,
559 gettext_noop("Sets immediate fsync at commit."),
566 {"zero_damaged_pages", PGC_SUSET, DEVELOPER_OPTIONS,
567 gettext_noop("Continues processing past damaged page headers."),
568 gettext_noop("Detection of a damaged page header normally causes PostgreSQL to "
569 "report an error, aborting the current transaction. Setting "
570 "zero_damaged_pages to true causes the system to instead report a "
571 "warning, zero out the damaged page, and continue processing. This "
572 "behavior will destroy data, namely all the rows on the damaged page."),
579 {"full_page_writes", PGC_SIGHUP, WAL_SETTINGS,
580 gettext_noop("Writes full pages to WAL when first modified after a checkpoint."),
581 gettext_noop("A page write in process during an operating system crash might be "
582 "only partially written to disk. During recovery, the row changes "
583 "stored in WAL are not enough to recover. This option writes "
584 "pages when first modified after a checkpoint to WAL so full recovery "
591 {"silent_mode", PGC_POSTMASTER, LOGGING_WHEN,
592 gettext_noop("Runs the server silently."),
593 gettext_noop("If this parameter is set, the server will automatically run in the "
594 "background and any controlling terminals are dissociated.")
600 {"log_checkpoints", PGC_SIGHUP, LOGGING_WHAT,
601 gettext_noop("Logs each checkpoint."),
608 {"log_connections", PGC_BACKEND, LOGGING_WHAT,
609 gettext_noop("Logs each successful connection."),
616 {"log_disconnections", PGC_BACKEND, LOGGING_WHAT,
617 gettext_noop("Logs end of a session, including duration."),
624 {"debug_assertions", PGC_USERSET, DEVELOPER_OPTIONS,
625 gettext_noop("Turns on various assertion checks."),
626 gettext_noop("This is a debugging aid."),
630 #ifdef USE_ASSERT_CHECKING
635 assign_debug_assertions, NULL
638 /* currently undocumented, so don't show in SHOW ALL */
639 {"exit_on_error", PGC_USERSET, UNGROUPED,
640 gettext_noop("No description available."),
642 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
648 {"log_duration", PGC_SUSET, LOGGING_WHAT,
649 gettext_noop("Logs the duration of each completed SQL statement."),
656 {"debug_print_parse", PGC_USERSET, LOGGING_WHAT,
657 gettext_noop("Prints the parse tree to the server log."),
664 {"debug_print_rewritten", PGC_USERSET, LOGGING_WHAT,
665 gettext_noop("Prints the parse tree after rewriting to server log."),
668 &Debug_print_rewritten,
672 {"debug_print_plan", PGC_USERSET, LOGGING_WHAT,
673 gettext_noop("Prints the execution plan to server log."),
680 {"debug_pretty_print", PGC_USERSET, LOGGING_WHAT,
681 gettext_noop("Indents parse and plan tree displays."),
688 {"log_parser_stats", PGC_SUSET, STATS_MONITORING,
689 gettext_noop("Writes parser performance statistics to the server log."),
693 false, assign_stage_log_stats, NULL
696 {"log_planner_stats", PGC_SUSET, STATS_MONITORING,
697 gettext_noop("Writes planner performance statistics to the server log."),
701 false, assign_stage_log_stats, NULL
704 {"log_executor_stats", PGC_SUSET, STATS_MONITORING,
705 gettext_noop("Writes executor performance statistics to the server log."),
709 false, assign_stage_log_stats, NULL
712 {"log_statement_stats", PGC_SUSET, STATS_MONITORING,
713 gettext_noop("Writes cumulative performance statistics to the server log."),
716 &log_statement_stats,
717 false, assign_log_stats, NULL
719 #ifdef BTREE_BUILD_STATS
721 {"log_btree_build_stats", PGC_SUSET, DEVELOPER_OPTIONS,
722 gettext_noop("No description available."),
726 &log_btree_build_stats,
732 {"explain_pretty_print", PGC_USERSET, CLIENT_CONN_OTHER,
733 gettext_noop("Uses the indented output format for EXPLAIN VERBOSE."),
736 &Explain_pretty_print,
740 {"stats_start_collector", PGC_POSTMASTER, STATS_COLLECTOR,
741 gettext_noop("Starts the server statistics-collection subprocess."),
744 &pgstat_collect_startcollector,
748 {"stats_reset_on_server_start", PGC_POSTMASTER, STATS_COLLECTOR,
749 gettext_noop("Zeroes collected statistics on server restart."),
752 &pgstat_collect_resetonpmstart,
756 {"stats_row_level", PGC_SUSET, STATS_COLLECTOR,
757 gettext_noop("Collects row-level statistics on database activity."),
760 &pgstat_collect_tuplelevel,
764 {"stats_block_level", PGC_SUSET, STATS_COLLECTOR,
765 gettext_noop("Collects block-level statistics on database activity."),
768 &pgstat_collect_blocklevel,
773 {"stats_command_string", PGC_SUSET, STATS_COLLECTOR,
774 gettext_noop("Collects information about executing commands."),
775 gettext_noop("Enables the collection of information on the currently "
776 "executing command of each session, along with the time "
777 "at which that command began execution.")
779 &pgstat_collect_querystring,
784 {"update_process_title", PGC_SUSET, STATS_COLLECTOR,
785 gettext_noop("Updates the process title to show the active SQL command."),
786 gettext_noop("Enables updating of the process title every time a new SQL command is received by the server.")
788 &update_process_title,
793 {"autovacuum", PGC_SIGHUP, AUTOVACUUM,
794 gettext_noop("Starts the autovacuum subprocess."),
797 &autovacuum_start_daemon,
802 {"trace_notify", PGC_USERSET, DEVELOPER_OPTIONS,
803 gettext_noop("Generates debugging output for LISTEN and NOTIFY."),
813 {"trace_locks", PGC_SUSET, DEVELOPER_OPTIONS,
814 gettext_noop("No description available."),
822 {"trace_userlocks", PGC_SUSET, DEVELOPER_OPTIONS,
823 gettext_noop("No description available."),
831 {"trace_lwlocks", PGC_SUSET, DEVELOPER_OPTIONS,
832 gettext_noop("No description available."),
840 {"debug_deadlocks", PGC_SUSET, DEVELOPER_OPTIONS,
841 gettext_noop("No description available."),
851 {"log_lock_waits", PGC_SUSET, LOGGING_WHAT,
852 gettext_noop("Logs long lock waits."),
860 {"log_hostname", PGC_SIGHUP, LOGGING_WHAT,
861 gettext_noop("Logs the host name in the connection logs."),
862 gettext_noop("By default, connection logs only show the IP address "
863 "of the connecting host. If you want them to show the host name you "
864 "can turn this on, but depending on your host name resolution "
865 "setup it might impose a non-negligible performance penalty.")
871 {"sql_inheritance", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
872 gettext_noop("Causes subtables to be included by default in various commands."),
879 {"password_encryption", PGC_USERSET, CONN_AUTH_SECURITY,
880 gettext_noop("Encrypt passwords."),
881 gettext_noop("When a password is specified in CREATE USER or "
882 "ALTER USER without writing either ENCRYPTED or UNENCRYPTED, "
883 "this parameter determines whether the password is to be encrypted.")
885 &Password_encryption,
889 {"transform_null_equals", PGC_USERSET, COMPAT_OPTIONS_CLIENT,
890 gettext_noop("Treats \"expr=NULL\" as \"expr IS NULL\"."),
891 gettext_noop("When turned on, expressions of the form expr = NULL "
892 "(or NULL = expr) are treated as expr IS NULL, that is, they "
893 "return true if expr evaluates to the null value, and false "
894 "otherwise. The correct behavior of expr = NULL is to always "
895 "return null (unknown).")
897 &Transform_null_equals,
901 {"db_user_namespace", PGC_SIGHUP, CONN_AUTH_SECURITY,
902 gettext_noop("Enables per-database user names."),
909 /* only here for backwards compatibility */
910 {"autocommit", PGC_USERSET, CLIENT_CONN_STATEMENT,
911 gettext_noop("This parameter doesn't do anything."),
912 gettext_noop("It's just here so that we won't choke on SET AUTOCOMMIT TO ON from 7.3-vintage clients."),
913 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
916 true, assign_phony_autocommit, NULL
919 {"default_transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
920 gettext_noop("Sets the default read-only status of new transactions."),
923 &DefaultXactReadOnly,
927 {"transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
928 gettext_noop("Sets the current transaction's read-only status."),
930 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
933 false, assign_transaction_read_only, NULL
936 {"add_missing_from", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
937 gettext_noop("Automatically adds missing table references to FROM clauses."),
944 {"check_function_bodies", PGC_USERSET, CLIENT_CONN_STATEMENT,
945 gettext_noop("Check function bodies during CREATE FUNCTION."),
948 &check_function_bodies,
952 {"array_nulls", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
953 gettext_noop("Enable input of NULL elements in arrays."),
954 gettext_noop("When turned on, unquoted NULL in an array input "
955 "value means a null value; "
956 "otherwise it is taken literally.")
962 {"default_with_oids", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
963 gettext_noop("Create new tables with OIDs by default."),
970 {"redirect_stderr", PGC_POSTMASTER, LOGGING_WHERE,
971 gettext_noop("Start a subprocess to capture stderr output into log files."),
978 {"log_truncate_on_rotation", PGC_SIGHUP, LOGGING_WHERE,
979 gettext_noop("Truncate existing log files of same name during log rotation."),
982 &Log_truncate_on_rotation,
988 {"trace_sort", PGC_USERSET, DEVELOPER_OPTIONS,
989 gettext_noop("Emit information about resource usage in sorting."),
998 #ifdef TRACE_SYNCSCAN
999 /* this is undocumented because not exposed in a standard build */
1001 {"trace_syncscan", PGC_USERSET, DEVELOPER_OPTIONS,
1002 gettext_noop("Generate debugging output for synchronized scanning."),
1011 #ifdef DEBUG_BOUNDED_SORT
1012 /* this is undocumented because not exposed in a standard build */
1015 "optimize_bounded_sort", PGC_USERSET, QUERY_TUNING_METHOD,
1016 gettext_noop("Enable bounded sorting using heap sort."),
1020 &optimize_bounded_sort,
1027 {"wal_debug", PGC_SUSET, DEVELOPER_OPTIONS,
1028 gettext_noop("Emit WAL-related debugging output."),
1038 {"integer_datetimes", PGC_INTERNAL, PRESET_OPTIONS,
1039 gettext_noop("Datetimes are integer based."),
1041 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1044 #ifdef HAVE_INT64_TIMESTAMP
1052 {"krb_caseins_users", PGC_POSTMASTER, CONN_AUTH_SECURITY,
1053 gettext_noop("Sets whether Kerberos and GSSAPI user names should be treated as case-insensitive."),
1056 &pg_krb_caseins_users,
1061 {"escape_string_warning", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1062 gettext_noop("Warn about backslash escapes in ordinary string literals."),
1065 &escape_string_warning,
1070 {"standard_conforming_strings", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1071 gettext_noop("Causes '...' strings to treat backslashes literally."),
1075 &standard_conforming_strings,
1080 {"allow_system_table_mods", PGC_POSTMASTER, DEVELOPER_OPTIONS,
1081 gettext_noop("Allows modifications of the structure of system tables."),
1085 &allowSystemTableMods,
1090 {"ignore_system_indexes", PGC_BACKEND, DEVELOPER_OPTIONS,
1091 gettext_noop("Disables reading from system indexes."),
1092 gettext_noop("It does not prevent updating the indexes, so it is safe "
1093 "to use. The worst consequence is slowness."),
1096 &IgnoreSystemIndexes,
1100 /* End-of-list marker */
1102 {NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL
1107 static struct config_int ConfigureNamesInt[] =
1110 {"archive_timeout", PGC_SIGHUP, WAL_SETTINGS,
1111 gettext_noop("Forces a switch to the next xlog file if a "
1112 "new file has not been started within N seconds."),
1116 &XLogArchiveTimeout,
1117 0, 0, INT_MAX, NULL, NULL
1120 {"post_auth_delay", PGC_BACKEND, DEVELOPER_OPTIONS,
1121 gettext_noop("Waits N seconds on connection startup after authentication."),
1122 gettext_noop("This allows attaching a debugger to the process."),
1123 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1126 0, 0, INT_MAX, NULL, NULL
1129 {"default_statistics_target", PGC_USERSET, QUERY_TUNING_OTHER,
1130 gettext_noop("Sets the default statistics target."),
1131 gettext_noop("This applies to table columns that have not had a "
1132 "column-specific target set via ALTER TABLE SET STATISTICS.")
1134 &default_statistics_target,
1135 10, 1, 1000, NULL, NULL
1138 {"from_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1139 gettext_noop("Sets the FROM-list size beyond which subqueries "
1140 "are not collapsed."),
1141 gettext_noop("The planner will merge subqueries into upper "
1142 "queries if the resulting FROM list would have no more than "
1145 &from_collapse_limit,
1146 8, 1, INT_MAX, NULL, NULL
1149 {"join_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1150 gettext_noop("Sets the FROM-list size beyond which JOIN "
1151 "constructs are not flattened."),
1152 gettext_noop("The planner will flatten explicit JOIN "
1153 "constructs into lists of FROM items whenever a "
1154 "list of no more than this many items would result.")
1156 &join_collapse_limit,
1157 8, 1, INT_MAX, NULL, NULL
1160 {"geqo_threshold", PGC_USERSET, QUERY_TUNING_GEQO,
1161 gettext_noop("Sets the threshold of FROM items beyond which GEQO is used."),
1165 12, 2, INT_MAX, NULL, NULL
1168 {"geqo_effort", PGC_USERSET, QUERY_TUNING_GEQO,
1169 gettext_noop("GEQO: effort is used to set the default for other GEQO parameters."),
1173 DEFAULT_GEQO_EFFORT, MIN_GEQO_EFFORT, MAX_GEQO_EFFORT, NULL, NULL
1176 {"geqo_pool_size", PGC_USERSET, QUERY_TUNING_GEQO,
1177 gettext_noop("GEQO: number of individuals in the population."),
1178 gettext_noop("Zero selects a suitable default value.")
1181 0, 0, INT_MAX, NULL, NULL
1184 {"geqo_generations", PGC_USERSET, QUERY_TUNING_GEQO,
1185 gettext_noop("GEQO: number of iterations of the algorithm."),
1186 gettext_noop("Zero selects a suitable default value.")
1189 0, 0, INT_MAX, NULL, NULL
1193 {"deadlock_timeout", PGC_SIGHUP, LOCK_MANAGEMENT,
1194 gettext_noop("Sets the time to wait on a lock before checking for deadlock."),
1199 1000, 1, INT_MAX/1000, NULL, NULL
1203 * Note: There is some postprocessing done in PostmasterMain() to make
1204 * sure the buffers are at least twice the number of backends, so the
1205 * constraints here are partially unused. Similarly, the superuser
1206 * reserved number is checked to ensure it is less than the max backends
1209 * MaxBackends is limited to INT_MAX/4 because some places compute
1210 * 4*MaxBackends without any overflow check. This check is made on
1211 * assign_maxconnections, since MaxBackends is computed as MaxConnections +
1212 * autovacuum_max_workers.
1214 * Likewise we have to limit NBuffers to INT_MAX/2.
1217 {"max_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1218 gettext_noop("Sets the maximum number of concurrent connections."),
1222 100, 1, INT_MAX / 4, assign_maxconnections, NULL
1226 {"superuser_reserved_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1227 gettext_noop("Sets the number of connection slots reserved for superusers."),
1231 3, 0, INT_MAX / 4, NULL, NULL
1235 {"shared_buffers", PGC_POSTMASTER, RESOURCES_MEM,
1236 gettext_noop("Sets the number of shared memory buffers used by the server."),
1241 1024, 16, INT_MAX / 2, NULL, NULL
1245 {"temp_buffers", PGC_USERSET, RESOURCES_MEM,
1246 gettext_noop("Sets the maximum number of temporary buffers used by each session."),
1251 1024, 100, INT_MAX / 2, NULL, show_num_temp_buffers
1255 {"port", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1256 gettext_noop("Sets the TCP port the server listens on."),
1260 DEF_PGPORT, 1, 65535, NULL, NULL
1264 {"unix_socket_permissions", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1265 gettext_noop("Sets the access permissions of the Unix-domain socket."),
1266 gettext_noop("Unix-domain sockets use the usual Unix file system "
1267 "permission set. The parameter value is expected to be an numeric mode "
1268 "specification in the form accepted by the chmod and umask system "
1269 "calls. (To use the customary octal format the number must start with "
1272 &Unix_socket_permissions,
1273 0777, 0000, 0777, NULL, NULL
1277 {"work_mem", PGC_USERSET, RESOURCES_MEM,
1278 gettext_noop("Sets the maximum memory to be used for query workspaces."),
1279 gettext_noop("This much memory can be used by each internal "
1280 "sort operation and hash table before switching to "
1281 "temporary disk files."),
1285 1024, 8 * BLCKSZ / 1024, MAX_KILOBYTES, NULL, NULL
1289 {"maintenance_work_mem", PGC_USERSET, RESOURCES_MEM,
1290 gettext_noop("Sets the maximum memory to be used for maintenance operations."),
1291 gettext_noop("This includes operations such as VACUUM and CREATE INDEX."),
1294 &maintenance_work_mem,
1295 16384, 1024, MAX_KILOBYTES, NULL, NULL
1299 {"max_stack_depth", PGC_SUSET, RESOURCES_MEM,
1300 gettext_noop("Sets the maximum stack depth, in kilobytes."),
1305 100, 100, MAX_KILOBYTES, assign_max_stack_depth, NULL
1309 {"vacuum_cost_page_hit", PGC_USERSET, RESOURCES,
1310 gettext_noop("Vacuum cost for a page found in the buffer cache."),
1314 1, 0, 10000, NULL, NULL
1318 {"vacuum_cost_page_miss", PGC_USERSET, RESOURCES,
1319 gettext_noop("Vacuum cost for a page not found in the buffer cache."),
1322 &VacuumCostPageMiss,
1323 10, 0, 10000, NULL, NULL
1327 {"vacuum_cost_page_dirty", PGC_USERSET, RESOURCES,
1328 gettext_noop("Vacuum cost for a page dirtied by vacuum."),
1331 &VacuumCostPageDirty,
1332 20, 0, 10000, NULL, NULL
1336 {"vacuum_cost_limit", PGC_USERSET, RESOURCES,
1337 gettext_noop("Vacuum cost amount available before napping."),
1341 200, 1, 10000, NULL, NULL
1345 {"vacuum_cost_delay", PGC_USERSET, RESOURCES,
1346 gettext_noop("Vacuum cost delay in milliseconds."),
1351 0, 0, 1000, NULL, NULL
1355 {"autovacuum_vacuum_cost_delay", PGC_SIGHUP, AUTOVACUUM,
1356 gettext_noop("Vacuum cost delay in milliseconds, for autovacuum."),
1360 &autovacuum_vac_cost_delay,
1361 20, -1, 1000, NULL, NULL
1365 {"autovacuum_vacuum_cost_limit", PGC_SIGHUP, AUTOVACUUM,
1366 gettext_noop("Vacuum cost amount available before napping, for autovacuum."),
1369 &autovacuum_vac_cost_limit,
1370 -1, -1, 10000, NULL, NULL
1374 {"max_files_per_process", PGC_POSTMASTER, RESOURCES_KERNEL,
1375 gettext_noop("Sets the maximum number of simultaneously open files for each server process."),
1378 &max_files_per_process,
1379 1000, 25, INT_MAX, NULL, NULL
1383 {"max_prepared_transactions", PGC_POSTMASTER, RESOURCES,
1384 gettext_noop("Sets the maximum number of simultaneously prepared transactions."),
1387 &max_prepared_xacts,
1388 5, 0, INT_MAX, NULL, NULL
1393 {"trace_lock_oidmin", PGC_SUSET, DEVELOPER_OPTIONS,
1394 gettext_noop("No description available."),
1399 FirstNormalObjectId, 0, INT_MAX, NULL, NULL
1402 {"trace_lock_table", PGC_SUSET, DEVELOPER_OPTIONS,
1403 gettext_noop("No description available."),
1408 0, 0, INT_MAX, NULL, NULL
1413 {"statement_timeout", PGC_USERSET, CLIENT_CONN_STATEMENT,
1414 gettext_noop("Sets the maximum allowed duration of any statement."),
1415 gettext_noop("A value of 0 turns off the timeout."),
1419 0, 0, INT_MAX, NULL, NULL
1423 {"vacuum_freeze_min_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1424 gettext_noop("Minimum age at which VACUUM should freeze a table row."),
1427 &vacuum_freeze_min_age,
1428 100000000, 0, 1000000000, NULL, NULL
1432 {"max_fsm_relations", PGC_POSTMASTER, RESOURCES_FSM,
1433 gettext_noop("Sets the maximum number of tables and indexes for which free space is tracked."),
1437 1000, 100, INT_MAX, NULL, NULL
1440 {"max_fsm_pages", PGC_POSTMASTER, RESOURCES_FSM,
1441 gettext_noop("Sets the maximum number of disk pages for which free space is tracked."),
1445 20000, 1000, INT_MAX, NULL, NULL
1449 {"max_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
1450 gettext_noop("Sets the maximum number of locks per transaction."),
1451 gettext_noop("The shared lock table is sized on the assumption that "
1452 "at most max_locks_per_transaction * max_connections distinct "
1453 "objects will need to be locked at any one time.")
1455 &max_locks_per_xact,
1456 64, 10, INT_MAX, NULL, NULL
1460 {"authentication_timeout", PGC_SIGHUP, CONN_AUTH_SECURITY,
1461 gettext_noop("Sets the maximum allowed time to complete client authentication."),
1465 &AuthenticationTimeout,
1466 60, 1, 600, NULL, NULL
1470 /* Not for general use */
1471 {"pre_auth_delay", PGC_SIGHUP, DEVELOPER_OPTIONS,
1472 gettext_noop("Waits N seconds on connection startup before authentication."),
1473 gettext_noop("This allows attaching a debugger to the process."),
1474 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1477 0, 0, 60, NULL, NULL
1481 {"checkpoint_segments", PGC_SIGHUP, WAL_CHECKPOINTS,
1482 gettext_noop("Sets the maximum distance in log segments between automatic WAL checkpoints."),
1485 &CheckPointSegments,
1486 3, 1, INT_MAX, NULL, NULL
1490 {"checkpoint_timeout", PGC_SIGHUP, WAL_CHECKPOINTS,
1491 gettext_noop("Sets the maximum time between automatic WAL checkpoints."),
1496 300, 30, 3600, NULL, NULL
1500 {"checkpoint_warning", PGC_SIGHUP, WAL_CHECKPOINTS,
1501 gettext_noop("Enables warnings if checkpoint segments are filled more "
1502 "frequently than this."),
1503 gettext_noop("Write a message to the server log if checkpoints "
1504 "caused by the filling of checkpoint segment files happens more "
1505 "frequently than this number of seconds. Zero turns off the warning."),
1509 30, 0, INT_MAX, NULL, NULL
1513 {"wal_buffers", PGC_POSTMASTER, WAL_SETTINGS,
1514 gettext_noop("Sets the number of disk-page buffers in shared memory for WAL."),
1519 8, 4, INT_MAX, NULL, NULL
1523 {"wal_writer_delay", PGC_SIGHUP, WAL_SETTINGS,
1524 gettext_noop("WAL writer sleep time between WAL flushes."),
1529 200, 1, 10000, NULL, NULL
1533 {"commit_delay", PGC_USERSET, WAL_SETTINGS,
1534 gettext_noop("Sets the delay in microseconds between transaction commit and "
1535 "flushing WAL to disk."),
1539 0, 0, 100000, NULL, NULL
1543 {"commit_siblings", PGC_USERSET, WAL_SETTINGS,
1544 gettext_noop("Sets the minimum concurrent open transactions before performing "
1549 5, 1, 1000, NULL, NULL
1553 {"extra_float_digits", PGC_USERSET, CLIENT_CONN_LOCALE,
1554 gettext_noop("Sets the number of digits displayed for floating-point values."),
1555 gettext_noop("This affects real, double precision, and geometric data types. "
1556 "The parameter value is added to the standard number of digits "
1557 "(FLT_DIG or DBL_DIG as appropriate).")
1559 &extra_float_digits,
1560 0, -15, 2, NULL, NULL
1564 {"log_min_duration_statement", PGC_SUSET, LOGGING_WHEN,
1565 gettext_noop("Sets the minimum execution time above which statements will "
1567 gettext_noop("Zero prints all queries. The default is -1 (turning this feature off)."),
1570 &log_min_duration_statement,
1571 -1, -1, INT_MAX / 1000, NULL, NULL
1575 {"log_autovacuum", PGC_BACKEND, LOGGING_WHAT,
1576 gettext_noop("Sets the minimum execution time above which autovacuum actions "
1578 gettext_noop("Zero prints all actions. The default is -1 (turning this feature off)."),
1582 -1, -1, INT_MAX / 1000, NULL, NULL
1586 {"bgwriter_delay", PGC_SIGHUP, RESOURCES,
1587 gettext_noop("Background writer sleep time between rounds."),
1592 200, 10, 10000, NULL, NULL
1596 {"bgwriter_lru_maxpages", PGC_SIGHUP, RESOURCES,
1597 gettext_noop("Background writer maximum number of LRU pages to flush per round."),
1600 &bgwriter_lru_maxpages,
1601 5, 0, 1000, NULL, NULL
1605 {"log_rotation_age", PGC_SIGHUP, LOGGING_WHERE,
1606 gettext_noop("Automatic log file rotation will occur after N minutes."),
1611 HOURS_PER_DAY * MINS_PER_HOUR, 0, INT_MAX / MINS_PER_HOUR, NULL, NULL
1615 {"log_rotation_size", PGC_SIGHUP, LOGGING_WHERE,
1616 gettext_noop("Automatic log file rotation will occur after N kilobytes."),
1621 10 * 1024, 0, INT_MAX / 1024, NULL, NULL
1625 {"max_function_args", PGC_INTERNAL, PRESET_OPTIONS,
1626 gettext_noop("Shows the maximum number of function arguments."),
1628 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1631 FUNC_MAX_ARGS, FUNC_MAX_ARGS, FUNC_MAX_ARGS, NULL, NULL
1635 {"max_index_keys", PGC_INTERNAL, PRESET_OPTIONS,
1636 gettext_noop("Shows the maximum number of index keys."),
1638 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1641 INDEX_MAX_KEYS, INDEX_MAX_KEYS, INDEX_MAX_KEYS, NULL, NULL
1645 {"max_identifier_length", PGC_INTERNAL, PRESET_OPTIONS,
1646 gettext_noop("Shows the maximum identifier length."),
1648 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1650 &max_identifier_length,
1651 NAMEDATALEN - 1, NAMEDATALEN - 1, NAMEDATALEN - 1, NULL, NULL
1655 {"block_size", PGC_INTERNAL, PRESET_OPTIONS,
1656 gettext_noop("Shows the size of a disk block."),
1658 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1661 BLCKSZ, BLCKSZ, BLCKSZ, NULL, NULL
1665 {"autovacuum_naptime", PGC_SIGHUP, AUTOVACUUM,
1666 gettext_noop("Time to sleep between autovacuum runs."),
1670 &autovacuum_naptime,
1671 60, 1, INT_MAX / 1000, NULL, NULL
1674 {"autovacuum_vacuum_threshold", PGC_SIGHUP, AUTOVACUUM,
1675 gettext_noop("Minimum number of tuple updates or deletes prior to vacuum."),
1678 &autovacuum_vac_thresh,
1679 50, 0, INT_MAX, NULL, NULL
1682 {"autovacuum_analyze_threshold", PGC_SIGHUP, AUTOVACUUM,
1683 gettext_noop("Minimum number of tuple inserts, updates or deletes prior to analyze."),
1686 &autovacuum_anl_thresh,
1687 50, 0, INT_MAX, NULL, NULL
1690 /* see varsup.c for why this is PGC_POSTMASTER not PGC_SIGHUP */
1691 {"autovacuum_freeze_max_age", PGC_POSTMASTER, AUTOVACUUM,
1692 gettext_noop("Age at which to autovacuum a table to prevent transaction ID wraparound."),
1695 &autovacuum_freeze_max_age,
1696 200000000, 100000000, 2000000000, NULL, NULL
1699 /* see max_connections */
1700 {"autovacuum_max_workers", PGC_POSTMASTER, AUTOVACUUM,
1701 gettext_noop("Sets the maximum number of simultaneously running autovacuum worker processes."),
1704 &autovacuum_max_workers,
1705 3, 1, INT_MAX / 4, assign_autovacuum_max_workers, NULL
1709 {"tcp_keepalives_idle", PGC_USERSET, CLIENT_CONN_OTHER,
1710 gettext_noop("Time between issuing TCP keepalives."),
1711 gettext_noop("A value of 0 uses the system default."),
1714 &tcp_keepalives_idle,
1715 0, 0, INT_MAX, assign_tcp_keepalives_idle, show_tcp_keepalives_idle
1719 {"tcp_keepalives_interval", PGC_USERSET, CLIENT_CONN_OTHER,
1720 gettext_noop("Time between TCP keepalive retransmits."),
1721 gettext_noop("A value of 0 uses the system default."),
1724 &tcp_keepalives_interval,
1725 0, 0, INT_MAX, assign_tcp_keepalives_interval, show_tcp_keepalives_interval
1729 {"tcp_keepalives_count", PGC_USERSET, CLIENT_CONN_OTHER,
1730 gettext_noop("Maximum number of TCP keepalive retransmits."),
1731 gettext_noop("This controls the number of consecutive keepalive retransmits that can be "
1732 "lost before a connection is considered dead. A value of 0 uses the "
1735 &tcp_keepalives_count,
1736 0, 0, INT_MAX, assign_tcp_keepalives_count, show_tcp_keepalives_count
1740 {"gin_fuzzy_search_limit", PGC_USERSET, CLIENT_CONN_OTHER,
1741 gettext_noop("Sets the maximum allowed result for exact search by GIN."),
1745 &GinFuzzySearchLimit,
1746 0, 0, INT_MAX, NULL, NULL
1750 {"effective_cache_size", PGC_USERSET, QUERY_TUNING_COST,
1751 gettext_noop("Sets the planner's assumption about the size of the disk cache."),
1752 gettext_noop("That is, the portion of the kernel's disk cache that "
1753 "will be used for PostgreSQL data files. This is measured in disk "
1754 "pages, which are normally 8 kB each."),
1757 &effective_cache_size,
1758 DEFAULT_EFFECTIVE_CACHE_SIZE, 1, INT_MAX, NULL, NULL
1762 /* Can't be set in postgresql.conf */
1763 {"server_version_num", PGC_INTERNAL, PRESET_OPTIONS,
1764 gettext_noop("Shows the server version as an integer."),
1766 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1768 &server_version_num,
1769 PG_VERSION_NUM, PG_VERSION_NUM, PG_VERSION_NUM, NULL, NULL
1773 {"log_temp_files", PGC_USERSET, LOGGING_WHAT,
1774 gettext_noop("Log the use of temporary files larger than this number of kilobytes."),
1775 gettext_noop("Zero logs all files. The default is -1 (turning this feature off)."),
1779 -1, -1, INT_MAX, NULL, NULL
1782 /* End-of-list marker */
1784 {NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL
1789 static struct config_real ConfigureNamesReal[] =
1792 {"seq_page_cost", PGC_USERSET, QUERY_TUNING_COST,
1793 gettext_noop("Sets the planner's estimate of the cost of a "
1794 "sequentially fetched disk page."),
1798 DEFAULT_SEQ_PAGE_COST, 0, DBL_MAX, NULL, NULL
1801 {"random_page_cost", PGC_USERSET, QUERY_TUNING_COST,
1802 gettext_noop("Sets the planner's estimate of the cost of a "
1803 "nonsequentially fetched disk page."),
1807 DEFAULT_RANDOM_PAGE_COST, 0, DBL_MAX, NULL, NULL
1810 {"cpu_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
1811 gettext_noop("Sets the planner's estimate of the cost of "
1812 "processing each tuple (row)."),
1816 DEFAULT_CPU_TUPLE_COST, 0, DBL_MAX, NULL, NULL
1819 {"cpu_index_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
1820 gettext_noop("Sets the planner's estimate of the cost of "
1821 "processing each index entry during an index scan."),
1824 &cpu_index_tuple_cost,
1825 DEFAULT_CPU_INDEX_TUPLE_COST, 0, DBL_MAX, NULL, NULL
1828 {"cpu_operator_cost", PGC_USERSET, QUERY_TUNING_COST,
1829 gettext_noop("Sets the planner's estimate of the cost of "
1830 "processing each operator or function call."),
1834 DEFAULT_CPU_OPERATOR_COST, 0, DBL_MAX, NULL, NULL
1838 {"geqo_selection_bias", PGC_USERSET, QUERY_TUNING_GEQO,
1839 gettext_noop("GEQO: selective pressure within the population."),
1842 &Geqo_selection_bias,
1843 DEFAULT_GEQO_SELECTION_BIAS, MIN_GEQO_SELECTION_BIAS,
1844 MAX_GEQO_SELECTION_BIAS, NULL, NULL
1848 {"bgwriter_lru_percent", PGC_SIGHUP, RESOURCES,
1849 gettext_noop("Background writer percentage of LRU buffers to flush per round."),
1852 &bgwriter_lru_percent,
1853 1.0, 0.0, 100.0, NULL, NULL
1857 {"seed", PGC_USERSET, UNGROUPED,
1858 gettext_noop("Sets the seed for random-number generation."),
1860 GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1863 0.5, 0.0, 1.0, assign_random_seed, show_random_seed
1867 {"autovacuum_vacuum_scale_factor", PGC_SIGHUP, AUTOVACUUM,
1868 gettext_noop("Number of tuple updates or deletes prior to vacuum as a fraction of reltuples."),
1871 &autovacuum_vac_scale,
1872 0.2, 0.0, 100.0, NULL, NULL
1875 {"autovacuum_analyze_scale_factor", PGC_SIGHUP, AUTOVACUUM,
1876 gettext_noop("Number of tuple inserts, updates or deletes prior to analyze as a fraction of reltuples."),
1879 &autovacuum_anl_scale,
1880 0.1, 0.0, 100.0, NULL, NULL
1884 {"checkpoint_completion_target", PGC_SIGHUP, WAL_CHECKPOINTS,
1885 gettext_noop("Time spent flushing dirty buffers during checkpoint, as fraction of checkpoint interval."),
1888 &CheckPointCompletionTarget,
1889 0.5, 0.0, 1.0, NULL, NULL
1892 /* End-of-list marker */
1894 {NULL, 0, 0, NULL, NULL}, NULL, 0.0, 0.0, 0.0, NULL, NULL
1899 static struct config_string ConfigureNamesString[] =
1902 {"archive_command", PGC_SIGHUP, WAL_SETTINGS,
1903 gettext_noop("Sets the shell command that will be called to archive a WAL file."),
1906 &XLogArchiveCommand,
1911 {"backslash_quote", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1912 gettext_noop("Sets whether \"\\'\" is allowed in string literals."),
1913 gettext_noop("Valid values are ON, OFF, and SAFE_ENCODING.")
1915 &backslash_quote_string,
1916 "safe_encoding", assign_backslash_quote, NULL
1920 {"client_encoding", PGC_USERSET, CLIENT_CONN_LOCALE,
1921 gettext_noop("Sets the client's character set encoding."),
1923 GUC_IS_NAME | GUC_REPORT
1925 &client_encoding_string,
1926 "SQL_ASCII", assign_client_encoding, NULL
1930 {"client_min_messages", PGC_USERSET, LOGGING_WHEN,
1931 gettext_noop("Sets the message levels that are sent to the client."),
1932 gettext_noop("Valid values are DEBUG5, DEBUG4, DEBUG3, DEBUG2, "
1933 "DEBUG1, LOG, NOTICE, WARNING, and ERROR. Each level includes all the "
1934 "levels that follow it. The later the level, the fewer messages are "
1937 &client_min_messages_str,
1938 "notice", assign_client_min_messages, NULL
1942 {"log_min_messages", PGC_SUSET, LOGGING_WHEN,
1943 gettext_noop("Sets the message levels that are logged."),
1944 gettext_noop("Valid values are DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1, "
1945 "INFO, NOTICE, WARNING, ERROR, LOG, FATAL, and PANIC. Each level "
1946 "includes all the levels that follow it.")
1948 &log_min_messages_str,
1949 "notice", assign_log_min_messages, NULL
1953 {"log_error_verbosity", PGC_SUSET, LOGGING_WHEN,
1954 gettext_noop("Sets the verbosity of logged messages."),
1955 gettext_noop("Valid values are \"terse\", \"default\", and \"verbose\".")
1957 &log_error_verbosity_str,
1958 "default", assign_log_error_verbosity, NULL
1961 {"log_statement", PGC_SUSET, LOGGING_WHAT,
1962 gettext_noop("Sets the type of statements logged."),
1963 gettext_noop("Valid values are \"none\", \"ddl\", \"mod\", and \"all\".")
1966 "none", assign_log_statement, NULL
1970 {"log_min_error_statement", PGC_SUSET, LOGGING_WHEN,
1971 gettext_noop("Causes all statements generating error at or above this level to be logged."),
1972 gettext_noop("All SQL statements that cause an error of the "
1973 "specified level or a higher level are logged.")
1975 &log_min_error_statement_str,
1976 "error", assign_min_error_statement, NULL
1980 {"log_line_prefix", PGC_SIGHUP, LOGGING_WHAT,
1981 gettext_noop("Controls information prefixed to each log line."),
1982 gettext_noop("If blank, no prefix is used.")
1989 {"log_timezone", PGC_SIGHUP, LOGGING_WHAT,
1990 gettext_noop("Sets the time zone to use in log messages."),
1993 &log_timezone_string,
1994 "UNKNOWN", assign_log_timezone, show_log_timezone
1998 {"DateStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
1999 gettext_noop("Sets the display format for date and time values."),
2000 gettext_noop("Also controls interpretation of ambiguous "
2002 GUC_LIST_INPUT | GUC_REPORT
2005 "ISO, MDY", assign_datestyle, NULL
2009 {"default_tablespace", PGC_USERSET, CLIENT_CONN_STATEMENT,
2010 gettext_noop("Sets the default tablespace to create tables and indexes in."),
2011 gettext_noop("An empty string selects the database's default tablespace."),
2014 &default_tablespace,
2015 "", assign_default_tablespace, NULL
2019 {"temp_tablespaces", PGC_USERSET, CLIENT_CONN_STATEMENT,
2020 gettext_noop("Sets the tablespace(s) to use for temporary tables and sort files."),
2022 GUC_LIST_INPUT | GUC_LIST_QUOTE
2025 "", assign_temp_tablespaces, NULL
2029 {"default_transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
2030 gettext_noop("Sets the transaction isolation level of each new transaction."),
2031 gettext_noop("Each SQL transaction has an isolation level, which "
2032 "can be either \"read uncommitted\", \"read committed\", \"repeatable read\", or \"serializable\".")
2034 &default_iso_level_string,
2035 "read committed", assign_defaultxactisolevel, NULL
2039 {"session_replication_role", PGC_SUSET, CLIENT_CONN_STATEMENT,
2040 gettext_noop("Sets the sessions behavior for triggers and rewrite rules."),
2041 gettext_noop("Each session can be either"
2042 " \"origin\", \"replica\" or \"local\".")
2044 &session_replication_role_string,
2045 "origin", assign_session_replication_role, NULL
2049 {"dynamic_library_path", PGC_SUSET, CLIENT_CONN_OTHER,
2050 gettext_noop("Sets the path for dynamically loadable modules."),
2051 gettext_noop("If a dynamically loadable module needs to be opened and "
2052 "the specified name does not have a directory component (i.e., the "
2053 "name does not contain a slash), the system will search this path for "
2054 "the specified file."),
2057 &Dynamic_library_path,
2058 "$libdir", NULL, NULL
2062 {"krb_server_keyfile", PGC_POSTMASTER, CONN_AUTH_SECURITY,
2063 gettext_noop("Sets the location of the Kerberos server key file."),
2067 &pg_krb_server_keyfile,
2068 PG_KRB_SRVTAB, NULL, NULL
2072 {"krb_srvname", PGC_POSTMASTER, CONN_AUTH_SECURITY,
2073 gettext_noop("Sets the name of the Kerberos service."),
2077 PG_KRB_SRVNAM, NULL, NULL
2081 {"krb_server_hostname", PGC_POSTMASTER, CONN_AUTH_SECURITY,
2082 gettext_noop("Sets the hostname of the Kerberos server."),
2085 &pg_krb_server_hostname,
2090 {"bonjour_name", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2091 gettext_noop("Sets the Bonjour broadcast service name."),
2098 /* See main.c about why defaults for LC_foo are not all alike */
2101 {"lc_collate", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2102 gettext_noop("Shows the collation order locale."),
2104 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2111 {"lc_ctype", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2112 gettext_noop("Shows the character classification and case conversion locale."),
2114 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2121 {"lc_messages", PGC_SUSET, CLIENT_CONN_LOCALE,
2122 gettext_noop("Sets the language in which messages are displayed."),
2126 "", locale_messages_assign, NULL
2130 {"lc_monetary", PGC_USERSET, CLIENT_CONN_LOCALE,
2131 gettext_noop("Sets the locale for formatting monetary amounts."),
2135 "C", locale_monetary_assign, NULL
2139 {"lc_numeric", PGC_USERSET, CLIENT_CONN_LOCALE,
2140 gettext_noop("Sets the locale for formatting numbers."),
2144 "C", locale_numeric_assign, NULL
2148 {"lc_time", PGC_USERSET, CLIENT_CONN_LOCALE,
2149 gettext_noop("Sets the locale for formatting date and time values."),
2153 "C", locale_time_assign, NULL
2157 {"shared_preload_libraries", PGC_POSTMASTER, RESOURCES_KERNEL,
2158 gettext_noop("Lists shared libraries to preload into server."),
2160 GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
2162 &shared_preload_libraries_string,
2167 {"local_preload_libraries", PGC_BACKEND, CLIENT_CONN_OTHER,
2168 gettext_noop("Lists shared libraries to preload into each backend."),
2170 GUC_LIST_INPUT | GUC_LIST_QUOTE
2172 &local_preload_libraries_string,
2177 {"regex_flavor", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
2178 gettext_noop("Sets the regular expression \"flavor\"."),
2179 gettext_noop("This can be set to advanced, extended, or basic.")
2181 ®ex_flavor_string,
2182 "advanced", assign_regex_flavor, NULL
2186 {"search_path", PGC_USERSET, CLIENT_CONN_STATEMENT,
2187 gettext_noop("Sets the schema search order for names that are not schema-qualified."),
2189 GUC_LIST_INPUT | GUC_LIST_QUOTE
2191 &namespace_search_path,
2192 "\"$user\",public", assign_search_path, NULL
2196 /* Can't be set in postgresql.conf */
2197 {"server_encoding", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2198 gettext_noop("Sets the server (database) character set encoding."),
2200 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2202 &server_encoding_string,
2203 "SQL_ASCII", NULL, NULL
2207 /* Can't be set in postgresql.conf */
2208 {"server_version", PGC_INTERNAL, PRESET_OPTIONS,
2209 gettext_noop("Shows the server version."),
2211 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2213 &server_version_string,
2214 PG_VERSION, NULL, NULL
2218 /* Not for general use --- used by SET ROLE */
2219 {"role", PGC_USERSET, UNGROUPED,
2220 gettext_noop("Sets the current role."),
2222 GUC_IS_NAME | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2225 "none", assign_role, show_role
2229 /* Not for general use --- used by SET SESSION AUTHORIZATION */
2230 {"session_authorization", PGC_USERSET, UNGROUPED,
2231 gettext_noop("Sets the session user name."),
2233 GUC_IS_NAME | GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2235 &session_authorization_string,
2236 NULL, assign_session_authorization, show_session_authorization
2240 {"log_destination", PGC_SIGHUP, LOGGING_WHERE,
2241 gettext_noop("Sets the destination for server log output."),
2242 gettext_noop("Valid values are combinations of \"stderr\", \"syslog\", "
2243 "and \"eventlog\", depending on the platform."),
2246 &log_destination_string,
2247 "stderr", assign_log_destination, NULL
2250 {"log_directory", PGC_SIGHUP, LOGGING_WHERE,
2251 gettext_noop("Sets the destination directory for log files."),
2252 gettext_noop("Can be specified as relative to the data directory "
2253 "or as absolute path."),
2257 "pg_log", assign_canonical_path, NULL
2260 {"log_filename", PGC_SIGHUP, LOGGING_WHERE,
2261 gettext_noop("Sets the file name pattern for log files."),
2266 "postgresql-%Y-%m-%d_%H%M%S.log", NULL, NULL
2271 {"syslog_facility", PGC_SIGHUP, LOGGING_WHERE,
2272 gettext_noop("Sets the syslog \"facility\" to be used when syslog enabled."),
2273 gettext_noop("Valid values are LOCAL0, LOCAL1, LOCAL2, LOCAL3, "
2274 "LOCAL4, LOCAL5, LOCAL6, LOCAL7.")
2276 &syslog_facility_str,
2277 "LOCAL0", assign_syslog_facility, NULL
2280 {"syslog_ident", PGC_SIGHUP, LOGGING_WHERE,
2281 gettext_noop("Sets the program name used to identify PostgreSQL "
2282 "messages in syslog."),
2286 "postgres", assign_syslog_ident, NULL
2291 {"TimeZone", PGC_USERSET, CLIENT_CONN_LOCALE,
2292 gettext_noop("Sets the time zone for displaying and interpreting time stamps."),
2297 "UNKNOWN", assign_timezone, show_timezone
2300 {"timezone_abbreviations", PGC_USERSET, CLIENT_CONN_LOCALE,
2301 gettext_noop("Selects a file of time zone abbreviations."),
2304 &timezone_abbreviations_string,
2305 "UNKNOWN", assign_timezone_abbreviations, NULL
2309 {"transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
2310 gettext_noop("Sets the current transaction's isolation level."),
2312 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2314 &XactIsoLevel_string,
2315 NULL, assign_XactIsoLevel, show_XactIsoLevel
2319 {"unix_socket_group", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2320 gettext_noop("Sets the owning group of the Unix-domain socket."),
2321 gettext_noop("The owning user of the socket is always the user "
2322 "that starts the server.")
2329 {"unix_socket_directory", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2330 gettext_noop("Sets the directory where the Unix-domain socket will be created."),
2335 "", assign_canonical_path, NULL
2339 {"listen_addresses", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2340 gettext_noop("Sets the host name or IP address(es) to listen to."),
2345 "localhost", NULL, NULL
2349 {"wal_sync_method", PGC_SIGHUP, WAL_SETTINGS,
2350 gettext_noop("Selects the method used for forcing WAL updates to disk."),
2354 XLOG_sync_method_default, assign_xlog_sync_method, NULL
2358 {"custom_variable_classes", PGC_SIGHUP, CUSTOM_OPTIONS,
2359 gettext_noop("Sets the list of known custom variable classes."),
2361 GUC_LIST_INPUT | GUC_LIST_QUOTE
2363 &custom_variable_classes,
2364 NULL, assign_custom_variable_classes, NULL
2368 {"data_directory", PGC_POSTMASTER, FILE_LOCATIONS,
2369 gettext_noop("Sets the server's data directory."),
2378 {"config_file", PGC_POSTMASTER, FILE_LOCATIONS,
2379 gettext_noop("Sets the server's main configuration file."),
2381 GUC_DISALLOW_IN_FILE | GUC_SUPERUSER_ONLY
2388 {"hba_file", PGC_POSTMASTER, FILE_LOCATIONS,
2389 gettext_noop("Sets the server's \"hba\" configuration file."),
2398 {"ident_file", PGC_POSTMASTER, FILE_LOCATIONS,
2399 gettext_noop("Sets the server's \"ident\" configuration file."),
2408 {"external_pid_file", PGC_POSTMASTER, FILE_LOCATIONS,
2409 gettext_noop("Writes the postmaster PID to the specified file."),
2414 NULL, assign_canonical_path, NULL
2418 {"xmlbinary", PGC_USERSET, CLIENT_CONN_STATEMENT,
2419 gettext_noop("Sets how binary values are to be encoded in XML."),
2420 gettext_noop("Valid values are BASE64 and HEX.")
2423 "base64", assign_xmlbinary, NULL
2427 {"xmloption", PGC_USERSET, CLIENT_CONN_STATEMENT,
2428 gettext_noop("Sets whether XML data in implicit parsing and serialization "
2429 "operations is to be considered as documents or content fragments."),
2430 gettext_noop("Valid values are DOCUMENT and CONTENT.")
2433 "content", assign_xmloption, NULL
2438 {"ssl_ciphers", PGC_POSTMASTER, CONN_AUTH_SECURITY,
2439 gettext_noop("Sets the list of allowed SSL ciphers."),
2444 "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH", NULL, NULL
2446 #endif /* USE_SSL */
2448 /* End-of-list marker */
2450 {NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL
2455 /******** end of options list ********/
2459 * To allow continued support of obsolete names for GUC variables, we apply
2460 * the following mappings to any unrecognized name. Note that an old name
2461 * should be mapped to a new one only if the new variable has very similar
2462 * semantics to the old.
2464 static const char *const map_old_guc_names[] = {
2465 "sort_mem", "work_mem",
2466 "vacuum_mem", "maintenance_work_mem",
2472 * Actual lookup of variables is done through this single, sorted array.
2474 static struct config_generic **guc_variables;
2476 /* Current number of variables contained in the vector */
2477 static int num_guc_variables;
2479 /* Vector capacity */
2480 static int size_guc_variables;
2483 static bool guc_dirty; /* TRUE if need to do commit/abort work */
2485 static bool reporting_enabled; /* TRUE to enable GUC_REPORT */
2488 static int guc_var_compare(const void *a, const void *b);
2489 static int guc_name_compare(const char *namea, const char *nameb);
2490 static void push_old_value(struct config_generic * gconf);
2491 static void ReportGUCOption(struct config_generic * record);
2492 static void ShowGUCConfigOption(const char *name, DestReceiver *dest);
2493 static void ShowAllGUCConfig(DestReceiver *dest);
2494 static char *_ShowOption(struct config_generic * record, bool use_units);
2495 static bool is_newvalue_equal(struct config_generic * record, const char *newvalue);
2499 * Some infrastructure for checking malloc/strdup/realloc calls
2502 guc_malloc(int elevel, size_t size)
2506 data = malloc(size);
2509 (errcode(ERRCODE_OUT_OF_MEMORY),
2510 errmsg("out of memory")));
2515 guc_realloc(int elevel, void *old, size_t size)
2519 data = realloc(old, size);
2522 (errcode(ERRCODE_OUT_OF_MEMORY),
2523 errmsg("out of memory")));
2528 guc_strdup(int elevel, const char *src)
2535 (errcode(ERRCODE_OUT_OF_MEMORY),
2536 errmsg("out of memory")));
2542 * Support for assigning to a field of a string GUC item. Free the prior
2543 * value if it's not referenced anywhere else in the item (including stacked
2547 set_string_field(struct config_string * conf, char **field, char *newval)
2549 char *oldval = *field;
2552 /* Do the assignment */
2555 /* Exit if any duplicate references, or if old value was NULL anyway */
2556 if (oldval == NULL ||
2557 oldval == *(conf->variable) ||
2558 oldval == conf->reset_val ||
2559 oldval == conf->tentative_val ||
2560 oldval == conf->boot_val)
2562 for (stack = conf->gen.stack; stack; stack = stack->prev)
2564 if (oldval == stack->tentative_val.stringval ||
2565 oldval == stack->value.stringval)
2569 /* Not used anymore, so free it */
2574 * Detect whether strval is referenced anywhere in a GUC string item
2577 string_field_used(struct config_string * conf, char *strval)
2581 if (strval == *(conf->variable) ||
2582 strval == conf->reset_val ||
2583 strval == conf->tentative_val ||
2584 strval == conf->boot_val)
2586 for (stack = conf->gen.stack; stack; stack = stack->prev)
2588 if (strval == stack->tentative_val.stringval ||
2589 strval == stack->value.stringval)
2596 struct config_generic **
2597 get_guc_variables(void)
2599 return guc_variables;
2604 * Build the sorted array. This is split out so that it could be
2605 * re-executed after startup (eg, we could allow loadable modules to
2606 * add vars, and then we'd need to re-sort).
2609 build_guc_variables(void)
2613 struct config_generic **guc_vars;
2616 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
2618 struct config_bool *conf = &ConfigureNamesBool[i];
2620 /* Rather than requiring vartype to be filled in by hand, do this: */
2621 conf->gen.vartype = PGC_BOOL;
2625 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
2627 struct config_int *conf = &ConfigureNamesInt[i];
2629 conf->gen.vartype = PGC_INT;
2633 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
2635 struct config_real *conf = &ConfigureNamesReal[i];
2637 conf->gen.vartype = PGC_REAL;
2641 for (i = 0; ConfigureNamesString[i].gen.name; i++)
2643 struct config_string *conf = &ConfigureNamesString[i];
2645 conf->gen.vartype = PGC_STRING;
2650 * Create table with 20% slack
2652 size_vars = num_vars + num_vars / 4;
2654 guc_vars = (struct config_generic **)
2655 guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
2659 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
2660 guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
2662 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
2663 guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
2665 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
2666 guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
2668 for (i = 0; ConfigureNamesString[i].gen.name; i++)
2669 guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
2672 free(guc_variables);
2673 guc_variables = guc_vars;
2674 num_guc_variables = num_vars;
2675 size_guc_variables = size_vars;
2676 qsort((void *) guc_variables, num_guc_variables,
2677 sizeof(struct config_generic *), guc_var_compare);
2681 is_custom_class(const char *name, int dotPos)
2684 * assign_custom_variable_classes() has made sure no empty identifiers or
2685 * whitespace exists in the variable
2687 bool result = false;
2688 const char *ccs = GetConfigOption("custom_variable_classes");
2692 const char *start = ccs;
2698 if (c == 0 || c == ',')
2700 if (dotPos == ccs - start && strncmp(start, name, dotPos) == 0)
2715 * Add a new GUC variable to the list of known variables. The
2716 * list is expanded if needed.
2719 add_guc_variable(struct config_generic * var, int elevel)
2721 if (num_guc_variables + 1 >= size_guc_variables)
2724 * Increase the vector by 25%
2726 int size_vars = size_guc_variables + size_guc_variables / 4;
2727 struct config_generic **guc_vars;
2732 guc_vars = (struct config_generic **)
2733 guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
2737 guc_vars = (struct config_generic **)
2738 guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
2741 if (guc_vars == NULL)
2742 return false; /* out of memory */
2744 guc_variables = guc_vars;
2745 size_guc_variables = size_vars;
2747 guc_variables[num_guc_variables++] = var;
2748 qsort((void *) guc_variables, num_guc_variables,
2749 sizeof(struct config_generic *), guc_var_compare);
2754 * Create and add a placeholder variable. It's presumed to belong
2755 * to a valid custom variable class at this point.
2757 static struct config_string *
2758 add_placeholder_variable(const char *name, int elevel)
2760 size_t sz = sizeof(struct config_string) + sizeof(char *);
2761 struct config_string *var;
2762 struct config_generic *gen;
2764 var = (struct config_string *) guc_malloc(elevel, sz);
2771 gen->name = guc_strdup(elevel, name);
2772 if (gen->name == NULL)
2778 gen->context = PGC_USERSET;
2779 gen->group = CUSTOM_OPTIONS;
2780 gen->short_desc = "GUC placeholder variable";
2781 gen->flags = GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_CUSTOM_PLACEHOLDER;
2782 gen->vartype = PGC_STRING;
2785 * The char* is allocated at the end of the struct since we have no
2786 * 'static' place to point to.
2788 var->variable = (char **) (var + 1);
2790 if (!add_guc_variable((struct config_generic *) var, elevel))
2792 free((void *) gen->name);
2801 * Look up option NAME. If it exists, return a pointer to its record,
2804 static struct config_generic *
2805 find_option(const char *name, int elevel)
2808 const char **key = &name;
2809 struct config_generic **res;
2815 * By equating const char ** with struct config_generic *, we are assuming
2816 * the name field is first in config_generic.
2818 res = (struct config_generic **) bsearch((void *) &key,
2819 (void *) guc_variables,
2821 sizeof(struct config_generic *),
2827 * See if the name is an obsolete name for a variable. We assume that the
2828 * set of supported old names is short enough that a brute-force search is
2831 for (i = 0; map_old_guc_names[i] != NULL; i += 2)
2833 if (guc_name_compare(name, map_old_guc_names[i]) == 0)
2834 return find_option(map_old_guc_names[i + 1], elevel);
2838 * Check if the name is qualified, and if so, check if the qualifier maps
2839 * to a custom variable class.
2841 dot = strchr(name, GUC_QUALIFIER_SEPARATOR);
2842 if (dot != NULL && is_custom_class(name, dot - name))
2843 /* Add a placeholder variable for this name */
2844 return (struct config_generic *) add_placeholder_variable(name, elevel);
2852 * comparator for qsorting and bsearching guc_variables array
2855 guc_var_compare(const void *a, const void *b)
2857 struct config_generic *confa = *(struct config_generic **) a;
2858 struct config_generic *confb = *(struct config_generic **) b;
2860 return guc_name_compare(confa->name, confb->name);
2865 guc_name_compare(const char *namea, const char *nameb)
2868 * The temptation to use strcasecmp() here must be resisted, because the
2869 * array ordering has to remain stable across setlocale() calls. So, build
2870 * our own with a simple ASCII-only downcasing.
2872 while (*namea && *nameb)
2874 char cha = *namea++;
2875 char chb = *nameb++;
2877 if (cha >= 'A' && cha <= 'Z')
2879 if (chb >= 'A' && chb <= 'Z')
2885 return 1; /* a is longer */
2887 return -1; /* b is longer */
2893 guc_get_index(const char *name)
2895 const char **key = &name;
2896 struct config_generic **res;
2901 * By equating const char ** with struct config_generic *, we are assuming
2902 * the name field is first in config_generic.
2904 res = (struct config_generic **) bsearch((void *) &key,
2905 (void *) guc_variables,
2907 sizeof(struct config_generic *),
2912 return res - guc_variables;
2917 * Initialize GUC options during program startup.
2919 * Note that we cannot read the config file yet, since we have not yet
2920 * processed command-line switches.
2923 InitializeGUCOptions(void)
2930 * Before log_line_prefix could possibly receive a nonempty setting,
2931 * make sure that timezone processing is minimally alive (see elog.c).
2933 pg_timezone_pre_initialize();
2936 * Build sorted array of all GUC variables.
2938 build_guc_variables();
2941 * Load all variables with their compiled-in defaults, and initialize
2942 * status fields as needed.
2944 for (i = 0; i < num_guc_variables; i++)
2946 struct config_generic *gconf = guc_variables[i];
2949 gconf->reset_source = PGC_S_DEFAULT;
2950 gconf->tentative_source = PGC_S_DEFAULT;
2951 gconf->source = PGC_S_DEFAULT;
2952 gconf->stack = NULL;
2954 switch (gconf->vartype)
2958 struct config_bool *conf = (struct config_bool *) gconf;
2960 if (conf->assign_hook)
2961 if (!(*conf->assign_hook) (conf->boot_val, true,
2963 elog(FATAL, "failed to initialize %s to %d",
2964 conf->gen.name, (int) conf->boot_val);
2965 *conf->variable = conf->reset_val = conf->boot_val;
2970 struct config_int *conf = (struct config_int *) gconf;
2972 Assert(conf->boot_val >= conf->min);
2973 Assert(conf->boot_val <= conf->max);
2974 if (conf->assign_hook)
2975 if (!(*conf->assign_hook) (conf->boot_val, true,
2977 elog(FATAL, "failed to initialize %s to %d",
2978 conf->gen.name, conf->boot_val);
2979 *conf->variable = conf->reset_val = conf->boot_val;
2984 struct config_real *conf = (struct config_real *) gconf;
2986 Assert(conf->boot_val >= conf->min);
2987 Assert(conf->boot_val <= conf->max);
2988 if (conf->assign_hook)
2989 if (!(*conf->assign_hook) (conf->boot_val, true,
2991 elog(FATAL, "failed to initialize %s to %g",
2992 conf->gen.name, conf->boot_val);
2993 *conf->variable = conf->reset_val = conf->boot_val;
2998 struct config_string *conf = (struct config_string *) gconf;
3001 *conf->variable = NULL;
3002 conf->reset_val = NULL;
3003 conf->tentative_val = NULL;
3005 if (conf->boot_val == NULL)
3007 /* Cannot set value yet */
3011 str = guc_strdup(FATAL, conf->boot_val);
3012 conf->reset_val = str;
3014 if (conf->assign_hook)
3018 newstr = (*conf->assign_hook) (str, true,
3022 elog(FATAL, "failed to initialize %s to \"%s\"",
3023 conf->gen.name, str);
3025 else if (newstr != str)
3030 * See notes in set_config_option about casting
3032 str = (char *) newstr;
3033 conf->reset_val = str;
3036 *conf->variable = str;
3044 reporting_enabled = false;
3047 * Prevent any attempt to override the transaction modes from
3048 * non-interactive sources.
3050 SetConfigOption("transaction_isolation", "default",
3051 PGC_POSTMASTER, PGC_S_OVERRIDE);
3052 SetConfigOption("transaction_read_only", "no",
3053 PGC_POSTMASTER, PGC_S_OVERRIDE);
3056 * For historical reasons, some GUC parameters can receive defaults from
3057 * environment variables. Process those settings.
3060 env = getenv("PGPORT");
3062 SetConfigOption("port", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3064 env = getenv("PGDATESTYLE");
3066 SetConfigOption("datestyle", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3068 env = getenv("PGCLIENTENCODING");
3070 SetConfigOption("client_encoding", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3073 * rlimit isn't exactly an "environment variable", but it behaves about
3074 * the same. If we can identify the platform stack depth rlimit, increase
3075 * default stack depth setting up to whatever is safe (but at most 2MB).
3077 stack_rlimit = get_stack_depth_rlimit();
3078 if (stack_rlimit > 0)
3080 int new_limit = (stack_rlimit - STACK_DEPTH_SLOP) / 1024L;
3082 if (new_limit > 100)
3086 new_limit = Min(new_limit, 2048);
3087 sprintf(limbuf, "%d", new_limit);
3088 SetConfigOption("max_stack_depth", limbuf,
3089 PGC_POSTMASTER, PGC_S_ENV_VAR);
3096 * Select the configuration files and data directory to be used, and
3097 * do the initial read of postgresql.conf.
3099 * This is called after processing command-line switches.
3100 * userDoption is the -D switch value if any (NULL if unspecified).
3101 * progname is just for use in error messages.
3103 * Returns true on success; on failure, prints a suitable error message
3104 * to stderr and returns false.
3107 SelectConfigFiles(const char *userDoption, const char *progname)
3111 struct stat stat_buf;
3113 /* configdir is -D option, or $PGDATA if no -D */
3115 configdir = make_absolute_path(userDoption);
3117 configdir = make_absolute_path(getenv("PGDATA"));
3120 * Find the configuration file: if config_file was specified on the
3121 * command line, use it, else use configdir/postgresql.conf. In any case
3122 * ensure the result is an absolute path, so that it will be interpreted
3123 * the same way by future backends.
3126 fname = make_absolute_path(ConfigFileName);
3129 fname = guc_malloc(FATAL,
3130 strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
3131 sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
3135 write_stderr("%s does not know where to find the server configuration file.\n"
3136 "You must specify the --config-file or -D invocation "
3137 "option or set the PGDATA environment variable.\n",
3143 * Set the ConfigFileName GUC variable to its final value, ensuring that
3144 * it can't be overridden later.
3146 SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
3150 * Now read the config file for the first time.
3152 if (stat(ConfigFileName, &stat_buf) != 0)
3154 write_stderr("%s cannot access the server configuration file \"%s\": %s\n",
3155 progname, ConfigFileName, strerror(errno));
3159 ProcessConfigFile(PGC_POSTMASTER);
3162 * If the data_directory GUC variable has been set, use that as DataDir;
3163 * otherwise use configdir if set; else punt.
3165 * Note: SetDataDir will copy and absolute-ize its argument, so we don't
3169 SetDataDir(data_directory);
3171 SetDataDir(configdir);
3174 write_stderr("%s does not know where to find the database system data.\n"
3175 "This can be specified as \"data_directory\" in \"%s\", "
3176 "or by the -D invocation option, or by the "
3177 "PGDATA environment variable.\n",
3178 progname, ConfigFileName);
3183 * Reflect the final DataDir value back into the data_directory GUC var.
3184 * (If you are wondering why we don't just make them a single variable,
3185 * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
3186 * child backends specially. XXX is that still true? Given that we now
3187 * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
3188 * DataDir in advance.)
3190 SetConfigOption("data_directory", DataDir, PGC_POSTMASTER, PGC_S_OVERRIDE);
3193 * Figure out where pg_hba.conf is, and make sure the path is absolute.
3196 fname = make_absolute_path(HbaFileName);
3199 fname = guc_malloc(FATAL,
3200 strlen(configdir) + strlen(HBA_FILENAME) + 2);
3201 sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
3205 write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
3206 "This can be specified as \"hba_file\" in \"%s\", "
3207 "or by the -D invocation option, or by the "
3208 "PGDATA environment variable.\n",
3209 progname, ConfigFileName);
3212 SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
3216 * Likewise for pg_ident.conf.
3219 fname = make_absolute_path(IdentFileName);
3222 fname = guc_malloc(FATAL,
3223 strlen(configdir) + strlen(IDENT_FILENAME) + 2);
3224 sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
3228 write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
3229 "This can be specified as \"ident_file\" in \"%s\", "
3230 "or by the -D invocation option, or by the "
3231 "PGDATA environment variable.\n",
3232 progname, ConfigFileName);
3235 SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
3245 * Reset all options to their saved default values (implements RESET ALL)
3248 ResetAllOptions(void)
3252 for (i = 0; i < num_guc_variables; i++)
3254 struct config_generic *gconf = guc_variables[i];
3256 /* Don't reset non-SET-able values */
3257 if (gconf->context != PGC_SUSET &&
3258 gconf->context != PGC_USERSET)
3260 /* Don't reset if special exclusion from RESET ALL */
3261 if (gconf->flags & GUC_NO_RESET_ALL)
3263 /* No need to reset if wasn't SET */
3264 if (gconf->source <= PGC_S_OVERRIDE)
3267 /* Save old value to support transaction abort */
3268 push_old_value(gconf);
3270 switch (gconf->vartype)
3274 struct config_bool *conf = (struct config_bool *) gconf;
3276 if (conf->assign_hook)
3277 if (!(*conf->assign_hook) (conf->reset_val, true,
3279 elog(ERROR, "failed to reset %s", conf->gen.name);
3280 *conf->variable = conf->reset_val;
3281 conf->tentative_val = conf->reset_val;
3282 conf->gen.source = conf->gen.reset_source;
3283 conf->gen.tentative_source = conf->gen.reset_source;
3284 conf->gen.status |= GUC_HAVE_TENTATIVE;
3290 struct config_int *conf = (struct config_int *) gconf;
3292 if (conf->assign_hook)
3293 if (!(*conf->assign_hook) (conf->reset_val, true,
3295 elog(ERROR, "failed to reset %s", conf->gen.name);
3296 *conf->variable = conf->reset_val;
3297 conf->tentative_val = conf->reset_val;
3298 conf->gen.source = conf->gen.reset_source;
3299 conf->gen.tentative_source = conf->gen.reset_source;
3300 conf->gen.status |= GUC_HAVE_TENTATIVE;
3306 struct config_real *conf = (struct config_real *) gconf;
3308 if (conf->assign_hook)
3309 if (!(*conf->assign_hook) (conf->reset_val, true,
3311 elog(ERROR, "failed to reset %s", conf->gen.name);
3312 *conf->variable = conf->reset_val;
3313 conf->tentative_val = conf->reset_val;
3314 conf->gen.source = conf->gen.reset_source;
3315 conf->gen.tentative_source = conf->gen.reset_source;
3316 conf->gen.status |= GUC_HAVE_TENTATIVE;
3322 struct config_string *conf = (struct config_string *) gconf;
3325 if (conf->reset_val == NULL)
3327 /* Nothing to reset to, as yet; so do nothing */
3331 /* We need not strdup here */
3332 str = conf->reset_val;
3334 if (conf->assign_hook)
3338 newstr = (*conf->assign_hook) (str, true,
3341 elog(ERROR, "failed to reset %s", conf->gen.name);
3342 else if (newstr != str)
3345 * See notes in set_config_option about casting
3347 str = (char *) newstr;
3351 set_string_field(conf, conf->variable, str);
3352 set_string_field(conf, &conf->tentative_val, str);
3353 conf->gen.source = conf->gen.reset_source;
3354 conf->gen.tentative_source = conf->gen.reset_source;
3355 conf->gen.status |= GUC_HAVE_TENTATIVE;
3361 if (gconf->flags & GUC_REPORT)
3362 ReportGUCOption(gconf);
3369 * Push previous state during first assignment to a GUC variable
3370 * within a particular transaction.
3372 * We have to be willing to "back-fill" the state stack if the first
3373 * assignment occurs within a subtransaction nested several levels deep.
3374 * This ensures that if an intermediate transaction aborts, it will have
3375 * the proper value available to restore the setting to.
3378 push_old_value(struct config_generic * gconf)
3380 int my_level = GetCurrentTransactionNestLevel();
3383 /* If we're not inside a transaction, do nothing */
3389 /* Done if we already pushed it at this nesting depth */
3390 if (gconf->stack && gconf->stack->nest_level >= my_level)
3394 * We keep all the stack entries in TopTransactionContext so as to
3395 * avoid allocation problems when a subtransaction back-fills stack
3396 * entries for upper transaction levels.
3398 stack = (GucStack *) MemoryContextAlloc(TopTransactionContext,
3401 stack->prev = gconf->stack;
3402 stack->nest_level = stack->prev ? stack->prev->nest_level + 1 : 1;
3403 stack->status = gconf->status;
3404 stack->tentative_source = gconf->tentative_source;
3405 stack->source = gconf->source;
3407 switch (gconf->vartype)
3410 stack->tentative_val.boolval =
3411 ((struct config_bool *) gconf)->tentative_val;
3412 stack->value.boolval =
3413 *((struct config_bool *) gconf)->variable;
3417 stack->tentative_val.intval =
3418 ((struct config_int *) gconf)->tentative_val;
3419 stack->value.intval =
3420 *((struct config_int *) gconf)->variable;
3424 stack->tentative_val.realval =
3425 ((struct config_real *) gconf)->tentative_val;
3426 stack->value.realval =
3427 *((struct config_real *) gconf)->variable;
3431 stack->tentative_val.stringval =
3432 ((struct config_string *) gconf)->tentative_val;
3433 stack->value.stringval =
3434 *((struct config_string *) gconf)->variable;
3438 gconf->stack = stack;
3440 /* Set state to indicate nothing happened yet within this level */
3441 gconf->status = GUC_HAVE_STACK;
3443 /* Ensure we remember to pop at end of xact */
3449 * Do GUC processing at transaction or subtransaction commit or abort.
3452 AtEOXact_GUC(bool isCommit, bool isSubXact)
3457 /* Quick exit if nothing's changed in this transaction */
3461 my_level = GetCurrentTransactionNestLevel();
3462 Assert(isSubXact ? (my_level > 1) : (my_level == 1));
3464 for (i = 0; i < num_guc_variables; i++)
3466 struct config_generic *gconf = guc_variables[i];
3467 int my_status = gconf->status;
3468 GucStack *stack = gconf->stack;
3473 * Skip if nothing's happened to this var in this transaction
3477 Assert(stack == NULL);
3480 /* Assert that we stacked old value before changing it */
3481 Assert(stack != NULL && (my_status & GUC_HAVE_STACK));
3482 /* However, the last change may have been at an outer xact level */
3483 if (stack->nest_level < my_level)
3485 Assert(stack->nest_level == my_level);
3488 * We will pop the stack entry. Start by restoring outer xact status
3489 * (since we may want to modify it below). Be careful to use
3490 * my_status to reference the inner xact status below this point...
3492 gconf->status = stack->status;
3495 * We have two cases:
3497 * If commit and HAVE_TENTATIVE, set actual value to tentative (this
3498 * is to override a SET LOCAL if one occurred later than SET). We keep
3499 * the tentative value and propagate HAVE_TENTATIVE to the parent
3500 * status, allowing the SET's effect to percolate up. (But if we're
3501 * exiting the outermost transaction, we'll drop the HAVE_TENTATIVE
3504 * Otherwise, we have a transaction that aborted or executed only SET
3505 * LOCAL (or no SET at all). In either case it should have no further
3506 * effect, so restore both tentative and actual values from the stack
3510 useTentative = isCommit && (my_status & GUC_HAVE_TENTATIVE) != 0;
3513 switch (gconf->vartype)
3517 struct config_bool *conf = (struct config_bool *) gconf;
3519 GucSource newsource;
3523 newval = conf->tentative_val;
3524 newsource = conf->gen.tentative_source;
3525 conf->gen.status |= GUC_HAVE_TENTATIVE;
3529 newval = stack->value.boolval;
3530 newsource = stack->source;
3531 conf->tentative_val = stack->tentative_val.boolval;
3532 conf->gen.tentative_source = stack->tentative_source;
3535 if (*conf->variable != newval)
3537 if (conf->assign_hook)
3538 if (!(*conf->assign_hook) (newval,
3539 true, PGC_S_OVERRIDE))
3540 elog(LOG, "failed to commit %s",
3542 *conf->variable = newval;
3545 conf->gen.source = newsource;
3550 struct config_int *conf = (struct config_int *) gconf;
3552 GucSource newsource;
3556 newval = conf->tentative_val;
3557 newsource = conf->gen.tentative_source;
3558 conf->gen.status |= GUC_HAVE_TENTATIVE;
3562 newval = stack->value.intval;
3563 newsource = stack->source;
3564 conf->tentative_val = stack->tentative_val.intval;
3565 conf->gen.tentative_source = stack->tentative_source;
3568 if (*conf->variable != newval)
3570 if (conf->assign_hook)
3571 if (!(*conf->assign_hook) (newval,
3572 true, PGC_S_OVERRIDE))
3573 elog(LOG, "failed to commit %s",
3575 *conf->variable = newval;
3578 conf->gen.source = newsource;
3583 struct config_real *conf = (struct config_real *) gconf;
3585 GucSource newsource;
3589 newval = conf->tentative_val;
3590 newsource = conf->gen.tentative_source;
3591 conf->gen.status |= GUC_HAVE_TENTATIVE;
3595 newval = stack->value.realval;
3596 newsource = stack->source;
3597 conf->tentative_val = stack->tentative_val.realval;
3598 conf->gen.tentative_source = stack->tentative_source;
3601 if (*conf->variable != newval)
3603 if (conf->assign_hook)
3604 if (!(*conf->assign_hook) (newval,
3605 true, PGC_S_OVERRIDE))
3606 elog(LOG, "failed to commit %s",
3608 *conf->variable = newval;
3611 conf->gen.source = newsource;
3616 struct config_string *conf = (struct config_string *) gconf;
3618 GucSource newsource;
3622 newval = conf->tentative_val;
3623 newsource = conf->gen.tentative_source;
3624 conf->gen.status |= GUC_HAVE_TENTATIVE;
3628 newval = stack->value.stringval;
3629 newsource = stack->source;
3630 set_string_field(conf, &conf->tentative_val,
3631 stack->tentative_val.stringval);
3632 conf->gen.tentative_source = stack->tentative_source;
3635 if (*conf->variable != newval)
3637 if (conf->assign_hook)
3641 newstr = (*conf->assign_hook) (newval, true,
3644 elog(LOG, "failed to commit %s",
3646 else if (newstr != newval)
3649 * If newval should now be freed, it'll be
3650 * taken care of below.
3652 * See notes in set_config_option about
3655 newval = (char *) newstr;
3659 set_string_field(conf, conf->variable, newval);
3662 conf->gen.source = newsource;
3663 /* Release stacked values if not used anymore */
3664 set_string_field(conf, &stack->value.stringval,
3666 set_string_field(conf, &stack->tentative_val.stringval,
3668 /* Don't store tentative value separately after commit */
3670 set_string_field(conf, &conf->tentative_val, NULL);
3675 /* Finish popping the state stack */
3676 gconf->stack = stack->prev;
3680 * If we're now out of all xact levels, forget TENTATIVE status bit;
3681 * there's nothing tentative about the value anymore.
3685 Assert(gconf->stack == NULL);
3689 /* Report new value if we changed it */
3690 if (changed && (gconf->flags & GUC_REPORT))
3691 ReportGUCOption(gconf);
3695 * If we're now out of all xact levels, we can clear guc_dirty. (Note: we
3696 * cannot reset guc_dirty when exiting a subtransaction, because we know
3697 * that all outer transaction levels will have stacked values to deal
3706 * Start up automatic reporting of changes to variables marked GUC_REPORT.
3707 * This is executed at completion of backend startup.
3710 BeginReportingGUCOptions(void)
3715 * Don't do anything unless talking to an interactive frontend of protocol
3718 if (whereToSendOutput != DestRemote ||
3719 PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
3722 reporting_enabled = true;
3724 /* Transmit initial values of interesting variables */
3725 for (i = 0; i < num_guc_variables; i++)
3727 struct config_generic *conf = guc_variables[i];
3729 if (conf->flags & GUC_REPORT)
3730 ReportGUCOption(conf);
3735 * ReportGUCOption: if appropriate, transmit option value to frontend
3738 ReportGUCOption(struct config_generic * record)
3740 if (reporting_enabled && (record->flags & GUC_REPORT))
3742 char *val = _ShowOption(record, false);
3743 StringInfoData msgbuf;
3745 pq_beginmessage(&msgbuf, 'S');
3746 pq_sendstring(&msgbuf, record->name);
3747 pq_sendstring(&msgbuf, val);
3748 pq_endmessage(&msgbuf);
3756 * Try to interpret value as boolean value. Valid values are: true,
3757 * false, yes, no, on, off, 1, 0; as well as unique prefixes thereof.
3758 * If the string parses okay, return true, else false.
3759 * If okay and result is not NULL, return the value in *result.
3762 parse_bool(const char *value, bool *result)
3764 size_t len = strlen(value);
3766 if (pg_strncasecmp(value, "true", len) == 0)
3771 else if (pg_strncasecmp(value, "false", len) == 0)
3777 else if (pg_strncasecmp(value, "yes", len) == 0)
3782 else if (pg_strncasecmp(value, "no", len) == 0)
3788 /* 'o' is not unique enough */
3789 else if (pg_strncasecmp(value, "on", (len > 2 ? len : 2)) == 0)
3794 else if (pg_strncasecmp(value, "off", (len > 2 ? len : 2)) == 0)
3800 else if (pg_strcasecmp(value, "1") == 0)
3805 else if (pg_strcasecmp(value, "0") == 0)
3814 *result = false; /* suppress compiler warning */
3823 * Try to parse value as an integer. The accepted formats are the
3824 * usual decimal, octal, or hexadecimal formats, optionally followed by
3825 * a unit name if "flags" indicates a unit is allowed.
3827 * If the string parses okay, return true, else false.
3828 * If okay and result is not NULL, return the value in *result.
3829 * If not okay and hintmsg is not NULL, *hintmsg is set to a suitable
3830 * HINT message, or NULL if no hint provided.
3833 parse_int(const char *value, int *result, int flags, const char **hintmsg)
3838 /* To suppress compiler warnings, always set output params */
3844 /* We assume here that int64 is at least as wide as long */
3846 val = strtol(value, &endptr, 0);
3848 if (endptr == value)
3849 return false; /* no HINT for integer syntax error */
3851 if (errno == ERANGE || val != (int64) ((int32) val))
3854 *hintmsg = gettext_noop("Value exceeds integer range.");
3858 /* allow whitespace between integer and unit */
3859 while (isspace((unsigned char) *endptr))
3862 /* Handle possible unit */
3863 if (*endptr != '\0')
3866 * Note: the multiple-switch coding technique here is a bit tedious,
3867 * but seems necessary to avoid intermediate-value overflows.
3869 * If INT64_IS_BUSTED (ie, it's really int32) we will fail to detect
3870 * overflow due to units conversion, but there are few enough such
3871 * machines that it does not seem worth trying to be smarter.
3873 if (flags & GUC_UNIT_MEMORY)
3875 /* Set hint for use if no match or trailing garbage */
3877 *hintmsg = gettext_noop("Valid units for this parameter are \"kB\", \"MB\", and \"GB\".");
3879 #if BLCKSZ < 1024 || BLCKSZ > (1024*1024)
3880 #error BLCKSZ must be between 1KB and 1MB
3882 #if XLOG_BLCKSZ < 1024 || XLOG_BLCKSZ > (1024*1024)
3883 #error XLOG_BLCKSZ must be between 1KB and 1MB
3886 if (strncmp(endptr, "kB", 2) == 0)
3889 switch (flags & GUC_UNIT_MEMORY)
3891 case GUC_UNIT_BLOCKS:
3892 val /= (BLCKSZ / 1024);
3894 case GUC_UNIT_XBLOCKS:
3895 val /= (XLOG_BLCKSZ / 1024);
3899 else if (strncmp(endptr, "MB", 2) == 0)
3902 switch (flags & GUC_UNIT_MEMORY)
3907 case GUC_UNIT_BLOCKS:
3908 val *= KB_PER_MB / (BLCKSZ / 1024);
3910 case GUC_UNIT_XBLOCKS:
3911 val *= KB_PER_MB / (XLOG_BLCKSZ / 1024);
3915 else if (strncmp(endptr, "GB", 2) == 0)
3918 switch (flags & GUC_UNIT_MEMORY)
3923 case GUC_UNIT_BLOCKS:
3924 val *= KB_PER_GB / (BLCKSZ / 1024);
3926 case GUC_UNIT_XBLOCKS:
3927 val *= KB_PER_GB / (XLOG_BLCKSZ / 1024);
3932 else if (flags & GUC_UNIT_TIME)
3934 /* Set hint for use if no match or trailing garbage */
3936 *hintmsg = gettext_noop("Valid units for this parameter are \"ms\", \"s\", \"min\", \"h\", and \"d\".");
3938 if (strncmp(endptr, "ms", 2) == 0)
3941 switch (flags & GUC_UNIT_TIME)
3951 else if (strncmp(endptr, "s", 1) == 0)
3954 switch (flags & GUC_UNIT_TIME)
3964 else if (strncmp(endptr, "min", 3) == 0)
3967 switch (flags & GUC_UNIT_TIME)
3977 else if (strncmp(endptr, "h", 1) == 0)
3980 switch (flags & GUC_UNIT_TIME)
3993 else if (strncmp(endptr, "d", 1) == 0)
3996 switch (flags & GUC_UNIT_TIME)
4011 /* allow whitespace after unit */
4012 while (isspace((unsigned char) *endptr))
4015 if (*endptr != '\0')
4016 return false; /* appropriate hint, if any, already set */
4018 /* Check for overflow due to units conversion */
4019 if (val != (int64) ((int32) val))
4022 *hintmsg = gettext_noop("Value exceeds integer range.");
4028 *result = (int) val;
4035 * Try to parse value as a floating point number in the usual format.
4036 * If the string parses okay, return true, else false.
4037 * If okay and result is not NULL, return the value in *result.
4040 parse_real(const char *value, double *result)
4046 *result = 0; /* suppress compiler warning */
4049 val = strtod(value, &endptr);
4050 if (endptr == value || errno == ERANGE)
4053 /* allow whitespace after number */
4054 while (isspace((unsigned char) *endptr))
4056 if (*endptr != '\0')
4066 * Call a GucStringAssignHook function, being careful to free the
4067 * "newval" string if the hook ereports.
4069 * This is split out of set_config_option just to avoid the "volatile"
4070 * qualifiers that would otherwise have to be plastered all over.
4073 call_string_assign_hook(GucStringAssignHook assign_hook,
4074 char *newval, bool doit, GucSource source)
4080 result = (*assign_hook) (newval, doit, source);
4094 * Sets option `name' to given value. The value should be a string
4095 * which is going to be parsed and converted to the appropriate data
4096 * type. The context and source parameters indicate in which context this
4097 * function is being called so it can apply the access restrictions
4100 * If value is NULL, set the option to its default value. If the
4101 * parameter changeVal is false then don't really set the option but do all
4102 * the checks to see if it would work.
4104 * If there is an error (non-existing option, invalid value) then an
4105 * ereport(ERROR) is thrown *unless* this is called in a context where we
4106 * don't want to ereport (currently, startup or SIGHUP config file reread).
4107 * In that case we write a suitable error message via ereport(DEBUG) and
4108 * return false. This is working around the deficiencies in the ereport
4109 * mechanism, so don't blame me. In all other cases, the function
4110 * returns true, including cases where the input is valid but we chose
4111 * not to apply it because of context or source-priority considerations.
4113 * See also SetConfigOption for an external interface.
4116 set_config_option(const char *name, const char *value,
4117 GucContext context, GucSource source,
4118 bool isLocal, bool changeVal)
4120 struct config_generic *record;
4124 if (context == PGC_SIGHUP || source == PGC_S_DEFAULT)
4127 * To avoid cluttering the log, only the postmaster bleats loudly
4128 * about problems with the config file.
4130 elevel = IsUnderPostmaster ? DEBUG2 : LOG;
4132 else if (source == PGC_S_DATABASE || source == PGC_S_USER)
4137 record = find_option(name, elevel);
4141 (errcode(ERRCODE_UNDEFINED_OBJECT),
4142 errmsg("unrecognized configuration parameter \"%s\"", name)));
4147 * Do not replace a value that has been set on the command line by a SIGHUP
4150 if (context == PGC_SIGHUP && record->source == PGC_S_ARGV)
4154 * Check if the option can be set at this time. See guc.h for the precise
4155 * rules. Note that we don't want to throw errors if we're in the SIGHUP
4156 * context. In that case we just ignore the attempt and return true.
4158 switch (record->context)
4161 if (context == PGC_SIGHUP)
4163 if (context != PGC_INTERNAL)
4166 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4167 errmsg("parameter \"%s\" cannot be changed",
4172 case PGC_POSTMASTER:
4173 if (context == PGC_SIGHUP)
4175 if (changeVal && !is_newvalue_equal(record, value))
4177 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4178 errmsg("parameter \"%s\" cannot be changed after server start; configuration file change ignored",
4183 if (context != PGC_POSTMASTER)
4186 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4187 errmsg("parameter \"%s\" cannot be changed after server start",
4193 if (context != PGC_SIGHUP && context != PGC_POSTMASTER)
4196 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4197 errmsg("parameter \"%s\" cannot be changed now",
4203 * Hmm, the idea of the SIGHUP context is "ought to be global, but
4204 * can be changed after postmaster start". But there's nothing
4205 * that prevents a crafty administrator from sending SIGHUP
4206 * signals to individual backends only.
4210 if (context == PGC_SIGHUP)
4213 * If a PGC_BACKEND parameter is changed in the config file,
4214 * we want to accept the new value in the postmaster (whence
4215 * it will propagate to subsequently-started backends), but
4216 * ignore it in existing backends. This is a tad klugy, but
4217 * necessary because we don't re-read the config file during
4220 if (IsUnderPostmaster)
4223 else if (context != PGC_BACKEND && context != PGC_POSTMASTER)
4226 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4227 errmsg("parameter \"%s\" cannot be set after connection start",
4233 if (context == PGC_USERSET || context == PGC_BACKEND)
4236 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4237 errmsg("permission denied to set parameter \"%s\"",
4248 * Should we set reset/stacked values? (If so, the behavior is not
4249 * transactional.) This is done either when we get a default
4250 * value from the database's/user's/client's default settings or
4251 * when we reset a value to its default.
4253 makeDefault = changeVal && (source <= PGC_S_OVERRIDE)
4254 && ((value != NULL) || source == PGC_S_DEFAULT);
4257 * Ignore attempted set if overridden by previously processed
4258 * setting. However, if changeVal is false then plow ahead anyway
4259 * since we are trying to find out if the value is potentially
4260 * good, not actually use it. Also keep going if makeDefault is
4261 * true, since we may want to set the reset/stacked values even if
4262 * we can't set the variable itself. There's one exception to
4263 * this rule: if we want to apply the default value to variables
4264 * that were removed from the configuration file. This is
4265 * indicated by source == PGC_S_DEFAULT and context == PGC_SIGHUP.
4267 if (record->source > source
4268 && !(source == PGC_S_DEFAULT && context == PGC_SIGHUP))
4270 if (changeVal && !makeDefault)
4272 elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
4280 * Evaluate value and set variable.
4282 switch (record->vartype)
4286 struct config_bool *conf = (struct config_bool *) record;
4291 if (!parse_bool(value, &newval))
4294 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4295 errmsg("parameter \"%s\" requires a Boolean value",
4301 * If value == NULL and source == PGC_S_DEFAULT then
4302 * we reset some value to its default (removed from
4303 * configuration file).
4305 else if (source == PGC_S_DEFAULT)
4306 newval = conf->boot_val;
4307 /* else we handle a "RESET varname" command */
4310 newval = conf->reset_val;
4311 source = conf->gen.reset_source;
4314 if (conf->assign_hook)
4315 if (!(*conf->assign_hook) (newval, changeVal, source))
4318 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4319 errmsg("invalid value for parameter \"%s\": %d",
4320 name, (int) newval)));
4324 if (changeVal || makeDefault)
4326 /* Save old value to support transaction abort */
4328 push_old_value(&conf->gen);
4331 *conf->variable = newval;
4332 conf->gen.source = source;
4338 if (conf->gen.reset_source <= source)
4340 conf->reset_val = newval;
4341 conf->gen.reset_source = source;
4343 for (stack = conf->gen.stack; stack; stack = stack->prev)
4345 if (stack->source <= source)
4347 stack->value.boolval = newval;
4348 stack->source = source;
4354 conf->gen.status |= GUC_HAVE_LOCAL;
4359 conf->tentative_val = newval;
4360 conf->gen.tentative_source = source;
4361 conf->gen.status |= GUC_HAVE_TENTATIVE;
4370 struct config_int *conf = (struct config_int *) record;
4375 const char *hintmsg;
4377 if (!parse_int(value, &newval, conf->gen.flags, &hintmsg))
4380 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4381 errmsg("invalid value for parameter \"%s\": \"%s\"",
4383 hintmsg ? errhint(hintmsg) : 0));
4386 if (newval < conf->min || newval > conf->max)
4389 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4390 errmsg("%d is outside the valid range for parameter \"%s\" (%d .. %d)",
4391 newval, name, conf->min, conf->max)));
4396 * If value == NULL and source == PGC_S_DEFAULT then
4397 * we reset some value to its default (removed from
4398 * configuration file).
4400 else if (source == PGC_S_DEFAULT)
4401 newval = conf->boot_val;
4402 /* else we handle a "RESET varname" command */
4405 newval = conf->reset_val;
4406 source = conf->gen.reset_source;
4409 if (conf->assign_hook)
4410 if (!(*conf->assign_hook) (newval, changeVal, source))
4413 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4414 errmsg("invalid value for parameter \"%s\": %d",
4419 if (changeVal || makeDefault)
4421 /* Save old value to support transaction abort */
4423 push_old_value(&conf->gen);
4426 *conf->variable = newval;
4427 conf->gen.source = source;
4433 if (conf->gen.reset_source <= source)
4435 conf->reset_val = newval;
4436 conf->gen.reset_source = source;
4438 for (stack = conf->gen.stack; stack; stack = stack->prev)
4440 if (stack->source <= source)
4442 stack->value.intval = newval;
4443 stack->source = source;
4449 conf->gen.status |= GUC_HAVE_LOCAL;
4454 conf->tentative_val = newval;
4455 conf->gen.tentative_source = source;
4456 conf->gen.status |= GUC_HAVE_TENTATIVE;
4465 struct config_real *conf = (struct config_real *) record;
4470 if (!parse_real(value, &newval))
4473 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4474 errmsg("parameter \"%s\" requires a numeric value",
4478 if (newval < conf->min || newval > conf->max)
4481 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4482 errmsg("%g is outside the valid range for parameter \"%s\" (%g .. %g)",
4483 newval, name, conf->min, conf->max)));
4488 * If value == NULL and source == PGC_S_DEFAULT then
4489 * we reset some value to its default (removed from
4490 * configuration file).
4492 else if (source == PGC_S_DEFAULT)
4493 newval = conf->boot_val;
4494 /* else we handle a "RESET varname" command */
4497 newval = conf->reset_val;
4498 source = conf->gen.reset_source;
4501 if (conf->assign_hook)
4502 if (!(*conf->assign_hook) (newval, changeVal, source))
4505 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4506 errmsg("invalid value for parameter \"%s\": %g",
4511 if (changeVal || makeDefault)
4513 /* Save old value to support transaction abort */
4515 push_old_value(&conf->gen);
4518 *conf->variable = newval;
4519 conf->gen.source = source;
4525 if (conf->gen.reset_source <= source)
4527 conf->reset_val = newval;
4528 conf->gen.reset_source = source;
4530 for (stack = conf->gen.stack; stack; stack = stack->prev)
4532 if (stack->source <= source)
4534 stack->value.realval = newval;
4535 stack->source = source;
4541 conf->gen.status |= GUC_HAVE_LOCAL;
4546 conf->tentative_val = newval;
4547 conf->gen.tentative_source = source;
4548 conf->gen.status |= GUC_HAVE_TENTATIVE;
4557 struct config_string *conf = (struct config_string *) record;
4562 newval = guc_strdup(elevel, value);
4567 * The only sort of "parsing" check we need to do is apply
4568 * truncation if GUC_IS_NAME.
4570 if (conf->gen.flags & GUC_IS_NAME)
4571 truncate_identifier(newval, strlen(newval), true);
4574 * If value == NULL and source == PGC_S_DEFAULT then
4575 * we reset some value to its default (removed from
4576 * configuration file).
4578 else if (source == PGC_S_DEFAULT)
4580 if (conf->boot_val == NULL)
4584 newval = guc_strdup(elevel, conf->boot_val);
4589 /* else we handle a "RESET varname" command */
4590 else if (conf->reset_val)
4593 * We could possibly avoid strdup here, but easier to make
4594 * this case work the same as the normal assignment case.
4596 newval = guc_strdup(elevel, conf->reset_val);
4599 source = conf->gen.reset_source;
4603 /* Nothing to reset to, as yet; so do nothing */
4607 if (conf->assign_hook)
4609 const char *hookresult;
4612 * If the hook ereports, we have to make sure we free
4613 * newval, else it will be a permanent memory leak.
4615 hookresult = call_string_assign_hook(conf->assign_hook,
4619 if (hookresult == NULL)
4623 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4624 errmsg("invalid value for parameter \"%s\": \"%s\"",
4625 name, value ? value : "")));
4628 else if (hookresult != newval)
4633 * Having to cast away const here is annoying, but the
4634 * alternative is to declare assign_hooks as returning
4635 * char*, which would mean they'd have to cast away
4636 * const, or as both taking and returning char*, which
4637 * doesn't seem attractive either --- we don't want
4638 * them to scribble on the passed str.
4640 newval = (char *) hookresult;
4644 if (changeVal || makeDefault)
4646 /* Save old value to support transaction abort */
4648 push_old_value(&conf->gen);
4651 set_string_field(conf, conf->variable, newval);
4652 conf->gen.source = source;
4658 if (conf->gen.reset_source <= source)
4660 set_string_field(conf, &conf->reset_val, newval);
4661 conf->gen.reset_source = source;
4663 for (stack = conf->gen.stack; stack; stack = stack->prev)
4665 if (stack->source <= source)
4667 set_string_field(conf, &stack->value.stringval,
4669 stack->source = source;
4672 /* Perhaps we didn't install newval anywhere */
4673 if (!string_field_used(conf, newval))
4678 conf->gen.status |= GUC_HAVE_LOCAL;
4683 set_string_field(conf, &conf->tentative_val, newval);
4684 conf->gen.tentative_source = source;
4685 conf->gen.status |= GUC_HAVE_TENTATIVE;
4695 if (changeVal && (record->flags & GUC_REPORT))
4696 ReportGUCOption(record);
4703 * Set a config option to the given value. See also set_config_option,
4704 * this is just the wrapper to be called from outside GUC. NB: this
4705 * is used only for non-transactional operations.
4708 SetConfigOption(const char *name, const char *value,
4709 GucContext context, GucSource source)
4711 (void) set_config_option(name, value, context, source, false, true);
4717 * Fetch the current value of the option `name'. If the option doesn't exist,
4718 * throw an ereport and don't return.
4720 * The string is *not* allocated for modification and is really only
4721 * valid until the next call to configuration related functions.
4724 GetConfigOption(const char *name)
4726 struct config_generic *record;
4727 static char buffer[256];
4729 record = find_option(name, ERROR);
4732 (errcode(ERRCODE_UNDEFINED_OBJECT),
4733 errmsg("unrecognized configuration parameter \"%s\"", name)));
4734 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
4736 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4737 errmsg("must be superuser to examine \"%s\"", name)));
4739 switch (record->vartype)
4742 return *((struct config_bool *) record)->variable ? "on" : "off";
4745 snprintf(buffer, sizeof(buffer), "%d",
4746 *((struct config_int *) record)->variable);
4750 snprintf(buffer, sizeof(buffer), "%g",
4751 *((struct config_real *) record)->variable);
4755 return *((struct config_string *) record)->variable;
4761 * Get the RESET value associated with the given option.
4764 GetConfigOptionResetString(const char *name)
4766 struct config_generic *record;
4767 static char buffer[256];
4769 record = find_option(name, ERROR);
4772 (errcode(ERRCODE_UNDEFINED_OBJECT),
4773 errmsg("unrecognized configuration parameter \"%s\"", name)));
4774 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
4776 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4777 errmsg("must be superuser to examine \"%s\"", name)));
4779 switch (record->vartype)
4782 return ((struct config_bool *) record)->reset_val ? "on" : "off";
4785 snprintf(buffer, sizeof(buffer), "%d",
4786 ((struct config_int *) record)->reset_val);
4790 snprintf(buffer, sizeof(buffer), "%g",
4791 ((struct config_real *) record)->reset_val);
4795 return ((struct config_string *) record)->reset_val;
4801 * Detect whether the given configuration option can only be set by
4805 IsSuperuserConfigOption(const char *name)
4807 struct config_generic *record;
4809 record = find_option(name, ERROR);
4810 /* On an unrecognized name, don't error, just return false. */
4813 return (record->context == PGC_SUSET);
4818 * flatten_set_variable_args
4819 * Given a parsenode List as emitted by the grammar for SET,
4820 * convert to the flat string representation used by GUC.
4822 * We need to be told the name of the variable the args are for, because
4823 * the flattening rules vary (ugh).
4825 * The result is NULL if input is NIL (ie, SET ... TO DEFAULT), otherwise
4826 * a palloc'd string.
4829 flatten_set_variable_args(const char *name, List *args)
4831 struct config_generic *record;
4837 * Fast path if just DEFAULT. We do not check the variable name in this
4838 * case --- necessary for RESET ALL to work correctly.
4843 /* Else get flags for the variable */
4844 record = find_option(name, ERROR);
4847 (errcode(ERRCODE_UNDEFINED_OBJECT),
4848 errmsg("unrecognized configuration parameter \"%s\"", name)));
4850 flags = record->flags;
4852 /* Complain if list input and non-list variable */
4853 if ((flags & GUC_LIST_INPUT) == 0 &&
4854 list_length(args) != 1)
4856 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4857 errmsg("SET %s takes only one argument", name)));
4859 initStringInfo(&buf);
4863 A_Const *arg = (A_Const *) lfirst(l);
4866 if (l != list_head(args))
4867 appendStringInfo(&buf, ", ");
4869 if (!IsA(arg, A_Const))
4870 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
4872 switch (nodeTag(&arg->val))
4875 appendStringInfo(&buf, "%ld", intVal(&arg->val));
4878 /* represented as a string, so just copy it */
4879 appendStringInfoString(&buf, strVal(&arg->val));
4882 val = strVal(&arg->val);
4883 if (arg->typename != NULL)
4886 * Must be a ConstInterval argument for TIME ZONE. Coerce
4887 * to interval and back to normalize the value and account
4894 typmod = typenameTypeMod(NULL, arg->typename, INTERVALOID);
4897 DirectFunctionCall3(interval_in,
4898 CStringGetDatum(val),
4899 ObjectIdGetDatum(InvalidOid),
4900 Int32GetDatum(typmod));
4903 DatumGetCString(DirectFunctionCall1(interval_out,
4905 appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
4910 * Plain string literal or identifier. For quote mode,
4911 * quote it if it's not a vanilla identifier.
4913 if (flags & GUC_LIST_QUOTE)
4914 appendStringInfoString(&buf, quote_identifier(val));
4916 appendStringInfoString(&buf, val);
4920 elog(ERROR, "unrecognized node type: %d",
4921 (int) nodeTag(&arg->val));
4934 SetPGVariable(const char *name, List *args, bool is_local)
4936 char *argstring = flatten_set_variable_args(name, args);
4938 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
4939 set_config_option(name,
4941 (superuser() ? PGC_SUSET : PGC_USERSET),
4948 * SET command wrapped as a SQL callable function.
4951 set_config_by_name(PG_FUNCTION_ARGS)
4959 if (PG_ARGISNULL(0))
4961 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
4962 errmsg("SET requires parameter name")));
4964 /* Get the GUC variable name */
4965 name = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(0)));
4967 /* Get the desired value or set to NULL for a reset request */
4968 if (PG_ARGISNULL(1))
4971 value = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(1)));
4974 * Get the desired state of is_local. Default to false if provided value
4977 if (PG_ARGISNULL(2))
4980 is_local = PG_GETARG_BOOL(2);
4982 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
4983 set_config_option(name,
4985 (superuser() ? PGC_SUSET : PGC_USERSET),
4990 /* get the new current value */
4991 new_value = GetConfigOptionByName(name, NULL);
4993 /* Convert return string to text */
4994 result_text = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(new_value)));
4997 PG_RETURN_TEXT_P(result_text);
5001 define_custom_variable(struct config_generic * variable)
5003 const char *name = variable->name;
5004 const char **nameAddr = &name;
5006 struct config_string *pHolder;
5007 struct config_generic **res = (struct config_generic **) bsearch(
5009 (void *) guc_variables,
5011 sizeof(struct config_generic *),
5016 add_guc_variable(variable, ERROR);
5021 * This better be a placeholder
5023 if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
5025 (errcode(ERRCODE_INTERNAL_ERROR),
5026 errmsg("attempt to redefine parameter \"%s\"", name)));
5028 Assert((*res)->vartype == PGC_STRING);
5029 pHolder = (struct config_string *) * res;
5031 /* We have the same name, no sorting is necessary */
5034 value = *pHolder->variable;
5037 * Assign the string value stored in the placeholder to the real variable.
5039 * XXX this is not really good enough --- it should be a nontransactional
5040 * assignment, since we don't want it to roll back if the current xact
5043 set_config_option(name, value,
5044 pHolder->gen.context, pHolder->gen.source,
5048 * Free up as much as we conveniently can of the placeholder structure
5049 * (this neglects any stack items...)
5051 set_string_field(pHolder, pHolder->variable, NULL);
5052 set_string_field(pHolder, &pHolder->reset_val, NULL);
5053 set_string_field(pHolder, &pHolder->tentative_val, NULL);
5059 init_custom_variable(struct config_generic * gen,
5061 const char *short_desc,
5062 const char *long_desc,
5064 enum config_type type)
5066 gen->name = guc_strdup(ERROR, name);
5067 gen->context = context;
5068 gen->group = CUSTOM_OPTIONS;
5069 gen->short_desc = short_desc;
5070 gen->long_desc = long_desc;
5071 gen->vartype = type;
5075 DefineCustomBoolVariable(const char *name,
5076 const char *short_desc,
5077 const char *long_desc,
5080 GucBoolAssignHook assign_hook,
5081 GucShowHook show_hook)
5083 size_t sz = sizeof(struct config_bool);
5084 struct config_bool *var = (struct config_bool *) guc_malloc(ERROR, sz);
5087 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_BOOL);
5089 var->variable = valueAddr;
5090 var->reset_val = *valueAddr;
5091 var->assign_hook = assign_hook;
5092 var->show_hook = show_hook;
5093 define_custom_variable(&var->gen);
5097 DefineCustomIntVariable(const char *name,
5098 const char *short_desc,
5099 const char *long_desc,
5104 GucIntAssignHook assign_hook,
5105 GucShowHook show_hook)
5107 size_t sz = sizeof(struct config_int);
5108 struct config_int *var = (struct config_int *) guc_malloc(ERROR, sz);
5111 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_INT);
5113 var->variable = valueAddr;
5114 var->reset_val = *valueAddr;
5115 var->min = minValue;
5116 var->max = maxValue;
5117 var->assign_hook = assign_hook;
5118 var->show_hook = show_hook;
5119 define_custom_variable(&var->gen);
5123 DefineCustomRealVariable(const char *name,
5124 const char *short_desc,
5125 const char *long_desc,
5130 GucRealAssignHook assign_hook,
5131 GucShowHook show_hook)
5133 size_t sz = sizeof(struct config_real);
5134 struct config_real *var = (struct config_real *) guc_malloc(ERROR, sz);
5137 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_REAL);
5139 var->variable = valueAddr;
5140 var->reset_val = *valueAddr;
5141 var->min = minValue;
5142 var->max = maxValue;
5143 var->assign_hook = assign_hook;
5144 var->show_hook = show_hook;
5145 define_custom_variable(&var->gen);
5149 DefineCustomStringVariable(const char *name,
5150 const char *short_desc,
5151 const char *long_desc,
5154 GucStringAssignHook assign_hook,
5155 GucShowHook show_hook)
5157 size_t sz = sizeof(struct config_string);
5158 struct config_string *var = (struct config_string *) guc_malloc(ERROR, sz);
5161 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_STRING);
5163 var->variable = valueAddr;
5164 var->reset_val = *valueAddr;
5165 var->assign_hook = assign_hook;
5166 var->show_hook = show_hook;
5167 define_custom_variable(&var->gen);
5171 EmitWarningsOnPlaceholders(const char *className)
5173 struct config_generic **vars = guc_variables;
5174 struct config_generic **last = vars + num_guc_variables;
5176 int nameLen = strlen(className);
5180 struct config_generic *var = *vars++;
5182 if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
5183 strncmp(className, var->name, nameLen) == 0 &&
5184 var->name[nameLen] == GUC_QUALIFIER_SEPARATOR)
5187 (errcode(ERRCODE_UNDEFINED_OBJECT),
5188 errmsg("unrecognized configuration parameter \"%s\"", var->name)));
5198 GetPGVariable(const char *name, DestReceiver *dest)
5200 if (pg_strcasecmp(name, "all") == 0)
5201 ShowAllGUCConfig(dest);
5203 ShowGUCConfigOption(name, dest);
5207 GetPGVariableResultDesc(const char *name)
5211 if (pg_strcasecmp(name, "all") == 0)
5213 /* need a tuple descriptor representing three TEXT columns */
5214 tupdesc = CreateTemplateTupleDesc(3, false);
5215 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
5217 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
5219 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
5225 const char *varname;
5227 /* Get the canonical spelling of name */
5228 (void) GetConfigOptionByName(name, &varname);
5230 /* need a tuple descriptor representing a single TEXT column */
5231 tupdesc = CreateTemplateTupleDesc(1, false);
5232 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
5242 ResetPGVariable(const char *name, bool isTopLevel)
5244 if (pg_strcasecmp(name, "all") == 0)
5247 set_config_option(name,
5249 (superuser() ? PGC_SUSET : PGC_USERSET),
5260 ShowGUCConfigOption(const char *name, DestReceiver *dest)
5262 TupOutputState *tstate;
5264 const char *varname;
5267 /* Get the value and canonical spelling of name */
5268 value = GetConfigOptionByName(name, &varname);
5270 /* need a tuple descriptor representing a single TEXT column */
5271 tupdesc = CreateTemplateTupleDesc(1, false);
5272 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
5275 /* prepare for projection of tuples */
5276 tstate = begin_tup_output_tupdesc(dest, tupdesc);
5279 do_text_output_oneline(tstate, value);
5281 end_tup_output(tstate);
5288 ShowAllGUCConfig(DestReceiver *dest)
5290 bool am_superuser = superuser();
5292 TupOutputState *tstate;
5296 /* need a tuple descriptor representing three TEXT columns */
5297 tupdesc = CreateTemplateTupleDesc(3, false);
5298 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
5300 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
5302 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
5306 /* prepare for projection of tuples */
5307 tstate = begin_tup_output_tupdesc(dest, tupdesc);
5309 for (i = 0; i < num_guc_variables; i++)
5311 struct config_generic *conf = guc_variables[i];
5313 if ((conf->flags & GUC_NO_SHOW_ALL) ||
5314 ((conf->flags & GUC_SUPERUSER_ONLY) && !am_superuser))
5317 /* assign to the values array */
5318 values[0] = (char *) conf->name;
5319 values[1] = _ShowOption(conf, true);
5320 values[2] = (char *) conf->short_desc;
5322 /* send it to dest */
5323 do_tup_output(tstate, values);
5326 if (values[1] != NULL)
5330 end_tup_output(tstate);
5334 * Return GUC variable value by name; optionally return canonical
5335 * form of name. Return value is palloc'd.
5338 GetConfigOptionByName(const char *name, const char **varname)
5340 struct config_generic *record;
5342 record = find_option(name, ERROR);
5345 (errcode(ERRCODE_UNDEFINED_OBJECT),
5346 errmsg("unrecognized configuration parameter \"%s\"", name)));
5347 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
5349 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5350 errmsg("must be superuser to examine \"%s\"", name)));
5353 *varname = record->name;
5355 return _ShowOption(record, true);
5359 * Return GUC variable value by variable number; optionally return canonical
5360 * form of name. Return value is palloc'd.
5363 GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
5366 struct config_generic *conf;
5368 /* check requested variable number valid */
5369 Assert((varnum >= 0) && (varnum < num_guc_variables));
5371 conf = guc_variables[varnum];
5375 if ((conf->flags & GUC_NO_SHOW_ALL) ||
5376 ((conf->flags & GUC_SUPERUSER_ONLY) && !superuser()))
5382 /* first get the generic attributes */
5385 values[0] = conf->name;
5387 /* setting : use _ShowOption in order to avoid duplicating the logic */
5388 values[1] = _ShowOption(conf, false);
5391 if (conf->vartype == PGC_INT)
5395 switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
5400 case GUC_UNIT_BLOCKS:
5401 snprintf(buf, sizeof(buf), "%dkB", BLCKSZ / 1024);
5404 case GUC_UNIT_XBLOCKS:
5405 snprintf(buf, sizeof(buf), "%dkB", XLOG_BLCKSZ / 1024);
5426 values[3] = config_group_names[conf->group];
5429 values[4] = conf->short_desc;
5432 values[5] = conf->long_desc;
5435 values[6] = GucContext_Names[conf->context];
5438 values[7] = config_type_names[conf->vartype];
5441 values[8] = GucSource_Names[conf->source];
5443 /* now get the type specifc attributes */
5444 switch (conf->vartype)
5458 struct config_int *lconf = (struct config_int *) conf;
5461 snprintf(buffer, sizeof(buffer), "%d", lconf->min);
5462 values[9] = pstrdup(buffer);
5465 snprintf(buffer, sizeof(buffer), "%d", lconf->max);
5466 values[10] = pstrdup(buffer);
5472 struct config_real *lconf = (struct config_real *) conf;
5475 snprintf(buffer, sizeof(buffer), "%g", lconf->min);
5476 values[9] = pstrdup(buffer);
5479 snprintf(buffer, sizeof(buffer), "%g", lconf->max);
5480 values[10] = pstrdup(buffer);
5497 * should never get here, but in case we do, set 'em to NULL
5511 * Return the total number of GUC variables
5514 GetNumConfigOptions(void)
5516 return num_guc_variables;
5520 * show_config_by_name - equiv to SHOW X command but implemented as
5524 show_config_by_name(PG_FUNCTION_ARGS)
5530 /* Get the GUC variable name */
5531 varname = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(0)));
5534 varval = GetConfigOptionByName(varname, NULL);
5536 /* Convert to text */
5537 result_text = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(varval)));
5540 PG_RETURN_TEXT_P(result_text);
5544 * show_all_settings - equiv to SHOW ALL command but implemented as
5547 #define NUM_PG_SETTINGS_ATTS 11
5550 show_all_settings(PG_FUNCTION_ARGS)
5552 FuncCallContext *funcctx;
5556 AttInMetadata *attinmeta;
5557 MemoryContext oldcontext;
5559 /* stuff done only on the first call of the function */
5560 if (SRF_IS_FIRSTCALL())
5562 /* create a function context for cross-call persistence */
5563 funcctx = SRF_FIRSTCALL_INIT();
5566 * switch to memory context appropriate for multiple function calls
5568 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
5571 * need a tuple descriptor representing NUM_PG_SETTINGS_ATTS columns
5572 * of the appropriate types
5574 tupdesc = CreateTemplateTupleDesc(NUM_PG_SETTINGS_ATTS, false);
5575 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
5577 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
5579 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "unit",
5581 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "category",
5583 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "short_desc",
5585 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "extra_desc",
5587 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "context",
5589 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "vartype",
5591 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "source",
5593 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "min_val",
5595 TupleDescInitEntry(tupdesc, (AttrNumber) 11, "max_val",
5599 * Generate attribute metadata needed later to produce tuples from raw
5602 attinmeta = TupleDescGetAttInMetadata(tupdesc);
5603 funcctx->attinmeta = attinmeta;
5605 /* total number of tuples to be returned */
5606 funcctx->max_calls = GetNumConfigOptions();
5608 MemoryContextSwitchTo(oldcontext);
5611 /* stuff done on every call of the function */
5612 funcctx = SRF_PERCALL_SETUP();
5614 call_cntr = funcctx->call_cntr;
5615 max_calls = funcctx->max_calls;
5616 attinmeta = funcctx->attinmeta;
5618 if (call_cntr < max_calls) /* do when there is more left to send */
5620 char *values[NUM_PG_SETTINGS_ATTS];
5626 * Get the next visible GUC variable name and value
5630 GetConfigOptionByNum(call_cntr, (const char **) values, &noshow);
5633 /* bump the counter and get the next config setting */
5634 call_cntr = ++funcctx->call_cntr;
5636 /* make sure we haven't gone too far now */
5637 if (call_cntr >= max_calls)
5638 SRF_RETURN_DONE(funcctx);
5643 tuple = BuildTupleFromCStrings(attinmeta, values);
5645 /* make the tuple into a datum */
5646 result = HeapTupleGetDatum(tuple);
5648 SRF_RETURN_NEXT(funcctx, result);
5652 /* do when there is no more left */
5653 SRF_RETURN_DONE(funcctx);
5658 _ShowOption(struct config_generic * record, bool use_units)
5663 switch (record->vartype)
5667 struct config_bool *conf = (struct config_bool *) record;
5669 if (conf->show_hook)
5670 val = (*conf->show_hook) ();
5672 val = *conf->variable ? "on" : "off";
5678 struct config_int *conf = (struct config_int *) record;
5680 if (conf->show_hook)
5681 val = (*conf->show_hook) ();
5685 int result = *conf->variable;
5687 if (use_units && result > 0 && (record->flags & GUC_UNIT_MEMORY))
5689 switch (record->flags & GUC_UNIT_MEMORY)
5691 case GUC_UNIT_BLOCKS:
5692 result *= BLCKSZ / 1024;
5694 case GUC_UNIT_XBLOCKS:
5695 result *= XLOG_BLCKSZ / 1024;
5699 if (result % KB_PER_GB == 0)
5701 result /= KB_PER_GB;
5704 else if (result % KB_PER_MB == 0)
5706 result /= KB_PER_MB;
5714 else if (use_units && result > 0 && (record->flags & GUC_UNIT_TIME))
5716 switch (record->flags & GUC_UNIT_TIME)
5722 result *= MS_PER_MIN;
5726 if (result % MS_PER_D == 0)
5731 else if (result % MS_PER_H == 0)
5736 else if (result % MS_PER_MIN == 0)
5738 result /= MS_PER_MIN;
5739 strcpy(unit, "min");
5741 else if (result % MS_PER_S == 0)
5754 snprintf(buffer, sizeof(buffer), "%d%s",
5755 (int) result, unit);
5763 struct config_real *conf = (struct config_real *) record;
5765 if (conf->show_hook)
5766 val = (*conf->show_hook) ();
5769 snprintf(buffer, sizeof(buffer), "%g",
5778 struct config_string *conf = (struct config_string *) record;
5780 if (conf->show_hook)
5781 val = (*conf->show_hook) ();
5782 else if (*conf->variable && **conf->variable)
5783 val = *conf->variable;
5790 /* just to keep compiler quiet */
5795 return pstrdup(val);
5800 is_newvalue_equal(struct config_generic * record, const char *newvalue)
5802 switch (record->vartype)
5806 struct config_bool *conf = (struct config_bool *) record;
5809 return parse_bool(newvalue, &newval)
5810 && *conf->variable == newval;
5814 struct config_int *conf = (struct config_int *) record;
5817 return parse_int(newvalue, &newval, record->flags, NULL)
5818 && *conf->variable == newval;
5822 struct config_real *conf = (struct config_real *) record;
5825 return parse_real(newvalue, &newval)
5826 && *conf->variable == newval;
5830 struct config_string *conf = (struct config_string *) record;
5832 return strcmp(*conf->variable, newvalue) == 0;
5843 * This routine dumps out all non-default GUC options into a binary
5844 * file that is read by all exec'ed backends. The format is:
5846 * variable name, string, null terminated
5847 * variable value, string, null terminated
5848 * variable source, integer
5851 write_nondefault_variables(GucContext context)
5857 Assert(context == PGC_POSTMASTER || context == PGC_SIGHUP);
5859 elevel = (context == PGC_SIGHUP) ? LOG : ERROR;
5864 fp = AllocateFile(CONFIG_EXEC_PARAMS_NEW, "w");
5868 (errcode_for_file_access(),
5869 errmsg("could not write to file \"%s\": %m",
5870 CONFIG_EXEC_PARAMS_NEW)));
5874 for (i = 0; i < num_guc_variables; i++)
5876 struct config_generic *gconf = guc_variables[i];
5878 if (gconf->source != PGC_S_DEFAULT)
5880 fprintf(fp, "%s", gconf->name);
5883 switch (gconf->vartype)
5887 struct config_bool *conf = (struct config_bool *) gconf;
5889 if (*conf->variable == 0)
5890 fprintf(fp, "false");
5892 fprintf(fp, "true");
5898 struct config_int *conf = (struct config_int *) gconf;
5900 fprintf(fp, "%d", *conf->variable);
5906 struct config_real *conf = (struct config_real *) gconf;
5908 /* Could lose precision here? */
5909 fprintf(fp, "%f", *conf->variable);
5915 struct config_string *conf = (struct config_string *) gconf;
5917 fprintf(fp, "%s", *conf->variable);
5924 fwrite(&gconf->source, sizeof(gconf->source), 1, fp);
5931 (errcode_for_file_access(),
5932 errmsg("could not write to file \"%s\": %m",
5933 CONFIG_EXEC_PARAMS_NEW)));
5938 * Put new file in place. This could delay on Win32, but we don't hold
5939 * any exclusive locks.
5941 rename(CONFIG_EXEC_PARAMS_NEW, CONFIG_EXEC_PARAMS);
5946 * Read string, including null byte from file
5948 * Return NULL on EOF and nothing read
5951 read_string_with_null(FILE *fp)
5960 if ((ch = fgetc(fp)) == EOF)
5965 elog(FATAL, "invalid format of exec config params file");
5968 str = guc_malloc(FATAL, maxlen);
5969 else if (i == maxlen)
5970 str = guc_realloc(FATAL, str, maxlen *= 2);
5979 * This routine loads a previous postmaster dump of its non-default
5983 read_nondefault_variables(void)
5993 fp = AllocateFile(CONFIG_EXEC_PARAMS, "r");
5996 /* File not found is fine */
5997 if (errno != ENOENT)
5999 (errcode_for_file_access(),
6000 errmsg("could not read from file \"%s\": %m",
6001 CONFIG_EXEC_PARAMS)));
6007 struct config_generic *record;
6009 if ((varname = read_string_with_null(fp)) == NULL)
6012 if ((record = find_option(varname, FATAL)) == NULL)
6013 elog(FATAL, "failed to locate variable %s in exec config params file", varname);
6014 if ((varvalue = read_string_with_null(fp)) == NULL)
6015 elog(FATAL, "invalid format of exec config params file");
6016 if (fread(&varsource, sizeof(varsource), 1, fp) == 0)
6017 elog(FATAL, "invalid format of exec config params file");
6019 (void) set_config_option(varname, varvalue, record->context,
6020 varsource, false, true);
6027 #endif /* EXEC_BACKEND */
6031 * A little "long argument" simulation, although not quite GNU
6032 * compliant. Takes a string of the form "some-option=some value" and
6033 * returns name = "some_option" and value = "some value" in malloc'ed
6034 * storage. Note that '-' is converted to '_' in the option name. If
6035 * there is no '=' in the input string then value will be NULL.
6038 ParseLongOption(const char *string, char **name, char **value)
6047 equal_pos = strcspn(string, "=");
6049 if (string[equal_pos] == '=')
6051 *name = guc_malloc(FATAL, equal_pos + 1);
6052 strlcpy(*name, string, equal_pos + 1);
6054 *value = guc_strdup(FATAL, &string[equal_pos + 1]);
6058 /* no equal sign in string */
6059 *name = guc_strdup(FATAL, string);
6063 for (cp = *name; *cp; cp++)
6070 * Handle options fetched from pg_database.datconfig or pg_authid.rolconfig.
6071 * The array parameter must be an array of TEXT (it must not be NULL).
6074 ProcessGUCArray(ArrayType *array, GucSource source)
6078 Assert(array != NULL);
6079 Assert(ARR_ELEMTYPE(array) == TEXTOID);
6080 Assert(ARR_NDIM(array) == 1);
6081 Assert(ARR_LBOUND(array)[0] == 1);
6082 Assert(source == PGC_S_DATABASE || source == PGC_S_USER);
6084 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
6092 d = array_ref(array, 1, &i,
6093 -1 /* varlenarray */ ,
6094 -1 /* TEXT's typlen */ ,
6095 false /* TEXT's typbyval */ ,
6096 'i' /* TEXT's typalign */ ,
6102 s = DatumGetCString(DirectFunctionCall1(textout, d));
6104 ParseLongOption(s, &name, &value);
6108 (errcode(ERRCODE_SYNTAX_ERROR),
6109 errmsg("could not parse setting for parameter \"%s\"", name)));
6115 * We process all these options at SUSET level. We assume that the
6116 * right to insert an option into pg_database or pg_authid was checked
6117 * when it was inserted.
6119 SetConfigOption(name, value, PGC_SUSET, source);
6129 * Add an entry to an option array. The array parameter may be NULL
6130 * to indicate the current table entry is NULL.
6133 GUCArrayAdd(ArrayType *array, const char *name, const char *value)
6135 const char *varname;
6143 /* test if the option is valid */
6144 set_config_option(name, value,
6145 superuser() ? PGC_SUSET : PGC_USERSET,
6146 PGC_S_TEST, false, false);
6148 /* convert name to canonical spelling, so we can use plain strcmp */
6149 (void) GetConfigOptionByName(name, &varname);
6152 newval = palloc(strlen(name) + 1 + strlen(value) + 1);
6153 sprintf(newval, "%s=%s", name, value);
6154 datum = DirectFunctionCall1(textin, CStringGetDatum(newval));
6162 Assert(ARR_ELEMTYPE(array) == TEXTOID);
6163 Assert(ARR_NDIM(array) == 1);
6164 Assert(ARR_LBOUND(array)[0] == 1);
6166 index = ARR_DIMS(array)[0] + 1; /* add after end */
6168 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
6173 d = array_ref(array, 1, &i,
6174 -1 /* varlenarray */ ,
6175 -1 /* TEXT's typlen */ ,
6176 false /* TEXT's typbyval */ ,
6177 'i' /* TEXT's typalign */ ,
6181 current = DatumGetCString(DirectFunctionCall1(textout, d));
6182 if (strncmp(current, newval, strlen(name) + 1) == 0)
6189 a = array_set(array, 1, &index,
6192 -1 /* varlena array */ ,
6193 -1 /* TEXT's typlen */ ,
6194 false /* TEXT's typbyval */ ,
6195 'i' /* TEXT's typalign */ );
6198 a = construct_array(&datum, 1,
6207 * Delete an entry from an option array. The array parameter may be NULL
6208 * to indicate the current table entry is NULL. Also, if the return value
6209 * is NULL then a null should be stored.
6212 GUCArrayDelete(ArrayType *array, const char *name)
6214 const char *varname;
6215 ArrayType *newarray;
6221 /* test if the option is valid */
6222 set_config_option(name, NULL,
6223 superuser() ? PGC_SUSET : PGC_USERSET,
6224 PGC_S_TEST, false, false);
6226 /* convert name to canonical spelling, so we can use plain strcmp */
6227 (void) GetConfigOptionByName(name, &varname);
6230 /* if array is currently null, then surely nothing to delete */
6237 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
6243 d = array_ref(array, 1, &i,
6244 -1 /* varlenarray */ ,
6245 -1 /* TEXT's typlen */ ,
6246 false /* TEXT's typbyval */ ,
6247 'i' /* TEXT's typalign */ ,
6251 val = DatumGetCString(DirectFunctionCall1(textout, d));
6253 /* ignore entry if it's what we want to delete */
6254 if (strncmp(val, name, strlen(name)) == 0
6255 && val[strlen(name)] == '=')
6258 /* else add it to the output array */
6261 newarray = array_set(newarray, 1, &index,
6264 -1 /* varlenarray */ ,
6265 -1 /* TEXT's typlen */ ,
6266 false /* TEXT's typbyval */ ,
6267 'i' /* TEXT's typalign */ );
6270 newarray = construct_array(&d, 1,
6282 * assign_hook subroutines
6286 assign_log_destination(const char *value, bool doit, GucSource source)
6293 /* Need a modifiable copy of string */
6294 rawstring = pstrdup(value);
6296 /* Parse string into list of identifiers */
6297 if (!SplitIdentifierString(rawstring, ',', &elemlist))
6299 /* syntax error in list */
6301 list_free(elemlist);
6302 if (source >= PGC_S_INTERACTIVE)
6304 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6305 errmsg("invalid list syntax for parameter \"log_destination\"")));
6309 foreach(l, elemlist)
6311 char *tok = (char *) lfirst(l);
6313 if (pg_strcasecmp(tok, "stderr") == 0)
6314 newlogdest |= LOG_DESTINATION_STDERR;
6316 else if (pg_strcasecmp(tok, "syslog") == 0)
6317 newlogdest |= LOG_DESTINATION_SYSLOG;
6320 else if (pg_strcasecmp(tok, "eventlog") == 0)
6321 newlogdest |= LOG_DESTINATION_EVENTLOG;
6325 if (source >= PGC_S_INTERACTIVE)
6327 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6328 errmsg("unrecognized \"log_destination\" key word: \"%s\"",
6331 list_free(elemlist);
6337 Log_destination = newlogdest;
6340 list_free(elemlist);
6348 assign_syslog_facility(const char *facility, bool doit, GucSource source)
6352 if (pg_strcasecmp(facility, "LOCAL0") == 0)
6353 syslog_fac = LOG_LOCAL0;
6354 else if (pg_strcasecmp(facility, "LOCAL1") == 0)
6355 syslog_fac = LOG_LOCAL1;
6356 else if (pg_strcasecmp(facility, "LOCAL2") == 0)
6357 syslog_fac = LOG_LOCAL2;
6358 else if (pg_strcasecmp(facility, "LOCAL3") == 0)
6359 syslog_fac = LOG_LOCAL3;
6360 else if (pg_strcasecmp(facility, "LOCAL4") == 0)
6361 syslog_fac = LOG_LOCAL4;
6362 else if (pg_strcasecmp(facility, "LOCAL5") == 0)
6363 syslog_fac = LOG_LOCAL5;
6364 else if (pg_strcasecmp(facility, "LOCAL6") == 0)
6365 syslog_fac = LOG_LOCAL6;
6366 else if (pg_strcasecmp(facility, "LOCAL7") == 0)
6367 syslog_fac = LOG_LOCAL7;
6369 return NULL; /* reject */
6373 syslog_facility = syslog_fac;
6374 set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
6382 assign_syslog_ident(const char *ident, bool doit, GucSource source)
6385 set_syslog_parameters(ident, syslog_facility);
6389 #endif /* HAVE_SYSLOG */
6393 assign_defaultxactisolevel(const char *newval, bool doit, GucSource source)
6395 if (pg_strcasecmp(newval, "serializable") == 0)
6398 DefaultXactIsoLevel = XACT_SERIALIZABLE;
6400 else if (pg_strcasecmp(newval, "repeatable read") == 0)
6403 DefaultXactIsoLevel = XACT_REPEATABLE_READ;
6405 else if (pg_strcasecmp(newval, "read committed") == 0)
6408 DefaultXactIsoLevel = XACT_READ_COMMITTED;
6410 else if (pg_strcasecmp(newval, "read uncommitted") == 0)
6413 DefaultXactIsoLevel = XACT_READ_UNCOMMITTED;
6421 assign_session_replication_role(const char *newval, bool doit, GucSource source)
6425 if (pg_strcasecmp(newval, "origin") == 0)
6426 newrole = SESSION_REPLICATION_ROLE_ORIGIN;
6427 else if (pg_strcasecmp(newval, "replica") == 0)
6428 newrole = SESSION_REPLICATION_ROLE_REPLICA;
6429 else if (pg_strcasecmp(newval, "local") == 0)
6430 newrole = SESSION_REPLICATION_ROLE_LOCAL;
6435 * Must flush the plan cache when changing replication role; but don't
6436 * flush unnecessarily.
6438 if (doit && SessionReplicationRole != newrole)
6441 SessionReplicationRole = newrole;
6448 assign_log_min_messages(const char *newval,
6449 bool doit, GucSource source)
6451 return (assign_msglvl(&log_min_messages, newval, doit, source));
6455 assign_client_min_messages(const char *newval, bool doit, GucSource source)
6457 return (assign_msglvl(&client_min_messages, newval, doit, source));
6461 assign_min_error_statement(const char *newval, bool doit, GucSource source)
6463 return (assign_msglvl(&log_min_error_statement, newval, doit, source));
6467 assign_msglvl(int *var, const char *newval, bool doit, GucSource source)
6469 if (pg_strcasecmp(newval, "debug") == 0)
6474 else if (pg_strcasecmp(newval, "debug5") == 0)
6479 else if (pg_strcasecmp(newval, "debug4") == 0)
6484 else if (pg_strcasecmp(newval, "debug3") == 0)
6489 else if (pg_strcasecmp(newval, "debug2") == 0)
6494 else if (pg_strcasecmp(newval, "debug1") == 0)
6499 else if (pg_strcasecmp(newval, "log") == 0)
6506 * Client_min_messages always prints 'info', but we allow it as a value
6509 else if (pg_strcasecmp(newval, "info") == 0)
6514 else if (pg_strcasecmp(newval, "notice") == 0)
6519 else if (pg_strcasecmp(newval, "warning") == 0)
6524 else if (pg_strcasecmp(newval, "error") == 0)
6529 /* We allow FATAL/PANIC for client-side messages too. */
6530 else if (pg_strcasecmp(newval, "fatal") == 0)
6535 else if (pg_strcasecmp(newval, "panic") == 0)
6541 return NULL; /* fail */
6542 return newval; /* OK */
6546 assign_log_error_verbosity(const char *newval, bool doit, GucSource source)
6548 if (pg_strcasecmp(newval, "terse") == 0)
6551 Log_error_verbosity = PGERROR_TERSE;
6553 else if (pg_strcasecmp(newval, "default") == 0)
6556 Log_error_verbosity = PGERROR_DEFAULT;
6558 else if (pg_strcasecmp(newval, "verbose") == 0)
6561 Log_error_verbosity = PGERROR_VERBOSE;
6564 return NULL; /* fail */
6565 return newval; /* OK */
6569 assign_log_statement(const char *newval, bool doit, GucSource source)
6571 if (pg_strcasecmp(newval, "none") == 0)
6574 log_statement = LOGSTMT_NONE;
6576 else if (pg_strcasecmp(newval, "ddl") == 0)
6579 log_statement = LOGSTMT_DDL;
6581 else if (pg_strcasecmp(newval, "mod") == 0)
6584 log_statement = LOGSTMT_MOD;
6586 else if (pg_strcasecmp(newval, "all") == 0)
6589 log_statement = LOGSTMT_ALL;
6592 return NULL; /* fail */
6593 return newval; /* OK */
6597 show_num_temp_buffers(void)
6600 * We show the GUC var until local buffers have been initialized, and
6601 * NLocBuffer afterwards.
6603 static char nbuf[32];
6605 sprintf(nbuf, "%d", NLocBuffer ? NLocBuffer : num_temp_buffers);
6610 assign_phony_autocommit(bool newval, bool doit, GucSource source)
6614 if (doit && source >= PGC_S_INTERACTIVE)
6616 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6617 errmsg("SET AUTOCOMMIT TO OFF is no longer supported")));
6624 assign_custom_variable_classes(const char *newval, bool doit, GucSource source)
6627 * Check syntax. newval must be a comma separated list of identifiers.
6628 * Whitespace is allowed but skipped.
6630 bool hasSpaceAfterToken = false;
6631 const char *cp = newval;
6637 * Resetting custom_variable_classes by removing it from the
6638 * configuration file will lead to newval = NULL
6641 return guc_strdup(ERROR, "");
6643 initStringInfo(&buf);
6644 while ((c = *cp++) != 0)
6646 if (isspace((unsigned char) c))
6649 hasSpaceAfterToken = true;
6655 hasSpaceAfterToken = false;
6659 appendStringInfoChar(&buf, ',');
6664 if (hasSpaceAfterToken || !isalnum((unsigned char) c))
6667 * Syntax error due to token following space after token or non
6668 * alpha numeric character
6671 (errcode(ERRCODE_SYNTAX_ERROR),
6672 errmsg("invalid syntax for \"custom_variable_classes\": \"%s\"", newval)));
6677 appendStringInfoChar(&buf, (char) c);
6680 /* Remove stray ',' at end */
6681 if (symLen == 0 && buf.len > 0)
6682 buf.data[--buf.len] = '\0';
6687 newval = guc_strdup(ERROR, buf.data);
6694 assign_debug_assertions(bool newval, bool doit, GucSource source)
6696 #ifndef USE_ASSERT_CHECKING
6699 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6700 errmsg("assertion checking is not supported by this build")));
6706 assign_ssl(bool newval, bool doit, GucSource source)
6711 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6712 errmsg("SSL is not supported by this build")));
6718 assign_stage_log_stats(bool newval, bool doit, GucSource source)
6720 if (newval && log_statement_stats)
6722 if (source >= PGC_S_INTERACTIVE)
6724 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6725 errmsg("cannot enable parameter when \"log_statement_stats\" is true")));
6726 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
6727 else if (source != PGC_S_OVERRIDE)
6734 assign_log_stats(bool newval, bool doit, GucSource source)
6737 (log_parser_stats || log_planner_stats || log_executor_stats))
6739 if (source >= PGC_S_INTERACTIVE)
6741 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6742 errmsg("cannot enable \"log_statement_stats\" when "
6743 "\"log_parser_stats\", \"log_planner_stats\", "
6744 "or \"log_executor_stats\" is true")));
6745 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
6746 else if (source != PGC_S_OVERRIDE)
6753 assign_transaction_read_only(bool newval, bool doit, GucSource source)
6755 /* Can't go to r/w mode inside a r/o transaction */
6756 if (newval == false && XactReadOnly && IsSubTransaction())
6758 if (source >= PGC_S_INTERACTIVE)
6760 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6761 errmsg("cannot set transaction read-write mode inside a read-only transaction")));
6762 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
6763 else if (source != PGC_S_OVERRIDE)
6770 assign_canonical_path(const char *newval, bool doit, GucSource source)
6774 char *canon_val = guc_strdup(ERROR, newval);
6776 canonicalize_path(canon_val);
6784 assign_backslash_quote(const char *newval, bool doit, GucSource source)
6786 BackslashQuoteType bq;
6790 * Although only "on", "off", and "safe_encoding" are documented, we use
6791 * parse_bool so we can accept all the likely variants of "on" and "off".
6793 if (pg_strcasecmp(newval, "safe_encoding") == 0)
6794 bq = BACKSLASH_QUOTE_SAFE_ENCODING;
6795 else if (parse_bool(newval, &bqbool))
6797 bq = bqbool ? BACKSLASH_QUOTE_ON : BACKSLASH_QUOTE_OFF;
6800 return NULL; /* reject */
6803 backslash_quote = bq;
6809 assign_timezone_abbreviations(const char *newval, bool doit, GucSource source)
6812 * The powerup value shown above for timezone_abbreviations is "UNKNOWN".
6813 * When we see this we just do nothing. If this value isn't overridden
6814 * from the config file then pg_timezone_abbrev_initialize() will
6815 * eventually replace it with "Default". This hack has two purposes: to
6816 * avoid wasting cycles loading values that might soon be overridden from
6817 * the config file, and to avoid trying to read the timezone abbrev files
6818 * during InitializeGUCOptions(). The latter doesn't work in an
6819 * EXEC_BACKEND subprocess because my_exec_path hasn't been set yet and so
6820 * we can't locate PGSHAREDIR. (Essentially the same hack is used to
6821 * delay initializing TimeZone ... if we have any more, we should try to
6822 * clean up and centralize this mechanism ...)
6824 if (strcmp(newval, "UNKNOWN") == 0)
6829 /* Loading abbrev file is expensive, so only do it when value changes */
6830 if (timezone_abbreviations_string == NULL ||
6831 strcmp(timezone_abbreviations_string, newval) != 0)
6836 * If reading config file, only the postmaster should bleat loudly
6837 * about problems. Otherwise, it's just this one process doing it,
6838 * and we use WARNING message level.
6840 if (source == PGC_S_FILE)
6841 elevel = IsUnderPostmaster ? DEBUG2 : LOG;
6844 if (!load_tzoffsets(newval, doit, elevel))
6851 * pg_timezone_abbrev_initialize --- set default value if not done already
6853 * This is called after initial loading of postgresql.conf. If no
6854 * timezone_abbreviations setting was found therein, select default.
6857 pg_timezone_abbrev_initialize(void)
6859 if (strcmp(timezone_abbreviations_string, "UNKNOWN") == 0)
6861 SetConfigOption("timezone_abbreviations", "Default",
6862 PGC_POSTMASTER, PGC_S_ARGV);
6867 assign_xmlbinary(const char *newval, bool doit, GucSource source)
6871 if (pg_strcasecmp(newval, "base64") == 0)
6872 xb = XMLBINARY_BASE64;
6873 else if (pg_strcasecmp(newval, "hex") == 0)
6876 return NULL; /* reject */
6885 assign_xmloption(const char *newval, bool doit, GucSource source)
6889 if (pg_strcasecmp(newval, "document") == 0)
6890 xo = XMLOPTION_DOCUMENT;
6891 else if (pg_strcasecmp(newval, "content") == 0)
6892 xo = XMLOPTION_CONTENT;
6894 return NULL; /* reject */
6903 assign_tcp_keepalives_idle(int newval, bool doit, GucSource source)
6906 return (pq_setkeepalivesidle(newval, MyProcPort) == STATUS_OK);
6912 show_tcp_keepalives_idle(void)
6914 static char nbuf[16];
6916 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesidle(MyProcPort));
6921 assign_tcp_keepalives_interval(int newval, bool doit, GucSource source)
6924 return (pq_setkeepalivesinterval(newval, MyProcPort) == STATUS_OK);
6930 show_tcp_keepalives_interval(void)
6932 static char nbuf[16];
6934 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesinterval(MyProcPort));
6939 assign_tcp_keepalives_count(int newval, bool doit, GucSource source)
6942 return (pq_setkeepalivescount(newval, MyProcPort) == STATUS_OK);
6948 show_tcp_keepalives_count(void)
6950 static char nbuf[16];
6952 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivescount(MyProcPort));
6957 assign_maxconnections(int newval, bool doit, GucSource source)
6959 if (newval + autovacuum_max_workers > INT_MAX / 4)
6963 MaxBackends = newval + autovacuum_max_workers;
6969 assign_autovacuum_max_workers(int newval, bool doit, GucSource source)
6971 if (newval + MaxConnections > INT_MAX / 4)
6975 MaxBackends = newval + MaxConnections;
6980 #include "guc-file.c"