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.359 2006/11/21 01:23:37 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 = ERROR;
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 {"vacuum_freeze_min_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1335 gettext_noop("Minimum age at which VACUUM should freeze a table row."),
1338 &vacuum_freeze_min_age,
1339 100000000, 0, 1000000000, NULL, NULL
1343 {"max_fsm_relations", PGC_POSTMASTER, RESOURCES_FSM,
1344 gettext_noop("Sets the maximum number of tables and indexes for which free space is tracked."),
1348 1000, 100, INT_MAX, NULL, NULL
1351 {"max_fsm_pages", PGC_POSTMASTER, RESOURCES_FSM,
1352 gettext_noop("Sets the maximum number of disk pages for which free space is tracked."),
1356 20000, 1000, INT_MAX, NULL, NULL
1360 {"max_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
1361 gettext_noop("Sets the maximum number of locks per transaction."),
1362 gettext_noop("The shared lock table is sized on the assumption that "
1363 "at most max_locks_per_transaction * max_connections distinct "
1364 "objects will need to be locked at any one time.")
1366 &max_locks_per_xact,
1367 64, 10, INT_MAX, NULL, NULL
1371 {"authentication_timeout", PGC_SIGHUP, CONN_AUTH_SECURITY,
1372 gettext_noop("Sets the maximum time in seconds to complete client authentication."),
1376 &AuthenticationTimeout,
1377 60, 1, 600, NULL, NULL
1381 /* Not for general use */
1382 {"pre_auth_delay", PGC_SIGHUP, DEVELOPER_OPTIONS,
1383 gettext_noop("no description available"),
1385 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1388 0, 0, 60, NULL, NULL
1392 {"checkpoint_segments", PGC_SIGHUP, WAL_CHECKPOINTS,
1393 gettext_noop("Sets the maximum distance in log segments between automatic WAL checkpoints."),
1396 &CheckPointSegments,
1397 3, 1, INT_MAX, NULL, NULL
1401 {"checkpoint_timeout", PGC_SIGHUP, WAL_CHECKPOINTS,
1402 gettext_noop("Sets the maximum time in seconds between automatic WAL checkpoints."),
1407 300, 30, 3600, NULL, NULL
1411 {"checkpoint_warning", PGC_SIGHUP, WAL_CHECKPOINTS,
1412 gettext_noop("Logs if filling of checkpoint segments happens more "
1413 "frequently than this (in seconds)."),
1414 gettext_noop("Write a message to the server log if checkpoints "
1415 "caused by the filling of checkpoint segment files happens more "
1416 "frequently than this number of seconds. Zero turns off the warning."),
1420 30, 0, INT_MAX, NULL, NULL
1424 {"wal_buffers", PGC_POSTMASTER, WAL_SETTINGS,
1425 gettext_noop("Sets the number of disk-page buffers in shared memory for WAL."),
1430 8, 4, INT_MAX, NULL, NULL
1434 {"commit_delay", PGC_USERSET, WAL_CHECKPOINTS,
1435 gettext_noop("Sets the delay in microseconds between transaction commit and "
1436 "flushing WAL to disk."),
1440 0, 0, 100000, NULL, NULL
1444 {"commit_siblings", PGC_USERSET, WAL_CHECKPOINTS,
1445 gettext_noop("Sets the minimum concurrent open transactions before performing "
1450 5, 1, 1000, NULL, NULL
1454 {"extra_float_digits", PGC_USERSET, CLIENT_CONN_LOCALE,
1455 gettext_noop("Sets the number of digits displayed for floating-point values."),
1456 gettext_noop("This affects real, double precision, and geometric data types. "
1457 "The parameter value is added to the standard number of digits "
1458 "(FLT_DIG or DBL_DIG as appropriate).")
1460 &extra_float_digits,
1461 0, -15, 2, NULL, NULL
1465 {"log_min_duration_statement", PGC_SUSET, LOGGING_WHEN,
1466 gettext_noop("Sets the minimum execution time in milliseconds above which statements will "
1468 gettext_noop("Zero prints all queries. The default is -1 (turning this feature off)."),
1471 &log_min_duration_statement,
1472 -1, -1, INT_MAX / 1000, NULL, NULL
1476 {"bgwriter_delay", PGC_SIGHUP, RESOURCES,
1477 gettext_noop("Background writer sleep time between rounds in milliseconds"),
1482 200, 10, 10000, NULL, NULL
1486 {"bgwriter_lru_maxpages", PGC_SIGHUP, RESOURCES,
1487 gettext_noop("Background writer maximum number of LRU pages to flush per round"),
1490 &bgwriter_lru_maxpages,
1491 5, 0, 1000, NULL, NULL
1495 {"bgwriter_all_maxpages", PGC_SIGHUP, RESOURCES,
1496 gettext_noop("Background writer maximum number of all pages to flush per round"),
1499 &bgwriter_all_maxpages,
1500 5, 0, 1000, NULL, NULL
1504 {"log_rotation_age", PGC_SIGHUP, LOGGING_WHERE,
1505 gettext_noop("Automatic log file rotation will occur after N minutes"),
1510 HOURS_PER_DAY * MINS_PER_HOUR, 0, INT_MAX / MINS_PER_HOUR, NULL, NULL
1514 {"log_rotation_size", PGC_SIGHUP, LOGGING_WHERE,
1515 gettext_noop("Automatic log file rotation will occur after N kilobytes"),
1520 10 * 1024, 0, INT_MAX / 1024, NULL, NULL
1524 {"max_function_args", PGC_INTERNAL, PRESET_OPTIONS,
1525 gettext_noop("Shows the maximum number of function arguments."),
1527 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1530 FUNC_MAX_ARGS, FUNC_MAX_ARGS, FUNC_MAX_ARGS, NULL, NULL
1534 {"max_index_keys", PGC_INTERNAL, PRESET_OPTIONS,
1535 gettext_noop("Shows the maximum number of index keys."),
1537 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1540 INDEX_MAX_KEYS, INDEX_MAX_KEYS, INDEX_MAX_KEYS, NULL, NULL
1544 {"max_identifier_length", PGC_INTERNAL, PRESET_OPTIONS,
1545 gettext_noop("Shows the maximum identifier length"),
1547 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1549 &max_identifier_length,
1550 NAMEDATALEN - 1, NAMEDATALEN - 1, NAMEDATALEN - 1, NULL, NULL
1554 {"block_size", PGC_INTERNAL, PRESET_OPTIONS,
1555 gettext_noop("Shows size of a disk block"),
1557 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1560 BLCKSZ, BLCKSZ, BLCKSZ, NULL, NULL
1564 {"autovacuum_naptime", PGC_SIGHUP, AUTOVACUUM,
1565 gettext_noop("Time to sleep between autovacuum runs, in seconds."),
1569 &autovacuum_naptime,
1570 60, 1, INT_MAX, NULL, NULL
1573 {"autovacuum_vacuum_threshold", PGC_SIGHUP, AUTOVACUUM,
1574 gettext_noop("Minimum number of tuple updates or deletes prior to vacuum."),
1577 &autovacuum_vac_thresh,
1578 500, 0, INT_MAX, NULL, NULL
1581 {"autovacuum_analyze_threshold", PGC_SIGHUP, AUTOVACUUM,
1582 gettext_noop("Minimum number of tuple inserts, updates or deletes prior to analyze."),
1585 &autovacuum_anl_thresh,
1586 250, 0, INT_MAX, NULL, NULL
1589 /* see varsup.c for why this is PGC_POSTMASTER not PGC_SIGHUP */
1590 {"autovacuum_freeze_max_age", PGC_POSTMASTER, AUTOVACUUM,
1591 gettext_noop("Age at which to autovacuum a table to prevent transacion ID wraparound."),
1594 &autovacuum_freeze_max_age,
1595 200000000, 100000000, 2000000000, NULL, NULL
1599 {"tcp_keepalives_idle", PGC_USERSET, CLIENT_CONN_OTHER,
1600 gettext_noop("Seconds between issuing TCP keepalives."),
1601 gettext_noop("A value of 0 uses the system default."),
1604 &tcp_keepalives_idle,
1605 0, 0, INT_MAX, assign_tcp_keepalives_idle, show_tcp_keepalives_idle
1609 {"tcp_keepalives_interval", PGC_USERSET, CLIENT_CONN_OTHER,
1610 gettext_noop("Seconds between TCP keepalive retransmits."),
1611 gettext_noop("A value of 0 uses the system default."),
1614 &tcp_keepalives_interval,
1615 0, 0, INT_MAX, assign_tcp_keepalives_interval, show_tcp_keepalives_interval
1619 {"tcp_keepalives_count", PGC_USERSET, CLIENT_CONN_OTHER,
1620 gettext_noop("Maximum number of TCP keepalive retransmits."),
1621 gettext_noop("This controls the number of consecutive keepalive retransmits that can be "
1622 "lost before a connection is considered dead. A value of 0 uses the "
1625 &tcp_keepalives_count,
1626 0, 0, INT_MAX, assign_tcp_keepalives_count, show_tcp_keepalives_count
1630 {"gin_fuzzy_search_limit", PGC_USERSET, CLIENT_CONN_OTHER,
1631 gettext_noop("Sets the maximum allowed result for exact search by GIN."),
1635 &GinFuzzySearchLimit,
1636 0, 0, INT_MAX, NULL, NULL
1640 {"effective_cache_size", PGC_USERSET, QUERY_TUNING_COST,
1641 gettext_noop("Sets the planner's assumption about size of the disk cache."),
1642 gettext_noop("That is, the portion of the kernel's disk cache that "
1643 "will be used for PostgreSQL data files. This is measured in disk "
1644 "pages, which are normally 8 kB each."),
1647 &effective_cache_size,
1648 DEFAULT_EFFECTIVE_CACHE_SIZE, 1, INT_MAX, NULL, NULL
1652 /* Can't be set in postgresql.conf */
1653 {"server_version_num", PGC_INTERNAL, PRESET_OPTIONS,
1654 gettext_noop("Shows the server version as an integer."),
1656 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1658 &server_version_num,
1659 PG_VERSION_NUM, PG_VERSION_NUM, PG_VERSION_NUM, NULL, NULL
1662 /* End-of-list marker */
1664 {NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL
1669 static struct config_real ConfigureNamesReal[] =
1672 {"seq_page_cost", PGC_USERSET, QUERY_TUNING_COST,
1673 gettext_noop("Sets the planner's estimate of the cost of a "
1674 "sequentially fetched disk page."),
1678 DEFAULT_SEQ_PAGE_COST, 0, DBL_MAX, NULL, NULL
1681 {"random_page_cost", PGC_USERSET, QUERY_TUNING_COST,
1682 gettext_noop("Sets the planner's estimate of the cost of a "
1683 "nonsequentially fetched disk page."),
1687 DEFAULT_RANDOM_PAGE_COST, 0, DBL_MAX, NULL, NULL
1690 {"cpu_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
1691 gettext_noop("Sets the planner's estimate of the cost of "
1692 "processing each tuple (row)."),
1696 DEFAULT_CPU_TUPLE_COST, 0, DBL_MAX, NULL, NULL
1699 {"cpu_index_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
1700 gettext_noop("Sets the planner's estimate of the cost of "
1701 "processing each index entry during an index scan."),
1704 &cpu_index_tuple_cost,
1705 DEFAULT_CPU_INDEX_TUPLE_COST, 0, DBL_MAX, NULL, NULL
1708 {"cpu_operator_cost", PGC_USERSET, QUERY_TUNING_COST,
1709 gettext_noop("Sets the planner's estimate of the cost of "
1710 "processing each operator or function call."),
1714 DEFAULT_CPU_OPERATOR_COST, 0, DBL_MAX, NULL, NULL
1718 {"geqo_selection_bias", PGC_USERSET, QUERY_TUNING_GEQO,
1719 gettext_noop("GEQO: selective pressure within the population."),
1722 &Geqo_selection_bias,
1723 DEFAULT_GEQO_SELECTION_BIAS, MIN_GEQO_SELECTION_BIAS,
1724 MAX_GEQO_SELECTION_BIAS, NULL, NULL
1728 {"bgwriter_lru_percent", PGC_SIGHUP, RESOURCES,
1729 gettext_noop("Background writer percentage of LRU buffers to flush per round"),
1732 &bgwriter_lru_percent,
1733 1.0, 0.0, 100.0, NULL, NULL
1737 {"bgwriter_all_percent", PGC_SIGHUP, RESOURCES,
1738 gettext_noop("Background writer percentage of all buffers to flush per round"),
1741 &bgwriter_all_percent,
1742 0.333, 0.0, 100.0, NULL, NULL
1746 {"seed", PGC_USERSET, UNGROUPED,
1747 gettext_noop("Sets the seed for random-number generation."),
1749 GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1752 0.5, 0.0, 1.0, assign_random_seed, show_random_seed
1756 {"autovacuum_vacuum_scale_factor", PGC_SIGHUP, AUTOVACUUM,
1757 gettext_noop("Number of tuple updates or deletes prior to vacuum as a fraction of reltuples."),
1760 &autovacuum_vac_scale,
1761 0.2, 0.0, 100.0, NULL, NULL
1764 {"autovacuum_analyze_scale_factor", PGC_SIGHUP, AUTOVACUUM,
1765 gettext_noop("Number of tuple inserts, updates or deletes prior to analyze as a fraction of reltuples."),
1768 &autovacuum_anl_scale,
1769 0.1, 0.0, 100.0, NULL, NULL
1772 /* End-of-list marker */
1774 {NULL, 0, 0, NULL, NULL}, NULL, 0.0, 0.0, 0.0, NULL, NULL
1779 static struct config_string ConfigureNamesString[] =
1782 {"archive_command", PGC_SIGHUP, WAL_SETTINGS,
1783 gettext_noop("WAL archiving command."),
1784 gettext_noop("The shell command that will be called to archive a WAL file.")
1786 &XLogArchiveCommand,
1791 {"backslash_quote", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1792 gettext_noop("Sets whether \"\\'\" is allowed in string literals."),
1793 gettext_noop("Valid values are ON, OFF, and SAFE_ENCODING.")
1795 &backslash_quote_string,
1796 "safe_encoding", assign_backslash_quote, NULL
1800 {"client_encoding", PGC_USERSET, CLIENT_CONN_LOCALE,
1801 gettext_noop("Sets the client's character set encoding."),
1803 GUC_IS_NAME | GUC_REPORT
1805 &client_encoding_string,
1806 "SQL_ASCII", assign_client_encoding, NULL
1810 {"client_min_messages", PGC_USERSET, LOGGING_WHEN,
1811 gettext_noop("Sets the message levels that are sent to the client."),
1812 gettext_noop("Valid values are DEBUG5, DEBUG4, DEBUG3, DEBUG2, "
1813 "DEBUG1, LOG, NOTICE, WARNING, and ERROR. Each level includes all the "
1814 "levels that follow it. The later the level, the fewer messages are "
1817 &client_min_messages_str,
1818 "notice", assign_client_min_messages, NULL
1822 {"log_min_messages", PGC_SUSET, LOGGING_WHEN,
1823 gettext_noop("Sets the message levels that are logged."),
1824 gettext_noop("Valid values are DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1, "
1825 "INFO, NOTICE, WARNING, ERROR, LOG, FATAL, and PANIC. Each level "
1826 "includes all the levels that follow it.")
1828 &log_min_messages_str,
1829 "notice", assign_log_min_messages, NULL
1833 {"log_error_verbosity", PGC_SUSET, LOGGING_WHEN,
1834 gettext_noop("Sets the verbosity of logged messages."),
1835 gettext_noop("Valid values are \"terse\", \"default\", and \"verbose\".")
1837 &log_error_verbosity_str,
1838 "default", assign_log_error_verbosity, NULL
1841 {"log_statement", PGC_SUSET, LOGGING_WHAT,
1842 gettext_noop("Sets the type of statements logged."),
1843 gettext_noop("Valid values are \"none\", \"ddl\", \"mod\", and \"all\".")
1846 "none", assign_log_statement, NULL
1850 {"log_min_error_statement", PGC_SUSET, LOGGING_WHEN,
1851 gettext_noop("Causes all statements generating error at or above this level to be logged."),
1852 gettext_noop("All SQL statements that cause an error of the "
1853 "specified level or a higher level are logged.")
1855 &log_min_error_statement_str,
1856 "error", assign_min_error_statement, NULL
1860 {"log_line_prefix", PGC_SIGHUP, LOGGING_WHAT,
1861 gettext_noop("Controls information prefixed to each log line"),
1862 gettext_noop("if blank no prefix is used")
1870 {"DateStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
1871 gettext_noop("Sets the display format for date and time values."),
1872 gettext_noop("Also controls interpretation of ambiguous "
1874 GUC_LIST_INPUT | GUC_REPORT
1877 "ISO, MDY", assign_datestyle, NULL
1881 {"default_tablespace", PGC_USERSET, CLIENT_CONN_STATEMENT,
1882 gettext_noop("Sets the default tablespace to create tables and indexes in."),
1883 gettext_noop("An empty string selects the database's default tablespace."),
1886 &default_tablespace,
1887 "", assign_default_tablespace, NULL
1891 {"default_transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
1892 gettext_noop("Sets the transaction isolation level of each new transaction."),
1893 gettext_noop("Each SQL transaction has an isolation level, which "
1894 "can be either \"read uncommitted\", \"read committed\", \"repeatable read\", or \"serializable\".")
1896 &default_iso_level_string,
1897 "read committed", assign_defaultxactisolevel, NULL
1901 {"dynamic_library_path", PGC_SUSET, CLIENT_CONN_OTHER,
1902 gettext_noop("Sets the path for dynamically loadable modules."),
1903 gettext_noop("If a dynamically loadable module needs to be opened and "
1904 "the specified name does not have a directory component (i.e., the "
1905 "name does not contain a slash), the system will search this path for "
1906 "the specified file."),
1909 &Dynamic_library_path,
1910 "$libdir", NULL, NULL
1914 {"krb_server_keyfile", PGC_POSTMASTER, CONN_AUTH_SECURITY,
1915 gettext_noop("Sets the location of the Kerberos server key file."),
1919 &pg_krb_server_keyfile,
1920 PG_KRB_SRVTAB, NULL, NULL
1924 {"krb_srvname", PGC_POSTMASTER, CONN_AUTH_SECURITY,
1925 gettext_noop("Sets the name of the Kerberos service."),
1929 PG_KRB_SRVNAM, NULL, NULL
1933 {"krb_server_hostname", PGC_POSTMASTER, CONN_AUTH_SECURITY,
1934 gettext_noop("Sets the hostname of the Kerberos server."),
1937 &pg_krb_server_hostname,
1942 {"bonjour_name", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1943 gettext_noop("Sets the Bonjour broadcast service name."),
1950 /* See main.c about why defaults for LC_foo are not all alike */
1953 {"lc_collate", PGC_INTERNAL, CLIENT_CONN_LOCALE,
1954 gettext_noop("Shows the collation order locale."),
1956 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1963 {"lc_ctype", PGC_INTERNAL, CLIENT_CONN_LOCALE,
1964 gettext_noop("Shows the character classification and case conversion locale."),
1966 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1973 {"lc_messages", PGC_SUSET, CLIENT_CONN_LOCALE,
1974 gettext_noop("Sets the language in which messages are displayed."),
1978 "", locale_messages_assign, NULL
1982 {"lc_monetary", PGC_USERSET, CLIENT_CONN_LOCALE,
1983 gettext_noop("Sets the locale for formatting monetary amounts."),
1987 "C", locale_monetary_assign, NULL
1991 {"lc_numeric", PGC_USERSET, CLIENT_CONN_LOCALE,
1992 gettext_noop("Sets the locale for formatting numbers."),
1996 "C", locale_numeric_assign, NULL
2000 {"lc_time", PGC_USERSET, CLIENT_CONN_LOCALE,
2001 gettext_noop("Sets the locale for formatting date and time values."),
2005 "C", locale_time_assign, NULL
2009 {"shared_preload_libraries", PGC_POSTMASTER, RESOURCES_KERNEL,
2010 gettext_noop("Lists shared libraries to preload into server."),
2012 GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
2014 &shared_preload_libraries_string,
2019 {"local_preload_libraries", PGC_BACKEND, CLIENT_CONN_OTHER,
2020 gettext_noop("Lists shared libraries to preload into each backend."),
2022 GUC_LIST_INPUT | GUC_LIST_QUOTE
2024 &local_preload_libraries_string,
2029 {"regex_flavor", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
2030 gettext_noop("Sets the regular expression \"flavor\"."),
2031 gettext_noop("This can be set to advanced, extended, or basic.")
2033 ®ex_flavor_string,
2034 "advanced", assign_regex_flavor, NULL
2038 {"search_path", PGC_USERSET, CLIENT_CONN_STATEMENT,
2039 gettext_noop("Sets the schema search order for names that are not schema-qualified."),
2041 GUC_LIST_INPUT | GUC_LIST_QUOTE
2043 &namespace_search_path,
2044 "\"$user\",public", assign_search_path, NULL
2048 /* Can't be set in postgresql.conf */
2049 {"server_encoding", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2050 gettext_noop("Sets the server (database) character set encoding."),
2052 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2054 &server_encoding_string,
2055 "SQL_ASCII", NULL, NULL
2059 /* Can't be set in postgresql.conf */
2060 {"server_version", PGC_INTERNAL, PRESET_OPTIONS,
2061 gettext_noop("Shows the server version."),
2063 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2065 &server_version_string,
2066 PG_VERSION, NULL, NULL
2070 /* Not for general use --- used by SET ROLE */
2071 {"role", PGC_USERSET, UNGROUPED,
2072 gettext_noop("Sets the current role."),
2074 GUC_IS_NAME | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2077 "none", assign_role, show_role
2081 /* Not for general use --- used by SET SESSION AUTHORIZATION */
2082 {"session_authorization", PGC_USERSET, UNGROUPED,
2083 gettext_noop("Sets the session user name."),
2085 GUC_IS_NAME | GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2087 &session_authorization_string,
2088 NULL, assign_session_authorization, show_session_authorization
2092 {"log_destination", PGC_SIGHUP, LOGGING_WHERE,
2093 gettext_noop("Sets the destination for server log output."),
2094 gettext_noop("Valid values are combinations of \"stderr\", \"syslog\", "
2095 "and \"eventlog\", depending on the platform."),
2098 &log_destination_string,
2099 "stderr", assign_log_destination, NULL
2102 {"log_directory", PGC_SIGHUP, LOGGING_WHERE,
2103 gettext_noop("Sets the destination directory for log files."),
2104 gettext_noop("May be specified as relative to the data directory "
2105 "or as absolute path."),
2109 "pg_log", assign_canonical_path, NULL
2112 {"log_filename", PGC_SIGHUP, LOGGING_WHERE,
2113 gettext_noop("Sets the file name pattern for log files."),
2118 "postgresql-%Y-%m-%d_%H%M%S.log", NULL, NULL
2123 {"syslog_facility", PGC_SIGHUP, LOGGING_WHERE,
2124 gettext_noop("Sets the syslog \"facility\" to be used when syslog enabled."),
2125 gettext_noop("Valid values are LOCAL0, LOCAL1, LOCAL2, LOCAL3, "
2126 "LOCAL4, LOCAL5, LOCAL6, LOCAL7.")
2128 &syslog_facility_str,
2129 "LOCAL0", assign_syslog_facility, NULL
2132 {"syslog_ident", PGC_SIGHUP, LOGGING_WHERE,
2133 gettext_noop("Sets the program name used to identify PostgreSQL "
2134 "messages in syslog."),
2138 "postgres", assign_syslog_ident, NULL
2143 {"TimeZone", PGC_USERSET, CLIENT_CONN_LOCALE,
2144 gettext_noop("Sets the time zone for displaying and interpreting time stamps."),
2149 "UNKNOWN", assign_timezone, show_timezone
2152 {"timezone_abbreviations", PGC_USERSET, CLIENT_CONN_LOCALE,
2153 gettext_noop("Selects a file of time zone abbreviations"),
2156 &timezone_abbreviations_string,
2157 "UNKNOWN", assign_timezone_abbreviations, NULL
2161 {"transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
2162 gettext_noop("Sets the current transaction's isolation level."),
2164 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2166 &XactIsoLevel_string,
2167 NULL, assign_XactIsoLevel, show_XactIsoLevel
2171 {"unix_socket_group", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2172 gettext_noop("Sets the owning group of the Unix-domain socket."),
2173 gettext_noop("(The owning user of the socket is always the user "
2174 "that starts the server.)")
2181 {"unix_socket_directory", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2182 gettext_noop("Sets the directory where the Unix-domain socket will be created."),
2187 "", assign_canonical_path, NULL
2191 {"listen_addresses", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2192 gettext_noop("Sets the host name or IP address(es) to listen to."),
2197 "localhost", NULL, NULL
2201 {"wal_sync_method", PGC_SIGHUP, WAL_SETTINGS,
2202 gettext_noop("Selects the method used for forcing WAL updates out to disk."),
2206 XLOG_sync_method_default, assign_xlog_sync_method, NULL
2210 {"custom_variable_classes", PGC_SIGHUP, CUSTOM_OPTIONS,
2211 gettext_noop("Sets the list of known custom variable classes."),
2213 GUC_LIST_INPUT | GUC_LIST_QUOTE
2215 &custom_variable_classes,
2216 NULL, assign_custom_variable_classes, NULL
2220 {"data_directory", PGC_POSTMASTER, FILE_LOCATIONS,
2221 gettext_noop("Sets the server's data directory."),
2230 {"config_file", PGC_POSTMASTER, FILE_LOCATIONS,
2231 gettext_noop("Sets the server's main configuration file."),
2233 GUC_DISALLOW_IN_FILE | GUC_SUPERUSER_ONLY
2240 {"hba_file", PGC_POSTMASTER, FILE_LOCATIONS,
2241 gettext_noop("Sets the server's \"hba\" configuration file"),
2250 {"ident_file", PGC_POSTMASTER, FILE_LOCATIONS,
2251 gettext_noop("Sets the server's \"ident\" configuration file"),
2260 {"external_pid_file", PGC_POSTMASTER, FILE_LOCATIONS,
2261 gettext_noop("Writes the postmaster PID to the specified file."),
2266 NULL, assign_canonical_path, NULL
2269 /* End-of-list marker */
2271 {NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL
2276 /******** end of options list ********/
2280 * To allow continued support of obsolete names for GUC variables, we apply
2281 * the following mappings to any unrecognized name. Note that an old name
2282 * should be mapped to a new one only if the new variable has very similar
2283 * semantics to the old.
2285 static const char *const map_old_guc_names[] = {
2286 "sort_mem", "work_mem",
2287 "vacuum_mem", "maintenance_work_mem",
2293 * Actual lookup of variables is done through this single, sorted array.
2295 static struct config_generic **guc_variables;
2297 /* Current number of variables contained in the vector */
2298 static int num_guc_variables;
2300 /* Vector capacity */
2301 static int size_guc_variables;
2304 static bool guc_dirty; /* TRUE if need to do commit/abort work */
2306 static bool reporting_enabled; /* TRUE to enable GUC_REPORT */
2309 static int guc_var_compare(const void *a, const void *b);
2310 static int guc_name_compare(const char *namea, const char *nameb);
2311 static void push_old_value(struct config_generic * gconf);
2312 static void ReportGUCOption(struct config_generic * record);
2313 static void ShowGUCConfigOption(const char *name, DestReceiver *dest);
2314 static void ShowAllGUCConfig(DestReceiver *dest);
2315 static char *_ShowOption(struct config_generic * record, bool use_units);
2316 static bool is_newvalue_equal(struct config_generic * record, const char *newvalue);
2320 * Some infrastructure for checking malloc/strdup/realloc calls
2323 guc_malloc(int elevel, size_t size)
2327 data = malloc(size);
2330 (errcode(ERRCODE_OUT_OF_MEMORY),
2331 errmsg("out of memory")));
2336 guc_realloc(int elevel, void *old, size_t size)
2340 data = realloc(old, size);
2343 (errcode(ERRCODE_OUT_OF_MEMORY),
2344 errmsg("out of memory")));
2349 guc_strdup(int elevel, const char *src)
2356 (errcode(ERRCODE_OUT_OF_MEMORY),
2357 errmsg("out of memory")));
2363 * Support for assigning to a field of a string GUC item. Free the prior
2364 * value if it's not referenced anywhere else in the item (including stacked
2368 set_string_field(struct config_string * conf, char **field, char *newval)
2370 char *oldval = *field;
2373 /* Do the assignment */
2376 /* Exit if any duplicate references, or if old value was NULL anyway */
2377 if (oldval == NULL ||
2378 oldval == *(conf->variable) ||
2379 oldval == conf->reset_val ||
2380 oldval == conf->tentative_val)
2382 for (stack = conf->gen.stack; stack; stack = stack->prev)
2384 if (oldval == stack->tentative_val.stringval ||
2385 oldval == stack->value.stringval)
2389 /* Not used anymore, so free it */
2394 * Detect whether strval is referenced anywhere in a GUC string item
2397 string_field_used(struct config_string * conf, char *strval)
2401 if (strval == *(conf->variable) ||
2402 strval == conf->reset_val ||
2403 strval == conf->tentative_val)
2405 for (stack = conf->gen.stack; stack; stack = stack->prev)
2407 if (strval == stack->tentative_val.stringval ||
2408 strval == stack->value.stringval)
2415 struct config_generic **
2416 get_guc_variables(void)
2418 return guc_variables;
2423 * Build the sorted array. This is split out so that it could be
2424 * re-executed after startup (eg, we could allow loadable modules to
2425 * add vars, and then we'd need to re-sort).
2428 build_guc_variables(void)
2432 struct config_generic **guc_vars;
2435 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
2437 struct config_bool *conf = &ConfigureNamesBool[i];
2439 /* Rather than requiring vartype to be filled in by hand, do this: */
2440 conf->gen.vartype = PGC_BOOL;
2444 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
2446 struct config_int *conf = &ConfigureNamesInt[i];
2448 conf->gen.vartype = PGC_INT;
2452 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
2454 struct config_real *conf = &ConfigureNamesReal[i];
2456 conf->gen.vartype = PGC_REAL;
2460 for (i = 0; ConfigureNamesString[i].gen.name; i++)
2462 struct config_string *conf = &ConfigureNamesString[i];
2464 conf->gen.vartype = PGC_STRING;
2469 * Create table with 20% slack
2471 size_vars = num_vars + num_vars / 4;
2473 guc_vars = (struct config_generic **)
2474 guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
2478 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
2479 guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
2481 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
2482 guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
2484 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
2485 guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
2487 for (i = 0; ConfigureNamesString[i].gen.name; i++)
2488 guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
2491 free(guc_variables);
2492 guc_variables = guc_vars;
2493 num_guc_variables = num_vars;
2494 size_guc_variables = size_vars;
2495 qsort((void *) guc_variables, num_guc_variables,
2496 sizeof(struct config_generic *), guc_var_compare);
2500 is_custom_class(const char *name, int dotPos)
2503 * assign_custom_variable_classes() has made sure no empty identifiers or
2504 * whitespace exists in the variable
2506 bool result = false;
2507 const char *ccs = GetConfigOption("custom_variable_classes");
2511 const char *start = ccs;
2517 if (c == 0 || c == ',')
2519 if (dotPos == ccs - start && strncmp(start, name, dotPos) == 0)
2534 * Add a new GUC variable to the list of known variables. The
2535 * list is expanded if needed.
2538 add_guc_variable(struct config_generic * var, int elevel)
2540 if (num_guc_variables + 1 >= size_guc_variables)
2543 * Increase the vector by 25%
2545 int size_vars = size_guc_variables + size_guc_variables / 4;
2546 struct config_generic **guc_vars;
2551 guc_vars = (struct config_generic **)
2552 guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
2556 guc_vars = (struct config_generic **)
2557 guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
2560 if (guc_vars == NULL)
2561 return false; /* out of memory */
2563 guc_variables = guc_vars;
2564 size_guc_variables = size_vars;
2566 guc_variables[num_guc_variables++] = var;
2567 qsort((void *) guc_variables, num_guc_variables,
2568 sizeof(struct config_generic *), guc_var_compare);
2573 * Create and add a placeholder variable. It's presumed to belong
2574 * to a valid custom variable class at this point.
2576 static struct config_string *
2577 add_placeholder_variable(const char *name, int elevel)
2579 size_t sz = sizeof(struct config_string) + sizeof(char *);
2580 struct config_string *var;
2581 struct config_generic *gen;
2583 var = (struct config_string *) guc_malloc(elevel, sz);
2590 gen->name = guc_strdup(elevel, name);
2591 if (gen->name == NULL)
2597 gen->context = PGC_USERSET;
2598 gen->group = CUSTOM_OPTIONS;
2599 gen->short_desc = "GUC placeholder variable";
2600 gen->flags = GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_CUSTOM_PLACEHOLDER;
2601 gen->vartype = PGC_STRING;
2604 * The char* is allocated at the end of the struct since we have no
2605 * 'static' place to point to.
2607 var->variable = (char **) (var + 1);
2609 if (!add_guc_variable((struct config_generic *) var, elevel))
2611 free((void *) gen->name);
2620 * Look up option NAME. If it exists, return a pointer to its record,
2623 static struct config_generic *
2624 find_option(const char *name, int elevel)
2627 const char **key = &name;
2628 struct config_generic **res;
2634 * By equating const char ** with struct config_generic *, we are assuming
2635 * the name field is first in config_generic.
2637 res = (struct config_generic **) bsearch((void *) &key,
2638 (void *) guc_variables,
2640 sizeof(struct config_generic *),
2646 * See if the name is an obsolete name for a variable. We assume that the
2647 * set of supported old names is short enough that a brute-force search is
2650 for (i = 0; map_old_guc_names[i] != NULL; i += 2)
2652 if (guc_name_compare(name, map_old_guc_names[i]) == 0)
2653 return find_option(map_old_guc_names[i + 1], elevel);
2657 * Check if the name is qualified, and if so, check if the qualifier maps
2658 * to a custom variable class.
2660 dot = strchr(name, GUC_QUALIFIER_SEPARATOR);
2661 if (dot != NULL && is_custom_class(name, dot - name))
2662 /* Add a placeholder variable for this name */
2663 return (struct config_generic *) add_placeholder_variable(name, elevel);
2671 * comparator for qsorting and bsearching guc_variables array
2674 guc_var_compare(const void *a, const void *b)
2676 struct config_generic *confa = *(struct config_generic **) a;
2677 struct config_generic *confb = *(struct config_generic **) b;
2679 return guc_name_compare(confa->name, confb->name);
2684 guc_name_compare(const char *namea, const char *nameb)
2687 * The temptation to use strcasecmp() here must be resisted, because the
2688 * array ordering has to remain stable across setlocale() calls. So, build
2689 * our own with a simple ASCII-only downcasing.
2691 while (*namea && *nameb)
2693 char cha = *namea++;
2694 char chb = *nameb++;
2696 if (cha >= 'A' && cha <= 'Z')
2698 if (chb >= 'A' && chb <= 'Z')
2704 return 1; /* a is longer */
2706 return -1; /* b is longer */
2712 * Initialize GUC options during program startup.
2714 * Note that we cannot read the config file yet, since we have not yet
2715 * processed command-line switches.
2718 InitializeGUCOptions(void)
2725 * Build sorted array of all GUC variables.
2727 build_guc_variables();
2730 * Load all variables with their compiled-in defaults, and initialize
2731 * status fields as needed.
2733 for (i = 0; i < num_guc_variables; i++)
2735 struct config_generic *gconf = guc_variables[i];
2738 gconf->reset_source = PGC_S_DEFAULT;
2739 gconf->tentative_source = PGC_S_DEFAULT;
2740 gconf->source = PGC_S_DEFAULT;
2741 gconf->stack = NULL;
2743 switch (gconf->vartype)
2747 struct config_bool *conf = (struct config_bool *) gconf;
2749 if (conf->assign_hook)
2750 if (!(*conf->assign_hook) (conf->reset_val, true,
2752 elog(FATAL, "failed to initialize %s to %d",
2753 conf->gen.name, (int) conf->reset_val);
2754 *conf->variable = conf->reset_val;
2759 struct config_int *conf = (struct config_int *) gconf;
2761 Assert(conf->reset_val >= conf->min);
2762 Assert(conf->reset_val <= conf->max);
2763 if (conf->assign_hook)
2764 if (!(*conf->assign_hook) (conf->reset_val, true,
2766 elog(FATAL, "failed to initialize %s to %d",
2767 conf->gen.name, conf->reset_val);
2768 *conf->variable = conf->reset_val;
2773 struct config_real *conf = (struct config_real *) gconf;
2775 Assert(conf->reset_val >= conf->min);
2776 Assert(conf->reset_val <= conf->max);
2777 if (conf->assign_hook)
2778 if (!(*conf->assign_hook) (conf->reset_val, true,
2780 elog(FATAL, "failed to initialize %s to %g",
2781 conf->gen.name, conf->reset_val);
2782 *conf->variable = conf->reset_val;
2787 struct config_string *conf = (struct config_string *) gconf;
2790 *conf->variable = NULL;
2791 conf->reset_val = NULL;
2792 conf->tentative_val = NULL;
2794 if (conf->boot_val == NULL)
2796 /* Cannot set value yet */
2800 str = guc_strdup(FATAL, conf->boot_val);
2801 conf->reset_val = str;
2803 if (conf->assign_hook)
2807 newstr = (*conf->assign_hook) (str, true,
2811 elog(FATAL, "failed to initialize %s to \"%s\"",
2812 conf->gen.name, str);
2814 else if (newstr != str)
2819 * See notes in set_config_option about casting
2821 str = (char *) newstr;
2822 conf->reset_val = str;
2825 *conf->variable = str;
2833 reporting_enabled = false;
2836 * Prevent any attempt to override the transaction modes from
2837 * non-interactive sources.
2839 SetConfigOption("transaction_isolation", "default",
2840 PGC_POSTMASTER, PGC_S_OVERRIDE);
2841 SetConfigOption("transaction_read_only", "no",
2842 PGC_POSTMASTER, PGC_S_OVERRIDE);
2845 * For historical reasons, some GUC parameters can receive defaults from
2846 * environment variables. Process those settings.
2849 env = getenv("PGPORT");
2851 SetConfigOption("port", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
2853 env = getenv("PGDATESTYLE");
2855 SetConfigOption("datestyle", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
2857 env = getenv("PGCLIENTENCODING");
2859 SetConfigOption("client_encoding", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
2862 * rlimit isn't exactly an "environment variable", but it behaves about
2863 * the same. If we can identify the platform stack depth rlimit, increase
2864 * default stack depth setting up to whatever is safe (but at most 2MB).
2866 stack_rlimit = get_stack_depth_rlimit();
2867 if (stack_rlimit > 0)
2869 int new_limit = (stack_rlimit - STACK_DEPTH_SLOP) / 1024L;
2871 if (new_limit > 100)
2875 new_limit = Min(new_limit, 2048);
2876 sprintf(limbuf, "%d", new_limit);
2877 SetConfigOption("max_stack_depth", limbuf,
2878 PGC_POSTMASTER, PGC_S_ENV_VAR);
2885 * Select the configuration files and data directory to be used, and
2886 * do the initial read of postgresql.conf.
2888 * This is called after processing command-line switches.
2889 * userDoption is the -D switch value if any (NULL if unspecified).
2890 * progname is just for use in error messages.
2892 * Returns true on success; on failure, prints a suitable error message
2893 * to stderr and returns false.
2896 SelectConfigFiles(const char *userDoption, const char *progname)
2900 struct stat stat_buf;
2902 /* configdir is -D option, or $PGDATA if no -D */
2904 configdir = make_absolute_path(userDoption);
2906 configdir = make_absolute_path(getenv("PGDATA"));
2909 * Find the configuration file: if config_file was specified on the
2910 * command line, use it, else use configdir/postgresql.conf. In any case
2911 * ensure the result is an absolute path, so that it will be interpreted
2912 * the same way by future backends.
2915 fname = make_absolute_path(ConfigFileName);
2918 fname = guc_malloc(FATAL,
2919 strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
2920 sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
2924 write_stderr("%s does not know where to find the server configuration file.\n"
2925 "You must specify the --config-file or -D invocation "
2926 "option or set the PGDATA environment variable.\n",
2932 * Set the ConfigFileName GUC variable to its final value, ensuring that
2933 * it can't be overridden later.
2935 SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
2939 * Now read the config file for the first time.
2941 if (stat(ConfigFileName, &stat_buf) != 0)
2943 write_stderr("%s cannot access the server configuration file \"%s\": %s\n",
2944 progname, ConfigFileName, strerror(errno));
2948 ProcessConfigFile(PGC_POSTMASTER);
2951 * If the data_directory GUC variable has been set, use that as DataDir;
2952 * otherwise use configdir if set; else punt.
2954 * Note: SetDataDir will copy and absolute-ize its argument, so we don't
2958 SetDataDir(data_directory);
2960 SetDataDir(configdir);
2963 write_stderr("%s does not know where to find the database system data.\n"
2964 "This can be specified as \"data_directory\" in \"%s\", "
2965 "or by the -D invocation option, or by the "
2966 "PGDATA environment variable.\n",
2967 progname, ConfigFileName);
2972 * Reflect the final DataDir value back into the data_directory GUC var.
2973 * (If you are wondering why we don't just make them a single variable,
2974 * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
2975 * child backends specially. XXX is that still true? Given that we now
2976 * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
2977 * DataDir in advance.)
2979 SetConfigOption("data_directory", DataDir, PGC_POSTMASTER, PGC_S_OVERRIDE);
2982 * Figure out where pg_hba.conf is, and make sure the path is absolute.
2985 fname = make_absolute_path(HbaFileName);
2988 fname = guc_malloc(FATAL,
2989 strlen(configdir) + strlen(HBA_FILENAME) + 2);
2990 sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
2994 write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
2995 "This can be specified as \"hba_file\" in \"%s\", "
2996 "or by the -D invocation option, or by the "
2997 "PGDATA environment variable.\n",
2998 progname, ConfigFileName);
3001 SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
3005 * Likewise for pg_ident.conf.
3008 fname = make_absolute_path(IdentFileName);
3011 fname = guc_malloc(FATAL,
3012 strlen(configdir) + strlen(IDENT_FILENAME) + 2);
3013 sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
3017 write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
3018 "This can be specified as \"ident_file\" in \"%s\", "
3019 "or by the -D invocation option, or by the "
3020 "PGDATA environment variable.\n",
3021 progname, ConfigFileName);
3024 SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
3034 * Reset all options to their saved default values (implements RESET ALL)
3037 ResetAllOptions(void)
3041 for (i = 0; i < num_guc_variables; i++)
3043 struct config_generic *gconf = guc_variables[i];
3045 /* Don't reset non-SET-able values */
3046 if (gconf->context != PGC_SUSET &&
3047 gconf->context != PGC_USERSET)
3049 /* Don't reset if special exclusion from RESET ALL */
3050 if (gconf->flags & GUC_NO_RESET_ALL)
3052 /* No need to reset if wasn't SET */
3053 if (gconf->source <= PGC_S_OVERRIDE)
3056 /* Save old value to support transaction abort */
3057 push_old_value(gconf);
3059 switch (gconf->vartype)
3063 struct config_bool *conf = (struct config_bool *) gconf;
3065 if (conf->assign_hook)
3066 if (!(*conf->assign_hook) (conf->reset_val, true,
3068 elog(ERROR, "failed to reset %s", conf->gen.name);
3069 *conf->variable = conf->reset_val;
3070 conf->tentative_val = conf->reset_val;
3071 conf->gen.source = conf->gen.reset_source;
3072 conf->gen.tentative_source = conf->gen.reset_source;
3073 conf->gen.status |= GUC_HAVE_TENTATIVE;
3079 struct config_int *conf = (struct config_int *) gconf;
3081 if (conf->assign_hook)
3082 if (!(*conf->assign_hook) (conf->reset_val, true,
3084 elog(ERROR, "failed to reset %s", conf->gen.name);
3085 *conf->variable = conf->reset_val;
3086 conf->tentative_val = conf->reset_val;
3087 conf->gen.source = conf->gen.reset_source;
3088 conf->gen.tentative_source = conf->gen.reset_source;
3089 conf->gen.status |= GUC_HAVE_TENTATIVE;
3095 struct config_real *conf = (struct config_real *) gconf;
3097 if (conf->assign_hook)
3098 if (!(*conf->assign_hook) (conf->reset_val, true,
3100 elog(ERROR, "failed to reset %s", conf->gen.name);
3101 *conf->variable = conf->reset_val;
3102 conf->tentative_val = conf->reset_val;
3103 conf->gen.source = conf->gen.reset_source;
3104 conf->gen.tentative_source = conf->gen.reset_source;
3105 conf->gen.status |= GUC_HAVE_TENTATIVE;
3111 struct config_string *conf = (struct config_string *) gconf;
3114 if (conf->reset_val == NULL)
3116 /* Nothing to reset to, as yet; so do nothing */
3120 /* We need not strdup here */
3121 str = conf->reset_val;
3123 if (conf->assign_hook)
3127 newstr = (*conf->assign_hook) (str, true,
3130 elog(ERROR, "failed to reset %s", conf->gen.name);
3131 else if (newstr != str)
3134 * See notes in set_config_option about casting
3136 str = (char *) newstr;
3140 set_string_field(conf, conf->variable, str);
3141 set_string_field(conf, &conf->tentative_val, str);
3142 conf->gen.source = conf->gen.reset_source;
3143 conf->gen.tentative_source = conf->gen.reset_source;
3144 conf->gen.status |= GUC_HAVE_TENTATIVE;
3150 if (gconf->flags & GUC_REPORT)
3151 ReportGUCOption(gconf);
3158 * Push previous state during first assignment to a GUC variable
3159 * within a particular transaction.
3161 * We have to be willing to "back-fill" the state stack if the first
3162 * assignment occurs within a subtransaction nested several levels deep.
3163 * This ensures that if an intermediate transaction aborts, it will have
3164 * the proper value available to restore the setting to.
3167 push_old_value(struct config_generic * gconf)
3169 int my_level = GetCurrentTransactionNestLevel();
3172 /* If we're not inside a transaction, do nothing */
3178 /* Done if we already pushed it at this nesting depth */
3179 if (gconf->stack && gconf->stack->nest_level >= my_level)
3183 * We keep all the stack entries in TopTransactionContext so as to
3184 * avoid allocation problems when a subtransaction back-fills stack
3185 * entries for upper transaction levels.
3187 stack = (GucStack *) MemoryContextAlloc(TopTransactionContext,
3190 stack->prev = gconf->stack;
3191 stack->nest_level = stack->prev ? stack->prev->nest_level + 1 : 1;
3192 stack->status = gconf->status;
3193 stack->tentative_source = gconf->tentative_source;
3194 stack->source = gconf->source;
3196 switch (gconf->vartype)
3199 stack->tentative_val.boolval =
3200 ((struct config_bool *) gconf)->tentative_val;
3201 stack->value.boolval =
3202 *((struct config_bool *) gconf)->variable;
3206 stack->tentative_val.intval =
3207 ((struct config_int *) gconf)->tentative_val;
3208 stack->value.intval =
3209 *((struct config_int *) gconf)->variable;
3213 stack->tentative_val.realval =
3214 ((struct config_real *) gconf)->tentative_val;
3215 stack->value.realval =
3216 *((struct config_real *) gconf)->variable;
3220 stack->tentative_val.stringval =
3221 ((struct config_string *) gconf)->tentative_val;
3222 stack->value.stringval =
3223 *((struct config_string *) gconf)->variable;
3227 gconf->stack = stack;
3229 /* Set state to indicate nothing happened yet within this level */
3230 gconf->status = GUC_HAVE_STACK;
3232 /* Ensure we remember to pop at end of xact */
3238 * Do GUC processing at transaction or subtransaction commit or abort.
3241 AtEOXact_GUC(bool isCommit, bool isSubXact)
3246 /* Quick exit if nothing's changed in this transaction */
3250 my_level = GetCurrentTransactionNestLevel();
3251 Assert(isSubXact ? (my_level > 1) : (my_level == 1));
3253 for (i = 0; i < num_guc_variables; i++)
3255 struct config_generic *gconf = guc_variables[i];
3256 int my_status = gconf->status;
3257 GucStack *stack = gconf->stack;
3262 * Skip if nothing's happened to this var in this transaction
3266 Assert(stack == NULL);
3269 /* Assert that we stacked old value before changing it */
3270 Assert(stack != NULL && (my_status & GUC_HAVE_STACK));
3271 /* However, the last change may have been at an outer xact level */
3272 if (stack->nest_level < my_level)
3274 Assert(stack->nest_level == my_level);
3277 * We will pop the stack entry. Start by restoring outer xact status
3278 * (since we may want to modify it below). Be careful to use
3279 * my_status to reference the inner xact status below this point...
3281 gconf->status = stack->status;
3284 * We have two cases:
3286 * If commit and HAVE_TENTATIVE, set actual value to tentative (this
3287 * is to override a SET LOCAL if one occurred later than SET). We keep
3288 * the tentative value and propagate HAVE_TENTATIVE to the parent
3289 * status, allowing the SET's effect to percolate up. (But if we're
3290 * exiting the outermost transaction, we'll drop the HAVE_TENTATIVE
3293 * Otherwise, we have a transaction that aborted or executed only SET
3294 * LOCAL (or no SET at all). In either case it should have no further
3295 * effect, so restore both tentative and actual values from the stack
3299 useTentative = isCommit && (my_status & GUC_HAVE_TENTATIVE) != 0;
3302 switch (gconf->vartype)
3306 struct config_bool *conf = (struct config_bool *) gconf;
3308 GucSource newsource;
3312 newval = conf->tentative_val;
3313 newsource = conf->gen.tentative_source;
3314 conf->gen.status |= GUC_HAVE_TENTATIVE;
3318 newval = stack->value.boolval;
3319 newsource = stack->source;
3320 conf->tentative_val = stack->tentative_val.boolval;
3321 conf->gen.tentative_source = stack->tentative_source;
3324 if (*conf->variable != newval)
3326 if (conf->assign_hook)
3327 if (!(*conf->assign_hook) (newval,
3328 true, PGC_S_OVERRIDE))
3329 elog(LOG, "failed to commit %s",
3331 *conf->variable = newval;
3334 conf->gen.source = newsource;
3339 struct config_int *conf = (struct config_int *) gconf;
3341 GucSource newsource;
3345 newval = conf->tentative_val;
3346 newsource = conf->gen.tentative_source;
3347 conf->gen.status |= GUC_HAVE_TENTATIVE;
3351 newval = stack->value.intval;
3352 newsource = stack->source;
3353 conf->tentative_val = stack->tentative_val.intval;
3354 conf->gen.tentative_source = stack->tentative_source;
3357 if (*conf->variable != newval)
3359 if (conf->assign_hook)
3360 if (!(*conf->assign_hook) (newval,
3361 true, PGC_S_OVERRIDE))
3362 elog(LOG, "failed to commit %s",
3364 *conf->variable = newval;
3367 conf->gen.source = newsource;
3372 struct config_real *conf = (struct config_real *) gconf;
3374 GucSource newsource;
3378 newval = conf->tentative_val;
3379 newsource = conf->gen.tentative_source;
3380 conf->gen.status |= GUC_HAVE_TENTATIVE;
3384 newval = stack->value.realval;
3385 newsource = stack->source;
3386 conf->tentative_val = stack->tentative_val.realval;
3387 conf->gen.tentative_source = stack->tentative_source;
3390 if (*conf->variable != newval)
3392 if (conf->assign_hook)
3393 if (!(*conf->assign_hook) (newval,
3394 true, PGC_S_OVERRIDE))
3395 elog(LOG, "failed to commit %s",
3397 *conf->variable = newval;
3400 conf->gen.source = newsource;
3405 struct config_string *conf = (struct config_string *) gconf;
3407 GucSource newsource;
3411 newval = conf->tentative_val;
3412 newsource = conf->gen.tentative_source;
3413 conf->gen.status |= GUC_HAVE_TENTATIVE;
3417 newval = stack->value.stringval;
3418 newsource = stack->source;
3419 set_string_field(conf, &conf->tentative_val,
3420 stack->tentative_val.stringval);
3421 conf->gen.tentative_source = stack->tentative_source;
3424 if (*conf->variable != newval)
3426 if (conf->assign_hook)
3430 newstr = (*conf->assign_hook) (newval, true,
3433 elog(LOG, "failed to commit %s",
3435 else if (newstr != newval)
3438 * If newval should now be freed, it'll be
3439 * taken care of below.
3441 * See notes in set_config_option about
3444 newval = (char *) newstr;
3448 set_string_field(conf, conf->variable, newval);
3451 conf->gen.source = newsource;
3452 /* Release stacked values if not used anymore */
3453 set_string_field(conf, &stack->value.stringval,
3455 set_string_field(conf, &stack->tentative_val.stringval,
3457 /* Don't store tentative value separately after commit */
3459 set_string_field(conf, &conf->tentative_val, NULL);
3464 /* Finish popping the state stack */
3465 gconf->stack = stack->prev;
3469 * If we're now out of all xact levels, forget TENTATIVE status bit;
3470 * there's nothing tentative about the value anymore.
3474 Assert(gconf->stack == NULL);
3478 /* Report new value if we changed it */
3479 if (changed && (gconf->flags & GUC_REPORT))
3480 ReportGUCOption(gconf);
3484 * If we're now out of all xact levels, we can clear guc_dirty. (Note: we
3485 * cannot reset guc_dirty when exiting a subtransaction, because we know
3486 * that all outer transaction levels will have stacked values to deal
3495 * Start up automatic reporting of changes to variables marked GUC_REPORT.
3496 * This is executed at completion of backend startup.
3499 BeginReportingGUCOptions(void)
3504 * Don't do anything unless talking to an interactive frontend of protocol
3507 if (whereToSendOutput != DestRemote ||
3508 PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
3511 reporting_enabled = true;
3513 /* Transmit initial values of interesting variables */
3514 for (i = 0; i < num_guc_variables; i++)
3516 struct config_generic *conf = guc_variables[i];
3518 if (conf->flags & GUC_REPORT)
3519 ReportGUCOption(conf);
3524 * ReportGUCOption: if appropriate, transmit option value to frontend
3527 ReportGUCOption(struct config_generic * record)
3529 if (reporting_enabled && (record->flags & GUC_REPORT))
3531 char *val = _ShowOption(record, false);
3532 StringInfoData msgbuf;
3534 pq_beginmessage(&msgbuf, 'S');
3535 pq_sendstring(&msgbuf, record->name);
3536 pq_sendstring(&msgbuf, val);
3537 pq_endmessage(&msgbuf);
3545 * Try to interpret value as boolean value. Valid values are: true,
3546 * false, yes, no, on, off, 1, 0. If the string parses okay, return
3547 * true, else false. If result is not NULL, return the parsing result
3551 parse_bool(const char *value, bool *result)
3553 size_t len = strlen(value);
3555 if (pg_strncasecmp(value, "true", len) == 0)
3560 else if (pg_strncasecmp(value, "false", len) == 0)
3566 else if (pg_strncasecmp(value, "yes", len) == 0)
3571 else if (pg_strncasecmp(value, "no", len) == 0)
3577 else if (pg_strcasecmp(value, "on") == 0)
3582 else if (pg_strcasecmp(value, "off") == 0)
3588 else if (pg_strcasecmp(value, "1") == 0)
3593 else if (pg_strcasecmp(value, "0") == 0)
3602 *result = false; /* suppress compiler warning */
3611 * Try to parse value as an integer. The accepted formats are the
3612 * usual decimal, octal, or hexadecimal formats. If the string parses
3613 * okay, return true, else false. If result is not NULL, return the
3617 parse_int(const char *value, int *result, int flags)
3623 val = strtol(value, &endptr, 0);
3625 if ((flags & GUC_UNIT_MEMORY) && endptr != value)
3629 while (*endptr == ' ')
3632 if (strcmp(endptr, "kB") == 0)
3637 else if (strcmp(endptr, "MB") == 0)
3643 else if (strcmp(endptr, "GB") == 0)
3652 switch (flags & GUC_UNIT_MEMORY)
3654 case GUC_UNIT_BLOCKS:
3655 val /= (BLCKSZ / 1024);
3657 case GUC_UNIT_XBLOCKS:
3658 val /= (XLOG_BLCKSZ / 1024);
3664 if ((flags & GUC_UNIT_TIME) && endptr != value)
3668 while (*endptr == ' ')
3671 if (strcmp(endptr, "ms") == 0)
3676 else if (strcmp(endptr, "s") == 0)
3682 else if (strcmp(endptr, "min") == 0)
3688 else if (strcmp(endptr, "h") == 0)
3694 else if (strcmp(endptr, "d") == 0)
3703 switch (flags & GUC_UNIT_TIME)
3715 if (endptr == value || *endptr != '\0' || errno == ERANGE
3716 #ifdef HAVE_LONG_INT_64
3717 /* if long > 32 bits, check for overflow of int4 */
3718 || val != (long) ((int32) val)
3723 *result = 0; /* suppress compiler warning */
3727 *result = (int) val;
3734 * Try to parse value as a floating point constant in the usual
3735 * format. If the value parsed okay return true, else false. If
3736 * result is not NULL, return the semantic value there.
3739 parse_real(const char *value, double *result)
3745 val = strtod(value, &endptr);
3746 if (endptr == value || *endptr != '\0' || errno == ERANGE)
3749 *result = 0; /* suppress compiler warning */
3759 * Call a GucStringAssignHook function, being careful to free the
3760 * "newval" string if the hook ereports.
3762 * This is split out of set_config_option just to avoid the "volatile"
3763 * qualifiers that would otherwise have to be plastered all over.
3766 call_string_assign_hook(GucStringAssignHook assign_hook,
3767 char *newval, bool doit, GucSource source)
3773 result = (*assign_hook) (newval, doit, source);
3787 * Sets option `name' to given value. The value should be a string
3788 * which is going to be parsed and converted to the appropriate data
3789 * type. The context and source parameters indicate in which context this
3790 * function is being called so it can apply the access restrictions
3793 * If value is NULL, set the option to its default value. If the
3794 * parameter changeVal is false then don't really set the option but do all
3795 * the checks to see if it would work.
3797 * If there is an error (non-existing option, invalid value) then an
3798 * ereport(ERROR) is thrown *unless* this is called in a context where we
3799 * don't want to ereport (currently, startup or SIGHUP config file reread).
3800 * In that case we write a suitable error message via ereport(DEBUG) and
3801 * return false. This is working around the deficiencies in the ereport
3802 * mechanism, so don't blame me. In all other cases, the function
3803 * returns true, including cases where the input is valid but we chose
3804 * not to apply it because of context or source-priority considerations.
3806 * See also SetConfigOption for an external interface.
3809 set_config_option(const char *name, const char *value,
3810 GucContext context, GucSource source,
3811 bool isLocal, bool changeVal)
3813 struct config_generic *record;
3817 if (context == PGC_SIGHUP || source == PGC_S_DEFAULT)
3820 * To avoid cluttering the log, only the postmaster bleats loudly
3821 * about problems with the config file.
3823 elevel = IsUnderPostmaster ? DEBUG2 : LOG;
3825 else if (source == PGC_S_DATABASE || source == PGC_S_USER)
3830 record = find_option(name, elevel);
3834 (errcode(ERRCODE_UNDEFINED_OBJECT),
3835 errmsg("unrecognized configuration parameter \"%s\"", name)));
3840 * Check if the option can be set at this time. See guc.h for the precise
3841 * rules. Note that we don't want to throw errors if we're in the SIGHUP
3842 * context. In that case we just ignore the attempt and return true.
3844 switch (record->context)
3847 if (context == PGC_SIGHUP)
3849 if (context != PGC_INTERNAL)
3852 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3853 errmsg("parameter \"%s\" cannot be changed",
3858 case PGC_POSTMASTER:
3859 if (context == PGC_SIGHUP)
3861 if (changeVal && !is_newvalue_equal(record, value))
3863 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3864 errmsg("parameter \"%s\" cannot be changed after server start; configuration file change ignored",
3869 if (context != PGC_POSTMASTER)
3872 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3873 errmsg("parameter \"%s\" cannot be changed after server start",
3879 if (context != PGC_SIGHUP && context != PGC_POSTMASTER)
3882 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3883 errmsg("parameter \"%s\" cannot be changed now",
3889 * Hmm, the idea of the SIGHUP context is "ought to be global, but
3890 * can be changed after postmaster start". But there's nothing
3891 * that prevents a crafty administrator from sending SIGHUP
3892 * signals to individual backends only.
3896 if (context == PGC_SIGHUP)
3899 * If a PGC_BACKEND parameter is changed in the config file,
3900 * we want to accept the new value in the postmaster (whence
3901 * it will propagate to subsequently-started backends), but
3902 * ignore it in existing backends. This is a tad klugy, but
3903 * necessary because we don't re-read the config file during
3906 if (IsUnderPostmaster)
3909 else if (context != PGC_BACKEND && context != PGC_POSTMASTER)
3912 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3913 errmsg("parameter \"%s\" cannot be set after connection start",
3919 if (context == PGC_USERSET || context == PGC_BACKEND)
3922 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3923 errmsg("permission denied to set parameter \"%s\"",
3934 * Should we set reset/stacked values? (If so, the behavior is not
3937 makeDefault = changeVal && (source <= PGC_S_OVERRIDE) && (value != NULL);
3940 * Ignore attempted set if overridden by previously processed setting.
3941 * However, if changeVal is false then plow ahead anyway since we are
3942 * trying to find out if the value is potentially good, not actually use
3943 * it. Also keep going if makeDefault is true, since we may want to set
3944 * the reset/stacked values even if we can't set the variable itself.
3946 if (record->source > source)
3948 if (changeVal && !makeDefault)
3950 elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
3958 * Evaluate value and set variable.
3960 switch (record->vartype)
3964 struct config_bool *conf = (struct config_bool *) record;
3969 if (!parse_bool(value, &newval))
3972 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3973 errmsg("parameter \"%s\" requires a Boolean value",
3980 newval = conf->reset_val;
3981 source = conf->gen.reset_source;
3984 if (conf->assign_hook)
3985 if (!(*conf->assign_hook) (newval, changeVal, source))
3988 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3989 errmsg("invalid value for parameter \"%s\": %d",
3990 name, (int) newval)));
3994 if (changeVal || makeDefault)
3996 /* Save old value to support transaction abort */
3998 push_old_value(&conf->gen);
4001 *conf->variable = newval;
4002 conf->gen.source = source;
4008 if (conf->gen.reset_source <= source)
4010 conf->reset_val = newval;
4011 conf->gen.reset_source = source;
4013 for (stack = conf->gen.stack; stack; stack = stack->prev)
4015 if (stack->source <= source)
4017 stack->value.boolval = newval;
4018 stack->source = source;
4024 conf->gen.status |= GUC_HAVE_LOCAL;
4029 conf->tentative_val = newval;
4030 conf->gen.tentative_source = source;
4031 conf->gen.status |= GUC_HAVE_TENTATIVE;
4040 struct config_int *conf = (struct config_int *) record;
4045 if (!parse_int(value, &newval, conf->gen.flags))
4048 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4049 errmsg("parameter \"%s\" requires an integer value",
4053 if (newval < conf->min || newval > conf->max)
4056 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4057 errmsg("%d is outside the valid range for parameter \"%s\" (%d .. %d)",
4058 newval, name, conf->min, conf->max)));
4064 newval = conf->reset_val;
4065 source = conf->gen.reset_source;
4068 if (conf->assign_hook)
4069 if (!(*conf->assign_hook) (newval, changeVal, source))
4072 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4073 errmsg("invalid value for parameter \"%s\": %d",
4078 if (changeVal || makeDefault)
4080 /* Save old value to support transaction abort */
4082 push_old_value(&conf->gen);
4085 *conf->variable = newval;
4086 conf->gen.source = source;
4092 if (conf->gen.reset_source <= source)
4094 conf->reset_val = newval;
4095 conf->gen.reset_source = source;
4097 for (stack = conf->gen.stack; stack; stack = stack->prev)
4099 if (stack->source <= source)
4101 stack->value.intval = newval;
4102 stack->source = source;
4108 conf->gen.status |= GUC_HAVE_LOCAL;
4113 conf->tentative_val = newval;
4114 conf->gen.tentative_source = source;
4115 conf->gen.status |= GUC_HAVE_TENTATIVE;
4124 struct config_real *conf = (struct config_real *) record;
4129 if (!parse_real(value, &newval))
4132 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4133 errmsg("parameter \"%s\" requires a numeric value",
4137 if (newval < conf->min || newval > conf->max)
4140 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4141 errmsg("%g is outside the valid range for parameter \"%s\" (%g .. %g)",
4142 newval, name, conf->min, conf->max)));
4148 newval = conf->reset_val;
4149 source = conf->gen.reset_source;
4152 if (conf->assign_hook)
4153 if (!(*conf->assign_hook) (newval, changeVal, source))
4156 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4157 errmsg("invalid value for parameter \"%s\": %g",
4162 if (changeVal || makeDefault)
4164 /* Save old value to support transaction abort */
4166 push_old_value(&conf->gen);
4169 *conf->variable = newval;
4170 conf->gen.source = source;
4176 if (conf->gen.reset_source <= source)
4178 conf->reset_val = newval;
4179 conf->gen.reset_source = source;
4181 for (stack = conf->gen.stack; stack; stack = stack->prev)
4183 if (stack->source <= source)
4185 stack->value.realval = newval;
4186 stack->source = source;
4192 conf->gen.status |= GUC_HAVE_LOCAL;
4197 conf->tentative_val = newval;
4198 conf->gen.tentative_source = source;
4199 conf->gen.status |= GUC_HAVE_TENTATIVE;
4208 struct config_string *conf = (struct config_string *) record;
4213 newval = guc_strdup(elevel, value);
4218 * The only sort of "parsing" check we need to do is apply
4219 * truncation if GUC_IS_NAME.
4221 if (conf->gen.flags & GUC_IS_NAME)
4222 truncate_identifier(newval, strlen(newval), true);
4224 else if (conf->reset_val)
4227 * We could possibly avoid strdup here, but easier to make
4228 * this case work the same as the normal assignment case.
4230 newval = guc_strdup(elevel, conf->reset_val);
4233 source = conf->gen.reset_source;
4237 /* Nothing to reset to, as yet; so do nothing */
4241 if (conf->assign_hook)
4243 const char *hookresult;
4246 * If the hook ereports, we have to make sure we free
4247 * newval, else it will be a permanent memory leak.
4249 hookresult = call_string_assign_hook(conf->assign_hook,
4253 if (hookresult == NULL)
4257 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4258 errmsg("invalid value for parameter \"%s\": \"%s\"",
4259 name, value ? value : "")));
4262 else if (hookresult != newval)
4267 * Having to cast away const here is annoying, but the
4268 * alternative is to declare assign_hooks as returning
4269 * char*, which would mean they'd have to cast away
4270 * const, or as both taking and returning char*, which
4271 * doesn't seem attractive either --- we don't want
4272 * them to scribble on the passed str.
4274 newval = (char *) hookresult;
4278 if (changeVal || makeDefault)
4280 /* Save old value to support transaction abort */
4282 push_old_value(&conf->gen);
4285 set_string_field(conf, conf->variable, newval);
4286 conf->gen.source = source;
4292 if (conf->gen.reset_source <= source)
4294 set_string_field(conf, &conf->reset_val, newval);
4295 conf->gen.reset_source = source;
4297 for (stack = conf->gen.stack; stack; stack = stack->prev)
4299 if (stack->source <= source)
4301 set_string_field(conf, &stack->value.stringval,
4303 stack->source = source;
4306 /* Perhaps we didn't install newval anywhere */
4307 if (!string_field_used(conf, newval))
4312 conf->gen.status |= GUC_HAVE_LOCAL;
4317 set_string_field(conf, &conf->tentative_val, newval);
4318 conf->gen.tentative_source = source;
4319 conf->gen.status |= GUC_HAVE_TENTATIVE;
4329 if (changeVal && (record->flags & GUC_REPORT))
4330 ReportGUCOption(record);
4337 * Set a config option to the given value. See also set_config_option,
4338 * this is just the wrapper to be called from outside GUC. NB: this
4339 * is used only for non-transactional operations.
4342 SetConfigOption(const char *name, const char *value,
4343 GucContext context, GucSource source)
4345 (void) set_config_option(name, value, context, source, false, true);
4351 * Fetch the current value of the option `name'. If the option doesn't exist,
4352 * throw an ereport and don't return.
4354 * The string is *not* allocated for modification and is really only
4355 * valid until the next call to configuration related functions.
4358 GetConfigOption(const char *name)
4360 struct config_generic *record;
4361 static char buffer[256];
4363 record = find_option(name, ERROR);
4366 (errcode(ERRCODE_UNDEFINED_OBJECT),
4367 errmsg("unrecognized configuration parameter \"%s\"", name)));
4368 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
4370 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4371 errmsg("must be superuser to examine \"%s\"", name)));
4373 switch (record->vartype)
4376 return *((struct config_bool *) record)->variable ? "on" : "off";
4379 snprintf(buffer, sizeof(buffer), "%d",
4380 *((struct config_int *) record)->variable);
4384 snprintf(buffer, sizeof(buffer), "%g",
4385 *((struct config_real *) record)->variable);
4389 return *((struct config_string *) record)->variable;
4395 * Get the RESET value associated with the given option.
4398 GetConfigOptionResetString(const char *name)
4400 struct config_generic *record;
4401 static char buffer[256];
4403 record = find_option(name, ERROR);
4406 (errcode(ERRCODE_UNDEFINED_OBJECT),
4407 errmsg("unrecognized configuration parameter \"%s\"", name)));
4408 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
4410 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4411 errmsg("must be superuser to examine \"%s\"", name)));
4413 switch (record->vartype)
4416 return ((struct config_bool *) record)->reset_val ? "on" : "off";
4419 snprintf(buffer, sizeof(buffer), "%d",
4420 ((struct config_int *) record)->reset_val);
4424 snprintf(buffer, sizeof(buffer), "%g",
4425 ((struct config_real *) record)->reset_val);
4429 return ((struct config_string *) record)->reset_val;
4435 * Detect whether the given configuration option can only be set by
4439 IsSuperuserConfigOption(const char *name)
4441 struct config_generic *record;
4443 record = find_option(name, ERROR);
4444 /* On an unrecognized name, don't error, just return false. */
4447 return (record->context == PGC_SUSET);
4452 * flatten_set_variable_args
4453 * Given a parsenode List as emitted by the grammar for SET,
4454 * convert to the flat string representation used by GUC.
4456 * We need to be told the name of the variable the args are for, because
4457 * the flattening rules vary (ugh).
4459 * The result is NULL if input is NIL (ie, SET ... TO DEFAULT), otherwise
4460 * a palloc'd string.
4463 flatten_set_variable_args(const char *name, List *args)
4465 struct config_generic *record;
4471 * Fast path if just DEFAULT. We do not check the variable name in this
4472 * case --- necessary for RESET ALL to work correctly.
4477 /* Else get flags for the variable */
4478 record = find_option(name, ERROR);
4481 (errcode(ERRCODE_UNDEFINED_OBJECT),
4482 errmsg("unrecognized configuration parameter \"%s\"", name)));
4484 flags = record->flags;
4486 /* Complain if list input and non-list variable */
4487 if ((flags & GUC_LIST_INPUT) == 0 &&
4488 list_length(args) != 1)
4490 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4491 errmsg("SET %s takes only one argument", name)));
4493 initStringInfo(&buf);
4497 A_Const *arg = (A_Const *) lfirst(l);
4500 if (l != list_head(args))
4501 appendStringInfo(&buf, ", ");
4503 if (!IsA(arg, A_Const))
4504 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
4506 switch (nodeTag(&arg->val))
4509 appendStringInfo(&buf, "%ld", intVal(&arg->val));
4512 /* represented as a string, so just copy it */
4513 appendStringInfoString(&buf, strVal(&arg->val));
4516 val = strVal(&arg->val);
4517 if (arg->typename != NULL)
4520 * Must be a ConstInterval argument for TIME ZONE. Coerce
4521 * to interval and back to normalize the value and account
4528 DirectFunctionCall3(interval_in,
4529 CStringGetDatum(val),
4530 ObjectIdGetDatum(InvalidOid),
4531 Int32GetDatum(arg->typename->typmod));
4534 DatumGetCString(DirectFunctionCall1(interval_out,
4536 appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
4541 * Plain string literal or identifier. For quote mode,
4542 * quote it if it's not a vanilla identifier.
4544 if (flags & GUC_LIST_QUOTE)
4545 appendStringInfoString(&buf, quote_identifier(val));
4547 appendStringInfoString(&buf, val);
4551 elog(ERROR, "unrecognized node type: %d",
4552 (int) nodeTag(&arg->val));
4565 SetPGVariable(const char *name, List *args, bool is_local)
4567 char *argstring = flatten_set_variable_args(name, args);
4569 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
4570 set_config_option(name,
4572 (superuser() ? PGC_SUSET : PGC_USERSET),
4579 * SET command wrapped as a SQL callable function.
4582 set_config_by_name(PG_FUNCTION_ARGS)
4590 if (PG_ARGISNULL(0))
4592 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
4593 errmsg("SET requires parameter name")));
4595 /* Get the GUC variable name */
4596 name = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(0)));
4598 /* Get the desired value or set to NULL for a reset request */
4599 if (PG_ARGISNULL(1))
4602 value = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(1)));
4605 * Get the desired state of is_local. Default to false if provided value
4608 if (PG_ARGISNULL(2))
4611 is_local = PG_GETARG_BOOL(2);
4613 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
4614 set_config_option(name,
4616 (superuser() ? PGC_SUSET : PGC_USERSET),
4621 /* get the new current value */
4622 new_value = GetConfigOptionByName(name, NULL);
4624 /* Convert return string to text */
4625 result_text = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(new_value)));
4628 PG_RETURN_TEXT_P(result_text);
4632 define_custom_variable(struct config_generic * variable)
4634 const char *name = variable->name;
4635 const char **nameAddr = &name;
4637 struct config_string *pHolder;
4638 struct config_generic **res = (struct config_generic **) bsearch(
4640 (void *) guc_variables,
4642 sizeof(struct config_generic *),
4647 add_guc_variable(variable, ERROR);
4652 * This better be a placeholder
4654 if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
4656 (errcode(ERRCODE_INTERNAL_ERROR),
4657 errmsg("attempt to redefine parameter \"%s\"", name)));
4659 Assert((*res)->vartype == PGC_STRING);
4660 pHolder = (struct config_string *) * res;
4662 /* We have the same name, no sorting is necessary */
4665 value = *pHolder->variable;
4668 * Assign the string value stored in the placeholder to the real variable.
4670 * XXX this is not really good enough --- it should be a nontransactional
4671 * assignment, since we don't want it to roll back if the current xact
4674 set_config_option(name, value,
4675 pHolder->gen.context, pHolder->gen.source,
4679 * Free up as much as we conveniently can of the placeholder structure
4680 * (this neglects any stack items...)
4682 set_string_field(pHolder, pHolder->variable, NULL);
4683 set_string_field(pHolder, &pHolder->reset_val, NULL);
4684 set_string_field(pHolder, &pHolder->tentative_val, NULL);
4690 init_custom_variable(struct config_generic * gen,
4692 const char *short_desc,
4693 const char *long_desc,
4695 enum config_type type)
4697 gen->name = guc_strdup(ERROR, name);
4698 gen->context = context;
4699 gen->group = CUSTOM_OPTIONS;
4700 gen->short_desc = short_desc;
4701 gen->long_desc = long_desc;
4702 gen->vartype = type;
4706 DefineCustomBoolVariable(const char *name,
4707 const char *short_desc,
4708 const char *long_desc,
4711 GucBoolAssignHook assign_hook,
4712 GucShowHook show_hook)
4714 size_t sz = sizeof(struct config_bool);
4715 struct config_bool *var = (struct config_bool *) guc_malloc(ERROR, sz);
4718 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_BOOL);
4720 var->variable = valueAddr;
4721 var->reset_val = *valueAddr;
4722 var->assign_hook = assign_hook;
4723 var->show_hook = show_hook;
4724 define_custom_variable(&var->gen);
4728 DefineCustomIntVariable(const char *name,
4729 const char *short_desc,
4730 const char *long_desc,
4735 GucIntAssignHook assign_hook,
4736 GucShowHook show_hook)
4738 size_t sz = sizeof(struct config_int);
4739 struct config_int *var = (struct config_int *) guc_malloc(ERROR, sz);
4742 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_INT);
4744 var->variable = valueAddr;
4745 var->reset_val = *valueAddr;
4746 var->min = minValue;
4747 var->max = maxValue;
4748 var->assign_hook = assign_hook;
4749 var->show_hook = show_hook;
4750 define_custom_variable(&var->gen);
4754 DefineCustomRealVariable(const char *name,
4755 const char *short_desc,
4756 const char *long_desc,
4761 GucRealAssignHook assign_hook,
4762 GucShowHook show_hook)
4764 size_t sz = sizeof(struct config_real);
4765 struct config_real *var = (struct config_real *) guc_malloc(ERROR, sz);
4768 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_REAL);
4770 var->variable = valueAddr;
4771 var->reset_val = *valueAddr;
4772 var->min = minValue;
4773 var->max = maxValue;
4774 var->assign_hook = assign_hook;
4775 var->show_hook = show_hook;
4776 define_custom_variable(&var->gen);
4780 DefineCustomStringVariable(const char *name,
4781 const char *short_desc,
4782 const char *long_desc,
4785 GucStringAssignHook assign_hook,
4786 GucShowHook show_hook)
4788 size_t sz = sizeof(struct config_string);
4789 struct config_string *var = (struct config_string *) guc_malloc(ERROR, sz);
4792 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_STRING);
4794 var->variable = valueAddr;
4795 var->reset_val = *valueAddr;
4796 var->assign_hook = assign_hook;
4797 var->show_hook = show_hook;
4798 define_custom_variable(&var->gen);
4802 EmitWarningsOnPlaceholders(const char *className)
4804 struct config_generic **vars = guc_variables;
4805 struct config_generic **last = vars + num_guc_variables;
4807 int nameLen = strlen(className);
4811 struct config_generic *var = *vars++;
4813 if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
4814 strncmp(className, var->name, nameLen) == 0 &&
4815 var->name[nameLen] == GUC_QUALIFIER_SEPARATOR)
4818 (errcode(ERRCODE_UNDEFINED_OBJECT),
4819 errmsg("unrecognized configuration parameter \"%s\"", var->name)));
4829 GetPGVariable(const char *name, DestReceiver *dest)
4831 if (pg_strcasecmp(name, "all") == 0)
4832 ShowAllGUCConfig(dest);
4834 ShowGUCConfigOption(name, dest);
4838 GetPGVariableResultDesc(const char *name)
4842 if (pg_strcasecmp(name, "all") == 0)
4844 /* need a tuple descriptor representing three TEXT columns */
4845 tupdesc = CreateTemplateTupleDesc(3, false);
4846 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
4848 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
4850 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
4856 const char *varname;
4858 /* Get the canonical spelling of name */
4859 (void) GetConfigOptionByName(name, &varname);
4861 /* need a tuple descriptor representing a single TEXT column */
4862 tupdesc = CreateTemplateTupleDesc(1, false);
4863 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
4873 ResetPGVariable(const char *name)
4875 if (pg_strcasecmp(name, "all") == 0)
4878 set_config_option(name,
4880 (superuser() ? PGC_SUSET : PGC_USERSET),
4891 ShowGUCConfigOption(const char *name, DestReceiver *dest)
4893 TupOutputState *tstate;
4895 const char *varname;
4898 /* Get the value and canonical spelling of name */
4899 value = GetConfigOptionByName(name, &varname);
4901 /* need a tuple descriptor representing a single TEXT column */
4902 tupdesc = CreateTemplateTupleDesc(1, false);
4903 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
4906 /* prepare for projection of tuples */
4907 tstate = begin_tup_output_tupdesc(dest, tupdesc);
4910 do_text_output_oneline(tstate, value);
4912 end_tup_output(tstate);
4919 ShowAllGUCConfig(DestReceiver *dest)
4921 bool am_superuser = superuser();
4923 TupOutputState *tstate;
4927 /* need a tuple descriptor representing three TEXT columns */
4928 tupdesc = CreateTemplateTupleDesc(3, false);
4929 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
4931 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
4933 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
4937 /* prepare for projection of tuples */
4938 tstate = begin_tup_output_tupdesc(dest, tupdesc);
4940 for (i = 0; i < num_guc_variables; i++)
4942 struct config_generic *conf = guc_variables[i];
4944 if ((conf->flags & GUC_NO_SHOW_ALL) ||
4945 ((conf->flags & GUC_SUPERUSER_ONLY) && !am_superuser))
4948 /* assign to the values array */
4949 values[0] = (char *) conf->name;
4950 values[1] = _ShowOption(conf, true);
4951 values[2] = (char *) conf->short_desc;
4953 /* send it to dest */
4954 do_tup_output(tstate, values);
4957 if (values[1] != NULL)
4961 end_tup_output(tstate);
4965 * Return GUC variable value by name; optionally return canonical
4966 * form of name. Return value is palloc'd.
4969 GetConfigOptionByName(const char *name, const char **varname)
4971 struct config_generic *record;
4973 record = find_option(name, ERROR);
4976 (errcode(ERRCODE_UNDEFINED_OBJECT),
4977 errmsg("unrecognized configuration parameter \"%s\"", name)));
4978 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
4980 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4981 errmsg("must be superuser to examine \"%s\"", name)));
4984 *varname = record->name;
4986 return _ShowOption(record, true);
4990 * Return GUC variable value by variable number; optionally return canonical
4991 * form of name. Return value is palloc'd.
4994 GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
4997 struct config_generic *conf;
4999 /* check requested variable number valid */
5000 Assert((varnum >= 0) && (varnum < num_guc_variables));
5002 conf = guc_variables[varnum];
5006 if ((conf->flags & GUC_NO_SHOW_ALL) ||
5007 ((conf->flags & GUC_SUPERUSER_ONLY) && !superuser()))
5013 /* first get the generic attributes */
5016 values[0] = conf->name;
5018 /* setting : use _ShowOption in order to avoid duplicating the logic */
5019 values[1] = _ShowOption(conf, false);
5022 if (conf->vartype == PGC_INT)
5026 switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
5031 case GUC_UNIT_BLOCKS:
5032 snprintf(buf, sizeof(buf), "%dkB", BLCKSZ / 1024);
5035 case GUC_UNIT_XBLOCKS:
5036 snprintf(buf, sizeof(buf), "%dkB", XLOG_BLCKSZ / 1024);
5057 values[3] = config_group_names[conf->group];
5060 values[4] = conf->short_desc;
5063 values[5] = conf->long_desc;
5066 values[6] = GucContext_Names[conf->context];
5069 values[7] = config_type_names[conf->vartype];
5072 values[8] = GucSource_Names[conf->source];
5074 /* now get the type specifc attributes */
5075 switch (conf->vartype)
5089 struct config_int *lconf = (struct config_int *) conf;
5092 snprintf(buffer, sizeof(buffer), "%d", lconf->min);
5093 values[9] = pstrdup(buffer);
5096 snprintf(buffer, sizeof(buffer), "%d", lconf->max);
5097 values[10] = pstrdup(buffer);
5103 struct config_real *lconf = (struct config_real *) conf;
5106 snprintf(buffer, sizeof(buffer), "%g", lconf->min);
5107 values[9] = pstrdup(buffer);
5110 snprintf(buffer, sizeof(buffer), "%g", lconf->max);
5111 values[10] = pstrdup(buffer);
5128 * should never get here, but in case we do, set 'em to NULL
5142 * Return the total number of GUC variables
5145 GetNumConfigOptions(void)
5147 return num_guc_variables;
5151 * show_config_by_name - equiv to SHOW X command but implemented as
5155 show_config_by_name(PG_FUNCTION_ARGS)
5161 /* Get the GUC variable name */
5162 varname = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(0)));
5165 varval = GetConfigOptionByName(varname, NULL);
5167 /* Convert to text */
5168 result_text = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(varval)));
5171 PG_RETURN_TEXT_P(result_text);
5175 * show_all_settings - equiv to SHOW ALL command but implemented as
5178 #define NUM_PG_SETTINGS_ATTS 11
5181 show_all_settings(PG_FUNCTION_ARGS)
5183 FuncCallContext *funcctx;
5187 AttInMetadata *attinmeta;
5188 MemoryContext oldcontext;
5190 /* stuff done only on the first call of the function */
5191 if (SRF_IS_FIRSTCALL())
5193 /* create a function context for cross-call persistence */
5194 funcctx = SRF_FIRSTCALL_INIT();
5197 * switch to memory context appropriate for multiple function calls
5199 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
5202 * need a tuple descriptor representing NUM_PG_SETTINGS_ATTS columns
5203 * of the appropriate types
5205 tupdesc = CreateTemplateTupleDesc(NUM_PG_SETTINGS_ATTS, false);
5206 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
5208 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
5210 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "unit",
5212 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "category",
5214 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "short_desc",
5216 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "extra_desc",
5218 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "context",
5220 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "vartype",
5222 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "source",
5224 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "min_val",
5226 TupleDescInitEntry(tupdesc, (AttrNumber) 11, "max_val",
5230 * Generate attribute metadata needed later to produce tuples from raw
5233 attinmeta = TupleDescGetAttInMetadata(tupdesc);
5234 funcctx->attinmeta = attinmeta;
5236 /* total number of tuples to be returned */
5237 funcctx->max_calls = GetNumConfigOptions();
5239 MemoryContextSwitchTo(oldcontext);
5242 /* stuff done on every call of the function */
5243 funcctx = SRF_PERCALL_SETUP();
5245 call_cntr = funcctx->call_cntr;
5246 max_calls = funcctx->max_calls;
5247 attinmeta = funcctx->attinmeta;
5249 if (call_cntr < max_calls) /* do when there is more left to send */
5251 char *values[NUM_PG_SETTINGS_ATTS];
5257 * Get the next visible GUC variable name and value
5261 GetConfigOptionByNum(call_cntr, (const char **) values, &noshow);
5264 /* bump the counter and get the next config setting */
5265 call_cntr = ++funcctx->call_cntr;
5267 /* make sure we haven't gone too far now */
5268 if (call_cntr >= max_calls)
5269 SRF_RETURN_DONE(funcctx);
5274 tuple = BuildTupleFromCStrings(attinmeta, values);
5276 /* make the tuple into a datum */
5277 result = HeapTupleGetDatum(tuple);
5279 SRF_RETURN_NEXT(funcctx, result);
5283 /* do when there is no more left */
5284 SRF_RETURN_DONE(funcctx);
5289 _ShowOption(struct config_generic * record, bool use_units)
5294 switch (record->vartype)
5298 struct config_bool *conf = (struct config_bool *) record;
5300 if (conf->show_hook)
5301 val = (*conf->show_hook) ();
5303 val = *conf->variable ? "on" : "off";
5309 struct config_int *conf = (struct config_int *) record;
5311 if (conf->show_hook)
5312 val = (*conf->show_hook) ();
5316 int result = *conf->variable;
5318 if (use_units && result > 0 && (record->flags & GUC_UNIT_MEMORY))
5320 switch (record->flags & GUC_UNIT_MEMORY)
5322 case GUC_UNIT_BLOCKS:
5323 result *= BLCKSZ / 1024;
5325 case GUC_UNIT_XBLOCKS:
5326 result *= XLOG_BLCKSZ / 1024;
5330 if (result % KB_PER_GB == 0)
5332 result /= KB_PER_GB;
5335 else if (result % KB_PER_MB == 0)
5337 result /= KB_PER_MB;
5345 else if (use_units && result > 0 && (record->flags & GUC_UNIT_TIME))
5347 switch (record->flags & GUC_UNIT_TIME)
5353 result *= MS_PER_MIN;
5357 if (result % MS_PER_D == 0)
5362 else if (result % MS_PER_H == 0)
5367 else if (result % MS_PER_MIN == 0)
5369 result /= MS_PER_MIN;
5370 strcpy(unit, "min");
5372 else if (result % MS_PER_S == 0)
5385 snprintf(buffer, sizeof(buffer), "%d%s",
5386 (int) result, unit);
5394 struct config_real *conf = (struct config_real *) record;
5396 if (conf->show_hook)
5397 val = (*conf->show_hook) ();
5400 snprintf(buffer, sizeof(buffer), "%g",
5409 struct config_string *conf = (struct config_string *) record;
5411 if (conf->show_hook)
5412 val = (*conf->show_hook) ();
5413 else if (*conf->variable && **conf->variable)
5414 val = *conf->variable;
5421 /* just to keep compiler quiet */
5426 return pstrdup(val);
5431 is_newvalue_equal(struct config_generic * record, const char *newvalue)
5433 switch (record->vartype)
5437 struct config_bool *conf = (struct config_bool *) record;
5440 return parse_bool(newvalue, &newval) && *conf->variable == newval;
5444 struct config_int *conf = (struct config_int *) record;
5447 return parse_int(newvalue, &newval, record->flags) && *conf->variable == newval;
5451 struct config_real *conf = (struct config_real *) record;
5454 return parse_real(newvalue, &newval) && *conf->variable == newval;
5458 struct config_string *conf = (struct config_string *) record;
5460 return strcmp(*conf->variable, newvalue) == 0;
5471 * This routine dumps out all non-default GUC options into a binary
5472 * file that is read by all exec'ed backends. The format is:
5474 * variable name, string, null terminated
5475 * variable value, string, null terminated
5476 * variable source, integer
5479 write_nondefault_variables(GucContext context)
5485 Assert(context == PGC_POSTMASTER || context == PGC_SIGHUP);
5487 elevel = (context == PGC_SIGHUP) ? LOG : ERROR;
5492 fp = AllocateFile(CONFIG_EXEC_PARAMS_NEW, "w");
5496 (errcode_for_file_access(),
5497 errmsg("could not write to file \"%s\": %m",
5498 CONFIG_EXEC_PARAMS_NEW)));
5502 for (i = 0; i < num_guc_variables; i++)
5504 struct config_generic *gconf = guc_variables[i];
5506 if (gconf->source != PGC_S_DEFAULT)
5508 fprintf(fp, "%s", gconf->name);
5511 switch (gconf->vartype)
5515 struct config_bool *conf = (struct config_bool *) gconf;
5517 if (*conf->variable == 0)
5518 fprintf(fp, "false");
5520 fprintf(fp, "true");
5526 struct config_int *conf = (struct config_int *) gconf;
5528 fprintf(fp, "%d", *conf->variable);
5534 struct config_real *conf = (struct config_real *) gconf;
5536 /* Could lose precision here? */
5537 fprintf(fp, "%f", *conf->variable);
5543 struct config_string *conf = (struct config_string *) gconf;
5545 fprintf(fp, "%s", *conf->variable);
5552 fwrite(&gconf->source, sizeof(gconf->source), 1, fp);
5559 (errcode_for_file_access(),
5560 errmsg("could not write to file \"%s\": %m",
5561 CONFIG_EXEC_PARAMS_NEW)));
5566 * Put new file in place. This could delay on Win32, but we don't hold
5567 * any exclusive locks.
5569 rename(CONFIG_EXEC_PARAMS_NEW, CONFIG_EXEC_PARAMS);
5574 * Read string, including null byte from file
5576 * Return NULL on EOF and nothing read
5579 read_string_with_null(FILE *fp)
5588 if ((ch = fgetc(fp)) == EOF)
5593 elog(FATAL, "invalid format of exec config params file");
5596 str = guc_malloc(FATAL, maxlen);
5597 else if (i == maxlen)
5598 str = guc_realloc(FATAL, str, maxlen *= 2);
5607 * This routine loads a previous postmaster dump of its non-default
5611 read_nondefault_variables(void)
5621 fp = AllocateFile(CONFIG_EXEC_PARAMS, "r");
5624 /* File not found is fine */
5625 if (errno != ENOENT)
5627 (errcode_for_file_access(),
5628 errmsg("could not read from file \"%s\": %m",
5629 CONFIG_EXEC_PARAMS)));
5635 struct config_generic *record;
5637 if ((varname = read_string_with_null(fp)) == NULL)
5640 if ((record = find_option(varname, FATAL)) == NULL)
5641 elog(FATAL, "failed to locate variable %s in exec config params file", varname);
5642 if ((varvalue = read_string_with_null(fp)) == NULL)
5643 elog(FATAL, "invalid format of exec config params file");
5644 if (fread(&varsource, sizeof(varsource), 1, fp) == 0)
5645 elog(FATAL, "invalid format of exec config params file");
5647 (void) set_config_option(varname, varvalue, record->context,
5648 varsource, false, true);
5655 #endif /* EXEC_BACKEND */
5659 * A little "long argument" simulation, although not quite GNU
5660 * compliant. Takes a string of the form "some-option=some value" and
5661 * returns name = "some_option" and value = "some value" in malloc'ed
5662 * storage. Note that '-' is converted to '_' in the option name. If
5663 * there is no '=' in the input string then value will be NULL.
5666 ParseLongOption(const char *string, char **name, char **value)
5675 equal_pos = strcspn(string, "=");
5677 if (string[equal_pos] == '=')
5679 *name = guc_malloc(FATAL, equal_pos + 1);
5680 strncpy(*name, string, equal_pos);
5681 (*name)[equal_pos] = '\0';
5683 *value = guc_strdup(FATAL, &string[equal_pos + 1]);
5687 /* no equal sign in string */
5688 *name = guc_strdup(FATAL, string);
5692 for (cp = *name; *cp; cp++)
5699 * Handle options fetched from pg_database.datconfig or pg_authid.rolconfig.
5700 * The array parameter must be an array of TEXT (it must not be NULL).
5703 ProcessGUCArray(ArrayType *array, GucSource source)
5707 Assert(array != NULL);
5708 Assert(ARR_ELEMTYPE(array) == TEXTOID);
5709 Assert(ARR_NDIM(array) == 1);
5710 Assert(ARR_LBOUND(array)[0] == 1);
5711 Assert(source == PGC_S_DATABASE || source == PGC_S_USER);
5713 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
5721 d = array_ref(array, 1, &i,
5722 -1 /* varlenarray */ ,
5723 -1 /* TEXT's typlen */ ,
5724 false /* TEXT's typbyval */ ,
5725 'i' /* TEXT's typalign */ ,
5731 s = DatumGetCString(DirectFunctionCall1(textout, d));
5733 ParseLongOption(s, &name, &value);
5737 (errcode(ERRCODE_SYNTAX_ERROR),
5738 errmsg("could not parse setting for parameter \"%s\"", name)));
5744 * We process all these options at SUSET level. We assume that the
5745 * right to insert an option into pg_database or pg_authid was checked
5746 * when it was inserted.
5748 SetConfigOption(name, value, PGC_SUSET, source);
5758 * Add an entry to an option array. The array parameter may be NULL
5759 * to indicate the current table entry is NULL.
5762 GUCArrayAdd(ArrayType *array, const char *name, const char *value)
5764 const char *varname;
5772 /* test if the option is valid */
5773 set_config_option(name, value,
5774 superuser() ? PGC_SUSET : PGC_USERSET,
5775 PGC_S_TEST, false, false);
5777 /* convert name to canonical spelling, so we can use plain strcmp */
5778 (void) GetConfigOptionByName(name, &varname);
5781 newval = palloc(strlen(name) + 1 + strlen(value) + 1);
5782 sprintf(newval, "%s=%s", name, value);
5783 datum = DirectFunctionCall1(textin, CStringGetDatum(newval));
5791 Assert(ARR_ELEMTYPE(array) == TEXTOID);
5792 Assert(ARR_NDIM(array) == 1);
5793 Assert(ARR_LBOUND(array)[0] == 1);
5795 index = ARR_DIMS(array)[0] + 1; /* add after end */
5797 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
5802 d = array_ref(array, 1, &i,
5803 -1 /* varlenarray */ ,
5804 -1 /* TEXT's typlen */ ,
5805 false /* TEXT's typbyval */ ,
5806 'i' /* TEXT's typalign */ ,
5810 current = DatumGetCString(DirectFunctionCall1(textout, d));
5811 if (strncmp(current, newval, strlen(name) + 1) == 0)
5818 a = array_set(array, 1, &index,
5821 -1 /* varlena array */ ,
5822 -1 /* TEXT's typlen */ ,
5823 false /* TEXT's typbyval */ ,
5824 'i' /* TEXT's typalign */ );
5827 a = construct_array(&datum, 1,
5836 * Delete an entry from an option array. The array parameter may be NULL
5837 * to indicate the current table entry is NULL. Also, if the return value
5838 * is NULL then a null should be stored.
5841 GUCArrayDelete(ArrayType *array, const char *name)
5843 const char *varname;
5844 ArrayType *newarray;
5850 /* test if the option is valid */
5851 set_config_option(name, NULL,
5852 superuser() ? PGC_SUSET : PGC_USERSET,
5853 PGC_S_TEST, false, false);
5855 /* convert name to canonical spelling, so we can use plain strcmp */
5856 (void) GetConfigOptionByName(name, &varname);
5859 /* if array is currently null, then surely nothing to delete */
5866 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
5872 d = array_ref(array, 1, &i,
5873 -1 /* varlenarray */ ,
5874 -1 /* TEXT's typlen */ ,
5875 false /* TEXT's typbyval */ ,
5876 'i' /* TEXT's typalign */ ,
5880 val = DatumGetCString(DirectFunctionCall1(textout, d));
5882 /* ignore entry if it's what we want to delete */
5883 if (strncmp(val, name, strlen(name)) == 0
5884 && val[strlen(name)] == '=')
5887 /* else add it to the output array */
5890 newarray = array_set(newarray, 1, &index,
5893 -1 /* varlenarray */ ,
5894 -1 /* TEXT's typlen */ ,
5895 false /* TEXT's typbyval */ ,
5896 'i' /* TEXT's typalign */ );
5899 newarray = construct_array(&d, 1,
5911 * assign_hook subroutines
5915 assign_log_destination(const char *value, bool doit, GucSource source)
5922 /* Need a modifiable copy of string */
5923 rawstring = pstrdup(value);
5925 /* Parse string into list of identifiers */
5926 if (!SplitIdentifierString(rawstring, ',', &elemlist))
5928 /* syntax error in list */
5930 list_free(elemlist);
5931 if (source >= PGC_S_INTERACTIVE)
5933 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5934 errmsg("invalid list syntax for parameter \"log_destination\"")));
5938 foreach(l, elemlist)
5940 char *tok = (char *) lfirst(l);
5942 if (pg_strcasecmp(tok, "stderr") == 0)
5943 newlogdest |= LOG_DESTINATION_STDERR;
5945 else if (pg_strcasecmp(tok, "syslog") == 0)
5946 newlogdest |= LOG_DESTINATION_SYSLOG;
5949 else if (pg_strcasecmp(tok, "eventlog") == 0)
5950 newlogdest |= LOG_DESTINATION_EVENTLOG;
5954 if (source >= PGC_S_INTERACTIVE)
5956 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5957 errmsg("unrecognized \"log_destination\" key word: \"%s\"",
5960 list_free(elemlist);
5966 Log_destination = newlogdest;
5969 list_free(elemlist);
5977 assign_syslog_facility(const char *facility, bool doit, GucSource source)
5981 if (pg_strcasecmp(facility, "LOCAL0") == 0)
5982 syslog_fac = LOG_LOCAL0;
5983 else if (pg_strcasecmp(facility, "LOCAL1") == 0)
5984 syslog_fac = LOG_LOCAL1;
5985 else if (pg_strcasecmp(facility, "LOCAL2") == 0)
5986 syslog_fac = LOG_LOCAL2;
5987 else if (pg_strcasecmp(facility, "LOCAL3") == 0)
5988 syslog_fac = LOG_LOCAL3;
5989 else if (pg_strcasecmp(facility, "LOCAL4") == 0)
5990 syslog_fac = LOG_LOCAL4;
5991 else if (pg_strcasecmp(facility, "LOCAL5") == 0)
5992 syslog_fac = LOG_LOCAL5;
5993 else if (pg_strcasecmp(facility, "LOCAL6") == 0)
5994 syslog_fac = LOG_LOCAL6;
5995 else if (pg_strcasecmp(facility, "LOCAL7") == 0)
5996 syslog_fac = LOG_LOCAL7;
5998 return NULL; /* reject */
6002 syslog_facility = syslog_fac;
6003 set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
6011 assign_syslog_ident(const char *ident, bool doit, GucSource source)
6014 set_syslog_parameters(ident, syslog_facility);
6018 #endif /* HAVE_SYSLOG */
6022 assign_defaultxactisolevel(const char *newval, bool doit, GucSource source)
6024 if (pg_strcasecmp(newval, "serializable") == 0)
6027 DefaultXactIsoLevel = XACT_SERIALIZABLE;
6029 else if (pg_strcasecmp(newval, "repeatable read") == 0)
6032 DefaultXactIsoLevel = XACT_REPEATABLE_READ;
6034 else if (pg_strcasecmp(newval, "read committed") == 0)
6037 DefaultXactIsoLevel = XACT_READ_COMMITTED;
6039 else if (pg_strcasecmp(newval, "read uncommitted") == 0)
6042 DefaultXactIsoLevel = XACT_READ_UNCOMMITTED;
6050 assign_log_min_messages(const char *newval,
6051 bool doit, GucSource source)
6053 return (assign_msglvl(&log_min_messages, newval, doit, source));
6057 assign_client_min_messages(const char *newval, bool doit, GucSource source)
6059 return (assign_msglvl(&client_min_messages, newval, doit, source));
6063 assign_min_error_statement(const char *newval, bool doit, GucSource source)
6065 return (assign_msglvl(&log_min_error_statement, newval, doit, source));
6069 assign_msglvl(int *var, const char *newval, bool doit, GucSource source)
6071 if (pg_strcasecmp(newval, "debug") == 0)
6076 else if (pg_strcasecmp(newval, "debug5") == 0)
6081 else if (pg_strcasecmp(newval, "debug4") == 0)
6086 else if (pg_strcasecmp(newval, "debug3") == 0)
6091 else if (pg_strcasecmp(newval, "debug2") == 0)
6096 else if (pg_strcasecmp(newval, "debug1") == 0)
6101 else if (pg_strcasecmp(newval, "log") == 0)
6108 * Client_min_messages always prints 'info', but we allow it as a value
6111 else if (pg_strcasecmp(newval, "info") == 0)
6116 else if (pg_strcasecmp(newval, "notice") == 0)
6121 else if (pg_strcasecmp(newval, "warning") == 0)
6126 else if (pg_strcasecmp(newval, "error") == 0)
6131 /* We allow FATAL/PANIC for client-side messages too. */
6132 else if (pg_strcasecmp(newval, "fatal") == 0)
6137 else if (pg_strcasecmp(newval, "panic") == 0)
6143 return NULL; /* fail */
6144 return newval; /* OK */
6148 assign_log_error_verbosity(const char *newval, bool doit, GucSource source)
6150 if (pg_strcasecmp(newval, "terse") == 0)
6153 Log_error_verbosity = PGERROR_TERSE;
6155 else if (pg_strcasecmp(newval, "default") == 0)
6158 Log_error_verbosity = PGERROR_DEFAULT;
6160 else if (pg_strcasecmp(newval, "verbose") == 0)
6163 Log_error_verbosity = PGERROR_VERBOSE;
6166 return NULL; /* fail */
6167 return newval; /* OK */
6171 assign_log_statement(const char *newval, bool doit, GucSource source)
6173 if (pg_strcasecmp(newval, "none") == 0)
6176 log_statement = LOGSTMT_NONE;
6178 else if (pg_strcasecmp(newval, "ddl") == 0)
6181 log_statement = LOGSTMT_DDL;
6183 else if (pg_strcasecmp(newval, "mod") == 0)
6186 log_statement = LOGSTMT_MOD;
6188 else if (pg_strcasecmp(newval, "all") == 0)
6191 log_statement = LOGSTMT_ALL;
6194 return NULL; /* fail */
6195 return newval; /* OK */
6199 show_num_temp_buffers(void)
6202 * We show the GUC var until local buffers have been initialized, and
6203 * NLocBuffer afterwards.
6205 static char nbuf[32];
6207 sprintf(nbuf, "%d", NLocBuffer ? NLocBuffer : num_temp_buffers);
6212 assign_phony_autocommit(bool newval, bool doit, GucSource source)
6216 if (doit && source >= PGC_S_INTERACTIVE)
6218 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6219 errmsg("SET AUTOCOMMIT TO OFF is no longer supported")));
6226 assign_custom_variable_classes(const char *newval, bool doit, GucSource source)
6229 * Check syntax. newval must be a comma separated list of identifiers.
6230 * Whitespace is allowed but skipped.
6232 bool hasSpaceAfterToken = false;
6233 const char *cp = newval;
6238 initStringInfo(&buf);
6239 while ((c = *cp++) != 0)
6241 if (isspace((unsigned char) c))
6244 hasSpaceAfterToken = true;
6250 hasSpaceAfterToken = false;
6254 appendStringInfoChar(&buf, ',');
6259 if (hasSpaceAfterToken || !isalnum((unsigned char) c))
6262 * Syntax error due to token following space after token or non
6263 * alpha numeric character
6266 (errcode(ERRCODE_SYNTAX_ERROR),
6267 errmsg("invalid syntax for \"custom_variable_classes\": \"%s\"", newval)));
6272 appendStringInfoChar(&buf, (char) c);
6275 /* Remove stray ',' at end */
6276 if (symLen == 0 && buf.len > 0)
6277 buf.data[--buf.len] = '\0';
6282 newval = strdup(buf.data);
6289 assign_debug_assertions(bool newval, bool doit, GucSource source)
6291 #ifndef USE_ASSERT_CHECKING
6294 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6295 errmsg("assertion checking is not supported by this build")));
6301 assign_ssl(bool newval, bool doit, GucSource source)
6306 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6307 errmsg("SSL is not supported by this build")));
6313 assign_stage_log_stats(bool newval, bool doit, GucSource source)
6315 if (newval && log_statement_stats)
6317 if (source >= PGC_S_INTERACTIVE)
6319 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6320 errmsg("cannot enable parameter when \"log_statement_stats\" is true")));
6321 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
6322 else if (source != PGC_S_OVERRIDE)
6329 assign_log_stats(bool newval, bool doit, GucSource source)
6332 (log_parser_stats || log_planner_stats || log_executor_stats))
6334 if (source >= PGC_S_INTERACTIVE)
6336 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6337 errmsg("cannot enable \"log_statement_stats\" when "
6338 "\"log_parser_stats\", \"log_planner_stats\", "
6339 "or \"log_executor_stats\" is true")));
6340 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
6341 else if (source != PGC_S_OVERRIDE)
6348 assign_transaction_read_only(bool newval, bool doit, GucSource source)
6350 /* Can't go to r/w mode inside a r/o transaction */
6351 if (newval == false && XactReadOnly && IsSubTransaction())
6353 if (source >= PGC_S_INTERACTIVE)
6355 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6356 errmsg("cannot set transaction read-write mode inside a read-only transaction")));
6357 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
6358 else if (source != PGC_S_OVERRIDE)
6365 assign_canonical_path(const char *newval, bool doit, GucSource source)
6369 char *canon_val = guc_strdup(ERROR, newval);
6371 canonicalize_path(canon_val);
6379 assign_backslash_quote(const char *newval, bool doit, GucSource source)
6381 BackslashQuoteType bq;
6385 * Although only "on", "off", and "safe_encoding" are documented, we use
6386 * parse_bool so we can accept all the likely variants of "on" and "off".
6388 if (pg_strcasecmp(newval, "safe_encoding") == 0)
6389 bq = BACKSLASH_QUOTE_SAFE_ENCODING;
6390 else if (parse_bool(newval, &bqbool))
6392 bq = bqbool ? BACKSLASH_QUOTE_ON : BACKSLASH_QUOTE_OFF;
6395 return NULL; /* reject */
6398 backslash_quote = bq;
6404 assign_timezone_abbreviations(const char *newval, bool doit, GucSource source)
6407 * The powerup value shown above for timezone_abbreviations is "UNKNOWN".
6408 * When we see this we just do nothing. If this value isn't overridden
6409 * from the config file then pg_timezone_abbrev_initialize() will
6410 * eventually replace it with "Default". This hack has two purposes: to
6411 * avoid wasting cycles loading values that might soon be overridden from
6412 * the config file, and to avoid trying to read the timezone abbrev files
6413 * during InitializeGUCOptions(). The latter doesn't work in an
6414 * EXEC_BACKEND subprocess because my_exec_path hasn't been set yet and so
6415 * we can't locate PGSHAREDIR. (Essentially the same hack is used to
6416 * delay initializing TimeZone ... if we have any more, we should try to
6417 * clean up and centralize this mechanism ...)
6419 if (strcmp(newval, "UNKNOWN") == 0)
6424 /* Loading abbrev file is expensive, so only do it when value changes */
6425 if (timezone_abbreviations_string == NULL ||
6426 strcmp(timezone_abbreviations_string, newval) != 0)
6431 * If reading config file, only the postmaster should bleat loudly
6432 * about problems. Otherwise, it's just this one process doing it,
6433 * and we use WARNING message level.
6435 if (source == PGC_S_FILE)
6436 elevel = IsUnderPostmaster ? DEBUG2 : LOG;
6439 if (!load_tzoffsets(newval, doit, elevel))
6446 * pg_timezone_abbrev_initialize --- set default value if not done already
6448 * This is called after initial loading of postgresql.conf. If no
6449 * timezone_abbreviations setting was found therein, select default.
6452 pg_timezone_abbrev_initialize(void)
6454 if (strcmp(timezone_abbreviations_string, "UNKNOWN") == 0)
6456 SetConfigOption("timezone_abbreviations", "Default",
6457 PGC_POSTMASTER, PGC_S_ARGV);
6462 assign_tcp_keepalives_idle(int newval, bool doit, GucSource source)
6465 return (pq_setkeepalivesidle(newval, MyProcPort) == STATUS_OK);
6471 show_tcp_keepalives_idle(void)
6473 static char nbuf[16];
6475 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesidle(MyProcPort));
6480 assign_tcp_keepalives_interval(int newval, bool doit, GucSource source)
6483 return (pq_setkeepalivesinterval(newval, MyProcPort) == STATUS_OK);
6489 show_tcp_keepalives_interval(void)
6491 static char nbuf[16];
6493 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesinterval(MyProcPort));
6498 assign_tcp_keepalives_count(int newval, bool doit, GucSource source)
6501 return (pq_setkeepalivescount(newval, MyProcPort) == STATUS_OK);
6507 show_tcp_keepalives_count(void)
6509 static char nbuf[16];
6511 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivescount(MyProcPort));
6516 #include "guc-file.c"