1 /*--------------------------------------------------------------------
4 * Support for grand unified configuration scheme, including SET
5 * command, configuration file, and command line options.
6 * See src/backend/utils/misc/README for more information.
9 * Copyright (c) 2000-2011, PostgreSQL Global Development Group
10 * Written by Peter Eisentraut <peter_e@gmx.net>.
13 * src/backend/utils/misc/guc.c
15 *--------------------------------------------------------------------
29 #include "access/gin.h"
30 #include "access/transam.h"
31 #include "access/twophase.h"
32 #include "access/xact.h"
33 #include "catalog/namespace.h"
34 #include "commands/async.h"
35 #include "commands/prepare.h"
36 #include "commands/vacuum.h"
37 #include "commands/variable.h"
38 #include "commands/trigger.h"
40 #include "libpq/auth.h"
41 #include "libpq/be-fsstubs.h"
42 #include "libpq/pqformat.h"
43 #include "miscadmin.h"
44 #include "optimizer/cost.h"
45 #include "optimizer/geqo.h"
46 #include "optimizer/paths.h"
47 #include "optimizer/planmain.h"
48 #include "parser/parse_expr.h"
49 #include "parser/parse_type.h"
50 #include "parser/parser.h"
51 #include "parser/scansup.h"
53 #include "postmaster/autovacuum.h"
54 #include "postmaster/bgwriter.h"
55 #include "postmaster/postmaster.h"
56 #include "postmaster/syslogger.h"
57 #include "postmaster/walwriter.h"
58 #include "replication/syncrep.h"
59 #include "replication/walreceiver.h"
60 #include "replication/walsender.h"
61 #include "storage/bufmgr.h"
62 #include "storage/standby.h"
63 #include "storage/fd.h"
64 #include "storage/predicate.h"
65 #include "tcop/tcopprot.h"
66 #include "tsearch/ts_cache.h"
67 #include "utils/builtins.h"
68 #include "utils/bytea.h"
69 #include "utils/guc_tables.h"
70 #include "utils/memutils.h"
71 #include "utils/pg_locale.h"
72 #include "utils/plancache.h"
73 #include "utils/portal.h"
74 #include "utils/ps_status.h"
75 #include "utils/tzparser.h"
76 #include "utils/xml.h"
79 #define PG_KRB_SRVTAB ""
82 #define PG_KRB_SRVNAM ""
85 #define CONFIG_FILENAME "postgresql.conf"
86 #define HBA_FILENAME "pg_hba.conf"
87 #define IDENT_FILENAME "pg_ident.conf"
90 #define CONFIG_EXEC_PARAMS "global/config_exec_params"
91 #define CONFIG_EXEC_PARAMS_NEW "global/config_exec_params.new"
94 /* upper limit for GUC variables measured in kilobytes of memory */
95 /* note that various places assume the byte size fits in a "long" variable */
96 #if SIZEOF_SIZE_T > 4 && SIZEOF_LONG > 4
97 #define MAX_KILOBYTES INT_MAX
99 #define MAX_KILOBYTES (INT_MAX / 1024)
103 * Note: MAX_BACKENDS is limited to 2^23-1 because inval.c stores the
104 * backend ID as a 3-byte signed integer. Even if that limitation were
105 * removed, we still could not exceed INT_MAX/4 because some places compute
106 * 4*MaxBackends without any overflow check. This is rechecked in
107 * check_maxconnections, since MaxBackends is computed as MaxConnections
108 * plus autovacuum_max_workers plus one (for the autovacuum launcher).
110 #define MAX_BACKENDS 0x7fffff
112 #define KB_PER_MB (1024)
113 #define KB_PER_GB (1024*1024)
115 #define MS_PER_S 1000
117 #define MS_PER_MIN (1000 * 60)
119 #define S_PER_H (60 * 60)
120 #define MS_PER_H (1000 * 60 * 60)
121 #define MIN_PER_D (60 * 24)
122 #define S_PER_D (60 * 60 * 24)
123 #define MS_PER_D (1000 * 60 * 60 * 24)
125 /* XXX these should appear in other modules' header files */
126 extern bool Log_disconnections;
127 extern int CommitDelay;
128 extern int CommitSiblings;
129 extern char *default_tablespace;
130 extern char *temp_tablespaces;
131 extern bool synchronize_seqscans;
132 extern bool fullPageWrites;
133 extern int ssl_renegotiation_limit;
134 extern char *SSLCipherSuites;
137 extern bool trace_sort;
139 #ifdef TRACE_SYNCSCAN
140 extern bool trace_syncscan;
142 #ifdef DEBUG_BOUNDED_SORT
143 extern bool optimize_bounded_sort;
146 static int GUC_check_errcode_value;
148 /* global variables for check hook support */
149 char *GUC_check_errmsg_string;
150 char *GUC_check_errdetail_string;
151 char *GUC_check_errhint_string;
154 static void set_config_sourcefile(const char *name, char *sourcefile,
156 static bool call_bool_check_hook(struct config_bool * conf, bool *newval,
157 void **extra, GucSource source, int elevel);
158 static bool call_int_check_hook(struct config_int * conf, int *newval,
159 void **extra, GucSource source, int elevel);
160 static bool call_real_check_hook(struct config_real * conf, double *newval,
161 void **extra, GucSource source, int elevel);
162 static bool call_string_check_hook(struct config_string * conf, char **newval,
163 void **extra, GucSource source, int elevel);
164 static bool call_enum_check_hook(struct config_enum * conf, int *newval,
165 void **extra, GucSource source, int elevel);
167 static bool check_log_destination(char **newval, void **extra, GucSource source);
168 static void assign_log_destination(const char *newval, void *extra);
171 static int syslog_facility = LOG_LOCAL0;
173 static int syslog_facility = 0;
176 static void assign_syslog_facility(int newval, void *extra);
177 static void assign_syslog_ident(const char *newval, void *extra);
178 static void assign_session_replication_role(int newval, void *extra);
179 static bool check_temp_buffers(int *newval, void **extra, GucSource source);
180 static bool check_phony_autocommit(bool *newval, void **extra, GucSource source);
181 static bool check_debug_assertions(bool *newval, void **extra, GucSource source);
182 static bool check_bonjour(bool *newval, void **extra, GucSource source);
183 static bool check_ssl(bool *newval, void **extra, GucSource source);
184 static bool check_stage_log_stats(bool *newval, void **extra, GucSource source);
185 static bool check_log_stats(bool *newval, void **extra, GucSource source);
186 static bool check_canonical_path(char **newval, void **extra, GucSource source);
187 static bool check_timezone_abbreviations(char **newval, void **extra, GucSource source);
188 static void assign_timezone_abbreviations(const char *newval, void *extra);
189 static void pg_timezone_abbrev_initialize(void);
190 static const char *show_archive_command(void);
191 static void assign_tcp_keepalives_idle(int newval, void *extra);
192 static void assign_tcp_keepalives_interval(int newval, void *extra);
193 static void assign_tcp_keepalives_count(int newval, void *extra);
194 static const char *show_tcp_keepalives_idle(void);
195 static const char *show_tcp_keepalives_interval(void);
196 static const char *show_tcp_keepalives_count(void);
197 static bool check_maxconnections(int *newval, void **extra, GucSource source);
198 static void assign_maxconnections(int newval, void *extra);
199 static bool check_autovacuum_max_workers(int *newval, void **extra, GucSource source);
200 static void assign_autovacuum_max_workers(int newval, void *extra);
201 static bool check_effective_io_concurrency(int *newval, void **extra, GucSource source);
202 static void assign_effective_io_concurrency(int newval, void *extra);
203 static void assign_pgstat_temp_directory(const char *newval, void *extra);
204 static bool check_application_name(char **newval, void **extra, GucSource source);
205 static void assign_application_name(const char *newval, void *extra);
206 static const char *show_unix_socket_permissions(void);
207 static const char *show_log_file_mode(void);
209 static char *config_enum_get_options(struct config_enum * record,
210 const char *prefix, const char *suffix,
211 const char *separator);
215 * Options for enum values defined in this module.
217 * NOTE! Option values may not contain double quotes!
220 static const struct config_enum_entry bytea_output_options[] = {
221 {"escape", BYTEA_OUTPUT_ESCAPE, false},
222 {"hex", BYTEA_OUTPUT_HEX, false},
227 * We have different sets for client and server message level options because
228 * they sort slightly different (see "log" level)
230 static const struct config_enum_entry client_message_level_options[] = {
231 {"debug", DEBUG2, true},
232 {"debug5", DEBUG5, false},
233 {"debug4", DEBUG4, false},
234 {"debug3", DEBUG3, false},
235 {"debug2", DEBUG2, false},
236 {"debug1", DEBUG1, false},
238 {"info", INFO, true},
239 {"notice", NOTICE, false},
240 {"warning", WARNING, false},
241 {"error", ERROR, false},
242 {"fatal", FATAL, true},
243 {"panic", PANIC, true},
247 static const struct config_enum_entry server_message_level_options[] = {
248 {"debug", DEBUG2, true},
249 {"debug5", DEBUG5, false},
250 {"debug4", DEBUG4, false},
251 {"debug3", DEBUG3, false},
252 {"debug2", DEBUG2, false},
253 {"debug1", DEBUG1, false},
254 {"info", INFO, false},
255 {"notice", NOTICE, false},
256 {"warning", WARNING, false},
257 {"error", ERROR, false},
259 {"fatal", FATAL, false},
260 {"panic", PANIC, false},
264 static const struct config_enum_entry intervalstyle_options[] = {
265 {"postgres", INTSTYLE_POSTGRES, false},
266 {"postgres_verbose", INTSTYLE_POSTGRES_VERBOSE, false},
267 {"sql_standard", INTSTYLE_SQL_STANDARD, false},
268 {"iso_8601", INTSTYLE_ISO_8601, false},
272 static const struct config_enum_entry log_error_verbosity_options[] = {
273 {"terse", PGERROR_TERSE, false},
274 {"default", PGERROR_DEFAULT, false},
275 {"verbose", PGERROR_VERBOSE, false},
279 static const struct config_enum_entry log_statement_options[] = {
280 {"none", LOGSTMT_NONE, false},
281 {"ddl", LOGSTMT_DDL, false},
282 {"mod", LOGSTMT_MOD, false},
283 {"all", LOGSTMT_ALL, false},
287 static const struct config_enum_entry isolation_level_options[] = {
288 {"serializable", XACT_SERIALIZABLE, false},
289 {"repeatable read", XACT_REPEATABLE_READ, false},
290 {"read committed", XACT_READ_COMMITTED, false},
291 {"read uncommitted", XACT_READ_UNCOMMITTED, false},
295 static const struct config_enum_entry session_replication_role_options[] = {
296 {"origin", SESSION_REPLICATION_ROLE_ORIGIN, false},
297 {"replica", SESSION_REPLICATION_ROLE_REPLICA, false},
298 {"local", SESSION_REPLICATION_ROLE_LOCAL, false},
302 static const struct config_enum_entry syslog_facility_options[] = {
304 {"local0", LOG_LOCAL0, false},
305 {"local1", LOG_LOCAL1, false},
306 {"local2", LOG_LOCAL2, false},
307 {"local3", LOG_LOCAL3, false},
308 {"local4", LOG_LOCAL4, false},
309 {"local5", LOG_LOCAL5, false},
310 {"local6", LOG_LOCAL6, false},
311 {"local7", LOG_LOCAL7, false},
318 static const struct config_enum_entry track_function_options[] = {
319 {"none", TRACK_FUNC_OFF, false},
320 {"pl", TRACK_FUNC_PL, false},
321 {"all", TRACK_FUNC_ALL, false},
325 static const struct config_enum_entry xmlbinary_options[] = {
326 {"base64", XMLBINARY_BASE64, false},
327 {"hex", XMLBINARY_HEX, false},
331 static const struct config_enum_entry xmloption_options[] = {
332 {"content", XMLOPTION_CONTENT, false},
333 {"document", XMLOPTION_DOCUMENT, false},
338 * Although only "on", "off", and "safe_encoding" are documented, we
339 * accept all the likely variants of "on" and "off".
341 static const struct config_enum_entry backslash_quote_options[] = {
342 {"safe_encoding", BACKSLASH_QUOTE_SAFE_ENCODING, false},
343 {"on", BACKSLASH_QUOTE_ON, false},
344 {"off", BACKSLASH_QUOTE_OFF, false},
345 {"true", BACKSLASH_QUOTE_ON, true},
346 {"false", BACKSLASH_QUOTE_OFF, true},
347 {"yes", BACKSLASH_QUOTE_ON, true},
348 {"no", BACKSLASH_QUOTE_OFF, true},
349 {"1", BACKSLASH_QUOTE_ON, true},
350 {"0", BACKSLASH_QUOTE_OFF, true},
355 * Although only "on", "off", and "partition" are documented, we
356 * accept all the likely variants of "on" and "off".
358 static const struct config_enum_entry constraint_exclusion_options[] = {
359 {"partition", CONSTRAINT_EXCLUSION_PARTITION, false},
360 {"on", CONSTRAINT_EXCLUSION_ON, false},
361 {"off", CONSTRAINT_EXCLUSION_OFF, false},
362 {"true", CONSTRAINT_EXCLUSION_ON, true},
363 {"false", CONSTRAINT_EXCLUSION_OFF, true},
364 {"yes", CONSTRAINT_EXCLUSION_ON, true},
365 {"no", CONSTRAINT_EXCLUSION_OFF, true},
366 {"1", CONSTRAINT_EXCLUSION_ON, true},
367 {"0", CONSTRAINT_EXCLUSION_OFF, true},
372 * Although only "on", "off", and "local" are documented, we
373 * accept all the likely variants of "on" and "off".
375 static const struct config_enum_entry synchronous_commit_options[] = {
376 {"local", SYNCHRONOUS_COMMIT_LOCAL_FLUSH, false},
377 {"on", SYNCHRONOUS_COMMIT_ON, false},
378 {"off", SYNCHRONOUS_COMMIT_OFF, false},
379 {"true", SYNCHRONOUS_COMMIT_ON, true},
380 {"false", SYNCHRONOUS_COMMIT_OFF, true},
381 {"yes", SYNCHRONOUS_COMMIT_ON, true},
382 {"no", SYNCHRONOUS_COMMIT_OFF, true},
383 {"1", SYNCHRONOUS_COMMIT_ON, true},
384 {"0", SYNCHRONOUS_COMMIT_OFF, true},
389 * Options for enum values stored in other modules
391 extern const struct config_enum_entry wal_level_options[];
392 extern const struct config_enum_entry sync_method_options[];
395 * GUC option variables that are exported from this module
397 #ifdef USE_ASSERT_CHECKING
398 bool assert_enabled = true;
400 bool assert_enabled = false;
402 bool log_duration = false;
403 bool Debug_print_plan = false;
404 bool Debug_print_parse = false;
405 bool Debug_print_rewritten = false;
406 bool Debug_pretty_print = true;
408 bool log_parser_stats = false;
409 bool log_planner_stats = false;
410 bool log_executor_stats = false;
411 bool log_statement_stats = false; /* this is sort of all three
413 bool log_btree_build_stats = false;
415 bool check_function_bodies = true;
416 bool default_with_oids = false;
417 bool SQL_inheritance = true;
419 bool Password_encryption = true;
421 int log_min_error_statement = ERROR;
422 int log_min_messages = WARNING;
423 int client_min_messages = NOTICE;
424 int log_min_duration_statement = -1;
425 int log_temp_files = -1;
426 int trace_recovery_messages = LOG;
428 int temp_file_limit = -1;
430 int num_temp_buffers = 1024;
432 char *data_directory;
433 char *ConfigFileName;
436 char *external_pid_file;
438 char *pgstat_temp_directory;
440 char *application_name;
442 int tcp_keepalives_idle;
443 int tcp_keepalives_interval;
444 int tcp_keepalives_count;
447 * These variables are all dummies that don't do anything, except in some
448 * cases provide the value for SHOW to display. The real state is elsewhere
449 * and is kept in sync by assign_hooks.
451 static char *log_destination_string;
453 static char *syslog_ident_str;
454 static bool phony_autocommit;
455 static bool session_auth_is_superuser;
456 static double phony_random_seed;
457 static char *client_encoding_string;
458 static char *datestyle_string;
459 static char *locale_collate;
460 static char *locale_ctype;
461 static char *server_encoding_string;
462 static char *server_version_string;
463 static int server_version_num;
464 static char *timezone_string;
465 static char *log_timezone_string;
466 static char *timezone_abbreviations_string;
467 static char *XactIsoLevel_string;
468 static char *session_authorization_string;
469 static int max_function_args;
470 static int max_index_keys;
471 static int max_identifier_length;
472 static int block_size;
473 static int segment_size;
474 static int wal_block_size;
475 static int wal_segment_size;
476 static bool integer_datetimes;
477 static int effective_io_concurrency;
479 /* should be static, but commands/variable.c needs to get at this */
484 * Displayable names for context types (enum GucContext)
486 * Note: these strings are deliberately not localized.
488 const char *const GucContext_Names[] =
490 /* PGC_INTERNAL */ "internal",
491 /* PGC_POSTMASTER */ "postmaster",
492 /* PGC_SIGHUP */ "sighup",
493 /* PGC_BACKEND */ "backend",
494 /* PGC_SUSET */ "superuser",
495 /* PGC_USERSET */ "user"
499 * Displayable names for source types (enum GucSource)
501 * Note: these strings are deliberately not localized.
503 const char *const GucSource_Names[] =
505 /* PGC_S_DEFAULT */ "default",
506 /* PGC_S_DYNAMIC_DEFAULT */ "default",
507 /* PGC_S_ENV_VAR */ "environment variable",
508 /* PGC_S_FILE */ "configuration file",
509 /* PGC_S_ARGV */ "command line",
510 /* PGC_S_DATABASE */ "database",
511 /* PGC_S_USER */ "user",
512 /* PGC_S_DATABASE_USER */ "database user",
513 /* PGC_S_CLIENT */ "client",
514 /* PGC_S_OVERRIDE */ "override",
515 /* PGC_S_INTERACTIVE */ "interactive",
516 /* PGC_S_TEST */ "test",
517 /* PGC_S_SESSION */ "session"
521 * Displayable names for the groupings defined in enum config_group
523 const char *const config_group_names[] =
526 gettext_noop("Ungrouped"),
528 gettext_noop("File Locations"),
530 gettext_noop("Connections and Authentication"),
531 /* CONN_AUTH_SETTINGS */
532 gettext_noop("Connections and Authentication / Connection Settings"),
533 /* CONN_AUTH_SECURITY */
534 gettext_noop("Connections and Authentication / Security and Authentication"),
536 gettext_noop("Resource Usage"),
538 gettext_noop("Resource Usage / Memory"),
540 gettext_noop("Resource Usage / Disk"),
541 /* RESOURCES_KERNEL */
542 gettext_noop("Resource Usage / Kernel Resources"),
543 /* RESOURCES_VACUUM_DELAY */
544 gettext_noop("Resource Usage / Cost-Based Vacuum Delay"),
545 /* RESOURCES_BGWRITER */
546 gettext_noop("Resource Usage / Background Writer"),
547 /* RESOURCES_ASYNCHRONOUS */
548 gettext_noop("Resource Usage / Asynchronous Behavior"),
550 gettext_noop("Write-Ahead Log"),
552 gettext_noop("Write-Ahead Log / Settings"),
553 /* WAL_CHECKPOINTS */
554 gettext_noop("Write-Ahead Log / Checkpoints"),
556 gettext_noop("Write-Ahead Log / Archiving"),
558 gettext_noop("Replication"),
559 /* REPLICATION_SENDING */
560 gettext_noop("Replication / Sending Servers"),
561 /* REPLICATION_MASTER */
562 gettext_noop("Replication / Master Server"),
563 /* REPLICATION_STANDBY */
564 gettext_noop("Replication / Standby Servers"),
566 gettext_noop("Query Tuning"),
567 /* QUERY_TUNING_METHOD */
568 gettext_noop("Query Tuning / Planner Method Configuration"),
569 /* QUERY_TUNING_COST */
570 gettext_noop("Query Tuning / Planner Cost Constants"),
571 /* QUERY_TUNING_GEQO */
572 gettext_noop("Query Tuning / Genetic Query Optimizer"),
573 /* QUERY_TUNING_OTHER */
574 gettext_noop("Query Tuning / Other Planner Options"),
576 gettext_noop("Reporting and Logging"),
578 gettext_noop("Reporting and Logging / Where to Log"),
580 gettext_noop("Reporting and Logging / When to Log"),
582 gettext_noop("Reporting and Logging / What to Log"),
584 gettext_noop("Statistics"),
585 /* STATS_MONITORING */
586 gettext_noop("Statistics / Monitoring"),
587 /* STATS_COLLECTOR */
588 gettext_noop("Statistics / Query and Index Statistics Collector"),
590 gettext_noop("Autovacuum"),
592 gettext_noop("Client Connection Defaults"),
593 /* CLIENT_CONN_STATEMENT */
594 gettext_noop("Client Connection Defaults / Statement Behavior"),
595 /* CLIENT_CONN_LOCALE */
596 gettext_noop("Client Connection Defaults / Locale and Formatting"),
597 /* CLIENT_CONN_OTHER */
598 gettext_noop("Client Connection Defaults / Other Defaults"),
599 /* LOCK_MANAGEMENT */
600 gettext_noop("Lock Management"),
602 gettext_noop("Version and Platform Compatibility"),
603 /* COMPAT_OPTIONS_PREVIOUS */
604 gettext_noop("Version and Platform Compatibility / Previous PostgreSQL Versions"),
605 /* COMPAT_OPTIONS_CLIENT */
606 gettext_noop("Version and Platform Compatibility / Other Platforms and Clients"),
608 gettext_noop("Error Handling"),
610 gettext_noop("Preset Options"),
612 gettext_noop("Customized Options"),
613 /* DEVELOPER_OPTIONS */
614 gettext_noop("Developer Options"),
615 /* help_config wants this array to be null-terminated */
620 * Displayable names for GUC variable types (enum config_type)
622 * Note: these strings are deliberately not localized.
624 const char *const config_type_names[] =
626 /* PGC_BOOL */ "bool",
627 /* PGC_INT */ "integer",
628 /* PGC_REAL */ "real",
629 /* PGC_STRING */ "string",
630 /* PGC_ENUM */ "enum"
635 * Contents of GUC tables
637 * See src/backend/utils/misc/README for design notes.
641 * 1. Declare a global variable of type bool, int, double, or char*
642 * and make use of it.
644 * 2. Decide at what times it's safe to set the option. See guc.h for
647 * 3. Decide on a name, a default value, upper and lower bounds (if
650 * 4. Add a record below.
652 * 5. Add it to src/backend/utils/misc/postgresql.conf.sample, if
655 * 6. Don't forget to document the option (at least in config.sgml).
657 * 7. If it's a new GUC_LIST option you must edit pg_dumpall.c to ensure
658 * it is not single quoted at dump time.
662 /******** option records follow ********/
664 static struct config_bool ConfigureNamesBool[] =
667 {"enable_seqscan", PGC_USERSET, QUERY_TUNING_METHOD,
668 gettext_noop("Enables the planner's use of sequential-scan plans."),
676 {"enable_indexscan", PGC_USERSET, QUERY_TUNING_METHOD,
677 gettext_noop("Enables the planner's use of index-scan plans."),
685 {"enable_indexonlyscan", PGC_USERSET, QUERY_TUNING_METHOD,
686 gettext_noop("Enables the planner's use of index-only-scan plans."),
689 &enable_indexonlyscan,
694 {"enable_bitmapscan", PGC_USERSET, QUERY_TUNING_METHOD,
695 gettext_noop("Enables the planner's use of bitmap-scan plans."),
703 {"enable_tidscan", PGC_USERSET, QUERY_TUNING_METHOD,
704 gettext_noop("Enables the planner's use of TID scan plans."),
712 {"enable_sort", PGC_USERSET, QUERY_TUNING_METHOD,
713 gettext_noop("Enables the planner's use of explicit sort steps."),
721 {"enable_hashagg", PGC_USERSET, QUERY_TUNING_METHOD,
722 gettext_noop("Enables the planner's use of hashed aggregation plans."),
730 {"enable_material", PGC_USERSET, QUERY_TUNING_METHOD,
731 gettext_noop("Enables the planner's use of materialization."),
739 {"enable_nestloop", PGC_USERSET, QUERY_TUNING_METHOD,
740 gettext_noop("Enables the planner's use of nested-loop join plans."),
748 {"enable_mergejoin", PGC_USERSET, QUERY_TUNING_METHOD,
749 gettext_noop("Enables the planner's use of merge join plans."),
757 {"enable_hashjoin", PGC_USERSET, QUERY_TUNING_METHOD,
758 gettext_noop("Enables the planner's use of hash join plans."),
766 {"geqo", PGC_USERSET, QUERY_TUNING_GEQO,
767 gettext_noop("Enables genetic query optimization."),
768 gettext_noop("This algorithm attempts to do planning without "
769 "exhaustive searching.")
776 /* Not for general use --- used by SET SESSION AUTHORIZATION */
777 {"is_superuser", PGC_INTERNAL, UNGROUPED,
778 gettext_noop("Shows whether the current user is a superuser."),
780 GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
782 &session_auth_is_superuser,
787 {"bonjour", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
788 gettext_noop("Enables advertising the server via Bonjour."),
793 check_bonjour, NULL, NULL
796 {"ssl", PGC_POSTMASTER, CONN_AUTH_SECURITY,
797 gettext_noop("Enables SSL connections."),
802 check_ssl, NULL, NULL
805 {"fsync", PGC_SIGHUP, WAL_SETTINGS,
806 gettext_noop("Forces synchronization of updates to disk."),
807 gettext_noop("The server will use the fsync() system call in several places to make "
808 "sure that updates are physically written to disk. This insures "
809 "that a database cluster will recover to a consistent state after "
810 "an operating system or hardware crash.")
817 {"zero_damaged_pages", PGC_SUSET, DEVELOPER_OPTIONS,
818 gettext_noop("Continues processing past damaged page headers."),
819 gettext_noop("Detection of a damaged page header normally causes PostgreSQL to "
820 "report an error, aborting the current transaction. Setting "
821 "zero_damaged_pages to true causes the system to instead report a "
822 "warning, zero out the damaged page, and continue processing. This "
823 "behavior will destroy data, namely all the rows on the damaged page."),
831 {"full_page_writes", PGC_SIGHUP, WAL_SETTINGS,
832 gettext_noop("Writes full pages to WAL when first modified after a checkpoint."),
833 gettext_noop("A page write in process during an operating system crash might be "
834 "only partially written to disk. During recovery, the row changes "
835 "stored in WAL are not enough to recover. This option writes "
836 "pages when first modified after a checkpoint to WAL so full recovery "
844 {"log_checkpoints", PGC_SIGHUP, LOGGING_WHAT,
845 gettext_noop("Logs each checkpoint."),
853 {"log_connections", PGC_BACKEND, LOGGING_WHAT,
854 gettext_noop("Logs each successful connection."),
862 {"log_disconnections", PGC_BACKEND, LOGGING_WHAT,
863 gettext_noop("Logs end of a session, including duration."),
871 {"debug_assertions", PGC_USERSET, DEVELOPER_OPTIONS,
872 gettext_noop("Turns on various assertion checks."),
873 gettext_noop("This is a debugging aid."),
877 #ifdef USE_ASSERT_CHECKING
882 check_debug_assertions, NULL, NULL
886 {"exit_on_error", PGC_USERSET, ERROR_HANDLING_OPTIONS,
887 gettext_noop("Terminate session on any error."),
895 {"restart_after_crash", PGC_SIGHUP, ERROR_HANDLING_OPTIONS,
896 gettext_noop("Reinitialize server after backend crash."),
899 &restart_after_crash,
905 {"log_duration", PGC_SUSET, LOGGING_WHAT,
906 gettext_noop("Logs the duration of each completed SQL statement."),
914 {"debug_print_parse", PGC_USERSET, LOGGING_WHAT,
915 gettext_noop("Logs each query's parse tree."),
923 {"debug_print_rewritten", PGC_USERSET, LOGGING_WHAT,
924 gettext_noop("Logs each query's rewritten parse tree."),
927 &Debug_print_rewritten,
932 {"debug_print_plan", PGC_USERSET, LOGGING_WHAT,
933 gettext_noop("Logs each query's execution plan."),
941 {"debug_pretty_print", PGC_USERSET, LOGGING_WHAT,
942 gettext_noop("Indents parse and plan tree displays."),
950 {"log_parser_stats", PGC_SUSET, STATS_MONITORING,
951 gettext_noop("Writes parser performance statistics to the server log."),
956 check_stage_log_stats, NULL, NULL
959 {"log_planner_stats", PGC_SUSET, STATS_MONITORING,
960 gettext_noop("Writes planner performance statistics to the server log."),
965 check_stage_log_stats, NULL, NULL
968 {"log_executor_stats", PGC_SUSET, STATS_MONITORING,
969 gettext_noop("Writes executor performance statistics to the server log."),
974 check_stage_log_stats, NULL, NULL
977 {"log_statement_stats", PGC_SUSET, STATS_MONITORING,
978 gettext_noop("Writes cumulative performance statistics to the server log."),
981 &log_statement_stats,
983 check_log_stats, NULL, NULL
985 #ifdef BTREE_BUILD_STATS
987 {"log_btree_build_stats", PGC_SUSET, DEVELOPER_OPTIONS,
988 gettext_noop("No description available."),
992 &log_btree_build_stats,
999 {"track_activities", PGC_SUSET, STATS_COLLECTOR,
1000 gettext_noop("Collects information about executing commands."),
1001 gettext_noop("Enables the collection of information on the currently "
1002 "executing command of each session, along with "
1003 "the time at which that command began execution.")
1005 &pgstat_track_activities,
1010 {"track_counts", PGC_SUSET, STATS_COLLECTOR,
1011 gettext_noop("Collects statistics on database activity."),
1014 &pgstat_track_counts,
1020 {"update_process_title", PGC_SUSET, STATS_COLLECTOR,
1021 gettext_noop("Updates the process title to show the active SQL command."),
1022 gettext_noop("Enables updating of the process title every time a new SQL command is received by the server.")
1024 &update_process_title,
1030 {"autovacuum", PGC_SIGHUP, AUTOVACUUM,
1031 gettext_noop("Starts the autovacuum subprocess."),
1034 &autovacuum_start_daemon,
1040 {"trace_notify", PGC_USERSET, DEVELOPER_OPTIONS,
1041 gettext_noop("Generates debugging output for LISTEN and NOTIFY."),
1052 {"trace_locks", PGC_SUSET, DEVELOPER_OPTIONS,
1053 gettext_noop("No description available."),
1062 {"trace_lwlocks", PGC_SUSET, DEVELOPER_OPTIONS,
1063 gettext_noop("No description available."),
1072 {"debug_deadlocks", PGC_SUSET, DEVELOPER_OPTIONS,
1073 gettext_noop("No description available."),
1084 {"log_lock_waits", PGC_SUSET, LOGGING_WHAT,
1085 gettext_noop("Logs long lock waits."),
1094 {"log_hostname", PGC_SIGHUP, LOGGING_WHAT,
1095 gettext_noop("Logs the host name in the connection logs."),
1096 gettext_noop("By default, connection logs only show the IP address "
1097 "of the connecting host. If you want them to show the host name you "
1098 "can turn this on, but depending on your host name resolution "
1099 "setup it might impose a non-negligible performance penalty.")
1106 {"sql_inheritance", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1107 gettext_noop("Causes subtables to be included by default in various commands."),
1115 {"password_encryption", PGC_USERSET, CONN_AUTH_SECURITY,
1116 gettext_noop("Encrypt passwords."),
1117 gettext_noop("When a password is specified in CREATE USER or "
1118 "ALTER USER without writing either ENCRYPTED or UNENCRYPTED, "
1119 "this parameter determines whether the password is to be encrypted.")
1121 &Password_encryption,
1126 {"transform_null_equals", PGC_USERSET, COMPAT_OPTIONS_CLIENT,
1127 gettext_noop("Treats \"expr=NULL\" as \"expr IS NULL\"."),
1128 gettext_noop("When turned on, expressions of the form expr = NULL "
1129 "(or NULL = expr) are treated as expr IS NULL, that is, they "
1130 "return true if expr evaluates to the null value, and false "
1131 "otherwise. The correct behavior of expr = NULL is to always "
1132 "return null (unknown).")
1134 &Transform_null_equals,
1139 {"db_user_namespace", PGC_SIGHUP, CONN_AUTH_SECURITY,
1140 gettext_noop("Enables per-database user names."),
1148 /* only here for backwards compatibility */
1149 {"autocommit", PGC_USERSET, CLIENT_CONN_STATEMENT,
1150 gettext_noop("This parameter doesn't do anything."),
1151 gettext_noop("It's just here so that we won't choke on SET AUTOCOMMIT TO ON from 7.3-vintage clients."),
1152 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
1156 check_phony_autocommit, NULL, NULL
1159 {"default_transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
1160 gettext_noop("Sets the default read-only status of new transactions."),
1163 &DefaultXactReadOnly,
1168 {"transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
1169 gettext_noop("Sets the current transaction's read-only status."),
1171 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1175 check_transaction_read_only, NULL, NULL
1178 {"default_transaction_deferrable", PGC_USERSET, CLIENT_CONN_STATEMENT,
1179 gettext_noop("Sets the default deferrable status of new transactions."),
1182 &DefaultXactDeferrable,
1187 {"transaction_deferrable", PGC_USERSET, CLIENT_CONN_STATEMENT,
1188 gettext_noop("Whether to defer a read-only serializable transaction until it can be executed with no possible serialization failures."),
1190 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1194 check_transaction_deferrable, NULL, NULL
1197 {"check_function_bodies", PGC_USERSET, CLIENT_CONN_STATEMENT,
1198 gettext_noop("Check function bodies during CREATE FUNCTION."),
1201 &check_function_bodies,
1206 {"array_nulls", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1207 gettext_noop("Enable input of NULL elements in arrays."),
1208 gettext_noop("When turned on, unquoted NULL in an array input "
1209 "value means a null value; "
1210 "otherwise it is taken literally.")
1217 {"default_with_oids", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1218 gettext_noop("Create new tables with OIDs by default."),
1226 {"logging_collector", PGC_POSTMASTER, LOGGING_WHERE,
1227 gettext_noop("Start a subprocess to capture stderr output and/or csvlogs into log files."),
1235 {"log_truncate_on_rotation", PGC_SIGHUP, LOGGING_WHERE,
1236 gettext_noop("Truncate existing log files of same name during log rotation."),
1239 &Log_truncate_on_rotation,
1246 {"trace_sort", PGC_USERSET, DEVELOPER_OPTIONS,
1247 gettext_noop("Emit information about resource usage in sorting."),
1257 #ifdef TRACE_SYNCSCAN
1258 /* this is undocumented because not exposed in a standard build */
1260 {"trace_syncscan", PGC_USERSET, DEVELOPER_OPTIONS,
1261 gettext_noop("Generate debugging output for synchronized scanning."),
1271 #ifdef DEBUG_BOUNDED_SORT
1272 /* this is undocumented because not exposed in a standard build */
1275 "optimize_bounded_sort", PGC_USERSET, QUERY_TUNING_METHOD,
1276 gettext_noop("Enable bounded sorting using heap sort."),
1280 &optimize_bounded_sort,
1288 {"wal_debug", PGC_SUSET, DEVELOPER_OPTIONS,
1289 gettext_noop("Emit WAL-related debugging output."),
1300 {"integer_datetimes", PGC_INTERNAL, PRESET_OPTIONS,
1301 gettext_noop("Datetimes are integer based."),
1303 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1306 #ifdef HAVE_INT64_TIMESTAMP
1315 {"krb_caseins_users", PGC_SIGHUP, CONN_AUTH_SECURITY,
1316 gettext_noop("Sets whether Kerberos and GSSAPI user names should be treated as case-insensitive."),
1319 &pg_krb_caseins_users,
1325 {"escape_string_warning", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1326 gettext_noop("Warn about backslash escapes in ordinary string literals."),
1329 &escape_string_warning,
1335 {"standard_conforming_strings", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1336 gettext_noop("Causes '...' strings to treat backslashes literally."),
1340 &standard_conforming_strings,
1346 {"synchronize_seqscans", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1347 gettext_noop("Enable synchronized sequential scans."),
1350 &synchronize_seqscans,
1356 {"archive_mode", PGC_POSTMASTER, WAL_ARCHIVING,
1357 gettext_noop("Allows archiving of WAL files using archive_command."),
1366 {"hot_standby", PGC_POSTMASTER, REPLICATION_STANDBY,
1367 gettext_noop("Allows connections and queries during recovery."),
1376 {"hot_standby_feedback", PGC_SIGHUP, REPLICATION_STANDBY,
1377 gettext_noop("Allows feedback from a hot standby to the primary that will avoid query conflicts."),
1380 &hot_standby_feedback,
1386 {"allow_system_table_mods", PGC_POSTMASTER, DEVELOPER_OPTIONS,
1387 gettext_noop("Allows modifications of the structure of system tables."),
1391 &allowSystemTableMods,
1397 {"ignore_system_indexes", PGC_BACKEND, DEVELOPER_OPTIONS,
1398 gettext_noop("Disables reading from system indexes."),
1399 gettext_noop("It does not prevent updating the indexes, so it is safe "
1400 "to use. The worst consequence is slowness."),
1403 &IgnoreSystemIndexes,
1409 {"lo_compat_privileges", PGC_SUSET, COMPAT_OPTIONS_PREVIOUS,
1410 gettext_noop("Enables backward compatibility mode for privilege checks on large objects."),
1411 gettext_noop("Skips privilege checks when reading or modifying large objects, "
1412 "for compatibility with PostgreSQL releases prior to 9.0.")
1414 &lo_compat_privileges,
1420 {"quote_all_identifiers", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1421 gettext_noop("When generating SQL fragments, quote all identifiers."),
1424 "e_all_identifiers,
1429 /* End-of-list marker */
1431 {NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL, NULL
1436 static struct config_int ConfigureNamesInt[] =
1439 {"archive_timeout", PGC_SIGHUP, WAL_ARCHIVING,
1440 gettext_noop("Forces a switch to the next xlog file if a "
1441 "new file has not been started within N seconds."),
1445 &XLogArchiveTimeout,
1450 {"post_auth_delay", PGC_BACKEND, DEVELOPER_OPTIONS,
1451 gettext_noop("Waits N seconds on connection startup after authentication."),
1452 gettext_noop("This allows attaching a debugger to the process."),
1453 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1460 {"default_statistics_target", PGC_USERSET, QUERY_TUNING_OTHER,
1461 gettext_noop("Sets the default statistics target."),
1462 gettext_noop("This applies to table columns that have not had a "
1463 "column-specific target set via ALTER TABLE SET STATISTICS.")
1465 &default_statistics_target,
1470 {"from_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1471 gettext_noop("Sets the FROM-list size beyond which subqueries "
1472 "are not collapsed."),
1473 gettext_noop("The planner will merge subqueries into upper "
1474 "queries if the resulting FROM list would have no more than "
1477 &from_collapse_limit,
1482 {"join_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1483 gettext_noop("Sets the FROM-list size beyond which JOIN "
1484 "constructs are not flattened."),
1485 gettext_noop("The planner will flatten explicit JOIN "
1486 "constructs into lists of FROM items whenever a "
1487 "list of no more than this many items would result.")
1489 &join_collapse_limit,
1494 {"geqo_threshold", PGC_USERSET, QUERY_TUNING_GEQO,
1495 gettext_noop("Sets the threshold of FROM items beyond which GEQO is used."),
1503 {"geqo_effort", PGC_USERSET, QUERY_TUNING_GEQO,
1504 gettext_noop("GEQO: effort is used to set the default for other GEQO parameters."),
1508 DEFAULT_GEQO_EFFORT, MIN_GEQO_EFFORT, MAX_GEQO_EFFORT,
1512 {"geqo_pool_size", PGC_USERSET, QUERY_TUNING_GEQO,
1513 gettext_noop("GEQO: number of individuals in the population."),
1514 gettext_noop("Zero selects a suitable default value.")
1521 {"geqo_generations", PGC_USERSET, QUERY_TUNING_GEQO,
1522 gettext_noop("GEQO: number of iterations of the algorithm."),
1523 gettext_noop("Zero selects a suitable default value.")
1531 /* This is PGC_SUSET to prevent hiding from log_lock_waits. */
1532 {"deadlock_timeout", PGC_SUSET, LOCK_MANAGEMENT,
1533 gettext_noop("Sets the time to wait on a lock before checking for deadlock."),
1543 {"max_standby_archive_delay", PGC_SIGHUP, REPLICATION_STANDBY,
1544 gettext_noop("Sets the maximum delay before canceling queries when a hot standby server is processing archived WAL data."),
1548 &max_standby_archive_delay,
1549 30 * 1000, -1, INT_MAX,
1554 {"max_standby_streaming_delay", PGC_SIGHUP, REPLICATION_STANDBY,
1555 gettext_noop("Sets the maximum delay before canceling queries when a hot standby server is processing streamed WAL data."),
1559 &max_standby_streaming_delay,
1560 30 * 1000, -1, INT_MAX,
1565 {"wal_receiver_status_interval", PGC_SIGHUP, REPLICATION_STANDBY,
1566 gettext_noop("Sets the maximum interval between WAL receiver status reports to the primary."),
1570 &wal_receiver_status_interval,
1571 10, 0, INT_MAX / 1000,
1576 {"max_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1577 gettext_noop("Sets the maximum number of concurrent connections."),
1581 100, 1, MAX_BACKENDS,
1582 check_maxconnections, assign_maxconnections, NULL
1586 {"superuser_reserved_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1587 gettext_noop("Sets the number of connection slots reserved for superusers."),
1596 * We sometimes multiply the number of shared buffers by two without
1597 * checking for overflow, so we mustn't allow more than INT_MAX / 2.
1600 {"shared_buffers", PGC_POSTMASTER, RESOURCES_MEM,
1601 gettext_noop("Sets the number of shared memory buffers used by the server."),
1606 1024, 16, INT_MAX / 2,
1611 {"temp_buffers", PGC_USERSET, RESOURCES_MEM,
1612 gettext_noop("Sets the maximum number of temporary buffers used by each session."),
1617 1024, 100, INT_MAX / 2,
1618 check_temp_buffers, NULL, NULL
1622 {"port", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1623 gettext_noop("Sets the TCP port the server listens on."),
1627 DEF_PGPORT, 1, 65535,
1632 {"unix_socket_permissions", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1633 gettext_noop("Sets the access permissions of the Unix-domain socket."),
1634 gettext_noop("Unix-domain sockets use the usual Unix file system "
1635 "permission set. The parameter value is expected "
1636 "to be a numeric mode specification in the form "
1637 "accepted by the chmod and umask system calls. "
1638 "(To use the customary octal format the number must "
1639 "start with a 0 (zero).)")
1641 &Unix_socket_permissions,
1643 NULL, NULL, show_unix_socket_permissions
1647 {"log_file_mode", PGC_SIGHUP, LOGGING_WHERE,
1648 gettext_noop("Sets the file permissions for log files."),
1649 gettext_noop("The parameter value is expected "
1650 "to be a numeric mode specification in the form "
1651 "accepted by the chmod and umask system calls. "
1652 "(To use the customary octal format the number must "
1653 "start with a 0 (zero).)")
1657 NULL, NULL, show_log_file_mode
1661 {"work_mem", PGC_USERSET, RESOURCES_MEM,
1662 gettext_noop("Sets the maximum memory to be used for query workspaces."),
1663 gettext_noop("This much memory can be used by each internal "
1664 "sort operation and hash table before switching to "
1665 "temporary disk files."),
1669 1024, 64, MAX_KILOBYTES,
1674 {"maintenance_work_mem", PGC_USERSET, RESOURCES_MEM,
1675 gettext_noop("Sets the maximum memory to be used for maintenance operations."),
1676 gettext_noop("This includes operations such as VACUUM and CREATE INDEX."),
1679 &maintenance_work_mem,
1680 16384, 1024, MAX_KILOBYTES,
1685 * We use the hopefully-safely-small value of 100kB as the compiled-in
1686 * default for max_stack_depth. InitializeGUCOptions will increase it if
1687 * possible, depending on the actual platform-specific stack limit.
1690 {"max_stack_depth", PGC_SUSET, RESOURCES_MEM,
1691 gettext_noop("Sets the maximum stack depth, in kilobytes."),
1696 100, 100, MAX_KILOBYTES,
1697 check_max_stack_depth, assign_max_stack_depth, NULL
1701 {"temp_file_limit", PGC_SUSET, RESOURCES_DISK,
1702 gettext_noop("Limits the total size of all temp files used by each session."),
1703 gettext_noop("-1 means no limit."),
1712 {"vacuum_cost_page_hit", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1713 gettext_noop("Vacuum cost for a page found in the buffer cache."),
1722 {"vacuum_cost_page_miss", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1723 gettext_noop("Vacuum cost for a page not found in the buffer cache."),
1726 &VacuumCostPageMiss,
1732 {"vacuum_cost_page_dirty", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1733 gettext_noop("Vacuum cost for a page dirtied by vacuum."),
1736 &VacuumCostPageDirty,
1742 {"vacuum_cost_limit", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1743 gettext_noop("Vacuum cost amount available before napping."),
1752 {"vacuum_cost_delay", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1753 gettext_noop("Vacuum cost delay in milliseconds."),
1763 {"autovacuum_vacuum_cost_delay", PGC_SIGHUP, AUTOVACUUM,
1764 gettext_noop("Vacuum cost delay in milliseconds, for autovacuum."),
1768 &autovacuum_vac_cost_delay,
1774 {"autovacuum_vacuum_cost_limit", PGC_SIGHUP, AUTOVACUUM,
1775 gettext_noop("Vacuum cost amount available before napping, for autovacuum."),
1778 &autovacuum_vac_cost_limit,
1784 {"max_files_per_process", PGC_POSTMASTER, RESOURCES_KERNEL,
1785 gettext_noop("Sets the maximum number of simultaneously open files for each server process."),
1788 &max_files_per_process,
1794 * See also CheckRequiredParameterValues() if this parameter changes
1797 {"max_prepared_transactions", PGC_POSTMASTER, RESOURCES_MEM,
1798 gettext_noop("Sets the maximum number of simultaneously prepared transactions."),
1801 &max_prepared_xacts,
1808 {"trace_lock_oidmin", PGC_SUSET, DEVELOPER_OPTIONS,
1809 gettext_noop("No description available."),
1814 FirstNormalObjectId, 0, INT_MAX,
1818 {"trace_lock_table", PGC_SUSET, DEVELOPER_OPTIONS,
1819 gettext_noop("No description available."),
1830 {"statement_timeout", PGC_USERSET, CLIENT_CONN_STATEMENT,
1831 gettext_noop("Sets the maximum allowed duration of any statement."),
1832 gettext_noop("A value of 0 turns off the timeout."),
1841 {"vacuum_freeze_min_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1842 gettext_noop("Minimum age at which VACUUM should freeze a table row."),
1845 &vacuum_freeze_min_age,
1846 50000000, 0, 1000000000,
1851 {"vacuum_freeze_table_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1852 gettext_noop("Age at which VACUUM should scan whole table to freeze tuples."),
1855 &vacuum_freeze_table_age,
1856 150000000, 0, 2000000000,
1861 {"vacuum_defer_cleanup_age", PGC_SIGHUP, REPLICATION_MASTER,
1862 gettext_noop("Number of transactions by which VACUUM and HOT cleanup should be deferred, if any."),
1865 &vacuum_defer_cleanup_age,
1871 * See also CheckRequiredParameterValues() if this parameter changes
1874 {"max_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
1875 gettext_noop("Sets the maximum number of locks per transaction."),
1876 gettext_noop("The shared lock table is sized on the assumption that "
1877 "at most max_locks_per_transaction * max_connections distinct "
1878 "objects will need to be locked at any one time.")
1880 &max_locks_per_xact,
1886 {"max_pred_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
1887 gettext_noop("Sets the maximum number of predicate locks per transaction."),
1888 gettext_noop("The shared predicate lock table is sized on the assumption that "
1889 "at most max_pred_locks_per_transaction * max_connections distinct "
1890 "objects will need to be locked at any one time.")
1892 &max_predicate_locks_per_xact,
1898 {"authentication_timeout", PGC_SIGHUP, CONN_AUTH_SECURITY,
1899 gettext_noop("Sets the maximum allowed time to complete client authentication."),
1903 &AuthenticationTimeout,
1909 /* Not for general use */
1910 {"pre_auth_delay", PGC_SIGHUP, DEVELOPER_OPTIONS,
1911 gettext_noop("Waits N seconds on connection startup before authentication."),
1912 gettext_noop("This allows attaching a debugger to the process."),
1913 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1921 {"wal_keep_segments", PGC_SIGHUP, REPLICATION_SENDING,
1922 gettext_noop("Sets the number of WAL files held for standby servers."),
1931 {"checkpoint_segments", PGC_SIGHUP, WAL_CHECKPOINTS,
1932 gettext_noop("Sets the maximum distance in log segments between automatic WAL checkpoints."),
1935 &CheckPointSegments,
1941 {"checkpoint_timeout", PGC_SIGHUP, WAL_CHECKPOINTS,
1942 gettext_noop("Sets the maximum time between automatic WAL checkpoints."),
1952 {"checkpoint_warning", PGC_SIGHUP, WAL_CHECKPOINTS,
1953 gettext_noop("Enables warnings if checkpoint segments are filled more "
1954 "frequently than this."),
1955 gettext_noop("Write a message to the server log if checkpoints "
1956 "caused by the filling of checkpoint segment files happens more "
1957 "frequently than this number of seconds. Zero turns off the warning."),
1966 {"wal_buffers", PGC_POSTMASTER, WAL_SETTINGS,
1967 gettext_noop("Sets the number of disk-page buffers in shared memory for WAL."),
1973 check_wal_buffers, NULL, NULL
1977 {"wal_writer_delay", PGC_SIGHUP, WAL_SETTINGS,
1978 gettext_noop("WAL writer sleep time between WAL flushes."),
1988 /* see max_connections */
1989 {"max_wal_senders", PGC_POSTMASTER, REPLICATION_SENDING,
1990 gettext_noop("Sets the maximum number of simultaneously running WAL sender processes."),
1999 {"replication_timeout", PGC_SIGHUP, REPLICATION_SENDING,
2000 gettext_noop("Sets the maximum time to wait for WAL replication."),
2004 &replication_timeout,
2005 60 * 1000, 0, INT_MAX,
2010 {"commit_delay", PGC_USERSET, WAL_SETTINGS,
2011 gettext_noop("Sets the delay in microseconds between transaction commit and "
2012 "flushing WAL to disk."),
2021 {"commit_siblings", PGC_USERSET, WAL_SETTINGS,
2022 gettext_noop("Sets the minimum concurrent open transactions before performing "
2032 {"extra_float_digits", PGC_USERSET, CLIENT_CONN_LOCALE,
2033 gettext_noop("Sets the number of digits displayed for floating-point values."),
2034 gettext_noop("This affects real, double precision, and geometric data types. "
2035 "The parameter value is added to the standard number of digits "
2036 "(FLT_DIG or DBL_DIG as appropriate).")
2038 &extra_float_digits,
2044 {"log_min_duration_statement", PGC_SUSET, LOGGING_WHEN,
2045 gettext_noop("Sets the minimum execution time above which "
2046 "statements will be logged."),
2047 gettext_noop("Zero prints all queries. -1 turns this feature off."),
2050 &log_min_duration_statement,
2056 {"log_autovacuum_min_duration", PGC_SIGHUP, LOGGING_WHAT,
2057 gettext_noop("Sets the minimum execution time above which "
2058 "autovacuum actions will be logged."),
2059 gettext_noop("Zero prints all actions. -1 turns autovacuum logging off."),
2062 &Log_autovacuum_min_duration,
2068 {"bgwriter_delay", PGC_SIGHUP, RESOURCES_BGWRITER,
2069 gettext_noop("Background writer sleep time between rounds."),
2079 {"bgwriter_lru_maxpages", PGC_SIGHUP, RESOURCES_BGWRITER,
2080 gettext_noop("Background writer maximum number of LRU pages to flush per round."),
2083 &bgwriter_lru_maxpages,
2089 {"effective_io_concurrency",
2095 RESOURCES_ASYNCHRONOUS,
2096 gettext_noop("Number of simultaneous requests that can be handled efficiently by the disk subsystem."),
2097 gettext_noop("For RAID arrays, this should be approximately the number of drive spindles in the array.")
2099 &effective_io_concurrency,
2105 check_effective_io_concurrency, assign_effective_io_concurrency, NULL
2109 {"log_rotation_age", PGC_SIGHUP, LOGGING_WHERE,
2110 gettext_noop("Automatic log file rotation will occur after N minutes."),
2115 HOURS_PER_DAY * MINS_PER_HOUR, 0, INT_MAX / MINS_PER_HOUR,
2120 {"log_rotation_size", PGC_SIGHUP, LOGGING_WHERE,
2121 gettext_noop("Automatic log file rotation will occur after N kilobytes."),
2126 10 * 1024, 0, INT_MAX / 1024,
2131 {"max_function_args", PGC_INTERNAL, PRESET_OPTIONS,
2132 gettext_noop("Shows the maximum number of function arguments."),
2134 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2137 FUNC_MAX_ARGS, FUNC_MAX_ARGS, FUNC_MAX_ARGS,
2142 {"max_index_keys", PGC_INTERNAL, PRESET_OPTIONS,
2143 gettext_noop("Shows the maximum number of index keys."),
2145 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2148 INDEX_MAX_KEYS, INDEX_MAX_KEYS, INDEX_MAX_KEYS,
2153 {"max_identifier_length", PGC_INTERNAL, PRESET_OPTIONS,
2154 gettext_noop("Shows the maximum identifier length."),
2156 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2158 &max_identifier_length,
2159 NAMEDATALEN - 1, NAMEDATALEN - 1, NAMEDATALEN - 1,
2164 {"block_size", PGC_INTERNAL, PRESET_OPTIONS,
2165 gettext_noop("Shows the size of a disk block."),
2167 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2170 BLCKSZ, BLCKSZ, BLCKSZ,
2175 {"segment_size", PGC_INTERNAL, PRESET_OPTIONS,
2176 gettext_noop("Shows the number of pages per disk file."),
2178 GUC_UNIT_BLOCKS | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2181 RELSEG_SIZE, RELSEG_SIZE, RELSEG_SIZE,
2186 {"wal_block_size", PGC_INTERNAL, PRESET_OPTIONS,
2187 gettext_noop("Shows the block size in the write ahead log."),
2189 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2192 XLOG_BLCKSZ, XLOG_BLCKSZ, XLOG_BLCKSZ,
2197 {"wal_segment_size", PGC_INTERNAL, PRESET_OPTIONS,
2198 gettext_noop("Shows the number of pages per write ahead log segment."),
2200 GUC_UNIT_XBLOCKS | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2203 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
2204 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
2205 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
2210 {"autovacuum_naptime", PGC_SIGHUP, AUTOVACUUM,
2211 gettext_noop("Time to sleep between autovacuum runs."),
2215 &autovacuum_naptime,
2216 60, 1, INT_MAX / 1000,
2220 {"autovacuum_vacuum_threshold", PGC_SIGHUP, AUTOVACUUM,
2221 gettext_noop("Minimum number of tuple updates or deletes prior to vacuum."),
2224 &autovacuum_vac_thresh,
2229 {"autovacuum_analyze_threshold", PGC_SIGHUP, AUTOVACUUM,
2230 gettext_noop("Minimum number of tuple inserts, updates or deletes prior to analyze."),
2233 &autovacuum_anl_thresh,
2238 /* see varsup.c for why this is PGC_POSTMASTER not PGC_SIGHUP */
2239 {"autovacuum_freeze_max_age", PGC_POSTMASTER, AUTOVACUUM,
2240 gettext_noop("Age at which to autovacuum a table to prevent transaction ID wraparound."),
2243 &autovacuum_freeze_max_age,
2244 /* see pg_resetxlog if you change the upper-limit value */
2245 200000000, 100000000, 2000000000,
2249 /* see max_connections */
2250 {"autovacuum_max_workers", PGC_POSTMASTER, AUTOVACUUM,
2251 gettext_noop("Sets the maximum number of simultaneously running autovacuum worker processes."),
2254 &autovacuum_max_workers,
2256 check_autovacuum_max_workers, assign_autovacuum_max_workers, NULL
2260 {"tcp_keepalives_idle", PGC_USERSET, CLIENT_CONN_OTHER,
2261 gettext_noop("Time between issuing TCP keepalives."),
2262 gettext_noop("A value of 0 uses the system default."),
2265 &tcp_keepalives_idle,
2267 NULL, assign_tcp_keepalives_idle, show_tcp_keepalives_idle
2271 {"tcp_keepalives_interval", PGC_USERSET, CLIENT_CONN_OTHER,
2272 gettext_noop("Time between TCP keepalive retransmits."),
2273 gettext_noop("A value of 0 uses the system default."),
2276 &tcp_keepalives_interval,
2278 NULL, assign_tcp_keepalives_interval, show_tcp_keepalives_interval
2282 {"ssl_renegotiation_limit", PGC_USERSET, CONN_AUTH_SECURITY,
2283 gettext_noop("Set the amount of traffic to send and receive before renegotiating the encryption keys."),
2287 &ssl_renegotiation_limit,
2288 512 * 1024, 0, MAX_KILOBYTES,
2293 {"tcp_keepalives_count", PGC_USERSET, CLIENT_CONN_OTHER,
2294 gettext_noop("Maximum number of TCP keepalive retransmits."),
2295 gettext_noop("This controls the number of consecutive keepalive retransmits that can be "
2296 "lost before a connection is considered dead. A value of 0 uses the "
2299 &tcp_keepalives_count,
2301 NULL, assign_tcp_keepalives_count, show_tcp_keepalives_count
2305 {"gin_fuzzy_search_limit", PGC_USERSET, CLIENT_CONN_OTHER,
2306 gettext_noop("Sets the maximum allowed result for exact search by GIN."),
2310 &GinFuzzySearchLimit,
2316 {"effective_cache_size", PGC_USERSET, QUERY_TUNING_COST,
2317 gettext_noop("Sets the planner's assumption about the size of the disk cache."),
2318 gettext_noop("That is, the portion of the kernel's disk cache that "
2319 "will be used for PostgreSQL data files. This is measured in disk "
2320 "pages, which are normally 8 kB each."),
2323 &effective_cache_size,
2324 DEFAULT_EFFECTIVE_CACHE_SIZE, 1, INT_MAX,
2329 /* Can't be set in postgresql.conf */
2330 {"server_version_num", PGC_INTERNAL, PRESET_OPTIONS,
2331 gettext_noop("Shows the server version as an integer."),
2333 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2335 &server_version_num,
2336 PG_VERSION_NUM, PG_VERSION_NUM, PG_VERSION_NUM,
2341 {"log_temp_files", PGC_SUSET, LOGGING_WHAT,
2342 gettext_noop("Log the use of temporary files larger than this number of kilobytes."),
2343 gettext_noop("Zero logs all files. The default is -1 (turning this feature off)."),
2352 {"track_activity_query_size", PGC_POSTMASTER, RESOURCES_MEM,
2353 gettext_noop("Sets the size reserved for pg_stat_activity.current_query, in bytes."),
2356 &pgstat_track_activity_query_size,
2361 /* End-of-list marker */
2363 {NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL, NULL
2368 static struct config_real ConfigureNamesReal[] =
2371 {"seq_page_cost", PGC_USERSET, QUERY_TUNING_COST,
2372 gettext_noop("Sets the planner's estimate of the cost of a "
2373 "sequentially fetched disk page."),
2377 DEFAULT_SEQ_PAGE_COST, 0, DBL_MAX,
2381 {"random_page_cost", PGC_USERSET, QUERY_TUNING_COST,
2382 gettext_noop("Sets the planner's estimate of the cost of a "
2383 "nonsequentially fetched disk page."),
2387 DEFAULT_RANDOM_PAGE_COST, 0, DBL_MAX,
2391 {"cpu_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
2392 gettext_noop("Sets the planner's estimate of the cost of "
2393 "processing each tuple (row)."),
2397 DEFAULT_CPU_TUPLE_COST, 0, DBL_MAX,
2401 {"cpu_index_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
2402 gettext_noop("Sets the planner's estimate of the cost of "
2403 "processing each index entry during an index scan."),
2406 &cpu_index_tuple_cost,
2407 DEFAULT_CPU_INDEX_TUPLE_COST, 0, DBL_MAX,
2411 {"cpu_operator_cost", PGC_USERSET, QUERY_TUNING_COST,
2412 gettext_noop("Sets the planner's estimate of the cost of "
2413 "processing each operator or function call."),
2417 DEFAULT_CPU_OPERATOR_COST, 0, DBL_MAX,
2422 {"cursor_tuple_fraction", PGC_USERSET, QUERY_TUNING_OTHER,
2423 gettext_noop("Sets the planner's estimate of the fraction of "
2424 "a cursor's rows that will be retrieved."),
2427 &cursor_tuple_fraction,
2428 DEFAULT_CURSOR_TUPLE_FRACTION, 0.0, 1.0,
2433 {"geqo_selection_bias", PGC_USERSET, QUERY_TUNING_GEQO,
2434 gettext_noop("GEQO: selective pressure within the population."),
2437 &Geqo_selection_bias,
2438 DEFAULT_GEQO_SELECTION_BIAS,
2439 MIN_GEQO_SELECTION_BIAS, MAX_GEQO_SELECTION_BIAS,
2443 {"geqo_seed", PGC_USERSET, QUERY_TUNING_GEQO,
2444 gettext_noop("GEQO: seed for random path selection."),
2453 {"bgwriter_lru_multiplier", PGC_SIGHUP, RESOURCES_BGWRITER,
2454 gettext_noop("Multiple of the average buffer usage to free per round."),
2457 &bgwriter_lru_multiplier,
2463 {"seed", PGC_USERSET, UNGROUPED,
2464 gettext_noop("Sets the seed for random-number generation."),
2466 GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2470 check_random_seed, assign_random_seed, show_random_seed
2474 {"autovacuum_vacuum_scale_factor", PGC_SIGHUP, AUTOVACUUM,
2475 gettext_noop("Number of tuple updates or deletes prior to vacuum as a fraction of reltuples."),
2478 &autovacuum_vac_scale,
2483 {"autovacuum_analyze_scale_factor", PGC_SIGHUP, AUTOVACUUM,
2484 gettext_noop("Number of tuple inserts, updates or deletes prior to analyze as a fraction of reltuples."),
2487 &autovacuum_anl_scale,
2493 {"checkpoint_completion_target", PGC_SIGHUP, WAL_CHECKPOINTS,
2494 gettext_noop("Time spent flushing dirty buffers during checkpoint, as fraction of checkpoint interval."),
2497 &CheckPointCompletionTarget,
2502 /* End-of-list marker */
2504 {NULL, 0, 0, NULL, NULL}, NULL, 0.0, 0.0, 0.0, NULL, NULL, NULL
2509 static struct config_string ConfigureNamesString[] =
2512 {"archive_command", PGC_SIGHUP, WAL_ARCHIVING,
2513 gettext_noop("Sets the shell command that will be called to archive a WAL file."),
2516 &XLogArchiveCommand,
2518 NULL, NULL, show_archive_command
2522 {"client_encoding", PGC_USERSET, CLIENT_CONN_LOCALE,
2523 gettext_noop("Sets the client's character set encoding."),
2525 GUC_IS_NAME | GUC_REPORT
2527 &client_encoding_string,
2529 check_client_encoding, assign_client_encoding, NULL
2533 {"log_line_prefix", PGC_SIGHUP, LOGGING_WHAT,
2534 gettext_noop("Controls information prefixed to each log line."),
2535 gettext_noop("If blank, no prefix is used.")
2543 {"log_timezone", PGC_SIGHUP, LOGGING_WHAT,
2544 gettext_noop("Sets the time zone to use in log messages."),
2547 &log_timezone_string,
2549 check_log_timezone, assign_log_timezone, show_log_timezone
2553 {"DateStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
2554 gettext_noop("Sets the display format for date and time values."),
2555 gettext_noop("Also controls interpretation of ambiguous "
2557 GUC_LIST_INPUT | GUC_REPORT
2561 check_datestyle, assign_datestyle, NULL
2565 {"default_tablespace", PGC_USERSET, CLIENT_CONN_STATEMENT,
2566 gettext_noop("Sets the default tablespace to create tables and indexes in."),
2567 gettext_noop("An empty string selects the database's default tablespace."),
2570 &default_tablespace,
2572 check_default_tablespace, NULL, NULL
2576 {"temp_tablespaces", PGC_USERSET, CLIENT_CONN_STATEMENT,
2577 gettext_noop("Sets the tablespace(s) to use for temporary tables and sort files."),
2579 GUC_LIST_INPUT | GUC_LIST_QUOTE
2583 check_temp_tablespaces, assign_temp_tablespaces, NULL
2587 {"dynamic_library_path", PGC_SUSET, CLIENT_CONN_OTHER,
2588 gettext_noop("Sets the path for dynamically loadable modules."),
2589 gettext_noop("If a dynamically loadable module needs to be opened and "
2590 "the specified name does not have a directory component (i.e., the "
2591 "name does not contain a slash), the system will search this path for "
2592 "the specified file."),
2595 &Dynamic_library_path,
2601 {"krb_server_keyfile", PGC_SIGHUP, CONN_AUTH_SECURITY,
2602 gettext_noop("Sets the location of the Kerberos server key file."),
2606 &pg_krb_server_keyfile,
2612 {"krb_srvname", PGC_SIGHUP, CONN_AUTH_SECURITY,
2613 gettext_noop("Sets the name of the Kerberos service."),
2622 {"bonjour_name", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2623 gettext_noop("Sets the Bonjour service name."),
2631 /* See main.c about why defaults for LC_foo are not all alike */
2634 {"lc_collate", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2635 gettext_noop("Shows the collation order locale."),
2637 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2645 {"lc_ctype", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2646 gettext_noop("Shows the character classification and case conversion locale."),
2648 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2656 {"lc_messages", PGC_SUSET, CLIENT_CONN_LOCALE,
2657 gettext_noop("Sets the language in which messages are displayed."),
2662 check_locale_messages, assign_locale_messages, NULL
2666 {"lc_monetary", PGC_USERSET, CLIENT_CONN_LOCALE,
2667 gettext_noop("Sets the locale for formatting monetary amounts."),
2672 check_locale_monetary, assign_locale_monetary, NULL
2676 {"lc_numeric", PGC_USERSET, CLIENT_CONN_LOCALE,
2677 gettext_noop("Sets the locale for formatting numbers."),
2682 check_locale_numeric, assign_locale_numeric, NULL
2686 {"lc_time", PGC_USERSET, CLIENT_CONN_LOCALE,
2687 gettext_noop("Sets the locale for formatting date and time values."),
2692 check_locale_time, assign_locale_time, NULL
2696 {"shared_preload_libraries", PGC_POSTMASTER, RESOURCES_KERNEL,
2697 gettext_noop("Lists shared libraries to preload into server."),
2699 GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
2701 &shared_preload_libraries_string,
2707 {"local_preload_libraries", PGC_BACKEND, CLIENT_CONN_OTHER,
2708 gettext_noop("Lists shared libraries to preload into each backend."),
2710 GUC_LIST_INPUT | GUC_LIST_QUOTE
2712 &local_preload_libraries_string,
2718 {"search_path", PGC_USERSET, CLIENT_CONN_STATEMENT,
2719 gettext_noop("Sets the schema search order for names that are not schema-qualified."),
2721 GUC_LIST_INPUT | GUC_LIST_QUOTE
2723 &namespace_search_path,
2725 check_search_path, assign_search_path, NULL
2729 /* Can't be set in postgresql.conf */
2730 {"server_encoding", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2731 gettext_noop("Sets the server (database) character set encoding."),
2733 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2735 &server_encoding_string,
2741 /* Can't be set in postgresql.conf */
2742 {"server_version", PGC_INTERNAL, PRESET_OPTIONS,
2743 gettext_noop("Shows the server version."),
2745 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2747 &server_version_string,
2753 /* Not for general use --- used by SET ROLE */
2754 {"role", PGC_USERSET, UNGROUPED,
2755 gettext_noop("Sets the current role."),
2757 GUC_IS_NAME | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_NOT_WHILE_SEC_REST
2761 check_role, assign_role, show_role
2765 /* Not for general use --- used by SET SESSION AUTHORIZATION */
2766 {"session_authorization", PGC_USERSET, UNGROUPED,
2767 gettext_noop("Sets the session user name."),
2769 GUC_IS_NAME | GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_NOT_WHILE_SEC_REST
2771 &session_authorization_string,
2773 check_session_authorization, assign_session_authorization, NULL
2777 {"log_destination", PGC_SIGHUP, LOGGING_WHERE,
2778 gettext_noop("Sets the destination for server log output."),
2779 gettext_noop("Valid values are combinations of \"stderr\", "
2780 "\"syslog\", \"csvlog\", and \"eventlog\", "
2781 "depending on the platform."),
2784 &log_destination_string,
2786 check_log_destination, assign_log_destination, NULL
2789 {"log_directory", PGC_SIGHUP, LOGGING_WHERE,
2790 gettext_noop("Sets the destination directory for log files."),
2791 gettext_noop("Can be specified as relative to the data directory "
2792 "or as absolute path."),
2797 check_canonical_path, NULL, NULL
2800 {"log_filename", PGC_SIGHUP, LOGGING_WHERE,
2801 gettext_noop("Sets the file name pattern for log files."),
2806 "postgresql-%Y-%m-%d_%H%M%S.log",
2811 {"syslog_ident", PGC_SIGHUP, LOGGING_WHERE,
2812 gettext_noop("Sets the program name used to identify PostgreSQL "
2813 "messages in syslog."),
2818 NULL, assign_syslog_ident, NULL
2822 {"TimeZone", PGC_USERSET, CLIENT_CONN_LOCALE,
2823 gettext_noop("Sets the time zone for displaying and interpreting time stamps."),
2829 check_timezone, assign_timezone, show_timezone
2832 {"timezone_abbreviations", PGC_USERSET, CLIENT_CONN_LOCALE,
2833 gettext_noop("Selects a file of time zone abbreviations."),
2836 &timezone_abbreviations_string,
2838 check_timezone_abbreviations, assign_timezone_abbreviations, NULL
2842 {"transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
2843 gettext_noop("Sets the current transaction's isolation level."),
2845 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2847 &XactIsoLevel_string,
2849 check_XactIsoLevel, assign_XactIsoLevel, show_XactIsoLevel
2853 {"unix_socket_group", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2854 gettext_noop("Sets the owning group of the Unix-domain socket."),
2855 gettext_noop("The owning user of the socket is always the user "
2856 "that starts the server.")
2864 {"unix_socket_directory", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2865 gettext_noop("Sets the directory where the Unix-domain socket will be created."),
2871 check_canonical_path, NULL, NULL
2875 {"listen_addresses", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2876 gettext_noop("Sets the host name or IP address(es) to listen to."),
2886 {"data_directory", PGC_POSTMASTER, FILE_LOCATIONS,
2887 gettext_noop("Sets the server's data directory."),
2897 {"config_file", PGC_POSTMASTER, FILE_LOCATIONS,
2898 gettext_noop("Sets the server's main configuration file."),
2900 GUC_DISALLOW_IN_FILE | GUC_SUPERUSER_ONLY
2908 {"hba_file", PGC_POSTMASTER, FILE_LOCATIONS,
2909 gettext_noop("Sets the server's \"hba\" configuration file."),
2919 {"ident_file", PGC_POSTMASTER, FILE_LOCATIONS,
2920 gettext_noop("Sets the server's \"ident\" configuration file."),
2930 {"external_pid_file", PGC_POSTMASTER, FILE_LOCATIONS,
2931 gettext_noop("Writes the postmaster PID to the specified file."),
2937 check_canonical_path, NULL, NULL
2941 {"stats_temp_directory", PGC_SIGHUP, STATS_COLLECTOR,
2942 gettext_noop("Writes temporary statistics files to the specified directory."),
2946 &pgstat_temp_directory,
2948 check_canonical_path, assign_pgstat_temp_directory, NULL
2952 {"synchronous_standby_names", PGC_SIGHUP, REPLICATION_MASTER,
2953 gettext_noop("List of names of potential synchronous standbys."),
2957 &SyncRepStandbyNames,
2959 check_synchronous_standby_names, NULL, NULL
2963 {"default_text_search_config", PGC_USERSET, CLIENT_CONN_LOCALE,
2964 gettext_noop("Sets default text search configuration."),
2968 "pg_catalog.simple",
2969 check_TSCurrentConfig, assign_TSCurrentConfig, NULL
2973 {"ssl_ciphers", PGC_POSTMASTER, CONN_AUTH_SECURITY,
2974 gettext_noop("Sets the list of allowed SSL ciphers."),
2980 "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH",
2988 {"application_name", PGC_USERSET, LOGGING_WHAT,
2989 gettext_noop("Sets the application name to be reported in statistics and logs."),
2991 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE
2995 check_application_name, assign_application_name, NULL
2998 /* End-of-list marker */
3000 {NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL, NULL
3005 static struct config_enum ConfigureNamesEnum[] =
3008 {"backslash_quote", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
3009 gettext_noop("Sets whether \"\\'\" is allowed in string literals."),
3013 BACKSLASH_QUOTE_SAFE_ENCODING, backslash_quote_options,
3018 {"bytea_output", PGC_USERSET, CLIENT_CONN_STATEMENT,
3019 gettext_noop("Sets the output format for bytea."),
3023 BYTEA_OUTPUT_HEX, bytea_output_options,
3028 {"client_min_messages", PGC_USERSET, LOGGING_WHEN,
3029 gettext_noop("Sets the message levels that are sent to the client."),
3030 gettext_noop("Each level includes all the levels that follow it. The later"
3031 " the level, the fewer messages are sent.")
3033 &client_min_messages,
3034 NOTICE, client_message_level_options,
3039 {"constraint_exclusion", PGC_USERSET, QUERY_TUNING_OTHER,
3040 gettext_noop("Enables the planner to use constraints to optimize queries."),
3041 gettext_noop("Table scans will be skipped if their constraints"
3042 " guarantee that no rows match the query.")
3044 &constraint_exclusion,
3045 CONSTRAINT_EXCLUSION_PARTITION, constraint_exclusion_options,
3050 {"default_transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
3051 gettext_noop("Sets the transaction isolation level of each new transaction."),
3054 &DefaultXactIsoLevel,
3055 XACT_READ_COMMITTED, isolation_level_options,
3060 {"IntervalStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
3061 gettext_noop("Sets the display format for interval values."),
3066 INTSTYLE_POSTGRES, intervalstyle_options,
3071 {"log_error_verbosity", PGC_SUSET, LOGGING_WHAT,
3072 gettext_noop("Sets the verbosity of logged messages."),
3075 &Log_error_verbosity,
3076 PGERROR_DEFAULT, log_error_verbosity_options,
3081 {"log_min_messages", PGC_SUSET, LOGGING_WHEN,
3082 gettext_noop("Sets the message levels that are logged."),
3083 gettext_noop("Each level includes all the levels that follow it. The later"
3084 " the level, the fewer messages are sent.")
3087 WARNING, server_message_level_options,
3092 {"log_min_error_statement", PGC_SUSET, LOGGING_WHEN,
3093 gettext_noop("Causes all statements generating error at or above this level to be logged."),
3094 gettext_noop("Each level includes all the levels that follow it. The later"
3095 " the level, the fewer messages are sent.")
3097 &log_min_error_statement,
3098 ERROR, server_message_level_options,
3103 {"log_statement", PGC_SUSET, LOGGING_WHAT,
3104 gettext_noop("Sets the type of statements logged."),
3108 LOGSTMT_NONE, log_statement_options,
3113 {"syslog_facility", PGC_SIGHUP, LOGGING_WHERE,
3114 gettext_noop("Sets the syslog \"facility\" to be used when syslog enabled."),
3123 syslog_facility_options,
3124 NULL, assign_syslog_facility, NULL
3128 {"session_replication_role", PGC_SUSET, CLIENT_CONN_STATEMENT,
3129 gettext_noop("Sets the session's behavior for triggers and rewrite rules."),
3132 &SessionReplicationRole,
3133 SESSION_REPLICATION_ROLE_ORIGIN, session_replication_role_options,
3134 NULL, assign_session_replication_role, NULL
3138 {"synchronous_commit", PGC_USERSET, WAL_SETTINGS,
3139 gettext_noop("Sets the current transaction's synchronization level."),
3142 &synchronous_commit,
3143 SYNCHRONOUS_COMMIT_ON, synchronous_commit_options,
3148 {"trace_recovery_messages", PGC_SIGHUP, DEVELOPER_OPTIONS,
3149 gettext_noop("Enables logging of recovery-related debugging information."),
3150 gettext_noop("Each level includes all the levels that follow it. The later"
3151 " the level, the fewer messages are sent.")
3153 &trace_recovery_messages,
3156 * client_message_level_options allows too many values, really, but
3157 * it's not worth having a separate options array for this.
3159 LOG, client_message_level_options,
3164 {"track_functions", PGC_SUSET, STATS_COLLECTOR,
3165 gettext_noop("Collects function-level statistics on database activity."),
3168 &pgstat_track_functions,
3169 TRACK_FUNC_OFF, track_function_options,
3174 {"wal_level", PGC_POSTMASTER, WAL_SETTINGS,
3175 gettext_noop("Set the level of information written to the WAL."),
3179 WAL_LEVEL_MINIMAL, wal_level_options,
3184 {"wal_sync_method", PGC_SIGHUP, WAL_SETTINGS,
3185 gettext_noop("Selects the method used for forcing WAL updates to disk."),
3189 DEFAULT_SYNC_METHOD, sync_method_options,
3190 NULL, assign_xlog_sync_method, NULL
3194 {"xmlbinary", PGC_USERSET, CLIENT_CONN_STATEMENT,
3195 gettext_noop("Sets how binary values are to be encoded in XML."),
3199 XMLBINARY_BASE64, xmlbinary_options,
3204 {"xmloption", PGC_USERSET, CLIENT_CONN_STATEMENT,
3205 gettext_noop("Sets whether XML data in implicit parsing and serialization "
3206 "operations is to be considered as documents or content fragments."),
3210 XMLOPTION_CONTENT, xmloption_options,
3215 /* End-of-list marker */
3217 {NULL, 0, 0, NULL, NULL}, NULL, 0, NULL, NULL, NULL, NULL
3221 /******** end of options list ********/
3225 * To allow continued support of obsolete names for GUC variables, we apply
3226 * the following mappings to any unrecognized name. Note that an old name
3227 * should be mapped to a new one only if the new variable has very similar
3228 * semantics to the old.
3230 static const char *const map_old_guc_names[] = {
3231 "sort_mem", "work_mem",
3232 "vacuum_mem", "maintenance_work_mem",
3238 * Actual lookup of variables is done through this single, sorted array.
3240 static struct config_generic **guc_variables;
3242 /* Current number of variables contained in the vector */
3243 static int num_guc_variables;
3245 /* Vector capacity */
3246 static int size_guc_variables;
3249 static bool guc_dirty; /* TRUE if need to do commit/abort work */
3251 static bool reporting_enabled; /* TRUE to enable GUC_REPORT */
3253 static int GUCNestLevel = 0; /* 1 when in main transaction */
3256 static int guc_var_compare(const void *a, const void *b);
3257 static int guc_name_compare(const char *namea, const char *nameb);
3258 static void InitializeGUCOptionsFromEnvironment(void);
3259 static void InitializeOneGUCOption(struct config_generic * gconf);
3260 static void push_old_value(struct config_generic * gconf, GucAction action);
3261 static void ReportGUCOption(struct config_generic * record);
3262 static void reapply_stacked_values(struct config_generic * variable,
3263 struct config_string *pHolder,
3265 const char *curvalue,
3266 GucContext curscontext, GucSource cursource);
3267 static void ShowGUCConfigOption(const char *name, DestReceiver *dest);
3268 static void ShowAllGUCConfig(DestReceiver *dest);
3269 static char *_ShowOption(struct config_generic * record, bool use_units);
3270 static bool validate_option_array_item(const char *name, const char *value,
3271 bool skipIfNoPermissions);
3275 * Some infrastructure for checking malloc/strdup/realloc calls
3278 guc_malloc(int elevel, size_t size)
3282 data = malloc(size);
3285 (errcode(ERRCODE_OUT_OF_MEMORY),
3286 errmsg("out of memory")));
3291 guc_realloc(int elevel, void *old, size_t size)
3295 data = realloc(old, size);
3298 (errcode(ERRCODE_OUT_OF_MEMORY),
3299 errmsg("out of memory")));
3304 guc_strdup(int elevel, const char *src)
3311 (errcode(ERRCODE_OUT_OF_MEMORY),
3312 errmsg("out of memory")));
3318 * Detect whether strval is referenced anywhere in a GUC string item
3321 string_field_used(struct config_string * conf, char *strval)
3325 if (strval == *(conf->variable) ||
3326 strval == conf->reset_val ||
3327 strval == conf->boot_val)
3329 for (stack = conf->gen.stack; stack; stack = stack->prev)
3331 if (strval == stack->prior.val.stringval ||
3332 strval == stack->masked.val.stringval)
3339 * Support for assigning to a field of a string GUC item. Free the prior
3340 * value if it's not referenced anywhere else in the item (including stacked
3344 set_string_field(struct config_string * conf, char **field, char *newval)
3346 char *oldval = *field;
3348 /* Do the assignment */
3351 /* Free old value if it's not NULL and isn't referenced anymore */
3352 if (oldval && !string_field_used(conf, oldval))
3357 * Detect whether an "extra" struct is referenced anywhere in a GUC item
3360 extra_field_used(struct config_generic * gconf, void *extra)
3364 if (extra == gconf->extra)
3366 switch (gconf->vartype)
3369 if (extra == ((struct config_bool *) gconf)->reset_extra)
3373 if (extra == ((struct config_int *) gconf)->reset_extra)
3377 if (extra == ((struct config_real *) gconf)->reset_extra)
3381 if (extra == ((struct config_string *) gconf)->reset_extra)
3385 if (extra == ((struct config_enum *) gconf)->reset_extra)
3389 for (stack = gconf->stack; stack; stack = stack->prev)
3391 if (extra == stack->prior.extra ||
3392 extra == stack->masked.extra)
3400 * Support for assigning to an "extra" field of a GUC item. Free the prior
3401 * value if it's not referenced anywhere else in the item (including stacked
3405 set_extra_field(struct config_generic * gconf, void **field, void *newval)
3407 void *oldval = *field;
3409 /* Do the assignment */
3412 /* Free old value if it's not NULL and isn't referenced anymore */
3413 if (oldval && !extra_field_used(gconf, oldval))
3418 * Support for copying a variable's active value into a stack entry.
3419 * The "extra" field associated with the active value is copied, too.
3421 * NB: be sure stringval and extra fields of a new stack entry are
3422 * initialized to NULL before this is used, else we'll try to free() them.
3425 set_stack_value(struct config_generic * gconf, config_var_value *val)
3427 switch (gconf->vartype)
3431 *((struct config_bool *) gconf)->variable;
3435 *((struct config_int *) gconf)->variable;
3439 *((struct config_real *) gconf)->variable;
3442 set_string_field((struct config_string *) gconf,
3443 &(val->val.stringval),
3444 *((struct config_string *) gconf)->variable);
3448 *((struct config_enum *) gconf)->variable;
3451 set_extra_field(gconf, &(val->extra), gconf->extra);
3455 * Support for discarding a no-longer-needed value in a stack entry.
3456 * The "extra" field associated with the stack entry is cleared, too.
3459 discard_stack_value(struct config_generic * gconf, config_var_value *val)
3461 switch (gconf->vartype)
3467 /* no need to do anything */
3470 set_string_field((struct config_string *) gconf,
3471 &(val->val.stringval),
3475 set_extra_field(gconf, &(val->extra), NULL);
3480 * Fetch the sorted array pointer (exported for help_config.c's use ONLY)
3482 struct config_generic **
3483 get_guc_variables(void)
3485 return guc_variables;
3490 * Build the sorted array. This is split out so that it could be
3491 * re-executed after startup (eg, we could allow loadable modules to
3492 * add vars, and then we'd need to re-sort).
3495 build_guc_variables(void)
3499 struct config_generic **guc_vars;
3502 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
3504 struct config_bool *conf = &ConfigureNamesBool[i];
3506 /* Rather than requiring vartype to be filled in by hand, do this: */
3507 conf->gen.vartype = PGC_BOOL;
3511 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
3513 struct config_int *conf = &ConfigureNamesInt[i];
3515 conf->gen.vartype = PGC_INT;
3519 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
3521 struct config_real *conf = &ConfigureNamesReal[i];
3523 conf->gen.vartype = PGC_REAL;
3527 for (i = 0; ConfigureNamesString[i].gen.name; i++)
3529 struct config_string *conf = &ConfigureNamesString[i];
3531 conf->gen.vartype = PGC_STRING;
3535 for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
3537 struct config_enum *conf = &ConfigureNamesEnum[i];
3539 conf->gen.vartype = PGC_ENUM;
3544 * Create table with 20% slack
3546 size_vars = num_vars + num_vars / 4;
3548 guc_vars = (struct config_generic **)
3549 guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
3553 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
3554 guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
3556 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
3557 guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
3559 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
3560 guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
3562 for (i = 0; ConfigureNamesString[i].gen.name; i++)
3563 guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
3565 for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
3566 guc_vars[num_vars++] = &ConfigureNamesEnum[i].gen;
3569 free(guc_variables);
3570 guc_variables = guc_vars;
3571 num_guc_variables = num_vars;
3572 size_guc_variables = size_vars;
3573 qsort((void *) guc_variables, num_guc_variables,
3574 sizeof(struct config_generic *), guc_var_compare);
3578 * Add a new GUC variable to the list of known variables. The
3579 * list is expanded if needed.
3582 add_guc_variable(struct config_generic * var, int elevel)
3584 if (num_guc_variables + 1 >= size_guc_variables)
3587 * Increase the vector by 25%
3589 int size_vars = size_guc_variables + size_guc_variables / 4;
3590 struct config_generic **guc_vars;
3595 guc_vars = (struct config_generic **)
3596 guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
3600 guc_vars = (struct config_generic **)
3601 guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
3604 if (guc_vars == NULL)
3605 return false; /* out of memory */
3607 guc_variables = guc_vars;
3608 size_guc_variables = size_vars;
3610 guc_variables[num_guc_variables++] = var;
3611 qsort((void *) guc_variables, num_guc_variables,
3612 sizeof(struct config_generic *), guc_var_compare);
3617 * Create and add a placeholder variable for a custom variable name.
3619 static struct config_generic *
3620 add_placeholder_variable(const char *name, int elevel)
3622 size_t sz = sizeof(struct config_string) + sizeof(char *);
3623 struct config_string *var;
3624 struct config_generic *gen;
3626 var = (struct config_string *) guc_malloc(elevel, sz);
3632 gen->name = guc_strdup(elevel, name);
3633 if (gen->name == NULL)
3639 gen->context = PGC_USERSET;
3640 gen->group = CUSTOM_OPTIONS;
3641 gen->short_desc = "GUC placeholder variable";
3642 gen->flags = GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_CUSTOM_PLACEHOLDER;
3643 gen->vartype = PGC_STRING;
3646 * The char* is allocated at the end of the struct since we have no
3647 * 'static' place to point to. Note that the current value, as well as
3648 * the boot and reset values, start out NULL.
3650 var->variable = (char **) (var + 1);
3652 if (!add_guc_variable((struct config_generic *) var, elevel))
3654 free((void *) gen->name);
3663 * Look up option NAME. If it exists, return a pointer to its record,
3664 * else return NULL. If create_placeholders is TRUE, we'll create a
3665 * placeholder record for a valid-looking custom variable name.
3667 static struct config_generic *
3668 find_option(const char *name, bool create_placeholders, int elevel)
3670 const char **key = &name;
3671 struct config_generic **res;
3677 * By equating const char ** with struct config_generic *, we are assuming
3678 * the name field is first in config_generic.
3680 res = (struct config_generic **) bsearch((void *) &key,
3681 (void *) guc_variables,
3683 sizeof(struct config_generic *),
3689 * See if the name is an obsolete name for a variable. We assume that the
3690 * set of supported old names is short enough that a brute-force search is
3693 for (i = 0; map_old_guc_names[i] != NULL; i += 2)
3695 if (guc_name_compare(name, map_old_guc_names[i]) == 0)
3696 return find_option(map_old_guc_names[i + 1], false, elevel);
3699 if (create_placeholders)
3702 * Check if the name is qualified, and if so, add a placeholder.
3704 if (strchr(name, GUC_QUALIFIER_SEPARATOR) != NULL)
3705 return add_placeholder_variable(name, elevel);
3714 * comparator for qsorting and bsearching guc_variables array
3717 guc_var_compare(const void *a, const void *b)
3719 struct config_generic *confa = *(struct config_generic **) a;
3720 struct config_generic *confb = *(struct config_generic **) b;
3722 return guc_name_compare(confa->name, confb->name);
3726 * the bare comparison function for GUC names
3729 guc_name_compare(const char *namea, const char *nameb)
3732 * The temptation to use strcasecmp() here must be resisted, because the
3733 * array ordering has to remain stable across setlocale() calls. So, build
3734 * our own with a simple ASCII-only downcasing.
3736 while (*namea && *nameb)
3738 char cha = *namea++;
3739 char chb = *nameb++;
3741 if (cha >= 'A' && cha <= 'Z')
3743 if (chb >= 'A' && chb <= 'Z')
3749 return 1; /* a is longer */
3751 return -1; /* b is longer */
3757 * Initialize GUC options during program startup.
3759 * Note that we cannot read the config file yet, since we have not yet
3760 * processed command-line switches.
3763 InitializeGUCOptions(void)
3768 * Before log_line_prefix could possibly receive a nonempty setting, make
3769 * sure that timezone processing is minimally alive (see elog.c).
3771 pg_timezone_initialize();
3774 * Build sorted array of all GUC variables.
3776 build_guc_variables();
3779 * Load all variables with their compiled-in defaults, and initialize
3780 * status fields as needed.
3782 for (i = 0; i < num_guc_variables; i++)
3784 InitializeOneGUCOption(guc_variables[i]);
3789 reporting_enabled = false;
3792 * Prevent any attempt to override the transaction modes from
3793 * non-interactive sources.
3795 SetConfigOption("transaction_isolation", "default",
3796 PGC_POSTMASTER, PGC_S_OVERRIDE);
3797 SetConfigOption("transaction_read_only", "no",
3798 PGC_POSTMASTER, PGC_S_OVERRIDE);
3799 SetConfigOption("transaction_deferrable", "no",
3800 PGC_POSTMASTER, PGC_S_OVERRIDE);
3803 * For historical reasons, some GUC parameters can receive defaults from
3804 * environment variables. Process those settings.
3806 InitializeGUCOptionsFromEnvironment();
3810 * Assign any GUC values that can come from the server's environment.
3812 * This is called from InitializeGUCOptions, and also from ProcessConfigFile
3813 * to deal with the possibility that a setting has been removed from
3814 * postgresql.conf and should now get a value from the environment.
3815 * (The latter is a kludge that should probably go away someday; if so,
3816 * fold this back into InitializeGUCOptions.)
3819 InitializeGUCOptionsFromEnvironment(void)
3824 env = getenv("PGPORT");
3826 SetConfigOption("port", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3828 env = getenv("PGDATESTYLE");
3830 SetConfigOption("datestyle", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3832 env = getenv("PGCLIENTENCODING");
3834 SetConfigOption("client_encoding", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3837 * rlimit isn't exactly an "environment variable", but it behaves about
3838 * the same. If we can identify the platform stack depth rlimit, increase
3839 * default stack depth setting up to whatever is safe (but at most 2MB).
3841 stack_rlimit = get_stack_depth_rlimit();
3842 if (stack_rlimit > 0)
3844 long new_limit = (stack_rlimit - STACK_DEPTH_SLOP) / 1024L;
3846 if (new_limit > 100)
3850 new_limit = Min(new_limit, 2048);
3851 sprintf(limbuf, "%ld", new_limit);
3852 SetConfigOption("max_stack_depth", limbuf,
3853 PGC_POSTMASTER, PGC_S_ENV_VAR);
3859 * Initialize one GUC option variable to its compiled-in default.
3861 * Note: the reason for calling check_hooks is not that we think the boot_val
3862 * might fail, but that the hooks might wish to compute an "extra" struct.
3865 InitializeOneGUCOption(struct config_generic * gconf)
3868 gconf->source = PGC_S_DEFAULT;
3869 gconf->reset_source = PGC_S_DEFAULT;
3870 gconf->scontext = PGC_INTERNAL;
3871 gconf->reset_scontext = PGC_INTERNAL;
3872 gconf->stack = NULL;
3873 gconf->extra = NULL;
3874 gconf->sourcefile = NULL;
3875 gconf->sourceline = 0;
3877 switch (gconf->vartype)
3881 struct config_bool *conf = (struct config_bool *) gconf;
3882 bool newval = conf->boot_val;
3885 if (!call_bool_check_hook(conf, &newval, &extra,
3886 PGC_S_DEFAULT, LOG))
3887 elog(FATAL, "failed to initialize %s to %d",
3888 conf->gen.name, (int) newval);
3889 if (conf->assign_hook)
3890 (*conf->assign_hook) (newval, extra);
3891 *conf->variable = conf->reset_val = newval;
3892 conf->gen.extra = conf->reset_extra = extra;
3897 struct config_int *conf = (struct config_int *) gconf;
3898 int newval = conf->boot_val;
3901 Assert(newval >= conf->min);
3902 Assert(newval <= conf->max);
3903 if (!call_int_check_hook(conf, &newval, &extra,
3904 PGC_S_DEFAULT, LOG))
3905 elog(FATAL, "failed to initialize %s to %d",
3906 conf->gen.name, newval);
3907 if (conf->assign_hook)
3908 (*conf->assign_hook) (newval, extra);
3909 *conf->variable = conf->reset_val = newval;
3910 conf->gen.extra = conf->reset_extra = extra;
3915 struct config_real *conf = (struct config_real *) gconf;
3916 double newval = conf->boot_val;
3919 Assert(newval >= conf->min);
3920 Assert(newval <= conf->max);
3921 if (!call_real_check_hook(conf, &newval, &extra,
3922 PGC_S_DEFAULT, LOG))
3923 elog(FATAL, "failed to initialize %s to %g",
3924 conf->gen.name, newval);
3925 if (conf->assign_hook)
3926 (*conf->assign_hook) (newval, extra);
3927 *conf->variable = conf->reset_val = newval;
3928 conf->gen.extra = conf->reset_extra = extra;
3933 struct config_string *conf = (struct config_string *) gconf;
3937 /* non-NULL boot_val must always get strdup'd */
3938 if (conf->boot_val != NULL)
3939 newval = guc_strdup(FATAL, conf->boot_val);
3943 if (!call_string_check_hook(conf, &newval, &extra,
3944 PGC_S_DEFAULT, LOG))
3945 elog(FATAL, "failed to initialize %s to \"%s\"",
3946 conf->gen.name, newval ? newval : "");
3947 if (conf->assign_hook)
3948 (*conf->assign_hook) (newval, extra);
3949 *conf->variable = conf->reset_val = newval;
3950 conf->gen.extra = conf->reset_extra = extra;
3955 struct config_enum *conf = (struct config_enum *) gconf;
3956 int newval = conf->boot_val;
3959 if (!call_enum_check_hook(conf, &newval, &extra,
3960 PGC_S_DEFAULT, LOG))
3961 elog(FATAL, "failed to initialize %s to %d",
3962 conf->gen.name, newval);
3963 if (conf->assign_hook)
3964 (*conf->assign_hook) (newval, extra);
3965 *conf->variable = conf->reset_val = newval;
3966 conf->gen.extra = conf->reset_extra = extra;
3974 * Select the configuration files and data directory to be used, and
3975 * do the initial read of postgresql.conf.
3977 * This is called after processing command-line switches.
3978 * userDoption is the -D switch value if any (NULL if unspecified).
3979 * progname is just for use in error messages.
3981 * Returns true on success; on failure, prints a suitable error message
3982 * to stderr and returns false.
3985 SelectConfigFiles(const char *userDoption, const char *progname)
3989 struct stat stat_buf;
3991 /* configdir is -D option, or $PGDATA if no -D */
3993 configdir = make_absolute_path(userDoption);
3995 configdir = make_absolute_path(getenv("PGDATA"));
3998 * Find the configuration file: if config_file was specified on the
3999 * command line, use it, else use configdir/postgresql.conf. In any case
4000 * ensure the result is an absolute path, so that it will be interpreted
4001 * the same way by future backends.
4004 fname = make_absolute_path(ConfigFileName);
4007 fname = guc_malloc(FATAL,
4008 strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
4009 sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
4013 write_stderr("%s does not know where to find the server configuration file.\n"
4014 "You must specify the --config-file or -D invocation "
4015 "option or set the PGDATA environment variable.\n",
4021 * Set the ConfigFileName GUC variable to its final value, ensuring that
4022 * it can't be overridden later.
4024 SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4028 * Now read the config file for the first time.
4030 if (stat(ConfigFileName, &stat_buf) != 0)
4032 write_stderr("%s cannot access the server configuration file \"%s\": %s\n",
4033 progname, ConfigFileName, strerror(errno));
4037 ProcessConfigFile(PGC_POSTMASTER);
4040 * If the data_directory GUC variable has been set, use that as DataDir;
4041 * otherwise use configdir if set; else punt.
4043 * Note: SetDataDir will copy and absolute-ize its argument, so we don't
4047 SetDataDir(data_directory);
4049 SetDataDir(configdir);
4052 write_stderr("%s does not know where to find the database system data.\n"
4053 "This can be specified as \"data_directory\" in \"%s\", "
4054 "or by the -D invocation option, or by the "
4055 "PGDATA environment variable.\n",
4056 progname, ConfigFileName);
4061 * Reflect the final DataDir value back into the data_directory GUC var.
4062 * (If you are wondering why we don't just make them a single variable,
4063 * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
4064 * child backends specially. XXX is that still true? Given that we now
4065 * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
4066 * DataDir in advance.)
4068 SetConfigOption("data_directory", DataDir, PGC_POSTMASTER, PGC_S_OVERRIDE);
4071 * If timezone_abbreviations wasn't set in the configuration file, install
4072 * the default value. We do it this way because we can't safely install
4073 * a "real" value until my_exec_path is set, which may not have happened
4074 * when InitializeGUCOptions runs, so the bootstrap default value cannot
4075 * be the real desired default.
4077 pg_timezone_abbrev_initialize();
4080 * Figure out where pg_hba.conf is, and make sure the path is absolute.
4083 fname = make_absolute_path(HbaFileName);
4086 fname = guc_malloc(FATAL,
4087 strlen(configdir) + strlen(HBA_FILENAME) + 2);
4088 sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
4092 write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
4093 "This can be specified as \"hba_file\" in \"%s\", "
4094 "or by the -D invocation option, or by the "
4095 "PGDATA environment variable.\n",
4096 progname, ConfigFileName);
4099 SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4103 * Likewise for pg_ident.conf.
4106 fname = make_absolute_path(IdentFileName);
4109 fname = guc_malloc(FATAL,
4110 strlen(configdir) + strlen(IDENT_FILENAME) + 2);
4111 sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
4115 write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
4116 "This can be specified as \"ident_file\" in \"%s\", "
4117 "or by the -D invocation option, or by the "
4118 "PGDATA environment variable.\n",
4119 progname, ConfigFileName);
4122 SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4132 * Reset all options to their saved default values (implements RESET ALL)
4135 ResetAllOptions(void)
4139 for (i = 0; i < num_guc_variables; i++)
4141 struct config_generic *gconf = guc_variables[i];
4143 /* Don't reset non-SET-able values */
4144 if (gconf->context != PGC_SUSET &&
4145 gconf->context != PGC_USERSET)
4147 /* Don't reset if special exclusion from RESET ALL */
4148 if (gconf->flags & GUC_NO_RESET_ALL)
4150 /* No need to reset if wasn't SET */
4151 if (gconf->source <= PGC_S_OVERRIDE)
4154 /* Save old value to support transaction abort */
4155 push_old_value(gconf, GUC_ACTION_SET);
4157 switch (gconf->vartype)
4161 struct config_bool *conf = (struct config_bool *) gconf;
4163 if (conf->assign_hook)
4164 (*conf->assign_hook) (conf->reset_val,
4166 *conf->variable = conf->reset_val;
4167 set_extra_field(&conf->gen, &conf->gen.extra,
4173 struct config_int *conf = (struct config_int *) gconf;
4175 if (conf->assign_hook)
4176 (*conf->assign_hook) (conf->reset_val,
4178 *conf->variable = conf->reset_val;
4179 set_extra_field(&conf->gen, &conf->gen.extra,
4185 struct config_real *conf = (struct config_real *) gconf;
4187 if (conf->assign_hook)
4188 (*conf->assign_hook) (conf->reset_val,
4190 *conf->variable = conf->reset_val;
4191 set_extra_field(&conf->gen, &conf->gen.extra,
4197 struct config_string *conf = (struct config_string *) gconf;
4199 if (conf->assign_hook)
4200 (*conf->assign_hook) (conf->reset_val,
4202 set_string_field(conf, conf->variable, conf->reset_val);
4203 set_extra_field(&conf->gen, &conf->gen.extra,
4209 struct config_enum *conf = (struct config_enum *) gconf;
4211 if (conf->assign_hook)
4212 (*conf->assign_hook) (conf->reset_val,
4214 *conf->variable = conf->reset_val;
4215 set_extra_field(&conf->gen, &conf->gen.extra,
4221 gconf->source = gconf->reset_source;
4222 gconf->scontext = gconf->reset_scontext;
4224 if (gconf->flags & GUC_REPORT)
4225 ReportGUCOption(gconf);
4232 * Push previous state during transactional assignment to a GUC variable.
4235 push_old_value(struct config_generic * gconf, GucAction action)
4239 /* If we're not inside a nest level, do nothing */
4240 if (GUCNestLevel == 0)
4243 /* Do we already have a stack entry of the current nest level? */
4244 stack = gconf->stack;
4245 if (stack && stack->nest_level >= GUCNestLevel)
4247 /* Yes, so adjust its state if necessary */
4248 Assert(stack->nest_level == GUCNestLevel);
4251 case GUC_ACTION_SET:
4252 /* SET overrides any prior action at same nest level */
4253 if (stack->state == GUC_SET_LOCAL)
4255 /* must discard old masked value */
4256 discard_stack_value(gconf, &stack->masked);
4258 stack->state = GUC_SET;
4260 case GUC_ACTION_LOCAL:
4261 if (stack->state == GUC_SET)
4263 /* SET followed by SET LOCAL, remember SET's value */
4264 stack->masked_scontext = gconf->scontext;
4265 set_stack_value(gconf, &stack->masked);
4266 stack->state = GUC_SET_LOCAL;
4268 /* in all other cases, no change to stack entry */
4270 case GUC_ACTION_SAVE:
4271 /* Could only have a prior SAVE of same variable */
4272 Assert(stack->state == GUC_SAVE);
4275 Assert(guc_dirty); /* must be set already */
4280 * Push a new stack entry
4282 * We keep all the stack entries in TopTransactionContext for simplicity.
4284 stack = (GucStack *) MemoryContextAllocZero(TopTransactionContext,
4287 stack->prev = gconf->stack;
4288 stack->nest_level = GUCNestLevel;
4291 case GUC_ACTION_SET:
4292 stack->state = GUC_SET;
4294 case GUC_ACTION_LOCAL:
4295 stack->state = GUC_LOCAL;
4297 case GUC_ACTION_SAVE:
4298 stack->state = GUC_SAVE;
4301 stack->source = gconf->source;
4302 stack->scontext = gconf->scontext;
4303 set_stack_value(gconf, &stack->prior);
4305 gconf->stack = stack;
4307 /* Ensure we remember to pop at end of xact */
4313 * Do GUC processing at main transaction start.
4319 * The nest level should be 0 between transactions; if it isn't, somebody
4320 * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
4321 * throw a warning but make no other effort to clean up.
4323 if (GUCNestLevel != 0)
4324 elog(WARNING, "GUC nest level = %d at transaction start",
4330 * Enter a new nesting level for GUC values. This is called at subtransaction
4331 * start, and when entering a function that has proconfig settings, and in
4332 * some other places where we want to set GUC variables transiently.
4333 * NOTE we must not risk error here, else subtransaction start will be unhappy.
4336 NewGUCNestLevel(void)
4338 return ++GUCNestLevel;
4342 * Do GUC processing at transaction or subtransaction commit or abort, or
4343 * when exiting a function that has proconfig settings, or when undoing a
4344 * transient assignment to some GUC variables. (The name is thus a bit of
4345 * a misnomer; perhaps it should be ExitGUCNestLevel or some such.)
4346 * During abort, we discard all GUC settings that were applied at nesting
4347 * levels >= nestLevel. nestLevel == 1 corresponds to the main transaction.
4350 AtEOXact_GUC(bool isCommit, int nestLevel)
4356 * Note: it's possible to get here with GUCNestLevel == nestLevel-1 during
4357 * abort, if there is a failure during transaction start before
4358 * AtStart_GUC is called.
4360 Assert(nestLevel > 0 &&
4361 (nestLevel <= GUCNestLevel ||
4362 (nestLevel == GUCNestLevel + 1 && !isCommit)));
4364 /* Quick exit if nothing's changed in this transaction */
4367 GUCNestLevel = nestLevel - 1;
4371 still_dirty = false;
4372 for (i = 0; i < num_guc_variables; i++)
4374 struct config_generic *gconf = guc_variables[i];
4378 * Process and pop each stack entry within the nest level. To simplify
4379 * fmgr_security_definer() and other places that use GUC_ACTION_SAVE,
4380 * we allow failure exit from code that uses a local nest level to be
4381 * recovered at the surrounding transaction or subtransaction abort;
4382 * so there could be more than one stack entry to pop.
4384 while ((stack = gconf->stack) != NULL &&
4385 stack->nest_level >= nestLevel)
4387 GucStack *prev = stack->prev;
4388 bool restorePrior = false;
4389 bool restoreMasked = false;
4393 * In this next bit, if we don't set either restorePrior or
4394 * restoreMasked, we must "discard" any unwanted fields of the
4395 * stack entries to avoid leaking memory. If we do set one of
4396 * those flags, unused fields will be cleaned up after restoring.
4398 if (!isCommit) /* if abort, always restore prior value */
4399 restorePrior = true;
4400 else if (stack->state == GUC_SAVE)
4401 restorePrior = true;
4402 else if (stack->nest_level == 1)
4404 /* transaction commit */
4405 if (stack->state == GUC_SET_LOCAL)
4406 restoreMasked = true;
4407 else if (stack->state == GUC_SET)
4409 /* we keep the current active value */
4410 discard_stack_value(gconf, &stack->prior);
4412 else /* must be GUC_LOCAL */
4413 restorePrior = true;
4415 else if (prev == NULL ||
4416 prev->nest_level < stack->nest_level - 1)
4418 /* decrement entry's level and do not pop it */
4419 stack->nest_level--;
4425 * We have to merge this stack entry into prev. See README for
4426 * discussion of this bit.
4428 switch (stack->state)
4431 Assert(false); /* can't get here */
4434 /* next level always becomes SET */
4435 discard_stack_value(gconf, &stack->prior);
4436 if (prev->state == GUC_SET_LOCAL)
4437 discard_stack_value(gconf, &prev->masked);
4438 prev->state = GUC_SET;
4442 if (prev->state == GUC_SET)
4444 /* LOCAL migrates down */
4445 prev->masked_scontext = stack->scontext;
4446 prev->masked = stack->prior;
4447 prev->state = GUC_SET_LOCAL;
4451 /* else just forget this stack level */
4452 discard_stack_value(gconf, &stack->prior);
4457 /* prior state at this level no longer wanted */
4458 discard_stack_value(gconf, &stack->prior);
4459 /* copy down the masked state */
4460 prev->masked_scontext = stack->masked_scontext;
4461 if (prev->state == GUC_SET_LOCAL)
4462 discard_stack_value(gconf, &prev->masked);
4463 prev->masked = stack->masked;
4464 prev->state = GUC_SET_LOCAL;
4471 if (restorePrior || restoreMasked)
4473 /* Perform appropriate restoration of the stacked value */
4474 config_var_value newvalue;
4475 GucSource newsource;
4476 GucContext newscontext;
4480 newvalue = stack->masked;
4481 newsource = PGC_S_SESSION;
4482 newscontext = stack->masked_scontext;
4486 newvalue = stack->prior;
4487 newsource = stack->source;
4488 newscontext = stack->scontext;
4491 switch (gconf->vartype)
4495 struct config_bool *conf = (struct config_bool *) gconf;
4496 bool newval = newvalue.val.boolval;
4497 void *newextra = newvalue.extra;
4499 if (*conf->variable != newval ||
4500 conf->gen.extra != newextra)
4502 if (conf->assign_hook)
4503 (*conf->assign_hook) (newval, newextra);
4504 *conf->variable = newval;
4505 set_extra_field(&conf->gen, &conf->gen.extra,
4513 struct config_int *conf = (struct config_int *) gconf;
4514 int newval = newvalue.val.intval;
4515 void *newextra = newvalue.extra;
4517 if (*conf->variable != newval ||
4518 conf->gen.extra != newextra)
4520 if (conf->assign_hook)
4521 (*conf->assign_hook) (newval, newextra);
4522 *conf->variable = newval;
4523 set_extra_field(&conf->gen, &conf->gen.extra,
4531 struct config_real *conf = (struct config_real *) gconf;
4532 double newval = newvalue.val.realval;
4533 void *newextra = newvalue.extra;
4535 if (*conf->variable != newval ||
4536 conf->gen.extra != newextra)
4538 if (conf->assign_hook)
4539 (*conf->assign_hook) (newval, newextra);
4540 *conf->variable = newval;
4541 set_extra_field(&conf->gen, &conf->gen.extra,
4549 struct config_string *conf = (struct config_string *) gconf;
4550 char *newval = newvalue.val.stringval;
4551 void *newextra = newvalue.extra;
4553 if (*conf->variable != newval ||
4554 conf->gen.extra != newextra)
4556 if (conf->assign_hook)
4557 (*conf->assign_hook) (newval, newextra);
4558 set_string_field(conf, conf->variable, newval);
4559 set_extra_field(&conf->gen, &conf->gen.extra,
4565 * Release stacked values if not used anymore. We
4566 * could use discard_stack_value() here, but since
4567 * we have type-specific code anyway, might as
4570 set_string_field(conf, &stack->prior.val.stringval, NULL);
4571 set_string_field(conf, &stack->masked.val.stringval, NULL);
4576 struct config_enum *conf = (struct config_enum *) gconf;
4577 int newval = newvalue.val.enumval;
4578 void *newextra = newvalue.extra;
4580 if (*conf->variable != newval ||
4581 conf->gen.extra != newextra)
4583 if (conf->assign_hook)
4584 (*conf->assign_hook) (newval, newextra);
4585 *conf->variable = newval;
4586 set_extra_field(&conf->gen, &conf->gen.extra,
4595 * Release stacked extra values if not used anymore.
4597 set_extra_field(gconf, &(stack->prior.extra), NULL);
4598 set_extra_field(gconf, &(stack->masked.extra), NULL);
4600 /* And restore source information */
4601 gconf->source = newsource;
4602 gconf->scontext = newscontext;
4605 /* Finish popping the state stack */
4606 gconf->stack = prev;
4609 /* Report new value if we changed it */
4610 if (changed && (gconf->flags & GUC_REPORT))
4611 ReportGUCOption(gconf);
4612 } /* end of stack-popping loop */
4618 /* If there are no remaining stack entries, we can reset guc_dirty */
4619 guc_dirty = still_dirty;
4621 /* Update nesting level */
4622 GUCNestLevel = nestLevel - 1;
4627 * Start up automatic reporting of changes to variables marked GUC_REPORT.
4628 * This is executed at completion of backend startup.
4631 BeginReportingGUCOptions(void)
4636 * Don't do anything unless talking to an interactive frontend of protocol
4639 if (whereToSendOutput != DestRemote ||
4640 PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
4643 reporting_enabled = true;
4645 /* Transmit initial values of interesting variables */
4646 for (i = 0; i < num_guc_variables; i++)
4648 struct config_generic *conf = guc_variables[i];
4650 if (conf->flags & GUC_REPORT)
4651 ReportGUCOption(conf);
4656 * ReportGUCOption: if appropriate, transmit option value to frontend
4659 ReportGUCOption(struct config_generic * record)
4661 if (reporting_enabled && (record->flags & GUC_REPORT))
4663 char *val = _ShowOption(record, false);
4664 StringInfoData msgbuf;
4666 pq_beginmessage(&msgbuf, 'S');
4667 pq_sendstring(&msgbuf, record->name);
4668 pq_sendstring(&msgbuf, val);
4669 pq_endmessage(&msgbuf);
4676 * Try to parse value as an integer. The accepted formats are the
4677 * usual decimal, octal, or hexadecimal formats, optionally followed by
4678 * a unit name if "flags" indicates a unit is allowed.
4680 * If the string parses okay, return true, else false.
4681 * If okay and result is not NULL, return the value in *result.
4682 * If not okay and hintmsg is not NULL, *hintmsg is set to a suitable
4683 * HINT message, or NULL if no hint provided.
4686 parse_int(const char *value, int *result, int flags, const char **hintmsg)
4691 /* To suppress compiler warnings, always set output params */
4697 /* We assume here that int64 is at least as wide as long */
4699 val = strtol(value, &endptr, 0);
4701 if (endptr == value)
4702 return false; /* no HINT for integer syntax error */
4704 if (errno == ERANGE || val != (int64) ((int32) val))
4707 *hintmsg = gettext_noop("Value exceeds integer range.");
4711 /* allow whitespace between integer and unit */
4712 while (isspace((unsigned char) *endptr))
4715 /* Handle possible unit */
4716 if (*endptr != '\0')
4719 * Note: the multiple-switch coding technique here is a bit tedious,
4720 * but seems necessary to avoid intermediate-value overflows.
4722 if (flags & GUC_UNIT_MEMORY)
4724 /* Set hint for use if no match or trailing garbage */
4726 *hintmsg = gettext_noop("Valid units for this parameter are \"kB\", \"MB\", and \"GB\".");
4728 #if BLCKSZ < 1024 || BLCKSZ > (1024*1024)
4729 #error BLCKSZ must be between 1KB and 1MB
4731 #if XLOG_BLCKSZ < 1024 || XLOG_BLCKSZ > (1024*1024)
4732 #error XLOG_BLCKSZ must be between 1KB and 1MB
4735 if (strncmp(endptr, "kB", 2) == 0)
4738 switch (flags & GUC_UNIT_MEMORY)
4740 case GUC_UNIT_BLOCKS:
4741 val /= (BLCKSZ / 1024);
4743 case GUC_UNIT_XBLOCKS:
4744 val /= (XLOG_BLCKSZ / 1024);
4748 else if (strncmp(endptr, "MB", 2) == 0)
4751 switch (flags & GUC_UNIT_MEMORY)
4756 case GUC_UNIT_BLOCKS:
4757 val *= KB_PER_MB / (BLCKSZ / 1024);
4759 case GUC_UNIT_XBLOCKS:
4760 val *= KB_PER_MB / (XLOG_BLCKSZ / 1024);
4764 else if (strncmp(endptr, "GB", 2) == 0)
4767 switch (flags & GUC_UNIT_MEMORY)
4772 case GUC_UNIT_BLOCKS:
4773 val *= KB_PER_GB / (BLCKSZ / 1024);
4775 case GUC_UNIT_XBLOCKS:
4776 val *= KB_PER_GB / (XLOG_BLCKSZ / 1024);
4781 else if (flags & GUC_UNIT_TIME)
4783 /* Set hint for use if no match or trailing garbage */
4785 *hintmsg = gettext_noop("Valid units for this parameter are \"ms\", \"s\", \"min\", \"h\", and \"d\".");
4787 if (strncmp(endptr, "ms", 2) == 0)
4790 switch (flags & GUC_UNIT_TIME)
4800 else if (strncmp(endptr, "s", 1) == 0)
4803 switch (flags & GUC_UNIT_TIME)
4813 else if (strncmp(endptr, "min", 3) == 0)
4816 switch (flags & GUC_UNIT_TIME)
4826 else if (strncmp(endptr, "h", 1) == 0)
4829 switch (flags & GUC_UNIT_TIME)
4842 else if (strncmp(endptr, "d", 1) == 0)
4845 switch (flags & GUC_UNIT_TIME)
4860 /* allow whitespace after unit */
4861 while (isspace((unsigned char) *endptr))
4864 if (*endptr != '\0')
4865 return false; /* appropriate hint, if any, already set */
4867 /* Check for overflow due to units conversion */
4868 if (val != (int64) ((int32) val))
4871 *hintmsg = gettext_noop("Value exceeds integer range.");
4877 *result = (int) val;
4884 * Try to parse value as a floating point number in the usual format.
4885 * If the string parses okay, return true, else false.
4886 * If okay and result is not NULL, return the value in *result.
4889 parse_real(const char *value, double *result)
4895 *result = 0; /* suppress compiler warning */
4898 val = strtod(value, &endptr);
4899 if (endptr == value || errno == ERANGE)
4902 /* allow whitespace after number */
4903 while (isspace((unsigned char) *endptr))
4905 if (*endptr != '\0')
4915 * Lookup the name for an enum option with the selected value.
4916 * Should only ever be called with known-valid values, so throws
4917 * an elog(ERROR) if the enum option is not found.
4919 * The returned string is a pointer to static data and not
4920 * allocated for modification.
4923 config_enum_lookup_by_value(struct config_enum * record, int val)
4925 const struct config_enum_entry *entry;
4927 for (entry = record->options; entry && entry->name; entry++)
4929 if (entry->val == val)
4933 elog(ERROR, "could not find enum option %d for %s",
4934 val, record->gen.name);
4935 return NULL; /* silence compiler */
4940 * Lookup the value for an enum option with the selected name
4941 * (case-insensitive).
4942 * If the enum option is found, sets the retval value and returns
4943 * true. If it's not found, return FALSE and retval is set to 0.
4946 config_enum_lookup_by_name(struct config_enum * record, const char *value,
4949 const struct config_enum_entry *entry;
4951 for (entry = record->options; entry && entry->name; entry++)
4953 if (pg_strcasecmp(value, entry->name) == 0)
4955 *retval = entry->val;
4966 * Return a list of all available options for an enum, excluding
4967 * hidden ones, separated by the given separator.
4968 * If prefix is non-NULL, it is added before the first enum value.
4969 * If suffix is non-NULL, it is added to the end of the string.
4972 config_enum_get_options(struct config_enum * record, const char *prefix,
4973 const char *suffix, const char *separator)
4975 const struct config_enum_entry *entry;
4976 StringInfoData retstr;
4979 initStringInfo(&retstr);
4980 appendStringInfoString(&retstr, prefix);
4982 seplen = strlen(separator);
4983 for (entry = record->options; entry && entry->name; entry++)
4987 appendStringInfoString(&retstr, entry->name);
4988 appendBinaryStringInfo(&retstr, separator, seplen);
4993 * All the entries may have been hidden, leaving the string empty if no
4994 * prefix was given. This indicates a broken GUC setup, since there is no
4995 * use for an enum without any values, so we just check to make sure we
4996 * don't write to invalid memory instead of actually trying to do
4997 * something smart with it.
4999 if (retstr.len >= seplen)
5001 /* Replace final separator */
5002 retstr.data[retstr.len - seplen] = '\0';
5003 retstr.len -= seplen;
5006 appendStringInfoString(&retstr, suffix);
5013 * Sets option `name' to given value.
5015 * The value should be a string, which will be parsed and converted to
5016 * the appropriate data type. The context and source parameters indicate
5017 * in which context this function is being called, so that it can apply the
5018 * access restrictions properly.
5020 * If value is NULL, set the option to its default value (normally the
5021 * reset_val, but if source == PGC_S_DEFAULT we instead use the boot_val).
5023 * action indicates whether to set the value globally in the session, locally
5024 * to the current top transaction, or just for the duration of a function call.
5026 * If changeVal is false then don't really set the option but do all
5027 * the checks to see if it would work.
5029 * elevel should normally be passed as zero, allowing this function to make
5030 * its standard choice of ereport level. However some callers need to be
5031 * able to override that choice; they should pass the ereport level to use.
5034 * +1: the value is valid and was successfully applied.
5035 * 0: the name or value is invalid (but see below).
5036 * -1: the value was not applied because of context, priority, or changeVal.
5038 * If there is an error (non-existing option, invalid value) then an
5039 * ereport(ERROR) is thrown *unless* this is called for a source for which
5040 * we don't want an ERROR (currently, those are defaults, the config file,
5041 * and per-database or per-user settings, as well as callers who specify
5042 * a less-than-ERROR elevel). In those cases we write a suitable error
5043 * message via ereport() and return 0.
5045 * See also SetConfigOption for an external interface.
5048 set_config_option(const char *name, const char *value,
5049 GucContext context, GucSource source,
5050 GucAction action, bool changeVal, int elevel)
5052 struct config_generic *record;
5053 bool prohibitValueChange = false;
5058 if (source == PGC_S_DEFAULT || source == PGC_S_FILE)
5061 * To avoid cluttering the log, only the postmaster bleats loudly
5062 * about problems with the config file.
5064 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
5066 else if (source == PGC_S_DATABASE || source == PGC_S_USER ||
5067 source == PGC_S_DATABASE_USER)
5073 record = find_option(name, true, elevel);
5077 (errcode(ERRCODE_UNDEFINED_OBJECT),
5078 errmsg("unrecognized configuration parameter \"%s\"", name)));
5083 * Check if the option can be set at this time. See guc.h for the precise
5086 switch (record->context)
5089 if (context != PGC_INTERNAL)
5092 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5093 errmsg("parameter \"%s\" cannot be changed",
5098 case PGC_POSTMASTER:
5099 if (context == PGC_SIGHUP)
5102 * We are re-reading a PGC_POSTMASTER variable from
5103 * postgresql.conf. We can't change the setting, so we should
5104 * give a warning if the DBA tries to change it. However,
5105 * because of variant formats, canonicalization by check
5106 * hooks, etc, we can't just compare the given string directly
5107 * to what's stored. Set a flag to check below after we have
5108 * the final storable value.
5110 prohibitValueChange = true;
5112 else if (context != PGC_POSTMASTER)
5115 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5116 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5122 if (context != PGC_SIGHUP && context != PGC_POSTMASTER)
5125 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5126 errmsg("parameter \"%s\" cannot be changed now",
5132 * Hmm, the idea of the SIGHUP context is "ought to be global, but
5133 * can be changed after postmaster start". But there's nothing
5134 * that prevents a crafty administrator from sending SIGHUP
5135 * signals to individual backends only.
5139 if (context == PGC_SIGHUP)
5142 * If a PGC_BACKEND parameter is changed in the config file,
5143 * we want to accept the new value in the postmaster (whence
5144 * it will propagate to subsequently-started backends), but
5145 * ignore it in existing backends. This is a tad klugy, but
5146 * necessary because we don't re-read the config file during
5149 if (IsUnderPostmaster)
5152 else if (context != PGC_POSTMASTER && context != PGC_BACKEND &&
5153 source != PGC_S_CLIENT)
5156 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5157 errmsg("parameter \"%s\" cannot be set after connection start",
5163 if (context == PGC_USERSET || context == PGC_BACKEND)
5166 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5167 errmsg("permission denied to set parameter \"%s\"",
5178 * Disallow changing GUC_NOT_WHILE_SEC_REST values if we are inside a
5179 * security restriction context. We can reject this regardless of the GUC
5180 * context or source, mainly because sources that it might be reasonable
5181 * to override for won't be seen while inside a function.
5183 * Note: variables marked GUC_NOT_WHILE_SEC_REST should usually be marked
5184 * GUC_NO_RESET_ALL as well, because ResetAllOptions() doesn't check this.
5185 * An exception might be made if the reset value is assumed to be "safe".
5187 * Note: this flag is currently used for "session_authorization" and
5188 * "role". We need to prohibit changing these inside a local userid
5189 * context because when we exit it, GUC won't be notified, leaving things
5190 * out of sync. (This could be fixed by forcing a new GUC nesting level,
5191 * but that would change behavior in possibly-undesirable ways.) Also, we
5192 * prohibit changing these in a security-restricted operation because
5193 * otherwise RESET could be used to regain the session user's privileges.
5195 if (record->flags & GUC_NOT_WHILE_SEC_REST)
5197 if (InLocalUserIdChange())
5200 * Phrasing of this error message is historical, but it's the most
5204 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5205 errmsg("cannot set parameter \"%s\" within security-definer function",
5209 if (InSecurityRestrictedOperation())
5212 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5213 errmsg("cannot set parameter \"%s\" within security-restricted operation",
5220 * Should we set reset/stacked values? (If so, the behavior is not
5221 * transactional.) This is done either when we get a default value from
5222 * the database's/user's/client's default settings or when we reset a
5223 * value to its default.
5225 makeDefault = changeVal && (source <= PGC_S_OVERRIDE) &&
5226 ((value != NULL) || source == PGC_S_DEFAULT);
5229 * Ignore attempted set if overridden by previously processed setting.
5230 * However, if changeVal is false then plow ahead anyway since we are
5231 * trying to find out if the value is potentially good, not actually use
5232 * it. Also keep going if makeDefault is true, since we may want to set
5233 * the reset/stacked values even if we can't set the variable itself.
5235 if (record->source > source)
5237 if (changeVal && !makeDefault)
5239 elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
5247 * Evaluate value and set variable.
5249 switch (record->vartype)
5253 struct config_bool *conf = (struct config_bool *) record;
5255 void *newextra = NULL;
5259 if (!parse_bool(value, &newval))
5262 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5263 errmsg("parameter \"%s\" requires a Boolean value",
5267 if (!call_bool_check_hook(conf, &newval, &newextra,
5271 else if (source == PGC_S_DEFAULT)
5273 newval = conf->boot_val;
5274 if (!call_bool_check_hook(conf, &newval, &newextra,
5280 newval = conf->reset_val;
5281 newextra = conf->reset_extra;
5282 source = conf->gen.reset_source;
5283 context = conf->gen.reset_scontext;
5286 if (prohibitValueChange)
5288 if (*conf->variable != newval)
5291 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5292 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5301 /* Save old value to support transaction abort */
5303 push_old_value(&conf->gen, action);
5305 if (conf->assign_hook)
5306 (*conf->assign_hook) (newval, newextra);
5307 *conf->variable = newval;
5308 set_extra_field(&conf->gen, &conf->gen.extra,
5310 conf->gen.source = source;
5311 conf->gen.scontext = context;
5317 if (conf->gen.reset_source <= source)
5319 conf->reset_val = newval;
5320 set_extra_field(&conf->gen, &conf->reset_extra,
5322 conf->gen.reset_source = source;
5323 conf->gen.reset_scontext = context;
5325 for (stack = conf->gen.stack; stack; stack = stack->prev)
5327 if (stack->source <= source)
5329 stack->prior.val.boolval = newval;
5330 set_extra_field(&conf->gen, &stack->prior.extra,
5332 stack->source = source;
5333 stack->scontext = context;
5338 /* Perhaps we didn't install newextra anywhere */
5339 if (newextra && !extra_field_used(&conf->gen, newextra))
5346 struct config_int *conf = (struct config_int *) record;
5348 void *newextra = NULL;
5352 const char *hintmsg;
5354 if (!parse_int(value, &newval, conf->gen.flags, &hintmsg))
5357 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5358 errmsg("invalid value for parameter \"%s\": \"%s\"",
5360 hintmsg ? errhint("%s", _(hintmsg)) : 0));
5363 if (newval < conf->min || newval > conf->max)
5366 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5367 errmsg("%d is outside the valid range for parameter \"%s\" (%d .. %d)",
5368 newval, name, conf->min, conf->max)));
5371 if (!call_int_check_hook(conf, &newval, &newextra,
5375 else if (source == PGC_S_DEFAULT)
5377 newval = conf->boot_val;
5378 if (!call_int_check_hook(conf, &newval, &newextra,
5384 newval = conf->reset_val;
5385 newextra = conf->reset_extra;
5386 source = conf->gen.reset_source;
5387 context = conf->gen.reset_scontext;
5390 if (prohibitValueChange)
5392 if (*conf->variable != newval)
5395 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5396 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5405 /* Save old value to support transaction abort */
5407 push_old_value(&conf->gen, action);
5409 if (conf->assign_hook)
5410 (*conf->assign_hook) (newval, newextra);
5411 *conf->variable = newval;
5412 set_extra_field(&conf->gen, &conf->gen.extra,
5414 conf->gen.source = source;
5415 conf->gen.scontext = context;
5421 if (conf->gen.reset_source <= source)
5423 conf->reset_val = newval;
5424 set_extra_field(&conf->gen, &conf->reset_extra,
5426 conf->gen.reset_source = source;
5427 conf->gen.reset_scontext = context;
5429 for (stack = conf->gen.stack; stack; stack = stack->prev)
5431 if (stack->source <= source)
5433 stack->prior.val.intval = newval;
5434 set_extra_field(&conf->gen, &stack->prior.extra,
5436 stack->source = source;
5437 stack->scontext = context;
5442 /* Perhaps we didn't install newextra anywhere */
5443 if (newextra && !extra_field_used(&conf->gen, newextra))
5450 struct config_real *conf = (struct config_real *) record;
5452 void *newextra = NULL;
5456 if (!parse_real(value, &newval))
5459 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5460 errmsg("parameter \"%s\" requires a numeric value",
5464 if (newval < conf->min || newval > conf->max)
5467 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5468 errmsg("%g is outside the valid range for parameter \"%s\" (%g .. %g)",
5469 newval, name, conf->min, conf->max)));
5472 if (!call_real_check_hook(conf, &newval, &newextra,
5476 else if (source == PGC_S_DEFAULT)
5478 newval = conf->boot_val;
5479 if (!call_real_check_hook(conf, &newval, &newextra,
5485 newval = conf->reset_val;
5486 newextra = conf->reset_extra;
5487 source = conf->gen.reset_source;
5488 context = conf->gen.reset_scontext;
5491 if (prohibitValueChange)
5493 if (*conf->variable != newval)
5496 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5497 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5506 /* Save old value to support transaction abort */
5508 push_old_value(&conf->gen, action);
5510 if (conf->assign_hook)
5511 (*conf->assign_hook) (newval, newextra);
5512 *conf->variable = newval;
5513 set_extra_field(&conf->gen, &conf->gen.extra,
5515 conf->gen.source = source;
5516 conf->gen.scontext = context;
5522 if (conf->gen.reset_source <= source)
5524 conf->reset_val = newval;
5525 set_extra_field(&conf->gen, &conf->reset_extra,
5527 conf->gen.reset_source = source;
5528 conf->gen.reset_scontext = context;
5530 for (stack = conf->gen.stack; stack; stack = stack->prev)
5532 if (stack->source <= source)
5534 stack->prior.val.realval = newval;
5535 set_extra_field(&conf->gen, &stack->prior.extra,
5537 stack->source = source;
5538 stack->scontext = context;
5543 /* Perhaps we didn't install newextra anywhere */
5544 if (newextra && !extra_field_used(&conf->gen, newextra))
5551 struct config_string *conf = (struct config_string *) record;
5553 void *newextra = NULL;
5558 * The value passed by the caller could be transient, so
5559 * we always strdup it.
5561 newval = guc_strdup(elevel, value);
5566 * The only built-in "parsing" check we have is to apply
5567 * truncation if GUC_IS_NAME.
5569 if (conf->gen.flags & GUC_IS_NAME)
5570 truncate_identifier(newval, strlen(newval), true);
5572 if (!call_string_check_hook(conf, &newval, &newextra,
5579 else if (source == PGC_S_DEFAULT)
5581 /* non-NULL boot_val must always get strdup'd */
5582 if (conf->boot_val != NULL)
5584 newval = guc_strdup(elevel, conf->boot_val);
5591 if (!call_string_check_hook(conf, &newval, &newextra,
5601 * strdup not needed, since reset_val is already under
5604 newval = conf->reset_val;
5605 newextra = conf->reset_extra;
5606 source = conf->gen.reset_source;
5607 context = conf->gen.reset_scontext;
5610 if (prohibitValueChange)
5612 /* newval shouldn't be NULL, so we're a bit sloppy here */
5613 if (*conf->variable == NULL || newval == NULL ||
5614 strcmp(*conf->variable, newval) != 0)
5617 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5618 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5627 /* Save old value to support transaction abort */
5629 push_old_value(&conf->gen, action);
5631 if (conf->assign_hook)
5632 (*conf->assign_hook) (newval, newextra);
5633 set_string_field(conf, conf->variable, newval);
5634 set_extra_field(&conf->gen, &conf->gen.extra,
5636 conf->gen.source = source;
5637 conf->gen.scontext = context;
5644 if (conf->gen.reset_source <= source)
5646 set_string_field(conf, &conf->reset_val, newval);
5647 set_extra_field(&conf->gen, &conf->reset_extra,
5649 conf->gen.reset_source = source;
5650 conf->gen.reset_scontext = context;
5652 for (stack = conf->gen.stack; stack; stack = stack->prev)
5654 if (stack->source <= source)
5656 set_string_field(conf, &stack->prior.val.stringval,
5658 set_extra_field(&conf->gen, &stack->prior.extra,
5660 stack->source = source;
5661 stack->scontext = context;
5666 /* Perhaps we didn't install newval anywhere */
5667 if (newval && !string_field_used(conf, newval))
5669 /* Perhaps we didn't install newextra anywhere */
5670 if (newextra && !extra_field_used(&conf->gen, newextra))
5677 struct config_enum *conf = (struct config_enum *) record;
5679 void *newextra = NULL;
5683 if (!config_enum_lookup_by_name(conf, value, &newval))
5687 hintmsg = config_enum_get_options(conf,
5688 "Available values: ",
5692 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5693 errmsg("invalid value for parameter \"%s\": \"%s\"",
5695 hintmsg ? errhint("%s", _(hintmsg)) : 0));
5701 if (!call_enum_check_hook(conf, &newval, &newextra,
5705 else if (source == PGC_S_DEFAULT)
5707 newval = conf->boot_val;
5708 if (!call_enum_check_hook(conf, &newval, &newextra,
5714 newval = conf->reset_val;
5715 newextra = conf->reset_extra;
5716 source = conf->gen.reset_source;
5717 context = conf->gen.reset_scontext;
5720 if (prohibitValueChange)
5722 if (*conf->variable != newval)
5725 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5726 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5735 /* Save old value to support transaction abort */
5737 push_old_value(&conf->gen, action);
5739 if (conf->assign_hook)
5740 (*conf->assign_hook) (newval, newextra);
5741 *conf->variable = newval;
5742 set_extra_field(&conf->gen, &conf->gen.extra,
5744 conf->gen.source = source;
5745 conf->gen.scontext = context;
5751 if (conf->gen.reset_source <= source)
5753 conf->reset_val = newval;
5754 set_extra_field(&conf->gen, &conf->reset_extra,
5756 conf->gen.reset_source = source;
5757 conf->gen.reset_scontext = context;
5759 for (stack = conf->gen.stack; stack; stack = stack->prev)
5761 if (stack->source <= source)
5763 stack->prior.val.enumval = newval;
5764 set_extra_field(&conf->gen, &stack->prior.extra,
5766 stack->source = source;
5767 stack->scontext = context;
5772 /* Perhaps we didn't install newextra anywhere */
5773 if (newextra && !extra_field_used(&conf->gen, newextra))
5779 if (changeVal && (record->flags & GUC_REPORT))
5780 ReportGUCOption(record);
5782 return changeVal ? 1 : -1;
5787 * Set the fields for source file and line number the setting came from.
5790 set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
5792 struct config_generic *record;
5796 * To avoid cluttering the log, only the postmaster bleats loudly about
5797 * problems with the config file.
5799 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
5801 record = find_option(name, true, elevel);
5802 /* should not happen */
5804 elog(ERROR, "unrecognized configuration parameter \"%s\"", name);
5806 sourcefile = guc_strdup(elevel, sourcefile);
5807 if (record->sourcefile)
5808 free(record->sourcefile);
5809 record->sourcefile = sourcefile;
5810 record->sourceline = sourceline;
5814 * Set a config option to the given value.
5816 * See also set_config_option; this is just the wrapper to be called from
5817 * outside GUC. (This function should be used when possible, because its API
5818 * is more stable than set_config_option's.)
5820 * Note: there is no support here for setting source file/line, as it
5821 * is currently not needed.
5824 SetConfigOption(const char *name, const char *value,
5825 GucContext context, GucSource source)
5827 (void) set_config_option(name, value, context, source,
5828 GUC_ACTION_SET, true, 0);
5834 * Fetch the current value of the option `name', as a string.
5836 * If the option doesn't exist, return NULL if missing_ok is true (NOTE that
5837 * this cannot be distinguished from a string variable with a NULL value!),
5838 * otherwise throw an ereport and don't return.
5840 * If restrict_superuser is true, we also enforce that only superusers can
5841 * see GUC_SUPERUSER_ONLY variables. This should only be passed as true
5842 * in user-driven calls.
5844 * The string is *not* allocated for modification and is really only
5845 * valid until the next call to configuration related functions.
5848 GetConfigOption(const char *name, bool missing_ok, bool restrict_superuser)
5850 struct config_generic *record;
5851 static char buffer[256];
5853 record = find_option(name, false, ERROR);
5859 (errcode(ERRCODE_UNDEFINED_OBJECT),
5860 errmsg("unrecognized configuration parameter \"%s\"",
5863 if (restrict_superuser &&
5864 (record->flags & GUC_SUPERUSER_ONLY) &&
5867 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5868 errmsg("must be superuser to examine \"%s\"", name)));
5870 switch (record->vartype)
5873 return *((struct config_bool *) record)->variable ? "on" : "off";
5876 snprintf(buffer, sizeof(buffer), "%d",
5877 *((struct config_int *) record)->variable);
5881 snprintf(buffer, sizeof(buffer), "%g",
5882 *((struct config_real *) record)->variable);
5886 return *((struct config_string *) record)->variable;
5889 return config_enum_lookup_by_value((struct config_enum *) record,
5890 *((struct config_enum *) record)->variable);
5896 * Get the RESET value associated with the given option.
5898 * Note: this is not re-entrant, due to use of static result buffer;
5899 * not to mention that a string variable could have its reset_val changed.
5900 * Beware of assuming the result value is good for very long.
5903 GetConfigOptionResetString(const char *name)
5905 struct config_generic *record;
5906 static char buffer[256];
5908 record = find_option(name, false, ERROR);
5911 (errcode(ERRCODE_UNDEFINED_OBJECT),
5912 errmsg("unrecognized configuration parameter \"%s\"", name)));
5913 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
5915 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5916 errmsg("must be superuser to examine \"%s\"", name)));
5918 switch (record->vartype)
5921 return ((struct config_bool *) record)->reset_val ? "on" : "off";
5924 snprintf(buffer, sizeof(buffer), "%d",
5925 ((struct config_int *) record)->reset_val);
5929 snprintf(buffer, sizeof(buffer), "%g",
5930 ((struct config_real *) record)->reset_val);
5934 return ((struct config_string *) record)->reset_val;
5937 return config_enum_lookup_by_value((struct config_enum *) record,
5938 ((struct config_enum *) record)->reset_val);
5945 * flatten_set_variable_args
5946 * Given a parsenode List as emitted by the grammar for SET,
5947 * convert to the flat string representation used by GUC.
5949 * We need to be told the name of the variable the args are for, because
5950 * the flattening rules vary (ugh).
5952 * The result is NULL if args is NIL (ie, SET ... TO DEFAULT), otherwise
5953 * a palloc'd string.
5956 flatten_set_variable_args(const char *name, List *args)
5958 struct config_generic *record;
5963 /* Fast path if just DEFAULT */
5968 * Get flags for the variable; if it's not known, use default flags.
5969 * (Caller might throw error later, but not our business to do so here.)
5971 record = find_option(name, false, WARNING);
5973 flags = record->flags;
5977 /* Complain if list input and non-list variable */
5978 if ((flags & GUC_LIST_INPUT) == 0 &&
5979 list_length(args) != 1)
5981 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5982 errmsg("SET %s takes only one argument", name)));
5984 initStringInfo(&buf);
5987 * Each list member may be a plain A_Const node, or an A_Const within a
5988 * TypeCast; the latter case is supported only for ConstInterval arguments
5989 * (for SET TIME ZONE).
5993 Node *arg = (Node *) lfirst(l);
5995 TypeName *typeName = NULL;
5998 if (l != list_head(args))
5999 appendStringInfo(&buf, ", ");
6001 if (IsA(arg, TypeCast))
6003 TypeCast *tc = (TypeCast *) arg;
6006 typeName = tc->typeName;
6009 if (!IsA(arg, A_Const))
6010 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
6011 con = (A_Const *) arg;
6013 switch (nodeTag(&con->val))
6016 appendStringInfo(&buf, "%ld", intVal(&con->val));
6019 /* represented as a string, so just copy it */
6020 appendStringInfoString(&buf, strVal(&con->val));
6023 val = strVal(&con->val);
6024 if (typeName != NULL)
6027 * Must be a ConstInterval argument for TIME ZONE. Coerce
6028 * to interval and back to normalize the value and account
6036 typenameTypeIdAndMod(NULL, typeName, &typoid, &typmod);
6037 Assert(typoid == INTERVALOID);
6040 DirectFunctionCall3(interval_in,
6041 CStringGetDatum(val),
6042 ObjectIdGetDatum(InvalidOid),
6043 Int32GetDatum(typmod));
6046 DatumGetCString(DirectFunctionCall1(interval_out,
6048 appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
6053 * Plain string literal or identifier. For quote mode,
6054 * quote it if it's not a vanilla identifier.
6056 if (flags & GUC_LIST_QUOTE)
6057 appendStringInfoString(&buf, quote_identifier(val));
6059 appendStringInfoString(&buf, val);
6063 elog(ERROR, "unrecognized node type: %d",
6064 (int) nodeTag(&con->val));
6077 ExecSetVariableStmt(VariableSetStmt *stmt)
6079 GucAction action = stmt->is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET;
6084 case VAR_SET_CURRENT:
6085 (void) set_config_option(stmt->name,
6086 ExtractSetVariableArgs(stmt),
6087 (superuser() ? PGC_SUSET : PGC_USERSET),
6096 * Special case for special SQL syntax that effectively sets more
6097 * than one variable per statement.
6099 if (strcmp(stmt->name, "TRANSACTION") == 0)
6103 foreach(head, stmt->args)
6105 DefElem *item = (DefElem *) lfirst(head);
6107 if (strcmp(item->defname, "transaction_isolation") == 0)
6108 SetPGVariable("transaction_isolation",
6109 list_make1(item->arg), stmt->is_local);
6110 else if (strcmp(item->defname, "transaction_read_only") == 0)
6111 SetPGVariable("transaction_read_only",
6112 list_make1(item->arg), stmt->is_local);
6113 else if (strcmp(item->defname, "transaction_deferrable") == 0)
6114 SetPGVariable("transaction_deferrable",
6115 list_make1(item->arg), stmt->is_local);
6117 elog(ERROR, "unexpected SET TRANSACTION element: %s",
6121 else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
6125 foreach(head, stmt->args)
6127 DefElem *item = (DefElem *) lfirst(head);
6129 if (strcmp(item->defname, "transaction_isolation") == 0)
6130 SetPGVariable("default_transaction_isolation",
6131 list_make1(item->arg), stmt->is_local);
6132 else if (strcmp(item->defname, "transaction_read_only") == 0)
6133 SetPGVariable("default_transaction_read_only",
6134 list_make1(item->arg), stmt->is_local);
6135 else if (strcmp(item->defname, "transaction_deferrable") == 0)
6136 SetPGVariable("default_transaction_deferrable",
6137 list_make1(item->arg), stmt->is_local);
6139 elog(ERROR, "unexpected SET SESSION element: %s",
6144 elog(ERROR, "unexpected SET MULTI element: %s",
6147 case VAR_SET_DEFAULT:
6149 (void) set_config_option(stmt->name,
6151 (superuser() ? PGC_SUSET : PGC_USERSET),
6164 * Get the value to assign for a VariableSetStmt, or NULL if it's RESET.
6165 * The result is palloc'd.
6167 * This is exported for use by actions such as ALTER ROLE SET.
6170 ExtractSetVariableArgs(VariableSetStmt *stmt)
6175 return flatten_set_variable_args(stmt->name, stmt->args);
6176 case VAR_SET_CURRENT:
6177 return GetConfigOptionByName(stmt->name, NULL);
6184 * SetPGVariable - SET command exported as an easily-C-callable function.
6186 * This provides access to SET TO value, as well as SET TO DEFAULT (expressed
6187 * by passing args == NIL), but not SET FROM CURRENT functionality.
6190 SetPGVariable(const char *name, List *args, bool is_local)
6192 char *argstring = flatten_set_variable_args(name, args);
6194 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
6195 (void) set_config_option(name,
6197 (superuser() ? PGC_SUSET : PGC_USERSET),
6199 is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET,
6205 * SET command wrapped as a SQL callable function.
6208 set_config_by_name(PG_FUNCTION_ARGS)
6215 if (PG_ARGISNULL(0))
6217 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
6218 errmsg("SET requires parameter name")));
6220 /* Get the GUC variable name */
6221 name = TextDatumGetCString(PG_GETARG_DATUM(0));
6223 /* Get the desired value or set to NULL for a reset request */
6224 if (PG_ARGISNULL(1))
6227 value = TextDatumGetCString(PG_GETARG_DATUM(1));
6230 * Get the desired state of is_local. Default to false if provided value
6233 if (PG_ARGISNULL(2))
6236 is_local = PG_GETARG_BOOL(2);
6238 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
6239 (void) set_config_option(name,
6241 (superuser() ? PGC_SUSET : PGC_USERSET),
6243 is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET,
6247 /* get the new current value */
6248 new_value = GetConfigOptionByName(name, NULL);
6250 /* Convert return string to text */
6251 PG_RETURN_TEXT_P(cstring_to_text(new_value));
6256 * Common code for DefineCustomXXXVariable subroutines: allocate the
6257 * new variable's config struct and fill in generic fields.
6259 static struct config_generic *
6260 init_custom_variable(const char *name,
6261 const char *short_desc,
6262 const char *long_desc,
6265 enum config_type type,
6268 struct config_generic *gen;
6271 * Only allow custom PGC_POSTMASTER variables to be created during shared
6272 * library preload; any later than that, we can't ensure that the value
6273 * doesn't change after startup. This is a fatal elog if it happens; just
6274 * erroring out isn't safe because we don't know what the calling loadable
6275 * module might already have hooked into.
6277 if (context == PGC_POSTMASTER &&
6278 !process_shared_preload_libraries_in_progress)
6279 elog(FATAL, "cannot create PGC_POSTMASTER variables after startup");
6281 gen = (struct config_generic *) guc_malloc(ERROR, sz);
6284 gen->name = guc_strdup(ERROR, name);
6285 gen->context = context;
6286 gen->group = CUSTOM_OPTIONS;
6287 gen->short_desc = short_desc;
6288 gen->long_desc = long_desc;
6290 gen->vartype = type;
6296 * Common code for DefineCustomXXXVariable subroutines: insert the new
6297 * variable into the GUC variable array, replacing any placeholder.
6300 define_custom_variable(struct config_generic * variable)
6302 const char *name = variable->name;
6303 const char **nameAddr = &name;
6304 struct config_string *pHolder;
6305 struct config_generic **res;
6308 * See if there's a placeholder by the same name.
6310 res = (struct config_generic **) bsearch((void *) &nameAddr,
6311 (void *) guc_variables,
6313 sizeof(struct config_generic *),
6318 * No placeholder to replace, so we can just add it ... but first,
6319 * make sure it's initialized to its default value.
6321 InitializeOneGUCOption(variable);
6322 add_guc_variable(variable, ERROR);
6327 * This better be a placeholder
6329 if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
6331 (errcode(ERRCODE_INTERNAL_ERROR),
6332 errmsg("attempt to redefine parameter \"%s\"", name)));
6334 Assert((*res)->vartype == PGC_STRING);
6335 pHolder = (struct config_string *) (*res);
6338 * First, set the variable to its default value. We must do this even
6339 * though we intend to immediately apply a new value, since it's possible
6340 * that the new value is invalid.
6342 InitializeOneGUCOption(variable);
6345 * Replace the placeholder. We aren't changing the name, so no re-sorting
6351 * Assign the string value(s) stored in the placeholder to the real
6352 * variable. Essentially, we need to duplicate all the active and stacked
6353 * values, but with appropriate validation and datatype adjustment.
6355 * If an assignment fails, we report a WARNING and keep going. We don't
6356 * want to throw ERROR for bad values, because it'd bollix the add-on
6357 * module that's presumably halfway through getting loaded. In such cases
6358 * the default or previous state will become active instead.
6361 /* First, apply the reset value if any */
6362 if (pHolder->reset_val)
6363 (void) set_config_option(name, pHolder->reset_val,
6364 pHolder->gen.reset_scontext,
6365 pHolder->gen.reset_source,
6366 GUC_ACTION_SET, true, WARNING);
6367 /* That should not have resulted in stacking anything */
6368 Assert(variable->stack == NULL);
6370 /* Now, apply current and stacked values, in the order they were stacked */
6371 reapply_stacked_values(variable, pHolder, pHolder->gen.stack,
6372 *(pHolder->variable),
6373 pHolder->gen.scontext, pHolder->gen.source);
6375 /* Also copy over any saved source-location information */
6376 if (pHolder->gen.sourcefile)
6377 set_config_sourcefile(name, pHolder->gen.sourcefile,
6378 pHolder->gen.sourceline);
6381 * Free up as much as we conveniently can of the placeholder structure.
6382 * (This neglects any stack items, so it's possible for some memory to be
6383 * leaked. Since this can only happen once per session per variable, it
6384 * doesn't seem worth spending much code on.)
6386 set_string_field(pHolder, pHolder->variable, NULL);
6387 set_string_field(pHolder, &pHolder->reset_val, NULL);
6393 * Recursive subroutine for define_custom_variable: reapply non-reset values
6395 * We recurse so that the values are applied in the same order as originally.
6396 * At each recursion level, apply the upper-level value (passed in) in the
6397 * fashion implied by the stack entry.
6400 reapply_stacked_values(struct config_generic * variable,
6401 struct config_string *pHolder,
6403 const char *curvalue,
6404 GucContext curscontext, GucSource cursource)
6406 const char *name = variable->name;
6407 GucStack *oldvarstack = variable->stack;
6411 /* First, recurse, so that stack items are processed bottom to top */
6412 reapply_stacked_values(variable, pHolder, stack->prev,
6413 stack->prior.val.stringval,
6414 stack->scontext, stack->source);
6416 /* See how to apply the passed-in value */
6417 switch (stack->state)
6420 (void) set_config_option(name, curvalue,
6421 curscontext, cursource,
6422 GUC_ACTION_SAVE, true, WARNING);
6426 (void) set_config_option(name, curvalue,
6427 curscontext, cursource,
6428 GUC_ACTION_SET, true, WARNING);
6432 (void) set_config_option(name, curvalue,
6433 curscontext, cursource,
6434 GUC_ACTION_LOCAL, true, WARNING);
6438 /* first, apply the masked value as SET */
6439 (void) set_config_option(name, stack->masked.val.stringval,
6440 stack->masked_scontext, PGC_S_SESSION,
6441 GUC_ACTION_SET, true, WARNING);
6442 /* then apply the current value as LOCAL */
6443 (void) set_config_option(name, curvalue,
6444 curscontext, cursource,
6445 GUC_ACTION_LOCAL, true, WARNING);
6449 /* If we successfully made a stack entry, adjust its nest level */
6450 if (variable->stack != oldvarstack)
6451 variable->stack->nest_level = stack->nest_level;
6456 * We are at the end of the stack. If the active/previous value is
6457 * different from the reset value, it must represent a previously
6458 * committed session value. Apply it, and then drop the stack entry
6459 * that set_config_option will have created under the impression that
6460 * this is to be just a transactional assignment. (We leak the stack
6463 if (curvalue != pHolder->reset_val ||
6464 curscontext != pHolder->gen.reset_scontext ||
6465 cursource != pHolder->gen.reset_source)
6467 (void) set_config_option(name, curvalue,
6468 curscontext, cursource,
6469 GUC_ACTION_SET, true, WARNING);
6470 variable->stack = NULL;
6476 DefineCustomBoolVariable(const char *name,
6477 const char *short_desc,
6478 const char *long_desc,
6483 GucBoolCheckHook check_hook,
6484 GucBoolAssignHook assign_hook,
6485 GucShowHook show_hook)
6487 struct config_bool *var;
6489 var = (struct config_bool *)
6490 init_custom_variable(name, short_desc, long_desc, context, flags,
6491 PGC_BOOL, sizeof(struct config_bool));
6492 var->variable = valueAddr;
6493 var->boot_val = bootValue;
6494 var->reset_val = bootValue;
6495 var->check_hook = check_hook;
6496 var->assign_hook = assign_hook;
6497 var->show_hook = show_hook;
6498 define_custom_variable(&var->gen);
6502 DefineCustomIntVariable(const char *name,
6503 const char *short_desc,
6504 const char *long_desc,
6511 GucIntCheckHook check_hook,
6512 GucIntAssignHook assign_hook,
6513 GucShowHook show_hook)
6515 struct config_int *var;
6517 var = (struct config_int *)
6518 init_custom_variable(name, short_desc, long_desc, context, flags,
6519 PGC_INT, sizeof(struct config_int));
6520 var->variable = valueAddr;
6521 var->boot_val = bootValue;
6522 var->reset_val = bootValue;
6523 var->min = minValue;
6524 var->max = maxValue;
6525 var->check_hook = check_hook;
6526 var->assign_hook = assign_hook;
6527 var->show_hook = show_hook;
6528 define_custom_variable(&var->gen);
6532 DefineCustomRealVariable(const char *name,
6533 const char *short_desc,
6534 const char *long_desc,
6541 GucRealCheckHook check_hook,
6542 GucRealAssignHook assign_hook,
6543 GucShowHook show_hook)
6545 struct config_real *var;
6547 var = (struct config_real *)
6548 init_custom_variable(name, short_desc, long_desc, context, flags,
6549 PGC_REAL, sizeof(struct config_real));
6550 var->variable = valueAddr;
6551 var->boot_val = bootValue;
6552 var->reset_val = bootValue;
6553 var->min = minValue;
6554 var->max = maxValue;
6555 var->check_hook = check_hook;
6556 var->assign_hook = assign_hook;
6557 var->show_hook = show_hook;
6558 define_custom_variable(&var->gen);
6562 DefineCustomStringVariable(const char *name,
6563 const char *short_desc,
6564 const char *long_desc,
6566 const char *bootValue,
6569 GucStringCheckHook check_hook,
6570 GucStringAssignHook assign_hook,
6571 GucShowHook show_hook)
6573 struct config_string *var;
6575 var = (struct config_string *)
6576 init_custom_variable(name, short_desc, long_desc, context, flags,
6577 PGC_STRING, sizeof(struct config_string));
6578 var->variable = valueAddr;
6579 var->boot_val = bootValue;
6580 var->check_hook = check_hook;
6581 var->assign_hook = assign_hook;
6582 var->show_hook = show_hook;
6583 define_custom_variable(&var->gen);
6587 DefineCustomEnumVariable(const char *name,
6588 const char *short_desc,
6589 const char *long_desc,
6592 const struct config_enum_entry * options,
6595 GucEnumCheckHook check_hook,
6596 GucEnumAssignHook assign_hook,
6597 GucShowHook show_hook)
6599 struct config_enum *var;
6601 var = (struct config_enum *)
6602 init_custom_variable(name, short_desc, long_desc, context, flags,
6603 PGC_ENUM, sizeof(struct config_enum));
6604 var->variable = valueAddr;
6605 var->boot_val = bootValue;
6606 var->reset_val = bootValue;
6607 var->options = options;
6608 var->check_hook = check_hook;
6609 var->assign_hook = assign_hook;
6610 var->show_hook = show_hook;
6611 define_custom_variable(&var->gen);
6615 EmitWarningsOnPlaceholders(const char *className)
6617 int classLen = strlen(className);
6620 for (i = 0; i < num_guc_variables; i++)
6622 struct config_generic *var = guc_variables[i];
6624 if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
6625 strncmp(className, var->name, classLen) == 0 &&
6626 var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
6629 (errcode(ERRCODE_UNDEFINED_OBJECT),
6630 errmsg("unrecognized configuration parameter \"%s\"",
6641 GetPGVariable(const char *name, DestReceiver *dest)
6643 if (guc_name_compare(name, "all") == 0)
6644 ShowAllGUCConfig(dest);
6646 ShowGUCConfigOption(name, dest);
6650 GetPGVariableResultDesc(const char *name)
6654 if (guc_name_compare(name, "all") == 0)
6656 /* need a tuple descriptor representing three TEXT columns */
6657 tupdesc = CreateTemplateTupleDesc(3, false);
6658 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
6660 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
6662 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
6667 const char *varname;
6669 /* Get the canonical spelling of name */
6670 (void) GetConfigOptionByName(name, &varname);
6672 /* need a tuple descriptor representing a single TEXT column */
6673 tupdesc = CreateTemplateTupleDesc(1, false);
6674 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
6685 ShowGUCConfigOption(const char *name, DestReceiver *dest)
6687 TupOutputState *tstate;
6689 const char *varname;
6692 /* Get the value and canonical spelling of name */
6693 value = GetConfigOptionByName(name, &varname);
6695 /* need a tuple descriptor representing a single TEXT column */
6696 tupdesc = CreateTemplateTupleDesc(1, false);
6697 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
6700 /* prepare for projection of tuples */
6701 tstate = begin_tup_output_tupdesc(dest, tupdesc);
6704 do_text_output_oneline(tstate, value);
6706 end_tup_output(tstate);
6713 ShowAllGUCConfig(DestReceiver *dest)
6715 bool am_superuser = superuser();
6717 TupOutputState *tstate;
6720 bool isnull[3] = {false, false, false};
6722 /* need a tuple descriptor representing three TEXT columns */
6723 tupdesc = CreateTemplateTupleDesc(3, false);
6724 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
6726 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
6728 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
6731 /* prepare for projection of tuples */
6732 tstate = begin_tup_output_tupdesc(dest, tupdesc);
6734 for (i = 0; i < num_guc_variables; i++)
6736 struct config_generic *conf = guc_variables[i];
6739 if ((conf->flags & GUC_NO_SHOW_ALL) ||
6740 ((conf->flags & GUC_SUPERUSER_ONLY) && !am_superuser))
6743 /* assign to the values array */
6744 values[0] = PointerGetDatum(cstring_to_text(conf->name));
6746 setting = _ShowOption(conf, true);
6749 values[1] = PointerGetDatum(cstring_to_text(setting));
6754 values[1] = PointerGetDatum(NULL);
6758 values[2] = PointerGetDatum(cstring_to_text(conf->short_desc));
6760 /* send it to dest */
6761 do_tup_output(tstate, values, isnull);
6764 pfree(DatumGetPointer(values[0]));
6768 pfree(DatumGetPointer(values[1]));
6770 pfree(DatumGetPointer(values[2]));
6773 end_tup_output(tstate);
6777 * Return GUC variable value by name; optionally return canonical
6778 * form of name. Return value is palloc'd.
6781 GetConfigOptionByName(const char *name, const char **varname)
6783 struct config_generic *record;
6785 record = find_option(name, false, ERROR);
6788 (errcode(ERRCODE_UNDEFINED_OBJECT),
6789 errmsg("unrecognized configuration parameter \"%s\"", name)));
6790 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
6792 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6793 errmsg("must be superuser to examine \"%s\"", name)));
6796 *varname = record->name;
6798 return _ShowOption(record, true);
6802 * Return GUC variable value by variable number; optionally return canonical
6803 * form of name. Return value is palloc'd.
6806 GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
6809 struct config_generic *conf;
6811 /* check requested variable number valid */
6812 Assert((varnum >= 0) && (varnum < num_guc_variables));
6814 conf = guc_variables[varnum];
6818 if ((conf->flags & GUC_NO_SHOW_ALL) ||
6819 ((conf->flags & GUC_SUPERUSER_ONLY) && !superuser()))
6825 /* first get the generic attributes */
6828 values[0] = conf->name;
6830 /* setting : use _ShowOption in order to avoid duplicating the logic */
6831 values[1] = _ShowOption(conf, false);
6834 if (conf->vartype == PGC_INT)
6838 switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
6843 case GUC_UNIT_BLOCKS:
6844 snprintf(buf, sizeof(buf), "%dkB", BLCKSZ / 1024);
6847 case GUC_UNIT_XBLOCKS:
6848 snprintf(buf, sizeof(buf), "%dkB", XLOG_BLCKSZ / 1024);
6869 values[3] = config_group_names[conf->group];
6872 values[4] = conf->short_desc;
6875 values[5] = conf->long_desc;
6878 values[6] = GucContext_Names[conf->context];
6881 values[7] = config_type_names[conf->vartype];
6884 values[8] = GucSource_Names[conf->source];
6886 /* now get the type specifc attributes */
6887 switch (conf->vartype)
6891 struct config_bool *lconf = (struct config_bool *) conf;
6903 values[12] = pstrdup(lconf->boot_val ? "on" : "off");
6906 values[13] = pstrdup(lconf->reset_val ? "on" : "off");
6912 struct config_int *lconf = (struct config_int *) conf;
6915 snprintf(buffer, sizeof(buffer), "%d", lconf->min);
6916 values[9] = pstrdup(buffer);
6919 snprintf(buffer, sizeof(buffer), "%d", lconf->max);
6920 values[10] = pstrdup(buffer);
6926 snprintf(buffer, sizeof(buffer), "%d", lconf->boot_val);
6927 values[12] = pstrdup(buffer);
6930 snprintf(buffer, sizeof(buffer), "%d", lconf->reset_val);
6931 values[13] = pstrdup(buffer);
6937 struct config_real *lconf = (struct config_real *) conf;
6940 snprintf(buffer, sizeof(buffer), "%g", lconf->min);
6941 values[9] = pstrdup(buffer);
6944 snprintf(buffer, sizeof(buffer), "%g", lconf->max);
6945 values[10] = pstrdup(buffer);
6951 snprintf(buffer, sizeof(buffer), "%g", lconf->boot_val);
6952 values[12] = pstrdup(buffer);
6955 snprintf(buffer, sizeof(buffer), "%g", lconf->reset_val);
6956 values[13] = pstrdup(buffer);
6962 struct config_string *lconf = (struct config_string *) conf;
6974 if (lconf->boot_val == NULL)
6977 values[12] = pstrdup(lconf->boot_val);
6980 if (lconf->reset_val == NULL)
6983 values[13] = pstrdup(lconf->reset_val);
6989 struct config_enum *lconf = (struct config_enum *) conf;
7000 * NOTE! enumvals with double quotes in them are not
7003 values[11] = config_enum_get_options((struct config_enum *) conf,
7004 "{\"", "\"}", "\",\"");
7007 values[12] = pstrdup(config_enum_lookup_by_value(lconf,
7011 values[13] = pstrdup(config_enum_lookup_by_value(lconf,
7019 * should never get here, but in case we do, set 'em to NULL
7041 * If the setting came from a config file, set the source location. For
7042 * security reasons, we don't show source file/line number for
7045 if (conf->source == PGC_S_FILE && superuser())
7047 values[14] = conf->sourcefile;
7048 snprintf(buffer, sizeof(buffer), "%d", conf->sourceline);
7049 values[15] = pstrdup(buffer);
7059 * Return the total number of GUC variables
7062 GetNumConfigOptions(void)
7064 return num_guc_variables;
7068 * show_config_by_name - equiv to SHOW X command but implemented as
7072 show_config_by_name(PG_FUNCTION_ARGS)
7077 /* Get the GUC variable name */
7078 varname = TextDatumGetCString(PG_GETARG_DATUM(0));
7081 varval = GetConfigOptionByName(varname, NULL);
7083 /* Convert to text */
7084 PG_RETURN_TEXT_P(cstring_to_text(varval));
7088 * show_all_settings - equiv to SHOW ALL command but implemented as
7091 #define NUM_PG_SETTINGS_ATTS 16
7094 show_all_settings(PG_FUNCTION_ARGS)
7096 FuncCallContext *funcctx;
7100 AttInMetadata *attinmeta;
7101 MemoryContext oldcontext;
7103 /* stuff done only on the first call of the function */
7104 if (SRF_IS_FIRSTCALL())
7106 /* create a function context for cross-call persistence */
7107 funcctx = SRF_FIRSTCALL_INIT();
7110 * switch to memory context appropriate for multiple function calls
7112 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
7115 * need a tuple descriptor representing NUM_PG_SETTINGS_ATTS columns
7116 * of the appropriate types
7118 tupdesc = CreateTemplateTupleDesc(NUM_PG_SETTINGS_ATTS, false);
7119 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
7121 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
7123 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "unit",
7125 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "category",
7127 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "short_desc",
7129 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "extra_desc",
7131 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "context",
7133 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "vartype",
7135 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "source",
7137 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "min_val",
7139 TupleDescInitEntry(tupdesc, (AttrNumber) 11, "max_val",
7141 TupleDescInitEntry(tupdesc, (AttrNumber) 12, "enumvals",
7142 TEXTARRAYOID, -1, 0);
7143 TupleDescInitEntry(tupdesc, (AttrNumber) 13, "boot_val",
7145 TupleDescInitEntry(tupdesc, (AttrNumber) 14, "reset_val",
7147 TupleDescInitEntry(tupdesc, (AttrNumber) 15, "sourcefile",
7149 TupleDescInitEntry(tupdesc, (AttrNumber) 16, "sourceline",
7153 * Generate attribute metadata needed later to produce tuples from raw
7156 attinmeta = TupleDescGetAttInMetadata(tupdesc);
7157 funcctx->attinmeta = attinmeta;
7159 /* total number of tuples to be returned */
7160 funcctx->max_calls = GetNumConfigOptions();
7162 MemoryContextSwitchTo(oldcontext);
7165 /* stuff done on every call of the function */
7166 funcctx = SRF_PERCALL_SETUP();
7168 call_cntr = funcctx->call_cntr;
7169 max_calls = funcctx->max_calls;
7170 attinmeta = funcctx->attinmeta;
7172 if (call_cntr < max_calls) /* do when there is more left to send */
7174 char *values[NUM_PG_SETTINGS_ATTS];
7180 * Get the next visible GUC variable name and value
7184 GetConfigOptionByNum(call_cntr, (const char **) values, &noshow);
7187 /* bump the counter and get the next config setting */
7188 call_cntr = ++funcctx->call_cntr;
7190 /* make sure we haven't gone too far now */
7191 if (call_cntr >= max_calls)
7192 SRF_RETURN_DONE(funcctx);
7197 tuple = BuildTupleFromCStrings(attinmeta, values);
7199 /* make the tuple into a datum */
7200 result = HeapTupleGetDatum(tuple);
7202 SRF_RETURN_NEXT(funcctx, result);
7206 /* do when there is no more left */
7207 SRF_RETURN_DONE(funcctx);
7212 _ShowOption(struct config_generic * record, bool use_units)
7217 switch (record->vartype)
7221 struct config_bool *conf = (struct config_bool *) record;
7223 if (conf->show_hook)
7224 val = (*conf->show_hook) ();
7226 val = *conf->variable ? "on" : "off";
7232 struct config_int *conf = (struct config_int *) record;
7234 if (conf->show_hook)
7235 val = (*conf->show_hook) ();
7239 * Use int64 arithmetic to avoid overflows in units
7242 int64 result = *conf->variable;
7245 if (use_units && result > 0 &&
7246 (record->flags & GUC_UNIT_MEMORY))
7248 switch (record->flags & GUC_UNIT_MEMORY)
7250 case GUC_UNIT_BLOCKS:
7251 result *= BLCKSZ / 1024;
7253 case GUC_UNIT_XBLOCKS:
7254 result *= XLOG_BLCKSZ / 1024;
7258 if (result % KB_PER_GB == 0)
7260 result /= KB_PER_GB;
7263 else if (result % KB_PER_MB == 0)
7265 result /= KB_PER_MB;
7273 else if (use_units && result > 0 &&
7274 (record->flags & GUC_UNIT_TIME))
7276 switch (record->flags & GUC_UNIT_TIME)
7282 result *= MS_PER_MIN;
7286 if (result % MS_PER_D == 0)
7291 else if (result % MS_PER_H == 0)
7296 else if (result % MS_PER_MIN == 0)
7298 result /= MS_PER_MIN;
7301 else if (result % MS_PER_S == 0)
7314 snprintf(buffer, sizeof(buffer), INT64_FORMAT "%s",
7323 struct config_real *conf = (struct config_real *) record;
7325 if (conf->show_hook)
7326 val = (*conf->show_hook) ();
7329 snprintf(buffer, sizeof(buffer), "%g",
7338 struct config_string *conf = (struct config_string *) record;
7340 if (conf->show_hook)
7341 val = (*conf->show_hook) ();
7342 else if (*conf->variable && **conf->variable)
7343 val = *conf->variable;
7351 struct config_enum *conf = (struct config_enum *) record;
7353 if (conf->show_hook)
7354 val = (*conf->show_hook) ();
7356 val = config_enum_lookup_by_value(conf, *conf->variable);
7361 /* just to keep compiler quiet */
7366 return pstrdup(val);
7373 * These routines dump out all non-default GUC options into a binary
7374 * file that is read by all exec'ed backends. The format is:
7376 * variable name, string, null terminated
7377 * variable value, string, null terminated
7378 * variable sourcefile, string, null terminated (empty if none)
7379 * variable sourceline, integer
7380 * variable source, integer
7381 * variable scontext, integer
7384 write_one_nondefault_variable(FILE *fp, struct config_generic * gconf)
7386 if (gconf->source == PGC_S_DEFAULT)
7389 fprintf(fp, "%s", gconf->name);
7392 switch (gconf->vartype)
7396 struct config_bool *conf = (struct config_bool *) gconf;
7398 if (*conf->variable)
7399 fprintf(fp, "true");
7401 fprintf(fp, "false");
7407 struct config_int *conf = (struct config_int *) gconf;
7409 fprintf(fp, "%d", *conf->variable);
7415 struct config_real *conf = (struct config_real *) gconf;
7417 fprintf(fp, "%.17g", *conf->variable);
7423 struct config_string *conf = (struct config_string *) gconf;
7425 fprintf(fp, "%s", *conf->variable);
7431 struct config_enum *conf = (struct config_enum *) gconf;
7434 config_enum_lookup_by_value(conf, *conf->variable));
7441 if (gconf->sourcefile)
7442 fprintf(fp, "%s", gconf->sourcefile);
7445 fwrite(&gconf->sourceline, 1, sizeof(gconf->sourceline), fp);
7446 fwrite(&gconf->source, 1, sizeof(gconf->source), fp);
7447 fwrite(&gconf->scontext, 1, sizeof(gconf->scontext), fp);
7451 write_nondefault_variables(GucContext context)
7457 Assert(context == PGC_POSTMASTER || context == PGC_SIGHUP);
7459 elevel = (context == PGC_SIGHUP) ? LOG : ERROR;
7464 fp = AllocateFile(CONFIG_EXEC_PARAMS_NEW, "w");
7468 (errcode_for_file_access(),
7469 errmsg("could not write to file \"%s\": %m",
7470 CONFIG_EXEC_PARAMS_NEW)));
7474 for (i = 0; i < num_guc_variables; i++)
7476 write_one_nondefault_variable(fp, guc_variables[i]);
7482 (errcode_for_file_access(),
7483 errmsg("could not write to file \"%s\": %m",
7484 CONFIG_EXEC_PARAMS_NEW)));
7489 * Put new file in place. This could delay on Win32, but we don't hold
7490 * any exclusive locks.
7492 rename(CONFIG_EXEC_PARAMS_NEW, CONFIG_EXEC_PARAMS);
7497 * Read string, including null byte from file
7499 * Return NULL on EOF and nothing read
7502 read_string_with_null(FILE *fp)
7511 if ((ch = fgetc(fp)) == EOF)
7516 elog(FATAL, "invalid format of exec config params file");
7519 str = guc_malloc(FATAL, maxlen);
7520 else if (i == maxlen)
7521 str = guc_realloc(FATAL, str, maxlen *= 2);
7530 * This routine loads a previous postmaster dump of its non-default
7534 read_nondefault_variables(void)
7541 GucSource varsource;
7542 GucContext varscontext;
7547 fp = AllocateFile(CONFIG_EXEC_PARAMS, "r");
7550 /* File not found is fine */
7551 if (errno != ENOENT)
7553 (errcode_for_file_access(),
7554 errmsg("could not read from file \"%s\": %m",
7555 CONFIG_EXEC_PARAMS)));
7561 struct config_generic *record;
7563 if ((varname = read_string_with_null(fp)) == NULL)
7566 if ((record = find_option(varname, true, FATAL)) == NULL)
7567 elog(FATAL, "failed to locate variable \"%s\" in exec config params file", varname);
7569 if ((varvalue = read_string_with_null(fp)) == NULL)
7570 elog(FATAL, "invalid format of exec config params file");
7571 if ((varsourcefile = read_string_with_null(fp)) == NULL)
7572 elog(FATAL, "invalid format of exec config params file");
7573 if (fread(&varsourceline, 1, sizeof(varsourceline), fp) != sizeof(varsourceline))
7574 elog(FATAL, "invalid format of exec config params file");
7575 if (fread(&varsource, 1, sizeof(varsource), fp) != sizeof(varsource))
7576 elog(FATAL, "invalid format of exec config params file");
7577 if (fread(&varscontext, 1, sizeof(varscontext), fp) != sizeof(varscontext))
7578 elog(FATAL, "invalid format of exec config params file");
7580 (void) set_config_option(varname, varvalue,
7581 varscontext, varsource,
7582 GUC_ACTION_SET, true, 0);
7583 if (varsourcefile[0])
7584 set_config_sourcefile(varname, varsourcefile, varsourceline);
7588 free(varsourcefile);
7593 #endif /* EXEC_BACKEND */
7597 * A little "long argument" simulation, although not quite GNU
7598 * compliant. Takes a string of the form "some-option=some value" and
7599 * returns name = "some_option" and value = "some value" in malloc'ed
7600 * storage. Note that '-' is converted to '_' in the option name. If
7601 * there is no '=' in the input string then value will be NULL.
7604 ParseLongOption(const char *string, char **name, char **value)
7613 equal_pos = strcspn(string, "=");
7615 if (string[equal_pos] == '=')
7617 *name = guc_malloc(FATAL, equal_pos + 1);
7618 strlcpy(*name, string, equal_pos + 1);
7620 *value = guc_strdup(FATAL, &string[equal_pos + 1]);
7624 /* no equal sign in string */
7625 *name = guc_strdup(FATAL, string);
7629 for (cp = *name; *cp; cp++)
7636 * Handle options fetched from pg_db_role_setting.setconfig,
7637 * pg_proc.proconfig, etc. Caller must specify proper context/source/action.
7639 * The array parameter must be an array of TEXT (it must not be NULL).
7642 ProcessGUCArray(ArrayType *array,
7643 GucContext context, GucSource source, GucAction action)
7647 Assert(array != NULL);
7648 Assert(ARR_ELEMTYPE(array) == TEXTOID);
7649 Assert(ARR_NDIM(array) == 1);
7650 Assert(ARR_LBOUND(array)[0] == 1);
7652 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
7660 d = array_ref(array, 1, &i,
7661 -1 /* varlenarray */ ,
7662 -1 /* TEXT's typlen */ ,
7663 false /* TEXT's typbyval */ ,
7664 'i' /* TEXT's typalign */ ,
7670 s = TextDatumGetCString(d);
7672 ParseLongOption(s, &name, &value);
7676 (errcode(ERRCODE_SYNTAX_ERROR),
7677 errmsg("could not parse setting for parameter \"%s\"",
7683 (void) set_config_option(name, value,
7696 * Add an entry to an option array. The array parameter may be NULL
7697 * to indicate the current table entry is NULL.
7700 GUCArrayAdd(ArrayType *array, const char *name, const char *value)
7702 struct config_generic *record;
7710 /* test if the option is valid and we're allowed to set it */
7711 (void) validate_option_array_item(name, value, false);
7713 /* normalize name (converts obsolete GUC names to modern spellings) */
7714 record = find_option(name, false, WARNING);
7716 name = record->name;
7718 /* build new item for array */
7719 newval = palloc(strlen(name) + 1 + strlen(value) + 1);
7720 sprintf(newval, "%s=%s", name, value);
7721 datum = CStringGetTextDatum(newval);
7729 Assert(ARR_ELEMTYPE(array) == TEXTOID);
7730 Assert(ARR_NDIM(array) == 1);
7731 Assert(ARR_LBOUND(array)[0] == 1);
7733 index = ARR_DIMS(array)[0] + 1; /* add after end */
7735 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
7740 d = array_ref(array, 1, &i,
7741 -1 /* varlenarray */ ,
7742 -1 /* TEXT's typlen */ ,
7743 false /* TEXT's typbyval */ ,
7744 'i' /* TEXT's typalign */ ,
7748 current = TextDatumGetCString(d);
7750 /* check for match up through and including '=' */
7751 if (strncmp(current, newval, strlen(name) + 1) == 0)
7758 a = array_set(array, 1, &index,
7761 -1 /* varlena array */ ,
7762 -1 /* TEXT's typlen */ ,
7763 false /* TEXT's typbyval */ ,
7764 'i' /* TEXT's typalign */ );
7767 a = construct_array(&datum, 1,
7776 * Delete an entry from an option array. The array parameter may be NULL
7777 * to indicate the current table entry is NULL. Also, if the return value
7778 * is NULL then a null should be stored.
7781 GUCArrayDelete(ArrayType *array, const char *name)
7783 struct config_generic *record;
7784 ArrayType *newarray;
7790 /* test if the option is valid and we're allowed to set it */
7791 (void) validate_option_array_item(name, NULL, false);
7793 /* normalize name (converts obsolete GUC names to modern spellings) */
7794 record = find_option(name, false, WARNING);
7796 name = record->name;
7798 /* if array is currently null, then surely nothing to delete */
7805 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
7811 d = array_ref(array, 1, &i,
7812 -1 /* varlenarray */ ,
7813 -1 /* TEXT's typlen */ ,
7814 false /* TEXT's typbyval */ ,
7815 'i' /* TEXT's typalign */ ,
7819 val = TextDatumGetCString(d);
7821 /* ignore entry if it's what we want to delete */
7822 if (strncmp(val, name, strlen(name)) == 0
7823 && val[strlen(name)] == '=')
7826 /* else add it to the output array */
7828 newarray = array_set(newarray, 1, &index,
7831 -1 /* varlenarray */ ,
7832 -1 /* TEXT's typlen */ ,
7833 false /* TEXT's typbyval */ ,
7834 'i' /* TEXT's typalign */ );
7836 newarray = construct_array(&d, 1,
7848 * Given a GUC array, delete all settings from it that our permission
7849 * level allows: if superuser, delete them all; if regular user, only
7850 * those that are PGC_USERSET
7853 GUCArrayReset(ArrayType *array)
7855 ArrayType *newarray;
7859 /* if array is currently null, nothing to do */
7863 /* if we're superuser, we can delete everything, so just do it */
7870 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
7877 d = array_ref(array, 1, &i,
7878 -1 /* varlenarray */ ,
7879 -1 /* TEXT's typlen */ ,
7880 false /* TEXT's typbyval */ ,
7881 'i' /* TEXT's typalign */ ,
7885 val = TextDatumGetCString(d);
7887 eqsgn = strchr(val, '=');
7890 /* skip if we have permission to delete it */
7891 if (validate_option_array_item(val, NULL, true))
7894 /* else add it to the output array */
7896 newarray = array_set(newarray, 1, &index,
7899 -1 /* varlenarray */ ,
7900 -1 /* TEXT's typlen */ ,
7901 false /* TEXT's typbyval */ ,
7902 'i' /* TEXT's typalign */ );
7904 newarray = construct_array(&d, 1,
7916 * Validate a proposed option setting for GUCArrayAdd/Delete/Reset.
7918 * name is the option name. value is the proposed value for the Add case,
7919 * or NULL for the Delete/Reset cases. If skipIfNoPermissions is true, it's
7920 * not an error to have no permissions to set the option.
7922 * Returns TRUE if OK, FALSE if skipIfNoPermissions is true and user does not
7923 * have permission to change this option (all other error cases result in an
7924 * error being thrown).
7927 validate_option_array_item(const char *name, const char *value,
7928 bool skipIfNoPermissions)
7931 struct config_generic *gconf;
7934 * There are three cases to consider:
7936 * name is a known GUC variable. Check the value normally, check
7937 * permissions normally (ie, allow if variable is USERSET, or if it's
7938 * SUSET and user is superuser).
7940 * name is not known, but exists or can be created as a placeholder (i.e.,
7941 * it has a prefixed name). We allow this case if you're a superuser,
7942 * otherwise not. Superusers are assumed to know what they're doing.
7943 * We can't allow it for other users, because when the placeholder is
7944 * resolved it might turn out to be a SUSET variable;
7945 * define_custom_variable assumes we checked that.
7947 * name is not known and can't be created as a placeholder. Throw error,
7948 * unless skipIfNoPermissions is true, in which case return FALSE.
7950 gconf = find_option(name, true, WARNING);
7953 /* not known, failed to make a placeholder */
7954 if (skipIfNoPermissions)
7957 (errcode(ERRCODE_UNDEFINED_OBJECT),
7958 errmsg("unrecognized configuration parameter \"%s\"",
7962 if (gconf->flags & GUC_CUSTOM_PLACEHOLDER)
7965 * We cannot do any meaningful check on the value, so only permissions
7966 * are useful to check.
7970 if (skipIfNoPermissions)
7973 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7974 errmsg("permission denied to set parameter \"%s\"", name)));
7977 /* manual permissions check so we can avoid an error being thrown */
7978 if (gconf->context == PGC_USERSET)
7980 else if (gconf->context == PGC_SUSET && superuser())
7982 else if (skipIfNoPermissions)
7984 /* if a permissions error should be thrown, let set_config_option do it */
7986 /* test for permissions and valid option value */
7987 (void) set_config_option(name, value,
7988 superuser() ? PGC_SUSET : PGC_USERSET,
7989 PGC_S_TEST, GUC_ACTION_SET, false, 0);
7996 * Called by check_hooks that want to override the normal
7997 * ERRCODE_INVALID_PARAMETER_VALUE SQLSTATE for check hook failures.
7999 * Note that GUC_check_errmsg() etc are just macros that result in a direct
8000 * assignment to the associated variables. That is ugly, but forced by the
8001 * limitations of C's macro mechanisms.
8004 GUC_check_errcode(int sqlerrcode)
8006 GUC_check_errcode_value = sqlerrcode;
8011 * Convenience functions to manage calling a variable's check_hook.
8012 * These mostly take care of the protocol for letting check hooks supply
8013 * portions of the error report on failure.
8017 call_bool_check_hook(struct config_bool * conf, bool *newval, void **extra,
8018 GucSource source, int elevel)
8020 /* Quick success if no hook */
8021 if (!conf->check_hook)
8024 /* Reset variables that might be set by hook */
8025 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8026 GUC_check_errmsg_string = NULL;
8027 GUC_check_errdetail_string = NULL;
8028 GUC_check_errhint_string = NULL;
8030 if (!(*conf->check_hook) (newval, extra, source))
8033 (errcode(GUC_check_errcode_value),
8034 GUC_check_errmsg_string ?
8035 errmsg_internal("%s", GUC_check_errmsg_string) :
8036 errmsg("invalid value for parameter \"%s\": %d",
8037 conf->gen.name, (int) *newval),
8038 GUC_check_errdetail_string ?
8039 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
8040 GUC_check_errhint_string ?
8041 errhint("%s", GUC_check_errhint_string) : 0));
8042 /* Flush any strings created in ErrorContext */
8051 call_int_check_hook(struct config_int * conf, int *newval, void **extra,
8052 GucSource source, int elevel)
8054 /* Quick success if no hook */
8055 if (!conf->check_hook)
8058 /* Reset variables that might be set by hook */
8059 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8060 GUC_check_errmsg_string = NULL;
8061 GUC_check_errdetail_string = NULL;
8062 GUC_check_errhint_string = NULL;
8064 if (!(*conf->check_hook) (newval, extra, source))
8067 (errcode(GUC_check_errcode_value),
8068 GUC_check_errmsg_string ?
8069 errmsg_internal("%s", GUC_check_errmsg_string) :
8070 errmsg("invalid value for parameter \"%s\": %d",
8071 conf->gen.name, *newval),
8072 GUC_check_errdetail_string ?
8073 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
8074 GUC_check_errhint_string ?
8075 errhint("%s", GUC_check_errhint_string) : 0));
8076 /* Flush any strings created in ErrorContext */
8085 call_real_check_hook(struct config_real * conf, double *newval, void **extra,
8086 GucSource source, int elevel)
8088 /* Quick success if no hook */
8089 if (!conf->check_hook)
8092 /* Reset variables that might be set by hook */
8093 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8094 GUC_check_errmsg_string = NULL;
8095 GUC_check_errdetail_string = NULL;
8096 GUC_check_errhint_string = NULL;
8098 if (!(*conf->check_hook) (newval, extra, source))
8101 (errcode(GUC_check_errcode_value),
8102 GUC_check_errmsg_string ?
8103 errmsg_internal("%s", GUC_check_errmsg_string) :
8104 errmsg("invalid value for parameter \"%s\": %g",
8105 conf->gen.name, *newval),
8106 GUC_check_errdetail_string ?
8107 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
8108 GUC_check_errhint_string ?
8109 errhint("%s", GUC_check_errhint_string) : 0));
8110 /* Flush any strings created in ErrorContext */
8119 call_string_check_hook(struct config_string * conf, char **newval, void **extra,
8120 GucSource source, int elevel)
8122 /* Quick success if no hook */
8123 if (!conf->check_hook)
8126 /* Reset variables that might be set by hook */
8127 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8128 GUC_check_errmsg_string = NULL;
8129 GUC_check_errdetail_string = NULL;
8130 GUC_check_errhint_string = NULL;
8132 if (!(*conf->check_hook) (newval, extra, source))
8135 (errcode(GUC_check_errcode_value),
8136 GUC_check_errmsg_string ?
8137 errmsg_internal("%s", GUC_check_errmsg_string) :
8138 errmsg("invalid value for parameter \"%s\": \"%s\"",
8139 conf->gen.name, *newval ? *newval : ""),
8140 GUC_check_errdetail_string ?
8141 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
8142 GUC_check_errhint_string ?
8143 errhint("%s", GUC_check_errhint_string) : 0));
8144 /* Flush any strings created in ErrorContext */
8153 call_enum_check_hook(struct config_enum * conf, int *newval, void **extra,
8154 GucSource source, int elevel)
8156 /* Quick success if no hook */
8157 if (!conf->check_hook)
8160 /* Reset variables that might be set by hook */
8161 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8162 GUC_check_errmsg_string = NULL;
8163 GUC_check_errdetail_string = NULL;
8164 GUC_check_errhint_string = NULL;
8166 if (!(*conf->check_hook) (newval, extra, source))
8169 (errcode(GUC_check_errcode_value),
8170 GUC_check_errmsg_string ?
8171 errmsg_internal("%s", GUC_check_errmsg_string) :
8172 errmsg("invalid value for parameter \"%s\": \"%s\"",
8174 config_enum_lookup_by_value(conf, *newval)),
8175 GUC_check_errdetail_string ?
8176 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
8177 GUC_check_errhint_string ?
8178 errhint("%s", GUC_check_errhint_string) : 0));
8179 /* Flush any strings created in ErrorContext */
8189 * check_hook, assign_hook and show_hook subroutines
8193 check_log_destination(char **newval, void **extra, GucSource source)
8201 /* Need a modifiable copy of string */
8202 rawstring = pstrdup(*newval);
8204 /* Parse string into list of identifiers */
8205 if (!SplitIdentifierString(rawstring, ',', &elemlist))
8207 /* syntax error in list */
8208 GUC_check_errdetail("List syntax is invalid.");
8210 list_free(elemlist);
8214 foreach(l, elemlist)
8216 char *tok = (char *) lfirst(l);
8218 if (pg_strcasecmp(tok, "stderr") == 0)
8219 newlogdest |= LOG_DESTINATION_STDERR;
8220 else if (pg_strcasecmp(tok, "csvlog") == 0)
8221 newlogdest |= LOG_DESTINATION_CSVLOG;
8223 else if (pg_strcasecmp(tok, "syslog") == 0)
8224 newlogdest |= LOG_DESTINATION_SYSLOG;
8227 else if (pg_strcasecmp(tok, "eventlog") == 0)
8228 newlogdest |= LOG_DESTINATION_EVENTLOG;
8232 GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
8234 list_free(elemlist);
8240 list_free(elemlist);
8242 myextra = (int *) guc_malloc(ERROR, sizeof(int));
8243 *myextra = newlogdest;
8244 *extra = (void *) myextra;
8250 assign_log_destination(const char *newval, void *extra)
8252 Log_destination = *((int *) extra);
8256 assign_syslog_facility(int newval, void *extra)
8259 set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
8262 /* Without syslog support, just ignore it */
8266 assign_syslog_ident(const char *newval, void *extra)
8269 set_syslog_parameters(newval, syslog_facility);
8271 /* Without syslog support, it will always be set to "none", so ignore */
8276 assign_session_replication_role(int newval, void *extra)
8279 * Must flush the plan cache when changing replication role; but don't
8280 * flush unnecessarily.
8282 if (SessionReplicationRole != newval)
8287 check_temp_buffers(int *newval, void **extra, GucSource source)
8290 * Once local buffers have been initialized, it's too late to change this.
8292 if (NLocBuffer && NLocBuffer != *newval)
8294 GUC_check_errdetail("\"temp_buffers\" cannot be changed after any temporary tables have been accessed in the session.");
8301 check_phony_autocommit(bool *newval, void **extra, GucSource source)
8305 GUC_check_errcode(ERRCODE_FEATURE_NOT_SUPPORTED);
8306 GUC_check_errmsg("SET AUTOCOMMIT TO OFF is no longer supported");
8313 check_debug_assertions(bool *newval, void **extra, GucSource source)
8315 #ifndef USE_ASSERT_CHECKING
8318 GUC_check_errmsg("assertion checking is not supported by this build");
8326 check_bonjour(bool *newval, void **extra, GucSource source)
8331 GUC_check_errmsg("Bonjour is not supported by this build");
8339 check_ssl(bool *newval, void **extra, GucSource source)
8344 GUC_check_errmsg("SSL is not supported by this build");
8352 check_stage_log_stats(bool *newval, void **extra, GucSource source)
8354 if (*newval && log_statement_stats)
8356 GUC_check_errdetail("Cannot enable parameter when \"log_statement_stats\" is true.");
8363 check_log_stats(bool *newval, void **extra, GucSource source)
8366 (log_parser_stats || log_planner_stats || log_executor_stats))
8368 GUC_check_errdetail("Cannot enable \"log_statement_stats\" when "
8369 "\"log_parser_stats\", \"log_planner_stats\", "
8370 "or \"log_executor_stats\" is true.");
8377 check_canonical_path(char **newval, void **extra, GucSource source)
8380 * Since canonicalize_path never enlarges the string, we can just modify
8381 * newval in-place. But watch out for NULL, which is the default value
8382 * for external_pid_file.
8385 canonicalize_path(*newval);
8390 check_timezone_abbreviations(char **newval, void **extra, GucSource source)
8393 * The boot_val given above for timezone_abbreviations is NULL. When we
8394 * see this we just do nothing. If this value isn't overridden from the
8395 * config file then pg_timezone_abbrev_initialize() will eventually
8396 * replace it with "Default". This hack has two purposes: to avoid
8397 * wasting cycles loading values that might soon be overridden from the
8398 * config file, and to avoid trying to read the timezone abbrev files
8399 * during InitializeGUCOptions(). The latter doesn't work in an
8400 * EXEC_BACKEND subprocess because my_exec_path hasn't been set yet and so
8401 * we can't locate PGSHAREDIR.
8403 if (*newval == NULL)
8405 Assert(source == PGC_S_DEFAULT);
8409 /* OK, load the file and produce a malloc'd TimeZoneAbbrevTable */
8410 *extra = load_tzoffsets(*newval);
8412 /* tzparser.c returns NULL on failure, reporting via GUC_check_errmsg */
8420 assign_timezone_abbreviations(const char *newval, void *extra)
8422 /* Do nothing for the boot_val default of NULL */
8426 InstallTimeZoneAbbrevs((TimeZoneAbbrevTable *) extra);
8430 * pg_timezone_abbrev_initialize --- set default value if not done already
8432 * This is called after initial loading of postgresql.conf. If no
8433 * timezone_abbreviations setting was found therein, select default.
8434 * If a non-default value is already installed, nothing will happen.
8436 * This can also be called from ProcessConfigFile to establish the default
8437 * value after a postgresql.conf entry for it is removed.
8440 pg_timezone_abbrev_initialize(void)
8442 SetConfigOption("timezone_abbreviations", "Default",
8443 PGC_POSTMASTER, PGC_S_DYNAMIC_DEFAULT);
8447 show_archive_command(void)
8449 if (XLogArchivingActive())
8450 return XLogArchiveCommand;
8452 return "(disabled)";
8456 assign_tcp_keepalives_idle(int newval, void *extra)
8459 * The kernel API provides no way to test a value without setting it; and
8460 * once we set it we might fail to unset it. So there seems little point
8461 * in fully implementing the check-then-assign GUC API for these
8462 * variables. Instead we just do the assignment on demand. pqcomm.c
8463 * reports any problems via elog(LOG).
8465 * This approach means that the GUC value might have little to do with the
8466 * actual kernel value, so we use a show_hook that retrieves the kernel
8467 * value rather than trusting GUC's copy.
8469 (void) pq_setkeepalivesidle(newval, MyProcPort);
8473 show_tcp_keepalives_idle(void)
8475 /* See comments in assign_tcp_keepalives_idle */
8476 static char nbuf[16];
8478 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesidle(MyProcPort));
8483 assign_tcp_keepalives_interval(int newval, void *extra)
8485 /* See comments in assign_tcp_keepalives_idle */
8486 (void) pq_setkeepalivesinterval(newval, MyProcPort);
8490 show_tcp_keepalives_interval(void)
8492 /* See comments in assign_tcp_keepalives_idle */
8493 static char nbuf[16];
8495 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesinterval(MyProcPort));
8500 assign_tcp_keepalives_count(int newval, void *extra)
8502 /* See comments in assign_tcp_keepalives_idle */
8503 (void) pq_setkeepalivescount(newval, MyProcPort);
8507 show_tcp_keepalives_count(void)
8509 /* See comments in assign_tcp_keepalives_idle */
8510 static char nbuf[16];
8512 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivescount(MyProcPort));
8517 check_maxconnections(int *newval, void **extra, GucSource source)
8519 if (*newval + autovacuum_max_workers + 1 > MAX_BACKENDS)
8525 assign_maxconnections(int newval, void *extra)
8527 MaxBackends = newval + autovacuum_max_workers + 1;
8531 check_autovacuum_max_workers(int *newval, void **extra, GucSource source)
8533 if (MaxConnections + *newval + 1 > MAX_BACKENDS)
8539 assign_autovacuum_max_workers(int newval, void *extra)
8541 MaxBackends = MaxConnections + newval + 1;
8545 check_effective_io_concurrency(int *newval, void **extra, GucSource source)
8548 double new_prefetch_pages = 0.0;
8552 * The user-visible GUC parameter is the number of drives (spindles),
8553 * which we need to translate to a number-of-pages-to-prefetch target.
8554 * The target value is stashed in *extra and then assigned to the actual
8555 * variable by assign_effective_io_concurrency.
8557 * The expected number of prefetch pages needed to keep N drives busy is:
8559 * drives | I/O requests
8560 * -------+----------------
8563 * 3 | 3/1 + 3/2 + 3/3 = 5 1/2
8564 * 4 | 4/1 + 4/2 + 4/3 + 4/4 = 8 1/3
8567 * This is called the "coupon collector problem" and H(n) is called the
8568 * harmonic series. This could be approximated by n * ln(n), but for
8569 * reasonable numbers of drives we might as well just compute the series.
8571 * Alternatively we could set the target to the number of pages necessary
8572 * so that the expected number of active spindles is some arbitrary
8573 * percentage of the total. This sounds the same but is actually slightly
8574 * different. The result ends up being ln(1-P)/ln((n-1)/n) where P is
8575 * that desired fraction.
8577 * Experimental results show that both of these formulas aren't aggressive
8578 * enough, but we don't really have any better proposals.
8580 * Note that if *newval = 0 (disabled), we must set target = 0.
8584 for (i = 1; i <= *newval; i++)
8585 new_prefetch_pages += (double) *newval / (double) i;
8587 /* This range check shouldn't fail, but let's be paranoid */
8588 if (new_prefetch_pages >= 0.0 && new_prefetch_pages < (double) INT_MAX)
8590 int *myextra = (int *) guc_malloc(ERROR, sizeof(int));
8592 *myextra = (int) rint(new_prefetch_pages);
8593 *extra = (void *) myextra;
8601 #endif /* USE_PREFETCH */
8605 assign_effective_io_concurrency(int newval, void *extra)
8608 target_prefetch_pages = *((int *) extra);
8609 #endif /* USE_PREFETCH */
8613 assign_pgstat_temp_directory(const char *newval, void *extra)
8615 /* check_canonical_path already canonicalized newval for us */
8619 tname = guc_malloc(ERROR, strlen(newval) + 12); /* /pgstat.tmp */
8620 sprintf(tname, "%s/pgstat.tmp", newval);
8621 fname = guc_malloc(ERROR, strlen(newval) + 13); /* /pgstat.stat */
8622 sprintf(fname, "%s/pgstat.stat", newval);
8624 if (pgstat_stat_tmpname)
8625 free(pgstat_stat_tmpname);
8626 pgstat_stat_tmpname = tname;
8627 if (pgstat_stat_filename)
8628 free(pgstat_stat_filename);
8629 pgstat_stat_filename = fname;
8633 check_application_name(char **newval, void **extra, GucSource source)
8635 /* Only allow clean ASCII chars in the application name */
8638 for (p = *newval; *p; p++)
8640 if (*p < 32 || *p > 126)
8648 assign_application_name(const char *newval, void *extra)
8650 /* Update the pg_stat_activity view */
8651 pgstat_report_appname(newval);
8655 show_unix_socket_permissions(void)
8659 snprintf(buf, sizeof(buf), "%04o", Unix_socket_permissions);
8664 show_log_file_mode(void)
8668 snprintf(buf, sizeof(buf), "%04o", Log_file_mode);
8672 #include "guc-file.c"