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-2007, PostgreSQL Global Development Group
10 * Written by Peter Eisentraut <peter_e@gmx.net>.
13 * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.376 2007/02/16 17:07:00 tgl Exp $
15 *--------------------------------------------------------------------
29 #include "access/gin.h"
30 #include "access/transam.h"
31 #include "access/twophase.h"
32 #include "access/xact.h"
33 #include "catalog/namespace.h"
34 #include "commands/async.h"
35 #include "commands/vacuum.h"
36 #include "commands/variable.h"
38 #include "libpq/auth.h"
39 #include "libpq/pqformat.h"
40 #include "miscadmin.h"
41 #include "optimizer/cost.h"
42 #include "optimizer/geqo.h"
43 #include "optimizer/paths.h"
44 #include "optimizer/planmain.h"
45 #include "parser/gramparse.h"
46 #include "parser/parse_expr.h"
47 #include "parser/parse_relation.h"
48 #include "parser/parse_type.h"
49 #include "parser/scansup.h"
51 #include "postmaster/autovacuum.h"
52 #include "postmaster/bgwriter.h"
53 #include "postmaster/postmaster.h"
54 #include "postmaster/syslogger.h"
55 #include "storage/fd.h"
56 #include "storage/freespace.h"
57 #include "tcop/tcopprot.h"
58 #include "utils/builtins.h"
59 #include "utils/guc_tables.h"
60 #include "utils/memutils.h"
61 #include "utils/pg_locale.h"
62 #include "utils/ps_status.h"
63 #include "utils/tzparser.h"
64 #include "utils/xml.h"
67 #define PG_KRB_SRVTAB ""
70 #define PG_KRB_SRVNAM ""
73 #define CONFIG_FILENAME "postgresql.conf"
74 #define HBA_FILENAME "pg_hba.conf"
75 #define IDENT_FILENAME "pg_ident.conf"
78 #define CONFIG_EXEC_PARAMS "global/config_exec_params"
79 #define CONFIG_EXEC_PARAMS_NEW "global/config_exec_params.new"
82 /* upper limit for GUC variables measured in kilobytes of memory */
84 #define MAX_KILOBYTES INT_MAX
86 #define MAX_KILOBYTES (INT_MAX / 1024)
89 #define KB_PER_MB (1024)
90 #define KB_PER_GB (1024*1024)
93 #define MS_PER_MIN (1000 * 60)
94 #define MS_PER_H (1000 * 60 * 60)
95 #define MS_PER_D (1000 * 60 * 60 * 24)
97 /* XXX these should appear in other modules' header files */
98 extern bool Log_disconnections;
99 extern int CommitDelay;
100 extern int CommitSiblings;
101 extern char *default_tablespace;
102 extern char *temp_tablespaces;
103 extern bool fullPageWrites;
106 extern bool trace_sort;
110 extern char *SSLCipherSuites;
114 static const char *assign_log_destination(const char *value,
115 bool doit, GucSource source);
118 static int syslog_facility = LOG_LOCAL0;
120 static const char *assign_syslog_facility(const char *facility,
121 bool doit, GucSource source);
122 static const char *assign_syslog_ident(const char *ident,
123 bool doit, GucSource source);
126 static const char *assign_defaultxactisolevel(const char *newval, bool doit,
128 static const char *assign_log_min_messages(const char *newval, bool doit,
130 static const char *assign_client_min_messages(const char *newval,
131 bool doit, GucSource source);
132 static const char *assign_min_error_statement(const char *newval, bool doit,
134 static const char *assign_msglvl(int *var, const char *newval, bool doit,
136 static const char *assign_log_error_verbosity(const char *newval, bool doit,
138 static const char *assign_log_statement(const char *newval, bool doit,
140 static const char *show_num_temp_buffers(void);
141 static bool assign_phony_autocommit(bool newval, bool doit, GucSource source);
142 static const char *assign_custom_variable_classes(const char *newval, bool doit,
144 static bool assign_debug_assertions(bool newval, bool doit, GucSource source);
145 static bool assign_ssl(bool newval, bool doit, GucSource source);
146 static bool assign_stage_log_stats(bool newval, bool doit, GucSource source);
147 static bool assign_log_stats(bool newval, bool doit, GucSource source);
148 static bool assign_transaction_read_only(bool newval, bool doit, GucSource source);
149 static const char *assign_canonical_path(const char *newval, bool doit, GucSource source);
150 static const char *assign_backslash_quote(const char *newval, bool doit, GucSource source);
151 static const char *assign_timezone_abbreviations(const char *newval, bool doit, GucSource source);
152 static const char *assign_xmlbinary(const char *newval, bool doit, GucSource source);
153 static const char *assign_xmloption(const char *newval, bool doit, GucSource source);
155 static bool assign_tcp_keepalives_idle(int newval, bool doit, GucSource source);
156 static bool assign_tcp_keepalives_interval(int newval, bool doit, GucSource source);
157 static bool assign_tcp_keepalives_count(int newval, bool doit, GucSource source);
158 static const char *show_tcp_keepalives_idle(void);
159 static const char *show_tcp_keepalives_interval(void);
160 static const char *show_tcp_keepalives_count(void);
163 * GUC option variables that are exported from this module
165 #ifdef USE_ASSERT_CHECKING
166 bool assert_enabled = true;
168 bool assert_enabled = false;
170 bool log_duration = false;
171 bool Debug_print_plan = false;
172 bool Debug_print_parse = false;
173 bool Debug_print_rewritten = false;
174 bool Debug_pretty_print = false;
175 bool Explain_pretty_print = true;
177 bool log_parser_stats = false;
178 bool log_planner_stats = false;
179 bool log_executor_stats = false;
180 bool log_statement_stats = false; /* this is sort of all three
182 bool log_btree_build_stats = false;
184 bool check_function_bodies = true;
185 bool default_with_oids = false;
186 bool SQL_inheritance = true;
188 bool Password_encryption = true;
190 int log_min_error_statement = ERROR;
191 int log_min_messages = NOTICE;
192 int client_min_messages = NOTICE;
193 int log_min_duration_statement = -1;
194 int log_temp_files = -1;
196 int num_temp_buffers = 1000;
198 char *ConfigFileName;
201 char *external_pid_file;
203 int tcp_keepalives_idle;
204 int tcp_keepalives_interval;
205 int tcp_keepalives_count;
208 * These variables are all dummies that don't do anything, except in some
209 * cases provide the value for SHOW to display. The real state is elsewhere
210 * and is kept in sync by assign_hooks.
212 static char *client_min_messages_str;
213 static char *log_min_messages_str;
214 static char *log_error_verbosity_str;
215 static char *log_statement_str;
216 static char *log_min_error_statement_str;
217 static char *log_destination_string;
220 static char *syslog_facility_str;
221 static char *syslog_ident_str;
223 static bool phony_autocommit;
224 static bool session_auth_is_superuser;
225 static double phony_random_seed;
226 static char *backslash_quote_string;
227 static char *client_encoding_string;
228 static char *datestyle_string;
229 static char *default_iso_level_string;
230 static char *locale_collate;
231 static char *locale_ctype;
232 static char *regex_flavor_string;
233 static char *server_encoding_string;
234 static char *server_version_string;
235 static int server_version_num;
236 static char *timezone_string;
237 static char *timezone_abbreviations_string;
238 static char *XactIsoLevel_string;
239 static char *data_directory;
240 static char *custom_variable_classes;
241 static char *xmlbinary_string;
242 static char *xmloption_string;
243 static int max_function_args;
244 static int max_index_keys;
245 static int max_identifier_length;
246 static int block_size;
247 static bool integer_datetimes;
249 /* should be static, but commands/variable.c needs to get at these */
251 char *session_authorization_string;
255 * Displayable names for context types (enum GucContext)
257 * Note: these strings are deliberately not localized.
259 const char *const GucContext_Names[] =
261 /* PGC_INTERNAL */ "internal",
262 /* PGC_POSTMASTER */ "postmaster",
263 /* PGC_SIGHUP */ "sighup",
264 /* PGC_BACKEND */ "backend",
265 /* PGC_SUSET */ "superuser",
266 /* PGC_USERSET */ "user"
270 * Displayable names for source types (enum GucSource)
272 * Note: these strings are deliberately not localized.
274 const char *const GucSource_Names[] =
276 /* PGC_S_DEFAULT */ "default",
277 /* PGC_S_ENV_VAR */ "environment variable",
278 /* PGC_S_FILE */ "configuration file",
279 /* PGC_S_ARGV */ "command line",
280 /* PGC_S_DATABASE */ "database",
281 /* PGC_S_USER */ "user",
282 /* PGC_S_CLIENT */ "client",
283 /* PGC_S_OVERRIDE */ "override",
284 /* PGC_S_INTERACTIVE */ "interactive",
285 /* PGC_S_TEST */ "test",
286 /* PGC_S_SESSION */ "session"
290 * Displayable names for the groupings defined in enum config_group
292 const char *const config_group_names[] =
295 gettext_noop("Ungrouped"),
297 gettext_noop("File Locations"),
299 gettext_noop("Connections and Authentication"),
300 /* CONN_AUTH_SETTINGS */
301 gettext_noop("Connections and Authentication / Connection Settings"),
302 /* CONN_AUTH_SECURITY */
303 gettext_noop("Connections and Authentication / Security and Authentication"),
305 gettext_noop("Resource Usage"),
307 gettext_noop("Resource Usage / Memory"),
309 gettext_noop("Resource Usage / Free Space Map"),
310 /* RESOURCES_KERNEL */
311 gettext_noop("Resource Usage / Kernel Resources"),
313 gettext_noop("Write-Ahead Log"),
315 gettext_noop("Write-Ahead Log / Settings"),
316 /* WAL_CHECKPOINTS */
317 gettext_noop("Write-Ahead Log / Checkpoints"),
319 gettext_noop("Query Tuning"),
320 /* QUERY_TUNING_METHOD */
321 gettext_noop("Query Tuning / Planner Method Configuration"),
322 /* QUERY_TUNING_COST */
323 gettext_noop("Query Tuning / Planner Cost Constants"),
324 /* QUERY_TUNING_GEQO */
325 gettext_noop("Query Tuning / Genetic Query Optimizer"),
326 /* QUERY_TUNING_OTHER */
327 gettext_noop("Query Tuning / Other Planner Options"),
329 gettext_noop("Reporting and Logging"),
331 gettext_noop("Reporting and Logging / Where to Log"),
333 gettext_noop("Reporting and Logging / When to Log"),
335 gettext_noop("Reporting and Logging / What to Log"),
337 gettext_noop("Statistics"),
338 /* STATS_MONITORING */
339 gettext_noop("Statistics / Monitoring"),
340 /* STATS_COLLECTOR */
341 gettext_noop("Statistics / Query and Index Statistics Collector"),
343 gettext_noop("Autovacuum"),
345 gettext_noop("Client Connection Defaults"),
346 /* CLIENT_CONN_STATEMENT */
347 gettext_noop("Client Connection Defaults / Statement Behavior"),
348 /* CLIENT_CONN_LOCALE */
349 gettext_noop("Client Connection Defaults / Locale and Formatting"),
350 /* CLIENT_CONN_OTHER */
351 gettext_noop("Client Connection Defaults / Other Defaults"),
352 /* LOCK_MANAGEMENT */
353 gettext_noop("Lock Management"),
355 gettext_noop("Version and Platform Compatibility"),
356 /* COMPAT_OPTIONS_PREVIOUS */
357 gettext_noop("Version and Platform Compatibility / Previous PostgreSQL Versions"),
358 /* COMPAT_OPTIONS_CLIENT */
359 gettext_noop("Version and Platform Compatibility / Other Platforms and Clients"),
361 gettext_noop("Preset Options"),
363 gettext_noop("Customized Options"),
364 /* DEVELOPER_OPTIONS */
365 gettext_noop("Developer Options"),
366 /* help_config wants this array to be null-terminated */
371 * Displayable names for GUC variable types (enum config_type)
373 * Note: these strings are deliberately not localized.
375 const char *const config_type_names[] =
377 /* PGC_BOOL */ "bool",
378 /* PGC_INT */ "integer",
379 /* PGC_REAL */ "real",
380 /* PGC_STRING */ "string"
385 * Contents of GUC tables
387 * See src/backend/utils/misc/README for design notes.
391 * 1. Declare a global variable of type bool, int, double, or char*
392 * and make use of it.
394 * 2. Decide at what times it's safe to set the option. See guc.h for
397 * 3. Decide on a name, a default value, upper and lower bounds (if
400 * 4. Add a record below.
402 * 5. Add it to src/backend/utils/misc/postgresql.conf.sample, if
405 * 6. Add it to src/bin/psql/tab-complete.c, if it's a USERSET option.
407 * 7. Don't forget to document the option.
409 * 8. If it's a new GUC_LIST option you must edit pg_dumpall.c to ensure
410 * it is not single quoted at dump time.
414 /******** option records follow ********/
416 static struct config_bool ConfigureNamesBool[] =
419 {"enable_seqscan", PGC_USERSET, QUERY_TUNING_METHOD,
420 gettext_noop("Enables the planner's use of sequential-scan plans."),
427 {"enable_indexscan", PGC_USERSET, QUERY_TUNING_METHOD,
428 gettext_noop("Enables the planner's use of index-scan plans."),
435 {"enable_bitmapscan", PGC_USERSET, QUERY_TUNING_METHOD,
436 gettext_noop("Enables the planner's use of bitmap-scan plans."),
443 {"enable_tidscan", PGC_USERSET, QUERY_TUNING_METHOD,
444 gettext_noop("Enables the planner's use of TID scan plans."),
451 {"enable_sort", PGC_USERSET, QUERY_TUNING_METHOD,
452 gettext_noop("Enables the planner's use of explicit sort steps."),
459 {"enable_hashagg", PGC_USERSET, QUERY_TUNING_METHOD,
460 gettext_noop("Enables the planner's use of hashed aggregation plans."),
467 {"enable_nestloop", PGC_USERSET, QUERY_TUNING_METHOD,
468 gettext_noop("Enables the planner's use of nested-loop join plans."),
475 {"enable_mergejoin", PGC_USERSET, QUERY_TUNING_METHOD,
476 gettext_noop("Enables the planner's use of merge join plans."),
483 {"enable_hashjoin", PGC_USERSET, QUERY_TUNING_METHOD,
484 gettext_noop("Enables the planner's use of hash join plans."),
491 {"constraint_exclusion", PGC_USERSET, QUERY_TUNING_OTHER,
492 gettext_noop("Enables the planner to use constraints to optimize queries."),
493 gettext_noop("Child table scans will be skipped if their "
494 "constraints guarantee that no rows match the query.")
496 &constraint_exclusion,
500 {"geqo", PGC_USERSET, QUERY_TUNING_GEQO,
501 gettext_noop("Enables genetic query optimization."),
502 gettext_noop("This algorithm attempts to do planning without "
503 "exhaustive searching.")
509 /* Not for general use --- used by SET SESSION AUTHORIZATION */
510 {"is_superuser", PGC_INTERNAL, UNGROUPED,
511 gettext_noop("Shows whether the current user is a superuser."),
513 GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
515 &session_auth_is_superuser,
519 {"ssl", PGC_POSTMASTER, CONN_AUTH_SECURITY,
520 gettext_noop("Enables SSL connections."),
524 false, assign_ssl, NULL
527 {"fsync", PGC_SIGHUP, WAL_SETTINGS,
528 gettext_noop("Forces synchronization of updates to disk."),
529 gettext_noop("The server will use the fsync() system call in several places to make "
530 "sure that updates are physically written to disk. This insures "
531 "that a database cluster will recover to a consistent state after "
532 "an operating system or hardware crash.")
538 {"zero_damaged_pages", PGC_SUSET, DEVELOPER_OPTIONS,
539 gettext_noop("Continues processing past damaged page headers."),
540 gettext_noop("Detection of a damaged page header normally causes PostgreSQL to "
541 "report an error, aborting the current transaction. Setting "
542 "zero_damaged_pages to true causes the system to instead report a "
543 "warning, zero out the damaged page, and continue processing. This "
544 "behavior will destroy data, namely all the rows on the damaged page."),
551 {"full_page_writes", PGC_SIGHUP, WAL_SETTINGS,
552 gettext_noop("Writes full pages to WAL when first modified after a checkpoint."),
553 gettext_noop("A page write in process during an operating system crash might be "
554 "only partially written to disk. During recovery, the row changes "
555 "stored in WAL are not enough to recover. This option writes "
556 "pages when first modified after a checkpoint to WAL so full recovery "
563 {"silent_mode", PGC_POSTMASTER, LOGGING_WHEN,
564 gettext_noop("Runs the server silently."),
565 gettext_noop("If this parameter is set, the server will automatically run in the "
566 "background and any controlling terminals are dissociated.")
572 {"log_connections", PGC_BACKEND, LOGGING_WHAT,
573 gettext_noop("Logs each successful connection."),
580 {"log_disconnections", PGC_BACKEND, LOGGING_WHAT,
581 gettext_noop("Logs end of a session, including duration."),
588 {"debug_assertions", PGC_USERSET, DEVELOPER_OPTIONS,
589 gettext_noop("Turns on various assertion checks."),
590 gettext_noop("This is a debugging aid."),
594 #ifdef USE_ASSERT_CHECKING
599 assign_debug_assertions, NULL
602 /* currently undocumented, so don't show in SHOW ALL */
603 {"exit_on_error", PGC_USERSET, UNGROUPED,
604 gettext_noop("No description available."),
606 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
612 {"log_duration", PGC_SUSET, LOGGING_WHAT,
613 gettext_noop("Logs the duration of each completed SQL statement."),
620 {"debug_print_parse", PGC_USERSET, LOGGING_WHAT,
621 gettext_noop("Prints the parse tree to the server log."),
628 {"debug_print_rewritten", PGC_USERSET, LOGGING_WHAT,
629 gettext_noop("Prints the parse tree after rewriting to server log."),
632 &Debug_print_rewritten,
636 {"debug_print_plan", PGC_USERSET, LOGGING_WHAT,
637 gettext_noop("Prints the execution plan to server log."),
644 {"debug_pretty_print", PGC_USERSET, LOGGING_WHAT,
645 gettext_noop("Indents parse and plan tree displays."),
652 {"log_parser_stats", PGC_SUSET, STATS_MONITORING,
653 gettext_noop("Writes parser performance statistics to the server log."),
657 false, assign_stage_log_stats, NULL
660 {"log_planner_stats", PGC_SUSET, STATS_MONITORING,
661 gettext_noop("Writes planner performance statistics to the server log."),
665 false, assign_stage_log_stats, NULL
668 {"log_executor_stats", PGC_SUSET, STATS_MONITORING,
669 gettext_noop("Writes executor performance statistics to the server log."),
673 false, assign_stage_log_stats, NULL
676 {"log_statement_stats", PGC_SUSET, STATS_MONITORING,
677 gettext_noop("Writes cumulative performance statistics to the server log."),
680 &log_statement_stats,
681 false, assign_log_stats, NULL
683 #ifdef BTREE_BUILD_STATS
685 {"log_btree_build_stats", PGC_SUSET, DEVELOPER_OPTIONS,
686 gettext_noop("No description available."),
690 &log_btree_build_stats,
696 {"explain_pretty_print", PGC_USERSET, CLIENT_CONN_OTHER,
697 gettext_noop("Uses the indented output format for EXPLAIN VERBOSE."),
700 &Explain_pretty_print,
704 {"stats_start_collector", PGC_POSTMASTER, STATS_COLLECTOR,
705 gettext_noop("Starts the server statistics-collection subprocess."),
708 &pgstat_collect_startcollector,
712 {"stats_reset_on_server_start", PGC_POSTMASTER, STATS_COLLECTOR,
713 gettext_noop("Zeroes collected statistics on server restart."),
716 &pgstat_collect_resetonpmstart,
720 {"stats_row_level", PGC_SUSET, STATS_COLLECTOR,
721 gettext_noop("Collects row-level statistics on database activity."),
724 &pgstat_collect_tuplelevel,
728 {"stats_block_level", PGC_SUSET, STATS_COLLECTOR,
729 gettext_noop("Collects block-level statistics on database activity."),
732 &pgstat_collect_blocklevel,
737 {"stats_command_string", PGC_SUSET, STATS_COLLECTOR,
738 gettext_noop("Collects information about executing commands."),
739 gettext_noop("Enables the collection of information on the currently "
740 "executing command of each session, along with the time "
741 "at which that command began execution.")
743 &pgstat_collect_querystring,
748 {"update_process_title", PGC_SUSET, STATS_COLLECTOR,
749 gettext_noop("Updates the process title to show the active SQL command."),
750 gettext_noop("Enables updating of the process title every time a new SQL command is received by the server.")
752 &update_process_title,
757 {"autovacuum", PGC_SIGHUP, AUTOVACUUM,
758 gettext_noop("Starts the autovacuum subprocess."),
761 &autovacuum_start_daemon,
766 {"trace_notify", PGC_USERSET, DEVELOPER_OPTIONS,
767 gettext_noop("Generates debugging output for LISTEN and NOTIFY."),
777 {"trace_locks", PGC_SUSET, DEVELOPER_OPTIONS,
778 gettext_noop("No description available."),
786 {"trace_userlocks", PGC_SUSET, DEVELOPER_OPTIONS,
787 gettext_noop("No description available."),
795 {"trace_lwlocks", PGC_SUSET, DEVELOPER_OPTIONS,
796 gettext_noop("No description available."),
804 {"debug_deadlocks", PGC_SUSET, DEVELOPER_OPTIONS,
805 gettext_noop("No description available."),
815 {"log_hostname", PGC_SIGHUP, LOGGING_WHAT,
816 gettext_noop("Logs the host name in the connection logs."),
817 gettext_noop("By default, connection logs only show the IP address "
818 "of the connecting host. If you want them to show the host name you "
819 "can turn this on, but depending on your host name resolution "
820 "setup it might impose a non-negligible performance penalty.")
826 {"sql_inheritance", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
827 gettext_noop("Causes subtables to be included by default in various commands."),
834 {"password_encryption", PGC_USERSET, CONN_AUTH_SECURITY,
835 gettext_noop("Encrypt passwords."),
836 gettext_noop("When a password is specified in CREATE USER or "
837 "ALTER USER without writing either ENCRYPTED or UNENCRYPTED, "
838 "this parameter determines whether the password is to be encrypted.")
840 &Password_encryption,
844 {"transform_null_equals", PGC_USERSET, COMPAT_OPTIONS_CLIENT,
845 gettext_noop("Treats \"expr=NULL\" as \"expr IS NULL\"."),
846 gettext_noop("When turned on, expressions of the form expr = NULL "
847 "(or NULL = expr) are treated as expr IS NULL, that is, they "
848 "return true if expr evaluates to the null value, and false "
849 "otherwise. The correct behavior of expr = NULL is to always "
850 "return null (unknown).")
852 &Transform_null_equals,
856 {"db_user_namespace", PGC_SIGHUP, CONN_AUTH_SECURITY,
857 gettext_noop("Enables per-database user names."),
864 /* only here for backwards compatibility */
865 {"autocommit", PGC_USERSET, CLIENT_CONN_STATEMENT,
866 gettext_noop("This parameter doesn't do anything."),
867 gettext_noop("It's just here so that we won't choke on SET AUTOCOMMIT TO ON from 7.3-vintage clients."),
868 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
871 true, assign_phony_autocommit, NULL
874 {"default_transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
875 gettext_noop("Sets the default read-only status of new transactions."),
878 &DefaultXactReadOnly,
882 {"transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
883 gettext_noop("Sets the current transaction's read-only status."),
885 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
888 false, assign_transaction_read_only, NULL
891 {"add_missing_from", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
892 gettext_noop("Automatically adds missing table references to FROM clauses."),
899 {"check_function_bodies", PGC_USERSET, CLIENT_CONN_STATEMENT,
900 gettext_noop("Check function bodies during CREATE FUNCTION."),
903 &check_function_bodies,
907 {"array_nulls", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
908 gettext_noop("Enable input of NULL elements in arrays."),
909 gettext_noop("When turned on, unquoted NULL in an array input "
910 "value means a null value; "
911 "otherwise it is taken literally.")
917 {"default_with_oids", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
918 gettext_noop("Create new tables with OIDs by default."),
925 {"redirect_stderr", PGC_POSTMASTER, LOGGING_WHERE,
926 gettext_noop("Start a subprocess to capture stderr output into log files."),
933 {"log_truncate_on_rotation", PGC_SIGHUP, LOGGING_WHERE,
934 gettext_noop("Truncate existing log files of same name during log rotation."),
937 &Log_truncate_on_rotation,
943 {"trace_sort", PGC_USERSET, DEVELOPER_OPTIONS,
944 gettext_noop("Emit information about resource usage in sorting."),
955 {"wal_debug", PGC_SUSET, DEVELOPER_OPTIONS,
956 gettext_noop("Emit WAL-related debugging output."),
966 {"integer_datetimes", PGC_INTERNAL, PRESET_OPTIONS,
967 gettext_noop("Datetimes are integer based."),
969 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
972 #ifdef HAVE_INT64_TIMESTAMP
980 {"krb_caseins_users", PGC_POSTMASTER, CONN_AUTH_SECURITY,
981 gettext_noop("Sets whether Kerberos user names should be treated as case-insensitive."),
984 &pg_krb_caseins_users,
989 {"escape_string_warning", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
990 gettext_noop("Warn about backslash escapes in ordinary string literals."),
993 &escape_string_warning,
998 {"standard_conforming_strings", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
999 gettext_noop("Causes '...' strings to treat backslashes literally."),
1003 &standard_conforming_strings,
1008 {"allow_system_table_mods", PGC_POSTMASTER, DEVELOPER_OPTIONS,
1009 gettext_noop("Allows modifications of the structure of system tables."),
1013 &allowSystemTableMods,
1018 {"ignore_system_indexes", PGC_BACKEND, DEVELOPER_OPTIONS,
1019 gettext_noop("Disables reading from system indexes."),
1020 gettext_noop("It does not prevent updating the indexes, so it is safe "
1021 "to use. The worst consequence is slowness."),
1024 &IgnoreSystemIndexes,
1028 /* End-of-list marker */
1030 {NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL
1035 static struct config_int ConfigureNamesInt[] =
1038 {"archive_timeout", PGC_SIGHUP, WAL_SETTINGS,
1039 gettext_noop("Forces a switch to the next xlog file if a "
1040 "new file has not been started within N seconds."),
1044 &XLogArchiveTimeout,
1045 0, 0, INT_MAX, NULL, NULL
1048 {"post_auth_delay", PGC_BACKEND, DEVELOPER_OPTIONS,
1049 gettext_noop("Waits N seconds on connection startup after authentication."),
1050 gettext_noop("This allows attaching a debugger to the process."),
1051 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1054 0, 0, INT_MAX, NULL, NULL
1057 {"default_statistics_target", PGC_USERSET, QUERY_TUNING_OTHER,
1058 gettext_noop("Sets the default statistics target."),
1059 gettext_noop("This applies to table columns that have not had a "
1060 "column-specific target set via ALTER TABLE SET STATISTICS.")
1062 &default_statistics_target,
1063 10, 1, 1000, NULL, NULL
1066 {"from_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1067 gettext_noop("Sets the FROM-list size beyond which subqueries "
1068 "are not collapsed."),
1069 gettext_noop("The planner will merge subqueries into upper "
1070 "queries if the resulting FROM list would have no more than "
1073 &from_collapse_limit,
1074 8, 1, INT_MAX, NULL, NULL
1077 {"join_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1078 gettext_noop("Sets the FROM-list size beyond which JOIN "
1079 "constructs are not flattened."),
1080 gettext_noop("The planner will flatten explicit JOIN "
1081 "constructs into lists of FROM items whenever a "
1082 "list of no more than this many items would result.")
1084 &join_collapse_limit,
1085 8, 1, INT_MAX, NULL, NULL
1088 {"geqo_threshold", PGC_USERSET, QUERY_TUNING_GEQO,
1089 gettext_noop("Sets the threshold of FROM items beyond which GEQO is used."),
1093 12, 2, INT_MAX, NULL, NULL
1096 {"geqo_effort", PGC_USERSET, QUERY_TUNING_GEQO,
1097 gettext_noop("GEQO: effort is used to set the default for other GEQO parameters."),
1101 DEFAULT_GEQO_EFFORT, MIN_GEQO_EFFORT, MAX_GEQO_EFFORT, NULL, NULL
1104 {"geqo_pool_size", PGC_USERSET, QUERY_TUNING_GEQO,
1105 gettext_noop("GEQO: number of individuals in the population."),
1106 gettext_noop("Zero selects a suitable default value.")
1109 0, 0, INT_MAX, NULL, NULL
1112 {"geqo_generations", PGC_USERSET, QUERY_TUNING_GEQO,
1113 gettext_noop("GEQO: number of iterations of the algorithm."),
1114 gettext_noop("Zero selects a suitable default value.")
1117 0, 0, INT_MAX, NULL, NULL
1121 {"deadlock_timeout", PGC_SIGHUP, LOCK_MANAGEMENT,
1122 gettext_noop("Sets the time to wait on a lock before checking for deadlock."),
1127 1000, 0, INT_MAX, NULL, NULL
1131 * Note: There is some postprocessing done in PostmasterMain() to make
1132 * sure the buffers are at least twice the number of backends, so the
1133 * constraints here are partially unused. Similarly, the superuser
1134 * reserved number is checked to ensure it is less than the max backends
1137 * MaxBackends is limited to INT_MAX/4 because some places compute
1138 * 4*MaxBackends without any overflow check. Likewise we have to limit
1139 * NBuffers to INT_MAX/2.
1142 {"max_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1143 gettext_noop("Sets the maximum number of concurrent connections."),
1147 100, 1, INT_MAX / 4, NULL, NULL
1151 {"superuser_reserved_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1152 gettext_noop("Sets the number of connection slots reserved for superusers."),
1156 3, 0, INT_MAX / 4, NULL, NULL
1160 {"shared_buffers", PGC_POSTMASTER, RESOURCES_MEM,
1161 gettext_noop("Sets the number of shared memory buffers used by the server."),
1166 1024, 16, INT_MAX / 2, NULL, NULL
1170 {"temp_buffers", PGC_USERSET, RESOURCES_MEM,
1171 gettext_noop("Sets the maximum number of temporary buffers used by each session."),
1176 1024, 100, INT_MAX / 2, NULL, show_num_temp_buffers
1180 {"port", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1181 gettext_noop("Sets the TCP port the server listens on."),
1185 DEF_PGPORT, 1, 65535, NULL, NULL
1189 {"unix_socket_permissions", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1190 gettext_noop("Sets the access permissions of the Unix-domain socket."),
1191 gettext_noop("Unix-domain sockets use the usual Unix file system "
1192 "permission set. The parameter value is expected to be an numeric mode "
1193 "specification in the form accepted by the chmod and umask system "
1194 "calls. (To use the customary octal format the number must start with "
1197 &Unix_socket_permissions,
1198 0777, 0000, 0777, NULL, NULL
1202 {"work_mem", PGC_USERSET, RESOURCES_MEM,
1203 gettext_noop("Sets the maximum memory to be used for query workspaces."),
1204 gettext_noop("This much memory can be used by each internal "
1205 "sort operation and hash table before switching to "
1206 "temporary disk files."),
1210 1024, 8 * BLCKSZ / 1024, MAX_KILOBYTES, NULL, NULL
1214 {"maintenance_work_mem", PGC_USERSET, RESOURCES_MEM,
1215 gettext_noop("Sets the maximum memory to be used for maintenance operations."),
1216 gettext_noop("This includes operations such as VACUUM and CREATE INDEX."),
1219 &maintenance_work_mem,
1220 16384, 1024, MAX_KILOBYTES, NULL, NULL
1224 {"max_stack_depth", PGC_SUSET, RESOURCES_MEM,
1225 gettext_noop("Sets the maximum stack depth, in kilobytes."),
1230 100, 100, MAX_KILOBYTES, assign_max_stack_depth, NULL
1234 {"vacuum_cost_page_hit", PGC_USERSET, RESOURCES,
1235 gettext_noop("Vacuum cost for a page found in the buffer cache."),
1239 1, 0, 10000, NULL, NULL
1243 {"vacuum_cost_page_miss", PGC_USERSET, RESOURCES,
1244 gettext_noop("Vacuum cost for a page not found in the buffer cache."),
1247 &VacuumCostPageMiss,
1248 10, 0, 10000, NULL, NULL
1252 {"vacuum_cost_page_dirty", PGC_USERSET, RESOURCES,
1253 gettext_noop("Vacuum cost for a page dirtied by vacuum."),
1256 &VacuumCostPageDirty,
1257 20, 0, 10000, NULL, NULL
1261 {"vacuum_cost_limit", PGC_USERSET, RESOURCES,
1262 gettext_noop("Vacuum cost amount available before napping."),
1266 200, 1, 10000, NULL, NULL
1270 {"vacuum_cost_delay", PGC_USERSET, RESOURCES,
1271 gettext_noop("Vacuum cost delay in milliseconds."),
1276 0, 0, 1000, NULL, NULL
1280 {"autovacuum_vacuum_cost_delay", PGC_SIGHUP, AUTOVACUUM,
1281 gettext_noop("Vacuum cost delay in milliseconds, for autovacuum."),
1285 &autovacuum_vac_cost_delay,
1286 -1, -1, 1000, NULL, NULL
1290 {"autovacuum_vacuum_cost_limit", PGC_SIGHUP, AUTOVACUUM,
1291 gettext_noop("Vacuum cost amount available before napping, for autovacuum."),
1294 &autovacuum_vac_cost_limit,
1295 -1, -1, 10000, NULL, NULL
1299 {"max_files_per_process", PGC_POSTMASTER, RESOURCES_KERNEL,
1300 gettext_noop("Sets the maximum number of simultaneously open files for each server process."),
1303 &max_files_per_process,
1304 1000, 25, INT_MAX, NULL, NULL
1308 {"max_prepared_transactions", PGC_POSTMASTER, RESOURCES,
1309 gettext_noop("Sets the maximum number of simultaneously prepared transactions."),
1312 &max_prepared_xacts,
1313 5, 0, INT_MAX, NULL, NULL
1318 {"trace_lock_oidmin", PGC_SUSET, DEVELOPER_OPTIONS,
1319 gettext_noop("No description available."),
1324 FirstNormalObjectId, 0, INT_MAX, NULL, NULL
1327 {"trace_lock_table", PGC_SUSET, DEVELOPER_OPTIONS,
1328 gettext_noop("No description available."),
1333 0, 0, INT_MAX, NULL, NULL
1338 {"statement_timeout", PGC_USERSET, CLIENT_CONN_STATEMENT,
1339 gettext_noop("Sets the maximum allowed duration of any statement."),
1340 gettext_noop("A value of 0 turns off the timeout."),
1344 0, 0, INT_MAX, NULL, NULL
1348 {"vacuum_freeze_min_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1349 gettext_noop("Minimum age at which VACUUM should freeze a table row."),
1352 &vacuum_freeze_min_age,
1353 100000000, 0, 1000000000, NULL, NULL
1357 {"max_fsm_relations", PGC_POSTMASTER, RESOURCES_FSM,
1358 gettext_noop("Sets the maximum number of tables and indexes for which free space is tracked."),
1362 1000, 100, INT_MAX, NULL, NULL
1365 {"max_fsm_pages", PGC_POSTMASTER, RESOURCES_FSM,
1366 gettext_noop("Sets the maximum number of disk pages for which free space is tracked."),
1370 20000, 1000, INT_MAX, NULL, NULL
1374 {"max_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
1375 gettext_noop("Sets the maximum number of locks per transaction."),
1376 gettext_noop("The shared lock table is sized on the assumption that "
1377 "at most max_locks_per_transaction * max_connections distinct "
1378 "objects will need to be locked at any one time.")
1380 &max_locks_per_xact,
1381 64, 10, INT_MAX, NULL, NULL
1385 {"authentication_timeout", PGC_SIGHUP, CONN_AUTH_SECURITY,
1386 gettext_noop("Sets the maximum allowed time to complete client authentication."),
1390 &AuthenticationTimeout,
1391 60, 1, 600, NULL, NULL
1395 /* Not for general use */
1396 {"pre_auth_delay", PGC_SIGHUP, DEVELOPER_OPTIONS,
1397 gettext_noop("Waits N seconds on connection startup before authentication."),
1398 gettext_noop("This allows attaching a debugger to the process."),
1399 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1402 0, 0, 60, NULL, NULL
1406 {"checkpoint_segments", PGC_SIGHUP, WAL_CHECKPOINTS,
1407 gettext_noop("Sets the maximum distance in log segments between automatic WAL checkpoints."),
1410 &CheckPointSegments,
1411 3, 1, INT_MAX, NULL, NULL
1415 {"checkpoint_timeout", PGC_SIGHUP, WAL_CHECKPOINTS,
1416 gettext_noop("Sets the maximum time between automatic WAL checkpoints."),
1421 300, 30, 3600, NULL, NULL
1425 {"checkpoint_warning", PGC_SIGHUP, WAL_CHECKPOINTS,
1426 gettext_noop("Enables warnings if checkpoint segments are filled more "
1427 "frequently than this."),
1428 gettext_noop("Write a message to the server log if checkpoints "
1429 "caused by the filling of checkpoint segment files happens more "
1430 "frequently than this number of seconds. Zero turns off the warning."),
1434 30, 0, INT_MAX, NULL, NULL
1438 {"wal_buffers", PGC_POSTMASTER, WAL_SETTINGS,
1439 gettext_noop("Sets the number of disk-page buffers in shared memory for WAL."),
1444 8, 4, INT_MAX, NULL, NULL
1448 {"commit_delay", PGC_USERSET, WAL_CHECKPOINTS,
1449 gettext_noop("Sets the delay in microseconds between transaction commit and "
1450 "flushing WAL to disk."),
1454 0, 0, 100000, NULL, NULL
1458 {"commit_siblings", PGC_USERSET, WAL_CHECKPOINTS,
1459 gettext_noop("Sets the minimum concurrent open transactions before performing "
1464 5, 1, 1000, NULL, NULL
1468 {"extra_float_digits", PGC_USERSET, CLIENT_CONN_LOCALE,
1469 gettext_noop("Sets the number of digits displayed for floating-point values."),
1470 gettext_noop("This affects real, double precision, and geometric data types. "
1471 "The parameter value is added to the standard number of digits "
1472 "(FLT_DIG or DBL_DIG as appropriate).")
1474 &extra_float_digits,
1475 0, -15, 2, NULL, NULL
1479 {"log_min_duration_statement", PGC_SUSET, LOGGING_WHEN,
1480 gettext_noop("Sets the minimum execution time above which statements will "
1482 gettext_noop("Zero prints all queries. The default is -1 (turning this feature off)."),
1485 &log_min_duration_statement,
1486 -1, -1, INT_MAX / 1000, NULL, NULL
1490 {"bgwriter_delay", PGC_SIGHUP, RESOURCES,
1491 gettext_noop("Background writer sleep time between rounds."),
1496 200, 10, 10000, NULL, NULL
1500 {"bgwriter_lru_maxpages", PGC_SIGHUP, RESOURCES,
1501 gettext_noop("Background writer maximum number of LRU pages to flush per round."),
1504 &bgwriter_lru_maxpages,
1505 5, 0, 1000, NULL, NULL
1509 {"bgwriter_all_maxpages", PGC_SIGHUP, RESOURCES,
1510 gettext_noop("Background writer maximum number of all pages to flush per round."),
1513 &bgwriter_all_maxpages,
1514 5, 0, 1000, NULL, NULL
1518 {"log_rotation_age", PGC_SIGHUP, LOGGING_WHERE,
1519 gettext_noop("Automatic log file rotation will occur after N minutes."),
1524 HOURS_PER_DAY * MINS_PER_HOUR, 0, INT_MAX / MINS_PER_HOUR, NULL, NULL
1528 {"log_rotation_size", PGC_SIGHUP, LOGGING_WHERE,
1529 gettext_noop("Automatic log file rotation will occur after N kilobytes."),
1534 10 * 1024, 0, INT_MAX / 1024, NULL, NULL
1538 {"max_function_args", PGC_INTERNAL, PRESET_OPTIONS,
1539 gettext_noop("Shows the maximum number of function arguments."),
1541 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1544 FUNC_MAX_ARGS, FUNC_MAX_ARGS, FUNC_MAX_ARGS, NULL, NULL
1548 {"max_index_keys", PGC_INTERNAL, PRESET_OPTIONS,
1549 gettext_noop("Shows the maximum number of index keys."),
1551 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1554 INDEX_MAX_KEYS, INDEX_MAX_KEYS, INDEX_MAX_KEYS, NULL, NULL
1558 {"max_identifier_length", PGC_INTERNAL, PRESET_OPTIONS,
1559 gettext_noop("Shows the maximum identifier length."),
1561 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1563 &max_identifier_length,
1564 NAMEDATALEN - 1, NAMEDATALEN - 1, NAMEDATALEN - 1, NULL, NULL
1568 {"block_size", PGC_INTERNAL, PRESET_OPTIONS,
1569 gettext_noop("Shows the size of a disk block."),
1571 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1574 BLCKSZ, BLCKSZ, BLCKSZ, NULL, NULL
1578 {"autovacuum_naptime", PGC_SIGHUP, AUTOVACUUM,
1579 gettext_noop("Time to sleep between autovacuum runs."),
1583 &autovacuum_naptime,
1584 60, 1, INT_MAX, NULL, NULL
1587 {"autovacuum_vacuum_threshold", PGC_SIGHUP, AUTOVACUUM,
1588 gettext_noop("Minimum number of tuple updates or deletes prior to vacuum."),
1591 &autovacuum_vac_thresh,
1592 500, 0, INT_MAX, NULL, NULL
1595 {"autovacuum_analyze_threshold", PGC_SIGHUP, AUTOVACUUM,
1596 gettext_noop("Minimum number of tuple inserts, updates or deletes prior to analyze."),
1599 &autovacuum_anl_thresh,
1600 250, 0, INT_MAX, NULL, NULL
1603 /* see varsup.c for why this is PGC_POSTMASTER not PGC_SIGHUP */
1604 {"autovacuum_freeze_max_age", PGC_POSTMASTER, AUTOVACUUM,
1605 gettext_noop("Age at which to autovacuum a table to prevent transaction ID wraparound."),
1608 &autovacuum_freeze_max_age,
1609 200000000, 100000000, 2000000000, NULL, NULL
1613 {"tcp_keepalives_idle", PGC_USERSET, CLIENT_CONN_OTHER,
1614 gettext_noop("Time between issuing TCP keepalives."),
1615 gettext_noop("A value of 0 uses the system default."),
1618 &tcp_keepalives_idle,
1619 0, 0, INT_MAX, assign_tcp_keepalives_idle, show_tcp_keepalives_idle
1623 {"tcp_keepalives_interval", PGC_USERSET, CLIENT_CONN_OTHER,
1624 gettext_noop("Time between TCP keepalive retransmits."),
1625 gettext_noop("A value of 0 uses the system default."),
1628 &tcp_keepalives_interval,
1629 0, 0, INT_MAX, assign_tcp_keepalives_interval, show_tcp_keepalives_interval
1633 {"tcp_keepalives_count", PGC_USERSET, CLIENT_CONN_OTHER,
1634 gettext_noop("Maximum number of TCP keepalive retransmits."),
1635 gettext_noop("This controls the number of consecutive keepalive retransmits that can be "
1636 "lost before a connection is considered dead. A value of 0 uses the "
1639 &tcp_keepalives_count,
1640 0, 0, INT_MAX, assign_tcp_keepalives_count, show_tcp_keepalives_count
1644 {"gin_fuzzy_search_limit", PGC_USERSET, CLIENT_CONN_OTHER,
1645 gettext_noop("Sets the maximum allowed result for exact search by GIN."),
1649 &GinFuzzySearchLimit,
1650 0, 0, INT_MAX, NULL, NULL
1654 {"effective_cache_size", PGC_USERSET, QUERY_TUNING_COST,
1655 gettext_noop("Sets the planner's assumption about the size of the disk cache."),
1656 gettext_noop("That is, the portion of the kernel's disk cache that "
1657 "will be used for PostgreSQL data files. This is measured in disk "
1658 "pages, which are normally 8 kB each."),
1661 &effective_cache_size,
1662 DEFAULT_EFFECTIVE_CACHE_SIZE, 1, INT_MAX, NULL, NULL
1666 /* Can't be set in postgresql.conf */
1667 {"server_version_num", PGC_INTERNAL, PRESET_OPTIONS,
1668 gettext_noop("Shows the server version as an integer."),
1670 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1672 &server_version_num,
1673 PG_VERSION_NUM, PG_VERSION_NUM, PG_VERSION_NUM, NULL, NULL
1677 {"log_temp_files", PGC_USERSET, LOGGING_WHAT,
1678 gettext_noop("Log the use of temporary files larger than this number of kilobytes."),
1679 gettext_noop("Zero logs all files. The default is -1 (turning this feature off)."),
1683 -1, -1, INT_MAX, NULL, NULL
1686 /* End-of-list marker */
1688 {NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL
1693 static struct config_real ConfigureNamesReal[] =
1696 {"seq_page_cost", PGC_USERSET, QUERY_TUNING_COST,
1697 gettext_noop("Sets the planner's estimate of the cost of a "
1698 "sequentially fetched disk page."),
1702 DEFAULT_SEQ_PAGE_COST, 0, DBL_MAX, NULL, NULL
1705 {"random_page_cost", PGC_USERSET, QUERY_TUNING_COST,
1706 gettext_noop("Sets the planner's estimate of the cost of a "
1707 "nonsequentially fetched disk page."),
1711 DEFAULT_RANDOM_PAGE_COST, 0, DBL_MAX, NULL, NULL
1714 {"cpu_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
1715 gettext_noop("Sets the planner's estimate of the cost of "
1716 "processing each tuple (row)."),
1720 DEFAULT_CPU_TUPLE_COST, 0, DBL_MAX, NULL, NULL
1723 {"cpu_index_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
1724 gettext_noop("Sets the planner's estimate of the cost of "
1725 "processing each index entry during an index scan."),
1728 &cpu_index_tuple_cost,
1729 DEFAULT_CPU_INDEX_TUPLE_COST, 0, DBL_MAX, NULL, NULL
1732 {"cpu_operator_cost", PGC_USERSET, QUERY_TUNING_COST,
1733 gettext_noop("Sets the planner's estimate of the cost of "
1734 "processing each operator or function call."),
1738 DEFAULT_CPU_OPERATOR_COST, 0, DBL_MAX, NULL, NULL
1742 {"geqo_selection_bias", PGC_USERSET, QUERY_TUNING_GEQO,
1743 gettext_noop("GEQO: selective pressure within the population."),
1746 &Geqo_selection_bias,
1747 DEFAULT_GEQO_SELECTION_BIAS, MIN_GEQO_SELECTION_BIAS,
1748 MAX_GEQO_SELECTION_BIAS, NULL, NULL
1752 {"bgwriter_lru_percent", PGC_SIGHUP, RESOURCES,
1753 gettext_noop("Background writer percentage of LRU buffers to flush per round."),
1756 &bgwriter_lru_percent,
1757 1.0, 0.0, 100.0, NULL, NULL
1761 {"bgwriter_all_percent", PGC_SIGHUP, RESOURCES,
1762 gettext_noop("Background writer percentage of all buffers to flush per round."),
1765 &bgwriter_all_percent,
1766 0.333, 0.0, 100.0, NULL, NULL
1770 {"seed", PGC_USERSET, UNGROUPED,
1771 gettext_noop("Sets the seed for random-number generation."),
1773 GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1776 0.5, 0.0, 1.0, assign_random_seed, show_random_seed
1780 {"autovacuum_vacuum_scale_factor", PGC_SIGHUP, AUTOVACUUM,
1781 gettext_noop("Number of tuple updates or deletes prior to vacuum as a fraction of reltuples."),
1784 &autovacuum_vac_scale,
1785 0.2, 0.0, 100.0, NULL, NULL
1788 {"autovacuum_analyze_scale_factor", PGC_SIGHUP, AUTOVACUUM,
1789 gettext_noop("Number of tuple inserts, updates or deletes prior to analyze as a fraction of reltuples."),
1792 &autovacuum_anl_scale,
1793 0.1, 0.0, 100.0, NULL, NULL
1796 /* End-of-list marker */
1798 {NULL, 0, 0, NULL, NULL}, NULL, 0.0, 0.0, 0.0, NULL, NULL
1803 static struct config_string ConfigureNamesString[] =
1806 {"archive_command", PGC_SIGHUP, WAL_SETTINGS,
1807 gettext_noop("Sets the shell command that will be called to archive a WAL file."),
1810 &XLogArchiveCommand,
1815 {"backslash_quote", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1816 gettext_noop("Sets whether \"\\'\" is allowed in string literals."),
1817 gettext_noop("Valid values are ON, OFF, and SAFE_ENCODING.")
1819 &backslash_quote_string,
1820 "safe_encoding", assign_backslash_quote, NULL
1824 {"client_encoding", PGC_USERSET, CLIENT_CONN_LOCALE,
1825 gettext_noop("Sets the client's character set encoding."),
1827 GUC_IS_NAME | GUC_REPORT
1829 &client_encoding_string,
1830 "SQL_ASCII", assign_client_encoding, NULL
1834 {"client_min_messages", PGC_USERSET, LOGGING_WHEN,
1835 gettext_noop("Sets the message levels that are sent to the client."),
1836 gettext_noop("Valid values are DEBUG5, DEBUG4, DEBUG3, DEBUG2, "
1837 "DEBUG1, LOG, NOTICE, WARNING, and ERROR. Each level includes all the "
1838 "levels that follow it. The later the level, the fewer messages are "
1841 &client_min_messages_str,
1842 "notice", assign_client_min_messages, NULL
1846 {"log_min_messages", PGC_SUSET, LOGGING_WHEN,
1847 gettext_noop("Sets the message levels that are logged."),
1848 gettext_noop("Valid values are DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1, "
1849 "INFO, NOTICE, WARNING, ERROR, LOG, FATAL, and PANIC. Each level "
1850 "includes all the levels that follow it.")
1852 &log_min_messages_str,
1853 "notice", assign_log_min_messages, NULL
1857 {"log_error_verbosity", PGC_SUSET, LOGGING_WHEN,
1858 gettext_noop("Sets the verbosity of logged messages."),
1859 gettext_noop("Valid values are \"terse\", \"default\", and \"verbose\".")
1861 &log_error_verbosity_str,
1862 "default", assign_log_error_verbosity, NULL
1865 {"log_statement", PGC_SUSET, LOGGING_WHAT,
1866 gettext_noop("Sets the type of statements logged."),
1867 gettext_noop("Valid values are \"none\", \"ddl\", \"mod\", and \"all\".")
1870 "none", assign_log_statement, NULL
1874 {"log_min_error_statement", PGC_SUSET, LOGGING_WHEN,
1875 gettext_noop("Causes all statements generating error at or above this level to be logged."),
1876 gettext_noop("All SQL statements that cause an error of the "
1877 "specified level or a higher level are logged.")
1879 &log_min_error_statement_str,
1880 "error", assign_min_error_statement, NULL
1884 {"log_line_prefix", PGC_SIGHUP, LOGGING_WHAT,
1885 gettext_noop("Controls information prefixed to each log line."),
1886 gettext_noop("If blank, no prefix is used.")
1894 {"DateStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
1895 gettext_noop("Sets the display format for date and time values."),
1896 gettext_noop("Also controls interpretation of ambiguous "
1898 GUC_LIST_INPUT | GUC_REPORT
1901 "ISO, MDY", assign_datestyle, NULL
1905 {"default_tablespace", PGC_USERSET, CLIENT_CONN_STATEMENT,
1906 gettext_noop("Sets the default tablespace to create tables and indexes in."),
1907 gettext_noop("An empty string selects the database's default tablespace."),
1910 &default_tablespace,
1911 "", assign_default_tablespace, NULL
1915 {"default_transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
1916 gettext_noop("Sets the transaction isolation level of each new transaction."),
1917 gettext_noop("Each SQL transaction has an isolation level, which "
1918 "can be either \"read uncommitted\", \"read committed\", \"repeatable read\", or \"serializable\".")
1920 &default_iso_level_string,
1921 "read committed", assign_defaultxactisolevel, NULL
1925 {"dynamic_library_path", PGC_SUSET, CLIENT_CONN_OTHER,
1926 gettext_noop("Sets the path for dynamically loadable modules."),
1927 gettext_noop("If a dynamically loadable module needs to be opened and "
1928 "the specified name does not have a directory component (i.e., the "
1929 "name does not contain a slash), the system will search this path for "
1930 "the specified file."),
1933 &Dynamic_library_path,
1934 "$libdir", NULL, NULL
1938 {"krb_server_keyfile", PGC_POSTMASTER, CONN_AUTH_SECURITY,
1939 gettext_noop("Sets the location of the Kerberos server key file."),
1943 &pg_krb_server_keyfile,
1944 PG_KRB_SRVTAB, NULL, NULL
1948 {"krb_srvname", PGC_POSTMASTER, CONN_AUTH_SECURITY,
1949 gettext_noop("Sets the name of the Kerberos service."),
1953 PG_KRB_SRVNAM, NULL, NULL
1957 {"krb_server_hostname", PGC_POSTMASTER, CONN_AUTH_SECURITY,
1958 gettext_noop("Sets the hostname of the Kerberos server."),
1961 &pg_krb_server_hostname,
1966 {"bonjour_name", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1967 gettext_noop("Sets the Bonjour broadcast service name."),
1974 /* See main.c about why defaults for LC_foo are not all alike */
1977 {"lc_collate", PGC_INTERNAL, CLIENT_CONN_LOCALE,
1978 gettext_noop("Shows the collation order locale."),
1980 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1987 {"lc_ctype", PGC_INTERNAL, CLIENT_CONN_LOCALE,
1988 gettext_noop("Shows the character classification and case conversion locale."),
1990 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1997 {"lc_messages", PGC_SUSET, CLIENT_CONN_LOCALE,
1998 gettext_noop("Sets the language in which messages are displayed."),
2002 "", locale_messages_assign, NULL
2006 {"lc_monetary", PGC_USERSET, CLIENT_CONN_LOCALE,
2007 gettext_noop("Sets the locale for formatting monetary amounts."),
2011 "C", locale_monetary_assign, NULL
2015 {"lc_numeric", PGC_USERSET, CLIENT_CONN_LOCALE,
2016 gettext_noop("Sets the locale for formatting numbers."),
2020 "C", locale_numeric_assign, NULL
2024 {"lc_time", PGC_USERSET, CLIENT_CONN_LOCALE,
2025 gettext_noop("Sets the locale for formatting date and time values."),
2029 "C", locale_time_assign, NULL
2033 {"shared_preload_libraries", PGC_POSTMASTER, RESOURCES_KERNEL,
2034 gettext_noop("Lists shared libraries to preload into server."),
2036 GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
2038 &shared_preload_libraries_string,
2043 {"local_preload_libraries", PGC_BACKEND, CLIENT_CONN_OTHER,
2044 gettext_noop("Lists shared libraries to preload into each backend."),
2046 GUC_LIST_INPUT | GUC_LIST_QUOTE
2048 &local_preload_libraries_string,
2053 {"regex_flavor", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
2054 gettext_noop("Sets the regular expression \"flavor\"."),
2055 gettext_noop("This can be set to advanced, extended, or basic.")
2057 ®ex_flavor_string,
2058 "advanced", assign_regex_flavor, NULL
2062 {"search_path", PGC_USERSET, CLIENT_CONN_STATEMENT,
2063 gettext_noop("Sets the schema search order for names that are not schema-qualified."),
2065 GUC_LIST_INPUT | GUC_LIST_QUOTE
2067 &namespace_search_path,
2068 "\"$user\",public", assign_search_path, NULL
2072 /* Can't be set in postgresql.conf */
2073 {"server_encoding", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2074 gettext_noop("Sets the server (database) character set encoding."),
2076 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2078 &server_encoding_string,
2079 "SQL_ASCII", NULL, NULL
2083 /* Can't be set in postgresql.conf */
2084 {"server_version", PGC_INTERNAL, PRESET_OPTIONS,
2085 gettext_noop("Shows the server version."),
2087 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2089 &server_version_string,
2090 PG_VERSION, NULL, NULL
2094 /* Not for general use --- used by SET ROLE */
2095 {"role", PGC_USERSET, UNGROUPED,
2096 gettext_noop("Sets the current role."),
2098 GUC_IS_NAME | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2101 "none", assign_role, show_role
2105 /* Not for general use --- used by SET SESSION AUTHORIZATION */
2106 {"session_authorization", PGC_USERSET, UNGROUPED,
2107 gettext_noop("Sets the session user name."),
2109 GUC_IS_NAME | GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2111 &session_authorization_string,
2112 NULL, assign_session_authorization, show_session_authorization
2116 {"log_destination", PGC_SIGHUP, LOGGING_WHERE,
2117 gettext_noop("Sets the destination for server log output."),
2118 gettext_noop("Valid values are combinations of \"stderr\", \"syslog\", "
2119 "and \"eventlog\", depending on the platform."),
2122 &log_destination_string,
2123 "stderr", assign_log_destination, NULL
2126 {"log_directory", PGC_SIGHUP, LOGGING_WHERE,
2127 gettext_noop("Sets the destination directory for log files."),
2128 gettext_noop("Can be specified as relative to the data directory "
2129 "or as absolute path."),
2133 "pg_log", assign_canonical_path, NULL
2136 {"log_filename", PGC_SIGHUP, LOGGING_WHERE,
2137 gettext_noop("Sets the file name pattern for log files."),
2142 "postgresql-%Y-%m-%d_%H%M%S.log", NULL, NULL
2147 {"syslog_facility", PGC_SIGHUP, LOGGING_WHERE,
2148 gettext_noop("Sets the syslog \"facility\" to be used when syslog enabled."),
2149 gettext_noop("Valid values are LOCAL0, LOCAL1, LOCAL2, LOCAL3, "
2150 "LOCAL4, LOCAL5, LOCAL6, LOCAL7.")
2152 &syslog_facility_str,
2153 "LOCAL0", assign_syslog_facility, NULL
2156 {"syslog_ident", PGC_SIGHUP, LOGGING_WHERE,
2157 gettext_noop("Sets the program name used to identify PostgreSQL "
2158 "messages in syslog."),
2162 "postgres", assign_syslog_ident, NULL
2167 {"TimeZone", PGC_USERSET, CLIENT_CONN_LOCALE,
2168 gettext_noop("Sets the time zone for displaying and interpreting time stamps."),
2173 "UNKNOWN", assign_timezone, show_timezone
2176 {"timezone_abbreviations", PGC_USERSET, CLIENT_CONN_LOCALE,
2177 gettext_noop("Selects a file of time zone abbreviations."),
2180 &timezone_abbreviations_string,
2181 "UNKNOWN", assign_timezone_abbreviations, NULL
2185 {"transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
2186 gettext_noop("Sets the current transaction's isolation level."),
2188 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2190 &XactIsoLevel_string,
2191 NULL, assign_XactIsoLevel, show_XactIsoLevel
2195 {"unix_socket_group", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2196 gettext_noop("Sets the owning group of the Unix-domain socket."),
2197 gettext_noop("The owning user of the socket is always the user "
2198 "that starts the server.")
2205 {"unix_socket_directory", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2206 gettext_noop("Sets the directory where the Unix-domain socket will be created."),
2211 "", assign_canonical_path, NULL
2215 {"listen_addresses", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2216 gettext_noop("Sets the host name or IP address(es) to listen to."),
2221 "localhost", NULL, NULL
2225 {"wal_sync_method", PGC_SIGHUP, WAL_SETTINGS,
2226 gettext_noop("Selects the method used for forcing WAL updates to disk."),
2230 XLOG_sync_method_default, assign_xlog_sync_method, NULL
2234 {"custom_variable_classes", PGC_SIGHUP, CUSTOM_OPTIONS,
2235 gettext_noop("Sets the list of known custom variable classes."),
2237 GUC_LIST_INPUT | GUC_LIST_QUOTE
2239 &custom_variable_classes,
2240 NULL, assign_custom_variable_classes, NULL
2244 {"data_directory", PGC_POSTMASTER, FILE_LOCATIONS,
2245 gettext_noop("Sets the server's data directory."),
2254 {"config_file", PGC_POSTMASTER, FILE_LOCATIONS,
2255 gettext_noop("Sets the server's main configuration file."),
2257 GUC_DISALLOW_IN_FILE | GUC_SUPERUSER_ONLY
2264 {"hba_file", PGC_POSTMASTER, FILE_LOCATIONS,
2265 gettext_noop("Sets the server's \"hba\" configuration file."),
2274 {"ident_file", PGC_POSTMASTER, FILE_LOCATIONS,
2275 gettext_noop("Sets the server's \"ident\" configuration file."),
2284 {"external_pid_file", PGC_POSTMASTER, FILE_LOCATIONS,
2285 gettext_noop("Writes the postmaster PID to the specified file."),
2290 NULL, assign_canonical_path, NULL
2294 {"xmlbinary", PGC_USERSET, CLIENT_CONN_STATEMENT,
2295 gettext_noop("Sets how binary values are to be encoded in XML."),
2296 gettext_noop("Valid values are BASE64 and HEX.")
2299 "base64", assign_xmlbinary, NULL
2303 {"xmloption", PGC_USERSET, CLIENT_CONN_STATEMENT,
2304 gettext_noop("Sets whether XML data in implicit parsing and serialization "
2305 "operations is to be considered as documents or content fragments."),
2306 gettext_noop("Valid values are DOCUMENT and CONTENT.")
2309 "content", assign_xmloption, NULL
2313 {"temp_tablespaces", PGC_USERSET, PGC_S_FILE,
2314 gettext_noop("Sets the tablespaces suitable for creating new objects and sort files."),
2316 GUC_LIST_INPUT | GUC_LIST_QUOTE
2319 NULL, assign_temp_tablespaces, NULL
2324 {"ssl_ciphers", PGC_POSTMASTER, CONN_AUTH_SECURITY,
2325 gettext_noop("Sets the list of allowed SSL ciphers."),
2330 "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH", NULL, NULL
2332 #endif /* USE_SSL */
2334 /* End-of-list marker */
2336 {NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL
2341 /******** end of options list ********/
2345 * To allow continued support of obsolete names for GUC variables, we apply
2346 * the following mappings to any unrecognized name. Note that an old name
2347 * should be mapped to a new one only if the new variable has very similar
2348 * semantics to the old.
2350 static const char *const map_old_guc_names[] = {
2351 "sort_mem", "work_mem",
2352 "vacuum_mem", "maintenance_work_mem",
2358 * Actual lookup of variables is done through this single, sorted array.
2360 static struct config_generic **guc_variables;
2362 /* Current number of variables contained in the vector */
2363 static int num_guc_variables;
2365 /* Vector capacity */
2366 static int size_guc_variables;
2369 static bool guc_dirty; /* TRUE if need to do commit/abort work */
2371 static bool reporting_enabled; /* TRUE to enable GUC_REPORT */
2374 static int guc_var_compare(const void *a, const void *b);
2375 static int guc_name_compare(const char *namea, const char *nameb);
2376 static void push_old_value(struct config_generic * gconf);
2377 static void ReportGUCOption(struct config_generic * record);
2378 static void ShowGUCConfigOption(const char *name, DestReceiver *dest);
2379 static void ShowAllGUCConfig(DestReceiver *dest);
2380 static char *_ShowOption(struct config_generic * record, bool use_units);
2381 static bool is_newvalue_equal(struct config_generic * record, const char *newvalue);
2385 * Some infrastructure for checking malloc/strdup/realloc calls
2388 guc_malloc(int elevel, size_t size)
2392 data = malloc(size);
2395 (errcode(ERRCODE_OUT_OF_MEMORY),
2396 errmsg("out of memory")));
2401 guc_realloc(int elevel, void *old, size_t size)
2405 data = realloc(old, size);
2408 (errcode(ERRCODE_OUT_OF_MEMORY),
2409 errmsg("out of memory")));
2414 guc_strdup(int elevel, const char *src)
2421 (errcode(ERRCODE_OUT_OF_MEMORY),
2422 errmsg("out of memory")));
2428 * Support for assigning to a field of a string GUC item. Free the prior
2429 * value if it's not referenced anywhere else in the item (including stacked
2433 set_string_field(struct config_string * conf, char **field, char *newval)
2435 char *oldval = *field;
2438 /* Do the assignment */
2441 /* Exit if any duplicate references, or if old value was NULL anyway */
2442 if (oldval == NULL ||
2443 oldval == *(conf->variable) ||
2444 oldval == conf->reset_val ||
2445 oldval == conf->tentative_val)
2447 for (stack = conf->gen.stack; stack; stack = stack->prev)
2449 if (oldval == stack->tentative_val.stringval ||
2450 oldval == stack->value.stringval)
2454 /* Not used anymore, so free it */
2459 * Detect whether strval is referenced anywhere in a GUC string item
2462 string_field_used(struct config_string * conf, char *strval)
2466 if (strval == *(conf->variable) ||
2467 strval == conf->reset_val ||
2468 strval == conf->tentative_val)
2470 for (stack = conf->gen.stack; stack; stack = stack->prev)
2472 if (strval == stack->tentative_val.stringval ||
2473 strval == stack->value.stringval)
2480 struct config_generic **
2481 get_guc_variables(void)
2483 return guc_variables;
2488 * Build the sorted array. This is split out so that it could be
2489 * re-executed after startup (eg, we could allow loadable modules to
2490 * add vars, and then we'd need to re-sort).
2493 build_guc_variables(void)
2497 struct config_generic **guc_vars;
2500 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
2502 struct config_bool *conf = &ConfigureNamesBool[i];
2504 /* Rather than requiring vartype to be filled in by hand, do this: */
2505 conf->gen.vartype = PGC_BOOL;
2509 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
2511 struct config_int *conf = &ConfigureNamesInt[i];
2513 conf->gen.vartype = PGC_INT;
2517 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
2519 struct config_real *conf = &ConfigureNamesReal[i];
2521 conf->gen.vartype = PGC_REAL;
2525 for (i = 0; ConfigureNamesString[i].gen.name; i++)
2527 struct config_string *conf = &ConfigureNamesString[i];
2529 conf->gen.vartype = PGC_STRING;
2534 * Create table with 20% slack
2536 size_vars = num_vars + num_vars / 4;
2538 guc_vars = (struct config_generic **)
2539 guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
2543 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
2544 guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
2546 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
2547 guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
2549 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
2550 guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
2552 for (i = 0; ConfigureNamesString[i].gen.name; i++)
2553 guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
2556 free(guc_variables);
2557 guc_variables = guc_vars;
2558 num_guc_variables = num_vars;
2559 size_guc_variables = size_vars;
2560 qsort((void *) guc_variables, num_guc_variables,
2561 sizeof(struct config_generic *), guc_var_compare);
2565 is_custom_class(const char *name, int dotPos)
2568 * assign_custom_variable_classes() has made sure no empty identifiers or
2569 * whitespace exists in the variable
2571 bool result = false;
2572 const char *ccs = GetConfigOption("custom_variable_classes");
2576 const char *start = ccs;
2582 if (c == 0 || c == ',')
2584 if (dotPos == ccs - start && strncmp(start, name, dotPos) == 0)
2599 * Add a new GUC variable to the list of known variables. The
2600 * list is expanded if needed.
2603 add_guc_variable(struct config_generic * var, int elevel)
2605 if (num_guc_variables + 1 >= size_guc_variables)
2608 * Increase the vector by 25%
2610 int size_vars = size_guc_variables + size_guc_variables / 4;
2611 struct config_generic **guc_vars;
2616 guc_vars = (struct config_generic **)
2617 guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
2621 guc_vars = (struct config_generic **)
2622 guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
2625 if (guc_vars == NULL)
2626 return false; /* out of memory */
2628 guc_variables = guc_vars;
2629 size_guc_variables = size_vars;
2631 guc_variables[num_guc_variables++] = var;
2632 qsort((void *) guc_variables, num_guc_variables,
2633 sizeof(struct config_generic *), guc_var_compare);
2638 * Create and add a placeholder variable. It's presumed to belong
2639 * to a valid custom variable class at this point.
2641 static struct config_string *
2642 add_placeholder_variable(const char *name, int elevel)
2644 size_t sz = sizeof(struct config_string) + sizeof(char *);
2645 struct config_string *var;
2646 struct config_generic *gen;
2648 var = (struct config_string *) guc_malloc(elevel, sz);
2655 gen->name = guc_strdup(elevel, name);
2656 if (gen->name == NULL)
2662 gen->context = PGC_USERSET;
2663 gen->group = CUSTOM_OPTIONS;
2664 gen->short_desc = "GUC placeholder variable";
2665 gen->flags = GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_CUSTOM_PLACEHOLDER;
2666 gen->vartype = PGC_STRING;
2669 * The char* is allocated at the end of the struct since we have no
2670 * 'static' place to point to.
2672 var->variable = (char **) (var + 1);
2674 if (!add_guc_variable((struct config_generic *) var, elevel))
2676 free((void *) gen->name);
2685 * Look up option NAME. If it exists, return a pointer to its record,
2688 static struct config_generic *
2689 find_option(const char *name, int elevel)
2692 const char **key = &name;
2693 struct config_generic **res;
2699 * By equating const char ** with struct config_generic *, we are assuming
2700 * the name field is first in config_generic.
2702 res = (struct config_generic **) bsearch((void *) &key,
2703 (void *) guc_variables,
2705 sizeof(struct config_generic *),
2711 * See if the name is an obsolete name for a variable. We assume that the
2712 * set of supported old names is short enough that a brute-force search is
2715 for (i = 0; map_old_guc_names[i] != NULL; i += 2)
2717 if (guc_name_compare(name, map_old_guc_names[i]) == 0)
2718 return find_option(map_old_guc_names[i + 1], elevel);
2722 * Check if the name is qualified, and if so, check if the qualifier maps
2723 * to a custom variable class.
2725 dot = strchr(name, GUC_QUALIFIER_SEPARATOR);
2726 if (dot != NULL && is_custom_class(name, dot - name))
2727 /* Add a placeholder variable for this name */
2728 return (struct config_generic *) add_placeholder_variable(name, elevel);
2736 * comparator for qsorting and bsearching guc_variables array
2739 guc_var_compare(const void *a, const void *b)
2741 struct config_generic *confa = *(struct config_generic **) a;
2742 struct config_generic *confb = *(struct config_generic **) b;
2744 return guc_name_compare(confa->name, confb->name);
2749 guc_name_compare(const char *namea, const char *nameb)
2752 * The temptation to use strcasecmp() here must be resisted, because the
2753 * array ordering has to remain stable across setlocale() calls. So, build
2754 * our own with a simple ASCII-only downcasing.
2756 while (*namea && *nameb)
2758 char cha = *namea++;
2759 char chb = *nameb++;
2761 if (cha >= 'A' && cha <= 'Z')
2763 if (chb >= 'A' && chb <= 'Z')
2769 return 1; /* a is longer */
2771 return -1; /* b is longer */
2777 * Initialize GUC options during program startup.
2779 * Note that we cannot read the config file yet, since we have not yet
2780 * processed command-line switches.
2783 InitializeGUCOptions(void)
2790 * Build sorted array of all GUC variables.
2792 build_guc_variables();
2795 * Load all variables with their compiled-in defaults, and initialize
2796 * status fields as needed.
2798 for (i = 0; i < num_guc_variables; i++)
2800 struct config_generic *gconf = guc_variables[i];
2803 gconf->reset_source = PGC_S_DEFAULT;
2804 gconf->tentative_source = PGC_S_DEFAULT;
2805 gconf->source = PGC_S_DEFAULT;
2806 gconf->stack = NULL;
2808 switch (gconf->vartype)
2812 struct config_bool *conf = (struct config_bool *) gconf;
2814 if (conf->assign_hook)
2815 if (!(*conf->assign_hook) (conf->reset_val, true,
2817 elog(FATAL, "failed to initialize %s to %d",
2818 conf->gen.name, (int) conf->reset_val);
2819 *conf->variable = conf->reset_val;
2824 struct config_int *conf = (struct config_int *) gconf;
2826 Assert(conf->reset_val >= conf->min);
2827 Assert(conf->reset_val <= conf->max);
2828 if (conf->assign_hook)
2829 if (!(*conf->assign_hook) (conf->reset_val, true,
2831 elog(FATAL, "failed to initialize %s to %d",
2832 conf->gen.name, conf->reset_val);
2833 *conf->variable = conf->reset_val;
2838 struct config_real *conf = (struct config_real *) gconf;
2840 Assert(conf->reset_val >= conf->min);
2841 Assert(conf->reset_val <= conf->max);
2842 if (conf->assign_hook)
2843 if (!(*conf->assign_hook) (conf->reset_val, true,
2845 elog(FATAL, "failed to initialize %s to %g",
2846 conf->gen.name, conf->reset_val);
2847 *conf->variable = conf->reset_val;
2852 struct config_string *conf = (struct config_string *) gconf;
2855 *conf->variable = NULL;
2856 conf->reset_val = NULL;
2857 conf->tentative_val = NULL;
2859 if (conf->boot_val == NULL)
2861 /* Cannot set value yet */
2865 str = guc_strdup(FATAL, conf->boot_val);
2866 conf->reset_val = str;
2868 if (conf->assign_hook)
2872 newstr = (*conf->assign_hook) (str, true,
2876 elog(FATAL, "failed to initialize %s to \"%s\"",
2877 conf->gen.name, str);
2879 else if (newstr != str)
2884 * See notes in set_config_option about casting
2886 str = (char *) newstr;
2887 conf->reset_val = str;
2890 *conf->variable = str;
2898 reporting_enabled = false;
2901 * Prevent any attempt to override the transaction modes from
2902 * non-interactive sources.
2904 SetConfigOption("transaction_isolation", "default",
2905 PGC_POSTMASTER, PGC_S_OVERRIDE);
2906 SetConfigOption("transaction_read_only", "no",
2907 PGC_POSTMASTER, PGC_S_OVERRIDE);
2910 * For historical reasons, some GUC parameters can receive defaults from
2911 * environment variables. Process those settings.
2914 env = getenv("PGPORT");
2916 SetConfigOption("port", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
2918 env = getenv("PGDATESTYLE");
2920 SetConfigOption("datestyle", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
2922 env = getenv("PGCLIENTENCODING");
2924 SetConfigOption("client_encoding", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
2927 * rlimit isn't exactly an "environment variable", but it behaves about
2928 * the same. If we can identify the platform stack depth rlimit, increase
2929 * default stack depth setting up to whatever is safe (but at most 2MB).
2931 stack_rlimit = get_stack_depth_rlimit();
2932 if (stack_rlimit > 0)
2934 int new_limit = (stack_rlimit - STACK_DEPTH_SLOP) / 1024L;
2936 if (new_limit > 100)
2940 new_limit = Min(new_limit, 2048);
2941 sprintf(limbuf, "%d", new_limit);
2942 SetConfigOption("max_stack_depth", limbuf,
2943 PGC_POSTMASTER, PGC_S_ENV_VAR);
2950 * Select the configuration files and data directory to be used, and
2951 * do the initial read of postgresql.conf.
2953 * This is called after processing command-line switches.
2954 * userDoption is the -D switch value if any (NULL if unspecified).
2955 * progname is just for use in error messages.
2957 * Returns true on success; on failure, prints a suitable error message
2958 * to stderr and returns false.
2961 SelectConfigFiles(const char *userDoption, const char *progname)
2965 struct stat stat_buf;
2967 /* configdir is -D option, or $PGDATA if no -D */
2969 configdir = make_absolute_path(userDoption);
2971 configdir = make_absolute_path(getenv("PGDATA"));
2974 * Find the configuration file: if config_file was specified on the
2975 * command line, use it, else use configdir/postgresql.conf. In any case
2976 * ensure the result is an absolute path, so that it will be interpreted
2977 * the same way by future backends.
2980 fname = make_absolute_path(ConfigFileName);
2983 fname = guc_malloc(FATAL,
2984 strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
2985 sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
2989 write_stderr("%s does not know where to find the server configuration file.\n"
2990 "You must specify the --config-file or -D invocation "
2991 "option or set the PGDATA environment variable.\n",
2997 * Set the ConfigFileName GUC variable to its final value, ensuring that
2998 * it can't be overridden later.
3000 SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
3004 * Now read the config file for the first time.
3006 if (stat(ConfigFileName, &stat_buf) != 0)
3008 write_stderr("%s cannot access the server configuration file \"%s\": %s\n",
3009 progname, ConfigFileName, strerror(errno));
3013 ProcessConfigFile(PGC_POSTMASTER);
3016 * If the data_directory GUC variable has been set, use that as DataDir;
3017 * otherwise use configdir if set; else punt.
3019 * Note: SetDataDir will copy and absolute-ize its argument, so we don't
3023 SetDataDir(data_directory);
3025 SetDataDir(configdir);
3028 write_stderr("%s does not know where to find the database system data.\n"
3029 "This can be specified as \"data_directory\" in \"%s\", "
3030 "or by the -D invocation option, or by the "
3031 "PGDATA environment variable.\n",
3032 progname, ConfigFileName);
3037 * Reflect the final DataDir value back into the data_directory GUC var.
3038 * (If you are wondering why we don't just make them a single variable,
3039 * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
3040 * child backends specially. XXX is that still true? Given that we now
3041 * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
3042 * DataDir in advance.)
3044 SetConfigOption("data_directory", DataDir, PGC_POSTMASTER, PGC_S_OVERRIDE);
3047 * Figure out where pg_hba.conf is, and make sure the path is absolute.
3050 fname = make_absolute_path(HbaFileName);
3053 fname = guc_malloc(FATAL,
3054 strlen(configdir) + strlen(HBA_FILENAME) + 2);
3055 sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
3059 write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
3060 "This can be specified as \"hba_file\" in \"%s\", "
3061 "or by the -D invocation option, or by the "
3062 "PGDATA environment variable.\n",
3063 progname, ConfigFileName);
3066 SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
3070 * Likewise for pg_ident.conf.
3073 fname = make_absolute_path(IdentFileName);
3076 fname = guc_malloc(FATAL,
3077 strlen(configdir) + strlen(IDENT_FILENAME) + 2);
3078 sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
3082 write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
3083 "This can be specified as \"ident_file\" in \"%s\", "
3084 "or by the -D invocation option, or by the "
3085 "PGDATA environment variable.\n",
3086 progname, ConfigFileName);
3089 SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
3099 * Reset all options to their saved default values (implements RESET ALL)
3102 ResetAllOptions(void)
3106 for (i = 0; i < num_guc_variables; i++)
3108 struct config_generic *gconf = guc_variables[i];
3110 /* Don't reset non-SET-able values */
3111 if (gconf->context != PGC_SUSET &&
3112 gconf->context != PGC_USERSET)
3114 /* Don't reset if special exclusion from RESET ALL */
3115 if (gconf->flags & GUC_NO_RESET_ALL)
3117 /* No need to reset if wasn't SET */
3118 if (gconf->source <= PGC_S_OVERRIDE)
3121 /* Save old value to support transaction abort */
3122 push_old_value(gconf);
3124 switch (gconf->vartype)
3128 struct config_bool *conf = (struct config_bool *) gconf;
3130 if (conf->assign_hook)
3131 if (!(*conf->assign_hook) (conf->reset_val, true,
3133 elog(ERROR, "failed to reset %s", conf->gen.name);
3134 *conf->variable = conf->reset_val;
3135 conf->tentative_val = conf->reset_val;
3136 conf->gen.source = conf->gen.reset_source;
3137 conf->gen.tentative_source = conf->gen.reset_source;
3138 conf->gen.status |= GUC_HAVE_TENTATIVE;
3144 struct config_int *conf = (struct config_int *) gconf;
3146 if (conf->assign_hook)
3147 if (!(*conf->assign_hook) (conf->reset_val, true,
3149 elog(ERROR, "failed to reset %s", conf->gen.name);
3150 *conf->variable = conf->reset_val;
3151 conf->tentative_val = conf->reset_val;
3152 conf->gen.source = conf->gen.reset_source;
3153 conf->gen.tentative_source = conf->gen.reset_source;
3154 conf->gen.status |= GUC_HAVE_TENTATIVE;
3160 struct config_real *conf = (struct config_real *) gconf;
3162 if (conf->assign_hook)
3163 if (!(*conf->assign_hook) (conf->reset_val, true,
3165 elog(ERROR, "failed to reset %s", conf->gen.name);
3166 *conf->variable = conf->reset_val;
3167 conf->tentative_val = conf->reset_val;
3168 conf->gen.source = conf->gen.reset_source;
3169 conf->gen.tentative_source = conf->gen.reset_source;
3170 conf->gen.status |= GUC_HAVE_TENTATIVE;
3176 struct config_string *conf = (struct config_string *) gconf;
3179 if (conf->reset_val == NULL)
3181 /* Nothing to reset to, as yet; so do nothing */
3185 /* We need not strdup here */
3186 str = conf->reset_val;
3188 if (conf->assign_hook)
3192 newstr = (*conf->assign_hook) (str, true,
3195 elog(ERROR, "failed to reset %s", conf->gen.name);
3196 else if (newstr != str)
3199 * See notes in set_config_option about casting
3201 str = (char *) newstr;
3205 set_string_field(conf, conf->variable, str);
3206 set_string_field(conf, &conf->tentative_val, str);
3207 conf->gen.source = conf->gen.reset_source;
3208 conf->gen.tentative_source = conf->gen.reset_source;
3209 conf->gen.status |= GUC_HAVE_TENTATIVE;
3215 if (gconf->flags & GUC_REPORT)
3216 ReportGUCOption(gconf);
3223 * Push previous state during first assignment to a GUC variable
3224 * within a particular transaction.
3226 * We have to be willing to "back-fill" the state stack if the first
3227 * assignment occurs within a subtransaction nested several levels deep.
3228 * This ensures that if an intermediate transaction aborts, it will have
3229 * the proper value available to restore the setting to.
3232 push_old_value(struct config_generic * gconf)
3234 int my_level = GetCurrentTransactionNestLevel();
3237 /* If we're not inside a transaction, do nothing */
3243 /* Done if we already pushed it at this nesting depth */
3244 if (gconf->stack && gconf->stack->nest_level >= my_level)
3248 * We keep all the stack entries in TopTransactionContext so as to
3249 * avoid allocation problems when a subtransaction back-fills stack
3250 * entries for upper transaction levels.
3252 stack = (GucStack *) MemoryContextAlloc(TopTransactionContext,
3255 stack->prev = gconf->stack;
3256 stack->nest_level = stack->prev ? stack->prev->nest_level + 1 : 1;
3257 stack->status = gconf->status;
3258 stack->tentative_source = gconf->tentative_source;
3259 stack->source = gconf->source;
3261 switch (gconf->vartype)
3264 stack->tentative_val.boolval =
3265 ((struct config_bool *) gconf)->tentative_val;
3266 stack->value.boolval =
3267 *((struct config_bool *) gconf)->variable;
3271 stack->tentative_val.intval =
3272 ((struct config_int *) gconf)->tentative_val;
3273 stack->value.intval =
3274 *((struct config_int *) gconf)->variable;
3278 stack->tentative_val.realval =
3279 ((struct config_real *) gconf)->tentative_val;
3280 stack->value.realval =
3281 *((struct config_real *) gconf)->variable;
3285 stack->tentative_val.stringval =
3286 ((struct config_string *) gconf)->tentative_val;
3287 stack->value.stringval =
3288 *((struct config_string *) gconf)->variable;
3292 gconf->stack = stack;
3294 /* Set state to indicate nothing happened yet within this level */
3295 gconf->status = GUC_HAVE_STACK;
3297 /* Ensure we remember to pop at end of xact */
3303 * Do GUC processing at transaction or subtransaction commit or abort.
3306 AtEOXact_GUC(bool isCommit, bool isSubXact)
3311 /* Quick exit if nothing's changed in this transaction */
3315 my_level = GetCurrentTransactionNestLevel();
3316 Assert(isSubXact ? (my_level > 1) : (my_level == 1));
3318 for (i = 0; i < num_guc_variables; i++)
3320 struct config_generic *gconf = guc_variables[i];
3321 int my_status = gconf->status;
3322 GucStack *stack = gconf->stack;
3327 * Skip if nothing's happened to this var in this transaction
3331 Assert(stack == NULL);
3334 /* Assert that we stacked old value before changing it */
3335 Assert(stack != NULL && (my_status & GUC_HAVE_STACK));
3336 /* However, the last change may have been at an outer xact level */
3337 if (stack->nest_level < my_level)
3339 Assert(stack->nest_level == my_level);
3342 * We will pop the stack entry. Start by restoring outer xact status
3343 * (since we may want to modify it below). Be careful to use
3344 * my_status to reference the inner xact status below this point...
3346 gconf->status = stack->status;
3349 * We have two cases:
3351 * If commit and HAVE_TENTATIVE, set actual value to tentative (this
3352 * is to override a SET LOCAL if one occurred later than SET). We keep
3353 * the tentative value and propagate HAVE_TENTATIVE to the parent
3354 * status, allowing the SET's effect to percolate up. (But if we're
3355 * exiting the outermost transaction, we'll drop the HAVE_TENTATIVE
3358 * Otherwise, we have a transaction that aborted or executed only SET
3359 * LOCAL (or no SET at all). In either case it should have no further
3360 * effect, so restore both tentative and actual values from the stack
3364 useTentative = isCommit && (my_status & GUC_HAVE_TENTATIVE) != 0;
3367 switch (gconf->vartype)
3371 struct config_bool *conf = (struct config_bool *) gconf;
3373 GucSource newsource;
3377 newval = conf->tentative_val;
3378 newsource = conf->gen.tentative_source;
3379 conf->gen.status |= GUC_HAVE_TENTATIVE;
3383 newval = stack->value.boolval;
3384 newsource = stack->source;
3385 conf->tentative_val = stack->tentative_val.boolval;
3386 conf->gen.tentative_source = stack->tentative_source;
3389 if (*conf->variable != newval)
3391 if (conf->assign_hook)
3392 if (!(*conf->assign_hook) (newval,
3393 true, PGC_S_OVERRIDE))
3394 elog(LOG, "failed to commit %s",
3396 *conf->variable = newval;
3399 conf->gen.source = newsource;
3404 struct config_int *conf = (struct config_int *) gconf;
3406 GucSource newsource;
3410 newval = conf->tentative_val;
3411 newsource = conf->gen.tentative_source;
3412 conf->gen.status |= GUC_HAVE_TENTATIVE;
3416 newval = stack->value.intval;
3417 newsource = stack->source;
3418 conf->tentative_val = stack->tentative_val.intval;
3419 conf->gen.tentative_source = stack->tentative_source;
3422 if (*conf->variable != newval)
3424 if (conf->assign_hook)
3425 if (!(*conf->assign_hook) (newval,
3426 true, PGC_S_OVERRIDE))
3427 elog(LOG, "failed to commit %s",
3429 *conf->variable = newval;
3432 conf->gen.source = newsource;
3437 struct config_real *conf = (struct config_real *) gconf;
3439 GucSource newsource;
3443 newval = conf->tentative_val;
3444 newsource = conf->gen.tentative_source;
3445 conf->gen.status |= GUC_HAVE_TENTATIVE;
3449 newval = stack->value.realval;
3450 newsource = stack->source;
3451 conf->tentative_val = stack->tentative_val.realval;
3452 conf->gen.tentative_source = stack->tentative_source;
3455 if (*conf->variable != newval)
3457 if (conf->assign_hook)
3458 if (!(*conf->assign_hook) (newval,
3459 true, PGC_S_OVERRIDE))
3460 elog(LOG, "failed to commit %s",
3462 *conf->variable = newval;
3465 conf->gen.source = newsource;
3470 struct config_string *conf = (struct config_string *) gconf;
3472 GucSource newsource;
3476 newval = conf->tentative_val;
3477 newsource = conf->gen.tentative_source;
3478 conf->gen.status |= GUC_HAVE_TENTATIVE;
3482 newval = stack->value.stringval;
3483 newsource = stack->source;
3484 set_string_field(conf, &conf->tentative_val,
3485 stack->tentative_val.stringval);
3486 conf->gen.tentative_source = stack->tentative_source;
3489 if (*conf->variable != newval)
3491 if (conf->assign_hook)
3495 newstr = (*conf->assign_hook) (newval, true,
3498 elog(LOG, "failed to commit %s",
3500 else if (newstr != newval)
3503 * If newval should now be freed, it'll be
3504 * taken care of below.
3506 * See notes in set_config_option about
3509 newval = (char *) newstr;
3513 set_string_field(conf, conf->variable, newval);
3516 conf->gen.source = newsource;
3517 /* Release stacked values if not used anymore */
3518 set_string_field(conf, &stack->value.stringval,
3520 set_string_field(conf, &stack->tentative_val.stringval,
3522 /* Don't store tentative value separately after commit */
3524 set_string_field(conf, &conf->tentative_val, NULL);
3529 /* Finish popping the state stack */
3530 gconf->stack = stack->prev;
3534 * If we're now out of all xact levels, forget TENTATIVE status bit;
3535 * there's nothing tentative about the value anymore.
3539 Assert(gconf->stack == NULL);
3543 /* Report new value if we changed it */
3544 if (changed && (gconf->flags & GUC_REPORT))
3545 ReportGUCOption(gconf);
3549 * If we're now out of all xact levels, we can clear guc_dirty. (Note: we
3550 * cannot reset guc_dirty when exiting a subtransaction, because we know
3551 * that all outer transaction levels will have stacked values to deal
3560 * Start up automatic reporting of changes to variables marked GUC_REPORT.
3561 * This is executed at completion of backend startup.
3564 BeginReportingGUCOptions(void)
3569 * Don't do anything unless talking to an interactive frontend of protocol
3572 if (whereToSendOutput != DestRemote ||
3573 PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
3576 reporting_enabled = true;
3578 /* Transmit initial values of interesting variables */
3579 for (i = 0; i < num_guc_variables; i++)
3581 struct config_generic *conf = guc_variables[i];
3583 if (conf->flags & GUC_REPORT)
3584 ReportGUCOption(conf);
3589 * ReportGUCOption: if appropriate, transmit option value to frontend
3592 ReportGUCOption(struct config_generic * record)
3594 if (reporting_enabled && (record->flags & GUC_REPORT))
3596 char *val = _ShowOption(record, false);
3597 StringInfoData msgbuf;
3599 pq_beginmessage(&msgbuf, 'S');
3600 pq_sendstring(&msgbuf, record->name);
3601 pq_sendstring(&msgbuf, val);
3602 pq_endmessage(&msgbuf);
3610 * Try to interpret value as boolean value. Valid values are: true,
3611 * false, yes, no, on, off, 1, 0. If the string parses okay, return
3612 * true, else false. If result is not NULL, return the parsing result
3616 parse_bool(const char *value, bool *result)
3618 size_t len = strlen(value);
3620 if (pg_strncasecmp(value, "true", len) == 0)
3625 else if (pg_strncasecmp(value, "false", len) == 0)
3631 else if (pg_strncasecmp(value, "yes", len) == 0)
3636 else if (pg_strncasecmp(value, "no", len) == 0)
3642 /* 'o' is not unique enough */
3643 else if (pg_strncasecmp(value, "on", (len > 2 ? len : 2)) == 0)
3648 else if (pg_strncasecmp(value, "off", (len > 2 ? len : 2)) == 0)
3654 else if (pg_strcasecmp(value, "1") == 0)
3659 else if (pg_strcasecmp(value, "0") == 0)
3668 *result = false; /* suppress compiler warning */
3677 * Try to parse value as an integer. The accepted formats are the
3678 * usual decimal, octal, or hexadecimal formats. If the string parses
3679 * okay, return true, else false. If result is not NULL, return the
3683 parse_int(const char *value, int *result, int flags)
3689 val = strtol(value, &endptr, 0);
3691 if ((flags & GUC_UNIT_MEMORY) && endptr != value)
3695 while (*endptr == ' ')
3698 if (strcmp(endptr, "kB") == 0)
3703 else if (strcmp(endptr, "MB") == 0)
3709 else if (strcmp(endptr, "GB") == 0)
3718 switch (flags & GUC_UNIT_MEMORY)
3720 case GUC_UNIT_BLOCKS:
3721 val /= (BLCKSZ / 1024);
3723 case GUC_UNIT_XBLOCKS:
3724 val /= (XLOG_BLCKSZ / 1024);
3730 if ((flags & GUC_UNIT_TIME) && endptr != value)
3734 while (*endptr == ' ')
3737 if (strcmp(endptr, "ms") == 0)
3742 else if (strcmp(endptr, "s") == 0)
3748 else if (strcmp(endptr, "min") == 0)
3754 else if (strcmp(endptr, "h") == 0)
3760 else if (strcmp(endptr, "d") == 0)
3769 switch (flags & GUC_UNIT_TIME)
3781 if (endptr == value || *endptr != '\0' || errno == ERANGE
3782 #ifdef HAVE_LONG_INT_64
3783 /* if long > 32 bits, check for overflow of int4 */
3784 || val != (long) ((int32) val)
3789 *result = 0; /* suppress compiler warning */
3793 *result = (int) val;
3800 * Try to parse value as a floating point constant in the usual
3801 * format. If the value parsed okay return true, else false. If
3802 * result is not NULL, return the semantic value there.
3805 parse_real(const char *value, double *result)
3811 val = strtod(value, &endptr);
3812 if (endptr == value || *endptr != '\0' || errno == ERANGE)
3815 *result = 0; /* suppress compiler warning */
3825 * Call a GucStringAssignHook function, being careful to free the
3826 * "newval" string if the hook ereports.
3828 * This is split out of set_config_option just to avoid the "volatile"
3829 * qualifiers that would otherwise have to be plastered all over.
3832 call_string_assign_hook(GucStringAssignHook assign_hook,
3833 char *newval, bool doit, GucSource source)
3839 result = (*assign_hook) (newval, doit, source);
3853 * Sets option `name' to given value. The value should be a string
3854 * which is going to be parsed and converted to the appropriate data
3855 * type. The context and source parameters indicate in which context this
3856 * function is being called so it can apply the access restrictions
3859 * If value is NULL, set the option to its default value. If the
3860 * parameter changeVal is false then don't really set the option but do all
3861 * the checks to see if it would work.
3863 * If there is an error (non-existing option, invalid value) then an
3864 * ereport(ERROR) is thrown *unless* this is called in a context where we
3865 * don't want to ereport (currently, startup or SIGHUP config file reread).
3866 * In that case we write a suitable error message via ereport(DEBUG) and
3867 * return false. This is working around the deficiencies in the ereport
3868 * mechanism, so don't blame me. In all other cases, the function
3869 * returns true, including cases where the input is valid but we chose
3870 * not to apply it because of context or source-priority considerations.
3872 * See also SetConfigOption for an external interface.
3875 set_config_option(const char *name, const char *value,
3876 GucContext context, GucSource source,
3877 bool isLocal, bool changeVal)
3879 struct config_generic *record;
3883 if (context == PGC_SIGHUP || source == PGC_S_DEFAULT)
3886 * To avoid cluttering the log, only the postmaster bleats loudly
3887 * about problems with the config file.
3889 elevel = IsUnderPostmaster ? DEBUG2 : LOG;
3891 else if (source == PGC_S_DATABASE || source == PGC_S_USER)
3896 record = find_option(name, elevel);
3900 (errcode(ERRCODE_UNDEFINED_OBJECT),
3901 errmsg("unrecognized configuration parameter \"%s\"", name)));
3906 * Check if the option can be set at this time. See guc.h for the precise
3907 * rules. Note that we don't want to throw errors if we're in the SIGHUP
3908 * context. In that case we just ignore the attempt and return true.
3910 switch (record->context)
3913 if (context == PGC_SIGHUP)
3915 if (context != PGC_INTERNAL)
3918 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3919 errmsg("parameter \"%s\" cannot be changed",
3924 case PGC_POSTMASTER:
3925 if (context == PGC_SIGHUP)
3927 if (changeVal && !is_newvalue_equal(record, value))
3929 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3930 errmsg("parameter \"%s\" cannot be changed after server start; configuration file change ignored",
3935 if (context != PGC_POSTMASTER)
3938 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3939 errmsg("parameter \"%s\" cannot be changed after server start",
3945 if (context != PGC_SIGHUP && context != PGC_POSTMASTER)
3948 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3949 errmsg("parameter \"%s\" cannot be changed now",
3955 * Hmm, the idea of the SIGHUP context is "ought to be global, but
3956 * can be changed after postmaster start". But there's nothing
3957 * that prevents a crafty administrator from sending SIGHUP
3958 * signals to individual backends only.
3962 if (context == PGC_SIGHUP)
3965 * If a PGC_BACKEND parameter is changed in the config file,
3966 * we want to accept the new value in the postmaster (whence
3967 * it will propagate to subsequently-started backends), but
3968 * ignore it in existing backends. This is a tad klugy, but
3969 * necessary because we don't re-read the config file during
3972 if (IsUnderPostmaster)
3975 else if (context != PGC_BACKEND && context != PGC_POSTMASTER)
3978 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3979 errmsg("parameter \"%s\" cannot be set after connection start",
3985 if (context == PGC_USERSET || context == PGC_BACKEND)
3988 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3989 errmsg("permission denied to set parameter \"%s\"",
4000 * Should we set reset/stacked values? (If so, the behavior is not
4003 makeDefault = changeVal && (source <= PGC_S_OVERRIDE) && (value != NULL);
4006 * Ignore attempted set if overridden by previously processed setting.
4007 * However, if changeVal is false then plow ahead anyway since we are
4008 * trying to find out if the value is potentially good, not actually use
4009 * it. Also keep going if makeDefault is true, since we may want to set
4010 * the reset/stacked values even if we can't set the variable itself.
4012 if (record->source > source)
4014 if (changeVal && !makeDefault)
4016 elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
4024 * Evaluate value and set variable.
4026 switch (record->vartype)
4030 struct config_bool *conf = (struct config_bool *) record;
4035 if (!parse_bool(value, &newval))
4038 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4039 errmsg("parameter \"%s\" requires a Boolean value",
4046 newval = conf->reset_val;
4047 source = conf->gen.reset_source;
4050 if (conf->assign_hook)
4051 if (!(*conf->assign_hook) (newval, changeVal, source))
4054 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4055 errmsg("invalid value for parameter \"%s\": %d",
4056 name, (int) newval)));
4060 if (changeVal || makeDefault)
4062 /* Save old value to support transaction abort */
4064 push_old_value(&conf->gen);
4067 *conf->variable = newval;
4068 conf->gen.source = source;
4074 if (conf->gen.reset_source <= source)
4076 conf->reset_val = newval;
4077 conf->gen.reset_source = source;
4079 for (stack = conf->gen.stack; stack; stack = stack->prev)
4081 if (stack->source <= source)
4083 stack->value.boolval = newval;
4084 stack->source = source;
4090 conf->gen.status |= GUC_HAVE_LOCAL;
4095 conf->tentative_val = newval;
4096 conf->gen.tentative_source = source;
4097 conf->gen.status |= GUC_HAVE_TENTATIVE;
4106 struct config_int *conf = (struct config_int *) record;
4111 if (!parse_int(value, &newval, conf->gen.flags))
4114 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4115 errmsg("parameter \"%s\" requires an integer value",
4119 if (newval < conf->min || newval > conf->max)
4122 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4123 errmsg("%d is outside the valid range for parameter \"%s\" (%d .. %d)",
4124 newval, name, conf->min, conf->max)));
4130 newval = conf->reset_val;
4131 source = conf->gen.reset_source;
4134 if (conf->assign_hook)
4135 if (!(*conf->assign_hook) (newval, changeVal, source))
4138 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4139 errmsg("invalid value for parameter \"%s\": %d",
4144 if (changeVal || makeDefault)
4146 /* Save old value to support transaction abort */
4148 push_old_value(&conf->gen);
4151 *conf->variable = newval;
4152 conf->gen.source = source;
4158 if (conf->gen.reset_source <= source)
4160 conf->reset_val = newval;
4161 conf->gen.reset_source = source;
4163 for (stack = conf->gen.stack; stack; stack = stack->prev)
4165 if (stack->source <= source)
4167 stack->value.intval = newval;
4168 stack->source = source;
4174 conf->gen.status |= GUC_HAVE_LOCAL;
4179 conf->tentative_val = newval;
4180 conf->gen.tentative_source = source;
4181 conf->gen.status |= GUC_HAVE_TENTATIVE;
4190 struct config_real *conf = (struct config_real *) record;
4195 if (!parse_real(value, &newval))
4198 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4199 errmsg("parameter \"%s\" requires a numeric value",
4203 if (newval < conf->min || newval > conf->max)
4206 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4207 errmsg("%g is outside the valid range for parameter \"%s\" (%g .. %g)",
4208 newval, name, conf->min, conf->max)));
4214 newval = conf->reset_val;
4215 source = conf->gen.reset_source;
4218 if (conf->assign_hook)
4219 if (!(*conf->assign_hook) (newval, changeVal, source))
4222 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4223 errmsg("invalid value for parameter \"%s\": %g",
4228 if (changeVal || makeDefault)
4230 /* Save old value to support transaction abort */
4232 push_old_value(&conf->gen);
4235 *conf->variable = newval;
4236 conf->gen.source = source;
4242 if (conf->gen.reset_source <= source)
4244 conf->reset_val = newval;
4245 conf->gen.reset_source = source;
4247 for (stack = conf->gen.stack; stack; stack = stack->prev)
4249 if (stack->source <= source)
4251 stack->value.realval = newval;
4252 stack->source = source;
4258 conf->gen.status |= GUC_HAVE_LOCAL;
4263 conf->tentative_val = newval;
4264 conf->gen.tentative_source = source;
4265 conf->gen.status |= GUC_HAVE_TENTATIVE;
4274 struct config_string *conf = (struct config_string *) record;
4279 newval = guc_strdup(elevel, value);
4284 * The only sort of "parsing" check we need to do is apply
4285 * truncation if GUC_IS_NAME.
4287 if (conf->gen.flags & GUC_IS_NAME)
4288 truncate_identifier(newval, strlen(newval), true);
4290 else if (conf->reset_val)
4293 * We could possibly avoid strdup here, but easier to make
4294 * this case work the same as the normal assignment case.
4296 newval = guc_strdup(elevel, conf->reset_val);
4299 source = conf->gen.reset_source;
4303 /* Nothing to reset to, as yet; so do nothing */
4307 if (conf->assign_hook)
4309 const char *hookresult;
4312 * If the hook ereports, we have to make sure we free
4313 * newval, else it will be a permanent memory leak.
4315 hookresult = call_string_assign_hook(conf->assign_hook,
4319 if (hookresult == NULL)
4323 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4324 errmsg("invalid value for parameter \"%s\": \"%s\"",
4325 name, value ? value : "")));
4328 else if (hookresult != newval)
4333 * Having to cast away const here is annoying, but the
4334 * alternative is to declare assign_hooks as returning
4335 * char*, which would mean they'd have to cast away
4336 * const, or as both taking and returning char*, which
4337 * doesn't seem attractive either --- we don't want
4338 * them to scribble on the passed str.
4340 newval = (char *) hookresult;
4344 if (changeVal || makeDefault)
4346 /* Save old value to support transaction abort */
4348 push_old_value(&conf->gen);
4351 set_string_field(conf, conf->variable, newval);
4352 conf->gen.source = source;
4358 if (conf->gen.reset_source <= source)
4360 set_string_field(conf, &conf->reset_val, newval);
4361 conf->gen.reset_source = source;
4363 for (stack = conf->gen.stack; stack; stack = stack->prev)
4365 if (stack->source <= source)
4367 set_string_field(conf, &stack->value.stringval,
4369 stack->source = source;
4372 /* Perhaps we didn't install newval anywhere */
4373 if (!string_field_used(conf, newval))
4378 conf->gen.status |= GUC_HAVE_LOCAL;
4383 set_string_field(conf, &conf->tentative_val, newval);
4384 conf->gen.tentative_source = source;
4385 conf->gen.status |= GUC_HAVE_TENTATIVE;
4395 if (changeVal && (record->flags & GUC_REPORT))
4396 ReportGUCOption(record);
4403 * Set a config option to the given value. See also set_config_option,
4404 * this is just the wrapper to be called from outside GUC. NB: this
4405 * is used only for non-transactional operations.
4408 SetConfigOption(const char *name, const char *value,
4409 GucContext context, GucSource source)
4411 (void) set_config_option(name, value, context, source, false, true);
4417 * Fetch the current value of the option `name'. If the option doesn't exist,
4418 * throw an ereport and don't return.
4420 * The string is *not* allocated for modification and is really only
4421 * valid until the next call to configuration related functions.
4424 GetConfigOption(const char *name)
4426 struct config_generic *record;
4427 static char buffer[256];
4429 record = find_option(name, ERROR);
4432 (errcode(ERRCODE_UNDEFINED_OBJECT),
4433 errmsg("unrecognized configuration parameter \"%s\"", name)));
4434 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
4436 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4437 errmsg("must be superuser to examine \"%s\"", name)));
4439 switch (record->vartype)
4442 return *((struct config_bool *) record)->variable ? "on" : "off";
4445 snprintf(buffer, sizeof(buffer), "%d",
4446 *((struct config_int *) record)->variable);
4450 snprintf(buffer, sizeof(buffer), "%g",
4451 *((struct config_real *) record)->variable);
4455 return *((struct config_string *) record)->variable;
4461 * Get the RESET value associated with the given option.
4464 GetConfigOptionResetString(const char *name)
4466 struct config_generic *record;
4467 static char buffer[256];
4469 record = find_option(name, ERROR);
4472 (errcode(ERRCODE_UNDEFINED_OBJECT),
4473 errmsg("unrecognized configuration parameter \"%s\"", name)));
4474 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
4476 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4477 errmsg("must be superuser to examine \"%s\"", name)));
4479 switch (record->vartype)
4482 return ((struct config_bool *) record)->reset_val ? "on" : "off";
4485 snprintf(buffer, sizeof(buffer), "%d",
4486 ((struct config_int *) record)->reset_val);
4490 snprintf(buffer, sizeof(buffer), "%g",
4491 ((struct config_real *) record)->reset_val);
4495 return ((struct config_string *) record)->reset_val;
4501 * Detect whether the given configuration option can only be set by
4505 IsSuperuserConfigOption(const char *name)
4507 struct config_generic *record;
4509 record = find_option(name, ERROR);
4510 /* On an unrecognized name, don't error, just return false. */
4513 return (record->context == PGC_SUSET);
4518 * flatten_set_variable_args
4519 * Given a parsenode List as emitted by the grammar for SET,
4520 * convert to the flat string representation used by GUC.
4522 * We need to be told the name of the variable the args are for, because
4523 * the flattening rules vary (ugh).
4525 * The result is NULL if input is NIL (ie, SET ... TO DEFAULT), otherwise
4526 * a palloc'd string.
4529 flatten_set_variable_args(const char *name, List *args)
4531 struct config_generic *record;
4537 * Fast path if just DEFAULT. We do not check the variable name in this
4538 * case --- necessary for RESET ALL to work correctly.
4543 /* Else get flags for the variable */
4544 record = find_option(name, ERROR);
4547 (errcode(ERRCODE_UNDEFINED_OBJECT),
4548 errmsg("unrecognized configuration parameter \"%s\"", name)));
4550 flags = record->flags;
4552 /* Complain if list input and non-list variable */
4553 if ((flags & GUC_LIST_INPUT) == 0 &&
4554 list_length(args) != 1)
4556 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4557 errmsg("SET %s takes only one argument", name)));
4559 initStringInfo(&buf);
4563 A_Const *arg = (A_Const *) lfirst(l);
4566 if (l != list_head(args))
4567 appendStringInfo(&buf, ", ");
4569 if (!IsA(arg, A_Const))
4570 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
4572 switch (nodeTag(&arg->val))
4575 appendStringInfo(&buf, "%ld", intVal(&arg->val));
4578 /* represented as a string, so just copy it */
4579 appendStringInfoString(&buf, strVal(&arg->val));
4582 val = strVal(&arg->val);
4583 if (arg->typename != NULL)
4586 * Must be a ConstInterval argument for TIME ZONE. Coerce
4587 * to interval and back to normalize the value and account
4594 typmod = typenameTypeMod(NULL, arg->typename, INTERVALOID);
4597 DirectFunctionCall3(interval_in,
4598 CStringGetDatum(val),
4599 ObjectIdGetDatum(InvalidOid),
4600 Int32GetDatum(typmod));
4603 DatumGetCString(DirectFunctionCall1(interval_out,
4605 appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
4610 * Plain string literal or identifier. For quote mode,
4611 * quote it if it's not a vanilla identifier.
4613 if (flags & GUC_LIST_QUOTE)
4614 appendStringInfoString(&buf, quote_identifier(val));
4616 appendStringInfoString(&buf, val);
4620 elog(ERROR, "unrecognized node type: %d",
4621 (int) nodeTag(&arg->val));
4634 SetPGVariable(const char *name, List *args, bool is_local)
4636 char *argstring = flatten_set_variable_args(name, args);
4638 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
4639 set_config_option(name,
4641 (superuser() ? PGC_SUSET : PGC_USERSET),
4648 * SET command wrapped as a SQL callable function.
4651 set_config_by_name(PG_FUNCTION_ARGS)
4659 if (PG_ARGISNULL(0))
4661 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
4662 errmsg("SET requires parameter name")));
4664 /* Get the GUC variable name */
4665 name = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(0)));
4667 /* Get the desired value or set to NULL for a reset request */
4668 if (PG_ARGISNULL(1))
4671 value = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(1)));
4674 * Get the desired state of is_local. Default to false if provided value
4677 if (PG_ARGISNULL(2))
4680 is_local = PG_GETARG_BOOL(2);
4682 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
4683 set_config_option(name,
4685 (superuser() ? PGC_SUSET : PGC_USERSET),
4690 /* get the new current value */
4691 new_value = GetConfigOptionByName(name, NULL);
4693 /* Convert return string to text */
4694 result_text = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(new_value)));
4697 PG_RETURN_TEXT_P(result_text);
4701 define_custom_variable(struct config_generic * variable)
4703 const char *name = variable->name;
4704 const char **nameAddr = &name;
4706 struct config_string *pHolder;
4707 struct config_generic **res = (struct config_generic **) bsearch(
4709 (void *) guc_variables,
4711 sizeof(struct config_generic *),
4716 add_guc_variable(variable, ERROR);
4721 * This better be a placeholder
4723 if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
4725 (errcode(ERRCODE_INTERNAL_ERROR),
4726 errmsg("attempt to redefine parameter \"%s\"", name)));
4728 Assert((*res)->vartype == PGC_STRING);
4729 pHolder = (struct config_string *) * res;
4731 /* We have the same name, no sorting is necessary */
4734 value = *pHolder->variable;
4737 * Assign the string value stored in the placeholder to the real variable.
4739 * XXX this is not really good enough --- it should be a nontransactional
4740 * assignment, since we don't want it to roll back if the current xact
4743 set_config_option(name, value,
4744 pHolder->gen.context, pHolder->gen.source,
4748 * Free up as much as we conveniently can of the placeholder structure
4749 * (this neglects any stack items...)
4751 set_string_field(pHolder, pHolder->variable, NULL);
4752 set_string_field(pHolder, &pHolder->reset_val, NULL);
4753 set_string_field(pHolder, &pHolder->tentative_val, NULL);
4759 init_custom_variable(struct config_generic * gen,
4761 const char *short_desc,
4762 const char *long_desc,
4764 enum config_type type)
4766 gen->name = guc_strdup(ERROR, name);
4767 gen->context = context;
4768 gen->group = CUSTOM_OPTIONS;
4769 gen->short_desc = short_desc;
4770 gen->long_desc = long_desc;
4771 gen->vartype = type;
4775 DefineCustomBoolVariable(const char *name,
4776 const char *short_desc,
4777 const char *long_desc,
4780 GucBoolAssignHook assign_hook,
4781 GucShowHook show_hook)
4783 size_t sz = sizeof(struct config_bool);
4784 struct config_bool *var = (struct config_bool *) guc_malloc(ERROR, sz);
4787 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_BOOL);
4789 var->variable = valueAddr;
4790 var->reset_val = *valueAddr;
4791 var->assign_hook = assign_hook;
4792 var->show_hook = show_hook;
4793 define_custom_variable(&var->gen);
4797 DefineCustomIntVariable(const char *name,
4798 const char *short_desc,
4799 const char *long_desc,
4804 GucIntAssignHook assign_hook,
4805 GucShowHook show_hook)
4807 size_t sz = sizeof(struct config_int);
4808 struct config_int *var = (struct config_int *) guc_malloc(ERROR, sz);
4811 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_INT);
4813 var->variable = valueAddr;
4814 var->reset_val = *valueAddr;
4815 var->min = minValue;
4816 var->max = maxValue;
4817 var->assign_hook = assign_hook;
4818 var->show_hook = show_hook;
4819 define_custom_variable(&var->gen);
4823 DefineCustomRealVariable(const char *name,
4824 const char *short_desc,
4825 const char *long_desc,
4830 GucRealAssignHook assign_hook,
4831 GucShowHook show_hook)
4833 size_t sz = sizeof(struct config_real);
4834 struct config_real *var = (struct config_real *) guc_malloc(ERROR, sz);
4837 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_REAL);
4839 var->variable = valueAddr;
4840 var->reset_val = *valueAddr;
4841 var->min = minValue;
4842 var->max = maxValue;
4843 var->assign_hook = assign_hook;
4844 var->show_hook = show_hook;
4845 define_custom_variable(&var->gen);
4849 DefineCustomStringVariable(const char *name,
4850 const char *short_desc,
4851 const char *long_desc,
4854 GucStringAssignHook assign_hook,
4855 GucShowHook show_hook)
4857 size_t sz = sizeof(struct config_string);
4858 struct config_string *var = (struct config_string *) guc_malloc(ERROR, sz);
4861 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_STRING);
4863 var->variable = valueAddr;
4864 var->reset_val = *valueAddr;
4865 var->assign_hook = assign_hook;
4866 var->show_hook = show_hook;
4867 define_custom_variable(&var->gen);
4871 EmitWarningsOnPlaceholders(const char *className)
4873 struct config_generic **vars = guc_variables;
4874 struct config_generic **last = vars + num_guc_variables;
4876 int nameLen = strlen(className);
4880 struct config_generic *var = *vars++;
4882 if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
4883 strncmp(className, var->name, nameLen) == 0 &&
4884 var->name[nameLen] == GUC_QUALIFIER_SEPARATOR)
4887 (errcode(ERRCODE_UNDEFINED_OBJECT),
4888 errmsg("unrecognized configuration parameter \"%s\"", var->name)));
4898 GetPGVariable(const char *name, DestReceiver *dest)
4900 if (pg_strcasecmp(name, "all") == 0)
4901 ShowAllGUCConfig(dest);
4903 ShowGUCConfigOption(name, dest);
4907 GetPGVariableResultDesc(const char *name)
4911 if (pg_strcasecmp(name, "all") == 0)
4913 /* need a tuple descriptor representing three TEXT columns */
4914 tupdesc = CreateTemplateTupleDesc(3, false);
4915 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
4917 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
4919 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
4925 const char *varname;
4927 /* Get the canonical spelling of name */
4928 (void) GetConfigOptionByName(name, &varname);
4930 /* need a tuple descriptor representing a single TEXT column */
4931 tupdesc = CreateTemplateTupleDesc(1, false);
4932 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
4942 ResetPGVariable(const char *name)
4944 if (pg_strcasecmp(name, "all") == 0)
4947 set_config_option(name,
4949 (superuser() ? PGC_SUSET : PGC_USERSET),
4960 ShowGUCConfigOption(const char *name, DestReceiver *dest)
4962 TupOutputState *tstate;
4964 const char *varname;
4967 /* Get the value and canonical spelling of name */
4968 value = GetConfigOptionByName(name, &varname);
4970 /* need a tuple descriptor representing a single TEXT column */
4971 tupdesc = CreateTemplateTupleDesc(1, false);
4972 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
4975 /* prepare for projection of tuples */
4976 tstate = begin_tup_output_tupdesc(dest, tupdesc);
4979 do_text_output_oneline(tstate, value);
4981 end_tup_output(tstate);
4988 ShowAllGUCConfig(DestReceiver *dest)
4990 bool am_superuser = superuser();
4992 TupOutputState *tstate;
4996 /* need a tuple descriptor representing three TEXT columns */
4997 tupdesc = CreateTemplateTupleDesc(3, false);
4998 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
5000 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
5002 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
5006 /* prepare for projection of tuples */
5007 tstate = begin_tup_output_tupdesc(dest, tupdesc);
5009 for (i = 0; i < num_guc_variables; i++)
5011 struct config_generic *conf = guc_variables[i];
5013 if ((conf->flags & GUC_NO_SHOW_ALL) ||
5014 ((conf->flags & GUC_SUPERUSER_ONLY) && !am_superuser))
5017 /* assign to the values array */
5018 values[0] = (char *) conf->name;
5019 values[1] = _ShowOption(conf, true);
5020 values[2] = (char *) conf->short_desc;
5022 /* send it to dest */
5023 do_tup_output(tstate, values);
5026 if (values[1] != NULL)
5030 end_tup_output(tstate);
5034 * Return GUC variable value by name; optionally return canonical
5035 * form of name. Return value is palloc'd.
5038 GetConfigOptionByName(const char *name, const char **varname)
5040 struct config_generic *record;
5042 record = find_option(name, ERROR);
5045 (errcode(ERRCODE_UNDEFINED_OBJECT),
5046 errmsg("unrecognized configuration parameter \"%s\"", name)));
5047 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
5049 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5050 errmsg("must be superuser to examine \"%s\"", name)));
5053 *varname = record->name;
5055 return _ShowOption(record, true);
5059 * Return GUC variable value by variable number; optionally return canonical
5060 * form of name. Return value is palloc'd.
5063 GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
5066 struct config_generic *conf;
5068 /* check requested variable number valid */
5069 Assert((varnum >= 0) && (varnum < num_guc_variables));
5071 conf = guc_variables[varnum];
5075 if ((conf->flags & GUC_NO_SHOW_ALL) ||
5076 ((conf->flags & GUC_SUPERUSER_ONLY) && !superuser()))
5082 /* first get the generic attributes */
5085 values[0] = conf->name;
5087 /* setting : use _ShowOption in order to avoid duplicating the logic */
5088 values[1] = _ShowOption(conf, false);
5091 if (conf->vartype == PGC_INT)
5095 switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
5100 case GUC_UNIT_BLOCKS:
5101 snprintf(buf, sizeof(buf), "%dkB", BLCKSZ / 1024);
5104 case GUC_UNIT_XBLOCKS:
5105 snprintf(buf, sizeof(buf), "%dkB", XLOG_BLCKSZ / 1024);
5126 values[3] = config_group_names[conf->group];
5129 values[4] = conf->short_desc;
5132 values[5] = conf->long_desc;
5135 values[6] = GucContext_Names[conf->context];
5138 values[7] = config_type_names[conf->vartype];
5141 values[8] = GucSource_Names[conf->source];
5143 /* now get the type specifc attributes */
5144 switch (conf->vartype)
5158 struct config_int *lconf = (struct config_int *) conf;
5161 snprintf(buffer, sizeof(buffer), "%d", lconf->min);
5162 values[9] = pstrdup(buffer);
5165 snprintf(buffer, sizeof(buffer), "%d", lconf->max);
5166 values[10] = pstrdup(buffer);
5172 struct config_real *lconf = (struct config_real *) conf;
5175 snprintf(buffer, sizeof(buffer), "%g", lconf->min);
5176 values[9] = pstrdup(buffer);
5179 snprintf(buffer, sizeof(buffer), "%g", lconf->max);
5180 values[10] = pstrdup(buffer);
5197 * should never get here, but in case we do, set 'em to NULL
5211 * Return the total number of GUC variables
5214 GetNumConfigOptions(void)
5216 return num_guc_variables;
5220 * show_config_by_name - equiv to SHOW X command but implemented as
5224 show_config_by_name(PG_FUNCTION_ARGS)
5230 /* Get the GUC variable name */
5231 varname = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(0)));
5234 varval = GetConfigOptionByName(varname, NULL);
5236 /* Convert to text */
5237 result_text = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(varval)));
5240 PG_RETURN_TEXT_P(result_text);
5244 * show_all_settings - equiv to SHOW ALL command but implemented as
5247 #define NUM_PG_SETTINGS_ATTS 11
5250 show_all_settings(PG_FUNCTION_ARGS)
5252 FuncCallContext *funcctx;
5256 AttInMetadata *attinmeta;
5257 MemoryContext oldcontext;
5259 /* stuff done only on the first call of the function */
5260 if (SRF_IS_FIRSTCALL())
5262 /* create a function context for cross-call persistence */
5263 funcctx = SRF_FIRSTCALL_INIT();
5266 * switch to memory context appropriate for multiple function calls
5268 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
5271 * need a tuple descriptor representing NUM_PG_SETTINGS_ATTS columns
5272 * of the appropriate types
5274 tupdesc = CreateTemplateTupleDesc(NUM_PG_SETTINGS_ATTS, false);
5275 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
5277 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
5279 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "unit",
5281 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "category",
5283 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "short_desc",
5285 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "extra_desc",
5287 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "context",
5289 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "vartype",
5291 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "source",
5293 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "min_val",
5295 TupleDescInitEntry(tupdesc, (AttrNumber) 11, "max_val",
5299 * Generate attribute metadata needed later to produce tuples from raw
5302 attinmeta = TupleDescGetAttInMetadata(tupdesc);
5303 funcctx->attinmeta = attinmeta;
5305 /* total number of tuples to be returned */
5306 funcctx->max_calls = GetNumConfigOptions();
5308 MemoryContextSwitchTo(oldcontext);
5311 /* stuff done on every call of the function */
5312 funcctx = SRF_PERCALL_SETUP();
5314 call_cntr = funcctx->call_cntr;
5315 max_calls = funcctx->max_calls;
5316 attinmeta = funcctx->attinmeta;
5318 if (call_cntr < max_calls) /* do when there is more left to send */
5320 char *values[NUM_PG_SETTINGS_ATTS];
5326 * Get the next visible GUC variable name and value
5330 GetConfigOptionByNum(call_cntr, (const char **) values, &noshow);
5333 /* bump the counter and get the next config setting */
5334 call_cntr = ++funcctx->call_cntr;
5336 /* make sure we haven't gone too far now */
5337 if (call_cntr >= max_calls)
5338 SRF_RETURN_DONE(funcctx);
5343 tuple = BuildTupleFromCStrings(attinmeta, values);
5345 /* make the tuple into a datum */
5346 result = HeapTupleGetDatum(tuple);
5348 SRF_RETURN_NEXT(funcctx, result);
5352 /* do when there is no more left */
5353 SRF_RETURN_DONE(funcctx);
5358 _ShowOption(struct config_generic * record, bool use_units)
5363 switch (record->vartype)
5367 struct config_bool *conf = (struct config_bool *) record;
5369 if (conf->show_hook)
5370 val = (*conf->show_hook) ();
5372 val = *conf->variable ? "on" : "off";
5378 struct config_int *conf = (struct config_int *) record;
5380 if (conf->show_hook)
5381 val = (*conf->show_hook) ();
5385 int result = *conf->variable;
5387 if (use_units && result > 0 && (record->flags & GUC_UNIT_MEMORY))
5389 switch (record->flags & GUC_UNIT_MEMORY)
5391 case GUC_UNIT_BLOCKS:
5392 result *= BLCKSZ / 1024;
5394 case GUC_UNIT_XBLOCKS:
5395 result *= XLOG_BLCKSZ / 1024;
5399 if (result % KB_PER_GB == 0)
5401 result /= KB_PER_GB;
5404 else if (result % KB_PER_MB == 0)
5406 result /= KB_PER_MB;
5414 else if (use_units && result > 0 && (record->flags & GUC_UNIT_TIME))
5416 switch (record->flags & GUC_UNIT_TIME)
5422 result *= MS_PER_MIN;
5426 if (result % MS_PER_D == 0)
5431 else if (result % MS_PER_H == 0)
5436 else if (result % MS_PER_MIN == 0)
5438 result /= MS_PER_MIN;
5439 strcpy(unit, "min");
5441 else if (result % MS_PER_S == 0)
5454 snprintf(buffer, sizeof(buffer), "%d%s",
5455 (int) result, unit);
5463 struct config_real *conf = (struct config_real *) record;
5465 if (conf->show_hook)
5466 val = (*conf->show_hook) ();
5469 snprintf(buffer, sizeof(buffer), "%g",
5478 struct config_string *conf = (struct config_string *) record;
5480 if (conf->show_hook)
5481 val = (*conf->show_hook) ();
5482 else if (*conf->variable && **conf->variable)
5483 val = *conf->variable;
5490 /* just to keep compiler quiet */
5495 return pstrdup(val);
5500 is_newvalue_equal(struct config_generic * record, const char *newvalue)
5502 switch (record->vartype)
5506 struct config_bool *conf = (struct config_bool *) record;
5509 return parse_bool(newvalue, &newval) && *conf->variable == newval;
5513 struct config_int *conf = (struct config_int *) record;
5516 return parse_int(newvalue, &newval, record->flags) && *conf->variable == newval;
5520 struct config_real *conf = (struct config_real *) record;
5523 return parse_real(newvalue, &newval) && *conf->variable == newval;
5527 struct config_string *conf = (struct config_string *) record;
5529 return strcmp(*conf->variable, newvalue) == 0;
5540 * This routine dumps out all non-default GUC options into a binary
5541 * file that is read by all exec'ed backends. The format is:
5543 * variable name, string, null terminated
5544 * variable value, string, null terminated
5545 * variable source, integer
5548 write_nondefault_variables(GucContext context)
5554 Assert(context == PGC_POSTMASTER || context == PGC_SIGHUP);
5556 elevel = (context == PGC_SIGHUP) ? LOG : ERROR;
5561 fp = AllocateFile(CONFIG_EXEC_PARAMS_NEW, "w");
5565 (errcode_for_file_access(),
5566 errmsg("could not write to file \"%s\": %m",
5567 CONFIG_EXEC_PARAMS_NEW)));
5571 for (i = 0; i < num_guc_variables; i++)
5573 struct config_generic *gconf = guc_variables[i];
5575 if (gconf->source != PGC_S_DEFAULT)
5577 fprintf(fp, "%s", gconf->name);
5580 switch (gconf->vartype)
5584 struct config_bool *conf = (struct config_bool *) gconf;
5586 if (*conf->variable == 0)
5587 fprintf(fp, "false");
5589 fprintf(fp, "true");
5595 struct config_int *conf = (struct config_int *) gconf;
5597 fprintf(fp, "%d", *conf->variable);
5603 struct config_real *conf = (struct config_real *) gconf;
5605 /* Could lose precision here? */
5606 fprintf(fp, "%f", *conf->variable);
5612 struct config_string *conf = (struct config_string *) gconf;
5614 fprintf(fp, "%s", *conf->variable);
5621 fwrite(&gconf->source, sizeof(gconf->source), 1, fp);
5628 (errcode_for_file_access(),
5629 errmsg("could not write to file \"%s\": %m",
5630 CONFIG_EXEC_PARAMS_NEW)));
5635 * Put new file in place. This could delay on Win32, but we don't hold
5636 * any exclusive locks.
5638 rename(CONFIG_EXEC_PARAMS_NEW, CONFIG_EXEC_PARAMS);
5643 * Read string, including null byte from file
5645 * Return NULL on EOF and nothing read
5648 read_string_with_null(FILE *fp)
5657 if ((ch = fgetc(fp)) == EOF)
5662 elog(FATAL, "invalid format of exec config params file");
5665 str = guc_malloc(FATAL, maxlen);
5666 else if (i == maxlen)
5667 str = guc_realloc(FATAL, str, maxlen *= 2);
5676 * This routine loads a previous postmaster dump of its non-default
5680 read_nondefault_variables(void)
5690 fp = AllocateFile(CONFIG_EXEC_PARAMS, "r");
5693 /* File not found is fine */
5694 if (errno != ENOENT)
5696 (errcode_for_file_access(),
5697 errmsg("could not read from file \"%s\": %m",
5698 CONFIG_EXEC_PARAMS)));
5704 struct config_generic *record;
5706 if ((varname = read_string_with_null(fp)) == NULL)
5709 if ((record = find_option(varname, FATAL)) == NULL)
5710 elog(FATAL, "failed to locate variable %s in exec config params file", varname);
5711 if ((varvalue = read_string_with_null(fp)) == NULL)
5712 elog(FATAL, "invalid format of exec config params file");
5713 if (fread(&varsource, sizeof(varsource), 1, fp) == 0)
5714 elog(FATAL, "invalid format of exec config params file");
5716 (void) set_config_option(varname, varvalue, record->context,
5717 varsource, false, true);
5724 #endif /* EXEC_BACKEND */
5728 * A little "long argument" simulation, although not quite GNU
5729 * compliant. Takes a string of the form "some-option=some value" and
5730 * returns name = "some_option" and value = "some value" in malloc'ed
5731 * storage. Note that '-' is converted to '_' in the option name. If
5732 * there is no '=' in the input string then value will be NULL.
5735 ParseLongOption(const char *string, char **name, char **value)
5744 equal_pos = strcspn(string, "=");
5746 if (string[equal_pos] == '=')
5748 *name = guc_malloc(FATAL, equal_pos + 1);
5749 strlcpy(*name, string, equal_pos + 1);
5751 *value = guc_strdup(FATAL, &string[equal_pos + 1]);
5755 /* no equal sign in string */
5756 *name = guc_strdup(FATAL, string);
5760 for (cp = *name; *cp; cp++)
5767 * Handle options fetched from pg_database.datconfig or pg_authid.rolconfig.
5768 * The array parameter must be an array of TEXT (it must not be NULL).
5771 ProcessGUCArray(ArrayType *array, GucSource source)
5775 Assert(array != NULL);
5776 Assert(ARR_ELEMTYPE(array) == TEXTOID);
5777 Assert(ARR_NDIM(array) == 1);
5778 Assert(ARR_LBOUND(array)[0] == 1);
5779 Assert(source == PGC_S_DATABASE || source == PGC_S_USER);
5781 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
5789 d = array_ref(array, 1, &i,
5790 -1 /* varlenarray */ ,
5791 -1 /* TEXT's typlen */ ,
5792 false /* TEXT's typbyval */ ,
5793 'i' /* TEXT's typalign */ ,
5799 s = DatumGetCString(DirectFunctionCall1(textout, d));
5801 ParseLongOption(s, &name, &value);
5805 (errcode(ERRCODE_SYNTAX_ERROR),
5806 errmsg("could not parse setting for parameter \"%s\"", name)));
5812 * We process all these options at SUSET level. We assume that the
5813 * right to insert an option into pg_database or pg_authid was checked
5814 * when it was inserted.
5816 SetConfigOption(name, value, PGC_SUSET, source);
5826 * Add an entry to an option array. The array parameter may be NULL
5827 * to indicate the current table entry is NULL.
5830 GUCArrayAdd(ArrayType *array, const char *name, const char *value)
5832 const char *varname;
5840 /* test if the option is valid */
5841 set_config_option(name, value,
5842 superuser() ? PGC_SUSET : PGC_USERSET,
5843 PGC_S_TEST, false, false);
5845 /* convert name to canonical spelling, so we can use plain strcmp */
5846 (void) GetConfigOptionByName(name, &varname);
5849 newval = palloc(strlen(name) + 1 + strlen(value) + 1);
5850 sprintf(newval, "%s=%s", name, value);
5851 datum = DirectFunctionCall1(textin, CStringGetDatum(newval));
5859 Assert(ARR_ELEMTYPE(array) == TEXTOID);
5860 Assert(ARR_NDIM(array) == 1);
5861 Assert(ARR_LBOUND(array)[0] == 1);
5863 index = ARR_DIMS(array)[0] + 1; /* add after end */
5865 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
5870 d = array_ref(array, 1, &i,
5871 -1 /* varlenarray */ ,
5872 -1 /* TEXT's typlen */ ,
5873 false /* TEXT's typbyval */ ,
5874 'i' /* TEXT's typalign */ ,
5878 current = DatumGetCString(DirectFunctionCall1(textout, d));
5879 if (strncmp(current, newval, strlen(name) + 1) == 0)
5886 a = array_set(array, 1, &index,
5889 -1 /* varlena array */ ,
5890 -1 /* TEXT's typlen */ ,
5891 false /* TEXT's typbyval */ ,
5892 'i' /* TEXT's typalign */ );
5895 a = construct_array(&datum, 1,
5904 * Delete an entry from an option array. The array parameter may be NULL
5905 * to indicate the current table entry is NULL. Also, if the return value
5906 * is NULL then a null should be stored.
5909 GUCArrayDelete(ArrayType *array, const char *name)
5911 const char *varname;
5912 ArrayType *newarray;
5918 /* test if the option is valid */
5919 set_config_option(name, NULL,
5920 superuser() ? PGC_SUSET : PGC_USERSET,
5921 PGC_S_TEST, false, false);
5923 /* convert name to canonical spelling, so we can use plain strcmp */
5924 (void) GetConfigOptionByName(name, &varname);
5927 /* if array is currently null, then surely nothing to delete */
5934 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
5940 d = array_ref(array, 1, &i,
5941 -1 /* varlenarray */ ,
5942 -1 /* TEXT's typlen */ ,
5943 false /* TEXT's typbyval */ ,
5944 'i' /* TEXT's typalign */ ,
5948 val = DatumGetCString(DirectFunctionCall1(textout, d));
5950 /* ignore entry if it's what we want to delete */
5951 if (strncmp(val, name, strlen(name)) == 0
5952 && val[strlen(name)] == '=')
5955 /* else add it to the output array */
5958 newarray = array_set(newarray, 1, &index,
5961 -1 /* varlenarray */ ,
5962 -1 /* TEXT's typlen */ ,
5963 false /* TEXT's typbyval */ ,
5964 'i' /* TEXT's typalign */ );
5967 newarray = construct_array(&d, 1,
5979 * assign_hook subroutines
5983 assign_log_destination(const char *value, bool doit, GucSource source)
5990 /* Need a modifiable copy of string */
5991 rawstring = pstrdup(value);
5993 /* Parse string into list of identifiers */
5994 if (!SplitIdentifierString(rawstring, ',', &elemlist))
5996 /* syntax error in list */
5998 list_free(elemlist);
5999 if (source >= PGC_S_INTERACTIVE)
6001 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6002 errmsg("invalid list syntax for parameter \"log_destination\"")));
6006 foreach(l, elemlist)
6008 char *tok = (char *) lfirst(l);
6010 if (pg_strcasecmp(tok, "stderr") == 0)
6011 newlogdest |= LOG_DESTINATION_STDERR;
6013 else if (pg_strcasecmp(tok, "syslog") == 0)
6014 newlogdest |= LOG_DESTINATION_SYSLOG;
6017 else if (pg_strcasecmp(tok, "eventlog") == 0)
6018 newlogdest |= LOG_DESTINATION_EVENTLOG;
6022 if (source >= PGC_S_INTERACTIVE)
6024 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6025 errmsg("unrecognized \"log_destination\" key word: \"%s\"",
6028 list_free(elemlist);
6034 Log_destination = newlogdest;
6037 list_free(elemlist);
6045 assign_syslog_facility(const char *facility, bool doit, GucSource source)
6049 if (pg_strcasecmp(facility, "LOCAL0") == 0)
6050 syslog_fac = LOG_LOCAL0;
6051 else if (pg_strcasecmp(facility, "LOCAL1") == 0)
6052 syslog_fac = LOG_LOCAL1;
6053 else if (pg_strcasecmp(facility, "LOCAL2") == 0)
6054 syslog_fac = LOG_LOCAL2;
6055 else if (pg_strcasecmp(facility, "LOCAL3") == 0)
6056 syslog_fac = LOG_LOCAL3;
6057 else if (pg_strcasecmp(facility, "LOCAL4") == 0)
6058 syslog_fac = LOG_LOCAL4;
6059 else if (pg_strcasecmp(facility, "LOCAL5") == 0)
6060 syslog_fac = LOG_LOCAL5;
6061 else if (pg_strcasecmp(facility, "LOCAL6") == 0)
6062 syslog_fac = LOG_LOCAL6;
6063 else if (pg_strcasecmp(facility, "LOCAL7") == 0)
6064 syslog_fac = LOG_LOCAL7;
6066 return NULL; /* reject */
6070 syslog_facility = syslog_fac;
6071 set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
6079 assign_syslog_ident(const char *ident, bool doit, GucSource source)
6082 set_syslog_parameters(ident, syslog_facility);
6086 #endif /* HAVE_SYSLOG */
6090 assign_defaultxactisolevel(const char *newval, bool doit, GucSource source)
6092 if (pg_strcasecmp(newval, "serializable") == 0)
6095 DefaultXactIsoLevel = XACT_SERIALIZABLE;
6097 else if (pg_strcasecmp(newval, "repeatable read") == 0)
6100 DefaultXactIsoLevel = XACT_REPEATABLE_READ;
6102 else if (pg_strcasecmp(newval, "read committed") == 0)
6105 DefaultXactIsoLevel = XACT_READ_COMMITTED;
6107 else if (pg_strcasecmp(newval, "read uncommitted") == 0)
6110 DefaultXactIsoLevel = XACT_READ_UNCOMMITTED;
6118 assign_log_min_messages(const char *newval,
6119 bool doit, GucSource source)
6121 return (assign_msglvl(&log_min_messages, newval, doit, source));
6125 assign_client_min_messages(const char *newval, bool doit, GucSource source)
6127 return (assign_msglvl(&client_min_messages, newval, doit, source));
6131 assign_min_error_statement(const char *newval, bool doit, GucSource source)
6133 return (assign_msglvl(&log_min_error_statement, newval, doit, source));
6137 assign_msglvl(int *var, const char *newval, bool doit, GucSource source)
6139 if (pg_strcasecmp(newval, "debug") == 0)
6144 else if (pg_strcasecmp(newval, "debug5") == 0)
6149 else if (pg_strcasecmp(newval, "debug4") == 0)
6154 else if (pg_strcasecmp(newval, "debug3") == 0)
6159 else if (pg_strcasecmp(newval, "debug2") == 0)
6164 else if (pg_strcasecmp(newval, "debug1") == 0)
6169 else if (pg_strcasecmp(newval, "log") == 0)
6176 * Client_min_messages always prints 'info', but we allow it as a value
6179 else if (pg_strcasecmp(newval, "info") == 0)
6184 else if (pg_strcasecmp(newval, "notice") == 0)
6189 else if (pg_strcasecmp(newval, "warning") == 0)
6194 else if (pg_strcasecmp(newval, "error") == 0)
6199 /* We allow FATAL/PANIC for client-side messages too. */
6200 else if (pg_strcasecmp(newval, "fatal") == 0)
6205 else if (pg_strcasecmp(newval, "panic") == 0)
6211 return NULL; /* fail */
6212 return newval; /* OK */
6216 assign_log_error_verbosity(const char *newval, bool doit, GucSource source)
6218 if (pg_strcasecmp(newval, "terse") == 0)
6221 Log_error_verbosity = PGERROR_TERSE;
6223 else if (pg_strcasecmp(newval, "default") == 0)
6226 Log_error_verbosity = PGERROR_DEFAULT;
6228 else if (pg_strcasecmp(newval, "verbose") == 0)
6231 Log_error_verbosity = PGERROR_VERBOSE;
6234 return NULL; /* fail */
6235 return newval; /* OK */
6239 assign_log_statement(const char *newval, bool doit, GucSource source)
6241 if (pg_strcasecmp(newval, "none") == 0)
6244 log_statement = LOGSTMT_NONE;
6246 else if (pg_strcasecmp(newval, "ddl") == 0)
6249 log_statement = LOGSTMT_DDL;
6251 else if (pg_strcasecmp(newval, "mod") == 0)
6254 log_statement = LOGSTMT_MOD;
6256 else if (pg_strcasecmp(newval, "all") == 0)
6259 log_statement = LOGSTMT_ALL;
6262 return NULL; /* fail */
6263 return newval; /* OK */
6267 show_num_temp_buffers(void)
6270 * We show the GUC var until local buffers have been initialized, and
6271 * NLocBuffer afterwards.
6273 static char nbuf[32];
6275 sprintf(nbuf, "%d", NLocBuffer ? NLocBuffer : num_temp_buffers);
6280 assign_phony_autocommit(bool newval, bool doit, GucSource source)
6284 if (doit && source >= PGC_S_INTERACTIVE)
6286 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6287 errmsg("SET AUTOCOMMIT TO OFF is no longer supported")));
6294 assign_custom_variable_classes(const char *newval, bool doit, GucSource source)
6297 * Check syntax. newval must be a comma separated list of identifiers.
6298 * Whitespace is allowed but skipped.
6300 bool hasSpaceAfterToken = false;
6301 const char *cp = newval;
6306 initStringInfo(&buf);
6307 while ((c = *cp++) != 0)
6309 if (isspace((unsigned char) c))
6312 hasSpaceAfterToken = true;
6318 hasSpaceAfterToken = false;
6322 appendStringInfoChar(&buf, ',');
6327 if (hasSpaceAfterToken || !isalnum((unsigned char) c))
6330 * Syntax error due to token following space after token or non
6331 * alpha numeric character
6334 (errcode(ERRCODE_SYNTAX_ERROR),
6335 errmsg("invalid syntax for \"custom_variable_classes\": \"%s\"", newval)));
6340 appendStringInfoChar(&buf, (char) c);
6343 /* Remove stray ',' at end */
6344 if (symLen == 0 && buf.len > 0)
6345 buf.data[--buf.len] = '\0';
6350 newval = strdup(buf.data);
6357 assign_debug_assertions(bool newval, bool doit, GucSource source)
6359 #ifndef USE_ASSERT_CHECKING
6362 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6363 errmsg("assertion checking is not supported by this build")));
6369 assign_ssl(bool newval, bool doit, GucSource source)
6374 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6375 errmsg("SSL is not supported by this build")));
6381 assign_stage_log_stats(bool newval, bool doit, GucSource source)
6383 if (newval && log_statement_stats)
6385 if (source >= PGC_S_INTERACTIVE)
6387 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6388 errmsg("cannot enable parameter when \"log_statement_stats\" is true")));
6389 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
6390 else if (source != PGC_S_OVERRIDE)
6397 assign_log_stats(bool newval, bool doit, GucSource source)
6400 (log_parser_stats || log_planner_stats || log_executor_stats))
6402 if (source >= PGC_S_INTERACTIVE)
6404 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6405 errmsg("cannot enable \"log_statement_stats\" when "
6406 "\"log_parser_stats\", \"log_planner_stats\", "
6407 "or \"log_executor_stats\" is true")));
6408 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
6409 else if (source != PGC_S_OVERRIDE)
6416 assign_transaction_read_only(bool newval, bool doit, GucSource source)
6418 /* Can't go to r/w mode inside a r/o transaction */
6419 if (newval == false && XactReadOnly && IsSubTransaction())
6421 if (source >= PGC_S_INTERACTIVE)
6423 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6424 errmsg("cannot set transaction read-write mode inside a read-only transaction")));
6425 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
6426 else if (source != PGC_S_OVERRIDE)
6433 assign_canonical_path(const char *newval, bool doit, GucSource source)
6437 char *canon_val = guc_strdup(ERROR, newval);
6439 canonicalize_path(canon_val);
6447 assign_backslash_quote(const char *newval, bool doit, GucSource source)
6449 BackslashQuoteType bq;
6453 * Although only "on", "off", and "safe_encoding" are documented, we use
6454 * parse_bool so we can accept all the likely variants of "on" and "off".
6456 if (pg_strcasecmp(newval, "safe_encoding") == 0)
6457 bq = BACKSLASH_QUOTE_SAFE_ENCODING;
6458 else if (parse_bool(newval, &bqbool))
6460 bq = bqbool ? BACKSLASH_QUOTE_ON : BACKSLASH_QUOTE_OFF;
6463 return NULL; /* reject */
6466 backslash_quote = bq;
6472 assign_timezone_abbreviations(const char *newval, bool doit, GucSource source)
6475 * The powerup value shown above for timezone_abbreviations is "UNKNOWN".
6476 * When we see this we just do nothing. If this value isn't overridden
6477 * from the config file then pg_timezone_abbrev_initialize() will
6478 * eventually replace it with "Default". This hack has two purposes: to
6479 * avoid wasting cycles loading values that might soon be overridden from
6480 * the config file, and to avoid trying to read the timezone abbrev files
6481 * during InitializeGUCOptions(). The latter doesn't work in an
6482 * EXEC_BACKEND subprocess because my_exec_path hasn't been set yet and so
6483 * we can't locate PGSHAREDIR. (Essentially the same hack is used to
6484 * delay initializing TimeZone ... if we have any more, we should try to
6485 * clean up and centralize this mechanism ...)
6487 if (strcmp(newval, "UNKNOWN") == 0)
6492 /* Loading abbrev file is expensive, so only do it when value changes */
6493 if (timezone_abbreviations_string == NULL ||
6494 strcmp(timezone_abbreviations_string, newval) != 0)
6499 * If reading config file, only the postmaster should bleat loudly
6500 * about problems. Otherwise, it's just this one process doing it,
6501 * and we use WARNING message level.
6503 if (source == PGC_S_FILE)
6504 elevel = IsUnderPostmaster ? DEBUG2 : LOG;
6507 if (!load_tzoffsets(newval, doit, elevel))
6514 * pg_timezone_abbrev_initialize --- set default value if not done already
6516 * This is called after initial loading of postgresql.conf. If no
6517 * timezone_abbreviations setting was found therein, select default.
6520 pg_timezone_abbrev_initialize(void)
6522 if (strcmp(timezone_abbreviations_string, "UNKNOWN") == 0)
6524 SetConfigOption("timezone_abbreviations", "Default",
6525 PGC_POSTMASTER, PGC_S_ARGV);
6530 assign_xmlbinary(const char *newval, bool doit, GucSource source)
6534 if (pg_strcasecmp(newval, "base64") == 0)
6535 xb = XMLBINARY_BASE64;
6536 else if (pg_strcasecmp(newval, "hex") == 0)
6539 return NULL; /* reject */
6548 assign_xmloption(const char *newval, bool doit, GucSource source)
6552 if (pg_strcasecmp(newval, "document") == 0)
6553 xo = XMLOPTION_DOCUMENT;
6554 else if (pg_strcasecmp(newval, "content") == 0)
6555 xo = XMLOPTION_CONTENT;
6557 return NULL; /* reject */
6566 assign_tcp_keepalives_idle(int newval, bool doit, GucSource source)
6569 return (pq_setkeepalivesidle(newval, MyProcPort) == STATUS_OK);
6575 show_tcp_keepalives_idle(void)
6577 static char nbuf[16];
6579 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesidle(MyProcPort));
6584 assign_tcp_keepalives_interval(int newval, bool doit, GucSource source)
6587 return (pq_setkeepalivesinterval(newval, MyProcPort) == STATUS_OK);
6593 show_tcp_keepalives_interval(void)
6595 static char nbuf[16];
6597 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesinterval(MyProcPort));
6602 assign_tcp_keepalives_count(int newval, bool doit, GucSource source)
6605 return (pq_setkeepalivescount(newval, MyProcPort) == STATUS_OK);
6611 show_tcp_keepalives_count(void)
6613 static char nbuf[16];
6615 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivescount(MyProcPort));
6620 #include "guc-file.c"