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-2005, PostgreSQL Global Development Group
10 * Written by Peter Eisentraut <peter_e@gmx.net>.
13 * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.305 2005/12/30 00:13:50 petere Exp $
15 *--------------------------------------------------------------------
28 #include "utils/guc.h"
29 #include "utils/guc_tables.h"
31 #include "access/twophase.h"
32 #include "catalog/namespace.h"
33 #include "catalog/pg_type.h"
34 #include "commands/async.h"
35 #include "commands/variable.h"
36 #include "commands/vacuum.h"
37 #include "executor/executor.h"
40 #include "libpq/auth.h"
41 #include "libpq/pqcomm.h"
42 #include "libpq/pqformat.h"
43 #include "mb/pg_wchar.h"
44 #include "miscadmin.h"
45 #include "optimizer/cost.h"
46 #include "optimizer/geqo.h"
47 #include "optimizer/paths.h"
48 #include "optimizer/planmain.h"
49 #include "parser/parse_expr.h"
50 #include "parser/parse_relation.h"
51 #include "postmaster/autovacuum.h"
52 #include "postmaster/bgwriter.h"
53 #include "postmaster/syslogger.h"
54 #include "postmaster/postmaster.h"
55 #include "storage/bufmgr.h"
56 #include "storage/fd.h"
57 #include "storage/freespace.h"
58 #include "storage/lock.h"
59 #include "storage/proc.h"
60 #include "tcop/tcopprot.h"
61 #include "utils/array.h"
62 #include "utils/builtins.h"
63 #include "utils/memutils.h"
64 #include "utils/pg_locale.h"
69 #define PG_KRB_SRVTAB ""
72 #define PG_KRB_SRVNAM ""
75 #define CONFIG_FILENAME "postgresql.conf"
76 #define HBA_FILENAME "pg_hba.conf"
77 #define IDENT_FILENAME "pg_ident.conf"
80 #define CONFIG_EXEC_PARAMS "global/config_exec_params"
81 #define CONFIG_EXEC_PARAMS_NEW "global/config_exec_params.new"
84 /* upper limit for GUC variables measured in kilobytes of memory */
86 #define MAX_KILOBYTES INT_MAX
88 #define MAX_KILOBYTES (INT_MAX / 1024)
91 /* XXX these should appear in other modules' header files */
92 extern bool Log_disconnections;
93 extern bool check_function_bodies;
94 extern int CommitDelay;
95 extern int CommitSiblings;
96 extern char *default_tablespace;
97 extern bool fullPageWrites;
100 extern bool trace_sort;
103 static const char *assign_log_destination(const char *value,
104 bool doit, GucSource source);
107 static int syslog_facility = LOG_LOCAL0;
109 static const char *assign_syslog_facility(const char *facility,
110 bool doit, GucSource source);
111 static const char *assign_syslog_ident(const char *ident,
112 bool doit, GucSource source);
115 static const char *assign_defaultxactisolevel(const char *newval, bool doit,
117 static const char *assign_log_min_messages(const char *newval, bool doit,
119 static const char *assign_client_min_messages(const char *newval,
120 bool doit, GucSource source);
121 static const char *assign_min_error_statement(const char *newval, bool doit,
123 static const char *assign_msglvl(int *var, const char *newval, bool doit,
125 static const char *assign_log_error_verbosity(const char *newval, bool doit,
127 static const char *assign_log_statement(const char *newval, bool doit,
129 static const char *show_num_temp_buffers(void);
130 static bool assign_phony_autocommit(bool newval, bool doit, GucSource source);
131 static const char *assign_custom_variable_classes(const char *newval, bool doit,
133 static bool assign_ssl(bool newval, bool doit, GucSource source);
134 static bool assign_stage_log_stats(bool newval, bool doit, GucSource source);
135 static bool assign_log_stats(bool newval, bool doit, GucSource source);
136 static bool assign_transaction_read_only(bool newval, bool doit, GucSource source);
137 static const char *assign_canonical_path(const char *newval, bool doit, GucSource source);
139 static bool assign_tcp_keepalives_idle(int newval, bool doit, GucSource source);
140 static bool assign_tcp_keepalives_interval(int newval, bool doit, GucSource source);
141 static bool assign_tcp_keepalives_count(int newval, bool doit, GucSource source);
142 static const char *show_tcp_keepalives_idle(void);
143 static const char *show_tcp_keepalives_interval(void);
144 static const char *show_tcp_keepalives_count(void);
147 * GUC option variables that are exported from this module
149 #ifdef USE_ASSERT_CHECKING
150 bool assert_enabled = true;
152 bool log_duration = false;
153 bool Debug_print_plan = false;
154 bool Debug_print_parse = false;
155 bool Debug_print_rewritten = false;
156 bool Debug_pretty_print = false;
157 bool Explain_pretty_print = true;
159 bool log_parser_stats = false;
160 bool log_planner_stats = false;
161 bool log_executor_stats = false;
162 bool log_statement_stats = false; /* this is sort of all three
164 bool log_btree_build_stats = false;
166 bool SQL_inheritance = true;
168 bool Australian_timezones = false;
170 bool Password_encryption = true;
172 bool default_with_oids = false;
174 int log_min_error_statement = PANIC;
175 int log_min_messages = NOTICE;
176 int client_min_messages = NOTICE;
177 int log_min_duration_statement = -1;
179 int num_temp_buffers = 1000;
181 char *ConfigFileName;
184 char *external_pid_file;
186 int tcp_keepalives_idle;
187 int tcp_keepalives_interval;
188 int tcp_keepalives_count;
191 * These variables are all dummies that don't do anything, except in some
192 * cases provide the value for SHOW to display. The real state is elsewhere
193 * and is kept in sync by assign_hooks.
195 static char *client_min_messages_str;
196 static char *log_min_messages_str;
197 static char *log_error_verbosity_str;
198 static char *log_statement_str;
199 static char *log_min_error_statement_str;
200 static char *log_destination_string;
201 static char *syslog_facility_str;
202 static char *syslog_ident_str;
203 static bool phony_autocommit;
204 static bool session_auth_is_superuser;
205 static double phony_random_seed;
206 static char *client_encoding_string;
207 static char *datestyle_string;
208 static char *default_iso_level_string;
209 static char *locale_collate;
210 static char *locale_ctype;
211 static char *regex_flavor_string;
212 static char *server_encoding_string;
213 static char *server_version_string;
214 static char *timezone_string;
215 static char *XactIsoLevel_string;
216 static char *data_directory;
217 static char *custom_variable_classes;
218 static int max_function_args;
219 static int max_index_keys;
220 static int max_identifier_length;
221 static int block_size;
222 static bool integer_datetimes;
223 static bool standard_conforming_strings;
225 /* should be static, but commands/variable.c needs to get at these */
227 char *session_authorization_string;
231 * Displayable names for context types (enum GucContext)
233 * Note: these strings are deliberately not localized.
235 const char *const GucContext_Names[] =
237 /* PGC_INTERNAL */ "internal",
238 /* PGC_POSTMASTER */ "postmaster",
239 /* PGC_SIGHUP */ "sighup",
240 /* PGC_BACKEND */ "backend",
241 /* PGC_SUSET */ "superuser",
242 /* PGC_USERSET */ "user"
246 * Displayable names for source types (enum GucSource)
248 * Note: these strings are deliberately not localized.
250 const char *const GucSource_Names[] =
252 /* PGC_S_DEFAULT */ "default",
253 /* PGC_S_ENV_VAR */ "environment variable",
254 /* PGC_S_FILE */ "configuration file",
255 /* PGC_S_ARGV */ "command line",
256 /* PGC_S_DATABASE */ "database",
257 /* PGC_S_USER */ "user",
258 /* PGC_S_CLIENT */ "client",
259 /* PGC_S_OVERRIDE */ "override",
260 /* PGC_S_INTERACTIVE */ "interactive",
261 /* PGC_S_TEST */ "test",
262 /* PGC_S_SESSION */ "session"
266 * Displayable names for the groupings defined in enum config_group
268 const char *const config_group_names[] =
271 gettext_noop("Ungrouped"),
273 gettext_noop("File Locations"),
275 gettext_noop("Connections and Authentication"),
276 /* CONN_AUTH_SETTINGS */
277 gettext_noop("Connections and Authentication / Connection Settings"),
278 /* CONN_AUTH_SECURITY */
279 gettext_noop("Connections and Authentication / Security and Authentication"),
281 gettext_noop("Resource Usage"),
283 gettext_noop("Resource Usage / Memory"),
285 gettext_noop("Resource Usage / Free Space Map"),
286 /* RESOURCES_KERNEL */
287 gettext_noop("Resource Usage / Kernel Resources"),
289 gettext_noop("Write-Ahead Log"),
291 gettext_noop("Write-Ahead Log / Settings"),
292 /* WAL_CHECKPOINTS */
293 gettext_noop("Write-Ahead Log / Checkpoints"),
295 gettext_noop("Query Tuning"),
296 /* QUERY_TUNING_METHOD */
297 gettext_noop("Query Tuning / Planner Method Configuration"),
298 /* QUERY_TUNING_COST */
299 gettext_noop("Query Tuning / Planner Cost Constants"),
300 /* QUERY_TUNING_GEQO */
301 gettext_noop("Query Tuning / Genetic Query Optimizer"),
302 /* QUERY_TUNING_OTHER */
303 gettext_noop("Query Tuning / Other Planner Options"),
305 gettext_noop("Reporting and Logging"),
307 gettext_noop("Reporting and Logging / Where to Log"),
309 gettext_noop("Reporting and Logging / When to Log"),
311 gettext_noop("Reporting and Logging / What to Log"),
313 gettext_noop("Statistics"),
314 /* STATS_MONITORING */
315 gettext_noop("Statistics / Monitoring"),
316 /* STATS_COLLECTOR */
317 gettext_noop("Statistics / Query and Index Statistics Collector"),
319 gettext_noop("Auto Vacuum"),
321 gettext_noop("Client Connection Defaults"),
322 /* CLIENT_CONN_STATEMENT */
323 gettext_noop("Client Connection Defaults / Statement Behavior"),
324 /* CLIENT_CONN_LOCALE */
325 gettext_noop("Client Connection Defaults / Locale and Formatting"),
326 /* CLIENT_CONN_OTHER */
327 gettext_noop("Client Connection Defaults / Other Defaults"),
328 /* LOCK_MANAGEMENT */
329 gettext_noop("Lock Management"),
331 gettext_noop("Version and Platform Compatibility"),
332 /* COMPAT_OPTIONS_PREVIOUS */
333 gettext_noop("Version and Platform Compatibility / Previous PostgreSQL Versions"),
334 /* COMPAT_OPTIONS_CLIENT */
335 gettext_noop("Version and Platform Compatibility / Other Platforms and Clients"),
337 gettext_noop("Preset Options"),
339 gettext_noop("Customized Options"),
340 /* DEVELOPER_OPTIONS */
341 gettext_noop("Developer Options"),
342 /* help_config wants this array to be null-terminated */
347 * Displayable names for GUC variable types (enum config_type)
349 * Note: these strings are deliberately not localized.
351 const char *const config_type_names[] =
353 /* PGC_BOOL */ "bool",
354 /* PGC_INT */ "integer",
355 /* PGC_REAL */ "real",
356 /* PGC_STRING */ "string"
361 * Contents of GUC tables
363 * See src/backend/utils/misc/README for design notes.
367 * 1. Declare a global variable of type bool, int, double, or char*
368 * and make use of it.
370 * 2. Decide at what times it's safe to set the option. See guc.h for
373 * 3. Decide on a name, a default value, upper and lower bounds (if
376 * 4. Add a record below.
378 * 5. Add it to src/backend/utils/misc/postgresql.conf.sample, if
381 * 6. Add it to src/bin/psql/tab-complete.c, if it's a USERSET option.
383 * 7. Don't forget to document the option.
385 * 8. If it's a new GUC_LIST option you must edit pg_dumpall.c to ensure
386 * it is not single quoted at dump time.
390 /******** option records follow ********/
392 static struct config_bool ConfigureNamesBool[] =
395 {"enable_seqscan", PGC_USERSET, QUERY_TUNING_METHOD,
396 gettext_noop("Enables the planner's use of sequential-scan plans."),
403 {"enable_indexscan", PGC_USERSET, QUERY_TUNING_METHOD,
404 gettext_noop("Enables the planner's use of index-scan plans."),
411 {"enable_bitmapscan", PGC_USERSET, QUERY_TUNING_METHOD,
412 gettext_noop("Enables the planner's use of bitmap-scan plans."),
419 {"enable_tidscan", PGC_USERSET, QUERY_TUNING_METHOD,
420 gettext_noop("Enables the planner's use of TID scan plans."),
427 {"enable_sort", PGC_USERSET, QUERY_TUNING_METHOD,
428 gettext_noop("Enables the planner's use of explicit sort steps."),
435 {"enable_hashagg", PGC_USERSET, QUERY_TUNING_METHOD,
436 gettext_noop("Enables the planner's use of hashed aggregation plans."),
443 {"enable_nestloop", PGC_USERSET, QUERY_TUNING_METHOD,
444 gettext_noop("Enables the planner's use of nested-loop join plans."),
451 {"enable_mergejoin", PGC_USERSET, QUERY_TUNING_METHOD,
452 gettext_noop("Enables the planner's use of merge join plans."),
459 {"enable_hashjoin", PGC_USERSET, QUERY_TUNING_METHOD,
460 gettext_noop("Enables the planner's use of hash join plans."),
467 {"constraint_exclusion", PGC_USERSET, QUERY_TUNING_OTHER,
468 gettext_noop("Enables the planner to use constraints to optimize queries."),
469 gettext_noop("Child table scans will be skipped if their "
470 "constraints guarantee that no rows match the query.")
472 &constraint_exclusion,
476 {"geqo", PGC_USERSET, QUERY_TUNING_GEQO,
477 gettext_noop("Enables genetic query optimization."),
478 gettext_noop("This algorithm attempts to do planning without "
479 "exhaustive searching.")
485 /* Not for general use --- used by SET SESSION AUTHORIZATION */
486 {"is_superuser", PGC_INTERNAL, UNGROUPED,
487 gettext_noop("Shows whether the current user is a superuser."),
489 GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
491 &session_auth_is_superuser,
495 {"ssl", PGC_POSTMASTER, CONN_AUTH_SECURITY,
496 gettext_noop("Enables SSL connections."),
500 false, assign_ssl, NULL
503 {"fsync", PGC_SIGHUP, WAL_SETTINGS,
504 gettext_noop("Forces synchronization of updates to disk."),
505 gettext_noop("The server will use the fsync() system call in several places to make "
506 "sure that updates are physically written to disk. This insures "
507 "that a database cluster will recover to a consistent state after "
508 "an operating system or hardware crash.")
514 {"zero_damaged_pages", PGC_SUSET, DEVELOPER_OPTIONS,
515 gettext_noop("Continues processing past damaged page headers."),
516 gettext_noop("Detection of a damaged page header normally causes PostgreSQL to "
517 "report an error, aborting the current transaction. Setting "
518 "zero_damaged_pages to true causes the system to instead report a "
519 "warning, zero out the damaged page, and continue processing. This "
520 "behavior will destroy data, namely all the rows on the damaged page."),
527 {"full_page_writes", PGC_SIGHUP, WAL_SETTINGS,
528 gettext_noop("Writes full pages to WAL when first modified after a checkpoint."),
529 gettext_noop("A page write in process during an operating system crash might be "
530 "only partially written to disk. During recovery, the row changes "
531 "stored in WAL are not enough to recover. This option writes "
532 "pages when first modified after a checkpoint to WAL so full recovery "
539 {"silent_mode", PGC_POSTMASTER, LOGGING_WHEN,
540 gettext_noop("Runs the server silently."),
541 gettext_noop("If this parameter is set, the server will automatically run in the "
542 "background and any controlling terminals are dissociated.")
548 {"log_connections", PGC_BACKEND, LOGGING_WHAT,
549 gettext_noop("Logs each successful connection."),
556 {"log_disconnections", PGC_BACKEND, LOGGING_WHAT,
557 gettext_noop("Logs end of a session, including duration."),
564 #ifdef USE_ASSERT_CHECKING
566 {"debug_assertions", PGC_USERSET, DEVELOPER_OPTIONS,
567 gettext_noop("Turns on various assertion checks."),
568 gettext_noop("This is a debugging aid."),
577 /* currently undocumented, so don't show in SHOW ALL */
578 {"exit_on_error", PGC_USERSET, UNGROUPED,
579 gettext_noop("no description available"),
581 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
587 {"log_duration", PGC_SUSET, LOGGING_WHAT,
588 gettext_noop("Logs the duration of each completed SQL statement."),
595 {"debug_print_parse", PGC_USERSET, LOGGING_WHAT,
596 gettext_noop("Prints the parse tree to the server log."),
603 {"debug_print_rewritten", PGC_USERSET, LOGGING_WHAT,
604 gettext_noop("Prints the parse tree after rewriting to server log."),
607 &Debug_print_rewritten,
611 {"debug_print_plan", PGC_USERSET, LOGGING_WHAT,
612 gettext_noop("Prints the execution plan to server log."),
619 {"debug_pretty_print", PGC_USERSET, LOGGING_WHAT,
620 gettext_noop("Indents parse and plan tree displays."),
627 {"log_parser_stats", PGC_SUSET, STATS_MONITORING,
628 gettext_noop("Writes parser performance statistics to the server log."),
632 false, assign_stage_log_stats, NULL
635 {"log_planner_stats", PGC_SUSET, STATS_MONITORING,
636 gettext_noop("Writes planner performance statistics to the server log."),
640 false, assign_stage_log_stats, NULL
643 {"log_executor_stats", PGC_SUSET, STATS_MONITORING,
644 gettext_noop("Writes executor performance statistics to the server log."),
648 false, assign_stage_log_stats, NULL
651 {"log_statement_stats", PGC_SUSET, STATS_MONITORING,
652 gettext_noop("Writes cumulative performance statistics to the server log."),
655 &log_statement_stats,
656 false, assign_log_stats, NULL
658 #ifdef BTREE_BUILD_STATS
660 {"log_btree_build_stats", PGC_SUSET, DEVELOPER_OPTIONS,
661 gettext_noop("no description available"),
665 &log_btree_build_stats,
671 {"explain_pretty_print", PGC_USERSET, CLIENT_CONN_OTHER,
672 gettext_noop("Uses the indented output format for EXPLAIN VERBOSE."),
675 &Explain_pretty_print,
679 {"stats_start_collector", PGC_POSTMASTER, STATS_COLLECTOR,
680 gettext_noop("Starts the server statistics-collection subprocess."),
683 &pgstat_collect_startcollector,
687 {"stats_reset_on_server_start", PGC_POSTMASTER, STATS_COLLECTOR,
688 gettext_noop("Zeroes collected statistics on server restart."),
691 &pgstat_collect_resetonpmstart,
695 {"stats_command_string", PGC_SUSET, STATS_COLLECTOR,
696 gettext_noop("Collects statistics about executing commands."),
697 gettext_noop("Enables the collection of statistics on the currently "
698 "executing command of each session, along with the time "
699 "at which that command began execution.")
701 &pgstat_collect_querystring,
705 {"stats_row_level", PGC_SUSET, STATS_COLLECTOR,
706 gettext_noop("Collects row-level statistics on database activity."),
709 &pgstat_collect_tuplelevel,
713 {"stats_block_level", PGC_SUSET, STATS_COLLECTOR,
714 gettext_noop("Collects block-level statistics on database activity."),
717 &pgstat_collect_blocklevel,
722 {"autovacuum", PGC_SIGHUP, AUTOVACUUM,
723 gettext_noop("Starts the autovacuum subprocess."),
726 &autovacuum_start_daemon,
731 {"trace_notify", PGC_USERSET, DEVELOPER_OPTIONS,
732 gettext_noop("Generates debugging output for LISTEN and NOTIFY."),
742 {"trace_locks", PGC_SUSET, DEVELOPER_OPTIONS,
743 gettext_noop("no description available"),
751 {"trace_userlocks", PGC_SUSET, DEVELOPER_OPTIONS,
752 gettext_noop("no description available"),
760 {"trace_lwlocks", PGC_SUSET, DEVELOPER_OPTIONS,
761 gettext_noop("no description available"),
769 {"debug_deadlocks", PGC_SUSET, DEVELOPER_OPTIONS,
770 gettext_noop("no description available"),
780 {"log_hostname", PGC_SIGHUP, LOGGING_WHAT,
781 gettext_noop("Logs the host name in the connection logs."),
782 gettext_noop("By default, connection logs only show the IP address "
783 "of the connecting host. If you want them to show the host name you "
784 "can turn this on, but depending on your host name resolution "
785 "setup it might impose a non-negligible performance penalty.")
791 {"sql_inheritance", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
792 gettext_noop("Causes subtables to be included by default in various commands."),
799 {"australian_timezones", PGC_USERSET, CLIENT_CONN_LOCALE,
800 gettext_noop("Interprets ACST, CST, EST, and SAT as Australian time zones."),
801 gettext_noop("Otherwise they are interpreted as North/South American "
802 "time zones and Saturday.")
804 &Australian_timezones,
805 false, ClearDateCache, NULL
808 {"password_encryption", PGC_USERSET, CONN_AUTH_SECURITY,
809 gettext_noop("Encrypt passwords."),
810 gettext_noop("When a password is specified in CREATE USER or "
811 "ALTER USER without writing either ENCRYPTED or UNENCRYPTED, "
812 "this parameter determines whether the password is to be encrypted.")
814 &Password_encryption,
818 {"transform_null_equals", PGC_USERSET, COMPAT_OPTIONS_CLIENT,
819 gettext_noop("Treats \"expr=NULL\" as \"expr IS NULL\"."),
820 gettext_noop("When turned on, expressions of the form expr = NULL "
821 "(or NULL = expr) are treated as expr IS NULL, that is, they "
822 "return true if expr evaluates to the null value, and false "
823 "otherwise. The correct behavior of expr = NULL is to always "
824 "return null (unknown).")
826 &Transform_null_equals,
830 {"db_user_namespace", PGC_SIGHUP, CONN_AUTH_SECURITY,
831 gettext_noop("Enables per-database user names."),
838 /* only here for backwards compatibility */
839 {"autocommit", PGC_USERSET, CLIENT_CONN_STATEMENT,
840 gettext_noop("This parameter doesn't do anything."),
841 gettext_noop("It's just here so that we won't choke on SET AUTOCOMMIT TO ON from 7.3-vintage clients."),
842 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
845 true, assign_phony_autocommit, NULL
848 {"default_transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
849 gettext_noop("Sets the default read-only status of new transactions."),
852 &DefaultXactReadOnly,
856 {"transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
857 gettext_noop("Sets the current transaction's read-only status."),
859 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
862 false, assign_transaction_read_only, NULL
865 {"add_missing_from", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
866 gettext_noop("Automatically adds missing table references to FROM clauses."),
873 {"check_function_bodies", PGC_USERSET, CLIENT_CONN_STATEMENT,
874 gettext_noop("Check function bodies during CREATE FUNCTION."),
877 &check_function_bodies,
881 {"array_nulls", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
882 gettext_noop("Enable input of NULL elements in arrays."),
883 gettext_noop("When turned on, unquoted NULL in an array input "
884 "value means a NULL value; "
885 "otherwise it is taken literally.")
891 {"default_with_oids", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
892 gettext_noop("Create new tables with OIDs by default."),
899 {"redirect_stderr", PGC_POSTMASTER, LOGGING_WHERE,
900 gettext_noop("Start a subprocess to capture stderr output into log files."),
907 {"log_truncate_on_rotation", PGC_SIGHUP, LOGGING_WHERE,
908 gettext_noop("Truncate existing log files of same name during log rotation."),
911 &Log_truncate_on_rotation,
917 {"trace_sort", PGC_USERSET, DEVELOPER_OPTIONS,
918 gettext_noop("Emit information about resource usage in sorting."),
929 {"wal_debug", PGC_SUSET, DEVELOPER_OPTIONS,
930 gettext_noop("Emit WAL-related debugging output."),
940 {"integer_datetimes", PGC_INTERNAL, PRESET_OPTIONS,
941 gettext_noop("Datetimes are integer based."),
943 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
946 #ifdef HAVE_INT64_TIMESTAMP
954 {"krb_caseins_users", PGC_POSTMASTER, CONN_AUTH_SECURITY,
955 gettext_noop("Sets whether Kerberos user names should be treated as case-insensitive."),
958 &pg_krb_caseins_users,
963 {"escape_string_warning", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
964 gettext_noop("Warn about backslash escapes in ordinary string literals."),
967 &escape_string_warning,
972 {"standard_conforming_strings", PGC_INTERNAL, PRESET_OPTIONS,
973 gettext_noop("'...' strings treat backslashes literally."),
975 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
977 &standard_conforming_strings,
981 /* End-of-list marker */
983 {NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL
988 static struct config_int ConfigureNamesInt[] =
991 {"default_statistics_target", PGC_USERSET, QUERY_TUNING_OTHER,
992 gettext_noop("Sets the default statistics target."),
993 gettext_noop("This applies to table columns that have not had a "
994 "column-specific target set via ALTER TABLE SET STATISTICS.")
996 &default_statistics_target,
997 10, 1, 1000, NULL, NULL
1000 {"from_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1001 gettext_noop("Sets the FROM-list size beyond which subqueries are not "
1003 gettext_noop("The planner will merge subqueries into upper "
1004 "queries if the resulting FROM list would have no more than "
1007 &from_collapse_limit,
1008 8, 1, INT_MAX, NULL, NULL
1011 {"join_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1012 gettext_noop("Sets the FROM-list size beyond which JOIN constructs are not "
1014 gettext_noop("The planner will flatten explicit JOIN "
1015 "constructs into lists of FROM items whenever a list of no more "
1016 "than this many items would result.")
1018 &join_collapse_limit,
1019 8, 1, INT_MAX, NULL, NULL
1022 {"geqo_threshold", PGC_USERSET, QUERY_TUNING_GEQO,
1023 gettext_noop("Sets the threshold of FROM items beyond which GEQO is used."),
1027 12, 2, INT_MAX, NULL, NULL
1030 {"geqo_effort", PGC_USERSET, QUERY_TUNING_GEQO,
1031 gettext_noop("GEQO: effort is used to set the default for other GEQO parameters."),
1035 DEFAULT_GEQO_EFFORT, MIN_GEQO_EFFORT, MAX_GEQO_EFFORT, NULL, NULL
1038 {"geqo_pool_size", PGC_USERSET, QUERY_TUNING_GEQO,
1039 gettext_noop("GEQO: number of individuals in the population."),
1040 gettext_noop("Zero selects a suitable default value.")
1043 0, 0, INT_MAX, NULL, NULL
1046 {"geqo_generations", PGC_USERSET, QUERY_TUNING_GEQO,
1047 gettext_noop("GEQO: number of iterations of the algorithm."),
1048 gettext_noop("Zero selects a suitable default value.")
1051 0, 0, INT_MAX, NULL, NULL
1055 {"deadlock_timeout", PGC_SIGHUP, LOCK_MANAGEMENT,
1056 gettext_noop("The time in milliseconds to wait on lock before checking for deadlock."),
1060 1000, 0, INT_MAX, NULL, NULL
1064 * Note: There is some postprocessing done in PostmasterMain() to make
1065 * sure the buffers are at least twice the number of backends, so the
1066 * constraints here are partially unused. Similarly, the superuser
1067 * reserved number is checked to ensure it is less than the max backends
1070 * MaxBackends is limited to INT_MAX/4 because some places compute
1071 * 4*MaxBackends without any overflow check. Likewise we have to limit
1072 * NBuffers to INT_MAX/2.
1075 {"max_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1076 gettext_noop("Sets the maximum number of concurrent connections."),
1080 100, 1, INT_MAX / 4, NULL, NULL
1084 {"superuser_reserved_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1085 gettext_noop("Sets the number of connection slots reserved for superusers."),
1089 2, 0, INT_MAX / 4, NULL, NULL
1093 {"shared_buffers", PGC_POSTMASTER, RESOURCES_MEM,
1094 gettext_noop("Sets the number of shared memory buffers used by the server."),
1098 1000, 16, INT_MAX / 2, NULL, NULL
1102 {"temp_buffers", PGC_USERSET, RESOURCES_MEM,
1103 gettext_noop("Sets the maximum number of temporary buffers used by each session."),
1107 1000, 100, INT_MAX / 2, NULL, show_num_temp_buffers
1111 {"port", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1112 gettext_noop("Sets the TCP port the server listens on."),
1116 DEF_PGPORT, 1, 65535, NULL, NULL
1120 {"unix_socket_permissions", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1121 gettext_noop("Sets the access permissions of the Unix-domain socket."),
1122 gettext_noop("Unix-domain sockets use the usual Unix file system "
1123 "permission set. The parameter value is expected to be an numeric mode "
1124 "specification in the form accepted by the chmod and umask system "
1125 "calls. (To use the customary octal format the number must start with "
1128 &Unix_socket_permissions,
1129 0777, 0000, 0777, NULL, NULL
1133 {"work_mem", PGC_USERSET, RESOURCES_MEM,
1134 gettext_noop("Sets the maximum memory to be used for query workspaces."),
1135 gettext_noop("This much memory may be used by each internal "
1136 "sort operation and hash table before switching to "
1137 "temporary disk files.")
1140 1024, 8 * BLCKSZ / 1024, MAX_KILOBYTES, NULL, NULL
1144 {"maintenance_work_mem", PGC_USERSET, RESOURCES_MEM,
1145 gettext_noop("Sets the maximum memory to be used for maintenance operations."),
1146 gettext_noop("This includes operations such as VACUUM and CREATE INDEX.")
1148 &maintenance_work_mem,
1149 16384, 1024, MAX_KILOBYTES, NULL, NULL
1153 {"max_stack_depth", PGC_SUSET, RESOURCES_MEM,
1154 gettext_noop("Sets the maximum stack depth, in kilobytes."),
1158 2048, 100, MAX_KILOBYTES, assign_max_stack_depth, NULL
1162 {"vacuum_cost_page_hit", PGC_USERSET, RESOURCES,
1163 gettext_noop("Vacuum cost for a page found in the buffer cache."),
1167 1, 0, 10000, NULL, NULL
1171 {"vacuum_cost_page_miss", PGC_USERSET, RESOURCES,
1172 gettext_noop("Vacuum cost for a page not found in the buffer cache."),
1175 &VacuumCostPageMiss,
1176 10, 0, 10000, NULL, NULL
1180 {"vacuum_cost_page_dirty", PGC_USERSET, RESOURCES,
1181 gettext_noop("Vacuum cost for a page dirtied by vacuum."),
1184 &VacuumCostPageDirty,
1185 20, 0, 10000, NULL, NULL
1189 {"vacuum_cost_limit", PGC_USERSET, RESOURCES,
1190 gettext_noop("Vacuum cost amount available before napping."),
1194 200, 1, 10000, NULL, NULL
1198 {"vacuum_cost_delay", PGC_USERSET, RESOURCES,
1199 gettext_noop("Vacuum cost delay in milliseconds."),
1203 0, 0, 1000, NULL, NULL
1207 {"autovacuum_vacuum_cost_delay", PGC_SIGHUP, AUTOVACUUM,
1208 gettext_noop("Vacuum cost delay in milliseconds, for autovacuum."),
1211 &autovacuum_vac_cost_delay,
1212 -1, -1, 1000, NULL, NULL
1216 {"autovacuum_vacuum_cost_limit", PGC_SIGHUP, AUTOVACUUM,
1217 gettext_noop("Vacuum cost amount available before napping, for autovacuum."),
1220 &autovacuum_vac_cost_limit,
1221 -1, -1, 10000, NULL, NULL
1225 {"max_files_per_process", PGC_POSTMASTER, RESOURCES_KERNEL,
1226 gettext_noop("Sets the maximum number of simultaneously open files for each server process."),
1229 &max_files_per_process,
1230 1000, 25, INT_MAX, NULL, NULL
1234 {"max_prepared_transactions", PGC_POSTMASTER, RESOURCES,
1235 gettext_noop("Sets the maximum number of simultaneously prepared transactions."),
1238 &max_prepared_xacts,
1239 5, 0, INT_MAX, NULL, NULL
1244 {"trace_lock_oidmin", PGC_SUSET, DEVELOPER_OPTIONS,
1245 gettext_noop("no description available"),
1250 FirstNormalObjectId, 0, INT_MAX, NULL, NULL
1253 {"trace_lock_table", PGC_SUSET, DEVELOPER_OPTIONS,
1254 gettext_noop("no description available"),
1259 0, 0, INT_MAX, NULL, NULL
1264 {"statement_timeout", PGC_USERSET, CLIENT_CONN_STATEMENT,
1265 gettext_noop("Sets the maximum allowed duration (in milliseconds) of any statement."),
1266 gettext_noop("A value of 0 turns off the timeout.")
1269 0, 0, INT_MAX, NULL, NULL
1273 {"max_fsm_relations", PGC_POSTMASTER, RESOURCES_FSM,
1274 gettext_noop("Sets the maximum number of tables and indexes for which free space is tracked."),
1278 1000, 100, INT_MAX, NULL, NULL
1281 {"max_fsm_pages", PGC_POSTMASTER, RESOURCES_FSM,
1282 gettext_noop("Sets the maximum number of disk pages for which free space is tracked."),
1286 20000, 1000, INT_MAX, NULL, NULL
1290 {"max_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
1291 gettext_noop("Sets the maximum number of locks per transaction."),
1292 gettext_noop("The shared lock table is sized on the assumption that "
1293 "at most max_locks_per_transaction * max_connections distinct "
1294 "objects will need to be locked at any one time.")
1296 &max_locks_per_xact,
1297 64, 10, INT_MAX, NULL, NULL
1301 {"authentication_timeout", PGC_SIGHUP, CONN_AUTH_SECURITY,
1302 gettext_noop("Sets the maximum time in seconds to complete client authentication."),
1305 &AuthenticationTimeout,
1306 60, 1, 600, NULL, NULL
1310 /* Not for general use */
1311 {"pre_auth_delay", PGC_SIGHUP, DEVELOPER_OPTIONS,
1312 gettext_noop("no description available"),
1317 0, 0, 60, NULL, NULL
1321 {"checkpoint_segments", PGC_SIGHUP, WAL_CHECKPOINTS,
1322 gettext_noop("Sets the maximum distance in log segments between automatic WAL checkpoints."),
1325 &CheckPointSegments,
1326 3, 1, INT_MAX, NULL, NULL
1330 {"checkpoint_timeout", PGC_SIGHUP, WAL_CHECKPOINTS,
1331 gettext_noop("Sets the maximum time in seconds between automatic WAL checkpoints."),
1335 300, 30, 3600, NULL, NULL
1339 {"checkpoint_warning", PGC_SIGHUP, WAL_CHECKPOINTS,
1340 gettext_noop("Logs if filling of checkpoint segments happens more "
1341 "frequently than this (in seconds)."),
1342 gettext_noop("Write a message to the server log if checkpoints "
1343 "caused by the filling of checkpoint segment files happens more "
1344 "frequently than this number of seconds. Zero turns off the warning.")
1347 30, 0, INT_MAX, NULL, NULL
1351 {"wal_buffers", PGC_POSTMASTER, WAL_SETTINGS,
1352 gettext_noop("Sets the number of disk-page buffers in shared memory for WAL."),
1356 8, 4, INT_MAX, NULL, NULL
1360 {"commit_delay", PGC_USERSET, WAL_CHECKPOINTS,
1361 gettext_noop("Sets the delay in microseconds between transaction commit and "
1362 "flushing WAL to disk."),
1366 0, 0, 100000, NULL, NULL
1370 {"commit_siblings", PGC_USERSET, WAL_CHECKPOINTS,
1371 gettext_noop("Sets the minimum concurrent open transactions before performing "
1376 5, 1, 1000, NULL, NULL
1380 {"extra_float_digits", PGC_USERSET, CLIENT_CONN_LOCALE,
1381 gettext_noop("Sets the number of digits displayed for floating-point values."),
1382 gettext_noop("This affects real, double precision, and geometric data types. "
1383 "The parameter value is added to the standard number of digits "
1384 "(FLT_DIG or DBL_DIG as appropriate).")
1386 &extra_float_digits,
1387 0, -15, 2, NULL, NULL
1391 {"log_min_duration_statement", PGC_SUSET, LOGGING_WHEN,
1392 gettext_noop("Sets the minimum execution time in milliseconds above which statements will "
1394 gettext_noop("Zero prints all queries. The default is -1 (turning this feature off).")
1396 &log_min_duration_statement,
1397 -1, -1, INT_MAX / 1000, NULL, NULL
1401 {"bgwriter_delay", PGC_SIGHUP, RESOURCES,
1402 gettext_noop("Background writer sleep time between rounds in milliseconds"),
1406 200, 10, 10000, NULL, NULL
1410 {"bgwriter_lru_maxpages", PGC_SIGHUP, RESOURCES,
1411 gettext_noop("Background writer maximum number of LRU pages to flush per round"),
1414 &bgwriter_lru_maxpages,
1415 5, 0, 1000, NULL, NULL
1419 {"bgwriter_all_maxpages", PGC_SIGHUP, RESOURCES,
1420 gettext_noop("Background writer maximum number of all pages to flush per round"),
1423 &bgwriter_all_maxpages,
1424 5, 0, 1000, NULL, NULL
1428 {"log_rotation_age", PGC_SIGHUP, LOGGING_WHERE,
1429 gettext_noop("Automatic log file rotation will occur after N minutes"),
1433 HOURS_PER_DAY * MINS_PER_HOUR, 0, INT_MAX / MINS_PER_HOUR, NULL, NULL
1437 {"log_rotation_size", PGC_SIGHUP, LOGGING_WHERE,
1438 gettext_noop("Automatic log file rotation will occur after N kilobytes"),
1442 10 * 1024, 0, INT_MAX / 1024, NULL, NULL
1446 {"max_function_args", PGC_INTERNAL, PRESET_OPTIONS,
1447 gettext_noop("Shows the maximum number of function arguments."),
1449 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1452 FUNC_MAX_ARGS, FUNC_MAX_ARGS, FUNC_MAX_ARGS, NULL, NULL
1456 {"max_index_keys", PGC_INTERNAL, PRESET_OPTIONS,
1457 gettext_noop("Shows the maximum number of index keys."),
1459 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1462 INDEX_MAX_KEYS, INDEX_MAX_KEYS, INDEX_MAX_KEYS, NULL, NULL
1466 {"max_identifier_length", PGC_INTERNAL, PRESET_OPTIONS,
1467 gettext_noop("Shows the maximum identifier length"),
1469 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1471 &max_identifier_length,
1472 NAMEDATALEN - 1, NAMEDATALEN - 1, NAMEDATALEN - 1, NULL, NULL
1476 {"block_size", PGC_INTERNAL, PRESET_OPTIONS,
1477 gettext_noop("Shows size of a disk block"),
1479 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1482 BLCKSZ, BLCKSZ, BLCKSZ, NULL, NULL
1486 {"autovacuum_naptime", PGC_SIGHUP, AUTOVACUUM,
1487 gettext_noop("Time to sleep between autovacuum runs, in seconds."),
1490 &autovacuum_naptime,
1491 60, 1, INT_MAX, NULL, NULL
1494 {"autovacuum_vacuum_threshold", PGC_SIGHUP, AUTOVACUUM,
1495 gettext_noop("Minimum number of tuple updates or deletes prior to vacuum."),
1498 &autovacuum_vac_thresh,
1499 1000, 0, INT_MAX, NULL, NULL
1502 {"autovacuum_analyze_threshold", PGC_SIGHUP, AUTOVACUUM,
1503 gettext_noop("Minimum number of tuple inserts, updates or deletes prior to analyze."),
1506 &autovacuum_anl_thresh,
1507 500, 0, INT_MAX, NULL, NULL
1511 {"tcp_keepalives_idle", PGC_USERSET, CLIENT_CONN_OTHER,
1512 gettext_noop("Seconds between issuing TCP keepalives."),
1513 gettext_noop("A value of 0 uses the system default."),
1515 &tcp_keepalives_idle,
1516 0, 0, INT_MAX, assign_tcp_keepalives_idle, show_tcp_keepalives_idle
1520 {"tcp_keepalives_interval", PGC_USERSET, CLIENT_CONN_OTHER,
1521 gettext_noop("Seconds between TCP keepalive retransmits."),
1522 gettext_noop("A value of 0 uses the system default."),
1524 &tcp_keepalives_interval,
1525 0, 0, INT_MAX, assign_tcp_keepalives_interval, show_tcp_keepalives_interval
1529 {"tcp_keepalives_count", PGC_USERSET, CLIENT_CONN_OTHER,
1530 gettext_noop("Maximum number of TCP keepalive retransmits."),
1531 gettext_noop("This controls the number of consecutive keepalive retransmits that can be "
1532 "lost before a connection is considered dead. A value of 0 uses the "
1535 &tcp_keepalives_count,
1536 0, 0, INT_MAX, assign_tcp_keepalives_count, show_tcp_keepalives_count
1539 /* End-of-list marker */
1541 {NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL
1546 static struct config_real ConfigureNamesReal[] =
1549 {"effective_cache_size", PGC_USERSET, QUERY_TUNING_COST,
1550 gettext_noop("Sets the planner's assumption about size of the disk cache."),
1551 gettext_noop("That is, the portion of the kernel's disk cache that "
1552 "will be used for PostgreSQL data files. This is measured in disk "
1553 "pages, which are normally 8 kB each.")
1555 &effective_cache_size,
1556 DEFAULT_EFFECTIVE_CACHE_SIZE, 1, DBL_MAX, NULL, NULL
1559 {"random_page_cost", PGC_USERSET, QUERY_TUNING_COST,
1560 gettext_noop("Sets the planner's estimate of the cost of a nonsequentially "
1561 "fetched disk page."),
1562 gettext_noop("This is measured as a multiple of the cost of a "
1563 "sequential page fetch. A higher value makes it more likely a "
1564 "sequential scan will be used, a lower value makes it more likely an "
1565 "index scan will be used.")
1568 DEFAULT_RANDOM_PAGE_COST, 0, DBL_MAX, NULL, NULL
1571 {"cpu_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
1572 gettext_noop("Sets the planner's estimate of the cost of processing each tuple (row)."),
1573 gettext_noop("This is measured as a fraction of the cost of a "
1574 "sequential page fetch.")
1577 DEFAULT_CPU_TUPLE_COST, 0, DBL_MAX, NULL, NULL
1580 {"cpu_index_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
1581 gettext_noop("Sets the planner's estimate of processing cost for each "
1582 "index tuple (row) during index scan."),
1583 gettext_noop("This is measured as a fraction of the cost of a "
1584 "sequential page fetch.")
1586 &cpu_index_tuple_cost,
1587 DEFAULT_CPU_INDEX_TUPLE_COST, 0, DBL_MAX, NULL, NULL
1590 {"cpu_operator_cost", PGC_USERSET, QUERY_TUNING_COST,
1591 gettext_noop("Sets the planner's estimate of processing cost of each operator in WHERE."),
1592 gettext_noop("This is measured as a fraction of the cost of a sequential "
1596 DEFAULT_CPU_OPERATOR_COST, 0, DBL_MAX, NULL, NULL
1600 {"geqo_selection_bias", PGC_USERSET, QUERY_TUNING_GEQO,
1601 gettext_noop("GEQO: selective pressure within the population."),
1604 &Geqo_selection_bias,
1605 DEFAULT_GEQO_SELECTION_BIAS, MIN_GEQO_SELECTION_BIAS,
1606 MAX_GEQO_SELECTION_BIAS, NULL, NULL
1610 {"bgwriter_lru_percent", PGC_SIGHUP, RESOURCES,
1611 gettext_noop("Background writer percentage of LRU buffers to flush per round"),
1614 &bgwriter_lru_percent,
1615 1.0, 0.0, 100.0, NULL, NULL
1619 {"bgwriter_all_percent", PGC_SIGHUP, RESOURCES,
1620 gettext_noop("Background writer percentage of all buffers to flush per round"),
1623 &bgwriter_all_percent,
1624 0.333, 0.0, 100.0, NULL, NULL
1628 {"seed", PGC_USERSET, UNGROUPED,
1629 gettext_noop("Sets the seed for random-number generation."),
1631 GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1634 0.5, 0.0, 1.0, assign_random_seed, show_random_seed
1638 {"autovacuum_vacuum_scale_factor", PGC_SIGHUP, AUTOVACUUM,
1639 gettext_noop("Number of tuple updates or deletes prior to vacuum as a fraction of reltuples."),
1642 &autovacuum_vac_scale,
1643 0.4, 0.0, 100.0, NULL, NULL
1646 {"autovacuum_analyze_scale_factor", PGC_SIGHUP, AUTOVACUUM,
1647 gettext_noop("Number of tuple inserts, updates or deletes prior to analyze as a fraction of reltuples."),
1650 &autovacuum_anl_scale,
1651 0.2, 0.0, 100.0, NULL, NULL
1654 /* End-of-list marker */
1656 {NULL, 0, 0, NULL, NULL}, NULL, 0.0, 0.0, 0.0, NULL, NULL
1661 static struct config_string ConfigureNamesString[] =
1664 {"archive_command", PGC_SIGHUP, WAL_SETTINGS,
1665 gettext_noop("WAL archiving command."),
1666 gettext_noop("The shell command that will be called to archive a WAL file.")
1668 &XLogArchiveCommand,
1673 {"client_encoding", PGC_USERSET, CLIENT_CONN_LOCALE,
1674 gettext_noop("Sets the client's character set encoding."),
1678 &client_encoding_string,
1679 "SQL_ASCII", assign_client_encoding, NULL
1683 {"client_min_messages", PGC_USERSET, LOGGING_WHEN,
1684 gettext_noop("Sets the message levels that are sent to the client."),
1685 gettext_noop("Valid values are DEBUG5, DEBUG4, DEBUG3, DEBUG2, "
1686 "DEBUG1, LOG, NOTICE, WARNING, and ERROR. Each level includes all the "
1687 "levels that follow it. The later the level, the fewer messages are "
1690 &client_min_messages_str,
1691 "notice", assign_client_min_messages, NULL
1695 {"log_min_messages", PGC_SUSET, LOGGING_WHEN,
1696 gettext_noop("Sets the message levels that are logged."),
1697 gettext_noop("Valid values are DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1, "
1698 "INFO, NOTICE, WARNING, ERROR, LOG, FATAL, and PANIC. Each level "
1699 "includes all the levels that follow it.")
1701 &log_min_messages_str,
1702 "notice", assign_log_min_messages, NULL
1706 {"log_error_verbosity", PGC_SUSET, LOGGING_WHEN,
1707 gettext_noop("Sets the verbosity of logged messages."),
1708 gettext_noop("Valid values are \"terse\", \"default\", and \"verbose\".")
1710 &log_error_verbosity_str,
1711 "default", assign_log_error_verbosity, NULL
1714 {"log_statement", PGC_SUSET, LOGGING_WHAT,
1715 gettext_noop("Sets the type of statements logged."),
1716 gettext_noop("Valid values are \"none\", \"ddl\", \"mod\", and \"all\".")
1719 "none", assign_log_statement, NULL
1723 {"log_min_error_statement", PGC_SUSET, LOGGING_WHEN,
1724 gettext_noop("Causes all statements generating error at or above this level to be logged."),
1725 gettext_noop("All SQL statements that cause an error of the "
1726 "specified level or a higher level are logged.")
1728 &log_min_error_statement_str,
1729 "panic", assign_min_error_statement, NULL
1733 {"log_line_prefix", PGC_SIGHUP, LOGGING_WHAT,
1734 gettext_noop("Controls information prefixed to each log line"),
1735 gettext_noop("if blank no prefix is used")
1743 {"DateStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
1744 gettext_noop("Sets the display format for date and time values."),
1745 gettext_noop("Also controls interpretation of ambiguous "
1747 GUC_LIST_INPUT | GUC_REPORT
1750 "ISO, MDY", assign_datestyle, NULL
1754 {"default_tablespace", PGC_USERSET, CLIENT_CONN_STATEMENT,
1755 gettext_noop("Sets the default tablespace to create tables and indexes in."),
1756 gettext_noop("An empty string selects the database's default tablespace.")
1758 &default_tablespace,
1759 "", assign_default_tablespace, NULL
1763 {"default_transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
1764 gettext_noop("Sets the transaction isolation level of each new transaction."),
1765 gettext_noop("Each SQL transaction has an isolation level, which "
1766 "can be either \"read uncommitted\", \"read committed\", \"repeatable read\", or \"serializable\".")
1768 &default_iso_level_string,
1769 "read committed", assign_defaultxactisolevel, NULL
1773 {"dynamic_library_path", PGC_SUSET, CLIENT_CONN_OTHER,
1774 gettext_noop("Sets the path for dynamically loadable modules."),
1775 gettext_noop("If a dynamically loadable module needs to be opened and "
1776 "the specified name does not have a directory component (i.e., the "
1777 "name does not contain a slash), the system will search this path for "
1778 "the specified file."),
1781 &Dynamic_library_path,
1782 "$libdir", NULL, NULL
1786 {"krb_server_keyfile", PGC_POSTMASTER, CONN_AUTH_SECURITY,
1787 gettext_noop("Sets the location of the Kerberos server key file."),
1791 &pg_krb_server_keyfile,
1792 PG_KRB_SRVTAB, NULL, NULL
1796 {"krb_srvname", PGC_POSTMASTER, CONN_AUTH_SECURITY,
1797 gettext_noop("Sets the name of the Kerberos service."),
1801 PG_KRB_SRVNAM, NULL, NULL
1805 {"krb_server_hostname", PGC_POSTMASTER, CONN_AUTH_SECURITY,
1806 gettext_noop("Sets the hostname of the Kerberos server."),
1809 &pg_krb_server_hostname,
1814 {"bonjour_name", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1815 gettext_noop("Sets the Bonjour broadcast service name."),
1822 /* See main.c about why defaults for LC_foo are not all alike */
1825 {"lc_collate", PGC_INTERNAL, CLIENT_CONN_LOCALE,
1826 gettext_noop("Shows the collation order locale."),
1828 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1835 {"lc_ctype", PGC_INTERNAL, CLIENT_CONN_LOCALE,
1836 gettext_noop("Shows the character classification and case conversion locale."),
1838 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1845 {"lc_messages", PGC_SUSET, CLIENT_CONN_LOCALE,
1846 gettext_noop("Sets the language in which messages are displayed."),
1850 "", locale_messages_assign, NULL
1854 {"lc_monetary", PGC_USERSET, CLIENT_CONN_LOCALE,
1855 gettext_noop("Sets the locale for formatting monetary amounts."),
1859 "C", locale_monetary_assign, NULL
1863 {"lc_numeric", PGC_USERSET, CLIENT_CONN_LOCALE,
1864 gettext_noop("Sets the locale for formatting numbers."),
1868 "C", locale_numeric_assign, NULL
1872 {"lc_time", PGC_USERSET, CLIENT_CONN_LOCALE,
1873 gettext_noop("Sets the locale for formatting date and time values."),
1877 "C", locale_time_assign, NULL
1881 {"preload_libraries", PGC_POSTMASTER, RESOURCES_KERNEL,
1882 gettext_noop("Lists shared libraries to preload into server."),
1884 GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
1886 &preload_libraries_string,
1891 {"regex_flavor", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1892 gettext_noop("Sets the regular expression \"flavor\"."),
1893 gettext_noop("This can be set to advanced, extended, or basic.")
1895 ®ex_flavor_string,
1896 "advanced", assign_regex_flavor, NULL
1900 {"search_path", PGC_USERSET, CLIENT_CONN_STATEMENT,
1901 gettext_noop("Sets the schema search order for names that are not schema-qualified."),
1903 GUC_LIST_INPUT | GUC_LIST_QUOTE
1905 &namespace_search_path,
1906 "\"$user\",public", assign_search_path, NULL
1910 /* Can't be set in postgresql.conf */
1911 {"server_encoding", PGC_INTERNAL, CLIENT_CONN_LOCALE,
1912 gettext_noop("Sets the server (database) character set encoding."),
1914 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1916 &server_encoding_string,
1917 "SQL_ASCII", NULL, NULL
1921 /* Can't be set in postgresql.conf */
1922 {"server_version", PGC_INTERNAL, PRESET_OPTIONS,
1923 gettext_noop("Shows the server version."),
1925 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1927 &server_version_string,
1928 PG_VERSION, NULL, NULL
1932 /* Not for general use --- used by SET ROLE */
1933 {"role", PGC_USERSET, UNGROUPED,
1934 gettext_noop("Sets the current role."),
1936 GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1939 "none", assign_role, show_role
1943 /* Not for general use --- used by SET SESSION AUTHORIZATION */
1944 {"session_authorization", PGC_USERSET, UNGROUPED,
1945 gettext_noop("Sets the session user name."),
1947 GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1949 &session_authorization_string,
1950 NULL, assign_session_authorization, show_session_authorization
1954 {"log_destination", PGC_SIGHUP, LOGGING_WHERE,
1955 gettext_noop("Sets the destination for server log output."),
1956 gettext_noop("Valid values are combinations of \"stderr\", \"syslog\", "
1957 "and \"eventlog\", depending on the platform."),
1960 &log_destination_string,
1961 "stderr", assign_log_destination, NULL
1964 {"log_directory", PGC_SIGHUP, LOGGING_WHERE,
1965 gettext_noop("Sets the destination directory for log files."),
1966 gettext_noop("May be specified as relative to the data directory "
1967 "or as absolute path."),
1971 "pg_log", assign_canonical_path, NULL
1974 {"log_filename", PGC_SIGHUP, LOGGING_WHERE,
1975 gettext_noop("Sets the file name pattern for log files."),
1980 "postgresql-%Y-%m-%d_%H%M%S.log", NULL, NULL
1985 {"syslog_facility", PGC_SIGHUP, LOGGING_WHERE,
1986 gettext_noop("Sets the syslog \"facility\" to be used when syslog enabled."),
1987 gettext_noop("Valid values are LOCAL0, LOCAL1, LOCAL2, LOCAL3, "
1988 "LOCAL4, LOCAL5, LOCAL6, LOCAL7.")
1990 &syslog_facility_str,
1991 "LOCAL0", assign_syslog_facility, NULL
1994 {"syslog_ident", PGC_SIGHUP, LOGGING_WHERE,
1995 gettext_noop("Sets the program name used to identify PostgreSQL "
1996 "messages in syslog."),
2000 "postgres", assign_syslog_ident, NULL
2005 {"TimeZone", PGC_USERSET, CLIENT_CONN_LOCALE,
2006 gettext_noop("Sets the time zone for displaying and interpreting time stamps."),
2011 "UNKNOWN", assign_timezone, show_timezone
2015 {"transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
2016 gettext_noop("Sets the current transaction's isolation level."),
2018 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2020 &XactIsoLevel_string,
2021 NULL, assign_XactIsoLevel, show_XactIsoLevel
2025 {"unix_socket_group", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2026 gettext_noop("Sets the owning group of the Unix-domain socket."),
2027 gettext_noop("(The owning user of the socket is always the user "
2028 "that starts the server.)")
2035 {"unix_socket_directory", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2036 gettext_noop("Sets the directory where the Unix-domain socket will be created."),
2041 "", assign_canonical_path, NULL
2045 {"listen_addresses", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2046 gettext_noop("Sets the host name or IP address(es) to listen to."),
2051 "localhost", NULL, NULL
2055 {"wal_sync_method", PGC_SIGHUP, WAL_SETTINGS,
2056 gettext_noop("Selects the method used for forcing WAL updates out to disk."),
2060 XLOG_sync_method_default, assign_xlog_sync_method, NULL
2064 {"custom_variable_classes", PGC_SIGHUP, CUSTOM_OPTIONS,
2065 gettext_noop("Sets the list of known custom variable classes."),
2067 GUC_LIST_INPUT | GUC_LIST_QUOTE
2069 &custom_variable_classes,
2070 NULL, assign_custom_variable_classes, NULL
2074 {"data_directory", PGC_POSTMASTER, FILE_LOCATIONS,
2075 gettext_noop("Sets the server's data directory."),
2084 {"config_file", PGC_POSTMASTER, FILE_LOCATIONS,
2085 gettext_noop("Sets the server's main configuration file."),
2087 GUC_DISALLOW_IN_FILE | GUC_SUPERUSER_ONLY
2094 {"hba_file", PGC_POSTMASTER, FILE_LOCATIONS,
2095 gettext_noop("Sets the server's \"hba\" configuration file"),
2104 {"ident_file", PGC_POSTMASTER, FILE_LOCATIONS,
2105 gettext_noop("Sets the server's \"ident\" configuration file"),
2114 {"external_pid_file", PGC_POSTMASTER, FILE_LOCATIONS,
2115 gettext_noop("Writes the postmaster PID to the specified file."),
2120 NULL, assign_canonical_path, NULL
2123 /* End-of-list marker */
2125 {NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL
2130 /******** end of options list ********/
2134 * To allow continued support of obsolete names for GUC variables, we apply
2135 * the following mappings to any unrecognized name. Note that an old name
2136 * should be mapped to a new one only if the new variable has very similar
2137 * semantics to the old.
2139 static const char *const map_old_guc_names[] = {
2140 "sort_mem", "work_mem",
2141 "vacuum_mem", "maintenance_work_mem",
2147 * Actual lookup of variables is done through this single, sorted array.
2149 static struct config_generic **guc_variables;
2151 /* Current number of variables contained in the vector */
2152 static int num_guc_variables;
2154 /* Vector capacity */
2155 static int size_guc_variables;
2158 static bool guc_dirty; /* TRUE if need to do commit/abort work */
2160 static bool reporting_enabled; /* TRUE to enable GUC_REPORT */
2163 static int guc_var_compare(const void *a, const void *b);
2164 static int guc_name_compare(const char *namea, const char *nameb);
2165 static void push_old_value(struct config_generic * gconf);
2166 static void ReportGUCOption(struct config_generic * record);
2167 static void ShowGUCConfigOption(const char *name, DestReceiver *dest);
2168 static void ShowAllGUCConfig(DestReceiver *dest);
2169 static char *_ShowOption(struct config_generic * record);
2173 * Some infrastructure for checking malloc/strdup/realloc calls
2176 guc_malloc(int elevel, size_t size)
2180 data = malloc(size);
2183 (errcode(ERRCODE_OUT_OF_MEMORY),
2184 errmsg("out of memory")));
2189 guc_realloc(int elevel, void *old, size_t size)
2193 data = realloc(old, size);
2196 (errcode(ERRCODE_OUT_OF_MEMORY),
2197 errmsg("out of memory")));
2202 guc_strdup(int elevel, const char *src)
2209 (errcode(ERRCODE_OUT_OF_MEMORY),
2210 errmsg("out of memory")));
2216 * Support for assigning to a field of a string GUC item. Free the prior
2217 * value if it's not referenced anywhere else in the item (including stacked
2221 set_string_field(struct config_string * conf, char **field, char *newval)
2223 char *oldval = *field;
2226 /* Do the assignment */
2229 /* Exit if any duplicate references, or if old value was NULL anyway */
2230 if (oldval == NULL ||
2231 oldval == *(conf->variable) ||
2232 oldval == conf->reset_val ||
2233 oldval == conf->tentative_val)
2235 for (stack = conf->gen.stack; stack; stack = stack->prev)
2237 if (oldval == stack->tentative_val.stringval ||
2238 oldval == stack->value.stringval)
2242 /* Not used anymore, so free it */
2247 * Detect whether strval is referenced anywhere in a GUC string item
2250 string_field_used(struct config_string * conf, char *strval)
2254 if (strval == *(conf->variable) ||
2255 strval == conf->reset_val ||
2256 strval == conf->tentative_val)
2258 for (stack = conf->gen.stack; stack; stack = stack->prev)
2260 if (strval == stack->tentative_val.stringval ||
2261 strval == stack->value.stringval)
2268 struct config_generic **
2269 get_guc_variables(void)
2271 return guc_variables;
2276 * Build the sorted array. This is split out so that it could be
2277 * re-executed after startup (eg, we could allow loadable modules to
2278 * add vars, and then we'd need to re-sort).
2281 build_guc_variables(void)
2285 struct config_generic **guc_vars;
2288 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
2290 struct config_bool *conf = &ConfigureNamesBool[i];
2292 /* Rather than requiring vartype to be filled in by hand, do this: */
2293 conf->gen.vartype = PGC_BOOL;
2297 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
2299 struct config_int *conf = &ConfigureNamesInt[i];
2301 conf->gen.vartype = PGC_INT;
2305 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
2307 struct config_real *conf = &ConfigureNamesReal[i];
2309 conf->gen.vartype = PGC_REAL;
2313 for (i = 0; ConfigureNamesString[i].gen.name; i++)
2315 struct config_string *conf = &ConfigureNamesString[i];
2317 conf->gen.vartype = PGC_STRING;
2322 * Create table with 20% slack
2324 size_vars = num_vars + num_vars / 4;
2326 guc_vars = (struct config_generic **)
2327 guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
2331 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
2332 guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
2334 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
2335 guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
2337 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
2338 guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
2340 for (i = 0; ConfigureNamesString[i].gen.name; i++)
2341 guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
2344 free(guc_variables);
2345 guc_variables = guc_vars;
2346 num_guc_variables = num_vars;
2347 size_guc_variables = size_vars;
2348 qsort((void *) guc_variables, num_guc_variables,
2349 sizeof(struct config_generic *), guc_var_compare);
2353 is_custom_class(const char *name, int dotPos)
2356 * assign_custom_variable_classes() has made sure no empty identifiers or
2357 * whitespace exists in the variable
2359 bool result = false;
2360 const char *ccs = GetConfigOption("custom_variable_classes");
2364 const char *start = ccs;
2370 if (c == 0 || c == ',')
2372 if (dotPos == ccs - start && strncmp(start, name, dotPos) == 0)
2387 * Add a new GUC variable to the list of known variables. The
2388 * list is expanded if needed.
2391 add_guc_variable(struct config_generic * var, int elevel)
2393 if (num_guc_variables + 1 >= size_guc_variables)
2396 * Increase the vector by 25%
2398 int size_vars = size_guc_variables + size_guc_variables / 4;
2399 struct config_generic **guc_vars;
2404 guc_vars = (struct config_generic **)
2405 guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
2409 guc_vars = (struct config_generic **)
2410 guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
2413 if (guc_vars == NULL)
2414 return false; /* out of memory */
2416 guc_variables = guc_vars;
2417 size_guc_variables = size_vars;
2419 guc_variables[num_guc_variables++] = var;
2420 qsort((void *) guc_variables, num_guc_variables,
2421 sizeof(struct config_generic *), guc_var_compare);
2426 * Create and add a placeholder variable. It's presumed to belong
2427 * to a valid custom variable class at this point.
2429 static struct config_string *
2430 add_placeholder_variable(const char *name, int elevel)
2432 size_t sz = sizeof(struct config_string) + sizeof(char *);
2433 struct config_string *var;
2434 struct config_generic *gen;
2436 var = (struct config_string *) guc_malloc(elevel, sz);
2443 gen->name = guc_strdup(elevel, name);
2444 if (gen->name == NULL)
2450 gen->context = PGC_USERSET;
2451 gen->group = CUSTOM_OPTIONS;
2452 gen->short_desc = "GUC placeholder variable";
2453 gen->flags = GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_CUSTOM_PLACEHOLDER;
2454 gen->vartype = PGC_STRING;
2457 * The char* is allocated at the end of the struct since we have no
2458 * 'static' place to point to.
2460 var->variable = (char **) (var + 1);
2462 if (!add_guc_variable((struct config_generic *) var, elevel))
2464 free((void *) gen->name);
2473 * Look up option NAME. If it exists, return a pointer to its record,
2476 static struct config_generic *
2477 find_option(const char *name, int elevel)
2480 const char **key = &name;
2481 struct config_generic **res;
2487 * By equating const char ** with struct config_generic *, we are assuming
2488 * the name field is first in config_generic.
2490 res = (struct config_generic **) bsearch((void *) &key,
2491 (void *) guc_variables,
2493 sizeof(struct config_generic *),
2499 * See if the name is an obsolete name for a variable. We assume that the
2500 * set of supported old names is short enough that a brute-force search is
2503 for (i = 0; map_old_guc_names[i] != NULL; i += 2)
2505 if (guc_name_compare(name, map_old_guc_names[i]) == 0)
2506 return find_option(map_old_guc_names[i + 1], elevel);
2510 * Check if the name is qualified, and if so, check if the qualifier maps
2511 * to a custom variable class.
2513 dot = strchr(name, GUC_QUALIFIER_SEPARATOR);
2514 if (dot != NULL && is_custom_class(name, dot - name))
2515 /* Add a placeholder variable for this name */
2516 return (struct config_generic *) add_placeholder_variable(name, elevel);
2524 * comparator for qsorting and bsearching guc_variables array
2527 guc_var_compare(const void *a, const void *b)
2529 struct config_generic *confa = *(struct config_generic **) a;
2530 struct config_generic *confb = *(struct config_generic **) b;
2532 return guc_name_compare(confa->name, confb->name);
2537 guc_name_compare(const char *namea, const char *nameb)
2540 * The temptation to use strcasecmp() here must be resisted, because the
2541 * array ordering has to remain stable across setlocale() calls. So, build
2542 * our own with a simple ASCII-only downcasing.
2544 while (*namea && *nameb)
2546 char cha = *namea++;
2547 char chb = *nameb++;
2549 if (cha >= 'A' && cha <= 'Z')
2551 if (chb >= 'A' && chb <= 'Z')
2557 return 1; /* a is longer */
2559 return -1; /* b is longer */
2565 * Initialize GUC options during program startup.
2567 * Note that we cannot read the config file yet, since we have not yet
2568 * processed command-line switches.
2571 InitializeGUCOptions(void)
2577 * Build sorted array of all GUC variables.
2579 build_guc_variables();
2582 * Load all variables with their compiled-in defaults, and initialize
2583 * status fields as needed.
2585 for (i = 0; i < num_guc_variables; i++)
2587 struct config_generic *gconf = guc_variables[i];
2590 gconf->reset_source = PGC_S_DEFAULT;
2591 gconf->tentative_source = PGC_S_DEFAULT;
2592 gconf->source = PGC_S_DEFAULT;
2593 gconf->stack = NULL;
2595 switch (gconf->vartype)
2599 struct config_bool *conf = (struct config_bool *) gconf;
2601 if (conf->assign_hook)
2602 if (!(*conf->assign_hook) (conf->reset_val, true,
2604 elog(FATAL, "failed to initialize %s to %d",
2605 conf->gen.name, (int) conf->reset_val);
2606 *conf->variable = conf->reset_val;
2611 struct config_int *conf = (struct config_int *) gconf;
2613 Assert(conf->reset_val >= conf->min);
2614 Assert(conf->reset_val <= conf->max);
2615 if (conf->assign_hook)
2616 if (!(*conf->assign_hook) (conf->reset_val, true,
2618 elog(FATAL, "failed to initialize %s to %d",
2619 conf->gen.name, conf->reset_val);
2620 *conf->variable = conf->reset_val;
2625 struct config_real *conf = (struct config_real *) gconf;
2627 Assert(conf->reset_val >= conf->min);
2628 Assert(conf->reset_val <= conf->max);
2629 if (conf->assign_hook)
2630 if (!(*conf->assign_hook) (conf->reset_val, true,
2632 elog(FATAL, "failed to initialize %s to %g",
2633 conf->gen.name, conf->reset_val);
2634 *conf->variable = conf->reset_val;
2639 struct config_string *conf = (struct config_string *) gconf;
2642 *conf->variable = NULL;
2643 conf->reset_val = NULL;
2644 conf->tentative_val = NULL;
2646 if (conf->boot_val == NULL)
2648 /* Cannot set value yet */
2652 str = guc_strdup(FATAL, conf->boot_val);
2653 conf->reset_val = str;
2655 if (conf->assign_hook)
2659 newstr = (*conf->assign_hook) (str, true,
2663 elog(FATAL, "failed to initialize %s to \"%s\"",
2664 conf->gen.name, str);
2666 else if (newstr != str)
2671 * See notes in set_config_option about casting
2673 str = (char *) newstr;
2674 conf->reset_val = str;
2677 *conf->variable = str;
2685 reporting_enabled = false;
2688 * Prevent any attempt to override the transaction modes from
2689 * non-interactive sources.
2691 SetConfigOption("transaction_isolation", "default",
2692 PGC_POSTMASTER, PGC_S_OVERRIDE);
2693 SetConfigOption("transaction_read_only", "no",
2694 PGC_POSTMASTER, PGC_S_OVERRIDE);
2697 * For historical reasons, some GUC parameters can receive defaults from
2698 * environment variables. Process those settings.
2701 env = getenv("PGPORT");
2703 SetConfigOption("port", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
2705 env = getenv("PGDATESTYLE");
2707 SetConfigOption("datestyle", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
2709 env = getenv("PGCLIENTENCODING");
2711 SetConfigOption("client_encoding", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
2716 * Select the configuration files and data directory to be used, and
2717 * do the initial read of postgresql.conf.
2719 * This is called after processing command-line switches.
2720 * userDoption is the -D switch value if any (NULL if unspecified).
2721 * progname is just for use in error messages.
2723 * Returns true on success; on failure, prints a suitable error message
2724 * to stderr and returns false.
2727 SelectConfigFiles(const char *userDoption, const char *progname)
2731 struct stat stat_buf;
2733 /* configdir is -D option, or $PGDATA if no -D */
2735 configdir = make_absolute_path(userDoption);
2737 configdir = make_absolute_path(getenv("PGDATA"));
2740 * Find the configuration file: if config_file was specified on the
2741 * command line, use it, else use configdir/postgresql.conf. In any case
2742 * ensure the result is an absolute path, so that it will be interpreted
2743 * the same way by future backends.
2746 fname = make_absolute_path(ConfigFileName);
2749 fname = guc_malloc(FATAL,
2750 strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
2751 sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
2755 write_stderr("%s does not know where to find the server configuration file.\n"
2756 "You must specify the --config-file or -D invocation "
2757 "option or set the PGDATA environment variable.\n",
2763 * Set the ConfigFileName GUC variable to its final value, ensuring that
2764 * it can't be overridden later.
2766 SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
2770 * Now read the config file for the first time.
2772 if (stat(ConfigFileName, &stat_buf) != 0)
2774 write_stderr("%s cannot access the server configuration file \"%s\": %s\n",
2775 progname, ConfigFileName, strerror(errno));
2779 ProcessConfigFile(PGC_POSTMASTER);
2782 * If the data_directory GUC variable has been set, use that as DataDir;
2783 * otherwise use configdir if set; else punt.
2785 * Note: SetDataDir will copy and absolute-ize its argument, so we don't
2789 SetDataDir(data_directory);
2791 SetDataDir(configdir);
2794 write_stderr("%s does not know where to find the database system data.\n"
2795 "This can be specified as \"data_directory\" in \"%s\", "
2796 "or by the -D invocation option, or by the "
2797 "PGDATA environment variable.\n",
2798 progname, ConfigFileName);
2803 * Reflect the final DataDir value back into the data_directory GUC var.
2804 * (If you are wondering why we don't just make them a single variable,
2805 * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
2806 * child backends specially. XXX is that still true? Given that we now
2807 * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
2808 * DataDir in advance.)
2810 SetConfigOption("data_directory", DataDir, PGC_POSTMASTER, PGC_S_OVERRIDE);
2813 * Figure out where pg_hba.conf is, and make sure the path is absolute.
2816 fname = make_absolute_path(HbaFileName);
2819 fname = guc_malloc(FATAL,
2820 strlen(configdir) + strlen(HBA_FILENAME) + 2);
2821 sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
2825 write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
2826 "This can be specified as \"hba_file\" in \"%s\", "
2827 "or by the -D invocation option, or by the "
2828 "PGDATA environment variable.\n",
2829 progname, ConfigFileName);
2832 SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
2836 * Likewise for pg_ident.conf.
2839 fname = make_absolute_path(IdentFileName);
2842 fname = guc_malloc(FATAL,
2843 strlen(configdir) + strlen(IDENT_FILENAME) + 2);
2844 sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
2848 write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
2849 "This can be specified as \"ident_file\" in \"%s\", "
2850 "or by the -D invocation option, or by the "
2851 "PGDATA environment variable.\n",
2852 progname, ConfigFileName);
2855 SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
2865 * Reset all options to their saved default values (implements RESET ALL)
2868 ResetAllOptions(void)
2872 for (i = 0; i < num_guc_variables; i++)
2874 struct config_generic *gconf = guc_variables[i];
2876 /* Don't reset non-SET-able values */
2877 if (gconf->context != PGC_SUSET &&
2878 gconf->context != PGC_USERSET)
2880 /* Don't reset if special exclusion from RESET ALL */
2881 if (gconf->flags & GUC_NO_RESET_ALL)
2883 /* No need to reset if wasn't SET */
2884 if (gconf->source <= PGC_S_OVERRIDE)
2887 /* Save old value to support transaction abort */
2888 push_old_value(gconf);
2890 switch (gconf->vartype)
2894 struct config_bool *conf = (struct config_bool *) gconf;
2896 if (conf->assign_hook)
2897 if (!(*conf->assign_hook) (conf->reset_val, true,
2899 elog(ERROR, "failed to reset %s", conf->gen.name);
2900 *conf->variable = conf->reset_val;
2901 conf->tentative_val = conf->reset_val;
2902 conf->gen.source = conf->gen.reset_source;
2903 conf->gen.tentative_source = conf->gen.reset_source;
2904 conf->gen.status |= GUC_HAVE_TENTATIVE;
2910 struct config_int *conf = (struct config_int *) gconf;
2912 if (conf->assign_hook)
2913 if (!(*conf->assign_hook) (conf->reset_val, true,
2915 elog(ERROR, "failed to reset %s", conf->gen.name);
2916 *conf->variable = conf->reset_val;
2917 conf->tentative_val = conf->reset_val;
2918 conf->gen.source = conf->gen.reset_source;
2919 conf->gen.tentative_source = conf->gen.reset_source;
2920 conf->gen.status |= GUC_HAVE_TENTATIVE;
2926 struct config_real *conf = (struct config_real *) gconf;
2928 if (conf->assign_hook)
2929 if (!(*conf->assign_hook) (conf->reset_val, true,
2931 elog(ERROR, "failed to reset %s", conf->gen.name);
2932 *conf->variable = conf->reset_val;
2933 conf->tentative_val = conf->reset_val;
2934 conf->gen.source = conf->gen.reset_source;
2935 conf->gen.tentative_source = conf->gen.reset_source;
2936 conf->gen.status |= GUC_HAVE_TENTATIVE;
2942 struct config_string *conf = (struct config_string *) gconf;
2945 if (conf->reset_val == NULL)
2947 /* Nothing to reset to, as yet; so do nothing */
2951 /* We need not strdup here */
2952 str = conf->reset_val;
2954 if (conf->assign_hook)
2958 newstr = (*conf->assign_hook) (str, true,
2961 elog(ERROR, "failed to reset %s", conf->gen.name);
2962 else if (newstr != str)
2965 * See notes in set_config_option about casting
2967 str = (char *) newstr;
2971 set_string_field(conf, conf->variable, str);
2972 set_string_field(conf, &conf->tentative_val, str);
2973 conf->gen.source = conf->gen.reset_source;
2974 conf->gen.tentative_source = conf->gen.reset_source;
2975 conf->gen.status |= GUC_HAVE_TENTATIVE;
2981 if (gconf->flags & GUC_REPORT)
2982 ReportGUCOption(gconf);
2989 * Push previous state during first assignment to a GUC variable
2990 * within a particular transaction.
2992 * We have to be willing to "back-fill" the state stack if the first
2993 * assignment occurs within a subtransaction nested several levels deep.
2994 * This ensures that if an intermediate transaction aborts, it will have
2995 * the proper value available to restore the setting to.
2998 push_old_value(struct config_generic * gconf)
3000 int my_level = GetCurrentTransactionNestLevel();
3003 /* If we're not inside a transaction, do nothing */
3009 /* Done if we already pushed it at this nesting depth */
3010 if (gconf->stack && gconf->stack->nest_level >= my_level)
3014 * We keep all the stack entries in TopTransactionContext so as to
3015 * avoid allocation problems when a subtransaction back-fills stack
3016 * entries for upper transaction levels.
3018 stack = (GucStack *) MemoryContextAlloc(TopTransactionContext,
3021 stack->prev = gconf->stack;
3022 stack->nest_level = stack->prev ? stack->prev->nest_level + 1 : 1;
3023 stack->status = gconf->status;
3024 stack->tentative_source = gconf->tentative_source;
3025 stack->source = gconf->source;
3027 switch (gconf->vartype)
3030 stack->tentative_val.boolval =
3031 ((struct config_bool *) gconf)->tentative_val;
3032 stack->value.boolval =
3033 *((struct config_bool *) gconf)->variable;
3037 stack->tentative_val.intval =
3038 ((struct config_int *) gconf)->tentative_val;
3039 stack->value.intval =
3040 *((struct config_int *) gconf)->variable;
3044 stack->tentative_val.realval =
3045 ((struct config_real *) gconf)->tentative_val;
3046 stack->value.realval =
3047 *((struct config_real *) gconf)->variable;
3051 stack->tentative_val.stringval =
3052 ((struct config_string *) gconf)->tentative_val;
3053 stack->value.stringval =
3054 *((struct config_string *) gconf)->variable;
3058 gconf->stack = stack;
3060 /* Set state to indicate nothing happened yet within this level */
3061 gconf->status = GUC_HAVE_STACK;
3063 /* Ensure we remember to pop at end of xact */
3069 * Do GUC processing at transaction or subtransaction commit or abort.
3072 AtEOXact_GUC(bool isCommit, bool isSubXact)
3077 /* Quick exit if nothing's changed in this transaction */
3081 my_level = GetCurrentTransactionNestLevel();
3082 Assert(isSubXact ? (my_level > 1) : (my_level == 1));
3084 for (i = 0; i < num_guc_variables; i++)
3086 struct config_generic *gconf = guc_variables[i];
3087 int my_status = gconf->status;
3088 GucStack *stack = gconf->stack;
3093 * Skip if nothing's happened to this var in this transaction
3097 Assert(stack == NULL);
3100 /* Assert that we stacked old value before changing it */
3101 Assert(stack != NULL && (my_status & GUC_HAVE_STACK));
3102 /* However, the last change may have been at an outer xact level */
3103 if (stack->nest_level < my_level)
3105 Assert(stack->nest_level == my_level);
3108 * We will pop the stack entry. Start by restoring outer xact status
3109 * (since we may want to modify it below). Be careful to use
3110 * my_status to reference the inner xact status below this point...
3112 gconf->status = stack->status;
3115 * We have two cases:
3117 * If commit and HAVE_TENTATIVE, set actual value to tentative (this
3118 * is to override a SET LOCAL if one occurred later than SET). We keep
3119 * the tentative value and propagate HAVE_TENTATIVE to the parent
3120 * status, allowing the SET's effect to percolate up. (But if we're
3121 * exiting the outermost transaction, we'll drop the HAVE_TENTATIVE
3124 * Otherwise, we have a transaction that aborted or executed only SET
3125 * LOCAL (or no SET at all). In either case it should have no further
3126 * effect, so restore both tentative and actual values from the stack
3130 useTentative = isCommit && (my_status & GUC_HAVE_TENTATIVE) != 0;
3133 switch (gconf->vartype)
3137 struct config_bool *conf = (struct config_bool *) gconf;
3139 GucSource newsource;
3143 newval = conf->tentative_val;
3144 newsource = conf->gen.tentative_source;
3145 conf->gen.status |= GUC_HAVE_TENTATIVE;
3149 newval = stack->value.boolval;
3150 newsource = stack->source;
3151 conf->tentative_val = stack->tentative_val.boolval;
3152 conf->gen.tentative_source = stack->tentative_source;
3155 if (*conf->variable != newval)
3157 if (conf->assign_hook)
3158 if (!(*conf->assign_hook) (newval,
3159 true, PGC_S_OVERRIDE))
3160 elog(LOG, "failed to commit %s",
3162 *conf->variable = newval;
3165 conf->gen.source = newsource;
3170 struct config_int *conf = (struct config_int *) gconf;
3172 GucSource newsource;
3176 newval = conf->tentative_val;
3177 newsource = conf->gen.tentative_source;
3178 conf->gen.status |= GUC_HAVE_TENTATIVE;
3182 newval = stack->value.intval;
3183 newsource = stack->source;
3184 conf->tentative_val = stack->tentative_val.intval;
3185 conf->gen.tentative_source = stack->tentative_source;
3188 if (*conf->variable != newval)
3190 if (conf->assign_hook)
3191 if (!(*conf->assign_hook) (newval,
3192 true, PGC_S_OVERRIDE))
3193 elog(LOG, "failed to commit %s",
3195 *conf->variable = newval;
3198 conf->gen.source = newsource;
3203 struct config_real *conf = (struct config_real *) gconf;
3205 GucSource newsource;
3209 newval = conf->tentative_val;
3210 newsource = conf->gen.tentative_source;
3211 conf->gen.status |= GUC_HAVE_TENTATIVE;
3215 newval = stack->value.realval;
3216 newsource = stack->source;
3217 conf->tentative_val = stack->tentative_val.realval;
3218 conf->gen.tentative_source = stack->tentative_source;
3221 if (*conf->variable != newval)
3223 if (conf->assign_hook)
3224 if (!(*conf->assign_hook) (newval,
3225 true, PGC_S_OVERRIDE))
3226 elog(LOG, "failed to commit %s",
3228 *conf->variable = newval;
3231 conf->gen.source = newsource;
3236 struct config_string *conf = (struct config_string *) gconf;
3238 GucSource newsource;
3242 newval = conf->tentative_val;
3243 newsource = conf->gen.tentative_source;
3244 conf->gen.status |= GUC_HAVE_TENTATIVE;
3248 newval = stack->value.stringval;
3249 newsource = stack->source;
3250 set_string_field(conf, &conf->tentative_val,
3251 stack->tentative_val.stringval);
3252 conf->gen.tentative_source = stack->tentative_source;
3255 if (*conf->variable != newval)
3257 if (conf->assign_hook)
3261 newstr = (*conf->assign_hook) (newval, true,
3264 elog(LOG, "failed to commit %s",
3266 else if (newstr != newval)
3269 * If newval should now be freed, it'll be
3270 * taken care of below.
3272 * See notes in set_config_option about
3275 newval = (char *) newstr;
3279 set_string_field(conf, conf->variable, newval);
3282 conf->gen.source = newsource;
3283 /* Release stacked values if not used anymore */
3284 set_string_field(conf, &stack->value.stringval,
3286 set_string_field(conf, &stack->tentative_val.stringval,
3288 /* Don't store tentative value separately after commit */
3290 set_string_field(conf, &conf->tentative_val, NULL);
3295 /* Finish popping the state stack */
3296 gconf->stack = stack->prev;
3300 * If we're now out of all xact levels, forget TENTATIVE status bit;
3301 * there's nothing tentative about the value anymore.
3305 Assert(gconf->stack == NULL);
3309 /* Report new value if we changed it */
3310 if (changed && (gconf->flags & GUC_REPORT))
3311 ReportGUCOption(gconf);
3315 * If we're now out of all xact levels, we can clear guc_dirty. (Note: we
3316 * cannot reset guc_dirty when exiting a subtransaction, because we know
3317 * that all outer transaction levels will have stacked values to deal
3326 * Start up automatic reporting of changes to variables marked GUC_REPORT.
3327 * This is executed at completion of backend startup.
3330 BeginReportingGUCOptions(void)
3335 * Don't do anything unless talking to an interactive frontend of protocol
3338 if (whereToSendOutput != DestRemote ||
3339 PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
3342 reporting_enabled = true;
3344 /* Transmit initial values of interesting variables */
3345 for (i = 0; i < num_guc_variables; i++)
3347 struct config_generic *conf = guc_variables[i];
3349 if (conf->flags & GUC_REPORT)
3350 ReportGUCOption(conf);
3355 * ReportGUCOption: if appropriate, transmit option value to frontend
3358 ReportGUCOption(struct config_generic * record)
3360 if (reporting_enabled && (record->flags & GUC_REPORT))
3362 char *val = _ShowOption(record);
3363 StringInfoData msgbuf;
3365 pq_beginmessage(&msgbuf, 'S');
3366 pq_sendstring(&msgbuf, record->name);
3367 pq_sendstring(&msgbuf, val);
3368 pq_endmessage(&msgbuf);
3376 * Try to interpret value as boolean value. Valid values are: true,
3377 * false, yes, no, on, off, 1, 0. If the string parses okay, return
3378 * true, else false. If result is not NULL, return the parsing result
3382 parse_bool(const char *value, bool *result)
3384 size_t len = strlen(value);
3386 if (pg_strncasecmp(value, "true", len) == 0)
3391 else if (pg_strncasecmp(value, "false", len) == 0)
3397 else if (pg_strncasecmp(value, "yes", len) == 0)
3402 else if (pg_strncasecmp(value, "no", len) == 0)
3408 else if (pg_strcasecmp(value, "on") == 0)
3413 else if (pg_strcasecmp(value, "off") == 0)
3419 else if (pg_strcasecmp(value, "1") == 0)
3424 else if (pg_strcasecmp(value, "0") == 0)
3433 *result = false; /* suppress compiler warning */
3442 * Try to parse value as an integer. The accepted formats are the
3443 * usual decimal, octal, or hexadecimal formats. If the string parses
3444 * okay, return true, else false. If result is not NULL, return the
3448 parse_int(const char *value, int *result)
3454 val = strtol(value, &endptr, 0);
3455 if (endptr == value || *endptr != '\0' || errno == ERANGE
3456 #ifdef HAVE_LONG_INT_64
3457 /* if long > 32 bits, check for overflow of int4 */
3458 || val != (long) ((int32) val)
3463 *result = 0; /* suppress compiler warning */
3467 *result = (int) val;
3474 * Try to parse value as a floating point constant in the usual
3475 * format. If the value parsed okay return true, else false. If
3476 * result is not NULL, return the semantic value there.
3479 parse_real(const char *value, double *result)
3485 val = strtod(value, &endptr);
3486 if (endptr == value || *endptr != '\0' || errno == ERANGE)
3489 *result = 0; /* suppress compiler warning */
3499 * Call a GucStringAssignHook function, being careful to free the
3500 * "newval" string if the hook ereports.
3502 * This is split out of set_config_option just to avoid the "volatile"
3503 * qualifiers that would otherwise have to be plastered all over.
3506 call_string_assign_hook(GucStringAssignHook assign_hook,
3507 char *newval, bool doit, GucSource source)
3513 result = (*assign_hook) (newval, doit, source);
3527 * Sets option `name' to given value. The value should be a string
3528 * which is going to be parsed and converted to the appropriate data
3529 * type. The context and source parameters indicate in which context this
3530 * function is being called so it can apply the access restrictions
3533 * If value is NULL, set the option to its default value. If the
3534 * parameter changeVal is false then don't really set the option but do all
3535 * the checks to see if it would work.
3537 * If there is an error (non-existing option, invalid value) then an
3538 * ereport(ERROR) is thrown *unless* this is called in a context where we
3539 * don't want to ereport (currently, startup or SIGHUP config file reread).
3540 * In that case we write a suitable error message via ereport(DEBUG) and
3541 * return false. This is working around the deficiencies in the ereport
3542 * mechanism, so don't blame me. In all other cases, the function
3543 * returns true, including cases where the input is valid but we chose
3544 * not to apply it because of context or source-priority considerations.
3546 * See also SetConfigOption for an external interface.
3549 set_config_option(const char *name, const char *value,
3550 GucContext context, GucSource source,
3551 bool isLocal, bool changeVal)
3553 struct config_generic *record;
3557 if (context == PGC_SIGHUP || source == PGC_S_DEFAULT)
3560 * To avoid cluttering the log, only the postmaster bleats loudly
3561 * about problems with the config file.
3563 elevel = IsUnderPostmaster ? DEBUG2 : LOG;
3565 else if (source == PGC_S_DATABASE || source == PGC_S_USER)
3570 record = find_option(name, elevel);
3574 (errcode(ERRCODE_UNDEFINED_OBJECT),
3575 errmsg("unrecognized configuration parameter \"%s\"", name)));
3580 * Check if the option can be set at this time. See guc.h for the precise
3581 * rules. Note that we don't want to throw errors if we're in the SIGHUP
3582 * context. In that case we just ignore the attempt and return true.
3584 switch (record->context)
3587 if (context == PGC_SIGHUP)
3589 if (context != PGC_INTERNAL)
3592 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3593 errmsg("parameter \"%s\" cannot be changed",
3598 case PGC_POSTMASTER:
3599 if (context == PGC_SIGHUP)
3601 if (context != PGC_POSTMASTER)
3604 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3605 errmsg("parameter \"%s\" cannot be changed after server start",
3611 if (context != PGC_SIGHUP && context != PGC_POSTMASTER)
3614 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3615 errmsg("parameter \"%s\" cannot be changed now",
3621 * Hmm, the idea of the SIGHUP context is "ought to be global, but
3622 * can be changed after postmaster start". But there's nothing
3623 * that prevents a crafty administrator from sending SIGHUP
3624 * signals to individual backends only.
3628 if (context == PGC_SIGHUP)
3631 * If a PGC_BACKEND parameter is changed in the config file,
3632 * we want to accept the new value in the postmaster (whence
3633 * it will propagate to subsequently-started backends), but
3634 * ignore it in existing backends. This is a tad klugy, but
3635 * necessary because we don't re-read the config file during
3638 if (IsUnderPostmaster)
3641 else if (context != PGC_BACKEND && context != PGC_POSTMASTER)
3644 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3645 errmsg("parameter \"%s\" cannot be set after connection start",
3651 if (context == PGC_USERSET || context == PGC_BACKEND)
3654 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3655 errmsg("permission denied to set parameter \"%s\"",
3666 * Should we set reset/stacked values? (If so, the behavior is not
3669 makeDefault = changeVal && (source <= PGC_S_OVERRIDE) && (value != NULL);
3672 * Ignore attempted set if overridden by previously processed setting.
3673 * However, if changeVal is false then plow ahead anyway since we are
3674 * trying to find out if the value is potentially good, not actually use
3675 * it. Also keep going if makeDefault is true, since we may want to set
3676 * the reset/stacked values even if we can't set the variable itself.
3678 if (record->source > source)
3680 if (changeVal && !makeDefault)
3682 elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
3690 * Evaluate value and set variable.
3692 switch (record->vartype)
3696 struct config_bool *conf = (struct config_bool *) record;
3701 if (!parse_bool(value, &newval))
3704 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3705 errmsg("parameter \"%s\" requires a Boolean value",
3712 newval = conf->reset_val;
3713 source = conf->gen.reset_source;
3716 if (conf->assign_hook)
3717 if (!(*conf->assign_hook) (newval, changeVal, source))
3720 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3721 errmsg("invalid value for parameter \"%s\": %d",
3722 name, (int) newval)));
3726 if (changeVal || makeDefault)
3728 /* Save old value to support transaction abort */
3730 push_old_value(&conf->gen);
3733 *conf->variable = newval;
3734 conf->gen.source = source;
3740 if (conf->gen.reset_source <= source)
3742 conf->reset_val = newval;
3743 conf->gen.reset_source = source;
3745 for (stack = conf->gen.stack; stack; stack = stack->prev)
3747 if (stack->source <= source)
3749 stack->value.boolval = newval;
3750 stack->source = source;
3756 conf->gen.status |= GUC_HAVE_LOCAL;
3761 conf->tentative_val = newval;
3762 conf->gen.tentative_source = source;
3763 conf->gen.status |= GUC_HAVE_TENTATIVE;
3772 struct config_int *conf = (struct config_int *) record;
3777 if (!parse_int(value, &newval))
3780 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3781 errmsg("parameter \"%s\" requires an integer value",
3785 if (newval < conf->min || newval > conf->max)
3788 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3789 errmsg("%d is outside the valid range for parameter \"%s\" (%d .. %d)",
3790 newval, name, conf->min, conf->max)));
3796 newval = conf->reset_val;
3797 source = conf->gen.reset_source;
3800 if (conf->assign_hook)
3801 if (!(*conf->assign_hook) (newval, changeVal, source))
3804 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3805 errmsg("invalid value for parameter \"%s\": %d",
3810 if (changeVal || makeDefault)
3812 /* Save old value to support transaction abort */
3814 push_old_value(&conf->gen);
3817 *conf->variable = newval;
3818 conf->gen.source = source;
3824 if (conf->gen.reset_source <= source)
3826 conf->reset_val = newval;
3827 conf->gen.reset_source = source;
3829 for (stack = conf->gen.stack; stack; stack = stack->prev)
3831 if (stack->source <= source)
3833 stack->value.intval = newval;
3834 stack->source = source;
3840 conf->gen.status |= GUC_HAVE_LOCAL;
3845 conf->tentative_val = newval;
3846 conf->gen.tentative_source = source;
3847 conf->gen.status |= GUC_HAVE_TENTATIVE;
3856 struct config_real *conf = (struct config_real *) record;
3861 if (!parse_real(value, &newval))
3864 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3865 errmsg("parameter \"%s\" requires a numeric value",
3869 if (newval < conf->min || newval > conf->max)
3872 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3873 errmsg("%g is outside the valid range for parameter \"%s\" (%g .. %g)",
3874 newval, name, conf->min, conf->max)));
3880 newval = conf->reset_val;
3881 source = conf->gen.reset_source;
3884 if (conf->assign_hook)
3885 if (!(*conf->assign_hook) (newval, changeVal, source))
3888 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3889 errmsg("invalid value for parameter \"%s\": %g",
3894 if (changeVal || makeDefault)
3896 /* Save old value to support transaction abort */
3898 push_old_value(&conf->gen);
3901 *conf->variable = newval;
3902 conf->gen.source = source;
3908 if (conf->gen.reset_source <= source)
3910 conf->reset_val = newval;
3911 conf->gen.reset_source = source;
3913 for (stack = conf->gen.stack; stack; stack = stack->prev)
3915 if (stack->source <= source)
3917 stack->value.realval = newval;
3918 stack->source = source;
3924 conf->gen.status |= GUC_HAVE_LOCAL;
3929 conf->tentative_val = newval;
3930 conf->gen.tentative_source = source;
3931 conf->gen.status |= GUC_HAVE_TENTATIVE;
3940 struct config_string *conf = (struct config_string *) record;
3945 newval = guc_strdup(elevel, value);
3949 else if (conf->reset_val)
3952 * We could possibly avoid strdup here, but easier to make
3953 * this case work the same as the normal assignment case.
3955 newval = guc_strdup(elevel, conf->reset_val);
3958 source = conf->gen.reset_source;
3962 /* Nothing to reset to, as yet; so do nothing */
3966 if (conf->assign_hook)
3968 const char *hookresult;
3971 * If the hook ereports, we have to make sure we free
3972 * newval, else it will be a permanent memory leak.
3974 hookresult = call_string_assign_hook(conf->assign_hook,
3978 if (hookresult == NULL)
3982 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3983 errmsg("invalid value for parameter \"%s\": \"%s\"",
3984 name, value ? value : "")));
3987 else if (hookresult != newval)
3992 * Having to cast away const here is annoying, but the
3993 * alternative is to declare assign_hooks as returning
3994 * char*, which would mean they'd have to cast away
3995 * const, or as both taking and returning char*, which
3996 * doesn't seem attractive either --- we don't want
3997 * them to scribble on the passed str.
3999 newval = (char *) hookresult;
4003 if (changeVal || makeDefault)
4005 /* Save old value to support transaction abort */
4007 push_old_value(&conf->gen);
4010 set_string_field(conf, conf->variable, newval);
4011 conf->gen.source = source;
4017 if (conf->gen.reset_source <= source)
4019 set_string_field(conf, &conf->reset_val, newval);
4020 conf->gen.reset_source = source;
4022 for (stack = conf->gen.stack; stack; stack = stack->prev)
4024 if (stack->source <= source)
4026 set_string_field(conf, &stack->value.stringval,
4028 stack->source = source;
4031 /* Perhaps we didn't install newval anywhere */
4032 if (!string_field_used(conf, newval))
4037 conf->gen.status |= GUC_HAVE_LOCAL;
4042 set_string_field(conf, &conf->tentative_val, newval);
4043 conf->gen.tentative_source = source;
4044 conf->gen.status |= GUC_HAVE_TENTATIVE;
4054 if (changeVal && (record->flags & GUC_REPORT))
4055 ReportGUCOption(record);
4062 * Set a config option to the given value. See also set_config_option,
4063 * this is just the wrapper to be called from outside GUC. NB: this
4064 * is used only for non-transactional operations.
4067 SetConfigOption(const char *name, const char *value,
4068 GucContext context, GucSource source)
4070 (void) set_config_option(name, value, context, source, false, true);
4076 * Fetch the current value of the option `name'. If the option doesn't exist,
4077 * throw an ereport and don't return.
4079 * The string is *not* allocated for modification and is really only
4080 * valid until the next call to configuration related functions.
4083 GetConfigOption(const char *name)
4085 struct config_generic *record;
4086 static char buffer[256];
4088 record = find_option(name, ERROR);
4091 (errcode(ERRCODE_UNDEFINED_OBJECT),
4092 errmsg("unrecognized configuration parameter \"%s\"", name)));
4093 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
4095 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4096 errmsg("must be superuser to examine \"%s\"", name)));
4098 switch (record->vartype)
4101 return *((struct config_bool *) record)->variable ? "on" : "off";
4104 snprintf(buffer, sizeof(buffer), "%d",
4105 *((struct config_int *) record)->variable);
4109 snprintf(buffer, sizeof(buffer), "%g",
4110 *((struct config_real *) record)->variable);
4114 return *((struct config_string *) record)->variable;
4120 * Get the RESET value associated with the given option.
4123 GetConfigOptionResetString(const char *name)
4125 struct config_generic *record;
4126 static char buffer[256];
4128 record = find_option(name, ERROR);
4131 (errcode(ERRCODE_UNDEFINED_OBJECT),
4132 errmsg("unrecognized configuration parameter \"%s\"", name)));
4133 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
4135 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4136 errmsg("must be superuser to examine \"%s\"", name)));
4138 switch (record->vartype)
4141 return ((struct config_bool *) record)->reset_val ? "on" : "off";
4144 snprintf(buffer, sizeof(buffer), "%d",
4145 ((struct config_int *) record)->reset_val);
4149 snprintf(buffer, sizeof(buffer), "%g",
4150 ((struct config_real *) record)->reset_val);
4154 return ((struct config_string *) record)->reset_val;
4160 * Detect whether the given configuration option can only be set by
4164 IsSuperuserConfigOption(const char *name)
4166 struct config_generic *record;
4168 record = find_option(name, ERROR);
4169 /* On an unrecognized name, don't error, just return false. */
4172 return (record->context == PGC_SUSET);
4177 * flatten_set_variable_args
4178 * Given a parsenode List as emitted by the grammar for SET,
4179 * convert to the flat string representation used by GUC.
4181 * We need to be told the name of the variable the args are for, because
4182 * the flattening rules vary (ugh).
4184 * The result is NULL if input is NIL (ie, SET ... TO DEFAULT), otherwise
4185 * a palloc'd string.
4188 flatten_set_variable_args(const char *name, List *args)
4190 struct config_generic *record;
4196 * Fast path if just DEFAULT. We do not check the variable name in this
4197 * case --- necessary for RESET ALL to work correctly.
4202 /* Else get flags for the variable */
4203 record = find_option(name, ERROR);
4206 (errcode(ERRCODE_UNDEFINED_OBJECT),
4207 errmsg("unrecognized configuration parameter \"%s\"", name)));
4209 flags = record->flags;
4211 /* Complain if list input and non-list variable */
4212 if ((flags & GUC_LIST_INPUT) == 0 &&
4213 list_length(args) != 1)
4215 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4216 errmsg("SET %s takes only one argument", name)));
4218 initStringInfo(&buf);
4222 A_Const *arg = (A_Const *) lfirst(l);
4225 if (l != list_head(args))
4226 appendStringInfo(&buf, ", ");
4228 if (!IsA(arg, A_Const))
4229 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
4231 switch (nodeTag(&arg->val))
4234 appendStringInfo(&buf, "%ld", intVal(&arg->val));
4237 /* represented as a string, so just copy it */
4238 appendStringInfoString(&buf, strVal(&arg->val));
4241 val = strVal(&arg->val);
4242 if (arg->typename != NULL)
4245 * Must be a ConstInterval argument for TIME ZONE. Coerce
4246 * to interval and back to normalize the value and account
4253 DirectFunctionCall3(interval_in,
4254 CStringGetDatum(val),
4255 ObjectIdGetDatum(InvalidOid),
4256 Int32GetDatum(arg->typename->typmod));
4259 DatumGetCString(DirectFunctionCall1(interval_out,
4261 appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
4266 * Plain string literal or identifier. For quote mode,
4267 * quote it if it's not a vanilla identifier.
4269 if (flags & GUC_LIST_QUOTE)
4270 appendStringInfoString(&buf, quote_identifier(val));
4272 appendStringInfoString(&buf, val);
4276 elog(ERROR, "unrecognized node type: %d",
4277 (int) nodeTag(&arg->val));
4290 SetPGVariable(const char *name, List *args, bool is_local)
4292 char *argstring = flatten_set_variable_args(name, args);
4294 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
4295 set_config_option(name,
4297 (superuser() ? PGC_SUSET : PGC_USERSET),
4304 * SET command wrapped as a SQL callable function.
4307 set_config_by_name(PG_FUNCTION_ARGS)
4315 if (PG_ARGISNULL(0))
4317 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
4318 errmsg("SET requires parameter name")));
4320 /* Get the GUC variable name */
4321 name = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(0)));
4323 /* Get the desired value or set to NULL for a reset request */
4324 if (PG_ARGISNULL(1))
4327 value = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(1)));
4330 * Get the desired state of is_local. Default to false if provided value
4333 if (PG_ARGISNULL(2))
4336 is_local = PG_GETARG_BOOL(2);
4338 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
4339 set_config_option(name,
4341 (superuser() ? PGC_SUSET : PGC_USERSET),
4346 /* get the new current value */
4347 new_value = GetConfigOptionByName(name, NULL);
4349 /* Convert return string to text */
4350 result_text = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(new_value)));
4353 PG_RETURN_TEXT_P(result_text);
4357 define_custom_variable(struct config_generic * variable)
4359 const char *name = variable->name;
4360 const char **nameAddr = &name;
4362 struct config_string *pHolder;
4363 struct config_generic **res = (struct config_generic **) bsearch(
4365 (void *) guc_variables,
4367 sizeof(struct config_generic *),
4372 add_guc_variable(variable, ERROR);
4377 * This better be a placeholder
4379 if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
4381 (errcode(ERRCODE_INTERNAL_ERROR),
4382 errmsg("attempt to redefine parameter \"%s\"", name)));
4384 Assert((*res)->vartype == PGC_STRING);
4385 pHolder = (struct config_string *) * res;
4387 /* We have the same name, no sorting is necessary */
4390 value = *pHolder->variable;
4393 * Assign the string value stored in the placeholder to the real variable.
4395 * XXX this is not really good enough --- it should be a nontransactional
4396 * assignment, since we don't want it to roll back if the current xact
4399 set_config_option(name, value,
4400 pHolder->gen.context, pHolder->gen.source,
4404 * Free up as much as we conveniently can of the placeholder structure
4405 * (this neglects any stack items...)
4407 set_string_field(pHolder, pHolder->variable, NULL);
4408 set_string_field(pHolder, &pHolder->reset_val, NULL);
4409 set_string_field(pHolder, &pHolder->tentative_val, NULL);
4415 init_custom_variable(struct config_generic * gen,
4417 const char *short_desc,
4418 const char *long_desc,
4420 enum config_type type)
4422 gen->name = guc_strdup(ERROR, name);
4423 gen->context = context;
4424 gen->group = CUSTOM_OPTIONS;
4425 gen->short_desc = short_desc;
4426 gen->long_desc = long_desc;
4427 gen->vartype = type;
4431 DefineCustomBoolVariable(const char *name,
4432 const char *short_desc,
4433 const char *long_desc,
4436 GucBoolAssignHook assign_hook,
4437 GucShowHook show_hook)
4439 size_t sz = sizeof(struct config_bool);
4440 struct config_bool *var = (struct config_bool *) guc_malloc(ERROR, sz);
4443 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_BOOL);
4445 var->variable = valueAddr;
4446 var->reset_val = *valueAddr;
4447 var->assign_hook = assign_hook;
4448 var->show_hook = show_hook;
4449 define_custom_variable(&var->gen);
4453 DefineCustomIntVariable(const char *name,
4454 const char *short_desc,
4455 const char *long_desc,
4460 GucIntAssignHook assign_hook,
4461 GucShowHook show_hook)
4463 size_t sz = sizeof(struct config_int);
4464 struct config_int *var = (struct config_int *) guc_malloc(ERROR, sz);
4467 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_INT);
4469 var->variable = valueAddr;
4470 var->reset_val = *valueAddr;
4471 var->min = minValue;
4472 var->max = maxValue;
4473 var->assign_hook = assign_hook;
4474 var->show_hook = show_hook;
4475 define_custom_variable(&var->gen);
4479 DefineCustomRealVariable(const char *name,
4480 const char *short_desc,
4481 const char *long_desc,
4486 GucRealAssignHook assign_hook,
4487 GucShowHook show_hook)
4489 size_t sz = sizeof(struct config_real);
4490 struct config_real *var = (struct config_real *) guc_malloc(ERROR, sz);
4493 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_REAL);
4495 var->variable = valueAddr;
4496 var->reset_val = *valueAddr;
4497 var->min = minValue;
4498 var->max = maxValue;
4499 var->assign_hook = assign_hook;
4500 var->show_hook = show_hook;
4501 define_custom_variable(&var->gen);
4505 DefineCustomStringVariable(const char *name,
4506 const char *short_desc,
4507 const char *long_desc,
4510 GucStringAssignHook assign_hook,
4511 GucShowHook show_hook)
4513 size_t sz = sizeof(struct config_string);
4514 struct config_string *var = (struct config_string *) guc_malloc(ERROR, sz);
4517 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_STRING);
4519 var->variable = valueAddr;
4520 var->reset_val = *valueAddr;
4521 var->assign_hook = assign_hook;
4522 var->show_hook = show_hook;
4523 define_custom_variable(&var->gen);
4527 EmitWarningsOnPlaceholders(const char *className)
4529 struct config_generic **vars = guc_variables;
4530 struct config_generic **last = vars + num_guc_variables;
4532 int nameLen = strlen(className);
4536 struct config_generic *var = *vars++;
4538 if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
4539 strncmp(className, var->name, nameLen) == 0 &&
4540 var->name[nameLen] == GUC_QUALIFIER_SEPARATOR)
4543 (errcode(ERRCODE_UNDEFINED_OBJECT),
4544 errmsg("unrecognized configuration parameter \"%s\"", var->name)));
4554 GetPGVariable(const char *name, DestReceiver *dest)
4556 if (pg_strcasecmp(name, "all") == 0)
4557 ShowAllGUCConfig(dest);
4559 ShowGUCConfigOption(name, dest);
4563 GetPGVariableResultDesc(const char *name)
4567 if (pg_strcasecmp(name, "all") == 0)
4569 /* need a tuple descriptor representing three TEXT columns */
4570 tupdesc = CreateTemplateTupleDesc(3, false);
4571 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
4573 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
4575 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
4581 const char *varname;
4583 /* Get the canonical spelling of name */
4584 (void) GetConfigOptionByName(name, &varname);
4586 /* need a tuple descriptor representing a single TEXT column */
4587 tupdesc = CreateTemplateTupleDesc(1, false);
4588 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
4598 ResetPGVariable(const char *name)
4600 if (pg_strcasecmp(name, "all") == 0)
4603 set_config_option(name,
4605 (superuser() ? PGC_SUSET : PGC_USERSET),
4616 ShowGUCConfigOption(const char *name, DestReceiver *dest)
4618 TupOutputState *tstate;
4620 const char *varname;
4623 /* Get the value and canonical spelling of name */
4624 value = GetConfigOptionByName(name, &varname);
4626 /* need a tuple descriptor representing a single TEXT column */
4627 tupdesc = CreateTemplateTupleDesc(1, false);
4628 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
4631 /* prepare for projection of tuples */
4632 tstate = begin_tup_output_tupdesc(dest, tupdesc);
4635 do_text_output_oneline(tstate, value);
4637 end_tup_output(tstate);
4644 ShowAllGUCConfig(DestReceiver *dest)
4646 bool am_superuser = superuser();
4648 TupOutputState *tstate;
4652 /* need a tuple descriptor representing three TEXT columns */
4653 tupdesc = CreateTemplateTupleDesc(3, false);
4654 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
4656 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
4658 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
4662 /* prepare for projection of tuples */
4663 tstate = begin_tup_output_tupdesc(dest, tupdesc);
4665 for (i = 0; i < num_guc_variables; i++)
4667 struct config_generic *conf = guc_variables[i];
4669 if ((conf->flags & GUC_NO_SHOW_ALL) ||
4670 ((conf->flags & GUC_SUPERUSER_ONLY) && !am_superuser))
4673 /* assign to the values array */
4674 values[0] = (char *) conf->name;
4675 values[1] = _ShowOption(conf);
4676 values[2] = (char *) conf->short_desc;
4678 /* send it to dest */
4679 do_tup_output(tstate, values);
4682 if (values[1] != NULL)
4686 end_tup_output(tstate);
4690 * Return GUC variable value by name; optionally return canonical
4691 * form of name. Return value is palloc'd.
4694 GetConfigOptionByName(const char *name, const char **varname)
4696 struct config_generic *record;
4698 record = find_option(name, ERROR);
4701 (errcode(ERRCODE_UNDEFINED_OBJECT),
4702 errmsg("unrecognized configuration parameter \"%s\"", name)));
4703 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
4705 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4706 errmsg("must be superuser to examine \"%s\"", name)));
4709 *varname = record->name;
4711 return _ShowOption(record);
4715 * Return GUC variable value by variable number; optionally return canonical
4716 * form of name. Return value is palloc'd.
4719 GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
4722 struct config_generic *conf;
4724 /* check requested variable number valid */
4725 Assert((varnum >= 0) && (varnum < num_guc_variables));
4727 conf = guc_variables[varnum];
4731 if ((conf->flags & GUC_NO_SHOW_ALL) ||
4732 ((conf->flags & GUC_SUPERUSER_ONLY) && !superuser()))
4738 /* first get the generic attributes */
4741 values[0] = conf->name;
4743 /* setting : use _ShowOption in order to avoid duplicating the logic */
4744 values[1] = _ShowOption(conf);
4747 values[2] = config_group_names[conf->group];
4750 values[3] = conf->short_desc;
4753 values[4] = conf->long_desc;
4756 values[5] = GucContext_Names[conf->context];
4759 values[6] = config_type_names[conf->vartype];
4762 values[7] = GucSource_Names[conf->source];
4764 /* now get the type specifc attributes */
4765 switch (conf->vartype)
4779 struct config_int *lconf = (struct config_int *) conf;
4782 snprintf(buffer, sizeof(buffer), "%d", lconf->min);
4783 values[8] = pstrdup(buffer);
4786 snprintf(buffer, sizeof(buffer), "%d", lconf->max);
4787 values[9] = pstrdup(buffer);
4793 struct config_real *lconf = (struct config_real *) conf;
4796 snprintf(buffer, sizeof(buffer), "%g", lconf->min);
4797 values[8] = pstrdup(buffer);
4800 snprintf(buffer, sizeof(buffer), "%g", lconf->max);
4801 values[9] = pstrdup(buffer);
4818 * should never get here, but in case we do, set 'em to NULL
4832 * Return the total number of GUC variables
4835 GetNumConfigOptions(void)
4837 return num_guc_variables;
4841 * show_config_by_name - equiv to SHOW X command but implemented as
4845 show_config_by_name(PG_FUNCTION_ARGS)
4851 /* Get the GUC variable name */
4852 varname = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(0)));
4855 varval = GetConfigOptionByName(varname, NULL);
4857 /* Convert to text */
4858 result_text = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(varval)));
4861 PG_RETURN_TEXT_P(result_text);
4865 * show_all_settings - equiv to SHOW ALL command but implemented as
4868 #define NUM_PG_SETTINGS_ATTS 10
4871 show_all_settings(PG_FUNCTION_ARGS)
4873 FuncCallContext *funcctx;
4877 AttInMetadata *attinmeta;
4878 MemoryContext oldcontext;
4880 /* stuff done only on the first call of the function */
4881 if (SRF_IS_FIRSTCALL())
4883 /* create a function context for cross-call persistence */
4884 funcctx = SRF_FIRSTCALL_INIT();
4887 * switch to memory context appropriate for multiple function calls
4889 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
4892 * need a tuple descriptor representing NUM_PG_SETTINGS_ATTS columns
4893 * of the appropriate types
4895 tupdesc = CreateTemplateTupleDesc(NUM_PG_SETTINGS_ATTS, false);
4896 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
4898 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
4900 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "category",
4902 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "short_desc",
4904 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "extra_desc",
4906 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "context",
4908 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "vartype",
4910 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "source",
4912 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "min_val",
4914 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "max_val",
4918 * Generate attribute metadata needed later to produce tuples from raw
4921 attinmeta = TupleDescGetAttInMetadata(tupdesc);
4922 funcctx->attinmeta = attinmeta;
4924 /* total number of tuples to be returned */
4925 funcctx->max_calls = GetNumConfigOptions();
4927 MemoryContextSwitchTo(oldcontext);
4930 /* stuff done on every call of the function */
4931 funcctx = SRF_PERCALL_SETUP();
4933 call_cntr = funcctx->call_cntr;
4934 max_calls = funcctx->max_calls;
4935 attinmeta = funcctx->attinmeta;
4937 if (call_cntr < max_calls) /* do when there is more left to send */
4939 char *values[NUM_PG_SETTINGS_ATTS];
4945 * Get the next visible GUC variable name and value
4949 GetConfigOptionByNum(call_cntr, (const char **) values, &noshow);
4952 /* bump the counter and get the next config setting */
4953 call_cntr = ++funcctx->call_cntr;
4955 /* make sure we haven't gone too far now */
4956 if (call_cntr >= max_calls)
4957 SRF_RETURN_DONE(funcctx);
4962 tuple = BuildTupleFromCStrings(attinmeta, values);
4964 /* make the tuple into a datum */
4965 result = HeapTupleGetDatum(tuple);
4967 SRF_RETURN_NEXT(funcctx, result);
4971 /* do when there is no more left */
4972 SRF_RETURN_DONE(funcctx);
4977 _ShowOption(struct config_generic * record)
4982 switch (record->vartype)
4986 struct config_bool *conf = (struct config_bool *) record;
4988 if (conf->show_hook)
4989 val = (*conf->show_hook) ();
4991 val = *conf->variable ? "on" : "off";
4997 struct config_int *conf = (struct config_int *) record;
4999 if (conf->show_hook)
5000 val = (*conf->show_hook) ();
5003 snprintf(buffer, sizeof(buffer), "%d",
5012 struct config_real *conf = (struct config_real *) record;
5014 if (conf->show_hook)
5015 val = (*conf->show_hook) ();
5018 snprintf(buffer, sizeof(buffer), "%g",
5027 struct config_string *conf = (struct config_string *) record;
5029 if (conf->show_hook)
5030 val = (*conf->show_hook) ();
5031 else if (*conf->variable && **conf->variable)
5032 val = *conf->variable;
5039 /* just to keep compiler quiet */
5044 return pstrdup(val);
5051 * This routine dumps out all non-default GUC options into a binary
5052 * file that is read by all exec'ed backends. The format is:
5054 * variable name, string, null terminated
5055 * variable value, string, null terminated
5056 * variable source, integer
5059 write_nondefault_variables(GucContext context)
5065 Assert(context == PGC_POSTMASTER || context == PGC_SIGHUP);
5067 elevel = (context == PGC_SIGHUP) ? LOG : ERROR;
5072 fp = AllocateFile(CONFIG_EXEC_PARAMS_NEW, "w");
5076 (errcode_for_file_access(),
5077 errmsg("could not write to file \"%s\": %m",
5078 CONFIG_EXEC_PARAMS_NEW)));
5082 for (i = 0; i < num_guc_variables; i++)
5084 struct config_generic *gconf = guc_variables[i];
5086 if (gconf->source != PGC_S_DEFAULT)
5088 fprintf(fp, "%s", gconf->name);
5091 switch (gconf->vartype)
5095 struct config_bool *conf = (struct config_bool *) gconf;
5097 if (*conf->variable == 0)
5098 fprintf(fp, "false");
5100 fprintf(fp, "true");
5106 struct config_int *conf = (struct config_int *) gconf;
5108 fprintf(fp, "%d", *conf->variable);
5114 struct config_real *conf = (struct config_real *) gconf;
5116 /* Could lose precision here? */
5117 fprintf(fp, "%f", *conf->variable);
5123 struct config_string *conf = (struct config_string *) gconf;
5125 fprintf(fp, "%s", *conf->variable);
5132 fwrite(&gconf->source, sizeof(gconf->source), 1, fp);
5139 (errcode_for_file_access(),
5140 errmsg("could not write to file \"%s\": %m",
5141 CONFIG_EXEC_PARAMS_NEW)));
5146 * Put new file in place. This could delay on Win32, but we don't hold
5147 * any exclusive locks.
5149 rename(CONFIG_EXEC_PARAMS_NEW, CONFIG_EXEC_PARAMS);
5154 * Read string, including null byte from file
5156 * Return NULL on EOF and nothing read
5159 read_string_with_null(FILE *fp)
5168 if ((ch = fgetc(fp)) == EOF)
5173 elog(FATAL, "invalid format of exec config params file");
5176 str = guc_malloc(FATAL, maxlen);
5177 else if (i == maxlen)
5178 str = guc_realloc(FATAL, str, maxlen *= 2);
5187 * This routine loads a previous postmaster dump of its non-default
5191 read_nondefault_variables(void)
5201 fp = AllocateFile(CONFIG_EXEC_PARAMS, "r");
5204 /* File not found is fine */
5205 if (errno != ENOENT)
5207 (errcode_for_file_access(),
5208 errmsg("could not read from file \"%s\": %m",
5209 CONFIG_EXEC_PARAMS)));
5215 struct config_generic *record;
5217 if ((varname = read_string_with_null(fp)) == NULL)
5220 if ((record = find_option(varname, FATAL)) == NULL)
5221 elog(FATAL, "failed to locate variable %s in exec config params file", varname);
5222 if ((varvalue = read_string_with_null(fp)) == NULL)
5223 elog(FATAL, "invalid format of exec config params file");
5224 if (fread(&varsource, sizeof(varsource), 1, fp) == 0)
5225 elog(FATAL, "invalid format of exec config params file");
5227 (void) set_config_option(varname, varvalue, record->context,
5228 varsource, false, true);
5235 #endif /* EXEC_BACKEND */
5239 * A little "long argument" simulation, although not quite GNU
5240 * compliant. Takes a string of the form "some-option=some value" and
5241 * returns name = "some_option" and value = "some value" in malloc'ed
5242 * storage. Note that '-' is converted to '_' in the option name. If
5243 * there is no '=' in the input string then value will be NULL.
5246 ParseLongOption(const char *string, char **name, char **value)
5255 equal_pos = strcspn(string, "=");
5257 if (string[equal_pos] == '=')
5259 *name = guc_malloc(FATAL, equal_pos + 1);
5260 strncpy(*name, string, equal_pos);
5261 (*name)[equal_pos] = '\0';
5263 *value = guc_strdup(FATAL, &string[equal_pos + 1]);
5267 /* no equal sign in string */
5268 *name = guc_strdup(FATAL, string);
5272 for (cp = *name; *cp; cp++)
5279 * Handle options fetched from pg_database.datconfig or pg_authid.rolconfig.
5280 * The array parameter must be an array of TEXT (it must not be NULL).
5283 ProcessGUCArray(ArrayType *array, GucSource source)
5287 Assert(array != NULL);
5288 Assert(ARR_ELEMTYPE(array) == TEXTOID);
5289 Assert(ARR_NDIM(array) == 1);
5290 Assert(ARR_LBOUND(array)[0] == 1);
5291 Assert(source == PGC_S_DATABASE || source == PGC_S_USER);
5293 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
5301 d = array_ref(array, 1, &i,
5302 -1 /* varlenarray */ ,
5303 -1 /* TEXT's typlen */ ,
5304 false /* TEXT's typbyval */ ,
5305 'i' /* TEXT's typalign */ ,
5311 s = DatumGetCString(DirectFunctionCall1(textout, d));
5313 ParseLongOption(s, &name, &value);
5317 (errcode(ERRCODE_SYNTAX_ERROR),
5318 errmsg("could not parse setting for parameter \"%s\"", name)));
5324 * We process all these options at SUSET level. We assume that the
5325 * right to insert an option into pg_database or pg_authid was checked
5326 * when it was inserted.
5328 SetConfigOption(name, value, PGC_SUSET, source);
5338 * Add an entry to an option array. The array parameter may be NULL
5339 * to indicate the current table entry is NULL.
5342 GUCArrayAdd(ArrayType *array, const char *name, const char *value)
5344 const char *varname;
5352 /* test if the option is valid */
5353 set_config_option(name, value,
5354 superuser() ? PGC_SUSET : PGC_USERSET,
5355 PGC_S_TEST, false, false);
5357 /* convert name to canonical spelling, so we can use plain strcmp */
5358 (void) GetConfigOptionByName(name, &varname);
5361 newval = palloc(strlen(name) + 1 + strlen(value) + 1);
5362 sprintf(newval, "%s=%s", name, value);
5363 datum = DirectFunctionCall1(textin, CStringGetDatum(newval));
5371 Assert(ARR_ELEMTYPE(array) == TEXTOID);
5372 Assert(ARR_NDIM(array) == 1);
5373 Assert(ARR_LBOUND(array)[0] == 1);
5375 index = ARR_DIMS(array)[0] + 1; /* add after end */
5377 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
5382 d = array_ref(array, 1, &i,
5383 -1 /* varlenarray */ ,
5384 -1 /* TEXT's typlen */ ,
5385 false /* TEXT's typbyval */ ,
5386 'i' /* TEXT's typalign */ ,
5390 current = DatumGetCString(DirectFunctionCall1(textout, d));
5391 if (strncmp(current, newval, strlen(name) + 1) == 0)
5398 a = array_set(array, 1, &index,
5401 -1 /* varlena array */ ,
5402 -1 /* TEXT's typlen */ ,
5403 false /* TEXT's typbyval */ ,
5404 'i' /* TEXT's typalign */ );
5407 a = construct_array(&datum, 1,
5416 * Delete an entry from an option array. The array parameter may be NULL
5417 * to indicate the current table entry is NULL. Also, if the return value
5418 * is NULL then a null should be stored.
5421 GUCArrayDelete(ArrayType *array, const char *name)
5423 const char *varname;
5424 ArrayType *newarray;
5430 /* test if the option is valid */
5431 set_config_option(name, NULL,
5432 superuser() ? PGC_SUSET : PGC_USERSET,
5433 PGC_S_TEST, false, false);
5435 /* convert name to canonical spelling, so we can use plain strcmp */
5436 (void) GetConfigOptionByName(name, &varname);
5439 /* if array is currently null, then surely nothing to delete */
5446 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
5452 d = array_ref(array, 1, &i,
5453 -1 /* varlenarray */ ,
5454 -1 /* TEXT's typlen */ ,
5455 false /* TEXT's typbyval */ ,
5456 'i' /* TEXT's typalign */ ,
5460 val = DatumGetCString(DirectFunctionCall1(textout, d));
5462 /* ignore entry if it's what we want to delete */
5463 if (strncmp(val, name, strlen(name)) == 0
5464 && val[strlen(name)] == '=')
5467 /* else add it to the output array */
5470 newarray = array_set(newarray, 1, &index,
5473 -1 /* varlenarray */ ,
5474 -1 /* TEXT's typlen */ ,
5475 false /* TEXT's typbyval */ ,
5476 'i' /* TEXT's typalign */ );
5479 newarray = construct_array(&d, 1,
5491 * assign_hook subroutines
5495 assign_log_destination(const char *value, bool doit, GucSource source)
5502 /* Need a modifiable copy of string */
5503 rawstring = pstrdup(value);
5505 /* Parse string into list of identifiers */
5506 if (!SplitIdentifierString(rawstring, ',', &elemlist))
5508 /* syntax error in list */
5510 list_free(elemlist);
5511 if (source >= PGC_S_INTERACTIVE)
5513 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5514 errmsg("invalid list syntax for parameter \"log_destination\"")));
5518 foreach(l, elemlist)
5520 char *tok = (char *) lfirst(l);
5522 if (pg_strcasecmp(tok, "stderr") == 0)
5523 newlogdest |= LOG_DESTINATION_STDERR;
5525 else if (pg_strcasecmp(tok, "syslog") == 0)
5526 newlogdest |= LOG_DESTINATION_SYSLOG;
5529 else if (pg_strcasecmp(tok, "eventlog") == 0)
5530 newlogdest |= LOG_DESTINATION_EVENTLOG;
5534 if (source >= PGC_S_INTERACTIVE)
5536 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5537 errmsg("unrecognized \"log_destination\" key word: \"%s\"",
5540 list_free(elemlist);
5546 Log_destination = newlogdest;
5549 list_free(elemlist);
5557 assign_syslog_facility(const char *facility, bool doit, GucSource source)
5561 if (pg_strcasecmp(facility, "LOCAL0") == 0)
5562 syslog_fac = LOG_LOCAL0;
5563 else if (pg_strcasecmp(facility, "LOCAL1") == 0)
5564 syslog_fac = LOG_LOCAL1;
5565 else if (pg_strcasecmp(facility, "LOCAL2") == 0)
5566 syslog_fac = LOG_LOCAL2;
5567 else if (pg_strcasecmp(facility, "LOCAL3") == 0)
5568 syslog_fac = LOG_LOCAL3;
5569 else if (pg_strcasecmp(facility, "LOCAL4") == 0)
5570 syslog_fac = LOG_LOCAL4;
5571 else if (pg_strcasecmp(facility, "LOCAL5") == 0)
5572 syslog_fac = LOG_LOCAL5;
5573 else if (pg_strcasecmp(facility, "LOCAL6") == 0)
5574 syslog_fac = LOG_LOCAL6;
5575 else if (pg_strcasecmp(facility, "LOCAL7") == 0)
5576 syslog_fac = LOG_LOCAL7;
5578 return NULL; /* reject */
5582 syslog_facility = syslog_fac;
5583 set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
5591 assign_syslog_ident(const char *ident, bool doit, GucSource source)
5594 set_syslog_parameters(ident, syslog_facility);
5598 #endif /* HAVE_SYSLOG */
5602 assign_defaultxactisolevel(const char *newval, bool doit, GucSource source)
5604 if (pg_strcasecmp(newval, "serializable") == 0)
5607 DefaultXactIsoLevel = XACT_SERIALIZABLE;
5609 else if (pg_strcasecmp(newval, "repeatable read") == 0)
5612 DefaultXactIsoLevel = XACT_REPEATABLE_READ;
5614 else if (pg_strcasecmp(newval, "read committed") == 0)
5617 DefaultXactIsoLevel = XACT_READ_COMMITTED;
5619 else if (pg_strcasecmp(newval, "read uncommitted") == 0)
5622 DefaultXactIsoLevel = XACT_READ_UNCOMMITTED;
5630 assign_log_min_messages(const char *newval,
5631 bool doit, GucSource source)
5633 return (assign_msglvl(&log_min_messages, newval, doit, source));
5637 assign_client_min_messages(const char *newval, bool doit, GucSource source)
5639 return (assign_msglvl(&client_min_messages, newval, doit, source));
5643 assign_min_error_statement(const char *newval, bool doit, GucSource source)
5645 return (assign_msglvl(&log_min_error_statement, newval, doit, source));
5649 assign_msglvl(int *var, const char *newval, bool doit, GucSource source)
5651 if (pg_strcasecmp(newval, "debug") == 0)
5656 else if (pg_strcasecmp(newval, "debug5") == 0)
5661 else if (pg_strcasecmp(newval, "debug4") == 0)
5666 else if (pg_strcasecmp(newval, "debug3") == 0)
5671 else if (pg_strcasecmp(newval, "debug2") == 0)
5676 else if (pg_strcasecmp(newval, "debug1") == 0)
5681 else if (pg_strcasecmp(newval, "log") == 0)
5688 * Client_min_messages always prints 'info', but we allow it as a value
5691 else if (pg_strcasecmp(newval, "info") == 0)
5696 else if (pg_strcasecmp(newval, "notice") == 0)
5701 else if (pg_strcasecmp(newval, "warning") == 0)
5706 else if (pg_strcasecmp(newval, "error") == 0)
5711 /* We allow FATAL/PANIC for client-side messages too. */
5712 else if (pg_strcasecmp(newval, "fatal") == 0)
5717 else if (pg_strcasecmp(newval, "panic") == 0)
5723 return NULL; /* fail */
5724 return newval; /* OK */
5728 assign_log_error_verbosity(const char *newval, bool doit, GucSource source)
5730 if (pg_strcasecmp(newval, "terse") == 0)
5733 Log_error_verbosity = PGERROR_TERSE;
5735 else if (pg_strcasecmp(newval, "default") == 0)
5738 Log_error_verbosity = PGERROR_DEFAULT;
5740 else if (pg_strcasecmp(newval, "verbose") == 0)
5743 Log_error_verbosity = PGERROR_VERBOSE;
5746 return NULL; /* fail */
5747 return newval; /* OK */
5751 assign_log_statement(const char *newval, bool doit, GucSource source)
5753 if (pg_strcasecmp(newval, "none") == 0)
5756 log_statement = LOGSTMT_NONE;
5758 else if (pg_strcasecmp(newval, "ddl") == 0)
5761 log_statement = LOGSTMT_DDL;
5763 else if (pg_strcasecmp(newval, "mod") == 0)
5766 log_statement = LOGSTMT_MOD;
5768 else if (pg_strcasecmp(newval, "all") == 0)
5771 log_statement = LOGSTMT_ALL;
5774 return NULL; /* fail */
5775 return newval; /* OK */
5779 show_num_temp_buffers(void)
5782 * We show the GUC var until local buffers have been initialized, and
5783 * NLocBuffer afterwards.
5785 static char nbuf[32];
5787 sprintf(nbuf, "%d", NLocBuffer ? NLocBuffer : num_temp_buffers);
5792 assign_phony_autocommit(bool newval, bool doit, GucSource source)
5796 if (doit && source >= PGC_S_INTERACTIVE)
5798 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5799 errmsg("SET AUTOCOMMIT TO OFF is no longer supported")));
5806 assign_custom_variable_classes(const char *newval, bool doit, GucSource source)
5809 * Check syntax. newval must be a comma separated list of identifiers.
5810 * Whitespace is allowed but skipped.
5812 bool hasSpaceAfterToken = false;
5813 const char *cp = newval;
5818 initStringInfo(&buf);
5819 while ((c = *cp++) != 0)
5824 hasSpaceAfterToken = true;
5830 hasSpaceAfterToken = false;
5834 appendStringInfoChar(&buf, ',');
5839 if (hasSpaceAfterToken || !isalnum(c))
5842 * Syntax error due to token following space after token or non
5843 * alpha numeric character
5846 (errcode(ERRCODE_SYNTAX_ERROR),
5847 errmsg("invalid syntax for \"custom_variable_classes\": \"%s\"", newval)));
5852 appendStringInfoChar(&buf, (char) c);
5855 /* Remove stray ',' at end */
5856 if (symLen == 0 && buf.len > 0)
5857 buf.data[--buf.len] = '\0';
5862 newval = strdup(buf.data);
5869 assign_ssl(bool newval, bool doit, GucSource source)
5874 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5875 errmsg("SSL is not supported by this build")));
5881 assign_stage_log_stats(bool newval, bool doit, GucSource source)
5883 if (newval && log_statement_stats)
5885 if (source >= PGC_S_INTERACTIVE)
5887 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5888 errmsg("cannot enable parameter when \"log_statement_stats\" is true")));
5889 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
5890 else if (source != PGC_S_OVERRIDE)
5897 assign_log_stats(bool newval, bool doit, GucSource source)
5900 (log_parser_stats || log_planner_stats || log_executor_stats))
5902 if (source >= PGC_S_INTERACTIVE)
5904 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5905 errmsg("cannot enable \"log_statement_stats\" when "
5906 "\"log_parser_stats\", \"log_planner_stats\", "
5907 "or \"log_executor_stats\" is true")));
5908 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
5909 else if (source != PGC_S_OVERRIDE)
5916 assign_transaction_read_only(bool newval, bool doit, GucSource source)
5918 /* Can't go to r/w mode inside a r/o transaction */
5919 if (newval == false && XactReadOnly && IsSubTransaction())
5921 if (source >= PGC_S_INTERACTIVE)
5923 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5924 errmsg("cannot set transaction read-write mode inside a read-only transaction")));
5925 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
5926 else if (source != PGC_S_OVERRIDE)
5933 assign_canonical_path(const char *newval, bool doit, GucSource source)
5937 char *canon_val = guc_strdup(ERROR, newval);
5939 canonicalize_path(canon_val);
5947 assign_tcp_keepalives_idle(int newval, bool doit, GucSource source)
5950 return (pq_setkeepalivesidle(newval, MyProcPort) == STATUS_OK);
5956 show_tcp_keepalives_idle(void)
5958 static char nbuf[16];
5960 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesidle(MyProcPort));
5965 assign_tcp_keepalives_interval(int newval, bool doit, GucSource source)
5968 return (pq_setkeepalivesinterval(newval, MyProcPort) == STATUS_OK);
5974 show_tcp_keepalives_interval(void)
5976 static char nbuf[16];
5978 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesinterval(MyProcPort));
5983 assign_tcp_keepalives_count(int newval, bool doit, GucSource source)
5986 return (pq_setkeepalivescount(newval, MyProcPort) == STATUS_OK);
5992 show_tcp_keepalives_count(void)
5994 static char nbuf[16];
5996 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivescount(MyProcPort));
6001 #include "guc-file.c"