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.413 2007/08/19 01:41:25 adunstan 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/prepare.h"
36 #include "commands/vacuum.h"
37 #include "commands/variable.h"
38 #include "commands/trigger.h"
40 #include "libpq/auth.h"
41 #include "libpq/pqformat.h"
42 #include "miscadmin.h"
43 #include "optimizer/cost.h"
44 #include "optimizer/geqo.h"
45 #include "optimizer/paths.h"
46 #include "optimizer/planmain.h"
47 #include "parser/gramparse.h"
48 #include "parser/parse_expr.h"
49 #include "parser/parse_relation.h"
50 #include "parser/parse_type.h"
51 #include "parser/scansup.h"
53 #include "postmaster/autovacuum.h"
54 #include "postmaster/bgwriter.h"
55 #include "postmaster/postmaster.h"
56 #include "postmaster/syslogger.h"
57 #include "postmaster/walwriter.h"
58 #include "storage/fd.h"
59 #include "storage/freespace.h"
60 #include "tcop/tcopprot.h"
61 #include "utils/builtins.h"
62 #include "utils/guc_tables.h"
63 #include "utils/memutils.h"
64 #include "utils/pg_locale.h"
65 #include "utils/plancache.h"
66 #include "utils/portal.h"
67 #include "utils/ps_status.h"
68 #include "utils/tzparser.h"
69 #include "utils/xml.h"
72 #define PG_KRB_SRVTAB ""
75 #define PG_KRB_SRVNAM ""
78 #define CONFIG_FILENAME "postgresql.conf"
79 #define HBA_FILENAME "pg_hba.conf"
80 #define IDENT_FILENAME "pg_ident.conf"
83 #define CONFIG_EXEC_PARAMS "global/config_exec_params"
84 #define CONFIG_EXEC_PARAMS_NEW "global/config_exec_params.new"
87 /* upper limit for GUC variables measured in kilobytes of memory */
89 #define MAX_KILOBYTES INT_MAX
91 #define MAX_KILOBYTES (INT_MAX / 1024)
94 #define KB_PER_MB (1024)
95 #define KB_PER_GB (1024*1024)
99 #define MS_PER_MIN (1000 * 60)
101 #define S_PER_H (60 * 60)
102 #define MS_PER_H (1000 * 60 * 60)
103 #define MIN_PER_D (60 * 24)
104 #define S_PER_D (60 * 60 * 24)
105 #define MS_PER_D (1000 * 60 * 60 * 24)
107 /* XXX these should appear in other modules' header files */
108 extern bool Log_disconnections;
109 extern int CommitDelay;
110 extern int CommitSiblings;
111 extern char *default_tablespace;
112 extern char *temp_tablespaces;
113 extern bool fullPageWrites;
116 extern bool trace_sort;
118 #ifdef TRACE_SYNCSCAN
119 extern bool trace_syncscan;
121 #ifdef DEBUG_BOUNDED_SORT
122 extern bool optimize_bounded_sort;
126 extern char *SSLCipherSuites;
130 static const char *assign_log_destination(const char *value,
131 bool doit, GucSource source);
134 static int syslog_facility = LOG_LOCAL0;
136 static const char *assign_syslog_facility(const char *facility,
137 bool doit, GucSource source);
138 static const char *assign_syslog_ident(const char *ident,
139 bool doit, GucSource source);
142 static const char *assign_defaultxactisolevel(const char *newval, bool doit,
144 static const char *assign_session_replication_role(const char *newval, bool doit,
146 static const char *assign_log_min_messages(const char *newval, bool doit,
148 static const char *assign_client_min_messages(const char *newval,
149 bool doit, GucSource source);
150 static const char *assign_min_error_statement(const char *newval, bool doit,
152 static const char *assign_msglvl(int *var, const char *newval, bool doit,
154 static const char *assign_log_error_verbosity(const char *newval, bool doit,
156 static const char *assign_log_statement(const char *newval, bool doit,
158 static const char *show_num_temp_buffers(void);
159 static bool assign_phony_autocommit(bool newval, bool doit, GucSource source);
160 static const char *assign_custom_variable_classes(const char *newval, bool doit,
162 static bool assign_debug_assertions(bool newval, bool doit, GucSource source);
163 static bool assign_ssl(bool newval, bool doit, GucSource source);
164 static bool assign_stage_log_stats(bool newval, bool doit, GucSource source);
165 static bool assign_log_stats(bool newval, bool doit, GucSource source);
166 static bool assign_transaction_read_only(bool newval, bool doit, GucSource source);
167 static const char *assign_canonical_path(const char *newval, bool doit, GucSource source);
168 static const char *assign_backslash_quote(const char *newval, bool doit, GucSource source);
169 static const char *assign_timezone_abbreviations(const char *newval, bool doit, GucSource source);
170 static const char *assign_xmlbinary(const char *newval, bool doit, GucSource source);
171 static const char *assign_xmloption(const char *newval, bool doit, GucSource source);
173 static bool assign_tcp_keepalives_idle(int newval, bool doit, GucSource source);
174 static bool assign_tcp_keepalives_interval(int newval, bool doit, GucSource source);
175 static bool assign_tcp_keepalives_count(int newval, bool doit, GucSource source);
176 static const char *show_tcp_keepalives_idle(void);
177 static const char *show_tcp_keepalives_interval(void);
178 static const char *show_tcp_keepalives_count(void);
179 static bool assign_autovacuum_max_workers(int newval, bool doit, GucSource source);
180 static bool assign_maxconnections(int newval, bool doit, GucSource source);
183 * GUC option variables that are exported from this module
185 #ifdef USE_ASSERT_CHECKING
186 bool assert_enabled = true;
188 bool assert_enabled = false;
190 bool log_duration = false;
191 bool Debug_print_plan = false;
192 bool Debug_print_parse = false;
193 bool Debug_print_rewritten = false;
194 bool Debug_pretty_print = false;
195 bool Explain_pretty_print = true;
197 bool log_parser_stats = false;
198 bool log_planner_stats = false;
199 bool log_executor_stats = false;
200 bool log_statement_stats = false; /* this is sort of all three
202 bool log_btree_build_stats = false;
204 bool check_function_bodies = true;
205 bool default_with_oids = false;
206 bool SQL_inheritance = true;
208 bool Password_encryption = true;
210 int log_min_error_statement = ERROR;
211 int log_min_messages = NOTICE;
212 int client_min_messages = NOTICE;
213 int log_min_duration_statement = -1;
214 int log_temp_files = -1;
216 int num_temp_buffers = 1000;
218 char *ConfigFileName;
221 char *external_pid_file;
223 int tcp_keepalives_idle;
224 int tcp_keepalives_interval;
225 int tcp_keepalives_count;
228 * These variables are all dummies that don't do anything, except in some
229 * cases provide the value for SHOW to display. The real state is elsewhere
230 * and is kept in sync by assign_hooks.
232 static char *client_min_messages_str;
233 static char *log_min_messages_str;
234 static char *log_error_verbosity_str;
235 static char *log_statement_str;
236 static char *log_min_error_statement_str;
237 static char *log_destination_string;
240 static char *syslog_facility_str;
241 static char *syslog_ident_str;
243 static bool phony_autocommit;
244 static bool session_auth_is_superuser;
245 static double phony_random_seed;
246 static char *backslash_quote_string;
247 static char *client_encoding_string;
248 static char *datestyle_string;
249 static char *default_iso_level_string;
250 static char *session_replication_role_string;
251 static char *locale_collate;
252 static char *locale_ctype;
253 static char *regex_flavor_string;
254 static char *server_encoding_string;
255 static char *server_version_string;
256 static int server_version_num;
257 static char *timezone_string;
258 static char *log_timezone_string;
259 static char *timezone_abbreviations_string;
260 static char *XactIsoLevel_string;
261 static char *data_directory;
262 static char *custom_variable_classes;
263 static char *xmlbinary_string;
264 static char *xmloption_string;
265 static int max_function_args;
266 static int max_index_keys;
267 static int max_identifier_length;
268 static int block_size;
269 static bool integer_datetimes;
271 /* should be static, but commands/variable.c needs to get at these */
273 char *session_authorization_string;
277 * Displayable names for context types (enum GucContext)
279 * Note: these strings are deliberately not localized.
281 const char *const GucContext_Names[] =
283 /* PGC_INTERNAL */ "internal",
284 /* PGC_POSTMASTER */ "postmaster",
285 /* PGC_SIGHUP */ "sighup",
286 /* PGC_BACKEND */ "backend",
287 /* PGC_SUSET */ "superuser",
288 /* PGC_USERSET */ "user"
292 * Displayable names for source types (enum GucSource)
294 * Note: these strings are deliberately not localized.
296 const char *const GucSource_Names[] =
298 /* PGC_S_DEFAULT */ "default",
299 /* PGC_S_ENV_VAR */ "environment variable",
300 /* PGC_S_FILE */ "configuration file",
301 /* PGC_S_ARGV */ "command line",
302 /* PGC_S_DATABASE */ "database",
303 /* PGC_S_USER */ "user",
304 /* PGC_S_CLIENT */ "client",
305 /* PGC_S_OVERRIDE */ "override",
306 /* PGC_S_INTERACTIVE */ "interactive",
307 /* PGC_S_TEST */ "test",
308 /* PGC_S_SESSION */ "session"
312 * Displayable names for the groupings defined in enum config_group
314 const char *const config_group_names[] =
317 gettext_noop("Ungrouped"),
319 gettext_noop("File Locations"),
321 gettext_noop("Connections and Authentication"),
322 /* CONN_AUTH_SETTINGS */
323 gettext_noop("Connections and Authentication / Connection Settings"),
324 /* CONN_AUTH_SECURITY */
325 gettext_noop("Connections and Authentication / Security and Authentication"),
327 gettext_noop("Resource Usage"),
329 gettext_noop("Resource Usage / Memory"),
331 gettext_noop("Resource Usage / Free Space Map"),
332 /* RESOURCES_KERNEL */
333 gettext_noop("Resource Usage / Kernel Resources"),
335 gettext_noop("Write-Ahead Log"),
337 gettext_noop("Write-Ahead Log / Settings"),
338 /* WAL_CHECKPOINTS */
339 gettext_noop("Write-Ahead Log / Checkpoints"),
341 gettext_noop("Query Tuning"),
342 /* QUERY_TUNING_METHOD */
343 gettext_noop("Query Tuning / Planner Method Configuration"),
344 /* QUERY_TUNING_COST */
345 gettext_noop("Query Tuning / Planner Cost Constants"),
346 /* QUERY_TUNING_GEQO */
347 gettext_noop("Query Tuning / Genetic Query Optimizer"),
348 /* QUERY_TUNING_OTHER */
349 gettext_noop("Query Tuning / Other Planner Options"),
351 gettext_noop("Reporting and Logging"),
353 gettext_noop("Reporting and Logging / Where to Log"),
355 gettext_noop("Reporting and Logging / When to Log"),
357 gettext_noop("Reporting and Logging / What to Log"),
359 gettext_noop("Statistics"),
360 /* STATS_MONITORING */
361 gettext_noop("Statistics / Monitoring"),
362 /* STATS_COLLECTOR */
363 gettext_noop("Statistics / Query and Index Statistics Collector"),
365 gettext_noop("Autovacuum"),
367 gettext_noop("Client Connection Defaults"),
368 /* CLIENT_CONN_STATEMENT */
369 gettext_noop("Client Connection Defaults / Statement Behavior"),
370 /* CLIENT_CONN_LOCALE */
371 gettext_noop("Client Connection Defaults / Locale and Formatting"),
372 /* CLIENT_CONN_OTHER */
373 gettext_noop("Client Connection Defaults / Other Defaults"),
374 /* LOCK_MANAGEMENT */
375 gettext_noop("Lock Management"),
377 gettext_noop("Version and Platform Compatibility"),
378 /* COMPAT_OPTIONS_PREVIOUS */
379 gettext_noop("Version and Platform Compatibility / Previous PostgreSQL Versions"),
380 /* COMPAT_OPTIONS_CLIENT */
381 gettext_noop("Version and Platform Compatibility / Other Platforms and Clients"),
383 gettext_noop("Preset Options"),
385 gettext_noop("Customized Options"),
386 /* DEVELOPER_OPTIONS */
387 gettext_noop("Developer Options"),
388 /* help_config wants this array to be null-terminated */
393 * Displayable names for GUC variable types (enum config_type)
395 * Note: these strings are deliberately not localized.
397 const char *const config_type_names[] =
399 /* PGC_BOOL */ "bool",
400 /* PGC_INT */ "integer",
401 /* PGC_REAL */ "real",
402 /* PGC_STRING */ "string"
407 * Contents of GUC tables
409 * See src/backend/utils/misc/README for design notes.
413 * 1. Declare a global variable of type bool, int, double, or char*
414 * and make use of it.
416 * 2. Decide at what times it's safe to set the option. See guc.h for
419 * 3. Decide on a name, a default value, upper and lower bounds (if
422 * 4. Add a record below.
424 * 5. Add it to src/backend/utils/misc/postgresql.conf.sample, if
427 * 6. Don't forget to document the option.
429 * 7. If it's a new GUC_LIST option you must edit pg_dumpall.c to ensure
430 * it is not single quoted at dump time.
434 /******** option records follow ********/
436 static struct config_bool ConfigureNamesBool[] =
439 {"enable_seqscan", PGC_USERSET, QUERY_TUNING_METHOD,
440 gettext_noop("Enables the planner's use of sequential-scan plans."),
447 {"enable_indexscan", PGC_USERSET, QUERY_TUNING_METHOD,
448 gettext_noop("Enables the planner's use of index-scan plans."),
455 {"enable_bitmapscan", PGC_USERSET, QUERY_TUNING_METHOD,
456 gettext_noop("Enables the planner's use of bitmap-scan plans."),
463 {"enable_tidscan", PGC_USERSET, QUERY_TUNING_METHOD,
464 gettext_noop("Enables the planner's use of TID scan plans."),
471 {"enable_sort", PGC_USERSET, QUERY_TUNING_METHOD,
472 gettext_noop("Enables the planner's use of explicit sort steps."),
479 {"enable_hashagg", PGC_USERSET, QUERY_TUNING_METHOD,
480 gettext_noop("Enables the planner's use of hashed aggregation plans."),
487 {"enable_nestloop", PGC_USERSET, QUERY_TUNING_METHOD,
488 gettext_noop("Enables the planner's use of nested-loop join plans."),
495 {"enable_mergejoin", PGC_USERSET, QUERY_TUNING_METHOD,
496 gettext_noop("Enables the planner's use of merge join plans."),
503 {"enable_hashjoin", PGC_USERSET, QUERY_TUNING_METHOD,
504 gettext_noop("Enables the planner's use of hash join plans."),
511 {"constraint_exclusion", PGC_USERSET, QUERY_TUNING_OTHER,
512 gettext_noop("Enables the planner to use constraints to optimize queries."),
513 gettext_noop("Child table scans will be skipped if their "
514 "constraints guarantee that no rows match the query.")
516 &constraint_exclusion,
520 {"geqo", PGC_USERSET, QUERY_TUNING_GEQO,
521 gettext_noop("Enables genetic query optimization."),
522 gettext_noop("This algorithm attempts to do planning without "
523 "exhaustive searching.")
529 /* Not for general use --- used by SET SESSION AUTHORIZATION */
530 {"is_superuser", PGC_INTERNAL, UNGROUPED,
531 gettext_noop("Shows whether the current user is a superuser."),
533 GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
535 &session_auth_is_superuser,
539 {"ssl", PGC_POSTMASTER, CONN_AUTH_SECURITY,
540 gettext_noop("Enables SSL connections."),
544 false, assign_ssl, NULL
547 {"fsync", PGC_SIGHUP, WAL_SETTINGS,
548 gettext_noop("Forces synchronization of updates to disk."),
549 gettext_noop("The server will use the fsync() system call in several places to make "
550 "sure that updates are physically written to disk. This insures "
551 "that a database cluster will recover to a consistent state after "
552 "an operating system or hardware crash.")
558 {"synchronous_commit", PGC_USERSET, WAL_SETTINGS,
559 gettext_noop("Sets immediate fsync at commit."),
563 /* XXX TEMPORARY FOR TESTING: sync commit should default to TRUE! */
567 {"zero_damaged_pages", PGC_SUSET, DEVELOPER_OPTIONS,
568 gettext_noop("Continues processing past damaged page headers."),
569 gettext_noop("Detection of a damaged page header normally causes PostgreSQL to "
570 "report an error, aborting the current transaction. Setting "
571 "zero_damaged_pages to true causes the system to instead report a "
572 "warning, zero out the damaged page, and continue processing. This "
573 "behavior will destroy data, namely all the rows on the damaged page."),
580 {"full_page_writes", PGC_SIGHUP, WAL_SETTINGS,
581 gettext_noop("Writes full pages to WAL when first modified after a checkpoint."),
582 gettext_noop("A page write in process during an operating system crash might be "
583 "only partially written to disk. During recovery, the row changes "
584 "stored in WAL are not enough to recover. This option writes "
585 "pages when first modified after a checkpoint to WAL so full recovery "
592 {"silent_mode", PGC_POSTMASTER, LOGGING_WHEN,
593 gettext_noop("Runs the server silently."),
594 gettext_noop("If this parameter is set, the server will automatically run in the "
595 "background and any controlling terminals are dissociated.")
601 {"log_checkpoints", PGC_SIGHUP, LOGGING_WHAT,
602 gettext_noop("Logs each checkpoint."),
609 {"log_connections", PGC_BACKEND, LOGGING_WHAT,
610 gettext_noop("Logs each successful connection."),
617 {"log_disconnections", PGC_BACKEND, LOGGING_WHAT,
618 gettext_noop("Logs end of a session, including duration."),
625 {"debug_assertions", PGC_USERSET, DEVELOPER_OPTIONS,
626 gettext_noop("Turns on various assertion checks."),
627 gettext_noop("This is a debugging aid."),
631 #ifdef USE_ASSERT_CHECKING
636 assign_debug_assertions, NULL
639 /* currently undocumented, so don't show in SHOW ALL */
640 {"exit_on_error", PGC_USERSET, UNGROUPED,
641 gettext_noop("No description available."),
643 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
649 {"log_duration", PGC_SUSET, LOGGING_WHAT,
650 gettext_noop("Logs the duration of each completed SQL statement."),
657 {"debug_print_parse", PGC_USERSET, LOGGING_WHAT,
658 gettext_noop("Prints the parse tree to the server log."),
665 {"debug_print_rewritten", PGC_USERSET, LOGGING_WHAT,
666 gettext_noop("Prints the parse tree after rewriting to server log."),
669 &Debug_print_rewritten,
673 {"debug_print_plan", PGC_USERSET, LOGGING_WHAT,
674 gettext_noop("Prints the execution plan to server log."),
681 {"debug_pretty_print", PGC_USERSET, LOGGING_WHAT,
682 gettext_noop("Indents parse and plan tree displays."),
689 {"log_parser_stats", PGC_SUSET, STATS_MONITORING,
690 gettext_noop("Writes parser performance statistics to the server log."),
694 false, assign_stage_log_stats, NULL
697 {"log_planner_stats", PGC_SUSET, STATS_MONITORING,
698 gettext_noop("Writes planner performance statistics to the server log."),
702 false, assign_stage_log_stats, NULL
705 {"log_executor_stats", PGC_SUSET, STATS_MONITORING,
706 gettext_noop("Writes executor performance statistics to the server log."),
710 false, assign_stage_log_stats, NULL
713 {"log_statement_stats", PGC_SUSET, STATS_MONITORING,
714 gettext_noop("Writes cumulative performance statistics to the server log."),
717 &log_statement_stats,
718 false, assign_log_stats, NULL
720 #ifdef BTREE_BUILD_STATS
722 {"log_btree_build_stats", PGC_SUSET, DEVELOPER_OPTIONS,
723 gettext_noop("No description available."),
727 &log_btree_build_stats,
733 {"explain_pretty_print", PGC_USERSET, CLIENT_CONN_OTHER,
734 gettext_noop("Uses the indented output format for EXPLAIN VERBOSE."),
737 &Explain_pretty_print,
741 {"stats_start_collector", PGC_POSTMASTER, STATS_COLLECTOR,
742 gettext_noop("Starts the server statistics-collection subprocess."),
745 &pgstat_collect_startcollector,
749 {"stats_reset_on_server_start", PGC_POSTMASTER, STATS_COLLECTOR,
750 gettext_noop("Zeroes collected statistics on server restart."),
753 &pgstat_collect_resetonpmstart,
757 {"stats_row_level", PGC_SUSET, STATS_COLLECTOR,
758 gettext_noop("Collects row-level statistics on database activity."),
761 &pgstat_collect_tuplelevel,
765 {"stats_block_level", PGC_SUSET, STATS_COLLECTOR,
766 gettext_noop("Collects block-level statistics on database activity."),
769 &pgstat_collect_blocklevel,
774 {"stats_command_string", PGC_SUSET, STATS_COLLECTOR,
775 gettext_noop("Collects information about executing commands."),
776 gettext_noop("Enables the collection of information on the currently "
777 "executing command of each session, along with the time "
778 "at which that command began execution.")
780 &pgstat_collect_querystring,
785 {"update_process_title", PGC_SUSET, STATS_COLLECTOR,
786 gettext_noop("Updates the process title to show the active SQL command."),
787 gettext_noop("Enables updating of the process title every time a new SQL command is received by the server.")
789 &update_process_title,
794 {"autovacuum", PGC_SIGHUP, AUTOVACUUM,
795 gettext_noop("Starts the autovacuum subprocess."),
798 &autovacuum_start_daemon,
803 {"trace_notify", PGC_USERSET, DEVELOPER_OPTIONS,
804 gettext_noop("Generates debugging output for LISTEN and NOTIFY."),
814 {"trace_locks", PGC_SUSET, DEVELOPER_OPTIONS,
815 gettext_noop("No description available."),
823 {"trace_userlocks", PGC_SUSET, DEVELOPER_OPTIONS,
824 gettext_noop("No description available."),
832 {"trace_lwlocks", PGC_SUSET, DEVELOPER_OPTIONS,
833 gettext_noop("No description available."),
841 {"debug_deadlocks", PGC_SUSET, DEVELOPER_OPTIONS,
842 gettext_noop("No description available."),
852 {"log_lock_waits", PGC_SUSET, LOGGING_WHAT,
853 gettext_noop("Logs long lock waits."),
861 {"log_hostname", PGC_SIGHUP, LOGGING_WHAT,
862 gettext_noop("Logs the host name in the connection logs."),
863 gettext_noop("By default, connection logs only show the IP address "
864 "of the connecting host. If you want them to show the host name you "
865 "can turn this on, but depending on your host name resolution "
866 "setup it might impose a non-negligible performance penalty.")
872 {"sql_inheritance", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
873 gettext_noop("Causes subtables to be included by default in various commands."),
880 {"password_encryption", PGC_USERSET, CONN_AUTH_SECURITY,
881 gettext_noop("Encrypt passwords."),
882 gettext_noop("When a password is specified in CREATE USER or "
883 "ALTER USER without writing either ENCRYPTED or UNENCRYPTED, "
884 "this parameter determines whether the password is to be encrypted.")
886 &Password_encryption,
890 {"transform_null_equals", PGC_USERSET, COMPAT_OPTIONS_CLIENT,
891 gettext_noop("Treats \"expr=NULL\" as \"expr IS NULL\"."),
892 gettext_noop("When turned on, expressions of the form expr = NULL "
893 "(or NULL = expr) are treated as expr IS NULL, that is, they "
894 "return true if expr evaluates to the null value, and false "
895 "otherwise. The correct behavior of expr = NULL is to always "
896 "return null (unknown).")
898 &Transform_null_equals,
902 {"db_user_namespace", PGC_SIGHUP, CONN_AUTH_SECURITY,
903 gettext_noop("Enables per-database user names."),
910 /* only here for backwards compatibility */
911 {"autocommit", PGC_USERSET, CLIENT_CONN_STATEMENT,
912 gettext_noop("This parameter doesn't do anything."),
913 gettext_noop("It's just here so that we won't choke on SET AUTOCOMMIT TO ON from 7.3-vintage clients."),
914 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
917 true, assign_phony_autocommit, NULL
920 {"default_transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
921 gettext_noop("Sets the default read-only status of new transactions."),
924 &DefaultXactReadOnly,
928 {"transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
929 gettext_noop("Sets the current transaction's read-only status."),
931 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
934 false, assign_transaction_read_only, NULL
937 {"add_missing_from", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
938 gettext_noop("Automatically adds missing table references to FROM clauses."),
945 {"check_function_bodies", PGC_USERSET, CLIENT_CONN_STATEMENT,
946 gettext_noop("Check function bodies during CREATE FUNCTION."),
949 &check_function_bodies,
953 {"array_nulls", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
954 gettext_noop("Enable input of NULL elements in arrays."),
955 gettext_noop("When turned on, unquoted NULL in an array input "
956 "value means a null value; "
957 "otherwise it is taken literally.")
963 {"default_with_oids", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
964 gettext_noop("Create new tables with OIDs by default."),
971 {"logging_collector", PGC_POSTMASTER, LOGGING_WHERE,
972 gettext_noop("Start a subprocess to capture stderr output and/or csvlogs into log files."),
979 {"log_truncate_on_rotation", PGC_SIGHUP, LOGGING_WHERE,
980 gettext_noop("Truncate existing log files of same name during log rotation."),
983 &Log_truncate_on_rotation,
989 {"trace_sort", PGC_USERSET, DEVELOPER_OPTIONS,
990 gettext_noop("Emit information about resource usage in sorting."),
999 #ifdef TRACE_SYNCSCAN
1000 /* this is undocumented because not exposed in a standard build */
1002 {"trace_syncscan", PGC_USERSET, DEVELOPER_OPTIONS,
1003 gettext_noop("Generate debugging output for synchronized scanning."),
1012 #ifdef DEBUG_BOUNDED_SORT
1013 /* this is undocumented because not exposed in a standard build */
1016 "optimize_bounded_sort", PGC_USERSET, QUERY_TUNING_METHOD,
1017 gettext_noop("Enable bounded sorting using heap sort."),
1021 &optimize_bounded_sort,
1028 {"wal_debug", PGC_SUSET, DEVELOPER_OPTIONS,
1029 gettext_noop("Emit WAL-related debugging output."),
1039 {"integer_datetimes", PGC_INTERNAL, PRESET_OPTIONS,
1040 gettext_noop("Datetimes are integer based."),
1042 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1045 #ifdef HAVE_INT64_TIMESTAMP
1053 {"krb_caseins_users", PGC_POSTMASTER, CONN_AUTH_SECURITY,
1054 gettext_noop("Sets whether Kerberos and GSSAPI user names should be treated as case-insensitive."),
1057 &pg_krb_caseins_users,
1062 {"escape_string_warning", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1063 gettext_noop("Warn about backslash escapes in ordinary string literals."),
1066 &escape_string_warning,
1071 {"standard_conforming_strings", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1072 gettext_noop("Causes '...' strings to treat backslashes literally."),
1076 &standard_conforming_strings,
1081 {"allow_system_table_mods", PGC_POSTMASTER, DEVELOPER_OPTIONS,
1082 gettext_noop("Allows modifications of the structure of system tables."),
1086 &allowSystemTableMods,
1091 {"ignore_system_indexes", PGC_BACKEND, DEVELOPER_OPTIONS,
1092 gettext_noop("Disables reading from system indexes."),
1093 gettext_noop("It does not prevent updating the indexes, so it is safe "
1094 "to use. The worst consequence is slowness."),
1097 &IgnoreSystemIndexes,
1101 /* End-of-list marker */
1103 {NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL
1108 static struct config_int ConfigureNamesInt[] =
1111 {"archive_timeout", PGC_SIGHUP, WAL_SETTINGS,
1112 gettext_noop("Forces a switch to the next xlog file if a "
1113 "new file has not been started within N seconds."),
1117 &XLogArchiveTimeout,
1118 0, 0, INT_MAX, NULL, NULL
1121 {"post_auth_delay", PGC_BACKEND, DEVELOPER_OPTIONS,
1122 gettext_noop("Waits N seconds on connection startup after authentication."),
1123 gettext_noop("This allows attaching a debugger to the process."),
1124 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1127 0, 0, INT_MAX, NULL, NULL
1130 {"default_statistics_target", PGC_USERSET, QUERY_TUNING_OTHER,
1131 gettext_noop("Sets the default statistics target."),
1132 gettext_noop("This applies to table columns that have not had a "
1133 "column-specific target set via ALTER TABLE SET STATISTICS.")
1135 &default_statistics_target,
1136 10, 1, 1000, NULL, NULL
1139 {"from_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1140 gettext_noop("Sets the FROM-list size beyond which subqueries "
1141 "are not collapsed."),
1142 gettext_noop("The planner will merge subqueries into upper "
1143 "queries if the resulting FROM list would have no more than "
1146 &from_collapse_limit,
1147 8, 1, INT_MAX, NULL, NULL
1150 {"join_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1151 gettext_noop("Sets the FROM-list size beyond which JOIN "
1152 "constructs are not flattened."),
1153 gettext_noop("The planner will flatten explicit JOIN "
1154 "constructs into lists of FROM items whenever a "
1155 "list of no more than this many items would result.")
1157 &join_collapse_limit,
1158 8, 1, INT_MAX, NULL, NULL
1161 {"geqo_threshold", PGC_USERSET, QUERY_TUNING_GEQO,
1162 gettext_noop("Sets the threshold of FROM items beyond which GEQO is used."),
1166 12, 2, INT_MAX, NULL, NULL
1169 {"geqo_effort", PGC_USERSET, QUERY_TUNING_GEQO,
1170 gettext_noop("GEQO: effort is used to set the default for other GEQO parameters."),
1174 DEFAULT_GEQO_EFFORT, MIN_GEQO_EFFORT, MAX_GEQO_EFFORT, NULL, NULL
1177 {"geqo_pool_size", PGC_USERSET, QUERY_TUNING_GEQO,
1178 gettext_noop("GEQO: number of individuals in the population."),
1179 gettext_noop("Zero selects a suitable default value.")
1182 0, 0, INT_MAX, NULL, NULL
1185 {"geqo_generations", PGC_USERSET, QUERY_TUNING_GEQO,
1186 gettext_noop("GEQO: number of iterations of the algorithm."),
1187 gettext_noop("Zero selects a suitable default value.")
1190 0, 0, INT_MAX, NULL, NULL
1194 {"deadlock_timeout", PGC_SIGHUP, LOCK_MANAGEMENT,
1195 gettext_noop("Sets the time to wait on a lock before checking for deadlock."),
1200 1000, 1, INT_MAX/1000, NULL, NULL
1204 * Note: There is some postprocessing done in PostmasterMain() to make
1205 * sure the buffers are at least twice the number of backends, so the
1206 * constraints here are partially unused. Similarly, the superuser
1207 * reserved number is checked to ensure it is less than the max backends
1210 * MaxBackends is limited to INT_MAX/4 because some places compute
1211 * 4*MaxBackends without any overflow check. This check is made on
1212 * assign_maxconnections, since MaxBackends is computed as MaxConnections +
1213 * autovacuum_max_workers.
1215 * Likewise we have to limit NBuffers to INT_MAX/2.
1218 {"max_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1219 gettext_noop("Sets the maximum number of concurrent connections."),
1223 100, 1, INT_MAX / 4, assign_maxconnections, NULL
1227 {"superuser_reserved_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1228 gettext_noop("Sets the number of connection slots reserved for superusers."),
1232 3, 0, INT_MAX / 4, NULL, NULL
1236 {"shared_buffers", PGC_POSTMASTER, RESOURCES_MEM,
1237 gettext_noop("Sets the number of shared memory buffers used by the server."),
1242 1024, 16, INT_MAX / 2, NULL, NULL
1246 {"temp_buffers", PGC_USERSET, RESOURCES_MEM,
1247 gettext_noop("Sets the maximum number of temporary buffers used by each session."),
1252 1024, 100, INT_MAX / 2, NULL, show_num_temp_buffers
1256 {"port", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1257 gettext_noop("Sets the TCP port the server listens on."),
1261 DEF_PGPORT, 1, 65535, NULL, NULL
1265 {"unix_socket_permissions", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1266 gettext_noop("Sets the access permissions of the Unix-domain socket."),
1267 gettext_noop("Unix-domain sockets use the usual Unix file system "
1268 "permission set. The parameter value is expected to be an numeric mode "
1269 "specification in the form accepted by the chmod and umask system "
1270 "calls. (To use the customary octal format the number must start with "
1273 &Unix_socket_permissions,
1274 0777, 0000, 0777, NULL, NULL
1278 {"work_mem", PGC_USERSET, RESOURCES_MEM,
1279 gettext_noop("Sets the maximum memory to be used for query workspaces."),
1280 gettext_noop("This much memory can be used by each internal "
1281 "sort operation and hash table before switching to "
1282 "temporary disk files."),
1286 1024, 8 * BLCKSZ / 1024, MAX_KILOBYTES, NULL, NULL
1290 {"maintenance_work_mem", PGC_USERSET, RESOURCES_MEM,
1291 gettext_noop("Sets the maximum memory to be used for maintenance operations."),
1292 gettext_noop("This includes operations such as VACUUM and CREATE INDEX."),
1295 &maintenance_work_mem,
1296 16384, 1024, MAX_KILOBYTES, NULL, NULL
1300 {"max_stack_depth", PGC_SUSET, RESOURCES_MEM,
1301 gettext_noop("Sets the maximum stack depth, in kilobytes."),
1306 100, 100, MAX_KILOBYTES, assign_max_stack_depth, NULL
1310 {"vacuum_cost_page_hit", PGC_USERSET, RESOURCES,
1311 gettext_noop("Vacuum cost for a page found in the buffer cache."),
1315 1, 0, 10000, NULL, NULL
1319 {"vacuum_cost_page_miss", PGC_USERSET, RESOURCES,
1320 gettext_noop("Vacuum cost for a page not found in the buffer cache."),
1323 &VacuumCostPageMiss,
1324 10, 0, 10000, NULL, NULL
1328 {"vacuum_cost_page_dirty", PGC_USERSET, RESOURCES,
1329 gettext_noop("Vacuum cost for a page dirtied by vacuum."),
1332 &VacuumCostPageDirty,
1333 20, 0, 10000, NULL, NULL
1337 {"vacuum_cost_limit", PGC_USERSET, RESOURCES,
1338 gettext_noop("Vacuum cost amount available before napping."),
1342 200, 1, 10000, NULL, NULL
1346 {"vacuum_cost_delay", PGC_USERSET, RESOURCES,
1347 gettext_noop("Vacuum cost delay in milliseconds."),
1352 0, 0, 1000, NULL, NULL
1356 {"autovacuum_vacuum_cost_delay", PGC_SIGHUP, AUTOVACUUM,
1357 gettext_noop("Vacuum cost delay in milliseconds, for autovacuum."),
1361 &autovacuum_vac_cost_delay,
1362 20, -1, 1000, NULL, NULL
1366 {"autovacuum_vacuum_cost_limit", PGC_SIGHUP, AUTOVACUUM,
1367 gettext_noop("Vacuum cost amount available before napping, for autovacuum."),
1370 &autovacuum_vac_cost_limit,
1371 -1, -1, 10000, NULL, NULL
1375 {"max_files_per_process", PGC_POSTMASTER, RESOURCES_KERNEL,
1376 gettext_noop("Sets the maximum number of simultaneously open files for each server process."),
1379 &max_files_per_process,
1380 1000, 25, INT_MAX, NULL, NULL
1384 {"max_prepared_transactions", PGC_POSTMASTER, RESOURCES,
1385 gettext_noop("Sets the maximum number of simultaneously prepared transactions."),
1388 &max_prepared_xacts,
1389 5, 0, INT_MAX, NULL, NULL
1394 {"trace_lock_oidmin", PGC_SUSET, DEVELOPER_OPTIONS,
1395 gettext_noop("No description available."),
1400 FirstNormalObjectId, 0, INT_MAX, NULL, NULL
1403 {"trace_lock_table", PGC_SUSET, DEVELOPER_OPTIONS,
1404 gettext_noop("No description available."),
1409 0, 0, INT_MAX, NULL, NULL
1414 {"statement_timeout", PGC_USERSET, CLIENT_CONN_STATEMENT,
1415 gettext_noop("Sets the maximum allowed duration of any statement."),
1416 gettext_noop("A value of 0 turns off the timeout."),
1420 0, 0, INT_MAX, NULL, NULL
1424 {"vacuum_freeze_min_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1425 gettext_noop("Minimum age at which VACUUM should freeze a table row."),
1428 &vacuum_freeze_min_age,
1429 100000000, 0, 1000000000, NULL, NULL
1433 {"max_fsm_relations", PGC_POSTMASTER, RESOURCES_FSM,
1434 gettext_noop("Sets the maximum number of tables and indexes for which free space is tracked."),
1438 1000, 100, INT_MAX, NULL, NULL
1441 {"max_fsm_pages", PGC_POSTMASTER, RESOURCES_FSM,
1442 gettext_noop("Sets the maximum number of disk pages for which free space is tracked."),
1446 20000, 1000, INT_MAX, NULL, NULL
1450 {"max_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
1451 gettext_noop("Sets the maximum number of locks per transaction."),
1452 gettext_noop("The shared lock table is sized on the assumption that "
1453 "at most max_locks_per_transaction * max_connections distinct "
1454 "objects will need to be locked at any one time.")
1456 &max_locks_per_xact,
1457 64, 10, INT_MAX, NULL, NULL
1461 {"authentication_timeout", PGC_SIGHUP, CONN_AUTH_SECURITY,
1462 gettext_noop("Sets the maximum allowed time to complete client authentication."),
1466 &AuthenticationTimeout,
1467 60, 1, 600, NULL, NULL
1471 /* Not for general use */
1472 {"pre_auth_delay", PGC_SIGHUP, DEVELOPER_OPTIONS,
1473 gettext_noop("Waits N seconds on connection startup before authentication."),
1474 gettext_noop("This allows attaching a debugger to the process."),
1475 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1478 0, 0, 60, NULL, NULL
1482 {"checkpoint_segments", PGC_SIGHUP, WAL_CHECKPOINTS,
1483 gettext_noop("Sets the maximum distance in log segments between automatic WAL checkpoints."),
1486 &CheckPointSegments,
1487 3, 1, INT_MAX, NULL, NULL
1491 {"checkpoint_timeout", PGC_SIGHUP, WAL_CHECKPOINTS,
1492 gettext_noop("Sets the maximum time between automatic WAL checkpoints."),
1497 300, 30, 3600, NULL, NULL
1501 {"checkpoint_warning", PGC_SIGHUP, WAL_CHECKPOINTS,
1502 gettext_noop("Enables warnings if checkpoint segments are filled more "
1503 "frequently than this."),
1504 gettext_noop("Write a message to the server log if checkpoints "
1505 "caused by the filling of checkpoint segment files happens more "
1506 "frequently than this number of seconds. Zero turns off the warning."),
1510 30, 0, INT_MAX, NULL, NULL
1514 {"wal_buffers", PGC_POSTMASTER, WAL_SETTINGS,
1515 gettext_noop("Sets the number of disk-page buffers in shared memory for WAL."),
1520 8, 4, INT_MAX, NULL, NULL
1524 {"wal_writer_delay", PGC_SIGHUP, WAL_SETTINGS,
1525 gettext_noop("WAL writer sleep time between WAL flushes."),
1530 200, 1, 10000, NULL, NULL
1534 {"commit_delay", PGC_USERSET, WAL_SETTINGS,
1535 gettext_noop("Sets the delay in microseconds between transaction commit and "
1536 "flushing WAL to disk."),
1540 0, 0, 100000, NULL, NULL
1544 {"commit_siblings", PGC_USERSET, WAL_SETTINGS,
1545 gettext_noop("Sets the minimum concurrent open transactions before performing "
1550 5, 1, 1000, NULL, NULL
1554 {"extra_float_digits", PGC_USERSET, CLIENT_CONN_LOCALE,
1555 gettext_noop("Sets the number of digits displayed for floating-point values."),
1556 gettext_noop("This affects real, double precision, and geometric data types. "
1557 "The parameter value is added to the standard number of digits "
1558 "(FLT_DIG or DBL_DIG as appropriate).")
1560 &extra_float_digits,
1561 0, -15, 2, NULL, NULL
1565 {"log_min_duration_statement", PGC_SUSET, LOGGING_WHEN,
1566 gettext_noop("Sets the minimum execution time above which statements will "
1568 gettext_noop("Zero prints all queries. The default is -1 (turning this feature off)."),
1571 &log_min_duration_statement,
1572 -1, -1, INT_MAX / 1000, NULL, NULL
1576 {"log_autovacuum", PGC_BACKEND, LOGGING_WHAT,
1577 gettext_noop("Sets the minimum execution time above which autovacuum actions "
1579 gettext_noop("Zero prints all actions. The default is -1 (turning this feature off)."),
1583 -1, -1, INT_MAX / 1000, NULL, NULL
1587 {"bgwriter_delay", PGC_SIGHUP, RESOURCES,
1588 gettext_noop("Background writer sleep time between rounds."),
1593 200, 10, 10000, NULL, NULL
1597 {"bgwriter_lru_maxpages", PGC_SIGHUP, RESOURCES,
1598 gettext_noop("Background writer maximum number of LRU pages to flush per round."),
1601 &bgwriter_lru_maxpages,
1602 5, 0, 1000, NULL, NULL
1606 {"log_rotation_age", PGC_SIGHUP, LOGGING_WHERE,
1607 gettext_noop("Automatic log file rotation will occur after N minutes."),
1612 HOURS_PER_DAY * MINS_PER_HOUR, 0, INT_MAX / MINS_PER_HOUR, NULL, NULL
1616 {"log_rotation_size", PGC_SIGHUP, LOGGING_WHERE,
1617 gettext_noop("Automatic log file rotation will occur after N kilobytes."),
1622 10 * 1024, 0, INT_MAX / 1024, NULL, NULL
1626 {"max_function_args", PGC_INTERNAL, PRESET_OPTIONS,
1627 gettext_noop("Shows the maximum number of function arguments."),
1629 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1632 FUNC_MAX_ARGS, FUNC_MAX_ARGS, FUNC_MAX_ARGS, NULL, NULL
1636 {"max_index_keys", PGC_INTERNAL, PRESET_OPTIONS,
1637 gettext_noop("Shows the maximum number of index keys."),
1639 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1642 INDEX_MAX_KEYS, INDEX_MAX_KEYS, INDEX_MAX_KEYS, NULL, NULL
1646 {"max_identifier_length", PGC_INTERNAL, PRESET_OPTIONS,
1647 gettext_noop("Shows the maximum identifier length."),
1649 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1651 &max_identifier_length,
1652 NAMEDATALEN - 1, NAMEDATALEN - 1, NAMEDATALEN - 1, NULL, NULL
1656 {"block_size", PGC_INTERNAL, PRESET_OPTIONS,
1657 gettext_noop("Shows the size of a disk block."),
1659 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1662 BLCKSZ, BLCKSZ, BLCKSZ, NULL, NULL
1666 {"autovacuum_naptime", PGC_SIGHUP, AUTOVACUUM,
1667 gettext_noop("Time to sleep between autovacuum runs."),
1671 &autovacuum_naptime,
1672 60, 1, INT_MAX / 1000, NULL, NULL
1675 {"autovacuum_vacuum_threshold", PGC_SIGHUP, AUTOVACUUM,
1676 gettext_noop("Minimum number of tuple updates or deletes prior to vacuum."),
1679 &autovacuum_vac_thresh,
1680 50, 0, INT_MAX, NULL, NULL
1683 {"autovacuum_analyze_threshold", PGC_SIGHUP, AUTOVACUUM,
1684 gettext_noop("Minimum number of tuple inserts, updates or deletes prior to analyze."),
1687 &autovacuum_anl_thresh,
1688 50, 0, INT_MAX, NULL, NULL
1691 /* see varsup.c for why this is PGC_POSTMASTER not PGC_SIGHUP */
1692 {"autovacuum_freeze_max_age", PGC_POSTMASTER, AUTOVACUUM,
1693 gettext_noop("Age at which to autovacuum a table to prevent transaction ID wraparound."),
1696 &autovacuum_freeze_max_age,
1697 200000000, 100000000, 2000000000, NULL, NULL
1700 /* see max_connections */
1701 {"autovacuum_max_workers", PGC_POSTMASTER, AUTOVACUUM,
1702 gettext_noop("Sets the maximum number of simultaneously running autovacuum worker processes."),
1705 &autovacuum_max_workers,
1706 3, 1, INT_MAX / 4, assign_autovacuum_max_workers, NULL
1710 {"tcp_keepalives_idle", PGC_USERSET, CLIENT_CONN_OTHER,
1711 gettext_noop("Time between issuing TCP keepalives."),
1712 gettext_noop("A value of 0 uses the system default."),
1715 &tcp_keepalives_idle,
1716 0, 0, INT_MAX, assign_tcp_keepalives_idle, show_tcp_keepalives_idle
1720 {"tcp_keepalives_interval", PGC_USERSET, CLIENT_CONN_OTHER,
1721 gettext_noop("Time between TCP keepalive retransmits."),
1722 gettext_noop("A value of 0 uses the system default."),
1725 &tcp_keepalives_interval,
1726 0, 0, INT_MAX, assign_tcp_keepalives_interval, show_tcp_keepalives_interval
1730 {"tcp_keepalives_count", PGC_USERSET, CLIENT_CONN_OTHER,
1731 gettext_noop("Maximum number of TCP keepalive retransmits."),
1732 gettext_noop("This controls the number of consecutive keepalive retransmits that can be "
1733 "lost before a connection is considered dead. A value of 0 uses the "
1736 &tcp_keepalives_count,
1737 0, 0, INT_MAX, assign_tcp_keepalives_count, show_tcp_keepalives_count
1741 {"gin_fuzzy_search_limit", PGC_USERSET, CLIENT_CONN_OTHER,
1742 gettext_noop("Sets the maximum allowed result for exact search by GIN."),
1746 &GinFuzzySearchLimit,
1747 0, 0, INT_MAX, NULL, NULL
1751 {"effective_cache_size", PGC_USERSET, QUERY_TUNING_COST,
1752 gettext_noop("Sets the planner's assumption about the size of the disk cache."),
1753 gettext_noop("That is, the portion of the kernel's disk cache that "
1754 "will be used for PostgreSQL data files. This is measured in disk "
1755 "pages, which are normally 8 kB each."),
1758 &effective_cache_size,
1759 DEFAULT_EFFECTIVE_CACHE_SIZE, 1, INT_MAX, NULL, NULL
1763 /* Can't be set in postgresql.conf */
1764 {"server_version_num", PGC_INTERNAL, PRESET_OPTIONS,
1765 gettext_noop("Shows the server version as an integer."),
1767 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1769 &server_version_num,
1770 PG_VERSION_NUM, PG_VERSION_NUM, PG_VERSION_NUM, NULL, NULL
1774 {"log_temp_files", PGC_USERSET, LOGGING_WHAT,
1775 gettext_noop("Log the use of temporary files larger than this number of kilobytes."),
1776 gettext_noop("Zero logs all files. The default is -1 (turning this feature off)."),
1780 -1, -1, INT_MAX, NULL, NULL
1783 /* End-of-list marker */
1785 {NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL
1790 static struct config_real ConfigureNamesReal[] =
1793 {"seq_page_cost", PGC_USERSET, QUERY_TUNING_COST,
1794 gettext_noop("Sets the planner's estimate of the cost of a "
1795 "sequentially fetched disk page."),
1799 DEFAULT_SEQ_PAGE_COST, 0, DBL_MAX, NULL, NULL
1802 {"random_page_cost", PGC_USERSET, QUERY_TUNING_COST,
1803 gettext_noop("Sets the planner's estimate of the cost of a "
1804 "nonsequentially fetched disk page."),
1808 DEFAULT_RANDOM_PAGE_COST, 0, DBL_MAX, NULL, NULL
1811 {"cpu_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
1812 gettext_noop("Sets the planner's estimate of the cost of "
1813 "processing each tuple (row)."),
1817 DEFAULT_CPU_TUPLE_COST, 0, DBL_MAX, NULL, NULL
1820 {"cpu_index_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
1821 gettext_noop("Sets the planner's estimate of the cost of "
1822 "processing each index entry during an index scan."),
1825 &cpu_index_tuple_cost,
1826 DEFAULT_CPU_INDEX_TUPLE_COST, 0, DBL_MAX, NULL, NULL
1829 {"cpu_operator_cost", PGC_USERSET, QUERY_TUNING_COST,
1830 gettext_noop("Sets the planner's estimate of the cost of "
1831 "processing each operator or function call."),
1835 DEFAULT_CPU_OPERATOR_COST, 0, DBL_MAX, NULL, NULL
1839 {"geqo_selection_bias", PGC_USERSET, QUERY_TUNING_GEQO,
1840 gettext_noop("GEQO: selective pressure within the population."),
1843 &Geqo_selection_bias,
1844 DEFAULT_GEQO_SELECTION_BIAS, MIN_GEQO_SELECTION_BIAS,
1845 MAX_GEQO_SELECTION_BIAS, NULL, NULL
1849 {"bgwriter_lru_percent", PGC_SIGHUP, RESOURCES,
1850 gettext_noop("Background writer percentage of LRU buffers to flush per round."),
1853 &bgwriter_lru_percent,
1854 1.0, 0.0, 100.0, NULL, NULL
1858 {"seed", PGC_USERSET, UNGROUPED,
1859 gettext_noop("Sets the seed for random-number generation."),
1861 GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1864 0.5, 0.0, 1.0, assign_random_seed, show_random_seed
1868 {"autovacuum_vacuum_scale_factor", PGC_SIGHUP, AUTOVACUUM,
1869 gettext_noop("Number of tuple updates or deletes prior to vacuum as a fraction of reltuples."),
1872 &autovacuum_vac_scale,
1873 0.2, 0.0, 100.0, NULL, NULL
1876 {"autovacuum_analyze_scale_factor", PGC_SIGHUP, AUTOVACUUM,
1877 gettext_noop("Number of tuple inserts, updates or deletes prior to analyze as a fraction of reltuples."),
1880 &autovacuum_anl_scale,
1881 0.1, 0.0, 100.0, NULL, NULL
1885 {"checkpoint_completion_target", PGC_SIGHUP, WAL_CHECKPOINTS,
1886 gettext_noop("Time spent flushing dirty buffers during checkpoint, as fraction of checkpoint interval."),
1889 &CheckPointCompletionTarget,
1890 0.5, 0.0, 1.0, NULL, NULL
1893 /* End-of-list marker */
1895 {NULL, 0, 0, NULL, NULL}, NULL, 0.0, 0.0, 0.0, NULL, NULL
1900 static struct config_string ConfigureNamesString[] =
1903 {"archive_command", PGC_SIGHUP, WAL_SETTINGS,
1904 gettext_noop("Sets the shell command that will be called to archive a WAL file."),
1907 &XLogArchiveCommand,
1912 {"backslash_quote", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1913 gettext_noop("Sets whether \"\\'\" is allowed in string literals."),
1914 gettext_noop("Valid values are ON, OFF, and SAFE_ENCODING.")
1916 &backslash_quote_string,
1917 "safe_encoding", assign_backslash_quote, NULL
1921 {"client_encoding", PGC_USERSET, CLIENT_CONN_LOCALE,
1922 gettext_noop("Sets the client's character set encoding."),
1924 GUC_IS_NAME | GUC_REPORT
1926 &client_encoding_string,
1927 "SQL_ASCII", assign_client_encoding, NULL
1931 {"client_min_messages", PGC_USERSET, LOGGING_WHEN,
1932 gettext_noop("Sets the message levels that are sent to the client."),
1933 gettext_noop("Valid values are DEBUG5, DEBUG4, DEBUG3, DEBUG2, "
1934 "DEBUG1, LOG, NOTICE, WARNING, and ERROR. Each level includes all the "
1935 "levels that follow it. The later the level, the fewer messages are "
1938 &client_min_messages_str,
1939 "notice", assign_client_min_messages, NULL
1943 {"log_min_messages", PGC_SUSET, LOGGING_WHEN,
1944 gettext_noop("Sets the message levels that are logged."),
1945 gettext_noop("Valid values are DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1, "
1946 "INFO, NOTICE, WARNING, ERROR, LOG, FATAL, and PANIC. Each level "
1947 "includes all the levels that follow it.")
1949 &log_min_messages_str,
1950 "notice", assign_log_min_messages, NULL
1954 {"log_error_verbosity", PGC_SUSET, LOGGING_WHEN,
1955 gettext_noop("Sets the verbosity of logged messages."),
1956 gettext_noop("Valid values are \"terse\", \"default\", and \"verbose\".")
1958 &log_error_verbosity_str,
1959 "default", assign_log_error_verbosity, NULL
1962 {"log_statement", PGC_SUSET, LOGGING_WHAT,
1963 gettext_noop("Sets the type of statements logged."),
1964 gettext_noop("Valid values are \"none\", \"ddl\", \"mod\", and \"all\".")
1967 "none", assign_log_statement, NULL
1971 {"log_min_error_statement", PGC_SUSET, LOGGING_WHEN,
1972 gettext_noop("Causes all statements generating error at or above this level to be logged."),
1973 gettext_noop("All SQL statements that cause an error of the "
1974 "specified level or a higher level are logged.")
1976 &log_min_error_statement_str,
1977 "error", assign_min_error_statement, NULL
1981 {"log_line_prefix", PGC_SIGHUP, LOGGING_WHAT,
1982 gettext_noop("Controls information prefixed to each log line."),
1983 gettext_noop("If blank, no prefix is used.")
1990 {"log_timezone", PGC_SIGHUP, LOGGING_WHAT,
1991 gettext_noop("Sets the time zone to use in log messages."),
1994 &log_timezone_string,
1995 "UNKNOWN", assign_log_timezone, show_log_timezone
1999 {"DateStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
2000 gettext_noop("Sets the display format for date and time values."),
2001 gettext_noop("Also controls interpretation of ambiguous "
2003 GUC_LIST_INPUT | GUC_REPORT
2006 "ISO, MDY", assign_datestyle, NULL
2010 {"default_tablespace", PGC_USERSET, CLIENT_CONN_STATEMENT,
2011 gettext_noop("Sets the default tablespace to create tables and indexes in."),
2012 gettext_noop("An empty string selects the database's default tablespace."),
2015 &default_tablespace,
2016 "", assign_default_tablespace, NULL
2020 {"temp_tablespaces", PGC_USERSET, CLIENT_CONN_STATEMENT,
2021 gettext_noop("Sets the tablespace(s) to use for temporary tables and sort files."),
2023 GUC_LIST_INPUT | GUC_LIST_QUOTE
2026 "", assign_temp_tablespaces, NULL
2030 {"default_transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
2031 gettext_noop("Sets the transaction isolation level of each new transaction."),
2032 gettext_noop("Each SQL transaction has an isolation level, which "
2033 "can be either \"read uncommitted\", \"read committed\", \"repeatable read\", or \"serializable\".")
2035 &default_iso_level_string,
2036 "read committed", assign_defaultxactisolevel, NULL
2040 {"session_replication_role", PGC_SUSET, CLIENT_CONN_STATEMENT,
2041 gettext_noop("Sets the sessions behavior for triggers and rewrite rules."),
2042 gettext_noop("Each session can be either"
2043 " \"origin\", \"replica\" or \"local\".")
2045 &session_replication_role_string,
2046 "origin", assign_session_replication_role, NULL
2050 {"dynamic_library_path", PGC_SUSET, CLIENT_CONN_OTHER,
2051 gettext_noop("Sets the path for dynamically loadable modules."),
2052 gettext_noop("If a dynamically loadable module needs to be opened and "
2053 "the specified name does not have a directory component (i.e., the "
2054 "name does not contain a slash), the system will search this path for "
2055 "the specified file."),
2058 &Dynamic_library_path,
2059 "$libdir", NULL, NULL
2063 {"krb_server_keyfile", PGC_POSTMASTER, CONN_AUTH_SECURITY,
2064 gettext_noop("Sets the location of the Kerberos server key file."),
2068 &pg_krb_server_keyfile,
2069 PG_KRB_SRVTAB, NULL, NULL
2073 {"krb_srvname", PGC_POSTMASTER, CONN_AUTH_SECURITY,
2074 gettext_noop("Sets the name of the Kerberos service."),
2078 PG_KRB_SRVNAM, NULL, NULL
2082 {"krb_server_hostname", PGC_POSTMASTER, CONN_AUTH_SECURITY,
2083 gettext_noop("Sets the hostname of the Kerberos server."),
2086 &pg_krb_server_hostname,
2091 {"bonjour_name", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2092 gettext_noop("Sets the Bonjour broadcast service name."),
2099 /* See main.c about why defaults for LC_foo are not all alike */
2102 {"lc_collate", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2103 gettext_noop("Shows the collation order locale."),
2105 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2112 {"lc_ctype", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2113 gettext_noop("Shows the character classification and case conversion locale."),
2115 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2122 {"lc_messages", PGC_SUSET, CLIENT_CONN_LOCALE,
2123 gettext_noop("Sets the language in which messages are displayed."),
2127 "", locale_messages_assign, NULL
2131 {"lc_monetary", PGC_USERSET, CLIENT_CONN_LOCALE,
2132 gettext_noop("Sets the locale for formatting monetary amounts."),
2136 "C", locale_monetary_assign, NULL
2140 {"lc_numeric", PGC_USERSET, CLIENT_CONN_LOCALE,
2141 gettext_noop("Sets the locale for formatting numbers."),
2145 "C", locale_numeric_assign, NULL
2149 {"lc_time", PGC_USERSET, CLIENT_CONN_LOCALE,
2150 gettext_noop("Sets the locale for formatting date and time values."),
2154 "C", locale_time_assign, NULL
2158 {"shared_preload_libraries", PGC_POSTMASTER, RESOURCES_KERNEL,
2159 gettext_noop("Lists shared libraries to preload into server."),
2161 GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
2163 &shared_preload_libraries_string,
2168 {"local_preload_libraries", PGC_BACKEND, CLIENT_CONN_OTHER,
2169 gettext_noop("Lists shared libraries to preload into each backend."),
2171 GUC_LIST_INPUT | GUC_LIST_QUOTE
2173 &local_preload_libraries_string,
2178 {"regex_flavor", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
2179 gettext_noop("Sets the regular expression \"flavor\"."),
2180 gettext_noop("This can be set to advanced, extended, or basic.")
2182 ®ex_flavor_string,
2183 "advanced", assign_regex_flavor, NULL
2187 {"search_path", PGC_USERSET, CLIENT_CONN_STATEMENT,
2188 gettext_noop("Sets the schema search order for names that are not schema-qualified."),
2190 GUC_LIST_INPUT | GUC_LIST_QUOTE
2192 &namespace_search_path,
2193 "\"$user\",public", assign_search_path, NULL
2197 /* Can't be set in postgresql.conf */
2198 {"server_encoding", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2199 gettext_noop("Sets the server (database) character set encoding."),
2201 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2203 &server_encoding_string,
2204 "SQL_ASCII", NULL, NULL
2208 /* Can't be set in postgresql.conf */
2209 {"server_version", PGC_INTERNAL, PRESET_OPTIONS,
2210 gettext_noop("Shows the server version."),
2212 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2214 &server_version_string,
2215 PG_VERSION, NULL, NULL
2219 /* Not for general use --- used by SET ROLE */
2220 {"role", PGC_USERSET, UNGROUPED,
2221 gettext_noop("Sets the current role."),
2223 GUC_IS_NAME | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2226 "none", assign_role, show_role
2230 /* Not for general use --- used by SET SESSION AUTHORIZATION */
2231 {"session_authorization", PGC_USERSET, UNGROUPED,
2232 gettext_noop("Sets the session user name."),
2234 GUC_IS_NAME | GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2236 &session_authorization_string,
2237 NULL, assign_session_authorization, show_session_authorization
2241 {"log_destination", PGC_SIGHUP, LOGGING_WHERE,
2242 gettext_noop("Sets the destination for server log output."),
2243 gettext_noop("Valid values are combinations of \"stderr\", \"syslog\", "
2244 " \"csvlog\" and \"eventlog\", depending on the platform."),
2247 &log_destination_string,
2248 "stderr", assign_log_destination, NULL
2251 {"log_directory", PGC_SIGHUP, LOGGING_WHERE,
2252 gettext_noop("Sets the destination directory for log files."),
2253 gettext_noop("Can be specified as relative to the data directory "
2254 "or as absolute path."),
2258 "pg_log", assign_canonical_path, NULL
2261 {"log_filename", PGC_SIGHUP, LOGGING_WHERE,
2262 gettext_noop("Sets the file name pattern for log files."),
2267 "postgresql-%Y-%m-%d_%H%M%S.log", NULL, NULL
2272 {"syslog_facility", PGC_SIGHUP, LOGGING_WHERE,
2273 gettext_noop("Sets the syslog \"facility\" to be used when syslog enabled."),
2274 gettext_noop("Valid values are LOCAL0, LOCAL1, LOCAL2, LOCAL3, "
2275 "LOCAL4, LOCAL5, LOCAL6, LOCAL7.")
2277 &syslog_facility_str,
2278 "LOCAL0", assign_syslog_facility, NULL
2281 {"syslog_ident", PGC_SIGHUP, LOGGING_WHERE,
2282 gettext_noop("Sets the program name used to identify PostgreSQL "
2283 "messages in syslog."),
2287 "postgres", assign_syslog_ident, NULL
2292 {"TimeZone", PGC_USERSET, CLIENT_CONN_LOCALE,
2293 gettext_noop("Sets the time zone for displaying and interpreting time stamps."),
2298 "UNKNOWN", assign_timezone, show_timezone
2301 {"timezone_abbreviations", PGC_USERSET, CLIENT_CONN_LOCALE,
2302 gettext_noop("Selects a file of time zone abbreviations."),
2305 &timezone_abbreviations_string,
2306 "UNKNOWN", assign_timezone_abbreviations, NULL
2310 {"transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
2311 gettext_noop("Sets the current transaction's isolation level."),
2313 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2315 &XactIsoLevel_string,
2316 NULL, assign_XactIsoLevel, show_XactIsoLevel
2320 {"unix_socket_group", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2321 gettext_noop("Sets the owning group of the Unix-domain socket."),
2322 gettext_noop("The owning user of the socket is always the user "
2323 "that starts the server.")
2330 {"unix_socket_directory", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2331 gettext_noop("Sets the directory where the Unix-domain socket will be created."),
2336 "", assign_canonical_path, NULL
2340 {"listen_addresses", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2341 gettext_noop("Sets the host name or IP address(es) to listen to."),
2346 "localhost", NULL, NULL
2350 {"wal_sync_method", PGC_SIGHUP, WAL_SETTINGS,
2351 gettext_noop("Selects the method used for forcing WAL updates to disk."),
2355 XLOG_sync_method_default, assign_xlog_sync_method, NULL
2359 {"custom_variable_classes", PGC_SIGHUP, CUSTOM_OPTIONS,
2360 gettext_noop("Sets the list of known custom variable classes."),
2362 GUC_LIST_INPUT | GUC_LIST_QUOTE
2364 &custom_variable_classes,
2365 NULL, assign_custom_variable_classes, NULL
2369 {"data_directory", PGC_POSTMASTER, FILE_LOCATIONS,
2370 gettext_noop("Sets the server's data directory."),
2379 {"config_file", PGC_POSTMASTER, FILE_LOCATIONS,
2380 gettext_noop("Sets the server's main configuration file."),
2382 GUC_DISALLOW_IN_FILE | GUC_SUPERUSER_ONLY
2389 {"hba_file", PGC_POSTMASTER, FILE_LOCATIONS,
2390 gettext_noop("Sets the server's \"hba\" configuration file."),
2399 {"ident_file", PGC_POSTMASTER, FILE_LOCATIONS,
2400 gettext_noop("Sets the server's \"ident\" configuration file."),
2409 {"external_pid_file", PGC_POSTMASTER, FILE_LOCATIONS,
2410 gettext_noop("Writes the postmaster PID to the specified file."),
2415 NULL, assign_canonical_path, NULL
2419 {"xmlbinary", PGC_USERSET, CLIENT_CONN_STATEMENT,
2420 gettext_noop("Sets how binary values are to be encoded in XML."),
2421 gettext_noop("Valid values are BASE64 and HEX.")
2424 "base64", assign_xmlbinary, NULL
2428 {"xmloption", PGC_USERSET, CLIENT_CONN_STATEMENT,
2429 gettext_noop("Sets whether XML data in implicit parsing and serialization "
2430 "operations is to be considered as documents or content fragments."),
2431 gettext_noop("Valid values are DOCUMENT and CONTENT.")
2434 "content", assign_xmloption, NULL
2439 {"ssl_ciphers", PGC_POSTMASTER, CONN_AUTH_SECURITY,
2440 gettext_noop("Sets the list of allowed SSL ciphers."),
2445 "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH", NULL, NULL
2447 #endif /* USE_SSL */
2449 /* End-of-list marker */
2451 {NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL
2456 /******** end of options list ********/
2460 * To allow continued support of obsolete names for GUC variables, we apply
2461 * the following mappings to any unrecognized name. Note that an old name
2462 * should be mapped to a new one only if the new variable has very similar
2463 * semantics to the old.
2465 static const char *const map_old_guc_names[] = {
2466 "sort_mem", "work_mem",
2467 "vacuum_mem", "maintenance_work_mem",
2473 * Actual lookup of variables is done through this single, sorted array.
2475 static struct config_generic **guc_variables;
2477 /* Current number of variables contained in the vector */
2478 static int num_guc_variables;
2480 /* Vector capacity */
2481 static int size_guc_variables;
2484 static bool guc_dirty; /* TRUE if need to do commit/abort work */
2486 static bool reporting_enabled; /* TRUE to enable GUC_REPORT */
2489 static int guc_var_compare(const void *a, const void *b);
2490 static int guc_name_compare(const char *namea, const char *nameb);
2491 static void push_old_value(struct config_generic * gconf);
2492 static void ReportGUCOption(struct config_generic * record);
2493 static void ShowGUCConfigOption(const char *name, DestReceiver *dest);
2494 static void ShowAllGUCConfig(DestReceiver *dest);
2495 static char *_ShowOption(struct config_generic * record, bool use_units);
2496 static bool is_newvalue_equal(struct config_generic * record, const char *newvalue);
2500 * Some infrastructure for checking malloc/strdup/realloc calls
2503 guc_malloc(int elevel, size_t size)
2507 data = malloc(size);
2510 (errcode(ERRCODE_OUT_OF_MEMORY),
2511 errmsg("out of memory")));
2516 guc_realloc(int elevel, void *old, size_t size)
2520 data = realloc(old, size);
2523 (errcode(ERRCODE_OUT_OF_MEMORY),
2524 errmsg("out of memory")));
2529 guc_strdup(int elevel, const char *src)
2536 (errcode(ERRCODE_OUT_OF_MEMORY),
2537 errmsg("out of memory")));
2543 * Support for assigning to a field of a string GUC item. Free the prior
2544 * value if it's not referenced anywhere else in the item (including stacked
2548 set_string_field(struct config_string * conf, char **field, char *newval)
2550 char *oldval = *field;
2553 /* Do the assignment */
2556 /* Exit if any duplicate references, or if old value was NULL anyway */
2557 if (oldval == NULL ||
2558 oldval == *(conf->variable) ||
2559 oldval == conf->reset_val ||
2560 oldval == conf->tentative_val ||
2561 oldval == conf->boot_val)
2563 for (stack = conf->gen.stack; stack; stack = stack->prev)
2565 if (oldval == stack->tentative_val.stringval ||
2566 oldval == stack->value.stringval)
2570 /* Not used anymore, so free it */
2575 * Detect whether strval is referenced anywhere in a GUC string item
2578 string_field_used(struct config_string * conf, char *strval)
2582 if (strval == *(conf->variable) ||
2583 strval == conf->reset_val ||
2584 strval == conf->tentative_val ||
2585 strval == conf->boot_val)
2587 for (stack = conf->gen.stack; stack; stack = stack->prev)
2589 if (strval == stack->tentative_val.stringval ||
2590 strval == stack->value.stringval)
2597 struct config_generic **
2598 get_guc_variables(void)
2600 return guc_variables;
2605 * Build the sorted array. This is split out so that it could be
2606 * re-executed after startup (eg, we could allow loadable modules to
2607 * add vars, and then we'd need to re-sort).
2610 build_guc_variables(void)
2614 struct config_generic **guc_vars;
2617 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
2619 struct config_bool *conf = &ConfigureNamesBool[i];
2621 /* Rather than requiring vartype to be filled in by hand, do this: */
2622 conf->gen.vartype = PGC_BOOL;
2626 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
2628 struct config_int *conf = &ConfigureNamesInt[i];
2630 conf->gen.vartype = PGC_INT;
2634 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
2636 struct config_real *conf = &ConfigureNamesReal[i];
2638 conf->gen.vartype = PGC_REAL;
2642 for (i = 0; ConfigureNamesString[i].gen.name; i++)
2644 struct config_string *conf = &ConfigureNamesString[i];
2646 conf->gen.vartype = PGC_STRING;
2651 * Create table with 20% slack
2653 size_vars = num_vars + num_vars / 4;
2655 guc_vars = (struct config_generic **)
2656 guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
2660 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
2661 guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
2663 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
2664 guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
2666 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
2667 guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
2669 for (i = 0; ConfigureNamesString[i].gen.name; i++)
2670 guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
2673 free(guc_variables);
2674 guc_variables = guc_vars;
2675 num_guc_variables = num_vars;
2676 size_guc_variables = size_vars;
2677 qsort((void *) guc_variables, num_guc_variables,
2678 sizeof(struct config_generic *), guc_var_compare);
2682 is_custom_class(const char *name, int dotPos)
2685 * assign_custom_variable_classes() has made sure no empty identifiers or
2686 * whitespace exists in the variable
2688 bool result = false;
2689 const char *ccs = GetConfigOption("custom_variable_classes");
2693 const char *start = ccs;
2699 if (c == 0 || c == ',')
2701 if (dotPos == ccs - start && strncmp(start, name, dotPos) == 0)
2716 * Add a new GUC variable to the list of known variables. The
2717 * list is expanded if needed.
2720 add_guc_variable(struct config_generic * var, int elevel)
2722 if (num_guc_variables + 1 >= size_guc_variables)
2725 * Increase the vector by 25%
2727 int size_vars = size_guc_variables + size_guc_variables / 4;
2728 struct config_generic **guc_vars;
2733 guc_vars = (struct config_generic **)
2734 guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
2738 guc_vars = (struct config_generic **)
2739 guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
2742 if (guc_vars == NULL)
2743 return false; /* out of memory */
2745 guc_variables = guc_vars;
2746 size_guc_variables = size_vars;
2748 guc_variables[num_guc_variables++] = var;
2749 qsort((void *) guc_variables, num_guc_variables,
2750 sizeof(struct config_generic *), guc_var_compare);
2755 * Create and add a placeholder variable. It's presumed to belong
2756 * to a valid custom variable class at this point.
2758 static struct config_string *
2759 add_placeholder_variable(const char *name, int elevel)
2761 size_t sz = sizeof(struct config_string) + sizeof(char *);
2762 struct config_string *var;
2763 struct config_generic *gen;
2765 var = (struct config_string *) guc_malloc(elevel, sz);
2772 gen->name = guc_strdup(elevel, name);
2773 if (gen->name == NULL)
2779 gen->context = PGC_USERSET;
2780 gen->group = CUSTOM_OPTIONS;
2781 gen->short_desc = "GUC placeholder variable";
2782 gen->flags = GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_CUSTOM_PLACEHOLDER;
2783 gen->vartype = PGC_STRING;
2786 * The char* is allocated at the end of the struct since we have no
2787 * 'static' place to point to.
2789 var->variable = (char **) (var + 1);
2791 if (!add_guc_variable((struct config_generic *) var, elevel))
2793 free((void *) gen->name);
2802 * Look up option NAME. If it exists, return a pointer to its record,
2805 static struct config_generic *
2806 find_option(const char *name, int elevel)
2809 const char **key = &name;
2810 struct config_generic **res;
2816 * By equating const char ** with struct config_generic *, we are assuming
2817 * the name field is first in config_generic.
2819 res = (struct config_generic **) bsearch((void *) &key,
2820 (void *) guc_variables,
2822 sizeof(struct config_generic *),
2828 * See if the name is an obsolete name for a variable. We assume that the
2829 * set of supported old names is short enough that a brute-force search is
2832 for (i = 0; map_old_guc_names[i] != NULL; i += 2)
2834 if (guc_name_compare(name, map_old_guc_names[i]) == 0)
2835 return find_option(map_old_guc_names[i + 1], elevel);
2839 * Check if the name is qualified, and if so, check if the qualifier maps
2840 * to a custom variable class.
2842 dot = strchr(name, GUC_QUALIFIER_SEPARATOR);
2843 if (dot != NULL && is_custom_class(name, dot - name))
2844 /* Add a placeholder variable for this name */
2845 return (struct config_generic *) add_placeholder_variable(name, elevel);
2853 * comparator for qsorting and bsearching guc_variables array
2856 guc_var_compare(const void *a, const void *b)
2858 struct config_generic *confa = *(struct config_generic **) a;
2859 struct config_generic *confb = *(struct config_generic **) b;
2861 return guc_name_compare(confa->name, confb->name);
2866 guc_name_compare(const char *namea, const char *nameb)
2869 * The temptation to use strcasecmp() here must be resisted, because the
2870 * array ordering has to remain stable across setlocale() calls. So, build
2871 * our own with a simple ASCII-only downcasing.
2873 while (*namea && *nameb)
2875 char cha = *namea++;
2876 char chb = *nameb++;
2878 if (cha >= 'A' && cha <= 'Z')
2880 if (chb >= 'A' && chb <= 'Z')
2886 return 1; /* a is longer */
2888 return -1; /* b is longer */
2894 guc_get_index(const char *name)
2896 const char **key = &name;
2897 struct config_generic **res;
2902 * By equating const char ** with struct config_generic *, we are assuming
2903 * the name field is first in config_generic.
2905 res = (struct config_generic **) bsearch((void *) &key,
2906 (void *) guc_variables,
2908 sizeof(struct config_generic *),
2913 return res - guc_variables;
2918 * Initialize GUC options during program startup.
2920 * Note that we cannot read the config file yet, since we have not yet
2921 * processed command-line switches.
2924 InitializeGUCOptions(void)
2931 * Before log_line_prefix could possibly receive a nonempty setting,
2932 * make sure that timezone processing is minimally alive (see elog.c).
2934 pg_timezone_pre_initialize();
2937 * Build sorted array of all GUC variables.
2939 build_guc_variables();
2942 * Load all variables with their compiled-in defaults, and initialize
2943 * status fields as needed.
2945 for (i = 0; i < num_guc_variables; i++)
2947 struct config_generic *gconf = guc_variables[i];
2950 gconf->reset_source = PGC_S_DEFAULT;
2951 gconf->tentative_source = PGC_S_DEFAULT;
2952 gconf->source = PGC_S_DEFAULT;
2953 gconf->stack = NULL;
2955 switch (gconf->vartype)
2959 struct config_bool *conf = (struct config_bool *) gconf;
2961 if (conf->assign_hook)
2962 if (!(*conf->assign_hook) (conf->boot_val, true,
2964 elog(FATAL, "failed to initialize %s to %d",
2965 conf->gen.name, (int) conf->boot_val);
2966 *conf->variable = conf->reset_val = conf->boot_val;
2971 struct config_int *conf = (struct config_int *) gconf;
2973 Assert(conf->boot_val >= conf->min);
2974 Assert(conf->boot_val <= conf->max);
2975 if (conf->assign_hook)
2976 if (!(*conf->assign_hook) (conf->boot_val, true,
2978 elog(FATAL, "failed to initialize %s to %d",
2979 conf->gen.name, conf->boot_val);
2980 *conf->variable = conf->reset_val = conf->boot_val;
2985 struct config_real *conf = (struct config_real *) gconf;
2987 Assert(conf->boot_val >= conf->min);
2988 Assert(conf->boot_val <= conf->max);
2989 if (conf->assign_hook)
2990 if (!(*conf->assign_hook) (conf->boot_val, true,
2992 elog(FATAL, "failed to initialize %s to %g",
2993 conf->gen.name, conf->boot_val);
2994 *conf->variable = conf->reset_val = conf->boot_val;
2999 struct config_string *conf = (struct config_string *) gconf;
3002 *conf->variable = NULL;
3003 conf->reset_val = NULL;
3004 conf->tentative_val = NULL;
3006 if (conf->boot_val == NULL)
3008 /* Cannot set value yet */
3012 str = guc_strdup(FATAL, conf->boot_val);
3013 conf->reset_val = str;
3015 if (conf->assign_hook)
3019 newstr = (*conf->assign_hook) (str, true,
3023 elog(FATAL, "failed to initialize %s to \"%s\"",
3024 conf->gen.name, str);
3026 else if (newstr != str)
3031 * See notes in set_config_option about casting
3033 str = (char *) newstr;
3034 conf->reset_val = str;
3037 *conf->variable = str;
3045 reporting_enabled = false;
3048 * Prevent any attempt to override the transaction modes from
3049 * non-interactive sources.
3051 SetConfigOption("transaction_isolation", "default",
3052 PGC_POSTMASTER, PGC_S_OVERRIDE);
3053 SetConfigOption("transaction_read_only", "no",
3054 PGC_POSTMASTER, PGC_S_OVERRIDE);
3057 * For historical reasons, some GUC parameters can receive defaults from
3058 * environment variables. Process those settings.
3061 env = getenv("PGPORT");
3063 SetConfigOption("port", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3065 env = getenv("PGDATESTYLE");
3067 SetConfigOption("datestyle", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3069 env = getenv("PGCLIENTENCODING");
3071 SetConfigOption("client_encoding", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3074 * rlimit isn't exactly an "environment variable", but it behaves about
3075 * the same. If we can identify the platform stack depth rlimit, increase
3076 * default stack depth setting up to whatever is safe (but at most 2MB).
3078 stack_rlimit = get_stack_depth_rlimit();
3079 if (stack_rlimit > 0)
3081 int new_limit = (stack_rlimit - STACK_DEPTH_SLOP) / 1024L;
3083 if (new_limit > 100)
3087 new_limit = Min(new_limit, 2048);
3088 sprintf(limbuf, "%d", new_limit);
3089 SetConfigOption("max_stack_depth", limbuf,
3090 PGC_POSTMASTER, PGC_S_ENV_VAR);
3097 * Select the configuration files and data directory to be used, and
3098 * do the initial read of postgresql.conf.
3100 * This is called after processing command-line switches.
3101 * userDoption is the -D switch value if any (NULL if unspecified).
3102 * progname is just for use in error messages.
3104 * Returns true on success; on failure, prints a suitable error message
3105 * to stderr and returns false.
3108 SelectConfigFiles(const char *userDoption, const char *progname)
3112 struct stat stat_buf;
3114 /* configdir is -D option, or $PGDATA if no -D */
3116 configdir = make_absolute_path(userDoption);
3118 configdir = make_absolute_path(getenv("PGDATA"));
3121 * Find the configuration file: if config_file was specified on the
3122 * command line, use it, else use configdir/postgresql.conf. In any case
3123 * ensure the result is an absolute path, so that it will be interpreted
3124 * the same way by future backends.
3127 fname = make_absolute_path(ConfigFileName);
3130 fname = guc_malloc(FATAL,
3131 strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
3132 sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
3136 write_stderr("%s does not know where to find the server configuration file.\n"
3137 "You must specify the --config-file or -D invocation "
3138 "option or set the PGDATA environment variable.\n",
3144 * Set the ConfigFileName GUC variable to its final value, ensuring that
3145 * it can't be overridden later.
3147 SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
3151 * Now read the config file for the first time.
3153 if (stat(ConfigFileName, &stat_buf) != 0)
3155 write_stderr("%s cannot access the server configuration file \"%s\": %s\n",
3156 progname, ConfigFileName, strerror(errno));
3160 ProcessConfigFile(PGC_POSTMASTER);
3163 * If the data_directory GUC variable has been set, use that as DataDir;
3164 * otherwise use configdir if set; else punt.
3166 * Note: SetDataDir will copy and absolute-ize its argument, so we don't
3170 SetDataDir(data_directory);
3172 SetDataDir(configdir);
3175 write_stderr("%s does not know where to find the database system data.\n"
3176 "This can be specified as \"data_directory\" in \"%s\", "
3177 "or by the -D invocation option, or by the "
3178 "PGDATA environment variable.\n",
3179 progname, ConfigFileName);
3184 * Reflect the final DataDir value back into the data_directory GUC var.
3185 * (If you are wondering why we don't just make them a single variable,
3186 * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
3187 * child backends specially. XXX is that still true? Given that we now
3188 * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
3189 * DataDir in advance.)
3191 SetConfigOption("data_directory", DataDir, PGC_POSTMASTER, PGC_S_OVERRIDE);
3194 * Figure out where pg_hba.conf is, and make sure the path is absolute.
3197 fname = make_absolute_path(HbaFileName);
3200 fname = guc_malloc(FATAL,
3201 strlen(configdir) + strlen(HBA_FILENAME) + 2);
3202 sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
3206 write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
3207 "This can be specified as \"hba_file\" in \"%s\", "
3208 "or by the -D invocation option, or by the "
3209 "PGDATA environment variable.\n",
3210 progname, ConfigFileName);
3213 SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
3217 * Likewise for pg_ident.conf.
3220 fname = make_absolute_path(IdentFileName);
3223 fname = guc_malloc(FATAL,
3224 strlen(configdir) + strlen(IDENT_FILENAME) + 2);
3225 sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
3229 write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
3230 "This can be specified as \"ident_file\" in \"%s\", "
3231 "or by the -D invocation option, or by the "
3232 "PGDATA environment variable.\n",
3233 progname, ConfigFileName);
3236 SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
3246 * Reset all options to their saved default values (implements RESET ALL)
3249 ResetAllOptions(void)
3253 for (i = 0; i < num_guc_variables; i++)
3255 struct config_generic *gconf = guc_variables[i];
3257 /* Don't reset non-SET-able values */
3258 if (gconf->context != PGC_SUSET &&
3259 gconf->context != PGC_USERSET)
3261 /* Don't reset if special exclusion from RESET ALL */
3262 if (gconf->flags & GUC_NO_RESET_ALL)
3264 /* No need to reset if wasn't SET */
3265 if (gconf->source <= PGC_S_OVERRIDE)
3268 /* Save old value to support transaction abort */
3269 push_old_value(gconf);
3271 switch (gconf->vartype)
3275 struct config_bool *conf = (struct config_bool *) gconf;
3277 if (conf->assign_hook)
3278 if (!(*conf->assign_hook) (conf->reset_val, true,
3280 elog(ERROR, "failed to reset %s", conf->gen.name);
3281 *conf->variable = conf->reset_val;
3282 conf->tentative_val = conf->reset_val;
3283 conf->gen.source = conf->gen.reset_source;
3284 conf->gen.tentative_source = conf->gen.reset_source;
3285 conf->gen.status |= GUC_HAVE_TENTATIVE;
3291 struct config_int *conf = (struct config_int *) gconf;
3293 if (conf->assign_hook)
3294 if (!(*conf->assign_hook) (conf->reset_val, true,
3296 elog(ERROR, "failed to reset %s", conf->gen.name);
3297 *conf->variable = conf->reset_val;
3298 conf->tentative_val = conf->reset_val;
3299 conf->gen.source = conf->gen.reset_source;
3300 conf->gen.tentative_source = conf->gen.reset_source;
3301 conf->gen.status |= GUC_HAVE_TENTATIVE;
3307 struct config_real *conf = (struct config_real *) gconf;
3309 if (conf->assign_hook)
3310 if (!(*conf->assign_hook) (conf->reset_val, true,
3312 elog(ERROR, "failed to reset %s", conf->gen.name);
3313 *conf->variable = conf->reset_val;
3314 conf->tentative_val = conf->reset_val;
3315 conf->gen.source = conf->gen.reset_source;
3316 conf->gen.tentative_source = conf->gen.reset_source;
3317 conf->gen.status |= GUC_HAVE_TENTATIVE;
3323 struct config_string *conf = (struct config_string *) gconf;
3326 if (conf->reset_val == NULL)
3328 /* Nothing to reset to, as yet; so do nothing */
3332 /* We need not strdup here */
3333 str = conf->reset_val;
3335 if (conf->assign_hook)
3339 newstr = (*conf->assign_hook) (str, true,
3342 elog(ERROR, "failed to reset %s", conf->gen.name);
3343 else if (newstr != str)
3346 * See notes in set_config_option about casting
3348 str = (char *) newstr;
3352 set_string_field(conf, conf->variable, str);
3353 set_string_field(conf, &conf->tentative_val, str);
3354 conf->gen.source = conf->gen.reset_source;
3355 conf->gen.tentative_source = conf->gen.reset_source;
3356 conf->gen.status |= GUC_HAVE_TENTATIVE;
3362 if (gconf->flags & GUC_REPORT)
3363 ReportGUCOption(gconf);
3370 * Push previous state during first assignment to a GUC variable
3371 * within a particular transaction.
3373 * We have to be willing to "back-fill" the state stack if the first
3374 * assignment occurs within a subtransaction nested several levels deep.
3375 * This ensures that if an intermediate transaction aborts, it will have
3376 * the proper value available to restore the setting to.
3379 push_old_value(struct config_generic * gconf)
3381 int my_level = GetCurrentTransactionNestLevel();
3384 /* If we're not inside a transaction, do nothing */
3390 /* Done if we already pushed it at this nesting depth */
3391 if (gconf->stack && gconf->stack->nest_level >= my_level)
3395 * We keep all the stack entries in TopTransactionContext so as to
3396 * avoid allocation problems when a subtransaction back-fills stack
3397 * entries for upper transaction levels.
3399 stack = (GucStack *) MemoryContextAlloc(TopTransactionContext,
3402 stack->prev = gconf->stack;
3403 stack->nest_level = stack->prev ? stack->prev->nest_level + 1 : 1;
3404 stack->status = gconf->status;
3405 stack->tentative_source = gconf->tentative_source;
3406 stack->source = gconf->source;
3408 switch (gconf->vartype)
3411 stack->tentative_val.boolval =
3412 ((struct config_bool *) gconf)->tentative_val;
3413 stack->value.boolval =
3414 *((struct config_bool *) gconf)->variable;
3418 stack->tentative_val.intval =
3419 ((struct config_int *) gconf)->tentative_val;
3420 stack->value.intval =
3421 *((struct config_int *) gconf)->variable;
3425 stack->tentative_val.realval =
3426 ((struct config_real *) gconf)->tentative_val;
3427 stack->value.realval =
3428 *((struct config_real *) gconf)->variable;
3432 stack->tentative_val.stringval =
3433 ((struct config_string *) gconf)->tentative_val;
3434 stack->value.stringval =
3435 *((struct config_string *) gconf)->variable;
3439 gconf->stack = stack;
3441 /* Set state to indicate nothing happened yet within this level */
3442 gconf->status = GUC_HAVE_STACK;
3444 /* Ensure we remember to pop at end of xact */
3450 * Do GUC processing at transaction or subtransaction commit or abort.
3453 AtEOXact_GUC(bool isCommit, bool isSubXact)
3458 /* Quick exit if nothing's changed in this transaction */
3462 my_level = GetCurrentTransactionNestLevel();
3463 Assert(isSubXact ? (my_level > 1) : (my_level == 1));
3465 for (i = 0; i < num_guc_variables; i++)
3467 struct config_generic *gconf = guc_variables[i];
3468 int my_status = gconf->status;
3469 GucStack *stack = gconf->stack;
3474 * Skip if nothing's happened to this var in this transaction
3478 Assert(stack == NULL);
3481 /* Assert that we stacked old value before changing it */
3482 Assert(stack != NULL && (my_status & GUC_HAVE_STACK));
3483 /* However, the last change may have been at an outer xact level */
3484 if (stack->nest_level < my_level)
3486 Assert(stack->nest_level == my_level);
3489 * We will pop the stack entry. Start by restoring outer xact status
3490 * (since we may want to modify it below). Be careful to use
3491 * my_status to reference the inner xact status below this point...
3493 gconf->status = stack->status;
3496 * We have two cases:
3498 * If commit and HAVE_TENTATIVE, set actual value to tentative (this
3499 * is to override a SET LOCAL if one occurred later than SET). We keep
3500 * the tentative value and propagate HAVE_TENTATIVE to the parent
3501 * status, allowing the SET's effect to percolate up. (But if we're
3502 * exiting the outermost transaction, we'll drop the HAVE_TENTATIVE
3505 * Otherwise, we have a transaction that aborted or executed only SET
3506 * LOCAL (or no SET at all). In either case it should have no further
3507 * effect, so restore both tentative and actual values from the stack
3511 useTentative = isCommit && (my_status & GUC_HAVE_TENTATIVE) != 0;
3514 switch (gconf->vartype)
3518 struct config_bool *conf = (struct config_bool *) gconf;
3520 GucSource newsource;
3524 newval = conf->tentative_val;
3525 newsource = conf->gen.tentative_source;
3526 conf->gen.status |= GUC_HAVE_TENTATIVE;
3530 newval = stack->value.boolval;
3531 newsource = stack->source;
3532 conf->tentative_val = stack->tentative_val.boolval;
3533 conf->gen.tentative_source = stack->tentative_source;
3536 if (*conf->variable != newval)
3538 if (conf->assign_hook)
3539 if (!(*conf->assign_hook) (newval,
3540 true, PGC_S_OVERRIDE))
3541 elog(LOG, "failed to commit %s",
3543 *conf->variable = newval;
3546 conf->gen.source = newsource;
3551 struct config_int *conf = (struct config_int *) gconf;
3553 GucSource newsource;
3557 newval = conf->tentative_val;
3558 newsource = conf->gen.tentative_source;
3559 conf->gen.status |= GUC_HAVE_TENTATIVE;
3563 newval = stack->value.intval;
3564 newsource = stack->source;
3565 conf->tentative_val = stack->tentative_val.intval;
3566 conf->gen.tentative_source = stack->tentative_source;
3569 if (*conf->variable != newval)
3571 if (conf->assign_hook)
3572 if (!(*conf->assign_hook) (newval,
3573 true, PGC_S_OVERRIDE))
3574 elog(LOG, "failed to commit %s",
3576 *conf->variable = newval;
3579 conf->gen.source = newsource;
3584 struct config_real *conf = (struct config_real *) gconf;
3586 GucSource newsource;
3590 newval = conf->tentative_val;
3591 newsource = conf->gen.tentative_source;
3592 conf->gen.status |= GUC_HAVE_TENTATIVE;
3596 newval = stack->value.realval;
3597 newsource = stack->source;
3598 conf->tentative_val = stack->tentative_val.realval;
3599 conf->gen.tentative_source = stack->tentative_source;
3602 if (*conf->variable != newval)
3604 if (conf->assign_hook)
3605 if (!(*conf->assign_hook) (newval,
3606 true, PGC_S_OVERRIDE))
3607 elog(LOG, "failed to commit %s",
3609 *conf->variable = newval;
3612 conf->gen.source = newsource;
3617 struct config_string *conf = (struct config_string *) gconf;
3619 GucSource newsource;
3623 newval = conf->tentative_val;
3624 newsource = conf->gen.tentative_source;
3625 conf->gen.status |= GUC_HAVE_TENTATIVE;
3629 newval = stack->value.stringval;
3630 newsource = stack->source;
3631 set_string_field(conf, &conf->tentative_val,
3632 stack->tentative_val.stringval);
3633 conf->gen.tentative_source = stack->tentative_source;
3636 if (*conf->variable != newval)
3638 if (conf->assign_hook)
3642 newstr = (*conf->assign_hook) (newval, true,
3645 elog(LOG, "failed to commit %s",
3647 else if (newstr != newval)
3650 * If newval should now be freed, it'll be
3651 * taken care of below.
3653 * See notes in set_config_option about
3656 newval = (char *) newstr;
3660 set_string_field(conf, conf->variable, newval);
3663 conf->gen.source = newsource;
3664 /* Release stacked values if not used anymore */
3665 set_string_field(conf, &stack->value.stringval,
3667 set_string_field(conf, &stack->tentative_val.stringval,
3669 /* Don't store tentative value separately after commit */
3671 set_string_field(conf, &conf->tentative_val, NULL);
3676 /* Finish popping the state stack */
3677 gconf->stack = stack->prev;
3681 * If we're now out of all xact levels, forget TENTATIVE status bit;
3682 * there's nothing tentative about the value anymore.
3686 Assert(gconf->stack == NULL);
3690 /* Report new value if we changed it */
3691 if (changed && (gconf->flags & GUC_REPORT))
3692 ReportGUCOption(gconf);
3696 * If we're now out of all xact levels, we can clear guc_dirty. (Note: we
3697 * cannot reset guc_dirty when exiting a subtransaction, because we know
3698 * that all outer transaction levels will have stacked values to deal
3707 * Start up automatic reporting of changes to variables marked GUC_REPORT.
3708 * This is executed at completion of backend startup.
3711 BeginReportingGUCOptions(void)
3716 * Don't do anything unless talking to an interactive frontend of protocol
3719 if (whereToSendOutput != DestRemote ||
3720 PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
3723 reporting_enabled = true;
3725 /* Transmit initial values of interesting variables */
3726 for (i = 0; i < num_guc_variables; i++)
3728 struct config_generic *conf = guc_variables[i];
3730 if (conf->flags & GUC_REPORT)
3731 ReportGUCOption(conf);
3736 * ReportGUCOption: if appropriate, transmit option value to frontend
3739 ReportGUCOption(struct config_generic * record)
3741 if (reporting_enabled && (record->flags & GUC_REPORT))
3743 char *val = _ShowOption(record, false);
3744 StringInfoData msgbuf;
3746 pq_beginmessage(&msgbuf, 'S');
3747 pq_sendstring(&msgbuf, record->name);
3748 pq_sendstring(&msgbuf, val);
3749 pq_endmessage(&msgbuf);
3757 * Try to interpret value as boolean value. Valid values are: true,
3758 * false, yes, no, on, off, 1, 0; as well as unique prefixes thereof.
3759 * If the string parses okay, return true, else false.
3760 * If okay and result is not NULL, return the value in *result.
3763 parse_bool(const char *value, bool *result)
3765 size_t len = strlen(value);
3767 if (pg_strncasecmp(value, "true", len) == 0)
3772 else if (pg_strncasecmp(value, "false", len) == 0)
3778 else if (pg_strncasecmp(value, "yes", len) == 0)
3783 else if (pg_strncasecmp(value, "no", len) == 0)
3789 /* 'o' is not unique enough */
3790 else if (pg_strncasecmp(value, "on", (len > 2 ? len : 2)) == 0)
3795 else if (pg_strncasecmp(value, "off", (len > 2 ? len : 2)) == 0)
3801 else if (pg_strcasecmp(value, "1") == 0)
3806 else if (pg_strcasecmp(value, "0") == 0)
3815 *result = false; /* suppress compiler warning */
3824 * Try to parse value as an integer. The accepted formats are the
3825 * usual decimal, octal, or hexadecimal formats, optionally followed by
3826 * a unit name if "flags" indicates a unit is allowed.
3828 * If the string parses okay, return true, else false.
3829 * If okay and result is not NULL, return the value in *result.
3830 * If not okay and hintmsg is not NULL, *hintmsg is set to a suitable
3831 * HINT message, or NULL if no hint provided.
3834 parse_int(const char *value, int *result, int flags, const char **hintmsg)
3839 /* To suppress compiler warnings, always set output params */
3845 /* We assume here that int64 is at least as wide as long */
3847 val = strtol(value, &endptr, 0);
3849 if (endptr == value)
3850 return false; /* no HINT for integer syntax error */
3852 if (errno == ERANGE || val != (int64) ((int32) val))
3855 *hintmsg = gettext_noop("Value exceeds integer range.");
3859 /* allow whitespace between integer and unit */
3860 while (isspace((unsigned char) *endptr))
3863 /* Handle possible unit */
3864 if (*endptr != '\0')
3867 * Note: the multiple-switch coding technique here is a bit tedious,
3868 * but seems necessary to avoid intermediate-value overflows.
3870 * If INT64_IS_BUSTED (ie, it's really int32) we will fail to detect
3871 * overflow due to units conversion, but there are few enough such
3872 * machines that it does not seem worth trying to be smarter.
3874 if (flags & GUC_UNIT_MEMORY)
3876 /* Set hint for use if no match or trailing garbage */
3878 *hintmsg = gettext_noop("Valid units for this parameter are \"kB\", \"MB\", and \"GB\".");
3880 #if BLCKSZ < 1024 || BLCKSZ > (1024*1024)
3881 #error BLCKSZ must be between 1KB and 1MB
3883 #if XLOG_BLCKSZ < 1024 || XLOG_BLCKSZ > (1024*1024)
3884 #error XLOG_BLCKSZ must be between 1KB and 1MB
3887 if (strncmp(endptr, "kB", 2) == 0)
3890 switch (flags & GUC_UNIT_MEMORY)
3892 case GUC_UNIT_BLOCKS:
3893 val /= (BLCKSZ / 1024);
3895 case GUC_UNIT_XBLOCKS:
3896 val /= (XLOG_BLCKSZ / 1024);
3900 else if (strncmp(endptr, "MB", 2) == 0)
3903 switch (flags & GUC_UNIT_MEMORY)
3908 case GUC_UNIT_BLOCKS:
3909 val *= KB_PER_MB / (BLCKSZ / 1024);
3911 case GUC_UNIT_XBLOCKS:
3912 val *= KB_PER_MB / (XLOG_BLCKSZ / 1024);
3916 else if (strncmp(endptr, "GB", 2) == 0)
3919 switch (flags & GUC_UNIT_MEMORY)
3924 case GUC_UNIT_BLOCKS:
3925 val *= KB_PER_GB / (BLCKSZ / 1024);
3927 case GUC_UNIT_XBLOCKS:
3928 val *= KB_PER_GB / (XLOG_BLCKSZ / 1024);
3933 else if (flags & GUC_UNIT_TIME)
3935 /* Set hint for use if no match or trailing garbage */
3937 *hintmsg = gettext_noop("Valid units for this parameter are \"ms\", \"s\", \"min\", \"h\", and \"d\".");
3939 if (strncmp(endptr, "ms", 2) == 0)
3942 switch (flags & GUC_UNIT_TIME)
3952 else if (strncmp(endptr, "s", 1) == 0)
3955 switch (flags & GUC_UNIT_TIME)
3965 else if (strncmp(endptr, "min", 3) == 0)
3968 switch (flags & GUC_UNIT_TIME)
3978 else if (strncmp(endptr, "h", 1) == 0)
3981 switch (flags & GUC_UNIT_TIME)
3994 else if (strncmp(endptr, "d", 1) == 0)
3997 switch (flags & GUC_UNIT_TIME)
4012 /* allow whitespace after unit */
4013 while (isspace((unsigned char) *endptr))
4016 if (*endptr != '\0')
4017 return false; /* appropriate hint, if any, already set */
4019 /* Check for overflow due to units conversion */
4020 if (val != (int64) ((int32) val))
4023 *hintmsg = gettext_noop("Value exceeds integer range.");
4029 *result = (int) val;
4036 * Try to parse value as a floating point number in the usual format.
4037 * If the string parses okay, return true, else false.
4038 * If okay and result is not NULL, return the value in *result.
4041 parse_real(const char *value, double *result)
4047 *result = 0; /* suppress compiler warning */
4050 val = strtod(value, &endptr);
4051 if (endptr == value || errno == ERANGE)
4054 /* allow whitespace after number */
4055 while (isspace((unsigned char) *endptr))
4057 if (*endptr != '\0')
4067 * Call a GucStringAssignHook function, being careful to free the
4068 * "newval" string if the hook ereports.
4070 * This is split out of set_config_option just to avoid the "volatile"
4071 * qualifiers that would otherwise have to be plastered all over.
4074 call_string_assign_hook(GucStringAssignHook assign_hook,
4075 char *newval, bool doit, GucSource source)
4081 result = (*assign_hook) (newval, doit, source);
4095 * Sets option `name' to given value. The value should be a string
4096 * which is going to be parsed and converted to the appropriate data
4097 * type. The context and source parameters indicate in which context this
4098 * function is being called so it can apply the access restrictions
4101 * If value is NULL, set the option to its default value. If the
4102 * parameter changeVal is false then don't really set the option but do all
4103 * the checks to see if it would work.
4105 * If there is an error (non-existing option, invalid value) then an
4106 * ereport(ERROR) is thrown *unless* this is called in a context where we
4107 * don't want to ereport (currently, startup or SIGHUP config file reread).
4108 * In that case we write a suitable error message via ereport(DEBUG) and
4109 * return false. This is working around the deficiencies in the ereport
4110 * mechanism, so don't blame me. In all other cases, the function
4111 * returns true, including cases where the input is valid but we chose
4112 * not to apply it because of context or source-priority considerations.
4114 * See also SetConfigOption for an external interface.
4117 set_config_option(const char *name, const char *value,
4118 GucContext context, GucSource source,
4119 bool isLocal, bool changeVal)
4121 struct config_generic *record;
4125 if (context == PGC_SIGHUP || source == PGC_S_DEFAULT)
4128 * To avoid cluttering the log, only the postmaster bleats loudly
4129 * about problems with the config file.
4131 elevel = IsUnderPostmaster ? DEBUG2 : LOG;
4133 else if (source == PGC_S_DATABASE || source == PGC_S_USER)
4138 record = find_option(name, elevel);
4142 (errcode(ERRCODE_UNDEFINED_OBJECT),
4143 errmsg("unrecognized configuration parameter \"%s\"", name)));
4148 * Do not replace a value that has been set on the command line by a SIGHUP
4151 if (context == PGC_SIGHUP && record->source == PGC_S_ARGV)
4155 * Check if the option can be set at this time. See guc.h for the precise
4156 * rules. Note that we don't want to throw errors if we're in the SIGHUP
4157 * context. In that case we just ignore the attempt and return true.
4159 switch (record->context)
4162 if (context == PGC_SIGHUP)
4164 if (context != PGC_INTERNAL)
4167 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4168 errmsg("parameter \"%s\" cannot be changed",
4173 case PGC_POSTMASTER:
4174 if (context == PGC_SIGHUP)
4176 if (changeVal && !is_newvalue_equal(record, value))
4178 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4179 errmsg("parameter \"%s\" cannot be changed after server start; configuration file change ignored",
4184 if (context != PGC_POSTMASTER)
4187 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4188 errmsg("parameter \"%s\" cannot be changed after server start",
4194 if (context != PGC_SIGHUP && context != PGC_POSTMASTER)
4197 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4198 errmsg("parameter \"%s\" cannot be changed now",
4204 * Hmm, the idea of the SIGHUP context is "ought to be global, but
4205 * can be changed after postmaster start". But there's nothing
4206 * that prevents a crafty administrator from sending SIGHUP
4207 * signals to individual backends only.
4211 if (context == PGC_SIGHUP)
4214 * If a PGC_BACKEND parameter is changed in the config file,
4215 * we want to accept the new value in the postmaster (whence
4216 * it will propagate to subsequently-started backends), but
4217 * ignore it in existing backends. This is a tad klugy, but
4218 * necessary because we don't re-read the config file during
4221 if (IsUnderPostmaster)
4224 else if (context != PGC_BACKEND && context != PGC_POSTMASTER)
4227 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4228 errmsg("parameter \"%s\" cannot be set after connection start",
4234 if (context == PGC_USERSET || context == PGC_BACKEND)
4237 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4238 errmsg("permission denied to set parameter \"%s\"",
4249 * Should we set reset/stacked values? (If so, the behavior is not
4250 * transactional.) This is done either when we get a default
4251 * value from the database's/user's/client's default settings or
4252 * when we reset a value to its default.
4254 makeDefault = changeVal && (source <= PGC_S_OVERRIDE)
4255 && ((value != NULL) || source == PGC_S_DEFAULT);
4258 * Ignore attempted set if overridden by previously processed
4259 * setting. However, if changeVal is false then plow ahead anyway
4260 * since we are trying to find out if the value is potentially
4261 * good, not actually use it. Also keep going if makeDefault is
4262 * true, since we may want to set the reset/stacked values even if
4263 * we can't set the variable itself. There's one exception to
4264 * this rule: if we want to apply the default value to variables
4265 * that were removed from the configuration file. This is
4266 * indicated by source == PGC_S_DEFAULT and context == PGC_SIGHUP.
4268 if (record->source > source
4269 && !(source == PGC_S_DEFAULT && context == PGC_SIGHUP))
4271 if (changeVal && !makeDefault)
4273 elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
4281 * Evaluate value and set variable.
4283 switch (record->vartype)
4287 struct config_bool *conf = (struct config_bool *) record;
4292 if (!parse_bool(value, &newval))
4295 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4296 errmsg("parameter \"%s\" requires a Boolean value",
4302 * If value == NULL and source == PGC_S_DEFAULT then
4303 * we reset some value to its default (removed from
4304 * configuration file).
4306 else if (source == PGC_S_DEFAULT)
4307 newval = conf->boot_val;
4308 /* else we handle a "RESET varname" command */
4311 newval = conf->reset_val;
4312 source = conf->gen.reset_source;
4315 if (conf->assign_hook)
4316 if (!(*conf->assign_hook) (newval, changeVal, source))
4319 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4320 errmsg("invalid value for parameter \"%s\": %d",
4321 name, (int) newval)));
4325 if (changeVal || makeDefault)
4327 /* Save old value to support transaction abort */
4329 push_old_value(&conf->gen);
4332 *conf->variable = newval;
4333 conf->gen.source = source;
4339 if (conf->gen.reset_source <= source)
4341 conf->reset_val = newval;
4342 conf->gen.reset_source = source;
4344 for (stack = conf->gen.stack; stack; stack = stack->prev)
4346 if (stack->source <= source)
4348 stack->value.boolval = newval;
4349 stack->source = source;
4355 conf->gen.status |= GUC_HAVE_LOCAL;
4360 conf->tentative_val = newval;
4361 conf->gen.tentative_source = source;
4362 conf->gen.status |= GUC_HAVE_TENTATIVE;
4371 struct config_int *conf = (struct config_int *) record;
4376 const char *hintmsg;
4378 if (!parse_int(value, &newval, conf->gen.flags, &hintmsg))
4381 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4382 errmsg("invalid value for parameter \"%s\": \"%s\"",
4384 hintmsg ? errhint(hintmsg) : 0));
4387 if (newval < conf->min || newval > conf->max)
4390 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4391 errmsg("%d is outside the valid range for parameter \"%s\" (%d .. %d)",
4392 newval, name, conf->min, conf->max)));
4397 * If value == NULL and source == PGC_S_DEFAULT then
4398 * we reset some value to its default (removed from
4399 * configuration file).
4401 else if (source == PGC_S_DEFAULT)
4402 newval = conf->boot_val;
4403 /* else we handle a "RESET varname" command */
4406 newval = conf->reset_val;
4407 source = conf->gen.reset_source;
4410 if (conf->assign_hook)
4411 if (!(*conf->assign_hook) (newval, changeVal, source))
4414 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4415 errmsg("invalid value for parameter \"%s\": %d",
4420 if (changeVal || makeDefault)
4422 /* Save old value to support transaction abort */
4424 push_old_value(&conf->gen);
4427 *conf->variable = newval;
4428 conf->gen.source = source;
4434 if (conf->gen.reset_source <= source)
4436 conf->reset_val = newval;
4437 conf->gen.reset_source = source;
4439 for (stack = conf->gen.stack; stack; stack = stack->prev)
4441 if (stack->source <= source)
4443 stack->value.intval = newval;
4444 stack->source = source;
4450 conf->gen.status |= GUC_HAVE_LOCAL;
4455 conf->tentative_val = newval;
4456 conf->gen.tentative_source = source;
4457 conf->gen.status |= GUC_HAVE_TENTATIVE;
4466 struct config_real *conf = (struct config_real *) record;
4471 if (!parse_real(value, &newval))
4474 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4475 errmsg("parameter \"%s\" requires a numeric value",
4479 if (newval < conf->min || newval > conf->max)
4482 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4483 errmsg("%g is outside the valid range for parameter \"%s\" (%g .. %g)",
4484 newval, name, conf->min, conf->max)));
4489 * If value == NULL and source == PGC_S_DEFAULT then
4490 * we reset some value to its default (removed from
4491 * configuration file).
4493 else if (source == PGC_S_DEFAULT)
4494 newval = conf->boot_val;
4495 /* else we handle a "RESET varname" command */
4498 newval = conf->reset_val;
4499 source = conf->gen.reset_source;
4502 if (conf->assign_hook)
4503 if (!(*conf->assign_hook) (newval, changeVal, source))
4506 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4507 errmsg("invalid value for parameter \"%s\": %g",
4512 if (changeVal || makeDefault)
4514 /* Save old value to support transaction abort */
4516 push_old_value(&conf->gen);
4519 *conf->variable = newval;
4520 conf->gen.source = source;
4526 if (conf->gen.reset_source <= source)
4528 conf->reset_val = newval;
4529 conf->gen.reset_source = source;
4531 for (stack = conf->gen.stack; stack; stack = stack->prev)
4533 if (stack->source <= source)
4535 stack->value.realval = newval;
4536 stack->source = source;
4542 conf->gen.status |= GUC_HAVE_LOCAL;
4547 conf->tentative_val = newval;
4548 conf->gen.tentative_source = source;
4549 conf->gen.status |= GUC_HAVE_TENTATIVE;
4558 struct config_string *conf = (struct config_string *) record;
4563 newval = guc_strdup(elevel, value);
4568 * The only sort of "parsing" check we need to do is apply
4569 * truncation if GUC_IS_NAME.
4571 if (conf->gen.flags & GUC_IS_NAME)
4572 truncate_identifier(newval, strlen(newval), true);
4575 * If value == NULL and source == PGC_S_DEFAULT then
4576 * we reset some value to its default (removed from
4577 * configuration file).
4579 else if (source == PGC_S_DEFAULT)
4581 if (conf->boot_val == NULL)
4585 newval = guc_strdup(elevel, conf->boot_val);
4590 /* else we handle a "RESET varname" command */
4591 else if (conf->reset_val)
4594 * We could possibly avoid strdup here, but easier to make
4595 * this case work the same as the normal assignment case.
4597 newval = guc_strdup(elevel, conf->reset_val);
4600 source = conf->gen.reset_source;
4604 /* Nothing to reset to, as yet; so do nothing */
4608 if (conf->assign_hook)
4610 const char *hookresult;
4613 * If the hook ereports, we have to make sure we free
4614 * newval, else it will be a permanent memory leak.
4616 hookresult = call_string_assign_hook(conf->assign_hook,
4620 if (hookresult == NULL)
4624 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4625 errmsg("invalid value for parameter \"%s\": \"%s\"",
4626 name, value ? value : "")));
4629 else if (hookresult != newval)
4634 * Having to cast away const here is annoying, but the
4635 * alternative is to declare assign_hooks as returning
4636 * char*, which would mean they'd have to cast away
4637 * const, or as both taking and returning char*, which
4638 * doesn't seem attractive either --- we don't want
4639 * them to scribble on the passed str.
4641 newval = (char *) hookresult;
4645 if (changeVal || makeDefault)
4647 /* Save old value to support transaction abort */
4649 push_old_value(&conf->gen);
4652 set_string_field(conf, conf->variable, newval);
4653 conf->gen.source = source;
4659 if (conf->gen.reset_source <= source)
4661 set_string_field(conf, &conf->reset_val, newval);
4662 conf->gen.reset_source = source;
4664 for (stack = conf->gen.stack; stack; stack = stack->prev)
4666 if (stack->source <= source)
4668 set_string_field(conf, &stack->value.stringval,
4670 stack->source = source;
4673 /* Perhaps we didn't install newval anywhere */
4674 if (!string_field_used(conf, newval))
4679 conf->gen.status |= GUC_HAVE_LOCAL;
4684 set_string_field(conf, &conf->tentative_val, newval);
4685 conf->gen.tentative_source = source;
4686 conf->gen.status |= GUC_HAVE_TENTATIVE;
4696 if (changeVal && (record->flags & GUC_REPORT))
4697 ReportGUCOption(record);
4704 * Set a config option to the given value. See also set_config_option,
4705 * this is just the wrapper to be called from outside GUC. NB: this
4706 * is used only for non-transactional operations.
4709 SetConfigOption(const char *name, const char *value,
4710 GucContext context, GucSource source)
4712 (void) set_config_option(name, value, context, source, false, true);
4718 * Fetch the current value of the option `name'. If the option doesn't exist,
4719 * throw an ereport and don't return.
4721 * The string is *not* allocated for modification and is really only
4722 * valid until the next call to configuration related functions.
4725 GetConfigOption(const char *name)
4727 struct config_generic *record;
4728 static char buffer[256];
4730 record = find_option(name, ERROR);
4733 (errcode(ERRCODE_UNDEFINED_OBJECT),
4734 errmsg("unrecognized configuration parameter \"%s\"", name)));
4735 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
4737 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4738 errmsg("must be superuser to examine \"%s\"", name)));
4740 switch (record->vartype)
4743 return *((struct config_bool *) record)->variable ? "on" : "off";
4746 snprintf(buffer, sizeof(buffer), "%d",
4747 *((struct config_int *) record)->variable);
4751 snprintf(buffer, sizeof(buffer), "%g",
4752 *((struct config_real *) record)->variable);
4756 return *((struct config_string *) record)->variable;
4762 * Get the RESET value associated with the given option.
4765 GetConfigOptionResetString(const char *name)
4767 struct config_generic *record;
4768 static char buffer[256];
4770 record = find_option(name, ERROR);
4773 (errcode(ERRCODE_UNDEFINED_OBJECT),
4774 errmsg("unrecognized configuration parameter \"%s\"", name)));
4775 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
4777 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4778 errmsg("must be superuser to examine \"%s\"", name)));
4780 switch (record->vartype)
4783 return ((struct config_bool *) record)->reset_val ? "on" : "off";
4786 snprintf(buffer, sizeof(buffer), "%d",
4787 ((struct config_int *) record)->reset_val);
4791 snprintf(buffer, sizeof(buffer), "%g",
4792 ((struct config_real *) record)->reset_val);
4796 return ((struct config_string *) record)->reset_val;
4802 * Detect whether the given configuration option can only be set by
4806 IsSuperuserConfigOption(const char *name)
4808 struct config_generic *record;
4810 record = find_option(name, ERROR);
4811 /* On an unrecognized name, don't error, just return false. */
4814 return (record->context == PGC_SUSET);
4819 * flatten_set_variable_args
4820 * Given a parsenode List as emitted by the grammar for SET,
4821 * convert to the flat string representation used by GUC.
4823 * We need to be told the name of the variable the args are for, because
4824 * the flattening rules vary (ugh).
4826 * The result is NULL if input is NIL (ie, SET ... TO DEFAULT), otherwise
4827 * a palloc'd string.
4830 flatten_set_variable_args(const char *name, List *args)
4832 struct config_generic *record;
4838 * Fast path if just DEFAULT. We do not check the variable name in this
4839 * case --- necessary for RESET ALL to work correctly.
4844 /* Else get flags for the variable */
4845 record = find_option(name, ERROR);
4848 (errcode(ERRCODE_UNDEFINED_OBJECT),
4849 errmsg("unrecognized configuration parameter \"%s\"", name)));
4851 flags = record->flags;
4853 /* Complain if list input and non-list variable */
4854 if ((flags & GUC_LIST_INPUT) == 0 &&
4855 list_length(args) != 1)
4857 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4858 errmsg("SET %s takes only one argument", name)));
4860 initStringInfo(&buf);
4864 A_Const *arg = (A_Const *) lfirst(l);
4867 if (l != list_head(args))
4868 appendStringInfo(&buf, ", ");
4870 if (!IsA(arg, A_Const))
4871 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
4873 switch (nodeTag(&arg->val))
4876 appendStringInfo(&buf, "%ld", intVal(&arg->val));
4879 /* represented as a string, so just copy it */
4880 appendStringInfoString(&buf, strVal(&arg->val));
4883 val = strVal(&arg->val);
4884 if (arg->typename != NULL)
4887 * Must be a ConstInterval argument for TIME ZONE. Coerce
4888 * to interval and back to normalize the value and account
4895 typmod = typenameTypeMod(NULL, arg->typename, INTERVALOID);
4898 DirectFunctionCall3(interval_in,
4899 CStringGetDatum(val),
4900 ObjectIdGetDatum(InvalidOid),
4901 Int32GetDatum(typmod));
4904 DatumGetCString(DirectFunctionCall1(interval_out,
4906 appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
4911 * Plain string literal or identifier. For quote mode,
4912 * quote it if it's not a vanilla identifier.
4914 if (flags & GUC_LIST_QUOTE)
4915 appendStringInfoString(&buf, quote_identifier(val));
4917 appendStringInfoString(&buf, val);
4921 elog(ERROR, "unrecognized node type: %d",
4922 (int) nodeTag(&arg->val));
4935 SetPGVariable(const char *name, List *args, bool is_local)
4937 char *argstring = flatten_set_variable_args(name, args);
4939 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
4940 set_config_option(name,
4942 (superuser() ? PGC_SUSET : PGC_USERSET),
4949 * SET command wrapped as a SQL callable function.
4952 set_config_by_name(PG_FUNCTION_ARGS)
4960 if (PG_ARGISNULL(0))
4962 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
4963 errmsg("SET requires parameter name")));
4965 /* Get the GUC variable name */
4966 name = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(0)));
4968 /* Get the desired value or set to NULL for a reset request */
4969 if (PG_ARGISNULL(1))
4972 value = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(1)));
4975 * Get the desired state of is_local. Default to false if provided value
4978 if (PG_ARGISNULL(2))
4981 is_local = PG_GETARG_BOOL(2);
4983 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
4984 set_config_option(name,
4986 (superuser() ? PGC_SUSET : PGC_USERSET),
4991 /* get the new current value */
4992 new_value = GetConfigOptionByName(name, NULL);
4994 /* Convert return string to text */
4995 result_text = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(new_value)));
4998 PG_RETURN_TEXT_P(result_text);
5002 define_custom_variable(struct config_generic * variable)
5004 const char *name = variable->name;
5005 const char **nameAddr = &name;
5007 struct config_string *pHolder;
5008 struct config_generic **res = (struct config_generic **) bsearch(
5010 (void *) guc_variables,
5012 sizeof(struct config_generic *),
5017 add_guc_variable(variable, ERROR);
5022 * This better be a placeholder
5024 if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
5026 (errcode(ERRCODE_INTERNAL_ERROR),
5027 errmsg("attempt to redefine parameter \"%s\"", name)));
5029 Assert((*res)->vartype == PGC_STRING);
5030 pHolder = (struct config_string *) * res;
5032 /* We have the same name, no sorting is necessary */
5035 value = *pHolder->variable;
5038 * Assign the string value stored in the placeholder to the real variable.
5040 * XXX this is not really good enough --- it should be a nontransactional
5041 * assignment, since we don't want it to roll back if the current xact
5044 set_config_option(name, value,
5045 pHolder->gen.context, pHolder->gen.source,
5049 * Free up as much as we conveniently can of the placeholder structure
5050 * (this neglects any stack items...)
5052 set_string_field(pHolder, pHolder->variable, NULL);
5053 set_string_field(pHolder, &pHolder->reset_val, NULL);
5054 set_string_field(pHolder, &pHolder->tentative_val, NULL);
5060 init_custom_variable(struct config_generic * gen,
5062 const char *short_desc,
5063 const char *long_desc,
5065 enum config_type type)
5067 gen->name = guc_strdup(ERROR, name);
5068 gen->context = context;
5069 gen->group = CUSTOM_OPTIONS;
5070 gen->short_desc = short_desc;
5071 gen->long_desc = long_desc;
5072 gen->vartype = type;
5076 DefineCustomBoolVariable(const char *name,
5077 const char *short_desc,
5078 const char *long_desc,
5081 GucBoolAssignHook assign_hook,
5082 GucShowHook show_hook)
5084 size_t sz = sizeof(struct config_bool);
5085 struct config_bool *var = (struct config_bool *) guc_malloc(ERROR, sz);
5088 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_BOOL);
5090 var->variable = valueAddr;
5091 var->reset_val = *valueAddr;
5092 var->assign_hook = assign_hook;
5093 var->show_hook = show_hook;
5094 define_custom_variable(&var->gen);
5098 DefineCustomIntVariable(const char *name,
5099 const char *short_desc,
5100 const char *long_desc,
5105 GucIntAssignHook assign_hook,
5106 GucShowHook show_hook)
5108 size_t sz = sizeof(struct config_int);
5109 struct config_int *var = (struct config_int *) guc_malloc(ERROR, sz);
5112 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_INT);
5114 var->variable = valueAddr;
5115 var->reset_val = *valueAddr;
5116 var->min = minValue;
5117 var->max = maxValue;
5118 var->assign_hook = assign_hook;
5119 var->show_hook = show_hook;
5120 define_custom_variable(&var->gen);
5124 DefineCustomRealVariable(const char *name,
5125 const char *short_desc,
5126 const char *long_desc,
5131 GucRealAssignHook assign_hook,
5132 GucShowHook show_hook)
5134 size_t sz = sizeof(struct config_real);
5135 struct config_real *var = (struct config_real *) guc_malloc(ERROR, sz);
5138 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_REAL);
5140 var->variable = valueAddr;
5141 var->reset_val = *valueAddr;
5142 var->min = minValue;
5143 var->max = maxValue;
5144 var->assign_hook = assign_hook;
5145 var->show_hook = show_hook;
5146 define_custom_variable(&var->gen);
5150 DefineCustomStringVariable(const char *name,
5151 const char *short_desc,
5152 const char *long_desc,
5155 GucStringAssignHook assign_hook,
5156 GucShowHook show_hook)
5158 size_t sz = sizeof(struct config_string);
5159 struct config_string *var = (struct config_string *) guc_malloc(ERROR, sz);
5162 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_STRING);
5164 var->variable = valueAddr;
5165 var->reset_val = *valueAddr;
5166 var->assign_hook = assign_hook;
5167 var->show_hook = show_hook;
5168 define_custom_variable(&var->gen);
5172 EmitWarningsOnPlaceholders(const char *className)
5174 struct config_generic **vars = guc_variables;
5175 struct config_generic **last = vars + num_guc_variables;
5177 int nameLen = strlen(className);
5181 struct config_generic *var = *vars++;
5183 if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
5184 strncmp(className, var->name, nameLen) == 0 &&
5185 var->name[nameLen] == GUC_QUALIFIER_SEPARATOR)
5188 (errcode(ERRCODE_UNDEFINED_OBJECT),
5189 errmsg("unrecognized configuration parameter \"%s\"", var->name)));
5199 GetPGVariable(const char *name, DestReceiver *dest)
5201 if (pg_strcasecmp(name, "all") == 0)
5202 ShowAllGUCConfig(dest);
5204 ShowGUCConfigOption(name, dest);
5208 GetPGVariableResultDesc(const char *name)
5212 if (pg_strcasecmp(name, "all") == 0)
5214 /* need a tuple descriptor representing three TEXT columns */
5215 tupdesc = CreateTemplateTupleDesc(3, false);
5216 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
5218 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
5220 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
5226 const char *varname;
5228 /* Get the canonical spelling of name */
5229 (void) GetConfigOptionByName(name, &varname);
5231 /* need a tuple descriptor representing a single TEXT column */
5232 tupdesc = CreateTemplateTupleDesc(1, false);
5233 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
5243 ResetPGVariable(const char *name, bool isTopLevel)
5245 if (pg_strcasecmp(name, "all") == 0)
5248 set_config_option(name,
5250 (superuser() ? PGC_SUSET : PGC_USERSET),
5261 ShowGUCConfigOption(const char *name, DestReceiver *dest)
5263 TupOutputState *tstate;
5265 const char *varname;
5268 /* Get the value and canonical spelling of name */
5269 value = GetConfigOptionByName(name, &varname);
5271 /* need a tuple descriptor representing a single TEXT column */
5272 tupdesc = CreateTemplateTupleDesc(1, false);
5273 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
5276 /* prepare for projection of tuples */
5277 tstate = begin_tup_output_tupdesc(dest, tupdesc);
5280 do_text_output_oneline(tstate, value);
5282 end_tup_output(tstate);
5289 ShowAllGUCConfig(DestReceiver *dest)
5291 bool am_superuser = superuser();
5293 TupOutputState *tstate;
5297 /* need a tuple descriptor representing three TEXT columns */
5298 tupdesc = CreateTemplateTupleDesc(3, false);
5299 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
5301 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
5303 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
5307 /* prepare for projection of tuples */
5308 tstate = begin_tup_output_tupdesc(dest, tupdesc);
5310 for (i = 0; i < num_guc_variables; i++)
5312 struct config_generic *conf = guc_variables[i];
5314 if ((conf->flags & GUC_NO_SHOW_ALL) ||
5315 ((conf->flags & GUC_SUPERUSER_ONLY) && !am_superuser))
5318 /* assign to the values array */
5319 values[0] = (char *) conf->name;
5320 values[1] = _ShowOption(conf, true);
5321 values[2] = (char *) conf->short_desc;
5323 /* send it to dest */
5324 do_tup_output(tstate, values);
5327 if (values[1] != NULL)
5331 end_tup_output(tstate);
5335 * Return GUC variable value by name; optionally return canonical
5336 * form of name. Return value is palloc'd.
5339 GetConfigOptionByName(const char *name, const char **varname)
5341 struct config_generic *record;
5343 record = find_option(name, ERROR);
5346 (errcode(ERRCODE_UNDEFINED_OBJECT),
5347 errmsg("unrecognized configuration parameter \"%s\"", name)));
5348 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
5350 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5351 errmsg("must be superuser to examine \"%s\"", name)));
5354 *varname = record->name;
5356 return _ShowOption(record, true);
5360 * Return GUC variable value by variable number; optionally return canonical
5361 * form of name. Return value is palloc'd.
5364 GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
5367 struct config_generic *conf;
5369 /* check requested variable number valid */
5370 Assert((varnum >= 0) && (varnum < num_guc_variables));
5372 conf = guc_variables[varnum];
5376 if ((conf->flags & GUC_NO_SHOW_ALL) ||
5377 ((conf->flags & GUC_SUPERUSER_ONLY) && !superuser()))
5383 /* first get the generic attributes */
5386 values[0] = conf->name;
5388 /* setting : use _ShowOption in order to avoid duplicating the logic */
5389 values[1] = _ShowOption(conf, false);
5392 if (conf->vartype == PGC_INT)
5396 switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
5401 case GUC_UNIT_BLOCKS:
5402 snprintf(buf, sizeof(buf), "%dkB", BLCKSZ / 1024);
5405 case GUC_UNIT_XBLOCKS:
5406 snprintf(buf, sizeof(buf), "%dkB", XLOG_BLCKSZ / 1024);
5427 values[3] = config_group_names[conf->group];
5430 values[4] = conf->short_desc;
5433 values[5] = conf->long_desc;
5436 values[6] = GucContext_Names[conf->context];
5439 values[7] = config_type_names[conf->vartype];
5442 values[8] = GucSource_Names[conf->source];
5444 /* now get the type specifc attributes */
5445 switch (conf->vartype)
5459 struct config_int *lconf = (struct config_int *) conf;
5462 snprintf(buffer, sizeof(buffer), "%d", lconf->min);
5463 values[9] = pstrdup(buffer);
5466 snprintf(buffer, sizeof(buffer), "%d", lconf->max);
5467 values[10] = pstrdup(buffer);
5473 struct config_real *lconf = (struct config_real *) conf;
5476 snprintf(buffer, sizeof(buffer), "%g", lconf->min);
5477 values[9] = pstrdup(buffer);
5480 snprintf(buffer, sizeof(buffer), "%g", lconf->max);
5481 values[10] = pstrdup(buffer);
5498 * should never get here, but in case we do, set 'em to NULL
5512 * Return the total number of GUC variables
5515 GetNumConfigOptions(void)
5517 return num_guc_variables;
5521 * show_config_by_name - equiv to SHOW X command but implemented as
5525 show_config_by_name(PG_FUNCTION_ARGS)
5531 /* Get the GUC variable name */
5532 varname = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(0)));
5535 varval = GetConfigOptionByName(varname, NULL);
5537 /* Convert to text */
5538 result_text = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(varval)));
5541 PG_RETURN_TEXT_P(result_text);
5545 * show_all_settings - equiv to SHOW ALL command but implemented as
5548 #define NUM_PG_SETTINGS_ATTS 11
5551 show_all_settings(PG_FUNCTION_ARGS)
5553 FuncCallContext *funcctx;
5557 AttInMetadata *attinmeta;
5558 MemoryContext oldcontext;
5560 /* stuff done only on the first call of the function */
5561 if (SRF_IS_FIRSTCALL())
5563 /* create a function context for cross-call persistence */
5564 funcctx = SRF_FIRSTCALL_INIT();
5567 * switch to memory context appropriate for multiple function calls
5569 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
5572 * need a tuple descriptor representing NUM_PG_SETTINGS_ATTS columns
5573 * of the appropriate types
5575 tupdesc = CreateTemplateTupleDesc(NUM_PG_SETTINGS_ATTS, false);
5576 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
5578 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
5580 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "unit",
5582 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "category",
5584 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "short_desc",
5586 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "extra_desc",
5588 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "context",
5590 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "vartype",
5592 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "source",
5594 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "min_val",
5596 TupleDescInitEntry(tupdesc, (AttrNumber) 11, "max_val",
5600 * Generate attribute metadata needed later to produce tuples from raw
5603 attinmeta = TupleDescGetAttInMetadata(tupdesc);
5604 funcctx->attinmeta = attinmeta;
5606 /* total number of tuples to be returned */
5607 funcctx->max_calls = GetNumConfigOptions();
5609 MemoryContextSwitchTo(oldcontext);
5612 /* stuff done on every call of the function */
5613 funcctx = SRF_PERCALL_SETUP();
5615 call_cntr = funcctx->call_cntr;
5616 max_calls = funcctx->max_calls;
5617 attinmeta = funcctx->attinmeta;
5619 if (call_cntr < max_calls) /* do when there is more left to send */
5621 char *values[NUM_PG_SETTINGS_ATTS];
5627 * Get the next visible GUC variable name and value
5631 GetConfigOptionByNum(call_cntr, (const char **) values, &noshow);
5634 /* bump the counter and get the next config setting */
5635 call_cntr = ++funcctx->call_cntr;
5637 /* make sure we haven't gone too far now */
5638 if (call_cntr >= max_calls)
5639 SRF_RETURN_DONE(funcctx);
5644 tuple = BuildTupleFromCStrings(attinmeta, values);
5646 /* make the tuple into a datum */
5647 result = HeapTupleGetDatum(tuple);
5649 SRF_RETURN_NEXT(funcctx, result);
5653 /* do when there is no more left */
5654 SRF_RETURN_DONE(funcctx);
5659 _ShowOption(struct config_generic * record, bool use_units)
5664 switch (record->vartype)
5668 struct config_bool *conf = (struct config_bool *) record;
5670 if (conf->show_hook)
5671 val = (*conf->show_hook) ();
5673 val = *conf->variable ? "on" : "off";
5679 struct config_int *conf = (struct config_int *) record;
5681 if (conf->show_hook)
5682 val = (*conf->show_hook) ();
5686 int result = *conf->variable;
5688 if (use_units && result > 0 && (record->flags & GUC_UNIT_MEMORY))
5690 switch (record->flags & GUC_UNIT_MEMORY)
5692 case GUC_UNIT_BLOCKS:
5693 result *= BLCKSZ / 1024;
5695 case GUC_UNIT_XBLOCKS:
5696 result *= XLOG_BLCKSZ / 1024;
5700 if (result % KB_PER_GB == 0)
5702 result /= KB_PER_GB;
5705 else if (result % KB_PER_MB == 0)
5707 result /= KB_PER_MB;
5715 else if (use_units && result > 0 && (record->flags & GUC_UNIT_TIME))
5717 switch (record->flags & GUC_UNIT_TIME)
5723 result *= MS_PER_MIN;
5727 if (result % MS_PER_D == 0)
5732 else if (result % MS_PER_H == 0)
5737 else if (result % MS_PER_MIN == 0)
5739 result /= MS_PER_MIN;
5740 strcpy(unit, "min");
5742 else if (result % MS_PER_S == 0)
5755 snprintf(buffer, sizeof(buffer), "%d%s",
5756 (int) result, unit);
5764 struct config_real *conf = (struct config_real *) record;
5766 if (conf->show_hook)
5767 val = (*conf->show_hook) ();
5770 snprintf(buffer, sizeof(buffer), "%g",
5779 struct config_string *conf = (struct config_string *) record;
5781 if (conf->show_hook)
5782 val = (*conf->show_hook) ();
5783 else if (*conf->variable && **conf->variable)
5784 val = *conf->variable;
5791 /* just to keep compiler quiet */
5796 return pstrdup(val);
5801 is_newvalue_equal(struct config_generic * record, const char *newvalue)
5803 switch (record->vartype)
5807 struct config_bool *conf = (struct config_bool *) record;
5810 return parse_bool(newvalue, &newval)
5811 && *conf->variable == newval;
5815 struct config_int *conf = (struct config_int *) record;
5818 return parse_int(newvalue, &newval, record->flags, NULL)
5819 && *conf->variable == newval;
5823 struct config_real *conf = (struct config_real *) record;
5826 return parse_real(newvalue, &newval)
5827 && *conf->variable == newval;
5831 struct config_string *conf = (struct config_string *) record;
5833 return strcmp(*conf->variable, newvalue) == 0;
5844 * This routine dumps out all non-default GUC options into a binary
5845 * file that is read by all exec'ed backends. The format is:
5847 * variable name, string, null terminated
5848 * variable value, string, null terminated
5849 * variable source, integer
5852 write_nondefault_variables(GucContext context)
5858 Assert(context == PGC_POSTMASTER || context == PGC_SIGHUP);
5860 elevel = (context == PGC_SIGHUP) ? LOG : ERROR;
5865 fp = AllocateFile(CONFIG_EXEC_PARAMS_NEW, "w");
5869 (errcode_for_file_access(),
5870 errmsg("could not write to file \"%s\": %m",
5871 CONFIG_EXEC_PARAMS_NEW)));
5875 for (i = 0; i < num_guc_variables; i++)
5877 struct config_generic *gconf = guc_variables[i];
5879 if (gconf->source != PGC_S_DEFAULT)
5881 fprintf(fp, "%s", gconf->name);
5884 switch (gconf->vartype)
5888 struct config_bool *conf = (struct config_bool *) gconf;
5890 if (*conf->variable == 0)
5891 fprintf(fp, "false");
5893 fprintf(fp, "true");
5899 struct config_int *conf = (struct config_int *) gconf;
5901 fprintf(fp, "%d", *conf->variable);
5907 struct config_real *conf = (struct config_real *) gconf;
5909 /* Could lose precision here? */
5910 fprintf(fp, "%f", *conf->variable);
5916 struct config_string *conf = (struct config_string *) gconf;
5918 fprintf(fp, "%s", *conf->variable);
5925 fwrite(&gconf->source, sizeof(gconf->source), 1, fp);
5932 (errcode_for_file_access(),
5933 errmsg("could not write to file \"%s\": %m",
5934 CONFIG_EXEC_PARAMS_NEW)));
5939 * Put new file in place. This could delay on Win32, but we don't hold
5940 * any exclusive locks.
5942 rename(CONFIG_EXEC_PARAMS_NEW, CONFIG_EXEC_PARAMS);
5947 * Read string, including null byte from file
5949 * Return NULL on EOF and nothing read
5952 read_string_with_null(FILE *fp)
5961 if ((ch = fgetc(fp)) == EOF)
5966 elog(FATAL, "invalid format of exec config params file");
5969 str = guc_malloc(FATAL, maxlen);
5970 else if (i == maxlen)
5971 str = guc_realloc(FATAL, str, maxlen *= 2);
5980 * This routine loads a previous postmaster dump of its non-default
5984 read_nondefault_variables(void)
5994 fp = AllocateFile(CONFIG_EXEC_PARAMS, "r");
5997 /* File not found is fine */
5998 if (errno != ENOENT)
6000 (errcode_for_file_access(),
6001 errmsg("could not read from file \"%s\": %m",
6002 CONFIG_EXEC_PARAMS)));
6008 struct config_generic *record;
6010 if ((varname = read_string_with_null(fp)) == NULL)
6013 if ((record = find_option(varname, FATAL)) == NULL)
6014 elog(FATAL, "failed to locate variable %s in exec config params file", varname);
6015 if ((varvalue = read_string_with_null(fp)) == NULL)
6016 elog(FATAL, "invalid format of exec config params file");
6017 if (fread(&varsource, sizeof(varsource), 1, fp) == 0)
6018 elog(FATAL, "invalid format of exec config params file");
6020 (void) set_config_option(varname, varvalue, record->context,
6021 varsource, false, true);
6028 #endif /* EXEC_BACKEND */
6032 * A little "long argument" simulation, although not quite GNU
6033 * compliant. Takes a string of the form "some-option=some value" and
6034 * returns name = "some_option" and value = "some value" in malloc'ed
6035 * storage. Note that '-' is converted to '_' in the option name. If
6036 * there is no '=' in the input string then value will be NULL.
6039 ParseLongOption(const char *string, char **name, char **value)
6048 equal_pos = strcspn(string, "=");
6050 if (string[equal_pos] == '=')
6052 *name = guc_malloc(FATAL, equal_pos + 1);
6053 strlcpy(*name, string, equal_pos + 1);
6055 *value = guc_strdup(FATAL, &string[equal_pos + 1]);
6059 /* no equal sign in string */
6060 *name = guc_strdup(FATAL, string);
6064 for (cp = *name; *cp; cp++)
6071 * Handle options fetched from pg_database.datconfig or pg_authid.rolconfig.
6072 * The array parameter must be an array of TEXT (it must not be NULL).
6075 ProcessGUCArray(ArrayType *array, GucSource source)
6079 Assert(array != NULL);
6080 Assert(ARR_ELEMTYPE(array) == TEXTOID);
6081 Assert(ARR_NDIM(array) == 1);
6082 Assert(ARR_LBOUND(array)[0] == 1);
6083 Assert(source == PGC_S_DATABASE || source == PGC_S_USER);
6085 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
6093 d = array_ref(array, 1, &i,
6094 -1 /* varlenarray */ ,
6095 -1 /* TEXT's typlen */ ,
6096 false /* TEXT's typbyval */ ,
6097 'i' /* TEXT's typalign */ ,
6103 s = DatumGetCString(DirectFunctionCall1(textout, d));
6105 ParseLongOption(s, &name, &value);
6109 (errcode(ERRCODE_SYNTAX_ERROR),
6110 errmsg("could not parse setting for parameter \"%s\"", name)));
6116 * We process all these options at SUSET level. We assume that the
6117 * right to insert an option into pg_database or pg_authid was checked
6118 * when it was inserted.
6120 SetConfigOption(name, value, PGC_SUSET, source);
6130 * Add an entry to an option array. The array parameter may be NULL
6131 * to indicate the current table entry is NULL.
6134 GUCArrayAdd(ArrayType *array, const char *name, const char *value)
6136 const char *varname;
6144 /* test if the option is valid */
6145 set_config_option(name, value,
6146 superuser() ? PGC_SUSET : PGC_USERSET,
6147 PGC_S_TEST, false, false);
6149 /* convert name to canonical spelling, so we can use plain strcmp */
6150 (void) GetConfigOptionByName(name, &varname);
6153 newval = palloc(strlen(name) + 1 + strlen(value) + 1);
6154 sprintf(newval, "%s=%s", name, value);
6155 datum = DirectFunctionCall1(textin, CStringGetDatum(newval));
6163 Assert(ARR_ELEMTYPE(array) == TEXTOID);
6164 Assert(ARR_NDIM(array) == 1);
6165 Assert(ARR_LBOUND(array)[0] == 1);
6167 index = ARR_DIMS(array)[0] + 1; /* add after end */
6169 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
6174 d = array_ref(array, 1, &i,
6175 -1 /* varlenarray */ ,
6176 -1 /* TEXT's typlen */ ,
6177 false /* TEXT's typbyval */ ,
6178 'i' /* TEXT's typalign */ ,
6182 current = DatumGetCString(DirectFunctionCall1(textout, d));
6183 if (strncmp(current, newval, strlen(name) + 1) == 0)
6190 a = array_set(array, 1, &index,
6193 -1 /* varlena array */ ,
6194 -1 /* TEXT's typlen */ ,
6195 false /* TEXT's typbyval */ ,
6196 'i' /* TEXT's typalign */ );
6199 a = construct_array(&datum, 1,
6208 * Delete an entry from an option array. The array parameter may be NULL
6209 * to indicate the current table entry is NULL. Also, if the return value
6210 * is NULL then a null should be stored.
6213 GUCArrayDelete(ArrayType *array, const char *name)
6215 const char *varname;
6216 ArrayType *newarray;
6222 /* test if the option is valid */
6223 set_config_option(name, NULL,
6224 superuser() ? PGC_SUSET : PGC_USERSET,
6225 PGC_S_TEST, false, false);
6227 /* convert name to canonical spelling, so we can use plain strcmp */
6228 (void) GetConfigOptionByName(name, &varname);
6231 /* if array is currently null, then surely nothing to delete */
6238 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
6244 d = array_ref(array, 1, &i,
6245 -1 /* varlenarray */ ,
6246 -1 /* TEXT's typlen */ ,
6247 false /* TEXT's typbyval */ ,
6248 'i' /* TEXT's typalign */ ,
6252 val = DatumGetCString(DirectFunctionCall1(textout, d));
6254 /* ignore entry if it's what we want to delete */
6255 if (strncmp(val, name, strlen(name)) == 0
6256 && val[strlen(name)] == '=')
6259 /* else add it to the output array */
6262 newarray = array_set(newarray, 1, &index,
6265 -1 /* varlenarray */ ,
6266 -1 /* TEXT's typlen */ ,
6267 false /* TEXT's typbyval */ ,
6268 'i' /* TEXT's typalign */ );
6271 newarray = construct_array(&d, 1,
6283 * assign_hook subroutines
6287 assign_log_destination(const char *value, bool doit, GucSource source)
6294 /* Need a modifiable copy of string */
6295 rawstring = pstrdup(value);
6297 /* Parse string into list of identifiers */
6298 if (!SplitIdentifierString(rawstring, ',', &elemlist))
6300 /* syntax error in list */
6302 list_free(elemlist);
6303 if (source >= PGC_S_INTERACTIVE)
6305 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6306 errmsg("invalid list syntax for parameter \"log_destination\"")));
6310 foreach(l, elemlist)
6312 char *tok = (char *) lfirst(l);
6314 if (pg_strcasecmp(tok, "stderr") == 0)
6315 newlogdest |= LOG_DESTINATION_STDERR;
6316 else if (pg_strcasecmp(tok, "csvlog") == 0)
6317 newlogdest |= LOG_DESTINATION_CSVLOG;
6319 else if (pg_strcasecmp(tok, "syslog") == 0)
6320 newlogdest |= LOG_DESTINATION_SYSLOG;
6323 else if (pg_strcasecmp(tok, "eventlog") == 0)
6324 newlogdest |= LOG_DESTINATION_EVENTLOG;
6328 if (source >= PGC_S_INTERACTIVE)
6330 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6331 errmsg("unrecognized \"log_destination\" key word: \"%s\"",
6334 list_free(elemlist);
6340 Log_destination = newlogdest;
6343 list_free(elemlist);
6351 assign_syslog_facility(const char *facility, bool doit, GucSource source)
6355 if (pg_strcasecmp(facility, "LOCAL0") == 0)
6356 syslog_fac = LOG_LOCAL0;
6357 else if (pg_strcasecmp(facility, "LOCAL1") == 0)
6358 syslog_fac = LOG_LOCAL1;
6359 else if (pg_strcasecmp(facility, "LOCAL2") == 0)
6360 syslog_fac = LOG_LOCAL2;
6361 else if (pg_strcasecmp(facility, "LOCAL3") == 0)
6362 syslog_fac = LOG_LOCAL3;
6363 else if (pg_strcasecmp(facility, "LOCAL4") == 0)
6364 syslog_fac = LOG_LOCAL4;
6365 else if (pg_strcasecmp(facility, "LOCAL5") == 0)
6366 syslog_fac = LOG_LOCAL5;
6367 else if (pg_strcasecmp(facility, "LOCAL6") == 0)
6368 syslog_fac = LOG_LOCAL6;
6369 else if (pg_strcasecmp(facility, "LOCAL7") == 0)
6370 syslog_fac = LOG_LOCAL7;
6372 return NULL; /* reject */
6376 syslog_facility = syslog_fac;
6377 set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
6385 assign_syslog_ident(const char *ident, bool doit, GucSource source)
6388 set_syslog_parameters(ident, syslog_facility);
6392 #endif /* HAVE_SYSLOG */
6396 assign_defaultxactisolevel(const char *newval, bool doit, GucSource source)
6398 if (pg_strcasecmp(newval, "serializable") == 0)
6401 DefaultXactIsoLevel = XACT_SERIALIZABLE;
6403 else if (pg_strcasecmp(newval, "repeatable read") == 0)
6406 DefaultXactIsoLevel = XACT_REPEATABLE_READ;
6408 else if (pg_strcasecmp(newval, "read committed") == 0)
6411 DefaultXactIsoLevel = XACT_READ_COMMITTED;
6413 else if (pg_strcasecmp(newval, "read uncommitted") == 0)
6416 DefaultXactIsoLevel = XACT_READ_UNCOMMITTED;
6424 assign_session_replication_role(const char *newval, bool doit, GucSource source)
6428 if (pg_strcasecmp(newval, "origin") == 0)
6429 newrole = SESSION_REPLICATION_ROLE_ORIGIN;
6430 else if (pg_strcasecmp(newval, "replica") == 0)
6431 newrole = SESSION_REPLICATION_ROLE_REPLICA;
6432 else if (pg_strcasecmp(newval, "local") == 0)
6433 newrole = SESSION_REPLICATION_ROLE_LOCAL;
6438 * Must flush the plan cache when changing replication role; but don't
6439 * flush unnecessarily.
6441 if (doit && SessionReplicationRole != newrole)
6444 SessionReplicationRole = newrole;
6451 assign_log_min_messages(const char *newval,
6452 bool doit, GucSource source)
6454 return (assign_msglvl(&log_min_messages, newval, doit, source));
6458 assign_client_min_messages(const char *newval, bool doit, GucSource source)
6460 return (assign_msglvl(&client_min_messages, newval, doit, source));
6464 assign_min_error_statement(const char *newval, bool doit, GucSource source)
6466 return (assign_msglvl(&log_min_error_statement, newval, doit, source));
6470 assign_msglvl(int *var, const char *newval, bool doit, GucSource source)
6472 if (pg_strcasecmp(newval, "debug") == 0)
6477 else if (pg_strcasecmp(newval, "debug5") == 0)
6482 else if (pg_strcasecmp(newval, "debug4") == 0)
6487 else if (pg_strcasecmp(newval, "debug3") == 0)
6492 else if (pg_strcasecmp(newval, "debug2") == 0)
6497 else if (pg_strcasecmp(newval, "debug1") == 0)
6502 else if (pg_strcasecmp(newval, "log") == 0)
6509 * Client_min_messages always prints 'info', but we allow it as a value
6512 else if (pg_strcasecmp(newval, "info") == 0)
6517 else if (pg_strcasecmp(newval, "notice") == 0)
6522 else if (pg_strcasecmp(newval, "warning") == 0)
6527 else if (pg_strcasecmp(newval, "error") == 0)
6532 /* We allow FATAL/PANIC for client-side messages too. */
6533 else if (pg_strcasecmp(newval, "fatal") == 0)
6538 else if (pg_strcasecmp(newval, "panic") == 0)
6544 return NULL; /* fail */
6545 return newval; /* OK */
6549 assign_log_error_verbosity(const char *newval, bool doit, GucSource source)
6551 if (pg_strcasecmp(newval, "terse") == 0)
6554 Log_error_verbosity = PGERROR_TERSE;
6556 else if (pg_strcasecmp(newval, "default") == 0)
6559 Log_error_verbosity = PGERROR_DEFAULT;
6561 else if (pg_strcasecmp(newval, "verbose") == 0)
6564 Log_error_verbosity = PGERROR_VERBOSE;
6567 return NULL; /* fail */
6568 return newval; /* OK */
6572 assign_log_statement(const char *newval, bool doit, GucSource source)
6574 if (pg_strcasecmp(newval, "none") == 0)
6577 log_statement = LOGSTMT_NONE;
6579 else if (pg_strcasecmp(newval, "ddl") == 0)
6582 log_statement = LOGSTMT_DDL;
6584 else if (pg_strcasecmp(newval, "mod") == 0)
6587 log_statement = LOGSTMT_MOD;
6589 else if (pg_strcasecmp(newval, "all") == 0)
6592 log_statement = LOGSTMT_ALL;
6595 return NULL; /* fail */
6596 return newval; /* OK */
6600 show_num_temp_buffers(void)
6603 * We show the GUC var until local buffers have been initialized, and
6604 * NLocBuffer afterwards.
6606 static char nbuf[32];
6608 sprintf(nbuf, "%d", NLocBuffer ? NLocBuffer : num_temp_buffers);
6613 assign_phony_autocommit(bool newval, bool doit, GucSource source)
6617 if (doit && source >= PGC_S_INTERACTIVE)
6619 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6620 errmsg("SET AUTOCOMMIT TO OFF is no longer supported")));
6627 assign_custom_variable_classes(const char *newval, bool doit, GucSource source)
6630 * Check syntax. newval must be a comma separated list of identifiers.
6631 * Whitespace is allowed but skipped.
6633 bool hasSpaceAfterToken = false;
6634 const char *cp = newval;
6640 * Resetting custom_variable_classes by removing it from the
6641 * configuration file will lead to newval = NULL
6644 return guc_strdup(ERROR, "");
6646 initStringInfo(&buf);
6647 while ((c = *cp++) != 0)
6649 if (isspace((unsigned char) c))
6652 hasSpaceAfterToken = true;
6658 hasSpaceAfterToken = false;
6662 appendStringInfoChar(&buf, ',');
6667 if (hasSpaceAfterToken || !isalnum((unsigned char) c))
6670 * Syntax error due to token following space after token or non
6671 * alpha numeric character
6674 (errcode(ERRCODE_SYNTAX_ERROR),
6675 errmsg("invalid syntax for \"custom_variable_classes\": \"%s\"", newval)));
6680 appendStringInfoChar(&buf, (char) c);
6683 /* Remove stray ',' at end */
6684 if (symLen == 0 && buf.len > 0)
6685 buf.data[--buf.len] = '\0';
6690 newval = guc_strdup(ERROR, buf.data);
6697 assign_debug_assertions(bool newval, bool doit, GucSource source)
6699 #ifndef USE_ASSERT_CHECKING
6702 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6703 errmsg("assertion checking is not supported by this build")));
6709 assign_ssl(bool newval, bool doit, GucSource source)
6714 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6715 errmsg("SSL is not supported by this build")));
6721 assign_stage_log_stats(bool newval, bool doit, GucSource source)
6723 if (newval && log_statement_stats)
6725 if (source >= PGC_S_INTERACTIVE)
6727 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6728 errmsg("cannot enable parameter when \"log_statement_stats\" is true")));
6729 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
6730 else if (source != PGC_S_OVERRIDE)
6737 assign_log_stats(bool newval, bool doit, GucSource source)
6740 (log_parser_stats || log_planner_stats || log_executor_stats))
6742 if (source >= PGC_S_INTERACTIVE)
6744 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6745 errmsg("cannot enable \"log_statement_stats\" when "
6746 "\"log_parser_stats\", \"log_planner_stats\", "
6747 "or \"log_executor_stats\" is true")));
6748 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
6749 else if (source != PGC_S_OVERRIDE)
6756 assign_transaction_read_only(bool newval, bool doit, GucSource source)
6758 /* Can't go to r/w mode inside a r/o transaction */
6759 if (newval == false && XactReadOnly && IsSubTransaction())
6761 if (source >= PGC_S_INTERACTIVE)
6763 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6764 errmsg("cannot set transaction read-write mode inside a read-only transaction")));
6765 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
6766 else if (source != PGC_S_OVERRIDE)
6773 assign_canonical_path(const char *newval, bool doit, GucSource source)
6777 char *canon_val = guc_strdup(ERROR, newval);
6779 canonicalize_path(canon_val);
6787 assign_backslash_quote(const char *newval, bool doit, GucSource source)
6789 BackslashQuoteType bq;
6793 * Although only "on", "off", and "safe_encoding" are documented, we use
6794 * parse_bool so we can accept all the likely variants of "on" and "off".
6796 if (pg_strcasecmp(newval, "safe_encoding") == 0)
6797 bq = BACKSLASH_QUOTE_SAFE_ENCODING;
6798 else if (parse_bool(newval, &bqbool))
6800 bq = bqbool ? BACKSLASH_QUOTE_ON : BACKSLASH_QUOTE_OFF;
6803 return NULL; /* reject */
6806 backslash_quote = bq;
6812 assign_timezone_abbreviations(const char *newval, bool doit, GucSource source)
6815 * The powerup value shown above for timezone_abbreviations is "UNKNOWN".
6816 * When we see this we just do nothing. If this value isn't overridden
6817 * from the config file then pg_timezone_abbrev_initialize() will
6818 * eventually replace it with "Default". This hack has two purposes: to
6819 * avoid wasting cycles loading values that might soon be overridden from
6820 * the config file, and to avoid trying to read the timezone abbrev files
6821 * during InitializeGUCOptions(). The latter doesn't work in an
6822 * EXEC_BACKEND subprocess because my_exec_path hasn't been set yet and so
6823 * we can't locate PGSHAREDIR. (Essentially the same hack is used to
6824 * delay initializing TimeZone ... if we have any more, we should try to
6825 * clean up and centralize this mechanism ...)
6827 if (strcmp(newval, "UNKNOWN") == 0)
6832 /* Loading abbrev file is expensive, so only do it when value changes */
6833 if (timezone_abbreviations_string == NULL ||
6834 strcmp(timezone_abbreviations_string, newval) != 0)
6839 * If reading config file, only the postmaster should bleat loudly
6840 * about problems. Otherwise, it's just this one process doing it,
6841 * and we use WARNING message level.
6843 if (source == PGC_S_FILE)
6844 elevel = IsUnderPostmaster ? DEBUG2 : LOG;
6847 if (!load_tzoffsets(newval, doit, elevel))
6854 * pg_timezone_abbrev_initialize --- set default value if not done already
6856 * This is called after initial loading of postgresql.conf. If no
6857 * timezone_abbreviations setting was found therein, select default.
6860 pg_timezone_abbrev_initialize(void)
6862 if (strcmp(timezone_abbreviations_string, "UNKNOWN") == 0)
6864 SetConfigOption("timezone_abbreviations", "Default",
6865 PGC_POSTMASTER, PGC_S_ARGV);
6870 assign_xmlbinary(const char *newval, bool doit, GucSource source)
6874 if (pg_strcasecmp(newval, "base64") == 0)
6875 xb = XMLBINARY_BASE64;
6876 else if (pg_strcasecmp(newval, "hex") == 0)
6879 return NULL; /* reject */
6888 assign_xmloption(const char *newval, bool doit, GucSource source)
6892 if (pg_strcasecmp(newval, "document") == 0)
6893 xo = XMLOPTION_DOCUMENT;
6894 else if (pg_strcasecmp(newval, "content") == 0)
6895 xo = XMLOPTION_CONTENT;
6897 return NULL; /* reject */
6906 assign_tcp_keepalives_idle(int newval, bool doit, GucSource source)
6909 return (pq_setkeepalivesidle(newval, MyProcPort) == STATUS_OK);
6915 show_tcp_keepalives_idle(void)
6917 static char nbuf[16];
6919 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesidle(MyProcPort));
6924 assign_tcp_keepalives_interval(int newval, bool doit, GucSource source)
6927 return (pq_setkeepalivesinterval(newval, MyProcPort) == STATUS_OK);
6933 show_tcp_keepalives_interval(void)
6935 static char nbuf[16];
6937 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesinterval(MyProcPort));
6942 assign_tcp_keepalives_count(int newval, bool doit, GucSource source)
6945 return (pq_setkeepalivescount(newval, MyProcPort) == STATUS_OK);
6951 show_tcp_keepalives_count(void)
6953 static char nbuf[16];
6955 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivescount(MyProcPort));
6960 assign_maxconnections(int newval, bool doit, GucSource source)
6962 if (newval + autovacuum_max_workers > INT_MAX / 4)
6966 MaxBackends = newval + autovacuum_max_workers;
6972 assign_autovacuum_max_workers(int newval, bool doit, GucSource source)
6974 if (newval + MaxConnections > INT_MAX / 4)
6978 MaxBackends = newval + MaxConnections;
6983 #include "guc-file.c"