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-2013, 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/bgworker.h"
56 #include "postmaster/bgwriter.h"
57 #include "postmaster/postmaster.h"
58 #include "postmaster/syslogger.h"
59 #include "postmaster/walwriter.h"
60 #include "replication/syncrep.h"
61 #include "replication/walreceiver.h"
62 #include "replication/walsender.h"
63 #include "storage/bufmgr.h"
64 #include "storage/standby.h"
65 #include "storage/fd.h"
66 #include "storage/proc.h"
67 #include "storage/predicate.h"
68 #include "tcop/tcopprot.h"
69 #include "tsearch/ts_cache.h"
70 #include "utils/builtins.h"
71 #include "utils/bytea.h"
72 #include "utils/guc_tables.h"
73 #include "utils/memutils.h"
74 #include "utils/pg_locale.h"
75 #include "utils/plancache.h"
76 #include "utils/portal.h"
77 #include "utils/ps_status.h"
78 #include "utils/snapmgr.h"
79 #include "utils/tzparser.h"
80 #include "utils/xml.h"
83 #define PG_KRB_SRVTAB ""
86 #define PG_KRB_SRVNAM ""
89 #define CONFIG_FILENAME "postgresql.conf"
90 #define HBA_FILENAME "pg_hba.conf"
91 #define IDENT_FILENAME "pg_ident.conf"
94 #define CONFIG_EXEC_PARAMS "global/config_exec_params"
95 #define CONFIG_EXEC_PARAMS_NEW "global/config_exec_params.new"
98 /* upper limit for GUC variables measured in kilobytes of memory */
99 /* note that various places assume the byte size fits in a "long" variable */
100 #if SIZEOF_SIZE_T > 4 && SIZEOF_LONG > 4
101 #define MAX_KILOBYTES INT_MAX
103 #define MAX_KILOBYTES (INT_MAX / 1024)
106 #define KB_PER_MB (1024)
107 #define KB_PER_GB (1024*1024)
108 #define KB_PER_TB (1024*1024*1024)
110 #define MS_PER_S 1000
112 #define MS_PER_MIN (1000 * 60)
114 #define S_PER_H (60 * 60)
115 #define MS_PER_H (1000 * 60 * 60)
116 #define MIN_PER_D (60 * 24)
117 #define S_PER_D (60 * 60 * 24)
118 #define MS_PER_D (1000 * 60 * 60 * 24)
120 /* XXX these should appear in other modules' header files */
121 extern bool Log_disconnections;
122 extern int CommitDelay;
123 extern int CommitSiblings;
124 extern char *default_tablespace;
125 extern char *temp_tablespaces;
126 extern bool ignore_checksum_failure;
127 extern bool synchronize_seqscans;
128 extern int ssl_renegotiation_limit;
129 extern char *SSLCipherSuites;
132 extern bool trace_sort;
134 #ifdef TRACE_SYNCSCAN
135 extern bool trace_syncscan;
137 #ifdef DEBUG_BOUNDED_SORT
138 extern bool optimize_bounded_sort;
141 static int GUC_check_errcode_value;
143 /* global variables for check hook support */
144 char *GUC_check_errmsg_string;
145 char *GUC_check_errdetail_string;
146 char *GUC_check_errhint_string;
149 static void set_config_sourcefile(const char *name, char *sourcefile,
151 static bool call_bool_check_hook(struct config_bool * conf, bool *newval,
152 void **extra, GucSource source, int elevel);
153 static bool call_int_check_hook(struct config_int * conf, int *newval,
154 void **extra, GucSource source, int elevel);
155 static bool call_real_check_hook(struct config_real * conf, double *newval,
156 void **extra, GucSource source, int elevel);
157 static bool call_string_check_hook(struct config_string * conf, char **newval,
158 void **extra, GucSource source, int elevel);
159 static bool call_enum_check_hook(struct config_enum * conf, int *newval,
160 void **extra, GucSource source, int elevel);
162 static bool check_log_destination(char **newval, void **extra, GucSource source);
163 static void assign_log_destination(const char *newval, void *extra);
166 static int syslog_facility = LOG_LOCAL0;
168 static int syslog_facility = 0;
171 static void assign_syslog_facility(int newval, void *extra);
172 static void assign_syslog_ident(const char *newval, void *extra);
173 static void assign_session_replication_role(int newval, void *extra);
174 static bool check_temp_buffers(int *newval, void **extra, GucSource source);
175 static bool check_phony_autocommit(bool *newval, void **extra, GucSource source);
176 static bool check_debug_assertions(bool *newval, void **extra, GucSource source);
177 static bool check_bonjour(bool *newval, void **extra, GucSource source);
178 static bool check_ssl(bool *newval, void **extra, GucSource source);
179 static bool check_stage_log_stats(bool *newval, void **extra, GucSource source);
180 static bool check_log_stats(bool *newval, void **extra, GucSource source);
181 static bool check_canonical_path(char **newval, void **extra, GucSource source);
182 static bool check_timezone_abbreviations(char **newval, void **extra, GucSource source);
183 static void assign_timezone_abbreviations(const char *newval, void *extra);
184 static void pg_timezone_abbrev_initialize(void);
185 static const char *show_archive_command(void);
186 static void assign_tcp_keepalives_idle(int newval, void *extra);
187 static void assign_tcp_keepalives_interval(int newval, void *extra);
188 static void assign_tcp_keepalives_count(int newval, void *extra);
189 static const char *show_tcp_keepalives_idle(void);
190 static const char *show_tcp_keepalives_interval(void);
191 static const char *show_tcp_keepalives_count(void);
192 static bool check_maxconnections(int *newval, void **extra, GucSource source);
193 static bool check_max_worker_processes(int *newval, void **extra, GucSource source);
194 static bool check_autovacuum_max_workers(int *newval, void **extra, GucSource source);
195 static bool check_effective_io_concurrency(int *newval, void **extra, GucSource source);
196 static void assign_effective_io_concurrency(int newval, void *extra);
197 static void assign_pgstat_temp_directory(const char *newval, void *extra);
198 static bool check_application_name(char **newval, void **extra, GucSource source);
199 static void assign_application_name(const char *newval, void *extra);
200 static const char *show_unix_socket_permissions(void);
201 static const char *show_log_file_mode(void);
203 static char *config_enum_get_options(struct config_enum * record,
204 const char *prefix, const char *suffix,
205 const char *separator);
209 * Options for enum values defined in this module.
211 * NOTE! Option values may not contain double quotes!
214 static const struct config_enum_entry bytea_output_options[] = {
215 {"escape", BYTEA_OUTPUT_ESCAPE, false},
216 {"hex", BYTEA_OUTPUT_HEX, false},
221 * We have different sets for client and server message level options because
222 * they sort slightly different (see "log" level)
224 static const struct config_enum_entry client_message_level_options[] = {
225 {"debug", DEBUG2, true},
226 {"debug5", DEBUG5, false},
227 {"debug4", DEBUG4, false},
228 {"debug3", DEBUG3, false},
229 {"debug2", DEBUG2, false},
230 {"debug1", DEBUG1, false},
232 {"info", INFO, true},
233 {"notice", NOTICE, false},
234 {"warning", WARNING, false},
235 {"error", ERROR, false},
236 {"fatal", FATAL, true},
237 {"panic", PANIC, true},
241 static const struct config_enum_entry server_message_level_options[] = {
242 {"debug", DEBUG2, true},
243 {"debug5", DEBUG5, false},
244 {"debug4", DEBUG4, false},
245 {"debug3", DEBUG3, false},
246 {"debug2", DEBUG2, false},
247 {"debug1", DEBUG1, false},
248 {"info", INFO, false},
249 {"notice", NOTICE, false},
250 {"warning", WARNING, false},
251 {"error", ERROR, false},
253 {"fatal", FATAL, false},
254 {"panic", PANIC, false},
258 static const struct config_enum_entry intervalstyle_options[] = {
259 {"postgres", INTSTYLE_POSTGRES, false},
260 {"postgres_verbose", INTSTYLE_POSTGRES_VERBOSE, false},
261 {"sql_standard", INTSTYLE_SQL_STANDARD, false},
262 {"iso_8601", INTSTYLE_ISO_8601, false},
266 static const struct config_enum_entry log_error_verbosity_options[] = {
267 {"terse", PGERROR_TERSE, false},
268 {"default", PGERROR_DEFAULT, false},
269 {"verbose", PGERROR_VERBOSE, false},
273 static const struct config_enum_entry log_statement_options[] = {
274 {"none", LOGSTMT_NONE, false},
275 {"ddl", LOGSTMT_DDL, false},
276 {"mod", LOGSTMT_MOD, false},
277 {"all", LOGSTMT_ALL, false},
281 static const struct config_enum_entry isolation_level_options[] = {
282 {"serializable", XACT_SERIALIZABLE, false},
283 {"repeatable read", XACT_REPEATABLE_READ, false},
284 {"read committed", XACT_READ_COMMITTED, false},
285 {"read uncommitted", XACT_READ_UNCOMMITTED, false},
289 static const struct config_enum_entry session_replication_role_options[] = {
290 {"origin", SESSION_REPLICATION_ROLE_ORIGIN, false},
291 {"replica", SESSION_REPLICATION_ROLE_REPLICA, false},
292 {"local", SESSION_REPLICATION_ROLE_LOCAL, false},
296 static const struct config_enum_entry syslog_facility_options[] = {
298 {"local0", LOG_LOCAL0, false},
299 {"local1", LOG_LOCAL1, false},
300 {"local2", LOG_LOCAL2, false},
301 {"local3", LOG_LOCAL3, false},
302 {"local4", LOG_LOCAL4, false},
303 {"local5", LOG_LOCAL5, false},
304 {"local6", LOG_LOCAL6, false},
305 {"local7", LOG_LOCAL7, false},
312 static const struct config_enum_entry track_function_options[] = {
313 {"none", TRACK_FUNC_OFF, false},
314 {"pl", TRACK_FUNC_PL, false},
315 {"all", TRACK_FUNC_ALL, false},
319 static const struct config_enum_entry xmlbinary_options[] = {
320 {"base64", XMLBINARY_BASE64, false},
321 {"hex", XMLBINARY_HEX, false},
325 static const struct config_enum_entry xmloption_options[] = {
326 {"content", XMLOPTION_CONTENT, false},
327 {"document", XMLOPTION_DOCUMENT, false},
332 * Although only "on", "off", and "safe_encoding" are documented, we
333 * accept all the likely variants of "on" and "off".
335 static const struct config_enum_entry backslash_quote_options[] = {
336 {"safe_encoding", BACKSLASH_QUOTE_SAFE_ENCODING, false},
337 {"on", BACKSLASH_QUOTE_ON, false},
338 {"off", BACKSLASH_QUOTE_OFF, false},
339 {"true", BACKSLASH_QUOTE_ON, true},
340 {"false", BACKSLASH_QUOTE_OFF, true},
341 {"yes", BACKSLASH_QUOTE_ON, true},
342 {"no", BACKSLASH_QUOTE_OFF, true},
343 {"1", BACKSLASH_QUOTE_ON, true},
344 {"0", BACKSLASH_QUOTE_OFF, true},
349 * Although only "on", "off", and "partition" are documented, we
350 * accept all the likely variants of "on" and "off".
352 static const struct config_enum_entry constraint_exclusion_options[] = {
353 {"partition", CONSTRAINT_EXCLUSION_PARTITION, false},
354 {"on", CONSTRAINT_EXCLUSION_ON, false},
355 {"off", CONSTRAINT_EXCLUSION_OFF, false},
356 {"true", CONSTRAINT_EXCLUSION_ON, true},
357 {"false", CONSTRAINT_EXCLUSION_OFF, true},
358 {"yes", CONSTRAINT_EXCLUSION_ON, true},
359 {"no", CONSTRAINT_EXCLUSION_OFF, true},
360 {"1", CONSTRAINT_EXCLUSION_ON, true},
361 {"0", CONSTRAINT_EXCLUSION_OFF, true},
366 * Although only "on", "off", "remote_write", and "local" are documented, we
367 * accept all the likely variants of "on" and "off".
369 static const struct config_enum_entry synchronous_commit_options[] = {
370 {"local", SYNCHRONOUS_COMMIT_LOCAL_FLUSH, false},
371 {"remote_write", SYNCHRONOUS_COMMIT_REMOTE_WRITE, false},
372 {"on", SYNCHRONOUS_COMMIT_ON, false},
373 {"off", SYNCHRONOUS_COMMIT_OFF, false},
374 {"true", SYNCHRONOUS_COMMIT_ON, true},
375 {"false", SYNCHRONOUS_COMMIT_OFF, true},
376 {"yes", SYNCHRONOUS_COMMIT_ON, true},
377 {"no", SYNCHRONOUS_COMMIT_OFF, true},
378 {"1", SYNCHRONOUS_COMMIT_ON, true},
379 {"0", SYNCHRONOUS_COMMIT_OFF, true},
384 * Options for enum values stored in other modules
386 extern const struct config_enum_entry wal_level_options[];
387 extern const struct config_enum_entry sync_method_options[];
390 * GUC option variables that are exported from this module
392 #ifdef USE_ASSERT_CHECKING
393 bool assert_enabled = true;
395 bool assert_enabled = false;
397 bool log_duration = false;
398 bool Debug_print_plan = false;
399 bool Debug_print_parse = false;
400 bool Debug_print_rewritten = false;
401 bool Debug_pretty_print = true;
403 bool log_parser_stats = false;
404 bool log_planner_stats = false;
405 bool log_executor_stats = false;
406 bool log_statement_stats = false; /* this is sort of all three
408 bool log_btree_build_stats = false;
411 bool check_function_bodies = true;
412 bool default_with_oids = false;
413 bool SQL_inheritance = true;
415 bool Password_encryption = true;
417 int log_min_error_statement = ERROR;
418 int log_min_messages = WARNING;
419 int client_min_messages = NOTICE;
420 int log_min_duration_statement = -1;
421 int log_temp_files = -1;
422 int trace_recovery_messages = LOG;
424 int temp_file_limit = -1;
426 int num_temp_buffers = 1024;
428 char *data_directory;
429 char *ConfigFileName;
432 char *external_pid_file;
434 char *pgstat_temp_directory;
436 char *application_name;
438 int tcp_keepalives_idle;
439 int tcp_keepalives_interval;
440 int tcp_keepalives_count;
443 * These variables are all dummies that don't do anything, except in some
444 * cases provide the value for SHOW to display. The real state is elsewhere
445 * and is kept in sync by assign_hooks.
447 static char *syslog_ident_str;
448 static bool phony_autocommit;
449 static bool session_auth_is_superuser;
450 static double phony_random_seed;
451 static char *client_encoding_string;
452 static char *datestyle_string;
453 static char *locale_collate;
454 static char *locale_ctype;
455 static char *server_encoding_string;
456 static char *server_version_string;
457 static int server_version_num;
458 static char *timezone_string;
459 static char *log_timezone_string;
460 static char *timezone_abbreviations_string;
461 static char *XactIsoLevel_string;
462 static char *session_authorization_string;
463 static int max_function_args;
464 static int max_index_keys;
465 static int max_identifier_length;
466 static int block_size;
467 static int segment_size;
468 static int wal_block_size;
469 static bool data_checksums;
470 static int wal_segment_size;
471 static bool integer_datetimes;
472 static int effective_io_concurrency;
474 /* should be static, but commands/variable.c needs to get at this */
479 * Displayable names for context types (enum GucContext)
481 * Note: these strings are deliberately not localized.
483 const char *const GucContext_Names[] =
485 /* PGC_INTERNAL */ "internal",
486 /* PGC_POSTMASTER */ "postmaster",
487 /* PGC_SIGHUP */ "sighup",
488 /* PGC_BACKEND */ "backend",
489 /* PGC_SUSET */ "superuser",
490 /* PGC_USERSET */ "user"
494 * Displayable names for source types (enum GucSource)
496 * Note: these strings are deliberately not localized.
498 const char *const GucSource_Names[] =
500 /* PGC_S_DEFAULT */ "default",
501 /* PGC_S_DYNAMIC_DEFAULT */ "default",
502 /* PGC_S_ENV_VAR */ "environment variable",
503 /* PGC_S_FILE */ "configuration file",
504 /* PGC_S_ARGV */ "command line",
505 /* PGC_S_GLOBAL */ "global",
506 /* PGC_S_DATABASE */ "database",
507 /* PGC_S_USER */ "user",
508 /* PGC_S_DATABASE_USER */ "database user",
509 /* PGC_S_CLIENT */ "client",
510 /* PGC_S_OVERRIDE */ "override",
511 /* PGC_S_INTERACTIVE */ "interactive",
512 /* PGC_S_TEST */ "test",
513 /* PGC_S_SESSION */ "session"
517 * Displayable names for the groupings defined in enum config_group
519 const char *const config_group_names[] =
522 gettext_noop("Ungrouped"),
524 gettext_noop("File Locations"),
526 gettext_noop("Connections and Authentication"),
527 /* CONN_AUTH_SETTINGS */
528 gettext_noop("Connections and Authentication / Connection Settings"),
529 /* CONN_AUTH_SECURITY */
530 gettext_noop("Connections and Authentication / Security and Authentication"),
532 gettext_noop("Resource Usage"),
534 gettext_noop("Resource Usage / Memory"),
536 gettext_noop("Resource Usage / Disk"),
537 /* RESOURCES_KERNEL */
538 gettext_noop("Resource Usage / Kernel Resources"),
539 /* RESOURCES_VACUUM_DELAY */
540 gettext_noop("Resource Usage / Cost-Based Vacuum Delay"),
541 /* RESOURCES_BGWRITER */
542 gettext_noop("Resource Usage / Background Writer"),
543 /* RESOURCES_ASYNCHRONOUS */
544 gettext_noop("Resource Usage / Asynchronous Behavior"),
546 gettext_noop("Write-Ahead Log"),
548 gettext_noop("Write-Ahead Log / Settings"),
549 /* WAL_CHECKPOINTS */
550 gettext_noop("Write-Ahead Log / Checkpoints"),
552 gettext_noop("Write-Ahead Log / Archiving"),
554 gettext_noop("Replication"),
555 /* REPLICATION_SENDING */
556 gettext_noop("Replication / Sending Servers"),
557 /* REPLICATION_MASTER */
558 gettext_noop("Replication / Master Server"),
559 /* REPLICATION_STANDBY */
560 gettext_noop("Replication / Standby Servers"),
562 gettext_noop("Query Tuning"),
563 /* QUERY_TUNING_METHOD */
564 gettext_noop("Query Tuning / Planner Method Configuration"),
565 /* QUERY_TUNING_COST */
566 gettext_noop("Query Tuning / Planner Cost Constants"),
567 /* QUERY_TUNING_GEQO */
568 gettext_noop("Query Tuning / Genetic Query Optimizer"),
569 /* QUERY_TUNING_OTHER */
570 gettext_noop("Query Tuning / Other Planner Options"),
572 gettext_noop("Reporting and Logging"),
574 gettext_noop("Reporting and Logging / Where to Log"),
576 gettext_noop("Reporting and Logging / When to Log"),
578 gettext_noop("Reporting and Logging / What to Log"),
580 gettext_noop("Statistics"),
581 /* STATS_MONITORING */
582 gettext_noop("Statistics / Monitoring"),
583 /* STATS_COLLECTOR */
584 gettext_noop("Statistics / Query and Index Statistics Collector"),
586 gettext_noop("Autovacuum"),
588 gettext_noop("Client Connection Defaults"),
589 /* CLIENT_CONN_STATEMENT */
590 gettext_noop("Client Connection Defaults / Statement Behavior"),
591 /* CLIENT_CONN_LOCALE */
592 gettext_noop("Client Connection Defaults / Locale and Formatting"),
593 /* CLIENT_CONN_PRELOAD */
594 gettext_noop("Client Connection Defaults / Shared Library Preloading"),
595 /* CLIENT_CONN_OTHER */
596 gettext_noop("Client Connection Defaults / Other Defaults"),
597 /* LOCK_MANAGEMENT */
598 gettext_noop("Lock Management"),
600 gettext_noop("Version and Platform Compatibility"),
601 /* COMPAT_OPTIONS_PREVIOUS */
602 gettext_noop("Version and Platform Compatibility / Previous PostgreSQL Versions"),
603 /* COMPAT_OPTIONS_CLIENT */
604 gettext_noop("Version and Platform Compatibility / Other Platforms and Clients"),
606 gettext_noop("Error Handling"),
608 gettext_noop("Preset Options"),
610 gettext_noop("Customized Options"),
611 /* DEVELOPER_OPTIONS */
612 gettext_noop("Developer Options"),
613 /* help_config wants this array to be null-terminated */
618 * Displayable names for GUC variable types (enum config_type)
620 * Note: these strings are deliberately not localized.
622 const char *const config_type_names[] =
624 /* PGC_BOOL */ "bool",
625 /* PGC_INT */ "integer",
626 /* PGC_REAL */ "real",
627 /* PGC_STRING */ "string",
628 /* PGC_ENUM */ "enum"
633 * Contents of GUC tables
635 * See src/backend/utils/misc/README for design notes.
639 * 1. Declare a global variable of type bool, int, double, or char*
640 * and make use of it.
642 * 2. Decide at what times it's safe to set the option. See guc.h for
645 * 3. Decide on a name, a default value, upper and lower bounds (if
648 * 4. Add a record below.
650 * 5. Add it to src/backend/utils/misc/postgresql.conf.sample, if
653 * 6. Don't forget to document the option (at least in config.sgml).
655 * 7. If it's a new GUC_LIST option you must edit pg_dumpall.c to ensure
656 * it is not single quoted at dump time.
660 /******** option records follow ********/
662 static struct config_bool ConfigureNamesBool[] =
665 {"enable_seqscan", PGC_USERSET, QUERY_TUNING_METHOD,
666 gettext_noop("Enables the planner's use of sequential-scan plans."),
674 {"enable_indexscan", PGC_USERSET, QUERY_TUNING_METHOD,
675 gettext_noop("Enables the planner's use of index-scan plans."),
683 {"enable_indexonlyscan", PGC_USERSET, QUERY_TUNING_METHOD,
684 gettext_noop("Enables the planner's use of index-only-scan plans."),
687 &enable_indexonlyscan,
692 {"enable_bitmapscan", PGC_USERSET, QUERY_TUNING_METHOD,
693 gettext_noop("Enables the planner's use of bitmap-scan plans."),
701 {"enable_tidscan", PGC_USERSET, QUERY_TUNING_METHOD,
702 gettext_noop("Enables the planner's use of TID scan plans."),
710 {"enable_sort", PGC_USERSET, QUERY_TUNING_METHOD,
711 gettext_noop("Enables the planner's use of explicit sort steps."),
719 {"enable_hashagg", PGC_USERSET, QUERY_TUNING_METHOD,
720 gettext_noop("Enables the planner's use of hashed aggregation plans."),
728 {"enable_material", PGC_USERSET, QUERY_TUNING_METHOD,
729 gettext_noop("Enables the planner's use of materialization."),
737 {"enable_nestloop", PGC_USERSET, QUERY_TUNING_METHOD,
738 gettext_noop("Enables the planner's use of nested-loop join plans."),
746 {"enable_mergejoin", PGC_USERSET, QUERY_TUNING_METHOD,
747 gettext_noop("Enables the planner's use of merge join plans."),
755 {"enable_hashjoin", PGC_USERSET, QUERY_TUNING_METHOD,
756 gettext_noop("Enables the planner's use of hash join plans."),
764 {"geqo", PGC_USERSET, QUERY_TUNING_GEQO,
765 gettext_noop("Enables genetic query optimization."),
766 gettext_noop("This algorithm attempts to do planning without "
767 "exhaustive searching.")
774 /* Not for general use --- used by SET SESSION AUTHORIZATION */
775 {"is_superuser", PGC_INTERNAL, UNGROUPED,
776 gettext_noop("Shows whether the current user is a superuser."),
778 GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
780 &session_auth_is_superuser,
785 {"bonjour", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
786 gettext_noop("Enables advertising the server via Bonjour."),
791 check_bonjour, NULL, NULL
794 {"ssl", PGC_POSTMASTER, CONN_AUTH_SECURITY,
795 gettext_noop("Enables SSL connections."),
800 check_ssl, NULL, NULL
803 {"fsync", PGC_SIGHUP, WAL_SETTINGS,
804 gettext_noop("Forces synchronization of updates to disk."),
805 gettext_noop("The server will use the fsync() system call in several places to make "
806 "sure that updates are physically written to disk. This insures "
807 "that a database cluster will recover to a consistent state after "
808 "an operating system or hardware crash.")
815 {"ignore_checksum_failure", PGC_SUSET, DEVELOPER_OPTIONS,
816 gettext_noop("Continues processing after a checksum failure."),
817 gettext_noop("Detection of a checksum failure normally causes PostgreSQL to "
818 "report an error, aborting the current transaction. Setting "
819 "ignore_checksum_failure to true causes the system to ignore the failure "
820 "(but still report a warning), and continue processing. This "
821 "behavior could cause crashes or other serious problems. Only "
822 "has an effect if checksums are enabled."),
825 &ignore_checksum_failure,
830 {"zero_damaged_pages", PGC_SUSET, DEVELOPER_OPTIONS,
831 gettext_noop("Continues processing past damaged page headers."),
832 gettext_noop("Detection of a damaged page header normally causes PostgreSQL to "
833 "report an error, aborting the current transaction. Setting "
834 "zero_damaged_pages to true causes the system to instead report a "
835 "warning, zero out the damaged page, and continue processing. This "
836 "behavior will destroy data, namely all the rows on the damaged page."),
844 {"full_page_writes", PGC_SIGHUP, WAL_SETTINGS,
845 gettext_noop("Writes full pages to WAL when first modified after a checkpoint."),
846 gettext_noop("A page write in process during an operating system crash might be "
847 "only partially written to disk. During recovery, the row changes "
848 "stored in WAL are not enough to recover. This option writes "
849 "pages when first modified after a checkpoint to WAL so full recovery "
857 {"log_checkpoints", PGC_SIGHUP, LOGGING_WHAT,
858 gettext_noop("Logs each checkpoint."),
866 {"log_connections", PGC_BACKEND, LOGGING_WHAT,
867 gettext_noop("Logs each successful connection."),
875 {"log_disconnections", PGC_BACKEND, LOGGING_WHAT,
876 gettext_noop("Logs end of a session, including duration."),
884 {"debug_assertions", PGC_USERSET, DEVELOPER_OPTIONS,
885 gettext_noop("Turns on various assertion checks."),
886 gettext_noop("This is a debugging aid."),
890 #ifdef USE_ASSERT_CHECKING
895 check_debug_assertions, NULL, NULL
899 {"exit_on_error", PGC_USERSET, ERROR_HANDLING_OPTIONS,
900 gettext_noop("Terminate session on any error."),
908 {"restart_after_crash", PGC_SIGHUP, ERROR_HANDLING_OPTIONS,
909 gettext_noop("Reinitialize server after backend crash."),
912 &restart_after_crash,
918 {"log_duration", PGC_SUSET, LOGGING_WHAT,
919 gettext_noop("Logs the duration of each completed SQL statement."),
927 {"debug_print_parse", PGC_USERSET, LOGGING_WHAT,
928 gettext_noop("Logs each query's parse tree."),
936 {"debug_print_rewritten", PGC_USERSET, LOGGING_WHAT,
937 gettext_noop("Logs each query's rewritten parse tree."),
940 &Debug_print_rewritten,
945 {"debug_print_plan", PGC_USERSET, LOGGING_WHAT,
946 gettext_noop("Logs each query's execution plan."),
954 {"debug_pretty_print", PGC_USERSET, LOGGING_WHAT,
955 gettext_noop("Indents parse and plan tree displays."),
963 {"log_parser_stats", PGC_SUSET, STATS_MONITORING,
964 gettext_noop("Writes parser performance statistics to the server log."),
969 check_stage_log_stats, NULL, NULL
972 {"log_planner_stats", PGC_SUSET, STATS_MONITORING,
973 gettext_noop("Writes planner performance statistics to the server log."),
978 check_stage_log_stats, NULL, NULL
981 {"log_executor_stats", PGC_SUSET, STATS_MONITORING,
982 gettext_noop("Writes executor performance statistics to the server log."),
987 check_stage_log_stats, NULL, NULL
990 {"log_statement_stats", PGC_SUSET, STATS_MONITORING,
991 gettext_noop("Writes cumulative performance statistics to the server log."),
994 &log_statement_stats,
996 check_log_stats, NULL, NULL
998 #ifdef BTREE_BUILD_STATS
1000 {"log_btree_build_stats", PGC_SUSET, DEVELOPER_OPTIONS,
1001 gettext_noop("Logs system resource usage statistics (memory and CPU) on various B-tree operations."),
1005 &log_btree_build_stats,
1012 {"track_activities", PGC_SUSET, STATS_COLLECTOR,
1013 gettext_noop("Collects information about executing commands."),
1014 gettext_noop("Enables the collection of information on the currently "
1015 "executing command of each session, along with "
1016 "the time at which that command began execution.")
1018 &pgstat_track_activities,
1023 {"track_counts", PGC_SUSET, STATS_COLLECTOR,
1024 gettext_noop("Collects statistics on database activity."),
1027 &pgstat_track_counts,
1032 {"track_io_timing", PGC_SUSET, STATS_COLLECTOR,
1033 gettext_noop("Collects timing statistics for database I/O activity."),
1042 {"update_process_title", PGC_SUSET, STATS_COLLECTOR,
1043 gettext_noop("Updates the process title to show the active SQL command."),
1044 gettext_noop("Enables updating of the process title every time a new SQL command is received by the server.")
1046 &update_process_title,
1052 {"autovacuum", PGC_SIGHUP, AUTOVACUUM,
1053 gettext_noop("Starts the autovacuum subprocess."),
1056 &autovacuum_start_daemon,
1062 {"trace_notify", PGC_USERSET, DEVELOPER_OPTIONS,
1063 gettext_noop("Generates debugging output for LISTEN and NOTIFY."),
1074 {"trace_locks", PGC_SUSET, DEVELOPER_OPTIONS,
1075 gettext_noop("Emits information about lock usage."),
1084 {"trace_userlocks", PGC_SUSET, DEVELOPER_OPTIONS,
1085 gettext_noop("Emits information about user lock usage."),
1094 {"trace_lwlocks", PGC_SUSET, DEVELOPER_OPTIONS,
1095 gettext_noop("Emits information about lightweight lock usage."),
1104 {"debug_deadlocks", PGC_SUSET, DEVELOPER_OPTIONS,
1105 gettext_noop("Dumps information about all current locks when a deadlock timeout occurs."),
1116 {"log_lock_waits", PGC_SUSET, LOGGING_WHAT,
1117 gettext_noop("Logs long lock waits."),
1126 {"log_hostname", PGC_SIGHUP, LOGGING_WHAT,
1127 gettext_noop("Logs the host name in the connection logs."),
1128 gettext_noop("By default, connection logs only show the IP address "
1129 "of the connecting host. If you want them to show the host name you "
1130 "can turn this on, but depending on your host name resolution "
1131 "setup it might impose a non-negligible performance penalty.")
1138 {"sql_inheritance", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1139 gettext_noop("Causes subtables to be included by default in various commands."),
1147 {"password_encryption", PGC_USERSET, CONN_AUTH_SECURITY,
1148 gettext_noop("Encrypt passwords."),
1149 gettext_noop("When a password is specified in CREATE USER or "
1150 "ALTER USER without writing either ENCRYPTED or UNENCRYPTED, "
1151 "this parameter determines whether the password is to be encrypted.")
1153 &Password_encryption,
1158 {"transform_null_equals", PGC_USERSET, COMPAT_OPTIONS_CLIENT,
1159 gettext_noop("Treats \"expr=NULL\" as \"expr IS NULL\"."),
1160 gettext_noop("When turned on, expressions of the form expr = NULL "
1161 "(or NULL = expr) are treated as expr IS NULL, that is, they "
1162 "return true if expr evaluates to the null value, and false "
1163 "otherwise. The correct behavior of expr = NULL is to always "
1164 "return null (unknown).")
1166 &Transform_null_equals,
1171 {"db_user_namespace", PGC_SIGHUP, CONN_AUTH_SECURITY,
1172 gettext_noop("Enables per-database user names."),
1180 /* only here for backwards compatibility */
1181 {"autocommit", PGC_USERSET, CLIENT_CONN_STATEMENT,
1182 gettext_noop("This parameter doesn't do anything."),
1183 gettext_noop("It's just here so that we won't choke on SET AUTOCOMMIT TO ON from 7.3-vintage clients."),
1184 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
1188 check_phony_autocommit, NULL, NULL
1191 {"default_transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
1192 gettext_noop("Sets the default read-only status of new transactions."),
1195 &DefaultXactReadOnly,
1200 {"transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
1201 gettext_noop("Sets the current transaction's read-only status."),
1203 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1207 check_transaction_read_only, NULL, NULL
1210 {"default_transaction_deferrable", PGC_USERSET, CLIENT_CONN_STATEMENT,
1211 gettext_noop("Sets the default deferrable status of new transactions."),
1214 &DefaultXactDeferrable,
1219 {"transaction_deferrable", PGC_USERSET, CLIENT_CONN_STATEMENT,
1220 gettext_noop("Whether to defer a read-only serializable transaction until it can be executed with no possible serialization failures."),
1222 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1226 check_transaction_deferrable, NULL, NULL
1229 {"check_function_bodies", PGC_USERSET, CLIENT_CONN_STATEMENT,
1230 gettext_noop("Check function bodies during CREATE FUNCTION."),
1233 &check_function_bodies,
1238 {"array_nulls", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1239 gettext_noop("Enable input of NULL elements in arrays."),
1240 gettext_noop("When turned on, unquoted NULL in an array input "
1241 "value means a null value; "
1242 "otherwise it is taken literally.")
1249 {"default_with_oids", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1250 gettext_noop("Create new tables with OIDs by default."),
1258 {"logging_collector", PGC_POSTMASTER, LOGGING_WHERE,
1259 gettext_noop("Start a subprocess to capture stderr output and/or csvlogs into log files."),
1267 {"log_truncate_on_rotation", PGC_SIGHUP, LOGGING_WHERE,
1268 gettext_noop("Truncate existing log files of same name during log rotation."),
1271 &Log_truncate_on_rotation,
1278 {"trace_sort", PGC_USERSET, DEVELOPER_OPTIONS,
1279 gettext_noop("Emit information about resource usage in sorting."),
1289 #ifdef TRACE_SYNCSCAN
1290 /* this is undocumented because not exposed in a standard build */
1292 {"trace_syncscan", PGC_USERSET, DEVELOPER_OPTIONS,
1293 gettext_noop("Generate debugging output for synchronized scanning."),
1303 #ifdef DEBUG_BOUNDED_SORT
1304 /* this is undocumented because not exposed in a standard build */
1307 "optimize_bounded_sort", PGC_USERSET, QUERY_TUNING_METHOD,
1308 gettext_noop("Enable bounded sorting using heap sort."),
1312 &optimize_bounded_sort,
1320 {"wal_debug", PGC_SUSET, DEVELOPER_OPTIONS,
1321 gettext_noop("Emit WAL-related debugging output."),
1332 {"integer_datetimes", PGC_INTERNAL, PRESET_OPTIONS,
1333 gettext_noop("Datetimes are integer based."),
1335 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1338 #ifdef HAVE_INT64_TIMESTAMP
1347 {"krb_caseins_users", PGC_SIGHUP, CONN_AUTH_SECURITY,
1348 gettext_noop("Sets whether Kerberos and GSSAPI user names should be treated as case-insensitive."),
1351 &pg_krb_caseins_users,
1357 {"escape_string_warning", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1358 gettext_noop("Warn about backslash escapes in ordinary string literals."),
1361 &escape_string_warning,
1367 {"standard_conforming_strings", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1368 gettext_noop("Causes '...' strings to treat backslashes literally."),
1372 &standard_conforming_strings,
1378 {"synchronize_seqscans", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1379 gettext_noop("Enable synchronized sequential scans."),
1382 &synchronize_seqscans,
1388 {"archive_mode", PGC_POSTMASTER, WAL_ARCHIVING,
1389 gettext_noop("Allows archiving of WAL files using archive_command."),
1398 {"hot_standby", PGC_POSTMASTER, REPLICATION_STANDBY,
1399 gettext_noop("Allows connections and queries during recovery."),
1408 {"hot_standby_feedback", PGC_SIGHUP, REPLICATION_STANDBY,
1409 gettext_noop("Allows feedback from a hot standby to the primary that will avoid query conflicts."),
1412 &hot_standby_feedback,
1418 {"allow_system_table_mods", PGC_POSTMASTER, DEVELOPER_OPTIONS,
1419 gettext_noop("Allows modifications of the structure of system tables."),
1423 &allowSystemTableMods,
1429 {"ignore_system_indexes", PGC_BACKEND, DEVELOPER_OPTIONS,
1430 gettext_noop("Disables reading from system indexes."),
1431 gettext_noop("It does not prevent updating the indexes, so it is safe "
1432 "to use. The worst consequence is slowness."),
1435 &IgnoreSystemIndexes,
1441 {"lo_compat_privileges", PGC_SUSET, COMPAT_OPTIONS_PREVIOUS,
1442 gettext_noop("Enables backward compatibility mode for privilege checks on large objects."),
1443 gettext_noop("Skips privilege checks when reading or modifying large objects, "
1444 "for compatibility with PostgreSQL releases prior to 9.0.")
1446 &lo_compat_privileges,
1452 {"quote_all_identifiers", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1453 gettext_noop("When generating SQL fragments, quote all identifiers."),
1456 "e_all_identifiers,
1462 {"data_checksums", PGC_INTERNAL, PRESET_OPTIONS,
1463 gettext_noop("Shows whether data checksums are turned on for this cluster"),
1465 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1472 /* End-of-list marker */
1474 {NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL, NULL
1479 static struct config_int ConfigureNamesInt[] =
1482 {"archive_timeout", PGC_SIGHUP, WAL_ARCHIVING,
1483 gettext_noop("Forces a switch to the next xlog file if a "
1484 "new file has not been started within N seconds."),
1488 &XLogArchiveTimeout,
1493 {"post_auth_delay", PGC_BACKEND, DEVELOPER_OPTIONS,
1494 gettext_noop("Waits N seconds on connection startup after authentication."),
1495 gettext_noop("This allows attaching a debugger to the process."),
1496 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1499 0, 0, INT_MAX / 1000000,
1503 {"default_statistics_target", PGC_USERSET, QUERY_TUNING_OTHER,
1504 gettext_noop("Sets the default statistics target."),
1505 gettext_noop("This applies to table columns that have not had a "
1506 "column-specific target set via ALTER TABLE SET STATISTICS.")
1508 &default_statistics_target,
1513 {"from_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1514 gettext_noop("Sets the FROM-list size beyond which subqueries "
1515 "are not collapsed."),
1516 gettext_noop("The planner will merge subqueries into upper "
1517 "queries if the resulting FROM list would have no more than "
1520 &from_collapse_limit,
1525 {"join_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1526 gettext_noop("Sets the FROM-list size beyond which JOIN "
1527 "constructs are not flattened."),
1528 gettext_noop("The planner will flatten explicit JOIN "
1529 "constructs into lists of FROM items whenever a "
1530 "list of no more than this many items would result.")
1532 &join_collapse_limit,
1537 {"geqo_threshold", PGC_USERSET, QUERY_TUNING_GEQO,
1538 gettext_noop("Sets the threshold of FROM items beyond which GEQO is used."),
1546 {"geqo_effort", PGC_USERSET, QUERY_TUNING_GEQO,
1547 gettext_noop("GEQO: effort is used to set the default for other GEQO parameters."),
1551 DEFAULT_GEQO_EFFORT, MIN_GEQO_EFFORT, MAX_GEQO_EFFORT,
1555 {"geqo_pool_size", PGC_USERSET, QUERY_TUNING_GEQO,
1556 gettext_noop("GEQO: number of individuals in the population."),
1557 gettext_noop("Zero selects a suitable default value.")
1564 {"geqo_generations", PGC_USERSET, QUERY_TUNING_GEQO,
1565 gettext_noop("GEQO: number of iterations of the algorithm."),
1566 gettext_noop("Zero selects a suitable default value.")
1574 /* This is PGC_SUSET to prevent hiding from log_lock_waits. */
1575 {"deadlock_timeout", PGC_SUSET, LOCK_MANAGEMENT,
1576 gettext_noop("Sets the time to wait on a lock before checking for deadlock."),
1586 {"max_standby_archive_delay", PGC_SIGHUP, REPLICATION_STANDBY,
1587 gettext_noop("Sets the maximum delay before canceling queries when a hot standby server is processing archived WAL data."),
1591 &max_standby_archive_delay,
1592 30 * 1000, -1, INT_MAX,
1597 {"max_standby_streaming_delay", PGC_SIGHUP, REPLICATION_STANDBY,
1598 gettext_noop("Sets the maximum delay before canceling queries when a hot standby server is processing streamed WAL data."),
1602 &max_standby_streaming_delay,
1603 30 * 1000, -1, INT_MAX,
1608 {"wal_receiver_status_interval", PGC_SIGHUP, REPLICATION_STANDBY,
1609 gettext_noop("Sets the maximum interval between WAL receiver status reports to the primary."),
1613 &wal_receiver_status_interval,
1614 10, 0, INT_MAX / 1000,
1619 {"wal_receiver_timeout", PGC_SIGHUP, REPLICATION_STANDBY,
1620 gettext_noop("Sets the maximum wait time to receive data from the primary."),
1624 &wal_receiver_timeout,
1625 60 * 1000, 0, INT_MAX,
1630 {"max_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1631 gettext_noop("Sets the maximum number of concurrent connections."),
1635 100, 1, MAX_BACKENDS,
1636 check_maxconnections, NULL, NULL
1640 {"superuser_reserved_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1641 gettext_noop("Sets the number of connection slots reserved for superusers."),
1650 * We sometimes multiply the number of shared buffers by two without
1651 * checking for overflow, so we mustn't allow more than INT_MAX / 2.
1654 {"shared_buffers", PGC_POSTMASTER, RESOURCES_MEM,
1655 gettext_noop("Sets the number of shared memory buffers used by the server."),
1660 1024, 16, INT_MAX / 2,
1665 {"temp_buffers", PGC_USERSET, RESOURCES_MEM,
1666 gettext_noop("Sets the maximum number of temporary buffers used by each session."),
1671 1024, 100, INT_MAX / 2,
1672 check_temp_buffers, NULL, NULL
1676 {"port", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1677 gettext_noop("Sets the TCP port the server listens on."),
1681 DEF_PGPORT, 1, 65535,
1686 {"unix_socket_permissions", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1687 gettext_noop("Sets the access permissions of the Unix-domain socket."),
1688 gettext_noop("Unix-domain sockets use the usual Unix file system "
1689 "permission set. The parameter value is expected "
1690 "to be a numeric mode specification in the form "
1691 "accepted by the chmod and umask system calls. "
1692 "(To use the customary octal format the number must "
1693 "start with a 0 (zero).)")
1695 &Unix_socket_permissions,
1697 NULL, NULL, show_unix_socket_permissions
1701 {"log_file_mode", PGC_SIGHUP, LOGGING_WHERE,
1702 gettext_noop("Sets the file permissions for log files."),
1703 gettext_noop("The parameter value is expected "
1704 "to be a numeric mode specification in the form "
1705 "accepted by the chmod and umask system calls. "
1706 "(To use the customary octal format the number must "
1707 "start with a 0 (zero).)")
1711 NULL, NULL, show_log_file_mode
1715 {"work_mem", PGC_USERSET, RESOURCES_MEM,
1716 gettext_noop("Sets the maximum memory to be used for query workspaces."),
1717 gettext_noop("This much memory can be used by each internal "
1718 "sort operation and hash table before switching to "
1719 "temporary disk files."),
1723 1024, 64, MAX_KILOBYTES,
1728 {"maintenance_work_mem", PGC_USERSET, RESOURCES_MEM,
1729 gettext_noop("Sets the maximum memory to be used for maintenance operations."),
1730 gettext_noop("This includes operations such as VACUUM and CREATE INDEX."),
1733 &maintenance_work_mem,
1734 16384, 1024, MAX_KILOBYTES,
1739 * We use the hopefully-safely-small value of 100kB as the compiled-in
1740 * default for max_stack_depth. InitializeGUCOptions will increase it if
1741 * possible, depending on the actual platform-specific stack limit.
1744 {"max_stack_depth", PGC_SUSET, RESOURCES_MEM,
1745 gettext_noop("Sets the maximum stack depth, in kilobytes."),
1750 100, 100, MAX_KILOBYTES,
1751 check_max_stack_depth, assign_max_stack_depth, NULL
1755 {"temp_file_limit", PGC_SUSET, RESOURCES_DISK,
1756 gettext_noop("Limits the total size of all temporary files used by each session."),
1757 gettext_noop("-1 means no limit."),
1766 {"vacuum_cost_page_hit", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1767 gettext_noop("Vacuum cost for a page found in the buffer cache."),
1776 {"vacuum_cost_page_miss", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1777 gettext_noop("Vacuum cost for a page not found in the buffer cache."),
1780 &VacuumCostPageMiss,
1786 {"vacuum_cost_page_dirty", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1787 gettext_noop("Vacuum cost for a page dirtied by vacuum."),
1790 &VacuumCostPageDirty,
1796 {"vacuum_cost_limit", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1797 gettext_noop("Vacuum cost amount available before napping."),
1806 {"vacuum_cost_delay", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1807 gettext_noop("Vacuum cost delay in milliseconds."),
1817 {"autovacuum_vacuum_cost_delay", PGC_SIGHUP, AUTOVACUUM,
1818 gettext_noop("Vacuum cost delay in milliseconds, for autovacuum."),
1822 &autovacuum_vac_cost_delay,
1828 {"autovacuum_vacuum_cost_limit", PGC_SIGHUP, AUTOVACUUM,
1829 gettext_noop("Vacuum cost amount available before napping, for autovacuum."),
1832 &autovacuum_vac_cost_limit,
1838 {"max_files_per_process", PGC_POSTMASTER, RESOURCES_KERNEL,
1839 gettext_noop("Sets the maximum number of simultaneously open files for each server process."),
1842 &max_files_per_process,
1848 * See also CheckRequiredParameterValues() if this parameter changes
1851 {"max_prepared_transactions", PGC_POSTMASTER, RESOURCES_MEM,
1852 gettext_noop("Sets the maximum number of simultaneously prepared transactions."),
1855 &max_prepared_xacts,
1862 {"trace_lock_oidmin", PGC_SUSET, DEVELOPER_OPTIONS,
1863 gettext_noop("Sets the minimum OID of tables for tracking locks."),
1864 gettext_noop("Is used to avoid output on system tables."),
1868 FirstNormalObjectId, 0, INT_MAX,
1872 {"trace_lock_table", PGC_SUSET, DEVELOPER_OPTIONS,
1873 gettext_noop("Sets the OID of the table with unconditionally lock tracing."),
1884 {"statement_timeout", PGC_USERSET, CLIENT_CONN_STATEMENT,
1885 gettext_noop("Sets the maximum allowed duration of any statement."),
1886 gettext_noop("A value of 0 turns off the timeout."),
1895 {"lock_timeout", PGC_USERSET, CLIENT_CONN_STATEMENT,
1896 gettext_noop("Sets the maximum allowed duration of any wait for a lock."),
1897 gettext_noop("A value of 0 turns off the timeout."),
1906 {"vacuum_freeze_min_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1907 gettext_noop("Minimum age at which VACUUM should freeze a table row."),
1910 &vacuum_freeze_min_age,
1911 50000000, 0, 1000000000,
1916 {"vacuum_freeze_table_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1917 gettext_noop("Age at which VACUUM should scan whole table to freeze tuples."),
1920 &vacuum_freeze_table_age,
1921 150000000, 0, 2000000000,
1926 {"vacuum_defer_cleanup_age", PGC_SIGHUP, REPLICATION_MASTER,
1927 gettext_noop("Number of transactions by which VACUUM and HOT cleanup should be deferred, if any."),
1930 &vacuum_defer_cleanup_age,
1936 * See also CheckRequiredParameterValues() if this parameter changes
1939 {"max_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
1940 gettext_noop("Sets the maximum number of locks per transaction."),
1941 gettext_noop("The shared lock table is sized on the assumption that "
1942 "at most max_locks_per_transaction * max_connections distinct "
1943 "objects will need to be locked at any one time.")
1945 &max_locks_per_xact,
1951 {"max_pred_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
1952 gettext_noop("Sets the maximum number of predicate locks per transaction."),
1953 gettext_noop("The shared predicate lock table is sized on the assumption that "
1954 "at most max_pred_locks_per_transaction * max_connections distinct "
1955 "objects will need to be locked at any one time.")
1957 &max_predicate_locks_per_xact,
1963 {"authentication_timeout", PGC_SIGHUP, CONN_AUTH_SECURITY,
1964 gettext_noop("Sets the maximum allowed time to complete client authentication."),
1968 &AuthenticationTimeout,
1974 /* Not for general use */
1975 {"pre_auth_delay", PGC_SIGHUP, DEVELOPER_OPTIONS,
1976 gettext_noop("Waits N seconds on connection startup before authentication."),
1977 gettext_noop("This allows attaching a debugger to the process."),
1978 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1986 {"wal_keep_segments", PGC_SIGHUP, REPLICATION_SENDING,
1987 gettext_noop("Sets the number of WAL files held for standby servers."),
1996 {"checkpoint_segments", PGC_SIGHUP, WAL_CHECKPOINTS,
1997 gettext_noop("Sets the maximum distance in log segments between automatic WAL checkpoints."),
2000 &CheckPointSegments,
2006 {"checkpoint_timeout", PGC_SIGHUP, WAL_CHECKPOINTS,
2007 gettext_noop("Sets the maximum time between automatic WAL checkpoints."),
2017 {"checkpoint_warning", PGC_SIGHUP, WAL_CHECKPOINTS,
2018 gettext_noop("Enables warnings if checkpoint segments are filled more "
2019 "frequently than this."),
2020 gettext_noop("Write a message to the server log if checkpoints "
2021 "caused by the filling of checkpoint segment files happens more "
2022 "frequently than this number of seconds. Zero turns off the warning."),
2031 {"wal_buffers", PGC_POSTMASTER, WAL_SETTINGS,
2032 gettext_noop("Sets the number of disk-page buffers in shared memory for WAL."),
2038 check_wal_buffers, NULL, NULL
2042 {"wal_writer_delay", PGC_SIGHUP, WAL_SETTINGS,
2043 gettext_noop("WAL writer sleep time between WAL flushes."),
2053 {"xloginsert_slots", PGC_POSTMASTER, WAL_SETTINGS,
2054 gettext_noop("Sets the number of slots for concurrent xlog insertions."),
2058 &num_xloginsert_slots,
2064 /* see max_connections */
2065 {"max_wal_senders", PGC_POSTMASTER, REPLICATION_SENDING,
2066 gettext_noop("Sets the maximum number of simultaneously running WAL sender processes."),
2075 {"wal_sender_timeout", PGC_SIGHUP, REPLICATION_SENDING,
2076 gettext_noop("Sets the maximum time to wait for WAL replication."),
2080 &wal_sender_timeout,
2081 60 * 1000, 0, INT_MAX,
2086 {"commit_delay", PGC_SUSET, WAL_SETTINGS,
2087 gettext_noop("Sets the delay in microseconds between transaction commit and "
2088 "flushing WAL to disk."),
2090 /* we have no microseconds designation, so can't supply units here */
2098 {"commit_siblings", PGC_USERSET, WAL_SETTINGS,
2099 gettext_noop("Sets the minimum concurrent open transactions before performing "
2109 {"extra_float_digits", PGC_USERSET, CLIENT_CONN_LOCALE,
2110 gettext_noop("Sets the number of digits displayed for floating-point values."),
2111 gettext_noop("This affects real, double precision, and geometric data types. "
2112 "The parameter value is added to the standard number of digits "
2113 "(FLT_DIG or DBL_DIG as appropriate).")
2115 &extra_float_digits,
2121 {"log_min_duration_statement", PGC_SUSET, LOGGING_WHEN,
2122 gettext_noop("Sets the minimum execution time above which "
2123 "statements will be logged."),
2124 gettext_noop("Zero prints all queries. -1 turns this feature off."),
2127 &log_min_duration_statement,
2133 {"log_autovacuum_min_duration", PGC_SIGHUP, LOGGING_WHAT,
2134 gettext_noop("Sets the minimum execution time above which "
2135 "autovacuum actions will be logged."),
2136 gettext_noop("Zero prints all actions. -1 turns autovacuum logging off."),
2139 &Log_autovacuum_min_duration,
2145 {"bgwriter_delay", PGC_SIGHUP, RESOURCES_BGWRITER,
2146 gettext_noop("Background writer sleep time between rounds."),
2156 {"bgwriter_lru_maxpages", PGC_SIGHUP, RESOURCES_BGWRITER,
2157 gettext_noop("Background writer maximum number of LRU pages to flush per round."),
2160 &bgwriter_lru_maxpages,
2166 {"effective_io_concurrency",
2172 RESOURCES_ASYNCHRONOUS,
2173 gettext_noop("Number of simultaneous requests that can be handled efficiently by the disk subsystem."),
2174 gettext_noop("For RAID arrays, this should be approximately the number of drive spindles in the array.")
2176 &effective_io_concurrency,
2182 check_effective_io_concurrency, assign_effective_io_concurrency, NULL
2186 {"max_worker_processes",
2188 RESOURCES_ASYNCHRONOUS,
2189 gettext_noop("Maximum number of concurrent worker processes."),
2192 &max_worker_processes,
2194 check_max_worker_processes, NULL, NULL
2198 {"log_rotation_age", PGC_SIGHUP, LOGGING_WHERE,
2199 gettext_noop("Automatic log file rotation will occur after N minutes."),
2204 HOURS_PER_DAY * MINS_PER_HOUR, 0, INT_MAX / SECS_PER_MINUTE,
2209 {"log_rotation_size", PGC_SIGHUP, LOGGING_WHERE,
2210 gettext_noop("Automatic log file rotation will occur after N kilobytes."),
2215 10 * 1024, 0, INT_MAX / 1024,
2220 {"max_function_args", PGC_INTERNAL, PRESET_OPTIONS,
2221 gettext_noop("Shows the maximum number of function arguments."),
2223 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2226 FUNC_MAX_ARGS, FUNC_MAX_ARGS, FUNC_MAX_ARGS,
2231 {"max_index_keys", PGC_INTERNAL, PRESET_OPTIONS,
2232 gettext_noop("Shows the maximum number of index keys."),
2234 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2237 INDEX_MAX_KEYS, INDEX_MAX_KEYS, INDEX_MAX_KEYS,
2242 {"max_identifier_length", PGC_INTERNAL, PRESET_OPTIONS,
2243 gettext_noop("Shows the maximum identifier length."),
2245 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2247 &max_identifier_length,
2248 NAMEDATALEN - 1, NAMEDATALEN - 1, NAMEDATALEN - 1,
2253 {"block_size", PGC_INTERNAL, PRESET_OPTIONS,
2254 gettext_noop("Shows the size of a disk block."),
2256 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2259 BLCKSZ, BLCKSZ, BLCKSZ,
2264 {"segment_size", PGC_INTERNAL, PRESET_OPTIONS,
2265 gettext_noop("Shows the number of pages per disk file."),
2267 GUC_UNIT_BLOCKS | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2270 RELSEG_SIZE, RELSEG_SIZE, RELSEG_SIZE,
2275 {"wal_block_size", PGC_INTERNAL, PRESET_OPTIONS,
2276 gettext_noop("Shows the block size in the write ahead log."),
2278 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2281 XLOG_BLCKSZ, XLOG_BLCKSZ, XLOG_BLCKSZ,
2286 {"wal_segment_size", PGC_INTERNAL, PRESET_OPTIONS,
2287 gettext_noop("Shows the number of pages per write ahead log segment."),
2289 GUC_UNIT_XBLOCKS | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2292 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
2293 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
2294 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
2299 {"autovacuum_naptime", PGC_SIGHUP, AUTOVACUUM,
2300 gettext_noop("Time to sleep between autovacuum runs."),
2304 &autovacuum_naptime,
2305 60, 1, INT_MAX / 1000,
2309 {"autovacuum_vacuum_threshold", PGC_SIGHUP, AUTOVACUUM,
2310 gettext_noop("Minimum number of tuple updates or deletes prior to vacuum."),
2313 &autovacuum_vac_thresh,
2318 {"autovacuum_analyze_threshold", PGC_SIGHUP, AUTOVACUUM,
2319 gettext_noop("Minimum number of tuple inserts, updates, or deletes prior to analyze."),
2322 &autovacuum_anl_thresh,
2327 /* see varsup.c for why this is PGC_POSTMASTER not PGC_SIGHUP */
2328 {"autovacuum_freeze_max_age", PGC_POSTMASTER, AUTOVACUUM,
2329 gettext_noop("Age at which to autovacuum a table to prevent transaction ID wraparound."),
2332 &autovacuum_freeze_max_age,
2333 /* see pg_resetxlog if you change the upper-limit value */
2334 200000000, 100000000, 2000000000,
2338 /* see max_connections */
2339 {"autovacuum_max_workers", PGC_POSTMASTER, AUTOVACUUM,
2340 gettext_noop("Sets the maximum number of simultaneously running autovacuum worker processes."),
2343 &autovacuum_max_workers,
2345 check_autovacuum_max_workers, NULL, NULL
2349 {"tcp_keepalives_idle", PGC_USERSET, CLIENT_CONN_OTHER,
2350 gettext_noop("Time between issuing TCP keepalives."),
2351 gettext_noop("A value of 0 uses the system default."),
2354 &tcp_keepalives_idle,
2356 NULL, assign_tcp_keepalives_idle, show_tcp_keepalives_idle
2360 {"tcp_keepalives_interval", PGC_USERSET, CLIENT_CONN_OTHER,
2361 gettext_noop("Time between TCP keepalive retransmits."),
2362 gettext_noop("A value of 0 uses the system default."),
2365 &tcp_keepalives_interval,
2367 NULL, assign_tcp_keepalives_interval, show_tcp_keepalives_interval
2371 {"ssl_renegotiation_limit", PGC_USERSET, CONN_AUTH_SECURITY,
2372 gettext_noop("Set the amount of traffic to send and receive before renegotiating the encryption keys."),
2376 &ssl_renegotiation_limit,
2377 512 * 1024, 0, MAX_KILOBYTES,
2382 {"tcp_keepalives_count", PGC_USERSET, CLIENT_CONN_OTHER,
2383 gettext_noop("Maximum number of TCP keepalive retransmits."),
2384 gettext_noop("This controls the number of consecutive keepalive retransmits that can be "
2385 "lost before a connection is considered dead. A value of 0 uses the "
2388 &tcp_keepalives_count,
2390 NULL, assign_tcp_keepalives_count, show_tcp_keepalives_count
2394 {"gin_fuzzy_search_limit", PGC_USERSET, CLIENT_CONN_OTHER,
2395 gettext_noop("Sets the maximum allowed result for exact search by GIN."),
2399 &GinFuzzySearchLimit,
2405 {"effective_cache_size", PGC_USERSET, QUERY_TUNING_COST,
2406 gettext_noop("Sets the planner's assumption about the size of the disk cache."),
2407 gettext_noop("That is, the portion of the kernel's disk cache that "
2408 "will be used for PostgreSQL data files. This is measured in disk "
2409 "pages, which are normally 8 kB each."),
2412 &effective_cache_size,
2414 check_effective_cache_size, NULL, NULL
2418 /* Can't be set in postgresql.conf */
2419 {"server_version_num", PGC_INTERNAL, PRESET_OPTIONS,
2420 gettext_noop("Shows the server version as an integer."),
2422 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2424 &server_version_num,
2425 PG_VERSION_NUM, PG_VERSION_NUM, PG_VERSION_NUM,
2430 {"log_temp_files", PGC_SUSET, LOGGING_WHAT,
2431 gettext_noop("Log the use of temporary files larger than this number of kilobytes."),
2432 gettext_noop("Zero logs all files. The default is -1 (turning this feature off)."),
2441 {"track_activity_query_size", PGC_POSTMASTER, RESOURCES_MEM,
2442 gettext_noop("Sets the size reserved for pg_stat_activity.query, in bytes."),
2445 &pgstat_track_activity_query_size,
2450 /* End-of-list marker */
2452 {NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL, NULL
2457 static struct config_real ConfigureNamesReal[] =
2460 {"seq_page_cost", PGC_USERSET, QUERY_TUNING_COST,
2461 gettext_noop("Sets the planner's estimate of the cost of a "
2462 "sequentially fetched disk page."),
2466 DEFAULT_SEQ_PAGE_COST, 0, DBL_MAX,
2470 {"random_page_cost", PGC_USERSET, QUERY_TUNING_COST,
2471 gettext_noop("Sets the planner's estimate of the cost of a "
2472 "nonsequentially fetched disk page."),
2476 DEFAULT_RANDOM_PAGE_COST, 0, DBL_MAX,
2480 {"cpu_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
2481 gettext_noop("Sets the planner's estimate of the cost of "
2482 "processing each tuple (row)."),
2486 DEFAULT_CPU_TUPLE_COST, 0, DBL_MAX,
2490 {"cpu_index_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
2491 gettext_noop("Sets the planner's estimate of the cost of "
2492 "processing each index entry during an index scan."),
2495 &cpu_index_tuple_cost,
2496 DEFAULT_CPU_INDEX_TUPLE_COST, 0, DBL_MAX,
2500 {"cpu_operator_cost", PGC_USERSET, QUERY_TUNING_COST,
2501 gettext_noop("Sets the planner's estimate of the cost of "
2502 "processing each operator or function call."),
2506 DEFAULT_CPU_OPERATOR_COST, 0, DBL_MAX,
2511 {"cursor_tuple_fraction", PGC_USERSET, QUERY_TUNING_OTHER,
2512 gettext_noop("Sets the planner's estimate of the fraction of "
2513 "a cursor's rows that will be retrieved."),
2516 &cursor_tuple_fraction,
2517 DEFAULT_CURSOR_TUPLE_FRACTION, 0.0, 1.0,
2522 {"geqo_selection_bias", PGC_USERSET, QUERY_TUNING_GEQO,
2523 gettext_noop("GEQO: selective pressure within the population."),
2526 &Geqo_selection_bias,
2527 DEFAULT_GEQO_SELECTION_BIAS,
2528 MIN_GEQO_SELECTION_BIAS, MAX_GEQO_SELECTION_BIAS,
2532 {"geqo_seed", PGC_USERSET, QUERY_TUNING_GEQO,
2533 gettext_noop("GEQO: seed for random path selection."),
2542 {"bgwriter_lru_multiplier", PGC_SIGHUP, RESOURCES_BGWRITER,
2543 gettext_noop("Multiple of the average buffer usage to free per round."),
2546 &bgwriter_lru_multiplier,
2552 {"seed", PGC_USERSET, UNGROUPED,
2553 gettext_noop("Sets the seed for random-number generation."),
2555 GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2559 check_random_seed, assign_random_seed, show_random_seed
2563 {"autovacuum_vacuum_scale_factor", PGC_SIGHUP, AUTOVACUUM,
2564 gettext_noop("Number of tuple updates or deletes prior to vacuum as a fraction of reltuples."),
2567 &autovacuum_vac_scale,
2572 {"autovacuum_analyze_scale_factor", PGC_SIGHUP, AUTOVACUUM,
2573 gettext_noop("Number of tuple inserts, updates, or deletes prior to analyze as a fraction of reltuples."),
2576 &autovacuum_anl_scale,
2582 {"checkpoint_completion_target", PGC_SIGHUP, WAL_CHECKPOINTS,
2583 gettext_noop("Time spent flushing dirty buffers during checkpoint, as fraction of checkpoint interval."),
2586 &CheckPointCompletionTarget,
2591 /* End-of-list marker */
2593 {NULL, 0, 0, NULL, NULL}, NULL, 0.0, 0.0, 0.0, NULL, NULL, NULL
2598 static struct config_string ConfigureNamesString[] =
2601 {"archive_command", PGC_SIGHUP, WAL_ARCHIVING,
2602 gettext_noop("Sets the shell command that will be called to archive a WAL file."),
2605 &XLogArchiveCommand,
2607 NULL, NULL, show_archive_command
2611 {"client_encoding", PGC_USERSET, CLIENT_CONN_LOCALE,
2612 gettext_noop("Sets the client's character set encoding."),
2614 GUC_IS_NAME | GUC_REPORT
2616 &client_encoding_string,
2618 check_client_encoding, assign_client_encoding, NULL
2622 {"log_line_prefix", PGC_SIGHUP, LOGGING_WHAT,
2623 gettext_noop("Controls information prefixed to each log line."),
2624 gettext_noop("If blank, no prefix is used.")
2632 {"log_timezone", PGC_SIGHUP, LOGGING_WHAT,
2633 gettext_noop("Sets the time zone to use in log messages."),
2636 &log_timezone_string,
2638 check_log_timezone, assign_log_timezone, show_log_timezone
2642 {"DateStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
2643 gettext_noop("Sets the display format for date and time values."),
2644 gettext_noop("Also controls interpretation of ambiguous "
2646 GUC_LIST_INPUT | GUC_REPORT
2650 check_datestyle, assign_datestyle, NULL
2654 {"default_tablespace", PGC_USERSET, CLIENT_CONN_STATEMENT,
2655 gettext_noop("Sets the default tablespace to create tables and indexes in."),
2656 gettext_noop("An empty string selects the database's default tablespace."),
2659 &default_tablespace,
2661 check_default_tablespace, NULL, NULL
2665 {"temp_tablespaces", PGC_USERSET, CLIENT_CONN_STATEMENT,
2666 gettext_noop("Sets the tablespace(s) to use for temporary tables and sort files."),
2668 GUC_LIST_INPUT | GUC_LIST_QUOTE
2672 check_temp_tablespaces, assign_temp_tablespaces, NULL
2676 {"dynamic_library_path", PGC_SUSET, CLIENT_CONN_OTHER,
2677 gettext_noop("Sets the path for dynamically loadable modules."),
2678 gettext_noop("If a dynamically loadable module needs to be opened and "
2679 "the specified name does not have a directory component (i.e., the "
2680 "name does not contain a slash), the system will search this path for "
2681 "the specified file."),
2684 &Dynamic_library_path,
2690 {"krb_server_keyfile", PGC_SIGHUP, CONN_AUTH_SECURITY,
2691 gettext_noop("Sets the location of the Kerberos server key file."),
2695 &pg_krb_server_keyfile,
2701 {"krb_srvname", PGC_SIGHUP, CONN_AUTH_SECURITY,
2702 gettext_noop("Sets the name of the Kerberos service."),
2711 {"bonjour_name", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2712 gettext_noop("Sets the Bonjour service name."),
2720 /* See main.c about why defaults for LC_foo are not all alike */
2723 {"lc_collate", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2724 gettext_noop("Shows the collation order locale."),
2726 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2734 {"lc_ctype", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2735 gettext_noop("Shows the character classification and case conversion locale."),
2737 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2745 {"lc_messages", PGC_SUSET, CLIENT_CONN_LOCALE,
2746 gettext_noop("Sets the language in which messages are displayed."),
2751 check_locale_messages, assign_locale_messages, NULL
2755 {"lc_monetary", PGC_USERSET, CLIENT_CONN_LOCALE,
2756 gettext_noop("Sets the locale for formatting monetary amounts."),
2761 check_locale_monetary, assign_locale_monetary, NULL
2765 {"lc_numeric", PGC_USERSET, CLIENT_CONN_LOCALE,
2766 gettext_noop("Sets the locale for formatting numbers."),
2771 check_locale_numeric, assign_locale_numeric, NULL
2775 {"lc_time", PGC_USERSET, CLIENT_CONN_LOCALE,
2776 gettext_noop("Sets the locale for formatting date and time values."),
2781 check_locale_time, assign_locale_time, NULL
2785 {"session_preload_libraries", PGC_SUSET, CLIENT_CONN_PRELOAD,
2786 gettext_noop("Lists shared libraries to preload into each backend."),
2788 GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
2790 &session_preload_libraries_string,
2796 {"shared_preload_libraries", PGC_POSTMASTER, CLIENT_CONN_PRELOAD,
2797 gettext_noop("Lists shared libraries to preload into server."),
2799 GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
2801 &shared_preload_libraries_string,
2807 {"local_preload_libraries", PGC_BACKEND, CLIENT_CONN_PRELOAD,
2808 gettext_noop("Lists unprivileged shared libraries to preload into each backend."),
2810 GUC_LIST_INPUT | GUC_LIST_QUOTE
2812 &local_preload_libraries_string,
2818 {"search_path", PGC_USERSET, CLIENT_CONN_STATEMENT,
2819 gettext_noop("Sets the schema search order for names that are not schema-qualified."),
2821 GUC_LIST_INPUT | GUC_LIST_QUOTE
2823 &namespace_search_path,
2825 check_search_path, assign_search_path, NULL
2829 /* Can't be set in postgresql.conf */
2830 {"server_encoding", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2831 gettext_noop("Sets the server (database) character set encoding."),
2833 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2835 &server_encoding_string,
2841 /* Can't be set in postgresql.conf */
2842 {"server_version", PGC_INTERNAL, PRESET_OPTIONS,
2843 gettext_noop("Shows the server version."),
2845 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2847 &server_version_string,
2853 /* Not for general use --- used by SET ROLE */
2854 {"role", PGC_USERSET, UNGROUPED,
2855 gettext_noop("Sets the current role."),
2857 GUC_IS_NAME | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_NOT_WHILE_SEC_REST
2861 check_role, assign_role, show_role
2865 /* Not for general use --- used by SET SESSION AUTHORIZATION */
2866 {"session_authorization", PGC_USERSET, UNGROUPED,
2867 gettext_noop("Sets the session user name."),
2869 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
2871 &session_authorization_string,
2873 check_session_authorization, assign_session_authorization, NULL
2877 {"log_destination", PGC_SIGHUP, LOGGING_WHERE,
2878 gettext_noop("Sets the destination for server log output."),
2879 gettext_noop("Valid values are combinations of \"stderr\", "
2880 "\"syslog\", \"csvlog\", and \"eventlog\", "
2881 "depending on the platform."),
2884 &Log_destination_string,
2886 check_log_destination, assign_log_destination, NULL
2889 {"log_directory", PGC_SIGHUP, LOGGING_WHERE,
2890 gettext_noop("Sets the destination directory for log files."),
2891 gettext_noop("Can be specified as relative to the data directory "
2892 "or as absolute path."),
2897 check_canonical_path, NULL, NULL
2900 {"log_filename", PGC_SIGHUP, LOGGING_WHERE,
2901 gettext_noop("Sets the file name pattern for log files."),
2906 "postgresql-%Y-%m-%d_%H%M%S.log",
2911 {"syslog_ident", PGC_SIGHUP, LOGGING_WHERE,
2912 gettext_noop("Sets the program name used to identify PostgreSQL "
2913 "messages in syslog."),
2918 NULL, assign_syslog_ident, NULL
2922 {"event_source", PGC_POSTMASTER, LOGGING_WHERE,
2923 gettext_noop("Sets the application name used to identify "
2924 "PostgreSQL messages in the event log."),
2933 {"TimeZone", PGC_USERSET, CLIENT_CONN_LOCALE,
2934 gettext_noop("Sets the time zone for displaying and interpreting time stamps."),
2940 check_timezone, assign_timezone, show_timezone
2943 {"timezone_abbreviations", PGC_USERSET, CLIENT_CONN_LOCALE,
2944 gettext_noop("Selects a file of time zone abbreviations."),
2947 &timezone_abbreviations_string,
2949 check_timezone_abbreviations, assign_timezone_abbreviations, NULL
2953 {"transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
2954 gettext_noop("Sets the current transaction's isolation level."),
2956 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2958 &XactIsoLevel_string,
2960 check_XactIsoLevel, assign_XactIsoLevel, show_XactIsoLevel
2964 {"unix_socket_group", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2965 gettext_noop("Sets the owning group of the Unix-domain socket."),
2966 gettext_noop("The owning user of the socket is always the user "
2967 "that starts the server.")
2975 {"unix_socket_directories", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2976 gettext_noop("Sets the directories where Unix-domain sockets will be created."),
2980 &Unix_socket_directories,
2981 #ifdef HAVE_UNIX_SOCKETS
2982 DEFAULT_PGSOCKET_DIR,
2990 {"listen_addresses", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2991 gettext_noop("Sets the host name or IP address(es) to listen to."),
3001 {"data_directory", PGC_POSTMASTER, FILE_LOCATIONS,
3002 gettext_noop("Sets the server's data directory."),
3012 {"config_file", PGC_POSTMASTER, FILE_LOCATIONS,
3013 gettext_noop("Sets the server's main configuration file."),
3015 GUC_DISALLOW_IN_FILE | GUC_SUPERUSER_ONLY
3023 {"hba_file", PGC_POSTMASTER, FILE_LOCATIONS,
3024 gettext_noop("Sets the server's \"hba\" configuration file."),
3034 {"ident_file", PGC_POSTMASTER, FILE_LOCATIONS,
3035 gettext_noop("Sets the server's \"ident\" configuration file."),
3045 {"external_pid_file", PGC_POSTMASTER, FILE_LOCATIONS,
3046 gettext_noop("Writes the postmaster PID to the specified file."),
3052 check_canonical_path, NULL, NULL
3056 {"ssl_cert_file", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3057 gettext_noop("Location of the SSL server certificate file."),
3066 {"ssl_key_file", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3067 gettext_noop("Location of the SSL server private key file."),
3076 {"ssl_ca_file", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3077 gettext_noop("Location of the SSL certificate authority file."),
3086 {"ssl_crl_file", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3087 gettext_noop("Location of the SSL certificate revocation list file."),
3096 {"stats_temp_directory", PGC_SIGHUP, STATS_COLLECTOR,
3097 gettext_noop("Writes temporary statistics files to the specified directory."),
3101 &pgstat_temp_directory,
3103 check_canonical_path, assign_pgstat_temp_directory, NULL
3107 {"synchronous_standby_names", PGC_SIGHUP, REPLICATION_MASTER,
3108 gettext_noop("List of names of potential synchronous standbys."),
3112 &SyncRepStandbyNames,
3114 check_synchronous_standby_names, NULL, NULL
3118 {"default_text_search_config", PGC_USERSET, CLIENT_CONN_LOCALE,
3119 gettext_noop("Sets default text search configuration."),
3123 "pg_catalog.simple",
3124 check_TSCurrentConfig, assign_TSCurrentConfig, NULL
3128 {"ssl_ciphers", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3129 gettext_noop("Sets the list of allowed SSL ciphers."),
3135 "DEFAULT:!LOW:!EXP:!MD5:@STRENGTH",
3143 {"application_name", PGC_USERSET, LOGGING_WHAT,
3144 gettext_noop("Sets the application name to be reported in statistics and logs."),
3146 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE
3150 check_application_name, assign_application_name, NULL
3153 /* End-of-list marker */
3155 {NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL, NULL
3160 static struct config_enum ConfigureNamesEnum[] =
3163 {"backslash_quote", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
3164 gettext_noop("Sets whether \"\\'\" is allowed in string literals."),
3168 BACKSLASH_QUOTE_SAFE_ENCODING, backslash_quote_options,
3173 {"bytea_output", PGC_USERSET, CLIENT_CONN_STATEMENT,
3174 gettext_noop("Sets the output format for bytea."),
3178 BYTEA_OUTPUT_HEX, bytea_output_options,
3183 {"client_min_messages", PGC_USERSET, LOGGING_WHEN,
3184 gettext_noop("Sets the message levels that are sent to the client."),
3185 gettext_noop("Each level includes all the levels that follow it. The later"
3186 " the level, the fewer messages are sent.")
3188 &client_min_messages,
3189 NOTICE, client_message_level_options,
3194 {"constraint_exclusion", PGC_USERSET, QUERY_TUNING_OTHER,
3195 gettext_noop("Enables the planner to use constraints to optimize queries."),
3196 gettext_noop("Table scans will be skipped if their constraints"
3197 " guarantee that no rows match the query.")
3199 &constraint_exclusion,
3200 CONSTRAINT_EXCLUSION_PARTITION, constraint_exclusion_options,
3205 {"default_transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
3206 gettext_noop("Sets the transaction isolation level of each new transaction."),
3209 &DefaultXactIsoLevel,
3210 XACT_READ_COMMITTED, isolation_level_options,
3215 {"IntervalStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
3216 gettext_noop("Sets the display format for interval values."),
3221 INTSTYLE_POSTGRES, intervalstyle_options,
3226 {"log_error_verbosity", PGC_SUSET, LOGGING_WHAT,
3227 gettext_noop("Sets the verbosity of logged messages."),
3230 &Log_error_verbosity,
3231 PGERROR_DEFAULT, log_error_verbosity_options,
3236 {"log_min_messages", PGC_SUSET, LOGGING_WHEN,
3237 gettext_noop("Sets the message levels that are logged."),
3238 gettext_noop("Each level includes all the levels that follow it. The later"
3239 " the level, the fewer messages are sent.")
3242 WARNING, server_message_level_options,
3247 {"log_min_error_statement", PGC_SUSET, LOGGING_WHEN,
3248 gettext_noop("Causes all statements generating error at or above this level to be logged."),
3249 gettext_noop("Each level includes all the levels that follow it. The later"
3250 " the level, the fewer messages are sent.")
3252 &log_min_error_statement,
3253 ERROR, server_message_level_options,
3258 {"log_statement", PGC_SUSET, LOGGING_WHAT,
3259 gettext_noop("Sets the type of statements logged."),
3263 LOGSTMT_NONE, log_statement_options,
3268 {"syslog_facility", PGC_SIGHUP, LOGGING_WHERE,
3269 gettext_noop("Sets the syslog \"facility\" to be used when syslog enabled."),
3278 syslog_facility_options,
3279 NULL, assign_syslog_facility, NULL
3283 {"session_replication_role", PGC_SUSET, CLIENT_CONN_STATEMENT,
3284 gettext_noop("Sets the session's behavior for triggers and rewrite rules."),
3287 &SessionReplicationRole,
3288 SESSION_REPLICATION_ROLE_ORIGIN, session_replication_role_options,
3289 NULL, assign_session_replication_role, NULL
3293 {"synchronous_commit", PGC_USERSET, WAL_SETTINGS,
3294 gettext_noop("Sets the current transaction's synchronization level."),
3297 &synchronous_commit,
3298 SYNCHRONOUS_COMMIT_ON, synchronous_commit_options,
3299 NULL, assign_synchronous_commit, NULL
3303 {"trace_recovery_messages", PGC_SIGHUP, DEVELOPER_OPTIONS,
3304 gettext_noop("Enables logging of recovery-related debugging information."),
3305 gettext_noop("Each level includes all the levels that follow it. The later"
3306 " the level, the fewer messages are sent.")
3308 &trace_recovery_messages,
3311 * client_message_level_options allows too many values, really, but
3312 * it's not worth having a separate options array for this.
3314 LOG, client_message_level_options,
3319 {"track_functions", PGC_SUSET, STATS_COLLECTOR,
3320 gettext_noop("Collects function-level statistics on database activity."),
3323 &pgstat_track_functions,
3324 TRACK_FUNC_OFF, track_function_options,
3329 {"wal_level", PGC_POSTMASTER, WAL_SETTINGS,
3330 gettext_noop("Set the level of information written to the WAL."),
3334 WAL_LEVEL_MINIMAL, wal_level_options,
3339 {"wal_sync_method", PGC_SIGHUP, WAL_SETTINGS,
3340 gettext_noop("Selects the method used for forcing WAL updates to disk."),
3344 DEFAULT_SYNC_METHOD, sync_method_options,
3345 NULL, assign_xlog_sync_method, NULL
3349 {"xmlbinary", PGC_USERSET, CLIENT_CONN_STATEMENT,
3350 gettext_noop("Sets how binary values are to be encoded in XML."),
3354 XMLBINARY_BASE64, xmlbinary_options,
3359 {"xmloption", PGC_USERSET, CLIENT_CONN_STATEMENT,
3360 gettext_noop("Sets whether XML data in implicit parsing and serialization "
3361 "operations is to be considered as documents or content fragments."),
3365 XMLOPTION_CONTENT, xmloption_options,
3370 /* End-of-list marker */
3372 {NULL, 0, 0, NULL, NULL}, NULL, 0, NULL, NULL, NULL, NULL
3376 /******** end of options list ********/
3380 * To allow continued support of obsolete names for GUC variables, we apply
3381 * the following mappings to any unrecognized name. Note that an old name
3382 * should be mapped to a new one only if the new variable has very similar
3383 * semantics to the old.
3385 static const char *const map_old_guc_names[] = {
3386 "sort_mem", "work_mem",
3387 "vacuum_mem", "maintenance_work_mem",
3393 * Actual lookup of variables is done through this single, sorted array.
3395 static struct config_generic **guc_variables;
3397 /* Current number of variables contained in the vector */
3398 static int num_guc_variables;
3400 /* Vector capacity */
3401 static int size_guc_variables;
3404 static bool guc_dirty; /* TRUE if need to do commit/abort work */
3406 static bool reporting_enabled; /* TRUE to enable GUC_REPORT */
3408 static int GUCNestLevel = 0; /* 1 when in main transaction */
3411 static int guc_var_compare(const void *a, const void *b);
3412 static int guc_name_compare(const char *namea, const char *nameb);
3413 static void InitializeGUCOptionsFromEnvironment(void);
3414 static void InitializeOneGUCOption(struct config_generic * gconf);
3415 static void push_old_value(struct config_generic * gconf, GucAction action);
3416 static void ReportGUCOption(struct config_generic * record);
3417 static void reapply_stacked_values(struct config_generic * variable,
3418 struct config_string * pHolder,
3420 const char *curvalue,
3421 GucContext curscontext, GucSource cursource);
3422 static void ShowGUCConfigOption(const char *name, DestReceiver *dest);
3423 static void ShowAllGUCConfig(DestReceiver *dest);
3424 static char *_ShowOption(struct config_generic * record, bool use_units);
3425 static bool validate_option_array_item(const char *name, const char *value,
3426 bool skipIfNoPermissions);
3430 * Some infrastructure for checking malloc/strdup/realloc calls
3433 guc_malloc(int elevel, size_t size)
3437 /* Avoid unportable behavior of malloc(0) */
3440 data = malloc(size);
3443 (errcode(ERRCODE_OUT_OF_MEMORY),
3444 errmsg("out of memory")));
3449 guc_realloc(int elevel, void *old, size_t size)
3453 /* Avoid unportable behavior of realloc(NULL, 0) */
3454 if (old == NULL && size == 0)
3456 data = realloc(old, size);
3459 (errcode(ERRCODE_OUT_OF_MEMORY),
3460 errmsg("out of memory")));
3465 guc_strdup(int elevel, const char *src)
3472 (errcode(ERRCODE_OUT_OF_MEMORY),
3473 errmsg("out of memory")));
3479 * Detect whether strval is referenced anywhere in a GUC string item
3482 string_field_used(struct config_string * conf, char *strval)
3486 if (strval == *(conf->variable) ||
3487 strval == conf->reset_val ||
3488 strval == conf->boot_val)
3490 for (stack = conf->gen.stack; stack; stack = stack->prev)
3492 if (strval == stack->prior.val.stringval ||
3493 strval == stack->masked.val.stringval)
3500 * Support for assigning to a field of a string GUC item. Free the prior
3501 * value if it's not referenced anywhere else in the item (including stacked
3505 set_string_field(struct config_string * conf, char **field, char *newval)
3507 char *oldval = *field;
3509 /* Do the assignment */
3512 /* Free old value if it's not NULL and isn't referenced anymore */
3513 if (oldval && !string_field_used(conf, oldval))
3518 * Detect whether an "extra" struct is referenced anywhere in a GUC item
3521 extra_field_used(struct config_generic * gconf, void *extra)
3525 if (extra == gconf->extra)
3527 switch (gconf->vartype)
3530 if (extra == ((struct config_bool *) gconf)->reset_extra)
3534 if (extra == ((struct config_int *) gconf)->reset_extra)
3538 if (extra == ((struct config_real *) gconf)->reset_extra)
3542 if (extra == ((struct config_string *) gconf)->reset_extra)
3546 if (extra == ((struct config_enum *) gconf)->reset_extra)
3550 for (stack = gconf->stack; stack; stack = stack->prev)
3552 if (extra == stack->prior.extra ||
3553 extra == stack->masked.extra)
3561 * Support for assigning to an "extra" field of a GUC item. Free the prior
3562 * value if it's not referenced anywhere else in the item (including stacked
3566 set_extra_field(struct config_generic * gconf, void **field, void *newval)
3568 void *oldval = *field;
3570 /* Do the assignment */
3573 /* Free old value if it's not NULL and isn't referenced anymore */
3574 if (oldval && !extra_field_used(gconf, oldval))
3579 * Support for copying a variable's active value into a stack entry.
3580 * The "extra" field associated with the active value is copied, too.
3582 * NB: be sure stringval and extra fields of a new stack entry are
3583 * initialized to NULL before this is used, else we'll try to free() them.
3586 set_stack_value(struct config_generic * gconf, config_var_value *val)
3588 switch (gconf->vartype)
3592 *((struct config_bool *) gconf)->variable;
3596 *((struct config_int *) gconf)->variable;
3600 *((struct config_real *) gconf)->variable;
3603 set_string_field((struct config_string *) gconf,
3604 &(val->val.stringval),
3605 *((struct config_string *) gconf)->variable);
3609 *((struct config_enum *) gconf)->variable;
3612 set_extra_field(gconf, &(val->extra), gconf->extra);
3616 * Support for discarding a no-longer-needed value in a stack entry.
3617 * The "extra" field associated with the stack entry is cleared, too.
3620 discard_stack_value(struct config_generic * gconf, config_var_value *val)
3622 switch (gconf->vartype)
3628 /* no need to do anything */
3631 set_string_field((struct config_string *) gconf,
3632 &(val->val.stringval),
3636 set_extra_field(gconf, &(val->extra), NULL);
3641 * Fetch the sorted array pointer (exported for help_config.c's use ONLY)
3643 struct config_generic **
3644 get_guc_variables(void)
3646 return guc_variables;
3651 * Build the sorted array. This is split out so that it could be
3652 * re-executed after startup (eg, we could allow loadable modules to
3653 * add vars, and then we'd need to re-sort).
3656 build_guc_variables(void)
3660 struct config_generic **guc_vars;
3663 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
3665 struct config_bool *conf = &ConfigureNamesBool[i];
3667 /* Rather than requiring vartype to be filled in by hand, do this: */
3668 conf->gen.vartype = PGC_BOOL;
3672 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
3674 struct config_int *conf = &ConfigureNamesInt[i];
3676 conf->gen.vartype = PGC_INT;
3680 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
3682 struct config_real *conf = &ConfigureNamesReal[i];
3684 conf->gen.vartype = PGC_REAL;
3688 for (i = 0; ConfigureNamesString[i].gen.name; i++)
3690 struct config_string *conf = &ConfigureNamesString[i];
3692 conf->gen.vartype = PGC_STRING;
3696 for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
3698 struct config_enum *conf = &ConfigureNamesEnum[i];
3700 conf->gen.vartype = PGC_ENUM;
3705 * Create table with 20% slack
3707 size_vars = num_vars + num_vars / 4;
3709 guc_vars = (struct config_generic **)
3710 guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
3714 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
3715 guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
3717 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
3718 guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
3720 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
3721 guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
3723 for (i = 0; ConfigureNamesString[i].gen.name; i++)
3724 guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
3726 for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
3727 guc_vars[num_vars++] = &ConfigureNamesEnum[i].gen;
3730 free(guc_variables);
3731 guc_variables = guc_vars;
3732 num_guc_variables = num_vars;
3733 size_guc_variables = size_vars;
3734 qsort((void *) guc_variables, num_guc_variables,
3735 sizeof(struct config_generic *), guc_var_compare);
3739 * Add a new GUC variable to the list of known variables. The
3740 * list is expanded if needed.
3743 add_guc_variable(struct config_generic * var, int elevel)
3745 if (num_guc_variables + 1 >= size_guc_variables)
3748 * Increase the vector by 25%
3750 int size_vars = size_guc_variables + size_guc_variables / 4;
3751 struct config_generic **guc_vars;
3756 guc_vars = (struct config_generic **)
3757 guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
3761 guc_vars = (struct config_generic **)
3762 guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
3765 if (guc_vars == NULL)
3766 return false; /* out of memory */
3768 guc_variables = guc_vars;
3769 size_guc_variables = size_vars;
3771 guc_variables[num_guc_variables++] = var;
3772 qsort((void *) guc_variables, num_guc_variables,
3773 sizeof(struct config_generic *), guc_var_compare);
3778 * Create and add a placeholder variable for a custom variable name.
3780 static struct config_generic *
3781 add_placeholder_variable(const char *name, int elevel)
3783 size_t sz = sizeof(struct config_string) + sizeof(char *);
3784 struct config_string *var;
3785 struct config_generic *gen;
3787 var = (struct config_string *) guc_malloc(elevel, sz);
3793 gen->name = guc_strdup(elevel, name);
3794 if (gen->name == NULL)
3800 gen->context = PGC_USERSET;
3801 gen->group = CUSTOM_OPTIONS;
3802 gen->short_desc = "GUC placeholder variable";
3803 gen->flags = GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_CUSTOM_PLACEHOLDER;
3804 gen->vartype = PGC_STRING;
3807 * The char* is allocated at the end of the struct since we have no
3808 * 'static' place to point to. Note that the current value, as well as
3809 * the boot and reset values, start out NULL.
3811 var->variable = (char **) (var + 1);
3813 if (!add_guc_variable((struct config_generic *) var, elevel))
3815 free((void *) gen->name);
3824 * Look up option NAME. If it exists, return a pointer to its record,
3825 * else return NULL. If create_placeholders is TRUE, we'll create a
3826 * placeholder record for a valid-looking custom variable name.
3828 static struct config_generic *
3829 find_option(const char *name, bool create_placeholders, int elevel)
3831 const char **key = &name;
3832 struct config_generic **res;
3838 * By equating const char ** with struct config_generic *, we are assuming
3839 * the name field is first in config_generic.
3841 res = (struct config_generic **) bsearch((void *) &key,
3842 (void *) guc_variables,
3844 sizeof(struct config_generic *),
3850 * See if the name is an obsolete name for a variable. We assume that the
3851 * set of supported old names is short enough that a brute-force search is
3854 for (i = 0; map_old_guc_names[i] != NULL; i += 2)
3856 if (guc_name_compare(name, map_old_guc_names[i]) == 0)
3857 return find_option(map_old_guc_names[i + 1], false, elevel);
3860 if (create_placeholders)
3863 * Check if the name is qualified, and if so, add a placeholder.
3865 if (strchr(name, GUC_QUALIFIER_SEPARATOR) != NULL)
3866 return add_placeholder_variable(name, elevel);
3875 * comparator for qsorting and bsearching guc_variables array
3878 guc_var_compare(const void *a, const void *b)
3880 const struct config_generic *confa = *(struct config_generic * const *) a;
3881 const struct config_generic *confb = *(struct config_generic * const *) b;
3883 return guc_name_compare(confa->name, confb->name);
3887 * the bare comparison function for GUC names
3890 guc_name_compare(const char *namea, const char *nameb)
3893 * The temptation to use strcasecmp() here must be resisted, because the
3894 * array ordering has to remain stable across setlocale() calls. So, build
3895 * our own with a simple ASCII-only downcasing.
3897 while (*namea && *nameb)
3899 char cha = *namea++;
3900 char chb = *nameb++;
3902 if (cha >= 'A' && cha <= 'Z')
3904 if (chb >= 'A' && chb <= 'Z')
3910 return 1; /* a is longer */
3912 return -1; /* b is longer */
3918 * Initialize GUC options during program startup.
3920 * Note that we cannot read the config file yet, since we have not yet
3921 * processed command-line switches.
3924 InitializeGUCOptions(void)
3929 * Before log_line_prefix could possibly receive a nonempty setting, make
3930 * sure that timezone processing is minimally alive (see elog.c).
3932 pg_timezone_initialize();
3935 * Build sorted array of all GUC variables.
3937 build_guc_variables();
3940 * Load all variables with their compiled-in defaults, and initialize
3941 * status fields as needed.
3943 for (i = 0; i < num_guc_variables; i++)
3945 InitializeOneGUCOption(guc_variables[i]);
3950 reporting_enabled = false;
3953 * Prevent any attempt to override the transaction modes from
3954 * non-interactive sources.
3956 SetConfigOption("transaction_isolation", "default",
3957 PGC_POSTMASTER, PGC_S_OVERRIDE);
3958 SetConfigOption("transaction_read_only", "no",
3959 PGC_POSTMASTER, PGC_S_OVERRIDE);
3960 SetConfigOption("transaction_deferrable", "no",
3961 PGC_POSTMASTER, PGC_S_OVERRIDE);
3964 * For historical reasons, some GUC parameters can receive defaults from
3965 * environment variables. Process those settings.
3967 InitializeGUCOptionsFromEnvironment();
3971 * Assign any GUC values that can come from the server's environment.
3973 * This is called from InitializeGUCOptions, and also from ProcessConfigFile
3974 * to deal with the possibility that a setting has been removed from
3975 * postgresql.conf and should now get a value from the environment.
3976 * (The latter is a kludge that should probably go away someday; if so,
3977 * fold this back into InitializeGUCOptions.)
3980 InitializeGUCOptionsFromEnvironment(void)
3985 env = getenv("PGPORT");
3987 SetConfigOption("port", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3989 env = getenv("PGDATESTYLE");
3991 SetConfigOption("datestyle", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3993 env = getenv("PGCLIENTENCODING");
3995 SetConfigOption("client_encoding", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
3998 * rlimit isn't exactly an "environment variable", but it behaves about
3999 * the same. If we can identify the platform stack depth rlimit, increase
4000 * default stack depth setting up to whatever is safe (but at most 2MB).
4002 stack_rlimit = get_stack_depth_rlimit();
4003 if (stack_rlimit > 0)
4005 long new_limit = (stack_rlimit - STACK_DEPTH_SLOP) / 1024L;
4007 if (new_limit > 100)
4011 new_limit = Min(new_limit, 2048);
4012 sprintf(limbuf, "%ld", new_limit);
4013 SetConfigOption("max_stack_depth", limbuf,
4014 PGC_POSTMASTER, PGC_S_ENV_VAR);
4020 * Initialize one GUC option variable to its compiled-in default.
4022 * Note: the reason for calling check_hooks is not that we think the boot_val
4023 * might fail, but that the hooks might wish to compute an "extra" struct.
4026 InitializeOneGUCOption(struct config_generic * gconf)
4029 gconf->source = PGC_S_DEFAULT;
4030 gconf->reset_source = PGC_S_DEFAULT;
4031 gconf->scontext = PGC_INTERNAL;
4032 gconf->reset_scontext = PGC_INTERNAL;
4033 gconf->stack = NULL;
4034 gconf->extra = NULL;
4035 gconf->sourcefile = NULL;
4036 gconf->sourceline = 0;
4038 switch (gconf->vartype)
4042 struct config_bool *conf = (struct config_bool *) gconf;
4043 bool newval = conf->boot_val;
4046 if (!call_bool_check_hook(conf, &newval, &extra,
4047 PGC_S_DEFAULT, LOG))
4048 elog(FATAL, "failed to initialize %s to %d",
4049 conf->gen.name, (int) newval);
4050 if (conf->assign_hook)
4051 (*conf->assign_hook) (newval, extra);
4052 *conf->variable = conf->reset_val = newval;
4053 conf->gen.extra = conf->reset_extra = extra;
4058 struct config_int *conf = (struct config_int *) gconf;
4059 int newval = conf->boot_val;
4062 Assert(newval >= conf->min);
4063 Assert(newval <= conf->max);
4064 if (!call_int_check_hook(conf, &newval, &extra,
4065 PGC_S_DEFAULT, LOG))
4066 elog(FATAL, "failed to initialize %s to %d",
4067 conf->gen.name, newval);
4068 if (conf->assign_hook)
4069 (*conf->assign_hook) (newval, extra);
4070 *conf->variable = conf->reset_val = newval;
4071 conf->gen.extra = conf->reset_extra = extra;
4076 struct config_real *conf = (struct config_real *) gconf;
4077 double newval = conf->boot_val;
4080 Assert(newval >= conf->min);
4081 Assert(newval <= conf->max);
4082 if (!call_real_check_hook(conf, &newval, &extra,
4083 PGC_S_DEFAULT, LOG))
4084 elog(FATAL, "failed to initialize %s to %g",
4085 conf->gen.name, newval);
4086 if (conf->assign_hook)
4087 (*conf->assign_hook) (newval, extra);
4088 *conf->variable = conf->reset_val = newval;
4089 conf->gen.extra = conf->reset_extra = extra;
4094 struct config_string *conf = (struct config_string *) gconf;
4098 /* non-NULL boot_val must always get strdup'd */
4099 if (conf->boot_val != NULL)
4100 newval = guc_strdup(FATAL, conf->boot_val);
4104 if (!call_string_check_hook(conf, &newval, &extra,
4105 PGC_S_DEFAULT, LOG))
4106 elog(FATAL, "failed to initialize %s to \"%s\"",
4107 conf->gen.name, newval ? newval : "");
4108 if (conf->assign_hook)
4109 (*conf->assign_hook) (newval, extra);
4110 *conf->variable = conf->reset_val = newval;
4111 conf->gen.extra = conf->reset_extra = extra;
4116 struct config_enum *conf = (struct config_enum *) gconf;
4117 int newval = conf->boot_val;
4120 if (!call_enum_check_hook(conf, &newval, &extra,
4121 PGC_S_DEFAULT, LOG))
4122 elog(FATAL, "failed to initialize %s to %d",
4123 conf->gen.name, newval);
4124 if (conf->assign_hook)
4125 (*conf->assign_hook) (newval, extra);
4126 *conf->variable = conf->reset_val = newval;
4127 conf->gen.extra = conf->reset_extra = extra;
4135 * Select the configuration files and data directory to be used, and
4136 * do the initial read of postgresql.conf.
4138 * This is called after processing command-line switches.
4139 * userDoption is the -D switch value if any (NULL if unspecified).
4140 * progname is just for use in error messages.
4142 * Returns true on success; on failure, prints a suitable error message
4143 * to stderr and returns false.
4146 SelectConfigFiles(const char *userDoption, const char *progname)
4150 struct stat stat_buf;
4152 /* configdir is -D option, or $PGDATA if no -D */
4154 configdir = make_absolute_path(userDoption);
4156 configdir = make_absolute_path(getenv("PGDATA"));
4159 * Find the configuration file: if config_file was specified on the
4160 * command line, use it, else use configdir/postgresql.conf. In any case
4161 * ensure the result is an absolute path, so that it will be interpreted
4162 * the same way by future backends.
4165 fname = make_absolute_path(ConfigFileName);
4168 fname = guc_malloc(FATAL,
4169 strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
4170 sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
4174 write_stderr("%s does not know where to find the server configuration file.\n"
4175 "You must specify the --config-file or -D invocation "
4176 "option or set the PGDATA environment variable.\n",
4182 * Set the ConfigFileName GUC variable to its final value, ensuring that
4183 * it can't be overridden later.
4185 SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4189 * Now read the config file for the first time.
4191 if (stat(ConfigFileName, &stat_buf) != 0)
4193 write_stderr("%s cannot access the server configuration file \"%s\": %s\n",
4194 progname, ConfigFileName, strerror(errno));
4199 ProcessConfigFile(PGC_POSTMASTER);
4202 * If the data_directory GUC variable has been set, use that as DataDir;
4203 * otherwise use configdir if set; else punt.
4205 * Note: SetDataDir will copy and absolute-ize its argument, so we don't
4209 SetDataDir(data_directory);
4211 SetDataDir(configdir);
4214 write_stderr("%s does not know where to find the database system data.\n"
4215 "This can be specified as \"data_directory\" in \"%s\", "
4216 "or by the -D invocation option, or by the "
4217 "PGDATA environment variable.\n",
4218 progname, ConfigFileName);
4223 * Reflect the final DataDir value back into the data_directory GUC var.
4224 * (If you are wondering why we don't just make them a single variable,
4225 * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
4226 * child backends specially. XXX is that still true? Given that we now
4227 * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
4228 * DataDir in advance.)
4230 SetConfigOption("data_directory", DataDir, PGC_POSTMASTER, PGC_S_OVERRIDE);
4233 * If timezone_abbreviations wasn't set in the configuration file, install
4234 * the default value. We do it this way because we can't safely install a
4235 * "real" value until my_exec_path is set, which may not have happened
4236 * when InitializeGUCOptions runs, so the bootstrap default value cannot
4237 * be the real desired default.
4239 pg_timezone_abbrev_initialize();
4242 * Figure out where pg_hba.conf is, and make sure the path is absolute.
4245 fname = make_absolute_path(HbaFileName);
4248 fname = guc_malloc(FATAL,
4249 strlen(configdir) + strlen(HBA_FILENAME) + 2);
4250 sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
4254 write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
4255 "This can be specified as \"hba_file\" in \"%s\", "
4256 "or by the -D invocation option, or by the "
4257 "PGDATA environment variable.\n",
4258 progname, ConfigFileName);
4261 SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4265 * Likewise for pg_ident.conf.
4268 fname = make_absolute_path(IdentFileName);
4271 fname = guc_malloc(FATAL,
4272 strlen(configdir) + strlen(IDENT_FILENAME) + 2);
4273 sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
4277 write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
4278 "This can be specified as \"ident_file\" in \"%s\", "
4279 "or by the -D invocation option, or by the "
4280 "PGDATA environment variable.\n",
4281 progname, ConfigFileName);
4284 SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4294 * Reset all options to their saved default values (implements RESET ALL)
4297 ResetAllOptions(void)
4301 for (i = 0; i < num_guc_variables; i++)
4303 struct config_generic *gconf = guc_variables[i];
4305 /* Don't reset non-SET-able values */
4306 if (gconf->context != PGC_SUSET &&
4307 gconf->context != PGC_USERSET)
4309 /* Don't reset if special exclusion from RESET ALL */
4310 if (gconf->flags & GUC_NO_RESET_ALL)
4312 /* No need to reset if wasn't SET */
4313 if (gconf->source <= PGC_S_OVERRIDE)
4316 /* Save old value to support transaction abort */
4317 push_old_value(gconf, GUC_ACTION_SET);
4319 switch (gconf->vartype)
4323 struct config_bool *conf = (struct config_bool *) gconf;
4325 if (conf->assign_hook)
4326 (*conf->assign_hook) (conf->reset_val,
4328 *conf->variable = conf->reset_val;
4329 set_extra_field(&conf->gen, &conf->gen.extra,
4335 struct config_int *conf = (struct config_int *) gconf;
4337 if (conf->assign_hook)
4338 (*conf->assign_hook) (conf->reset_val,
4340 *conf->variable = conf->reset_val;
4341 set_extra_field(&conf->gen, &conf->gen.extra,
4347 struct config_real *conf = (struct config_real *) gconf;
4349 if (conf->assign_hook)
4350 (*conf->assign_hook) (conf->reset_val,
4352 *conf->variable = conf->reset_val;
4353 set_extra_field(&conf->gen, &conf->gen.extra,
4359 struct config_string *conf = (struct config_string *) gconf;
4361 if (conf->assign_hook)
4362 (*conf->assign_hook) (conf->reset_val,
4364 set_string_field(conf, conf->variable, conf->reset_val);
4365 set_extra_field(&conf->gen, &conf->gen.extra,
4371 struct config_enum *conf = (struct config_enum *) gconf;
4373 if (conf->assign_hook)
4374 (*conf->assign_hook) (conf->reset_val,
4376 *conf->variable = conf->reset_val;
4377 set_extra_field(&conf->gen, &conf->gen.extra,
4383 gconf->source = gconf->reset_source;
4384 gconf->scontext = gconf->reset_scontext;
4386 if (gconf->flags & GUC_REPORT)
4387 ReportGUCOption(gconf);
4394 * Push previous state during transactional assignment to a GUC variable.
4397 push_old_value(struct config_generic * gconf, GucAction action)
4401 /* If we're not inside a nest level, do nothing */
4402 if (GUCNestLevel == 0)
4405 /* Do we already have a stack entry of the current nest level? */
4406 stack = gconf->stack;
4407 if (stack && stack->nest_level >= GUCNestLevel)
4409 /* Yes, so adjust its state if necessary */
4410 Assert(stack->nest_level == GUCNestLevel);
4413 case GUC_ACTION_SET:
4414 /* SET overrides any prior action at same nest level */
4415 if (stack->state == GUC_SET_LOCAL)
4417 /* must discard old masked value */
4418 discard_stack_value(gconf, &stack->masked);
4420 stack->state = GUC_SET;
4422 case GUC_ACTION_LOCAL:
4423 if (stack->state == GUC_SET)
4425 /* SET followed by SET LOCAL, remember SET's value */
4426 stack->masked_scontext = gconf->scontext;
4427 set_stack_value(gconf, &stack->masked);
4428 stack->state = GUC_SET_LOCAL;
4430 /* in all other cases, no change to stack entry */
4432 case GUC_ACTION_SAVE:
4433 /* Could only have a prior SAVE of same variable */
4434 Assert(stack->state == GUC_SAVE);
4437 Assert(guc_dirty); /* must be set already */
4442 * Push a new stack entry
4444 * We keep all the stack entries in TopTransactionContext for simplicity.
4446 stack = (GucStack *) MemoryContextAllocZero(TopTransactionContext,
4449 stack->prev = gconf->stack;
4450 stack->nest_level = GUCNestLevel;
4453 case GUC_ACTION_SET:
4454 stack->state = GUC_SET;
4456 case GUC_ACTION_LOCAL:
4457 stack->state = GUC_LOCAL;
4459 case GUC_ACTION_SAVE:
4460 stack->state = GUC_SAVE;
4463 stack->source = gconf->source;
4464 stack->scontext = gconf->scontext;
4465 set_stack_value(gconf, &stack->prior);
4467 gconf->stack = stack;
4469 /* Ensure we remember to pop at end of xact */
4475 * Do GUC processing at main transaction start.
4481 * The nest level should be 0 between transactions; if it isn't, somebody
4482 * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
4483 * throw a warning but make no other effort to clean up.
4485 if (GUCNestLevel != 0)
4486 elog(WARNING, "GUC nest level = %d at transaction start",
4492 * Enter a new nesting level for GUC values. This is called at subtransaction
4493 * start, and when entering a function that has proconfig settings, and in
4494 * some other places where we want to set GUC variables transiently.
4495 * NOTE we must not risk error here, else subtransaction start will be unhappy.
4498 NewGUCNestLevel(void)
4500 return ++GUCNestLevel;
4504 * Do GUC processing at transaction or subtransaction commit or abort, or
4505 * when exiting a function that has proconfig settings, or when undoing a
4506 * transient assignment to some GUC variables. (The name is thus a bit of
4507 * a misnomer; perhaps it should be ExitGUCNestLevel or some such.)
4508 * During abort, we discard all GUC settings that were applied at nesting
4509 * levels >= nestLevel. nestLevel == 1 corresponds to the main transaction.
4512 AtEOXact_GUC(bool isCommit, int nestLevel)
4518 * Note: it's possible to get here with GUCNestLevel == nestLevel-1 during
4519 * abort, if there is a failure during transaction start before
4520 * AtStart_GUC is called.
4522 Assert(nestLevel > 0 &&
4523 (nestLevel <= GUCNestLevel ||
4524 (nestLevel == GUCNestLevel + 1 && !isCommit)));
4526 /* Quick exit if nothing's changed in this transaction */
4529 GUCNestLevel = nestLevel - 1;
4533 still_dirty = false;
4534 for (i = 0; i < num_guc_variables; i++)
4536 struct config_generic *gconf = guc_variables[i];
4540 * Process and pop each stack entry within the nest level. To simplify
4541 * fmgr_security_definer() and other places that use GUC_ACTION_SAVE,
4542 * we allow failure exit from code that uses a local nest level to be
4543 * recovered at the surrounding transaction or subtransaction abort;
4544 * so there could be more than one stack entry to pop.
4546 while ((stack = gconf->stack) != NULL &&
4547 stack->nest_level >= nestLevel)
4549 GucStack *prev = stack->prev;
4550 bool restorePrior = false;
4551 bool restoreMasked = false;
4555 * In this next bit, if we don't set either restorePrior or
4556 * restoreMasked, we must "discard" any unwanted fields of the
4557 * stack entries to avoid leaking memory. If we do set one of
4558 * those flags, unused fields will be cleaned up after restoring.
4560 if (!isCommit) /* if abort, always restore prior value */
4561 restorePrior = true;
4562 else if (stack->state == GUC_SAVE)
4563 restorePrior = true;
4564 else if (stack->nest_level == 1)
4566 /* transaction commit */
4567 if (stack->state == GUC_SET_LOCAL)
4568 restoreMasked = true;
4569 else if (stack->state == GUC_SET)
4571 /* we keep the current active value */
4572 discard_stack_value(gconf, &stack->prior);
4574 else /* must be GUC_LOCAL */
4575 restorePrior = true;
4577 else if (prev == NULL ||
4578 prev->nest_level < stack->nest_level - 1)
4580 /* decrement entry's level and do not pop it */
4581 stack->nest_level--;
4587 * We have to merge this stack entry into prev. See README for
4588 * discussion of this bit.
4590 switch (stack->state)
4593 Assert(false); /* can't get here */
4596 /* next level always becomes SET */
4597 discard_stack_value(gconf, &stack->prior);
4598 if (prev->state == GUC_SET_LOCAL)
4599 discard_stack_value(gconf, &prev->masked);
4600 prev->state = GUC_SET;
4604 if (prev->state == GUC_SET)
4606 /* LOCAL migrates down */
4607 prev->masked_scontext = stack->scontext;
4608 prev->masked = stack->prior;
4609 prev->state = GUC_SET_LOCAL;
4613 /* else just forget this stack level */
4614 discard_stack_value(gconf, &stack->prior);
4619 /* prior state at this level no longer wanted */
4620 discard_stack_value(gconf, &stack->prior);
4621 /* copy down the masked state */
4622 prev->masked_scontext = stack->masked_scontext;
4623 if (prev->state == GUC_SET_LOCAL)
4624 discard_stack_value(gconf, &prev->masked);
4625 prev->masked = stack->masked;
4626 prev->state = GUC_SET_LOCAL;
4633 if (restorePrior || restoreMasked)
4635 /* Perform appropriate restoration of the stacked value */
4636 config_var_value newvalue;
4637 GucSource newsource;
4638 GucContext newscontext;
4642 newvalue = stack->masked;
4643 newsource = PGC_S_SESSION;
4644 newscontext = stack->masked_scontext;
4648 newvalue = stack->prior;
4649 newsource = stack->source;
4650 newscontext = stack->scontext;
4653 switch (gconf->vartype)
4657 struct config_bool *conf = (struct config_bool *) gconf;
4658 bool newval = newvalue.val.boolval;
4659 void *newextra = newvalue.extra;
4661 if (*conf->variable != newval ||
4662 conf->gen.extra != newextra)
4664 if (conf->assign_hook)
4665 (*conf->assign_hook) (newval, newextra);
4666 *conf->variable = newval;
4667 set_extra_field(&conf->gen, &conf->gen.extra,
4675 struct config_int *conf = (struct config_int *) gconf;
4676 int newval = newvalue.val.intval;
4677 void *newextra = newvalue.extra;
4679 if (*conf->variable != newval ||
4680 conf->gen.extra != newextra)
4682 if (conf->assign_hook)
4683 (*conf->assign_hook) (newval, newextra);
4684 *conf->variable = newval;
4685 set_extra_field(&conf->gen, &conf->gen.extra,
4693 struct config_real *conf = (struct config_real *) gconf;
4694 double newval = newvalue.val.realval;
4695 void *newextra = newvalue.extra;
4697 if (*conf->variable != newval ||
4698 conf->gen.extra != newextra)
4700 if (conf->assign_hook)
4701 (*conf->assign_hook) (newval, newextra);
4702 *conf->variable = newval;
4703 set_extra_field(&conf->gen, &conf->gen.extra,
4711 struct config_string *conf = (struct config_string *) gconf;
4712 char *newval = newvalue.val.stringval;
4713 void *newextra = newvalue.extra;
4715 if (*conf->variable != newval ||
4716 conf->gen.extra != newextra)
4718 if (conf->assign_hook)
4719 (*conf->assign_hook) (newval, newextra);
4720 set_string_field(conf, conf->variable, newval);
4721 set_extra_field(&conf->gen, &conf->gen.extra,
4727 * Release stacked values if not used anymore. We
4728 * could use discard_stack_value() here, but since
4729 * we have type-specific code anyway, might as
4732 set_string_field(conf, &stack->prior.val.stringval, NULL);
4733 set_string_field(conf, &stack->masked.val.stringval, NULL);
4738 struct config_enum *conf = (struct config_enum *) gconf;
4739 int newval = newvalue.val.enumval;
4740 void *newextra = newvalue.extra;
4742 if (*conf->variable != newval ||
4743 conf->gen.extra != newextra)
4745 if (conf->assign_hook)
4746 (*conf->assign_hook) (newval, newextra);
4747 *conf->variable = newval;
4748 set_extra_field(&conf->gen, &conf->gen.extra,
4757 * Release stacked extra values if not used anymore.
4759 set_extra_field(gconf, &(stack->prior.extra), NULL);
4760 set_extra_field(gconf, &(stack->masked.extra), NULL);
4762 /* And restore source information */
4763 gconf->source = newsource;
4764 gconf->scontext = newscontext;
4767 /* Finish popping the state stack */
4768 gconf->stack = prev;
4771 /* Report new value if we changed it */
4772 if (changed && (gconf->flags & GUC_REPORT))
4773 ReportGUCOption(gconf);
4774 } /* end of stack-popping loop */
4780 /* If there are no remaining stack entries, we can reset guc_dirty */
4781 guc_dirty = still_dirty;
4783 /* Update nesting level */
4784 GUCNestLevel = nestLevel - 1;
4789 * Start up automatic reporting of changes to variables marked GUC_REPORT.
4790 * This is executed at completion of backend startup.
4793 BeginReportingGUCOptions(void)
4798 * Don't do anything unless talking to an interactive frontend of protocol
4801 if (whereToSendOutput != DestRemote ||
4802 PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
4805 reporting_enabled = true;
4807 /* Transmit initial values of interesting variables */
4808 for (i = 0; i < num_guc_variables; i++)
4810 struct config_generic *conf = guc_variables[i];
4812 if (conf->flags & GUC_REPORT)
4813 ReportGUCOption(conf);
4818 * ReportGUCOption: if appropriate, transmit option value to frontend
4821 ReportGUCOption(struct config_generic * record)
4823 if (reporting_enabled && (record->flags & GUC_REPORT))
4825 char *val = _ShowOption(record, false);
4826 StringInfoData msgbuf;
4828 pq_beginmessage(&msgbuf, 'S');
4829 pq_sendstring(&msgbuf, record->name);
4830 pq_sendstring(&msgbuf, val);
4831 pq_endmessage(&msgbuf);
4838 * Try to parse value as an integer. The accepted formats are the
4839 * usual decimal, octal, or hexadecimal formats, optionally followed by
4840 * a unit name if "flags" indicates a unit is allowed.
4842 * If the string parses okay, return true, else false.
4843 * If okay and result is not NULL, return the value in *result.
4844 * If not okay and hintmsg is not NULL, *hintmsg is set to a suitable
4845 * HINT message, or NULL if no hint provided.
4848 parse_int(const char *value, int *result, int flags, const char **hintmsg)
4853 /* To suppress compiler warnings, always set output params */
4859 /* We assume here that int64 is at least as wide as long */
4861 val = strtol(value, &endptr, 0);
4863 if (endptr == value)
4864 return false; /* no HINT for integer syntax error */
4866 if (errno == ERANGE || val != (int64) ((int32) val))
4869 *hintmsg = gettext_noop("Value exceeds integer range.");
4873 /* allow whitespace between integer and unit */
4874 while (isspace((unsigned char) *endptr))
4877 /* Handle possible unit */
4878 if (*endptr != '\0')
4881 * Note: the multiple-switch coding technique here is a bit tedious,
4882 * but seems necessary to avoid intermediate-value overflows.
4884 if (flags & GUC_UNIT_MEMORY)
4886 /* Set hint for use if no match or trailing garbage */
4888 *hintmsg = gettext_noop("Valid units for this parameter are \"kB\", \"MB\", \"GB\", and \"TB\".");
4890 #if BLCKSZ < 1024 || BLCKSZ > (1024*1024)
4891 #error BLCKSZ must be between 1KB and 1MB
4893 #if XLOG_BLCKSZ < 1024 || XLOG_BLCKSZ > (1024*1024)
4894 #error XLOG_BLCKSZ must be between 1KB and 1MB
4897 if (strncmp(endptr, "kB", 2) == 0)
4900 switch (flags & GUC_UNIT_MEMORY)
4902 case GUC_UNIT_BLOCKS:
4903 val /= (BLCKSZ / 1024);
4905 case GUC_UNIT_XBLOCKS:
4906 val /= (XLOG_BLCKSZ / 1024);
4910 else if (strncmp(endptr, "MB", 2) == 0)
4913 switch (flags & GUC_UNIT_MEMORY)
4918 case GUC_UNIT_BLOCKS:
4919 val *= KB_PER_MB / (BLCKSZ / 1024);
4921 case GUC_UNIT_XBLOCKS:
4922 val *= KB_PER_MB / (XLOG_BLCKSZ / 1024);
4926 else if (strncmp(endptr, "GB", 2) == 0)
4929 switch (flags & GUC_UNIT_MEMORY)
4934 case GUC_UNIT_BLOCKS:
4935 val *= KB_PER_GB / (BLCKSZ / 1024);
4937 case GUC_UNIT_XBLOCKS:
4938 val *= KB_PER_GB / (XLOG_BLCKSZ / 1024);
4942 else if (strncmp(endptr, "TB", 2) == 0)
4945 switch (flags & GUC_UNIT_MEMORY)
4950 case GUC_UNIT_BLOCKS:
4951 val *= KB_PER_TB / (BLCKSZ / 1024);
4953 case GUC_UNIT_XBLOCKS:
4954 val *= KB_PER_TB / (XLOG_BLCKSZ / 1024);
4959 else if (flags & GUC_UNIT_TIME)
4961 /* Set hint for use if no match or trailing garbage */
4963 *hintmsg = gettext_noop("Valid units for this parameter are \"ms\", \"s\", \"min\", \"h\", and \"d\".");
4965 if (strncmp(endptr, "ms", 2) == 0)
4968 switch (flags & GUC_UNIT_TIME)
4978 else if (strncmp(endptr, "s", 1) == 0)
4981 switch (flags & GUC_UNIT_TIME)
4991 else if (strncmp(endptr, "min", 3) == 0)
4994 switch (flags & GUC_UNIT_TIME)
5004 else if (strncmp(endptr, "h", 1) == 0)
5007 switch (flags & GUC_UNIT_TIME)
5020 else if (strncmp(endptr, "d", 1) == 0)
5023 switch (flags & GUC_UNIT_TIME)
5038 /* allow whitespace after unit */
5039 while (isspace((unsigned char) *endptr))
5042 if (*endptr != '\0')
5043 return false; /* appropriate hint, if any, already set */
5045 /* Check for overflow due to units conversion */
5046 if (val != (int64) ((int32) val))
5049 *hintmsg = gettext_noop("Value exceeds integer range.");
5055 *result = (int) val;
5062 * Try to parse value as a floating point number in the usual format.
5063 * If the string parses okay, return true, else false.
5064 * If okay and result is not NULL, return the value in *result.
5067 parse_real(const char *value, double *result)
5073 *result = 0; /* suppress compiler warning */
5076 val = strtod(value, &endptr);
5077 if (endptr == value || errno == ERANGE)
5080 /* allow whitespace after number */
5081 while (isspace((unsigned char) *endptr))
5083 if (*endptr != '\0')
5093 * Lookup the name for an enum option with the selected value.
5094 * Should only ever be called with known-valid values, so throws
5095 * an elog(ERROR) if the enum option is not found.
5097 * The returned string is a pointer to static data and not
5098 * allocated for modification.
5101 config_enum_lookup_by_value(struct config_enum * record, int val)
5103 const struct config_enum_entry *entry;
5105 for (entry = record->options; entry && entry->name; entry++)
5107 if (entry->val == val)
5111 elog(ERROR, "could not find enum option %d for %s",
5112 val, record->gen.name);
5113 return NULL; /* silence compiler */
5118 * Lookup the value for an enum option with the selected name
5119 * (case-insensitive).
5120 * If the enum option is found, sets the retval value and returns
5121 * true. If it's not found, return FALSE and retval is set to 0.
5124 config_enum_lookup_by_name(struct config_enum * record, const char *value,
5127 const struct config_enum_entry *entry;
5129 for (entry = record->options; entry && entry->name; entry++)
5131 if (pg_strcasecmp(value, entry->name) == 0)
5133 *retval = entry->val;
5144 * Return a list of all available options for an enum, excluding
5145 * hidden ones, separated by the given separator.
5146 * If prefix is non-NULL, it is added before the first enum value.
5147 * If suffix is non-NULL, it is added to the end of the string.
5150 config_enum_get_options(struct config_enum * record, const char *prefix,
5151 const char *suffix, const char *separator)
5153 const struct config_enum_entry *entry;
5154 StringInfoData retstr;
5157 initStringInfo(&retstr);
5158 appendStringInfoString(&retstr, prefix);
5160 seplen = strlen(separator);
5161 for (entry = record->options; entry && entry->name; entry++)
5165 appendStringInfoString(&retstr, entry->name);
5166 appendBinaryStringInfo(&retstr, separator, seplen);
5171 * All the entries may have been hidden, leaving the string empty if no
5172 * prefix was given. This indicates a broken GUC setup, since there is no
5173 * use for an enum without any values, so we just check to make sure we
5174 * don't write to invalid memory instead of actually trying to do
5175 * something smart with it.
5177 if (retstr.len >= seplen)
5179 /* Replace final separator */
5180 retstr.data[retstr.len - seplen] = '\0';
5181 retstr.len -= seplen;
5184 appendStringInfoString(&retstr, suffix);
5191 * Sets option `name' to given value.
5193 * The value should be a string, which will be parsed and converted to
5194 * the appropriate data type. The context and source parameters indicate
5195 * in which context this function is being called, so that it can apply the
5196 * access restrictions properly.
5198 * If value is NULL, set the option to its default value (normally the
5199 * reset_val, but if source == PGC_S_DEFAULT we instead use the boot_val).
5201 * action indicates whether to set the value globally in the session, locally
5202 * to the current top transaction, or just for the duration of a function call.
5204 * If changeVal is false then don't really set the option but do all
5205 * the checks to see if it would work.
5207 * elevel should normally be passed as zero, allowing this function to make
5208 * its standard choice of ereport level. However some callers need to be
5209 * able to override that choice; they should pass the ereport level to use.
5212 * +1: the value is valid and was successfully applied.
5213 * 0: the name or value is invalid (but see below).
5214 * -1: the value was not applied because of context, priority, or changeVal.
5216 * If there is an error (non-existing option, invalid value) then an
5217 * ereport(ERROR) is thrown *unless* this is called for a source for which
5218 * we don't want an ERROR (currently, those are defaults, the config file,
5219 * and per-database or per-user settings, as well as callers who specify
5220 * a less-than-ERROR elevel). In those cases we write a suitable error
5221 * message via ereport() and return 0.
5223 * See also SetConfigOption for an external interface.
5226 set_config_option(const char *name, const char *value,
5227 GucContext context, GucSource source,
5228 GucAction action, bool changeVal, int elevel)
5230 struct config_generic *record;
5231 bool prohibitValueChange = false;
5236 if (source == PGC_S_DEFAULT || source == PGC_S_FILE)
5239 * To avoid cluttering the log, only the postmaster bleats loudly
5240 * about problems with the config file.
5242 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
5244 else if (source == PGC_S_GLOBAL || source == PGC_S_DATABASE || source == PGC_S_USER ||
5245 source == PGC_S_DATABASE_USER)
5251 record = find_option(name, true, elevel);
5255 (errcode(ERRCODE_UNDEFINED_OBJECT),
5256 errmsg("unrecognized configuration parameter \"%s\"", name)));
5261 * Check if the option can be set at this time. See guc.h for the precise
5264 switch (record->context)
5267 if (context != PGC_INTERNAL)
5270 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5271 errmsg("parameter \"%s\" cannot be changed",
5276 case PGC_POSTMASTER:
5277 if (context == PGC_SIGHUP)
5280 * We are re-reading a PGC_POSTMASTER variable from
5281 * postgresql.conf. We can't change the setting, so we should
5282 * give a warning if the DBA tries to change it. However,
5283 * because of variant formats, canonicalization by check
5284 * hooks, etc, we can't just compare the given string directly
5285 * to what's stored. Set a flag to check below after we have
5286 * the final storable value.
5288 prohibitValueChange = true;
5290 else if (context != PGC_POSTMASTER)
5293 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5294 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5300 if (context != PGC_SIGHUP && context != PGC_POSTMASTER)
5303 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5304 errmsg("parameter \"%s\" cannot be changed now",
5310 * Hmm, the idea of the SIGHUP context is "ought to be global, but
5311 * can be changed after postmaster start". But there's nothing
5312 * that prevents a crafty administrator from sending SIGHUP
5313 * signals to individual backends only.
5317 if (context == PGC_SIGHUP)
5320 * If a PGC_BACKEND parameter is changed in the config file,
5321 * we want to accept the new value in the postmaster (whence
5322 * it will propagate to subsequently-started backends), but
5323 * ignore it in existing backends. This is a tad klugy, but
5324 * necessary because we don't re-read the config file during
5327 if (IsUnderPostmaster)
5330 else if (context != PGC_POSTMASTER && context != PGC_BACKEND &&
5331 source != PGC_S_CLIENT)
5334 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5335 errmsg("parameter \"%s\" cannot be set after connection start",
5341 if (context == PGC_USERSET || context == PGC_BACKEND)
5344 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5345 errmsg("permission denied to set parameter \"%s\"",
5356 * Disallow changing GUC_NOT_WHILE_SEC_REST values if we are inside a
5357 * security restriction context. We can reject this regardless of the GUC
5358 * context or source, mainly because sources that it might be reasonable
5359 * to override for won't be seen while inside a function.
5361 * Note: variables marked GUC_NOT_WHILE_SEC_REST should usually be marked
5362 * GUC_NO_RESET_ALL as well, because ResetAllOptions() doesn't check this.
5363 * An exception might be made if the reset value is assumed to be "safe".
5365 * Note: this flag is currently used for "session_authorization" and
5366 * "role". We need to prohibit changing these inside a local userid
5367 * context because when we exit it, GUC won't be notified, leaving things
5368 * out of sync. (This could be fixed by forcing a new GUC nesting level,
5369 * but that would change behavior in possibly-undesirable ways.) Also, we
5370 * prohibit changing these in a security-restricted operation because
5371 * otherwise RESET could be used to regain the session user's privileges.
5373 if (record->flags & GUC_NOT_WHILE_SEC_REST)
5375 if (InLocalUserIdChange())
5378 * Phrasing of this error message is historical, but it's the most
5382 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5383 errmsg("cannot set parameter \"%s\" within security-definer function",
5387 if (InSecurityRestrictedOperation())
5390 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5391 errmsg("cannot set parameter \"%s\" within security-restricted operation",
5398 * Should we set reset/stacked values? (If so, the behavior is not
5399 * transactional.) This is done either when we get a default value from
5400 * the database's/user's/client's default settings or when we reset a
5401 * value to its default.
5403 makeDefault = changeVal && (source <= PGC_S_OVERRIDE) &&
5404 ((value != NULL) || source == PGC_S_DEFAULT);
5407 * Ignore attempted set if overridden by previously processed setting.
5408 * However, if changeVal is false then plow ahead anyway since we are
5409 * trying to find out if the value is potentially good, not actually use
5410 * it. Also keep going if makeDefault is true, since we may want to set
5411 * the reset/stacked values even if we can't set the variable itself.
5413 if (record->source > source)
5415 if (changeVal && !makeDefault)
5417 elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
5425 * Evaluate value and set variable.
5427 switch (record->vartype)
5431 struct config_bool *conf = (struct config_bool *) record;
5433 void *newextra = NULL;
5437 if (!parse_bool(value, &newval))
5440 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5441 errmsg("parameter \"%s\" requires a Boolean value",
5445 if (!call_bool_check_hook(conf, &newval, &newextra,
5449 else if (source == PGC_S_DEFAULT)
5451 newval = conf->boot_val;
5452 if (!call_bool_check_hook(conf, &newval, &newextra,
5458 newval = conf->reset_val;
5459 newextra = conf->reset_extra;
5460 source = conf->gen.reset_source;
5461 context = conf->gen.reset_scontext;
5464 if (prohibitValueChange)
5466 if (*conf->variable != newval)
5469 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5470 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5479 /* Save old value to support transaction abort */
5481 push_old_value(&conf->gen, action);
5483 if (conf->assign_hook)
5484 (*conf->assign_hook) (newval, newextra);
5485 *conf->variable = newval;
5486 set_extra_field(&conf->gen, &conf->gen.extra,
5488 conf->gen.source = source;
5489 conf->gen.scontext = context;
5495 if (conf->gen.reset_source <= source)
5497 conf->reset_val = newval;
5498 set_extra_field(&conf->gen, &conf->reset_extra,
5500 conf->gen.reset_source = source;
5501 conf->gen.reset_scontext = context;
5503 for (stack = conf->gen.stack; stack; stack = stack->prev)
5505 if (stack->source <= source)
5507 stack->prior.val.boolval = newval;
5508 set_extra_field(&conf->gen, &stack->prior.extra,
5510 stack->source = source;
5511 stack->scontext = context;
5516 /* Perhaps we didn't install newextra anywhere */
5517 if (newextra && !extra_field_used(&conf->gen, newextra))
5524 struct config_int *conf = (struct config_int *) record;
5526 void *newextra = NULL;
5530 const char *hintmsg;
5532 if (!parse_int(value, &newval, conf->gen.flags, &hintmsg))
5535 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5536 errmsg("invalid value for parameter \"%s\": \"%s\"",
5538 hintmsg ? errhint("%s", _(hintmsg)) : 0));
5541 if (newval < conf->min || newval > conf->max)
5544 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5545 errmsg("%d is outside the valid range for parameter \"%s\" (%d .. %d)",
5546 newval, name, conf->min, conf->max)));
5549 if (!call_int_check_hook(conf, &newval, &newextra,
5553 else if (source == PGC_S_DEFAULT)
5555 newval = conf->boot_val;
5556 if (!call_int_check_hook(conf, &newval, &newextra,
5562 newval = conf->reset_val;
5563 newextra = conf->reset_extra;
5564 source = conf->gen.reset_source;
5565 context = conf->gen.reset_scontext;
5568 if (prohibitValueChange)
5570 if (*conf->variable != newval)
5573 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5574 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5583 /* Save old value to support transaction abort */
5585 push_old_value(&conf->gen, action);
5587 if (conf->assign_hook)
5588 (*conf->assign_hook) (newval, newextra);
5589 *conf->variable = newval;
5590 set_extra_field(&conf->gen, &conf->gen.extra,
5592 conf->gen.source = source;
5593 conf->gen.scontext = context;
5599 if (conf->gen.reset_source <= source)
5601 conf->reset_val = newval;
5602 set_extra_field(&conf->gen, &conf->reset_extra,
5604 conf->gen.reset_source = source;
5605 conf->gen.reset_scontext = context;
5607 for (stack = conf->gen.stack; stack; stack = stack->prev)
5609 if (stack->source <= source)
5611 stack->prior.val.intval = newval;
5612 set_extra_field(&conf->gen, &stack->prior.extra,
5614 stack->source = source;
5615 stack->scontext = context;
5620 /* Perhaps we didn't install newextra anywhere */
5621 if (newextra && !extra_field_used(&conf->gen, newextra))
5628 struct config_real *conf = (struct config_real *) record;
5630 void *newextra = NULL;
5634 if (!parse_real(value, &newval))
5637 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5638 errmsg("parameter \"%s\" requires a numeric value",
5642 if (newval < conf->min || newval > conf->max)
5645 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5646 errmsg("%g is outside the valid range for parameter \"%s\" (%g .. %g)",
5647 newval, name, conf->min, conf->max)));
5650 if (!call_real_check_hook(conf, &newval, &newextra,
5654 else if (source == PGC_S_DEFAULT)
5656 newval = conf->boot_val;
5657 if (!call_real_check_hook(conf, &newval, &newextra,
5663 newval = conf->reset_val;
5664 newextra = conf->reset_extra;
5665 source = conf->gen.reset_source;
5666 context = conf->gen.reset_scontext;
5669 if (prohibitValueChange)
5671 if (*conf->variable != newval)
5674 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5675 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5684 /* Save old value to support transaction abort */
5686 push_old_value(&conf->gen, action);
5688 if (conf->assign_hook)
5689 (*conf->assign_hook) (newval, newextra);
5690 *conf->variable = newval;
5691 set_extra_field(&conf->gen, &conf->gen.extra,
5693 conf->gen.source = source;
5694 conf->gen.scontext = context;
5700 if (conf->gen.reset_source <= source)
5702 conf->reset_val = newval;
5703 set_extra_field(&conf->gen, &conf->reset_extra,
5705 conf->gen.reset_source = source;
5706 conf->gen.reset_scontext = context;
5708 for (stack = conf->gen.stack; stack; stack = stack->prev)
5710 if (stack->source <= source)
5712 stack->prior.val.realval = newval;
5713 set_extra_field(&conf->gen, &stack->prior.extra,
5715 stack->source = source;
5716 stack->scontext = context;
5721 /* Perhaps we didn't install newextra anywhere */
5722 if (newextra && !extra_field_used(&conf->gen, newextra))
5729 struct config_string *conf = (struct config_string *) record;
5731 void *newextra = NULL;
5736 * The value passed by the caller could be transient, so
5737 * we always strdup it.
5739 newval = guc_strdup(elevel, value);
5744 * The only built-in "parsing" check we have is to apply
5745 * truncation if GUC_IS_NAME.
5747 if (conf->gen.flags & GUC_IS_NAME)
5748 truncate_identifier(newval, strlen(newval), true);
5750 if (!call_string_check_hook(conf, &newval, &newextra,
5757 else if (source == PGC_S_DEFAULT)
5759 /* non-NULL boot_val must always get strdup'd */
5760 if (conf->boot_val != NULL)
5762 newval = guc_strdup(elevel, conf->boot_val);
5769 if (!call_string_check_hook(conf, &newval, &newextra,
5779 * strdup not needed, since reset_val is already under
5782 newval = conf->reset_val;
5783 newextra = conf->reset_extra;
5784 source = conf->gen.reset_source;
5785 context = conf->gen.reset_scontext;
5788 if (prohibitValueChange)
5790 /* newval shouldn't be NULL, so we're a bit sloppy here */
5791 if (*conf->variable == NULL || newval == NULL ||
5792 strcmp(*conf->variable, newval) != 0)
5795 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5796 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5805 /* Save old value to support transaction abort */
5807 push_old_value(&conf->gen, action);
5809 if (conf->assign_hook)
5810 (*conf->assign_hook) (newval, newextra);
5811 set_string_field(conf, conf->variable, newval);
5812 set_extra_field(&conf->gen, &conf->gen.extra,
5814 conf->gen.source = source;
5815 conf->gen.scontext = context;
5822 if (conf->gen.reset_source <= source)
5824 set_string_field(conf, &conf->reset_val, newval);
5825 set_extra_field(&conf->gen, &conf->reset_extra,
5827 conf->gen.reset_source = source;
5828 conf->gen.reset_scontext = context;
5830 for (stack = conf->gen.stack; stack; stack = stack->prev)
5832 if (stack->source <= source)
5834 set_string_field(conf, &stack->prior.val.stringval,
5836 set_extra_field(&conf->gen, &stack->prior.extra,
5838 stack->source = source;
5839 stack->scontext = context;
5844 /* Perhaps we didn't install newval anywhere */
5845 if (newval && !string_field_used(conf, newval))
5847 /* Perhaps we didn't install newextra anywhere */
5848 if (newextra && !extra_field_used(&conf->gen, newextra))
5855 struct config_enum *conf = (struct config_enum *) record;
5857 void *newextra = NULL;
5861 if (!config_enum_lookup_by_name(conf, value, &newval))
5865 hintmsg = config_enum_get_options(conf,
5866 "Available values: ",
5870 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5871 errmsg("invalid value for parameter \"%s\": \"%s\"",
5873 hintmsg ? errhint("%s", _(hintmsg)) : 0));
5879 if (!call_enum_check_hook(conf, &newval, &newextra,
5883 else if (source == PGC_S_DEFAULT)
5885 newval = conf->boot_val;
5886 if (!call_enum_check_hook(conf, &newval, &newextra,
5892 newval = conf->reset_val;
5893 newextra = conf->reset_extra;
5894 source = conf->gen.reset_source;
5895 context = conf->gen.reset_scontext;
5898 if (prohibitValueChange)
5900 if (*conf->variable != newval)
5903 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5904 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5913 /* Save old value to support transaction abort */
5915 push_old_value(&conf->gen, action);
5917 if (conf->assign_hook)
5918 (*conf->assign_hook) (newval, newextra);
5919 *conf->variable = newval;
5920 set_extra_field(&conf->gen, &conf->gen.extra,
5922 conf->gen.source = source;
5923 conf->gen.scontext = context;
5929 if (conf->gen.reset_source <= source)
5931 conf->reset_val = newval;
5932 set_extra_field(&conf->gen, &conf->reset_extra,
5934 conf->gen.reset_source = source;
5935 conf->gen.reset_scontext = context;
5937 for (stack = conf->gen.stack; stack; stack = stack->prev)
5939 if (stack->source <= source)
5941 stack->prior.val.enumval = newval;
5942 set_extra_field(&conf->gen, &stack->prior.extra,
5944 stack->source = source;
5945 stack->scontext = context;
5950 /* Perhaps we didn't install newextra anywhere */
5951 if (newextra && !extra_field_used(&conf->gen, newextra))
5957 if (changeVal && (record->flags & GUC_REPORT))
5958 ReportGUCOption(record);
5960 return changeVal ? 1 : -1;
5965 * Set the fields for source file and line number the setting came from.
5968 set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
5970 struct config_generic *record;
5974 * To avoid cluttering the log, only the postmaster bleats loudly about
5975 * problems with the config file.
5977 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
5979 record = find_option(name, true, elevel);
5980 /* should not happen */
5982 elog(ERROR, "unrecognized configuration parameter \"%s\"", name);
5984 sourcefile = guc_strdup(elevel, sourcefile);
5985 if (record->sourcefile)
5986 free(record->sourcefile);
5987 record->sourcefile = sourcefile;
5988 record->sourceline = sourceline;
5992 * Set a config option to the given value.
5994 * See also set_config_option; this is just the wrapper to be called from
5995 * outside GUC. (This function should be used when possible, because its API
5996 * is more stable than set_config_option's.)
5998 * Note: there is no support here for setting source file/line, as it
5999 * is currently not needed.
6002 SetConfigOption(const char *name, const char *value,
6003 GucContext context, GucSource source)
6005 (void) set_config_option(name, value, context, source,
6006 GUC_ACTION_SET, true, 0);
6012 * Fetch the current value of the option `name', as a string.
6014 * If the option doesn't exist, return NULL if missing_ok is true (NOTE that
6015 * this cannot be distinguished from a string variable with a NULL value!),
6016 * otherwise throw an ereport and don't return.
6018 * If restrict_superuser is true, we also enforce that only superusers can
6019 * see GUC_SUPERUSER_ONLY variables. This should only be passed as true
6020 * in user-driven calls.
6022 * The string is *not* allocated for modification and is really only
6023 * valid until the next call to configuration related functions.
6026 GetConfigOption(const char *name, bool missing_ok, bool restrict_superuser)
6028 struct config_generic *record;
6029 static char buffer[256];
6031 record = find_option(name, false, ERROR);
6037 (errcode(ERRCODE_UNDEFINED_OBJECT),
6038 errmsg("unrecognized configuration parameter \"%s\"",
6041 if (restrict_superuser &&
6042 (record->flags & GUC_SUPERUSER_ONLY) &&
6045 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6046 errmsg("must be superuser to examine \"%s\"", name)));
6048 switch (record->vartype)
6051 return *((struct config_bool *) record)->variable ? "on" : "off";
6054 snprintf(buffer, sizeof(buffer), "%d",
6055 *((struct config_int *) record)->variable);
6059 snprintf(buffer, sizeof(buffer), "%g",
6060 *((struct config_real *) record)->variable);
6064 return *((struct config_string *) record)->variable;
6067 return config_enum_lookup_by_value((struct config_enum *) record,
6068 *((struct config_enum *) record)->variable);
6074 * Get the RESET value associated with the given option.
6076 * Note: this is not re-entrant, due to use of static result buffer;
6077 * not to mention that a string variable could have its reset_val changed.
6078 * Beware of assuming the result value is good for very long.
6081 GetConfigOptionResetString(const char *name)
6083 struct config_generic *record;
6084 static char buffer[256];
6086 record = find_option(name, false, ERROR);
6089 (errcode(ERRCODE_UNDEFINED_OBJECT),
6090 errmsg("unrecognized configuration parameter \"%s\"", name)));
6091 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
6093 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6094 errmsg("must be superuser to examine \"%s\"", name)));
6096 switch (record->vartype)
6099 return ((struct config_bool *) record)->reset_val ? "on" : "off";
6102 snprintf(buffer, sizeof(buffer), "%d",
6103 ((struct config_int *) record)->reset_val);
6107 snprintf(buffer, sizeof(buffer), "%g",
6108 ((struct config_real *) record)->reset_val);
6112 return ((struct config_string *) record)->reset_val;
6115 return config_enum_lookup_by_value((struct config_enum *) record,
6116 ((struct config_enum *) record)->reset_val);
6123 * flatten_set_variable_args
6124 * Given a parsenode List as emitted by the grammar for SET,
6125 * convert to the flat string representation used by GUC.
6127 * We need to be told the name of the variable the args are for, because
6128 * the flattening rules vary (ugh).
6130 * The result is NULL if args is NIL (ie, SET ... TO DEFAULT), otherwise
6131 * a palloc'd string.
6134 flatten_set_variable_args(const char *name, List *args)
6136 struct config_generic *record;
6141 /* Fast path if just DEFAULT */
6146 * Get flags for the variable; if it's not known, use default flags.
6147 * (Caller might throw error later, but not our business to do so here.)
6149 record = find_option(name, false, WARNING);
6151 flags = record->flags;
6155 /* Complain if list input and non-list variable */
6156 if ((flags & GUC_LIST_INPUT) == 0 &&
6157 list_length(args) != 1)
6159 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6160 errmsg("SET %s takes only one argument", name)));
6162 initStringInfo(&buf);
6165 * Each list member may be a plain A_Const node, or an A_Const within a
6166 * TypeCast; the latter case is supported only for ConstInterval arguments
6167 * (for SET TIME ZONE).
6171 Node *arg = (Node *) lfirst(l);
6173 TypeName *typeName = NULL;
6176 if (l != list_head(args))
6177 appendStringInfo(&buf, ", ");
6179 if (IsA(arg, TypeCast))
6181 TypeCast *tc = (TypeCast *) arg;
6184 typeName = tc->typeName;
6187 if (!IsA(arg, A_Const))
6188 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
6189 con = (A_Const *) arg;
6191 switch (nodeTag(&con->val))
6194 appendStringInfo(&buf, "%ld", intVal(&con->val));
6197 /* represented as a string, so just copy it */
6198 appendStringInfoString(&buf, strVal(&con->val));
6201 val = strVal(&con->val);
6202 if (typeName != NULL)
6205 * Must be a ConstInterval argument for TIME ZONE. Coerce
6206 * to interval and back to normalize the value and account
6214 typenameTypeIdAndMod(NULL, typeName, &typoid, &typmod);
6215 Assert(typoid == INTERVALOID);
6218 DirectFunctionCall3(interval_in,
6219 CStringGetDatum(val),
6220 ObjectIdGetDatum(InvalidOid),
6221 Int32GetDatum(typmod));
6224 DatumGetCString(DirectFunctionCall1(interval_out,
6226 appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
6231 * Plain string literal or identifier. For quote mode,
6232 * quote it if it's not a vanilla identifier.
6234 if (flags & GUC_LIST_QUOTE)
6235 appendStringInfoString(&buf, quote_identifier(val));
6237 appendStringInfoString(&buf, val);
6241 elog(ERROR, "unrecognized node type: %d",
6242 (int) nodeTag(&con->val));
6255 ExecSetVariableStmt(VariableSetStmt *stmt, bool isTopLevel)
6257 GucAction action = stmt->is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET;
6262 case VAR_SET_CURRENT:
6264 RequireTransactionChain(isTopLevel, "SET LOCAL");
6265 (void) set_config_option(stmt->name,
6266 ExtractSetVariableArgs(stmt),
6267 (superuser() ? PGC_SUSET : PGC_USERSET),
6275 * Special-case SQL syntaxes. The TRANSACTION and SESSION
6276 * CHARACTERISTICS cases effectively set more than one variable
6277 * per statement. TRANSACTION SNAPSHOT only takes one argument,
6278 * but we put it here anyway since it's a special case and not
6279 * related to any GUC variable.
6281 if (strcmp(stmt->name, "TRANSACTION") == 0)
6285 RequireTransactionChain(isTopLevel, "SET TRANSACTION");
6287 foreach(head, stmt->args)
6289 DefElem *item = (DefElem *) lfirst(head);
6291 if (strcmp(item->defname, "transaction_isolation") == 0)
6292 SetPGVariable("transaction_isolation",
6293 list_make1(item->arg), stmt->is_local);
6294 else if (strcmp(item->defname, "transaction_read_only") == 0)
6295 SetPGVariable("transaction_read_only",
6296 list_make1(item->arg), stmt->is_local);
6297 else if (strcmp(item->defname, "transaction_deferrable") == 0)
6298 SetPGVariable("transaction_deferrable",
6299 list_make1(item->arg), stmt->is_local);
6301 elog(ERROR, "unexpected SET TRANSACTION element: %s",
6305 else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
6309 foreach(head, stmt->args)
6311 DefElem *item = (DefElem *) lfirst(head);
6313 if (strcmp(item->defname, "transaction_isolation") == 0)
6314 SetPGVariable("default_transaction_isolation",
6315 list_make1(item->arg), stmt->is_local);
6316 else if (strcmp(item->defname, "transaction_read_only") == 0)
6317 SetPGVariable("default_transaction_read_only",
6318 list_make1(item->arg), stmt->is_local);
6319 else if (strcmp(item->defname, "transaction_deferrable") == 0)
6320 SetPGVariable("default_transaction_deferrable",
6321 list_make1(item->arg), stmt->is_local);
6323 elog(ERROR, "unexpected SET SESSION element: %s",
6327 else if (strcmp(stmt->name, "TRANSACTION SNAPSHOT") == 0)
6329 A_Const *con = (A_Const *) linitial(stmt->args);
6333 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6334 errmsg("SET LOCAL TRANSACTION SNAPSHOT is not implemented")));
6336 RequireTransactionChain(isTopLevel, "SET TRANSACTION");
6337 Assert(IsA(con, A_Const));
6338 Assert(nodeTag(&con->val) == T_String);
6339 ImportSnapshot(strVal(&con->val));
6342 elog(ERROR, "unexpected SET MULTI element: %s",
6345 case VAR_SET_DEFAULT:
6347 RequireTransactionChain(isTopLevel, "SET LOCAL");
6350 if (strcmp(stmt->name, "transaction_isolation") == 0)
6351 RequireTransactionChain(isTopLevel, "RESET TRANSACTION");
6353 (void) set_config_option(stmt->name,
6355 (superuser() ? PGC_SUSET : PGC_USERSET),
6368 * Get the value to assign for a VariableSetStmt, or NULL if it's RESET.
6369 * The result is palloc'd.
6371 * This is exported for use by actions such as ALTER ROLE SET.
6374 ExtractSetVariableArgs(VariableSetStmt *stmt)
6379 return flatten_set_variable_args(stmt->name, stmt->args);
6380 case VAR_SET_CURRENT:
6381 return GetConfigOptionByName(stmt->name, NULL);
6388 * SetPGVariable - SET command exported as an easily-C-callable function.
6390 * This provides access to SET TO value, as well as SET TO DEFAULT (expressed
6391 * by passing args == NIL), but not SET FROM CURRENT functionality.
6394 SetPGVariable(const char *name, List *args, bool is_local)
6396 char *argstring = flatten_set_variable_args(name, args);
6398 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
6399 (void) set_config_option(name,
6401 (superuser() ? PGC_SUSET : PGC_USERSET),
6403 is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET,
6409 * SET command wrapped as a SQL callable function.
6412 set_config_by_name(PG_FUNCTION_ARGS)
6419 if (PG_ARGISNULL(0))
6421 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
6422 errmsg("SET requires parameter name")));
6424 /* Get the GUC variable name */
6425 name = TextDatumGetCString(PG_GETARG_DATUM(0));
6427 /* Get the desired value or set to NULL for a reset request */
6428 if (PG_ARGISNULL(1))
6431 value = TextDatumGetCString(PG_GETARG_DATUM(1));
6434 * Get the desired state of is_local. Default to false if provided value
6437 if (PG_ARGISNULL(2))
6440 is_local = PG_GETARG_BOOL(2);
6442 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
6443 (void) set_config_option(name,
6445 (superuser() ? PGC_SUSET : PGC_USERSET),
6447 is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET,
6451 /* get the new current value */
6452 new_value = GetConfigOptionByName(name, NULL);
6454 /* Convert return string to text */
6455 PG_RETURN_TEXT_P(cstring_to_text(new_value));
6460 * Common code for DefineCustomXXXVariable subroutines: allocate the
6461 * new variable's config struct and fill in generic fields.
6463 static struct config_generic *
6464 init_custom_variable(const char *name,
6465 const char *short_desc,
6466 const char *long_desc,
6469 enum config_type type,
6472 struct config_generic *gen;
6475 * Only allow custom PGC_POSTMASTER variables to be created during shared
6476 * library preload; any later than that, we can't ensure that the value
6477 * doesn't change after startup. This is a fatal elog if it happens; just
6478 * erroring out isn't safe because we don't know what the calling loadable
6479 * module might already have hooked into.
6481 if (context == PGC_POSTMASTER &&
6482 !process_shared_preload_libraries_in_progress)
6483 elog(FATAL, "cannot create PGC_POSTMASTER variables after startup");
6485 gen = (struct config_generic *) guc_malloc(ERROR, sz);
6488 gen->name = guc_strdup(ERROR, name);
6489 gen->context = context;
6490 gen->group = CUSTOM_OPTIONS;
6491 gen->short_desc = short_desc;
6492 gen->long_desc = long_desc;
6494 gen->vartype = type;
6500 * Common code for DefineCustomXXXVariable subroutines: insert the new
6501 * variable into the GUC variable array, replacing any placeholder.
6504 define_custom_variable(struct config_generic * variable)
6506 const char *name = variable->name;
6507 const char **nameAddr = &name;
6508 struct config_string *pHolder;
6509 struct config_generic **res;
6512 * See if there's a placeholder by the same name.
6514 res = (struct config_generic **) bsearch((void *) &nameAddr,
6515 (void *) guc_variables,
6517 sizeof(struct config_generic *),
6522 * No placeholder to replace, so we can just add it ... but first,
6523 * make sure it's initialized to its default value.
6525 InitializeOneGUCOption(variable);
6526 add_guc_variable(variable, ERROR);
6531 * This better be a placeholder
6533 if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
6535 (errcode(ERRCODE_INTERNAL_ERROR),
6536 errmsg("attempt to redefine parameter \"%s\"", name)));
6538 Assert((*res)->vartype == PGC_STRING);
6539 pHolder = (struct config_string *) (*res);
6542 * First, set the variable to its default value. We must do this even
6543 * though we intend to immediately apply a new value, since it's possible
6544 * that the new value is invalid.
6546 InitializeOneGUCOption(variable);
6549 * Replace the placeholder. We aren't changing the name, so no re-sorting
6555 * Assign the string value(s) stored in the placeholder to the real
6556 * variable. Essentially, we need to duplicate all the active and stacked
6557 * values, but with appropriate validation and datatype adjustment.
6559 * If an assignment fails, we report a WARNING and keep going. We don't
6560 * want to throw ERROR for bad values, because it'd bollix the add-on
6561 * module that's presumably halfway through getting loaded. In such cases
6562 * the default or previous state will become active instead.
6565 /* First, apply the reset value if any */
6566 if (pHolder->reset_val)
6567 (void) set_config_option(name, pHolder->reset_val,
6568 pHolder->gen.reset_scontext,
6569 pHolder->gen.reset_source,
6570 GUC_ACTION_SET, true, WARNING);
6571 /* That should not have resulted in stacking anything */
6572 Assert(variable->stack == NULL);
6574 /* Now, apply current and stacked values, in the order they were stacked */
6575 reapply_stacked_values(variable, pHolder, pHolder->gen.stack,
6576 *(pHolder->variable),
6577 pHolder->gen.scontext, pHolder->gen.source);
6579 /* Also copy over any saved source-location information */
6580 if (pHolder->gen.sourcefile)
6581 set_config_sourcefile(name, pHolder->gen.sourcefile,
6582 pHolder->gen.sourceline);
6585 * Free up as much as we conveniently can of the placeholder structure.
6586 * (This neglects any stack items, so it's possible for some memory to be
6587 * leaked. Since this can only happen once per session per variable, it
6588 * doesn't seem worth spending much code on.)
6590 set_string_field(pHolder, pHolder->variable, NULL);
6591 set_string_field(pHolder, &pHolder->reset_val, NULL);
6597 * Recursive subroutine for define_custom_variable: reapply non-reset values
6599 * We recurse so that the values are applied in the same order as originally.
6600 * At each recursion level, apply the upper-level value (passed in) in the
6601 * fashion implied by the stack entry.
6604 reapply_stacked_values(struct config_generic * variable,
6605 struct config_string * pHolder,
6607 const char *curvalue,
6608 GucContext curscontext, GucSource cursource)
6610 const char *name = variable->name;
6611 GucStack *oldvarstack = variable->stack;
6615 /* First, recurse, so that stack items are processed bottom to top */
6616 reapply_stacked_values(variable, pHolder, stack->prev,
6617 stack->prior.val.stringval,
6618 stack->scontext, stack->source);
6620 /* See how to apply the passed-in value */
6621 switch (stack->state)
6624 (void) set_config_option(name, curvalue,
6625 curscontext, cursource,
6626 GUC_ACTION_SAVE, true, WARNING);
6630 (void) set_config_option(name, curvalue,
6631 curscontext, cursource,
6632 GUC_ACTION_SET, true, WARNING);
6636 (void) set_config_option(name, curvalue,
6637 curscontext, cursource,
6638 GUC_ACTION_LOCAL, true, WARNING);
6642 /* first, apply the masked value as SET */
6643 (void) set_config_option(name, stack->masked.val.stringval,
6644 stack->masked_scontext, PGC_S_SESSION,
6645 GUC_ACTION_SET, true, WARNING);
6646 /* then apply the current value as LOCAL */
6647 (void) set_config_option(name, curvalue,
6648 curscontext, cursource,
6649 GUC_ACTION_LOCAL, true, WARNING);
6653 /* If we successfully made a stack entry, adjust its nest level */
6654 if (variable->stack != oldvarstack)
6655 variable->stack->nest_level = stack->nest_level;
6660 * We are at the end of the stack. If the active/previous value is
6661 * different from the reset value, it must represent a previously
6662 * committed session value. Apply it, and then drop the stack entry
6663 * that set_config_option will have created under the impression that
6664 * this is to be just a transactional assignment. (We leak the stack
6667 if (curvalue != pHolder->reset_val ||
6668 curscontext != pHolder->gen.reset_scontext ||
6669 cursource != pHolder->gen.reset_source)
6671 (void) set_config_option(name, curvalue,
6672 curscontext, cursource,
6673 GUC_ACTION_SET, true, WARNING);
6674 variable->stack = NULL;
6680 DefineCustomBoolVariable(const char *name,
6681 const char *short_desc,
6682 const char *long_desc,
6687 GucBoolCheckHook check_hook,
6688 GucBoolAssignHook assign_hook,
6689 GucShowHook show_hook)
6691 struct config_bool *var;
6693 var = (struct config_bool *)
6694 init_custom_variable(name, short_desc, long_desc, context, flags,
6695 PGC_BOOL, sizeof(struct config_bool));
6696 var->variable = valueAddr;
6697 var->boot_val = bootValue;
6698 var->reset_val = bootValue;
6699 var->check_hook = check_hook;
6700 var->assign_hook = assign_hook;
6701 var->show_hook = show_hook;
6702 define_custom_variable(&var->gen);
6706 DefineCustomIntVariable(const char *name,
6707 const char *short_desc,
6708 const char *long_desc,
6715 GucIntCheckHook check_hook,
6716 GucIntAssignHook assign_hook,
6717 GucShowHook show_hook)
6719 struct config_int *var;
6721 var = (struct config_int *)
6722 init_custom_variable(name, short_desc, long_desc, context, flags,
6723 PGC_INT, sizeof(struct config_int));
6724 var->variable = valueAddr;
6725 var->boot_val = bootValue;
6726 var->reset_val = bootValue;
6727 var->min = minValue;
6728 var->max = maxValue;
6729 var->check_hook = check_hook;
6730 var->assign_hook = assign_hook;
6731 var->show_hook = show_hook;
6732 define_custom_variable(&var->gen);
6736 DefineCustomRealVariable(const char *name,
6737 const char *short_desc,
6738 const char *long_desc,
6745 GucRealCheckHook check_hook,
6746 GucRealAssignHook assign_hook,
6747 GucShowHook show_hook)
6749 struct config_real *var;
6751 var = (struct config_real *)
6752 init_custom_variable(name, short_desc, long_desc, context, flags,
6753 PGC_REAL, sizeof(struct config_real));
6754 var->variable = valueAddr;
6755 var->boot_val = bootValue;
6756 var->reset_val = bootValue;
6757 var->min = minValue;
6758 var->max = maxValue;
6759 var->check_hook = check_hook;
6760 var->assign_hook = assign_hook;
6761 var->show_hook = show_hook;
6762 define_custom_variable(&var->gen);
6766 DefineCustomStringVariable(const char *name,
6767 const char *short_desc,
6768 const char *long_desc,
6770 const char *bootValue,
6773 GucStringCheckHook check_hook,
6774 GucStringAssignHook assign_hook,
6775 GucShowHook show_hook)
6777 struct config_string *var;
6779 var = (struct config_string *)
6780 init_custom_variable(name, short_desc, long_desc, context, flags,
6781 PGC_STRING, sizeof(struct config_string));
6782 var->variable = valueAddr;
6783 var->boot_val = bootValue;
6784 var->check_hook = check_hook;
6785 var->assign_hook = assign_hook;
6786 var->show_hook = show_hook;
6787 define_custom_variable(&var->gen);
6791 DefineCustomEnumVariable(const char *name,
6792 const char *short_desc,
6793 const char *long_desc,
6796 const struct config_enum_entry * options,
6799 GucEnumCheckHook check_hook,
6800 GucEnumAssignHook assign_hook,
6801 GucShowHook show_hook)
6803 struct config_enum *var;
6805 var = (struct config_enum *)
6806 init_custom_variable(name, short_desc, long_desc, context, flags,
6807 PGC_ENUM, sizeof(struct config_enum));
6808 var->variable = valueAddr;
6809 var->boot_val = bootValue;
6810 var->reset_val = bootValue;
6811 var->options = options;
6812 var->check_hook = check_hook;
6813 var->assign_hook = assign_hook;
6814 var->show_hook = show_hook;
6815 define_custom_variable(&var->gen);
6819 EmitWarningsOnPlaceholders(const char *className)
6821 int classLen = strlen(className);
6824 for (i = 0; i < num_guc_variables; i++)
6826 struct config_generic *var = guc_variables[i];
6828 if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
6829 strncmp(className, var->name, classLen) == 0 &&
6830 var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
6833 (errcode(ERRCODE_UNDEFINED_OBJECT),
6834 errmsg("unrecognized configuration parameter \"%s\"",
6845 GetPGVariable(const char *name, DestReceiver *dest)
6847 if (guc_name_compare(name, "all") == 0)
6848 ShowAllGUCConfig(dest);
6850 ShowGUCConfigOption(name, dest);
6854 GetPGVariableResultDesc(const char *name)
6858 if (guc_name_compare(name, "all") == 0)
6860 /* need a tuple descriptor representing three TEXT columns */
6861 tupdesc = CreateTemplateTupleDesc(3, false);
6862 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
6864 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
6866 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
6871 const char *varname;
6873 /* Get the canonical spelling of name */
6874 (void) GetConfigOptionByName(name, &varname);
6876 /* need a tuple descriptor representing a single TEXT column */
6877 tupdesc = CreateTemplateTupleDesc(1, false);
6878 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
6889 ShowGUCConfigOption(const char *name, DestReceiver *dest)
6891 TupOutputState *tstate;
6893 const char *varname;
6896 /* Get the value and canonical spelling of name */
6897 value = GetConfigOptionByName(name, &varname);
6899 /* need a tuple descriptor representing a single TEXT column */
6900 tupdesc = CreateTemplateTupleDesc(1, false);
6901 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
6904 /* prepare for projection of tuples */
6905 tstate = begin_tup_output_tupdesc(dest, tupdesc);
6908 do_text_output_oneline(tstate, value);
6910 end_tup_output(tstate);
6917 ShowAllGUCConfig(DestReceiver *dest)
6919 bool am_superuser = superuser();
6921 TupOutputState *tstate;
6924 bool isnull[3] = {false, false, false};
6926 /* need a tuple descriptor representing three TEXT columns */
6927 tupdesc = CreateTemplateTupleDesc(3, false);
6928 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
6930 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
6932 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
6935 /* prepare for projection of tuples */
6936 tstate = begin_tup_output_tupdesc(dest, tupdesc);
6938 for (i = 0; i < num_guc_variables; i++)
6940 struct config_generic *conf = guc_variables[i];
6943 if ((conf->flags & GUC_NO_SHOW_ALL) ||
6944 ((conf->flags & GUC_SUPERUSER_ONLY) && !am_superuser))
6947 /* assign to the values array */
6948 values[0] = PointerGetDatum(cstring_to_text(conf->name));
6950 setting = _ShowOption(conf, true);
6953 values[1] = PointerGetDatum(cstring_to_text(setting));
6958 values[1] = PointerGetDatum(NULL);
6962 values[2] = PointerGetDatum(cstring_to_text(conf->short_desc));
6964 /* send it to dest */
6965 do_tup_output(tstate, values, isnull);
6968 pfree(DatumGetPointer(values[0]));
6972 pfree(DatumGetPointer(values[1]));
6974 pfree(DatumGetPointer(values[2]));
6977 end_tup_output(tstate);
6981 * Return GUC variable value by name; optionally return canonical
6982 * form of name. Return value is palloc'd.
6985 GetConfigOptionByName(const char *name, const char **varname)
6987 struct config_generic *record;
6989 record = find_option(name, false, ERROR);
6992 (errcode(ERRCODE_UNDEFINED_OBJECT),
6993 errmsg("unrecognized configuration parameter \"%s\"", name)));
6994 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
6996 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6997 errmsg("must be superuser to examine \"%s\"", name)));
7000 *varname = record->name;
7002 return _ShowOption(record, true);
7006 * Return GUC variable value by variable number; optionally return canonical
7007 * form of name. Return value is palloc'd.
7010 GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
7013 struct config_generic *conf;
7015 /* check requested variable number valid */
7016 Assert((varnum >= 0) && (varnum < num_guc_variables));
7018 conf = guc_variables[varnum];
7022 if ((conf->flags & GUC_NO_SHOW_ALL) ||
7023 ((conf->flags & GUC_SUPERUSER_ONLY) && !superuser()))
7029 /* first get the generic attributes */
7032 values[0] = conf->name;
7034 /* setting : use _ShowOption in order to avoid duplicating the logic */
7035 values[1] = _ShowOption(conf, false);
7038 if (conf->vartype == PGC_INT)
7042 switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
7047 case GUC_UNIT_BLOCKS:
7048 snprintf(buf, sizeof(buf), "%dkB", BLCKSZ / 1024);
7051 case GUC_UNIT_XBLOCKS:
7052 snprintf(buf, sizeof(buf), "%dkB", XLOG_BLCKSZ / 1024);
7073 values[3] = config_group_names[conf->group];
7076 values[4] = conf->short_desc;
7079 values[5] = conf->long_desc;
7082 values[6] = GucContext_Names[conf->context];
7085 values[7] = config_type_names[conf->vartype];
7088 values[8] = GucSource_Names[conf->source];
7090 /* now get the type specifc attributes */
7091 switch (conf->vartype)
7095 struct config_bool *lconf = (struct config_bool *) conf;
7107 values[12] = pstrdup(lconf->boot_val ? "on" : "off");
7110 values[13] = pstrdup(lconf->reset_val ? "on" : "off");
7116 struct config_int *lconf = (struct config_int *) conf;
7119 snprintf(buffer, sizeof(buffer), "%d", lconf->min);
7120 values[9] = pstrdup(buffer);
7123 snprintf(buffer, sizeof(buffer), "%d", lconf->max);
7124 values[10] = pstrdup(buffer);
7130 snprintf(buffer, sizeof(buffer), "%d", lconf->boot_val);
7131 values[12] = pstrdup(buffer);
7134 snprintf(buffer, sizeof(buffer), "%d", lconf->reset_val);
7135 values[13] = pstrdup(buffer);
7141 struct config_real *lconf = (struct config_real *) conf;
7144 snprintf(buffer, sizeof(buffer), "%g", lconf->min);
7145 values[9] = pstrdup(buffer);
7148 snprintf(buffer, sizeof(buffer), "%g", lconf->max);
7149 values[10] = pstrdup(buffer);
7155 snprintf(buffer, sizeof(buffer), "%g", lconf->boot_val);
7156 values[12] = pstrdup(buffer);
7159 snprintf(buffer, sizeof(buffer), "%g", lconf->reset_val);
7160 values[13] = pstrdup(buffer);
7166 struct config_string *lconf = (struct config_string *) conf;
7178 if (lconf->boot_val == NULL)
7181 values[12] = pstrdup(lconf->boot_val);
7184 if (lconf->reset_val == NULL)
7187 values[13] = pstrdup(lconf->reset_val);
7193 struct config_enum *lconf = (struct config_enum *) conf;
7204 * NOTE! enumvals with double quotes in them are not
7207 values[11] = config_enum_get_options((struct config_enum *) conf,
7208 "{\"", "\"}", "\",\"");
7211 values[12] = pstrdup(config_enum_lookup_by_value(lconf,
7215 values[13] = pstrdup(config_enum_lookup_by_value(lconf,
7223 * should never get here, but in case we do, set 'em to NULL
7245 * If the setting came from a config file, set the source location. For
7246 * security reasons, we don't show source file/line number for
7249 if (conf->source == PGC_S_FILE && superuser())
7251 values[14] = conf->sourcefile;
7252 snprintf(buffer, sizeof(buffer), "%d", conf->sourceline);
7253 values[15] = pstrdup(buffer);
7263 * Return the total number of GUC variables
7266 GetNumConfigOptions(void)
7268 return num_guc_variables;
7272 * show_config_by_name - equiv to SHOW X command but implemented as
7276 show_config_by_name(PG_FUNCTION_ARGS)
7281 /* Get the GUC variable name */
7282 varname = TextDatumGetCString(PG_GETARG_DATUM(0));
7285 varval = GetConfigOptionByName(varname, NULL);
7287 /* Convert to text */
7288 PG_RETURN_TEXT_P(cstring_to_text(varval));
7292 * show_all_settings - equiv to SHOW ALL command but implemented as
7295 #define NUM_PG_SETTINGS_ATTS 16
7298 show_all_settings(PG_FUNCTION_ARGS)
7300 FuncCallContext *funcctx;
7304 AttInMetadata *attinmeta;
7305 MemoryContext oldcontext;
7307 /* stuff done only on the first call of the function */
7308 if (SRF_IS_FIRSTCALL())
7310 /* create a function context for cross-call persistence */
7311 funcctx = SRF_FIRSTCALL_INIT();
7314 * switch to memory context appropriate for multiple function calls
7316 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
7319 * need a tuple descriptor representing NUM_PG_SETTINGS_ATTS columns
7320 * of the appropriate types
7322 tupdesc = CreateTemplateTupleDesc(NUM_PG_SETTINGS_ATTS, false);
7323 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
7325 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
7327 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "unit",
7329 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "category",
7331 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "short_desc",
7333 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "extra_desc",
7335 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "context",
7337 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "vartype",
7339 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "source",
7341 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "min_val",
7343 TupleDescInitEntry(tupdesc, (AttrNumber) 11, "max_val",
7345 TupleDescInitEntry(tupdesc, (AttrNumber) 12, "enumvals",
7346 TEXTARRAYOID, -1, 0);
7347 TupleDescInitEntry(tupdesc, (AttrNumber) 13, "boot_val",
7349 TupleDescInitEntry(tupdesc, (AttrNumber) 14, "reset_val",
7351 TupleDescInitEntry(tupdesc, (AttrNumber) 15, "sourcefile",
7353 TupleDescInitEntry(tupdesc, (AttrNumber) 16, "sourceline",
7357 * Generate attribute metadata needed later to produce tuples from raw
7360 attinmeta = TupleDescGetAttInMetadata(tupdesc);
7361 funcctx->attinmeta = attinmeta;
7363 /* total number of tuples to be returned */
7364 funcctx->max_calls = GetNumConfigOptions();
7366 MemoryContextSwitchTo(oldcontext);
7369 /* stuff done on every call of the function */
7370 funcctx = SRF_PERCALL_SETUP();
7372 call_cntr = funcctx->call_cntr;
7373 max_calls = funcctx->max_calls;
7374 attinmeta = funcctx->attinmeta;
7376 if (call_cntr < max_calls) /* do when there is more left to send */
7378 char *values[NUM_PG_SETTINGS_ATTS];
7384 * Get the next visible GUC variable name and value
7388 GetConfigOptionByNum(call_cntr, (const char **) values, &noshow);
7391 /* bump the counter and get the next config setting */
7392 call_cntr = ++funcctx->call_cntr;
7394 /* make sure we haven't gone too far now */
7395 if (call_cntr >= max_calls)
7396 SRF_RETURN_DONE(funcctx);
7401 tuple = BuildTupleFromCStrings(attinmeta, values);
7403 /* make the tuple into a datum */
7404 result = HeapTupleGetDatum(tuple);
7406 SRF_RETURN_NEXT(funcctx, result);
7410 /* do when there is no more left */
7411 SRF_RETURN_DONE(funcctx);
7416 _ShowOption(struct config_generic * record, bool use_units)
7421 switch (record->vartype)
7425 struct config_bool *conf = (struct config_bool *) record;
7427 if (conf->show_hook)
7428 val = (*conf->show_hook) ();
7430 val = *conf->variable ? "on" : "off";
7436 struct config_int *conf = (struct config_int *) record;
7438 if (conf->show_hook)
7439 val = (*conf->show_hook) ();
7443 * Use int64 arithmetic to avoid overflows in units
7446 int64 result = *conf->variable;
7449 if (use_units && result > 0 &&
7450 (record->flags & GUC_UNIT_MEMORY))
7452 switch (record->flags & GUC_UNIT_MEMORY)
7454 case GUC_UNIT_BLOCKS:
7455 result *= BLCKSZ / 1024;
7457 case GUC_UNIT_XBLOCKS:
7458 result *= XLOG_BLCKSZ / 1024;
7462 if (result % KB_PER_TB == 0)
7464 result /= KB_PER_TB;
7467 else if (result % KB_PER_GB == 0)
7469 result /= KB_PER_GB;
7472 else if (result % KB_PER_MB == 0)
7474 result /= KB_PER_MB;
7482 else if (use_units && result > 0 &&
7483 (record->flags & GUC_UNIT_TIME))
7485 switch (record->flags & GUC_UNIT_TIME)
7491 result *= MS_PER_MIN;
7495 if (result % MS_PER_D == 0)
7500 else if (result % MS_PER_H == 0)
7505 else if (result % MS_PER_MIN == 0)
7507 result /= MS_PER_MIN;
7510 else if (result % MS_PER_S == 0)
7523 snprintf(buffer, sizeof(buffer), INT64_FORMAT "%s",
7532 struct config_real *conf = (struct config_real *) record;
7534 if (conf->show_hook)
7535 val = (*conf->show_hook) ();
7538 snprintf(buffer, sizeof(buffer), "%g",
7547 struct config_string *conf = (struct config_string *) record;
7549 if (conf->show_hook)
7550 val = (*conf->show_hook) ();
7551 else if (*conf->variable && **conf->variable)
7552 val = *conf->variable;
7560 struct config_enum *conf = (struct config_enum *) record;
7562 if (conf->show_hook)
7563 val = (*conf->show_hook) ();
7565 val = config_enum_lookup_by_value(conf, *conf->variable);
7570 /* just to keep compiler quiet */
7575 return pstrdup(val);
7582 * These routines dump out all non-default GUC options into a binary
7583 * file that is read by all exec'ed backends. The format is:
7585 * variable name, string, null terminated
7586 * variable value, string, null terminated
7587 * variable sourcefile, string, null terminated (empty if none)
7588 * variable sourceline, integer
7589 * variable source, integer
7590 * variable scontext, integer
7593 write_one_nondefault_variable(FILE *fp, struct config_generic * gconf)
7595 if (gconf->source == PGC_S_DEFAULT)
7598 fprintf(fp, "%s", gconf->name);
7601 switch (gconf->vartype)
7605 struct config_bool *conf = (struct config_bool *) gconf;
7607 if (*conf->variable)
7608 fprintf(fp, "true");
7610 fprintf(fp, "false");
7616 struct config_int *conf = (struct config_int *) gconf;
7618 fprintf(fp, "%d", *conf->variable);
7624 struct config_real *conf = (struct config_real *) gconf;
7626 fprintf(fp, "%.17g", *conf->variable);
7632 struct config_string *conf = (struct config_string *) gconf;
7634 fprintf(fp, "%s", *conf->variable);
7640 struct config_enum *conf = (struct config_enum *) gconf;
7643 config_enum_lookup_by_value(conf, *conf->variable));
7650 if (gconf->sourcefile)
7651 fprintf(fp, "%s", gconf->sourcefile);
7654 fwrite(&gconf->sourceline, 1, sizeof(gconf->sourceline), fp);
7655 fwrite(&gconf->source, 1, sizeof(gconf->source), fp);
7656 fwrite(&gconf->scontext, 1, sizeof(gconf->scontext), fp);
7660 write_nondefault_variables(GucContext context)
7666 Assert(context == PGC_POSTMASTER || context == PGC_SIGHUP);
7668 elevel = (context == PGC_SIGHUP) ? LOG : ERROR;
7673 fp = AllocateFile(CONFIG_EXEC_PARAMS_NEW, "w");
7677 (errcode_for_file_access(),
7678 errmsg("could not write to file \"%s\": %m",
7679 CONFIG_EXEC_PARAMS_NEW)));
7683 for (i = 0; i < num_guc_variables; i++)
7685 write_one_nondefault_variable(fp, guc_variables[i]);
7691 (errcode_for_file_access(),
7692 errmsg("could not write to file \"%s\": %m",
7693 CONFIG_EXEC_PARAMS_NEW)));
7698 * Put new file in place. This could delay on Win32, but we don't hold
7699 * any exclusive locks.
7701 rename(CONFIG_EXEC_PARAMS_NEW, CONFIG_EXEC_PARAMS);
7706 * Read string, including null byte from file
7708 * Return NULL on EOF and nothing read
7711 read_string_with_null(FILE *fp)
7720 if ((ch = fgetc(fp)) == EOF)
7725 elog(FATAL, "invalid format of exec config params file");
7728 str = guc_malloc(FATAL, maxlen);
7729 else if (i == maxlen)
7730 str = guc_realloc(FATAL, str, maxlen *= 2);
7739 * This routine loads a previous postmaster dump of its non-default
7743 read_nondefault_variables(void)
7750 GucSource varsource;
7751 GucContext varscontext;
7756 fp = AllocateFile(CONFIG_EXEC_PARAMS, "r");
7759 /* File not found is fine */
7760 if (errno != ENOENT)
7762 (errcode_for_file_access(),
7763 errmsg("could not read from file \"%s\": %m",
7764 CONFIG_EXEC_PARAMS)));
7770 struct config_generic *record;
7772 if ((varname = read_string_with_null(fp)) == NULL)
7775 if ((record = find_option(varname, true, FATAL)) == NULL)
7776 elog(FATAL, "failed to locate variable \"%s\" in exec config params file", varname);
7778 if ((varvalue = read_string_with_null(fp)) == NULL)
7779 elog(FATAL, "invalid format of exec config params file");
7780 if ((varsourcefile = read_string_with_null(fp)) == NULL)
7781 elog(FATAL, "invalid format of exec config params file");
7782 if (fread(&varsourceline, 1, sizeof(varsourceline), fp) != sizeof(varsourceline))
7783 elog(FATAL, "invalid format of exec config params file");
7784 if (fread(&varsource, 1, sizeof(varsource), fp) != sizeof(varsource))
7785 elog(FATAL, "invalid format of exec config params file");
7786 if (fread(&varscontext, 1, sizeof(varscontext), fp) != sizeof(varscontext))
7787 elog(FATAL, "invalid format of exec config params file");
7789 (void) set_config_option(varname, varvalue,
7790 varscontext, varsource,
7791 GUC_ACTION_SET, true, 0);
7792 if (varsourcefile[0])
7793 set_config_sourcefile(varname, varsourcefile, varsourceline);
7797 free(varsourcefile);
7802 #endif /* EXEC_BACKEND */
7806 * A little "long argument" simulation, although not quite GNU
7807 * compliant. Takes a string of the form "some-option=some value" and
7808 * returns name = "some_option" and value = "some value" in malloc'ed
7809 * storage. Note that '-' is converted to '_' in the option name. If
7810 * there is no '=' in the input string then value will be NULL.
7813 ParseLongOption(const char *string, char **name, char **value)
7822 equal_pos = strcspn(string, "=");
7824 if (string[equal_pos] == '=')
7826 *name = guc_malloc(FATAL, equal_pos + 1);
7827 strlcpy(*name, string, equal_pos + 1);
7829 *value = guc_strdup(FATAL, &string[equal_pos + 1]);
7833 /* no equal sign in string */
7834 *name = guc_strdup(FATAL, string);
7838 for (cp = *name; *cp; cp++)
7845 * Handle options fetched from pg_db_role_setting.setconfig,
7846 * pg_proc.proconfig, etc. Caller must specify proper context/source/action.
7848 * The array parameter must be an array of TEXT (it must not be NULL).
7851 ProcessGUCArray(ArrayType *array,
7852 GucContext context, GucSource source, GucAction action)
7856 Assert(array != NULL);
7857 Assert(ARR_ELEMTYPE(array) == TEXTOID);
7858 Assert(ARR_NDIM(array) == 1);
7859 Assert(ARR_LBOUND(array)[0] == 1);
7861 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
7869 d = array_ref(array, 1, &i,
7870 -1 /* varlenarray */ ,
7871 -1 /* TEXT's typlen */ ,
7872 false /* TEXT's typbyval */ ,
7873 'i' /* TEXT's typalign */ ,
7879 s = TextDatumGetCString(d);
7881 ParseLongOption(s, &name, &value);
7885 (errcode(ERRCODE_SYNTAX_ERROR),
7886 errmsg("could not parse setting for parameter \"%s\"",
7892 (void) set_config_option(name, value,
7905 * Add an entry to an option array. The array parameter may be NULL
7906 * to indicate the current table entry is NULL.
7909 GUCArrayAdd(ArrayType *array, const char *name, const char *value)
7911 struct config_generic *record;
7919 /* test if the option is valid and we're allowed to set it */
7920 (void) validate_option_array_item(name, value, false);
7922 /* normalize name (converts obsolete GUC names to modern spellings) */
7923 record = find_option(name, false, WARNING);
7925 name = record->name;
7927 /* build new item for array */
7928 newval = palloc(strlen(name) + 1 + strlen(value) + 1);
7929 sprintf(newval, "%s=%s", name, value);
7930 datum = CStringGetTextDatum(newval);
7938 Assert(ARR_ELEMTYPE(array) == TEXTOID);
7939 Assert(ARR_NDIM(array) == 1);
7940 Assert(ARR_LBOUND(array)[0] == 1);
7942 index = ARR_DIMS(array)[0] + 1; /* add after end */
7944 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
7949 d = array_ref(array, 1, &i,
7950 -1 /* varlenarray */ ,
7951 -1 /* TEXT's typlen */ ,
7952 false /* TEXT's typbyval */ ,
7953 'i' /* TEXT's typalign */ ,
7957 current = TextDatumGetCString(d);
7959 /* check for match up through and including '=' */
7960 if (strncmp(current, newval, strlen(name) + 1) == 0)
7967 a = array_set(array, 1, &index,
7970 -1 /* varlena array */ ,
7971 -1 /* TEXT's typlen */ ,
7972 false /* TEXT's typbyval */ ,
7973 'i' /* TEXT's typalign */ );
7976 a = construct_array(&datum, 1,
7985 * Delete an entry from an option array. The array parameter may be NULL
7986 * to indicate the current table entry is NULL. Also, if the return value
7987 * is NULL then a null should be stored.
7990 GUCArrayDelete(ArrayType *array, const char *name)
7992 struct config_generic *record;
7993 ArrayType *newarray;
7999 /* test if the option is valid and we're allowed to set it */
8000 (void) validate_option_array_item(name, NULL, false);
8002 /* normalize name (converts obsolete GUC names to modern spellings) */
8003 record = find_option(name, false, WARNING);
8005 name = record->name;
8007 /* if array is currently null, then surely nothing to delete */
8014 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
8020 d = array_ref(array, 1, &i,
8021 -1 /* varlenarray */ ,
8022 -1 /* TEXT's typlen */ ,
8023 false /* TEXT's typbyval */ ,
8024 'i' /* TEXT's typalign */ ,
8028 val = TextDatumGetCString(d);
8030 /* ignore entry if it's what we want to delete */
8031 if (strncmp(val, name, strlen(name)) == 0
8032 && val[strlen(name)] == '=')
8035 /* else add it to the output array */
8037 newarray = array_set(newarray, 1, &index,
8040 -1 /* varlenarray */ ,
8041 -1 /* TEXT's typlen */ ,
8042 false /* TEXT's typbyval */ ,
8043 'i' /* TEXT's typalign */ );
8045 newarray = construct_array(&d, 1,
8057 * Given a GUC array, delete all settings from it that our permission
8058 * level allows: if superuser, delete them all; if regular user, only
8059 * those that are PGC_USERSET
8062 GUCArrayReset(ArrayType *array)
8064 ArrayType *newarray;
8068 /* if array is currently null, nothing to do */
8072 /* if we're superuser, we can delete everything, so just do it */
8079 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
8086 d = array_ref(array, 1, &i,
8087 -1 /* varlenarray */ ,
8088 -1 /* TEXT's typlen */ ,
8089 false /* TEXT's typbyval */ ,
8090 'i' /* TEXT's typalign */ ,
8094 val = TextDatumGetCString(d);
8096 eqsgn = strchr(val, '=');
8099 /* skip if we have permission to delete it */
8100 if (validate_option_array_item(val, NULL, true))
8103 /* else add it to the output array */
8105 newarray = array_set(newarray, 1, &index,
8108 -1 /* varlenarray */ ,
8109 -1 /* TEXT's typlen */ ,
8110 false /* TEXT's typbyval */ ,
8111 'i' /* TEXT's typalign */ );
8113 newarray = construct_array(&d, 1,
8125 * Validate a proposed option setting for GUCArrayAdd/Delete/Reset.
8127 * name is the option name. value is the proposed value for the Add case,
8128 * or NULL for the Delete/Reset cases. If skipIfNoPermissions is true, it's
8129 * not an error to have no permissions to set the option.
8131 * Returns TRUE if OK, FALSE if skipIfNoPermissions is true and user does not
8132 * have permission to change this option (all other error cases result in an
8133 * error being thrown).
8136 validate_option_array_item(const char *name, const char *value,
8137 bool skipIfNoPermissions)
8140 struct config_generic *gconf;
8143 * There are three cases to consider:
8145 * name is a known GUC variable. Check the value normally, check
8146 * permissions normally (ie, allow if variable is USERSET, or if it's
8147 * SUSET and user is superuser).
8149 * name is not known, but exists or can be created as a placeholder (i.e.,
8150 * it has a prefixed name). We allow this case if you're a superuser,
8151 * otherwise not. Superusers are assumed to know what they're doing. We
8152 * can't allow it for other users, because when the placeholder is
8153 * resolved it might turn out to be a SUSET variable;
8154 * define_custom_variable assumes we checked that.
8156 * name is not known and can't be created as a placeholder. Throw error,
8157 * unless skipIfNoPermissions is true, in which case return FALSE.
8159 gconf = find_option(name, true, WARNING);
8162 /* not known, failed to make a placeholder */
8163 if (skipIfNoPermissions)
8166 (errcode(ERRCODE_UNDEFINED_OBJECT),
8167 errmsg("unrecognized configuration parameter \"%s\"",
8171 if (gconf->flags & GUC_CUSTOM_PLACEHOLDER)
8174 * We cannot do any meaningful check on the value, so only permissions
8175 * are useful to check.
8179 if (skipIfNoPermissions)
8182 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
8183 errmsg("permission denied to set parameter \"%s\"", name)));
8186 /* manual permissions check so we can avoid an error being thrown */
8187 if (gconf->context == PGC_USERSET)
8189 else if (gconf->context == PGC_SUSET && superuser())
8191 else if (skipIfNoPermissions)
8193 /* if a permissions error should be thrown, let set_config_option do it */
8195 /* test for permissions and valid option value */
8196 (void) set_config_option(name, value,
8197 superuser() ? PGC_SUSET : PGC_USERSET,
8198 PGC_S_TEST, GUC_ACTION_SET, false, 0);
8205 * Called by check_hooks that want to override the normal
8206 * ERRCODE_INVALID_PARAMETER_VALUE SQLSTATE for check hook failures.
8208 * Note that GUC_check_errmsg() etc are just macros that result in a direct
8209 * assignment to the associated variables. That is ugly, but forced by the
8210 * limitations of C's macro mechanisms.
8213 GUC_check_errcode(int sqlerrcode)
8215 GUC_check_errcode_value = sqlerrcode;
8220 * Convenience functions to manage calling a variable's check_hook.
8221 * These mostly take care of the protocol for letting check hooks supply
8222 * portions of the error report on failure.
8226 call_bool_check_hook(struct config_bool * conf, bool *newval, void **extra,
8227 GucSource source, int elevel)
8229 /* Quick success if no hook */
8230 if (!conf->check_hook)
8233 /* Reset variables that might be set by hook */
8234 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8235 GUC_check_errmsg_string = NULL;
8236 GUC_check_errdetail_string = NULL;
8237 GUC_check_errhint_string = NULL;
8239 if (!(*conf->check_hook) (newval, extra, source))
8242 (errcode(GUC_check_errcode_value),
8243 GUC_check_errmsg_string ?
8244 errmsg_internal("%s", GUC_check_errmsg_string) :
8245 errmsg("invalid value for parameter \"%s\": %d",
8246 conf->gen.name, (int) *newval),
8247 GUC_check_errdetail_string ?
8248 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
8249 GUC_check_errhint_string ?
8250 errhint("%s", GUC_check_errhint_string) : 0));
8251 /* Flush any strings created in ErrorContext */
8260 call_int_check_hook(struct config_int * conf, int *newval, void **extra,
8261 GucSource source, int elevel)
8263 /* Quick success if no hook */
8264 if (!conf->check_hook)
8267 /* Reset variables that might be set by hook */
8268 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8269 GUC_check_errmsg_string = NULL;
8270 GUC_check_errdetail_string = NULL;
8271 GUC_check_errhint_string = NULL;
8273 if (!(*conf->check_hook) (newval, extra, source))
8276 (errcode(GUC_check_errcode_value),
8277 GUC_check_errmsg_string ?
8278 errmsg_internal("%s", GUC_check_errmsg_string) :
8279 errmsg("invalid value for parameter \"%s\": %d",
8280 conf->gen.name, *newval),
8281 GUC_check_errdetail_string ?
8282 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
8283 GUC_check_errhint_string ?
8284 errhint("%s", GUC_check_errhint_string) : 0));
8285 /* Flush any strings created in ErrorContext */
8294 call_real_check_hook(struct config_real * conf, double *newval, void **extra,
8295 GucSource source, int elevel)
8297 /* Quick success if no hook */
8298 if (!conf->check_hook)
8301 /* Reset variables that might be set by hook */
8302 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8303 GUC_check_errmsg_string = NULL;
8304 GUC_check_errdetail_string = NULL;
8305 GUC_check_errhint_string = NULL;
8307 if (!(*conf->check_hook) (newval, extra, source))
8310 (errcode(GUC_check_errcode_value),
8311 GUC_check_errmsg_string ?
8312 errmsg_internal("%s", GUC_check_errmsg_string) :
8313 errmsg("invalid value for parameter \"%s\": %g",
8314 conf->gen.name, *newval),
8315 GUC_check_errdetail_string ?
8316 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
8317 GUC_check_errhint_string ?
8318 errhint("%s", GUC_check_errhint_string) : 0));
8319 /* Flush any strings created in ErrorContext */
8328 call_string_check_hook(struct config_string * conf, char **newval, void **extra,
8329 GucSource source, int elevel)
8331 /* Quick success if no hook */
8332 if (!conf->check_hook)
8335 /* Reset variables that might be set by hook */
8336 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8337 GUC_check_errmsg_string = NULL;
8338 GUC_check_errdetail_string = NULL;
8339 GUC_check_errhint_string = NULL;
8341 if (!(*conf->check_hook) (newval, extra, source))
8344 (errcode(GUC_check_errcode_value),
8345 GUC_check_errmsg_string ?
8346 errmsg_internal("%s", GUC_check_errmsg_string) :
8347 errmsg("invalid value for parameter \"%s\": \"%s\"",
8348 conf->gen.name, *newval ? *newval : ""),
8349 GUC_check_errdetail_string ?
8350 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
8351 GUC_check_errhint_string ?
8352 errhint("%s", GUC_check_errhint_string) : 0));
8353 /* Flush any strings created in ErrorContext */
8362 call_enum_check_hook(struct config_enum * conf, int *newval, void **extra,
8363 GucSource source, int elevel)
8365 /* Quick success if no hook */
8366 if (!conf->check_hook)
8369 /* Reset variables that might be set by hook */
8370 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8371 GUC_check_errmsg_string = NULL;
8372 GUC_check_errdetail_string = NULL;
8373 GUC_check_errhint_string = NULL;
8375 if (!(*conf->check_hook) (newval, extra, source))
8378 (errcode(GUC_check_errcode_value),
8379 GUC_check_errmsg_string ?
8380 errmsg_internal("%s", GUC_check_errmsg_string) :
8381 errmsg("invalid value for parameter \"%s\": \"%s\"",
8383 config_enum_lookup_by_value(conf, *newval)),
8384 GUC_check_errdetail_string ?
8385 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
8386 GUC_check_errhint_string ?
8387 errhint("%s", GUC_check_errhint_string) : 0));
8388 /* Flush any strings created in ErrorContext */
8398 * check_hook, assign_hook and show_hook subroutines
8402 check_log_destination(char **newval, void **extra, GucSource source)
8410 /* Need a modifiable copy of string */
8411 rawstring = pstrdup(*newval);
8413 /* Parse string into list of identifiers */
8414 if (!SplitIdentifierString(rawstring, ',', &elemlist))
8416 /* syntax error in list */
8417 GUC_check_errdetail("List syntax is invalid.");
8419 list_free(elemlist);
8423 foreach(l, elemlist)
8425 char *tok = (char *) lfirst(l);
8427 if (pg_strcasecmp(tok, "stderr") == 0)
8428 newlogdest |= LOG_DESTINATION_STDERR;
8429 else if (pg_strcasecmp(tok, "csvlog") == 0)
8430 newlogdest |= LOG_DESTINATION_CSVLOG;
8432 else if (pg_strcasecmp(tok, "syslog") == 0)
8433 newlogdest |= LOG_DESTINATION_SYSLOG;
8436 else if (pg_strcasecmp(tok, "eventlog") == 0)
8437 newlogdest |= LOG_DESTINATION_EVENTLOG;
8441 GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
8443 list_free(elemlist);
8449 list_free(elemlist);
8451 myextra = (int *) guc_malloc(ERROR, sizeof(int));
8452 *myextra = newlogdest;
8453 *extra = (void *) myextra;
8459 assign_log_destination(const char *newval, void *extra)
8461 Log_destination = *((int *) extra);
8465 assign_syslog_facility(int newval, void *extra)
8468 set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
8471 /* Without syslog support, just ignore it */
8475 assign_syslog_ident(const char *newval, void *extra)
8478 set_syslog_parameters(newval, syslog_facility);
8480 /* Without syslog support, it will always be set to "none", so ignore */
8485 assign_session_replication_role(int newval, void *extra)
8488 * Must flush the plan cache when changing replication role; but don't
8489 * flush unnecessarily.
8491 if (SessionReplicationRole != newval)
8496 check_temp_buffers(int *newval, void **extra, GucSource source)
8499 * Once local buffers have been initialized, it's too late to change this.
8501 if (NLocBuffer && NLocBuffer != *newval)
8503 GUC_check_errdetail("\"temp_buffers\" cannot be changed after any temporary tables have been accessed in the session.");
8510 check_phony_autocommit(bool *newval, void **extra, GucSource source)
8514 GUC_check_errcode(ERRCODE_FEATURE_NOT_SUPPORTED);
8515 GUC_check_errmsg("SET AUTOCOMMIT TO OFF is no longer supported");
8522 check_debug_assertions(bool *newval, void **extra, GucSource source)
8524 #ifndef USE_ASSERT_CHECKING
8527 GUC_check_errmsg("assertion checking is not supported by this build");
8535 check_bonjour(bool *newval, void **extra, GucSource source)
8540 GUC_check_errmsg("Bonjour is not supported by this build");
8548 check_ssl(bool *newval, void **extra, GucSource source)
8553 GUC_check_errmsg("SSL is not supported by this build");
8561 check_stage_log_stats(bool *newval, void **extra, GucSource source)
8563 if (*newval && log_statement_stats)
8565 GUC_check_errdetail("Cannot enable parameter when \"log_statement_stats\" is true.");
8572 check_log_stats(bool *newval, void **extra, GucSource source)
8575 (log_parser_stats || log_planner_stats || log_executor_stats))
8577 GUC_check_errdetail("Cannot enable \"log_statement_stats\" when "
8578 "\"log_parser_stats\", \"log_planner_stats\", "
8579 "or \"log_executor_stats\" is true.");
8586 check_canonical_path(char **newval, void **extra, GucSource source)
8589 * Since canonicalize_path never enlarges the string, we can just modify
8590 * newval in-place. But watch out for NULL, which is the default value
8591 * for external_pid_file.
8594 canonicalize_path(*newval);
8599 check_timezone_abbreviations(char **newval, void **extra, GucSource source)
8602 * The boot_val given above for timezone_abbreviations is NULL. When we
8603 * see this we just do nothing. If this value isn't overridden from the
8604 * config file then pg_timezone_abbrev_initialize() will eventually
8605 * replace it with "Default". This hack has two purposes: to avoid
8606 * wasting cycles loading values that might soon be overridden from the
8607 * config file, and to avoid trying to read the timezone abbrev files
8608 * during InitializeGUCOptions(). The latter doesn't work in an
8609 * EXEC_BACKEND subprocess because my_exec_path hasn't been set yet and so
8610 * we can't locate PGSHAREDIR.
8612 if (*newval == NULL)
8614 Assert(source == PGC_S_DEFAULT);
8618 /* OK, load the file and produce a malloc'd TimeZoneAbbrevTable */
8619 *extra = load_tzoffsets(*newval);
8621 /* tzparser.c returns NULL on failure, reporting via GUC_check_errmsg */
8629 assign_timezone_abbreviations(const char *newval, void *extra)
8631 /* Do nothing for the boot_val default of NULL */
8635 InstallTimeZoneAbbrevs((TimeZoneAbbrevTable *) extra);
8639 * pg_timezone_abbrev_initialize --- set default value if not done already
8641 * This is called after initial loading of postgresql.conf. If no
8642 * timezone_abbreviations setting was found therein, select default.
8643 * If a non-default value is already installed, nothing will happen.
8645 * This can also be called from ProcessConfigFile to establish the default
8646 * value after a postgresql.conf entry for it is removed.
8649 pg_timezone_abbrev_initialize(void)
8651 SetConfigOption("timezone_abbreviations", "Default",
8652 PGC_POSTMASTER, PGC_S_DYNAMIC_DEFAULT);
8656 show_archive_command(void)
8658 if (XLogArchivingActive())
8659 return XLogArchiveCommand;
8661 return "(disabled)";
8665 assign_tcp_keepalives_idle(int newval, void *extra)
8668 * The kernel API provides no way to test a value without setting it; and
8669 * once we set it we might fail to unset it. So there seems little point
8670 * in fully implementing the check-then-assign GUC API for these
8671 * variables. Instead we just do the assignment on demand. pqcomm.c
8672 * reports any problems via elog(LOG).
8674 * This approach means that the GUC value might have little to do with the
8675 * actual kernel value, so we use a show_hook that retrieves the kernel
8676 * value rather than trusting GUC's copy.
8678 (void) pq_setkeepalivesidle(newval, MyProcPort);
8682 show_tcp_keepalives_idle(void)
8684 /* See comments in assign_tcp_keepalives_idle */
8685 static char nbuf[16];
8687 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesidle(MyProcPort));
8692 assign_tcp_keepalives_interval(int newval, void *extra)
8694 /* See comments in assign_tcp_keepalives_idle */
8695 (void) pq_setkeepalivesinterval(newval, MyProcPort);
8699 show_tcp_keepalives_interval(void)
8701 /* See comments in assign_tcp_keepalives_idle */
8702 static char nbuf[16];
8704 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesinterval(MyProcPort));
8709 assign_tcp_keepalives_count(int newval, void *extra)
8711 /* See comments in assign_tcp_keepalives_idle */
8712 (void) pq_setkeepalivescount(newval, MyProcPort);
8716 show_tcp_keepalives_count(void)
8718 /* See comments in assign_tcp_keepalives_idle */
8719 static char nbuf[16];
8721 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivescount(MyProcPort));
8726 check_maxconnections(int *newval, void **extra, GucSource source)
8728 if (*newval + autovacuum_max_workers + 1 +
8729 max_worker_processes > MAX_BACKENDS)
8735 check_autovacuum_max_workers(int *newval, void **extra, GucSource source)
8737 if (MaxConnections + *newval + 1 + max_worker_processes > MAX_BACKENDS)
8743 check_max_worker_processes(int *newval, void **extra, GucSource source)
8745 if (MaxConnections + autovacuum_max_workers + 1 + *newval > MAX_BACKENDS)
8751 check_effective_io_concurrency(int *newval, void **extra, GucSource source)
8754 double new_prefetch_pages = 0.0;
8758 * The user-visible GUC parameter is the number of drives (spindles),
8759 * which we need to translate to a number-of-pages-to-prefetch target.
8760 * The target value is stashed in *extra and then assigned to the actual
8761 * variable by assign_effective_io_concurrency.
8763 * The expected number of prefetch pages needed to keep N drives busy is:
8765 * drives | I/O requests
8766 * -------+----------------
8769 * 3 | 3/1 + 3/2 + 3/3 = 5 1/2
8770 * 4 | 4/1 + 4/2 + 4/3 + 4/4 = 8 1/3
8773 * This is called the "coupon collector problem" and H(n) is called the
8774 * harmonic series. This could be approximated by n * ln(n), but for
8775 * reasonable numbers of drives we might as well just compute the series.
8777 * Alternatively we could set the target to the number of pages necessary
8778 * so that the expected number of active spindles is some arbitrary
8779 * percentage of the total. This sounds the same but is actually slightly
8780 * different. The result ends up being ln(1-P)/ln((n-1)/n) where P is
8781 * that desired fraction.
8783 * Experimental results show that both of these formulas aren't aggressive
8784 * enough, but we don't really have any better proposals.
8786 * Note that if *newval = 0 (disabled), we must set target = 0.
8790 for (i = 1; i <= *newval; i++)
8791 new_prefetch_pages += (double) *newval / (double) i;
8793 /* This range check shouldn't fail, but let's be paranoid */
8794 if (new_prefetch_pages >= 0.0 && new_prefetch_pages < (double) INT_MAX)
8796 int *myextra = (int *) guc_malloc(ERROR, sizeof(int));
8798 *myextra = (int) rint(new_prefetch_pages);
8799 *extra = (void *) myextra;
8807 #endif /* USE_PREFETCH */
8811 assign_effective_io_concurrency(int newval, void *extra)
8814 target_prefetch_pages = *((int *) extra);
8815 #endif /* USE_PREFETCH */
8819 assign_pgstat_temp_directory(const char *newval, void *extra)
8821 /* check_canonical_path already canonicalized newval for us */
8827 dname = guc_malloc(ERROR, strlen(newval) + 1); /* runtime dir */
8828 sprintf(dname, "%s", newval);
8831 tname = guc_malloc(ERROR, strlen(newval) + 12); /* /global.tmp */
8832 sprintf(tname, "%s/global.tmp", newval);
8833 fname = guc_malloc(ERROR, strlen(newval) + 13); /* /global.stat */
8834 sprintf(fname, "%s/global.stat", newval);
8836 if (pgstat_stat_directory)
8837 free(pgstat_stat_directory);
8838 pgstat_stat_directory = dname;
8839 if (pgstat_stat_tmpname)
8840 free(pgstat_stat_tmpname);
8841 pgstat_stat_tmpname = tname;
8842 if (pgstat_stat_filename)
8843 free(pgstat_stat_filename);
8844 pgstat_stat_filename = fname;
8848 check_application_name(char **newval, void **extra, GucSource source)
8850 /* Only allow clean ASCII chars in the application name */
8853 for (p = *newval; *p; p++)
8855 if (*p < 32 || *p > 126)
8863 assign_application_name(const char *newval, void *extra)
8865 /* Update the pg_stat_activity view */
8866 pgstat_report_appname(newval);
8870 show_unix_socket_permissions(void)
8874 snprintf(buf, sizeof(buf), "%04o", Unix_socket_permissions);
8879 show_log_file_mode(void)
8883 snprintf(buf, sizeof(buf), "%04o", Log_file_mode);
8887 #include "guc-file.c"