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.354 2006/10/04 00:30:03 momjian 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 bool check_function_bodies;
97 extern int CommitDelay;
98 extern int CommitSiblings;
99 extern char *default_tablespace;
100 extern bool fullPageWrites;
103 extern bool trace_sort;
106 static const char *assign_log_destination(const char *value,
107 bool doit, GucSource source);
110 static int syslog_facility = LOG_LOCAL0;
112 static const char *assign_syslog_facility(const char *facility,
113 bool doit, GucSource source);
114 static const char *assign_syslog_ident(const char *ident,
115 bool doit, GucSource source);
118 static const char *assign_defaultxactisolevel(const char *newval, bool doit,
120 static const char *assign_log_min_messages(const char *newval, bool doit,
122 static const char *assign_client_min_messages(const char *newval,
123 bool doit, GucSource source);
124 static const char *assign_min_error_statement(const char *newval, bool doit,
126 static const char *assign_msglvl(int *var, const char *newval, bool doit,
128 static const char *assign_log_error_verbosity(const char *newval, bool doit,
130 static const char *assign_log_statement(const char *newval, bool doit,
132 static const char *show_num_temp_buffers(void);
133 static bool assign_phony_autocommit(bool newval, bool doit, GucSource source);
134 static const char *assign_custom_variable_classes(const char *newval, bool doit,
136 static bool assign_debug_assertions(bool newval, bool doit, GucSource source);
137 static bool assign_ssl(bool newval, bool doit, GucSource source);
138 static bool assign_stage_log_stats(bool newval, bool doit, GucSource source);
139 static bool assign_log_stats(bool newval, bool doit, GucSource source);
140 static bool assign_transaction_read_only(bool newval, bool doit, GucSource source);
141 static const char *assign_canonical_path(const char *newval, bool doit, GucSource source);
142 static const char *assign_backslash_quote(const char *newval, bool doit, GucSource source);
143 static const char *assign_timezone_abbreviations(const char *newval, bool doit, GucSource source);
145 static bool assign_tcp_keepalives_idle(int newval, bool doit, GucSource source);
146 static bool assign_tcp_keepalives_interval(int newval, bool doit, GucSource source);
147 static bool assign_tcp_keepalives_count(int newval, bool doit, GucSource source);
148 static const char *show_tcp_keepalives_idle(void);
149 static const char *show_tcp_keepalives_interval(void);
150 static const char *show_tcp_keepalives_count(void);
153 * GUC option variables that are exported from this module
155 #ifdef USE_ASSERT_CHECKING
156 bool assert_enabled = true;
158 bool assert_enabled = false;
160 bool log_duration = false;
161 bool Debug_print_plan = false;
162 bool Debug_print_parse = false;
163 bool Debug_print_rewritten = false;
164 bool Debug_pretty_print = false;
165 bool Explain_pretty_print = true;
167 bool log_parser_stats = false;
168 bool log_planner_stats = false;
169 bool log_executor_stats = false;
170 bool log_statement_stats = false; /* this is sort of all three
172 bool log_btree_build_stats = false;
174 bool SQL_inheritance = true;
176 bool Password_encryption = true;
178 bool default_with_oids = false;
180 int log_min_error_statement = PANIC;
181 int log_min_messages = NOTICE;
182 int client_min_messages = NOTICE;
183 int log_min_duration_statement = -1;
185 int num_temp_buffers = 1000;
187 char *ConfigFileName;
190 char *external_pid_file;
192 int tcp_keepalives_idle;
193 int tcp_keepalives_interval;
194 int tcp_keepalives_count;
197 * These variables are all dummies that don't do anything, except in some
198 * cases provide the value for SHOW to display. The real state is elsewhere
199 * and is kept in sync by assign_hooks.
201 static char *client_min_messages_str;
202 static char *log_min_messages_str;
203 static char *log_error_verbosity_str;
204 static char *log_statement_str;
205 static char *log_min_error_statement_str;
206 static char *log_destination_string;
209 static char *syslog_facility_str;
210 static char *syslog_ident_str;
212 static bool phony_autocommit;
213 static bool session_auth_is_superuser;
214 static double phony_random_seed;
215 static char *backslash_quote_string;
216 static char *client_encoding_string;
217 static char *datestyle_string;
218 static char *default_iso_level_string;
219 static char *locale_collate;
220 static char *locale_ctype;
221 static char *regex_flavor_string;
222 static char *server_encoding_string;
223 static char *server_version_string;
224 static int server_version_num;
225 static char *timezone_string;
226 static char *timezone_abbreviations_string;
227 static char *XactIsoLevel_string;
228 static char *data_directory;
229 static char *custom_variable_classes;
230 static int max_function_args;
231 static int max_index_keys;
232 static int max_identifier_length;
233 static int block_size;
234 static bool integer_datetimes;
236 /* should be static, but commands/variable.c needs to get at these */
238 char *session_authorization_string;
242 * Displayable names for context types (enum GucContext)
244 * Note: these strings are deliberately not localized.
246 const char *const GucContext_Names[] =
248 /* PGC_INTERNAL */ "internal",
249 /* PGC_POSTMASTER */ "postmaster",
250 /* PGC_SIGHUP */ "sighup",
251 /* PGC_BACKEND */ "backend",
252 /* PGC_SUSET */ "superuser",
253 /* PGC_USERSET */ "user"
257 * Displayable names for source types (enum GucSource)
259 * Note: these strings are deliberately not localized.
261 const char *const GucSource_Names[] =
263 /* PGC_S_DEFAULT */ "default",
264 /* PGC_S_ENV_VAR */ "environment variable",
265 /* PGC_S_FILE */ "configuration file",
266 /* PGC_S_ARGV */ "command line",
267 /* PGC_S_DATABASE */ "database",
268 /* PGC_S_USER */ "user",
269 /* PGC_S_CLIENT */ "client",
270 /* PGC_S_OVERRIDE */ "override",
271 /* PGC_S_INTERACTIVE */ "interactive",
272 /* PGC_S_TEST */ "test",
273 /* PGC_S_SESSION */ "session"
277 * Displayable names for the groupings defined in enum config_group
279 const char *const config_group_names[] =
282 gettext_noop("Ungrouped"),
284 gettext_noop("File Locations"),
286 gettext_noop("Connections and Authentication"),
287 /* CONN_AUTH_SETTINGS */
288 gettext_noop("Connections and Authentication / Connection Settings"),
289 /* CONN_AUTH_SECURITY */
290 gettext_noop("Connections and Authentication / Security and Authentication"),
292 gettext_noop("Resource Usage"),
294 gettext_noop("Resource Usage / Memory"),
296 gettext_noop("Resource Usage / Free Space Map"),
297 /* RESOURCES_KERNEL */
298 gettext_noop("Resource Usage / Kernel Resources"),
300 gettext_noop("Write-Ahead Log"),
302 gettext_noop("Write-Ahead Log / Settings"),
303 /* WAL_CHECKPOINTS */
304 gettext_noop("Write-Ahead Log / Checkpoints"),
306 gettext_noop("Query Tuning"),
307 /* QUERY_TUNING_METHOD */
308 gettext_noop("Query Tuning / Planner Method Configuration"),
309 /* QUERY_TUNING_COST */
310 gettext_noop("Query Tuning / Planner Cost Constants"),
311 /* QUERY_TUNING_GEQO */
312 gettext_noop("Query Tuning / Genetic Query Optimizer"),
313 /* QUERY_TUNING_OTHER */
314 gettext_noop("Query Tuning / Other Planner Options"),
316 gettext_noop("Reporting and Logging"),
318 gettext_noop("Reporting and Logging / Where to Log"),
320 gettext_noop("Reporting and Logging / When to Log"),
322 gettext_noop("Reporting and Logging / What to Log"),
324 gettext_noop("Statistics"),
325 /* STATS_MONITORING */
326 gettext_noop("Statistics / Monitoring"),
327 /* STATS_COLLECTOR */
328 gettext_noop("Statistics / Query and Index Statistics Collector"),
330 gettext_noop("Autovacuum"),
332 gettext_noop("Client Connection Defaults"),
333 /* CLIENT_CONN_STATEMENT */
334 gettext_noop("Client Connection Defaults / Statement Behavior"),
335 /* CLIENT_CONN_LOCALE */
336 gettext_noop("Client Connection Defaults / Locale and Formatting"),
337 /* CLIENT_CONN_OTHER */
338 gettext_noop("Client Connection Defaults / Other Defaults"),
339 /* LOCK_MANAGEMENT */
340 gettext_noop("Lock Management"),
342 gettext_noop("Version and Platform Compatibility"),
343 /* COMPAT_OPTIONS_PREVIOUS */
344 gettext_noop("Version and Platform Compatibility / Previous PostgreSQL Versions"),
345 /* COMPAT_OPTIONS_CLIENT */
346 gettext_noop("Version and Platform Compatibility / Other Platforms and Clients"),
348 gettext_noop("Preset Options"),
350 gettext_noop("Customized Options"),
351 /* DEVELOPER_OPTIONS */
352 gettext_noop("Developer Options"),
353 /* help_config wants this array to be null-terminated */
358 * Displayable names for GUC variable types (enum config_type)
360 * Note: these strings are deliberately not localized.
362 const char *const config_type_names[] =
364 /* PGC_BOOL */ "bool",
365 /* PGC_INT */ "integer",
366 /* PGC_REAL */ "real",
367 /* PGC_STRING */ "string"
372 * Contents of GUC tables
374 * See src/backend/utils/misc/README for design notes.
378 * 1. Declare a global variable of type bool, int, double, or char*
379 * and make use of it.
381 * 2. Decide at what times it's safe to set the option. See guc.h for
384 * 3. Decide on a name, a default value, upper and lower bounds (if
387 * 4. Add a record below.
389 * 5. Add it to src/backend/utils/misc/postgresql.conf.sample, if
392 * 6. Add it to src/bin/psql/tab-complete.c, if it's a USERSET option.
394 * 7. Don't forget to document the option.
396 * 8. If it's a new GUC_LIST option you must edit pg_dumpall.c to ensure
397 * it is not single quoted at dump time.
401 /******** option records follow ********/
403 static struct config_bool ConfigureNamesBool[] =
406 {"enable_seqscan", PGC_USERSET, QUERY_TUNING_METHOD,
407 gettext_noop("Enables the planner's use of sequential-scan plans."),
414 {"enable_indexscan", PGC_USERSET, QUERY_TUNING_METHOD,
415 gettext_noop("Enables the planner's use of index-scan plans."),
422 {"enable_bitmapscan", PGC_USERSET, QUERY_TUNING_METHOD,
423 gettext_noop("Enables the planner's use of bitmap-scan plans."),
430 {"enable_tidscan", PGC_USERSET, QUERY_TUNING_METHOD,
431 gettext_noop("Enables the planner's use of TID scan plans."),
438 {"enable_sort", PGC_USERSET, QUERY_TUNING_METHOD,
439 gettext_noop("Enables the planner's use of explicit sort steps."),
446 {"enable_hashagg", PGC_USERSET, QUERY_TUNING_METHOD,
447 gettext_noop("Enables the planner's use of hashed aggregation plans."),
454 {"enable_nestloop", PGC_USERSET, QUERY_TUNING_METHOD,
455 gettext_noop("Enables the planner's use of nested-loop join plans."),
462 {"enable_mergejoin", PGC_USERSET, QUERY_TUNING_METHOD,
463 gettext_noop("Enables the planner's use of merge join plans."),
470 {"enable_hashjoin", PGC_USERSET, QUERY_TUNING_METHOD,
471 gettext_noop("Enables the planner's use of hash join plans."),
478 {"constraint_exclusion", PGC_USERSET, QUERY_TUNING_OTHER,
479 gettext_noop("Enables the planner to use constraints to optimize queries."),
480 gettext_noop("Child table scans will be skipped if their "
481 "constraints guarantee that no rows match the query.")
483 &constraint_exclusion,
487 {"geqo", PGC_USERSET, QUERY_TUNING_GEQO,
488 gettext_noop("Enables genetic query optimization."),
489 gettext_noop("This algorithm attempts to do planning without "
490 "exhaustive searching.")
496 /* Not for general use --- used by SET SESSION AUTHORIZATION */
497 {"is_superuser", PGC_INTERNAL, UNGROUPED,
498 gettext_noop("Shows whether the current user is a superuser."),
500 GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
502 &session_auth_is_superuser,
506 {"ssl", PGC_POSTMASTER, CONN_AUTH_SECURITY,
507 gettext_noop("Enables SSL connections."),
511 false, assign_ssl, NULL
514 {"fsync", PGC_SIGHUP, WAL_SETTINGS,
515 gettext_noop("Forces synchronization of updates to disk."),
516 gettext_noop("The server will use the fsync() system call in several places to make "
517 "sure that updates are physically written to disk. This insures "
518 "that a database cluster will recover to a consistent state after "
519 "an operating system or hardware crash.")
525 {"zero_damaged_pages", PGC_SUSET, DEVELOPER_OPTIONS,
526 gettext_noop("Continues processing past damaged page headers."),
527 gettext_noop("Detection of a damaged page header normally causes PostgreSQL to "
528 "report an error, aborting the current transaction. Setting "
529 "zero_damaged_pages to true causes the system to instead report a "
530 "warning, zero out the damaged page, and continue processing. This "
531 "behavior will destroy data, namely all the rows on the damaged page."),
538 {"full_page_writes", PGC_SIGHUP, WAL_SETTINGS,
539 gettext_noop("Writes full pages to WAL when first modified after a checkpoint."),
540 gettext_noop("A page write in process during an operating system crash might be "
541 "only partially written to disk. During recovery, the row changes "
542 "stored in WAL are not enough to recover. This option writes "
543 "pages when first modified after a checkpoint to WAL so full recovery "
550 {"silent_mode", PGC_POSTMASTER, LOGGING_WHEN,
551 gettext_noop("Runs the server silently."),
552 gettext_noop("If this parameter is set, the server will automatically run in the "
553 "background and any controlling terminals are dissociated.")
559 {"log_connections", PGC_BACKEND, LOGGING_WHAT,
560 gettext_noop("Logs each successful connection."),
567 {"log_disconnections", PGC_BACKEND, LOGGING_WHAT,
568 gettext_noop("Logs end of a session, including duration."),
575 {"debug_assertions", PGC_USERSET, DEVELOPER_OPTIONS,
576 gettext_noop("Turns on various assertion checks."),
577 gettext_noop("This is a debugging aid."),
581 #ifdef USE_ASSERT_CHECKING
586 assign_debug_assertions, NULL
589 /* currently undocumented, so don't show in SHOW ALL */
590 {"exit_on_error", PGC_USERSET, UNGROUPED,
591 gettext_noop("no description available"),
593 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
599 {"log_duration", PGC_SUSET, LOGGING_WHAT,
600 gettext_noop("Logs the duration of each completed SQL statement."),
607 {"debug_print_parse", PGC_USERSET, LOGGING_WHAT,
608 gettext_noop("Prints the parse tree to the server log."),
615 {"debug_print_rewritten", PGC_USERSET, LOGGING_WHAT,
616 gettext_noop("Prints the parse tree after rewriting to server log."),
619 &Debug_print_rewritten,
623 {"debug_print_plan", PGC_USERSET, LOGGING_WHAT,
624 gettext_noop("Prints the execution plan to server log."),
631 {"debug_pretty_print", PGC_USERSET, LOGGING_WHAT,
632 gettext_noop("Indents parse and plan tree displays."),
639 {"log_parser_stats", PGC_SUSET, STATS_MONITORING,
640 gettext_noop("Writes parser performance statistics to the server log."),
644 false, assign_stage_log_stats, NULL
647 {"log_planner_stats", PGC_SUSET, STATS_MONITORING,
648 gettext_noop("Writes planner performance statistics to the server log."),
652 false, assign_stage_log_stats, NULL
655 {"log_executor_stats", PGC_SUSET, STATS_MONITORING,
656 gettext_noop("Writes executor performance statistics to the server log."),
660 false, assign_stage_log_stats, NULL
663 {"log_statement_stats", PGC_SUSET, STATS_MONITORING,
664 gettext_noop("Writes cumulative performance statistics to the server log."),
667 &log_statement_stats,
668 false, assign_log_stats, NULL
670 #ifdef BTREE_BUILD_STATS
672 {"log_btree_build_stats", PGC_SUSET, DEVELOPER_OPTIONS,
673 gettext_noop("no description available"),
677 &log_btree_build_stats,
683 {"explain_pretty_print", PGC_USERSET, CLIENT_CONN_OTHER,
684 gettext_noop("Uses the indented output format for EXPLAIN VERBOSE."),
687 &Explain_pretty_print,
691 {"stats_start_collector", PGC_POSTMASTER, STATS_COLLECTOR,
692 gettext_noop("Starts the server statistics-collection subprocess."),
695 &pgstat_collect_startcollector,
699 {"stats_reset_on_server_start", PGC_POSTMASTER, STATS_COLLECTOR,
700 gettext_noop("Zeroes collected statistics on server restart."),
703 &pgstat_collect_resetonpmstart,
707 {"stats_row_level", PGC_SUSET, STATS_COLLECTOR,
708 gettext_noop("Collects row-level statistics on database activity."),
711 &pgstat_collect_tuplelevel,
715 {"stats_block_level", PGC_SUSET, STATS_COLLECTOR,
716 gettext_noop("Collects block-level statistics on database activity."),
719 &pgstat_collect_blocklevel,
724 {"stats_command_string", PGC_SUSET, STATS_COLLECTOR,
725 gettext_noop("Collects information about executing commands."),
726 gettext_noop("Enables the collection of information on the currently "
727 "executing command of each session, along with the time "
728 "at which that command began execution.")
730 &pgstat_collect_querystring,
735 {"update_process_title", PGC_SUSET, STATS_COLLECTOR,
736 gettext_noop("Updates the process title to show the active SQL command."),
737 gettext_noop("Enables updating of the process title every time a new SQL command is received by the server.")
739 &update_process_title,
744 {"autovacuum", PGC_SIGHUP, AUTOVACUUM,
745 gettext_noop("Starts the autovacuum subprocess."),
748 &autovacuum_start_daemon,
753 {"trace_notify", PGC_USERSET, DEVELOPER_OPTIONS,
754 gettext_noop("Generates debugging output for LISTEN and NOTIFY."),
764 {"trace_locks", PGC_SUSET, DEVELOPER_OPTIONS,
765 gettext_noop("no description available"),
773 {"trace_userlocks", PGC_SUSET, DEVELOPER_OPTIONS,
774 gettext_noop("no description available"),
782 {"trace_lwlocks", PGC_SUSET, DEVELOPER_OPTIONS,
783 gettext_noop("no description available"),
791 {"debug_deadlocks", PGC_SUSET, DEVELOPER_OPTIONS,
792 gettext_noop("no description available"),
802 {"log_hostname", PGC_SIGHUP, LOGGING_WHAT,
803 gettext_noop("Logs the host name in the connection logs."),
804 gettext_noop("By default, connection logs only show the IP address "
805 "of the connecting host. If you want them to show the host name you "
806 "can turn this on, but depending on your host name resolution "
807 "setup it might impose a non-negligible performance penalty.")
813 {"sql_inheritance", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
814 gettext_noop("Causes subtables to be included by default in various commands."),
821 {"password_encryption", PGC_USERSET, CONN_AUTH_SECURITY,
822 gettext_noop("Encrypt passwords."),
823 gettext_noop("When a password is specified in CREATE USER or "
824 "ALTER USER without writing either ENCRYPTED or UNENCRYPTED, "
825 "this parameter determines whether the password is to be encrypted.")
827 &Password_encryption,
831 {"transform_null_equals", PGC_USERSET, COMPAT_OPTIONS_CLIENT,
832 gettext_noop("Treats \"expr=NULL\" as \"expr IS NULL\"."),
833 gettext_noop("When turned on, expressions of the form expr = NULL "
834 "(or NULL = expr) are treated as expr IS NULL, that is, they "
835 "return true if expr evaluates to the null value, and false "
836 "otherwise. The correct behavior of expr = NULL is to always "
837 "return null (unknown).")
839 &Transform_null_equals,
843 {"db_user_namespace", PGC_SIGHUP, CONN_AUTH_SECURITY,
844 gettext_noop("Enables per-database user names."),
851 /* only here for backwards compatibility */
852 {"autocommit", PGC_USERSET, CLIENT_CONN_STATEMENT,
853 gettext_noop("This parameter doesn't do anything."),
854 gettext_noop("It's just here so that we won't choke on SET AUTOCOMMIT TO ON from 7.3-vintage clients."),
855 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
858 true, assign_phony_autocommit, NULL
861 {"default_transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
862 gettext_noop("Sets the default read-only status of new transactions."),
865 &DefaultXactReadOnly,
869 {"transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
870 gettext_noop("Sets the current transaction's read-only status."),
872 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
875 false, assign_transaction_read_only, NULL
878 {"add_missing_from", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
879 gettext_noop("Automatically adds missing table references to FROM clauses."),
886 {"check_function_bodies", PGC_USERSET, CLIENT_CONN_STATEMENT,
887 gettext_noop("Check function bodies during CREATE FUNCTION."),
890 &check_function_bodies,
894 {"array_nulls", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
895 gettext_noop("Enable input of NULL elements in arrays."),
896 gettext_noop("When turned on, unquoted NULL in an array input "
897 "value means a NULL value; "
898 "otherwise it is taken literally.")
904 {"default_with_oids", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
905 gettext_noop("Create new tables with OIDs by default."),
912 {"redirect_stderr", PGC_POSTMASTER, LOGGING_WHERE,
913 gettext_noop("Start a subprocess to capture stderr output into log files."),
920 {"log_truncate_on_rotation", PGC_SIGHUP, LOGGING_WHERE,
921 gettext_noop("Truncate existing log files of same name during log rotation."),
924 &Log_truncate_on_rotation,
930 {"trace_sort", PGC_USERSET, DEVELOPER_OPTIONS,
931 gettext_noop("Emit information about resource usage in sorting."),
942 {"wal_debug", PGC_SUSET, DEVELOPER_OPTIONS,
943 gettext_noop("Emit WAL-related debugging output."),
953 {"integer_datetimes", PGC_INTERNAL, PRESET_OPTIONS,
954 gettext_noop("Datetimes are integer based."),
956 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
959 #ifdef HAVE_INT64_TIMESTAMP
967 {"krb_caseins_users", PGC_POSTMASTER, CONN_AUTH_SECURITY,
968 gettext_noop("Sets whether Kerberos user names should be treated as case-insensitive."),
971 &pg_krb_caseins_users,
976 {"escape_string_warning", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
977 gettext_noop("Warn about backslash escapes in ordinary string literals."),
980 &escape_string_warning,
985 {"standard_conforming_strings", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
986 gettext_noop("'...' strings treat backslashes literally."),
990 &standard_conforming_strings,
995 {"allow_system_table_mods", PGC_POSTMASTER, DEVELOPER_OPTIONS,
996 gettext_noop("Allows modifications of the structure of system tables."),
1000 &allowSystemTableMods,
1005 {"ignore_system_indexes", PGC_BACKEND, DEVELOPER_OPTIONS,
1006 gettext_noop("Disables reading from system indexes."),
1007 gettext_noop("It does not prevent updating the indexes, so it is safe "
1008 "to use. The worst consequence is slowness."),
1011 &IgnoreSystemIndexes,
1015 /* End-of-list marker */
1017 {NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL
1022 static struct config_int ConfigureNamesInt[] =
1025 {"archive_timeout", PGC_SIGHUP, WAL_SETTINGS,
1026 gettext_noop("Forces a switch to the next xlog file if a "
1027 "new file has not been started within N seconds."),
1031 &XLogArchiveTimeout,
1032 0, 0, INT_MAX, NULL, NULL
1035 {"post_auth_delay", PGC_BACKEND, DEVELOPER_OPTIONS,
1036 gettext_noop("Waits N seconds on connection startup after authentication."),
1037 gettext_noop("This allows attaching a debugger to the process."),
1038 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1041 0, 0, INT_MAX, NULL, NULL
1044 {"default_statistics_target", PGC_USERSET, QUERY_TUNING_OTHER,
1045 gettext_noop("Sets the default statistics target."),
1046 gettext_noop("This applies to table columns that have not had a "
1047 "column-specific target set via ALTER TABLE SET STATISTICS.")
1049 &default_statistics_target,
1050 10, 1, 1000, NULL, NULL
1053 {"from_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1054 gettext_noop("Sets the FROM-list size beyond which subqueries are not "
1056 gettext_noop("The planner will merge subqueries into upper "
1057 "queries if the resulting FROM list would have no more than "
1060 &from_collapse_limit,
1061 8, 1, INT_MAX, NULL, NULL
1064 {"join_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1065 gettext_noop("Sets the FROM-list size beyond which JOIN constructs are not "
1067 gettext_noop("The planner will flatten explicit JOIN "
1068 "constructs into lists of FROM items whenever a list of no more "
1069 "than this many items would result.")
1071 &join_collapse_limit,
1072 8, 1, INT_MAX, NULL, NULL
1075 {"geqo_threshold", PGC_USERSET, QUERY_TUNING_GEQO,
1076 gettext_noop("Sets the threshold of FROM items beyond which GEQO is used."),
1080 12, 2, INT_MAX, NULL, NULL
1083 {"geqo_effort", PGC_USERSET, QUERY_TUNING_GEQO,
1084 gettext_noop("GEQO: effort is used to set the default for other GEQO parameters."),
1088 DEFAULT_GEQO_EFFORT, MIN_GEQO_EFFORT, MAX_GEQO_EFFORT, NULL, NULL
1091 {"geqo_pool_size", PGC_USERSET, QUERY_TUNING_GEQO,
1092 gettext_noop("GEQO: number of individuals in the population."),
1093 gettext_noop("Zero selects a suitable default value.")
1096 0, 0, INT_MAX, NULL, NULL
1099 {"geqo_generations", PGC_USERSET, QUERY_TUNING_GEQO,
1100 gettext_noop("GEQO: number of iterations of the algorithm."),
1101 gettext_noop("Zero selects a suitable default value.")
1104 0, 0, INT_MAX, NULL, NULL
1108 {"deadlock_timeout", PGC_SIGHUP, LOCK_MANAGEMENT,
1109 gettext_noop("The time in milliseconds to wait on lock before checking for deadlock."),
1114 1000, 0, INT_MAX, NULL, NULL
1118 * Note: There is some postprocessing done in PostmasterMain() to make
1119 * sure the buffers are at least twice the number of backends, so the
1120 * constraints here are partially unused. Similarly, the superuser
1121 * reserved number is checked to ensure it is less than the max backends
1124 * MaxBackends is limited to INT_MAX/4 because some places compute
1125 * 4*MaxBackends without any overflow check. Likewise we have to limit
1126 * NBuffers to INT_MAX/2.
1129 {"max_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1130 gettext_noop("Sets the maximum number of concurrent connections."),
1134 100, 1, INT_MAX / 4, NULL, NULL
1138 {"superuser_reserved_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1139 gettext_noop("Sets the number of connection slots reserved for superusers."),
1143 3, 0, INT_MAX / 4, NULL, NULL
1147 {"shared_buffers", PGC_POSTMASTER, RESOURCES_MEM,
1148 gettext_noop("Sets the number of shared memory buffers used by the server."),
1153 1024, 16, INT_MAX / 2, NULL, NULL
1157 {"temp_buffers", PGC_USERSET, RESOURCES_MEM,
1158 gettext_noop("Sets the maximum number of temporary buffers used by each session."),
1163 1024, 100, INT_MAX / 2, NULL, show_num_temp_buffers
1167 {"port", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1168 gettext_noop("Sets the TCP port the server listens on."),
1172 DEF_PGPORT, 1, 65535, NULL, NULL
1176 {"unix_socket_permissions", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1177 gettext_noop("Sets the access permissions of the Unix-domain socket."),
1178 gettext_noop("Unix-domain sockets use the usual Unix file system "
1179 "permission set. The parameter value is expected to be an numeric mode "
1180 "specification in the form accepted by the chmod and umask system "
1181 "calls. (To use the customary octal format the number must start with "
1184 &Unix_socket_permissions,
1185 0777, 0000, 0777, NULL, NULL
1189 {"work_mem", PGC_USERSET, RESOURCES_MEM,
1190 gettext_noop("Sets the maximum memory to be used for query workspaces."),
1191 gettext_noop("This much memory may be used by each internal "
1192 "sort operation and hash table before switching to "
1193 "temporary disk files."),
1197 1024, 8 * BLCKSZ / 1024, MAX_KILOBYTES, NULL, NULL
1201 {"maintenance_work_mem", PGC_USERSET, RESOURCES_MEM,
1202 gettext_noop("Sets the maximum memory to be used for maintenance operations."),
1203 gettext_noop("This includes operations such as VACUUM and CREATE INDEX."),
1206 &maintenance_work_mem,
1207 16384, 1024, MAX_KILOBYTES, NULL, NULL
1211 {"max_stack_depth", PGC_SUSET, RESOURCES_MEM,
1212 gettext_noop("Sets the maximum stack depth, in kilobytes."),
1217 2048, 100, MAX_KILOBYTES, assign_max_stack_depth, NULL
1221 {"vacuum_cost_page_hit", PGC_USERSET, RESOURCES,
1222 gettext_noop("Vacuum cost for a page found in the buffer cache."),
1226 1, 0, 10000, NULL, NULL
1230 {"vacuum_cost_page_miss", PGC_USERSET, RESOURCES,
1231 gettext_noop("Vacuum cost for a page not found in the buffer cache."),
1234 &VacuumCostPageMiss,
1235 10, 0, 10000, NULL, NULL
1239 {"vacuum_cost_page_dirty", PGC_USERSET, RESOURCES,
1240 gettext_noop("Vacuum cost for a page dirtied by vacuum."),
1243 &VacuumCostPageDirty,
1244 20, 0, 10000, NULL, NULL
1248 {"vacuum_cost_limit", PGC_USERSET, RESOURCES,
1249 gettext_noop("Vacuum cost amount available before napping."),
1253 200, 1, 10000, NULL, NULL
1257 {"vacuum_cost_delay", PGC_USERSET, RESOURCES,
1258 gettext_noop("Vacuum cost delay in milliseconds."),
1263 0, 0, 1000, NULL, NULL
1267 {"autovacuum_vacuum_cost_delay", PGC_SIGHUP, AUTOVACUUM,
1268 gettext_noop("Vacuum cost delay in milliseconds, for autovacuum."),
1272 &autovacuum_vac_cost_delay,
1273 -1, -1, 1000, NULL, NULL
1277 {"autovacuum_vacuum_cost_limit", PGC_SIGHUP, AUTOVACUUM,
1278 gettext_noop("Vacuum cost amount available before napping, for autovacuum."),
1281 &autovacuum_vac_cost_limit,
1282 -1, -1, 10000, NULL, NULL
1286 {"max_files_per_process", PGC_POSTMASTER, RESOURCES_KERNEL,
1287 gettext_noop("Sets the maximum number of simultaneously open files for each server process."),
1290 &max_files_per_process,
1291 1000, 25, INT_MAX, NULL, NULL
1295 {"max_prepared_transactions", PGC_POSTMASTER, RESOURCES,
1296 gettext_noop("Sets the maximum number of simultaneously prepared transactions."),
1299 &max_prepared_xacts,
1300 5, 0, INT_MAX, NULL, NULL
1305 {"trace_lock_oidmin", PGC_SUSET, DEVELOPER_OPTIONS,
1306 gettext_noop("no description available"),
1311 FirstNormalObjectId, 0, INT_MAX, NULL, NULL
1314 {"trace_lock_table", PGC_SUSET, DEVELOPER_OPTIONS,
1315 gettext_noop("no description available"),
1320 0, 0, INT_MAX, NULL, NULL
1325 {"statement_timeout", PGC_USERSET, CLIENT_CONN_STATEMENT,
1326 gettext_noop("Sets the maximum allowed duration (in milliseconds) of any statement."),
1327 gettext_noop("A value of 0 turns off the timeout."),
1331 0, 0, INT_MAX, NULL, NULL
1335 {"max_fsm_relations", PGC_POSTMASTER, RESOURCES_FSM,
1336 gettext_noop("Sets the maximum number of tables and indexes for which free space is tracked."),
1340 1000, 100, INT_MAX, NULL, NULL
1343 {"max_fsm_pages", PGC_POSTMASTER, RESOURCES_FSM,
1344 gettext_noop("Sets the maximum number of disk pages for which free space is tracked."),
1348 20000, 1000, INT_MAX, NULL, NULL
1352 {"max_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
1353 gettext_noop("Sets the maximum number of locks per transaction."),
1354 gettext_noop("The shared lock table is sized on the assumption that "
1355 "at most max_locks_per_transaction * max_connections distinct "
1356 "objects will need to be locked at any one time.")
1358 &max_locks_per_xact,
1359 64, 10, INT_MAX, NULL, NULL
1363 {"authentication_timeout", PGC_SIGHUP, CONN_AUTH_SECURITY,
1364 gettext_noop("Sets the maximum time in seconds to complete client authentication."),
1368 &AuthenticationTimeout,
1369 60, 1, 600, NULL, NULL
1373 /* Not for general use */
1374 {"pre_auth_delay", PGC_SIGHUP, DEVELOPER_OPTIONS,
1375 gettext_noop("no description available"),
1377 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1380 0, 0, 60, NULL, NULL
1384 {"checkpoint_segments", PGC_SIGHUP, WAL_CHECKPOINTS,
1385 gettext_noop("Sets the maximum distance in log segments between automatic WAL checkpoints."),
1388 &CheckPointSegments,
1389 3, 1, INT_MAX, NULL, NULL
1393 {"checkpoint_timeout", PGC_SIGHUP, WAL_CHECKPOINTS,
1394 gettext_noop("Sets the maximum time in seconds between automatic WAL checkpoints."),
1399 300, 30, 3600, NULL, NULL
1403 {"checkpoint_warning", PGC_SIGHUP, WAL_CHECKPOINTS,
1404 gettext_noop("Logs if filling of checkpoint segments happens more "
1405 "frequently than this (in seconds)."),
1406 gettext_noop("Write a message to the server log if checkpoints "
1407 "caused by the filling of checkpoint segment files happens more "
1408 "frequently than this number of seconds. Zero turns off the warning."),
1412 30, 0, INT_MAX, NULL, NULL
1416 {"wal_buffers", PGC_POSTMASTER, WAL_SETTINGS,
1417 gettext_noop("Sets the number of disk-page buffers in shared memory for WAL."),
1422 8, 4, INT_MAX, NULL, NULL
1426 {"commit_delay", PGC_USERSET, WAL_CHECKPOINTS,
1427 gettext_noop("Sets the delay in microseconds between transaction commit and "
1428 "flushing WAL to disk."),
1432 0, 0, 100000, NULL, NULL
1436 {"commit_siblings", PGC_USERSET, WAL_CHECKPOINTS,
1437 gettext_noop("Sets the minimum concurrent open transactions before performing "
1442 5, 1, 1000, NULL, NULL
1446 {"extra_float_digits", PGC_USERSET, CLIENT_CONN_LOCALE,
1447 gettext_noop("Sets the number of digits displayed for floating-point values."),
1448 gettext_noop("This affects real, double precision, and geometric data types. "
1449 "The parameter value is added to the standard number of digits "
1450 "(FLT_DIG or DBL_DIG as appropriate).")
1452 &extra_float_digits,
1453 0, -15, 2, NULL, NULL
1457 {"log_min_duration_statement", PGC_SUSET, LOGGING_WHEN,
1458 gettext_noop("Sets the minimum execution time in milliseconds above which statements will "
1460 gettext_noop("Zero prints all queries. The default is -1 (turning this feature off)."),
1463 &log_min_duration_statement,
1464 -1, -1, INT_MAX / 1000, NULL, NULL
1468 {"bgwriter_delay", PGC_SIGHUP, RESOURCES,
1469 gettext_noop("Background writer sleep time between rounds in milliseconds"),
1474 200, 10, 10000, NULL, NULL
1478 {"bgwriter_lru_maxpages", PGC_SIGHUP, RESOURCES,
1479 gettext_noop("Background writer maximum number of LRU pages to flush per round"),
1482 &bgwriter_lru_maxpages,
1483 5, 0, 1000, NULL, NULL
1487 {"bgwriter_all_maxpages", PGC_SIGHUP, RESOURCES,
1488 gettext_noop("Background writer maximum number of all pages to flush per round"),
1491 &bgwriter_all_maxpages,
1492 5, 0, 1000, NULL, NULL
1496 {"log_rotation_age", PGC_SIGHUP, LOGGING_WHERE,
1497 gettext_noop("Automatic log file rotation will occur after N minutes"),
1502 HOURS_PER_DAY * MINS_PER_HOUR, 0, INT_MAX / MINS_PER_HOUR, NULL, NULL
1506 {"log_rotation_size", PGC_SIGHUP, LOGGING_WHERE,
1507 gettext_noop("Automatic log file rotation will occur after N kilobytes"),
1512 10 * 1024, 0, INT_MAX / 1024, NULL, NULL
1516 {"max_function_args", PGC_INTERNAL, PRESET_OPTIONS,
1517 gettext_noop("Shows the maximum number of function arguments."),
1519 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1522 FUNC_MAX_ARGS, FUNC_MAX_ARGS, FUNC_MAX_ARGS, NULL, NULL
1526 {"max_index_keys", PGC_INTERNAL, PRESET_OPTIONS,
1527 gettext_noop("Shows the maximum number of index keys."),
1529 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1532 INDEX_MAX_KEYS, INDEX_MAX_KEYS, INDEX_MAX_KEYS, NULL, NULL
1536 {"max_identifier_length", PGC_INTERNAL, PRESET_OPTIONS,
1537 gettext_noop("Shows the maximum identifier length"),
1539 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1541 &max_identifier_length,
1542 NAMEDATALEN - 1, NAMEDATALEN - 1, NAMEDATALEN - 1, NULL, NULL
1546 {"block_size", PGC_INTERNAL, PRESET_OPTIONS,
1547 gettext_noop("Shows size of a disk block"),
1549 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1552 BLCKSZ, BLCKSZ, BLCKSZ, NULL, NULL
1556 {"autovacuum_naptime", PGC_SIGHUP, AUTOVACUUM,
1557 gettext_noop("Time to sleep between autovacuum runs, in seconds."),
1561 &autovacuum_naptime,
1562 60, 1, INT_MAX, NULL, NULL
1565 {"autovacuum_vacuum_threshold", PGC_SIGHUP, AUTOVACUUM,
1566 gettext_noop("Minimum number of tuple updates or deletes prior to vacuum."),
1569 &autovacuum_vac_thresh,
1570 500, 0, INT_MAX, NULL, NULL
1573 {"autovacuum_analyze_threshold", PGC_SIGHUP, AUTOVACUUM,
1574 gettext_noop("Minimum number of tuple inserts, updates or deletes prior to analyze."),
1577 &autovacuum_anl_thresh,
1578 250, 0, INT_MAX, NULL, NULL
1582 {"tcp_keepalives_idle", PGC_USERSET, CLIENT_CONN_OTHER,
1583 gettext_noop("Seconds between issuing TCP keepalives."),
1584 gettext_noop("A value of 0 uses the system default."),
1587 &tcp_keepalives_idle,
1588 0, 0, INT_MAX, assign_tcp_keepalives_idle, show_tcp_keepalives_idle
1592 {"tcp_keepalives_interval", PGC_USERSET, CLIENT_CONN_OTHER,
1593 gettext_noop("Seconds between TCP keepalive retransmits."),
1594 gettext_noop("A value of 0 uses the system default."),
1597 &tcp_keepalives_interval,
1598 0, 0, INT_MAX, assign_tcp_keepalives_interval, show_tcp_keepalives_interval
1602 {"tcp_keepalives_count", PGC_USERSET, CLIENT_CONN_OTHER,
1603 gettext_noop("Maximum number of TCP keepalive retransmits."),
1604 gettext_noop("This controls the number of consecutive keepalive retransmits that can be "
1605 "lost before a connection is considered dead. A value of 0 uses the "
1608 &tcp_keepalives_count,
1609 0, 0, INT_MAX, assign_tcp_keepalives_count, show_tcp_keepalives_count
1613 {"gin_fuzzy_search_limit", PGC_USERSET, UNGROUPED,
1614 gettext_noop("Sets the maximum allowed result for exact search by gin."),
1618 &GinFuzzySearchLimit,
1619 0, 0, INT_MAX, NULL, NULL
1623 {"effective_cache_size", PGC_USERSET, QUERY_TUNING_COST,
1624 gettext_noop("Sets the planner's assumption about size of the disk cache."),
1625 gettext_noop("That is, the portion of the kernel's disk cache that "
1626 "will be used for PostgreSQL data files. This is measured in disk "
1627 "pages, which are normally 8 kB each."),
1630 &effective_cache_size,
1631 DEFAULT_EFFECTIVE_CACHE_SIZE, 1, INT_MAX, NULL, NULL
1635 /* Can't be set in postgresql.conf */
1636 {"server_version_num", PGC_INTERNAL, PRESET_OPTIONS,
1637 gettext_noop("Shows the server version as an integer."),
1639 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1641 &server_version_num,
1642 PG_VERSION_NUM, PG_VERSION_NUM, PG_VERSION_NUM, NULL, NULL
1645 /* End-of-list marker */
1647 {NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL
1652 static struct config_real ConfigureNamesReal[] =
1655 {"seq_page_cost", PGC_USERSET, QUERY_TUNING_COST,
1656 gettext_noop("Sets the planner's estimate of the cost of a "
1657 "sequentially fetched disk page."),
1661 DEFAULT_SEQ_PAGE_COST, 0, DBL_MAX, NULL, NULL
1664 {"random_page_cost", PGC_USERSET, QUERY_TUNING_COST,
1665 gettext_noop("Sets the planner's estimate of the cost of a "
1666 "nonsequentially fetched disk page."),
1670 DEFAULT_RANDOM_PAGE_COST, 0, DBL_MAX, NULL, NULL
1673 {"cpu_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
1674 gettext_noop("Sets the planner's estimate of the cost of "
1675 "processing each tuple (row)."),
1679 DEFAULT_CPU_TUPLE_COST, 0, DBL_MAX, NULL, NULL
1682 {"cpu_index_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
1683 gettext_noop("Sets the planner's estimate of the cost of "
1684 "processing each index entry during an index scan."),
1687 &cpu_index_tuple_cost,
1688 DEFAULT_CPU_INDEX_TUPLE_COST, 0, DBL_MAX, NULL, NULL
1691 {"cpu_operator_cost", PGC_USERSET, QUERY_TUNING_COST,
1692 gettext_noop("Sets the planner's estimate of the cost of "
1693 "processing each operator or function call."),
1697 DEFAULT_CPU_OPERATOR_COST, 0, DBL_MAX, NULL, NULL
1701 {"geqo_selection_bias", PGC_USERSET, QUERY_TUNING_GEQO,
1702 gettext_noop("GEQO: selective pressure within the population."),
1705 &Geqo_selection_bias,
1706 DEFAULT_GEQO_SELECTION_BIAS, MIN_GEQO_SELECTION_BIAS,
1707 MAX_GEQO_SELECTION_BIAS, NULL, NULL
1711 {"bgwriter_lru_percent", PGC_SIGHUP, RESOURCES,
1712 gettext_noop("Background writer percentage of LRU buffers to flush per round"),
1715 &bgwriter_lru_percent,
1716 1.0, 0.0, 100.0, NULL, NULL
1720 {"bgwriter_all_percent", PGC_SIGHUP, RESOURCES,
1721 gettext_noop("Background writer percentage of all buffers to flush per round"),
1724 &bgwriter_all_percent,
1725 0.333, 0.0, 100.0, NULL, NULL
1729 {"seed", PGC_USERSET, UNGROUPED,
1730 gettext_noop("Sets the seed for random-number generation."),
1732 GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1735 0.5, 0.0, 1.0, assign_random_seed, show_random_seed
1739 {"autovacuum_vacuum_scale_factor", PGC_SIGHUP, AUTOVACUUM,
1740 gettext_noop("Number of tuple updates or deletes prior to vacuum as a fraction of reltuples."),
1743 &autovacuum_vac_scale,
1744 0.2, 0.0, 100.0, NULL, NULL
1747 {"autovacuum_analyze_scale_factor", PGC_SIGHUP, AUTOVACUUM,
1748 gettext_noop("Number of tuple inserts, updates or deletes prior to analyze as a fraction of reltuples."),
1751 &autovacuum_anl_scale,
1752 0.1, 0.0, 100.0, NULL, NULL
1755 /* End-of-list marker */
1757 {NULL, 0, 0, NULL, NULL}, NULL, 0.0, 0.0, 0.0, NULL, NULL
1762 static struct config_string ConfigureNamesString[] =
1765 {"archive_command", PGC_SIGHUP, WAL_SETTINGS,
1766 gettext_noop("WAL archiving command."),
1767 gettext_noop("The shell command that will be called to archive a WAL file.")
1769 &XLogArchiveCommand,
1774 {"backslash_quote", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1775 gettext_noop("Sets whether \"\\'\" is allowed in string literals."),
1776 gettext_noop("Valid values are ON, OFF, and SAFE_ENCODING.")
1778 &backslash_quote_string,
1779 "safe_encoding", assign_backslash_quote, NULL
1783 {"client_encoding", PGC_USERSET, CLIENT_CONN_LOCALE,
1784 gettext_noop("Sets the client's character set encoding."),
1786 GUC_IS_NAME | GUC_REPORT
1788 &client_encoding_string,
1789 "SQL_ASCII", assign_client_encoding, NULL
1793 {"client_min_messages", PGC_USERSET, LOGGING_WHEN,
1794 gettext_noop("Sets the message levels that are sent to the client."),
1795 gettext_noop("Valid values are DEBUG5, DEBUG4, DEBUG3, DEBUG2, "
1796 "DEBUG1, LOG, NOTICE, WARNING, and ERROR. Each level includes all the "
1797 "levels that follow it. The later the level, the fewer messages are "
1800 &client_min_messages_str,
1801 "notice", assign_client_min_messages, NULL
1805 {"log_min_messages", PGC_SUSET, LOGGING_WHEN,
1806 gettext_noop("Sets the message levels that are logged."),
1807 gettext_noop("Valid values are DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1, "
1808 "INFO, NOTICE, WARNING, ERROR, LOG, FATAL, and PANIC. Each level "
1809 "includes all the levels that follow it.")
1811 &log_min_messages_str,
1812 "notice", assign_log_min_messages, NULL
1816 {"log_error_verbosity", PGC_SUSET, LOGGING_WHEN,
1817 gettext_noop("Sets the verbosity of logged messages."),
1818 gettext_noop("Valid values are \"terse\", \"default\", and \"verbose\".")
1820 &log_error_verbosity_str,
1821 "default", assign_log_error_verbosity, NULL
1824 {"log_statement", PGC_SUSET, LOGGING_WHAT,
1825 gettext_noop("Sets the type of statements logged."),
1826 gettext_noop("Valid values are \"none\", \"ddl\", \"mod\", and \"all\".")
1829 "none", assign_log_statement, NULL
1833 {"log_min_error_statement", PGC_SUSET, LOGGING_WHEN,
1834 gettext_noop("Causes all statements generating error at or above this level to be logged."),
1835 gettext_noop("All SQL statements that cause an error of the "
1836 "specified level or a higher level are logged.")
1838 &log_min_error_statement_str,
1839 "panic", assign_min_error_statement, NULL
1843 {"log_line_prefix", PGC_SIGHUP, LOGGING_WHAT,
1844 gettext_noop("Controls information prefixed to each log line"),
1845 gettext_noop("if blank no prefix is used")
1853 {"DateStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
1854 gettext_noop("Sets the display format for date and time values."),
1855 gettext_noop("Also controls interpretation of ambiguous "
1857 GUC_LIST_INPUT | GUC_REPORT
1860 "ISO, MDY", assign_datestyle, NULL
1864 {"default_tablespace", PGC_USERSET, CLIENT_CONN_STATEMENT,
1865 gettext_noop("Sets the default tablespace to create tables and indexes in."),
1866 gettext_noop("An empty string selects the database's default tablespace."),
1869 &default_tablespace,
1870 "", assign_default_tablespace, NULL
1874 {"default_transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
1875 gettext_noop("Sets the transaction isolation level of each new transaction."),
1876 gettext_noop("Each SQL transaction has an isolation level, which "
1877 "can be either \"read uncommitted\", \"read committed\", \"repeatable read\", or \"serializable\".")
1879 &default_iso_level_string,
1880 "read committed", assign_defaultxactisolevel, NULL
1884 {"dynamic_library_path", PGC_SUSET, CLIENT_CONN_OTHER,
1885 gettext_noop("Sets the path for dynamically loadable modules."),
1886 gettext_noop("If a dynamically loadable module needs to be opened and "
1887 "the specified name does not have a directory component (i.e., the "
1888 "name does not contain a slash), the system will search this path for "
1889 "the specified file."),
1892 &Dynamic_library_path,
1893 "$libdir", NULL, NULL
1897 {"krb_server_keyfile", PGC_POSTMASTER, CONN_AUTH_SECURITY,
1898 gettext_noop("Sets the location of the Kerberos server key file."),
1902 &pg_krb_server_keyfile,
1903 PG_KRB_SRVTAB, NULL, NULL
1907 {"krb_srvname", PGC_POSTMASTER, CONN_AUTH_SECURITY,
1908 gettext_noop("Sets the name of the Kerberos service."),
1912 PG_KRB_SRVNAM, NULL, NULL
1916 {"krb_server_hostname", PGC_POSTMASTER, CONN_AUTH_SECURITY,
1917 gettext_noop("Sets the hostname of the Kerberos server."),
1920 &pg_krb_server_hostname,
1925 {"bonjour_name", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1926 gettext_noop("Sets the Bonjour broadcast service name."),
1933 /* See main.c about why defaults for LC_foo are not all alike */
1936 {"lc_collate", PGC_INTERNAL, CLIENT_CONN_LOCALE,
1937 gettext_noop("Shows the collation order locale."),
1939 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1946 {"lc_ctype", PGC_INTERNAL, CLIENT_CONN_LOCALE,
1947 gettext_noop("Shows the character classification and case conversion locale."),
1949 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1956 {"lc_messages", PGC_SUSET, CLIENT_CONN_LOCALE,
1957 gettext_noop("Sets the language in which messages are displayed."),
1961 "", locale_messages_assign, NULL
1965 {"lc_monetary", PGC_USERSET, CLIENT_CONN_LOCALE,
1966 gettext_noop("Sets the locale for formatting monetary amounts."),
1970 "C", locale_monetary_assign, NULL
1974 {"lc_numeric", PGC_USERSET, CLIENT_CONN_LOCALE,
1975 gettext_noop("Sets the locale for formatting numbers."),
1979 "C", locale_numeric_assign, NULL
1983 {"lc_time", PGC_USERSET, CLIENT_CONN_LOCALE,
1984 gettext_noop("Sets the locale for formatting date and time values."),
1988 "C", locale_time_assign, NULL
1992 {"shared_preload_libraries", PGC_POSTMASTER, RESOURCES_KERNEL,
1993 gettext_noop("Lists shared libraries to preload into server."),
1995 GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
1997 &shared_preload_libraries_string,
2002 {"local_preload_libraries", PGC_BACKEND, CLIENT_CONN_OTHER,
2003 gettext_noop("Lists shared libraries to preload into each backend."),
2005 GUC_LIST_INPUT | GUC_LIST_QUOTE
2007 &local_preload_libraries_string,
2012 {"regex_flavor", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
2013 gettext_noop("Sets the regular expression \"flavor\"."),
2014 gettext_noop("This can be set to advanced, extended, or basic.")
2016 ®ex_flavor_string,
2017 "advanced", assign_regex_flavor, NULL
2021 {"search_path", PGC_USERSET, CLIENT_CONN_STATEMENT,
2022 gettext_noop("Sets the schema search order for names that are not schema-qualified."),
2024 GUC_LIST_INPUT | GUC_LIST_QUOTE
2026 &namespace_search_path,
2027 "\"$user\",public", assign_search_path, NULL
2031 /* Can't be set in postgresql.conf */
2032 {"server_encoding", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2033 gettext_noop("Sets the server (database) character set encoding."),
2035 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2037 &server_encoding_string,
2038 "SQL_ASCII", NULL, NULL
2042 /* Can't be set in postgresql.conf */
2043 {"server_version", PGC_INTERNAL, PRESET_OPTIONS,
2044 gettext_noop("Shows the server version."),
2046 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2048 &server_version_string,
2049 PG_VERSION, NULL, NULL
2053 /* Not for general use --- used by SET ROLE */
2054 {"role", PGC_USERSET, UNGROUPED,
2055 gettext_noop("Sets the current role."),
2057 GUC_IS_NAME | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2060 "none", assign_role, show_role
2064 /* Not for general use --- used by SET SESSION AUTHORIZATION */
2065 {"session_authorization", PGC_USERSET, UNGROUPED,
2066 gettext_noop("Sets the session user name."),
2068 GUC_IS_NAME | GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2070 &session_authorization_string,
2071 NULL, assign_session_authorization, show_session_authorization
2075 {"log_destination", PGC_SIGHUP, LOGGING_WHERE,
2076 gettext_noop("Sets the destination for server log output."),
2077 gettext_noop("Valid values are combinations of \"stderr\", \"syslog\", "
2078 "and \"eventlog\", depending on the platform."),
2081 &log_destination_string,
2082 "stderr", assign_log_destination, NULL
2085 {"log_directory", PGC_SIGHUP, LOGGING_WHERE,
2086 gettext_noop("Sets the destination directory for log files."),
2087 gettext_noop("May be specified as relative to the data directory "
2088 "or as absolute path."),
2092 "pg_log", assign_canonical_path, NULL
2095 {"log_filename", PGC_SIGHUP, LOGGING_WHERE,
2096 gettext_noop("Sets the file name pattern for log files."),
2101 "postgresql-%Y-%m-%d_%H%M%S.log", NULL, NULL
2106 {"syslog_facility", PGC_SIGHUP, LOGGING_WHERE,
2107 gettext_noop("Sets the syslog \"facility\" to be used when syslog enabled."),
2108 gettext_noop("Valid values are LOCAL0, LOCAL1, LOCAL2, LOCAL3, "
2109 "LOCAL4, LOCAL5, LOCAL6, LOCAL7.")
2111 &syslog_facility_str,
2112 "LOCAL0", assign_syslog_facility, NULL
2115 {"syslog_ident", PGC_SIGHUP, LOGGING_WHERE,
2116 gettext_noop("Sets the program name used to identify PostgreSQL "
2117 "messages in syslog."),
2121 "postgres", assign_syslog_ident, NULL
2126 {"TimeZone", PGC_USERSET, CLIENT_CONN_LOCALE,
2127 gettext_noop("Sets the time zone for displaying and interpreting time stamps."),
2132 "UNKNOWN", assign_timezone, show_timezone
2135 {"timezone_abbreviations", PGC_USERSET, CLIENT_CONN_LOCALE,
2136 gettext_noop("Selects a file of timezone abbreviations"),
2139 &timezone_abbreviations_string,
2140 "UNKNOWN", assign_timezone_abbreviations, NULL
2144 {"transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
2145 gettext_noop("Sets the current transaction's isolation level."),
2147 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2149 &XactIsoLevel_string,
2150 NULL, assign_XactIsoLevel, show_XactIsoLevel
2154 {"unix_socket_group", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2155 gettext_noop("Sets the owning group of the Unix-domain socket."),
2156 gettext_noop("(The owning user of the socket is always the user "
2157 "that starts the server.)")
2164 {"unix_socket_directory", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2165 gettext_noop("Sets the directory where the Unix-domain socket will be created."),
2170 "", assign_canonical_path, NULL
2174 {"listen_addresses", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2175 gettext_noop("Sets the host name or IP address(es) to listen to."),
2180 "localhost", NULL, NULL
2184 {"wal_sync_method", PGC_SIGHUP, WAL_SETTINGS,
2185 gettext_noop("Selects the method used for forcing WAL updates out to disk."),
2189 XLOG_sync_method_default, assign_xlog_sync_method, NULL
2193 {"custom_variable_classes", PGC_SIGHUP, CUSTOM_OPTIONS,
2194 gettext_noop("Sets the list of known custom variable classes."),
2196 GUC_LIST_INPUT | GUC_LIST_QUOTE
2198 &custom_variable_classes,
2199 NULL, assign_custom_variable_classes, NULL
2203 {"data_directory", PGC_POSTMASTER, FILE_LOCATIONS,
2204 gettext_noop("Sets the server's data directory."),
2213 {"config_file", PGC_POSTMASTER, FILE_LOCATIONS,
2214 gettext_noop("Sets the server's main configuration file."),
2216 GUC_DISALLOW_IN_FILE | GUC_SUPERUSER_ONLY
2223 {"hba_file", PGC_POSTMASTER, FILE_LOCATIONS,
2224 gettext_noop("Sets the server's \"hba\" configuration file"),
2233 {"ident_file", PGC_POSTMASTER, FILE_LOCATIONS,
2234 gettext_noop("Sets the server's \"ident\" configuration file"),
2243 {"external_pid_file", PGC_POSTMASTER, FILE_LOCATIONS,
2244 gettext_noop("Writes the postmaster PID to the specified file."),
2249 NULL, assign_canonical_path, NULL
2252 /* End-of-list marker */
2254 {NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL
2259 /******** end of options list ********/
2263 * To allow continued support of obsolete names for GUC variables, we apply
2264 * the following mappings to any unrecognized name. Note that an old name
2265 * should be mapped to a new one only if the new variable has very similar
2266 * semantics to the old.
2268 static const char *const map_old_guc_names[] = {
2269 "sort_mem", "work_mem",
2270 "vacuum_mem", "maintenance_work_mem",
2276 * Actual lookup of variables is done through this single, sorted array.
2278 static struct config_generic **guc_variables;
2280 /* Current number of variables contained in the vector */
2281 static int num_guc_variables;
2283 /* Vector capacity */
2284 static int size_guc_variables;
2287 static bool guc_dirty; /* TRUE if need to do commit/abort work */
2289 static bool reporting_enabled; /* TRUE to enable GUC_REPORT */
2292 static int guc_var_compare(const void *a, const void *b);
2293 static int guc_name_compare(const char *namea, const char *nameb);
2294 static void push_old_value(struct config_generic * gconf);
2295 static void ReportGUCOption(struct config_generic * record);
2296 static void ShowGUCConfigOption(const char *name, DestReceiver *dest);
2297 static void ShowAllGUCConfig(DestReceiver *dest);
2298 static char *_ShowOption(struct config_generic * record, bool use_units);
2299 static bool is_newvalue_equal(struct config_generic * record, const char *newvalue);
2303 * Some infrastructure for checking malloc/strdup/realloc calls
2306 guc_malloc(int elevel, size_t size)
2310 data = malloc(size);
2313 (errcode(ERRCODE_OUT_OF_MEMORY),
2314 errmsg("out of memory")));
2319 guc_realloc(int elevel, void *old, size_t size)
2323 data = realloc(old, size);
2326 (errcode(ERRCODE_OUT_OF_MEMORY),
2327 errmsg("out of memory")));
2332 guc_strdup(int elevel, const char *src)
2339 (errcode(ERRCODE_OUT_OF_MEMORY),
2340 errmsg("out of memory")));
2346 * Support for assigning to a field of a string GUC item. Free the prior
2347 * value if it's not referenced anywhere else in the item (including stacked
2351 set_string_field(struct config_string * conf, char **field, char *newval)
2353 char *oldval = *field;
2356 /* Do the assignment */
2359 /* Exit if any duplicate references, or if old value was NULL anyway */
2360 if (oldval == NULL ||
2361 oldval == *(conf->variable) ||
2362 oldval == conf->reset_val ||
2363 oldval == conf->tentative_val)
2365 for (stack = conf->gen.stack; stack; stack = stack->prev)
2367 if (oldval == stack->tentative_val.stringval ||
2368 oldval == stack->value.stringval)
2372 /* Not used anymore, so free it */
2377 * Detect whether strval is referenced anywhere in a GUC string item
2380 string_field_used(struct config_string * conf, char *strval)
2384 if (strval == *(conf->variable) ||
2385 strval == conf->reset_val ||
2386 strval == conf->tentative_val)
2388 for (stack = conf->gen.stack; stack; stack = stack->prev)
2390 if (strval == stack->tentative_val.stringval ||
2391 strval == stack->value.stringval)
2398 struct config_generic **
2399 get_guc_variables(void)
2401 return guc_variables;
2406 * Build the sorted array. This is split out so that it could be
2407 * re-executed after startup (eg, we could allow loadable modules to
2408 * add vars, and then we'd need to re-sort).
2411 build_guc_variables(void)
2415 struct config_generic **guc_vars;
2418 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
2420 struct config_bool *conf = &ConfigureNamesBool[i];
2422 /* Rather than requiring vartype to be filled in by hand, do this: */
2423 conf->gen.vartype = PGC_BOOL;
2427 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
2429 struct config_int *conf = &ConfigureNamesInt[i];
2431 conf->gen.vartype = PGC_INT;
2435 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
2437 struct config_real *conf = &ConfigureNamesReal[i];
2439 conf->gen.vartype = PGC_REAL;
2443 for (i = 0; ConfigureNamesString[i].gen.name; i++)
2445 struct config_string *conf = &ConfigureNamesString[i];
2447 conf->gen.vartype = PGC_STRING;
2452 * Create table with 20% slack
2454 size_vars = num_vars + num_vars / 4;
2456 guc_vars = (struct config_generic **)
2457 guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
2461 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
2462 guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
2464 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
2465 guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
2467 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
2468 guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
2470 for (i = 0; ConfigureNamesString[i].gen.name; i++)
2471 guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
2474 free(guc_variables);
2475 guc_variables = guc_vars;
2476 num_guc_variables = num_vars;
2477 size_guc_variables = size_vars;
2478 qsort((void *) guc_variables, num_guc_variables,
2479 sizeof(struct config_generic *), guc_var_compare);
2483 is_custom_class(const char *name, int dotPos)
2486 * assign_custom_variable_classes() has made sure no empty identifiers or
2487 * whitespace exists in the variable
2489 bool result = false;
2490 const char *ccs = GetConfigOption("custom_variable_classes");
2494 const char *start = ccs;
2500 if (c == 0 || c == ',')
2502 if (dotPos == ccs - start && strncmp(start, name, dotPos) == 0)
2517 * Add a new GUC variable to the list of known variables. The
2518 * list is expanded if needed.
2521 add_guc_variable(struct config_generic * var, int elevel)
2523 if (num_guc_variables + 1 >= size_guc_variables)
2526 * Increase the vector by 25%
2528 int size_vars = size_guc_variables + size_guc_variables / 4;
2529 struct config_generic **guc_vars;
2534 guc_vars = (struct config_generic **)
2535 guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
2539 guc_vars = (struct config_generic **)
2540 guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
2543 if (guc_vars == NULL)
2544 return false; /* out of memory */
2546 guc_variables = guc_vars;
2547 size_guc_variables = size_vars;
2549 guc_variables[num_guc_variables++] = var;
2550 qsort((void *) guc_variables, num_guc_variables,
2551 sizeof(struct config_generic *), guc_var_compare);
2556 * Create and add a placeholder variable. It's presumed to belong
2557 * to a valid custom variable class at this point.
2559 static struct config_string *
2560 add_placeholder_variable(const char *name, int elevel)
2562 size_t sz = sizeof(struct config_string) + sizeof(char *);
2563 struct config_string *var;
2564 struct config_generic *gen;
2566 var = (struct config_string *) guc_malloc(elevel, sz);
2573 gen->name = guc_strdup(elevel, name);
2574 if (gen->name == NULL)
2580 gen->context = PGC_USERSET;
2581 gen->group = CUSTOM_OPTIONS;
2582 gen->short_desc = "GUC placeholder variable";
2583 gen->flags = GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_CUSTOM_PLACEHOLDER;
2584 gen->vartype = PGC_STRING;
2587 * The char* is allocated at the end of the struct since we have no
2588 * 'static' place to point to.
2590 var->variable = (char **) (var + 1);
2592 if (!add_guc_variable((struct config_generic *) var, elevel))
2594 free((void *) gen->name);
2603 * Look up option NAME. If it exists, return a pointer to its record,
2606 static struct config_generic *
2607 find_option(const char *name, int elevel)
2610 const char **key = &name;
2611 struct config_generic **res;
2617 * By equating const char ** with struct config_generic *, we are assuming
2618 * the name field is first in config_generic.
2620 res = (struct config_generic **) bsearch((void *) &key,
2621 (void *) guc_variables,
2623 sizeof(struct config_generic *),
2629 * See if the name is an obsolete name for a variable. We assume that the
2630 * set of supported old names is short enough that a brute-force search is
2633 for (i = 0; map_old_guc_names[i] != NULL; i += 2)
2635 if (guc_name_compare(name, map_old_guc_names[i]) == 0)
2636 return find_option(map_old_guc_names[i + 1], elevel);
2640 * Check if the name is qualified, and if so, check if the qualifier maps
2641 * to a custom variable class.
2643 dot = strchr(name, GUC_QUALIFIER_SEPARATOR);
2644 if (dot != NULL && is_custom_class(name, dot - name))
2645 /* Add a placeholder variable for this name */
2646 return (struct config_generic *) add_placeholder_variable(name, elevel);
2654 * comparator for qsorting and bsearching guc_variables array
2657 guc_var_compare(const void *a, const void *b)
2659 struct config_generic *confa = *(struct config_generic **) a;
2660 struct config_generic *confb = *(struct config_generic **) b;
2662 return guc_name_compare(confa->name, confb->name);
2667 guc_name_compare(const char *namea, const char *nameb)
2670 * The temptation to use strcasecmp() here must be resisted, because the
2671 * array ordering has to remain stable across setlocale() calls. So, build
2672 * our own with a simple ASCII-only downcasing.
2674 while (*namea && *nameb)
2676 char cha = *namea++;
2677 char chb = *nameb++;
2679 if (cha >= 'A' && cha <= 'Z')
2681 if (chb >= 'A' && chb <= 'Z')
2687 return 1; /* a is longer */
2689 return -1; /* b is longer */
2695 * Initialize GUC options during program startup.
2697 * Note that we cannot read the config file yet, since we have not yet
2698 * processed command-line switches.
2701 InitializeGUCOptions(void)
2707 * Build sorted array of all GUC variables.
2709 build_guc_variables();
2712 * Load all variables with their compiled-in defaults, and initialize
2713 * status fields as needed.
2715 for (i = 0; i < num_guc_variables; i++)
2717 struct config_generic *gconf = guc_variables[i];
2720 gconf->reset_source = PGC_S_DEFAULT;
2721 gconf->tentative_source = PGC_S_DEFAULT;
2722 gconf->source = PGC_S_DEFAULT;
2723 gconf->stack = NULL;
2725 switch (gconf->vartype)
2729 struct config_bool *conf = (struct config_bool *) gconf;
2731 if (conf->assign_hook)
2732 if (!(*conf->assign_hook) (conf->reset_val, true,
2734 elog(FATAL, "failed to initialize %s to %d",
2735 conf->gen.name, (int) conf->reset_val);
2736 *conf->variable = conf->reset_val;
2741 struct config_int *conf = (struct config_int *) gconf;
2743 Assert(conf->reset_val >= conf->min);
2744 Assert(conf->reset_val <= conf->max);
2745 if (conf->assign_hook)
2746 if (!(*conf->assign_hook) (conf->reset_val, true,
2748 elog(FATAL, "failed to initialize %s to %d",
2749 conf->gen.name, conf->reset_val);
2750 *conf->variable = conf->reset_val;
2755 struct config_real *conf = (struct config_real *) gconf;
2757 Assert(conf->reset_val >= conf->min);
2758 Assert(conf->reset_val <= conf->max);
2759 if (conf->assign_hook)
2760 if (!(*conf->assign_hook) (conf->reset_val, true,
2762 elog(FATAL, "failed to initialize %s to %g",
2763 conf->gen.name, conf->reset_val);
2764 *conf->variable = conf->reset_val;
2769 struct config_string *conf = (struct config_string *) gconf;
2772 *conf->variable = NULL;
2773 conf->reset_val = NULL;
2774 conf->tentative_val = NULL;
2776 if (conf->boot_val == NULL)
2778 /* Cannot set value yet */
2782 str = guc_strdup(FATAL, conf->boot_val);
2783 conf->reset_val = str;
2785 if (conf->assign_hook)
2789 newstr = (*conf->assign_hook) (str, true,
2793 elog(FATAL, "failed to initialize %s to \"%s\"",
2794 conf->gen.name, str);
2796 else if (newstr != str)
2801 * See notes in set_config_option about casting
2803 str = (char *) newstr;
2804 conf->reset_val = str;
2807 *conf->variable = str;
2815 reporting_enabled = false;
2818 * Prevent any attempt to override the transaction modes from
2819 * non-interactive sources.
2821 SetConfigOption("transaction_isolation", "default",
2822 PGC_POSTMASTER, PGC_S_OVERRIDE);
2823 SetConfigOption("transaction_read_only", "no",
2824 PGC_POSTMASTER, PGC_S_OVERRIDE);
2827 * For historical reasons, some GUC parameters can receive defaults from
2828 * environment variables. Process those settings.
2831 env = getenv("PGPORT");
2833 SetConfigOption("port", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
2835 env = getenv("PGDATESTYLE");
2837 SetConfigOption("datestyle", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
2839 env = getenv("PGCLIENTENCODING");
2841 SetConfigOption("client_encoding", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
2846 * Select the configuration files and data directory to be used, and
2847 * do the initial read of postgresql.conf.
2849 * This is called after processing command-line switches.
2850 * userDoption is the -D switch value if any (NULL if unspecified).
2851 * progname is just for use in error messages.
2853 * Returns true on success; on failure, prints a suitable error message
2854 * to stderr and returns false.
2857 SelectConfigFiles(const char *userDoption, const char *progname)
2861 struct stat stat_buf;
2863 /* configdir is -D option, or $PGDATA if no -D */
2865 configdir = make_absolute_path(userDoption);
2867 configdir = make_absolute_path(getenv("PGDATA"));
2870 * Find the configuration file: if config_file was specified on the
2871 * command line, use it, else use configdir/postgresql.conf. In any case
2872 * ensure the result is an absolute path, so that it will be interpreted
2873 * the same way by future backends.
2876 fname = make_absolute_path(ConfigFileName);
2879 fname = guc_malloc(FATAL,
2880 strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
2881 sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
2885 write_stderr("%s does not know where to find the server configuration file.\n"
2886 "You must specify the --config-file or -D invocation "
2887 "option or set the PGDATA environment variable.\n",
2893 * Set the ConfigFileName GUC variable to its final value, ensuring that
2894 * it can't be overridden later.
2896 SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
2900 * Now read the config file for the first time.
2902 if (stat(ConfigFileName, &stat_buf) != 0)
2904 write_stderr("%s cannot access the server configuration file \"%s\": %s\n",
2905 progname, ConfigFileName, strerror(errno));
2909 ProcessConfigFile(PGC_POSTMASTER);
2912 * If the data_directory GUC variable has been set, use that as DataDir;
2913 * otherwise use configdir if set; else punt.
2915 * Note: SetDataDir will copy and absolute-ize its argument, so we don't
2919 SetDataDir(data_directory);
2921 SetDataDir(configdir);
2924 write_stderr("%s does not know where to find the database system data.\n"
2925 "This can be specified as \"data_directory\" in \"%s\", "
2926 "or by the -D invocation option, or by the "
2927 "PGDATA environment variable.\n",
2928 progname, ConfigFileName);
2933 * Reflect the final DataDir value back into the data_directory GUC var.
2934 * (If you are wondering why we don't just make them a single variable,
2935 * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
2936 * child backends specially. XXX is that still true? Given that we now
2937 * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
2938 * DataDir in advance.)
2940 SetConfigOption("data_directory", DataDir, PGC_POSTMASTER, PGC_S_OVERRIDE);
2943 * Figure out where pg_hba.conf is, and make sure the path is absolute.
2946 fname = make_absolute_path(HbaFileName);
2949 fname = guc_malloc(FATAL,
2950 strlen(configdir) + strlen(HBA_FILENAME) + 2);
2951 sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
2955 write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
2956 "This can be specified as \"hba_file\" in \"%s\", "
2957 "or by the -D invocation option, or by the "
2958 "PGDATA environment variable.\n",
2959 progname, ConfigFileName);
2962 SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
2966 * Likewise for pg_ident.conf.
2969 fname = make_absolute_path(IdentFileName);
2972 fname = guc_malloc(FATAL,
2973 strlen(configdir) + strlen(IDENT_FILENAME) + 2);
2974 sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
2978 write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
2979 "This can be specified as \"ident_file\" in \"%s\", "
2980 "or by the -D invocation option, or by the "
2981 "PGDATA environment variable.\n",
2982 progname, ConfigFileName);
2985 SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
2995 * Reset all options to their saved default values (implements RESET ALL)
2998 ResetAllOptions(void)
3002 for (i = 0; i < num_guc_variables; i++)
3004 struct config_generic *gconf = guc_variables[i];
3006 /* Don't reset non-SET-able values */
3007 if (gconf->context != PGC_SUSET &&
3008 gconf->context != PGC_USERSET)
3010 /* Don't reset if special exclusion from RESET ALL */
3011 if (gconf->flags & GUC_NO_RESET_ALL)
3013 /* No need to reset if wasn't SET */
3014 if (gconf->source <= PGC_S_OVERRIDE)
3017 /* Save old value to support transaction abort */
3018 push_old_value(gconf);
3020 switch (gconf->vartype)
3024 struct config_bool *conf = (struct config_bool *) gconf;
3026 if (conf->assign_hook)
3027 if (!(*conf->assign_hook) (conf->reset_val, true,
3029 elog(ERROR, "failed to reset %s", conf->gen.name);
3030 *conf->variable = conf->reset_val;
3031 conf->tentative_val = conf->reset_val;
3032 conf->gen.source = conf->gen.reset_source;
3033 conf->gen.tentative_source = conf->gen.reset_source;
3034 conf->gen.status |= GUC_HAVE_TENTATIVE;
3040 struct config_int *conf = (struct config_int *) gconf;
3042 if (conf->assign_hook)
3043 if (!(*conf->assign_hook) (conf->reset_val, true,
3045 elog(ERROR, "failed to reset %s", conf->gen.name);
3046 *conf->variable = conf->reset_val;
3047 conf->tentative_val = conf->reset_val;
3048 conf->gen.source = conf->gen.reset_source;
3049 conf->gen.tentative_source = conf->gen.reset_source;
3050 conf->gen.status |= GUC_HAVE_TENTATIVE;
3056 struct config_real *conf = (struct config_real *) gconf;
3058 if (conf->assign_hook)
3059 if (!(*conf->assign_hook) (conf->reset_val, true,
3061 elog(ERROR, "failed to reset %s", conf->gen.name);
3062 *conf->variable = conf->reset_val;
3063 conf->tentative_val = conf->reset_val;
3064 conf->gen.source = conf->gen.reset_source;
3065 conf->gen.tentative_source = conf->gen.reset_source;
3066 conf->gen.status |= GUC_HAVE_TENTATIVE;
3072 struct config_string *conf = (struct config_string *) gconf;
3075 if (conf->reset_val == NULL)
3077 /* Nothing to reset to, as yet; so do nothing */
3081 /* We need not strdup here */
3082 str = conf->reset_val;
3084 if (conf->assign_hook)
3088 newstr = (*conf->assign_hook) (str, true,
3091 elog(ERROR, "failed to reset %s", conf->gen.name);
3092 else if (newstr != str)
3095 * See notes in set_config_option about casting
3097 str = (char *) newstr;
3101 set_string_field(conf, conf->variable, str);
3102 set_string_field(conf, &conf->tentative_val, str);
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 if (gconf->flags & GUC_REPORT)
3112 ReportGUCOption(gconf);
3119 * Push previous state during first assignment to a GUC variable
3120 * within a particular transaction.
3122 * We have to be willing to "back-fill" the state stack if the first
3123 * assignment occurs within a subtransaction nested several levels deep.
3124 * This ensures that if an intermediate transaction aborts, it will have
3125 * the proper value available to restore the setting to.
3128 push_old_value(struct config_generic * gconf)
3130 int my_level = GetCurrentTransactionNestLevel();
3133 /* If we're not inside a transaction, do nothing */
3139 /* Done if we already pushed it at this nesting depth */
3140 if (gconf->stack && gconf->stack->nest_level >= my_level)
3144 * We keep all the stack entries in TopTransactionContext so as to
3145 * avoid allocation problems when a subtransaction back-fills stack
3146 * entries for upper transaction levels.
3148 stack = (GucStack *) MemoryContextAlloc(TopTransactionContext,
3151 stack->prev = gconf->stack;
3152 stack->nest_level = stack->prev ? stack->prev->nest_level + 1 : 1;
3153 stack->status = gconf->status;
3154 stack->tentative_source = gconf->tentative_source;
3155 stack->source = gconf->source;
3157 switch (gconf->vartype)
3160 stack->tentative_val.boolval =
3161 ((struct config_bool *) gconf)->tentative_val;
3162 stack->value.boolval =
3163 *((struct config_bool *) gconf)->variable;
3167 stack->tentative_val.intval =
3168 ((struct config_int *) gconf)->tentative_val;
3169 stack->value.intval =
3170 *((struct config_int *) gconf)->variable;
3174 stack->tentative_val.realval =
3175 ((struct config_real *) gconf)->tentative_val;
3176 stack->value.realval =
3177 *((struct config_real *) gconf)->variable;
3181 stack->tentative_val.stringval =
3182 ((struct config_string *) gconf)->tentative_val;
3183 stack->value.stringval =
3184 *((struct config_string *) gconf)->variable;
3188 gconf->stack = stack;
3190 /* Set state to indicate nothing happened yet within this level */
3191 gconf->status = GUC_HAVE_STACK;
3193 /* Ensure we remember to pop at end of xact */
3199 * Do GUC processing at transaction or subtransaction commit or abort.
3202 AtEOXact_GUC(bool isCommit, bool isSubXact)
3207 /* Quick exit if nothing's changed in this transaction */
3211 my_level = GetCurrentTransactionNestLevel();
3212 Assert(isSubXact ? (my_level > 1) : (my_level == 1));
3214 for (i = 0; i < num_guc_variables; i++)
3216 struct config_generic *gconf = guc_variables[i];
3217 int my_status = gconf->status;
3218 GucStack *stack = gconf->stack;
3223 * Skip if nothing's happened to this var in this transaction
3227 Assert(stack == NULL);
3230 /* Assert that we stacked old value before changing it */
3231 Assert(stack != NULL && (my_status & GUC_HAVE_STACK));
3232 /* However, the last change may have been at an outer xact level */
3233 if (stack->nest_level < my_level)
3235 Assert(stack->nest_level == my_level);
3238 * We will pop the stack entry. Start by restoring outer xact status
3239 * (since we may want to modify it below). Be careful to use
3240 * my_status to reference the inner xact status below this point...
3242 gconf->status = stack->status;
3245 * We have two cases:
3247 * If commit and HAVE_TENTATIVE, set actual value to tentative (this
3248 * is to override a SET LOCAL if one occurred later than SET). We keep
3249 * the tentative value and propagate HAVE_TENTATIVE to the parent
3250 * status, allowing the SET's effect to percolate up. (But if we're
3251 * exiting the outermost transaction, we'll drop the HAVE_TENTATIVE
3254 * Otherwise, we have a transaction that aborted or executed only SET
3255 * LOCAL (or no SET at all). In either case it should have no further
3256 * effect, so restore both tentative and actual values from the stack
3260 useTentative = isCommit && (my_status & GUC_HAVE_TENTATIVE) != 0;
3263 switch (gconf->vartype)
3267 struct config_bool *conf = (struct config_bool *) gconf;
3269 GucSource newsource;
3273 newval = conf->tentative_val;
3274 newsource = conf->gen.tentative_source;
3275 conf->gen.status |= GUC_HAVE_TENTATIVE;
3279 newval = stack->value.boolval;
3280 newsource = stack->source;
3281 conf->tentative_val = stack->tentative_val.boolval;
3282 conf->gen.tentative_source = stack->tentative_source;
3285 if (*conf->variable != newval)
3287 if (conf->assign_hook)
3288 if (!(*conf->assign_hook) (newval,
3289 true, PGC_S_OVERRIDE))
3290 elog(LOG, "failed to commit %s",
3292 *conf->variable = newval;
3295 conf->gen.source = newsource;
3300 struct config_int *conf = (struct config_int *) gconf;
3302 GucSource newsource;
3306 newval = conf->tentative_val;
3307 newsource = conf->gen.tentative_source;
3308 conf->gen.status |= GUC_HAVE_TENTATIVE;
3312 newval = stack->value.intval;
3313 newsource = stack->source;
3314 conf->tentative_val = stack->tentative_val.intval;
3315 conf->gen.tentative_source = stack->tentative_source;
3318 if (*conf->variable != newval)
3320 if (conf->assign_hook)
3321 if (!(*conf->assign_hook) (newval,
3322 true, PGC_S_OVERRIDE))
3323 elog(LOG, "failed to commit %s",
3325 *conf->variable = newval;
3328 conf->gen.source = newsource;
3333 struct config_real *conf = (struct config_real *) gconf;
3335 GucSource newsource;
3339 newval = conf->tentative_val;
3340 newsource = conf->gen.tentative_source;
3341 conf->gen.status |= GUC_HAVE_TENTATIVE;
3345 newval = stack->value.realval;
3346 newsource = stack->source;
3347 conf->tentative_val = stack->tentative_val.realval;
3348 conf->gen.tentative_source = stack->tentative_source;
3351 if (*conf->variable != newval)
3353 if (conf->assign_hook)
3354 if (!(*conf->assign_hook) (newval,
3355 true, PGC_S_OVERRIDE))
3356 elog(LOG, "failed to commit %s",
3358 *conf->variable = newval;
3361 conf->gen.source = newsource;
3366 struct config_string *conf = (struct config_string *) gconf;
3368 GucSource newsource;
3372 newval = conf->tentative_val;
3373 newsource = conf->gen.tentative_source;
3374 conf->gen.status |= GUC_HAVE_TENTATIVE;
3378 newval = stack->value.stringval;
3379 newsource = stack->source;
3380 set_string_field(conf, &conf->tentative_val,
3381 stack->tentative_val.stringval);
3382 conf->gen.tentative_source = stack->tentative_source;
3385 if (*conf->variable != newval)
3387 if (conf->assign_hook)
3391 newstr = (*conf->assign_hook) (newval, true,
3394 elog(LOG, "failed to commit %s",
3396 else if (newstr != newval)
3399 * If newval should now be freed, it'll be
3400 * taken care of below.
3402 * See notes in set_config_option about
3405 newval = (char *) newstr;
3409 set_string_field(conf, conf->variable, newval);
3412 conf->gen.source = newsource;
3413 /* Release stacked values if not used anymore */
3414 set_string_field(conf, &stack->value.stringval,
3416 set_string_field(conf, &stack->tentative_val.stringval,
3418 /* Don't store tentative value separately after commit */
3420 set_string_field(conf, &conf->tentative_val, NULL);
3425 /* Finish popping the state stack */
3426 gconf->stack = stack->prev;
3430 * If we're now out of all xact levels, forget TENTATIVE status bit;
3431 * there's nothing tentative about the value anymore.
3435 Assert(gconf->stack == NULL);
3439 /* Report new value if we changed it */
3440 if (changed && (gconf->flags & GUC_REPORT))
3441 ReportGUCOption(gconf);
3445 * If we're now out of all xact levels, we can clear guc_dirty. (Note: we
3446 * cannot reset guc_dirty when exiting a subtransaction, because we know
3447 * that all outer transaction levels will have stacked values to deal
3456 * Start up automatic reporting of changes to variables marked GUC_REPORT.
3457 * This is executed at completion of backend startup.
3460 BeginReportingGUCOptions(void)
3465 * Don't do anything unless talking to an interactive frontend of protocol
3468 if (whereToSendOutput != DestRemote ||
3469 PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
3472 reporting_enabled = true;
3474 /* Transmit initial values of interesting variables */
3475 for (i = 0; i < num_guc_variables; i++)
3477 struct config_generic *conf = guc_variables[i];
3479 if (conf->flags & GUC_REPORT)
3480 ReportGUCOption(conf);
3485 * ReportGUCOption: if appropriate, transmit option value to frontend
3488 ReportGUCOption(struct config_generic * record)
3490 if (reporting_enabled && (record->flags & GUC_REPORT))
3492 char *val = _ShowOption(record, false);
3493 StringInfoData msgbuf;
3495 pq_beginmessage(&msgbuf, 'S');
3496 pq_sendstring(&msgbuf, record->name);
3497 pq_sendstring(&msgbuf, val);
3498 pq_endmessage(&msgbuf);
3506 * Try to interpret value as boolean value. Valid values are: true,
3507 * false, yes, no, on, off, 1, 0. If the string parses okay, return
3508 * true, else false. If result is not NULL, return the parsing result
3512 parse_bool(const char *value, bool *result)
3514 size_t len = strlen(value);
3516 if (pg_strncasecmp(value, "true", len) == 0)
3521 else if (pg_strncasecmp(value, "false", len) == 0)
3527 else if (pg_strncasecmp(value, "yes", len) == 0)
3532 else if (pg_strncasecmp(value, "no", len) == 0)
3538 else if (pg_strcasecmp(value, "on") == 0)
3543 else if (pg_strcasecmp(value, "off") == 0)
3549 else if (pg_strcasecmp(value, "1") == 0)
3554 else if (pg_strcasecmp(value, "0") == 0)
3563 *result = false; /* suppress compiler warning */
3572 * Try to parse value as an integer. The accepted formats are the
3573 * usual decimal, octal, or hexadecimal formats. If the string parses
3574 * okay, return true, else false. If result is not NULL, return the
3578 parse_int(const char *value, int *result, int flags)
3584 val = strtol(value, &endptr, 0);
3586 if ((flags & GUC_UNIT_MEMORY) && endptr != value)
3590 while (*endptr == ' ')
3593 if (strcmp(endptr, "kB") == 0)
3598 else if (strcmp(endptr, "MB") == 0)
3604 else if (strcmp(endptr, "GB") == 0)
3613 switch (flags & GUC_UNIT_MEMORY)
3615 case GUC_UNIT_BLOCKS:
3616 val /= (BLCKSZ / 1024);
3618 case GUC_UNIT_XBLOCKS:
3619 val /= (XLOG_BLCKSZ / 1024);
3625 if ((flags & GUC_UNIT_TIME) && endptr != value)
3629 while (*endptr == ' ')
3632 if (strcmp(endptr, "ms") == 0)
3637 else if (strcmp(endptr, "s") == 0)
3643 else if (strcmp(endptr, "min") == 0)
3649 else if (strcmp(endptr, "h") == 0)
3655 else if (strcmp(endptr, "d") == 0)
3664 switch (flags & GUC_UNIT_TIME)
3676 if (endptr == value || *endptr != '\0' || errno == ERANGE
3677 #ifdef HAVE_LONG_INT_64
3678 /* if long > 32 bits, check for overflow of int4 */
3679 || val != (long) ((int32) val)
3684 *result = 0; /* suppress compiler warning */
3688 *result = (int) val;
3695 * Try to parse value as a floating point constant in the usual
3696 * format. If the value parsed okay return true, else false. If
3697 * result is not NULL, return the semantic value there.
3700 parse_real(const char *value, double *result)
3706 val = strtod(value, &endptr);
3707 if (endptr == value || *endptr != '\0' || errno == ERANGE)
3710 *result = 0; /* suppress compiler warning */
3720 * Call a GucStringAssignHook function, being careful to free the
3721 * "newval" string if the hook ereports.
3723 * This is split out of set_config_option just to avoid the "volatile"
3724 * qualifiers that would otherwise have to be plastered all over.
3727 call_string_assign_hook(GucStringAssignHook assign_hook,
3728 char *newval, bool doit, GucSource source)
3734 result = (*assign_hook) (newval, doit, source);
3748 * Sets option `name' to given value. The value should be a string
3749 * which is going to be parsed and converted to the appropriate data
3750 * type. The context and source parameters indicate in which context this
3751 * function is being called so it can apply the access restrictions
3754 * If value is NULL, set the option to its default value. If the
3755 * parameter changeVal is false then don't really set the option but do all
3756 * the checks to see if it would work.
3758 * If there is an error (non-existing option, invalid value) then an
3759 * ereport(ERROR) is thrown *unless* this is called in a context where we
3760 * don't want to ereport (currently, startup or SIGHUP config file reread).
3761 * In that case we write a suitable error message via ereport(DEBUG) and
3762 * return false. This is working around the deficiencies in the ereport
3763 * mechanism, so don't blame me. In all other cases, the function
3764 * returns true, including cases where the input is valid but we chose
3765 * not to apply it because of context or source-priority considerations.
3767 * See also SetConfigOption for an external interface.
3770 set_config_option(const char *name, const char *value,
3771 GucContext context, GucSource source,
3772 bool isLocal, bool changeVal)
3774 struct config_generic *record;
3778 if (context == PGC_SIGHUP || source == PGC_S_DEFAULT)
3781 * To avoid cluttering the log, only the postmaster bleats loudly
3782 * about problems with the config file.
3784 elevel = IsUnderPostmaster ? DEBUG2 : LOG;
3786 else if (source == PGC_S_DATABASE || source == PGC_S_USER)
3791 record = find_option(name, elevel);
3795 (errcode(ERRCODE_UNDEFINED_OBJECT),
3796 errmsg("unrecognized configuration parameter \"%s\"", name)));
3801 * Check if the option can be set at this time. See guc.h for the precise
3802 * rules. Note that we don't want to throw errors if we're in the SIGHUP
3803 * context. In that case we just ignore the attempt and return true.
3805 switch (record->context)
3808 if (context == PGC_SIGHUP)
3810 if (context != PGC_INTERNAL)
3813 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3814 errmsg("parameter \"%s\" cannot be changed",
3819 case PGC_POSTMASTER:
3820 if (context == PGC_SIGHUP)
3822 if (changeVal && !is_newvalue_equal(record, value))
3824 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3825 errmsg("parameter \"%s\" cannot be changed after server start; configuration file change ignored",
3830 if (context != PGC_POSTMASTER)
3833 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3834 errmsg("parameter \"%s\" cannot be changed after server start",
3840 if (context != PGC_SIGHUP && context != PGC_POSTMASTER)
3843 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3844 errmsg("parameter \"%s\" cannot be changed now",
3850 * Hmm, the idea of the SIGHUP context is "ought to be global, but
3851 * can be changed after postmaster start". But there's nothing
3852 * that prevents a crafty administrator from sending SIGHUP
3853 * signals to individual backends only.
3857 if (context == PGC_SIGHUP)
3860 * If a PGC_BACKEND parameter is changed in the config file,
3861 * we want to accept the new value in the postmaster (whence
3862 * it will propagate to subsequently-started backends), but
3863 * ignore it in existing backends. This is a tad klugy, but
3864 * necessary because we don't re-read the config file during
3867 if (IsUnderPostmaster)
3870 else if (context != PGC_BACKEND && context != PGC_POSTMASTER)
3873 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3874 errmsg("parameter \"%s\" cannot be set after connection start",
3880 if (context == PGC_USERSET || context == PGC_BACKEND)
3883 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3884 errmsg("permission denied to set parameter \"%s\"",
3895 * Should we set reset/stacked values? (If so, the behavior is not
3898 makeDefault = changeVal && (source <= PGC_S_OVERRIDE) && (value != NULL);
3901 * Ignore attempted set if overridden by previously processed setting.
3902 * However, if changeVal is false then plow ahead anyway since we are
3903 * trying to find out if the value is potentially good, not actually use
3904 * it. Also keep going if makeDefault is true, since we may want to set
3905 * the reset/stacked values even if we can't set the variable itself.
3907 if (record->source > source)
3909 if (changeVal && !makeDefault)
3911 elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
3919 * Evaluate value and set variable.
3921 switch (record->vartype)
3925 struct config_bool *conf = (struct config_bool *) record;
3930 if (!parse_bool(value, &newval))
3933 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3934 errmsg("parameter \"%s\" requires a Boolean value",
3941 newval = conf->reset_val;
3942 source = conf->gen.reset_source;
3945 if (conf->assign_hook)
3946 if (!(*conf->assign_hook) (newval, changeVal, source))
3949 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3950 errmsg("invalid value for parameter \"%s\": %d",
3951 name, (int) newval)));
3955 if (changeVal || makeDefault)
3957 /* Save old value to support transaction abort */
3959 push_old_value(&conf->gen);
3962 *conf->variable = newval;
3963 conf->gen.source = source;
3969 if (conf->gen.reset_source <= source)
3971 conf->reset_val = newval;
3972 conf->gen.reset_source = source;
3974 for (stack = conf->gen.stack; stack; stack = stack->prev)
3976 if (stack->source <= source)
3978 stack->value.boolval = newval;
3979 stack->source = source;
3985 conf->gen.status |= GUC_HAVE_LOCAL;
3990 conf->tentative_val = newval;
3991 conf->gen.tentative_source = source;
3992 conf->gen.status |= GUC_HAVE_TENTATIVE;
4001 struct config_int *conf = (struct config_int *) record;
4006 if (!parse_int(value, &newval, conf->gen.flags))
4009 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4010 errmsg("parameter \"%s\" requires an integer value",
4014 if (newval < conf->min || newval > conf->max)
4017 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4018 errmsg("%d is outside the valid range for parameter \"%s\" (%d .. %d)",
4019 newval, name, conf->min, conf->max)));
4025 newval = conf->reset_val;
4026 source = conf->gen.reset_source;
4029 if (conf->assign_hook)
4030 if (!(*conf->assign_hook) (newval, changeVal, source))
4033 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4034 errmsg("invalid value for parameter \"%s\": %d",
4039 if (changeVal || makeDefault)
4041 /* Save old value to support transaction abort */
4043 push_old_value(&conf->gen);
4046 *conf->variable = newval;
4047 conf->gen.source = source;
4053 if (conf->gen.reset_source <= source)
4055 conf->reset_val = newval;
4056 conf->gen.reset_source = source;
4058 for (stack = conf->gen.stack; stack; stack = stack->prev)
4060 if (stack->source <= source)
4062 stack->value.intval = newval;
4063 stack->source = source;
4069 conf->gen.status |= GUC_HAVE_LOCAL;
4074 conf->tentative_val = newval;
4075 conf->gen.tentative_source = source;
4076 conf->gen.status |= GUC_HAVE_TENTATIVE;
4085 struct config_real *conf = (struct config_real *) record;
4090 if (!parse_real(value, &newval))
4093 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4094 errmsg("parameter \"%s\" requires a numeric value",
4098 if (newval < conf->min || newval > conf->max)
4101 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4102 errmsg("%g is outside the valid range for parameter \"%s\" (%g .. %g)",
4103 newval, name, conf->min, conf->max)));
4109 newval = conf->reset_val;
4110 source = conf->gen.reset_source;
4113 if (conf->assign_hook)
4114 if (!(*conf->assign_hook) (newval, changeVal, source))
4117 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4118 errmsg("invalid value for parameter \"%s\": %g",
4123 if (changeVal || makeDefault)
4125 /* Save old value to support transaction abort */
4127 push_old_value(&conf->gen);
4130 *conf->variable = newval;
4131 conf->gen.source = source;
4137 if (conf->gen.reset_source <= source)
4139 conf->reset_val = newval;
4140 conf->gen.reset_source = source;
4142 for (stack = conf->gen.stack; stack; stack = stack->prev)
4144 if (stack->source <= source)
4146 stack->value.realval = newval;
4147 stack->source = source;
4153 conf->gen.status |= GUC_HAVE_LOCAL;
4158 conf->tentative_val = newval;
4159 conf->gen.tentative_source = source;
4160 conf->gen.status |= GUC_HAVE_TENTATIVE;
4169 struct config_string *conf = (struct config_string *) record;
4174 newval = guc_strdup(elevel, value);
4179 * The only sort of "parsing" check we need to do is apply
4180 * truncation if GUC_IS_NAME.
4182 if (conf->gen.flags & GUC_IS_NAME)
4183 truncate_identifier(newval, strlen(newval), true);
4185 else if (conf->reset_val)
4188 * We could possibly avoid strdup here, but easier to make
4189 * this case work the same as the normal assignment case.
4191 newval = guc_strdup(elevel, conf->reset_val);
4194 source = conf->gen.reset_source;
4198 /* Nothing to reset to, as yet; so do nothing */
4202 if (conf->assign_hook)
4204 const char *hookresult;
4207 * If the hook ereports, we have to make sure we free
4208 * newval, else it will be a permanent memory leak.
4210 hookresult = call_string_assign_hook(conf->assign_hook,
4214 if (hookresult == NULL)
4218 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4219 errmsg("invalid value for parameter \"%s\": \"%s\"",
4220 name, value ? value : "")));
4223 else if (hookresult != newval)
4228 * Having to cast away const here is annoying, but the
4229 * alternative is to declare assign_hooks as returning
4230 * char*, which would mean they'd have to cast away
4231 * const, or as both taking and returning char*, which
4232 * doesn't seem attractive either --- we don't want
4233 * them to scribble on the passed str.
4235 newval = (char *) hookresult;
4239 if (changeVal || makeDefault)
4241 /* Save old value to support transaction abort */
4243 push_old_value(&conf->gen);
4246 set_string_field(conf, conf->variable, newval);
4247 conf->gen.source = source;
4253 if (conf->gen.reset_source <= source)
4255 set_string_field(conf, &conf->reset_val, newval);
4256 conf->gen.reset_source = source;
4258 for (stack = conf->gen.stack; stack; stack = stack->prev)
4260 if (stack->source <= source)
4262 set_string_field(conf, &stack->value.stringval,
4264 stack->source = source;
4267 /* Perhaps we didn't install newval anywhere */
4268 if (!string_field_used(conf, newval))
4273 conf->gen.status |= GUC_HAVE_LOCAL;
4278 set_string_field(conf, &conf->tentative_val, newval);
4279 conf->gen.tentative_source = source;
4280 conf->gen.status |= GUC_HAVE_TENTATIVE;
4290 if (changeVal && (record->flags & GUC_REPORT))
4291 ReportGUCOption(record);
4298 * Set a config option to the given value. See also set_config_option,
4299 * this is just the wrapper to be called from outside GUC. NB: this
4300 * is used only for non-transactional operations.
4303 SetConfigOption(const char *name, const char *value,
4304 GucContext context, GucSource source)
4306 (void) set_config_option(name, value, context, source, false, true);
4312 * Fetch the current value of the option `name'. If the option doesn't exist,
4313 * throw an ereport and don't return.
4315 * The string is *not* allocated for modification and is really only
4316 * valid until the next call to configuration related functions.
4319 GetConfigOption(const char *name)
4321 struct config_generic *record;
4322 static char buffer[256];
4324 record = find_option(name, ERROR);
4327 (errcode(ERRCODE_UNDEFINED_OBJECT),
4328 errmsg("unrecognized configuration parameter \"%s\"", name)));
4329 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
4331 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4332 errmsg("must be superuser to examine \"%s\"", name)));
4334 switch (record->vartype)
4337 return *((struct config_bool *) record)->variable ? "on" : "off";
4340 snprintf(buffer, sizeof(buffer), "%d",
4341 *((struct config_int *) record)->variable);
4345 snprintf(buffer, sizeof(buffer), "%g",
4346 *((struct config_real *) record)->variable);
4350 return *((struct config_string *) record)->variable;
4356 * Get the RESET value associated with the given option.
4359 GetConfigOptionResetString(const char *name)
4361 struct config_generic *record;
4362 static char buffer[256];
4364 record = find_option(name, ERROR);
4367 (errcode(ERRCODE_UNDEFINED_OBJECT),
4368 errmsg("unrecognized configuration parameter \"%s\"", name)));
4369 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
4371 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4372 errmsg("must be superuser to examine \"%s\"", name)));
4374 switch (record->vartype)
4377 return ((struct config_bool *) record)->reset_val ? "on" : "off";
4380 snprintf(buffer, sizeof(buffer), "%d",
4381 ((struct config_int *) record)->reset_val);
4385 snprintf(buffer, sizeof(buffer), "%g",
4386 ((struct config_real *) record)->reset_val);
4390 return ((struct config_string *) record)->reset_val;
4396 * Detect whether the given configuration option can only be set by
4400 IsSuperuserConfigOption(const char *name)
4402 struct config_generic *record;
4404 record = find_option(name, ERROR);
4405 /* On an unrecognized name, don't error, just return false. */
4408 return (record->context == PGC_SUSET);
4413 * flatten_set_variable_args
4414 * Given a parsenode List as emitted by the grammar for SET,
4415 * convert to the flat string representation used by GUC.
4417 * We need to be told the name of the variable the args are for, because
4418 * the flattening rules vary (ugh).
4420 * The result is NULL if input is NIL (ie, SET ... TO DEFAULT), otherwise
4421 * a palloc'd string.
4424 flatten_set_variable_args(const char *name, List *args)
4426 struct config_generic *record;
4432 * Fast path if just DEFAULT. We do not check the variable name in this
4433 * case --- necessary for RESET ALL to work correctly.
4438 /* Else get flags for the variable */
4439 record = find_option(name, ERROR);
4442 (errcode(ERRCODE_UNDEFINED_OBJECT),
4443 errmsg("unrecognized configuration parameter \"%s\"", name)));
4445 flags = record->flags;
4447 /* Complain if list input and non-list variable */
4448 if ((flags & GUC_LIST_INPUT) == 0 &&
4449 list_length(args) != 1)
4451 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4452 errmsg("SET %s takes only one argument", name)));
4454 initStringInfo(&buf);
4458 A_Const *arg = (A_Const *) lfirst(l);
4461 if (l != list_head(args))
4462 appendStringInfo(&buf, ", ");
4464 if (!IsA(arg, A_Const))
4465 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
4467 switch (nodeTag(&arg->val))
4470 appendStringInfo(&buf, "%ld", intVal(&arg->val));
4473 /* represented as a string, so just copy it */
4474 appendStringInfoString(&buf, strVal(&arg->val));
4477 val = strVal(&arg->val);
4478 if (arg->typename != NULL)
4481 * Must be a ConstInterval argument for TIME ZONE. Coerce
4482 * to interval and back to normalize the value and account
4489 DirectFunctionCall3(interval_in,
4490 CStringGetDatum(val),
4491 ObjectIdGetDatum(InvalidOid),
4492 Int32GetDatum(arg->typename->typmod));
4495 DatumGetCString(DirectFunctionCall1(interval_out,
4497 appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
4502 * Plain string literal or identifier. For quote mode,
4503 * quote it if it's not a vanilla identifier.
4505 if (flags & GUC_LIST_QUOTE)
4506 appendStringInfoString(&buf, quote_identifier(val));
4508 appendStringInfoString(&buf, val);
4512 elog(ERROR, "unrecognized node type: %d",
4513 (int) nodeTag(&arg->val));
4526 SetPGVariable(const char *name, List *args, bool is_local)
4528 char *argstring = flatten_set_variable_args(name, args);
4530 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
4531 set_config_option(name,
4533 (superuser() ? PGC_SUSET : PGC_USERSET),
4540 * SET command wrapped as a SQL callable function.
4543 set_config_by_name(PG_FUNCTION_ARGS)
4551 if (PG_ARGISNULL(0))
4553 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
4554 errmsg("SET requires parameter name")));
4556 /* Get the GUC variable name */
4557 name = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(0)));
4559 /* Get the desired value or set to NULL for a reset request */
4560 if (PG_ARGISNULL(1))
4563 value = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(1)));
4566 * Get the desired state of is_local. Default to false if provided value
4569 if (PG_ARGISNULL(2))
4572 is_local = PG_GETARG_BOOL(2);
4574 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
4575 set_config_option(name,
4577 (superuser() ? PGC_SUSET : PGC_USERSET),
4582 /* get the new current value */
4583 new_value = GetConfigOptionByName(name, NULL);
4585 /* Convert return string to text */
4586 result_text = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(new_value)));
4589 PG_RETURN_TEXT_P(result_text);
4593 define_custom_variable(struct config_generic * variable)
4595 const char *name = variable->name;
4596 const char **nameAddr = &name;
4598 struct config_string *pHolder;
4599 struct config_generic **res = (struct config_generic **) bsearch(
4601 (void *) guc_variables,
4603 sizeof(struct config_generic *),
4608 add_guc_variable(variable, ERROR);
4613 * This better be a placeholder
4615 if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
4617 (errcode(ERRCODE_INTERNAL_ERROR),
4618 errmsg("attempt to redefine parameter \"%s\"", name)));
4620 Assert((*res)->vartype == PGC_STRING);
4621 pHolder = (struct config_string *) * res;
4623 /* We have the same name, no sorting is necessary */
4626 value = *pHolder->variable;
4629 * Assign the string value stored in the placeholder to the real variable.
4631 * XXX this is not really good enough --- it should be a nontransactional
4632 * assignment, since we don't want it to roll back if the current xact
4635 set_config_option(name, value,
4636 pHolder->gen.context, pHolder->gen.source,
4640 * Free up as much as we conveniently can of the placeholder structure
4641 * (this neglects any stack items...)
4643 set_string_field(pHolder, pHolder->variable, NULL);
4644 set_string_field(pHolder, &pHolder->reset_val, NULL);
4645 set_string_field(pHolder, &pHolder->tentative_val, NULL);
4651 init_custom_variable(struct config_generic * gen,
4653 const char *short_desc,
4654 const char *long_desc,
4656 enum config_type type)
4658 gen->name = guc_strdup(ERROR, name);
4659 gen->context = context;
4660 gen->group = CUSTOM_OPTIONS;
4661 gen->short_desc = short_desc;
4662 gen->long_desc = long_desc;
4663 gen->vartype = type;
4667 DefineCustomBoolVariable(const char *name,
4668 const char *short_desc,
4669 const char *long_desc,
4672 GucBoolAssignHook assign_hook,
4673 GucShowHook show_hook)
4675 size_t sz = sizeof(struct config_bool);
4676 struct config_bool *var = (struct config_bool *) guc_malloc(ERROR, sz);
4679 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_BOOL);
4681 var->variable = valueAddr;
4682 var->reset_val = *valueAddr;
4683 var->assign_hook = assign_hook;
4684 var->show_hook = show_hook;
4685 define_custom_variable(&var->gen);
4689 DefineCustomIntVariable(const char *name,
4690 const char *short_desc,
4691 const char *long_desc,
4696 GucIntAssignHook assign_hook,
4697 GucShowHook show_hook)
4699 size_t sz = sizeof(struct config_int);
4700 struct config_int *var = (struct config_int *) guc_malloc(ERROR, sz);
4703 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_INT);
4705 var->variable = valueAddr;
4706 var->reset_val = *valueAddr;
4707 var->min = minValue;
4708 var->max = maxValue;
4709 var->assign_hook = assign_hook;
4710 var->show_hook = show_hook;
4711 define_custom_variable(&var->gen);
4715 DefineCustomRealVariable(const char *name,
4716 const char *short_desc,
4717 const char *long_desc,
4722 GucRealAssignHook assign_hook,
4723 GucShowHook show_hook)
4725 size_t sz = sizeof(struct config_real);
4726 struct config_real *var = (struct config_real *) guc_malloc(ERROR, sz);
4729 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_REAL);
4731 var->variable = valueAddr;
4732 var->reset_val = *valueAddr;
4733 var->min = minValue;
4734 var->max = maxValue;
4735 var->assign_hook = assign_hook;
4736 var->show_hook = show_hook;
4737 define_custom_variable(&var->gen);
4741 DefineCustomStringVariable(const char *name,
4742 const char *short_desc,
4743 const char *long_desc,
4746 GucStringAssignHook assign_hook,
4747 GucShowHook show_hook)
4749 size_t sz = sizeof(struct config_string);
4750 struct config_string *var = (struct config_string *) guc_malloc(ERROR, sz);
4753 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_STRING);
4755 var->variable = valueAddr;
4756 var->reset_val = *valueAddr;
4757 var->assign_hook = assign_hook;
4758 var->show_hook = show_hook;
4759 define_custom_variable(&var->gen);
4763 EmitWarningsOnPlaceholders(const char *className)
4765 struct config_generic **vars = guc_variables;
4766 struct config_generic **last = vars + num_guc_variables;
4768 int nameLen = strlen(className);
4772 struct config_generic *var = *vars++;
4774 if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
4775 strncmp(className, var->name, nameLen) == 0 &&
4776 var->name[nameLen] == GUC_QUALIFIER_SEPARATOR)
4779 (errcode(ERRCODE_UNDEFINED_OBJECT),
4780 errmsg("unrecognized configuration parameter \"%s\"", var->name)));
4790 GetPGVariable(const char *name, DestReceiver *dest)
4792 if (pg_strcasecmp(name, "all") == 0)
4793 ShowAllGUCConfig(dest);
4795 ShowGUCConfigOption(name, dest);
4799 GetPGVariableResultDesc(const char *name)
4803 if (pg_strcasecmp(name, "all") == 0)
4805 /* need a tuple descriptor representing three TEXT columns */
4806 tupdesc = CreateTemplateTupleDesc(3, false);
4807 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
4809 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
4811 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
4817 const char *varname;
4819 /* Get the canonical spelling of name */
4820 (void) GetConfigOptionByName(name, &varname);
4822 /* need a tuple descriptor representing a single TEXT column */
4823 tupdesc = CreateTemplateTupleDesc(1, false);
4824 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
4834 ResetPGVariable(const char *name)
4836 if (pg_strcasecmp(name, "all") == 0)
4839 set_config_option(name,
4841 (superuser() ? PGC_SUSET : PGC_USERSET),
4852 ShowGUCConfigOption(const char *name, DestReceiver *dest)
4854 TupOutputState *tstate;
4856 const char *varname;
4859 /* Get the value and canonical spelling of name */
4860 value = GetConfigOptionByName(name, &varname);
4862 /* need a tuple descriptor representing a single TEXT column */
4863 tupdesc = CreateTemplateTupleDesc(1, false);
4864 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
4867 /* prepare for projection of tuples */
4868 tstate = begin_tup_output_tupdesc(dest, tupdesc);
4871 do_text_output_oneline(tstate, value);
4873 end_tup_output(tstate);
4880 ShowAllGUCConfig(DestReceiver *dest)
4882 bool am_superuser = superuser();
4884 TupOutputState *tstate;
4888 /* need a tuple descriptor representing three TEXT columns */
4889 tupdesc = CreateTemplateTupleDesc(3, false);
4890 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
4892 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
4894 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
4898 /* prepare for projection of tuples */
4899 tstate = begin_tup_output_tupdesc(dest, tupdesc);
4901 for (i = 0; i < num_guc_variables; i++)
4903 struct config_generic *conf = guc_variables[i];
4905 if ((conf->flags & GUC_NO_SHOW_ALL) ||
4906 ((conf->flags & GUC_SUPERUSER_ONLY) && !am_superuser))
4909 /* assign to the values array */
4910 values[0] = (char *) conf->name;
4911 values[1] = _ShowOption(conf, true);
4912 values[2] = (char *) conf->short_desc;
4914 /* send it to dest */
4915 do_tup_output(tstate, values);
4918 if (values[1] != NULL)
4922 end_tup_output(tstate);
4926 * Return GUC variable value by name; optionally return canonical
4927 * form of name. Return value is palloc'd.
4930 GetConfigOptionByName(const char *name, const char **varname)
4932 struct config_generic *record;
4934 record = find_option(name, ERROR);
4937 (errcode(ERRCODE_UNDEFINED_OBJECT),
4938 errmsg("unrecognized configuration parameter \"%s\"", name)));
4939 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
4941 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4942 errmsg("must be superuser to examine \"%s\"", name)));
4945 *varname = record->name;
4947 return _ShowOption(record, true);
4951 * Return GUC variable value by variable number; optionally return canonical
4952 * form of name. Return value is palloc'd.
4955 GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
4958 struct config_generic *conf;
4960 /* check requested variable number valid */
4961 Assert((varnum >= 0) && (varnum < num_guc_variables));
4963 conf = guc_variables[varnum];
4967 if ((conf->flags & GUC_NO_SHOW_ALL) ||
4968 ((conf->flags & GUC_SUPERUSER_ONLY) && !superuser()))
4974 /* first get the generic attributes */
4977 values[0] = conf->name;
4979 /* setting : use _ShowOption in order to avoid duplicating the logic */
4980 values[1] = _ShowOption(conf, false);
4983 if (conf->vartype == PGC_INT)
4987 switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
4992 case GUC_UNIT_BLOCKS:
4993 snprintf(buf, sizeof(buf), "%dkB", BLCKSZ / 1024);
4996 case GUC_UNIT_XBLOCKS:
4997 snprintf(buf, sizeof(buf), "%dkB", XLOG_BLCKSZ / 1024);
5018 values[3] = config_group_names[conf->group];
5021 values[4] = conf->short_desc;
5024 values[5] = conf->long_desc;
5027 values[6] = GucContext_Names[conf->context];
5030 values[7] = config_type_names[conf->vartype];
5033 values[8] = GucSource_Names[conf->source];
5035 /* now get the type specifc attributes */
5036 switch (conf->vartype)
5050 struct config_int *lconf = (struct config_int *) conf;
5053 snprintf(buffer, sizeof(buffer), "%d", lconf->min);
5054 values[9] = pstrdup(buffer);
5057 snprintf(buffer, sizeof(buffer), "%d", lconf->max);
5058 values[10] = pstrdup(buffer);
5064 struct config_real *lconf = (struct config_real *) conf;
5067 snprintf(buffer, sizeof(buffer), "%g", lconf->min);
5068 values[9] = pstrdup(buffer);
5071 snprintf(buffer, sizeof(buffer), "%g", lconf->max);
5072 values[10] = pstrdup(buffer);
5089 * should never get here, but in case we do, set 'em to NULL
5103 * Return the total number of GUC variables
5106 GetNumConfigOptions(void)
5108 return num_guc_variables;
5112 * show_config_by_name - equiv to SHOW X command but implemented as
5116 show_config_by_name(PG_FUNCTION_ARGS)
5122 /* Get the GUC variable name */
5123 varname = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(0)));
5126 varval = GetConfigOptionByName(varname, NULL);
5128 /* Convert to text */
5129 result_text = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(varval)));
5132 PG_RETURN_TEXT_P(result_text);
5136 * show_all_settings - equiv to SHOW ALL command but implemented as
5139 #define NUM_PG_SETTINGS_ATTS 11
5142 show_all_settings(PG_FUNCTION_ARGS)
5144 FuncCallContext *funcctx;
5148 AttInMetadata *attinmeta;
5149 MemoryContext oldcontext;
5151 /* stuff done only on the first call of the function */
5152 if (SRF_IS_FIRSTCALL())
5154 /* create a function context for cross-call persistence */
5155 funcctx = SRF_FIRSTCALL_INIT();
5158 * switch to memory context appropriate for multiple function calls
5160 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
5163 * need a tuple descriptor representing NUM_PG_SETTINGS_ATTS columns
5164 * of the appropriate types
5166 tupdesc = CreateTemplateTupleDesc(NUM_PG_SETTINGS_ATTS, false);
5167 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
5169 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
5171 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "unit",
5173 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "category",
5175 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "short_desc",
5177 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "extra_desc",
5179 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "context",
5181 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "vartype",
5183 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "source",
5185 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "min_val",
5187 TupleDescInitEntry(tupdesc, (AttrNumber) 11, "max_val",
5191 * Generate attribute metadata needed later to produce tuples from raw
5194 attinmeta = TupleDescGetAttInMetadata(tupdesc);
5195 funcctx->attinmeta = attinmeta;
5197 /* total number of tuples to be returned */
5198 funcctx->max_calls = GetNumConfigOptions();
5200 MemoryContextSwitchTo(oldcontext);
5203 /* stuff done on every call of the function */
5204 funcctx = SRF_PERCALL_SETUP();
5206 call_cntr = funcctx->call_cntr;
5207 max_calls = funcctx->max_calls;
5208 attinmeta = funcctx->attinmeta;
5210 if (call_cntr < max_calls) /* do when there is more left to send */
5212 char *values[NUM_PG_SETTINGS_ATTS];
5218 * Get the next visible GUC variable name and value
5222 GetConfigOptionByNum(call_cntr, (const char **) values, &noshow);
5225 /* bump the counter and get the next config setting */
5226 call_cntr = ++funcctx->call_cntr;
5228 /* make sure we haven't gone too far now */
5229 if (call_cntr >= max_calls)
5230 SRF_RETURN_DONE(funcctx);
5235 tuple = BuildTupleFromCStrings(attinmeta, values);
5237 /* make the tuple into a datum */
5238 result = HeapTupleGetDatum(tuple);
5240 SRF_RETURN_NEXT(funcctx, result);
5244 /* do when there is no more left */
5245 SRF_RETURN_DONE(funcctx);
5250 _ShowOption(struct config_generic * record, bool use_units)
5255 switch (record->vartype)
5259 struct config_bool *conf = (struct config_bool *) record;
5261 if (conf->show_hook)
5262 val = (*conf->show_hook) ();
5264 val = *conf->variable ? "on" : "off";
5270 struct config_int *conf = (struct config_int *) record;
5272 if (conf->show_hook)
5273 val = (*conf->show_hook) ();
5277 int result = *conf->variable;
5279 if (use_units && result > 0 && (record->flags & GUC_UNIT_MEMORY))
5281 switch (record->flags & GUC_UNIT_MEMORY)
5283 case GUC_UNIT_BLOCKS:
5284 result *= BLCKSZ / 1024;
5286 case GUC_UNIT_XBLOCKS:
5287 result *= XLOG_BLCKSZ / 1024;
5291 if (result % KB_PER_GB == 0)
5293 result /= KB_PER_GB;
5296 else if (result % KB_PER_MB == 0)
5298 result /= KB_PER_MB;
5306 else if (use_units && result > 0 && (record->flags & GUC_UNIT_TIME))
5308 switch (record->flags & GUC_UNIT_TIME)
5314 result *= MS_PER_MIN;
5318 if (result % MS_PER_D == 0)
5323 else if (result % MS_PER_H == 0)
5328 else if (result % MS_PER_MIN == 0)
5330 result /= MS_PER_MIN;
5331 strcpy(unit, "min");
5333 else if (result % MS_PER_S == 0)
5346 snprintf(buffer, sizeof(buffer), "%d%s",
5347 (int) result, unit);
5355 struct config_real *conf = (struct config_real *) record;
5357 if (conf->show_hook)
5358 val = (*conf->show_hook) ();
5361 snprintf(buffer, sizeof(buffer), "%g",
5370 struct config_string *conf = (struct config_string *) record;
5372 if (conf->show_hook)
5373 val = (*conf->show_hook) ();
5374 else if (*conf->variable && **conf->variable)
5375 val = *conf->variable;
5382 /* just to keep compiler quiet */
5387 return pstrdup(val);
5392 is_newvalue_equal(struct config_generic * record, const char *newvalue)
5394 switch (record->vartype)
5398 struct config_bool *conf = (struct config_bool *) record;
5401 return parse_bool(newvalue, &newval) && *conf->variable == newval;
5405 struct config_int *conf = (struct config_int *) record;
5408 return parse_int(newvalue, &newval, record->flags) && *conf->variable == newval;
5412 struct config_real *conf = (struct config_real *) record;
5415 return parse_real(newvalue, &newval) && *conf->variable == newval;
5419 struct config_string *conf = (struct config_string *) record;
5421 return strcmp(*conf->variable, newvalue) == 0;
5432 * This routine dumps out all non-default GUC options into a binary
5433 * file that is read by all exec'ed backends. The format is:
5435 * variable name, string, null terminated
5436 * variable value, string, null terminated
5437 * variable source, integer
5440 write_nondefault_variables(GucContext context)
5446 Assert(context == PGC_POSTMASTER || context == PGC_SIGHUP);
5448 elevel = (context == PGC_SIGHUP) ? LOG : ERROR;
5453 fp = AllocateFile(CONFIG_EXEC_PARAMS_NEW, "w");
5457 (errcode_for_file_access(),
5458 errmsg("could not write to file \"%s\": %m",
5459 CONFIG_EXEC_PARAMS_NEW)));
5463 for (i = 0; i < num_guc_variables; i++)
5465 struct config_generic *gconf = guc_variables[i];
5467 if (gconf->source != PGC_S_DEFAULT)
5469 fprintf(fp, "%s", gconf->name);
5472 switch (gconf->vartype)
5476 struct config_bool *conf = (struct config_bool *) gconf;
5478 if (*conf->variable == 0)
5479 fprintf(fp, "false");
5481 fprintf(fp, "true");
5487 struct config_int *conf = (struct config_int *) gconf;
5489 fprintf(fp, "%d", *conf->variable);
5495 struct config_real *conf = (struct config_real *) gconf;
5497 /* Could lose precision here? */
5498 fprintf(fp, "%f", *conf->variable);
5504 struct config_string *conf = (struct config_string *) gconf;
5506 fprintf(fp, "%s", *conf->variable);
5513 fwrite(&gconf->source, sizeof(gconf->source), 1, fp);
5520 (errcode_for_file_access(),
5521 errmsg("could not write to file \"%s\": %m",
5522 CONFIG_EXEC_PARAMS_NEW)));
5527 * Put new file in place. This could delay on Win32, but we don't hold
5528 * any exclusive locks.
5530 rename(CONFIG_EXEC_PARAMS_NEW, CONFIG_EXEC_PARAMS);
5535 * Read string, including null byte from file
5537 * Return NULL on EOF and nothing read
5540 read_string_with_null(FILE *fp)
5549 if ((ch = fgetc(fp)) == EOF)
5554 elog(FATAL, "invalid format of exec config params file");
5557 str = guc_malloc(FATAL, maxlen);
5558 else if (i == maxlen)
5559 str = guc_realloc(FATAL, str, maxlen *= 2);
5568 * This routine loads a previous postmaster dump of its non-default
5572 read_nondefault_variables(void)
5582 fp = AllocateFile(CONFIG_EXEC_PARAMS, "r");
5585 /* File not found is fine */
5586 if (errno != ENOENT)
5588 (errcode_for_file_access(),
5589 errmsg("could not read from file \"%s\": %m",
5590 CONFIG_EXEC_PARAMS)));
5596 struct config_generic *record;
5598 if ((varname = read_string_with_null(fp)) == NULL)
5601 if ((record = find_option(varname, FATAL)) == NULL)
5602 elog(FATAL, "failed to locate variable %s in exec config params file", varname);
5603 if ((varvalue = read_string_with_null(fp)) == NULL)
5604 elog(FATAL, "invalid format of exec config params file");
5605 if (fread(&varsource, sizeof(varsource), 1, fp) == 0)
5606 elog(FATAL, "invalid format of exec config params file");
5608 (void) set_config_option(varname, varvalue, record->context,
5609 varsource, false, true);
5616 #endif /* EXEC_BACKEND */
5620 * A little "long argument" simulation, although not quite GNU
5621 * compliant. Takes a string of the form "some-option=some value" and
5622 * returns name = "some_option" and value = "some value" in malloc'ed
5623 * storage. Note that '-' is converted to '_' in the option name. If
5624 * there is no '=' in the input string then value will be NULL.
5627 ParseLongOption(const char *string, char **name, char **value)
5636 equal_pos = strcspn(string, "=");
5638 if (string[equal_pos] == '=')
5640 *name = guc_malloc(FATAL, equal_pos + 1);
5641 strncpy(*name, string, equal_pos);
5642 (*name)[equal_pos] = '\0';
5644 *value = guc_strdup(FATAL, &string[equal_pos + 1]);
5648 /* no equal sign in string */
5649 *name = guc_strdup(FATAL, string);
5653 for (cp = *name; *cp; cp++)
5660 * Handle options fetched from pg_database.datconfig or pg_authid.rolconfig.
5661 * The array parameter must be an array of TEXT (it must not be NULL).
5664 ProcessGUCArray(ArrayType *array, GucSource source)
5668 Assert(array != NULL);
5669 Assert(ARR_ELEMTYPE(array) == TEXTOID);
5670 Assert(ARR_NDIM(array) == 1);
5671 Assert(ARR_LBOUND(array)[0] == 1);
5672 Assert(source == PGC_S_DATABASE || source == PGC_S_USER);
5674 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
5682 d = array_ref(array, 1, &i,
5683 -1 /* varlenarray */ ,
5684 -1 /* TEXT's typlen */ ,
5685 false /* TEXT's typbyval */ ,
5686 'i' /* TEXT's typalign */ ,
5692 s = DatumGetCString(DirectFunctionCall1(textout, d));
5694 ParseLongOption(s, &name, &value);
5698 (errcode(ERRCODE_SYNTAX_ERROR),
5699 errmsg("could not parse setting for parameter \"%s\"", name)));
5705 * We process all these options at SUSET level. We assume that the
5706 * right to insert an option into pg_database or pg_authid was checked
5707 * when it was inserted.
5709 SetConfigOption(name, value, PGC_SUSET, source);
5719 * Add an entry to an option array. The array parameter may be NULL
5720 * to indicate the current table entry is NULL.
5723 GUCArrayAdd(ArrayType *array, const char *name, const char *value)
5725 const char *varname;
5733 /* test if the option is valid */
5734 set_config_option(name, value,
5735 superuser() ? PGC_SUSET : PGC_USERSET,
5736 PGC_S_TEST, false, false);
5738 /* convert name to canonical spelling, so we can use plain strcmp */
5739 (void) GetConfigOptionByName(name, &varname);
5742 newval = palloc(strlen(name) + 1 + strlen(value) + 1);
5743 sprintf(newval, "%s=%s", name, value);
5744 datum = DirectFunctionCall1(textin, CStringGetDatum(newval));
5752 Assert(ARR_ELEMTYPE(array) == TEXTOID);
5753 Assert(ARR_NDIM(array) == 1);
5754 Assert(ARR_LBOUND(array)[0] == 1);
5756 index = ARR_DIMS(array)[0] + 1; /* add after end */
5758 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
5763 d = array_ref(array, 1, &i,
5764 -1 /* varlenarray */ ,
5765 -1 /* TEXT's typlen */ ,
5766 false /* TEXT's typbyval */ ,
5767 'i' /* TEXT's typalign */ ,
5771 current = DatumGetCString(DirectFunctionCall1(textout, d));
5772 if (strncmp(current, newval, strlen(name) + 1) == 0)
5779 a = array_set(array, 1, &index,
5782 -1 /* varlena array */ ,
5783 -1 /* TEXT's typlen */ ,
5784 false /* TEXT's typbyval */ ,
5785 'i' /* TEXT's typalign */ );
5788 a = construct_array(&datum, 1,
5797 * Delete an entry from an option array. The array parameter may be NULL
5798 * to indicate the current table entry is NULL. Also, if the return value
5799 * is NULL then a null should be stored.
5802 GUCArrayDelete(ArrayType *array, const char *name)
5804 const char *varname;
5805 ArrayType *newarray;
5811 /* test if the option is valid */
5812 set_config_option(name, NULL,
5813 superuser() ? PGC_SUSET : PGC_USERSET,
5814 PGC_S_TEST, false, false);
5816 /* convert name to canonical spelling, so we can use plain strcmp */
5817 (void) GetConfigOptionByName(name, &varname);
5820 /* if array is currently null, then surely nothing to delete */
5827 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
5833 d = array_ref(array, 1, &i,
5834 -1 /* varlenarray */ ,
5835 -1 /* TEXT's typlen */ ,
5836 false /* TEXT's typbyval */ ,
5837 'i' /* TEXT's typalign */ ,
5841 val = DatumGetCString(DirectFunctionCall1(textout, d));
5843 /* ignore entry if it's what we want to delete */
5844 if (strncmp(val, name, strlen(name)) == 0
5845 && val[strlen(name)] == '=')
5848 /* else add it to the output array */
5851 newarray = array_set(newarray, 1, &index,
5854 -1 /* varlenarray */ ,
5855 -1 /* TEXT's typlen */ ,
5856 false /* TEXT's typbyval */ ,
5857 'i' /* TEXT's typalign */ );
5860 newarray = construct_array(&d, 1,
5872 * assign_hook subroutines
5876 assign_log_destination(const char *value, bool doit, GucSource source)
5883 /* Need a modifiable copy of string */
5884 rawstring = pstrdup(value);
5886 /* Parse string into list of identifiers */
5887 if (!SplitIdentifierString(rawstring, ',', &elemlist))
5889 /* syntax error in list */
5891 list_free(elemlist);
5892 if (source >= PGC_S_INTERACTIVE)
5894 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5895 errmsg("invalid list syntax for parameter \"log_destination\"")));
5899 foreach(l, elemlist)
5901 char *tok = (char *) lfirst(l);
5903 if (pg_strcasecmp(tok, "stderr") == 0)
5904 newlogdest |= LOG_DESTINATION_STDERR;
5906 else if (pg_strcasecmp(tok, "syslog") == 0)
5907 newlogdest |= LOG_DESTINATION_SYSLOG;
5910 else if (pg_strcasecmp(tok, "eventlog") == 0)
5911 newlogdest |= LOG_DESTINATION_EVENTLOG;
5915 if (source >= PGC_S_INTERACTIVE)
5917 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5918 errmsg("unrecognized \"log_destination\" key word: \"%s\"",
5921 list_free(elemlist);
5927 Log_destination = newlogdest;
5930 list_free(elemlist);
5938 assign_syslog_facility(const char *facility, bool doit, GucSource source)
5942 if (pg_strcasecmp(facility, "LOCAL0") == 0)
5943 syslog_fac = LOG_LOCAL0;
5944 else if (pg_strcasecmp(facility, "LOCAL1") == 0)
5945 syslog_fac = LOG_LOCAL1;
5946 else if (pg_strcasecmp(facility, "LOCAL2") == 0)
5947 syslog_fac = LOG_LOCAL2;
5948 else if (pg_strcasecmp(facility, "LOCAL3") == 0)
5949 syslog_fac = LOG_LOCAL3;
5950 else if (pg_strcasecmp(facility, "LOCAL4") == 0)
5951 syslog_fac = LOG_LOCAL4;
5952 else if (pg_strcasecmp(facility, "LOCAL5") == 0)
5953 syslog_fac = LOG_LOCAL5;
5954 else if (pg_strcasecmp(facility, "LOCAL6") == 0)
5955 syslog_fac = LOG_LOCAL6;
5956 else if (pg_strcasecmp(facility, "LOCAL7") == 0)
5957 syslog_fac = LOG_LOCAL7;
5959 return NULL; /* reject */
5963 syslog_facility = syslog_fac;
5964 set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
5972 assign_syslog_ident(const char *ident, bool doit, GucSource source)
5975 set_syslog_parameters(ident, syslog_facility);
5979 #endif /* HAVE_SYSLOG */
5983 assign_defaultxactisolevel(const char *newval, bool doit, GucSource source)
5985 if (pg_strcasecmp(newval, "serializable") == 0)
5988 DefaultXactIsoLevel = XACT_SERIALIZABLE;
5990 else if (pg_strcasecmp(newval, "repeatable read") == 0)
5993 DefaultXactIsoLevel = XACT_REPEATABLE_READ;
5995 else if (pg_strcasecmp(newval, "read committed") == 0)
5998 DefaultXactIsoLevel = XACT_READ_COMMITTED;
6000 else if (pg_strcasecmp(newval, "read uncommitted") == 0)
6003 DefaultXactIsoLevel = XACT_READ_UNCOMMITTED;
6011 assign_log_min_messages(const char *newval,
6012 bool doit, GucSource source)
6014 return (assign_msglvl(&log_min_messages, newval, doit, source));
6018 assign_client_min_messages(const char *newval, bool doit, GucSource source)
6020 return (assign_msglvl(&client_min_messages, newval, doit, source));
6024 assign_min_error_statement(const char *newval, bool doit, GucSource source)
6026 return (assign_msglvl(&log_min_error_statement, newval, doit, source));
6030 assign_msglvl(int *var, const char *newval, bool doit, GucSource source)
6032 if (pg_strcasecmp(newval, "debug") == 0)
6037 else if (pg_strcasecmp(newval, "debug5") == 0)
6042 else if (pg_strcasecmp(newval, "debug4") == 0)
6047 else if (pg_strcasecmp(newval, "debug3") == 0)
6052 else if (pg_strcasecmp(newval, "debug2") == 0)
6057 else if (pg_strcasecmp(newval, "debug1") == 0)
6062 else if (pg_strcasecmp(newval, "log") == 0)
6069 * Client_min_messages always prints 'info', but we allow it as a value
6072 else if (pg_strcasecmp(newval, "info") == 0)
6077 else if (pg_strcasecmp(newval, "notice") == 0)
6082 else if (pg_strcasecmp(newval, "warning") == 0)
6087 else if (pg_strcasecmp(newval, "error") == 0)
6092 /* We allow FATAL/PANIC for client-side messages too. */
6093 else if (pg_strcasecmp(newval, "fatal") == 0)
6098 else if (pg_strcasecmp(newval, "panic") == 0)
6104 return NULL; /* fail */
6105 return newval; /* OK */
6109 assign_log_error_verbosity(const char *newval, bool doit, GucSource source)
6111 if (pg_strcasecmp(newval, "terse") == 0)
6114 Log_error_verbosity = PGERROR_TERSE;
6116 else if (pg_strcasecmp(newval, "default") == 0)
6119 Log_error_verbosity = PGERROR_DEFAULT;
6121 else if (pg_strcasecmp(newval, "verbose") == 0)
6124 Log_error_verbosity = PGERROR_VERBOSE;
6127 return NULL; /* fail */
6128 return newval; /* OK */
6132 assign_log_statement(const char *newval, bool doit, GucSource source)
6134 if (pg_strcasecmp(newval, "none") == 0)
6137 log_statement = LOGSTMT_NONE;
6139 else if (pg_strcasecmp(newval, "ddl") == 0)
6142 log_statement = LOGSTMT_DDL;
6144 else if (pg_strcasecmp(newval, "mod") == 0)
6147 log_statement = LOGSTMT_MOD;
6149 else if (pg_strcasecmp(newval, "all") == 0)
6152 log_statement = LOGSTMT_ALL;
6155 return NULL; /* fail */
6156 return newval; /* OK */
6160 show_num_temp_buffers(void)
6163 * We show the GUC var until local buffers have been initialized, and
6164 * NLocBuffer afterwards.
6166 static char nbuf[32];
6168 sprintf(nbuf, "%d", NLocBuffer ? NLocBuffer : num_temp_buffers);
6173 assign_phony_autocommit(bool newval, bool doit, GucSource source)
6177 if (doit && source >= PGC_S_INTERACTIVE)
6179 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6180 errmsg("SET AUTOCOMMIT TO OFF is no longer supported")));
6187 assign_custom_variable_classes(const char *newval, bool doit, GucSource source)
6190 * Check syntax. newval must be a comma separated list of identifiers.
6191 * Whitespace is allowed but skipped.
6193 bool hasSpaceAfterToken = false;
6194 const char *cp = newval;
6199 initStringInfo(&buf);
6200 while ((c = *cp++) != 0)
6202 if (isspace((unsigned char) c))
6205 hasSpaceAfterToken = true;
6211 hasSpaceAfterToken = false;
6215 appendStringInfoChar(&buf, ',');
6220 if (hasSpaceAfterToken || !isalnum((unsigned char) c))
6223 * Syntax error due to token following space after token or non
6224 * alpha numeric character
6227 (errcode(ERRCODE_SYNTAX_ERROR),
6228 errmsg("invalid syntax for \"custom_variable_classes\": \"%s\"", newval)));
6233 appendStringInfoChar(&buf, (char) c);
6236 /* Remove stray ',' at end */
6237 if (symLen == 0 && buf.len > 0)
6238 buf.data[--buf.len] = '\0';
6243 newval = strdup(buf.data);
6250 assign_debug_assertions(bool newval, bool doit, GucSource source)
6252 #ifndef USE_ASSERT_CHECKING
6255 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6256 errmsg("assertion checking is not supported by this build")));
6262 assign_ssl(bool newval, bool doit, GucSource source)
6267 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6268 errmsg("SSL is not supported by this build")));
6274 assign_stage_log_stats(bool newval, bool doit, GucSource source)
6276 if (newval && log_statement_stats)
6278 if (source >= PGC_S_INTERACTIVE)
6280 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6281 errmsg("cannot enable parameter when \"log_statement_stats\" is true")));
6282 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
6283 else if (source != PGC_S_OVERRIDE)
6290 assign_log_stats(bool newval, bool doit, GucSource source)
6293 (log_parser_stats || log_planner_stats || log_executor_stats))
6295 if (source >= PGC_S_INTERACTIVE)
6297 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6298 errmsg("cannot enable \"log_statement_stats\" when "
6299 "\"log_parser_stats\", \"log_planner_stats\", "
6300 "or \"log_executor_stats\" is true")));
6301 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
6302 else if (source != PGC_S_OVERRIDE)
6309 assign_transaction_read_only(bool newval, bool doit, GucSource source)
6311 /* Can't go to r/w mode inside a r/o transaction */
6312 if (newval == false && XactReadOnly && IsSubTransaction())
6314 if (source >= PGC_S_INTERACTIVE)
6316 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6317 errmsg("cannot set transaction read-write mode inside a read-only transaction")));
6318 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
6319 else if (source != PGC_S_OVERRIDE)
6326 assign_canonical_path(const char *newval, bool doit, GucSource source)
6330 char *canon_val = guc_strdup(ERROR, newval);
6332 canonicalize_path(canon_val);
6340 assign_backslash_quote(const char *newval, bool doit, GucSource source)
6342 BackslashQuoteType bq;
6346 * Although only "on", "off", and "safe_encoding" are documented, we use
6347 * parse_bool so we can accept all the likely variants of "on" and "off".
6349 if (pg_strcasecmp(newval, "safe_encoding") == 0)
6350 bq = BACKSLASH_QUOTE_SAFE_ENCODING;
6351 else if (parse_bool(newval, &bqbool))
6353 bq = bqbool ? BACKSLASH_QUOTE_ON : BACKSLASH_QUOTE_OFF;
6356 return NULL; /* reject */
6359 backslash_quote = bq;
6365 assign_timezone_abbreviations(const char *newval, bool doit, GucSource source)
6368 * The powerup value shown above for timezone_abbreviations is "UNKNOWN".
6369 * When we see this we just do nothing. If this value isn't overridden
6370 * from the config file then pg_timezone_abbrev_initialize() will
6371 * eventually replace it with "Default". This hack has two purposes: to
6372 * avoid wasting cycles loading values that might soon be overridden from
6373 * the config file, and to avoid trying to read the timezone abbrev files
6374 * during InitializeGUCOptions(). The latter doesn't work in an
6375 * EXEC_BACKEND subprocess because my_exec_path hasn't been set yet and so
6376 * we can't locate PGSHAREDIR. (Essentially the same hack is used to
6377 * delay initializing TimeZone ... if we have any more, we should try to
6378 * clean up and centralize this mechanism ...)
6380 if (strcmp(newval, "UNKNOWN") == 0)
6385 /* Loading abbrev file is expensive, so only do it when value changes */
6386 if (timezone_abbreviations_string == NULL ||
6387 strcmp(timezone_abbreviations_string, newval) != 0)
6392 * If reading config file, only the postmaster should bleat loudly
6393 * about problems. Otherwise, it's just this one process doing it,
6394 * and we use WARNING message level.
6396 if (source == PGC_S_FILE)
6397 elevel = IsUnderPostmaster ? DEBUG2 : LOG;
6400 if (!load_tzoffsets(newval, doit, elevel))
6407 * pg_timezone_abbrev_initialize --- set default value if not done already
6409 * This is called after initial loading of postgresql.conf. If no
6410 * timezone_abbreviations setting was found therein, select default.
6413 pg_timezone_abbrev_initialize(void)
6415 if (strcmp(timezone_abbreviations_string, "UNKNOWN") == 0)
6417 SetConfigOption("timezone_abbreviations", "Default",
6418 PGC_POSTMASTER, PGC_S_ARGV);
6423 assign_tcp_keepalives_idle(int newval, bool doit, GucSource source)
6426 return (pq_setkeepalivesidle(newval, MyProcPort) == STATUS_OK);
6432 show_tcp_keepalives_idle(void)
6434 static char nbuf[16];
6436 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesidle(MyProcPort));
6441 assign_tcp_keepalives_interval(int newval, bool doit, GucSource source)
6444 return (pq_setkeepalivesinterval(newval, MyProcPort) == STATUS_OK);
6450 show_tcp_keepalives_interval(void)
6452 static char nbuf[16];
6454 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesinterval(MyProcPort));
6459 assign_tcp_keepalives_count(int newval, bool doit, GucSource source)
6462 return (pq_setkeepalivescount(newval, MyProcPort) == STATUS_OK);
6468 show_tcp_keepalives_count(void)
6470 static char nbuf[16];
6472 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivescount(MyProcPort));
6477 #include "guc-file.c"