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.304 2005/12/28 16:38:38 tgl 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_stage_log_stats(bool newval, bool doit, GucSource source);
134 static bool assign_log_stats(bool newval, bool doit, GucSource source);
135 static bool assign_transaction_read_only(bool newval, bool doit, GucSource source);
136 static const char *assign_canonical_path(const char *newval, bool doit, GucSource source);
138 static bool assign_tcp_keepalives_idle(int newval, bool doit, GucSource source);
139 static bool assign_tcp_keepalives_interval(int newval, bool doit, GucSource source);
140 static bool assign_tcp_keepalives_count(int newval, bool doit, GucSource source);
141 static const char *show_tcp_keepalives_idle(void);
142 static const char *show_tcp_keepalives_interval(void);
143 static const char *show_tcp_keepalives_count(void);
146 * GUC option variables that are exported from this module
148 #ifdef USE_ASSERT_CHECKING
149 bool assert_enabled = true;
151 bool log_duration = false;
152 bool Debug_print_plan = false;
153 bool Debug_print_parse = false;
154 bool Debug_print_rewritten = false;
155 bool Debug_pretty_print = false;
156 bool Explain_pretty_print = true;
158 bool log_parser_stats = false;
159 bool log_planner_stats = false;
160 bool log_executor_stats = false;
161 bool log_statement_stats = false; /* this is sort of all three
163 bool log_btree_build_stats = false;
165 bool SQL_inheritance = true;
167 bool Australian_timezones = false;
169 bool Password_encryption = true;
171 bool default_with_oids = false;
173 int log_min_error_statement = PANIC;
174 int log_min_messages = NOTICE;
175 int client_min_messages = NOTICE;
176 int log_min_duration_statement = -1;
178 int num_temp_buffers = 1000;
180 char *ConfigFileName;
183 char *external_pid_file;
185 int tcp_keepalives_idle;
186 int tcp_keepalives_interval;
187 int tcp_keepalives_count;
190 * These variables are all dummies that don't do anything, except in some
191 * cases provide the value for SHOW to display. The real state is elsewhere
192 * and is kept in sync by assign_hooks.
194 static char *client_min_messages_str;
195 static char *log_min_messages_str;
196 static char *log_error_verbosity_str;
197 static char *log_statement_str;
198 static char *log_min_error_statement_str;
199 static char *log_destination_string;
200 static char *syslog_facility_str;
201 static char *syslog_ident_str;
202 static bool phony_autocommit;
203 static bool session_auth_is_superuser;
204 static double phony_random_seed;
205 static char *client_encoding_string;
206 static char *datestyle_string;
207 static char *default_iso_level_string;
208 static char *locale_collate;
209 static char *locale_ctype;
210 static char *regex_flavor_string;
211 static char *server_encoding_string;
212 static char *server_version_string;
213 static char *timezone_string;
214 static char *XactIsoLevel_string;
215 static char *data_directory;
216 static char *custom_variable_classes;
217 static int max_function_args;
218 static int max_index_keys;
219 static int max_identifier_length;
220 static int block_size;
221 static bool integer_datetimes;
222 static bool standard_conforming_strings;
224 /* should be static, but commands/variable.c needs to get at these */
226 char *session_authorization_string;
230 * Displayable names for context types (enum GucContext)
232 * Note: these strings are deliberately not localized.
234 const char *const GucContext_Names[] =
236 /* PGC_INTERNAL */ "internal",
237 /* PGC_POSTMASTER */ "postmaster",
238 /* PGC_SIGHUP */ "sighup",
239 /* PGC_BACKEND */ "backend",
240 /* PGC_SUSET */ "superuser",
241 /* PGC_USERSET */ "user"
245 * Displayable names for source types (enum GucSource)
247 * Note: these strings are deliberately not localized.
249 const char *const GucSource_Names[] =
251 /* PGC_S_DEFAULT */ "default",
252 /* PGC_S_ENV_VAR */ "environment variable",
253 /* PGC_S_FILE */ "configuration file",
254 /* PGC_S_ARGV */ "command line",
255 /* PGC_S_DATABASE */ "database",
256 /* PGC_S_USER */ "user",
257 /* PGC_S_CLIENT */ "client",
258 /* PGC_S_OVERRIDE */ "override",
259 /* PGC_S_INTERACTIVE */ "interactive",
260 /* PGC_S_TEST */ "test",
261 /* PGC_S_SESSION */ "session"
265 * Displayable names for the groupings defined in enum config_group
267 const char *const config_group_names[] =
270 gettext_noop("Ungrouped"),
272 gettext_noop("File Locations"),
274 gettext_noop("Connections and Authentication"),
275 /* CONN_AUTH_SETTINGS */
276 gettext_noop("Connections and Authentication / Connection Settings"),
277 /* CONN_AUTH_SECURITY */
278 gettext_noop("Connections and Authentication / Security and Authentication"),
280 gettext_noop("Resource Usage"),
282 gettext_noop("Resource Usage / Memory"),
284 gettext_noop("Resource Usage / Free Space Map"),
285 /* RESOURCES_KERNEL */
286 gettext_noop("Resource Usage / Kernel Resources"),
288 gettext_noop("Write-Ahead Log"),
290 gettext_noop("Write-Ahead Log / Settings"),
291 /* WAL_CHECKPOINTS */
292 gettext_noop("Write-Ahead Log / Checkpoints"),
294 gettext_noop("Query Tuning"),
295 /* QUERY_TUNING_METHOD */
296 gettext_noop("Query Tuning / Planner Method Configuration"),
297 /* QUERY_TUNING_COST */
298 gettext_noop("Query Tuning / Planner Cost Constants"),
299 /* QUERY_TUNING_GEQO */
300 gettext_noop("Query Tuning / Genetic Query Optimizer"),
301 /* QUERY_TUNING_OTHER */
302 gettext_noop("Query Tuning / Other Planner Options"),
304 gettext_noop("Reporting and Logging"),
306 gettext_noop("Reporting and Logging / Where to Log"),
308 gettext_noop("Reporting and Logging / When to Log"),
310 gettext_noop("Reporting and Logging / What to Log"),
312 gettext_noop("Statistics"),
313 /* STATS_MONITORING */
314 gettext_noop("Statistics / Monitoring"),
315 /* STATS_COLLECTOR */
316 gettext_noop("Statistics / Query and Index Statistics Collector"),
318 gettext_noop("Auto Vacuum"),
320 gettext_noop("Client Connection Defaults"),
321 /* CLIENT_CONN_STATEMENT */
322 gettext_noop("Client Connection Defaults / Statement Behavior"),
323 /* CLIENT_CONN_LOCALE */
324 gettext_noop("Client Connection Defaults / Locale and Formatting"),
325 /* CLIENT_CONN_OTHER */
326 gettext_noop("Client Connection Defaults / Other Defaults"),
327 /* LOCK_MANAGEMENT */
328 gettext_noop("Lock Management"),
330 gettext_noop("Version and Platform Compatibility"),
331 /* COMPAT_OPTIONS_PREVIOUS */
332 gettext_noop("Version and Platform Compatibility / Previous PostgreSQL Versions"),
333 /* COMPAT_OPTIONS_CLIENT */
334 gettext_noop("Version and Platform Compatibility / Other Platforms and Clients"),
336 gettext_noop("Preset Options"),
338 gettext_noop("Customized Options"),
339 /* DEVELOPER_OPTIONS */
340 gettext_noop("Developer Options"),
341 /* help_config wants this array to be null-terminated */
346 * Displayable names for GUC variable types (enum config_type)
348 * Note: these strings are deliberately not localized.
350 const char *const config_type_names[] =
352 /* PGC_BOOL */ "bool",
353 /* PGC_INT */ "integer",
354 /* PGC_REAL */ "real",
355 /* PGC_STRING */ "string"
360 * Contents of GUC tables
362 * See src/backend/utils/misc/README for design notes.
366 * 1. Declare a global variable of type bool, int, double, or char*
367 * and make use of it.
369 * 2. Decide at what times it's safe to set the option. See guc.h for
372 * 3. Decide on a name, a default value, upper and lower bounds (if
375 * 4. Add a record below.
377 * 5. Add it to src/backend/utils/misc/postgresql.conf.sample, if
380 * 6. Add it to src/bin/psql/tab-complete.c, if it's a USERSET option.
382 * 7. Don't forget to document the option.
384 * 8. If it's a new GUC_LIST option you must edit pg_dumpall.c to ensure
385 * it is not single quoted at dump time.
389 /******** option records follow ********/
391 static struct config_bool ConfigureNamesBool[] =
394 {"enable_seqscan", PGC_USERSET, QUERY_TUNING_METHOD,
395 gettext_noop("Enables the planner's use of sequential-scan plans."),
402 {"enable_indexscan", PGC_USERSET, QUERY_TUNING_METHOD,
403 gettext_noop("Enables the planner's use of index-scan plans."),
410 {"enable_bitmapscan", PGC_USERSET, QUERY_TUNING_METHOD,
411 gettext_noop("Enables the planner's use of bitmap-scan plans."),
418 {"enable_tidscan", PGC_USERSET, QUERY_TUNING_METHOD,
419 gettext_noop("Enables the planner's use of TID scan plans."),
426 {"enable_sort", PGC_USERSET, QUERY_TUNING_METHOD,
427 gettext_noop("Enables the planner's use of explicit sort steps."),
434 {"enable_hashagg", PGC_USERSET, QUERY_TUNING_METHOD,
435 gettext_noop("Enables the planner's use of hashed aggregation plans."),
442 {"enable_nestloop", PGC_USERSET, QUERY_TUNING_METHOD,
443 gettext_noop("Enables the planner's use of nested-loop join plans."),
450 {"enable_mergejoin", PGC_USERSET, QUERY_TUNING_METHOD,
451 gettext_noop("Enables the planner's use of merge join plans."),
458 {"enable_hashjoin", PGC_USERSET, QUERY_TUNING_METHOD,
459 gettext_noop("Enables the planner's use of hash join plans."),
466 {"constraint_exclusion", PGC_USERSET, QUERY_TUNING_OTHER,
467 gettext_noop("Enables the planner to use constraints to optimize queries."),
468 gettext_noop("Child table scans will be skipped if their "
469 "constraints guarantee that no rows match the query.")
471 &constraint_exclusion,
475 {"geqo", PGC_USERSET, QUERY_TUNING_GEQO,
476 gettext_noop("Enables genetic query optimization."),
477 gettext_noop("This algorithm attempts to do planning without "
478 "exhaustive searching.")
484 /* Not for general use --- used by SET SESSION AUTHORIZATION */
485 {"is_superuser", PGC_INTERNAL, UNGROUPED,
486 gettext_noop("Shows whether the current user is a superuser."),
488 GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
490 &session_auth_is_superuser,
494 {"ssl", PGC_POSTMASTER, CONN_AUTH_SECURITY,
495 gettext_noop("Enables SSL connections."),
502 {"fsync", PGC_SIGHUP, WAL_SETTINGS,
503 gettext_noop("Forces synchronization of updates to disk."),
504 gettext_noop("The server will use the fsync() system call in several places to make "
505 "sure that updates are physically written to disk. This insures "
506 "that a database cluster will recover to a consistent state after "
507 "an operating system or hardware crash.")
513 {"zero_damaged_pages", PGC_SUSET, DEVELOPER_OPTIONS,
514 gettext_noop("Continues processing past damaged page headers."),
515 gettext_noop("Detection of a damaged page header normally causes PostgreSQL to "
516 "report an error, aborting the current transaction. Setting "
517 "zero_damaged_pages to true causes the system to instead report a "
518 "warning, zero out the damaged page, and continue processing. This "
519 "behavior will destroy data, namely all the rows on the damaged page."),
526 {"full_page_writes", PGC_SIGHUP, WAL_SETTINGS,
527 gettext_noop("Writes full pages to WAL when first modified after a checkpoint."),
528 gettext_noop("A page write in process during an operating system crash might be "
529 "only partially written to disk. During recovery, the row changes "
530 "stored in WAL are not enough to recover. This option writes "
531 "pages when first modified after a checkpoint to WAL so full recovery "
538 {"silent_mode", PGC_POSTMASTER, LOGGING_WHEN,
539 gettext_noop("Runs the server silently."),
540 gettext_noop("If this parameter is set, the server will automatically run in the "
541 "background and any controlling terminals are dissociated.")
547 {"log_connections", PGC_BACKEND, LOGGING_WHAT,
548 gettext_noop("Logs each successful connection."),
555 {"log_disconnections", PGC_BACKEND, LOGGING_WHAT,
556 gettext_noop("Logs end of a session, including duration."),
563 #ifdef USE_ASSERT_CHECKING
565 {"debug_assertions", PGC_USERSET, DEVELOPER_OPTIONS,
566 gettext_noop("Turns on various assertion checks."),
567 gettext_noop("This is a debugging aid."),
576 /* currently undocumented, so don't show in SHOW ALL */
577 {"exit_on_error", PGC_USERSET, UNGROUPED,
578 gettext_noop("no description available"),
580 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
586 {"log_duration", PGC_SUSET, LOGGING_WHAT,
587 gettext_noop("Logs the duration of each completed SQL statement."),
594 {"debug_print_parse", PGC_USERSET, LOGGING_WHAT,
595 gettext_noop("Prints the parse tree to the server log."),
602 {"debug_print_rewritten", PGC_USERSET, LOGGING_WHAT,
603 gettext_noop("Prints the parse tree after rewriting to server log."),
606 &Debug_print_rewritten,
610 {"debug_print_plan", PGC_USERSET, LOGGING_WHAT,
611 gettext_noop("Prints the execution plan to server log."),
618 {"debug_pretty_print", PGC_USERSET, LOGGING_WHAT,
619 gettext_noop("Indents parse and plan tree displays."),
626 {"log_parser_stats", PGC_SUSET, STATS_MONITORING,
627 gettext_noop("Writes parser performance statistics to the server log."),
631 false, assign_stage_log_stats, NULL
634 {"log_planner_stats", PGC_SUSET, STATS_MONITORING,
635 gettext_noop("Writes planner performance statistics to the server log."),
639 false, assign_stage_log_stats, NULL
642 {"log_executor_stats", PGC_SUSET, STATS_MONITORING,
643 gettext_noop("Writes executor performance statistics to the server log."),
647 false, assign_stage_log_stats, NULL
650 {"log_statement_stats", PGC_SUSET, STATS_MONITORING,
651 gettext_noop("Writes cumulative performance statistics to the server log."),
654 &log_statement_stats,
655 false, assign_log_stats, NULL
657 #ifdef BTREE_BUILD_STATS
659 {"log_btree_build_stats", PGC_SUSET, DEVELOPER_OPTIONS,
660 gettext_noop("no description available"),
664 &log_btree_build_stats,
670 {"explain_pretty_print", PGC_USERSET, CLIENT_CONN_OTHER,
671 gettext_noop("Uses the indented output format for EXPLAIN VERBOSE."),
674 &Explain_pretty_print,
678 {"stats_start_collector", PGC_POSTMASTER, STATS_COLLECTOR,
679 gettext_noop("Starts the server statistics-collection subprocess."),
682 &pgstat_collect_startcollector,
686 {"stats_reset_on_server_start", PGC_POSTMASTER, STATS_COLLECTOR,
687 gettext_noop("Zeroes collected statistics on server restart."),
690 &pgstat_collect_resetonpmstart,
694 {"stats_command_string", PGC_SUSET, STATS_COLLECTOR,
695 gettext_noop("Collects statistics about executing commands."),
696 gettext_noop("Enables the collection of statistics on the currently "
697 "executing command of each session, along with the time "
698 "at which that command began execution.")
700 &pgstat_collect_querystring,
704 {"stats_row_level", PGC_SUSET, STATS_COLLECTOR,
705 gettext_noop("Collects row-level statistics on database activity."),
708 &pgstat_collect_tuplelevel,
712 {"stats_block_level", PGC_SUSET, STATS_COLLECTOR,
713 gettext_noop("Collects block-level statistics on database activity."),
716 &pgstat_collect_blocklevel,
721 {"autovacuum", PGC_SIGHUP, AUTOVACUUM,
722 gettext_noop("Starts the autovacuum subprocess."),
725 &autovacuum_start_daemon,
730 {"trace_notify", PGC_USERSET, DEVELOPER_OPTIONS,
731 gettext_noop("Generates debugging output for LISTEN and NOTIFY."),
741 {"trace_locks", PGC_SUSET, DEVELOPER_OPTIONS,
742 gettext_noop("no description available"),
750 {"trace_userlocks", PGC_SUSET, DEVELOPER_OPTIONS,
751 gettext_noop("no description available"),
759 {"trace_lwlocks", PGC_SUSET, DEVELOPER_OPTIONS,
760 gettext_noop("no description available"),
768 {"debug_deadlocks", PGC_SUSET, DEVELOPER_OPTIONS,
769 gettext_noop("no description available"),
779 {"log_hostname", PGC_SIGHUP, LOGGING_WHAT,
780 gettext_noop("Logs the host name in the connection logs."),
781 gettext_noop("By default, connection logs only show the IP address "
782 "of the connecting host. If you want them to show the host name you "
783 "can turn this on, but depending on your host name resolution "
784 "setup it might impose a non-negligible performance penalty.")
790 {"sql_inheritance", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
791 gettext_noop("Causes subtables to be included by default in various commands."),
798 {"australian_timezones", PGC_USERSET, CLIENT_CONN_LOCALE,
799 gettext_noop("Interprets ACST, CST, EST, and SAT as Australian time zones."),
800 gettext_noop("Otherwise they are interpreted as North/South American "
801 "time zones and Saturday.")
803 &Australian_timezones,
804 false, ClearDateCache, NULL
807 {"password_encryption", PGC_USERSET, CONN_AUTH_SECURITY,
808 gettext_noop("Encrypt passwords."),
809 gettext_noop("When a password is specified in CREATE USER or "
810 "ALTER USER without writing either ENCRYPTED or UNENCRYPTED, "
811 "this parameter determines whether the password is to be encrypted.")
813 &Password_encryption,
817 {"transform_null_equals", PGC_USERSET, COMPAT_OPTIONS_CLIENT,
818 gettext_noop("Treats \"expr=NULL\" as \"expr IS NULL\"."),
819 gettext_noop("When turned on, expressions of the form expr = NULL "
820 "(or NULL = expr) are treated as expr IS NULL, that is, they "
821 "return true if expr evaluates to the null value, and false "
822 "otherwise. The correct behavior of expr = NULL is to always "
823 "return null (unknown).")
825 &Transform_null_equals,
829 {"db_user_namespace", PGC_SIGHUP, CONN_AUTH_SECURITY,
830 gettext_noop("Enables per-database user names."),
837 /* only here for backwards compatibility */
838 {"autocommit", PGC_USERSET, CLIENT_CONN_STATEMENT,
839 gettext_noop("This parameter doesn't do anything."),
840 gettext_noop("It's just here so that we won't choke on SET AUTOCOMMIT TO ON from 7.3-vintage clients."),
841 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
844 true, assign_phony_autocommit, NULL
847 {"default_transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
848 gettext_noop("Sets the default read-only status of new transactions."),
851 &DefaultXactReadOnly,
855 {"transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
856 gettext_noop("Sets the current transaction's read-only status."),
858 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
861 false, assign_transaction_read_only, NULL
864 {"add_missing_from", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
865 gettext_noop("Automatically adds missing table references to FROM clauses."),
872 {"check_function_bodies", PGC_USERSET, CLIENT_CONN_STATEMENT,
873 gettext_noop("Check function bodies during CREATE FUNCTION."),
876 &check_function_bodies,
880 {"array_nulls", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
881 gettext_noop("Enable input of NULL elements in arrays."),
882 gettext_noop("When turned on, unquoted NULL in an array input "
883 "value means a NULL value; "
884 "otherwise it is taken literally.")
890 {"default_with_oids", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
891 gettext_noop("Create new tables with OIDs by default."),
898 {"redirect_stderr", PGC_POSTMASTER, LOGGING_WHERE,
899 gettext_noop("Start a subprocess to capture stderr output into log files."),
906 {"log_truncate_on_rotation", PGC_SIGHUP, LOGGING_WHERE,
907 gettext_noop("Truncate existing log files of same name during log rotation."),
910 &Log_truncate_on_rotation,
916 {"trace_sort", PGC_USERSET, DEVELOPER_OPTIONS,
917 gettext_noop("Emit information about resource usage in sorting."),
928 {"wal_debug", PGC_SUSET, DEVELOPER_OPTIONS,
929 gettext_noop("Emit WAL-related debugging output."),
939 {"integer_datetimes", PGC_INTERNAL, PRESET_OPTIONS,
940 gettext_noop("Datetimes are integer based."),
942 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
945 #ifdef HAVE_INT64_TIMESTAMP
953 {"krb_caseins_users", PGC_POSTMASTER, CONN_AUTH_SECURITY,
954 gettext_noop("Sets whether Kerberos user names should be treated as case-insensitive."),
957 &pg_krb_caseins_users,
962 {"escape_string_warning", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
963 gettext_noop("Warn about backslash escapes in ordinary string literals."),
966 &escape_string_warning,
971 {"standard_conforming_strings", PGC_INTERNAL, PRESET_OPTIONS,
972 gettext_noop("'...' strings treat backslashes literally."),
974 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
976 &standard_conforming_strings,
980 /* End-of-list marker */
982 {NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL
987 static struct config_int ConfigureNamesInt[] =
990 {"default_statistics_target", PGC_USERSET, QUERY_TUNING_OTHER,
991 gettext_noop("Sets the default statistics target."),
992 gettext_noop("This applies to table columns that have not had a "
993 "column-specific target set via ALTER TABLE SET STATISTICS.")
995 &default_statistics_target,
996 10, 1, 1000, NULL, NULL
999 {"from_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1000 gettext_noop("Sets the FROM-list size beyond which subqueries are not "
1002 gettext_noop("The planner will merge subqueries into upper "
1003 "queries if the resulting FROM list would have no more than "
1006 &from_collapse_limit,
1007 8, 1, INT_MAX, NULL, NULL
1010 {"join_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1011 gettext_noop("Sets the FROM-list size beyond which JOIN constructs are not "
1013 gettext_noop("The planner will flatten explicit JOIN "
1014 "constructs into lists of FROM items whenever a list of no more "
1015 "than this many items would result.")
1017 &join_collapse_limit,
1018 8, 1, INT_MAX, NULL, NULL
1021 {"geqo_threshold", PGC_USERSET, QUERY_TUNING_GEQO,
1022 gettext_noop("Sets the threshold of FROM items beyond which GEQO is used."),
1026 12, 2, INT_MAX, NULL, NULL
1029 {"geqo_effort", PGC_USERSET, QUERY_TUNING_GEQO,
1030 gettext_noop("GEQO: effort is used to set the default for other GEQO parameters."),
1034 DEFAULT_GEQO_EFFORT, MIN_GEQO_EFFORT, MAX_GEQO_EFFORT, NULL, NULL
1037 {"geqo_pool_size", PGC_USERSET, QUERY_TUNING_GEQO,
1038 gettext_noop("GEQO: number of individuals in the population."),
1039 gettext_noop("Zero selects a suitable default value.")
1042 0, 0, INT_MAX, NULL, NULL
1045 {"geqo_generations", PGC_USERSET, QUERY_TUNING_GEQO,
1046 gettext_noop("GEQO: number of iterations of the algorithm."),
1047 gettext_noop("Zero selects a suitable default value.")
1050 0, 0, INT_MAX, NULL, NULL
1054 {"deadlock_timeout", PGC_SIGHUP, LOCK_MANAGEMENT,
1055 gettext_noop("The time in milliseconds to wait on lock before checking for deadlock."),
1059 1000, 0, INT_MAX, NULL, NULL
1063 * Note: There is some postprocessing done in PostmasterMain() to make
1064 * sure the buffers are at least twice the number of backends, so the
1065 * constraints here are partially unused. Similarly, the superuser
1066 * reserved number is checked to ensure it is less than the max backends
1069 * MaxBackends is limited to INT_MAX/4 because some places compute
1070 * 4*MaxBackends without any overflow check. Likewise we have to limit
1071 * NBuffers to INT_MAX/2.
1074 {"max_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1075 gettext_noop("Sets the maximum number of concurrent connections."),
1079 100, 1, INT_MAX / 4, NULL, NULL
1083 {"superuser_reserved_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1084 gettext_noop("Sets the number of connection slots reserved for superusers."),
1088 2, 0, INT_MAX / 4, NULL, NULL
1092 {"shared_buffers", PGC_POSTMASTER, RESOURCES_MEM,
1093 gettext_noop("Sets the number of shared memory buffers used by the server."),
1097 1000, 16, INT_MAX / 2, NULL, NULL
1101 {"temp_buffers", PGC_USERSET, RESOURCES_MEM,
1102 gettext_noop("Sets the maximum number of temporary buffers used by each session."),
1106 1000, 100, INT_MAX / 2, NULL, show_num_temp_buffers
1110 {"port", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1111 gettext_noop("Sets the TCP port the server listens on."),
1115 DEF_PGPORT, 1, 65535, NULL, NULL
1119 {"unix_socket_permissions", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1120 gettext_noop("Sets the access permissions of the Unix-domain socket."),
1121 gettext_noop("Unix-domain sockets use the usual Unix file system "
1122 "permission set. The parameter value is expected to be an numeric mode "
1123 "specification in the form accepted by the chmod and umask system "
1124 "calls. (To use the customary octal format the number must start with "
1127 &Unix_socket_permissions,
1128 0777, 0000, 0777, NULL, NULL
1132 {"work_mem", PGC_USERSET, RESOURCES_MEM,
1133 gettext_noop("Sets the maximum memory to be used for query workspaces."),
1134 gettext_noop("This much memory may be used by each internal "
1135 "sort operation and hash table before switching to "
1136 "temporary disk files.")
1139 1024, 8 * BLCKSZ / 1024, MAX_KILOBYTES, NULL, NULL
1143 {"maintenance_work_mem", PGC_USERSET, RESOURCES_MEM,
1144 gettext_noop("Sets the maximum memory to be used for maintenance operations."),
1145 gettext_noop("This includes operations such as VACUUM and CREATE INDEX.")
1147 &maintenance_work_mem,
1148 16384, 1024, MAX_KILOBYTES, NULL, NULL
1152 {"max_stack_depth", PGC_SUSET, RESOURCES_MEM,
1153 gettext_noop("Sets the maximum stack depth, in kilobytes."),
1157 2048, 100, MAX_KILOBYTES, assign_max_stack_depth, NULL
1161 {"vacuum_cost_page_hit", PGC_USERSET, RESOURCES,
1162 gettext_noop("Vacuum cost for a page found in the buffer cache."),
1166 1, 0, 10000, NULL, NULL
1170 {"vacuum_cost_page_miss", PGC_USERSET, RESOURCES,
1171 gettext_noop("Vacuum cost for a page not found in the buffer cache."),
1174 &VacuumCostPageMiss,
1175 10, 0, 10000, NULL, NULL
1179 {"vacuum_cost_page_dirty", PGC_USERSET, RESOURCES,
1180 gettext_noop("Vacuum cost for a page dirtied by vacuum."),
1183 &VacuumCostPageDirty,
1184 20, 0, 10000, NULL, NULL
1188 {"vacuum_cost_limit", PGC_USERSET, RESOURCES,
1189 gettext_noop("Vacuum cost amount available before napping."),
1193 200, 1, 10000, NULL, NULL
1197 {"vacuum_cost_delay", PGC_USERSET, RESOURCES,
1198 gettext_noop("Vacuum cost delay in milliseconds."),
1202 0, 0, 1000, NULL, NULL
1206 {"autovacuum_vacuum_cost_delay", PGC_SIGHUP, AUTOVACUUM,
1207 gettext_noop("Vacuum cost delay in milliseconds, for autovacuum."),
1210 &autovacuum_vac_cost_delay,
1211 -1, -1, 1000, NULL, NULL
1215 {"autovacuum_vacuum_cost_limit", PGC_SIGHUP, AUTOVACUUM,
1216 gettext_noop("Vacuum cost amount available before napping, for autovacuum."),
1219 &autovacuum_vac_cost_limit,
1220 -1, -1, 10000, NULL, NULL
1224 {"max_files_per_process", PGC_POSTMASTER, RESOURCES_KERNEL,
1225 gettext_noop("Sets the maximum number of simultaneously open files for each server process."),
1228 &max_files_per_process,
1229 1000, 25, INT_MAX, NULL, NULL
1233 {"max_prepared_transactions", PGC_POSTMASTER, RESOURCES,
1234 gettext_noop("Sets the maximum number of simultaneously prepared transactions."),
1237 &max_prepared_xacts,
1238 5, 0, INT_MAX, NULL, NULL
1243 {"trace_lock_oidmin", PGC_SUSET, DEVELOPER_OPTIONS,
1244 gettext_noop("no description available"),
1249 FirstNormalObjectId, 0, INT_MAX, NULL, NULL
1252 {"trace_lock_table", PGC_SUSET, DEVELOPER_OPTIONS,
1253 gettext_noop("no description available"),
1258 0, 0, INT_MAX, NULL, NULL
1263 {"statement_timeout", PGC_USERSET, CLIENT_CONN_STATEMENT,
1264 gettext_noop("Sets the maximum allowed duration (in milliseconds) of any statement."),
1265 gettext_noop("A value of 0 turns off the timeout.")
1268 0, 0, INT_MAX, NULL, NULL
1272 {"max_fsm_relations", PGC_POSTMASTER, RESOURCES_FSM,
1273 gettext_noop("Sets the maximum number of tables and indexes for which free space is tracked."),
1277 1000, 100, INT_MAX, NULL, NULL
1280 {"max_fsm_pages", PGC_POSTMASTER, RESOURCES_FSM,
1281 gettext_noop("Sets the maximum number of disk pages for which free space is tracked."),
1285 20000, 1000, INT_MAX, NULL, NULL
1289 {"max_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
1290 gettext_noop("Sets the maximum number of locks per transaction."),
1291 gettext_noop("The shared lock table is sized on the assumption that "
1292 "at most max_locks_per_transaction * max_connections distinct "
1293 "objects will need to be locked at any one time.")
1295 &max_locks_per_xact,
1296 64, 10, INT_MAX, NULL, NULL
1300 {"authentication_timeout", PGC_SIGHUP, CONN_AUTH_SECURITY,
1301 gettext_noop("Sets the maximum time in seconds to complete client authentication."),
1304 &AuthenticationTimeout,
1305 60, 1, 600, NULL, NULL
1309 /* Not for general use */
1310 {"pre_auth_delay", PGC_SIGHUP, DEVELOPER_OPTIONS,
1311 gettext_noop("no description available"),
1316 0, 0, 60, NULL, NULL
1320 {"checkpoint_segments", PGC_SIGHUP, WAL_CHECKPOINTS,
1321 gettext_noop("Sets the maximum distance in log segments between automatic WAL checkpoints."),
1324 &CheckPointSegments,
1325 3, 1, INT_MAX, NULL, NULL
1329 {"checkpoint_timeout", PGC_SIGHUP, WAL_CHECKPOINTS,
1330 gettext_noop("Sets the maximum time in seconds between automatic WAL checkpoints."),
1334 300, 30, 3600, NULL, NULL
1338 {"checkpoint_warning", PGC_SIGHUP, WAL_CHECKPOINTS,
1339 gettext_noop("Logs if filling of checkpoint segments happens more "
1340 "frequently than this (in seconds)."),
1341 gettext_noop("Write a message to the server log if checkpoints "
1342 "caused by the filling of checkpoint segment files happens more "
1343 "frequently than this number of seconds. Zero turns off the warning.")
1346 30, 0, INT_MAX, NULL, NULL
1350 {"wal_buffers", PGC_POSTMASTER, WAL_SETTINGS,
1351 gettext_noop("Sets the number of disk-page buffers in shared memory for WAL."),
1355 8, 4, INT_MAX, NULL, NULL
1359 {"commit_delay", PGC_USERSET, WAL_CHECKPOINTS,
1360 gettext_noop("Sets the delay in microseconds between transaction commit and "
1361 "flushing WAL to disk."),
1365 0, 0, 100000, NULL, NULL
1369 {"commit_siblings", PGC_USERSET, WAL_CHECKPOINTS,
1370 gettext_noop("Sets the minimum concurrent open transactions before performing "
1375 5, 1, 1000, NULL, NULL
1379 {"extra_float_digits", PGC_USERSET, CLIENT_CONN_LOCALE,
1380 gettext_noop("Sets the number of digits displayed for floating-point values."),
1381 gettext_noop("This affects real, double precision, and geometric data types. "
1382 "The parameter value is added to the standard number of digits "
1383 "(FLT_DIG or DBL_DIG as appropriate).")
1385 &extra_float_digits,
1386 0, -15, 2, NULL, NULL
1390 {"log_min_duration_statement", PGC_SUSET, LOGGING_WHEN,
1391 gettext_noop("Sets the minimum execution time in milliseconds above which statements will "
1393 gettext_noop("Zero prints all queries. The default is -1 (turning this feature off).")
1395 &log_min_duration_statement,
1396 -1, -1, INT_MAX / 1000, NULL, NULL
1400 {"bgwriter_delay", PGC_SIGHUP, RESOURCES,
1401 gettext_noop("Background writer sleep time between rounds in milliseconds"),
1405 200, 10, 10000, NULL, NULL
1409 {"bgwriter_lru_maxpages", PGC_SIGHUP, RESOURCES,
1410 gettext_noop("Background writer maximum number of LRU pages to flush per round"),
1413 &bgwriter_lru_maxpages,
1414 5, 0, 1000, NULL, NULL
1418 {"bgwriter_all_maxpages", PGC_SIGHUP, RESOURCES,
1419 gettext_noop("Background writer maximum number of all pages to flush per round"),
1422 &bgwriter_all_maxpages,
1423 5, 0, 1000, NULL, NULL
1427 {"log_rotation_age", PGC_SIGHUP, LOGGING_WHERE,
1428 gettext_noop("Automatic log file rotation will occur after N minutes"),
1432 HOURS_PER_DAY * MINS_PER_HOUR, 0, INT_MAX / MINS_PER_HOUR, NULL, NULL
1436 {"log_rotation_size", PGC_SIGHUP, LOGGING_WHERE,
1437 gettext_noop("Automatic log file rotation will occur after N kilobytes"),
1441 10 * 1024, 0, INT_MAX / 1024, NULL, NULL
1445 {"max_function_args", PGC_INTERNAL, PRESET_OPTIONS,
1446 gettext_noop("Shows the maximum number of function arguments."),
1448 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1451 FUNC_MAX_ARGS, FUNC_MAX_ARGS, FUNC_MAX_ARGS, NULL, NULL
1455 {"max_index_keys", PGC_INTERNAL, PRESET_OPTIONS,
1456 gettext_noop("Shows the maximum number of index keys."),
1458 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1461 INDEX_MAX_KEYS, INDEX_MAX_KEYS, INDEX_MAX_KEYS, NULL, NULL
1465 {"max_identifier_length", PGC_INTERNAL, PRESET_OPTIONS,
1466 gettext_noop("Shows the maximum identifier length"),
1468 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1470 &max_identifier_length,
1471 NAMEDATALEN - 1, NAMEDATALEN - 1, NAMEDATALEN - 1, NULL, NULL
1475 {"block_size", PGC_INTERNAL, PRESET_OPTIONS,
1476 gettext_noop("Shows size of a disk block"),
1478 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1481 BLCKSZ, BLCKSZ, BLCKSZ, NULL, NULL
1485 {"autovacuum_naptime", PGC_SIGHUP, AUTOVACUUM,
1486 gettext_noop("Time to sleep between autovacuum runs, in seconds."),
1489 &autovacuum_naptime,
1490 60, 1, INT_MAX, NULL, NULL
1493 {"autovacuum_vacuum_threshold", PGC_SIGHUP, AUTOVACUUM,
1494 gettext_noop("Minimum number of tuple updates or deletes prior to vacuum."),
1497 &autovacuum_vac_thresh,
1498 1000, 0, INT_MAX, NULL, NULL
1501 {"autovacuum_analyze_threshold", PGC_SIGHUP, AUTOVACUUM,
1502 gettext_noop("Minimum number of tuple inserts, updates or deletes prior to analyze."),
1505 &autovacuum_anl_thresh,
1506 500, 0, INT_MAX, NULL, NULL
1510 {"tcp_keepalives_idle", PGC_USERSET, CLIENT_CONN_OTHER,
1511 gettext_noop("Seconds between issuing TCP keepalives."),
1512 gettext_noop("A value of 0 uses the system default."),
1514 &tcp_keepalives_idle,
1515 0, 0, INT_MAX, assign_tcp_keepalives_idle, show_tcp_keepalives_idle
1519 {"tcp_keepalives_interval", PGC_USERSET, CLIENT_CONN_OTHER,
1520 gettext_noop("Seconds between TCP keepalive retransmits."),
1521 gettext_noop("A value of 0 uses the system default."),
1523 &tcp_keepalives_interval,
1524 0, 0, INT_MAX, assign_tcp_keepalives_interval, show_tcp_keepalives_interval
1528 {"tcp_keepalives_count", PGC_USERSET, CLIENT_CONN_OTHER,
1529 gettext_noop("Maximum number of TCP keepalive retransmits."),
1530 gettext_noop("This controls the number of consecutive keepalive retransmits that can be "
1531 "lost before a connection is considered dead. A value of 0 uses the "
1534 &tcp_keepalives_count,
1535 0, 0, INT_MAX, assign_tcp_keepalives_count, show_tcp_keepalives_count
1538 /* End-of-list marker */
1540 {NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL
1545 static struct config_real ConfigureNamesReal[] =
1548 {"effective_cache_size", PGC_USERSET, QUERY_TUNING_COST,
1549 gettext_noop("Sets the planner's assumption about size of the disk cache."),
1550 gettext_noop("That is, the portion of the kernel's disk cache that "
1551 "will be used for PostgreSQL data files. This is measured in disk "
1552 "pages, which are normally 8 kB each.")
1554 &effective_cache_size,
1555 DEFAULT_EFFECTIVE_CACHE_SIZE, 1, DBL_MAX, NULL, NULL
1558 {"random_page_cost", PGC_USERSET, QUERY_TUNING_COST,
1559 gettext_noop("Sets the planner's estimate of the cost of a nonsequentially "
1560 "fetched disk page."),
1561 gettext_noop("This is measured as a multiple of the cost of a "
1562 "sequential page fetch. A higher value makes it more likely a "
1563 "sequential scan will be used, a lower value makes it more likely an "
1564 "index scan will be used.")
1567 DEFAULT_RANDOM_PAGE_COST, 0, DBL_MAX, NULL, NULL
1570 {"cpu_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
1571 gettext_noop("Sets the planner's estimate of the cost of processing each tuple (row)."),
1572 gettext_noop("This is measured as a fraction of the cost of a "
1573 "sequential page fetch.")
1576 DEFAULT_CPU_TUPLE_COST, 0, DBL_MAX, NULL, NULL
1579 {"cpu_index_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
1580 gettext_noop("Sets the planner's estimate of processing cost for each "
1581 "index tuple (row) during index scan."),
1582 gettext_noop("This is measured as a fraction of the cost of a "
1583 "sequential page fetch.")
1585 &cpu_index_tuple_cost,
1586 DEFAULT_CPU_INDEX_TUPLE_COST, 0, DBL_MAX, NULL, NULL
1589 {"cpu_operator_cost", PGC_USERSET, QUERY_TUNING_COST,
1590 gettext_noop("Sets the planner's estimate of processing cost of each operator in WHERE."),
1591 gettext_noop("This is measured as a fraction of the cost of a sequential "
1595 DEFAULT_CPU_OPERATOR_COST, 0, DBL_MAX, NULL, NULL
1599 {"geqo_selection_bias", PGC_USERSET, QUERY_TUNING_GEQO,
1600 gettext_noop("GEQO: selective pressure within the population."),
1603 &Geqo_selection_bias,
1604 DEFAULT_GEQO_SELECTION_BIAS, MIN_GEQO_SELECTION_BIAS,
1605 MAX_GEQO_SELECTION_BIAS, NULL, NULL
1609 {"bgwriter_lru_percent", PGC_SIGHUP, RESOURCES,
1610 gettext_noop("Background writer percentage of LRU buffers to flush per round"),
1613 &bgwriter_lru_percent,
1614 1.0, 0.0, 100.0, NULL, NULL
1618 {"bgwriter_all_percent", PGC_SIGHUP, RESOURCES,
1619 gettext_noop("Background writer percentage of all buffers to flush per round"),
1622 &bgwriter_all_percent,
1623 0.333, 0.0, 100.0, NULL, NULL
1627 {"seed", PGC_USERSET, UNGROUPED,
1628 gettext_noop("Sets the seed for random-number generation."),
1630 GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1633 0.5, 0.0, 1.0, assign_random_seed, show_random_seed
1637 {"autovacuum_vacuum_scale_factor", PGC_SIGHUP, AUTOVACUUM,
1638 gettext_noop("Number of tuple updates or deletes prior to vacuum as a fraction of reltuples."),
1641 &autovacuum_vac_scale,
1642 0.4, 0.0, 100.0, NULL, NULL
1645 {"autovacuum_analyze_scale_factor", PGC_SIGHUP, AUTOVACUUM,
1646 gettext_noop("Number of tuple inserts, updates or deletes prior to analyze as a fraction of reltuples."),
1649 &autovacuum_anl_scale,
1650 0.2, 0.0, 100.0, NULL, NULL
1653 /* End-of-list marker */
1655 {NULL, 0, 0, NULL, NULL}, NULL, 0.0, 0.0, 0.0, NULL, NULL
1660 static struct config_string ConfigureNamesString[] =
1663 {"archive_command", PGC_SIGHUP, WAL_SETTINGS,
1664 gettext_noop("WAL archiving command."),
1665 gettext_noop("The shell command that will be called to archive a WAL file.")
1667 &XLogArchiveCommand,
1672 {"client_encoding", PGC_USERSET, CLIENT_CONN_LOCALE,
1673 gettext_noop("Sets the client's character set encoding."),
1677 &client_encoding_string,
1678 "SQL_ASCII", assign_client_encoding, NULL
1682 {"client_min_messages", PGC_USERSET, LOGGING_WHEN,
1683 gettext_noop("Sets the message levels that are sent to the client."),
1684 gettext_noop("Valid values are DEBUG5, DEBUG4, DEBUG3, DEBUG2, "
1685 "DEBUG1, LOG, NOTICE, WARNING, and ERROR. Each level includes all the "
1686 "levels that follow it. The later the level, the fewer messages are "
1689 &client_min_messages_str,
1690 "notice", assign_client_min_messages, NULL
1694 {"log_min_messages", PGC_SUSET, LOGGING_WHEN,
1695 gettext_noop("Sets the message levels that are logged."),
1696 gettext_noop("Valid values are DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1, "
1697 "INFO, NOTICE, WARNING, ERROR, LOG, FATAL, and PANIC. Each level "
1698 "includes all the levels that follow it.")
1700 &log_min_messages_str,
1701 "notice", assign_log_min_messages, NULL
1705 {"log_error_verbosity", PGC_SUSET, LOGGING_WHEN,
1706 gettext_noop("Sets the verbosity of logged messages."),
1707 gettext_noop("Valid values are \"terse\", \"default\", and \"verbose\".")
1709 &log_error_verbosity_str,
1710 "default", assign_log_error_verbosity, NULL
1713 {"log_statement", PGC_SUSET, LOGGING_WHAT,
1714 gettext_noop("Sets the type of statements logged."),
1715 gettext_noop("Valid values are \"none\", \"ddl\", \"mod\", and \"all\".")
1718 "none", assign_log_statement, NULL
1722 {"log_min_error_statement", PGC_SUSET, LOGGING_WHEN,
1723 gettext_noop("Causes all statements generating error at or above this level to be logged."),
1724 gettext_noop("All SQL statements that cause an error of the "
1725 "specified level or a higher level are logged.")
1727 &log_min_error_statement_str,
1728 "panic", assign_min_error_statement, NULL
1732 {"log_line_prefix", PGC_SIGHUP, LOGGING_WHAT,
1733 gettext_noop("Controls information prefixed to each log line"),
1734 gettext_noop("if blank no prefix is used")
1742 {"DateStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
1743 gettext_noop("Sets the display format for date and time values."),
1744 gettext_noop("Also controls interpretation of ambiguous "
1746 GUC_LIST_INPUT | GUC_REPORT
1749 "ISO, MDY", assign_datestyle, NULL
1753 {"default_tablespace", PGC_USERSET, CLIENT_CONN_STATEMENT,
1754 gettext_noop("Sets the default tablespace to create tables and indexes in."),
1755 gettext_noop("An empty string selects the database's default tablespace.")
1757 &default_tablespace,
1758 "", assign_default_tablespace, NULL
1762 {"default_transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
1763 gettext_noop("Sets the transaction isolation level of each new transaction."),
1764 gettext_noop("Each SQL transaction has an isolation level, which "
1765 "can be either \"read uncommitted\", \"read committed\", \"repeatable read\", or \"serializable\".")
1767 &default_iso_level_string,
1768 "read committed", assign_defaultxactisolevel, NULL
1772 {"dynamic_library_path", PGC_SUSET, CLIENT_CONN_OTHER,
1773 gettext_noop("Sets the path for dynamically loadable modules."),
1774 gettext_noop("If a dynamically loadable module needs to be opened and "
1775 "the specified name does not have a directory component (i.e., the "
1776 "name does not contain a slash), the system will search this path for "
1777 "the specified file."),
1780 &Dynamic_library_path,
1781 "$libdir", NULL, NULL
1785 {"krb_server_keyfile", PGC_POSTMASTER, CONN_AUTH_SECURITY,
1786 gettext_noop("Sets the location of the Kerberos server key file."),
1790 &pg_krb_server_keyfile,
1791 PG_KRB_SRVTAB, NULL, NULL
1795 {"krb_srvname", PGC_POSTMASTER, CONN_AUTH_SECURITY,
1796 gettext_noop("Sets the name of the Kerberos service."),
1800 PG_KRB_SRVNAM, NULL, NULL
1804 {"krb_server_hostname", PGC_POSTMASTER, CONN_AUTH_SECURITY,
1805 gettext_noop("Sets the hostname of the Kerberos server."),
1808 &pg_krb_server_hostname,
1813 {"bonjour_name", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1814 gettext_noop("Sets the Bonjour broadcast service name."),
1821 /* See main.c about why defaults for LC_foo are not all alike */
1824 {"lc_collate", PGC_INTERNAL, CLIENT_CONN_LOCALE,
1825 gettext_noop("Shows the collation order locale."),
1827 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1834 {"lc_ctype", PGC_INTERNAL, CLIENT_CONN_LOCALE,
1835 gettext_noop("Shows the character classification and case conversion locale."),
1837 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1844 {"lc_messages", PGC_SUSET, CLIENT_CONN_LOCALE,
1845 gettext_noop("Sets the language in which messages are displayed."),
1849 "", locale_messages_assign, NULL
1853 {"lc_monetary", PGC_USERSET, CLIENT_CONN_LOCALE,
1854 gettext_noop("Sets the locale for formatting monetary amounts."),
1858 "C", locale_monetary_assign, NULL
1862 {"lc_numeric", PGC_USERSET, CLIENT_CONN_LOCALE,
1863 gettext_noop("Sets the locale for formatting numbers."),
1867 "C", locale_numeric_assign, NULL
1871 {"lc_time", PGC_USERSET, CLIENT_CONN_LOCALE,
1872 gettext_noop("Sets the locale for formatting date and time values."),
1876 "C", locale_time_assign, NULL
1880 {"preload_libraries", PGC_POSTMASTER, RESOURCES_KERNEL,
1881 gettext_noop("Lists shared libraries to preload into server."),
1883 GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
1885 &preload_libraries_string,
1890 {"regex_flavor", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1891 gettext_noop("Sets the regular expression \"flavor\"."),
1892 gettext_noop("This can be set to advanced, extended, or basic.")
1894 ®ex_flavor_string,
1895 "advanced", assign_regex_flavor, NULL
1899 {"search_path", PGC_USERSET, CLIENT_CONN_STATEMENT,
1900 gettext_noop("Sets the schema search order for names that are not schema-qualified."),
1902 GUC_LIST_INPUT | GUC_LIST_QUOTE
1904 &namespace_search_path,
1905 "\"$user\",public", assign_search_path, NULL
1909 /* Can't be set in postgresql.conf */
1910 {"server_encoding", PGC_INTERNAL, CLIENT_CONN_LOCALE,
1911 gettext_noop("Sets the server (database) character set encoding."),
1913 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1915 &server_encoding_string,
1916 "SQL_ASCII", NULL, NULL
1920 /* Can't be set in postgresql.conf */
1921 {"server_version", PGC_INTERNAL, PRESET_OPTIONS,
1922 gettext_noop("Shows the server version."),
1924 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1926 &server_version_string,
1927 PG_VERSION, NULL, NULL
1931 /* Not for general use --- used by SET ROLE */
1932 {"role", PGC_USERSET, UNGROUPED,
1933 gettext_noop("Sets the current role."),
1935 GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1938 "none", assign_role, show_role
1942 /* Not for general use --- used by SET SESSION AUTHORIZATION */
1943 {"session_authorization", PGC_USERSET, UNGROUPED,
1944 gettext_noop("Sets the session user name."),
1946 GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1948 &session_authorization_string,
1949 NULL, assign_session_authorization, show_session_authorization
1953 {"log_destination", PGC_SIGHUP, LOGGING_WHERE,
1954 gettext_noop("Sets the destination for server log output."),
1955 gettext_noop("Valid values are combinations of \"stderr\", \"syslog\", "
1956 "and \"eventlog\", depending on the platform."),
1959 &log_destination_string,
1960 "stderr", assign_log_destination, NULL
1963 {"log_directory", PGC_SIGHUP, LOGGING_WHERE,
1964 gettext_noop("Sets the destination directory for log files."),
1965 gettext_noop("May be specified as relative to the data directory "
1966 "or as absolute path."),
1970 "pg_log", assign_canonical_path, NULL
1973 {"log_filename", PGC_SIGHUP, LOGGING_WHERE,
1974 gettext_noop("Sets the file name pattern for log files."),
1979 "postgresql-%Y-%m-%d_%H%M%S.log", NULL, NULL
1984 {"syslog_facility", PGC_SIGHUP, LOGGING_WHERE,
1985 gettext_noop("Sets the syslog \"facility\" to be used when syslog enabled."),
1986 gettext_noop("Valid values are LOCAL0, LOCAL1, LOCAL2, LOCAL3, "
1987 "LOCAL4, LOCAL5, LOCAL6, LOCAL7.")
1989 &syslog_facility_str,
1990 "LOCAL0", assign_syslog_facility, NULL
1993 {"syslog_ident", PGC_SIGHUP, LOGGING_WHERE,
1994 gettext_noop("Sets the program name used to identify PostgreSQL "
1995 "messages in syslog."),
1999 "postgres", assign_syslog_ident, NULL
2004 {"TimeZone", PGC_USERSET, CLIENT_CONN_LOCALE,
2005 gettext_noop("Sets the time zone for displaying and interpreting time stamps."),
2010 "UNKNOWN", assign_timezone, show_timezone
2014 {"transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
2015 gettext_noop("Sets the current transaction's isolation level."),
2017 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2019 &XactIsoLevel_string,
2020 NULL, assign_XactIsoLevel, show_XactIsoLevel
2024 {"unix_socket_group", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2025 gettext_noop("Sets the owning group of the Unix-domain socket."),
2026 gettext_noop("(The owning user of the socket is always the user "
2027 "that starts the server.)")
2034 {"unix_socket_directory", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2035 gettext_noop("Sets the directory where the Unix-domain socket will be created."),
2040 "", assign_canonical_path, NULL
2044 {"listen_addresses", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2045 gettext_noop("Sets the host name or IP address(es) to listen to."),
2050 "localhost", NULL, NULL
2054 {"wal_sync_method", PGC_SIGHUP, WAL_SETTINGS,
2055 gettext_noop("Selects the method used for forcing WAL updates out to disk."),
2059 XLOG_sync_method_default, assign_xlog_sync_method, NULL
2063 {"custom_variable_classes", PGC_SIGHUP, CUSTOM_OPTIONS,
2064 gettext_noop("Sets the list of known custom variable classes."),
2066 GUC_LIST_INPUT | GUC_LIST_QUOTE
2068 &custom_variable_classes,
2069 NULL, assign_custom_variable_classes, NULL
2073 {"data_directory", PGC_POSTMASTER, FILE_LOCATIONS,
2074 gettext_noop("Sets the server's data directory."),
2083 {"config_file", PGC_POSTMASTER, FILE_LOCATIONS,
2084 gettext_noop("Sets the server's main configuration file."),
2086 GUC_DISALLOW_IN_FILE | GUC_SUPERUSER_ONLY
2093 {"hba_file", PGC_POSTMASTER, FILE_LOCATIONS,
2094 gettext_noop("Sets the server's \"hba\" configuration file"),
2103 {"ident_file", PGC_POSTMASTER, FILE_LOCATIONS,
2104 gettext_noop("Sets the server's \"ident\" configuration file"),
2113 {"external_pid_file", PGC_POSTMASTER, FILE_LOCATIONS,
2114 gettext_noop("Writes the postmaster PID to the specified file."),
2119 NULL, assign_canonical_path, NULL
2122 /* End-of-list marker */
2124 {NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL
2129 /******** end of options list ********/
2133 * To allow continued support of obsolete names for GUC variables, we apply
2134 * the following mappings to any unrecognized name. Note that an old name
2135 * should be mapped to a new one only if the new variable has very similar
2136 * semantics to the old.
2138 static const char *const map_old_guc_names[] = {
2139 "sort_mem", "work_mem",
2140 "vacuum_mem", "maintenance_work_mem",
2146 * Actual lookup of variables is done through this single, sorted array.
2148 static struct config_generic **guc_variables;
2150 /* Current number of variables contained in the vector */
2151 static int num_guc_variables;
2153 /* Vector capacity */
2154 static int size_guc_variables;
2157 static bool guc_dirty; /* TRUE if need to do commit/abort work */
2159 static bool reporting_enabled; /* TRUE to enable GUC_REPORT */
2162 static int guc_var_compare(const void *a, const void *b);
2163 static int guc_name_compare(const char *namea, const char *nameb);
2164 static void push_old_value(struct config_generic * gconf);
2165 static void ReportGUCOption(struct config_generic * record);
2166 static void ShowGUCConfigOption(const char *name, DestReceiver *dest);
2167 static void ShowAllGUCConfig(DestReceiver *dest);
2168 static char *_ShowOption(struct config_generic * record);
2172 * Some infrastructure for checking malloc/strdup/realloc calls
2175 guc_malloc(int elevel, size_t size)
2179 data = malloc(size);
2182 (errcode(ERRCODE_OUT_OF_MEMORY),
2183 errmsg("out of memory")));
2188 guc_realloc(int elevel, void *old, size_t size)
2192 data = realloc(old, size);
2195 (errcode(ERRCODE_OUT_OF_MEMORY),
2196 errmsg("out of memory")));
2201 guc_strdup(int elevel, const char *src)
2208 (errcode(ERRCODE_OUT_OF_MEMORY),
2209 errmsg("out of memory")));
2215 * Support for assigning to a field of a string GUC item. Free the prior
2216 * value if it's not referenced anywhere else in the item (including stacked
2220 set_string_field(struct config_string * conf, char **field, char *newval)
2222 char *oldval = *field;
2225 /* Do the assignment */
2228 /* Exit if any duplicate references, or if old value was NULL anyway */
2229 if (oldval == NULL ||
2230 oldval == *(conf->variable) ||
2231 oldval == conf->reset_val ||
2232 oldval == conf->tentative_val)
2234 for (stack = conf->gen.stack; stack; stack = stack->prev)
2236 if (oldval == stack->tentative_val.stringval ||
2237 oldval == stack->value.stringval)
2241 /* Not used anymore, so free it */
2246 * Detect whether strval is referenced anywhere in a GUC string item
2249 string_field_used(struct config_string * conf, char *strval)
2253 if (strval == *(conf->variable) ||
2254 strval == conf->reset_val ||
2255 strval == conf->tentative_val)
2257 for (stack = conf->gen.stack; stack; stack = stack->prev)
2259 if (strval == stack->tentative_val.stringval ||
2260 strval == stack->value.stringval)
2267 struct config_generic **
2268 get_guc_variables(void)
2270 return guc_variables;
2275 * Build the sorted array. This is split out so that it could be
2276 * re-executed after startup (eg, we could allow loadable modules to
2277 * add vars, and then we'd need to re-sort).
2280 build_guc_variables(void)
2284 struct config_generic **guc_vars;
2287 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
2289 struct config_bool *conf = &ConfigureNamesBool[i];
2291 /* Rather than requiring vartype to be filled in by hand, do this: */
2292 conf->gen.vartype = PGC_BOOL;
2296 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
2298 struct config_int *conf = &ConfigureNamesInt[i];
2300 conf->gen.vartype = PGC_INT;
2304 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
2306 struct config_real *conf = &ConfigureNamesReal[i];
2308 conf->gen.vartype = PGC_REAL;
2312 for (i = 0; ConfigureNamesString[i].gen.name; i++)
2314 struct config_string *conf = &ConfigureNamesString[i];
2316 conf->gen.vartype = PGC_STRING;
2321 * Create table with 20% slack
2323 size_vars = num_vars + num_vars / 4;
2325 guc_vars = (struct config_generic **)
2326 guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
2330 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
2331 guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
2333 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
2334 guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
2336 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
2337 guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
2339 for (i = 0; ConfigureNamesString[i].gen.name; i++)
2340 guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
2343 free(guc_variables);
2344 guc_variables = guc_vars;
2345 num_guc_variables = num_vars;
2346 size_guc_variables = size_vars;
2347 qsort((void *) guc_variables, num_guc_variables,
2348 sizeof(struct config_generic *), guc_var_compare);
2352 is_custom_class(const char *name, int dotPos)
2355 * assign_custom_variable_classes() has made sure no empty identifiers or
2356 * whitespace exists in the variable
2358 bool result = false;
2359 const char *ccs = GetConfigOption("custom_variable_classes");
2363 const char *start = ccs;
2369 if (c == 0 || c == ',')
2371 if (dotPos == ccs - start && strncmp(start, name, dotPos) == 0)
2386 * Add a new GUC variable to the list of known variables. The
2387 * list is expanded if needed.
2390 add_guc_variable(struct config_generic * var, int elevel)
2392 if (num_guc_variables + 1 >= size_guc_variables)
2395 * Increase the vector by 25%
2397 int size_vars = size_guc_variables + size_guc_variables / 4;
2398 struct config_generic **guc_vars;
2403 guc_vars = (struct config_generic **)
2404 guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
2408 guc_vars = (struct config_generic **)
2409 guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
2412 if (guc_vars == NULL)
2413 return false; /* out of memory */
2415 guc_variables = guc_vars;
2416 size_guc_variables = size_vars;
2418 guc_variables[num_guc_variables++] = var;
2419 qsort((void *) guc_variables, num_guc_variables,
2420 sizeof(struct config_generic *), guc_var_compare);
2425 * Create and add a placeholder variable. It's presumed to belong
2426 * to a valid custom variable class at this point.
2428 static struct config_string *
2429 add_placeholder_variable(const char *name, int elevel)
2431 size_t sz = sizeof(struct config_string) + sizeof(char *);
2432 struct config_string *var;
2433 struct config_generic *gen;
2435 var = (struct config_string *) guc_malloc(elevel, sz);
2442 gen->name = guc_strdup(elevel, name);
2443 if (gen->name == NULL)
2449 gen->context = PGC_USERSET;
2450 gen->group = CUSTOM_OPTIONS;
2451 gen->short_desc = "GUC placeholder variable";
2452 gen->flags = GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_CUSTOM_PLACEHOLDER;
2453 gen->vartype = PGC_STRING;
2456 * The char* is allocated at the end of the struct since we have no
2457 * 'static' place to point to.
2459 var->variable = (char **) (var + 1);
2461 if (!add_guc_variable((struct config_generic *) var, elevel))
2463 free((void *) gen->name);
2472 * Look up option NAME. If it exists, return a pointer to its record,
2475 static struct config_generic *
2476 find_option(const char *name, int elevel)
2479 const char **key = &name;
2480 struct config_generic **res;
2486 * By equating const char ** with struct config_generic *, we are assuming
2487 * the name field is first in config_generic.
2489 res = (struct config_generic **) bsearch((void *) &key,
2490 (void *) guc_variables,
2492 sizeof(struct config_generic *),
2498 * See if the name is an obsolete name for a variable. We assume that the
2499 * set of supported old names is short enough that a brute-force search is
2502 for (i = 0; map_old_guc_names[i] != NULL; i += 2)
2504 if (guc_name_compare(name, map_old_guc_names[i]) == 0)
2505 return find_option(map_old_guc_names[i + 1], elevel);
2509 * Check if the name is qualified, and if so, check if the qualifier maps
2510 * to a custom variable class.
2512 dot = strchr(name, GUC_QUALIFIER_SEPARATOR);
2513 if (dot != NULL && is_custom_class(name, dot - name))
2514 /* Add a placeholder variable for this name */
2515 return (struct config_generic *) add_placeholder_variable(name, elevel);
2523 * comparator for qsorting and bsearching guc_variables array
2526 guc_var_compare(const void *a, const void *b)
2528 struct config_generic *confa = *(struct config_generic **) a;
2529 struct config_generic *confb = *(struct config_generic **) b;
2531 return guc_name_compare(confa->name, confb->name);
2536 guc_name_compare(const char *namea, const char *nameb)
2539 * The temptation to use strcasecmp() here must be resisted, because the
2540 * array ordering has to remain stable across setlocale() calls. So, build
2541 * our own with a simple ASCII-only downcasing.
2543 while (*namea && *nameb)
2545 char cha = *namea++;
2546 char chb = *nameb++;
2548 if (cha >= 'A' && cha <= 'Z')
2550 if (chb >= 'A' && chb <= 'Z')
2556 return 1; /* a is longer */
2558 return -1; /* b is longer */
2564 * Initialize GUC options during program startup.
2566 * Note that we cannot read the config file yet, since we have not yet
2567 * processed command-line switches.
2570 InitializeGUCOptions(void)
2576 * Build sorted array of all GUC variables.
2578 build_guc_variables();
2581 * Load all variables with their compiled-in defaults, and initialize
2582 * status fields as needed.
2584 for (i = 0; i < num_guc_variables; i++)
2586 struct config_generic *gconf = guc_variables[i];
2589 gconf->reset_source = PGC_S_DEFAULT;
2590 gconf->tentative_source = PGC_S_DEFAULT;
2591 gconf->source = PGC_S_DEFAULT;
2592 gconf->stack = NULL;
2594 switch (gconf->vartype)
2598 struct config_bool *conf = (struct config_bool *) gconf;
2600 if (conf->assign_hook)
2601 if (!(*conf->assign_hook) (conf->reset_val, true,
2603 elog(FATAL, "failed to initialize %s to %d",
2604 conf->gen.name, (int) conf->reset_val);
2605 *conf->variable = conf->reset_val;
2610 struct config_int *conf = (struct config_int *) gconf;
2612 Assert(conf->reset_val >= conf->min);
2613 Assert(conf->reset_val <= conf->max);
2614 if (conf->assign_hook)
2615 if (!(*conf->assign_hook) (conf->reset_val, true,
2617 elog(FATAL, "failed to initialize %s to %d",
2618 conf->gen.name, conf->reset_val);
2619 *conf->variable = conf->reset_val;
2624 struct config_real *conf = (struct config_real *) gconf;
2626 Assert(conf->reset_val >= conf->min);
2627 Assert(conf->reset_val <= conf->max);
2628 if (conf->assign_hook)
2629 if (!(*conf->assign_hook) (conf->reset_val, true,
2631 elog(FATAL, "failed to initialize %s to %g",
2632 conf->gen.name, conf->reset_val);
2633 *conf->variable = conf->reset_val;
2638 struct config_string *conf = (struct config_string *) gconf;
2641 *conf->variable = NULL;
2642 conf->reset_val = NULL;
2643 conf->tentative_val = NULL;
2645 if (conf->boot_val == NULL)
2647 /* Cannot set value yet */
2651 str = guc_strdup(FATAL, conf->boot_val);
2652 conf->reset_val = str;
2654 if (conf->assign_hook)
2658 newstr = (*conf->assign_hook) (str, true,
2662 elog(FATAL, "failed to initialize %s to \"%s\"",
2663 conf->gen.name, str);
2665 else if (newstr != str)
2670 * See notes in set_config_option about casting
2672 str = (char *) newstr;
2673 conf->reset_val = str;
2676 *conf->variable = str;
2684 reporting_enabled = false;
2687 * Prevent any attempt to override the transaction modes from
2688 * non-interactive sources.
2690 SetConfigOption("transaction_isolation", "default",
2691 PGC_POSTMASTER, PGC_S_OVERRIDE);
2692 SetConfigOption("transaction_read_only", "no",
2693 PGC_POSTMASTER, PGC_S_OVERRIDE);
2696 * For historical reasons, some GUC parameters can receive defaults from
2697 * environment variables. Process those settings.
2700 env = getenv("PGPORT");
2702 SetConfigOption("port", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
2704 env = getenv("PGDATESTYLE");
2706 SetConfigOption("datestyle", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
2708 env = getenv("PGCLIENTENCODING");
2710 SetConfigOption("client_encoding", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
2715 * Select the configuration files and data directory to be used, and
2716 * do the initial read of postgresql.conf.
2718 * This is called after processing command-line switches.
2719 * userDoption is the -D switch value if any (NULL if unspecified).
2720 * progname is just for use in error messages.
2722 * Returns true on success; on failure, prints a suitable error message
2723 * to stderr and returns false.
2726 SelectConfigFiles(const char *userDoption, const char *progname)
2730 struct stat stat_buf;
2732 /* configdir is -D option, or $PGDATA if no -D */
2734 configdir = make_absolute_path(userDoption);
2736 configdir = make_absolute_path(getenv("PGDATA"));
2739 * Find the configuration file: if config_file was specified on the
2740 * command line, use it, else use configdir/postgresql.conf. In any case
2741 * ensure the result is an absolute path, so that it will be interpreted
2742 * the same way by future backends.
2745 fname = make_absolute_path(ConfigFileName);
2748 fname = guc_malloc(FATAL,
2749 strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
2750 sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
2754 write_stderr("%s does not know where to find the server configuration file.\n"
2755 "You must specify the --config-file or -D invocation "
2756 "option or set the PGDATA environment variable.\n",
2762 * Set the ConfigFileName GUC variable to its final value, ensuring that
2763 * it can't be overridden later.
2765 SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
2769 * Now read the config file for the first time.
2771 if (stat(ConfigFileName, &stat_buf) != 0)
2773 write_stderr("%s cannot access the server configuration file \"%s\": %s\n",
2774 progname, ConfigFileName, strerror(errno));
2778 ProcessConfigFile(PGC_POSTMASTER);
2781 * If the data_directory GUC variable has been set, use that as DataDir;
2782 * otherwise use configdir if set; else punt.
2784 * Note: SetDataDir will copy and absolute-ize its argument, so we don't
2788 SetDataDir(data_directory);
2790 SetDataDir(configdir);
2793 write_stderr("%s does not know where to find the database system data.\n"
2794 "This can be specified as \"data_directory\" in \"%s\", "
2795 "or by the -D invocation option, or by the "
2796 "PGDATA environment variable.\n",
2797 progname, ConfigFileName);
2802 * Reflect the final DataDir value back into the data_directory GUC var.
2803 * (If you are wondering why we don't just make them a single variable,
2804 * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
2805 * child backends specially. XXX is that still true? Given that we now
2806 * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
2807 * DataDir in advance.)
2809 SetConfigOption("data_directory", DataDir, PGC_POSTMASTER, PGC_S_OVERRIDE);
2812 * Figure out where pg_hba.conf is, and make sure the path is absolute.
2815 fname = make_absolute_path(HbaFileName);
2818 fname = guc_malloc(FATAL,
2819 strlen(configdir) + strlen(HBA_FILENAME) + 2);
2820 sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
2824 write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
2825 "This can be specified as \"hba_file\" in \"%s\", "
2826 "or by the -D invocation option, or by the "
2827 "PGDATA environment variable.\n",
2828 progname, ConfigFileName);
2831 SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
2835 * Likewise for pg_ident.conf.
2838 fname = make_absolute_path(IdentFileName);
2841 fname = guc_malloc(FATAL,
2842 strlen(configdir) + strlen(IDENT_FILENAME) + 2);
2843 sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
2847 write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
2848 "This can be specified as \"ident_file\" in \"%s\", "
2849 "or by the -D invocation option, or by the "
2850 "PGDATA environment variable.\n",
2851 progname, ConfigFileName);
2854 SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
2864 * Reset all options to their saved default values (implements RESET ALL)
2867 ResetAllOptions(void)
2871 for (i = 0; i < num_guc_variables; i++)
2873 struct config_generic *gconf = guc_variables[i];
2875 /* Don't reset non-SET-able values */
2876 if (gconf->context != PGC_SUSET &&
2877 gconf->context != PGC_USERSET)
2879 /* Don't reset if special exclusion from RESET ALL */
2880 if (gconf->flags & GUC_NO_RESET_ALL)
2882 /* No need to reset if wasn't SET */
2883 if (gconf->source <= PGC_S_OVERRIDE)
2886 /* Save old value to support transaction abort */
2887 push_old_value(gconf);
2889 switch (gconf->vartype)
2893 struct config_bool *conf = (struct config_bool *) gconf;
2895 if (conf->assign_hook)
2896 if (!(*conf->assign_hook) (conf->reset_val, true,
2898 elog(ERROR, "failed to reset %s", conf->gen.name);
2899 *conf->variable = conf->reset_val;
2900 conf->tentative_val = conf->reset_val;
2901 conf->gen.source = conf->gen.reset_source;
2902 conf->gen.tentative_source = conf->gen.reset_source;
2903 conf->gen.status |= GUC_HAVE_TENTATIVE;
2909 struct config_int *conf = (struct config_int *) gconf;
2911 if (conf->assign_hook)
2912 if (!(*conf->assign_hook) (conf->reset_val, true,
2914 elog(ERROR, "failed to reset %s", conf->gen.name);
2915 *conf->variable = conf->reset_val;
2916 conf->tentative_val = conf->reset_val;
2917 conf->gen.source = conf->gen.reset_source;
2918 conf->gen.tentative_source = conf->gen.reset_source;
2919 conf->gen.status |= GUC_HAVE_TENTATIVE;
2925 struct config_real *conf = (struct config_real *) gconf;
2927 if (conf->assign_hook)
2928 if (!(*conf->assign_hook) (conf->reset_val, true,
2930 elog(ERROR, "failed to reset %s", conf->gen.name);
2931 *conf->variable = conf->reset_val;
2932 conf->tentative_val = conf->reset_val;
2933 conf->gen.source = conf->gen.reset_source;
2934 conf->gen.tentative_source = conf->gen.reset_source;
2935 conf->gen.status |= GUC_HAVE_TENTATIVE;
2941 struct config_string *conf = (struct config_string *) gconf;
2944 if (conf->reset_val == NULL)
2946 /* Nothing to reset to, as yet; so do nothing */
2950 /* We need not strdup here */
2951 str = conf->reset_val;
2953 if (conf->assign_hook)
2957 newstr = (*conf->assign_hook) (str, true,
2960 elog(ERROR, "failed to reset %s", conf->gen.name);
2961 else if (newstr != str)
2964 * See notes in set_config_option about casting
2966 str = (char *) newstr;
2970 set_string_field(conf, conf->variable, str);
2971 set_string_field(conf, &conf->tentative_val, str);
2972 conf->gen.source = conf->gen.reset_source;
2973 conf->gen.tentative_source = conf->gen.reset_source;
2974 conf->gen.status |= GUC_HAVE_TENTATIVE;
2980 if (gconf->flags & GUC_REPORT)
2981 ReportGUCOption(gconf);
2988 * Push previous state during first assignment to a GUC variable
2989 * within a particular transaction.
2991 * We have to be willing to "back-fill" the state stack if the first
2992 * assignment occurs within a subtransaction nested several levels deep.
2993 * This ensures that if an intermediate transaction aborts, it will have
2994 * the proper value available to restore the setting to.
2997 push_old_value(struct config_generic * gconf)
2999 int my_level = GetCurrentTransactionNestLevel();
3002 /* If we're not inside a transaction, do nothing */
3008 /* Done if we already pushed it at this nesting depth */
3009 if (gconf->stack && gconf->stack->nest_level >= my_level)
3013 * We keep all the stack entries in TopTransactionContext so as to
3014 * avoid allocation problems when a subtransaction back-fills stack
3015 * entries for upper transaction levels.
3017 stack = (GucStack *) MemoryContextAlloc(TopTransactionContext,
3020 stack->prev = gconf->stack;
3021 stack->nest_level = stack->prev ? stack->prev->nest_level + 1 : 1;
3022 stack->status = gconf->status;
3023 stack->tentative_source = gconf->tentative_source;
3024 stack->source = gconf->source;
3026 switch (gconf->vartype)
3029 stack->tentative_val.boolval =
3030 ((struct config_bool *) gconf)->tentative_val;
3031 stack->value.boolval =
3032 *((struct config_bool *) gconf)->variable;
3036 stack->tentative_val.intval =
3037 ((struct config_int *) gconf)->tentative_val;
3038 stack->value.intval =
3039 *((struct config_int *) gconf)->variable;
3043 stack->tentative_val.realval =
3044 ((struct config_real *) gconf)->tentative_val;
3045 stack->value.realval =
3046 *((struct config_real *) gconf)->variable;
3050 stack->tentative_val.stringval =
3051 ((struct config_string *) gconf)->tentative_val;
3052 stack->value.stringval =
3053 *((struct config_string *) gconf)->variable;
3057 gconf->stack = stack;
3059 /* Set state to indicate nothing happened yet within this level */
3060 gconf->status = GUC_HAVE_STACK;
3062 /* Ensure we remember to pop at end of xact */
3068 * Do GUC processing at transaction or subtransaction commit or abort.
3071 AtEOXact_GUC(bool isCommit, bool isSubXact)
3076 /* Quick exit if nothing's changed in this transaction */
3080 my_level = GetCurrentTransactionNestLevel();
3081 Assert(isSubXact ? (my_level > 1) : (my_level == 1));
3083 for (i = 0; i < num_guc_variables; i++)
3085 struct config_generic *gconf = guc_variables[i];
3086 int my_status = gconf->status;
3087 GucStack *stack = gconf->stack;
3092 * Skip if nothing's happened to this var in this transaction
3096 Assert(stack == NULL);
3099 /* Assert that we stacked old value before changing it */
3100 Assert(stack != NULL && (my_status & GUC_HAVE_STACK));
3101 /* However, the last change may have been at an outer xact level */
3102 if (stack->nest_level < my_level)
3104 Assert(stack->nest_level == my_level);
3107 * We will pop the stack entry. Start by restoring outer xact status
3108 * (since we may want to modify it below). Be careful to use
3109 * my_status to reference the inner xact status below this point...
3111 gconf->status = stack->status;
3114 * We have two cases:
3116 * If commit and HAVE_TENTATIVE, set actual value to tentative (this
3117 * is to override a SET LOCAL if one occurred later than SET). We keep
3118 * the tentative value and propagate HAVE_TENTATIVE to the parent
3119 * status, allowing the SET's effect to percolate up. (But if we're
3120 * exiting the outermost transaction, we'll drop the HAVE_TENTATIVE
3123 * Otherwise, we have a transaction that aborted or executed only SET
3124 * LOCAL (or no SET at all). In either case it should have no further
3125 * effect, so restore both tentative and actual values from the stack
3129 useTentative = isCommit && (my_status & GUC_HAVE_TENTATIVE) != 0;
3132 switch (gconf->vartype)
3136 struct config_bool *conf = (struct config_bool *) gconf;
3138 GucSource newsource;
3142 newval = conf->tentative_val;
3143 newsource = conf->gen.tentative_source;
3144 conf->gen.status |= GUC_HAVE_TENTATIVE;
3148 newval = stack->value.boolval;
3149 newsource = stack->source;
3150 conf->tentative_val = stack->tentative_val.boolval;
3151 conf->gen.tentative_source = stack->tentative_source;
3154 if (*conf->variable != newval)
3156 if (conf->assign_hook)
3157 if (!(*conf->assign_hook) (newval,
3158 true, PGC_S_OVERRIDE))
3159 elog(LOG, "failed to commit %s",
3161 *conf->variable = newval;
3164 conf->gen.source = newsource;
3169 struct config_int *conf = (struct config_int *) gconf;
3171 GucSource newsource;
3175 newval = conf->tentative_val;
3176 newsource = conf->gen.tentative_source;
3177 conf->gen.status |= GUC_HAVE_TENTATIVE;
3181 newval = stack->value.intval;
3182 newsource = stack->source;
3183 conf->tentative_val = stack->tentative_val.intval;
3184 conf->gen.tentative_source = stack->tentative_source;
3187 if (*conf->variable != newval)
3189 if (conf->assign_hook)
3190 if (!(*conf->assign_hook) (newval,
3191 true, PGC_S_OVERRIDE))
3192 elog(LOG, "failed to commit %s",
3194 *conf->variable = newval;
3197 conf->gen.source = newsource;
3202 struct config_real *conf = (struct config_real *) gconf;
3204 GucSource newsource;
3208 newval = conf->tentative_val;
3209 newsource = conf->gen.tentative_source;
3210 conf->gen.status |= GUC_HAVE_TENTATIVE;
3214 newval = stack->value.realval;
3215 newsource = stack->source;
3216 conf->tentative_val = stack->tentative_val.realval;
3217 conf->gen.tentative_source = stack->tentative_source;
3220 if (*conf->variable != newval)
3222 if (conf->assign_hook)
3223 if (!(*conf->assign_hook) (newval,
3224 true, PGC_S_OVERRIDE))
3225 elog(LOG, "failed to commit %s",
3227 *conf->variable = newval;
3230 conf->gen.source = newsource;
3235 struct config_string *conf = (struct config_string *) gconf;
3237 GucSource newsource;
3241 newval = conf->tentative_val;
3242 newsource = conf->gen.tentative_source;
3243 conf->gen.status |= GUC_HAVE_TENTATIVE;
3247 newval = stack->value.stringval;
3248 newsource = stack->source;
3249 set_string_field(conf, &conf->tentative_val,
3250 stack->tentative_val.stringval);
3251 conf->gen.tentative_source = stack->tentative_source;
3254 if (*conf->variable != newval)
3256 if (conf->assign_hook)
3260 newstr = (*conf->assign_hook) (newval, true,
3263 elog(LOG, "failed to commit %s",
3265 else if (newstr != newval)
3268 * If newval should now be freed, it'll be
3269 * taken care of below.
3271 * See notes in set_config_option about
3274 newval = (char *) newstr;
3278 set_string_field(conf, conf->variable, newval);
3281 conf->gen.source = newsource;
3282 /* Release stacked values if not used anymore */
3283 set_string_field(conf, &stack->value.stringval,
3285 set_string_field(conf, &stack->tentative_val.stringval,
3287 /* Don't store tentative value separately after commit */
3289 set_string_field(conf, &conf->tentative_val, NULL);
3294 /* Finish popping the state stack */
3295 gconf->stack = stack->prev;
3299 * If we're now out of all xact levels, forget TENTATIVE status bit;
3300 * there's nothing tentative about the value anymore.
3304 Assert(gconf->stack == NULL);
3308 /* Report new value if we changed it */
3309 if (changed && (gconf->flags & GUC_REPORT))
3310 ReportGUCOption(gconf);
3314 * If we're now out of all xact levels, we can clear guc_dirty. (Note: we
3315 * cannot reset guc_dirty when exiting a subtransaction, because we know
3316 * that all outer transaction levels will have stacked values to deal
3325 * Start up automatic reporting of changes to variables marked GUC_REPORT.
3326 * This is executed at completion of backend startup.
3329 BeginReportingGUCOptions(void)
3334 * Don't do anything unless talking to an interactive frontend of protocol
3337 if (whereToSendOutput != DestRemote ||
3338 PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
3341 reporting_enabled = true;
3343 /* Transmit initial values of interesting variables */
3344 for (i = 0; i < num_guc_variables; i++)
3346 struct config_generic *conf = guc_variables[i];
3348 if (conf->flags & GUC_REPORT)
3349 ReportGUCOption(conf);
3354 * ReportGUCOption: if appropriate, transmit option value to frontend
3357 ReportGUCOption(struct config_generic * record)
3359 if (reporting_enabled && (record->flags & GUC_REPORT))
3361 char *val = _ShowOption(record);
3362 StringInfoData msgbuf;
3364 pq_beginmessage(&msgbuf, 'S');
3365 pq_sendstring(&msgbuf, record->name);
3366 pq_sendstring(&msgbuf, val);
3367 pq_endmessage(&msgbuf);
3375 * Try to interpret value as boolean value. Valid values are: true,
3376 * false, yes, no, on, off, 1, 0. If the string parses okay, return
3377 * true, else false. If result is not NULL, return the parsing result
3381 parse_bool(const char *value, bool *result)
3383 size_t len = strlen(value);
3385 if (pg_strncasecmp(value, "true", len) == 0)
3390 else if (pg_strncasecmp(value, "false", len) == 0)
3396 else if (pg_strncasecmp(value, "yes", len) == 0)
3401 else if (pg_strncasecmp(value, "no", len) == 0)
3407 else if (pg_strcasecmp(value, "on") == 0)
3412 else if (pg_strcasecmp(value, "off") == 0)
3418 else if (pg_strcasecmp(value, "1") == 0)
3423 else if (pg_strcasecmp(value, "0") == 0)
3432 *result = false; /* suppress compiler warning */
3441 * Try to parse value as an integer. The accepted formats are the
3442 * usual decimal, octal, or hexadecimal formats. If the string parses
3443 * okay, return true, else false. If result is not NULL, return the
3447 parse_int(const char *value, int *result)
3453 val = strtol(value, &endptr, 0);
3454 if (endptr == value || *endptr != '\0' || errno == ERANGE
3455 #ifdef HAVE_LONG_INT_64
3456 /* if long > 32 bits, check for overflow of int4 */
3457 || val != (long) ((int32) val)
3462 *result = 0; /* suppress compiler warning */
3466 *result = (int) val;
3473 * Try to parse value as a floating point constant in the usual
3474 * format. If the value parsed okay return true, else false. If
3475 * result is not NULL, return the semantic value there.
3478 parse_real(const char *value, double *result)
3484 val = strtod(value, &endptr);
3485 if (endptr == value || *endptr != '\0' || errno == ERANGE)
3488 *result = 0; /* suppress compiler warning */
3498 * Call a GucStringAssignHook function, being careful to free the
3499 * "newval" string if the hook ereports.
3501 * This is split out of set_config_option just to avoid the "volatile"
3502 * qualifiers that would otherwise have to be plastered all over.
3505 call_string_assign_hook(GucStringAssignHook assign_hook,
3506 char *newval, bool doit, GucSource source)
3512 result = (*assign_hook) (newval, doit, source);
3526 * Sets option `name' to given value. The value should be a string
3527 * which is going to be parsed and converted to the appropriate data
3528 * type. The context and source parameters indicate in which context this
3529 * function is being called so it can apply the access restrictions
3532 * If value is NULL, set the option to its default value. If the
3533 * parameter changeVal is false then don't really set the option but do all
3534 * the checks to see if it would work.
3536 * If there is an error (non-existing option, invalid value) then an
3537 * ereport(ERROR) is thrown *unless* this is called in a context where we
3538 * don't want to ereport (currently, startup or SIGHUP config file reread).
3539 * In that case we write a suitable error message via ereport(DEBUG) and
3540 * return false. This is working around the deficiencies in the ereport
3541 * mechanism, so don't blame me. In all other cases, the function
3542 * returns true, including cases where the input is valid but we chose
3543 * not to apply it because of context or source-priority considerations.
3545 * See also SetConfigOption for an external interface.
3548 set_config_option(const char *name, const char *value,
3549 GucContext context, GucSource source,
3550 bool isLocal, bool changeVal)
3552 struct config_generic *record;
3556 if (context == PGC_SIGHUP || source == PGC_S_DEFAULT)
3559 * To avoid cluttering the log, only the postmaster bleats loudly
3560 * about problems with the config file.
3562 elevel = IsUnderPostmaster ? DEBUG2 : LOG;
3564 else if (source == PGC_S_DATABASE || source == PGC_S_USER)
3569 record = find_option(name, elevel);
3573 (errcode(ERRCODE_UNDEFINED_OBJECT),
3574 errmsg("unrecognized configuration parameter \"%s\"", name)));
3579 * Check if the option can be set at this time. See guc.h for the precise
3580 * rules. Note that we don't want to throw errors if we're in the SIGHUP
3581 * context. In that case we just ignore the attempt and return true.
3583 switch (record->context)
3586 if (context == PGC_SIGHUP)
3588 if (context != PGC_INTERNAL)
3591 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3592 errmsg("parameter \"%s\" cannot be changed",
3597 case PGC_POSTMASTER:
3598 if (context == PGC_SIGHUP)
3600 if (context != PGC_POSTMASTER)
3603 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3604 errmsg("parameter \"%s\" cannot be changed after server start",
3610 if (context != PGC_SIGHUP && context != PGC_POSTMASTER)
3613 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3614 errmsg("parameter \"%s\" cannot be changed now",
3620 * Hmm, the idea of the SIGHUP context is "ought to be global, but
3621 * can be changed after postmaster start". But there's nothing
3622 * that prevents a crafty administrator from sending SIGHUP
3623 * signals to individual backends only.
3627 if (context == PGC_SIGHUP)
3630 * If a PGC_BACKEND parameter is changed in the config file,
3631 * we want to accept the new value in the postmaster (whence
3632 * it will propagate to subsequently-started backends), but
3633 * ignore it in existing backends. This is a tad klugy, but
3634 * necessary because we don't re-read the config file during
3637 if (IsUnderPostmaster)
3640 else if (context != PGC_BACKEND && context != PGC_POSTMASTER)
3643 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3644 errmsg("parameter \"%s\" cannot be set after connection start",
3650 if (context == PGC_USERSET || context == PGC_BACKEND)
3653 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3654 errmsg("permission denied to set parameter \"%s\"",
3665 * Should we set reset/stacked values? (If so, the behavior is not
3668 makeDefault = changeVal && (source <= PGC_S_OVERRIDE) && (value != NULL);
3671 * Ignore attempted set if overridden by previously processed setting.
3672 * However, if changeVal is false then plow ahead anyway since we are
3673 * trying to find out if the value is potentially good, not actually use
3674 * it. Also keep going if makeDefault is true, since we may want to set
3675 * the reset/stacked values even if we can't set the variable itself.
3677 if (record->source > source)
3679 if (changeVal && !makeDefault)
3681 elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
3689 * Evaluate value and set variable.
3691 switch (record->vartype)
3695 struct config_bool *conf = (struct config_bool *) record;
3700 if (!parse_bool(value, &newval))
3703 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3704 errmsg("parameter \"%s\" requires a Boolean value",
3711 newval = conf->reset_val;
3712 source = conf->gen.reset_source;
3715 if (conf->assign_hook)
3716 if (!(*conf->assign_hook) (newval, changeVal, source))
3719 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3720 errmsg("invalid value for parameter \"%s\": %d",
3721 name, (int) newval)));
3725 if (changeVal || makeDefault)
3727 /* Save old value to support transaction abort */
3729 push_old_value(&conf->gen);
3732 *conf->variable = newval;
3733 conf->gen.source = source;
3739 if (conf->gen.reset_source <= source)
3741 conf->reset_val = newval;
3742 conf->gen.reset_source = source;
3744 for (stack = conf->gen.stack; stack; stack = stack->prev)
3746 if (stack->source <= source)
3748 stack->value.boolval = newval;
3749 stack->source = source;
3755 conf->gen.status |= GUC_HAVE_LOCAL;
3760 conf->tentative_val = newval;
3761 conf->gen.tentative_source = source;
3762 conf->gen.status |= GUC_HAVE_TENTATIVE;
3771 struct config_int *conf = (struct config_int *) record;
3776 if (!parse_int(value, &newval))
3779 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3780 errmsg("parameter \"%s\" requires an integer value",
3784 if (newval < conf->min || newval > conf->max)
3787 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3788 errmsg("%d is outside the valid range for parameter \"%s\" (%d .. %d)",
3789 newval, name, conf->min, conf->max)));
3795 newval = conf->reset_val;
3796 source = conf->gen.reset_source;
3799 if (conf->assign_hook)
3800 if (!(*conf->assign_hook) (newval, changeVal, source))
3803 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3804 errmsg("invalid value for parameter \"%s\": %d",
3809 if (changeVal || makeDefault)
3811 /* Save old value to support transaction abort */
3813 push_old_value(&conf->gen);
3816 *conf->variable = newval;
3817 conf->gen.source = source;
3823 if (conf->gen.reset_source <= source)
3825 conf->reset_val = newval;
3826 conf->gen.reset_source = source;
3828 for (stack = conf->gen.stack; stack; stack = stack->prev)
3830 if (stack->source <= source)
3832 stack->value.intval = newval;
3833 stack->source = source;
3839 conf->gen.status |= GUC_HAVE_LOCAL;
3844 conf->tentative_val = newval;
3845 conf->gen.tentative_source = source;
3846 conf->gen.status |= GUC_HAVE_TENTATIVE;
3855 struct config_real *conf = (struct config_real *) record;
3860 if (!parse_real(value, &newval))
3863 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3864 errmsg("parameter \"%s\" requires a numeric value",
3868 if (newval < conf->min || newval > conf->max)
3871 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3872 errmsg("%g is outside the valid range for parameter \"%s\" (%g .. %g)",
3873 newval, name, conf->min, conf->max)));
3879 newval = conf->reset_val;
3880 source = conf->gen.reset_source;
3883 if (conf->assign_hook)
3884 if (!(*conf->assign_hook) (newval, changeVal, source))
3887 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3888 errmsg("invalid value for parameter \"%s\": %g",
3893 if (changeVal || makeDefault)
3895 /* Save old value to support transaction abort */
3897 push_old_value(&conf->gen);
3900 *conf->variable = newval;
3901 conf->gen.source = source;
3907 if (conf->gen.reset_source <= source)
3909 conf->reset_val = newval;
3910 conf->gen.reset_source = source;
3912 for (stack = conf->gen.stack; stack; stack = stack->prev)
3914 if (stack->source <= source)
3916 stack->value.realval = newval;
3917 stack->source = source;
3923 conf->gen.status |= GUC_HAVE_LOCAL;
3928 conf->tentative_val = newval;
3929 conf->gen.tentative_source = source;
3930 conf->gen.status |= GUC_HAVE_TENTATIVE;
3939 struct config_string *conf = (struct config_string *) record;
3944 newval = guc_strdup(elevel, value);
3948 else if (conf->reset_val)
3951 * We could possibly avoid strdup here, but easier to make
3952 * this case work the same as the normal assignment case.
3954 newval = guc_strdup(elevel, conf->reset_val);
3957 source = conf->gen.reset_source;
3961 /* Nothing to reset to, as yet; so do nothing */
3965 if (conf->assign_hook)
3967 const char *hookresult;
3970 * If the hook ereports, we have to make sure we free
3971 * newval, else it will be a permanent memory leak.
3973 hookresult = call_string_assign_hook(conf->assign_hook,
3977 if (hookresult == NULL)
3981 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3982 errmsg("invalid value for parameter \"%s\": \"%s\"",
3983 name, value ? value : "")));
3986 else if (hookresult != newval)
3991 * Having to cast away const here is annoying, but the
3992 * alternative is to declare assign_hooks as returning
3993 * char*, which would mean they'd have to cast away
3994 * const, or as both taking and returning char*, which
3995 * doesn't seem attractive either --- we don't want
3996 * them to scribble on the passed str.
3998 newval = (char *) hookresult;
4002 if (changeVal || makeDefault)
4004 /* Save old value to support transaction abort */
4006 push_old_value(&conf->gen);
4009 set_string_field(conf, conf->variable, newval);
4010 conf->gen.source = source;
4016 if (conf->gen.reset_source <= source)
4018 set_string_field(conf, &conf->reset_val, newval);
4019 conf->gen.reset_source = source;
4021 for (stack = conf->gen.stack; stack; stack = stack->prev)
4023 if (stack->source <= source)
4025 set_string_field(conf, &stack->value.stringval,
4027 stack->source = source;
4030 /* Perhaps we didn't install newval anywhere */
4031 if (!string_field_used(conf, newval))
4036 conf->gen.status |= GUC_HAVE_LOCAL;
4041 set_string_field(conf, &conf->tentative_val, newval);
4042 conf->gen.tentative_source = source;
4043 conf->gen.status |= GUC_HAVE_TENTATIVE;
4053 if (changeVal && (record->flags & GUC_REPORT))
4054 ReportGUCOption(record);
4061 * Set a config option to the given value. See also set_config_option,
4062 * this is just the wrapper to be called from outside GUC. NB: this
4063 * is used only for non-transactional operations.
4066 SetConfigOption(const char *name, const char *value,
4067 GucContext context, GucSource source)
4069 (void) set_config_option(name, value, context, source, false, true);
4075 * Fetch the current value of the option `name'. If the option doesn't exist,
4076 * throw an ereport and don't return.
4078 * The string is *not* allocated for modification and is really only
4079 * valid until the next call to configuration related functions.
4082 GetConfigOption(const char *name)
4084 struct config_generic *record;
4085 static char buffer[256];
4087 record = find_option(name, ERROR);
4090 (errcode(ERRCODE_UNDEFINED_OBJECT),
4091 errmsg("unrecognized configuration parameter \"%s\"", name)));
4092 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
4094 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4095 errmsg("must be superuser to examine \"%s\"", name)));
4097 switch (record->vartype)
4100 return *((struct config_bool *) record)->variable ? "on" : "off";
4103 snprintf(buffer, sizeof(buffer), "%d",
4104 *((struct config_int *) record)->variable);
4108 snprintf(buffer, sizeof(buffer), "%g",
4109 *((struct config_real *) record)->variable);
4113 return *((struct config_string *) record)->variable;
4119 * Get the RESET value associated with the given option.
4122 GetConfigOptionResetString(const char *name)
4124 struct config_generic *record;
4125 static char buffer[256];
4127 record = find_option(name, ERROR);
4130 (errcode(ERRCODE_UNDEFINED_OBJECT),
4131 errmsg("unrecognized configuration parameter \"%s\"", name)));
4132 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
4134 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4135 errmsg("must be superuser to examine \"%s\"", name)));
4137 switch (record->vartype)
4140 return ((struct config_bool *) record)->reset_val ? "on" : "off";
4143 snprintf(buffer, sizeof(buffer), "%d",
4144 ((struct config_int *) record)->reset_val);
4148 snprintf(buffer, sizeof(buffer), "%g",
4149 ((struct config_real *) record)->reset_val);
4153 return ((struct config_string *) record)->reset_val;
4159 * Detect whether the given configuration option can only be set by
4163 IsSuperuserConfigOption(const char *name)
4165 struct config_generic *record;
4167 record = find_option(name, ERROR);
4168 /* On an unrecognized name, don't error, just return false. */
4171 return (record->context == PGC_SUSET);
4176 * flatten_set_variable_args
4177 * Given a parsenode List as emitted by the grammar for SET,
4178 * convert to the flat string representation used by GUC.
4180 * We need to be told the name of the variable the args are for, because
4181 * the flattening rules vary (ugh).
4183 * The result is NULL if input is NIL (ie, SET ... TO DEFAULT), otherwise
4184 * a palloc'd string.
4187 flatten_set_variable_args(const char *name, List *args)
4189 struct config_generic *record;
4195 * Fast path if just DEFAULT. We do not check the variable name in this
4196 * case --- necessary for RESET ALL to work correctly.
4201 /* Else get flags for the variable */
4202 record = find_option(name, ERROR);
4205 (errcode(ERRCODE_UNDEFINED_OBJECT),
4206 errmsg("unrecognized configuration parameter \"%s\"", name)));
4208 flags = record->flags;
4210 /* Complain if list input and non-list variable */
4211 if ((flags & GUC_LIST_INPUT) == 0 &&
4212 list_length(args) != 1)
4214 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4215 errmsg("SET %s takes only one argument", name)));
4217 initStringInfo(&buf);
4221 A_Const *arg = (A_Const *) lfirst(l);
4224 if (l != list_head(args))
4225 appendStringInfo(&buf, ", ");
4227 if (!IsA(arg, A_Const))
4228 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
4230 switch (nodeTag(&arg->val))
4233 appendStringInfo(&buf, "%ld", intVal(&arg->val));
4236 /* represented as a string, so just copy it */
4237 appendStringInfoString(&buf, strVal(&arg->val));
4240 val = strVal(&arg->val);
4241 if (arg->typename != NULL)
4244 * Must be a ConstInterval argument for TIME ZONE. Coerce
4245 * to interval and back to normalize the value and account
4252 DirectFunctionCall3(interval_in,
4253 CStringGetDatum(val),
4254 ObjectIdGetDatum(InvalidOid),
4255 Int32GetDatum(arg->typename->typmod));
4258 DatumGetCString(DirectFunctionCall1(interval_out,
4260 appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
4265 * Plain string literal or identifier. For quote mode,
4266 * quote it if it's not a vanilla identifier.
4268 if (flags & GUC_LIST_QUOTE)
4269 appendStringInfoString(&buf, quote_identifier(val));
4271 appendStringInfoString(&buf, val);
4275 elog(ERROR, "unrecognized node type: %d",
4276 (int) nodeTag(&arg->val));
4289 SetPGVariable(const char *name, List *args, bool is_local)
4291 char *argstring = flatten_set_variable_args(name, args);
4293 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
4294 set_config_option(name,
4296 (superuser() ? PGC_SUSET : PGC_USERSET),
4303 * SET command wrapped as a SQL callable function.
4306 set_config_by_name(PG_FUNCTION_ARGS)
4314 if (PG_ARGISNULL(0))
4316 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
4317 errmsg("SET requires parameter name")));
4319 /* Get the GUC variable name */
4320 name = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(0)));
4322 /* Get the desired value or set to NULL for a reset request */
4323 if (PG_ARGISNULL(1))
4326 value = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(1)));
4329 * Get the desired state of is_local. Default to false if provided value
4332 if (PG_ARGISNULL(2))
4335 is_local = PG_GETARG_BOOL(2);
4337 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
4338 set_config_option(name,
4340 (superuser() ? PGC_SUSET : PGC_USERSET),
4345 /* get the new current value */
4346 new_value = GetConfigOptionByName(name, NULL);
4348 /* Convert return string to text */
4349 result_text = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(new_value)));
4352 PG_RETURN_TEXT_P(result_text);
4356 define_custom_variable(struct config_generic * variable)
4358 const char *name = variable->name;
4359 const char **nameAddr = &name;
4361 struct config_string *pHolder;
4362 struct config_generic **res = (struct config_generic **) bsearch(
4364 (void *) guc_variables,
4366 sizeof(struct config_generic *),
4371 add_guc_variable(variable, ERROR);
4376 * This better be a placeholder
4378 if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
4380 (errcode(ERRCODE_INTERNAL_ERROR),
4381 errmsg("attempt to redefine parameter \"%s\"", name)));
4383 Assert((*res)->vartype == PGC_STRING);
4384 pHolder = (struct config_string *) * res;
4386 /* We have the same name, no sorting is necessary */
4389 value = *pHolder->variable;
4392 * Assign the string value stored in the placeholder to the real variable.
4394 * XXX this is not really good enough --- it should be a nontransactional
4395 * assignment, since we don't want it to roll back if the current xact
4398 set_config_option(name, value,
4399 pHolder->gen.context, pHolder->gen.source,
4403 * Free up as much as we conveniently can of the placeholder structure
4404 * (this neglects any stack items...)
4406 set_string_field(pHolder, pHolder->variable, NULL);
4407 set_string_field(pHolder, &pHolder->reset_val, NULL);
4408 set_string_field(pHolder, &pHolder->tentative_val, NULL);
4414 init_custom_variable(struct config_generic * gen,
4416 const char *short_desc,
4417 const char *long_desc,
4419 enum config_type type)
4421 gen->name = guc_strdup(ERROR, name);
4422 gen->context = context;
4423 gen->group = CUSTOM_OPTIONS;
4424 gen->short_desc = short_desc;
4425 gen->long_desc = long_desc;
4426 gen->vartype = type;
4430 DefineCustomBoolVariable(const char *name,
4431 const char *short_desc,
4432 const char *long_desc,
4435 GucBoolAssignHook assign_hook,
4436 GucShowHook show_hook)
4438 size_t sz = sizeof(struct config_bool);
4439 struct config_bool *var = (struct config_bool *) guc_malloc(ERROR, sz);
4442 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_BOOL);
4444 var->variable = valueAddr;
4445 var->reset_val = *valueAddr;
4446 var->assign_hook = assign_hook;
4447 var->show_hook = show_hook;
4448 define_custom_variable(&var->gen);
4452 DefineCustomIntVariable(const char *name,
4453 const char *short_desc,
4454 const char *long_desc,
4459 GucIntAssignHook assign_hook,
4460 GucShowHook show_hook)
4462 size_t sz = sizeof(struct config_int);
4463 struct config_int *var = (struct config_int *) guc_malloc(ERROR, sz);
4466 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_INT);
4468 var->variable = valueAddr;
4469 var->reset_val = *valueAddr;
4470 var->min = minValue;
4471 var->max = maxValue;
4472 var->assign_hook = assign_hook;
4473 var->show_hook = show_hook;
4474 define_custom_variable(&var->gen);
4478 DefineCustomRealVariable(const char *name,
4479 const char *short_desc,
4480 const char *long_desc,
4485 GucRealAssignHook assign_hook,
4486 GucShowHook show_hook)
4488 size_t sz = sizeof(struct config_real);
4489 struct config_real *var = (struct config_real *) guc_malloc(ERROR, sz);
4492 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_REAL);
4494 var->variable = valueAddr;
4495 var->reset_val = *valueAddr;
4496 var->min = minValue;
4497 var->max = maxValue;
4498 var->assign_hook = assign_hook;
4499 var->show_hook = show_hook;
4500 define_custom_variable(&var->gen);
4504 DefineCustomStringVariable(const char *name,
4505 const char *short_desc,
4506 const char *long_desc,
4509 GucStringAssignHook assign_hook,
4510 GucShowHook show_hook)
4512 size_t sz = sizeof(struct config_string);
4513 struct config_string *var = (struct config_string *) guc_malloc(ERROR, sz);
4516 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_STRING);
4518 var->variable = valueAddr;
4519 var->reset_val = *valueAddr;
4520 var->assign_hook = assign_hook;
4521 var->show_hook = show_hook;
4522 define_custom_variable(&var->gen);
4526 EmitWarningsOnPlaceholders(const char *className)
4528 struct config_generic **vars = guc_variables;
4529 struct config_generic **last = vars + num_guc_variables;
4531 int nameLen = strlen(className);
4535 struct config_generic *var = *vars++;
4537 if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
4538 strncmp(className, var->name, nameLen) == 0 &&
4539 var->name[nameLen] == GUC_QUALIFIER_SEPARATOR)
4542 (errcode(ERRCODE_UNDEFINED_OBJECT),
4543 errmsg("unrecognized configuration parameter \"%s\"", var->name)));
4553 GetPGVariable(const char *name, DestReceiver *dest)
4555 if (pg_strcasecmp(name, "all") == 0)
4556 ShowAllGUCConfig(dest);
4558 ShowGUCConfigOption(name, dest);
4562 GetPGVariableResultDesc(const char *name)
4566 if (pg_strcasecmp(name, "all") == 0)
4568 /* need a tuple descriptor representing three TEXT columns */
4569 tupdesc = CreateTemplateTupleDesc(3, false);
4570 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
4572 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
4574 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
4580 const char *varname;
4582 /* Get the canonical spelling of name */
4583 (void) GetConfigOptionByName(name, &varname);
4585 /* need a tuple descriptor representing a single TEXT column */
4586 tupdesc = CreateTemplateTupleDesc(1, false);
4587 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
4597 ResetPGVariable(const char *name)
4599 if (pg_strcasecmp(name, "all") == 0)
4602 set_config_option(name,
4604 (superuser() ? PGC_SUSET : PGC_USERSET),
4615 ShowGUCConfigOption(const char *name, DestReceiver *dest)
4617 TupOutputState *tstate;
4619 const char *varname;
4622 /* Get the value and canonical spelling of name */
4623 value = GetConfigOptionByName(name, &varname);
4625 /* need a tuple descriptor representing a single TEXT column */
4626 tupdesc = CreateTemplateTupleDesc(1, false);
4627 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
4630 /* prepare for projection of tuples */
4631 tstate = begin_tup_output_tupdesc(dest, tupdesc);
4634 do_text_output_oneline(tstate, value);
4636 end_tup_output(tstate);
4643 ShowAllGUCConfig(DestReceiver *dest)
4645 bool am_superuser = superuser();
4647 TupOutputState *tstate;
4651 /* need a tuple descriptor representing three TEXT columns */
4652 tupdesc = CreateTemplateTupleDesc(3, false);
4653 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
4655 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
4657 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
4661 /* prepare for projection of tuples */
4662 tstate = begin_tup_output_tupdesc(dest, tupdesc);
4664 for (i = 0; i < num_guc_variables; i++)
4666 struct config_generic *conf = guc_variables[i];
4668 if ((conf->flags & GUC_NO_SHOW_ALL) ||
4669 ((conf->flags & GUC_SUPERUSER_ONLY) && !am_superuser))
4672 /* assign to the values array */
4673 values[0] = (char *) conf->name;
4674 values[1] = _ShowOption(conf);
4675 values[2] = (char *) conf->short_desc;
4677 /* send it to dest */
4678 do_tup_output(tstate, values);
4681 if (values[1] != NULL)
4685 end_tup_output(tstate);
4689 * Return GUC variable value by name; optionally return canonical
4690 * form of name. Return value is palloc'd.
4693 GetConfigOptionByName(const char *name, const char **varname)
4695 struct config_generic *record;
4697 record = find_option(name, ERROR);
4700 (errcode(ERRCODE_UNDEFINED_OBJECT),
4701 errmsg("unrecognized configuration parameter \"%s\"", name)));
4702 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
4704 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4705 errmsg("must be superuser to examine \"%s\"", name)));
4708 *varname = record->name;
4710 return _ShowOption(record);
4714 * Return GUC variable value by variable number; optionally return canonical
4715 * form of name. Return value is palloc'd.
4718 GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
4721 struct config_generic *conf;
4723 /* check requested variable number valid */
4724 Assert((varnum >= 0) && (varnum < num_guc_variables));
4726 conf = guc_variables[varnum];
4730 if ((conf->flags & GUC_NO_SHOW_ALL) ||
4731 ((conf->flags & GUC_SUPERUSER_ONLY) && !superuser()))
4737 /* first get the generic attributes */
4740 values[0] = conf->name;
4742 /* setting : use _ShowOption in order to avoid duplicating the logic */
4743 values[1] = _ShowOption(conf);
4746 values[2] = config_group_names[conf->group];
4749 values[3] = conf->short_desc;
4752 values[4] = conf->long_desc;
4755 values[5] = GucContext_Names[conf->context];
4758 values[6] = config_type_names[conf->vartype];
4761 values[7] = GucSource_Names[conf->source];
4763 /* now get the type specifc attributes */
4764 switch (conf->vartype)
4778 struct config_int *lconf = (struct config_int *) conf;
4781 snprintf(buffer, sizeof(buffer), "%d", lconf->min);
4782 values[8] = pstrdup(buffer);
4785 snprintf(buffer, sizeof(buffer), "%d", lconf->max);
4786 values[9] = pstrdup(buffer);
4792 struct config_real *lconf = (struct config_real *) conf;
4795 snprintf(buffer, sizeof(buffer), "%g", lconf->min);
4796 values[8] = pstrdup(buffer);
4799 snprintf(buffer, sizeof(buffer), "%g", lconf->max);
4800 values[9] = pstrdup(buffer);
4817 * should never get here, but in case we do, set 'em to NULL
4831 * Return the total number of GUC variables
4834 GetNumConfigOptions(void)
4836 return num_guc_variables;
4840 * show_config_by_name - equiv to SHOW X command but implemented as
4844 show_config_by_name(PG_FUNCTION_ARGS)
4850 /* Get the GUC variable name */
4851 varname = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(0)));
4854 varval = GetConfigOptionByName(varname, NULL);
4856 /* Convert to text */
4857 result_text = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(varval)));
4860 PG_RETURN_TEXT_P(result_text);
4864 * show_all_settings - equiv to SHOW ALL command but implemented as
4867 #define NUM_PG_SETTINGS_ATTS 10
4870 show_all_settings(PG_FUNCTION_ARGS)
4872 FuncCallContext *funcctx;
4876 AttInMetadata *attinmeta;
4877 MemoryContext oldcontext;
4879 /* stuff done only on the first call of the function */
4880 if (SRF_IS_FIRSTCALL())
4882 /* create a function context for cross-call persistence */
4883 funcctx = SRF_FIRSTCALL_INIT();
4886 * switch to memory context appropriate for multiple function calls
4888 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
4891 * need a tuple descriptor representing NUM_PG_SETTINGS_ATTS columns
4892 * of the appropriate types
4894 tupdesc = CreateTemplateTupleDesc(NUM_PG_SETTINGS_ATTS, false);
4895 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
4897 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
4899 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "category",
4901 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "short_desc",
4903 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "extra_desc",
4905 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "context",
4907 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "vartype",
4909 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "source",
4911 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "min_val",
4913 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "max_val",
4917 * Generate attribute metadata needed later to produce tuples from raw
4920 attinmeta = TupleDescGetAttInMetadata(tupdesc);
4921 funcctx->attinmeta = attinmeta;
4923 /* total number of tuples to be returned */
4924 funcctx->max_calls = GetNumConfigOptions();
4926 MemoryContextSwitchTo(oldcontext);
4929 /* stuff done on every call of the function */
4930 funcctx = SRF_PERCALL_SETUP();
4932 call_cntr = funcctx->call_cntr;
4933 max_calls = funcctx->max_calls;
4934 attinmeta = funcctx->attinmeta;
4936 if (call_cntr < max_calls) /* do when there is more left to send */
4938 char *values[NUM_PG_SETTINGS_ATTS];
4944 * Get the next visible GUC variable name and value
4948 GetConfigOptionByNum(call_cntr, (const char **) values, &noshow);
4951 /* bump the counter and get the next config setting */
4952 call_cntr = ++funcctx->call_cntr;
4954 /* make sure we haven't gone too far now */
4955 if (call_cntr >= max_calls)
4956 SRF_RETURN_DONE(funcctx);
4961 tuple = BuildTupleFromCStrings(attinmeta, values);
4963 /* make the tuple into a datum */
4964 result = HeapTupleGetDatum(tuple);
4966 SRF_RETURN_NEXT(funcctx, result);
4970 /* do when there is no more left */
4971 SRF_RETURN_DONE(funcctx);
4976 _ShowOption(struct config_generic * record)
4981 switch (record->vartype)
4985 struct config_bool *conf = (struct config_bool *) record;
4987 if (conf->show_hook)
4988 val = (*conf->show_hook) ();
4990 val = *conf->variable ? "on" : "off";
4996 struct config_int *conf = (struct config_int *) record;
4998 if (conf->show_hook)
4999 val = (*conf->show_hook) ();
5002 snprintf(buffer, sizeof(buffer), "%d",
5011 struct config_real *conf = (struct config_real *) record;
5013 if (conf->show_hook)
5014 val = (*conf->show_hook) ();
5017 snprintf(buffer, sizeof(buffer), "%g",
5026 struct config_string *conf = (struct config_string *) record;
5028 if (conf->show_hook)
5029 val = (*conf->show_hook) ();
5030 else if (*conf->variable && **conf->variable)
5031 val = *conf->variable;
5038 /* just to keep compiler quiet */
5043 return pstrdup(val);
5050 * This routine dumps out all non-default GUC options into a binary
5051 * file that is read by all exec'ed backends. The format is:
5053 * variable name, string, null terminated
5054 * variable value, string, null terminated
5055 * variable source, integer
5058 write_nondefault_variables(GucContext context)
5064 Assert(context == PGC_POSTMASTER || context == PGC_SIGHUP);
5066 elevel = (context == PGC_SIGHUP) ? LOG : ERROR;
5071 fp = AllocateFile(CONFIG_EXEC_PARAMS_NEW, "w");
5075 (errcode_for_file_access(),
5076 errmsg("could not write to file \"%s\": %m",
5077 CONFIG_EXEC_PARAMS_NEW)));
5081 for (i = 0; i < num_guc_variables; i++)
5083 struct config_generic *gconf = guc_variables[i];
5085 if (gconf->source != PGC_S_DEFAULT)
5087 fprintf(fp, "%s", gconf->name);
5090 switch (gconf->vartype)
5094 struct config_bool *conf = (struct config_bool *) gconf;
5096 if (*conf->variable == 0)
5097 fprintf(fp, "false");
5099 fprintf(fp, "true");
5105 struct config_int *conf = (struct config_int *) gconf;
5107 fprintf(fp, "%d", *conf->variable);
5113 struct config_real *conf = (struct config_real *) gconf;
5115 /* Could lose precision here? */
5116 fprintf(fp, "%f", *conf->variable);
5122 struct config_string *conf = (struct config_string *) gconf;
5124 fprintf(fp, "%s", *conf->variable);
5131 fwrite(&gconf->source, sizeof(gconf->source), 1, fp);
5138 (errcode_for_file_access(),
5139 errmsg("could not write to file \"%s\": %m",
5140 CONFIG_EXEC_PARAMS_NEW)));
5145 * Put new file in place. This could delay on Win32, but we don't hold
5146 * any exclusive locks.
5148 rename(CONFIG_EXEC_PARAMS_NEW, CONFIG_EXEC_PARAMS);
5153 * Read string, including null byte from file
5155 * Return NULL on EOF and nothing read
5158 read_string_with_null(FILE *fp)
5167 if ((ch = fgetc(fp)) == EOF)
5172 elog(FATAL, "invalid format of exec config params file");
5175 str = guc_malloc(FATAL, maxlen);
5176 else if (i == maxlen)
5177 str = guc_realloc(FATAL, str, maxlen *= 2);
5186 * This routine loads a previous postmaster dump of its non-default
5190 read_nondefault_variables(void)
5200 fp = AllocateFile(CONFIG_EXEC_PARAMS, "r");
5203 /* File not found is fine */
5204 if (errno != ENOENT)
5206 (errcode_for_file_access(),
5207 errmsg("could not read from file \"%s\": %m",
5208 CONFIG_EXEC_PARAMS)));
5214 struct config_generic *record;
5216 if ((varname = read_string_with_null(fp)) == NULL)
5219 if ((record = find_option(varname, FATAL)) == NULL)
5220 elog(FATAL, "failed to locate variable %s in exec config params file", varname);
5221 if ((varvalue = read_string_with_null(fp)) == NULL)
5222 elog(FATAL, "invalid format of exec config params file");
5223 if (fread(&varsource, sizeof(varsource), 1, fp) == 0)
5224 elog(FATAL, "invalid format of exec config params file");
5226 (void) set_config_option(varname, varvalue, record->context,
5227 varsource, false, true);
5234 #endif /* EXEC_BACKEND */
5238 * A little "long argument" simulation, although not quite GNU
5239 * compliant. Takes a string of the form "some-option=some value" and
5240 * returns name = "some_option" and value = "some value" in malloc'ed
5241 * storage. Note that '-' is converted to '_' in the option name. If
5242 * there is no '=' in the input string then value will be NULL.
5245 ParseLongOption(const char *string, char **name, char **value)
5254 equal_pos = strcspn(string, "=");
5256 if (string[equal_pos] == '=')
5258 *name = guc_malloc(FATAL, equal_pos + 1);
5259 strncpy(*name, string, equal_pos);
5260 (*name)[equal_pos] = '\0';
5262 *value = guc_strdup(FATAL, &string[equal_pos + 1]);
5266 /* no equal sign in string */
5267 *name = guc_strdup(FATAL, string);
5271 for (cp = *name; *cp; cp++)
5278 * Handle options fetched from pg_database.datconfig or pg_authid.rolconfig.
5279 * The array parameter must be an array of TEXT (it must not be NULL).
5282 ProcessGUCArray(ArrayType *array, GucSource source)
5286 Assert(array != NULL);
5287 Assert(ARR_ELEMTYPE(array) == TEXTOID);
5288 Assert(ARR_NDIM(array) == 1);
5289 Assert(ARR_LBOUND(array)[0] == 1);
5290 Assert(source == PGC_S_DATABASE || source == PGC_S_USER);
5292 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
5300 d = array_ref(array, 1, &i,
5301 -1 /* varlenarray */ ,
5302 -1 /* TEXT's typlen */ ,
5303 false /* TEXT's typbyval */ ,
5304 'i' /* TEXT's typalign */ ,
5310 s = DatumGetCString(DirectFunctionCall1(textout, d));
5312 ParseLongOption(s, &name, &value);
5316 (errcode(ERRCODE_SYNTAX_ERROR),
5317 errmsg("could not parse setting for parameter \"%s\"", name)));
5323 * We process all these options at SUSET level. We assume that the
5324 * right to insert an option into pg_database or pg_authid was checked
5325 * when it was inserted.
5327 SetConfigOption(name, value, PGC_SUSET, source);
5337 * Add an entry to an option array. The array parameter may be NULL
5338 * to indicate the current table entry is NULL.
5341 GUCArrayAdd(ArrayType *array, const char *name, const char *value)
5343 const char *varname;
5351 /* test if the option is valid */
5352 set_config_option(name, value,
5353 superuser() ? PGC_SUSET : PGC_USERSET,
5354 PGC_S_TEST, false, false);
5356 /* convert name to canonical spelling, so we can use plain strcmp */
5357 (void) GetConfigOptionByName(name, &varname);
5360 newval = palloc(strlen(name) + 1 + strlen(value) + 1);
5361 sprintf(newval, "%s=%s", name, value);
5362 datum = DirectFunctionCall1(textin, CStringGetDatum(newval));
5370 Assert(ARR_ELEMTYPE(array) == TEXTOID);
5371 Assert(ARR_NDIM(array) == 1);
5372 Assert(ARR_LBOUND(array)[0] == 1);
5374 index = ARR_DIMS(array)[0] + 1; /* add after end */
5376 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
5381 d = array_ref(array, 1, &i,
5382 -1 /* varlenarray */ ,
5383 -1 /* TEXT's typlen */ ,
5384 false /* TEXT's typbyval */ ,
5385 'i' /* TEXT's typalign */ ,
5389 current = DatumGetCString(DirectFunctionCall1(textout, d));
5390 if (strncmp(current, newval, strlen(name) + 1) == 0)
5397 a = array_set(array, 1, &index,
5400 -1 /* varlena array */ ,
5401 -1 /* TEXT's typlen */ ,
5402 false /* TEXT's typbyval */ ,
5403 'i' /* TEXT's typalign */ );
5406 a = construct_array(&datum, 1,
5415 * Delete an entry from an option array. The array parameter may be NULL
5416 * to indicate the current table entry is NULL. Also, if the return value
5417 * is NULL then a null should be stored.
5420 GUCArrayDelete(ArrayType *array, const char *name)
5422 const char *varname;
5423 ArrayType *newarray;
5429 /* test if the option is valid */
5430 set_config_option(name, NULL,
5431 superuser() ? PGC_SUSET : PGC_USERSET,
5432 PGC_S_TEST, false, false);
5434 /* convert name to canonical spelling, so we can use plain strcmp */
5435 (void) GetConfigOptionByName(name, &varname);
5438 /* if array is currently null, then surely nothing to delete */
5445 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
5451 d = array_ref(array, 1, &i,
5452 -1 /* varlenarray */ ,
5453 -1 /* TEXT's typlen */ ,
5454 false /* TEXT's typbyval */ ,
5455 'i' /* TEXT's typalign */ ,
5459 val = DatumGetCString(DirectFunctionCall1(textout, d));
5461 /* ignore entry if it's what we want to delete */
5462 if (strncmp(val, name, strlen(name)) == 0
5463 && val[strlen(name)] == '=')
5466 /* else add it to the output array */
5469 newarray = array_set(newarray, 1, &index,
5472 -1 /* varlenarray */ ,
5473 -1 /* TEXT's typlen */ ,
5474 false /* TEXT's typbyval */ ,
5475 'i' /* TEXT's typalign */ );
5478 newarray = construct_array(&d, 1,
5490 * assign_hook subroutines
5494 assign_log_destination(const char *value, bool doit, GucSource source)
5501 /* Need a modifiable copy of string */
5502 rawstring = pstrdup(value);
5504 /* Parse string into list of identifiers */
5505 if (!SplitIdentifierString(rawstring, ',', &elemlist))
5507 /* syntax error in list */
5509 list_free(elemlist);
5510 if (source >= PGC_S_INTERACTIVE)
5512 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5513 errmsg("invalid list syntax for parameter \"log_destination\"")));
5517 foreach(l, elemlist)
5519 char *tok = (char *) lfirst(l);
5521 if (pg_strcasecmp(tok, "stderr") == 0)
5522 newlogdest |= LOG_DESTINATION_STDERR;
5524 else if (pg_strcasecmp(tok, "syslog") == 0)
5525 newlogdest |= LOG_DESTINATION_SYSLOG;
5528 else if (pg_strcasecmp(tok, "eventlog") == 0)
5529 newlogdest |= LOG_DESTINATION_EVENTLOG;
5533 if (source >= PGC_S_INTERACTIVE)
5535 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5536 errmsg("unrecognized \"log_destination\" key word: \"%s\"",
5539 list_free(elemlist);
5545 Log_destination = newlogdest;
5548 list_free(elemlist);
5556 assign_syslog_facility(const char *facility, bool doit, GucSource source)
5560 if (pg_strcasecmp(facility, "LOCAL0") == 0)
5561 syslog_fac = LOG_LOCAL0;
5562 else if (pg_strcasecmp(facility, "LOCAL1") == 0)
5563 syslog_fac = LOG_LOCAL1;
5564 else if (pg_strcasecmp(facility, "LOCAL2") == 0)
5565 syslog_fac = LOG_LOCAL2;
5566 else if (pg_strcasecmp(facility, "LOCAL3") == 0)
5567 syslog_fac = LOG_LOCAL3;
5568 else if (pg_strcasecmp(facility, "LOCAL4") == 0)
5569 syslog_fac = LOG_LOCAL4;
5570 else if (pg_strcasecmp(facility, "LOCAL5") == 0)
5571 syslog_fac = LOG_LOCAL5;
5572 else if (pg_strcasecmp(facility, "LOCAL6") == 0)
5573 syslog_fac = LOG_LOCAL6;
5574 else if (pg_strcasecmp(facility, "LOCAL7") == 0)
5575 syslog_fac = LOG_LOCAL7;
5577 return NULL; /* reject */
5581 syslog_facility = syslog_fac;
5582 set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
5590 assign_syslog_ident(const char *ident, bool doit, GucSource source)
5593 set_syslog_parameters(ident, syslog_facility);
5597 #endif /* HAVE_SYSLOG */
5601 assign_defaultxactisolevel(const char *newval, bool doit, GucSource source)
5603 if (pg_strcasecmp(newval, "serializable") == 0)
5606 DefaultXactIsoLevel = XACT_SERIALIZABLE;
5608 else if (pg_strcasecmp(newval, "repeatable read") == 0)
5611 DefaultXactIsoLevel = XACT_REPEATABLE_READ;
5613 else if (pg_strcasecmp(newval, "read committed") == 0)
5616 DefaultXactIsoLevel = XACT_READ_COMMITTED;
5618 else if (pg_strcasecmp(newval, "read uncommitted") == 0)
5621 DefaultXactIsoLevel = XACT_READ_UNCOMMITTED;
5629 assign_log_min_messages(const char *newval,
5630 bool doit, GucSource source)
5632 return (assign_msglvl(&log_min_messages, newval, doit, source));
5636 assign_client_min_messages(const char *newval, bool doit, GucSource source)
5638 return (assign_msglvl(&client_min_messages, newval, doit, source));
5642 assign_min_error_statement(const char *newval, bool doit, GucSource source)
5644 return (assign_msglvl(&log_min_error_statement, newval, doit, source));
5648 assign_msglvl(int *var, const char *newval, bool doit, GucSource source)
5650 if (pg_strcasecmp(newval, "debug") == 0)
5655 else if (pg_strcasecmp(newval, "debug5") == 0)
5660 else if (pg_strcasecmp(newval, "debug4") == 0)
5665 else if (pg_strcasecmp(newval, "debug3") == 0)
5670 else if (pg_strcasecmp(newval, "debug2") == 0)
5675 else if (pg_strcasecmp(newval, "debug1") == 0)
5680 else if (pg_strcasecmp(newval, "log") == 0)
5687 * Client_min_messages always prints 'info', but we allow it as a value
5690 else if (pg_strcasecmp(newval, "info") == 0)
5695 else if (pg_strcasecmp(newval, "notice") == 0)
5700 else if (pg_strcasecmp(newval, "warning") == 0)
5705 else if (pg_strcasecmp(newval, "error") == 0)
5710 /* We allow FATAL/PANIC for client-side messages too. */
5711 else if (pg_strcasecmp(newval, "fatal") == 0)
5716 else if (pg_strcasecmp(newval, "panic") == 0)
5722 return NULL; /* fail */
5723 return newval; /* OK */
5727 assign_log_error_verbosity(const char *newval, bool doit, GucSource source)
5729 if (pg_strcasecmp(newval, "terse") == 0)
5732 Log_error_verbosity = PGERROR_TERSE;
5734 else if (pg_strcasecmp(newval, "default") == 0)
5737 Log_error_verbosity = PGERROR_DEFAULT;
5739 else if (pg_strcasecmp(newval, "verbose") == 0)
5742 Log_error_verbosity = PGERROR_VERBOSE;
5745 return NULL; /* fail */
5746 return newval; /* OK */
5750 assign_log_statement(const char *newval, bool doit, GucSource source)
5752 if (pg_strcasecmp(newval, "none") == 0)
5755 log_statement = LOGSTMT_NONE;
5757 else if (pg_strcasecmp(newval, "ddl") == 0)
5760 log_statement = LOGSTMT_DDL;
5762 else if (pg_strcasecmp(newval, "mod") == 0)
5765 log_statement = LOGSTMT_MOD;
5767 else if (pg_strcasecmp(newval, "all") == 0)
5770 log_statement = LOGSTMT_ALL;
5773 return NULL; /* fail */
5774 return newval; /* OK */
5778 show_num_temp_buffers(void)
5781 * We show the GUC var until local buffers have been initialized, and
5782 * NLocBuffer afterwards.
5784 static char nbuf[32];
5786 sprintf(nbuf, "%d", NLocBuffer ? NLocBuffer : num_temp_buffers);
5791 assign_phony_autocommit(bool newval, bool doit, GucSource source)
5795 if (doit && source >= PGC_S_INTERACTIVE)
5797 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5798 errmsg("SET AUTOCOMMIT TO OFF is no longer supported")));
5805 assign_custom_variable_classes(const char *newval, bool doit, GucSource source)
5808 * Check syntax. newval must be a comma separated list of identifiers.
5809 * Whitespace is allowed but skipped.
5811 bool hasSpaceAfterToken = false;
5812 const char *cp = newval;
5817 initStringInfo(&buf);
5818 while ((c = *cp++) != 0)
5823 hasSpaceAfterToken = true;
5829 hasSpaceAfterToken = false;
5833 appendStringInfoChar(&buf, ',');
5838 if (hasSpaceAfterToken || !isalnum(c))
5841 * Syntax error due to token following space after token or non
5842 * alpha numeric character
5845 (errcode(ERRCODE_SYNTAX_ERROR),
5846 errmsg("invalid syntax for \"custom_variable_classes\": \"%s\"", newval)));
5851 appendStringInfoChar(&buf, (char) c);
5854 /* Remove stray ',' at end */
5855 if (symLen == 0 && buf.len > 0)
5856 buf.data[--buf.len] = '\0';
5861 newval = strdup(buf.data);
5868 assign_stage_log_stats(bool newval, bool doit, GucSource source)
5870 if (newval && log_statement_stats)
5872 if (source >= PGC_S_INTERACTIVE)
5874 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5875 errmsg("cannot enable parameter when \"log_statement_stats\" is true")));
5876 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
5877 else if (source != PGC_S_OVERRIDE)
5884 assign_log_stats(bool newval, bool doit, GucSource source)
5887 (log_parser_stats || log_planner_stats || log_executor_stats))
5889 if (source >= PGC_S_INTERACTIVE)
5891 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5892 errmsg("cannot enable \"log_statement_stats\" when "
5893 "\"log_parser_stats\", \"log_planner_stats\", "
5894 "or \"log_executor_stats\" is true")));
5895 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
5896 else if (source != PGC_S_OVERRIDE)
5903 assign_transaction_read_only(bool newval, bool doit, GucSource source)
5905 /* Can't go to r/w mode inside a r/o transaction */
5906 if (newval == false && XactReadOnly && IsSubTransaction())
5908 if (source >= PGC_S_INTERACTIVE)
5910 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5911 errmsg("cannot set transaction read-write mode inside a read-only transaction")));
5912 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
5913 else if (source != PGC_S_OVERRIDE)
5920 assign_canonical_path(const char *newval, bool doit, GucSource source)
5924 char *canon_val = guc_strdup(ERROR, newval);
5926 canonicalize_path(canon_val);
5934 assign_tcp_keepalives_idle(int newval, bool doit, GucSource source)
5937 return (pq_setkeepalivesidle(newval, MyProcPort) == STATUS_OK);
5943 show_tcp_keepalives_idle(void)
5945 static char nbuf[16];
5947 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesidle(MyProcPort));
5952 assign_tcp_keepalives_interval(int newval, bool doit, GucSource source)
5955 return (pq_setkeepalivesinterval(newval, MyProcPort) == STATUS_OK);
5961 show_tcp_keepalives_interval(void)
5963 static char nbuf[16];
5965 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesinterval(MyProcPort));
5970 assign_tcp_keepalives_count(int newval, bool doit, GucSource source)
5973 return (pq_setkeepalivescount(newval, MyProcPort) == STATUS_OK);
5979 show_tcp_keepalives_count(void)
5981 static char nbuf[16];
5983 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivescount(MyProcPort));
5988 #include "guc-file.c"