1 /*--------------------------------------------------------------------
4 * Support for grand unified configuration scheme, including SET
5 * command, configuration file, and command line options.
6 * See src/backend/utils/misc/README for more information.
9 * Copyright (c) 2000-2005, PostgreSQL Global Development Group
10 * Written by Peter Eisentraut <peter_e@gmx.net>.
13 * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.266 2005/06/14 20:42:53 momjian Exp $
15 *--------------------------------------------------------------------
25 #include "utils/guc.h"
26 #include "utils/guc_tables.h"
28 #include "catalog/namespace.h"
29 #include "catalog/pg_type.h"
30 #include "commands/async.h"
31 #include "commands/variable.h"
32 #include "commands/vacuum.h"
33 #include "executor/executor.h"
36 #include "libpq/auth.h"
37 #include "libpq/pqcomm.h"
38 #include "libpq/pqformat.h"
39 #include "mb/pg_wchar.h"
40 #include "miscadmin.h"
41 #include "optimizer/cost.h"
42 #include "optimizer/geqo.h"
43 #include "optimizer/paths.h"
44 #include "optimizer/prep.h"
45 #include "parser/parse_expr.h"
46 #include "parser/parse_relation.h"
47 #include "postmaster/bgwriter.h"
48 #include "postmaster/syslogger.h"
49 #include "postmaster/postmaster.h"
50 #include "storage/bufmgr.h"
51 #include "storage/fd.h"
52 #include "storage/freespace.h"
53 #include "storage/lock.h"
54 #include "storage/proc.h"
55 #include "tcop/tcopprot.h"
56 #include "utils/array.h"
57 #include "utils/builtins.h"
58 #include "utils/memutils.h"
59 #include "utils/pg_locale.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"
78 /* XXX these should appear in other modules' header files */
79 extern bool Log_disconnections;
80 extern DLLIMPORT bool check_function_bodies;
81 extern int CommitDelay;
82 extern int CommitSiblings;
83 extern char *default_tablespace;
85 static const char *assign_log_destination(const char *value,
86 bool doit, GucSource source);
89 extern char *Syslog_facility;
90 extern char *Syslog_ident;
92 static const char *assign_facility(const char *facility,
93 bool doit, GucSource source);
96 static const char *assign_defaultxactisolevel(const char *newval, bool doit,
98 static const char *assign_log_min_messages(const char *newval, bool doit,
100 static const char *assign_client_min_messages(const char *newval,
101 bool doit, GucSource source);
102 static const char *assign_min_error_statement(const char *newval, bool doit,
104 static const char *assign_msglvl(int *var, const char *newval, bool doit,
106 static const char *assign_log_error_verbosity(const char *newval, bool doit,
108 static const char *assign_log_statement(const char *newval, bool doit,
110 static const char *show_num_temp_buffers(void);
111 static bool assign_phony_autocommit(bool newval, bool doit, GucSource source);
112 static const char *assign_custom_variable_classes(const char *newval, bool doit,
114 static bool assign_stage_log_stats(bool newval, bool doit, GucSource source);
115 static bool assign_log_stats(bool newval, bool doit, GucSource source);
116 static bool assign_transaction_read_only(bool newval, bool doit, GucSource source);
117 static const char *assign_canonical_path(const char *newval, bool doit, GucSource source);
121 * GUC option variables that are exported from this module
123 #ifdef USE_ASSERT_CHECKING
124 bool assert_enabled = true;
126 bool log_duration = false;
127 bool Debug_print_plan = false;
128 bool Debug_print_parse = false;
129 bool Debug_print_rewritten = false;
130 bool Debug_pretty_print = false;
131 bool Explain_pretty_print = true;
133 bool log_parser_stats = false;
134 bool log_planner_stats = false;
135 bool log_executor_stats = false;
136 bool log_statement_stats = false; /* this is sort of all
137 * three above together */
138 bool log_btree_build_stats = false;
140 bool SQL_inheritance = true;
142 bool Australian_timezones = false;
144 bool Password_encryption = true;
146 bool default_with_oids = false;
148 int log_min_error_statement = PANIC;
149 int log_min_messages = NOTICE;
150 int client_min_messages = NOTICE;
151 int log_min_duration_statement = -1;
153 int num_temp_buffers = 1000;
155 char *ConfigFileName;
158 char *external_pid_file;
162 * These variables are all dummies that don't do anything, except in some
163 * cases provide the value for SHOW to display. The real state is elsewhere
164 * and is kept in sync by assign_hooks.
166 static char *client_min_messages_str;
167 static char *log_min_messages_str;
168 static char *log_error_verbosity_str;
169 static char *log_statement_str;
170 static char *log_min_error_statement_str;
171 static char *log_destination_string;
172 static bool phony_autocommit;
173 static bool session_auth_is_superuser;
174 static double phony_random_seed;
175 static char *client_encoding_string;
176 static char *datestyle_string;
177 static char *default_iso_level_string;
178 static char *locale_collate;
179 static char *locale_ctype;
180 static char *regex_flavor_string;
181 static char *server_encoding_string;
182 static char *server_version_string;
183 static char *timezone_string;
184 static char *XactIsoLevel_string;
185 static char *data_directory;
186 static char *custom_variable_classes;
187 static int max_function_args;
188 static int max_index_keys;
189 static int max_identifier_length;
190 static int block_size;
191 static bool integer_datetimes;
193 /* should be static, but commands/variable.c needs to get at it */
194 char *session_authorization_string;
198 * Displayable names for context types (enum GucContext)
200 * Note: these strings are deliberately not localized.
202 const char *const GucContext_Names[] =
204 /* PGC_INTERNAL */ "internal",
205 /* PGC_POSTMASTER */ "postmaster",
206 /* PGC_SIGHUP */ "sighup",
207 /* PGC_BACKEND */ "backend",
208 /* PGC_SUSET */ "superuser",
209 /* PGC_USERSET */ "user"
213 * Displayable names for source types (enum GucSource)
215 * Note: these strings are deliberately not localized.
217 const char *const GucSource_Names[] =
219 /* PGC_S_DEFAULT */ "default",
220 /* PGC_S_ENV_VAR */ "environment variable",
221 /* PGC_S_FILE */ "configuration file",
222 /* PGC_S_ARGV */ "command line",
223 /* PGC_S_DATABASE */ "database",
224 /* PGC_S_USER */ "user",
225 /* PGC_S_CLIENT */ "client",
226 /* PGC_S_OVERRIDE */ "override",
227 /* PGC_S_INTERACTIVE */ "interactive",
228 /* PGC_S_TEST */ "test",
229 /* PGC_S_SESSION */ "session"
233 * Displayable names for the groupings defined in enum config_group
235 const char *const config_group_names[] =
238 gettext_noop("Ungrouped"),
240 gettext_noop("File Locations"),
242 gettext_noop("Connections and Authentication"),
243 /* CONN_AUTH_SETTINGS */
244 gettext_noop("Connections and Authentication / Connection Settings"),
245 /* CONN_AUTH_SECURITY */
246 gettext_noop("Connections and Authentication / Security and Authentication"),
248 gettext_noop("Resource Usage"),
250 gettext_noop("Resource Usage / Memory"),
252 gettext_noop("Resource Usage / Free Space Map"),
253 /* RESOURCES_KERNEL */
254 gettext_noop("Resource Usage / Kernel Resources"),
256 gettext_noop("Write-Ahead Log"),
258 gettext_noop("Write-Ahead Log / Settings"),
259 /* WAL_CHECKPOINTS */
260 gettext_noop("Write-Ahead Log / Checkpoints"),
262 gettext_noop("Query Tuning"),
263 /* QUERY_TUNING_METHOD */
264 gettext_noop("Query Tuning / Planner Method Configuration"),
265 /* QUERY_TUNING_COST */
266 gettext_noop("Query Tuning / Planner Cost Constants"),
267 /* QUERY_TUNING_GEQO */
268 gettext_noop("Query Tuning / Genetic Query Optimizer"),
269 /* QUERY_TUNING_OTHER */
270 gettext_noop("Query Tuning / Other Planner Options"),
272 gettext_noop("Reporting and Logging"),
274 gettext_noop("Reporting and Logging / Where to Log"),
276 gettext_noop("Reporting and Logging / When to Log"),
278 gettext_noop("Reporting and Logging / What to Log"),
280 gettext_noop("Statistics"),
281 /* STATS_MONITORING */
282 gettext_noop("Statistics / Monitoring"),
283 /* STATS_COLLECTOR */
284 gettext_noop("Statistics / Query and Index Statistics Collector"),
286 gettext_noop("Client Connection Defaults"),
287 /* CLIENT_CONN_STATEMENT */
288 gettext_noop("Client Connection Defaults / Statement Behavior"),
289 /* CLIENT_CONN_LOCALE */
290 gettext_noop("Client Connection Defaults / Locale and Formatting"),
291 /* CLIENT_CONN_OTHER */
292 gettext_noop("Client Connection Defaults / Other Defaults"),
293 /* LOCK_MANAGEMENT */
294 gettext_noop("Lock Management"),
296 gettext_noop("Version and Platform Compatibility"),
297 /* COMPAT_OPTIONS_PREVIOUS */
298 gettext_noop("Version and Platform Compatibility / Previous PostgreSQL Versions"),
299 /* COMPAT_OPTIONS_CLIENT */
300 gettext_noop("Version and Platform Compatibility / Other Platforms and Clients"),
302 gettext_noop("Preset Options"),
304 gettext_noop("Customized Options"),
305 /* DEVELOPER_OPTIONS */
306 gettext_noop("Developer Options"),
307 /* help_config wants this array to be null-terminated */
312 * Displayable names for GUC variable types (enum config_type)
314 * Note: these strings are deliberately not localized.
316 const char *const config_type_names[] =
318 /* PGC_BOOL */ "bool",
319 /* PGC_INT */ "integer",
320 /* PGC_REAL */ "real",
321 /* PGC_STRING */ "string"
326 * Contents of GUC tables
328 * See src/backend/utils/misc/README for design notes.
332 * 1. Declare a global variable of type bool, int, double, or char*
333 * and make use of it.
335 * 2. Decide at what times it's safe to set the option. See guc.h for
338 * 3. Decide on a name, a default value, upper and lower bounds (if
341 * 4. Add a record below.
343 * 5. Add it to src/backend/utils/misc/postgresql.conf.sample, if
346 * 6. Add it to src/bin/psql/tab-complete.c, if it's a USERSET option.
348 * 7. Don't forget to document the option.
350 * 8. If it's a new GUC_LIST option you must edit pg_dumpall.c to ensure
351 * it is not single quoted at dump time.
355 /******** option records follow ********/
357 static struct config_bool ConfigureNamesBool[] =
360 {"enable_seqscan", PGC_USERSET, QUERY_TUNING_METHOD,
361 gettext_noop("Enables the planner's use of sequential-scan plans."),
368 {"enable_indexscan", PGC_USERSET, QUERY_TUNING_METHOD,
369 gettext_noop("Enables the planner's use of index-scan plans."),
376 {"enable_bitmapscan", PGC_USERSET, QUERY_TUNING_METHOD,
377 gettext_noop("Enables the planner's use of bitmap-scan plans."),
384 {"enable_tidscan", PGC_USERSET, QUERY_TUNING_METHOD,
385 gettext_noop("Enables the planner's use of TID scan plans."),
392 {"enable_sort", PGC_USERSET, QUERY_TUNING_METHOD,
393 gettext_noop("Enables the planner's use of explicit sort steps."),
400 {"enable_hashagg", PGC_USERSET, QUERY_TUNING_METHOD,
401 gettext_noop("Enables the planner's use of hashed aggregation plans."),
408 {"enable_nestloop", PGC_USERSET, QUERY_TUNING_METHOD,
409 gettext_noop("Enables the planner's use of nested-loop join plans."),
416 {"enable_mergejoin", PGC_USERSET, QUERY_TUNING_METHOD,
417 gettext_noop("Enables the planner's use of merge join plans."),
424 {"enable_hashjoin", PGC_USERSET, QUERY_TUNING_METHOD,
425 gettext_noop("Enables the planner's use of hash join plans."),
432 {"geqo", PGC_USERSET, QUERY_TUNING_GEQO,
433 gettext_noop("Enables genetic query optimization."),
434 gettext_noop("This algorithm attempts to do planning without "
435 "exhaustive searching.")
441 /* Not for general use --- used by SET SESSION AUTHORIZATION */
442 {"is_superuser", PGC_INTERNAL, UNGROUPED,
443 gettext_noop("Shows whether the current user is a superuser."),
445 GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
447 &session_auth_is_superuser,
451 {"ssl", PGC_POSTMASTER, CONN_AUTH_SECURITY,
452 gettext_noop("Enables SSL connections."),
459 {"fsync", PGC_SIGHUP, WAL_SETTINGS,
460 gettext_noop("Forces synchronization of updates to disk."),
461 gettext_noop("The server will use the fsync() system call in several places to make "
462 "sure that updates are physically written to disk. This insures "
463 "that a database cluster will recover to a consistent state after "
464 "an operating system or hardware crash.")
470 {"zero_damaged_pages", PGC_SUSET, DEVELOPER_OPTIONS,
471 gettext_noop("Continues processing past damaged page headers."),
472 gettext_noop("Detection of a damaged page header normally causes PostgreSQL to "
473 "report an error, aborting the current transaction. Setting "
474 "zero_damaged_pages to true causes the system to instead report a "
475 "warning, zero out the damaged page, and continue processing. This "
476 "behavior will destroy data, namely all the rows on the damaged page."),
483 {"silent_mode", PGC_POSTMASTER, LOGGING_WHEN,
484 gettext_noop("Runs the server silently."),
485 gettext_noop("If this parameter is set, the server will automatically run in the "
486 "background and any controlling terminals are dissociated.")
492 {"log_connections", PGC_BACKEND, LOGGING_WHAT,
493 gettext_noop("Logs each successful connection."),
500 {"log_disconnections", PGC_BACKEND, LOGGING_WHAT,
501 gettext_noop("Logs end of a session, including duration."),
508 #ifdef USE_ASSERT_CHECKING
510 {"debug_assertions", PGC_USERSET, DEVELOPER_OPTIONS,
511 gettext_noop("Turns on various assertion checks."),
512 gettext_noop("This is a debugging aid."),
521 /* currently undocumented, so don't show in SHOW ALL */
522 {"exit_on_error", PGC_USERSET, UNGROUPED,
523 gettext_noop("no description available"),
525 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
531 {"log_duration", PGC_SUSET, LOGGING_WHAT,
532 gettext_noop("Logs the duration of each completed SQL statement."),
539 {"debug_print_parse", PGC_USERSET, LOGGING_WHAT,
540 gettext_noop("Prints the parse tree to the server log."),
547 {"debug_print_rewritten", PGC_USERSET, LOGGING_WHAT,
548 gettext_noop("Prints the parse tree after rewriting to server log."),
551 &Debug_print_rewritten,
555 {"debug_print_plan", PGC_USERSET, LOGGING_WHAT,
556 gettext_noop("Prints the execution plan to server log."),
563 {"debug_pretty_print", PGC_USERSET, LOGGING_WHAT,
564 gettext_noop("Indents parse and plan tree displays."),
571 {"log_parser_stats", PGC_SUSET, STATS_MONITORING,
572 gettext_noop("Writes parser performance statistics to the server log."),
576 false, assign_stage_log_stats, NULL
579 {"log_planner_stats", PGC_SUSET, STATS_MONITORING,
580 gettext_noop("Writes planner performance statistics to the server log."),
584 false, assign_stage_log_stats, NULL
587 {"log_executor_stats", PGC_SUSET, STATS_MONITORING,
588 gettext_noop("Writes executor performance statistics to the server log."),
592 false, assign_stage_log_stats, NULL
595 {"log_statement_stats", PGC_SUSET, STATS_MONITORING,
596 gettext_noop("Writes cumulative performance statistics to the server log."),
599 &log_statement_stats,
600 false, assign_log_stats, NULL
602 #ifdef BTREE_BUILD_STATS
604 {"log_btree_build_stats", PGC_SUSET, DEVELOPER_OPTIONS,
605 gettext_noop("no description available"),
609 &log_btree_build_stats,
615 {"explain_pretty_print", PGC_USERSET, CLIENT_CONN_OTHER,
616 gettext_noop("Uses the indented output format for EXPLAIN VERBOSE."),
619 &Explain_pretty_print,
623 {"stats_start_collector", PGC_POSTMASTER, STATS_COLLECTOR,
624 gettext_noop("Starts the server statistics-collection subprocess."),
627 &pgstat_collect_startcollector,
631 {"stats_reset_on_server_start", PGC_POSTMASTER, STATS_COLLECTOR,
632 gettext_noop("Zeroes collected statistics on server restart."),
635 &pgstat_collect_resetonpmstart,
639 {"stats_command_string", PGC_SUSET, STATS_COLLECTOR,
640 gettext_noop("Collects statistics about executing commands."),
641 gettext_noop("Enables the collection of statistics on the currently "
642 "executing command of each session, along with the time "
643 "at which that command began execution.")
645 &pgstat_collect_querystring,
649 {"stats_row_level", PGC_SUSET, STATS_COLLECTOR,
650 gettext_noop("Collects row-level statistics on database activity."),
653 &pgstat_collect_tuplelevel,
657 {"stats_block_level", PGC_SUSET, STATS_COLLECTOR,
658 gettext_noop("Collects block-level statistics on database activity."),
661 &pgstat_collect_blocklevel,
666 {"trace_notify", PGC_USERSET, DEVELOPER_OPTIONS,
667 gettext_noop("Generates debugging output for LISTEN and NOTIFY."),
677 {"trace_locks", PGC_SUSET, DEVELOPER_OPTIONS,
678 gettext_noop("no description available"),
686 {"trace_userlocks", PGC_SUSET, DEVELOPER_OPTIONS,
687 gettext_noop("no description available"),
695 {"trace_lwlocks", PGC_SUSET, DEVELOPER_OPTIONS,
696 gettext_noop("no description available"),
704 {"debug_deadlocks", PGC_SUSET, DEVELOPER_OPTIONS,
705 gettext_noop("no description available"),
715 {"log_hostname", PGC_SIGHUP, LOGGING_WHAT,
716 gettext_noop("Logs the host name in the connection logs."),
717 gettext_noop("By default, connection logs only show the IP address "
718 "of the connecting host. If you want them to show the host name you "
719 "can turn this on, but depending on your host name resolution "
720 "setup it might impose a non-negligible performance penalty.")
726 {"sql_inheritance", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
727 gettext_noop("Causes subtables to be included by default in various commands."),
734 {"australian_timezones", PGC_USERSET, CLIENT_CONN_LOCALE,
735 gettext_noop("Interprets ACST, CST, EST, and SAT as Australian time zones."),
736 gettext_noop("Otherwise they are interpreted as North/South American "
737 "time zones and Saturday.")
739 &Australian_timezones,
740 false, ClearDateCache, NULL
743 {"password_encryption", PGC_USERSET, CONN_AUTH_SECURITY,
744 gettext_noop("Encrypt passwords."),
745 gettext_noop("When a password is specified in CREATE USER or "
746 "ALTER USER without writing either ENCRYPTED or UNENCRYPTED, "
747 "this parameter determines whether the password is to be encrypted.")
749 &Password_encryption,
753 {"transform_null_equals", PGC_USERSET, COMPAT_OPTIONS_CLIENT,
754 gettext_noop("Treats \"expr=NULL\" as \"expr IS NULL\"."),
755 gettext_noop("When turned on, expressions of the form expr = NULL "
756 "(or NULL = expr) are treated as expr IS NULL, that is, they "
757 "return true if expr evaluates to the null value, and false "
758 "otherwise. The correct behavior of expr = NULL is to always "
759 "return null (unknown).")
761 &Transform_null_equals,
765 {"db_user_namespace", PGC_SIGHUP, CONN_AUTH_SECURITY,
766 gettext_noop("Enables per-database user names."),
773 /* only here for backwards compatibility */
774 {"autocommit", PGC_USERSET, CLIENT_CONN_STATEMENT,
775 gettext_noop("This parameter doesn't do anything."),
776 gettext_noop("It's just here so that we won't choke on SET AUTOCOMMIT TO ON from 7.3-vintage clients."),
777 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
780 true, assign_phony_autocommit, NULL
783 {"default_transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
784 gettext_noop("Sets the default read-only status of new transactions."),
787 &DefaultXactReadOnly,
791 {"transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
792 gettext_noop("Sets the current transaction's read-only status."),
794 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
797 false, assign_transaction_read_only, NULL
800 {"add_missing_from", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
801 gettext_noop("Automatically adds missing table references to FROM clauses."),
808 {"check_function_bodies", PGC_USERSET, CLIENT_CONN_STATEMENT,
809 gettext_noop("Check function bodies during CREATE FUNCTION."),
812 &check_function_bodies,
816 {"default_with_oids", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
817 gettext_noop("Create new tables with OIDs by default."),
824 {"redirect_stderr", PGC_POSTMASTER, LOGGING_WHERE,
825 gettext_noop("Start a subprocess to capture stderr output into log files."),
832 {"log_truncate_on_rotation", PGC_SIGHUP, LOGGING_WHERE,
833 gettext_noop("Truncate existing log files of same name during log rotation."),
836 &Log_truncate_on_rotation,
842 {"wal_debug", PGC_SUSET, DEVELOPER_OPTIONS,
843 gettext_noop("Emit WAL-related debugging output."),
853 {"integer_datetimes", PGC_INTERNAL, PRESET_OPTIONS,
854 gettext_noop("Datetimes are integer based"),
856 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
859 #ifdef HAVE_INT64_TIMESTAMP
867 {"krb_caseins_users", PGC_POSTMASTER, CONN_AUTH_SECURITY,
868 gettext_noop("Sets if Kerberos user names should be treated case insensitive."),
871 &pg_krb_caseins_users,
875 /* End-of-list marker */
877 {NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL
882 static struct config_int ConfigureNamesInt[] =
885 {"default_statistics_target", PGC_USERSET, QUERY_TUNING_OTHER,
886 gettext_noop("Sets the default statistics target."),
887 gettext_noop("This applies to table columns that have not had a "
888 "column-specific target set via ALTER TABLE SET STATISTICS.")
890 &default_statistics_target,
891 10, 1, 1000, NULL, NULL
894 {"from_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
895 gettext_noop("Sets the FROM-list size beyond which subqueries are not "
897 gettext_noop("The planner will merge subqueries into upper "
898 "queries if the resulting FROM list would have no more than "
901 &from_collapse_limit,
902 8, 1, INT_MAX, NULL, NULL
905 {"join_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
906 gettext_noop("Sets the FROM-list size beyond which JOIN constructs are not "
908 gettext_noop("The planner will flatten explicit inner JOIN "
909 "constructs into lists of FROM items whenever a list of no more "
910 "than this many items would result.")
912 &join_collapse_limit,
913 8, 1, INT_MAX, NULL, NULL
916 {"geqo_threshold", PGC_USERSET, QUERY_TUNING_GEQO,
917 gettext_noop("Sets the threshold of FROM items beyond which GEQO is used."),
921 12, 2, INT_MAX, NULL, NULL
924 {"geqo_effort", PGC_USERSET, QUERY_TUNING_GEQO,
925 gettext_noop("GEQO: effort is used to set the default for other GEQO parameters."),
929 DEFAULT_GEQO_EFFORT, MIN_GEQO_EFFORT, MAX_GEQO_EFFORT, NULL, NULL
932 {"geqo_pool_size", PGC_USERSET, QUERY_TUNING_GEQO,
933 gettext_noop("GEQO: number of individuals in the population."),
934 gettext_noop("Zero selects a suitable default value.")
937 0, 0, INT_MAX, NULL, NULL
940 {"geqo_generations", PGC_USERSET, QUERY_TUNING_GEQO,
941 gettext_noop("GEQO: number of iterations of the algorithm."),
942 gettext_noop("Zero selects a suitable default value.")
945 0, 0, INT_MAX, NULL, NULL
949 {"deadlock_timeout", PGC_SIGHUP, LOCK_MANAGEMENT,
950 gettext_noop("The time in milliseconds to wait on lock before checking for deadlock."),
954 1000, 0, INT_MAX, NULL, NULL
958 * Note: There is some postprocessing done in PostmasterMain() to make
959 * sure the buffers are at least twice the number of backends, so the
960 * constraints here are partially unused. Similarly, the superuser
961 * reserved number is checked to ensure it is less than the max
965 {"max_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
966 gettext_noop("Sets the maximum number of concurrent connections."),
970 100, 1, INT_MAX / BLCKSZ, NULL, NULL
974 {"superuser_reserved_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
975 gettext_noop("Sets the number of connection slots reserved for superusers."),
979 2, 0, INT_MAX / BLCKSZ, NULL, NULL
983 {"shared_buffers", PGC_POSTMASTER, RESOURCES_MEM,
984 gettext_noop("Sets the number of shared memory buffers used by the server."),
988 1000, 16, INT_MAX / BLCKSZ, NULL, NULL
992 {"temp_buffers", PGC_USERSET, RESOURCES_MEM,
993 gettext_noop("Sets the maximum number of temporary buffers used by each session."),
997 1000, 100, INT_MAX / BLCKSZ, NULL, show_num_temp_buffers
1001 {"port", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1002 gettext_noop("Sets the TCP port the server listens on."),
1006 DEF_PGPORT, 1, 65535, NULL, NULL
1010 {"unix_socket_permissions", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1011 gettext_noop("Sets the access permissions of the Unix-domain socket."),
1012 gettext_noop("Unix-domain sockets use the usual Unix file system "
1013 "permission set. The parameter value is expected to be an numeric mode "
1014 "specification in the form accepted by the chmod and umask system "
1015 "calls. (To use the customary octal format the number must start with "
1018 &Unix_socket_permissions,
1019 0777, 0000, 0777, NULL, NULL
1023 {"work_mem", PGC_USERSET, RESOURCES_MEM,
1024 gettext_noop("Sets the maximum memory to be used for query workspaces."),
1025 gettext_noop("This much memory may be used by each internal "
1026 "sort operation and hash table before switching to "
1027 "temporary disk files.")
1030 1024, 8 * BLCKSZ / 1024, INT_MAX / 1024, NULL, NULL
1034 {"maintenance_work_mem", PGC_USERSET, RESOURCES_MEM,
1035 gettext_noop("Sets the maximum memory to be used for maintenance operations."),
1036 gettext_noop("This includes operations such as VACUUM and CREATE INDEX.")
1038 &maintenance_work_mem,
1039 16384, 1024, INT_MAX / 1024, NULL, NULL
1043 {"max_stack_depth", PGC_SUSET, RESOURCES_MEM,
1044 gettext_noop("Sets the maximum stack depth, in kilobytes."),
1048 2048, 100, INT_MAX / 1024, assign_max_stack_depth, NULL
1052 {"vacuum_cost_page_hit", PGC_USERSET, RESOURCES,
1053 gettext_noop("Vacuum cost for a page found in the buffer cache."),
1057 1, 0, 10000, NULL, NULL
1061 {"vacuum_cost_page_miss", PGC_USERSET, RESOURCES,
1062 gettext_noop("Vacuum cost for a page not found in the buffer cache."),
1065 &VacuumCostPageMiss,
1066 10, 0, 10000, NULL, NULL
1070 {"vacuum_cost_page_dirty", PGC_USERSET, RESOURCES,
1071 gettext_noop("Vacuum cost for a page dirtied by vacuum."),
1074 &VacuumCostPageDirty,
1075 20, 0, 10000, NULL, NULL
1079 {"vacuum_cost_limit", PGC_USERSET, RESOURCES,
1080 gettext_noop("Vacuum cost amount available before napping."),
1084 200, 1, 10000, NULL, NULL
1088 {"vacuum_cost_delay", PGC_USERSET, RESOURCES,
1089 gettext_noop("Vacuum cost delay in milliseconds."),
1093 0, 0, 1000, NULL, NULL
1097 {"max_files_per_process", PGC_POSTMASTER, RESOURCES_KERNEL,
1098 gettext_noop("Sets the maximum number of simultaneously open files for each server process."),
1101 &max_files_per_process,
1102 1000, 25, INT_MAX, NULL, NULL
1107 {"trace_lock_oidmin", PGC_SUSET, DEVELOPER_OPTIONS,
1108 gettext_noop("no description available"),
1113 FirstNormalObjectId, 0, INT_MAX, NULL, NULL
1116 {"trace_lock_table", PGC_SUSET, DEVELOPER_OPTIONS,
1117 gettext_noop("no description available"),
1122 0, 0, INT_MAX, NULL, NULL
1127 {"statement_timeout", PGC_USERSET, CLIENT_CONN_STATEMENT,
1128 gettext_noop("Sets the maximum allowed duration (in milliseconds) of any statement."),
1129 gettext_noop("A value of 0 turns off the timeout.")
1132 0, 0, INT_MAX, NULL, NULL
1136 {"max_fsm_relations", PGC_POSTMASTER, RESOURCES_FSM,
1137 gettext_noop("Sets the maximum number of tables and indexes for which free space is tracked."),
1141 1000, 100, INT_MAX, NULL, NULL
1144 {"max_fsm_pages", PGC_POSTMASTER, RESOURCES_FSM,
1145 gettext_noop("Sets the maximum number of disk pages for which free space is tracked."),
1149 20000, 1000, INT_MAX, NULL, NULL
1153 {"max_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
1154 gettext_noop("Sets the maximum number of locks per transaction."),
1155 gettext_noop("The shared lock table is sized on the assumption that "
1156 "at most max_locks_per_transaction * max_connections distinct "
1157 "objects will need to be locked at any one time.")
1159 &max_locks_per_xact,
1160 64, 10, INT_MAX, NULL, NULL
1164 {"authentication_timeout", PGC_SIGHUP, CONN_AUTH_SECURITY,
1165 gettext_noop("Sets the maximum time in seconds to complete client authentication."),
1168 &AuthenticationTimeout,
1169 60, 1, 600, NULL, NULL
1173 /* Not for general use */
1174 {"pre_auth_delay", PGC_SIGHUP, DEVELOPER_OPTIONS,
1175 gettext_noop("no description available"),
1180 0, 0, 60, NULL, NULL
1184 {"checkpoint_segments", PGC_SIGHUP, WAL_CHECKPOINTS,
1185 gettext_noop("Sets the maximum distance in log segments between automatic WAL checkpoints."),
1188 &CheckPointSegments,
1189 3, 1, INT_MAX, NULL, NULL
1193 {"checkpoint_timeout", PGC_SIGHUP, WAL_CHECKPOINTS,
1194 gettext_noop("Sets the maximum time in seconds between automatic WAL checkpoints."),
1198 300, 30, 3600, NULL, NULL
1202 {"checkpoint_warning", PGC_SIGHUP, WAL_CHECKPOINTS,
1203 gettext_noop("Logs if filling of checkpoint segments happens more "
1204 "frequently than this (in seconds)."),
1205 gettext_noop("Write a message to the server log if checkpoints "
1206 "caused by the filling of checkpoint segment files happens more "
1207 "frequently than this number of seconds. Zero turns off the warning.")
1210 30, 0, INT_MAX, NULL, NULL
1214 {"wal_buffers", PGC_POSTMASTER, WAL_SETTINGS,
1215 gettext_noop("Sets the number of disk-page buffers in shared memory for WAL."),
1219 8, 4, INT_MAX / BLCKSZ, NULL, NULL
1223 {"commit_delay", PGC_USERSET, WAL_CHECKPOINTS,
1224 gettext_noop("Sets the delay in microseconds between transaction commit and "
1225 "flushing WAL to disk."),
1229 0, 0, 100000, NULL, NULL
1233 {"commit_siblings", PGC_USERSET, WAL_CHECKPOINTS,
1234 gettext_noop("Sets the minimum concurrent open transactions before performing "
1239 5, 1, 1000, NULL, NULL
1243 {"extra_float_digits", PGC_USERSET, CLIENT_CONN_LOCALE,
1244 gettext_noop("Sets the number of digits displayed for floating-point values."),
1245 gettext_noop("This affects real, double precision, and geometric data types. "
1246 "The parameter value is added to the standard number of digits "
1247 "(FLT_DIG or DBL_DIG as appropriate).")
1249 &extra_float_digits,
1250 0, -15, 2, NULL, NULL
1254 {"log_min_duration_statement", PGC_SUSET, LOGGING_WHEN,
1255 gettext_noop("Sets the minimum execution time in milliseconds above which statements will "
1257 gettext_noop("Zero prints all queries. The default is -1 (turning this feature off).")
1259 &log_min_duration_statement,
1260 -1, -1, INT_MAX / 1000, NULL, NULL
1264 {"bgwriter_delay", PGC_SIGHUP, RESOURCES,
1265 gettext_noop("Background writer sleep time between rounds in milliseconds"),
1269 200, 10, 10000, NULL, NULL
1273 {"bgwriter_lru_maxpages", PGC_SIGHUP, RESOURCES,
1274 gettext_noop("Background writer maximum number of all pages to flush per round"),
1277 &bgwriter_lru_maxpages,
1278 5, 0, 1000, NULL, NULL
1282 {"bgwriter_all_maxpages", PGC_SIGHUP, RESOURCES,
1283 gettext_noop("Background writer maximum number of LRU pages to flush per round"),
1286 &bgwriter_all_maxpages,
1287 5, 0, 1000, NULL, NULL
1291 {"log_rotation_age", PGC_SIGHUP, LOGGING_WHERE,
1292 gettext_noop("Automatic log file rotation will occur after N minutes"),
1296 24 * 60, 0, INT_MAX / 60, NULL, NULL
1300 {"log_rotation_size", PGC_SIGHUP, LOGGING_WHERE,
1301 gettext_noop("Automatic log file rotation will occur after N kilobytes"),
1305 10 * 1024, 0, INT_MAX / 1024, NULL, NULL
1309 {"max_function_args", PGC_INTERNAL, PRESET_OPTIONS,
1310 gettext_noop("Shows the maximum number of function arguments."),
1312 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1315 FUNC_MAX_ARGS, FUNC_MAX_ARGS, FUNC_MAX_ARGS, NULL, NULL
1319 {"max_index_keys", PGC_INTERNAL, PRESET_OPTIONS,
1320 gettext_noop("Shows the maximum number of index keys."),
1322 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1325 INDEX_MAX_KEYS, INDEX_MAX_KEYS, INDEX_MAX_KEYS, NULL, NULL
1329 {"max_identifier_length", PGC_INTERNAL, PRESET_OPTIONS,
1330 gettext_noop("Shows the maximum identifier length"),
1332 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1334 &max_identifier_length,
1335 NAMEDATALEN - 1, NAMEDATALEN - 1, NAMEDATALEN - 1, NULL, NULL
1339 {"block_size", PGC_INTERNAL, PRESET_OPTIONS,
1340 gettext_noop("Shows size of a disk block"),
1342 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1345 BLCKSZ, BLCKSZ, BLCKSZ, NULL, NULL
1348 /* End-of-list marker */
1350 {NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL
1355 static struct config_real ConfigureNamesReal[] =
1358 {"effective_cache_size", PGC_USERSET, QUERY_TUNING_COST,
1359 gettext_noop("Sets the planner's assumption about size of the disk cache."),
1360 gettext_noop("That is, the portion of the kernel's disk cache that "
1361 "will be used for PostgreSQL data files. This is measured in disk "
1362 "pages, which are normally 8 kB each.")
1364 &effective_cache_size,
1365 DEFAULT_EFFECTIVE_CACHE_SIZE, 1, DBL_MAX, NULL, NULL
1368 {"random_page_cost", PGC_USERSET, QUERY_TUNING_COST,
1369 gettext_noop("Sets the planner's estimate of the cost of a nonsequentially "
1370 "fetched disk page."),
1371 gettext_noop("This is measured as a multiple of the cost of a "
1372 "sequential page fetch. A higher value makes it more likely a "
1373 "sequential scan will be used, a lower value makes it more likely an "
1374 "index scan will be used.")
1377 DEFAULT_RANDOM_PAGE_COST, 0, DBL_MAX, NULL, NULL
1380 {"cpu_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
1381 gettext_noop("Sets the planner's estimate of the cost of processing each tuple (row)."),
1382 gettext_noop("This is measured as a fraction of the cost of a "
1383 "sequential page fetch.")
1386 DEFAULT_CPU_TUPLE_COST, 0, DBL_MAX, NULL, NULL
1389 {"cpu_index_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
1390 gettext_noop("Sets the planner's estimate of processing cost for each "
1391 "index tuple (row) during index scan."),
1392 gettext_noop("This is measured as a fraction of the cost of a "
1393 "sequential page fetch.")
1395 &cpu_index_tuple_cost,
1396 DEFAULT_CPU_INDEX_TUPLE_COST, 0, DBL_MAX, NULL, NULL
1399 {"cpu_operator_cost", PGC_USERSET, QUERY_TUNING_COST,
1400 gettext_noop("Sets the planner's estimate of processing cost of each operator in WHERE."),
1401 gettext_noop("This is measured as a fraction of the cost of a sequential "
1405 DEFAULT_CPU_OPERATOR_COST, 0, DBL_MAX, NULL, NULL
1409 {"geqo_selection_bias", PGC_USERSET, QUERY_TUNING_GEQO,
1410 gettext_noop("GEQO: selective pressure within the population."),
1413 &Geqo_selection_bias,
1414 DEFAULT_GEQO_SELECTION_BIAS, MIN_GEQO_SELECTION_BIAS,
1415 MAX_GEQO_SELECTION_BIAS, NULL, NULL
1419 {"bgwriter_lru_percent", PGC_SIGHUP, RESOURCES,
1420 gettext_noop("Background writer percentage of LRU buffers to flush per round"),
1423 &bgwriter_lru_percent,
1424 1.0, 0.0, 100.0, NULL, NULL
1428 {"bgwriter_all_percent", PGC_SIGHUP, RESOURCES,
1429 gettext_noop("Background writer percentage of all buffers to flush per round"),
1432 &bgwriter_all_percent,
1433 0.333, 0.0, 100.0, NULL, NULL
1437 {"seed", PGC_USERSET, UNGROUPED,
1438 gettext_noop("Sets the seed for random-number generation."),
1440 GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1443 0.5, 0.0, 1.0, assign_random_seed, show_random_seed
1446 /* End-of-list marker */
1448 {NULL, 0, 0, NULL, NULL}, NULL, 0.0, 0.0, 0.0, NULL, NULL
1453 static struct config_string ConfigureNamesString[] =
1456 {"archive_command", PGC_SIGHUP, WAL_SETTINGS,
1457 gettext_noop("WAL archiving command."),
1458 gettext_noop("The shell command that will be called to archive a WAL file.")
1460 &XLogArchiveCommand,
1465 {"client_encoding", PGC_USERSET, CLIENT_CONN_LOCALE,
1466 gettext_noop("Sets the client's character set encoding."),
1470 &client_encoding_string,
1471 "SQL_ASCII", assign_client_encoding, NULL
1475 {"client_min_messages", PGC_USERSET, LOGGING_WHEN,
1476 gettext_noop("Sets the message levels that are sent to the client."),
1477 gettext_noop("Valid values are DEBUG5, DEBUG4, DEBUG3, DEBUG2, "
1478 "DEBUG1, LOG, NOTICE, WARNING, and ERROR. Each level includes all the "
1479 "levels that follow it. The later the level, the fewer messages are "
1482 &client_min_messages_str,
1483 "notice", assign_client_min_messages, NULL
1487 {"log_min_messages", PGC_SUSET, LOGGING_WHEN,
1488 gettext_noop("Sets the message levels that are logged."),
1489 gettext_noop("Valid values are DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1, "
1490 "INFO, NOTICE, WARNING, ERROR, LOG, FATAL, and PANIC. Each level "
1491 "includes all the levels that follow it.")
1493 &log_min_messages_str,
1494 "notice", assign_log_min_messages, NULL
1498 {"log_error_verbosity", PGC_SUSET, LOGGING_WHEN,
1499 gettext_noop("Sets the verbosity of logged messages."),
1500 gettext_noop("Valid values are \"terse\", \"default\", and \"verbose\".")
1502 &log_error_verbosity_str,
1503 "default", assign_log_error_verbosity, NULL
1506 {"log_statement", PGC_SUSET, LOGGING_WHAT,
1507 gettext_noop("Sets the type of statements logged."),
1508 gettext_noop("Valid values are \"none\", \"ddl\", \"mod\", and \"all\".")
1511 "none", assign_log_statement, NULL
1515 {"log_min_error_statement", PGC_SUSET, LOGGING_WHEN,
1516 gettext_noop("Causes all statements generating error at or above this level to be logged."),
1517 gettext_noop("All SQL statements that cause an error of the "
1518 "specified level or a higher level are logged.")
1520 &log_min_error_statement_str,
1521 "panic", assign_min_error_statement, NULL
1525 {"log_line_prefix", PGC_SIGHUP, LOGGING_WHAT,
1526 gettext_noop("Controls information prefixed to each log line"),
1527 gettext_noop("if blank no prefix is used")
1535 {"DateStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
1536 gettext_noop("Sets the display format for date and time values."),
1537 gettext_noop("Also controls interpretation of ambiguous "
1539 GUC_LIST_INPUT | GUC_REPORT
1542 "ISO, MDY", assign_datestyle, NULL
1546 {"default_tablespace", PGC_USERSET, CLIENT_CONN_STATEMENT,
1547 gettext_noop("Sets the default tablespace to create tables and indexes in."),
1548 gettext_noop("An empty string selects the database's default tablespace.")
1550 &default_tablespace,
1551 "", assign_default_tablespace, NULL
1555 {"default_transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
1556 gettext_noop("Sets the transaction isolation level of each new transaction."),
1557 gettext_noop("Each SQL transaction has an isolation level, which "
1558 "can be either \"read uncommitted\", \"read committed\", \"repeatable read\", or \"serializable\".")
1560 &default_iso_level_string,
1561 "read committed", assign_defaultxactisolevel, NULL
1565 {"dynamic_library_path", PGC_SUSET, CLIENT_CONN_OTHER,
1566 gettext_noop("Sets the path for dynamically loadable modules."),
1567 gettext_noop("If a dynamically loadable module needs to be opened and "
1568 "the specified name does not have a directory component (i.e., the "
1569 "name does not contain a slash), the system will search this path for "
1570 "the specified file."),
1573 &Dynamic_library_path,
1574 "$libdir", NULL, NULL
1578 {"krb_server_keyfile", PGC_POSTMASTER, CONN_AUTH_SECURITY,
1579 gettext_noop("Sets the location of the Kerberos server key file."),
1583 &pg_krb_server_keyfile,
1584 PG_KRB_SRVTAB, NULL, NULL
1588 {"krb_srvname", PGC_POSTMASTER, CONN_AUTH_SECURITY,
1589 gettext_noop("Sets the name of the Kerberos service."),
1593 PG_KRB_SRVNAM, NULL, NULL
1597 {"krb_server_hostname", PGC_POSTMASTER, CONN_AUTH_SECURITY,
1598 gettext_noop("Sets the hostname of the Kerberos server."),
1601 &pg_krb_server_hostname,
1606 {"bonjour_name", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1607 gettext_noop("Sets the Bonjour broadcast service name."),
1614 /* See main.c about why defaults for LC_foo are not all alike */
1617 {"lc_collate", PGC_INTERNAL, CLIENT_CONN_LOCALE,
1618 gettext_noop("Shows the collation order locale."),
1620 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1627 {"lc_ctype", PGC_INTERNAL, CLIENT_CONN_LOCALE,
1628 gettext_noop("Shows the character classification and case conversion locale."),
1630 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1637 {"lc_messages", PGC_SUSET, CLIENT_CONN_LOCALE,
1638 gettext_noop("Sets the language in which messages are displayed."),
1642 "", locale_messages_assign, NULL
1646 {"lc_monetary", PGC_USERSET, CLIENT_CONN_LOCALE,
1647 gettext_noop("Sets the locale for formatting monetary amounts."),
1651 "C", locale_monetary_assign, NULL
1655 {"lc_numeric", PGC_USERSET, CLIENT_CONN_LOCALE,
1656 gettext_noop("Sets the locale for formatting numbers."),
1660 "C", locale_numeric_assign, NULL
1664 {"lc_time", PGC_USERSET, CLIENT_CONN_LOCALE,
1665 gettext_noop("Sets the locale for formatting date and time values."),
1669 "C", locale_time_assign, NULL
1673 {"preload_libraries", PGC_POSTMASTER, RESOURCES_KERNEL,
1674 gettext_noop("Lists shared libraries to preload into server."),
1676 GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
1678 &preload_libraries_string,
1683 {"regex_flavor", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1684 gettext_noop("Sets the regular expression \"flavor\"."),
1685 gettext_noop("This can be set to advanced, extended, or basic.")
1687 ®ex_flavor_string,
1688 "advanced", assign_regex_flavor, NULL
1692 {"search_path", PGC_USERSET, CLIENT_CONN_STATEMENT,
1693 gettext_noop("Sets the schema search order for names that are not schema-qualified."),
1695 GUC_LIST_INPUT | GUC_LIST_QUOTE
1697 &namespace_search_path,
1698 "$user,public", assign_search_path, NULL
1702 /* Can't be set in postgresql.conf */
1703 {"server_encoding", PGC_INTERNAL, CLIENT_CONN_LOCALE,
1704 gettext_noop("Sets the server (database) character set encoding."),
1706 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1708 &server_encoding_string,
1709 "SQL_ASCII", NULL, NULL
1713 /* Can't be set in postgresql.conf */
1714 {"server_version", PGC_INTERNAL, PRESET_OPTIONS,
1715 gettext_noop("Shows the server version."),
1717 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1719 &server_version_string,
1720 PG_VERSION, NULL, NULL
1724 /* Not for general use --- used by SET SESSION AUTHORIZATION */
1725 {"session_authorization", PGC_USERSET, UNGROUPED,
1726 gettext_noop("Sets the session user name."),
1728 GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1730 &session_authorization_string,
1731 NULL, assign_session_authorization, show_session_authorization
1735 {"log_destination", PGC_SIGHUP, LOGGING_WHERE,
1736 gettext_noop("Sets the destination for server log output."),
1737 gettext_noop("Valid values are combinations of \"stderr\", \"syslog\", "
1738 "and \"eventlog\", depending on the platform."),
1741 &log_destination_string,
1742 "stderr", assign_log_destination, NULL
1745 {"log_directory", PGC_SIGHUP, LOGGING_WHERE,
1746 gettext_noop("Sets the destination directory for log files."),
1747 gettext_noop("May be specified as relative to the data directory "
1748 "or as absolute path."),
1752 "pg_log", assign_canonical_path, NULL
1755 {"log_filename", PGC_SIGHUP, LOGGING_WHERE,
1756 gettext_noop("Sets the file name pattern for log files."),
1761 "postgresql-%Y-%m-%d_%H%M%S.log", NULL, NULL
1766 {"syslog_facility", PGC_POSTMASTER, LOGGING_WHERE,
1767 gettext_noop("Sets the syslog \"facility\" to be used when syslog enabled."),
1768 gettext_noop("Valid values are LOCAL0, LOCAL1, LOCAL2, LOCAL3, "
1769 "LOCAL4, LOCAL5, LOCAL6, LOCAL7.")
1772 "LOCAL0", assign_facility, NULL
1775 {"syslog_ident", PGC_POSTMASTER, LOGGING_WHERE,
1776 gettext_noop("Sets the program name used to identify PostgreSQL messages "
1781 "postgres", NULL, NULL
1786 {"TimeZone", PGC_USERSET, CLIENT_CONN_LOCALE,
1787 gettext_noop("Sets the time zone for displaying and interpreting time stamps."),
1792 "UNKNOWN", assign_timezone, show_timezone
1796 {"transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
1797 gettext_noop("Sets the current transaction's isolation level."),
1799 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1801 &XactIsoLevel_string,
1802 NULL, assign_XactIsoLevel, show_XactIsoLevel
1806 {"unix_socket_group", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1807 gettext_noop("Sets the owning group of the Unix-domain socket."),
1808 gettext_noop("(The owning user of the socket is always the user "
1809 "that starts the server.)")
1816 {"unix_socket_directory", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1817 gettext_noop("Sets the directory where the Unix-domain socket will be created."),
1822 "", assign_canonical_path, NULL
1826 {"listen_addresses", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1827 gettext_noop("Sets the host name or IP address(es) to listen to."),
1832 "localhost", NULL, NULL
1836 {"wal_sync_method", PGC_SIGHUP, WAL_SETTINGS,
1837 gettext_noop("Selects the method used for forcing WAL updates out to disk."),
1841 XLOG_sync_method_default, assign_xlog_sync_method, NULL
1845 {"custom_variable_classes", PGC_POSTMASTER, RESOURCES_KERNEL,
1846 gettext_noop("Sets the list of known custom variable classes."),
1848 GUC_LIST_INPUT | GUC_LIST_QUOTE
1850 &custom_variable_classes,
1851 NULL, assign_custom_variable_classes, NULL
1855 {"data_directory", PGC_POSTMASTER, FILE_LOCATIONS,
1856 gettext_noop("Sets the server's data directory."),
1865 {"config_file", PGC_POSTMASTER, FILE_LOCATIONS,
1866 gettext_noop("Sets the server's main configuration file."),
1868 GUC_DISALLOW_IN_FILE | GUC_SUPERUSER_ONLY
1875 {"hba_file", PGC_POSTMASTER, FILE_LOCATIONS,
1876 gettext_noop("Sets the server's \"hba\" configuration file"),
1885 {"ident_file", PGC_POSTMASTER, FILE_LOCATIONS,
1886 gettext_noop("Sets the server's \"ident\" configuration file"),
1895 {"external_pid_file", PGC_POSTMASTER, FILE_LOCATIONS,
1896 gettext_noop("Writes the postmaster PID to the specified file."),
1901 NULL, assign_canonical_path, NULL
1904 /* End-of-list marker */
1906 {NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL
1911 /******** end of options list ********/
1915 * To allow continued support of obsolete names for GUC variables, we apply
1916 * the following mappings to any unrecognized name. Note that an old name
1917 * should be mapped to a new one only if the new variable has very similar
1918 * semantics to the old.
1920 static const char *const map_old_guc_names[] = {
1921 "sort_mem", "work_mem",
1922 "vacuum_mem", "maintenance_work_mem",
1928 * Actual lookup of variables is done through this single, sorted array.
1930 static struct config_generic **guc_variables;
1932 /* Current number of variables contained in the vector */
1933 static int num_guc_variables;
1935 /* Vector capacity */
1936 static int size_guc_variables;
1939 static bool guc_dirty; /* TRUE if need to do commit/abort work */
1941 static bool reporting_enabled; /* TRUE to enable GUC_REPORT */
1943 static char *guc_string_workspace; /* for avoiding memory leaks */
1946 static int guc_var_compare(const void *a, const void *b);
1947 static int guc_name_compare(const char *namea, const char *nameb);
1948 static void push_old_value(struct config_generic * gconf);
1949 static void ReportGUCOption(struct config_generic * record);
1950 static void ShowGUCConfigOption(const char *name, DestReceiver *dest);
1951 static void ShowAllGUCConfig(DestReceiver *dest);
1952 static char *_ShowOption(struct config_generic * record);
1956 * Some infrastructure for checking malloc/strdup/realloc calls
1959 guc_malloc(int elevel, size_t size)
1963 data = malloc(size);
1966 (errcode(ERRCODE_OUT_OF_MEMORY),
1967 errmsg("out of memory")));
1972 guc_realloc(int elevel, void *old, size_t size)
1976 data = realloc(old, size);
1979 (errcode(ERRCODE_OUT_OF_MEMORY),
1980 errmsg("out of memory")));
1985 guc_strdup(int elevel, const char *src)
1992 (errcode(ERRCODE_OUT_OF_MEMORY),
1993 errmsg("out of memory")));
1999 * Support for assigning to a field of a string GUC item. Free the prior
2000 * value if it's not referenced anywhere else in the item (including stacked
2004 set_string_field(struct config_string * conf, char **field, char *newval)
2006 char *oldval = *field;
2009 /* Do the assignment */
2012 /* Exit if any duplicate references, or if old value was NULL anyway */
2013 if (oldval == NULL ||
2014 oldval == *(conf->variable) ||
2015 oldval == conf->reset_val ||
2016 oldval == conf->tentative_val)
2018 for (stack = conf->gen.stack; stack; stack = stack->prev)
2020 if (oldval == stack->tentative_val.stringval ||
2021 oldval == stack->value.stringval)
2025 /* Not used anymore, so free it */
2030 * Detect whether strval is referenced anywhere in a GUC string item
2033 string_field_used(struct config_string * conf, char *strval)
2037 if (strval == *(conf->variable) ||
2038 strval == conf->reset_val ||
2039 strval == conf->tentative_val)
2041 for (stack = conf->gen.stack; stack; stack = stack->prev)
2043 if (strval == stack->tentative_val.stringval ||
2044 strval == stack->value.stringval)
2051 struct config_generic **
2052 get_guc_variables(void)
2054 return guc_variables;
2059 * Build the sorted array. This is split out so that it could be
2060 * re-executed after startup (eg, we could allow loadable modules to
2061 * add vars, and then we'd need to re-sort).
2064 build_guc_variables(void)
2068 struct config_generic **guc_vars;
2071 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
2073 struct config_bool *conf = &ConfigureNamesBool[i];
2075 /* Rather than requiring vartype to be filled in by hand, do this: */
2076 conf->gen.vartype = PGC_BOOL;
2080 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
2082 struct config_int *conf = &ConfigureNamesInt[i];
2084 conf->gen.vartype = PGC_INT;
2088 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
2090 struct config_real *conf = &ConfigureNamesReal[i];
2092 conf->gen.vartype = PGC_REAL;
2096 for (i = 0; ConfigureNamesString[i].gen.name; i++)
2098 struct config_string *conf = &ConfigureNamesString[i];
2100 conf->gen.vartype = PGC_STRING;
2105 * Create table with 20% slack
2107 size_vars = num_vars + num_vars / 4;
2109 guc_vars = (struct config_generic **)
2110 guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
2114 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
2115 guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
2117 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
2118 guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
2120 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
2121 guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
2123 for (i = 0; ConfigureNamesString[i].gen.name; i++)
2124 guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
2127 free(guc_variables);
2128 guc_variables = guc_vars;
2129 num_guc_variables = num_vars;
2130 size_guc_variables = size_vars;
2131 qsort((void *) guc_variables, num_guc_variables,
2132 sizeof(struct config_generic *), guc_var_compare);
2136 is_custom_class(const char *name, int dotPos)
2139 * assign_custom_variable_classes() has made sure no empty
2140 * identifiers or whitespace exists in the variable
2142 bool result = false;
2143 const char *ccs = GetConfigOption("custom_variable_classes");
2147 const char *start = ccs;
2153 if (c == 0 || c == ',')
2155 if (dotPos == ccs - start && strncmp(start, name, dotPos) == 0)
2170 * Add a new GUC variable to the list of known variables. The
2171 * list is expanded if needed.
2174 add_guc_variable(struct config_generic * var, int elevel)
2176 if (num_guc_variables + 1 >= size_guc_variables)
2179 * Increase the vector by 25%
2181 int size_vars = size_guc_variables + size_guc_variables / 4;
2182 struct config_generic **guc_vars;
2187 guc_vars = (struct config_generic **)
2188 guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
2192 guc_vars = (struct config_generic **)
2193 guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
2196 if (guc_vars == NULL)
2197 return false; /* out of memory */
2199 guc_variables = guc_vars;
2200 size_guc_variables = size_vars;
2202 guc_variables[num_guc_variables++] = var;
2203 qsort((void *) guc_variables, num_guc_variables,
2204 sizeof(struct config_generic *), guc_var_compare);
2209 * Create and add a placeholder variable. It's presumed to belong
2210 * to a valid custom variable class at this point.
2212 static struct config_string *
2213 add_placeholder_variable(const char *name, int elevel)
2215 size_t sz = sizeof(struct config_string) + sizeof(char *);
2216 struct config_string *var;
2217 struct config_generic *gen;
2219 var = (struct config_string *) guc_malloc(elevel, sz);
2226 gen->name = guc_strdup(elevel, name);
2227 if (gen->name == NULL)
2233 gen->context = PGC_USERSET;
2234 gen->group = CUSTOM_OPTIONS;
2235 gen->short_desc = "GUC placeholder variable";
2236 gen->flags = GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_CUSTOM_PLACEHOLDER;
2237 gen->vartype = PGC_STRING;
2240 * The char* is allocated at the end of the struct since we have no
2241 * 'static' place to point to.
2243 var->variable = (char **) (var + 1);
2245 if (!add_guc_variable((struct config_generic *) var, elevel))
2247 free((void *) gen->name);
2256 * Look up option NAME. If it exists, return a pointer to its record,
2259 static struct config_generic *
2260 find_option(const char *name, int elevel)
2263 const char **key = &name;
2264 struct config_generic **res;
2270 * By equating const char ** with struct config_generic *, we are
2271 * assuming the name field is first in config_generic.
2273 res = (struct config_generic **) bsearch((void *) &key,
2274 (void *) guc_variables,
2276 sizeof(struct config_generic *),
2282 * See if the name is an obsolete name for a variable. We assume that
2283 * the set of supported old names is short enough that a brute-force
2284 * search is the best way.
2286 for (i = 0; map_old_guc_names[i] != NULL; i += 2)
2288 if (guc_name_compare(name, map_old_guc_names[i]) == 0)
2289 return find_option(map_old_guc_names[i + 1], elevel);
2293 * Check if the name is qualified, and if so, check if the qualifier
2294 * maps to a custom variable class.
2296 dot = strchr(name, GUC_QUALIFIER_SEPARATOR);
2297 if (dot != NULL && is_custom_class(name, dot - name))
2298 /* Add a placeholder variable for this name */
2299 return (struct config_generic *) add_placeholder_variable(name, elevel);
2307 * comparator for qsorting and bsearching guc_variables array
2310 guc_var_compare(const void *a, const void *b)
2312 struct config_generic *confa = *(struct config_generic **) a;
2313 struct config_generic *confb = *(struct config_generic **) b;
2315 return guc_name_compare(confa->name, confb->name);
2320 guc_name_compare(const char *namea, const char *nameb)
2323 * The temptation to use strcasecmp() here must be resisted, because
2324 * the array ordering has to remain stable across setlocale() calls.
2325 * So, build our own with a simple ASCII-only downcasing.
2327 while (*namea && *nameb)
2329 char cha = *namea++;
2330 char chb = *nameb++;
2332 if (cha >= 'A' && cha <= 'Z')
2334 if (chb >= 'A' && chb <= 'Z')
2340 return 1; /* a is longer */
2342 return -1; /* b is longer */
2348 * Initialize GUC options during program startup.
2350 * Note that we cannot read the config file yet, since we have not yet
2351 * processed command-line switches.
2354 InitializeGUCOptions(void)
2360 * Build sorted array of all GUC variables.
2362 build_guc_variables();
2365 * Load all variables with their compiled-in defaults, and initialize
2366 * status fields as needed.
2368 for (i = 0; i < num_guc_variables; i++)
2370 struct config_generic *gconf = guc_variables[i];
2373 gconf->reset_source = PGC_S_DEFAULT;
2374 gconf->tentative_source = PGC_S_DEFAULT;
2375 gconf->source = PGC_S_DEFAULT;
2376 gconf->stack = NULL;
2378 switch (gconf->vartype)
2382 struct config_bool *conf = (struct config_bool *) gconf;
2384 if (conf->assign_hook)
2385 if (!(*conf->assign_hook) (conf->reset_val, true,
2387 elog(FATAL, "failed to initialize %s to %d",
2388 conf->gen.name, (int) conf->reset_val);
2389 *conf->variable = conf->reset_val;
2394 struct config_int *conf = (struct config_int *) gconf;
2396 Assert(conf->reset_val >= conf->min);
2397 Assert(conf->reset_val <= conf->max);
2398 if (conf->assign_hook)
2399 if (!(*conf->assign_hook) (conf->reset_val, true,
2401 elog(FATAL, "failed to initialize %s to %d",
2402 conf->gen.name, conf->reset_val);
2403 *conf->variable = conf->reset_val;
2408 struct config_real *conf = (struct config_real *) gconf;
2410 Assert(conf->reset_val >= conf->min);
2411 Assert(conf->reset_val <= conf->max);
2412 if (conf->assign_hook)
2413 if (!(*conf->assign_hook) (conf->reset_val, true,
2415 elog(FATAL, "failed to initialize %s to %g",
2416 conf->gen.name, conf->reset_val);
2417 *conf->variable = conf->reset_val;
2422 struct config_string *conf = (struct config_string *) gconf;
2425 *conf->variable = NULL;
2426 conf->reset_val = NULL;
2427 conf->tentative_val = NULL;
2429 if (conf->boot_val == NULL)
2431 /* Cannot set value yet */
2435 str = guc_strdup(FATAL, conf->boot_val);
2436 conf->reset_val = str;
2438 if (conf->assign_hook)
2442 newstr = (*conf->assign_hook) (str, true,
2446 elog(FATAL, "failed to initialize %s to \"%s\"",
2447 conf->gen.name, str);
2449 else if (newstr != str)
2454 * See notes in set_config_option about
2457 str = (char *) newstr;
2458 conf->reset_val = str;
2461 *conf->variable = str;
2469 reporting_enabled = false;
2471 guc_string_workspace = NULL;
2474 * Prevent any attempt to override the transaction modes from
2475 * non-interactive sources.
2477 SetConfigOption("transaction_isolation", "default",
2478 PGC_POSTMASTER, PGC_S_OVERRIDE);
2479 SetConfigOption("transaction_read_only", "no",
2480 PGC_POSTMASTER, PGC_S_OVERRIDE);
2483 * For historical reasons, some GUC parameters can receive defaults
2484 * from environment variables. Process those settings.
2487 env = getenv("PGPORT");
2489 SetConfigOption("port", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
2491 env = getenv("PGDATESTYLE");
2493 SetConfigOption("datestyle", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
2495 env = getenv("PGCLIENTENCODING");
2497 SetConfigOption("client_encoding", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
2502 * Select the configuration files and data directory to be used, and
2503 * do the initial read of postgresql.conf.
2505 * This is called after processing command-line switches.
2506 * userDoption is the -D switch value if any (NULL if unspecified).
2507 * progname is just for use in error messages.
2509 * Returns true on success; on failure, prints a suitable error message
2510 * to stderr and returns false.
2513 SelectConfigFiles(const char *userDoption, const char *progname)
2517 struct stat stat_buf;
2519 /* configdir is -D option, or $PGDATA if no -D */
2521 configdir = make_absolute_path(userDoption);
2523 configdir = make_absolute_path(getenv("PGDATA"));
2526 * Find the configuration file: if config_file was specified on the
2527 * command line, use it, else use configdir/postgresql.conf. In any
2528 * case ensure the result is an absolute path, so that it will be
2529 * interpreted the same way by future backends.
2532 fname = make_absolute_path(ConfigFileName);
2535 fname = guc_malloc(FATAL,
2536 strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
2537 sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
2541 write_stderr("%s does not know where to find the server configuration file.\n"
2542 "You must specify the --config-file or -D invocation "
2543 "option or set the PGDATA environment variable.\n",
2549 * Set the ConfigFileName GUC variable to its final value, ensuring
2550 * that it can't be overridden later.
2552 SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
2556 * Now read the config file for the first time.
2558 if (stat(ConfigFileName, &stat_buf) != 0)
2560 write_stderr("%s cannot access the server configuration file \"%s\": %s\n",
2561 progname, ConfigFileName, strerror(errno));
2565 ProcessConfigFile(PGC_POSTMASTER);
2568 * If the data_directory GUC variable has been set, use that as DataDir;
2569 * otherwise use configdir if set; else punt.
2571 * Note: SetDataDir will copy and absolute-ize its argument,
2572 * so we don't have to.
2575 SetDataDir(data_directory);
2577 SetDataDir(configdir);
2580 write_stderr("%s does not know where to find the database system data.\n"
2581 "This can be specified as \"data_directory\" in \"%s\", "
2582 "or by the -D invocation option, or by the "
2583 "PGDATA environment variable.\n",
2584 progname, ConfigFileName);
2589 * Reflect the final DataDir value back into the data_directory GUC var.
2590 * (If you are wondering why we don't just make them a single variable,
2591 * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
2592 * child backends specially.)
2594 SetConfigOption("data_directory", DataDir, PGC_POSTMASTER, PGC_S_OVERRIDE);
2597 * Figure out where pg_hba.conf is, and make sure the path is absolute.
2600 fname = make_absolute_path(HbaFileName);
2603 fname = guc_malloc(FATAL,
2604 strlen(configdir) + strlen(HBA_FILENAME) + 2);
2605 sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
2609 write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
2610 "This can be specified as \"hba_file\" in \"%s\", "
2611 "or by the -D invocation option, or by the "
2612 "PGDATA environment variable.\n",
2613 progname, ConfigFileName);
2616 SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
2620 * Likewise for pg_ident.conf.
2623 fname = make_absolute_path(IdentFileName);
2626 fname = guc_malloc(FATAL,
2627 strlen(configdir) + strlen(IDENT_FILENAME) + 2);
2628 sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
2632 write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
2633 "This can be specified as \"ident_file\" in \"%s\", "
2634 "or by the -D invocation option, or by the "
2635 "PGDATA environment variable.\n",
2636 progname, ConfigFileName);
2639 SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
2644 /* If timezone is not set, determine what the OS uses */
2645 pg_timezone_initialize();
2652 * Reset all options to their saved default values (implements RESET ALL)
2655 ResetAllOptions(void)
2659 for (i = 0; i < num_guc_variables; i++)
2661 struct config_generic *gconf = guc_variables[i];
2663 /* Don't reset non-SET-able values */
2664 if (gconf->context != PGC_SUSET &&
2665 gconf->context != PGC_USERSET)
2667 /* Don't reset if special exclusion from RESET ALL */
2668 if (gconf->flags & GUC_NO_RESET_ALL)
2670 /* No need to reset if wasn't SET */
2671 if (gconf->source <= PGC_S_OVERRIDE)
2674 /* Save old value to support transaction abort */
2675 push_old_value(gconf);
2677 switch (gconf->vartype)
2681 struct config_bool *conf = (struct config_bool *) gconf;
2683 if (conf->assign_hook)
2684 if (!(*conf->assign_hook) (conf->reset_val, true,
2686 elog(ERROR, "failed to reset %s", conf->gen.name);
2687 *conf->variable = conf->reset_val;
2688 conf->tentative_val = conf->reset_val;
2689 conf->gen.source = conf->gen.reset_source;
2690 conf->gen.tentative_source = conf->gen.reset_source;
2691 conf->gen.status |= GUC_HAVE_TENTATIVE;
2697 struct config_int *conf = (struct config_int *) gconf;
2699 if (conf->assign_hook)
2700 if (!(*conf->assign_hook) (conf->reset_val, true,
2702 elog(ERROR, "failed to reset %s", conf->gen.name);
2703 *conf->variable = conf->reset_val;
2704 conf->tentative_val = conf->reset_val;
2705 conf->gen.source = conf->gen.reset_source;
2706 conf->gen.tentative_source = conf->gen.reset_source;
2707 conf->gen.status |= GUC_HAVE_TENTATIVE;
2713 struct config_real *conf = (struct config_real *) gconf;
2715 if (conf->assign_hook)
2716 if (!(*conf->assign_hook) (conf->reset_val, true,
2718 elog(ERROR, "failed to reset %s", conf->gen.name);
2719 *conf->variable = conf->reset_val;
2720 conf->tentative_val = conf->reset_val;
2721 conf->gen.source = conf->gen.reset_source;
2722 conf->gen.tentative_source = conf->gen.reset_source;
2723 conf->gen.status |= GUC_HAVE_TENTATIVE;
2729 struct config_string *conf = (struct config_string *) gconf;
2732 if (conf->reset_val == NULL)
2734 /* Nothing to reset to, as yet; so do nothing */
2738 /* We need not strdup here */
2739 str = conf->reset_val;
2741 if (conf->assign_hook)
2745 newstr = (*conf->assign_hook) (str, true,
2748 elog(ERROR, "failed to reset %s", conf->gen.name);
2749 else if (newstr != str)
2752 * See notes in set_config_option about
2755 str = (char *) newstr;
2759 set_string_field(conf, conf->variable, str);
2760 set_string_field(conf, &conf->tentative_val, str);
2761 conf->gen.source = conf->gen.reset_source;
2762 conf->gen.tentative_source = conf->gen.reset_source;
2763 conf->gen.status |= GUC_HAVE_TENTATIVE;
2769 if (gconf->flags & GUC_REPORT)
2770 ReportGUCOption(gconf);
2777 * Push previous state during first assignment to a GUC variable
2778 * within a particular transaction.
2780 * We have to be willing to "back-fill" the state stack if the first
2781 * assignment occurs within a subtransaction nested several levels deep.
2782 * This ensures that if an intermediate transaction aborts, it will have
2783 * the proper value available to restore the setting to.
2786 push_old_value(struct config_generic * gconf)
2788 int my_level = GetCurrentTransactionNestLevel();
2791 /* If we're not inside a transaction, do nothing */
2797 /* Done if we already pushed it at this nesting depth */
2798 if (gconf->stack && gconf->stack->nest_level >= my_level)
2802 * We keep all the stack entries in TopTransactionContext so as to
2803 * avoid allocation problems when a subtransaction back-fills
2804 * stack entries for upper transaction levels.
2806 stack = (GucStack *) MemoryContextAlloc(TopTransactionContext,
2809 stack->prev = gconf->stack;
2810 stack->nest_level = stack->prev ? stack->prev->nest_level + 1 : 1;
2811 stack->status = gconf->status;
2812 stack->tentative_source = gconf->tentative_source;
2813 stack->source = gconf->source;
2815 switch (gconf->vartype)
2818 stack->tentative_val.boolval =
2819 ((struct config_bool *) gconf)->tentative_val;
2820 stack->value.boolval =
2821 *((struct config_bool *) gconf)->variable;
2825 stack->tentative_val.intval =
2826 ((struct config_int *) gconf)->tentative_val;
2827 stack->value.intval =
2828 *((struct config_int *) gconf)->variable;
2832 stack->tentative_val.realval =
2833 ((struct config_real *) gconf)->tentative_val;
2834 stack->value.realval =
2835 *((struct config_real *) gconf)->variable;
2839 stack->tentative_val.stringval =
2840 ((struct config_string *) gconf)->tentative_val;
2841 stack->value.stringval =
2842 *((struct config_string *) gconf)->variable;
2846 gconf->stack = stack;
2848 /* Set state to indicate nothing happened yet within this level */
2849 gconf->status = GUC_HAVE_STACK;
2851 /* Ensure we remember to pop at end of xact */
2857 * Do GUC processing at transaction or subtransaction commit or abort.
2860 AtEOXact_GUC(bool isCommit, bool isSubXact)
2865 /* Quick exit if nothing's changed in this transaction */
2869 /* Prevent memory leak if ereport during an assign_hook */
2870 if (guc_string_workspace)
2872 free(guc_string_workspace);
2873 guc_string_workspace = NULL;
2876 my_level = GetCurrentTransactionNestLevel();
2877 Assert(isSubXact ? (my_level > 1) : (my_level == 1));
2879 for (i = 0; i < num_guc_variables; i++)
2881 struct config_generic *gconf = guc_variables[i];
2882 int my_status = gconf->status;
2883 GucStack *stack = gconf->stack;
2888 * Skip if nothing's happened to this var in this transaction
2892 Assert(stack == NULL);
2895 /* Assert that we stacked old value before changing it */
2896 Assert(stack != NULL && (my_status & GUC_HAVE_STACK));
2897 /* However, the last change may have been at an outer xact level */
2898 if (stack->nest_level < my_level)
2900 Assert(stack->nest_level == my_level);
2903 * We will pop the stack entry. Start by restoring outer xact
2904 * status (since we may want to modify it below). Be careful to
2905 * use my_status to reference the inner xact status below this
2908 gconf->status = stack->status;
2911 * We have two cases:
2913 * If commit and HAVE_TENTATIVE, set actual value to tentative (this
2914 * is to override a SET LOCAL if one occurred later than SET). We
2915 * keep the tentative value and propagate HAVE_TENTATIVE to the
2916 * parent status, allowing the SET's effect to percolate up. (But
2917 * if we're exiting the outermost transaction, we'll drop the
2918 * HAVE_TENTATIVE bit below.)
2920 * Otherwise, we have a transaction that aborted or executed only SET
2921 * LOCAL (or no SET at all). In either case it should have no
2922 * further effect, so restore both tentative and actual values
2923 * from the stack entry.
2926 useTentative = isCommit && (my_status & GUC_HAVE_TENTATIVE) != 0;
2929 switch (gconf->vartype)
2933 struct config_bool *conf = (struct config_bool *) gconf;
2935 GucSource newsource;
2939 newval = conf->tentative_val;
2940 newsource = conf->gen.tentative_source;
2941 conf->gen.status |= GUC_HAVE_TENTATIVE;
2945 newval = stack->value.boolval;
2946 newsource = stack->source;
2947 conf->tentative_val = stack->tentative_val.boolval;
2948 conf->gen.tentative_source = stack->tentative_source;
2951 if (*conf->variable != newval)
2953 if (conf->assign_hook)
2954 if (!(*conf->assign_hook) (newval,
2955 true, PGC_S_OVERRIDE))
2956 elog(LOG, "failed to commit %s",
2958 *conf->variable = newval;
2961 conf->gen.source = newsource;
2966 struct config_int *conf = (struct config_int *) gconf;
2968 GucSource newsource;
2972 newval = conf->tentative_val;
2973 newsource = conf->gen.tentative_source;
2974 conf->gen.status |= GUC_HAVE_TENTATIVE;
2978 newval = stack->value.intval;
2979 newsource = stack->source;
2980 conf->tentative_val = stack->tentative_val.intval;
2981 conf->gen.tentative_source = stack->tentative_source;
2984 if (*conf->variable != newval)
2986 if (conf->assign_hook)
2987 if (!(*conf->assign_hook) (newval,
2988 true, PGC_S_OVERRIDE))
2989 elog(LOG, "failed to commit %s",
2991 *conf->variable = newval;
2994 conf->gen.source = newsource;
2999 struct config_real *conf = (struct config_real *) gconf;
3001 GucSource newsource;
3005 newval = conf->tentative_val;
3006 newsource = conf->gen.tentative_source;
3007 conf->gen.status |= GUC_HAVE_TENTATIVE;
3011 newval = stack->value.realval;
3012 newsource = stack->source;
3013 conf->tentative_val = stack->tentative_val.realval;
3014 conf->gen.tentative_source = stack->tentative_source;
3017 if (*conf->variable != newval)
3019 if (conf->assign_hook)
3020 if (!(*conf->assign_hook) (newval,
3021 true, PGC_S_OVERRIDE))
3022 elog(LOG, "failed to commit %s",
3024 *conf->variable = newval;
3027 conf->gen.source = newsource;
3032 struct config_string *conf = (struct config_string *) gconf;
3034 GucSource newsource;
3038 newval = conf->tentative_val;
3039 newsource = conf->gen.tentative_source;
3040 conf->gen.status |= GUC_HAVE_TENTATIVE;
3044 newval = stack->value.stringval;
3045 newsource = stack->source;
3046 set_string_field(conf, &conf->tentative_val,
3047 stack->tentative_val.stringval);
3048 conf->gen.tentative_source = stack->tentative_source;
3051 if (*conf->variable != newval)
3053 if (conf->assign_hook)
3057 newstr = (*conf->assign_hook) (newval, true,
3060 elog(LOG, "failed to commit %s",
3062 else if (newstr != newval)
3065 * If newval should now be freed, it'll be
3066 * taken care of below.
3068 * See notes in set_config_option about
3071 newval = (char *) newstr;
3075 set_string_field(conf, conf->variable, newval);
3078 conf->gen.source = newsource;
3079 /* Release stacked values if not used anymore */
3080 set_string_field(conf, &stack->value.stringval,
3082 set_string_field(conf, &stack->tentative_val.stringval,
3084 /* Don't store tentative value separately after commit */
3086 set_string_field(conf, &conf->tentative_val, NULL);
3091 /* Finish popping the state stack */
3092 gconf->stack = stack->prev;
3096 * If we're now out of all xact levels, forget TENTATIVE status
3097 * bit; there's nothing tentative about the value anymore.
3101 Assert(gconf->stack == NULL);
3105 /* Report new value if we changed it */
3106 if (changed && (gconf->flags & GUC_REPORT))
3107 ReportGUCOption(gconf);
3111 * If we're now out of all xact levels, we can clear guc_dirty. (Note:
3112 * we cannot reset guc_dirty when exiting a subtransaction, because we
3113 * know that all outer transaction levels will have stacked values to
3122 * Start up automatic reporting of changes to variables marked GUC_REPORT.
3123 * This is executed at completion of backend startup.
3126 BeginReportingGUCOptions(void)
3131 * Don't do anything unless talking to an interactive frontend of
3132 * protocol 3.0 or later.
3134 if (whereToSendOutput != Remote ||
3135 PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
3138 reporting_enabled = true;
3140 /* Transmit initial values of interesting variables */
3141 for (i = 0; i < num_guc_variables; i++)
3143 struct config_generic *conf = guc_variables[i];
3145 if (conf->flags & GUC_REPORT)
3146 ReportGUCOption(conf);
3151 * ReportGUCOption: if appropriate, transmit option value to frontend
3154 ReportGUCOption(struct config_generic * record)
3156 if (reporting_enabled && (record->flags & GUC_REPORT))
3158 char *val = _ShowOption(record);
3159 StringInfoData msgbuf;
3161 pq_beginmessage(&msgbuf, 'S');
3162 pq_sendstring(&msgbuf, record->name);
3163 pq_sendstring(&msgbuf, val);
3164 pq_endmessage(&msgbuf);
3172 * Try to interpret value as boolean value. Valid values are: true,
3173 * false, yes, no, on, off, 1, 0. If the string parses okay, return
3174 * true, else false. If result is not NULL, return the parsing result
3178 parse_bool(const char *value, bool *result)
3180 size_t len = strlen(value);
3182 if (pg_strncasecmp(value, "true", len) == 0)
3187 else if (pg_strncasecmp(value, "false", len) == 0)
3193 else if (pg_strncasecmp(value, "yes", len) == 0)
3198 else if (pg_strncasecmp(value, "no", len) == 0)
3204 else if (pg_strcasecmp(value, "on") == 0)
3209 else if (pg_strcasecmp(value, "off") == 0)
3215 else if (pg_strcasecmp(value, "1") == 0)
3220 else if (pg_strcasecmp(value, "0") == 0)
3234 * Try to parse value as an integer. The accepted formats are the
3235 * usual decimal, octal, or hexadecimal formats. If the string parses
3236 * okay, return true, else false. If result is not NULL, return the
3240 parse_int(const char *value, int *result)
3246 val = strtol(value, &endptr, 0);
3247 if (endptr == value || *endptr != '\0' || errno == ERANGE
3248 #ifdef HAVE_LONG_INT_64
3249 /* if long > 32 bits, check for overflow of int4 */
3250 || val != (long) ((int32) val)
3255 *result = (int) val;
3262 * Try to parse value as a floating point constant in the usual
3263 * format. If the value parsed okay return true, else false. If
3264 * result is not NULL, return the semantic value there.
3267 parse_real(const char *value, double *result)
3273 val = strtod(value, &endptr);
3274 if (endptr == value || *endptr != '\0' || errno == ERANGE)
3284 * Sets option `name' to given value. The value should be a string
3285 * which is going to be parsed and converted to the appropriate data
3286 * type. The context and source parameters indicate in which context this
3287 * function is being called so it can apply the access restrictions
3290 * If value is NULL, set the option to its default value. If the
3291 * parameter changeVal is false then don't really set the option but do all
3292 * the checks to see if it would work.
3294 * If there is an error (non-existing option, invalid value) then an
3295 * ereport(ERROR) is thrown *unless* this is called in a context where we
3296 * don't want to ereport (currently, startup or SIGHUP config file reread).
3297 * In that case we write a suitable error message via ereport(DEBUG) and
3298 * return false. This is working around the deficiencies in the ereport
3299 * mechanism, so don't blame me. In all other cases, the function
3300 * returns true, including cases where the input is valid but we chose
3301 * not to apply it because of context or source-priority considerations.
3303 * See also SetConfigOption for an external interface.
3306 set_config_option(const char *name, const char *value,
3307 GucContext context, GucSource source,
3308 bool isLocal, bool changeVal)
3310 struct config_generic *record;
3314 if (context == PGC_SIGHUP || source == PGC_S_DEFAULT)
3317 * To avoid cluttering the log, only the postmaster bleats loudly
3318 * about problems with the config file.
3320 elevel = IsUnderPostmaster ? DEBUG2 : LOG;
3322 else if (source == PGC_S_DATABASE || source == PGC_S_USER)
3327 record = find_option(name, elevel);
3331 (errcode(ERRCODE_UNDEFINED_OBJECT),
3332 errmsg("unrecognized configuration parameter \"%s\"", name)));
3337 * Check if the option can be set at this time. See guc.h for the
3338 * precise rules. Note that we don't want to throw errors if we're in
3339 * the SIGHUP context. In that case we just ignore the attempt and
3342 switch (record->context)
3345 if (context == PGC_SIGHUP)
3347 if (context != PGC_INTERNAL)
3350 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3351 errmsg("parameter \"%s\" cannot be changed",
3356 case PGC_POSTMASTER:
3357 if (context == PGC_SIGHUP)
3359 if (context != PGC_POSTMASTER)
3362 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3363 errmsg("parameter \"%s\" cannot be changed after server start",
3369 if (context != PGC_SIGHUP && context != PGC_POSTMASTER)
3372 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3373 errmsg("parameter \"%s\" cannot be changed now",
3379 * Hmm, the idea of the SIGHUP context is "ought to be global,
3380 * but can be changed after postmaster start". But there's
3381 * nothing that prevents a crafty administrator from sending
3382 * SIGHUP signals to individual backends only.
3386 if (context == PGC_SIGHUP)
3389 * If a PGC_BACKEND parameter is changed in the config
3390 * file, we want to accept the new value in the postmaster
3391 * (whence it will propagate to subsequently-started
3392 * backends), but ignore it in existing backends. This is
3393 * a tad klugy, but necessary because we don't re-read the
3394 * config file during backend start.
3396 if (IsUnderPostmaster)
3399 else if (context != PGC_BACKEND && context != PGC_POSTMASTER)
3402 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
3403 errmsg("parameter \"%s\" cannot be set after connection start",
3409 if (context == PGC_USERSET || context == PGC_BACKEND)
3412 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3413 errmsg("permission denied to set parameter \"%s\"",
3424 * Should we set reset/stacked values? (If so, the behavior is not
3427 makeDefault = changeVal && (source <= PGC_S_OVERRIDE) && (value != NULL);
3430 * Ignore attempted set if overridden by previously processed setting.
3431 * However, if changeVal is false then plow ahead anyway since we are
3432 * trying to find out if the value is potentially good, not actually
3433 * use it. Also keep going if makeDefault is true, since we may want
3434 * to set the reset/stacked values even if we can't set the variable
3437 if (record->source > source)
3439 if (changeVal && !makeDefault)
3441 elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
3449 * Evaluate value and set variable.
3451 switch (record->vartype)
3455 struct config_bool *conf = (struct config_bool *) record;
3460 if (!parse_bool(value, &newval))
3463 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3464 errmsg("parameter \"%s\" requires a Boolean value",
3471 newval = conf->reset_val;
3472 source = conf->gen.reset_source;
3475 if (conf->assign_hook)
3476 if (!(*conf->assign_hook) (newval, changeVal, source))
3479 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3480 errmsg("invalid value for parameter \"%s\": %d",
3481 name, (int) newval)));
3485 if (changeVal || makeDefault)
3487 /* Save old value to support transaction abort */
3489 push_old_value(&conf->gen);
3492 *conf->variable = newval;
3493 conf->gen.source = source;
3499 if (conf->gen.reset_source <= source)
3501 conf->reset_val = newval;
3502 conf->gen.reset_source = source;
3504 for (stack = conf->gen.stack; stack; stack = stack->prev)
3506 if (stack->source <= source)
3508 stack->value.boolval = newval;
3509 stack->source = source;
3515 conf->gen.status |= GUC_HAVE_LOCAL;
3520 conf->tentative_val = newval;
3521 conf->gen.tentative_source = source;
3522 conf->gen.status |= GUC_HAVE_TENTATIVE;
3531 struct config_int *conf = (struct config_int *) record;
3536 if (!parse_int(value, &newval))
3539 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3540 errmsg("parameter \"%s\" requires an integer value",
3544 if (newval < conf->min || newval > conf->max)
3547 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3548 errmsg("%d is outside the valid range for parameter \"%s\" (%d .. %d)",
3549 newval, name, conf->min, conf->max)));
3555 newval = conf->reset_val;
3556 source = conf->gen.reset_source;
3559 if (conf->assign_hook)
3560 if (!(*conf->assign_hook) (newval, changeVal, source))
3563 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3564 errmsg("invalid value for parameter \"%s\": %d",
3569 if (changeVal || makeDefault)
3571 /* Save old value to support transaction abort */
3573 push_old_value(&conf->gen);
3576 *conf->variable = newval;
3577 conf->gen.source = source;
3583 if (conf->gen.reset_source <= source)
3585 conf->reset_val = newval;
3586 conf->gen.reset_source = source;
3588 for (stack = conf->gen.stack; stack; stack = stack->prev)
3590 if (stack->source <= source)
3592 stack->value.intval = newval;
3593 stack->source = source;
3599 conf->gen.status |= GUC_HAVE_LOCAL;
3604 conf->tentative_val = newval;
3605 conf->gen.tentative_source = source;
3606 conf->gen.status |= GUC_HAVE_TENTATIVE;
3615 struct config_real *conf = (struct config_real *) record;
3620 if (!parse_real(value, &newval))
3623 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3624 errmsg("parameter \"%s\" requires a numeric value",
3628 if (newval < conf->min || newval > conf->max)
3631 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3632 errmsg("%g is outside the valid range for parameter \"%s\" (%g .. %g)",
3633 newval, name, conf->min, conf->max)));
3639 newval = conf->reset_val;
3640 source = conf->gen.reset_source;
3643 if (conf->assign_hook)
3644 if (!(*conf->assign_hook) (newval, changeVal, source))
3647 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3648 errmsg("invalid value for parameter \"%s\": %g",
3653 if (changeVal || makeDefault)
3655 /* Save old value to support transaction abort */
3657 push_old_value(&conf->gen);
3660 *conf->variable = newval;
3661 conf->gen.source = source;
3667 if (conf->gen.reset_source <= source)
3669 conf->reset_val = newval;
3670 conf->gen.reset_source = source;
3672 for (stack = conf->gen.stack; stack; stack = stack->prev)
3674 if (stack->source <= source)
3676 stack->value.realval = newval;
3677 stack->source = source;
3683 conf->gen.status |= GUC_HAVE_LOCAL;
3688 conf->tentative_val = newval;
3689 conf->gen.tentative_source = source;
3690 conf->gen.status |= GUC_HAVE_TENTATIVE;
3699 struct config_string *conf = (struct config_string *) record;
3704 newval = guc_strdup(elevel, value);
3708 else if (conf->reset_val)
3711 * We could possibly avoid strdup here, but easier to
3712 * make this case work the same as the normal
3715 newval = guc_strdup(elevel, conf->reset_val);
3718 source = conf->gen.reset_source;
3722 /* Nothing to reset to, as yet; so do nothing */
3727 * Remember string in workspace, so that we can free it
3728 * and avoid a permanent memory leak if hook ereports.
3730 if (guc_string_workspace)
3731 free(guc_string_workspace);
3732 guc_string_workspace = newval;
3734 if (conf->assign_hook)
3736 const char *hookresult;
3738 hookresult = (*conf->assign_hook) (newval,
3740 guc_string_workspace = NULL;
3741 if (hookresult == NULL)
3745 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3746 errmsg("invalid value for parameter \"%s\": \"%s\"",
3747 name, value ? value : "")));
3750 else if (hookresult != newval)
3755 * Having to cast away const here is annoying, but
3756 * the alternative is to declare assign_hooks as
3757 * returning char*, which would mean they'd have
3758 * to cast away const, or as both taking and
3759 * returning char*, which doesn't seem attractive
3760 * either --- we don't want them to scribble on
3763 newval = (char *) hookresult;
3767 guc_string_workspace = NULL;
3769 if (changeVal || makeDefault)
3771 /* Save old value to support transaction abort */
3773 push_old_value(&conf->gen);
3776 set_string_field(conf, conf->variable, newval);
3777 conf->gen.source = source;
3783 if (conf->gen.reset_source <= source)
3785 set_string_field(conf, &conf->reset_val, newval);
3786 conf->gen.reset_source = source;
3788 for (stack = conf->gen.stack; stack; stack = stack->prev)
3790 if (stack->source <= source)
3792 set_string_field(conf, &stack->value.stringval,
3794 stack->source = source;
3797 /* Perhaps we didn't install newval anywhere */
3798 if (!string_field_used(conf, newval))
3803 conf->gen.status |= GUC_HAVE_LOCAL;
3808 set_string_field(conf, &conf->tentative_val, newval);
3809 conf->gen.tentative_source = source;
3810 conf->gen.status |= GUC_HAVE_TENTATIVE;
3820 if (changeVal && (record->flags & GUC_REPORT))
3821 ReportGUCOption(record);
3828 * Set a config option to the given value. See also set_config_option,
3829 * this is just the wrapper to be called from outside GUC. NB: this
3830 * is used only for non-transactional operations.
3833 SetConfigOption(const char *name, const char *value,
3834 GucContext context, GucSource source)
3836 (void) set_config_option(name, value, context, source, false, true);
3842 * Fetch the current value of the option `name'. If the option doesn't exist,
3843 * throw an ereport and don't return.
3845 * The string is *not* allocated for modification and is really only
3846 * valid until the next call to configuration related functions.
3849 GetConfigOption(const char *name)
3851 struct config_generic *record;
3852 static char buffer[256];
3854 record = find_option(name, ERROR);
3857 (errcode(ERRCODE_UNDEFINED_OBJECT),
3858 errmsg("unrecognized configuration parameter \"%s\"", name)));
3859 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
3861 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3862 errmsg("must be superuser to examine \"%s\"", name)));
3864 switch (record->vartype)
3867 return *((struct config_bool *) record)->variable ? "on" : "off";
3870 snprintf(buffer, sizeof(buffer), "%d",
3871 *((struct config_int *) record)->variable);
3875 snprintf(buffer, sizeof(buffer), "%g",
3876 *((struct config_real *) record)->variable);
3880 return *((struct config_string *) record)->variable;
3886 * Get the RESET value associated with the given option.
3889 GetConfigOptionResetString(const char *name)
3891 struct config_generic *record;
3892 static char buffer[256];
3894 record = find_option(name, ERROR);
3897 (errcode(ERRCODE_UNDEFINED_OBJECT),
3898 errmsg("unrecognized configuration parameter \"%s\"", name)));
3899 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
3901 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3902 errmsg("must be superuser to examine \"%s\"", name)));
3904 switch (record->vartype)
3907 return ((struct config_bool *) record)->reset_val ? "on" : "off";
3910 snprintf(buffer, sizeof(buffer), "%d",
3911 ((struct config_int *) record)->reset_val);
3915 snprintf(buffer, sizeof(buffer), "%g",
3916 ((struct config_real *) record)->reset_val);
3920 return ((struct config_string *) record)->reset_val;
3926 * Detect whether the given configuration option can only be set by
3930 IsSuperuserConfigOption(const char *name)
3932 struct config_generic *record;
3934 record = find_option(name, ERROR);
3935 /* On an unrecognized name, don't error, just return false. */
3938 return (record->context == PGC_SUSET);
3943 * flatten_set_variable_args
3944 * Given a parsenode List as emitted by the grammar for SET,
3945 * convert to the flat string representation used by GUC.
3947 * We need to be told the name of the variable the args are for, because
3948 * the flattening rules vary (ugh).
3950 * The result is NULL if input is NIL (ie, SET ... TO DEFAULT), otherwise
3951 * a palloc'd string.
3954 flatten_set_variable_args(const char *name, List *args)
3956 struct config_generic *record;
3962 * Fast path if just DEFAULT. We do not check the variable name in
3963 * this case --- necessary for RESET ALL to work correctly.
3968 /* Else get flags for the variable */
3969 record = find_option(name, ERROR);
3972 (errcode(ERRCODE_UNDEFINED_OBJECT),
3973 errmsg("unrecognized configuration parameter \"%s\"", name)));
3975 flags = record->flags;
3977 /* Complain if list input and non-list variable */
3978 if ((flags & GUC_LIST_INPUT) == 0 &&
3979 list_length(args) != 1)
3981 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3982 errmsg("SET %s takes only one argument", name)));
3984 initStringInfo(&buf);
3988 A_Const *arg = (A_Const *) lfirst(l);
3991 if (l != list_head(args))
3992 appendStringInfo(&buf, ", ");
3994 if (!IsA(arg, A_Const))
3995 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
3997 switch (nodeTag(&arg->val))
4000 appendStringInfo(&buf, "%ld", intVal(&arg->val));
4003 /* represented as a string, so just copy it */
4004 appendStringInfoString(&buf, strVal(&arg->val));
4007 val = strVal(&arg->val);
4008 if (arg->typename != NULL)
4011 * Must be a ConstInterval argument for TIME ZONE.
4012 * Coerce to interval and back to normalize the value
4013 * and account for any typmod.
4019 DirectFunctionCall3(interval_in,
4020 CStringGetDatum(val),
4021 ObjectIdGetDatum(InvalidOid),
4022 Int32GetDatum(arg->typename->typmod));
4025 DatumGetCString(DirectFunctionCall1(interval_out,
4027 appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
4032 * Plain string literal or identifier. For quote
4033 * mode, quote it if it's not a vanilla identifier.
4035 if (flags & GUC_LIST_QUOTE)
4036 appendStringInfoString(&buf, quote_identifier(val));
4038 appendStringInfoString(&buf, val);
4042 elog(ERROR, "unrecognized node type: %d",
4043 (int) nodeTag(&arg->val));
4056 SetPGVariable(const char *name, List *args, bool is_local)
4058 char *argstring = flatten_set_variable_args(name, args);
4060 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
4061 set_config_option(name,
4063 (superuser() ? PGC_SUSET : PGC_USERSET),
4070 * SET command wrapped as a SQL callable function.
4073 set_config_by_name(PG_FUNCTION_ARGS)
4081 if (PG_ARGISNULL(0))
4083 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
4084 errmsg("SET requires parameter name")));
4086 /* Get the GUC variable name */
4087 name = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(0)));
4089 /* Get the desired value or set to NULL for a reset request */
4090 if (PG_ARGISNULL(1))
4093 value = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(1)));
4096 * Get the desired state of is_local. Default to false if provided
4099 if (PG_ARGISNULL(2))
4102 is_local = PG_GETARG_BOOL(2);
4104 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
4105 set_config_option(name,
4107 (superuser() ? PGC_SUSET : PGC_USERSET),
4112 /* get the new current value */
4113 new_value = GetConfigOptionByName(name, NULL);
4115 /* Convert return string to text */
4116 result_text = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(new_value)));
4119 PG_RETURN_TEXT_P(result_text);
4123 define_custom_variable(struct config_generic * variable)
4125 const char *name = variable->name;
4126 const char **nameAddr = &name;
4128 struct config_string *pHolder;
4129 struct config_generic **res = (struct config_generic **) bsearch(
4131 (void *) guc_variables,
4133 sizeof(struct config_generic *),
4138 add_guc_variable(variable, ERROR);
4143 * This better be a placeholder
4145 if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
4147 (errcode(ERRCODE_INTERNAL_ERROR),
4148 errmsg("attempt to redefine parameter \"%s\"", name)));
4150 Assert((*res)->vartype == PGC_STRING);
4151 pHolder = (struct config_string *) * res;
4153 /* We have the same name, no sorting is necessary */
4156 value = *pHolder->variable;
4159 * Assign the string value stored in the placeholder to the real
4162 * XXX this is not really good enough --- it should be a nontransactional
4163 * assignment, since we don't want it to roll back if the current xact
4166 set_config_option(name, value,
4167 pHolder->gen.context, pHolder->gen.source,
4171 * Free up as much as we conveniently can of the placeholder structure
4172 * (this neglects any stack items...)
4174 set_string_field(pHolder, pHolder->variable, NULL);
4175 set_string_field(pHolder, &pHolder->reset_val, NULL);
4176 set_string_field(pHolder, &pHolder->tentative_val, NULL);
4182 init_custom_variable(struct config_generic * gen,
4184 const char *short_desc,
4185 const char *long_desc,
4187 enum config_type type)
4189 gen->name = guc_strdup(ERROR, name);
4190 gen->context = context;
4191 gen->group = CUSTOM_OPTIONS;
4192 gen->short_desc = short_desc;
4193 gen->long_desc = long_desc;
4194 gen->vartype = type;
4198 DefineCustomBoolVariable(
4200 const char *short_desc,
4201 const char *long_desc,
4204 GucBoolAssignHook assign_hook,
4205 GucShowHook show_hook)
4207 size_t sz = sizeof(struct config_bool);
4208 struct config_bool *var = (struct config_bool *) guc_malloc(ERROR, sz);
4211 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_BOOL);
4213 var->variable = valueAddr;
4214 var->reset_val = *valueAddr;
4215 var->assign_hook = assign_hook;
4216 var->show_hook = show_hook;
4217 define_custom_variable(&var->gen);
4221 DefineCustomIntVariable(
4223 const char *short_desc,
4224 const char *long_desc,
4229 GucIntAssignHook assign_hook,
4230 GucShowHook show_hook)
4232 size_t sz = sizeof(struct config_int);
4233 struct config_int *var = (struct config_int *) guc_malloc(ERROR, sz);
4236 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_INT);
4238 var->variable = valueAddr;
4239 var->reset_val = *valueAddr;
4240 var->min = minValue;
4241 var->max = maxValue;
4242 var->assign_hook = assign_hook;
4243 var->show_hook = show_hook;
4244 define_custom_variable(&var->gen);
4248 DefineCustomRealVariable(
4250 const char *short_desc,
4251 const char *long_desc,
4256 GucRealAssignHook assign_hook,
4257 GucShowHook show_hook)
4259 size_t sz = sizeof(struct config_real);
4260 struct config_real *var = (struct config_real *) guc_malloc(ERROR, sz);
4263 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_REAL);
4265 var->variable = valueAddr;
4266 var->reset_val = *valueAddr;
4267 var->min = minValue;
4268 var->max = maxValue;
4269 var->assign_hook = assign_hook;
4270 var->show_hook = show_hook;
4271 define_custom_variable(&var->gen);
4275 DefineCustomStringVariable(
4277 const char *short_desc,
4278 const char *long_desc,
4281 GucStringAssignHook assign_hook,
4282 GucShowHook show_hook)
4284 size_t sz = sizeof(struct config_string);
4285 struct config_string *var = (struct config_string *) guc_malloc(ERROR, sz);
4288 init_custom_variable(&var->gen, name, short_desc, long_desc, context, PGC_STRING);
4290 var->variable = valueAddr;
4291 var->reset_val = *valueAddr;
4292 var->assign_hook = assign_hook;
4293 var->show_hook = show_hook;
4294 define_custom_variable(&var->gen);
4298 EmitWarningsOnPlaceholders(const char *className)
4300 struct config_generic **vars = guc_variables;
4301 struct config_generic **last = vars + num_guc_variables;
4303 int nameLen = strlen(className);
4307 struct config_generic *var = *vars++;
4309 if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
4310 strncmp(className, var->name, nameLen) == 0 &&
4311 var->name[nameLen] == GUC_QUALIFIER_SEPARATOR)
4314 (errcode(ERRCODE_UNDEFINED_OBJECT),
4315 errmsg("unrecognized configuration parameter \"%s\"", var->name)));
4325 GetPGVariable(const char *name, DestReceiver *dest)
4327 if (pg_strcasecmp(name, "all") == 0)
4328 ShowAllGUCConfig(dest);
4330 ShowGUCConfigOption(name, dest);
4334 GetPGVariableResultDesc(const char *name)
4338 if (pg_strcasecmp(name, "all") == 0)
4340 /* need a tuple descriptor representing three TEXT columns */
4341 tupdesc = CreateTemplateTupleDesc(3, false);
4342 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
4344 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
4346 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
4352 const char *varname;
4354 /* Get the canonical spelling of name */
4355 (void) GetConfigOptionByName(name, &varname);
4357 /* need a tuple descriptor representing a single TEXT column */
4358 tupdesc = CreateTemplateTupleDesc(1, false);
4359 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
4369 ResetPGVariable(const char *name)
4371 if (pg_strcasecmp(name, "all") == 0)
4374 set_config_option(name,
4376 (superuser() ? PGC_SUSET : PGC_USERSET),
4387 ShowGUCConfigOption(const char *name, DestReceiver *dest)
4389 TupOutputState *tstate;
4391 const char *varname;
4394 /* Get the value and canonical spelling of name */
4395 value = GetConfigOptionByName(name, &varname);
4397 /* need a tuple descriptor representing a single TEXT column */
4398 tupdesc = CreateTemplateTupleDesc(1, false);
4399 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
4402 /* prepare for projection of tuples */
4403 tstate = begin_tup_output_tupdesc(dest, tupdesc);
4406 do_text_output_oneline(tstate, value);
4408 end_tup_output(tstate);
4415 ShowAllGUCConfig(DestReceiver *dest)
4417 bool am_superuser = superuser();
4419 TupOutputState *tstate;
4423 /* need a tuple descriptor representing three TEXT columns */
4424 tupdesc = CreateTemplateTupleDesc(3, false);
4425 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
4427 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
4429 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
4433 /* prepare for projection of tuples */
4434 tstate = begin_tup_output_tupdesc(dest, tupdesc);
4436 for (i = 0; i < num_guc_variables; i++)
4438 struct config_generic *conf = guc_variables[i];
4440 if ((conf->flags & GUC_NO_SHOW_ALL) ||
4441 ((conf->flags & GUC_SUPERUSER_ONLY) && !am_superuser))
4444 /* assign to the values array */
4445 values[0] = (char *) conf->name;
4446 values[1] = _ShowOption(conf);
4447 values[2] = (char *) conf->short_desc;
4449 /* send it to dest */
4450 do_tup_output(tstate, values);
4453 if (values[1] != NULL)
4457 end_tup_output(tstate);
4461 * Return GUC variable value by name; optionally return canonical
4462 * form of name. Return value is palloc'd.
4465 GetConfigOptionByName(const char *name, const char **varname)
4467 struct config_generic *record;
4469 record = find_option(name, ERROR);
4472 (errcode(ERRCODE_UNDEFINED_OBJECT),
4473 errmsg("unrecognized configuration parameter \"%s\"", name)));
4474 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
4476 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4477 errmsg("must be superuser to examine \"%s\"", name)));
4480 *varname = record->name;
4482 return _ShowOption(record);
4486 * Return GUC variable value by variable number; optionally return canonical
4487 * form of name. Return value is palloc'd.
4490 GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
4493 struct config_generic *conf;
4495 /* check requested variable number valid */
4496 Assert((varnum >= 0) && (varnum < num_guc_variables));
4498 conf = guc_variables[varnum];
4502 if ((conf->flags & GUC_NO_SHOW_ALL) ||
4503 ((conf->flags & GUC_SUPERUSER_ONLY) && !superuser()))
4509 /* first get the generic attributes */
4512 values[0] = conf->name;
4514 /* setting : use _ShowOption in order to avoid duplicating the logic */
4515 values[1] = _ShowOption(conf);
4518 values[2] = config_group_names[conf->group];
4521 values[3] = conf->short_desc;
4524 values[4] = conf->long_desc;
4527 values[5] = GucContext_Names[conf->context];
4530 values[6] = config_type_names[conf->vartype];
4533 values[7] = GucSource_Names[conf->source];
4535 /* now get the type specifc attributes */
4536 switch (conf->vartype)
4550 struct config_int *lconf = (struct config_int *) conf;
4553 snprintf(buffer, sizeof(buffer), "%d", lconf->min);
4554 values[8] = pstrdup(buffer);
4557 snprintf(buffer, sizeof(buffer), "%d", lconf->max);
4558 values[9] = pstrdup(buffer);
4564 struct config_real *lconf = (struct config_real *) conf;
4567 snprintf(buffer, sizeof(buffer), "%g", lconf->min);
4568 values[8] = pstrdup(buffer);
4571 snprintf(buffer, sizeof(buffer), "%g", lconf->max);
4572 values[9] = pstrdup(buffer);
4589 * should never get here, but in case we do, set 'em to
4604 * Return the total number of GUC variables
4607 GetNumConfigOptions(void)
4609 return num_guc_variables;
4613 * show_config_by_name - equiv to SHOW X command but implemented as
4617 show_config_by_name(PG_FUNCTION_ARGS)
4623 /* Get the GUC variable name */
4624 varname = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(0)));
4627 varval = GetConfigOptionByName(varname, NULL);
4629 /* Convert to text */
4630 result_text = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(varval)));
4633 PG_RETURN_TEXT_P(result_text);
4637 * show_all_settings - equiv to SHOW ALL command but implemented as
4640 #define NUM_PG_SETTINGS_ATTS 10
4643 show_all_settings(PG_FUNCTION_ARGS)
4645 FuncCallContext *funcctx;
4649 AttInMetadata *attinmeta;
4650 MemoryContext oldcontext;
4652 /* stuff done only on the first call of the function */
4653 if (SRF_IS_FIRSTCALL())
4655 /* create a function context for cross-call persistence */
4656 funcctx = SRF_FIRSTCALL_INIT();
4659 * switch to memory context appropriate for multiple function
4662 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
4665 * need a tuple descriptor representing NUM_PG_SETTINGS_ATTS
4666 * columns of the appropriate types
4668 tupdesc = CreateTemplateTupleDesc(NUM_PG_SETTINGS_ATTS, false);
4669 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
4671 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
4673 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "category",
4675 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "short_desc",
4677 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "extra_desc",
4679 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "context",
4681 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "vartype",
4683 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "source",
4685 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "min_val",
4687 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "max_val",
4691 * Generate attribute metadata needed later to produce tuples from
4694 attinmeta = TupleDescGetAttInMetadata(tupdesc);
4695 funcctx->attinmeta = attinmeta;
4697 /* total number of tuples to be returned */
4698 funcctx->max_calls = GetNumConfigOptions();
4700 MemoryContextSwitchTo(oldcontext);
4703 /* stuff done on every call of the function */
4704 funcctx = SRF_PERCALL_SETUP();
4706 call_cntr = funcctx->call_cntr;
4707 max_calls = funcctx->max_calls;
4708 attinmeta = funcctx->attinmeta;
4710 if (call_cntr < max_calls) /* do when there is more left to send */
4712 char *values[NUM_PG_SETTINGS_ATTS];
4718 * Get the next visible GUC variable name and value
4722 GetConfigOptionByNum(call_cntr, (const char **) values, &noshow);
4725 /* bump the counter and get the next config setting */
4726 call_cntr = ++funcctx->call_cntr;
4728 /* make sure we haven't gone too far now */
4729 if (call_cntr >= max_calls)
4730 SRF_RETURN_DONE(funcctx);
4735 tuple = BuildTupleFromCStrings(attinmeta, values);
4737 /* make the tuple into a datum */
4738 result = HeapTupleGetDatum(tuple);
4740 SRF_RETURN_NEXT(funcctx, result);
4744 /* do when there is no more left */
4745 SRF_RETURN_DONE(funcctx);
4750 _ShowOption(struct config_generic * record)
4755 switch (record->vartype)
4759 struct config_bool *conf = (struct config_bool *) record;
4761 if (conf->show_hook)
4762 val = (*conf->show_hook) ();
4764 val = *conf->variable ? "on" : "off";
4770 struct config_int *conf = (struct config_int *) record;
4772 if (conf->show_hook)
4773 val = (*conf->show_hook) ();
4776 snprintf(buffer, sizeof(buffer), "%d",
4785 struct config_real *conf = (struct config_real *) record;
4787 if (conf->show_hook)
4788 val = (*conf->show_hook) ();
4791 snprintf(buffer, sizeof(buffer), "%g",
4800 struct config_string *conf = (struct config_string *) record;
4802 if (conf->show_hook)
4803 val = (*conf->show_hook) ();
4804 else if (*conf->variable && **conf->variable)
4805 val = *conf->variable;
4812 /* just to keep compiler quiet */
4817 return pstrdup(val);
4823 * This routine dumps out all non-default GUC options into a binary
4824 * file that is read by all exec'ed backends. The format is:
4826 * variable name, string, null terminated
4827 * variable value, string, null terminated
4828 * variable source, integer
4831 write_nondefault_variables(GucContext context)
4839 Assert(context == PGC_POSTMASTER || context == PGC_SIGHUP);
4842 elevel = (context == PGC_SIGHUP) ? LOG : ERROR;
4847 new_filename = guc_malloc(elevel, strlen(DataDir) + strlen(CONFIG_EXEC_PARAMS) +
4848 strlen(".new") + 2);
4849 if (new_filename == NULL)
4852 filename = guc_malloc(elevel, strlen(DataDir) + strlen(CONFIG_EXEC_PARAMS) + 2);
4853 if (filename == NULL)
4859 sprintf(new_filename, "%s/" CONFIG_EXEC_PARAMS ".new", DataDir);
4860 sprintf(filename, "%s/" CONFIG_EXEC_PARAMS, DataDir);
4862 fp = AllocateFile(new_filename, "w");
4868 (errcode_for_file_access(),
4869 errmsg("could not write to file \"%s\": %m", CONFIG_EXEC_PARAMS)));
4873 for (i = 0; i < num_guc_variables; i++)
4875 struct config_generic *gconf = guc_variables[i];
4877 if (gconf->source != PGC_S_DEFAULT)
4879 fprintf(fp, "%s", gconf->name);
4882 switch (gconf->vartype)
4886 struct config_bool *conf = (struct config_bool *) gconf;
4888 if (*conf->variable == 0)
4889 fprintf(fp, "false");
4891 fprintf(fp, "true");
4897 struct config_int *conf = (struct config_int *) gconf;
4899 fprintf(fp, "%d", *conf->variable);
4905 struct config_real *conf = (struct config_real *) gconf;
4907 /* Could lose precision here? */
4908 fprintf(fp, "%f", *conf->variable);
4914 struct config_string *conf = (struct config_string *) gconf;
4916 fprintf(fp, "%s", *conf->variable);
4923 fwrite(&gconf->source, sizeof(gconf->source), 1, fp);
4932 (errcode_for_file_access(),
4933 errmsg("could not write to file \"%s\": %m", CONFIG_EXEC_PARAMS)));
4938 * Put new file in place. This could delay on Win32, but we don't
4939 * hold any exclusive locks.
4941 rename(new_filename, filename);
4948 * Read string, including null byte from file
4950 * Return NULL on EOF and nothing read
4953 read_string_with_null(FILE *fp)
4962 if ((ch = fgetc(fp)) == EOF)
4967 elog(FATAL, "invalid format of exec config params file");
4970 str = guc_malloc(FATAL, maxlen);
4971 else if (i == maxlen)
4972 str = guc_realloc(FATAL, str, maxlen *= 2);
4981 * This routine loads a previous postmaster dump of its non-default
4985 read_nondefault_variables(void)
4998 filename = guc_malloc(FATAL, strlen(DataDir) + strlen(CONFIG_EXEC_PARAMS) + 2);
4999 sprintf(filename, "%s/" CONFIG_EXEC_PARAMS, DataDir);
5001 fp = AllocateFile(filename, "r");
5005 /* File not found is fine */
5006 if (errno != ENOENT)
5008 (errcode_for_file_access(),
5009 errmsg("could not read from file \"%s\": %m", CONFIG_EXEC_PARAMS)));
5015 struct config_generic *record;
5017 if ((varname = read_string_with_null(fp)) == NULL)
5020 if ((record = find_option(varname, FATAL)) == NULL)
5021 elog(FATAL, "failed to locate variable %s in exec config params file", varname);
5022 if ((varvalue = read_string_with_null(fp)) == NULL)
5023 elog(FATAL, "invalid format of exec config params file");
5024 if (fread(&varsource, sizeof(varsource), 1, fp) == 0)
5025 elog(FATAL, "invalid format of exec config params file");
5027 (void) set_config_option(varname, varvalue, record->context,
5028 varsource, false, true);
5041 * A little "long argument" simulation, although not quite GNU
5042 * compliant. Takes a string of the form "some-option=some value" and
5043 * returns name = "some_option" and value = "some value" in malloc'ed
5044 * storage. Note that '-' is converted to '_' in the option name. If
5045 * there is no '=' in the input string then value will be NULL.
5048 ParseLongOption(const char *string, char **name, char **value)
5057 equal_pos = strcspn(string, "=");
5059 if (string[equal_pos] == '=')
5061 *name = guc_malloc(FATAL, equal_pos + 1);
5062 strncpy(*name, string, equal_pos);
5063 (*name)[equal_pos] = '\0';
5065 *value = guc_strdup(FATAL, &string[equal_pos + 1]);
5069 /* no equal sign in string */
5070 *name = guc_strdup(FATAL, string);
5074 for (cp = *name; *cp; cp++)
5081 * Handle options fetched from pg_database.datconfig or pg_shadow.useconfig.
5082 * The array parameter must be an array of TEXT (it must not be NULL).
5085 ProcessGUCArray(ArrayType *array, GucSource source)
5089 Assert(array != NULL);
5090 Assert(ARR_ELEMTYPE(array) == TEXTOID);
5091 Assert(ARR_NDIM(array) == 1);
5092 Assert(ARR_LBOUND(array)[0] == 1);
5093 Assert(source == PGC_S_DATABASE || source == PGC_S_USER);
5095 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
5103 d = array_ref(array, 1, &i,
5104 -1 /* varlenarray */ ,
5105 -1 /* TEXT's typlen */ ,
5106 false /* TEXT's typbyval */ ,
5107 'i' /* TEXT's typalign */ ,
5113 s = DatumGetCString(DirectFunctionCall1(textout, d));
5115 ParseLongOption(s, &name, &value);
5119 (errcode(ERRCODE_SYNTAX_ERROR),
5120 errmsg("could not parse setting for parameter \"%s\"", name)));
5126 * We process all these options at SUSET level. We assume that
5127 * the right to insert an option into pg_database or pg_shadow was
5128 * checked when it was inserted.
5130 SetConfigOption(name, value, PGC_SUSET, source);
5140 * Add an entry to an option array. The array parameter may be NULL
5141 * to indicate the current table entry is NULL.
5144 GUCArrayAdd(ArrayType *array, const char *name, const char *value)
5146 const char *varname;
5154 /* test if the option is valid */
5155 set_config_option(name, value,
5156 superuser() ? PGC_SUSET : PGC_USERSET,
5157 PGC_S_TEST, false, false);
5159 /* convert name to canonical spelling, so we can use plain strcmp */
5160 (void) GetConfigOptionByName(name, &varname);
5163 newval = palloc(strlen(name) + 1 + strlen(value) + 1);
5164 sprintf(newval, "%s=%s", name, value);
5165 datum = DirectFunctionCall1(textin, CStringGetDatum(newval));
5173 Assert(ARR_ELEMTYPE(array) == TEXTOID);
5174 Assert(ARR_NDIM(array) == 1);
5175 Assert(ARR_LBOUND(array)[0] == 1);
5177 index = ARR_DIMS(array)[0] + 1; /* add after end */
5179 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
5184 d = array_ref(array, 1, &i,
5185 -1 /* varlenarray */ ,
5186 -1 /* TEXT's typlen */ ,
5187 false /* TEXT's typbyval */ ,
5188 'i' /* TEXT's typalign */ ,
5192 current = DatumGetCString(DirectFunctionCall1(textout, d));
5193 if (strncmp(current, newval, strlen(name) + 1) == 0)
5201 a = array_set(array, 1, &index,
5203 -1 /* varlenarray */ ,
5204 -1 /* TEXT's typlen */ ,
5205 false /* TEXT's typbyval */ ,
5206 'i' /* TEXT's typalign */ ,
5210 a = construct_array(&datum, 1,
5219 * Delete an entry from an option array. The array parameter may be NULL
5220 * to indicate the current table entry is NULL. Also, if the return value
5221 * is NULL then a null should be stored.
5224 GUCArrayDelete(ArrayType *array, const char *name)
5226 const char *varname;
5227 ArrayType *newarray;
5233 /* test if the option is valid */
5234 set_config_option(name, NULL,
5235 superuser() ? PGC_SUSET : PGC_USERSET,
5236 PGC_S_TEST, false, false);
5238 /* convert name to canonical spelling, so we can use plain strcmp */
5239 (void) GetConfigOptionByName(name, &varname);
5242 /* if array is currently null, then surely nothing to delete */
5249 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
5255 d = array_ref(array, 1, &i,
5256 -1 /* varlenarray */ ,
5257 -1 /* TEXT's typlen */ ,
5258 false /* TEXT's typbyval */ ,
5259 'i' /* TEXT's typalign */ ,
5263 val = DatumGetCString(DirectFunctionCall1(textout, d));
5265 /* ignore entry if it's what we want to delete */
5266 if (strncmp(val, name, strlen(name)) == 0
5267 && val[strlen(name)] == '=')
5270 /* else add it to the output array */
5274 newarray = array_set(newarray, 1, &index,
5276 -1 /* varlenarray */ ,
5277 -1 /* TEXT's typlen */ ,
5278 false /* TEXT's typbyval */ ,
5279 'i' /* TEXT's typalign */ ,
5283 newarray = construct_array(&d, 1,
5295 * assign_hook subroutines
5299 assign_log_destination(const char *value, bool doit, GucSource source)
5306 /* Need a modifiable copy of string */
5307 rawstring = pstrdup(value);
5309 /* Parse string into list of identifiers */
5310 if (!SplitIdentifierString(rawstring, ',', &elemlist))
5312 /* syntax error in list */
5314 list_free(elemlist);
5315 if (source >= PGC_S_INTERACTIVE)
5317 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5318 errmsg("invalid list syntax for parameter \"log_destination\"")));
5322 foreach(l, elemlist)
5324 char *tok = (char *) lfirst(l);
5326 if (pg_strcasecmp(tok, "stderr") == 0)
5327 newlogdest |= LOG_DESTINATION_STDERR;
5329 else if (pg_strcasecmp(tok, "syslog") == 0)
5330 newlogdest |= LOG_DESTINATION_SYSLOG;
5333 else if (pg_strcasecmp(tok, "eventlog") == 0)
5334 newlogdest |= LOG_DESTINATION_EVENTLOG;
5338 if (source >= PGC_S_INTERACTIVE)
5340 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5341 errmsg("unrecognized \"log_destination\" key word: \"%s\"",
5344 list_free(elemlist);
5350 Log_destination = newlogdest;
5353 list_free(elemlist);
5361 assign_facility(const char *facility, bool doit, GucSource source)
5363 if (pg_strcasecmp(facility, "LOCAL0") == 0)
5365 if (pg_strcasecmp(facility, "LOCAL1") == 0)
5367 if (pg_strcasecmp(facility, "LOCAL2") == 0)
5369 if (pg_strcasecmp(facility, "LOCAL3") == 0)
5371 if (pg_strcasecmp(facility, "LOCAL4") == 0)
5373 if (pg_strcasecmp(facility, "LOCAL5") == 0)
5375 if (pg_strcasecmp(facility, "LOCAL6") == 0)
5377 if (pg_strcasecmp(facility, "LOCAL7") == 0)
5385 assign_defaultxactisolevel(const char *newval, bool doit, GucSource source)
5387 if (pg_strcasecmp(newval, "serializable") == 0)
5390 DefaultXactIsoLevel = XACT_SERIALIZABLE;
5392 else if (pg_strcasecmp(newval, "repeatable read") == 0)
5395 DefaultXactIsoLevel = XACT_REPEATABLE_READ;
5397 else if (pg_strcasecmp(newval, "read committed") == 0)
5400 DefaultXactIsoLevel = XACT_READ_COMMITTED;
5402 else if (pg_strcasecmp(newval, "read uncommitted") == 0)
5405 DefaultXactIsoLevel = XACT_READ_UNCOMMITTED;
5413 assign_log_min_messages(const char *newval,
5414 bool doit, GucSource source)
5416 return (assign_msglvl(&log_min_messages, newval, doit, source));
5420 assign_client_min_messages(const char *newval, bool doit, GucSource source)
5422 return (assign_msglvl(&client_min_messages, newval, doit, source));
5426 assign_min_error_statement(const char *newval, bool doit, GucSource source)
5428 return (assign_msglvl(&log_min_error_statement, newval, doit, source));
5432 assign_msglvl(int *var, const char *newval, bool doit, GucSource source)
5434 if (pg_strcasecmp(newval, "debug") == 0)
5439 else if (pg_strcasecmp(newval, "debug5") == 0)
5444 else if (pg_strcasecmp(newval, "debug4") == 0)
5449 else if (pg_strcasecmp(newval, "debug3") == 0)
5454 else if (pg_strcasecmp(newval, "debug2") == 0)
5459 else if (pg_strcasecmp(newval, "debug1") == 0)
5464 else if (pg_strcasecmp(newval, "log") == 0)
5471 * Client_min_messages always prints 'info', but we allow it as a
5474 else if (pg_strcasecmp(newval, "info") == 0)
5479 else if (pg_strcasecmp(newval, "notice") == 0)
5484 else if (pg_strcasecmp(newval, "warning") == 0)
5489 else if (pg_strcasecmp(newval, "error") == 0)
5494 /* We allow FATAL/PANIC for client-side messages too. */
5495 else if (pg_strcasecmp(newval, "fatal") == 0)
5500 else if (pg_strcasecmp(newval, "panic") == 0)
5506 return NULL; /* fail */
5507 return newval; /* OK */
5511 assign_log_error_verbosity(const char *newval, bool doit, GucSource source)
5513 if (pg_strcasecmp(newval, "terse") == 0)
5516 Log_error_verbosity = PGERROR_TERSE;
5518 else if (pg_strcasecmp(newval, "default") == 0)
5521 Log_error_verbosity = PGERROR_DEFAULT;
5523 else if (pg_strcasecmp(newval, "verbose") == 0)
5526 Log_error_verbosity = PGERROR_VERBOSE;
5529 return NULL; /* fail */
5530 return newval; /* OK */
5534 assign_log_statement(const char *newval, bool doit, GucSource source)
5536 if (pg_strcasecmp(newval, "none") == 0)
5539 log_statement = LOGSTMT_NONE;
5541 else if (pg_strcasecmp(newval, "ddl") == 0)
5544 log_statement = LOGSTMT_DDL;
5546 else if (pg_strcasecmp(newval, "mod") == 0)
5549 log_statement = LOGSTMT_MOD;
5551 else if (pg_strcasecmp(newval, "all") == 0)
5554 log_statement = LOGSTMT_ALL;
5557 return NULL; /* fail */
5558 return newval; /* OK */
5562 show_num_temp_buffers(void)
5565 * We show the GUC var until local buffers have been initialized,
5566 * and NLocBuffer afterwards.
5568 static char nbuf[32];
5570 sprintf(nbuf, "%d", NLocBuffer ? NLocBuffer : num_temp_buffers);
5575 assign_phony_autocommit(bool newval, bool doit, GucSource source)
5579 if (doit && source >= PGC_S_INTERACTIVE)
5581 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5582 errmsg("SET AUTOCOMMIT TO OFF is no longer supported")));
5589 assign_custom_variable_classes(const char *newval, bool doit, GucSource source)
5592 * Check syntax. newval must be a comma separated list of identifiers.
5593 * Whitespace is allowed but skipped.
5595 bool hasSpaceAfterToken = false;
5596 const char *cp = newval;
5601 initStringInfo(&buf);
5602 while ((c = *cp++) != 0)
5607 hasSpaceAfterToken = true;
5613 hasSpaceAfterToken = false;
5617 appendStringInfoChar(&buf, ',');
5622 if (hasSpaceAfterToken || !isalnum(c))
5625 * Syntax error due to token following space after token or
5626 * non alpha numeric character
5629 (errcode(ERRCODE_SYNTAX_ERROR),
5630 errmsg("invalid syntax for \"custom_variable_classes\": \"%s\"", newval)));
5635 appendStringInfoChar(&buf, (char) c);
5638 /* Remove stray ',' at end */
5639 if (symLen == 0 && buf.len > 0)
5640 buf.data[--buf.len] = '\0';
5645 newval = strdup(buf.data);
5652 assign_stage_log_stats(bool newval, bool doit, GucSource source)
5654 if (newval && log_statement_stats)
5656 if (source >= PGC_S_INTERACTIVE)
5658 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5659 errmsg("cannot enable parameter when \"log_statement_stats\" is true")));
5660 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
5661 else if (source != PGC_S_OVERRIDE)
5668 assign_log_stats(bool newval, bool doit, GucSource source)
5671 (log_parser_stats || log_planner_stats || log_executor_stats))
5673 if (source >= PGC_S_INTERACTIVE)
5675 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5676 errmsg("cannot enable \"log_statement_stats\" when "
5677 "\"log_parser_stats\", \"log_planner_stats\", "
5678 "or \"log_executor_stats\" is true")));
5679 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
5680 else if (source != PGC_S_OVERRIDE)
5687 assign_transaction_read_only(bool newval, bool doit, GucSource source)
5689 /* Can't go to r/w mode inside a r/o transaction */
5690 if (newval == false && XactReadOnly && IsSubTransaction())
5692 if (source >= PGC_S_INTERACTIVE)
5694 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5695 errmsg("cannot set transaction read-write mode inside a read-only transaction")));
5696 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
5697 else if (source != PGC_S_OVERRIDE)
5704 assign_canonical_path(const char *newval, bool doit, GucSource source)
5708 char *canon_val = guc_strdup(ERROR, newval);
5710 canonicalize_path(canon_val);
5718 #include "guc-file.c"