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-2006, PostgreSQL Global Development Group
10 * Written by Peter Eisentraut <peter_e@gmx.net>.
13 * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.332 2006/07/27 08:30:41 petere Exp $
15 *--------------------------------------------------------------------
29 #include "access/gin.h"
30 #include "access/twophase.h"
31 #include "access/xact.h"
32 #include "catalog/namespace.h"
33 #include "commands/async.h"
34 #include "commands/vacuum.h"
35 #include "commands/variable.h"
37 #include "libpq/auth.h"
38 #include "libpq/pqformat.h"
39 #include "miscadmin.h"
40 #include "optimizer/cost.h"
41 #include "optimizer/geqo.h"
42 #include "optimizer/paths.h"
43 #include "optimizer/planmain.h"
44 #include "parser/gramparse.h"
45 #include "parser/parse_expr.h"
46 #include "parser/parse_relation.h"
47 #include "parser/scansup.h"
49 #include "postmaster/autovacuum.h"
50 #include "postmaster/bgwriter.h"
51 #include "postmaster/postmaster.h"
52 #include "postmaster/syslogger.h"
53 #include "storage/fd.h"
54 #include "storage/freespace.h"
55 #include "tcop/tcopprot.h"
56 #include "utils/builtins.h"
57 #include "utils/guc_tables.h"
58 #include "utils/memutils.h"
59 #include "utils/pg_locale.h"
60 #include "utils/ps_status.h"
61 #include "utils/tzparser.h"
64 #define PG_KRB_SRVTAB ""
67 #define PG_KRB_SRVNAM ""
70 #define CONFIG_FILENAME "postgresql.conf"
71 #define HBA_FILENAME "pg_hba.conf"
72 #define IDENT_FILENAME "pg_ident.conf"
75 #define CONFIG_EXEC_PARAMS "global/config_exec_params"
76 #define CONFIG_EXEC_PARAMS_NEW "global/config_exec_params.new"
79 /* upper limit for GUC variables measured in kilobytes of memory */
81 #define MAX_KILOBYTES INT_MAX
83 #define MAX_KILOBYTES (INT_MAX / 1024)
86 #define KB_PER_MB (1024)
87 #define KB_PER_GB (1024*1024)
90 #define MS_PER_MIN (1000 * 60)
91 #define MS_PER_H (1000 * 60 * 60)
92 #define MS_PER_D (1000 * 60 * 60 * 24)
94 /* XXX these should appear in other modules' header files */
95 extern bool Log_disconnections;
96 extern bool check_function_bodies;
97 extern int CommitDelay;
98 extern int CommitSiblings;
99 extern char *default_tablespace;
100 extern bool fullPageWrites;
103 extern bool trace_sort;
106 static const char *assign_log_destination(const char *value,
107 bool doit, GucSource source);
110 static int syslog_facility = LOG_LOCAL0;
112 static const char *assign_syslog_facility(const char *facility,
113 bool doit, GucSource source);
114 static const char *assign_syslog_ident(const char *ident,
115 bool doit, GucSource source);
118 static const char *assign_defaultxactisolevel(const char *newval, bool doit,
120 static const char *assign_log_min_messages(const char *newval, bool doit,
122 static const char *assign_client_min_messages(const char *newval,
123 bool doit, GucSource source);
124 static const char *assign_min_error_statement(const char *newval, bool doit,
126 static const char *assign_msglvl(int *var, const char *newval, bool doit,
128 static const char *assign_log_error_verbosity(const char *newval, bool doit,
130 static const char *assign_log_statement(const char *newval, bool doit,
132 static const char *show_num_temp_buffers(void);
133 static bool assign_phony_autocommit(bool newval, bool doit, GucSource source);
134 static const char *assign_custom_variable_classes(const char *newval, bool doit,
136 static bool assign_debug_assertions(bool newval, bool doit, GucSource source);
137 static bool assign_ssl(bool newval, bool doit, GucSource source);
138 static bool assign_stage_log_stats(bool newval, bool doit, GucSource source);
139 static bool assign_log_stats(bool newval, bool doit, GucSource source);
140 static bool assign_transaction_read_only(bool newval, bool doit, GucSource source);
141 static const char *assign_canonical_path(const char *newval, bool doit, GucSource source);
142 static const char *assign_backslash_quote(const char *newval, bool doit, GucSource source);
143 static const char *assign_timezone_abbreviations(const char *newval, bool doit, GucSource source);
145 static bool assign_tcp_keepalives_idle(int newval, bool doit, GucSource source);
146 static bool assign_tcp_keepalives_interval(int newval, bool doit, GucSource source);
147 static bool assign_tcp_keepalives_count(int newval, bool doit, GucSource source);
148 static const char *show_tcp_keepalives_idle(void);
149 static const char *show_tcp_keepalives_interval(void);
150 static const char *show_tcp_keepalives_count(void);
153 * GUC option variables that are exported from this module
155 #ifdef USE_ASSERT_CHECKING
156 bool assert_enabled = true;
158 bool assert_enabled = false;
160 bool log_duration = false;
161 bool Debug_print_plan = false;
162 bool Debug_print_parse = false;
163 bool Debug_print_rewritten = false;
164 bool Debug_pretty_print = false;
165 bool Explain_pretty_print = true;
167 bool log_parser_stats = false;
168 bool log_planner_stats = false;
169 bool log_executor_stats = false;
170 bool log_statement_stats = false; /* this is sort of all three
172 bool log_btree_build_stats = false;
174 bool SQL_inheritance = true;
176 bool Password_encryption = true;
178 bool default_with_oids = false;
180 int log_min_error_statement = PANIC;
181 int log_min_messages = NOTICE;
182 int client_min_messages = NOTICE;
183 int log_min_duration_statement = -1;
185 int num_temp_buffers = 1000;
187 char *ConfigFileName;
190 char *external_pid_file;
192 int tcp_keepalives_idle;
193 int tcp_keepalives_interval;
194 int tcp_keepalives_count;
197 * These variables are all dummies that don't do anything, except in some
198 * cases provide the value for SHOW to display. The real state is elsewhere
199 * and is kept in sync by assign_hooks.
201 static char *client_min_messages_str;
202 static char *log_min_messages_str;
203 static char *log_error_verbosity_str;
204 static char *log_statement_str;
205 static char *log_min_error_statement_str;
206 static char *log_destination_string;
208 static char *syslog_facility_str;
209 static char *syslog_ident_str;
211 static bool phony_autocommit;
212 static bool session_auth_is_superuser;
213 static double phony_random_seed;
214 static char *backslash_quote_string;
215 static char *client_encoding_string;
216 static char *datestyle_string;
217 static char *default_iso_level_string;
218 static char *locale_collate;
219 static char *locale_ctype;
220 static char *regex_flavor_string;
221 static char *server_encoding_string;
222 static char *server_version_string;
223 static char *timezone_string;
224 static char *XactIsoLevel_string;
225 static char *data_directory;
226 static char *custom_variable_classes;
227 static char *timezone_abbreviations;
228 static int max_function_args;
229 static int max_index_keys;
230 static int max_identifier_length;
231 static int block_size;
232 static bool integer_datetimes;
234 /* should be static, but commands/variable.c needs to get at these */
236 char *session_authorization_string;
240 * Displayable names for context types (enum GucContext)
242 * Note: these strings are deliberately not localized.
244 const char *const GucContext_Names[] =
246 /* PGC_INTERNAL */ "internal",
247 /* PGC_POSTMASTER */ "postmaster",
248 /* PGC_SIGHUP */ "sighup",
249 /* PGC_BACKEND */ "backend",
250 /* PGC_SUSET */ "superuser",
251 /* PGC_USERSET */ "user"
255 * Displayable names for source types (enum GucSource)
257 * Note: these strings are deliberately not localized.
259 const char *const GucSource_Names[] =
261 /* PGC_S_DEFAULT */ "default",
262 /* PGC_S_ENV_VAR */ "environment variable",
263 /* PGC_S_FILE */ "configuration file",
264 /* PGC_S_ARGV */ "command line",
265 /* PGC_S_DATABASE */ "database",
266 /* PGC_S_USER */ "user",
267 /* PGC_S_CLIENT */ "client",
268 /* PGC_S_OVERRIDE */ "override",
269 /* PGC_S_INTERACTIVE */ "interactive",
270 /* PGC_S_TEST */ "test",
271 /* PGC_S_SESSION */ "session"
275 * Displayable names for the groupings defined in enum config_group
277 const char *const config_group_names[] =
280 gettext_noop("Ungrouped"),
282 gettext_noop("File Locations"),
284 gettext_noop("Connections and Authentication"),
285 /* CONN_AUTH_SETTINGS */
286 gettext_noop("Connections and Authentication / Connection Settings"),
287 /* CONN_AUTH_SECURITY */
288 gettext_noop("Connections and Authentication / Security and Authentication"),
290 gettext_noop("Resource Usage"),
292 gettext_noop("Resource Usage / Memory"),
294 gettext_noop("Resource Usage / Free Space Map"),
295 /* RESOURCES_KERNEL */
296 gettext_noop("Resource Usage / Kernel Resources"),
298 gettext_noop("Write-Ahead Log"),
300 gettext_noop("Write-Ahead Log / Settings"),
301 /* WAL_CHECKPOINTS */
302 gettext_noop("Write-Ahead Log / Checkpoints"),
304 gettext_noop("Query Tuning"),
305 /* QUERY_TUNING_METHOD */
306 gettext_noop("Query Tuning / Planner Method Configuration"),
307 /* QUERY_TUNING_COST */
308 gettext_noop("Query Tuning / Planner Cost Constants"),
309 /* QUERY_TUNING_GEQO */
310 gettext_noop("Query Tuning / Genetic Query Optimizer"),
311 /* QUERY_TUNING_OTHER */
312 gettext_noop("Query Tuning / Other Planner Options"),
314 gettext_noop("Reporting and Logging"),
316 gettext_noop("Reporting and Logging / Where to Log"),
318 gettext_noop("Reporting and Logging / When to Log"),
320 gettext_noop("Reporting and Logging / What to Log"),
322 gettext_noop("Statistics"),
323 /* STATS_MONITORING */
324 gettext_noop("Statistics / Monitoring"),
325 /* STATS_COLLECTOR */
326 gettext_noop("Statistics / Query and Index Statistics Collector"),
328 gettext_noop("Autovacuum"),
330 gettext_noop("Client Connection Defaults"),
331 /* CLIENT_CONN_STATEMENT */
332 gettext_noop("Client Connection Defaults / Statement Behavior"),
333 /* CLIENT_CONN_LOCALE */
334 gettext_noop("Client Connection Defaults / Locale and Formatting"),
335 /* CLIENT_CONN_OTHER */
336 gettext_noop("Client Connection Defaults / Other Defaults"),
337 /* LOCK_MANAGEMENT */
338 gettext_noop("Lock Management"),
340 gettext_noop("Version and Platform Compatibility"),
341 /* COMPAT_OPTIONS_PREVIOUS */
342 gettext_noop("Version and Platform Compatibility / Previous PostgreSQL Versions"),
343 /* COMPAT_OPTIONS_CLIENT */
344 gettext_noop("Version and Platform Compatibility / Other Platforms and Clients"),
346 gettext_noop("Preset Options"),
348 gettext_noop("Customized Options"),
349 /* DEVELOPER_OPTIONS */
350 gettext_noop("Developer Options"),
351 /* help_config wants this array to be null-terminated */
356 * Displayable names for GUC variable types (enum config_type)
358 * Note: these strings are deliberately not localized.
360 const char *const config_type_names[] =
362 /* PGC_BOOL */ "bool",
363 /* PGC_INT */ "integer",
364 /* PGC_REAL */ "real",
365 /* PGC_STRING */ "string"
370 * Contents of GUC tables
372 * See src/backend/utils/misc/README for design notes.
376 * 1. Declare a global variable of type bool, int, double, or char*
377 * and make use of it.
379 * 2. Decide at what times it's safe to set the option. See guc.h for
382 * 3. Decide on a name, a default value, upper and lower bounds (if
385 * 4. Add a record below.
387 * 5. Add it to src/backend/utils/misc/postgresql.conf.sample, if
390 * 6. Add it to src/bin/psql/tab-complete.c, if it's a USERSET option.
392 * 7. Don't forget to document the option.
394 * 8. If it's a new GUC_LIST option you must edit pg_dumpall.c to ensure
395 * it is not single quoted at dump time.
399 /******** option records follow ********/
401 static struct config_bool ConfigureNamesBool[] =
404 {"enable_seqscan", PGC_USERSET, QUERY_TUNING_METHOD,
405 gettext_noop("Enables the planner's use of sequential-scan plans."),
412 {"enable_indexscan", PGC_USERSET, QUERY_TUNING_METHOD,
413 gettext_noop("Enables the planner's use of index-scan plans."),
420 {"enable_bitmapscan", PGC_USERSET, QUERY_TUNING_METHOD,
421 gettext_noop("Enables the planner's use of bitmap-scan plans."),
428 {"enable_tidscan", PGC_USERSET, QUERY_TUNING_METHOD,
429 gettext_noop("Enables the planner's use of TID scan plans."),
436 {"enable_sort", PGC_USERSET, QUERY_TUNING_METHOD,
437 gettext_noop("Enables the planner's use of explicit sort steps."),
444 {"enable_hashagg", PGC_USERSET, QUERY_TUNING_METHOD,
445 gettext_noop("Enables the planner's use of hashed aggregation plans."),
452 {"enable_nestloop", PGC_USERSET, QUERY_TUNING_METHOD,
453 gettext_noop("Enables the planner's use of nested-loop join plans."),
460 {"enable_mergejoin", PGC_USERSET, QUERY_TUNING_METHOD,
461 gettext_noop("Enables the planner's use of merge join plans."),
468 {"enable_hashjoin", PGC_USERSET, QUERY_TUNING_METHOD,
469 gettext_noop("Enables the planner's use of hash join plans."),
476 {"constraint_exclusion", PGC_USERSET, QUERY_TUNING_OTHER,
477 gettext_noop("Enables the planner to use constraints to optimize queries."),
478 gettext_noop("Child table scans will be skipped if their "
479 "constraints guarantee that no rows match the query.")
481 &constraint_exclusion,
485 {"geqo", PGC_USERSET, QUERY_TUNING_GEQO,
486 gettext_noop("Enables genetic query optimization."),
487 gettext_noop("This algorithm attempts to do planning without "
488 "exhaustive searching.")
494 /* Not for general use --- used by SET SESSION AUTHORIZATION */
495 {"is_superuser", PGC_INTERNAL, UNGROUPED,
496 gettext_noop("Shows whether the current user is a superuser."),
498 GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
500 &session_auth_is_superuser,
504 {"ssl", PGC_POSTMASTER, CONN_AUTH_SECURITY,
505 gettext_noop("Enables SSL connections."),
509 false, assign_ssl, NULL
512 {"fsync", PGC_SIGHUP, WAL_SETTINGS,
513 gettext_noop("Forces synchronization of updates to disk."),
514 gettext_noop("The server will use the fsync() system call in several places to make "
515 "sure that updates are physically written to disk. This insures "
516 "that a database cluster will recover to a consistent state after "
517 "an operating system or hardware crash.")
523 {"zero_damaged_pages", PGC_SUSET, DEVELOPER_OPTIONS,
524 gettext_noop("Continues processing past damaged page headers."),
525 gettext_noop("Detection of a damaged page header normally causes PostgreSQL to "
526 "report an error, aborting the current transaction. Setting "
527 "zero_damaged_pages to true causes the system to instead report a "
528 "warning, zero out the damaged page, and continue processing. This "
529 "behavior will destroy data, namely all the rows on the damaged page."),
536 {"full_page_writes", PGC_SIGHUP, WAL_SETTINGS,
537 gettext_noop("Writes full pages to WAL when first modified after a checkpoint."),
538 gettext_noop("A page write in process during an operating system crash might be "
539 "only partially written to disk. During recovery, the row changes "
540 "stored in WAL are not enough to recover. This option writes "
541 "pages when first modified after a checkpoint to WAL so full recovery "
548 {"silent_mode", PGC_POSTMASTER, LOGGING_WHEN,
549 gettext_noop("Runs the server silently."),
550 gettext_noop("If this parameter is set, the server will automatically run in the "
551 "background and any controlling terminals are dissociated.")
557 {"log_connections", PGC_BACKEND, LOGGING_WHAT,
558 gettext_noop("Logs each successful connection."),
565 {"log_disconnections", PGC_BACKEND, LOGGING_WHAT,
566 gettext_noop("Logs end of a session, including duration."),
573 {"debug_assertions", PGC_USERSET, DEVELOPER_OPTIONS,
574 gettext_noop("Turns on various assertion checks."),
575 gettext_noop("This is a debugging aid."),
579 #ifdef USE_ASSERT_CHECKING
584 assign_debug_assertions, NULL
587 /* currently undocumented, so don't show in SHOW ALL */
588 {"exit_on_error", PGC_USERSET, UNGROUPED,
589 gettext_noop("no description available"),
591 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
597 {"log_duration", PGC_SUSET, LOGGING_WHAT,
598 gettext_noop("Logs the duration of each completed SQL statement."),
605 {"debug_print_parse", PGC_USERSET, LOGGING_WHAT,
606 gettext_noop("Prints the parse tree to the server log."),
613 {"debug_print_rewritten", PGC_USERSET, LOGGING_WHAT,
614 gettext_noop("Prints the parse tree after rewriting to server log."),
617 &Debug_print_rewritten,
621 {"debug_print_plan", PGC_USERSET, LOGGING_WHAT,
622 gettext_noop("Prints the execution plan to server log."),
629 {"debug_pretty_print", PGC_USERSET, LOGGING_WHAT,
630 gettext_noop("Indents parse and plan tree displays."),
637 {"log_parser_stats", PGC_SUSET, STATS_MONITORING,
638 gettext_noop("Writes parser performance statistics to the server log."),
642 false, assign_stage_log_stats, NULL
645 {"log_planner_stats", PGC_SUSET, STATS_MONITORING,
646 gettext_noop("Writes planner performance statistics to the server log."),
650 false, assign_stage_log_stats, NULL
653 {"log_executor_stats", PGC_SUSET, STATS_MONITORING,
654 gettext_noop("Writes executor performance statistics to the server log."),
658 false, assign_stage_log_stats, NULL
661 {"log_statement_stats", PGC_SUSET, STATS_MONITORING,
662 gettext_noop("Writes cumulative performance statistics to the server log."),
665 &log_statement_stats,
666 false, assign_log_stats, NULL
668 #ifdef BTREE_BUILD_STATS
670 {"log_btree_build_stats", PGC_SUSET, DEVELOPER_OPTIONS,
671 gettext_noop("no description available"),
675 &log_btree_build_stats,
681 {"explain_pretty_print", PGC_USERSET, CLIENT_CONN_OTHER,
682 gettext_noop("Uses the indented output format for EXPLAIN VERBOSE."),
685 &Explain_pretty_print,
689 {"stats_start_collector", PGC_POSTMASTER, STATS_COLLECTOR,
690 gettext_noop("Starts the server statistics-collection subprocess."),
693 &pgstat_collect_startcollector,
697 {"stats_reset_on_server_start", PGC_POSTMASTER, STATS_COLLECTOR,
698 gettext_noop("Zeroes collected statistics on server restart."),
701 &pgstat_collect_resetonpmstart,
705 {"stats_row_level", PGC_SUSET, STATS_COLLECTOR,
706 gettext_noop("Collects row-level statistics on database activity."),
709 &pgstat_collect_tuplelevel,
713 {"stats_block_level", PGC_SUSET, STATS_COLLECTOR,
714 gettext_noop("Collects block-level statistics on database activity."),
717 &pgstat_collect_blocklevel,
722 {"stats_command_string", PGC_SUSET, STATS_COLLECTOR,
723 gettext_noop("Collects information about executing commands."),
724 gettext_noop("Enables the collection of information on the currently "
725 "executing command of each session, along with the time "
726 "at which that command began execution.")
728 &pgstat_collect_querystring,
733 {"update_process_title", PGC_SUSET, STATS_COLLECTOR,
734 gettext_noop("Updates the process title to show the active SQL command."),
735 gettext_noop("Enables updating of the process title every time a new SQL command is received by the server.")
737 &update_process_title,
742 {"autovacuum", PGC_SIGHUP, AUTOVACUUM,
743 gettext_noop("Starts the autovacuum subprocess."),
746 &autovacuum_start_daemon,
751 {"trace_notify", PGC_USERSET, DEVELOPER_OPTIONS,
752 gettext_noop("Generates debugging output for LISTEN and NOTIFY."),
762 {"trace_locks", PGC_SUSET, DEVELOPER_OPTIONS,
763 gettext_noop("no description available"),
771 {"trace_userlocks", PGC_SUSET, DEVELOPER_OPTIONS,
772 gettext_noop("no description available"),
780 {"trace_lwlocks", PGC_SUSET, DEVELOPER_OPTIONS,
781 gettext_noop("no description available"),
789 {"debug_deadlocks", PGC_SUSET, DEVELOPER_OPTIONS,
790 gettext_noop("no description available"),
800 {"log_hostname", PGC_SIGHUP, LOGGING_WHAT,
801 gettext_noop("Logs the host name in the connection logs."),
802 gettext_noop("By default, connection logs only show the IP address "
803 "of the connecting host. If you want them to show the host name you "
804 "can turn this on, but depending on your host name resolution "
805 "setup it might impose a non-negligible performance penalty.")
811 {"sql_inheritance", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
812 gettext_noop("Causes subtables to be included by default in various commands."),
819 {"password_encryption", PGC_USERSET, CONN_AUTH_SECURITY,
820 gettext_noop("Encrypt passwords."),
821 gettext_noop("When a password is specified in CREATE USER or "
822 "ALTER USER without writing either ENCRYPTED or UNENCRYPTED, "
823 "this parameter determines whether the password is to be encrypted.")
825 &Password_encryption,
829 {"transform_null_equals", PGC_USERSET, COMPAT_OPTIONS_CLIENT,
830 gettext_noop("Treats \"expr=NULL\" as \"expr IS NULL\"."),
831 gettext_noop("When turned on, expressions of the form expr = NULL "
832 "(or NULL = expr) are treated as expr IS NULL, that is, they "
833 "return true if expr evaluates to the null value, and false "
834 "otherwise. The correct behavior of expr = NULL is to always "
835 "return null (unknown).")
837 &Transform_null_equals,
841 {"db_user_namespace", PGC_SIGHUP, CONN_AUTH_SECURITY,
842 gettext_noop("Enables per-database user names."),
849 /* only here for backwards compatibility */
850 {"autocommit", PGC_USERSET, CLIENT_CONN_STATEMENT,
851 gettext_noop("This parameter doesn't do anything."),
852 gettext_noop("It's just here so that we won't choke on SET AUTOCOMMIT TO ON from 7.3-vintage clients."),
853 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
856 true, assign_phony_autocommit, NULL
859 {"default_transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
860 gettext_noop("Sets the default read-only status of new transactions."),
863 &DefaultXactReadOnly,
867 {"transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
868 gettext_noop("Sets the current transaction's read-only status."),
870 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
873 false, assign_transaction_read_only, NULL
876 {"add_missing_from", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
877 gettext_noop("Automatically adds missing table references to FROM clauses."),
884 {"check_function_bodies", PGC_USERSET, CLIENT_CONN_STATEMENT,
885 gettext_noop("Check function bodies during CREATE FUNCTION."),
888 &check_function_bodies,
892 {"array_nulls", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
893 gettext_noop("Enable input of NULL elements in arrays."),
894 gettext_noop("When turned on, unquoted NULL in an array input "
895 "value means a NULL value; "
896 "otherwise it is taken literally.")
902 {"default_with_oids", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
903 gettext_noop("Create new tables with OIDs by default."),
910 {"redirect_stderr", PGC_POSTMASTER, LOGGING_WHERE,
911 gettext_noop("Start a subprocess to capture stderr output into log files."),
918 {"log_truncate_on_rotation", PGC_SIGHUP, LOGGING_WHERE,
919 gettext_noop("Truncate existing log files of same name during log rotation."),
922 &Log_truncate_on_rotation,
928 {"trace_sort", PGC_USERSET, DEVELOPER_OPTIONS,
929 gettext_noop("Emit information about resource usage in sorting."),
940 {"wal_debug", PGC_SUSET, DEVELOPER_OPTIONS,
941 gettext_noop("Emit WAL-related debugging output."),
951 {"integer_datetimes", PGC_INTERNAL, PRESET_OPTIONS,
952 gettext_noop("Datetimes are integer based."),
954 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
957 #ifdef HAVE_INT64_TIMESTAMP
965 {"krb_caseins_users", PGC_POSTMASTER, CONN_AUTH_SECURITY,
966 gettext_noop("Sets whether Kerberos user names should be treated as case-insensitive."),
969 &pg_krb_caseins_users,
974 {"escape_string_warning", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
975 gettext_noop("Warn about backslash escapes in ordinary string literals."),
978 &escape_string_warning,
983 {"standard_conforming_strings", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
984 gettext_noop("'...' strings treat backslashes literally."),
988 &standard_conforming_strings,
993 {"allow_system_table_mods", PGC_POSTMASTER, DEVELOPER_OPTIONS,
994 gettext_noop("Allows modifications of the structure of system tables."),
998 &allowSystemTableMods,
1003 {"ignore_system_indexes", PGC_BACKEND, DEVELOPER_OPTIONS,
1004 gettext_noop("Disabled reading from system indexes."),
1005 gettext_noop("It does not prevent updating the indexes, so it is safe "
1006 "to use. The worst consequence is slowness."),
1009 &IgnoreSystemIndexes,
1013 /* End-of-list marker */
1015 {NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL
1020 static struct config_int ConfigureNamesInt[] =
1023 {"post_auth_delay", PGC_BACKEND, DEVELOPER_OPTIONS,
1024 gettext_noop("Waits N seconds on connection startup after authentication."),
1025 gettext_noop("This allows attaching a debugger to the process."),
1026 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1029 0, 0, INT_MAX, NULL, NULL
1032 {"default_statistics_target", PGC_USERSET, QUERY_TUNING_OTHER,
1033 gettext_noop("Sets the default statistics target."),
1034 gettext_noop("This applies to table columns that have not had a "
1035 "column-specific target set via ALTER TABLE SET STATISTICS.")
1037 &default_statistics_target,
1038 10, 1, 1000, NULL, NULL
1041 {"from_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1042 gettext_noop("Sets the FROM-list size beyond which subqueries are not "
1044 gettext_noop("The planner will merge subqueries into upper "
1045 "queries if the resulting FROM list would have no more than "
1048 &from_collapse_limit,
1049 8, 1, INT_MAX, NULL, NULL
1052 {"join_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1053 gettext_noop("Sets the FROM-list size beyond which JOIN constructs are not "
1055 gettext_noop("The planner will flatten explicit JOIN "
1056 "constructs into lists of FROM items whenever a list of no more "
1057 "than this many items would result.")
1059 &join_collapse_limit,
1060 8, 1, INT_MAX, NULL, NULL
1063 {"geqo_threshold", PGC_USERSET, QUERY_TUNING_GEQO,
1064 gettext_noop("Sets the threshold of FROM items beyond which GEQO is used."),
1068 12, 2, INT_MAX, NULL, NULL
1071 {"geqo_effort", PGC_USERSET, QUERY_TUNING_GEQO,
1072 gettext_noop("GEQO: effort is used to set the default for other GEQO parameters."),
1076 DEFAULT_GEQO_EFFORT, MIN_GEQO_EFFORT, MAX_GEQO_EFFORT, NULL, NULL
1079 {"geqo_pool_size", PGC_USERSET, QUERY_TUNING_GEQO,
1080 gettext_noop("GEQO: number of individuals in the population."),
1081 gettext_noop("Zero selects a suitable default value.")
1084 0, 0, INT_MAX, NULL, NULL
1087 {"geqo_generations", PGC_USERSET, QUERY_TUNING_GEQO,
1088 gettext_noop("GEQO: number of iterations of the algorithm."),
1089 gettext_noop("Zero selects a suitable default value.")
1092 0, 0, INT_MAX, NULL, NULL
1096 {"deadlock_timeout", PGC_SIGHUP, LOCK_MANAGEMENT,
1097 gettext_noop("The time in milliseconds to wait on lock before checking for deadlock."),
1102 1000, 0, INT_MAX, NULL, NULL
1106 * Note: There is some postprocessing done in PostmasterMain() to make
1107 * sure the buffers are at least twice the number of backends, so the
1108 * constraints here are partially unused. Similarly, the superuser
1109 * reserved number is checked to ensure it is less than the max backends
1112 * MaxBackends is limited to INT_MAX/4 because some places compute
1113 * 4*MaxBackends without any overflow check. Likewise we have to limit
1114 * NBuffers to INT_MAX/2.
1117 {"max_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1118 gettext_noop("Sets the maximum number of concurrent connections."),
1122 100, 1, INT_MAX / 4, NULL, NULL
1126 {"superuser_reserved_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1127 gettext_noop("Sets the number of connection slots reserved for superusers."),
1131 2, 0, INT_MAX / 4, NULL, NULL
1135 {"shared_buffers", PGC_POSTMASTER, RESOURCES_MEM,
1136 gettext_noop("Sets the number of shared memory buffers used by the server."),
1141 1000, 16, INT_MAX / 2, NULL, NULL
1145 {"temp_buffers", PGC_USERSET, RESOURCES_MEM,
1146 gettext_noop("Sets the maximum number of temporary buffers used by each session."),
1151 1000, 100, INT_MAX / 2, NULL, show_num_temp_buffers
1155 {"port", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1156 gettext_noop("Sets the TCP port the server listens on."),
1160 DEF_PGPORT, 1, 65535, NULL, NULL
1164 {"unix_socket_permissions", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1165 gettext_noop("Sets the access permissions of the Unix-domain socket."),
1166 gettext_noop("Unix-domain sockets use the usual Unix file system "
1167 "permission set. The parameter value is expected to be an numeric mode "
1168 "specification in the form accepted by the chmod and umask system "
1169 "calls. (To use the customary octal format the number must start with "
1172 &Unix_socket_permissions,
1173 0777, 0000, 0777, NULL, NULL
1177 {"work_mem", PGC_USERSET, RESOURCES_MEM,
1178 gettext_noop("Sets the maximum memory to be used for query workspaces."),
1179 gettext_noop("This much memory may be used by each internal "
1180 "sort operation and hash table before switching to "
1181 "temporary disk files."),
1185 1024, 8 * BLCKSZ / 1024, MAX_KILOBYTES, NULL, NULL
1189 {"maintenance_work_mem", PGC_USERSET, RESOURCES_MEM,
1190 gettext_noop("Sets the maximum memory to be used for maintenance operations."),
1191 gettext_noop("This includes operations such as VACUUM and CREATE INDEX."),
1194 &maintenance_work_mem,
1195 16384, 1024, MAX_KILOBYTES, NULL, NULL
1199 {"max_stack_depth", PGC_SUSET, RESOURCES_MEM,
1200 gettext_noop("Sets the maximum stack depth, in kilobytes."),
1205 2048, 100, MAX_KILOBYTES, assign_max_stack_depth, NULL
1209 {"vacuum_cost_page_hit", PGC_USERSET, RESOURCES,
1210 gettext_noop("Vacuum cost for a page found in the buffer cache."),
1214 1, 0, 10000, NULL, NULL
1218 {"vacuum_cost_page_miss", PGC_USERSET, RESOURCES,
1219 gettext_noop("Vacuum cost for a page not found in the buffer cache."),
1222 &VacuumCostPageMiss,
1223 10, 0, 10000, NULL, NULL
1227 {"vacuum_cost_page_dirty", PGC_USERSET, RESOURCES,
1228 gettext_noop("Vacuum cost for a page dirtied by vacuum."),
1231 &VacuumCostPageDirty,
1232 20, 0, 10000, NULL, NULL
1236 {"vacuum_cost_limit", PGC_USERSET, RESOURCES,
1237 gettext_noop("Vacuum cost amount available before napping."),
1241 200, 1, 10000, NULL, NULL
1245 {"vacuum_cost_delay", PGC_USERSET, RESOURCES,
1246 gettext_noop("Vacuum cost delay in milliseconds."),
1251 0, 0, 1000, NULL, NULL
1255 {"autovacuum_vacuum_cost_delay", PGC_SIGHUP, AUTOVACUUM,
1256 gettext_noop("Vacuum cost delay in milliseconds, for autovacuum."),
1260 &autovacuum_vac_cost_delay,
1261 -1, -1, 1000, NULL, NULL
1265 {"autovacuum_vacuum_cost_limit", PGC_SIGHUP, AUTOVACUUM,
1266 gettext_noop("Vacuum cost amount available before napping, for autovacuum."),
1269 &autovacuum_vac_cost_limit,
1270 -1, -1, 10000, NULL, NULL
1274 {"max_files_per_process", PGC_POSTMASTER, RESOURCES_KERNEL,
1275 gettext_noop("Sets the maximum number of simultaneously open files for each server process."),
1278 &max_files_per_process,
1279 1000, 25, INT_MAX, NULL, NULL
1283 {"max_prepared_transactions", PGC_POSTMASTER, RESOURCES,
1284 gettext_noop("Sets the maximum number of simultaneously prepared transactions."),
1287 &max_prepared_xacts,
1288 5, 0, INT_MAX, NULL, NULL
1293 {"trace_lock_oidmin", PGC_SUSET, DEVELOPER_OPTIONS,
1294 gettext_noop("no description available"),
1299 FirstNormalObjectId, 0, INT_MAX, NULL, NULL
1302 {"trace_lock_table", PGC_SUSET, DEVELOPER_OPTIONS,
1303 gettext_noop("no description available"),
1308 0, 0, INT_MAX, NULL, NULL
1313 {"statement_timeout", PGC_USERSET, CLIENT_CONN_STATEMENT,
1314 gettext_noop("Sets the maximum allowed duration (in milliseconds) of any statement."),
1315 gettext_noop("A value of 0 turns off the timeout."),
1319 0, 0, INT_MAX, NULL, NULL
1323 {"max_fsm_relations", PGC_POSTMASTER, RESOURCES_FSM,
1324 gettext_noop("Sets the maximum number of tables and indexes for which free space is tracked."),
1328 1000, 100, INT_MAX, NULL, NULL
1331 {"max_fsm_pages", PGC_POSTMASTER, RESOURCES_FSM,
1332 gettext_noop("Sets the maximum number of disk pages for which free space is tracked."),
1336 20000, 1000, INT_MAX, NULL, NULL
1340 {"max_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
1341 gettext_noop("Sets the maximum number of locks per transaction."),
1342 gettext_noop("The shared lock table is sized on the assumption that "
1343 "at most max_locks_per_transaction * max_connections distinct "
1344 "objects will need to be locked at any one time.")
1346 &max_locks_per_xact,
1347 64, 10, INT_MAX, NULL, NULL
1351 {"authentication_timeout", PGC_SIGHUP, CONN_AUTH_SECURITY,
1352 gettext_noop("Sets the maximum time in seconds to complete client authentication."),
1356 &AuthenticationTimeout,
1357 60, 1, 600, NULL, NULL
1361 /* Not for general use */
1362 {"pre_auth_delay", PGC_SIGHUP, DEVELOPER_OPTIONS,
1363 gettext_noop("no description available"),
1365 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1368 0, 0, 60, NULL, NULL
1372 {"checkpoint_segments", PGC_SIGHUP, WAL_CHECKPOINTS,
1373 gettext_noop("Sets the maximum distance in log segments between automatic WAL checkpoints."),
1376 &CheckPointSegments,
1377 3, 1, INT_MAX, NULL, NULL
1381 {"checkpoint_timeout", PGC_SIGHUP, WAL_CHECKPOINTS,
1382 gettext_noop("Sets the maximum time in seconds between automatic WAL checkpoints."),
1387 300, 30, 3600, NULL, NULL
1391 {"checkpoint_warning", PGC_SIGHUP, WAL_CHECKPOINTS,
1392 gettext_noop("Logs if filling of checkpoint segments happens more "
1393 "frequently than this (in seconds)."),
1394 gettext_noop("Write a message to the server log if checkpoints "
1395 "caused by the filling of checkpoint segment files happens more "
1396 "frequently than this number of seconds. Zero turns off the warning.")
1399 30, 0, INT_MAX, NULL, NULL
1403 {"wal_buffers", PGC_POSTMASTER, WAL_SETTINGS,
1404 gettext_noop("Sets the number of disk-page buffers in shared memory for WAL."),
1408 8, 4, INT_MAX, NULL, NULL
1412 {"commit_delay", PGC_USERSET, WAL_CHECKPOINTS,
1413 gettext_noop("Sets the delay in microseconds between transaction commit and "
1414 "flushing WAL to disk."),
1418 0, 0, 100000, NULL, NULL
1422 {"commit_siblings", PGC_USERSET, WAL_CHECKPOINTS,
1423 gettext_noop("Sets the minimum concurrent open transactions before performing "
1428 5, 1, 1000, NULL, NULL
1432 {"extra_float_digits", PGC_USERSET, CLIENT_CONN_LOCALE,
1433 gettext_noop("Sets the number of digits displayed for floating-point values."),
1434 gettext_noop("This affects real, double precision, and geometric data types. "
1435 "The parameter value is added to the standard number of digits "
1436 "(FLT_DIG or DBL_DIG as appropriate).")
1438 &extra_float_digits,
1439 0, -15, 2, NULL, NULL
1443 {"log_min_duration_statement", PGC_SUSET, LOGGING_WHEN,
1444 gettext_noop("Sets the minimum execution time in milliseconds above which statements will "
1446 gettext_noop("Zero prints all queries. The default is -1 (turning this feature off)."),
1449 &log_min_duration_statement,
1450 -1, -1, INT_MAX / 1000, NULL, NULL
1454 {"bgwriter_delay", PGC_SIGHUP, RESOURCES,
1455 gettext_noop("Background writer sleep time between rounds in milliseconds"),
1460 200, 10, 10000, NULL, NULL
1464 {"bgwriter_lru_maxpages", PGC_SIGHUP, RESOURCES,
1465 gettext_noop("Background writer maximum number of LRU pages to flush per round"),
1468 &bgwriter_lru_maxpages,
1469 5, 0, 1000, NULL, NULL
1473 {"bgwriter_all_maxpages", PGC_SIGHUP, RESOURCES,
1474 gettext_noop("Background writer maximum number of all pages to flush per round"),
1477 &bgwriter_all_maxpages,
1478 5, 0, 1000, NULL, NULL
1482 {"log_rotation_age", PGC_SIGHUP, LOGGING_WHERE,
1483 gettext_noop("Automatic log file rotation will occur after N minutes"),
1488 HOURS_PER_DAY * MINS_PER_HOUR, 0, INT_MAX / MINS_PER_HOUR, NULL, NULL
1492 {"log_rotation_size", PGC_SIGHUP, LOGGING_WHERE,
1493 gettext_noop("Automatic log file rotation will occur after N kilobytes"),
1498 10 * 1024, 0, INT_MAX / 1024, NULL, NULL
1502 {"max_function_args", PGC_INTERNAL, PRESET_OPTIONS,
1503 gettext_noop("Shows the maximum number of function arguments."),
1505 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1508 FUNC_MAX_ARGS, FUNC_MAX_ARGS, FUNC_MAX_ARGS, NULL, NULL
1512 {"max_index_keys", PGC_INTERNAL, PRESET_OPTIONS,
1513 gettext_noop("Shows the maximum number of index keys."),
1515 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1518 INDEX_MAX_KEYS, INDEX_MAX_KEYS, INDEX_MAX_KEYS, NULL, NULL
1522 {"max_identifier_length", PGC_INTERNAL, PRESET_OPTIONS,
1523 gettext_noop("Shows the maximum identifier length"),
1525 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1527 &max_identifier_length,
1528 NAMEDATALEN - 1, NAMEDATALEN - 1, NAMEDATALEN - 1, NULL, NULL
1532 {"block_size", PGC_INTERNAL, PRESET_OPTIONS,
1533 gettext_noop("Shows size of a disk block"),
1535 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1538 BLCKSZ, BLCKSZ, BLCKSZ, NULL, NULL
1542 {"autovacuum_naptime", PGC_SIGHUP, AUTOVACUUM,
1543 gettext_noop("Time to sleep between autovacuum runs, in seconds."),
1547 &autovacuum_naptime,
1548 60, 1, INT_MAX, NULL, NULL
1551 {"autovacuum_vacuum_threshold", PGC_SIGHUP, AUTOVACUUM,
1552 gettext_noop("Minimum number of tuple updates or deletes prior to vacuum."),
1555 &autovacuum_vac_thresh,
1556 1000, 0, INT_MAX, NULL, NULL
1559 {"autovacuum_analyze_threshold", PGC_SIGHUP, AUTOVACUUM,
1560 gettext_noop("Minimum number of tuple inserts, updates or deletes prior to analyze."),
1563 &autovacuum_anl_thresh,
1564 500, 0, INT_MAX, NULL, NULL
1568 {"tcp_keepalives_idle", PGC_USERSET, CLIENT_CONN_OTHER,
1569 gettext_noop("Seconds between issuing TCP keepalives."),
1570 gettext_noop("A value of 0 uses the system default."),
1573 &tcp_keepalives_idle,
1574 0, 0, INT_MAX, assign_tcp_keepalives_idle, show_tcp_keepalives_idle
1578 {"tcp_keepalives_interval", PGC_USERSET, CLIENT_CONN_OTHER,
1579 gettext_noop("Seconds between TCP keepalive retransmits."),
1580 gettext_noop("A value of 0 uses the system default."),
1583 &tcp_keepalives_interval,
1584 0, 0, INT_MAX, assign_tcp_keepalives_interval, show_tcp_keepalives_interval
1588 {"tcp_keepalives_count", PGC_USERSET, CLIENT_CONN_OTHER,
1589 gettext_noop("Maximum number of TCP keepalive retransmits."),
1590 gettext_noop("This controls the number of consecutive keepalive retransmits that can be "
1591 "lost before a connection is considered dead. A value of 0 uses the "
1594 &tcp_keepalives_count,
1595 0, 0, INT_MAX, assign_tcp_keepalives_count, show_tcp_keepalives_count
1599 {"gin_fuzzy_search_limit", PGC_USERSET, UNGROUPED,
1600 gettext_noop("Sets the maximum allowed result for exact search by gin."),
1604 &GinFuzzySearchLimit,
1605 0, 0, INT_MAX, NULL, NULL
1609 {"effective_cache_size", PGC_USERSET, QUERY_TUNING_COST,
1610 gettext_noop("Sets the planner's assumption about size of the disk cache."),
1611 gettext_noop("That is, the portion of the kernel's disk cache that "
1612 "will be used for PostgreSQL data files. This is measured in disk "
1613 "pages, which are normally 8 kB each."),
1616 &effective_cache_size,
1617 DEFAULT_EFFECTIVE_CACHE_SIZE, 1, INT_MAX, NULL, NULL
1620 /* End-of-list marker */
1622 {NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL
1627 static struct config_real ConfigureNamesReal[] =
1630 {"seq_page_cost", PGC_USERSET, QUERY_TUNING_COST,
1631 gettext_noop("Sets the planner's estimate of the cost of a "
1632 "sequentially fetched disk page."),
1636 DEFAULT_SEQ_PAGE_COST, 0, DBL_MAX, NULL, NULL
1639 {"random_page_cost", PGC_USERSET, QUERY_TUNING_COST,
1640 gettext_noop("Sets the planner's estimate of the cost of a "
1641 "nonsequentially fetched disk page."),
1645 DEFAULT_RANDOM_PAGE_COST, 0, DBL_MAX, NULL, NULL
1648 {"cpu_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
1649 gettext_noop("Sets the planner's estimate of the cost of "
1650 "processing each tuple (row)."),
1654 DEFAULT_CPU_TUPLE_COST, 0, DBL_MAX, NULL, NULL
1657 {"cpu_index_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
1658 gettext_noop("Sets the planner's estimate of the cost of "
1659 "processing each index entry during an index scan."),
1662 &cpu_index_tuple_cost,
1663 DEFAULT_CPU_INDEX_TUPLE_COST, 0, DBL_MAX, NULL, NULL
1666 {"cpu_operator_cost", PGC_USERSET, QUERY_TUNING_COST,
1667 gettext_noop("Sets the planner's estimate of the cost of "
1668 "processing each operator or function call."),
1672 DEFAULT_CPU_OPERATOR_COST, 0, DBL_MAX, NULL, NULL
1676 {"geqo_selection_bias", PGC_USERSET, QUERY_TUNING_GEQO,
1677 gettext_noop("GEQO: selective pressure within the population."),
1680 &Geqo_selection_bias,
1681 DEFAULT_GEQO_SELECTION_BIAS, MIN_GEQO_SELECTION_BIAS,
1682 MAX_GEQO_SELECTION_BIAS, NULL, NULL
1686 {"bgwriter_lru_percent", PGC_SIGHUP, RESOURCES,
1687 gettext_noop("Background writer percentage of LRU buffers to flush per round"),
1690 &bgwriter_lru_percent,
1691 1.0, 0.0, 100.0, NULL, NULL
1695 {"bgwriter_all_percent", PGC_SIGHUP, RESOURCES,
1696 gettext_noop("Background writer percentage of all buffers to flush per round"),
1699 &bgwriter_all_percent,
1700 0.333, 0.0, 100.0, NULL, NULL
1704 {"seed", PGC_USERSET, UNGROUPED,
1705 gettext_noop("Sets the seed for random-number generation."),
1707 GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1710 0.5, 0.0, 1.0, assign_random_seed, show_random_seed
1714 {"autovacuum_vacuum_scale_factor", PGC_SIGHUP, AUTOVACUUM,
1715 gettext_noop("Number of tuple updates or deletes prior to vacuum as a fraction of reltuples."),
1718 &autovacuum_vac_scale,
1719 0.4, 0.0, 100.0, NULL, NULL
1722 {"autovacuum_analyze_scale_factor", PGC_SIGHUP, AUTOVACUUM,
1723 gettext_noop("Number of tuple inserts, updates or deletes prior to analyze as a fraction of reltuples."),
1726 &autovacuum_anl_scale,
1727 0.2, 0.0, 100.0, NULL, NULL
1730 /* End-of-list marker */
1732 {NULL, 0, 0, NULL, NULL}, NULL, 0.0, 0.0, 0.0, NULL, NULL
1737 static struct config_string ConfigureNamesString[] =
1740 {"archive_command", PGC_SIGHUP, WAL_SETTINGS,
1741 gettext_noop("WAL archiving command."),
1742 gettext_noop("The shell command that will be called to archive a WAL file.")
1744 &XLogArchiveCommand,
1749 {"backslash_quote", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1750 gettext_noop("Sets whether \"\\'\" is allowed in string literals."),
1751 gettext_noop("Valid values are ON, OFF, and SAFE_ENCODING.")
1753 &backslash_quote_string,
1754 "safe_encoding", assign_backslash_quote, NULL
1758 {"client_encoding", PGC_USERSET, CLIENT_CONN_LOCALE,
1759 gettext_noop("Sets the client's character set encoding."),
1761 GUC_IS_NAME | GUC_REPORT
1763 &client_encoding_string,
1764 "SQL_ASCII", assign_client_encoding, NULL
1768 {"client_min_messages", PGC_USERSET, LOGGING_WHEN,
1769 gettext_noop("Sets the message levels that are sent to the client."),
1770 gettext_noop("Valid values are DEBUG5, DEBUG4, DEBUG3, DEBUG2, "
1771 "DEBUG1, LOG, NOTICE, WARNING, and ERROR. Each level includes all the "
1772 "levels that follow it. The later the level, the fewer messages are "
1775 &client_min_messages_str,
1776 "notice", assign_client_min_messages, NULL
1780 {"log_min_messages", PGC_SUSET, LOGGING_WHEN,
1781 gettext_noop("Sets the message levels that are logged."),
1782 gettext_noop("Valid values are DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1, "
1783 "INFO, NOTICE, WARNING, ERROR, LOG, FATAL, and PANIC. Each level "
1784 "includes all the levels that follow it.")
1786 &log_min_messages_str,
1787 "notice", assign_log_min_messages, NULL
1791 {"log_error_verbosity", PGC_SUSET, LOGGING_WHEN,
1792 gettext_noop("Sets the verbosity of logged messages."),
1793 gettext_noop("Valid values are \"terse\", \"default\", and \"verbose\".")
1795 &log_error_verbosity_str,
1796 "default", assign_log_error_verbosity, NULL
1799 {"log_statement", PGC_SUSET, LOGGING_WHAT,
1800 gettext_noop("Sets the type of statements logged."),
1801 gettext_noop("Valid values are \"none\", \"ddl\", \"mod\", and \"all\".")
1804 "none", assign_log_statement, NULL
1808 {"log_min_error_statement", PGC_SUSET, LOGGING_WHEN,
1809 gettext_noop("Causes all statements generating error at or above this level to be logged."),
1810 gettext_noop("All SQL statements that cause an error of the "
1811 "specified level or a higher level are logged.")
1813 &log_min_error_statement_str,
1814 "panic", assign_min_error_statement, NULL
1818 {"log_line_prefix", PGC_SIGHUP, LOGGING_WHAT,
1819 gettext_noop("Controls information prefixed to each log line"),
1820 gettext_noop("if blank no prefix is used")
1828 {"DateStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
1829 gettext_noop("Sets the display format for date and time values."),
1830 gettext_noop("Also controls interpretation of ambiguous "
1832 GUC_LIST_INPUT | GUC_REPORT
1835 "ISO, MDY", assign_datestyle, NULL
1839 {"default_tablespace", PGC_USERSET, CLIENT_CONN_STATEMENT,
1840 gettext_noop("Sets the default tablespace to create tables and indexes in."),
1841 gettext_noop("An empty string selects the database's default tablespace."),
1844 &default_tablespace,
1845 "", assign_default_tablespace, NULL
1849 {"default_transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
1850 gettext_noop("Sets the transaction isolation level of each new transaction."),
1851 gettext_noop("Each SQL transaction has an isolation level, which "
1852 "can be either \"read uncommitted\", \"read committed\", \"repeatable read\", or \"serializable\".")
1854 &default_iso_level_string,
1855 "read committed", assign_defaultxactisolevel, NULL
1859 {"dynamic_library_path", PGC_SUSET, CLIENT_CONN_OTHER,
1860 gettext_noop("Sets the path for dynamically loadable modules."),
1861 gettext_noop("If a dynamically loadable module needs to be opened and "
1862 "the specified name does not have a directory component (i.e., the "
1863 "name does not contain a slash), the system will search this path for "
1864 "the specified file."),
1867 &Dynamic_library_path,
1868 "$libdir", NULL, NULL
1872 {"krb_server_keyfile", PGC_POSTMASTER, CONN_AUTH_SECURITY,
1873 gettext_noop("Sets the location of the Kerberos server key file."),
1877 &pg_krb_server_keyfile,
1878 PG_KRB_SRVTAB, NULL, NULL
1882 {"krb_srvname", PGC_POSTMASTER, CONN_AUTH_SECURITY,
1883 gettext_noop("Sets the name of the Kerberos service."),
1887 PG_KRB_SRVNAM, NULL, NULL
1891 {"krb_server_hostname", PGC_POSTMASTER, CONN_AUTH_SECURITY,
1892 gettext_noop("Sets the hostname of the Kerberos server."),
1895 &pg_krb_server_hostname,
1900 {"bonjour_name", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1901 gettext_noop("Sets the Bonjour broadcast service name."),
1908 /* See main.c about why defaults for LC_foo are not all alike */
1911 {"lc_collate", PGC_INTERNAL, CLIENT_CONN_LOCALE,
1912 gettext_noop("Shows the collation order locale."),
1914 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1921 {"lc_ctype", PGC_INTERNAL, CLIENT_CONN_LOCALE,
1922 gettext_noop("Shows the character classification and case conversion locale."),
1924 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1931 {"lc_messages", PGC_SUSET, CLIENT_CONN_LOCALE,
1932 gettext_noop("Sets the language in which messages are displayed."),
1936 "", locale_messages_assign, NULL
1940 {"lc_monetary", PGC_USERSET, CLIENT_CONN_LOCALE,
1941 gettext_noop("Sets the locale for formatting monetary amounts."),
1945 "C", locale_monetary_assign, NULL
1949 {"lc_numeric", PGC_USERSET, CLIENT_CONN_LOCALE,
1950 gettext_noop("Sets the locale for formatting numbers."),
1954 "C", locale_numeric_assign, NULL
1958 {"lc_time", PGC_USERSET, CLIENT_CONN_LOCALE,
1959 gettext_noop("Sets the locale for formatting date and time values."),
1963 "C", locale_time_assign, NULL
1967 {"preload_libraries", PGC_POSTMASTER, RESOURCES_KERNEL,
1968 gettext_noop("Lists shared libraries to preload into server."),
1970 GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
1972 &preload_libraries_string,
1977 {"regex_flavor", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1978 gettext_noop("Sets the regular expression \"flavor\"."),
1979 gettext_noop("This can be set to advanced, extended, or basic.")
1981 ®ex_flavor_string,
1982 "advanced", assign_regex_flavor, NULL
1986 {"search_path", PGC_USERSET, CLIENT_CONN_STATEMENT,
1987 gettext_noop("Sets the schema search order for names that are not schema-qualified."),
1989 GUC_LIST_INPUT | GUC_LIST_QUOTE
1991 &namespace_search_path,
1992 "\"$user\",public", assign_search_path, NULL
1996 /* Can't be set in postgresql.conf */
1997 {"server_encoding", PGC_INTERNAL, CLIENT_CONN_LOCALE,
1998 gettext_noop("Sets the server (database) character set encoding."),
2000 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2002 &server_encoding_string,
2003 "SQL_ASCII", NULL, NULL
2007 /* Can't be set in postgresql.conf */
2008 {"server_version", PGC_INTERNAL, PRESET_OPTIONS,
2009 gettext_noop("Shows the server version."),
2011 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2013 &server_version_string,
2014 PG_VERSION, NULL, NULL
2018 /* Not for general use --- used by SET ROLE */
2019 {"role", PGC_USERSET, UNGROUPED,
2020 gettext_noop("Sets the current role."),
2022 GUC_IS_NAME | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2025 "none", assign_role, show_role
2029 /* Not for general use --- used by SET SESSION AUTHORIZATION */
2030 {"session_authorization", PGC_USERSET, UNGROUPED,
2031 gettext_noop("Sets the session user name."),
2033 GUC_IS_NAME | GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2035 &session_authorization_string,
2036 NULL, assign_session_authorization, show_session_authorization
2040 {"log_destination", PGC_SIGHUP, LOGGING_WHERE,
2041 gettext_noop("Sets the destination for server log output."),
2042 gettext_noop("Valid values are combinations of \"stderr\", \"syslog\", "
2043 "and \"eventlog\", depending on the platform."),
2046 &log_destination_string,
2047 "stderr", assign_log_destination, NULL
2050 {"log_directory", PGC_SIGHUP, LOGGING_WHERE,
2051 gettext_noop("Sets the destination directory for log files."),
2052 gettext_noop("May be specified as relative to the data directory "
2053 "or as absolute path."),
2057 "pg_log", assign_canonical_path, NULL
2060 {"log_filename", PGC_SIGHUP, LOGGING_WHERE,
2061 gettext_noop("Sets the file name pattern for log files."),
2066 "postgresql-%Y-%m-%d_%H%M%S.log", NULL, NULL
2071 {"syslog_facility", PGC_SIGHUP, LOGGING_WHERE,
2072 gettext_noop("Sets the syslog \"facility\" to be used when syslog enabled."),
2073 gettext_noop("Valid values are LOCAL0, LOCAL1, LOCAL2, LOCAL3, "
2074 "LOCAL4, LOCAL5, LOCAL6, LOCAL7.")
2076 &syslog_facility_str,
2077 "LOCAL0", assign_syslog_facility, NULL
2080 {"syslog_ident", PGC_SIGHUP, LOGGING_WHERE,
2081 gettext_noop("Sets the program name used to identify PostgreSQL "
2082 "messages in syslog."),
2086 "postgres", assign_syslog_ident, NULL
2091 {"TimeZone", PGC_USERSET, CLIENT_CONN_LOCALE,
2092 gettext_noop("Sets the time zone for displaying and interpreting time stamps."),
2097 "UNKNOWN", assign_timezone, show_timezone
2100 {"timezone_abbreviations", PGC_USERSET, CLIENT_CONN_LOCALE,
2101 gettext_noop("Selects a file of timezone abbreviations"),
2104 &timezone_abbreviations,
2105 "Default", assign_timezone_abbreviations, NULL
2109 {"transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
2110 gettext_noop("Sets the current transaction's isolation level."),
2112 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2114 &XactIsoLevel_string,
2115 NULL, assign_XactIsoLevel, show_XactIsoLevel
2119 {"unix_socket_group", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2120 gettext_noop("Sets the owning group of the Unix-domain socket."),
2121 gettext_noop("(The owning user of the socket is always the user "
2122 "that starts the server.)")
2129 {"unix_socket_directory", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2130 gettext_noop("Sets the directory where the Unix-domain socket will be created."),
2135 "", assign_canonical_path, NULL
2139 {"listen_addresses", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2140 gettext_noop("Sets the host name or IP address(es) to listen to."),
2145 "localhost", NULL, NULL
2149 {"wal_sync_method", PGC_SIGHUP, WAL_SETTINGS,
2150 gettext_noop("Selects the method used for forcing WAL updates out to disk."),
2154 XLOG_sync_method_default, assign_xlog_sync_method, NULL
2158 {"custom_variable_classes", PGC_SIGHUP, CUSTOM_OPTIONS,
2159 gettext_noop("Sets the list of known custom variable classes."),
2161 GUC_LIST_INPUT | GUC_LIST_QUOTE
2163 &custom_variable_classes,
2164 NULL, assign_custom_variable_classes, NULL
2168 {"data_directory", PGC_POSTMASTER, FILE_LOCATIONS,
2169 gettext_noop("Sets the server's data directory."),
2178 {"config_file", PGC_POSTMASTER, FILE_LOCATIONS,
2179 gettext_noop("Sets the server's main configuration file."),
2181 GUC_DISALLOW_IN_FILE | GUC_SUPERUSER_ONLY
2188 {"hba_file", PGC_POSTMASTER, FILE_LOCATIONS,
2189 gettext_noop("Sets the server's \"hba\" configuration file"),
2198 {"ident_file", PGC_POSTMASTER, FILE_LOCATIONS,
2199 gettext_noop("Sets the server's \"ident\" configuration file"),
2208 {"external_pid_file", PGC_POSTMASTER, FILE_LOCATIONS,
2209 gettext_noop("Writes the postmaster PID to the specified file."),
2214 NULL, assign_canonical_path, NULL
2217 /* End-of-list marker */
2219 {NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL
2224 /******** end of options list ********/
2228 * To allow continued support of obsolete names for GUC variables, we apply
2229 * the following mappings to any unrecognized name. Note that an old name
2230 * should be mapped to a new one only if the new variable has very similar
2231 * semantics to the old.
2233 static const char *const map_old_guc_names[] = {
2234 "sort_mem", "work_mem",
2235 "vacuum_mem", "maintenance_work_mem",
2241 * Actual lookup of variables is done through this single, sorted array.
2243 static struct config_generic **guc_variables;
2245 /* Current number of variables contained in the vector */
2246 static int num_guc_variables;
2248 /* Vector capacity */
2249 static int size_guc_variables;
2252 static bool guc_dirty; /* TRUE if need to do commit/abort work */
2254 static bool reporting_enabled; /* TRUE to enable GUC_REPORT */
2257 static int guc_var_compare(const void *a, const void *b);
2258 static int guc_name_compare(const char *namea, const char *nameb);
2259 static void push_old_value(struct config_generic * gconf);
2260 static void ReportGUCOption(struct config_generic * record);
2261 static void ShowGUCConfigOption(const char *name, DestReceiver *dest);
2262 static void ShowAllGUCConfig(DestReceiver *dest);
2263 static char *_ShowOption(struct config_generic * record, bool use_units);
2264 static bool is_newvalue_equal(struct config_generic *record, const char *newvalue);
2268 * Some infrastructure for checking malloc/strdup/realloc calls
2271 guc_malloc(int elevel, size_t size)
2275 data = malloc(size);
2278 (errcode(ERRCODE_OUT_OF_MEMORY),
2279 errmsg("out of memory")));
2284 guc_realloc(int elevel, void *old, size_t size)
2288 data = realloc(old, size);
2291 (errcode(ERRCODE_OUT_OF_MEMORY),
2292 errmsg("out of memory")));
2297 guc_strdup(int elevel, const char *src)
2304 (errcode(ERRCODE_OUT_OF_MEMORY),
2305 errmsg("out of memory")));
2311 * Support for assigning to a field of a string GUC item. Free the prior
2312 * value if it's not referenced anywhere else in the item (including stacked
2316 set_string_field(struct config_string * conf, char **field, char *newval)
2318 char *oldval = *field;
2321 /* Do the assignment */
2324 /* Exit if any duplicate references, or if old value was NULL anyway */
2325 if (oldval == NULL ||
2326 oldval == *(conf->variable) ||
2327 oldval == conf->reset_val ||
2328 oldval == conf->tentative_val)
2330 for (stack = conf->gen.stack; stack; stack = stack->prev)
2332 if (oldval == stack->tentative_val.stringval ||
2333 oldval == stack->value.stringval)
2337 /* Not used anymore, so free it */
2342 * Detect whether strval is referenced anywhere in a GUC string item
2345 string_field_used(struct config_string * conf, char *strval)
2349 if (strval == *(conf->variable) ||
2350 strval == conf->reset_val ||
2351 strval == conf->tentative_val)
2353 for (stack = conf->gen.stack; stack; stack = stack->prev)
2355 if (strval == stack->tentative_val.stringval ||
2356 strval == stack->value.stringval)
2363 struct config_generic **
2364 get_guc_variables(void)
2366 return guc_variables;
2371 * Build the sorted array. This is split out so that it could be
2372 * re-executed after startup (eg, we could allow loadable modules to
2373 * add vars, and then we'd need to re-sort).
2376 build_guc_variables(void)
2380 struct config_generic **guc_vars;
2383 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
2385 struct config_bool *conf = &ConfigureNamesBool[i];
2387 /* Rather than requiring vartype to be filled in by hand, do this: */
2388 conf->gen.vartype = PGC_BOOL;
2392 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
2394 struct config_int *conf = &ConfigureNamesInt[i];
2396 conf->gen.vartype = PGC_INT;
2400 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
2402 struct config_real *conf = &ConfigureNamesReal[i];
2404 conf->gen.vartype = PGC_REAL;
2408 for (i = 0; ConfigureNamesString[i].gen.name; i++)
2410 struct config_string *conf = &ConfigureNamesString[i];
2412 conf->gen.vartype = PGC_STRING;
2417 * Create table with 20% slack
2419 size_vars = num_vars + num_vars / 4;
2421 guc_vars = (struct config_generic **)
2422 guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
2426 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
2427 guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
2429 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
2430 guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
2432 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
2433 guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
2435 for (i = 0; ConfigureNamesString[i].gen.name; i++)
2436 guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
2439 free(guc_variables);
2440 guc_variables = guc_vars;
2441 num_guc_variables = num_vars;
2442 size_guc_variables = size_vars;
2443 qsort((void *) guc_variables, num_guc_variables,
2444 sizeof(struct config_generic *), guc_var_compare);
2448 is_custom_class(const char *name, int dotPos)
2451 * assign_custom_variable_classes() has made sure no empty identifiers or
2452 * whitespace exists in the variable
2454 bool result = false;
2455 const char *ccs = GetConfigOption("custom_variable_classes");
2459 const char *start = ccs;
2465 if (c == 0 || c == ',')
2467 if (dotPos == ccs - start && strncmp(start, name, dotPos) == 0)
2482 * Add a new GUC variable to the list of known variables. The
2483 * list is expanded if needed.
2486 add_guc_variable(struct config_generic * var, int elevel)
2488 if (num_guc_variables + 1 >= size_guc_variables)
2491 * Increase the vector by 25%
2493 int size_vars = size_guc_variables + size_guc_variables / 4;
2494 struct config_generic **guc_vars;
2499 guc_vars = (struct config_generic **)
2500 guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
2504 guc_vars = (struct config_generic **)
2505 guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
2508 if (guc_vars == NULL)
2509 return false; /* out of memory */
2511 guc_variables = guc_vars;
2512 size_guc_variables = size_vars;
2514 guc_variables[num_guc_variables++] = var;
2515 qsort((void *) guc_variables, num_guc_variables,
2516 sizeof(struct config_generic *), guc_var_compare);
2521 * Create and add a placeholder variable. It's presumed to belong
2522 * to a valid custom variable class at this point.
2524 static struct config_string *
2525 add_placeholder_variable(const char *name, int elevel)
2527 size_t sz = sizeof(struct config_string) + sizeof(char *);
2528 struct config_string *var;
2529 struct config_generic *gen;
2531 var = (struct config_string *) guc_malloc(elevel, sz);
2538 gen->name = guc_strdup(elevel, name);
2539 if (gen->name == NULL)
2545 gen->context = PGC_USERSET;
2546 gen->group = CUSTOM_OPTIONS;
2547 gen->short_desc = "GUC placeholder variable";
2548 gen->flags = GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_CUSTOM_PLACEHOLDER;
2549 gen->vartype = PGC_STRING;
2552 * The char* is allocated at the end of the struct since we have no
2553 * 'static' place to point to.
2555 var->variable = (char **) (var + 1);
2557 if (!add_guc_variable((struct config_generic *) var, elevel))
2559 free((void *) gen->name);
2568 * Look up option NAME. If it exists, return a pointer to its record,
2571 static struct config_generic *
2572 find_option(const char *name, int elevel)
2575 const char **key = &name;
2576 struct config_generic **res;
2582 * By equating const char ** with struct config_generic *, we are assuming
2583 * the name field is first in config_generic.
2585 res = (struct config_generic **) bsearch((void *) &key,
2586 (void *) guc_variables,
2588 sizeof(struct config_generic *),
2594 * See if the name is an obsolete name for a variable. We assume that the
2595 * set of supported old names is short enough that a brute-force search is
2598 for (i = 0; map_old_guc_names[i] != NULL; i += 2)
2600 if (guc_name_compare(name, map_old_guc_names[i]) == 0)
2601 return find_option(map_old_guc_names[i + 1], elevel);
2605 * Check if the name is qualified, and if so, check if the qualifier maps
2606 * to a custom variable class.
2608 dot = strchr(name, GUC_QUALIFIER_SEPARATOR);
2609 if (dot != NULL && is_custom_class(name, dot - name))
2610 /* Add a placeholder variable for this name */
2611 return (struct config_generic *) add_placeholder_variable(name, elevel);
2619 * comparator for qsorting and bsearching guc_variables array
2622 guc_var_compare(const void *a, const void *b)
2624 struct config_generic *confa = *(struct config_generic **) a;
2625 struct config_generic *confb = *(struct config_generic **) b;
2627 return guc_name_compare(confa->name, confb->name);
2632 guc_name_compare(const char *namea, const char *nameb)
2635 * The temptation to use strcasecmp() here must be resisted, because the
2636 * array ordering has to remain stable across setlocale() calls. So, build
2637 * our own with a simple ASCII-only downcasing.
2639 while (*namea && *nameb)
2641 char cha = *namea++;
2642 char chb = *nameb++;
2644 if (cha >= 'A' && cha <= 'Z')
2646 if (chb >= 'A' && chb <= 'Z')
2652 return 1; /* a is longer */
2654 return -1; /* b is longer */
2660 * Initialize GUC options during program startup.
2662 * Note that we cannot read the config file yet, since we have not yet
2663 * processed command-line switches.
2666 InitializeGUCOptions(void)
2672 * Build sorted array of all GUC variables.
2674 build_guc_variables();
2677 * Load all variables with their compiled-in defaults, and initialize
2678 * status fields as needed.
2680 for (i = 0; i < num_guc_variables; i++)
2682 struct config_generic *gconf = guc_variables[i];
2685 gconf->reset_source = PGC_S_DEFAULT;
2686 gconf->tentative_source = PGC_S_DEFAULT;
2687 gconf->source = PGC_S_DEFAULT;
2688 gconf->stack = NULL;
2690 switch (gconf->vartype)
2694 struct config_bool *conf = (struct config_bool *) gconf;
2696 if (conf->assign_hook)
2697 if (!(*conf->assign_hook) (conf->reset_val, true,
2699 elog(FATAL, "failed to initialize %s to %d",
2700 conf->gen.name, (int) conf->reset_val);
2701 *conf->variable = conf->reset_val;
2706 struct config_int *conf = (struct config_int *) gconf;
2708 Assert(conf->reset_val >= conf->min);
2709 Assert(conf->reset_val <= conf->max);
2710 if (conf->assign_hook)
2711 if (!(*conf->assign_hook) (conf->reset_val, true,
2713 elog(FATAL, "failed to initialize %s to %d",
2714 conf->gen.name, conf->reset_val);
2715 *conf->variable = conf->reset_val;
2720 struct config_real *conf = (struct config_real *) gconf;
2722 Assert(conf->reset_val >= conf->min);
2723 Assert(conf->reset_val <= conf->max);
2724 if (conf->assign_hook)
2725 if (!(*conf->assign_hook) (conf->reset_val, true,
2727 elog(FATAL, "failed to initialize %s to %g",
2728 conf->gen.name, conf->reset_val);
2729 *conf->variable = conf->reset_val;
2734 struct config_string *conf = (struct config_string *) gconf;
2737 *conf->variable = NULL;
2738 conf->reset_val = NULL;
2739 conf->tentative_val = NULL;
2741 if (conf->boot_val == NULL)
2743 /* Cannot set value yet */
2747 str = guc_strdup(FATAL, conf->boot_val);
2748 conf->reset_val = str;
2750 if (conf->assign_hook)
2754 newstr = (*conf->assign_hook) (str, true,
2758 elog(FATAL, "failed to initialize %s to \"%s\"",
2759 conf->gen.name, str);
2761 else if (newstr != str)
2766 * See notes in set_config_option about casting
2768 str = (char *) newstr;
2769 conf->reset_val = str;
2772 *conf->variable = str;
2780 reporting_enabled = false;
2783 * Prevent any attempt to override the transaction modes from
2784 * non-interactive sources.
2786 SetConfigOption("transaction_isolation", "default",
2787 PGC_POSTMASTER, PGC_S_OVERRIDE);
2788 SetConfigOption("transaction_read_only", "no",
2789 PGC_POSTMASTER, PGC_S_OVERRIDE);
2792 * For historical reasons, some GUC parameters can receive defaults from
2793 * environment variables. Process those settings.
2796 env = getenv("PGPORT");
2798 SetConfigOption("port", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
2800 env = getenv("PGDATESTYLE");
2802 SetConfigOption("datestyle", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
2804 env = getenv("PGCLIENTENCODING");
2806 SetConfigOption("client_encoding", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
2811 * Select the configuration files and data directory to be used, and
2812 * do the initial read of postgresql.conf.
2814 * This is called after processing command-line switches.
2815 * userDoption is the -D switch value if any (NULL if unspecified).
2816 * progname is just for use in error messages.
2818 * Returns true on success; on failure, prints a suitable error message
2819 * to stderr and returns false.
2822 SelectConfigFiles(const char *userDoption, const char *progname)
2826 struct stat stat_buf;
2828 /* configdir is -D option, or $PGDATA if no -D */
2830 configdir = make_absolute_path(userDoption);
2832 configdir = make_absolute_path(getenv("PGDATA"));
2835 * Find the configuration file: if config_file was specified on the
2836 * command line, use it, else use configdir/postgresql.conf. In any case
2837 * ensure the result is an absolute path, so that it will be interpreted
2838 * the same way by future backends.
2841 fname = make_absolute_path(ConfigFileName);
2844 fname = guc_malloc(FATAL,
2845 strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
2846 sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
2850 write_stderr("%s does not know where to find the server configuration file.\n"
2851 "You must specify the --config-file or -D invocation "
2852 "option or set the PGDATA environment variable.\n",
2858 * Set the ConfigFileName GUC variable to its final value, ensuring that
2859 * it can't be overridden later.
2861 SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
2865 * Now read the config file for the first time.
2867 if (stat(ConfigFileName, &stat_buf) != 0)
2869 write_stderr("%s cannot access the server configuration file \"%s\": %s\n",
2870 progname, ConfigFileName, strerror(errno));
2874 ProcessConfigFile(PGC_POSTMASTER);
2877 * If the data_directory GUC variable has been set, use that as DataDir;
2878 * otherwise use configdir if set; else punt.
2880 * Note: SetDataDir will copy and absolute-ize its argument, so we don't
2884 SetDataDir(data_directory);
2886 SetDataDir(configdir);
2889 write_stderr("%s does not know where to find the database system data.\n"
2890 "This can be specified as \"data_directory\" in \"%s\", "
2891 "or by the -D invocation option, or by the "
2892 "PGDATA environment variable.\n",
2893 progname, ConfigFileName);
2898 * Reflect the final DataDir value back into the data_directory GUC var.
2899 * (If you are wondering why we don't just make them a single variable,
2900 * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
2901 * child backends specially. XXX is that still true? Given that we now
2902 * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
2903 * DataDir in advance.)
2905 SetConfigOption("data_directory", DataDir, PGC_POSTMASTER, PGC_S_OVERRIDE);
2908 * Figure out where pg_hba.conf is, and make sure the path is absolute.
2911 fname = make_absolute_path(HbaFileName);
2914 fname = guc_malloc(FATAL,
2915 strlen(configdir) + strlen(HBA_FILENAME) + 2);
2916 sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
2920 write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
2921 "This can be specified as \"hba_file\" in \"%s\", "
2922 "or by the -D invocation option, or by the "
2923 "PGDATA environment variable.\n",
2924 progname, ConfigFileName);
2927 SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
2931 * Likewise for pg_ident.conf.
2934 fname = make_absolute_path(IdentFileName);
2937 fname = guc_malloc(FATAL,
2938 strlen(configdir) + strlen(IDENT_FILENAME) + 2);
2939 sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
2943 write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
2944 "This can be specified as \"ident_file\" in \"%s\", "
2945 "or by the -D invocation option, or by the "
2946 "PGDATA environment variable.\n",
2947 progname, ConfigFileName);
2950 SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
2960 * Reset all options to their saved default values (implements RESET ALL)
2963 ResetAllOptions(void)
2967 for (i = 0; i < num_guc_variables; i++)
2969 struct config_generic *gconf = guc_variables[i];
2971 /* Don't reset non-SET-able values */
2972 if (gconf->context != PGC_SUSET &&
2973 gconf->context != PGC_USERSET)
2975 /* Don't reset if special exclusion from RESET ALL */
2976 if (gconf->flags & GUC_NO_RESET_ALL)
2978 /* No need to reset if wasn't SET */
2979 if (gconf->source <= PGC_S_OVERRIDE)
2982 /* Save old value to support transaction abort */
2983 push_old_value(gconf);
2985 switch (gconf->vartype)
2989 struct config_bool *conf = (struct config_bool *) gconf;
2991 if (conf->assign_hook)
2992 if (!(*conf->assign_hook) (conf->reset_val, true,
2994 elog(ERROR, "failed to reset %s", conf->gen.name);
2995 *conf->variable = conf->reset_val;
2996 conf->tentative_val = conf->reset_val;
2997 conf->gen.source = conf->gen.reset_source;
2998 conf->gen.tentative_source = conf->gen.reset_source;
2999 conf->gen.status |= GUC_HAVE_TENTATIVE;
3005 struct config_int *conf = (struct config_int *) gconf;
3007 if (conf->assign_hook)
3008 if (!(*conf->assign_hook) (conf->reset_val, true,
3010 elog(ERROR, "failed to reset %s", conf->gen.name);
3011 *conf->variable = conf->reset_val;
3012 conf->tentative_val = conf->reset_val;
3013 conf->gen.source = conf->gen.reset_source;
3014 conf->gen.tentative_source = conf->gen.reset_source;
3015 conf->gen.status |= GUC_HAVE_TENTATIVE;
3021 struct config_real *conf = (struct config_real *) gconf;
3023 if (conf->assign_hook)
3024 if (!(*conf->assign_hook) (conf->reset_val, true,
3026 elog(ERROR, "failed to reset %s", conf->gen.name);
3027 *conf->variable = conf->reset_val;
3028 conf->tentative_val = conf->reset_val;
3029 conf->gen.source = conf->gen.reset_source;
3030 conf->gen.tentative_source = conf->gen.reset_source;
3031 conf->gen.status |= GUC_HAVE_TENTATIVE;
3037 struct config_string *conf = (struct config_string *) gconf;
3040 if (conf->reset_val == NULL)
3042 /* Nothing to reset to, as yet; so do nothing */
3046 /* We need not strdup here */
3047 str = conf->reset_val;
3049 if (conf->assign_hook)
3053 newstr = (*conf->assign_hook) (str, true,
3056 elog(ERROR, "failed to reset %s", conf->gen.name);
3057 else if (newstr != str)
3060 * See notes in set_config_option about casting
3062 str = (char *) newstr;
3066 set_string_field(conf, conf->variable, str);
3067 set_string_field(conf, &conf->tentative_val, str);
3068 conf->gen.source = conf->gen.reset_source;
3069 conf->gen.tentative_source = conf->gen.reset_source;
3070 conf->gen.status |= GUC_HAVE_TENTATIVE;
3076 if (gconf->flags & GUC_REPORT)
3077 ReportGUCOption(gconf);
3084 * Push previous state during first assignment to a GUC variable
3085 * within a particular transaction.
3087 * We have to be willing to "back-fill" the state stack if the first
3088 * assignment occurs within a subtransaction nested several levels deep.
3089 * This ensures that if an intermediate transaction aborts, it will have
3090 * the proper value available to restore the setting to.
3093 push_old_value(struct config_generic * gconf)
3095 int my_level = GetCurrentTransactionNestLevel();
3098 /* If we're not inside a transaction, do nothing */
3104 /* Done if we already pushed it at this nesting depth */
3105 if (gconf->stack && gconf->stack->nest_level >= my_level)
3109 * We keep all the stack entries in TopTransactionContext so as to
3110 * avoid allocation problems when a subtransaction back-fills stack
3111 * entries for upper transaction levels.
3113 stack = (GucStack *) MemoryContextAlloc(TopTransactionContext,
3116 stack->prev = gconf->stack;
3117 stack->nest_level = stack->prev ? stack->prev->nest_level + 1 : 1;
3118 stack->status = gconf->status;
3119 stack->tentative_source = gconf->tentative_source;
3120 stack->source = gconf->source;
3122 switch (gconf->vartype)
3125 stack->tentative_val.boolval =
3126 ((struct config_bool *) gconf)->tentative_val;
3127 stack->value.boolval =
3128 *((struct config_bool *) gconf)->variable;
3132 stack->tentative_val.intval =
3133 ((struct config_int *) gconf)->tentative_val;
3134 stack->value.intval =
3135 *((struct config_int *) gconf)->variable;
3139 stack->tentative_val.realval =
3140 ((struct config_real *) gconf)->tentative_val;
3141 stack->value.realval =
3142 *((struct config_real *) gconf)->variable;
3146 stack->tentative_val.stringval =
3147 ((struct config_string *) gconf)->tentative_val;
3148 stack->value.stringval =
3149 *((struct config_string *) gconf)->variable;
3153 gconf->stack = stack;
3155 /* Set state to indicate nothing happened yet within this level */
3156 gconf->status = GUC_HAVE_STACK;
3158 /* Ensure we remember to pop at end of xact */
3164 * Do GUC processing at transaction or subtransaction commit or abort.
3167 AtEOXact_GUC(bool isCommit, bool isSubXact)
3172 /* Quick exit if nothing's changed in this transaction */
3176 my_level = GetCurrentTransactionNestLevel();
3177 Assert(isSubXact ? (my_level > 1) : (my_level == 1));
3179 for (i = 0; i < num_guc_variables; i++)
3181 struct config_generic *gconf = guc_variables[i];
3182 int my_status = gconf->status;
3183 GucStack *stack = gconf->stack;
3188 * Skip if nothing's happened to this var in this transaction
3192 Assert(stack == NULL);
3195 /* Assert that we stacked old value before changing it */
3196 Assert(stack != NULL && (my_status & GUC_HAVE_STACK));
3197 /* However, the last change may have been at an outer xact level */
3198 if (stack->nest_level < my_level)
3200 Assert(stack->nest_level == my_level);
3203 * We will pop the stack entry. Start by restoring outer xact status
3204 * (since we may want to modify it below). Be careful to use
3205 * my_status to reference the inner xact status below this point...
3207 gconf->status = stack->status;
3210 * We have two cases:
3212 * If commit and HAVE_TENTATIVE, set actual value to tentative (this
3213 * is to override a SET LOCAL if one occurred later than SET). We keep
3214 * the tentative value and propagate HAVE_TENTATIVE to the parent
3215 * status, allowing the SET's effect to percolate up. (But if we're
3216 * exiting the outermost transaction, we'll drop the HAVE_TENTATIVE
3219 * Otherwise, we have a transaction that aborted or executed only SET
3220 * LOCAL (or no SET at all). In either case it should have no further
3221 * effect, so restore both tentative and actual values from the stack
3225 useTentative = isCommit && (my_status & GUC_HAVE_TENTATIVE) != 0;
3228 switch (gconf->vartype)
3232 struct config_bool *conf = (struct config_bool *) gconf;
3234 GucSource newsource;
3238 newval = conf->tentative_val;
3239 newsource = conf->gen.tentative_source;
3240 conf->gen.status |= GUC_HAVE_TENTATIVE;
3244 newval = stack->value.boolval;
3245 newsource = stack->source;
3246 conf->tentative_val = stack->tentative_val.boolval;
3247 conf->gen.tentative_source = stack->tentative_source;
3250 if (*conf->variable != newval)
3252 if (conf->assign_hook)
3253 if (!(*conf->assign_hook) (newval,
3254 true, PGC_S_OVERRIDE))
3255 elog(LOG, "failed to commit %s",
3257 *conf->variable = newval;
3260 conf->gen.source = newsource;
3265 struct config_int *conf = (struct config_int *) gconf;
3267 GucSource newsource;
3271 newval = conf->tentative_val;
3272 newsource = conf->gen.tentative_source;
3273 conf->gen.status |= GUC_HAVE_TENTATIVE;
3277 newval = stack->value.intval;
3278 newsource = stack->source;
3279 conf->tentative_val = stack->tentative_val.intval;
3280 conf->gen.tentative_source = stack->tentative_source;
3283 if (*conf->variable != newval)
3285 if (conf->assign_hook)
3286 if (!(*conf->assign_hook) (newval,
3287 true, PGC_S_OVERRIDE))
3288 elog(LOG, "failed to commit %s",
3290 *conf->variable = newval;
3293 conf->gen.source = newsource;
3298 struct config_real *conf = (struct config_real *) gconf;
3300 GucSource newsource;
3304 newval = conf->tentative_val;
3305 newsource = conf->gen.tentative_source;
3306 conf->gen.status |= GUC_HAVE_TENTATIVE;
3310 newval = stack->value.realval;
3311 newsource = stack->source;
3312 conf->tentative_val = stack->tentative_val.realval;
3313 conf->gen.tentative_source = stack->tentative_source;
3316 if (*conf->variable != newval)
3318 if (conf->assign_hook)
3319 if (!(*conf->assign_hook) (newval,
3320 true, PGC_S_OVERRIDE))
3321 elog(LOG, "failed to commit %s",
3323 *conf->variable = newval;
3326 conf->gen.source = newsource;
3331 struct config_string *conf = (struct config_string *) gconf;
3333 GucSource newsource;
3337 newval = conf->tentative_val;
3338 newsource = conf->gen.tentative_source;
3339 conf->gen.status |= GUC_HAVE_TENTATIVE;
3343 newval = stack->value.stringval;
3344 newsource = stack->source;
3345 set_string_field(conf, &conf->tentative_val,
3346 stack->tentative_val.stringval);
3347 conf->gen.tentative_source = stack->tentative_source;
3350 if (*conf->variable != newval)
3352 if (conf->assign_hook)
3356 newstr = (*conf->assign_hook) (newval, true,
3359 elog(LOG, "failed to commit %s",
3361 else if (newstr != newval)
3364 * If newval should now be freed, it'll be
3365 * taken care of below.
3367 * See notes in set_config_option about
3370 newval = (char *) newstr;
3374 set_string_field(conf, conf->variable, newval);
3377 conf->gen.source = newsource;
3378 /* Release stacked values if not used anymore */
3379 set_string_field(conf, &stack->value.stringval,
3381 set_string_field(conf, &stack->tentative_val.stringval,
3383 /* Don't store tentative value separately after commit */
3385 set_string_field(conf, &conf->tentative_val, NULL);
3390 /* Finish popping the state stack */
3391 gconf->stack = stack->prev;
3395 * If we're now out of all xact levels, forget TENTATIVE status bit;
3396 * there's nothing tentative about the value anymore.
3400 Assert(gconf->stack == NULL);
3404 /* Report new value if we changed it */
3405 if (changed && (gconf->flags & GUC_REPORT))
3406 ReportGUCOption(gconf);
3410 * If we're now out of all xact levels, we can clear guc_dirty. (Note: we
3411 * cannot reset guc_dirty when exiting a subtransaction, because we know
3412 * that all outer transaction levels will have stacked values to deal
3421 * Start up automatic reporting of changes to variables marked GUC_REPORT.
3422 * This is executed at completion of backend startup.
3425 BeginReportingGUCOptions(void)
3430 * Don't do anything unless talking to an interactive frontend of protocol
3433 if (whereToSendOutput != DestRemote ||
3434 PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
3437 reporting_enabled = true;
3439 /* Transmit initial values of interesting variables */
3440 for (i = 0; i < num_guc_variables; i++)
3442 struct config_generic *conf = guc_variables[i];
3444 if (conf->flags & GUC_REPORT)
3445 ReportGUCOption(conf);
3450 * ReportGUCOption: if appropriate, transmit option value to frontend
3453 ReportGUCOption(struct config_generic * record)
3455 if (reporting_enabled && (record->flags & GUC_REPORT))
3457 char *val = _ShowOption(record, false);
3458 StringInfoData msgbuf;
3460 pq_beginmessage(&msgbuf, 'S');
3461 pq_sendstring(&msgbuf, record->name);
3462 pq_sendstring(&msgbuf, val);
3463 pq_endmessage(&msgbuf);
3471 * Try to interpret value as boolean value. Valid values are: true,
3472 * false, yes, no, on, off, 1, 0. If the string parses okay, return
3473 * true, else false. If result is not NULL, return the parsing result
3477 parse_bool(const char *value, bool *result)
3479 size_t len = strlen(value);
3481 if (pg_strncasecmp(value, "true", len) == 0)
3486 else if (pg_strncasecmp(value, "false", len) == 0)
3492 else if (pg_strncasecmp(value, "yes", len) == 0)
3497 else if (pg_strncasecmp(value, "no", len) == 0)
3503 else if (pg_strcasecmp(value, "on") == 0)
3508 else if (pg_strcasecmp(value, "off") == 0)
3514 else if (pg_strcasecmp(value, "1") == 0)
3519 else if (pg_strcasecmp(value, "0") == 0)
3528 *result = false; /* suppress compiler warning */
3537 * Try to parse value as an integer. The accepted formats are the
3538 * usual decimal, octal, or hexadecimal formats. If the string parses
3539 * okay, return true, else false. If result is not NULL, return the
3543 parse_int(const char *value, int *result, int flags)
3549 val = strtol(value, &endptr, 0);
3551 if ((flags & GUC_UNIT_MEMORY) && endptr != value)
3555 while (*endptr == ' ')
3558 if (strcmp(endptr, "kB") == 0)
3563 else if (strcmp(endptr, "MB") == 0)
3569 else if (strcmp(endptr, "GB") == 0)
3576 if (used && (flags & GUC_UNIT_BLOCKS))
3577 val /= (BLCKSZ/1024);
3580 if ((flags & GUC_UNIT_TIME) && endptr != value)
3584 while (*endptr == ' ')
3587 if (strcmp(endptr, "ms") == 0)
3592 else if (strcmp(endptr, "s") == 0)
3598 else if (strcmp(endptr, "min") == 0)
3604 else if (strcmp(endptr, "h") == 0)
3610 else if (strcmp(endptr, "d") == 0)
3617 if (used && (flags & GUC_UNIT_S))
3619 else if (used && (flags & GUC_UNIT_MIN))
3623 if (endptr == value || *endptr != '\0' || errno == ERANGE
3624 #ifdef HAVE_LONG_INT_64
3625 /* if long > 32 bits, check for overflow of int4 */
3626 || val != (long) ((int32) val)
3631 *result = 0; /* suppress compiler warning */
3635 *result = (int) val;
3642 * Try to parse value as a floating point constant in the usual
3643 * format. If the value parsed okay return true, else false. If
3644 * result is not NULL, return the semantic value there.
3647 parse_real(const char *value, double *result)
3653 val = strtod(value, &endptr);
3654 if (endptr == value || *endptr != '\0' || errno == ERANGE)
3657 *result = 0; /* suppress compiler warning */
3667 * Call a GucStringAssignHook function, being careful to free the
3668 * "newval" string if the hook ereports.
3670 * This is split out of set_config_option just to avoid the "volatile"
3671 * qualifiers that would otherwise have to be plastered all over.
3674 call_string_assign_hook(GucStringAssignHook assign_hook,
3675 char *newval, bool doit, GucSource source)
3681 result = (*assign_hook) (newval, doit, source);
3695 * Sets option `name' to given value. The value should be a string
3696 * which is going to be parsed and converted to the appropriate data
3697 * type. The context and source parameters indicate in which context this
3698 * function is being called so it can apply the access restrictions
3701 * If value is NULL, set the option to its default value. If the
3702 * parameter changeVal is false then don't really set the option but do all
3703 * the checks to see if it would work.
3705 * If there is an error (non-existing option, invalid value) then an
3706 * ereport(ERROR) is thrown *unless* this is called in a context where we
3707 * don't want to ereport (currently, startup or SIGHUP config file reread).
3708 * In that case we write a suitable error message via ereport(DEBUG) and
3709 * return false. This is working around the deficiencies in the ereport
3710 * mechanism, so don't blame me. In all other cases, the function
3711 * returns true, including cases where the input is valid but we chose
3712 * not to apply it because of context or source-priority considerations.
3714 * See also SetConfigOption for an external interface.
3717 set_config_option(const char *name, const char *value,
3718 GucContext context, GucSource source,
3719 bool isLocal, bool changeVal)
3721 struct config_generic *record;
3725 if (context == PGC_SIGHUP || source == PGC_S_DEFAULT)
3728 * To avoid cluttering the log, only the postmaster bleats loudly
3729 * about problems with the config file.
3731 elevel = IsUnderPostmaster ? DEBUG2 : LOG;
3733 else if (source == PGC_S_DATABASE || source == PGC_S_USER)
3738 record = find_option(name, elevel);
3742 (errcode(ERRCODE_UNDEFINED_OBJECT),
3743 errmsg("unrecognized configuration parameter \"%s\"", name)));
3748 * Check if the option can be set at this time. See guc.h for the precise
3749 * rules. Note that we don't want to throw errors if we're in the SIGHUP
3750 * context. In that case we just ignore the attempt and return true.
3752 switch (record->context)
3755 if (context == PGC_SIGHUP)
3757 if (context != PGC_INTERNAL)
3760 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3761 errmsg("parameter \"%s\" cannot be changed",
3766 case PGC_POSTMASTER:
3767 if (context == PGC_SIGHUP)
3769 if (changeVal && !is_newvalue_equal(record, value))
3771 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3772 errmsg("parameter \"%s\" cannot be changed after server start; configuration file change ignored",
3777 if (context != PGC_POSTMASTER)
3780 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3781 errmsg("parameter \"%s\" cannot be changed after server start",
3787 if (context != PGC_SIGHUP && context != PGC_POSTMASTER)
3790 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3791 errmsg("parameter \"%s\" cannot be changed now",
3797 * Hmm, the idea of the SIGHUP context is "ought to be global, but
3798 * can be changed after postmaster start". But there's nothing
3799 * that prevents a crafty administrator from sending SIGHUP
3800 * signals to individual backends only.
3804 if (context == PGC_SIGHUP)
3807 * If a PGC_BACKEND parameter is changed in the config file,
3808 * we want to accept the new value in the postmaster (whence
3809 * it will propagate to subsequently-started backends), but
3810 * ignore it in existing backends. This is a tad klugy, but
3811 * necessary because we don't re-read the config file during
3814 if (IsUnderPostmaster)
3817 else if (context != PGC_BACKEND && context != PGC_POSTMASTER)
3820 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3821 errmsg("parameter \"%s\" cannot be set after connection start",
3827 if (context == PGC_USERSET || context == PGC_BACKEND)
3830 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3831 errmsg("permission denied to set parameter \"%s\"",
3842 * Should we set reset/stacked values? (If so, the behavior is not
3845 makeDefault = changeVal && (source <= PGC_S_OVERRIDE) && (value != NULL);
3848 * Ignore attempted set if overridden by previously processed setting.
3849 * However, if changeVal is false then plow ahead anyway since we are
3850 * trying to find out if the value is potentially good, not actually use
3851 * it. Also keep going if makeDefault is true, since we may want to set
3852 * the reset/stacked values even if we can't set the variable itself.
3854 if (record->source > source)
3856 if (changeVal && !makeDefault)
3858 elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
3866 * Evaluate value and set variable.
3868 switch (record->vartype)
3872 struct config_bool *conf = (struct config_bool *) record;
3877 if (!parse_bool(value, &newval))
3880 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3881 errmsg("parameter \"%s\" requires a Boolean value",
3888 newval = conf->reset_val;
3889 source = conf->gen.reset_source;
3892 if (conf->assign_hook)
3893 if (!(*conf->assign_hook) (newval, changeVal, source))
3896 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3897 errmsg("invalid value for parameter \"%s\": %d",
3898 name, (int) newval)));
3902 if (changeVal || makeDefault)
3904 /* Save old value to support transaction abort */
3906 push_old_value(&conf->gen);
3909 *conf->variable = newval;
3910 conf->gen.source = source;
3916 if (conf->gen.reset_source <= source)
3918 conf->reset_val = newval;
3919 conf->gen.reset_source = source;
3921 for (stack = conf->gen.stack; stack; stack = stack->prev)
3923 if (stack->source <= source)
3925 stack->value.boolval = newval;
3926 stack->source = source;
3932 conf->gen.status |= GUC_HAVE_LOCAL;
3937 conf->tentative_val = newval;
3938 conf->gen.tentative_source = source;
3939 conf->gen.status |= GUC_HAVE_TENTATIVE;
3948 struct config_int *conf = (struct config_int *) record;
3953 if (!parse_int(value, &newval, conf->gen.flags))
3956 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3957 errmsg("parameter \"%s\" requires an integer value",
3961 if (newval < conf->min || newval > conf->max)
3964 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3965 errmsg("%d is outside the valid range for parameter \"%s\" (%d .. %d)",
3966 newval, name, conf->min, conf->max)));
3972 newval = conf->reset_val;
3973 source = conf->gen.reset_source;
3976 if (conf->assign_hook)
3977 if (!(*conf->assign_hook) (newval, changeVal, source))
3980 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3981 errmsg("invalid value for parameter \"%s\": %d",
3986 if (changeVal || makeDefault)
3988 /* Save old value to support transaction abort */
3990 push_old_value(&conf->gen);
3993 *conf->variable = newval;
3994 conf->gen.source = source;
4000 if (conf->gen.reset_source <= source)
4002 conf->reset_val = newval;
4003 conf->gen.reset_source = source;
4005 for (stack = conf->gen.stack; stack; stack = stack->prev)
4007 if (stack->source <= source)
4009 stack->value.intval = newval;
4010 stack->source = source;
4016 conf->gen.status |= GUC_HAVE_LOCAL;
4021 conf->tentative_val = newval;
4022 conf->gen.tentative_source = source;
4023 conf->gen.status |= GUC_HAVE_TENTATIVE;
4032 struct config_real *conf = (struct config_real *) record;
4037 if (!parse_real(value, &newval))
4040 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4041 errmsg("parameter \"%s\" requires a numeric value",
4045 if (newval < conf->min || newval > conf->max)
4048 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4049 errmsg("%g is outside the valid range for parameter \"%s\" (%g .. %g)",
4050 newval, name, conf->min, conf->max)));
4056 newval = conf->reset_val;
4057 source = conf->gen.reset_source;
4060 if (conf->assign_hook)
4061 if (!(*conf->assign_hook) (newval, changeVal, source))
4064 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4065 errmsg("invalid value for parameter \"%s\": %g",
4070 if (changeVal || makeDefault)
4072 /* Save old value to support transaction abort */
4074 push_old_value(&conf->gen);
4077 *conf->variable = newval;
4078 conf->gen.source = source;
4084 if (conf->gen.reset_source <= source)
4086 conf->reset_val = newval;
4087 conf->gen.reset_source = source;
4089 for (stack = conf->gen.stack; stack; stack = stack->prev)
4091 if (stack->source <= source)
4093 stack->value.realval = newval;
4094 stack->source = source;
4100 conf->gen.status |= GUC_HAVE_LOCAL;
4105 conf->tentative_val = newval;
4106 conf->gen.tentative_source = source;
4107 conf->gen.status |= GUC_HAVE_TENTATIVE;
4116 struct config_string *conf = (struct config_string *) record;
4121 newval = guc_strdup(elevel, value);
4125 * The only sort of "parsing" check we need to do is
4126 * apply truncation if GUC_IS_NAME.
4128 if (conf->gen.flags & GUC_IS_NAME)
4129 truncate_identifier(newval, strlen(newval), true);
4131 else if (conf->reset_val)
4134 * We could possibly avoid strdup here, but easier to make
4135 * this case work the same as the normal assignment case.
4137 newval = guc_strdup(elevel, conf->reset_val);
4140 source = conf->gen.reset_source;
4144 /* Nothing to reset to, as yet; so do nothing */
4148 if (conf->assign_hook)
4150 const char *hookresult;
4153 * If the hook ereports, we have to make sure we free
4154 * newval, else it will be a permanent memory leak.
4156 hookresult = call_string_assign_hook(conf->assign_hook,
4160 if (hookresult == NULL)
4164 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4165 errmsg("invalid value for parameter \"%s\": \"%s\"",
4166 name, value ? value : "")));
4169 else if (hookresult != newval)
4174 * Having to cast away const here is annoying, but the
4175 * alternative is to declare assign_hooks as returning
4176 * char*, which would mean they'd have to cast away
4177 * const, or as both taking and returning char*, which
4178 * doesn't seem attractive either --- we don't want
4179 * them to scribble on the passed str.
4181 newval = (char *) hookresult;
4185 if (changeVal || makeDefault)
4187 /* Save old value to support transaction abort */
4189 push_old_value(&conf->gen);
4192 set_string_field(conf, conf->variable, newval);
4193 conf->gen.source = source;
4199 if (conf->gen.reset_source <= source)
4201 set_string_field(conf, &conf->reset_val, newval);
4202 conf->gen.reset_source = source;
4204 for (stack = conf->gen.stack; stack; stack = stack->prev)
4206 if (stack->source <= source)
4208 set_string_field(conf, &stack->value.stringval,
4210 stack->source = source;
4213 /* Perhaps we didn't install newval anywhere */
4214 if (!string_field_used(conf, newval))
4219 conf->gen.status |= GUC_HAVE_LOCAL;
4224 set_string_field(conf, &conf->tentative_val, newval);
4225 conf->gen.tentative_source = source;
4226 conf->gen.status |= GUC_HAVE_TENTATIVE;
4236 if (changeVal && (record->flags & GUC_REPORT))
4237 ReportGUCOption(record);
4244 * Set a config option to the given value. See also set_config_option,
4245 * this is just the wrapper to be called from outside GUC. NB: this
4246 * is used only for non-transactional operations.
4249 SetConfigOption(const char *name, const char *value,
4250 GucContext context, GucSource source)
4252 (void) set_config_option(name, value, context, source, false, true);
4258 * Fetch the current value of the option `name'. If the option doesn't exist,
4259 * throw an ereport and don't return.
4261 * The string is *not* allocated for modification and is really only
4262 * valid until the next call to configuration related functions.
4265 GetConfigOption(const char *name)
4267 struct config_generic *record;
4268 static char buffer[256];
4270 record = find_option(name, ERROR);
4273 (errcode(ERRCODE_UNDEFINED_OBJECT),
4274 errmsg("unrecognized configuration parameter \"%s\"", name)));
4275 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
4277 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4278 errmsg("must be superuser to examine \"%s\"", name)));
4280 switch (record->vartype)
4283 return *((struct config_bool *) record)->variable ? "on" : "off";
4286 snprintf(buffer, sizeof(buffer), "%d",
4287 *((struct config_int *) record)->variable);
4291 snprintf(buffer, sizeof(buffer), "%g",
4292 *((struct config_real *) record)->variable);
4296 return *((struct config_string *) record)->variable;
4302 * Get the RESET value associated with the given option.
4305 GetConfigOptionResetString(const char *name)
4307 struct config_generic *record;
4308 static char buffer[256];
4310 record = find_option(name, ERROR);
4313 (errcode(ERRCODE_UNDEFINED_OBJECT),
4314 errmsg("unrecognized configuration parameter \"%s\"", name)));
4315 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
4317 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4318 errmsg("must be superuser to examine \"%s\"", name)));
4320 switch (record->vartype)
4323 return ((struct config_bool *) record)->reset_val ? "on" : "off";
4326 snprintf(buffer, sizeof(buffer), "%d",
4327 ((struct config_int *) record)->reset_val);
4331 snprintf(buffer, sizeof(buffer), "%g",
4332 ((struct config_real *) record)->reset_val);
4336 return ((struct config_string *) record)->reset_val;
4342 * Detect whether the given configuration option can only be set by
4346 IsSuperuserConfigOption(const char *name)
4348 struct config_generic *record;
4350 record = find_option(name, ERROR);
4351 /* On an unrecognized name, don't error, just return false. */
4354 return (record->context == PGC_SUSET);
4359 * flatten_set_variable_args
4360 * Given a parsenode List as emitted by the grammar for SET,
4361 * convert to the flat string representation used by GUC.
4363 * We need to be told the name of the variable the args are for, because
4364 * the flattening rules vary (ugh).
4366 * The result is NULL if input is NIL (ie, SET ... TO DEFAULT), otherwise
4367 * a palloc'd string.
4370 flatten_set_variable_args(const char *name, List *args)
4372 struct config_generic *record;
4378 * Fast path if just DEFAULT. We do not check the variable name in this
4379 * case --- necessary for RESET ALL to work correctly.
4384 /* Else get flags for the variable */
4385 record = find_option(name, ERROR);
4388 (errcode(ERRCODE_UNDEFINED_OBJECT),
4389 errmsg("unrecognized configuration parameter \"%s\"", name)));
4391 flags = record->flags;
4393 /* Complain if list input and non-list variable */
4394 if ((flags & GUC_LIST_INPUT) == 0 &&
4395 list_length(args) != 1)
4397 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4398 errmsg("SET %s takes only one argument", name)));
4400 initStringInfo(&buf);
4404 A_Const *arg = (A_Const *) lfirst(l);
4407 if (l != list_head(args))
4408 appendStringInfo(&buf, ", ");
4410 if (!IsA(arg, A_Const))
4411 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
4413 switch (nodeTag(&arg->val))
4416 appendStringInfo(&buf, "%ld", intVal(&arg->val));
4419 /* represented as a string, so just copy it */
4420 appendStringInfoString(&buf, strVal(&arg->val));
4423 val = strVal(&arg->val);
4424 if (arg->typename != NULL)
4427 * Must be a ConstInterval argument for TIME ZONE. Coerce
4428 * to interval and back to normalize the value and account
4435 DirectFunctionCall3(interval_in,
4436 CStringGetDatum(val),
4437 ObjectIdGetDatum(InvalidOid),
4438 Int32GetDatum(arg->typename->typmod));
4441 DatumGetCString(DirectFunctionCall1(interval_out,
4443 appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
4448 * Plain string literal or identifier. For quote mode,
4449 * quote it if it's not a vanilla identifier.
4451 if (flags & GUC_LIST_QUOTE)
4452 appendStringInfoString(&buf, quote_identifier(val));
4454 appendStringInfoString(&buf, val);
4458 elog(ERROR, "unrecognized node type: %d",
4459 (int) nodeTag(&arg->val));
4472 SetPGVariable(const char *name, List *args, bool is_local)
4474 char *argstring = flatten_set_variable_args(name, args);
4476 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
4477 set_config_option(name,
4479 (superuser() ? PGC_SUSET : PGC_USERSET),
4486 * SET command wrapped as a SQL callable function.
4489 set_config_by_name(PG_FUNCTION_ARGS)
4497 if (PG_ARGISNULL(0))
4499 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
4500 errmsg("SET requires parameter name")));
4502 /* Get the GUC variable name */
4503 name = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(0)));
4505 /* Get the desired value or set to NULL for a reset request */
4506 if (PG_ARGISNULL(1))
4509 value = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(1)));
4512 * Get the desired state of is_local. Default to false if provided value
4515 if (PG_ARGISNULL(2))
4518 is_local = PG_GETARG_BOOL(2);
4520 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
4521 set_config_option(name,
4523 (superuser() ? PGC_SUSET : PGC_USERSET),
4528 /* get the new current value */
4529 new_value = GetConfigOptionByName(name, NULL);
4531 /* Convert return string to text */
4532 result_text = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(new_value)));
4535 PG_RETURN_TEXT_P(result_text);
4539 define_custom_variable(struct config_generic * variable)
4541 const char *name = variable->name;
4542 const char **nameAddr = &name;
4544 struct config_string *pHolder;
4545 struct config_generic **res = (struct config_generic **) bsearch(
4547 (void *) guc_variables,
4549 sizeof(struct config_generic *),
4554 add_guc_variable(variable, ERROR);
4559 * This better be a placeholder
4561 if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
4563 (errcode(ERRCODE_INTERNAL_ERROR),
4564 errmsg("attempt to redefine parameter \"%s\"", name)));
4566 Assert((*res)->vartype == PGC_STRING);
4567 pHolder = (struct config_string *) * res;
4569 /* We have the same name, no sorting is necessary */
4572 value = *pHolder->variable;
4575 * Assign the string value stored in the placeholder to the real variable.
4577 * XXX this is not really good enough --- it should be a nontransactional
4578 * assignment, since we don't want it to roll back if the current xact
4581 set_config_option(name, value,
4582 pHolder->gen.context, pHolder->gen.source,
4586 * Free up as much as we conveniently can of the placeholder structure
4587 * (this neglects any stack items...)
4589 set_string_field(pHolder, pHolder->variable, NULL);
4590 set_string_field(pHolder, &pHolder->reset_val, NULL);
4591 set_string_field(pHolder, &pHolder->tentative_val, NULL);
4597 init_custom_variable(struct config_generic * gen,
4599 const char *short_desc,
4600 const char *long_desc,
4602 enum config_type type)
4604 gen->name = guc_strdup(ERROR, name);
4605 gen->context = context;
4606 gen->group = CUSTOM_OPTIONS;
4607 gen->short_desc = short_desc;
4608 gen->long_desc = long_desc;
4609 gen->vartype = type;
4613 DefineCustomBoolVariable(const char *name,
4614 const char *short_desc,
4615 const char *long_desc,
4618 GucBoolAssignHook assign_hook,
4619 GucShowHook show_hook)
4621 size_t sz = sizeof(struct config_bool);
4622 struct config_bool *var = (struct config_bool *) guc_malloc(ERROR, sz);
4625 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_BOOL);
4627 var->variable = valueAddr;
4628 var->reset_val = *valueAddr;
4629 var->assign_hook = assign_hook;
4630 var->show_hook = show_hook;
4631 define_custom_variable(&var->gen);
4635 DefineCustomIntVariable(const char *name,
4636 const char *short_desc,
4637 const char *long_desc,
4642 GucIntAssignHook assign_hook,
4643 GucShowHook show_hook)
4645 size_t sz = sizeof(struct config_int);
4646 struct config_int *var = (struct config_int *) guc_malloc(ERROR, sz);
4649 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_INT);
4651 var->variable = valueAddr;
4652 var->reset_val = *valueAddr;
4653 var->min = minValue;
4654 var->max = maxValue;
4655 var->assign_hook = assign_hook;
4656 var->show_hook = show_hook;
4657 define_custom_variable(&var->gen);
4661 DefineCustomRealVariable(const char *name,
4662 const char *short_desc,
4663 const char *long_desc,
4668 GucRealAssignHook assign_hook,
4669 GucShowHook show_hook)
4671 size_t sz = sizeof(struct config_real);
4672 struct config_real *var = (struct config_real *) guc_malloc(ERROR, sz);
4675 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_REAL);
4677 var->variable = valueAddr;
4678 var->reset_val = *valueAddr;
4679 var->min = minValue;
4680 var->max = maxValue;
4681 var->assign_hook = assign_hook;
4682 var->show_hook = show_hook;
4683 define_custom_variable(&var->gen);
4687 DefineCustomStringVariable(const char *name,
4688 const char *short_desc,
4689 const char *long_desc,
4692 GucStringAssignHook assign_hook,
4693 GucShowHook show_hook)
4695 size_t sz = sizeof(struct config_string);
4696 struct config_string *var = (struct config_string *) guc_malloc(ERROR, sz);
4699 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_STRING);
4701 var->variable = valueAddr;
4702 var->reset_val = *valueAddr;
4703 var->assign_hook = assign_hook;
4704 var->show_hook = show_hook;
4705 define_custom_variable(&var->gen);
4709 EmitWarningsOnPlaceholders(const char *className)
4711 struct config_generic **vars = guc_variables;
4712 struct config_generic **last = vars + num_guc_variables;
4714 int nameLen = strlen(className);
4718 struct config_generic *var = *vars++;
4720 if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
4721 strncmp(className, var->name, nameLen) == 0 &&
4722 var->name[nameLen] == GUC_QUALIFIER_SEPARATOR)
4725 (errcode(ERRCODE_UNDEFINED_OBJECT),
4726 errmsg("unrecognized configuration parameter \"%s\"", var->name)));
4736 GetPGVariable(const char *name, DestReceiver *dest)
4738 if (pg_strcasecmp(name, "all") == 0)
4739 ShowAllGUCConfig(dest);
4741 ShowGUCConfigOption(name, dest);
4745 GetPGVariableResultDesc(const char *name)
4749 if (pg_strcasecmp(name, "all") == 0)
4751 /* need a tuple descriptor representing three TEXT columns */
4752 tupdesc = CreateTemplateTupleDesc(3, false);
4753 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
4755 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
4757 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
4763 const char *varname;
4765 /* Get the canonical spelling of name */
4766 (void) GetConfigOptionByName(name, &varname);
4768 /* need a tuple descriptor representing a single TEXT column */
4769 tupdesc = CreateTemplateTupleDesc(1, false);
4770 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
4780 ResetPGVariable(const char *name)
4782 if (pg_strcasecmp(name, "all") == 0)
4785 set_config_option(name,
4787 (superuser() ? PGC_SUSET : PGC_USERSET),
4798 ShowGUCConfigOption(const char *name, DestReceiver *dest)
4800 TupOutputState *tstate;
4802 const char *varname;
4805 /* Get the value and canonical spelling of name */
4806 value = GetConfigOptionByName(name, &varname);
4808 /* need a tuple descriptor representing a single TEXT column */
4809 tupdesc = CreateTemplateTupleDesc(1, false);
4810 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
4813 /* prepare for projection of tuples */
4814 tstate = begin_tup_output_tupdesc(dest, tupdesc);
4817 do_text_output_oneline(tstate, value);
4819 end_tup_output(tstate);
4826 ShowAllGUCConfig(DestReceiver *dest)
4828 bool am_superuser = superuser();
4830 TupOutputState *tstate;
4834 /* need a tuple descriptor representing three TEXT columns */
4835 tupdesc = CreateTemplateTupleDesc(3, false);
4836 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
4838 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
4840 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
4844 /* prepare for projection of tuples */
4845 tstate = begin_tup_output_tupdesc(dest, tupdesc);
4847 for (i = 0; i < num_guc_variables; i++)
4849 struct config_generic *conf = guc_variables[i];
4851 if ((conf->flags & GUC_NO_SHOW_ALL) ||
4852 ((conf->flags & GUC_SUPERUSER_ONLY) && !am_superuser))
4855 /* assign to the values array */
4856 values[0] = (char *) conf->name;
4857 values[1] = _ShowOption(conf, true);
4858 values[2] = (char *) conf->short_desc;
4860 /* send it to dest */
4861 do_tup_output(tstate, values);
4864 if (values[1] != NULL)
4868 end_tup_output(tstate);
4872 * Return GUC variable value by name; optionally return canonical
4873 * form of name. Return value is palloc'd.
4876 GetConfigOptionByName(const char *name, const char **varname)
4878 struct config_generic *record;
4880 record = find_option(name, ERROR);
4883 (errcode(ERRCODE_UNDEFINED_OBJECT),
4884 errmsg("unrecognized configuration parameter \"%s\"", name)));
4885 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
4887 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4888 errmsg("must be superuser to examine \"%s\"", name)));
4891 *varname = record->name;
4893 return _ShowOption(record, true);
4897 * Return GUC variable value by variable number; optionally return canonical
4898 * form of name. Return value is palloc'd.
4901 GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
4904 struct config_generic *conf;
4906 /* check requested variable number valid */
4907 Assert((varnum >= 0) && (varnum < num_guc_variables));
4909 conf = guc_variables[varnum];
4913 if ((conf->flags & GUC_NO_SHOW_ALL) ||
4914 ((conf->flags & GUC_SUPERUSER_ONLY) && !superuser()))
4920 /* first get the generic attributes */
4923 values[0] = conf->name;
4925 /* setting : use _ShowOption in order to avoid duplicating the logic */
4926 values[1] = _ShowOption(conf, false);
4929 if (conf->vartype == PGC_INT)
4931 if (conf->flags & GUC_UNIT_KB)
4933 else if (conf->flags & GUC_UNIT_BLOCKS)
4937 snprintf(buf, sizeof(buf), "%dkB", BLCKSZ/1024);
4940 else if (conf->flags & GUC_UNIT_MS)
4942 else if (conf->flags & GUC_UNIT_S)
4944 else if (conf->flags & GUC_UNIT_MIN)
4953 values[3] = config_group_names[conf->group];
4956 values[4] = conf->short_desc;
4959 values[5] = conf->long_desc;
4962 values[6] = GucContext_Names[conf->context];
4965 values[7] = config_type_names[conf->vartype];
4968 values[8] = GucSource_Names[conf->source];
4970 /* now get the type specifc attributes */
4971 switch (conf->vartype)
4985 struct config_int *lconf = (struct config_int *) conf;
4988 snprintf(buffer, sizeof(buffer), "%d", lconf->min);
4989 values[9] = pstrdup(buffer);
4992 snprintf(buffer, sizeof(buffer), "%d", lconf->max);
4993 values[10] = pstrdup(buffer);
4999 struct config_real *lconf = (struct config_real *) conf;
5002 snprintf(buffer, sizeof(buffer), "%g", lconf->min);
5003 values[9] = pstrdup(buffer);
5006 snprintf(buffer, sizeof(buffer), "%g", lconf->max);
5007 values[10] = pstrdup(buffer);
5024 * should never get here, but in case we do, set 'em to NULL
5038 * Return the total number of GUC variables
5041 GetNumConfigOptions(void)
5043 return num_guc_variables;
5047 * show_config_by_name - equiv to SHOW X command but implemented as
5051 show_config_by_name(PG_FUNCTION_ARGS)
5057 /* Get the GUC variable name */
5058 varname = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(0)));
5061 varval = GetConfigOptionByName(varname, NULL);
5063 /* Convert to text */
5064 result_text = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(varval)));
5067 PG_RETURN_TEXT_P(result_text);
5071 * show_all_settings - equiv to SHOW ALL command but implemented as
5074 #define NUM_PG_SETTINGS_ATTS 11
5077 show_all_settings(PG_FUNCTION_ARGS)
5079 FuncCallContext *funcctx;
5083 AttInMetadata *attinmeta;
5084 MemoryContext oldcontext;
5086 /* stuff done only on the first call of the function */
5087 if (SRF_IS_FIRSTCALL())
5089 /* create a function context for cross-call persistence */
5090 funcctx = SRF_FIRSTCALL_INIT();
5093 * switch to memory context appropriate for multiple function calls
5095 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
5098 * need a tuple descriptor representing NUM_PG_SETTINGS_ATTS columns
5099 * of the appropriate types
5101 tupdesc = CreateTemplateTupleDesc(NUM_PG_SETTINGS_ATTS, false);
5102 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
5104 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
5106 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "unit",
5108 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "category",
5110 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "short_desc",
5112 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "extra_desc",
5114 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "context",
5116 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "vartype",
5118 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "source",
5120 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "min_val",
5122 TupleDescInitEntry(tupdesc, (AttrNumber) 11, "max_val",
5126 * Generate attribute metadata needed later to produce tuples from raw
5129 attinmeta = TupleDescGetAttInMetadata(tupdesc);
5130 funcctx->attinmeta = attinmeta;
5132 /* total number of tuples to be returned */
5133 funcctx->max_calls = GetNumConfigOptions();
5135 MemoryContextSwitchTo(oldcontext);
5138 /* stuff done on every call of the function */
5139 funcctx = SRF_PERCALL_SETUP();
5141 call_cntr = funcctx->call_cntr;
5142 max_calls = funcctx->max_calls;
5143 attinmeta = funcctx->attinmeta;
5145 if (call_cntr < max_calls) /* do when there is more left to send */
5147 char *values[NUM_PG_SETTINGS_ATTS];
5153 * Get the next visible GUC variable name and value
5157 GetConfigOptionByNum(call_cntr, (const char **) values, &noshow);
5160 /* bump the counter and get the next config setting */
5161 call_cntr = ++funcctx->call_cntr;
5163 /* make sure we haven't gone too far now */
5164 if (call_cntr >= max_calls)
5165 SRF_RETURN_DONE(funcctx);
5170 tuple = BuildTupleFromCStrings(attinmeta, values);
5172 /* make the tuple into a datum */
5173 result = HeapTupleGetDatum(tuple);
5175 SRF_RETURN_NEXT(funcctx, result);
5179 /* do when there is no more left */
5180 SRF_RETURN_DONE(funcctx);
5185 _ShowOption(struct config_generic * record, bool use_units)
5190 switch (record->vartype)
5194 struct config_bool *conf = (struct config_bool *) record;
5196 if (conf->show_hook)
5197 val = (*conf->show_hook) ();
5199 val = *conf->variable ? "on" : "off";
5205 struct config_int *conf = (struct config_int *) record;
5207 if (conf->show_hook)
5208 val = (*conf->show_hook) ();
5212 int result = *conf->variable;
5214 if (use_units && result > 0 && (record->flags & GUC_UNIT_MEMORY))
5216 if (record->flags & GUC_UNIT_BLOCKS)
5217 result *= BLCKSZ/1024;
5219 if (result % KB_PER_GB == 0)
5221 result /= KB_PER_GB;
5224 else if (result % KB_PER_MB == 0)
5226 result /= KB_PER_MB;
5234 else if (use_units && result > 0 && (record->flags & GUC_UNIT_TIME))
5236 if (record->flags & GUC_UNIT_S)
5237 result = result * MS_PER_S;
5238 else if (record->flags & GUC_UNIT_MIN)
5239 result = result * MS_PER_MIN;
5241 if (result % MS_PER_D == 0)
5246 else if (result % MS_PER_H == 0)
5251 else if (result % MS_PER_MIN == 0)
5253 result /= MS_PER_MIN;
5254 strcpy(unit, "min");
5256 else if (result % MS_PER_S == 0)
5269 snprintf(buffer, sizeof(buffer), "%d%s",
5278 struct config_real *conf = (struct config_real *) record;
5280 if (conf->show_hook)
5281 val = (*conf->show_hook) ();
5284 snprintf(buffer, sizeof(buffer), "%g",
5293 struct config_string *conf = (struct config_string *) record;
5295 if (conf->show_hook)
5296 val = (*conf->show_hook) ();
5297 else if (*conf->variable && **conf->variable)
5298 val = *conf->variable;
5305 /* just to keep compiler quiet */
5310 return pstrdup(val);
5315 is_newvalue_equal(struct config_generic *record, const char *newvalue)
5317 switch (record->vartype)
5321 struct config_bool *conf = (struct config_bool *) record;
5324 return parse_bool(newvalue, &newval) && *conf->variable == newval;
5328 struct config_int *conf = (struct config_int *) record;
5331 return parse_int(newvalue, &newval, record->flags) && *conf->variable == newval;
5335 struct config_real *conf = (struct config_real *) record;
5338 return parse_real(newvalue, &newval) && *conf->variable == newval;
5342 struct config_string *conf = (struct config_string *) record;
5344 return strcmp(*conf->variable, newvalue) == 0;
5355 * This routine dumps out all non-default GUC options into a binary
5356 * file that is read by all exec'ed backends. The format is:
5358 * variable name, string, null terminated
5359 * variable value, string, null terminated
5360 * variable source, integer
5363 write_nondefault_variables(GucContext context)
5369 Assert(context == PGC_POSTMASTER || context == PGC_SIGHUP);
5371 elevel = (context == PGC_SIGHUP) ? LOG : ERROR;
5376 fp = AllocateFile(CONFIG_EXEC_PARAMS_NEW, "w");
5380 (errcode_for_file_access(),
5381 errmsg("could not write to file \"%s\": %m",
5382 CONFIG_EXEC_PARAMS_NEW)));
5386 for (i = 0; i < num_guc_variables; i++)
5388 struct config_generic *gconf = guc_variables[i];
5390 if (gconf->source != PGC_S_DEFAULT)
5392 fprintf(fp, "%s", gconf->name);
5395 switch (gconf->vartype)
5399 struct config_bool *conf = (struct config_bool *) gconf;
5401 if (*conf->variable == 0)
5402 fprintf(fp, "false");
5404 fprintf(fp, "true");
5410 struct config_int *conf = (struct config_int *) gconf;
5412 fprintf(fp, "%d", *conf->variable);
5418 struct config_real *conf = (struct config_real *) gconf;
5420 /* Could lose precision here? */
5421 fprintf(fp, "%f", *conf->variable);
5427 struct config_string *conf = (struct config_string *) gconf;
5429 fprintf(fp, "%s", *conf->variable);
5436 fwrite(&gconf->source, sizeof(gconf->source), 1, fp);
5443 (errcode_for_file_access(),
5444 errmsg("could not write to file \"%s\": %m",
5445 CONFIG_EXEC_PARAMS_NEW)));
5450 * Put new file in place. This could delay on Win32, but we don't hold
5451 * any exclusive locks.
5453 rename(CONFIG_EXEC_PARAMS_NEW, CONFIG_EXEC_PARAMS);
5458 * Read string, including null byte from file
5460 * Return NULL on EOF and nothing read
5463 read_string_with_null(FILE *fp)
5472 if ((ch = fgetc(fp)) == EOF)
5477 elog(FATAL, "invalid format of exec config params file");
5480 str = guc_malloc(FATAL, maxlen);
5481 else if (i == maxlen)
5482 str = guc_realloc(FATAL, str, maxlen *= 2);
5491 * This routine loads a previous postmaster dump of its non-default
5495 read_nondefault_variables(void)
5505 fp = AllocateFile(CONFIG_EXEC_PARAMS, "r");
5508 /* File not found is fine */
5509 if (errno != ENOENT)
5511 (errcode_for_file_access(),
5512 errmsg("could not read from file \"%s\": %m",
5513 CONFIG_EXEC_PARAMS)));
5519 struct config_generic *record;
5521 if ((varname = read_string_with_null(fp)) == NULL)
5524 if ((record = find_option(varname, FATAL)) == NULL)
5525 elog(FATAL, "failed to locate variable %s in exec config params file", varname);
5526 if ((varvalue = read_string_with_null(fp)) == NULL)
5527 elog(FATAL, "invalid format of exec config params file");
5528 if (fread(&varsource, sizeof(varsource), 1, fp) == 0)
5529 elog(FATAL, "invalid format of exec config params file");
5531 (void) set_config_option(varname, varvalue, record->context,
5532 varsource, false, true);
5539 #endif /* EXEC_BACKEND */
5543 * A little "long argument" simulation, although not quite GNU
5544 * compliant. Takes a string of the form "some-option=some value" and
5545 * returns name = "some_option" and value = "some value" in malloc'ed
5546 * storage. Note that '-' is converted to '_' in the option name. If
5547 * there is no '=' in the input string then value will be NULL.
5550 ParseLongOption(const char *string, char **name, char **value)
5559 equal_pos = strcspn(string, "=");
5561 if (string[equal_pos] == '=')
5563 *name = guc_malloc(FATAL, equal_pos + 1);
5564 strncpy(*name, string, equal_pos);
5565 (*name)[equal_pos] = '\0';
5567 *value = guc_strdup(FATAL, &string[equal_pos + 1]);
5571 /* no equal sign in string */
5572 *name = guc_strdup(FATAL, string);
5576 for (cp = *name; *cp; cp++)
5583 * Handle options fetched from pg_database.datconfig or pg_authid.rolconfig.
5584 * The array parameter must be an array of TEXT (it must not be NULL).
5587 ProcessGUCArray(ArrayType *array, GucSource source)
5591 Assert(array != NULL);
5592 Assert(ARR_ELEMTYPE(array) == TEXTOID);
5593 Assert(ARR_NDIM(array) == 1);
5594 Assert(ARR_LBOUND(array)[0] == 1);
5595 Assert(source == PGC_S_DATABASE || source == PGC_S_USER);
5597 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
5605 d = array_ref(array, 1, &i,
5606 -1 /* varlenarray */ ,
5607 -1 /* TEXT's typlen */ ,
5608 false /* TEXT's typbyval */ ,
5609 'i' /* TEXT's typalign */ ,
5615 s = DatumGetCString(DirectFunctionCall1(textout, d));
5617 ParseLongOption(s, &name, &value);
5621 (errcode(ERRCODE_SYNTAX_ERROR),
5622 errmsg("could not parse setting for parameter \"%s\"", name)));
5628 * We process all these options at SUSET level. We assume that the
5629 * right to insert an option into pg_database or pg_authid was checked
5630 * when it was inserted.
5632 SetConfigOption(name, value, PGC_SUSET, source);
5642 * Add an entry to an option array. The array parameter may be NULL
5643 * to indicate the current table entry is NULL.
5646 GUCArrayAdd(ArrayType *array, const char *name, const char *value)
5648 const char *varname;
5656 /* test if the option is valid */
5657 set_config_option(name, value,
5658 superuser() ? PGC_SUSET : PGC_USERSET,
5659 PGC_S_TEST, false, false);
5661 /* convert name to canonical spelling, so we can use plain strcmp */
5662 (void) GetConfigOptionByName(name, &varname);
5665 newval = palloc(strlen(name) + 1 + strlen(value) + 1);
5666 sprintf(newval, "%s=%s", name, value);
5667 datum = DirectFunctionCall1(textin, CStringGetDatum(newval));
5675 Assert(ARR_ELEMTYPE(array) == TEXTOID);
5676 Assert(ARR_NDIM(array) == 1);
5677 Assert(ARR_LBOUND(array)[0] == 1);
5679 index = ARR_DIMS(array)[0] + 1; /* add after end */
5681 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
5686 d = array_ref(array, 1, &i,
5687 -1 /* varlenarray */ ,
5688 -1 /* TEXT's typlen */ ,
5689 false /* TEXT's typbyval */ ,
5690 'i' /* TEXT's typalign */ ,
5694 current = DatumGetCString(DirectFunctionCall1(textout, d));
5695 if (strncmp(current, newval, strlen(name) + 1) == 0)
5702 a = array_set(array, 1, &index,
5705 -1 /* varlena array */ ,
5706 -1 /* TEXT's typlen */ ,
5707 false /* TEXT's typbyval */ ,
5708 'i' /* TEXT's typalign */ );
5711 a = construct_array(&datum, 1,
5720 * Delete an entry from an option array. The array parameter may be NULL
5721 * to indicate the current table entry is NULL. Also, if the return value
5722 * is NULL then a null should be stored.
5725 GUCArrayDelete(ArrayType *array, const char *name)
5727 const char *varname;
5728 ArrayType *newarray;
5734 /* test if the option is valid */
5735 set_config_option(name, NULL,
5736 superuser() ? PGC_SUSET : PGC_USERSET,
5737 PGC_S_TEST, false, false);
5739 /* convert name to canonical spelling, so we can use plain strcmp */
5740 (void) GetConfigOptionByName(name, &varname);
5743 /* if array is currently null, then surely nothing to delete */
5750 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
5756 d = array_ref(array, 1, &i,
5757 -1 /* varlenarray */ ,
5758 -1 /* TEXT's typlen */ ,
5759 false /* TEXT's typbyval */ ,
5760 'i' /* TEXT's typalign */ ,
5764 val = DatumGetCString(DirectFunctionCall1(textout, d));
5766 /* ignore entry if it's what we want to delete */
5767 if (strncmp(val, name, strlen(name)) == 0
5768 && val[strlen(name)] == '=')
5771 /* else add it to the output array */
5774 newarray = array_set(newarray, 1, &index,
5777 -1 /* varlenarray */ ,
5778 -1 /* TEXT's typlen */ ,
5779 false /* TEXT's typbyval */ ,
5780 'i' /* TEXT's typalign */ );
5783 newarray = construct_array(&d, 1,
5795 * assign_hook subroutines
5799 assign_log_destination(const char *value, bool doit, GucSource source)
5806 /* Need a modifiable copy of string */
5807 rawstring = pstrdup(value);
5809 /* Parse string into list of identifiers */
5810 if (!SplitIdentifierString(rawstring, ',', &elemlist))
5812 /* syntax error in list */
5814 list_free(elemlist);
5815 if (source >= PGC_S_INTERACTIVE)
5817 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5818 errmsg("invalid list syntax for parameter \"log_destination\"")));
5822 foreach(l, elemlist)
5824 char *tok = (char *) lfirst(l);
5826 if (pg_strcasecmp(tok, "stderr") == 0)
5827 newlogdest |= LOG_DESTINATION_STDERR;
5829 else if (pg_strcasecmp(tok, "syslog") == 0)
5830 newlogdest |= LOG_DESTINATION_SYSLOG;
5833 else if (pg_strcasecmp(tok, "eventlog") == 0)
5834 newlogdest |= LOG_DESTINATION_EVENTLOG;
5838 if (source >= PGC_S_INTERACTIVE)
5840 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5841 errmsg("unrecognized \"log_destination\" key word: \"%s\"",
5844 list_free(elemlist);
5850 Log_destination = newlogdest;
5853 list_free(elemlist);
5861 assign_syslog_facility(const char *facility, bool doit, GucSource source)
5865 if (pg_strcasecmp(facility, "LOCAL0") == 0)
5866 syslog_fac = LOG_LOCAL0;
5867 else if (pg_strcasecmp(facility, "LOCAL1") == 0)
5868 syslog_fac = LOG_LOCAL1;
5869 else if (pg_strcasecmp(facility, "LOCAL2") == 0)
5870 syslog_fac = LOG_LOCAL2;
5871 else if (pg_strcasecmp(facility, "LOCAL3") == 0)
5872 syslog_fac = LOG_LOCAL3;
5873 else if (pg_strcasecmp(facility, "LOCAL4") == 0)
5874 syslog_fac = LOG_LOCAL4;
5875 else if (pg_strcasecmp(facility, "LOCAL5") == 0)
5876 syslog_fac = LOG_LOCAL5;
5877 else if (pg_strcasecmp(facility, "LOCAL6") == 0)
5878 syslog_fac = LOG_LOCAL6;
5879 else if (pg_strcasecmp(facility, "LOCAL7") == 0)
5880 syslog_fac = LOG_LOCAL7;
5882 return NULL; /* reject */
5886 syslog_facility = syslog_fac;
5887 set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
5895 assign_syslog_ident(const char *ident, bool doit, GucSource source)
5898 set_syslog_parameters(ident, syslog_facility);
5902 #endif /* HAVE_SYSLOG */
5906 assign_defaultxactisolevel(const char *newval, bool doit, GucSource source)
5908 if (pg_strcasecmp(newval, "serializable") == 0)
5911 DefaultXactIsoLevel = XACT_SERIALIZABLE;
5913 else if (pg_strcasecmp(newval, "repeatable read") == 0)
5916 DefaultXactIsoLevel = XACT_REPEATABLE_READ;
5918 else if (pg_strcasecmp(newval, "read committed") == 0)
5921 DefaultXactIsoLevel = XACT_READ_COMMITTED;
5923 else if (pg_strcasecmp(newval, "read uncommitted") == 0)
5926 DefaultXactIsoLevel = XACT_READ_UNCOMMITTED;
5934 assign_log_min_messages(const char *newval,
5935 bool doit, GucSource source)
5937 return (assign_msglvl(&log_min_messages, newval, doit, source));
5941 assign_client_min_messages(const char *newval, bool doit, GucSource source)
5943 return (assign_msglvl(&client_min_messages, newval, doit, source));
5947 assign_min_error_statement(const char *newval, bool doit, GucSource source)
5949 return (assign_msglvl(&log_min_error_statement, newval, doit, source));
5953 assign_msglvl(int *var, const char *newval, bool doit, GucSource source)
5955 if (pg_strcasecmp(newval, "debug") == 0)
5960 else if (pg_strcasecmp(newval, "debug5") == 0)
5965 else if (pg_strcasecmp(newval, "debug4") == 0)
5970 else if (pg_strcasecmp(newval, "debug3") == 0)
5975 else if (pg_strcasecmp(newval, "debug2") == 0)
5980 else if (pg_strcasecmp(newval, "debug1") == 0)
5985 else if (pg_strcasecmp(newval, "log") == 0)
5992 * Client_min_messages always prints 'info', but we allow it as a value
5995 else if (pg_strcasecmp(newval, "info") == 0)
6000 else if (pg_strcasecmp(newval, "notice") == 0)
6005 else if (pg_strcasecmp(newval, "warning") == 0)
6010 else if (pg_strcasecmp(newval, "error") == 0)
6015 /* We allow FATAL/PANIC for client-side messages too. */
6016 else if (pg_strcasecmp(newval, "fatal") == 0)
6021 else if (pg_strcasecmp(newval, "panic") == 0)
6027 return NULL; /* fail */
6028 return newval; /* OK */
6032 assign_log_error_verbosity(const char *newval, bool doit, GucSource source)
6034 if (pg_strcasecmp(newval, "terse") == 0)
6037 Log_error_verbosity = PGERROR_TERSE;
6039 else if (pg_strcasecmp(newval, "default") == 0)
6042 Log_error_verbosity = PGERROR_DEFAULT;
6044 else if (pg_strcasecmp(newval, "verbose") == 0)
6047 Log_error_verbosity = PGERROR_VERBOSE;
6050 return NULL; /* fail */
6051 return newval; /* OK */
6055 assign_log_statement(const char *newval, bool doit, GucSource source)
6057 if (pg_strcasecmp(newval, "none") == 0)
6060 log_statement = LOGSTMT_NONE;
6062 else if (pg_strcasecmp(newval, "ddl") == 0)
6065 log_statement = LOGSTMT_DDL;
6067 else if (pg_strcasecmp(newval, "mod") == 0)
6070 log_statement = LOGSTMT_MOD;
6072 else if (pg_strcasecmp(newval, "all") == 0)
6075 log_statement = LOGSTMT_ALL;
6078 return NULL; /* fail */
6079 return newval; /* OK */
6083 show_num_temp_buffers(void)
6086 * We show the GUC var until local buffers have been initialized, and
6087 * NLocBuffer afterwards.
6089 static char nbuf[32];
6091 sprintf(nbuf, "%d", NLocBuffer ? NLocBuffer : num_temp_buffers);
6096 assign_phony_autocommit(bool newval, bool doit, GucSource source)
6100 if (doit && source >= PGC_S_INTERACTIVE)
6102 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6103 errmsg("SET AUTOCOMMIT TO OFF is no longer supported")));
6110 assign_custom_variable_classes(const char *newval, bool doit, GucSource source)
6113 * Check syntax. newval must be a comma separated list of identifiers.
6114 * Whitespace is allowed but skipped.
6116 bool hasSpaceAfterToken = false;
6117 const char *cp = newval;
6122 initStringInfo(&buf);
6123 while ((c = *cp++) != 0)
6128 hasSpaceAfterToken = true;
6134 hasSpaceAfterToken = false;
6138 appendStringInfoChar(&buf, ',');
6143 if (hasSpaceAfterToken || !isalnum(c))
6146 * Syntax error due to token following space after token or non
6147 * alpha numeric character
6150 (errcode(ERRCODE_SYNTAX_ERROR),
6151 errmsg("invalid syntax for \"custom_variable_classes\": \"%s\"", newval)));
6156 appendStringInfoChar(&buf, (char) c);
6159 /* Remove stray ',' at end */
6160 if (symLen == 0 && buf.len > 0)
6161 buf.data[--buf.len] = '\0';
6166 newval = strdup(buf.data);
6173 assign_debug_assertions(bool newval, bool doit, GucSource source)
6175 #ifndef USE_ASSERT_CHECKING
6178 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6179 errmsg("assertion checking is not supported by this build")));
6185 assign_ssl(bool newval, bool doit, GucSource source)
6190 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6191 errmsg("SSL is not supported by this build")));
6197 assign_stage_log_stats(bool newval, bool doit, GucSource source)
6199 if (newval && log_statement_stats)
6201 if (source >= PGC_S_INTERACTIVE)
6203 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6204 errmsg("cannot enable parameter when \"log_statement_stats\" is true")));
6205 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
6206 else if (source != PGC_S_OVERRIDE)
6213 assign_log_stats(bool newval, bool doit, GucSource source)
6216 (log_parser_stats || log_planner_stats || log_executor_stats))
6218 if (source >= PGC_S_INTERACTIVE)
6220 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6221 errmsg("cannot enable \"log_statement_stats\" when "
6222 "\"log_parser_stats\", \"log_planner_stats\", "
6223 "or \"log_executor_stats\" is true")));
6224 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
6225 else if (source != PGC_S_OVERRIDE)
6232 assign_transaction_read_only(bool newval, bool doit, GucSource source)
6234 /* Can't go to r/w mode inside a r/o transaction */
6235 if (newval == false && XactReadOnly && IsSubTransaction())
6237 if (source >= PGC_S_INTERACTIVE)
6239 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6240 errmsg("cannot set transaction read-write mode inside a read-only transaction")));
6241 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
6242 else if (source != PGC_S_OVERRIDE)
6249 assign_canonical_path(const char *newval, bool doit, GucSource source)
6253 char *canon_val = guc_strdup(ERROR, newval);
6255 canonicalize_path(canon_val);
6263 assign_backslash_quote(const char *newval, bool doit, GucSource source)
6265 BackslashQuoteType bq;
6269 * Although only "on", "off", and "safe_encoding" are documented,
6270 * we use parse_bool so we can accept all the likely variants of
6273 if (pg_strcasecmp(newval, "safe_encoding") == 0)
6274 bq = BACKSLASH_QUOTE_SAFE_ENCODING;
6275 else if (parse_bool(newval, &bqbool))
6277 bq = bqbool ? BACKSLASH_QUOTE_ON : BACKSLASH_QUOTE_OFF;
6280 return NULL; /* reject */
6283 backslash_quote = bq;
6289 assign_timezone_abbreviations(const char *newval, bool doit, GucSource source)
6291 /* Loading abbrev file is expensive, so only do it when value changes */
6292 if (timezone_abbreviations == NULL ||
6293 strcmp(timezone_abbreviations, newval) != 0)
6298 * If reading config file, only the postmaster should bleat loudly
6299 * about problems. Otherwise, it's just this one process doing it,
6300 * and we use WARNING message level.
6302 if (source == PGC_S_FILE)
6303 elevel = IsUnderPostmaster ? DEBUG2 : LOG;
6306 if (!load_tzoffsets(newval, doit, elevel))
6313 assign_tcp_keepalives_idle(int newval, bool doit, GucSource source)
6316 return (pq_setkeepalivesidle(newval, MyProcPort) == STATUS_OK);
6322 show_tcp_keepalives_idle(void)
6324 static char nbuf[16];
6326 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesidle(MyProcPort));
6331 assign_tcp_keepalives_interval(int newval, bool doit, GucSource source)
6334 return (pq_setkeepalivesinterval(newval, MyProcPort) == STATUS_OK);
6340 show_tcp_keepalives_interval(void)
6342 static char nbuf[16];
6344 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesinterval(MyProcPort));
6349 assign_tcp_keepalives_count(int newval, bool doit, GucSource source)
6352 return (pq_setkeepalivescount(newval, MyProcPort) == STATUS_OK);
6358 show_tcp_keepalives_count(void)
6360 static char nbuf[16];
6362 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivescount(MyProcPort));
6367 #include "guc-file.c"