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_bitmapscan", PGC_USERSET, QUERY_TUNING_METHOD,
686 gettext_noop("Enables the planner's use of bitmap-scan plans."),
694 {"enable_tidscan", PGC_USERSET, QUERY_TUNING_METHOD,
695 gettext_noop("Enables the planner's use of TID scan plans."),
703 {"enable_sort", PGC_USERSET, QUERY_TUNING_METHOD,
704 gettext_noop("Enables the planner's use of explicit sort steps."),
712 {"enable_hashagg", PGC_USERSET, QUERY_TUNING_METHOD,
713 gettext_noop("Enables the planner's use of hashed aggregation plans."),
721 {"enable_material", PGC_USERSET, QUERY_TUNING_METHOD,
722 gettext_noop("Enables the planner's use of materialization."),
730 {"enable_nestloop", PGC_USERSET, QUERY_TUNING_METHOD,
731 gettext_noop("Enables the planner's use of nested-loop join plans."),
739 {"enable_mergejoin", PGC_USERSET, QUERY_TUNING_METHOD,
740 gettext_noop("Enables the planner's use of merge join plans."),
748 {"enable_hashjoin", PGC_USERSET, QUERY_TUNING_METHOD,
749 gettext_noop("Enables the planner's use of hash join plans."),
757 {"geqo", PGC_USERSET, QUERY_TUNING_GEQO,
758 gettext_noop("Enables genetic query optimization."),
759 gettext_noop("This algorithm attempts to do planning without "
760 "exhaustive searching.")
767 /* Not for general use --- used by SET SESSION AUTHORIZATION */
768 {"is_superuser", PGC_INTERNAL, UNGROUPED,
769 gettext_noop("Shows whether the current user is a superuser."),
771 GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
773 &session_auth_is_superuser,
778 {"bonjour", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
779 gettext_noop("Enables advertising the server via Bonjour."),
784 check_bonjour, NULL, NULL
787 {"ssl", PGC_POSTMASTER, CONN_AUTH_SECURITY,
788 gettext_noop("Enables SSL connections."),
793 check_ssl, NULL, NULL
796 {"fsync", PGC_SIGHUP, WAL_SETTINGS,
797 gettext_noop("Forces synchronization of updates to disk."),
798 gettext_noop("The server will use the fsync() system call in several places to make "
799 "sure that updates are physically written to disk. This insures "
800 "that a database cluster will recover to a consistent state after "
801 "an operating system or hardware crash.")
808 {"zero_damaged_pages", PGC_SUSET, DEVELOPER_OPTIONS,
809 gettext_noop("Continues processing past damaged page headers."),
810 gettext_noop("Detection of a damaged page header normally causes PostgreSQL to "
811 "report an error, aborting the current transaction. Setting "
812 "zero_damaged_pages to true causes the system to instead report a "
813 "warning, zero out the damaged page, and continue processing. This "
814 "behavior will destroy data, namely all the rows on the damaged page."),
822 {"full_page_writes", PGC_SIGHUP, WAL_SETTINGS,
823 gettext_noop("Writes full pages to WAL when first modified after a checkpoint."),
824 gettext_noop("A page write in process during an operating system crash might be "
825 "only partially written to disk. During recovery, the row changes "
826 "stored in WAL are not enough to recover. This option writes "
827 "pages when first modified after a checkpoint to WAL so full recovery "
835 {"log_checkpoints", PGC_SIGHUP, LOGGING_WHAT,
836 gettext_noop("Logs each checkpoint."),
844 {"log_connections", PGC_BACKEND, LOGGING_WHAT,
845 gettext_noop("Logs each successful connection."),
853 {"log_disconnections", PGC_BACKEND, LOGGING_WHAT,
854 gettext_noop("Logs end of a session, including duration."),
862 {"debug_assertions", PGC_USERSET, DEVELOPER_OPTIONS,
863 gettext_noop("Turns on various assertion checks."),
864 gettext_noop("This is a debugging aid."),
868 #ifdef USE_ASSERT_CHECKING
873 check_debug_assertions, NULL, NULL
877 {"exit_on_error", PGC_USERSET, ERROR_HANDLING_OPTIONS,
878 gettext_noop("Terminate session on any error."),
886 {"restart_after_crash", PGC_SIGHUP, ERROR_HANDLING_OPTIONS,
887 gettext_noop("Reinitialize server after backend crash."),
890 &restart_after_crash,
896 {"log_duration", PGC_SUSET, LOGGING_WHAT,
897 gettext_noop("Logs the duration of each completed SQL statement."),
905 {"debug_print_parse", PGC_USERSET, LOGGING_WHAT,
906 gettext_noop("Logs each query's parse tree."),
914 {"debug_print_rewritten", PGC_USERSET, LOGGING_WHAT,
915 gettext_noop("Logs each query's rewritten parse tree."),
918 &Debug_print_rewritten,
923 {"debug_print_plan", PGC_USERSET, LOGGING_WHAT,
924 gettext_noop("Logs each query's execution plan."),
932 {"debug_pretty_print", PGC_USERSET, LOGGING_WHAT,
933 gettext_noop("Indents parse and plan tree displays."),
941 {"log_parser_stats", PGC_SUSET, STATS_MONITORING,
942 gettext_noop("Writes parser performance statistics to the server log."),
947 check_stage_log_stats, NULL, NULL
950 {"log_planner_stats", PGC_SUSET, STATS_MONITORING,
951 gettext_noop("Writes planner performance statistics to the server log."),
956 check_stage_log_stats, NULL, NULL
959 {"log_executor_stats", PGC_SUSET, STATS_MONITORING,
960 gettext_noop("Writes executor performance statistics to the server log."),
965 check_stage_log_stats, NULL, NULL
968 {"log_statement_stats", PGC_SUSET, STATS_MONITORING,
969 gettext_noop("Writes cumulative performance statistics to the server log."),
972 &log_statement_stats,
974 check_log_stats, NULL, NULL
976 #ifdef BTREE_BUILD_STATS
978 {"log_btree_build_stats", PGC_SUSET, DEVELOPER_OPTIONS,
979 gettext_noop("No description available."),
983 &log_btree_build_stats,
990 {"track_activities", PGC_SUSET, STATS_COLLECTOR,
991 gettext_noop("Collects information about executing commands."),
992 gettext_noop("Enables the collection of information on the currently "
993 "executing command of each session, along with "
994 "the time at which that command began execution.")
996 &pgstat_track_activities,
1001 {"track_counts", PGC_SUSET, STATS_COLLECTOR,
1002 gettext_noop("Collects statistics on database activity."),
1005 &pgstat_track_counts,
1011 {"update_process_title", PGC_SUSET, STATS_COLLECTOR,
1012 gettext_noop("Updates the process title to show the active SQL command."),
1013 gettext_noop("Enables updating of the process title every time a new SQL command is received by the server.")
1015 &update_process_title,
1021 {"autovacuum", PGC_SIGHUP, AUTOVACUUM,
1022 gettext_noop("Starts the autovacuum subprocess."),
1025 &autovacuum_start_daemon,
1031 {"trace_notify", PGC_USERSET, DEVELOPER_OPTIONS,
1032 gettext_noop("Generates debugging output for LISTEN and NOTIFY."),
1043 {"trace_locks", PGC_SUSET, DEVELOPER_OPTIONS,
1044 gettext_noop("No description available."),
1053 {"trace_userlocks", PGC_SUSET, DEVELOPER_OPTIONS,
1054 gettext_noop("No description available."),
1063 {"trace_lwlocks", PGC_SUSET, DEVELOPER_OPTIONS,
1064 gettext_noop("No description available."),
1073 {"debug_deadlocks", PGC_SUSET, DEVELOPER_OPTIONS,
1074 gettext_noop("No description available."),
1085 {"log_lock_waits", PGC_SUSET, LOGGING_WHAT,
1086 gettext_noop("Logs long lock waits."),
1095 {"log_hostname", PGC_SIGHUP, LOGGING_WHAT,
1096 gettext_noop("Logs the host name in the connection logs."),
1097 gettext_noop("By default, connection logs only show the IP address "
1098 "of the connecting host. If you want them to show the host name you "
1099 "can turn this on, but depending on your host name resolution "
1100 "setup it might impose a non-negligible performance penalty.")
1107 {"sql_inheritance", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1108 gettext_noop("Causes subtables to be included by default in various commands."),
1116 {"password_encryption", PGC_USERSET, CONN_AUTH_SECURITY,
1117 gettext_noop("Encrypt passwords."),
1118 gettext_noop("When a password is specified in CREATE USER or "
1119 "ALTER USER without writing either ENCRYPTED or UNENCRYPTED, "
1120 "this parameter determines whether the password is to be encrypted.")
1122 &Password_encryption,
1127 {"transform_null_equals", PGC_USERSET, COMPAT_OPTIONS_CLIENT,
1128 gettext_noop("Treats \"expr=NULL\" as \"expr IS NULL\"."),
1129 gettext_noop("When turned on, expressions of the form expr = NULL "
1130 "(or NULL = expr) are treated as expr IS NULL, that is, they "
1131 "return true if expr evaluates to the null value, and false "
1132 "otherwise. The correct behavior of expr = NULL is to always "
1133 "return null (unknown).")
1135 &Transform_null_equals,
1140 {"db_user_namespace", PGC_SIGHUP, CONN_AUTH_SECURITY,
1141 gettext_noop("Enables per-database user names."),
1149 /* only here for backwards compatibility */
1150 {"autocommit", PGC_USERSET, CLIENT_CONN_STATEMENT,
1151 gettext_noop("This parameter doesn't do anything."),
1152 gettext_noop("It's just here so that we won't choke on SET AUTOCOMMIT TO ON from 7.3-vintage clients."),
1153 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
1157 check_phony_autocommit, NULL, NULL
1160 {"default_transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
1161 gettext_noop("Sets the default read-only status of new transactions."),
1164 &DefaultXactReadOnly,
1169 {"transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
1170 gettext_noop("Sets the current transaction's read-only status."),
1172 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1176 check_transaction_read_only, NULL, NULL
1179 {"default_transaction_deferrable", PGC_USERSET, CLIENT_CONN_STATEMENT,
1180 gettext_noop("Sets the default deferrable status of new transactions."),
1183 &DefaultXactDeferrable,
1188 {"transaction_deferrable", PGC_USERSET, CLIENT_CONN_STATEMENT,
1189 gettext_noop("Whether to defer a read-only serializable transaction until it can be executed with no possible serialization failures."),
1191 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1195 check_transaction_deferrable, NULL, NULL
1198 {"check_function_bodies", PGC_USERSET, CLIENT_CONN_STATEMENT,
1199 gettext_noop("Check function bodies during CREATE FUNCTION."),
1202 &check_function_bodies,
1207 {"array_nulls", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1208 gettext_noop("Enable input of NULL elements in arrays."),
1209 gettext_noop("When turned on, unquoted NULL in an array input "
1210 "value means a null value; "
1211 "otherwise it is taken literally.")
1218 {"default_with_oids", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1219 gettext_noop("Create new tables with OIDs by default."),
1227 {"logging_collector", PGC_POSTMASTER, LOGGING_WHERE,
1228 gettext_noop("Start a subprocess to capture stderr output and/or csvlogs into log files."),
1236 {"log_truncate_on_rotation", PGC_SIGHUP, LOGGING_WHERE,
1237 gettext_noop("Truncate existing log files of same name during log rotation."),
1240 &Log_truncate_on_rotation,
1247 {"trace_sort", PGC_USERSET, DEVELOPER_OPTIONS,
1248 gettext_noop("Emit information about resource usage in sorting."),
1258 #ifdef TRACE_SYNCSCAN
1259 /* this is undocumented because not exposed in a standard build */
1261 {"trace_syncscan", PGC_USERSET, DEVELOPER_OPTIONS,
1262 gettext_noop("Generate debugging output for synchronized scanning."),
1272 #ifdef DEBUG_BOUNDED_SORT
1273 /* this is undocumented because not exposed in a standard build */
1276 "optimize_bounded_sort", PGC_USERSET, QUERY_TUNING_METHOD,
1277 gettext_noop("Enable bounded sorting using heap sort."),
1281 &optimize_bounded_sort,
1289 {"wal_debug", PGC_SUSET, DEVELOPER_OPTIONS,
1290 gettext_noop("Emit WAL-related debugging output."),
1301 {"integer_datetimes", PGC_INTERNAL, PRESET_OPTIONS,
1302 gettext_noop("Datetimes are integer based."),
1304 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1307 #ifdef HAVE_INT64_TIMESTAMP
1316 {"krb_caseins_users", PGC_SIGHUP, CONN_AUTH_SECURITY,
1317 gettext_noop("Sets whether Kerberos and GSSAPI user names should be treated as case-insensitive."),
1320 &pg_krb_caseins_users,
1326 {"escape_string_warning", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1327 gettext_noop("Warn about backslash escapes in ordinary string literals."),
1330 &escape_string_warning,
1336 {"standard_conforming_strings", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1337 gettext_noop("Causes '...' strings to treat backslashes literally."),
1341 &standard_conforming_strings,
1347 {"synchronize_seqscans", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1348 gettext_noop("Enable synchronized sequential scans."),
1351 &synchronize_seqscans,
1357 {"archive_mode", PGC_POSTMASTER, WAL_ARCHIVING,
1358 gettext_noop("Allows archiving of WAL files using archive_command."),
1367 {"hot_standby", PGC_POSTMASTER, REPLICATION_STANDBY,
1368 gettext_noop("Allows connections and queries during recovery."),
1377 {"hot_standby_feedback", PGC_SIGHUP, REPLICATION_STANDBY,
1378 gettext_noop("Allows feedback from a hot standby to the primary that will avoid query conflicts."),
1381 &hot_standby_feedback,
1387 {"allow_system_table_mods", PGC_POSTMASTER, DEVELOPER_OPTIONS,
1388 gettext_noop("Allows modifications of the structure of system tables."),
1392 &allowSystemTableMods,
1398 {"ignore_system_indexes", PGC_BACKEND, DEVELOPER_OPTIONS,
1399 gettext_noop("Disables reading from system indexes."),
1400 gettext_noop("It does not prevent updating the indexes, so it is safe "
1401 "to use. The worst consequence is slowness."),
1404 &IgnoreSystemIndexes,
1410 {"lo_compat_privileges", PGC_SUSET, COMPAT_OPTIONS_PREVIOUS,
1411 gettext_noop("Enables backward compatibility mode for privilege checks on large objects."),
1412 gettext_noop("Skips privilege checks when reading or modifying large objects, "
1413 "for compatibility with PostgreSQL releases prior to 9.0.")
1415 &lo_compat_privileges,
1421 {"quote_all_identifiers", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1422 gettext_noop("When generating SQL fragments, quote all identifiers."),
1425 "e_all_identifiers,
1430 /* End-of-list marker */
1432 {NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL, NULL
1437 static struct config_int ConfigureNamesInt[] =
1440 {"archive_timeout", PGC_SIGHUP, WAL_ARCHIVING,
1441 gettext_noop("Forces a switch to the next xlog file if a "
1442 "new file has not been started within N seconds."),
1446 &XLogArchiveTimeout,
1451 {"post_auth_delay", PGC_BACKEND, DEVELOPER_OPTIONS,
1452 gettext_noop("Waits N seconds on connection startup after authentication."),
1453 gettext_noop("This allows attaching a debugger to the process."),
1454 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1461 {"default_statistics_target", PGC_USERSET, QUERY_TUNING_OTHER,
1462 gettext_noop("Sets the default statistics target."),
1463 gettext_noop("This applies to table columns that have not had a "
1464 "column-specific target set via ALTER TABLE SET STATISTICS.")
1466 &default_statistics_target,
1471 {"from_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1472 gettext_noop("Sets the FROM-list size beyond which subqueries "
1473 "are not collapsed."),
1474 gettext_noop("The planner will merge subqueries into upper "
1475 "queries if the resulting FROM list would have no more than "
1478 &from_collapse_limit,
1483 {"join_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1484 gettext_noop("Sets the FROM-list size beyond which JOIN "
1485 "constructs are not flattened."),
1486 gettext_noop("The planner will flatten explicit JOIN "
1487 "constructs into lists of FROM items whenever a "
1488 "list of no more than this many items would result.")
1490 &join_collapse_limit,
1495 {"geqo_threshold", PGC_USERSET, QUERY_TUNING_GEQO,
1496 gettext_noop("Sets the threshold of FROM items beyond which GEQO is used."),
1504 {"geqo_effort", PGC_USERSET, QUERY_TUNING_GEQO,
1505 gettext_noop("GEQO: effort is used to set the default for other GEQO parameters."),
1509 DEFAULT_GEQO_EFFORT, MIN_GEQO_EFFORT, MAX_GEQO_EFFORT,
1513 {"geqo_pool_size", PGC_USERSET, QUERY_TUNING_GEQO,
1514 gettext_noop("GEQO: number of individuals in the population."),
1515 gettext_noop("Zero selects a suitable default value.")
1522 {"geqo_generations", PGC_USERSET, QUERY_TUNING_GEQO,
1523 gettext_noop("GEQO: number of iterations of the algorithm."),
1524 gettext_noop("Zero selects a suitable default value.")
1532 /* This is PGC_SUSET to prevent hiding from log_lock_waits. */
1533 {"deadlock_timeout", PGC_SUSET, LOCK_MANAGEMENT,
1534 gettext_noop("Sets the time to wait on a lock before checking for deadlock."),
1544 {"max_standby_archive_delay", PGC_SIGHUP, REPLICATION_STANDBY,
1545 gettext_noop("Sets the maximum delay before canceling queries when a hot standby server is processing archived WAL data."),
1549 &max_standby_archive_delay,
1550 30 * 1000, -1, INT_MAX,
1555 {"max_standby_streaming_delay", PGC_SIGHUP, REPLICATION_STANDBY,
1556 gettext_noop("Sets the maximum delay before canceling queries when a hot standby server is processing streamed WAL data."),
1560 &max_standby_streaming_delay,
1561 30 * 1000, -1, INT_MAX,
1566 {"wal_receiver_status_interval", PGC_SIGHUP, REPLICATION_STANDBY,
1567 gettext_noop("Sets the maximum interval between WAL receiver status reports to the primary."),
1571 &wal_receiver_status_interval,
1572 10, 0, INT_MAX / 1000,
1577 {"max_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1578 gettext_noop("Sets the maximum number of concurrent connections."),
1582 100, 1, MAX_BACKENDS,
1583 check_maxconnections, assign_maxconnections, NULL
1587 {"superuser_reserved_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1588 gettext_noop("Sets the number of connection slots reserved for superusers."),
1597 * We sometimes multiply the number of shared buffers by two without
1598 * checking for overflow, so we mustn't allow more than INT_MAX / 2.
1601 {"shared_buffers", PGC_POSTMASTER, RESOURCES_MEM,
1602 gettext_noop("Sets the number of shared memory buffers used by the server."),
1607 1024, 16, INT_MAX / 2,
1612 {"temp_buffers", PGC_USERSET, RESOURCES_MEM,
1613 gettext_noop("Sets the maximum number of temporary buffers used by each session."),
1618 1024, 100, INT_MAX / 2,
1619 check_temp_buffers, NULL, NULL
1623 {"port", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1624 gettext_noop("Sets the TCP port the server listens on."),
1628 DEF_PGPORT, 1, 65535,
1633 {"unix_socket_permissions", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1634 gettext_noop("Sets the access permissions of the Unix-domain socket."),
1635 gettext_noop("Unix-domain sockets use the usual Unix file system "
1636 "permission set. The parameter value is expected "
1637 "to be a numeric mode specification in the form "
1638 "accepted by the chmod and umask system calls. "
1639 "(To use the customary octal format the number must "
1640 "start with a 0 (zero).)")
1642 &Unix_socket_permissions,
1644 NULL, NULL, show_unix_socket_permissions
1648 {"log_file_mode", PGC_SIGHUP, LOGGING_WHERE,
1649 gettext_noop("Sets the file permissions for log files."),
1650 gettext_noop("The parameter value is expected "
1651 "to be a numeric mode specification in the form "
1652 "accepted by the chmod and umask system calls. "
1653 "(To use the customary octal format the number must "
1654 "start with a 0 (zero).)")
1658 NULL, NULL, show_log_file_mode
1662 {"work_mem", PGC_USERSET, RESOURCES_MEM,
1663 gettext_noop("Sets the maximum memory to be used for query workspaces."),
1664 gettext_noop("This much memory can be used by each internal "
1665 "sort operation and hash table before switching to "
1666 "temporary disk files."),
1670 1024, 64, MAX_KILOBYTES,
1675 {"maintenance_work_mem", PGC_USERSET, RESOURCES_MEM,
1676 gettext_noop("Sets the maximum memory to be used for maintenance operations."),
1677 gettext_noop("This includes operations such as VACUUM and CREATE INDEX."),
1680 &maintenance_work_mem,
1681 16384, 1024, MAX_KILOBYTES,
1686 * We use the hopefully-safely-small value of 100kB as the compiled-in
1687 * default for max_stack_depth. InitializeGUCOptions will increase it if
1688 * possible, depending on the actual platform-specific stack limit.
1691 {"max_stack_depth", PGC_SUSET, RESOURCES_MEM,
1692 gettext_noop("Sets the maximum stack depth, in kilobytes."),
1697 100, 100, MAX_KILOBYTES,
1698 check_max_stack_depth, assign_max_stack_depth, NULL
1702 {"temp_file_limit", PGC_SUSET, RESOURCES_DISK,
1703 gettext_noop("Limits the total size of all temp files used by each session."),
1704 gettext_noop("-1 means no limit."),
1713 {"vacuum_cost_page_hit", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1714 gettext_noop("Vacuum cost for a page found in the buffer cache."),
1723 {"vacuum_cost_page_miss", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1724 gettext_noop("Vacuum cost for a page not found in the buffer cache."),
1727 &VacuumCostPageMiss,
1733 {"vacuum_cost_page_dirty", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1734 gettext_noop("Vacuum cost for a page dirtied by vacuum."),
1737 &VacuumCostPageDirty,
1743 {"vacuum_cost_limit", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1744 gettext_noop("Vacuum cost amount available before napping."),
1753 {"vacuum_cost_delay", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1754 gettext_noop("Vacuum cost delay in milliseconds."),
1764 {"autovacuum_vacuum_cost_delay", PGC_SIGHUP, AUTOVACUUM,
1765 gettext_noop("Vacuum cost delay in milliseconds, for autovacuum."),
1769 &autovacuum_vac_cost_delay,
1775 {"autovacuum_vacuum_cost_limit", PGC_SIGHUP, AUTOVACUUM,
1776 gettext_noop("Vacuum cost amount available before napping, for autovacuum."),
1779 &autovacuum_vac_cost_limit,
1785 {"max_files_per_process", PGC_POSTMASTER, RESOURCES_KERNEL,
1786 gettext_noop("Sets the maximum number of simultaneously open files for each server process."),
1789 &max_files_per_process,
1795 * See also CheckRequiredParameterValues() if this parameter changes
1798 {"max_prepared_transactions", PGC_POSTMASTER, RESOURCES_MEM,
1799 gettext_noop("Sets the maximum number of simultaneously prepared transactions."),
1802 &max_prepared_xacts,
1809 {"trace_lock_oidmin", PGC_SUSET, DEVELOPER_OPTIONS,
1810 gettext_noop("No description available."),
1815 FirstNormalObjectId, 0, INT_MAX,
1819 {"trace_lock_table", PGC_SUSET, DEVELOPER_OPTIONS,
1820 gettext_noop("No description available."),
1831 {"statement_timeout", PGC_USERSET, CLIENT_CONN_STATEMENT,
1832 gettext_noop("Sets the maximum allowed duration of any statement."),
1833 gettext_noop("A value of 0 turns off the timeout."),
1842 {"vacuum_freeze_min_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1843 gettext_noop("Minimum age at which VACUUM should freeze a table row."),
1846 &vacuum_freeze_min_age,
1847 50000000, 0, 1000000000,
1852 {"vacuum_freeze_table_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1853 gettext_noop("Age at which VACUUM should scan whole table to freeze tuples."),
1856 &vacuum_freeze_table_age,
1857 150000000, 0, 2000000000,
1862 {"vacuum_defer_cleanup_age", PGC_SIGHUP, REPLICATION_MASTER,
1863 gettext_noop("Number of transactions by which VACUUM and HOT cleanup should be deferred, if any."),
1866 &vacuum_defer_cleanup_age,
1872 * See also CheckRequiredParameterValues() if this parameter changes
1875 {"max_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
1876 gettext_noop("Sets the maximum number of locks per transaction."),
1877 gettext_noop("The shared lock table is sized on the assumption that "
1878 "at most max_locks_per_transaction * max_connections distinct "
1879 "objects will need to be locked at any one time.")
1881 &max_locks_per_xact,
1887 {"max_pred_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
1888 gettext_noop("Sets the maximum number of predicate locks per transaction."),
1889 gettext_noop("The shared predicate lock table is sized on the assumption that "
1890 "at most max_pred_locks_per_transaction * max_connections distinct "
1891 "objects will need to be locked at any one time.")
1893 &max_predicate_locks_per_xact,
1899 {"authentication_timeout", PGC_SIGHUP, CONN_AUTH_SECURITY,
1900 gettext_noop("Sets the maximum allowed time to complete client authentication."),
1904 &AuthenticationTimeout,
1910 /* Not for general use */
1911 {"pre_auth_delay", PGC_SIGHUP, DEVELOPER_OPTIONS,
1912 gettext_noop("Waits N seconds on connection startup before authentication."),
1913 gettext_noop("This allows attaching a debugger to the process."),
1914 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1922 {"wal_keep_segments", PGC_SIGHUP, REPLICATION_SENDING,
1923 gettext_noop("Sets the number of WAL files held for standby servers."),
1932 {"checkpoint_segments", PGC_SIGHUP, WAL_CHECKPOINTS,
1933 gettext_noop("Sets the maximum distance in log segments between automatic WAL checkpoints."),
1936 &CheckPointSegments,
1942 {"checkpoint_timeout", PGC_SIGHUP, WAL_CHECKPOINTS,
1943 gettext_noop("Sets the maximum time between automatic WAL checkpoints."),
1953 {"checkpoint_warning", PGC_SIGHUP, WAL_CHECKPOINTS,
1954 gettext_noop("Enables warnings if checkpoint segments are filled more "
1955 "frequently than this."),
1956 gettext_noop("Write a message to the server log if checkpoints "
1957 "caused by the filling of checkpoint segment files happens more "
1958 "frequently than this number of seconds. Zero turns off the warning."),
1967 {"wal_buffers", PGC_POSTMASTER, WAL_SETTINGS,
1968 gettext_noop("Sets the number of disk-page buffers in shared memory for WAL."),
1974 check_wal_buffers, NULL, NULL
1978 {"wal_writer_delay", PGC_SIGHUP, WAL_SETTINGS,
1979 gettext_noop("WAL writer sleep time between WAL flushes."),
1989 /* see max_connections */
1990 {"max_wal_senders", PGC_POSTMASTER, REPLICATION_SENDING,
1991 gettext_noop("Sets the maximum number of simultaneously running WAL sender processes."),
2000 {"replication_timeout", PGC_SIGHUP, REPLICATION_SENDING,
2001 gettext_noop("Sets the maximum time to wait for WAL replication."),
2005 &replication_timeout,
2006 60 * 1000, 0, INT_MAX,
2011 {"commit_delay", PGC_USERSET, WAL_SETTINGS,
2012 gettext_noop("Sets the delay in microseconds between transaction commit and "
2013 "flushing WAL to disk."),
2022 {"commit_siblings", PGC_USERSET, WAL_SETTINGS,
2023 gettext_noop("Sets the minimum concurrent open transactions before performing "
2033 {"extra_float_digits", PGC_USERSET, CLIENT_CONN_LOCALE,
2034 gettext_noop("Sets the number of digits displayed for floating-point values."),
2035 gettext_noop("This affects real, double precision, and geometric data types. "
2036 "The parameter value is added to the standard number of digits "
2037 "(FLT_DIG or DBL_DIG as appropriate).")
2039 &extra_float_digits,
2045 {"log_min_duration_statement", PGC_SUSET, LOGGING_WHEN,
2046 gettext_noop("Sets the minimum execution time above which "
2047 "statements will be logged."),
2048 gettext_noop("Zero prints all queries. -1 turns this feature off."),
2051 &log_min_duration_statement,
2057 {"log_autovacuum_min_duration", PGC_SIGHUP, LOGGING_WHAT,
2058 gettext_noop("Sets the minimum execution time above which "
2059 "autovacuum actions will be logged."),
2060 gettext_noop("Zero prints all actions. -1 turns autovacuum logging off."),
2063 &Log_autovacuum_min_duration,
2069 {"bgwriter_delay", PGC_SIGHUP, RESOURCES_BGWRITER,
2070 gettext_noop("Background writer sleep time between rounds."),
2080 {"bgwriter_lru_maxpages", PGC_SIGHUP, RESOURCES_BGWRITER,
2081 gettext_noop("Background writer maximum number of LRU pages to flush per round."),
2084 &bgwriter_lru_maxpages,
2090 {"effective_io_concurrency",
2096 RESOURCES_ASYNCHRONOUS,
2097 gettext_noop("Number of simultaneous requests that can be handled efficiently by the disk subsystem."),
2098 gettext_noop("For RAID arrays, this should be approximately the number of drive spindles in the array.")
2100 &effective_io_concurrency,
2106 check_effective_io_concurrency, assign_effective_io_concurrency, NULL
2110 {"log_rotation_age", PGC_SIGHUP, LOGGING_WHERE,
2111 gettext_noop("Automatic log file rotation will occur after N minutes."),
2116 HOURS_PER_DAY * MINS_PER_HOUR, 0, INT_MAX / MINS_PER_HOUR,
2121 {"log_rotation_size", PGC_SIGHUP, LOGGING_WHERE,
2122 gettext_noop("Automatic log file rotation will occur after N kilobytes."),
2127 10 * 1024, 0, INT_MAX / 1024,
2132 {"max_function_args", PGC_INTERNAL, PRESET_OPTIONS,
2133 gettext_noop("Shows the maximum number of function arguments."),
2135 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2138 FUNC_MAX_ARGS, FUNC_MAX_ARGS, FUNC_MAX_ARGS,
2143 {"max_index_keys", PGC_INTERNAL, PRESET_OPTIONS,
2144 gettext_noop("Shows the maximum number of index keys."),
2146 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2149 INDEX_MAX_KEYS, INDEX_MAX_KEYS, INDEX_MAX_KEYS,
2154 {"max_identifier_length", PGC_INTERNAL, PRESET_OPTIONS,
2155 gettext_noop("Shows the maximum identifier length."),
2157 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2159 &max_identifier_length,
2160 NAMEDATALEN - 1, NAMEDATALEN - 1, NAMEDATALEN - 1,
2165 {"block_size", PGC_INTERNAL, PRESET_OPTIONS,
2166 gettext_noop("Shows the size of a disk block."),
2168 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2171 BLCKSZ, BLCKSZ, BLCKSZ,
2176 {"segment_size", PGC_INTERNAL, PRESET_OPTIONS,
2177 gettext_noop("Shows the number of pages per disk file."),
2179 GUC_UNIT_BLOCKS | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2182 RELSEG_SIZE, RELSEG_SIZE, RELSEG_SIZE,
2187 {"wal_block_size", PGC_INTERNAL, PRESET_OPTIONS,
2188 gettext_noop("Shows the block size in the write ahead log."),
2190 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2193 XLOG_BLCKSZ, XLOG_BLCKSZ, XLOG_BLCKSZ,
2198 {"wal_segment_size", PGC_INTERNAL, PRESET_OPTIONS,
2199 gettext_noop("Shows the number of pages per write ahead log segment."),
2201 GUC_UNIT_XBLOCKS | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2204 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
2205 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
2206 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
2211 {"autovacuum_naptime", PGC_SIGHUP, AUTOVACUUM,
2212 gettext_noop("Time to sleep between autovacuum runs."),
2216 &autovacuum_naptime,
2217 60, 1, INT_MAX / 1000,
2221 {"autovacuum_vacuum_threshold", PGC_SIGHUP, AUTOVACUUM,
2222 gettext_noop("Minimum number of tuple updates or deletes prior to vacuum."),
2225 &autovacuum_vac_thresh,
2230 {"autovacuum_analyze_threshold", PGC_SIGHUP, AUTOVACUUM,
2231 gettext_noop("Minimum number of tuple inserts, updates or deletes prior to analyze."),
2234 &autovacuum_anl_thresh,
2239 /* see varsup.c for why this is PGC_POSTMASTER not PGC_SIGHUP */
2240 {"autovacuum_freeze_max_age", PGC_POSTMASTER, AUTOVACUUM,
2241 gettext_noop("Age at which to autovacuum a table to prevent transaction ID wraparound."),
2244 &autovacuum_freeze_max_age,
2245 /* see pg_resetxlog if you change the upper-limit value */
2246 200000000, 100000000, 2000000000,
2250 /* see max_connections */
2251 {"autovacuum_max_workers", PGC_POSTMASTER, AUTOVACUUM,
2252 gettext_noop("Sets the maximum number of simultaneously running autovacuum worker processes."),
2255 &autovacuum_max_workers,
2257 check_autovacuum_max_workers, assign_autovacuum_max_workers, NULL
2261 {"tcp_keepalives_idle", PGC_USERSET, CLIENT_CONN_OTHER,
2262 gettext_noop("Time between issuing TCP keepalives."),
2263 gettext_noop("A value of 0 uses the system default."),
2266 &tcp_keepalives_idle,
2268 NULL, assign_tcp_keepalives_idle, show_tcp_keepalives_idle
2272 {"tcp_keepalives_interval", PGC_USERSET, CLIENT_CONN_OTHER,
2273 gettext_noop("Time between TCP keepalive retransmits."),
2274 gettext_noop("A value of 0 uses the system default."),
2277 &tcp_keepalives_interval,
2279 NULL, assign_tcp_keepalives_interval, show_tcp_keepalives_interval
2283 {"ssl_renegotiation_limit", PGC_USERSET, CONN_AUTH_SECURITY,
2284 gettext_noop("Set the amount of traffic to send and receive before renegotiating the encryption keys."),
2288 &ssl_renegotiation_limit,
2289 512 * 1024, 0, MAX_KILOBYTES,
2294 {"tcp_keepalives_count", PGC_USERSET, CLIENT_CONN_OTHER,
2295 gettext_noop("Maximum number of TCP keepalive retransmits."),
2296 gettext_noop("This controls the number of consecutive keepalive retransmits that can be "
2297 "lost before a connection is considered dead. A value of 0 uses the "
2300 &tcp_keepalives_count,
2302 NULL, assign_tcp_keepalives_count, show_tcp_keepalives_count
2306 {"gin_fuzzy_search_limit", PGC_USERSET, CLIENT_CONN_OTHER,
2307 gettext_noop("Sets the maximum allowed result for exact search by GIN."),
2311 &GinFuzzySearchLimit,
2317 {"effective_cache_size", PGC_USERSET, QUERY_TUNING_COST,
2318 gettext_noop("Sets the planner's assumption about the size of the disk cache."),
2319 gettext_noop("That is, the portion of the kernel's disk cache that "
2320 "will be used for PostgreSQL data files. This is measured in disk "
2321 "pages, which are normally 8 kB each."),
2324 &effective_cache_size,
2325 DEFAULT_EFFECTIVE_CACHE_SIZE, 1, INT_MAX,
2330 /* Can't be set in postgresql.conf */
2331 {"server_version_num", PGC_INTERNAL, PRESET_OPTIONS,
2332 gettext_noop("Shows the server version as an integer."),
2334 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2336 &server_version_num,
2337 PG_VERSION_NUM, PG_VERSION_NUM, PG_VERSION_NUM,
2342 {"log_temp_files", PGC_SUSET, LOGGING_WHAT,
2343 gettext_noop("Log the use of temporary files larger than this number of kilobytes."),
2344 gettext_noop("Zero logs all files. The default is -1 (turning this feature off)."),
2353 {"track_activity_query_size", PGC_POSTMASTER, RESOURCES_MEM,
2354 gettext_noop("Sets the size reserved for pg_stat_activity.current_query, in bytes."),
2357 &pgstat_track_activity_query_size,
2362 /* End-of-list marker */
2364 {NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL, NULL
2369 static struct config_real ConfigureNamesReal[] =
2372 {"seq_page_cost", PGC_USERSET, QUERY_TUNING_COST,
2373 gettext_noop("Sets the planner's estimate of the cost of a "
2374 "sequentially fetched disk page."),
2378 DEFAULT_SEQ_PAGE_COST, 0, DBL_MAX,
2382 {"random_page_cost", PGC_USERSET, QUERY_TUNING_COST,
2383 gettext_noop("Sets the planner's estimate of the cost of a "
2384 "nonsequentially fetched disk page."),
2388 DEFAULT_RANDOM_PAGE_COST, 0, DBL_MAX,
2392 {"cpu_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
2393 gettext_noop("Sets the planner's estimate of the cost of "
2394 "processing each tuple (row)."),
2398 DEFAULT_CPU_TUPLE_COST, 0, DBL_MAX,
2402 {"cpu_index_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
2403 gettext_noop("Sets the planner's estimate of the cost of "
2404 "processing each index entry during an index scan."),
2407 &cpu_index_tuple_cost,
2408 DEFAULT_CPU_INDEX_TUPLE_COST, 0, DBL_MAX,
2412 {"cpu_operator_cost", PGC_USERSET, QUERY_TUNING_COST,
2413 gettext_noop("Sets the planner's estimate of the cost of "
2414 "processing each operator or function call."),
2418 DEFAULT_CPU_OPERATOR_COST, 0, DBL_MAX,
2423 {"cursor_tuple_fraction", PGC_USERSET, QUERY_TUNING_OTHER,
2424 gettext_noop("Sets the planner's estimate of the fraction of "
2425 "a cursor's rows that will be retrieved."),
2428 &cursor_tuple_fraction,
2429 DEFAULT_CURSOR_TUPLE_FRACTION, 0.0, 1.0,
2434 {"geqo_selection_bias", PGC_USERSET, QUERY_TUNING_GEQO,
2435 gettext_noop("GEQO: selective pressure within the population."),
2438 &Geqo_selection_bias,
2439 DEFAULT_GEQO_SELECTION_BIAS,
2440 MIN_GEQO_SELECTION_BIAS, MAX_GEQO_SELECTION_BIAS,
2444 {"geqo_seed", PGC_USERSET, QUERY_TUNING_GEQO,
2445 gettext_noop("GEQO: seed for random path selection."),
2454 {"bgwriter_lru_multiplier", PGC_SIGHUP, RESOURCES_BGWRITER,
2455 gettext_noop("Multiple of the average buffer usage to free per round."),
2458 &bgwriter_lru_multiplier,
2464 {"seed", PGC_USERSET, UNGROUPED,
2465 gettext_noop("Sets the seed for random-number generation."),
2467 GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2471 check_random_seed, assign_random_seed, show_random_seed
2475 {"autovacuum_vacuum_scale_factor", PGC_SIGHUP, AUTOVACUUM,
2476 gettext_noop("Number of tuple updates or deletes prior to vacuum as a fraction of reltuples."),
2479 &autovacuum_vac_scale,
2484 {"autovacuum_analyze_scale_factor", PGC_SIGHUP, AUTOVACUUM,
2485 gettext_noop("Number of tuple inserts, updates or deletes prior to analyze as a fraction of reltuples."),
2488 &autovacuum_anl_scale,
2494 {"checkpoint_completion_target", PGC_SIGHUP, WAL_CHECKPOINTS,
2495 gettext_noop("Time spent flushing dirty buffers during checkpoint, as fraction of checkpoint interval."),
2498 &CheckPointCompletionTarget,
2503 /* End-of-list marker */
2505 {NULL, 0, 0, NULL, NULL}, NULL, 0.0, 0.0, 0.0, NULL, NULL, NULL
2510 static struct config_string ConfigureNamesString[] =
2513 {"archive_command", PGC_SIGHUP, WAL_ARCHIVING,
2514 gettext_noop("Sets the shell command that will be called to archive a WAL file."),
2517 &XLogArchiveCommand,
2519 NULL, NULL, show_archive_command
2523 {"client_encoding", PGC_USERSET, CLIENT_CONN_LOCALE,
2524 gettext_noop("Sets the client's character set encoding."),
2526 GUC_IS_NAME | GUC_REPORT
2528 &client_encoding_string,
2530 check_client_encoding, assign_client_encoding, NULL
2534 {"log_line_prefix", PGC_SIGHUP, LOGGING_WHAT,
2535 gettext_noop("Controls information prefixed to each log line."),
2536 gettext_noop("If blank, no prefix is used.")
2544 {"log_timezone", PGC_SIGHUP, LOGGING_WHAT,
2545 gettext_noop("Sets the time zone to use in log messages."),
2548 &log_timezone_string,
2550 check_log_timezone, assign_log_timezone, show_log_timezone
2554 {"DateStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
2555 gettext_noop("Sets the display format for date and time values."),
2556 gettext_noop("Also controls interpretation of ambiguous "
2558 GUC_LIST_INPUT | GUC_REPORT
2562 check_datestyle, assign_datestyle, NULL
2566 {"default_tablespace", PGC_USERSET, CLIENT_CONN_STATEMENT,
2567 gettext_noop("Sets the default tablespace to create tables and indexes in."),
2568 gettext_noop("An empty string selects the database's default tablespace."),
2571 &default_tablespace,
2573 check_default_tablespace, NULL, NULL
2577 {"temp_tablespaces", PGC_USERSET, CLIENT_CONN_STATEMENT,
2578 gettext_noop("Sets the tablespace(s) to use for temporary tables and sort files."),
2580 GUC_LIST_INPUT | GUC_LIST_QUOTE
2584 check_temp_tablespaces, assign_temp_tablespaces, NULL
2588 {"dynamic_library_path", PGC_SUSET, CLIENT_CONN_OTHER,
2589 gettext_noop("Sets the path for dynamically loadable modules."),
2590 gettext_noop("If a dynamically loadable module needs to be opened and "
2591 "the specified name does not have a directory component (i.e., the "
2592 "name does not contain a slash), the system will search this path for "
2593 "the specified file."),
2596 &Dynamic_library_path,
2602 {"krb_server_keyfile", PGC_SIGHUP, CONN_AUTH_SECURITY,
2603 gettext_noop("Sets the location of the Kerberos server key file."),
2607 &pg_krb_server_keyfile,
2613 {"krb_srvname", PGC_SIGHUP, CONN_AUTH_SECURITY,
2614 gettext_noop("Sets the name of the Kerberos service."),
2623 {"bonjour_name", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2624 gettext_noop("Sets the Bonjour service name."),
2632 /* See main.c about why defaults for LC_foo are not all alike */
2635 {"lc_collate", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2636 gettext_noop("Shows the collation order locale."),
2638 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2646 {"lc_ctype", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2647 gettext_noop("Shows the character classification and case conversion locale."),
2649 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2657 {"lc_messages", PGC_SUSET, CLIENT_CONN_LOCALE,
2658 gettext_noop("Sets the language in which messages are displayed."),
2663 check_locale_messages, assign_locale_messages, NULL
2667 {"lc_monetary", PGC_USERSET, CLIENT_CONN_LOCALE,
2668 gettext_noop("Sets the locale for formatting monetary amounts."),
2673 check_locale_monetary, assign_locale_monetary, NULL
2677 {"lc_numeric", PGC_USERSET, CLIENT_CONN_LOCALE,
2678 gettext_noop("Sets the locale for formatting numbers."),
2683 check_locale_numeric, assign_locale_numeric, NULL
2687 {"lc_time", PGC_USERSET, CLIENT_CONN_LOCALE,
2688 gettext_noop("Sets the locale for formatting date and time values."),
2693 check_locale_time, assign_locale_time, NULL
2697 {"shared_preload_libraries", PGC_POSTMASTER, RESOURCES_KERNEL,
2698 gettext_noop("Lists shared libraries to preload into server."),
2700 GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
2702 &shared_preload_libraries_string,
2708 {"local_preload_libraries", PGC_BACKEND, CLIENT_CONN_OTHER,
2709 gettext_noop("Lists shared libraries to preload into each backend."),
2711 GUC_LIST_INPUT | GUC_LIST_QUOTE
2713 &local_preload_libraries_string,
2719 {"search_path", PGC_USERSET, CLIENT_CONN_STATEMENT,
2720 gettext_noop("Sets the schema search order for names that are not schema-qualified."),
2722 GUC_LIST_INPUT | GUC_LIST_QUOTE
2724 &namespace_search_path,
2726 check_search_path, assign_search_path, NULL
2730 /* Can't be set in postgresql.conf */
2731 {"server_encoding", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2732 gettext_noop("Sets the server (database) character set encoding."),
2734 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2736 &server_encoding_string,
2742 /* Can't be set in postgresql.conf */
2743 {"server_version", PGC_INTERNAL, PRESET_OPTIONS,
2744 gettext_noop("Shows the server version."),
2746 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2748 &server_version_string,
2754 /* Not for general use --- used by SET ROLE */
2755 {"role", PGC_USERSET, UNGROUPED,
2756 gettext_noop("Sets the current role."),
2758 GUC_IS_NAME | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_NOT_WHILE_SEC_REST
2762 check_role, assign_role, show_role
2766 /* Not for general use --- used by SET SESSION AUTHORIZATION */
2767 {"session_authorization", PGC_USERSET, UNGROUPED,
2768 gettext_noop("Sets the session user name."),
2770 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
2772 &session_authorization_string,
2774 check_session_authorization, assign_session_authorization, NULL
2778 {"log_destination", PGC_SIGHUP, LOGGING_WHERE,
2779 gettext_noop("Sets the destination for server log output."),
2780 gettext_noop("Valid values are combinations of \"stderr\", "
2781 "\"syslog\", \"csvlog\", and \"eventlog\", "
2782 "depending on the platform."),
2785 &log_destination_string,
2787 check_log_destination, assign_log_destination, NULL
2790 {"log_directory", PGC_SIGHUP, LOGGING_WHERE,
2791 gettext_noop("Sets the destination directory for log files."),
2792 gettext_noop("Can be specified as relative to the data directory "
2793 "or as absolute path."),
2798 check_canonical_path, NULL, NULL
2801 {"log_filename", PGC_SIGHUP, LOGGING_WHERE,
2802 gettext_noop("Sets the file name pattern for log files."),
2807 "postgresql-%Y-%m-%d_%H%M%S.log",
2812 {"syslog_ident", PGC_SIGHUP, LOGGING_WHERE,
2813 gettext_noop("Sets the program name used to identify PostgreSQL "
2814 "messages in syslog."),
2819 NULL, assign_syslog_ident, NULL
2823 {"TimeZone", PGC_USERSET, CLIENT_CONN_LOCALE,
2824 gettext_noop("Sets the time zone for displaying and interpreting time stamps."),
2830 check_timezone, assign_timezone, show_timezone
2833 {"timezone_abbreviations", PGC_USERSET, CLIENT_CONN_LOCALE,
2834 gettext_noop("Selects a file of time zone abbreviations."),
2837 &timezone_abbreviations_string,
2839 check_timezone_abbreviations, assign_timezone_abbreviations, NULL
2843 {"transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
2844 gettext_noop("Sets the current transaction's isolation level."),
2846 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2848 &XactIsoLevel_string,
2850 check_XactIsoLevel, assign_XactIsoLevel, show_XactIsoLevel
2854 {"unix_socket_group", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2855 gettext_noop("Sets the owning group of the Unix-domain socket."),
2856 gettext_noop("The owning user of the socket is always the user "
2857 "that starts the server.")
2865 {"unix_socket_directory", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2866 gettext_noop("Sets the directory where the Unix-domain socket will be created."),
2872 check_canonical_path, NULL, NULL
2876 {"listen_addresses", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2877 gettext_noop("Sets the host name or IP address(es) to listen to."),
2887 {"data_directory", PGC_POSTMASTER, FILE_LOCATIONS,
2888 gettext_noop("Sets the server's data directory."),
2898 {"config_file", PGC_POSTMASTER, FILE_LOCATIONS,
2899 gettext_noop("Sets the server's main configuration file."),
2901 GUC_DISALLOW_IN_FILE | GUC_SUPERUSER_ONLY
2909 {"hba_file", PGC_POSTMASTER, FILE_LOCATIONS,
2910 gettext_noop("Sets the server's \"hba\" configuration file."),
2920 {"ident_file", PGC_POSTMASTER, FILE_LOCATIONS,
2921 gettext_noop("Sets the server's \"ident\" configuration file."),
2931 {"external_pid_file", PGC_POSTMASTER, FILE_LOCATIONS,
2932 gettext_noop("Writes the postmaster PID to the specified file."),
2938 check_canonical_path, NULL, NULL
2942 {"stats_temp_directory", PGC_SIGHUP, STATS_COLLECTOR,
2943 gettext_noop("Writes temporary statistics files to the specified directory."),
2947 &pgstat_temp_directory,
2949 check_canonical_path, assign_pgstat_temp_directory, NULL
2953 {"synchronous_standby_names", PGC_SIGHUP, REPLICATION_MASTER,
2954 gettext_noop("List of names of potential synchronous standbys."),
2958 &SyncRepStandbyNames,
2960 check_synchronous_standby_names, NULL, NULL
2964 {"default_text_search_config", PGC_USERSET, CLIENT_CONN_LOCALE,
2965 gettext_noop("Sets default text search configuration."),
2969 "pg_catalog.simple",
2970 check_TSCurrentConfig, assign_TSCurrentConfig, NULL
2974 {"ssl_ciphers", PGC_POSTMASTER, CONN_AUTH_SECURITY,
2975 gettext_noop("Sets the list of allowed SSL ciphers."),
2981 "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH",
2989 {"application_name", PGC_USERSET, LOGGING_WHAT,
2990 gettext_noop("Sets the application name to be reported in statistics and logs."),
2992 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE
2996 check_application_name, assign_application_name, NULL
2999 /* End-of-list marker */
3001 {NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL, NULL
3006 static struct config_enum ConfigureNamesEnum[] =
3009 {"backslash_quote", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
3010 gettext_noop("Sets whether \"\\'\" is allowed in string literals."),
3014 BACKSLASH_QUOTE_SAFE_ENCODING, backslash_quote_options,
3019 {"bytea_output", PGC_USERSET, CLIENT_CONN_STATEMENT,
3020 gettext_noop("Sets the output format for bytea."),
3024 BYTEA_OUTPUT_HEX, bytea_output_options,
3029 {"client_min_messages", PGC_USERSET, LOGGING_WHEN,
3030 gettext_noop("Sets the message levels that are sent to the client."),
3031 gettext_noop("Each level includes all the levels that follow it. The later"
3032 " the level, the fewer messages are sent.")
3034 &client_min_messages,
3035 NOTICE, client_message_level_options,
3040 {"constraint_exclusion", PGC_USERSET, QUERY_TUNING_OTHER,
3041 gettext_noop("Enables the planner to use constraints to optimize queries."),
3042 gettext_noop("Table scans will be skipped if their constraints"
3043 " guarantee that no rows match the query.")
3045 &constraint_exclusion,
3046 CONSTRAINT_EXCLUSION_PARTITION, constraint_exclusion_options,
3051 {"default_transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
3052 gettext_noop("Sets the transaction isolation level of each new transaction."),
3055 &DefaultXactIsoLevel,
3056 XACT_READ_COMMITTED, isolation_level_options,
3061 {"IntervalStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
3062 gettext_noop("Sets the display format for interval values."),
3067 INTSTYLE_POSTGRES, intervalstyle_options,
3072 {"log_error_verbosity", PGC_SUSET, LOGGING_WHAT,
3073 gettext_noop("Sets the verbosity of logged messages."),
3076 &Log_error_verbosity,
3077 PGERROR_DEFAULT, log_error_verbosity_options,
3082 {"log_min_messages", PGC_SUSET, LOGGING_WHEN,
3083 gettext_noop("Sets the message levels that are logged."),
3084 gettext_noop("Each level includes all the levels that follow it. The later"
3085 " the level, the fewer messages are sent.")
3088 WARNING, server_message_level_options,
3093 {"log_min_error_statement", PGC_SUSET, LOGGING_WHEN,
3094 gettext_noop("Causes all statements generating error at or above this level to be logged."),
3095 gettext_noop("Each level includes all the levels that follow it. The later"
3096 " the level, the fewer messages are sent.")
3098 &log_min_error_statement,
3099 ERROR, server_message_level_options,
3104 {"log_statement", PGC_SUSET, LOGGING_WHAT,
3105 gettext_noop("Sets the type of statements logged."),
3109 LOGSTMT_NONE, log_statement_options,
3114 {"syslog_facility", PGC_SIGHUP, LOGGING_WHERE,
3115 gettext_noop("Sets the syslog \"facility\" to be used when syslog enabled."),
3124 syslog_facility_options,
3125 NULL, assign_syslog_facility, NULL
3129 {"session_replication_role", PGC_SUSET, CLIENT_CONN_STATEMENT,
3130 gettext_noop("Sets the session's behavior for triggers and rewrite rules."),
3133 &SessionReplicationRole,
3134 SESSION_REPLICATION_ROLE_ORIGIN, session_replication_role_options,
3135 NULL, assign_session_replication_role, NULL
3139 {"synchronous_commit", PGC_USERSET, WAL_SETTINGS,
3140 gettext_noop("Sets the current transaction's synchronization level."),
3143 &synchronous_commit,
3144 SYNCHRONOUS_COMMIT_ON, synchronous_commit_options,
3149 {"trace_recovery_messages", PGC_SIGHUP, DEVELOPER_OPTIONS,
3150 gettext_noop("Enables logging of recovery-related debugging information."),
3151 gettext_noop("Each level includes all the levels that follow it. The later"
3152 " the level, the fewer messages are sent.")
3154 &trace_recovery_messages,
3157 * client_message_level_options allows too many values, really, but
3158 * it's not worth having a separate options array for this.
3160 LOG, client_message_level_options,
3165 {"track_functions", PGC_SUSET, STATS_COLLECTOR,
3166 gettext_noop("Collects function-level statistics on database activity."),
3169 &pgstat_track_functions,
3170 TRACK_FUNC_OFF, track_function_options,
3175 {"wal_level", PGC_POSTMASTER, WAL_SETTINGS,
3176 gettext_noop("Set the level of information written to the WAL."),
3180 WAL_LEVEL_MINIMAL, wal_level_options,
3185 {"wal_sync_method", PGC_SIGHUP, WAL_SETTINGS,
3186 gettext_noop("Selects the method used for forcing WAL updates to disk."),
3190 DEFAULT_SYNC_METHOD, sync_method_options,
3191 NULL, assign_xlog_sync_method, NULL
3195 {"xmlbinary", PGC_USERSET, CLIENT_CONN_STATEMENT,
3196 gettext_noop("Sets how binary values are to be encoded in XML."),
3200 XMLBINARY_BASE64, xmlbinary_options,
3205 {"xmloption", PGC_USERSET, CLIENT_CONN_STATEMENT,
3206 gettext_noop("Sets whether XML data in implicit parsing and serialization "
3207 "operations is to be considered as documents or content fragments."),
3211 XMLOPTION_CONTENT, xmloption_options,
3216 /* End-of-list marker */
3218 {NULL, 0, 0, NULL, NULL}, NULL, 0, NULL, NULL, NULL, NULL
3222 /******** end of options list ********/
3226 * To allow continued support of obsolete names for GUC variables, we apply
3227 * the following mappings to any unrecognized name. Note that an old name
3228 * should be mapped to a new one only if the new variable has very similar
3229 * semantics to the old.
3231 static const char *const map_old_guc_names[] = {
3232 "sort_mem", "work_mem",
3233 "vacuum_mem", "maintenance_work_mem",
3239 * Actual lookup of variables is done through this single, sorted array.
3241 static struct config_generic **guc_variables;
3243 /* Current number of variables contained in the vector */
3244 static int num_guc_variables;
3246 /* Vector capacity */
3247 static int size_guc_variables;
3250 static bool guc_dirty; /* TRUE if need to do commit/abort work */
3252 static bool reporting_enabled; /* TRUE to enable GUC_REPORT */
3254 static int GUCNestLevel = 0; /* 1 when in main transaction */
3257 static int guc_var_compare(const void *a, const void *b);
3258 static int guc_name_compare(const char *namea, const char *nameb);
3259 static void InitializeGUCOptionsFromEnvironment(void);
3260 static void InitializeOneGUCOption(struct config_generic * gconf);
3261 static void push_old_value(struct config_generic * gconf, GucAction action);
3262 static void ReportGUCOption(struct config_generic * record);
3263 static void reapply_stacked_values(struct config_generic * variable,
3264 struct config_string *pHolder,
3266 const char *curvalue,
3267 GucContext curscontext, GucSource cursource);
3268 static void ShowGUCConfigOption(const char *name, DestReceiver *dest);
3269 static void ShowAllGUCConfig(DestReceiver *dest);
3270 static char *_ShowOption(struct config_generic * record, bool use_units);
3271 static bool validate_option_array_item(const char *name, const char *value,
3272 bool skipIfNoPermissions);
3276 * Some infrastructure for checking malloc/strdup/realloc calls
3279 guc_malloc(int elevel, size_t size)
3283 data = malloc(size);
3286 (errcode(ERRCODE_OUT_OF_MEMORY),
3287 errmsg("out of memory")));
3292 guc_realloc(int elevel, void *old, size_t size)
3296 data = realloc(old, size);
3299 (errcode(ERRCODE_OUT_OF_MEMORY),
3300 errmsg("out of memory")));
3305 guc_strdup(int elevel, const char *src)
3312 (errcode(ERRCODE_OUT_OF_MEMORY),
3313 errmsg("out of memory")));
3319 * Detect whether strval is referenced anywhere in a GUC string item
3322 string_field_used(struct config_string * conf, char *strval)
3326 if (strval == *(conf->variable) ||
3327 strval == conf->reset_val ||
3328 strval == conf->boot_val)
3330 for (stack = conf->gen.stack; stack; stack = stack->prev)
3332 if (strval == stack->prior.val.stringval ||
3333 strval == stack->masked.val.stringval)
3340 * Support for assigning to a field of a string GUC item. Free the prior
3341 * value if it's not referenced anywhere else in the item (including stacked
3345 set_string_field(struct config_string * conf, char **field, char *newval)
3347 char *oldval = *field;
3349 /* Do the assignment */
3352 /* Free old value if it's not NULL and isn't referenced anymore */
3353 if (oldval && !string_field_used(conf, oldval))
3358 * Detect whether an "extra" struct is referenced anywhere in a GUC item
3361 extra_field_used(struct config_generic * gconf, void *extra)
3365 if (extra == gconf->extra)
3367 switch (gconf->vartype)
3370 if (extra == ((struct config_bool *) gconf)->reset_extra)
3374 if (extra == ((struct config_int *) gconf)->reset_extra)
3378 if (extra == ((struct config_real *) gconf)->reset_extra)
3382 if (extra == ((struct config_string *) gconf)->reset_extra)
3386 if (extra == ((struct config_enum *) gconf)->reset_extra)
3390 for (stack = gconf->stack; stack; stack = stack->prev)
3392 if (extra == stack->prior.extra ||
3393 extra == stack->masked.extra)
3401 * Support for assigning to an "extra" field of a GUC item. Free the prior
3402 * value if it's not referenced anywhere else in the item (including stacked
3406 set_extra_field(struct config_generic * gconf, void **field, void *newval)
3408 void *oldval = *field;
3410 /* Do the assignment */
3413 /* Free old value if it's not NULL and isn't referenced anymore */
3414 if (oldval && !extra_field_used(gconf, oldval))
3419 * Support for copying a variable's active value into a stack entry.
3420 * The "extra" field associated with the active value is copied, too.
3422 * NB: be sure stringval and extra fields of a new stack entry are
3423 * initialized to NULL before this is used, else we'll try to free() them.
3426 set_stack_value(struct config_generic * gconf, config_var_value *val)
3428 switch (gconf->vartype)
3432 *((struct config_bool *) gconf)->variable;
3436 *((struct config_int *) gconf)->variable;
3440 *((struct config_real *) gconf)->variable;
3443 set_string_field((struct config_string *) gconf,
3444 &(val->val.stringval),
3445 *((struct config_string *) gconf)->variable);
3449 *((struct config_enum *) gconf)->variable;
3452 set_extra_field(gconf, &(val->extra), gconf->extra);
3456 * Support for discarding a no-longer-needed value in a stack entry.
3457 * The "extra" field associated with the stack entry is cleared, too.
3460 discard_stack_value(struct config_generic * gconf, config_var_value *val)
3462 switch (gconf->vartype)
3468 /* no need to do anything */
3471 set_string_field((struct config_string *) gconf,
3472 &(val->val.stringval),
3476 set_extra_field(gconf, &(val->extra), NULL);
3481 * Fetch the sorted array pointer (exported for help_config.c's use ONLY)
3483 struct config_generic **
3484 get_guc_variables(void)
3486 return guc_variables;
3491 * Build the sorted array. This is split out so that it could be
3492 * re-executed after startup (eg, we could allow loadable modules to
3493 * add vars, and then we'd need to re-sort).
3496 build_guc_variables(void)
3500 struct config_generic **guc_vars;
3503 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
3505 struct config_bool *conf = &ConfigureNamesBool[i];
3507 /* Rather than requiring vartype to be filled in by hand, do this: */
3508 conf->gen.vartype = PGC_BOOL;
3512 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
3514 struct config_int *conf = &ConfigureNamesInt[i];
3516 conf->gen.vartype = PGC_INT;
3520 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
3522 struct config_real *conf = &ConfigureNamesReal[i];
3524 conf->gen.vartype = PGC_REAL;
3528 for (i = 0; ConfigureNamesString[i].gen.name; i++)
3530 struct config_string *conf = &ConfigureNamesString[i];
3532 conf->gen.vartype = PGC_STRING;
3536 for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
3538 struct config_enum *conf = &ConfigureNamesEnum[i];
3540 conf->gen.vartype = PGC_ENUM;
3545 * Create table with 20% slack
3547 size_vars = num_vars + num_vars / 4;
3549 guc_vars = (struct config_generic **)
3550 guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
3554 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
3555 guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
3557 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
3558 guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
3560 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
3561 guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
3563 for (i = 0; ConfigureNamesString[i].gen.name; i++)
3564 guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
3566 for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
3567 guc_vars[num_vars++] = &ConfigureNamesEnum[i].gen;
3570 free(guc_variables);
3571 guc_variables = guc_vars;
3572 num_guc_variables = num_vars;
3573 size_guc_variables = size_vars;
3574 qsort((void *) guc_variables, num_guc_variables,
3575 sizeof(struct config_generic *), guc_var_compare);
3579 * Add a new GUC variable to the list of known variables. The
3580 * list is expanded if needed.
3583 add_guc_variable(struct config_generic * var, int elevel)
3585 if (num_guc_variables + 1 >= size_guc_variables)
3588 * Increase the vector by 25%
3590 int size_vars = size_guc_variables + size_guc_variables / 4;
3591 struct config_generic **guc_vars;
3596 guc_vars = (struct config_generic **)
3597 guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
3601 guc_vars = (struct config_generic **)
3602 guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
3605 if (guc_vars == NULL)
3606 return false; /* out of memory */
3608 guc_variables = guc_vars;
3609 size_guc_variables = size_vars;
3611 guc_variables[num_guc_variables++] = var;
3612 qsort((void *) guc_variables, num_guc_variables,
3613 sizeof(struct config_generic *), guc_var_compare);
3618 * Create and add a placeholder variable for a custom variable name.
3620 static struct config_generic *
3621 add_placeholder_variable(const char *name, int elevel)
3623 size_t sz = sizeof(struct config_string) + sizeof(char *);
3624 struct config_string *var;
3625 struct config_generic *gen;
3627 var = (struct config_string *) guc_malloc(elevel, sz);
3633 gen->name = guc_strdup(elevel, name);
3634 if (gen->name == NULL)
3640 gen->context = PGC_USERSET;
3641 gen->group = CUSTOM_OPTIONS;
3642 gen->short_desc = "GUC placeholder variable";
3643 gen->flags = GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_CUSTOM_PLACEHOLDER;
3644 gen->vartype = PGC_STRING;
3647 * The char* is allocated at the end of the struct since we have no
3648 * 'static' place to point to. Note that the current value, as well as
3649 * the boot and reset values, start out NULL.
3651 var->variable = (char **) (var + 1);
3653 if (!add_guc_variable((struct config_generic *) var, elevel))
3655 free((void *) gen->name);
3664 * Look up option NAME. If it exists, return a pointer to its record,
3665 * else return NULL. If create_placeholders is TRUE, we'll create a
3666 * placeholder record for a valid-looking custom variable name.
3668 static struct config_generic *
3669 find_option(const char *name, bool create_placeholders, int elevel)
3671 const char **key = &name;
3672 struct config_generic **res;
3678 * By equating const char ** with struct config_generic *, we are assuming
3679 * the name field is first in config_generic.
3681 res = (struct config_generic **) bsearch((void *) &key,
3682 (void *) guc_variables,
3684 sizeof(struct config_generic *),
3690 * See if the name is an obsolete name for a variable. We assume that the
3691 * set of supported old names is short enough that a brute-force search is
3694 for (i = 0; map_old_guc_names[i] != NULL; i += 2)
3696 if (guc_name_compare(name, map_old_guc_names[i]) == 0)
3697 return find_option(map_old_guc_names[i + 1], false, elevel);
3700 if (create_placeholders)
3703 * Check if the name is qualified, and if so, add a placeholder.
3705 if (strchr(name, GUC_QUALIFIER_SEPARATOR) != NULL)
3706 return add_placeholder_variable(name, elevel);
3715 * comparator for qsorting and bsearching guc_variables array
3718 guc_var_compare(const void *a, const void *b)
3720 struct config_generic *confa = *(struct config_generic **) a;
3721 struct config_generic *confb = *(struct config_generic **) b;
3723 return guc_name_compare(confa->name, confb->name);
3727 * the bare comparison function for GUC names
3730 guc_name_compare(const char *namea, const char *nameb)
3733 * The temptation to use strcasecmp() here must be resisted, because the
3734 * array ordering has to remain stable across setlocale() calls. So, build
3735 * our own with a simple ASCII-only downcasing.
3737 while (*namea && *nameb)
3739 char cha = *namea++;
3740 char chb = *nameb++;
3742 if (cha >= 'A' && cha <= 'Z')
3744 if (chb >= 'A' && chb <= 'Z')
3750 return 1; /* a is longer */
3752 return -1; /* b is longer */
3758 * Initialize GUC options during program startup.
3760 * Note that we cannot read the config file yet, since we have not yet
3761 * processed command-line switches.
3764 InitializeGUCOptions(void)
3769 * Before log_line_prefix could possibly receive a nonempty setting, make
3770 * sure that timezone processing is minimally alive (see elog.c).
3772 pg_timezone_initialize();
3775 * Build sorted array of all GUC variables.
3777 build_guc_variables();
3780 * Load all variables with their compiled-in defaults, and initialize
3781 * status fields as needed.
3783 for (i = 0; i < num_guc_variables; i++)
3785 InitializeOneGUCOption(guc_variables[i]);
3790 reporting_enabled = false;
3793 * Prevent any attempt to override the transaction modes from
3794 * non-interactive sources.
3796 SetConfigOption("transaction_isolation", "default",
3797 PGC_POSTMASTER, PGC_S_OVERRIDE);
3798 SetConfigOption("transaction_read_only", "no",
3799 PGC_POSTMASTER, PGC_S_OVERRIDE);
3800 SetConfigOption("transaction_deferrable", "no",
3801 PGC_POSTMASTER, PGC_S_OVERRIDE);
3804 * For historical reasons, some GUC parameters can receive defaults from
3805 * environment variables. Process those settings.
3807 InitializeGUCOptionsFromEnvironment();
3811 * Assign any GUC values that can come from the server's environment.
3813 * This is called from InitializeGUCOptions, and also from ProcessConfigFile
3814 * to deal with the possibility that a setting has been removed from
3815 * postgresql.conf and should now get a value from the environment.
3816 * (The latter is a kludge that should probably go away someday; if so,
3817 * fold this back into InitializeGUCOptions.)
3820 InitializeGUCOptionsFromEnvironment(void)
3825 env = getenv("PGPORT");
3827 SetConfigOption("port", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3829 env = getenv("PGDATESTYLE");
3831 SetConfigOption("datestyle", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3833 env = getenv("PGCLIENTENCODING");
3835 SetConfigOption("client_encoding", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3838 * rlimit isn't exactly an "environment variable", but it behaves about
3839 * the same. If we can identify the platform stack depth rlimit, increase
3840 * default stack depth setting up to whatever is safe (but at most 2MB).
3842 stack_rlimit = get_stack_depth_rlimit();
3843 if (stack_rlimit > 0)
3845 long new_limit = (stack_rlimit - STACK_DEPTH_SLOP) / 1024L;
3847 if (new_limit > 100)
3851 new_limit = Min(new_limit, 2048);
3852 sprintf(limbuf, "%ld", new_limit);
3853 SetConfigOption("max_stack_depth", limbuf,
3854 PGC_POSTMASTER, PGC_S_ENV_VAR);
3860 * Initialize one GUC option variable to its compiled-in default.
3862 * Note: the reason for calling check_hooks is not that we think the boot_val
3863 * might fail, but that the hooks might wish to compute an "extra" struct.
3866 InitializeOneGUCOption(struct config_generic * gconf)
3869 gconf->source = PGC_S_DEFAULT;
3870 gconf->reset_source = PGC_S_DEFAULT;
3871 gconf->scontext = PGC_INTERNAL;
3872 gconf->reset_scontext = PGC_INTERNAL;
3873 gconf->stack = NULL;
3874 gconf->extra = NULL;
3875 gconf->sourcefile = NULL;
3876 gconf->sourceline = 0;
3878 switch (gconf->vartype)
3882 struct config_bool *conf = (struct config_bool *) gconf;
3883 bool newval = conf->boot_val;
3886 if (!call_bool_check_hook(conf, &newval, &extra,
3887 PGC_S_DEFAULT, LOG))
3888 elog(FATAL, "failed to initialize %s to %d",
3889 conf->gen.name, (int) newval);
3890 if (conf->assign_hook)
3891 (*conf->assign_hook) (newval, extra);
3892 *conf->variable = conf->reset_val = newval;
3893 conf->gen.extra = conf->reset_extra = extra;
3898 struct config_int *conf = (struct config_int *) gconf;
3899 int newval = conf->boot_val;
3902 Assert(newval >= conf->min);
3903 Assert(newval <= conf->max);
3904 if (!call_int_check_hook(conf, &newval, &extra,
3905 PGC_S_DEFAULT, LOG))
3906 elog(FATAL, "failed to initialize %s to %d",
3907 conf->gen.name, newval);
3908 if (conf->assign_hook)
3909 (*conf->assign_hook) (newval, extra);
3910 *conf->variable = conf->reset_val = newval;
3911 conf->gen.extra = conf->reset_extra = extra;
3916 struct config_real *conf = (struct config_real *) gconf;
3917 double newval = conf->boot_val;
3920 Assert(newval >= conf->min);
3921 Assert(newval <= conf->max);
3922 if (!call_real_check_hook(conf, &newval, &extra,
3923 PGC_S_DEFAULT, LOG))
3924 elog(FATAL, "failed to initialize %s to %g",
3925 conf->gen.name, newval);
3926 if (conf->assign_hook)
3927 (*conf->assign_hook) (newval, extra);
3928 *conf->variable = conf->reset_val = newval;
3929 conf->gen.extra = conf->reset_extra = extra;
3934 struct config_string *conf = (struct config_string *) gconf;
3938 /* non-NULL boot_val must always get strdup'd */
3939 if (conf->boot_val != NULL)
3940 newval = guc_strdup(FATAL, conf->boot_val);
3944 if (!call_string_check_hook(conf, &newval, &extra,
3945 PGC_S_DEFAULT, LOG))
3946 elog(FATAL, "failed to initialize %s to \"%s\"",
3947 conf->gen.name, newval ? newval : "");
3948 if (conf->assign_hook)
3949 (*conf->assign_hook) (newval, extra);
3950 *conf->variable = conf->reset_val = newval;
3951 conf->gen.extra = conf->reset_extra = extra;
3956 struct config_enum *conf = (struct config_enum *) gconf;
3957 int newval = conf->boot_val;
3960 if (!call_enum_check_hook(conf, &newval, &extra,
3961 PGC_S_DEFAULT, LOG))
3962 elog(FATAL, "failed to initialize %s to %d",
3963 conf->gen.name, newval);
3964 if (conf->assign_hook)
3965 (*conf->assign_hook) (newval, extra);
3966 *conf->variable = conf->reset_val = newval;
3967 conf->gen.extra = conf->reset_extra = extra;
3975 * Select the configuration files and data directory to be used, and
3976 * do the initial read of postgresql.conf.
3978 * This is called after processing command-line switches.
3979 * userDoption is the -D switch value if any (NULL if unspecified).
3980 * progname is just for use in error messages.
3982 * Returns true on success; on failure, prints a suitable error message
3983 * to stderr and returns false.
3986 SelectConfigFiles(const char *userDoption, const char *progname)
3990 struct stat stat_buf;
3992 /* configdir is -D option, or $PGDATA if no -D */
3994 configdir = make_absolute_path(userDoption);
3996 configdir = make_absolute_path(getenv("PGDATA"));
3999 * Find the configuration file: if config_file was specified on the
4000 * command line, use it, else use configdir/postgresql.conf. In any case
4001 * ensure the result is an absolute path, so that it will be interpreted
4002 * the same way by future backends.
4005 fname = make_absolute_path(ConfigFileName);
4008 fname = guc_malloc(FATAL,
4009 strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
4010 sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
4014 write_stderr("%s does not know where to find the server configuration file.\n"
4015 "You must specify the --config-file or -D invocation "
4016 "option or set the PGDATA environment variable.\n",
4022 * Set the ConfigFileName GUC variable to its final value, ensuring that
4023 * it can't be overridden later.
4025 SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4029 * Now read the config file for the first time.
4031 if (stat(ConfigFileName, &stat_buf) != 0)
4033 write_stderr("%s cannot access the server configuration file \"%s\": %s\n",
4034 progname, ConfigFileName, strerror(errno));
4038 ProcessConfigFile(PGC_POSTMASTER);
4041 * If the data_directory GUC variable has been set, use that as DataDir;
4042 * otherwise use configdir if set; else punt.
4044 * Note: SetDataDir will copy and absolute-ize its argument, so we don't
4048 SetDataDir(data_directory);
4050 SetDataDir(configdir);
4053 write_stderr("%s does not know where to find the database system data.\n"
4054 "This can be specified as \"data_directory\" in \"%s\", "
4055 "or by the -D invocation option, or by the "
4056 "PGDATA environment variable.\n",
4057 progname, ConfigFileName);
4062 * Reflect the final DataDir value back into the data_directory GUC var.
4063 * (If you are wondering why we don't just make them a single variable,
4064 * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
4065 * child backends specially. XXX is that still true? Given that we now
4066 * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
4067 * DataDir in advance.)
4069 SetConfigOption("data_directory", DataDir, PGC_POSTMASTER, PGC_S_OVERRIDE);
4072 * If timezone_abbreviations wasn't set in the configuration file, install
4073 * the default value. We do it this way because we can't safely install
4074 * a "real" value until my_exec_path is set, which may not have happened
4075 * when InitializeGUCOptions runs, so the bootstrap default value cannot
4076 * be the real desired default.
4078 pg_timezone_abbrev_initialize();
4081 * Figure out where pg_hba.conf is, and make sure the path is absolute.
4084 fname = make_absolute_path(HbaFileName);
4087 fname = guc_malloc(FATAL,
4088 strlen(configdir) + strlen(HBA_FILENAME) + 2);
4089 sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
4093 write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
4094 "This can be specified as \"hba_file\" in \"%s\", "
4095 "or by the -D invocation option, or by the "
4096 "PGDATA environment variable.\n",
4097 progname, ConfigFileName);
4100 SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4104 * Likewise for pg_ident.conf.
4107 fname = make_absolute_path(IdentFileName);
4110 fname = guc_malloc(FATAL,
4111 strlen(configdir) + strlen(IDENT_FILENAME) + 2);
4112 sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
4116 write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
4117 "This can be specified as \"ident_file\" in \"%s\", "
4118 "or by the -D invocation option, or by the "
4119 "PGDATA environment variable.\n",
4120 progname, ConfigFileName);
4123 SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4133 * Reset all options to their saved default values (implements RESET ALL)
4136 ResetAllOptions(void)
4140 for (i = 0; i < num_guc_variables; i++)
4142 struct config_generic *gconf = guc_variables[i];
4144 /* Don't reset non-SET-able values */
4145 if (gconf->context != PGC_SUSET &&
4146 gconf->context != PGC_USERSET)
4148 /* Don't reset if special exclusion from RESET ALL */
4149 if (gconf->flags & GUC_NO_RESET_ALL)
4151 /* No need to reset if wasn't SET */
4152 if (gconf->source <= PGC_S_OVERRIDE)
4155 /* Save old value to support transaction abort */
4156 push_old_value(gconf, GUC_ACTION_SET);
4158 switch (gconf->vartype)
4162 struct config_bool *conf = (struct config_bool *) gconf;
4164 if (conf->assign_hook)
4165 (*conf->assign_hook) (conf->reset_val,
4167 *conf->variable = conf->reset_val;
4168 set_extra_field(&conf->gen, &conf->gen.extra,
4174 struct config_int *conf = (struct config_int *) gconf;
4176 if (conf->assign_hook)
4177 (*conf->assign_hook) (conf->reset_val,
4179 *conf->variable = conf->reset_val;
4180 set_extra_field(&conf->gen, &conf->gen.extra,
4186 struct config_real *conf = (struct config_real *) gconf;
4188 if (conf->assign_hook)
4189 (*conf->assign_hook) (conf->reset_val,
4191 *conf->variable = conf->reset_val;
4192 set_extra_field(&conf->gen, &conf->gen.extra,
4198 struct config_string *conf = (struct config_string *) gconf;
4200 if (conf->assign_hook)
4201 (*conf->assign_hook) (conf->reset_val,
4203 set_string_field(conf, conf->variable, conf->reset_val);
4204 set_extra_field(&conf->gen, &conf->gen.extra,
4210 struct config_enum *conf = (struct config_enum *) gconf;
4212 if (conf->assign_hook)
4213 (*conf->assign_hook) (conf->reset_val,
4215 *conf->variable = conf->reset_val;
4216 set_extra_field(&conf->gen, &conf->gen.extra,
4222 gconf->source = gconf->reset_source;
4223 gconf->scontext = gconf->reset_scontext;
4225 if (gconf->flags & GUC_REPORT)
4226 ReportGUCOption(gconf);
4233 * Push previous state during transactional assignment to a GUC variable.
4236 push_old_value(struct config_generic * gconf, GucAction action)
4240 /* If we're not inside a nest level, do nothing */
4241 if (GUCNestLevel == 0)
4244 /* Do we already have a stack entry of the current nest level? */
4245 stack = gconf->stack;
4246 if (stack && stack->nest_level >= GUCNestLevel)
4248 /* Yes, so adjust its state if necessary */
4249 Assert(stack->nest_level == GUCNestLevel);
4252 case GUC_ACTION_SET:
4253 /* SET overrides any prior action at same nest level */
4254 if (stack->state == GUC_SET_LOCAL)
4256 /* must discard old masked value */
4257 discard_stack_value(gconf, &stack->masked);
4259 stack->state = GUC_SET;
4261 case GUC_ACTION_LOCAL:
4262 if (stack->state == GUC_SET)
4264 /* SET followed by SET LOCAL, remember SET's value */
4265 stack->masked_scontext = gconf->scontext;
4266 set_stack_value(gconf, &stack->masked);
4267 stack->state = GUC_SET_LOCAL;
4269 /* in all other cases, no change to stack entry */
4271 case GUC_ACTION_SAVE:
4272 /* Could only have a prior SAVE of same variable */
4273 Assert(stack->state == GUC_SAVE);
4276 Assert(guc_dirty); /* must be set already */
4281 * Push a new stack entry
4283 * We keep all the stack entries in TopTransactionContext for simplicity.
4285 stack = (GucStack *) MemoryContextAllocZero(TopTransactionContext,
4288 stack->prev = gconf->stack;
4289 stack->nest_level = GUCNestLevel;
4292 case GUC_ACTION_SET:
4293 stack->state = GUC_SET;
4295 case GUC_ACTION_LOCAL:
4296 stack->state = GUC_LOCAL;
4298 case GUC_ACTION_SAVE:
4299 stack->state = GUC_SAVE;
4302 stack->source = gconf->source;
4303 stack->scontext = gconf->scontext;
4304 set_stack_value(gconf, &stack->prior);
4306 gconf->stack = stack;
4308 /* Ensure we remember to pop at end of xact */
4314 * Do GUC processing at main transaction start.
4320 * The nest level should be 0 between transactions; if it isn't, somebody
4321 * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
4322 * throw a warning but make no other effort to clean up.
4324 if (GUCNestLevel != 0)
4325 elog(WARNING, "GUC nest level = %d at transaction start",
4331 * Enter a new nesting level for GUC values. This is called at subtransaction
4332 * start and when entering a function that has proconfig settings. NOTE that
4333 * 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. (The name is thus
4344 * a bit of a misnomer; perhaps it should be ExitGUCNestLevel or some such.)
4345 * During abort, we discard all GUC settings that were applied at nesting
4346 * levels >= nestLevel. nestLevel == 1 corresponds to the main transaction.
4349 AtEOXact_GUC(bool isCommit, int nestLevel)
4355 * Note: it's possible to get here with GUCNestLevel == nestLevel-1 during
4356 * abort, if there is a failure during transaction start before
4357 * AtStart_GUC is called.
4359 Assert(nestLevel > 0 &&
4360 (nestLevel <= GUCNestLevel ||
4361 (nestLevel == GUCNestLevel + 1 && !isCommit)));
4363 /* Quick exit if nothing's changed in this transaction */
4366 GUCNestLevel = nestLevel - 1;
4370 still_dirty = false;
4371 for (i = 0; i < num_guc_variables; i++)
4373 struct config_generic *gconf = guc_variables[i];
4377 * Process and pop each stack entry within the nest level. To
4378 * simplify fmgr_security_definer(), we allow failure exit from a
4379 * function-with-SET-options to be recovered at the surrounding
4380 * transaction or subtransaction abort; so there could be more than
4381 * one stack entry to pop.
4383 while ((stack = gconf->stack) != NULL &&
4384 stack->nest_level >= nestLevel)
4386 GucStack *prev = stack->prev;
4387 bool restorePrior = false;
4388 bool restoreMasked = false;
4392 * In this next bit, if we don't set either restorePrior or
4393 * restoreMasked, we must "discard" any unwanted fields of the
4394 * stack entries to avoid leaking memory. If we do set one of
4395 * those flags, unused fields will be cleaned up after restoring.
4397 if (!isCommit) /* if abort, always restore prior value */
4398 restorePrior = true;
4399 else if (stack->state == GUC_SAVE)
4400 restorePrior = true;
4401 else if (stack->nest_level == 1)
4403 /* transaction commit */
4404 if (stack->state == GUC_SET_LOCAL)
4405 restoreMasked = true;
4406 else if (stack->state == GUC_SET)
4408 /* we keep the current active value */
4409 discard_stack_value(gconf, &stack->prior);
4411 else /* must be GUC_LOCAL */
4412 restorePrior = true;
4414 else if (prev == NULL ||
4415 prev->nest_level < stack->nest_level - 1)
4417 /* decrement entry's level and do not pop it */
4418 stack->nest_level--;
4424 * We have to merge this stack entry into prev. See README for
4425 * discussion of this bit.
4427 switch (stack->state)
4430 Assert(false); /* can't get here */
4433 /* next level always becomes SET */
4434 discard_stack_value(gconf, &stack->prior);
4435 if (prev->state == GUC_SET_LOCAL)
4436 discard_stack_value(gconf, &prev->masked);
4437 prev->state = GUC_SET;
4441 if (prev->state == GUC_SET)
4443 /* LOCAL migrates down */
4444 prev->masked_scontext = stack->scontext;
4445 prev->masked = stack->prior;
4446 prev->state = GUC_SET_LOCAL;
4450 /* else just forget this stack level */
4451 discard_stack_value(gconf, &stack->prior);
4456 /* prior state at this level no longer wanted */
4457 discard_stack_value(gconf, &stack->prior);
4458 /* copy down the masked state */
4459 prev->masked_scontext = stack->masked_scontext;
4460 if (prev->state == GUC_SET_LOCAL)
4461 discard_stack_value(gconf, &prev->masked);
4462 prev->masked = stack->masked;
4463 prev->state = GUC_SET_LOCAL;
4470 if (restorePrior || restoreMasked)
4472 /* Perform appropriate restoration of the stacked value */
4473 config_var_value newvalue;
4474 GucSource newsource;
4475 GucContext newscontext;
4479 newvalue = stack->masked;
4480 newsource = PGC_S_SESSION;
4481 newscontext = stack->masked_scontext;
4485 newvalue = stack->prior;
4486 newsource = stack->source;
4487 newscontext = stack->scontext;
4490 switch (gconf->vartype)
4494 struct config_bool *conf = (struct config_bool *) gconf;
4495 bool newval = newvalue.val.boolval;
4496 void *newextra = newvalue.extra;
4498 if (*conf->variable != newval ||
4499 conf->gen.extra != newextra)
4501 if (conf->assign_hook)
4502 (*conf->assign_hook) (newval, newextra);
4503 *conf->variable = newval;
4504 set_extra_field(&conf->gen, &conf->gen.extra,
4512 struct config_int *conf = (struct config_int *) gconf;
4513 int newval = newvalue.val.intval;
4514 void *newextra = newvalue.extra;
4516 if (*conf->variable != newval ||
4517 conf->gen.extra != newextra)
4519 if (conf->assign_hook)
4520 (*conf->assign_hook) (newval, newextra);
4521 *conf->variable = newval;
4522 set_extra_field(&conf->gen, &conf->gen.extra,
4530 struct config_real *conf = (struct config_real *) gconf;
4531 double newval = newvalue.val.realval;
4532 void *newextra = newvalue.extra;
4534 if (*conf->variable != newval ||
4535 conf->gen.extra != newextra)
4537 if (conf->assign_hook)
4538 (*conf->assign_hook) (newval, newextra);
4539 *conf->variable = newval;
4540 set_extra_field(&conf->gen, &conf->gen.extra,
4548 struct config_string *conf = (struct config_string *) gconf;
4549 char *newval = newvalue.val.stringval;
4550 void *newextra = newvalue.extra;
4552 if (*conf->variable != newval ||
4553 conf->gen.extra != newextra)
4555 if (conf->assign_hook)
4556 (*conf->assign_hook) (newval, newextra);
4557 set_string_field(conf, conf->variable, newval);
4558 set_extra_field(&conf->gen, &conf->gen.extra,
4564 * Release stacked values if not used anymore. We
4565 * could use discard_stack_value() here, but since
4566 * we have type-specific code anyway, might as
4569 set_string_field(conf, &stack->prior.val.stringval, NULL);
4570 set_string_field(conf, &stack->masked.val.stringval, NULL);
4575 struct config_enum *conf = (struct config_enum *) gconf;
4576 int newval = newvalue.val.enumval;
4577 void *newextra = newvalue.extra;
4579 if (*conf->variable != newval ||
4580 conf->gen.extra != newextra)
4582 if (conf->assign_hook)
4583 (*conf->assign_hook) (newval, newextra);
4584 *conf->variable = newval;
4585 set_extra_field(&conf->gen, &conf->gen.extra,
4594 * Release stacked extra values if not used anymore.
4596 set_extra_field(gconf, &(stack->prior.extra), NULL);
4597 set_extra_field(gconf, &(stack->masked.extra), NULL);
4599 /* And restore source information */
4600 gconf->source = newsource;
4601 gconf->scontext = newscontext;
4604 /* Finish popping the state stack */
4605 gconf->stack = prev;
4608 /* Report new value if we changed it */
4609 if (changed && (gconf->flags & GUC_REPORT))
4610 ReportGUCOption(gconf);
4611 } /* end of stack-popping loop */
4617 /* If there are no remaining stack entries, we can reset guc_dirty */
4618 guc_dirty = still_dirty;
4620 /* Update nesting level */
4621 GUCNestLevel = nestLevel - 1;
4626 * Start up automatic reporting of changes to variables marked GUC_REPORT.
4627 * This is executed at completion of backend startup.
4630 BeginReportingGUCOptions(void)
4635 * Don't do anything unless talking to an interactive frontend of protocol
4638 if (whereToSendOutput != DestRemote ||
4639 PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
4642 reporting_enabled = true;
4644 /* Transmit initial values of interesting variables */
4645 for (i = 0; i < num_guc_variables; i++)
4647 struct config_generic *conf = guc_variables[i];
4649 if (conf->flags & GUC_REPORT)
4650 ReportGUCOption(conf);
4655 * ReportGUCOption: if appropriate, transmit option value to frontend
4658 ReportGUCOption(struct config_generic * record)
4660 if (reporting_enabled && (record->flags & GUC_REPORT))
4662 char *val = _ShowOption(record, false);
4663 StringInfoData msgbuf;
4665 pq_beginmessage(&msgbuf, 'S');
4666 pq_sendstring(&msgbuf, record->name);
4667 pq_sendstring(&msgbuf, val);
4668 pq_endmessage(&msgbuf);
4675 * Try to parse value as an integer. The accepted formats are the
4676 * usual decimal, octal, or hexadecimal formats, optionally followed by
4677 * a unit name if "flags" indicates a unit is allowed.
4679 * If the string parses okay, return true, else false.
4680 * If okay and result is not NULL, return the value in *result.
4681 * If not okay and hintmsg is not NULL, *hintmsg is set to a suitable
4682 * HINT message, or NULL if no hint provided.
4685 parse_int(const char *value, int *result, int flags, const char **hintmsg)
4690 /* To suppress compiler warnings, always set output params */
4696 /* We assume here that int64 is at least as wide as long */
4698 val = strtol(value, &endptr, 0);
4700 if (endptr == value)
4701 return false; /* no HINT for integer syntax error */
4703 if (errno == ERANGE || val != (int64) ((int32) val))
4706 *hintmsg = gettext_noop("Value exceeds integer range.");
4710 /* allow whitespace between integer and unit */
4711 while (isspace((unsigned char) *endptr))
4714 /* Handle possible unit */
4715 if (*endptr != '\0')
4718 * Note: the multiple-switch coding technique here is a bit tedious,
4719 * but seems necessary to avoid intermediate-value overflows.
4721 if (flags & GUC_UNIT_MEMORY)
4723 /* Set hint for use if no match or trailing garbage */
4725 *hintmsg = gettext_noop("Valid units for this parameter are \"kB\", \"MB\", and \"GB\".");
4727 #if BLCKSZ < 1024 || BLCKSZ > (1024*1024)
4728 #error BLCKSZ must be between 1KB and 1MB
4730 #if XLOG_BLCKSZ < 1024 || XLOG_BLCKSZ > (1024*1024)
4731 #error XLOG_BLCKSZ must be between 1KB and 1MB
4734 if (strncmp(endptr, "kB", 2) == 0)
4737 switch (flags & GUC_UNIT_MEMORY)
4739 case GUC_UNIT_BLOCKS:
4740 val /= (BLCKSZ / 1024);
4742 case GUC_UNIT_XBLOCKS:
4743 val /= (XLOG_BLCKSZ / 1024);
4747 else if (strncmp(endptr, "MB", 2) == 0)
4750 switch (flags & GUC_UNIT_MEMORY)
4755 case GUC_UNIT_BLOCKS:
4756 val *= KB_PER_MB / (BLCKSZ / 1024);
4758 case GUC_UNIT_XBLOCKS:
4759 val *= KB_PER_MB / (XLOG_BLCKSZ / 1024);
4763 else if (strncmp(endptr, "GB", 2) == 0)
4766 switch (flags & GUC_UNIT_MEMORY)
4771 case GUC_UNIT_BLOCKS:
4772 val *= KB_PER_GB / (BLCKSZ / 1024);
4774 case GUC_UNIT_XBLOCKS:
4775 val *= KB_PER_GB / (XLOG_BLCKSZ / 1024);
4780 else if (flags & GUC_UNIT_TIME)
4782 /* Set hint for use if no match or trailing garbage */
4784 *hintmsg = gettext_noop("Valid units for this parameter are \"ms\", \"s\", \"min\", \"h\", and \"d\".");
4786 if (strncmp(endptr, "ms", 2) == 0)
4789 switch (flags & GUC_UNIT_TIME)
4799 else if (strncmp(endptr, "s", 1) == 0)
4802 switch (flags & GUC_UNIT_TIME)
4812 else if (strncmp(endptr, "min", 3) == 0)
4815 switch (flags & GUC_UNIT_TIME)
4825 else if (strncmp(endptr, "h", 1) == 0)
4828 switch (flags & GUC_UNIT_TIME)
4841 else if (strncmp(endptr, "d", 1) == 0)
4844 switch (flags & GUC_UNIT_TIME)
4859 /* allow whitespace after unit */
4860 while (isspace((unsigned char) *endptr))
4863 if (*endptr != '\0')
4864 return false; /* appropriate hint, if any, already set */
4866 /* Check for overflow due to units conversion */
4867 if (val != (int64) ((int32) val))
4870 *hintmsg = gettext_noop("Value exceeds integer range.");
4876 *result = (int) val;
4883 * Try to parse value as a floating point number in the usual format.
4884 * If the string parses okay, return true, else false.
4885 * If okay and result is not NULL, return the value in *result.
4888 parse_real(const char *value, double *result)
4894 *result = 0; /* suppress compiler warning */
4897 val = strtod(value, &endptr);
4898 if (endptr == value || errno == ERANGE)
4901 /* allow whitespace after number */
4902 while (isspace((unsigned char) *endptr))
4904 if (*endptr != '\0')
4914 * Lookup the name for an enum option with the selected value.
4915 * Should only ever be called with known-valid values, so throws
4916 * an elog(ERROR) if the enum option is not found.
4918 * The returned string is a pointer to static data and not
4919 * allocated for modification.
4922 config_enum_lookup_by_value(struct config_enum * record, int val)
4924 const struct config_enum_entry *entry;
4926 for (entry = record->options; entry && entry->name; entry++)
4928 if (entry->val == val)
4932 elog(ERROR, "could not find enum option %d for %s",
4933 val, record->gen.name);
4934 return NULL; /* silence compiler */
4939 * Lookup the value for an enum option with the selected name
4940 * (case-insensitive).
4941 * If the enum option is found, sets the retval value and returns
4942 * true. If it's not found, return FALSE and retval is set to 0.
4945 config_enum_lookup_by_name(struct config_enum * record, const char *value,
4948 const struct config_enum_entry *entry;
4950 for (entry = record->options; entry && entry->name; entry++)
4952 if (pg_strcasecmp(value, entry->name) == 0)
4954 *retval = entry->val;
4965 * Return a list of all available options for an enum, excluding
4966 * hidden ones, separated by the given separator.
4967 * If prefix is non-NULL, it is added before the first enum value.
4968 * If suffix is non-NULL, it is added to the end of the string.
4971 config_enum_get_options(struct config_enum * record, const char *prefix,
4972 const char *suffix, const char *separator)
4974 const struct config_enum_entry *entry;
4975 StringInfoData retstr;
4978 initStringInfo(&retstr);
4979 appendStringInfoString(&retstr, prefix);
4981 seplen = strlen(separator);
4982 for (entry = record->options; entry && entry->name; entry++)
4986 appendStringInfoString(&retstr, entry->name);
4987 appendBinaryStringInfo(&retstr, separator, seplen);
4992 * All the entries may have been hidden, leaving the string empty if no
4993 * prefix was given. This indicates a broken GUC setup, since there is no
4994 * use for an enum without any values, so we just check to make sure we
4995 * don't write to invalid memory instead of actually trying to do
4996 * something smart with it.
4998 if (retstr.len >= seplen)
5000 /* Replace final separator */
5001 retstr.data[retstr.len - seplen] = '\0';
5002 retstr.len -= seplen;
5005 appendStringInfoString(&retstr, suffix);
5012 * Sets option `name' to given value.
5014 * The value should be a string, which will be parsed and converted to
5015 * the appropriate data type. The context and source parameters indicate
5016 * in which context this function is being called, so that it can apply the
5017 * access restrictions properly.
5019 * If value is NULL, set the option to its default value (normally the
5020 * reset_val, but if source == PGC_S_DEFAULT we instead use the boot_val).
5022 * action indicates whether to set the value globally in the session, locally
5023 * to the current top transaction, or just for the duration of a function call.
5025 * If changeVal is false then don't really set the option but do all
5026 * the checks to see if it would work.
5028 * elevel should normally be passed as zero, allowing this function to make
5029 * its standard choice of ereport level. However some callers need to be
5030 * able to override that choice; they should pass the ereport level to use.
5033 * +1: the value is valid and was successfully applied.
5034 * 0: the name or value is invalid (but see below).
5035 * -1: the value was not applied because of context, priority, or changeVal.
5037 * If there is an error (non-existing option, invalid value) then an
5038 * ereport(ERROR) is thrown *unless* this is called for a source for which
5039 * we don't want an ERROR (currently, those are defaults, the config file,
5040 * and per-database or per-user settings, as well as callers who specify
5041 * a less-than-ERROR elevel). In those cases we write a suitable error
5042 * message via ereport() and return 0.
5044 * See also SetConfigOption for an external interface.
5047 set_config_option(const char *name, const char *value,
5048 GucContext context, GucSource source,
5049 GucAction action, bool changeVal, int elevel)
5051 struct config_generic *record;
5052 bool prohibitValueChange = false;
5057 if (source == PGC_S_DEFAULT || source == PGC_S_FILE)
5060 * To avoid cluttering the log, only the postmaster bleats loudly
5061 * about problems with the config file.
5063 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
5065 else if (source == PGC_S_DATABASE || source == PGC_S_USER ||
5066 source == PGC_S_DATABASE_USER)
5072 record = find_option(name, true, elevel);
5076 (errcode(ERRCODE_UNDEFINED_OBJECT),
5077 errmsg("unrecognized configuration parameter \"%s\"", name)));
5082 * Check if the option can be set at this time. See guc.h for the precise
5085 switch (record->context)
5088 if (context != PGC_INTERNAL)
5091 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5092 errmsg("parameter \"%s\" cannot be changed",
5097 case PGC_POSTMASTER:
5098 if (context == PGC_SIGHUP)
5101 * We are re-reading a PGC_POSTMASTER variable from
5102 * postgresql.conf. We can't change the setting, so we should
5103 * give a warning if the DBA tries to change it. However,
5104 * because of variant formats, canonicalization by check
5105 * hooks, etc, we can't just compare the given string directly
5106 * to what's stored. Set a flag to check below after we have
5107 * the final storable value.
5109 prohibitValueChange = true;
5111 else if (context != PGC_POSTMASTER)
5114 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5115 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5121 if (context != PGC_SIGHUP && context != PGC_POSTMASTER)
5124 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5125 errmsg("parameter \"%s\" cannot be changed now",
5131 * Hmm, the idea of the SIGHUP context is "ought to be global, but
5132 * can be changed after postmaster start". But there's nothing
5133 * that prevents a crafty administrator from sending SIGHUP
5134 * signals to individual backends only.
5138 if (context == PGC_SIGHUP)
5141 * If a PGC_BACKEND parameter is changed in the config file,
5142 * we want to accept the new value in the postmaster (whence
5143 * it will propagate to subsequently-started backends), but
5144 * ignore it in existing backends. This is a tad klugy, but
5145 * necessary because we don't re-read the config file during
5148 if (IsUnderPostmaster)
5151 else if (context != PGC_POSTMASTER && context != PGC_BACKEND &&
5152 source != PGC_S_CLIENT)
5155 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5156 errmsg("parameter \"%s\" cannot be set after connection start",
5162 if (context == PGC_USERSET || context == PGC_BACKEND)
5165 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5166 errmsg("permission denied to set parameter \"%s\"",
5177 * Disallow changing GUC_NOT_WHILE_SEC_REST values if we are inside a
5178 * security restriction context. We can reject this regardless of the GUC
5179 * context or source, mainly because sources that it might be reasonable
5180 * to override for won't be seen while inside a function.
5182 * Note: variables marked GUC_NOT_WHILE_SEC_REST should usually be marked
5183 * GUC_NO_RESET_ALL as well, because ResetAllOptions() doesn't check this.
5184 * An exception might be made if the reset value is assumed to be "safe".
5186 * Note: this flag is currently used for "session_authorization" and
5187 * "role". We need to prohibit changing these inside a local userid
5188 * context because when we exit it, GUC won't be notified, leaving things
5189 * out of sync. (This could be fixed by forcing a new GUC nesting level,
5190 * but that would change behavior in possibly-undesirable ways.) Also, we
5191 * prohibit changing these in a security-restricted operation because
5192 * otherwise RESET could be used to regain the session user's privileges.
5194 if (record->flags & GUC_NOT_WHILE_SEC_REST)
5196 if (InLocalUserIdChange())
5199 * Phrasing of this error message is historical, but it's the most
5203 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5204 errmsg("cannot set parameter \"%s\" within security-definer function",
5208 if (InSecurityRestrictedOperation())
5211 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5212 errmsg("cannot set parameter \"%s\" within security-restricted operation",
5219 * Should we set reset/stacked values? (If so, the behavior is not
5220 * transactional.) This is done either when we get a default value from
5221 * the database's/user's/client's default settings or when we reset a
5222 * value to its default.
5224 makeDefault = changeVal && (source <= PGC_S_OVERRIDE) &&
5225 ((value != NULL) || source == PGC_S_DEFAULT);
5228 * Ignore attempted set if overridden by previously processed setting.
5229 * However, if changeVal is false then plow ahead anyway since we are
5230 * trying to find out if the value is potentially good, not actually use
5231 * it. Also keep going if makeDefault is true, since we may want to set
5232 * the reset/stacked values even if we can't set the variable itself.
5234 if (record->source > source)
5236 if (changeVal && !makeDefault)
5238 elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
5246 * Evaluate value and set variable.
5248 switch (record->vartype)
5252 struct config_bool *conf = (struct config_bool *) record;
5254 void *newextra = NULL;
5258 if (!parse_bool(value, &newval))
5261 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5262 errmsg("parameter \"%s\" requires a Boolean value",
5266 if (!call_bool_check_hook(conf, &newval, &newextra,
5270 else if (source == PGC_S_DEFAULT)
5272 newval = conf->boot_val;
5273 if (!call_bool_check_hook(conf, &newval, &newextra,
5279 newval = conf->reset_val;
5280 newextra = conf->reset_extra;
5281 source = conf->gen.reset_source;
5282 context = conf->gen.reset_scontext;
5285 if (prohibitValueChange)
5287 if (*conf->variable != newval)
5290 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5291 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5300 /* Save old value to support transaction abort */
5302 push_old_value(&conf->gen, action);
5304 if (conf->assign_hook)
5305 (*conf->assign_hook) (newval, newextra);
5306 *conf->variable = newval;
5307 set_extra_field(&conf->gen, &conf->gen.extra,
5309 conf->gen.source = source;
5310 conf->gen.scontext = context;
5316 if (conf->gen.reset_source <= source)
5318 conf->reset_val = newval;
5319 set_extra_field(&conf->gen, &conf->reset_extra,
5321 conf->gen.reset_source = source;
5322 conf->gen.reset_scontext = context;
5324 for (stack = conf->gen.stack; stack; stack = stack->prev)
5326 if (stack->source <= source)
5328 stack->prior.val.boolval = newval;
5329 set_extra_field(&conf->gen, &stack->prior.extra,
5331 stack->source = source;
5332 stack->scontext = context;
5337 /* Perhaps we didn't install newextra anywhere */
5338 if (newextra && !extra_field_used(&conf->gen, newextra))
5345 struct config_int *conf = (struct config_int *) record;
5347 void *newextra = NULL;
5351 const char *hintmsg;
5353 if (!parse_int(value, &newval, conf->gen.flags, &hintmsg))
5356 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5357 errmsg("invalid value for parameter \"%s\": \"%s\"",
5359 hintmsg ? errhint("%s", _(hintmsg)) : 0));
5362 if (newval < conf->min || newval > conf->max)
5365 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5366 errmsg("%d is outside the valid range for parameter \"%s\" (%d .. %d)",
5367 newval, name, conf->min, conf->max)));
5370 if (!call_int_check_hook(conf, &newval, &newextra,
5374 else if (source == PGC_S_DEFAULT)
5376 newval = conf->boot_val;
5377 if (!call_int_check_hook(conf, &newval, &newextra,
5383 newval = conf->reset_val;
5384 newextra = conf->reset_extra;
5385 source = conf->gen.reset_source;
5386 context = conf->gen.reset_scontext;
5389 if (prohibitValueChange)
5391 if (*conf->variable != newval)
5394 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5395 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5404 /* Save old value to support transaction abort */
5406 push_old_value(&conf->gen, action);
5408 if (conf->assign_hook)
5409 (*conf->assign_hook) (newval, newextra);
5410 *conf->variable = newval;
5411 set_extra_field(&conf->gen, &conf->gen.extra,
5413 conf->gen.source = source;
5414 conf->gen.scontext = context;
5420 if (conf->gen.reset_source <= source)
5422 conf->reset_val = newval;
5423 set_extra_field(&conf->gen, &conf->reset_extra,
5425 conf->gen.reset_source = source;
5426 conf->gen.reset_scontext = context;
5428 for (stack = conf->gen.stack; stack; stack = stack->prev)
5430 if (stack->source <= source)
5432 stack->prior.val.intval = newval;
5433 set_extra_field(&conf->gen, &stack->prior.extra,
5435 stack->source = source;
5436 stack->scontext = context;
5441 /* Perhaps we didn't install newextra anywhere */
5442 if (newextra && !extra_field_used(&conf->gen, newextra))
5449 struct config_real *conf = (struct config_real *) record;
5451 void *newextra = NULL;
5455 if (!parse_real(value, &newval))
5458 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5459 errmsg("parameter \"%s\" requires a numeric value",
5463 if (newval < conf->min || newval > conf->max)
5466 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5467 errmsg("%g is outside the valid range for parameter \"%s\" (%g .. %g)",
5468 newval, name, conf->min, conf->max)));
5471 if (!call_real_check_hook(conf, &newval, &newextra,
5475 else if (source == PGC_S_DEFAULT)
5477 newval = conf->boot_val;
5478 if (!call_real_check_hook(conf, &newval, &newextra,
5484 newval = conf->reset_val;
5485 newextra = conf->reset_extra;
5486 source = conf->gen.reset_source;
5487 context = conf->gen.reset_scontext;
5490 if (prohibitValueChange)
5492 if (*conf->variable != newval)
5495 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5496 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5505 /* Save old value to support transaction abort */
5507 push_old_value(&conf->gen, action);
5509 if (conf->assign_hook)
5510 (*conf->assign_hook) (newval, newextra);
5511 *conf->variable = newval;
5512 set_extra_field(&conf->gen, &conf->gen.extra,
5514 conf->gen.source = source;
5515 conf->gen.scontext = context;
5521 if (conf->gen.reset_source <= source)
5523 conf->reset_val = newval;
5524 set_extra_field(&conf->gen, &conf->reset_extra,
5526 conf->gen.reset_source = source;
5527 conf->gen.reset_scontext = context;
5529 for (stack = conf->gen.stack; stack; stack = stack->prev)
5531 if (stack->source <= source)
5533 stack->prior.val.realval = newval;
5534 set_extra_field(&conf->gen, &stack->prior.extra,
5536 stack->source = source;
5537 stack->scontext = context;
5542 /* Perhaps we didn't install newextra anywhere */
5543 if (newextra && !extra_field_used(&conf->gen, newextra))
5550 struct config_string *conf = (struct config_string *) record;
5552 void *newextra = NULL;
5557 * The value passed by the caller could be transient, so
5558 * we always strdup it.
5560 newval = guc_strdup(elevel, value);
5565 * The only built-in "parsing" check we have is to apply
5566 * truncation if GUC_IS_NAME.
5568 if (conf->gen.flags & GUC_IS_NAME)
5569 truncate_identifier(newval, strlen(newval), true);
5571 if (!call_string_check_hook(conf, &newval, &newextra,
5578 else if (source == PGC_S_DEFAULT)
5580 /* non-NULL boot_val must always get strdup'd */
5581 if (conf->boot_val != NULL)
5583 newval = guc_strdup(elevel, conf->boot_val);
5590 if (!call_string_check_hook(conf, &newval, &newextra,
5600 * strdup not needed, since reset_val is already under
5603 newval = conf->reset_val;
5604 newextra = conf->reset_extra;
5605 source = conf->gen.reset_source;
5606 context = conf->gen.reset_scontext;
5609 if (prohibitValueChange)
5611 /* newval shouldn't be NULL, so we're a bit sloppy here */
5612 if (*conf->variable == NULL || newval == NULL ||
5613 strcmp(*conf->variable, newval) != 0)
5616 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5617 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5626 /* Save old value to support transaction abort */
5628 push_old_value(&conf->gen, action);
5630 if (conf->assign_hook)
5631 (*conf->assign_hook) (newval, newextra);
5632 set_string_field(conf, conf->variable, newval);
5633 set_extra_field(&conf->gen, &conf->gen.extra,
5635 conf->gen.source = source;
5636 conf->gen.scontext = context;
5643 if (conf->gen.reset_source <= source)
5645 set_string_field(conf, &conf->reset_val, newval);
5646 set_extra_field(&conf->gen, &conf->reset_extra,
5648 conf->gen.reset_source = source;
5649 conf->gen.reset_scontext = context;
5651 for (stack = conf->gen.stack; stack; stack = stack->prev)
5653 if (stack->source <= source)
5655 set_string_field(conf, &stack->prior.val.stringval,
5657 set_extra_field(&conf->gen, &stack->prior.extra,
5659 stack->source = source;
5660 stack->scontext = context;
5665 /* Perhaps we didn't install newval anywhere */
5666 if (newval && !string_field_used(conf, newval))
5668 /* Perhaps we didn't install newextra anywhere */
5669 if (newextra && !extra_field_used(&conf->gen, newextra))
5676 struct config_enum *conf = (struct config_enum *) record;
5678 void *newextra = NULL;
5682 if (!config_enum_lookup_by_name(conf, value, &newval))
5686 hintmsg = config_enum_get_options(conf,
5687 "Available values: ",
5691 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5692 errmsg("invalid value for parameter \"%s\": \"%s\"",
5694 hintmsg ? errhint("%s", _(hintmsg)) : 0));
5700 if (!call_enum_check_hook(conf, &newval, &newextra,
5704 else if (source == PGC_S_DEFAULT)
5706 newval = conf->boot_val;
5707 if (!call_enum_check_hook(conf, &newval, &newextra,
5713 newval = conf->reset_val;
5714 newextra = conf->reset_extra;
5715 source = conf->gen.reset_source;
5716 context = conf->gen.reset_scontext;
5719 if (prohibitValueChange)
5721 if (*conf->variable != newval)
5724 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5725 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5734 /* Save old value to support transaction abort */
5736 push_old_value(&conf->gen, action);
5738 if (conf->assign_hook)
5739 (*conf->assign_hook) (newval, newextra);
5740 *conf->variable = newval;
5741 set_extra_field(&conf->gen, &conf->gen.extra,
5743 conf->gen.source = source;
5744 conf->gen.scontext = context;
5750 if (conf->gen.reset_source <= source)
5752 conf->reset_val = newval;
5753 set_extra_field(&conf->gen, &conf->reset_extra,
5755 conf->gen.reset_source = source;
5756 conf->gen.reset_scontext = context;
5758 for (stack = conf->gen.stack; stack; stack = stack->prev)
5760 if (stack->source <= source)
5762 stack->prior.val.enumval = newval;
5763 set_extra_field(&conf->gen, &stack->prior.extra,
5765 stack->source = source;
5766 stack->scontext = context;
5771 /* Perhaps we didn't install newextra anywhere */
5772 if (newextra && !extra_field_used(&conf->gen, newextra))
5778 if (changeVal && (record->flags & GUC_REPORT))
5779 ReportGUCOption(record);
5781 return changeVal ? 1 : -1;
5786 * Set the fields for source file and line number the setting came from.
5789 set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
5791 struct config_generic *record;
5795 * To avoid cluttering the log, only the postmaster bleats loudly about
5796 * problems with the config file.
5798 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
5800 record = find_option(name, true, elevel);
5801 /* should not happen */
5803 elog(ERROR, "unrecognized configuration parameter \"%s\"", name);
5805 sourcefile = guc_strdup(elevel, sourcefile);
5806 if (record->sourcefile)
5807 free(record->sourcefile);
5808 record->sourcefile = sourcefile;
5809 record->sourceline = sourceline;
5813 * Set a config option to the given value.
5815 * See also set_config_option; this is just the wrapper to be called from
5816 * outside GUC. (This function should be used when possible, because its API
5817 * is more stable than set_config_option's.)
5819 * Note: there is no support here for setting source file/line, as it
5820 * is currently not needed.
5823 SetConfigOption(const char *name, const char *value,
5824 GucContext context, GucSource source)
5826 (void) set_config_option(name, value, context, source,
5827 GUC_ACTION_SET, true, 0);
5833 * Fetch the current value of the option `name', as a string.
5835 * If the option doesn't exist, return NULL if missing_ok is true (NOTE that
5836 * this cannot be distinguished from a string variable with a NULL value!),
5837 * otherwise throw an ereport and don't return.
5839 * If restrict_superuser is true, we also enforce that only superusers can
5840 * see GUC_SUPERUSER_ONLY variables. This should only be passed as true
5841 * in user-driven calls.
5843 * The string is *not* allocated for modification and is really only
5844 * valid until the next call to configuration related functions.
5847 GetConfigOption(const char *name, bool missing_ok, bool restrict_superuser)
5849 struct config_generic *record;
5850 static char buffer[256];
5852 record = find_option(name, false, ERROR);
5858 (errcode(ERRCODE_UNDEFINED_OBJECT),
5859 errmsg("unrecognized configuration parameter \"%s\"",
5862 if (restrict_superuser &&
5863 (record->flags & GUC_SUPERUSER_ONLY) &&
5866 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5867 errmsg("must be superuser to examine \"%s\"", name)));
5869 switch (record->vartype)
5872 return *((struct config_bool *) record)->variable ? "on" : "off";
5875 snprintf(buffer, sizeof(buffer), "%d",
5876 *((struct config_int *) record)->variable);
5880 snprintf(buffer, sizeof(buffer), "%g",
5881 *((struct config_real *) record)->variable);
5885 return *((struct config_string *) record)->variable;
5888 return config_enum_lookup_by_value((struct config_enum *) record,
5889 *((struct config_enum *) record)->variable);
5895 * Get the RESET value associated with the given option.
5897 * Note: this is not re-entrant, due to use of static result buffer;
5898 * not to mention that a string variable could have its reset_val changed.
5899 * Beware of assuming the result value is good for very long.
5902 GetConfigOptionResetString(const char *name)
5904 struct config_generic *record;
5905 static char buffer[256];
5907 record = find_option(name, false, ERROR);
5910 (errcode(ERRCODE_UNDEFINED_OBJECT),
5911 errmsg("unrecognized configuration parameter \"%s\"", name)));
5912 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
5914 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5915 errmsg("must be superuser to examine \"%s\"", name)));
5917 switch (record->vartype)
5920 return ((struct config_bool *) record)->reset_val ? "on" : "off";
5923 snprintf(buffer, sizeof(buffer), "%d",
5924 ((struct config_int *) record)->reset_val);
5928 snprintf(buffer, sizeof(buffer), "%g",
5929 ((struct config_real *) record)->reset_val);
5933 return ((struct config_string *) record)->reset_val;
5936 return config_enum_lookup_by_value((struct config_enum *) record,
5937 ((struct config_enum *) record)->reset_val);
5944 * flatten_set_variable_args
5945 * Given a parsenode List as emitted by the grammar for SET,
5946 * convert to the flat string representation used by GUC.
5948 * We need to be told the name of the variable the args are for, because
5949 * the flattening rules vary (ugh).
5951 * The result is NULL if args is NIL (ie, SET ... TO DEFAULT), otherwise
5952 * a palloc'd string.
5955 flatten_set_variable_args(const char *name, List *args)
5957 struct config_generic *record;
5962 /* Fast path if just DEFAULT */
5967 * Get flags for the variable; if it's not known, use default flags.
5968 * (Caller might throw error later, but not our business to do so here.)
5970 record = find_option(name, false, WARNING);
5972 flags = record->flags;
5976 /* Complain if list input and non-list variable */
5977 if ((flags & GUC_LIST_INPUT) == 0 &&
5978 list_length(args) != 1)
5980 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5981 errmsg("SET %s takes only one argument", name)));
5983 initStringInfo(&buf);
5986 * Each list member may be a plain A_Const node, or an A_Const within a
5987 * TypeCast; the latter case is supported only for ConstInterval arguments
5988 * (for SET TIME ZONE).
5992 Node *arg = (Node *) lfirst(l);
5994 TypeName *typeName = NULL;
5997 if (l != list_head(args))
5998 appendStringInfo(&buf, ", ");
6000 if (IsA(arg, TypeCast))
6002 TypeCast *tc = (TypeCast *) arg;
6005 typeName = tc->typeName;
6008 if (!IsA(arg, A_Const))
6009 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
6010 con = (A_Const *) arg;
6012 switch (nodeTag(&con->val))
6015 appendStringInfo(&buf, "%ld", intVal(&con->val));
6018 /* represented as a string, so just copy it */
6019 appendStringInfoString(&buf, strVal(&con->val));
6022 val = strVal(&con->val);
6023 if (typeName != NULL)
6026 * Must be a ConstInterval argument for TIME ZONE. Coerce
6027 * to interval and back to normalize the value and account
6035 typenameTypeIdAndMod(NULL, typeName, &typoid, &typmod);
6036 Assert(typoid == INTERVALOID);
6039 DirectFunctionCall3(interval_in,
6040 CStringGetDatum(val),
6041 ObjectIdGetDatum(InvalidOid),
6042 Int32GetDatum(typmod));
6045 DatumGetCString(DirectFunctionCall1(interval_out,
6047 appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
6052 * Plain string literal or identifier. For quote mode,
6053 * quote it if it's not a vanilla identifier.
6055 if (flags & GUC_LIST_QUOTE)
6056 appendStringInfoString(&buf, quote_identifier(val));
6058 appendStringInfoString(&buf, val);
6062 elog(ERROR, "unrecognized node type: %d",
6063 (int) nodeTag(&con->val));
6076 ExecSetVariableStmt(VariableSetStmt *stmt)
6078 GucAction action = stmt->is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET;
6083 case VAR_SET_CURRENT:
6084 (void) set_config_option(stmt->name,
6085 ExtractSetVariableArgs(stmt),
6086 (superuser() ? PGC_SUSET : PGC_USERSET),
6095 * Special case for special SQL syntax that effectively sets more
6096 * than one variable per statement.
6098 if (strcmp(stmt->name, "TRANSACTION") == 0)
6102 foreach(head, stmt->args)
6104 DefElem *item = (DefElem *) lfirst(head);
6106 if (strcmp(item->defname, "transaction_isolation") == 0)
6107 SetPGVariable("transaction_isolation",
6108 list_make1(item->arg), stmt->is_local);
6109 else if (strcmp(item->defname, "transaction_read_only") == 0)
6110 SetPGVariable("transaction_read_only",
6111 list_make1(item->arg), stmt->is_local);
6112 else if (strcmp(item->defname, "transaction_deferrable") == 0)
6113 SetPGVariable("transaction_deferrable",
6114 list_make1(item->arg), stmt->is_local);
6116 elog(ERROR, "unexpected SET TRANSACTION element: %s",
6120 else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
6124 foreach(head, stmt->args)
6126 DefElem *item = (DefElem *) lfirst(head);
6128 if (strcmp(item->defname, "transaction_isolation") == 0)
6129 SetPGVariable("default_transaction_isolation",
6130 list_make1(item->arg), stmt->is_local);
6131 else if (strcmp(item->defname, "transaction_read_only") == 0)
6132 SetPGVariable("default_transaction_read_only",
6133 list_make1(item->arg), stmt->is_local);
6134 else if (strcmp(item->defname, "transaction_deferrable") == 0)
6135 SetPGVariable("default_transaction_deferrable",
6136 list_make1(item->arg), stmt->is_local);
6138 elog(ERROR, "unexpected SET SESSION element: %s",
6143 elog(ERROR, "unexpected SET MULTI element: %s",
6146 case VAR_SET_DEFAULT:
6148 (void) set_config_option(stmt->name,
6150 (superuser() ? PGC_SUSET : PGC_USERSET),
6163 * Get the value to assign for a VariableSetStmt, or NULL if it's RESET.
6164 * The result is palloc'd.
6166 * This is exported for use by actions such as ALTER ROLE SET.
6169 ExtractSetVariableArgs(VariableSetStmt *stmt)
6174 return flatten_set_variable_args(stmt->name, stmt->args);
6175 case VAR_SET_CURRENT:
6176 return GetConfigOptionByName(stmt->name, NULL);
6183 * SetPGVariable - SET command exported as an easily-C-callable function.
6185 * This provides access to SET TO value, as well as SET TO DEFAULT (expressed
6186 * by passing args == NIL), but not SET FROM CURRENT functionality.
6189 SetPGVariable(const char *name, List *args, bool is_local)
6191 char *argstring = flatten_set_variable_args(name, args);
6193 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
6194 (void) set_config_option(name,
6196 (superuser() ? PGC_SUSET : PGC_USERSET),
6198 is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET,
6204 * SET command wrapped as a SQL callable function.
6207 set_config_by_name(PG_FUNCTION_ARGS)
6214 if (PG_ARGISNULL(0))
6216 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
6217 errmsg("SET requires parameter name")));
6219 /* Get the GUC variable name */
6220 name = TextDatumGetCString(PG_GETARG_DATUM(0));
6222 /* Get the desired value or set to NULL for a reset request */
6223 if (PG_ARGISNULL(1))
6226 value = TextDatumGetCString(PG_GETARG_DATUM(1));
6229 * Get the desired state of is_local. Default to false if provided value
6232 if (PG_ARGISNULL(2))
6235 is_local = PG_GETARG_BOOL(2);
6237 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
6238 (void) set_config_option(name,
6240 (superuser() ? PGC_SUSET : PGC_USERSET),
6242 is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET,
6246 /* get the new current value */
6247 new_value = GetConfigOptionByName(name, NULL);
6249 /* Convert return string to text */
6250 PG_RETURN_TEXT_P(cstring_to_text(new_value));
6255 * Common code for DefineCustomXXXVariable subroutines: allocate the
6256 * new variable's config struct and fill in generic fields.
6258 static struct config_generic *
6259 init_custom_variable(const char *name,
6260 const char *short_desc,
6261 const char *long_desc,
6264 enum config_type type,
6267 struct config_generic *gen;
6270 * Only allow custom PGC_POSTMASTER variables to be created during shared
6271 * library preload; any later than that, we can't ensure that the value
6272 * doesn't change after startup. This is a fatal elog if it happens; just
6273 * erroring out isn't safe because we don't know what the calling loadable
6274 * module might already have hooked into.
6276 if (context == PGC_POSTMASTER &&
6277 !process_shared_preload_libraries_in_progress)
6278 elog(FATAL, "cannot create PGC_POSTMASTER variables after startup");
6280 gen = (struct config_generic *) guc_malloc(ERROR, sz);
6283 gen->name = guc_strdup(ERROR, name);
6284 gen->context = context;
6285 gen->group = CUSTOM_OPTIONS;
6286 gen->short_desc = short_desc;
6287 gen->long_desc = long_desc;
6289 gen->vartype = type;
6295 * Common code for DefineCustomXXXVariable subroutines: insert the new
6296 * variable into the GUC variable array, replacing any placeholder.
6299 define_custom_variable(struct config_generic * variable)
6301 const char *name = variable->name;
6302 const char **nameAddr = &name;
6303 struct config_string *pHolder;
6304 struct config_generic **res;
6307 * See if there's a placeholder by the same name.
6309 res = (struct config_generic **) bsearch((void *) &nameAddr,
6310 (void *) guc_variables,
6312 sizeof(struct config_generic *),
6317 * No placeholder to replace, so we can just add it ... but first,
6318 * make sure it's initialized to its default value.
6320 InitializeOneGUCOption(variable);
6321 add_guc_variable(variable, ERROR);
6326 * This better be a placeholder
6328 if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
6330 (errcode(ERRCODE_INTERNAL_ERROR),
6331 errmsg("attempt to redefine parameter \"%s\"", name)));
6333 Assert((*res)->vartype == PGC_STRING);
6334 pHolder = (struct config_string *) (*res);
6337 * First, set the variable to its default value. We must do this even
6338 * though we intend to immediately apply a new value, since it's possible
6339 * that the new value is invalid.
6341 InitializeOneGUCOption(variable);
6344 * Replace the placeholder. We aren't changing the name, so no re-sorting
6350 * Assign the string value(s) stored in the placeholder to the real
6351 * variable. Essentially, we need to duplicate all the active and stacked
6352 * values, but with appropriate validation and datatype adjustment.
6354 * If an assignment fails, we report a WARNING and keep going. We don't
6355 * want to throw ERROR for bad values, because it'd bollix the add-on
6356 * module that's presumably halfway through getting loaded. In such cases
6357 * the default or previous state will become active instead.
6360 /* First, apply the reset value if any */
6361 if (pHolder->reset_val)
6362 (void) set_config_option(name, pHolder->reset_val,
6363 pHolder->gen.reset_scontext,
6364 pHolder->gen.reset_source,
6365 GUC_ACTION_SET, true, WARNING);
6366 /* That should not have resulted in stacking anything */
6367 Assert(variable->stack == NULL);
6369 /* Now, apply current and stacked values, in the order they were stacked */
6370 reapply_stacked_values(variable, pHolder, pHolder->gen.stack,
6371 *(pHolder->variable),
6372 pHolder->gen.scontext, pHolder->gen.source);
6374 /* Also copy over any saved source-location information */
6375 if (pHolder->gen.sourcefile)
6376 set_config_sourcefile(name, pHolder->gen.sourcefile,
6377 pHolder->gen.sourceline);
6380 * Free up as much as we conveniently can of the placeholder structure.
6381 * (This neglects any stack items, so it's possible for some memory to be
6382 * leaked. Since this can only happen once per session per variable, it
6383 * doesn't seem worth spending much code on.)
6385 set_string_field(pHolder, pHolder->variable, NULL);
6386 set_string_field(pHolder, &pHolder->reset_val, NULL);
6392 * Recursive subroutine for define_custom_variable: reapply non-reset values
6394 * We recurse so that the values are applied in the same order as originally.
6395 * At each recursion level, apply the upper-level value (passed in) in the
6396 * fashion implied by the stack entry.
6399 reapply_stacked_values(struct config_generic * variable,
6400 struct config_string *pHolder,
6402 const char *curvalue,
6403 GucContext curscontext, GucSource cursource)
6405 const char *name = variable->name;
6406 GucStack *oldvarstack = variable->stack;
6410 /* First, recurse, so that stack items are processed bottom to top */
6411 reapply_stacked_values(variable, pHolder, stack->prev,
6412 stack->prior.val.stringval,
6413 stack->scontext, stack->source);
6415 /* See how to apply the passed-in value */
6416 switch (stack->state)
6419 (void) set_config_option(name, curvalue,
6420 curscontext, cursource,
6421 GUC_ACTION_SAVE, true, WARNING);
6425 (void) set_config_option(name, curvalue,
6426 curscontext, cursource,
6427 GUC_ACTION_SET, true, WARNING);
6431 (void) set_config_option(name, curvalue,
6432 curscontext, cursource,
6433 GUC_ACTION_LOCAL, true, WARNING);
6437 /* first, apply the masked value as SET */
6438 (void) set_config_option(name, stack->masked.val.stringval,
6439 stack->masked_scontext, PGC_S_SESSION,
6440 GUC_ACTION_SET, true, WARNING);
6441 /* then apply the current value as LOCAL */
6442 (void) set_config_option(name, curvalue,
6443 curscontext, cursource,
6444 GUC_ACTION_LOCAL, true, WARNING);
6448 /* If we successfully made a stack entry, adjust its nest level */
6449 if (variable->stack != oldvarstack)
6450 variable->stack->nest_level = stack->nest_level;
6455 * We are at the end of the stack. If the active/previous value is
6456 * different from the reset value, it must represent a previously
6457 * committed session value. Apply it, and then drop the stack entry
6458 * that set_config_option will have created under the impression that
6459 * this is to be just a transactional assignment. (We leak the stack
6462 if (curvalue != pHolder->reset_val ||
6463 curscontext != pHolder->gen.reset_scontext ||
6464 cursource != pHolder->gen.reset_source)
6466 (void) set_config_option(name, curvalue,
6467 curscontext, cursource,
6468 GUC_ACTION_SET, true, WARNING);
6469 variable->stack = NULL;
6475 DefineCustomBoolVariable(const char *name,
6476 const char *short_desc,
6477 const char *long_desc,
6482 GucBoolCheckHook check_hook,
6483 GucBoolAssignHook assign_hook,
6484 GucShowHook show_hook)
6486 struct config_bool *var;
6488 var = (struct config_bool *)
6489 init_custom_variable(name, short_desc, long_desc, context, flags,
6490 PGC_BOOL, sizeof(struct config_bool));
6491 var->variable = valueAddr;
6492 var->boot_val = bootValue;
6493 var->reset_val = bootValue;
6494 var->check_hook = check_hook;
6495 var->assign_hook = assign_hook;
6496 var->show_hook = show_hook;
6497 define_custom_variable(&var->gen);
6501 DefineCustomIntVariable(const char *name,
6502 const char *short_desc,
6503 const char *long_desc,
6510 GucIntCheckHook check_hook,
6511 GucIntAssignHook assign_hook,
6512 GucShowHook show_hook)
6514 struct config_int *var;
6516 var = (struct config_int *)
6517 init_custom_variable(name, short_desc, long_desc, context, flags,
6518 PGC_INT, sizeof(struct config_int));
6519 var->variable = valueAddr;
6520 var->boot_val = bootValue;
6521 var->reset_val = bootValue;
6522 var->min = minValue;
6523 var->max = maxValue;
6524 var->check_hook = check_hook;
6525 var->assign_hook = assign_hook;
6526 var->show_hook = show_hook;
6527 define_custom_variable(&var->gen);
6531 DefineCustomRealVariable(const char *name,
6532 const char *short_desc,
6533 const char *long_desc,
6540 GucRealCheckHook check_hook,
6541 GucRealAssignHook assign_hook,
6542 GucShowHook show_hook)
6544 struct config_real *var;
6546 var = (struct config_real *)
6547 init_custom_variable(name, short_desc, long_desc, context, flags,
6548 PGC_REAL, sizeof(struct config_real));
6549 var->variable = valueAddr;
6550 var->boot_val = bootValue;
6551 var->reset_val = bootValue;
6552 var->min = minValue;
6553 var->max = maxValue;
6554 var->check_hook = check_hook;
6555 var->assign_hook = assign_hook;
6556 var->show_hook = show_hook;
6557 define_custom_variable(&var->gen);
6561 DefineCustomStringVariable(const char *name,
6562 const char *short_desc,
6563 const char *long_desc,
6565 const char *bootValue,
6568 GucStringCheckHook check_hook,
6569 GucStringAssignHook assign_hook,
6570 GucShowHook show_hook)
6572 struct config_string *var;
6574 var = (struct config_string *)
6575 init_custom_variable(name, short_desc, long_desc, context, flags,
6576 PGC_STRING, sizeof(struct config_string));
6577 var->variable = valueAddr;
6578 var->boot_val = bootValue;
6579 var->check_hook = check_hook;
6580 var->assign_hook = assign_hook;
6581 var->show_hook = show_hook;
6582 define_custom_variable(&var->gen);
6586 DefineCustomEnumVariable(const char *name,
6587 const char *short_desc,
6588 const char *long_desc,
6591 const struct config_enum_entry * options,
6594 GucEnumCheckHook check_hook,
6595 GucEnumAssignHook assign_hook,
6596 GucShowHook show_hook)
6598 struct config_enum *var;
6600 var = (struct config_enum *)
6601 init_custom_variable(name, short_desc, long_desc, context, flags,
6602 PGC_ENUM, sizeof(struct config_enum));
6603 var->variable = valueAddr;
6604 var->boot_val = bootValue;
6605 var->reset_val = bootValue;
6606 var->options = options;
6607 var->check_hook = check_hook;
6608 var->assign_hook = assign_hook;
6609 var->show_hook = show_hook;
6610 define_custom_variable(&var->gen);
6614 EmitWarningsOnPlaceholders(const char *className)
6616 int classLen = strlen(className);
6619 for (i = 0; i < num_guc_variables; i++)
6621 struct config_generic *var = guc_variables[i];
6623 if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
6624 strncmp(className, var->name, classLen) == 0 &&
6625 var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
6628 (errcode(ERRCODE_UNDEFINED_OBJECT),
6629 errmsg("unrecognized configuration parameter \"%s\"",
6640 GetPGVariable(const char *name, DestReceiver *dest)
6642 if (guc_name_compare(name, "all") == 0)
6643 ShowAllGUCConfig(dest);
6645 ShowGUCConfigOption(name, dest);
6649 GetPGVariableResultDesc(const char *name)
6653 if (guc_name_compare(name, "all") == 0)
6655 /* need a tuple descriptor representing three TEXT columns */
6656 tupdesc = CreateTemplateTupleDesc(3, false);
6657 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
6659 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
6661 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
6666 const char *varname;
6668 /* Get the canonical spelling of name */
6669 (void) GetConfigOptionByName(name, &varname);
6671 /* need a tuple descriptor representing a single TEXT column */
6672 tupdesc = CreateTemplateTupleDesc(1, false);
6673 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
6684 ShowGUCConfigOption(const char *name, DestReceiver *dest)
6686 TupOutputState *tstate;
6688 const char *varname;
6691 /* Get the value and canonical spelling of name */
6692 value = GetConfigOptionByName(name, &varname);
6694 /* need a tuple descriptor representing a single TEXT column */
6695 tupdesc = CreateTemplateTupleDesc(1, false);
6696 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
6699 /* prepare for projection of tuples */
6700 tstate = begin_tup_output_tupdesc(dest, tupdesc);
6703 do_text_output_oneline(tstate, value);
6705 end_tup_output(tstate);
6712 ShowAllGUCConfig(DestReceiver *dest)
6714 bool am_superuser = superuser();
6716 TupOutputState *tstate;
6719 bool isnull[3] = {false, false, false};
6721 /* need a tuple descriptor representing three TEXT columns */
6722 tupdesc = CreateTemplateTupleDesc(3, false);
6723 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
6725 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
6727 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
6730 /* prepare for projection of tuples */
6731 tstate = begin_tup_output_tupdesc(dest, tupdesc);
6733 for (i = 0; i < num_guc_variables; i++)
6735 struct config_generic *conf = guc_variables[i];
6738 if ((conf->flags & GUC_NO_SHOW_ALL) ||
6739 ((conf->flags & GUC_SUPERUSER_ONLY) && !am_superuser))
6742 /* assign to the values array */
6743 values[0] = PointerGetDatum(cstring_to_text(conf->name));
6745 setting = _ShowOption(conf, true);
6748 values[1] = PointerGetDatum(cstring_to_text(setting));
6753 values[1] = PointerGetDatum(NULL);
6757 values[2] = PointerGetDatum(cstring_to_text(conf->short_desc));
6759 /* send it to dest */
6760 do_tup_output(tstate, values, isnull);
6763 pfree(DatumGetPointer(values[0]));
6767 pfree(DatumGetPointer(values[1]));
6769 pfree(DatumGetPointer(values[2]));
6772 end_tup_output(tstate);
6776 * Return GUC variable value by name; optionally return canonical
6777 * form of name. Return value is palloc'd.
6780 GetConfigOptionByName(const char *name, const char **varname)
6782 struct config_generic *record;
6784 record = find_option(name, false, ERROR);
6787 (errcode(ERRCODE_UNDEFINED_OBJECT),
6788 errmsg("unrecognized configuration parameter \"%s\"", name)));
6789 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
6791 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6792 errmsg("must be superuser to examine \"%s\"", name)));
6795 *varname = record->name;
6797 return _ShowOption(record, true);
6801 * Return GUC variable value by variable number; optionally return canonical
6802 * form of name. Return value is palloc'd.
6805 GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
6808 struct config_generic *conf;
6810 /* check requested variable number valid */
6811 Assert((varnum >= 0) && (varnum < num_guc_variables));
6813 conf = guc_variables[varnum];
6817 if ((conf->flags & GUC_NO_SHOW_ALL) ||
6818 ((conf->flags & GUC_SUPERUSER_ONLY) && !superuser()))
6824 /* first get the generic attributes */
6827 values[0] = conf->name;
6829 /* setting : use _ShowOption in order to avoid duplicating the logic */
6830 values[1] = _ShowOption(conf, false);
6833 if (conf->vartype == PGC_INT)
6837 switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
6842 case GUC_UNIT_BLOCKS:
6843 snprintf(buf, sizeof(buf), "%dkB", BLCKSZ / 1024);
6846 case GUC_UNIT_XBLOCKS:
6847 snprintf(buf, sizeof(buf), "%dkB", XLOG_BLCKSZ / 1024);
6868 values[3] = config_group_names[conf->group];
6871 values[4] = conf->short_desc;
6874 values[5] = conf->long_desc;
6877 values[6] = GucContext_Names[conf->context];
6880 values[7] = config_type_names[conf->vartype];
6883 values[8] = GucSource_Names[conf->source];
6885 /* now get the type specifc attributes */
6886 switch (conf->vartype)
6890 struct config_bool *lconf = (struct config_bool *) conf;
6902 values[12] = pstrdup(lconf->boot_val ? "on" : "off");
6905 values[13] = pstrdup(lconf->reset_val ? "on" : "off");
6911 struct config_int *lconf = (struct config_int *) conf;
6914 snprintf(buffer, sizeof(buffer), "%d", lconf->min);
6915 values[9] = pstrdup(buffer);
6918 snprintf(buffer, sizeof(buffer), "%d", lconf->max);
6919 values[10] = pstrdup(buffer);
6925 snprintf(buffer, sizeof(buffer), "%d", lconf->boot_val);
6926 values[12] = pstrdup(buffer);
6929 snprintf(buffer, sizeof(buffer), "%d", lconf->reset_val);
6930 values[13] = pstrdup(buffer);
6936 struct config_real *lconf = (struct config_real *) conf;
6939 snprintf(buffer, sizeof(buffer), "%g", lconf->min);
6940 values[9] = pstrdup(buffer);
6943 snprintf(buffer, sizeof(buffer), "%g", lconf->max);
6944 values[10] = pstrdup(buffer);
6950 snprintf(buffer, sizeof(buffer), "%g", lconf->boot_val);
6951 values[12] = pstrdup(buffer);
6954 snprintf(buffer, sizeof(buffer), "%g", lconf->reset_val);
6955 values[13] = pstrdup(buffer);
6961 struct config_string *lconf = (struct config_string *) conf;
6973 if (lconf->boot_val == NULL)
6976 values[12] = pstrdup(lconf->boot_val);
6979 if (lconf->reset_val == NULL)
6982 values[13] = pstrdup(lconf->reset_val);
6988 struct config_enum *lconf = (struct config_enum *) conf;
6999 * NOTE! enumvals with double quotes in them are not
7002 values[11] = config_enum_get_options((struct config_enum *) conf,
7003 "{\"", "\"}", "\",\"");
7006 values[12] = pstrdup(config_enum_lookup_by_value(lconf,
7010 values[13] = pstrdup(config_enum_lookup_by_value(lconf,
7018 * should never get here, but in case we do, set 'em to NULL
7040 * If the setting came from a config file, set the source location. For
7041 * security reasons, we don't show source file/line number for
7044 if (conf->source == PGC_S_FILE && superuser())
7046 values[14] = conf->sourcefile;
7047 snprintf(buffer, sizeof(buffer), "%d", conf->sourceline);
7048 values[15] = pstrdup(buffer);
7058 * Return the total number of GUC variables
7061 GetNumConfigOptions(void)
7063 return num_guc_variables;
7067 * show_config_by_name - equiv to SHOW X command but implemented as
7071 show_config_by_name(PG_FUNCTION_ARGS)
7076 /* Get the GUC variable name */
7077 varname = TextDatumGetCString(PG_GETARG_DATUM(0));
7080 varval = GetConfigOptionByName(varname, NULL);
7082 /* Convert to text */
7083 PG_RETURN_TEXT_P(cstring_to_text(varval));
7087 * show_all_settings - equiv to SHOW ALL command but implemented as
7090 #define NUM_PG_SETTINGS_ATTS 16
7093 show_all_settings(PG_FUNCTION_ARGS)
7095 FuncCallContext *funcctx;
7099 AttInMetadata *attinmeta;
7100 MemoryContext oldcontext;
7102 /* stuff done only on the first call of the function */
7103 if (SRF_IS_FIRSTCALL())
7105 /* create a function context for cross-call persistence */
7106 funcctx = SRF_FIRSTCALL_INIT();
7109 * switch to memory context appropriate for multiple function calls
7111 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
7114 * need a tuple descriptor representing NUM_PG_SETTINGS_ATTS columns
7115 * of the appropriate types
7117 tupdesc = CreateTemplateTupleDesc(NUM_PG_SETTINGS_ATTS, false);
7118 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
7120 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
7122 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "unit",
7124 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "category",
7126 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "short_desc",
7128 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "extra_desc",
7130 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "context",
7132 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "vartype",
7134 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "source",
7136 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "min_val",
7138 TupleDescInitEntry(tupdesc, (AttrNumber) 11, "max_val",
7140 TupleDescInitEntry(tupdesc, (AttrNumber) 12, "enumvals",
7141 TEXTARRAYOID, -1, 0);
7142 TupleDescInitEntry(tupdesc, (AttrNumber) 13, "boot_val",
7144 TupleDescInitEntry(tupdesc, (AttrNumber) 14, "reset_val",
7146 TupleDescInitEntry(tupdesc, (AttrNumber) 15, "sourcefile",
7148 TupleDescInitEntry(tupdesc, (AttrNumber) 16, "sourceline",
7152 * Generate attribute metadata needed later to produce tuples from raw
7155 attinmeta = TupleDescGetAttInMetadata(tupdesc);
7156 funcctx->attinmeta = attinmeta;
7158 /* total number of tuples to be returned */
7159 funcctx->max_calls = GetNumConfigOptions();
7161 MemoryContextSwitchTo(oldcontext);
7164 /* stuff done on every call of the function */
7165 funcctx = SRF_PERCALL_SETUP();
7167 call_cntr = funcctx->call_cntr;
7168 max_calls = funcctx->max_calls;
7169 attinmeta = funcctx->attinmeta;
7171 if (call_cntr < max_calls) /* do when there is more left to send */
7173 char *values[NUM_PG_SETTINGS_ATTS];
7179 * Get the next visible GUC variable name and value
7183 GetConfigOptionByNum(call_cntr, (const char **) values, &noshow);
7186 /* bump the counter and get the next config setting */
7187 call_cntr = ++funcctx->call_cntr;
7189 /* make sure we haven't gone too far now */
7190 if (call_cntr >= max_calls)
7191 SRF_RETURN_DONE(funcctx);
7196 tuple = BuildTupleFromCStrings(attinmeta, values);
7198 /* make the tuple into a datum */
7199 result = HeapTupleGetDatum(tuple);
7201 SRF_RETURN_NEXT(funcctx, result);
7205 /* do when there is no more left */
7206 SRF_RETURN_DONE(funcctx);
7211 _ShowOption(struct config_generic * record, bool use_units)
7216 switch (record->vartype)
7220 struct config_bool *conf = (struct config_bool *) record;
7222 if (conf->show_hook)
7223 val = (*conf->show_hook) ();
7225 val = *conf->variable ? "on" : "off";
7231 struct config_int *conf = (struct config_int *) record;
7233 if (conf->show_hook)
7234 val = (*conf->show_hook) ();
7238 * Use int64 arithmetic to avoid overflows in units
7241 int64 result = *conf->variable;
7244 if (use_units && result > 0 &&
7245 (record->flags & GUC_UNIT_MEMORY))
7247 switch (record->flags & GUC_UNIT_MEMORY)
7249 case GUC_UNIT_BLOCKS:
7250 result *= BLCKSZ / 1024;
7252 case GUC_UNIT_XBLOCKS:
7253 result *= XLOG_BLCKSZ / 1024;
7257 if (result % KB_PER_GB == 0)
7259 result /= KB_PER_GB;
7262 else if (result % KB_PER_MB == 0)
7264 result /= KB_PER_MB;
7272 else if (use_units && result > 0 &&
7273 (record->flags & GUC_UNIT_TIME))
7275 switch (record->flags & GUC_UNIT_TIME)
7281 result *= MS_PER_MIN;
7285 if (result % MS_PER_D == 0)
7290 else if (result % MS_PER_H == 0)
7295 else if (result % MS_PER_MIN == 0)
7297 result /= MS_PER_MIN;
7300 else if (result % MS_PER_S == 0)
7313 snprintf(buffer, sizeof(buffer), INT64_FORMAT "%s",
7322 struct config_real *conf = (struct config_real *) record;
7324 if (conf->show_hook)
7325 val = (*conf->show_hook) ();
7328 snprintf(buffer, sizeof(buffer), "%g",
7337 struct config_string *conf = (struct config_string *) record;
7339 if (conf->show_hook)
7340 val = (*conf->show_hook) ();
7341 else if (*conf->variable && **conf->variable)
7342 val = *conf->variable;
7350 struct config_enum *conf = (struct config_enum *) record;
7352 if (conf->show_hook)
7353 val = (*conf->show_hook) ();
7355 val = config_enum_lookup_by_value(conf, *conf->variable);
7360 /* just to keep compiler quiet */
7365 return pstrdup(val);
7372 * These routines dump out all non-default GUC options into a binary
7373 * file that is read by all exec'ed backends. The format is:
7375 * variable name, string, null terminated
7376 * variable value, string, null terminated
7377 * variable sourcefile, string, null terminated (empty if none)
7378 * variable sourceline, integer
7379 * variable source, integer
7380 * variable scontext, integer
7383 write_one_nondefault_variable(FILE *fp, struct config_generic * gconf)
7385 if (gconf->source == PGC_S_DEFAULT)
7388 fprintf(fp, "%s", gconf->name);
7391 switch (gconf->vartype)
7395 struct config_bool *conf = (struct config_bool *) gconf;
7397 if (*conf->variable)
7398 fprintf(fp, "true");
7400 fprintf(fp, "false");
7406 struct config_int *conf = (struct config_int *) gconf;
7408 fprintf(fp, "%d", *conf->variable);
7414 struct config_real *conf = (struct config_real *) gconf;
7416 fprintf(fp, "%.17g", *conf->variable);
7422 struct config_string *conf = (struct config_string *) gconf;
7424 fprintf(fp, "%s", *conf->variable);
7430 struct config_enum *conf = (struct config_enum *) gconf;
7433 config_enum_lookup_by_value(conf, *conf->variable));
7440 if (gconf->sourcefile)
7441 fprintf(fp, "%s", gconf->sourcefile);
7444 fwrite(&gconf->sourceline, 1, sizeof(gconf->sourceline), fp);
7445 fwrite(&gconf->source, 1, sizeof(gconf->source), fp);
7446 fwrite(&gconf->scontext, 1, sizeof(gconf->scontext), fp);
7450 write_nondefault_variables(GucContext context)
7456 Assert(context == PGC_POSTMASTER || context == PGC_SIGHUP);
7458 elevel = (context == PGC_SIGHUP) ? LOG : ERROR;
7463 fp = AllocateFile(CONFIG_EXEC_PARAMS_NEW, "w");
7467 (errcode_for_file_access(),
7468 errmsg("could not write to file \"%s\": %m",
7469 CONFIG_EXEC_PARAMS_NEW)));
7473 for (i = 0; i < num_guc_variables; i++)
7475 write_one_nondefault_variable(fp, guc_variables[i]);
7481 (errcode_for_file_access(),
7482 errmsg("could not write to file \"%s\": %m",
7483 CONFIG_EXEC_PARAMS_NEW)));
7488 * Put new file in place. This could delay on Win32, but we don't hold
7489 * any exclusive locks.
7491 rename(CONFIG_EXEC_PARAMS_NEW, CONFIG_EXEC_PARAMS);
7496 * Read string, including null byte from file
7498 * Return NULL on EOF and nothing read
7501 read_string_with_null(FILE *fp)
7510 if ((ch = fgetc(fp)) == EOF)
7515 elog(FATAL, "invalid format of exec config params file");
7518 str = guc_malloc(FATAL, maxlen);
7519 else if (i == maxlen)
7520 str = guc_realloc(FATAL, str, maxlen *= 2);
7529 * This routine loads a previous postmaster dump of its non-default
7533 read_nondefault_variables(void)
7540 GucSource varsource;
7541 GucContext varscontext;
7546 fp = AllocateFile(CONFIG_EXEC_PARAMS, "r");
7549 /* File not found is fine */
7550 if (errno != ENOENT)
7552 (errcode_for_file_access(),
7553 errmsg("could not read from file \"%s\": %m",
7554 CONFIG_EXEC_PARAMS)));
7560 struct config_generic *record;
7562 if ((varname = read_string_with_null(fp)) == NULL)
7565 if ((record = find_option(varname, true, FATAL)) == NULL)
7566 elog(FATAL, "failed to locate variable \"%s\" in exec config params file", varname);
7568 if ((varvalue = read_string_with_null(fp)) == NULL)
7569 elog(FATAL, "invalid format of exec config params file");
7570 if ((varsourcefile = read_string_with_null(fp)) == NULL)
7571 elog(FATAL, "invalid format of exec config params file");
7572 if (fread(&varsourceline, 1, sizeof(varsourceline), fp) != sizeof(varsourceline))
7573 elog(FATAL, "invalid format of exec config params file");
7574 if (fread(&varsource, 1, sizeof(varsource), fp) != sizeof(varsource))
7575 elog(FATAL, "invalid format of exec config params file");
7576 if (fread(&varscontext, 1, sizeof(varscontext), fp) != sizeof(varscontext))
7577 elog(FATAL, "invalid format of exec config params file");
7579 (void) set_config_option(varname, varvalue,
7580 varscontext, varsource,
7581 GUC_ACTION_SET, true, 0);
7582 if (varsourcefile[0])
7583 set_config_sourcefile(varname, varsourcefile, varsourceline);
7587 free(varsourcefile);
7592 #endif /* EXEC_BACKEND */
7596 * A little "long argument" simulation, although not quite GNU
7597 * compliant. Takes a string of the form "some-option=some value" and
7598 * returns name = "some_option" and value = "some value" in malloc'ed
7599 * storage. Note that '-' is converted to '_' in the option name. If
7600 * there is no '=' in the input string then value will be NULL.
7603 ParseLongOption(const char *string, char **name, char **value)
7612 equal_pos = strcspn(string, "=");
7614 if (string[equal_pos] == '=')
7616 *name = guc_malloc(FATAL, equal_pos + 1);
7617 strlcpy(*name, string, equal_pos + 1);
7619 *value = guc_strdup(FATAL, &string[equal_pos + 1]);
7623 /* no equal sign in string */
7624 *name = guc_strdup(FATAL, string);
7628 for (cp = *name; *cp; cp++)
7635 * Handle options fetched from pg_db_role_setting.setconfig,
7636 * pg_proc.proconfig, etc. Caller must specify proper context/source/action.
7638 * The array parameter must be an array of TEXT (it must not be NULL).
7641 ProcessGUCArray(ArrayType *array,
7642 GucContext context, GucSource source, GucAction action)
7646 Assert(array != NULL);
7647 Assert(ARR_ELEMTYPE(array) == TEXTOID);
7648 Assert(ARR_NDIM(array) == 1);
7649 Assert(ARR_LBOUND(array)[0] == 1);
7651 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
7659 d = array_ref(array, 1, &i,
7660 -1 /* varlenarray */ ,
7661 -1 /* TEXT's typlen */ ,
7662 false /* TEXT's typbyval */ ,
7663 'i' /* TEXT's typalign */ ,
7669 s = TextDatumGetCString(d);
7671 ParseLongOption(s, &name, &value);
7675 (errcode(ERRCODE_SYNTAX_ERROR),
7676 errmsg("could not parse setting for parameter \"%s\"",
7682 (void) set_config_option(name, value,
7695 * Add an entry to an option array. The array parameter may be NULL
7696 * to indicate the current table entry is NULL.
7699 GUCArrayAdd(ArrayType *array, const char *name, const char *value)
7701 struct config_generic *record;
7709 /* test if the option is valid and we're allowed to set it */
7710 (void) validate_option_array_item(name, value, false);
7712 /* normalize name (converts obsolete GUC names to modern spellings) */
7713 record = find_option(name, false, WARNING);
7715 name = record->name;
7717 /* build new item for array */
7718 newval = palloc(strlen(name) + 1 + strlen(value) + 1);
7719 sprintf(newval, "%s=%s", name, value);
7720 datum = CStringGetTextDatum(newval);
7728 Assert(ARR_ELEMTYPE(array) == TEXTOID);
7729 Assert(ARR_NDIM(array) == 1);
7730 Assert(ARR_LBOUND(array)[0] == 1);
7732 index = ARR_DIMS(array)[0] + 1; /* add after end */
7734 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
7739 d = array_ref(array, 1, &i,
7740 -1 /* varlenarray */ ,
7741 -1 /* TEXT's typlen */ ,
7742 false /* TEXT's typbyval */ ,
7743 'i' /* TEXT's typalign */ ,
7747 current = TextDatumGetCString(d);
7749 /* check for match up through and including '=' */
7750 if (strncmp(current, newval, strlen(name) + 1) == 0)
7757 a = array_set(array, 1, &index,
7760 -1 /* varlena array */ ,
7761 -1 /* TEXT's typlen */ ,
7762 false /* TEXT's typbyval */ ,
7763 'i' /* TEXT's typalign */ );
7766 a = construct_array(&datum, 1,
7775 * Delete an entry from an option array. The array parameter may be NULL
7776 * to indicate the current table entry is NULL. Also, if the return value
7777 * is NULL then a null should be stored.
7780 GUCArrayDelete(ArrayType *array, const char *name)
7782 struct config_generic *record;
7783 ArrayType *newarray;
7789 /* test if the option is valid and we're allowed to set it */
7790 (void) validate_option_array_item(name, NULL, false);
7792 /* normalize name (converts obsolete GUC names to modern spellings) */
7793 record = find_option(name, false, WARNING);
7795 name = record->name;
7797 /* if array is currently null, then surely nothing to delete */
7804 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
7810 d = array_ref(array, 1, &i,
7811 -1 /* varlenarray */ ,
7812 -1 /* TEXT's typlen */ ,
7813 false /* TEXT's typbyval */ ,
7814 'i' /* TEXT's typalign */ ,
7818 val = TextDatumGetCString(d);
7820 /* ignore entry if it's what we want to delete */
7821 if (strncmp(val, name, strlen(name)) == 0
7822 && val[strlen(name)] == '=')
7825 /* else add it to the output array */
7827 newarray = array_set(newarray, 1, &index,
7830 -1 /* varlenarray */ ,
7831 -1 /* TEXT's typlen */ ,
7832 false /* TEXT's typbyval */ ,
7833 'i' /* TEXT's typalign */ );
7835 newarray = construct_array(&d, 1,
7847 * Given a GUC array, delete all settings from it that our permission
7848 * level allows: if superuser, delete them all; if regular user, only
7849 * those that are PGC_USERSET
7852 GUCArrayReset(ArrayType *array)
7854 ArrayType *newarray;
7858 /* if array is currently null, nothing to do */
7862 /* if we're superuser, we can delete everything, so just do it */
7869 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
7876 d = array_ref(array, 1, &i,
7877 -1 /* varlenarray */ ,
7878 -1 /* TEXT's typlen */ ,
7879 false /* TEXT's typbyval */ ,
7880 'i' /* TEXT's typalign */ ,
7884 val = TextDatumGetCString(d);
7886 eqsgn = strchr(val, '=');
7889 /* skip if we have permission to delete it */
7890 if (validate_option_array_item(val, NULL, true))
7893 /* else add it to the output array */
7895 newarray = array_set(newarray, 1, &index,
7898 -1 /* varlenarray */ ,
7899 -1 /* TEXT's typlen */ ,
7900 false /* TEXT's typbyval */ ,
7901 'i' /* TEXT's typalign */ );
7903 newarray = construct_array(&d, 1,
7915 * Validate a proposed option setting for GUCArrayAdd/Delete/Reset.
7917 * name is the option name. value is the proposed value for the Add case,
7918 * or NULL for the Delete/Reset cases. If skipIfNoPermissions is true, it's
7919 * not an error to have no permissions to set the option.
7921 * Returns TRUE if OK, FALSE if skipIfNoPermissions is true and user does not
7922 * have permission to change this option (all other error cases result in an
7923 * error being thrown).
7926 validate_option_array_item(const char *name, const char *value,
7927 bool skipIfNoPermissions)
7930 struct config_generic *gconf;
7933 * There are three cases to consider:
7935 * name is a known GUC variable. Check the value normally, check
7936 * permissions normally (ie, allow if variable is USERSET, or if it's
7937 * SUSET and user is superuser).
7939 * name is not known, but exists or can be created as a placeholder (i.e.,
7940 * it has a prefixed name). We allow this case if you're a superuser,
7941 * otherwise not. Superusers are assumed to know what they're doing.
7942 * We can't allow it for other users, because when the placeholder is
7943 * resolved it might turn out to be a SUSET variable;
7944 * define_custom_variable assumes we checked that.
7946 * name is not known and can't be created as a placeholder. Throw error,
7947 * unless skipIfNoPermissions is true, in which case return FALSE.
7949 gconf = find_option(name, true, WARNING);
7952 /* not known, failed to make a placeholder */
7953 if (skipIfNoPermissions)
7956 (errcode(ERRCODE_UNDEFINED_OBJECT),
7957 errmsg("unrecognized configuration parameter \"%s\"",
7961 if (gconf->flags & GUC_CUSTOM_PLACEHOLDER)
7964 * We cannot do any meaningful check on the value, so only permissions
7965 * are useful to check.
7969 if (skipIfNoPermissions)
7972 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7973 errmsg("permission denied to set parameter \"%s\"", name)));
7976 /* manual permissions check so we can avoid an error being thrown */
7977 if (gconf->context == PGC_USERSET)
7979 else if (gconf->context == PGC_SUSET && superuser())
7981 else if (skipIfNoPermissions)
7983 /* if a permissions error should be thrown, let set_config_option do it */
7985 /* test for permissions and valid option value */
7986 (void) set_config_option(name, value,
7987 superuser() ? PGC_SUSET : PGC_USERSET,
7988 PGC_S_TEST, GUC_ACTION_SET, false, 0);
7995 * Called by check_hooks that want to override the normal
7996 * ERRCODE_INVALID_PARAMETER_VALUE SQLSTATE for check hook failures.
7998 * Note that GUC_check_errmsg() etc are just macros that result in a direct
7999 * assignment to the associated variables. That is ugly, but forced by the
8000 * limitations of C's macro mechanisms.
8003 GUC_check_errcode(int sqlerrcode)
8005 GUC_check_errcode_value = sqlerrcode;
8010 * Convenience functions to manage calling a variable's check_hook.
8011 * These mostly take care of the protocol for letting check hooks supply
8012 * portions of the error report on failure.
8016 call_bool_check_hook(struct config_bool * conf, bool *newval, void **extra,
8017 GucSource source, int elevel)
8019 /* Quick success if no hook */
8020 if (!conf->check_hook)
8023 /* Reset variables that might be set by hook */
8024 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8025 GUC_check_errmsg_string = NULL;
8026 GUC_check_errdetail_string = NULL;
8027 GUC_check_errhint_string = NULL;
8029 if (!(*conf->check_hook) (newval, extra, source))
8032 (errcode(GUC_check_errcode_value),
8033 GUC_check_errmsg_string ?
8034 errmsg_internal("%s", GUC_check_errmsg_string) :
8035 errmsg("invalid value for parameter \"%s\": %d",
8036 conf->gen.name, (int) *newval),
8037 GUC_check_errdetail_string ?
8038 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
8039 GUC_check_errhint_string ?
8040 errhint("%s", GUC_check_errhint_string) : 0));
8041 /* Flush any strings created in ErrorContext */
8050 call_int_check_hook(struct config_int * conf, int *newval, void **extra,
8051 GucSource source, int elevel)
8053 /* Quick success if no hook */
8054 if (!conf->check_hook)
8057 /* Reset variables that might be set by hook */
8058 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8059 GUC_check_errmsg_string = NULL;
8060 GUC_check_errdetail_string = NULL;
8061 GUC_check_errhint_string = NULL;
8063 if (!(*conf->check_hook) (newval, extra, source))
8066 (errcode(GUC_check_errcode_value),
8067 GUC_check_errmsg_string ?
8068 errmsg_internal("%s", GUC_check_errmsg_string) :
8069 errmsg("invalid value for parameter \"%s\": %d",
8070 conf->gen.name, *newval),
8071 GUC_check_errdetail_string ?
8072 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
8073 GUC_check_errhint_string ?
8074 errhint("%s", GUC_check_errhint_string) : 0));
8075 /* Flush any strings created in ErrorContext */
8084 call_real_check_hook(struct config_real * conf, double *newval, void **extra,
8085 GucSource source, int elevel)
8087 /* Quick success if no hook */
8088 if (!conf->check_hook)
8091 /* Reset variables that might be set by hook */
8092 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8093 GUC_check_errmsg_string = NULL;
8094 GUC_check_errdetail_string = NULL;
8095 GUC_check_errhint_string = NULL;
8097 if (!(*conf->check_hook) (newval, extra, source))
8100 (errcode(GUC_check_errcode_value),
8101 GUC_check_errmsg_string ?
8102 errmsg_internal("%s", GUC_check_errmsg_string) :
8103 errmsg("invalid value for parameter \"%s\": %g",
8104 conf->gen.name, *newval),
8105 GUC_check_errdetail_string ?
8106 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
8107 GUC_check_errhint_string ?
8108 errhint("%s", GUC_check_errhint_string) : 0));
8109 /* Flush any strings created in ErrorContext */
8118 call_string_check_hook(struct config_string * conf, char **newval, void **extra,
8119 GucSource source, int elevel)
8121 /* Quick success if no hook */
8122 if (!conf->check_hook)
8125 /* Reset variables that might be set by hook */
8126 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8127 GUC_check_errmsg_string = NULL;
8128 GUC_check_errdetail_string = NULL;
8129 GUC_check_errhint_string = NULL;
8131 if (!(*conf->check_hook) (newval, extra, source))
8134 (errcode(GUC_check_errcode_value),
8135 GUC_check_errmsg_string ?
8136 errmsg_internal("%s", GUC_check_errmsg_string) :
8137 errmsg("invalid value for parameter \"%s\": \"%s\"",
8138 conf->gen.name, *newval ? *newval : ""),
8139 GUC_check_errdetail_string ?
8140 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
8141 GUC_check_errhint_string ?
8142 errhint("%s", GUC_check_errhint_string) : 0));
8143 /* Flush any strings created in ErrorContext */
8152 call_enum_check_hook(struct config_enum * conf, int *newval, void **extra,
8153 GucSource source, int elevel)
8155 /* Quick success if no hook */
8156 if (!conf->check_hook)
8159 /* Reset variables that might be set by hook */
8160 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8161 GUC_check_errmsg_string = NULL;
8162 GUC_check_errdetail_string = NULL;
8163 GUC_check_errhint_string = NULL;
8165 if (!(*conf->check_hook) (newval, extra, source))
8168 (errcode(GUC_check_errcode_value),
8169 GUC_check_errmsg_string ?
8170 errmsg_internal("%s", GUC_check_errmsg_string) :
8171 errmsg("invalid value for parameter \"%s\": \"%s\"",
8173 config_enum_lookup_by_value(conf, *newval)),
8174 GUC_check_errdetail_string ?
8175 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
8176 GUC_check_errhint_string ?
8177 errhint("%s", GUC_check_errhint_string) : 0));
8178 /* Flush any strings created in ErrorContext */
8188 * check_hook, assign_hook and show_hook subroutines
8192 check_log_destination(char **newval, void **extra, GucSource source)
8200 /* Need a modifiable copy of string */
8201 rawstring = pstrdup(*newval);
8203 /* Parse string into list of identifiers */
8204 if (!SplitIdentifierString(rawstring, ',', &elemlist))
8206 /* syntax error in list */
8207 GUC_check_errdetail("List syntax is invalid.");
8209 list_free(elemlist);
8213 foreach(l, elemlist)
8215 char *tok = (char *) lfirst(l);
8217 if (pg_strcasecmp(tok, "stderr") == 0)
8218 newlogdest |= LOG_DESTINATION_STDERR;
8219 else if (pg_strcasecmp(tok, "csvlog") == 0)
8220 newlogdest |= LOG_DESTINATION_CSVLOG;
8222 else if (pg_strcasecmp(tok, "syslog") == 0)
8223 newlogdest |= LOG_DESTINATION_SYSLOG;
8226 else if (pg_strcasecmp(tok, "eventlog") == 0)
8227 newlogdest |= LOG_DESTINATION_EVENTLOG;
8231 GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
8233 list_free(elemlist);
8239 list_free(elemlist);
8241 myextra = (int *) guc_malloc(ERROR, sizeof(int));
8242 *myextra = newlogdest;
8243 *extra = (void *) myextra;
8249 assign_log_destination(const char *newval, void *extra)
8251 Log_destination = *((int *) extra);
8255 assign_syslog_facility(int newval, void *extra)
8258 set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
8261 /* Without syslog support, just ignore it */
8265 assign_syslog_ident(const char *newval, void *extra)
8268 set_syslog_parameters(newval, syslog_facility);
8270 /* Without syslog support, it will always be set to "none", so ignore */
8275 assign_session_replication_role(int newval, void *extra)
8278 * Must flush the plan cache when changing replication role; but don't
8279 * flush unnecessarily.
8281 if (SessionReplicationRole != newval)
8286 check_temp_buffers(int *newval, void **extra, GucSource source)
8289 * Once local buffers have been initialized, it's too late to change this.
8291 if (NLocBuffer && NLocBuffer != *newval)
8293 GUC_check_errdetail("\"temp_buffers\" cannot be changed after any temporary tables have been accessed in the session.");
8300 check_phony_autocommit(bool *newval, void **extra, GucSource source)
8304 GUC_check_errcode(ERRCODE_FEATURE_NOT_SUPPORTED);
8305 GUC_check_errmsg("SET AUTOCOMMIT TO OFF is no longer supported");
8312 check_debug_assertions(bool *newval, void **extra, GucSource source)
8314 #ifndef USE_ASSERT_CHECKING
8317 GUC_check_errmsg("assertion checking is not supported by this build");
8325 check_bonjour(bool *newval, void **extra, GucSource source)
8330 GUC_check_errmsg("Bonjour is not supported by this build");
8338 check_ssl(bool *newval, void **extra, GucSource source)
8343 GUC_check_errmsg("SSL is not supported by this build");
8351 check_stage_log_stats(bool *newval, void **extra, GucSource source)
8353 if (*newval && log_statement_stats)
8355 GUC_check_errdetail("Cannot enable parameter when \"log_statement_stats\" is true.");
8362 check_log_stats(bool *newval, void **extra, GucSource source)
8365 (log_parser_stats || log_planner_stats || log_executor_stats))
8367 GUC_check_errdetail("Cannot enable \"log_statement_stats\" when "
8368 "\"log_parser_stats\", \"log_planner_stats\", "
8369 "or \"log_executor_stats\" is true.");
8376 check_canonical_path(char **newval, void **extra, GucSource source)
8379 * Since canonicalize_path never enlarges the string, we can just modify
8380 * newval in-place. But watch out for NULL, which is the default value
8381 * for external_pid_file.
8384 canonicalize_path(*newval);
8389 check_timezone_abbreviations(char **newval, void **extra, GucSource source)
8392 * The boot_val given above for timezone_abbreviations is NULL. When we
8393 * see this we just do nothing. If this value isn't overridden from the
8394 * config file then pg_timezone_abbrev_initialize() will eventually
8395 * replace it with "Default". This hack has two purposes: to avoid
8396 * wasting cycles loading values that might soon be overridden from the
8397 * config file, and to avoid trying to read the timezone abbrev files
8398 * during InitializeGUCOptions(). The latter doesn't work in an
8399 * EXEC_BACKEND subprocess because my_exec_path hasn't been set yet and so
8400 * we can't locate PGSHAREDIR.
8402 if (*newval == NULL)
8404 Assert(source == PGC_S_DEFAULT);
8408 /* OK, load the file and produce a malloc'd TimeZoneAbbrevTable */
8409 *extra = load_tzoffsets(*newval);
8411 /* tzparser.c returns NULL on failure, reporting via GUC_check_errmsg */
8419 assign_timezone_abbreviations(const char *newval, void *extra)
8421 /* Do nothing for the boot_val default of NULL */
8425 InstallTimeZoneAbbrevs((TimeZoneAbbrevTable *) extra);
8429 * pg_timezone_abbrev_initialize --- set default value if not done already
8431 * This is called after initial loading of postgresql.conf. If no
8432 * timezone_abbreviations setting was found therein, select default.
8433 * If a non-default value is already installed, nothing will happen.
8435 * This can also be called from ProcessConfigFile to establish the default
8436 * value after a postgresql.conf entry for it is removed.
8439 pg_timezone_abbrev_initialize(void)
8441 SetConfigOption("timezone_abbreviations", "Default",
8442 PGC_POSTMASTER, PGC_S_DYNAMIC_DEFAULT);
8446 show_archive_command(void)
8448 if (XLogArchivingActive())
8449 return XLogArchiveCommand;
8451 return "(disabled)";
8455 assign_tcp_keepalives_idle(int newval, void *extra)
8458 * The kernel API provides no way to test a value without setting it; and
8459 * once we set it we might fail to unset it. So there seems little point
8460 * in fully implementing the check-then-assign GUC API for these
8461 * variables. Instead we just do the assignment on demand. pqcomm.c
8462 * reports any problems via elog(LOG).
8464 * This approach means that the GUC value might have little to do with the
8465 * actual kernel value, so we use a show_hook that retrieves the kernel
8466 * value rather than trusting GUC's copy.
8468 (void) pq_setkeepalivesidle(newval, MyProcPort);
8472 show_tcp_keepalives_idle(void)
8474 /* See comments in assign_tcp_keepalives_idle */
8475 static char nbuf[16];
8477 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesidle(MyProcPort));
8482 assign_tcp_keepalives_interval(int newval, void *extra)
8484 /* See comments in assign_tcp_keepalives_idle */
8485 (void) pq_setkeepalivesinterval(newval, MyProcPort);
8489 show_tcp_keepalives_interval(void)
8491 /* See comments in assign_tcp_keepalives_idle */
8492 static char nbuf[16];
8494 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesinterval(MyProcPort));
8499 assign_tcp_keepalives_count(int newval, void *extra)
8501 /* See comments in assign_tcp_keepalives_idle */
8502 (void) pq_setkeepalivescount(newval, MyProcPort);
8506 show_tcp_keepalives_count(void)
8508 /* See comments in assign_tcp_keepalives_idle */
8509 static char nbuf[16];
8511 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivescount(MyProcPort));
8516 check_maxconnections(int *newval, void **extra, GucSource source)
8518 if (*newval + autovacuum_max_workers + 1 > MAX_BACKENDS)
8524 assign_maxconnections(int newval, void *extra)
8526 MaxBackends = newval + autovacuum_max_workers + 1;
8530 check_autovacuum_max_workers(int *newval, void **extra, GucSource source)
8532 if (MaxConnections + *newval + 1 > MAX_BACKENDS)
8538 assign_autovacuum_max_workers(int newval, void *extra)
8540 MaxBackends = MaxConnections + newval + 1;
8544 check_effective_io_concurrency(int *newval, void **extra, GucSource source)
8547 double new_prefetch_pages = 0.0;
8551 * The user-visible GUC parameter is the number of drives (spindles),
8552 * which we need to translate to a number-of-pages-to-prefetch target.
8553 * The target value is stashed in *extra and then assigned to the actual
8554 * variable by assign_effective_io_concurrency.
8556 * The expected number of prefetch pages needed to keep N drives busy is:
8558 * drives | I/O requests
8559 * -------+----------------
8562 * 3 | 3/1 + 3/2 + 3/3 = 5 1/2
8563 * 4 | 4/1 + 4/2 + 4/3 + 4/4 = 8 1/3
8566 * This is called the "coupon collector problem" and H(n) is called the
8567 * harmonic series. This could be approximated by n * ln(n), but for
8568 * reasonable numbers of drives we might as well just compute the series.
8570 * Alternatively we could set the target to the number of pages necessary
8571 * so that the expected number of active spindles is some arbitrary
8572 * percentage of the total. This sounds the same but is actually slightly
8573 * different. The result ends up being ln(1-P)/ln((n-1)/n) where P is
8574 * that desired fraction.
8576 * Experimental results show that both of these formulas aren't aggressive
8577 * enough, but we don't really have any better proposals.
8579 * Note that if *newval = 0 (disabled), we must set target = 0.
8583 for (i = 1; i <= *newval; i++)
8584 new_prefetch_pages += (double) *newval / (double) i;
8586 /* This range check shouldn't fail, but let's be paranoid */
8587 if (new_prefetch_pages >= 0.0 && new_prefetch_pages < (double) INT_MAX)
8589 int *myextra = (int *) guc_malloc(ERROR, sizeof(int));
8591 *myextra = (int) rint(new_prefetch_pages);
8592 *extra = (void *) myextra;
8600 #endif /* USE_PREFETCH */
8604 assign_effective_io_concurrency(int newval, void *extra)
8607 target_prefetch_pages = *((int *) extra);
8608 #endif /* USE_PREFETCH */
8612 assign_pgstat_temp_directory(const char *newval, void *extra)
8614 /* check_canonical_path already canonicalized newval for us */
8618 tname = guc_malloc(ERROR, strlen(newval) + 12); /* /pgstat.tmp */
8619 sprintf(tname, "%s/pgstat.tmp", newval);
8620 fname = guc_malloc(ERROR, strlen(newval) + 13); /* /pgstat.stat */
8621 sprintf(fname, "%s/pgstat.stat", newval);
8623 if (pgstat_stat_tmpname)
8624 free(pgstat_stat_tmpname);
8625 pgstat_stat_tmpname = tname;
8626 if (pgstat_stat_filename)
8627 free(pgstat_stat_filename);
8628 pgstat_stat_filename = fname;
8632 check_application_name(char **newval, void **extra, GucSource source)
8634 /* Only allow clean ASCII chars in the application name */
8637 for (p = *newval; *p; p++)
8639 if (*p < 32 || *p > 126)
8647 assign_application_name(const char *newval, void *extra)
8649 /* Update the pg_stat_activity view */
8650 pgstat_report_appname(newval);
8654 show_unix_socket_permissions(void)
8658 snprintf(buf, sizeof(buf), "%04o", Unix_socket_permissions);
8663 show_log_file_mode(void)
8667 snprintf(buf, sizeof(buf), "%04o", Log_file_mode);
8671 #include "guc-file.c"