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_DYNAMIC_DEFAULT */ "default",
506 /* PGC_S_ENV_VAR */ "environment variable",
507 /* PGC_S_FILE */ "configuration file",
508 /* PGC_S_ARGV */ "command line",
509 /* PGC_S_DATABASE */ "database",
510 /* PGC_S_USER */ "user",
511 /* PGC_S_DATABASE_USER */ "database user",
512 /* PGC_S_CLIENT */ "client",
513 /* PGC_S_OVERRIDE */ "override",
514 /* PGC_S_INTERACTIVE */ "interactive",
515 /* PGC_S_TEST */ "test",
516 /* PGC_S_SESSION */ "session"
520 * Displayable names for the groupings defined in enum config_group
522 const char *const config_group_names[] =
525 gettext_noop("Ungrouped"),
527 gettext_noop("File Locations"),
529 gettext_noop("Connections and Authentication"),
530 /* CONN_AUTH_SETTINGS */
531 gettext_noop("Connections and Authentication / Connection Settings"),
532 /* CONN_AUTH_SECURITY */
533 gettext_noop("Connections and Authentication / Security and Authentication"),
535 gettext_noop("Resource Usage"),
537 gettext_noop("Resource Usage / Memory"),
538 /* RESOURCES_KERNEL */
539 gettext_noop("Resource Usage / Kernel Resources"),
540 /* RESOURCES_VACUUM_DELAY */
541 gettext_noop("Resource Usage / Cost-Based Vacuum Delay"),
542 /* RESOURCES_BGWRITER */
543 gettext_noop("Resource Usage / Background Writer"),
544 /* RESOURCES_ASYNCHRONOUS */
545 gettext_noop("Resource Usage / Asynchronous Behavior"),
547 gettext_noop("Write-Ahead Log"),
549 gettext_noop("Write-Ahead Log / Settings"),
550 /* WAL_CHECKPOINTS */
551 gettext_noop("Write-Ahead Log / Checkpoints"),
553 gettext_noop("Write-Ahead Log / Archiving"),
554 /* WAL_REPLICATION */
555 gettext_noop("Write-Ahead Log / Streaming Replication"),
556 /* WAL_STANDBY_SERVERS */
557 gettext_noop("Write-Ahead Log / Standby Servers"),
559 gettext_noop("Query Tuning"),
560 /* QUERY_TUNING_METHOD */
561 gettext_noop("Query Tuning / Planner Method Configuration"),
562 /* QUERY_TUNING_COST */
563 gettext_noop("Query Tuning / Planner Cost Constants"),
564 /* QUERY_TUNING_GEQO */
565 gettext_noop("Query Tuning / Genetic Query Optimizer"),
566 /* QUERY_TUNING_OTHER */
567 gettext_noop("Query Tuning / Other Planner Options"),
569 gettext_noop("Reporting and Logging"),
571 gettext_noop("Reporting and Logging / Where to Log"),
573 gettext_noop("Reporting and Logging / When to Log"),
575 gettext_noop("Reporting and Logging / What to Log"),
577 gettext_noop("Statistics"),
578 /* STATS_MONITORING */
579 gettext_noop("Statistics / Monitoring"),
580 /* STATS_COLLECTOR */
581 gettext_noop("Statistics / Query and Index Statistics Collector"),
583 gettext_noop("Autovacuum"),
585 gettext_noop("Client Connection Defaults"),
586 /* CLIENT_CONN_STATEMENT */
587 gettext_noop("Client Connection Defaults / Statement Behavior"),
588 /* CLIENT_CONN_LOCALE */
589 gettext_noop("Client Connection Defaults / Locale and Formatting"),
590 /* CLIENT_CONN_OTHER */
591 gettext_noop("Client Connection Defaults / Other Defaults"),
592 /* LOCK_MANAGEMENT */
593 gettext_noop("Lock Management"),
595 gettext_noop("Version and Platform Compatibility"),
596 /* COMPAT_OPTIONS_PREVIOUS */
597 gettext_noop("Version and Platform Compatibility / Previous PostgreSQL Versions"),
598 /* COMPAT_OPTIONS_CLIENT */
599 gettext_noop("Version and Platform Compatibility / Other Platforms and Clients"),
601 gettext_noop("Error Handling"),
603 gettext_noop("Preset Options"),
605 gettext_noop("Customized Options"),
606 /* DEVELOPER_OPTIONS */
607 gettext_noop("Developer Options"),
608 /* help_config wants this array to be null-terminated */
613 * Displayable names for GUC variable types (enum config_type)
615 * Note: these strings are deliberately not localized.
617 const char *const config_type_names[] =
619 /* PGC_BOOL */ "bool",
620 /* PGC_INT */ "integer",
621 /* PGC_REAL */ "real",
622 /* PGC_STRING */ "string",
623 /* PGC_ENUM */ "enum"
628 * Contents of GUC tables
630 * See src/backend/utils/misc/README for design notes.
634 * 1. Declare a global variable of type bool, int, double, or char*
635 * and make use of it.
637 * 2. Decide at what times it's safe to set the option. See guc.h for
640 * 3. Decide on a name, a default value, upper and lower bounds (if
643 * 4. Add a record below.
645 * 5. Add it to src/backend/utils/misc/postgresql.conf.sample, if
648 * 6. Don't forget to document the option (at least in config.sgml).
650 * 7. If it's a new GUC_LIST option you must edit pg_dumpall.c to ensure
651 * it is not single quoted at dump time.
655 /******** option records follow ********/
657 static struct config_bool ConfigureNamesBool[] =
660 {"enable_seqscan", PGC_USERSET, QUERY_TUNING_METHOD,
661 gettext_noop("Enables the planner's use of sequential-scan plans."),
669 {"enable_indexscan", PGC_USERSET, QUERY_TUNING_METHOD,
670 gettext_noop("Enables the planner's use of index-scan plans."),
678 {"enable_bitmapscan", PGC_USERSET, QUERY_TUNING_METHOD,
679 gettext_noop("Enables the planner's use of bitmap-scan plans."),
687 {"enable_tidscan", PGC_USERSET, QUERY_TUNING_METHOD,
688 gettext_noop("Enables the planner's use of TID scan plans."),
696 {"enable_sort", PGC_USERSET, QUERY_TUNING_METHOD,
697 gettext_noop("Enables the planner's use of explicit sort steps."),
705 {"enable_hashagg", PGC_USERSET, QUERY_TUNING_METHOD,
706 gettext_noop("Enables the planner's use of hashed aggregation plans."),
714 {"enable_material", PGC_USERSET, QUERY_TUNING_METHOD,
715 gettext_noop("Enables the planner's use of materialization."),
723 {"enable_nestloop", PGC_USERSET, QUERY_TUNING_METHOD,
724 gettext_noop("Enables the planner's use of nested-loop join plans."),
732 {"enable_mergejoin", PGC_USERSET, QUERY_TUNING_METHOD,
733 gettext_noop("Enables the planner's use of merge join plans."),
741 {"enable_hashjoin", PGC_USERSET, QUERY_TUNING_METHOD,
742 gettext_noop("Enables the planner's use of hash join plans."),
750 {"geqo", PGC_USERSET, QUERY_TUNING_GEQO,
751 gettext_noop("Enables genetic query optimization."),
752 gettext_noop("This algorithm attempts to do planning without "
753 "exhaustive searching.")
760 /* Not for general use --- used by SET SESSION AUTHORIZATION */
761 {"is_superuser", PGC_INTERNAL, UNGROUPED,
762 gettext_noop("Shows whether the current user is a superuser."),
764 GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
766 &session_auth_is_superuser,
771 {"bonjour", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
772 gettext_noop("Enables advertising the server via Bonjour."),
777 check_bonjour, NULL, NULL
780 {"ssl", PGC_POSTMASTER, CONN_AUTH_SECURITY,
781 gettext_noop("Enables SSL connections."),
786 check_ssl, NULL, NULL
789 {"fsync", PGC_SIGHUP, WAL_SETTINGS,
790 gettext_noop("Forces synchronization of updates to disk."),
791 gettext_noop("The server will use the fsync() system call in several places to make "
792 "sure that updates are physically written to disk. This insures "
793 "that a database cluster will recover to a consistent state after "
794 "an operating system or hardware crash.")
801 {"zero_damaged_pages", PGC_SUSET, DEVELOPER_OPTIONS,
802 gettext_noop("Continues processing past damaged page headers."),
803 gettext_noop("Detection of a damaged page header normally causes PostgreSQL to "
804 "report an error, aborting the current transaction. Setting "
805 "zero_damaged_pages to true causes the system to instead report a "
806 "warning, zero out the damaged page, and continue processing. This "
807 "behavior will destroy data, namely all the rows on the damaged page."),
815 {"full_page_writes", PGC_SIGHUP, WAL_SETTINGS,
816 gettext_noop("Writes full pages to WAL when first modified after a checkpoint."),
817 gettext_noop("A page write in process during an operating system crash might be "
818 "only partially written to disk. During recovery, the row changes "
819 "stored in WAL are not enough to recover. This option writes "
820 "pages when first modified after a checkpoint to WAL so full recovery "
828 {"log_checkpoints", PGC_SIGHUP, LOGGING_WHAT,
829 gettext_noop("Logs each checkpoint."),
837 {"log_connections", PGC_BACKEND, LOGGING_WHAT,
838 gettext_noop("Logs each successful connection."),
846 {"log_disconnections", PGC_BACKEND, LOGGING_WHAT,
847 gettext_noop("Logs end of a session, including duration."),
855 {"debug_assertions", PGC_USERSET, DEVELOPER_OPTIONS,
856 gettext_noop("Turns on various assertion checks."),
857 gettext_noop("This is a debugging aid."),
861 #ifdef USE_ASSERT_CHECKING
866 check_debug_assertions, NULL, NULL
870 {"exit_on_error", PGC_USERSET, ERROR_HANDLING_OPTIONS,
871 gettext_noop("Terminate session on any error."),
879 {"restart_after_crash", PGC_SIGHUP, ERROR_HANDLING_OPTIONS,
880 gettext_noop("Reinitialize after backend crash."),
883 &restart_after_crash,
889 {"log_duration", PGC_SUSET, LOGGING_WHAT,
890 gettext_noop("Logs the duration of each completed SQL statement."),
898 {"debug_print_parse", PGC_USERSET, LOGGING_WHAT,
899 gettext_noop("Logs each query's parse tree."),
907 {"debug_print_rewritten", PGC_USERSET, LOGGING_WHAT,
908 gettext_noop("Logs each query's rewritten parse tree."),
911 &Debug_print_rewritten,
916 {"debug_print_plan", PGC_USERSET, LOGGING_WHAT,
917 gettext_noop("Logs each query's execution plan."),
925 {"debug_pretty_print", PGC_USERSET, LOGGING_WHAT,
926 gettext_noop("Indents parse and plan tree displays."),
934 {"log_parser_stats", PGC_SUSET, STATS_MONITORING,
935 gettext_noop("Writes parser performance statistics to the server log."),
940 check_stage_log_stats, NULL, NULL
943 {"log_planner_stats", PGC_SUSET, STATS_MONITORING,
944 gettext_noop("Writes planner performance statistics to the server log."),
949 check_stage_log_stats, NULL, NULL
952 {"log_executor_stats", PGC_SUSET, STATS_MONITORING,
953 gettext_noop("Writes executor performance statistics to the server log."),
958 check_stage_log_stats, NULL, NULL
961 {"log_statement_stats", PGC_SUSET, STATS_MONITORING,
962 gettext_noop("Writes cumulative performance statistics to the server log."),
965 &log_statement_stats,
967 check_log_stats, NULL, NULL
969 #ifdef BTREE_BUILD_STATS
971 {"log_btree_build_stats", PGC_SUSET, DEVELOPER_OPTIONS,
972 gettext_noop("No description available."),
976 &log_btree_build_stats,
983 {"track_activities", PGC_SUSET, STATS_COLLECTOR,
984 gettext_noop("Collects information about executing commands."),
985 gettext_noop("Enables the collection of information on the currently "
986 "executing command of each session, along with "
987 "the time at which that command began execution.")
989 &pgstat_track_activities,
994 {"track_counts", PGC_SUSET, STATS_COLLECTOR,
995 gettext_noop("Collects statistics on database activity."),
998 &pgstat_track_counts,
1004 {"update_process_title", PGC_SUSET, STATS_COLLECTOR,
1005 gettext_noop("Updates the process title to show the active SQL command."),
1006 gettext_noop("Enables updating of the process title every time a new SQL command is received by the server.")
1008 &update_process_title,
1014 {"autovacuum", PGC_SIGHUP, AUTOVACUUM,
1015 gettext_noop("Starts the autovacuum subprocess."),
1018 &autovacuum_start_daemon,
1024 {"trace_notify", PGC_USERSET, DEVELOPER_OPTIONS,
1025 gettext_noop("Generates debugging output for LISTEN and NOTIFY."),
1036 {"trace_locks", PGC_SUSET, DEVELOPER_OPTIONS,
1037 gettext_noop("No description available."),
1046 {"trace_userlocks", PGC_SUSET, DEVELOPER_OPTIONS,
1047 gettext_noop("No description available."),
1056 {"trace_lwlocks", PGC_SUSET, DEVELOPER_OPTIONS,
1057 gettext_noop("No description available."),
1066 {"debug_deadlocks", PGC_SUSET, DEVELOPER_OPTIONS,
1067 gettext_noop("No description available."),
1078 {"log_lock_waits", PGC_SUSET, LOGGING_WHAT,
1079 gettext_noop("Logs long lock waits."),
1088 {"log_hostname", PGC_SIGHUP, LOGGING_WHAT,
1089 gettext_noop("Logs the host name in the connection logs."),
1090 gettext_noop("By default, connection logs only show the IP address "
1091 "of the connecting host. If you want them to show the host name you "
1092 "can turn this on, but depending on your host name resolution "
1093 "setup it might impose a non-negligible performance penalty.")
1100 {"sql_inheritance", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1101 gettext_noop("Causes subtables to be included by default in various commands."),
1109 {"password_encryption", PGC_USERSET, CONN_AUTH_SECURITY,
1110 gettext_noop("Encrypt passwords."),
1111 gettext_noop("When a password is specified in CREATE USER or "
1112 "ALTER USER without writing either ENCRYPTED or UNENCRYPTED, "
1113 "this parameter determines whether the password is to be encrypted.")
1115 &Password_encryption,
1120 {"transform_null_equals", PGC_USERSET, COMPAT_OPTIONS_CLIENT,
1121 gettext_noop("Treats \"expr=NULL\" as \"expr IS NULL\"."),
1122 gettext_noop("When turned on, expressions of the form expr = NULL "
1123 "(or NULL = expr) are treated as expr IS NULL, that is, they "
1124 "return true if expr evaluates to the null value, and false "
1125 "otherwise. The correct behavior of expr = NULL is to always "
1126 "return null (unknown).")
1128 &Transform_null_equals,
1133 {"db_user_namespace", PGC_SIGHUP, CONN_AUTH_SECURITY,
1134 gettext_noop("Enables per-database user names."),
1142 /* only here for backwards compatibility */
1143 {"autocommit", PGC_USERSET, CLIENT_CONN_STATEMENT,
1144 gettext_noop("This parameter doesn't do anything."),
1145 gettext_noop("It's just here so that we won't choke on SET AUTOCOMMIT TO ON from 7.3-vintage clients."),
1146 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
1150 check_phony_autocommit, NULL, NULL
1153 {"default_transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
1154 gettext_noop("Sets the default read-only status of new transactions."),
1157 &DefaultXactReadOnly,
1162 {"transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
1163 gettext_noop("Sets the current transaction's read-only status."),
1165 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1169 check_transaction_read_only, NULL, NULL
1172 {"default_transaction_deferrable", PGC_USERSET, CLIENT_CONN_STATEMENT,
1173 gettext_noop("Sets the default deferrable status of new transactions."),
1176 &DefaultXactDeferrable,
1181 {"transaction_deferrable", PGC_USERSET, CLIENT_CONN_STATEMENT,
1182 gettext_noop("Whether to defer a read-only serializable transaction until it can be executed with no possible serialization failures."),
1184 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1188 check_transaction_deferrable, NULL, NULL
1191 {"check_function_bodies", PGC_USERSET, CLIENT_CONN_STATEMENT,
1192 gettext_noop("Check function bodies during CREATE FUNCTION."),
1195 &check_function_bodies,
1200 {"array_nulls", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1201 gettext_noop("Enable input of NULL elements in arrays."),
1202 gettext_noop("When turned on, unquoted NULL in an array input "
1203 "value means a null value; "
1204 "otherwise it is taken literally.")
1211 {"default_with_oids", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1212 gettext_noop("Create new tables with OIDs by default."),
1220 {"logging_collector", PGC_POSTMASTER, LOGGING_WHERE,
1221 gettext_noop("Start a subprocess to capture stderr output and/or csvlogs into log files."),
1229 {"log_truncate_on_rotation", PGC_SIGHUP, LOGGING_WHERE,
1230 gettext_noop("Truncate existing log files of same name during log rotation."),
1233 &Log_truncate_on_rotation,
1240 {"trace_sort", PGC_USERSET, DEVELOPER_OPTIONS,
1241 gettext_noop("Emit information about resource usage in sorting."),
1251 #ifdef TRACE_SYNCSCAN
1252 /* this is undocumented because not exposed in a standard build */
1254 {"trace_syncscan", PGC_USERSET, DEVELOPER_OPTIONS,
1255 gettext_noop("Generate debugging output for synchronized scanning."),
1265 #ifdef DEBUG_BOUNDED_SORT
1266 /* this is undocumented because not exposed in a standard build */
1269 "optimize_bounded_sort", PGC_USERSET, QUERY_TUNING_METHOD,
1270 gettext_noop("Enable bounded sorting using heap sort."),
1274 &optimize_bounded_sort,
1282 {"wal_debug", PGC_SUSET, DEVELOPER_OPTIONS,
1283 gettext_noop("Emit WAL-related debugging output."),
1294 {"integer_datetimes", PGC_INTERNAL, PRESET_OPTIONS,
1295 gettext_noop("Datetimes are integer based."),
1297 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1300 #ifdef HAVE_INT64_TIMESTAMP
1309 {"krb_caseins_users", PGC_SIGHUP, CONN_AUTH_SECURITY,
1310 gettext_noop("Sets whether Kerberos and GSSAPI user names should be treated as case-insensitive."),
1313 &pg_krb_caseins_users,
1319 {"escape_string_warning", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1320 gettext_noop("Warn about backslash escapes in ordinary string literals."),
1323 &escape_string_warning,
1329 {"standard_conforming_strings", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1330 gettext_noop("Causes '...' strings to treat backslashes literally."),
1334 &standard_conforming_strings,
1340 {"synchronize_seqscans", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1341 gettext_noop("Enable synchronized sequential scans."),
1344 &synchronize_seqscans,
1350 {"archive_mode", PGC_POSTMASTER, WAL_ARCHIVING,
1351 gettext_noop("Allows archiving of WAL files using archive_command."),
1360 {"hot_standby", PGC_POSTMASTER, WAL_STANDBY_SERVERS,
1361 gettext_noop("Allows connections and queries during recovery."),
1370 {"hot_standby_feedback", PGC_SIGHUP, WAL_STANDBY_SERVERS,
1371 gettext_noop("Allows feedback from a hot standby primary that will avoid query conflicts."),
1374 &hot_standby_feedback,
1380 {"allow_system_table_mods", PGC_POSTMASTER, DEVELOPER_OPTIONS,
1381 gettext_noop("Allows modifications of the structure of system tables."),
1385 &allowSystemTableMods,
1391 {"ignore_system_indexes", PGC_BACKEND, DEVELOPER_OPTIONS,
1392 gettext_noop("Disables reading from system indexes."),
1393 gettext_noop("It does not prevent updating the indexes, so it is safe "
1394 "to use. The worst consequence is slowness."),
1397 &IgnoreSystemIndexes,
1403 {"lo_compat_privileges", PGC_SUSET, COMPAT_OPTIONS_PREVIOUS,
1404 gettext_noop("Enables backward compatibility mode for privilege checks on large objects."),
1405 gettext_noop("Skips privilege checks when reading or modifying large objects, "
1406 "for compatibility with PostgreSQL releases prior to 9.0.")
1408 &lo_compat_privileges,
1414 {"quote_all_identifiers", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1415 gettext_noop("When generating SQL fragments, quote all identifiers."),
1418 "e_all_identifiers,
1423 /* End-of-list marker */
1425 {NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL, NULL
1430 static struct config_int ConfigureNamesInt[] =
1433 {"archive_timeout", PGC_SIGHUP, WAL_ARCHIVING,
1434 gettext_noop("Forces a switch to the next xlog file if a "
1435 "new file has not been started within N seconds."),
1439 &XLogArchiveTimeout,
1444 {"post_auth_delay", PGC_BACKEND, DEVELOPER_OPTIONS,
1445 gettext_noop("Waits N seconds on connection startup after authentication."),
1446 gettext_noop("This allows attaching a debugger to the process."),
1447 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1454 {"default_statistics_target", PGC_USERSET, QUERY_TUNING_OTHER,
1455 gettext_noop("Sets the default statistics target."),
1456 gettext_noop("This applies to table columns that have not had a "
1457 "column-specific target set via ALTER TABLE SET STATISTICS.")
1459 &default_statistics_target,
1464 {"from_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1465 gettext_noop("Sets the FROM-list size beyond which subqueries "
1466 "are not collapsed."),
1467 gettext_noop("The planner will merge subqueries into upper "
1468 "queries if the resulting FROM list would have no more than "
1471 &from_collapse_limit,
1476 {"join_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1477 gettext_noop("Sets the FROM-list size beyond which JOIN "
1478 "constructs are not flattened."),
1479 gettext_noop("The planner will flatten explicit JOIN "
1480 "constructs into lists of FROM items whenever a "
1481 "list of no more than this many items would result.")
1483 &join_collapse_limit,
1488 {"geqo_threshold", PGC_USERSET, QUERY_TUNING_GEQO,
1489 gettext_noop("Sets the threshold of FROM items beyond which GEQO is used."),
1497 {"geqo_effort", PGC_USERSET, QUERY_TUNING_GEQO,
1498 gettext_noop("GEQO: effort is used to set the default for other GEQO parameters."),
1502 DEFAULT_GEQO_EFFORT, MIN_GEQO_EFFORT, MAX_GEQO_EFFORT,
1506 {"geqo_pool_size", PGC_USERSET, QUERY_TUNING_GEQO,
1507 gettext_noop("GEQO: number of individuals in the population."),
1508 gettext_noop("Zero selects a suitable default value.")
1515 {"geqo_generations", PGC_USERSET, QUERY_TUNING_GEQO,
1516 gettext_noop("GEQO: number of iterations of the algorithm."),
1517 gettext_noop("Zero selects a suitable default value.")
1525 /* This is PGC_SUSET to prevent hiding from log_lock_waits. */
1526 {"deadlock_timeout", PGC_SUSET, LOCK_MANAGEMENT,
1527 gettext_noop("Sets the time to wait on a lock before checking for deadlock."),
1537 {"max_standby_archive_delay", PGC_SIGHUP, WAL_STANDBY_SERVERS,
1538 gettext_noop("Sets the maximum delay before canceling queries when a hot standby server is processing archived WAL data."),
1542 &max_standby_archive_delay,
1543 30 * 1000, -1, INT_MAX,
1548 {"max_standby_streaming_delay", PGC_SIGHUP, WAL_STANDBY_SERVERS,
1549 gettext_noop("Sets the maximum delay before canceling queries when a hot standby server is processing streamed WAL data."),
1553 &max_standby_streaming_delay,
1554 30 * 1000, -1, INT_MAX,
1559 {"wal_receiver_status_interval", PGC_SIGHUP, WAL_STANDBY_SERVERS,
1560 gettext_noop("Sets the maximum interval between WAL receiver status reports to the master."),
1564 &wal_receiver_status_interval,
1565 10, 0, INT_MAX / 1000,
1570 {"max_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1571 gettext_noop("Sets the maximum number of concurrent connections."),
1575 100, 1, MAX_BACKENDS,
1576 check_maxconnections, assign_maxconnections, NULL
1580 {"superuser_reserved_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1581 gettext_noop("Sets the number of connection slots reserved for superusers."),
1590 * We sometimes multiply the number of shared buffers by two without
1591 * checking for overflow, so we mustn't allow more than INT_MAX / 2.
1594 {"shared_buffers", PGC_POSTMASTER, RESOURCES_MEM,
1595 gettext_noop("Sets the number of shared memory buffers used by the server."),
1600 1024, 16, INT_MAX / 2,
1605 {"temp_buffers", PGC_USERSET, RESOURCES_MEM,
1606 gettext_noop("Sets the maximum number of temporary buffers used by each session."),
1611 1024, 100, INT_MAX / 2,
1612 check_temp_buffers, NULL, NULL
1616 {"port", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1617 gettext_noop("Sets the TCP port the server listens on."),
1621 DEF_PGPORT, 1, 65535,
1626 {"unix_socket_permissions", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1627 gettext_noop("Sets the access permissions of the Unix-domain socket."),
1628 gettext_noop("Unix-domain sockets use the usual Unix file system "
1629 "permission set. The parameter value is expected "
1630 "to be a numeric mode specification in the form "
1631 "accepted by the chmod and umask system calls. "
1632 "(To use the customary octal format the number must "
1633 "start with a 0 (zero).)")
1635 &Unix_socket_permissions,
1637 NULL, NULL, show_unix_socket_permissions
1641 {"log_file_mode", PGC_SIGHUP, LOGGING_WHERE,
1642 gettext_noop("Sets the file permissions for log files."),
1643 gettext_noop("The parameter value is expected "
1644 "to be a numeric mode specification in the form "
1645 "accepted by the chmod and umask system calls. "
1646 "(To use the customary octal format the number must "
1647 "start with a 0 (zero).)")
1651 NULL, NULL, show_log_file_mode
1655 {"work_mem", PGC_USERSET, RESOURCES_MEM,
1656 gettext_noop("Sets the maximum memory to be used for query workspaces."),
1657 gettext_noop("This much memory can be used by each internal "
1658 "sort operation and hash table before switching to "
1659 "temporary disk files."),
1663 1024, 64, MAX_KILOBYTES,
1668 {"maintenance_work_mem", PGC_USERSET, RESOURCES_MEM,
1669 gettext_noop("Sets the maximum memory to be used for maintenance operations."),
1670 gettext_noop("This includes operations such as VACUUM and CREATE INDEX."),
1673 &maintenance_work_mem,
1674 16384, 1024, MAX_KILOBYTES,
1679 * We use the hopefully-safely-small value of 100kB as the compiled-in
1680 * default for max_stack_depth. InitializeGUCOptions will increase it if
1681 * possible, depending on the actual platform-specific stack limit.
1684 {"max_stack_depth", PGC_SUSET, RESOURCES_MEM,
1685 gettext_noop("Sets the maximum stack depth, in kilobytes."),
1690 100, 100, MAX_KILOBYTES,
1691 check_max_stack_depth, assign_max_stack_depth, NULL
1695 {"vacuum_cost_page_hit", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1696 gettext_noop("Vacuum cost for a page found in the buffer cache."),
1705 {"vacuum_cost_page_miss", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1706 gettext_noop("Vacuum cost for a page not found in the buffer cache."),
1709 &VacuumCostPageMiss,
1715 {"vacuum_cost_page_dirty", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1716 gettext_noop("Vacuum cost for a page dirtied by vacuum."),
1719 &VacuumCostPageDirty,
1725 {"vacuum_cost_limit", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1726 gettext_noop("Vacuum cost amount available before napping."),
1735 {"vacuum_cost_delay", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1736 gettext_noop("Vacuum cost delay in milliseconds."),
1746 {"autovacuum_vacuum_cost_delay", PGC_SIGHUP, AUTOVACUUM,
1747 gettext_noop("Vacuum cost delay in milliseconds, for autovacuum."),
1751 &autovacuum_vac_cost_delay,
1757 {"autovacuum_vacuum_cost_limit", PGC_SIGHUP, AUTOVACUUM,
1758 gettext_noop("Vacuum cost amount available before napping, for autovacuum."),
1761 &autovacuum_vac_cost_limit,
1767 {"max_files_per_process", PGC_POSTMASTER, RESOURCES_KERNEL,
1768 gettext_noop("Sets the maximum number of simultaneously open files for each server process."),
1771 &max_files_per_process,
1777 * See also CheckRequiredParameterValues() if this parameter changes
1780 {"max_prepared_transactions", PGC_POSTMASTER, RESOURCES_MEM,
1781 gettext_noop("Sets the maximum number of simultaneously prepared transactions."),
1784 &max_prepared_xacts,
1791 {"trace_lock_oidmin", PGC_SUSET, DEVELOPER_OPTIONS,
1792 gettext_noop("No description available."),
1797 FirstNormalObjectId, 0, INT_MAX,
1801 {"trace_lock_table", PGC_SUSET, DEVELOPER_OPTIONS,
1802 gettext_noop("No description available."),
1813 {"statement_timeout", PGC_USERSET, CLIENT_CONN_STATEMENT,
1814 gettext_noop("Sets the maximum allowed duration of any statement."),
1815 gettext_noop("A value of 0 turns off the timeout."),
1824 {"vacuum_freeze_min_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1825 gettext_noop("Minimum age at which VACUUM should freeze a table row."),
1828 &vacuum_freeze_min_age,
1829 50000000, 0, 1000000000,
1834 {"vacuum_freeze_table_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1835 gettext_noop("Age at which VACUUM should scan whole table to freeze tuples."),
1838 &vacuum_freeze_table_age,
1839 150000000, 0, 2000000000,
1844 {"vacuum_defer_cleanup_age", PGC_SIGHUP, WAL_REPLICATION,
1845 gettext_noop("Number of transactions by which VACUUM and HOT cleanup should be deferred, if any."),
1848 &vacuum_defer_cleanup_age,
1854 * See also CheckRequiredParameterValues() if this parameter changes
1857 {"max_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
1858 gettext_noop("Sets the maximum number of locks per transaction."),
1859 gettext_noop("The shared lock table is sized on the assumption that "
1860 "at most max_locks_per_transaction * max_connections distinct "
1861 "objects will need to be locked at any one time.")
1863 &max_locks_per_xact,
1869 {"max_pred_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
1870 gettext_noop("Sets the maximum number of predicate locks per transaction."),
1871 gettext_noop("The shared predicate lock table is sized on the assumption that "
1872 "at most max_pred_locks_per_transaction * max_connections distinct "
1873 "objects will need to be locked at any one time.")
1875 &max_predicate_locks_per_xact,
1881 {"authentication_timeout", PGC_SIGHUP, CONN_AUTH_SECURITY,
1882 gettext_noop("Sets the maximum allowed time to complete client authentication."),
1886 &AuthenticationTimeout,
1892 /* Not for general use */
1893 {"pre_auth_delay", PGC_SIGHUP, DEVELOPER_OPTIONS,
1894 gettext_noop("Waits N seconds on connection startup before authentication."),
1895 gettext_noop("This allows attaching a debugger to the process."),
1896 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1904 {"wal_keep_segments", PGC_SIGHUP, WAL_REPLICATION,
1905 gettext_noop("Sets the number of WAL files held for standby servers."),
1914 {"checkpoint_segments", PGC_SIGHUP, WAL_CHECKPOINTS,
1915 gettext_noop("Sets the maximum distance in log segments between automatic WAL checkpoints."),
1918 &CheckPointSegments,
1924 {"checkpoint_timeout", PGC_SIGHUP, WAL_CHECKPOINTS,
1925 gettext_noop("Sets the maximum time between automatic WAL checkpoints."),
1935 {"checkpoint_warning", PGC_SIGHUP, WAL_CHECKPOINTS,
1936 gettext_noop("Enables warnings if checkpoint segments are filled more "
1937 "frequently than this."),
1938 gettext_noop("Write a message to the server log if checkpoints "
1939 "caused by the filling of checkpoint segment files happens more "
1940 "frequently than this number of seconds. Zero turns off the warning."),
1949 {"wal_buffers", PGC_POSTMASTER, WAL_SETTINGS,
1950 gettext_noop("Sets the number of disk-page buffers in shared memory for WAL."),
1956 check_wal_buffers, NULL, NULL
1960 {"wal_writer_delay", PGC_SIGHUP, WAL_SETTINGS,
1961 gettext_noop("WAL writer sleep time between WAL flushes."),
1971 /* see max_connections */
1972 {"max_wal_senders", PGC_POSTMASTER, WAL_REPLICATION,
1973 gettext_noop("Sets the maximum number of simultaneously running WAL sender processes."),
1982 {"wal_sender_delay", PGC_SIGHUP, WAL_REPLICATION,
1983 gettext_noop("WAL sender sleep time between WAL replications."),
1993 {"replication_timeout", PGC_SIGHUP, WAL_REPLICATION,
1994 gettext_noop("Sets the maximum time to wait for WAL replication."),
1998 &replication_timeout,
1999 60 * 1000, 0, INT_MAX,
2004 {"commit_delay", PGC_USERSET, WAL_SETTINGS,
2005 gettext_noop("Sets the delay in microseconds between transaction commit and "
2006 "flushing WAL to disk."),
2015 {"commit_siblings", PGC_USERSET, WAL_SETTINGS,
2016 gettext_noop("Sets the minimum concurrent open transactions before performing "
2026 {"extra_float_digits", PGC_USERSET, CLIENT_CONN_LOCALE,
2027 gettext_noop("Sets the number of digits displayed for floating-point values."),
2028 gettext_noop("This affects real, double precision, and geometric data types. "
2029 "The parameter value is added to the standard number of digits "
2030 "(FLT_DIG or DBL_DIG as appropriate).")
2032 &extra_float_digits,
2038 {"log_min_duration_statement", PGC_SUSET, LOGGING_WHEN,
2039 gettext_noop("Sets the minimum execution time above which "
2040 "statements will be logged."),
2041 gettext_noop("Zero prints all queries. -1 turns this feature off."),
2044 &log_min_duration_statement,
2050 {"log_autovacuum_min_duration", PGC_SIGHUP, LOGGING_WHAT,
2051 gettext_noop("Sets the minimum execution time above which "
2052 "autovacuum actions will be logged."),
2053 gettext_noop("Zero prints all actions. -1 turns autovacuum logging off."),
2056 &Log_autovacuum_min_duration,
2062 {"bgwriter_delay", PGC_SIGHUP, RESOURCES_BGWRITER,
2063 gettext_noop("Background writer sleep time between rounds."),
2073 {"bgwriter_lru_maxpages", PGC_SIGHUP, RESOURCES_BGWRITER,
2074 gettext_noop("Background writer maximum number of LRU pages to flush per round."),
2077 &bgwriter_lru_maxpages,
2083 {"effective_io_concurrency",
2089 RESOURCES_ASYNCHRONOUS,
2090 gettext_noop("Number of simultaneous requests that can be handled efficiently by the disk subsystem."),
2091 gettext_noop("For RAID arrays, this should be approximately the number of drive spindles in the array.")
2093 &effective_io_concurrency,
2099 check_effective_io_concurrency, assign_effective_io_concurrency, NULL
2103 {"log_rotation_age", PGC_SIGHUP, LOGGING_WHERE,
2104 gettext_noop("Automatic log file rotation will occur after N minutes."),
2109 HOURS_PER_DAY * MINS_PER_HOUR, 0, INT_MAX / MINS_PER_HOUR,
2114 {"log_rotation_size", PGC_SIGHUP, LOGGING_WHERE,
2115 gettext_noop("Automatic log file rotation will occur after N kilobytes."),
2120 10 * 1024, 0, INT_MAX / 1024,
2125 {"max_function_args", PGC_INTERNAL, PRESET_OPTIONS,
2126 gettext_noop("Shows the maximum number of function arguments."),
2128 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2131 FUNC_MAX_ARGS, FUNC_MAX_ARGS, FUNC_MAX_ARGS,
2136 {"max_index_keys", PGC_INTERNAL, PRESET_OPTIONS,
2137 gettext_noop("Shows the maximum number of index keys."),
2139 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2142 INDEX_MAX_KEYS, INDEX_MAX_KEYS, INDEX_MAX_KEYS,
2147 {"max_identifier_length", PGC_INTERNAL, PRESET_OPTIONS,
2148 gettext_noop("Shows the maximum identifier length."),
2150 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2152 &max_identifier_length,
2153 NAMEDATALEN - 1, NAMEDATALEN - 1, NAMEDATALEN - 1,
2158 {"block_size", PGC_INTERNAL, PRESET_OPTIONS,
2159 gettext_noop("Shows the size of a disk block."),
2161 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2164 BLCKSZ, BLCKSZ, BLCKSZ,
2169 {"segment_size", PGC_INTERNAL, PRESET_OPTIONS,
2170 gettext_noop("Shows the number of pages per disk file."),
2172 GUC_UNIT_BLOCKS | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2175 RELSEG_SIZE, RELSEG_SIZE, RELSEG_SIZE,
2180 {"wal_block_size", PGC_INTERNAL, PRESET_OPTIONS,
2181 gettext_noop("Shows the block size in the write ahead log."),
2183 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2186 XLOG_BLCKSZ, XLOG_BLCKSZ, XLOG_BLCKSZ,
2191 {"wal_segment_size", PGC_INTERNAL, PRESET_OPTIONS,
2192 gettext_noop("Shows the number of pages per write ahead log segment."),
2194 GUC_UNIT_XBLOCKS | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2197 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
2198 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
2199 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
2204 {"autovacuum_naptime", PGC_SIGHUP, AUTOVACUUM,
2205 gettext_noop("Time to sleep between autovacuum runs."),
2209 &autovacuum_naptime,
2210 60, 1, INT_MAX / 1000,
2214 {"autovacuum_vacuum_threshold", PGC_SIGHUP, AUTOVACUUM,
2215 gettext_noop("Minimum number of tuple updates or deletes prior to vacuum."),
2218 &autovacuum_vac_thresh,
2223 {"autovacuum_analyze_threshold", PGC_SIGHUP, AUTOVACUUM,
2224 gettext_noop("Minimum number of tuple inserts, updates or deletes prior to analyze."),
2227 &autovacuum_anl_thresh,
2232 /* see varsup.c for why this is PGC_POSTMASTER not PGC_SIGHUP */
2233 {"autovacuum_freeze_max_age", PGC_POSTMASTER, AUTOVACUUM,
2234 gettext_noop("Age at which to autovacuum a table to prevent transaction ID wraparound."),
2237 &autovacuum_freeze_max_age,
2238 /* see pg_resetxlog if you change the upper-limit value */
2239 200000000, 100000000, 2000000000,
2243 /* see max_connections */
2244 {"autovacuum_max_workers", PGC_POSTMASTER, AUTOVACUUM,
2245 gettext_noop("Sets the maximum number of simultaneously running autovacuum worker processes."),
2248 &autovacuum_max_workers,
2250 check_autovacuum_max_workers, assign_autovacuum_max_workers, NULL
2254 {"tcp_keepalives_idle", PGC_USERSET, CLIENT_CONN_OTHER,
2255 gettext_noop("Time between issuing TCP keepalives."),
2256 gettext_noop("A value of 0 uses the system default."),
2259 &tcp_keepalives_idle,
2261 NULL, assign_tcp_keepalives_idle, show_tcp_keepalives_idle
2265 {"tcp_keepalives_interval", PGC_USERSET, CLIENT_CONN_OTHER,
2266 gettext_noop("Time between TCP keepalive retransmits."),
2267 gettext_noop("A value of 0 uses the system default."),
2270 &tcp_keepalives_interval,
2272 NULL, assign_tcp_keepalives_interval, show_tcp_keepalives_interval
2276 {"ssl_renegotiation_limit", PGC_USERSET, CONN_AUTH_SECURITY,
2277 gettext_noop("Set the amount of traffic to send and receive before renegotiating the encryption keys."),
2281 &ssl_renegotiation_limit,
2282 512 * 1024, 0, MAX_KILOBYTES,
2287 {"tcp_keepalives_count", PGC_USERSET, CLIENT_CONN_OTHER,
2288 gettext_noop("Maximum number of TCP keepalive retransmits."),
2289 gettext_noop("This controls the number of consecutive keepalive retransmits that can be "
2290 "lost before a connection is considered dead. A value of 0 uses the "
2293 &tcp_keepalives_count,
2295 NULL, assign_tcp_keepalives_count, show_tcp_keepalives_count
2299 {"gin_fuzzy_search_limit", PGC_USERSET, CLIENT_CONN_OTHER,
2300 gettext_noop("Sets the maximum allowed result for exact search by GIN."),
2304 &GinFuzzySearchLimit,
2310 {"effective_cache_size", PGC_USERSET, QUERY_TUNING_COST,
2311 gettext_noop("Sets the planner's assumption about the size of the disk cache."),
2312 gettext_noop("That is, the portion of the kernel's disk cache that "
2313 "will be used for PostgreSQL data files. This is measured in disk "
2314 "pages, which are normally 8 kB each."),
2317 &effective_cache_size,
2318 DEFAULT_EFFECTIVE_CACHE_SIZE, 1, INT_MAX,
2323 /* Can't be set in postgresql.conf */
2324 {"server_version_num", PGC_INTERNAL, PRESET_OPTIONS,
2325 gettext_noop("Shows the server version as an integer."),
2327 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2329 &server_version_num,
2330 PG_VERSION_NUM, PG_VERSION_NUM, PG_VERSION_NUM,
2335 {"log_temp_files", PGC_SUSET, LOGGING_WHAT,
2336 gettext_noop("Log the use of temporary files larger than this number of kilobytes."),
2337 gettext_noop("Zero logs all files. The default is -1 (turning this feature off)."),
2346 {"track_activity_query_size", PGC_POSTMASTER, RESOURCES_MEM,
2347 gettext_noop("Sets the size reserved for pg_stat_activity.current_query, in bytes."),
2350 &pgstat_track_activity_query_size,
2355 /* End-of-list marker */
2357 {NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL, NULL
2362 static struct config_real ConfigureNamesReal[] =
2365 {"seq_page_cost", PGC_USERSET, QUERY_TUNING_COST,
2366 gettext_noop("Sets the planner's estimate of the cost of a "
2367 "sequentially fetched disk page."),
2371 DEFAULT_SEQ_PAGE_COST, 0, DBL_MAX,
2375 {"random_page_cost", PGC_USERSET, QUERY_TUNING_COST,
2376 gettext_noop("Sets the planner's estimate of the cost of a "
2377 "nonsequentially fetched disk page."),
2381 DEFAULT_RANDOM_PAGE_COST, 0, DBL_MAX,
2385 {"cpu_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
2386 gettext_noop("Sets the planner's estimate of the cost of "
2387 "processing each tuple (row)."),
2391 DEFAULT_CPU_TUPLE_COST, 0, DBL_MAX,
2395 {"cpu_index_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
2396 gettext_noop("Sets the planner's estimate of the cost of "
2397 "processing each index entry during an index scan."),
2400 &cpu_index_tuple_cost,
2401 DEFAULT_CPU_INDEX_TUPLE_COST, 0, DBL_MAX,
2405 {"cpu_operator_cost", PGC_USERSET, QUERY_TUNING_COST,
2406 gettext_noop("Sets the planner's estimate of the cost of "
2407 "processing each operator or function call."),
2411 DEFAULT_CPU_OPERATOR_COST, 0, DBL_MAX,
2416 {"cursor_tuple_fraction", PGC_USERSET, QUERY_TUNING_OTHER,
2417 gettext_noop("Sets the planner's estimate of the fraction of "
2418 "a cursor's rows that will be retrieved."),
2421 &cursor_tuple_fraction,
2422 DEFAULT_CURSOR_TUPLE_FRACTION, 0.0, 1.0,
2427 {"geqo_selection_bias", PGC_USERSET, QUERY_TUNING_GEQO,
2428 gettext_noop("GEQO: selective pressure within the population."),
2431 &Geqo_selection_bias,
2432 DEFAULT_GEQO_SELECTION_BIAS,
2433 MIN_GEQO_SELECTION_BIAS, MAX_GEQO_SELECTION_BIAS,
2437 {"geqo_seed", PGC_USERSET, QUERY_TUNING_GEQO,
2438 gettext_noop("GEQO: seed for random path selection."),
2447 {"bgwriter_lru_multiplier", PGC_SIGHUP, RESOURCES_BGWRITER,
2448 gettext_noop("Multiple of the average buffer usage to free per round."),
2451 &bgwriter_lru_multiplier,
2457 {"seed", PGC_USERSET, UNGROUPED,
2458 gettext_noop("Sets the seed for random-number generation."),
2460 GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2464 check_random_seed, assign_random_seed, show_random_seed
2468 {"autovacuum_vacuum_scale_factor", PGC_SIGHUP, AUTOVACUUM,
2469 gettext_noop("Number of tuple updates or deletes prior to vacuum as a fraction of reltuples."),
2472 &autovacuum_vac_scale,
2477 {"autovacuum_analyze_scale_factor", PGC_SIGHUP, AUTOVACUUM,
2478 gettext_noop("Number of tuple inserts, updates or deletes prior to analyze as a fraction of reltuples."),
2481 &autovacuum_anl_scale,
2487 {"checkpoint_completion_target", PGC_SIGHUP, WAL_CHECKPOINTS,
2488 gettext_noop("Time spent flushing dirty buffers during checkpoint, as fraction of checkpoint interval."),
2491 &CheckPointCompletionTarget,
2496 /* End-of-list marker */
2498 {NULL, 0, 0, NULL, NULL}, NULL, 0.0, 0.0, 0.0, NULL, NULL, NULL
2503 static struct config_string ConfigureNamesString[] =
2506 {"archive_command", PGC_SIGHUP, WAL_ARCHIVING,
2507 gettext_noop("Sets the shell command that will be called to archive a WAL file."),
2510 &XLogArchiveCommand,
2512 NULL, NULL, show_archive_command
2516 {"client_encoding", PGC_USERSET, CLIENT_CONN_LOCALE,
2517 gettext_noop("Sets the client's character set encoding."),
2519 GUC_IS_NAME | GUC_REPORT
2521 &client_encoding_string,
2523 check_client_encoding, assign_client_encoding, NULL
2527 {"log_line_prefix", PGC_SIGHUP, LOGGING_WHAT,
2528 gettext_noop("Controls information prefixed to each log line."),
2529 gettext_noop("If blank, no prefix is used.")
2537 {"log_timezone", PGC_SIGHUP, LOGGING_WHAT,
2538 gettext_noop("Sets the time zone to use in log messages."),
2541 &log_timezone_string,
2543 check_log_timezone, assign_log_timezone, show_log_timezone
2547 {"DateStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
2548 gettext_noop("Sets the display format for date and time values."),
2549 gettext_noop("Also controls interpretation of ambiguous "
2551 GUC_LIST_INPUT | GUC_REPORT
2555 check_datestyle, assign_datestyle, NULL
2559 {"default_tablespace", PGC_USERSET, CLIENT_CONN_STATEMENT,
2560 gettext_noop("Sets the default tablespace to create tables and indexes in."),
2561 gettext_noop("An empty string selects the database's default tablespace."),
2564 &default_tablespace,
2566 check_default_tablespace, NULL, NULL
2570 {"temp_tablespaces", PGC_USERSET, CLIENT_CONN_STATEMENT,
2571 gettext_noop("Sets the tablespace(s) to use for temporary tables and sort files."),
2573 GUC_LIST_INPUT | GUC_LIST_QUOTE
2577 check_temp_tablespaces, assign_temp_tablespaces, NULL
2581 {"dynamic_library_path", PGC_SUSET, CLIENT_CONN_OTHER,
2582 gettext_noop("Sets the path for dynamically loadable modules."),
2583 gettext_noop("If a dynamically loadable module needs to be opened and "
2584 "the specified name does not have a directory component (i.e., the "
2585 "name does not contain a slash), the system will search this path for "
2586 "the specified file."),
2589 &Dynamic_library_path,
2595 {"krb_server_keyfile", PGC_SIGHUP, CONN_AUTH_SECURITY,
2596 gettext_noop("Sets the location of the Kerberos server key file."),
2600 &pg_krb_server_keyfile,
2606 {"krb_srvname", PGC_SIGHUP, CONN_AUTH_SECURITY,
2607 gettext_noop("Sets the name of the Kerberos service."),
2616 {"bonjour_name", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2617 gettext_noop("Sets the Bonjour service name."),
2625 /* See main.c about why defaults for LC_foo are not all alike */
2628 {"lc_collate", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2629 gettext_noop("Shows the collation order locale."),
2631 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2639 {"lc_ctype", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2640 gettext_noop("Shows the character classification and case conversion locale."),
2642 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2650 {"lc_messages", PGC_SUSET, CLIENT_CONN_LOCALE,
2651 gettext_noop("Sets the language in which messages are displayed."),
2656 check_locale_messages, assign_locale_messages, NULL
2660 {"lc_monetary", PGC_USERSET, CLIENT_CONN_LOCALE,
2661 gettext_noop("Sets the locale for formatting monetary amounts."),
2666 check_locale_monetary, assign_locale_monetary, NULL
2670 {"lc_numeric", PGC_USERSET, CLIENT_CONN_LOCALE,
2671 gettext_noop("Sets the locale for formatting numbers."),
2676 check_locale_numeric, assign_locale_numeric, NULL
2680 {"lc_time", PGC_USERSET, CLIENT_CONN_LOCALE,
2681 gettext_noop("Sets the locale for formatting date and time values."),
2686 check_locale_time, assign_locale_time, NULL
2690 {"shared_preload_libraries", PGC_POSTMASTER, RESOURCES_KERNEL,
2691 gettext_noop("Lists shared libraries to preload into server."),
2693 GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
2695 &shared_preload_libraries_string,
2701 {"local_preload_libraries", PGC_BACKEND, CLIENT_CONN_OTHER,
2702 gettext_noop("Lists shared libraries to preload into each backend."),
2704 GUC_LIST_INPUT | GUC_LIST_QUOTE
2706 &local_preload_libraries_string,
2712 {"search_path", PGC_USERSET, CLIENT_CONN_STATEMENT,
2713 gettext_noop("Sets the schema search order for names that are not schema-qualified."),
2715 GUC_LIST_INPUT | GUC_LIST_QUOTE
2717 &namespace_search_path,
2719 check_search_path, assign_search_path, NULL
2723 /* Can't be set in postgresql.conf */
2724 {"server_encoding", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2725 gettext_noop("Sets the server (database) character set encoding."),
2727 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2729 &server_encoding_string,
2735 /* Can't be set in postgresql.conf */
2736 {"server_version", PGC_INTERNAL, PRESET_OPTIONS,
2737 gettext_noop("Shows the server version."),
2739 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2741 &server_version_string,
2747 /* Not for general use --- used by SET ROLE */
2748 {"role", PGC_USERSET, UNGROUPED,
2749 gettext_noop("Sets the current role."),
2751 GUC_IS_NAME | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_NOT_WHILE_SEC_REST
2755 check_role, assign_role, show_role
2759 /* Not for general use --- used by SET SESSION AUTHORIZATION */
2760 {"session_authorization", PGC_USERSET, UNGROUPED,
2761 gettext_noop("Sets the session user name."),
2763 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
2765 &session_authorization_string,
2767 check_session_authorization, assign_session_authorization, NULL
2771 {"log_destination", PGC_SIGHUP, LOGGING_WHERE,
2772 gettext_noop("Sets the destination for server log output."),
2773 gettext_noop("Valid values are combinations of \"stderr\", "
2774 "\"syslog\", \"csvlog\", and \"eventlog\", "
2775 "depending on the platform."),
2778 &log_destination_string,
2780 check_log_destination, assign_log_destination, NULL
2783 {"log_directory", PGC_SIGHUP, LOGGING_WHERE,
2784 gettext_noop("Sets the destination directory for log files."),
2785 gettext_noop("Can be specified as relative to the data directory "
2786 "or as absolute path."),
2791 check_canonical_path, NULL, NULL
2794 {"log_filename", PGC_SIGHUP, LOGGING_WHERE,
2795 gettext_noop("Sets the file name pattern for log files."),
2800 "postgresql-%Y-%m-%d_%H%M%S.log",
2805 {"syslog_ident", PGC_SIGHUP, LOGGING_WHERE,
2806 gettext_noop("Sets the program name used to identify PostgreSQL "
2807 "messages in syslog."),
2812 NULL, assign_syslog_ident, NULL
2816 {"TimeZone", PGC_USERSET, CLIENT_CONN_LOCALE,
2817 gettext_noop("Sets the time zone for displaying and interpreting time stamps."),
2823 check_timezone, assign_timezone, show_timezone
2826 {"timezone_abbreviations", PGC_USERSET, CLIENT_CONN_LOCALE,
2827 gettext_noop("Selects a file of time zone abbreviations."),
2830 &timezone_abbreviations_string,
2832 check_timezone_abbreviations, assign_timezone_abbreviations, NULL
2836 {"transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
2837 gettext_noop("Sets the current transaction's isolation level."),
2839 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2841 &XactIsoLevel_string,
2843 check_XactIsoLevel, assign_XactIsoLevel, show_XactIsoLevel
2847 {"unix_socket_group", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2848 gettext_noop("Sets the owning group of the Unix-domain socket."),
2849 gettext_noop("The owning user of the socket is always the user "
2850 "that starts the server.")
2858 {"unix_socket_directory", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2859 gettext_noop("Sets the directory where the Unix-domain socket will be created."),
2865 check_canonical_path, NULL, NULL
2869 {"listen_addresses", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2870 gettext_noop("Sets the host name or IP address(es) to listen to."),
2880 {"custom_variable_classes", PGC_SIGHUP, CUSTOM_OPTIONS,
2881 gettext_noop("Sets the list of known custom variable classes."),
2883 GUC_LIST_INPUT | GUC_LIST_QUOTE
2885 &custom_variable_classes,
2887 check_custom_variable_classes, NULL, NULL
2891 {"data_directory", PGC_POSTMASTER, FILE_LOCATIONS,
2892 gettext_noop("Sets the server's data directory."),
2902 {"config_file", PGC_POSTMASTER, FILE_LOCATIONS,
2903 gettext_noop("Sets the server's main configuration file."),
2905 GUC_DISALLOW_IN_FILE | GUC_SUPERUSER_ONLY
2913 {"hba_file", PGC_POSTMASTER, FILE_LOCATIONS,
2914 gettext_noop("Sets the server's \"hba\" configuration file."),
2924 {"ident_file", PGC_POSTMASTER, FILE_LOCATIONS,
2925 gettext_noop("Sets the server's \"ident\" configuration file."),
2935 {"external_pid_file", PGC_POSTMASTER, FILE_LOCATIONS,
2936 gettext_noop("Writes the postmaster PID to the specified file."),
2942 check_canonical_path, NULL, NULL
2946 {"stats_temp_directory", PGC_SIGHUP, STATS_COLLECTOR,
2947 gettext_noop("Writes temporary statistics files to the specified directory."),
2951 &pgstat_temp_directory,
2953 check_canonical_path, assign_pgstat_temp_directory, NULL
2957 {"synchronous_standby_names", PGC_SIGHUP, WAL_REPLICATION,
2958 gettext_noop("List of potential standby names to synchronize with."),
2962 &SyncRepStandbyNames,
2964 check_synchronous_standby_names, NULL, NULL
2968 {"default_text_search_config", PGC_USERSET, CLIENT_CONN_LOCALE,
2969 gettext_noop("Sets default text search configuration."),
2973 "pg_catalog.simple",
2974 check_TSCurrentConfig, assign_TSCurrentConfig, NULL
2978 {"ssl_ciphers", PGC_POSTMASTER, CONN_AUTH_SECURITY,
2979 gettext_noop("Sets the list of allowed SSL ciphers."),
2985 "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH",
2993 {"application_name", PGC_USERSET, LOGGING_WHAT,
2994 gettext_noop("Sets the application name to be reported in statistics and logs."),
2996 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE
3000 check_application_name, assign_application_name, NULL
3003 /* End-of-list marker */
3005 {NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL, NULL
3010 static struct config_enum ConfigureNamesEnum[] =
3013 {"backslash_quote", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
3014 gettext_noop("Sets whether \"\\'\" is allowed in string literals."),
3018 BACKSLASH_QUOTE_SAFE_ENCODING, backslash_quote_options,
3023 {"bytea_output", PGC_USERSET, CLIENT_CONN_STATEMENT,
3024 gettext_noop("Sets the output format for bytea."),
3028 BYTEA_OUTPUT_HEX, bytea_output_options,
3033 {"client_min_messages", PGC_USERSET, LOGGING_WHEN,
3034 gettext_noop("Sets the message levels that are sent to the client."),
3035 gettext_noop("Each level includes all the levels that follow it. The later"
3036 " the level, the fewer messages are sent.")
3038 &client_min_messages,
3039 NOTICE, client_message_level_options,
3044 {"constraint_exclusion", PGC_USERSET, QUERY_TUNING_OTHER,
3045 gettext_noop("Enables the planner to use constraints to optimize queries."),
3046 gettext_noop("Table scans will be skipped if their constraints"
3047 " guarantee that no rows match the query.")
3049 &constraint_exclusion,
3050 CONSTRAINT_EXCLUSION_PARTITION, constraint_exclusion_options,
3055 {"default_transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
3056 gettext_noop("Sets the transaction isolation level of each new transaction."),
3059 &DefaultXactIsoLevel,
3060 XACT_READ_COMMITTED, isolation_level_options,
3065 {"IntervalStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
3066 gettext_noop("Sets the display format for interval values."),
3071 INTSTYLE_POSTGRES, intervalstyle_options,
3076 {"log_error_verbosity", PGC_SUSET, LOGGING_WHAT,
3077 gettext_noop("Sets the verbosity of logged messages."),
3080 &Log_error_verbosity,
3081 PGERROR_DEFAULT, log_error_verbosity_options,
3086 {"log_min_messages", PGC_SUSET, LOGGING_WHEN,
3087 gettext_noop("Sets the message levels that are logged."),
3088 gettext_noop("Each level includes all the levels that follow it. The later"
3089 " the level, the fewer messages are sent.")
3092 WARNING, server_message_level_options,
3097 {"log_min_error_statement", PGC_SUSET, LOGGING_WHEN,
3098 gettext_noop("Causes all statements generating error at or above this level to be logged."),
3099 gettext_noop("Each level includes all the levels that follow it. The later"
3100 " the level, the fewer messages are sent.")
3102 &log_min_error_statement,
3103 ERROR, server_message_level_options,
3108 {"log_statement", PGC_SUSET, LOGGING_WHAT,
3109 gettext_noop("Sets the type of statements logged."),
3113 LOGSTMT_NONE, log_statement_options,
3118 {"syslog_facility", PGC_SIGHUP, LOGGING_WHERE,
3119 gettext_noop("Sets the syslog \"facility\" to be used when syslog enabled."),
3128 syslog_facility_options,
3129 NULL, assign_syslog_facility, NULL
3133 {"session_replication_role", PGC_SUSET, CLIENT_CONN_STATEMENT,
3134 gettext_noop("Sets the session's behavior for triggers and rewrite rules."),
3137 &SessionReplicationRole,
3138 SESSION_REPLICATION_ROLE_ORIGIN, session_replication_role_options,
3139 NULL, assign_session_replication_role, NULL
3143 {"synchronous_commit", PGC_USERSET, WAL_SETTINGS,
3144 gettext_noop("Sets the current transaction's synchronization level."),
3147 &synchronous_commit,
3148 SYNCHRONOUS_COMMIT_ON, synchronous_commit_options,
3153 {"trace_recovery_messages", PGC_SIGHUP, DEVELOPER_OPTIONS,
3154 gettext_noop("Enables logging of recovery-related debugging information."),
3155 gettext_noop("Each level includes all the levels that follow it. The later"
3156 " the level, the fewer messages are sent.")
3158 &trace_recovery_messages,
3161 * client_message_level_options allows too many values, really, but
3162 * it's not worth having a separate options array for this.
3164 LOG, client_message_level_options,
3169 {"track_functions", PGC_SUSET, STATS_COLLECTOR,
3170 gettext_noop("Collects function-level statistics on database activity."),
3173 &pgstat_track_functions,
3174 TRACK_FUNC_OFF, track_function_options,
3179 {"wal_level", PGC_POSTMASTER, WAL_SETTINGS,
3180 gettext_noop("Set the level of information written to the WAL."),
3184 WAL_LEVEL_MINIMAL, wal_level_options,
3189 {"wal_sync_method", PGC_SIGHUP, WAL_SETTINGS,
3190 gettext_noop("Selects the method used for forcing WAL updates to disk."),
3194 DEFAULT_SYNC_METHOD, sync_method_options,
3195 NULL, assign_xlog_sync_method, NULL
3199 {"xmlbinary", PGC_USERSET, CLIENT_CONN_STATEMENT,
3200 gettext_noop("Sets how binary values are to be encoded in XML."),
3204 XMLBINARY_BASE64, xmlbinary_options,
3209 {"xmloption", PGC_USERSET, CLIENT_CONN_STATEMENT,
3210 gettext_noop("Sets whether XML data in implicit parsing and serialization "
3211 "operations is to be considered as documents or content fragments."),
3215 XMLOPTION_CONTENT, xmloption_options,
3220 /* End-of-list marker */
3222 {NULL, 0, 0, NULL, NULL}, NULL, 0, NULL, NULL, NULL, NULL
3226 /******** end of options list ********/
3230 * To allow continued support of obsolete names for GUC variables, we apply
3231 * the following mappings to any unrecognized name. Note that an old name
3232 * should be mapped to a new one only if the new variable has very similar
3233 * semantics to the old.
3235 static const char *const map_old_guc_names[] = {
3236 "sort_mem", "work_mem",
3237 "vacuum_mem", "maintenance_work_mem",
3243 * Actual lookup of variables is done through this single, sorted array.
3245 static struct config_generic **guc_variables;
3247 /* Current number of variables contained in the vector */
3248 static int num_guc_variables;
3250 /* Vector capacity */
3251 static int size_guc_variables;
3254 static bool guc_dirty; /* TRUE if need to do commit/abort work */
3256 static bool reporting_enabled; /* TRUE to enable GUC_REPORT */
3258 static int GUCNestLevel = 0; /* 1 when in main transaction */
3261 static int guc_var_compare(const void *a, const void *b);
3262 static int guc_name_compare(const char *namea, const char *nameb);
3263 static void InitializeGUCOptionsFromEnvironment(void);
3264 static void InitializeOneGUCOption(struct config_generic * gconf);
3265 static void push_old_value(struct config_generic * gconf, GucAction action);
3266 static void ReportGUCOption(struct config_generic * record);
3267 static void ShowGUCConfigOption(const char *name, DestReceiver *dest);
3268 static void ShowAllGUCConfig(DestReceiver *dest);
3269 static char *_ShowOption(struct config_generic * record, bool use_units);
3270 static bool validate_option_array_item(const char *name, const char *value,
3271 bool skipIfNoPermissions);
3275 * Some infrastructure for checking malloc/strdup/realloc calls
3278 guc_malloc(int elevel, size_t size)
3282 data = malloc(size);
3285 (errcode(ERRCODE_OUT_OF_MEMORY),
3286 errmsg("out of memory")));
3291 guc_realloc(int elevel, void *old, size_t size)
3295 data = realloc(old, size);
3298 (errcode(ERRCODE_OUT_OF_MEMORY),
3299 errmsg("out of memory")));
3304 guc_strdup(int elevel, const char *src)
3311 (errcode(ERRCODE_OUT_OF_MEMORY),
3312 errmsg("out of memory")));
3318 * Detect whether strval is referenced anywhere in a GUC string item
3321 string_field_used(struct config_string * conf, char *strval)
3325 if (strval == *(conf->variable) ||
3326 strval == conf->reset_val ||
3327 strval == conf->boot_val)
3329 for (stack = conf->gen.stack; stack; stack = stack->prev)
3331 if (strval == stack->prior.val.stringval ||
3332 strval == stack->masked.val.stringval)
3339 * Support for assigning to a field of a string GUC item. Free the prior
3340 * value if it's not referenced anywhere else in the item (including stacked
3344 set_string_field(struct config_string * conf, char **field, char *newval)
3346 char *oldval = *field;
3348 /* Do the assignment */
3351 /* Free old value if it's not NULL and isn't referenced anymore */
3352 if (oldval && !string_field_used(conf, oldval))
3357 * Detect whether an "extra" struct is referenced anywhere in a GUC item
3360 extra_field_used(struct config_generic * gconf, void *extra)
3364 if (extra == gconf->extra)
3366 switch (gconf->vartype)
3369 if (extra == ((struct config_bool *) gconf)->reset_extra)
3373 if (extra == ((struct config_int *) gconf)->reset_extra)
3377 if (extra == ((struct config_real *) gconf)->reset_extra)
3381 if (extra == ((struct config_string *) gconf)->reset_extra)
3385 if (extra == ((struct config_enum *) gconf)->reset_extra)
3389 for (stack = gconf->stack; stack; stack = stack->prev)
3391 if (extra == stack->prior.extra ||
3392 extra == stack->masked.extra)
3400 * Support for assigning to an "extra" field of a GUC item. Free the prior
3401 * value if it's not referenced anywhere else in the item (including stacked
3405 set_extra_field(struct config_generic * gconf, void **field, void *newval)
3407 void *oldval = *field;
3409 /* Do the assignment */
3412 /* Free old value if it's not NULL and isn't referenced anymore */
3413 if (oldval && !extra_field_used(gconf, oldval))
3418 * Support for copying a variable's active value into a stack entry.
3419 * The "extra" field associated with the active value is copied, too.
3421 * NB: be sure stringval and extra fields of a new stack entry are
3422 * initialized to NULL before this is used, else we'll try to free() them.
3425 set_stack_value(struct config_generic * gconf, config_var_value *val)
3427 switch (gconf->vartype)
3431 *((struct config_bool *) gconf)->variable;
3435 *((struct config_int *) gconf)->variable;
3439 *((struct config_real *) gconf)->variable;
3442 set_string_field((struct config_string *) gconf,
3443 &(val->val.stringval),
3444 *((struct config_string *) gconf)->variable);
3448 *((struct config_enum *) gconf)->variable;
3451 set_extra_field(gconf, &(val->extra), gconf->extra);
3455 * Support for discarding a no-longer-needed value in a stack entry.
3456 * The "extra" field associated with the stack entry is cleared, too.
3459 discard_stack_value(struct config_generic * gconf, config_var_value *val)
3461 switch (gconf->vartype)
3467 /* no need to do anything */
3470 set_string_field((struct config_string *) gconf,
3471 &(val->val.stringval),
3475 set_extra_field(gconf, &(val->extra), NULL);
3480 * Fetch the sorted array pointer (exported for help_config.c's use ONLY)
3482 struct config_generic **
3483 get_guc_variables(void)
3485 return guc_variables;
3490 * Build the sorted array. This is split out so that it could be
3491 * re-executed after startup (eg, we could allow loadable modules to
3492 * add vars, and then we'd need to re-sort).
3495 build_guc_variables(void)
3499 struct config_generic **guc_vars;
3502 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
3504 struct config_bool *conf = &ConfigureNamesBool[i];
3506 /* Rather than requiring vartype to be filled in by hand, do this: */
3507 conf->gen.vartype = PGC_BOOL;
3511 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
3513 struct config_int *conf = &ConfigureNamesInt[i];
3515 conf->gen.vartype = PGC_INT;
3519 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
3521 struct config_real *conf = &ConfigureNamesReal[i];
3523 conf->gen.vartype = PGC_REAL;
3527 for (i = 0; ConfigureNamesString[i].gen.name; i++)
3529 struct config_string *conf = &ConfigureNamesString[i];
3531 conf->gen.vartype = PGC_STRING;
3535 for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
3537 struct config_enum *conf = &ConfigureNamesEnum[i];
3539 conf->gen.vartype = PGC_ENUM;
3544 * Create table with 20% slack
3546 size_vars = num_vars + num_vars / 4;
3548 guc_vars = (struct config_generic **)
3549 guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
3553 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
3554 guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
3556 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
3557 guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
3559 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
3560 guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
3562 for (i = 0; ConfigureNamesString[i].gen.name; i++)
3563 guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
3565 for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
3566 guc_vars[num_vars++] = &ConfigureNamesEnum[i].gen;
3569 free(guc_variables);
3570 guc_variables = guc_vars;
3571 num_guc_variables = num_vars;
3572 size_guc_variables = size_vars;
3573 qsort((void *) guc_variables, num_guc_variables,
3574 sizeof(struct config_generic *), guc_var_compare);
3578 * Add a new GUC variable to the list of known variables. The
3579 * list is expanded if needed.
3582 add_guc_variable(struct config_generic * var, int elevel)
3584 if (num_guc_variables + 1 >= size_guc_variables)
3587 * Increase the vector by 25%
3589 int size_vars = size_guc_variables + size_guc_variables / 4;
3590 struct config_generic **guc_vars;
3595 guc_vars = (struct config_generic **)
3596 guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
3600 guc_vars = (struct config_generic **)
3601 guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
3604 if (guc_vars == NULL)
3605 return false; /* out of memory */
3607 guc_variables = guc_vars;
3608 size_guc_variables = size_vars;
3610 guc_variables[num_guc_variables++] = var;
3611 qsort((void *) guc_variables, num_guc_variables,
3612 sizeof(struct config_generic *), guc_var_compare);
3617 * Create and add a placeholder variable. It's presumed to belong
3618 * to a valid custom variable class at this point.
3620 static struct config_generic *
3621 add_placeholder_variable(const char *name, int elevel)
3623 size_t sz = sizeof(struct config_string) + sizeof(char *);
3624 struct config_string *var;
3625 struct config_generic *gen;
3627 var = (struct config_string *) guc_malloc(elevel, sz);
3633 gen->name = guc_strdup(elevel, name);
3634 if (gen->name == NULL)
3640 gen->context = PGC_USERSET;
3641 gen->group = CUSTOM_OPTIONS;
3642 gen->short_desc = "GUC placeholder variable";
3643 gen->flags = GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_CUSTOM_PLACEHOLDER;
3644 gen->vartype = PGC_STRING;
3647 * The char* is allocated at the end of the struct since we have no
3648 * 'static' place to point to. Note that the current value, as well as
3649 * the boot and reset values, start out NULL.
3651 var->variable = (char **) (var + 1);
3653 if (!add_guc_variable((struct config_generic *) var, elevel))
3655 free((void *) gen->name);
3664 * Detect whether the portion of "name" before dotPos matches any custom
3665 * variable class name listed in custom_var_classes. The latter must be
3666 * formatted the way that assign_custom_variable_classes does it, ie,
3667 * no whitespace. NULL is valid for custom_var_classes.
3670 is_custom_class(const char *name, int dotPos, const char *custom_var_classes)
3672 bool result = false;
3673 const char *ccs = custom_var_classes;
3677 const char *start = ccs;
3683 if (c == '\0' || c == ',')
3685 if (dotPos == ccs - start && strncmp(start, name, dotPos) == 0)
3700 * Look up option NAME. If it exists, return a pointer to its record,
3701 * else return NULL. If create_placeholders is TRUE, we'll create a
3702 * placeholder record for a valid-looking custom variable name.
3704 static struct config_generic *
3705 find_option(const char *name, bool create_placeholders, int elevel)
3707 const char **key = &name;
3708 struct config_generic **res;
3714 * By equating const char ** with struct config_generic *, we are assuming
3715 * the name field is first in config_generic.
3717 res = (struct config_generic **) bsearch((void *) &key,
3718 (void *) guc_variables,
3720 sizeof(struct config_generic *),
3726 * See if the name is an obsolete name for a variable. We assume that the
3727 * set of supported old names is short enough that a brute-force search is
3730 for (i = 0; map_old_guc_names[i] != NULL; i += 2)
3732 if (guc_name_compare(name, map_old_guc_names[i]) == 0)
3733 return find_option(map_old_guc_names[i + 1], false, elevel);
3736 if (create_placeholders)
3739 * Check if the name is qualified, and if so, check if the qualifier
3740 * matches any custom variable class. If so, add a placeholder.
3742 const char *dot = strchr(name, GUC_QUALIFIER_SEPARATOR);
3745 is_custom_class(name, dot - name, custom_variable_classes))
3746 return add_placeholder_variable(name, elevel);
3755 * comparator for qsorting and bsearching guc_variables array
3758 guc_var_compare(const void *a, const void *b)
3760 struct config_generic *confa = *(struct config_generic **) a;
3761 struct config_generic *confb = *(struct config_generic **) b;
3763 return guc_name_compare(confa->name, confb->name);
3767 * the bare comparison function for GUC names
3770 guc_name_compare(const char *namea, const char *nameb)
3773 * The temptation to use strcasecmp() here must be resisted, because the
3774 * array ordering has to remain stable across setlocale() calls. So, build
3775 * our own with a simple ASCII-only downcasing.
3777 while (*namea && *nameb)
3779 char cha = *namea++;
3780 char chb = *nameb++;
3782 if (cha >= 'A' && cha <= 'Z')
3784 if (chb >= 'A' && chb <= 'Z')
3790 return 1; /* a is longer */
3792 return -1; /* b is longer */
3798 * Initialize GUC options during program startup.
3800 * Note that we cannot read the config file yet, since we have not yet
3801 * processed command-line switches.
3804 InitializeGUCOptions(void)
3809 * Before log_line_prefix could possibly receive a nonempty setting, make
3810 * sure that timezone processing is minimally alive (see elog.c).
3812 pg_timezone_pre_initialize();
3815 * Build sorted array of all GUC variables.
3817 build_guc_variables();
3820 * Load all variables with their compiled-in defaults, and initialize
3821 * status fields as needed.
3823 for (i = 0; i < num_guc_variables; i++)
3825 InitializeOneGUCOption(guc_variables[i]);
3830 reporting_enabled = false;
3833 * Prevent any attempt to override the transaction modes from
3834 * non-interactive sources.
3836 SetConfigOption("transaction_isolation", "default",
3837 PGC_POSTMASTER, PGC_S_OVERRIDE);
3838 SetConfigOption("transaction_read_only", "no",
3839 PGC_POSTMASTER, PGC_S_OVERRIDE);
3840 SetConfigOption("transaction_deferrable", "no",
3841 PGC_POSTMASTER, PGC_S_OVERRIDE);
3844 * For historical reasons, some GUC parameters can receive defaults from
3845 * environment variables. Process those settings.
3847 InitializeGUCOptionsFromEnvironment();
3851 * Assign any GUC values that can come from the server's environment.
3853 * This is called from InitializeGUCOptions, and also from ProcessConfigFile
3854 * to deal with the possibility that a setting has been removed from
3855 * postgresql.conf and should now get a value from the environment.
3856 * (The latter is a kludge that should probably go away someday; if so,
3857 * fold this back into InitializeGUCOptions.)
3860 InitializeGUCOptionsFromEnvironment(void)
3865 env = getenv("PGPORT");
3867 SetConfigOption("port", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3869 env = getenv("PGDATESTYLE");
3871 SetConfigOption("datestyle", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3873 env = getenv("PGCLIENTENCODING");
3875 SetConfigOption("client_encoding", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3878 * rlimit isn't exactly an "environment variable", but it behaves about
3879 * the same. If we can identify the platform stack depth rlimit, increase
3880 * default stack depth setting up to whatever is safe (but at most 2MB).
3882 stack_rlimit = get_stack_depth_rlimit();
3883 if (stack_rlimit > 0)
3885 long new_limit = (stack_rlimit - STACK_DEPTH_SLOP) / 1024L;
3887 if (new_limit > 100)
3891 new_limit = Min(new_limit, 2048);
3892 sprintf(limbuf, "%ld", new_limit);
3893 SetConfigOption("max_stack_depth", limbuf,
3894 PGC_POSTMASTER, PGC_S_ENV_VAR);
3900 * Initialize one GUC option variable to its compiled-in default.
3902 * Note: the reason for calling check_hooks is not that we think the boot_val
3903 * might fail, but that the hooks might wish to compute an "extra" struct.
3906 InitializeOneGUCOption(struct config_generic * gconf)
3909 gconf->reset_source = PGC_S_DEFAULT;
3910 gconf->source = PGC_S_DEFAULT;
3911 gconf->stack = NULL;
3912 gconf->extra = NULL;
3913 gconf->sourcefile = NULL;
3914 gconf->sourceline = 0;
3916 switch (gconf->vartype)
3920 struct config_bool *conf = (struct config_bool *) gconf;
3921 bool newval = conf->boot_val;
3924 if (!call_bool_check_hook(conf, &newval, &extra,
3925 PGC_S_DEFAULT, LOG))
3926 elog(FATAL, "failed to initialize %s to %d",
3927 conf->gen.name, (int) newval);
3928 if (conf->assign_hook)
3929 (*conf->assign_hook) (newval, extra);
3930 *conf->variable = conf->reset_val = newval;
3931 conf->gen.extra = conf->reset_extra = extra;
3936 struct config_int *conf = (struct config_int *) gconf;
3937 int newval = conf->boot_val;
3940 Assert(newval >= conf->min);
3941 Assert(newval <= conf->max);
3942 if (!call_int_check_hook(conf, &newval, &extra,
3943 PGC_S_DEFAULT, LOG))
3944 elog(FATAL, "failed to initialize %s to %d",
3945 conf->gen.name, newval);
3946 if (conf->assign_hook)
3947 (*conf->assign_hook) (newval, extra);
3948 *conf->variable = conf->reset_val = newval;
3949 conf->gen.extra = conf->reset_extra = extra;
3954 struct config_real *conf = (struct config_real *) gconf;
3955 double newval = conf->boot_val;
3958 Assert(newval >= conf->min);
3959 Assert(newval <= conf->max);
3960 if (!call_real_check_hook(conf, &newval, &extra,
3961 PGC_S_DEFAULT, LOG))
3962 elog(FATAL, "failed to initialize %s to %g",
3963 conf->gen.name, newval);
3964 if (conf->assign_hook)
3965 (*conf->assign_hook) (newval, extra);
3966 *conf->variable = conf->reset_val = newval;
3967 conf->gen.extra = conf->reset_extra = extra;
3972 struct config_string *conf = (struct config_string *) gconf;
3976 /* non-NULL boot_val must always get strdup'd */
3977 if (conf->boot_val != NULL)
3978 newval = guc_strdup(FATAL, conf->boot_val);
3982 if (!call_string_check_hook(conf, &newval, &extra,
3983 PGC_S_DEFAULT, LOG))
3984 elog(FATAL, "failed to initialize %s to \"%s\"",
3985 conf->gen.name, newval ? newval : "");
3986 if (conf->assign_hook)
3987 (*conf->assign_hook) (newval, extra);
3988 *conf->variable = conf->reset_val = newval;
3989 conf->gen.extra = conf->reset_extra = extra;
3994 struct config_enum *conf = (struct config_enum *) gconf;
3995 int newval = conf->boot_val;
3998 if (!call_enum_check_hook(conf, &newval, &extra,
3999 PGC_S_DEFAULT, LOG))
4000 elog(FATAL, "failed to initialize %s to %d",
4001 conf->gen.name, newval);
4002 if (conf->assign_hook)
4003 (*conf->assign_hook) (newval, extra);
4004 *conf->variable = conf->reset_val = newval;
4005 conf->gen.extra = conf->reset_extra = extra;
4013 * Select the configuration files and data directory to be used, and
4014 * do the initial read of postgresql.conf.
4016 * This is called after processing command-line switches.
4017 * userDoption is the -D switch value if any (NULL if unspecified).
4018 * progname is just for use in error messages.
4020 * Returns true on success; on failure, prints a suitable error message
4021 * to stderr and returns false.
4024 SelectConfigFiles(const char *userDoption, const char *progname)
4028 struct stat stat_buf;
4030 /* configdir is -D option, or $PGDATA if no -D */
4032 configdir = make_absolute_path(userDoption);
4034 configdir = make_absolute_path(getenv("PGDATA"));
4037 * Find the configuration file: if config_file was specified on the
4038 * command line, use it, else use configdir/postgresql.conf. In any case
4039 * ensure the result is an absolute path, so that it will be interpreted
4040 * the same way by future backends.
4043 fname = make_absolute_path(ConfigFileName);
4046 fname = guc_malloc(FATAL,
4047 strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
4048 sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
4052 write_stderr("%s does not know where to find the server configuration file.\n"
4053 "You must specify the --config-file or -D invocation "
4054 "option or set the PGDATA environment variable.\n",
4060 * Set the ConfigFileName GUC variable to its final value, ensuring that
4061 * it can't be overridden later.
4063 SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4067 * Now read the config file for the first time.
4069 if (stat(ConfigFileName, &stat_buf) != 0)
4071 write_stderr("%s cannot access the server configuration file \"%s\": %s\n",
4072 progname, ConfigFileName, strerror(errno));
4076 ProcessConfigFile(PGC_POSTMASTER);
4079 * If the data_directory GUC variable has been set, use that as DataDir;
4080 * otherwise use configdir if set; else punt.
4082 * Note: SetDataDir will copy and absolute-ize its argument, so we don't
4086 SetDataDir(data_directory);
4088 SetDataDir(configdir);
4091 write_stderr("%s does not know where to find the database system data.\n"
4092 "This can be specified as \"data_directory\" in \"%s\", "
4093 "or by the -D invocation option, or by the "
4094 "PGDATA environment variable.\n",
4095 progname, ConfigFileName);
4100 * Reflect the final DataDir value back into the data_directory GUC var.
4101 * (If you are wondering why we don't just make them a single variable,
4102 * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
4103 * child backends specially. XXX is that still true? Given that we now
4104 * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
4105 * DataDir in advance.)
4107 SetConfigOption("data_directory", DataDir, PGC_POSTMASTER, PGC_S_OVERRIDE);
4110 * Figure out where pg_hba.conf is, and make sure the path is absolute.
4113 fname = make_absolute_path(HbaFileName);
4116 fname = guc_malloc(FATAL,
4117 strlen(configdir) + strlen(HBA_FILENAME) + 2);
4118 sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
4122 write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
4123 "This can be specified as \"hba_file\" in \"%s\", "
4124 "or by the -D invocation option, or by the "
4125 "PGDATA environment variable.\n",
4126 progname, ConfigFileName);
4129 SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4133 * Likewise for pg_ident.conf.
4136 fname = make_absolute_path(IdentFileName);
4139 fname = guc_malloc(FATAL,
4140 strlen(configdir) + strlen(IDENT_FILENAME) + 2);
4141 sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
4145 write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
4146 "This can be specified as \"ident_file\" in \"%s\", "
4147 "or by the -D invocation option, or by the "
4148 "PGDATA environment variable.\n",
4149 progname, ConfigFileName);
4152 SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4162 * Reset all options to their saved default values (implements RESET ALL)
4165 ResetAllOptions(void)
4169 for (i = 0; i < num_guc_variables; i++)
4171 struct config_generic *gconf = guc_variables[i];
4173 /* Don't reset non-SET-able values */
4174 if (gconf->context != PGC_SUSET &&
4175 gconf->context != PGC_USERSET)
4177 /* Don't reset if special exclusion from RESET ALL */
4178 if (gconf->flags & GUC_NO_RESET_ALL)
4180 /* No need to reset if wasn't SET */
4181 if (gconf->source <= PGC_S_OVERRIDE)
4184 /* Save old value to support transaction abort */
4185 push_old_value(gconf, GUC_ACTION_SET);
4187 switch (gconf->vartype)
4191 struct config_bool *conf = (struct config_bool *) gconf;
4193 if (conf->assign_hook)
4194 (*conf->assign_hook) (conf->reset_val,
4196 *conf->variable = conf->reset_val;
4197 set_extra_field(&conf->gen, &conf->gen.extra,
4203 struct config_int *conf = (struct config_int *) gconf;
4205 if (conf->assign_hook)
4206 (*conf->assign_hook) (conf->reset_val,
4208 *conf->variable = conf->reset_val;
4209 set_extra_field(&conf->gen, &conf->gen.extra,
4215 struct config_real *conf = (struct config_real *) gconf;
4217 if (conf->assign_hook)
4218 (*conf->assign_hook) (conf->reset_val,
4220 *conf->variable = conf->reset_val;
4221 set_extra_field(&conf->gen, &conf->gen.extra,
4227 struct config_string *conf = (struct config_string *) gconf;
4229 if (conf->assign_hook)
4230 (*conf->assign_hook) (conf->reset_val,
4232 set_string_field(conf, conf->variable, conf->reset_val);
4233 set_extra_field(&conf->gen, &conf->gen.extra,
4239 struct config_enum *conf = (struct config_enum *) gconf;
4241 if (conf->assign_hook)
4242 (*conf->assign_hook) (conf->reset_val,
4244 *conf->variable = conf->reset_val;
4245 set_extra_field(&conf->gen, &conf->gen.extra,
4251 gconf->source = gconf->reset_source;
4253 if (gconf->flags & GUC_REPORT)
4254 ReportGUCOption(gconf);
4261 * Push previous state during transactional assignment to a GUC variable.
4264 push_old_value(struct config_generic * gconf, GucAction action)
4268 /* If we're not inside a nest level, do nothing */
4269 if (GUCNestLevel == 0)
4272 /* Do we already have a stack entry of the current nest level? */
4273 stack = gconf->stack;
4274 if (stack && stack->nest_level >= GUCNestLevel)
4276 /* Yes, so adjust its state if necessary */
4277 Assert(stack->nest_level == GUCNestLevel);
4280 case GUC_ACTION_SET:
4281 /* SET overrides any prior action at same nest level */
4282 if (stack->state == GUC_SET_LOCAL)
4284 /* must discard old masked value */
4285 discard_stack_value(gconf, &stack->masked);
4287 stack->state = GUC_SET;
4289 case GUC_ACTION_LOCAL:
4290 if (stack->state == GUC_SET)
4292 /* SET followed by SET LOCAL, remember SET's value */
4293 set_stack_value(gconf, &stack->masked);
4294 stack->state = GUC_SET_LOCAL;
4296 /* in all other cases, no change to stack entry */
4298 case GUC_ACTION_SAVE:
4299 /* Could only have a prior SAVE of same variable */
4300 Assert(stack->state == GUC_SAVE);
4303 Assert(guc_dirty); /* must be set already */
4308 * Push a new stack entry
4310 * We keep all the stack entries in TopTransactionContext for simplicity.
4312 stack = (GucStack *) MemoryContextAllocZero(TopTransactionContext,
4315 stack->prev = gconf->stack;
4316 stack->nest_level = GUCNestLevel;
4319 case GUC_ACTION_SET:
4320 stack->state = GUC_SET;
4322 case GUC_ACTION_LOCAL:
4323 stack->state = GUC_LOCAL;
4325 case GUC_ACTION_SAVE:
4326 stack->state = GUC_SAVE;
4329 stack->source = gconf->source;
4330 set_stack_value(gconf, &stack->prior);
4332 gconf->stack = stack;
4334 /* Ensure we remember to pop at end of xact */
4340 * Do GUC processing at main transaction start.
4346 * The nest level should be 0 between transactions; if it isn't, somebody
4347 * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
4348 * throw a warning but make no other effort to clean up.
4350 if (GUCNestLevel != 0)
4351 elog(WARNING, "GUC nest level = %d at transaction start",
4357 * Enter a new nesting level for GUC values. This is called at subtransaction
4358 * start and when entering a function that has proconfig settings. NOTE that
4359 * we must not risk error here, else subtransaction start will be unhappy.
4362 NewGUCNestLevel(void)
4364 return ++GUCNestLevel;
4368 * Do GUC processing at transaction or subtransaction commit or abort, or
4369 * when exiting a function that has proconfig settings. (The name is thus
4370 * a bit of a misnomer; perhaps it should be ExitGUCNestLevel or some such.)
4371 * During abort, we discard all GUC settings that were applied at nesting
4372 * levels >= nestLevel. nestLevel == 1 corresponds to the main transaction.
4375 AtEOXact_GUC(bool isCommit, int nestLevel)
4381 * Note: it's possible to get here with GUCNestLevel == nestLevel-1 during
4382 * abort, if there is a failure during transaction start before
4383 * AtStart_GUC is called.
4385 Assert(nestLevel > 0 &&
4386 (nestLevel <= GUCNestLevel ||
4387 (nestLevel == GUCNestLevel + 1 && !isCommit)));
4389 /* Quick exit if nothing's changed in this transaction */
4392 GUCNestLevel = nestLevel - 1;
4396 still_dirty = false;
4397 for (i = 0; i < num_guc_variables; i++)
4399 struct config_generic *gconf = guc_variables[i];
4403 * Process and pop each stack entry within the nest level. To
4404 * simplify fmgr_security_definer(), we allow failure exit from a
4405 * function-with-SET-options to be recovered at the surrounding
4406 * transaction or subtransaction abort; so there could be more than
4407 * one stack entry to pop.
4409 while ((stack = gconf->stack) != NULL &&
4410 stack->nest_level >= nestLevel)
4412 GucStack *prev = stack->prev;
4413 bool restorePrior = false;
4414 bool restoreMasked = false;
4418 * In this next bit, if we don't set either restorePrior or
4419 * restoreMasked, we must "discard" any unwanted fields of the
4420 * stack entries to avoid leaking memory. If we do set one of
4421 * those flags, unused fields will be cleaned up after restoring.
4423 if (!isCommit) /* if abort, always restore prior value */
4424 restorePrior = true;
4425 else if (stack->state == GUC_SAVE)
4426 restorePrior = true;
4427 else if (stack->nest_level == 1)
4429 /* transaction commit */
4430 if (stack->state == GUC_SET_LOCAL)
4431 restoreMasked = true;
4432 else if (stack->state == GUC_SET)
4434 /* we keep the current active value */
4435 discard_stack_value(gconf, &stack->prior);
4437 else /* must be GUC_LOCAL */
4438 restorePrior = true;
4440 else if (prev == NULL ||
4441 prev->nest_level < stack->nest_level - 1)
4443 /* decrement entry's level and do not pop it */
4444 stack->nest_level--;
4450 * We have to merge this stack entry into prev. See README for
4451 * discussion of this bit.
4453 switch (stack->state)
4456 Assert(false); /* can't get here */
4459 /* next level always becomes SET */
4460 discard_stack_value(gconf, &stack->prior);
4461 if (prev->state == GUC_SET_LOCAL)
4462 discard_stack_value(gconf, &prev->masked);
4463 prev->state = GUC_SET;
4467 if (prev->state == GUC_SET)
4469 /* LOCAL migrates down */
4470 prev->masked = stack->prior;
4471 prev->state = GUC_SET_LOCAL;
4475 /* else just forget this stack level */
4476 discard_stack_value(gconf, &stack->prior);
4481 /* prior state at this level no longer wanted */
4482 discard_stack_value(gconf, &stack->prior);
4483 /* copy down the masked state */
4484 if (prev->state == GUC_SET_LOCAL)
4485 discard_stack_value(gconf, &prev->masked);
4486 prev->masked = stack->masked;
4487 prev->state = GUC_SET_LOCAL;
4494 if (restorePrior || restoreMasked)
4496 /* Perform appropriate restoration of the stacked value */
4497 config_var_value newvalue;
4498 GucSource newsource;
4502 newvalue = stack->masked;
4503 newsource = PGC_S_SESSION;
4507 newvalue = stack->prior;
4508 newsource = stack->source;
4511 switch (gconf->vartype)
4515 struct config_bool *conf = (struct config_bool *) gconf;
4516 bool newval = newvalue.val.boolval;
4517 void *newextra = newvalue.extra;
4519 if (*conf->variable != newval ||
4520 conf->gen.extra != newextra)
4522 if (conf->assign_hook)
4523 (*conf->assign_hook) (newval, newextra);
4524 *conf->variable = newval;
4525 set_extra_field(&conf->gen, &conf->gen.extra,
4533 struct config_int *conf = (struct config_int *) gconf;
4534 int newval = newvalue.val.intval;
4535 void *newextra = newvalue.extra;
4537 if (*conf->variable != newval ||
4538 conf->gen.extra != newextra)
4540 if (conf->assign_hook)
4541 (*conf->assign_hook) (newval, newextra);
4542 *conf->variable = newval;
4543 set_extra_field(&conf->gen, &conf->gen.extra,
4551 struct config_real *conf = (struct config_real *) gconf;
4552 double newval = newvalue.val.realval;
4553 void *newextra = newvalue.extra;
4555 if (*conf->variable != newval ||
4556 conf->gen.extra != newextra)
4558 if (conf->assign_hook)
4559 (*conf->assign_hook) (newval, newextra);
4560 *conf->variable = newval;
4561 set_extra_field(&conf->gen, &conf->gen.extra,
4569 struct config_string *conf = (struct config_string *) gconf;
4570 char *newval = newvalue.val.stringval;
4571 void *newextra = newvalue.extra;
4573 if (*conf->variable != newval ||
4574 conf->gen.extra != newextra)
4576 if (conf->assign_hook)
4577 (*conf->assign_hook) (newval, newextra);
4578 set_string_field(conf, conf->variable, newval);
4579 set_extra_field(&conf->gen, &conf->gen.extra,
4585 * Release stacked values if not used anymore. We
4586 * could use discard_stack_value() here, but since
4587 * we have type-specific code anyway, might as
4590 set_string_field(conf, &stack->prior.val.stringval, NULL);
4591 set_string_field(conf, &stack->masked.val.stringval, NULL);
4596 struct config_enum *conf = (struct config_enum *) gconf;
4597 int newval = newvalue.val.enumval;
4598 void *newextra = newvalue.extra;
4600 if (*conf->variable != newval ||
4601 conf->gen.extra != newextra)
4603 if (conf->assign_hook)
4604 (*conf->assign_hook) (newval, newextra);
4605 *conf->variable = newval;
4606 set_extra_field(&conf->gen, &conf->gen.extra,
4615 * Release stacked extra values if not used anymore.
4617 set_extra_field(gconf, &(stack->prior.extra), NULL);
4618 set_extra_field(gconf, &(stack->masked.extra), NULL);
4620 gconf->source = newsource;
4623 /* Finish popping the state stack */
4624 gconf->stack = prev;
4627 /* Report new value if we changed it */
4628 if (changed && (gconf->flags & GUC_REPORT))
4629 ReportGUCOption(gconf);
4630 } /* end of stack-popping loop */
4636 /* If there are no remaining stack entries, we can reset guc_dirty */
4637 guc_dirty = still_dirty;
4639 /* Update nesting level */
4640 GUCNestLevel = nestLevel - 1;
4645 * Start up automatic reporting of changes to variables marked GUC_REPORT.
4646 * This is executed at completion of backend startup.
4649 BeginReportingGUCOptions(void)
4654 * Don't do anything unless talking to an interactive frontend of protocol
4657 if (whereToSendOutput != DestRemote ||
4658 PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
4661 reporting_enabled = true;
4663 /* Transmit initial values of interesting variables */
4664 for (i = 0; i < num_guc_variables; i++)
4666 struct config_generic *conf = guc_variables[i];
4668 if (conf->flags & GUC_REPORT)
4669 ReportGUCOption(conf);
4674 * ReportGUCOption: if appropriate, transmit option value to frontend
4677 ReportGUCOption(struct config_generic * record)
4679 if (reporting_enabled && (record->flags & GUC_REPORT))
4681 char *val = _ShowOption(record, false);
4682 StringInfoData msgbuf;
4684 pq_beginmessage(&msgbuf, 'S');
4685 pq_sendstring(&msgbuf, record->name);
4686 pq_sendstring(&msgbuf, val);
4687 pq_endmessage(&msgbuf);
4694 * Try to parse value as an integer. The accepted formats are the
4695 * usual decimal, octal, or hexadecimal formats, optionally followed by
4696 * a unit name if "flags" indicates a unit is allowed.
4698 * If the string parses okay, return true, else false.
4699 * If okay and result is not NULL, return the value in *result.
4700 * If not okay and hintmsg is not NULL, *hintmsg is set to a suitable
4701 * HINT message, or NULL if no hint provided.
4704 parse_int(const char *value, int *result, int flags, const char **hintmsg)
4709 /* To suppress compiler warnings, always set output params */
4715 /* We assume here that int64 is at least as wide as long */
4717 val = strtol(value, &endptr, 0);
4719 if (endptr == value)
4720 return false; /* no HINT for integer syntax error */
4722 if (errno == ERANGE || val != (int64) ((int32) val))
4725 *hintmsg = gettext_noop("Value exceeds integer range.");
4729 /* allow whitespace between integer and unit */
4730 while (isspace((unsigned char) *endptr))
4733 /* Handle possible unit */
4734 if (*endptr != '\0')
4737 * Note: the multiple-switch coding technique here is a bit tedious,
4738 * but seems necessary to avoid intermediate-value overflows.
4740 if (flags & GUC_UNIT_MEMORY)
4742 /* Set hint for use if no match or trailing garbage */
4744 *hintmsg = gettext_noop("Valid units for this parameter are \"kB\", \"MB\", and \"GB\".");
4746 #if BLCKSZ < 1024 || BLCKSZ > (1024*1024)
4747 #error BLCKSZ must be between 1KB and 1MB
4749 #if XLOG_BLCKSZ < 1024 || XLOG_BLCKSZ > (1024*1024)
4750 #error XLOG_BLCKSZ must be between 1KB and 1MB
4753 if (strncmp(endptr, "kB", 2) == 0)
4756 switch (flags & GUC_UNIT_MEMORY)
4758 case GUC_UNIT_BLOCKS:
4759 val /= (BLCKSZ / 1024);
4761 case GUC_UNIT_XBLOCKS:
4762 val /= (XLOG_BLCKSZ / 1024);
4766 else if (strncmp(endptr, "MB", 2) == 0)
4769 switch (flags & GUC_UNIT_MEMORY)
4774 case GUC_UNIT_BLOCKS:
4775 val *= KB_PER_MB / (BLCKSZ / 1024);
4777 case GUC_UNIT_XBLOCKS:
4778 val *= KB_PER_MB / (XLOG_BLCKSZ / 1024);
4782 else if (strncmp(endptr, "GB", 2) == 0)
4785 switch (flags & GUC_UNIT_MEMORY)
4790 case GUC_UNIT_BLOCKS:
4791 val *= KB_PER_GB / (BLCKSZ / 1024);
4793 case GUC_UNIT_XBLOCKS:
4794 val *= KB_PER_GB / (XLOG_BLCKSZ / 1024);
4799 else if (flags & GUC_UNIT_TIME)
4801 /* Set hint for use if no match or trailing garbage */
4803 *hintmsg = gettext_noop("Valid units for this parameter are \"ms\", \"s\", \"min\", \"h\", and \"d\".");
4805 if (strncmp(endptr, "ms", 2) == 0)
4808 switch (flags & GUC_UNIT_TIME)
4818 else if (strncmp(endptr, "s", 1) == 0)
4821 switch (flags & GUC_UNIT_TIME)
4831 else if (strncmp(endptr, "min", 3) == 0)
4834 switch (flags & GUC_UNIT_TIME)
4844 else if (strncmp(endptr, "h", 1) == 0)
4847 switch (flags & GUC_UNIT_TIME)
4860 else if (strncmp(endptr, "d", 1) == 0)
4863 switch (flags & GUC_UNIT_TIME)
4878 /* allow whitespace after unit */
4879 while (isspace((unsigned char) *endptr))
4882 if (*endptr != '\0')
4883 return false; /* appropriate hint, if any, already set */
4885 /* Check for overflow due to units conversion */
4886 if (val != (int64) ((int32) val))
4889 *hintmsg = gettext_noop("Value exceeds integer range.");
4895 *result = (int) val;
4902 * Try to parse value as a floating point number in the usual format.
4903 * If the string parses okay, return true, else false.
4904 * If okay and result is not NULL, return the value in *result.
4907 parse_real(const char *value, double *result)
4913 *result = 0; /* suppress compiler warning */
4916 val = strtod(value, &endptr);
4917 if (endptr == value || errno == ERANGE)
4920 /* allow whitespace after number */
4921 while (isspace((unsigned char) *endptr))
4923 if (*endptr != '\0')
4933 * Lookup the name for an enum option with the selected value.
4934 * Should only ever be called with known-valid values, so throws
4935 * an elog(ERROR) if the enum option is not found.
4937 * The returned string is a pointer to static data and not
4938 * allocated for modification.
4941 config_enum_lookup_by_value(struct config_enum * record, int val)
4943 const struct config_enum_entry *entry;
4945 for (entry = record->options; entry && entry->name; entry++)
4947 if (entry->val == val)
4951 elog(ERROR, "could not find enum option %d for %s",
4952 val, record->gen.name);
4953 return NULL; /* silence compiler */
4958 * Lookup the value for an enum option with the selected name
4959 * (case-insensitive).
4960 * If the enum option is found, sets the retval value and returns
4961 * true. If it's not found, return FALSE and retval is set to 0.
4964 config_enum_lookup_by_name(struct config_enum * record, const char *value,
4967 const struct config_enum_entry *entry;
4969 for (entry = record->options; entry && entry->name; entry++)
4971 if (pg_strcasecmp(value, entry->name) == 0)
4973 *retval = entry->val;
4984 * Return a list of all available options for an enum, excluding
4985 * hidden ones, separated by the given separator.
4986 * If prefix is non-NULL, it is added before the first enum value.
4987 * If suffix is non-NULL, it is added to the end of the string.
4990 config_enum_get_options(struct config_enum * record, const char *prefix,
4991 const char *suffix, const char *separator)
4993 const struct config_enum_entry *entry;
4994 StringInfoData retstr;
4997 initStringInfo(&retstr);
4998 appendStringInfoString(&retstr, prefix);
5000 seplen = strlen(separator);
5001 for (entry = record->options; entry && entry->name; entry++)
5005 appendStringInfoString(&retstr, entry->name);
5006 appendBinaryStringInfo(&retstr, separator, seplen);
5011 * All the entries may have been hidden, leaving the string empty if no
5012 * prefix was given. This indicates a broken GUC setup, since there is no
5013 * use for an enum without any values, so we just check to make sure we
5014 * don't write to invalid memory instead of actually trying to do
5015 * something smart with it.
5017 if (retstr.len >= seplen)
5019 /* Replace final separator */
5020 retstr.data[retstr.len - seplen] = '\0';
5021 retstr.len -= seplen;
5024 appendStringInfoString(&retstr, suffix);
5031 * Sets option `name' to given value. The value should be a string
5032 * which is going to be parsed and converted to the appropriate data
5033 * type. The context and source parameters indicate in which context this
5034 * function is being called so it can apply the access restrictions
5037 * If value is NULL, set the option to its default value (normally the
5038 * reset_val, but if source == PGC_S_DEFAULT we instead use the boot_val).
5040 * action indicates whether to set the value globally in the session, locally
5041 * to the current top transaction, or just for the duration of a function call.
5043 * If changeVal is false then don't really set the option but do all
5044 * the checks to see if it would work.
5046 * If there is an error (non-existing option, invalid value) then an
5047 * ereport(ERROR) is thrown *unless* this is called in a context where we
5048 * don't want to ereport (currently, startup or SIGHUP config file reread).
5049 * In that case we write a suitable error message via ereport(LOG) and
5050 * return false. This is working around the deficiencies in the ereport
5051 * mechanism, so don't blame me. In all other cases, the function
5052 * returns true, including cases where the input is valid but we chose
5053 * not to apply it because of context or source-priority considerations.
5055 * See also SetConfigOption for an external interface.
5058 set_config_option(const char *name, const char *value,
5059 GucContext context, GucSource source,
5060 GucAction action, bool changeVal)
5062 struct config_generic *record;
5064 bool prohibitValueChange = false;
5067 if (context == PGC_SIGHUP || source == PGC_S_DEFAULT)
5070 * To avoid cluttering the log, only the postmaster bleats loudly
5071 * about problems with the config file.
5073 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
5075 else if (source == PGC_S_DATABASE || source == PGC_S_USER ||
5076 source == PGC_S_DATABASE_USER)
5081 record = find_option(name, true, elevel);
5085 (errcode(ERRCODE_UNDEFINED_OBJECT),
5086 errmsg("unrecognized configuration parameter \"%s\"", name)));
5091 * If source is postgresql.conf, mark the found record with
5092 * GUC_IS_IN_FILE. This is for the convenience of ProcessConfigFile. Note
5093 * that we do it even if changeVal is false, since ProcessConfigFile wants
5094 * the marking to occur during its testing pass.
5096 if (source == PGC_S_FILE)
5097 record->status |= GUC_IS_IN_FILE;
5100 * Check if the option can be set at this time. See guc.h for the precise
5103 switch (record->context)
5106 if (context == PGC_SIGHUP)
5109 * Historically we've just silently ignored attempts to set
5110 * PGC_INTERNAL variables from the config file. Maybe it'd be
5111 * better to use the prohibitValueChange logic for this?
5115 else if (context != PGC_INTERNAL)
5118 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5119 errmsg("parameter \"%s\" cannot be changed",
5124 case PGC_POSTMASTER:
5125 if (context == PGC_SIGHUP)
5128 * We are re-reading a PGC_POSTMASTER variable from
5129 * postgresql.conf. We can't change the setting, so we should
5130 * give a warning if the DBA tries to change it. However,
5131 * because of variant formats, canonicalization by check
5132 * hooks, etc, we can't just compare the given string directly
5133 * to what's stored. Set a flag to check below after we have
5134 * the final storable value.
5136 * During the "checking" pass we just do nothing, to avoid
5137 * printing the warning twice.
5142 prohibitValueChange = true;
5144 else if (context != PGC_POSTMASTER)
5147 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5148 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5154 if (context != PGC_SIGHUP && context != PGC_POSTMASTER)
5157 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5158 errmsg("parameter \"%s\" cannot be changed now",
5164 * Hmm, the idea of the SIGHUP context is "ought to be global, but
5165 * can be changed after postmaster start". But there's nothing
5166 * that prevents a crafty administrator from sending SIGHUP
5167 * signals to individual backends only.
5171 if (context == PGC_SIGHUP)
5174 * If a PGC_BACKEND parameter is changed in the config file,
5175 * we want to accept the new value in the postmaster (whence
5176 * it will propagate to subsequently-started backends), but
5177 * ignore it in existing backends. This is a tad klugy, but
5178 * necessary because we don't re-read the config file during
5181 if (IsUnderPostmaster)
5184 else if (context != PGC_POSTMASTER && context != PGC_BACKEND &&
5185 source != PGC_S_CLIENT)
5188 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5189 errmsg("parameter \"%s\" cannot be set after connection start",
5195 if (context == PGC_USERSET || context == PGC_BACKEND)
5198 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5199 errmsg("permission denied to set parameter \"%s\"",
5210 * Disallow changing GUC_NOT_WHILE_SEC_REST values if we are inside a
5211 * security restriction context. We can reject this regardless of the GUC
5212 * context or source, mainly because sources that it might be reasonable
5213 * to override for won't be seen while inside a function.
5215 * Note: variables marked GUC_NOT_WHILE_SEC_REST should usually be marked
5216 * GUC_NO_RESET_ALL as well, because ResetAllOptions() doesn't check this.
5217 * An exception might be made if the reset value is assumed to be "safe".
5219 * Note: this flag is currently used for "session_authorization" and
5220 * "role". We need to prohibit changing these inside a local userid
5221 * context because when we exit it, GUC won't be notified, leaving things
5222 * out of sync. (This could be fixed by forcing a new GUC nesting level,
5223 * but that would change behavior in possibly-undesirable ways.) Also, we
5224 * prohibit changing these in a security-restricted operation because
5225 * otherwise RESET could be used to regain the session user's privileges.
5227 if (record->flags & GUC_NOT_WHILE_SEC_REST)
5229 if (InLocalUserIdChange())
5232 * Phrasing of this error message is historical, but it's the most
5236 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5237 errmsg("cannot set parameter \"%s\" within security-definer function",
5241 if (InSecurityRestrictedOperation())
5244 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5245 errmsg("cannot set parameter \"%s\" within security-restricted operation",
5252 * Should we set reset/stacked values? (If so, the behavior is not
5253 * transactional.) This is done either when we get a default value from
5254 * the database's/user's/client's default settings or when we reset a
5255 * value to its default.
5257 makeDefault = changeVal && (source <= PGC_S_OVERRIDE) &&
5258 ((value != NULL) || source == PGC_S_DEFAULT);
5261 * Ignore attempted set if overridden by previously processed setting.
5262 * However, if changeVal is false then plow ahead anyway since we are
5263 * trying to find out if the value is potentially good, not actually use
5264 * it. Also keep going if makeDefault is true, since we may want to set
5265 * the reset/stacked values even if we can't set the variable itself.
5267 if (record->source > source)
5269 if (changeVal && !makeDefault)
5271 elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
5279 * Evaluate value and set variable.
5281 switch (record->vartype)
5285 struct config_bool *conf = (struct config_bool *) record;
5287 void *newextra = NULL;
5291 if (!parse_bool(value, &newval))
5294 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5295 errmsg("parameter \"%s\" requires a Boolean value",
5299 if (!call_bool_check_hook(conf, &newval, &newextra,
5303 else if (source == PGC_S_DEFAULT)
5305 newval = conf->boot_val;
5306 if (!call_bool_check_hook(conf, &newval, &newextra,
5312 newval = conf->reset_val;
5313 newextra = conf->reset_extra;
5314 source = conf->gen.reset_source;
5317 if (prohibitValueChange)
5319 if (*conf->variable != newval)
5321 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5322 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5329 /* Save old value to support transaction abort */
5331 push_old_value(&conf->gen, action);
5333 if (conf->assign_hook)
5334 (*conf->assign_hook) (newval, newextra);
5335 *conf->variable = newval;
5336 set_extra_field(&conf->gen, &conf->gen.extra,
5338 conf->gen.source = source;
5344 if (conf->gen.reset_source <= source)
5346 conf->reset_val = newval;
5347 set_extra_field(&conf->gen, &conf->reset_extra,
5349 conf->gen.reset_source = source;
5351 for (stack = conf->gen.stack; stack; stack = stack->prev)
5353 if (stack->source <= source)
5355 stack->prior.val.boolval = newval;
5356 set_extra_field(&conf->gen, &stack->prior.extra,
5358 stack->source = source;
5363 /* Perhaps we didn't install newextra anywhere */
5364 if (newextra && !extra_field_used(&conf->gen, newextra))
5371 struct config_int *conf = (struct config_int *) record;
5373 void *newextra = NULL;
5377 const char *hintmsg;
5379 if (!parse_int(value, &newval, conf->gen.flags, &hintmsg))
5382 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5383 errmsg("invalid value for parameter \"%s\": \"%s\"",
5385 hintmsg ? errhint("%s", _(hintmsg)) : 0));
5388 if (newval < conf->min || newval > conf->max)
5391 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5392 errmsg("%d is outside the valid range for parameter \"%s\" (%d .. %d)",
5393 newval, name, conf->min, conf->max)));
5396 if (!call_int_check_hook(conf, &newval, &newextra,
5400 else if (source == PGC_S_DEFAULT)
5402 newval = conf->boot_val;
5403 if (!call_int_check_hook(conf, &newval, &newextra,
5409 newval = conf->reset_val;
5410 newextra = conf->reset_extra;
5411 source = conf->gen.reset_source;
5414 if (prohibitValueChange)
5416 if (*conf->variable != newval)
5418 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5419 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5426 /* Save old value to support transaction abort */
5428 push_old_value(&conf->gen, action);
5430 if (conf->assign_hook)
5431 (*conf->assign_hook) (newval, newextra);
5432 *conf->variable = newval;
5433 set_extra_field(&conf->gen, &conf->gen.extra,
5435 conf->gen.source = source;
5441 if (conf->gen.reset_source <= source)
5443 conf->reset_val = newval;
5444 set_extra_field(&conf->gen, &conf->reset_extra,
5446 conf->gen.reset_source = source;
5448 for (stack = conf->gen.stack; stack; stack = stack->prev)
5450 if (stack->source <= source)
5452 stack->prior.val.intval = newval;
5453 set_extra_field(&conf->gen, &stack->prior.extra,
5455 stack->source = source;
5460 /* Perhaps we didn't install newextra anywhere */
5461 if (newextra && !extra_field_used(&conf->gen, newextra))
5468 struct config_real *conf = (struct config_real *) record;
5470 void *newextra = NULL;
5474 if (!parse_real(value, &newval))
5477 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5478 errmsg("parameter \"%s\" requires a numeric value",
5482 if (newval < conf->min || newval > conf->max)
5485 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5486 errmsg("%g is outside the valid range for parameter \"%s\" (%g .. %g)",
5487 newval, name, conf->min, conf->max)));
5490 if (!call_real_check_hook(conf, &newval, &newextra,
5494 else if (source == PGC_S_DEFAULT)
5496 newval = conf->boot_val;
5497 if (!call_real_check_hook(conf, &newval, &newextra,
5503 newval = conf->reset_val;
5504 newextra = conf->reset_extra;
5505 source = conf->gen.reset_source;
5508 if (prohibitValueChange)
5510 if (*conf->variable != newval)
5512 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5513 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5520 /* Save old value to support transaction abort */
5522 push_old_value(&conf->gen, action);
5524 if (conf->assign_hook)
5525 (*conf->assign_hook) (newval, newextra);
5526 *conf->variable = newval;
5527 set_extra_field(&conf->gen, &conf->gen.extra,
5529 conf->gen.source = source;
5535 if (conf->gen.reset_source <= source)
5537 conf->reset_val = newval;
5538 set_extra_field(&conf->gen, &conf->reset_extra,
5540 conf->gen.reset_source = source;
5542 for (stack = conf->gen.stack; stack; stack = stack->prev)
5544 if (stack->source <= source)
5546 stack->prior.val.realval = newval;
5547 set_extra_field(&conf->gen, &stack->prior.extra,
5549 stack->source = source;
5554 /* Perhaps we didn't install newextra anywhere */
5555 if (newextra && !extra_field_used(&conf->gen, newextra))
5562 struct config_string *conf = (struct config_string *) record;
5564 void *newextra = NULL;
5569 * The value passed by the caller could be transient, so
5570 * we always strdup it.
5572 newval = guc_strdup(elevel, value);
5577 * The only built-in "parsing" check we have is to apply
5578 * truncation if GUC_IS_NAME.
5580 if (conf->gen.flags & GUC_IS_NAME)
5581 truncate_identifier(newval, strlen(newval), true);
5583 if (!call_string_check_hook(conf, &newval, &newextra,
5590 else if (source == PGC_S_DEFAULT)
5592 /* non-NULL boot_val must always get strdup'd */
5593 if (conf->boot_val != NULL)
5595 newval = guc_strdup(elevel, conf->boot_val);
5602 if (!call_string_check_hook(conf, &newval, &newextra,
5612 * strdup not needed, since reset_val is already under
5615 newval = conf->reset_val;
5616 newextra = conf->reset_extra;
5617 source = conf->gen.reset_source;
5620 if (prohibitValueChange)
5622 /* newval shouldn't be NULL, so we're a bit sloppy here */
5623 if (*conf->variable == NULL || newval == NULL ||
5624 strcmp(*conf->variable, newval) != 0)
5626 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5627 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5634 /* Save old value to support transaction abort */
5636 push_old_value(&conf->gen, action);
5638 if (conf->assign_hook)
5639 (*conf->assign_hook) (newval, newextra);
5640 set_string_field(conf, conf->variable, newval);
5641 set_extra_field(&conf->gen, &conf->gen.extra,
5643 conf->gen.source = source;
5650 if (conf->gen.reset_source <= source)
5652 set_string_field(conf, &conf->reset_val, newval);
5653 set_extra_field(&conf->gen, &conf->reset_extra,
5655 conf->gen.reset_source = source;
5657 for (stack = conf->gen.stack; stack; stack = stack->prev)
5659 if (stack->source <= source)
5661 set_string_field(conf, &stack->prior.val.stringval,
5663 set_extra_field(&conf->gen, &stack->prior.extra,
5665 stack->source = source;
5670 /* Perhaps we didn't install newval anywhere */
5671 if (newval && !string_field_used(conf, newval))
5673 /* Perhaps we didn't install newextra anywhere */
5674 if (newextra && !extra_field_used(&conf->gen, newextra))
5681 struct config_enum *conf = (struct config_enum *) record;
5683 void *newextra = NULL;
5687 if (!config_enum_lookup_by_name(conf, value, &newval))
5691 hintmsg = config_enum_get_options(conf,
5692 "Available values: ",
5696 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5697 errmsg("invalid value for parameter \"%s\": \"%s\"",
5699 hintmsg ? errhint("%s", _(hintmsg)) : 0));
5705 if (!call_enum_check_hook(conf, &newval, &newextra,
5709 else if (source == PGC_S_DEFAULT)
5711 newval = conf->boot_val;
5712 if (!call_enum_check_hook(conf, &newval, &newextra,
5718 newval = conf->reset_val;
5719 newextra = conf->reset_extra;
5720 source = conf->gen.reset_source;
5723 if (prohibitValueChange)
5725 if (*conf->variable != newval)
5727 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5728 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5735 /* Save old value to support transaction abort */
5737 push_old_value(&conf->gen, action);
5739 if (conf->assign_hook)
5740 (*conf->assign_hook) (newval, newextra);
5741 *conf->variable = newval;
5742 set_extra_field(&conf->gen, &conf->gen.extra,
5744 conf->gen.source = source;
5750 if (conf->gen.reset_source <= source)
5752 conf->reset_val = newval;
5753 set_extra_field(&conf->gen, &conf->reset_extra,
5755 conf->gen.reset_source = source;
5757 for (stack = conf->gen.stack; stack; stack = stack->prev)
5759 if (stack->source <= source)
5761 stack->prior.val.enumval = newval;
5762 set_extra_field(&conf->gen, &stack->prior.extra,
5764 stack->source = source;
5769 /* Perhaps we didn't install newextra anywhere */
5770 if (newextra && !extra_field_used(&conf->gen, newextra))
5776 if (changeVal && (record->flags & GUC_REPORT))
5777 ReportGUCOption(record);
5784 * Set the fields for source file and line number the setting came from.
5787 set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
5789 struct config_generic *record;
5793 * To avoid cluttering the log, only the postmaster bleats loudly about
5794 * problems with the config file.
5796 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
5798 record = find_option(name, true, elevel);
5799 /* should not happen */
5801 elog(ERROR, "unrecognized configuration parameter \"%s\"", name);
5803 sourcefile = guc_strdup(elevel, sourcefile);
5804 if (record->sourcefile)
5805 free(record->sourcefile);
5806 record->sourcefile = sourcefile;
5807 record->sourceline = sourceline;
5811 * Set a config option to the given value. See also set_config_option,
5812 * this is just the wrapper to be called from outside GUC. NB: this
5813 * is used only for non-transactional operations.
5815 * Note: there is no support here for setting source file/line, as it
5816 * is currently not needed.
5819 SetConfigOption(const char *name, const char *value,
5820 GucContext context, GucSource source)
5822 (void) set_config_option(name, value, context, source,
5823 GUC_ACTION_SET, true);
5829 * Fetch the current value of the option `name'. If the option doesn't exist,
5830 * throw an ereport and don't return.
5832 * If restrict_superuser is true, we also enforce that only superusers can
5833 * see GUC_SUPERUSER_ONLY variables. This should only be passed as true
5834 * in user-driven calls.
5836 * The string is *not* allocated for modification and is really only
5837 * valid until the next call to configuration related functions.
5840 GetConfigOption(const char *name, bool restrict_superuser)
5842 struct config_generic *record;
5843 static char buffer[256];
5845 record = find_option(name, false, ERROR);
5848 (errcode(ERRCODE_UNDEFINED_OBJECT),
5849 errmsg("unrecognized configuration parameter \"%s\"", name)));
5850 if (restrict_superuser &&
5851 (record->flags & GUC_SUPERUSER_ONLY) &&
5854 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5855 errmsg("must be superuser to examine \"%s\"", name)));
5857 switch (record->vartype)
5860 return *((struct config_bool *) record)->variable ? "on" : "off";
5863 snprintf(buffer, sizeof(buffer), "%d",
5864 *((struct config_int *) record)->variable);
5868 snprintf(buffer, sizeof(buffer), "%g",
5869 *((struct config_real *) record)->variable);
5873 return *((struct config_string *) record)->variable;
5876 return config_enum_lookup_by_value((struct config_enum *) record,
5877 *((struct config_enum *) record)->variable);
5883 * Get the RESET value associated with the given option.
5885 * Note: this is not re-entrant, due to use of static result buffer;
5886 * not to mention that a string variable could have its reset_val changed.
5887 * Beware of assuming the result value is good for very long.
5890 GetConfigOptionResetString(const char *name)
5892 struct config_generic *record;
5893 static char buffer[256];
5895 record = find_option(name, false, ERROR);
5898 (errcode(ERRCODE_UNDEFINED_OBJECT),
5899 errmsg("unrecognized configuration parameter \"%s\"", name)));
5900 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
5902 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5903 errmsg("must be superuser to examine \"%s\"", name)));
5905 switch (record->vartype)
5908 return ((struct config_bool *) record)->reset_val ? "on" : "off";
5911 snprintf(buffer, sizeof(buffer), "%d",
5912 ((struct config_int *) record)->reset_val);
5916 snprintf(buffer, sizeof(buffer), "%g",
5917 ((struct config_real *) record)->reset_val);
5921 return ((struct config_string *) record)->reset_val;
5924 return config_enum_lookup_by_value((struct config_enum *) record,
5925 ((struct config_enum *) record)->reset_val);
5932 * flatten_set_variable_args
5933 * Given a parsenode List as emitted by the grammar for SET,
5934 * convert to the flat string representation used by GUC.
5936 * We need to be told the name of the variable the args are for, because
5937 * the flattening rules vary (ugh).
5939 * The result is NULL if args is NIL (ie, SET ... TO DEFAULT), otherwise
5940 * a palloc'd string.
5943 flatten_set_variable_args(const char *name, List *args)
5945 struct config_generic *record;
5950 /* Fast path if just DEFAULT */
5955 * Get flags for the variable; if it's not known, use default flags.
5956 * (Caller might throw error later, but not our business to do so here.)
5958 record = find_option(name, false, WARNING);
5960 flags = record->flags;
5964 /* Complain if list input and non-list variable */
5965 if ((flags & GUC_LIST_INPUT) == 0 &&
5966 list_length(args) != 1)
5968 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5969 errmsg("SET %s takes only one argument", name)));
5971 initStringInfo(&buf);
5974 * Each list member may be a plain A_Const node, or an A_Const within a
5975 * TypeCast; the latter case is supported only for ConstInterval arguments
5976 * (for SET TIME ZONE).
5980 Node *arg = (Node *) lfirst(l);
5982 TypeName *typeName = NULL;
5985 if (l != list_head(args))
5986 appendStringInfo(&buf, ", ");
5988 if (IsA(arg, TypeCast))
5990 TypeCast *tc = (TypeCast *) arg;
5993 typeName = tc->typeName;
5996 if (!IsA(arg, A_Const))
5997 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
5998 con = (A_Const *) arg;
6000 switch (nodeTag(&con->val))
6003 appendStringInfo(&buf, "%ld", intVal(&con->val));
6006 /* represented as a string, so just copy it */
6007 appendStringInfoString(&buf, strVal(&con->val));
6010 val = strVal(&con->val);
6011 if (typeName != NULL)
6014 * Must be a ConstInterval argument for TIME ZONE. Coerce
6015 * to interval and back to normalize the value and account
6023 typenameTypeIdAndMod(NULL, typeName, &typoid, &typmod);
6024 Assert(typoid == INTERVALOID);
6027 DirectFunctionCall3(interval_in,
6028 CStringGetDatum(val),
6029 ObjectIdGetDatum(InvalidOid),
6030 Int32GetDatum(typmod));
6033 DatumGetCString(DirectFunctionCall1(interval_out,
6035 appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
6040 * Plain string literal or identifier. For quote mode,
6041 * quote it if it's not a vanilla identifier.
6043 if (flags & GUC_LIST_QUOTE)
6044 appendStringInfoString(&buf, quote_identifier(val));
6046 appendStringInfoString(&buf, val);
6050 elog(ERROR, "unrecognized node type: %d",
6051 (int) nodeTag(&con->val));
6064 ExecSetVariableStmt(VariableSetStmt *stmt)
6066 GucAction action = stmt->is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET;
6071 case VAR_SET_CURRENT:
6072 set_config_option(stmt->name,
6073 ExtractSetVariableArgs(stmt),
6074 (superuser() ? PGC_SUSET : PGC_USERSET),
6082 * Special case for special SQL syntax that effectively sets more
6083 * than one variable per statement.
6085 if (strcmp(stmt->name, "TRANSACTION") == 0)
6089 foreach(head, stmt->args)
6091 DefElem *item = (DefElem *) lfirst(head);
6093 if (strcmp(item->defname, "transaction_isolation") == 0)
6094 SetPGVariable("transaction_isolation",
6095 list_make1(item->arg), stmt->is_local);
6096 else if (strcmp(item->defname, "transaction_read_only") == 0)
6097 SetPGVariable("transaction_read_only",
6098 list_make1(item->arg), stmt->is_local);
6099 else if (strcmp(item->defname, "transaction_deferrable") == 0)
6100 SetPGVariable("transaction_deferrable",
6101 list_make1(item->arg), stmt->is_local);
6103 elog(ERROR, "unexpected SET TRANSACTION element: %s",
6107 else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
6111 foreach(head, stmt->args)
6113 DefElem *item = (DefElem *) lfirst(head);
6115 if (strcmp(item->defname, "transaction_isolation") == 0)
6116 SetPGVariable("default_transaction_isolation",
6117 list_make1(item->arg), stmt->is_local);
6118 else if (strcmp(item->defname, "transaction_read_only") == 0)
6119 SetPGVariable("default_transaction_read_only",
6120 list_make1(item->arg), stmt->is_local);
6121 else if (strcmp(item->defname, "transaction_deferrable") == 0)
6122 SetPGVariable("default_transaction_deferrable",
6123 list_make1(item->arg), stmt->is_local);
6125 elog(ERROR, "unexpected SET SESSION element: %s",
6130 elog(ERROR, "unexpected SET MULTI element: %s",
6133 case VAR_SET_DEFAULT:
6135 set_config_option(stmt->name,
6137 (superuser() ? PGC_SUSET : PGC_USERSET),
6149 * Get the value to assign for a VariableSetStmt, or NULL if it's RESET.
6150 * The result is palloc'd.
6152 * This is exported for use by actions such as ALTER ROLE SET.
6155 ExtractSetVariableArgs(VariableSetStmt *stmt)
6160 return flatten_set_variable_args(stmt->name, stmt->args);
6161 case VAR_SET_CURRENT:
6162 return GetConfigOptionByName(stmt->name, NULL);
6169 * SetPGVariable - SET command exported as an easily-C-callable function.
6171 * This provides access to SET TO value, as well as SET TO DEFAULT (expressed
6172 * by passing args == NIL), but not SET FROM CURRENT functionality.
6175 SetPGVariable(const char *name, List *args, bool is_local)
6177 char *argstring = flatten_set_variable_args(name, args);
6179 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
6180 set_config_option(name,
6182 (superuser() ? PGC_SUSET : PGC_USERSET),
6184 is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET,
6189 * SET command wrapped as a SQL callable function.
6192 set_config_by_name(PG_FUNCTION_ARGS)
6199 if (PG_ARGISNULL(0))
6201 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
6202 errmsg("SET requires parameter name")));
6204 /* Get the GUC variable name */
6205 name = TextDatumGetCString(PG_GETARG_DATUM(0));
6207 /* Get the desired value or set to NULL for a reset request */
6208 if (PG_ARGISNULL(1))
6211 value = TextDatumGetCString(PG_GETARG_DATUM(1));
6214 * Get the desired state of is_local. Default to false if provided value
6217 if (PG_ARGISNULL(2))
6220 is_local = PG_GETARG_BOOL(2);
6222 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
6223 set_config_option(name,
6225 (superuser() ? PGC_SUSET : PGC_USERSET),
6227 is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET,
6230 /* get the new current value */
6231 new_value = GetConfigOptionByName(name, NULL);
6233 /* Convert return string to text */
6234 PG_RETURN_TEXT_P(cstring_to_text(new_value));
6239 * Common code for DefineCustomXXXVariable subroutines: allocate the
6240 * new variable's config struct and fill in generic fields.
6242 static struct config_generic *
6243 init_custom_variable(const char *name,
6244 const char *short_desc,
6245 const char *long_desc,
6248 enum config_type type,
6251 struct config_generic *gen;
6254 * Only allow custom PGC_POSTMASTER variables to be created during shared
6255 * library preload; any later than that, we can't ensure that the value
6256 * doesn't change after startup. This is a fatal elog if it happens; just
6257 * erroring out isn't safe because we don't know what the calling loadable
6258 * module might already have hooked into.
6260 if (context == PGC_POSTMASTER &&
6261 !process_shared_preload_libraries_in_progress)
6262 elog(FATAL, "cannot create PGC_POSTMASTER variables after startup");
6264 gen = (struct config_generic *) guc_malloc(ERROR, sz);
6267 gen->name = guc_strdup(ERROR, name);
6268 gen->context = context;
6269 gen->group = CUSTOM_OPTIONS;
6270 gen->short_desc = short_desc;
6271 gen->long_desc = long_desc;
6273 gen->vartype = type;
6279 * Common code for DefineCustomXXXVariable subroutines: insert the new
6280 * variable into the GUC variable array, replacing any placeholder.
6283 define_custom_variable(struct config_generic * variable)
6285 const char *name = variable->name;
6286 const char **nameAddr = &name;
6288 struct config_string *pHolder;
6289 GucContext phcontext;
6290 struct config_generic **res;
6293 * See if there's a placeholder by the same name.
6295 res = (struct config_generic **) bsearch((void *) &nameAddr,
6296 (void *) guc_variables,
6298 sizeof(struct config_generic *),
6303 * No placeholder to replace, so we can just add it ... but first,
6304 * make sure it's initialized to its default value.
6306 InitializeOneGUCOption(variable);
6307 add_guc_variable(variable, ERROR);
6312 * This better be a placeholder
6314 if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
6316 (errcode(ERRCODE_INTERNAL_ERROR),
6317 errmsg("attempt to redefine parameter \"%s\"", name)));
6319 Assert((*res)->vartype == PGC_STRING);
6320 pHolder = (struct config_string *) (*res);
6323 * First, set the variable to its default value. We must do this even
6324 * though we intend to immediately apply a new value, since it's possible
6325 * that the new value is invalid.
6327 InitializeOneGUCOption(variable);
6330 * Replace the placeholder. We aren't changing the name, so no re-sorting
6336 * Infer context for assignment based on source of existing value. We
6337 * can't tell this with exact accuracy, but we can at least do something
6338 * reasonable in typical cases.
6340 switch (pHolder->gen.source)
6343 case PGC_S_DYNAMIC_DEFAULT:
6349 * If we got past the check in init_custom_variable, we can safely
6350 * assume that any existing value for a PGC_POSTMASTER variable
6351 * was set in postmaster context.
6353 if (variable->context == PGC_POSTMASTER)
6354 phcontext = PGC_POSTMASTER;
6356 phcontext = PGC_SIGHUP;
6359 case PGC_S_DATABASE:
6361 case PGC_S_DATABASE_USER:
6364 * The existing value came from an ALTER ROLE/DATABASE SET
6365 * command. We can assume that at the time the command was issued,
6366 * we checked that the issuing user was superuser if the variable
6367 * requires superuser privileges to set. So it's safe to use
6368 * SUSET context here.
6370 phcontext = PGC_SUSET;
6378 * We must assume that the value came from an untrusted user, even
6379 * if the current_user is a superuser.
6381 phcontext = PGC_USERSET;
6386 * Assign the string value stored in the placeholder to the real variable.
6388 * XXX this is not really good enough --- it should be a nontransactional
6389 * assignment, since we don't want it to roll back if the current xact
6390 * fails later. (Or do we?)
6392 value = *pHolder->variable;
6396 if (set_config_option(name, value,
6397 phcontext, pHolder->gen.source,
6398 GUC_ACTION_SET, true))
6400 /* Also copy over any saved source-location information */
6401 if (pHolder->gen.sourcefile)
6402 set_config_sourcefile(name, pHolder->gen.sourcefile,
6403 pHolder->gen.sourceline);
6408 * Free up as much as we conveniently can of the placeholder structure
6409 * (this neglects any stack items...)
6411 set_string_field(pHolder, pHolder->variable, NULL);
6412 set_string_field(pHolder, &pHolder->reset_val, NULL);
6418 DefineCustomBoolVariable(const char *name,
6419 const char *short_desc,
6420 const char *long_desc,
6425 GucBoolCheckHook check_hook,
6426 GucBoolAssignHook assign_hook,
6427 GucShowHook show_hook)
6429 struct config_bool *var;
6431 var = (struct config_bool *)
6432 init_custom_variable(name, short_desc, long_desc, context, flags,
6433 PGC_BOOL, sizeof(struct config_bool));
6434 var->variable = valueAddr;
6435 var->boot_val = bootValue;
6436 var->reset_val = bootValue;
6437 var->check_hook = check_hook;
6438 var->assign_hook = assign_hook;
6439 var->show_hook = show_hook;
6440 define_custom_variable(&var->gen);
6444 DefineCustomIntVariable(const char *name,
6445 const char *short_desc,
6446 const char *long_desc,
6453 GucIntCheckHook check_hook,
6454 GucIntAssignHook assign_hook,
6455 GucShowHook show_hook)
6457 struct config_int *var;
6459 var = (struct config_int *)
6460 init_custom_variable(name, short_desc, long_desc, context, flags,
6461 PGC_INT, sizeof(struct config_int));
6462 var->variable = valueAddr;
6463 var->boot_val = bootValue;
6464 var->reset_val = bootValue;
6465 var->min = minValue;
6466 var->max = maxValue;
6467 var->check_hook = check_hook;
6468 var->assign_hook = assign_hook;
6469 var->show_hook = show_hook;
6470 define_custom_variable(&var->gen);
6474 DefineCustomRealVariable(const char *name,
6475 const char *short_desc,
6476 const char *long_desc,
6483 GucRealCheckHook check_hook,
6484 GucRealAssignHook assign_hook,
6485 GucShowHook show_hook)
6487 struct config_real *var;
6489 var = (struct config_real *)
6490 init_custom_variable(name, short_desc, long_desc, context, flags,
6491 PGC_REAL, sizeof(struct config_real));
6492 var->variable = valueAddr;
6493 var->boot_val = bootValue;
6494 var->reset_val = bootValue;
6495 var->min = minValue;
6496 var->max = maxValue;
6497 var->check_hook = check_hook;
6498 var->assign_hook = assign_hook;
6499 var->show_hook = show_hook;
6500 define_custom_variable(&var->gen);
6504 DefineCustomStringVariable(const char *name,
6505 const char *short_desc,
6506 const char *long_desc,
6508 const char *bootValue,
6511 GucStringCheckHook check_hook,
6512 GucStringAssignHook assign_hook,
6513 GucShowHook show_hook)
6515 struct config_string *var;
6517 var = (struct config_string *)
6518 init_custom_variable(name, short_desc, long_desc, context, flags,
6519 PGC_STRING, sizeof(struct config_string));
6520 var->variable = valueAddr;
6521 var->boot_val = bootValue;
6522 var->check_hook = check_hook;
6523 var->assign_hook = assign_hook;
6524 var->show_hook = show_hook;
6525 define_custom_variable(&var->gen);
6529 DefineCustomEnumVariable(const char *name,
6530 const char *short_desc,
6531 const char *long_desc,
6534 const struct config_enum_entry * options,
6537 GucEnumCheckHook check_hook,
6538 GucEnumAssignHook assign_hook,
6539 GucShowHook show_hook)
6541 struct config_enum *var;
6543 var = (struct config_enum *)
6544 init_custom_variable(name, short_desc, long_desc, context, flags,
6545 PGC_ENUM, sizeof(struct config_enum));
6546 var->variable = valueAddr;
6547 var->boot_val = bootValue;
6548 var->reset_val = bootValue;
6549 var->options = options;
6550 var->check_hook = check_hook;
6551 var->assign_hook = assign_hook;
6552 var->show_hook = show_hook;
6553 define_custom_variable(&var->gen);
6557 EmitWarningsOnPlaceholders(const char *className)
6559 int classLen = strlen(className);
6562 for (i = 0; i < num_guc_variables; i++)
6564 struct config_generic *var = guc_variables[i];
6566 if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
6567 strncmp(className, var->name, classLen) == 0 &&
6568 var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
6571 (errcode(ERRCODE_UNDEFINED_OBJECT),
6572 errmsg("unrecognized configuration parameter \"%s\"",
6583 GetPGVariable(const char *name, DestReceiver *dest)
6585 if (guc_name_compare(name, "all") == 0)
6586 ShowAllGUCConfig(dest);
6588 ShowGUCConfigOption(name, dest);
6592 GetPGVariableResultDesc(const char *name)
6596 if (guc_name_compare(name, "all") == 0)
6598 /* need a tuple descriptor representing three TEXT columns */
6599 tupdesc = CreateTemplateTupleDesc(3, false);
6600 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
6602 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
6604 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
6609 const char *varname;
6611 /* Get the canonical spelling of name */
6612 (void) GetConfigOptionByName(name, &varname);
6614 /* need a tuple descriptor representing a single TEXT column */
6615 tupdesc = CreateTemplateTupleDesc(1, false);
6616 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
6627 ShowGUCConfigOption(const char *name, DestReceiver *dest)
6629 TupOutputState *tstate;
6631 const char *varname;
6634 /* Get the value and canonical spelling of name */
6635 value = GetConfigOptionByName(name, &varname);
6637 /* need a tuple descriptor representing a single TEXT column */
6638 tupdesc = CreateTemplateTupleDesc(1, false);
6639 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
6642 /* prepare for projection of tuples */
6643 tstate = begin_tup_output_tupdesc(dest, tupdesc);
6646 do_text_output_oneline(tstate, value);
6648 end_tup_output(tstate);
6655 ShowAllGUCConfig(DestReceiver *dest)
6657 bool am_superuser = superuser();
6659 TupOutputState *tstate;
6662 bool isnull[3] = {false, false, false};
6664 /* need a tuple descriptor representing three TEXT columns */
6665 tupdesc = CreateTemplateTupleDesc(3, false);
6666 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
6668 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
6670 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
6673 /* prepare for projection of tuples */
6674 tstate = begin_tup_output_tupdesc(dest, tupdesc);
6676 for (i = 0; i < num_guc_variables; i++)
6678 struct config_generic *conf = guc_variables[i];
6681 if ((conf->flags & GUC_NO_SHOW_ALL) ||
6682 ((conf->flags & GUC_SUPERUSER_ONLY) && !am_superuser))
6685 /* assign to the values array */
6686 values[0] = PointerGetDatum(cstring_to_text(conf->name));
6688 setting = _ShowOption(conf, true);
6691 values[1] = PointerGetDatum(cstring_to_text(setting));
6696 values[1] = PointerGetDatum(NULL);
6700 values[2] = PointerGetDatum(cstring_to_text(conf->short_desc));
6702 /* send it to dest */
6703 do_tup_output(tstate, values, isnull);
6706 pfree(DatumGetPointer(values[0]));
6710 pfree(DatumGetPointer(values[1]));
6712 pfree(DatumGetPointer(values[2]));
6715 end_tup_output(tstate);
6719 * Return GUC variable value by name; optionally return canonical
6720 * form of name. Return value is palloc'd.
6723 GetConfigOptionByName(const char *name, const char **varname)
6725 struct config_generic *record;
6727 record = find_option(name, false, ERROR);
6730 (errcode(ERRCODE_UNDEFINED_OBJECT),
6731 errmsg("unrecognized configuration parameter \"%s\"", name)));
6732 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
6734 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6735 errmsg("must be superuser to examine \"%s\"", name)));
6738 *varname = record->name;
6740 return _ShowOption(record, true);
6744 * Return GUC variable value by variable number; optionally return canonical
6745 * form of name. Return value is palloc'd.
6748 GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
6751 struct config_generic *conf;
6753 /* check requested variable number valid */
6754 Assert((varnum >= 0) && (varnum < num_guc_variables));
6756 conf = guc_variables[varnum];
6760 if ((conf->flags & GUC_NO_SHOW_ALL) ||
6761 ((conf->flags & GUC_SUPERUSER_ONLY) && !superuser()))
6767 /* first get the generic attributes */
6770 values[0] = conf->name;
6772 /* setting : use _ShowOption in order to avoid duplicating the logic */
6773 values[1] = _ShowOption(conf, false);
6776 if (conf->vartype == PGC_INT)
6780 switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
6785 case GUC_UNIT_BLOCKS:
6786 snprintf(buf, sizeof(buf), "%dkB", BLCKSZ / 1024);
6789 case GUC_UNIT_XBLOCKS:
6790 snprintf(buf, sizeof(buf), "%dkB", XLOG_BLCKSZ / 1024);
6811 values[3] = config_group_names[conf->group];
6814 values[4] = conf->short_desc;
6817 values[5] = conf->long_desc;
6820 values[6] = GucContext_Names[conf->context];
6823 values[7] = config_type_names[conf->vartype];
6826 values[8] = GucSource_Names[conf->source];
6828 /* now get the type specifc attributes */
6829 switch (conf->vartype)
6833 struct config_bool *lconf = (struct config_bool *) conf;
6845 values[12] = pstrdup(lconf->boot_val ? "on" : "off");
6848 values[13] = pstrdup(lconf->reset_val ? "on" : "off");
6854 struct config_int *lconf = (struct config_int *) conf;
6857 snprintf(buffer, sizeof(buffer), "%d", lconf->min);
6858 values[9] = pstrdup(buffer);
6861 snprintf(buffer, sizeof(buffer), "%d", lconf->max);
6862 values[10] = pstrdup(buffer);
6868 snprintf(buffer, sizeof(buffer), "%d", lconf->boot_val);
6869 values[12] = pstrdup(buffer);
6872 snprintf(buffer, sizeof(buffer), "%d", lconf->reset_val);
6873 values[13] = pstrdup(buffer);
6879 struct config_real *lconf = (struct config_real *) conf;
6882 snprintf(buffer, sizeof(buffer), "%g", lconf->min);
6883 values[9] = pstrdup(buffer);
6886 snprintf(buffer, sizeof(buffer), "%g", lconf->max);
6887 values[10] = pstrdup(buffer);
6893 snprintf(buffer, sizeof(buffer), "%g", lconf->boot_val);
6894 values[12] = pstrdup(buffer);
6897 snprintf(buffer, sizeof(buffer), "%g", lconf->reset_val);
6898 values[13] = pstrdup(buffer);
6904 struct config_string *lconf = (struct config_string *) conf;
6916 if (lconf->boot_val == NULL)
6919 values[12] = pstrdup(lconf->boot_val);
6922 if (lconf->reset_val == NULL)
6925 values[13] = pstrdup(lconf->reset_val);
6931 struct config_enum *lconf = (struct config_enum *) conf;
6942 * NOTE! enumvals with double quotes in them are not
6945 values[11] = config_enum_get_options((struct config_enum *) conf,
6946 "{\"", "\"}", "\",\"");
6949 values[12] = pstrdup(config_enum_lookup_by_value(lconf,
6953 values[13] = pstrdup(config_enum_lookup_by_value(lconf,
6961 * should never get here, but in case we do, set 'em to NULL
6983 * If the setting came from a config file, set the source location. For
6984 * security reasons, we don't show source file/line number for
6987 if (conf->source == PGC_S_FILE && superuser())
6989 values[14] = conf->sourcefile;
6990 snprintf(buffer, sizeof(buffer), "%d", conf->sourceline);
6991 values[15] = pstrdup(buffer);
7001 * Return the total number of GUC variables
7004 GetNumConfigOptions(void)
7006 return num_guc_variables;
7010 * show_config_by_name - equiv to SHOW X command but implemented as
7014 show_config_by_name(PG_FUNCTION_ARGS)
7019 /* Get the GUC variable name */
7020 varname = TextDatumGetCString(PG_GETARG_DATUM(0));
7023 varval = GetConfigOptionByName(varname, NULL);
7025 /* Convert to text */
7026 PG_RETURN_TEXT_P(cstring_to_text(varval));
7030 * show_all_settings - equiv to SHOW ALL command but implemented as
7033 #define NUM_PG_SETTINGS_ATTS 16
7036 show_all_settings(PG_FUNCTION_ARGS)
7038 FuncCallContext *funcctx;
7042 AttInMetadata *attinmeta;
7043 MemoryContext oldcontext;
7045 /* stuff done only on the first call of the function */
7046 if (SRF_IS_FIRSTCALL())
7048 /* create a function context for cross-call persistence */
7049 funcctx = SRF_FIRSTCALL_INIT();
7052 * switch to memory context appropriate for multiple function calls
7054 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
7057 * need a tuple descriptor representing NUM_PG_SETTINGS_ATTS columns
7058 * of the appropriate types
7060 tupdesc = CreateTemplateTupleDesc(NUM_PG_SETTINGS_ATTS, false);
7061 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
7063 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
7065 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "unit",
7067 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "category",
7069 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "short_desc",
7071 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "extra_desc",
7073 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "context",
7075 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "vartype",
7077 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "source",
7079 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "min_val",
7081 TupleDescInitEntry(tupdesc, (AttrNumber) 11, "max_val",
7083 TupleDescInitEntry(tupdesc, (AttrNumber) 12, "enumvals",
7084 TEXTARRAYOID, -1, 0);
7085 TupleDescInitEntry(tupdesc, (AttrNumber) 13, "boot_val",
7087 TupleDescInitEntry(tupdesc, (AttrNumber) 14, "reset_val",
7089 TupleDescInitEntry(tupdesc, (AttrNumber) 15, "sourcefile",
7091 TupleDescInitEntry(tupdesc, (AttrNumber) 16, "sourceline",
7095 * Generate attribute metadata needed later to produce tuples from raw
7098 attinmeta = TupleDescGetAttInMetadata(tupdesc);
7099 funcctx->attinmeta = attinmeta;
7101 /* total number of tuples to be returned */
7102 funcctx->max_calls = GetNumConfigOptions();
7104 MemoryContextSwitchTo(oldcontext);
7107 /* stuff done on every call of the function */
7108 funcctx = SRF_PERCALL_SETUP();
7110 call_cntr = funcctx->call_cntr;
7111 max_calls = funcctx->max_calls;
7112 attinmeta = funcctx->attinmeta;
7114 if (call_cntr < max_calls) /* do when there is more left to send */
7116 char *values[NUM_PG_SETTINGS_ATTS];
7122 * Get the next visible GUC variable name and value
7126 GetConfigOptionByNum(call_cntr, (const char **) values, &noshow);
7129 /* bump the counter and get the next config setting */
7130 call_cntr = ++funcctx->call_cntr;
7132 /* make sure we haven't gone too far now */
7133 if (call_cntr >= max_calls)
7134 SRF_RETURN_DONE(funcctx);
7139 tuple = BuildTupleFromCStrings(attinmeta, values);
7141 /* make the tuple into a datum */
7142 result = HeapTupleGetDatum(tuple);
7144 SRF_RETURN_NEXT(funcctx, result);
7148 /* do when there is no more left */
7149 SRF_RETURN_DONE(funcctx);
7154 _ShowOption(struct config_generic * record, bool use_units)
7159 switch (record->vartype)
7163 struct config_bool *conf = (struct config_bool *) record;
7165 if (conf->show_hook)
7166 val = (*conf->show_hook) ();
7168 val = *conf->variable ? "on" : "off";
7174 struct config_int *conf = (struct config_int *) record;
7176 if (conf->show_hook)
7177 val = (*conf->show_hook) ();
7181 * Use int64 arithmetic to avoid overflows in units
7184 int64 result = *conf->variable;
7187 if (use_units && result > 0 &&
7188 (record->flags & GUC_UNIT_MEMORY))
7190 switch (record->flags & GUC_UNIT_MEMORY)
7192 case GUC_UNIT_BLOCKS:
7193 result *= BLCKSZ / 1024;
7195 case GUC_UNIT_XBLOCKS:
7196 result *= XLOG_BLCKSZ / 1024;
7200 if (result % KB_PER_GB == 0)
7202 result /= KB_PER_GB;
7205 else if (result % KB_PER_MB == 0)
7207 result /= KB_PER_MB;
7215 else if (use_units && result > 0 &&
7216 (record->flags & GUC_UNIT_TIME))
7218 switch (record->flags & GUC_UNIT_TIME)
7224 result *= MS_PER_MIN;
7228 if (result % MS_PER_D == 0)
7233 else if (result % MS_PER_H == 0)
7238 else if (result % MS_PER_MIN == 0)
7240 result /= MS_PER_MIN;
7243 else if (result % MS_PER_S == 0)
7256 snprintf(buffer, sizeof(buffer), INT64_FORMAT "%s",
7265 struct config_real *conf = (struct config_real *) record;
7267 if (conf->show_hook)
7268 val = (*conf->show_hook) ();
7271 snprintf(buffer, sizeof(buffer), "%g",
7280 struct config_string *conf = (struct config_string *) record;
7282 if (conf->show_hook)
7283 val = (*conf->show_hook) ();
7284 else if (*conf->variable && **conf->variable)
7285 val = *conf->variable;
7293 struct config_enum *conf = (struct config_enum *) record;
7295 if (conf->show_hook)
7296 val = (*conf->show_hook) ();
7298 val = config_enum_lookup_by_value(conf, *conf->variable);
7303 /* just to keep compiler quiet */
7308 return pstrdup(val);
7315 * These routines dump out all non-default GUC options into a binary
7316 * file that is read by all exec'ed backends. The format is:
7318 * variable name, string, null terminated
7319 * variable value, string, null terminated
7320 * variable source, integer
7323 write_one_nondefault_variable(FILE *fp, struct config_generic * gconf)
7325 if (gconf->source == PGC_S_DEFAULT)
7328 fprintf(fp, "%s", gconf->name);
7331 switch (gconf->vartype)
7335 struct config_bool *conf = (struct config_bool *) gconf;
7337 if (*conf->variable)
7338 fprintf(fp, "true");
7340 fprintf(fp, "false");
7346 struct config_int *conf = (struct config_int *) gconf;
7348 fprintf(fp, "%d", *conf->variable);
7354 struct config_real *conf = (struct config_real *) gconf;
7356 /* Could lose precision here? */
7357 fprintf(fp, "%f", *conf->variable);
7363 struct config_string *conf = (struct config_string *) gconf;
7365 fprintf(fp, "%s", *conf->variable);
7371 struct config_enum *conf = (struct config_enum *) gconf;
7374 config_enum_lookup_by_value(conf, *conf->variable));
7381 fwrite(&gconf->source, sizeof(gconf->source), 1, fp);
7385 write_nondefault_variables(GucContext context)
7389 struct config_generic *cvc_conf;
7392 Assert(context == PGC_POSTMASTER || context == PGC_SIGHUP);
7394 elevel = (context == PGC_SIGHUP) ? LOG : ERROR;
7399 fp = AllocateFile(CONFIG_EXEC_PARAMS_NEW, "w");
7403 (errcode_for_file_access(),
7404 errmsg("could not write to file \"%s\": %m",
7405 CONFIG_EXEC_PARAMS_NEW)));
7410 * custom_variable_classes must be written out first; otherwise we might
7411 * reject custom variable values while reading the file.
7413 cvc_conf = find_option("custom_variable_classes", false, ERROR);
7415 write_one_nondefault_variable(fp, cvc_conf);
7417 for (i = 0; i < num_guc_variables; i++)
7419 struct config_generic *gconf = guc_variables[i];
7421 if (gconf != cvc_conf)
7422 write_one_nondefault_variable(fp, gconf);
7428 (errcode_for_file_access(),
7429 errmsg("could not write to file \"%s\": %m",
7430 CONFIG_EXEC_PARAMS_NEW)));
7435 * Put new file in place. This could delay on Win32, but we don't hold
7436 * any exclusive locks.
7438 rename(CONFIG_EXEC_PARAMS_NEW, CONFIG_EXEC_PARAMS);
7443 * Read string, including null byte from file
7445 * Return NULL on EOF and nothing read
7448 read_string_with_null(FILE *fp)
7457 if ((ch = fgetc(fp)) == EOF)
7462 elog(FATAL, "invalid format of exec config params file");
7465 str = guc_malloc(FATAL, maxlen);
7466 else if (i == maxlen)
7467 str = guc_realloc(FATAL, str, maxlen *= 2);
7476 * This routine loads a previous postmaster dump of its non-default
7480 read_nondefault_variables(void)
7490 fp = AllocateFile(CONFIG_EXEC_PARAMS, "r");
7493 /* File not found is fine */
7494 if (errno != ENOENT)
7496 (errcode_for_file_access(),
7497 errmsg("could not read from file \"%s\": %m",
7498 CONFIG_EXEC_PARAMS)));
7504 struct config_generic *record;
7506 if ((varname = read_string_with_null(fp)) == NULL)
7509 if ((record = find_option(varname, true, FATAL)) == NULL)
7510 elog(FATAL, "failed to locate variable %s in exec config params file", varname);
7511 if ((varvalue = read_string_with_null(fp)) == NULL)
7512 elog(FATAL, "invalid format of exec config params file");
7513 if (fread(&varsource, sizeof(varsource), 1, fp) == 0)
7514 elog(FATAL, "invalid format of exec config params file");
7516 (void) set_config_option(varname, varvalue, record->context,
7517 varsource, GUC_ACTION_SET, true);
7524 #endif /* EXEC_BACKEND */
7528 * A little "long argument" simulation, although not quite GNU
7529 * compliant. Takes a string of the form "some-option=some value" and
7530 * returns name = "some_option" and value = "some value" in malloc'ed
7531 * storage. Note that '-' is converted to '_' in the option name. If
7532 * there is no '=' in the input string then value will be NULL.
7535 ParseLongOption(const char *string, char **name, char **value)
7544 equal_pos = strcspn(string, "=");
7546 if (string[equal_pos] == '=')
7548 *name = guc_malloc(FATAL, equal_pos + 1);
7549 strlcpy(*name, string, equal_pos + 1);
7551 *value = guc_strdup(FATAL, &string[equal_pos + 1]);
7555 /* no equal sign in string */
7556 *name = guc_strdup(FATAL, string);
7560 for (cp = *name; *cp; cp++)
7567 * Handle options fetched from pg_db_role_setting.setconfig,
7568 * pg_proc.proconfig, etc. Caller must specify proper context/source/action.
7570 * The array parameter must be an array of TEXT (it must not be NULL).
7573 ProcessGUCArray(ArrayType *array,
7574 GucContext context, GucSource source, GucAction action)
7578 Assert(array != NULL);
7579 Assert(ARR_ELEMTYPE(array) == TEXTOID);
7580 Assert(ARR_NDIM(array) == 1);
7581 Assert(ARR_LBOUND(array)[0] == 1);
7583 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
7591 d = array_ref(array, 1, &i,
7592 -1 /* varlenarray */ ,
7593 -1 /* TEXT's typlen */ ,
7594 false /* TEXT's typbyval */ ,
7595 'i' /* TEXT's typalign */ ,
7601 s = TextDatumGetCString(d);
7603 ParseLongOption(s, &name, &value);
7607 (errcode(ERRCODE_SYNTAX_ERROR),
7608 errmsg("could not parse setting for parameter \"%s\"",
7614 (void) set_config_option(name, value, context, source, action, true);
7625 * Add an entry to an option array. The array parameter may be NULL
7626 * to indicate the current table entry is NULL.
7629 GUCArrayAdd(ArrayType *array, const char *name, const char *value)
7631 struct config_generic *record;
7639 /* test if the option is valid and we're allowed to set it */
7640 (void) validate_option_array_item(name, value, false);
7642 /* normalize name (converts obsolete GUC names to modern spellings) */
7643 record = find_option(name, false, WARNING);
7645 name = record->name;
7647 /* build new item for array */
7648 newval = palloc(strlen(name) + 1 + strlen(value) + 1);
7649 sprintf(newval, "%s=%s", name, value);
7650 datum = CStringGetTextDatum(newval);
7658 Assert(ARR_ELEMTYPE(array) == TEXTOID);
7659 Assert(ARR_NDIM(array) == 1);
7660 Assert(ARR_LBOUND(array)[0] == 1);
7662 index = ARR_DIMS(array)[0] + 1; /* add after end */
7664 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
7669 d = array_ref(array, 1, &i,
7670 -1 /* varlenarray */ ,
7671 -1 /* TEXT's typlen */ ,
7672 false /* TEXT's typbyval */ ,
7673 'i' /* TEXT's typalign */ ,
7677 current = TextDatumGetCString(d);
7679 /* check for match up through and including '=' */
7680 if (strncmp(current, newval, strlen(name) + 1) == 0)
7687 a = array_set(array, 1, &index,
7690 -1 /* varlena array */ ,
7691 -1 /* TEXT's typlen */ ,
7692 false /* TEXT's typbyval */ ,
7693 'i' /* TEXT's typalign */ );
7696 a = construct_array(&datum, 1,
7705 * Delete an entry from an option array. The array parameter may be NULL
7706 * to indicate the current table entry is NULL. Also, if the return value
7707 * is NULL then a null should be stored.
7710 GUCArrayDelete(ArrayType *array, const char *name)
7712 struct config_generic *record;
7713 ArrayType *newarray;
7719 /* test if the option is valid and we're allowed to set it */
7720 (void) validate_option_array_item(name, NULL, false);
7722 /* normalize name (converts obsolete GUC names to modern spellings) */
7723 record = find_option(name, false, WARNING);
7725 name = record->name;
7727 /* if array is currently null, then surely nothing to delete */
7734 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
7740 d = array_ref(array, 1, &i,
7741 -1 /* varlenarray */ ,
7742 -1 /* TEXT's typlen */ ,
7743 false /* TEXT's typbyval */ ,
7744 'i' /* TEXT's typalign */ ,
7748 val = TextDatumGetCString(d);
7750 /* ignore entry if it's what we want to delete */
7751 if (strncmp(val, name, strlen(name)) == 0
7752 && val[strlen(name)] == '=')
7755 /* else add it to the output array */
7757 newarray = array_set(newarray, 1, &index,
7760 -1 /* varlenarray */ ,
7761 -1 /* TEXT's typlen */ ,
7762 false /* TEXT's typbyval */ ,
7763 'i' /* TEXT's typalign */ );
7765 newarray = construct_array(&d, 1,
7777 * Given a GUC array, delete all settings from it that our permission
7778 * level allows: if superuser, delete them all; if regular user, only
7779 * those that are PGC_USERSET
7782 GUCArrayReset(ArrayType *array)
7784 ArrayType *newarray;
7788 /* if array is currently null, nothing to do */
7792 /* if we're superuser, we can delete everything, so just do it */
7799 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
7806 d = array_ref(array, 1, &i,
7807 -1 /* varlenarray */ ,
7808 -1 /* TEXT's typlen */ ,
7809 false /* TEXT's typbyval */ ,
7810 'i' /* TEXT's typalign */ ,
7814 val = TextDatumGetCString(d);
7816 eqsgn = strchr(val, '=');
7819 /* skip if we have permission to delete it */
7820 if (validate_option_array_item(val, NULL, true))
7823 /* else add it to the output array */
7825 newarray = array_set(newarray, 1, &index,
7828 -1 /* varlenarray */ ,
7829 -1 /* TEXT's typlen */ ,
7830 false /* TEXT's typbyval */ ,
7831 'i' /* TEXT's typalign */ );
7833 newarray = construct_array(&d, 1,
7845 * Validate a proposed option setting for GUCArrayAdd/Delete/Reset.
7847 * name is the option name. value is the proposed value for the Add case,
7848 * or NULL for the Delete/Reset cases. If skipIfNoPermissions is true, it's
7849 * not an error to have no permissions to set the option.
7851 * Returns TRUE if OK, FALSE if skipIfNoPermissions is true and user does not
7852 * have permission to change this option (all other error cases result in an
7853 * error being thrown).
7856 validate_option_array_item(const char *name, const char *value,
7857 bool skipIfNoPermissions)
7860 struct config_generic *gconf;
7863 * There are three cases to consider:
7865 * name is a known GUC variable. Check the value normally, check
7866 * permissions normally (ie, allow if variable is USERSET, or if it's
7867 * SUSET and user is superuser).
7869 * name is not known, but exists or can be created as a placeholder
7870 * (implying it has a prefix listed in custom_variable_classes). We allow
7871 * this case if you're a superuser, otherwise not. Superusers are assumed
7872 * to know what they're doing. We can't allow it for other users, because
7873 * when the placeholder is resolved it might turn out to be a SUSET
7874 * variable; define_custom_variable assumes we checked that.
7876 * name is not known and can't be created as a placeholder. Throw error,
7877 * unless skipIfNoPermissions is true, in which case return FALSE. (It's
7878 * tempting to allow this case to superusers, if the name is qualified but
7879 * not listed in custom_variable_classes. That would ease restoring of
7880 * dumps containing ALTER ROLE/DATABASE SET. However, it's not clear that
7881 * this usage justifies such a loss of error checking. You can always fix
7882 * custom_variable_classes before you restore.)
7884 gconf = find_option(name, true, WARNING);
7887 /* not known, failed to make a placeholder */
7888 if (skipIfNoPermissions)
7891 (errcode(ERRCODE_UNDEFINED_OBJECT),
7892 errmsg("unrecognized configuration parameter \"%s\"", name)));
7895 if (gconf->flags & GUC_CUSTOM_PLACEHOLDER)
7898 * We cannot do any meaningful check on the value, so only permissions
7899 * are useful to check.
7903 if (skipIfNoPermissions)
7906 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7907 errmsg("permission denied to set parameter \"%s\"", name)));
7910 /* manual permissions check so we can avoid an error being thrown */
7911 if (gconf->context == PGC_USERSET)
7913 else if (gconf->context == PGC_SUSET && superuser())
7915 else if (skipIfNoPermissions)
7917 /* if a permissions error should be thrown, let set_config_option do it */
7919 /* test for permissions and valid option value */
7920 set_config_option(name, value,
7921 superuser() ? PGC_SUSET : PGC_USERSET,
7922 PGC_S_TEST, GUC_ACTION_SET, false);
7929 * Called by check_hooks that want to override the normal
7930 * ERRCODE_INVALID_PARAMETER_VALUE SQLSTATE for check hook failures.
7932 * Note that GUC_check_errmsg() etc are just macros that result in a direct
7933 * assignment to the associated variables. That is ugly, but forced by the
7934 * limitations of C's macro mechanisms.
7937 GUC_check_errcode(int sqlerrcode)
7939 GUC_check_errcode_value = sqlerrcode;
7944 * Convenience functions to manage calling a variable's check_hook.
7945 * These mostly take care of the protocol for letting check hooks supply
7946 * portions of the error report on failure.
7950 call_bool_check_hook(struct config_bool * conf, bool *newval, void **extra,
7951 GucSource source, int elevel)
7953 /* Quick success if no hook */
7954 if (!conf->check_hook)
7957 /* Reset variables that might be set by hook */
7958 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
7959 GUC_check_errmsg_string = NULL;
7960 GUC_check_errdetail_string = NULL;
7961 GUC_check_errhint_string = NULL;
7963 if (!(*conf->check_hook) (newval, extra, source))
7966 (errcode(GUC_check_errcode_value),
7967 GUC_check_errmsg_string ?
7968 errmsg("%s", GUC_check_errmsg_string) :
7969 errmsg("invalid value for parameter \"%s\": %d",
7970 conf->gen.name, (int) *newval),
7971 GUC_check_errdetail_string ?
7972 errdetail("%s", GUC_check_errdetail_string) : 0,
7973 GUC_check_errhint_string ?
7974 errhint("%s", GUC_check_errhint_string) : 0));
7975 /* Flush any strings created in ErrorContext */
7984 call_int_check_hook(struct config_int * conf, int *newval, void **extra,
7985 GucSource source, int elevel)
7987 /* Quick success if no hook */
7988 if (!conf->check_hook)
7991 /* Reset variables that might be set by hook */
7992 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
7993 GUC_check_errmsg_string = NULL;
7994 GUC_check_errdetail_string = NULL;
7995 GUC_check_errhint_string = NULL;
7997 if (!(*conf->check_hook) (newval, extra, source))
8000 (errcode(GUC_check_errcode_value),
8001 GUC_check_errmsg_string ?
8002 errmsg("%s", GUC_check_errmsg_string) :
8003 errmsg("invalid value for parameter \"%s\": %d",
8004 conf->gen.name, *newval),
8005 GUC_check_errdetail_string ?
8006 errdetail("%s", GUC_check_errdetail_string) : 0,
8007 GUC_check_errhint_string ?
8008 errhint("%s", GUC_check_errhint_string) : 0));
8009 /* Flush any strings created in ErrorContext */
8018 call_real_check_hook(struct config_real * conf, double *newval, void **extra,
8019 GucSource source, int elevel)
8021 /* Quick success if no hook */
8022 if (!conf->check_hook)
8025 /* Reset variables that might be set by hook */
8026 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8027 GUC_check_errmsg_string = NULL;
8028 GUC_check_errdetail_string = NULL;
8029 GUC_check_errhint_string = NULL;
8031 if (!(*conf->check_hook) (newval, extra, source))
8034 (errcode(GUC_check_errcode_value),
8035 GUC_check_errmsg_string ?
8036 errmsg("%s", GUC_check_errmsg_string) :
8037 errmsg("invalid value for parameter \"%s\": %g",
8038 conf->gen.name, *newval),
8039 GUC_check_errdetail_string ?
8040 errdetail("%s", GUC_check_errdetail_string) : 0,
8041 GUC_check_errhint_string ?
8042 errhint("%s", GUC_check_errhint_string) : 0));
8043 /* Flush any strings created in ErrorContext */
8052 call_string_check_hook(struct config_string * conf, char **newval, void **extra,
8053 GucSource source, int elevel)
8055 /* Quick success if no hook */
8056 if (!conf->check_hook)
8059 /* Reset variables that might be set by hook */
8060 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8061 GUC_check_errmsg_string = NULL;
8062 GUC_check_errdetail_string = NULL;
8063 GUC_check_errhint_string = NULL;
8065 if (!(*conf->check_hook) (newval, extra, source))
8068 (errcode(GUC_check_errcode_value),
8069 GUC_check_errmsg_string ?
8070 errmsg("%s", GUC_check_errmsg_string) :
8071 errmsg("invalid value for parameter \"%s\": \"%s\"",
8072 conf->gen.name, *newval ? *newval : ""),
8073 GUC_check_errdetail_string ?
8074 errdetail("%s", GUC_check_errdetail_string) : 0,
8075 GUC_check_errhint_string ?
8076 errhint("%s", GUC_check_errhint_string) : 0));
8077 /* Flush any strings created in ErrorContext */
8086 call_enum_check_hook(struct config_enum * conf, int *newval, void **extra,
8087 GucSource source, int elevel)
8089 /* Quick success if no hook */
8090 if (!conf->check_hook)
8093 /* Reset variables that might be set by hook */
8094 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8095 GUC_check_errmsg_string = NULL;
8096 GUC_check_errdetail_string = NULL;
8097 GUC_check_errhint_string = NULL;
8099 if (!(*conf->check_hook) (newval, extra, source))
8102 (errcode(GUC_check_errcode_value),
8103 GUC_check_errmsg_string ?
8104 errmsg("%s", GUC_check_errmsg_string) :
8105 errmsg("invalid value for parameter \"%s\": \"%s\"",
8107 config_enum_lookup_by_value(conf, *newval)),
8108 GUC_check_errdetail_string ?
8109 errdetail("%s", GUC_check_errdetail_string) : 0,
8110 GUC_check_errhint_string ?
8111 errhint("%s", GUC_check_errhint_string) : 0));
8112 /* Flush any strings created in ErrorContext */
8122 * check_hook, assign_hook and show_hook subroutines
8126 check_log_destination(char **newval, void **extra, GucSource source)
8134 /* Need a modifiable copy of string */
8135 rawstring = pstrdup(*newval);
8137 /* Parse string into list of identifiers */
8138 if (!SplitIdentifierString(rawstring, ',', &elemlist))
8140 /* syntax error in list */
8141 GUC_check_errdetail("List syntax is invalid.");
8143 list_free(elemlist);
8147 foreach(l, elemlist)
8149 char *tok = (char *) lfirst(l);
8151 if (pg_strcasecmp(tok, "stderr") == 0)
8152 newlogdest |= LOG_DESTINATION_STDERR;
8153 else if (pg_strcasecmp(tok, "csvlog") == 0)
8154 newlogdest |= LOG_DESTINATION_CSVLOG;
8156 else if (pg_strcasecmp(tok, "syslog") == 0)
8157 newlogdest |= LOG_DESTINATION_SYSLOG;
8160 else if (pg_strcasecmp(tok, "eventlog") == 0)
8161 newlogdest |= LOG_DESTINATION_EVENTLOG;
8165 GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
8167 list_free(elemlist);
8173 list_free(elemlist);
8175 myextra = (int *) guc_malloc(ERROR, sizeof(int));
8176 *myextra = newlogdest;
8177 *extra = (void *) myextra;
8183 assign_log_destination(const char *newval, void *extra)
8185 Log_destination = *((int *) extra);
8189 assign_syslog_facility(int newval, void *extra)
8192 set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
8195 /* Without syslog support, just ignore it */
8199 assign_syslog_ident(const char *newval, void *extra)
8202 set_syslog_parameters(newval, syslog_facility);
8204 /* Without syslog support, it will always be set to "none", so ignore */
8209 assign_session_replication_role(int newval, void *extra)
8212 * Must flush the plan cache when changing replication role; but don't
8213 * flush unnecessarily.
8215 if (SessionReplicationRole != newval)
8220 check_temp_buffers(int *newval, void **extra, GucSource source)
8223 * Once local buffers have been initialized, it's too late to change this.
8225 if (NLocBuffer && NLocBuffer != *newval)
8227 GUC_check_errdetail("\"temp_buffers\" cannot be changed after any temporary tables have been accessed in the session.");
8234 check_phony_autocommit(bool *newval, void **extra, GucSource source)
8238 GUC_check_errcode(ERRCODE_FEATURE_NOT_SUPPORTED);
8239 GUC_check_errmsg("SET AUTOCOMMIT TO OFF is no longer supported");
8246 check_custom_variable_classes(char **newval, void **extra, GucSource source)
8249 * Check syntax. newval must be a comma separated list of identifiers.
8250 * Whitespace is allowed but removed from the result.
8252 bool hasSpaceAfterToken = false;
8253 const char *cp = *newval;
8258 /* Default NULL is OK */
8262 initStringInfo(&buf);
8263 while ((c = *cp++) != '\0')
8265 if (isspace((unsigned char) c))
8268 hasSpaceAfterToken = true;
8274 if (symLen > 0) /* terminate identifier */
8276 appendStringInfoChar(&buf, ',');
8279 hasSpaceAfterToken = false;
8283 if (hasSpaceAfterToken || !(isalnum((unsigned char) c) || c == '_'))
8286 * Syntax error due to token following space after token or
8287 * non-identifier character
8292 appendStringInfoChar(&buf, c);
8296 /* Remove stray ',' at end */
8297 if (symLen == 0 && buf.len > 0)
8298 buf.data[--buf.len] = '\0';
8300 /* GUC wants the result malloc'd */
8302 *newval = guc_strdup(LOG, buf.data);
8309 check_debug_assertions(bool *newval, void **extra, GucSource source)
8311 #ifndef USE_ASSERT_CHECKING
8314 GUC_check_errmsg("assertion checking is not supported by this build");
8322 check_bonjour(bool *newval, void **extra, GucSource source)
8327 GUC_check_errmsg("Bonjour is not supported by this build");
8335 check_ssl(bool *newval, void **extra, GucSource source)
8340 GUC_check_errmsg("SSL is not supported by this build");
8348 check_stage_log_stats(bool *newval, void **extra, GucSource source)
8350 if (*newval && log_statement_stats)
8352 GUC_check_errdetail("Cannot enable parameter when \"log_statement_stats\" is true.");
8359 check_log_stats(bool *newval, void **extra, GucSource source)
8362 (log_parser_stats || log_planner_stats || log_executor_stats))
8364 GUC_check_errdetail("Cannot enable \"log_statement_stats\" when "
8365 "\"log_parser_stats\", \"log_planner_stats\", "
8366 "or \"log_executor_stats\" is true.");
8373 check_canonical_path(char **newval, void **extra, GucSource source)
8376 * Since canonicalize_path never enlarges the string, we can just modify
8377 * newval in-place. But watch out for NULL, which is the default value
8378 * for external_pid_file.
8381 canonicalize_path(*newval);
8386 check_timezone_abbreviations(char **newval, void **extra, GucSource source)
8389 * The boot_val given above for timezone_abbreviations is NULL. When we
8390 * see this we just do nothing. If this value isn't overridden from the
8391 * config file then pg_timezone_abbrev_initialize() will eventually
8392 * replace it with "Default". This hack has two purposes: to avoid
8393 * wasting cycles loading values that might soon be overridden from the
8394 * config file, and to avoid trying to read the timezone abbrev files
8395 * during InitializeGUCOptions(). The latter doesn't work in an
8396 * EXEC_BACKEND subprocess because my_exec_path hasn't been set yet and so
8397 * we can't locate PGSHAREDIR.
8399 if (*newval == NULL)
8401 Assert(source == PGC_S_DEFAULT);
8405 /* OK, load the file and produce a malloc'd TimeZoneAbbrevTable */
8406 *extra = load_tzoffsets(*newval);
8408 /* tzparser.c returns NULL on failure, reporting via GUC_check_errmsg */
8416 assign_timezone_abbreviations(const char *newval, void *extra)
8418 /* Do nothing for the boot_val default of NULL */
8422 InstallTimeZoneAbbrevs((TimeZoneAbbrevTable *) extra);
8426 * pg_timezone_abbrev_initialize --- set default value if not done already
8428 * This is called after initial loading of postgresql.conf. If no
8429 * timezone_abbreviations setting was found therein, select default.
8430 * If a non-default value is already installed, nothing will happen.
8433 pg_timezone_abbrev_initialize(void)
8435 SetConfigOption("timezone_abbreviations", "Default",
8436 PGC_POSTMASTER, PGC_S_DYNAMIC_DEFAULT);
8440 show_archive_command(void)
8442 if (XLogArchivingActive())
8443 return XLogArchiveCommand;
8445 return "(disabled)";
8449 assign_tcp_keepalives_idle(int newval, void *extra)
8452 * The kernel API provides no way to test a value without setting it; and
8453 * once we set it we might fail to unset it. So there seems little point
8454 * in fully implementing the check-then-assign GUC API for these
8455 * variables. Instead we just do the assignment on demand. pqcomm.c
8456 * reports any problems via elog(LOG).
8458 * This approach means that the GUC value might have little to do with the
8459 * actual kernel value, so we use a show_hook that retrieves the kernel
8460 * value rather than trusting GUC's copy.
8462 (void) pq_setkeepalivesidle(newval, MyProcPort);
8466 show_tcp_keepalives_idle(void)
8468 /* See comments in assign_tcp_keepalives_idle */
8469 static char nbuf[16];
8471 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesidle(MyProcPort));
8476 assign_tcp_keepalives_interval(int newval, void *extra)
8478 /* See comments in assign_tcp_keepalives_idle */
8479 (void) pq_setkeepalivesinterval(newval, MyProcPort);
8483 show_tcp_keepalives_interval(void)
8485 /* See comments in assign_tcp_keepalives_idle */
8486 static char nbuf[16];
8488 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesinterval(MyProcPort));
8493 assign_tcp_keepalives_count(int newval, void *extra)
8495 /* See comments in assign_tcp_keepalives_idle */
8496 (void) pq_setkeepalivescount(newval, MyProcPort);
8500 show_tcp_keepalives_count(void)
8502 /* See comments in assign_tcp_keepalives_idle */
8503 static char nbuf[16];
8505 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivescount(MyProcPort));
8510 check_maxconnections(int *newval, void **extra, GucSource source)
8512 if (*newval + autovacuum_max_workers + 1 > MAX_BACKENDS)
8518 assign_maxconnections(int newval, void *extra)
8520 MaxBackends = newval + autovacuum_max_workers + 1;
8524 check_autovacuum_max_workers(int *newval, void **extra, GucSource source)
8526 if (MaxConnections + *newval + 1 > MAX_BACKENDS)
8532 assign_autovacuum_max_workers(int newval, void *extra)
8534 MaxBackends = MaxConnections + newval + 1;
8538 check_effective_io_concurrency(int *newval, void **extra, GucSource source)
8541 double new_prefetch_pages = 0.0;
8545 * The user-visible GUC parameter is the number of drives (spindles),
8546 * which we need to translate to a number-of-pages-to-prefetch target.
8547 * The target value is stashed in *extra and then assigned to the actual
8548 * variable by assign_effective_io_concurrency.
8550 * The expected number of prefetch pages needed to keep N drives busy is:
8552 * drives | I/O requests
8553 * -------+----------------
8556 * 3 | 3/1 + 3/2 + 3/3 = 5 1/2
8557 * 4 | 4/1 + 4/2 + 4/3 + 4/4 = 8 1/3
8560 * This is called the "coupon collector problem" and H(n) is called the
8561 * harmonic series. This could be approximated by n * ln(n), but for
8562 * reasonable numbers of drives we might as well just compute the series.
8564 * Alternatively we could set the target to the number of pages necessary
8565 * so that the expected number of active spindles is some arbitrary
8566 * percentage of the total. This sounds the same but is actually slightly
8567 * different. The result ends up being ln(1-P)/ln((n-1)/n) where P is
8568 * that desired fraction.
8570 * Experimental results show that both of these formulas aren't aggressive
8571 * enough, but we don't really have any better proposals.
8573 * Note that if *newval = 0 (disabled), we must set target = 0.
8577 for (i = 1; i <= *newval; i++)
8578 new_prefetch_pages += (double) *newval / (double) i;
8580 /* This range check shouldn't fail, but let's be paranoid */
8581 if (new_prefetch_pages >= 0.0 && new_prefetch_pages < (double) INT_MAX)
8583 int *myextra = (int *) guc_malloc(ERROR, sizeof(int));
8585 *myextra = (int) rint(new_prefetch_pages);
8586 *extra = (void *) myextra;
8594 #endif /* USE_PREFETCH */
8598 assign_effective_io_concurrency(int newval, void *extra)
8601 target_prefetch_pages = *((int *) extra);
8602 #endif /* USE_PREFETCH */
8606 assign_pgstat_temp_directory(const char *newval, void *extra)
8608 /* check_canonical_path already canonicalized newval for us */
8612 tname = guc_malloc(ERROR, strlen(newval) + 12); /* /pgstat.tmp */
8613 sprintf(tname, "%s/pgstat.tmp", newval);
8614 fname = guc_malloc(ERROR, strlen(newval) + 13); /* /pgstat.stat */
8615 sprintf(fname, "%s/pgstat.stat", newval);
8617 if (pgstat_stat_tmpname)
8618 free(pgstat_stat_tmpname);
8619 pgstat_stat_tmpname = tname;
8620 if (pgstat_stat_filename)
8621 free(pgstat_stat_filename);
8622 pgstat_stat_filename = fname;
8626 check_application_name(char **newval, void **extra, GucSource source)
8628 /* Only allow clean ASCII chars in the application name */
8631 for (p = *newval; *p; p++)
8633 if (*p < 32 || *p > 126)
8641 assign_application_name(const char *newval, void *extra)
8643 /* Update the pg_stat_activity view */
8644 pgstat_report_appname(newval);
8648 show_unix_socket_permissions(void)
8652 snprintf(buf, sizeof(buf), "%04o", Unix_socket_permissions);
8657 show_log_file_mode(void)
8661 snprintf(buf, sizeof(buf), "%04o", Log_file_mode);
8665 #include "guc-file.c"