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-2006, PostgreSQL Global Development Group
10 * Written by Peter Eisentraut <peter_e@gmx.net>.
13 * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.357 2006/10/19 18:32:47 tgl Exp $
15 *--------------------------------------------------------------------
29 #include "access/gin.h"
30 #include "access/twophase.h"
31 #include "access/xact.h"
32 #include "catalog/namespace.h"
33 #include "commands/async.h"
34 #include "commands/vacuum.h"
35 #include "commands/variable.h"
37 #include "libpq/auth.h"
38 #include "libpq/pqformat.h"
39 #include "miscadmin.h"
40 #include "optimizer/cost.h"
41 #include "optimizer/geqo.h"
42 #include "optimizer/paths.h"
43 #include "optimizer/planmain.h"
44 #include "parser/gramparse.h"
45 #include "parser/parse_expr.h"
46 #include "parser/parse_relation.h"
47 #include "parser/scansup.h"
49 #include "postmaster/autovacuum.h"
50 #include "postmaster/bgwriter.h"
51 #include "postmaster/postmaster.h"
52 #include "postmaster/syslogger.h"
53 #include "storage/fd.h"
54 #include "storage/freespace.h"
55 #include "tcop/tcopprot.h"
56 #include "utils/builtins.h"
57 #include "utils/guc_tables.h"
58 #include "utils/memutils.h"
59 #include "utils/pg_locale.h"
60 #include "utils/ps_status.h"
61 #include "utils/tzparser.h"
64 #define PG_KRB_SRVTAB ""
67 #define PG_KRB_SRVNAM ""
70 #define CONFIG_FILENAME "postgresql.conf"
71 #define HBA_FILENAME "pg_hba.conf"
72 #define IDENT_FILENAME "pg_ident.conf"
75 #define CONFIG_EXEC_PARAMS "global/config_exec_params"
76 #define CONFIG_EXEC_PARAMS_NEW "global/config_exec_params.new"
79 /* upper limit for GUC variables measured in kilobytes of memory */
81 #define MAX_KILOBYTES INT_MAX
83 #define MAX_KILOBYTES (INT_MAX / 1024)
86 #define KB_PER_MB (1024)
87 #define KB_PER_GB (1024*1024)
90 #define MS_PER_MIN (1000 * 60)
91 #define MS_PER_H (1000 * 60 * 60)
92 #define MS_PER_D (1000 * 60 * 60 * 24)
94 /* XXX these should appear in other modules' header files */
95 extern bool Log_disconnections;
96 extern int CommitDelay;
97 extern int CommitSiblings;
98 extern char *default_tablespace;
99 extern bool fullPageWrites;
102 extern bool trace_sort;
105 static const char *assign_log_destination(const char *value,
106 bool doit, GucSource source);
109 static int syslog_facility = LOG_LOCAL0;
111 static const char *assign_syslog_facility(const char *facility,
112 bool doit, GucSource source);
113 static const char *assign_syslog_ident(const char *ident,
114 bool doit, GucSource source);
117 static const char *assign_defaultxactisolevel(const char *newval, bool doit,
119 static const char *assign_log_min_messages(const char *newval, bool doit,
121 static const char *assign_client_min_messages(const char *newval,
122 bool doit, GucSource source);
123 static const char *assign_min_error_statement(const char *newval, bool doit,
125 static const char *assign_msglvl(int *var, const char *newval, bool doit,
127 static const char *assign_log_error_verbosity(const char *newval, bool doit,
129 static const char *assign_log_statement(const char *newval, bool doit,
131 static const char *show_num_temp_buffers(void);
132 static bool assign_phony_autocommit(bool newval, bool doit, GucSource source);
133 static const char *assign_custom_variable_classes(const char *newval, bool doit,
135 static bool assign_debug_assertions(bool newval, bool doit, GucSource source);
136 static bool assign_ssl(bool newval, bool doit, GucSource source);
137 static bool assign_stage_log_stats(bool newval, bool doit, GucSource source);
138 static bool assign_log_stats(bool newval, bool doit, GucSource source);
139 static bool assign_transaction_read_only(bool newval, bool doit, GucSource source);
140 static const char *assign_canonical_path(const char *newval, bool doit, GucSource source);
141 static const char *assign_backslash_quote(const char *newval, bool doit, GucSource source);
142 static const char *assign_timezone_abbreviations(const char *newval, bool doit, GucSource source);
144 static bool assign_tcp_keepalives_idle(int newval, bool doit, GucSource source);
145 static bool assign_tcp_keepalives_interval(int newval, bool doit, GucSource source);
146 static bool assign_tcp_keepalives_count(int newval, bool doit, GucSource source);
147 static const char *show_tcp_keepalives_idle(void);
148 static const char *show_tcp_keepalives_interval(void);
149 static const char *show_tcp_keepalives_count(void);
152 * GUC option variables that are exported from this module
154 #ifdef USE_ASSERT_CHECKING
155 bool assert_enabled = true;
157 bool assert_enabled = false;
159 bool log_duration = false;
160 bool Debug_print_plan = false;
161 bool Debug_print_parse = false;
162 bool Debug_print_rewritten = false;
163 bool Debug_pretty_print = false;
164 bool Explain_pretty_print = true;
166 bool log_parser_stats = false;
167 bool log_planner_stats = false;
168 bool log_executor_stats = false;
169 bool log_statement_stats = false; /* this is sort of all three
171 bool log_btree_build_stats = false;
173 bool check_function_bodies = true;
174 bool default_with_oids = false;
175 bool SQL_inheritance = true;
177 bool Password_encryption = true;
179 int log_min_error_statement = PANIC;
180 int log_min_messages = NOTICE;
181 int client_min_messages = NOTICE;
182 int log_min_duration_statement = -1;
184 int num_temp_buffers = 1000;
186 char *ConfigFileName;
189 char *external_pid_file;
191 int tcp_keepalives_idle;
192 int tcp_keepalives_interval;
193 int tcp_keepalives_count;
196 * These variables are all dummies that don't do anything, except in some
197 * cases provide the value for SHOW to display. The real state is elsewhere
198 * and is kept in sync by assign_hooks.
200 static char *client_min_messages_str;
201 static char *log_min_messages_str;
202 static char *log_error_verbosity_str;
203 static char *log_statement_str;
204 static char *log_min_error_statement_str;
205 static char *log_destination_string;
208 static char *syslog_facility_str;
209 static char *syslog_ident_str;
211 static bool phony_autocommit;
212 static bool session_auth_is_superuser;
213 static double phony_random_seed;
214 static char *backslash_quote_string;
215 static char *client_encoding_string;
216 static char *datestyle_string;
217 static char *default_iso_level_string;
218 static char *locale_collate;
219 static char *locale_ctype;
220 static char *regex_flavor_string;
221 static char *server_encoding_string;
222 static char *server_version_string;
223 static int server_version_num;
224 static char *timezone_string;
225 static char *timezone_abbreviations_string;
226 static char *XactIsoLevel_string;
227 static char *data_directory;
228 static char *custom_variable_classes;
229 static int max_function_args;
230 static int max_index_keys;
231 static int max_identifier_length;
232 static int block_size;
233 static bool integer_datetimes;
235 /* should be static, but commands/variable.c needs to get at these */
237 char *session_authorization_string;
241 * Displayable names for context types (enum GucContext)
243 * Note: these strings are deliberately not localized.
245 const char *const GucContext_Names[] =
247 /* PGC_INTERNAL */ "internal",
248 /* PGC_POSTMASTER */ "postmaster",
249 /* PGC_SIGHUP */ "sighup",
250 /* PGC_BACKEND */ "backend",
251 /* PGC_SUSET */ "superuser",
252 /* PGC_USERSET */ "user"
256 * Displayable names for source types (enum GucSource)
258 * Note: these strings are deliberately not localized.
260 const char *const GucSource_Names[] =
262 /* PGC_S_DEFAULT */ "default",
263 /* PGC_S_ENV_VAR */ "environment variable",
264 /* PGC_S_FILE */ "configuration file",
265 /* PGC_S_ARGV */ "command line",
266 /* PGC_S_DATABASE */ "database",
267 /* PGC_S_USER */ "user",
268 /* PGC_S_CLIENT */ "client",
269 /* PGC_S_OVERRIDE */ "override",
270 /* PGC_S_INTERACTIVE */ "interactive",
271 /* PGC_S_TEST */ "test",
272 /* PGC_S_SESSION */ "session"
276 * Displayable names for the groupings defined in enum config_group
278 const char *const config_group_names[] =
281 gettext_noop("Ungrouped"),
283 gettext_noop("File Locations"),
285 gettext_noop("Connections and Authentication"),
286 /* CONN_AUTH_SETTINGS */
287 gettext_noop("Connections and Authentication / Connection Settings"),
288 /* CONN_AUTH_SECURITY */
289 gettext_noop("Connections and Authentication / Security and Authentication"),
291 gettext_noop("Resource Usage"),
293 gettext_noop("Resource Usage / Memory"),
295 gettext_noop("Resource Usage / Free Space Map"),
296 /* RESOURCES_KERNEL */
297 gettext_noop("Resource Usage / Kernel Resources"),
299 gettext_noop("Write-Ahead Log"),
301 gettext_noop("Write-Ahead Log / Settings"),
302 /* WAL_CHECKPOINTS */
303 gettext_noop("Write-Ahead Log / Checkpoints"),
305 gettext_noop("Query Tuning"),
306 /* QUERY_TUNING_METHOD */
307 gettext_noop("Query Tuning / Planner Method Configuration"),
308 /* QUERY_TUNING_COST */
309 gettext_noop("Query Tuning / Planner Cost Constants"),
310 /* QUERY_TUNING_GEQO */
311 gettext_noop("Query Tuning / Genetic Query Optimizer"),
312 /* QUERY_TUNING_OTHER */
313 gettext_noop("Query Tuning / Other Planner Options"),
315 gettext_noop("Reporting and Logging"),
317 gettext_noop("Reporting and Logging / Where to Log"),
319 gettext_noop("Reporting and Logging / When to Log"),
321 gettext_noop("Reporting and Logging / What to Log"),
323 gettext_noop("Statistics"),
324 /* STATS_MONITORING */
325 gettext_noop("Statistics / Monitoring"),
326 /* STATS_COLLECTOR */
327 gettext_noop("Statistics / Query and Index Statistics Collector"),
329 gettext_noop("Autovacuum"),
331 gettext_noop("Client Connection Defaults"),
332 /* CLIENT_CONN_STATEMENT */
333 gettext_noop("Client Connection Defaults / Statement Behavior"),
334 /* CLIENT_CONN_LOCALE */
335 gettext_noop("Client Connection Defaults / Locale and Formatting"),
336 /* CLIENT_CONN_OTHER */
337 gettext_noop("Client Connection Defaults / Other Defaults"),
338 /* LOCK_MANAGEMENT */
339 gettext_noop("Lock Management"),
341 gettext_noop("Version and Platform Compatibility"),
342 /* COMPAT_OPTIONS_PREVIOUS */
343 gettext_noop("Version and Platform Compatibility / Previous PostgreSQL Versions"),
344 /* COMPAT_OPTIONS_CLIENT */
345 gettext_noop("Version and Platform Compatibility / Other Platforms and Clients"),
347 gettext_noop("Preset Options"),
349 gettext_noop("Customized Options"),
350 /* DEVELOPER_OPTIONS */
351 gettext_noop("Developer Options"),
352 /* help_config wants this array to be null-terminated */
357 * Displayable names for GUC variable types (enum config_type)
359 * Note: these strings are deliberately not localized.
361 const char *const config_type_names[] =
363 /* PGC_BOOL */ "bool",
364 /* PGC_INT */ "integer",
365 /* PGC_REAL */ "real",
366 /* PGC_STRING */ "string"
371 * Contents of GUC tables
373 * See src/backend/utils/misc/README for design notes.
377 * 1. Declare a global variable of type bool, int, double, or char*
378 * and make use of it.
380 * 2. Decide at what times it's safe to set the option. See guc.h for
383 * 3. Decide on a name, a default value, upper and lower bounds (if
386 * 4. Add a record below.
388 * 5. Add it to src/backend/utils/misc/postgresql.conf.sample, if
391 * 6. Add it to src/bin/psql/tab-complete.c, if it's a USERSET option.
393 * 7. Don't forget to document the option.
395 * 8. If it's a new GUC_LIST option you must edit pg_dumpall.c to ensure
396 * it is not single quoted at dump time.
400 /******** option records follow ********/
402 static struct config_bool ConfigureNamesBool[] =
405 {"enable_seqscan", PGC_USERSET, QUERY_TUNING_METHOD,
406 gettext_noop("Enables the planner's use of sequential-scan plans."),
413 {"enable_indexscan", PGC_USERSET, QUERY_TUNING_METHOD,
414 gettext_noop("Enables the planner's use of index-scan plans."),
421 {"enable_bitmapscan", PGC_USERSET, QUERY_TUNING_METHOD,
422 gettext_noop("Enables the planner's use of bitmap-scan plans."),
429 {"enable_tidscan", PGC_USERSET, QUERY_TUNING_METHOD,
430 gettext_noop("Enables the planner's use of TID scan plans."),
437 {"enable_sort", PGC_USERSET, QUERY_TUNING_METHOD,
438 gettext_noop("Enables the planner's use of explicit sort steps."),
445 {"enable_hashagg", PGC_USERSET, QUERY_TUNING_METHOD,
446 gettext_noop("Enables the planner's use of hashed aggregation plans."),
453 {"enable_nestloop", PGC_USERSET, QUERY_TUNING_METHOD,
454 gettext_noop("Enables the planner's use of nested-loop join plans."),
461 {"enable_mergejoin", PGC_USERSET, QUERY_TUNING_METHOD,
462 gettext_noop("Enables the planner's use of merge join plans."),
469 {"enable_hashjoin", PGC_USERSET, QUERY_TUNING_METHOD,
470 gettext_noop("Enables the planner's use of hash join plans."),
477 {"constraint_exclusion", PGC_USERSET, QUERY_TUNING_OTHER,
478 gettext_noop("Enables the planner to use constraints to optimize queries."),
479 gettext_noop("Child table scans will be skipped if their "
480 "constraints guarantee that no rows match the query.")
482 &constraint_exclusion,
486 {"geqo", PGC_USERSET, QUERY_TUNING_GEQO,
487 gettext_noop("Enables genetic query optimization."),
488 gettext_noop("This algorithm attempts to do planning without "
489 "exhaustive searching.")
495 /* Not for general use --- used by SET SESSION AUTHORIZATION */
496 {"is_superuser", PGC_INTERNAL, UNGROUPED,
497 gettext_noop("Shows whether the current user is a superuser."),
499 GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
501 &session_auth_is_superuser,
505 {"ssl", PGC_POSTMASTER, CONN_AUTH_SECURITY,
506 gettext_noop("Enables SSL connections."),
510 false, assign_ssl, NULL
513 {"fsync", PGC_SIGHUP, WAL_SETTINGS,
514 gettext_noop("Forces synchronization of updates to disk."),
515 gettext_noop("The server will use the fsync() system call in several places to make "
516 "sure that updates are physically written to disk. This insures "
517 "that a database cluster will recover to a consistent state after "
518 "an operating system or hardware crash.")
524 {"zero_damaged_pages", PGC_SUSET, DEVELOPER_OPTIONS,
525 gettext_noop("Continues processing past damaged page headers."),
526 gettext_noop("Detection of a damaged page header normally causes PostgreSQL to "
527 "report an error, aborting the current transaction. Setting "
528 "zero_damaged_pages to true causes the system to instead report a "
529 "warning, zero out the damaged page, and continue processing. This "
530 "behavior will destroy data, namely all the rows on the damaged page."),
537 {"full_page_writes", PGC_SIGHUP, WAL_SETTINGS,
538 gettext_noop("Writes full pages to WAL when first modified after a checkpoint."),
539 gettext_noop("A page write in process during an operating system crash might be "
540 "only partially written to disk. During recovery, the row changes "
541 "stored in WAL are not enough to recover. This option writes "
542 "pages when first modified after a checkpoint to WAL so full recovery "
549 {"silent_mode", PGC_POSTMASTER, LOGGING_WHEN,
550 gettext_noop("Runs the server silently."),
551 gettext_noop("If this parameter is set, the server will automatically run in the "
552 "background and any controlling terminals are dissociated.")
558 {"log_connections", PGC_BACKEND, LOGGING_WHAT,
559 gettext_noop("Logs each successful connection."),
566 {"log_disconnections", PGC_BACKEND, LOGGING_WHAT,
567 gettext_noop("Logs end of a session, including duration."),
574 {"debug_assertions", PGC_USERSET, DEVELOPER_OPTIONS,
575 gettext_noop("Turns on various assertion checks."),
576 gettext_noop("This is a debugging aid."),
580 #ifdef USE_ASSERT_CHECKING
585 assign_debug_assertions, NULL
588 /* currently undocumented, so don't show in SHOW ALL */
589 {"exit_on_error", PGC_USERSET, UNGROUPED,
590 gettext_noop("no description available"),
592 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
598 {"log_duration", PGC_SUSET, LOGGING_WHAT,
599 gettext_noop("Logs the duration of each completed SQL statement."),
606 {"debug_print_parse", PGC_USERSET, LOGGING_WHAT,
607 gettext_noop("Prints the parse tree to the server log."),
614 {"debug_print_rewritten", PGC_USERSET, LOGGING_WHAT,
615 gettext_noop("Prints the parse tree after rewriting to server log."),
618 &Debug_print_rewritten,
622 {"debug_print_plan", PGC_USERSET, LOGGING_WHAT,
623 gettext_noop("Prints the execution plan to server log."),
630 {"debug_pretty_print", PGC_USERSET, LOGGING_WHAT,
631 gettext_noop("Indents parse and plan tree displays."),
638 {"log_parser_stats", PGC_SUSET, STATS_MONITORING,
639 gettext_noop("Writes parser performance statistics to the server log."),
643 false, assign_stage_log_stats, NULL
646 {"log_planner_stats", PGC_SUSET, STATS_MONITORING,
647 gettext_noop("Writes planner performance statistics to the server log."),
651 false, assign_stage_log_stats, NULL
654 {"log_executor_stats", PGC_SUSET, STATS_MONITORING,
655 gettext_noop("Writes executor performance statistics to the server log."),
659 false, assign_stage_log_stats, NULL
662 {"log_statement_stats", PGC_SUSET, STATS_MONITORING,
663 gettext_noop("Writes cumulative performance statistics to the server log."),
666 &log_statement_stats,
667 false, assign_log_stats, NULL
669 #ifdef BTREE_BUILD_STATS
671 {"log_btree_build_stats", PGC_SUSET, DEVELOPER_OPTIONS,
672 gettext_noop("no description available"),
676 &log_btree_build_stats,
682 {"explain_pretty_print", PGC_USERSET, CLIENT_CONN_OTHER,
683 gettext_noop("Uses the indented output format for EXPLAIN VERBOSE."),
686 &Explain_pretty_print,
690 {"stats_start_collector", PGC_POSTMASTER, STATS_COLLECTOR,
691 gettext_noop("Starts the server statistics-collection subprocess."),
694 &pgstat_collect_startcollector,
698 {"stats_reset_on_server_start", PGC_POSTMASTER, STATS_COLLECTOR,
699 gettext_noop("Zeroes collected statistics on server restart."),
702 &pgstat_collect_resetonpmstart,
706 {"stats_row_level", PGC_SUSET, STATS_COLLECTOR,
707 gettext_noop("Collects row-level statistics on database activity."),
710 &pgstat_collect_tuplelevel,
714 {"stats_block_level", PGC_SUSET, STATS_COLLECTOR,
715 gettext_noop("Collects block-level statistics on database activity."),
718 &pgstat_collect_blocklevel,
723 {"stats_command_string", PGC_SUSET, STATS_COLLECTOR,
724 gettext_noop("Collects information about executing commands."),
725 gettext_noop("Enables the collection of information on the currently "
726 "executing command of each session, along with the time "
727 "at which that command began execution.")
729 &pgstat_collect_querystring,
734 {"update_process_title", PGC_SUSET, STATS_COLLECTOR,
735 gettext_noop("Updates the process title to show the active SQL command."),
736 gettext_noop("Enables updating of the process title every time a new SQL command is received by the server.")
738 &update_process_title,
743 {"autovacuum", PGC_SIGHUP, AUTOVACUUM,
744 gettext_noop("Starts the autovacuum subprocess."),
747 &autovacuum_start_daemon,
752 {"trace_notify", PGC_USERSET, DEVELOPER_OPTIONS,
753 gettext_noop("Generates debugging output for LISTEN and NOTIFY."),
763 {"trace_locks", PGC_SUSET, DEVELOPER_OPTIONS,
764 gettext_noop("no description available"),
772 {"trace_userlocks", PGC_SUSET, DEVELOPER_OPTIONS,
773 gettext_noop("no description available"),
781 {"trace_lwlocks", PGC_SUSET, DEVELOPER_OPTIONS,
782 gettext_noop("no description available"),
790 {"debug_deadlocks", PGC_SUSET, DEVELOPER_OPTIONS,
791 gettext_noop("no description available"),
801 {"log_hostname", PGC_SIGHUP, LOGGING_WHAT,
802 gettext_noop("Logs the host name in the connection logs."),
803 gettext_noop("By default, connection logs only show the IP address "
804 "of the connecting host. If you want them to show the host name you "
805 "can turn this on, but depending on your host name resolution "
806 "setup it might impose a non-negligible performance penalty.")
812 {"sql_inheritance", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
813 gettext_noop("Causes subtables to be included by default in various commands."),
820 {"password_encryption", PGC_USERSET, CONN_AUTH_SECURITY,
821 gettext_noop("Encrypt passwords."),
822 gettext_noop("When a password is specified in CREATE USER or "
823 "ALTER USER without writing either ENCRYPTED or UNENCRYPTED, "
824 "this parameter determines whether the password is to be encrypted.")
826 &Password_encryption,
830 {"transform_null_equals", PGC_USERSET, COMPAT_OPTIONS_CLIENT,
831 gettext_noop("Treats \"expr=NULL\" as \"expr IS NULL\"."),
832 gettext_noop("When turned on, expressions of the form expr = NULL "
833 "(or NULL = expr) are treated as expr IS NULL, that is, they "
834 "return true if expr evaluates to the null value, and false "
835 "otherwise. The correct behavior of expr = NULL is to always "
836 "return null (unknown).")
838 &Transform_null_equals,
842 {"db_user_namespace", PGC_SIGHUP, CONN_AUTH_SECURITY,
843 gettext_noop("Enables per-database user names."),
850 /* only here for backwards compatibility */
851 {"autocommit", PGC_USERSET, CLIENT_CONN_STATEMENT,
852 gettext_noop("This parameter doesn't do anything."),
853 gettext_noop("It's just here so that we won't choke on SET AUTOCOMMIT TO ON from 7.3-vintage clients."),
854 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
857 true, assign_phony_autocommit, NULL
860 {"default_transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
861 gettext_noop("Sets the default read-only status of new transactions."),
864 &DefaultXactReadOnly,
868 {"transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
869 gettext_noop("Sets the current transaction's read-only status."),
871 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
874 false, assign_transaction_read_only, NULL
877 {"add_missing_from", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
878 gettext_noop("Automatically adds missing table references to FROM clauses."),
885 {"check_function_bodies", PGC_USERSET, CLIENT_CONN_STATEMENT,
886 gettext_noop("Check function bodies during CREATE FUNCTION."),
889 &check_function_bodies,
893 {"array_nulls", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
894 gettext_noop("Enable input of NULL elements in arrays."),
895 gettext_noop("When turned on, unquoted NULL in an array input "
896 "value means a null value; "
897 "otherwise it is taken literally.")
903 {"default_with_oids", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
904 gettext_noop("Create new tables with OIDs by default."),
911 {"redirect_stderr", PGC_POSTMASTER, LOGGING_WHERE,
912 gettext_noop("Start a subprocess to capture stderr output into log files."),
919 {"log_truncate_on_rotation", PGC_SIGHUP, LOGGING_WHERE,
920 gettext_noop("Truncate existing log files of same name during log rotation."),
923 &Log_truncate_on_rotation,
929 {"trace_sort", PGC_USERSET, DEVELOPER_OPTIONS,
930 gettext_noop("Emit information about resource usage in sorting."),
941 {"wal_debug", PGC_SUSET, DEVELOPER_OPTIONS,
942 gettext_noop("Emit WAL-related debugging output."),
952 {"integer_datetimes", PGC_INTERNAL, PRESET_OPTIONS,
953 gettext_noop("Datetimes are integer based."),
955 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
958 #ifdef HAVE_INT64_TIMESTAMP
966 {"krb_caseins_users", PGC_POSTMASTER, CONN_AUTH_SECURITY,
967 gettext_noop("Sets whether Kerberos user names should be treated as case-insensitive."),
970 &pg_krb_caseins_users,
975 {"escape_string_warning", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
976 gettext_noop("Warn about backslash escapes in ordinary string literals."),
979 &escape_string_warning,
984 {"standard_conforming_strings", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
985 gettext_noop("'...' strings treat backslashes literally."),
989 &standard_conforming_strings,
994 {"allow_system_table_mods", PGC_POSTMASTER, DEVELOPER_OPTIONS,
995 gettext_noop("Allows modifications of the structure of system tables."),
999 &allowSystemTableMods,
1004 {"ignore_system_indexes", PGC_BACKEND, DEVELOPER_OPTIONS,
1005 gettext_noop("Disables reading from system indexes."),
1006 gettext_noop("It does not prevent updating the indexes, so it is safe "
1007 "to use. The worst consequence is slowness."),
1010 &IgnoreSystemIndexes,
1014 /* End-of-list marker */
1016 {NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL
1021 static struct config_int ConfigureNamesInt[] =
1024 {"archive_timeout", PGC_SIGHUP, WAL_SETTINGS,
1025 gettext_noop("Forces a switch to the next xlog file if a "
1026 "new file has not been started within N seconds."),
1030 &XLogArchiveTimeout,
1031 0, 0, INT_MAX, NULL, NULL
1034 {"post_auth_delay", PGC_BACKEND, DEVELOPER_OPTIONS,
1035 gettext_noop("Waits N seconds on connection startup after authentication."),
1036 gettext_noop("This allows attaching a debugger to the process."),
1037 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1040 0, 0, INT_MAX, NULL, NULL
1043 {"default_statistics_target", PGC_USERSET, QUERY_TUNING_OTHER,
1044 gettext_noop("Sets the default statistics target."),
1045 gettext_noop("This applies to table columns that have not had a "
1046 "column-specific target set via ALTER TABLE SET STATISTICS.")
1048 &default_statistics_target,
1049 10, 1, 1000, NULL, NULL
1052 {"from_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1053 gettext_noop("Sets the FROM-list size beyond which subqueries are not "
1055 gettext_noop("The planner will merge subqueries into upper "
1056 "queries if the resulting FROM list would have no more than "
1059 &from_collapse_limit,
1060 8, 1, INT_MAX, NULL, NULL
1063 {"join_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1064 gettext_noop("Sets the FROM-list size beyond which JOIN constructs are not "
1066 gettext_noop("The planner will flatten explicit JOIN "
1067 "constructs into lists of FROM items whenever a list of no more "
1068 "than this many items would result.")
1070 &join_collapse_limit,
1071 8, 1, INT_MAX, NULL, NULL
1074 {"geqo_threshold", PGC_USERSET, QUERY_TUNING_GEQO,
1075 gettext_noop("Sets the threshold of FROM items beyond which GEQO is used."),
1079 12, 2, INT_MAX, NULL, NULL
1082 {"geqo_effort", PGC_USERSET, QUERY_TUNING_GEQO,
1083 gettext_noop("GEQO: effort is used to set the default for other GEQO parameters."),
1087 DEFAULT_GEQO_EFFORT, MIN_GEQO_EFFORT, MAX_GEQO_EFFORT, NULL, NULL
1090 {"geqo_pool_size", PGC_USERSET, QUERY_TUNING_GEQO,
1091 gettext_noop("GEQO: number of individuals in the population."),
1092 gettext_noop("Zero selects a suitable default value.")
1095 0, 0, INT_MAX, NULL, NULL
1098 {"geqo_generations", PGC_USERSET, QUERY_TUNING_GEQO,
1099 gettext_noop("GEQO: number of iterations of the algorithm."),
1100 gettext_noop("Zero selects a suitable default value.")
1103 0, 0, INT_MAX, NULL, NULL
1107 {"deadlock_timeout", PGC_SIGHUP, LOCK_MANAGEMENT,
1108 gettext_noop("The time in milliseconds to wait on lock before checking for deadlock."),
1113 1000, 0, INT_MAX, NULL, NULL
1117 * Note: There is some postprocessing done in PostmasterMain() to make
1118 * sure the buffers are at least twice the number of backends, so the
1119 * constraints here are partially unused. Similarly, the superuser
1120 * reserved number is checked to ensure it is less than the max backends
1123 * MaxBackends is limited to INT_MAX/4 because some places compute
1124 * 4*MaxBackends without any overflow check. Likewise we have to limit
1125 * NBuffers to INT_MAX/2.
1128 {"max_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1129 gettext_noop("Sets the maximum number of concurrent connections."),
1133 100, 1, INT_MAX / 4, NULL, NULL
1137 {"superuser_reserved_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1138 gettext_noop("Sets the number of connection slots reserved for superusers."),
1142 3, 0, INT_MAX / 4, NULL, NULL
1146 {"shared_buffers", PGC_POSTMASTER, RESOURCES_MEM,
1147 gettext_noop("Sets the number of shared memory buffers used by the server."),
1152 1024, 16, INT_MAX / 2, NULL, NULL
1156 {"temp_buffers", PGC_USERSET, RESOURCES_MEM,
1157 gettext_noop("Sets the maximum number of temporary buffers used by each session."),
1162 1024, 100, INT_MAX / 2, NULL, show_num_temp_buffers
1166 {"port", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1167 gettext_noop("Sets the TCP port the server listens on."),
1171 DEF_PGPORT, 1, 65535, NULL, NULL
1175 {"unix_socket_permissions", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1176 gettext_noop("Sets the access permissions of the Unix-domain socket."),
1177 gettext_noop("Unix-domain sockets use the usual Unix file system "
1178 "permission set. The parameter value is expected to be an numeric mode "
1179 "specification in the form accepted by the chmod and umask system "
1180 "calls. (To use the customary octal format the number must start with "
1183 &Unix_socket_permissions,
1184 0777, 0000, 0777, NULL, NULL
1188 {"work_mem", PGC_USERSET, RESOURCES_MEM,
1189 gettext_noop("Sets the maximum memory to be used for query workspaces."),
1190 gettext_noop("This much memory may be used by each internal "
1191 "sort operation and hash table before switching to "
1192 "temporary disk files."),
1196 1024, 8 * BLCKSZ / 1024, MAX_KILOBYTES, NULL, NULL
1200 {"maintenance_work_mem", PGC_USERSET, RESOURCES_MEM,
1201 gettext_noop("Sets the maximum memory to be used for maintenance operations."),
1202 gettext_noop("This includes operations such as VACUUM and CREATE INDEX."),
1205 &maintenance_work_mem,
1206 16384, 1024, MAX_KILOBYTES, NULL, NULL
1210 {"max_stack_depth", PGC_SUSET, RESOURCES_MEM,
1211 gettext_noop("Sets the maximum stack depth, in kilobytes."),
1216 100, 100, MAX_KILOBYTES, assign_max_stack_depth, NULL
1220 {"vacuum_cost_page_hit", PGC_USERSET, RESOURCES,
1221 gettext_noop("Vacuum cost for a page found in the buffer cache."),
1225 1, 0, 10000, NULL, NULL
1229 {"vacuum_cost_page_miss", PGC_USERSET, RESOURCES,
1230 gettext_noop("Vacuum cost for a page not found in the buffer cache."),
1233 &VacuumCostPageMiss,
1234 10, 0, 10000, NULL, NULL
1238 {"vacuum_cost_page_dirty", PGC_USERSET, RESOURCES,
1239 gettext_noop("Vacuum cost for a page dirtied by vacuum."),
1242 &VacuumCostPageDirty,
1243 20, 0, 10000, NULL, NULL
1247 {"vacuum_cost_limit", PGC_USERSET, RESOURCES,
1248 gettext_noop("Vacuum cost amount available before napping."),
1252 200, 1, 10000, NULL, NULL
1256 {"vacuum_cost_delay", PGC_USERSET, RESOURCES,
1257 gettext_noop("Vacuum cost delay in milliseconds."),
1262 0, 0, 1000, NULL, NULL
1266 {"autovacuum_vacuum_cost_delay", PGC_SIGHUP, AUTOVACUUM,
1267 gettext_noop("Vacuum cost delay in milliseconds, for autovacuum."),
1271 &autovacuum_vac_cost_delay,
1272 -1, -1, 1000, NULL, NULL
1276 {"autovacuum_vacuum_cost_limit", PGC_SIGHUP, AUTOVACUUM,
1277 gettext_noop("Vacuum cost amount available before napping, for autovacuum."),
1280 &autovacuum_vac_cost_limit,
1281 -1, -1, 10000, NULL, NULL
1285 {"max_files_per_process", PGC_POSTMASTER, RESOURCES_KERNEL,
1286 gettext_noop("Sets the maximum number of simultaneously open files for each server process."),
1289 &max_files_per_process,
1290 1000, 25, INT_MAX, NULL, NULL
1294 {"max_prepared_transactions", PGC_POSTMASTER, RESOURCES,
1295 gettext_noop("Sets the maximum number of simultaneously prepared transactions."),
1298 &max_prepared_xacts,
1299 5, 0, INT_MAX, NULL, NULL
1304 {"trace_lock_oidmin", PGC_SUSET, DEVELOPER_OPTIONS,
1305 gettext_noop("no description available"),
1310 FirstNormalObjectId, 0, INT_MAX, NULL, NULL
1313 {"trace_lock_table", PGC_SUSET, DEVELOPER_OPTIONS,
1314 gettext_noop("no description available"),
1319 0, 0, INT_MAX, NULL, NULL
1324 {"statement_timeout", PGC_USERSET, CLIENT_CONN_STATEMENT,
1325 gettext_noop("Sets the maximum allowed duration (in milliseconds) of any statement."),
1326 gettext_noop("A value of 0 turns off the timeout."),
1330 0, 0, INT_MAX, NULL, NULL
1334 {"max_fsm_relations", PGC_POSTMASTER, RESOURCES_FSM,
1335 gettext_noop("Sets the maximum number of tables and indexes for which free space is tracked."),
1339 1000, 100, INT_MAX, NULL, NULL
1342 {"max_fsm_pages", PGC_POSTMASTER, RESOURCES_FSM,
1343 gettext_noop("Sets the maximum number of disk pages for which free space is tracked."),
1347 20000, 1000, INT_MAX, NULL, NULL
1351 {"max_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
1352 gettext_noop("Sets the maximum number of locks per transaction."),
1353 gettext_noop("The shared lock table is sized on the assumption that "
1354 "at most max_locks_per_transaction * max_connections distinct "
1355 "objects will need to be locked at any one time.")
1357 &max_locks_per_xact,
1358 64, 10, INT_MAX, NULL, NULL
1362 {"authentication_timeout", PGC_SIGHUP, CONN_AUTH_SECURITY,
1363 gettext_noop("Sets the maximum time in seconds to complete client authentication."),
1367 &AuthenticationTimeout,
1368 60, 1, 600, NULL, NULL
1372 /* Not for general use */
1373 {"pre_auth_delay", PGC_SIGHUP, DEVELOPER_OPTIONS,
1374 gettext_noop("no description available"),
1376 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1379 0, 0, 60, NULL, NULL
1383 {"checkpoint_segments", PGC_SIGHUP, WAL_CHECKPOINTS,
1384 gettext_noop("Sets the maximum distance in log segments between automatic WAL checkpoints."),
1387 &CheckPointSegments,
1388 3, 1, INT_MAX, NULL, NULL
1392 {"checkpoint_timeout", PGC_SIGHUP, WAL_CHECKPOINTS,
1393 gettext_noop("Sets the maximum time in seconds between automatic WAL checkpoints."),
1398 300, 30, 3600, NULL, NULL
1402 {"checkpoint_warning", PGC_SIGHUP, WAL_CHECKPOINTS,
1403 gettext_noop("Logs if filling of checkpoint segments happens more "
1404 "frequently than this (in seconds)."),
1405 gettext_noop("Write a message to the server log if checkpoints "
1406 "caused by the filling of checkpoint segment files happens more "
1407 "frequently than this number of seconds. Zero turns off the warning."),
1411 30, 0, INT_MAX, NULL, NULL
1415 {"wal_buffers", PGC_POSTMASTER, WAL_SETTINGS,
1416 gettext_noop("Sets the number of disk-page buffers in shared memory for WAL."),
1421 8, 4, INT_MAX, NULL, NULL
1425 {"commit_delay", PGC_USERSET, WAL_CHECKPOINTS,
1426 gettext_noop("Sets the delay in microseconds between transaction commit and "
1427 "flushing WAL to disk."),
1431 0, 0, 100000, NULL, NULL
1435 {"commit_siblings", PGC_USERSET, WAL_CHECKPOINTS,
1436 gettext_noop("Sets the minimum concurrent open transactions before performing "
1441 5, 1, 1000, NULL, NULL
1445 {"extra_float_digits", PGC_USERSET, CLIENT_CONN_LOCALE,
1446 gettext_noop("Sets the number of digits displayed for floating-point values."),
1447 gettext_noop("This affects real, double precision, and geometric data types. "
1448 "The parameter value is added to the standard number of digits "
1449 "(FLT_DIG or DBL_DIG as appropriate).")
1451 &extra_float_digits,
1452 0, -15, 2, NULL, NULL
1456 {"log_min_duration_statement", PGC_SUSET, LOGGING_WHEN,
1457 gettext_noop("Sets the minimum execution time in milliseconds above which statements will "
1459 gettext_noop("Zero prints all queries. The default is -1 (turning this feature off)."),
1462 &log_min_duration_statement,
1463 -1, -1, INT_MAX / 1000, NULL, NULL
1467 {"bgwriter_delay", PGC_SIGHUP, RESOURCES,
1468 gettext_noop("Background writer sleep time between rounds in milliseconds"),
1473 200, 10, 10000, NULL, NULL
1477 {"bgwriter_lru_maxpages", PGC_SIGHUP, RESOURCES,
1478 gettext_noop("Background writer maximum number of LRU pages to flush per round"),
1481 &bgwriter_lru_maxpages,
1482 5, 0, 1000, NULL, NULL
1486 {"bgwriter_all_maxpages", PGC_SIGHUP, RESOURCES,
1487 gettext_noop("Background writer maximum number of all pages to flush per round"),
1490 &bgwriter_all_maxpages,
1491 5, 0, 1000, NULL, NULL
1495 {"log_rotation_age", PGC_SIGHUP, LOGGING_WHERE,
1496 gettext_noop("Automatic log file rotation will occur after N minutes"),
1501 HOURS_PER_DAY * MINS_PER_HOUR, 0, INT_MAX / MINS_PER_HOUR, NULL, NULL
1505 {"log_rotation_size", PGC_SIGHUP, LOGGING_WHERE,
1506 gettext_noop("Automatic log file rotation will occur after N kilobytes"),
1511 10 * 1024, 0, INT_MAX / 1024, NULL, NULL
1515 {"max_function_args", PGC_INTERNAL, PRESET_OPTIONS,
1516 gettext_noop("Shows the maximum number of function arguments."),
1518 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1521 FUNC_MAX_ARGS, FUNC_MAX_ARGS, FUNC_MAX_ARGS, NULL, NULL
1525 {"max_index_keys", PGC_INTERNAL, PRESET_OPTIONS,
1526 gettext_noop("Shows the maximum number of index keys."),
1528 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1531 INDEX_MAX_KEYS, INDEX_MAX_KEYS, INDEX_MAX_KEYS, NULL, NULL
1535 {"max_identifier_length", PGC_INTERNAL, PRESET_OPTIONS,
1536 gettext_noop("Shows the maximum identifier length"),
1538 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1540 &max_identifier_length,
1541 NAMEDATALEN - 1, NAMEDATALEN - 1, NAMEDATALEN - 1, NULL, NULL
1545 {"block_size", PGC_INTERNAL, PRESET_OPTIONS,
1546 gettext_noop("Shows size of a disk block"),
1548 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1551 BLCKSZ, BLCKSZ, BLCKSZ, NULL, NULL
1555 {"autovacuum_naptime", PGC_SIGHUP, AUTOVACUUM,
1556 gettext_noop("Time to sleep between autovacuum runs, in seconds."),
1560 &autovacuum_naptime,
1561 60, 1, INT_MAX, NULL, NULL
1564 {"autovacuum_vacuum_threshold", PGC_SIGHUP, AUTOVACUUM,
1565 gettext_noop("Minimum number of tuple updates or deletes prior to vacuum."),
1568 &autovacuum_vac_thresh,
1569 500, 0, INT_MAX, NULL, NULL
1572 {"autovacuum_analyze_threshold", PGC_SIGHUP, AUTOVACUUM,
1573 gettext_noop("Minimum number of tuple inserts, updates or deletes prior to analyze."),
1576 &autovacuum_anl_thresh,
1577 250, 0, INT_MAX, NULL, NULL
1581 {"tcp_keepalives_idle", PGC_USERSET, CLIENT_CONN_OTHER,
1582 gettext_noop("Seconds between issuing TCP keepalives."),
1583 gettext_noop("A value of 0 uses the system default."),
1586 &tcp_keepalives_idle,
1587 0, 0, INT_MAX, assign_tcp_keepalives_idle, show_tcp_keepalives_idle
1591 {"tcp_keepalives_interval", PGC_USERSET, CLIENT_CONN_OTHER,
1592 gettext_noop("Seconds between TCP keepalive retransmits."),
1593 gettext_noop("A value of 0 uses the system default."),
1596 &tcp_keepalives_interval,
1597 0, 0, INT_MAX, assign_tcp_keepalives_interval, show_tcp_keepalives_interval
1601 {"tcp_keepalives_count", PGC_USERSET, CLIENT_CONN_OTHER,
1602 gettext_noop("Maximum number of TCP keepalive retransmits."),
1603 gettext_noop("This controls the number of consecutive keepalive retransmits that can be "
1604 "lost before a connection is considered dead. A value of 0 uses the "
1607 &tcp_keepalives_count,
1608 0, 0, INT_MAX, assign_tcp_keepalives_count, show_tcp_keepalives_count
1612 {"gin_fuzzy_search_limit", PGC_USERSET, CLIENT_CONN_OTHER,
1613 gettext_noop("Sets the maximum allowed result for exact search by GIN."),
1617 &GinFuzzySearchLimit,
1618 0, 0, INT_MAX, NULL, NULL
1622 {"effective_cache_size", PGC_USERSET, QUERY_TUNING_COST,
1623 gettext_noop("Sets the planner's assumption about size of the disk cache."),
1624 gettext_noop("That is, the portion of the kernel's disk cache that "
1625 "will be used for PostgreSQL data files. This is measured in disk "
1626 "pages, which are normally 8 kB each."),
1629 &effective_cache_size,
1630 DEFAULT_EFFECTIVE_CACHE_SIZE, 1, INT_MAX, NULL, NULL
1634 /* Can't be set in postgresql.conf */
1635 {"server_version_num", PGC_INTERNAL, PRESET_OPTIONS,
1636 gettext_noop("Shows the server version as an integer."),
1638 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1640 &server_version_num,
1641 PG_VERSION_NUM, PG_VERSION_NUM, PG_VERSION_NUM, NULL, NULL
1644 /* End-of-list marker */
1646 {NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL
1651 static struct config_real ConfigureNamesReal[] =
1654 {"seq_page_cost", PGC_USERSET, QUERY_TUNING_COST,
1655 gettext_noop("Sets the planner's estimate of the cost of a "
1656 "sequentially fetched disk page."),
1660 DEFAULT_SEQ_PAGE_COST, 0, DBL_MAX, NULL, NULL
1663 {"random_page_cost", PGC_USERSET, QUERY_TUNING_COST,
1664 gettext_noop("Sets the planner's estimate of the cost of a "
1665 "nonsequentially fetched disk page."),
1669 DEFAULT_RANDOM_PAGE_COST, 0, DBL_MAX, NULL, NULL
1672 {"cpu_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
1673 gettext_noop("Sets the planner's estimate of the cost of "
1674 "processing each tuple (row)."),
1678 DEFAULT_CPU_TUPLE_COST, 0, DBL_MAX, NULL, NULL
1681 {"cpu_index_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
1682 gettext_noop("Sets the planner's estimate of the cost of "
1683 "processing each index entry during an index scan."),
1686 &cpu_index_tuple_cost,
1687 DEFAULT_CPU_INDEX_TUPLE_COST, 0, DBL_MAX, NULL, NULL
1690 {"cpu_operator_cost", PGC_USERSET, QUERY_TUNING_COST,
1691 gettext_noop("Sets the planner's estimate of the cost of "
1692 "processing each operator or function call."),
1696 DEFAULT_CPU_OPERATOR_COST, 0, DBL_MAX, NULL, NULL
1700 {"geqo_selection_bias", PGC_USERSET, QUERY_TUNING_GEQO,
1701 gettext_noop("GEQO: selective pressure within the population."),
1704 &Geqo_selection_bias,
1705 DEFAULT_GEQO_SELECTION_BIAS, MIN_GEQO_SELECTION_BIAS,
1706 MAX_GEQO_SELECTION_BIAS, NULL, NULL
1710 {"bgwriter_lru_percent", PGC_SIGHUP, RESOURCES,
1711 gettext_noop("Background writer percentage of LRU buffers to flush per round"),
1714 &bgwriter_lru_percent,
1715 1.0, 0.0, 100.0, NULL, NULL
1719 {"bgwriter_all_percent", PGC_SIGHUP, RESOURCES,
1720 gettext_noop("Background writer percentage of all buffers to flush per round"),
1723 &bgwriter_all_percent,
1724 0.333, 0.0, 100.0, NULL, NULL
1728 {"seed", PGC_USERSET, UNGROUPED,
1729 gettext_noop("Sets the seed for random-number generation."),
1731 GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1734 0.5, 0.0, 1.0, assign_random_seed, show_random_seed
1738 {"autovacuum_vacuum_scale_factor", PGC_SIGHUP, AUTOVACUUM,
1739 gettext_noop("Number of tuple updates or deletes prior to vacuum as a fraction of reltuples."),
1742 &autovacuum_vac_scale,
1743 0.2, 0.0, 100.0, NULL, NULL
1746 {"autovacuum_analyze_scale_factor", PGC_SIGHUP, AUTOVACUUM,
1747 gettext_noop("Number of tuple inserts, updates or deletes prior to analyze as a fraction of reltuples."),
1750 &autovacuum_anl_scale,
1751 0.1, 0.0, 100.0, NULL, NULL
1754 /* End-of-list marker */
1756 {NULL, 0, 0, NULL, NULL}, NULL, 0.0, 0.0, 0.0, NULL, NULL
1761 static struct config_string ConfigureNamesString[] =
1764 {"archive_command", PGC_SIGHUP, WAL_SETTINGS,
1765 gettext_noop("WAL archiving command."),
1766 gettext_noop("The shell command that will be called to archive a WAL file.")
1768 &XLogArchiveCommand,
1773 {"backslash_quote", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1774 gettext_noop("Sets whether \"\\'\" is allowed in string literals."),
1775 gettext_noop("Valid values are ON, OFF, and SAFE_ENCODING.")
1777 &backslash_quote_string,
1778 "safe_encoding", assign_backslash_quote, NULL
1782 {"client_encoding", PGC_USERSET, CLIENT_CONN_LOCALE,
1783 gettext_noop("Sets the client's character set encoding."),
1785 GUC_IS_NAME | GUC_REPORT
1787 &client_encoding_string,
1788 "SQL_ASCII", assign_client_encoding, NULL
1792 {"client_min_messages", PGC_USERSET, LOGGING_WHEN,
1793 gettext_noop("Sets the message levels that are sent to the client."),
1794 gettext_noop("Valid values are DEBUG5, DEBUG4, DEBUG3, DEBUG2, "
1795 "DEBUG1, LOG, NOTICE, WARNING, and ERROR. Each level includes all the "
1796 "levels that follow it. The later the level, the fewer messages are "
1799 &client_min_messages_str,
1800 "notice", assign_client_min_messages, NULL
1804 {"log_min_messages", PGC_SUSET, LOGGING_WHEN,
1805 gettext_noop("Sets the message levels that are logged."),
1806 gettext_noop("Valid values are DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1, "
1807 "INFO, NOTICE, WARNING, ERROR, LOG, FATAL, and PANIC. Each level "
1808 "includes all the levels that follow it.")
1810 &log_min_messages_str,
1811 "notice", assign_log_min_messages, NULL
1815 {"log_error_verbosity", PGC_SUSET, LOGGING_WHEN,
1816 gettext_noop("Sets the verbosity of logged messages."),
1817 gettext_noop("Valid values are \"terse\", \"default\", and \"verbose\".")
1819 &log_error_verbosity_str,
1820 "default", assign_log_error_verbosity, NULL
1823 {"log_statement", PGC_SUSET, LOGGING_WHAT,
1824 gettext_noop("Sets the type of statements logged."),
1825 gettext_noop("Valid values are \"none\", \"ddl\", \"mod\", and \"all\".")
1828 "none", assign_log_statement, NULL
1832 {"log_min_error_statement", PGC_SUSET, LOGGING_WHEN,
1833 gettext_noop("Causes all statements generating error at or above this level to be logged."),
1834 gettext_noop("All SQL statements that cause an error of the "
1835 "specified level or a higher level are logged.")
1837 &log_min_error_statement_str,
1838 "panic", assign_min_error_statement, NULL
1842 {"log_line_prefix", PGC_SIGHUP, LOGGING_WHAT,
1843 gettext_noop("Controls information prefixed to each log line"),
1844 gettext_noop("if blank no prefix is used")
1852 {"DateStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
1853 gettext_noop("Sets the display format for date and time values."),
1854 gettext_noop("Also controls interpretation of ambiguous "
1856 GUC_LIST_INPUT | GUC_REPORT
1859 "ISO, MDY", assign_datestyle, NULL
1863 {"default_tablespace", PGC_USERSET, CLIENT_CONN_STATEMENT,
1864 gettext_noop("Sets the default tablespace to create tables and indexes in."),
1865 gettext_noop("An empty string selects the database's default tablespace."),
1868 &default_tablespace,
1869 "", assign_default_tablespace, NULL
1873 {"default_transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
1874 gettext_noop("Sets the transaction isolation level of each new transaction."),
1875 gettext_noop("Each SQL transaction has an isolation level, which "
1876 "can be either \"read uncommitted\", \"read committed\", \"repeatable read\", or \"serializable\".")
1878 &default_iso_level_string,
1879 "read committed", assign_defaultxactisolevel, NULL
1883 {"dynamic_library_path", PGC_SUSET, CLIENT_CONN_OTHER,
1884 gettext_noop("Sets the path for dynamically loadable modules."),
1885 gettext_noop("If a dynamically loadable module needs to be opened and "
1886 "the specified name does not have a directory component (i.e., the "
1887 "name does not contain a slash), the system will search this path for "
1888 "the specified file."),
1891 &Dynamic_library_path,
1892 "$libdir", NULL, NULL
1896 {"krb_server_keyfile", PGC_POSTMASTER, CONN_AUTH_SECURITY,
1897 gettext_noop("Sets the location of the Kerberos server key file."),
1901 &pg_krb_server_keyfile,
1902 PG_KRB_SRVTAB, NULL, NULL
1906 {"krb_srvname", PGC_POSTMASTER, CONN_AUTH_SECURITY,
1907 gettext_noop("Sets the name of the Kerberos service."),
1911 PG_KRB_SRVNAM, NULL, NULL
1915 {"krb_server_hostname", PGC_POSTMASTER, CONN_AUTH_SECURITY,
1916 gettext_noop("Sets the hostname of the Kerberos server."),
1919 &pg_krb_server_hostname,
1924 {"bonjour_name", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1925 gettext_noop("Sets the Bonjour broadcast service name."),
1932 /* See main.c about why defaults for LC_foo are not all alike */
1935 {"lc_collate", PGC_INTERNAL, CLIENT_CONN_LOCALE,
1936 gettext_noop("Shows the collation order locale."),
1938 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1945 {"lc_ctype", PGC_INTERNAL, CLIENT_CONN_LOCALE,
1946 gettext_noop("Shows the character classification and case conversion locale."),
1948 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1955 {"lc_messages", PGC_SUSET, CLIENT_CONN_LOCALE,
1956 gettext_noop("Sets the language in which messages are displayed."),
1960 "", locale_messages_assign, NULL
1964 {"lc_monetary", PGC_USERSET, CLIENT_CONN_LOCALE,
1965 gettext_noop("Sets the locale for formatting monetary amounts."),
1969 "C", locale_monetary_assign, NULL
1973 {"lc_numeric", PGC_USERSET, CLIENT_CONN_LOCALE,
1974 gettext_noop("Sets the locale for formatting numbers."),
1978 "C", locale_numeric_assign, NULL
1982 {"lc_time", PGC_USERSET, CLIENT_CONN_LOCALE,
1983 gettext_noop("Sets the locale for formatting date and time values."),
1987 "C", locale_time_assign, NULL
1991 {"shared_preload_libraries", PGC_POSTMASTER, RESOURCES_KERNEL,
1992 gettext_noop("Lists shared libraries to preload into server."),
1994 GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
1996 &shared_preload_libraries_string,
2001 {"local_preload_libraries", PGC_BACKEND, CLIENT_CONN_OTHER,
2002 gettext_noop("Lists shared libraries to preload into each backend."),
2004 GUC_LIST_INPUT | GUC_LIST_QUOTE
2006 &local_preload_libraries_string,
2011 {"regex_flavor", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
2012 gettext_noop("Sets the regular expression \"flavor\"."),
2013 gettext_noop("This can be set to advanced, extended, or basic.")
2015 ®ex_flavor_string,
2016 "advanced", assign_regex_flavor, NULL
2020 {"search_path", PGC_USERSET, CLIENT_CONN_STATEMENT,
2021 gettext_noop("Sets the schema search order for names that are not schema-qualified."),
2023 GUC_LIST_INPUT | GUC_LIST_QUOTE
2025 &namespace_search_path,
2026 "\"$user\",public", assign_search_path, NULL
2030 /* Can't be set in postgresql.conf */
2031 {"server_encoding", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2032 gettext_noop("Sets the server (database) character set encoding."),
2034 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2036 &server_encoding_string,
2037 "SQL_ASCII", NULL, NULL
2041 /* Can't be set in postgresql.conf */
2042 {"server_version", PGC_INTERNAL, PRESET_OPTIONS,
2043 gettext_noop("Shows the server version."),
2045 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2047 &server_version_string,
2048 PG_VERSION, NULL, NULL
2052 /* Not for general use --- used by SET ROLE */
2053 {"role", PGC_USERSET, UNGROUPED,
2054 gettext_noop("Sets the current role."),
2056 GUC_IS_NAME | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2059 "none", assign_role, show_role
2063 /* Not for general use --- used by SET SESSION AUTHORIZATION */
2064 {"session_authorization", PGC_USERSET, UNGROUPED,
2065 gettext_noop("Sets the session user name."),
2067 GUC_IS_NAME | GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2069 &session_authorization_string,
2070 NULL, assign_session_authorization, show_session_authorization
2074 {"log_destination", PGC_SIGHUP, LOGGING_WHERE,
2075 gettext_noop("Sets the destination for server log output."),
2076 gettext_noop("Valid values are combinations of \"stderr\", \"syslog\", "
2077 "and \"eventlog\", depending on the platform."),
2080 &log_destination_string,
2081 "stderr", assign_log_destination, NULL
2084 {"log_directory", PGC_SIGHUP, LOGGING_WHERE,
2085 gettext_noop("Sets the destination directory for log files."),
2086 gettext_noop("May be specified as relative to the data directory "
2087 "or as absolute path."),
2091 "pg_log", assign_canonical_path, NULL
2094 {"log_filename", PGC_SIGHUP, LOGGING_WHERE,
2095 gettext_noop("Sets the file name pattern for log files."),
2100 "postgresql-%Y-%m-%d_%H%M%S.log", NULL, NULL
2105 {"syslog_facility", PGC_SIGHUP, LOGGING_WHERE,
2106 gettext_noop("Sets the syslog \"facility\" to be used when syslog enabled."),
2107 gettext_noop("Valid values are LOCAL0, LOCAL1, LOCAL2, LOCAL3, "
2108 "LOCAL4, LOCAL5, LOCAL6, LOCAL7.")
2110 &syslog_facility_str,
2111 "LOCAL0", assign_syslog_facility, NULL
2114 {"syslog_ident", PGC_SIGHUP, LOGGING_WHERE,
2115 gettext_noop("Sets the program name used to identify PostgreSQL "
2116 "messages in syslog."),
2120 "postgres", assign_syslog_ident, NULL
2125 {"TimeZone", PGC_USERSET, CLIENT_CONN_LOCALE,
2126 gettext_noop("Sets the time zone for displaying and interpreting time stamps."),
2131 "UNKNOWN", assign_timezone, show_timezone
2134 {"timezone_abbreviations", PGC_USERSET, CLIENT_CONN_LOCALE,
2135 gettext_noop("Selects a file of time zone abbreviations"),
2138 &timezone_abbreviations_string,
2139 "UNKNOWN", assign_timezone_abbreviations, NULL
2143 {"transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
2144 gettext_noop("Sets the current transaction's isolation level."),
2146 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2148 &XactIsoLevel_string,
2149 NULL, assign_XactIsoLevel, show_XactIsoLevel
2153 {"unix_socket_group", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2154 gettext_noop("Sets the owning group of the Unix-domain socket."),
2155 gettext_noop("(The owning user of the socket is always the user "
2156 "that starts the server.)")
2163 {"unix_socket_directory", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2164 gettext_noop("Sets the directory where the Unix-domain socket will be created."),
2169 "", assign_canonical_path, NULL
2173 {"listen_addresses", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2174 gettext_noop("Sets the host name or IP address(es) to listen to."),
2179 "localhost", NULL, NULL
2183 {"wal_sync_method", PGC_SIGHUP, WAL_SETTINGS,
2184 gettext_noop("Selects the method used for forcing WAL updates out to disk."),
2188 XLOG_sync_method_default, assign_xlog_sync_method, NULL
2192 {"custom_variable_classes", PGC_SIGHUP, CUSTOM_OPTIONS,
2193 gettext_noop("Sets the list of known custom variable classes."),
2195 GUC_LIST_INPUT | GUC_LIST_QUOTE
2197 &custom_variable_classes,
2198 NULL, assign_custom_variable_classes, NULL
2202 {"data_directory", PGC_POSTMASTER, FILE_LOCATIONS,
2203 gettext_noop("Sets the server's data directory."),
2212 {"config_file", PGC_POSTMASTER, FILE_LOCATIONS,
2213 gettext_noop("Sets the server's main configuration file."),
2215 GUC_DISALLOW_IN_FILE | GUC_SUPERUSER_ONLY
2222 {"hba_file", PGC_POSTMASTER, FILE_LOCATIONS,
2223 gettext_noop("Sets the server's \"hba\" configuration file"),
2232 {"ident_file", PGC_POSTMASTER, FILE_LOCATIONS,
2233 gettext_noop("Sets the server's \"ident\" configuration file"),
2242 {"external_pid_file", PGC_POSTMASTER, FILE_LOCATIONS,
2243 gettext_noop("Writes the postmaster PID to the specified file."),
2248 NULL, assign_canonical_path, NULL
2251 /* End-of-list marker */
2253 {NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL
2258 /******** end of options list ********/
2262 * To allow continued support of obsolete names for GUC variables, we apply
2263 * the following mappings to any unrecognized name. Note that an old name
2264 * should be mapped to a new one only if the new variable has very similar
2265 * semantics to the old.
2267 static const char *const map_old_guc_names[] = {
2268 "sort_mem", "work_mem",
2269 "vacuum_mem", "maintenance_work_mem",
2275 * Actual lookup of variables is done through this single, sorted array.
2277 static struct config_generic **guc_variables;
2279 /* Current number of variables contained in the vector */
2280 static int num_guc_variables;
2282 /* Vector capacity */
2283 static int size_guc_variables;
2286 static bool guc_dirty; /* TRUE if need to do commit/abort work */
2288 static bool reporting_enabled; /* TRUE to enable GUC_REPORT */
2291 static int guc_var_compare(const void *a, const void *b);
2292 static int guc_name_compare(const char *namea, const char *nameb);
2293 static void push_old_value(struct config_generic * gconf);
2294 static void ReportGUCOption(struct config_generic * record);
2295 static void ShowGUCConfigOption(const char *name, DestReceiver *dest);
2296 static void ShowAllGUCConfig(DestReceiver *dest);
2297 static char *_ShowOption(struct config_generic * record, bool use_units);
2298 static bool is_newvalue_equal(struct config_generic * record, const char *newvalue);
2302 * Some infrastructure for checking malloc/strdup/realloc calls
2305 guc_malloc(int elevel, size_t size)
2309 data = malloc(size);
2312 (errcode(ERRCODE_OUT_OF_MEMORY),
2313 errmsg("out of memory")));
2318 guc_realloc(int elevel, void *old, size_t size)
2322 data = realloc(old, size);
2325 (errcode(ERRCODE_OUT_OF_MEMORY),
2326 errmsg("out of memory")));
2331 guc_strdup(int elevel, const char *src)
2338 (errcode(ERRCODE_OUT_OF_MEMORY),
2339 errmsg("out of memory")));
2345 * Support for assigning to a field of a string GUC item. Free the prior
2346 * value if it's not referenced anywhere else in the item (including stacked
2350 set_string_field(struct config_string * conf, char **field, char *newval)
2352 char *oldval = *field;
2355 /* Do the assignment */
2358 /* Exit if any duplicate references, or if old value was NULL anyway */
2359 if (oldval == NULL ||
2360 oldval == *(conf->variable) ||
2361 oldval == conf->reset_val ||
2362 oldval == conf->tentative_val)
2364 for (stack = conf->gen.stack; stack; stack = stack->prev)
2366 if (oldval == stack->tentative_val.stringval ||
2367 oldval == stack->value.stringval)
2371 /* Not used anymore, so free it */
2376 * Detect whether strval is referenced anywhere in a GUC string item
2379 string_field_used(struct config_string * conf, char *strval)
2383 if (strval == *(conf->variable) ||
2384 strval == conf->reset_val ||
2385 strval == conf->tentative_val)
2387 for (stack = conf->gen.stack; stack; stack = stack->prev)
2389 if (strval == stack->tentative_val.stringval ||
2390 strval == stack->value.stringval)
2397 struct config_generic **
2398 get_guc_variables(void)
2400 return guc_variables;
2405 * Build the sorted array. This is split out so that it could be
2406 * re-executed after startup (eg, we could allow loadable modules to
2407 * add vars, and then we'd need to re-sort).
2410 build_guc_variables(void)
2414 struct config_generic **guc_vars;
2417 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
2419 struct config_bool *conf = &ConfigureNamesBool[i];
2421 /* Rather than requiring vartype to be filled in by hand, do this: */
2422 conf->gen.vartype = PGC_BOOL;
2426 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
2428 struct config_int *conf = &ConfigureNamesInt[i];
2430 conf->gen.vartype = PGC_INT;
2434 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
2436 struct config_real *conf = &ConfigureNamesReal[i];
2438 conf->gen.vartype = PGC_REAL;
2442 for (i = 0; ConfigureNamesString[i].gen.name; i++)
2444 struct config_string *conf = &ConfigureNamesString[i];
2446 conf->gen.vartype = PGC_STRING;
2451 * Create table with 20% slack
2453 size_vars = num_vars + num_vars / 4;
2455 guc_vars = (struct config_generic **)
2456 guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
2460 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
2461 guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
2463 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
2464 guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
2466 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
2467 guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
2469 for (i = 0; ConfigureNamesString[i].gen.name; i++)
2470 guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
2473 free(guc_variables);
2474 guc_variables = guc_vars;
2475 num_guc_variables = num_vars;
2476 size_guc_variables = size_vars;
2477 qsort((void *) guc_variables, num_guc_variables,
2478 sizeof(struct config_generic *), guc_var_compare);
2482 is_custom_class(const char *name, int dotPos)
2485 * assign_custom_variable_classes() has made sure no empty identifiers or
2486 * whitespace exists in the variable
2488 bool result = false;
2489 const char *ccs = GetConfigOption("custom_variable_classes");
2493 const char *start = ccs;
2499 if (c == 0 || c == ',')
2501 if (dotPos == ccs - start && strncmp(start, name, dotPos) == 0)
2516 * Add a new GUC variable to the list of known variables. The
2517 * list is expanded if needed.
2520 add_guc_variable(struct config_generic * var, int elevel)
2522 if (num_guc_variables + 1 >= size_guc_variables)
2525 * Increase the vector by 25%
2527 int size_vars = size_guc_variables + size_guc_variables / 4;
2528 struct config_generic **guc_vars;
2533 guc_vars = (struct config_generic **)
2534 guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
2538 guc_vars = (struct config_generic **)
2539 guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
2542 if (guc_vars == NULL)
2543 return false; /* out of memory */
2545 guc_variables = guc_vars;
2546 size_guc_variables = size_vars;
2548 guc_variables[num_guc_variables++] = var;
2549 qsort((void *) guc_variables, num_guc_variables,
2550 sizeof(struct config_generic *), guc_var_compare);
2555 * Create and add a placeholder variable. It's presumed to belong
2556 * to a valid custom variable class at this point.
2558 static struct config_string *
2559 add_placeholder_variable(const char *name, int elevel)
2561 size_t sz = sizeof(struct config_string) + sizeof(char *);
2562 struct config_string *var;
2563 struct config_generic *gen;
2565 var = (struct config_string *) guc_malloc(elevel, sz);
2572 gen->name = guc_strdup(elevel, name);
2573 if (gen->name == NULL)
2579 gen->context = PGC_USERSET;
2580 gen->group = CUSTOM_OPTIONS;
2581 gen->short_desc = "GUC placeholder variable";
2582 gen->flags = GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_CUSTOM_PLACEHOLDER;
2583 gen->vartype = PGC_STRING;
2586 * The char* is allocated at the end of the struct since we have no
2587 * 'static' place to point to.
2589 var->variable = (char **) (var + 1);
2591 if (!add_guc_variable((struct config_generic *) var, elevel))
2593 free((void *) gen->name);
2602 * Look up option NAME. If it exists, return a pointer to its record,
2605 static struct config_generic *
2606 find_option(const char *name, int elevel)
2609 const char **key = &name;
2610 struct config_generic **res;
2616 * By equating const char ** with struct config_generic *, we are assuming
2617 * the name field is first in config_generic.
2619 res = (struct config_generic **) bsearch((void *) &key,
2620 (void *) guc_variables,
2622 sizeof(struct config_generic *),
2628 * See if the name is an obsolete name for a variable. We assume that the
2629 * set of supported old names is short enough that a brute-force search is
2632 for (i = 0; map_old_guc_names[i] != NULL; i += 2)
2634 if (guc_name_compare(name, map_old_guc_names[i]) == 0)
2635 return find_option(map_old_guc_names[i + 1], elevel);
2639 * Check if the name is qualified, and if so, check if the qualifier maps
2640 * to a custom variable class.
2642 dot = strchr(name, GUC_QUALIFIER_SEPARATOR);
2643 if (dot != NULL && is_custom_class(name, dot - name))
2644 /* Add a placeholder variable for this name */
2645 return (struct config_generic *) add_placeholder_variable(name, elevel);
2653 * comparator for qsorting and bsearching guc_variables array
2656 guc_var_compare(const void *a, const void *b)
2658 struct config_generic *confa = *(struct config_generic **) a;
2659 struct config_generic *confb = *(struct config_generic **) b;
2661 return guc_name_compare(confa->name, confb->name);
2666 guc_name_compare(const char *namea, const char *nameb)
2669 * The temptation to use strcasecmp() here must be resisted, because the
2670 * array ordering has to remain stable across setlocale() calls. So, build
2671 * our own with a simple ASCII-only downcasing.
2673 while (*namea && *nameb)
2675 char cha = *namea++;
2676 char chb = *nameb++;
2678 if (cha >= 'A' && cha <= 'Z')
2680 if (chb >= 'A' && chb <= 'Z')
2686 return 1; /* a is longer */
2688 return -1; /* b is longer */
2694 * Initialize GUC options during program startup.
2696 * Note that we cannot read the config file yet, since we have not yet
2697 * processed command-line switches.
2700 InitializeGUCOptions(void)
2707 * Build sorted array of all GUC variables.
2709 build_guc_variables();
2712 * Load all variables with their compiled-in defaults, and initialize
2713 * status fields as needed.
2715 for (i = 0; i < num_guc_variables; i++)
2717 struct config_generic *gconf = guc_variables[i];
2720 gconf->reset_source = PGC_S_DEFAULT;
2721 gconf->tentative_source = PGC_S_DEFAULT;
2722 gconf->source = PGC_S_DEFAULT;
2723 gconf->stack = NULL;
2725 switch (gconf->vartype)
2729 struct config_bool *conf = (struct config_bool *) gconf;
2731 if (conf->assign_hook)
2732 if (!(*conf->assign_hook) (conf->reset_val, true,
2734 elog(FATAL, "failed to initialize %s to %d",
2735 conf->gen.name, (int) conf->reset_val);
2736 *conf->variable = conf->reset_val;
2741 struct config_int *conf = (struct config_int *) gconf;
2743 Assert(conf->reset_val >= conf->min);
2744 Assert(conf->reset_val <= conf->max);
2745 if (conf->assign_hook)
2746 if (!(*conf->assign_hook) (conf->reset_val, true,
2748 elog(FATAL, "failed to initialize %s to %d",
2749 conf->gen.name, conf->reset_val);
2750 *conf->variable = conf->reset_val;
2755 struct config_real *conf = (struct config_real *) gconf;
2757 Assert(conf->reset_val >= conf->min);
2758 Assert(conf->reset_val <= conf->max);
2759 if (conf->assign_hook)
2760 if (!(*conf->assign_hook) (conf->reset_val, true,
2762 elog(FATAL, "failed to initialize %s to %g",
2763 conf->gen.name, conf->reset_val);
2764 *conf->variable = conf->reset_val;
2769 struct config_string *conf = (struct config_string *) gconf;
2772 *conf->variable = NULL;
2773 conf->reset_val = NULL;
2774 conf->tentative_val = NULL;
2776 if (conf->boot_val == NULL)
2778 /* Cannot set value yet */
2782 str = guc_strdup(FATAL, conf->boot_val);
2783 conf->reset_val = str;
2785 if (conf->assign_hook)
2789 newstr = (*conf->assign_hook) (str, true,
2793 elog(FATAL, "failed to initialize %s to \"%s\"",
2794 conf->gen.name, str);
2796 else if (newstr != str)
2801 * See notes in set_config_option about casting
2803 str = (char *) newstr;
2804 conf->reset_val = str;
2807 *conf->variable = str;
2815 reporting_enabled = false;
2818 * Prevent any attempt to override the transaction modes from
2819 * non-interactive sources.
2821 SetConfigOption("transaction_isolation", "default",
2822 PGC_POSTMASTER, PGC_S_OVERRIDE);
2823 SetConfigOption("transaction_read_only", "no",
2824 PGC_POSTMASTER, PGC_S_OVERRIDE);
2827 * For historical reasons, some GUC parameters can receive defaults from
2828 * environment variables. Process those settings.
2831 env = getenv("PGPORT");
2833 SetConfigOption("port", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
2835 env = getenv("PGDATESTYLE");
2837 SetConfigOption("datestyle", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
2839 env = getenv("PGCLIENTENCODING");
2841 SetConfigOption("client_encoding", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
2844 * rlimit isn't exactly an "environment variable", but it behaves about
2845 * the same. If we can identify the platform stack depth rlimit, increase
2846 * default stack depth setting up to whatever is safe (but at most 2MB).
2848 stack_rlimit = get_stack_depth_rlimit();
2849 if (stack_rlimit > 0)
2851 int new_limit = (stack_rlimit - STACK_DEPTH_SLOP) / 1024L;
2853 if (new_limit > 100)
2857 new_limit = Min(new_limit, 2048);
2858 sprintf(limbuf, "%d", new_limit);
2859 SetConfigOption("max_stack_depth", limbuf,
2860 PGC_POSTMASTER, PGC_S_ENV_VAR);
2867 * Select the configuration files and data directory to be used, and
2868 * do the initial read of postgresql.conf.
2870 * This is called after processing command-line switches.
2871 * userDoption is the -D switch value if any (NULL if unspecified).
2872 * progname is just for use in error messages.
2874 * Returns true on success; on failure, prints a suitable error message
2875 * to stderr and returns false.
2878 SelectConfigFiles(const char *userDoption, const char *progname)
2882 struct stat stat_buf;
2884 /* configdir is -D option, or $PGDATA if no -D */
2886 configdir = make_absolute_path(userDoption);
2888 configdir = make_absolute_path(getenv("PGDATA"));
2891 * Find the configuration file: if config_file was specified on the
2892 * command line, use it, else use configdir/postgresql.conf. In any case
2893 * ensure the result is an absolute path, so that it will be interpreted
2894 * the same way by future backends.
2897 fname = make_absolute_path(ConfigFileName);
2900 fname = guc_malloc(FATAL,
2901 strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
2902 sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
2906 write_stderr("%s does not know where to find the server configuration file.\n"
2907 "You must specify the --config-file or -D invocation "
2908 "option or set the PGDATA environment variable.\n",
2914 * Set the ConfigFileName GUC variable to its final value, ensuring that
2915 * it can't be overridden later.
2917 SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
2921 * Now read the config file for the first time.
2923 if (stat(ConfigFileName, &stat_buf) != 0)
2925 write_stderr("%s cannot access the server configuration file \"%s\": %s\n",
2926 progname, ConfigFileName, strerror(errno));
2930 ProcessConfigFile(PGC_POSTMASTER);
2933 * If the data_directory GUC variable has been set, use that as DataDir;
2934 * otherwise use configdir if set; else punt.
2936 * Note: SetDataDir will copy and absolute-ize its argument, so we don't
2940 SetDataDir(data_directory);
2942 SetDataDir(configdir);
2945 write_stderr("%s does not know where to find the database system data.\n"
2946 "This can be specified as \"data_directory\" in \"%s\", "
2947 "or by the -D invocation option, or by the "
2948 "PGDATA environment variable.\n",
2949 progname, ConfigFileName);
2954 * Reflect the final DataDir value back into the data_directory GUC var.
2955 * (If you are wondering why we don't just make them a single variable,
2956 * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
2957 * child backends specially. XXX is that still true? Given that we now
2958 * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
2959 * DataDir in advance.)
2961 SetConfigOption("data_directory", DataDir, PGC_POSTMASTER, PGC_S_OVERRIDE);
2964 * Figure out where pg_hba.conf is, and make sure the path is absolute.
2967 fname = make_absolute_path(HbaFileName);
2970 fname = guc_malloc(FATAL,
2971 strlen(configdir) + strlen(HBA_FILENAME) + 2);
2972 sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
2976 write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
2977 "This can be specified as \"hba_file\" in \"%s\", "
2978 "or by the -D invocation option, or by the "
2979 "PGDATA environment variable.\n",
2980 progname, ConfigFileName);
2983 SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
2987 * Likewise for pg_ident.conf.
2990 fname = make_absolute_path(IdentFileName);
2993 fname = guc_malloc(FATAL,
2994 strlen(configdir) + strlen(IDENT_FILENAME) + 2);
2995 sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
2999 write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
3000 "This can be specified as \"ident_file\" in \"%s\", "
3001 "or by the -D invocation option, or by the "
3002 "PGDATA environment variable.\n",
3003 progname, ConfigFileName);
3006 SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
3016 * Reset all options to their saved default values (implements RESET ALL)
3019 ResetAllOptions(void)
3023 for (i = 0; i < num_guc_variables; i++)
3025 struct config_generic *gconf = guc_variables[i];
3027 /* Don't reset non-SET-able values */
3028 if (gconf->context != PGC_SUSET &&
3029 gconf->context != PGC_USERSET)
3031 /* Don't reset if special exclusion from RESET ALL */
3032 if (gconf->flags & GUC_NO_RESET_ALL)
3034 /* No need to reset if wasn't SET */
3035 if (gconf->source <= PGC_S_OVERRIDE)
3038 /* Save old value to support transaction abort */
3039 push_old_value(gconf);
3041 switch (gconf->vartype)
3045 struct config_bool *conf = (struct config_bool *) gconf;
3047 if (conf->assign_hook)
3048 if (!(*conf->assign_hook) (conf->reset_val, true,
3050 elog(ERROR, "failed to reset %s", conf->gen.name);
3051 *conf->variable = conf->reset_val;
3052 conf->tentative_val = conf->reset_val;
3053 conf->gen.source = conf->gen.reset_source;
3054 conf->gen.tentative_source = conf->gen.reset_source;
3055 conf->gen.status |= GUC_HAVE_TENTATIVE;
3061 struct config_int *conf = (struct config_int *) gconf;
3063 if (conf->assign_hook)
3064 if (!(*conf->assign_hook) (conf->reset_val, true,
3066 elog(ERROR, "failed to reset %s", conf->gen.name);
3067 *conf->variable = conf->reset_val;
3068 conf->tentative_val = conf->reset_val;
3069 conf->gen.source = conf->gen.reset_source;
3070 conf->gen.tentative_source = conf->gen.reset_source;
3071 conf->gen.status |= GUC_HAVE_TENTATIVE;
3077 struct config_real *conf = (struct config_real *) gconf;
3079 if (conf->assign_hook)
3080 if (!(*conf->assign_hook) (conf->reset_val, true,
3082 elog(ERROR, "failed to reset %s", conf->gen.name);
3083 *conf->variable = conf->reset_val;
3084 conf->tentative_val = conf->reset_val;
3085 conf->gen.source = conf->gen.reset_source;
3086 conf->gen.tentative_source = conf->gen.reset_source;
3087 conf->gen.status |= GUC_HAVE_TENTATIVE;
3093 struct config_string *conf = (struct config_string *) gconf;
3096 if (conf->reset_val == NULL)
3098 /* Nothing to reset to, as yet; so do nothing */
3102 /* We need not strdup here */
3103 str = conf->reset_val;
3105 if (conf->assign_hook)
3109 newstr = (*conf->assign_hook) (str, true,
3112 elog(ERROR, "failed to reset %s", conf->gen.name);
3113 else if (newstr != str)
3116 * See notes in set_config_option about casting
3118 str = (char *) newstr;
3122 set_string_field(conf, conf->variable, str);
3123 set_string_field(conf, &conf->tentative_val, str);
3124 conf->gen.source = conf->gen.reset_source;
3125 conf->gen.tentative_source = conf->gen.reset_source;
3126 conf->gen.status |= GUC_HAVE_TENTATIVE;
3132 if (gconf->flags & GUC_REPORT)
3133 ReportGUCOption(gconf);
3140 * Push previous state during first assignment to a GUC variable
3141 * within a particular transaction.
3143 * We have to be willing to "back-fill" the state stack if the first
3144 * assignment occurs within a subtransaction nested several levels deep.
3145 * This ensures that if an intermediate transaction aborts, it will have
3146 * the proper value available to restore the setting to.
3149 push_old_value(struct config_generic * gconf)
3151 int my_level = GetCurrentTransactionNestLevel();
3154 /* If we're not inside a transaction, do nothing */
3160 /* Done if we already pushed it at this nesting depth */
3161 if (gconf->stack && gconf->stack->nest_level >= my_level)
3165 * We keep all the stack entries in TopTransactionContext so as to
3166 * avoid allocation problems when a subtransaction back-fills stack
3167 * entries for upper transaction levels.
3169 stack = (GucStack *) MemoryContextAlloc(TopTransactionContext,
3172 stack->prev = gconf->stack;
3173 stack->nest_level = stack->prev ? stack->prev->nest_level + 1 : 1;
3174 stack->status = gconf->status;
3175 stack->tentative_source = gconf->tentative_source;
3176 stack->source = gconf->source;
3178 switch (gconf->vartype)
3181 stack->tentative_val.boolval =
3182 ((struct config_bool *) gconf)->tentative_val;
3183 stack->value.boolval =
3184 *((struct config_bool *) gconf)->variable;
3188 stack->tentative_val.intval =
3189 ((struct config_int *) gconf)->tentative_val;
3190 stack->value.intval =
3191 *((struct config_int *) gconf)->variable;
3195 stack->tentative_val.realval =
3196 ((struct config_real *) gconf)->tentative_val;
3197 stack->value.realval =
3198 *((struct config_real *) gconf)->variable;
3202 stack->tentative_val.stringval =
3203 ((struct config_string *) gconf)->tentative_val;
3204 stack->value.stringval =
3205 *((struct config_string *) gconf)->variable;
3209 gconf->stack = stack;
3211 /* Set state to indicate nothing happened yet within this level */
3212 gconf->status = GUC_HAVE_STACK;
3214 /* Ensure we remember to pop at end of xact */
3220 * Do GUC processing at transaction or subtransaction commit or abort.
3223 AtEOXact_GUC(bool isCommit, bool isSubXact)
3228 /* Quick exit if nothing's changed in this transaction */
3232 my_level = GetCurrentTransactionNestLevel();
3233 Assert(isSubXact ? (my_level > 1) : (my_level == 1));
3235 for (i = 0; i < num_guc_variables; i++)
3237 struct config_generic *gconf = guc_variables[i];
3238 int my_status = gconf->status;
3239 GucStack *stack = gconf->stack;
3244 * Skip if nothing's happened to this var in this transaction
3248 Assert(stack == NULL);
3251 /* Assert that we stacked old value before changing it */
3252 Assert(stack != NULL && (my_status & GUC_HAVE_STACK));
3253 /* However, the last change may have been at an outer xact level */
3254 if (stack->nest_level < my_level)
3256 Assert(stack->nest_level == my_level);
3259 * We will pop the stack entry. Start by restoring outer xact status
3260 * (since we may want to modify it below). Be careful to use
3261 * my_status to reference the inner xact status below this point...
3263 gconf->status = stack->status;
3266 * We have two cases:
3268 * If commit and HAVE_TENTATIVE, set actual value to tentative (this
3269 * is to override a SET LOCAL if one occurred later than SET). We keep
3270 * the tentative value and propagate HAVE_TENTATIVE to the parent
3271 * status, allowing the SET's effect to percolate up. (But if we're
3272 * exiting the outermost transaction, we'll drop the HAVE_TENTATIVE
3275 * Otherwise, we have a transaction that aborted or executed only SET
3276 * LOCAL (or no SET at all). In either case it should have no further
3277 * effect, so restore both tentative and actual values from the stack
3281 useTentative = isCommit && (my_status & GUC_HAVE_TENTATIVE) != 0;
3284 switch (gconf->vartype)
3288 struct config_bool *conf = (struct config_bool *) gconf;
3290 GucSource newsource;
3294 newval = conf->tentative_val;
3295 newsource = conf->gen.tentative_source;
3296 conf->gen.status |= GUC_HAVE_TENTATIVE;
3300 newval = stack->value.boolval;
3301 newsource = stack->source;
3302 conf->tentative_val = stack->tentative_val.boolval;
3303 conf->gen.tentative_source = stack->tentative_source;
3306 if (*conf->variable != newval)
3308 if (conf->assign_hook)
3309 if (!(*conf->assign_hook) (newval,
3310 true, PGC_S_OVERRIDE))
3311 elog(LOG, "failed to commit %s",
3313 *conf->variable = newval;
3316 conf->gen.source = newsource;
3321 struct config_int *conf = (struct config_int *) gconf;
3323 GucSource newsource;
3327 newval = conf->tentative_val;
3328 newsource = conf->gen.tentative_source;
3329 conf->gen.status |= GUC_HAVE_TENTATIVE;
3333 newval = stack->value.intval;
3334 newsource = stack->source;
3335 conf->tentative_val = stack->tentative_val.intval;
3336 conf->gen.tentative_source = stack->tentative_source;
3339 if (*conf->variable != newval)
3341 if (conf->assign_hook)
3342 if (!(*conf->assign_hook) (newval,
3343 true, PGC_S_OVERRIDE))
3344 elog(LOG, "failed to commit %s",
3346 *conf->variable = newval;
3349 conf->gen.source = newsource;
3354 struct config_real *conf = (struct config_real *) gconf;
3356 GucSource newsource;
3360 newval = conf->tentative_val;
3361 newsource = conf->gen.tentative_source;
3362 conf->gen.status |= GUC_HAVE_TENTATIVE;
3366 newval = stack->value.realval;
3367 newsource = stack->source;
3368 conf->tentative_val = stack->tentative_val.realval;
3369 conf->gen.tentative_source = stack->tentative_source;
3372 if (*conf->variable != newval)
3374 if (conf->assign_hook)
3375 if (!(*conf->assign_hook) (newval,
3376 true, PGC_S_OVERRIDE))
3377 elog(LOG, "failed to commit %s",
3379 *conf->variable = newval;
3382 conf->gen.source = newsource;
3387 struct config_string *conf = (struct config_string *) gconf;
3389 GucSource newsource;
3393 newval = conf->tentative_val;
3394 newsource = conf->gen.tentative_source;
3395 conf->gen.status |= GUC_HAVE_TENTATIVE;
3399 newval = stack->value.stringval;
3400 newsource = stack->source;
3401 set_string_field(conf, &conf->tentative_val,
3402 stack->tentative_val.stringval);
3403 conf->gen.tentative_source = stack->tentative_source;
3406 if (*conf->variable != newval)
3408 if (conf->assign_hook)
3412 newstr = (*conf->assign_hook) (newval, true,
3415 elog(LOG, "failed to commit %s",
3417 else if (newstr != newval)
3420 * If newval should now be freed, it'll be
3421 * taken care of below.
3423 * See notes in set_config_option about
3426 newval = (char *) newstr;
3430 set_string_field(conf, conf->variable, newval);
3433 conf->gen.source = newsource;
3434 /* Release stacked values if not used anymore */
3435 set_string_field(conf, &stack->value.stringval,
3437 set_string_field(conf, &stack->tentative_val.stringval,
3439 /* Don't store tentative value separately after commit */
3441 set_string_field(conf, &conf->tentative_val, NULL);
3446 /* Finish popping the state stack */
3447 gconf->stack = stack->prev;
3451 * If we're now out of all xact levels, forget TENTATIVE status bit;
3452 * there's nothing tentative about the value anymore.
3456 Assert(gconf->stack == NULL);
3460 /* Report new value if we changed it */
3461 if (changed && (gconf->flags & GUC_REPORT))
3462 ReportGUCOption(gconf);
3466 * If we're now out of all xact levels, we can clear guc_dirty. (Note: we
3467 * cannot reset guc_dirty when exiting a subtransaction, because we know
3468 * that all outer transaction levels will have stacked values to deal
3477 * Start up automatic reporting of changes to variables marked GUC_REPORT.
3478 * This is executed at completion of backend startup.
3481 BeginReportingGUCOptions(void)
3486 * Don't do anything unless talking to an interactive frontend of protocol
3489 if (whereToSendOutput != DestRemote ||
3490 PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
3493 reporting_enabled = true;
3495 /* Transmit initial values of interesting variables */
3496 for (i = 0; i < num_guc_variables; i++)
3498 struct config_generic *conf = guc_variables[i];
3500 if (conf->flags & GUC_REPORT)
3501 ReportGUCOption(conf);
3506 * ReportGUCOption: if appropriate, transmit option value to frontend
3509 ReportGUCOption(struct config_generic * record)
3511 if (reporting_enabled && (record->flags & GUC_REPORT))
3513 char *val = _ShowOption(record, false);
3514 StringInfoData msgbuf;
3516 pq_beginmessage(&msgbuf, 'S');
3517 pq_sendstring(&msgbuf, record->name);
3518 pq_sendstring(&msgbuf, val);
3519 pq_endmessage(&msgbuf);
3527 * Try to interpret value as boolean value. Valid values are: true,
3528 * false, yes, no, on, off, 1, 0. If the string parses okay, return
3529 * true, else false. If result is not NULL, return the parsing result
3533 parse_bool(const char *value, bool *result)
3535 size_t len = strlen(value);
3537 if (pg_strncasecmp(value, "true", len) == 0)
3542 else if (pg_strncasecmp(value, "false", len) == 0)
3548 else if (pg_strncasecmp(value, "yes", len) == 0)
3553 else if (pg_strncasecmp(value, "no", len) == 0)
3559 else if (pg_strcasecmp(value, "on") == 0)
3564 else if (pg_strcasecmp(value, "off") == 0)
3570 else if (pg_strcasecmp(value, "1") == 0)
3575 else if (pg_strcasecmp(value, "0") == 0)
3584 *result = false; /* suppress compiler warning */
3593 * Try to parse value as an integer. The accepted formats are the
3594 * usual decimal, octal, or hexadecimal formats. If the string parses
3595 * okay, return true, else false. If result is not NULL, return the
3599 parse_int(const char *value, int *result, int flags)
3605 val = strtol(value, &endptr, 0);
3607 if ((flags & GUC_UNIT_MEMORY) && endptr != value)
3611 while (*endptr == ' ')
3614 if (strcmp(endptr, "kB") == 0)
3619 else if (strcmp(endptr, "MB") == 0)
3625 else if (strcmp(endptr, "GB") == 0)
3634 switch (flags & GUC_UNIT_MEMORY)
3636 case GUC_UNIT_BLOCKS:
3637 val /= (BLCKSZ / 1024);
3639 case GUC_UNIT_XBLOCKS:
3640 val /= (XLOG_BLCKSZ / 1024);
3646 if ((flags & GUC_UNIT_TIME) && endptr != value)
3650 while (*endptr == ' ')
3653 if (strcmp(endptr, "ms") == 0)
3658 else if (strcmp(endptr, "s") == 0)
3664 else if (strcmp(endptr, "min") == 0)
3670 else if (strcmp(endptr, "h") == 0)
3676 else if (strcmp(endptr, "d") == 0)
3685 switch (flags & GUC_UNIT_TIME)
3697 if (endptr == value || *endptr != '\0' || errno == ERANGE
3698 #ifdef HAVE_LONG_INT_64
3699 /* if long > 32 bits, check for overflow of int4 */
3700 || val != (long) ((int32) val)
3705 *result = 0; /* suppress compiler warning */
3709 *result = (int) val;
3716 * Try to parse value as a floating point constant in the usual
3717 * format. If the value parsed okay return true, else false. If
3718 * result is not NULL, return the semantic value there.
3721 parse_real(const char *value, double *result)
3727 val = strtod(value, &endptr);
3728 if (endptr == value || *endptr != '\0' || errno == ERANGE)
3731 *result = 0; /* suppress compiler warning */
3741 * Call a GucStringAssignHook function, being careful to free the
3742 * "newval" string if the hook ereports.
3744 * This is split out of set_config_option just to avoid the "volatile"
3745 * qualifiers that would otherwise have to be plastered all over.
3748 call_string_assign_hook(GucStringAssignHook assign_hook,
3749 char *newval, bool doit, GucSource source)
3755 result = (*assign_hook) (newval, doit, source);
3769 * Sets option `name' to given value. The value should be a string
3770 * which is going to be parsed and converted to the appropriate data
3771 * type. The context and source parameters indicate in which context this
3772 * function is being called so it can apply the access restrictions
3775 * If value is NULL, set the option to its default value. If the
3776 * parameter changeVal is false then don't really set the option but do all
3777 * the checks to see if it would work.
3779 * If there is an error (non-existing option, invalid value) then an
3780 * ereport(ERROR) is thrown *unless* this is called in a context where we
3781 * don't want to ereport (currently, startup or SIGHUP config file reread).
3782 * In that case we write a suitable error message via ereport(DEBUG) and
3783 * return false. This is working around the deficiencies in the ereport
3784 * mechanism, so don't blame me. In all other cases, the function
3785 * returns true, including cases where the input is valid but we chose
3786 * not to apply it because of context or source-priority considerations.
3788 * See also SetConfigOption for an external interface.
3791 set_config_option(const char *name, const char *value,
3792 GucContext context, GucSource source,
3793 bool isLocal, bool changeVal)
3795 struct config_generic *record;
3799 if (context == PGC_SIGHUP || source == PGC_S_DEFAULT)
3802 * To avoid cluttering the log, only the postmaster bleats loudly
3803 * about problems with the config file.
3805 elevel = IsUnderPostmaster ? DEBUG2 : LOG;
3807 else if (source == PGC_S_DATABASE || source == PGC_S_USER)
3812 record = find_option(name, elevel);
3816 (errcode(ERRCODE_UNDEFINED_OBJECT),
3817 errmsg("unrecognized configuration parameter \"%s\"", name)));
3822 * Check if the option can be set at this time. See guc.h for the precise
3823 * rules. Note that we don't want to throw errors if we're in the SIGHUP
3824 * context. In that case we just ignore the attempt and return true.
3826 switch (record->context)
3829 if (context == PGC_SIGHUP)
3831 if (context != PGC_INTERNAL)
3834 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3835 errmsg("parameter \"%s\" cannot be changed",
3840 case PGC_POSTMASTER:
3841 if (context == PGC_SIGHUP)
3843 if (changeVal && !is_newvalue_equal(record, value))
3845 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3846 errmsg("parameter \"%s\" cannot be changed after server start; configuration file change ignored",
3851 if (context != PGC_POSTMASTER)
3854 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3855 errmsg("parameter \"%s\" cannot be changed after server start",
3861 if (context != PGC_SIGHUP && context != PGC_POSTMASTER)
3864 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3865 errmsg("parameter \"%s\" cannot be changed now",
3871 * Hmm, the idea of the SIGHUP context is "ought to be global, but
3872 * can be changed after postmaster start". But there's nothing
3873 * that prevents a crafty administrator from sending SIGHUP
3874 * signals to individual backends only.
3878 if (context == PGC_SIGHUP)
3881 * If a PGC_BACKEND parameter is changed in the config file,
3882 * we want to accept the new value in the postmaster (whence
3883 * it will propagate to subsequently-started backends), but
3884 * ignore it in existing backends. This is a tad klugy, but
3885 * necessary because we don't re-read the config file during
3888 if (IsUnderPostmaster)
3891 else if (context != PGC_BACKEND && context != PGC_POSTMASTER)
3894 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3895 errmsg("parameter \"%s\" cannot be set after connection start",
3901 if (context == PGC_USERSET || context == PGC_BACKEND)
3904 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3905 errmsg("permission denied to set parameter \"%s\"",
3916 * Should we set reset/stacked values? (If so, the behavior is not
3919 makeDefault = changeVal && (source <= PGC_S_OVERRIDE) && (value != NULL);
3922 * Ignore attempted set if overridden by previously processed setting.
3923 * However, if changeVal is false then plow ahead anyway since we are
3924 * trying to find out if the value is potentially good, not actually use
3925 * it. Also keep going if makeDefault is true, since we may want to set
3926 * the reset/stacked values even if we can't set the variable itself.
3928 if (record->source > source)
3930 if (changeVal && !makeDefault)
3932 elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
3940 * Evaluate value and set variable.
3942 switch (record->vartype)
3946 struct config_bool *conf = (struct config_bool *) record;
3951 if (!parse_bool(value, &newval))
3954 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3955 errmsg("parameter \"%s\" requires a Boolean value",
3962 newval = conf->reset_val;
3963 source = conf->gen.reset_source;
3966 if (conf->assign_hook)
3967 if (!(*conf->assign_hook) (newval, changeVal, source))
3970 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3971 errmsg("invalid value for parameter \"%s\": %d",
3972 name, (int) newval)));
3976 if (changeVal || makeDefault)
3978 /* Save old value to support transaction abort */
3980 push_old_value(&conf->gen);
3983 *conf->variable = newval;
3984 conf->gen.source = source;
3990 if (conf->gen.reset_source <= source)
3992 conf->reset_val = newval;
3993 conf->gen.reset_source = source;
3995 for (stack = conf->gen.stack; stack; stack = stack->prev)
3997 if (stack->source <= source)
3999 stack->value.boolval = newval;
4000 stack->source = source;
4006 conf->gen.status |= GUC_HAVE_LOCAL;
4011 conf->tentative_val = newval;
4012 conf->gen.tentative_source = source;
4013 conf->gen.status |= GUC_HAVE_TENTATIVE;
4022 struct config_int *conf = (struct config_int *) record;
4027 if (!parse_int(value, &newval, conf->gen.flags))
4030 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4031 errmsg("parameter \"%s\" requires an integer value",
4035 if (newval < conf->min || newval > conf->max)
4038 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4039 errmsg("%d is outside the valid range for parameter \"%s\" (%d .. %d)",
4040 newval, name, conf->min, conf->max)));
4046 newval = conf->reset_val;
4047 source = conf->gen.reset_source;
4050 if (conf->assign_hook)
4051 if (!(*conf->assign_hook) (newval, changeVal, source))
4054 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4055 errmsg("invalid value for parameter \"%s\": %d",
4060 if (changeVal || makeDefault)
4062 /* Save old value to support transaction abort */
4064 push_old_value(&conf->gen);
4067 *conf->variable = newval;
4068 conf->gen.source = source;
4074 if (conf->gen.reset_source <= source)
4076 conf->reset_val = newval;
4077 conf->gen.reset_source = source;
4079 for (stack = conf->gen.stack; stack; stack = stack->prev)
4081 if (stack->source <= source)
4083 stack->value.intval = newval;
4084 stack->source = source;
4090 conf->gen.status |= GUC_HAVE_LOCAL;
4095 conf->tentative_val = newval;
4096 conf->gen.tentative_source = source;
4097 conf->gen.status |= GUC_HAVE_TENTATIVE;
4106 struct config_real *conf = (struct config_real *) record;
4111 if (!parse_real(value, &newval))
4114 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4115 errmsg("parameter \"%s\" requires a numeric value",
4119 if (newval < conf->min || newval > conf->max)
4122 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4123 errmsg("%g is outside the valid range for parameter \"%s\" (%g .. %g)",
4124 newval, name, conf->min, conf->max)));
4130 newval = conf->reset_val;
4131 source = conf->gen.reset_source;
4134 if (conf->assign_hook)
4135 if (!(*conf->assign_hook) (newval, changeVal, source))
4138 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4139 errmsg("invalid value for parameter \"%s\": %g",
4144 if (changeVal || makeDefault)
4146 /* Save old value to support transaction abort */
4148 push_old_value(&conf->gen);
4151 *conf->variable = newval;
4152 conf->gen.source = source;
4158 if (conf->gen.reset_source <= source)
4160 conf->reset_val = newval;
4161 conf->gen.reset_source = source;
4163 for (stack = conf->gen.stack; stack; stack = stack->prev)
4165 if (stack->source <= source)
4167 stack->value.realval = newval;
4168 stack->source = source;
4174 conf->gen.status |= GUC_HAVE_LOCAL;
4179 conf->tentative_val = newval;
4180 conf->gen.tentative_source = source;
4181 conf->gen.status |= GUC_HAVE_TENTATIVE;
4190 struct config_string *conf = (struct config_string *) record;
4195 newval = guc_strdup(elevel, value);
4200 * The only sort of "parsing" check we need to do is apply
4201 * truncation if GUC_IS_NAME.
4203 if (conf->gen.flags & GUC_IS_NAME)
4204 truncate_identifier(newval, strlen(newval), true);
4206 else if (conf->reset_val)
4209 * We could possibly avoid strdup here, but easier to make
4210 * this case work the same as the normal assignment case.
4212 newval = guc_strdup(elevel, conf->reset_val);
4215 source = conf->gen.reset_source;
4219 /* Nothing to reset to, as yet; so do nothing */
4223 if (conf->assign_hook)
4225 const char *hookresult;
4228 * If the hook ereports, we have to make sure we free
4229 * newval, else it will be a permanent memory leak.
4231 hookresult = call_string_assign_hook(conf->assign_hook,
4235 if (hookresult == NULL)
4239 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4240 errmsg("invalid value for parameter \"%s\": \"%s\"",
4241 name, value ? value : "")));
4244 else if (hookresult != newval)
4249 * Having to cast away const here is annoying, but the
4250 * alternative is to declare assign_hooks as returning
4251 * char*, which would mean they'd have to cast away
4252 * const, or as both taking and returning char*, which
4253 * doesn't seem attractive either --- we don't want
4254 * them to scribble on the passed str.
4256 newval = (char *) hookresult;
4260 if (changeVal || makeDefault)
4262 /* Save old value to support transaction abort */
4264 push_old_value(&conf->gen);
4267 set_string_field(conf, conf->variable, newval);
4268 conf->gen.source = source;
4274 if (conf->gen.reset_source <= source)
4276 set_string_field(conf, &conf->reset_val, newval);
4277 conf->gen.reset_source = source;
4279 for (stack = conf->gen.stack; stack; stack = stack->prev)
4281 if (stack->source <= source)
4283 set_string_field(conf, &stack->value.stringval,
4285 stack->source = source;
4288 /* Perhaps we didn't install newval anywhere */
4289 if (!string_field_used(conf, newval))
4294 conf->gen.status |= GUC_HAVE_LOCAL;
4299 set_string_field(conf, &conf->tentative_val, newval);
4300 conf->gen.tentative_source = source;
4301 conf->gen.status |= GUC_HAVE_TENTATIVE;
4311 if (changeVal && (record->flags & GUC_REPORT))
4312 ReportGUCOption(record);
4319 * Set a config option to the given value. See also set_config_option,
4320 * this is just the wrapper to be called from outside GUC. NB: this
4321 * is used only for non-transactional operations.
4324 SetConfigOption(const char *name, const char *value,
4325 GucContext context, GucSource source)
4327 (void) set_config_option(name, value, context, source, false, true);
4333 * Fetch the current value of the option `name'. If the option doesn't exist,
4334 * throw an ereport and don't return.
4336 * The string is *not* allocated for modification and is really only
4337 * valid until the next call to configuration related functions.
4340 GetConfigOption(const char *name)
4342 struct config_generic *record;
4343 static char buffer[256];
4345 record = find_option(name, ERROR);
4348 (errcode(ERRCODE_UNDEFINED_OBJECT),
4349 errmsg("unrecognized configuration parameter \"%s\"", name)));
4350 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
4352 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4353 errmsg("must be superuser to examine \"%s\"", name)));
4355 switch (record->vartype)
4358 return *((struct config_bool *) record)->variable ? "on" : "off";
4361 snprintf(buffer, sizeof(buffer), "%d",
4362 *((struct config_int *) record)->variable);
4366 snprintf(buffer, sizeof(buffer), "%g",
4367 *((struct config_real *) record)->variable);
4371 return *((struct config_string *) record)->variable;
4377 * Get the RESET value associated with the given option.
4380 GetConfigOptionResetString(const char *name)
4382 struct config_generic *record;
4383 static char buffer[256];
4385 record = find_option(name, ERROR);
4388 (errcode(ERRCODE_UNDEFINED_OBJECT),
4389 errmsg("unrecognized configuration parameter \"%s\"", name)));
4390 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
4392 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4393 errmsg("must be superuser to examine \"%s\"", name)));
4395 switch (record->vartype)
4398 return ((struct config_bool *) record)->reset_val ? "on" : "off";
4401 snprintf(buffer, sizeof(buffer), "%d",
4402 ((struct config_int *) record)->reset_val);
4406 snprintf(buffer, sizeof(buffer), "%g",
4407 ((struct config_real *) record)->reset_val);
4411 return ((struct config_string *) record)->reset_val;
4417 * Detect whether the given configuration option can only be set by
4421 IsSuperuserConfigOption(const char *name)
4423 struct config_generic *record;
4425 record = find_option(name, ERROR);
4426 /* On an unrecognized name, don't error, just return false. */
4429 return (record->context == PGC_SUSET);
4434 * flatten_set_variable_args
4435 * Given a parsenode List as emitted by the grammar for SET,
4436 * convert to the flat string representation used by GUC.
4438 * We need to be told the name of the variable the args are for, because
4439 * the flattening rules vary (ugh).
4441 * The result is NULL if input is NIL (ie, SET ... TO DEFAULT), otherwise
4442 * a palloc'd string.
4445 flatten_set_variable_args(const char *name, List *args)
4447 struct config_generic *record;
4453 * Fast path if just DEFAULT. We do not check the variable name in this
4454 * case --- necessary for RESET ALL to work correctly.
4459 /* Else get flags for the variable */
4460 record = find_option(name, ERROR);
4463 (errcode(ERRCODE_UNDEFINED_OBJECT),
4464 errmsg("unrecognized configuration parameter \"%s\"", name)));
4466 flags = record->flags;
4468 /* Complain if list input and non-list variable */
4469 if ((flags & GUC_LIST_INPUT) == 0 &&
4470 list_length(args) != 1)
4472 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4473 errmsg("SET %s takes only one argument", name)));
4475 initStringInfo(&buf);
4479 A_Const *arg = (A_Const *) lfirst(l);
4482 if (l != list_head(args))
4483 appendStringInfo(&buf, ", ");
4485 if (!IsA(arg, A_Const))
4486 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
4488 switch (nodeTag(&arg->val))
4491 appendStringInfo(&buf, "%ld", intVal(&arg->val));
4494 /* represented as a string, so just copy it */
4495 appendStringInfoString(&buf, strVal(&arg->val));
4498 val = strVal(&arg->val);
4499 if (arg->typename != NULL)
4502 * Must be a ConstInterval argument for TIME ZONE. Coerce
4503 * to interval and back to normalize the value and account
4510 DirectFunctionCall3(interval_in,
4511 CStringGetDatum(val),
4512 ObjectIdGetDatum(InvalidOid),
4513 Int32GetDatum(arg->typename->typmod));
4516 DatumGetCString(DirectFunctionCall1(interval_out,
4518 appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
4523 * Plain string literal or identifier. For quote mode,
4524 * quote it if it's not a vanilla identifier.
4526 if (flags & GUC_LIST_QUOTE)
4527 appendStringInfoString(&buf, quote_identifier(val));
4529 appendStringInfoString(&buf, val);
4533 elog(ERROR, "unrecognized node type: %d",
4534 (int) nodeTag(&arg->val));
4547 SetPGVariable(const char *name, List *args, bool is_local)
4549 char *argstring = flatten_set_variable_args(name, args);
4551 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
4552 set_config_option(name,
4554 (superuser() ? PGC_SUSET : PGC_USERSET),
4561 * SET command wrapped as a SQL callable function.
4564 set_config_by_name(PG_FUNCTION_ARGS)
4572 if (PG_ARGISNULL(0))
4574 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
4575 errmsg("SET requires parameter name")));
4577 /* Get the GUC variable name */
4578 name = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(0)));
4580 /* Get the desired value or set to NULL for a reset request */
4581 if (PG_ARGISNULL(1))
4584 value = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(1)));
4587 * Get the desired state of is_local. Default to false if provided value
4590 if (PG_ARGISNULL(2))
4593 is_local = PG_GETARG_BOOL(2);
4595 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
4596 set_config_option(name,
4598 (superuser() ? PGC_SUSET : PGC_USERSET),
4603 /* get the new current value */
4604 new_value = GetConfigOptionByName(name, NULL);
4606 /* Convert return string to text */
4607 result_text = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(new_value)));
4610 PG_RETURN_TEXT_P(result_text);
4614 define_custom_variable(struct config_generic * variable)
4616 const char *name = variable->name;
4617 const char **nameAddr = &name;
4619 struct config_string *pHolder;
4620 struct config_generic **res = (struct config_generic **) bsearch(
4622 (void *) guc_variables,
4624 sizeof(struct config_generic *),
4629 add_guc_variable(variable, ERROR);
4634 * This better be a placeholder
4636 if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
4638 (errcode(ERRCODE_INTERNAL_ERROR),
4639 errmsg("attempt to redefine parameter \"%s\"", name)));
4641 Assert((*res)->vartype == PGC_STRING);
4642 pHolder = (struct config_string *) * res;
4644 /* We have the same name, no sorting is necessary */
4647 value = *pHolder->variable;
4650 * Assign the string value stored in the placeholder to the real variable.
4652 * XXX this is not really good enough --- it should be a nontransactional
4653 * assignment, since we don't want it to roll back if the current xact
4656 set_config_option(name, value,
4657 pHolder->gen.context, pHolder->gen.source,
4661 * Free up as much as we conveniently can of the placeholder structure
4662 * (this neglects any stack items...)
4664 set_string_field(pHolder, pHolder->variable, NULL);
4665 set_string_field(pHolder, &pHolder->reset_val, NULL);
4666 set_string_field(pHolder, &pHolder->tentative_val, NULL);
4672 init_custom_variable(struct config_generic * gen,
4674 const char *short_desc,
4675 const char *long_desc,
4677 enum config_type type)
4679 gen->name = guc_strdup(ERROR, name);
4680 gen->context = context;
4681 gen->group = CUSTOM_OPTIONS;
4682 gen->short_desc = short_desc;
4683 gen->long_desc = long_desc;
4684 gen->vartype = type;
4688 DefineCustomBoolVariable(const char *name,
4689 const char *short_desc,
4690 const char *long_desc,
4693 GucBoolAssignHook assign_hook,
4694 GucShowHook show_hook)
4696 size_t sz = sizeof(struct config_bool);
4697 struct config_bool *var = (struct config_bool *) guc_malloc(ERROR, sz);
4700 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_BOOL);
4702 var->variable = valueAddr;
4703 var->reset_val = *valueAddr;
4704 var->assign_hook = assign_hook;
4705 var->show_hook = show_hook;
4706 define_custom_variable(&var->gen);
4710 DefineCustomIntVariable(const char *name,
4711 const char *short_desc,
4712 const char *long_desc,
4717 GucIntAssignHook assign_hook,
4718 GucShowHook show_hook)
4720 size_t sz = sizeof(struct config_int);
4721 struct config_int *var = (struct config_int *) guc_malloc(ERROR, sz);
4724 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_INT);
4726 var->variable = valueAddr;
4727 var->reset_val = *valueAddr;
4728 var->min = minValue;
4729 var->max = maxValue;
4730 var->assign_hook = assign_hook;
4731 var->show_hook = show_hook;
4732 define_custom_variable(&var->gen);
4736 DefineCustomRealVariable(const char *name,
4737 const char *short_desc,
4738 const char *long_desc,
4743 GucRealAssignHook assign_hook,
4744 GucShowHook show_hook)
4746 size_t sz = sizeof(struct config_real);
4747 struct config_real *var = (struct config_real *) guc_malloc(ERROR, sz);
4750 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_REAL);
4752 var->variable = valueAddr;
4753 var->reset_val = *valueAddr;
4754 var->min = minValue;
4755 var->max = maxValue;
4756 var->assign_hook = assign_hook;
4757 var->show_hook = show_hook;
4758 define_custom_variable(&var->gen);
4762 DefineCustomStringVariable(const char *name,
4763 const char *short_desc,
4764 const char *long_desc,
4767 GucStringAssignHook assign_hook,
4768 GucShowHook show_hook)
4770 size_t sz = sizeof(struct config_string);
4771 struct config_string *var = (struct config_string *) guc_malloc(ERROR, sz);
4774 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_STRING);
4776 var->variable = valueAddr;
4777 var->reset_val = *valueAddr;
4778 var->assign_hook = assign_hook;
4779 var->show_hook = show_hook;
4780 define_custom_variable(&var->gen);
4784 EmitWarningsOnPlaceholders(const char *className)
4786 struct config_generic **vars = guc_variables;
4787 struct config_generic **last = vars + num_guc_variables;
4789 int nameLen = strlen(className);
4793 struct config_generic *var = *vars++;
4795 if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
4796 strncmp(className, var->name, nameLen) == 0 &&
4797 var->name[nameLen] == GUC_QUALIFIER_SEPARATOR)
4800 (errcode(ERRCODE_UNDEFINED_OBJECT),
4801 errmsg("unrecognized configuration parameter \"%s\"", var->name)));
4811 GetPGVariable(const char *name, DestReceiver *dest)
4813 if (pg_strcasecmp(name, "all") == 0)
4814 ShowAllGUCConfig(dest);
4816 ShowGUCConfigOption(name, dest);
4820 GetPGVariableResultDesc(const char *name)
4824 if (pg_strcasecmp(name, "all") == 0)
4826 /* need a tuple descriptor representing three TEXT columns */
4827 tupdesc = CreateTemplateTupleDesc(3, false);
4828 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
4830 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
4832 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
4838 const char *varname;
4840 /* Get the canonical spelling of name */
4841 (void) GetConfigOptionByName(name, &varname);
4843 /* need a tuple descriptor representing a single TEXT column */
4844 tupdesc = CreateTemplateTupleDesc(1, false);
4845 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
4855 ResetPGVariable(const char *name)
4857 if (pg_strcasecmp(name, "all") == 0)
4860 set_config_option(name,
4862 (superuser() ? PGC_SUSET : PGC_USERSET),
4873 ShowGUCConfigOption(const char *name, DestReceiver *dest)
4875 TupOutputState *tstate;
4877 const char *varname;
4880 /* Get the value and canonical spelling of name */
4881 value = GetConfigOptionByName(name, &varname);
4883 /* need a tuple descriptor representing a single TEXT column */
4884 tupdesc = CreateTemplateTupleDesc(1, false);
4885 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
4888 /* prepare for projection of tuples */
4889 tstate = begin_tup_output_tupdesc(dest, tupdesc);
4892 do_text_output_oneline(tstate, value);
4894 end_tup_output(tstate);
4901 ShowAllGUCConfig(DestReceiver *dest)
4903 bool am_superuser = superuser();
4905 TupOutputState *tstate;
4909 /* need a tuple descriptor representing three TEXT columns */
4910 tupdesc = CreateTemplateTupleDesc(3, false);
4911 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
4913 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
4915 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
4919 /* prepare for projection of tuples */
4920 tstate = begin_tup_output_tupdesc(dest, tupdesc);
4922 for (i = 0; i < num_guc_variables; i++)
4924 struct config_generic *conf = guc_variables[i];
4926 if ((conf->flags & GUC_NO_SHOW_ALL) ||
4927 ((conf->flags & GUC_SUPERUSER_ONLY) && !am_superuser))
4930 /* assign to the values array */
4931 values[0] = (char *) conf->name;
4932 values[1] = _ShowOption(conf, true);
4933 values[2] = (char *) conf->short_desc;
4935 /* send it to dest */
4936 do_tup_output(tstate, values);
4939 if (values[1] != NULL)
4943 end_tup_output(tstate);
4947 * Return GUC variable value by name; optionally return canonical
4948 * form of name. Return value is palloc'd.
4951 GetConfigOptionByName(const char *name, const char **varname)
4953 struct config_generic *record;
4955 record = find_option(name, ERROR);
4958 (errcode(ERRCODE_UNDEFINED_OBJECT),
4959 errmsg("unrecognized configuration parameter \"%s\"", name)));
4960 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
4962 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4963 errmsg("must be superuser to examine \"%s\"", name)));
4966 *varname = record->name;
4968 return _ShowOption(record, true);
4972 * Return GUC variable value by variable number; optionally return canonical
4973 * form of name. Return value is palloc'd.
4976 GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
4979 struct config_generic *conf;
4981 /* check requested variable number valid */
4982 Assert((varnum >= 0) && (varnum < num_guc_variables));
4984 conf = guc_variables[varnum];
4988 if ((conf->flags & GUC_NO_SHOW_ALL) ||
4989 ((conf->flags & GUC_SUPERUSER_ONLY) && !superuser()))
4995 /* first get the generic attributes */
4998 values[0] = conf->name;
5000 /* setting : use _ShowOption in order to avoid duplicating the logic */
5001 values[1] = _ShowOption(conf, false);
5004 if (conf->vartype == PGC_INT)
5008 switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
5013 case GUC_UNIT_BLOCKS:
5014 snprintf(buf, sizeof(buf), "%dkB", BLCKSZ / 1024);
5017 case GUC_UNIT_XBLOCKS:
5018 snprintf(buf, sizeof(buf), "%dkB", XLOG_BLCKSZ / 1024);
5039 values[3] = config_group_names[conf->group];
5042 values[4] = conf->short_desc;
5045 values[5] = conf->long_desc;
5048 values[6] = GucContext_Names[conf->context];
5051 values[7] = config_type_names[conf->vartype];
5054 values[8] = GucSource_Names[conf->source];
5056 /* now get the type specifc attributes */
5057 switch (conf->vartype)
5071 struct config_int *lconf = (struct config_int *) conf;
5074 snprintf(buffer, sizeof(buffer), "%d", lconf->min);
5075 values[9] = pstrdup(buffer);
5078 snprintf(buffer, sizeof(buffer), "%d", lconf->max);
5079 values[10] = pstrdup(buffer);
5085 struct config_real *lconf = (struct config_real *) conf;
5088 snprintf(buffer, sizeof(buffer), "%g", lconf->min);
5089 values[9] = pstrdup(buffer);
5092 snprintf(buffer, sizeof(buffer), "%g", lconf->max);
5093 values[10] = pstrdup(buffer);
5110 * should never get here, but in case we do, set 'em to NULL
5124 * Return the total number of GUC variables
5127 GetNumConfigOptions(void)
5129 return num_guc_variables;
5133 * show_config_by_name - equiv to SHOW X command but implemented as
5137 show_config_by_name(PG_FUNCTION_ARGS)
5143 /* Get the GUC variable name */
5144 varname = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(0)));
5147 varval = GetConfigOptionByName(varname, NULL);
5149 /* Convert to text */
5150 result_text = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(varval)));
5153 PG_RETURN_TEXT_P(result_text);
5157 * show_all_settings - equiv to SHOW ALL command but implemented as
5160 #define NUM_PG_SETTINGS_ATTS 11
5163 show_all_settings(PG_FUNCTION_ARGS)
5165 FuncCallContext *funcctx;
5169 AttInMetadata *attinmeta;
5170 MemoryContext oldcontext;
5172 /* stuff done only on the first call of the function */
5173 if (SRF_IS_FIRSTCALL())
5175 /* create a function context for cross-call persistence */
5176 funcctx = SRF_FIRSTCALL_INIT();
5179 * switch to memory context appropriate for multiple function calls
5181 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
5184 * need a tuple descriptor representing NUM_PG_SETTINGS_ATTS columns
5185 * of the appropriate types
5187 tupdesc = CreateTemplateTupleDesc(NUM_PG_SETTINGS_ATTS, false);
5188 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
5190 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
5192 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "unit",
5194 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "category",
5196 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "short_desc",
5198 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "extra_desc",
5200 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "context",
5202 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "vartype",
5204 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "source",
5206 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "min_val",
5208 TupleDescInitEntry(tupdesc, (AttrNumber) 11, "max_val",
5212 * Generate attribute metadata needed later to produce tuples from raw
5215 attinmeta = TupleDescGetAttInMetadata(tupdesc);
5216 funcctx->attinmeta = attinmeta;
5218 /* total number of tuples to be returned */
5219 funcctx->max_calls = GetNumConfigOptions();
5221 MemoryContextSwitchTo(oldcontext);
5224 /* stuff done on every call of the function */
5225 funcctx = SRF_PERCALL_SETUP();
5227 call_cntr = funcctx->call_cntr;
5228 max_calls = funcctx->max_calls;
5229 attinmeta = funcctx->attinmeta;
5231 if (call_cntr < max_calls) /* do when there is more left to send */
5233 char *values[NUM_PG_SETTINGS_ATTS];
5239 * Get the next visible GUC variable name and value
5243 GetConfigOptionByNum(call_cntr, (const char **) values, &noshow);
5246 /* bump the counter and get the next config setting */
5247 call_cntr = ++funcctx->call_cntr;
5249 /* make sure we haven't gone too far now */
5250 if (call_cntr >= max_calls)
5251 SRF_RETURN_DONE(funcctx);
5256 tuple = BuildTupleFromCStrings(attinmeta, values);
5258 /* make the tuple into a datum */
5259 result = HeapTupleGetDatum(tuple);
5261 SRF_RETURN_NEXT(funcctx, result);
5265 /* do when there is no more left */
5266 SRF_RETURN_DONE(funcctx);
5271 _ShowOption(struct config_generic * record, bool use_units)
5276 switch (record->vartype)
5280 struct config_bool *conf = (struct config_bool *) record;
5282 if (conf->show_hook)
5283 val = (*conf->show_hook) ();
5285 val = *conf->variable ? "on" : "off";
5291 struct config_int *conf = (struct config_int *) record;
5293 if (conf->show_hook)
5294 val = (*conf->show_hook) ();
5298 int result = *conf->variable;
5300 if (use_units && result > 0 && (record->flags & GUC_UNIT_MEMORY))
5302 switch (record->flags & GUC_UNIT_MEMORY)
5304 case GUC_UNIT_BLOCKS:
5305 result *= BLCKSZ / 1024;
5307 case GUC_UNIT_XBLOCKS:
5308 result *= XLOG_BLCKSZ / 1024;
5312 if (result % KB_PER_GB == 0)
5314 result /= KB_PER_GB;
5317 else if (result % KB_PER_MB == 0)
5319 result /= KB_PER_MB;
5327 else if (use_units && result > 0 && (record->flags & GUC_UNIT_TIME))
5329 switch (record->flags & GUC_UNIT_TIME)
5335 result *= MS_PER_MIN;
5339 if (result % MS_PER_D == 0)
5344 else if (result % MS_PER_H == 0)
5349 else if (result % MS_PER_MIN == 0)
5351 result /= MS_PER_MIN;
5352 strcpy(unit, "min");
5354 else if (result % MS_PER_S == 0)
5367 snprintf(buffer, sizeof(buffer), "%d%s",
5368 (int) result, unit);
5376 struct config_real *conf = (struct config_real *) record;
5378 if (conf->show_hook)
5379 val = (*conf->show_hook) ();
5382 snprintf(buffer, sizeof(buffer), "%g",
5391 struct config_string *conf = (struct config_string *) record;
5393 if (conf->show_hook)
5394 val = (*conf->show_hook) ();
5395 else if (*conf->variable && **conf->variable)
5396 val = *conf->variable;
5403 /* just to keep compiler quiet */
5408 return pstrdup(val);
5413 is_newvalue_equal(struct config_generic * record, const char *newvalue)
5415 switch (record->vartype)
5419 struct config_bool *conf = (struct config_bool *) record;
5422 return parse_bool(newvalue, &newval) && *conf->variable == newval;
5426 struct config_int *conf = (struct config_int *) record;
5429 return parse_int(newvalue, &newval, record->flags) && *conf->variable == newval;
5433 struct config_real *conf = (struct config_real *) record;
5436 return parse_real(newvalue, &newval) && *conf->variable == newval;
5440 struct config_string *conf = (struct config_string *) record;
5442 return strcmp(*conf->variable, newvalue) == 0;
5453 * This routine dumps out all non-default GUC options into a binary
5454 * file that is read by all exec'ed backends. The format is:
5456 * variable name, string, null terminated
5457 * variable value, string, null terminated
5458 * variable source, integer
5461 write_nondefault_variables(GucContext context)
5467 Assert(context == PGC_POSTMASTER || context == PGC_SIGHUP);
5469 elevel = (context == PGC_SIGHUP) ? LOG : ERROR;
5474 fp = AllocateFile(CONFIG_EXEC_PARAMS_NEW, "w");
5478 (errcode_for_file_access(),
5479 errmsg("could not write to file \"%s\": %m",
5480 CONFIG_EXEC_PARAMS_NEW)));
5484 for (i = 0; i < num_guc_variables; i++)
5486 struct config_generic *gconf = guc_variables[i];
5488 if (gconf->source != PGC_S_DEFAULT)
5490 fprintf(fp, "%s", gconf->name);
5493 switch (gconf->vartype)
5497 struct config_bool *conf = (struct config_bool *) gconf;
5499 if (*conf->variable == 0)
5500 fprintf(fp, "false");
5502 fprintf(fp, "true");
5508 struct config_int *conf = (struct config_int *) gconf;
5510 fprintf(fp, "%d", *conf->variable);
5516 struct config_real *conf = (struct config_real *) gconf;
5518 /* Could lose precision here? */
5519 fprintf(fp, "%f", *conf->variable);
5525 struct config_string *conf = (struct config_string *) gconf;
5527 fprintf(fp, "%s", *conf->variable);
5534 fwrite(&gconf->source, sizeof(gconf->source), 1, fp);
5541 (errcode_for_file_access(),
5542 errmsg("could not write to file \"%s\": %m",
5543 CONFIG_EXEC_PARAMS_NEW)));
5548 * Put new file in place. This could delay on Win32, but we don't hold
5549 * any exclusive locks.
5551 rename(CONFIG_EXEC_PARAMS_NEW, CONFIG_EXEC_PARAMS);
5556 * Read string, including null byte from file
5558 * Return NULL on EOF and nothing read
5561 read_string_with_null(FILE *fp)
5570 if ((ch = fgetc(fp)) == EOF)
5575 elog(FATAL, "invalid format of exec config params file");
5578 str = guc_malloc(FATAL, maxlen);
5579 else if (i == maxlen)
5580 str = guc_realloc(FATAL, str, maxlen *= 2);
5589 * This routine loads a previous postmaster dump of its non-default
5593 read_nondefault_variables(void)
5603 fp = AllocateFile(CONFIG_EXEC_PARAMS, "r");
5606 /* File not found is fine */
5607 if (errno != ENOENT)
5609 (errcode_for_file_access(),
5610 errmsg("could not read from file \"%s\": %m",
5611 CONFIG_EXEC_PARAMS)));
5617 struct config_generic *record;
5619 if ((varname = read_string_with_null(fp)) == NULL)
5622 if ((record = find_option(varname, FATAL)) == NULL)
5623 elog(FATAL, "failed to locate variable %s in exec config params file", varname);
5624 if ((varvalue = read_string_with_null(fp)) == NULL)
5625 elog(FATAL, "invalid format of exec config params file");
5626 if (fread(&varsource, sizeof(varsource), 1, fp) == 0)
5627 elog(FATAL, "invalid format of exec config params file");
5629 (void) set_config_option(varname, varvalue, record->context,
5630 varsource, false, true);
5637 #endif /* EXEC_BACKEND */
5641 * A little "long argument" simulation, although not quite GNU
5642 * compliant. Takes a string of the form "some-option=some value" and
5643 * returns name = "some_option" and value = "some value" in malloc'ed
5644 * storage. Note that '-' is converted to '_' in the option name. If
5645 * there is no '=' in the input string then value will be NULL.
5648 ParseLongOption(const char *string, char **name, char **value)
5657 equal_pos = strcspn(string, "=");
5659 if (string[equal_pos] == '=')
5661 *name = guc_malloc(FATAL, equal_pos + 1);
5662 strncpy(*name, string, equal_pos);
5663 (*name)[equal_pos] = '\0';
5665 *value = guc_strdup(FATAL, &string[equal_pos + 1]);
5669 /* no equal sign in string */
5670 *name = guc_strdup(FATAL, string);
5674 for (cp = *name; *cp; cp++)
5681 * Handle options fetched from pg_database.datconfig or pg_authid.rolconfig.
5682 * The array parameter must be an array of TEXT (it must not be NULL).
5685 ProcessGUCArray(ArrayType *array, GucSource source)
5689 Assert(array != NULL);
5690 Assert(ARR_ELEMTYPE(array) == TEXTOID);
5691 Assert(ARR_NDIM(array) == 1);
5692 Assert(ARR_LBOUND(array)[0] == 1);
5693 Assert(source == PGC_S_DATABASE || source == PGC_S_USER);
5695 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
5703 d = array_ref(array, 1, &i,
5704 -1 /* varlenarray */ ,
5705 -1 /* TEXT's typlen */ ,
5706 false /* TEXT's typbyval */ ,
5707 'i' /* TEXT's typalign */ ,
5713 s = DatumGetCString(DirectFunctionCall1(textout, d));
5715 ParseLongOption(s, &name, &value);
5719 (errcode(ERRCODE_SYNTAX_ERROR),
5720 errmsg("could not parse setting for parameter \"%s\"", name)));
5726 * We process all these options at SUSET level. We assume that the
5727 * right to insert an option into pg_database or pg_authid was checked
5728 * when it was inserted.
5730 SetConfigOption(name, value, PGC_SUSET, source);
5740 * Add an entry to an option array. The array parameter may be NULL
5741 * to indicate the current table entry is NULL.
5744 GUCArrayAdd(ArrayType *array, const char *name, const char *value)
5746 const char *varname;
5754 /* test if the option is valid */
5755 set_config_option(name, value,
5756 superuser() ? PGC_SUSET : PGC_USERSET,
5757 PGC_S_TEST, false, false);
5759 /* convert name to canonical spelling, so we can use plain strcmp */
5760 (void) GetConfigOptionByName(name, &varname);
5763 newval = palloc(strlen(name) + 1 + strlen(value) + 1);
5764 sprintf(newval, "%s=%s", name, value);
5765 datum = DirectFunctionCall1(textin, CStringGetDatum(newval));
5773 Assert(ARR_ELEMTYPE(array) == TEXTOID);
5774 Assert(ARR_NDIM(array) == 1);
5775 Assert(ARR_LBOUND(array)[0] == 1);
5777 index = ARR_DIMS(array)[0] + 1; /* add after end */
5779 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
5784 d = array_ref(array, 1, &i,
5785 -1 /* varlenarray */ ,
5786 -1 /* TEXT's typlen */ ,
5787 false /* TEXT's typbyval */ ,
5788 'i' /* TEXT's typalign */ ,
5792 current = DatumGetCString(DirectFunctionCall1(textout, d));
5793 if (strncmp(current, newval, strlen(name) + 1) == 0)
5800 a = array_set(array, 1, &index,
5803 -1 /* varlena array */ ,
5804 -1 /* TEXT's typlen */ ,
5805 false /* TEXT's typbyval */ ,
5806 'i' /* TEXT's typalign */ );
5809 a = construct_array(&datum, 1,
5818 * Delete an entry from an option array. The array parameter may be NULL
5819 * to indicate the current table entry is NULL. Also, if the return value
5820 * is NULL then a null should be stored.
5823 GUCArrayDelete(ArrayType *array, const char *name)
5825 const char *varname;
5826 ArrayType *newarray;
5832 /* test if the option is valid */
5833 set_config_option(name, NULL,
5834 superuser() ? PGC_SUSET : PGC_USERSET,
5835 PGC_S_TEST, false, false);
5837 /* convert name to canonical spelling, so we can use plain strcmp */
5838 (void) GetConfigOptionByName(name, &varname);
5841 /* if array is currently null, then surely nothing to delete */
5848 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
5854 d = array_ref(array, 1, &i,
5855 -1 /* varlenarray */ ,
5856 -1 /* TEXT's typlen */ ,
5857 false /* TEXT's typbyval */ ,
5858 'i' /* TEXT's typalign */ ,
5862 val = DatumGetCString(DirectFunctionCall1(textout, d));
5864 /* ignore entry if it's what we want to delete */
5865 if (strncmp(val, name, strlen(name)) == 0
5866 && val[strlen(name)] == '=')
5869 /* else add it to the output array */
5872 newarray = array_set(newarray, 1, &index,
5875 -1 /* varlenarray */ ,
5876 -1 /* TEXT's typlen */ ,
5877 false /* TEXT's typbyval */ ,
5878 'i' /* TEXT's typalign */ );
5881 newarray = construct_array(&d, 1,
5893 * assign_hook subroutines
5897 assign_log_destination(const char *value, bool doit, GucSource source)
5904 /* Need a modifiable copy of string */
5905 rawstring = pstrdup(value);
5907 /* Parse string into list of identifiers */
5908 if (!SplitIdentifierString(rawstring, ',', &elemlist))
5910 /* syntax error in list */
5912 list_free(elemlist);
5913 if (source >= PGC_S_INTERACTIVE)
5915 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5916 errmsg("invalid list syntax for parameter \"log_destination\"")));
5920 foreach(l, elemlist)
5922 char *tok = (char *) lfirst(l);
5924 if (pg_strcasecmp(tok, "stderr") == 0)
5925 newlogdest |= LOG_DESTINATION_STDERR;
5927 else if (pg_strcasecmp(tok, "syslog") == 0)
5928 newlogdest |= LOG_DESTINATION_SYSLOG;
5931 else if (pg_strcasecmp(tok, "eventlog") == 0)
5932 newlogdest |= LOG_DESTINATION_EVENTLOG;
5936 if (source >= PGC_S_INTERACTIVE)
5938 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5939 errmsg("unrecognized \"log_destination\" key word: \"%s\"",
5942 list_free(elemlist);
5948 Log_destination = newlogdest;
5951 list_free(elemlist);
5959 assign_syslog_facility(const char *facility, bool doit, GucSource source)
5963 if (pg_strcasecmp(facility, "LOCAL0") == 0)
5964 syslog_fac = LOG_LOCAL0;
5965 else if (pg_strcasecmp(facility, "LOCAL1") == 0)
5966 syslog_fac = LOG_LOCAL1;
5967 else if (pg_strcasecmp(facility, "LOCAL2") == 0)
5968 syslog_fac = LOG_LOCAL2;
5969 else if (pg_strcasecmp(facility, "LOCAL3") == 0)
5970 syslog_fac = LOG_LOCAL3;
5971 else if (pg_strcasecmp(facility, "LOCAL4") == 0)
5972 syslog_fac = LOG_LOCAL4;
5973 else if (pg_strcasecmp(facility, "LOCAL5") == 0)
5974 syslog_fac = LOG_LOCAL5;
5975 else if (pg_strcasecmp(facility, "LOCAL6") == 0)
5976 syslog_fac = LOG_LOCAL6;
5977 else if (pg_strcasecmp(facility, "LOCAL7") == 0)
5978 syslog_fac = LOG_LOCAL7;
5980 return NULL; /* reject */
5984 syslog_facility = syslog_fac;
5985 set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
5993 assign_syslog_ident(const char *ident, bool doit, GucSource source)
5996 set_syslog_parameters(ident, syslog_facility);
6000 #endif /* HAVE_SYSLOG */
6004 assign_defaultxactisolevel(const char *newval, bool doit, GucSource source)
6006 if (pg_strcasecmp(newval, "serializable") == 0)
6009 DefaultXactIsoLevel = XACT_SERIALIZABLE;
6011 else if (pg_strcasecmp(newval, "repeatable read") == 0)
6014 DefaultXactIsoLevel = XACT_REPEATABLE_READ;
6016 else if (pg_strcasecmp(newval, "read committed") == 0)
6019 DefaultXactIsoLevel = XACT_READ_COMMITTED;
6021 else if (pg_strcasecmp(newval, "read uncommitted") == 0)
6024 DefaultXactIsoLevel = XACT_READ_UNCOMMITTED;
6032 assign_log_min_messages(const char *newval,
6033 bool doit, GucSource source)
6035 return (assign_msglvl(&log_min_messages, newval, doit, source));
6039 assign_client_min_messages(const char *newval, bool doit, GucSource source)
6041 return (assign_msglvl(&client_min_messages, newval, doit, source));
6045 assign_min_error_statement(const char *newval, bool doit, GucSource source)
6047 return (assign_msglvl(&log_min_error_statement, newval, doit, source));
6051 assign_msglvl(int *var, const char *newval, bool doit, GucSource source)
6053 if (pg_strcasecmp(newval, "debug") == 0)
6058 else if (pg_strcasecmp(newval, "debug5") == 0)
6063 else if (pg_strcasecmp(newval, "debug4") == 0)
6068 else if (pg_strcasecmp(newval, "debug3") == 0)
6073 else if (pg_strcasecmp(newval, "debug2") == 0)
6078 else if (pg_strcasecmp(newval, "debug1") == 0)
6083 else if (pg_strcasecmp(newval, "log") == 0)
6090 * Client_min_messages always prints 'info', but we allow it as a value
6093 else if (pg_strcasecmp(newval, "info") == 0)
6098 else if (pg_strcasecmp(newval, "notice") == 0)
6103 else if (pg_strcasecmp(newval, "warning") == 0)
6108 else if (pg_strcasecmp(newval, "error") == 0)
6113 /* We allow FATAL/PANIC for client-side messages too. */
6114 else if (pg_strcasecmp(newval, "fatal") == 0)
6119 else if (pg_strcasecmp(newval, "panic") == 0)
6125 return NULL; /* fail */
6126 return newval; /* OK */
6130 assign_log_error_verbosity(const char *newval, bool doit, GucSource source)
6132 if (pg_strcasecmp(newval, "terse") == 0)
6135 Log_error_verbosity = PGERROR_TERSE;
6137 else if (pg_strcasecmp(newval, "default") == 0)
6140 Log_error_verbosity = PGERROR_DEFAULT;
6142 else if (pg_strcasecmp(newval, "verbose") == 0)
6145 Log_error_verbosity = PGERROR_VERBOSE;
6148 return NULL; /* fail */
6149 return newval; /* OK */
6153 assign_log_statement(const char *newval, bool doit, GucSource source)
6155 if (pg_strcasecmp(newval, "none") == 0)
6158 log_statement = LOGSTMT_NONE;
6160 else if (pg_strcasecmp(newval, "ddl") == 0)
6163 log_statement = LOGSTMT_DDL;
6165 else if (pg_strcasecmp(newval, "mod") == 0)
6168 log_statement = LOGSTMT_MOD;
6170 else if (pg_strcasecmp(newval, "all") == 0)
6173 log_statement = LOGSTMT_ALL;
6176 return NULL; /* fail */
6177 return newval; /* OK */
6181 show_num_temp_buffers(void)
6184 * We show the GUC var until local buffers have been initialized, and
6185 * NLocBuffer afterwards.
6187 static char nbuf[32];
6189 sprintf(nbuf, "%d", NLocBuffer ? NLocBuffer : num_temp_buffers);
6194 assign_phony_autocommit(bool newval, bool doit, GucSource source)
6198 if (doit && source >= PGC_S_INTERACTIVE)
6200 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6201 errmsg("SET AUTOCOMMIT TO OFF is no longer supported")));
6208 assign_custom_variable_classes(const char *newval, bool doit, GucSource source)
6211 * Check syntax. newval must be a comma separated list of identifiers.
6212 * Whitespace is allowed but skipped.
6214 bool hasSpaceAfterToken = false;
6215 const char *cp = newval;
6220 initStringInfo(&buf);
6221 while ((c = *cp++) != 0)
6223 if (isspace((unsigned char) c))
6226 hasSpaceAfterToken = true;
6232 hasSpaceAfterToken = false;
6236 appendStringInfoChar(&buf, ',');
6241 if (hasSpaceAfterToken || !isalnum((unsigned char) c))
6244 * Syntax error due to token following space after token or non
6245 * alpha numeric character
6248 (errcode(ERRCODE_SYNTAX_ERROR),
6249 errmsg("invalid syntax for \"custom_variable_classes\": \"%s\"", newval)));
6254 appendStringInfoChar(&buf, (char) c);
6257 /* Remove stray ',' at end */
6258 if (symLen == 0 && buf.len > 0)
6259 buf.data[--buf.len] = '\0';
6264 newval = strdup(buf.data);
6271 assign_debug_assertions(bool newval, bool doit, GucSource source)
6273 #ifndef USE_ASSERT_CHECKING
6276 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6277 errmsg("assertion checking is not supported by this build")));
6283 assign_ssl(bool newval, bool doit, GucSource source)
6288 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6289 errmsg("SSL is not supported by this build")));
6295 assign_stage_log_stats(bool newval, bool doit, GucSource source)
6297 if (newval && log_statement_stats)
6299 if (source >= PGC_S_INTERACTIVE)
6301 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6302 errmsg("cannot enable parameter when \"log_statement_stats\" is true")));
6303 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
6304 else if (source != PGC_S_OVERRIDE)
6311 assign_log_stats(bool newval, bool doit, GucSource source)
6314 (log_parser_stats || log_planner_stats || log_executor_stats))
6316 if (source >= PGC_S_INTERACTIVE)
6318 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6319 errmsg("cannot enable \"log_statement_stats\" when "
6320 "\"log_parser_stats\", \"log_planner_stats\", "
6321 "or \"log_executor_stats\" is true")));
6322 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
6323 else if (source != PGC_S_OVERRIDE)
6330 assign_transaction_read_only(bool newval, bool doit, GucSource source)
6332 /* Can't go to r/w mode inside a r/o transaction */
6333 if (newval == false && XactReadOnly && IsSubTransaction())
6335 if (source >= PGC_S_INTERACTIVE)
6337 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6338 errmsg("cannot set transaction read-write mode inside a read-only transaction")));
6339 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
6340 else if (source != PGC_S_OVERRIDE)
6347 assign_canonical_path(const char *newval, bool doit, GucSource source)
6351 char *canon_val = guc_strdup(ERROR, newval);
6353 canonicalize_path(canon_val);
6361 assign_backslash_quote(const char *newval, bool doit, GucSource source)
6363 BackslashQuoteType bq;
6367 * Although only "on", "off", and "safe_encoding" are documented, we use
6368 * parse_bool so we can accept all the likely variants of "on" and "off".
6370 if (pg_strcasecmp(newval, "safe_encoding") == 0)
6371 bq = BACKSLASH_QUOTE_SAFE_ENCODING;
6372 else if (parse_bool(newval, &bqbool))
6374 bq = bqbool ? BACKSLASH_QUOTE_ON : BACKSLASH_QUOTE_OFF;
6377 return NULL; /* reject */
6380 backslash_quote = bq;
6386 assign_timezone_abbreviations(const char *newval, bool doit, GucSource source)
6389 * The powerup value shown above for timezone_abbreviations is "UNKNOWN".
6390 * When we see this we just do nothing. If this value isn't overridden
6391 * from the config file then pg_timezone_abbrev_initialize() will
6392 * eventually replace it with "Default". This hack has two purposes: to
6393 * avoid wasting cycles loading values that might soon be overridden from
6394 * the config file, and to avoid trying to read the timezone abbrev files
6395 * during InitializeGUCOptions(). The latter doesn't work in an
6396 * EXEC_BACKEND subprocess because my_exec_path hasn't been set yet and so
6397 * we can't locate PGSHAREDIR. (Essentially the same hack is used to
6398 * delay initializing TimeZone ... if we have any more, we should try to
6399 * clean up and centralize this mechanism ...)
6401 if (strcmp(newval, "UNKNOWN") == 0)
6406 /* Loading abbrev file is expensive, so only do it when value changes */
6407 if (timezone_abbreviations_string == NULL ||
6408 strcmp(timezone_abbreviations_string, newval) != 0)
6413 * If reading config file, only the postmaster should bleat loudly
6414 * about problems. Otherwise, it's just this one process doing it,
6415 * and we use WARNING message level.
6417 if (source == PGC_S_FILE)
6418 elevel = IsUnderPostmaster ? DEBUG2 : LOG;
6421 if (!load_tzoffsets(newval, doit, elevel))
6428 * pg_timezone_abbrev_initialize --- set default value if not done already
6430 * This is called after initial loading of postgresql.conf. If no
6431 * timezone_abbreviations setting was found therein, select default.
6434 pg_timezone_abbrev_initialize(void)
6436 if (strcmp(timezone_abbreviations_string, "UNKNOWN") == 0)
6438 SetConfigOption("timezone_abbreviations", "Default",
6439 PGC_POSTMASTER, PGC_S_ARGV);
6444 assign_tcp_keepalives_idle(int newval, bool doit, GucSource source)
6447 return (pq_setkeepalivesidle(newval, MyProcPort) == STATUS_OK);
6453 show_tcp_keepalives_idle(void)
6455 static char nbuf[16];
6457 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesidle(MyProcPort));
6462 assign_tcp_keepalives_interval(int newval, bool doit, GucSource source)
6465 return (pq_setkeepalivesinterval(newval, MyProcPort) == STATUS_OK);
6471 show_tcp_keepalives_interval(void)
6473 static char nbuf[16];
6475 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesinterval(MyProcPort));
6480 assign_tcp_keepalives_count(int newval, bool doit, GucSource source)
6483 return (pq_setkeepalivescount(newval, MyProcPort) == STATUS_OK);
6489 show_tcp_keepalives_count(void)
6491 static char nbuf[16];
6493 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivescount(MyProcPort));
6498 #include "guc-file.c"