Minor improvements in backup and recovery:
[PostgreSQL.git] / src / backend / utils / misc / guc.c
blob35836288b1d7d9874b4f8fb43f011f5976603e3d
1 /*--------------------------------------------------------------------
2 * guc.c
4 * Support for grand unified configuration scheme, including SET
5 * command, configuration file, and command line options.
6 * See src/backend/utils/misc/README for more information.
9 * Copyright (c) 2000-2007, PostgreSQL Global Development Group
10 * Written by Peter Eisentraut <peter_e@gmx.net>.
12 * IDENTIFICATION
13 * $PostgreSQL$
15 *--------------------------------------------------------------------
17 #include "postgres.h"
19 #include <ctype.h>
20 #include <float.h>
21 #include <limits.h>
22 #include <unistd.h>
23 #include <sys/stat.h>
24 #ifdef HAVE_SYSLOG
25 #include <syslog.h>
26 #endif
28 #include "access/gin.h"
29 #include "access/transam.h"
30 #include "access/twophase.h"
31 #include "access/xact.h"
32 #include "catalog/namespace.h"
33 #include "commands/async.h"
34 #include "commands/prepare.h"
35 #include "commands/vacuum.h"
36 #include "commands/variable.h"
37 #include "commands/trigger.h"
38 #include "funcapi.h"
39 #include "libpq/auth.h"
40 #include "libpq/pqformat.h"
41 #include "miscadmin.h"
42 #include "optimizer/cost.h"
43 #include "optimizer/geqo.h"
44 #include "optimizer/paths.h"
45 #include "optimizer/planmain.h"
46 #include "parser/gramparse.h"
47 #include "parser/parse_expr.h"
48 #include "parser/parse_relation.h"
49 #include "parser/parse_type.h"
50 #include "parser/scansup.h"
51 #include "pgstat.h"
52 #include "postmaster/autovacuum.h"
53 #include "postmaster/bgwriter.h"
54 #include "postmaster/postmaster.h"
55 #include "postmaster/syslogger.h"
56 #include "postmaster/walwriter.h"
57 #include "storage/fd.h"
58 #include "storage/freespace.h"
59 #include "tcop/tcopprot.h"
60 #include "tsearch/ts_cache.h"
61 #include "utils/builtins.h"
62 #include "utils/guc_tables.h"
63 #include "utils/memutils.h"
64 #include "utils/pg_locale.h"
65 #include "utils/plancache.h"
66 #include "utils/portal.h"
67 #include "utils/ps_status.h"
68 #include "utils/tzparser.h"
69 #include "utils/xml.h"
71 #ifndef PG_KRB_SRVTAB
72 #define PG_KRB_SRVTAB ""
73 #endif
74 #ifndef PG_KRB_SRVNAM
75 #define PG_KRB_SRVNAM ""
76 #endif
78 #define CONFIG_FILENAME "postgresql.conf"
79 #define HBA_FILENAME "pg_hba.conf"
80 #define IDENT_FILENAME "pg_ident.conf"
82 #ifdef EXEC_BACKEND
83 #define CONFIG_EXEC_PARAMS "global/config_exec_params"
84 #define CONFIG_EXEC_PARAMS_NEW "global/config_exec_params.new"
85 #endif
87 /* upper limit for GUC variables measured in kilobytes of memory */
88 #if SIZEOF_SIZE_T > 4
89 #define MAX_KILOBYTES INT_MAX
90 #else
91 #define MAX_KILOBYTES (INT_MAX / 1024)
92 #endif
94 #define KB_PER_MB (1024)
95 #define KB_PER_GB (1024*1024)
97 #define MS_PER_S 1000
98 #define S_PER_MIN 60
99 #define MS_PER_MIN (1000 * 60)
100 #define MIN_PER_H 60
101 #define S_PER_H (60 * 60)
102 #define MS_PER_H (1000 * 60 * 60)
103 #define MIN_PER_D (60 * 24)
104 #define S_PER_D (60 * 60 * 24)
105 #define MS_PER_D (1000 * 60 * 60 * 24)
107 /* XXX these should appear in other modules' header files */
108 extern bool Log_disconnections;
109 extern int CommitDelay;
110 extern int CommitSiblings;
111 extern char *default_tablespace;
112 extern char *temp_tablespaces;
113 extern bool fullPageWrites;
115 #ifdef TRACE_SORT
116 extern bool trace_sort;
117 #endif
118 #ifdef TRACE_SYNCSCAN
119 extern bool trace_syncscan;
120 #endif
121 #ifdef DEBUG_BOUNDED_SORT
122 extern bool optimize_bounded_sort;
123 #endif
125 #ifdef USE_SSL
126 extern char *SSLCipherSuites;
127 #endif
130 static const char *assign_log_destination(const char *value,
131 bool doit, GucSource source);
133 #ifdef HAVE_SYSLOG
134 static int syslog_facility = LOG_LOCAL0;
136 static const char *assign_syslog_facility(const char *facility,
137 bool doit, GucSource source);
138 static const char *assign_syslog_ident(const char *ident,
139 bool doit, GucSource source);
140 #endif
142 static const char *assign_defaultxactisolevel(const char *newval, bool doit,
143 GucSource source);
144 static const char *assign_session_replication_role(const char *newval, bool doit,
145 GucSource source);
146 static const char *assign_log_min_messages(const char *newval, bool doit,
147 GucSource source);
148 static const char *assign_client_min_messages(const char *newval,
149 bool doit, GucSource source);
150 static const char *assign_min_error_statement(const char *newval, bool doit,
151 GucSource source);
152 static const char *assign_msglvl(int *var, const char *newval, bool doit,
153 GucSource source);
154 static const char *assign_log_error_verbosity(const char *newval, bool doit,
155 GucSource source);
156 static const char *assign_log_statement(const char *newval, bool doit,
157 GucSource source);
158 static const char *show_num_temp_buffers(void);
159 static bool assign_phony_autocommit(bool newval, bool doit, GucSource source);
160 static const char *assign_custom_variable_classes(const char *newval, bool doit,
161 GucSource source);
162 static bool assign_debug_assertions(bool newval, bool doit, GucSource source);
163 static bool assign_ssl(bool newval, bool doit, GucSource source);
164 static bool assign_stage_log_stats(bool newval, bool doit, GucSource source);
165 static bool assign_log_stats(bool newval, bool doit, GucSource source);
166 static bool assign_transaction_read_only(bool newval, bool doit, GucSource source);
167 static const char *assign_canonical_path(const char *newval, bool doit, GucSource source);
168 static const char *assign_backslash_quote(const char *newval, bool doit, GucSource source);
169 static const char *assign_timezone_abbreviations(const char *newval, bool doit, GucSource source);
170 static const char *assign_xmlbinary(const char *newval, bool doit, GucSource source);
171 static const char *assign_xmloption(const char *newval, bool doit, GucSource source);
172 static const char *show_archive_command(void);
173 static bool assign_tcp_keepalives_idle(int newval, bool doit, GucSource source);
174 static bool assign_tcp_keepalives_interval(int newval, bool doit, GucSource source);
175 static bool assign_tcp_keepalives_count(int newval, bool doit, GucSource source);
176 static const char *show_tcp_keepalives_idle(void);
177 static const char *show_tcp_keepalives_interval(void);
178 static const char *show_tcp_keepalives_count(void);
179 static bool assign_autovacuum_max_workers(int newval, bool doit, GucSource source);
180 static bool assign_maxconnections(int newval, bool doit, GucSource source);
183 * GUC option variables that are exported from this module
185 #ifdef USE_ASSERT_CHECKING
186 bool assert_enabled = true;
187 #else
188 bool assert_enabled = false;
189 #endif
190 bool log_duration = false;
191 bool Debug_print_plan = false;
192 bool Debug_print_parse = false;
193 bool Debug_print_rewritten = false;
194 bool Debug_pretty_print = false;
195 bool Explain_pretty_print = true;
197 bool log_parser_stats = false;
198 bool log_planner_stats = false;
199 bool log_executor_stats = false;
200 bool log_statement_stats = false; /* this is sort of all three
201 * above together */
202 bool log_btree_build_stats = false;
204 bool check_function_bodies = true;
205 bool default_with_oids = false;
206 bool SQL_inheritance = true;
208 bool Password_encryption = true;
210 int log_min_error_statement = ERROR;
211 int log_min_messages = NOTICE;
212 int client_min_messages = NOTICE;
213 int log_min_duration_statement = -1;
214 int log_temp_files = -1;
216 int num_temp_buffers = 1000;
218 char *ConfigFileName;
219 char *HbaFileName;
220 char *IdentFileName;
221 char *external_pid_file;
223 int tcp_keepalives_idle;
224 int tcp_keepalives_interval;
225 int tcp_keepalives_count;
228 * These variables are all dummies that don't do anything, except in some
229 * cases provide the value for SHOW to display. The real state is elsewhere
230 * and is kept in sync by assign_hooks.
232 static char *client_min_messages_str;
233 static char *log_min_messages_str;
234 static char *log_error_verbosity_str;
235 static char *log_statement_str;
236 static char *log_min_error_statement_str;
237 static char *log_destination_string;
239 #ifdef HAVE_SYSLOG
240 static char *syslog_facility_str;
241 static char *syslog_ident_str;
242 #endif
243 static bool phony_autocommit;
244 static bool session_auth_is_superuser;
245 static double phony_random_seed;
246 static char *backslash_quote_string;
247 static char *client_encoding_string;
248 static char *datestyle_string;
249 static char *default_iso_level_string;
250 static char *session_replication_role_string;
251 static char *locale_collate;
252 static char *locale_ctype;
253 static char *regex_flavor_string;
254 static char *server_encoding_string;
255 static char *server_version_string;
256 static int server_version_num;
257 static char *timezone_string;
258 static char *log_timezone_string;
259 static char *timezone_abbreviations_string;
260 static char *XactIsoLevel_string;
261 static char *data_directory;
262 static char *custom_variable_classes;
263 static char *xmlbinary_string;
264 static char *xmloption_string;
265 static int max_function_args;
266 static int max_index_keys;
267 static int max_identifier_length;
268 static int block_size;
269 static bool integer_datetimes;
271 /* should be static, but commands/variable.c needs to get at these */
272 char *role_string;
273 char *session_authorization_string;
277 * Displayable names for context types (enum GucContext)
279 * Note: these strings are deliberately not localized.
281 const char *const GucContext_Names[] =
283 /* PGC_INTERNAL */ "internal",
284 /* PGC_POSTMASTER */ "postmaster",
285 /* PGC_SIGHUP */ "sighup",
286 /* PGC_BACKEND */ "backend",
287 /* PGC_SUSET */ "superuser",
288 /* PGC_USERSET */ "user"
292 * Displayable names for source types (enum GucSource)
294 * Note: these strings are deliberately not localized.
296 const char *const GucSource_Names[] =
298 /* PGC_S_DEFAULT */ "default",
299 /* PGC_S_ENV_VAR */ "environment variable",
300 /* PGC_S_FILE */ "configuration file",
301 /* PGC_S_ARGV */ "command line",
302 /* PGC_S_DATABASE */ "database",
303 /* PGC_S_USER */ "user",
304 /* PGC_S_CLIENT */ "client",
305 /* PGC_S_OVERRIDE */ "override",
306 /* PGC_S_INTERACTIVE */ "interactive",
307 /* PGC_S_TEST */ "test",
308 /* PGC_S_SESSION */ "session"
312 * Displayable names for the groupings defined in enum config_group
314 const char *const config_group_names[] =
316 /* UNGROUPED */
317 gettext_noop("Ungrouped"),
318 /* FILE_LOCATIONS */
319 gettext_noop("File Locations"),
320 /* CONN_AUTH */
321 gettext_noop("Connections and Authentication"),
322 /* CONN_AUTH_SETTINGS */
323 gettext_noop("Connections and Authentication / Connection Settings"),
324 /* CONN_AUTH_SECURITY */
325 gettext_noop("Connections and Authentication / Security and Authentication"),
326 /* RESOURCES */
327 gettext_noop("Resource Usage"),
328 /* RESOURCES_MEM */
329 gettext_noop("Resource Usage / Memory"),
330 /* RESOURCES_FSM */
331 gettext_noop("Resource Usage / Free Space Map"),
332 /* RESOURCES_KERNEL */
333 gettext_noop("Resource Usage / Kernel Resources"),
334 /* WAL */
335 gettext_noop("Write-Ahead Log"),
336 /* WAL_SETTINGS */
337 gettext_noop("Write-Ahead Log / Settings"),
338 /* WAL_CHECKPOINTS */
339 gettext_noop("Write-Ahead Log / Checkpoints"),
340 /* QUERY_TUNING */
341 gettext_noop("Query Tuning"),
342 /* QUERY_TUNING_METHOD */
343 gettext_noop("Query Tuning / Planner Method Configuration"),
344 /* QUERY_TUNING_COST */
345 gettext_noop("Query Tuning / Planner Cost Constants"),
346 /* QUERY_TUNING_GEQO */
347 gettext_noop("Query Tuning / Genetic Query Optimizer"),
348 /* QUERY_TUNING_OTHER */
349 gettext_noop("Query Tuning / Other Planner Options"),
350 /* LOGGING */
351 gettext_noop("Reporting and Logging"),
352 /* LOGGING_WHERE */
353 gettext_noop("Reporting and Logging / Where to Log"),
354 /* LOGGING_WHEN */
355 gettext_noop("Reporting and Logging / When to Log"),
356 /* LOGGING_WHAT */
357 gettext_noop("Reporting and Logging / What to Log"),
358 /* STATS */
359 gettext_noop("Statistics"),
360 /* STATS_MONITORING */
361 gettext_noop("Statistics / Monitoring"),
362 /* STATS_COLLECTOR */
363 gettext_noop("Statistics / Query and Index Statistics Collector"),
364 /* AUTOVACUUM */
365 gettext_noop("Autovacuum"),
366 /* CLIENT_CONN */
367 gettext_noop("Client Connection Defaults"),
368 /* CLIENT_CONN_STATEMENT */
369 gettext_noop("Client Connection Defaults / Statement Behavior"),
370 /* CLIENT_CONN_LOCALE */
371 gettext_noop("Client Connection Defaults / Locale and Formatting"),
372 /* CLIENT_CONN_OTHER */
373 gettext_noop("Client Connection Defaults / Other Defaults"),
374 /* LOCK_MANAGEMENT */
375 gettext_noop("Lock Management"),
376 /* COMPAT_OPTIONS */
377 gettext_noop("Version and Platform Compatibility"),
378 /* COMPAT_OPTIONS_PREVIOUS */
379 gettext_noop("Version and Platform Compatibility / Previous PostgreSQL Versions"),
380 /* COMPAT_OPTIONS_CLIENT */
381 gettext_noop("Version and Platform Compatibility / Other Platforms and Clients"),
382 /* PRESET_OPTIONS */
383 gettext_noop("Preset Options"),
384 /* CUSTOM_OPTIONS */
385 gettext_noop("Customized Options"),
386 /* DEVELOPER_OPTIONS */
387 gettext_noop("Developer Options"),
388 /* help_config wants this array to be null-terminated */
389 NULL
393 * Displayable names for GUC variable types (enum config_type)
395 * Note: these strings are deliberately not localized.
397 const char *const config_type_names[] =
399 /* PGC_BOOL */ "bool",
400 /* PGC_INT */ "integer",
401 /* PGC_REAL */ "real",
402 /* PGC_STRING */ "string"
407 * Contents of GUC tables
409 * See src/backend/utils/misc/README for design notes.
411 * TO ADD AN OPTION:
413 * 1. Declare a global variable of type bool, int, double, or char*
414 * and make use of it.
416 * 2. Decide at what times it's safe to set the option. See guc.h for
417 * details.
419 * 3. Decide on a name, a default value, upper and lower bounds (if
420 * applicable), etc.
422 * 4. Add a record below.
424 * 5. Add it to src/backend/utils/misc/postgresql.conf.sample, if
425 * appropriate.
427 * 6. Don't forget to document the option (at least in config.sgml).
429 * 7. If it's a new GUC_LIST option you must edit pg_dumpall.c to ensure
430 * it is not single quoted at dump time.
434 /******** option records follow ********/
436 static struct config_bool ConfigureNamesBool[] =
439 {"enable_seqscan", PGC_USERSET, QUERY_TUNING_METHOD,
440 gettext_noop("Enables the planner's use of sequential-scan plans."),
441 NULL
443 &enable_seqscan,
444 true, NULL, NULL
447 {"enable_indexscan", PGC_USERSET, QUERY_TUNING_METHOD,
448 gettext_noop("Enables the planner's use of index-scan plans."),
449 NULL
451 &enable_indexscan,
452 true, NULL, NULL
455 {"enable_bitmapscan", PGC_USERSET, QUERY_TUNING_METHOD,
456 gettext_noop("Enables the planner's use of bitmap-scan plans."),
457 NULL
459 &enable_bitmapscan,
460 true, NULL, NULL
463 {"enable_tidscan", PGC_USERSET, QUERY_TUNING_METHOD,
464 gettext_noop("Enables the planner's use of TID scan plans."),
465 NULL
467 &enable_tidscan,
468 true, NULL, NULL
471 {"enable_sort", PGC_USERSET, QUERY_TUNING_METHOD,
472 gettext_noop("Enables the planner's use of explicit sort steps."),
473 NULL
475 &enable_sort,
476 true, NULL, NULL
479 {"enable_hashagg", PGC_USERSET, QUERY_TUNING_METHOD,
480 gettext_noop("Enables the planner's use of hashed aggregation plans."),
481 NULL
483 &enable_hashagg,
484 true, NULL, NULL
487 {"enable_nestloop", PGC_USERSET, QUERY_TUNING_METHOD,
488 gettext_noop("Enables the planner's use of nested-loop join plans."),
489 NULL
491 &enable_nestloop,
492 true, NULL, NULL
495 {"enable_mergejoin", PGC_USERSET, QUERY_TUNING_METHOD,
496 gettext_noop("Enables the planner's use of merge join plans."),
497 NULL
499 &enable_mergejoin,
500 true, NULL, NULL
503 {"enable_hashjoin", PGC_USERSET, QUERY_TUNING_METHOD,
504 gettext_noop("Enables the planner's use of hash join plans."),
505 NULL
507 &enable_hashjoin,
508 true, NULL, NULL
511 {"constraint_exclusion", PGC_USERSET, QUERY_TUNING_OTHER,
512 gettext_noop("Enables the planner to use constraints to optimize queries."),
513 gettext_noop("Child table scans will be skipped if their "
514 "constraints guarantee that no rows match the query.")
516 &constraint_exclusion,
517 false, NULL, NULL
520 {"geqo", PGC_USERSET, QUERY_TUNING_GEQO,
521 gettext_noop("Enables genetic query optimization."),
522 gettext_noop("This algorithm attempts to do planning without "
523 "exhaustive searching.")
525 &enable_geqo,
526 true, NULL, NULL
529 /* Not for general use --- used by SET SESSION AUTHORIZATION */
530 {"is_superuser", PGC_INTERNAL, UNGROUPED,
531 gettext_noop("Shows whether the current user is a superuser."),
532 NULL,
533 GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
535 &session_auth_is_superuser,
536 false, NULL, NULL
539 {"ssl", PGC_POSTMASTER, CONN_AUTH_SECURITY,
540 gettext_noop("Enables SSL connections."),
541 NULL
543 &EnableSSL,
544 false, assign_ssl, NULL
547 {"fsync", PGC_SIGHUP, WAL_SETTINGS,
548 gettext_noop("Forces synchronization of updates to disk."),
549 gettext_noop("The server will use the fsync() system call in several places to make "
550 "sure that updates are physically written to disk. This insures "
551 "that a database cluster will recover to a consistent state after "
552 "an operating system or hardware crash.")
554 &enableFsync,
555 true, NULL, NULL
558 {"synchronous_commit", PGC_USERSET, WAL_SETTINGS,
559 gettext_noop("Sets immediate fsync at commit."),
560 NULL
562 &XactSyncCommit,
563 true, NULL, NULL
566 {"zero_damaged_pages", PGC_SUSET, DEVELOPER_OPTIONS,
567 gettext_noop("Continues processing past damaged page headers."),
568 gettext_noop("Detection of a damaged page header normally causes PostgreSQL to "
569 "report an error, aborting the current transaction. Setting "
570 "zero_damaged_pages to true causes the system to instead report a "
571 "warning, zero out the damaged page, and continue processing. This "
572 "behavior will destroy data, namely all the rows on the damaged page."),
573 GUC_NOT_IN_SAMPLE
575 &zero_damaged_pages,
576 false, NULL, NULL
579 {"full_page_writes", PGC_SIGHUP, WAL_SETTINGS,
580 gettext_noop("Writes full pages to WAL when first modified after a checkpoint."),
581 gettext_noop("A page write in process during an operating system crash might be "
582 "only partially written to disk. During recovery, the row changes "
583 "stored in WAL are not enough to recover. This option writes "
584 "pages when first modified after a checkpoint to WAL so full recovery "
585 "is possible.")
587 &fullPageWrites,
588 true, NULL, NULL
591 {"silent_mode", PGC_POSTMASTER, LOGGING_WHEN,
592 gettext_noop("Runs the server silently."),
593 gettext_noop("If this parameter is set, the server will automatically run in the "
594 "background and any controlling terminals are dissociated.")
596 &SilentMode,
597 false, NULL, NULL
600 {"log_checkpoints", PGC_SIGHUP, LOGGING_WHAT,
601 gettext_noop("Logs each checkpoint."),
602 NULL
604 &log_checkpoints,
605 false, NULL, NULL
608 {"log_connections", PGC_BACKEND, LOGGING_WHAT,
609 gettext_noop("Logs each successful connection."),
610 NULL
612 &Log_connections,
613 false, NULL, NULL
616 {"log_disconnections", PGC_BACKEND, LOGGING_WHAT,
617 gettext_noop("Logs end of a session, including duration."),
618 NULL
620 &Log_disconnections,
621 false, NULL, NULL
624 {"debug_assertions", PGC_USERSET, DEVELOPER_OPTIONS,
625 gettext_noop("Turns on various assertion checks."),
626 gettext_noop("This is a debugging aid."),
627 GUC_NOT_IN_SAMPLE
629 &assert_enabled,
630 #ifdef USE_ASSERT_CHECKING
631 true,
632 #else
633 false,
634 #endif
635 assign_debug_assertions, NULL
638 /* currently undocumented, so don't show in SHOW ALL */
639 {"exit_on_error", PGC_USERSET, UNGROUPED,
640 gettext_noop("No description available."),
641 NULL,
642 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
644 &ExitOnAnyError,
645 false, NULL, NULL
648 {"log_duration", PGC_SUSET, LOGGING_WHAT,
649 gettext_noop("Logs the duration of each completed SQL statement."),
650 NULL
652 &log_duration,
653 false, NULL, NULL
656 {"debug_print_parse", PGC_USERSET, LOGGING_WHAT,
657 gettext_noop("Prints the parse tree to the server log."),
658 NULL
660 &Debug_print_parse,
661 false, NULL, NULL
664 {"debug_print_rewritten", PGC_USERSET, LOGGING_WHAT,
665 gettext_noop("Prints the parse tree after rewriting to server log."),
666 NULL
668 &Debug_print_rewritten,
669 false, NULL, NULL
672 {"debug_print_plan", PGC_USERSET, LOGGING_WHAT,
673 gettext_noop("Prints the execution plan to server log."),
674 NULL
676 &Debug_print_plan,
677 false, NULL, NULL
680 {"debug_pretty_print", PGC_USERSET, LOGGING_WHAT,
681 gettext_noop("Indents parse and plan tree displays."),
682 NULL
684 &Debug_pretty_print,
685 false, NULL, NULL
688 {"log_parser_stats", PGC_SUSET, STATS_MONITORING,
689 gettext_noop("Writes parser performance statistics to the server log."),
690 NULL
692 &log_parser_stats,
693 false, assign_stage_log_stats, NULL
696 {"log_planner_stats", PGC_SUSET, STATS_MONITORING,
697 gettext_noop("Writes planner performance statistics to the server log."),
698 NULL
700 &log_planner_stats,
701 false, assign_stage_log_stats, NULL
704 {"log_executor_stats", PGC_SUSET, STATS_MONITORING,
705 gettext_noop("Writes executor performance statistics to the server log."),
706 NULL
708 &log_executor_stats,
709 false, assign_stage_log_stats, NULL
712 {"log_statement_stats", PGC_SUSET, STATS_MONITORING,
713 gettext_noop("Writes cumulative performance statistics to the server log."),
714 NULL
716 &log_statement_stats,
717 false, assign_log_stats, NULL
719 #ifdef BTREE_BUILD_STATS
721 {"log_btree_build_stats", PGC_SUSET, DEVELOPER_OPTIONS,
722 gettext_noop("No description available."),
723 NULL,
724 GUC_NOT_IN_SAMPLE
726 &log_btree_build_stats,
727 false, NULL, NULL
729 #endif
732 {"explain_pretty_print", PGC_USERSET, CLIENT_CONN_OTHER,
733 gettext_noop("Uses the indented output format for EXPLAIN VERBOSE."),
734 NULL
736 &Explain_pretty_print,
737 true, NULL, NULL
741 {"track_activities", PGC_SUSET, STATS_COLLECTOR,
742 gettext_noop("Collects information about executing commands."),
743 gettext_noop("Enables the collection of information on the currently "
744 "executing command of each session, along with "
745 "the time at which that command began execution.")
747 &pgstat_track_activities,
748 true, NULL, NULL
751 {"track_counts", PGC_SUSET, STATS_COLLECTOR,
752 gettext_noop("Collects statistics on database activity."),
753 NULL
755 &pgstat_track_counts,
756 true, NULL, NULL
760 {"update_process_title", PGC_SUSET, STATS_COLLECTOR,
761 gettext_noop("Updates the process title to show the active SQL command."),
762 gettext_noop("Enables updating of the process title every time a new SQL command is received by the server.")
764 &update_process_title,
765 true, NULL, NULL
769 {"autovacuum", PGC_SIGHUP, AUTOVACUUM,
770 gettext_noop("Starts the autovacuum subprocess."),
771 NULL
773 &autovacuum_start_daemon,
774 true, NULL, NULL
778 {"trace_notify", PGC_USERSET, DEVELOPER_OPTIONS,
779 gettext_noop("Generates debugging output for LISTEN and NOTIFY."),
780 NULL,
781 GUC_NOT_IN_SAMPLE
783 &Trace_notify,
784 false, NULL, NULL
787 #ifdef LOCK_DEBUG
789 {"trace_locks", PGC_SUSET, DEVELOPER_OPTIONS,
790 gettext_noop("No description available."),
791 NULL,
792 GUC_NOT_IN_SAMPLE
794 &Trace_locks,
795 false, NULL, NULL
798 {"trace_userlocks", PGC_SUSET, DEVELOPER_OPTIONS,
799 gettext_noop("No description available."),
800 NULL,
801 GUC_NOT_IN_SAMPLE
803 &Trace_userlocks,
804 false, NULL, NULL
807 {"trace_lwlocks", PGC_SUSET, DEVELOPER_OPTIONS,
808 gettext_noop("No description available."),
809 NULL,
810 GUC_NOT_IN_SAMPLE
812 &Trace_lwlocks,
813 false, NULL, NULL
816 {"debug_deadlocks", PGC_SUSET, DEVELOPER_OPTIONS,
817 gettext_noop("No description available."),
818 NULL,
819 GUC_NOT_IN_SAMPLE
821 &Debug_deadlocks,
822 false, NULL, NULL
824 #endif
827 {"log_lock_waits", PGC_SUSET, LOGGING_WHAT,
828 gettext_noop("Logs long lock waits."),
829 NULL
831 &log_lock_waits,
832 false, NULL, NULL
836 {"log_hostname", PGC_SIGHUP, LOGGING_WHAT,
837 gettext_noop("Logs the host name in the connection logs."),
838 gettext_noop("By default, connection logs only show the IP address "
839 "of the connecting host. If you want them to show the host name you "
840 "can turn this on, but depending on your host name resolution "
841 "setup it might impose a non-negligible performance penalty.")
843 &log_hostname,
844 false, NULL, NULL
847 {"sql_inheritance", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
848 gettext_noop("Causes subtables to be included by default in various commands."),
849 NULL
851 &SQL_inheritance,
852 true, NULL, NULL
855 {"password_encryption", PGC_USERSET, CONN_AUTH_SECURITY,
856 gettext_noop("Encrypt passwords."),
857 gettext_noop("When a password is specified in CREATE USER or "
858 "ALTER USER without writing either ENCRYPTED or UNENCRYPTED, "
859 "this parameter determines whether the password is to be encrypted.")
861 &Password_encryption,
862 true, NULL, NULL
865 {"transform_null_equals", PGC_USERSET, COMPAT_OPTIONS_CLIENT,
866 gettext_noop("Treats \"expr=NULL\" as \"expr IS NULL\"."),
867 gettext_noop("When turned on, expressions of the form expr = NULL "
868 "(or NULL = expr) are treated as expr IS NULL, that is, they "
869 "return true if expr evaluates to the null value, and false "
870 "otherwise. The correct behavior of expr = NULL is to always "
871 "return null (unknown).")
873 &Transform_null_equals,
874 false, NULL, NULL
877 {"db_user_namespace", PGC_SIGHUP, CONN_AUTH_SECURITY,
878 gettext_noop("Enables per-database user names."),
879 NULL
881 &Db_user_namespace,
882 false, NULL, NULL
885 /* only here for backwards compatibility */
886 {"autocommit", PGC_USERSET, CLIENT_CONN_STATEMENT,
887 gettext_noop("This parameter doesn't do anything."),
888 gettext_noop("It's just here so that we won't choke on SET AUTOCOMMIT TO ON from 7.3-vintage clients."),
889 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
891 &phony_autocommit,
892 true, assign_phony_autocommit, NULL
895 {"default_transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
896 gettext_noop("Sets the default read-only status of new transactions."),
897 NULL
899 &DefaultXactReadOnly,
900 false, NULL, NULL
903 {"transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
904 gettext_noop("Sets the current transaction's read-only status."),
905 NULL,
906 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
908 &XactReadOnly,
909 false, assign_transaction_read_only, NULL
912 {"add_missing_from", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
913 gettext_noop("Automatically adds missing table references to FROM clauses."),
914 NULL
916 &add_missing_from,
917 false, NULL, NULL
920 {"check_function_bodies", PGC_USERSET, CLIENT_CONN_STATEMENT,
921 gettext_noop("Check function bodies during CREATE FUNCTION."),
922 NULL
924 &check_function_bodies,
925 true, NULL, NULL
928 {"array_nulls", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
929 gettext_noop("Enable input of NULL elements in arrays."),
930 gettext_noop("When turned on, unquoted NULL in an array input "
931 "value means a null value; "
932 "otherwise it is taken literally.")
934 &Array_nulls,
935 true, NULL, NULL
938 {"default_with_oids", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
939 gettext_noop("Create new tables with OIDs by default."),
940 NULL
942 &default_with_oids,
943 false, NULL, NULL
946 {"logging_collector", PGC_POSTMASTER, LOGGING_WHERE,
947 gettext_noop("Start a subprocess to capture stderr output and/or csvlogs into log files."),
948 NULL
950 &Logging_collector,
951 false, NULL, NULL
954 {"log_truncate_on_rotation", PGC_SIGHUP, LOGGING_WHERE,
955 gettext_noop("Truncate existing log files of same name during log rotation."),
956 NULL
958 &Log_truncate_on_rotation,
959 false, NULL, NULL
962 #ifdef TRACE_SORT
964 {"trace_sort", PGC_USERSET, DEVELOPER_OPTIONS,
965 gettext_noop("Emit information about resource usage in sorting."),
966 NULL,
967 GUC_NOT_IN_SAMPLE
969 &trace_sort,
970 false, NULL, NULL
972 #endif
974 #ifdef TRACE_SYNCSCAN
975 /* this is undocumented because not exposed in a standard build */
977 {"trace_syncscan", PGC_USERSET, DEVELOPER_OPTIONS,
978 gettext_noop("Generate debugging output for synchronized scanning."),
979 NULL,
980 GUC_NOT_IN_SAMPLE
982 &trace_syncscan,
983 false, NULL, NULL
985 #endif
987 #ifdef DEBUG_BOUNDED_SORT
988 /* this is undocumented because not exposed in a standard build */
991 "optimize_bounded_sort", PGC_USERSET, QUERY_TUNING_METHOD,
992 gettext_noop("Enable bounded sorting using heap sort."),
993 NULL,
994 GUC_NOT_IN_SAMPLE
996 &optimize_bounded_sort,
997 true, NULL, NULL
999 #endif
1001 #ifdef WAL_DEBUG
1003 {"wal_debug", PGC_SUSET, DEVELOPER_OPTIONS,
1004 gettext_noop("Emit WAL-related debugging output."),
1005 NULL,
1006 GUC_NOT_IN_SAMPLE
1008 &XLOG_DEBUG,
1009 false, NULL, NULL
1011 #endif
1014 {"integer_datetimes", PGC_INTERNAL, PRESET_OPTIONS,
1015 gettext_noop("Datetimes are integer based."),
1016 NULL,
1017 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1019 &integer_datetimes,
1020 #ifdef HAVE_INT64_TIMESTAMP
1021 true, NULL, NULL
1022 #else
1023 false, NULL, NULL
1024 #endif
1028 {"krb_caseins_users", PGC_POSTMASTER, CONN_AUTH_SECURITY,
1029 gettext_noop("Sets whether Kerberos and GSSAPI user names should be treated as case-insensitive."),
1030 NULL
1032 &pg_krb_caseins_users,
1033 false, NULL, NULL
1037 {"escape_string_warning", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1038 gettext_noop("Warn about backslash escapes in ordinary string literals."),
1039 NULL
1041 &escape_string_warning,
1042 true, NULL, NULL
1046 {"standard_conforming_strings", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1047 gettext_noop("Causes '...' strings to treat backslashes literally."),
1048 NULL,
1049 GUC_REPORT
1051 &standard_conforming_strings,
1052 false, NULL, NULL
1056 {"archive_mode", PGC_POSTMASTER, WAL_SETTINGS,
1057 gettext_noop("Allows archiving of WAL files using archive_command."),
1058 NULL
1060 &XLogArchiveMode,
1061 false, NULL, NULL
1065 {"allow_system_table_mods", PGC_POSTMASTER, DEVELOPER_OPTIONS,
1066 gettext_noop("Allows modifications of the structure of system tables."),
1067 NULL,
1068 GUC_NOT_IN_SAMPLE
1070 &allowSystemTableMods,
1071 false, NULL, NULL
1075 {"ignore_system_indexes", PGC_BACKEND, DEVELOPER_OPTIONS,
1076 gettext_noop("Disables reading from system indexes."),
1077 gettext_noop("It does not prevent updating the indexes, so it is safe "
1078 "to use. The worst consequence is slowness."),
1079 GUC_NOT_IN_SAMPLE
1081 &IgnoreSystemIndexes,
1082 false, NULL, NULL
1085 /* End-of-list marker */
1087 {NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL
1092 static struct config_int ConfigureNamesInt[] =
1095 {"archive_timeout", PGC_SIGHUP, WAL_SETTINGS,
1096 gettext_noop("Forces a switch to the next xlog file if a "
1097 "new file has not been started within N seconds."),
1098 NULL,
1099 GUC_UNIT_S
1101 &XLogArchiveTimeout,
1102 0, 0, INT_MAX, NULL, NULL
1105 {"post_auth_delay", PGC_BACKEND, DEVELOPER_OPTIONS,
1106 gettext_noop("Waits N seconds on connection startup after authentication."),
1107 gettext_noop("This allows attaching a debugger to the process."),
1108 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1110 &PostAuthDelay,
1111 0, 0, INT_MAX, NULL, NULL
1114 {"default_statistics_target", PGC_USERSET, QUERY_TUNING_OTHER,
1115 gettext_noop("Sets the default statistics target."),
1116 gettext_noop("This applies to table columns that have not had a "
1117 "column-specific target set via ALTER TABLE SET STATISTICS.")
1119 &default_statistics_target,
1120 10, 1, 1000, NULL, NULL
1123 {"from_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1124 gettext_noop("Sets the FROM-list size beyond which subqueries "
1125 "are not collapsed."),
1126 gettext_noop("The planner will merge subqueries into upper "
1127 "queries if the resulting FROM list would have no more than "
1128 "this many items.")
1130 &from_collapse_limit,
1131 8, 1, INT_MAX, NULL, NULL
1134 {"join_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1135 gettext_noop("Sets the FROM-list size beyond which JOIN "
1136 "constructs are not flattened."),
1137 gettext_noop("The planner will flatten explicit JOIN "
1138 "constructs into lists of FROM items whenever a "
1139 "list of no more than this many items would result.")
1141 &join_collapse_limit,
1142 8, 1, INT_MAX, NULL, NULL
1145 {"geqo_threshold", PGC_USERSET, QUERY_TUNING_GEQO,
1146 gettext_noop("Sets the threshold of FROM items beyond which GEQO is used."),
1147 NULL
1149 &geqo_threshold,
1150 12, 2, INT_MAX, NULL, NULL
1153 {"geqo_effort", PGC_USERSET, QUERY_TUNING_GEQO,
1154 gettext_noop("GEQO: effort is used to set the default for other GEQO parameters."),
1155 NULL
1157 &Geqo_effort,
1158 DEFAULT_GEQO_EFFORT, MIN_GEQO_EFFORT, MAX_GEQO_EFFORT, NULL, NULL
1161 {"geqo_pool_size", PGC_USERSET, QUERY_TUNING_GEQO,
1162 gettext_noop("GEQO: number of individuals in the population."),
1163 gettext_noop("Zero selects a suitable default value.")
1165 &Geqo_pool_size,
1166 0, 0, INT_MAX, NULL, NULL
1169 {"geqo_generations", PGC_USERSET, QUERY_TUNING_GEQO,
1170 gettext_noop("GEQO: number of iterations of the algorithm."),
1171 gettext_noop("Zero selects a suitable default value.")
1173 &Geqo_generations,
1174 0, 0, INT_MAX, NULL, NULL
1178 {"deadlock_timeout", PGC_SIGHUP, LOCK_MANAGEMENT,
1179 gettext_noop("Sets the time to wait on a lock before checking for deadlock."),
1180 NULL,
1181 GUC_UNIT_MS
1183 &DeadlockTimeout,
1184 1000, 1, INT_MAX/1000, NULL, NULL
1188 * Note: There is some postprocessing done in PostmasterMain() to make
1189 * sure the buffers are at least twice the number of backends, so the
1190 * constraints here are partially unused. Similarly, the superuser
1191 * reserved number is checked to ensure it is less than the max backends
1192 * number.
1194 * MaxBackends is limited to INT_MAX/4 because some places compute
1195 * 4*MaxBackends without any overflow check. This check is made on
1196 * assign_maxconnections, since MaxBackends is computed as MaxConnections +
1197 * autovacuum_max_workers.
1199 * Likewise we have to limit NBuffers to INT_MAX/2.
1202 {"max_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1203 gettext_noop("Sets the maximum number of concurrent connections."),
1204 NULL
1206 &MaxConnections,
1207 100, 1, INT_MAX / 4, assign_maxconnections, NULL
1211 {"superuser_reserved_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1212 gettext_noop("Sets the number of connection slots reserved for superusers."),
1213 NULL
1215 &ReservedBackends,
1216 3, 0, INT_MAX / 4, NULL, NULL
1220 {"shared_buffers", PGC_POSTMASTER, RESOURCES_MEM,
1221 gettext_noop("Sets the number of shared memory buffers used by the server."),
1222 NULL,
1223 GUC_UNIT_BLOCKS
1225 &NBuffers,
1226 1024, 16, INT_MAX / 2, NULL, NULL
1230 {"temp_buffers", PGC_USERSET, RESOURCES_MEM,
1231 gettext_noop("Sets the maximum number of temporary buffers used by each session."),
1232 NULL,
1233 GUC_UNIT_BLOCKS
1235 &num_temp_buffers,
1236 1024, 100, INT_MAX / 2, NULL, show_num_temp_buffers
1240 {"port", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1241 gettext_noop("Sets the TCP port the server listens on."),
1242 NULL
1244 &PostPortNumber,
1245 DEF_PGPORT, 1, 65535, NULL, NULL
1249 {"unix_socket_permissions", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1250 gettext_noop("Sets the access permissions of the Unix-domain socket."),
1251 gettext_noop("Unix-domain sockets use the usual Unix file system "
1252 "permission set. The parameter value is expected to be an numeric mode "
1253 "specification in the form accepted by the chmod and umask system "
1254 "calls. (To use the customary octal format the number must start with "
1255 "a 0 (zero).)")
1257 &Unix_socket_permissions,
1258 0777, 0000, 0777, NULL, NULL
1262 {"work_mem", PGC_USERSET, RESOURCES_MEM,
1263 gettext_noop("Sets the maximum memory to be used for query workspaces."),
1264 gettext_noop("This much memory can be used by each internal "
1265 "sort operation and hash table before switching to "
1266 "temporary disk files."),
1267 GUC_UNIT_KB
1269 &work_mem,
1270 1024, 8 * BLCKSZ / 1024, MAX_KILOBYTES, NULL, NULL
1274 {"maintenance_work_mem", PGC_USERSET, RESOURCES_MEM,
1275 gettext_noop("Sets the maximum memory to be used for maintenance operations."),
1276 gettext_noop("This includes operations such as VACUUM and CREATE INDEX."),
1277 GUC_UNIT_KB
1279 &maintenance_work_mem,
1280 16384, 1024, MAX_KILOBYTES, NULL, NULL
1284 {"max_stack_depth", PGC_SUSET, RESOURCES_MEM,
1285 gettext_noop("Sets the maximum stack depth, in kilobytes."),
1286 NULL,
1287 GUC_UNIT_KB
1289 &max_stack_depth,
1290 100, 100, MAX_KILOBYTES, assign_max_stack_depth, NULL
1294 {"vacuum_cost_page_hit", PGC_USERSET, RESOURCES,
1295 gettext_noop("Vacuum cost for a page found in the buffer cache."),
1296 NULL
1298 &VacuumCostPageHit,
1299 1, 0, 10000, NULL, NULL
1303 {"vacuum_cost_page_miss", PGC_USERSET, RESOURCES,
1304 gettext_noop("Vacuum cost for a page not found in the buffer cache."),
1305 NULL
1307 &VacuumCostPageMiss,
1308 10, 0, 10000, NULL, NULL
1312 {"vacuum_cost_page_dirty", PGC_USERSET, RESOURCES,
1313 gettext_noop("Vacuum cost for a page dirtied by vacuum."),
1314 NULL
1316 &VacuumCostPageDirty,
1317 20, 0, 10000, NULL, NULL
1321 {"vacuum_cost_limit", PGC_USERSET, RESOURCES,
1322 gettext_noop("Vacuum cost amount available before napping."),
1323 NULL
1325 &VacuumCostLimit,
1326 200, 1, 10000, NULL, NULL
1330 {"vacuum_cost_delay", PGC_USERSET, RESOURCES,
1331 gettext_noop("Vacuum cost delay in milliseconds."),
1332 NULL,
1333 GUC_UNIT_MS
1335 &VacuumCostDelay,
1336 0, 0, 1000, NULL, NULL
1340 {"autovacuum_vacuum_cost_delay", PGC_SIGHUP, AUTOVACUUM,
1341 gettext_noop("Vacuum cost delay in milliseconds, for autovacuum."),
1342 NULL,
1343 GUC_UNIT_MS
1345 &autovacuum_vac_cost_delay,
1346 20, -1, 1000, NULL, NULL
1350 {"autovacuum_vacuum_cost_limit", PGC_SIGHUP, AUTOVACUUM,
1351 gettext_noop("Vacuum cost amount available before napping, for autovacuum."),
1352 NULL
1354 &autovacuum_vac_cost_limit,
1355 -1, -1, 10000, NULL, NULL
1359 {"max_files_per_process", PGC_POSTMASTER, RESOURCES_KERNEL,
1360 gettext_noop("Sets the maximum number of simultaneously open files for each server process."),
1361 NULL
1363 &max_files_per_process,
1364 1000, 25, INT_MAX, NULL, NULL
1368 {"max_prepared_transactions", PGC_POSTMASTER, RESOURCES,
1369 gettext_noop("Sets the maximum number of simultaneously prepared transactions."),
1370 NULL
1372 &max_prepared_xacts,
1373 5, 0, INT_MAX, NULL, NULL
1376 #ifdef LOCK_DEBUG
1378 {"trace_lock_oidmin", PGC_SUSET, DEVELOPER_OPTIONS,
1379 gettext_noop("No description available."),
1380 NULL,
1381 GUC_NOT_IN_SAMPLE
1383 &Trace_lock_oidmin,
1384 FirstNormalObjectId, 0, INT_MAX, NULL, NULL
1387 {"trace_lock_table", PGC_SUSET, DEVELOPER_OPTIONS,
1388 gettext_noop("No description available."),
1389 NULL,
1390 GUC_NOT_IN_SAMPLE
1392 &Trace_lock_table,
1393 0, 0, INT_MAX, NULL, NULL
1395 #endif
1398 {"statement_timeout", PGC_USERSET, CLIENT_CONN_STATEMENT,
1399 gettext_noop("Sets the maximum allowed duration of any statement."),
1400 gettext_noop("A value of 0 turns off the timeout."),
1401 GUC_UNIT_MS
1403 &StatementTimeout,
1404 0, 0, INT_MAX, NULL, NULL
1408 {"vacuum_freeze_min_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1409 gettext_noop("Minimum age at which VACUUM should freeze a table row."),
1410 NULL
1412 &vacuum_freeze_min_age,
1413 100000000, 0, 1000000000, NULL, NULL
1417 {"max_fsm_relations", PGC_POSTMASTER, RESOURCES_FSM,
1418 gettext_noop("Sets the maximum number of tables and indexes for which free space is tracked."),
1419 NULL
1421 &MaxFSMRelations,
1422 1000, 100, INT_MAX, NULL, NULL
1425 {"max_fsm_pages", PGC_POSTMASTER, RESOURCES_FSM,
1426 gettext_noop("Sets the maximum number of disk pages for which free space is tracked."),
1427 NULL
1429 &MaxFSMPages,
1430 20000, 1000, INT_MAX, NULL, NULL
1434 {"max_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
1435 gettext_noop("Sets the maximum number of locks per transaction."),
1436 gettext_noop("The shared lock table is sized on the assumption that "
1437 "at most max_locks_per_transaction * max_connections distinct "
1438 "objects will need to be locked at any one time.")
1440 &max_locks_per_xact,
1441 64, 10, INT_MAX, NULL, NULL
1445 {"authentication_timeout", PGC_SIGHUP, CONN_AUTH_SECURITY,
1446 gettext_noop("Sets the maximum allowed time to complete client authentication."),
1447 NULL,
1448 GUC_UNIT_S
1450 &AuthenticationTimeout,
1451 60, 1, 600, NULL, NULL
1455 /* Not for general use */
1456 {"pre_auth_delay", PGC_SIGHUP, DEVELOPER_OPTIONS,
1457 gettext_noop("Waits N seconds on connection startup before authentication."),
1458 gettext_noop("This allows attaching a debugger to the process."),
1459 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1461 &PreAuthDelay,
1462 0, 0, 60, NULL, NULL
1466 {"checkpoint_segments", PGC_SIGHUP, WAL_CHECKPOINTS,
1467 gettext_noop("Sets the maximum distance in log segments between automatic WAL checkpoints."),
1468 NULL
1470 &CheckPointSegments,
1471 3, 1, INT_MAX, NULL, NULL
1475 {"checkpoint_timeout", PGC_SIGHUP, WAL_CHECKPOINTS,
1476 gettext_noop("Sets the maximum time between automatic WAL checkpoints."),
1477 NULL,
1478 GUC_UNIT_S
1480 &CheckPointTimeout,
1481 300, 30, 3600, NULL, NULL
1485 {"checkpoint_warning", PGC_SIGHUP, WAL_CHECKPOINTS,
1486 gettext_noop("Enables warnings if checkpoint segments are filled more "
1487 "frequently than this."),
1488 gettext_noop("Write a message to the server log if checkpoints "
1489 "caused by the filling of checkpoint segment files happens more "
1490 "frequently than this number of seconds. Zero turns off the warning."),
1491 GUC_UNIT_S
1493 &CheckPointWarning,
1494 30, 0, INT_MAX, NULL, NULL
1498 {"wal_buffers", PGC_POSTMASTER, WAL_SETTINGS,
1499 gettext_noop("Sets the number of disk-page buffers in shared memory for WAL."),
1500 NULL,
1501 GUC_UNIT_XBLOCKS
1503 &XLOGbuffers,
1504 8, 4, INT_MAX, NULL, NULL
1508 {"wal_writer_delay", PGC_SIGHUP, WAL_SETTINGS,
1509 gettext_noop("WAL writer sleep time between WAL flushes."),
1510 NULL,
1511 GUC_UNIT_MS
1513 &WalWriterDelay,
1514 200, 1, 10000, NULL, NULL
1518 {"commit_delay", PGC_USERSET, WAL_SETTINGS,
1519 gettext_noop("Sets the delay in microseconds between transaction commit and "
1520 "flushing WAL to disk."),
1521 NULL
1523 &CommitDelay,
1524 0, 0, 100000, NULL, NULL
1528 {"commit_siblings", PGC_USERSET, WAL_SETTINGS,
1529 gettext_noop("Sets the minimum concurrent open transactions before performing "
1530 "commit_delay."),
1531 NULL
1533 &CommitSiblings,
1534 5, 1, 1000, NULL, NULL
1538 {"extra_float_digits", PGC_USERSET, CLIENT_CONN_LOCALE,
1539 gettext_noop("Sets the number of digits displayed for floating-point values."),
1540 gettext_noop("This affects real, double precision, and geometric data types. "
1541 "The parameter value is added to the standard number of digits "
1542 "(FLT_DIG or DBL_DIG as appropriate).")
1544 &extra_float_digits,
1545 0, -15, 2, NULL, NULL
1549 {"log_min_duration_statement", PGC_SUSET, LOGGING_WHEN,
1550 gettext_noop("Sets the minimum execution time above which "
1551 "statements will be logged."),
1552 gettext_noop("Zero prints all queries. -1 turns this feature off."),
1553 GUC_UNIT_MS
1555 &log_min_duration_statement,
1556 -1, -1, INT_MAX / 1000, NULL, NULL
1560 {"log_autovacuum_min_duration", PGC_SIGHUP, LOGGING_WHAT,
1561 gettext_noop("Sets the minimum execution time above which "
1562 "autovacuum actions will be logged."),
1563 gettext_noop("Zero prints all actions. -1 turns autovacuum logging off."),
1564 GUC_UNIT_MS
1566 &Log_autovacuum_min_duration,
1567 -1, -1, INT_MAX / 1000, NULL, NULL
1571 {"bgwriter_delay", PGC_SIGHUP, RESOURCES,
1572 gettext_noop("Background writer sleep time between rounds."),
1573 NULL,
1574 GUC_UNIT_MS
1576 &BgWriterDelay,
1577 200, 10, 10000, NULL, NULL
1581 {"bgwriter_lru_maxpages", PGC_SIGHUP, RESOURCES,
1582 gettext_noop("Background writer maximum number of LRU pages to flush per round."),
1583 NULL
1585 &bgwriter_lru_maxpages,
1586 100, 0, 1000, NULL, NULL
1590 {"log_rotation_age", PGC_SIGHUP, LOGGING_WHERE,
1591 gettext_noop("Automatic log file rotation will occur after N minutes."),
1592 NULL,
1593 GUC_UNIT_MIN
1595 &Log_RotationAge,
1596 HOURS_PER_DAY * MINS_PER_HOUR, 0, INT_MAX / MINS_PER_HOUR, NULL, NULL
1600 {"log_rotation_size", PGC_SIGHUP, LOGGING_WHERE,
1601 gettext_noop("Automatic log file rotation will occur after N kilobytes."),
1602 NULL,
1603 GUC_UNIT_KB
1605 &Log_RotationSize,
1606 10 * 1024, 0, INT_MAX / 1024, NULL, NULL
1610 {"max_function_args", PGC_INTERNAL, PRESET_OPTIONS,
1611 gettext_noop("Shows the maximum number of function arguments."),
1612 NULL,
1613 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1615 &max_function_args,
1616 FUNC_MAX_ARGS, FUNC_MAX_ARGS, FUNC_MAX_ARGS, NULL, NULL
1620 {"max_index_keys", PGC_INTERNAL, PRESET_OPTIONS,
1621 gettext_noop("Shows the maximum number of index keys."),
1622 NULL,
1623 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1625 &max_index_keys,
1626 INDEX_MAX_KEYS, INDEX_MAX_KEYS, INDEX_MAX_KEYS, NULL, NULL
1630 {"max_identifier_length", PGC_INTERNAL, PRESET_OPTIONS,
1631 gettext_noop("Shows the maximum identifier length."),
1632 NULL,
1633 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1635 &max_identifier_length,
1636 NAMEDATALEN - 1, NAMEDATALEN - 1, NAMEDATALEN - 1, NULL, NULL
1640 {"block_size", PGC_INTERNAL, PRESET_OPTIONS,
1641 gettext_noop("Shows the size of a disk block."),
1642 NULL,
1643 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1645 &block_size,
1646 BLCKSZ, BLCKSZ, BLCKSZ, NULL, NULL
1650 {"autovacuum_naptime", PGC_SIGHUP, AUTOVACUUM,
1651 gettext_noop("Time to sleep between autovacuum runs."),
1652 NULL,
1653 GUC_UNIT_S
1655 &autovacuum_naptime,
1656 60, 1, INT_MAX / 1000, NULL, NULL
1659 {"autovacuum_vacuum_threshold", PGC_SIGHUP, AUTOVACUUM,
1660 gettext_noop("Minimum number of tuple updates or deletes prior to vacuum."),
1661 NULL
1663 &autovacuum_vac_thresh,
1664 50, 0, INT_MAX, NULL, NULL
1667 {"autovacuum_analyze_threshold", PGC_SIGHUP, AUTOVACUUM,
1668 gettext_noop("Minimum number of tuple inserts, updates or deletes prior to analyze."),
1669 NULL
1671 &autovacuum_anl_thresh,
1672 50, 0, INT_MAX, NULL, NULL
1675 /* see varsup.c for why this is PGC_POSTMASTER not PGC_SIGHUP */
1676 {"autovacuum_freeze_max_age", PGC_POSTMASTER, AUTOVACUUM,
1677 gettext_noop("Age at which to autovacuum a table to prevent transaction ID wraparound."),
1678 NULL
1680 &autovacuum_freeze_max_age,
1681 200000000, 100000000, 2000000000, NULL, NULL
1684 /* see max_connections */
1685 {"autovacuum_max_workers", PGC_POSTMASTER, AUTOVACUUM,
1686 gettext_noop("Sets the maximum number of simultaneously running autovacuum worker processes."),
1687 NULL
1689 &autovacuum_max_workers,
1690 3, 1, INT_MAX / 4, assign_autovacuum_max_workers, NULL
1694 {"tcp_keepalives_idle", PGC_USERSET, CLIENT_CONN_OTHER,
1695 gettext_noop("Time between issuing TCP keepalives."),
1696 gettext_noop("A value of 0 uses the system default."),
1697 GUC_UNIT_S
1699 &tcp_keepalives_idle,
1700 0, 0, INT_MAX, assign_tcp_keepalives_idle, show_tcp_keepalives_idle
1704 {"tcp_keepalives_interval", PGC_USERSET, CLIENT_CONN_OTHER,
1705 gettext_noop("Time between TCP keepalive retransmits."),
1706 gettext_noop("A value of 0 uses the system default."),
1707 GUC_UNIT_S
1709 &tcp_keepalives_interval,
1710 0, 0, INT_MAX, assign_tcp_keepalives_interval, show_tcp_keepalives_interval
1714 {"tcp_keepalives_count", PGC_USERSET, CLIENT_CONN_OTHER,
1715 gettext_noop("Maximum number of TCP keepalive retransmits."),
1716 gettext_noop("This controls the number of consecutive keepalive retransmits that can be "
1717 "lost before a connection is considered dead. A value of 0 uses the "
1718 "system default."),
1720 &tcp_keepalives_count,
1721 0, 0, INT_MAX, assign_tcp_keepalives_count, show_tcp_keepalives_count
1725 {"gin_fuzzy_search_limit", PGC_USERSET, CLIENT_CONN_OTHER,
1726 gettext_noop("Sets the maximum allowed result for exact search by GIN."),
1727 NULL,
1730 &GinFuzzySearchLimit,
1731 0, 0, INT_MAX, NULL, NULL
1735 {"effective_cache_size", PGC_USERSET, QUERY_TUNING_COST,
1736 gettext_noop("Sets the planner's assumption about the size of the disk cache."),
1737 gettext_noop("That is, the portion of the kernel's disk cache that "
1738 "will be used for PostgreSQL data files. This is measured in disk "
1739 "pages, which are normally 8 kB each."),
1740 GUC_UNIT_BLOCKS,
1742 &effective_cache_size,
1743 DEFAULT_EFFECTIVE_CACHE_SIZE, 1, INT_MAX, NULL, NULL
1747 /* Can't be set in postgresql.conf */
1748 {"server_version_num", PGC_INTERNAL, PRESET_OPTIONS,
1749 gettext_noop("Shows the server version as an integer."),
1750 NULL,
1751 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1753 &server_version_num,
1754 PG_VERSION_NUM, PG_VERSION_NUM, PG_VERSION_NUM, NULL, NULL
1758 {"log_temp_files", PGC_USERSET, LOGGING_WHAT,
1759 gettext_noop("Log the use of temporary files larger than this number of kilobytes."),
1760 gettext_noop("Zero logs all files. The default is -1 (turning this feature off)."),
1761 GUC_UNIT_KB
1763 &log_temp_files,
1764 -1, -1, INT_MAX, NULL, NULL
1767 /* End-of-list marker */
1769 {NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL
1774 static struct config_real ConfigureNamesReal[] =
1777 {"seq_page_cost", PGC_USERSET, QUERY_TUNING_COST,
1778 gettext_noop("Sets the planner's estimate of the cost of a "
1779 "sequentially fetched disk page."),
1780 NULL
1782 &seq_page_cost,
1783 DEFAULT_SEQ_PAGE_COST, 0, DBL_MAX, NULL, NULL
1786 {"random_page_cost", PGC_USERSET, QUERY_TUNING_COST,
1787 gettext_noop("Sets the planner's estimate of the cost of a "
1788 "nonsequentially fetched disk page."),
1789 NULL
1791 &random_page_cost,
1792 DEFAULT_RANDOM_PAGE_COST, 0, DBL_MAX, NULL, NULL
1795 {"cpu_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
1796 gettext_noop("Sets the planner's estimate of the cost of "
1797 "processing each tuple (row)."),
1798 NULL
1800 &cpu_tuple_cost,
1801 DEFAULT_CPU_TUPLE_COST, 0, DBL_MAX, NULL, NULL
1804 {"cpu_index_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
1805 gettext_noop("Sets the planner's estimate of the cost of "
1806 "processing each index entry during an index scan."),
1807 NULL
1809 &cpu_index_tuple_cost,
1810 DEFAULT_CPU_INDEX_TUPLE_COST, 0, DBL_MAX, NULL, NULL
1813 {"cpu_operator_cost", PGC_USERSET, QUERY_TUNING_COST,
1814 gettext_noop("Sets the planner's estimate of the cost of "
1815 "processing each operator or function call."),
1816 NULL
1818 &cpu_operator_cost,
1819 DEFAULT_CPU_OPERATOR_COST, 0, DBL_MAX, NULL, NULL
1823 {"geqo_selection_bias", PGC_USERSET, QUERY_TUNING_GEQO,
1824 gettext_noop("GEQO: selective pressure within the population."),
1825 NULL
1827 &Geqo_selection_bias,
1828 DEFAULT_GEQO_SELECTION_BIAS, MIN_GEQO_SELECTION_BIAS,
1829 MAX_GEQO_SELECTION_BIAS, NULL, NULL
1833 {"bgwriter_lru_multiplier", PGC_SIGHUP, RESOURCES,
1834 gettext_noop("Background writer multiplier on average buffers to scan per round."),
1835 NULL
1837 &bgwriter_lru_multiplier,
1838 2.0, 0.0, 10.0, NULL, NULL
1842 {"seed", PGC_USERSET, UNGROUPED,
1843 gettext_noop("Sets the seed for random-number generation."),
1844 NULL,
1845 GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1847 &phony_random_seed,
1848 0.5, 0.0, 1.0, assign_random_seed, show_random_seed
1852 {"autovacuum_vacuum_scale_factor", PGC_SIGHUP, AUTOVACUUM,
1853 gettext_noop("Number of tuple updates or deletes prior to vacuum as a fraction of reltuples."),
1854 NULL
1856 &autovacuum_vac_scale,
1857 0.2, 0.0, 100.0, NULL, NULL
1860 {"autovacuum_analyze_scale_factor", PGC_SIGHUP, AUTOVACUUM,
1861 gettext_noop("Number of tuple inserts, updates or deletes prior to analyze as a fraction of reltuples."),
1862 NULL
1864 &autovacuum_anl_scale,
1865 0.1, 0.0, 100.0, NULL, NULL
1869 {"checkpoint_completion_target", PGC_SIGHUP, WAL_CHECKPOINTS,
1870 gettext_noop("Time spent flushing dirty buffers during checkpoint, as fraction of checkpoint interval."),
1871 NULL
1873 &CheckPointCompletionTarget,
1874 0.5, 0.0, 1.0, NULL, NULL
1877 /* End-of-list marker */
1879 {NULL, 0, 0, NULL, NULL}, NULL, 0.0, 0.0, 0.0, NULL, NULL
1884 static struct config_string ConfigureNamesString[] =
1887 {"archive_command", PGC_SIGHUP, WAL_SETTINGS,
1888 gettext_noop("Sets the shell command that will be called to archive a WAL file."),
1889 NULL
1891 &XLogArchiveCommand,
1892 "", NULL, show_archive_command
1896 {"backslash_quote", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1897 gettext_noop("Sets whether \"\\'\" is allowed in string literals."),
1898 gettext_noop("Valid values are ON, OFF, and SAFE_ENCODING.")
1900 &backslash_quote_string,
1901 "safe_encoding", assign_backslash_quote, NULL
1905 {"client_encoding", PGC_USERSET, CLIENT_CONN_LOCALE,
1906 gettext_noop("Sets the client's character set encoding."),
1907 NULL,
1908 GUC_IS_NAME | GUC_REPORT
1910 &client_encoding_string,
1911 "SQL_ASCII", assign_client_encoding, NULL
1915 {"client_min_messages", PGC_USERSET, LOGGING_WHEN,
1916 gettext_noop("Sets the message levels that are sent to the client."),
1917 gettext_noop("Valid values are DEBUG5, DEBUG4, DEBUG3, DEBUG2, "
1918 "DEBUG1, LOG, NOTICE, WARNING, and ERROR. Each level includes all the "
1919 "levels that follow it. The later the level, the fewer messages are "
1920 "sent.")
1922 &client_min_messages_str,
1923 "notice", assign_client_min_messages, NULL
1927 {"log_min_messages", PGC_SUSET, LOGGING_WHEN,
1928 gettext_noop("Sets the message levels that are logged."),
1929 gettext_noop("Valid values are DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1, "
1930 "INFO, NOTICE, WARNING, ERROR, LOG, FATAL, and PANIC. Each level "
1931 "includes all the levels that follow it.")
1933 &log_min_messages_str,
1934 "notice", assign_log_min_messages, NULL
1938 {"log_error_verbosity", PGC_SUSET, LOGGING_WHEN,
1939 gettext_noop("Sets the verbosity of logged messages."),
1940 gettext_noop("Valid values are \"terse\", \"default\", and \"verbose\".")
1942 &log_error_verbosity_str,
1943 "default", assign_log_error_verbosity, NULL
1946 {"log_statement", PGC_SUSET, LOGGING_WHAT,
1947 gettext_noop("Sets the type of statements logged."),
1948 gettext_noop("Valid values are \"none\", \"ddl\", \"mod\", and \"all\".")
1950 &log_statement_str,
1951 "none", assign_log_statement, NULL
1955 {"log_min_error_statement", PGC_SUSET, LOGGING_WHEN,
1956 gettext_noop("Causes all statements generating error at or above this level to be logged."),
1957 gettext_noop("All SQL statements that cause an error of the "
1958 "specified level or a higher level are logged.")
1960 &log_min_error_statement_str,
1961 "error", assign_min_error_statement, NULL
1965 {"log_line_prefix", PGC_SIGHUP, LOGGING_WHAT,
1966 gettext_noop("Controls information prefixed to each log line."),
1967 gettext_noop("If blank, no prefix is used.")
1969 &Log_line_prefix,
1970 "", NULL, NULL
1974 {"log_timezone", PGC_SIGHUP, LOGGING_WHAT,
1975 gettext_noop("Sets the time zone to use in log messages."),
1976 NULL
1978 &log_timezone_string,
1979 "UNKNOWN", assign_log_timezone, show_log_timezone
1983 {"DateStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
1984 gettext_noop("Sets the display format for date and time values."),
1985 gettext_noop("Also controls interpretation of ambiguous "
1986 "date inputs."),
1987 GUC_LIST_INPUT | GUC_REPORT
1989 &datestyle_string,
1990 "ISO, MDY", assign_datestyle, NULL
1994 {"default_tablespace", PGC_USERSET, CLIENT_CONN_STATEMENT,
1995 gettext_noop("Sets the default tablespace to create tables and indexes in."),
1996 gettext_noop("An empty string selects the database's default tablespace."),
1997 GUC_IS_NAME
1999 &default_tablespace,
2000 "", assign_default_tablespace, NULL
2004 {"temp_tablespaces", PGC_USERSET, CLIENT_CONN_STATEMENT,
2005 gettext_noop("Sets the tablespace(s) to use for temporary tables and sort files."),
2006 NULL,
2007 GUC_LIST_INPUT | GUC_LIST_QUOTE
2009 &temp_tablespaces,
2010 "", assign_temp_tablespaces, NULL
2014 {"default_transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
2015 gettext_noop("Sets the transaction isolation level of each new transaction."),
2016 gettext_noop("Each SQL transaction has an isolation level, which "
2017 "can be either \"read uncommitted\", \"read committed\", \"repeatable read\", or \"serializable\".")
2019 &default_iso_level_string,
2020 "read committed", assign_defaultxactisolevel, NULL
2024 {"session_replication_role", PGC_SUSET, CLIENT_CONN_STATEMENT,
2025 gettext_noop("Sets the sessions behavior for triggers and rewrite rules."),
2026 gettext_noop("Each session can be either"
2027 " \"origin\", \"replica\" or \"local\".")
2029 &session_replication_role_string,
2030 "origin", assign_session_replication_role, NULL
2034 {"dynamic_library_path", PGC_SUSET, CLIENT_CONN_OTHER,
2035 gettext_noop("Sets the path for dynamically loadable modules."),
2036 gettext_noop("If a dynamically loadable module needs to be opened and "
2037 "the specified name does not have a directory component (i.e., the "
2038 "name does not contain a slash), the system will search this path for "
2039 "the specified file."),
2040 GUC_SUPERUSER_ONLY
2042 &Dynamic_library_path,
2043 "$libdir", NULL, NULL
2047 {"krb_server_keyfile", PGC_POSTMASTER, CONN_AUTH_SECURITY,
2048 gettext_noop("Sets the location of the Kerberos server key file."),
2049 NULL,
2050 GUC_SUPERUSER_ONLY
2052 &pg_krb_server_keyfile,
2053 PG_KRB_SRVTAB, NULL, NULL
2057 {"krb_srvname", PGC_POSTMASTER, CONN_AUTH_SECURITY,
2058 gettext_noop("Sets the name of the Kerberos service."),
2059 NULL
2061 &pg_krb_srvnam,
2062 PG_KRB_SRVNAM, NULL, NULL
2066 {"krb_server_hostname", PGC_POSTMASTER, CONN_AUTH_SECURITY,
2067 gettext_noop("Sets the hostname of the Kerberos server."),
2068 NULL
2070 &pg_krb_server_hostname,
2071 NULL, NULL, NULL
2075 {"bonjour_name", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2076 gettext_noop("Sets the Bonjour broadcast service name."),
2077 NULL
2079 &bonjour_name,
2080 "", NULL, NULL
2083 /* See main.c about why defaults for LC_foo are not all alike */
2086 {"lc_collate", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2087 gettext_noop("Shows the collation order locale."),
2088 NULL,
2089 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2091 &locale_collate,
2092 "C", NULL, NULL
2096 {"lc_ctype", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2097 gettext_noop("Shows the character classification and case conversion locale."),
2098 NULL,
2099 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2101 &locale_ctype,
2102 "C", NULL, NULL
2106 {"lc_messages", PGC_SUSET, CLIENT_CONN_LOCALE,
2107 gettext_noop("Sets the language in which messages are displayed."),
2108 NULL
2110 &locale_messages,
2111 "", locale_messages_assign, NULL
2115 {"lc_monetary", PGC_USERSET, CLIENT_CONN_LOCALE,
2116 gettext_noop("Sets the locale for formatting monetary amounts."),
2117 NULL
2119 &locale_monetary,
2120 "C", locale_monetary_assign, NULL
2124 {"lc_numeric", PGC_USERSET, CLIENT_CONN_LOCALE,
2125 gettext_noop("Sets the locale for formatting numbers."),
2126 NULL
2128 &locale_numeric,
2129 "C", locale_numeric_assign, NULL
2133 {"lc_time", PGC_USERSET, CLIENT_CONN_LOCALE,
2134 gettext_noop("Sets the locale for formatting date and time values."),
2135 NULL
2137 &locale_time,
2138 "C", locale_time_assign, NULL
2142 {"shared_preload_libraries", PGC_POSTMASTER, RESOURCES_KERNEL,
2143 gettext_noop("Lists shared libraries to preload into server."),
2144 NULL,
2145 GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
2147 &shared_preload_libraries_string,
2148 "", NULL, NULL
2152 {"local_preload_libraries", PGC_BACKEND, CLIENT_CONN_OTHER,
2153 gettext_noop("Lists shared libraries to preload into each backend."),
2154 NULL,
2155 GUC_LIST_INPUT | GUC_LIST_QUOTE
2157 &local_preload_libraries_string,
2158 "", NULL, NULL
2162 {"regex_flavor", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
2163 gettext_noop("Sets the regular expression \"flavor\"."),
2164 gettext_noop("This can be set to advanced, extended, or basic.")
2166 &regex_flavor_string,
2167 "advanced", assign_regex_flavor, NULL
2171 {"search_path", PGC_USERSET, CLIENT_CONN_STATEMENT,
2172 gettext_noop("Sets the schema search order for names that are not schema-qualified."),
2173 NULL,
2174 GUC_LIST_INPUT | GUC_LIST_QUOTE
2176 &namespace_search_path,
2177 "\"$user\",public", assign_search_path, NULL
2181 /* Can't be set in postgresql.conf */
2182 {"server_encoding", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2183 gettext_noop("Sets the server (database) character set encoding."),
2184 NULL,
2185 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2187 &server_encoding_string,
2188 "SQL_ASCII", NULL, NULL
2192 /* Can't be set in postgresql.conf */
2193 {"server_version", PGC_INTERNAL, PRESET_OPTIONS,
2194 gettext_noop("Shows the server version."),
2195 NULL,
2196 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2198 &server_version_string,
2199 PG_VERSION, NULL, NULL
2203 /* Not for general use --- used by SET ROLE */
2204 {"role", PGC_USERSET, UNGROUPED,
2205 gettext_noop("Sets the current role."),
2206 NULL,
2207 GUC_IS_NAME | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2209 &role_string,
2210 "none", assign_role, show_role
2214 /* Not for general use --- used by SET SESSION AUTHORIZATION */
2215 {"session_authorization", PGC_USERSET, UNGROUPED,
2216 gettext_noop("Sets the session user name."),
2217 NULL,
2218 GUC_IS_NAME | GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2220 &session_authorization_string,
2221 NULL, assign_session_authorization, show_session_authorization
2225 {"log_destination", PGC_SIGHUP, LOGGING_WHERE,
2226 gettext_noop("Sets the destination for server log output."),
2227 gettext_noop("Valid values are combinations of \"stderr\", "
2228 "\"syslog\", \"csvlog\", and \"eventlog\", "
2229 "depending on the platform."),
2230 GUC_LIST_INPUT
2232 &log_destination_string,
2233 "stderr", assign_log_destination, NULL
2236 {"log_directory", PGC_SIGHUP, LOGGING_WHERE,
2237 gettext_noop("Sets the destination directory for log files."),
2238 gettext_noop("Can be specified as relative to the data directory "
2239 "or as absolute path."),
2240 GUC_SUPERUSER_ONLY
2242 &Log_directory,
2243 "pg_log", assign_canonical_path, NULL
2246 {"log_filename", PGC_SIGHUP, LOGGING_WHERE,
2247 gettext_noop("Sets the file name pattern for log files."),
2248 NULL,
2249 GUC_SUPERUSER_ONLY
2251 &Log_filename,
2252 "postgresql-%Y-%m-%d_%H%M%S.log", NULL, NULL
2255 #ifdef HAVE_SYSLOG
2257 {"syslog_facility", PGC_SIGHUP, LOGGING_WHERE,
2258 gettext_noop("Sets the syslog \"facility\" to be used when syslog enabled."),
2259 gettext_noop("Valid values are LOCAL0, LOCAL1, LOCAL2, LOCAL3, "
2260 "LOCAL4, LOCAL5, LOCAL6, LOCAL7.")
2262 &syslog_facility_str,
2263 "LOCAL0", assign_syslog_facility, NULL
2266 {"syslog_ident", PGC_SIGHUP, LOGGING_WHERE,
2267 gettext_noop("Sets the program name used to identify PostgreSQL "
2268 "messages in syslog."),
2269 NULL
2271 &syslog_ident_str,
2272 "postgres", assign_syslog_ident, NULL
2274 #endif
2277 {"TimeZone", PGC_USERSET, CLIENT_CONN_LOCALE,
2278 gettext_noop("Sets the time zone for displaying and interpreting time stamps."),
2279 NULL,
2280 GUC_REPORT
2282 &timezone_string,
2283 "UNKNOWN", assign_timezone, show_timezone
2286 {"timezone_abbreviations", PGC_USERSET, CLIENT_CONN_LOCALE,
2287 gettext_noop("Selects a file of time zone abbreviations."),
2288 NULL,
2290 &timezone_abbreviations_string,
2291 "UNKNOWN", assign_timezone_abbreviations, NULL
2295 {"transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
2296 gettext_noop("Sets the current transaction's isolation level."),
2297 NULL,
2298 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2300 &XactIsoLevel_string,
2301 NULL, assign_XactIsoLevel, show_XactIsoLevel
2305 {"unix_socket_group", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2306 gettext_noop("Sets the owning group of the Unix-domain socket."),
2307 gettext_noop("The owning user of the socket is always the user "
2308 "that starts the server.")
2310 &Unix_socket_group,
2311 "", NULL, NULL
2315 {"unix_socket_directory", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2316 gettext_noop("Sets the directory where the Unix-domain socket will be created."),
2317 NULL,
2318 GUC_SUPERUSER_ONLY
2320 &UnixSocketDir,
2321 "", assign_canonical_path, NULL
2325 {"listen_addresses", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2326 gettext_noop("Sets the host name or IP address(es) to listen to."),
2327 NULL,
2328 GUC_LIST_INPUT
2330 &ListenAddresses,
2331 "localhost", NULL, NULL
2335 {"wal_sync_method", PGC_SIGHUP, WAL_SETTINGS,
2336 gettext_noop("Selects the method used for forcing WAL updates to disk."),
2337 NULL
2339 &XLOG_sync_method,
2340 XLOG_sync_method_default, assign_xlog_sync_method, NULL
2344 {"custom_variable_classes", PGC_SIGHUP, CUSTOM_OPTIONS,
2345 gettext_noop("Sets the list of known custom variable classes."),
2346 NULL,
2347 GUC_LIST_INPUT | GUC_LIST_QUOTE
2349 &custom_variable_classes,
2350 NULL, assign_custom_variable_classes, NULL
2354 {"data_directory", PGC_POSTMASTER, FILE_LOCATIONS,
2355 gettext_noop("Sets the server's data directory."),
2356 NULL,
2357 GUC_SUPERUSER_ONLY
2359 &data_directory,
2360 NULL, NULL, NULL
2364 {"config_file", PGC_POSTMASTER, FILE_LOCATIONS,
2365 gettext_noop("Sets the server's main configuration file."),
2366 NULL,
2367 GUC_DISALLOW_IN_FILE | GUC_SUPERUSER_ONLY
2369 &ConfigFileName,
2370 NULL, NULL, NULL
2374 {"hba_file", PGC_POSTMASTER, FILE_LOCATIONS,
2375 gettext_noop("Sets the server's \"hba\" configuration file."),
2376 NULL,
2377 GUC_SUPERUSER_ONLY
2379 &HbaFileName,
2380 NULL, NULL, NULL
2384 {"ident_file", PGC_POSTMASTER, FILE_LOCATIONS,
2385 gettext_noop("Sets the server's \"ident\" configuration file."),
2386 NULL,
2387 GUC_SUPERUSER_ONLY
2389 &IdentFileName,
2390 NULL, NULL, NULL
2394 {"external_pid_file", PGC_POSTMASTER, FILE_LOCATIONS,
2395 gettext_noop("Writes the postmaster PID to the specified file."),
2396 NULL,
2397 GUC_SUPERUSER_ONLY
2399 &external_pid_file,
2400 NULL, assign_canonical_path, NULL
2404 {"xmlbinary", PGC_USERSET, CLIENT_CONN_STATEMENT,
2405 gettext_noop("Sets how binary values are to be encoded in XML."),
2406 gettext_noop("Valid values are BASE64 and HEX.")
2408 &xmlbinary_string,
2409 "base64", assign_xmlbinary, NULL
2413 {"xmloption", PGC_USERSET, CLIENT_CONN_STATEMENT,
2414 gettext_noop("Sets whether XML data in implicit parsing and serialization "
2415 "operations is to be considered as documents or content fragments."),
2416 gettext_noop("Valid values are DOCUMENT and CONTENT.")
2418 &xmloption_string,
2419 "content", assign_xmloption, NULL
2423 {"default_text_search_config", PGC_USERSET, CLIENT_CONN_LOCALE,
2424 gettext_noop("Sets default text search configuration."),
2425 NULL
2427 &TSCurrentConfig,
2428 "pg_catalog.simple", assignTSCurrentConfig, NULL
2431 #ifdef USE_SSL
2433 {"ssl_ciphers", PGC_POSTMASTER, CONN_AUTH_SECURITY,
2434 gettext_noop("Sets the list of allowed SSL ciphers."),
2435 NULL,
2436 GUC_SUPERUSER_ONLY
2438 &SSLCipherSuites,
2439 "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH", NULL, NULL
2441 #endif /* USE_SSL */
2443 /* End-of-list marker */
2445 {NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL
2450 /******** end of options list ********/
2454 * To allow continued support of obsolete names for GUC variables, we apply
2455 * the following mappings to any unrecognized name. Note that an old name
2456 * should be mapped to a new one only if the new variable has very similar
2457 * semantics to the old.
2459 static const char *const map_old_guc_names[] = {
2460 "sort_mem", "work_mem",
2461 "vacuum_mem", "maintenance_work_mem",
2462 NULL
2467 * Actual lookup of variables is done through this single, sorted array.
2469 static struct config_generic **guc_variables;
2471 /* Current number of variables contained in the vector */
2472 static int num_guc_variables;
2474 /* Vector capacity */
2475 static int size_guc_variables;
2478 static bool guc_dirty; /* TRUE if need to do commit/abort work */
2480 static bool reporting_enabled; /* TRUE to enable GUC_REPORT */
2482 static int GUCNestLevel = 0; /* 1 when in main transaction */
2485 static int guc_var_compare(const void *a, const void *b);
2486 static int guc_name_compare(const char *namea, const char *nameb);
2487 static void push_old_value(struct config_generic * gconf, GucAction action);
2488 static void ReportGUCOption(struct config_generic * record);
2489 static void ShowGUCConfigOption(const char *name, DestReceiver *dest);
2490 static void ShowAllGUCConfig(DestReceiver *dest);
2491 static char *_ShowOption(struct config_generic * record, bool use_units);
2492 static bool is_newvalue_equal(struct config_generic *record, const char *newvalue);
2496 * Some infrastructure for checking malloc/strdup/realloc calls
2498 static void *
2499 guc_malloc(int elevel, size_t size)
2501 void *data;
2503 data = malloc(size);
2504 if (data == NULL)
2505 ereport(elevel,
2506 (errcode(ERRCODE_OUT_OF_MEMORY),
2507 errmsg("out of memory")));
2508 return data;
2511 static void *
2512 guc_realloc(int elevel, void *old, size_t size)
2514 void *data;
2516 data = realloc(old, size);
2517 if (data == NULL)
2518 ereport(elevel,
2519 (errcode(ERRCODE_OUT_OF_MEMORY),
2520 errmsg("out of memory")));
2521 return data;
2524 static char *
2525 guc_strdup(int elevel, const char *src)
2527 char *data;
2529 data = strdup(src);
2530 if (data == NULL)
2531 ereport(elevel,
2532 (errcode(ERRCODE_OUT_OF_MEMORY),
2533 errmsg("out of memory")));
2534 return data;
2539 * Support for assigning to a field of a string GUC item. Free the prior
2540 * value if it's not referenced anywhere else in the item (including stacked
2541 * states).
2543 static void
2544 set_string_field(struct config_string * conf, char **field, char *newval)
2546 char *oldval = *field;
2547 GucStack *stack;
2549 /* Do the assignment */
2550 *field = newval;
2552 /* Exit if any duplicate references, or if old value was NULL anyway */
2553 if (oldval == NULL ||
2554 oldval == *(conf->variable) ||
2555 oldval == conf->reset_val ||
2556 oldval == conf->boot_val)
2557 return;
2558 for (stack = conf->gen.stack; stack; stack = stack->prev)
2560 if (oldval == stack->prior.stringval ||
2561 oldval == stack->masked.stringval)
2562 return;
2565 /* Not used anymore, so free it */
2566 free(oldval);
2570 * Detect whether strval is referenced anywhere in a GUC string item
2572 static bool
2573 string_field_used(struct config_string * conf, char *strval)
2575 GucStack *stack;
2577 if (strval == *(conf->variable) ||
2578 strval == conf->reset_val ||
2579 strval == conf->boot_val)
2580 return true;
2581 for (stack = conf->gen.stack; stack; stack = stack->prev)
2583 if (strval == stack->prior.stringval ||
2584 strval == stack->masked.stringval)
2585 return true;
2587 return false;
2591 * Support for copying a variable's active value into a stack entry
2593 static void
2594 set_stack_value(struct config_generic * gconf, union config_var_value * val)
2596 switch (gconf->vartype)
2598 case PGC_BOOL:
2599 val->boolval =
2600 *((struct config_bool *) gconf)->variable;
2601 break;
2602 case PGC_INT:
2603 val->intval =
2604 *((struct config_int *) gconf)->variable;
2605 break;
2606 case PGC_REAL:
2607 val->realval =
2608 *((struct config_real *) gconf)->variable;
2609 break;
2610 case PGC_STRING:
2611 /* we assume stringval is NULL if not valid */
2612 set_string_field((struct config_string *) gconf,
2613 &(val->stringval),
2614 *((struct config_string *) gconf)->variable);
2615 break;
2620 * Support for discarding a no-longer-needed value in a stack entry
2622 static void
2623 discard_stack_value(struct config_generic *gconf, union config_var_value *val)
2625 switch (gconf->vartype)
2627 case PGC_BOOL:
2628 case PGC_INT:
2629 case PGC_REAL:
2630 /* no need to do anything */
2631 break;
2632 case PGC_STRING:
2633 set_string_field((struct config_string *) gconf,
2634 &(val->stringval),
2635 NULL);
2636 break;
2642 * Fetch the sorted array pointer (exported for help_config.c's use ONLY)
2644 struct config_generic **
2645 get_guc_variables(void)
2647 return guc_variables;
2652 * Build the sorted array. This is split out so that it could be
2653 * re-executed after startup (eg, we could allow loadable modules to
2654 * add vars, and then we'd need to re-sort).
2656 void
2657 build_guc_variables(void)
2659 int size_vars;
2660 int num_vars = 0;
2661 struct config_generic **guc_vars;
2662 int i;
2664 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
2666 struct config_bool *conf = &ConfigureNamesBool[i];
2668 /* Rather than requiring vartype to be filled in by hand, do this: */
2669 conf->gen.vartype = PGC_BOOL;
2670 num_vars++;
2673 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
2675 struct config_int *conf = &ConfigureNamesInt[i];
2677 conf->gen.vartype = PGC_INT;
2678 num_vars++;
2681 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
2683 struct config_real *conf = &ConfigureNamesReal[i];
2685 conf->gen.vartype = PGC_REAL;
2686 num_vars++;
2689 for (i = 0; ConfigureNamesString[i].gen.name; i++)
2691 struct config_string *conf = &ConfigureNamesString[i];
2693 conf->gen.vartype = PGC_STRING;
2694 num_vars++;
2698 * Create table with 20% slack
2700 size_vars = num_vars + num_vars / 4;
2702 guc_vars = (struct config_generic **)
2703 guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
2705 num_vars = 0;
2707 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
2708 guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
2710 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
2711 guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
2713 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
2714 guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
2716 for (i = 0; ConfigureNamesString[i].gen.name; i++)
2717 guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
2719 if (guc_variables)
2720 free(guc_variables);
2721 guc_variables = guc_vars;
2722 num_guc_variables = num_vars;
2723 size_guc_variables = size_vars;
2724 qsort((void *) guc_variables, num_guc_variables,
2725 sizeof(struct config_generic *), guc_var_compare);
2729 * Add a new GUC variable to the list of known variables. The
2730 * list is expanded if needed.
2732 static bool
2733 add_guc_variable(struct config_generic * var, int elevel)
2735 if (num_guc_variables + 1 >= size_guc_variables)
2738 * Increase the vector by 25%
2740 int size_vars = size_guc_variables + size_guc_variables / 4;
2741 struct config_generic **guc_vars;
2743 if (size_vars == 0)
2745 size_vars = 100;
2746 guc_vars = (struct config_generic **)
2747 guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
2749 else
2751 guc_vars = (struct config_generic **)
2752 guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
2755 if (guc_vars == NULL)
2756 return false; /* out of memory */
2758 guc_variables = guc_vars;
2759 size_guc_variables = size_vars;
2761 guc_variables[num_guc_variables++] = var;
2762 qsort((void *) guc_variables, num_guc_variables,
2763 sizeof(struct config_generic *), guc_var_compare);
2764 return true;
2768 * Create and add a placeholder variable. It's presumed to belong
2769 * to a valid custom variable class at this point.
2771 static struct config_generic *
2772 add_placeholder_variable(const char *name, int elevel)
2774 size_t sz = sizeof(struct config_string) + sizeof(char *);
2775 struct config_string *var;
2776 struct config_generic *gen;
2778 var = (struct config_string *) guc_malloc(elevel, sz);
2779 if (var == NULL)
2780 return NULL;
2781 memset(var, 0, sz);
2782 gen = &var->gen;
2784 gen->name = guc_strdup(elevel, name);
2785 if (gen->name == NULL)
2787 free(var);
2788 return NULL;
2791 gen->context = PGC_USERSET;
2792 gen->group = CUSTOM_OPTIONS;
2793 gen->short_desc = "GUC placeholder variable";
2794 gen->flags = GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_CUSTOM_PLACEHOLDER;
2795 gen->vartype = PGC_STRING;
2798 * The char* is allocated at the end of the struct since we have no
2799 * 'static' place to point to. Note that the current value, as well
2800 * as the boot and reset values, start out NULL.
2802 var->variable = (char **) (var + 1);
2804 if (!add_guc_variable((struct config_generic *) var, elevel))
2806 free((void *) gen->name);
2807 free(var);
2808 return NULL;
2811 return gen;
2815 * Detect whether the portion of "name" before dotPos matches any custom
2816 * variable class name listed in custom_var_classes. The latter must be
2817 * formatted the way that assign_custom_variable_classes does it, ie,
2818 * no whitespace. NULL is valid for custom_var_classes.
2820 static bool
2821 is_custom_class(const char *name, int dotPos, const char *custom_var_classes)
2823 bool result = false;
2824 const char *ccs = custom_var_classes;
2826 if (ccs != NULL)
2828 const char *start = ccs;
2830 for (;; ++ccs)
2832 char c = *ccs;
2834 if (c == '\0' || c == ',')
2836 if (dotPos == ccs - start && strncmp(start, name, dotPos) == 0)
2838 result = true;
2839 break;
2841 if (c == '\0')
2842 break;
2843 start = ccs + 1;
2847 return result;
2851 * Look up option NAME. If it exists, return a pointer to its record,
2852 * else return NULL. If create_placeholders is TRUE, we'll create a
2853 * placeholder record for a valid-looking custom variable name.
2855 static struct config_generic *
2856 find_option(const char *name, bool create_placeholders, int elevel)
2858 const char **key = &name;
2859 struct config_generic **res;
2860 int i;
2862 Assert(name);
2865 * By equating const char ** with struct config_generic *, we are assuming
2866 * the name field is first in config_generic.
2868 res = (struct config_generic **) bsearch((void *) &key,
2869 (void *) guc_variables,
2870 num_guc_variables,
2871 sizeof(struct config_generic *),
2872 guc_var_compare);
2873 if (res)
2874 return *res;
2877 * See if the name is an obsolete name for a variable. We assume that the
2878 * set of supported old names is short enough that a brute-force search is
2879 * the best way.
2881 for (i = 0; map_old_guc_names[i] != NULL; i += 2)
2883 if (guc_name_compare(name, map_old_guc_names[i]) == 0)
2884 return find_option(map_old_guc_names[i + 1], false, elevel);
2887 if (create_placeholders)
2890 * Check if the name is qualified, and if so, check if the qualifier
2891 * matches any custom variable class. If so, add a placeholder.
2893 const char *dot = strchr(name, GUC_QUALIFIER_SEPARATOR);
2895 if (dot != NULL &&
2896 is_custom_class(name, dot - name, custom_variable_classes))
2897 return add_placeholder_variable(name, elevel);
2900 /* Unknown name */
2901 return NULL;
2906 * comparator for qsorting and bsearching guc_variables array
2908 static int
2909 guc_var_compare(const void *a, const void *b)
2911 struct config_generic *confa = *(struct config_generic **) a;
2912 struct config_generic *confb = *(struct config_generic **) b;
2914 return guc_name_compare(confa->name, confb->name);
2918 * the bare comparison function for GUC names
2920 static int
2921 guc_name_compare(const char *namea, const char *nameb)
2924 * The temptation to use strcasecmp() here must be resisted, because the
2925 * array ordering has to remain stable across setlocale() calls. So, build
2926 * our own with a simple ASCII-only downcasing.
2928 while (*namea && *nameb)
2930 char cha = *namea++;
2931 char chb = *nameb++;
2933 if (cha >= 'A' && cha <= 'Z')
2934 cha += 'a' - 'A';
2935 if (chb >= 'A' && chb <= 'Z')
2936 chb += 'a' - 'A';
2937 if (cha != chb)
2938 return cha - chb;
2940 if (*namea)
2941 return 1; /* a is longer */
2942 if (*nameb)
2943 return -1; /* b is longer */
2944 return 0;
2949 * Initialize GUC options during program startup.
2951 * Note that we cannot read the config file yet, since we have not yet
2952 * processed command-line switches.
2954 void
2955 InitializeGUCOptions(void)
2957 int i;
2958 char *env;
2959 long stack_rlimit;
2962 * Before log_line_prefix could possibly receive a nonempty setting,
2963 * make sure that timezone processing is minimally alive (see elog.c).
2965 pg_timezone_pre_initialize();
2968 * Build sorted array of all GUC variables.
2970 build_guc_variables();
2973 * Load all variables with their compiled-in defaults, and initialize
2974 * status fields as needed.
2976 for (i = 0; i < num_guc_variables; i++)
2978 struct config_generic *gconf = guc_variables[i];
2980 gconf->status = 0;
2981 gconf->reset_source = PGC_S_DEFAULT;
2982 gconf->source = PGC_S_DEFAULT;
2983 gconf->stack = NULL;
2985 switch (gconf->vartype)
2987 case PGC_BOOL:
2989 struct config_bool *conf = (struct config_bool *) gconf;
2991 if (conf->assign_hook)
2992 if (!(*conf->assign_hook) (conf->boot_val, true,
2993 PGC_S_DEFAULT))
2994 elog(FATAL, "failed to initialize %s to %d",
2995 conf->gen.name, (int) conf->boot_val);
2996 *conf->variable = conf->reset_val = conf->boot_val;
2997 break;
2999 case PGC_INT:
3001 struct config_int *conf = (struct config_int *) gconf;
3003 Assert(conf->boot_val >= conf->min);
3004 Assert(conf->boot_val <= conf->max);
3005 if (conf->assign_hook)
3006 if (!(*conf->assign_hook) (conf->boot_val, true,
3007 PGC_S_DEFAULT))
3008 elog(FATAL, "failed to initialize %s to %d",
3009 conf->gen.name, conf->boot_val);
3010 *conf->variable = conf->reset_val = conf->boot_val;
3011 break;
3013 case PGC_REAL:
3015 struct config_real *conf = (struct config_real *) gconf;
3017 Assert(conf->boot_val >= conf->min);
3018 Assert(conf->boot_val <= conf->max);
3019 if (conf->assign_hook)
3020 if (!(*conf->assign_hook) (conf->boot_val, true,
3021 PGC_S_DEFAULT))
3022 elog(FATAL, "failed to initialize %s to %g",
3023 conf->gen.name, conf->boot_val);
3024 *conf->variable = conf->reset_val = conf->boot_val;
3025 break;
3027 case PGC_STRING:
3029 struct config_string *conf = (struct config_string *) gconf;
3030 char *str;
3032 *conf->variable = NULL;
3033 conf->reset_val = NULL;
3035 if (conf->boot_val == NULL)
3037 /* leave the value NULL, do not call assign hook */
3038 break;
3041 str = guc_strdup(FATAL, conf->boot_val);
3042 conf->reset_val = str;
3044 if (conf->assign_hook)
3046 const char *newstr;
3048 newstr = (*conf->assign_hook) (str, true,
3049 PGC_S_DEFAULT);
3050 if (newstr == NULL)
3052 elog(FATAL, "failed to initialize %s to \"%s\"",
3053 conf->gen.name, str);
3055 else if (newstr != str)
3057 free(str);
3060 * See notes in set_config_option about casting
3062 str = (char *) newstr;
3063 conf->reset_val = str;
3066 *conf->variable = str;
3067 break;
3072 guc_dirty = false;
3074 reporting_enabled = false;
3077 * Prevent any attempt to override the transaction modes from
3078 * non-interactive sources.
3080 SetConfigOption("transaction_isolation", "default",
3081 PGC_POSTMASTER, PGC_S_OVERRIDE);
3082 SetConfigOption("transaction_read_only", "no",
3083 PGC_POSTMASTER, PGC_S_OVERRIDE);
3086 * For historical reasons, some GUC parameters can receive defaults from
3087 * environment variables. Process those settings. NB: if you add or
3088 * remove anything here, see also ProcessConfigFile().
3091 env = getenv("PGPORT");
3092 if (env != NULL)
3093 SetConfigOption("port", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3095 env = getenv("PGDATESTYLE");
3096 if (env != NULL)
3097 SetConfigOption("datestyle", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3099 env = getenv("PGCLIENTENCODING");
3100 if (env != NULL)
3101 SetConfigOption("client_encoding", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3104 * rlimit isn't exactly an "environment variable", but it behaves about
3105 * the same. If we can identify the platform stack depth rlimit, increase
3106 * default stack depth setting up to whatever is safe (but at most 2MB).
3108 stack_rlimit = get_stack_depth_rlimit();
3109 if (stack_rlimit > 0)
3111 int new_limit = (stack_rlimit - STACK_DEPTH_SLOP) / 1024L;
3113 if (new_limit > 100)
3115 char limbuf[16];
3117 new_limit = Min(new_limit, 2048);
3118 sprintf(limbuf, "%d", new_limit);
3119 SetConfigOption("max_stack_depth", limbuf,
3120 PGC_POSTMASTER, PGC_S_ENV_VAR);
3127 * Select the configuration files and data directory to be used, and
3128 * do the initial read of postgresql.conf.
3130 * This is called after processing command-line switches.
3131 * userDoption is the -D switch value if any (NULL if unspecified).
3132 * progname is just for use in error messages.
3134 * Returns true on success; on failure, prints a suitable error message
3135 * to stderr and returns false.
3137 bool
3138 SelectConfigFiles(const char *userDoption, const char *progname)
3140 char *configdir;
3141 char *fname;
3142 struct stat stat_buf;
3144 /* configdir is -D option, or $PGDATA if no -D */
3145 if (userDoption)
3146 configdir = make_absolute_path(userDoption);
3147 else
3148 configdir = make_absolute_path(getenv("PGDATA"));
3151 * Find the configuration file: if config_file was specified on the
3152 * command line, use it, else use configdir/postgresql.conf. In any case
3153 * ensure the result is an absolute path, so that it will be interpreted
3154 * the same way by future backends.
3156 if (ConfigFileName)
3157 fname = make_absolute_path(ConfigFileName);
3158 else if (configdir)
3160 fname = guc_malloc(FATAL,
3161 strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
3162 sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
3164 else
3166 write_stderr("%s does not know where to find the server configuration file.\n"
3167 "You must specify the --config-file or -D invocation "
3168 "option or set the PGDATA environment variable.\n",
3169 progname);
3170 return false;
3174 * Set the ConfigFileName GUC variable to its final value, ensuring that
3175 * it can't be overridden later.
3177 SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
3178 free(fname);
3181 * Now read the config file for the first time.
3183 if (stat(ConfigFileName, &stat_buf) != 0)
3185 write_stderr("%s cannot access the server configuration file \"%s\": %s\n",
3186 progname, ConfigFileName, strerror(errno));
3187 return false;
3190 ProcessConfigFile(PGC_POSTMASTER);
3193 * If the data_directory GUC variable has been set, use that as DataDir;
3194 * otherwise use configdir if set; else punt.
3196 * Note: SetDataDir will copy and absolute-ize its argument, so we don't
3197 * have to.
3199 if (data_directory)
3200 SetDataDir(data_directory);
3201 else if (configdir)
3202 SetDataDir(configdir);
3203 else
3205 write_stderr("%s does not know where to find the database system data.\n"
3206 "This can be specified as \"data_directory\" in \"%s\", "
3207 "or by the -D invocation option, or by the "
3208 "PGDATA environment variable.\n",
3209 progname, ConfigFileName);
3210 return false;
3214 * Reflect the final DataDir value back into the data_directory GUC var.
3215 * (If you are wondering why we don't just make them a single variable,
3216 * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
3217 * child backends specially. XXX is that still true? Given that we now
3218 * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
3219 * DataDir in advance.)
3221 SetConfigOption("data_directory", DataDir, PGC_POSTMASTER, PGC_S_OVERRIDE);
3224 * Figure out where pg_hba.conf is, and make sure the path is absolute.
3226 if (HbaFileName)
3227 fname = make_absolute_path(HbaFileName);
3228 else if (configdir)
3230 fname = guc_malloc(FATAL,
3231 strlen(configdir) + strlen(HBA_FILENAME) + 2);
3232 sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
3234 else
3236 write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
3237 "This can be specified as \"hba_file\" in \"%s\", "
3238 "or by the -D invocation option, or by the "
3239 "PGDATA environment variable.\n",
3240 progname, ConfigFileName);
3241 return false;
3243 SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
3244 free(fname);
3247 * Likewise for pg_ident.conf.
3249 if (IdentFileName)
3250 fname = make_absolute_path(IdentFileName);
3251 else if (configdir)
3253 fname = guc_malloc(FATAL,
3254 strlen(configdir) + strlen(IDENT_FILENAME) + 2);
3255 sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
3257 else
3259 write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
3260 "This can be specified as \"ident_file\" in \"%s\", "
3261 "or by the -D invocation option, or by the "
3262 "PGDATA environment variable.\n",
3263 progname, ConfigFileName);
3264 return false;
3266 SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
3267 free(fname);
3269 free(configdir);
3271 return true;
3276 * Reset all options to their saved default values (implements RESET ALL)
3278 void
3279 ResetAllOptions(void)
3281 int i;
3283 for (i = 0; i < num_guc_variables; i++)
3285 struct config_generic *gconf = guc_variables[i];
3287 /* Don't reset non-SET-able values */
3288 if (gconf->context != PGC_SUSET &&
3289 gconf->context != PGC_USERSET)
3290 continue;
3291 /* Don't reset if special exclusion from RESET ALL */
3292 if (gconf->flags & GUC_NO_RESET_ALL)
3293 continue;
3294 /* No need to reset if wasn't SET */
3295 if (gconf->source <= PGC_S_OVERRIDE)
3296 continue;
3298 /* Save old value to support transaction abort */
3299 push_old_value(gconf, GUC_ACTION_SET);
3301 switch (gconf->vartype)
3303 case PGC_BOOL:
3305 struct config_bool *conf = (struct config_bool *) gconf;
3307 if (conf->assign_hook)
3308 if (!(*conf->assign_hook) (conf->reset_val, true,
3309 PGC_S_SESSION))
3310 elog(ERROR, "failed to reset %s", conf->gen.name);
3311 *conf->variable = conf->reset_val;
3312 conf->gen.source = conf->gen.reset_source;
3313 break;
3315 case PGC_INT:
3317 struct config_int *conf = (struct config_int *) gconf;
3319 if (conf->assign_hook)
3320 if (!(*conf->assign_hook) (conf->reset_val, true,
3321 PGC_S_SESSION))
3322 elog(ERROR, "failed to reset %s", conf->gen.name);
3323 *conf->variable = conf->reset_val;
3324 conf->gen.source = conf->gen.reset_source;
3325 break;
3327 case PGC_REAL:
3329 struct config_real *conf = (struct config_real *) gconf;
3331 if (conf->assign_hook)
3332 if (!(*conf->assign_hook) (conf->reset_val, true,
3333 PGC_S_SESSION))
3334 elog(ERROR, "failed to reset %s", conf->gen.name);
3335 *conf->variable = conf->reset_val;
3336 conf->gen.source = conf->gen.reset_source;
3337 break;
3339 case PGC_STRING:
3341 struct config_string *conf = (struct config_string *) gconf;
3342 char *str;
3344 /* We need not strdup here */
3345 str = conf->reset_val;
3347 if (conf->assign_hook && str)
3349 const char *newstr;
3351 newstr = (*conf->assign_hook) (str, true,
3352 PGC_S_SESSION);
3353 if (newstr == NULL)
3354 elog(ERROR, "failed to reset %s", conf->gen.name);
3355 else if (newstr != str)
3358 * See notes in set_config_option about casting
3360 str = (char *) newstr;
3364 set_string_field(conf, conf->variable, str);
3365 conf->gen.source = conf->gen.reset_source;
3366 break;
3370 if (gconf->flags & GUC_REPORT)
3371 ReportGUCOption(gconf);
3377 * push_old_value
3378 * Push previous state during transactional assignment to a GUC variable.
3380 static void
3381 push_old_value(struct config_generic * gconf, GucAction action)
3383 GucStack *stack;
3385 /* If we're not inside a nest level, do nothing */
3386 if (GUCNestLevel == 0)
3387 return;
3389 /* Do we already have a stack entry of the current nest level? */
3390 stack = gconf->stack;
3391 if (stack && stack->nest_level >= GUCNestLevel)
3393 /* Yes, so adjust its state if necessary */
3394 Assert(stack->nest_level == GUCNestLevel);
3395 switch (action)
3397 case GUC_ACTION_SET:
3398 /* SET overrides any prior action at same nest level */
3399 if (stack->state == GUC_SET_LOCAL)
3401 /* must discard old masked value */
3402 discard_stack_value(gconf, &stack->masked);
3404 stack->state = GUC_SET;
3405 break;
3406 case GUC_ACTION_LOCAL:
3407 if (stack->state == GUC_SET)
3409 /* SET followed by SET LOCAL, remember SET's value */
3410 set_stack_value(gconf, &stack->masked);
3411 stack->state = GUC_SET_LOCAL;
3413 /* in all other cases, no change to stack entry */
3414 break;
3415 case GUC_ACTION_SAVE:
3416 /* Could only have a prior SAVE of same variable */
3417 Assert(stack->state == GUC_SAVE);
3418 break;
3420 Assert(guc_dirty); /* must be set already */
3421 return;
3425 * Push a new stack entry
3427 * We keep all the stack entries in TopTransactionContext for simplicity.
3429 stack = (GucStack *) MemoryContextAllocZero(TopTransactionContext,
3430 sizeof(GucStack));
3432 stack->prev = gconf->stack;
3433 stack->nest_level = GUCNestLevel;
3434 switch (action)
3436 case GUC_ACTION_SET:
3437 stack->state = GUC_SET;
3438 break;
3439 case GUC_ACTION_LOCAL:
3440 stack->state = GUC_LOCAL;
3441 break;
3442 case GUC_ACTION_SAVE:
3443 stack->state = GUC_SAVE;
3444 break;
3446 stack->source = gconf->source;
3447 set_stack_value(gconf, &stack->prior);
3449 gconf->stack = stack;
3451 /* Ensure we remember to pop at end of xact */
3452 guc_dirty = true;
3457 * Do GUC processing at main transaction start.
3459 void
3460 AtStart_GUC(void)
3463 * The nest level should be 0 between transactions; if it isn't,
3464 * somebody didn't call AtEOXact_GUC, or called it with the wrong
3465 * nestLevel. We throw a warning but make no other effort to clean up.
3467 if (GUCNestLevel != 0)
3468 elog(WARNING, "GUC nest level = %d at transaction start",
3469 GUCNestLevel);
3470 GUCNestLevel = 1;
3474 * Enter a new nesting level for GUC values. This is called at subtransaction
3475 * start and when entering a function that has proconfig settings. NOTE that
3476 * we must not risk error here, else subtransaction start will be unhappy.
3479 NewGUCNestLevel(void)
3481 return ++GUCNestLevel;
3485 * Do GUC processing at transaction or subtransaction commit or abort, or
3486 * when exiting a function that has proconfig settings. (The name is thus
3487 * a bit of a misnomer; perhaps it should be ExitGUCNestLevel or some such.)
3488 * During abort, we discard all GUC settings that were applied at nesting
3489 * levels >= nestLevel. nestLevel == 1 corresponds to the main transaction.
3491 void
3492 AtEOXact_GUC(bool isCommit, int nestLevel)
3494 bool still_dirty;
3495 int i;
3497 Assert(nestLevel > 0 && nestLevel <= GUCNestLevel);
3499 /* Quick exit if nothing's changed in this transaction */
3500 if (!guc_dirty)
3502 GUCNestLevel = nestLevel - 1;
3503 return;
3506 still_dirty = false;
3507 for (i = 0; i < num_guc_variables; i++)
3509 struct config_generic *gconf = guc_variables[i];
3510 GucStack *stack;
3513 * Process and pop each stack entry within the nest level. To
3514 * simplify fmgr_security_definer(), we allow failure exit from
3515 * a function-with-SET-options to be recovered at the surrounding
3516 * transaction or subtransaction abort; so there could be more than
3517 * one stack entry to pop.
3519 while ((stack = gconf->stack) != NULL &&
3520 stack->nest_level >= nestLevel)
3522 GucStack *prev = stack->prev;
3523 bool restorePrior = false;
3524 bool restoreMasked = false;
3525 bool changed;
3528 * In this next bit, if we don't set either restorePrior or
3529 * restoreMasked, we must "discard" any unwanted fields of the
3530 * stack entries to avoid leaking memory. If we do set one of
3531 * those flags, unused fields will be cleaned up after restoring.
3533 if (!isCommit) /* if abort, always restore prior value */
3534 restorePrior = true;
3535 else if (stack->state == GUC_SAVE)
3536 restorePrior = true;
3537 else if (stack->nest_level == 1)
3539 /* transaction commit */
3540 if (stack->state == GUC_SET_LOCAL)
3541 restoreMasked = true;
3542 else if (stack->state == GUC_SET)
3544 /* we keep the current active value */
3545 discard_stack_value(gconf, &stack->prior);
3547 else /* must be GUC_LOCAL */
3548 restorePrior = true;
3550 else if (prev == NULL ||
3551 prev->nest_level < stack->nest_level - 1)
3553 /* decrement entry's level and do not pop it */
3554 stack->nest_level--;
3555 continue;
3557 else
3560 * We have to merge this stack entry into prev.
3561 * See README for discussion of this bit.
3563 switch (stack->state)
3565 case GUC_SAVE:
3566 Assert(false); /* can't get here */
3568 case GUC_SET:
3569 /* next level always becomes SET */
3570 discard_stack_value(gconf, &stack->prior);
3571 if (prev->state == GUC_SET_LOCAL)
3572 discard_stack_value(gconf, &prev->masked);
3573 prev->state = GUC_SET;
3574 break;
3576 case GUC_LOCAL:
3577 if (prev->state == GUC_SET)
3579 /* LOCAL migrates down */
3580 prev->masked = stack->prior;
3581 prev->state = GUC_SET_LOCAL;
3583 else
3585 /* else just forget this stack level */
3586 discard_stack_value(gconf, &stack->prior);
3588 break;
3590 case GUC_SET_LOCAL:
3591 /* prior state at this level no longer wanted */
3592 discard_stack_value(gconf, &stack->prior);
3593 /* copy down the masked state */
3594 if (prev->state == GUC_SET_LOCAL)
3595 discard_stack_value(gconf, &prev->masked);
3596 prev->masked = stack->masked;
3597 prev->state = GUC_SET_LOCAL;
3598 break;
3602 changed = false;
3604 if (restorePrior || restoreMasked)
3606 /* Perform appropriate restoration of the stacked value */
3607 union config_var_value newvalue;
3608 GucSource newsource;
3610 if (restoreMasked)
3612 newvalue = stack->masked;
3613 newsource = PGC_S_SESSION;
3615 else
3617 newvalue = stack->prior;
3618 newsource = stack->source;
3621 switch (gconf->vartype)
3623 case PGC_BOOL:
3625 struct config_bool *conf = (struct config_bool *) gconf;
3626 bool newval = newvalue.boolval;
3628 if (*conf->variable != newval)
3630 if (conf->assign_hook)
3631 if (!(*conf->assign_hook) (newval,
3632 true, PGC_S_OVERRIDE))
3633 elog(LOG, "failed to commit %s",
3634 conf->gen.name);
3635 *conf->variable = newval;
3636 changed = true;
3638 break;
3640 case PGC_INT:
3642 struct config_int *conf = (struct config_int *) gconf;
3643 int newval = newvalue.intval;
3645 if (*conf->variable != newval)
3647 if (conf->assign_hook)
3648 if (!(*conf->assign_hook) (newval,
3649 true, PGC_S_OVERRIDE))
3650 elog(LOG, "failed to commit %s",
3651 conf->gen.name);
3652 *conf->variable = newval;
3653 changed = true;
3655 break;
3657 case PGC_REAL:
3659 struct config_real *conf = (struct config_real *) gconf;
3660 double newval = newvalue.realval;
3662 if (*conf->variable != newval)
3664 if (conf->assign_hook)
3665 if (!(*conf->assign_hook) (newval,
3666 true, PGC_S_OVERRIDE))
3667 elog(LOG, "failed to commit %s",
3668 conf->gen.name);
3669 *conf->variable = newval;
3670 changed = true;
3672 break;
3674 case PGC_STRING:
3676 struct config_string *conf = (struct config_string *) gconf;
3677 char *newval = newvalue.stringval;
3679 if (*conf->variable != newval)
3681 if (conf->assign_hook && newval)
3683 const char *newstr;
3685 newstr = (*conf->assign_hook) (newval, true,
3686 PGC_S_OVERRIDE);
3687 if (newstr == NULL)
3688 elog(LOG, "failed to commit %s",
3689 conf->gen.name);
3690 else if (newstr != newval)
3693 * If newval should now be freed, it'll be
3694 * taken care of below.
3696 * See notes in set_config_option about
3697 * casting
3699 newval = (char *) newstr;
3703 set_string_field(conf, conf->variable, newval);
3704 changed = true;
3707 * Release stacked values if not used anymore.
3708 * We could use discard_stack_value() here, but since
3709 * we have type-specific code anyway, might as well
3710 * inline it.
3712 set_string_field(conf, &stack->prior.stringval, NULL);
3713 set_string_field(conf, &stack->masked.stringval, NULL);
3714 break;
3718 gconf->source = newsource;
3721 /* Finish popping the state stack */
3722 gconf->stack = prev;
3723 pfree(stack);
3725 /* Report new value if we changed it */
3726 if (changed && (gconf->flags & GUC_REPORT))
3727 ReportGUCOption(gconf);
3728 } /* end of stack-popping loop */
3730 if (stack != NULL)
3731 still_dirty = true;
3734 /* If there are no remaining stack entries, we can reset guc_dirty */
3735 guc_dirty = still_dirty;
3737 /* Update nesting level */
3738 GUCNestLevel = nestLevel - 1;
3743 * Start up automatic reporting of changes to variables marked GUC_REPORT.
3744 * This is executed at completion of backend startup.
3746 void
3747 BeginReportingGUCOptions(void)
3749 int i;
3752 * Don't do anything unless talking to an interactive frontend of protocol
3753 * 3.0 or later.
3755 if (whereToSendOutput != DestRemote ||
3756 PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
3757 return;
3759 reporting_enabled = true;
3761 /* Transmit initial values of interesting variables */
3762 for (i = 0; i < num_guc_variables; i++)
3764 struct config_generic *conf = guc_variables[i];
3766 if (conf->flags & GUC_REPORT)
3767 ReportGUCOption(conf);
3772 * ReportGUCOption: if appropriate, transmit option value to frontend
3774 static void
3775 ReportGUCOption(struct config_generic * record)
3777 if (reporting_enabled && (record->flags & GUC_REPORT))
3779 char *val = _ShowOption(record, false);
3780 StringInfoData msgbuf;
3782 pq_beginmessage(&msgbuf, 'S');
3783 pq_sendstring(&msgbuf, record->name);
3784 pq_sendstring(&msgbuf, val);
3785 pq_endmessage(&msgbuf);
3787 pfree(val);
3793 * Try to interpret value as boolean value. Valid values are: true,
3794 * false, yes, no, on, off, 1, 0; as well as unique prefixes thereof.
3795 * If the string parses okay, return true, else false.
3796 * If okay and result is not NULL, return the value in *result.
3798 static bool
3799 parse_bool(const char *value, bool *result)
3801 size_t len = strlen(value);
3803 if (pg_strncasecmp(value, "true", len) == 0)
3805 if (result)
3806 *result = true;
3808 else if (pg_strncasecmp(value, "false", len) == 0)
3810 if (result)
3811 *result = false;
3814 else if (pg_strncasecmp(value, "yes", len) == 0)
3816 if (result)
3817 *result = true;
3819 else if (pg_strncasecmp(value, "no", len) == 0)
3821 if (result)
3822 *result = false;
3825 /* 'o' is not unique enough */
3826 else if (pg_strncasecmp(value, "on", (len > 2 ? len : 2)) == 0)
3828 if (result)
3829 *result = true;
3831 else if (pg_strncasecmp(value, "off", (len > 2 ? len : 2)) == 0)
3833 if (result)
3834 *result = false;
3837 else if (pg_strcasecmp(value, "1") == 0)
3839 if (result)
3840 *result = true;
3842 else if (pg_strcasecmp(value, "0") == 0)
3844 if (result)
3845 *result = false;
3848 else
3850 if (result)
3851 *result = false; /* suppress compiler warning */
3852 return false;
3854 return true;
3860 * Try to parse value as an integer. The accepted formats are the
3861 * usual decimal, octal, or hexadecimal formats, optionally followed by
3862 * a unit name if "flags" indicates a unit is allowed.
3864 * If the string parses okay, return true, else false.
3865 * If okay and result is not NULL, return the value in *result.
3866 * If not okay and hintmsg is not NULL, *hintmsg is set to a suitable
3867 * HINT message, or NULL if no hint provided.
3869 static bool
3870 parse_int(const char *value, int *result, int flags, const char **hintmsg)
3872 int64 val;
3873 char *endptr;
3875 /* To suppress compiler warnings, always set output params */
3876 if (result)
3877 *result = 0;
3878 if (hintmsg)
3879 *hintmsg = NULL;
3881 /* We assume here that int64 is at least as wide as long */
3882 errno = 0;
3883 val = strtol(value, &endptr, 0);
3885 if (endptr == value)
3886 return false; /* no HINT for integer syntax error */
3888 if (errno == ERANGE || val != (int64) ((int32) val))
3890 if (hintmsg)
3891 *hintmsg = gettext_noop("Value exceeds integer range.");
3892 return false;
3895 /* allow whitespace between integer and unit */
3896 while (isspace((unsigned char) *endptr))
3897 endptr++;
3899 /* Handle possible unit */
3900 if (*endptr != '\0')
3903 * Note: the multiple-switch coding technique here is a bit tedious,
3904 * but seems necessary to avoid intermediate-value overflows.
3906 * If INT64_IS_BUSTED (ie, it's really int32) we will fail to detect
3907 * overflow due to units conversion, but there are few enough such
3908 * machines that it does not seem worth trying to be smarter.
3910 if (flags & GUC_UNIT_MEMORY)
3912 /* Set hint for use if no match or trailing garbage */
3913 if (hintmsg)
3914 *hintmsg = gettext_noop("Valid units for this parameter are \"kB\", \"MB\", and \"GB\".");
3916 #if BLCKSZ < 1024 || BLCKSZ > (1024*1024)
3917 #error BLCKSZ must be between 1KB and 1MB
3918 #endif
3919 #if XLOG_BLCKSZ < 1024 || XLOG_BLCKSZ > (1024*1024)
3920 #error XLOG_BLCKSZ must be between 1KB and 1MB
3921 #endif
3923 if (strncmp(endptr, "kB", 2) == 0)
3925 endptr += 2;
3926 switch (flags & GUC_UNIT_MEMORY)
3928 case GUC_UNIT_BLOCKS:
3929 val /= (BLCKSZ / 1024);
3930 break;
3931 case GUC_UNIT_XBLOCKS:
3932 val /= (XLOG_BLCKSZ / 1024);
3933 break;
3936 else if (strncmp(endptr, "MB", 2) == 0)
3938 endptr += 2;
3939 switch (flags & GUC_UNIT_MEMORY)
3941 case GUC_UNIT_KB:
3942 val *= KB_PER_MB;
3943 break;
3944 case GUC_UNIT_BLOCKS:
3945 val *= KB_PER_MB / (BLCKSZ / 1024);
3946 break;
3947 case GUC_UNIT_XBLOCKS:
3948 val *= KB_PER_MB / (XLOG_BLCKSZ / 1024);
3949 break;
3952 else if (strncmp(endptr, "GB", 2) == 0)
3954 endptr += 2;
3955 switch (flags & GUC_UNIT_MEMORY)
3957 case GUC_UNIT_KB:
3958 val *= KB_PER_GB;
3959 break;
3960 case GUC_UNIT_BLOCKS:
3961 val *= KB_PER_GB / (BLCKSZ / 1024);
3962 break;
3963 case GUC_UNIT_XBLOCKS:
3964 val *= KB_PER_GB / (XLOG_BLCKSZ / 1024);
3965 break;
3969 else if (flags & GUC_UNIT_TIME)
3971 /* Set hint for use if no match or trailing garbage */
3972 if (hintmsg)
3973 *hintmsg = gettext_noop("Valid units for this parameter are \"ms\", \"s\", \"min\", \"h\", and \"d\".");
3975 if (strncmp(endptr, "ms", 2) == 0)
3977 endptr += 2;
3978 switch (flags & GUC_UNIT_TIME)
3980 case GUC_UNIT_S:
3981 val /= MS_PER_S;
3982 break;
3983 case GUC_UNIT_MIN:
3984 val /= MS_PER_MIN;
3985 break;
3988 else if (strncmp(endptr, "s", 1) == 0)
3990 endptr += 1;
3991 switch (flags & GUC_UNIT_TIME)
3993 case GUC_UNIT_MS:
3994 val *= MS_PER_S;
3995 break;
3996 case GUC_UNIT_MIN:
3997 val /= S_PER_MIN;
3998 break;
4001 else if (strncmp(endptr, "min", 3) == 0)
4003 endptr += 3;
4004 switch (flags & GUC_UNIT_TIME)
4006 case GUC_UNIT_MS:
4007 val *= MS_PER_MIN;
4008 break;
4009 case GUC_UNIT_S:
4010 val *= S_PER_MIN;
4011 break;
4014 else if (strncmp(endptr, "h", 1) == 0)
4016 endptr += 1;
4017 switch (flags & GUC_UNIT_TIME)
4019 case GUC_UNIT_MS:
4020 val *= MS_PER_H;
4021 break;
4022 case GUC_UNIT_S:
4023 val *= S_PER_H;
4024 break;
4025 case GUC_UNIT_MIN:
4026 val *= MIN_PER_H;
4027 break;
4030 else if (strncmp(endptr, "d", 1) == 0)
4032 endptr += 1;
4033 switch (flags & GUC_UNIT_TIME)
4035 case GUC_UNIT_MS:
4036 val *= MS_PER_D;
4037 break;
4038 case GUC_UNIT_S:
4039 val *= S_PER_D;
4040 break;
4041 case GUC_UNIT_MIN:
4042 val *= MIN_PER_D;
4043 break;
4048 /* allow whitespace after unit */
4049 while (isspace((unsigned char) *endptr))
4050 endptr++;
4052 if (*endptr != '\0')
4053 return false; /* appropriate hint, if any, already set */
4055 /* Check for overflow due to units conversion */
4056 if (val != (int64) ((int32) val))
4058 if (hintmsg)
4059 *hintmsg = gettext_noop("Value exceeds integer range.");
4060 return false;
4064 if (result)
4065 *result = (int) val;
4066 return true;
4072 * Try to parse value as a floating point number in the usual format.
4073 * If the string parses okay, return true, else false.
4074 * If okay and result is not NULL, return the value in *result.
4076 static bool
4077 parse_real(const char *value, double *result)
4079 double val;
4080 char *endptr;
4082 if (result)
4083 *result = 0; /* suppress compiler warning */
4085 errno = 0;
4086 val = strtod(value, &endptr);
4087 if (endptr == value || errno == ERANGE)
4088 return false;
4090 /* allow whitespace after number */
4091 while (isspace((unsigned char) *endptr))
4092 endptr++;
4093 if (*endptr != '\0')
4094 return false;
4096 if (result)
4097 *result = val;
4098 return true;
4103 * Call a GucStringAssignHook function, being careful to free the
4104 * "newval" string if the hook ereports.
4106 * This is split out of set_config_option just to avoid the "volatile"
4107 * qualifiers that would otherwise have to be plastered all over.
4109 static const char *
4110 call_string_assign_hook(GucStringAssignHook assign_hook,
4111 char *newval, bool doit, GucSource source)
4113 const char *result;
4115 PG_TRY();
4117 result = (*assign_hook) (newval, doit, source);
4119 PG_CATCH();
4121 free(newval);
4122 PG_RE_THROW();
4124 PG_END_TRY();
4126 return result;
4131 * Sets option `name' to given value. The value should be a string
4132 * which is going to be parsed and converted to the appropriate data
4133 * type. The context and source parameters indicate in which context this
4134 * function is being called so it can apply the access restrictions
4135 * properly.
4137 * If value is NULL, set the option to its default value (normally the
4138 * reset_val, but if source == PGC_S_DEFAULT we instead use the boot_val).
4140 * action indicates whether to set the value globally in the session, locally
4141 * to the current top transaction, or just for the duration of a function call.
4143 * If changeVal is false then don't really set the option but do all
4144 * the checks to see if it would work.
4146 * If there is an error (non-existing option, invalid value) then an
4147 * ereport(ERROR) is thrown *unless* this is called in a context where we
4148 * don't want to ereport (currently, startup or SIGHUP config file reread).
4149 * In that case we write a suitable error message via ereport(DEBUG) and
4150 * return false. This is working around the deficiencies in the ereport
4151 * mechanism, so don't blame me. In all other cases, the function
4152 * returns true, including cases where the input is valid but we chose
4153 * not to apply it because of context or source-priority considerations.
4155 * See also SetConfigOption for an external interface.
4157 bool
4158 set_config_option(const char *name, const char *value,
4159 GucContext context, GucSource source,
4160 GucAction action, bool changeVal)
4162 struct config_generic *record;
4163 int elevel;
4164 bool makeDefault;
4166 if (context == PGC_SIGHUP || source == PGC_S_DEFAULT)
4169 * To avoid cluttering the log, only the postmaster bleats loudly
4170 * about problems with the config file.
4172 elevel = IsUnderPostmaster ? DEBUG2 : LOG;
4174 else if (source == PGC_S_DATABASE || source == PGC_S_USER)
4175 elevel = INFO;
4176 else
4177 elevel = ERROR;
4179 record = find_option(name, true, elevel);
4180 if (record == NULL)
4182 ereport(elevel,
4183 (errcode(ERRCODE_UNDEFINED_OBJECT),
4184 errmsg("unrecognized configuration parameter \"%s\"", name)));
4185 return false;
4189 * If source is postgresql.conf, mark the found record with GUC_IS_IN_FILE.
4190 * This is for the convenience of ProcessConfigFile. Note that we do it
4191 * even if changeVal is false, since ProcessConfigFile wants the marking
4192 * to occur during its testing pass.
4194 if (source == PGC_S_FILE)
4195 record->status |= GUC_IS_IN_FILE;
4198 * Check if the option can be set at this time. See guc.h for the precise
4199 * rules. Note that we don't want to throw errors if we're in the SIGHUP
4200 * context. In that case we just ignore the attempt and return true.
4202 switch (record->context)
4204 case PGC_INTERNAL:
4205 if (context == PGC_SIGHUP)
4206 return true;
4207 if (context != PGC_INTERNAL)
4209 ereport(elevel,
4210 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4211 errmsg("parameter \"%s\" cannot be changed",
4212 name)));
4213 return false;
4215 break;
4216 case PGC_POSTMASTER:
4217 if (context == PGC_SIGHUP)
4220 * We are reading a PGC_POSTMASTER var from postgresql.conf.
4221 * We can't change the setting, so give a warning if the DBA
4222 * tries to change it. (Throwing an error would be more
4223 * consistent, but seems overly rigid.)
4225 if (changeVal && !is_newvalue_equal(record, value))
4226 ereport(elevel,
4227 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4228 errmsg("parameter \"%s\" cannot be changed after server start; configuration file change ignored",
4229 name)));
4230 return true;
4232 if (context != PGC_POSTMASTER)
4234 ereport(elevel,
4235 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4236 errmsg("parameter \"%s\" cannot be changed after server start",
4237 name)));
4238 return false;
4240 break;
4241 case PGC_SIGHUP:
4242 if (context != PGC_SIGHUP && context != PGC_POSTMASTER)
4244 ereport(elevel,
4245 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4246 errmsg("parameter \"%s\" cannot be changed now",
4247 name)));
4248 return false;
4252 * Hmm, the idea of the SIGHUP context is "ought to be global, but
4253 * can be changed after postmaster start". But there's nothing
4254 * that prevents a crafty administrator from sending SIGHUP
4255 * signals to individual backends only.
4257 break;
4258 case PGC_BACKEND:
4259 if (context == PGC_SIGHUP)
4262 * If a PGC_BACKEND parameter is changed in the config file,
4263 * we want to accept the new value in the postmaster (whence
4264 * it will propagate to subsequently-started backends), but
4265 * ignore it in existing backends. This is a tad klugy, but
4266 * necessary because we don't re-read the config file during
4267 * backend start.
4269 if (IsUnderPostmaster)
4270 return true;
4272 else if (context != PGC_BACKEND && context != PGC_POSTMASTER)
4274 ereport(elevel,
4275 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4276 errmsg("parameter \"%s\" cannot be set after connection start",
4277 name)));
4278 return false;
4280 break;
4281 case PGC_SUSET:
4282 if (context == PGC_USERSET || context == PGC_BACKEND)
4284 ereport(elevel,
4285 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4286 errmsg("permission denied to set parameter \"%s\"",
4287 name)));
4288 return false;
4290 break;
4291 case PGC_USERSET:
4292 /* always okay */
4293 break;
4297 * Should we set reset/stacked values? (If so, the behavior is not
4298 * transactional.) This is done either when we get a default
4299 * value from the database's/user's/client's default settings or
4300 * when we reset a value to its default.
4302 makeDefault = changeVal && (source <= PGC_S_OVERRIDE) &&
4303 ((value != NULL) || source == PGC_S_DEFAULT);
4306 * Ignore attempted set if overridden by previously processed setting.
4307 * However, if changeVal is false then plow ahead anyway since we are
4308 * trying to find out if the value is potentially good, not actually use
4309 * it. Also keep going if makeDefault is true, since we may want to set
4310 * the reset/stacked values even if we can't set the variable itself.
4312 if (record->source > source)
4314 if (changeVal && !makeDefault)
4316 elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
4317 name);
4318 return true;
4320 changeVal = false;
4324 * Evaluate value and set variable.
4326 switch (record->vartype)
4328 case PGC_BOOL:
4330 struct config_bool *conf = (struct config_bool *) record;
4331 bool newval;
4333 if (value)
4335 if (!parse_bool(value, &newval))
4337 ereport(elevel,
4338 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4339 errmsg("parameter \"%s\" requires a Boolean value",
4340 name)));
4341 return false;
4344 else if (source == PGC_S_DEFAULT)
4345 newval = conf->boot_val;
4346 else
4348 newval = conf->reset_val;
4349 source = conf->gen.reset_source;
4352 if (conf->assign_hook)
4353 if (!(*conf->assign_hook) (newval, changeVal, source))
4355 ereport(elevel,
4356 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4357 errmsg("invalid value for parameter \"%s\": %d",
4358 name, (int) newval)));
4359 return false;
4362 if (changeVal || makeDefault)
4364 /* Save old value to support transaction abort */
4365 if (!makeDefault)
4366 push_old_value(&conf->gen, action);
4367 if (changeVal)
4369 *conf->variable = newval;
4370 conf->gen.source = source;
4372 if (makeDefault)
4374 GucStack *stack;
4376 if (conf->gen.reset_source <= source)
4378 conf->reset_val = newval;
4379 conf->gen.reset_source = source;
4381 for (stack = conf->gen.stack; stack; stack = stack->prev)
4383 if (stack->source <= source)
4385 stack->prior.boolval = newval;
4386 stack->source = source;
4391 break;
4394 case PGC_INT:
4396 struct config_int *conf = (struct config_int *) record;
4397 int newval;
4399 if (value)
4401 const char *hintmsg;
4403 if (!parse_int(value, &newval, conf->gen.flags, &hintmsg))
4405 ereport(elevel,
4406 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4407 errmsg("invalid value for parameter \"%s\": \"%s\"",
4408 name, value),
4409 hintmsg ? errhint(hintmsg) : 0));
4410 return false;
4412 if (newval < conf->min || newval > conf->max)
4414 ereport(elevel,
4415 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4416 errmsg("%d is outside the valid range for parameter \"%s\" (%d .. %d)",
4417 newval, name, conf->min, conf->max)));
4418 return false;
4421 else if (source == PGC_S_DEFAULT)
4422 newval = conf->boot_val;
4423 else
4425 newval = conf->reset_val;
4426 source = conf->gen.reset_source;
4429 if (conf->assign_hook)
4430 if (!(*conf->assign_hook) (newval, changeVal, source))
4432 ereport(elevel,
4433 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4434 errmsg("invalid value for parameter \"%s\": %d",
4435 name, newval)));
4436 return false;
4439 if (changeVal || makeDefault)
4441 /* Save old value to support transaction abort */
4442 if (!makeDefault)
4443 push_old_value(&conf->gen, action);
4444 if (changeVal)
4446 *conf->variable = newval;
4447 conf->gen.source = source;
4449 if (makeDefault)
4451 GucStack *stack;
4453 if (conf->gen.reset_source <= source)
4455 conf->reset_val = newval;
4456 conf->gen.reset_source = source;
4458 for (stack = conf->gen.stack; stack; stack = stack->prev)
4460 if (stack->source <= source)
4462 stack->prior.intval = newval;
4463 stack->source = source;
4468 break;
4471 case PGC_REAL:
4473 struct config_real *conf = (struct config_real *) record;
4474 double newval;
4476 if (value)
4478 if (!parse_real(value, &newval))
4480 ereport(elevel,
4481 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4482 errmsg("parameter \"%s\" requires a numeric value",
4483 name)));
4484 return false;
4486 if (newval < conf->min || newval > conf->max)
4488 ereport(elevel,
4489 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4490 errmsg("%g is outside the valid range for parameter \"%s\" (%g .. %g)",
4491 newval, name, conf->min, conf->max)));
4492 return false;
4495 else if (source == PGC_S_DEFAULT)
4496 newval = conf->boot_val;
4497 else
4499 newval = conf->reset_val;
4500 source = conf->gen.reset_source;
4503 if (conf->assign_hook)
4504 if (!(*conf->assign_hook) (newval, changeVal, source))
4506 ereport(elevel,
4507 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4508 errmsg("invalid value for parameter \"%s\": %g",
4509 name, newval)));
4510 return false;
4513 if (changeVal || makeDefault)
4515 /* Save old value to support transaction abort */
4516 if (!makeDefault)
4517 push_old_value(&conf->gen, action);
4518 if (changeVal)
4520 *conf->variable = newval;
4521 conf->gen.source = source;
4523 if (makeDefault)
4525 GucStack *stack;
4527 if (conf->gen.reset_source <= source)
4529 conf->reset_val = newval;
4530 conf->gen.reset_source = source;
4532 for (stack = conf->gen.stack; stack; stack = stack->prev)
4534 if (stack->source <= source)
4536 stack->prior.realval = newval;
4537 stack->source = source;
4542 break;
4545 case PGC_STRING:
4547 struct config_string *conf = (struct config_string *) record;
4548 char *newval;
4550 if (value)
4552 newval = guc_strdup(elevel, value);
4553 if (newval == NULL)
4554 return false;
4557 * The only sort of "parsing" check we need to do is apply
4558 * truncation if GUC_IS_NAME.
4560 if (conf->gen.flags & GUC_IS_NAME)
4561 truncate_identifier(newval, strlen(newval), true);
4563 else if (source == PGC_S_DEFAULT)
4565 if (conf->boot_val == NULL)
4566 newval = NULL;
4567 else
4569 newval = guc_strdup(elevel, conf->boot_val);
4570 if (newval == NULL)
4571 return false;
4574 else
4577 * We could possibly avoid strdup here, but easier to make
4578 * this case work the same as the normal assignment case;
4579 * note the possible free of newval below.
4581 if (conf->reset_val == NULL)
4582 newval = NULL;
4583 else
4585 newval = guc_strdup(elevel, conf->reset_val);
4586 if (newval == NULL)
4587 return false;
4589 source = conf->gen.reset_source;
4592 if (conf->assign_hook && newval)
4594 const char *hookresult;
4597 * If the hook ereports, we have to make sure we free
4598 * newval, else it will be a permanent memory leak.
4600 hookresult = call_string_assign_hook(conf->assign_hook,
4601 newval,
4602 changeVal,
4603 source);
4604 if (hookresult == NULL)
4606 free(newval);
4607 ereport(elevel,
4608 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4609 errmsg("invalid value for parameter \"%s\": \"%s\"",
4610 name, value ? value : "")));
4611 return false;
4613 else if (hookresult != newval)
4615 free(newval);
4618 * Having to cast away const here is annoying, but the
4619 * alternative is to declare assign_hooks as returning
4620 * char*, which would mean they'd have to cast away
4621 * const, or as both taking and returning char*, which
4622 * doesn't seem attractive either --- we don't want
4623 * them to scribble on the passed str.
4625 newval = (char *) hookresult;
4629 if (changeVal || makeDefault)
4631 /* Save old value to support transaction abort */
4632 if (!makeDefault)
4633 push_old_value(&conf->gen, action);
4634 if (changeVal)
4636 set_string_field(conf, conf->variable, newval);
4637 conf->gen.source = source;
4639 if (makeDefault)
4641 GucStack *stack;
4643 if (conf->gen.reset_source <= source)
4645 set_string_field(conf, &conf->reset_val, newval);
4646 conf->gen.reset_source = source;
4648 for (stack = conf->gen.stack; stack; stack = stack->prev)
4650 if (stack->source <= source)
4652 set_string_field(conf, &stack->prior.stringval,
4653 newval);
4654 stack->source = source;
4657 /* Perhaps we didn't install newval anywhere */
4658 if (newval && !string_field_used(conf, newval))
4659 free(newval);
4662 else if (newval)
4663 free(newval);
4664 break;
4668 if (changeVal && (record->flags & GUC_REPORT))
4669 ReportGUCOption(record);
4671 return true;
4676 * Set a config option to the given value. See also set_config_option,
4677 * this is just the wrapper to be called from outside GUC. NB: this
4678 * is used only for non-transactional operations.
4680 void
4681 SetConfigOption(const char *name, const char *value,
4682 GucContext context, GucSource source)
4684 (void) set_config_option(name, value, context, source,
4685 GUC_ACTION_SET, true);
4691 * Fetch the current value of the option `name'. If the option doesn't exist,
4692 * throw an ereport and don't return.
4694 * The string is *not* allocated for modification and is really only
4695 * valid until the next call to configuration related functions.
4697 const char *
4698 GetConfigOption(const char *name)
4700 struct config_generic *record;
4701 static char buffer[256];
4703 record = find_option(name, false, ERROR);
4704 if (record == NULL)
4705 ereport(ERROR,
4706 (errcode(ERRCODE_UNDEFINED_OBJECT),
4707 errmsg("unrecognized configuration parameter \"%s\"", name)));
4708 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
4709 ereport(ERROR,
4710 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4711 errmsg("must be superuser to examine \"%s\"", name)));
4713 switch (record->vartype)
4715 case PGC_BOOL:
4716 return *((struct config_bool *) record)->variable ? "on" : "off";
4718 case PGC_INT:
4719 snprintf(buffer, sizeof(buffer), "%d",
4720 *((struct config_int *) record)->variable);
4721 return buffer;
4723 case PGC_REAL:
4724 snprintf(buffer, sizeof(buffer), "%g",
4725 *((struct config_real *) record)->variable);
4726 return buffer;
4728 case PGC_STRING:
4729 return *((struct config_string *) record)->variable;
4731 return NULL;
4735 * Get the RESET value associated with the given option.
4737 * Note: this is not re-entrant, due to use of static result buffer;
4738 * not to mention that a string variable could have its reset_val changed.
4739 * Beware of assuming the result value is good for very long.
4741 const char *
4742 GetConfigOptionResetString(const char *name)
4744 struct config_generic *record;
4745 static char buffer[256];
4747 record = find_option(name, false, ERROR);
4748 if (record == NULL)
4749 ereport(ERROR,
4750 (errcode(ERRCODE_UNDEFINED_OBJECT),
4751 errmsg("unrecognized configuration parameter \"%s\"", name)));
4752 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
4753 ereport(ERROR,
4754 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4755 errmsg("must be superuser to examine \"%s\"", name)));
4757 switch (record->vartype)
4759 case PGC_BOOL:
4760 return ((struct config_bool *) record)->reset_val ? "on" : "off";
4762 case PGC_INT:
4763 snprintf(buffer, sizeof(buffer), "%d",
4764 ((struct config_int *) record)->reset_val);
4765 return buffer;
4767 case PGC_REAL:
4768 snprintf(buffer, sizeof(buffer), "%g",
4769 ((struct config_real *) record)->reset_val);
4770 return buffer;
4772 case PGC_STRING:
4773 return ((struct config_string *) record)->reset_val;
4775 return NULL;
4779 * Detect whether the given configuration option can only be set by
4780 * a superuser.
4782 bool
4783 IsSuperuserConfigOption(const char *name)
4785 struct config_generic *record;
4787 record = find_option(name, false, ERROR);
4788 /* On an unrecognized name, don't error, just return false. */
4789 if (record == NULL)
4790 return false;
4791 return (record->context == PGC_SUSET);
4796 * flatten_set_variable_args
4797 * Given a parsenode List as emitted by the grammar for SET,
4798 * convert to the flat string representation used by GUC.
4800 * We need to be told the name of the variable the args are for, because
4801 * the flattening rules vary (ugh).
4803 * The result is NULL if args is NIL (ie, SET ... TO DEFAULT), otherwise
4804 * a palloc'd string.
4806 static char *
4807 flatten_set_variable_args(const char *name, List *args)
4809 struct config_generic *record;
4810 int flags;
4811 StringInfoData buf;
4812 ListCell *l;
4814 /* Fast path if just DEFAULT */
4815 if (args == NIL)
4816 return NULL;
4818 /* Else get flags for the variable */
4819 record = find_option(name, true, ERROR);
4820 if (record == NULL)
4821 ereport(ERROR,
4822 (errcode(ERRCODE_UNDEFINED_OBJECT),
4823 errmsg("unrecognized configuration parameter \"%s\"", name)));
4825 flags = record->flags;
4827 /* Complain if list input and non-list variable */
4828 if ((flags & GUC_LIST_INPUT) == 0 &&
4829 list_length(args) != 1)
4830 ereport(ERROR,
4831 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4832 errmsg("SET %s takes only one argument", name)));
4834 initStringInfo(&buf);
4836 foreach(l, args)
4838 A_Const *arg = (A_Const *) lfirst(l);
4839 char *val;
4841 if (l != list_head(args))
4842 appendStringInfo(&buf, ", ");
4844 if (!IsA(arg, A_Const))
4845 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
4847 switch (nodeTag(&arg->val))
4849 case T_Integer:
4850 appendStringInfo(&buf, "%ld", intVal(&arg->val));
4851 break;
4852 case T_Float:
4853 /* represented as a string, so just copy it */
4854 appendStringInfoString(&buf, strVal(&arg->val));
4855 break;
4856 case T_String:
4857 val = strVal(&arg->val);
4858 if (arg->typename != NULL)
4861 * Must be a ConstInterval argument for TIME ZONE. Coerce
4862 * to interval and back to normalize the value and account
4863 * for any typmod.
4865 int32 typmod;
4866 Datum interval;
4867 char *intervalout;
4869 typmod = typenameTypeMod(NULL, arg->typename, INTERVALOID);
4871 interval =
4872 DirectFunctionCall3(interval_in,
4873 CStringGetDatum(val),
4874 ObjectIdGetDatum(InvalidOid),
4875 Int32GetDatum(typmod));
4877 intervalout =
4878 DatumGetCString(DirectFunctionCall1(interval_out,
4879 interval));
4880 appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
4882 else
4885 * Plain string literal or identifier. For quote mode,
4886 * quote it if it's not a vanilla identifier.
4888 if (flags & GUC_LIST_QUOTE)
4889 appendStringInfoString(&buf, quote_identifier(val));
4890 else
4891 appendStringInfoString(&buf, val);
4893 break;
4894 default:
4895 elog(ERROR, "unrecognized node type: %d",
4896 (int) nodeTag(&arg->val));
4897 break;
4901 return buf.data;
4906 * SET command
4908 void
4909 ExecSetVariableStmt(VariableSetStmt *stmt)
4911 GucAction action = stmt->is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET;
4913 switch (stmt->kind)
4915 case VAR_SET_VALUE:
4916 case VAR_SET_CURRENT:
4917 set_config_option(stmt->name,
4918 ExtractSetVariableArgs(stmt),
4919 (superuser() ? PGC_SUSET : PGC_USERSET),
4920 PGC_S_SESSION,
4921 action,
4922 true);
4923 break;
4924 case VAR_SET_MULTI:
4926 * Special case for special SQL syntax that effectively sets
4927 * more than one variable per statement.
4929 if (strcmp(stmt->name, "TRANSACTION") == 0)
4931 ListCell *head;
4933 foreach(head, stmt->args)
4935 DefElem *item = (DefElem *) lfirst(head);
4937 if (strcmp(item->defname, "transaction_isolation") == 0)
4938 SetPGVariable("transaction_isolation",
4939 list_make1(item->arg), stmt->is_local);
4940 else if (strcmp(item->defname, "transaction_read_only") == 0)
4941 SetPGVariable("transaction_read_only",
4942 list_make1(item->arg), stmt->is_local);
4943 else
4944 elog(ERROR, "unexpected SET TRANSACTION element: %s",
4945 item->defname);
4948 else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
4950 ListCell *head;
4952 foreach(head, stmt->args)
4954 DefElem *item = (DefElem *) lfirst(head);
4956 if (strcmp(item->defname, "transaction_isolation") == 0)
4957 SetPGVariable("default_transaction_isolation",
4958 list_make1(item->arg), stmt->is_local);
4959 else if (strcmp(item->defname, "transaction_read_only") == 0)
4960 SetPGVariable("default_transaction_read_only",
4961 list_make1(item->arg), stmt->is_local);
4962 else
4963 elog(ERROR, "unexpected SET SESSION element: %s",
4964 item->defname);
4967 else
4968 elog(ERROR, "unexpected SET MULTI element: %s",
4969 stmt->name);
4970 break;
4971 case VAR_SET_DEFAULT:
4972 case VAR_RESET:
4973 set_config_option(stmt->name,
4974 NULL,
4975 (superuser() ? PGC_SUSET : PGC_USERSET),
4976 PGC_S_SESSION,
4977 action,
4978 true);
4979 break;
4980 case VAR_RESET_ALL:
4981 ResetAllOptions();
4982 break;
4987 * Get the value to assign for a VariableSetStmt, or NULL if it's RESET.
4988 * The result is palloc'd.
4990 * This is exported for use by actions such as ALTER ROLE SET.
4992 char *
4993 ExtractSetVariableArgs(VariableSetStmt *stmt)
4995 switch (stmt->kind)
4997 case VAR_SET_VALUE:
4998 return flatten_set_variable_args(stmt->name, stmt->args);
4999 case VAR_SET_CURRENT:
5000 return GetConfigOptionByName(stmt->name, NULL);
5001 default:
5002 return NULL;
5007 * SetPGVariable - SET command exported as an easily-C-callable function.
5009 * This provides access to SET TO value, as well as SET TO DEFAULT (expressed
5010 * by passing args == NIL), but not SET FROM CURRENT functionality.
5012 void
5013 SetPGVariable(const char *name, List *args, bool is_local)
5015 char *argstring = flatten_set_variable_args(name, args);
5017 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
5018 set_config_option(name,
5019 argstring,
5020 (superuser() ? PGC_SUSET : PGC_USERSET),
5021 PGC_S_SESSION,
5022 is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET,
5023 true);
5027 * SET command wrapped as a SQL callable function.
5029 Datum
5030 set_config_by_name(PG_FUNCTION_ARGS)
5032 char *name;
5033 char *value;
5034 char *new_value;
5035 bool is_local;
5036 text *result_text;
5038 if (PG_ARGISNULL(0))
5039 ereport(ERROR,
5040 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
5041 errmsg("SET requires parameter name")));
5043 /* Get the GUC variable name */
5044 name = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(0)));
5046 /* Get the desired value or set to NULL for a reset request */
5047 if (PG_ARGISNULL(1))
5048 value = NULL;
5049 else
5050 value = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(1)));
5053 * Get the desired state of is_local. Default to false if provided value
5054 * is NULL
5056 if (PG_ARGISNULL(2))
5057 is_local = false;
5058 else
5059 is_local = PG_GETARG_BOOL(2);
5061 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
5062 set_config_option(name,
5063 value,
5064 (superuser() ? PGC_SUSET : PGC_USERSET),
5065 PGC_S_SESSION,
5066 is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET,
5067 true);
5069 /* get the new current value */
5070 new_value = GetConfigOptionByName(name, NULL);
5072 /* Convert return string to text */
5073 result_text = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(new_value)));
5075 /* return it */
5076 PG_RETURN_TEXT_P(result_text);
5081 * Common code for DefineCustomXXXVariable subroutines: allocate the
5082 * new variable's config struct and fill in generic fields.
5084 static struct config_generic *
5085 init_custom_variable(const char *name,
5086 const char *short_desc,
5087 const char *long_desc,
5088 GucContext context,
5089 enum config_type type,
5090 size_t sz)
5092 struct config_generic *gen;
5094 gen = (struct config_generic *) guc_malloc(ERROR, sz);
5095 memset(gen, 0, sz);
5097 gen->name = guc_strdup(ERROR, name);
5098 gen->context = context;
5099 gen->group = CUSTOM_OPTIONS;
5100 gen->short_desc = short_desc;
5101 gen->long_desc = long_desc;
5102 gen->vartype = type;
5104 return gen;
5108 * Common code for DefineCustomXXXVariable subroutines: insert the new
5109 * variable into the GUC variable array, replacing any placeholder.
5111 static void
5112 define_custom_variable(struct config_generic *variable)
5114 const char *name = variable->name;
5115 const char **nameAddr = &name;
5116 const char *value;
5117 struct config_string *pHolder;
5118 struct config_generic **res;
5120 res = (struct config_generic **) bsearch((void *) &nameAddr,
5121 (void *) guc_variables,
5122 num_guc_variables,
5123 sizeof(struct config_generic *),
5124 guc_var_compare);
5125 if (res == NULL)
5127 /* No placeholder to replace, so just add it */
5128 add_guc_variable(variable, ERROR);
5129 return;
5133 * This better be a placeholder
5135 if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
5136 ereport(ERROR,
5137 (errcode(ERRCODE_INTERNAL_ERROR),
5138 errmsg("attempt to redefine parameter \"%s\"", name)));
5140 Assert((*res)->vartype == PGC_STRING);
5141 pHolder = (struct config_string *) (*res);
5144 * Replace the placeholder.
5145 * We aren't changing the name, so no re-sorting is necessary
5147 *res = variable;
5150 * Assign the string value stored in the placeholder to the real variable.
5152 * XXX this is not really good enough --- it should be a nontransactional
5153 * assignment, since we don't want it to roll back if the current xact
5154 * fails later.
5156 value = *pHolder->variable;
5158 if (value)
5159 set_config_option(name, value,
5160 pHolder->gen.context, pHolder->gen.source,
5161 GUC_ACTION_SET, true);
5164 * Free up as much as we conveniently can of the placeholder structure
5165 * (this neglects any stack items...)
5167 set_string_field(pHolder, pHolder->variable, NULL);
5168 set_string_field(pHolder, &pHolder->reset_val, NULL);
5170 free(pHolder);
5173 void
5174 DefineCustomBoolVariable(const char *name,
5175 const char *short_desc,
5176 const char *long_desc,
5177 bool *valueAddr,
5178 GucContext context,
5179 GucBoolAssignHook assign_hook,
5180 GucShowHook show_hook)
5182 struct config_bool *var;
5184 var = (struct config_bool *)
5185 init_custom_variable(name, short_desc, long_desc, context,
5186 PGC_BOOL, sizeof(struct config_bool));
5187 var->variable = valueAddr;
5188 var->boot_val = *valueAddr;
5189 var->reset_val = *valueAddr;
5190 var->assign_hook = assign_hook;
5191 var->show_hook = show_hook;
5192 define_custom_variable(&var->gen);
5195 void
5196 DefineCustomIntVariable(const char *name,
5197 const char *short_desc,
5198 const char *long_desc,
5199 int *valueAddr,
5200 int minValue,
5201 int maxValue,
5202 GucContext context,
5203 GucIntAssignHook assign_hook,
5204 GucShowHook show_hook)
5206 struct config_int *var;
5208 var = (struct config_int *)
5209 init_custom_variable(name, short_desc, long_desc, context,
5210 PGC_INT, sizeof(struct config_int));
5211 var->variable = valueAddr;
5212 var->boot_val = *valueAddr;
5213 var->reset_val = *valueAddr;
5214 var->min = minValue;
5215 var->max = maxValue;
5216 var->assign_hook = assign_hook;
5217 var->show_hook = show_hook;
5218 define_custom_variable(&var->gen);
5221 void
5222 DefineCustomRealVariable(const char *name,
5223 const char *short_desc,
5224 const char *long_desc,
5225 double *valueAddr,
5226 double minValue,
5227 double maxValue,
5228 GucContext context,
5229 GucRealAssignHook assign_hook,
5230 GucShowHook show_hook)
5232 struct config_real *var;
5234 var = (struct config_real *)
5235 init_custom_variable(name, short_desc, long_desc, context,
5236 PGC_REAL, sizeof(struct config_real));
5237 var->variable = valueAddr;
5238 var->boot_val = *valueAddr;
5239 var->reset_val = *valueAddr;
5240 var->min = minValue;
5241 var->max = maxValue;
5242 var->assign_hook = assign_hook;
5243 var->show_hook = show_hook;
5244 define_custom_variable(&var->gen);
5247 void
5248 DefineCustomStringVariable(const char *name,
5249 const char *short_desc,
5250 const char *long_desc,
5251 char **valueAddr,
5252 GucContext context,
5253 GucStringAssignHook assign_hook,
5254 GucShowHook show_hook)
5256 struct config_string *var;
5258 var = (struct config_string *)
5259 init_custom_variable(name, short_desc, long_desc, context,
5260 PGC_STRING, sizeof(struct config_string));
5261 var->variable = valueAddr;
5262 var->boot_val = *valueAddr;
5263 /* we could probably do without strdup, but keep it like normal case */
5264 if (var->boot_val)
5265 var->reset_val = guc_strdup(ERROR, var->boot_val);
5266 var->assign_hook = assign_hook;
5267 var->show_hook = show_hook;
5268 define_custom_variable(&var->gen);
5271 void
5272 EmitWarningsOnPlaceholders(const char *className)
5274 struct config_generic **vars = guc_variables;
5275 struct config_generic **last = vars + num_guc_variables;
5277 int nameLen = strlen(className);
5279 while (vars < last)
5281 struct config_generic *var = *vars++;
5283 if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
5284 strncmp(className, var->name, nameLen) == 0 &&
5285 var->name[nameLen] == GUC_QUALIFIER_SEPARATOR)
5287 ereport(INFO,
5288 (errcode(ERRCODE_UNDEFINED_OBJECT),
5289 errmsg("unrecognized configuration parameter \"%s\"", var->name)));
5296 * SHOW command
5298 void
5299 GetPGVariable(const char *name, DestReceiver *dest)
5301 if (guc_name_compare(name, "all") == 0)
5302 ShowAllGUCConfig(dest);
5303 else
5304 ShowGUCConfigOption(name, dest);
5307 TupleDesc
5308 GetPGVariableResultDesc(const char *name)
5310 TupleDesc tupdesc;
5312 if (guc_name_compare(name, "all") == 0)
5314 /* need a tuple descriptor representing three TEXT columns */
5315 tupdesc = CreateTemplateTupleDesc(3, false);
5316 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
5317 TEXTOID, -1, 0);
5318 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
5319 TEXTOID, -1, 0);
5320 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
5321 TEXTOID, -1, 0);
5324 else
5326 const char *varname;
5328 /* Get the canonical spelling of name */
5329 (void) GetConfigOptionByName(name, &varname);
5331 /* need a tuple descriptor representing a single TEXT column */
5332 tupdesc = CreateTemplateTupleDesc(1, false);
5333 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
5334 TEXTOID, -1, 0);
5336 return tupdesc;
5341 * SHOW command
5343 static void
5344 ShowGUCConfigOption(const char *name, DestReceiver *dest)
5346 TupOutputState *tstate;
5347 TupleDesc tupdesc;
5348 const char *varname;
5349 char *value;
5351 /* Get the value and canonical spelling of name */
5352 value = GetConfigOptionByName(name, &varname);
5354 /* need a tuple descriptor representing a single TEXT column */
5355 tupdesc = CreateTemplateTupleDesc(1, false);
5356 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
5357 TEXTOID, -1, 0);
5359 /* prepare for projection of tuples */
5360 tstate = begin_tup_output_tupdesc(dest, tupdesc);
5362 /* Send it */
5363 do_text_output_oneline(tstate, value);
5365 end_tup_output(tstate);
5369 * SHOW ALL command
5371 static void
5372 ShowAllGUCConfig(DestReceiver *dest)
5374 bool am_superuser = superuser();
5375 int i;
5376 TupOutputState *tstate;
5377 TupleDesc tupdesc;
5378 char *values[3];
5380 /* need a tuple descriptor representing three TEXT columns */
5381 tupdesc = CreateTemplateTupleDesc(3, false);
5382 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
5383 TEXTOID, -1, 0);
5384 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
5385 TEXTOID, -1, 0);
5386 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
5387 TEXTOID, -1, 0);
5390 /* prepare for projection of tuples */
5391 tstate = begin_tup_output_tupdesc(dest, tupdesc);
5393 for (i = 0; i < num_guc_variables; i++)
5395 struct config_generic *conf = guc_variables[i];
5397 if ((conf->flags & GUC_NO_SHOW_ALL) ||
5398 ((conf->flags & GUC_SUPERUSER_ONLY) && !am_superuser))
5399 continue;
5401 /* assign to the values array */
5402 values[0] = (char *) conf->name;
5403 values[1] = _ShowOption(conf, true);
5404 values[2] = (char *) conf->short_desc;
5406 /* send it to dest */
5407 do_tup_output(tstate, values);
5409 /* clean up */
5410 if (values[1] != NULL)
5411 pfree(values[1]);
5414 end_tup_output(tstate);
5418 * Return GUC variable value by name; optionally return canonical
5419 * form of name. Return value is palloc'd.
5421 char *
5422 GetConfigOptionByName(const char *name, const char **varname)
5424 struct config_generic *record;
5426 record = find_option(name, false, ERROR);
5427 if (record == NULL)
5428 ereport(ERROR,
5429 (errcode(ERRCODE_UNDEFINED_OBJECT),
5430 errmsg("unrecognized configuration parameter \"%s\"", name)));
5431 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
5432 ereport(ERROR,
5433 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5434 errmsg("must be superuser to examine \"%s\"", name)));
5436 if (varname)
5437 *varname = record->name;
5439 return _ShowOption(record, true);
5443 * Return GUC variable value by variable number; optionally return canonical
5444 * form of name. Return value is palloc'd.
5446 void
5447 GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
5449 char buffer[256];
5450 struct config_generic *conf;
5452 /* check requested variable number valid */
5453 Assert((varnum >= 0) && (varnum < num_guc_variables));
5455 conf = guc_variables[varnum];
5457 if (noshow)
5459 if ((conf->flags & GUC_NO_SHOW_ALL) ||
5460 ((conf->flags & GUC_SUPERUSER_ONLY) && !superuser()))
5461 *noshow = true;
5462 else
5463 *noshow = false;
5466 /* first get the generic attributes */
5468 /* name */
5469 values[0] = conf->name;
5471 /* setting : use _ShowOption in order to avoid duplicating the logic */
5472 values[1] = _ShowOption(conf, false);
5474 /* unit */
5475 if (conf->vartype == PGC_INT)
5477 static char buf[8];
5479 switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
5481 case GUC_UNIT_KB:
5482 values[2] = "kB";
5483 break;
5484 case GUC_UNIT_BLOCKS:
5485 snprintf(buf, sizeof(buf), "%dkB", BLCKSZ / 1024);
5486 values[2] = buf;
5487 break;
5488 case GUC_UNIT_XBLOCKS:
5489 snprintf(buf, sizeof(buf), "%dkB", XLOG_BLCKSZ / 1024);
5490 values[2] = buf;
5491 break;
5492 case GUC_UNIT_MS:
5493 values[2] = "ms";
5494 break;
5495 case GUC_UNIT_S:
5496 values[2] = "s";
5497 break;
5498 case GUC_UNIT_MIN:
5499 values[2] = "min";
5500 break;
5501 default:
5502 values[2] = "";
5503 break;
5506 else
5507 values[2] = NULL;
5509 /* group */
5510 values[3] = config_group_names[conf->group];
5512 /* short_desc */
5513 values[4] = conf->short_desc;
5515 /* extra_desc */
5516 values[5] = conf->long_desc;
5518 /* context */
5519 values[6] = GucContext_Names[conf->context];
5521 /* vartype */
5522 values[7] = config_type_names[conf->vartype];
5524 /* source */
5525 values[8] = GucSource_Names[conf->source];
5527 /* now get the type specifc attributes */
5528 switch (conf->vartype)
5530 case PGC_BOOL:
5532 /* min_val */
5533 values[9] = NULL;
5535 /* max_val */
5536 values[10] = NULL;
5538 break;
5540 case PGC_INT:
5542 struct config_int *lconf = (struct config_int *) conf;
5544 /* min_val */
5545 snprintf(buffer, sizeof(buffer), "%d", lconf->min);
5546 values[9] = pstrdup(buffer);
5548 /* max_val */
5549 snprintf(buffer, sizeof(buffer), "%d", lconf->max);
5550 values[10] = pstrdup(buffer);
5552 break;
5554 case PGC_REAL:
5556 struct config_real *lconf = (struct config_real *) conf;
5558 /* min_val */
5559 snprintf(buffer, sizeof(buffer), "%g", lconf->min);
5560 values[9] = pstrdup(buffer);
5562 /* max_val */
5563 snprintf(buffer, sizeof(buffer), "%g", lconf->max);
5564 values[10] = pstrdup(buffer);
5566 break;
5568 case PGC_STRING:
5570 /* min_val */
5571 values[9] = NULL;
5573 /* max_val */
5574 values[10] = NULL;
5576 break;
5578 default:
5581 * should never get here, but in case we do, set 'em to NULL
5584 /* min_val */
5585 values[9] = NULL;
5587 /* max_val */
5588 values[10] = NULL;
5590 break;
5595 * Return the total number of GUC variables
5598 GetNumConfigOptions(void)
5600 return num_guc_variables;
5604 * show_config_by_name - equiv to SHOW X command but implemented as
5605 * a function.
5607 Datum
5608 show_config_by_name(PG_FUNCTION_ARGS)
5610 char *varname;
5611 char *varval;
5612 text *result_text;
5614 /* Get the GUC variable name */
5615 varname = DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(0)));
5617 /* Get the value */
5618 varval = GetConfigOptionByName(varname, NULL);
5620 /* Convert to text */
5621 result_text = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(varval)));
5623 /* return it */
5624 PG_RETURN_TEXT_P(result_text);
5628 * show_all_settings - equiv to SHOW ALL command but implemented as
5629 * a Table Function.
5631 #define NUM_PG_SETTINGS_ATTS 11
5633 Datum
5634 show_all_settings(PG_FUNCTION_ARGS)
5636 FuncCallContext *funcctx;
5637 TupleDesc tupdesc;
5638 int call_cntr;
5639 int max_calls;
5640 AttInMetadata *attinmeta;
5641 MemoryContext oldcontext;
5643 /* stuff done only on the first call of the function */
5644 if (SRF_IS_FIRSTCALL())
5646 /* create a function context for cross-call persistence */
5647 funcctx = SRF_FIRSTCALL_INIT();
5650 * switch to memory context appropriate for multiple function calls
5652 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
5655 * need a tuple descriptor representing NUM_PG_SETTINGS_ATTS columns
5656 * of the appropriate types
5658 tupdesc = CreateTemplateTupleDesc(NUM_PG_SETTINGS_ATTS, false);
5659 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
5660 TEXTOID, -1, 0);
5661 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
5662 TEXTOID, -1, 0);
5663 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "unit",
5664 TEXTOID, -1, 0);
5665 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "category",
5666 TEXTOID, -1, 0);
5667 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "short_desc",
5668 TEXTOID, -1, 0);
5669 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "extra_desc",
5670 TEXTOID, -1, 0);
5671 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "context",
5672 TEXTOID, -1, 0);
5673 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "vartype",
5674 TEXTOID, -1, 0);
5675 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "source",
5676 TEXTOID, -1, 0);
5677 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "min_val",
5678 TEXTOID, -1, 0);
5679 TupleDescInitEntry(tupdesc, (AttrNumber) 11, "max_val",
5680 TEXTOID, -1, 0);
5683 * Generate attribute metadata needed later to produce tuples from raw
5684 * C strings
5686 attinmeta = TupleDescGetAttInMetadata(tupdesc);
5687 funcctx->attinmeta = attinmeta;
5689 /* total number of tuples to be returned */
5690 funcctx->max_calls = GetNumConfigOptions();
5692 MemoryContextSwitchTo(oldcontext);
5695 /* stuff done on every call of the function */
5696 funcctx = SRF_PERCALL_SETUP();
5698 call_cntr = funcctx->call_cntr;
5699 max_calls = funcctx->max_calls;
5700 attinmeta = funcctx->attinmeta;
5702 if (call_cntr < max_calls) /* do when there is more left to send */
5704 char *values[NUM_PG_SETTINGS_ATTS];
5705 bool noshow;
5706 HeapTuple tuple;
5707 Datum result;
5710 * Get the next visible GUC variable name and value
5714 GetConfigOptionByNum(call_cntr, (const char **) values, &noshow);
5715 if (noshow)
5717 /* bump the counter and get the next config setting */
5718 call_cntr = ++funcctx->call_cntr;
5720 /* make sure we haven't gone too far now */
5721 if (call_cntr >= max_calls)
5722 SRF_RETURN_DONE(funcctx);
5724 } while (noshow);
5726 /* build a tuple */
5727 tuple = BuildTupleFromCStrings(attinmeta, values);
5729 /* make the tuple into a datum */
5730 result = HeapTupleGetDatum(tuple);
5732 SRF_RETURN_NEXT(funcctx, result);
5734 else
5736 /* do when there is no more left */
5737 SRF_RETURN_DONE(funcctx);
5741 static char *
5742 _ShowOption(struct config_generic * record, bool use_units)
5744 char buffer[256];
5745 const char *val;
5747 switch (record->vartype)
5749 case PGC_BOOL:
5751 struct config_bool *conf = (struct config_bool *) record;
5753 if (conf->show_hook)
5754 val = (*conf->show_hook) ();
5755 else
5756 val = *conf->variable ? "on" : "off";
5758 break;
5760 case PGC_INT:
5762 struct config_int *conf = (struct config_int *) record;
5764 if (conf->show_hook)
5765 val = (*conf->show_hook) ();
5766 else
5768 char unit[4];
5769 int result = *conf->variable;
5771 if (use_units && result > 0 && (record->flags & GUC_UNIT_MEMORY))
5773 switch (record->flags & GUC_UNIT_MEMORY)
5775 case GUC_UNIT_BLOCKS:
5776 result *= BLCKSZ / 1024;
5777 break;
5778 case GUC_UNIT_XBLOCKS:
5779 result *= XLOG_BLCKSZ / 1024;
5780 break;
5783 if (result % KB_PER_GB == 0)
5785 result /= KB_PER_GB;
5786 strcpy(unit, "GB");
5788 else if (result % KB_PER_MB == 0)
5790 result /= KB_PER_MB;
5791 strcpy(unit, "MB");
5793 else
5795 strcpy(unit, "kB");
5798 else if (use_units && result > 0 && (record->flags & GUC_UNIT_TIME))
5800 switch (record->flags & GUC_UNIT_TIME)
5802 case GUC_UNIT_S:
5803 result *= MS_PER_S;
5804 break;
5805 case GUC_UNIT_MIN:
5806 result *= MS_PER_MIN;
5807 break;
5810 if (result % MS_PER_D == 0)
5812 result /= MS_PER_D;
5813 strcpy(unit, "d");
5815 else if (result % MS_PER_H == 0)
5817 result /= MS_PER_H;
5818 strcpy(unit, "h");
5820 else if (result % MS_PER_MIN == 0)
5822 result /= MS_PER_MIN;
5823 strcpy(unit, "min");
5825 else if (result % MS_PER_S == 0)
5827 result /= MS_PER_S;
5828 strcpy(unit, "s");
5830 else
5832 strcpy(unit, "ms");
5835 else
5836 strcpy(unit, "");
5838 snprintf(buffer, sizeof(buffer), "%d%s",
5839 (int) result, unit);
5840 val = buffer;
5843 break;
5845 case PGC_REAL:
5847 struct config_real *conf = (struct config_real *) record;
5849 if (conf->show_hook)
5850 val = (*conf->show_hook) ();
5851 else
5853 snprintf(buffer, sizeof(buffer), "%g",
5854 *conf->variable);
5855 val = buffer;
5858 break;
5860 case PGC_STRING:
5862 struct config_string *conf = (struct config_string *) record;
5864 if (conf->show_hook)
5865 val = (*conf->show_hook) ();
5866 else if (*conf->variable && **conf->variable)
5867 val = *conf->variable;
5868 else
5869 val = "";
5871 break;
5873 default:
5874 /* just to keep compiler quiet */
5875 val = "???";
5876 break;
5879 return pstrdup(val);
5884 * Attempt (badly) to detect if a proposed new GUC setting is the same
5885 * as the current value.
5887 * XXX this does not really work because it doesn't account for the
5888 * effects of canonicalization of string values by assign_hooks.
5890 static bool
5891 is_newvalue_equal(struct config_generic *record, const char *newvalue)
5893 /* newvalue == NULL isn't supported */
5894 Assert(newvalue != NULL);
5896 switch (record->vartype)
5898 case PGC_BOOL:
5900 struct config_bool *conf = (struct config_bool *) record;
5901 bool newval;
5903 return parse_bool(newvalue, &newval)
5904 && *conf->variable == newval;
5906 case PGC_INT:
5908 struct config_int *conf = (struct config_int *) record;
5909 int newval;
5911 return parse_int(newvalue, &newval, record->flags, NULL)
5912 && *conf->variable == newval;
5914 case PGC_REAL:
5916 struct config_real *conf = (struct config_real *) record;
5917 double newval;
5919 return parse_real(newvalue, &newval)
5920 && *conf->variable == newval;
5922 case PGC_STRING:
5924 struct config_string *conf = (struct config_string *) record;
5926 return *conf->variable != NULL &&
5927 strcmp(*conf->variable, newvalue) == 0;
5931 return false;
5935 #ifdef EXEC_BACKEND
5938 * This routine dumps out all non-default GUC options into a binary
5939 * file that is read by all exec'ed backends. The format is:
5941 * variable name, string, null terminated
5942 * variable value, string, null terminated
5943 * variable source, integer
5945 void
5946 write_nondefault_variables(GucContext context)
5948 int i;
5949 int elevel;
5950 FILE *fp;
5952 Assert(context == PGC_POSTMASTER || context == PGC_SIGHUP);
5954 elevel = (context == PGC_SIGHUP) ? LOG : ERROR;
5957 * Open file
5959 fp = AllocateFile(CONFIG_EXEC_PARAMS_NEW, "w");
5960 if (!fp)
5962 ereport(elevel,
5963 (errcode_for_file_access(),
5964 errmsg("could not write to file \"%s\": %m",
5965 CONFIG_EXEC_PARAMS_NEW)));
5966 return;
5969 for (i = 0; i < num_guc_variables; i++)
5971 struct config_generic *gconf = guc_variables[i];
5973 if (gconf->source != PGC_S_DEFAULT)
5975 fprintf(fp, "%s", gconf->name);
5976 fputc(0, fp);
5978 switch (gconf->vartype)
5980 case PGC_BOOL:
5982 struct config_bool *conf = (struct config_bool *) gconf;
5984 if (*conf->variable == 0)
5985 fprintf(fp, "false");
5986 else
5987 fprintf(fp, "true");
5989 break;
5991 case PGC_INT:
5993 struct config_int *conf = (struct config_int *) gconf;
5995 fprintf(fp, "%d", *conf->variable);
5997 break;
5999 case PGC_REAL:
6001 struct config_real *conf = (struct config_real *) gconf;
6003 /* Could lose precision here? */
6004 fprintf(fp, "%f", *conf->variable);
6006 break;
6008 case PGC_STRING:
6010 struct config_string *conf = (struct config_string *) gconf;
6012 fprintf(fp, "%s", *conf->variable);
6014 break;
6017 fputc(0, fp);
6019 fwrite(&gconf->source, sizeof(gconf->source), 1, fp);
6023 if (FreeFile(fp))
6025 ereport(elevel,
6026 (errcode_for_file_access(),
6027 errmsg("could not write to file \"%s\": %m",
6028 CONFIG_EXEC_PARAMS_NEW)));
6029 return;
6033 * Put new file in place. This could delay on Win32, but we don't hold
6034 * any exclusive locks.
6036 rename(CONFIG_EXEC_PARAMS_NEW, CONFIG_EXEC_PARAMS);
6041 * Read string, including null byte from file
6043 * Return NULL on EOF and nothing read
6045 static char *
6046 read_string_with_null(FILE *fp)
6048 int i = 0,
6050 maxlen = 256;
6051 char *str = NULL;
6055 if ((ch = fgetc(fp)) == EOF)
6057 if (i == 0)
6058 return NULL;
6059 else
6060 elog(FATAL, "invalid format of exec config params file");
6062 if (i == 0)
6063 str = guc_malloc(FATAL, maxlen);
6064 else if (i == maxlen)
6065 str = guc_realloc(FATAL, str, maxlen *= 2);
6066 str[i++] = ch;
6067 } while (ch != 0);
6069 return str;
6074 * This routine loads a previous postmaster dump of its non-default
6075 * settings.
6077 void
6078 read_nondefault_variables(void)
6080 FILE *fp;
6081 char *varname,
6082 *varvalue;
6083 int varsource;
6086 * Open file
6088 fp = AllocateFile(CONFIG_EXEC_PARAMS, "r");
6089 if (!fp)
6091 /* File not found is fine */
6092 if (errno != ENOENT)
6093 ereport(FATAL,
6094 (errcode_for_file_access(),
6095 errmsg("could not read from file \"%s\": %m",
6096 CONFIG_EXEC_PARAMS)));
6097 return;
6100 for (;;)
6102 struct config_generic *record;
6104 if ((varname = read_string_with_null(fp)) == NULL)
6105 break;
6107 if ((record = find_option(varname, true, FATAL)) == NULL)
6108 elog(FATAL, "failed to locate variable %s in exec config params file", varname);
6109 if ((varvalue = read_string_with_null(fp)) == NULL)
6110 elog(FATAL, "invalid format of exec config params file");
6111 if (fread(&varsource, sizeof(varsource), 1, fp) == 0)
6112 elog(FATAL, "invalid format of exec config params file");
6114 (void) set_config_option(varname, varvalue, record->context,
6115 varsource, GUC_ACTION_SET, true);
6116 free(varname);
6117 free(varvalue);
6120 FreeFile(fp);
6122 #endif /* EXEC_BACKEND */
6126 * A little "long argument" simulation, although not quite GNU
6127 * compliant. Takes a string of the form "some-option=some value" and
6128 * returns name = "some_option" and value = "some value" in malloc'ed
6129 * storage. Note that '-' is converted to '_' in the option name. If
6130 * there is no '=' in the input string then value will be NULL.
6132 void
6133 ParseLongOption(const char *string, char **name, char **value)
6135 size_t equal_pos;
6136 char *cp;
6138 AssertArg(string);
6139 AssertArg(name);
6140 AssertArg(value);
6142 equal_pos = strcspn(string, "=");
6144 if (string[equal_pos] == '=')
6146 *name = guc_malloc(FATAL, equal_pos + 1);
6147 strlcpy(*name, string, equal_pos + 1);
6149 *value = guc_strdup(FATAL, &string[equal_pos + 1]);
6151 else
6153 /* no equal sign in string */
6154 *name = guc_strdup(FATAL, string);
6155 *value = NULL;
6158 for (cp = *name; *cp; cp++)
6159 if (*cp == '-')
6160 *cp = '_';
6165 * Handle options fetched from pg_database.datconfig, pg_authid.rolconfig,
6166 * pg_proc.proconfig, etc. Caller must specify proper context/source/action.
6168 * The array parameter must be an array of TEXT (it must not be NULL).
6170 void
6171 ProcessGUCArray(ArrayType *array,
6172 GucContext context, GucSource source, GucAction action)
6174 int i;
6176 Assert(array != NULL);
6177 Assert(ARR_ELEMTYPE(array) == TEXTOID);
6178 Assert(ARR_NDIM(array) == 1);
6179 Assert(ARR_LBOUND(array)[0] == 1);
6181 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
6183 Datum d;
6184 bool isnull;
6185 char *s;
6186 char *name;
6187 char *value;
6189 d = array_ref(array, 1, &i,
6190 -1 /* varlenarray */ ,
6191 -1 /* TEXT's typlen */ ,
6192 false /* TEXT's typbyval */ ,
6193 'i' /* TEXT's typalign */ ,
6194 &isnull);
6196 if (isnull)
6197 continue;
6199 s = DatumGetCString(DirectFunctionCall1(textout, d));
6201 ParseLongOption(s, &name, &value);
6202 if (!value)
6204 ereport(WARNING,
6205 (errcode(ERRCODE_SYNTAX_ERROR),
6206 errmsg("could not parse setting for parameter \"%s\"",
6207 name)));
6208 free(name);
6209 continue;
6212 (void) set_config_option(name, value, context, source, action, true);
6214 free(name);
6215 if (value)
6216 free(value);
6222 * Add an entry to an option array. The array parameter may be NULL
6223 * to indicate the current table entry is NULL.
6225 ArrayType *
6226 GUCArrayAdd(ArrayType *array, const char *name, const char *value)
6228 const char *varname;
6229 Datum datum;
6230 char *newval;
6231 ArrayType *a;
6233 Assert(name);
6234 Assert(value);
6236 /* test if the option is valid */
6237 set_config_option(name, value,
6238 superuser() ? PGC_SUSET : PGC_USERSET,
6239 PGC_S_TEST, GUC_ACTION_SET, false);
6241 /* convert name to canonical spelling, so we can use plain strcmp */
6242 (void) GetConfigOptionByName(name, &varname);
6243 name = varname;
6245 newval = palloc(strlen(name) + 1 + strlen(value) + 1);
6246 sprintf(newval, "%s=%s", name, value);
6247 datum = DirectFunctionCall1(textin, CStringGetDatum(newval));
6249 if (array)
6251 int index;
6252 bool isnull;
6253 int i;
6255 Assert(ARR_ELEMTYPE(array) == TEXTOID);
6256 Assert(ARR_NDIM(array) == 1);
6257 Assert(ARR_LBOUND(array)[0] == 1);
6259 index = ARR_DIMS(array)[0] + 1; /* add after end */
6261 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
6263 Datum d;
6264 char *current;
6266 d = array_ref(array, 1, &i,
6267 -1 /* varlenarray */ ,
6268 -1 /* TEXT's typlen */ ,
6269 false /* TEXT's typbyval */ ,
6270 'i' /* TEXT's typalign */ ,
6271 &isnull);
6272 if (isnull)
6273 continue;
6274 current = DatumGetCString(DirectFunctionCall1(textout, d));
6275 if (strncmp(current, newval, strlen(name) + 1) == 0)
6277 index = i;
6278 break;
6282 a = array_set(array, 1, &index,
6283 datum,
6284 false,
6285 -1 /* varlena array */ ,
6286 -1 /* TEXT's typlen */ ,
6287 false /* TEXT's typbyval */ ,
6288 'i' /* TEXT's typalign */ );
6290 else
6291 a = construct_array(&datum, 1,
6292 TEXTOID,
6293 -1, false, 'i');
6295 return a;
6300 * Delete an entry from an option array. The array parameter may be NULL
6301 * to indicate the current table entry is NULL. Also, if the return value
6302 * is NULL then a null should be stored.
6304 ArrayType *
6305 GUCArrayDelete(ArrayType *array, const char *name)
6307 const char *varname;
6308 ArrayType *newarray;
6309 int i;
6310 int index;
6312 Assert(name);
6314 /* test if the option is valid */
6315 set_config_option(name, NULL,
6316 superuser() ? PGC_SUSET : PGC_USERSET,
6317 PGC_S_TEST, GUC_ACTION_SET, false);
6319 /* convert name to canonical spelling, so we can use plain strcmp */
6320 (void) GetConfigOptionByName(name, &varname);
6321 name = varname;
6323 /* if array is currently null, then surely nothing to delete */
6324 if (!array)
6325 return NULL;
6327 newarray = NULL;
6328 index = 1;
6330 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
6332 Datum d;
6333 char *val;
6334 bool isnull;
6336 d = array_ref(array, 1, &i,
6337 -1 /* varlenarray */ ,
6338 -1 /* TEXT's typlen */ ,
6339 false /* TEXT's typbyval */ ,
6340 'i' /* TEXT's typalign */ ,
6341 &isnull);
6342 if (isnull)
6343 continue;
6344 val = DatumGetCString(DirectFunctionCall1(textout, d));
6346 /* ignore entry if it's what we want to delete */
6347 if (strncmp(val, name, strlen(name)) == 0
6348 && val[strlen(name)] == '=')
6349 continue;
6351 /* else add it to the output array */
6352 if (newarray)
6354 newarray = array_set(newarray, 1, &index,
6356 false,
6357 -1 /* varlenarray */ ,
6358 -1 /* TEXT's typlen */ ,
6359 false /* TEXT's typbyval */ ,
6360 'i' /* TEXT's typalign */ );
6362 else
6363 newarray = construct_array(&d, 1,
6364 TEXTOID,
6365 -1, false, 'i');
6367 index++;
6370 return newarray;
6375 * assign_hook and show_hook subroutines
6378 static const char *
6379 assign_log_destination(const char *value, bool doit, GucSource source)
6381 char *rawstring;
6382 List *elemlist;
6383 ListCell *l;
6384 int newlogdest = 0;
6386 /* Need a modifiable copy of string */
6387 rawstring = pstrdup(value);
6389 /* Parse string into list of identifiers */
6390 if (!SplitIdentifierString(rawstring, ',', &elemlist))
6392 /* syntax error in list */
6393 pfree(rawstring);
6394 list_free(elemlist);
6395 if (source >= PGC_S_INTERACTIVE)
6396 ereport(ERROR,
6397 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6398 errmsg("invalid list syntax for parameter \"log_destination\"")));
6399 return NULL;
6402 foreach(l, elemlist)
6404 char *tok = (char *) lfirst(l);
6406 if (pg_strcasecmp(tok, "stderr") == 0)
6407 newlogdest |= LOG_DESTINATION_STDERR;
6408 else if (pg_strcasecmp(tok, "csvlog") == 0)
6409 newlogdest |= LOG_DESTINATION_CSVLOG;
6410 #ifdef HAVE_SYSLOG
6411 else if (pg_strcasecmp(tok, "syslog") == 0)
6412 newlogdest |= LOG_DESTINATION_SYSLOG;
6413 #endif
6414 #ifdef WIN32
6415 else if (pg_strcasecmp(tok, "eventlog") == 0)
6416 newlogdest |= LOG_DESTINATION_EVENTLOG;
6417 #endif
6418 else
6420 if (source >= PGC_S_INTERACTIVE)
6421 ereport(ERROR,
6422 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6423 errmsg("unrecognized \"log_destination\" key word: \"%s\"",
6424 tok)));
6425 pfree(rawstring);
6426 list_free(elemlist);
6427 return NULL;
6431 if (doit)
6432 Log_destination = newlogdest;
6434 pfree(rawstring);
6435 list_free(elemlist);
6437 return value;
6440 #ifdef HAVE_SYSLOG
6442 static const char *
6443 assign_syslog_facility(const char *facility, bool doit, GucSource source)
6445 int syslog_fac;
6447 if (pg_strcasecmp(facility, "LOCAL0") == 0)
6448 syslog_fac = LOG_LOCAL0;
6449 else if (pg_strcasecmp(facility, "LOCAL1") == 0)
6450 syslog_fac = LOG_LOCAL1;
6451 else if (pg_strcasecmp(facility, "LOCAL2") == 0)
6452 syslog_fac = LOG_LOCAL2;
6453 else if (pg_strcasecmp(facility, "LOCAL3") == 0)
6454 syslog_fac = LOG_LOCAL3;
6455 else if (pg_strcasecmp(facility, "LOCAL4") == 0)
6456 syslog_fac = LOG_LOCAL4;
6457 else if (pg_strcasecmp(facility, "LOCAL5") == 0)
6458 syslog_fac = LOG_LOCAL5;
6459 else if (pg_strcasecmp(facility, "LOCAL6") == 0)
6460 syslog_fac = LOG_LOCAL6;
6461 else if (pg_strcasecmp(facility, "LOCAL7") == 0)
6462 syslog_fac = LOG_LOCAL7;
6463 else
6464 return NULL; /* reject */
6466 if (doit)
6468 syslog_facility = syslog_fac;
6469 set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
6470 syslog_facility);
6473 return facility;
6476 static const char *
6477 assign_syslog_ident(const char *ident, bool doit, GucSource source)
6479 if (doit)
6480 set_syslog_parameters(ident, syslog_facility);
6482 return ident;
6484 #endif /* HAVE_SYSLOG */
6487 static const char *
6488 assign_defaultxactisolevel(const char *newval, bool doit, GucSource source)
6490 if (pg_strcasecmp(newval, "serializable") == 0)
6492 if (doit)
6493 DefaultXactIsoLevel = XACT_SERIALIZABLE;
6495 else if (pg_strcasecmp(newval, "repeatable read") == 0)
6497 if (doit)
6498 DefaultXactIsoLevel = XACT_REPEATABLE_READ;
6500 else if (pg_strcasecmp(newval, "read committed") == 0)
6502 if (doit)
6503 DefaultXactIsoLevel = XACT_READ_COMMITTED;
6505 else if (pg_strcasecmp(newval, "read uncommitted") == 0)
6507 if (doit)
6508 DefaultXactIsoLevel = XACT_READ_UNCOMMITTED;
6510 else
6511 return NULL;
6512 return newval;
6515 static const char *
6516 assign_session_replication_role(const char *newval, bool doit, GucSource source)
6518 int newrole;
6520 if (pg_strcasecmp(newval, "origin") == 0)
6521 newrole = SESSION_REPLICATION_ROLE_ORIGIN;
6522 else if (pg_strcasecmp(newval, "replica") == 0)
6523 newrole = SESSION_REPLICATION_ROLE_REPLICA;
6524 else if (pg_strcasecmp(newval, "local") == 0)
6525 newrole = SESSION_REPLICATION_ROLE_LOCAL;
6526 else
6527 return NULL;
6530 * Must flush the plan cache when changing replication role; but don't
6531 * flush unnecessarily.
6533 if (doit && SessionReplicationRole != newrole)
6535 ResetPlanCache();
6536 SessionReplicationRole = newrole;
6539 return newval;
6542 static const char *
6543 assign_log_min_messages(const char *newval, bool doit, GucSource source)
6545 return (assign_msglvl(&log_min_messages, newval, doit, source));
6548 static const char *
6549 assign_client_min_messages(const char *newval, bool doit, GucSource source)
6551 return (assign_msglvl(&client_min_messages, newval, doit, source));
6554 static const char *
6555 assign_min_error_statement(const char *newval, bool doit, GucSource source)
6557 return (assign_msglvl(&log_min_error_statement, newval, doit, source));
6560 static const char *
6561 assign_msglvl(int *var, const char *newval, bool doit, GucSource source)
6563 if (pg_strcasecmp(newval, "debug") == 0)
6565 if (doit)
6566 (*var) = DEBUG2;
6568 else if (pg_strcasecmp(newval, "debug5") == 0)
6570 if (doit)
6571 (*var) = DEBUG5;
6573 else if (pg_strcasecmp(newval, "debug4") == 0)
6575 if (doit)
6576 (*var) = DEBUG4;
6578 else if (pg_strcasecmp(newval, "debug3") == 0)
6580 if (doit)
6581 (*var) = DEBUG3;
6583 else if (pg_strcasecmp(newval, "debug2") == 0)
6585 if (doit)
6586 (*var) = DEBUG2;
6588 else if (pg_strcasecmp(newval, "debug1") == 0)
6590 if (doit)
6591 (*var) = DEBUG1;
6593 else if (pg_strcasecmp(newval, "log") == 0)
6595 if (doit)
6596 (*var) = LOG;
6600 * Client_min_messages always prints 'info', but we allow it as a value
6601 * anyway.
6603 else if (pg_strcasecmp(newval, "info") == 0)
6605 if (doit)
6606 (*var) = INFO;
6608 else if (pg_strcasecmp(newval, "notice") == 0)
6610 if (doit)
6611 (*var) = NOTICE;
6613 else if (pg_strcasecmp(newval, "warning") == 0)
6615 if (doit)
6616 (*var) = WARNING;
6618 else if (pg_strcasecmp(newval, "error") == 0)
6620 if (doit)
6621 (*var) = ERROR;
6623 /* We allow FATAL/PANIC for client-side messages too. */
6624 else if (pg_strcasecmp(newval, "fatal") == 0)
6626 if (doit)
6627 (*var) = FATAL;
6629 else if (pg_strcasecmp(newval, "panic") == 0)
6631 if (doit)
6632 (*var) = PANIC;
6634 else
6635 return NULL; /* fail */
6636 return newval; /* OK */
6639 static const char *
6640 assign_log_error_verbosity(const char *newval, bool doit, GucSource source)
6642 if (pg_strcasecmp(newval, "terse") == 0)
6644 if (doit)
6645 Log_error_verbosity = PGERROR_TERSE;
6647 else if (pg_strcasecmp(newval, "default") == 0)
6649 if (doit)
6650 Log_error_verbosity = PGERROR_DEFAULT;
6652 else if (pg_strcasecmp(newval, "verbose") == 0)
6654 if (doit)
6655 Log_error_verbosity = PGERROR_VERBOSE;
6657 else
6658 return NULL; /* fail */
6659 return newval; /* OK */
6662 static const char *
6663 assign_log_statement(const char *newval, bool doit, GucSource source)
6665 if (pg_strcasecmp(newval, "none") == 0)
6667 if (doit)
6668 log_statement = LOGSTMT_NONE;
6670 else if (pg_strcasecmp(newval, "ddl") == 0)
6672 if (doit)
6673 log_statement = LOGSTMT_DDL;
6675 else if (pg_strcasecmp(newval, "mod") == 0)
6677 if (doit)
6678 log_statement = LOGSTMT_MOD;
6680 else if (pg_strcasecmp(newval, "all") == 0)
6682 if (doit)
6683 log_statement = LOGSTMT_ALL;
6685 else
6686 return NULL; /* fail */
6687 return newval; /* OK */
6690 static const char *
6691 show_num_temp_buffers(void)
6694 * We show the GUC var until local buffers have been initialized, and
6695 * NLocBuffer afterwards.
6697 static char nbuf[32];
6699 sprintf(nbuf, "%d", NLocBuffer ? NLocBuffer : num_temp_buffers);
6700 return nbuf;
6703 static bool
6704 assign_phony_autocommit(bool newval, bool doit, GucSource source)
6706 if (!newval)
6708 if (doit && source >= PGC_S_INTERACTIVE)
6709 ereport(ERROR,
6710 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6711 errmsg("SET AUTOCOMMIT TO OFF is no longer supported")));
6712 return false;
6714 return true;
6717 static const char *
6718 assign_custom_variable_classes(const char *newval, bool doit, GucSource source)
6721 * Check syntax. newval must be a comma separated list of identifiers.
6722 * Whitespace is allowed but removed from the result.
6724 bool hasSpaceAfterToken = false;
6725 const char *cp = newval;
6726 int symLen = 0;
6727 char c;
6728 StringInfoData buf;
6730 initStringInfo(&buf);
6731 while ((c = *cp++) != '\0')
6733 if (isspace((unsigned char) c))
6735 if (symLen > 0)
6736 hasSpaceAfterToken = true;
6737 continue;
6740 if (c == ',')
6742 if (symLen > 0) /* terminate identifier */
6744 appendStringInfoChar(&buf, ',');
6745 symLen = 0;
6747 hasSpaceAfterToken = false;
6748 continue;
6751 if (hasSpaceAfterToken || !isalnum((unsigned char) c))
6754 * Syntax error due to token following space after token or non
6755 * alpha numeric character
6757 pfree(buf.data);
6758 return NULL;
6760 appendStringInfoChar(&buf, c);
6761 symLen++;
6764 /* Remove stray ',' at end */
6765 if (symLen == 0 && buf.len > 0)
6766 buf.data[--buf.len] = '\0';
6768 /* GUC wants the result malloc'd */
6769 newval = guc_strdup(LOG, buf.data);
6771 pfree(buf.data);
6772 return newval;
6775 static bool
6776 assign_debug_assertions(bool newval, bool doit, GucSource source)
6778 #ifndef USE_ASSERT_CHECKING
6779 if (newval)
6780 ereport(ERROR,
6781 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6782 errmsg("assertion checking is not supported by this build")));
6783 #endif
6784 return true;
6787 static bool
6788 assign_ssl(bool newval, bool doit, GucSource source)
6790 #ifndef USE_SSL
6791 if (newval)
6792 ereport(ERROR,
6793 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6794 errmsg("SSL is not supported by this build")));
6795 #endif
6796 return true;
6799 static bool
6800 assign_stage_log_stats(bool newval, bool doit, GucSource source)
6802 if (newval && log_statement_stats)
6804 if (source >= PGC_S_INTERACTIVE)
6805 ereport(ERROR,
6806 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6807 errmsg("cannot enable parameter when \"log_statement_stats\" is true")));
6808 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
6809 else if (source != PGC_S_OVERRIDE)
6810 return false;
6812 return true;
6815 static bool
6816 assign_log_stats(bool newval, bool doit, GucSource source)
6818 if (newval &&
6819 (log_parser_stats || log_planner_stats || log_executor_stats))
6821 if (source >= PGC_S_INTERACTIVE)
6822 ereport(ERROR,
6823 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6824 errmsg("cannot enable \"log_statement_stats\" when "
6825 "\"log_parser_stats\", \"log_planner_stats\", "
6826 "or \"log_executor_stats\" is true")));
6827 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
6828 else if (source != PGC_S_OVERRIDE)
6829 return false;
6831 return true;
6834 static bool
6835 assign_transaction_read_only(bool newval, bool doit, GucSource source)
6837 /* Can't go to r/w mode inside a r/o transaction */
6838 if (newval == false && XactReadOnly && IsSubTransaction())
6840 if (source >= PGC_S_INTERACTIVE)
6841 ereport(ERROR,
6842 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6843 errmsg("cannot set transaction read-write mode inside a read-only transaction")));
6844 /* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
6845 else if (source != PGC_S_OVERRIDE)
6846 return false;
6848 return true;
6851 static const char *
6852 assign_canonical_path(const char *newval, bool doit, GucSource source)
6854 if (doit)
6856 char *canon_val = guc_strdup(ERROR, newval);
6858 canonicalize_path(canon_val);
6859 return canon_val;
6861 else
6862 return newval;
6865 static const char *
6866 assign_backslash_quote(const char *newval, bool doit, GucSource source)
6868 BackslashQuoteType bq;
6869 bool bqbool;
6872 * Although only "on", "off", and "safe_encoding" are documented, we use
6873 * parse_bool so we can accept all the likely variants of "on" and "off".
6875 if (pg_strcasecmp(newval, "safe_encoding") == 0)
6876 bq = BACKSLASH_QUOTE_SAFE_ENCODING;
6877 else if (parse_bool(newval, &bqbool))
6879 bq = bqbool ? BACKSLASH_QUOTE_ON : BACKSLASH_QUOTE_OFF;
6881 else
6882 return NULL; /* reject */
6884 if (doit)
6885 backslash_quote = bq;
6887 return newval;
6890 static const char *
6891 assign_timezone_abbreviations(const char *newval, bool doit, GucSource source)
6894 * The powerup value shown above for timezone_abbreviations is "UNKNOWN".
6895 * When we see this we just do nothing. If this value isn't overridden
6896 * from the config file then pg_timezone_abbrev_initialize() will
6897 * eventually replace it with "Default". This hack has two purposes: to
6898 * avoid wasting cycles loading values that might soon be overridden from
6899 * the config file, and to avoid trying to read the timezone abbrev files
6900 * during InitializeGUCOptions(). The latter doesn't work in an
6901 * EXEC_BACKEND subprocess because my_exec_path hasn't been set yet and so
6902 * we can't locate PGSHAREDIR. (Essentially the same hack is used to
6903 * delay initializing TimeZone ... if we have any more, we should try to
6904 * clean up and centralize this mechanism ...)
6906 if (strcmp(newval, "UNKNOWN") == 0)
6908 return newval;
6911 /* Loading abbrev file is expensive, so only do it when value changes */
6912 if (timezone_abbreviations_string == NULL ||
6913 strcmp(timezone_abbreviations_string, newval) != 0)
6915 int elevel;
6918 * If reading config file, only the postmaster should bleat loudly
6919 * about problems. Otherwise, it's just this one process doing it,
6920 * and we use WARNING message level.
6922 if (source == PGC_S_FILE)
6923 elevel = IsUnderPostmaster ? DEBUG2 : LOG;
6924 else
6925 elevel = WARNING;
6926 if (!load_tzoffsets(newval, doit, elevel))
6927 return NULL;
6929 return newval;
6933 * pg_timezone_abbrev_initialize --- set default value if not done already
6935 * This is called after initial loading of postgresql.conf. If no
6936 * timezone_abbreviations setting was found therein, select default.
6938 void
6939 pg_timezone_abbrev_initialize(void)
6941 if (strcmp(timezone_abbreviations_string, "UNKNOWN") == 0)
6943 SetConfigOption("timezone_abbreviations", "Default",
6944 PGC_POSTMASTER, PGC_S_ARGV);
6948 static const char *
6949 assign_xmlbinary(const char *newval, bool doit, GucSource source)
6951 XmlBinaryType xb;
6953 if (pg_strcasecmp(newval, "base64") == 0)
6954 xb = XMLBINARY_BASE64;
6955 else if (pg_strcasecmp(newval, "hex") == 0)
6956 xb = XMLBINARY_HEX;
6957 else
6958 return NULL; /* reject */
6960 if (doit)
6961 xmlbinary = xb;
6963 return newval;
6966 static const char *
6967 assign_xmloption(const char *newval, bool doit, GucSource source)
6969 XmlOptionType xo;
6971 if (pg_strcasecmp(newval, "document") == 0)
6972 xo = XMLOPTION_DOCUMENT;
6973 else if (pg_strcasecmp(newval, "content") == 0)
6974 xo = XMLOPTION_CONTENT;
6975 else
6976 return NULL; /* reject */
6978 if (doit)
6979 xmloption = xo;
6981 return newval;
6984 static const char *
6985 show_archive_command(void)
6987 if (XLogArchiveMode)
6988 return XLogArchiveCommand;
6989 else
6990 return "(disabled)";
6993 static bool
6994 assign_tcp_keepalives_idle(int newval, bool doit, GucSource source)
6996 if (doit)
6997 return (pq_setkeepalivesidle(newval, MyProcPort) == STATUS_OK);
6999 return true;
7002 static const char *
7003 show_tcp_keepalives_idle(void)
7005 static char nbuf[16];
7007 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesidle(MyProcPort));
7008 return nbuf;
7011 static bool
7012 assign_tcp_keepalives_interval(int newval, bool doit, GucSource source)
7014 if (doit)
7015 return (pq_setkeepalivesinterval(newval, MyProcPort) == STATUS_OK);
7017 return true;
7020 static const char *
7021 show_tcp_keepalives_interval(void)
7023 static char nbuf[16];
7025 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesinterval(MyProcPort));
7026 return nbuf;
7029 static bool
7030 assign_tcp_keepalives_count(int newval, bool doit, GucSource source)
7032 if (doit)
7033 return (pq_setkeepalivescount(newval, MyProcPort) == STATUS_OK);
7035 return true;
7038 static const char *
7039 show_tcp_keepalives_count(void)
7041 static char nbuf[16];
7043 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivescount(MyProcPort));
7044 return nbuf;
7047 static bool
7048 assign_maxconnections(int newval, bool doit, GucSource source)
7050 if (newval + autovacuum_max_workers > INT_MAX / 4)
7051 return false;
7053 if (doit)
7054 MaxBackends = newval + autovacuum_max_workers;
7056 return true;
7059 static bool
7060 assign_autovacuum_max_workers(int newval, bool doit, GucSource source)
7062 if (newval + MaxConnections > INT_MAX / 4)
7063 return false;
7065 if (doit)
7066 MaxBackends = newval + MaxConnections;
7068 return true;
7071 #include "guc-file.c"