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_custom_variable_classes(char **newval, void **extra, GucSource source);
182 static bool check_debug_assertions(bool *newval, void **extra, GucSource source);
183 static bool check_bonjour(bool *newval, void **extra, GucSource source);
184 static bool check_ssl(bool *newval, void **extra, GucSource source);
185 static bool check_stage_log_stats(bool *newval, void **extra, GucSource source);
186 static bool check_log_stats(bool *newval, void **extra, GucSource source);
187 static bool check_canonical_path(char **newval, void **extra, GucSource source);
188 static bool check_timezone_abbreviations(char **newval, void **extra, GucSource source);
189 static void assign_timezone_abbreviations(const char *newval, void *extra);
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 num_temp_buffers = 1024;
430 char *data_directory;
431 char *ConfigFileName;
434 char *external_pid_file;
436 char *pgstat_temp_directory;
438 char *application_name;
440 int tcp_keepalives_idle;
441 int tcp_keepalives_interval;
442 int tcp_keepalives_count;
445 * These variables are all dummies that don't do anything, except in some
446 * cases provide the value for SHOW to display. The real state is elsewhere
447 * and is kept in sync by assign_hooks.
449 static char *log_destination_string;
451 static char *syslog_ident_str;
452 static bool phony_autocommit;
453 static bool session_auth_is_superuser;
454 static double phony_random_seed;
455 static char *client_encoding_string;
456 static char *datestyle_string;
457 static char *locale_collate;
458 static char *locale_ctype;
459 static char *server_encoding_string;
460 static char *server_version_string;
461 static int server_version_num;
462 static char *timezone_string;
463 static char *log_timezone_string;
464 static char *timezone_abbreviations_string;
465 static char *XactIsoLevel_string;
466 static char *session_authorization_string;
467 static char *custom_variable_classes;
468 static int max_function_args;
469 static int max_index_keys;
470 static int max_identifier_length;
471 static int block_size;
472 static int segment_size;
473 static int wal_block_size;
474 static int wal_segment_size;
475 static bool integer_datetimes;
476 static int effective_io_concurrency;
478 /* should be static, but commands/variable.c needs to get at this */
483 * Displayable names for context types (enum GucContext)
485 * Note: these strings are deliberately not localized.
487 const char *const GucContext_Names[] =
489 /* PGC_INTERNAL */ "internal",
490 /* PGC_POSTMASTER */ "postmaster",
491 /* PGC_SIGHUP */ "sighup",
492 /* PGC_BACKEND */ "backend",
493 /* PGC_SUSET */ "superuser",
494 /* PGC_USERSET */ "user"
498 * Displayable names for source types (enum GucSource)
500 * Note: these strings are deliberately not localized.
502 const char *const GucSource_Names[] =
504 /* PGC_S_DEFAULT */ "default",
505 /* PGC_S_ENV_VAR */ "environment variable",
506 /* PGC_S_FILE */ "configuration file",
507 /* PGC_S_ARGV */ "command line",
508 /* PGC_S_DATABASE */ "database",
509 /* PGC_S_USER */ "user",
510 /* PGC_S_DATABASE_USER */ "database user",
511 /* PGC_S_CLIENT */ "client",
512 /* PGC_S_OVERRIDE */ "override",
513 /* PGC_S_INTERACTIVE */ "interactive",
514 /* PGC_S_TEST */ "test",
515 /* PGC_S_SESSION */ "session"
519 * Displayable names for the groupings defined in enum config_group
521 const char *const config_group_names[] =
524 gettext_noop("Ungrouped"),
526 gettext_noop("File Locations"),
528 gettext_noop("Connections and Authentication"),
529 /* CONN_AUTH_SETTINGS */
530 gettext_noop("Connections and Authentication / Connection Settings"),
531 /* CONN_AUTH_SECURITY */
532 gettext_noop("Connections and Authentication / Security and Authentication"),
534 gettext_noop("Resource Usage"),
536 gettext_noop("Resource Usage / Memory"),
537 /* RESOURCES_KERNEL */
538 gettext_noop("Resource Usage / Kernel Resources"),
539 /* RESOURCES_VACUUM_DELAY */
540 gettext_noop("Resource Usage / Cost-Based Vacuum Delay"),
541 /* RESOURCES_BGWRITER */
542 gettext_noop("Resource Usage / Background Writer"),
543 /* RESOURCES_ASYNCHRONOUS */
544 gettext_noop("Resource Usage / Asynchronous Behavior"),
546 gettext_noop("Write-Ahead Log"),
548 gettext_noop("Write-Ahead Log / Settings"),
549 /* WAL_CHECKPOINTS */
550 gettext_noop("Write-Ahead Log / Checkpoints"),
552 gettext_noop("Write-Ahead Log / Archiving"),
553 /* WAL_REPLICATION */
554 gettext_noop("Write-Ahead Log / Streaming Replication"),
555 /* WAL_STANDBY_SERVERS */
556 gettext_noop("Write-Ahead Log / Standby Servers"),
558 gettext_noop("Query Tuning"),
559 /* QUERY_TUNING_METHOD */
560 gettext_noop("Query Tuning / Planner Method Configuration"),
561 /* QUERY_TUNING_COST */
562 gettext_noop("Query Tuning / Planner Cost Constants"),
563 /* QUERY_TUNING_GEQO */
564 gettext_noop("Query Tuning / Genetic Query Optimizer"),
565 /* QUERY_TUNING_OTHER */
566 gettext_noop("Query Tuning / Other Planner Options"),
568 gettext_noop("Reporting and Logging"),
570 gettext_noop("Reporting and Logging / Where to Log"),
572 gettext_noop("Reporting and Logging / When to Log"),
574 gettext_noop("Reporting and Logging / What to Log"),
576 gettext_noop("Statistics"),
577 /* STATS_MONITORING */
578 gettext_noop("Statistics / Monitoring"),
579 /* STATS_COLLECTOR */
580 gettext_noop("Statistics / Query and Index Statistics Collector"),
582 gettext_noop("Autovacuum"),
584 gettext_noop("Client Connection Defaults"),
585 /* CLIENT_CONN_STATEMENT */
586 gettext_noop("Client Connection Defaults / Statement Behavior"),
587 /* CLIENT_CONN_LOCALE */
588 gettext_noop("Client Connection Defaults / Locale and Formatting"),
589 /* CLIENT_CONN_OTHER */
590 gettext_noop("Client Connection Defaults / Other Defaults"),
591 /* LOCK_MANAGEMENT */
592 gettext_noop("Lock Management"),
594 gettext_noop("Version and Platform Compatibility"),
595 /* COMPAT_OPTIONS_PREVIOUS */
596 gettext_noop("Version and Platform Compatibility / Previous PostgreSQL Versions"),
597 /* COMPAT_OPTIONS_CLIENT */
598 gettext_noop("Version and Platform Compatibility / Other Platforms and Clients"),
600 gettext_noop("Error Handling"),
602 gettext_noop("Preset Options"),
604 gettext_noop("Customized Options"),
605 /* DEVELOPER_OPTIONS */
606 gettext_noop("Developer Options"),
607 /* help_config wants this array to be null-terminated */
612 * Displayable names for GUC variable types (enum config_type)
614 * Note: these strings are deliberately not localized.
616 const char *const config_type_names[] =
618 /* PGC_BOOL */ "bool",
619 /* PGC_INT */ "integer",
620 /* PGC_REAL */ "real",
621 /* PGC_STRING */ "string",
622 /* PGC_ENUM */ "enum"
627 * Contents of GUC tables
629 * See src/backend/utils/misc/README for design notes.
633 * 1. Declare a global variable of type bool, int, double, or char*
634 * and make use of it.
636 * 2. Decide at what times it's safe to set the option. See guc.h for
639 * 3. Decide on a name, a default value, upper and lower bounds (if
642 * 4. Add a record below.
644 * 5. Add it to src/backend/utils/misc/postgresql.conf.sample, if
647 * 6. Don't forget to document the option (at least in config.sgml).
649 * 7. If it's a new GUC_LIST option you must edit pg_dumpall.c to ensure
650 * it is not single quoted at dump time.
654 /******** option records follow ********/
656 static struct config_bool ConfigureNamesBool[] =
659 {"enable_seqscan", PGC_USERSET, QUERY_TUNING_METHOD,
660 gettext_noop("Enables the planner's use of sequential-scan plans."),
668 {"enable_indexscan", PGC_USERSET, QUERY_TUNING_METHOD,
669 gettext_noop("Enables the planner's use of index-scan plans."),
677 {"enable_bitmapscan", PGC_USERSET, QUERY_TUNING_METHOD,
678 gettext_noop("Enables the planner's use of bitmap-scan plans."),
686 {"enable_tidscan", PGC_USERSET, QUERY_TUNING_METHOD,
687 gettext_noop("Enables the planner's use of TID scan plans."),
695 {"enable_sort", PGC_USERSET, QUERY_TUNING_METHOD,
696 gettext_noop("Enables the planner's use of explicit sort steps."),
704 {"enable_hashagg", PGC_USERSET, QUERY_TUNING_METHOD,
705 gettext_noop("Enables the planner's use of hashed aggregation plans."),
713 {"enable_material", PGC_USERSET, QUERY_TUNING_METHOD,
714 gettext_noop("Enables the planner's use of materialization."),
722 {"enable_nestloop", PGC_USERSET, QUERY_TUNING_METHOD,
723 gettext_noop("Enables the planner's use of nested-loop join plans."),
731 {"enable_mergejoin", PGC_USERSET, QUERY_TUNING_METHOD,
732 gettext_noop("Enables the planner's use of merge join plans."),
740 {"enable_hashjoin", PGC_USERSET, QUERY_TUNING_METHOD,
741 gettext_noop("Enables the planner's use of hash join plans."),
749 {"geqo", PGC_USERSET, QUERY_TUNING_GEQO,
750 gettext_noop("Enables genetic query optimization."),
751 gettext_noop("This algorithm attempts to do planning without "
752 "exhaustive searching.")
759 /* Not for general use --- used by SET SESSION AUTHORIZATION */
760 {"is_superuser", PGC_INTERNAL, UNGROUPED,
761 gettext_noop("Shows whether the current user is a superuser."),
763 GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
765 &session_auth_is_superuser,
770 {"bonjour", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
771 gettext_noop("Enables advertising the server via Bonjour."),
776 check_bonjour, NULL, NULL
779 {"ssl", PGC_POSTMASTER, CONN_AUTH_SECURITY,
780 gettext_noop("Enables SSL connections."),
785 check_ssl, NULL, NULL
788 {"fsync", PGC_SIGHUP, WAL_SETTINGS,
789 gettext_noop("Forces synchronization of updates to disk."),
790 gettext_noop("The server will use the fsync() system call in several places to make "
791 "sure that updates are physically written to disk. This insures "
792 "that a database cluster will recover to a consistent state after "
793 "an operating system or hardware crash.")
800 {"zero_damaged_pages", PGC_SUSET, DEVELOPER_OPTIONS,
801 gettext_noop("Continues processing past damaged page headers."),
802 gettext_noop("Detection of a damaged page header normally causes PostgreSQL to "
803 "report an error, aborting the current transaction. Setting "
804 "zero_damaged_pages to true causes the system to instead report a "
805 "warning, zero out the damaged page, and continue processing. This "
806 "behavior will destroy data, namely all the rows on the damaged page."),
814 {"full_page_writes", PGC_SIGHUP, WAL_SETTINGS,
815 gettext_noop("Writes full pages to WAL when first modified after a checkpoint."),
816 gettext_noop("A page write in process during an operating system crash might be "
817 "only partially written to disk. During recovery, the row changes "
818 "stored in WAL are not enough to recover. This option writes "
819 "pages when first modified after a checkpoint to WAL so full recovery "
827 {"silent_mode", PGC_POSTMASTER, LOGGING_WHERE,
828 gettext_noop("Runs the server silently."),
829 gettext_noop("If this parameter is set, the server will automatically run in the "
830 "background and any controlling terminals are dissociated.")
837 {"log_checkpoints", PGC_SIGHUP, LOGGING_WHAT,
838 gettext_noop("Logs each checkpoint."),
846 {"log_connections", PGC_BACKEND, LOGGING_WHAT,
847 gettext_noop("Logs each successful connection."),
855 {"log_disconnections", PGC_BACKEND, LOGGING_WHAT,
856 gettext_noop("Logs end of a session, including duration."),
864 {"debug_assertions", PGC_USERSET, DEVELOPER_OPTIONS,
865 gettext_noop("Turns on various assertion checks."),
866 gettext_noop("This is a debugging aid."),
870 #ifdef USE_ASSERT_CHECKING
875 check_debug_assertions, NULL, NULL
879 {"exit_on_error", PGC_USERSET, ERROR_HANDLING_OPTIONS,
880 gettext_noop("Terminate session on any error."),
888 {"restart_after_crash", PGC_SIGHUP, ERROR_HANDLING_OPTIONS,
889 gettext_noop("Reinitialize after backend crash."),
892 &restart_after_crash,
898 {"log_duration", PGC_SUSET, LOGGING_WHAT,
899 gettext_noop("Logs the duration of each completed SQL statement."),
907 {"debug_print_parse", PGC_USERSET, LOGGING_WHAT,
908 gettext_noop("Logs each query's parse tree."),
916 {"debug_print_rewritten", PGC_USERSET, LOGGING_WHAT,
917 gettext_noop("Logs each query's rewritten parse tree."),
920 &Debug_print_rewritten,
925 {"debug_print_plan", PGC_USERSET, LOGGING_WHAT,
926 gettext_noop("Logs each query's execution plan."),
934 {"debug_pretty_print", PGC_USERSET, LOGGING_WHAT,
935 gettext_noop("Indents parse and plan tree displays."),
943 {"log_parser_stats", PGC_SUSET, STATS_MONITORING,
944 gettext_noop("Writes parser performance statistics to the server log."),
949 check_stage_log_stats, NULL, NULL
952 {"log_planner_stats", PGC_SUSET, STATS_MONITORING,
953 gettext_noop("Writes planner performance statistics to the server log."),
958 check_stage_log_stats, NULL, NULL
961 {"log_executor_stats", PGC_SUSET, STATS_MONITORING,
962 gettext_noop("Writes executor performance statistics to the server log."),
967 check_stage_log_stats, NULL, NULL
970 {"log_statement_stats", PGC_SUSET, STATS_MONITORING,
971 gettext_noop("Writes cumulative performance statistics to the server log."),
974 &log_statement_stats,
976 check_log_stats, NULL, NULL
978 #ifdef BTREE_BUILD_STATS
980 {"log_btree_build_stats", PGC_SUSET, DEVELOPER_OPTIONS,
981 gettext_noop("No description available."),
985 &log_btree_build_stats,
992 {"track_activities", PGC_SUSET, STATS_COLLECTOR,
993 gettext_noop("Collects information about executing commands."),
994 gettext_noop("Enables the collection of information on the currently "
995 "executing command of each session, along with "
996 "the time at which that command began execution.")
998 &pgstat_track_activities,
1003 {"track_counts", PGC_SUSET, STATS_COLLECTOR,
1004 gettext_noop("Collects statistics on database activity."),
1007 &pgstat_track_counts,
1013 {"update_process_title", PGC_SUSET, STATS_COLLECTOR,
1014 gettext_noop("Updates the process title to show the active SQL command."),
1015 gettext_noop("Enables updating of the process title every time a new SQL command is received by the server.")
1017 &update_process_title,
1023 {"autovacuum", PGC_SIGHUP, AUTOVACUUM,
1024 gettext_noop("Starts the autovacuum subprocess."),
1027 &autovacuum_start_daemon,
1033 {"trace_notify", PGC_USERSET, DEVELOPER_OPTIONS,
1034 gettext_noop("Generates debugging output for LISTEN and NOTIFY."),
1045 {"trace_locks", PGC_SUSET, DEVELOPER_OPTIONS,
1046 gettext_noop("No description available."),
1055 {"trace_userlocks", PGC_SUSET, DEVELOPER_OPTIONS,
1056 gettext_noop("No description available."),
1065 {"trace_lwlocks", PGC_SUSET, DEVELOPER_OPTIONS,
1066 gettext_noop("No description available."),
1075 {"debug_deadlocks", PGC_SUSET, DEVELOPER_OPTIONS,
1076 gettext_noop("No description available."),
1087 {"log_lock_waits", PGC_SUSET, LOGGING_WHAT,
1088 gettext_noop("Logs long lock waits."),
1097 {"log_hostname", PGC_SIGHUP, LOGGING_WHAT,
1098 gettext_noop("Logs the host name in the connection logs."),
1099 gettext_noop("By default, connection logs only show the IP address "
1100 "of the connecting host. If you want them to show the host name you "
1101 "can turn this on, but depending on your host name resolution "
1102 "setup it might impose a non-negligible performance penalty.")
1109 {"sql_inheritance", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1110 gettext_noop("Causes subtables to be included by default in various commands."),
1118 {"password_encryption", PGC_USERSET, CONN_AUTH_SECURITY,
1119 gettext_noop("Encrypt passwords."),
1120 gettext_noop("When a password is specified in CREATE USER or "
1121 "ALTER USER without writing either ENCRYPTED or UNENCRYPTED, "
1122 "this parameter determines whether the password is to be encrypted.")
1124 &Password_encryption,
1129 {"transform_null_equals", PGC_USERSET, COMPAT_OPTIONS_CLIENT,
1130 gettext_noop("Treats \"expr=NULL\" as \"expr IS NULL\"."),
1131 gettext_noop("When turned on, expressions of the form expr = NULL "
1132 "(or NULL = expr) are treated as expr IS NULL, that is, they "
1133 "return true if expr evaluates to the null value, and false "
1134 "otherwise. The correct behavior of expr = NULL is to always "
1135 "return null (unknown).")
1137 &Transform_null_equals,
1142 {"db_user_namespace", PGC_SIGHUP, CONN_AUTH_SECURITY,
1143 gettext_noop("Enables per-database user names."),
1151 /* only here for backwards compatibility */
1152 {"autocommit", PGC_USERSET, CLIENT_CONN_STATEMENT,
1153 gettext_noop("This parameter doesn't do anything."),
1154 gettext_noop("It's just here so that we won't choke on SET AUTOCOMMIT TO ON from 7.3-vintage clients."),
1155 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
1159 check_phony_autocommit, NULL, NULL
1162 {"default_transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
1163 gettext_noop("Sets the default read-only status of new transactions."),
1166 &DefaultXactReadOnly,
1171 {"transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
1172 gettext_noop("Sets the current transaction's read-only status."),
1174 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1178 check_transaction_read_only, NULL, NULL
1181 {"default_transaction_deferrable", PGC_USERSET, CLIENT_CONN_STATEMENT,
1182 gettext_noop("Sets the default deferrable status of new transactions."),
1185 &DefaultXactDeferrable,
1190 {"transaction_deferrable", PGC_USERSET, CLIENT_CONN_STATEMENT,
1191 gettext_noop("Whether to defer a read-only serializable transaction until it can be executed with no possible serialization failures."),
1193 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1197 check_transaction_deferrable, NULL, NULL
1200 {"check_function_bodies", PGC_USERSET, CLIENT_CONN_STATEMENT,
1201 gettext_noop("Check function bodies during CREATE FUNCTION."),
1204 &check_function_bodies,
1209 {"array_nulls", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1210 gettext_noop("Enable input of NULL elements in arrays."),
1211 gettext_noop("When turned on, unquoted NULL in an array input "
1212 "value means a null value; "
1213 "otherwise it is taken literally.")
1220 {"default_with_oids", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1221 gettext_noop("Create new tables with OIDs by default."),
1229 {"logging_collector", PGC_POSTMASTER, LOGGING_WHERE,
1230 gettext_noop("Start a subprocess to capture stderr output and/or csvlogs into log files."),
1238 {"log_truncate_on_rotation", PGC_SIGHUP, LOGGING_WHERE,
1239 gettext_noop("Truncate existing log files of same name during log rotation."),
1242 &Log_truncate_on_rotation,
1249 {"trace_sort", PGC_USERSET, DEVELOPER_OPTIONS,
1250 gettext_noop("Emit information about resource usage in sorting."),
1260 #ifdef TRACE_SYNCSCAN
1261 /* this is undocumented because not exposed in a standard build */
1263 {"trace_syncscan", PGC_USERSET, DEVELOPER_OPTIONS,
1264 gettext_noop("Generate debugging output for synchronized scanning."),
1274 #ifdef DEBUG_BOUNDED_SORT
1275 /* this is undocumented because not exposed in a standard build */
1278 "optimize_bounded_sort", PGC_USERSET, QUERY_TUNING_METHOD,
1279 gettext_noop("Enable bounded sorting using heap sort."),
1283 &optimize_bounded_sort,
1291 {"wal_debug", PGC_SUSET, DEVELOPER_OPTIONS,
1292 gettext_noop("Emit WAL-related debugging output."),
1303 {"integer_datetimes", PGC_INTERNAL, PRESET_OPTIONS,
1304 gettext_noop("Datetimes are integer based."),
1306 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1309 #ifdef HAVE_INT64_TIMESTAMP
1318 {"krb_caseins_users", PGC_SIGHUP, CONN_AUTH_SECURITY,
1319 gettext_noop("Sets whether Kerberos and GSSAPI user names should be treated as case-insensitive."),
1322 &pg_krb_caseins_users,
1328 {"escape_string_warning", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1329 gettext_noop("Warn about backslash escapes in ordinary string literals."),
1332 &escape_string_warning,
1338 {"standard_conforming_strings", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1339 gettext_noop("Causes '...' strings to treat backslashes literally."),
1343 &standard_conforming_strings,
1349 {"synchronize_seqscans", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1350 gettext_noop("Enable synchronized sequential scans."),
1353 &synchronize_seqscans,
1359 {"archive_mode", PGC_POSTMASTER, WAL_ARCHIVING,
1360 gettext_noop("Allows archiving of WAL files using archive_command."),
1369 {"hot_standby", PGC_POSTMASTER, WAL_STANDBY_SERVERS,
1370 gettext_noop("Allows connections and queries during recovery."),
1379 {"hot_standby_feedback", PGC_SIGHUP, WAL_STANDBY_SERVERS,
1380 gettext_noop("Allows feedback from a hot standby primary that will avoid query conflicts."),
1383 &hot_standby_feedback,
1389 {"allow_system_table_mods", PGC_POSTMASTER, DEVELOPER_OPTIONS,
1390 gettext_noop("Allows modifications of the structure of system tables."),
1394 &allowSystemTableMods,
1400 {"ignore_system_indexes", PGC_BACKEND, DEVELOPER_OPTIONS,
1401 gettext_noop("Disables reading from system indexes."),
1402 gettext_noop("It does not prevent updating the indexes, so it is safe "
1403 "to use. The worst consequence is slowness."),
1406 &IgnoreSystemIndexes,
1412 {"lo_compat_privileges", PGC_SUSET, COMPAT_OPTIONS_PREVIOUS,
1413 gettext_noop("Enables backward compatibility mode for privilege checks on large objects."),
1414 gettext_noop("Skips privilege checks when reading or modifying large objects, "
1415 "for compatibility with PostgreSQL releases prior to 9.0.")
1417 &lo_compat_privileges,
1423 {"quote_all_identifiers", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1424 gettext_noop("When generating SQL fragments, quote all identifiers."),
1427 "e_all_identifiers,
1432 /* End-of-list marker */
1434 {NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL, NULL
1439 static struct config_int ConfigureNamesInt[] =
1442 {"archive_timeout", PGC_SIGHUP, WAL_ARCHIVING,
1443 gettext_noop("Forces a switch to the next xlog file if a "
1444 "new file has not been started within N seconds."),
1448 &XLogArchiveTimeout,
1453 {"post_auth_delay", PGC_BACKEND, DEVELOPER_OPTIONS,
1454 gettext_noop("Waits N seconds on connection startup after authentication."),
1455 gettext_noop("This allows attaching a debugger to the process."),
1456 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1463 {"default_statistics_target", PGC_USERSET, QUERY_TUNING_OTHER,
1464 gettext_noop("Sets the default statistics target."),
1465 gettext_noop("This applies to table columns that have not had a "
1466 "column-specific target set via ALTER TABLE SET STATISTICS.")
1468 &default_statistics_target,
1473 {"from_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1474 gettext_noop("Sets the FROM-list size beyond which subqueries "
1475 "are not collapsed."),
1476 gettext_noop("The planner will merge subqueries into upper "
1477 "queries if the resulting FROM list would have no more than "
1480 &from_collapse_limit,
1485 {"join_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1486 gettext_noop("Sets the FROM-list size beyond which JOIN "
1487 "constructs are not flattened."),
1488 gettext_noop("The planner will flatten explicit JOIN "
1489 "constructs into lists of FROM items whenever a "
1490 "list of no more than this many items would result.")
1492 &join_collapse_limit,
1497 {"geqo_threshold", PGC_USERSET, QUERY_TUNING_GEQO,
1498 gettext_noop("Sets the threshold of FROM items beyond which GEQO is used."),
1506 {"geqo_effort", PGC_USERSET, QUERY_TUNING_GEQO,
1507 gettext_noop("GEQO: effort is used to set the default for other GEQO parameters."),
1511 DEFAULT_GEQO_EFFORT, MIN_GEQO_EFFORT, MAX_GEQO_EFFORT,
1515 {"geqo_pool_size", PGC_USERSET, QUERY_TUNING_GEQO,
1516 gettext_noop("GEQO: number of individuals in the population."),
1517 gettext_noop("Zero selects a suitable default value.")
1524 {"geqo_generations", PGC_USERSET, QUERY_TUNING_GEQO,
1525 gettext_noop("GEQO: number of iterations of the algorithm."),
1526 gettext_noop("Zero selects a suitable default value.")
1534 /* This is PGC_SIGHUP so all backends have the same value. */
1535 {"deadlock_timeout", PGC_SIGHUP, LOCK_MANAGEMENT,
1536 gettext_noop("Sets the time to wait on a lock before checking for deadlock."),
1546 {"max_standby_archive_delay", PGC_SIGHUP, WAL_STANDBY_SERVERS,
1547 gettext_noop("Sets the maximum delay before canceling queries when a hot standby server is processing archived WAL data."),
1551 &max_standby_archive_delay,
1552 30 * 1000, -1, INT_MAX,
1557 {"max_standby_streaming_delay", PGC_SIGHUP, WAL_STANDBY_SERVERS,
1558 gettext_noop("Sets the maximum delay before canceling queries when a hot standby server is processing streamed WAL data."),
1562 &max_standby_streaming_delay,
1563 30 * 1000, -1, INT_MAX,
1568 {"wal_receiver_status_interval", PGC_SIGHUP, WAL_STANDBY_SERVERS,
1569 gettext_noop("Sets the maximum interval between WAL receiver status reports to the master."),
1573 &wal_receiver_status_interval,
1574 10, 0, INT_MAX/1000,
1579 {"max_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1580 gettext_noop("Sets the maximum number of concurrent connections."),
1584 100, 1, MAX_BACKENDS,
1585 check_maxconnections, assign_maxconnections, NULL
1589 {"superuser_reserved_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1590 gettext_noop("Sets the number of connection slots reserved for superusers."),
1599 * We sometimes multiply the number of shared buffers by two without
1600 * checking for overflow, so we mustn't allow more than INT_MAX / 2.
1603 {"shared_buffers", PGC_POSTMASTER, RESOURCES_MEM,
1604 gettext_noop("Sets the number of shared memory buffers used by the server."),
1609 1024, 16, INT_MAX / 2,
1614 {"temp_buffers", PGC_USERSET, RESOURCES_MEM,
1615 gettext_noop("Sets the maximum number of temporary buffers used by each session."),
1620 1024, 100, INT_MAX / 2,
1621 check_temp_buffers, NULL, NULL
1625 {"port", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1626 gettext_noop("Sets the TCP port the server listens on."),
1630 DEF_PGPORT, 1, 65535,
1635 {"unix_socket_permissions", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1636 gettext_noop("Sets the access permissions of the Unix-domain socket."),
1637 gettext_noop("Unix-domain sockets use the usual Unix file system "
1638 "permission set. The parameter value is expected "
1639 "to be a numeric mode specification in the form "
1640 "accepted by the chmod and umask system calls. "
1641 "(To use the customary octal format the number must "
1642 "start with a 0 (zero).)")
1644 &Unix_socket_permissions,
1646 NULL, NULL, show_unix_socket_permissions
1650 {"log_file_mode", PGC_SIGHUP, LOGGING_WHERE,
1651 gettext_noop("Sets the file permissions for log files."),
1652 gettext_noop("The parameter value is expected "
1653 "to be a numeric mode specification in the form "
1654 "accepted by the chmod and umask system calls. "
1655 "(To use the customary octal format the number must "
1656 "start with a 0 (zero).)")
1660 NULL, NULL, show_log_file_mode
1664 {"work_mem", PGC_USERSET, RESOURCES_MEM,
1665 gettext_noop("Sets the maximum memory to be used for query workspaces."),
1666 gettext_noop("This much memory can be used by each internal "
1667 "sort operation and hash table before switching to "
1668 "temporary disk files."),
1672 1024, 64, MAX_KILOBYTES,
1677 {"maintenance_work_mem", PGC_USERSET, RESOURCES_MEM,
1678 gettext_noop("Sets the maximum memory to be used for maintenance operations."),
1679 gettext_noop("This includes operations such as VACUUM and CREATE INDEX."),
1682 &maintenance_work_mem,
1683 16384, 1024, MAX_KILOBYTES,
1688 * We use the hopefully-safely-small value of 100kB as the compiled-in
1689 * default for max_stack_depth. InitializeGUCOptions will increase it if
1690 * possible, depending on the actual platform-specific stack limit.
1693 {"max_stack_depth", PGC_SUSET, RESOURCES_MEM,
1694 gettext_noop("Sets the maximum stack depth, in kilobytes."),
1699 100, 100, MAX_KILOBYTES,
1700 check_max_stack_depth, assign_max_stack_depth, NULL
1704 {"vacuum_cost_page_hit", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1705 gettext_noop("Vacuum cost for a page found in the buffer cache."),
1714 {"vacuum_cost_page_miss", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1715 gettext_noop("Vacuum cost for a page not found in the buffer cache."),
1718 &VacuumCostPageMiss,
1724 {"vacuum_cost_page_dirty", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1725 gettext_noop("Vacuum cost for a page dirtied by vacuum."),
1728 &VacuumCostPageDirty,
1734 {"vacuum_cost_limit", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1735 gettext_noop("Vacuum cost amount available before napping."),
1744 {"vacuum_cost_delay", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1745 gettext_noop("Vacuum cost delay in milliseconds."),
1755 {"autovacuum_vacuum_cost_delay", PGC_SIGHUP, AUTOVACUUM,
1756 gettext_noop("Vacuum cost delay in milliseconds, for autovacuum."),
1760 &autovacuum_vac_cost_delay,
1766 {"autovacuum_vacuum_cost_limit", PGC_SIGHUP, AUTOVACUUM,
1767 gettext_noop("Vacuum cost amount available before napping, for autovacuum."),
1770 &autovacuum_vac_cost_limit,
1776 {"max_files_per_process", PGC_POSTMASTER, RESOURCES_KERNEL,
1777 gettext_noop("Sets the maximum number of simultaneously open files for each server process."),
1780 &max_files_per_process,
1786 * See also CheckRequiredParameterValues() if this parameter changes
1789 {"max_prepared_transactions", PGC_POSTMASTER, RESOURCES_MEM,
1790 gettext_noop("Sets the maximum number of simultaneously prepared transactions."),
1793 &max_prepared_xacts,
1800 {"trace_lock_oidmin", PGC_SUSET, DEVELOPER_OPTIONS,
1801 gettext_noop("No description available."),
1806 FirstNormalObjectId, 0, INT_MAX,
1810 {"trace_lock_table", PGC_SUSET, DEVELOPER_OPTIONS,
1811 gettext_noop("No description available."),
1822 {"statement_timeout", PGC_USERSET, CLIENT_CONN_STATEMENT,
1823 gettext_noop("Sets the maximum allowed duration of any statement."),
1824 gettext_noop("A value of 0 turns off the timeout."),
1833 {"vacuum_freeze_min_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1834 gettext_noop("Minimum age at which VACUUM should freeze a table row."),
1837 &vacuum_freeze_min_age,
1838 50000000, 0, 1000000000,
1843 {"vacuum_freeze_table_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1844 gettext_noop("Age at which VACUUM should scan whole table to freeze tuples."),
1847 &vacuum_freeze_table_age,
1848 150000000, 0, 2000000000,
1853 {"vacuum_defer_cleanup_age", PGC_SIGHUP, WAL_REPLICATION,
1854 gettext_noop("Number of transactions by which VACUUM and HOT cleanup should be deferred, if any."),
1857 &vacuum_defer_cleanup_age,
1863 * See also CheckRequiredParameterValues() if this parameter changes
1866 {"max_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
1867 gettext_noop("Sets the maximum number of locks per transaction."),
1868 gettext_noop("The shared lock table is sized on the assumption that "
1869 "at most max_locks_per_transaction * max_connections distinct "
1870 "objects will need to be locked at any one time.")
1872 &max_locks_per_xact,
1878 {"max_pred_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
1879 gettext_noop("Sets the maximum number of predicate locks per transaction."),
1880 gettext_noop("The shared predicate lock table is sized on the assumption that "
1881 "at most max_pred_locks_per_transaction * max_connections distinct "
1882 "objects will need to be locked at any one time.")
1884 &max_predicate_locks_per_xact,
1890 {"authentication_timeout", PGC_SIGHUP, CONN_AUTH_SECURITY,
1891 gettext_noop("Sets the maximum allowed time to complete client authentication."),
1895 &AuthenticationTimeout,
1901 /* Not for general use */
1902 {"pre_auth_delay", PGC_SIGHUP, DEVELOPER_OPTIONS,
1903 gettext_noop("Waits N seconds on connection startup before authentication."),
1904 gettext_noop("This allows attaching a debugger to the process."),
1905 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1913 {"wal_keep_segments", PGC_SIGHUP, WAL_REPLICATION,
1914 gettext_noop("Sets the number of WAL files held for standby servers."),
1923 {"checkpoint_segments", PGC_SIGHUP, WAL_CHECKPOINTS,
1924 gettext_noop("Sets the maximum distance in log segments between automatic WAL checkpoints."),
1927 &CheckPointSegments,
1933 {"checkpoint_timeout", PGC_SIGHUP, WAL_CHECKPOINTS,
1934 gettext_noop("Sets the maximum time between automatic WAL checkpoints."),
1944 {"checkpoint_warning", PGC_SIGHUP, WAL_CHECKPOINTS,
1945 gettext_noop("Enables warnings if checkpoint segments are filled more "
1946 "frequently than this."),
1947 gettext_noop("Write a message to the server log if checkpoints "
1948 "caused by the filling of checkpoint segment files happens more "
1949 "frequently than this number of seconds. Zero turns off the warning."),
1958 {"wal_buffers", PGC_POSTMASTER, WAL_SETTINGS,
1959 gettext_noop("Sets the number of disk-page buffers in shared memory for WAL."),
1965 check_wal_buffers, NULL, NULL
1969 {"wal_writer_delay", PGC_SIGHUP, WAL_SETTINGS,
1970 gettext_noop("WAL writer sleep time between WAL flushes."),
1980 /* see max_connections */
1981 {"max_wal_senders", PGC_POSTMASTER, WAL_REPLICATION,
1982 gettext_noop("Sets the maximum number of simultaneously running WAL sender processes."),
1991 {"wal_sender_delay", PGC_SIGHUP, WAL_REPLICATION,
1992 gettext_noop("WAL sender sleep time between WAL replications."),
2002 {"replication_timeout", PGC_SIGHUP, WAL_REPLICATION,
2003 gettext_noop("Sets the maximum time to wait for WAL replication."),
2007 &replication_timeout,
2008 60 * 1000, 0, INT_MAX,
2013 {"commit_delay", PGC_USERSET, WAL_SETTINGS,
2014 gettext_noop("Sets the delay in microseconds between transaction commit and "
2015 "flushing WAL to disk."),
2024 {"commit_siblings", PGC_USERSET, WAL_SETTINGS,
2025 gettext_noop("Sets the minimum concurrent open transactions before performing "
2035 {"extra_float_digits", PGC_USERSET, CLIENT_CONN_LOCALE,
2036 gettext_noop("Sets the number of digits displayed for floating-point values."),
2037 gettext_noop("This affects real, double precision, and geometric data types. "
2038 "The parameter value is added to the standard number of digits "
2039 "(FLT_DIG or DBL_DIG as appropriate).")
2041 &extra_float_digits,
2047 {"log_min_duration_statement", PGC_SUSET, LOGGING_WHEN,
2048 gettext_noop("Sets the minimum execution time above which "
2049 "statements will be logged."),
2050 gettext_noop("Zero prints all queries. -1 turns this feature off."),
2053 &log_min_duration_statement,
2059 {"log_autovacuum_min_duration", PGC_SIGHUP, LOGGING_WHAT,
2060 gettext_noop("Sets the minimum execution time above which "
2061 "autovacuum actions will be logged."),
2062 gettext_noop("Zero prints all actions. -1 turns autovacuum logging off."),
2065 &Log_autovacuum_min_duration,
2071 {"bgwriter_delay", PGC_SIGHUP, RESOURCES_BGWRITER,
2072 gettext_noop("Background writer sleep time between rounds."),
2082 {"bgwriter_lru_maxpages", PGC_SIGHUP, RESOURCES_BGWRITER,
2083 gettext_noop("Background writer maximum number of LRU pages to flush per round."),
2086 &bgwriter_lru_maxpages,
2092 {"effective_io_concurrency",
2098 RESOURCES_ASYNCHRONOUS,
2099 gettext_noop("Number of simultaneous requests that can be handled efficiently by the disk subsystem."),
2100 gettext_noop("For RAID arrays, this should be approximately the number of drive spindles in the array.")
2102 &effective_io_concurrency,
2108 check_effective_io_concurrency, assign_effective_io_concurrency, NULL
2112 {"log_rotation_age", PGC_SIGHUP, LOGGING_WHERE,
2113 gettext_noop("Automatic log file rotation will occur after N minutes."),
2118 HOURS_PER_DAY * MINS_PER_HOUR, 0, INT_MAX / MINS_PER_HOUR,
2123 {"log_rotation_size", PGC_SIGHUP, LOGGING_WHERE,
2124 gettext_noop("Automatic log file rotation will occur after N kilobytes."),
2129 10 * 1024, 0, INT_MAX / 1024,
2134 {"max_function_args", PGC_INTERNAL, PRESET_OPTIONS,
2135 gettext_noop("Shows the maximum number of function arguments."),
2137 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2140 FUNC_MAX_ARGS, FUNC_MAX_ARGS, FUNC_MAX_ARGS,
2145 {"max_index_keys", PGC_INTERNAL, PRESET_OPTIONS,
2146 gettext_noop("Shows the maximum number of index keys."),
2148 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2151 INDEX_MAX_KEYS, INDEX_MAX_KEYS, INDEX_MAX_KEYS,
2156 {"max_identifier_length", PGC_INTERNAL, PRESET_OPTIONS,
2157 gettext_noop("Shows the maximum identifier length."),
2159 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2161 &max_identifier_length,
2162 NAMEDATALEN - 1, NAMEDATALEN - 1, NAMEDATALEN - 1,
2167 {"block_size", PGC_INTERNAL, PRESET_OPTIONS,
2168 gettext_noop("Shows the size of a disk block."),
2170 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2173 BLCKSZ, BLCKSZ, BLCKSZ,
2178 {"segment_size", PGC_INTERNAL, PRESET_OPTIONS,
2179 gettext_noop("Shows the number of pages per disk file."),
2181 GUC_UNIT_BLOCKS | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2184 RELSEG_SIZE, RELSEG_SIZE, RELSEG_SIZE,
2189 {"wal_block_size", PGC_INTERNAL, PRESET_OPTIONS,
2190 gettext_noop("Shows the block size in the write ahead log."),
2192 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2195 XLOG_BLCKSZ, XLOG_BLCKSZ, XLOG_BLCKSZ,
2200 {"wal_segment_size", PGC_INTERNAL, PRESET_OPTIONS,
2201 gettext_noop("Shows the number of pages per write ahead log segment."),
2203 GUC_UNIT_XBLOCKS | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2206 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
2207 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
2208 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
2213 {"autovacuum_naptime", PGC_SIGHUP, AUTOVACUUM,
2214 gettext_noop("Time to sleep between autovacuum runs."),
2218 &autovacuum_naptime,
2219 60, 1, INT_MAX / 1000,
2223 {"autovacuum_vacuum_threshold", PGC_SIGHUP, AUTOVACUUM,
2224 gettext_noop("Minimum number of tuple updates or deletes prior to vacuum."),
2227 &autovacuum_vac_thresh,
2232 {"autovacuum_analyze_threshold", PGC_SIGHUP, AUTOVACUUM,
2233 gettext_noop("Minimum number of tuple inserts, updates or deletes prior to analyze."),
2236 &autovacuum_anl_thresh,
2241 /* see varsup.c for why this is PGC_POSTMASTER not PGC_SIGHUP */
2242 {"autovacuum_freeze_max_age", PGC_POSTMASTER, AUTOVACUUM,
2243 gettext_noop("Age at which to autovacuum a table to prevent transaction ID wraparound."),
2246 &autovacuum_freeze_max_age,
2247 /* see pg_resetxlog if you change the upper-limit value */
2248 200000000, 100000000, 2000000000,
2252 /* see max_connections */
2253 {"autovacuum_max_workers", PGC_POSTMASTER, AUTOVACUUM,
2254 gettext_noop("Sets the maximum number of simultaneously running autovacuum worker processes."),
2257 &autovacuum_max_workers,
2259 check_autovacuum_max_workers, assign_autovacuum_max_workers, NULL
2263 {"tcp_keepalives_idle", PGC_USERSET, CLIENT_CONN_OTHER,
2264 gettext_noop("Time between issuing TCP keepalives."),
2265 gettext_noop("A value of 0 uses the system default."),
2268 &tcp_keepalives_idle,
2270 NULL, assign_tcp_keepalives_idle, show_tcp_keepalives_idle
2274 {"tcp_keepalives_interval", PGC_USERSET, CLIENT_CONN_OTHER,
2275 gettext_noop("Time between TCP keepalive retransmits."),
2276 gettext_noop("A value of 0 uses the system default."),
2279 &tcp_keepalives_interval,
2281 NULL, assign_tcp_keepalives_interval, show_tcp_keepalives_interval
2285 {"ssl_renegotiation_limit", PGC_USERSET, CONN_AUTH_SECURITY,
2286 gettext_noop("Set the amount of traffic to send and receive before renegotiating the encryption keys."),
2290 &ssl_renegotiation_limit,
2291 512 * 1024, 0, MAX_KILOBYTES,
2296 {"tcp_keepalives_count", PGC_USERSET, CLIENT_CONN_OTHER,
2297 gettext_noop("Maximum number of TCP keepalive retransmits."),
2298 gettext_noop("This controls the number of consecutive keepalive retransmits that can be "
2299 "lost before a connection is considered dead. A value of 0 uses the "
2302 &tcp_keepalives_count,
2304 NULL, assign_tcp_keepalives_count, show_tcp_keepalives_count
2308 {"gin_fuzzy_search_limit", PGC_USERSET, CLIENT_CONN_OTHER,
2309 gettext_noop("Sets the maximum allowed result for exact search by GIN."),
2313 &GinFuzzySearchLimit,
2319 {"effective_cache_size", PGC_USERSET, QUERY_TUNING_COST,
2320 gettext_noop("Sets the planner's assumption about the size of the disk cache."),
2321 gettext_noop("That is, the portion of the kernel's disk cache that "
2322 "will be used for PostgreSQL data files. This is measured in disk "
2323 "pages, which are normally 8 kB each."),
2326 &effective_cache_size,
2327 DEFAULT_EFFECTIVE_CACHE_SIZE, 1, INT_MAX,
2332 /* Can't be set in postgresql.conf */
2333 {"server_version_num", PGC_INTERNAL, PRESET_OPTIONS,
2334 gettext_noop("Shows the server version as an integer."),
2336 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2338 &server_version_num,
2339 PG_VERSION_NUM, PG_VERSION_NUM, PG_VERSION_NUM,
2344 {"log_temp_files", PGC_SUSET, LOGGING_WHAT,
2345 gettext_noop("Log the use of temporary files larger than this number of kilobytes."),
2346 gettext_noop("Zero logs all files. The default is -1 (turning this feature off)."),
2355 {"track_activity_query_size", PGC_POSTMASTER, RESOURCES_MEM,
2356 gettext_noop("Sets the size reserved for pg_stat_activity.current_query, in bytes."),
2359 &pgstat_track_activity_query_size,
2364 /* End-of-list marker */
2366 {NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL, NULL
2371 static struct config_real ConfigureNamesReal[] =
2374 {"seq_page_cost", PGC_USERSET, QUERY_TUNING_COST,
2375 gettext_noop("Sets the planner's estimate of the cost of a "
2376 "sequentially fetched disk page."),
2380 DEFAULT_SEQ_PAGE_COST, 0, DBL_MAX,
2384 {"random_page_cost", PGC_USERSET, QUERY_TUNING_COST,
2385 gettext_noop("Sets the planner's estimate of the cost of a "
2386 "nonsequentially fetched disk page."),
2390 DEFAULT_RANDOM_PAGE_COST, 0, DBL_MAX,
2394 {"cpu_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
2395 gettext_noop("Sets the planner's estimate of the cost of "
2396 "processing each tuple (row)."),
2400 DEFAULT_CPU_TUPLE_COST, 0, DBL_MAX,
2404 {"cpu_index_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
2405 gettext_noop("Sets the planner's estimate of the cost of "
2406 "processing each index entry during an index scan."),
2409 &cpu_index_tuple_cost,
2410 DEFAULT_CPU_INDEX_TUPLE_COST, 0, DBL_MAX,
2414 {"cpu_operator_cost", PGC_USERSET, QUERY_TUNING_COST,
2415 gettext_noop("Sets the planner's estimate of the cost of "
2416 "processing each operator or function call."),
2420 DEFAULT_CPU_OPERATOR_COST, 0, DBL_MAX,
2425 {"cursor_tuple_fraction", PGC_USERSET, QUERY_TUNING_OTHER,
2426 gettext_noop("Sets the planner's estimate of the fraction of "
2427 "a cursor's rows that will be retrieved."),
2430 &cursor_tuple_fraction,
2431 DEFAULT_CURSOR_TUPLE_FRACTION, 0.0, 1.0,
2436 {"geqo_selection_bias", PGC_USERSET, QUERY_TUNING_GEQO,
2437 gettext_noop("GEQO: selective pressure within the population."),
2440 &Geqo_selection_bias,
2441 DEFAULT_GEQO_SELECTION_BIAS,
2442 MIN_GEQO_SELECTION_BIAS, MAX_GEQO_SELECTION_BIAS,
2446 {"geqo_seed", PGC_USERSET, QUERY_TUNING_GEQO,
2447 gettext_noop("GEQO: seed for random path selection."),
2456 {"bgwriter_lru_multiplier", PGC_SIGHUP, RESOURCES_BGWRITER,
2457 gettext_noop("Multiple of the average buffer usage to free per round."),
2460 &bgwriter_lru_multiplier,
2466 {"seed", PGC_USERSET, UNGROUPED,
2467 gettext_noop("Sets the seed for random-number generation."),
2469 GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2473 check_random_seed, assign_random_seed, show_random_seed
2477 {"autovacuum_vacuum_scale_factor", PGC_SIGHUP, AUTOVACUUM,
2478 gettext_noop("Number of tuple updates or deletes prior to vacuum as a fraction of reltuples."),
2481 &autovacuum_vac_scale,
2486 {"autovacuum_analyze_scale_factor", PGC_SIGHUP, AUTOVACUUM,
2487 gettext_noop("Number of tuple inserts, updates or deletes prior to analyze as a fraction of reltuples."),
2490 &autovacuum_anl_scale,
2496 {"checkpoint_completion_target", PGC_SIGHUP, WAL_CHECKPOINTS,
2497 gettext_noop("Time spent flushing dirty buffers during checkpoint, as fraction of checkpoint interval."),
2500 &CheckPointCompletionTarget,
2505 /* End-of-list marker */
2507 {NULL, 0, 0, NULL, NULL}, NULL, 0.0, 0.0, 0.0, NULL, NULL, NULL
2512 static struct config_string ConfigureNamesString[] =
2515 {"archive_command", PGC_SIGHUP, WAL_ARCHIVING,
2516 gettext_noop("Sets the shell command that will be called to archive a WAL file."),
2519 &XLogArchiveCommand,
2521 NULL, NULL, show_archive_command
2525 {"client_encoding", PGC_USERSET, CLIENT_CONN_LOCALE,
2526 gettext_noop("Sets the client's character set encoding."),
2528 GUC_IS_NAME | GUC_REPORT
2530 &client_encoding_string,
2532 check_client_encoding, assign_client_encoding, NULL
2536 {"log_line_prefix", PGC_SIGHUP, LOGGING_WHAT,
2537 gettext_noop("Controls information prefixed to each log line."),
2538 gettext_noop("If blank, no prefix is used.")
2546 {"log_timezone", PGC_SIGHUP, LOGGING_WHAT,
2547 gettext_noop("Sets the time zone to use in log messages."),
2550 &log_timezone_string,
2552 check_log_timezone, assign_log_timezone, show_log_timezone
2556 {"DateStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
2557 gettext_noop("Sets the display format for date and time values."),
2558 gettext_noop("Also controls interpretation of ambiguous "
2560 GUC_LIST_INPUT | GUC_REPORT
2564 check_datestyle, assign_datestyle, NULL
2568 {"default_tablespace", PGC_USERSET, CLIENT_CONN_STATEMENT,
2569 gettext_noop("Sets the default tablespace to create tables and indexes in."),
2570 gettext_noop("An empty string selects the database's default tablespace."),
2573 &default_tablespace,
2575 check_default_tablespace, NULL, NULL
2579 {"temp_tablespaces", PGC_USERSET, CLIENT_CONN_STATEMENT,
2580 gettext_noop("Sets the tablespace(s) to use for temporary tables and sort files."),
2582 GUC_LIST_INPUT | GUC_LIST_QUOTE
2586 check_temp_tablespaces, assign_temp_tablespaces, NULL
2590 {"dynamic_library_path", PGC_SUSET, CLIENT_CONN_OTHER,
2591 gettext_noop("Sets the path for dynamically loadable modules."),
2592 gettext_noop("If a dynamically loadable module needs to be opened and "
2593 "the specified name does not have a directory component (i.e., the "
2594 "name does not contain a slash), the system will search this path for "
2595 "the specified file."),
2598 &Dynamic_library_path,
2604 {"krb_server_keyfile", PGC_SIGHUP, CONN_AUTH_SECURITY,
2605 gettext_noop("Sets the location of the Kerberos server key file."),
2609 &pg_krb_server_keyfile,
2615 {"krb_srvname", PGC_SIGHUP, CONN_AUTH_SECURITY,
2616 gettext_noop("Sets the name of the Kerberos service."),
2625 {"bonjour_name", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2626 gettext_noop("Sets the Bonjour service name."),
2634 /* See main.c about why defaults for LC_foo are not all alike */
2637 {"lc_collate", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2638 gettext_noop("Shows the collation order locale."),
2640 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2648 {"lc_ctype", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2649 gettext_noop("Shows the character classification and case conversion locale."),
2651 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2659 {"lc_messages", PGC_SUSET, CLIENT_CONN_LOCALE,
2660 gettext_noop("Sets the language in which messages are displayed."),
2665 check_locale_messages, assign_locale_messages, NULL
2669 {"lc_monetary", PGC_USERSET, CLIENT_CONN_LOCALE,
2670 gettext_noop("Sets the locale for formatting monetary amounts."),
2675 check_locale_monetary, assign_locale_monetary, NULL
2679 {"lc_numeric", PGC_USERSET, CLIENT_CONN_LOCALE,
2680 gettext_noop("Sets the locale for formatting numbers."),
2685 check_locale_numeric, assign_locale_numeric, NULL
2689 {"lc_time", PGC_USERSET, CLIENT_CONN_LOCALE,
2690 gettext_noop("Sets the locale for formatting date and time values."),
2695 check_locale_time, assign_locale_time, NULL
2699 {"shared_preload_libraries", PGC_POSTMASTER, RESOURCES_KERNEL,
2700 gettext_noop("Lists shared libraries to preload into server."),
2702 GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
2704 &shared_preload_libraries_string,
2710 {"local_preload_libraries", PGC_BACKEND, CLIENT_CONN_OTHER,
2711 gettext_noop("Lists shared libraries to preload into each backend."),
2713 GUC_LIST_INPUT | GUC_LIST_QUOTE
2715 &local_preload_libraries_string,
2721 {"search_path", PGC_USERSET, CLIENT_CONN_STATEMENT,
2722 gettext_noop("Sets the schema search order for names that are not schema-qualified."),
2724 GUC_LIST_INPUT | GUC_LIST_QUOTE
2726 &namespace_search_path,
2728 check_search_path, assign_search_path, NULL
2732 /* Can't be set in postgresql.conf */
2733 {"server_encoding", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2734 gettext_noop("Sets the server (database) character set encoding."),
2736 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2738 &server_encoding_string,
2744 /* Can't be set in postgresql.conf */
2745 {"server_version", PGC_INTERNAL, PRESET_OPTIONS,
2746 gettext_noop("Shows the server version."),
2748 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2750 &server_version_string,
2756 /* Not for general use --- used by SET ROLE */
2757 {"role", PGC_USERSET, UNGROUPED,
2758 gettext_noop("Sets the current role."),
2760 GUC_IS_NAME | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_NOT_WHILE_SEC_REST
2764 check_role, assign_role, show_role
2768 /* Not for general use --- used by SET SESSION AUTHORIZATION */
2769 {"session_authorization", PGC_USERSET, UNGROUPED,
2770 gettext_noop("Sets the session user name."),
2772 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
2774 &session_authorization_string,
2776 check_session_authorization, assign_session_authorization, NULL
2780 {"log_destination", PGC_SIGHUP, LOGGING_WHERE,
2781 gettext_noop("Sets the destination for server log output."),
2782 gettext_noop("Valid values are combinations of \"stderr\", "
2783 "\"syslog\", \"csvlog\", and \"eventlog\", "
2784 "depending on the platform."),
2787 &log_destination_string,
2789 check_log_destination, assign_log_destination, NULL
2792 {"log_directory", PGC_SIGHUP, LOGGING_WHERE,
2793 gettext_noop("Sets the destination directory for log files."),
2794 gettext_noop("Can be specified as relative to the data directory "
2795 "or as absolute path."),
2800 check_canonical_path, NULL, NULL
2803 {"log_filename", PGC_SIGHUP, LOGGING_WHERE,
2804 gettext_noop("Sets the file name pattern for log files."),
2809 "postgresql-%Y-%m-%d_%H%M%S.log",
2814 {"syslog_ident", PGC_SIGHUP, LOGGING_WHERE,
2815 gettext_noop("Sets the program name used to identify PostgreSQL "
2816 "messages in syslog."),
2821 NULL, assign_syslog_ident, NULL
2825 {"TimeZone", PGC_USERSET, CLIENT_CONN_LOCALE,
2826 gettext_noop("Sets the time zone for displaying and interpreting time stamps."),
2832 check_timezone, assign_timezone, show_timezone
2835 {"timezone_abbreviations", PGC_USERSET, CLIENT_CONN_LOCALE,
2836 gettext_noop("Selects a file of time zone abbreviations."),
2839 &timezone_abbreviations_string,
2841 check_timezone_abbreviations, assign_timezone_abbreviations, NULL
2845 {"transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
2846 gettext_noop("Sets the current transaction's isolation level."),
2848 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2850 &XactIsoLevel_string,
2852 check_XactIsoLevel, assign_XactIsoLevel, show_XactIsoLevel
2856 {"unix_socket_group", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2857 gettext_noop("Sets the owning group of the Unix-domain socket."),
2858 gettext_noop("The owning user of the socket is always the user "
2859 "that starts the server.")
2867 {"unix_socket_directory", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2868 gettext_noop("Sets the directory where the Unix-domain socket will be created."),
2874 check_canonical_path, NULL, NULL
2878 {"listen_addresses", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2879 gettext_noop("Sets the host name or IP address(es) to listen to."),
2889 {"custom_variable_classes", PGC_SIGHUP, CUSTOM_OPTIONS,
2890 gettext_noop("Sets the list of known custom variable classes."),
2892 GUC_LIST_INPUT | GUC_LIST_QUOTE
2894 &custom_variable_classes,
2896 check_custom_variable_classes, NULL, NULL
2900 {"data_directory", PGC_POSTMASTER, FILE_LOCATIONS,
2901 gettext_noop("Sets the server's data directory."),
2911 {"config_file", PGC_POSTMASTER, FILE_LOCATIONS,
2912 gettext_noop("Sets the server's main configuration file."),
2914 GUC_DISALLOW_IN_FILE | GUC_SUPERUSER_ONLY
2922 {"hba_file", PGC_POSTMASTER, FILE_LOCATIONS,
2923 gettext_noop("Sets the server's \"hba\" configuration file."),
2933 {"ident_file", PGC_POSTMASTER, FILE_LOCATIONS,
2934 gettext_noop("Sets the server's \"ident\" configuration file."),
2944 {"external_pid_file", PGC_POSTMASTER, FILE_LOCATIONS,
2945 gettext_noop("Writes the postmaster PID to the specified file."),
2951 check_canonical_path, NULL, NULL
2955 {"stats_temp_directory", PGC_SIGHUP, STATS_COLLECTOR,
2956 gettext_noop("Writes temporary statistics files to the specified directory."),
2960 &pgstat_temp_directory,
2962 check_canonical_path, assign_pgstat_temp_directory, NULL
2966 {"synchronous_standby_names", PGC_SIGHUP, WAL_REPLICATION,
2967 gettext_noop("List of potential standby names to synchronise with."),
2971 &SyncRepStandbyNames,
2973 check_synchronous_standby_names, NULL, NULL
2977 {"default_text_search_config", PGC_USERSET, CLIENT_CONN_LOCALE,
2978 gettext_noop("Sets default text search configuration."),
2982 "pg_catalog.simple",
2983 check_TSCurrentConfig, assign_TSCurrentConfig, NULL
2987 {"ssl_ciphers", PGC_POSTMASTER, CONN_AUTH_SECURITY,
2988 gettext_noop("Sets the list of allowed SSL ciphers."),
2994 "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH",
3002 {"application_name", PGC_USERSET, LOGGING_WHAT,
3003 gettext_noop("Sets the application name to be reported in statistics and logs."),
3005 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE
3009 check_application_name, assign_application_name, NULL
3012 /* End-of-list marker */
3014 {NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL, NULL
3019 static struct config_enum ConfigureNamesEnum[] =
3022 {"backslash_quote", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
3023 gettext_noop("Sets whether \"\\'\" is allowed in string literals."),
3027 BACKSLASH_QUOTE_SAFE_ENCODING, backslash_quote_options,
3032 {"bytea_output", PGC_USERSET, CLIENT_CONN_STATEMENT,
3033 gettext_noop("Sets the output format for bytea."),
3037 BYTEA_OUTPUT_HEX, bytea_output_options,
3042 {"client_min_messages", PGC_USERSET, LOGGING_WHEN,
3043 gettext_noop("Sets the message levels that are sent to the client."),
3044 gettext_noop("Each level includes all the levels that follow it. The later"
3045 " the level, the fewer messages are sent.")
3047 &client_min_messages,
3048 NOTICE, client_message_level_options,
3053 {"constraint_exclusion", PGC_USERSET, QUERY_TUNING_OTHER,
3054 gettext_noop("Enables the planner to use constraints to optimize queries."),
3055 gettext_noop("Table scans will be skipped if their constraints"
3056 " guarantee that no rows match the query.")
3058 &constraint_exclusion,
3059 CONSTRAINT_EXCLUSION_PARTITION, constraint_exclusion_options,
3064 {"default_transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
3065 gettext_noop("Sets the transaction isolation level of each new transaction."),
3068 &DefaultXactIsoLevel,
3069 XACT_READ_COMMITTED, isolation_level_options,
3074 {"IntervalStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
3075 gettext_noop("Sets the display format for interval values."),
3080 INTSTYLE_POSTGRES, intervalstyle_options,
3085 {"log_error_verbosity", PGC_SUSET, LOGGING_WHAT,
3086 gettext_noop("Sets the verbosity of logged messages."),
3089 &Log_error_verbosity,
3090 PGERROR_DEFAULT, log_error_verbosity_options,
3095 {"log_min_messages", PGC_SUSET, LOGGING_WHEN,
3096 gettext_noop("Sets the message levels that are logged."),
3097 gettext_noop("Each level includes all the levels that follow it. The later"
3098 " the level, the fewer messages are sent.")
3101 WARNING, server_message_level_options,
3106 {"log_min_error_statement", PGC_SUSET, LOGGING_WHEN,
3107 gettext_noop("Causes all statements generating error at or above this level to be logged."),
3108 gettext_noop("Each level includes all the levels that follow it. The later"
3109 " the level, the fewer messages are sent.")
3111 &log_min_error_statement,
3112 ERROR, server_message_level_options,
3117 {"log_statement", PGC_SUSET, LOGGING_WHAT,
3118 gettext_noop("Sets the type of statements logged."),
3122 LOGSTMT_NONE, log_statement_options,
3127 {"syslog_facility", PGC_SIGHUP, LOGGING_WHERE,
3128 gettext_noop("Sets the syslog \"facility\" to be used when syslog enabled."),
3137 syslog_facility_options,
3138 NULL, assign_syslog_facility, NULL
3142 {"session_replication_role", PGC_SUSET, CLIENT_CONN_STATEMENT,
3143 gettext_noop("Sets the session's behavior for triggers and rewrite rules."),
3146 &SessionReplicationRole,
3147 SESSION_REPLICATION_ROLE_ORIGIN, session_replication_role_options,
3148 NULL, assign_session_replication_role, NULL
3152 {"synchronous_commit", PGC_USERSET, WAL_SETTINGS,
3153 gettext_noop("Sets the current transaction's synchronization level."),
3156 &synchronous_commit,
3157 SYNCHRONOUS_COMMIT_ON, synchronous_commit_options,
3162 {"trace_recovery_messages", PGC_SIGHUP, DEVELOPER_OPTIONS,
3163 gettext_noop("Enables logging of recovery-related debugging information."),
3164 gettext_noop("Each level includes all the levels that follow it. The later"
3165 " the level, the fewer messages are sent.")
3167 &trace_recovery_messages,
3169 * client_message_level_options allows too many values, really,
3170 * but it's not worth having a separate options array for this.
3172 LOG, client_message_level_options,
3177 {"track_functions", PGC_SUSET, STATS_COLLECTOR,
3178 gettext_noop("Collects function-level statistics on database activity."),
3181 &pgstat_track_functions,
3182 TRACK_FUNC_OFF, track_function_options,
3187 {"wal_level", PGC_POSTMASTER, WAL_SETTINGS,
3188 gettext_noop("Set the level of information written to the WAL."),
3192 WAL_LEVEL_MINIMAL, wal_level_options,
3197 {"wal_sync_method", PGC_SIGHUP, WAL_SETTINGS,
3198 gettext_noop("Selects the method used for forcing WAL updates to disk."),
3202 DEFAULT_SYNC_METHOD, sync_method_options,
3203 NULL, assign_xlog_sync_method, NULL
3207 {"xmlbinary", PGC_USERSET, CLIENT_CONN_STATEMENT,
3208 gettext_noop("Sets how binary values are to be encoded in XML."),
3212 XMLBINARY_BASE64, xmlbinary_options,
3217 {"xmloption", PGC_USERSET, CLIENT_CONN_STATEMENT,
3218 gettext_noop("Sets whether XML data in implicit parsing and serialization "
3219 "operations is to be considered as documents or content fragments."),
3223 XMLOPTION_CONTENT, xmloption_options,
3228 /* End-of-list marker */
3230 {NULL, 0, 0, NULL, NULL}, NULL, 0, NULL, NULL, NULL, NULL
3234 /******** end of options list ********/
3238 * To allow continued support of obsolete names for GUC variables, we apply
3239 * the following mappings to any unrecognized name. Note that an old name
3240 * should be mapped to a new one only if the new variable has very similar
3241 * semantics to the old.
3243 static const char *const map_old_guc_names[] = {
3244 "sort_mem", "work_mem",
3245 "vacuum_mem", "maintenance_work_mem",
3251 * Actual lookup of variables is done through this single, sorted array.
3253 static struct config_generic **guc_variables;
3255 /* Current number of variables contained in the vector */
3256 static int num_guc_variables;
3258 /* Vector capacity */
3259 static int size_guc_variables;
3262 static bool guc_dirty; /* TRUE if need to do commit/abort work */
3264 static bool reporting_enabled; /* TRUE to enable GUC_REPORT */
3266 static int GUCNestLevel = 0; /* 1 when in main transaction */
3269 static int guc_var_compare(const void *a, const void *b);
3270 static int guc_name_compare(const char *namea, const char *nameb);
3271 static void InitializeOneGUCOption(struct config_generic * gconf);
3272 static void push_old_value(struct config_generic * gconf, GucAction action);
3273 static void ReportGUCOption(struct config_generic * record);
3274 static void ShowGUCConfigOption(const char *name, DestReceiver *dest);
3275 static void ShowAllGUCConfig(DestReceiver *dest);
3276 static char *_ShowOption(struct config_generic * record, bool use_units);
3277 static bool validate_option_array_item(const char *name, const char *value,
3278 bool skipIfNoPermissions);
3282 * Some infrastructure for checking malloc/strdup/realloc calls
3285 guc_malloc(int elevel, size_t size)
3289 data = malloc(size);
3292 (errcode(ERRCODE_OUT_OF_MEMORY),
3293 errmsg("out of memory")));
3298 guc_realloc(int elevel, void *old, size_t size)
3302 data = realloc(old, size);
3305 (errcode(ERRCODE_OUT_OF_MEMORY),
3306 errmsg("out of memory")));
3311 guc_strdup(int elevel, const char *src)
3318 (errcode(ERRCODE_OUT_OF_MEMORY),
3319 errmsg("out of memory")));
3325 * Detect whether strval is referenced anywhere in a GUC string item
3328 string_field_used(struct config_string * conf, char *strval)
3332 if (strval == *(conf->variable) ||
3333 strval == conf->reset_val ||
3334 strval == conf->boot_val)
3336 for (stack = conf->gen.stack; stack; stack = stack->prev)
3338 if (strval == stack->prior.val.stringval ||
3339 strval == stack->masked.val.stringval)
3346 * Support for assigning to a field of a string GUC item. Free the prior
3347 * value if it's not referenced anywhere else in the item (including stacked
3351 set_string_field(struct config_string * conf, char **field, char *newval)
3353 char *oldval = *field;
3355 /* Do the assignment */
3358 /* Free old value if it's not NULL and isn't referenced anymore */
3359 if (oldval && !string_field_used(conf, oldval))
3364 * Detect whether an "extra" struct is referenced anywhere in a GUC item
3367 extra_field_used(struct config_generic * gconf, void *extra)
3371 if (extra == gconf->extra)
3373 switch (gconf->vartype)
3376 if (extra == ((struct config_bool *) gconf)->reset_extra)
3380 if (extra == ((struct config_int *) gconf)->reset_extra)
3384 if (extra == ((struct config_real *) gconf)->reset_extra)
3388 if (extra == ((struct config_string *) gconf)->reset_extra)
3392 if (extra == ((struct config_enum *) gconf)->reset_extra)
3396 for (stack = gconf->stack; stack; stack = stack->prev)
3398 if (extra == stack->prior.extra ||
3399 extra == stack->masked.extra)
3407 * Support for assigning to an "extra" field of a GUC item. Free the prior
3408 * value if it's not referenced anywhere else in the item (including stacked
3412 set_extra_field(struct config_generic * gconf, void **field, void *newval)
3414 void *oldval = *field;
3416 /* Do the assignment */
3419 /* Free old value if it's not NULL and isn't referenced anymore */
3420 if (oldval && !extra_field_used(gconf, oldval))
3425 * Support for copying a variable's active value into a stack entry.
3426 * The "extra" field associated with the active value is copied, too.
3428 * NB: be sure stringval and extra fields of a new stack entry are
3429 * initialized to NULL before this is used, else we'll try to free() them.
3432 set_stack_value(struct config_generic * gconf, config_var_value *val)
3434 switch (gconf->vartype)
3438 *((struct config_bool *) gconf)->variable;
3442 *((struct config_int *) gconf)->variable;
3446 *((struct config_real *) gconf)->variable;
3449 set_string_field((struct config_string *) gconf,
3450 &(val->val.stringval),
3451 *((struct config_string *) gconf)->variable);
3455 *((struct config_enum *) gconf)->variable;
3458 set_extra_field(gconf, &(val->extra), gconf->extra);
3462 * Support for discarding a no-longer-needed value in a stack entry.
3463 * The "extra" field associated with the stack entry is cleared, too.
3466 discard_stack_value(struct config_generic * gconf, config_var_value *val)
3468 switch (gconf->vartype)
3474 /* no need to do anything */
3477 set_string_field((struct config_string *) gconf,
3478 &(val->val.stringval),
3482 set_extra_field(gconf, &(val->extra), NULL);
3487 * Fetch the sorted array pointer (exported for help_config.c's use ONLY)
3489 struct config_generic **
3490 get_guc_variables(void)
3492 return guc_variables;
3497 * Build the sorted array. This is split out so that it could be
3498 * re-executed after startup (eg, we could allow loadable modules to
3499 * add vars, and then we'd need to re-sort).
3502 build_guc_variables(void)
3506 struct config_generic **guc_vars;
3509 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
3511 struct config_bool *conf = &ConfigureNamesBool[i];
3513 /* Rather than requiring vartype to be filled in by hand, do this: */
3514 conf->gen.vartype = PGC_BOOL;
3518 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
3520 struct config_int *conf = &ConfigureNamesInt[i];
3522 conf->gen.vartype = PGC_INT;
3526 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
3528 struct config_real *conf = &ConfigureNamesReal[i];
3530 conf->gen.vartype = PGC_REAL;
3534 for (i = 0; ConfigureNamesString[i].gen.name; i++)
3536 struct config_string *conf = &ConfigureNamesString[i];
3538 conf->gen.vartype = PGC_STRING;
3542 for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
3544 struct config_enum *conf = &ConfigureNamesEnum[i];
3546 conf->gen.vartype = PGC_ENUM;
3551 * Create table with 20% slack
3553 size_vars = num_vars + num_vars / 4;
3555 guc_vars = (struct config_generic **)
3556 guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
3560 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
3561 guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
3563 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
3564 guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
3566 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
3567 guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
3569 for (i = 0; ConfigureNamesString[i].gen.name; i++)
3570 guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
3572 for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
3573 guc_vars[num_vars++] = &ConfigureNamesEnum[i].gen;
3576 free(guc_variables);
3577 guc_variables = guc_vars;
3578 num_guc_variables = num_vars;
3579 size_guc_variables = size_vars;
3580 qsort((void *) guc_variables, num_guc_variables,
3581 sizeof(struct config_generic *), guc_var_compare);
3585 * Add a new GUC variable to the list of known variables. The
3586 * list is expanded if needed.
3589 add_guc_variable(struct config_generic * var, int elevel)
3591 if (num_guc_variables + 1 >= size_guc_variables)
3594 * Increase the vector by 25%
3596 int size_vars = size_guc_variables + size_guc_variables / 4;
3597 struct config_generic **guc_vars;
3602 guc_vars = (struct config_generic **)
3603 guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
3607 guc_vars = (struct config_generic **)
3608 guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
3611 if (guc_vars == NULL)
3612 return false; /* out of memory */
3614 guc_variables = guc_vars;
3615 size_guc_variables = size_vars;
3617 guc_variables[num_guc_variables++] = var;
3618 qsort((void *) guc_variables, num_guc_variables,
3619 sizeof(struct config_generic *), guc_var_compare);
3624 * Create and add a placeholder variable. It's presumed to belong
3625 * to a valid custom variable class at this point.
3627 static struct config_generic *
3628 add_placeholder_variable(const char *name, int elevel)
3630 size_t sz = sizeof(struct config_string) + sizeof(char *);
3631 struct config_string *var;
3632 struct config_generic *gen;
3634 var = (struct config_string *) guc_malloc(elevel, sz);
3640 gen->name = guc_strdup(elevel, name);
3641 if (gen->name == NULL)
3647 gen->context = PGC_USERSET;
3648 gen->group = CUSTOM_OPTIONS;
3649 gen->short_desc = "GUC placeholder variable";
3650 gen->flags = GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_CUSTOM_PLACEHOLDER;
3651 gen->vartype = PGC_STRING;
3654 * The char* is allocated at the end of the struct since we have no
3655 * 'static' place to point to. Note that the current value, as well as
3656 * the boot and reset values, start out NULL.
3658 var->variable = (char **) (var + 1);
3660 if (!add_guc_variable((struct config_generic *) var, elevel))
3662 free((void *) gen->name);
3671 * Detect whether the portion of "name" before dotPos matches any custom
3672 * variable class name listed in custom_var_classes. The latter must be
3673 * formatted the way that assign_custom_variable_classes does it, ie,
3674 * no whitespace. NULL is valid for custom_var_classes.
3677 is_custom_class(const char *name, int dotPos, const char *custom_var_classes)
3679 bool result = false;
3680 const char *ccs = custom_var_classes;
3684 const char *start = ccs;
3690 if (c == '\0' || c == ',')
3692 if (dotPos == ccs - start && strncmp(start, name, dotPos) == 0)
3707 * Look up option NAME. If it exists, return a pointer to its record,
3708 * else return NULL. If create_placeholders is TRUE, we'll create a
3709 * placeholder record for a valid-looking custom variable name.
3711 static struct config_generic *
3712 find_option(const char *name, bool create_placeholders, int elevel)
3714 const char **key = &name;
3715 struct config_generic **res;
3721 * By equating const char ** with struct config_generic *, we are assuming
3722 * the name field is first in config_generic.
3724 res = (struct config_generic **) bsearch((void *) &key,
3725 (void *) guc_variables,
3727 sizeof(struct config_generic *),
3733 * See if the name is an obsolete name for a variable. We assume that the
3734 * set of supported old names is short enough that a brute-force search is
3737 for (i = 0; map_old_guc_names[i] != NULL; i += 2)
3739 if (guc_name_compare(name, map_old_guc_names[i]) == 0)
3740 return find_option(map_old_guc_names[i + 1], false, elevel);
3743 if (create_placeholders)
3746 * Check if the name is qualified, and if so, check if the qualifier
3747 * matches any custom variable class. If so, add a placeholder.
3749 const char *dot = strchr(name, GUC_QUALIFIER_SEPARATOR);
3752 is_custom_class(name, dot - name, custom_variable_classes))
3753 return add_placeholder_variable(name, elevel);
3762 * comparator for qsorting and bsearching guc_variables array
3765 guc_var_compare(const void *a, const void *b)
3767 struct config_generic *confa = *(struct config_generic **) a;
3768 struct config_generic *confb = *(struct config_generic **) b;
3770 return guc_name_compare(confa->name, confb->name);
3774 * the bare comparison function for GUC names
3777 guc_name_compare(const char *namea, const char *nameb)
3780 * The temptation to use strcasecmp() here must be resisted, because the
3781 * array ordering has to remain stable across setlocale() calls. So, build
3782 * our own with a simple ASCII-only downcasing.
3784 while (*namea && *nameb)
3786 char cha = *namea++;
3787 char chb = *nameb++;
3789 if (cha >= 'A' && cha <= 'Z')
3791 if (chb >= 'A' && chb <= 'Z')
3797 return 1; /* a is longer */
3799 return -1; /* b is longer */
3805 * Initialize GUC options during program startup.
3807 * Note that we cannot read the config file yet, since we have not yet
3808 * processed command-line switches.
3811 InitializeGUCOptions(void)
3818 * Before log_line_prefix could possibly receive a nonempty setting, make
3819 * sure that timezone processing is minimally alive (see elog.c).
3821 pg_timezone_pre_initialize();
3824 * Build sorted array of all GUC variables.
3826 build_guc_variables();
3829 * Load all variables with their compiled-in defaults, and initialize
3830 * status fields as needed.
3832 for (i = 0; i < num_guc_variables; i++)
3834 InitializeOneGUCOption(guc_variables[i]);
3839 reporting_enabled = false;
3842 * Prevent any attempt to override the transaction modes from
3843 * non-interactive sources.
3845 SetConfigOption("transaction_isolation", "default",
3846 PGC_POSTMASTER, PGC_S_OVERRIDE);
3847 SetConfigOption("transaction_read_only", "no",
3848 PGC_POSTMASTER, PGC_S_OVERRIDE);
3849 SetConfigOption("transaction_deferrable", "no",
3850 PGC_POSTMASTER, PGC_S_OVERRIDE);
3853 * For historical reasons, some GUC parameters can receive defaults from
3854 * environment variables. Process those settings. NB: if you add or
3855 * remove anything here, see also ProcessConfigFile().
3858 env = getenv("PGPORT");
3860 SetConfigOption("port", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3862 env = getenv("PGDATESTYLE");
3864 SetConfigOption("datestyle", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3866 env = getenv("PGCLIENTENCODING");
3868 SetConfigOption("client_encoding", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3871 * rlimit isn't exactly an "environment variable", but it behaves about
3872 * the same. If we can identify the platform stack depth rlimit, increase
3873 * default stack depth setting up to whatever is safe (but at most 2MB).
3875 stack_rlimit = get_stack_depth_rlimit();
3876 if (stack_rlimit > 0)
3878 long new_limit = (stack_rlimit - STACK_DEPTH_SLOP) / 1024L;
3880 if (new_limit > 100)
3884 new_limit = Min(new_limit, 2048);
3885 sprintf(limbuf, "%ld", new_limit);
3886 SetConfigOption("max_stack_depth", limbuf,
3887 PGC_POSTMASTER, PGC_S_ENV_VAR);
3893 * Initialize one GUC option variable to its compiled-in default.
3895 * Note: the reason for calling check_hooks is not that we think the boot_val
3896 * might fail, but that the hooks might wish to compute an "extra" struct.
3899 InitializeOneGUCOption(struct config_generic * gconf)
3902 gconf->reset_source = PGC_S_DEFAULT;
3903 gconf->source = PGC_S_DEFAULT;
3904 gconf->stack = NULL;
3905 gconf->extra = NULL;
3906 gconf->sourcefile = NULL;
3907 gconf->sourceline = 0;
3909 switch (gconf->vartype)
3913 struct config_bool *conf = (struct config_bool *) gconf;
3914 bool newval = conf->boot_val;
3917 if (!call_bool_check_hook(conf, &newval, &extra,
3918 PGC_S_DEFAULT, LOG))
3919 elog(FATAL, "failed to initialize %s to %d",
3920 conf->gen.name, (int) newval);
3921 if (conf->assign_hook)
3922 (*conf->assign_hook) (newval, extra);
3923 *conf->variable = conf->reset_val = newval;
3924 conf->gen.extra = conf->reset_extra = extra;
3929 struct config_int *conf = (struct config_int *) gconf;
3930 int newval = conf->boot_val;
3933 Assert(newval >= conf->min);
3934 Assert(newval <= conf->max);
3935 if (!call_int_check_hook(conf, &newval, &extra,
3936 PGC_S_DEFAULT, LOG))
3937 elog(FATAL, "failed to initialize %s to %d",
3938 conf->gen.name, newval);
3939 if (conf->assign_hook)
3940 (*conf->assign_hook) (newval, extra);
3941 *conf->variable = conf->reset_val = newval;
3942 conf->gen.extra = conf->reset_extra = extra;
3947 struct config_real *conf = (struct config_real *) gconf;
3948 double newval = conf->boot_val;
3951 Assert(newval >= conf->min);
3952 Assert(newval <= conf->max);
3953 if (!call_real_check_hook(conf, &newval, &extra,
3954 PGC_S_DEFAULT, LOG))
3955 elog(FATAL, "failed to initialize %s to %g",
3956 conf->gen.name, newval);
3957 if (conf->assign_hook)
3958 (*conf->assign_hook) (newval, extra);
3959 *conf->variable = conf->reset_val = newval;
3960 conf->gen.extra = conf->reset_extra = extra;
3965 struct config_string *conf = (struct config_string *) gconf;
3969 /* non-NULL boot_val must always get strdup'd */
3970 if (conf->boot_val != NULL)
3971 newval = guc_strdup(FATAL, conf->boot_val);
3975 if (!call_string_check_hook(conf, &newval, &extra,
3976 PGC_S_DEFAULT, LOG))
3977 elog(FATAL, "failed to initialize %s to \"%s\"",
3978 conf->gen.name, newval ? newval : "");
3979 if (conf->assign_hook)
3980 (*conf->assign_hook) (newval, extra);
3981 *conf->variable = conf->reset_val = newval;
3982 conf->gen.extra = conf->reset_extra = extra;
3987 struct config_enum *conf = (struct config_enum *) gconf;
3988 int newval = conf->boot_val;
3991 if (!call_enum_check_hook(conf, &newval, &extra,
3992 PGC_S_DEFAULT, LOG))
3993 elog(FATAL, "failed to initialize %s to %d",
3994 conf->gen.name, newval);
3995 if (conf->assign_hook)
3996 (*conf->assign_hook) (newval, extra);
3997 *conf->variable = conf->reset_val = newval;
3998 conf->gen.extra = conf->reset_extra = extra;
4006 * Select the configuration files and data directory to be used, and
4007 * do the initial read of postgresql.conf.
4009 * This is called after processing command-line switches.
4010 * userDoption is the -D switch value if any (NULL if unspecified).
4011 * progname is just for use in error messages.
4013 * Returns true on success; on failure, prints a suitable error message
4014 * to stderr and returns false.
4017 SelectConfigFiles(const char *userDoption, const char *progname)
4021 struct stat stat_buf;
4023 /* configdir is -D option, or $PGDATA if no -D */
4025 configdir = make_absolute_path(userDoption);
4027 configdir = make_absolute_path(getenv("PGDATA"));
4030 * Find the configuration file: if config_file was specified on the
4031 * command line, use it, else use configdir/postgresql.conf. In any case
4032 * ensure the result is an absolute path, so that it will be interpreted
4033 * the same way by future backends.
4036 fname = make_absolute_path(ConfigFileName);
4039 fname = guc_malloc(FATAL,
4040 strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
4041 sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
4045 write_stderr("%s does not know where to find the server configuration file.\n"
4046 "You must specify the --config-file or -D invocation "
4047 "option or set the PGDATA environment variable.\n",
4053 * Set the ConfigFileName GUC variable to its final value, ensuring that
4054 * it can't be overridden later.
4056 SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4060 * Now read the config file for the first time.
4062 if (stat(ConfigFileName, &stat_buf) != 0)
4064 write_stderr("%s cannot access the server configuration file \"%s\": %s\n",
4065 progname, ConfigFileName, strerror(errno));
4069 ProcessConfigFile(PGC_POSTMASTER);
4072 * If the data_directory GUC variable has been set, use that as DataDir;
4073 * otherwise use configdir if set; else punt.
4075 * Note: SetDataDir will copy and absolute-ize its argument, so we don't
4079 SetDataDir(data_directory);
4081 SetDataDir(configdir);
4084 write_stderr("%s does not know where to find the database system data.\n"
4085 "This can be specified as \"data_directory\" in \"%s\", "
4086 "or by the -D invocation option, or by the "
4087 "PGDATA environment variable.\n",
4088 progname, ConfigFileName);
4093 * Reflect the final DataDir value back into the data_directory GUC var.
4094 * (If you are wondering why we don't just make them a single variable,
4095 * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
4096 * child backends specially. XXX is that still true? Given that we now
4097 * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
4098 * DataDir in advance.)
4100 SetConfigOption("data_directory", DataDir, PGC_POSTMASTER, PGC_S_OVERRIDE);
4103 * Figure out where pg_hba.conf is, and make sure the path is absolute.
4106 fname = make_absolute_path(HbaFileName);
4109 fname = guc_malloc(FATAL,
4110 strlen(configdir) + strlen(HBA_FILENAME) + 2);
4111 sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
4115 write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
4116 "This can be specified as \"hba_file\" in \"%s\", "
4117 "or by the -D invocation option, or by the "
4118 "PGDATA environment variable.\n",
4119 progname, ConfigFileName);
4122 SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4126 * Likewise for pg_ident.conf.
4129 fname = make_absolute_path(IdentFileName);
4132 fname = guc_malloc(FATAL,
4133 strlen(configdir) + strlen(IDENT_FILENAME) + 2);
4134 sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
4138 write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
4139 "This can be specified as \"ident_file\" in \"%s\", "
4140 "or by the -D invocation option, or by the "
4141 "PGDATA environment variable.\n",
4142 progname, ConfigFileName);
4145 SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4155 * Reset all options to their saved default values (implements RESET ALL)
4158 ResetAllOptions(void)
4162 for (i = 0; i < num_guc_variables; i++)
4164 struct config_generic *gconf = guc_variables[i];
4166 /* Don't reset non-SET-able values */
4167 if (gconf->context != PGC_SUSET &&
4168 gconf->context != PGC_USERSET)
4170 /* Don't reset if special exclusion from RESET ALL */
4171 if (gconf->flags & GUC_NO_RESET_ALL)
4173 /* No need to reset if wasn't SET */
4174 if (gconf->source <= PGC_S_OVERRIDE)
4177 /* Save old value to support transaction abort */
4178 push_old_value(gconf, GUC_ACTION_SET);
4180 switch (gconf->vartype)
4184 struct config_bool *conf = (struct config_bool *) gconf;
4186 if (conf->assign_hook)
4187 (*conf->assign_hook) (conf->reset_val,
4189 *conf->variable = conf->reset_val;
4190 set_extra_field(&conf->gen, &conf->gen.extra,
4196 struct config_int *conf = (struct config_int *) gconf;
4198 if (conf->assign_hook)
4199 (*conf->assign_hook) (conf->reset_val,
4201 *conf->variable = conf->reset_val;
4202 set_extra_field(&conf->gen, &conf->gen.extra,
4208 struct config_real *conf = (struct config_real *) gconf;
4210 if (conf->assign_hook)
4211 (*conf->assign_hook) (conf->reset_val,
4213 *conf->variable = conf->reset_val;
4214 set_extra_field(&conf->gen, &conf->gen.extra,
4220 struct config_string *conf = (struct config_string *) gconf;
4222 if (conf->assign_hook)
4223 (*conf->assign_hook) (conf->reset_val,
4225 set_string_field(conf, conf->variable, conf->reset_val);
4226 set_extra_field(&conf->gen, &conf->gen.extra,
4232 struct config_enum *conf = (struct config_enum *) gconf;
4234 if (conf->assign_hook)
4235 (*conf->assign_hook) (conf->reset_val,
4237 *conf->variable = conf->reset_val;
4238 set_extra_field(&conf->gen, &conf->gen.extra,
4244 gconf->source = gconf->reset_source;
4246 if (gconf->flags & GUC_REPORT)
4247 ReportGUCOption(gconf);
4254 * Push previous state during transactional assignment to a GUC variable.
4257 push_old_value(struct config_generic * gconf, GucAction action)
4261 /* If we're not inside a nest level, do nothing */
4262 if (GUCNestLevel == 0)
4265 /* Do we already have a stack entry of the current nest level? */
4266 stack = gconf->stack;
4267 if (stack && stack->nest_level >= GUCNestLevel)
4269 /* Yes, so adjust its state if necessary */
4270 Assert(stack->nest_level == GUCNestLevel);
4273 case GUC_ACTION_SET:
4274 /* SET overrides any prior action at same nest level */
4275 if (stack->state == GUC_SET_LOCAL)
4277 /* must discard old masked value */
4278 discard_stack_value(gconf, &stack->masked);
4280 stack->state = GUC_SET;
4282 case GUC_ACTION_LOCAL:
4283 if (stack->state == GUC_SET)
4285 /* SET followed by SET LOCAL, remember SET's value */
4286 set_stack_value(gconf, &stack->masked);
4287 stack->state = GUC_SET_LOCAL;
4289 /* in all other cases, no change to stack entry */
4291 case GUC_ACTION_SAVE:
4292 /* Could only have a prior SAVE of same variable */
4293 Assert(stack->state == GUC_SAVE);
4296 Assert(guc_dirty); /* must be set already */
4301 * Push a new stack entry
4303 * We keep all the stack entries in TopTransactionContext for simplicity.
4305 stack = (GucStack *) MemoryContextAllocZero(TopTransactionContext,
4308 stack->prev = gconf->stack;
4309 stack->nest_level = GUCNestLevel;
4312 case GUC_ACTION_SET:
4313 stack->state = GUC_SET;
4315 case GUC_ACTION_LOCAL:
4316 stack->state = GUC_LOCAL;
4318 case GUC_ACTION_SAVE:
4319 stack->state = GUC_SAVE;
4322 stack->source = gconf->source;
4323 set_stack_value(gconf, &stack->prior);
4325 gconf->stack = stack;
4327 /* Ensure we remember to pop at end of xact */
4333 * Do GUC processing at main transaction start.
4339 * The nest level should be 0 between transactions; if it isn't, somebody
4340 * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
4341 * throw a warning but make no other effort to clean up.
4343 if (GUCNestLevel != 0)
4344 elog(WARNING, "GUC nest level = %d at transaction start",
4350 * Enter a new nesting level for GUC values. This is called at subtransaction
4351 * start and when entering a function that has proconfig settings. NOTE that
4352 * we must not risk error here, else subtransaction start will be unhappy.
4355 NewGUCNestLevel(void)
4357 return ++GUCNestLevel;
4361 * Do GUC processing at transaction or subtransaction commit or abort, or
4362 * when exiting a function that has proconfig settings. (The name is thus
4363 * a bit of a misnomer; perhaps it should be ExitGUCNestLevel or some such.)
4364 * During abort, we discard all GUC settings that were applied at nesting
4365 * levels >= nestLevel. nestLevel == 1 corresponds to the main transaction.
4368 AtEOXact_GUC(bool isCommit, int nestLevel)
4374 * Note: it's possible to get here with GUCNestLevel == nestLevel-1 during
4375 * abort, if there is a failure during transaction start before
4376 * AtStart_GUC is called.
4378 Assert(nestLevel > 0 &&
4379 (nestLevel <= GUCNestLevel ||
4380 (nestLevel == GUCNestLevel + 1 && !isCommit)));
4382 /* Quick exit if nothing's changed in this transaction */
4385 GUCNestLevel = nestLevel - 1;
4389 still_dirty = false;
4390 for (i = 0; i < num_guc_variables; i++)
4392 struct config_generic *gconf = guc_variables[i];
4396 * Process and pop each stack entry within the nest level. To
4397 * simplify fmgr_security_definer(), we allow failure exit from a
4398 * function-with-SET-options to be recovered at the surrounding
4399 * transaction or subtransaction abort; so there could be more than
4400 * one stack entry to pop.
4402 while ((stack = gconf->stack) != NULL &&
4403 stack->nest_level >= nestLevel)
4405 GucStack *prev = stack->prev;
4406 bool restorePrior = false;
4407 bool restoreMasked = false;
4411 * In this next bit, if we don't set either restorePrior or
4412 * restoreMasked, we must "discard" any unwanted fields of the
4413 * stack entries to avoid leaking memory. If we do set one of
4414 * those flags, unused fields will be cleaned up after restoring.
4416 if (!isCommit) /* if abort, always restore prior value */
4417 restorePrior = true;
4418 else if (stack->state == GUC_SAVE)
4419 restorePrior = true;
4420 else if (stack->nest_level == 1)
4422 /* transaction commit */
4423 if (stack->state == GUC_SET_LOCAL)
4424 restoreMasked = true;
4425 else if (stack->state == GUC_SET)
4427 /* we keep the current active value */
4428 discard_stack_value(gconf, &stack->prior);
4430 else /* must be GUC_LOCAL */
4431 restorePrior = true;
4433 else if (prev == NULL ||
4434 prev->nest_level < stack->nest_level - 1)
4436 /* decrement entry's level and do not pop it */
4437 stack->nest_level--;
4443 * We have to merge this stack entry into prev. See README for
4444 * discussion of this bit.
4446 switch (stack->state)
4449 Assert(false); /* can't get here */
4452 /* next level always becomes SET */
4453 discard_stack_value(gconf, &stack->prior);
4454 if (prev->state == GUC_SET_LOCAL)
4455 discard_stack_value(gconf, &prev->masked);
4456 prev->state = GUC_SET;
4460 if (prev->state == GUC_SET)
4462 /* LOCAL migrates down */
4463 prev->masked = stack->prior;
4464 prev->state = GUC_SET_LOCAL;
4468 /* else just forget this stack level */
4469 discard_stack_value(gconf, &stack->prior);
4474 /* prior state at this level no longer wanted */
4475 discard_stack_value(gconf, &stack->prior);
4476 /* copy down the masked state */
4477 if (prev->state == GUC_SET_LOCAL)
4478 discard_stack_value(gconf, &prev->masked);
4479 prev->masked = stack->masked;
4480 prev->state = GUC_SET_LOCAL;
4487 if (restorePrior || restoreMasked)
4489 /* Perform appropriate restoration of the stacked value */
4490 config_var_value newvalue;
4491 GucSource newsource;
4495 newvalue = stack->masked;
4496 newsource = PGC_S_SESSION;
4500 newvalue = stack->prior;
4501 newsource = stack->source;
4504 switch (gconf->vartype)
4508 struct config_bool *conf = (struct config_bool *) gconf;
4509 bool newval = newvalue.val.boolval;
4510 void *newextra = newvalue.extra;
4512 if (*conf->variable != newval ||
4513 conf->gen.extra != newextra)
4515 if (conf->assign_hook)
4516 (*conf->assign_hook) (newval, newextra);
4517 *conf->variable = newval;
4518 set_extra_field(&conf->gen, &conf->gen.extra,
4526 struct config_int *conf = (struct config_int *) gconf;
4527 int newval = newvalue.val.intval;
4528 void *newextra = newvalue.extra;
4530 if (*conf->variable != newval ||
4531 conf->gen.extra != newextra)
4533 if (conf->assign_hook)
4534 (*conf->assign_hook) (newval, newextra);
4535 *conf->variable = newval;
4536 set_extra_field(&conf->gen, &conf->gen.extra,
4544 struct config_real *conf = (struct config_real *) gconf;
4545 double newval = newvalue.val.realval;
4546 void *newextra = newvalue.extra;
4548 if (*conf->variable != newval ||
4549 conf->gen.extra != newextra)
4551 if (conf->assign_hook)
4552 (*conf->assign_hook) (newval, newextra);
4553 *conf->variable = newval;
4554 set_extra_field(&conf->gen, &conf->gen.extra,
4562 struct config_string *conf = (struct config_string *) gconf;
4563 char *newval = newvalue.val.stringval;
4564 void *newextra = newvalue.extra;
4566 if (*conf->variable != newval ||
4567 conf->gen.extra != newextra)
4569 if (conf->assign_hook)
4570 (*conf->assign_hook) (newval, newextra);
4571 set_string_field(conf, conf->variable, newval);
4572 set_extra_field(&conf->gen, &conf->gen.extra,
4578 * Release stacked values if not used anymore. We
4579 * could use discard_stack_value() here, but since
4580 * we have type-specific code anyway, might as
4583 set_string_field(conf, &stack->prior.val.stringval, NULL);
4584 set_string_field(conf, &stack->masked.val.stringval, NULL);
4589 struct config_enum *conf = (struct config_enum *) gconf;
4590 int newval = newvalue.val.enumval;
4591 void *newextra = newvalue.extra;
4593 if (*conf->variable != newval ||
4594 conf->gen.extra != newextra)
4596 if (conf->assign_hook)
4597 (*conf->assign_hook) (newval, newextra);
4598 *conf->variable = newval;
4599 set_extra_field(&conf->gen, &conf->gen.extra,
4608 * Release stacked extra values if not used anymore.
4610 set_extra_field(gconf, &(stack->prior.extra), NULL);
4611 set_extra_field(gconf, &(stack->masked.extra), NULL);
4613 gconf->source = newsource;
4616 /* Finish popping the state stack */
4617 gconf->stack = prev;
4620 /* Report new value if we changed it */
4621 if (changed && (gconf->flags & GUC_REPORT))
4622 ReportGUCOption(gconf);
4623 } /* end of stack-popping loop */
4629 /* If there are no remaining stack entries, we can reset guc_dirty */
4630 guc_dirty = still_dirty;
4632 /* Update nesting level */
4633 GUCNestLevel = nestLevel - 1;
4638 * Start up automatic reporting of changes to variables marked GUC_REPORT.
4639 * This is executed at completion of backend startup.
4642 BeginReportingGUCOptions(void)
4647 * Don't do anything unless talking to an interactive frontend of protocol
4650 if (whereToSendOutput != DestRemote ||
4651 PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
4654 reporting_enabled = true;
4656 /* Transmit initial values of interesting variables */
4657 for (i = 0; i < num_guc_variables; i++)
4659 struct config_generic *conf = guc_variables[i];
4661 if (conf->flags & GUC_REPORT)
4662 ReportGUCOption(conf);
4667 * ReportGUCOption: if appropriate, transmit option value to frontend
4670 ReportGUCOption(struct config_generic * record)
4672 if (reporting_enabled && (record->flags & GUC_REPORT))
4674 char *val = _ShowOption(record, false);
4675 StringInfoData msgbuf;
4677 pq_beginmessage(&msgbuf, 'S');
4678 pq_sendstring(&msgbuf, record->name);
4679 pq_sendstring(&msgbuf, val);
4680 pq_endmessage(&msgbuf);
4687 * Try to parse value as an integer. The accepted formats are the
4688 * usual decimal, octal, or hexadecimal formats, optionally followed by
4689 * a unit name if "flags" indicates a unit is allowed.
4691 * If the string parses okay, return true, else false.
4692 * If okay and result is not NULL, return the value in *result.
4693 * If not okay and hintmsg is not NULL, *hintmsg is set to a suitable
4694 * HINT message, or NULL if no hint provided.
4697 parse_int(const char *value, int *result, int flags, const char **hintmsg)
4702 /* To suppress compiler warnings, always set output params */
4708 /* We assume here that int64 is at least as wide as long */
4710 val = strtol(value, &endptr, 0);
4712 if (endptr == value)
4713 return false; /* no HINT for integer syntax error */
4715 if (errno == ERANGE || val != (int64) ((int32) val))
4718 *hintmsg = gettext_noop("Value exceeds integer range.");
4722 /* allow whitespace between integer and unit */
4723 while (isspace((unsigned char) *endptr))
4726 /* Handle possible unit */
4727 if (*endptr != '\0')
4730 * Note: the multiple-switch coding technique here is a bit tedious,
4731 * but seems necessary to avoid intermediate-value overflows.
4733 if (flags & GUC_UNIT_MEMORY)
4735 /* Set hint for use if no match or trailing garbage */
4737 *hintmsg = gettext_noop("Valid units for this parameter are \"kB\", \"MB\", and \"GB\".");
4739 #if BLCKSZ < 1024 || BLCKSZ > (1024*1024)
4740 #error BLCKSZ must be between 1KB and 1MB
4742 #if XLOG_BLCKSZ < 1024 || XLOG_BLCKSZ > (1024*1024)
4743 #error XLOG_BLCKSZ must be between 1KB and 1MB
4746 if (strncmp(endptr, "kB", 2) == 0)
4749 switch (flags & GUC_UNIT_MEMORY)
4751 case GUC_UNIT_BLOCKS:
4752 val /= (BLCKSZ / 1024);
4754 case GUC_UNIT_XBLOCKS:
4755 val /= (XLOG_BLCKSZ / 1024);
4759 else if (strncmp(endptr, "MB", 2) == 0)
4762 switch (flags & GUC_UNIT_MEMORY)
4767 case GUC_UNIT_BLOCKS:
4768 val *= KB_PER_MB / (BLCKSZ / 1024);
4770 case GUC_UNIT_XBLOCKS:
4771 val *= KB_PER_MB / (XLOG_BLCKSZ / 1024);
4775 else if (strncmp(endptr, "GB", 2) == 0)
4778 switch (flags & GUC_UNIT_MEMORY)
4783 case GUC_UNIT_BLOCKS:
4784 val *= KB_PER_GB / (BLCKSZ / 1024);
4786 case GUC_UNIT_XBLOCKS:
4787 val *= KB_PER_GB / (XLOG_BLCKSZ / 1024);
4792 else if (flags & GUC_UNIT_TIME)
4794 /* Set hint for use if no match or trailing garbage */
4796 *hintmsg = gettext_noop("Valid units for this parameter are \"ms\", \"s\", \"min\", \"h\", and \"d\".");
4798 if (strncmp(endptr, "ms", 2) == 0)
4801 switch (flags & GUC_UNIT_TIME)
4811 else if (strncmp(endptr, "s", 1) == 0)
4814 switch (flags & GUC_UNIT_TIME)
4824 else if (strncmp(endptr, "min", 3) == 0)
4827 switch (flags & GUC_UNIT_TIME)
4837 else if (strncmp(endptr, "h", 1) == 0)
4840 switch (flags & GUC_UNIT_TIME)
4853 else if (strncmp(endptr, "d", 1) == 0)
4856 switch (flags & GUC_UNIT_TIME)
4871 /* allow whitespace after unit */
4872 while (isspace((unsigned char) *endptr))
4875 if (*endptr != '\0')
4876 return false; /* appropriate hint, if any, already set */
4878 /* Check for overflow due to units conversion */
4879 if (val != (int64) ((int32) val))
4882 *hintmsg = gettext_noop("Value exceeds integer range.");
4888 *result = (int) val;
4895 * Try to parse value as a floating point number in the usual format.
4896 * If the string parses okay, return true, else false.
4897 * If okay and result is not NULL, return the value in *result.
4900 parse_real(const char *value, double *result)
4906 *result = 0; /* suppress compiler warning */
4909 val = strtod(value, &endptr);
4910 if (endptr == value || errno == ERANGE)
4913 /* allow whitespace after number */
4914 while (isspace((unsigned char) *endptr))
4916 if (*endptr != '\0')
4926 * Lookup the name for an enum option with the selected value.
4927 * Should only ever be called with known-valid values, so throws
4928 * an elog(ERROR) if the enum option is not found.
4930 * The returned string is a pointer to static data and not
4931 * allocated for modification.
4934 config_enum_lookup_by_value(struct config_enum * record, int val)
4936 const struct config_enum_entry *entry;
4938 for (entry = record->options; entry && entry->name; entry++)
4940 if (entry->val == val)
4944 elog(ERROR, "could not find enum option %d for %s",
4945 val, record->gen.name);
4946 return NULL; /* silence compiler */
4951 * Lookup the value for an enum option with the selected name
4952 * (case-insensitive).
4953 * If the enum option is found, sets the retval value and returns
4954 * true. If it's not found, return FALSE and retval is set to 0.
4957 config_enum_lookup_by_name(struct config_enum * record, const char *value,
4960 const struct config_enum_entry *entry;
4962 for (entry = record->options; entry && entry->name; entry++)
4964 if (pg_strcasecmp(value, entry->name) == 0)
4966 *retval = entry->val;
4977 * Return a list of all available options for an enum, excluding
4978 * hidden ones, separated by the given separator.
4979 * If prefix is non-NULL, it is added before the first enum value.
4980 * If suffix is non-NULL, it is added to the end of the string.
4983 config_enum_get_options(struct config_enum * record, const char *prefix,
4984 const char *suffix, const char *separator)
4986 const struct config_enum_entry *entry;
4987 StringInfoData retstr;
4990 initStringInfo(&retstr);
4991 appendStringInfoString(&retstr, prefix);
4993 seplen = strlen(separator);
4994 for (entry = record->options; entry && entry->name; entry++)
4998 appendStringInfoString(&retstr, entry->name);
4999 appendBinaryStringInfo(&retstr, separator, seplen);
5004 * All the entries may have been hidden, leaving the string empty if no
5005 * prefix was given. This indicates a broken GUC setup, since there is no
5006 * use for an enum without any values, so we just check to make sure we
5007 * don't write to invalid memory instead of actually trying to do
5008 * something smart with it.
5010 if (retstr.len >= seplen)
5012 /* Replace final separator */
5013 retstr.data[retstr.len - seplen] = '\0';
5014 retstr.len -= seplen;
5017 appendStringInfoString(&retstr, suffix);
5024 * Sets option `name' to given value. The value should be a string
5025 * which is going to be parsed and converted to the appropriate data
5026 * type. The context and source parameters indicate in which context this
5027 * function is being called so it can apply the access restrictions
5030 * If value is NULL, set the option to its default value (normally the
5031 * reset_val, but if source == PGC_S_DEFAULT we instead use the boot_val).
5033 * action indicates whether to set the value globally in the session, locally
5034 * to the current top transaction, or just for the duration of a function call.
5036 * If changeVal is false then don't really set the option but do all
5037 * the checks to see if it would work.
5039 * If there is an error (non-existing option, invalid value) then an
5040 * ereport(ERROR) is thrown *unless* this is called in a context where we
5041 * don't want to ereport (currently, startup or SIGHUP config file reread).
5042 * In that case we write a suitable error message via ereport(LOG) and
5043 * return false. This is working around the deficiencies in the ereport
5044 * mechanism, so don't blame me. In all other cases, the function
5045 * returns true, including cases where the input is valid but we chose
5046 * not to apply it because of context or source-priority considerations.
5048 * See also SetConfigOption for an external interface.
5051 set_config_option(const char *name, const char *value,
5052 GucContext context, GucSource source,
5053 GucAction action, bool changeVal)
5055 struct config_generic *record;
5057 bool prohibitValueChange = false;
5060 if (context == PGC_SIGHUP || source == PGC_S_DEFAULT)
5063 * To avoid cluttering the log, only the postmaster bleats loudly
5064 * about problems with the config file.
5066 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
5068 else if (source == PGC_S_DATABASE || source == PGC_S_USER ||
5069 source == PGC_S_DATABASE_USER)
5074 record = find_option(name, true, elevel);
5078 (errcode(ERRCODE_UNDEFINED_OBJECT),
5079 errmsg("unrecognized configuration parameter \"%s\"", name)));
5084 * If source is postgresql.conf, mark the found record with
5085 * GUC_IS_IN_FILE. This is for the convenience of ProcessConfigFile. Note
5086 * that we do it even if changeVal is false, since ProcessConfigFile wants
5087 * the marking to occur during its testing pass.
5089 if (source == PGC_S_FILE)
5090 record->status |= GUC_IS_IN_FILE;
5093 * Check if the option can be set at this time. See guc.h for the precise
5096 switch (record->context)
5099 if (context == PGC_SIGHUP)
5102 * Historically we've just silently ignored attempts to set
5103 * PGC_INTERNAL variables from the config file. Maybe it'd
5104 * be better to use the prohibitValueChange logic for this?
5108 else if (context != PGC_INTERNAL)
5111 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5112 errmsg("parameter \"%s\" cannot be changed",
5117 case PGC_POSTMASTER:
5118 if (context == PGC_SIGHUP)
5121 * We are re-reading a PGC_POSTMASTER variable from
5122 * postgresql.conf. We can't change the setting, so we should
5123 * give a warning if the DBA tries to change it. However,
5124 * because of variant formats, canonicalization by check
5125 * hooks, etc, we can't just compare the given string directly
5126 * to what's stored. Set a flag to check below after we have
5127 * the final storable value.
5129 * During the "checking" pass we just do nothing, to avoid
5130 * printing the warning twice.
5135 prohibitValueChange = true;
5137 else if (context != PGC_POSTMASTER)
5140 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5141 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5147 if (context != PGC_SIGHUP && context != PGC_POSTMASTER)
5150 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5151 errmsg("parameter \"%s\" cannot be changed now",
5157 * Hmm, the idea of the SIGHUP context is "ought to be global, but
5158 * can be changed after postmaster start". But there's nothing
5159 * that prevents a crafty administrator from sending SIGHUP
5160 * signals to individual backends only.
5164 if (context == PGC_SIGHUP)
5167 * If a PGC_BACKEND parameter is changed in the config file,
5168 * we want to accept the new value in the postmaster (whence
5169 * it will propagate to subsequently-started backends), but
5170 * ignore it in existing backends. This is a tad klugy, but
5171 * necessary because we don't re-read the config file during
5174 if (IsUnderPostmaster)
5177 else if (context != PGC_POSTMASTER && context != PGC_BACKEND &&
5178 source != PGC_S_CLIENT)
5181 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5182 errmsg("parameter \"%s\" cannot be set after connection start",
5188 if (context == PGC_USERSET || context == PGC_BACKEND)
5191 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5192 errmsg("permission denied to set parameter \"%s\"",
5203 * Disallow changing GUC_NOT_WHILE_SEC_REST values if we are inside a
5204 * security restriction context. We can reject this regardless of the GUC
5205 * context or source, mainly because sources that it might be reasonable
5206 * to override for won't be seen while inside a function.
5208 * Note: variables marked GUC_NOT_WHILE_SEC_REST should usually be marked
5209 * GUC_NO_RESET_ALL as well, because ResetAllOptions() doesn't check this.
5210 * An exception might be made if the reset value is assumed to be "safe".
5212 * Note: this flag is currently used for "session_authorization" and
5213 * "role". We need to prohibit changing these inside a local userid
5214 * context because when we exit it, GUC won't be notified, leaving things
5215 * out of sync. (This could be fixed by forcing a new GUC nesting level,
5216 * but that would change behavior in possibly-undesirable ways.) Also, we
5217 * prohibit changing these in a security-restricted operation because
5218 * otherwise RESET could be used to regain the session user's privileges.
5220 if (record->flags & GUC_NOT_WHILE_SEC_REST)
5222 if (InLocalUserIdChange())
5225 * Phrasing of this error message is historical, but it's the most
5229 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5230 errmsg("cannot set parameter \"%s\" within security-definer function",
5234 if (InSecurityRestrictedOperation())
5237 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5238 errmsg("cannot set parameter \"%s\" within security-restricted operation",
5245 * Should we set reset/stacked values? (If so, the behavior is not
5246 * transactional.) This is done either when we get a default value from
5247 * the database's/user's/client's default settings or when we reset a
5248 * value to its default.
5250 makeDefault = changeVal && (source <= PGC_S_OVERRIDE) &&
5251 ((value != NULL) || source == PGC_S_DEFAULT);
5254 * Ignore attempted set if overridden by previously processed setting.
5255 * However, if changeVal is false then plow ahead anyway since we are
5256 * trying to find out if the value is potentially good, not actually use
5257 * it. Also keep going if makeDefault is true, since we may want to set
5258 * the reset/stacked values even if we can't set the variable itself.
5260 if (record->source > source)
5262 if (changeVal && !makeDefault)
5264 elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
5272 * Evaluate value and set variable.
5274 switch (record->vartype)
5278 struct config_bool *conf = (struct config_bool *) record;
5280 void *newextra = NULL;
5284 if (!parse_bool(value, &newval))
5287 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5288 errmsg("parameter \"%s\" requires a Boolean value",
5292 if (!call_bool_check_hook(conf, &newval, &newextra,
5296 else if (source == PGC_S_DEFAULT)
5298 newval = conf->boot_val;
5299 if (!call_bool_check_hook(conf, &newval, &newextra,
5305 newval = conf->reset_val;
5306 newextra = conf->reset_extra;
5307 source = conf->gen.reset_source;
5310 if (prohibitValueChange)
5312 if (*conf->variable != newval)
5314 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5315 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5322 /* Save old value to support transaction abort */
5324 push_old_value(&conf->gen, action);
5326 if (conf->assign_hook)
5327 (*conf->assign_hook) (newval, newextra);
5328 *conf->variable = newval;
5329 set_extra_field(&conf->gen, &conf->gen.extra,
5331 conf->gen.source = source;
5337 if (conf->gen.reset_source <= source)
5339 conf->reset_val = newval;
5340 set_extra_field(&conf->gen, &conf->reset_extra,
5342 conf->gen.reset_source = source;
5344 for (stack = conf->gen.stack; stack; stack = stack->prev)
5346 if (stack->source <= source)
5348 stack->prior.val.boolval = newval;
5349 set_extra_field(&conf->gen, &stack->prior.extra,
5351 stack->source = source;
5356 /* Perhaps we didn't install newextra anywhere */
5357 if (newextra && !extra_field_used(&conf->gen, newextra))
5364 struct config_int *conf = (struct config_int *) record;
5366 void *newextra = NULL;
5370 const char *hintmsg;
5372 if (!parse_int(value, &newval, conf->gen.flags, &hintmsg))
5375 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5376 errmsg("invalid value for parameter \"%s\": \"%s\"",
5378 hintmsg ? errhint("%s", _(hintmsg)) : 0));
5381 if (newval < conf->min || newval > conf->max)
5384 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5385 errmsg("%d is outside the valid range for parameter \"%s\" (%d .. %d)",
5386 newval, name, conf->min, conf->max)));
5389 if (!call_int_check_hook(conf, &newval, &newextra,
5393 else if (source == PGC_S_DEFAULT)
5395 newval = conf->boot_val;
5396 if (!call_int_check_hook(conf, &newval, &newextra,
5402 newval = conf->reset_val;
5403 newextra = conf->reset_extra;
5404 source = conf->gen.reset_source;
5407 if (prohibitValueChange)
5409 if (*conf->variable != newval)
5411 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5412 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5419 /* Save old value to support transaction abort */
5421 push_old_value(&conf->gen, action);
5423 if (conf->assign_hook)
5424 (*conf->assign_hook) (newval, newextra);
5425 *conf->variable = newval;
5426 set_extra_field(&conf->gen, &conf->gen.extra,
5428 conf->gen.source = source;
5434 if (conf->gen.reset_source <= source)
5436 conf->reset_val = newval;
5437 set_extra_field(&conf->gen, &conf->reset_extra,
5439 conf->gen.reset_source = source;
5441 for (stack = conf->gen.stack; stack; stack = stack->prev)
5443 if (stack->source <= source)
5445 stack->prior.val.intval = newval;
5446 set_extra_field(&conf->gen, &stack->prior.extra,
5448 stack->source = source;
5453 /* Perhaps we didn't install newextra anywhere */
5454 if (newextra && !extra_field_used(&conf->gen, newextra))
5461 struct config_real *conf = (struct config_real *) record;
5463 void *newextra = NULL;
5467 if (!parse_real(value, &newval))
5470 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5471 errmsg("parameter \"%s\" requires a numeric value",
5475 if (newval < conf->min || newval > conf->max)
5478 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5479 errmsg("%g is outside the valid range for parameter \"%s\" (%g .. %g)",
5480 newval, name, conf->min, conf->max)));
5483 if (!call_real_check_hook(conf, &newval, &newextra,
5487 else if (source == PGC_S_DEFAULT)
5489 newval = conf->boot_val;
5490 if (!call_real_check_hook(conf, &newval, &newextra,
5496 newval = conf->reset_val;
5497 newextra = conf->reset_extra;
5498 source = conf->gen.reset_source;
5501 if (prohibitValueChange)
5503 if (*conf->variable != newval)
5505 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5506 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5513 /* Save old value to support transaction abort */
5515 push_old_value(&conf->gen, action);
5517 if (conf->assign_hook)
5518 (*conf->assign_hook) (newval, newextra);
5519 *conf->variable = newval;
5520 set_extra_field(&conf->gen, &conf->gen.extra,
5522 conf->gen.source = source;
5528 if (conf->gen.reset_source <= source)
5530 conf->reset_val = newval;
5531 set_extra_field(&conf->gen, &conf->reset_extra,
5533 conf->gen.reset_source = source;
5535 for (stack = conf->gen.stack; stack; stack = stack->prev)
5537 if (stack->source <= source)
5539 stack->prior.val.realval = newval;
5540 set_extra_field(&conf->gen, &stack->prior.extra,
5542 stack->source = source;
5547 /* Perhaps we didn't install newextra anywhere */
5548 if (newextra && !extra_field_used(&conf->gen, newextra))
5555 struct config_string *conf = (struct config_string *) record;
5557 void *newextra = NULL;
5562 * The value passed by the caller could be transient,
5563 * so we always strdup it.
5565 newval = guc_strdup(elevel, value);
5570 * The only built-in "parsing" check we have is to apply
5571 * truncation if GUC_IS_NAME.
5573 if (conf->gen.flags & GUC_IS_NAME)
5574 truncate_identifier(newval, strlen(newval), true);
5576 if (!call_string_check_hook(conf, &newval, &newextra,
5583 else if (source == PGC_S_DEFAULT)
5585 /* non-NULL boot_val must always get strdup'd */
5586 if (conf->boot_val != NULL)
5588 newval = guc_strdup(elevel, conf->boot_val);
5595 if (!call_string_check_hook(conf, &newval, &newextra,
5605 * strdup not needed, since reset_val is already under
5608 newval = conf->reset_val;
5609 newextra = conf->reset_extra;
5610 source = conf->gen.reset_source;
5613 if (prohibitValueChange)
5615 /* newval shouldn't be NULL, so we're a bit sloppy here */
5616 if (*conf->variable == NULL || newval == NULL ||
5617 strcmp(*conf->variable, newval) != 0)
5619 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5620 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5627 /* Save old value to support transaction abort */
5629 push_old_value(&conf->gen, action);
5631 if (conf->assign_hook)
5632 (*conf->assign_hook) (newval, newextra);
5633 set_string_field(conf, conf->variable, newval);
5634 set_extra_field(&conf->gen, &conf->gen.extra,
5636 conf->gen.source = source;
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;
5650 for (stack = conf->gen.stack; stack; stack = stack->prev)
5652 if (stack->source <= source)
5654 set_string_field(conf, &stack->prior.val.stringval,
5656 set_extra_field(&conf->gen, &stack->prior.extra,
5658 stack->source = source;
5663 /* Perhaps we didn't install newval anywhere */
5664 if (newval && !string_field_used(conf, newval))
5666 /* Perhaps we didn't install newextra anywhere */
5667 if (newextra && !extra_field_used(&conf->gen, newextra))
5674 struct config_enum *conf = (struct config_enum *) record;
5676 void *newextra = NULL;
5680 if (!config_enum_lookup_by_name(conf, value, &newval))
5684 hintmsg = config_enum_get_options(conf,
5685 "Available values: ",
5689 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5690 errmsg("invalid value for parameter \"%s\": \"%s\"",
5692 hintmsg ? errhint("%s", _(hintmsg)) : 0));
5698 if (!call_enum_check_hook(conf, &newval, &newextra,
5702 else if (source == PGC_S_DEFAULT)
5704 newval = conf->boot_val;
5705 if (!call_enum_check_hook(conf, &newval, &newextra,
5711 newval = conf->reset_val;
5712 newextra = conf->reset_extra;
5713 source = conf->gen.reset_source;
5716 if (prohibitValueChange)
5718 if (*conf->variable != newval)
5720 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5721 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5728 /* Save old value to support transaction abort */
5730 push_old_value(&conf->gen, action);
5732 if (conf->assign_hook)
5733 (*conf->assign_hook) (newval, newextra);
5734 *conf->variable = newval;
5735 set_extra_field(&conf->gen, &conf->gen.extra,
5737 conf->gen.source = source;
5743 if (conf->gen.reset_source <= source)
5745 conf->reset_val = newval;
5746 set_extra_field(&conf->gen, &conf->reset_extra,
5748 conf->gen.reset_source = source;
5750 for (stack = conf->gen.stack; stack; stack = stack->prev)
5752 if (stack->source <= source)
5754 stack->prior.val.enumval = newval;
5755 set_extra_field(&conf->gen, &stack->prior.extra,
5757 stack->source = source;
5762 /* Perhaps we didn't install newextra anywhere */
5763 if (newextra && !extra_field_used(&conf->gen, newextra))
5769 if (changeVal && (record->flags & GUC_REPORT))
5770 ReportGUCOption(record);
5777 * Set the fields for source file and line number the setting came from.
5780 set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
5782 struct config_generic *record;
5786 * To avoid cluttering the log, only the postmaster bleats loudly about
5787 * problems with the config file.
5789 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
5791 record = find_option(name, true, elevel);
5792 /* should not happen */
5794 elog(ERROR, "unrecognized configuration parameter \"%s\"", name);
5796 sourcefile = guc_strdup(elevel, sourcefile);
5797 if (record->sourcefile)
5798 free(record->sourcefile);
5799 record->sourcefile = sourcefile;
5800 record->sourceline = sourceline;
5804 * Set a config option to the given value. See also set_config_option,
5805 * this is just the wrapper to be called from outside GUC. NB: this
5806 * is used only for non-transactional operations.
5808 * Note: there is no support here for setting source file/line, as it
5809 * is currently not needed.
5812 SetConfigOption(const char *name, const char *value,
5813 GucContext context, GucSource source)
5815 (void) set_config_option(name, value, context, source,
5816 GUC_ACTION_SET, true);
5822 * Fetch the current value of the option `name'. If the option doesn't exist,
5823 * throw an ereport and don't return.
5825 * If restrict_superuser is true, we also enforce that only superusers can
5826 * see GUC_SUPERUSER_ONLY variables. This should only be passed as true
5827 * in user-driven calls.
5829 * The string is *not* allocated for modification and is really only
5830 * valid until the next call to configuration related functions.
5833 GetConfigOption(const char *name, bool restrict_superuser)
5835 struct config_generic *record;
5836 static char buffer[256];
5838 record = find_option(name, false, ERROR);
5841 (errcode(ERRCODE_UNDEFINED_OBJECT),
5842 errmsg("unrecognized configuration parameter \"%s\"", name)));
5843 if (restrict_superuser &&
5844 (record->flags & GUC_SUPERUSER_ONLY) &&
5847 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5848 errmsg("must be superuser to examine \"%s\"", name)));
5850 switch (record->vartype)
5853 return *((struct config_bool *) record)->variable ? "on" : "off";
5856 snprintf(buffer, sizeof(buffer), "%d",
5857 *((struct config_int *) record)->variable);
5861 snprintf(buffer, sizeof(buffer), "%g",
5862 *((struct config_real *) record)->variable);
5866 return *((struct config_string *) record)->variable;
5869 return config_enum_lookup_by_value((struct config_enum *) record,
5870 *((struct config_enum *) record)->variable);
5876 * Get the RESET value associated with the given option.
5878 * Note: this is not re-entrant, due to use of static result buffer;
5879 * not to mention that a string variable could have its reset_val changed.
5880 * Beware of assuming the result value is good for very long.
5883 GetConfigOptionResetString(const char *name)
5885 struct config_generic *record;
5886 static char buffer[256];
5888 record = find_option(name, false, ERROR);
5891 (errcode(ERRCODE_UNDEFINED_OBJECT),
5892 errmsg("unrecognized configuration parameter \"%s\"", name)));
5893 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
5895 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5896 errmsg("must be superuser to examine \"%s\"", name)));
5898 switch (record->vartype)
5901 return ((struct config_bool *) record)->reset_val ? "on" : "off";
5904 snprintf(buffer, sizeof(buffer), "%d",
5905 ((struct config_int *) record)->reset_val);
5909 snprintf(buffer, sizeof(buffer), "%g",
5910 ((struct config_real *) record)->reset_val);
5914 return ((struct config_string *) record)->reset_val;
5917 return config_enum_lookup_by_value((struct config_enum *) record,
5918 ((struct config_enum *) record)->reset_val);
5925 * flatten_set_variable_args
5926 * Given a parsenode List as emitted by the grammar for SET,
5927 * convert to the flat string representation used by GUC.
5929 * We need to be told the name of the variable the args are for, because
5930 * the flattening rules vary (ugh).
5932 * The result is NULL if args is NIL (ie, SET ... TO DEFAULT), otherwise
5933 * a palloc'd string.
5936 flatten_set_variable_args(const char *name, List *args)
5938 struct config_generic *record;
5943 /* Fast path if just DEFAULT */
5948 * Get flags for the variable; if it's not known, use default flags.
5949 * (Caller might throw error later, but not our business to do so here.)
5951 record = find_option(name, false, WARNING);
5953 flags = record->flags;
5957 /* Complain if list input and non-list variable */
5958 if ((flags & GUC_LIST_INPUT) == 0 &&
5959 list_length(args) != 1)
5961 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5962 errmsg("SET %s takes only one argument", name)));
5964 initStringInfo(&buf);
5967 * Each list member may be a plain A_Const node, or an A_Const within a
5968 * TypeCast; the latter case is supported only for ConstInterval arguments
5969 * (for SET TIME ZONE).
5973 Node *arg = (Node *) lfirst(l);
5975 TypeName *typeName = NULL;
5978 if (l != list_head(args))
5979 appendStringInfo(&buf, ", ");
5981 if (IsA(arg, TypeCast))
5983 TypeCast *tc = (TypeCast *) arg;
5986 typeName = tc->typeName;
5989 if (!IsA(arg, A_Const))
5990 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
5991 con = (A_Const *) arg;
5993 switch (nodeTag(&con->val))
5996 appendStringInfo(&buf, "%ld", intVal(&con->val));
5999 /* represented as a string, so just copy it */
6000 appendStringInfoString(&buf, strVal(&con->val));
6003 val = strVal(&con->val);
6004 if (typeName != NULL)
6007 * Must be a ConstInterval argument for TIME ZONE. Coerce
6008 * to interval and back to normalize the value and account
6016 typenameTypeIdAndMod(NULL, typeName, &typoid, &typmod);
6017 Assert(typoid == INTERVALOID);
6020 DirectFunctionCall3(interval_in,
6021 CStringGetDatum(val),
6022 ObjectIdGetDatum(InvalidOid),
6023 Int32GetDatum(typmod));
6026 DatumGetCString(DirectFunctionCall1(interval_out,
6028 appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
6033 * Plain string literal or identifier. For quote mode,
6034 * quote it if it's not a vanilla identifier.
6036 if (flags & GUC_LIST_QUOTE)
6037 appendStringInfoString(&buf, quote_identifier(val));
6039 appendStringInfoString(&buf, val);
6043 elog(ERROR, "unrecognized node type: %d",
6044 (int) nodeTag(&con->val));
6057 ExecSetVariableStmt(VariableSetStmt *stmt)
6059 GucAction action = stmt->is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET;
6064 case VAR_SET_CURRENT:
6065 set_config_option(stmt->name,
6066 ExtractSetVariableArgs(stmt),
6067 (superuser() ? PGC_SUSET : PGC_USERSET),
6075 * Special case for special SQL syntax that effectively sets more
6076 * than one variable per statement.
6078 if (strcmp(stmt->name, "TRANSACTION") == 0)
6082 foreach(head, stmt->args)
6084 DefElem *item = (DefElem *) lfirst(head);
6086 if (strcmp(item->defname, "transaction_isolation") == 0)
6087 SetPGVariable("transaction_isolation",
6088 list_make1(item->arg), stmt->is_local);
6089 else if (strcmp(item->defname, "transaction_read_only") == 0)
6090 SetPGVariable("transaction_read_only",
6091 list_make1(item->arg), stmt->is_local);
6092 else if (strcmp(item->defname, "transaction_deferrable") == 0)
6093 SetPGVariable("transaction_deferrable",
6094 list_make1(item->arg), stmt->is_local);
6096 elog(ERROR, "unexpected SET TRANSACTION element: %s",
6100 else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
6104 foreach(head, stmt->args)
6106 DefElem *item = (DefElem *) lfirst(head);
6108 if (strcmp(item->defname, "transaction_isolation") == 0)
6109 SetPGVariable("default_transaction_isolation",
6110 list_make1(item->arg), stmt->is_local);
6111 else if (strcmp(item->defname, "transaction_read_only") == 0)
6112 SetPGVariable("default_transaction_read_only",
6113 list_make1(item->arg), stmt->is_local);
6114 else if (strcmp(item->defname, "transaction_deferrable") == 0)
6115 SetPGVariable("default_transaction_deferrable",
6116 list_make1(item->arg), stmt->is_local);
6118 elog(ERROR, "unexpected SET SESSION element: %s",
6123 elog(ERROR, "unexpected SET MULTI element: %s",
6126 case VAR_SET_DEFAULT:
6128 set_config_option(stmt->name,
6130 (superuser() ? PGC_SUSET : PGC_USERSET),
6142 * Get the value to assign for a VariableSetStmt, or NULL if it's RESET.
6143 * The result is palloc'd.
6145 * This is exported for use by actions such as ALTER ROLE SET.
6148 ExtractSetVariableArgs(VariableSetStmt *stmt)
6153 return flatten_set_variable_args(stmt->name, stmt->args);
6154 case VAR_SET_CURRENT:
6155 return GetConfigOptionByName(stmt->name, NULL);
6162 * SetPGVariable - SET command exported as an easily-C-callable function.
6164 * This provides access to SET TO value, as well as SET TO DEFAULT (expressed
6165 * by passing args == NIL), but not SET FROM CURRENT functionality.
6168 SetPGVariable(const char *name, List *args, bool is_local)
6170 char *argstring = flatten_set_variable_args(name, args);
6172 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
6173 set_config_option(name,
6175 (superuser() ? PGC_SUSET : PGC_USERSET),
6177 is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET,
6182 * SET command wrapped as a SQL callable function.
6185 set_config_by_name(PG_FUNCTION_ARGS)
6192 if (PG_ARGISNULL(0))
6194 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
6195 errmsg("SET requires parameter name")));
6197 /* Get the GUC variable name */
6198 name = TextDatumGetCString(PG_GETARG_DATUM(0));
6200 /* Get the desired value or set to NULL for a reset request */
6201 if (PG_ARGISNULL(1))
6204 value = TextDatumGetCString(PG_GETARG_DATUM(1));
6207 * Get the desired state of is_local. Default to false if provided value
6210 if (PG_ARGISNULL(2))
6213 is_local = PG_GETARG_BOOL(2);
6215 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
6216 set_config_option(name,
6218 (superuser() ? PGC_SUSET : PGC_USERSET),
6220 is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET,
6223 /* get the new current value */
6224 new_value = GetConfigOptionByName(name, NULL);
6226 /* Convert return string to text */
6227 PG_RETURN_TEXT_P(cstring_to_text(new_value));
6232 * Common code for DefineCustomXXXVariable subroutines: allocate the
6233 * new variable's config struct and fill in generic fields.
6235 static struct config_generic *
6236 init_custom_variable(const char *name,
6237 const char *short_desc,
6238 const char *long_desc,
6241 enum config_type type,
6244 struct config_generic *gen;
6247 * Only allow custom PGC_POSTMASTER variables to be created during shared
6248 * library preload; any later than that, we can't ensure that the value
6249 * doesn't change after startup. This is a fatal elog if it happens; just
6250 * erroring out isn't safe because we don't know what the calling loadable
6251 * module might already have hooked into.
6253 if (context == PGC_POSTMASTER &&
6254 !process_shared_preload_libraries_in_progress)
6255 elog(FATAL, "cannot create PGC_POSTMASTER variables after startup");
6257 gen = (struct config_generic *) guc_malloc(ERROR, sz);
6260 gen->name = guc_strdup(ERROR, name);
6261 gen->context = context;
6262 gen->group = CUSTOM_OPTIONS;
6263 gen->short_desc = short_desc;
6264 gen->long_desc = long_desc;
6266 gen->vartype = type;
6272 * Common code for DefineCustomXXXVariable subroutines: insert the new
6273 * variable into the GUC variable array, replacing any placeholder.
6276 define_custom_variable(struct config_generic * variable)
6278 const char *name = variable->name;
6279 const char **nameAddr = &name;
6281 struct config_string *pHolder;
6282 GucContext phcontext;
6283 struct config_generic **res;
6286 * See if there's a placeholder by the same name.
6288 res = (struct config_generic **) bsearch((void *) &nameAddr,
6289 (void *) guc_variables,
6291 sizeof(struct config_generic *),
6296 * No placeholder to replace, so we can just add it ... but first,
6297 * make sure it's initialized to its default value.
6299 InitializeOneGUCOption(variable);
6300 add_guc_variable(variable, ERROR);
6305 * This better be a placeholder
6307 if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
6309 (errcode(ERRCODE_INTERNAL_ERROR),
6310 errmsg("attempt to redefine parameter \"%s\"", name)));
6312 Assert((*res)->vartype == PGC_STRING);
6313 pHolder = (struct config_string *) (*res);
6316 * First, set the variable to its default value. We must do this even
6317 * though we intend to immediately apply a new value, since it's possible
6318 * that the new value is invalid.
6320 InitializeOneGUCOption(variable);
6323 * Replace the placeholder. We aren't changing the name, so no re-sorting
6329 * Infer context for assignment based on source of existing value. We
6330 * can't tell this with exact accuracy, but we can at least do something
6331 * reasonable in typical cases.
6333 switch (pHolder->gen.source)
6341 * If we got past the check in init_custom_variable, we can safely
6342 * assume that any existing value for a PGC_POSTMASTER variable
6343 * was set in postmaster context.
6345 if (variable->context == PGC_POSTMASTER)
6346 phcontext = PGC_POSTMASTER;
6348 phcontext = PGC_SIGHUP;
6351 case PGC_S_DATABASE:
6353 case PGC_S_DATABASE_USER:
6356 * The existing value came from an ALTER ROLE/DATABASE SET
6357 * command. We can assume that at the time the command was issued,
6358 * we checked that the issuing user was superuser if the variable
6359 * requires superuser privileges to set. So it's safe to use
6360 * SUSET context here.
6362 phcontext = PGC_SUSET;
6370 * We must assume that the value came from an untrusted user, even
6371 * if the current_user is a superuser.
6373 phcontext = PGC_USERSET;
6378 * Assign the string value stored in the placeholder to the real variable.
6380 * XXX this is not really good enough --- it should be a nontransactional
6381 * assignment, since we don't want it to roll back if the current xact
6382 * fails later. (Or do we?)
6384 value = *pHolder->variable;
6388 if (set_config_option(name, value,
6389 phcontext, pHolder->gen.source,
6390 GUC_ACTION_SET, true))
6392 /* Also copy over any saved source-location information */
6393 if (pHolder->gen.sourcefile)
6394 set_config_sourcefile(name, pHolder->gen.sourcefile,
6395 pHolder->gen.sourceline);
6400 * Free up as much as we conveniently can of the placeholder structure
6401 * (this neglects any stack items...)
6403 set_string_field(pHolder, pHolder->variable, NULL);
6404 set_string_field(pHolder, &pHolder->reset_val, NULL);
6410 DefineCustomBoolVariable(const char *name,
6411 const char *short_desc,
6412 const char *long_desc,
6417 GucBoolCheckHook check_hook,
6418 GucBoolAssignHook assign_hook,
6419 GucShowHook show_hook)
6421 struct config_bool *var;
6423 var = (struct config_bool *)
6424 init_custom_variable(name, short_desc, long_desc, context, flags,
6425 PGC_BOOL, sizeof(struct config_bool));
6426 var->variable = valueAddr;
6427 var->boot_val = bootValue;
6428 var->reset_val = bootValue;
6429 var->check_hook = check_hook;
6430 var->assign_hook = assign_hook;
6431 var->show_hook = show_hook;
6432 define_custom_variable(&var->gen);
6436 DefineCustomIntVariable(const char *name,
6437 const char *short_desc,
6438 const char *long_desc,
6445 GucIntCheckHook check_hook,
6446 GucIntAssignHook assign_hook,
6447 GucShowHook show_hook)
6449 struct config_int *var;
6451 var = (struct config_int *)
6452 init_custom_variable(name, short_desc, long_desc, context, flags,
6453 PGC_INT, sizeof(struct config_int));
6454 var->variable = valueAddr;
6455 var->boot_val = bootValue;
6456 var->reset_val = bootValue;
6457 var->min = minValue;
6458 var->max = maxValue;
6459 var->check_hook = check_hook;
6460 var->assign_hook = assign_hook;
6461 var->show_hook = show_hook;
6462 define_custom_variable(&var->gen);
6466 DefineCustomRealVariable(const char *name,
6467 const char *short_desc,
6468 const char *long_desc,
6475 GucRealCheckHook check_hook,
6476 GucRealAssignHook assign_hook,
6477 GucShowHook show_hook)
6479 struct config_real *var;
6481 var = (struct config_real *)
6482 init_custom_variable(name, short_desc, long_desc, context, flags,
6483 PGC_REAL, sizeof(struct config_real));
6484 var->variable = valueAddr;
6485 var->boot_val = bootValue;
6486 var->reset_val = bootValue;
6487 var->min = minValue;
6488 var->max = maxValue;
6489 var->check_hook = check_hook;
6490 var->assign_hook = assign_hook;
6491 var->show_hook = show_hook;
6492 define_custom_variable(&var->gen);
6496 DefineCustomStringVariable(const char *name,
6497 const char *short_desc,
6498 const char *long_desc,
6500 const char *bootValue,
6503 GucStringCheckHook check_hook,
6504 GucStringAssignHook assign_hook,
6505 GucShowHook show_hook)
6507 struct config_string *var;
6509 var = (struct config_string *)
6510 init_custom_variable(name, short_desc, long_desc, context, flags,
6511 PGC_STRING, sizeof(struct config_string));
6512 var->variable = valueAddr;
6513 var->boot_val = bootValue;
6514 var->check_hook = check_hook;
6515 var->assign_hook = assign_hook;
6516 var->show_hook = show_hook;
6517 define_custom_variable(&var->gen);
6521 DefineCustomEnumVariable(const char *name,
6522 const char *short_desc,
6523 const char *long_desc,
6526 const struct config_enum_entry * options,
6529 GucEnumCheckHook check_hook,
6530 GucEnumAssignHook assign_hook,
6531 GucShowHook show_hook)
6533 struct config_enum *var;
6535 var = (struct config_enum *)
6536 init_custom_variable(name, short_desc, long_desc, context, flags,
6537 PGC_ENUM, sizeof(struct config_enum));
6538 var->variable = valueAddr;
6539 var->boot_val = bootValue;
6540 var->reset_val = bootValue;
6541 var->options = options;
6542 var->check_hook = check_hook;
6543 var->assign_hook = assign_hook;
6544 var->show_hook = show_hook;
6545 define_custom_variable(&var->gen);
6549 EmitWarningsOnPlaceholders(const char *className)
6551 int classLen = strlen(className);
6554 for (i = 0; i < num_guc_variables; i++)
6556 struct config_generic *var = guc_variables[i];
6558 if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
6559 strncmp(className, var->name, classLen) == 0 &&
6560 var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
6563 (errcode(ERRCODE_UNDEFINED_OBJECT),
6564 errmsg("unrecognized configuration parameter \"%s\"",
6575 GetPGVariable(const char *name, DestReceiver *dest)
6577 if (guc_name_compare(name, "all") == 0)
6578 ShowAllGUCConfig(dest);
6580 ShowGUCConfigOption(name, dest);
6584 GetPGVariableResultDesc(const char *name)
6588 if (guc_name_compare(name, "all") == 0)
6590 /* need a tuple descriptor representing three TEXT columns */
6591 tupdesc = CreateTemplateTupleDesc(3, false);
6592 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
6594 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
6596 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
6601 const char *varname;
6603 /* Get the canonical spelling of name */
6604 (void) GetConfigOptionByName(name, &varname);
6606 /* need a tuple descriptor representing a single TEXT column */
6607 tupdesc = CreateTemplateTupleDesc(1, false);
6608 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
6619 ShowGUCConfigOption(const char *name, DestReceiver *dest)
6621 TupOutputState *tstate;
6623 const char *varname;
6626 /* Get the value and canonical spelling of name */
6627 value = GetConfigOptionByName(name, &varname);
6629 /* need a tuple descriptor representing a single TEXT column */
6630 tupdesc = CreateTemplateTupleDesc(1, false);
6631 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
6634 /* prepare for projection of tuples */
6635 tstate = begin_tup_output_tupdesc(dest, tupdesc);
6638 do_text_output_oneline(tstate, value);
6640 end_tup_output(tstate);
6647 ShowAllGUCConfig(DestReceiver *dest)
6649 bool am_superuser = superuser();
6651 TupOutputState *tstate;
6654 bool isnull[3] = {false, false, false};
6656 /* need a tuple descriptor representing three TEXT columns */
6657 tupdesc = CreateTemplateTupleDesc(3, false);
6658 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
6660 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
6662 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
6665 /* prepare for projection of tuples */
6666 tstate = begin_tup_output_tupdesc(dest, tupdesc);
6668 for (i = 0; i < num_guc_variables; i++)
6670 struct config_generic *conf = guc_variables[i];
6673 if ((conf->flags & GUC_NO_SHOW_ALL) ||
6674 ((conf->flags & GUC_SUPERUSER_ONLY) && !am_superuser))
6677 /* assign to the values array */
6678 values[0] = PointerGetDatum(cstring_to_text(conf->name));
6680 setting = _ShowOption(conf, true);
6683 values[1] = PointerGetDatum(cstring_to_text(setting));
6688 values[1] = PointerGetDatum(NULL);
6692 values[2] = PointerGetDatum(cstring_to_text(conf->short_desc));
6694 /* send it to dest */
6695 do_tup_output(tstate, values, isnull);
6698 pfree(DatumGetPointer(values[0]));
6702 pfree(DatumGetPointer(values[1]));
6704 pfree(DatumGetPointer(values[2]));
6707 end_tup_output(tstate);
6711 * Return GUC variable value by name; optionally return canonical
6712 * form of name. Return value is palloc'd.
6715 GetConfigOptionByName(const char *name, const char **varname)
6717 struct config_generic *record;
6719 record = find_option(name, false, ERROR);
6722 (errcode(ERRCODE_UNDEFINED_OBJECT),
6723 errmsg("unrecognized configuration parameter \"%s\"", name)));
6724 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
6726 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6727 errmsg("must be superuser to examine \"%s\"", name)));
6730 *varname = record->name;
6732 return _ShowOption(record, true);
6736 * Return GUC variable value by variable number; optionally return canonical
6737 * form of name. Return value is palloc'd.
6740 GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
6743 struct config_generic *conf;
6745 /* check requested variable number valid */
6746 Assert((varnum >= 0) && (varnum < num_guc_variables));
6748 conf = guc_variables[varnum];
6752 if ((conf->flags & GUC_NO_SHOW_ALL) ||
6753 ((conf->flags & GUC_SUPERUSER_ONLY) && !superuser()))
6759 /* first get the generic attributes */
6762 values[0] = conf->name;
6764 /* setting : use _ShowOption in order to avoid duplicating the logic */
6765 values[1] = _ShowOption(conf, false);
6768 if (conf->vartype == PGC_INT)
6772 switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
6777 case GUC_UNIT_BLOCKS:
6778 snprintf(buf, sizeof(buf), "%dkB", BLCKSZ / 1024);
6781 case GUC_UNIT_XBLOCKS:
6782 snprintf(buf, sizeof(buf), "%dkB", XLOG_BLCKSZ / 1024);
6803 values[3] = config_group_names[conf->group];
6806 values[4] = conf->short_desc;
6809 values[5] = conf->long_desc;
6812 values[6] = GucContext_Names[conf->context];
6815 values[7] = config_type_names[conf->vartype];
6818 values[8] = GucSource_Names[conf->source];
6820 /* now get the type specifc attributes */
6821 switch (conf->vartype)
6825 struct config_bool *lconf = (struct config_bool *) conf;
6837 values[12] = pstrdup(lconf->boot_val ? "on" : "off");
6840 values[13] = pstrdup(lconf->reset_val ? "on" : "off");
6846 struct config_int *lconf = (struct config_int *) conf;
6849 snprintf(buffer, sizeof(buffer), "%d", lconf->min);
6850 values[9] = pstrdup(buffer);
6853 snprintf(buffer, sizeof(buffer), "%d", lconf->max);
6854 values[10] = pstrdup(buffer);
6860 snprintf(buffer, sizeof(buffer), "%d", lconf->boot_val);
6861 values[12] = pstrdup(buffer);
6864 snprintf(buffer, sizeof(buffer), "%d", lconf->reset_val);
6865 values[13] = pstrdup(buffer);
6871 struct config_real *lconf = (struct config_real *) conf;
6874 snprintf(buffer, sizeof(buffer), "%g", lconf->min);
6875 values[9] = pstrdup(buffer);
6878 snprintf(buffer, sizeof(buffer), "%g", lconf->max);
6879 values[10] = pstrdup(buffer);
6885 snprintf(buffer, sizeof(buffer), "%g", lconf->boot_val);
6886 values[12] = pstrdup(buffer);
6889 snprintf(buffer, sizeof(buffer), "%g", lconf->reset_val);
6890 values[13] = pstrdup(buffer);
6896 struct config_string *lconf = (struct config_string *) conf;
6908 if (lconf->boot_val == NULL)
6911 values[12] = pstrdup(lconf->boot_val);
6914 if (lconf->reset_val == NULL)
6917 values[13] = pstrdup(lconf->reset_val);
6923 struct config_enum *lconf = (struct config_enum *) conf;
6934 * NOTE! enumvals with double quotes in them are not
6937 values[11] = config_enum_get_options((struct config_enum *) conf,
6938 "{\"", "\"}", "\",\"");
6941 values[12] = pstrdup(config_enum_lookup_by_value(lconf,
6945 values[13] = pstrdup(config_enum_lookup_by_value(lconf,
6953 * should never get here, but in case we do, set 'em to NULL
6975 * If the setting came from a config file, set the source location. For
6976 * security reasons, we don't show source file/line number for
6979 if (conf->source == PGC_S_FILE && superuser())
6981 values[14] = conf->sourcefile;
6982 snprintf(buffer, sizeof(buffer), "%d", conf->sourceline);
6983 values[15] = pstrdup(buffer);
6993 * Return the total number of GUC variables
6996 GetNumConfigOptions(void)
6998 return num_guc_variables;
7002 * show_config_by_name - equiv to SHOW X command but implemented as
7006 show_config_by_name(PG_FUNCTION_ARGS)
7011 /* Get the GUC variable name */
7012 varname = TextDatumGetCString(PG_GETARG_DATUM(0));
7015 varval = GetConfigOptionByName(varname, NULL);
7017 /* Convert to text */
7018 PG_RETURN_TEXT_P(cstring_to_text(varval));
7022 * show_all_settings - equiv to SHOW ALL command but implemented as
7025 #define NUM_PG_SETTINGS_ATTS 16
7028 show_all_settings(PG_FUNCTION_ARGS)
7030 FuncCallContext *funcctx;
7034 AttInMetadata *attinmeta;
7035 MemoryContext oldcontext;
7037 /* stuff done only on the first call of the function */
7038 if (SRF_IS_FIRSTCALL())
7040 /* create a function context for cross-call persistence */
7041 funcctx = SRF_FIRSTCALL_INIT();
7044 * switch to memory context appropriate for multiple function calls
7046 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
7049 * need a tuple descriptor representing NUM_PG_SETTINGS_ATTS columns
7050 * of the appropriate types
7052 tupdesc = CreateTemplateTupleDesc(NUM_PG_SETTINGS_ATTS, false);
7053 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
7055 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
7057 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "unit",
7059 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "category",
7061 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "short_desc",
7063 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "extra_desc",
7065 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "context",
7067 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "vartype",
7069 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "source",
7071 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "min_val",
7073 TupleDescInitEntry(tupdesc, (AttrNumber) 11, "max_val",
7075 TupleDescInitEntry(tupdesc, (AttrNumber) 12, "enumvals",
7076 TEXTARRAYOID, -1, 0);
7077 TupleDescInitEntry(tupdesc, (AttrNumber) 13, "boot_val",
7079 TupleDescInitEntry(tupdesc, (AttrNumber) 14, "reset_val",
7081 TupleDescInitEntry(tupdesc, (AttrNumber) 15, "sourcefile",
7083 TupleDescInitEntry(tupdesc, (AttrNumber) 16, "sourceline",
7087 * Generate attribute metadata needed later to produce tuples from raw
7090 attinmeta = TupleDescGetAttInMetadata(tupdesc);
7091 funcctx->attinmeta = attinmeta;
7093 /* total number of tuples to be returned */
7094 funcctx->max_calls = GetNumConfigOptions();
7096 MemoryContextSwitchTo(oldcontext);
7099 /* stuff done on every call of the function */
7100 funcctx = SRF_PERCALL_SETUP();
7102 call_cntr = funcctx->call_cntr;
7103 max_calls = funcctx->max_calls;
7104 attinmeta = funcctx->attinmeta;
7106 if (call_cntr < max_calls) /* do when there is more left to send */
7108 char *values[NUM_PG_SETTINGS_ATTS];
7114 * Get the next visible GUC variable name and value
7118 GetConfigOptionByNum(call_cntr, (const char **) values, &noshow);
7121 /* bump the counter and get the next config setting */
7122 call_cntr = ++funcctx->call_cntr;
7124 /* make sure we haven't gone too far now */
7125 if (call_cntr >= max_calls)
7126 SRF_RETURN_DONE(funcctx);
7131 tuple = BuildTupleFromCStrings(attinmeta, values);
7133 /* make the tuple into a datum */
7134 result = HeapTupleGetDatum(tuple);
7136 SRF_RETURN_NEXT(funcctx, result);
7140 /* do when there is no more left */
7141 SRF_RETURN_DONE(funcctx);
7146 _ShowOption(struct config_generic * record, bool use_units)
7151 switch (record->vartype)
7155 struct config_bool *conf = (struct config_bool *) record;
7157 if (conf->show_hook)
7158 val = (*conf->show_hook) ();
7160 val = *conf->variable ? "on" : "off";
7166 struct config_int *conf = (struct config_int *) record;
7168 if (conf->show_hook)
7169 val = (*conf->show_hook) ();
7173 * Use int64 arithmetic to avoid overflows in units
7176 int64 result = *conf->variable;
7179 if (use_units && result > 0 &&
7180 (record->flags & GUC_UNIT_MEMORY))
7182 switch (record->flags & GUC_UNIT_MEMORY)
7184 case GUC_UNIT_BLOCKS:
7185 result *= BLCKSZ / 1024;
7187 case GUC_UNIT_XBLOCKS:
7188 result *= XLOG_BLCKSZ / 1024;
7192 if (result % KB_PER_GB == 0)
7194 result /= KB_PER_GB;
7197 else if (result % KB_PER_MB == 0)
7199 result /= KB_PER_MB;
7207 else if (use_units && result > 0 &&
7208 (record->flags & GUC_UNIT_TIME))
7210 switch (record->flags & GUC_UNIT_TIME)
7216 result *= MS_PER_MIN;
7220 if (result % MS_PER_D == 0)
7225 else if (result % MS_PER_H == 0)
7230 else if (result % MS_PER_MIN == 0)
7232 result /= MS_PER_MIN;
7235 else if (result % MS_PER_S == 0)
7248 snprintf(buffer, sizeof(buffer), INT64_FORMAT "%s",
7257 struct config_real *conf = (struct config_real *) record;
7259 if (conf->show_hook)
7260 val = (*conf->show_hook) ();
7263 snprintf(buffer, sizeof(buffer), "%g",
7272 struct config_string *conf = (struct config_string *) record;
7274 if (conf->show_hook)
7275 val = (*conf->show_hook) ();
7276 else if (*conf->variable && **conf->variable)
7277 val = *conf->variable;
7285 struct config_enum *conf = (struct config_enum *) record;
7287 if (conf->show_hook)
7288 val = (*conf->show_hook) ();
7290 val = config_enum_lookup_by_value(conf, *conf->variable);
7295 /* just to keep compiler quiet */
7300 return pstrdup(val);
7307 * These routines dump out all non-default GUC options into a binary
7308 * file that is read by all exec'ed backends. The format is:
7310 * variable name, string, null terminated
7311 * variable value, string, null terminated
7312 * variable source, integer
7315 write_one_nondefault_variable(FILE *fp, struct config_generic * gconf)
7317 if (gconf->source == PGC_S_DEFAULT)
7320 fprintf(fp, "%s", gconf->name);
7323 switch (gconf->vartype)
7327 struct config_bool *conf = (struct config_bool *) gconf;
7329 if (*conf->variable)
7330 fprintf(fp, "true");
7332 fprintf(fp, "false");
7338 struct config_int *conf = (struct config_int *) gconf;
7340 fprintf(fp, "%d", *conf->variable);
7346 struct config_real *conf = (struct config_real *) gconf;
7348 /* Could lose precision here? */
7349 fprintf(fp, "%f", *conf->variable);
7355 struct config_string *conf = (struct config_string *) gconf;
7357 fprintf(fp, "%s", *conf->variable);
7363 struct config_enum *conf = (struct config_enum *) gconf;
7366 config_enum_lookup_by_value(conf, *conf->variable));
7373 fwrite(&gconf->source, sizeof(gconf->source), 1, fp);
7377 write_nondefault_variables(GucContext context)
7381 struct config_generic *cvc_conf;
7384 Assert(context == PGC_POSTMASTER || context == PGC_SIGHUP);
7386 elevel = (context == PGC_SIGHUP) ? LOG : ERROR;
7391 fp = AllocateFile(CONFIG_EXEC_PARAMS_NEW, "w");
7395 (errcode_for_file_access(),
7396 errmsg("could not write to file \"%s\": %m",
7397 CONFIG_EXEC_PARAMS_NEW)));
7402 * custom_variable_classes must be written out first; otherwise we might
7403 * reject custom variable values while reading the file.
7405 cvc_conf = find_option("custom_variable_classes", false, ERROR);
7407 write_one_nondefault_variable(fp, cvc_conf);
7409 for (i = 0; i < num_guc_variables; i++)
7411 struct config_generic *gconf = guc_variables[i];
7413 if (gconf != cvc_conf)
7414 write_one_nondefault_variable(fp, gconf);
7420 (errcode_for_file_access(),
7421 errmsg("could not write to file \"%s\": %m",
7422 CONFIG_EXEC_PARAMS_NEW)));
7427 * Put new file in place. This could delay on Win32, but we don't hold
7428 * any exclusive locks.
7430 rename(CONFIG_EXEC_PARAMS_NEW, CONFIG_EXEC_PARAMS);
7435 * Read string, including null byte from file
7437 * Return NULL on EOF and nothing read
7440 read_string_with_null(FILE *fp)
7449 if ((ch = fgetc(fp)) == EOF)
7454 elog(FATAL, "invalid format of exec config params file");
7457 str = guc_malloc(FATAL, maxlen);
7458 else if (i == maxlen)
7459 str = guc_realloc(FATAL, str, maxlen *= 2);
7468 * This routine loads a previous postmaster dump of its non-default
7472 read_nondefault_variables(void)
7482 fp = AllocateFile(CONFIG_EXEC_PARAMS, "r");
7485 /* File not found is fine */
7486 if (errno != ENOENT)
7488 (errcode_for_file_access(),
7489 errmsg("could not read from file \"%s\": %m",
7490 CONFIG_EXEC_PARAMS)));
7496 struct config_generic *record;
7498 if ((varname = read_string_with_null(fp)) == NULL)
7501 if ((record = find_option(varname, true, FATAL)) == NULL)
7502 elog(FATAL, "failed to locate variable %s in exec config params file", varname);
7503 if ((varvalue = read_string_with_null(fp)) == NULL)
7504 elog(FATAL, "invalid format of exec config params file");
7505 if (fread(&varsource, sizeof(varsource), 1, fp) == 0)
7506 elog(FATAL, "invalid format of exec config params file");
7508 (void) set_config_option(varname, varvalue, record->context,
7509 varsource, GUC_ACTION_SET, true);
7516 #endif /* EXEC_BACKEND */
7520 * A little "long argument" simulation, although not quite GNU
7521 * compliant. Takes a string of the form "some-option=some value" and
7522 * returns name = "some_option" and value = "some value" in malloc'ed
7523 * storage. Note that '-' is converted to '_' in the option name. If
7524 * there is no '=' in the input string then value will be NULL.
7527 ParseLongOption(const char *string, char **name, char **value)
7536 equal_pos = strcspn(string, "=");
7538 if (string[equal_pos] == '=')
7540 *name = guc_malloc(FATAL, equal_pos + 1);
7541 strlcpy(*name, string, equal_pos + 1);
7543 *value = guc_strdup(FATAL, &string[equal_pos + 1]);
7547 /* no equal sign in string */
7548 *name = guc_strdup(FATAL, string);
7552 for (cp = *name; *cp; cp++)
7559 * Handle options fetched from pg_db_role_setting.setconfig,
7560 * pg_proc.proconfig, etc. Caller must specify proper context/source/action.
7562 * The array parameter must be an array of TEXT (it must not be NULL).
7565 ProcessGUCArray(ArrayType *array,
7566 GucContext context, GucSource source, GucAction action)
7570 Assert(array != NULL);
7571 Assert(ARR_ELEMTYPE(array) == TEXTOID);
7572 Assert(ARR_NDIM(array) == 1);
7573 Assert(ARR_LBOUND(array)[0] == 1);
7575 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
7583 d = array_ref(array, 1, &i,
7584 -1 /* varlenarray */ ,
7585 -1 /* TEXT's typlen */ ,
7586 false /* TEXT's typbyval */ ,
7587 'i' /* TEXT's typalign */ ,
7593 s = TextDatumGetCString(d);
7595 ParseLongOption(s, &name, &value);
7599 (errcode(ERRCODE_SYNTAX_ERROR),
7600 errmsg("could not parse setting for parameter \"%s\"",
7606 (void) set_config_option(name, value, context, source, action, true);
7617 * Add an entry to an option array. The array parameter may be NULL
7618 * to indicate the current table entry is NULL.
7621 GUCArrayAdd(ArrayType *array, const char *name, const char *value)
7623 struct config_generic *record;
7631 /* test if the option is valid and we're allowed to set it */
7632 (void) validate_option_array_item(name, value, false);
7634 /* normalize name (converts obsolete GUC names to modern spellings) */
7635 record = find_option(name, false, WARNING);
7637 name = record->name;
7639 /* build new item for array */
7640 newval = palloc(strlen(name) + 1 + strlen(value) + 1);
7641 sprintf(newval, "%s=%s", name, value);
7642 datum = CStringGetTextDatum(newval);
7650 Assert(ARR_ELEMTYPE(array) == TEXTOID);
7651 Assert(ARR_NDIM(array) == 1);
7652 Assert(ARR_LBOUND(array)[0] == 1);
7654 index = ARR_DIMS(array)[0] + 1; /* add after end */
7656 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
7661 d = array_ref(array, 1, &i,
7662 -1 /* varlenarray */ ,
7663 -1 /* TEXT's typlen */ ,
7664 false /* TEXT's typbyval */ ,
7665 'i' /* TEXT's typalign */ ,
7669 current = TextDatumGetCString(d);
7671 /* check for match up through and including '=' */
7672 if (strncmp(current, newval, strlen(name) + 1) == 0)
7679 a = array_set(array, 1, &index,
7682 -1 /* varlena array */ ,
7683 -1 /* TEXT's typlen */ ,
7684 false /* TEXT's typbyval */ ,
7685 'i' /* TEXT's typalign */ );
7688 a = construct_array(&datum, 1,
7697 * Delete an entry from an option array. The array parameter may be NULL
7698 * to indicate the current table entry is NULL. Also, if the return value
7699 * is NULL then a null should be stored.
7702 GUCArrayDelete(ArrayType *array, const char *name)
7704 struct config_generic *record;
7705 ArrayType *newarray;
7711 /* test if the option is valid and we're allowed to set it */
7712 (void) validate_option_array_item(name, NULL, false);
7714 /* normalize name (converts obsolete GUC names to modern spellings) */
7715 record = find_option(name, false, WARNING);
7717 name = record->name;
7719 /* if array is currently null, then surely nothing to delete */
7726 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
7732 d = array_ref(array, 1, &i,
7733 -1 /* varlenarray */ ,
7734 -1 /* TEXT's typlen */ ,
7735 false /* TEXT's typbyval */ ,
7736 'i' /* TEXT's typalign */ ,
7740 val = TextDatumGetCString(d);
7742 /* ignore entry if it's what we want to delete */
7743 if (strncmp(val, name, strlen(name)) == 0
7744 && val[strlen(name)] == '=')
7747 /* else add it to the output array */
7749 newarray = array_set(newarray, 1, &index,
7752 -1 /* varlenarray */ ,
7753 -1 /* TEXT's typlen */ ,
7754 false /* TEXT's typbyval */ ,
7755 'i' /* TEXT's typalign */ );
7757 newarray = construct_array(&d, 1,
7769 * Given a GUC array, delete all settings from it that our permission
7770 * level allows: if superuser, delete them all; if regular user, only
7771 * those that are PGC_USERSET
7774 GUCArrayReset(ArrayType *array)
7776 ArrayType *newarray;
7780 /* if array is currently null, nothing to do */
7784 /* if we're superuser, we can delete everything, so just do it */
7791 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
7798 d = array_ref(array, 1, &i,
7799 -1 /* varlenarray */ ,
7800 -1 /* TEXT's typlen */ ,
7801 false /* TEXT's typbyval */ ,
7802 'i' /* TEXT's typalign */ ,
7806 val = TextDatumGetCString(d);
7808 eqsgn = strchr(val, '=');
7811 /* skip if we have permission to delete it */
7812 if (validate_option_array_item(val, NULL, true))
7815 /* else add it to the output array */
7817 newarray = array_set(newarray, 1, &index,
7820 -1 /* varlenarray */ ,
7821 -1 /* TEXT's typlen */ ,
7822 false /* TEXT's typbyval */ ,
7823 'i' /* TEXT's typalign */ );
7825 newarray = construct_array(&d, 1,
7837 * Validate a proposed option setting for GUCArrayAdd/Delete/Reset.
7839 * name is the option name. value is the proposed value for the Add case,
7840 * or NULL for the Delete/Reset cases. If skipIfNoPermissions is true, it's
7841 * not an error to have no permissions to set the option.
7843 * Returns TRUE if OK, FALSE if skipIfNoPermissions is true and user does not
7844 * have permission to change this option (all other error cases result in an
7845 * error being thrown).
7848 validate_option_array_item(const char *name, const char *value,
7849 bool skipIfNoPermissions)
7852 struct config_generic *gconf;
7855 * There are three cases to consider:
7857 * name is a known GUC variable. Check the value normally, check
7858 * permissions normally (ie, allow if variable is USERSET, or if it's
7859 * SUSET and user is superuser).
7861 * name is not known, but exists or can be created as a placeholder
7862 * (implying it has a prefix listed in custom_variable_classes). We allow
7863 * this case if you're a superuser, otherwise not. Superusers are assumed
7864 * to know what they're doing. We can't allow it for other users, because
7865 * when the placeholder is resolved it might turn out to be a SUSET
7866 * variable; define_custom_variable assumes we checked that.
7868 * name is not known and can't be created as a placeholder. Throw error,
7869 * unless skipIfNoPermissions is true, in which case return FALSE. (It's
7870 * tempting to allow this case to superusers, if the name is qualified but
7871 * not listed in custom_variable_classes. That would ease restoring of
7872 * dumps containing ALTER ROLE/DATABASE SET. However, it's not clear that
7873 * this usage justifies such a loss of error checking. You can always fix
7874 * custom_variable_classes before you restore.)
7876 gconf = find_option(name, true, WARNING);
7879 /* not known, failed to make a placeholder */
7880 if (skipIfNoPermissions)
7883 (errcode(ERRCODE_UNDEFINED_OBJECT),
7884 errmsg("unrecognized configuration parameter \"%s\"", name)));
7887 if (gconf->flags & GUC_CUSTOM_PLACEHOLDER)
7890 * We cannot do any meaningful check on the value, so only permissions
7891 * are useful to check.
7895 if (skipIfNoPermissions)
7898 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7899 errmsg("permission denied to set parameter \"%s\"", name)));
7902 /* manual permissions check so we can avoid an error being thrown */
7903 if (gconf->context == PGC_USERSET)
7905 else if (gconf->context == PGC_SUSET && superuser())
7907 else if (skipIfNoPermissions)
7909 /* if a permissions error should be thrown, let set_config_option do it */
7911 /* test for permissions and valid option value */
7912 set_config_option(name, value,
7913 superuser() ? PGC_SUSET : PGC_USERSET,
7914 PGC_S_TEST, GUC_ACTION_SET, false);
7921 * Called by check_hooks that want to override the normal
7922 * ERRCODE_INVALID_PARAMETER_VALUE SQLSTATE for check hook failures.
7924 * Note that GUC_check_errmsg() etc are just macros that result in a direct
7925 * assignment to the associated variables. That is ugly, but forced by the
7926 * limitations of C's macro mechanisms.
7929 GUC_check_errcode(int sqlerrcode)
7931 GUC_check_errcode_value = sqlerrcode;
7936 * Convenience functions to manage calling a variable's check_hook.
7937 * These mostly take care of the protocol for letting check hooks supply
7938 * portions of the error report on failure.
7942 call_bool_check_hook(struct config_bool *conf, bool *newval, void **extra,
7943 GucSource source, int elevel)
7945 /* Quick success if no hook */
7946 if (!conf->check_hook)
7949 /* Reset variables that might be set by hook */
7950 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
7951 GUC_check_errmsg_string = NULL;
7952 GUC_check_errdetail_string = NULL;
7953 GUC_check_errhint_string = NULL;
7955 if (!(*conf->check_hook) (newval, extra, source))
7958 (errcode(GUC_check_errcode_value),
7959 GUC_check_errmsg_string ?
7960 errmsg("%s", GUC_check_errmsg_string) :
7961 errmsg("invalid value for parameter \"%s\": %d",
7962 conf->gen.name, (int) *newval),
7963 GUC_check_errdetail_string ?
7964 errdetail("%s", GUC_check_errdetail_string) : 0,
7965 GUC_check_errhint_string ?
7966 errhint("%s", GUC_check_errhint_string) : 0));
7967 /* Flush any strings created in ErrorContext */
7976 call_int_check_hook(struct config_int *conf, int *newval, void **extra,
7977 GucSource source, int elevel)
7979 /* Quick success if no hook */
7980 if (!conf->check_hook)
7983 /* Reset variables that might be set by hook */
7984 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
7985 GUC_check_errmsg_string = NULL;
7986 GUC_check_errdetail_string = NULL;
7987 GUC_check_errhint_string = NULL;
7989 if (!(*conf->check_hook) (newval, extra, source))
7992 (errcode(GUC_check_errcode_value),
7993 GUC_check_errmsg_string ?
7994 errmsg("%s", GUC_check_errmsg_string) :
7995 errmsg("invalid value for parameter \"%s\": %d",
7996 conf->gen.name, *newval),
7997 GUC_check_errdetail_string ?
7998 errdetail("%s", GUC_check_errdetail_string) : 0,
7999 GUC_check_errhint_string ?
8000 errhint("%s", GUC_check_errhint_string) : 0));
8001 /* Flush any strings created in ErrorContext */
8010 call_real_check_hook(struct config_real *conf, double *newval, void **extra,
8011 GucSource source, int elevel)
8013 /* Quick success if no hook */
8014 if (!conf->check_hook)
8017 /* Reset variables that might be set by hook */
8018 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8019 GUC_check_errmsg_string = NULL;
8020 GUC_check_errdetail_string = NULL;
8021 GUC_check_errhint_string = NULL;
8023 if (!(*conf->check_hook) (newval, extra, source))
8026 (errcode(GUC_check_errcode_value),
8027 GUC_check_errmsg_string ?
8028 errmsg("%s", GUC_check_errmsg_string) :
8029 errmsg("invalid value for parameter \"%s\": %g",
8030 conf->gen.name, *newval),
8031 GUC_check_errdetail_string ?
8032 errdetail("%s", GUC_check_errdetail_string) : 0,
8033 GUC_check_errhint_string ?
8034 errhint("%s", GUC_check_errhint_string) : 0));
8035 /* Flush any strings created in ErrorContext */
8044 call_string_check_hook(struct config_string *conf, char **newval, void **extra,
8045 GucSource source, int elevel)
8047 /* Quick success if no hook */
8048 if (!conf->check_hook)
8051 /* Reset variables that might be set by hook */
8052 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8053 GUC_check_errmsg_string = NULL;
8054 GUC_check_errdetail_string = NULL;
8055 GUC_check_errhint_string = NULL;
8057 if (!(*conf->check_hook) (newval, extra, source))
8060 (errcode(GUC_check_errcode_value),
8061 GUC_check_errmsg_string ?
8062 errmsg("%s", GUC_check_errmsg_string) :
8063 errmsg("invalid value for parameter \"%s\": \"%s\"",
8064 conf->gen.name, *newval ? *newval : ""),
8065 GUC_check_errdetail_string ?
8066 errdetail("%s", GUC_check_errdetail_string) : 0,
8067 GUC_check_errhint_string ?
8068 errhint("%s", GUC_check_errhint_string) : 0));
8069 /* Flush any strings created in ErrorContext */
8078 call_enum_check_hook(struct config_enum *conf, int *newval, void **extra,
8079 GucSource source, int elevel)
8081 /* Quick success if no hook */
8082 if (!conf->check_hook)
8085 /* Reset variables that might be set by hook */
8086 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8087 GUC_check_errmsg_string = NULL;
8088 GUC_check_errdetail_string = NULL;
8089 GUC_check_errhint_string = NULL;
8091 if (!(*conf->check_hook) (newval, extra, source))
8094 (errcode(GUC_check_errcode_value),
8095 GUC_check_errmsg_string ?
8096 errmsg("%s", GUC_check_errmsg_string) :
8097 errmsg("invalid value for parameter \"%s\": \"%s\"",
8099 config_enum_lookup_by_value(conf, *newval)),
8100 GUC_check_errdetail_string ?
8101 errdetail("%s", GUC_check_errdetail_string) : 0,
8102 GUC_check_errhint_string ?
8103 errhint("%s", GUC_check_errhint_string) : 0));
8104 /* Flush any strings created in ErrorContext */
8114 * check_hook, assign_hook and show_hook subroutines
8118 check_log_destination(char **newval, void **extra, GucSource source)
8126 /* Need a modifiable copy of string */
8127 rawstring = pstrdup(*newval);
8129 /* Parse string into list of identifiers */
8130 if (!SplitIdentifierString(rawstring, ',', &elemlist))
8132 /* syntax error in list */
8133 GUC_check_errdetail("List syntax is invalid.");
8135 list_free(elemlist);
8139 foreach(l, elemlist)
8141 char *tok = (char *) lfirst(l);
8143 if (pg_strcasecmp(tok, "stderr") == 0)
8144 newlogdest |= LOG_DESTINATION_STDERR;
8145 else if (pg_strcasecmp(tok, "csvlog") == 0)
8146 newlogdest |= LOG_DESTINATION_CSVLOG;
8148 else if (pg_strcasecmp(tok, "syslog") == 0)
8149 newlogdest |= LOG_DESTINATION_SYSLOG;
8152 else if (pg_strcasecmp(tok, "eventlog") == 0)
8153 newlogdest |= LOG_DESTINATION_EVENTLOG;
8157 GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
8159 list_free(elemlist);
8165 list_free(elemlist);
8167 myextra = (int *) guc_malloc(ERROR, sizeof(int));
8168 *myextra = newlogdest;
8169 *extra = (void *) myextra;
8175 assign_log_destination(const char *newval, void *extra)
8177 Log_destination = *((int *) extra);
8181 assign_syslog_facility(int newval, void *extra)
8184 set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
8187 /* Without syslog support, just ignore it */
8191 assign_syslog_ident(const char *newval, void *extra)
8194 set_syslog_parameters(newval, syslog_facility);
8196 /* Without syslog support, it will always be set to "none", so ignore */
8201 assign_session_replication_role(int newval, void *extra)
8204 * Must flush the plan cache when changing replication role; but don't
8205 * flush unnecessarily.
8207 if (SessionReplicationRole != newval)
8212 check_temp_buffers(int *newval, void **extra, GucSource source)
8215 * Once local buffers have been initialized, it's too late to change this.
8217 if (NLocBuffer && NLocBuffer != *newval)
8219 GUC_check_errdetail("\"temp_buffers\" cannot be changed after any temp tables have been accessed in the session.");
8226 check_phony_autocommit(bool *newval, void **extra, GucSource source)
8230 GUC_check_errcode(ERRCODE_FEATURE_NOT_SUPPORTED);
8231 GUC_check_errmsg("SET AUTOCOMMIT TO OFF is no longer supported");
8238 check_custom_variable_classes(char **newval, void **extra, GucSource source)
8241 * Check syntax. newval must be a comma separated list of identifiers.
8242 * Whitespace is allowed but removed from the result.
8244 bool hasSpaceAfterToken = false;
8245 const char *cp = *newval;
8250 /* Default NULL is OK */
8254 initStringInfo(&buf);
8255 while ((c = *cp++) != '\0')
8257 if (isspace((unsigned char) c))
8260 hasSpaceAfterToken = true;
8266 if (symLen > 0) /* terminate identifier */
8268 appendStringInfoChar(&buf, ',');
8271 hasSpaceAfterToken = false;
8275 if (hasSpaceAfterToken || !(isalnum((unsigned char) c) || c == '_'))
8278 * Syntax error due to token following space after token or
8279 * non-identifier character
8284 appendStringInfoChar(&buf, c);
8288 /* Remove stray ',' at end */
8289 if (symLen == 0 && buf.len > 0)
8290 buf.data[--buf.len] = '\0';
8292 /* GUC wants the result malloc'd */
8294 *newval = guc_strdup(LOG, buf.data);
8301 check_debug_assertions(bool *newval, void **extra, GucSource source)
8303 #ifndef USE_ASSERT_CHECKING
8306 GUC_check_errmsg("assertion checking is not supported by this build");
8314 check_bonjour(bool *newval, void **extra, GucSource source)
8319 GUC_check_errmsg("Bonjour is not supported by this build");
8327 check_ssl(bool *newval, void **extra, GucSource source)
8332 GUC_check_errmsg("SSL is not supported by this build");
8340 check_stage_log_stats(bool *newval, void **extra, GucSource source)
8342 if (*newval && log_statement_stats)
8344 GUC_check_errdetail("Cannot enable parameter when \"log_statement_stats\" is true.");
8351 check_log_stats(bool *newval, void **extra, GucSource source)
8354 (log_parser_stats || log_planner_stats || log_executor_stats))
8356 GUC_check_errdetail("Cannot enable \"log_statement_stats\" when "
8357 "\"log_parser_stats\", \"log_planner_stats\", "
8358 "or \"log_executor_stats\" is true.");
8365 check_canonical_path(char **newval, void **extra, GucSource source)
8368 * Since canonicalize_path never enlarges the string, we can just
8369 * modify newval in-place. But watch out for NULL, which is the
8370 * default value for external_pid_file.
8373 canonicalize_path(*newval);
8378 check_timezone_abbreviations(char **newval, void **extra, GucSource source)
8381 * The boot_val given above for timezone_abbreviations is NULL.
8382 * When we see this we just do nothing. If this value isn't overridden
8383 * from the config file then pg_timezone_abbrev_initialize() will
8384 * eventually replace it with "Default". This hack has two purposes: to
8385 * avoid wasting cycles loading values that might soon be overridden from
8386 * the config file, and to avoid trying to read the timezone abbrev files
8387 * during InitializeGUCOptions(). The latter doesn't work in an
8388 * EXEC_BACKEND subprocess because my_exec_path hasn't been set yet and so
8389 * we can't locate PGSHAREDIR.
8391 if (*newval == NULL)
8393 Assert(source == PGC_S_DEFAULT);
8397 /* OK, load the file and produce a malloc'd TimeZoneAbbrevTable */
8398 *extra = load_tzoffsets(*newval);
8400 /* tzparser.c returns NULL on failure, reporting via GUC_check_errmsg */
8408 assign_timezone_abbreviations(const char *newval, void *extra)
8410 /* Do nothing for the boot_val default of NULL */
8414 InstallTimeZoneAbbrevs((TimeZoneAbbrevTable *) extra);
8418 * pg_timezone_abbrev_initialize --- set default value if not done already
8420 * This is called after initial loading of postgresql.conf. If no
8421 * timezone_abbreviations setting was found therein, select default.
8424 pg_timezone_abbrev_initialize(void)
8426 if (timezone_abbreviations_string == NULL)
8428 SetConfigOption("timezone_abbreviations", "Default",
8429 PGC_POSTMASTER, PGC_S_DEFAULT);
8434 show_archive_command(void)
8436 if (XLogArchivingActive())
8437 return XLogArchiveCommand;
8439 return "(disabled)";
8443 assign_tcp_keepalives_idle(int newval, void *extra)
8446 * The kernel API provides no way to test a value without setting it;
8447 * and once we set it we might fail to unset it. So there seems little
8448 * point in fully implementing the check-then-assign GUC API for these
8449 * variables. Instead we just do the assignment on demand. pqcomm.c
8450 * reports any problems via elog(LOG).
8452 * This approach means that the GUC value might have little to do with
8453 * the actual kernel value, so we use a show_hook that retrieves the
8454 * kernel value rather than trusting GUC's copy.
8456 (void) pq_setkeepalivesidle(newval, MyProcPort);
8460 show_tcp_keepalives_idle(void)
8462 /* See comments in assign_tcp_keepalives_idle */
8463 static char nbuf[16];
8465 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesidle(MyProcPort));
8470 assign_tcp_keepalives_interval(int newval, void *extra)
8472 /* See comments in assign_tcp_keepalives_idle */
8473 (void) pq_setkeepalivesinterval(newval, MyProcPort);
8477 show_tcp_keepalives_interval(void)
8479 /* See comments in assign_tcp_keepalives_idle */
8480 static char nbuf[16];
8482 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesinterval(MyProcPort));
8487 assign_tcp_keepalives_count(int newval, void *extra)
8489 /* See comments in assign_tcp_keepalives_idle */
8490 (void) pq_setkeepalivescount(newval, MyProcPort);
8494 show_tcp_keepalives_count(void)
8496 /* See comments in assign_tcp_keepalives_idle */
8497 static char nbuf[16];
8499 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivescount(MyProcPort));
8504 check_maxconnections(int *newval, void **extra, GucSource source)
8506 if (*newval + autovacuum_max_workers + 1 > MAX_BACKENDS)
8512 assign_maxconnections(int newval, void *extra)
8514 MaxBackends = newval + autovacuum_max_workers + 1;
8518 check_autovacuum_max_workers(int *newval, void **extra, GucSource source)
8520 if (MaxConnections + *newval + 1 > MAX_BACKENDS)
8526 assign_autovacuum_max_workers(int newval, void *extra)
8528 MaxBackends = MaxConnections + newval + 1;
8532 check_effective_io_concurrency(int *newval, void **extra, GucSource source)
8535 double new_prefetch_pages = 0.0;
8539 * The user-visible GUC parameter is the number of drives (spindles),
8540 * which we need to translate to a number-of-pages-to-prefetch target.
8541 * The target value is stashed in *extra and then assigned to the actual
8542 * variable by assign_effective_io_concurrency.
8544 * The expected number of prefetch pages needed to keep N drives busy is:
8546 * drives | I/O requests
8547 * -------+----------------
8550 * 3 | 3/1 + 3/2 + 3/3 = 5 1/2
8551 * 4 | 4/1 + 4/2 + 4/3 + 4/4 = 8 1/3
8554 * This is called the "coupon collector problem" and H(n) is called the
8555 * harmonic series. This could be approximated by n * ln(n), but for
8556 * reasonable numbers of drives we might as well just compute the series.
8558 * Alternatively we could set the target to the number of pages necessary
8559 * so that the expected number of active spindles is some arbitrary
8560 * percentage of the total. This sounds the same but is actually slightly
8561 * different. The result ends up being ln(1-P)/ln((n-1)/n) where P is
8562 * that desired fraction.
8564 * Experimental results show that both of these formulas aren't aggressive
8565 * enough, but we don't really have any better proposals.
8567 * Note that if *newval = 0 (disabled), we must set target = 0.
8571 for (i = 1; i <= *newval; i++)
8572 new_prefetch_pages += (double) *newval / (double) i;
8574 /* This range check shouldn't fail, but let's be paranoid */
8575 if (new_prefetch_pages >= 0.0 && new_prefetch_pages < (double) INT_MAX)
8577 int *myextra = (int *) guc_malloc(ERROR, sizeof(int));
8579 *myextra = (int) rint(new_prefetch_pages);
8580 *extra = (void *) myextra;
8588 #endif /* USE_PREFETCH */
8592 assign_effective_io_concurrency(int newval, void *extra)
8595 target_prefetch_pages = *((int *) extra);
8596 #endif /* USE_PREFETCH */
8600 assign_pgstat_temp_directory(const char *newval, void *extra)
8602 /* check_canonical_path already canonicalized newval for us */
8606 tname = guc_malloc(ERROR, strlen(newval) + 12); /* /pgstat.tmp */
8607 sprintf(tname, "%s/pgstat.tmp", newval);
8608 fname = guc_malloc(ERROR, strlen(newval) + 13); /* /pgstat.stat */
8609 sprintf(fname, "%s/pgstat.stat", newval);
8611 if (pgstat_stat_tmpname)
8612 free(pgstat_stat_tmpname);
8613 pgstat_stat_tmpname = tname;
8614 if (pgstat_stat_filename)
8615 free(pgstat_stat_filename);
8616 pgstat_stat_filename = fname;
8620 check_application_name(char **newval, void **extra, GucSource source)
8622 /* Only allow clean ASCII chars in the application name */
8625 for (p = *newval; *p; p++)
8627 if (*p < 32 || *p > 126)
8635 assign_application_name(const char *newval, void *extra)
8637 /* Update the pg_stat_activity view */
8638 pgstat_report_appname(newval);
8642 show_unix_socket_permissions(void)
8646 snprintf(buf, sizeof(buf), "%04o", Unix_socket_permissions);
8651 show_log_file_mode(void)
8655 snprintf(buf, sizeof(buf), "%04o", Log_file_mode);
8659 #include "guc-file.c"