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-2012, 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/libpq.h"
43 #include "libpq/pqformat.h"
44 #include "miscadmin.h"
45 #include "optimizer/cost.h"
46 #include "optimizer/geqo.h"
47 #include "optimizer/paths.h"
48 #include "optimizer/planmain.h"
49 #include "parser/parse_expr.h"
50 #include "parser/parse_type.h"
51 #include "parser/parser.h"
52 #include "parser/scansup.h"
54 #include "postmaster/autovacuum.h"
55 #include "postmaster/bgwriter.h"
56 #include "postmaster/postmaster.h"
57 #include "postmaster/syslogger.h"
58 #include "postmaster/walwriter.h"
59 #include "replication/syncrep.h"
60 #include "replication/walreceiver.h"
61 #include "replication/walsender.h"
62 #include "storage/bufmgr.h"
63 #include "storage/standby.h"
64 #include "storage/fd.h"
65 #include "storage/predicate.h"
66 #include "tcop/tcopprot.h"
67 #include "tsearch/ts_cache.h"
68 #include "utils/builtins.h"
69 #include "utils/bytea.h"
70 #include "utils/guc_tables.h"
71 #include "utils/memutils.h"
72 #include "utils/pg_locale.h"
73 #include "utils/plancache.h"
74 #include "utils/portal.h"
75 #include "utils/ps_status.h"
76 #include "utils/snapmgr.h"
77 #include "utils/tzparser.h"
78 #include "utils/xml.h"
81 #define PG_KRB_SRVTAB ""
84 #define PG_KRB_SRVNAM ""
87 #define CONFIG_FILENAME "postgresql.conf"
88 #define HBA_FILENAME "pg_hba.conf"
89 #define IDENT_FILENAME "pg_ident.conf"
92 #define CONFIG_EXEC_PARAMS "global/config_exec_params"
93 #define CONFIG_EXEC_PARAMS_NEW "global/config_exec_params.new"
96 /* upper limit for GUC variables measured in kilobytes of memory */
97 /* note that various places assume the byte size fits in a "long" variable */
98 #if SIZEOF_SIZE_T > 4 && SIZEOF_LONG > 4
99 #define MAX_KILOBYTES INT_MAX
101 #define MAX_KILOBYTES (INT_MAX / 1024)
105 * Note: MAX_BACKENDS is limited to 2^23-1 because inval.c stores the
106 * backend ID as a 3-byte signed integer. Even if that limitation were
107 * removed, we still could not exceed INT_MAX/4 because some places compute
108 * 4*MaxBackends without any overflow check. This is rechecked in
109 * check_maxconnections, since MaxBackends is computed as MaxConnections
110 * plus autovacuum_max_workers plus one (for the autovacuum launcher).
112 #define MAX_BACKENDS 0x7fffff
114 #define KB_PER_MB (1024)
115 #define KB_PER_GB (1024*1024)
117 #define MS_PER_S 1000
119 #define MS_PER_MIN (1000 * 60)
121 #define S_PER_H (60 * 60)
122 #define MS_PER_H (1000 * 60 * 60)
123 #define MIN_PER_D (60 * 24)
124 #define S_PER_D (60 * 60 * 24)
125 #define MS_PER_D (1000 * 60 * 60 * 24)
127 /* XXX these should appear in other modules' header files */
128 extern bool Log_disconnections;
129 extern int CommitDelay;
130 extern int CommitSiblings;
131 extern char *default_tablespace;
132 extern char *temp_tablespaces;
133 extern bool synchronize_seqscans;
134 extern int ssl_renegotiation_limit;
135 extern char *SSLCipherSuites;
138 extern bool trace_sort;
140 #ifdef TRACE_SYNCSCAN
141 extern bool trace_syncscan;
143 #ifdef DEBUG_BOUNDED_SORT
144 extern bool optimize_bounded_sort;
147 static int GUC_check_errcode_value;
149 /* global variables for check hook support */
150 char *GUC_check_errmsg_string;
151 char *GUC_check_errdetail_string;
152 char *GUC_check_errhint_string;
155 static void set_config_sourcefile(const char *name, char *sourcefile,
157 static bool call_bool_check_hook(struct config_bool * conf, bool *newval,
158 void **extra, GucSource source, int elevel);
159 static bool call_int_check_hook(struct config_int * conf, int *newval,
160 void **extra, GucSource source, int elevel);
161 static bool call_real_check_hook(struct config_real * conf, double *newval,
162 void **extra, GucSource source, int elevel);
163 static bool call_string_check_hook(struct config_string * conf, char **newval,
164 void **extra, GucSource source, int elevel);
165 static bool call_enum_check_hook(struct config_enum * conf, int *newval,
166 void **extra, GucSource source, int elevel);
168 static bool check_log_destination(char **newval, void **extra, GucSource source);
169 static void assign_log_destination(const char *newval, void *extra);
172 static int syslog_facility = LOG_LOCAL0;
174 static int syslog_facility = 0;
177 static void assign_syslog_facility(int newval, void *extra);
178 static void assign_syslog_ident(const char *newval, void *extra);
179 static void assign_session_replication_role(int newval, void *extra);
180 static bool check_temp_buffers(int *newval, void **extra, GucSource source);
181 static bool check_phony_autocommit(bool *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 void pg_timezone_abbrev_initialize(void);
191 static const char *show_archive_command(void);
192 static void assign_tcp_keepalives_idle(int newval, void *extra);
193 static void assign_tcp_keepalives_interval(int newval, void *extra);
194 static void assign_tcp_keepalives_count(int newval, void *extra);
195 static const char *show_tcp_keepalives_idle(void);
196 static const char *show_tcp_keepalives_interval(void);
197 static const char *show_tcp_keepalives_count(void);
198 static bool check_maxconnections(int *newval, void **extra, GucSource source);
199 static void assign_maxconnections(int newval, void *extra);
200 static bool check_autovacuum_max_workers(int *newval, void **extra, GucSource source);
201 static void assign_autovacuum_max_workers(int newval, void *extra);
202 static bool check_effective_io_concurrency(int *newval, void **extra, GucSource source);
203 static void assign_effective_io_concurrency(int newval, void *extra);
204 static void assign_pgstat_temp_directory(const char *newval, void *extra);
205 static bool check_application_name(char **newval, void **extra, GucSource source);
206 static void assign_application_name(const char *newval, void *extra);
207 static const char *show_unix_socket_permissions(void);
208 static const char *show_log_file_mode(void);
210 static char *config_enum_get_options(struct config_enum * record,
211 const char *prefix, const char *suffix,
212 const char *separator);
216 * Options for enum values defined in this module.
218 * NOTE! Option values may not contain double quotes!
221 static const struct config_enum_entry bytea_output_options[] = {
222 {"escape", BYTEA_OUTPUT_ESCAPE, false},
223 {"hex", BYTEA_OUTPUT_HEX, false},
228 * We have different sets for client and server message level options because
229 * they sort slightly different (see "log" level)
231 static const struct config_enum_entry client_message_level_options[] = {
232 {"debug", DEBUG2, true},
233 {"debug5", DEBUG5, false},
234 {"debug4", DEBUG4, false},
235 {"debug3", DEBUG3, false},
236 {"debug2", DEBUG2, false},
237 {"debug1", DEBUG1, false},
239 {"info", INFO, true},
240 {"notice", NOTICE, false},
241 {"warning", WARNING, false},
242 {"error", ERROR, false},
243 {"fatal", FATAL, true},
244 {"panic", PANIC, true},
248 static const struct config_enum_entry server_message_level_options[] = {
249 {"debug", DEBUG2, true},
250 {"debug5", DEBUG5, false},
251 {"debug4", DEBUG4, false},
252 {"debug3", DEBUG3, false},
253 {"debug2", DEBUG2, false},
254 {"debug1", DEBUG1, false},
255 {"info", INFO, false},
256 {"notice", NOTICE, false},
257 {"warning", WARNING, false},
258 {"error", ERROR, false},
260 {"fatal", FATAL, false},
261 {"panic", PANIC, false},
265 static const struct config_enum_entry intervalstyle_options[] = {
266 {"postgres", INTSTYLE_POSTGRES, false},
267 {"postgres_verbose", INTSTYLE_POSTGRES_VERBOSE, false},
268 {"sql_standard", INTSTYLE_SQL_STANDARD, false},
269 {"iso_8601", INTSTYLE_ISO_8601, false},
273 static const struct config_enum_entry log_error_verbosity_options[] = {
274 {"terse", PGERROR_TERSE, false},
275 {"default", PGERROR_DEFAULT, false},
276 {"verbose", PGERROR_VERBOSE, false},
280 static const struct config_enum_entry log_statement_options[] = {
281 {"none", LOGSTMT_NONE, false},
282 {"ddl", LOGSTMT_DDL, false},
283 {"mod", LOGSTMT_MOD, false},
284 {"all", LOGSTMT_ALL, false},
288 static const struct config_enum_entry isolation_level_options[] = {
289 {"serializable", XACT_SERIALIZABLE, false},
290 {"repeatable read", XACT_REPEATABLE_READ, false},
291 {"read committed", XACT_READ_COMMITTED, false},
292 {"read uncommitted", XACT_READ_UNCOMMITTED, false},
296 static const struct config_enum_entry session_replication_role_options[] = {
297 {"origin", SESSION_REPLICATION_ROLE_ORIGIN, false},
298 {"replica", SESSION_REPLICATION_ROLE_REPLICA, false},
299 {"local", SESSION_REPLICATION_ROLE_LOCAL, false},
303 static const struct config_enum_entry syslog_facility_options[] = {
305 {"local0", LOG_LOCAL0, false},
306 {"local1", LOG_LOCAL1, false},
307 {"local2", LOG_LOCAL2, false},
308 {"local3", LOG_LOCAL3, false},
309 {"local4", LOG_LOCAL4, false},
310 {"local5", LOG_LOCAL5, false},
311 {"local6", LOG_LOCAL6, false},
312 {"local7", LOG_LOCAL7, false},
319 static const struct config_enum_entry track_function_options[] = {
320 {"none", TRACK_FUNC_OFF, false},
321 {"pl", TRACK_FUNC_PL, false},
322 {"all", TRACK_FUNC_ALL, false},
326 static const struct config_enum_entry xmlbinary_options[] = {
327 {"base64", XMLBINARY_BASE64, false},
328 {"hex", XMLBINARY_HEX, false},
332 static const struct config_enum_entry xmloption_options[] = {
333 {"content", XMLOPTION_CONTENT, false},
334 {"document", XMLOPTION_DOCUMENT, false},
339 * Although only "on", "off", and "safe_encoding" are documented, we
340 * accept all the likely variants of "on" and "off".
342 static const struct config_enum_entry backslash_quote_options[] = {
343 {"safe_encoding", BACKSLASH_QUOTE_SAFE_ENCODING, false},
344 {"on", BACKSLASH_QUOTE_ON, false},
345 {"off", BACKSLASH_QUOTE_OFF, false},
346 {"true", BACKSLASH_QUOTE_ON, true},
347 {"false", BACKSLASH_QUOTE_OFF, true},
348 {"yes", BACKSLASH_QUOTE_ON, true},
349 {"no", BACKSLASH_QUOTE_OFF, true},
350 {"1", BACKSLASH_QUOTE_ON, true},
351 {"0", BACKSLASH_QUOTE_OFF, true},
356 * Although only "on", "off", and "partition" are documented, we
357 * accept all the likely variants of "on" and "off".
359 static const struct config_enum_entry constraint_exclusion_options[] = {
360 {"partition", CONSTRAINT_EXCLUSION_PARTITION, false},
361 {"on", CONSTRAINT_EXCLUSION_ON, false},
362 {"off", CONSTRAINT_EXCLUSION_OFF, false},
363 {"true", CONSTRAINT_EXCLUSION_ON, true},
364 {"false", CONSTRAINT_EXCLUSION_OFF, true},
365 {"yes", CONSTRAINT_EXCLUSION_ON, true},
366 {"no", CONSTRAINT_EXCLUSION_OFF, true},
367 {"1", CONSTRAINT_EXCLUSION_ON, true},
368 {"0", CONSTRAINT_EXCLUSION_OFF, true},
373 * Although only "on", "off", "write", and "local" are documented, we
374 * accept all the likely variants of "on" and "off".
376 static const struct config_enum_entry synchronous_commit_options[] = {
377 {"local", SYNCHRONOUS_COMMIT_LOCAL_FLUSH, false},
378 {"write", SYNCHRONOUS_COMMIT_REMOTE_WRITE, false},
379 {"on", SYNCHRONOUS_COMMIT_ON, false},
380 {"off", SYNCHRONOUS_COMMIT_OFF, false},
381 {"true", SYNCHRONOUS_COMMIT_ON, true},
382 {"false", SYNCHRONOUS_COMMIT_OFF, true},
383 {"yes", SYNCHRONOUS_COMMIT_ON, true},
384 {"no", SYNCHRONOUS_COMMIT_OFF, true},
385 {"1", SYNCHRONOUS_COMMIT_ON, true},
386 {"0", SYNCHRONOUS_COMMIT_OFF, true},
391 * Options for enum values stored in other modules
393 extern const struct config_enum_entry wal_level_options[];
394 extern const struct config_enum_entry sync_method_options[];
397 * GUC option variables that are exported from this module
399 #ifdef USE_ASSERT_CHECKING
400 bool assert_enabled = true;
402 bool assert_enabled = false;
404 bool log_duration = false;
405 bool Debug_print_plan = false;
406 bool Debug_print_parse = false;
407 bool Debug_print_rewritten = false;
408 bool Debug_pretty_print = true;
410 bool log_parser_stats = false;
411 bool log_planner_stats = false;
412 bool log_executor_stats = false;
413 bool log_statement_stats = false; /* this is sort of all three
415 bool log_btree_build_stats = false;
418 bool check_function_bodies = true;
419 bool default_with_oids = false;
420 bool SQL_inheritance = true;
422 bool Password_encryption = true;
424 int log_min_error_statement = ERROR;
425 int log_min_messages = WARNING;
426 int client_min_messages = NOTICE;
427 int log_min_duration_statement = -1;
428 int log_temp_files = -1;
429 int trace_recovery_messages = LOG;
431 int temp_file_limit = -1;
433 int num_temp_buffers = 1024;
435 char *data_directory;
436 char *ConfigFileName;
439 char *external_pid_file;
441 char *pgstat_temp_directory;
443 char *application_name;
445 int tcp_keepalives_idle;
446 int tcp_keepalives_interval;
447 int tcp_keepalives_count;
450 * These variables are all dummies that don't do anything, except in some
451 * cases provide the value for SHOW to display. The real state is elsewhere
452 * and is kept in sync by assign_hooks.
454 static char *log_destination_string;
456 static char *syslog_ident_str;
457 static bool phony_autocommit;
458 static bool session_auth_is_superuser;
459 static double phony_random_seed;
460 static char *client_encoding_string;
461 static char *datestyle_string;
462 static char *locale_collate;
463 static char *locale_ctype;
464 static char *server_encoding_string;
465 static char *server_version_string;
466 static int server_version_num;
467 static char *timezone_string;
468 static char *log_timezone_string;
469 static char *timezone_abbreviations_string;
470 static char *XactIsoLevel_string;
471 static char *session_authorization_string;
472 static int max_function_args;
473 static int max_index_keys;
474 static int max_identifier_length;
475 static int block_size;
476 static int segment_size;
477 static int wal_block_size;
478 static int wal_segment_size;
479 static bool integer_datetimes;
480 static int effective_io_concurrency;
482 /* should be static, but commands/variable.c needs to get at this */
487 * Displayable names for context types (enum GucContext)
489 * Note: these strings are deliberately not localized.
491 const char *const GucContext_Names[] =
493 /* PGC_INTERNAL */ "internal",
494 /* PGC_POSTMASTER */ "postmaster",
495 /* PGC_SIGHUP */ "sighup",
496 /* PGC_BACKEND */ "backend",
497 /* PGC_SUSET */ "superuser",
498 /* PGC_USERSET */ "user"
502 * Displayable names for source types (enum GucSource)
504 * Note: these strings are deliberately not localized.
506 const char *const GucSource_Names[] =
508 /* PGC_S_DEFAULT */ "default",
509 /* PGC_S_DYNAMIC_DEFAULT */ "default",
510 /* PGC_S_ENV_VAR */ "environment variable",
511 /* PGC_S_FILE */ "configuration file",
512 /* PGC_S_ARGV */ "command line",
513 /* PGC_S_DATABASE */ "database",
514 /* PGC_S_USER */ "user",
515 /* PGC_S_DATABASE_USER */ "database user",
516 /* PGC_S_CLIENT */ "client",
517 /* PGC_S_OVERRIDE */ "override",
518 /* PGC_S_INTERACTIVE */ "interactive",
519 /* PGC_S_TEST */ "test",
520 /* PGC_S_SESSION */ "session"
524 * Displayable names for the groupings defined in enum config_group
526 const char *const config_group_names[] =
529 gettext_noop("Ungrouped"),
531 gettext_noop("File Locations"),
533 gettext_noop("Connections and Authentication"),
534 /* CONN_AUTH_SETTINGS */
535 gettext_noop("Connections and Authentication / Connection Settings"),
536 /* CONN_AUTH_SECURITY */
537 gettext_noop("Connections and Authentication / Security and Authentication"),
539 gettext_noop("Resource Usage"),
541 gettext_noop("Resource Usage / Memory"),
543 gettext_noop("Resource Usage / Disk"),
544 /* RESOURCES_KERNEL */
545 gettext_noop("Resource Usage / Kernel Resources"),
546 /* RESOURCES_VACUUM_DELAY */
547 gettext_noop("Resource Usage / Cost-Based Vacuum Delay"),
548 /* RESOURCES_BGWRITER */
549 gettext_noop("Resource Usage / Background Writer"),
550 /* RESOURCES_ASYNCHRONOUS */
551 gettext_noop("Resource Usage / Asynchronous Behavior"),
553 gettext_noop("Write-Ahead Log"),
555 gettext_noop("Write-Ahead Log / Settings"),
556 /* WAL_CHECKPOINTS */
557 gettext_noop("Write-Ahead Log / Checkpoints"),
559 gettext_noop("Write-Ahead Log / Archiving"),
561 gettext_noop("Replication"),
562 /* REPLICATION_SENDING */
563 gettext_noop("Replication / Sending Servers"),
564 /* REPLICATION_MASTER */
565 gettext_noop("Replication / Master Server"),
566 /* REPLICATION_STANDBY */
567 gettext_noop("Replication / Standby Servers"),
569 gettext_noop("Query Tuning"),
570 /* QUERY_TUNING_METHOD */
571 gettext_noop("Query Tuning / Planner Method Configuration"),
572 /* QUERY_TUNING_COST */
573 gettext_noop("Query Tuning / Planner Cost Constants"),
574 /* QUERY_TUNING_GEQO */
575 gettext_noop("Query Tuning / Genetic Query Optimizer"),
576 /* QUERY_TUNING_OTHER */
577 gettext_noop("Query Tuning / Other Planner Options"),
579 gettext_noop("Reporting and Logging"),
581 gettext_noop("Reporting and Logging / Where to Log"),
583 gettext_noop("Reporting and Logging / When to Log"),
585 gettext_noop("Reporting and Logging / What to Log"),
587 gettext_noop("Statistics"),
588 /* STATS_MONITORING */
589 gettext_noop("Statistics / Monitoring"),
590 /* STATS_COLLECTOR */
591 gettext_noop("Statistics / Query and Index Statistics Collector"),
593 gettext_noop("Autovacuum"),
595 gettext_noop("Client Connection Defaults"),
596 /* CLIENT_CONN_STATEMENT */
597 gettext_noop("Client Connection Defaults / Statement Behavior"),
598 /* CLIENT_CONN_LOCALE */
599 gettext_noop("Client Connection Defaults / Locale and Formatting"),
600 /* CLIENT_CONN_OTHER */
601 gettext_noop("Client Connection Defaults / Other Defaults"),
602 /* LOCK_MANAGEMENT */
603 gettext_noop("Lock Management"),
605 gettext_noop("Version and Platform Compatibility"),
606 /* COMPAT_OPTIONS_PREVIOUS */
607 gettext_noop("Version and Platform Compatibility / Previous PostgreSQL Versions"),
608 /* COMPAT_OPTIONS_CLIENT */
609 gettext_noop("Version and Platform Compatibility / Other Platforms and Clients"),
611 gettext_noop("Error Handling"),
613 gettext_noop("Preset Options"),
615 gettext_noop("Customized Options"),
616 /* DEVELOPER_OPTIONS */
617 gettext_noop("Developer Options"),
618 /* help_config wants this array to be null-terminated */
623 * Displayable names for GUC variable types (enum config_type)
625 * Note: these strings are deliberately not localized.
627 const char *const config_type_names[] =
629 /* PGC_BOOL */ "bool",
630 /* PGC_INT */ "integer",
631 /* PGC_REAL */ "real",
632 /* PGC_STRING */ "string",
633 /* PGC_ENUM */ "enum"
638 * Contents of GUC tables
640 * See src/backend/utils/misc/README for design notes.
644 * 1. Declare a global variable of type bool, int, double, or char*
645 * and make use of it.
647 * 2. Decide at what times it's safe to set the option. See guc.h for
650 * 3. Decide on a name, a default value, upper and lower bounds (if
653 * 4. Add a record below.
655 * 5. Add it to src/backend/utils/misc/postgresql.conf.sample, if
658 * 6. Don't forget to document the option (at least in config.sgml).
660 * 7. If it's a new GUC_LIST option you must edit pg_dumpall.c to ensure
661 * it is not single quoted at dump time.
665 /******** option records follow ********/
667 static struct config_bool ConfigureNamesBool[] =
670 {"enable_seqscan", PGC_USERSET, QUERY_TUNING_METHOD,
671 gettext_noop("Enables the planner's use of sequential-scan plans."),
679 {"enable_indexscan", PGC_USERSET, QUERY_TUNING_METHOD,
680 gettext_noop("Enables the planner's use of index-scan plans."),
688 {"enable_indexonlyscan", PGC_USERSET, QUERY_TUNING_METHOD,
689 gettext_noop("Enables the planner's use of index-only-scan plans."),
692 &enable_indexonlyscan,
697 {"enable_bitmapscan", PGC_USERSET, QUERY_TUNING_METHOD,
698 gettext_noop("Enables the planner's use of bitmap-scan plans."),
706 {"enable_tidscan", PGC_USERSET, QUERY_TUNING_METHOD,
707 gettext_noop("Enables the planner's use of TID scan plans."),
715 {"enable_sort", PGC_USERSET, QUERY_TUNING_METHOD,
716 gettext_noop("Enables the planner's use of explicit sort steps."),
724 {"enable_hashagg", PGC_USERSET, QUERY_TUNING_METHOD,
725 gettext_noop("Enables the planner's use of hashed aggregation plans."),
733 {"enable_material", PGC_USERSET, QUERY_TUNING_METHOD,
734 gettext_noop("Enables the planner's use of materialization."),
742 {"enable_nestloop", PGC_USERSET, QUERY_TUNING_METHOD,
743 gettext_noop("Enables the planner's use of nested-loop join plans."),
751 {"enable_mergejoin", PGC_USERSET, QUERY_TUNING_METHOD,
752 gettext_noop("Enables the planner's use of merge join plans."),
760 {"enable_hashjoin", PGC_USERSET, QUERY_TUNING_METHOD,
761 gettext_noop("Enables the planner's use of hash join plans."),
769 {"geqo", PGC_USERSET, QUERY_TUNING_GEQO,
770 gettext_noop("Enables genetic query optimization."),
771 gettext_noop("This algorithm attempts to do planning without "
772 "exhaustive searching.")
779 /* Not for general use --- used by SET SESSION AUTHORIZATION */
780 {"is_superuser", PGC_INTERNAL, UNGROUPED,
781 gettext_noop("Shows whether the current user is a superuser."),
783 GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
785 &session_auth_is_superuser,
790 {"bonjour", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
791 gettext_noop("Enables advertising the server via Bonjour."),
796 check_bonjour, NULL, NULL
799 {"ssl", PGC_POSTMASTER, CONN_AUTH_SECURITY,
800 gettext_noop("Enables SSL connections."),
805 check_ssl, NULL, NULL
808 {"fsync", PGC_SIGHUP, WAL_SETTINGS,
809 gettext_noop("Forces synchronization of updates to disk."),
810 gettext_noop("The server will use the fsync() system call in several places to make "
811 "sure that updates are physically written to disk. This insures "
812 "that a database cluster will recover to a consistent state after "
813 "an operating system or hardware crash.")
820 {"zero_damaged_pages", PGC_SUSET, DEVELOPER_OPTIONS,
821 gettext_noop("Continues processing past damaged page headers."),
822 gettext_noop("Detection of a damaged page header normally causes PostgreSQL to "
823 "report an error, aborting the current transaction. Setting "
824 "zero_damaged_pages to true causes the system to instead report a "
825 "warning, zero out the damaged page, and continue processing. This "
826 "behavior will destroy data, namely all the rows on the damaged page."),
834 {"full_page_writes", PGC_SIGHUP, WAL_SETTINGS,
835 gettext_noop("Writes full pages to WAL when first modified after a checkpoint."),
836 gettext_noop("A page write in process during an operating system crash might be "
837 "only partially written to disk. During recovery, the row changes "
838 "stored in WAL are not enough to recover. This option writes "
839 "pages when first modified after a checkpoint to WAL so full recovery "
847 {"log_checkpoints", PGC_SIGHUP, LOGGING_WHAT,
848 gettext_noop("Logs each checkpoint."),
856 {"log_connections", PGC_BACKEND, LOGGING_WHAT,
857 gettext_noop("Logs each successful connection."),
865 {"log_disconnections", PGC_BACKEND, LOGGING_WHAT,
866 gettext_noop("Logs end of a session, including duration."),
874 {"debug_assertions", PGC_USERSET, DEVELOPER_OPTIONS,
875 gettext_noop("Turns on various assertion checks."),
876 gettext_noop("This is a debugging aid."),
880 #ifdef USE_ASSERT_CHECKING
885 check_debug_assertions, NULL, NULL
889 {"exit_on_error", PGC_USERSET, ERROR_HANDLING_OPTIONS,
890 gettext_noop("Terminate session on any error."),
898 {"restart_after_crash", PGC_SIGHUP, ERROR_HANDLING_OPTIONS,
899 gettext_noop("Reinitialize server after backend crash."),
902 &restart_after_crash,
908 {"log_duration", PGC_SUSET, LOGGING_WHAT,
909 gettext_noop("Logs the duration of each completed SQL statement."),
917 {"debug_print_parse", PGC_USERSET, LOGGING_WHAT,
918 gettext_noop("Logs each query's parse tree."),
926 {"debug_print_rewritten", PGC_USERSET, LOGGING_WHAT,
927 gettext_noop("Logs each query's rewritten parse tree."),
930 &Debug_print_rewritten,
935 {"debug_print_plan", PGC_USERSET, LOGGING_WHAT,
936 gettext_noop("Logs each query's execution plan."),
944 {"debug_pretty_print", PGC_USERSET, LOGGING_WHAT,
945 gettext_noop("Indents parse and plan tree displays."),
953 {"log_parser_stats", PGC_SUSET, STATS_MONITORING,
954 gettext_noop("Writes parser performance statistics to the server log."),
959 check_stage_log_stats, NULL, NULL
962 {"log_planner_stats", PGC_SUSET, STATS_MONITORING,
963 gettext_noop("Writes planner performance statistics to the server log."),
968 check_stage_log_stats, NULL, NULL
971 {"log_executor_stats", PGC_SUSET, STATS_MONITORING,
972 gettext_noop("Writes executor performance statistics to the server log."),
977 check_stage_log_stats, NULL, NULL
980 {"log_statement_stats", PGC_SUSET, STATS_MONITORING,
981 gettext_noop("Writes cumulative performance statistics to the server log."),
984 &log_statement_stats,
986 check_log_stats, NULL, NULL
988 #ifdef BTREE_BUILD_STATS
990 {"log_btree_build_stats", PGC_SUSET, DEVELOPER_OPTIONS,
991 gettext_noop("No description available."),
995 &log_btree_build_stats,
1002 {"track_activities", PGC_SUSET, STATS_COLLECTOR,
1003 gettext_noop("Collects information about executing commands."),
1004 gettext_noop("Enables the collection of information on the currently "
1005 "executing command of each session, along with "
1006 "the time at which that command began execution.")
1008 &pgstat_track_activities,
1013 {"track_counts", PGC_SUSET, STATS_COLLECTOR,
1014 gettext_noop("Collects statistics on database activity."),
1017 &pgstat_track_counts,
1023 {"update_process_title", PGC_SUSET, STATS_COLLECTOR,
1024 gettext_noop("Updates the process title to show the active SQL command."),
1025 gettext_noop("Enables updating of the process title every time a new SQL command is received by the server.")
1027 &update_process_title,
1033 {"autovacuum", PGC_SIGHUP, AUTOVACUUM,
1034 gettext_noop("Starts the autovacuum subprocess."),
1037 &autovacuum_start_daemon,
1043 {"trace_notify", PGC_USERSET, DEVELOPER_OPTIONS,
1044 gettext_noop("Generates debugging output for LISTEN and NOTIFY."),
1055 {"trace_locks", PGC_SUSET, DEVELOPER_OPTIONS,
1056 gettext_noop("No description available."),
1065 {"trace_userlocks", PGC_SUSET, DEVELOPER_OPTIONS,
1066 gettext_noop("No description available."),
1075 {"trace_lwlocks", PGC_SUSET, DEVELOPER_OPTIONS,
1076 gettext_noop("No description available."),
1085 {"debug_deadlocks", PGC_SUSET, DEVELOPER_OPTIONS,
1086 gettext_noop("No description available."),
1097 {"log_lock_waits", PGC_SUSET, LOGGING_WHAT,
1098 gettext_noop("Logs long lock waits."),
1107 {"log_hostname", PGC_SIGHUP, LOGGING_WHAT,
1108 gettext_noop("Logs the host name in the connection logs."),
1109 gettext_noop("By default, connection logs only show the IP address "
1110 "of the connecting host. If you want them to show the host name you "
1111 "can turn this on, but depending on your host name resolution "
1112 "setup it might impose a non-negligible performance penalty.")
1119 {"sql_inheritance", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1120 gettext_noop("Causes subtables to be included by default in various commands."),
1128 {"password_encryption", PGC_USERSET, CONN_AUTH_SECURITY,
1129 gettext_noop("Encrypt passwords."),
1130 gettext_noop("When a password is specified in CREATE USER or "
1131 "ALTER USER without writing either ENCRYPTED or UNENCRYPTED, "
1132 "this parameter determines whether the password is to be encrypted.")
1134 &Password_encryption,
1139 {"transform_null_equals", PGC_USERSET, COMPAT_OPTIONS_CLIENT,
1140 gettext_noop("Treats \"expr=NULL\" as \"expr IS NULL\"."),
1141 gettext_noop("When turned on, expressions of the form expr = NULL "
1142 "(or NULL = expr) are treated as expr IS NULL, that is, they "
1143 "return true if expr evaluates to the null value, and false "
1144 "otherwise. The correct behavior of expr = NULL is to always "
1145 "return null (unknown).")
1147 &Transform_null_equals,
1152 {"db_user_namespace", PGC_SIGHUP, CONN_AUTH_SECURITY,
1153 gettext_noop("Enables per-database user names."),
1161 /* only here for backwards compatibility */
1162 {"autocommit", PGC_USERSET, CLIENT_CONN_STATEMENT,
1163 gettext_noop("This parameter doesn't do anything."),
1164 gettext_noop("It's just here so that we won't choke on SET AUTOCOMMIT TO ON from 7.3-vintage clients."),
1165 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
1169 check_phony_autocommit, NULL, NULL
1172 {"default_transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
1173 gettext_noop("Sets the default read-only status of new transactions."),
1176 &DefaultXactReadOnly,
1181 {"transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
1182 gettext_noop("Sets the current transaction's read-only status."),
1184 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1188 check_transaction_read_only, NULL, NULL
1191 {"default_transaction_deferrable", PGC_USERSET, CLIENT_CONN_STATEMENT,
1192 gettext_noop("Sets the default deferrable status of new transactions."),
1195 &DefaultXactDeferrable,
1200 {"transaction_deferrable", PGC_USERSET, CLIENT_CONN_STATEMENT,
1201 gettext_noop("Whether to defer a read-only serializable transaction until it can be executed with no possible serialization failures."),
1203 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1207 check_transaction_deferrable, NULL, NULL
1210 {"check_function_bodies", PGC_USERSET, CLIENT_CONN_STATEMENT,
1211 gettext_noop("Check function bodies during CREATE FUNCTION."),
1214 &check_function_bodies,
1219 {"array_nulls", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1220 gettext_noop("Enable input of NULL elements in arrays."),
1221 gettext_noop("When turned on, unquoted NULL in an array input "
1222 "value means a null value; "
1223 "otherwise it is taken literally.")
1230 {"default_with_oids", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1231 gettext_noop("Create new tables with OIDs by default."),
1239 {"logging_collector", PGC_POSTMASTER, LOGGING_WHERE,
1240 gettext_noop("Start a subprocess to capture stderr output and/or csvlogs into log files."),
1248 {"log_truncate_on_rotation", PGC_SIGHUP, LOGGING_WHERE,
1249 gettext_noop("Truncate existing log files of same name during log rotation."),
1252 &Log_truncate_on_rotation,
1259 {"trace_sort", PGC_USERSET, DEVELOPER_OPTIONS,
1260 gettext_noop("Emit information about resource usage in sorting."),
1270 #ifdef TRACE_SYNCSCAN
1271 /* this is undocumented because not exposed in a standard build */
1273 {"trace_syncscan", PGC_USERSET, DEVELOPER_OPTIONS,
1274 gettext_noop("Generate debugging output for synchronized scanning."),
1284 #ifdef DEBUG_BOUNDED_SORT
1285 /* this is undocumented because not exposed in a standard build */
1288 "optimize_bounded_sort", PGC_USERSET, QUERY_TUNING_METHOD,
1289 gettext_noop("Enable bounded sorting using heap sort."),
1293 &optimize_bounded_sort,
1301 {"wal_debug", PGC_SUSET, DEVELOPER_OPTIONS,
1302 gettext_noop("Emit WAL-related debugging output."),
1313 {"integer_datetimes", PGC_INTERNAL, PRESET_OPTIONS,
1314 gettext_noop("Datetimes are integer based."),
1316 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1319 #ifdef HAVE_INT64_TIMESTAMP
1328 {"krb_caseins_users", PGC_SIGHUP, CONN_AUTH_SECURITY,
1329 gettext_noop("Sets whether Kerberos and GSSAPI user names should be treated as case-insensitive."),
1332 &pg_krb_caseins_users,
1338 {"escape_string_warning", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1339 gettext_noop("Warn about backslash escapes in ordinary string literals."),
1342 &escape_string_warning,
1348 {"standard_conforming_strings", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1349 gettext_noop("Causes '...' strings to treat backslashes literally."),
1353 &standard_conforming_strings,
1359 {"synchronize_seqscans", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1360 gettext_noop("Enable synchronized sequential scans."),
1363 &synchronize_seqscans,
1369 {"archive_mode", PGC_POSTMASTER, WAL_ARCHIVING,
1370 gettext_noop("Allows archiving of WAL files using archive_command."),
1379 {"hot_standby", PGC_POSTMASTER, REPLICATION_STANDBY,
1380 gettext_noop("Allows connections and queries during recovery."),
1389 {"hot_standby_feedback", PGC_SIGHUP, REPLICATION_STANDBY,
1390 gettext_noop("Allows feedback from a hot standby to the primary that will avoid query conflicts."),
1393 &hot_standby_feedback,
1399 {"allow_system_table_mods", PGC_POSTMASTER, DEVELOPER_OPTIONS,
1400 gettext_noop("Allows modifications of the structure of system tables."),
1404 &allowSystemTableMods,
1410 {"ignore_system_indexes", PGC_BACKEND, DEVELOPER_OPTIONS,
1411 gettext_noop("Disables reading from system indexes."),
1412 gettext_noop("It does not prevent updating the indexes, so it is safe "
1413 "to use. The worst consequence is slowness."),
1416 &IgnoreSystemIndexes,
1422 {"lo_compat_privileges", PGC_SUSET, COMPAT_OPTIONS_PREVIOUS,
1423 gettext_noop("Enables backward compatibility mode for privilege checks on large objects."),
1424 gettext_noop("Skips privilege checks when reading or modifying large objects, "
1425 "for compatibility with PostgreSQL releases prior to 9.0.")
1427 &lo_compat_privileges,
1433 {"quote_all_identifiers", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1434 gettext_noop("When generating SQL fragments, quote all identifiers."),
1437 "e_all_identifiers,
1442 /* End-of-list marker */
1444 {NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL, NULL
1449 static struct config_int ConfigureNamesInt[] =
1452 {"archive_timeout", PGC_SIGHUP, WAL_ARCHIVING,
1453 gettext_noop("Forces a switch to the next xlog file if a "
1454 "new file has not been started within N seconds."),
1458 &XLogArchiveTimeout,
1463 {"post_auth_delay", PGC_BACKEND, DEVELOPER_OPTIONS,
1464 gettext_noop("Waits N seconds on connection startup after authentication."),
1465 gettext_noop("This allows attaching a debugger to the process."),
1466 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1473 {"default_statistics_target", PGC_USERSET, QUERY_TUNING_OTHER,
1474 gettext_noop("Sets the default statistics target."),
1475 gettext_noop("This applies to table columns that have not had a "
1476 "column-specific target set via ALTER TABLE SET STATISTICS.")
1478 &default_statistics_target,
1483 {"from_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1484 gettext_noop("Sets the FROM-list size beyond which subqueries "
1485 "are not collapsed."),
1486 gettext_noop("The planner will merge subqueries into upper "
1487 "queries if the resulting FROM list would have no more than "
1490 &from_collapse_limit,
1495 {"join_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1496 gettext_noop("Sets the FROM-list size beyond which JOIN "
1497 "constructs are not flattened."),
1498 gettext_noop("The planner will flatten explicit JOIN "
1499 "constructs into lists of FROM items whenever a "
1500 "list of no more than this many items would result.")
1502 &join_collapse_limit,
1507 {"geqo_threshold", PGC_USERSET, QUERY_TUNING_GEQO,
1508 gettext_noop("Sets the threshold of FROM items beyond which GEQO is used."),
1516 {"geqo_effort", PGC_USERSET, QUERY_TUNING_GEQO,
1517 gettext_noop("GEQO: effort is used to set the default for other GEQO parameters."),
1521 DEFAULT_GEQO_EFFORT, MIN_GEQO_EFFORT, MAX_GEQO_EFFORT,
1525 {"geqo_pool_size", PGC_USERSET, QUERY_TUNING_GEQO,
1526 gettext_noop("GEQO: number of individuals in the population."),
1527 gettext_noop("Zero selects a suitable default value.")
1534 {"geqo_generations", PGC_USERSET, QUERY_TUNING_GEQO,
1535 gettext_noop("GEQO: number of iterations of the algorithm."),
1536 gettext_noop("Zero selects a suitable default value.")
1544 /* This is PGC_SUSET to prevent hiding from log_lock_waits. */
1545 {"deadlock_timeout", PGC_SUSET, LOCK_MANAGEMENT,
1546 gettext_noop("Sets the time to wait on a lock before checking for deadlock."),
1556 {"max_standby_archive_delay", PGC_SIGHUP, REPLICATION_STANDBY,
1557 gettext_noop("Sets the maximum delay before canceling queries when a hot standby server is processing archived WAL data."),
1561 &max_standby_archive_delay,
1562 30 * 1000, -1, INT_MAX,
1567 {"max_standby_streaming_delay", PGC_SIGHUP, REPLICATION_STANDBY,
1568 gettext_noop("Sets the maximum delay before canceling queries when a hot standby server is processing streamed WAL data."),
1572 &max_standby_streaming_delay,
1573 30 * 1000, -1, INT_MAX,
1578 {"wal_receiver_status_interval", PGC_SIGHUP, REPLICATION_STANDBY,
1579 gettext_noop("Sets the maximum interval between WAL receiver status reports to the primary."),
1583 &wal_receiver_status_interval,
1584 10, 0, INT_MAX / 1000,
1589 {"max_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1590 gettext_noop("Sets the maximum number of concurrent connections."),
1594 100, 1, MAX_BACKENDS,
1595 check_maxconnections, assign_maxconnections, NULL
1599 {"superuser_reserved_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1600 gettext_noop("Sets the number of connection slots reserved for superusers."),
1609 * We sometimes multiply the number of shared buffers by two without
1610 * checking for overflow, so we mustn't allow more than INT_MAX / 2.
1613 {"shared_buffers", PGC_POSTMASTER, RESOURCES_MEM,
1614 gettext_noop("Sets the number of shared memory buffers used by the server."),
1619 1024, 16, INT_MAX / 2,
1624 {"temp_buffers", PGC_USERSET, RESOURCES_MEM,
1625 gettext_noop("Sets the maximum number of temporary buffers used by each session."),
1630 1024, 100, INT_MAX / 2,
1631 check_temp_buffers, NULL, NULL
1635 {"port", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1636 gettext_noop("Sets the TCP port the server listens on."),
1640 DEF_PGPORT, 1, 65535,
1645 {"unix_socket_permissions", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1646 gettext_noop("Sets the access permissions of the Unix-domain socket."),
1647 gettext_noop("Unix-domain sockets use the usual Unix file system "
1648 "permission set. The parameter value is expected "
1649 "to be a numeric mode specification in the form "
1650 "accepted by the chmod and umask system calls. "
1651 "(To use the customary octal format the number must "
1652 "start with a 0 (zero).)")
1654 &Unix_socket_permissions,
1656 NULL, NULL, show_unix_socket_permissions
1660 {"log_file_mode", PGC_SIGHUP, LOGGING_WHERE,
1661 gettext_noop("Sets the file permissions for log files."),
1662 gettext_noop("The parameter value is expected "
1663 "to be a numeric mode specification in the form "
1664 "accepted by the chmod and umask system calls. "
1665 "(To use the customary octal format the number must "
1666 "start with a 0 (zero).)")
1670 NULL, NULL, show_log_file_mode
1674 {"work_mem", PGC_USERSET, RESOURCES_MEM,
1675 gettext_noop("Sets the maximum memory to be used for query workspaces."),
1676 gettext_noop("This much memory can be used by each internal "
1677 "sort operation and hash table before switching to "
1678 "temporary disk files."),
1682 1024, 64, MAX_KILOBYTES,
1687 {"maintenance_work_mem", PGC_USERSET, RESOURCES_MEM,
1688 gettext_noop("Sets the maximum memory to be used for maintenance operations."),
1689 gettext_noop("This includes operations such as VACUUM and CREATE INDEX."),
1692 &maintenance_work_mem,
1693 16384, 1024, MAX_KILOBYTES,
1698 * We use the hopefully-safely-small value of 100kB as the compiled-in
1699 * default for max_stack_depth. InitializeGUCOptions will increase it if
1700 * possible, depending on the actual platform-specific stack limit.
1703 {"max_stack_depth", PGC_SUSET, RESOURCES_MEM,
1704 gettext_noop("Sets the maximum stack depth, in kilobytes."),
1709 100, 100, MAX_KILOBYTES,
1710 check_max_stack_depth, assign_max_stack_depth, NULL
1714 {"temp_file_limit", PGC_SUSET, RESOURCES_DISK,
1715 gettext_noop("Limits the total size of all temp files used by each session."),
1716 gettext_noop("-1 means no limit."),
1725 {"vacuum_cost_page_hit", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1726 gettext_noop("Vacuum cost for a page found in the buffer cache."),
1735 {"vacuum_cost_page_miss", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1736 gettext_noop("Vacuum cost for a page not found in the buffer cache."),
1739 &VacuumCostPageMiss,
1745 {"vacuum_cost_page_dirty", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1746 gettext_noop("Vacuum cost for a page dirtied by vacuum."),
1749 &VacuumCostPageDirty,
1755 {"vacuum_cost_limit", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1756 gettext_noop("Vacuum cost amount available before napping."),
1765 {"vacuum_cost_delay", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1766 gettext_noop("Vacuum cost delay in milliseconds."),
1776 {"autovacuum_vacuum_cost_delay", PGC_SIGHUP, AUTOVACUUM,
1777 gettext_noop("Vacuum cost delay in milliseconds, for autovacuum."),
1781 &autovacuum_vac_cost_delay,
1787 {"autovacuum_vacuum_cost_limit", PGC_SIGHUP, AUTOVACUUM,
1788 gettext_noop("Vacuum cost amount available before napping, for autovacuum."),
1791 &autovacuum_vac_cost_limit,
1797 {"max_files_per_process", PGC_POSTMASTER, RESOURCES_KERNEL,
1798 gettext_noop("Sets the maximum number of simultaneously open files for each server process."),
1801 &max_files_per_process,
1807 * See also CheckRequiredParameterValues() if this parameter changes
1810 {"max_prepared_transactions", PGC_POSTMASTER, RESOURCES_MEM,
1811 gettext_noop("Sets the maximum number of simultaneously prepared transactions."),
1814 &max_prepared_xacts,
1821 {"trace_lock_oidmin", PGC_SUSET, DEVELOPER_OPTIONS,
1822 gettext_noop("No description available."),
1827 FirstNormalObjectId, 0, INT_MAX,
1831 {"trace_lock_table", PGC_SUSET, DEVELOPER_OPTIONS,
1832 gettext_noop("No description available."),
1843 {"statement_timeout", PGC_USERSET, CLIENT_CONN_STATEMENT,
1844 gettext_noop("Sets the maximum allowed duration of any statement."),
1845 gettext_noop("A value of 0 turns off the timeout."),
1854 {"vacuum_freeze_min_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1855 gettext_noop("Minimum age at which VACUUM should freeze a table row."),
1858 &vacuum_freeze_min_age,
1859 50000000, 0, 1000000000,
1864 {"vacuum_freeze_table_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1865 gettext_noop("Age at which VACUUM should scan whole table to freeze tuples."),
1868 &vacuum_freeze_table_age,
1869 150000000, 0, 2000000000,
1874 {"vacuum_defer_cleanup_age", PGC_SIGHUP, REPLICATION_MASTER,
1875 gettext_noop("Number of transactions by which VACUUM and HOT cleanup should be deferred, if any."),
1878 &vacuum_defer_cleanup_age,
1884 * See also CheckRequiredParameterValues() if this parameter changes
1887 {"max_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
1888 gettext_noop("Sets the maximum number of locks per transaction."),
1889 gettext_noop("The shared lock table is sized on the assumption that "
1890 "at most max_locks_per_transaction * max_connections distinct "
1891 "objects will need to be locked at any one time.")
1893 &max_locks_per_xact,
1899 {"max_pred_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
1900 gettext_noop("Sets the maximum number of predicate locks per transaction."),
1901 gettext_noop("The shared predicate lock table is sized on the assumption that "
1902 "at most max_pred_locks_per_transaction * max_connections distinct "
1903 "objects will need to be locked at any one time.")
1905 &max_predicate_locks_per_xact,
1911 {"authentication_timeout", PGC_SIGHUP, CONN_AUTH_SECURITY,
1912 gettext_noop("Sets the maximum allowed time to complete client authentication."),
1916 &AuthenticationTimeout,
1922 /* Not for general use */
1923 {"pre_auth_delay", PGC_SIGHUP, DEVELOPER_OPTIONS,
1924 gettext_noop("Waits N seconds on connection startup before authentication."),
1925 gettext_noop("This allows attaching a debugger to the process."),
1926 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1934 {"wal_keep_segments", PGC_SIGHUP, REPLICATION_SENDING,
1935 gettext_noop("Sets the number of WAL files held for standby servers."),
1944 {"checkpoint_segments", PGC_SIGHUP, WAL_CHECKPOINTS,
1945 gettext_noop("Sets the maximum distance in log segments between automatic WAL checkpoints."),
1948 &CheckPointSegments,
1954 {"checkpoint_timeout", PGC_SIGHUP, WAL_CHECKPOINTS,
1955 gettext_noop("Sets the maximum time between automatic WAL checkpoints."),
1965 {"checkpoint_warning", PGC_SIGHUP, WAL_CHECKPOINTS,
1966 gettext_noop("Enables warnings if checkpoint segments are filled more "
1967 "frequently than this."),
1968 gettext_noop("Write a message to the server log if checkpoints "
1969 "caused by the filling of checkpoint segment files happens more "
1970 "frequently than this number of seconds. Zero turns off the warning."),
1979 {"wal_buffers", PGC_POSTMASTER, WAL_SETTINGS,
1980 gettext_noop("Sets the number of disk-page buffers in shared memory for WAL."),
1986 check_wal_buffers, NULL, NULL
1990 {"wal_writer_delay", PGC_SIGHUP, WAL_SETTINGS,
1991 gettext_noop("WAL writer sleep time between WAL flushes."),
2001 /* see max_connections */
2002 {"max_wal_senders", PGC_POSTMASTER, REPLICATION_SENDING,
2003 gettext_noop("Sets the maximum number of simultaneously running WAL sender processes."),
2012 {"replication_timeout", PGC_SIGHUP, REPLICATION_SENDING,
2013 gettext_noop("Sets the maximum time to wait for WAL replication."),
2017 &replication_timeout,
2018 60 * 1000, 0, INT_MAX,
2023 {"commit_delay", PGC_USERSET, WAL_SETTINGS,
2024 gettext_noop("Sets the delay in microseconds between transaction commit and "
2025 "flushing WAL to disk."),
2034 {"commit_siblings", PGC_USERSET, WAL_SETTINGS,
2035 gettext_noop("Sets the minimum concurrent open transactions before performing "
2045 {"extra_float_digits", PGC_USERSET, CLIENT_CONN_LOCALE,
2046 gettext_noop("Sets the number of digits displayed for floating-point values."),
2047 gettext_noop("This affects real, double precision, and geometric data types. "
2048 "The parameter value is added to the standard number of digits "
2049 "(FLT_DIG or DBL_DIG as appropriate).")
2051 &extra_float_digits,
2057 {"log_min_duration_statement", PGC_SUSET, LOGGING_WHEN,
2058 gettext_noop("Sets the minimum execution time above which "
2059 "statements will be logged."),
2060 gettext_noop("Zero prints all queries. -1 turns this feature off."),
2063 &log_min_duration_statement,
2069 {"log_autovacuum_min_duration", PGC_SIGHUP, LOGGING_WHAT,
2070 gettext_noop("Sets the minimum execution time above which "
2071 "autovacuum actions will be logged."),
2072 gettext_noop("Zero prints all actions. -1 turns autovacuum logging off."),
2075 &Log_autovacuum_min_duration,
2081 {"bgwriter_delay", PGC_SIGHUP, RESOURCES_BGWRITER,
2082 gettext_noop("Background writer sleep time between rounds."),
2092 {"bgwriter_lru_maxpages", PGC_SIGHUP, RESOURCES_BGWRITER,
2093 gettext_noop("Background writer maximum number of LRU pages to flush per round."),
2096 &bgwriter_lru_maxpages,
2102 {"effective_io_concurrency",
2108 RESOURCES_ASYNCHRONOUS,
2109 gettext_noop("Number of simultaneous requests that can be handled efficiently by the disk subsystem."),
2110 gettext_noop("For RAID arrays, this should be approximately the number of drive spindles in the array.")
2112 &effective_io_concurrency,
2118 check_effective_io_concurrency, assign_effective_io_concurrency, NULL
2122 {"log_rotation_age", PGC_SIGHUP, LOGGING_WHERE,
2123 gettext_noop("Automatic log file rotation will occur after N minutes."),
2128 HOURS_PER_DAY * MINS_PER_HOUR, 0, INT_MAX / MINS_PER_HOUR,
2133 {"log_rotation_size", PGC_SIGHUP, LOGGING_WHERE,
2134 gettext_noop("Automatic log file rotation will occur after N kilobytes."),
2139 10 * 1024, 0, INT_MAX / 1024,
2144 {"max_function_args", PGC_INTERNAL, PRESET_OPTIONS,
2145 gettext_noop("Shows the maximum number of function arguments."),
2147 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2150 FUNC_MAX_ARGS, FUNC_MAX_ARGS, FUNC_MAX_ARGS,
2155 {"max_index_keys", PGC_INTERNAL, PRESET_OPTIONS,
2156 gettext_noop("Shows the maximum number of index keys."),
2158 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2161 INDEX_MAX_KEYS, INDEX_MAX_KEYS, INDEX_MAX_KEYS,
2166 {"max_identifier_length", PGC_INTERNAL, PRESET_OPTIONS,
2167 gettext_noop("Shows the maximum identifier length."),
2169 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2171 &max_identifier_length,
2172 NAMEDATALEN - 1, NAMEDATALEN - 1, NAMEDATALEN - 1,
2177 {"block_size", PGC_INTERNAL, PRESET_OPTIONS,
2178 gettext_noop("Shows the size of a disk block."),
2180 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2183 BLCKSZ, BLCKSZ, BLCKSZ,
2188 {"segment_size", PGC_INTERNAL, PRESET_OPTIONS,
2189 gettext_noop("Shows the number of pages per disk file."),
2191 GUC_UNIT_BLOCKS | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2194 RELSEG_SIZE, RELSEG_SIZE, RELSEG_SIZE,
2199 {"wal_block_size", PGC_INTERNAL, PRESET_OPTIONS,
2200 gettext_noop("Shows the block size in the write ahead log."),
2202 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2205 XLOG_BLCKSZ, XLOG_BLCKSZ, XLOG_BLCKSZ,
2210 {"wal_segment_size", PGC_INTERNAL, PRESET_OPTIONS,
2211 gettext_noop("Shows the number of pages per write ahead log segment."),
2213 GUC_UNIT_XBLOCKS | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2216 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
2217 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
2218 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
2223 {"autovacuum_naptime", PGC_SIGHUP, AUTOVACUUM,
2224 gettext_noop("Time to sleep between autovacuum runs."),
2228 &autovacuum_naptime,
2229 60, 1, INT_MAX / 1000,
2233 {"autovacuum_vacuum_threshold", PGC_SIGHUP, AUTOVACUUM,
2234 gettext_noop("Minimum number of tuple updates or deletes prior to vacuum."),
2237 &autovacuum_vac_thresh,
2242 {"autovacuum_analyze_threshold", PGC_SIGHUP, AUTOVACUUM,
2243 gettext_noop("Minimum number of tuple inserts, updates, or deletes prior to analyze."),
2246 &autovacuum_anl_thresh,
2251 /* see varsup.c for why this is PGC_POSTMASTER not PGC_SIGHUP */
2252 {"autovacuum_freeze_max_age", PGC_POSTMASTER, AUTOVACUUM,
2253 gettext_noop("Age at which to autovacuum a table to prevent transaction ID wraparound."),
2256 &autovacuum_freeze_max_age,
2257 /* see pg_resetxlog if you change the upper-limit value */
2258 200000000, 100000000, 2000000000,
2262 /* see max_connections */
2263 {"autovacuum_max_workers", PGC_POSTMASTER, AUTOVACUUM,
2264 gettext_noop("Sets the maximum number of simultaneously running autovacuum worker processes."),
2267 &autovacuum_max_workers,
2269 check_autovacuum_max_workers, assign_autovacuum_max_workers, NULL
2273 {"tcp_keepalives_idle", PGC_USERSET, CLIENT_CONN_OTHER,
2274 gettext_noop("Time between issuing TCP keepalives."),
2275 gettext_noop("A value of 0 uses the system default."),
2278 &tcp_keepalives_idle,
2280 NULL, assign_tcp_keepalives_idle, show_tcp_keepalives_idle
2284 {"tcp_keepalives_interval", PGC_USERSET, CLIENT_CONN_OTHER,
2285 gettext_noop("Time between TCP keepalive retransmits."),
2286 gettext_noop("A value of 0 uses the system default."),
2289 &tcp_keepalives_interval,
2291 NULL, assign_tcp_keepalives_interval, show_tcp_keepalives_interval
2295 {"ssl_renegotiation_limit", PGC_USERSET, CONN_AUTH_SECURITY,
2296 gettext_noop("Set the amount of traffic to send and receive before renegotiating the encryption keys."),
2300 &ssl_renegotiation_limit,
2301 512 * 1024, 0, MAX_KILOBYTES,
2306 {"tcp_keepalives_count", PGC_USERSET, CLIENT_CONN_OTHER,
2307 gettext_noop("Maximum number of TCP keepalive retransmits."),
2308 gettext_noop("This controls the number of consecutive keepalive retransmits that can be "
2309 "lost before a connection is considered dead. A value of 0 uses the "
2312 &tcp_keepalives_count,
2314 NULL, assign_tcp_keepalives_count, show_tcp_keepalives_count
2318 {"gin_fuzzy_search_limit", PGC_USERSET, CLIENT_CONN_OTHER,
2319 gettext_noop("Sets the maximum allowed result for exact search by GIN."),
2323 &GinFuzzySearchLimit,
2329 {"effective_cache_size", PGC_USERSET, QUERY_TUNING_COST,
2330 gettext_noop("Sets the planner's assumption about the size of the disk cache."),
2331 gettext_noop("That is, the portion of the kernel's disk cache that "
2332 "will be used for PostgreSQL data files. This is measured in disk "
2333 "pages, which are normally 8 kB each."),
2336 &effective_cache_size,
2337 DEFAULT_EFFECTIVE_CACHE_SIZE, 1, INT_MAX,
2342 /* Can't be set in postgresql.conf */
2343 {"server_version_num", PGC_INTERNAL, PRESET_OPTIONS,
2344 gettext_noop("Shows the server version as an integer."),
2346 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2348 &server_version_num,
2349 PG_VERSION_NUM, PG_VERSION_NUM, PG_VERSION_NUM,
2354 {"log_temp_files", PGC_SUSET, LOGGING_WHAT,
2355 gettext_noop("Log the use of temporary files larger than this number of kilobytes."),
2356 gettext_noop("Zero logs all files. The default is -1 (turning this feature off)."),
2365 {"track_activity_query_size", PGC_POSTMASTER, RESOURCES_MEM,
2366 gettext_noop("Sets the size reserved for pg_stat_activity.query, in bytes."),
2369 &pgstat_track_activity_query_size,
2374 /* End-of-list marker */
2376 {NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL, NULL
2381 static struct config_real ConfigureNamesReal[] =
2384 {"seq_page_cost", PGC_USERSET, QUERY_TUNING_COST,
2385 gettext_noop("Sets the planner's estimate of the cost of a "
2386 "sequentially fetched disk page."),
2390 DEFAULT_SEQ_PAGE_COST, 0, DBL_MAX,
2394 {"random_page_cost", PGC_USERSET, QUERY_TUNING_COST,
2395 gettext_noop("Sets the planner's estimate of the cost of a "
2396 "nonsequentially fetched disk page."),
2400 DEFAULT_RANDOM_PAGE_COST, 0, DBL_MAX,
2404 {"cpu_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
2405 gettext_noop("Sets the planner's estimate of the cost of "
2406 "processing each tuple (row)."),
2410 DEFAULT_CPU_TUPLE_COST, 0, DBL_MAX,
2414 {"cpu_index_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
2415 gettext_noop("Sets the planner's estimate of the cost of "
2416 "processing each index entry during an index scan."),
2419 &cpu_index_tuple_cost,
2420 DEFAULT_CPU_INDEX_TUPLE_COST, 0, DBL_MAX,
2424 {"cpu_operator_cost", PGC_USERSET, QUERY_TUNING_COST,
2425 gettext_noop("Sets the planner's estimate of the cost of "
2426 "processing each operator or function call."),
2430 DEFAULT_CPU_OPERATOR_COST, 0, DBL_MAX,
2435 {"cursor_tuple_fraction", PGC_USERSET, QUERY_TUNING_OTHER,
2436 gettext_noop("Sets the planner's estimate of the fraction of "
2437 "a cursor's rows that will be retrieved."),
2440 &cursor_tuple_fraction,
2441 DEFAULT_CURSOR_TUPLE_FRACTION, 0.0, 1.0,
2446 {"geqo_selection_bias", PGC_USERSET, QUERY_TUNING_GEQO,
2447 gettext_noop("GEQO: selective pressure within the population."),
2450 &Geqo_selection_bias,
2451 DEFAULT_GEQO_SELECTION_BIAS,
2452 MIN_GEQO_SELECTION_BIAS, MAX_GEQO_SELECTION_BIAS,
2456 {"geqo_seed", PGC_USERSET, QUERY_TUNING_GEQO,
2457 gettext_noop("GEQO: seed for random path selection."),
2466 {"bgwriter_lru_multiplier", PGC_SIGHUP, RESOURCES_BGWRITER,
2467 gettext_noop("Multiple of the average buffer usage to free per round."),
2470 &bgwriter_lru_multiplier,
2476 {"seed", PGC_USERSET, UNGROUPED,
2477 gettext_noop("Sets the seed for random-number generation."),
2479 GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2483 check_random_seed, assign_random_seed, show_random_seed
2487 {"autovacuum_vacuum_scale_factor", PGC_SIGHUP, AUTOVACUUM,
2488 gettext_noop("Number of tuple updates or deletes prior to vacuum as a fraction of reltuples."),
2491 &autovacuum_vac_scale,
2496 {"autovacuum_analyze_scale_factor", PGC_SIGHUP, AUTOVACUUM,
2497 gettext_noop("Number of tuple inserts, updates, or deletes prior to analyze as a fraction of reltuples."),
2500 &autovacuum_anl_scale,
2506 {"checkpoint_completion_target", PGC_SIGHUP, WAL_CHECKPOINTS,
2507 gettext_noop("Time spent flushing dirty buffers during checkpoint, as fraction of checkpoint interval."),
2510 &CheckPointCompletionTarget,
2515 /* End-of-list marker */
2517 {NULL, 0, 0, NULL, NULL}, NULL, 0.0, 0.0, 0.0, NULL, NULL, NULL
2522 static struct config_string ConfigureNamesString[] =
2525 {"archive_command", PGC_SIGHUP, WAL_ARCHIVING,
2526 gettext_noop("Sets the shell command that will be called to archive a WAL file."),
2529 &XLogArchiveCommand,
2531 NULL, NULL, show_archive_command
2535 {"client_encoding", PGC_USERSET, CLIENT_CONN_LOCALE,
2536 gettext_noop("Sets the client's character set encoding."),
2538 GUC_IS_NAME | GUC_REPORT
2540 &client_encoding_string,
2542 check_client_encoding, assign_client_encoding, NULL
2546 {"log_line_prefix", PGC_SIGHUP, LOGGING_WHAT,
2547 gettext_noop("Controls information prefixed to each log line."),
2548 gettext_noop("If blank, no prefix is used.")
2556 {"log_timezone", PGC_SIGHUP, LOGGING_WHAT,
2557 gettext_noop("Sets the time zone to use in log messages."),
2560 &log_timezone_string,
2562 check_log_timezone, assign_log_timezone, show_log_timezone
2566 {"DateStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
2567 gettext_noop("Sets the display format for date and time values."),
2568 gettext_noop("Also controls interpretation of ambiguous "
2570 GUC_LIST_INPUT | GUC_REPORT
2574 check_datestyle, assign_datestyle, NULL
2578 {"default_tablespace", PGC_USERSET, CLIENT_CONN_STATEMENT,
2579 gettext_noop("Sets the default tablespace to create tables and indexes in."),
2580 gettext_noop("An empty string selects the database's default tablespace."),
2583 &default_tablespace,
2585 check_default_tablespace, NULL, NULL
2589 {"temp_tablespaces", PGC_USERSET, CLIENT_CONN_STATEMENT,
2590 gettext_noop("Sets the tablespace(s) to use for temporary tables and sort files."),
2592 GUC_LIST_INPUT | GUC_LIST_QUOTE
2596 check_temp_tablespaces, assign_temp_tablespaces, NULL
2600 {"dynamic_library_path", PGC_SUSET, CLIENT_CONN_OTHER,
2601 gettext_noop("Sets the path for dynamically loadable modules."),
2602 gettext_noop("If a dynamically loadable module needs to be opened and "
2603 "the specified name does not have a directory component (i.e., the "
2604 "name does not contain a slash), the system will search this path for "
2605 "the specified file."),
2608 &Dynamic_library_path,
2614 {"krb_server_keyfile", PGC_SIGHUP, CONN_AUTH_SECURITY,
2615 gettext_noop("Sets the location of the Kerberos server key file."),
2619 &pg_krb_server_keyfile,
2625 {"krb_srvname", PGC_SIGHUP, CONN_AUTH_SECURITY,
2626 gettext_noop("Sets the name of the Kerberos service."),
2635 {"bonjour_name", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2636 gettext_noop("Sets the Bonjour service name."),
2644 /* See main.c about why defaults for LC_foo are not all alike */
2647 {"lc_collate", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2648 gettext_noop("Shows the collation order locale."),
2650 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2658 {"lc_ctype", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2659 gettext_noop("Shows the character classification and case conversion locale."),
2661 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2669 {"lc_messages", PGC_SUSET, CLIENT_CONN_LOCALE,
2670 gettext_noop("Sets the language in which messages are displayed."),
2675 check_locale_messages, assign_locale_messages, NULL
2679 {"lc_monetary", PGC_USERSET, CLIENT_CONN_LOCALE,
2680 gettext_noop("Sets the locale for formatting monetary amounts."),
2685 check_locale_monetary, assign_locale_monetary, NULL
2689 {"lc_numeric", PGC_USERSET, CLIENT_CONN_LOCALE,
2690 gettext_noop("Sets the locale for formatting numbers."),
2695 check_locale_numeric, assign_locale_numeric, NULL
2699 {"lc_time", PGC_USERSET, CLIENT_CONN_LOCALE,
2700 gettext_noop("Sets the locale for formatting date and time values."),
2705 check_locale_time, assign_locale_time, NULL
2709 {"shared_preload_libraries", PGC_POSTMASTER, RESOURCES_KERNEL,
2710 gettext_noop("Lists shared libraries to preload into server."),
2712 GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
2714 &shared_preload_libraries_string,
2720 {"local_preload_libraries", PGC_BACKEND, CLIENT_CONN_OTHER,
2721 gettext_noop("Lists shared libraries to preload into each backend."),
2723 GUC_LIST_INPUT | GUC_LIST_QUOTE
2725 &local_preload_libraries_string,
2731 {"search_path", PGC_USERSET, CLIENT_CONN_STATEMENT,
2732 gettext_noop("Sets the schema search order for names that are not schema-qualified."),
2734 GUC_LIST_INPUT | GUC_LIST_QUOTE
2736 &namespace_search_path,
2738 check_search_path, assign_search_path, NULL
2742 /* Can't be set in postgresql.conf */
2743 {"server_encoding", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2744 gettext_noop("Sets the server (database) character set encoding."),
2746 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2748 &server_encoding_string,
2754 /* Can't be set in postgresql.conf */
2755 {"server_version", PGC_INTERNAL, PRESET_OPTIONS,
2756 gettext_noop("Shows the server version."),
2758 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2760 &server_version_string,
2766 /* Not for general use --- used by SET ROLE */
2767 {"role", PGC_USERSET, UNGROUPED,
2768 gettext_noop("Sets the current role."),
2770 GUC_IS_NAME | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_NOT_WHILE_SEC_REST
2774 check_role, assign_role, show_role
2778 /* Not for general use --- used by SET SESSION AUTHORIZATION */
2779 {"session_authorization", PGC_USERSET, UNGROUPED,
2780 gettext_noop("Sets the session user name."),
2782 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
2784 &session_authorization_string,
2786 check_session_authorization, assign_session_authorization, NULL
2790 {"log_destination", PGC_SIGHUP, LOGGING_WHERE,
2791 gettext_noop("Sets the destination for server log output."),
2792 gettext_noop("Valid values are combinations of \"stderr\", "
2793 "\"syslog\", \"csvlog\", and \"eventlog\", "
2794 "depending on the platform."),
2797 &log_destination_string,
2799 check_log_destination, assign_log_destination, NULL
2802 {"log_directory", PGC_SIGHUP, LOGGING_WHERE,
2803 gettext_noop("Sets the destination directory for log files."),
2804 gettext_noop("Can be specified as relative to the data directory "
2805 "or as absolute path."),
2810 check_canonical_path, NULL, NULL
2813 {"log_filename", PGC_SIGHUP, LOGGING_WHERE,
2814 gettext_noop("Sets the file name pattern for log files."),
2819 "postgresql-%Y-%m-%d_%H%M%S.log",
2824 {"syslog_ident", PGC_SIGHUP, LOGGING_WHERE,
2825 gettext_noop("Sets the program name used to identify PostgreSQL "
2826 "messages in syslog."),
2831 NULL, assign_syslog_ident, NULL
2835 {"event_source", PGC_POSTMASTER, LOGGING_WHERE,
2836 gettext_noop("Sets the application name used to identify"
2837 "PostgreSQL messages in the event log."),
2846 {"TimeZone", PGC_USERSET, CLIENT_CONN_LOCALE,
2847 gettext_noop("Sets the time zone for displaying and interpreting time stamps."),
2853 check_timezone, assign_timezone, show_timezone
2856 {"timezone_abbreviations", PGC_USERSET, CLIENT_CONN_LOCALE,
2857 gettext_noop("Selects a file of time zone abbreviations."),
2860 &timezone_abbreviations_string,
2862 check_timezone_abbreviations, assign_timezone_abbreviations, NULL
2866 {"transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
2867 gettext_noop("Sets the current transaction's isolation level."),
2869 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2871 &XactIsoLevel_string,
2873 check_XactIsoLevel, assign_XactIsoLevel, show_XactIsoLevel
2877 {"unix_socket_group", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2878 gettext_noop("Sets the owning group of the Unix-domain socket."),
2879 gettext_noop("The owning user of the socket is always the user "
2880 "that starts the server.")
2888 {"unix_socket_directory", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2889 gettext_noop("Sets the directory where the Unix-domain socket will be created."),
2895 check_canonical_path, NULL, NULL
2899 {"listen_addresses", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2900 gettext_noop("Sets the host name or IP address(es) to listen to."),
2910 {"data_directory", PGC_POSTMASTER, FILE_LOCATIONS,
2911 gettext_noop("Sets the server's data directory."),
2921 {"config_file", PGC_POSTMASTER, FILE_LOCATIONS,
2922 gettext_noop("Sets the server's main configuration file."),
2924 GUC_DISALLOW_IN_FILE | GUC_SUPERUSER_ONLY
2932 {"hba_file", PGC_POSTMASTER, FILE_LOCATIONS,
2933 gettext_noop("Sets the server's \"hba\" configuration file."),
2943 {"ident_file", PGC_POSTMASTER, FILE_LOCATIONS,
2944 gettext_noop("Sets the server's \"ident\" configuration file."),
2954 {"external_pid_file", PGC_POSTMASTER, FILE_LOCATIONS,
2955 gettext_noop("Writes the postmaster PID to the specified file."),
2961 check_canonical_path, NULL, NULL
2965 {"ssl_cert_file", PGC_POSTMASTER, CONN_AUTH_SECURITY,
2966 gettext_noop("Location of the SSL server certificate file."),
2975 {"ssl_key_file", PGC_POSTMASTER, CONN_AUTH_SECURITY,
2976 gettext_noop("Location of the SSL server private key file."),
2985 {"ssl_ca_file", PGC_POSTMASTER, CONN_AUTH_SECURITY,
2986 gettext_noop("Location of the SSL certificate authority file."),
2995 {"ssl_crl_file", PGC_POSTMASTER, CONN_AUTH_SECURITY,
2996 gettext_noop("Location of the SSL certificate revocation list file."),
3005 {"stats_temp_directory", PGC_SIGHUP, STATS_COLLECTOR,
3006 gettext_noop("Writes temporary statistics files to the specified directory."),
3010 &pgstat_temp_directory,
3012 check_canonical_path, assign_pgstat_temp_directory, NULL
3016 {"synchronous_standby_names", PGC_SIGHUP, REPLICATION_MASTER,
3017 gettext_noop("List of names of potential synchronous standbys."),
3021 &SyncRepStandbyNames,
3023 check_synchronous_standby_names, NULL, NULL
3027 {"default_text_search_config", PGC_USERSET, CLIENT_CONN_LOCALE,
3028 gettext_noop("Sets default text search configuration."),
3032 "pg_catalog.simple",
3033 check_TSCurrentConfig, assign_TSCurrentConfig, NULL
3037 {"ssl_ciphers", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3038 gettext_noop("Sets the list of allowed SSL ciphers."),
3044 "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH",
3052 {"application_name", PGC_USERSET, LOGGING_WHAT,
3053 gettext_noop("Sets the application name to be reported in statistics and logs."),
3055 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE
3059 check_application_name, assign_application_name, NULL
3062 /* End-of-list marker */
3064 {NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL, NULL
3069 static struct config_enum ConfigureNamesEnum[] =
3072 {"backslash_quote", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
3073 gettext_noop("Sets whether \"\\'\" is allowed in string literals."),
3077 BACKSLASH_QUOTE_SAFE_ENCODING, backslash_quote_options,
3082 {"bytea_output", PGC_USERSET, CLIENT_CONN_STATEMENT,
3083 gettext_noop("Sets the output format for bytea."),
3087 BYTEA_OUTPUT_HEX, bytea_output_options,
3092 {"client_min_messages", PGC_USERSET, LOGGING_WHEN,
3093 gettext_noop("Sets the message levels that are sent to the client."),
3094 gettext_noop("Each level includes all the levels that follow it. The later"
3095 " the level, the fewer messages are sent.")
3097 &client_min_messages,
3098 NOTICE, client_message_level_options,
3103 {"constraint_exclusion", PGC_USERSET, QUERY_TUNING_OTHER,
3104 gettext_noop("Enables the planner to use constraints to optimize queries."),
3105 gettext_noop("Table scans will be skipped if their constraints"
3106 " guarantee that no rows match the query.")
3108 &constraint_exclusion,
3109 CONSTRAINT_EXCLUSION_PARTITION, constraint_exclusion_options,
3114 {"default_transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
3115 gettext_noop("Sets the transaction isolation level of each new transaction."),
3118 &DefaultXactIsoLevel,
3119 XACT_READ_COMMITTED, isolation_level_options,
3124 {"IntervalStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
3125 gettext_noop("Sets the display format for interval values."),
3130 INTSTYLE_POSTGRES, intervalstyle_options,
3135 {"log_error_verbosity", PGC_SUSET, LOGGING_WHAT,
3136 gettext_noop("Sets the verbosity of logged messages."),
3139 &Log_error_verbosity,
3140 PGERROR_DEFAULT, log_error_verbosity_options,
3145 {"log_min_messages", PGC_SUSET, LOGGING_WHEN,
3146 gettext_noop("Sets the message levels that are logged."),
3147 gettext_noop("Each level includes all the levels that follow it. The later"
3148 " the level, the fewer messages are sent.")
3151 WARNING, server_message_level_options,
3156 {"log_min_error_statement", PGC_SUSET, LOGGING_WHEN,
3157 gettext_noop("Causes all statements generating error at or above this level to be logged."),
3158 gettext_noop("Each level includes all the levels that follow it. The later"
3159 " the level, the fewer messages are sent.")
3161 &log_min_error_statement,
3162 ERROR, server_message_level_options,
3167 {"log_statement", PGC_SUSET, LOGGING_WHAT,
3168 gettext_noop("Sets the type of statements logged."),
3172 LOGSTMT_NONE, log_statement_options,
3177 {"syslog_facility", PGC_SIGHUP, LOGGING_WHERE,
3178 gettext_noop("Sets the syslog \"facility\" to be used when syslog enabled."),
3187 syslog_facility_options,
3188 NULL, assign_syslog_facility, NULL
3192 {"session_replication_role", PGC_SUSET, CLIENT_CONN_STATEMENT,
3193 gettext_noop("Sets the session's behavior for triggers and rewrite rules."),
3196 &SessionReplicationRole,
3197 SESSION_REPLICATION_ROLE_ORIGIN, session_replication_role_options,
3198 NULL, assign_session_replication_role, NULL
3202 {"synchronous_commit", PGC_USERSET, WAL_SETTINGS,
3203 gettext_noop("Sets the current transaction's synchronization level."),
3206 &synchronous_commit,
3207 SYNCHRONOUS_COMMIT_ON, synchronous_commit_options,
3208 NULL, assign_synchronous_commit, NULL
3212 {"trace_recovery_messages", PGC_SIGHUP, DEVELOPER_OPTIONS,
3213 gettext_noop("Enables logging of recovery-related debugging information."),
3214 gettext_noop("Each level includes all the levels that follow it. The later"
3215 " the level, the fewer messages are sent.")
3217 &trace_recovery_messages,
3220 * client_message_level_options allows too many values, really, but
3221 * it's not worth having a separate options array for this.
3223 LOG, client_message_level_options,
3228 {"track_functions", PGC_SUSET, STATS_COLLECTOR,
3229 gettext_noop("Collects function-level statistics on database activity."),
3232 &pgstat_track_functions,
3233 TRACK_FUNC_OFF, track_function_options,
3238 {"wal_level", PGC_POSTMASTER, WAL_SETTINGS,
3239 gettext_noop("Set the level of information written to the WAL."),
3243 WAL_LEVEL_MINIMAL, wal_level_options,
3248 {"wal_sync_method", PGC_SIGHUP, WAL_SETTINGS,
3249 gettext_noop("Selects the method used for forcing WAL updates to disk."),
3253 DEFAULT_SYNC_METHOD, sync_method_options,
3254 NULL, assign_xlog_sync_method, NULL
3258 {"xmlbinary", PGC_USERSET, CLIENT_CONN_STATEMENT,
3259 gettext_noop("Sets how binary values are to be encoded in XML."),
3263 XMLBINARY_BASE64, xmlbinary_options,
3268 {"xmloption", PGC_USERSET, CLIENT_CONN_STATEMENT,
3269 gettext_noop("Sets whether XML data in implicit parsing and serialization "
3270 "operations is to be considered as documents or content fragments."),
3274 XMLOPTION_CONTENT, xmloption_options,
3279 /* End-of-list marker */
3281 {NULL, 0, 0, NULL, NULL}, NULL, 0, NULL, NULL, NULL, NULL
3285 /******** end of options list ********/
3289 * To allow continued support of obsolete names for GUC variables, we apply
3290 * the following mappings to any unrecognized name. Note that an old name
3291 * should be mapped to a new one only if the new variable has very similar
3292 * semantics to the old.
3294 static const char *const map_old_guc_names[] = {
3295 "sort_mem", "work_mem",
3296 "vacuum_mem", "maintenance_work_mem",
3302 * Actual lookup of variables is done through this single, sorted array.
3304 static struct config_generic **guc_variables;
3306 /* Current number of variables contained in the vector */
3307 static int num_guc_variables;
3309 /* Vector capacity */
3310 static int size_guc_variables;
3313 static bool guc_dirty; /* TRUE if need to do commit/abort work */
3315 static bool reporting_enabled; /* TRUE to enable GUC_REPORT */
3317 static int GUCNestLevel = 0; /* 1 when in main transaction */
3320 static int guc_var_compare(const void *a, const void *b);
3321 static int guc_name_compare(const char *namea, const char *nameb);
3322 static void InitializeGUCOptionsFromEnvironment(void);
3323 static void InitializeOneGUCOption(struct config_generic * gconf);
3324 static void push_old_value(struct config_generic * gconf, GucAction action);
3325 static void ReportGUCOption(struct config_generic * record);
3326 static void reapply_stacked_values(struct config_generic * variable,
3327 struct config_string *pHolder,
3329 const char *curvalue,
3330 GucContext curscontext, GucSource cursource);
3331 static void ShowGUCConfigOption(const char *name, DestReceiver *dest);
3332 static void ShowAllGUCConfig(DestReceiver *dest);
3333 static char *_ShowOption(struct config_generic * record, bool use_units);
3334 static bool validate_option_array_item(const char *name, const char *value,
3335 bool skipIfNoPermissions);
3339 * Some infrastructure for checking malloc/strdup/realloc calls
3342 guc_malloc(int elevel, size_t size)
3346 data = malloc(size);
3349 (errcode(ERRCODE_OUT_OF_MEMORY),
3350 errmsg("out of memory")));
3355 guc_realloc(int elevel, void *old, size_t size)
3359 data = realloc(old, size);
3362 (errcode(ERRCODE_OUT_OF_MEMORY),
3363 errmsg("out of memory")));
3368 guc_strdup(int elevel, const char *src)
3375 (errcode(ERRCODE_OUT_OF_MEMORY),
3376 errmsg("out of memory")));
3382 * Detect whether strval is referenced anywhere in a GUC string item
3385 string_field_used(struct config_string * conf, char *strval)
3389 if (strval == *(conf->variable) ||
3390 strval == conf->reset_val ||
3391 strval == conf->boot_val)
3393 for (stack = conf->gen.stack; stack; stack = stack->prev)
3395 if (strval == stack->prior.val.stringval ||
3396 strval == stack->masked.val.stringval)
3403 * Support for assigning to a field of a string GUC item. Free the prior
3404 * value if it's not referenced anywhere else in the item (including stacked
3408 set_string_field(struct config_string * conf, char **field, char *newval)
3410 char *oldval = *field;
3412 /* Do the assignment */
3415 /* Free old value if it's not NULL and isn't referenced anymore */
3416 if (oldval && !string_field_used(conf, oldval))
3421 * Detect whether an "extra" struct is referenced anywhere in a GUC item
3424 extra_field_used(struct config_generic * gconf, void *extra)
3428 if (extra == gconf->extra)
3430 switch (gconf->vartype)
3433 if (extra == ((struct config_bool *) gconf)->reset_extra)
3437 if (extra == ((struct config_int *) gconf)->reset_extra)
3441 if (extra == ((struct config_real *) gconf)->reset_extra)
3445 if (extra == ((struct config_string *) gconf)->reset_extra)
3449 if (extra == ((struct config_enum *) gconf)->reset_extra)
3453 for (stack = gconf->stack; stack; stack = stack->prev)
3455 if (extra == stack->prior.extra ||
3456 extra == stack->masked.extra)
3464 * Support for assigning to an "extra" field of a GUC item. Free the prior
3465 * value if it's not referenced anywhere else in the item (including stacked
3469 set_extra_field(struct config_generic * gconf, void **field, void *newval)
3471 void *oldval = *field;
3473 /* Do the assignment */
3476 /* Free old value if it's not NULL and isn't referenced anymore */
3477 if (oldval && !extra_field_used(gconf, oldval))
3482 * Support for copying a variable's active value into a stack entry.
3483 * The "extra" field associated with the active value is copied, too.
3485 * NB: be sure stringval and extra fields of a new stack entry are
3486 * initialized to NULL before this is used, else we'll try to free() them.
3489 set_stack_value(struct config_generic * gconf, config_var_value *val)
3491 switch (gconf->vartype)
3495 *((struct config_bool *) gconf)->variable;
3499 *((struct config_int *) gconf)->variable;
3503 *((struct config_real *) gconf)->variable;
3506 set_string_field((struct config_string *) gconf,
3507 &(val->val.stringval),
3508 *((struct config_string *) gconf)->variable);
3512 *((struct config_enum *) gconf)->variable;
3515 set_extra_field(gconf, &(val->extra), gconf->extra);
3519 * Support for discarding a no-longer-needed value in a stack entry.
3520 * The "extra" field associated with the stack entry is cleared, too.
3523 discard_stack_value(struct config_generic * gconf, config_var_value *val)
3525 switch (gconf->vartype)
3531 /* no need to do anything */
3534 set_string_field((struct config_string *) gconf,
3535 &(val->val.stringval),
3539 set_extra_field(gconf, &(val->extra), NULL);
3544 * Fetch the sorted array pointer (exported for help_config.c's use ONLY)
3546 struct config_generic **
3547 get_guc_variables(void)
3549 return guc_variables;
3554 * Build the sorted array. This is split out so that it could be
3555 * re-executed after startup (eg, we could allow loadable modules to
3556 * add vars, and then we'd need to re-sort).
3559 build_guc_variables(void)
3563 struct config_generic **guc_vars;
3566 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
3568 struct config_bool *conf = &ConfigureNamesBool[i];
3570 /* Rather than requiring vartype to be filled in by hand, do this: */
3571 conf->gen.vartype = PGC_BOOL;
3575 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
3577 struct config_int *conf = &ConfigureNamesInt[i];
3579 conf->gen.vartype = PGC_INT;
3583 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
3585 struct config_real *conf = &ConfigureNamesReal[i];
3587 conf->gen.vartype = PGC_REAL;
3591 for (i = 0; ConfigureNamesString[i].gen.name; i++)
3593 struct config_string *conf = &ConfigureNamesString[i];
3595 conf->gen.vartype = PGC_STRING;
3599 for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
3601 struct config_enum *conf = &ConfigureNamesEnum[i];
3603 conf->gen.vartype = PGC_ENUM;
3608 * Create table with 20% slack
3610 size_vars = num_vars + num_vars / 4;
3612 guc_vars = (struct config_generic **)
3613 guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
3617 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
3618 guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
3620 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
3621 guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
3623 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
3624 guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
3626 for (i = 0; ConfigureNamesString[i].gen.name; i++)
3627 guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
3629 for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
3630 guc_vars[num_vars++] = &ConfigureNamesEnum[i].gen;
3633 free(guc_variables);
3634 guc_variables = guc_vars;
3635 num_guc_variables = num_vars;
3636 size_guc_variables = size_vars;
3637 qsort((void *) guc_variables, num_guc_variables,
3638 sizeof(struct config_generic *), guc_var_compare);
3642 * Add a new GUC variable to the list of known variables. The
3643 * list is expanded if needed.
3646 add_guc_variable(struct config_generic * var, int elevel)
3648 if (num_guc_variables + 1 >= size_guc_variables)
3651 * Increase the vector by 25%
3653 int size_vars = size_guc_variables + size_guc_variables / 4;
3654 struct config_generic **guc_vars;
3659 guc_vars = (struct config_generic **)
3660 guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
3664 guc_vars = (struct config_generic **)
3665 guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
3668 if (guc_vars == NULL)
3669 return false; /* out of memory */
3671 guc_variables = guc_vars;
3672 size_guc_variables = size_vars;
3674 guc_variables[num_guc_variables++] = var;
3675 qsort((void *) guc_variables, num_guc_variables,
3676 sizeof(struct config_generic *), guc_var_compare);
3681 * Create and add a placeholder variable for a custom variable name.
3683 static struct config_generic *
3684 add_placeholder_variable(const char *name, int elevel)
3686 size_t sz = sizeof(struct config_string) + sizeof(char *);
3687 struct config_string *var;
3688 struct config_generic *gen;
3690 var = (struct config_string *) guc_malloc(elevel, sz);
3696 gen->name = guc_strdup(elevel, name);
3697 if (gen->name == NULL)
3703 gen->context = PGC_USERSET;
3704 gen->group = CUSTOM_OPTIONS;
3705 gen->short_desc = "GUC placeholder variable";
3706 gen->flags = GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_CUSTOM_PLACEHOLDER;
3707 gen->vartype = PGC_STRING;
3710 * The char* is allocated at the end of the struct since we have no
3711 * 'static' place to point to. Note that the current value, as well as
3712 * the boot and reset values, start out NULL.
3714 var->variable = (char **) (var + 1);
3716 if (!add_guc_variable((struct config_generic *) var, elevel))
3718 free((void *) gen->name);
3727 * Look up option NAME. If it exists, return a pointer to its record,
3728 * else return NULL. If create_placeholders is TRUE, we'll create a
3729 * placeholder record for a valid-looking custom variable name.
3731 static struct config_generic *
3732 find_option(const char *name, bool create_placeholders, int elevel)
3734 const char **key = &name;
3735 struct config_generic **res;
3741 * By equating const char ** with struct config_generic *, we are assuming
3742 * the name field is first in config_generic.
3744 res = (struct config_generic **) bsearch((void *) &key,
3745 (void *) guc_variables,
3747 sizeof(struct config_generic *),
3753 * See if the name is an obsolete name for a variable. We assume that the
3754 * set of supported old names is short enough that a brute-force search is
3757 for (i = 0; map_old_guc_names[i] != NULL; i += 2)
3759 if (guc_name_compare(name, map_old_guc_names[i]) == 0)
3760 return find_option(map_old_guc_names[i + 1], false, elevel);
3763 if (create_placeholders)
3766 * Check if the name is qualified, and if so, add a placeholder.
3768 if (strchr(name, GUC_QUALIFIER_SEPARATOR) != NULL)
3769 return add_placeholder_variable(name, elevel);
3778 * comparator for qsorting and bsearching guc_variables array
3781 guc_var_compare(const void *a, const void *b)
3783 const struct config_generic *confa = *(struct config_generic * const *) a;
3784 const struct config_generic *confb = *(struct config_generic * const *) b;
3786 return guc_name_compare(confa->name, confb->name);
3790 * the bare comparison function for GUC names
3793 guc_name_compare(const char *namea, const char *nameb)
3796 * The temptation to use strcasecmp() here must be resisted, because the
3797 * array ordering has to remain stable across setlocale() calls. So, build
3798 * our own with a simple ASCII-only downcasing.
3800 while (*namea && *nameb)
3802 char cha = *namea++;
3803 char chb = *nameb++;
3805 if (cha >= 'A' && cha <= 'Z')
3807 if (chb >= 'A' && chb <= 'Z')
3813 return 1; /* a is longer */
3815 return -1; /* b is longer */
3821 * Initialize GUC options during program startup.
3823 * Note that we cannot read the config file yet, since we have not yet
3824 * processed command-line switches.
3827 InitializeGUCOptions(void)
3832 * Before log_line_prefix could possibly receive a nonempty setting, make
3833 * sure that timezone processing is minimally alive (see elog.c).
3835 pg_timezone_initialize();
3838 * Build sorted array of all GUC variables.
3840 build_guc_variables();
3843 * Load all variables with their compiled-in defaults, and initialize
3844 * status fields as needed.
3846 for (i = 0; i < num_guc_variables; i++)
3848 InitializeOneGUCOption(guc_variables[i]);
3853 reporting_enabled = false;
3856 * Prevent any attempt to override the transaction modes from
3857 * non-interactive sources.
3859 SetConfigOption("transaction_isolation", "default",
3860 PGC_POSTMASTER, PGC_S_OVERRIDE);
3861 SetConfigOption("transaction_read_only", "no",
3862 PGC_POSTMASTER, PGC_S_OVERRIDE);
3863 SetConfigOption("transaction_deferrable", "no",
3864 PGC_POSTMASTER, PGC_S_OVERRIDE);
3867 * For historical reasons, some GUC parameters can receive defaults from
3868 * environment variables. Process those settings.
3870 InitializeGUCOptionsFromEnvironment();
3874 * Assign any GUC values that can come from the server's environment.
3876 * This is called from InitializeGUCOptions, and also from ProcessConfigFile
3877 * to deal with the possibility that a setting has been removed from
3878 * postgresql.conf and should now get a value from the environment.
3879 * (The latter is a kludge that should probably go away someday; if so,
3880 * fold this back into InitializeGUCOptions.)
3883 InitializeGUCOptionsFromEnvironment(void)
3888 env = getenv("PGPORT");
3890 SetConfigOption("port", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3892 env = getenv("PGDATESTYLE");
3894 SetConfigOption("datestyle", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3896 env = getenv("PGCLIENTENCODING");
3898 SetConfigOption("client_encoding", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3901 * rlimit isn't exactly an "environment variable", but it behaves about
3902 * the same. If we can identify the platform stack depth rlimit, increase
3903 * default stack depth setting up to whatever is safe (but at most 2MB).
3905 stack_rlimit = get_stack_depth_rlimit();
3906 if (stack_rlimit > 0)
3908 long new_limit = (stack_rlimit - STACK_DEPTH_SLOP) / 1024L;
3910 if (new_limit > 100)
3914 new_limit = Min(new_limit, 2048);
3915 sprintf(limbuf, "%ld", new_limit);
3916 SetConfigOption("max_stack_depth", limbuf,
3917 PGC_POSTMASTER, PGC_S_ENV_VAR);
3923 * Initialize one GUC option variable to its compiled-in default.
3925 * Note: the reason for calling check_hooks is not that we think the boot_val
3926 * might fail, but that the hooks might wish to compute an "extra" struct.
3929 InitializeOneGUCOption(struct config_generic * gconf)
3932 gconf->source = PGC_S_DEFAULT;
3933 gconf->reset_source = PGC_S_DEFAULT;
3934 gconf->scontext = PGC_INTERNAL;
3935 gconf->reset_scontext = PGC_INTERNAL;
3936 gconf->stack = NULL;
3937 gconf->extra = NULL;
3938 gconf->sourcefile = NULL;
3939 gconf->sourceline = 0;
3941 switch (gconf->vartype)
3945 struct config_bool *conf = (struct config_bool *) gconf;
3946 bool newval = conf->boot_val;
3949 if (!call_bool_check_hook(conf, &newval, &extra,
3950 PGC_S_DEFAULT, LOG))
3951 elog(FATAL, "failed to initialize %s to %d",
3952 conf->gen.name, (int) newval);
3953 if (conf->assign_hook)
3954 (*conf->assign_hook) (newval, extra);
3955 *conf->variable = conf->reset_val = newval;
3956 conf->gen.extra = conf->reset_extra = extra;
3961 struct config_int *conf = (struct config_int *) gconf;
3962 int newval = conf->boot_val;
3965 Assert(newval >= conf->min);
3966 Assert(newval <= conf->max);
3967 if (!call_int_check_hook(conf, &newval, &extra,
3968 PGC_S_DEFAULT, LOG))
3969 elog(FATAL, "failed to initialize %s to %d",
3970 conf->gen.name, newval);
3971 if (conf->assign_hook)
3972 (*conf->assign_hook) (newval, extra);
3973 *conf->variable = conf->reset_val = newval;
3974 conf->gen.extra = conf->reset_extra = extra;
3979 struct config_real *conf = (struct config_real *) gconf;
3980 double newval = conf->boot_val;
3983 Assert(newval >= conf->min);
3984 Assert(newval <= conf->max);
3985 if (!call_real_check_hook(conf, &newval, &extra,
3986 PGC_S_DEFAULT, LOG))
3987 elog(FATAL, "failed to initialize %s to %g",
3988 conf->gen.name, newval);
3989 if (conf->assign_hook)
3990 (*conf->assign_hook) (newval, extra);
3991 *conf->variable = conf->reset_val = newval;
3992 conf->gen.extra = conf->reset_extra = extra;
3997 struct config_string *conf = (struct config_string *) gconf;
4001 /* non-NULL boot_val must always get strdup'd */
4002 if (conf->boot_val != NULL)
4003 newval = guc_strdup(FATAL, conf->boot_val);
4007 if (!call_string_check_hook(conf, &newval, &extra,
4008 PGC_S_DEFAULT, LOG))
4009 elog(FATAL, "failed to initialize %s to \"%s\"",
4010 conf->gen.name, newval ? newval : "");
4011 if (conf->assign_hook)
4012 (*conf->assign_hook) (newval, extra);
4013 *conf->variable = conf->reset_val = newval;
4014 conf->gen.extra = conf->reset_extra = extra;
4019 struct config_enum *conf = (struct config_enum *) gconf;
4020 int newval = conf->boot_val;
4023 if (!call_enum_check_hook(conf, &newval, &extra,
4024 PGC_S_DEFAULT, LOG))
4025 elog(FATAL, "failed to initialize %s to %d",
4026 conf->gen.name, newval);
4027 if (conf->assign_hook)
4028 (*conf->assign_hook) (newval, extra);
4029 *conf->variable = conf->reset_val = newval;
4030 conf->gen.extra = conf->reset_extra = extra;
4038 * Select the configuration files and data directory to be used, and
4039 * do the initial read of postgresql.conf.
4041 * This is called after processing command-line switches.
4042 * userDoption is the -D switch value if any (NULL if unspecified).
4043 * progname is just for use in error messages.
4045 * Returns true on success; on failure, prints a suitable error message
4046 * to stderr and returns false.
4049 SelectConfigFiles(const char *userDoption, const char *progname)
4053 struct stat stat_buf;
4055 /* configdir is -D option, or $PGDATA if no -D */
4057 configdir = make_absolute_path(userDoption);
4059 configdir = make_absolute_path(getenv("PGDATA"));
4062 * Find the configuration file: if config_file was specified on the
4063 * command line, use it, else use configdir/postgresql.conf. In any case
4064 * ensure the result is an absolute path, so that it will be interpreted
4065 * the same way by future backends.
4068 fname = make_absolute_path(ConfigFileName);
4071 fname = guc_malloc(FATAL,
4072 strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
4073 sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
4077 write_stderr("%s does not know where to find the server configuration file.\n"
4078 "You must specify the --config-file or -D invocation "
4079 "option or set the PGDATA environment variable.\n",
4085 * Set the ConfigFileName GUC variable to its final value, ensuring that
4086 * it can't be overridden later.
4088 SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4092 * Now read the config file for the first time.
4094 if (stat(ConfigFileName, &stat_buf) != 0)
4096 write_stderr("%s cannot access the server configuration file \"%s\": %s\n",
4097 progname, ConfigFileName, strerror(errno));
4102 ProcessConfigFile(PGC_POSTMASTER);
4105 * If the data_directory GUC variable has been set, use that as DataDir;
4106 * otherwise use configdir if set; else punt.
4108 * Note: SetDataDir will copy and absolute-ize its argument, so we don't
4112 SetDataDir(data_directory);
4114 SetDataDir(configdir);
4117 write_stderr("%s does not know where to find the database system data.\n"
4118 "This can be specified as \"data_directory\" in \"%s\", "
4119 "or by the -D invocation option, or by the "
4120 "PGDATA environment variable.\n",
4121 progname, ConfigFileName);
4126 * Reflect the final DataDir value back into the data_directory GUC var.
4127 * (If you are wondering why we don't just make them a single variable,
4128 * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
4129 * child backends specially. XXX is that still true? Given that we now
4130 * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
4131 * DataDir in advance.)
4133 SetConfigOption("data_directory", DataDir, PGC_POSTMASTER, PGC_S_OVERRIDE);
4136 * If timezone_abbreviations wasn't set in the configuration file, install
4137 * the default value. We do it this way because we can't safely install
4138 * a "real" value until my_exec_path is set, which may not have happened
4139 * when InitializeGUCOptions runs, so the bootstrap default value cannot
4140 * be the real desired default.
4142 pg_timezone_abbrev_initialize();
4145 * Figure out where pg_hba.conf is, and make sure the path is absolute.
4148 fname = make_absolute_path(HbaFileName);
4151 fname = guc_malloc(FATAL,
4152 strlen(configdir) + strlen(HBA_FILENAME) + 2);
4153 sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
4157 write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
4158 "This can be specified as \"hba_file\" in \"%s\", "
4159 "or by the -D invocation option, or by the "
4160 "PGDATA environment variable.\n",
4161 progname, ConfigFileName);
4164 SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4168 * Likewise for pg_ident.conf.
4171 fname = make_absolute_path(IdentFileName);
4174 fname = guc_malloc(FATAL,
4175 strlen(configdir) + strlen(IDENT_FILENAME) + 2);
4176 sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
4180 write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
4181 "This can be specified as \"ident_file\" in \"%s\", "
4182 "or by the -D invocation option, or by the "
4183 "PGDATA environment variable.\n",
4184 progname, ConfigFileName);
4187 SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4197 * Reset all options to their saved default values (implements RESET ALL)
4200 ResetAllOptions(void)
4204 for (i = 0; i < num_guc_variables; i++)
4206 struct config_generic *gconf = guc_variables[i];
4208 /* Don't reset non-SET-able values */
4209 if (gconf->context != PGC_SUSET &&
4210 gconf->context != PGC_USERSET)
4212 /* Don't reset if special exclusion from RESET ALL */
4213 if (gconf->flags & GUC_NO_RESET_ALL)
4215 /* No need to reset if wasn't SET */
4216 if (gconf->source <= PGC_S_OVERRIDE)
4219 /* Save old value to support transaction abort */
4220 push_old_value(gconf, GUC_ACTION_SET);
4222 switch (gconf->vartype)
4226 struct config_bool *conf = (struct config_bool *) gconf;
4228 if (conf->assign_hook)
4229 (*conf->assign_hook) (conf->reset_val,
4231 *conf->variable = conf->reset_val;
4232 set_extra_field(&conf->gen, &conf->gen.extra,
4238 struct config_int *conf = (struct config_int *) gconf;
4240 if (conf->assign_hook)
4241 (*conf->assign_hook) (conf->reset_val,
4243 *conf->variable = conf->reset_val;
4244 set_extra_field(&conf->gen, &conf->gen.extra,
4250 struct config_real *conf = (struct config_real *) gconf;
4252 if (conf->assign_hook)
4253 (*conf->assign_hook) (conf->reset_val,
4255 *conf->variable = conf->reset_val;
4256 set_extra_field(&conf->gen, &conf->gen.extra,
4262 struct config_string *conf = (struct config_string *) gconf;
4264 if (conf->assign_hook)
4265 (*conf->assign_hook) (conf->reset_val,
4267 set_string_field(conf, conf->variable, conf->reset_val);
4268 set_extra_field(&conf->gen, &conf->gen.extra,
4274 struct config_enum *conf = (struct config_enum *) gconf;
4276 if (conf->assign_hook)
4277 (*conf->assign_hook) (conf->reset_val,
4279 *conf->variable = conf->reset_val;
4280 set_extra_field(&conf->gen, &conf->gen.extra,
4286 gconf->source = gconf->reset_source;
4287 gconf->scontext = gconf->reset_scontext;
4289 if (gconf->flags & GUC_REPORT)
4290 ReportGUCOption(gconf);
4297 * Push previous state during transactional assignment to a GUC variable.
4300 push_old_value(struct config_generic * gconf, GucAction action)
4304 /* If we're not inside a nest level, do nothing */
4305 if (GUCNestLevel == 0)
4308 /* Do we already have a stack entry of the current nest level? */
4309 stack = gconf->stack;
4310 if (stack && stack->nest_level >= GUCNestLevel)
4312 /* Yes, so adjust its state if necessary */
4313 Assert(stack->nest_level == GUCNestLevel);
4316 case GUC_ACTION_SET:
4317 /* SET overrides any prior action at same nest level */
4318 if (stack->state == GUC_SET_LOCAL)
4320 /* must discard old masked value */
4321 discard_stack_value(gconf, &stack->masked);
4323 stack->state = GUC_SET;
4325 case GUC_ACTION_LOCAL:
4326 if (stack->state == GUC_SET)
4328 /* SET followed by SET LOCAL, remember SET's value */
4329 stack->masked_scontext = gconf->scontext;
4330 set_stack_value(gconf, &stack->masked);
4331 stack->state = GUC_SET_LOCAL;
4333 /* in all other cases, no change to stack entry */
4335 case GUC_ACTION_SAVE:
4336 /* Could only have a prior SAVE of same variable */
4337 Assert(stack->state == GUC_SAVE);
4340 Assert(guc_dirty); /* must be set already */
4345 * Push a new stack entry
4347 * We keep all the stack entries in TopTransactionContext for simplicity.
4349 stack = (GucStack *) MemoryContextAllocZero(TopTransactionContext,
4352 stack->prev = gconf->stack;
4353 stack->nest_level = GUCNestLevel;
4356 case GUC_ACTION_SET:
4357 stack->state = GUC_SET;
4359 case GUC_ACTION_LOCAL:
4360 stack->state = GUC_LOCAL;
4362 case GUC_ACTION_SAVE:
4363 stack->state = GUC_SAVE;
4366 stack->source = gconf->source;
4367 stack->scontext = gconf->scontext;
4368 set_stack_value(gconf, &stack->prior);
4370 gconf->stack = stack;
4372 /* Ensure we remember to pop at end of xact */
4378 * Do GUC processing at main transaction start.
4384 * The nest level should be 0 between transactions; if it isn't, somebody
4385 * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
4386 * throw a warning but make no other effort to clean up.
4388 if (GUCNestLevel != 0)
4389 elog(WARNING, "GUC nest level = %d at transaction start",
4395 * Enter a new nesting level for GUC values. This is called at subtransaction
4396 * start, and when entering a function that has proconfig settings, and in
4397 * some other places where we want to set GUC variables transiently.
4398 * NOTE we must not risk error here, else subtransaction start will be unhappy.
4401 NewGUCNestLevel(void)
4403 return ++GUCNestLevel;
4407 * Do GUC processing at transaction or subtransaction commit or abort, or
4408 * when exiting a function that has proconfig settings, or when undoing a
4409 * transient assignment to some GUC variables. (The name is thus a bit of
4410 * a misnomer; perhaps it should be ExitGUCNestLevel or some such.)
4411 * During abort, we discard all GUC settings that were applied at nesting
4412 * levels >= nestLevel. nestLevel == 1 corresponds to the main transaction.
4415 AtEOXact_GUC(bool isCommit, int nestLevel)
4421 * Note: it's possible to get here with GUCNestLevel == nestLevel-1 during
4422 * abort, if there is a failure during transaction start before
4423 * AtStart_GUC is called.
4425 Assert(nestLevel > 0 &&
4426 (nestLevel <= GUCNestLevel ||
4427 (nestLevel == GUCNestLevel + 1 && !isCommit)));
4429 /* Quick exit if nothing's changed in this transaction */
4432 GUCNestLevel = nestLevel - 1;
4436 still_dirty = false;
4437 for (i = 0; i < num_guc_variables; i++)
4439 struct config_generic *gconf = guc_variables[i];
4443 * Process and pop each stack entry within the nest level. To simplify
4444 * fmgr_security_definer() and other places that use GUC_ACTION_SAVE,
4445 * we allow failure exit from code that uses a local nest level to be
4446 * recovered at the surrounding transaction or subtransaction abort;
4447 * so there could be more than one stack entry to pop.
4449 while ((stack = gconf->stack) != NULL &&
4450 stack->nest_level >= nestLevel)
4452 GucStack *prev = stack->prev;
4453 bool restorePrior = false;
4454 bool restoreMasked = false;
4458 * In this next bit, if we don't set either restorePrior or
4459 * restoreMasked, we must "discard" any unwanted fields of the
4460 * stack entries to avoid leaking memory. If we do set one of
4461 * those flags, unused fields will be cleaned up after restoring.
4463 if (!isCommit) /* if abort, always restore prior value */
4464 restorePrior = true;
4465 else if (stack->state == GUC_SAVE)
4466 restorePrior = true;
4467 else if (stack->nest_level == 1)
4469 /* transaction commit */
4470 if (stack->state == GUC_SET_LOCAL)
4471 restoreMasked = true;
4472 else if (stack->state == GUC_SET)
4474 /* we keep the current active value */
4475 discard_stack_value(gconf, &stack->prior);
4477 else /* must be GUC_LOCAL */
4478 restorePrior = true;
4480 else if (prev == NULL ||
4481 prev->nest_level < stack->nest_level - 1)
4483 /* decrement entry's level and do not pop it */
4484 stack->nest_level--;
4490 * We have to merge this stack entry into prev. See README for
4491 * discussion of this bit.
4493 switch (stack->state)
4496 Assert(false); /* can't get here */
4499 /* next level always becomes SET */
4500 discard_stack_value(gconf, &stack->prior);
4501 if (prev->state == GUC_SET_LOCAL)
4502 discard_stack_value(gconf, &prev->masked);
4503 prev->state = GUC_SET;
4507 if (prev->state == GUC_SET)
4509 /* LOCAL migrates down */
4510 prev->masked_scontext = stack->scontext;
4511 prev->masked = stack->prior;
4512 prev->state = GUC_SET_LOCAL;
4516 /* else just forget this stack level */
4517 discard_stack_value(gconf, &stack->prior);
4522 /* prior state at this level no longer wanted */
4523 discard_stack_value(gconf, &stack->prior);
4524 /* copy down the masked state */
4525 prev->masked_scontext = stack->masked_scontext;
4526 if (prev->state == GUC_SET_LOCAL)
4527 discard_stack_value(gconf, &prev->masked);
4528 prev->masked = stack->masked;
4529 prev->state = GUC_SET_LOCAL;
4536 if (restorePrior || restoreMasked)
4538 /* Perform appropriate restoration of the stacked value */
4539 config_var_value newvalue;
4540 GucSource newsource;
4541 GucContext newscontext;
4545 newvalue = stack->masked;
4546 newsource = PGC_S_SESSION;
4547 newscontext = stack->masked_scontext;
4551 newvalue = stack->prior;
4552 newsource = stack->source;
4553 newscontext = stack->scontext;
4556 switch (gconf->vartype)
4560 struct config_bool *conf = (struct config_bool *) gconf;
4561 bool newval = newvalue.val.boolval;
4562 void *newextra = newvalue.extra;
4564 if (*conf->variable != newval ||
4565 conf->gen.extra != newextra)
4567 if (conf->assign_hook)
4568 (*conf->assign_hook) (newval, newextra);
4569 *conf->variable = newval;
4570 set_extra_field(&conf->gen, &conf->gen.extra,
4578 struct config_int *conf = (struct config_int *) gconf;
4579 int newval = newvalue.val.intval;
4580 void *newextra = newvalue.extra;
4582 if (*conf->variable != newval ||
4583 conf->gen.extra != newextra)
4585 if (conf->assign_hook)
4586 (*conf->assign_hook) (newval, newextra);
4587 *conf->variable = newval;
4588 set_extra_field(&conf->gen, &conf->gen.extra,
4596 struct config_real *conf = (struct config_real *) gconf;
4597 double newval = newvalue.val.realval;
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,
4614 struct config_string *conf = (struct config_string *) gconf;
4615 char *newval = newvalue.val.stringval;
4616 void *newextra = newvalue.extra;
4618 if (*conf->variable != newval ||
4619 conf->gen.extra != newextra)
4621 if (conf->assign_hook)
4622 (*conf->assign_hook) (newval, newextra);
4623 set_string_field(conf, conf->variable, newval);
4624 set_extra_field(&conf->gen, &conf->gen.extra,
4630 * Release stacked values if not used anymore. We
4631 * could use discard_stack_value() here, but since
4632 * we have type-specific code anyway, might as
4635 set_string_field(conf, &stack->prior.val.stringval, NULL);
4636 set_string_field(conf, &stack->masked.val.stringval, NULL);
4641 struct config_enum *conf = (struct config_enum *) gconf;
4642 int newval = newvalue.val.enumval;
4643 void *newextra = newvalue.extra;
4645 if (*conf->variable != newval ||
4646 conf->gen.extra != newextra)
4648 if (conf->assign_hook)
4649 (*conf->assign_hook) (newval, newextra);
4650 *conf->variable = newval;
4651 set_extra_field(&conf->gen, &conf->gen.extra,
4660 * Release stacked extra values if not used anymore.
4662 set_extra_field(gconf, &(stack->prior.extra), NULL);
4663 set_extra_field(gconf, &(stack->masked.extra), NULL);
4665 /* And restore source information */
4666 gconf->source = newsource;
4667 gconf->scontext = newscontext;
4670 /* Finish popping the state stack */
4671 gconf->stack = prev;
4674 /* Report new value if we changed it */
4675 if (changed && (gconf->flags & GUC_REPORT))
4676 ReportGUCOption(gconf);
4677 } /* end of stack-popping loop */
4683 /* If there are no remaining stack entries, we can reset guc_dirty */
4684 guc_dirty = still_dirty;
4686 /* Update nesting level */
4687 GUCNestLevel = nestLevel - 1;
4692 * Start up automatic reporting of changes to variables marked GUC_REPORT.
4693 * This is executed at completion of backend startup.
4696 BeginReportingGUCOptions(void)
4701 * Don't do anything unless talking to an interactive frontend of protocol
4704 if (whereToSendOutput != DestRemote ||
4705 PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
4708 reporting_enabled = true;
4710 /* Transmit initial values of interesting variables */
4711 for (i = 0; i < num_guc_variables; i++)
4713 struct config_generic *conf = guc_variables[i];
4715 if (conf->flags & GUC_REPORT)
4716 ReportGUCOption(conf);
4721 * ReportGUCOption: if appropriate, transmit option value to frontend
4724 ReportGUCOption(struct config_generic * record)
4726 if (reporting_enabled && (record->flags & GUC_REPORT))
4728 char *val = _ShowOption(record, false);
4729 StringInfoData msgbuf;
4731 pq_beginmessage(&msgbuf, 'S');
4732 pq_sendstring(&msgbuf, record->name);
4733 pq_sendstring(&msgbuf, val);
4734 pq_endmessage(&msgbuf);
4741 * Try to parse value as an integer. The accepted formats are the
4742 * usual decimal, octal, or hexadecimal formats, optionally followed by
4743 * a unit name if "flags" indicates a unit is allowed.
4745 * If the string parses okay, return true, else false.
4746 * If okay and result is not NULL, return the value in *result.
4747 * If not okay and hintmsg is not NULL, *hintmsg is set to a suitable
4748 * HINT message, or NULL if no hint provided.
4751 parse_int(const char *value, int *result, int flags, const char **hintmsg)
4756 /* To suppress compiler warnings, always set output params */
4762 /* We assume here that int64 is at least as wide as long */
4764 val = strtol(value, &endptr, 0);
4766 if (endptr == value)
4767 return false; /* no HINT for integer syntax error */
4769 if (errno == ERANGE || val != (int64) ((int32) val))
4772 *hintmsg = gettext_noop("Value exceeds integer range.");
4776 /* allow whitespace between integer and unit */
4777 while (isspace((unsigned char) *endptr))
4780 /* Handle possible unit */
4781 if (*endptr != '\0')
4784 * Note: the multiple-switch coding technique here is a bit tedious,
4785 * but seems necessary to avoid intermediate-value overflows.
4787 if (flags & GUC_UNIT_MEMORY)
4789 /* Set hint for use if no match or trailing garbage */
4791 *hintmsg = gettext_noop("Valid units for this parameter are \"kB\", \"MB\", and \"GB\".");
4793 #if BLCKSZ < 1024 || BLCKSZ > (1024*1024)
4794 #error BLCKSZ must be between 1KB and 1MB
4796 #if XLOG_BLCKSZ < 1024 || XLOG_BLCKSZ > (1024*1024)
4797 #error XLOG_BLCKSZ must be between 1KB and 1MB
4800 if (strncmp(endptr, "kB", 2) == 0)
4803 switch (flags & GUC_UNIT_MEMORY)
4805 case GUC_UNIT_BLOCKS:
4806 val /= (BLCKSZ / 1024);
4808 case GUC_UNIT_XBLOCKS:
4809 val /= (XLOG_BLCKSZ / 1024);
4813 else if (strncmp(endptr, "MB", 2) == 0)
4816 switch (flags & GUC_UNIT_MEMORY)
4821 case GUC_UNIT_BLOCKS:
4822 val *= KB_PER_MB / (BLCKSZ / 1024);
4824 case GUC_UNIT_XBLOCKS:
4825 val *= KB_PER_MB / (XLOG_BLCKSZ / 1024);
4829 else if (strncmp(endptr, "GB", 2) == 0)
4832 switch (flags & GUC_UNIT_MEMORY)
4837 case GUC_UNIT_BLOCKS:
4838 val *= KB_PER_GB / (BLCKSZ / 1024);
4840 case GUC_UNIT_XBLOCKS:
4841 val *= KB_PER_GB / (XLOG_BLCKSZ / 1024);
4846 else if (flags & GUC_UNIT_TIME)
4848 /* Set hint for use if no match or trailing garbage */
4850 *hintmsg = gettext_noop("Valid units for this parameter are \"ms\", \"s\", \"min\", \"h\", and \"d\".");
4852 if (strncmp(endptr, "ms", 2) == 0)
4855 switch (flags & GUC_UNIT_TIME)
4865 else if (strncmp(endptr, "s", 1) == 0)
4868 switch (flags & GUC_UNIT_TIME)
4878 else if (strncmp(endptr, "min", 3) == 0)
4881 switch (flags & GUC_UNIT_TIME)
4891 else if (strncmp(endptr, "h", 1) == 0)
4894 switch (flags & GUC_UNIT_TIME)
4907 else if (strncmp(endptr, "d", 1) == 0)
4910 switch (flags & GUC_UNIT_TIME)
4925 /* allow whitespace after unit */
4926 while (isspace((unsigned char) *endptr))
4929 if (*endptr != '\0')
4930 return false; /* appropriate hint, if any, already set */
4932 /* Check for overflow due to units conversion */
4933 if (val != (int64) ((int32) val))
4936 *hintmsg = gettext_noop("Value exceeds integer range.");
4942 *result = (int) val;
4949 * Try to parse value as a floating point number in the usual format.
4950 * If the string parses okay, return true, else false.
4951 * If okay and result is not NULL, return the value in *result.
4954 parse_real(const char *value, double *result)
4960 *result = 0; /* suppress compiler warning */
4963 val = strtod(value, &endptr);
4964 if (endptr == value || errno == ERANGE)
4967 /* allow whitespace after number */
4968 while (isspace((unsigned char) *endptr))
4970 if (*endptr != '\0')
4980 * Lookup the name for an enum option with the selected value.
4981 * Should only ever be called with known-valid values, so throws
4982 * an elog(ERROR) if the enum option is not found.
4984 * The returned string is a pointer to static data and not
4985 * allocated for modification.
4988 config_enum_lookup_by_value(struct config_enum * record, int val)
4990 const struct config_enum_entry *entry;
4992 for (entry = record->options; entry && entry->name; entry++)
4994 if (entry->val == val)
4998 elog(ERROR, "could not find enum option %d for %s",
4999 val, record->gen.name);
5000 return NULL; /* silence compiler */
5005 * Lookup the value for an enum option with the selected name
5006 * (case-insensitive).
5007 * If the enum option is found, sets the retval value and returns
5008 * true. If it's not found, return FALSE and retval is set to 0.
5011 config_enum_lookup_by_name(struct config_enum * record, const char *value,
5014 const struct config_enum_entry *entry;
5016 for (entry = record->options; entry && entry->name; entry++)
5018 if (pg_strcasecmp(value, entry->name) == 0)
5020 *retval = entry->val;
5031 * Return a list of all available options for an enum, excluding
5032 * hidden ones, separated by the given separator.
5033 * If prefix is non-NULL, it is added before the first enum value.
5034 * If suffix is non-NULL, it is added to the end of the string.
5037 config_enum_get_options(struct config_enum * record, const char *prefix,
5038 const char *suffix, const char *separator)
5040 const struct config_enum_entry *entry;
5041 StringInfoData retstr;
5044 initStringInfo(&retstr);
5045 appendStringInfoString(&retstr, prefix);
5047 seplen = strlen(separator);
5048 for (entry = record->options; entry && entry->name; entry++)
5052 appendStringInfoString(&retstr, entry->name);
5053 appendBinaryStringInfo(&retstr, separator, seplen);
5058 * All the entries may have been hidden, leaving the string empty if no
5059 * prefix was given. This indicates a broken GUC setup, since there is no
5060 * use for an enum without any values, so we just check to make sure we
5061 * don't write to invalid memory instead of actually trying to do
5062 * something smart with it.
5064 if (retstr.len >= seplen)
5066 /* Replace final separator */
5067 retstr.data[retstr.len - seplen] = '\0';
5068 retstr.len -= seplen;
5071 appendStringInfoString(&retstr, suffix);
5078 * Sets option `name' to given value.
5080 * The value should be a string, which will be parsed and converted to
5081 * the appropriate data type. The context and source parameters indicate
5082 * in which context this function is being called, so that it can apply the
5083 * access restrictions properly.
5085 * If value is NULL, set the option to its default value (normally the
5086 * reset_val, but if source == PGC_S_DEFAULT we instead use the boot_val).
5088 * action indicates whether to set the value globally in the session, locally
5089 * to the current top transaction, or just for the duration of a function call.
5091 * If changeVal is false then don't really set the option but do all
5092 * the checks to see if it would work.
5094 * elevel should normally be passed as zero, allowing this function to make
5095 * its standard choice of ereport level. However some callers need to be
5096 * able to override that choice; they should pass the ereport level to use.
5099 * +1: the value is valid and was successfully applied.
5100 * 0: the name or value is invalid (but see below).
5101 * -1: the value was not applied because of context, priority, or changeVal.
5103 * If there is an error (non-existing option, invalid value) then an
5104 * ereport(ERROR) is thrown *unless* this is called for a source for which
5105 * we don't want an ERROR (currently, those are defaults, the config file,
5106 * and per-database or per-user settings, as well as callers who specify
5107 * a less-than-ERROR elevel). In those cases we write a suitable error
5108 * message via ereport() and return 0.
5110 * See also SetConfigOption for an external interface.
5113 set_config_option(const char *name, const char *value,
5114 GucContext context, GucSource source,
5115 GucAction action, bool changeVal, int elevel)
5117 struct config_generic *record;
5118 bool prohibitValueChange = false;
5123 if (source == PGC_S_DEFAULT || source == PGC_S_FILE)
5126 * To avoid cluttering the log, only the postmaster bleats loudly
5127 * about problems with the config file.
5129 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
5131 else if (source == PGC_S_DATABASE || source == PGC_S_USER ||
5132 source == PGC_S_DATABASE_USER)
5138 record = find_option(name, true, elevel);
5142 (errcode(ERRCODE_UNDEFINED_OBJECT),
5143 errmsg("unrecognized configuration parameter \"%s\"", name)));
5148 * Check if the option can be set at this time. See guc.h for the precise
5151 switch (record->context)
5154 if (context != PGC_INTERNAL)
5157 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5158 errmsg("parameter \"%s\" cannot be changed",
5163 case PGC_POSTMASTER:
5164 if (context == PGC_SIGHUP)
5167 * We are re-reading a PGC_POSTMASTER variable from
5168 * postgresql.conf. We can't change the setting, so we should
5169 * give a warning if the DBA tries to change it. However,
5170 * because of variant formats, canonicalization by check
5171 * hooks, etc, we can't just compare the given string directly
5172 * to what's stored. Set a flag to check below after we have
5173 * the final storable value.
5175 prohibitValueChange = true;
5177 else if (context != PGC_POSTMASTER)
5180 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5181 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5187 if (context != PGC_SIGHUP && context != PGC_POSTMASTER)
5190 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5191 errmsg("parameter \"%s\" cannot be changed now",
5197 * Hmm, the idea of the SIGHUP context is "ought to be global, but
5198 * can be changed after postmaster start". But there's nothing
5199 * that prevents a crafty administrator from sending SIGHUP
5200 * signals to individual backends only.
5204 if (context == PGC_SIGHUP)
5207 * If a PGC_BACKEND parameter is changed in the config file,
5208 * we want to accept the new value in the postmaster (whence
5209 * it will propagate to subsequently-started backends), but
5210 * ignore it in existing backends. This is a tad klugy, but
5211 * necessary because we don't re-read the config file during
5214 if (IsUnderPostmaster)
5217 else if (context != PGC_POSTMASTER && context != PGC_BACKEND &&
5218 source != PGC_S_CLIENT)
5221 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5222 errmsg("parameter \"%s\" cannot be set after connection start",
5228 if (context == PGC_USERSET || context == PGC_BACKEND)
5231 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5232 errmsg("permission denied to set parameter \"%s\"",
5243 * Disallow changing GUC_NOT_WHILE_SEC_REST values if we are inside a
5244 * security restriction context. We can reject this regardless of the GUC
5245 * context or source, mainly because sources that it might be reasonable
5246 * to override for won't be seen while inside a function.
5248 * Note: variables marked GUC_NOT_WHILE_SEC_REST should usually be marked
5249 * GUC_NO_RESET_ALL as well, because ResetAllOptions() doesn't check this.
5250 * An exception might be made if the reset value is assumed to be "safe".
5252 * Note: this flag is currently used for "session_authorization" and
5253 * "role". We need to prohibit changing these inside a local userid
5254 * context because when we exit it, GUC won't be notified, leaving things
5255 * out of sync. (This could be fixed by forcing a new GUC nesting level,
5256 * but that would change behavior in possibly-undesirable ways.) Also, we
5257 * prohibit changing these in a security-restricted operation because
5258 * otherwise RESET could be used to regain the session user's privileges.
5260 if (record->flags & GUC_NOT_WHILE_SEC_REST)
5262 if (InLocalUserIdChange())
5265 * Phrasing of this error message is historical, but it's the most
5269 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5270 errmsg("cannot set parameter \"%s\" within security-definer function",
5274 if (InSecurityRestrictedOperation())
5277 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5278 errmsg("cannot set parameter \"%s\" within security-restricted operation",
5285 * Should we set reset/stacked values? (If so, the behavior is not
5286 * transactional.) This is done either when we get a default value from
5287 * the database's/user's/client's default settings or when we reset a
5288 * value to its default.
5290 makeDefault = changeVal && (source <= PGC_S_OVERRIDE) &&
5291 ((value != NULL) || source == PGC_S_DEFAULT);
5294 * Ignore attempted set if overridden by previously processed setting.
5295 * However, if changeVal is false then plow ahead anyway since we are
5296 * trying to find out if the value is potentially good, not actually use
5297 * it. Also keep going if makeDefault is true, since we may want to set
5298 * the reset/stacked values even if we can't set the variable itself.
5300 if (record->source > source)
5302 if (changeVal && !makeDefault)
5304 elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
5312 * Evaluate value and set variable.
5314 switch (record->vartype)
5318 struct config_bool *conf = (struct config_bool *) record;
5320 void *newextra = NULL;
5324 if (!parse_bool(value, &newval))
5327 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5328 errmsg("parameter \"%s\" requires a Boolean value",
5332 if (!call_bool_check_hook(conf, &newval, &newextra,
5336 else if (source == PGC_S_DEFAULT)
5338 newval = conf->boot_val;
5339 if (!call_bool_check_hook(conf, &newval, &newextra,
5345 newval = conf->reset_val;
5346 newextra = conf->reset_extra;
5347 source = conf->gen.reset_source;
5348 context = conf->gen.reset_scontext;
5351 if (prohibitValueChange)
5353 if (*conf->variable != newval)
5356 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5357 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5366 /* Save old value to support transaction abort */
5368 push_old_value(&conf->gen, action);
5370 if (conf->assign_hook)
5371 (*conf->assign_hook) (newval, newextra);
5372 *conf->variable = newval;
5373 set_extra_field(&conf->gen, &conf->gen.extra,
5375 conf->gen.source = source;
5376 conf->gen.scontext = context;
5382 if (conf->gen.reset_source <= source)
5384 conf->reset_val = newval;
5385 set_extra_field(&conf->gen, &conf->reset_extra,
5387 conf->gen.reset_source = source;
5388 conf->gen.reset_scontext = context;
5390 for (stack = conf->gen.stack; stack; stack = stack->prev)
5392 if (stack->source <= source)
5394 stack->prior.val.boolval = newval;
5395 set_extra_field(&conf->gen, &stack->prior.extra,
5397 stack->source = source;
5398 stack->scontext = context;
5403 /* Perhaps we didn't install newextra anywhere */
5404 if (newextra && !extra_field_used(&conf->gen, newextra))
5411 struct config_int *conf = (struct config_int *) record;
5413 void *newextra = NULL;
5417 const char *hintmsg;
5419 if (!parse_int(value, &newval, conf->gen.flags, &hintmsg))
5422 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5423 errmsg("invalid value for parameter \"%s\": \"%s\"",
5425 hintmsg ? errhint("%s", _(hintmsg)) : 0));
5428 if (newval < conf->min || newval > conf->max)
5431 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5432 errmsg("%d is outside the valid range for parameter \"%s\" (%d .. %d)",
5433 newval, name, conf->min, conf->max)));
5436 if (!call_int_check_hook(conf, &newval, &newextra,
5440 else if (source == PGC_S_DEFAULT)
5442 newval = conf->boot_val;
5443 if (!call_int_check_hook(conf, &newval, &newextra,
5449 newval = conf->reset_val;
5450 newextra = conf->reset_extra;
5451 source = conf->gen.reset_source;
5452 context = conf->gen.reset_scontext;
5455 if (prohibitValueChange)
5457 if (*conf->variable != newval)
5460 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5461 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5470 /* Save old value to support transaction abort */
5472 push_old_value(&conf->gen, action);
5474 if (conf->assign_hook)
5475 (*conf->assign_hook) (newval, newextra);
5476 *conf->variable = newval;
5477 set_extra_field(&conf->gen, &conf->gen.extra,
5479 conf->gen.source = source;
5480 conf->gen.scontext = context;
5486 if (conf->gen.reset_source <= source)
5488 conf->reset_val = newval;
5489 set_extra_field(&conf->gen, &conf->reset_extra,
5491 conf->gen.reset_source = source;
5492 conf->gen.reset_scontext = context;
5494 for (stack = conf->gen.stack; stack; stack = stack->prev)
5496 if (stack->source <= source)
5498 stack->prior.val.intval = newval;
5499 set_extra_field(&conf->gen, &stack->prior.extra,
5501 stack->source = source;
5502 stack->scontext = context;
5507 /* Perhaps we didn't install newextra anywhere */
5508 if (newextra && !extra_field_used(&conf->gen, newextra))
5515 struct config_real *conf = (struct config_real *) record;
5517 void *newextra = NULL;
5521 if (!parse_real(value, &newval))
5524 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5525 errmsg("parameter \"%s\" requires a numeric value",
5529 if (newval < conf->min || newval > conf->max)
5532 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5533 errmsg("%g is outside the valid range for parameter \"%s\" (%g .. %g)",
5534 newval, name, conf->min, conf->max)));
5537 if (!call_real_check_hook(conf, &newval, &newextra,
5541 else if (source == PGC_S_DEFAULT)
5543 newval = conf->boot_val;
5544 if (!call_real_check_hook(conf, &newval, &newextra,
5550 newval = conf->reset_val;
5551 newextra = conf->reset_extra;
5552 source = conf->gen.reset_source;
5553 context = conf->gen.reset_scontext;
5556 if (prohibitValueChange)
5558 if (*conf->variable != newval)
5561 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5562 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5571 /* Save old value to support transaction abort */
5573 push_old_value(&conf->gen, action);
5575 if (conf->assign_hook)
5576 (*conf->assign_hook) (newval, newextra);
5577 *conf->variable = newval;
5578 set_extra_field(&conf->gen, &conf->gen.extra,
5580 conf->gen.source = source;
5581 conf->gen.scontext = context;
5587 if (conf->gen.reset_source <= source)
5589 conf->reset_val = newval;
5590 set_extra_field(&conf->gen, &conf->reset_extra,
5592 conf->gen.reset_source = source;
5593 conf->gen.reset_scontext = context;
5595 for (stack = conf->gen.stack; stack; stack = stack->prev)
5597 if (stack->source <= source)
5599 stack->prior.val.realval = newval;
5600 set_extra_field(&conf->gen, &stack->prior.extra,
5602 stack->source = source;
5603 stack->scontext = context;
5608 /* Perhaps we didn't install newextra anywhere */
5609 if (newextra && !extra_field_used(&conf->gen, newextra))
5616 struct config_string *conf = (struct config_string *) record;
5618 void *newextra = NULL;
5623 * The value passed by the caller could be transient, so
5624 * we always strdup it.
5626 newval = guc_strdup(elevel, value);
5631 * The only built-in "parsing" check we have is to apply
5632 * truncation if GUC_IS_NAME.
5634 if (conf->gen.flags & GUC_IS_NAME)
5635 truncate_identifier(newval, strlen(newval), true);
5637 if (!call_string_check_hook(conf, &newval, &newextra,
5644 else if (source == PGC_S_DEFAULT)
5646 /* non-NULL boot_val must always get strdup'd */
5647 if (conf->boot_val != NULL)
5649 newval = guc_strdup(elevel, conf->boot_val);
5656 if (!call_string_check_hook(conf, &newval, &newextra,
5666 * strdup not needed, since reset_val is already under
5669 newval = conf->reset_val;
5670 newextra = conf->reset_extra;
5671 source = conf->gen.reset_source;
5672 context = conf->gen.reset_scontext;
5675 if (prohibitValueChange)
5677 /* newval shouldn't be NULL, so we're a bit sloppy here */
5678 if (*conf->variable == NULL || newval == NULL ||
5679 strcmp(*conf->variable, newval) != 0)
5682 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5683 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5692 /* Save old value to support transaction abort */
5694 push_old_value(&conf->gen, action);
5696 if (conf->assign_hook)
5697 (*conf->assign_hook) (newval, newextra);
5698 set_string_field(conf, conf->variable, newval);
5699 set_extra_field(&conf->gen, &conf->gen.extra,
5701 conf->gen.source = source;
5702 conf->gen.scontext = context;
5709 if (conf->gen.reset_source <= source)
5711 set_string_field(conf, &conf->reset_val, newval);
5712 set_extra_field(&conf->gen, &conf->reset_extra,
5714 conf->gen.reset_source = source;
5715 conf->gen.reset_scontext = context;
5717 for (stack = conf->gen.stack; stack; stack = stack->prev)
5719 if (stack->source <= source)
5721 set_string_field(conf, &stack->prior.val.stringval,
5723 set_extra_field(&conf->gen, &stack->prior.extra,
5725 stack->source = source;
5726 stack->scontext = context;
5731 /* Perhaps we didn't install newval anywhere */
5732 if (newval && !string_field_used(conf, newval))
5734 /* Perhaps we didn't install newextra anywhere */
5735 if (newextra && !extra_field_used(&conf->gen, newextra))
5742 struct config_enum *conf = (struct config_enum *) record;
5744 void *newextra = NULL;
5748 if (!config_enum_lookup_by_name(conf, value, &newval))
5752 hintmsg = config_enum_get_options(conf,
5753 "Available values: ",
5757 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5758 errmsg("invalid value for parameter \"%s\": \"%s\"",
5760 hintmsg ? errhint("%s", _(hintmsg)) : 0));
5766 if (!call_enum_check_hook(conf, &newval, &newextra,
5770 else if (source == PGC_S_DEFAULT)
5772 newval = conf->boot_val;
5773 if (!call_enum_check_hook(conf, &newval, &newextra,
5779 newval = conf->reset_val;
5780 newextra = conf->reset_extra;
5781 source = conf->gen.reset_source;
5782 context = conf->gen.reset_scontext;
5785 if (prohibitValueChange)
5787 if (*conf->variable != newval)
5790 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5791 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5800 /* Save old value to support transaction abort */
5802 push_old_value(&conf->gen, action);
5804 if (conf->assign_hook)
5805 (*conf->assign_hook) (newval, newextra);
5806 *conf->variable = newval;
5807 set_extra_field(&conf->gen, &conf->gen.extra,
5809 conf->gen.source = source;
5810 conf->gen.scontext = context;
5816 if (conf->gen.reset_source <= source)
5818 conf->reset_val = newval;
5819 set_extra_field(&conf->gen, &conf->reset_extra,
5821 conf->gen.reset_source = source;
5822 conf->gen.reset_scontext = context;
5824 for (stack = conf->gen.stack; stack; stack = stack->prev)
5826 if (stack->source <= source)
5828 stack->prior.val.enumval = newval;
5829 set_extra_field(&conf->gen, &stack->prior.extra,
5831 stack->source = source;
5832 stack->scontext = context;
5837 /* Perhaps we didn't install newextra anywhere */
5838 if (newextra && !extra_field_used(&conf->gen, newextra))
5844 if (changeVal && (record->flags & GUC_REPORT))
5845 ReportGUCOption(record);
5847 return changeVal ? 1 : -1;
5852 * Set the fields for source file and line number the setting came from.
5855 set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
5857 struct config_generic *record;
5861 * To avoid cluttering the log, only the postmaster bleats loudly about
5862 * problems with the config file.
5864 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
5866 record = find_option(name, true, elevel);
5867 /* should not happen */
5869 elog(ERROR, "unrecognized configuration parameter \"%s\"", name);
5871 sourcefile = guc_strdup(elevel, sourcefile);
5872 if (record->sourcefile)
5873 free(record->sourcefile);
5874 record->sourcefile = sourcefile;
5875 record->sourceline = sourceline;
5879 * Set a config option to the given value.
5881 * See also set_config_option; this is just the wrapper to be called from
5882 * outside GUC. (This function should be used when possible, because its API
5883 * is more stable than set_config_option's.)
5885 * Note: there is no support here for setting source file/line, as it
5886 * is currently not needed.
5889 SetConfigOption(const char *name, const char *value,
5890 GucContext context, GucSource source)
5892 (void) set_config_option(name, value, context, source,
5893 GUC_ACTION_SET, true, 0);
5899 * Fetch the current value of the option `name', as a string.
5901 * If the option doesn't exist, return NULL if missing_ok is true (NOTE that
5902 * this cannot be distinguished from a string variable with a NULL value!),
5903 * otherwise throw an ereport and don't return.
5905 * If restrict_superuser is true, we also enforce that only superusers can
5906 * see GUC_SUPERUSER_ONLY variables. This should only be passed as true
5907 * in user-driven calls.
5909 * The string is *not* allocated for modification and is really only
5910 * valid until the next call to configuration related functions.
5913 GetConfigOption(const char *name, bool missing_ok, bool restrict_superuser)
5915 struct config_generic *record;
5916 static char buffer[256];
5918 record = find_option(name, false, ERROR);
5924 (errcode(ERRCODE_UNDEFINED_OBJECT),
5925 errmsg("unrecognized configuration parameter \"%s\"",
5928 if (restrict_superuser &&
5929 (record->flags & GUC_SUPERUSER_ONLY) &&
5932 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5933 errmsg("must be superuser to examine \"%s\"", name)));
5935 switch (record->vartype)
5938 return *((struct config_bool *) record)->variable ? "on" : "off";
5941 snprintf(buffer, sizeof(buffer), "%d",
5942 *((struct config_int *) record)->variable);
5946 snprintf(buffer, sizeof(buffer), "%g",
5947 *((struct config_real *) record)->variable);
5951 return *((struct config_string *) record)->variable;
5954 return config_enum_lookup_by_value((struct config_enum *) record,
5955 *((struct config_enum *) record)->variable);
5961 * Get the RESET value associated with the given option.
5963 * Note: this is not re-entrant, due to use of static result buffer;
5964 * not to mention that a string variable could have its reset_val changed.
5965 * Beware of assuming the result value is good for very long.
5968 GetConfigOptionResetString(const char *name)
5970 struct config_generic *record;
5971 static char buffer[256];
5973 record = find_option(name, false, ERROR);
5976 (errcode(ERRCODE_UNDEFINED_OBJECT),
5977 errmsg("unrecognized configuration parameter \"%s\"", name)));
5978 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
5980 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5981 errmsg("must be superuser to examine \"%s\"", name)));
5983 switch (record->vartype)
5986 return ((struct config_bool *) record)->reset_val ? "on" : "off";
5989 snprintf(buffer, sizeof(buffer), "%d",
5990 ((struct config_int *) record)->reset_val);
5994 snprintf(buffer, sizeof(buffer), "%g",
5995 ((struct config_real *) record)->reset_val);
5999 return ((struct config_string *) record)->reset_val;
6002 return config_enum_lookup_by_value((struct config_enum *) record,
6003 ((struct config_enum *) record)->reset_val);
6010 * flatten_set_variable_args
6011 * Given a parsenode List as emitted by the grammar for SET,
6012 * convert to the flat string representation used by GUC.
6014 * We need to be told the name of the variable the args are for, because
6015 * the flattening rules vary (ugh).
6017 * The result is NULL if args is NIL (ie, SET ... TO DEFAULT), otherwise
6018 * a palloc'd string.
6021 flatten_set_variable_args(const char *name, List *args)
6023 struct config_generic *record;
6028 /* Fast path if just DEFAULT */
6033 * Get flags for the variable; if it's not known, use default flags.
6034 * (Caller might throw error later, but not our business to do so here.)
6036 record = find_option(name, false, WARNING);
6038 flags = record->flags;
6042 /* Complain if list input and non-list variable */
6043 if ((flags & GUC_LIST_INPUT) == 0 &&
6044 list_length(args) != 1)
6046 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6047 errmsg("SET %s takes only one argument", name)));
6049 initStringInfo(&buf);
6052 * Each list member may be a plain A_Const node, or an A_Const within a
6053 * TypeCast; the latter case is supported only for ConstInterval arguments
6054 * (for SET TIME ZONE).
6058 Node *arg = (Node *) lfirst(l);
6060 TypeName *typeName = NULL;
6063 if (l != list_head(args))
6064 appendStringInfo(&buf, ", ");
6066 if (IsA(arg, TypeCast))
6068 TypeCast *tc = (TypeCast *) arg;
6071 typeName = tc->typeName;
6074 if (!IsA(arg, A_Const))
6075 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
6076 con = (A_Const *) arg;
6078 switch (nodeTag(&con->val))
6081 appendStringInfo(&buf, "%ld", intVal(&con->val));
6084 /* represented as a string, so just copy it */
6085 appendStringInfoString(&buf, strVal(&con->val));
6088 val = strVal(&con->val);
6089 if (typeName != NULL)
6092 * Must be a ConstInterval argument for TIME ZONE. Coerce
6093 * to interval and back to normalize the value and account
6101 typenameTypeIdAndMod(NULL, typeName, &typoid, &typmod);
6102 Assert(typoid == INTERVALOID);
6105 DirectFunctionCall3(interval_in,
6106 CStringGetDatum(val),
6107 ObjectIdGetDatum(InvalidOid),
6108 Int32GetDatum(typmod));
6111 DatumGetCString(DirectFunctionCall1(interval_out,
6113 appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
6118 * Plain string literal or identifier. For quote mode,
6119 * quote it if it's not a vanilla identifier.
6121 if (flags & GUC_LIST_QUOTE)
6122 appendStringInfoString(&buf, quote_identifier(val));
6124 appendStringInfoString(&buf, val);
6128 elog(ERROR, "unrecognized node type: %d",
6129 (int) nodeTag(&con->val));
6142 ExecSetVariableStmt(VariableSetStmt *stmt)
6144 GucAction action = stmt->is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET;
6149 case VAR_SET_CURRENT:
6150 (void) set_config_option(stmt->name,
6151 ExtractSetVariableArgs(stmt),
6152 (superuser() ? PGC_SUSET : PGC_USERSET),
6161 * Special-case SQL syntaxes. The TRANSACTION and SESSION
6162 * CHARACTERISTICS cases effectively set more than one variable
6163 * per statement. TRANSACTION SNAPSHOT only takes one argument,
6164 * but we put it here anyway since it's a special case and not
6165 * related to any GUC variable.
6167 if (strcmp(stmt->name, "TRANSACTION") == 0)
6171 foreach(head, stmt->args)
6173 DefElem *item = (DefElem *) lfirst(head);
6175 if (strcmp(item->defname, "transaction_isolation") == 0)
6176 SetPGVariable("transaction_isolation",
6177 list_make1(item->arg), stmt->is_local);
6178 else if (strcmp(item->defname, "transaction_read_only") == 0)
6179 SetPGVariable("transaction_read_only",
6180 list_make1(item->arg), stmt->is_local);
6181 else if (strcmp(item->defname, "transaction_deferrable") == 0)
6182 SetPGVariable("transaction_deferrable",
6183 list_make1(item->arg), stmt->is_local);
6185 elog(ERROR, "unexpected SET TRANSACTION element: %s",
6189 else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
6193 foreach(head, stmt->args)
6195 DefElem *item = (DefElem *) lfirst(head);
6197 if (strcmp(item->defname, "transaction_isolation") == 0)
6198 SetPGVariable("default_transaction_isolation",
6199 list_make1(item->arg), stmt->is_local);
6200 else if (strcmp(item->defname, "transaction_read_only") == 0)
6201 SetPGVariable("default_transaction_read_only",
6202 list_make1(item->arg), stmt->is_local);
6203 else if (strcmp(item->defname, "transaction_deferrable") == 0)
6204 SetPGVariable("default_transaction_deferrable",
6205 list_make1(item->arg), stmt->is_local);
6207 elog(ERROR, "unexpected SET SESSION element: %s",
6211 else if (strcmp(stmt->name, "TRANSACTION SNAPSHOT") == 0)
6213 A_Const *con = (A_Const *) linitial(stmt->args);
6217 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6218 errmsg("SET LOCAL TRANSACTION SNAPSHOT is not implemented")));
6219 Assert(IsA(con, A_Const));
6220 Assert(nodeTag(&con->val) == T_String);
6221 ImportSnapshot(strVal(&con->val));
6224 elog(ERROR, "unexpected SET MULTI element: %s",
6227 case VAR_SET_DEFAULT:
6229 (void) set_config_option(stmt->name,
6231 (superuser() ? PGC_SUSET : PGC_USERSET),
6244 * Get the value to assign for a VariableSetStmt, or NULL if it's RESET.
6245 * The result is palloc'd.
6247 * This is exported for use by actions such as ALTER ROLE SET.
6250 ExtractSetVariableArgs(VariableSetStmt *stmt)
6255 return flatten_set_variable_args(stmt->name, stmt->args);
6256 case VAR_SET_CURRENT:
6257 return GetConfigOptionByName(stmt->name, NULL);
6264 * SetPGVariable - SET command exported as an easily-C-callable function.
6266 * This provides access to SET TO value, as well as SET TO DEFAULT (expressed
6267 * by passing args == NIL), but not SET FROM CURRENT functionality.
6270 SetPGVariable(const char *name, List *args, bool is_local)
6272 char *argstring = flatten_set_variable_args(name, args);
6274 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
6275 (void) set_config_option(name,
6277 (superuser() ? PGC_SUSET : PGC_USERSET),
6279 is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET,
6285 * SET command wrapped as a SQL callable function.
6288 set_config_by_name(PG_FUNCTION_ARGS)
6295 if (PG_ARGISNULL(0))
6297 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
6298 errmsg("SET requires parameter name")));
6300 /* Get the GUC variable name */
6301 name = TextDatumGetCString(PG_GETARG_DATUM(0));
6303 /* Get the desired value or set to NULL for a reset request */
6304 if (PG_ARGISNULL(1))
6307 value = TextDatumGetCString(PG_GETARG_DATUM(1));
6310 * Get the desired state of is_local. Default to false if provided value
6313 if (PG_ARGISNULL(2))
6316 is_local = PG_GETARG_BOOL(2);
6318 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
6319 (void) set_config_option(name,
6321 (superuser() ? PGC_SUSET : PGC_USERSET),
6323 is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET,
6327 /* get the new current value */
6328 new_value = GetConfigOptionByName(name, NULL);
6330 /* Convert return string to text */
6331 PG_RETURN_TEXT_P(cstring_to_text(new_value));
6336 * Common code for DefineCustomXXXVariable subroutines: allocate the
6337 * new variable's config struct and fill in generic fields.
6339 static struct config_generic *
6340 init_custom_variable(const char *name,
6341 const char *short_desc,
6342 const char *long_desc,
6345 enum config_type type,
6348 struct config_generic *gen;
6351 * Only allow custom PGC_POSTMASTER variables to be created during shared
6352 * library preload; any later than that, we can't ensure that the value
6353 * doesn't change after startup. This is a fatal elog if it happens; just
6354 * erroring out isn't safe because we don't know what the calling loadable
6355 * module might already have hooked into.
6357 if (context == PGC_POSTMASTER &&
6358 !process_shared_preload_libraries_in_progress)
6359 elog(FATAL, "cannot create PGC_POSTMASTER variables after startup");
6361 gen = (struct config_generic *) guc_malloc(ERROR, sz);
6364 gen->name = guc_strdup(ERROR, name);
6365 gen->context = context;
6366 gen->group = CUSTOM_OPTIONS;
6367 gen->short_desc = short_desc;
6368 gen->long_desc = long_desc;
6370 gen->vartype = type;
6376 * Common code for DefineCustomXXXVariable subroutines: insert the new
6377 * variable into the GUC variable array, replacing any placeholder.
6380 define_custom_variable(struct config_generic * variable)
6382 const char *name = variable->name;
6383 const char **nameAddr = &name;
6384 struct config_string *pHolder;
6385 struct config_generic **res;
6388 * See if there's a placeholder by the same name.
6390 res = (struct config_generic **) bsearch((void *) &nameAddr,
6391 (void *) guc_variables,
6393 sizeof(struct config_generic *),
6398 * No placeholder to replace, so we can just add it ... but first,
6399 * make sure it's initialized to its default value.
6401 InitializeOneGUCOption(variable);
6402 add_guc_variable(variable, ERROR);
6407 * This better be a placeholder
6409 if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
6411 (errcode(ERRCODE_INTERNAL_ERROR),
6412 errmsg("attempt to redefine parameter \"%s\"", name)));
6414 Assert((*res)->vartype == PGC_STRING);
6415 pHolder = (struct config_string *) (*res);
6418 * First, set the variable to its default value. We must do this even
6419 * though we intend to immediately apply a new value, since it's possible
6420 * that the new value is invalid.
6422 InitializeOneGUCOption(variable);
6425 * Replace the placeholder. We aren't changing the name, so no re-sorting
6431 * Assign the string value(s) stored in the placeholder to the real
6432 * variable. Essentially, we need to duplicate all the active and stacked
6433 * values, but with appropriate validation and datatype adjustment.
6435 * If an assignment fails, we report a WARNING and keep going. We don't
6436 * want to throw ERROR for bad values, because it'd bollix the add-on
6437 * module that's presumably halfway through getting loaded. In such cases
6438 * the default or previous state will become active instead.
6441 /* First, apply the reset value if any */
6442 if (pHolder->reset_val)
6443 (void) set_config_option(name, pHolder->reset_val,
6444 pHolder->gen.reset_scontext,
6445 pHolder->gen.reset_source,
6446 GUC_ACTION_SET, true, WARNING);
6447 /* That should not have resulted in stacking anything */
6448 Assert(variable->stack == NULL);
6450 /* Now, apply current and stacked values, in the order they were stacked */
6451 reapply_stacked_values(variable, pHolder, pHolder->gen.stack,
6452 *(pHolder->variable),
6453 pHolder->gen.scontext, pHolder->gen.source);
6455 /* Also copy over any saved source-location information */
6456 if (pHolder->gen.sourcefile)
6457 set_config_sourcefile(name, pHolder->gen.sourcefile,
6458 pHolder->gen.sourceline);
6461 * Free up as much as we conveniently can of the placeholder structure.
6462 * (This neglects any stack items, so it's possible for some memory to be
6463 * leaked. Since this can only happen once per session per variable, it
6464 * doesn't seem worth spending much code on.)
6466 set_string_field(pHolder, pHolder->variable, NULL);
6467 set_string_field(pHolder, &pHolder->reset_val, NULL);
6473 * Recursive subroutine for define_custom_variable: reapply non-reset values
6475 * We recurse so that the values are applied in the same order as originally.
6476 * At each recursion level, apply the upper-level value (passed in) in the
6477 * fashion implied by the stack entry.
6480 reapply_stacked_values(struct config_generic * variable,
6481 struct config_string *pHolder,
6483 const char *curvalue,
6484 GucContext curscontext, GucSource cursource)
6486 const char *name = variable->name;
6487 GucStack *oldvarstack = variable->stack;
6491 /* First, recurse, so that stack items are processed bottom to top */
6492 reapply_stacked_values(variable, pHolder, stack->prev,
6493 stack->prior.val.stringval,
6494 stack->scontext, stack->source);
6496 /* See how to apply the passed-in value */
6497 switch (stack->state)
6500 (void) set_config_option(name, curvalue,
6501 curscontext, cursource,
6502 GUC_ACTION_SAVE, true, WARNING);
6506 (void) set_config_option(name, curvalue,
6507 curscontext, cursource,
6508 GUC_ACTION_SET, true, WARNING);
6512 (void) set_config_option(name, curvalue,
6513 curscontext, cursource,
6514 GUC_ACTION_LOCAL, true, WARNING);
6518 /* first, apply the masked value as SET */
6519 (void) set_config_option(name, stack->masked.val.stringval,
6520 stack->masked_scontext, PGC_S_SESSION,
6521 GUC_ACTION_SET, true, WARNING);
6522 /* then apply the current value as LOCAL */
6523 (void) set_config_option(name, curvalue,
6524 curscontext, cursource,
6525 GUC_ACTION_LOCAL, true, WARNING);
6529 /* If we successfully made a stack entry, adjust its nest level */
6530 if (variable->stack != oldvarstack)
6531 variable->stack->nest_level = stack->nest_level;
6536 * We are at the end of the stack. If the active/previous value is
6537 * different from the reset value, it must represent a previously
6538 * committed session value. Apply it, and then drop the stack entry
6539 * that set_config_option will have created under the impression that
6540 * this is to be just a transactional assignment. (We leak the stack
6543 if (curvalue != pHolder->reset_val ||
6544 curscontext != pHolder->gen.reset_scontext ||
6545 cursource != pHolder->gen.reset_source)
6547 (void) set_config_option(name, curvalue,
6548 curscontext, cursource,
6549 GUC_ACTION_SET, true, WARNING);
6550 variable->stack = NULL;
6556 DefineCustomBoolVariable(const char *name,
6557 const char *short_desc,
6558 const char *long_desc,
6563 GucBoolCheckHook check_hook,
6564 GucBoolAssignHook assign_hook,
6565 GucShowHook show_hook)
6567 struct config_bool *var;
6569 var = (struct config_bool *)
6570 init_custom_variable(name, short_desc, long_desc, context, flags,
6571 PGC_BOOL, sizeof(struct config_bool));
6572 var->variable = valueAddr;
6573 var->boot_val = bootValue;
6574 var->reset_val = bootValue;
6575 var->check_hook = check_hook;
6576 var->assign_hook = assign_hook;
6577 var->show_hook = show_hook;
6578 define_custom_variable(&var->gen);
6582 DefineCustomIntVariable(const char *name,
6583 const char *short_desc,
6584 const char *long_desc,
6591 GucIntCheckHook check_hook,
6592 GucIntAssignHook assign_hook,
6593 GucShowHook show_hook)
6595 struct config_int *var;
6597 var = (struct config_int *)
6598 init_custom_variable(name, short_desc, long_desc, context, flags,
6599 PGC_INT, sizeof(struct config_int));
6600 var->variable = valueAddr;
6601 var->boot_val = bootValue;
6602 var->reset_val = bootValue;
6603 var->min = minValue;
6604 var->max = maxValue;
6605 var->check_hook = check_hook;
6606 var->assign_hook = assign_hook;
6607 var->show_hook = show_hook;
6608 define_custom_variable(&var->gen);
6612 DefineCustomRealVariable(const char *name,
6613 const char *short_desc,
6614 const char *long_desc,
6621 GucRealCheckHook check_hook,
6622 GucRealAssignHook assign_hook,
6623 GucShowHook show_hook)
6625 struct config_real *var;
6627 var = (struct config_real *)
6628 init_custom_variable(name, short_desc, long_desc, context, flags,
6629 PGC_REAL, sizeof(struct config_real));
6630 var->variable = valueAddr;
6631 var->boot_val = bootValue;
6632 var->reset_val = bootValue;
6633 var->min = minValue;
6634 var->max = maxValue;
6635 var->check_hook = check_hook;
6636 var->assign_hook = assign_hook;
6637 var->show_hook = show_hook;
6638 define_custom_variable(&var->gen);
6642 DefineCustomStringVariable(const char *name,
6643 const char *short_desc,
6644 const char *long_desc,
6646 const char *bootValue,
6649 GucStringCheckHook check_hook,
6650 GucStringAssignHook assign_hook,
6651 GucShowHook show_hook)
6653 struct config_string *var;
6655 var = (struct config_string *)
6656 init_custom_variable(name, short_desc, long_desc, context, flags,
6657 PGC_STRING, sizeof(struct config_string));
6658 var->variable = valueAddr;
6659 var->boot_val = bootValue;
6660 var->check_hook = check_hook;
6661 var->assign_hook = assign_hook;
6662 var->show_hook = show_hook;
6663 define_custom_variable(&var->gen);
6667 DefineCustomEnumVariable(const char *name,
6668 const char *short_desc,
6669 const char *long_desc,
6672 const struct config_enum_entry * options,
6675 GucEnumCheckHook check_hook,
6676 GucEnumAssignHook assign_hook,
6677 GucShowHook show_hook)
6679 struct config_enum *var;
6681 var = (struct config_enum *)
6682 init_custom_variable(name, short_desc, long_desc, context, flags,
6683 PGC_ENUM, sizeof(struct config_enum));
6684 var->variable = valueAddr;
6685 var->boot_val = bootValue;
6686 var->reset_val = bootValue;
6687 var->options = options;
6688 var->check_hook = check_hook;
6689 var->assign_hook = assign_hook;
6690 var->show_hook = show_hook;
6691 define_custom_variable(&var->gen);
6695 EmitWarningsOnPlaceholders(const char *className)
6697 int classLen = strlen(className);
6700 for (i = 0; i < num_guc_variables; i++)
6702 struct config_generic *var = guc_variables[i];
6704 if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
6705 strncmp(className, var->name, classLen) == 0 &&
6706 var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
6709 (errcode(ERRCODE_UNDEFINED_OBJECT),
6710 errmsg("unrecognized configuration parameter \"%s\"",
6721 GetPGVariable(const char *name, DestReceiver *dest)
6723 if (guc_name_compare(name, "all") == 0)
6724 ShowAllGUCConfig(dest);
6726 ShowGUCConfigOption(name, dest);
6730 GetPGVariableResultDesc(const char *name)
6734 if (guc_name_compare(name, "all") == 0)
6736 /* need a tuple descriptor representing three TEXT columns */
6737 tupdesc = CreateTemplateTupleDesc(3, false);
6738 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
6740 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
6742 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
6747 const char *varname;
6749 /* Get the canonical spelling of name */
6750 (void) GetConfigOptionByName(name, &varname);
6752 /* need a tuple descriptor representing a single TEXT column */
6753 tupdesc = CreateTemplateTupleDesc(1, false);
6754 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
6765 ShowGUCConfigOption(const char *name, DestReceiver *dest)
6767 TupOutputState *tstate;
6769 const char *varname;
6772 /* Get the value and canonical spelling of name */
6773 value = GetConfigOptionByName(name, &varname);
6775 /* need a tuple descriptor representing a single TEXT column */
6776 tupdesc = CreateTemplateTupleDesc(1, false);
6777 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
6780 /* prepare for projection of tuples */
6781 tstate = begin_tup_output_tupdesc(dest, tupdesc);
6784 do_text_output_oneline(tstate, value);
6786 end_tup_output(tstate);
6793 ShowAllGUCConfig(DestReceiver *dest)
6795 bool am_superuser = superuser();
6797 TupOutputState *tstate;
6800 bool isnull[3] = {false, false, false};
6802 /* need a tuple descriptor representing three TEXT columns */
6803 tupdesc = CreateTemplateTupleDesc(3, false);
6804 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
6806 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
6808 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
6811 /* prepare for projection of tuples */
6812 tstate = begin_tup_output_tupdesc(dest, tupdesc);
6814 for (i = 0; i < num_guc_variables; i++)
6816 struct config_generic *conf = guc_variables[i];
6819 if ((conf->flags & GUC_NO_SHOW_ALL) ||
6820 ((conf->flags & GUC_SUPERUSER_ONLY) && !am_superuser))
6823 /* assign to the values array */
6824 values[0] = PointerGetDatum(cstring_to_text(conf->name));
6826 setting = _ShowOption(conf, true);
6829 values[1] = PointerGetDatum(cstring_to_text(setting));
6834 values[1] = PointerGetDatum(NULL);
6838 values[2] = PointerGetDatum(cstring_to_text(conf->short_desc));
6840 /* send it to dest */
6841 do_tup_output(tstate, values, isnull);
6844 pfree(DatumGetPointer(values[0]));
6848 pfree(DatumGetPointer(values[1]));
6850 pfree(DatumGetPointer(values[2]));
6853 end_tup_output(tstate);
6857 * Return GUC variable value by name; optionally return canonical
6858 * form of name. Return value is palloc'd.
6861 GetConfigOptionByName(const char *name, const char **varname)
6863 struct config_generic *record;
6865 record = find_option(name, false, ERROR);
6868 (errcode(ERRCODE_UNDEFINED_OBJECT),
6869 errmsg("unrecognized configuration parameter \"%s\"", name)));
6870 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
6872 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6873 errmsg("must be superuser to examine \"%s\"", name)));
6876 *varname = record->name;
6878 return _ShowOption(record, true);
6882 * Return GUC variable value by variable number; optionally return canonical
6883 * form of name. Return value is palloc'd.
6886 GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
6889 struct config_generic *conf;
6891 /* check requested variable number valid */
6892 Assert((varnum >= 0) && (varnum < num_guc_variables));
6894 conf = guc_variables[varnum];
6898 if ((conf->flags & GUC_NO_SHOW_ALL) ||
6899 ((conf->flags & GUC_SUPERUSER_ONLY) && !superuser()))
6905 /* first get the generic attributes */
6908 values[0] = conf->name;
6910 /* setting : use _ShowOption in order to avoid duplicating the logic */
6911 values[1] = _ShowOption(conf, false);
6914 if (conf->vartype == PGC_INT)
6918 switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
6923 case GUC_UNIT_BLOCKS:
6924 snprintf(buf, sizeof(buf), "%dkB", BLCKSZ / 1024);
6927 case GUC_UNIT_XBLOCKS:
6928 snprintf(buf, sizeof(buf), "%dkB", XLOG_BLCKSZ / 1024);
6949 values[3] = config_group_names[conf->group];
6952 values[4] = conf->short_desc;
6955 values[5] = conf->long_desc;
6958 values[6] = GucContext_Names[conf->context];
6961 values[7] = config_type_names[conf->vartype];
6964 values[8] = GucSource_Names[conf->source];
6966 /* now get the type specifc attributes */
6967 switch (conf->vartype)
6971 struct config_bool *lconf = (struct config_bool *) conf;
6983 values[12] = pstrdup(lconf->boot_val ? "on" : "off");
6986 values[13] = pstrdup(lconf->reset_val ? "on" : "off");
6992 struct config_int *lconf = (struct config_int *) conf;
6995 snprintf(buffer, sizeof(buffer), "%d", lconf->min);
6996 values[9] = pstrdup(buffer);
6999 snprintf(buffer, sizeof(buffer), "%d", lconf->max);
7000 values[10] = pstrdup(buffer);
7006 snprintf(buffer, sizeof(buffer), "%d", lconf->boot_val);
7007 values[12] = pstrdup(buffer);
7010 snprintf(buffer, sizeof(buffer), "%d", lconf->reset_val);
7011 values[13] = pstrdup(buffer);
7017 struct config_real *lconf = (struct config_real *) conf;
7020 snprintf(buffer, sizeof(buffer), "%g", lconf->min);
7021 values[9] = pstrdup(buffer);
7024 snprintf(buffer, sizeof(buffer), "%g", lconf->max);
7025 values[10] = pstrdup(buffer);
7031 snprintf(buffer, sizeof(buffer), "%g", lconf->boot_val);
7032 values[12] = pstrdup(buffer);
7035 snprintf(buffer, sizeof(buffer), "%g", lconf->reset_val);
7036 values[13] = pstrdup(buffer);
7042 struct config_string *lconf = (struct config_string *) conf;
7054 if (lconf->boot_val == NULL)
7057 values[12] = pstrdup(lconf->boot_val);
7060 if (lconf->reset_val == NULL)
7063 values[13] = pstrdup(lconf->reset_val);
7069 struct config_enum *lconf = (struct config_enum *) conf;
7080 * NOTE! enumvals with double quotes in them are not
7083 values[11] = config_enum_get_options((struct config_enum *) conf,
7084 "{\"", "\"}", "\",\"");
7087 values[12] = pstrdup(config_enum_lookup_by_value(lconf,
7091 values[13] = pstrdup(config_enum_lookup_by_value(lconf,
7099 * should never get here, but in case we do, set 'em to NULL
7121 * If the setting came from a config file, set the source location. For
7122 * security reasons, we don't show source file/line number for
7125 if (conf->source == PGC_S_FILE && superuser())
7127 values[14] = conf->sourcefile;
7128 snprintf(buffer, sizeof(buffer), "%d", conf->sourceline);
7129 values[15] = pstrdup(buffer);
7139 * Return the total number of GUC variables
7142 GetNumConfigOptions(void)
7144 return num_guc_variables;
7148 * show_config_by_name - equiv to SHOW X command but implemented as
7152 show_config_by_name(PG_FUNCTION_ARGS)
7157 /* Get the GUC variable name */
7158 varname = TextDatumGetCString(PG_GETARG_DATUM(0));
7161 varval = GetConfigOptionByName(varname, NULL);
7163 /* Convert to text */
7164 PG_RETURN_TEXT_P(cstring_to_text(varval));
7168 * show_all_settings - equiv to SHOW ALL command but implemented as
7171 #define NUM_PG_SETTINGS_ATTS 16
7174 show_all_settings(PG_FUNCTION_ARGS)
7176 FuncCallContext *funcctx;
7180 AttInMetadata *attinmeta;
7181 MemoryContext oldcontext;
7183 /* stuff done only on the first call of the function */
7184 if (SRF_IS_FIRSTCALL())
7186 /* create a function context for cross-call persistence */
7187 funcctx = SRF_FIRSTCALL_INIT();
7190 * switch to memory context appropriate for multiple function calls
7192 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
7195 * need a tuple descriptor representing NUM_PG_SETTINGS_ATTS columns
7196 * of the appropriate types
7198 tupdesc = CreateTemplateTupleDesc(NUM_PG_SETTINGS_ATTS, false);
7199 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
7201 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
7203 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "unit",
7205 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "category",
7207 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "short_desc",
7209 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "extra_desc",
7211 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "context",
7213 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "vartype",
7215 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "source",
7217 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "min_val",
7219 TupleDescInitEntry(tupdesc, (AttrNumber) 11, "max_val",
7221 TupleDescInitEntry(tupdesc, (AttrNumber) 12, "enumvals",
7222 TEXTARRAYOID, -1, 0);
7223 TupleDescInitEntry(tupdesc, (AttrNumber) 13, "boot_val",
7225 TupleDescInitEntry(tupdesc, (AttrNumber) 14, "reset_val",
7227 TupleDescInitEntry(tupdesc, (AttrNumber) 15, "sourcefile",
7229 TupleDescInitEntry(tupdesc, (AttrNumber) 16, "sourceline",
7233 * Generate attribute metadata needed later to produce tuples from raw
7236 attinmeta = TupleDescGetAttInMetadata(tupdesc);
7237 funcctx->attinmeta = attinmeta;
7239 /* total number of tuples to be returned */
7240 funcctx->max_calls = GetNumConfigOptions();
7242 MemoryContextSwitchTo(oldcontext);
7245 /* stuff done on every call of the function */
7246 funcctx = SRF_PERCALL_SETUP();
7248 call_cntr = funcctx->call_cntr;
7249 max_calls = funcctx->max_calls;
7250 attinmeta = funcctx->attinmeta;
7252 if (call_cntr < max_calls) /* do when there is more left to send */
7254 char *values[NUM_PG_SETTINGS_ATTS];
7260 * Get the next visible GUC variable name and value
7264 GetConfigOptionByNum(call_cntr, (const char **) values, &noshow);
7267 /* bump the counter and get the next config setting */
7268 call_cntr = ++funcctx->call_cntr;
7270 /* make sure we haven't gone too far now */
7271 if (call_cntr >= max_calls)
7272 SRF_RETURN_DONE(funcctx);
7277 tuple = BuildTupleFromCStrings(attinmeta, values);
7279 /* make the tuple into a datum */
7280 result = HeapTupleGetDatum(tuple);
7282 SRF_RETURN_NEXT(funcctx, result);
7286 /* do when there is no more left */
7287 SRF_RETURN_DONE(funcctx);
7292 _ShowOption(struct config_generic * record, bool use_units)
7297 switch (record->vartype)
7301 struct config_bool *conf = (struct config_bool *) record;
7303 if (conf->show_hook)
7304 val = (*conf->show_hook) ();
7306 val = *conf->variable ? "on" : "off";
7312 struct config_int *conf = (struct config_int *) record;
7314 if (conf->show_hook)
7315 val = (*conf->show_hook) ();
7319 * Use int64 arithmetic to avoid overflows in units
7322 int64 result = *conf->variable;
7325 if (use_units && result > 0 &&
7326 (record->flags & GUC_UNIT_MEMORY))
7328 switch (record->flags & GUC_UNIT_MEMORY)
7330 case GUC_UNIT_BLOCKS:
7331 result *= BLCKSZ / 1024;
7333 case GUC_UNIT_XBLOCKS:
7334 result *= XLOG_BLCKSZ / 1024;
7338 if (result % KB_PER_GB == 0)
7340 result /= KB_PER_GB;
7343 else if (result % KB_PER_MB == 0)
7345 result /= KB_PER_MB;
7353 else if (use_units && result > 0 &&
7354 (record->flags & GUC_UNIT_TIME))
7356 switch (record->flags & GUC_UNIT_TIME)
7362 result *= MS_PER_MIN;
7366 if (result % MS_PER_D == 0)
7371 else if (result % MS_PER_H == 0)
7376 else if (result % MS_PER_MIN == 0)
7378 result /= MS_PER_MIN;
7381 else if (result % MS_PER_S == 0)
7394 snprintf(buffer, sizeof(buffer), INT64_FORMAT "%s",
7403 struct config_real *conf = (struct config_real *) record;
7405 if (conf->show_hook)
7406 val = (*conf->show_hook) ();
7409 snprintf(buffer, sizeof(buffer), "%g",
7418 struct config_string *conf = (struct config_string *) record;
7420 if (conf->show_hook)
7421 val = (*conf->show_hook) ();
7422 else if (*conf->variable && **conf->variable)
7423 val = *conf->variable;
7431 struct config_enum *conf = (struct config_enum *) record;
7433 if (conf->show_hook)
7434 val = (*conf->show_hook) ();
7436 val = config_enum_lookup_by_value(conf, *conf->variable);
7441 /* just to keep compiler quiet */
7446 return pstrdup(val);
7453 * These routines dump out all non-default GUC options into a binary
7454 * file that is read by all exec'ed backends. The format is:
7456 * variable name, string, null terminated
7457 * variable value, string, null terminated
7458 * variable sourcefile, string, null terminated (empty if none)
7459 * variable sourceline, integer
7460 * variable source, integer
7461 * variable scontext, integer
7464 write_one_nondefault_variable(FILE *fp, struct config_generic * gconf)
7466 if (gconf->source == PGC_S_DEFAULT)
7469 fprintf(fp, "%s", gconf->name);
7472 switch (gconf->vartype)
7476 struct config_bool *conf = (struct config_bool *) gconf;
7478 if (*conf->variable)
7479 fprintf(fp, "true");
7481 fprintf(fp, "false");
7487 struct config_int *conf = (struct config_int *) gconf;
7489 fprintf(fp, "%d", *conf->variable);
7495 struct config_real *conf = (struct config_real *) gconf;
7497 fprintf(fp, "%.17g", *conf->variable);
7503 struct config_string *conf = (struct config_string *) gconf;
7505 fprintf(fp, "%s", *conf->variable);
7511 struct config_enum *conf = (struct config_enum *) gconf;
7514 config_enum_lookup_by_value(conf, *conf->variable));
7521 if (gconf->sourcefile)
7522 fprintf(fp, "%s", gconf->sourcefile);
7525 fwrite(&gconf->sourceline, 1, sizeof(gconf->sourceline), fp);
7526 fwrite(&gconf->source, 1, sizeof(gconf->source), fp);
7527 fwrite(&gconf->scontext, 1, sizeof(gconf->scontext), fp);
7531 write_nondefault_variables(GucContext context)
7537 Assert(context == PGC_POSTMASTER || context == PGC_SIGHUP);
7539 elevel = (context == PGC_SIGHUP) ? LOG : ERROR;
7544 fp = AllocateFile(CONFIG_EXEC_PARAMS_NEW, "w");
7548 (errcode_for_file_access(),
7549 errmsg("could not write to file \"%s\": %m",
7550 CONFIG_EXEC_PARAMS_NEW)));
7554 for (i = 0; i < num_guc_variables; i++)
7556 write_one_nondefault_variable(fp, guc_variables[i]);
7562 (errcode_for_file_access(),
7563 errmsg("could not write to file \"%s\": %m",
7564 CONFIG_EXEC_PARAMS_NEW)));
7569 * Put new file in place. This could delay on Win32, but we don't hold
7570 * any exclusive locks.
7572 rename(CONFIG_EXEC_PARAMS_NEW, CONFIG_EXEC_PARAMS);
7577 * Read string, including null byte from file
7579 * Return NULL on EOF and nothing read
7582 read_string_with_null(FILE *fp)
7591 if ((ch = fgetc(fp)) == EOF)
7596 elog(FATAL, "invalid format of exec config params file");
7599 str = guc_malloc(FATAL, maxlen);
7600 else if (i == maxlen)
7601 str = guc_realloc(FATAL, str, maxlen *= 2);
7610 * This routine loads a previous postmaster dump of its non-default
7614 read_nondefault_variables(void)
7621 GucSource varsource;
7622 GucContext varscontext;
7627 fp = AllocateFile(CONFIG_EXEC_PARAMS, "r");
7630 /* File not found is fine */
7631 if (errno != ENOENT)
7633 (errcode_for_file_access(),
7634 errmsg("could not read from file \"%s\": %m",
7635 CONFIG_EXEC_PARAMS)));
7641 struct config_generic *record;
7643 if ((varname = read_string_with_null(fp)) == NULL)
7646 if ((record = find_option(varname, true, FATAL)) == NULL)
7647 elog(FATAL, "failed to locate variable \"%s\" in exec config params file", varname);
7649 if ((varvalue = read_string_with_null(fp)) == NULL)
7650 elog(FATAL, "invalid format of exec config params file");
7651 if ((varsourcefile = read_string_with_null(fp)) == NULL)
7652 elog(FATAL, "invalid format of exec config params file");
7653 if (fread(&varsourceline, 1, sizeof(varsourceline), fp) != sizeof(varsourceline))
7654 elog(FATAL, "invalid format of exec config params file");
7655 if (fread(&varsource, 1, sizeof(varsource), fp) != sizeof(varsource))
7656 elog(FATAL, "invalid format of exec config params file");
7657 if (fread(&varscontext, 1, sizeof(varscontext), fp) != sizeof(varscontext))
7658 elog(FATAL, "invalid format of exec config params file");
7660 (void) set_config_option(varname, varvalue,
7661 varscontext, varsource,
7662 GUC_ACTION_SET, true, 0);
7663 if (varsourcefile[0])
7664 set_config_sourcefile(varname, varsourcefile, varsourceline);
7668 free(varsourcefile);
7673 #endif /* EXEC_BACKEND */
7677 * A little "long argument" simulation, although not quite GNU
7678 * compliant. Takes a string of the form "some-option=some value" and
7679 * returns name = "some_option" and value = "some value" in malloc'ed
7680 * storage. Note that '-' is converted to '_' in the option name. If
7681 * there is no '=' in the input string then value will be NULL.
7684 ParseLongOption(const char *string, char **name, char **value)
7693 equal_pos = strcspn(string, "=");
7695 if (string[equal_pos] == '=')
7697 *name = guc_malloc(FATAL, equal_pos + 1);
7698 strlcpy(*name, string, equal_pos + 1);
7700 *value = guc_strdup(FATAL, &string[equal_pos + 1]);
7704 /* no equal sign in string */
7705 *name = guc_strdup(FATAL, string);
7709 for (cp = *name; *cp; cp++)
7716 * Handle options fetched from pg_db_role_setting.setconfig,
7717 * pg_proc.proconfig, etc. Caller must specify proper context/source/action.
7719 * The array parameter must be an array of TEXT (it must not be NULL).
7722 ProcessGUCArray(ArrayType *array,
7723 GucContext context, GucSource source, GucAction action)
7727 Assert(array != NULL);
7728 Assert(ARR_ELEMTYPE(array) == TEXTOID);
7729 Assert(ARR_NDIM(array) == 1);
7730 Assert(ARR_LBOUND(array)[0] == 1);
7732 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 */ ,
7750 s = TextDatumGetCString(d);
7752 ParseLongOption(s, &name, &value);
7756 (errcode(ERRCODE_SYNTAX_ERROR),
7757 errmsg("could not parse setting for parameter \"%s\"",
7763 (void) set_config_option(name, value,
7776 * Add an entry to an option array. The array parameter may be NULL
7777 * to indicate the current table entry is NULL.
7780 GUCArrayAdd(ArrayType *array, const char *name, const char *value)
7782 struct config_generic *record;
7790 /* test if the option is valid and we're allowed to set it */
7791 (void) validate_option_array_item(name, value, false);
7793 /* normalize name (converts obsolete GUC names to modern spellings) */
7794 record = find_option(name, false, WARNING);
7796 name = record->name;
7798 /* build new item for array */
7799 newval = palloc(strlen(name) + 1 + strlen(value) + 1);
7800 sprintf(newval, "%s=%s", name, value);
7801 datum = CStringGetTextDatum(newval);
7809 Assert(ARR_ELEMTYPE(array) == TEXTOID);
7810 Assert(ARR_NDIM(array) == 1);
7811 Assert(ARR_LBOUND(array)[0] == 1);
7813 index = ARR_DIMS(array)[0] + 1; /* add after end */
7815 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
7820 d = array_ref(array, 1, &i,
7821 -1 /* varlenarray */ ,
7822 -1 /* TEXT's typlen */ ,
7823 false /* TEXT's typbyval */ ,
7824 'i' /* TEXT's typalign */ ,
7828 current = TextDatumGetCString(d);
7830 /* check for match up through and including '=' */
7831 if (strncmp(current, newval, strlen(name) + 1) == 0)
7838 a = array_set(array, 1, &index,
7841 -1 /* varlena array */ ,
7842 -1 /* TEXT's typlen */ ,
7843 false /* TEXT's typbyval */ ,
7844 'i' /* TEXT's typalign */ );
7847 a = construct_array(&datum, 1,
7856 * Delete an entry from an option array. The array parameter may be NULL
7857 * to indicate the current table entry is NULL. Also, if the return value
7858 * is NULL then a null should be stored.
7861 GUCArrayDelete(ArrayType *array, const char *name)
7863 struct config_generic *record;
7864 ArrayType *newarray;
7870 /* test if the option is valid and we're allowed to set it */
7871 (void) validate_option_array_item(name, NULL, false);
7873 /* normalize name (converts obsolete GUC names to modern spellings) */
7874 record = find_option(name, false, WARNING);
7876 name = record->name;
7878 /* if array is currently null, then surely nothing to delete */
7885 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
7891 d = array_ref(array, 1, &i,
7892 -1 /* varlenarray */ ,
7893 -1 /* TEXT's typlen */ ,
7894 false /* TEXT's typbyval */ ,
7895 'i' /* TEXT's typalign */ ,
7899 val = TextDatumGetCString(d);
7901 /* ignore entry if it's what we want to delete */
7902 if (strncmp(val, name, strlen(name)) == 0
7903 && val[strlen(name)] == '=')
7906 /* else add it to the output array */
7908 newarray = array_set(newarray, 1, &index,
7911 -1 /* varlenarray */ ,
7912 -1 /* TEXT's typlen */ ,
7913 false /* TEXT's typbyval */ ,
7914 'i' /* TEXT's typalign */ );
7916 newarray = construct_array(&d, 1,
7928 * Given a GUC array, delete all settings from it that our permission
7929 * level allows: if superuser, delete them all; if regular user, only
7930 * those that are PGC_USERSET
7933 GUCArrayReset(ArrayType *array)
7935 ArrayType *newarray;
7939 /* if array is currently null, nothing to do */
7943 /* if we're superuser, we can delete everything, so just do it */
7950 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
7957 d = array_ref(array, 1, &i,
7958 -1 /* varlenarray */ ,
7959 -1 /* TEXT's typlen */ ,
7960 false /* TEXT's typbyval */ ,
7961 'i' /* TEXT's typalign */ ,
7965 val = TextDatumGetCString(d);
7967 eqsgn = strchr(val, '=');
7970 /* skip if we have permission to delete it */
7971 if (validate_option_array_item(val, NULL, true))
7974 /* else add it to the output array */
7976 newarray = array_set(newarray, 1, &index,
7979 -1 /* varlenarray */ ,
7980 -1 /* TEXT's typlen */ ,
7981 false /* TEXT's typbyval */ ,
7982 'i' /* TEXT's typalign */ );
7984 newarray = construct_array(&d, 1,
7996 * Validate a proposed option setting for GUCArrayAdd/Delete/Reset.
7998 * name is the option name. value is the proposed value for the Add case,
7999 * or NULL for the Delete/Reset cases. If skipIfNoPermissions is true, it's
8000 * not an error to have no permissions to set the option.
8002 * Returns TRUE if OK, FALSE if skipIfNoPermissions is true and user does not
8003 * have permission to change this option (all other error cases result in an
8004 * error being thrown).
8007 validate_option_array_item(const char *name, const char *value,
8008 bool skipIfNoPermissions)
8011 struct config_generic *gconf;
8014 * There are three cases to consider:
8016 * name is a known GUC variable. Check the value normally, check
8017 * permissions normally (ie, allow if variable is USERSET, or if it's
8018 * SUSET and user is superuser).
8020 * name is not known, but exists or can be created as a placeholder (i.e.,
8021 * it has a prefixed name). We allow this case if you're a superuser,
8022 * otherwise not. Superusers are assumed to know what they're doing.
8023 * We can't allow it for other users, because when the placeholder is
8024 * resolved it might turn out to be a SUSET variable;
8025 * define_custom_variable assumes we checked that.
8027 * name is not known and can't be created as a placeholder. Throw error,
8028 * unless skipIfNoPermissions is true, in which case return FALSE.
8030 gconf = find_option(name, true, WARNING);
8033 /* not known, failed to make a placeholder */
8034 if (skipIfNoPermissions)
8037 (errcode(ERRCODE_UNDEFINED_OBJECT),
8038 errmsg("unrecognized configuration parameter \"%s\"",
8042 if (gconf->flags & GUC_CUSTOM_PLACEHOLDER)
8045 * We cannot do any meaningful check on the value, so only permissions
8046 * are useful to check.
8050 if (skipIfNoPermissions)
8053 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
8054 errmsg("permission denied to set parameter \"%s\"", name)));
8057 /* manual permissions check so we can avoid an error being thrown */
8058 if (gconf->context == PGC_USERSET)
8060 else if (gconf->context == PGC_SUSET && superuser())
8062 else if (skipIfNoPermissions)
8064 /* if a permissions error should be thrown, let set_config_option do it */
8066 /* test for permissions and valid option value */
8067 (void) set_config_option(name, value,
8068 superuser() ? PGC_SUSET : PGC_USERSET,
8069 PGC_S_TEST, GUC_ACTION_SET, false, 0);
8076 * Called by check_hooks that want to override the normal
8077 * ERRCODE_INVALID_PARAMETER_VALUE SQLSTATE for check hook failures.
8079 * Note that GUC_check_errmsg() etc are just macros that result in a direct
8080 * assignment to the associated variables. That is ugly, but forced by the
8081 * limitations of C's macro mechanisms.
8084 GUC_check_errcode(int sqlerrcode)
8086 GUC_check_errcode_value = sqlerrcode;
8091 * Convenience functions to manage calling a variable's check_hook.
8092 * These mostly take care of the protocol for letting check hooks supply
8093 * portions of the error report on failure.
8097 call_bool_check_hook(struct config_bool * conf, bool *newval, void **extra,
8098 GucSource source, int elevel)
8100 /* Quick success if no hook */
8101 if (!conf->check_hook)
8104 /* Reset variables that might be set by hook */
8105 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8106 GUC_check_errmsg_string = NULL;
8107 GUC_check_errdetail_string = NULL;
8108 GUC_check_errhint_string = NULL;
8110 if (!(*conf->check_hook) (newval, extra, source))
8113 (errcode(GUC_check_errcode_value),
8114 GUC_check_errmsg_string ?
8115 errmsg_internal("%s", GUC_check_errmsg_string) :
8116 errmsg("invalid value for parameter \"%s\": %d",
8117 conf->gen.name, (int) *newval),
8118 GUC_check_errdetail_string ?
8119 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
8120 GUC_check_errhint_string ?
8121 errhint("%s", GUC_check_errhint_string) : 0));
8122 /* Flush any strings created in ErrorContext */
8131 call_int_check_hook(struct config_int * conf, int *newval, void **extra,
8132 GucSource source, int elevel)
8134 /* Quick success if no hook */
8135 if (!conf->check_hook)
8138 /* Reset variables that might be set by hook */
8139 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8140 GUC_check_errmsg_string = NULL;
8141 GUC_check_errdetail_string = NULL;
8142 GUC_check_errhint_string = NULL;
8144 if (!(*conf->check_hook) (newval, extra, source))
8147 (errcode(GUC_check_errcode_value),
8148 GUC_check_errmsg_string ?
8149 errmsg_internal("%s", GUC_check_errmsg_string) :
8150 errmsg("invalid value for parameter \"%s\": %d",
8151 conf->gen.name, *newval),
8152 GUC_check_errdetail_string ?
8153 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
8154 GUC_check_errhint_string ?
8155 errhint("%s", GUC_check_errhint_string) : 0));
8156 /* Flush any strings created in ErrorContext */
8165 call_real_check_hook(struct config_real * conf, double *newval, void **extra,
8166 GucSource source, int elevel)
8168 /* Quick success if no hook */
8169 if (!conf->check_hook)
8172 /* Reset variables that might be set by hook */
8173 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8174 GUC_check_errmsg_string = NULL;
8175 GUC_check_errdetail_string = NULL;
8176 GUC_check_errhint_string = NULL;
8178 if (!(*conf->check_hook) (newval, extra, source))
8181 (errcode(GUC_check_errcode_value),
8182 GUC_check_errmsg_string ?
8183 errmsg_internal("%s", GUC_check_errmsg_string) :
8184 errmsg("invalid value for parameter \"%s\": %g",
8185 conf->gen.name, *newval),
8186 GUC_check_errdetail_string ?
8187 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
8188 GUC_check_errhint_string ?
8189 errhint("%s", GUC_check_errhint_string) : 0));
8190 /* Flush any strings created in ErrorContext */
8199 call_string_check_hook(struct config_string * conf, char **newval, void **extra,
8200 GucSource source, int elevel)
8202 /* Quick success if no hook */
8203 if (!conf->check_hook)
8206 /* Reset variables that might be set by hook */
8207 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8208 GUC_check_errmsg_string = NULL;
8209 GUC_check_errdetail_string = NULL;
8210 GUC_check_errhint_string = NULL;
8212 if (!(*conf->check_hook) (newval, extra, source))
8215 (errcode(GUC_check_errcode_value),
8216 GUC_check_errmsg_string ?
8217 errmsg_internal("%s", GUC_check_errmsg_string) :
8218 errmsg("invalid value for parameter \"%s\": \"%s\"",
8219 conf->gen.name, *newval ? *newval : ""),
8220 GUC_check_errdetail_string ?
8221 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
8222 GUC_check_errhint_string ?
8223 errhint("%s", GUC_check_errhint_string) : 0));
8224 /* Flush any strings created in ErrorContext */
8233 call_enum_check_hook(struct config_enum * conf, int *newval, void **extra,
8234 GucSource source, int elevel)
8236 /* Quick success if no hook */
8237 if (!conf->check_hook)
8240 /* Reset variables that might be set by hook */
8241 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8242 GUC_check_errmsg_string = NULL;
8243 GUC_check_errdetail_string = NULL;
8244 GUC_check_errhint_string = NULL;
8246 if (!(*conf->check_hook) (newval, extra, source))
8249 (errcode(GUC_check_errcode_value),
8250 GUC_check_errmsg_string ?
8251 errmsg_internal("%s", GUC_check_errmsg_string) :
8252 errmsg("invalid value for parameter \"%s\": \"%s\"",
8254 config_enum_lookup_by_value(conf, *newval)),
8255 GUC_check_errdetail_string ?
8256 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
8257 GUC_check_errhint_string ?
8258 errhint("%s", GUC_check_errhint_string) : 0));
8259 /* Flush any strings created in ErrorContext */
8269 * check_hook, assign_hook and show_hook subroutines
8273 check_log_destination(char **newval, void **extra, GucSource source)
8281 /* Need a modifiable copy of string */
8282 rawstring = pstrdup(*newval);
8284 /* Parse string into list of identifiers */
8285 if (!SplitIdentifierString(rawstring, ',', &elemlist))
8287 /* syntax error in list */
8288 GUC_check_errdetail("List syntax is invalid.");
8290 list_free(elemlist);
8294 foreach(l, elemlist)
8296 char *tok = (char *) lfirst(l);
8298 if (pg_strcasecmp(tok, "stderr") == 0)
8299 newlogdest |= LOG_DESTINATION_STDERR;
8300 else if (pg_strcasecmp(tok, "csvlog") == 0)
8301 newlogdest |= LOG_DESTINATION_CSVLOG;
8303 else if (pg_strcasecmp(tok, "syslog") == 0)
8304 newlogdest |= LOG_DESTINATION_SYSLOG;
8307 else if (pg_strcasecmp(tok, "eventlog") == 0)
8308 newlogdest |= LOG_DESTINATION_EVENTLOG;
8312 GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
8314 list_free(elemlist);
8320 list_free(elemlist);
8322 myextra = (int *) guc_malloc(ERROR, sizeof(int));
8323 *myextra = newlogdest;
8324 *extra = (void *) myextra;
8330 assign_log_destination(const char *newval, void *extra)
8332 Log_destination = *((int *) extra);
8336 assign_syslog_facility(int newval, void *extra)
8339 set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
8342 /* Without syslog support, just ignore it */
8346 assign_syslog_ident(const char *newval, void *extra)
8349 set_syslog_parameters(newval, syslog_facility);
8351 /* Without syslog support, it will always be set to "none", so ignore */
8356 assign_session_replication_role(int newval, void *extra)
8359 * Must flush the plan cache when changing replication role; but don't
8360 * flush unnecessarily.
8362 if (SessionReplicationRole != newval)
8367 check_temp_buffers(int *newval, void **extra, GucSource source)
8370 * Once local buffers have been initialized, it's too late to change this.
8372 if (NLocBuffer && NLocBuffer != *newval)
8374 GUC_check_errdetail("\"temp_buffers\" cannot be changed after any temporary tables have been accessed in the session.");
8381 check_phony_autocommit(bool *newval, void **extra, GucSource source)
8385 GUC_check_errcode(ERRCODE_FEATURE_NOT_SUPPORTED);
8386 GUC_check_errmsg("SET AUTOCOMMIT TO OFF is no longer supported");
8393 check_debug_assertions(bool *newval, void **extra, GucSource source)
8395 #ifndef USE_ASSERT_CHECKING
8398 GUC_check_errmsg("assertion checking is not supported by this build");
8406 check_bonjour(bool *newval, void **extra, GucSource source)
8411 GUC_check_errmsg("Bonjour is not supported by this build");
8419 check_ssl(bool *newval, void **extra, GucSource source)
8424 GUC_check_errmsg("SSL is not supported by this build");
8432 check_stage_log_stats(bool *newval, void **extra, GucSource source)
8434 if (*newval && log_statement_stats)
8436 GUC_check_errdetail("Cannot enable parameter when \"log_statement_stats\" is true.");
8443 check_log_stats(bool *newval, void **extra, GucSource source)
8446 (log_parser_stats || log_planner_stats || log_executor_stats))
8448 GUC_check_errdetail("Cannot enable \"log_statement_stats\" when "
8449 "\"log_parser_stats\", \"log_planner_stats\", "
8450 "or \"log_executor_stats\" is true.");
8457 check_canonical_path(char **newval, void **extra, GucSource source)
8460 * Since canonicalize_path never enlarges the string, we can just modify
8461 * newval in-place. But watch out for NULL, which is the default value
8462 * for external_pid_file.
8465 canonicalize_path(*newval);
8470 check_timezone_abbreviations(char **newval, void **extra, GucSource source)
8473 * The boot_val given above for timezone_abbreviations is NULL. When we
8474 * see this we just do nothing. If this value isn't overridden from the
8475 * config file then pg_timezone_abbrev_initialize() will eventually
8476 * replace it with "Default". This hack has two purposes: to avoid
8477 * wasting cycles loading values that might soon be overridden from the
8478 * config file, and to avoid trying to read the timezone abbrev files
8479 * during InitializeGUCOptions(). The latter doesn't work in an
8480 * EXEC_BACKEND subprocess because my_exec_path hasn't been set yet and so
8481 * we can't locate PGSHAREDIR.
8483 if (*newval == NULL)
8485 Assert(source == PGC_S_DEFAULT);
8489 /* OK, load the file and produce a malloc'd TimeZoneAbbrevTable */
8490 *extra = load_tzoffsets(*newval);
8492 /* tzparser.c returns NULL on failure, reporting via GUC_check_errmsg */
8500 assign_timezone_abbreviations(const char *newval, void *extra)
8502 /* Do nothing for the boot_val default of NULL */
8506 InstallTimeZoneAbbrevs((TimeZoneAbbrevTable *) extra);
8510 * pg_timezone_abbrev_initialize --- set default value if not done already
8512 * This is called after initial loading of postgresql.conf. If no
8513 * timezone_abbreviations setting was found therein, select default.
8514 * If a non-default value is already installed, nothing will happen.
8516 * This can also be called from ProcessConfigFile to establish the default
8517 * value after a postgresql.conf entry for it is removed.
8520 pg_timezone_abbrev_initialize(void)
8522 SetConfigOption("timezone_abbreviations", "Default",
8523 PGC_POSTMASTER, PGC_S_DYNAMIC_DEFAULT);
8527 show_archive_command(void)
8529 if (XLogArchivingActive())
8530 return XLogArchiveCommand;
8532 return "(disabled)";
8536 assign_tcp_keepalives_idle(int newval, void *extra)
8539 * The kernel API provides no way to test a value without setting it; and
8540 * once we set it we might fail to unset it. So there seems little point
8541 * in fully implementing the check-then-assign GUC API for these
8542 * variables. Instead we just do the assignment on demand. pqcomm.c
8543 * reports any problems via elog(LOG).
8545 * This approach means that the GUC value might have little to do with the
8546 * actual kernel value, so we use a show_hook that retrieves the kernel
8547 * value rather than trusting GUC's copy.
8549 (void) pq_setkeepalivesidle(newval, MyProcPort);
8553 show_tcp_keepalives_idle(void)
8555 /* See comments in assign_tcp_keepalives_idle */
8556 static char nbuf[16];
8558 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesidle(MyProcPort));
8563 assign_tcp_keepalives_interval(int newval, void *extra)
8565 /* See comments in assign_tcp_keepalives_idle */
8566 (void) pq_setkeepalivesinterval(newval, MyProcPort);
8570 show_tcp_keepalives_interval(void)
8572 /* See comments in assign_tcp_keepalives_idle */
8573 static char nbuf[16];
8575 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesinterval(MyProcPort));
8580 assign_tcp_keepalives_count(int newval, void *extra)
8582 /* See comments in assign_tcp_keepalives_idle */
8583 (void) pq_setkeepalivescount(newval, MyProcPort);
8587 show_tcp_keepalives_count(void)
8589 /* See comments in assign_tcp_keepalives_idle */
8590 static char nbuf[16];
8592 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivescount(MyProcPort));
8597 check_maxconnections(int *newval, void **extra, GucSource source)
8599 if (*newval + autovacuum_max_workers + 1 > MAX_BACKENDS)
8605 assign_maxconnections(int newval, void *extra)
8607 MaxBackends = newval + autovacuum_max_workers + 1;
8611 check_autovacuum_max_workers(int *newval, void **extra, GucSource source)
8613 if (MaxConnections + *newval + 1 > MAX_BACKENDS)
8619 assign_autovacuum_max_workers(int newval, void *extra)
8621 MaxBackends = MaxConnections + newval + 1;
8625 check_effective_io_concurrency(int *newval, void **extra, GucSource source)
8628 double new_prefetch_pages = 0.0;
8632 * The user-visible GUC parameter is the number of drives (spindles),
8633 * which we need to translate to a number-of-pages-to-prefetch target.
8634 * The target value is stashed in *extra and then assigned to the actual
8635 * variable by assign_effective_io_concurrency.
8637 * The expected number of prefetch pages needed to keep N drives busy is:
8639 * drives | I/O requests
8640 * -------+----------------
8643 * 3 | 3/1 + 3/2 + 3/3 = 5 1/2
8644 * 4 | 4/1 + 4/2 + 4/3 + 4/4 = 8 1/3
8647 * This is called the "coupon collector problem" and H(n) is called the
8648 * harmonic series. This could be approximated by n * ln(n), but for
8649 * reasonable numbers of drives we might as well just compute the series.
8651 * Alternatively we could set the target to the number of pages necessary
8652 * so that the expected number of active spindles is some arbitrary
8653 * percentage of the total. This sounds the same but is actually slightly
8654 * different. The result ends up being ln(1-P)/ln((n-1)/n) where P is
8655 * that desired fraction.
8657 * Experimental results show that both of these formulas aren't aggressive
8658 * enough, but we don't really have any better proposals.
8660 * Note that if *newval = 0 (disabled), we must set target = 0.
8664 for (i = 1; i <= *newval; i++)
8665 new_prefetch_pages += (double) *newval / (double) i;
8667 /* This range check shouldn't fail, but let's be paranoid */
8668 if (new_prefetch_pages >= 0.0 && new_prefetch_pages < (double) INT_MAX)
8670 int *myextra = (int *) guc_malloc(ERROR, sizeof(int));
8672 *myextra = (int) rint(new_prefetch_pages);
8673 *extra = (void *) myextra;
8681 #endif /* USE_PREFETCH */
8685 assign_effective_io_concurrency(int newval, void *extra)
8688 target_prefetch_pages = *((int *) extra);
8689 #endif /* USE_PREFETCH */
8693 assign_pgstat_temp_directory(const char *newval, void *extra)
8695 /* check_canonical_path already canonicalized newval for us */
8699 tname = guc_malloc(ERROR, strlen(newval) + 12); /* /pgstat.tmp */
8700 sprintf(tname, "%s/pgstat.tmp", newval);
8701 fname = guc_malloc(ERROR, strlen(newval) + 13); /* /pgstat.stat */
8702 sprintf(fname, "%s/pgstat.stat", newval);
8704 if (pgstat_stat_tmpname)
8705 free(pgstat_stat_tmpname);
8706 pgstat_stat_tmpname = tname;
8707 if (pgstat_stat_filename)
8708 free(pgstat_stat_filename);
8709 pgstat_stat_filename = fname;
8713 check_application_name(char **newval, void **extra, GucSource source)
8715 /* Only allow clean ASCII chars in the application name */
8718 for (p = *newval; *p; p++)
8720 if (*p < 32 || *p > 126)
8728 assign_application_name(const char *newval, void *extra)
8730 /* Update the pg_stat_activity view */
8731 pgstat_report_appname(newval);
8735 show_unix_socket_permissions(void)
8739 snprintf(buf, sizeof(buf), "%04o", Unix_socket_permissions);
8744 show_log_file_mode(void)
8748 snprintf(buf, sizeof(buf), "%04o", Log_file_mode);
8752 #include "guc-file.c"