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.384 2007/04/12 06:53:47 neilc 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 "storage/fd.h"
58 #include "storage/freespace.h"
59 #include "tcop/tcopprot.h"
60 #include "utils/builtins.h"
61 #include "utils/guc_tables.h"
62 #include "utils/memutils.h"
63 #include "utils/pg_locale.h"
64 #include "utils/plancache.h"
65 #include "utils/portal.h"
66 #include "utils/ps_status.h"
67 #include "utils/tzparser.h"
68 #include "utils/xml.h"
71 #define PG_KRB_SRVTAB ""
74 #define PG_KRB_SRVNAM ""
77 #define CONFIG_FILENAME "postgresql.conf"
78 #define HBA_FILENAME "pg_hba.conf"
79 #define IDENT_FILENAME "pg_ident.conf"
82 #define CONFIG_EXEC_PARAMS "global/config_exec_params"
83 #define CONFIG_EXEC_PARAMS_NEW "global/config_exec_params.new"
86 /* upper limit for GUC variables measured in kilobytes of memory */
88 #define MAX_KILOBYTES INT_MAX
90 #define MAX_KILOBYTES (INT_MAX / 1024)
93 #define KB_PER_MB (1024)
94 #define KB_PER_GB (1024*1024)
97 #define MS_PER_MIN (1000 * 60)
98 #define MS_PER_H (1000 * 60 * 60)
99 #define MS_PER_D (1000 * 60 * 60 * 24)
101 /* XXX these should appear in other modules' header files */
102 extern bool Log_disconnections;
103 extern int CommitDelay;
104 extern int CommitSiblings;
105 extern char *default_tablespace;
106 extern bool fullPageWrites;
109 extern bool trace_sort;
113 extern char *SSLCipherSuites;
117 static const char *assign_log_destination(const char *value,
118 bool doit, GucSource source);
121 static int syslog_facility = LOG_LOCAL0;
123 static const char *assign_syslog_facility(const char *facility,
124 bool doit, GucSource source);
125 static const char *assign_syslog_ident(const char *ident,
126 bool doit, GucSource source);
129 static const char *assign_defaultxactisolevel(const char *newval, bool doit,
131 static const char *assign_session_replication_role(const char *newval, bool doit,
133 static const char *assign_log_min_messages(const char *newval, bool doit,
135 static const char *assign_client_min_messages(const char *newval,
136 bool doit, GucSource source);
137 static const char *assign_min_error_statement(const char *newval, bool doit,
139 static const char *assign_msglvl(int *var, const char *newval, bool doit,
141 static const char *assign_log_error_verbosity(const char *newval, bool doit,
143 static const char *assign_log_statement(const char *newval, bool doit,
145 static const char *show_num_temp_buffers(void);
146 static bool assign_phony_autocommit(bool newval, bool doit, GucSource source);
147 static const char *assign_custom_variable_classes(const char *newval, bool doit,
149 static bool assign_debug_assertions(bool newval, bool doit, GucSource source);
150 static bool assign_ssl(bool newval, bool doit, GucSource source);
151 static bool assign_stage_log_stats(bool newval, bool doit, GucSource source);
152 static bool assign_log_stats(bool newval, bool doit, GucSource source);
153 static bool assign_transaction_read_only(bool newval, bool doit, GucSource source);
154 static const char *assign_canonical_path(const char *newval, bool doit, GucSource source);
155 static const char *assign_backslash_quote(const char *newval, bool doit, GucSource source);
156 static const char *assign_timezone_abbreviations(const char *newval, bool doit, GucSource source);
157 static const char *assign_xmlbinary(const char *newval, bool doit, GucSource source);
158 static const char *assign_xmloption(const char *newval, bool doit, GucSource source);
160 static bool assign_tcp_keepalives_idle(int newval, bool doit, GucSource source);
161 static bool assign_tcp_keepalives_interval(int newval, bool doit, GucSource source);
162 static bool assign_tcp_keepalives_count(int newval, bool doit, GucSource source);
163 static const char *show_tcp_keepalives_idle(void);
164 static const char *show_tcp_keepalives_interval(void);
165 static const char *show_tcp_keepalives_count(void);
168 * GUC option variables that are exported from this module
170 #ifdef USE_ASSERT_CHECKING
171 bool assert_enabled = true;
173 bool assert_enabled = false;
175 bool log_duration = false;
176 bool Debug_print_plan = false;
177 bool Debug_print_parse = false;
178 bool Debug_print_rewritten = false;
179 bool Debug_pretty_print = false;
180 bool Explain_pretty_print = true;
182 bool log_parser_stats = false;
183 bool log_planner_stats = false;
184 bool log_executor_stats = false;
185 bool log_statement_stats = false; /* this is sort of all three
187 bool log_btree_build_stats = false;
189 bool check_function_bodies = true;
190 bool default_with_oids = false;
191 bool SQL_inheritance = true;
193 bool Password_encryption = true;
195 int log_min_error_statement = ERROR;
196 int log_min_messages = NOTICE;
197 int client_min_messages = NOTICE;
198 int log_min_duration_statement = -1;
199 int log_temp_files = -1;
201 int num_temp_buffers = 1000;
203 char *ConfigFileName;
206 char *external_pid_file;
208 int tcp_keepalives_idle;
209 int tcp_keepalives_interval;
210 int tcp_keepalives_count;
213 * These variables are all dummies that don't do anything, except in some
214 * cases provide the value for SHOW to display. The real state is elsewhere
215 * and is kept in sync by assign_hooks.
217 static char *client_min_messages_str;
218 static char *log_min_messages_str;
219 static char *log_error_verbosity_str;
220 static char *log_statement_str;
221 static char *log_min_error_statement_str;
222 static char *log_destination_string;
225 static char *syslog_facility_str;
226 static char *syslog_ident_str;
228 static bool phony_autocommit;
229 static bool session_auth_is_superuser;
230 static double phony_random_seed;
231 static char *backslash_quote_string;
232 static char *client_encoding_string;
233 static char *datestyle_string;
234 static char *default_iso_level_string;
235 static char *session_replication_role_string;
236 static char *locale_collate;
237 static char *locale_ctype;
238 static char *regex_flavor_string;
239 static char *server_encoding_string;
240 static char *server_version_string;
241 static int server_version_num;
242 static char *timezone_string;
243 static char *timezone_abbreviations_string;
244 static char *XactIsoLevel_string;
245 static char *data_directory;
246 static char *custom_variable_classes;
247 static char *xmlbinary_string;
248 static char *xmloption_string;
249 static int max_function_args;
250 static int max_index_keys;
251 static int max_identifier_length;
252 static int block_size;
253 static bool integer_datetimes;
255 /* should be static, but commands/variable.c needs to get at these */
257 char *session_authorization_string;
261 * Displayable names for context types (enum GucContext)
263 * Note: these strings are deliberately not localized.
265 const char *const GucContext_Names[] =
267 /* PGC_INTERNAL */ "internal",
268 /* PGC_POSTMASTER */ "postmaster",
269 /* PGC_SIGHUP */ "sighup",
270 /* PGC_BACKEND */ "backend",
271 /* PGC_SUSET */ "superuser",
272 /* PGC_USERSET */ "user"
276 * Displayable names for source types (enum GucSource)
278 * Note: these strings are deliberately not localized.
280 const char *const GucSource_Names[] =
282 /* PGC_S_DEFAULT */ "default",
283 /* PGC_S_ENV_VAR */ "environment variable",
284 /* PGC_S_FILE */ "configuration file",
285 /* PGC_S_ARGV */ "command line",
286 /* PGC_S_DATABASE */ "database",
287 /* PGC_S_USER */ "user",
288 /* PGC_S_CLIENT */ "client",
289 /* PGC_S_OVERRIDE */ "override",
290 /* PGC_S_INTERACTIVE */ "interactive",
291 /* PGC_S_TEST */ "test",
292 /* PGC_S_SESSION */ "session"
296 * Displayable names for the groupings defined in enum config_group
298 const char *const config_group_names[] =
301 gettext_noop("Ungrouped"),
303 gettext_noop("File Locations"),
305 gettext_noop("Connections and Authentication"),
306 /* CONN_AUTH_SETTINGS */
307 gettext_noop("Connections and Authentication / Connection Settings"),
308 /* CONN_AUTH_SECURITY */
309 gettext_noop("Connections and Authentication / Security and Authentication"),
311 gettext_noop("Resource Usage"),
313 gettext_noop("Resource Usage / Memory"),
315 gettext_noop("Resource Usage / Free Space Map"),
316 /* RESOURCES_KERNEL */
317 gettext_noop("Resource Usage / Kernel Resources"),
319 gettext_noop("Write-Ahead Log"),
321 gettext_noop("Write-Ahead Log / Settings"),
322 /* WAL_CHECKPOINTS */
323 gettext_noop("Write-Ahead Log / Checkpoints"),
325 gettext_noop("Query Tuning"),
326 /* QUERY_TUNING_METHOD */
327 gettext_noop("Query Tuning / Planner Method Configuration"),
328 /* QUERY_TUNING_COST */
329 gettext_noop("Query Tuning / Planner Cost Constants"),
330 /* QUERY_TUNING_GEQO */
331 gettext_noop("Query Tuning / Genetic Query Optimizer"),
332 /* QUERY_TUNING_OTHER */
333 gettext_noop("Query Tuning / Other Planner Options"),
335 gettext_noop("Reporting and Logging"),
337 gettext_noop("Reporting and Logging / Where to Log"),
339 gettext_noop("Reporting and Logging / When to Log"),
341 gettext_noop("Reporting and Logging / What to Log"),
343 gettext_noop("Statistics"),
344 /* STATS_MONITORING */
345 gettext_noop("Statistics / Monitoring"),
346 /* STATS_COLLECTOR */
347 gettext_noop("Statistics / Query and Index Statistics Collector"),
349 gettext_noop("Autovacuum"),
351 gettext_noop("Client Connection Defaults"),
352 /* CLIENT_CONN_STATEMENT */
353 gettext_noop("Client Connection Defaults / Statement Behavior"),
354 /* CLIENT_CONN_LOCALE */
355 gettext_noop("Client Connection Defaults / Locale and Formatting"),
356 /* CLIENT_CONN_OTHER */
357 gettext_noop("Client Connection Defaults / Other Defaults"),
358 /* LOCK_MANAGEMENT */
359 gettext_noop("Lock Management"),
361 gettext_noop("Version and Platform Compatibility"),
362 /* COMPAT_OPTIONS_PREVIOUS */
363 gettext_noop("Version and Platform Compatibility / Previous PostgreSQL Versions"),
364 /* COMPAT_OPTIONS_CLIENT */
365 gettext_noop("Version and Platform Compatibility / Other Platforms and Clients"),
367 gettext_noop("Preset Options"),
369 gettext_noop("Customized Options"),
370 /* DEVELOPER_OPTIONS */
371 gettext_noop("Developer Options"),
372 /* help_config wants this array to be null-terminated */
377 * Displayable names for GUC variable types (enum config_type)
379 * Note: these strings are deliberately not localized.
381 const char *const config_type_names[] =
383 /* PGC_BOOL */ "bool",
384 /* PGC_INT */ "integer",
385 /* PGC_REAL */ "real",
386 /* PGC_STRING */ "string"
391 * Contents of GUC tables
393 * See src/backend/utils/misc/README for design notes.
397 * 1. Declare a global variable of type bool, int, double, or char*
398 * and make use of it.
400 * 2. Decide at what times it's safe to set the option. See guc.h for
403 * 3. Decide on a name, a default value, upper and lower bounds (if
406 * 4. Add a record below.
408 * 5. Add it to src/backend/utils/misc/postgresql.conf.sample, if
411 * 6. Add it to src/bin/psql/tab-complete.c, if it's a USERSET option.
413 * 7. Don't forget to document the option.
415 * 8. If it's a new GUC_LIST option you must edit pg_dumpall.c to ensure
416 * it is not single quoted at dump time.
420 /******** option records follow ********/
422 static struct config_bool ConfigureNamesBool[] =
425 {"enable_seqscan", PGC_USERSET, QUERY_TUNING_METHOD,
426 gettext_noop("Enables the planner's use of sequential-scan plans."),
433 {"enable_indexscan", PGC_USERSET, QUERY_TUNING_METHOD,
434 gettext_noop("Enables the planner's use of index-scan plans."),
441 {"enable_bitmapscan", PGC_USERSET, QUERY_TUNING_METHOD,
442 gettext_noop("Enables the planner's use of bitmap-scan plans."),
449 {"enable_tidscan", PGC_USERSET, QUERY_TUNING_METHOD,
450 gettext_noop("Enables the planner's use of TID scan plans."),
457 {"enable_sort", PGC_USERSET, QUERY_TUNING_METHOD,
458 gettext_noop("Enables the planner's use of explicit sort steps."),
465 {"enable_hashagg", PGC_USERSET, QUERY_TUNING_METHOD,
466 gettext_noop("Enables the planner's use of hashed aggregation plans."),
473 {"enable_nestloop", PGC_USERSET, QUERY_TUNING_METHOD,
474 gettext_noop("Enables the planner's use of nested-loop join plans."),
481 {"enable_mergejoin", PGC_USERSET, QUERY_TUNING_METHOD,
482 gettext_noop("Enables the planner's use of merge join plans."),
489 {"enable_hashjoin", PGC_USERSET, QUERY_TUNING_METHOD,
490 gettext_noop("Enables the planner's use of hash join plans."),
497 {"constraint_exclusion", PGC_USERSET, QUERY_TUNING_OTHER,
498 gettext_noop("Enables the planner to use constraints to optimize queries."),
499 gettext_noop("Child table scans will be skipped if their "
500 "constraints guarantee that no rows match the query.")
502 &constraint_exclusion,
506 {"geqo", PGC_USERSET, QUERY_TUNING_GEQO,
507 gettext_noop("Enables genetic query optimization."),
508 gettext_noop("This algorithm attempts to do planning without "
509 "exhaustive searching.")
515 /* Not for general use --- used by SET SESSION AUTHORIZATION */
516 {"is_superuser", PGC_INTERNAL, UNGROUPED,
517 gettext_noop("Shows whether the current user is a superuser."),
519 GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
521 &session_auth_is_superuser,
525 {"ssl", PGC_POSTMASTER, CONN_AUTH_SECURITY,
526 gettext_noop("Enables SSL connections."),
530 false, assign_ssl, NULL
533 {"fsync", PGC_SIGHUP, WAL_SETTINGS,
534 gettext_noop("Forces synchronization of updates to disk."),
535 gettext_noop("The server will use the fsync() system call in several places to make "
536 "sure that updates are physically written to disk. This insures "
537 "that a database cluster will recover to a consistent state after "
538 "an operating system or hardware crash.")
544 {"zero_damaged_pages", PGC_SUSET, DEVELOPER_OPTIONS,
545 gettext_noop("Continues processing past damaged page headers."),
546 gettext_noop("Detection of a damaged page header normally causes PostgreSQL to "
547 "report an error, aborting the current transaction. Setting "
548 "zero_damaged_pages to true causes the system to instead report a "
549 "warning, zero out the damaged page, and continue processing. This "
550 "behavior will destroy data, namely all the rows on the damaged page."),
557 {"full_page_writes", PGC_SIGHUP, WAL_SETTINGS,
558 gettext_noop("Writes full pages to WAL when first modified after a checkpoint."),
559 gettext_noop("A page write in process during an operating system crash might be "
560 "only partially written to disk. During recovery, the row changes "
561 "stored in WAL are not enough to recover. This option writes "
562 "pages when first modified after a checkpoint to WAL so full recovery "
569 {"silent_mode", PGC_POSTMASTER, LOGGING_WHEN,
570 gettext_noop("Runs the server silently."),
571 gettext_noop("If this parameter is set, the server will automatically run in the "
572 "background and any controlling terminals are dissociated.")
578 {"log_connections", PGC_BACKEND, LOGGING_WHAT,
579 gettext_noop("Logs each successful connection."),
586 {"log_disconnections", PGC_BACKEND, LOGGING_WHAT,
587 gettext_noop("Logs end of a session, including duration."),
594 {"debug_assertions", PGC_USERSET, DEVELOPER_OPTIONS,
595 gettext_noop("Turns on various assertion checks."),
596 gettext_noop("This is a debugging aid."),
600 #ifdef USE_ASSERT_CHECKING
605 assign_debug_assertions, NULL
608 /* currently undocumented, so don't show in SHOW ALL */
609 {"exit_on_error", PGC_USERSET, UNGROUPED,
610 gettext_noop("No description available."),
612 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
618 {"log_duration", PGC_SUSET, LOGGING_WHAT,
619 gettext_noop("Logs the duration of each completed SQL statement."),
626 {"debug_print_parse", PGC_USERSET, LOGGING_WHAT,
627 gettext_noop("Prints the parse tree to the server log."),
634 {"debug_print_rewritten", PGC_USERSET, LOGGING_WHAT,
635 gettext_noop("Prints the parse tree after rewriting to server log."),
638 &Debug_print_rewritten,
642 {"debug_print_plan", PGC_USERSET, LOGGING_WHAT,
643 gettext_noop("Prints the execution plan to server log."),
650 {"debug_pretty_print", PGC_USERSET, LOGGING_WHAT,
651 gettext_noop("Indents parse and plan tree displays."),
658 {"log_parser_stats", PGC_SUSET, STATS_MONITORING,
659 gettext_noop("Writes parser performance statistics to the server log."),
663 false, assign_stage_log_stats, NULL
666 {"log_planner_stats", PGC_SUSET, STATS_MONITORING,
667 gettext_noop("Writes planner performance statistics to the server log."),
671 false, assign_stage_log_stats, NULL
674 {"log_executor_stats", PGC_SUSET, STATS_MONITORING,
675 gettext_noop("Writes executor performance statistics to the server log."),
679 false, assign_stage_log_stats, NULL
682 {"log_statement_stats", PGC_SUSET, STATS_MONITORING,
683 gettext_noop("Writes cumulative performance statistics to the server log."),
686 &log_statement_stats,
687 false, assign_log_stats, NULL
689 #ifdef BTREE_BUILD_STATS
691 {"log_btree_build_stats", PGC_SUSET, DEVELOPER_OPTIONS,
692 gettext_noop("No description available."),
696 &log_btree_build_stats,
702 {"explain_pretty_print", PGC_USERSET, CLIENT_CONN_OTHER,
703 gettext_noop("Uses the indented output format for EXPLAIN VERBOSE."),
706 &Explain_pretty_print,
710 {"stats_start_collector", PGC_POSTMASTER, STATS_COLLECTOR,
711 gettext_noop("Starts the server statistics-collection subprocess."),
714 &pgstat_collect_startcollector,
718 {"stats_reset_on_server_start", PGC_POSTMASTER, STATS_COLLECTOR,
719 gettext_noop("Zeroes collected statistics on server restart."),
722 &pgstat_collect_resetonpmstart,
726 {"stats_row_level", PGC_SUSET, STATS_COLLECTOR,
727 gettext_noop("Collects row-level statistics on database activity."),
730 &pgstat_collect_tuplelevel,
734 {"stats_block_level", PGC_SUSET, STATS_COLLECTOR,
735 gettext_noop("Collects block-level statistics on database activity."),
738 &pgstat_collect_blocklevel,
743 {"stats_command_string", PGC_SUSET, STATS_COLLECTOR,
744 gettext_noop("Collects information about executing commands."),
745 gettext_noop("Enables the collection of information on the currently "
746 "executing command of each session, along with the time "
747 "at which that command began execution.")
749 &pgstat_collect_querystring,
754 {"update_process_title", PGC_SUSET, STATS_COLLECTOR,
755 gettext_noop("Updates the process title to show the active SQL command."),
756 gettext_noop("Enables updating of the process title every time a new SQL command is received by the server.")
758 &update_process_title,
763 {"autovacuum", PGC_SIGHUP, AUTOVACUUM,
764 gettext_noop("Starts the autovacuum subprocess."),
767 &autovacuum_start_daemon,
772 {"trace_notify", PGC_USERSET, DEVELOPER_OPTIONS,
773 gettext_noop("Generates debugging output for LISTEN and NOTIFY."),
783 {"trace_locks", PGC_SUSET, DEVELOPER_OPTIONS,
784 gettext_noop("No description available."),
792 {"trace_userlocks", PGC_SUSET, DEVELOPER_OPTIONS,
793 gettext_noop("No description available."),
801 {"trace_lwlocks", PGC_SUSET, DEVELOPER_OPTIONS,
802 gettext_noop("No description available."),
810 {"debug_deadlocks", PGC_SUSET, DEVELOPER_OPTIONS,
811 gettext_noop("No description available."),
821 {"log_lock_waits", PGC_SIGHUP, LOGGING_WHAT,
822 gettext_noop("Logs long lock wait events."),
829 {"log_hostname", PGC_SIGHUP, LOGGING_WHAT,
830 gettext_noop("Logs the host name in the connection logs."),
831 gettext_noop("By default, connection logs only show the IP address "
832 "of the connecting host. If you want them to show the host name you "
833 "can turn this on, but depending on your host name resolution "
834 "setup it might impose a non-negligible performance penalty.")
840 {"sql_inheritance", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
841 gettext_noop("Causes subtables to be included by default in various commands."),
848 {"password_encryption", PGC_USERSET, CONN_AUTH_SECURITY,
849 gettext_noop("Encrypt passwords."),
850 gettext_noop("When a password is specified in CREATE USER or "
851 "ALTER USER without writing either ENCRYPTED or UNENCRYPTED, "
852 "this parameter determines whether the password is to be encrypted.")
854 &Password_encryption,
858 {"transform_null_equals", PGC_USERSET, COMPAT_OPTIONS_CLIENT,
859 gettext_noop("Treats \"expr=NULL\" as \"expr IS NULL\"."),
860 gettext_noop("When turned on, expressions of the form expr = NULL "
861 "(or NULL = expr) are treated as expr IS NULL, that is, they "
862 "return true if expr evaluates to the null value, and false "
863 "otherwise. The correct behavior of expr = NULL is to always "
864 "return null (unknown).")
866 &Transform_null_equals,
870 {"db_user_namespace", PGC_SIGHUP, CONN_AUTH_SECURITY,
871 gettext_noop("Enables per-database user names."),
878 /* only here for backwards compatibility */
879 {"autocommit", PGC_USERSET, CLIENT_CONN_STATEMENT,
880 gettext_noop("This parameter doesn't do anything."),
881 gettext_noop("It's just here so that we won't choke on SET AUTOCOMMIT TO ON from 7.3-vintage clients."),
882 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
885 true, assign_phony_autocommit, NULL
888 {"default_transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
889 gettext_noop("Sets the default read-only status of new transactions."),
892 &DefaultXactReadOnly,
896 {"transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
897 gettext_noop("Sets the current transaction's read-only status."),
899 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
902 false, assign_transaction_read_only, NULL
905 {"add_missing_from", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
906 gettext_noop("Automatically adds missing table references to FROM clauses."),
913 {"check_function_bodies", PGC_USERSET, CLIENT_CONN_STATEMENT,
914 gettext_noop("Check function bodies during CREATE FUNCTION."),
917 &check_function_bodies,
921 {"array_nulls", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
922 gettext_noop("Enable input of NULL elements in arrays."),
923 gettext_noop("When turned on, unquoted NULL in an array input "
924 "value means a null value; "
925 "otherwise it is taken literally.")
931 {"default_with_oids", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
932 gettext_noop("Create new tables with OIDs by default."),
939 {"redirect_stderr", PGC_POSTMASTER, LOGGING_WHERE,
940 gettext_noop("Start a subprocess to capture stderr output into log files."),
947 {"log_truncate_on_rotation", PGC_SIGHUP, LOGGING_WHERE,
948 gettext_noop("Truncate existing log files of same name during log rotation."),
951 &Log_truncate_on_rotation,
957 {"trace_sort", PGC_USERSET, DEVELOPER_OPTIONS,
958 gettext_noop("Emit information about resource usage in sorting."),
969 {"wal_debug", PGC_SUSET, DEVELOPER_OPTIONS,
970 gettext_noop("Emit WAL-related debugging output."),
980 {"integer_datetimes", PGC_INTERNAL, PRESET_OPTIONS,
981 gettext_noop("Datetimes are integer based."),
983 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
986 #ifdef HAVE_INT64_TIMESTAMP
994 {"krb_caseins_users", PGC_POSTMASTER, CONN_AUTH_SECURITY,
995 gettext_noop("Sets whether Kerberos user names should be treated as case-insensitive."),
998 &pg_krb_caseins_users,
1003 {"escape_string_warning", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1004 gettext_noop("Warn about backslash escapes in ordinary string literals."),
1007 &escape_string_warning,
1012 {"standard_conforming_strings", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1013 gettext_noop("Causes '...' strings to treat backslashes literally."),
1017 &standard_conforming_strings,
1022 {"allow_system_table_mods", PGC_POSTMASTER, DEVELOPER_OPTIONS,
1023 gettext_noop("Allows modifications of the structure of system tables."),
1027 &allowSystemTableMods,
1032 {"ignore_system_indexes", PGC_BACKEND, DEVELOPER_OPTIONS,
1033 gettext_noop("Disables reading from system indexes."),
1034 gettext_noop("It does not prevent updating the indexes, so it is safe "
1035 "to use. The worst consequence is slowness."),
1038 &IgnoreSystemIndexes,
1042 /* End-of-list marker */
1044 {NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL
1049 static struct config_int ConfigureNamesInt[] =
1052 {"archive_timeout", PGC_SIGHUP, WAL_SETTINGS,
1053 gettext_noop("Forces a switch to the next xlog file if a "
1054 "new file has not been started within N seconds."),
1058 &XLogArchiveTimeout,
1059 0, 0, INT_MAX, NULL, NULL
1062 {"post_auth_delay", PGC_BACKEND, DEVELOPER_OPTIONS,
1063 gettext_noop("Waits N seconds on connection startup after authentication."),
1064 gettext_noop("This allows attaching a debugger to the process."),
1065 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1068 0, 0, INT_MAX, NULL, NULL
1071 {"default_statistics_target", PGC_USERSET, QUERY_TUNING_OTHER,
1072 gettext_noop("Sets the default statistics target."),
1073 gettext_noop("This applies to table columns that have not had a "
1074 "column-specific target set via ALTER TABLE SET STATISTICS.")
1076 &default_statistics_target,
1077 10, 1, 1000, NULL, NULL
1080 {"from_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1081 gettext_noop("Sets the FROM-list size beyond which subqueries "
1082 "are not collapsed."),
1083 gettext_noop("The planner will merge subqueries into upper "
1084 "queries if the resulting FROM list would have no more than "
1087 &from_collapse_limit,
1088 8, 1, INT_MAX, NULL, NULL
1091 {"join_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1092 gettext_noop("Sets the FROM-list size beyond which JOIN "
1093 "constructs are not flattened."),
1094 gettext_noop("The planner will flatten explicit JOIN "
1095 "constructs into lists of FROM items whenever a "
1096 "list of no more than this many items would result.")
1098 &join_collapse_limit,
1099 8, 1, INT_MAX, NULL, NULL
1102 {"geqo_threshold", PGC_USERSET, QUERY_TUNING_GEQO,
1103 gettext_noop("Sets the threshold of FROM items beyond which GEQO is used."),
1107 12, 2, INT_MAX, NULL, NULL
1110 {"geqo_effort", PGC_USERSET, QUERY_TUNING_GEQO,
1111 gettext_noop("GEQO: effort is used to set the default for other GEQO parameters."),
1115 DEFAULT_GEQO_EFFORT, MIN_GEQO_EFFORT, MAX_GEQO_EFFORT, NULL, NULL
1118 {"geqo_pool_size", PGC_USERSET, QUERY_TUNING_GEQO,
1119 gettext_noop("GEQO: number of individuals in the population."),
1120 gettext_noop("Zero selects a suitable default value.")
1123 0, 0, INT_MAX, NULL, NULL
1126 {"geqo_generations", PGC_USERSET, QUERY_TUNING_GEQO,
1127 gettext_noop("GEQO: number of iterations of the algorithm."),
1128 gettext_noop("Zero selects a suitable default value.")
1131 0, 0, INT_MAX, NULL, NULL
1135 {"deadlock_timeout", PGC_SIGHUP, LOCK_MANAGEMENT,
1136 gettext_noop("Sets the time to wait on a lock before checking for deadlock."),
1141 1000, 0, INT_MAX, NULL, NULL
1145 * Note: There is some postprocessing done in PostmasterMain() to make
1146 * sure the buffers are at least twice the number of backends, so the
1147 * constraints here are partially unused. Similarly, the superuser
1148 * reserved number is checked to ensure it is less than the max backends
1151 * MaxBackends is limited to INT_MAX/4 because some places compute
1152 * 4*MaxBackends without any overflow check. Likewise we have to limit
1153 * NBuffers to INT_MAX/2.
1156 {"max_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1157 gettext_noop("Sets the maximum number of concurrent connections."),
1161 100, 1, INT_MAX / 4, NULL, NULL
1165 {"superuser_reserved_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1166 gettext_noop("Sets the number of connection slots reserved for superusers."),
1170 3, 0, INT_MAX / 4, NULL, NULL
1174 {"shared_buffers", PGC_POSTMASTER, RESOURCES_MEM,
1175 gettext_noop("Sets the number of shared memory buffers used by the server."),
1180 1024, 16, INT_MAX / 2, NULL, NULL
1184 {"temp_buffers", PGC_USERSET, RESOURCES_MEM,
1185 gettext_noop("Sets the maximum number of temporary buffers used by each session."),
1190 1024, 100, INT_MAX / 2, NULL, show_num_temp_buffers
1194 {"port", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1195 gettext_noop("Sets the TCP port the server listens on."),
1199 DEF_PGPORT, 1, 65535, NULL, NULL
1203 {"unix_socket_permissions", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1204 gettext_noop("Sets the access permissions of the Unix-domain socket."),
1205 gettext_noop("Unix-domain sockets use the usual Unix file system "
1206 "permission set. The parameter value is expected to be an numeric mode "
1207 "specification in the form accepted by the chmod and umask system "
1208 "calls. (To use the customary octal format the number must start with "
1211 &Unix_socket_permissions,
1212 0777, 0000, 0777, NULL, NULL
1216 {"work_mem", PGC_USERSET, RESOURCES_MEM,
1217 gettext_noop("Sets the maximum memory to be used for query workspaces."),
1218 gettext_noop("This much memory can be used by each internal "
1219 "sort operation and hash table before switching to "
1220 "temporary disk files."),
1224 1024, 8 * BLCKSZ / 1024, MAX_KILOBYTES, NULL, NULL
1228 {"maintenance_work_mem", PGC_USERSET, RESOURCES_MEM,
1229 gettext_noop("Sets the maximum memory to be used for maintenance operations."),
1230 gettext_noop("This includes operations such as VACUUM and CREATE INDEX."),
1233 &maintenance_work_mem,
1234 16384, 1024, MAX_KILOBYTES, NULL, NULL
1238 {"max_stack_depth", PGC_SUSET, RESOURCES_MEM,
1239 gettext_noop("Sets the maximum stack depth, in kilobytes."),
1244 100, 100, MAX_KILOBYTES, assign_max_stack_depth, NULL
1248 {"vacuum_cost_page_hit", PGC_USERSET, RESOURCES,
1249 gettext_noop("Vacuum cost for a page found in the buffer cache."),
1253 1, 0, 10000, NULL, NULL
1257 {"vacuum_cost_page_miss", PGC_USERSET, RESOURCES,
1258 gettext_noop("Vacuum cost for a page not found in the buffer cache."),
1261 &VacuumCostPageMiss,
1262 10, 0, 10000, NULL, NULL
1266 {"vacuum_cost_page_dirty", PGC_USERSET, RESOURCES,
1267 gettext_noop("Vacuum cost for a page dirtied by vacuum."),
1270 &VacuumCostPageDirty,
1271 20, 0, 10000, NULL, NULL
1275 {"vacuum_cost_limit", PGC_USERSET, RESOURCES,
1276 gettext_noop("Vacuum cost amount available before napping."),
1280 200, 1, 10000, NULL, NULL
1284 {"vacuum_cost_delay", PGC_USERSET, RESOURCES,
1285 gettext_noop("Vacuum cost delay in milliseconds."),
1290 0, 0, 1000, NULL, NULL
1294 {"autovacuum_vacuum_cost_delay", PGC_SIGHUP, AUTOVACUUM,
1295 gettext_noop("Vacuum cost delay in milliseconds, for autovacuum."),
1299 &autovacuum_vac_cost_delay,
1300 -1, -1, 1000, NULL, NULL
1304 {"autovacuum_vacuum_cost_limit", PGC_SIGHUP, AUTOVACUUM,
1305 gettext_noop("Vacuum cost amount available before napping, for autovacuum."),
1308 &autovacuum_vac_cost_limit,
1309 -1, -1, 10000, NULL, NULL
1313 {"max_files_per_process", PGC_POSTMASTER, RESOURCES_KERNEL,
1314 gettext_noop("Sets the maximum number of simultaneously open files for each server process."),
1317 &max_files_per_process,
1318 1000, 25, INT_MAX, NULL, NULL
1322 {"max_prepared_transactions", PGC_POSTMASTER, RESOURCES,
1323 gettext_noop("Sets the maximum number of simultaneously prepared transactions."),
1326 &max_prepared_xacts,
1327 5, 0, INT_MAX, NULL, NULL
1332 {"trace_lock_oidmin", PGC_SUSET, DEVELOPER_OPTIONS,
1333 gettext_noop("No description available."),
1338 FirstNormalObjectId, 0, INT_MAX, NULL, NULL
1341 {"trace_lock_table", PGC_SUSET, DEVELOPER_OPTIONS,
1342 gettext_noop("No description available."),
1347 0, 0, INT_MAX, NULL, NULL
1352 {"statement_timeout", PGC_USERSET, CLIENT_CONN_STATEMENT,
1353 gettext_noop("Sets the maximum allowed duration of any statement."),
1354 gettext_noop("A value of 0 turns off the timeout."),
1358 0, 0, INT_MAX, NULL, NULL
1362 {"vacuum_freeze_min_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1363 gettext_noop("Minimum age at which VACUUM should freeze a table row."),
1366 &vacuum_freeze_min_age,
1367 100000000, 0, 1000000000, NULL, NULL
1371 {"max_fsm_relations", PGC_POSTMASTER, RESOURCES_FSM,
1372 gettext_noop("Sets the maximum number of tables and indexes for which free space is tracked."),
1376 1000, 100, INT_MAX, NULL, NULL
1379 {"max_fsm_pages", PGC_POSTMASTER, RESOURCES_FSM,
1380 gettext_noop("Sets the maximum number of disk pages for which free space is tracked."),
1384 20000, 1000, INT_MAX, NULL, NULL
1388 {"max_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
1389 gettext_noop("Sets the maximum number of locks per transaction."),
1390 gettext_noop("The shared lock table is sized on the assumption that "
1391 "at most max_locks_per_transaction * max_connections distinct "
1392 "objects will need to be locked at any one time.")
1394 &max_locks_per_xact,
1395 64, 10, INT_MAX, NULL, NULL
1399 {"authentication_timeout", PGC_SIGHUP, CONN_AUTH_SECURITY,
1400 gettext_noop("Sets the maximum allowed time to complete client authentication."),
1404 &AuthenticationTimeout,
1405 60, 1, 600, NULL, NULL
1409 /* Not for general use */
1410 {"pre_auth_delay", PGC_SIGHUP, DEVELOPER_OPTIONS,
1411 gettext_noop("Waits N seconds on connection startup before authentication."),
1412 gettext_noop("This allows attaching a debugger to the process."),
1413 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1416 0, 0, 60, NULL, NULL
1420 {"checkpoint_segments", PGC_SIGHUP, WAL_CHECKPOINTS,
1421 gettext_noop("Sets the maximum distance in log segments between automatic WAL checkpoints."),
1424 &CheckPointSegments,
1425 3, 1, INT_MAX, NULL, NULL
1429 {"checkpoint_timeout", PGC_SIGHUP, WAL_CHECKPOINTS,
1430 gettext_noop("Sets the maximum time between automatic WAL checkpoints."),
1435 300, 30, 3600, NULL, NULL
1439 {"checkpoint_warning", PGC_SIGHUP, WAL_CHECKPOINTS,
1440 gettext_noop("Enables warnings if checkpoint segments are filled more "
1441 "frequently than this."),
1442 gettext_noop("Write a message to the server log if checkpoints "
1443 "caused by the filling of checkpoint segment files happens more "
1444 "frequently than this number of seconds. Zero turns off the warning."),
1448 30, 0, INT_MAX, NULL, NULL
1452 {"wal_buffers", PGC_POSTMASTER, WAL_SETTINGS,
1453 gettext_noop("Sets the number of disk-page buffers in shared memory for WAL."),
1458 8, 4, INT_MAX, NULL, NULL
1462 {"commit_delay", PGC_USERSET, WAL_CHECKPOINTS,
1463 gettext_noop("Sets the delay in microseconds between transaction commit and "
1464 "flushing WAL to disk."),
1468 0, 0, 100000, NULL, NULL
1472 {"commit_siblings", PGC_USERSET, WAL_CHECKPOINTS,
1473 gettext_noop("Sets the minimum concurrent open transactions before performing "
1478 5, 1, 1000, NULL, NULL
1482 {"extra_float_digits", PGC_USERSET, CLIENT_CONN_LOCALE,
1483 gettext_noop("Sets the number of digits displayed for floating-point values."),
1484 gettext_noop("This affects real, double precision, and geometric data types. "
1485 "The parameter value is added to the standard number of digits "
1486 "(FLT_DIG or DBL_DIG as appropriate).")
1488 &extra_float_digits,
1489 0, -15, 2, NULL, NULL
1493 {"log_min_duration_statement", PGC_SUSET, LOGGING_WHEN,
1494 gettext_noop("Sets the minimum execution time above which statements will "
1496 gettext_noop("Zero prints all queries. The default is -1 (turning this feature off)."),
1499 &log_min_duration_statement,
1500 -1, -1, INT_MAX / 1000, NULL, NULL
1504 {"bgwriter_delay", PGC_SIGHUP, RESOURCES,
1505 gettext_noop("Background writer sleep time between rounds."),
1510 200, 10, 10000, NULL, NULL
1514 {"bgwriter_lru_maxpages", PGC_SIGHUP, RESOURCES,
1515 gettext_noop("Background writer maximum number of LRU pages to flush per round."),
1518 &bgwriter_lru_maxpages,
1519 5, 0, 1000, NULL, NULL
1523 {"bgwriter_all_maxpages", PGC_SIGHUP, RESOURCES,
1524 gettext_noop("Background writer maximum number of all pages to flush per round."),
1527 &bgwriter_all_maxpages,
1528 5, 0, 1000, NULL, NULL
1532 {"log_rotation_age", PGC_SIGHUP, LOGGING_WHERE,
1533 gettext_noop("Automatic log file rotation will occur after N minutes."),
1538 HOURS_PER_DAY * MINS_PER_HOUR, 0, INT_MAX / MINS_PER_HOUR, NULL, NULL
1542 {"log_rotation_size", PGC_SIGHUP, LOGGING_WHERE,
1543 gettext_noop("Automatic log file rotation will occur after N kilobytes."),
1548 10 * 1024, 0, INT_MAX / 1024, NULL, NULL
1552 {"max_function_args", PGC_INTERNAL, PRESET_OPTIONS,
1553 gettext_noop("Shows the maximum number of function arguments."),
1555 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1558 FUNC_MAX_ARGS, FUNC_MAX_ARGS, FUNC_MAX_ARGS, NULL, NULL
1562 {"max_index_keys", PGC_INTERNAL, PRESET_OPTIONS,
1563 gettext_noop("Shows the maximum number of index keys."),
1565 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1568 INDEX_MAX_KEYS, INDEX_MAX_KEYS, INDEX_MAX_KEYS, NULL, NULL
1572 {"max_identifier_length", PGC_INTERNAL, PRESET_OPTIONS,
1573 gettext_noop("Shows the maximum identifier length."),
1575 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1577 &max_identifier_length,
1578 NAMEDATALEN - 1, NAMEDATALEN - 1, NAMEDATALEN - 1, NULL, NULL
1582 {"block_size", PGC_INTERNAL, PRESET_OPTIONS,
1583 gettext_noop("Shows the size of a disk block."),
1585 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1588 BLCKSZ, BLCKSZ, BLCKSZ, NULL, NULL
1592 {"autovacuum_naptime", PGC_SIGHUP, AUTOVACUUM,
1593 gettext_noop("Time to sleep between autovacuum runs."),
1597 &autovacuum_naptime,
1598 60, 1, INT_MAX, NULL, NULL
1601 {"autovacuum_vacuum_threshold", PGC_SIGHUP, AUTOVACUUM,
1602 gettext_noop("Minimum number of tuple updates or deletes prior to vacuum."),
1605 &autovacuum_vac_thresh,
1606 500, 0, INT_MAX, NULL, NULL
1609 {"autovacuum_analyze_threshold", PGC_SIGHUP, AUTOVACUUM,
1610 gettext_noop("Minimum number of tuple inserts, updates or deletes prior to analyze."),
1613 &autovacuum_anl_thresh,
1614 250, 0, INT_MAX, NULL, NULL
1617 /* see varsup.c for why this is PGC_POSTMASTER not PGC_SIGHUP */
1618 {"autovacuum_freeze_max_age", PGC_POSTMASTER, AUTOVACUUM,
1619 gettext_noop("Age at which to autovacuum a table to prevent transaction ID wraparound."),
1622 &autovacuum_freeze_max_age,
1623 200000000, 100000000, 2000000000, NULL, NULL
1627 {"tcp_keepalives_idle", PGC_USERSET, CLIENT_CONN_OTHER,
1628 gettext_noop("Time between issuing TCP keepalives."),
1629 gettext_noop("A value of 0 uses the system default."),
1632 &tcp_keepalives_idle,
1633 0, 0, INT_MAX, assign_tcp_keepalives_idle, show_tcp_keepalives_idle
1637 {"tcp_keepalives_interval", PGC_USERSET, CLIENT_CONN_OTHER,
1638 gettext_noop("Time between TCP keepalive retransmits."),
1639 gettext_noop("A value of 0 uses the system default."),
1642 &tcp_keepalives_interval,
1643 0, 0, INT_MAX, assign_tcp_keepalives_interval, show_tcp_keepalives_interval
1647 {"tcp_keepalives_count", PGC_USERSET, CLIENT_CONN_OTHER,
1648 gettext_noop("Maximum number of TCP keepalive retransmits."),
1649 gettext_noop("This controls the number of consecutive keepalive retransmits that can be "
1650 "lost before a connection is considered dead. A value of 0 uses the "
1653 &tcp_keepalives_count,
1654 0, 0, INT_MAX, assign_tcp_keepalives_count, show_tcp_keepalives_count
1658 {"gin_fuzzy_search_limit", PGC_USERSET, CLIENT_CONN_OTHER,
1659 gettext_noop("Sets the maximum allowed result for exact search by GIN."),
1663 &GinFuzzySearchLimit,
1664 0, 0, INT_MAX, NULL, NULL
1668 {"effective_cache_size", PGC_USERSET, QUERY_TUNING_COST,
1669 gettext_noop("Sets the planner's assumption about the size of the disk cache."),
1670 gettext_noop("That is, the portion of the kernel's disk cache that "
1671 "will be used for PostgreSQL data files. This is measured in disk "
1672 "pages, which are normally 8 kB each."),
1675 &effective_cache_size,
1676 DEFAULT_EFFECTIVE_CACHE_SIZE, 1, INT_MAX, NULL, NULL
1680 /* Can't be set in postgresql.conf */
1681 {"server_version_num", PGC_INTERNAL, PRESET_OPTIONS,
1682 gettext_noop("Shows the server version as an integer."),
1684 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1686 &server_version_num,
1687 PG_VERSION_NUM, PG_VERSION_NUM, PG_VERSION_NUM, NULL, NULL
1691 {"log_temp_files", PGC_USERSET, LOGGING_WHAT,
1692 gettext_noop("Log the use of temporary files larger than this number of kilobytes."),
1693 gettext_noop("Zero logs all files. The default is -1 (turning this feature off)."),
1697 -1, -1, INT_MAX, NULL, NULL
1700 /* End-of-list marker */
1702 {NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL
1707 static struct config_real ConfigureNamesReal[] =
1710 {"seq_page_cost", PGC_USERSET, QUERY_TUNING_COST,
1711 gettext_noop("Sets the planner's estimate of the cost of a "
1712 "sequentially fetched disk page."),
1716 DEFAULT_SEQ_PAGE_COST, 0, DBL_MAX, NULL, NULL
1719 {"random_page_cost", PGC_USERSET, QUERY_TUNING_COST,
1720 gettext_noop("Sets the planner's estimate of the cost of a "
1721 "nonsequentially fetched disk page."),
1725 DEFAULT_RANDOM_PAGE_COST, 0, DBL_MAX, NULL, NULL
1728 {"cpu_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
1729 gettext_noop("Sets the planner's estimate of the cost of "
1730 "processing each tuple (row)."),
1734 DEFAULT_CPU_TUPLE_COST, 0, DBL_MAX, NULL, NULL
1737 {"cpu_index_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
1738 gettext_noop("Sets the planner's estimate of the cost of "
1739 "processing each index entry during an index scan."),
1742 &cpu_index_tuple_cost,
1743 DEFAULT_CPU_INDEX_TUPLE_COST, 0, DBL_MAX, NULL, NULL
1746 {"cpu_operator_cost", PGC_USERSET, QUERY_TUNING_COST,
1747 gettext_noop("Sets the planner's estimate of the cost of "
1748 "processing each operator or function call."),
1752 DEFAULT_CPU_OPERATOR_COST, 0, DBL_MAX, NULL, NULL
1756 {"geqo_selection_bias", PGC_USERSET, QUERY_TUNING_GEQO,
1757 gettext_noop("GEQO: selective pressure within the population."),
1760 &Geqo_selection_bias,
1761 DEFAULT_GEQO_SELECTION_BIAS, MIN_GEQO_SELECTION_BIAS,
1762 MAX_GEQO_SELECTION_BIAS, NULL, NULL
1766 {"bgwriter_lru_percent", PGC_SIGHUP, RESOURCES,
1767 gettext_noop("Background writer percentage of LRU buffers to flush per round."),
1770 &bgwriter_lru_percent,
1771 1.0, 0.0, 100.0, NULL, NULL
1775 {"bgwriter_all_percent", PGC_SIGHUP, RESOURCES,
1776 gettext_noop("Background writer percentage of all buffers to flush per round."),
1779 &bgwriter_all_percent,
1780 0.333, 0.0, 100.0, NULL, NULL
1784 {"seed", PGC_USERSET, UNGROUPED,
1785 gettext_noop("Sets the seed for random-number generation."),
1787 GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1790 0.5, 0.0, 1.0, assign_random_seed, show_random_seed
1794 {"autovacuum_vacuum_scale_factor", PGC_SIGHUP, AUTOVACUUM,
1795 gettext_noop("Number of tuple updates or deletes prior to vacuum as a fraction of reltuples."),
1798 &autovacuum_vac_scale,
1799 0.2, 0.0, 100.0, NULL, NULL
1802 {"autovacuum_analyze_scale_factor", PGC_SIGHUP, AUTOVACUUM,
1803 gettext_noop("Number of tuple inserts, updates or deletes prior to analyze as a fraction of reltuples."),
1806 &autovacuum_anl_scale,
1807 0.1, 0.0, 100.0, NULL, NULL
1810 /* End-of-list marker */
1812 {NULL, 0, 0, NULL, NULL}, NULL, 0.0, 0.0, 0.0, NULL, NULL
1817 static struct config_string ConfigureNamesString[] =
1820 {"archive_command", PGC_SIGHUP, WAL_SETTINGS,
1821 gettext_noop("Sets the shell command that will be called to archive a WAL file."),
1824 &XLogArchiveCommand,
1829 {"backslash_quote", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1830 gettext_noop("Sets whether \"\\'\" is allowed in string literals."),
1831 gettext_noop("Valid values are ON, OFF, and SAFE_ENCODING.")
1833 &backslash_quote_string,
1834 "safe_encoding", assign_backslash_quote, NULL
1838 {"client_encoding", PGC_USERSET, CLIENT_CONN_LOCALE,
1839 gettext_noop("Sets the client's character set encoding."),
1841 GUC_IS_NAME | GUC_REPORT
1843 &client_encoding_string,
1844 "SQL_ASCII", assign_client_encoding, NULL
1848 {"client_min_messages", PGC_USERSET, LOGGING_WHEN,
1849 gettext_noop("Sets the message levels that are sent to the client."),
1850 gettext_noop("Valid values are DEBUG5, DEBUG4, DEBUG3, DEBUG2, "
1851 "DEBUG1, LOG, NOTICE, WARNING, and ERROR. Each level includes all the "
1852 "levels that follow it. The later the level, the fewer messages are "
1855 &client_min_messages_str,
1856 "notice", assign_client_min_messages, NULL
1860 {"log_min_messages", PGC_SUSET, LOGGING_WHEN,
1861 gettext_noop("Sets the message levels that are logged."),
1862 gettext_noop("Valid values are DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1, "
1863 "INFO, NOTICE, WARNING, ERROR, LOG, FATAL, and PANIC. Each level "
1864 "includes all the levels that follow it.")
1866 &log_min_messages_str,
1867 "notice", assign_log_min_messages, NULL
1871 {"log_error_verbosity", PGC_SUSET, LOGGING_WHEN,
1872 gettext_noop("Sets the verbosity of logged messages."),
1873 gettext_noop("Valid values are \"terse\", \"default\", and \"verbose\".")
1875 &log_error_verbosity_str,
1876 "default", assign_log_error_verbosity, NULL
1879 {"log_statement", PGC_SUSET, LOGGING_WHAT,
1880 gettext_noop("Sets the type of statements logged."),
1881 gettext_noop("Valid values are \"none\", \"ddl\", \"mod\", and \"all\".")
1884 "none", assign_log_statement, NULL
1888 {"log_min_error_statement", PGC_SUSET, LOGGING_WHEN,
1889 gettext_noop("Causes all statements generating error at or above this level to be logged."),
1890 gettext_noop("All SQL statements that cause an error of the "
1891 "specified level or a higher level are logged.")
1893 &log_min_error_statement_str,
1894 "error", assign_min_error_statement, NULL
1898 {"log_line_prefix", PGC_SIGHUP, LOGGING_WHAT,
1899 gettext_noop("Controls information prefixed to each log line."),
1900 gettext_noop("If blank, no prefix is used.")
1908 {"DateStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
1909 gettext_noop("Sets the display format for date and time values."),
1910 gettext_noop("Also controls interpretation of ambiguous "
1912 GUC_LIST_INPUT | GUC_REPORT
1915 "ISO, MDY", assign_datestyle, NULL
1919 {"default_tablespace", PGC_USERSET, CLIENT_CONN_STATEMENT,
1920 gettext_noop("Sets the default tablespace to create tables and indexes in."),
1921 gettext_noop("An empty string selects the database's default tablespace."),
1924 &default_tablespace,
1925 "", assign_default_tablespace, NULL
1929 {"default_transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
1930 gettext_noop("Sets the transaction isolation level of each new transaction."),
1931 gettext_noop("Each SQL transaction has an isolation level, which "
1932 "can be either \"read uncommitted\", \"read committed\", \"repeatable read\", or \"serializable\".")
1934 &default_iso_level_string,
1935 "read committed", assign_defaultxactisolevel, NULL
1939 {"session_replication_role", PGC_SUSET, CLIENT_CONN_STATEMENT,
1940 gettext_noop("Sets the sessions behaviour for triggers and rewrite rules."),
1941 gettext_noop("Each session can be either"
1942 " \"origin\", \"replica\" or \"local\".")
1944 &session_replication_role_string,
1945 "origin", assign_session_replication_role, NULL
1949 {"dynamic_library_path", PGC_SUSET, CLIENT_CONN_OTHER,
1950 gettext_noop("Sets the path for dynamically loadable modules."),
1951 gettext_noop("If a dynamically loadable module needs to be opened and "
1952 "the specified name does not have a directory component (i.e., the "
1953 "name does not contain a slash), the system will search this path for "
1954 "the specified file."),
1957 &Dynamic_library_path,
1958 "$libdir", NULL, NULL
1962 {"krb_server_keyfile", PGC_POSTMASTER, CONN_AUTH_SECURITY,
1963 gettext_noop("Sets the location of the Kerberos server key file."),
1967 &pg_krb_server_keyfile,
1968 PG_KRB_SRVTAB, NULL, NULL
1972 {"krb_srvname", PGC_POSTMASTER, CONN_AUTH_SECURITY,
1973 gettext_noop("Sets the name of the Kerberos service."),
1977 PG_KRB_SRVNAM, NULL, NULL
1981 {"krb_server_hostname", PGC_POSTMASTER, CONN_AUTH_SECURITY,
1982 gettext_noop("Sets the hostname of the Kerberos server."),
1985 &pg_krb_server_hostname,
1990 {"bonjour_name", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1991 gettext_noop("Sets the Bonjour broadcast service name."),
1998 /* See main.c about why defaults for LC_foo are not all alike */
2001 {"lc_collate", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2002 gettext_noop("Shows the collation order locale."),
2004 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2011 {"lc_ctype", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2012 gettext_noop("Shows the character classification and case conversion locale."),
2014 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2021 {"lc_messages", PGC_SUSET, CLIENT_CONN_LOCALE,
2022 gettext_noop("Sets the language in which messages are displayed."),
2026 "", locale_messages_assign, NULL
2030 {"lc_monetary", PGC_USERSET, CLIENT_CONN_LOCALE,
2031 gettext_noop("Sets the locale for formatting monetary amounts."),
2035 "C", locale_monetary_assign, NULL
2039 {"lc_numeric", PGC_USERSET, CLIENT_CONN_LOCALE,
2040 gettext_noop("Sets the locale for formatting numbers."),
2044 "C", locale_numeric_assign, NULL
2048 {"lc_time", PGC_USERSET, CLIENT_CONN_LOCALE,
2049 gettext_noop("Sets the locale for formatting date and time values."),
2053 "C", locale_time_assign, NULL
2057 {"shared_preload_libraries", PGC_POSTMASTER, RESOURCES_KERNEL,
2058 gettext_noop("Lists shared libraries to preload into server."),
2060 GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
2062 &shared_preload_libraries_string,
2067 {"local_preload_libraries", PGC_BACKEND, CLIENT_CONN_OTHER,
2068 gettext_noop("Lists shared libraries to preload into each backend."),
2070 GUC_LIST_INPUT | GUC_LIST_QUOTE
2072 &local_preload_libraries_string,
2077 {"regex_flavor", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
2078 gettext_noop("Sets the regular expression \"flavor\"."),
2079 gettext_noop("This can be set to advanced, extended, or basic.")
2081 ®ex_flavor_string,
2082 "advanced", assign_regex_flavor, NULL
2086 {"search_path", PGC_USERSET, CLIENT_CONN_STATEMENT,
2087 gettext_noop("Sets the schema search order for names that are not schema-qualified."),
2089 GUC_LIST_INPUT | GUC_LIST_QUOTE
2091 &namespace_search_path,
2092 "\"$user\",public", assign_search_path, NULL
2096 /* Can't be set in postgresql.conf */
2097 {"server_encoding", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2098 gettext_noop("Sets the server (database) character set encoding."),
2100 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2102 &server_encoding_string,
2103 "SQL_ASCII", NULL, NULL
2107 /* Can't be set in postgresql.conf */
2108 {"server_version", PGC_INTERNAL, PRESET_OPTIONS,
2109 gettext_noop("Shows the server version."),
2111 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2113 &server_version_string,
2114 PG_VERSION, NULL, NULL
2118 /* Not for general use --- used by SET ROLE */
2119 {"role", PGC_USERSET, UNGROUPED,
2120 gettext_noop("Sets the current role."),
2122 GUC_IS_NAME | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2125 "none", assign_role, show_role
2129 /* Not for general use --- used by SET SESSION AUTHORIZATION */
2130 {"session_authorization", PGC_USERSET, UNGROUPED,
2131 gettext_noop("Sets the session user name."),
2133 GUC_IS_NAME | GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2135 &session_authorization_string,
2136 NULL, assign_session_authorization, show_session_authorization
2140 {"log_destination", PGC_SIGHUP, LOGGING_WHERE,
2141 gettext_noop("Sets the destination for server log output."),
2142 gettext_noop("Valid values are combinations of \"stderr\", \"syslog\", "
2143 "and \"eventlog\", depending on the platform."),
2146 &log_destination_string,
2147 "stderr", assign_log_destination, NULL
2150 {"log_directory", PGC_SIGHUP, LOGGING_WHERE,
2151 gettext_noop("Sets the destination directory for log files."),
2152 gettext_noop("Can be specified as relative to the data directory "
2153 "or as absolute path."),
2157 "pg_log", assign_canonical_path, NULL
2160 {"log_filename", PGC_SIGHUP, LOGGING_WHERE,
2161 gettext_noop("Sets the file name pattern for log files."),
2166 "postgresql-%Y-%m-%d_%H%M%S.log", NULL, NULL
2171 {"syslog_facility", PGC_SIGHUP, LOGGING_WHERE,
2172 gettext_noop("Sets the syslog \"facility\" to be used when syslog enabled."),
2173 gettext_noop("Valid values are LOCAL0, LOCAL1, LOCAL2, LOCAL3, "
2174 "LOCAL4, LOCAL5, LOCAL6, LOCAL7.")
2176 &syslog_facility_str,
2177 "LOCAL0", assign_syslog_facility, NULL
2180 {"syslog_ident", PGC_SIGHUP, LOGGING_WHERE,
2181 gettext_noop("Sets the program name used to identify PostgreSQL "
2182 "messages in syslog."),
2186 "postgres", assign_syslog_ident, NULL
2191 {"TimeZone", PGC_USERSET, CLIENT_CONN_LOCALE,
2192 gettext_noop("Sets the time zone for displaying and interpreting time stamps."),
2197 "UNKNOWN", assign_timezone, show_timezone
2200 {"timezone_abbreviations", PGC_USERSET, CLIENT_CONN_LOCALE,
2201 gettext_noop("Selects a file of time zone abbreviations."),
2204 &timezone_abbreviations_string,
2205 "UNKNOWN", assign_timezone_abbreviations, NULL
2209 {"transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
2210 gettext_noop("Sets the current transaction's isolation level."),
2212 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2214 &XactIsoLevel_string,
2215 NULL, assign_XactIsoLevel, show_XactIsoLevel
2219 {"unix_socket_group", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2220 gettext_noop("Sets the owning group of the Unix-domain socket."),
2221 gettext_noop("The owning user of the socket is always the user "
2222 "that starts the server.")
2229 {"unix_socket_directory", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2230 gettext_noop("Sets the directory where the Unix-domain socket will be created."),
2235 "", assign_canonical_path, NULL
2239 {"listen_addresses", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2240 gettext_noop("Sets the host name or IP address(es) to listen to."),
2245 "localhost", NULL, NULL
2249 {"wal_sync_method", PGC_SIGHUP, WAL_SETTINGS,
2250 gettext_noop("Selects the method used for forcing WAL updates to disk."),
2254 XLOG_sync_method_default, assign_xlog_sync_method, NULL
2258 {"custom_variable_classes", PGC_SIGHUP, CUSTOM_OPTIONS,
2259 gettext_noop("Sets the list of known custom variable classes."),
2261 GUC_LIST_INPUT | GUC_LIST_QUOTE
2263 &custom_variable_classes,
2264 NULL, assign_custom_variable_classes, NULL
2268 {"data_directory", PGC_POSTMASTER, FILE_LOCATIONS,
2269 gettext_noop("Sets the server's data directory."),
2278 {"config_file", PGC_POSTMASTER, FILE_LOCATIONS,
2279 gettext_noop("Sets the server's main configuration file."),
2281 GUC_DISALLOW_IN_FILE | GUC_SUPERUSER_ONLY
2288 {"hba_file", PGC_POSTMASTER, FILE_LOCATIONS,
2289 gettext_noop("Sets the server's \"hba\" configuration file."),
2298 {"ident_file", PGC_POSTMASTER, FILE_LOCATIONS,
2299 gettext_noop("Sets the server's \"ident\" configuration file."),
2308 {"external_pid_file", PGC_POSTMASTER, FILE_LOCATIONS,
2309 gettext_noop("Writes the postmaster PID to the specified file."),
2314 NULL, assign_canonical_path, NULL
2318 {"xmlbinary", PGC_USERSET, CLIENT_CONN_STATEMENT,
2319 gettext_noop("Sets how binary values are to be encoded in XML."),
2320 gettext_noop("Valid values are BASE64 and HEX.")
2323 "base64", assign_xmlbinary, NULL
2327 {"xmloption", PGC_USERSET, CLIENT_CONN_STATEMENT,
2328 gettext_noop("Sets whether XML data in implicit parsing and serialization "
2329 "operations is to be considered as documents or content fragments."),
2330 gettext_noop("Valid values are DOCUMENT and CONTENT.")
2333 "content", assign_xmloption, NULL
2338 {"ssl_ciphers", PGC_POSTMASTER, CONN_AUTH_SECURITY,
2339 gettext_noop("Sets the list of allowed SSL ciphers."),
2344 "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH", NULL, NULL
2346 #endif /* USE_SSL */
2348 /* End-of-list marker */
2350 {NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL
2355 /******** end of options list ********/
2359 * To allow continued support of obsolete names for GUC variables, we apply
2360 * the following mappings to any unrecognized name. Note that an old name
2361 * should be mapped to a new one only if the new variable has very similar
2362 * semantics to the old.
2364 static const char *const map_old_guc_names[] = {
2365 "sort_mem", "work_mem",
2366 "vacuum_mem", "maintenance_work_mem",
2372 * Actual lookup of variables is done through this single, sorted array.
2374 static struct config_generic **guc_variables;
2376 /* Current number of variables contained in the vector */
2377 static int num_guc_variables;
2379 /* Vector capacity */
2380 static int size_guc_variables;
2383 static bool guc_dirty; /* TRUE if need to do commit/abort work */
2385 static bool reporting_enabled; /* TRUE to enable GUC_REPORT */
2388 static int guc_var_compare(const void *a, const void *b);
2389 static int guc_name_compare(const char *namea, const char *nameb);
2390 static void push_old_value(struct config_generic * gconf);
2391 static void ReportGUCOption(struct config_generic * record);
2392 static void ShowGUCConfigOption(const char *name, DestReceiver *dest);
2393 static void ShowAllGUCConfig(DestReceiver *dest);
2394 static char *_ShowOption(struct config_generic * record, bool use_units);
2395 static bool is_newvalue_equal(struct config_generic * record, const char *newvalue);
2399 * Some infrastructure for checking malloc/strdup/realloc calls
2402 guc_malloc(int elevel, size_t size)
2406 data = malloc(size);
2409 (errcode(ERRCODE_OUT_OF_MEMORY),
2410 errmsg("out of memory")));
2415 guc_realloc(int elevel, void *old, size_t size)
2419 data = realloc(old, size);
2422 (errcode(ERRCODE_OUT_OF_MEMORY),
2423 errmsg("out of memory")));
2428 guc_strdup(int elevel, const char *src)
2435 (errcode(ERRCODE_OUT_OF_MEMORY),
2436 errmsg("out of memory")));
2442 * Support for assigning to a field of a string GUC item. Free the prior
2443 * value if it's not referenced anywhere else in the item (including stacked
2447 set_string_field(struct config_string * conf, char **field, char *newval)
2449 char *oldval = *field;
2452 /* Do the assignment */
2455 /* Exit if any duplicate references, or if old value was NULL anyway */
2456 if (oldval == NULL ||
2457 oldval == *(conf->variable) ||
2458 oldval == conf->reset_val ||
2459 oldval == conf->tentative_val)
2461 for (stack = conf->gen.stack; stack; stack = stack->prev)
2463 if (oldval == stack->tentative_val.stringval ||
2464 oldval == stack->value.stringval)
2468 /* Not used anymore, so free it */
2473 * Detect whether strval is referenced anywhere in a GUC string item
2476 string_field_used(struct config_string * conf, char *strval)
2480 if (strval == *(conf->variable) ||
2481 strval == conf->reset_val ||
2482 strval == conf->tentative_val)
2484 for (stack = conf->gen.stack; stack; stack = stack->prev)
2486 if (strval == stack->tentative_val.stringval ||
2487 strval == stack->value.stringval)
2494 struct config_generic **
2495 get_guc_variables(void)
2497 return guc_variables;
2502 * Build the sorted array. This is split out so that it could be
2503 * re-executed after startup (eg, we could allow loadable modules to
2504 * add vars, and then we'd need to re-sort).
2507 build_guc_variables(void)
2511 struct config_generic **guc_vars;
2514 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
2516 struct config_bool *conf = &ConfigureNamesBool[i];
2518 /* Rather than requiring vartype to be filled in by hand, do this: */
2519 conf->gen.vartype = PGC_BOOL;
2523 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
2525 struct config_int *conf = &ConfigureNamesInt[i];
2527 conf->gen.vartype = PGC_INT;
2531 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
2533 struct config_real *conf = &ConfigureNamesReal[i];
2535 conf->gen.vartype = PGC_REAL;
2539 for (i = 0; ConfigureNamesString[i].gen.name; i++)
2541 struct config_string *conf = &ConfigureNamesString[i];
2543 conf->gen.vartype = PGC_STRING;
2548 * Create table with 20% slack
2550 size_vars = num_vars + num_vars / 4;
2552 guc_vars = (struct config_generic **)
2553 guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
2557 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
2558 guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
2560 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
2561 guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
2563 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
2564 guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
2566 for (i = 0; ConfigureNamesString[i].gen.name; i++)
2567 guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
2570 free(guc_variables);
2571 guc_variables = guc_vars;
2572 num_guc_variables = num_vars;
2573 size_guc_variables = size_vars;
2574 qsort((void *) guc_variables, num_guc_variables,
2575 sizeof(struct config_generic *), guc_var_compare);
2579 is_custom_class(const char *name, int dotPos)
2582 * assign_custom_variable_classes() has made sure no empty identifiers or
2583 * whitespace exists in the variable
2585 bool result = false;
2586 const char *ccs = GetConfigOption("custom_variable_classes");
2590 const char *start = ccs;
2596 if (c == 0 || c == ',')
2598 if (dotPos == ccs - start && strncmp(start, name, dotPos) == 0)
2613 * Add a new GUC variable to the list of known variables. The
2614 * list is expanded if needed.
2617 add_guc_variable(struct config_generic * var, int elevel)
2619 if (num_guc_variables + 1 >= size_guc_variables)
2622 * Increase the vector by 25%
2624 int size_vars = size_guc_variables + size_guc_variables / 4;
2625 struct config_generic **guc_vars;
2630 guc_vars = (struct config_generic **)
2631 guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
2635 guc_vars = (struct config_generic **)
2636 guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
2639 if (guc_vars == NULL)
2640 return false; /* out of memory */
2642 guc_variables = guc_vars;
2643 size_guc_variables = size_vars;
2645 guc_variables[num_guc_variables++] = var;
2646 qsort((void *) guc_variables, num_guc_variables,
2647 sizeof(struct config_generic *), guc_var_compare);
2652 * Create and add a placeholder variable. It's presumed to belong
2653 * to a valid custom variable class at this point.
2655 static struct config_string *
2656 add_placeholder_variable(const char *name, int elevel)
2658 size_t sz = sizeof(struct config_string) + sizeof(char *);
2659 struct config_string *var;
2660 struct config_generic *gen;
2662 var = (struct config_string *) guc_malloc(elevel, sz);
2669 gen->name = guc_strdup(elevel, name);
2670 if (gen->name == NULL)
2676 gen->context = PGC_USERSET;
2677 gen->group = CUSTOM_OPTIONS;
2678 gen->short_desc = "GUC placeholder variable";
2679 gen->flags = GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_CUSTOM_PLACEHOLDER;
2680 gen->vartype = PGC_STRING;
2683 * The char* is allocated at the end of the struct since we have no
2684 * 'static' place to point to.
2686 var->variable = (char **) (var + 1);
2688 if (!add_guc_variable((struct config_generic *) var, elevel))
2690 free((void *) gen->name);
2699 * Look up option NAME. If it exists, return a pointer to its record,
2702 static struct config_generic *
2703 find_option(const char *name, int elevel)
2706 const char **key = &name;
2707 struct config_generic **res;
2713 * By equating const char ** with struct config_generic *, we are assuming
2714 * the name field is first in config_generic.
2716 res = (struct config_generic **) bsearch((void *) &key,
2717 (void *) guc_variables,
2719 sizeof(struct config_generic *),
2725 * See if the name is an obsolete name for a variable. We assume that the
2726 * set of supported old names is short enough that a brute-force search is
2729 for (i = 0; map_old_guc_names[i] != NULL; i += 2)
2731 if (guc_name_compare(name, map_old_guc_names[i]) == 0)
2732 return find_option(map_old_guc_names[i + 1], elevel);
2736 * Check if the name is qualified, and if so, check if the qualifier maps
2737 * to a custom variable class.
2739 dot = strchr(name, GUC_QUALIFIER_SEPARATOR);
2740 if (dot != NULL && is_custom_class(name, dot - name))
2741 /* Add a placeholder variable for this name */
2742 return (struct config_generic *) add_placeholder_variable(name, elevel);
2750 * comparator for qsorting and bsearching guc_variables array
2753 guc_var_compare(const void *a, const void *b)
2755 struct config_generic *confa = *(struct config_generic **) a;
2756 struct config_generic *confb = *(struct config_generic **) b;
2758 return guc_name_compare(confa->name, confb->name);
2763 guc_name_compare(const char *namea, const char *nameb)
2766 * The temptation to use strcasecmp() here must be resisted, because the
2767 * array ordering has to remain stable across setlocale() calls. So, build
2768 * our own with a simple ASCII-only downcasing.
2770 while (*namea && *nameb)
2772 char cha = *namea++;
2773 char chb = *nameb++;
2775 if (cha >= 'A' && cha <= 'Z')
2777 if (chb >= 'A' && chb <= 'Z')
2783 return 1; /* a is longer */
2785 return -1; /* b is longer */
2791 * Initialize GUC options during program startup.
2793 * Note that we cannot read the config file yet, since we have not yet
2794 * processed command-line switches.
2797 InitializeGUCOptions(void)
2804 * Build sorted array of all GUC variables.
2806 build_guc_variables();
2809 * Load all variables with their compiled-in defaults, and initialize
2810 * status fields as needed.
2812 for (i = 0; i < num_guc_variables; i++)
2814 struct config_generic *gconf = guc_variables[i];
2817 gconf->reset_source = PGC_S_DEFAULT;
2818 gconf->tentative_source = PGC_S_DEFAULT;
2819 gconf->source = PGC_S_DEFAULT;
2820 gconf->stack = NULL;
2822 switch (gconf->vartype)
2826 struct config_bool *conf = (struct config_bool *) gconf;
2828 if (conf->assign_hook)
2829 if (!(*conf->assign_hook) (conf->reset_val, true,
2831 elog(FATAL, "failed to initialize %s to %d",
2832 conf->gen.name, (int) conf->reset_val);
2833 *conf->variable = conf->reset_val;
2838 struct config_int *conf = (struct config_int *) gconf;
2840 Assert(conf->reset_val >= conf->min);
2841 Assert(conf->reset_val <= conf->max);
2842 if (conf->assign_hook)
2843 if (!(*conf->assign_hook) (conf->reset_val, true,
2845 elog(FATAL, "failed to initialize %s to %d",
2846 conf->gen.name, conf->reset_val);
2847 *conf->variable = conf->reset_val;
2852 struct config_real *conf = (struct config_real *) gconf;
2854 Assert(conf->reset_val >= conf->min);
2855 Assert(conf->reset_val <= conf->max);
2856 if (conf->assign_hook)
2857 if (!(*conf->assign_hook) (conf->reset_val, true,
2859 elog(FATAL, "failed to initialize %s to %g",
2860 conf->gen.name, conf->reset_val);
2861 *conf->variable = conf->reset_val;
2866 struct config_string *conf = (struct config_string *) gconf;
2869 *conf->variable = NULL;
2870 conf->reset_val = NULL;
2871 conf->tentative_val = NULL;
2873 if (conf->boot_val == NULL)
2875 /* Cannot set value yet */
2879 str = guc_strdup(FATAL, conf->boot_val);
2880 conf->reset_val = str;
2882 if (conf->assign_hook)
2886 newstr = (*conf->assign_hook) (str, true,
2890 elog(FATAL, "failed to initialize %s to \"%s\"",
2891 conf->gen.name, str);
2893 else if (newstr != str)
2898 * See notes in set_config_option about casting
2900 str = (char *) newstr;
2901 conf->reset_val = str;
2904 *conf->variable = str;
2912 reporting_enabled = false;
2915 * Prevent any attempt to override the transaction modes from
2916 * non-interactive sources.
2918 SetConfigOption("transaction_isolation", "default",
2919 PGC_POSTMASTER, PGC_S_OVERRIDE);
2920 SetConfigOption("transaction_read_only", "no",
2921 PGC_POSTMASTER, PGC_S_OVERRIDE);
2924 * For historical reasons, some GUC parameters can receive defaults from
2925 * environment variables. Process those settings.
2928 env = getenv("PGPORT");
2930 SetConfigOption("port", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
2932 env = getenv("PGDATESTYLE");
2934 SetConfigOption("datestyle", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
2936 env = getenv("PGCLIENTENCODING");
2938 SetConfigOption("client_encoding", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
2941 * rlimit isn't exactly an "environment variable", but it behaves about
2942 * the same. If we can identify the platform stack depth rlimit, increase
2943 * default stack depth setting up to whatever is safe (but at most 2MB).
2945 stack_rlimit = get_stack_depth_rlimit();
2946 if (stack_rlimit > 0)
2948 int new_limit = (stack_rlimit - STACK_DEPTH_SLOP) / 1024L;
2950 if (new_limit > 100)
2954 new_limit = Min(new_limit, 2048);
2955 sprintf(limbuf, "%d", new_limit);
2956 SetConfigOption("max_stack_depth", limbuf,
2957 PGC_POSTMASTER, PGC_S_ENV_VAR);
2964 * Select the configuration files and data directory to be used, and
2965 * do the initial read of postgresql.conf.
2967 * This is called after processing command-line switches.
2968 * userDoption is the -D switch value if any (NULL if unspecified).
2969 * progname is just for use in error messages.
2971 * Returns true on success; on failure, prints a suitable error message
2972 * to stderr and returns false.
2975 SelectConfigFiles(const char *userDoption, const char *progname)
2979 struct stat stat_buf;
2981 /* configdir is -D option, or $PGDATA if no -D */
2983 configdir = make_absolute_path(userDoption);
2985 configdir = make_absolute_path(getenv("PGDATA"));
2988 * Find the configuration file: if config_file was specified on the
2989 * command line, use it, else use configdir/postgresql.conf. In any case
2990 * ensure the result is an absolute path, so that it will be interpreted
2991 * the same way by future backends.
2994 fname = make_absolute_path(ConfigFileName);
2997 fname = guc_malloc(FATAL,
2998 strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
2999 sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
3003 write_stderr("%s does not know where to find the server configuration file.\n"
3004 "You must specify the --config-file or -D invocation "
3005 "option or set the PGDATA environment variable.\n",
3011 * Set the ConfigFileName GUC variable to its final value, ensuring that
3012 * it can't be overridden later.
3014 SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
3018 * Now read the config file for the first time.
3020 if (stat(ConfigFileName, &stat_buf) != 0)
3022 write_stderr("%s cannot access the server configuration file \"%s\": %s\n",
3023 progname, ConfigFileName, strerror(errno));
3027 ProcessConfigFile(PGC_POSTMASTER);
3030 * If the data_directory GUC variable has been set, use that as DataDir;
3031 * otherwise use configdir if set; else punt.
3033 * Note: SetDataDir will copy and absolute-ize its argument, so we don't
3037 SetDataDir(data_directory);
3039 SetDataDir(configdir);
3042 write_stderr("%s does not know where to find the database system data.\n"
3043 "This can be specified as \"data_directory\" in \"%s\", "
3044 "or by the -D invocation option, or by the "
3045 "PGDATA environment variable.\n",
3046 progname, ConfigFileName);
3051 * Reflect the final DataDir value back into the data_directory GUC var.
3052 * (If you are wondering why we don't just make them a single variable,
3053 * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
3054 * child backends specially. XXX is that still true? Given that we now
3055 * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
3056 * DataDir in advance.)
3058 SetConfigOption("data_directory", DataDir, PGC_POSTMASTER, PGC_S_OVERRIDE);
3061 * Figure out where pg_hba.conf is, and make sure the path is absolute.
3064 fname = make_absolute_path(HbaFileName);
3067 fname = guc_malloc(FATAL,
3068 strlen(configdir) + strlen(HBA_FILENAME) + 2);
3069 sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
3073 write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
3074 "This can be specified as \"hba_file\" in \"%s\", "
3075 "or by the -D invocation option, or by the "
3076 "PGDATA environment variable.\n",
3077 progname, ConfigFileName);
3080 SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
3084 * Likewise for pg_ident.conf.
3087 fname = make_absolute_path(IdentFileName);
3090 fname = guc_malloc(FATAL,
3091 strlen(configdir) + strlen(IDENT_FILENAME) + 2);
3092 sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
3096 write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
3097 "This can be specified as \"ident_file\" in \"%s\", "
3098 "or by the -D invocation option, or by the "
3099 "PGDATA environment variable.\n",
3100 progname, ConfigFileName);
3103 SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
3113 * Reset all options to their saved default values (implements RESET ALL)
3116 ResetAllOptions(void)
3120 for (i = 0; i < num_guc_variables; i++)
3122 struct config_generic *gconf = guc_variables[i];
3124 /* Don't reset non-SET-able values */
3125 if (gconf->context != PGC_SUSET &&
3126 gconf->context != PGC_USERSET)
3128 /* Don't reset if special exclusion from RESET ALL */
3129 if (gconf->flags & GUC_NO_RESET_ALL)
3131 /* No need to reset if wasn't SET */
3132 if (gconf->source <= PGC_S_OVERRIDE)
3135 /* Save old value to support transaction abort */
3136 push_old_value(gconf);
3138 switch (gconf->vartype)
3142 struct config_bool *conf = (struct config_bool *) gconf;
3144 if (conf->assign_hook)
3145 if (!(*conf->assign_hook) (conf->reset_val, true,
3147 elog(ERROR, "failed to reset %s", conf->gen.name);
3148 *conf->variable = conf->reset_val;
3149 conf->tentative_val = conf->reset_val;
3150 conf->gen.source = conf->gen.reset_source;
3151 conf->gen.tentative_source = conf->gen.reset_source;
3152 conf->gen.status |= GUC_HAVE_TENTATIVE;
3158 struct config_int *conf = (struct config_int *) gconf;
3160 if (conf->assign_hook)
3161 if (!(*conf->assign_hook) (conf->reset_val, true,
3163 elog(ERROR, "failed to reset %s", conf->gen.name);
3164 *conf->variable = conf->reset_val;
3165 conf->tentative_val = conf->reset_val;
3166 conf->gen.source = conf->gen.reset_source;
3167 conf->gen.tentative_source = conf->gen.reset_source;
3168 conf->gen.status |= GUC_HAVE_TENTATIVE;
3174 struct config_real *conf = (struct config_real *) gconf;
3176 if (conf->assign_hook)
3177 if (!(*conf->assign_hook) (conf->reset_val, true,
3179 elog(ERROR, "failed to reset %s", conf->gen.name);
3180 *conf->variable = conf->reset_val;
3181 conf->tentative_val = conf->reset_val;
3182 conf->gen.source = conf->gen.reset_source;
3183 conf->gen.tentative_source = conf->gen.reset_source;
3184 conf->gen.status |= GUC_HAVE_TENTATIVE;
3190 struct config_string *conf = (struct config_string *) gconf;
3193 if (conf->reset_val == NULL)
3195 /* Nothing to reset to, as yet; so do nothing */
3199 /* We need not strdup here */
3200 str = conf->reset_val;
3202 if (conf->assign_hook)
3206 newstr = (*conf->assign_hook) (str, true,
3209 elog(ERROR, "failed to reset %s", conf->gen.name);
3210 else if (newstr != str)
3213 * See notes in set_config_option about casting
3215 str = (char *) newstr;
3219 set_string_field(conf, conf->variable, str);
3220 set_string_field(conf, &conf->tentative_val, str);
3221 conf->gen.source = conf->gen.reset_source;
3222 conf->gen.tentative_source = conf->gen.reset_source;
3223 conf->gen.status |= GUC_HAVE_TENTATIVE;
3229 if (gconf->flags & GUC_REPORT)
3230 ReportGUCOption(gconf);
3237 * Push previous state during first assignment to a GUC variable
3238 * within a particular transaction.
3240 * We have to be willing to "back-fill" the state stack if the first
3241 * assignment occurs within a subtransaction nested several levels deep.
3242 * This ensures that if an intermediate transaction aborts, it will have
3243 * the proper value available to restore the setting to.
3246 push_old_value(struct config_generic * gconf)
3248 int my_level = GetCurrentTransactionNestLevel();
3251 /* If we're not inside a transaction, do nothing */
3257 /* Done if we already pushed it at this nesting depth */
3258 if (gconf->stack && gconf->stack->nest_level >= my_level)
3262 * We keep all the stack entries in TopTransactionContext so as to
3263 * avoid allocation problems when a subtransaction back-fills stack
3264 * entries for upper transaction levels.
3266 stack = (GucStack *) MemoryContextAlloc(TopTransactionContext,
3269 stack->prev = gconf->stack;
3270 stack->nest_level = stack->prev ? stack->prev->nest_level + 1 : 1;
3271 stack->status = gconf->status;
3272 stack->tentative_source = gconf->tentative_source;
3273 stack->source = gconf->source;
3275 switch (gconf->vartype)
3278 stack->tentative_val.boolval =
3279 ((struct config_bool *) gconf)->tentative_val;
3280 stack->value.boolval =
3281 *((struct config_bool *) gconf)->variable;
3285 stack->tentative_val.intval =
3286 ((struct config_int *) gconf)->tentative_val;
3287 stack->value.intval =
3288 *((struct config_int *) gconf)->variable;
3292 stack->tentative_val.realval =
3293 ((struct config_real *) gconf)->tentative_val;
3294 stack->value.realval =
3295 *((struct config_real *) gconf)->variable;
3299 stack->tentative_val.stringval =
3300 ((struct config_string *) gconf)->tentative_val;
3301 stack->value.stringval =
3302 *((struct config_string *) gconf)->variable;
3306 gconf->stack = stack;
3308 /* Set state to indicate nothing happened yet within this level */
3309 gconf->status = GUC_HAVE_STACK;
3311 /* Ensure we remember to pop at end of xact */
3317 * Do GUC processing at transaction or subtransaction commit or abort.
3320 AtEOXact_GUC(bool isCommit, bool isSubXact)
3325 /* Quick exit if nothing's changed in this transaction */
3329 my_level = GetCurrentTransactionNestLevel();
3330 Assert(isSubXact ? (my_level > 1) : (my_level == 1));
3332 for (i = 0; i < num_guc_variables; i++)
3334 struct config_generic *gconf = guc_variables[i];
3335 int my_status = gconf->status;
3336 GucStack *stack = gconf->stack;
3341 * Skip if nothing's happened to this var in this transaction
3345 Assert(stack == NULL);
3348 /* Assert that we stacked old value before changing it */
3349 Assert(stack != NULL && (my_status & GUC_HAVE_STACK));
3350 /* However, the last change may have been at an outer xact level */
3351 if (stack->nest_level < my_level)
3353 Assert(stack->nest_level == my_level);
3356 * We will pop the stack entry. Start by restoring outer xact status
3357 * (since we may want to modify it below). Be careful to use
3358 * my_status to reference the inner xact status below this point...
3360 gconf->status = stack->status;
3363 * We have two cases:
3365 * If commit and HAVE_TENTATIVE, set actual value to tentative (this
3366 * is to override a SET LOCAL if one occurred later than SET). We keep
3367 * the tentative value and propagate HAVE_TENTATIVE to the parent
3368 * status, allowing the SET's effect to percolate up. (But if we're
3369 * exiting the outermost transaction, we'll drop the HAVE_TENTATIVE
3372 * Otherwise, we have a transaction that aborted or executed only SET
3373 * LOCAL (or no SET at all). In either case it should have no further
3374 * effect, so restore both tentative and actual values from the stack
3378 useTentative = isCommit && (my_status & GUC_HAVE_TENTATIVE) != 0;
3381 switch (gconf->vartype)
3385 struct config_bool *conf = (struct config_bool *) gconf;
3387 GucSource newsource;
3391 newval = conf->tentative_val;
3392 newsource = conf->gen.tentative_source;
3393 conf->gen.status |= GUC_HAVE_TENTATIVE;
3397 newval = stack->value.boolval;
3398 newsource = stack->source;
3399 conf->tentative_val = stack->tentative_val.boolval;
3400 conf->gen.tentative_source = stack->tentative_source;
3403 if (*conf->variable != newval)
3405 if (conf->assign_hook)
3406 if (!(*conf->assign_hook) (newval,
3407 true, PGC_S_OVERRIDE))
3408 elog(LOG, "failed to commit %s",
3410 *conf->variable = newval;
3413 conf->gen.source = newsource;
3418 struct config_int *conf = (struct config_int *) gconf;
3420 GucSource newsource;
3424 newval = conf->tentative_val;
3425 newsource = conf->gen.tentative_source;
3426 conf->gen.status |= GUC_HAVE_TENTATIVE;
3430 newval = stack->value.intval;
3431 newsource = stack->source;
3432 conf->tentative_val = stack->tentative_val.intval;
3433 conf->gen.tentative_source = stack->tentative_source;
3436 if (*conf->variable != newval)
3438 if (conf->assign_hook)
3439 if (!(*conf->assign_hook) (newval,
3440 true, PGC_S_OVERRIDE))
3441 elog(LOG, "failed to commit %s",
3443 *conf->variable = newval;
3446 conf->gen.source = newsource;
3451 struct config_real *conf = (struct config_real *) gconf;
3453 GucSource newsource;
3457 newval = conf->tentative_val;
3458 newsource = conf->gen.tentative_source;
3459 conf->gen.status |= GUC_HAVE_TENTATIVE;
3463 newval = stack->value.realval;
3464 newsource = stack->source;
3465 conf->tentative_val = stack->tentative_val.realval;
3466 conf->gen.tentative_source = stack->tentative_source;
3469 if (*conf->variable != newval)
3471 if (conf->assign_hook)
3472 if (!(*conf->assign_hook) (newval,
3473 true, PGC_S_OVERRIDE))
3474 elog(LOG, "failed to commit %s",
3476 *conf->variable = newval;
3479 conf->gen.source = newsource;
3484 struct config_string *conf = (struct config_string *) gconf;
3486 GucSource newsource;
3490 newval = conf->tentative_val;
3491 newsource = conf->gen.tentative_source;
3492 conf->gen.status |= GUC_HAVE_TENTATIVE;
3496 newval = stack->value.stringval;
3497 newsource = stack->source;
3498 set_string_field(conf, &conf->tentative_val,
3499 stack->tentative_val.stringval);
3500 conf->gen.tentative_source = stack->tentative_source;
3503 if (*conf->variable != newval)
3505 if (conf->assign_hook)
3509 newstr = (*conf->assign_hook) (newval, true,
3512 elog(LOG, "failed to commit %s",
3514 else if (newstr != newval)
3517 * If newval should now be freed, it'll be
3518 * taken care of below.
3520 * See notes in set_config_option about
3523 newval = (char *) newstr;
3527 set_string_field(conf, conf->variable, newval);
3530 conf->gen.source = newsource;
3531 /* Release stacked values if not used anymore */
3532 set_string_field(conf, &stack->value.stringval,
3534 set_string_field(conf, &stack->tentative_val.stringval,
3536 /* Don't store tentative value separately after commit */
3538 set_string_field(conf, &conf->tentative_val, NULL);
3543 /* Finish popping the state stack */
3544 gconf->stack = stack->prev;
3548 * If we're now out of all xact levels, forget TENTATIVE status bit;
3549 * there's nothing tentative about the value anymore.
3553 Assert(gconf->stack == NULL);
3557 /* Report new value if we changed it */
3558 if (changed && (gconf->flags & GUC_REPORT))
3559 ReportGUCOption(gconf);
3563 * If we're now out of all xact levels, we can clear guc_dirty. (Note: we
3564 * cannot reset guc_dirty when exiting a subtransaction, because we know
3565 * that all outer transaction levels will have stacked values to deal
3574 * Start up automatic reporting of changes to variables marked GUC_REPORT.
3575 * This is executed at completion of backend startup.
3578 BeginReportingGUCOptions(void)
3583 * Don't do anything unless talking to an interactive frontend of protocol
3586 if (whereToSendOutput != DestRemote ||
3587 PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
3590 reporting_enabled = true;
3592 /* Transmit initial values of interesting variables */
3593 for (i = 0; i < num_guc_variables; i++)
3595 struct config_generic *conf = guc_variables[i];
3597 if (conf->flags & GUC_REPORT)
3598 ReportGUCOption(conf);
3603 * ReportGUCOption: if appropriate, transmit option value to frontend
3606 ReportGUCOption(struct config_generic * record)
3608 if (reporting_enabled && (record->flags & GUC_REPORT))
3610 char *val = _ShowOption(record, false);
3611 StringInfoData msgbuf;
3613 pq_beginmessage(&msgbuf, 'S');
3614 pq_sendstring(&msgbuf, record->name);
3615 pq_sendstring(&msgbuf, val);
3616 pq_endmessage(&msgbuf);
3624 * Try to interpret value as boolean value. Valid values are: true,
3625 * false, yes, no, on, off, 1, 0. If the string parses okay, return
3626 * true, else false. If result is not NULL, return the parsing result
3630 parse_bool(const char *value, bool *result)
3632 size_t len = strlen(value);
3634 if (pg_strncasecmp(value, "true", len) == 0)
3639 else if (pg_strncasecmp(value, "false", len) == 0)
3645 else if (pg_strncasecmp(value, "yes", len) == 0)
3650 else if (pg_strncasecmp(value, "no", len) == 0)
3656 /* 'o' is not unique enough */
3657 else if (pg_strncasecmp(value, "on", (len > 2 ? len : 2)) == 0)
3662 else if (pg_strncasecmp(value, "off", (len > 2 ? len : 2)) == 0)
3668 else if (pg_strcasecmp(value, "1") == 0)
3673 else if (pg_strcasecmp(value, "0") == 0)
3682 *result = false; /* suppress compiler warning */
3691 * Try to parse value as an integer. The accepted formats are the
3692 * usual decimal, octal, or hexadecimal formats. If the string parses
3693 * okay, return true, else false. If result is not NULL, return the
3697 parse_int(const char *value, int *result, int flags)
3703 val = strtol(value, &endptr, 0);
3705 if ((flags & GUC_UNIT_MEMORY) && endptr != value)
3709 while (*endptr == ' ')
3712 if (strcmp(endptr, "kB") == 0)
3717 else if (strcmp(endptr, "MB") == 0)
3723 else if (strcmp(endptr, "GB") == 0)
3731 #error BLCKSZ must be >= 1024
3736 switch (flags & GUC_UNIT_MEMORY)
3738 case GUC_UNIT_BLOCKS:
3739 val /= (BLCKSZ / 1024);
3741 case GUC_UNIT_XBLOCKS:
3742 val /= (XLOG_BLCKSZ / 1024);
3748 if ((flags & GUC_UNIT_TIME) && endptr != value)
3752 while (*endptr == ' ')
3755 if (strcmp(endptr, "ms") == 0)
3760 else if (strcmp(endptr, "s") == 0)
3766 else if (strcmp(endptr, "min") == 0)
3772 else if (strcmp(endptr, "h") == 0)
3778 else if (strcmp(endptr, "d") == 0)
3787 switch (flags & GUC_UNIT_TIME)
3799 if (endptr == value || *endptr != '\0' || errno == ERANGE
3800 #ifdef HAVE_LONG_INT_64
3801 /* if long > 32 bits, check for overflow of int4 */
3802 || val != (long) ((int32) val)
3807 *result = 0; /* suppress compiler warning */
3811 *result = (int) val;
3818 * Try to parse value as a floating point constant in the usual
3819 * format. If the value parsed okay return true, else false. If
3820 * result is not NULL, return the semantic value there.
3823 parse_real(const char *value, double *result)
3829 val = strtod(value, &endptr);
3830 if (endptr == value || *endptr != '\0' || errno == ERANGE)
3833 *result = 0; /* suppress compiler warning */
3843 * Call a GucStringAssignHook function, being careful to free the
3844 * "newval" string if the hook ereports.
3846 * This is split out of set_config_option just to avoid the "volatile"
3847 * qualifiers that would otherwise have to be plastered all over.
3850 call_string_assign_hook(GucStringAssignHook assign_hook,
3851 char *newval, bool doit, GucSource source)
3857 result = (*assign_hook) (newval, doit, source);
3871 * Sets option `name' to given value. The value should be a string
3872 * which is going to be parsed and converted to the appropriate data
3873 * type. The context and source parameters indicate in which context this
3874 * function is being called so it can apply the access restrictions
3877 * If value is NULL, set the option to its default value. If the
3878 * parameter changeVal is false then don't really set the option but do all
3879 * the checks to see if it would work.
3881 * If there is an error (non-existing option, invalid value) then an
3882 * ereport(ERROR) is thrown *unless* this is called in a context where we
3883 * don't want to ereport (currently, startup or SIGHUP config file reread).
3884 * In that case we write a suitable error message via ereport(DEBUG) and
3885 * return false. This is working around the deficiencies in the ereport
3886 * mechanism, so don't blame me. In all other cases, the function
3887 * returns true, including cases where the input is valid but we chose
3888 * not to apply it because of context or source-priority considerations.
3890 * See also SetConfigOption for an external interface.
3893 set_config_option(const char *name, const char *value,
3894 GucContext context, GucSource source,
3895 bool isLocal, bool changeVal)
3897 struct config_generic *record;
3901 if (context == PGC_SIGHUP || source == PGC_S_DEFAULT)
3904 * To avoid cluttering the log, only the postmaster bleats loudly
3905 * about problems with the config file.
3907 elevel = IsUnderPostmaster ? DEBUG2 : LOG;
3909 else if (source == PGC_S_DATABASE || source == PGC_S_USER)
3914 record = find_option(name, elevel);
3918 (errcode(ERRCODE_UNDEFINED_OBJECT),
3919 errmsg("unrecognized configuration parameter \"%s\"", name)));
3924 * Check if the option can be set at this time. See guc.h for the precise
3925 * rules. Note that we don't want to throw errors if we're in the SIGHUP
3926 * context. In that case we just ignore the attempt and return true.
3928 switch (record->context)
3931 if (context == PGC_SIGHUP)
3933 if (context != PGC_INTERNAL)
3936 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3937 errmsg("parameter \"%s\" cannot be changed",
3942 case PGC_POSTMASTER:
3943 if (context == PGC_SIGHUP)
3945 if (changeVal && !is_newvalue_equal(record, value))
3947 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3948 errmsg("parameter \"%s\" cannot be changed after server start; configuration file change ignored",
3953 if (context != PGC_POSTMASTER)
3956 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3957 errmsg("parameter \"%s\" cannot be changed after server start",
3963 if (context != PGC_SIGHUP && context != PGC_POSTMASTER)
3966 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3967 errmsg("parameter \"%s\" cannot be changed now",
3973 * Hmm, the idea of the SIGHUP context is "ought to be global, but
3974 * can be changed after postmaster start". But there's nothing
3975 * that prevents a crafty administrator from sending SIGHUP
3976 * signals to individual backends only.
3980 if (context == PGC_SIGHUP)
3983 * If a PGC_BACKEND parameter is changed in the config file,
3984 * we want to accept the new value in the postmaster (whence
3985 * it will propagate to subsequently-started backends), but
3986 * ignore it in existing backends. This is a tad klugy, but
3987 * necessary because we don't re-read the config file during
3990 if (IsUnderPostmaster)
3993 else if (context != PGC_BACKEND && context != PGC_POSTMASTER)
3996 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3997 errmsg("parameter \"%s\" cannot be set after connection start",
4003 if (context == PGC_USERSET || context == PGC_BACKEND)
4006 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4007 errmsg("permission denied to set parameter \"%s\"",
4018 * Should we set reset/stacked values? (If so, the behavior is not
4021 makeDefault = changeVal && (source <= PGC_S_OVERRIDE) && (value != NULL);
4024 * Ignore attempted set if overridden by previously processed setting.
4025 * However, if changeVal is false then plow ahead anyway since we are
4026 * trying to find out if the value is potentially good, not actually use
4027 * it. Also keep going if makeDefault is true, since we may want to set
4028 * the reset/stacked values even if we can't set the variable itself.
4030 if (record->source > source)
4032 if (changeVal && !makeDefault)
4034 elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
4042 * Evaluate value and set variable.
4044 switch (record->vartype)
4048 struct config_bool *conf = (struct config_bool *) record;
4053 if (!parse_bool(value, &newval))
4056 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4057 errmsg("parameter \"%s\" requires a Boolean value",
4064 newval = conf->reset_val;
4065 source = conf->gen.reset_source;
4068 if (conf->assign_hook)
4069 if (!(*conf->assign_hook) (newval, changeVal, source))
4072 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4073 errmsg("invalid value for parameter \"%s\": %d",
4074 name, (int) newval)));
4078 if (changeVal || makeDefault)
4080 /* Save old value to support transaction abort */
4082 push_old_value(&conf->gen);
4085 *conf->variable = newval;
4086 conf->gen.source = source;
4092 if (conf->gen.reset_source <= source)
4094 conf->reset_val = newval;
4095 conf->gen.reset_source = source;
4097 for (stack = conf->gen.stack; stack; stack = stack->prev)
4099 if (stack->source <= source)
4101 stack->value.boolval = newval;
4102 stack->source = source;
4108 conf->gen.status |= GUC_HAVE_LOCAL;
4113 conf->tentative_val = newval;
4114 conf->gen.tentative_source = source;
4115 conf->gen.status |= GUC_HAVE_TENTATIVE;
4124 struct config_int *conf = (struct config_int *) record;
4129 if (!parse_int(value, &newval, conf->gen.flags))
4132 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4133 errmsg("parameter \"%s\" requires an integer value",
4137 if (newval < conf->min || newval > conf->max)
4140 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4141 errmsg("%d is outside the valid range for parameter \"%s\" (%d .. %d)",
4142 newval, name, conf->min, conf->max)));
4148 newval = conf->reset_val;
4149 source = conf->gen.reset_source;
4152 if (conf->assign_hook)
4153 if (!(*conf->assign_hook) (newval, changeVal, source))
4156 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4157 errmsg("invalid value for parameter \"%s\": %d",
4162 if (changeVal || makeDefault)
4164 /* Save old value to support transaction abort */
4166 push_old_value(&conf->gen);
4169 *conf->variable = newval;
4170 conf->gen.source = source;
4176 if (conf->gen.reset_source <= source)
4178 conf->reset_val = newval;
4179 conf->gen.reset_source = source;
4181 for (stack = conf->gen.stack; stack; stack = stack->prev)
4183 if (stack->source <= source)
4185 stack->value.intval = newval;
4186 stack->source = source;
4192 conf->gen.status |= GUC_HAVE_LOCAL;
4197 conf->tentative_val = newval;
4198 conf->gen.tentative_source = source;
4199 conf->gen.status |= GUC_HAVE_TENTATIVE;
4208 struct config_real *conf = (struct config_real *) record;
4213 if (!parse_real(value, &newval))
4216 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4217 errmsg("parameter \"%s\" requires a numeric value",
4221 if (newval < conf->min || newval > conf->max)
4224 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4225 errmsg("%g is outside the valid range for parameter \"%s\" (%g .. %g)",
4226 newval, name, conf->min, conf->max)));
4232 newval = conf->reset_val;
4233 source = conf->gen.reset_source;
4236 if (conf->assign_hook)
4237 if (!(*conf->assign_hook) (newval, changeVal, source))
4240 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4241 errmsg("invalid value for parameter \"%s\": %g",
4246 if (changeVal || makeDefault)
4248 /* Save old value to support transaction abort */
4250 push_old_value(&conf->gen);
4253 *conf->variable = newval;
4254 conf->gen.source = source;
4260 if (conf->gen.reset_source <= source)
4262 conf->reset_val = newval;
4263 conf->gen.reset_source = source;
4265 for (stack = conf->gen.stack; stack; stack = stack->prev)
4267 if (stack->source <= source)
4269 stack->value.realval = newval;
4270 stack->source = source;
4276 conf->gen.status |= GUC_HAVE_LOCAL;
4281 conf->tentative_val = newval;
4282 conf->gen.tentative_source = source;
4283 conf->gen.status |= GUC_HAVE_TENTATIVE;
4292 struct config_string *conf = (struct config_string *) record;
4297 newval = guc_strdup(elevel, value);
4302 * The only sort of "parsing" check we need to do is apply
4303 * truncation if GUC_IS_NAME.
4305 if (conf->gen.flags & GUC_IS_NAME)
4306 truncate_identifier(newval, strlen(newval), true);
4308 else if (conf->reset_val)
4311 * We could possibly avoid strdup here, but easier to make
4312 * this case work the same as the normal assignment case.
4314 newval = guc_strdup(elevel, conf->reset_val);
4317 source = conf->gen.reset_source;
4321 /* Nothing to reset to, as yet; so do nothing */
4325 if (conf->assign_hook)
4327 const char *hookresult;
4330 * If the hook ereports, we have to make sure we free
4331 * newval, else it will be a permanent memory leak.
4333 hookresult = call_string_assign_hook(conf->assign_hook,
4337 if (hookresult == NULL)
4341 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4342 errmsg("invalid value for parameter \"%s\": \"%s\"",
4343 name, value ? value : "")));
4346 else if (hookresult != newval)
4351 * Having to cast away const here is annoying, but the
4352 * alternative is to declare assign_hooks as returning
4353 * char*, which would mean they'd have to cast away
4354 * const, or as both taking and returning char*, which
4355 * doesn't seem attractive either --- we don't want
4356 * them to scribble on the passed str.
4358 newval = (char *) hookresult;
4362 if (changeVal || makeDefault)
4364 /* Save old value to support transaction abort */
4366 push_old_value(&conf->gen);
4369 set_string_field(conf, conf->variable, newval);
4370 conf->gen.source = source;
4376 if (conf->gen.reset_source <= source)
4378 set_string_field(conf, &conf->reset_val, newval);
4379 conf->gen.reset_source = source;
4381 for (stack = conf->gen.stack; stack; stack = stack->prev)
4383 if (stack->source <= source)
4385 set_string_field(conf, &stack->value.stringval,
4387 stack->source = source;
4390 /* Perhaps we didn't install newval anywhere */
4391 if (!string_field_used(conf, newval))
4396 conf->gen.status |= GUC_HAVE_LOCAL;
4401 set_string_field(conf, &conf->tentative_val, newval);
4402 conf->gen.tentative_source = source;
4403 conf->gen.status |= GUC_HAVE_TENTATIVE;
4413 if (changeVal && (record->flags & GUC_REPORT))
4414 ReportGUCOption(record);
4421 * Set a config option to the given value. See also set_config_option,
4422 * this is just the wrapper to be called from outside GUC. NB: this
4423 * is used only for non-transactional operations.
4426 SetConfigOption(const char *name, const char *value,
4427 GucContext context, GucSource source)
4429 (void) set_config_option(name, value, context, source, false, true);
4435 * Fetch the current value of the option `name'. If the option doesn't exist,
4436 * throw an ereport and don't return.
4438 * The string is *not* allocated for modification and is really only
4439 * valid until the next call to configuration related functions.
4442 GetConfigOption(const char *name)
4444 struct config_generic *record;
4445 static char buffer[256];
4447 record = find_option(name, ERROR);
4450 (errcode(ERRCODE_UNDEFINED_OBJECT),
4451 errmsg("unrecognized configuration parameter \"%s\"", name)));
4452 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
4454 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4455 errmsg("must be superuser to examine \"%s\"", name)));
4457 switch (record->vartype)
4460 return *((struct config_bool *) record)->variable ? "on" : "off";
4463 snprintf(buffer, sizeof(buffer), "%d",
4464 *((struct config_int *) record)->variable);
4468 snprintf(buffer, sizeof(buffer), "%g",
4469 *((struct config_real *) record)->variable);
4473 return *((struct config_string *) record)->variable;
4479 * Get the RESET value associated with the given option.
4482 GetConfigOptionResetString(const char *name)
4484 struct config_generic *record;
4485 static char buffer[256];
4487 record = find_option(name, ERROR);
4490 (errcode(ERRCODE_UNDEFINED_OBJECT),
4491 errmsg("unrecognized configuration parameter \"%s\"", name)));
4492 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
4494 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4495 errmsg("must be superuser to examine \"%s\"", name)));
4497 switch (record->vartype)
4500 return ((struct config_bool *) record)->reset_val ? "on" : "off";
4503 snprintf(buffer, sizeof(buffer), "%d",
4504 ((struct config_int *) record)->reset_val);
4508 snprintf(buffer, sizeof(buffer), "%g",
4509 ((struct config_real *) record)->reset_val);
4513 return ((struct config_string *) record)->reset_val;
4519 * Detect whether the given configuration option can only be set by
4523 IsSuperuserConfigOption(const char *name)
4525 struct config_generic *record;
4527 record = find_option(name, ERROR);
4528 /* On an unrecognized name, don't error, just return false. */
4531 return (record->context == PGC_SUSET);
4536 * flatten_set_variable_args
4537 * Given a parsenode List as emitted by the grammar for SET,
4538 * convert to the flat string representation used by GUC.
4540 * We need to be told the name of the variable the args are for, because
4541 * the flattening rules vary (ugh).
4543 * The result is NULL if input is NIL (ie, SET ... TO DEFAULT), otherwise
4544 * a palloc'd string.
4547 flatten_set_variable_args(const char *name, List *args)
4549 struct config_generic *record;
4555 * Fast path if just DEFAULT. We do not check the variable name in this
4556 * case --- necessary for RESET ALL to work correctly.
4561 /* Else get flags for the variable */
4562 record = find_option(name, ERROR);
4565 (errcode(ERRCODE_UNDEFINED_OBJECT),
4566 errmsg("unrecognized configuration parameter \"%s\"", name)));
4568 flags = record->flags;
4570 /* Complain if list input and non-list variable */
4571 if ((flags & GUC_LIST_INPUT) == 0 &&
4572 list_length(args) != 1)
4574 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4575 errmsg("SET %s takes only one argument", name)));
4577 initStringInfo(&buf);
4581 A_Const *arg = (A_Const *) lfirst(l);
4584 if (l != list_head(args))
4585 appendStringInfo(&buf, ", ");
4587 if (!IsA(arg, A_Const))
4588 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
4590 switch (nodeTag(&arg->val))
4593 appendStringInfo(&buf, "%ld", intVal(&arg->val));
4596 /* represented as a string, so just copy it */
4597 appendStringInfoString(&buf, strVal(&arg->val));
4600 val = strVal(&arg->val);
4601 if (arg->typename != NULL)
4604 * Must be a ConstInterval argument for TIME ZONE. Coerce
4605 * to interval and back to normalize the value and account
4612 typmod = typenameTypeMod(NULL, arg->typename, INTERVALOID);
4615 DirectFunctionCall3(interval_in,
4616 CStringGetDatum(val),
4617 ObjectIdGetDatum(InvalidOid),
4618 Int32GetDatum(typmod));
4621 DatumGetCString(DirectFunctionCall1(interval_out,
4623 appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
4628 * Plain string literal or identifier. For quote mode,
4629 * quote it if it's not a vanilla identifier.
4631 if (flags & GUC_LIST_QUOTE)
4632 appendStringInfoString(&buf, quote_identifier(val));
4634 appendStringInfoString(&buf, val);
4638 elog(ERROR, "unrecognized node type: %d",
4639 (int) nodeTag(&arg->val));
4652 SetPGVariable(const char *name, List *args, bool is_local)
4654 char *argstring = flatten_set_variable_args(name, args);
4656 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
4657 set_config_option(name,
4659 (superuser() ? PGC_SUSET : PGC_USERSET),
4666 * SET command wrapped as a SQL callable function.
4669 set_config_by_name(PG_FUNCTION_ARGS)
4677 if (PG_ARGISNULL(0))
4679 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
4680 errmsg("SET requires parameter name")));
4682 /* Get the GUC variable name */
4683 name = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(0)));
4685 /* Get the desired value or set to NULL for a reset request */
4686 if (PG_ARGISNULL(1))
4689 value = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(1)));
4692 * Get the desired state of is_local. Default to false if provided value
4695 if (PG_ARGISNULL(2))
4698 is_local = PG_GETARG_BOOL(2);
4700 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
4701 set_config_option(name,
4703 (superuser() ? PGC_SUSET : PGC_USERSET),
4708 /* get the new current value */
4709 new_value = GetConfigOptionByName(name, NULL);
4711 /* Convert return string to text */
4712 result_text = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(new_value)));
4715 PG_RETURN_TEXT_P(result_text);
4719 define_custom_variable(struct config_generic * variable)
4721 const char *name = variable->name;
4722 const char **nameAddr = &name;
4724 struct config_string *pHolder;
4725 struct config_generic **res = (struct config_generic **) bsearch(
4727 (void *) guc_variables,
4729 sizeof(struct config_generic *),
4734 add_guc_variable(variable, ERROR);
4739 * This better be a placeholder
4741 if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
4743 (errcode(ERRCODE_INTERNAL_ERROR),
4744 errmsg("attempt to redefine parameter \"%s\"", name)));
4746 Assert((*res)->vartype == PGC_STRING);
4747 pHolder = (struct config_string *) * res;
4749 /* We have the same name, no sorting is necessary */
4752 value = *pHolder->variable;
4755 * Assign the string value stored in the placeholder to the real variable.
4757 * XXX this is not really good enough --- it should be a nontransactional
4758 * assignment, since we don't want it to roll back if the current xact
4761 set_config_option(name, value,
4762 pHolder->gen.context, pHolder->gen.source,
4766 * Free up as much as we conveniently can of the placeholder structure
4767 * (this neglects any stack items...)
4769 set_string_field(pHolder, pHolder->variable, NULL);
4770 set_string_field(pHolder, &pHolder->reset_val, NULL);
4771 set_string_field(pHolder, &pHolder->tentative_val, NULL);
4777 init_custom_variable(struct config_generic * gen,
4779 const char *short_desc,
4780 const char *long_desc,
4782 enum config_type type)
4784 gen->name = guc_strdup(ERROR, name);
4785 gen->context = context;
4786 gen->group = CUSTOM_OPTIONS;
4787 gen->short_desc = short_desc;
4788 gen->long_desc = long_desc;
4789 gen->vartype = type;
4793 DefineCustomBoolVariable(const char *name,
4794 const char *short_desc,
4795 const char *long_desc,
4798 GucBoolAssignHook assign_hook,
4799 GucShowHook show_hook)
4801 size_t sz = sizeof(struct config_bool);
4802 struct config_bool *var = (struct config_bool *) guc_malloc(ERROR, sz);
4805 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_BOOL);
4807 var->variable = valueAddr;
4808 var->reset_val = *valueAddr;
4809 var->assign_hook = assign_hook;
4810 var->show_hook = show_hook;
4811 define_custom_variable(&var->gen);
4815 DefineCustomIntVariable(const char *name,
4816 const char *short_desc,
4817 const char *long_desc,
4822 GucIntAssignHook assign_hook,
4823 GucShowHook show_hook)
4825 size_t sz = sizeof(struct config_int);
4826 struct config_int *var = (struct config_int *) guc_malloc(ERROR, sz);
4829 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_INT);
4831 var->variable = valueAddr;
4832 var->reset_val = *valueAddr;
4833 var->min = minValue;
4834 var->max = maxValue;
4835 var->assign_hook = assign_hook;
4836 var->show_hook = show_hook;
4837 define_custom_variable(&var->gen);
4841 DefineCustomRealVariable(const char *name,
4842 const char *short_desc,
4843 const char *long_desc,
4848 GucRealAssignHook assign_hook,
4849 GucShowHook show_hook)
4851 size_t sz = sizeof(struct config_real);
4852 struct config_real *var = (struct config_real *) guc_malloc(ERROR, sz);
4855 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_REAL);
4857 var->variable = valueAddr;
4858 var->reset_val = *valueAddr;
4859 var->min = minValue;
4860 var->max = maxValue;
4861 var->assign_hook = assign_hook;
4862 var->show_hook = show_hook;
4863 define_custom_variable(&var->gen);
4867 DefineCustomStringVariable(const char *name,
4868 const char *short_desc,
4869 const char *long_desc,
4872 GucStringAssignHook assign_hook,
4873 GucShowHook show_hook)
4875 size_t sz = sizeof(struct config_string);
4876 struct config_string *var = (struct config_string *) guc_malloc(ERROR, sz);
4879 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_STRING);
4881 var->variable = valueAddr;
4882 var->reset_val = *valueAddr;
4883 var->assign_hook = assign_hook;
4884 var->show_hook = show_hook;
4885 define_custom_variable(&var->gen);
4889 EmitWarningsOnPlaceholders(const char *className)
4891 struct config_generic **vars = guc_variables;
4892 struct config_generic **last = vars + num_guc_variables;
4894 int nameLen = strlen(className);
4898 struct config_generic *var = *vars++;
4900 if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
4901 strncmp(className, var->name, nameLen) == 0 &&
4902 var->name[nameLen] == GUC_QUALIFIER_SEPARATOR)
4905 (errcode(ERRCODE_UNDEFINED_OBJECT),
4906 errmsg("unrecognized configuration parameter \"%s\"", var->name)));
4916 GetPGVariable(const char *name, DestReceiver *dest)
4918 if (pg_strcasecmp(name, "all") == 0)
4919 ShowAllGUCConfig(dest);
4921 ShowGUCConfigOption(name, dest);
4925 GetPGVariableResultDesc(const char *name)
4929 if (pg_strcasecmp(name, "all") == 0)
4931 /* need a tuple descriptor representing three TEXT columns */
4932 tupdesc = CreateTemplateTupleDesc(3, false);
4933 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
4935 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
4937 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
4943 const char *varname;
4945 /* Get the canonical spelling of name */
4946 (void) GetConfigOptionByName(name, &varname);
4948 /* need a tuple descriptor representing a single TEXT column */
4949 tupdesc = CreateTemplateTupleDesc(1, false);
4950 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
4957 * RESET SESSION command.
4960 ResetSession(bool isTopLevel)
4963 * Disallow RESET SESSION in a transaction block. This is arguably
4964 * inconsistent (we don't make a similar check in the command
4965 * sequence that RESET SESSION is equivalent to), but the idea is
4966 * to catch mistakes: RESET SESSION inside a transaction block
4967 * would leave the transaction still uncommitted.
4969 PreventTransactionChain(isTopLevel, "RESET SESSION");
4971 SetPGVariable("session_authorization", NIL, false);
4973 DropAllPreparedStatements();
4974 PortalHashTableDeleteAll();
4975 Async_UnlistenAll();
4977 ResetTempTableNamespace();
4984 ResetPGVariable(const char *name, bool isTopLevel)
4986 if (pg_strcasecmp(name, "all") == 0)
4988 else if (pg_strcasecmp(name, "session") == 0)
4989 ResetSession(isTopLevel);
4990 else if (pg_strcasecmp(name, "temp") == 0 ||
4991 pg_strcasecmp(name, "temporary") == 0)
4992 ResetTempTableNamespace();
4993 else if (pg_strcasecmp(name, "plans") == 0)
4996 set_config_option(name,
4998 (superuser() ? PGC_SUSET : PGC_USERSET),
5009 ShowGUCConfigOption(const char *name, DestReceiver *dest)
5011 TupOutputState *tstate;
5013 const char *varname;
5016 /* Get the value and canonical spelling of name */
5017 value = GetConfigOptionByName(name, &varname);
5019 /* need a tuple descriptor representing a single TEXT column */
5020 tupdesc = CreateTemplateTupleDesc(1, false);
5021 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
5024 /* prepare for projection of tuples */
5025 tstate = begin_tup_output_tupdesc(dest, tupdesc);
5028 do_text_output_oneline(tstate, value);
5030 end_tup_output(tstate);
5037 ShowAllGUCConfig(DestReceiver *dest)
5039 bool am_superuser = superuser();
5041 TupOutputState *tstate;
5045 /* need a tuple descriptor representing three TEXT columns */
5046 tupdesc = CreateTemplateTupleDesc(3, false);
5047 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
5049 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
5051 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
5055 /* prepare for projection of tuples */
5056 tstate = begin_tup_output_tupdesc(dest, tupdesc);
5058 for (i = 0; i < num_guc_variables; i++)
5060 struct config_generic *conf = guc_variables[i];
5062 if ((conf->flags & GUC_NO_SHOW_ALL) ||
5063 ((conf->flags & GUC_SUPERUSER_ONLY) && !am_superuser))
5066 /* assign to the values array */
5067 values[0] = (char *) conf->name;
5068 values[1] = _ShowOption(conf, true);
5069 values[2] = (char *) conf->short_desc;
5071 /* send it to dest */
5072 do_tup_output(tstate, values);
5075 if (values[1] != NULL)
5079 end_tup_output(tstate);
5083 * Return GUC variable value by name; optionally return canonical
5084 * form of name. Return value is palloc'd.
5087 GetConfigOptionByName(const char *name, const char **varname)
5089 struct config_generic *record;
5091 record = find_option(name, ERROR);
5094 (errcode(ERRCODE_UNDEFINED_OBJECT),
5095 errmsg("unrecognized configuration parameter \"%s\"", name)));
5096 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
5098 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5099 errmsg("must be superuser to examine \"%s\"", name)));
5102 *varname = record->name;
5104 return _ShowOption(record, true);
5108 * Return GUC variable value by variable number; optionally return canonical
5109 * form of name. Return value is palloc'd.
5112 GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
5115 struct config_generic *conf;
5117 /* check requested variable number valid */
5118 Assert((varnum >= 0) && (varnum < num_guc_variables));
5120 conf = guc_variables[varnum];
5124 if ((conf->flags & GUC_NO_SHOW_ALL) ||
5125 ((conf->flags & GUC_SUPERUSER_ONLY) && !superuser()))
5131 /* first get the generic attributes */
5134 values[0] = conf->name;
5136 /* setting : use _ShowOption in order to avoid duplicating the logic */
5137 values[1] = _ShowOption(conf, false);
5140 if (conf->vartype == PGC_INT)
5144 switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
5149 case GUC_UNIT_BLOCKS:
5150 snprintf(buf, sizeof(buf), "%dkB", BLCKSZ / 1024);
5153 case GUC_UNIT_XBLOCKS:
5154 snprintf(buf, sizeof(buf), "%dkB", XLOG_BLCKSZ / 1024);
5175 values[3] = config_group_names[conf->group];
5178 values[4] = conf->short_desc;
5181 values[5] = conf->long_desc;
5184 values[6] = GucContext_Names[conf->context];
5187 values[7] = config_type_names[conf->vartype];
5190 values[8] = GucSource_Names[conf->source];
5192 /* now get the type specifc attributes */
5193 switch (conf->vartype)
5207 struct config_int *lconf = (struct config_int *) conf;
5210 snprintf(buffer, sizeof(buffer), "%d", lconf->min);
5211 values[9] = pstrdup(buffer);
5214 snprintf(buffer, sizeof(buffer), "%d", lconf->max);
5215 values[10] = pstrdup(buffer);
5221 struct config_real *lconf = (struct config_real *) conf;
5224 snprintf(buffer, sizeof(buffer), "%g", lconf->min);
5225 values[9] = pstrdup(buffer);
5228 snprintf(buffer, sizeof(buffer), "%g", lconf->max);
5229 values[10] = pstrdup(buffer);
5246 * should never get here, but in case we do, set 'em to NULL
5260 * Return the total number of GUC variables
5263 GetNumConfigOptions(void)
5265 return num_guc_variables;
5269 * show_config_by_name - equiv to SHOW X command but implemented as
5273 show_config_by_name(PG_FUNCTION_ARGS)
5279 /* Get the GUC variable name */
5280 varname = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(0)));
5283 varval = GetConfigOptionByName(varname, NULL);
5285 /* Convert to text */
5286 result_text = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(varval)));
5289 PG_RETURN_TEXT_P(result_text);
5293 * show_all_settings - equiv to SHOW ALL command but implemented as
5296 #define NUM_PG_SETTINGS_ATTS 11
5299 show_all_settings(PG_FUNCTION_ARGS)
5301 FuncCallContext *funcctx;
5305 AttInMetadata *attinmeta;
5306 MemoryContext oldcontext;
5308 /* stuff done only on the first call of the function */
5309 if (SRF_IS_FIRSTCALL())
5311 /* create a function context for cross-call persistence */
5312 funcctx = SRF_FIRSTCALL_INIT();
5315 * switch to memory context appropriate for multiple function calls
5317 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
5320 * need a tuple descriptor representing NUM_PG_SETTINGS_ATTS columns
5321 * of the appropriate types
5323 tupdesc = CreateTemplateTupleDesc(NUM_PG_SETTINGS_ATTS, false);
5324 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
5326 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
5328 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "unit",
5330 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "category",
5332 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "short_desc",
5334 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "extra_desc",
5336 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "context",
5338 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "vartype",
5340 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "source",
5342 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "min_val",
5344 TupleDescInitEntry(tupdesc, (AttrNumber) 11, "max_val",
5348 * Generate attribute metadata needed later to produce tuples from raw
5351 attinmeta = TupleDescGetAttInMetadata(tupdesc);
5352 funcctx->attinmeta = attinmeta;
5354 /* total number of tuples to be returned */
5355 funcctx->max_calls = GetNumConfigOptions();
5357 MemoryContextSwitchTo(oldcontext);
5360 /* stuff done on every call of the function */
5361 funcctx = SRF_PERCALL_SETUP();
5363 call_cntr = funcctx->call_cntr;
5364 max_calls = funcctx->max_calls;
5365 attinmeta = funcctx->attinmeta;
5367 if (call_cntr < max_calls) /* do when there is more left to send */
5369 char *values[NUM_PG_SETTINGS_ATTS];
5375 * Get the next visible GUC variable name and value
5379 GetConfigOptionByNum(call_cntr, (const char **) values, &noshow);
5382 /* bump the counter and get the next config setting */
5383 call_cntr = ++funcctx->call_cntr;
5385 /* make sure we haven't gone too far now */
5386 if (call_cntr >= max_calls)
5387 SRF_RETURN_DONE(funcctx);
5392 tuple = BuildTupleFromCStrings(attinmeta, values);
5394 /* make the tuple into a datum */
5395 result = HeapTupleGetDatum(tuple);
5397 SRF_RETURN_NEXT(funcctx, result);
5401 /* do when there is no more left */
5402 SRF_RETURN_DONE(funcctx);
5407 _ShowOption(struct config_generic * record, bool use_units)
5412 switch (record->vartype)
5416 struct config_bool *conf = (struct config_bool *) record;
5418 if (conf->show_hook)
5419 val = (*conf->show_hook) ();
5421 val = *conf->variable ? "on" : "off";
5427 struct config_int *conf = (struct config_int *) record;
5429 if (conf->show_hook)
5430 val = (*conf->show_hook) ();
5434 int result = *conf->variable;
5436 if (use_units && result > 0 && (record->flags & GUC_UNIT_MEMORY))
5438 switch (record->flags & GUC_UNIT_MEMORY)
5440 case GUC_UNIT_BLOCKS:
5441 result *= BLCKSZ / 1024;
5443 case GUC_UNIT_XBLOCKS:
5444 result *= XLOG_BLCKSZ / 1024;
5448 if (result % KB_PER_GB == 0)
5450 result /= KB_PER_GB;
5453 else if (result % KB_PER_MB == 0)
5455 result /= KB_PER_MB;
5463 else if (use_units && result > 0 && (record->flags & GUC_UNIT_TIME))
5465 switch (record->flags & GUC_UNIT_TIME)
5471 result *= MS_PER_MIN;
5475 if (result % MS_PER_D == 0)
5480 else if (result % MS_PER_H == 0)
5485 else if (result % MS_PER_MIN == 0)
5487 result /= MS_PER_MIN;
5488 strcpy(unit, "min");
5490 else if (result % MS_PER_S == 0)
5503 snprintf(buffer, sizeof(buffer), "%d%s",
5504 (int) result, unit);
5512 struct config_real *conf = (struct config_real *) record;
5514 if (conf->show_hook)
5515 val = (*conf->show_hook) ();
5518 snprintf(buffer, sizeof(buffer), "%g",
5527 struct config_string *conf = (struct config_string *) record;
5529 if (conf->show_hook)
5530 val = (*conf->show_hook) ();
5531 else if (*conf->variable && **conf->variable)
5532 val = *conf->variable;
5539 /* just to keep compiler quiet */
5544 return pstrdup(val);
5549 is_newvalue_equal(struct config_generic * record, const char *newvalue)
5551 switch (record->vartype)
5555 struct config_bool *conf = (struct config_bool *) record;
5558 return parse_bool(newvalue, &newval) && *conf->variable == newval;
5562 struct config_int *conf = (struct config_int *) record;
5565 return parse_int(newvalue, &newval, record->flags) && *conf->variable == newval;
5569 struct config_real *conf = (struct config_real *) record;
5572 return parse_real(newvalue, &newval) && *conf->variable == newval;
5576 struct config_string *conf = (struct config_string *) record;
5578 return strcmp(*conf->variable, newvalue) == 0;
5589 * This routine dumps out all non-default GUC options into a binary
5590 * file that is read by all exec'ed backends. The format is:
5592 * variable name, string, null terminated
5593 * variable value, string, null terminated
5594 * variable source, integer
5597 write_nondefault_variables(GucContext context)
5603 Assert(context == PGC_POSTMASTER || context == PGC_SIGHUP);
5605 elevel = (context == PGC_SIGHUP) ? LOG : ERROR;
5610 fp = AllocateFile(CONFIG_EXEC_PARAMS_NEW, "w");
5614 (errcode_for_file_access(),
5615 errmsg("could not write to file \"%s\": %m",
5616 CONFIG_EXEC_PARAMS_NEW)));
5620 for (i = 0; i < num_guc_variables; i++)
5622 struct config_generic *gconf = guc_variables[i];
5624 if (gconf->source != PGC_S_DEFAULT)
5626 fprintf(fp, "%s", gconf->name);
5629 switch (gconf->vartype)
5633 struct config_bool *conf = (struct config_bool *) gconf;
5635 if (*conf->variable == 0)
5636 fprintf(fp, "false");
5638 fprintf(fp, "true");
5644 struct config_int *conf = (struct config_int *) gconf;
5646 fprintf(fp, "%d", *conf->variable);
5652 struct config_real *conf = (struct config_real *) gconf;
5654 /* Could lose precision here? */
5655 fprintf(fp, "%f", *conf->variable);
5661 struct config_string *conf = (struct config_string *) gconf;
5663 fprintf(fp, "%s", *conf->variable);
5670 fwrite(&gconf->source, sizeof(gconf->source), 1, fp);
5677 (errcode_for_file_access(),
5678 errmsg("could not write to file \"%s\": %m",
5679 CONFIG_EXEC_PARAMS_NEW)));
5684 * Put new file in place. This could delay on Win32, but we don't hold
5685 * any exclusive locks.
5687 rename(CONFIG_EXEC_PARAMS_NEW, CONFIG_EXEC_PARAMS);
5692 * Read string, including null byte from file
5694 * Return NULL on EOF and nothing read
5697 read_string_with_null(FILE *fp)
5706 if ((ch = fgetc(fp)) == EOF)
5711 elog(FATAL, "invalid format of exec config params file");
5714 str = guc_malloc(FATAL, maxlen);
5715 else if (i == maxlen)
5716 str = guc_realloc(FATAL, str, maxlen *= 2);
5725 * This routine loads a previous postmaster dump of its non-default
5729 read_nondefault_variables(void)
5739 fp = AllocateFile(CONFIG_EXEC_PARAMS, "r");
5742 /* File not found is fine */
5743 if (errno != ENOENT)
5745 (errcode_for_file_access(),
5746 errmsg("could not read from file \"%s\": %m",
5747 CONFIG_EXEC_PARAMS)));
5753 struct config_generic *record;
5755 if ((varname = read_string_with_null(fp)) == NULL)
5758 if ((record = find_option(varname, FATAL)) == NULL)
5759 elog(FATAL, "failed to locate variable %s in exec config params file", varname);
5760 if ((varvalue = read_string_with_null(fp)) == NULL)
5761 elog(FATAL, "invalid format of exec config params file");
5762 if (fread(&varsource, sizeof(varsource), 1, fp) == 0)
5763 elog(FATAL, "invalid format of exec config params file");
5765 (void) set_config_option(varname, varvalue, record->context,
5766 varsource, false, true);
5773 #endif /* EXEC_BACKEND */
5777 * A little "long argument" simulation, although not quite GNU
5778 * compliant. Takes a string of the form "some-option=some value" and
5779 * returns name = "some_option" and value = "some value" in malloc'ed
5780 * storage. Note that '-' is converted to '_' in the option name. If
5781 * there is no '=' in the input string then value will be NULL.
5784 ParseLongOption(const char *string, char **name, char **value)
5793 equal_pos = strcspn(string, "=");
5795 if (string[equal_pos] == '=')
5797 *name = guc_malloc(FATAL, equal_pos + 1);
5798 strlcpy(*name, string, equal_pos + 1);
5800 *value = guc_strdup(FATAL, &string[equal_pos + 1]);
5804 /* no equal sign in string */
5805 *name = guc_strdup(FATAL, string);
5809 for (cp = *name; *cp; cp++)
5816 * Handle options fetched from pg_database.datconfig or pg_authid.rolconfig.
5817 * The array parameter must be an array of TEXT (it must not be NULL).
5820 ProcessGUCArray(ArrayType *array, GucSource source)
5824 Assert(array != NULL);
5825 Assert(ARR_ELEMTYPE(array) == TEXTOID);
5826 Assert(ARR_NDIM(array) == 1);
5827 Assert(ARR_LBOUND(array)[0] == 1);
5828 Assert(source == PGC_S_DATABASE || source == PGC_S_USER);
5830 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
5838 d = array_ref(array, 1, &i,
5839 -1 /* varlenarray */ ,
5840 -1 /* TEXT's typlen */ ,
5841 false /* TEXT's typbyval */ ,
5842 'i' /* TEXT's typalign */ ,
5848 s = DatumGetCString(DirectFunctionCall1(textout, d));
5850 ParseLongOption(s, &name, &value);
5854 (errcode(ERRCODE_SYNTAX_ERROR),
5855 errmsg("could not parse setting for parameter \"%s\"", name)));
5861 * We process all these options at SUSET level. We assume that the
5862 * right to insert an option into pg_database or pg_authid was checked
5863 * when it was inserted.
5865 SetConfigOption(name, value, PGC_SUSET, source);
5875 * Add an entry to an option array. The array parameter may be NULL
5876 * to indicate the current table entry is NULL.
5879 GUCArrayAdd(ArrayType *array, const char *name, const char *value)
5881 const char *varname;
5889 /* test if the option is valid */
5890 set_config_option(name, value,
5891 superuser() ? PGC_SUSET : PGC_USERSET,
5892 PGC_S_TEST, false, false);
5894 /* convert name to canonical spelling, so we can use plain strcmp */
5895 (void) GetConfigOptionByName(name, &varname);
5898 newval = palloc(strlen(name) + 1 + strlen(value) + 1);
5899 sprintf(newval, "%s=%s", name, value);
5900 datum = DirectFunctionCall1(textin, CStringGetDatum(newval));
5908 Assert(ARR_ELEMTYPE(array) == TEXTOID);
5909 Assert(ARR_NDIM(array) == 1);
5910 Assert(ARR_LBOUND(array)[0] == 1);
5912 index = ARR_DIMS(array)[0] + 1; /* add after end */
5914 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
5919 d = array_ref(array, 1, &i,
5920 -1 /* varlenarray */ ,
5921 -1 /* TEXT's typlen */ ,
5922 false /* TEXT's typbyval */ ,
5923 'i' /* TEXT's typalign */ ,
5927 current = DatumGetCString(DirectFunctionCall1(textout, d));
5928 if (strncmp(current, newval, strlen(name) + 1) == 0)
5935 a = array_set(array, 1, &index,
5938 -1 /* varlena array */ ,
5939 -1 /* TEXT's typlen */ ,
5940 false /* TEXT's typbyval */ ,
5941 'i' /* TEXT's typalign */ );
5944 a = construct_array(&datum, 1,
5953 * Delete an entry from an option array. The array parameter may be NULL
5954 * to indicate the current table entry is NULL. Also, if the return value
5955 * is NULL then a null should be stored.
5958 GUCArrayDelete(ArrayType *array, const char *name)
5960 const char *varname;
5961 ArrayType *newarray;
5967 /* test if the option is valid */
5968 set_config_option(name, NULL,
5969 superuser() ? PGC_SUSET : PGC_USERSET,
5970 PGC_S_TEST, false, false);
5972 /* convert name to canonical spelling, so we can use plain strcmp */
5973 (void) GetConfigOptionByName(name, &varname);
5976 /* if array is currently null, then surely nothing to delete */
5983 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
5989 d = array_ref(array, 1, &i,
5990 -1 /* varlenarray */ ,
5991 -1 /* TEXT's typlen */ ,
5992 false /* TEXT's typbyval */ ,
5993 'i' /* TEXT's typalign */ ,
5997 val = DatumGetCString(DirectFunctionCall1(textout, d));
5999 /* ignore entry if it's what we want to delete */
6000 if (strncmp(val, name, strlen(name)) == 0
6001 && val[strlen(name)] == '=')
6004 /* else add it to the output array */
6007 newarray = array_set(newarray, 1, &index,
6010 -1 /* varlenarray */ ,
6011 -1 /* TEXT's typlen */ ,
6012 false /* TEXT's typbyval */ ,
6013 'i' /* TEXT's typalign */ );
6016 newarray = construct_array(&d, 1,
6028 * assign_hook subroutines
6032 assign_log_destination(const char *value, bool doit, GucSource source)
6039 /* Need a modifiable copy of string */
6040 rawstring = pstrdup(value);
6042 /* Parse string into list of identifiers */
6043 if (!SplitIdentifierString(rawstring, ',', &elemlist))
6045 /* syntax error in list */
6047 list_free(elemlist);
6048 if (source >= PGC_S_INTERACTIVE)
6050 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6051 errmsg("invalid list syntax for parameter \"log_destination\"")));
6055 foreach(l, elemlist)
6057 char *tok = (char *) lfirst(l);
6059 if (pg_strcasecmp(tok, "stderr") == 0)
6060 newlogdest |= LOG_DESTINATION_STDERR;
6062 else if (pg_strcasecmp(tok, "syslog") == 0)
6063 newlogdest |= LOG_DESTINATION_SYSLOG;
6066 else if (pg_strcasecmp(tok, "eventlog") == 0)
6067 newlogdest |= LOG_DESTINATION_EVENTLOG;
6071 if (source >= PGC_S_INTERACTIVE)
6073 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6074 errmsg("unrecognized \"log_destination\" key word: \"%s\"",
6077 list_free(elemlist);
6083 Log_destination = newlogdest;
6086 list_free(elemlist);
6094 assign_syslog_facility(const char *facility, bool doit, GucSource source)
6098 if (pg_strcasecmp(facility, "LOCAL0") == 0)
6099 syslog_fac = LOG_LOCAL0;
6100 else if (pg_strcasecmp(facility, "LOCAL1") == 0)
6101 syslog_fac = LOG_LOCAL1;
6102 else if (pg_strcasecmp(facility, "LOCAL2") == 0)
6103 syslog_fac = LOG_LOCAL2;
6104 else if (pg_strcasecmp(facility, "LOCAL3") == 0)
6105 syslog_fac = LOG_LOCAL3;
6106 else if (pg_strcasecmp(facility, "LOCAL4") == 0)
6107 syslog_fac = LOG_LOCAL4;
6108 else if (pg_strcasecmp(facility, "LOCAL5") == 0)
6109 syslog_fac = LOG_LOCAL5;
6110 else if (pg_strcasecmp(facility, "LOCAL6") == 0)
6111 syslog_fac = LOG_LOCAL6;
6112 else if (pg_strcasecmp(facility, "LOCAL7") == 0)
6113 syslog_fac = LOG_LOCAL7;
6115 return NULL; /* reject */
6119 syslog_facility = syslog_fac;
6120 set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
6128 assign_syslog_ident(const char *ident, bool doit, GucSource source)
6131 set_syslog_parameters(ident, syslog_facility);
6135 #endif /* HAVE_SYSLOG */
6139 assign_defaultxactisolevel(const char *newval, bool doit, GucSource source)
6141 if (pg_strcasecmp(newval, "serializable") == 0)
6144 DefaultXactIsoLevel = XACT_SERIALIZABLE;
6146 else if (pg_strcasecmp(newval, "repeatable read") == 0)
6149 DefaultXactIsoLevel = XACT_REPEATABLE_READ;
6151 else if (pg_strcasecmp(newval, "read committed") == 0)
6154 DefaultXactIsoLevel = XACT_READ_COMMITTED;
6156 else if (pg_strcasecmp(newval, "read uncommitted") == 0)
6159 DefaultXactIsoLevel = XACT_READ_UNCOMMITTED;
6167 assign_session_replication_role(const char *newval, bool doit, GucSource source)
6169 if (HaveCachedPlans())
6170 elog(ERROR, "session_replication_role cannot be changed "
6171 "after prepared plans have been cached");
6173 if (pg_strcasecmp(newval, "origin") == 0)
6176 SessionReplicationRole = SESSION_REPLICATION_ROLE_ORIGIN;
6178 else if (pg_strcasecmp(newval, "replica") == 0)
6181 SessionReplicationRole = SESSION_REPLICATION_ROLE_REPLICA;
6183 else if (pg_strcasecmp(newval, "local") == 0)
6186 SessionReplicationRole = SESSION_REPLICATION_ROLE_LOCAL;
6194 assign_log_min_messages(const char *newval,
6195 bool doit, GucSource source)
6197 return (assign_msglvl(&log_min_messages, newval, doit, source));
6201 assign_client_min_messages(const char *newval, bool doit, GucSource source)
6203 return (assign_msglvl(&client_min_messages, newval, doit, source));
6207 assign_min_error_statement(const char *newval, bool doit, GucSource source)
6209 return (assign_msglvl(&log_min_error_statement, newval, doit, source));
6213 assign_msglvl(int *var, const char *newval, bool doit, GucSource source)
6215 if (pg_strcasecmp(newval, "debug") == 0)
6220 else if (pg_strcasecmp(newval, "debug5") == 0)
6225 else if (pg_strcasecmp(newval, "debug4") == 0)
6230 else if (pg_strcasecmp(newval, "debug3") == 0)
6235 else if (pg_strcasecmp(newval, "debug2") == 0)
6240 else if (pg_strcasecmp(newval, "debug1") == 0)
6245 else if (pg_strcasecmp(newval, "log") == 0)
6252 * Client_min_messages always prints 'info', but we allow it as a value
6255 else if (pg_strcasecmp(newval, "info") == 0)
6260 else if (pg_strcasecmp(newval, "notice") == 0)
6265 else if (pg_strcasecmp(newval, "warning") == 0)
6270 else if (pg_strcasecmp(newval, "error") == 0)
6275 /* We allow FATAL/PANIC for client-side messages too. */
6276 else if (pg_strcasecmp(newval, "fatal") == 0)
6281 else if (pg_strcasecmp(newval, "panic") == 0)
6287 return NULL; /* fail */
6288 return newval; /* OK */
6292 assign_log_error_verbosity(const char *newval, bool doit, GucSource source)
6294 if (pg_strcasecmp(newval, "terse") == 0)
6297 Log_error_verbosity = PGERROR_TERSE;
6299 else if (pg_strcasecmp(newval, "default") == 0)
6302 Log_error_verbosity = PGERROR_DEFAULT;
6304 else if (pg_strcasecmp(newval, "verbose") == 0)
6307 Log_error_verbosity = PGERROR_VERBOSE;
6310 return NULL; /* fail */
6311 return newval; /* OK */
6315 assign_log_statement(const char *newval, bool doit, GucSource source)
6317 if (pg_strcasecmp(newval, "none") == 0)
6320 log_statement = LOGSTMT_NONE;
6322 else if (pg_strcasecmp(newval, "ddl") == 0)
6325 log_statement = LOGSTMT_DDL;
6327 else if (pg_strcasecmp(newval, "mod") == 0)
6330 log_statement = LOGSTMT_MOD;
6332 else if (pg_strcasecmp(newval, "all") == 0)
6335 log_statement = LOGSTMT_ALL;
6338 return NULL; /* fail */
6339 return newval; /* OK */
6343 show_num_temp_buffers(void)
6346 * We show the GUC var until local buffers have been initialized, and
6347 * NLocBuffer afterwards.
6349 static char nbuf[32];
6351 sprintf(nbuf, "%d", NLocBuffer ? NLocBuffer : num_temp_buffers);
6356 assign_phony_autocommit(bool newval, bool doit, GucSource source)
6360 if (doit && source >= PGC_S_INTERACTIVE)
6362 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6363 errmsg("SET AUTOCOMMIT TO OFF is no longer supported")));
6370 assign_custom_variable_classes(const char *newval, bool doit, GucSource source)
6373 * Check syntax. newval must be a comma separated list of identifiers.
6374 * Whitespace is allowed but skipped.
6376 bool hasSpaceAfterToken = false;
6377 const char *cp = newval;
6382 initStringInfo(&buf);
6383 while ((c = *cp++) != 0)
6385 if (isspace((unsigned char) c))
6388 hasSpaceAfterToken = true;
6394 hasSpaceAfterToken = false;
6398 appendStringInfoChar(&buf, ',');
6403 if (hasSpaceAfterToken || !isalnum((unsigned char) c))
6406 * Syntax error due to token following space after token or non
6407 * alpha numeric character
6410 (errcode(ERRCODE_SYNTAX_ERROR),
6411 errmsg("invalid syntax for \"custom_variable_classes\": \"%s\"", newval)));
6416 appendStringInfoChar(&buf, (char) c);
6419 /* Remove stray ',' at end */
6420 if (symLen == 0 && buf.len > 0)
6421 buf.data[--buf.len] = '\0';
6426 newval = strdup(buf.data);
6433 assign_debug_assertions(bool newval, bool doit, GucSource source)
6435 #ifndef USE_ASSERT_CHECKING
6438 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6439 errmsg("assertion checking is not supported by this build")));
6445 assign_ssl(bool newval, bool doit, GucSource source)
6450 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6451 errmsg("SSL is not supported by this build")));
6457 assign_stage_log_stats(bool newval, bool doit, GucSource source)
6459 if (newval && log_statement_stats)
6461 if (source >= PGC_S_INTERACTIVE)
6463 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6464 errmsg("cannot enable parameter when \"log_statement_stats\" is true")));
6465 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
6466 else if (source != PGC_S_OVERRIDE)
6473 assign_log_stats(bool newval, bool doit, GucSource source)
6476 (log_parser_stats || log_planner_stats || log_executor_stats))
6478 if (source >= PGC_S_INTERACTIVE)
6480 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6481 errmsg("cannot enable \"log_statement_stats\" when "
6482 "\"log_parser_stats\", \"log_planner_stats\", "
6483 "or \"log_executor_stats\" is true")));
6484 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
6485 else if (source != PGC_S_OVERRIDE)
6492 assign_transaction_read_only(bool newval, bool doit, GucSource source)
6494 /* Can't go to r/w mode inside a r/o transaction */
6495 if (newval == false && XactReadOnly && IsSubTransaction())
6497 if (source >= PGC_S_INTERACTIVE)
6499 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6500 errmsg("cannot set transaction read-write mode inside a read-only transaction")));
6501 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
6502 else if (source != PGC_S_OVERRIDE)
6509 assign_canonical_path(const char *newval, bool doit, GucSource source)
6513 char *canon_val = guc_strdup(ERROR, newval);
6515 canonicalize_path(canon_val);
6523 assign_backslash_quote(const char *newval, bool doit, GucSource source)
6525 BackslashQuoteType bq;
6529 * Although only "on", "off", and "safe_encoding" are documented, we use
6530 * parse_bool so we can accept all the likely variants of "on" and "off".
6532 if (pg_strcasecmp(newval, "safe_encoding") == 0)
6533 bq = BACKSLASH_QUOTE_SAFE_ENCODING;
6534 else if (parse_bool(newval, &bqbool))
6536 bq = bqbool ? BACKSLASH_QUOTE_ON : BACKSLASH_QUOTE_OFF;
6539 return NULL; /* reject */
6542 backslash_quote = bq;
6548 assign_timezone_abbreviations(const char *newval, bool doit, GucSource source)
6551 * The powerup value shown above for timezone_abbreviations is "UNKNOWN".
6552 * When we see this we just do nothing. If this value isn't overridden
6553 * from the config file then pg_timezone_abbrev_initialize() will
6554 * eventually replace it with "Default". This hack has two purposes: to
6555 * avoid wasting cycles loading values that might soon be overridden from
6556 * the config file, and to avoid trying to read the timezone abbrev files
6557 * during InitializeGUCOptions(). The latter doesn't work in an
6558 * EXEC_BACKEND subprocess because my_exec_path hasn't been set yet and so
6559 * we can't locate PGSHAREDIR. (Essentially the same hack is used to
6560 * delay initializing TimeZone ... if we have any more, we should try to
6561 * clean up and centralize this mechanism ...)
6563 if (strcmp(newval, "UNKNOWN") == 0)
6568 /* Loading abbrev file is expensive, so only do it when value changes */
6569 if (timezone_abbreviations_string == NULL ||
6570 strcmp(timezone_abbreviations_string, newval) != 0)
6575 * If reading config file, only the postmaster should bleat loudly
6576 * about problems. Otherwise, it's just this one process doing it,
6577 * and we use WARNING message level.
6579 if (source == PGC_S_FILE)
6580 elevel = IsUnderPostmaster ? DEBUG2 : LOG;
6583 if (!load_tzoffsets(newval, doit, elevel))
6590 * pg_timezone_abbrev_initialize --- set default value if not done already
6592 * This is called after initial loading of postgresql.conf. If no
6593 * timezone_abbreviations setting was found therein, select default.
6596 pg_timezone_abbrev_initialize(void)
6598 if (strcmp(timezone_abbreviations_string, "UNKNOWN") == 0)
6600 SetConfigOption("timezone_abbreviations", "Default",
6601 PGC_POSTMASTER, PGC_S_ARGV);
6606 assign_xmlbinary(const char *newval, bool doit, GucSource source)
6610 if (pg_strcasecmp(newval, "base64") == 0)
6611 xb = XMLBINARY_BASE64;
6612 else if (pg_strcasecmp(newval, "hex") == 0)
6615 return NULL; /* reject */
6624 assign_xmloption(const char *newval, bool doit, GucSource source)
6628 if (pg_strcasecmp(newval, "document") == 0)
6629 xo = XMLOPTION_DOCUMENT;
6630 else if (pg_strcasecmp(newval, "content") == 0)
6631 xo = XMLOPTION_CONTENT;
6633 return NULL; /* reject */
6642 assign_tcp_keepalives_idle(int newval, bool doit, GucSource source)
6645 return (pq_setkeepalivesidle(newval, MyProcPort) == STATUS_OK);
6651 show_tcp_keepalives_idle(void)
6653 static char nbuf[16];
6655 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesidle(MyProcPort));
6660 assign_tcp_keepalives_interval(int newval, bool doit, GucSource source)
6663 return (pq_setkeepalivesinterval(newval, MyProcPort) == STATUS_OK);
6669 show_tcp_keepalives_interval(void)
6671 static char nbuf[16];
6673 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesinterval(MyProcPort));
6678 assign_tcp_keepalives_count(int newval, bool doit, GucSource source)
6681 return (pq_setkeepalivescount(newval, MyProcPort) == STATUS_OK);
6687 show_tcp_keepalives_count(void)
6689 static char nbuf[16];
6691 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivescount(MyProcPort));
6696 #include "guc-file.c"