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-2015, PostgreSQL Global Development Group
10 * Written by Peter Eisentraut <peter_e@gmx.net>.
13 * src/backend/utils/misc/guc.c
15 *--------------------------------------------------------------------
29 #include "access/commit_ts.h"
30 #include "access/gin.h"
31 #include "access/transam.h"
32 #include "access/twophase.h"
33 #include "access/xact.h"
34 #include "catalog/namespace.h"
35 #include "commands/async.h"
36 #include "commands/prepare.h"
37 #include "commands/vacuum.h"
38 #include "commands/variable.h"
39 #include "commands/trigger.h"
41 #include "libpq/auth.h"
42 #include "libpq/be-fsstubs.h"
43 #include "libpq/libpq.h"
44 #include "libpq/pqformat.h"
45 #include "miscadmin.h"
46 #include "optimizer/cost.h"
47 #include "optimizer/geqo.h"
48 #include "optimizer/paths.h"
49 #include "optimizer/planmain.h"
50 #include "parser/parse_expr.h"
51 #include "parser/parse_type.h"
52 #include "parser/parser.h"
53 #include "parser/scansup.h"
55 #include "postmaster/autovacuum.h"
56 #include "postmaster/bgworker.h"
57 #include "postmaster/bgwriter.h"
58 #include "postmaster/postmaster.h"
59 #include "postmaster/syslogger.h"
60 #include "postmaster/walwriter.h"
61 #include "replication/slot.h"
62 #include "replication/syncrep.h"
63 #include "replication/walreceiver.h"
64 #include "replication/walsender.h"
65 #include "storage/bufmgr.h"
66 #include "storage/dsm_impl.h"
67 #include "storage/standby.h"
68 #include "storage/fd.h"
69 #include "storage/pg_shmem.h"
70 #include "storage/proc.h"
71 #include "storage/predicate.h"
72 #include "tcop/tcopprot.h"
73 #include "tsearch/ts_cache.h"
74 #include "utils/builtins.h"
75 #include "utils/bytea.h"
76 #include "utils/guc_tables.h"
77 #include "utils/memutils.h"
78 #include "utils/pg_locale.h"
79 #include "utils/plancache.h"
80 #include "utils/portal.h"
81 #include "utils/ps_status.h"
82 #include "utils/rls.h"
83 #include "utils/snapmgr.h"
84 #include "utils/tzparser.h"
85 #include "utils/xml.h"
88 #define PG_KRB_SRVTAB ""
91 #define CONFIG_FILENAME "postgresql.conf"
92 #define HBA_FILENAME "pg_hba.conf"
93 #define IDENT_FILENAME "pg_ident.conf"
96 #define CONFIG_EXEC_PARAMS "global/config_exec_params"
97 #define CONFIG_EXEC_PARAMS_NEW "global/config_exec_params.new"
101 * Precision with which REAL type guc values are to be printed for GUC
104 #define REALTYPE_PRECISION 17
106 /* XXX these should appear in other modules' header files */
107 extern bool Log_disconnections;
108 extern int CommitDelay;
109 extern int CommitSiblings;
110 extern char *default_tablespace;
111 extern char *temp_tablespaces;
112 extern bool ignore_checksum_failure;
113 extern bool synchronize_seqscans;
115 #ifdef TRACE_SYNCSCAN
116 extern bool trace_syncscan;
118 #ifdef DEBUG_BOUNDED_SORT
119 extern bool optimize_bounded_sort;
122 static int GUC_check_errcode_value;
124 /* global variables for check hook support */
125 char *GUC_check_errmsg_string;
126 char *GUC_check_errdetail_string;
127 char *GUC_check_errhint_string;
129 static void do_serialize(char **destptr, Size *maxbytes, const char *fmt,...) pg_attribute_printf(3, 4);
131 static void set_config_sourcefile(const char *name, char *sourcefile,
133 static bool call_bool_check_hook(struct config_bool * conf, bool *newval,
134 void **extra, GucSource source, int elevel);
135 static bool call_int_check_hook(struct config_int * conf, int *newval,
136 void **extra, GucSource source, int elevel);
137 static bool call_real_check_hook(struct config_real * conf, double *newval,
138 void **extra, GucSource source, int elevel);
139 static bool call_string_check_hook(struct config_string * conf, char **newval,
140 void **extra, GucSource source, int elevel);
141 static bool call_enum_check_hook(struct config_enum * conf, int *newval,
142 void **extra, GucSource source, int elevel);
144 static bool check_log_destination(char **newval, void **extra, GucSource source);
145 static void assign_log_destination(const char *newval, void *extra);
148 static int syslog_facility = LOG_LOCAL0;
150 static int syslog_facility = 0;
153 static void assign_syslog_facility(int newval, void *extra);
154 static void assign_syslog_ident(const char *newval, void *extra);
155 static void assign_session_replication_role(int newval, void *extra);
156 static bool check_temp_buffers(int *newval, void **extra, GucSource source);
157 static bool check_bonjour(bool *newval, void **extra, GucSource source);
158 static bool check_ssl(bool *newval, void **extra, GucSource source);
159 static bool check_stage_log_stats(bool *newval, void **extra, GucSource source);
160 static bool check_log_stats(bool *newval, void **extra, GucSource source);
161 static bool check_canonical_path(char **newval, void **extra, GucSource source);
162 static bool check_timezone_abbreviations(char **newval, void **extra, GucSource source);
163 static void assign_timezone_abbreviations(const char *newval, void *extra);
164 static void pg_timezone_abbrev_initialize(void);
165 static const char *show_archive_command(void);
166 static void assign_tcp_keepalives_idle(int newval, void *extra);
167 static void assign_tcp_keepalives_interval(int newval, void *extra);
168 static void assign_tcp_keepalives_count(int newval, void *extra);
169 static const char *show_tcp_keepalives_idle(void);
170 static const char *show_tcp_keepalives_interval(void);
171 static const char *show_tcp_keepalives_count(void);
172 static bool check_maxconnections(int *newval, void **extra, GucSource source);
173 static bool check_max_worker_processes(int *newval, void **extra, GucSource source);
174 static bool check_autovacuum_max_workers(int *newval, void **extra, GucSource source);
175 static bool check_autovacuum_work_mem(int *newval, void **extra, GucSource source);
176 static bool check_effective_io_concurrency(int *newval, void **extra, GucSource source);
177 static void assign_effective_io_concurrency(int newval, void *extra);
178 static void assign_pgstat_temp_directory(const char *newval, void *extra);
179 static bool check_application_name(char **newval, void **extra, GucSource source);
180 static void assign_application_name(const char *newval, void *extra);
181 static bool check_cluster_name(char **newval, void **extra, GucSource source);
182 static const char *show_unix_socket_permissions(void);
183 static const char *show_log_file_mode(void);
185 /* Private functions in guc-file.l that need to be called from guc.c */
186 static ConfigVariable *ProcessConfigFileInternal(GucContext context,
187 bool applySettings, int elevel);
191 * Options for enum values defined in this module.
193 * NOTE! Option values may not contain double quotes!
196 static const struct config_enum_entry bytea_output_options[] = {
197 {"escape", BYTEA_OUTPUT_ESCAPE, false},
198 {"hex", BYTEA_OUTPUT_HEX, false},
203 * We have different sets for client and server message level options because
204 * they sort slightly different (see "log" level)
206 static const struct config_enum_entry client_message_level_options[] = {
207 {"debug", DEBUG2, true},
208 {"debug5", DEBUG5, false},
209 {"debug4", DEBUG4, false},
210 {"debug3", DEBUG3, false},
211 {"debug2", DEBUG2, false},
212 {"debug1", DEBUG1, false},
214 {"info", INFO, true},
215 {"notice", NOTICE, false},
216 {"warning", WARNING, false},
217 {"error", ERROR, false},
218 {"fatal", FATAL, true},
219 {"panic", PANIC, true},
223 static const struct config_enum_entry server_message_level_options[] = {
224 {"debug", DEBUG2, true},
225 {"debug5", DEBUG5, false},
226 {"debug4", DEBUG4, false},
227 {"debug3", DEBUG3, false},
228 {"debug2", DEBUG2, false},
229 {"debug1", DEBUG1, false},
230 {"info", INFO, false},
231 {"notice", NOTICE, false},
232 {"warning", WARNING, false},
233 {"error", ERROR, false},
235 {"fatal", FATAL, false},
236 {"panic", PANIC, false},
240 static const struct config_enum_entry intervalstyle_options[] = {
241 {"postgres", INTSTYLE_POSTGRES, false},
242 {"postgres_verbose", INTSTYLE_POSTGRES_VERBOSE, false},
243 {"sql_standard", INTSTYLE_SQL_STANDARD, false},
244 {"iso_8601", INTSTYLE_ISO_8601, false},
248 static const struct config_enum_entry log_error_verbosity_options[] = {
249 {"terse", PGERROR_TERSE, false},
250 {"default", PGERROR_DEFAULT, false},
251 {"verbose", PGERROR_VERBOSE, false},
255 static const struct config_enum_entry log_statement_options[] = {
256 {"none", LOGSTMT_NONE, false},
257 {"ddl", LOGSTMT_DDL, false},
258 {"mod", LOGSTMT_MOD, false},
259 {"all", LOGSTMT_ALL, false},
263 static const struct config_enum_entry isolation_level_options[] = {
264 {"serializable", XACT_SERIALIZABLE, false},
265 {"repeatable read", XACT_REPEATABLE_READ, false},
266 {"read committed", XACT_READ_COMMITTED, false},
267 {"read uncommitted", XACT_READ_UNCOMMITTED, false},
271 static const struct config_enum_entry session_replication_role_options[] = {
272 {"origin", SESSION_REPLICATION_ROLE_ORIGIN, false},
273 {"replica", SESSION_REPLICATION_ROLE_REPLICA, false},
274 {"local", SESSION_REPLICATION_ROLE_LOCAL, false},
278 static const struct config_enum_entry syslog_facility_options[] = {
280 {"local0", LOG_LOCAL0, false},
281 {"local1", LOG_LOCAL1, false},
282 {"local2", LOG_LOCAL2, false},
283 {"local3", LOG_LOCAL3, false},
284 {"local4", LOG_LOCAL4, false},
285 {"local5", LOG_LOCAL5, false},
286 {"local6", LOG_LOCAL6, false},
287 {"local7", LOG_LOCAL7, false},
294 static const struct config_enum_entry track_function_options[] = {
295 {"none", TRACK_FUNC_OFF, false},
296 {"pl", TRACK_FUNC_PL, false},
297 {"all", TRACK_FUNC_ALL, false},
301 static const struct config_enum_entry xmlbinary_options[] = {
302 {"base64", XMLBINARY_BASE64, false},
303 {"hex", XMLBINARY_HEX, false},
307 static const struct config_enum_entry xmloption_options[] = {
308 {"content", XMLOPTION_CONTENT, false},
309 {"document", XMLOPTION_DOCUMENT, false},
314 * Although only "on", "off", and "safe_encoding" are documented, we
315 * accept all the likely variants of "on" and "off".
317 static const struct config_enum_entry backslash_quote_options[] = {
318 {"safe_encoding", BACKSLASH_QUOTE_SAFE_ENCODING, false},
319 {"on", BACKSLASH_QUOTE_ON, false},
320 {"off", BACKSLASH_QUOTE_OFF, false},
321 {"true", BACKSLASH_QUOTE_ON, true},
322 {"false", BACKSLASH_QUOTE_OFF, true},
323 {"yes", BACKSLASH_QUOTE_ON, true},
324 {"no", BACKSLASH_QUOTE_OFF, true},
325 {"1", BACKSLASH_QUOTE_ON, true},
326 {"0", BACKSLASH_QUOTE_OFF, true},
331 * Although only "on", "off", and "partition" are documented, we
332 * accept all the likely variants of "on" and "off".
334 static const struct config_enum_entry constraint_exclusion_options[] = {
335 {"partition", CONSTRAINT_EXCLUSION_PARTITION, false},
336 {"on", CONSTRAINT_EXCLUSION_ON, false},
337 {"off", CONSTRAINT_EXCLUSION_OFF, false},
338 {"true", CONSTRAINT_EXCLUSION_ON, true},
339 {"false", CONSTRAINT_EXCLUSION_OFF, true},
340 {"yes", CONSTRAINT_EXCLUSION_ON, true},
341 {"no", CONSTRAINT_EXCLUSION_OFF, true},
342 {"1", CONSTRAINT_EXCLUSION_ON, true},
343 {"0", CONSTRAINT_EXCLUSION_OFF, true},
348 * Although only "on", "off", "remote_write", and "local" are documented, we
349 * accept all the likely variants of "on" and "off".
351 static const struct config_enum_entry synchronous_commit_options[] = {
352 {"local", SYNCHRONOUS_COMMIT_LOCAL_FLUSH, false},
353 {"remote_write", SYNCHRONOUS_COMMIT_REMOTE_WRITE, false},
354 {"on", SYNCHRONOUS_COMMIT_ON, false},
355 {"off", SYNCHRONOUS_COMMIT_OFF, false},
356 {"true", SYNCHRONOUS_COMMIT_ON, true},
357 {"false", SYNCHRONOUS_COMMIT_OFF, true},
358 {"yes", SYNCHRONOUS_COMMIT_ON, true},
359 {"no", SYNCHRONOUS_COMMIT_OFF, true},
360 {"1", SYNCHRONOUS_COMMIT_ON, true},
361 {"0", SYNCHRONOUS_COMMIT_OFF, true},
366 * Although only "on", "off", "try" are documented, we accept all the likely
367 * variants of "on" and "off".
369 static const struct config_enum_entry huge_pages_options[] = {
370 {"off", HUGE_PAGES_OFF, false},
371 {"on", HUGE_PAGES_ON, false},
372 {"try", HUGE_PAGES_TRY, false},
373 {"true", HUGE_PAGES_ON, true},
374 {"false", HUGE_PAGES_OFF, true},
375 {"yes", HUGE_PAGES_ON, true},
376 {"no", HUGE_PAGES_OFF, true},
377 {"1", HUGE_PAGES_ON, true},
378 {"0", HUGE_PAGES_OFF, true},
383 * Options for enum values stored in other modules
385 extern const struct config_enum_entry wal_level_options[];
386 extern const struct config_enum_entry archive_mode_options[];
387 extern const struct config_enum_entry sync_method_options[];
388 extern const struct config_enum_entry dynamic_shared_memory_options[];
391 * GUC option variables that are exported from this module
393 bool log_duration = false;
394 bool Debug_print_plan = false;
395 bool Debug_print_parse = false;
396 bool Debug_print_rewritten = false;
397 bool Debug_pretty_print = true;
399 bool log_parser_stats = false;
400 bool log_planner_stats = false;
401 bool log_executor_stats = false;
402 bool log_statement_stats = false; /* this is sort of all three
404 bool log_btree_build_stats = false;
408 bool check_function_bodies = true;
409 bool default_with_oids = false;
410 bool SQL_inheritance = true;
412 bool Password_encryption = true;
414 int log_min_error_statement = ERROR;
415 int log_min_messages = WARNING;
416 int client_min_messages = NOTICE;
417 int log_min_duration_statement = -1;
418 int log_temp_files = -1;
419 int trace_recovery_messages = LOG;
421 int temp_file_limit = -1;
423 int num_temp_buffers = 1024;
425 char *cluster_name = "";
426 char *ConfigFileName;
429 char *external_pid_file;
431 char *pgstat_temp_directory;
433 char *application_name;
435 int tcp_keepalives_idle;
436 int tcp_keepalives_interval;
437 int tcp_keepalives_count;
440 * This really belongs in pg_shmem.c, but is defined here so that it doesn't
441 * need to be duplicated in all the different implementations of pg_shmem.c.
446 * These variables are all dummies that don't do anything, except in some
447 * cases provide the value for SHOW to display. The real state is elsewhere
448 * and is kept in sync by assign_hooks.
450 static char *syslog_ident_str;
451 static bool session_auth_is_superuser;
452 static double phony_random_seed;
453 static char *client_encoding_string;
454 static char *datestyle_string;
455 static char *locale_collate;
456 static char *locale_ctype;
457 static char *server_encoding_string;
458 static char *server_version_string;
459 static int server_version_num;
460 static char *timezone_string;
461 static char *log_timezone_string;
462 static char *timezone_abbreviations_string;
463 static char *XactIsoLevel_string;
464 static char *data_directory;
465 static char *session_authorization_string;
466 static int max_function_args;
467 static int max_index_keys;
468 static int max_identifier_length;
469 static int block_size;
470 static int segment_size;
471 static int wal_block_size;
472 static bool data_checksums;
473 static int wal_segment_size;
474 static bool integer_datetimes;
475 static bool assert_enabled;
477 /* should be static, but commands/variable.c needs to get at this */
482 * Displayable names for context types (enum GucContext)
484 * Note: these strings are deliberately not localized.
486 const char *const GucContext_Names[] =
488 /* PGC_INTERNAL */ "internal",
489 /* PGC_POSTMASTER */ "postmaster",
490 /* PGC_SIGHUP */ "sighup",
491 /* PGC_SU_BACKEND */ "superuser-backend",
492 /* PGC_BACKEND */ "backend",
493 /* PGC_SUSET */ "superuser",
494 /* PGC_USERSET */ "user"
498 * Displayable names for source types (enum GucSource)
500 * Note: these strings are deliberately not localized.
502 const char *const GucSource_Names[] =
504 /* PGC_S_DEFAULT */ "default",
505 /* PGC_S_DYNAMIC_DEFAULT */ "default",
506 /* PGC_S_ENV_VAR */ "environment variable",
507 /* PGC_S_FILE */ "configuration file",
508 /* PGC_S_ARGV */ "command line",
509 /* PGC_S_GLOBAL */ "global",
510 /* PGC_S_DATABASE */ "database",
511 /* PGC_S_USER */ "user",
512 /* PGC_S_DATABASE_USER */ "database user",
513 /* PGC_S_CLIENT */ "client",
514 /* PGC_S_OVERRIDE */ "override",
515 /* PGC_S_INTERACTIVE */ "interactive",
516 /* PGC_S_TEST */ "test",
517 /* PGC_S_SESSION */ "session"
521 * Displayable names for the groupings defined in enum config_group
523 const char *const config_group_names[] =
526 gettext_noop("Ungrouped"),
528 gettext_noop("File Locations"),
530 gettext_noop("Connections and Authentication"),
531 /* CONN_AUTH_SETTINGS */
532 gettext_noop("Connections and Authentication / Connection Settings"),
533 /* CONN_AUTH_SECURITY */
534 gettext_noop("Connections and Authentication / Security and Authentication"),
536 gettext_noop("Resource Usage"),
538 gettext_noop("Resource Usage / Memory"),
540 gettext_noop("Resource Usage / Disk"),
541 /* RESOURCES_KERNEL */
542 gettext_noop("Resource Usage / Kernel Resources"),
543 /* RESOURCES_VACUUM_DELAY */
544 gettext_noop("Resource Usage / Cost-Based Vacuum Delay"),
545 /* RESOURCES_BGWRITER */
546 gettext_noop("Resource Usage / Background Writer"),
547 /* RESOURCES_ASYNCHRONOUS */
548 gettext_noop("Resource Usage / Asynchronous Behavior"),
550 gettext_noop("Write-Ahead Log"),
552 gettext_noop("Write-Ahead Log / Settings"),
553 /* WAL_CHECKPOINTS */
554 gettext_noop("Write-Ahead Log / Checkpoints"),
556 gettext_noop("Write-Ahead Log / Archiving"),
558 gettext_noop("Replication"),
559 /* REPLICATION_SENDING */
560 gettext_noop("Replication / Sending Servers"),
561 /* REPLICATION_MASTER */
562 gettext_noop("Replication / Master Server"),
563 /* REPLICATION_STANDBY */
564 gettext_noop("Replication / Standby Servers"),
566 gettext_noop("Query Tuning"),
567 /* QUERY_TUNING_METHOD */
568 gettext_noop("Query Tuning / Planner Method Configuration"),
569 /* QUERY_TUNING_COST */
570 gettext_noop("Query Tuning / Planner Cost Constants"),
571 /* QUERY_TUNING_GEQO */
572 gettext_noop("Query Tuning / Genetic Query Optimizer"),
573 /* QUERY_TUNING_OTHER */
574 gettext_noop("Query Tuning / Other Planner Options"),
576 gettext_noop("Reporting and Logging"),
578 gettext_noop("Reporting and Logging / Where to Log"),
580 gettext_noop("Reporting and Logging / When to Log"),
582 gettext_noop("Reporting and Logging / What to Log"),
584 gettext_noop("Statistics"),
585 /* STATS_MONITORING */
586 gettext_noop("Statistics / Monitoring"),
587 /* STATS_COLLECTOR */
588 gettext_noop("Statistics / Query and Index Statistics Collector"),
590 gettext_noop("Autovacuum"),
592 gettext_noop("Client Connection Defaults"),
593 /* CLIENT_CONN_STATEMENT */
594 gettext_noop("Client Connection Defaults / Statement Behavior"),
595 /* CLIENT_CONN_LOCALE */
596 gettext_noop("Client Connection Defaults / Locale and Formatting"),
597 /* CLIENT_CONN_PRELOAD */
598 gettext_noop("Client Connection Defaults / Shared Library Preloading"),
599 /* CLIENT_CONN_OTHER */
600 gettext_noop("Client Connection Defaults / Other Defaults"),
601 /* LOCK_MANAGEMENT */
602 gettext_noop("Lock Management"),
604 gettext_noop("Version and Platform Compatibility"),
605 /* COMPAT_OPTIONS_PREVIOUS */
606 gettext_noop("Version and Platform Compatibility / Previous PostgreSQL Versions"),
607 /* COMPAT_OPTIONS_CLIENT */
608 gettext_noop("Version and Platform Compatibility / Other Platforms and Clients"),
610 gettext_noop("Error Handling"),
612 gettext_noop("Preset Options"),
614 gettext_noop("Customized Options"),
615 /* DEVELOPER_OPTIONS */
616 gettext_noop("Developer Options"),
617 /* help_config wants this array to be null-terminated */
622 * Displayable names for GUC variable types (enum config_type)
624 * Note: these strings are deliberately not localized.
626 const char *const config_type_names[] =
628 /* PGC_BOOL */ "bool",
629 /* PGC_INT */ "integer",
630 /* PGC_REAL */ "real",
631 /* PGC_STRING */ "string",
632 /* PGC_ENUM */ "enum"
636 * Unit conversion tables.
638 * There are two tables, one for memory units, and another for time units.
639 * For each supported conversion from one unit to another, we have an entry
642 * To keep things simple, and to avoid intermediate-value overflows,
643 * conversions are never chained. There needs to be a direct conversion
644 * between all units (of the same type).
646 * The conversions from each base unit must be kept in order from greatest
647 * to smallest unit; convert_from_base_unit() relies on that. (The order of
648 * the base units does not matter.)
650 #define MAX_UNIT_LEN 3 /* length of longest recognized unit string */
654 char unit[MAX_UNIT_LEN + 1]; /* unit, as a string, like "kB" or
656 int base_unit; /* GUC_UNIT_XXX */
657 int multiplier; /* If positive, multiply the value with this
658 * for unit -> base_unit conversion. If
659 * negative, divide (with the absolute value) */
662 /* Ensure that the constants in the tables don't overflow or underflow */
663 #if BLCKSZ < 1024 || BLCKSZ > (1024*1024)
664 #error BLCKSZ must be between 1KB and 1MB
666 #if XLOG_BLCKSZ < 1024 || XLOG_BLCKSZ > (1024*1024)
667 #error XLOG_BLCKSZ must be between 1KB and 1MB
669 #if XLOG_SEG_SIZE < (1024*1024) || XLOG_BLCKSZ > (1024*1024*1024)
670 #error XLOG_SEG_SIZE must be between 1MB and 1GB
673 static const char *memory_units_hint = gettext_noop("Valid units for this parameter are \"kB\", \"MB\", \"GB\", and \"TB\".");
675 static const unit_conversion memory_unit_conversion_table[] =
677 {"TB", GUC_UNIT_KB, 1024 * 1024 * 1024},
678 {"GB", GUC_UNIT_KB, 1024 * 1024},
679 {"MB", GUC_UNIT_KB, 1024},
680 {"kB", GUC_UNIT_KB, 1},
682 {"TB", GUC_UNIT_BLOCKS, (1024 * 1024 * 1024) / (BLCKSZ / 1024)},
683 {"GB", GUC_UNIT_BLOCKS, (1024 * 1024) / (BLCKSZ / 1024)},
684 {"MB", GUC_UNIT_BLOCKS, 1024 / (BLCKSZ / 1024)},
685 {"kB", GUC_UNIT_BLOCKS, -(BLCKSZ / 1024)},
687 {"TB", GUC_UNIT_XBLOCKS, (1024 * 1024 * 1024) / (XLOG_BLCKSZ / 1024)},
688 {"GB", GUC_UNIT_XBLOCKS, (1024 * 1024) / (XLOG_BLCKSZ / 1024)},
689 {"MB", GUC_UNIT_XBLOCKS, 1024 / (XLOG_BLCKSZ / 1024)},
690 {"kB", GUC_UNIT_XBLOCKS, -(XLOG_BLCKSZ / 1024)},
692 {"TB", GUC_UNIT_XSEGS, (1024 * 1024 * 1024) / (XLOG_SEG_SIZE / 1024)},
693 {"GB", GUC_UNIT_XSEGS, (1024 * 1024) / (XLOG_SEG_SIZE / 1024)},
694 {"MB", GUC_UNIT_XSEGS, -(XLOG_SEG_SIZE / (1024 * 1024))},
695 {"kB", GUC_UNIT_XSEGS, -(XLOG_SEG_SIZE / 1024)},
697 {""} /* end of table marker */
700 static const char *time_units_hint = gettext_noop("Valid units for this parameter are \"ms\", \"s\", \"min\", \"h\", and \"d\".");
702 static const unit_conversion time_unit_conversion_table[] =
704 {"d", GUC_UNIT_MS, 1000 * 60 * 60 * 24},
705 {"h", GUC_UNIT_MS, 1000 * 60 * 60},
706 {"min", GUC_UNIT_MS, 1000 * 60},
707 {"s", GUC_UNIT_MS, 1000},
708 {"ms", GUC_UNIT_MS, 1},
710 {"d", GUC_UNIT_S, 60 * 60 * 24},
711 {"h", GUC_UNIT_S, 60 * 60},
712 {"min", GUC_UNIT_S, 60},
713 {"s", GUC_UNIT_S, 1},
714 {"ms", GUC_UNIT_S, -1000},
716 {"d", GUC_UNIT_MIN, 60 * 24},
717 {"h", GUC_UNIT_MIN, 60},
718 {"min", GUC_UNIT_MIN, 1},
719 {"s", GUC_UNIT_MIN, -60},
720 {"ms", GUC_UNIT_MIN, -1000 * 60},
722 {""} /* end of table marker */
726 * Contents of GUC tables
728 * See src/backend/utils/misc/README for design notes.
732 * 1. Declare a global variable of type bool, int, double, or char*
733 * and make use of it.
735 * 2. Decide at what times it's safe to set the option. See guc.h for
738 * 3. Decide on a name, a default value, upper and lower bounds (if
741 * 4. Add a record below.
743 * 5. Add it to src/backend/utils/misc/postgresql.conf.sample, if
746 * 6. Don't forget to document the option (at least in config.sgml).
748 * 7. If it's a new GUC_LIST option you must edit pg_dumpall.c to ensure
749 * it is not single quoted at dump time.
753 /******** option records follow ********/
755 static struct config_bool ConfigureNamesBool[] =
758 {"enable_seqscan", PGC_USERSET, QUERY_TUNING_METHOD,
759 gettext_noop("Enables the planner's use of sequential-scan plans."),
767 {"enable_indexscan", PGC_USERSET, QUERY_TUNING_METHOD,
768 gettext_noop("Enables the planner's use of index-scan plans."),
776 {"enable_indexonlyscan", PGC_USERSET, QUERY_TUNING_METHOD,
777 gettext_noop("Enables the planner's use of index-only-scan plans."),
780 &enable_indexonlyscan,
785 {"enable_bitmapscan", PGC_USERSET, QUERY_TUNING_METHOD,
786 gettext_noop("Enables the planner's use of bitmap-scan plans."),
794 {"enable_tidscan", PGC_USERSET, QUERY_TUNING_METHOD,
795 gettext_noop("Enables the planner's use of TID scan plans."),
803 {"enable_sort", PGC_USERSET, QUERY_TUNING_METHOD,
804 gettext_noop("Enables the planner's use of explicit sort steps."),
812 {"enable_hashagg", PGC_USERSET, QUERY_TUNING_METHOD,
813 gettext_noop("Enables the planner's use of hashed aggregation plans."),
821 {"enable_material", PGC_USERSET, QUERY_TUNING_METHOD,
822 gettext_noop("Enables the planner's use of materialization."),
830 {"enable_nestloop", PGC_USERSET, QUERY_TUNING_METHOD,
831 gettext_noop("Enables the planner's use of nested-loop join plans."),
839 {"enable_mergejoin", PGC_USERSET, QUERY_TUNING_METHOD,
840 gettext_noop("Enables the planner's use of merge join plans."),
848 {"enable_hashjoin", PGC_USERSET, QUERY_TUNING_METHOD,
849 gettext_noop("Enables the planner's use of hash join plans."),
857 {"geqo", PGC_USERSET, QUERY_TUNING_GEQO,
858 gettext_noop("Enables genetic query optimization."),
859 gettext_noop("This algorithm attempts to do planning without "
860 "exhaustive searching.")
867 /* Not for general use --- used by SET SESSION AUTHORIZATION */
868 {"is_superuser", PGC_INTERNAL, UNGROUPED,
869 gettext_noop("Shows whether the current user is a superuser."),
871 GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
873 &session_auth_is_superuser,
878 {"bonjour", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
879 gettext_noop("Enables advertising the server via Bonjour."),
884 check_bonjour, NULL, NULL
887 {"track_commit_timestamp", PGC_POSTMASTER, REPLICATION,
888 gettext_noop("Collects transaction commit time."),
891 &track_commit_timestamp,
896 {"ssl", PGC_POSTMASTER, CONN_AUTH_SECURITY,
897 gettext_noop("Enables SSL connections."),
902 check_ssl, NULL, NULL
905 {"ssl_prefer_server_ciphers", PGC_POSTMASTER, CONN_AUTH_SECURITY,
906 gettext_noop("Give priority to server ciphersuite order."),
909 &SSLPreferServerCiphers,
914 {"fsync", PGC_SIGHUP, WAL_SETTINGS,
915 gettext_noop("Forces synchronization of updates to disk."),
916 gettext_noop("The server will use the fsync() system call in several places to make "
917 "sure that updates are physically written to disk. This insures "
918 "that a database cluster will recover to a consistent state after "
919 "an operating system or hardware crash.")
926 {"ignore_checksum_failure", PGC_SUSET, DEVELOPER_OPTIONS,
927 gettext_noop("Continues processing after a checksum failure."),
928 gettext_noop("Detection of a checksum failure normally causes PostgreSQL to "
929 "report an error, aborting the current transaction. Setting "
930 "ignore_checksum_failure to true causes the system to ignore the failure "
931 "(but still report a warning), and continue processing. This "
932 "behavior could cause crashes or other serious problems. Only "
933 "has an effect if checksums are enabled."),
936 &ignore_checksum_failure,
941 {"zero_damaged_pages", PGC_SUSET, DEVELOPER_OPTIONS,
942 gettext_noop("Continues processing past damaged page headers."),
943 gettext_noop("Detection of a damaged page header normally causes PostgreSQL to "
944 "report an error, aborting the current transaction. Setting "
945 "zero_damaged_pages to true causes the system to instead report a "
946 "warning, zero out the damaged page, and continue processing. This "
947 "behavior will destroy data, namely all the rows on the damaged page."),
955 {"full_page_writes", PGC_SIGHUP, WAL_SETTINGS,
956 gettext_noop("Writes full pages to WAL when first modified after a checkpoint."),
957 gettext_noop("A page write in process during an operating system crash might be "
958 "only partially written to disk. During recovery, the row changes "
959 "stored in WAL are not enough to recover. This option writes "
960 "pages when first modified after a checkpoint to WAL so full recovery "
969 {"wal_log_hints", PGC_POSTMASTER, WAL_SETTINGS,
970 gettext_noop("Writes full pages to WAL when first modified after a checkpoint, even for a non-critical modifications."),
979 {"wal_compression", PGC_SUSET, WAL_SETTINGS,
980 gettext_noop("Compresses full-page writes written in WAL file."),
989 {"log_checkpoints", PGC_SIGHUP, LOGGING_WHAT,
990 gettext_noop("Logs each checkpoint."),
998 {"log_connections", PGC_SU_BACKEND, LOGGING_WHAT,
999 gettext_noop("Logs each successful connection."),
1007 {"log_disconnections", PGC_SU_BACKEND, LOGGING_WHAT,
1008 gettext_noop("Logs end of a session, including duration."),
1011 &Log_disconnections,
1016 {"log_replication_commands", PGC_SUSET, LOGGING_WHAT,
1017 gettext_noop("Logs each replication command."),
1020 &log_replication_commands,
1025 {"debug_assertions", PGC_INTERNAL, PRESET_OPTIONS,
1026 gettext_noop("Shows whether the running server has assertion checks enabled."),
1028 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1031 #ifdef USE_ASSERT_CHECKING
1040 {"exit_on_error", PGC_USERSET, ERROR_HANDLING_OPTIONS,
1041 gettext_noop("Terminate session on any error."),
1049 {"restart_after_crash", PGC_SIGHUP, ERROR_HANDLING_OPTIONS,
1050 gettext_noop("Reinitialize server after backend crash."),
1053 &restart_after_crash,
1059 {"log_duration", PGC_SUSET, LOGGING_WHAT,
1060 gettext_noop("Logs the duration of each completed SQL statement."),
1068 {"debug_print_parse", PGC_USERSET, LOGGING_WHAT,
1069 gettext_noop("Logs each query's parse tree."),
1077 {"debug_print_rewritten", PGC_USERSET, LOGGING_WHAT,
1078 gettext_noop("Logs each query's rewritten parse tree."),
1081 &Debug_print_rewritten,
1086 {"debug_print_plan", PGC_USERSET, LOGGING_WHAT,
1087 gettext_noop("Logs each query's execution plan."),
1095 {"debug_pretty_print", PGC_USERSET, LOGGING_WHAT,
1096 gettext_noop("Indents parse and plan tree displays."),
1099 &Debug_pretty_print,
1104 {"log_parser_stats", PGC_SUSET, STATS_MONITORING,
1105 gettext_noop("Writes parser performance statistics to the server log."),
1110 check_stage_log_stats, NULL, NULL
1113 {"log_planner_stats", PGC_SUSET, STATS_MONITORING,
1114 gettext_noop("Writes planner performance statistics to the server log."),
1119 check_stage_log_stats, NULL, NULL
1122 {"log_executor_stats", PGC_SUSET, STATS_MONITORING,
1123 gettext_noop("Writes executor performance statistics to the server log."),
1126 &log_executor_stats,
1128 check_stage_log_stats, NULL, NULL
1131 {"log_statement_stats", PGC_SUSET, STATS_MONITORING,
1132 gettext_noop("Writes cumulative performance statistics to the server log."),
1135 &log_statement_stats,
1137 check_log_stats, NULL, NULL
1139 #ifdef BTREE_BUILD_STATS
1141 {"log_btree_build_stats", PGC_SUSET, DEVELOPER_OPTIONS,
1142 gettext_noop("Logs system resource usage statistics (memory and CPU) on various B-tree operations."),
1146 &log_btree_build_stats,
1153 {"track_activities", PGC_SUSET, STATS_COLLECTOR,
1154 gettext_noop("Collects information about executing commands."),
1155 gettext_noop("Enables the collection of information on the currently "
1156 "executing command of each session, along with "
1157 "the time at which that command began execution.")
1159 &pgstat_track_activities,
1164 {"track_counts", PGC_SUSET, STATS_COLLECTOR,
1165 gettext_noop("Collects statistics on database activity."),
1168 &pgstat_track_counts,
1173 {"track_io_timing", PGC_SUSET, STATS_COLLECTOR,
1174 gettext_noop("Collects timing statistics for database I/O activity."),
1183 {"update_process_title", PGC_SUSET, STATS_COLLECTOR,
1184 gettext_noop("Updates the process title to show the active SQL command."),
1185 gettext_noop("Enables updating of the process title every time a new SQL command is received by the server.")
1187 &update_process_title,
1193 {"autovacuum", PGC_SIGHUP, AUTOVACUUM,
1194 gettext_noop("Starts the autovacuum subprocess."),
1197 &autovacuum_start_daemon,
1203 {"trace_notify", PGC_USERSET, DEVELOPER_OPTIONS,
1204 gettext_noop("Generates debugging output for LISTEN and NOTIFY."),
1215 {"trace_locks", PGC_SUSET, DEVELOPER_OPTIONS,
1216 gettext_noop("Emits information about lock usage."),
1225 {"trace_userlocks", PGC_SUSET, DEVELOPER_OPTIONS,
1226 gettext_noop("Emits information about user lock usage."),
1235 {"trace_lwlocks", PGC_SUSET, DEVELOPER_OPTIONS,
1236 gettext_noop("Emits information about lightweight lock usage."),
1245 {"debug_deadlocks", PGC_SUSET, DEVELOPER_OPTIONS,
1246 gettext_noop("Dumps information about all current locks when a deadlock timeout occurs."),
1257 {"log_lock_waits", PGC_SUSET, LOGGING_WHAT,
1258 gettext_noop("Logs long lock waits."),
1267 {"log_hostname", PGC_SIGHUP, LOGGING_WHAT,
1268 gettext_noop("Logs the host name in the connection logs."),
1269 gettext_noop("By default, connection logs only show the IP address "
1270 "of the connecting host. If you want them to show the host name you "
1271 "can turn this on, but depending on your host name resolution "
1272 "setup it might impose a non-negligible performance penalty.")
1279 {"sql_inheritance", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1280 gettext_noop("Causes subtables to be included by default in various commands."),
1288 {"password_encryption", PGC_USERSET, CONN_AUTH_SECURITY,
1289 gettext_noop("Encrypt passwords."),
1290 gettext_noop("When a password is specified in CREATE USER or "
1291 "ALTER USER without writing either ENCRYPTED or UNENCRYPTED, "
1292 "this parameter determines whether the password is to be encrypted.")
1294 &Password_encryption,
1299 {"transform_null_equals", PGC_USERSET, COMPAT_OPTIONS_CLIENT,
1300 gettext_noop("Treats \"expr=NULL\" as \"expr IS NULL\"."),
1301 gettext_noop("When turned on, expressions of the form expr = NULL "
1302 "(or NULL = expr) are treated as expr IS NULL, that is, they "
1303 "return true if expr evaluates to the null value, and false "
1304 "otherwise. The correct behavior of expr = NULL is to always "
1305 "return null (unknown).")
1307 &Transform_null_equals,
1312 {"db_user_namespace", PGC_SIGHUP, CONN_AUTH_SECURITY,
1313 gettext_noop("Enables per-database user names."),
1321 {"default_transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
1322 gettext_noop("Sets the default read-only status of new transactions."),
1325 &DefaultXactReadOnly,
1330 {"transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
1331 gettext_noop("Sets the current transaction's read-only status."),
1333 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1337 check_transaction_read_only, NULL, NULL
1340 {"default_transaction_deferrable", PGC_USERSET, CLIENT_CONN_STATEMENT,
1341 gettext_noop("Sets the default deferrable status of new transactions."),
1344 &DefaultXactDeferrable,
1349 {"transaction_deferrable", PGC_USERSET, CLIENT_CONN_STATEMENT,
1350 gettext_noop("Whether to defer a read-only serializable transaction until it can be executed with no possible serialization failures."),
1352 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1356 check_transaction_deferrable, NULL, NULL
1359 {"row_security", PGC_USERSET, CONN_AUTH_SECURITY,
1360 gettext_noop("Enable row security."),
1361 gettext_noop("When enabled, row security will be applied to all users.")
1368 {"check_function_bodies", PGC_USERSET, CLIENT_CONN_STATEMENT,
1369 gettext_noop("Check function bodies during CREATE FUNCTION."),
1372 &check_function_bodies,
1377 {"array_nulls", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1378 gettext_noop("Enable input of NULL elements in arrays."),
1379 gettext_noop("When turned on, unquoted NULL in an array input "
1380 "value means a null value; "
1381 "otherwise it is taken literally.")
1388 {"default_with_oids", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1389 gettext_noop("Create new tables with OIDs by default."),
1397 {"logging_collector", PGC_POSTMASTER, LOGGING_WHERE,
1398 gettext_noop("Start a subprocess to capture stderr output and/or csvlogs into log files."),
1406 {"log_truncate_on_rotation", PGC_SIGHUP, LOGGING_WHERE,
1407 gettext_noop("Truncate existing log files of same name during log rotation."),
1410 &Log_truncate_on_rotation,
1417 {"trace_sort", PGC_USERSET, DEVELOPER_OPTIONS,
1418 gettext_noop("Emit information about resource usage in sorting."),
1428 #ifdef TRACE_SYNCSCAN
1429 /* this is undocumented because not exposed in a standard build */
1431 {"trace_syncscan", PGC_USERSET, DEVELOPER_OPTIONS,
1432 gettext_noop("Generate debugging output for synchronized scanning."),
1442 #ifdef DEBUG_BOUNDED_SORT
1443 /* this is undocumented because not exposed in a standard build */
1446 "optimize_bounded_sort", PGC_USERSET, QUERY_TUNING_METHOD,
1447 gettext_noop("Enable bounded sorting using heap sort."),
1451 &optimize_bounded_sort,
1459 {"wal_debug", PGC_SUSET, DEVELOPER_OPTIONS,
1460 gettext_noop("Emit WAL-related debugging output."),
1471 {"integer_datetimes", PGC_INTERNAL, PRESET_OPTIONS,
1472 gettext_noop("Datetimes are integer based."),
1474 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1477 #ifdef HAVE_INT64_TIMESTAMP
1486 {"krb_caseins_users", PGC_SIGHUP, CONN_AUTH_SECURITY,
1487 gettext_noop("Sets whether Kerberos and GSSAPI user names should be treated as case-insensitive."),
1490 &pg_krb_caseins_users,
1496 {"escape_string_warning", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1497 gettext_noop("Warn about backslash escapes in ordinary string literals."),
1500 &escape_string_warning,
1506 {"standard_conforming_strings", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1507 gettext_noop("Causes '...' strings to treat backslashes literally."),
1511 &standard_conforming_strings,
1517 {"synchronize_seqscans", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1518 gettext_noop("Enable synchronized sequential scans."),
1521 &synchronize_seqscans,
1527 {"hot_standby", PGC_POSTMASTER, REPLICATION_STANDBY,
1528 gettext_noop("Allows connections and queries during recovery."),
1537 {"hot_standby_feedback", PGC_SIGHUP, REPLICATION_STANDBY,
1538 gettext_noop("Allows feedback from a hot standby to the primary that will avoid query conflicts."),
1541 &hot_standby_feedback,
1547 {"allow_system_table_mods", PGC_POSTMASTER, DEVELOPER_OPTIONS,
1548 gettext_noop("Allows modifications of the structure of system tables."),
1552 &allowSystemTableMods,
1558 {"ignore_system_indexes", PGC_BACKEND, DEVELOPER_OPTIONS,
1559 gettext_noop("Disables reading from system indexes."),
1560 gettext_noop("It does not prevent updating the indexes, so it is safe "
1561 "to use. The worst consequence is slowness."),
1564 &IgnoreSystemIndexes,
1570 {"lo_compat_privileges", PGC_SUSET, COMPAT_OPTIONS_PREVIOUS,
1571 gettext_noop("Enables backward compatibility mode for privilege checks on large objects."),
1572 gettext_noop("Skips privilege checks when reading or modifying large objects, "
1573 "for compatibility with PostgreSQL releases prior to 9.0.")
1575 &lo_compat_privileges,
1581 {"operator_precedence_warning", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1582 gettext_noop("Emit a warning for constructs that changed meaning since PostgreSQL 9.4."),
1585 &operator_precedence_warning,
1591 {"quote_all_identifiers", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1592 gettext_noop("When generating SQL fragments, quote all identifiers."),
1595 "e_all_identifiers,
1601 {"data_checksums", PGC_INTERNAL, PRESET_OPTIONS,
1602 gettext_noop("Shows whether data checksums are turned on for this cluster."),
1604 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1611 /* End-of-list marker */
1613 {NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL, NULL
1618 static struct config_int ConfigureNamesInt[] =
1621 {"archive_timeout", PGC_SIGHUP, WAL_ARCHIVING,
1622 gettext_noop("Forces a switch to the next xlog file if a "
1623 "new file has not been started within N seconds."),
1627 &XLogArchiveTimeout,
1632 {"post_auth_delay", PGC_BACKEND, DEVELOPER_OPTIONS,
1633 gettext_noop("Waits N seconds on connection startup after authentication."),
1634 gettext_noop("This allows attaching a debugger to the process."),
1635 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1638 0, 0, INT_MAX / 1000000,
1642 {"default_statistics_target", PGC_USERSET, QUERY_TUNING_OTHER,
1643 gettext_noop("Sets the default statistics target."),
1644 gettext_noop("This applies to table columns that have not had a "
1645 "column-specific target set via ALTER TABLE SET STATISTICS.")
1647 &default_statistics_target,
1652 {"from_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1653 gettext_noop("Sets the FROM-list size beyond which subqueries "
1654 "are not collapsed."),
1655 gettext_noop("The planner will merge subqueries into upper "
1656 "queries if the resulting FROM list would have no more than "
1659 &from_collapse_limit,
1664 {"join_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1665 gettext_noop("Sets the FROM-list size beyond which JOIN "
1666 "constructs are not flattened."),
1667 gettext_noop("The planner will flatten explicit JOIN "
1668 "constructs into lists of FROM items whenever a "
1669 "list of no more than this many items would result.")
1671 &join_collapse_limit,
1676 {"geqo_threshold", PGC_USERSET, QUERY_TUNING_GEQO,
1677 gettext_noop("Sets the threshold of FROM items beyond which GEQO is used."),
1685 {"geqo_effort", PGC_USERSET, QUERY_TUNING_GEQO,
1686 gettext_noop("GEQO: effort is used to set the default for other GEQO parameters."),
1690 DEFAULT_GEQO_EFFORT, MIN_GEQO_EFFORT, MAX_GEQO_EFFORT,
1694 {"geqo_pool_size", PGC_USERSET, QUERY_TUNING_GEQO,
1695 gettext_noop("GEQO: number of individuals in the population."),
1696 gettext_noop("Zero selects a suitable default value.")
1703 {"geqo_generations", PGC_USERSET, QUERY_TUNING_GEQO,
1704 gettext_noop("GEQO: number of iterations of the algorithm."),
1705 gettext_noop("Zero selects a suitable default value.")
1713 /* This is PGC_SUSET to prevent hiding from log_lock_waits. */
1714 {"deadlock_timeout", PGC_SUSET, LOCK_MANAGEMENT,
1715 gettext_noop("Sets the time to wait on a lock before checking for deadlock."),
1725 {"max_standby_archive_delay", PGC_SIGHUP, REPLICATION_STANDBY,
1726 gettext_noop("Sets the maximum delay before canceling queries when a hot standby server is processing archived WAL data."),
1730 &max_standby_archive_delay,
1731 30 * 1000, -1, INT_MAX,
1736 {"max_standby_streaming_delay", PGC_SIGHUP, REPLICATION_STANDBY,
1737 gettext_noop("Sets the maximum delay before canceling queries when a hot standby server is processing streamed WAL data."),
1741 &max_standby_streaming_delay,
1742 30 * 1000, -1, INT_MAX,
1747 {"wal_receiver_status_interval", PGC_SIGHUP, REPLICATION_STANDBY,
1748 gettext_noop("Sets the maximum interval between WAL receiver status reports to the primary."),
1752 &wal_receiver_status_interval,
1753 10, 0, INT_MAX / 1000,
1758 {"wal_receiver_timeout", PGC_SIGHUP, REPLICATION_STANDBY,
1759 gettext_noop("Sets the maximum wait time to receive data from the primary."),
1763 &wal_receiver_timeout,
1764 60 * 1000, 0, INT_MAX,
1769 {"max_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1770 gettext_noop("Sets the maximum number of concurrent connections."),
1774 100, 1, MAX_BACKENDS,
1775 check_maxconnections, NULL, NULL
1779 {"superuser_reserved_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1780 gettext_noop("Sets the number of connection slots reserved for superusers."),
1789 * We sometimes multiply the number of shared buffers by two without
1790 * checking for overflow, so we mustn't allow more than INT_MAX / 2.
1793 {"shared_buffers", PGC_POSTMASTER, RESOURCES_MEM,
1794 gettext_noop("Sets the number of shared memory buffers used by the server."),
1799 1024, 16, INT_MAX / 2,
1804 {"temp_buffers", PGC_USERSET, RESOURCES_MEM,
1805 gettext_noop("Sets the maximum number of temporary buffers used by each session."),
1810 1024, 100, INT_MAX / 2,
1811 check_temp_buffers, NULL, NULL
1815 {"port", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1816 gettext_noop("Sets the TCP port the server listens on."),
1820 DEF_PGPORT, 1, 65535,
1825 {"unix_socket_permissions", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1826 gettext_noop("Sets the access permissions of the Unix-domain socket."),
1827 gettext_noop("Unix-domain sockets use the usual Unix file system "
1828 "permission set. The parameter value is expected "
1829 "to be a numeric mode specification in the form "
1830 "accepted by the chmod and umask system calls. "
1831 "(To use the customary octal format the number must "
1832 "start with a 0 (zero).)")
1834 &Unix_socket_permissions,
1836 NULL, NULL, show_unix_socket_permissions
1840 {"log_file_mode", PGC_SIGHUP, LOGGING_WHERE,
1841 gettext_noop("Sets the file permissions for log files."),
1842 gettext_noop("The parameter value is expected "
1843 "to be a numeric mode specification in the form "
1844 "accepted by the chmod and umask system calls. "
1845 "(To use the customary octal format the number must "
1846 "start with a 0 (zero).)")
1850 NULL, NULL, show_log_file_mode
1854 {"work_mem", PGC_USERSET, RESOURCES_MEM,
1855 gettext_noop("Sets the maximum memory to be used for query workspaces."),
1856 gettext_noop("This much memory can be used by each internal "
1857 "sort operation and hash table before switching to "
1858 "temporary disk files."),
1862 4096, 64, MAX_KILOBYTES,
1867 {"maintenance_work_mem", PGC_USERSET, RESOURCES_MEM,
1868 gettext_noop("Sets the maximum memory to be used for maintenance operations."),
1869 gettext_noop("This includes operations such as VACUUM and CREATE INDEX."),
1872 &maintenance_work_mem,
1873 65536, 1024, MAX_KILOBYTES,
1878 * We use the hopefully-safely-small value of 100kB as the compiled-in
1879 * default for max_stack_depth. InitializeGUCOptions will increase it if
1880 * possible, depending on the actual platform-specific stack limit.
1883 {"max_stack_depth", PGC_SUSET, RESOURCES_MEM,
1884 gettext_noop("Sets the maximum stack depth, in kilobytes."),
1889 100, 100, MAX_KILOBYTES,
1890 check_max_stack_depth, assign_max_stack_depth, NULL
1894 {"temp_file_limit", PGC_SUSET, RESOURCES_DISK,
1895 gettext_noop("Limits the total size of all temporary files used by each session."),
1896 gettext_noop("-1 means no limit."),
1905 {"vacuum_cost_page_hit", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1906 gettext_noop("Vacuum cost for a page found in the buffer cache."),
1915 {"vacuum_cost_page_miss", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1916 gettext_noop("Vacuum cost for a page not found in the buffer cache."),
1919 &VacuumCostPageMiss,
1925 {"vacuum_cost_page_dirty", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1926 gettext_noop("Vacuum cost for a page dirtied by vacuum."),
1929 &VacuumCostPageDirty,
1935 {"vacuum_cost_limit", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1936 gettext_noop("Vacuum cost amount available before napping."),
1945 {"vacuum_cost_delay", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1946 gettext_noop("Vacuum cost delay in milliseconds."),
1956 {"autovacuum_vacuum_cost_delay", PGC_SIGHUP, AUTOVACUUM,
1957 gettext_noop("Vacuum cost delay in milliseconds, for autovacuum."),
1961 &autovacuum_vac_cost_delay,
1967 {"autovacuum_vacuum_cost_limit", PGC_SIGHUP, AUTOVACUUM,
1968 gettext_noop("Vacuum cost amount available before napping, for autovacuum."),
1971 &autovacuum_vac_cost_limit,
1977 {"max_files_per_process", PGC_POSTMASTER, RESOURCES_KERNEL,
1978 gettext_noop("Sets the maximum number of simultaneously open files for each server process."),
1981 &max_files_per_process,
1987 * See also CheckRequiredParameterValues() if this parameter changes
1990 {"max_prepared_transactions", PGC_POSTMASTER, RESOURCES_MEM,
1991 gettext_noop("Sets the maximum number of simultaneously prepared transactions."),
1994 &max_prepared_xacts,
2001 {"trace_lock_oidmin", PGC_SUSET, DEVELOPER_OPTIONS,
2002 gettext_noop("Sets the minimum OID of tables for tracking locks."),
2003 gettext_noop("Is used to avoid output on system tables."),
2007 FirstNormalObjectId, 0, INT_MAX,
2011 {"trace_lock_table", PGC_SUSET, DEVELOPER_OPTIONS,
2012 gettext_noop("Sets the OID of the table with unconditionally lock tracing."),
2023 {"statement_timeout", PGC_USERSET, CLIENT_CONN_STATEMENT,
2024 gettext_noop("Sets the maximum allowed duration of any statement."),
2025 gettext_noop("A value of 0 turns off the timeout."),
2034 {"lock_timeout", PGC_USERSET, CLIENT_CONN_STATEMENT,
2035 gettext_noop("Sets the maximum allowed duration of any wait for a lock."),
2036 gettext_noop("A value of 0 turns off the timeout."),
2045 {"vacuum_freeze_min_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
2046 gettext_noop("Minimum age at which VACUUM should freeze a table row."),
2049 &vacuum_freeze_min_age,
2050 50000000, 0, 1000000000,
2055 {"vacuum_freeze_table_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
2056 gettext_noop("Age at which VACUUM should scan whole table to freeze tuples."),
2059 &vacuum_freeze_table_age,
2060 150000000, 0, 2000000000,
2065 {"vacuum_multixact_freeze_min_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
2066 gettext_noop("Minimum age at which VACUUM should freeze a MultiXactId in a table row."),
2069 &vacuum_multixact_freeze_min_age,
2070 5000000, 0, 1000000000,
2075 {"vacuum_multixact_freeze_table_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
2076 gettext_noop("Multixact age at which VACUUM should scan whole table to freeze tuples."),
2079 &vacuum_multixact_freeze_table_age,
2080 150000000, 0, 2000000000,
2085 {"vacuum_defer_cleanup_age", PGC_SIGHUP, REPLICATION_MASTER,
2086 gettext_noop("Number of transactions by which VACUUM and HOT cleanup should be deferred, if any."),
2089 &vacuum_defer_cleanup_age,
2095 * See also CheckRequiredParameterValues() if this parameter changes
2098 {"max_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
2099 gettext_noop("Sets the maximum number of locks per transaction."),
2100 gettext_noop("The shared lock table is sized on the assumption that "
2101 "at most max_locks_per_transaction * max_connections distinct "
2102 "objects will need to be locked at any one time.")
2104 &max_locks_per_xact,
2110 {"max_pred_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
2111 gettext_noop("Sets the maximum number of predicate locks per transaction."),
2112 gettext_noop("The shared predicate lock table is sized on the assumption that "
2113 "at most max_pred_locks_per_transaction * max_connections distinct "
2114 "objects will need to be locked at any one time.")
2116 &max_predicate_locks_per_xact,
2122 {"authentication_timeout", PGC_SIGHUP, CONN_AUTH_SECURITY,
2123 gettext_noop("Sets the maximum allowed time to complete client authentication."),
2127 &AuthenticationTimeout,
2133 /* Not for general use */
2134 {"pre_auth_delay", PGC_SIGHUP, DEVELOPER_OPTIONS,
2135 gettext_noop("Waits N seconds on connection startup before authentication."),
2136 gettext_noop("This allows attaching a debugger to the process."),
2137 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
2145 {"wal_keep_segments", PGC_SIGHUP, REPLICATION_SENDING,
2146 gettext_noop("Sets the number of WAL files held for standby servers."),
2155 {"min_wal_size", PGC_SIGHUP, WAL_CHECKPOINTS,
2156 gettext_noop("Sets the minimum size to shrink the WAL to."),
2166 {"max_wal_size", PGC_SIGHUP, WAL_CHECKPOINTS,
2167 gettext_noop("Sets the WAL size that triggers a checkpoint."),
2173 NULL, assign_max_wal_size, NULL
2177 {"checkpoint_timeout", PGC_SIGHUP, WAL_CHECKPOINTS,
2178 gettext_noop("Sets the maximum time between automatic WAL checkpoints."),
2188 {"checkpoint_warning", PGC_SIGHUP, WAL_CHECKPOINTS,
2189 gettext_noop("Enables warnings if checkpoint segments are filled more "
2190 "frequently than this."),
2191 gettext_noop("Write a message to the server log if checkpoints "
2192 "caused by the filling of checkpoint segment files happens more "
2193 "frequently than this number of seconds. Zero turns off the warning."),
2202 {"wal_buffers", PGC_POSTMASTER, WAL_SETTINGS,
2203 gettext_noop("Sets the number of disk-page buffers in shared memory for WAL."),
2208 -1, -1, (INT_MAX / XLOG_BLCKSZ),
2209 check_wal_buffers, NULL, NULL
2213 {"wal_writer_delay", PGC_SIGHUP, WAL_SETTINGS,
2214 gettext_noop("WAL writer sleep time between WAL flushes."),
2224 /* see max_connections */
2225 {"max_wal_senders", PGC_POSTMASTER, REPLICATION_SENDING,
2226 gettext_noop("Sets the maximum number of simultaneously running WAL sender processes."),
2235 /* see max_connections */
2236 {"max_replication_slots", PGC_POSTMASTER, REPLICATION_SENDING,
2237 gettext_noop("Sets the maximum number of simultaneously defined replication slots."),
2240 &max_replication_slots,
2241 0, 0, MAX_BACKENDS /* XXX? */ ,
2246 {"wal_sender_timeout", PGC_SIGHUP, REPLICATION_SENDING,
2247 gettext_noop("Sets the maximum time to wait for WAL replication."),
2251 &wal_sender_timeout,
2252 60 * 1000, 0, INT_MAX,
2257 {"commit_delay", PGC_SUSET, WAL_SETTINGS,
2258 gettext_noop("Sets the delay in microseconds between transaction commit and "
2259 "flushing WAL to disk."),
2261 /* we have no microseconds designation, so can't supply units here */
2269 {"commit_siblings", PGC_USERSET, WAL_SETTINGS,
2270 gettext_noop("Sets the minimum concurrent open transactions before performing "
2280 {"extra_float_digits", PGC_USERSET, CLIENT_CONN_LOCALE,
2281 gettext_noop("Sets the number of digits displayed for floating-point values."),
2282 gettext_noop("This affects real, double precision, and geometric data types. "
2283 "The parameter value is added to the standard number of digits "
2284 "(FLT_DIG or DBL_DIG as appropriate).")
2286 &extra_float_digits,
2292 {"log_min_duration_statement", PGC_SUSET, LOGGING_WHEN,
2293 gettext_noop("Sets the minimum execution time above which "
2294 "statements will be logged."),
2295 gettext_noop("Zero prints all queries. -1 turns this feature off."),
2298 &log_min_duration_statement,
2304 {"log_autovacuum_min_duration", PGC_SIGHUP, LOGGING_WHAT,
2305 gettext_noop("Sets the minimum execution time above which "
2306 "autovacuum actions will be logged."),
2307 gettext_noop("Zero prints all actions. -1 turns autovacuum logging off."),
2310 &Log_autovacuum_min_duration,
2316 {"bgwriter_delay", PGC_SIGHUP, RESOURCES_BGWRITER,
2317 gettext_noop("Background writer sleep time between rounds."),
2327 {"bgwriter_lru_maxpages", PGC_SIGHUP, RESOURCES_BGWRITER,
2328 gettext_noop("Background writer maximum number of LRU pages to flush per round."),
2331 &bgwriter_lru_maxpages,
2337 {"effective_io_concurrency",
2339 RESOURCES_ASYNCHRONOUS,
2340 gettext_noop("Number of simultaneous requests that can be handled efficiently by the disk subsystem."),
2341 gettext_noop("For RAID arrays, this should be approximately the number of drive spindles in the array.")
2343 &effective_io_concurrency,
2345 1, 0, MAX_IO_CONCURRENCY,
2349 check_effective_io_concurrency, assign_effective_io_concurrency, NULL
2353 {"max_worker_processes",
2355 RESOURCES_ASYNCHRONOUS,
2356 gettext_noop("Maximum number of concurrent worker processes."),
2359 &max_worker_processes,
2361 check_max_worker_processes, NULL, NULL
2365 {"log_rotation_age", PGC_SIGHUP, LOGGING_WHERE,
2366 gettext_noop("Automatic log file rotation will occur after N minutes."),
2371 HOURS_PER_DAY * MINS_PER_HOUR, 0, INT_MAX / SECS_PER_MINUTE,
2376 {"log_rotation_size", PGC_SIGHUP, LOGGING_WHERE,
2377 gettext_noop("Automatic log file rotation will occur after N kilobytes."),
2382 10 * 1024, 0, INT_MAX / 1024,
2387 {"max_function_args", PGC_INTERNAL, PRESET_OPTIONS,
2388 gettext_noop("Shows the maximum number of function arguments."),
2390 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2393 FUNC_MAX_ARGS, FUNC_MAX_ARGS, FUNC_MAX_ARGS,
2398 {"max_index_keys", PGC_INTERNAL, PRESET_OPTIONS,
2399 gettext_noop("Shows the maximum number of index keys."),
2401 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2404 INDEX_MAX_KEYS, INDEX_MAX_KEYS, INDEX_MAX_KEYS,
2409 {"max_identifier_length", PGC_INTERNAL, PRESET_OPTIONS,
2410 gettext_noop("Shows the maximum identifier length."),
2412 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2414 &max_identifier_length,
2415 NAMEDATALEN - 1, NAMEDATALEN - 1, NAMEDATALEN - 1,
2420 {"block_size", PGC_INTERNAL, PRESET_OPTIONS,
2421 gettext_noop("Shows the size of a disk block."),
2423 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2426 BLCKSZ, BLCKSZ, BLCKSZ,
2431 {"segment_size", PGC_INTERNAL, PRESET_OPTIONS,
2432 gettext_noop("Shows the number of pages per disk file."),
2434 GUC_UNIT_BLOCKS | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2437 RELSEG_SIZE, RELSEG_SIZE, RELSEG_SIZE,
2442 {"wal_block_size", PGC_INTERNAL, PRESET_OPTIONS,
2443 gettext_noop("Shows the block size in the write ahead log."),
2445 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2448 XLOG_BLCKSZ, XLOG_BLCKSZ, XLOG_BLCKSZ,
2453 {"wal_retrieve_retry_interval", PGC_SIGHUP, REPLICATION_STANDBY,
2454 gettext_noop("Sets the time to wait before retrying to retrieve WAL"
2455 "after a failed attempt."),
2459 &wal_retrieve_retry_interval,
2465 {"wal_segment_size", PGC_INTERNAL, PRESET_OPTIONS,
2466 gettext_noop("Shows the number of pages per write ahead log segment."),
2468 GUC_UNIT_XBLOCKS | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2471 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
2472 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
2473 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
2478 {"autovacuum_naptime", PGC_SIGHUP, AUTOVACUUM,
2479 gettext_noop("Time to sleep between autovacuum runs."),
2483 &autovacuum_naptime,
2484 60, 1, INT_MAX / 1000,
2488 {"autovacuum_vacuum_threshold", PGC_SIGHUP, AUTOVACUUM,
2489 gettext_noop("Minimum number of tuple updates or deletes prior to vacuum."),
2492 &autovacuum_vac_thresh,
2497 {"autovacuum_analyze_threshold", PGC_SIGHUP, AUTOVACUUM,
2498 gettext_noop("Minimum number of tuple inserts, updates, or deletes prior to analyze."),
2501 &autovacuum_anl_thresh,
2506 /* see varsup.c for why this is PGC_POSTMASTER not PGC_SIGHUP */
2507 {"autovacuum_freeze_max_age", PGC_POSTMASTER, AUTOVACUUM,
2508 gettext_noop("Age at which to autovacuum a table to prevent transaction ID wraparound."),
2511 &autovacuum_freeze_max_age,
2512 /* see pg_resetxlog if you change the upper-limit value */
2513 200000000, 100000000, 2000000000,
2517 /* see varsup.c for why this is PGC_POSTMASTER not PGC_SIGHUP */
2518 {"autovacuum_multixact_freeze_max_age", PGC_POSTMASTER, AUTOVACUUM,
2519 gettext_noop("Multixact age at which to autovacuum a table to prevent multixact wraparound."),
2522 &autovacuum_multixact_freeze_max_age,
2523 400000000, 10000000, 2000000000,
2527 /* see max_connections */
2528 {"autovacuum_max_workers", PGC_POSTMASTER, AUTOVACUUM,
2529 gettext_noop("Sets the maximum number of simultaneously running autovacuum worker processes."),
2532 &autovacuum_max_workers,
2534 check_autovacuum_max_workers, NULL, NULL
2538 {"autovacuum_work_mem", PGC_SIGHUP, RESOURCES_MEM,
2539 gettext_noop("Sets the maximum memory to be used by each autovacuum worker process."),
2543 &autovacuum_work_mem,
2544 -1, -1, MAX_KILOBYTES,
2545 check_autovacuum_work_mem, NULL, NULL
2549 {"tcp_keepalives_idle", PGC_USERSET, CLIENT_CONN_OTHER,
2550 gettext_noop("Time between issuing TCP keepalives."),
2551 gettext_noop("A value of 0 uses the system default."),
2554 &tcp_keepalives_idle,
2556 NULL, assign_tcp_keepalives_idle, show_tcp_keepalives_idle
2560 {"tcp_keepalives_interval", PGC_USERSET, CLIENT_CONN_OTHER,
2561 gettext_noop("Time between TCP keepalive retransmits."),
2562 gettext_noop("A value of 0 uses the system default."),
2565 &tcp_keepalives_interval,
2567 NULL, assign_tcp_keepalives_interval, show_tcp_keepalives_interval
2571 {"tcp_keepalives_count", PGC_USERSET, CLIENT_CONN_OTHER,
2572 gettext_noop("Maximum number of TCP keepalive retransmits."),
2573 gettext_noop("This controls the number of consecutive keepalive retransmits that can be "
2574 "lost before a connection is considered dead. A value of 0 uses the "
2577 &tcp_keepalives_count,
2579 NULL, assign_tcp_keepalives_count, show_tcp_keepalives_count
2583 {"gin_fuzzy_search_limit", PGC_USERSET, CLIENT_CONN_OTHER,
2584 gettext_noop("Sets the maximum allowed result for exact search by GIN."),
2588 &GinFuzzySearchLimit,
2594 {"effective_cache_size", PGC_USERSET, QUERY_TUNING_COST,
2595 gettext_noop("Sets the planner's assumption about the size of the disk cache."),
2596 gettext_noop("That is, the portion of the kernel's disk cache that "
2597 "will be used for PostgreSQL data files. This is measured in disk "
2598 "pages, which are normally 8 kB each."),
2601 &effective_cache_size,
2602 DEFAULT_EFFECTIVE_CACHE_SIZE, 1, INT_MAX,
2607 /* Can't be set in postgresql.conf */
2608 {"server_version_num", PGC_INTERNAL, PRESET_OPTIONS,
2609 gettext_noop("Shows the server version as an integer."),
2611 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2613 &server_version_num,
2614 PG_VERSION_NUM, PG_VERSION_NUM, PG_VERSION_NUM,
2619 {"log_temp_files", PGC_SUSET, LOGGING_WHAT,
2620 gettext_noop("Log the use of temporary files larger than this number of kilobytes."),
2621 gettext_noop("Zero logs all files. The default is -1 (turning this feature off)."),
2630 {"track_activity_query_size", PGC_POSTMASTER, RESOURCES_MEM,
2631 gettext_noop("Sets the size reserved for pg_stat_activity.query, in bytes."),
2635 * There is no _bytes_ unit, so the user can't supply units for
2639 &pgstat_track_activity_query_size,
2645 {"gin_pending_list_limit", PGC_USERSET, CLIENT_CONN_STATEMENT,
2646 gettext_noop("Sets the maximum size of the pending list for GIN index."),
2650 &gin_pending_list_limit,
2651 4096, 64, MAX_KILOBYTES,
2655 /* End-of-list marker */
2657 {NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL, NULL
2662 static struct config_real ConfigureNamesReal[] =
2665 {"seq_page_cost", PGC_USERSET, QUERY_TUNING_COST,
2666 gettext_noop("Sets the planner's estimate of the cost of a "
2667 "sequentially fetched disk page."),
2671 DEFAULT_SEQ_PAGE_COST, 0, DBL_MAX,
2675 {"random_page_cost", PGC_USERSET, QUERY_TUNING_COST,
2676 gettext_noop("Sets the planner's estimate of the cost of a "
2677 "nonsequentially fetched disk page."),
2681 DEFAULT_RANDOM_PAGE_COST, 0, DBL_MAX,
2685 {"cpu_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
2686 gettext_noop("Sets the planner's estimate of the cost of "
2687 "processing each tuple (row)."),
2691 DEFAULT_CPU_TUPLE_COST, 0, DBL_MAX,
2695 {"cpu_index_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
2696 gettext_noop("Sets the planner's estimate of the cost of "
2697 "processing each index entry during an index scan."),
2700 &cpu_index_tuple_cost,
2701 DEFAULT_CPU_INDEX_TUPLE_COST, 0, DBL_MAX,
2705 {"cpu_operator_cost", PGC_USERSET, QUERY_TUNING_COST,
2706 gettext_noop("Sets the planner's estimate of the cost of "
2707 "processing each operator or function call."),
2711 DEFAULT_CPU_OPERATOR_COST, 0, DBL_MAX,
2716 {"cursor_tuple_fraction", PGC_USERSET, QUERY_TUNING_OTHER,
2717 gettext_noop("Sets the planner's estimate of the fraction of "
2718 "a cursor's rows that will be retrieved."),
2721 &cursor_tuple_fraction,
2722 DEFAULT_CURSOR_TUPLE_FRACTION, 0.0, 1.0,
2727 {"geqo_selection_bias", PGC_USERSET, QUERY_TUNING_GEQO,
2728 gettext_noop("GEQO: selective pressure within the population."),
2731 &Geqo_selection_bias,
2732 DEFAULT_GEQO_SELECTION_BIAS,
2733 MIN_GEQO_SELECTION_BIAS, MAX_GEQO_SELECTION_BIAS,
2737 {"geqo_seed", PGC_USERSET, QUERY_TUNING_GEQO,
2738 gettext_noop("GEQO: seed for random path selection."),
2747 {"bgwriter_lru_multiplier", PGC_SIGHUP, RESOURCES_BGWRITER,
2748 gettext_noop("Multiple of the average buffer usage to free per round."),
2751 &bgwriter_lru_multiplier,
2757 {"seed", PGC_USERSET, UNGROUPED,
2758 gettext_noop("Sets the seed for random-number generation."),
2760 GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2764 check_random_seed, assign_random_seed, show_random_seed
2768 {"autovacuum_vacuum_scale_factor", PGC_SIGHUP, AUTOVACUUM,
2769 gettext_noop("Number of tuple updates or deletes prior to vacuum as a fraction of reltuples."),
2772 &autovacuum_vac_scale,
2777 {"autovacuum_analyze_scale_factor", PGC_SIGHUP, AUTOVACUUM,
2778 gettext_noop("Number of tuple inserts, updates, or deletes prior to analyze as a fraction of reltuples."),
2781 &autovacuum_anl_scale,
2787 {"checkpoint_completion_target", PGC_SIGHUP, WAL_CHECKPOINTS,
2788 gettext_noop("Time spent flushing dirty buffers during checkpoint, as fraction of checkpoint interval."),
2791 &CheckPointCompletionTarget,
2796 /* End-of-list marker */
2798 {NULL, 0, 0, NULL, NULL}, NULL, 0.0, 0.0, 0.0, NULL, NULL, NULL
2803 static struct config_string ConfigureNamesString[] =
2806 {"archive_command", PGC_SIGHUP, WAL_ARCHIVING,
2807 gettext_noop("Sets the shell command that will be called to archive a WAL file."),
2810 &XLogArchiveCommand,
2812 NULL, NULL, show_archive_command
2816 {"client_encoding", PGC_USERSET, CLIENT_CONN_LOCALE,
2817 gettext_noop("Sets the client's character set encoding."),
2819 GUC_IS_NAME | GUC_REPORT
2821 &client_encoding_string,
2823 check_client_encoding, assign_client_encoding, NULL
2827 {"log_line_prefix", PGC_SIGHUP, LOGGING_WHAT,
2828 gettext_noop("Controls information prefixed to each log line."),
2829 gettext_noop("If blank, no prefix is used.")
2837 {"log_timezone", PGC_SIGHUP, LOGGING_WHAT,
2838 gettext_noop("Sets the time zone to use in log messages."),
2841 &log_timezone_string,
2843 check_log_timezone, assign_log_timezone, show_log_timezone
2847 {"DateStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
2848 gettext_noop("Sets the display format for date and time values."),
2849 gettext_noop("Also controls interpretation of ambiguous "
2851 GUC_LIST_INPUT | GUC_REPORT
2855 check_datestyle, assign_datestyle, NULL
2859 {"default_tablespace", PGC_USERSET, CLIENT_CONN_STATEMENT,
2860 gettext_noop("Sets the default tablespace to create tables and indexes in."),
2861 gettext_noop("An empty string selects the database's default tablespace."),
2864 &default_tablespace,
2866 check_default_tablespace, NULL, NULL
2870 {"temp_tablespaces", PGC_USERSET, CLIENT_CONN_STATEMENT,
2871 gettext_noop("Sets the tablespace(s) to use for temporary tables and sort files."),
2873 GUC_LIST_INPUT | GUC_LIST_QUOTE
2877 check_temp_tablespaces, assign_temp_tablespaces, NULL
2881 {"dynamic_library_path", PGC_SUSET, CLIENT_CONN_OTHER,
2882 gettext_noop("Sets the path for dynamically loadable modules."),
2883 gettext_noop("If a dynamically loadable module needs to be opened and "
2884 "the specified name does not have a directory component (i.e., the "
2885 "name does not contain a slash), the system will search this path for "
2886 "the specified file."),
2889 &Dynamic_library_path,
2895 {"krb_server_keyfile", PGC_SIGHUP, CONN_AUTH_SECURITY,
2896 gettext_noop("Sets the location of the Kerberos server key file."),
2900 &pg_krb_server_keyfile,
2906 {"bonjour_name", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2907 gettext_noop("Sets the Bonjour service name."),
2915 /* See main.c about why defaults for LC_foo are not all alike */
2918 {"lc_collate", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2919 gettext_noop("Shows the collation order locale."),
2921 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2929 {"lc_ctype", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2930 gettext_noop("Shows the character classification and case conversion locale."),
2932 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2940 {"lc_messages", PGC_SUSET, CLIENT_CONN_LOCALE,
2941 gettext_noop("Sets the language in which messages are displayed."),
2946 check_locale_messages, assign_locale_messages, NULL
2950 {"lc_monetary", PGC_USERSET, CLIENT_CONN_LOCALE,
2951 gettext_noop("Sets the locale for formatting monetary amounts."),
2956 check_locale_monetary, assign_locale_monetary, NULL
2960 {"lc_numeric", PGC_USERSET, CLIENT_CONN_LOCALE,
2961 gettext_noop("Sets the locale for formatting numbers."),
2966 check_locale_numeric, assign_locale_numeric, NULL
2970 {"lc_time", PGC_USERSET, CLIENT_CONN_LOCALE,
2971 gettext_noop("Sets the locale for formatting date and time values."),
2976 check_locale_time, assign_locale_time, NULL
2980 {"session_preload_libraries", PGC_SUSET, CLIENT_CONN_PRELOAD,
2981 gettext_noop("Lists shared libraries to preload into each backend."),
2983 GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
2985 &session_preload_libraries_string,
2991 {"shared_preload_libraries", PGC_POSTMASTER, CLIENT_CONN_PRELOAD,
2992 gettext_noop("Lists shared libraries to preload into server."),
2994 GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
2996 &shared_preload_libraries_string,
3002 {"local_preload_libraries", PGC_USERSET, CLIENT_CONN_PRELOAD,
3003 gettext_noop("Lists unprivileged shared libraries to preload into each backend."),
3005 GUC_LIST_INPUT | GUC_LIST_QUOTE
3007 &local_preload_libraries_string,
3013 {"search_path", PGC_USERSET, CLIENT_CONN_STATEMENT,
3014 gettext_noop("Sets the schema search order for names that are not schema-qualified."),
3016 GUC_LIST_INPUT | GUC_LIST_QUOTE
3018 &namespace_search_path,
3019 "\"$user\", public",
3020 check_search_path, assign_search_path, NULL
3024 /* Can't be set in postgresql.conf */
3025 {"server_encoding", PGC_INTERNAL, CLIENT_CONN_LOCALE,
3026 gettext_noop("Sets the server (database) character set encoding."),
3028 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
3030 &server_encoding_string,
3036 /* Can't be set in postgresql.conf */
3037 {"server_version", PGC_INTERNAL, PRESET_OPTIONS,
3038 gettext_noop("Shows the server version."),
3040 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
3042 &server_version_string,
3048 /* Not for general use --- used by SET ROLE */
3049 {"role", PGC_USERSET, UNGROUPED,
3050 gettext_noop("Sets the current role."),
3052 GUC_IS_NAME | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_NOT_WHILE_SEC_REST
3056 check_role, assign_role, show_role
3060 /* Not for general use --- used by SET SESSION AUTHORIZATION */
3061 {"session_authorization", PGC_USERSET, UNGROUPED,
3062 gettext_noop("Sets the session user name."),
3064 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
3066 &session_authorization_string,
3068 check_session_authorization, assign_session_authorization, NULL
3072 {"log_destination", PGC_SIGHUP, LOGGING_WHERE,
3073 gettext_noop("Sets the destination for server log output."),
3074 gettext_noop("Valid values are combinations of \"stderr\", "
3075 "\"syslog\", \"csvlog\", and \"eventlog\", "
3076 "depending on the platform."),
3079 &Log_destination_string,
3081 check_log_destination, assign_log_destination, NULL
3084 {"log_directory", PGC_SIGHUP, LOGGING_WHERE,
3085 gettext_noop("Sets the destination directory for log files."),
3086 gettext_noop("Can be specified as relative to the data directory "
3087 "or as absolute path."),
3092 check_canonical_path, NULL, NULL
3095 {"log_filename", PGC_SIGHUP, LOGGING_WHERE,
3096 gettext_noop("Sets the file name pattern for log files."),
3101 "postgresql-%Y-%m-%d_%H%M%S.log",
3106 {"syslog_ident", PGC_SIGHUP, LOGGING_WHERE,
3107 gettext_noop("Sets the program name used to identify PostgreSQL "
3108 "messages in syslog."),
3113 NULL, assign_syslog_ident, NULL
3117 {"event_source", PGC_POSTMASTER, LOGGING_WHERE,
3118 gettext_noop("Sets the application name used to identify "
3119 "PostgreSQL messages in the event log."),
3123 DEFAULT_EVENT_SOURCE,
3128 {"TimeZone", PGC_USERSET, CLIENT_CONN_LOCALE,
3129 gettext_noop("Sets the time zone for displaying and interpreting time stamps."),
3135 check_timezone, assign_timezone, show_timezone
3138 {"timezone_abbreviations", PGC_USERSET, CLIENT_CONN_LOCALE,
3139 gettext_noop("Selects a file of time zone abbreviations."),
3142 &timezone_abbreviations_string,
3144 check_timezone_abbreviations, assign_timezone_abbreviations, NULL
3148 {"transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
3149 gettext_noop("Sets the current transaction's isolation level."),
3151 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
3153 &XactIsoLevel_string,
3155 check_XactIsoLevel, assign_XactIsoLevel, show_XactIsoLevel
3159 {"unix_socket_group", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
3160 gettext_noop("Sets the owning group of the Unix-domain socket."),
3161 gettext_noop("The owning user of the socket is always the user "
3162 "that starts the server.")
3170 {"unix_socket_directories", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
3171 gettext_noop("Sets the directories where Unix-domain sockets will be created."),
3175 &Unix_socket_directories,
3176 #ifdef HAVE_UNIX_SOCKETS
3177 DEFAULT_PGSOCKET_DIR,
3185 {"listen_addresses", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
3186 gettext_noop("Sets the host name or IP address(es) to listen to."),
3197 * Can't be set by ALTER SYSTEM as it can lead to recursive definition
3198 * of data_directory.
3200 {"data_directory", PGC_POSTMASTER, FILE_LOCATIONS,
3201 gettext_noop("Sets the server's data directory."),
3203 GUC_SUPERUSER_ONLY | GUC_DISALLOW_IN_AUTO_FILE
3211 {"config_file", PGC_POSTMASTER, FILE_LOCATIONS,
3212 gettext_noop("Sets the server's main configuration file."),
3214 GUC_DISALLOW_IN_FILE | GUC_SUPERUSER_ONLY
3222 {"hba_file", PGC_POSTMASTER, FILE_LOCATIONS,
3223 gettext_noop("Sets the server's \"hba\" configuration file."),
3233 {"ident_file", PGC_POSTMASTER, FILE_LOCATIONS,
3234 gettext_noop("Sets the server's \"ident\" configuration file."),
3244 {"external_pid_file", PGC_POSTMASTER, FILE_LOCATIONS,
3245 gettext_noop("Writes the postmaster PID to the specified file."),
3251 check_canonical_path, NULL, NULL
3255 {"ssl_cert_file", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3256 gettext_noop("Location of the SSL server certificate file."),
3265 {"ssl_key_file", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3266 gettext_noop("Location of the SSL server private key file."),
3275 {"ssl_ca_file", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3276 gettext_noop("Location of the SSL certificate authority file."),
3285 {"ssl_crl_file", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3286 gettext_noop("Location of the SSL certificate revocation list file."),
3295 {"stats_temp_directory", PGC_SIGHUP, STATS_COLLECTOR,
3296 gettext_noop("Writes temporary statistics files to the specified directory."),
3300 &pgstat_temp_directory,
3302 check_canonical_path, assign_pgstat_temp_directory, NULL
3306 {"synchronous_standby_names", PGC_SIGHUP, REPLICATION_MASTER,
3307 gettext_noop("List of names of potential synchronous standbys."),
3311 &SyncRepStandbyNames,
3313 check_synchronous_standby_names, NULL, NULL
3317 {"default_text_search_config", PGC_USERSET, CLIENT_CONN_LOCALE,
3318 gettext_noop("Sets default text search configuration."),
3322 "pg_catalog.simple",
3323 check_TSCurrentConfig, assign_TSCurrentConfig, NULL
3327 {"ssl_ciphers", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3328 gettext_noop("Sets the list of allowed SSL ciphers."),
3334 "HIGH:MEDIUM:+3DES:!aNULL",
3342 {"ssl_ecdh_curve", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3343 gettext_noop("Sets the curve to use for ECDH."),
3357 {"application_name", PGC_USERSET, LOGGING_WHAT,
3358 gettext_noop("Sets the application name to be reported in statistics and logs."),
3360 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE
3364 check_application_name, assign_application_name, NULL
3368 {"cluster_name", PGC_POSTMASTER, LOGGING_WHAT,
3369 gettext_noop("Sets the name of the cluster which is included in the process title."),
3375 check_cluster_name, NULL, NULL
3378 /* End-of-list marker */
3380 {NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL, NULL
3385 static struct config_enum ConfigureNamesEnum[] =
3388 {"backslash_quote", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
3389 gettext_noop("Sets whether \"\\'\" is allowed in string literals."),
3393 BACKSLASH_QUOTE_SAFE_ENCODING, backslash_quote_options,
3398 {"bytea_output", PGC_USERSET, CLIENT_CONN_STATEMENT,
3399 gettext_noop("Sets the output format for bytea."),
3403 BYTEA_OUTPUT_HEX, bytea_output_options,
3408 {"client_min_messages", PGC_USERSET, LOGGING_WHEN,
3409 gettext_noop("Sets the message levels that are sent to the client."),
3410 gettext_noop("Each level includes all the levels that follow it. The later"
3411 " the level, the fewer messages are sent.")
3413 &client_min_messages,
3414 NOTICE, client_message_level_options,
3419 {"constraint_exclusion", PGC_USERSET, QUERY_TUNING_OTHER,
3420 gettext_noop("Enables the planner to use constraints to optimize queries."),
3421 gettext_noop("Table scans will be skipped if their constraints"
3422 " guarantee that no rows match the query.")
3424 &constraint_exclusion,
3425 CONSTRAINT_EXCLUSION_PARTITION, constraint_exclusion_options,
3430 {"default_transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
3431 gettext_noop("Sets the transaction isolation level of each new transaction."),
3434 &DefaultXactIsoLevel,
3435 XACT_READ_COMMITTED, isolation_level_options,
3440 {"IntervalStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
3441 gettext_noop("Sets the display format for interval values."),
3446 INTSTYLE_POSTGRES, intervalstyle_options,
3451 {"log_error_verbosity", PGC_SUSET, LOGGING_WHAT,
3452 gettext_noop("Sets the verbosity of logged messages."),
3455 &Log_error_verbosity,
3456 PGERROR_DEFAULT, log_error_verbosity_options,
3461 {"log_min_messages", PGC_SUSET, LOGGING_WHEN,
3462 gettext_noop("Sets the message levels that are logged."),
3463 gettext_noop("Each level includes all the levels that follow it. The later"
3464 " the level, the fewer messages are sent.")
3467 WARNING, server_message_level_options,
3472 {"log_min_error_statement", PGC_SUSET, LOGGING_WHEN,
3473 gettext_noop("Causes all statements generating error at or above this level to be logged."),
3474 gettext_noop("Each level includes all the levels that follow it. The later"
3475 " the level, the fewer messages are sent.")
3477 &log_min_error_statement,
3478 ERROR, server_message_level_options,
3483 {"log_statement", PGC_SUSET, LOGGING_WHAT,
3484 gettext_noop("Sets the type of statements logged."),
3488 LOGSTMT_NONE, log_statement_options,
3493 {"syslog_facility", PGC_SIGHUP, LOGGING_WHERE,
3494 gettext_noop("Sets the syslog \"facility\" to be used when syslog enabled."),
3503 syslog_facility_options,
3504 NULL, assign_syslog_facility, NULL
3508 {"session_replication_role", PGC_SUSET, CLIENT_CONN_STATEMENT,
3509 gettext_noop("Sets the session's behavior for triggers and rewrite rules."),
3512 &SessionReplicationRole,
3513 SESSION_REPLICATION_ROLE_ORIGIN, session_replication_role_options,
3514 NULL, assign_session_replication_role, NULL
3518 {"synchronous_commit", PGC_USERSET, WAL_SETTINGS,
3519 gettext_noop("Sets the current transaction's synchronization level."),
3522 &synchronous_commit,
3523 SYNCHRONOUS_COMMIT_ON, synchronous_commit_options,
3524 NULL, assign_synchronous_commit, NULL
3528 {"archive_mode", PGC_POSTMASTER, WAL_ARCHIVING,
3529 gettext_noop("Allows archiving of WAL files using archive_command."),
3533 ARCHIVE_MODE_OFF, archive_mode_options,
3538 {"trace_recovery_messages", PGC_SIGHUP, DEVELOPER_OPTIONS,
3539 gettext_noop("Enables logging of recovery-related debugging information."),
3540 gettext_noop("Each level includes all the levels that follow it. The later"
3541 " the level, the fewer messages are sent.")
3543 &trace_recovery_messages,
3546 * client_message_level_options allows too many values, really, but
3547 * it's not worth having a separate options array for this.
3549 LOG, client_message_level_options,
3554 {"track_functions", PGC_SUSET, STATS_COLLECTOR,
3555 gettext_noop("Collects function-level statistics on database activity."),
3558 &pgstat_track_functions,
3559 TRACK_FUNC_OFF, track_function_options,
3564 {"wal_level", PGC_POSTMASTER, WAL_SETTINGS,
3565 gettext_noop("Set the level of information written to the WAL."),
3569 WAL_LEVEL_MINIMAL, wal_level_options,
3574 {"dynamic_shared_memory_type", PGC_POSTMASTER, RESOURCES_MEM,
3575 gettext_noop("Selects the dynamic shared memory implementation used."),
3578 &dynamic_shared_memory_type,
3579 DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE, dynamic_shared_memory_options,
3584 {"wal_sync_method", PGC_SIGHUP, WAL_SETTINGS,
3585 gettext_noop("Selects the method used for forcing WAL updates to disk."),
3589 DEFAULT_SYNC_METHOD, sync_method_options,
3590 NULL, assign_xlog_sync_method, NULL
3594 {"xmlbinary", PGC_USERSET, CLIENT_CONN_STATEMENT,
3595 gettext_noop("Sets how binary values are to be encoded in XML."),
3599 XMLBINARY_BASE64, xmlbinary_options,
3604 {"xmloption", PGC_USERSET, CLIENT_CONN_STATEMENT,
3605 gettext_noop("Sets whether XML data in implicit parsing and serialization "
3606 "operations is to be considered as documents or content fragments."),
3610 XMLOPTION_CONTENT, xmloption_options,
3615 {"huge_pages", PGC_POSTMASTER, RESOURCES_MEM,
3616 gettext_noop("Use of huge pages on Linux."),
3620 HUGE_PAGES_TRY, huge_pages_options,
3624 /* End-of-list marker */
3626 {NULL, 0, 0, NULL, NULL}, NULL, 0, NULL, NULL, NULL, NULL
3630 /******** end of options list ********/
3634 * To allow continued support of obsolete names for GUC variables, we apply
3635 * the following mappings to any unrecognized name. Note that an old name
3636 * should be mapped to a new one only if the new variable has very similar
3637 * semantics to the old.
3639 static const char *const map_old_guc_names[] = {
3640 "sort_mem", "work_mem",
3641 "vacuum_mem", "maintenance_work_mem",
3647 * Actual lookup of variables is done through this single, sorted array.
3649 static struct config_generic **guc_variables;
3651 /* Current number of variables contained in the vector */
3652 static int num_guc_variables;
3654 /* Vector capacity */
3655 static int size_guc_variables;
3658 static bool guc_dirty; /* TRUE if need to do commit/abort work */
3660 static bool reporting_enabled; /* TRUE to enable GUC_REPORT */
3662 static int GUCNestLevel = 0; /* 1 when in main transaction */
3665 static int guc_var_compare(const void *a, const void *b);
3666 static int guc_name_compare(const char *namea, const char *nameb);
3667 static void InitializeGUCOptionsFromEnvironment(void);
3668 static void InitializeOneGUCOption(struct config_generic * gconf);
3669 static void push_old_value(struct config_generic * gconf, GucAction action);
3670 static void ReportGUCOption(struct config_generic * record);
3671 static void reapply_stacked_values(struct config_generic * variable,
3672 struct config_string * pHolder,
3674 const char *curvalue,
3675 GucContext curscontext, GucSource cursource);
3676 static void ShowGUCConfigOption(const char *name, DestReceiver *dest);
3677 static void ShowAllGUCConfig(DestReceiver *dest);
3678 static char *_ShowOption(struct config_generic * record, bool use_units);
3679 static bool validate_option_array_item(const char *name, const char *value,
3680 bool skipIfNoPermissions);
3681 static void write_auto_conf_file(int fd, const char *filename, ConfigVariable *head_p);
3682 static void replace_auto_config_value(ConfigVariable **head_p, ConfigVariable **tail_p,
3683 const char *name, const char *value);
3687 * Some infrastructure for checking malloc/strdup/realloc calls
3690 guc_malloc(int elevel, size_t size)
3694 /* Avoid unportable behavior of malloc(0) */
3697 data = malloc(size);
3700 (errcode(ERRCODE_OUT_OF_MEMORY),
3701 errmsg("out of memory")));
3706 guc_realloc(int elevel, void *old, size_t size)
3710 /* Avoid unportable behavior of realloc(NULL, 0) */
3711 if (old == NULL && size == 0)
3713 data = realloc(old, size);
3716 (errcode(ERRCODE_OUT_OF_MEMORY),
3717 errmsg("out of memory")));
3722 guc_strdup(int elevel, const char *src)
3729 (errcode(ERRCODE_OUT_OF_MEMORY),
3730 errmsg("out of memory")));
3736 * Detect whether strval is referenced anywhere in a GUC string item
3739 string_field_used(struct config_string * conf, char *strval)
3743 if (strval == *(conf->variable) ||
3744 strval == conf->reset_val ||
3745 strval == conf->boot_val)
3747 for (stack = conf->gen.stack; stack; stack = stack->prev)
3749 if (strval == stack->prior.val.stringval ||
3750 strval == stack->masked.val.stringval)
3757 * Support for assigning to a field of a string GUC item. Free the prior
3758 * value if it's not referenced anywhere else in the item (including stacked
3762 set_string_field(struct config_string * conf, char **field, char *newval)
3764 char *oldval = *field;
3766 /* Do the assignment */
3769 /* Free old value if it's not NULL and isn't referenced anymore */
3770 if (oldval && !string_field_used(conf, oldval))
3775 * Detect whether an "extra" struct is referenced anywhere in a GUC item
3778 extra_field_used(struct config_generic * gconf, void *extra)
3782 if (extra == gconf->extra)
3784 switch (gconf->vartype)
3787 if (extra == ((struct config_bool *) gconf)->reset_extra)
3791 if (extra == ((struct config_int *) gconf)->reset_extra)
3795 if (extra == ((struct config_real *) gconf)->reset_extra)
3799 if (extra == ((struct config_string *) gconf)->reset_extra)
3803 if (extra == ((struct config_enum *) gconf)->reset_extra)
3807 for (stack = gconf->stack; stack; stack = stack->prev)
3809 if (extra == stack->prior.extra ||
3810 extra == stack->masked.extra)
3818 * Support for assigning to an "extra" field of a GUC item. Free the prior
3819 * value if it's not referenced anywhere else in the item (including stacked
3823 set_extra_field(struct config_generic * gconf, void **field, void *newval)
3825 void *oldval = *field;
3827 /* Do the assignment */
3830 /* Free old value if it's not NULL and isn't referenced anymore */
3831 if (oldval && !extra_field_used(gconf, oldval))
3836 * Support for copying a variable's active value into a stack entry.
3837 * The "extra" field associated with the active value is copied, too.
3839 * NB: be sure stringval and extra fields of a new stack entry are
3840 * initialized to NULL before this is used, else we'll try to free() them.
3843 set_stack_value(struct config_generic * gconf, config_var_value *val)
3845 switch (gconf->vartype)
3849 *((struct config_bool *) gconf)->variable;
3853 *((struct config_int *) gconf)->variable;
3857 *((struct config_real *) gconf)->variable;
3860 set_string_field((struct config_string *) gconf,
3861 &(val->val.stringval),
3862 *((struct config_string *) gconf)->variable);
3866 *((struct config_enum *) gconf)->variable;
3869 set_extra_field(gconf, &(val->extra), gconf->extra);
3873 * Support for discarding a no-longer-needed value in a stack entry.
3874 * The "extra" field associated with the stack entry is cleared, too.
3877 discard_stack_value(struct config_generic * gconf, config_var_value *val)
3879 switch (gconf->vartype)
3885 /* no need to do anything */
3888 set_string_field((struct config_string *) gconf,
3889 &(val->val.stringval),
3893 set_extra_field(gconf, &(val->extra), NULL);
3898 * Fetch the sorted array pointer (exported for help_config.c's use ONLY)
3900 struct config_generic **
3901 get_guc_variables(void)
3903 return guc_variables;
3908 * Build the sorted array. This is split out so that it could be
3909 * re-executed after startup (eg, we could allow loadable modules to
3910 * add vars, and then we'd need to re-sort).
3913 build_guc_variables(void)
3917 struct config_generic **guc_vars;
3920 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
3922 struct config_bool *conf = &ConfigureNamesBool[i];
3924 /* Rather than requiring vartype to be filled in by hand, do this: */
3925 conf->gen.vartype = PGC_BOOL;
3929 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
3931 struct config_int *conf = &ConfigureNamesInt[i];
3933 conf->gen.vartype = PGC_INT;
3937 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
3939 struct config_real *conf = &ConfigureNamesReal[i];
3941 conf->gen.vartype = PGC_REAL;
3945 for (i = 0; ConfigureNamesString[i].gen.name; i++)
3947 struct config_string *conf = &ConfigureNamesString[i];
3949 conf->gen.vartype = PGC_STRING;
3953 for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
3955 struct config_enum *conf = &ConfigureNamesEnum[i];
3957 conf->gen.vartype = PGC_ENUM;
3962 * Create table with 20% slack
3964 size_vars = num_vars + num_vars / 4;
3966 guc_vars = (struct config_generic **)
3967 guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
3971 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
3972 guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
3974 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
3975 guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
3977 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
3978 guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
3980 for (i = 0; ConfigureNamesString[i].gen.name; i++)
3981 guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
3983 for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
3984 guc_vars[num_vars++] = &ConfigureNamesEnum[i].gen;
3987 free(guc_variables);
3988 guc_variables = guc_vars;
3989 num_guc_variables = num_vars;
3990 size_guc_variables = size_vars;
3991 qsort((void *) guc_variables, num_guc_variables,
3992 sizeof(struct config_generic *), guc_var_compare);
3996 * Add a new GUC variable to the list of known variables. The
3997 * list is expanded if needed.
4000 add_guc_variable(struct config_generic * var, int elevel)
4002 if (num_guc_variables + 1 >= size_guc_variables)
4005 * Increase the vector by 25%
4007 int size_vars = size_guc_variables + size_guc_variables / 4;
4008 struct config_generic **guc_vars;
4013 guc_vars = (struct config_generic **)
4014 guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
4018 guc_vars = (struct config_generic **)
4019 guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
4022 if (guc_vars == NULL)
4023 return false; /* out of memory */
4025 guc_variables = guc_vars;
4026 size_guc_variables = size_vars;
4028 guc_variables[num_guc_variables++] = var;
4029 qsort((void *) guc_variables, num_guc_variables,
4030 sizeof(struct config_generic *), guc_var_compare);
4035 * Create and add a placeholder variable for a custom variable name.
4037 static struct config_generic *
4038 add_placeholder_variable(const char *name, int elevel)
4040 size_t sz = sizeof(struct config_string) + sizeof(char *);
4041 struct config_string *var;
4042 struct config_generic *gen;
4044 var = (struct config_string *) guc_malloc(elevel, sz);
4050 gen->name = guc_strdup(elevel, name);
4051 if (gen->name == NULL)
4057 gen->context = PGC_USERSET;
4058 gen->group = CUSTOM_OPTIONS;
4059 gen->short_desc = "GUC placeholder variable";
4060 gen->flags = GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_CUSTOM_PLACEHOLDER;
4061 gen->vartype = PGC_STRING;
4064 * The char* is allocated at the end of the struct since we have no
4065 * 'static' place to point to. Note that the current value, as well as
4066 * the boot and reset values, start out NULL.
4068 var->variable = (char **) (var + 1);
4070 if (!add_guc_variable((struct config_generic *) var, elevel))
4072 free((void *) gen->name);
4081 * Look up option NAME. If it exists, return a pointer to its record,
4082 * else return NULL. If create_placeholders is TRUE, we'll create a
4083 * placeholder record for a valid-looking custom variable name.
4085 static struct config_generic *
4086 find_option(const char *name, bool create_placeholders, int elevel)
4088 const char **key = &name;
4089 struct config_generic **res;
4095 * By equating const char ** with struct config_generic *, we are assuming
4096 * the name field is first in config_generic.
4098 res = (struct config_generic **) bsearch((void *) &key,
4099 (void *) guc_variables,
4101 sizeof(struct config_generic *),
4107 * See if the name is an obsolete name for a variable. We assume that the
4108 * set of supported old names is short enough that a brute-force search is
4111 for (i = 0; map_old_guc_names[i] != NULL; i += 2)
4113 if (guc_name_compare(name, map_old_guc_names[i]) == 0)
4114 return find_option(map_old_guc_names[i + 1], false, elevel);
4117 if (create_placeholders)
4120 * Check if the name is qualified, and if so, add a placeholder.
4122 if (strchr(name, GUC_QUALIFIER_SEPARATOR) != NULL)
4123 return add_placeholder_variable(name, elevel);
4132 * comparator for qsorting and bsearching guc_variables array
4135 guc_var_compare(const void *a, const void *b)
4137 const struct config_generic *confa = *(struct config_generic * const *) a;
4138 const struct config_generic *confb = *(struct config_generic * const *) b;
4140 return guc_name_compare(confa->name, confb->name);
4144 * the bare comparison function for GUC names
4147 guc_name_compare(const char *namea, const char *nameb)
4150 * The temptation to use strcasecmp() here must be resisted, because the
4151 * array ordering has to remain stable across setlocale() calls. So, build
4152 * our own with a simple ASCII-only downcasing.
4154 while (*namea && *nameb)
4156 char cha = *namea++;
4157 char chb = *nameb++;
4159 if (cha >= 'A' && cha <= 'Z')
4161 if (chb >= 'A' && chb <= 'Z')
4167 return 1; /* a is longer */
4169 return -1; /* b is longer */
4175 * Initialize GUC options during program startup.
4177 * Note that we cannot read the config file yet, since we have not yet
4178 * processed command-line switches.
4181 InitializeGUCOptions(void)
4186 * Before log_line_prefix could possibly receive a nonempty setting, make
4187 * sure that timezone processing is minimally alive (see elog.c).
4189 pg_timezone_initialize();
4192 * Build sorted array of all GUC variables.
4194 build_guc_variables();
4197 * Load all variables with their compiled-in defaults, and initialize
4198 * status fields as needed.
4200 for (i = 0; i < num_guc_variables; i++)
4202 InitializeOneGUCOption(guc_variables[i]);
4207 reporting_enabled = false;
4210 * Prevent any attempt to override the transaction modes from
4211 * non-interactive sources.
4213 SetConfigOption("transaction_isolation", "default",
4214 PGC_POSTMASTER, PGC_S_OVERRIDE);
4215 SetConfigOption("transaction_read_only", "no",
4216 PGC_POSTMASTER, PGC_S_OVERRIDE);
4217 SetConfigOption("transaction_deferrable", "no",
4218 PGC_POSTMASTER, PGC_S_OVERRIDE);
4221 * For historical reasons, some GUC parameters can receive defaults from
4222 * environment variables. Process those settings.
4224 InitializeGUCOptionsFromEnvironment();
4228 * Assign any GUC values that can come from the server's environment.
4230 * This is called from InitializeGUCOptions, and also from ProcessConfigFile
4231 * to deal with the possibility that a setting has been removed from
4232 * postgresql.conf and should now get a value from the environment.
4233 * (The latter is a kludge that should probably go away someday; if so,
4234 * fold this back into InitializeGUCOptions.)
4237 InitializeGUCOptionsFromEnvironment(void)
4242 env = getenv("PGPORT");
4244 SetConfigOption("port", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
4246 env = getenv("PGDATESTYLE");
4248 SetConfigOption("datestyle", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
4250 env = getenv("PGCLIENTENCODING");
4252 SetConfigOption("client_encoding", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
4255 * rlimit isn't exactly an "environment variable", but it behaves about
4256 * the same. If we can identify the platform stack depth rlimit, increase
4257 * default stack depth setting up to whatever is safe (but at most 2MB).
4259 stack_rlimit = get_stack_depth_rlimit();
4260 if (stack_rlimit > 0)
4262 long new_limit = (stack_rlimit - STACK_DEPTH_SLOP) / 1024L;
4264 if (new_limit > 100)
4268 new_limit = Min(new_limit, 2048);
4269 sprintf(limbuf, "%ld", new_limit);
4270 SetConfigOption("max_stack_depth", limbuf,
4271 PGC_POSTMASTER, PGC_S_ENV_VAR);
4277 * Initialize one GUC option variable to its compiled-in default.
4279 * Note: the reason for calling check_hooks is not that we think the boot_val
4280 * might fail, but that the hooks might wish to compute an "extra" struct.
4283 InitializeOneGUCOption(struct config_generic * gconf)
4286 gconf->source = PGC_S_DEFAULT;
4287 gconf->reset_source = PGC_S_DEFAULT;
4288 gconf->scontext = PGC_INTERNAL;
4289 gconf->reset_scontext = PGC_INTERNAL;
4290 gconf->stack = NULL;
4291 gconf->extra = NULL;
4292 gconf->sourcefile = NULL;
4293 gconf->sourceline = 0;
4295 switch (gconf->vartype)
4299 struct config_bool *conf = (struct config_bool *) gconf;
4300 bool newval = conf->boot_val;
4303 if (!call_bool_check_hook(conf, &newval, &extra,
4304 PGC_S_DEFAULT, LOG))
4305 elog(FATAL, "failed to initialize %s to %d",
4306 conf->gen.name, (int) newval);
4307 if (conf->assign_hook)
4308 (*conf->assign_hook) (newval, extra);
4309 *conf->variable = conf->reset_val = newval;
4310 conf->gen.extra = conf->reset_extra = extra;
4315 struct config_int *conf = (struct config_int *) gconf;
4316 int newval = conf->boot_val;
4319 Assert(newval >= conf->min);
4320 Assert(newval <= conf->max);
4321 if (!call_int_check_hook(conf, &newval, &extra,
4322 PGC_S_DEFAULT, LOG))
4323 elog(FATAL, "failed to initialize %s to %d",
4324 conf->gen.name, newval);
4325 if (conf->assign_hook)
4326 (*conf->assign_hook) (newval, extra);
4327 *conf->variable = conf->reset_val = newval;
4328 conf->gen.extra = conf->reset_extra = extra;
4333 struct config_real *conf = (struct config_real *) gconf;
4334 double newval = conf->boot_val;
4337 Assert(newval >= conf->min);
4338 Assert(newval <= conf->max);
4339 if (!call_real_check_hook(conf, &newval, &extra,
4340 PGC_S_DEFAULT, LOG))
4341 elog(FATAL, "failed to initialize %s to %g",
4342 conf->gen.name, newval);
4343 if (conf->assign_hook)
4344 (*conf->assign_hook) (newval, extra);
4345 *conf->variable = conf->reset_val = newval;
4346 conf->gen.extra = conf->reset_extra = extra;
4351 struct config_string *conf = (struct config_string *) gconf;
4355 /* non-NULL boot_val must always get strdup'd */
4356 if (conf->boot_val != NULL)
4357 newval = guc_strdup(FATAL, conf->boot_val);
4361 if (!call_string_check_hook(conf, &newval, &extra,
4362 PGC_S_DEFAULT, LOG))
4363 elog(FATAL, "failed to initialize %s to \"%s\"",
4364 conf->gen.name, newval ? newval : "");
4365 if (conf->assign_hook)
4366 (*conf->assign_hook) (newval, extra);
4367 *conf->variable = conf->reset_val = newval;
4368 conf->gen.extra = conf->reset_extra = extra;
4373 struct config_enum *conf = (struct config_enum *) gconf;
4374 int newval = conf->boot_val;
4377 if (!call_enum_check_hook(conf, &newval, &extra,
4378 PGC_S_DEFAULT, LOG))
4379 elog(FATAL, "failed to initialize %s to %d",
4380 conf->gen.name, newval);
4381 if (conf->assign_hook)
4382 (*conf->assign_hook) (newval, extra);
4383 *conf->variable = conf->reset_val = newval;
4384 conf->gen.extra = conf->reset_extra = extra;
4392 * Select the configuration files and data directory to be used, and
4393 * do the initial read of postgresql.conf.
4395 * This is called after processing command-line switches.
4396 * userDoption is the -D switch value if any (NULL if unspecified).
4397 * progname is just for use in error messages.
4399 * Returns true on success; on failure, prints a suitable error message
4400 * to stderr and returns false.
4403 SelectConfigFiles(const char *userDoption, const char *progname)
4407 struct stat stat_buf;
4409 /* configdir is -D option, or $PGDATA if no -D */
4411 configdir = make_absolute_path(userDoption);
4413 configdir = make_absolute_path(getenv("PGDATA"));
4416 * Find the configuration file: if config_file was specified on the
4417 * command line, use it, else use configdir/postgresql.conf. In any case
4418 * ensure the result is an absolute path, so that it will be interpreted
4419 * the same way by future backends.
4422 fname = make_absolute_path(ConfigFileName);
4425 fname = guc_malloc(FATAL,
4426 strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
4427 sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
4431 write_stderr("%s does not know where to find the server configuration file.\n"
4432 "You must specify the --config-file or -D invocation "
4433 "option or set the PGDATA environment variable.\n",
4439 * Set the ConfigFileName GUC variable to its final value, ensuring that
4440 * it can't be overridden later.
4442 SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4446 * Now read the config file for the first time.
4448 if (stat(ConfigFileName, &stat_buf) != 0)
4450 write_stderr("%s cannot access the server configuration file \"%s\": %s\n",
4451 progname, ConfigFileName, strerror(errno));
4457 * Read the configuration file for the first time. This time only the
4458 * data_directory parameter is picked up to determine the data directory,
4459 * so that we can read the PG_AUTOCONF_FILENAME file next time.
4461 ProcessConfigFile(PGC_POSTMASTER);
4464 * If the data_directory GUC variable has been set, use that as DataDir;
4465 * otherwise use configdir if set; else punt.
4467 * Note: SetDataDir will copy and absolute-ize its argument, so we don't
4471 SetDataDir(data_directory);
4473 SetDataDir(configdir);
4476 write_stderr("%s does not know where to find the database system data.\n"
4477 "This can be specified as \"data_directory\" in \"%s\", "
4478 "or by the -D invocation option, or by the "
4479 "PGDATA environment variable.\n",
4480 progname, ConfigFileName);
4485 * Reflect the final DataDir value back into the data_directory GUC var.
4486 * (If you are wondering why we don't just make them a single variable,
4487 * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
4488 * child backends specially. XXX is that still true? Given that we now
4489 * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
4490 * DataDir in advance.)
4492 SetConfigOption("data_directory", DataDir, PGC_POSTMASTER, PGC_S_OVERRIDE);
4495 * Now read the config file a second time, allowing any settings in the
4496 * PG_AUTOCONF_FILENAME file to take effect. (This is pretty ugly, but
4497 * since we have to determine the DataDir before we can find the autoconf
4498 * file, the alternatives seem worse.)
4500 ProcessConfigFile(PGC_POSTMASTER);
4503 * If timezone_abbreviations wasn't set in the configuration file, install
4504 * the default value. We do it this way because we can't safely install a
4505 * "real" value until my_exec_path is set, which may not have happened
4506 * when InitializeGUCOptions runs, so the bootstrap default value cannot
4507 * be the real desired default.
4509 pg_timezone_abbrev_initialize();
4512 * Figure out where pg_hba.conf is, and make sure the path is absolute.
4515 fname = make_absolute_path(HbaFileName);
4518 fname = guc_malloc(FATAL,
4519 strlen(configdir) + strlen(HBA_FILENAME) + 2);
4520 sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
4524 write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
4525 "This can be specified as \"hba_file\" in \"%s\", "
4526 "or by the -D invocation option, or by the "
4527 "PGDATA environment variable.\n",
4528 progname, ConfigFileName);
4531 SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4535 * Likewise for pg_ident.conf.
4538 fname = make_absolute_path(IdentFileName);
4541 fname = guc_malloc(FATAL,
4542 strlen(configdir) + strlen(IDENT_FILENAME) + 2);
4543 sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
4547 write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
4548 "This can be specified as \"ident_file\" in \"%s\", "
4549 "or by the -D invocation option, or by the "
4550 "PGDATA environment variable.\n",
4551 progname, ConfigFileName);
4554 SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4564 * Reset all options to their saved default values (implements RESET ALL)
4567 ResetAllOptions(void)
4571 for (i = 0; i < num_guc_variables; i++)
4573 struct config_generic *gconf = guc_variables[i];
4575 /* Don't reset non-SET-able values */
4576 if (gconf->context != PGC_SUSET &&
4577 gconf->context != PGC_USERSET)
4579 /* Don't reset if special exclusion from RESET ALL */
4580 if (gconf->flags & GUC_NO_RESET_ALL)
4582 /* No need to reset if wasn't SET */
4583 if (gconf->source <= PGC_S_OVERRIDE)
4586 /* Save old value to support transaction abort */
4587 push_old_value(gconf, GUC_ACTION_SET);
4589 switch (gconf->vartype)
4593 struct config_bool *conf = (struct config_bool *) gconf;
4595 if (conf->assign_hook)
4596 (*conf->assign_hook) (conf->reset_val,
4598 *conf->variable = conf->reset_val;
4599 set_extra_field(&conf->gen, &conf->gen.extra,
4605 struct config_int *conf = (struct config_int *) gconf;
4607 if (conf->assign_hook)
4608 (*conf->assign_hook) (conf->reset_val,
4610 *conf->variable = conf->reset_val;
4611 set_extra_field(&conf->gen, &conf->gen.extra,
4617 struct config_real *conf = (struct config_real *) gconf;
4619 if (conf->assign_hook)
4620 (*conf->assign_hook) (conf->reset_val,
4622 *conf->variable = conf->reset_val;
4623 set_extra_field(&conf->gen, &conf->gen.extra,
4629 struct config_string *conf = (struct config_string *) gconf;
4631 if (conf->assign_hook)
4632 (*conf->assign_hook) (conf->reset_val,
4634 set_string_field(conf, conf->variable, conf->reset_val);
4635 set_extra_field(&conf->gen, &conf->gen.extra,
4641 struct config_enum *conf = (struct config_enum *) gconf;
4643 if (conf->assign_hook)
4644 (*conf->assign_hook) (conf->reset_val,
4646 *conf->variable = conf->reset_val;
4647 set_extra_field(&conf->gen, &conf->gen.extra,
4653 gconf->source = gconf->reset_source;
4654 gconf->scontext = gconf->reset_scontext;
4656 if (gconf->flags & GUC_REPORT)
4657 ReportGUCOption(gconf);
4664 * Push previous state during transactional assignment to a GUC variable.
4667 push_old_value(struct config_generic * gconf, GucAction action)
4671 /* If we're not inside a nest level, do nothing */
4672 if (GUCNestLevel == 0)
4675 /* Do we already have a stack entry of the current nest level? */
4676 stack = gconf->stack;
4677 if (stack && stack->nest_level >= GUCNestLevel)
4679 /* Yes, so adjust its state if necessary */
4680 Assert(stack->nest_level == GUCNestLevel);
4683 case GUC_ACTION_SET:
4684 /* SET overrides any prior action at same nest level */
4685 if (stack->state == GUC_SET_LOCAL)
4687 /* must discard old masked value */
4688 discard_stack_value(gconf, &stack->masked);
4690 stack->state = GUC_SET;
4692 case GUC_ACTION_LOCAL:
4693 if (stack->state == GUC_SET)
4695 /* SET followed by SET LOCAL, remember SET's value */
4696 stack->masked_scontext = gconf->scontext;
4697 set_stack_value(gconf, &stack->masked);
4698 stack->state = GUC_SET_LOCAL;
4700 /* in all other cases, no change to stack entry */
4702 case GUC_ACTION_SAVE:
4703 /* Could only have a prior SAVE of same variable */
4704 Assert(stack->state == GUC_SAVE);
4707 Assert(guc_dirty); /* must be set already */
4712 * Push a new stack entry
4714 * We keep all the stack entries in TopTransactionContext for simplicity.
4716 stack = (GucStack *) MemoryContextAllocZero(TopTransactionContext,
4719 stack->prev = gconf->stack;
4720 stack->nest_level = GUCNestLevel;
4723 case GUC_ACTION_SET:
4724 stack->state = GUC_SET;
4726 case GUC_ACTION_LOCAL:
4727 stack->state = GUC_LOCAL;
4729 case GUC_ACTION_SAVE:
4730 stack->state = GUC_SAVE;
4733 stack->source = gconf->source;
4734 stack->scontext = gconf->scontext;
4735 set_stack_value(gconf, &stack->prior);
4737 gconf->stack = stack;
4739 /* Ensure we remember to pop at end of xact */
4745 * Do GUC processing at main transaction start.
4751 * The nest level should be 0 between transactions; if it isn't, somebody
4752 * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
4753 * throw a warning but make no other effort to clean up.
4755 if (GUCNestLevel != 0)
4756 elog(WARNING, "GUC nest level = %d at transaction start",
4762 * Enter a new nesting level for GUC values. This is called at subtransaction
4763 * start, and when entering a function that has proconfig settings, and in
4764 * some other places where we want to set GUC variables transiently.
4765 * NOTE we must not risk error here, else subtransaction start will be unhappy.
4768 NewGUCNestLevel(void)
4770 return ++GUCNestLevel;
4774 * Do GUC processing at transaction or subtransaction commit or abort, or
4775 * when exiting a function that has proconfig settings, or when undoing a
4776 * transient assignment to some GUC variables. (The name is thus a bit of
4777 * a misnomer; perhaps it should be ExitGUCNestLevel or some such.)
4778 * During abort, we discard all GUC settings that were applied at nesting
4779 * levels >= nestLevel. nestLevel == 1 corresponds to the main transaction.
4782 AtEOXact_GUC(bool isCommit, int nestLevel)
4788 * Note: it's possible to get here with GUCNestLevel == nestLevel-1 during
4789 * abort, if there is a failure during transaction start before
4790 * AtStart_GUC is called.
4792 Assert(nestLevel > 0 &&
4793 (nestLevel <= GUCNestLevel ||
4794 (nestLevel == GUCNestLevel + 1 && !isCommit)));
4796 /* Quick exit if nothing's changed in this transaction */
4799 GUCNestLevel = nestLevel - 1;
4803 still_dirty = false;
4804 for (i = 0; i < num_guc_variables; i++)
4806 struct config_generic *gconf = guc_variables[i];
4810 * Process and pop each stack entry within the nest level. To simplify
4811 * fmgr_security_definer() and other places that use GUC_ACTION_SAVE,
4812 * we allow failure exit from code that uses a local nest level to be
4813 * recovered at the surrounding transaction or subtransaction abort;
4814 * so there could be more than one stack entry to pop.
4816 while ((stack = gconf->stack) != NULL &&
4817 stack->nest_level >= nestLevel)
4819 GucStack *prev = stack->prev;
4820 bool restorePrior = false;
4821 bool restoreMasked = false;
4825 * In this next bit, if we don't set either restorePrior or
4826 * restoreMasked, we must "discard" any unwanted fields of the
4827 * stack entries to avoid leaking memory. If we do set one of
4828 * those flags, unused fields will be cleaned up after restoring.
4830 if (!isCommit) /* if abort, always restore prior value */
4831 restorePrior = true;
4832 else if (stack->state == GUC_SAVE)
4833 restorePrior = true;
4834 else if (stack->nest_level == 1)
4836 /* transaction commit */
4837 if (stack->state == GUC_SET_LOCAL)
4838 restoreMasked = true;
4839 else if (stack->state == GUC_SET)
4841 /* we keep the current active value */
4842 discard_stack_value(gconf, &stack->prior);
4844 else /* must be GUC_LOCAL */
4845 restorePrior = true;
4847 else if (prev == NULL ||
4848 prev->nest_level < stack->nest_level - 1)
4850 /* decrement entry's level and do not pop it */
4851 stack->nest_level--;
4857 * We have to merge this stack entry into prev. See README for
4858 * discussion of this bit.
4860 switch (stack->state)
4863 Assert(false); /* can't get here */
4866 /* next level always becomes SET */
4867 discard_stack_value(gconf, &stack->prior);
4868 if (prev->state == GUC_SET_LOCAL)
4869 discard_stack_value(gconf, &prev->masked);
4870 prev->state = GUC_SET;
4874 if (prev->state == GUC_SET)
4876 /* LOCAL migrates down */
4877 prev->masked_scontext = stack->scontext;
4878 prev->masked = stack->prior;
4879 prev->state = GUC_SET_LOCAL;
4883 /* else just forget this stack level */
4884 discard_stack_value(gconf, &stack->prior);
4889 /* prior state at this level no longer wanted */
4890 discard_stack_value(gconf, &stack->prior);
4891 /* copy down the masked state */
4892 prev->masked_scontext = stack->masked_scontext;
4893 if (prev->state == GUC_SET_LOCAL)
4894 discard_stack_value(gconf, &prev->masked);
4895 prev->masked = stack->masked;
4896 prev->state = GUC_SET_LOCAL;
4903 if (restorePrior || restoreMasked)
4905 /* Perform appropriate restoration of the stacked value */
4906 config_var_value newvalue;
4907 GucSource newsource;
4908 GucContext newscontext;
4912 newvalue = stack->masked;
4913 newsource = PGC_S_SESSION;
4914 newscontext = stack->masked_scontext;
4918 newvalue = stack->prior;
4919 newsource = stack->source;
4920 newscontext = stack->scontext;
4923 switch (gconf->vartype)
4927 struct config_bool *conf = (struct config_bool *) gconf;
4928 bool newval = newvalue.val.boolval;
4929 void *newextra = newvalue.extra;
4931 if (*conf->variable != newval ||
4932 conf->gen.extra != newextra)
4934 if (conf->assign_hook)
4935 (*conf->assign_hook) (newval, newextra);
4936 *conf->variable = newval;
4937 set_extra_field(&conf->gen, &conf->gen.extra,
4945 struct config_int *conf = (struct config_int *) gconf;
4946 int newval = newvalue.val.intval;
4947 void *newextra = newvalue.extra;
4949 if (*conf->variable != newval ||
4950 conf->gen.extra != newextra)
4952 if (conf->assign_hook)
4953 (*conf->assign_hook) (newval, newextra);
4954 *conf->variable = newval;
4955 set_extra_field(&conf->gen, &conf->gen.extra,
4963 struct config_real *conf = (struct config_real *) gconf;
4964 double newval = newvalue.val.realval;
4965 void *newextra = newvalue.extra;
4967 if (*conf->variable != newval ||
4968 conf->gen.extra != newextra)
4970 if (conf->assign_hook)
4971 (*conf->assign_hook) (newval, newextra);
4972 *conf->variable = newval;
4973 set_extra_field(&conf->gen, &conf->gen.extra,
4981 struct config_string *conf = (struct config_string *) gconf;
4982 char *newval = newvalue.val.stringval;
4983 void *newextra = newvalue.extra;
4985 if (*conf->variable != newval ||
4986 conf->gen.extra != newextra)
4988 if (conf->assign_hook)
4989 (*conf->assign_hook) (newval, newextra);
4990 set_string_field(conf, conf->variable, newval);
4991 set_extra_field(&conf->gen, &conf->gen.extra,
4997 * Release stacked values if not used anymore. We
4998 * could use discard_stack_value() here, but since
4999 * we have type-specific code anyway, might as
5002 set_string_field(conf, &stack->prior.val.stringval, NULL);
5003 set_string_field(conf, &stack->masked.val.stringval, NULL);
5008 struct config_enum *conf = (struct config_enum *) gconf;
5009 int newval = newvalue.val.enumval;
5010 void *newextra = newvalue.extra;
5012 if (*conf->variable != newval ||
5013 conf->gen.extra != newextra)
5015 if (conf->assign_hook)
5016 (*conf->assign_hook) (newval, newextra);
5017 *conf->variable = newval;
5018 set_extra_field(&conf->gen, &conf->gen.extra,
5027 * Release stacked extra values if not used anymore.
5029 set_extra_field(gconf, &(stack->prior.extra), NULL);
5030 set_extra_field(gconf, &(stack->masked.extra), NULL);
5032 /* And restore source information */
5033 gconf->source = newsource;
5034 gconf->scontext = newscontext;
5037 /* Finish popping the state stack */
5038 gconf->stack = prev;
5041 /* Report new value if we changed it */
5042 if (changed && (gconf->flags & GUC_REPORT))
5043 ReportGUCOption(gconf);
5044 } /* end of stack-popping loop */
5050 /* If there are no remaining stack entries, we can reset guc_dirty */
5051 guc_dirty = still_dirty;
5053 /* Update nesting level */
5054 GUCNestLevel = nestLevel - 1;
5059 * Start up automatic reporting of changes to variables marked GUC_REPORT.
5060 * This is executed at completion of backend startup.
5063 BeginReportingGUCOptions(void)
5068 * Don't do anything unless talking to an interactive frontend of protocol
5071 if (whereToSendOutput != DestRemote ||
5072 PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
5075 reporting_enabled = true;
5077 /* Transmit initial values of interesting variables */
5078 for (i = 0; i < num_guc_variables; i++)
5080 struct config_generic *conf = guc_variables[i];
5082 if (conf->flags & GUC_REPORT)
5083 ReportGUCOption(conf);
5088 * ReportGUCOption: if appropriate, transmit option value to frontend
5091 ReportGUCOption(struct config_generic * record)
5093 if (reporting_enabled && (record->flags & GUC_REPORT))
5095 char *val = _ShowOption(record, false);
5096 StringInfoData msgbuf;
5098 pq_beginmessage(&msgbuf, 'S');
5099 pq_sendstring(&msgbuf, record->name);
5100 pq_sendstring(&msgbuf, val);
5101 pq_endmessage(&msgbuf);
5108 * Convert a value from one of the human-friendly units ("kB", "min" etc.)
5109 * to the given base unit. 'value' and 'unit' are the input value and unit
5110 * to convert from. The converted value is stored in *base_value.
5112 * Returns true on success, false if the input unit is not recognized.
5115 convert_to_base_unit(int64 value, const char *unit,
5116 int base_unit, int64 *base_value)
5118 const unit_conversion *table;
5121 if (base_unit & GUC_UNIT_MEMORY)
5122 table = memory_unit_conversion_table;
5124 table = time_unit_conversion_table;
5126 for (i = 0; *table[i].unit; i++)
5128 if (base_unit == table[i].base_unit &&
5129 strcmp(unit, table[i].unit) == 0)
5131 if (table[i].multiplier < 0)
5132 *base_value = value / (-table[i].multiplier);
5134 *base_value = value * table[i].multiplier;
5142 * Convert a value in some base unit to a human-friendly unit. The output
5143 * unit is chosen so that it's the greatest unit that can represent the value
5144 * without loss. For example, if the base unit is GUC_UNIT_KB, 1024 is
5145 * converted to 1 MB, but 1025 is represented as 1025 kB.
5148 convert_from_base_unit(int64 base_value, int base_unit,
5149 int64 *value, const char **unit)
5151 const unit_conversion *table;
5156 if (base_unit & GUC_UNIT_MEMORY)
5157 table = memory_unit_conversion_table;
5159 table = time_unit_conversion_table;
5161 for (i = 0; *table[i].unit; i++)
5163 if (base_unit == table[i].base_unit)
5166 * Accept the first conversion that divides the value evenly. We
5167 * assume that the conversions for each base unit are ordered from
5168 * greatest unit to the smallest!
5170 if (table[i].multiplier < 0)
5172 *value = base_value * (-table[i].multiplier);
5173 *unit = table[i].unit;
5176 else if (base_value % table[i].multiplier == 0)
5178 *value = base_value / table[i].multiplier;
5179 *unit = table[i].unit;
5185 Assert(*unit != NULL);
5190 * Try to parse value as an integer. The accepted formats are the
5191 * usual decimal, octal, or hexadecimal formats, optionally followed by
5192 * a unit name if "flags" indicates a unit is allowed.
5194 * If the string parses okay, return true, else false.
5195 * If okay and result is not NULL, return the value in *result.
5196 * If not okay and hintmsg is not NULL, *hintmsg is set to a suitable
5197 * HINT message, or NULL if no hint provided.
5200 parse_int(const char *value, int *result, int flags, const char **hintmsg)
5205 /* To suppress compiler warnings, always set output params */
5211 /* We assume here that int64 is at least as wide as long */
5213 val = strtol(value, &endptr, 0);
5215 if (endptr == value)
5216 return false; /* no HINT for integer syntax error */
5218 if (errno == ERANGE || val != (int64) ((int32) val))
5221 *hintmsg = gettext_noop("Value exceeds integer range.");
5225 /* allow whitespace between integer and unit */
5226 while (isspace((unsigned char) *endptr))
5229 /* Handle possible unit */
5230 if (*endptr != '\0')
5232 char unit[MAX_UNIT_LEN + 1];
5234 bool converted = false;
5236 if ((flags & GUC_UNIT) == 0)
5237 return false; /* this setting does not accept a unit */
5240 while (*endptr != '\0' && !isspace((unsigned char) *endptr) &&
5241 unitlen < MAX_UNIT_LEN)
5242 unit[unitlen++] = *(endptr++);
5243 unit[unitlen] = '\0';
5244 /* allow whitespace after unit */
5245 while (isspace((unsigned char) *endptr))
5248 if (*endptr == '\0')
5249 converted = convert_to_base_unit(val, unit, (flags & GUC_UNIT),
5253 /* invalid unit, or garbage after the unit; set hint and fail. */
5256 if (flags & GUC_UNIT_MEMORY)
5257 *hintmsg = memory_units_hint;
5259 *hintmsg = time_units_hint;
5264 /* Check for overflow due to units conversion */
5265 if (val != (int64) ((int32) val))
5268 *hintmsg = gettext_noop("Value exceeds integer range.");
5274 *result = (int) val;
5281 * Try to parse value as a floating point number in the usual format.
5282 * If the string parses okay, return true, else false.
5283 * If okay and result is not NULL, return the value in *result.
5286 parse_real(const char *value, double *result)
5292 *result = 0; /* suppress compiler warning */
5295 val = strtod(value, &endptr);
5296 if (endptr == value || errno == ERANGE)
5299 /* allow whitespace after number */
5300 while (isspace((unsigned char) *endptr))
5302 if (*endptr != '\0')
5312 * Lookup the name for an enum option with the selected value.
5313 * Should only ever be called with known-valid values, so throws
5314 * an elog(ERROR) if the enum option is not found.
5316 * The returned string is a pointer to static data and not
5317 * allocated for modification.
5320 config_enum_lookup_by_value(struct config_enum * record, int val)
5322 const struct config_enum_entry *entry;
5324 for (entry = record->options; entry && entry->name; entry++)
5326 if (entry->val == val)
5330 elog(ERROR, "could not find enum option %d for %s",
5331 val, record->gen.name);
5332 return NULL; /* silence compiler */
5337 * Lookup the value for an enum option with the selected name
5338 * (case-insensitive).
5339 * If the enum option is found, sets the retval value and returns
5340 * true. If it's not found, return FALSE and retval is set to 0.
5343 config_enum_lookup_by_name(struct config_enum * record, const char *value,
5346 const struct config_enum_entry *entry;
5348 for (entry = record->options; entry && entry->name; entry++)
5350 if (pg_strcasecmp(value, entry->name) == 0)
5352 *retval = entry->val;
5363 * Return a list of all available options for an enum, excluding
5364 * hidden ones, separated by the given separator.
5365 * If prefix is non-NULL, it is added before the first enum value.
5366 * If suffix is non-NULL, it is added to the end of the string.
5369 config_enum_get_options(struct config_enum * record, const char *prefix,
5370 const char *suffix, const char *separator)
5372 const struct config_enum_entry *entry;
5373 StringInfoData retstr;
5376 initStringInfo(&retstr);
5377 appendStringInfoString(&retstr, prefix);
5379 seplen = strlen(separator);
5380 for (entry = record->options; entry && entry->name; entry++)
5384 appendStringInfoString(&retstr, entry->name);
5385 appendBinaryStringInfo(&retstr, separator, seplen);
5390 * All the entries may have been hidden, leaving the string empty if no
5391 * prefix was given. This indicates a broken GUC setup, since there is no
5392 * use for an enum without any values, so we just check to make sure we
5393 * don't write to invalid memory instead of actually trying to do
5394 * something smart with it.
5396 if (retstr.len >= seplen)
5398 /* Replace final separator */
5399 retstr.data[retstr.len - seplen] = '\0';
5400 retstr.len -= seplen;
5403 appendStringInfoString(&retstr, suffix);
5409 * Parse and validate a proposed value for the specified configuration
5412 * This does built-in checks (such as range limits for an integer parameter)
5413 * and also calls any check hook the parameter may have.
5415 * record: GUC variable's info record
5416 * name: variable name (should match the record of course)
5417 * value: proposed value, as a string
5418 * source: identifies source of value (check hooks may need this)
5419 * elevel: level to log any error reports at
5420 * newval: on success, converted parameter value is returned here
5421 * newextra: on success, receives any "extra" data returned by check hook
5422 * (caller must initialize *newextra to NULL)
5424 * Returns true if OK, false if not (or throws error, if elevel >= ERROR)
5427 parse_and_validate_value(struct config_generic * record,
5428 const char *name, const char *value,
5429 GucSource source, int elevel,
5430 union config_var_val * newval, void **newextra)
5432 switch (record->vartype)
5436 struct config_bool *conf = (struct config_bool *) record;
5438 if (!parse_bool(value, &newval->boolval))
5441 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5442 errmsg("parameter \"%s\" requires a Boolean value",
5447 if (!call_bool_check_hook(conf, &newval->boolval, newextra,
5454 struct config_int *conf = (struct config_int *) record;
5455 const char *hintmsg;
5457 if (!parse_int(value, &newval->intval,
5458 conf->gen.flags, &hintmsg))
5461 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5462 errmsg("invalid value for parameter \"%s\": \"%s\"",
5464 hintmsg ? errhint("%s", _(hintmsg)) : 0));
5468 if (newval->intval < conf->min || newval->intval > conf->max)
5471 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5472 errmsg("%d is outside the valid range for parameter \"%s\" (%d .. %d)",
5473 newval->intval, name,
5474 conf->min, conf->max)));
5478 if (!call_int_check_hook(conf, &newval->intval, newextra,
5485 struct config_real *conf = (struct config_real *) record;
5487 if (!parse_real(value, &newval->realval))
5490 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5491 errmsg("parameter \"%s\" requires a numeric value",
5496 if (newval->realval < conf->min || newval->realval > conf->max)
5499 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5500 errmsg("%g is outside the valid range for parameter \"%s\" (%g .. %g)",
5501 newval->realval, name,
5502 conf->min, conf->max)));
5506 if (!call_real_check_hook(conf, &newval->realval, newextra,
5513 struct config_string *conf = (struct config_string *) record;
5516 * The value passed by the caller could be transient, so we
5519 newval->stringval = guc_strdup(elevel, value);
5520 if (newval->stringval == NULL)
5524 * The only built-in "parsing" check we have is to apply
5525 * truncation if GUC_IS_NAME.
5527 if (conf->gen.flags & GUC_IS_NAME)
5528 truncate_identifier(newval->stringval,
5529 strlen(newval->stringval),
5532 if (!call_string_check_hook(conf, &newval->stringval, newextra,
5535 free(newval->stringval);
5536 newval->stringval = NULL;
5543 struct config_enum *conf = (struct config_enum *) record;
5545 if (!config_enum_lookup_by_name(conf, value, &newval->enumval))
5549 hintmsg = config_enum_get_options(conf,
5550 "Available values: ",
5554 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5555 errmsg("invalid value for parameter \"%s\": \"%s\"",
5557 hintmsg ? errhint("%s", _(hintmsg)) : 0));
5564 if (!call_enum_check_hook(conf, &newval->enumval, newextra,
5576 * Sets option `name' to given value.
5578 * The value should be a string, which will be parsed and converted to
5579 * the appropriate data type. The context and source parameters indicate
5580 * in which context this function is being called, so that it can apply the
5581 * access restrictions properly.
5583 * If value is NULL, set the option to its default value (normally the
5584 * reset_val, but if source == PGC_S_DEFAULT we instead use the boot_val).
5586 * action indicates whether to set the value globally in the session, locally
5587 * to the current top transaction, or just for the duration of a function call.
5589 * If changeVal is false then don't really set the option but do all
5590 * the checks to see if it would work.
5592 * elevel should normally be passed as zero, allowing this function to make
5593 * its standard choice of ereport level. However some callers need to be
5594 * able to override that choice; they should pass the ereport level to use.
5597 * +1: the value is valid and was successfully applied.
5598 * 0: the name or value is invalid (but see below).
5599 * -1: the value was not applied because of context, priority, or changeVal.
5601 * If there is an error (non-existing option, invalid value) then an
5602 * ereport(ERROR) is thrown *unless* this is called for a source for which
5603 * we don't want an ERROR (currently, those are defaults, the config file,
5604 * and per-database or per-user settings, as well as callers who specify
5605 * a less-than-ERROR elevel). In those cases we write a suitable error
5606 * message via ereport() and return 0.
5608 * See also SetConfigOption for an external interface.
5611 set_config_option(const char *name, const char *value,
5612 GucContext context, GucSource source,
5613 GucAction action, bool changeVal, int elevel,
5616 struct config_generic *record;
5617 union config_var_val newval_union;
5618 void *newextra = NULL;
5619 bool prohibitValueChange = false;
5624 if (source == PGC_S_DEFAULT || source == PGC_S_FILE)
5627 * To avoid cluttering the log, only the postmaster bleats loudly
5628 * about problems with the config file.
5630 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
5632 else if (source == PGC_S_GLOBAL ||
5633 source == PGC_S_DATABASE ||
5634 source == PGC_S_USER ||
5635 source == PGC_S_DATABASE_USER)
5642 * GUC_ACTION_SAVE changes are acceptable during a parallel operation,
5643 * because the current worker will also pop the change. We're probably
5644 * dealing with a function having a proconfig entry. Only the function's
5645 * body should observe the change, and peer workers do not share in the
5646 * execution of a function call started by this worker.
5648 * Other changes might need to affect other workers, so forbid them.
5650 if (IsInParallelMode() && changeVal && action != GUC_ACTION_SAVE)
5652 (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
5653 errmsg("cannot set parameters during a parallel operation")));
5655 record = find_option(name, true, elevel);
5659 (errcode(ERRCODE_UNDEFINED_OBJECT),
5660 errmsg("unrecognized configuration parameter \"%s\"", name)));
5665 * Check if the option can be set at this time. See guc.h for the precise
5668 switch (record->context)
5671 if (context != PGC_INTERNAL)
5674 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5675 errmsg("parameter \"%s\" cannot be changed",
5680 case PGC_POSTMASTER:
5681 if (context == PGC_SIGHUP)
5684 * We are re-reading a PGC_POSTMASTER variable from
5685 * postgresql.conf. We can't change the setting, so we should
5686 * give a warning if the DBA tries to change it. However,
5687 * because of variant formats, canonicalization by check
5688 * hooks, etc, we can't just compare the given string directly
5689 * to what's stored. Set a flag to check below after we have
5690 * the final storable value.
5692 prohibitValueChange = true;
5694 else if (context != PGC_POSTMASTER)
5697 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5698 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5704 if (context != PGC_SIGHUP && context != PGC_POSTMASTER)
5707 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5708 errmsg("parameter \"%s\" cannot be changed now",
5714 * Hmm, the idea of the SIGHUP context is "ought to be global, but
5715 * can be changed after postmaster start". But there's nothing
5716 * that prevents a crafty administrator from sending SIGHUP
5717 * signals to individual backends only.
5720 case PGC_SU_BACKEND:
5721 /* Reject if we're connecting but user is not superuser */
5722 if (context == PGC_BACKEND)
5725 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5726 errmsg("permission denied to set parameter \"%s\"",
5730 /* FALL THRU to process the same as PGC_BACKEND */
5732 if (context == PGC_SIGHUP)
5735 * If a PGC_BACKEND or PGC_SU_BACKEND parameter is changed in
5736 * the config file, we want to accept the new value in the
5737 * postmaster (whence it will propagate to
5738 * subsequently-started backends), but ignore it in existing
5739 * backends. This is a tad klugy, but necessary because we
5740 * don't re-read the config file during backend start.
5742 * In EXEC_BACKEND builds, this works differently: we load all
5743 * nondefault settings from the CONFIG_EXEC_PARAMS file during
5744 * backend start. In that case we must accept PGC_SIGHUP
5745 * settings, so as to have the same value as if we'd forked
5746 * from the postmaster. This can also happen when using
5747 * RestoreGUCState() within a background worker that needs to
5748 * have the same settings as the user backend that started it.
5749 * is_reload will be true when either situation applies.
5751 if (IsUnderPostmaster && !is_reload)
5754 else if (context != PGC_POSTMASTER &&
5755 context != PGC_BACKEND &&
5756 context != PGC_SU_BACKEND &&
5757 source != PGC_S_CLIENT)
5760 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5761 errmsg("parameter \"%s\" cannot be set after connection start",
5767 if (context == PGC_USERSET || context == PGC_BACKEND)
5770 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5771 errmsg("permission denied to set parameter \"%s\"",
5782 * Disallow changing GUC_NOT_WHILE_SEC_REST values if we are inside a
5783 * security restriction context. We can reject this regardless of the GUC
5784 * context or source, mainly because sources that it might be reasonable
5785 * to override for won't be seen while inside a function.
5787 * Note: variables marked GUC_NOT_WHILE_SEC_REST should usually be marked
5788 * GUC_NO_RESET_ALL as well, because ResetAllOptions() doesn't check this.
5789 * An exception might be made if the reset value is assumed to be "safe".
5791 * Note: this flag is currently used for "session_authorization" and
5792 * "role". We need to prohibit changing these inside a local userid
5793 * context because when we exit it, GUC won't be notified, leaving things
5794 * out of sync. (This could be fixed by forcing a new GUC nesting level,
5795 * but that would change behavior in possibly-undesirable ways.) Also, we
5796 * prohibit changing these in a security-restricted operation because
5797 * otherwise RESET could be used to regain the session user's privileges.
5799 if (record->flags & GUC_NOT_WHILE_SEC_REST)
5801 if (InLocalUserIdChange())
5804 * Phrasing of this error message is historical, but it's the most
5808 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5809 errmsg("cannot set parameter \"%s\" within security-definer function",
5813 if (InSecurityRestrictedOperation())
5816 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5817 errmsg("cannot set parameter \"%s\" within security-restricted operation",
5824 * Should we set reset/stacked values? (If so, the behavior is not
5825 * transactional.) This is done either when we get a default value from
5826 * the database's/user's/client's default settings or when we reset a
5827 * value to its default.
5829 makeDefault = changeVal && (source <= PGC_S_OVERRIDE) &&
5830 ((value != NULL) || source == PGC_S_DEFAULT);
5833 * Ignore attempted set if overridden by previously processed setting.
5834 * However, if changeVal is false then plow ahead anyway since we are
5835 * trying to find out if the value is potentially good, not actually use
5836 * it. Also keep going if makeDefault is true, since we may want to set
5837 * the reset/stacked values even if we can't set the variable itself.
5839 if (record->source > source)
5841 if (changeVal && !makeDefault)
5843 elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
5851 * Evaluate value and set variable.
5853 switch (record->vartype)
5857 struct config_bool *conf = (struct config_bool *) record;
5859 #define newval (newval_union.boolval)
5863 if (!parse_and_validate_value(record, name, value,
5865 &newval_union, &newextra))
5868 else if (source == PGC_S_DEFAULT)
5870 newval = conf->boot_val;
5871 if (!call_bool_check_hook(conf, &newval, &newextra,
5877 newval = conf->reset_val;
5878 newextra = conf->reset_extra;
5879 source = conf->gen.reset_source;
5880 context = conf->gen.reset_scontext;
5883 if (prohibitValueChange)
5885 if (*conf->variable != newval)
5887 record->status |= GUC_PENDING_RESTART;
5889 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5890 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5894 record->status &= ~GUC_PENDING_RESTART;
5900 /* Save old value to support transaction abort */
5902 push_old_value(&conf->gen, action);
5904 if (conf->assign_hook)
5905 (*conf->assign_hook) (newval, newextra);
5906 *conf->variable = newval;
5907 set_extra_field(&conf->gen, &conf->gen.extra,
5909 conf->gen.source = source;
5910 conf->gen.scontext = context;
5916 if (conf->gen.reset_source <= source)
5918 conf->reset_val = newval;
5919 set_extra_field(&conf->gen, &conf->reset_extra,
5921 conf->gen.reset_source = source;
5922 conf->gen.reset_scontext = context;
5924 for (stack = conf->gen.stack; stack; stack = stack->prev)
5926 if (stack->source <= source)
5928 stack->prior.val.boolval = newval;
5929 set_extra_field(&conf->gen, &stack->prior.extra,
5931 stack->source = source;
5932 stack->scontext = context;
5937 /* Perhaps we didn't install newextra anywhere */
5938 if (newextra && !extra_field_used(&conf->gen, newextra))
5947 struct config_int *conf = (struct config_int *) record;
5949 #define newval (newval_union.intval)
5953 if (!parse_and_validate_value(record, name, value,
5955 &newval_union, &newextra))
5958 else if (source == PGC_S_DEFAULT)
5960 newval = conf->boot_val;
5961 if (!call_int_check_hook(conf, &newval, &newextra,
5967 newval = conf->reset_val;
5968 newextra = conf->reset_extra;
5969 source = conf->gen.reset_source;
5970 context = conf->gen.reset_scontext;
5973 if (prohibitValueChange)
5975 if (*conf->variable != newval)
5977 record->status |= GUC_PENDING_RESTART;
5979 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5980 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5984 record->status &= ~GUC_PENDING_RESTART;
5990 /* Save old value to support transaction abort */
5992 push_old_value(&conf->gen, action);
5994 if (conf->assign_hook)
5995 (*conf->assign_hook) (newval, newextra);
5996 *conf->variable = newval;
5997 set_extra_field(&conf->gen, &conf->gen.extra,
5999 conf->gen.source = source;
6000 conf->gen.scontext = context;
6006 if (conf->gen.reset_source <= source)
6008 conf->reset_val = newval;
6009 set_extra_field(&conf->gen, &conf->reset_extra,
6011 conf->gen.reset_source = source;
6012 conf->gen.reset_scontext = context;
6014 for (stack = conf->gen.stack; stack; stack = stack->prev)
6016 if (stack->source <= source)
6018 stack->prior.val.intval = newval;
6019 set_extra_field(&conf->gen, &stack->prior.extra,
6021 stack->source = source;
6022 stack->scontext = context;
6027 /* Perhaps we didn't install newextra anywhere */
6028 if (newextra && !extra_field_used(&conf->gen, newextra))
6037 struct config_real *conf = (struct config_real *) record;
6039 #define newval (newval_union.realval)
6043 if (!parse_and_validate_value(record, name, value,
6045 &newval_union, &newextra))
6048 else if (source == PGC_S_DEFAULT)
6050 newval = conf->boot_val;
6051 if (!call_real_check_hook(conf, &newval, &newextra,
6057 newval = conf->reset_val;
6058 newextra = conf->reset_extra;
6059 source = conf->gen.reset_source;
6060 context = conf->gen.reset_scontext;
6063 if (prohibitValueChange)
6065 if (*conf->variable != newval)
6067 record->status |= GUC_PENDING_RESTART;
6069 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6070 errmsg("parameter \"%s\" cannot be changed without restarting the server",
6074 record->status &= ~GUC_PENDING_RESTART;
6080 /* Save old value to support transaction abort */
6082 push_old_value(&conf->gen, action);
6084 if (conf->assign_hook)
6085 (*conf->assign_hook) (newval, newextra);
6086 *conf->variable = newval;
6087 set_extra_field(&conf->gen, &conf->gen.extra,
6089 conf->gen.source = source;
6090 conf->gen.scontext = context;
6096 if (conf->gen.reset_source <= source)
6098 conf->reset_val = newval;
6099 set_extra_field(&conf->gen, &conf->reset_extra,
6101 conf->gen.reset_source = source;
6102 conf->gen.reset_scontext = context;
6104 for (stack = conf->gen.stack; stack; stack = stack->prev)
6106 if (stack->source <= source)
6108 stack->prior.val.realval = newval;
6109 set_extra_field(&conf->gen, &stack->prior.extra,
6111 stack->source = source;
6112 stack->scontext = context;
6117 /* Perhaps we didn't install newextra anywhere */
6118 if (newextra && !extra_field_used(&conf->gen, newextra))
6127 struct config_string *conf = (struct config_string *) record;
6129 #define newval (newval_union.stringval)
6133 if (!parse_and_validate_value(record, name, value,
6135 &newval_union, &newextra))
6138 else if (source == PGC_S_DEFAULT)
6140 /* non-NULL boot_val must always get strdup'd */
6141 if (conf->boot_val != NULL)
6143 newval = guc_strdup(elevel, conf->boot_val);
6150 if (!call_string_check_hook(conf, &newval, &newextra,
6160 * strdup not needed, since reset_val is already under
6163 newval = conf->reset_val;
6164 newextra = conf->reset_extra;
6165 source = conf->gen.reset_source;
6166 context = conf->gen.reset_scontext;
6169 if (prohibitValueChange)
6171 /* newval shouldn't be NULL, so we're a bit sloppy here */
6172 if (*conf->variable == NULL || newval == NULL ||
6173 strcmp(*conf->variable, newval) != 0)
6175 record->status |= GUC_PENDING_RESTART;
6177 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6178 errmsg("parameter \"%s\" cannot be changed without restarting the server",
6182 record->status &= ~GUC_PENDING_RESTART;
6188 /* Save old value to support transaction abort */
6190 push_old_value(&conf->gen, action);
6192 if (conf->assign_hook)
6193 (*conf->assign_hook) (newval, newextra);
6194 set_string_field(conf, conf->variable, newval);
6195 set_extra_field(&conf->gen, &conf->gen.extra,
6197 conf->gen.source = source;
6198 conf->gen.scontext = context;
6205 if (conf->gen.reset_source <= source)
6207 set_string_field(conf, &conf->reset_val, newval);
6208 set_extra_field(&conf->gen, &conf->reset_extra,
6210 conf->gen.reset_source = source;
6211 conf->gen.reset_scontext = context;
6213 for (stack = conf->gen.stack; stack; stack = stack->prev)
6215 if (stack->source <= source)
6217 set_string_field(conf, &stack->prior.val.stringval,
6219 set_extra_field(&conf->gen, &stack->prior.extra,
6221 stack->source = source;
6222 stack->scontext = context;
6227 /* Perhaps we didn't install newval anywhere */
6228 if (newval && !string_field_used(conf, newval))
6230 /* Perhaps we didn't install newextra anywhere */
6231 if (newextra && !extra_field_used(&conf->gen, newextra))
6240 struct config_enum *conf = (struct config_enum *) record;
6242 #define newval (newval_union.enumval)
6246 if (!parse_and_validate_value(record, name, value,
6248 &newval_union, &newextra))
6251 else if (source == PGC_S_DEFAULT)
6253 newval = conf->boot_val;
6254 if (!call_enum_check_hook(conf, &newval, &newextra,
6260 newval = conf->reset_val;
6261 newextra = conf->reset_extra;
6262 source = conf->gen.reset_source;
6263 context = conf->gen.reset_scontext;
6266 if (prohibitValueChange)
6268 if (*conf->variable != newval)
6270 record->status |= GUC_PENDING_RESTART;
6272 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6273 errmsg("parameter \"%s\" cannot be changed without restarting the server",
6277 record->status &= ~GUC_PENDING_RESTART;
6283 /* Save old value to support transaction abort */
6285 push_old_value(&conf->gen, action);
6287 if (conf->assign_hook)
6288 (*conf->assign_hook) (newval, newextra);
6289 *conf->variable = newval;
6290 set_extra_field(&conf->gen, &conf->gen.extra,
6292 conf->gen.source = source;
6293 conf->gen.scontext = context;
6299 if (conf->gen.reset_source <= source)
6301 conf->reset_val = newval;
6302 set_extra_field(&conf->gen, &conf->reset_extra,
6304 conf->gen.reset_source = source;
6305 conf->gen.reset_scontext = context;
6307 for (stack = conf->gen.stack; stack; stack = stack->prev)
6309 if (stack->source <= source)
6311 stack->prior.val.enumval = newval;
6312 set_extra_field(&conf->gen, &stack->prior.extra,
6314 stack->source = source;
6315 stack->scontext = context;
6320 /* Perhaps we didn't install newextra anywhere */
6321 if (newextra && !extra_field_used(&conf->gen, newextra))
6329 if (changeVal && (record->flags & GUC_REPORT))
6330 ReportGUCOption(record);
6332 return changeVal ? 1 : -1;
6337 * Set the fields for source file and line number the setting came from.
6340 set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
6342 struct config_generic *record;
6346 * To avoid cluttering the log, only the postmaster bleats loudly about
6347 * problems with the config file.
6349 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
6351 record = find_option(name, true, elevel);
6352 /* should not happen */
6354 elog(ERROR, "unrecognized configuration parameter \"%s\"", name);
6356 sourcefile = guc_strdup(elevel, sourcefile);
6357 if (record->sourcefile)
6358 free(record->sourcefile);
6359 record->sourcefile = sourcefile;
6360 record->sourceline = sourceline;
6364 * Set a config option to the given value.
6366 * See also set_config_option; this is just the wrapper to be called from
6367 * outside GUC. (This function should be used when possible, because its API
6368 * is more stable than set_config_option's.)
6370 * Note: there is no support here for setting source file/line, as it
6371 * is currently not needed.
6374 SetConfigOption(const char *name, const char *value,
6375 GucContext context, GucSource source)
6377 (void) set_config_option(name, value, context, source,
6378 GUC_ACTION_SET, true, 0, false);
6384 * Fetch the current value of the option `name', as a string.
6386 * If the option doesn't exist, return NULL if missing_ok is true (NOTE that
6387 * this cannot be distinguished from a string variable with a NULL value!),
6388 * otherwise throw an ereport and don't return.
6390 * If restrict_superuser is true, we also enforce that only superusers can
6391 * see GUC_SUPERUSER_ONLY variables. This should only be passed as true
6392 * in user-driven calls.
6394 * The string is *not* allocated for modification and is really only
6395 * valid until the next call to configuration related functions.
6398 GetConfigOption(const char *name, bool missing_ok, bool restrict_superuser)
6400 struct config_generic *record;
6401 static char buffer[256];
6403 record = find_option(name, false, ERROR);
6409 (errcode(ERRCODE_UNDEFINED_OBJECT),
6410 errmsg("unrecognized configuration parameter \"%s\"",
6413 if (restrict_superuser &&
6414 (record->flags & GUC_SUPERUSER_ONLY) &&
6417 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6418 errmsg("must be superuser to examine \"%s\"", name)));
6420 switch (record->vartype)
6423 return *((struct config_bool *) record)->variable ? "on" : "off";
6426 snprintf(buffer, sizeof(buffer), "%d",
6427 *((struct config_int *) record)->variable);
6431 snprintf(buffer, sizeof(buffer), "%g",
6432 *((struct config_real *) record)->variable);
6436 return *((struct config_string *) record)->variable;
6439 return config_enum_lookup_by_value((struct config_enum *) record,
6440 *((struct config_enum *) record)->variable);
6446 * Get the RESET value associated with the given option.
6448 * Note: this is not re-entrant, due to use of static result buffer;
6449 * not to mention that a string variable could have its reset_val changed.
6450 * Beware of assuming the result value is good for very long.
6453 GetConfigOptionResetString(const char *name)
6455 struct config_generic *record;
6456 static char buffer[256];
6458 record = find_option(name, false, ERROR);
6461 (errcode(ERRCODE_UNDEFINED_OBJECT),
6462 errmsg("unrecognized configuration parameter \"%s\"", name)));
6463 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
6465 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6466 errmsg("must be superuser to examine \"%s\"", name)));
6468 switch (record->vartype)
6471 return ((struct config_bool *) record)->reset_val ? "on" : "off";
6474 snprintf(buffer, sizeof(buffer), "%d",
6475 ((struct config_int *) record)->reset_val);
6479 snprintf(buffer, sizeof(buffer), "%g",
6480 ((struct config_real *) record)->reset_val);
6484 return ((struct config_string *) record)->reset_val;
6487 return config_enum_lookup_by_value((struct config_enum *) record,
6488 ((struct config_enum *) record)->reset_val);
6495 * flatten_set_variable_args
6496 * Given a parsenode List as emitted by the grammar for SET,
6497 * convert to the flat string representation used by GUC.
6499 * We need to be told the name of the variable the args are for, because
6500 * the flattening rules vary (ugh).
6502 * The result is NULL if args is NIL (ie, SET ... TO DEFAULT), otherwise
6503 * a palloc'd string.
6506 flatten_set_variable_args(const char *name, List *args)
6508 struct config_generic *record;
6513 /* Fast path if just DEFAULT */
6518 * Get flags for the variable; if it's not known, use default flags.
6519 * (Caller might throw error later, but not our business to do so here.)
6521 record = find_option(name, false, WARNING);
6523 flags = record->flags;
6527 /* Complain if list input and non-list variable */
6528 if ((flags & GUC_LIST_INPUT) == 0 &&
6529 list_length(args) != 1)
6531 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6532 errmsg("SET %s takes only one argument", name)));
6534 initStringInfo(&buf);
6537 * Each list member may be a plain A_Const node, or an A_Const within a
6538 * TypeCast; the latter case is supported only for ConstInterval arguments
6539 * (for SET TIME ZONE).
6543 Node *arg = (Node *) lfirst(l);
6545 TypeName *typeName = NULL;
6548 if (l != list_head(args))
6549 appendStringInfoString(&buf, ", ");
6551 if (IsA(arg, TypeCast))
6553 TypeCast *tc = (TypeCast *) arg;
6556 typeName = tc->typeName;
6559 if (!IsA(arg, A_Const))
6560 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
6561 con = (A_Const *) arg;
6563 switch (nodeTag(&con->val))
6566 appendStringInfo(&buf, "%ld", intVal(&con->val));
6569 /* represented as a string, so just copy it */
6570 appendStringInfoString(&buf, strVal(&con->val));
6573 val = strVal(&con->val);
6574 if (typeName != NULL)
6577 * Must be a ConstInterval argument for TIME ZONE. Coerce
6578 * to interval and back to normalize the value and account
6586 typenameTypeIdAndMod(NULL, typeName, &typoid, &typmod);
6587 Assert(typoid == INTERVALOID);
6590 DirectFunctionCall3(interval_in,
6591 CStringGetDatum(val),
6592 ObjectIdGetDatum(InvalidOid),
6593 Int32GetDatum(typmod));
6596 DatumGetCString(DirectFunctionCall1(interval_out,
6598 appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
6603 * Plain string literal or identifier. For quote mode,
6604 * quote it if it's not a vanilla identifier.
6606 if (flags & GUC_LIST_QUOTE)
6607 appendStringInfoString(&buf, quote_identifier(val));
6609 appendStringInfoString(&buf, val);
6613 elog(ERROR, "unrecognized node type: %d",
6614 (int) nodeTag(&con->val));
6623 * Write updated configuration parameter values into a temporary file.
6624 * This function traverses the list of parameters and quotes the string
6625 * values before writing them.
6628 write_auto_conf_file(int fd, const char *filename, ConfigVariable *head)
6631 ConfigVariable *item;
6633 initStringInfo(&buf);
6635 /* Emit file header containing warning comment */
6636 appendStringInfoString(&buf, "# Do not edit this file manually!\n");
6637 appendStringInfoString(&buf, "# It will be overwritten by ALTER SYSTEM command.\n");
6640 if (write(fd, buf.data, buf.len) != buf.len)
6642 /* if write didn't set errno, assume problem is no disk space */
6646 (errcode_for_file_access(),
6647 errmsg("could not write to file \"%s\": %m", filename)));
6650 /* Emit each parameter, properly quoting the value */
6651 for (item = head; item != NULL; item = item->next)
6655 resetStringInfo(&buf);
6657 appendStringInfoString(&buf, item->name);
6658 appendStringInfoString(&buf, " = '");
6660 escaped = escape_single_quotes_ascii(item->value);
6663 (errcode(ERRCODE_OUT_OF_MEMORY),
6664 errmsg("out of memory")));
6665 appendStringInfoString(&buf, escaped);
6668 appendStringInfoString(&buf, "'\n");
6671 if (write(fd, buf.data, buf.len) != buf.len)
6673 /* if write didn't set errno, assume problem is no disk space */
6677 (errcode_for_file_access(),
6678 errmsg("could not write to file \"%s\": %m", filename)));
6682 /* fsync before considering the write to be successful */
6683 if (pg_fsync(fd) != 0)
6685 (errcode_for_file_access(),
6686 errmsg("could not fsync file \"%s\": %m", filename)));
6692 * Update the given list of configuration parameters, adding, replacing
6693 * or deleting the entry for item "name" (delete if "value" == NULL).
6696 replace_auto_config_value(ConfigVariable **head_p, ConfigVariable **tail_p,
6697 const char *name, const char *value)
6699 ConfigVariable *item,
6702 /* Search the list for an existing match (we assume there's only one) */
6703 for (item = *head_p; item != NULL; item = item->next)
6705 if (strcmp(item->name, name) == 0)
6707 /* found a match, replace it */
6711 /* update the parameter value */
6712 item->value = pstrdup(value);
6716 /* delete the configuration parameter from list */
6717 if (*head_p == item)
6718 *head_p = item->next;
6720 prev->next = item->next;
6721 if (*tail_p == item)
6725 pfree(item->filename);
6733 /* Not there; no work if we're trying to delete it */
6737 /* OK, append a new entry */
6738 item = palloc(sizeof *item);
6739 item->name = pstrdup(name);
6740 item->value = pstrdup(value);
6741 item->errmsg = NULL;
6742 item->filename = pstrdup(""); /* new item has no location */
6743 item->sourceline = 0;
6744 item->ignore = false;
6745 item->applied = false;
6748 if (*head_p == NULL)
6751 (*tail_p)->next = item;
6757 * Execute ALTER SYSTEM statement.
6759 * Read the old PG_AUTOCONF_FILENAME file, merge in the new variable value,
6760 * and write out an updated file. If the command is ALTER SYSTEM RESET ALL,
6761 * we can skip reading the old file and just write an empty file.
6763 * An LWLock is used to serialize updates of the configuration file.
6765 * In case of an error, we leave the original automatic
6766 * configuration file (PG_AUTOCONF_FILENAME) intact.
6769 AlterSystemSetConfigFile(AlterSystemStmt *altersysstmt)
6773 bool resetall = false;
6774 ConfigVariable *head = NULL;
6775 ConfigVariable *tail = NULL;
6777 char AutoConfFileName[MAXPGPATH];
6778 char AutoConfTmpFileName[MAXPGPATH];
6782 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6783 (errmsg("must be superuser to execute ALTER SYSTEM command"))));
6786 * Extract statement arguments
6788 name = altersysstmt->setstmt->name;
6790 switch (altersysstmt->setstmt->kind)
6793 value = ExtractSetVariableArgs(altersysstmt->setstmt);
6796 case VAR_SET_DEFAULT:
6807 elog(ERROR, "unrecognized alter system stmt type: %d",
6808 altersysstmt->setstmt->kind);
6813 * Unless it's RESET_ALL, validate the target variable and value
6817 struct config_generic *record;
6819 record = find_option(name, false, ERROR);
6822 (errcode(ERRCODE_UNDEFINED_OBJECT),
6823 errmsg("unrecognized configuration parameter \"%s\"",
6827 * Don't allow parameters that can't be set in configuration files to
6828 * be set in PG_AUTOCONF_FILENAME file.
6830 if ((record->context == PGC_INTERNAL) ||
6831 (record->flags & GUC_DISALLOW_IN_FILE) ||
6832 (record->flags & GUC_DISALLOW_IN_AUTO_FILE))
6834 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6835 errmsg("parameter \"%s\" cannot be changed",
6840 union config_var_val newval;
6841 void *newextra = NULL;
6843 if (!parse_and_validate_value(record, name, value,
6845 &newval, &newextra))
6847 (errmsg("invalid value for parameter \"%s\": \"%s\"",
6850 if (record->vartype == PGC_STRING && newval.stringval != NULL)
6851 free(newval.stringval);
6858 * PG_AUTOCONF_FILENAME and its corresponding temporary file are always in
6859 * the data directory, so we can reference them by simple relative paths.
6861 snprintf(AutoConfFileName, sizeof(AutoConfFileName), "%s",
6862 PG_AUTOCONF_FILENAME);
6863 snprintf(AutoConfTmpFileName, sizeof(AutoConfTmpFileName), "%s.%s",
6868 * Only one backend is allowed to operate on PG_AUTOCONF_FILENAME at a
6869 * time. Use AutoFileLock to ensure that. We must hold the lock while
6870 * reading the old file contents.
6872 LWLockAcquire(AutoFileLock, LW_EXCLUSIVE);
6875 * If we're going to reset everything, then no need to open or parse the
6876 * old file. We'll just write out an empty list.
6882 if (stat(AutoConfFileName, &st) == 0)
6884 /* open old file PG_AUTOCONF_FILENAME */
6887 infile = AllocateFile(AutoConfFileName, "r");
6890 (errmsg("could not open file \"%s\": %m",
6891 AutoConfFileName)));
6894 if (!ParseConfigFp(infile, AutoConfFileName, 0, LOG, &head, &tail))
6896 (errmsg("could not parse contents of file \"%s\"",
6897 AutoConfFileName)));
6903 * Now, replace any existing entry with the new value, or add it if
6906 replace_auto_config_value(&head, &tail, name, value);
6910 * To ensure crash safety, first write the new file data to a temp file,
6911 * then atomically rename it into place.
6913 * If there is a temp file left over due to a previous crash, it's okay to
6914 * truncate and reuse it.
6916 Tmpfd = BasicOpenFile(AutoConfTmpFileName,
6917 O_CREAT | O_RDWR | O_TRUNC,
6921 (errcode_for_file_access(),
6922 errmsg("could not open file \"%s\": %m",
6923 AutoConfTmpFileName)));
6926 * Use a TRY block to clean up the file if we fail. Since we need a TRY
6927 * block anyway, OK to use BasicOpenFile rather than OpenTransientFile.
6931 /* Write and sync the new contents to the temporary file */
6932 write_auto_conf_file(Tmpfd, AutoConfTmpFileName, head);
6934 /* Close before renaming; may be required on some platforms */
6939 * As the rename is atomic operation, if any problem occurs after this
6940 * at worst it can lose the parameters set by last ALTER SYSTEM
6943 if (rename(AutoConfTmpFileName, AutoConfFileName) < 0)
6945 (errcode_for_file_access(),
6946 errmsg("could not rename file \"%s\" to \"%s\": %m",
6947 AutoConfTmpFileName, AutoConfFileName)));
6951 /* Close file first, else unlink might fail on some platforms */
6955 /* Unlink, but ignore any error */
6956 (void) unlink(AutoConfTmpFileName);
6962 FreeConfigVariables(head);
6964 LWLockRelease(AutoFileLock);
6971 ExecSetVariableStmt(VariableSetStmt *stmt, bool isTopLevel)
6973 GucAction action = stmt->is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET;
6976 * Workers synchronize these parameters at the start of the parallel
6977 * operation; then, we block SET during the operation.
6979 if (IsInParallelMode())
6981 (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
6982 errmsg("cannot set parameters during a parallel operation")));
6987 case VAR_SET_CURRENT:
6989 WarnNoTransactionChain(isTopLevel, "SET LOCAL");
6990 (void) set_config_option(stmt->name,
6991 ExtractSetVariableArgs(stmt),
6992 (superuser() ? PGC_SUSET : PGC_USERSET),
6994 action, true, 0, false);
6999 * Special-case SQL syntaxes. The TRANSACTION and SESSION
7000 * CHARACTERISTICS cases effectively set more than one variable
7001 * per statement. TRANSACTION SNAPSHOT only takes one argument,
7002 * but we put it here anyway since it's a special case and not
7003 * related to any GUC variable.
7005 if (strcmp(stmt->name, "TRANSACTION") == 0)
7009 WarnNoTransactionChain(isTopLevel, "SET TRANSACTION");
7011 foreach(head, stmt->args)
7013 DefElem *item = (DefElem *) lfirst(head);
7015 if (strcmp(item->defname, "transaction_isolation") == 0)
7016 SetPGVariable("transaction_isolation",
7017 list_make1(item->arg), stmt->is_local);
7018 else if (strcmp(item->defname, "transaction_read_only") == 0)
7019 SetPGVariable("transaction_read_only",
7020 list_make1(item->arg), stmt->is_local);
7021 else if (strcmp(item->defname, "transaction_deferrable") == 0)
7022 SetPGVariable("transaction_deferrable",
7023 list_make1(item->arg), stmt->is_local);
7025 elog(ERROR, "unexpected SET TRANSACTION element: %s",
7029 else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
7033 foreach(head, stmt->args)
7035 DefElem *item = (DefElem *) lfirst(head);
7037 if (strcmp(item->defname, "transaction_isolation") == 0)
7038 SetPGVariable("default_transaction_isolation",
7039 list_make1(item->arg), stmt->is_local);
7040 else if (strcmp(item->defname, "transaction_read_only") == 0)
7041 SetPGVariable("default_transaction_read_only",
7042 list_make1(item->arg), stmt->is_local);
7043 else if (strcmp(item->defname, "transaction_deferrable") == 0)
7044 SetPGVariable("default_transaction_deferrable",
7045 list_make1(item->arg), stmt->is_local);
7047 elog(ERROR, "unexpected SET SESSION element: %s",
7051 else if (strcmp(stmt->name, "TRANSACTION SNAPSHOT") == 0)
7053 A_Const *con = (A_Const *) linitial(stmt->args);
7057 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7058 errmsg("SET LOCAL TRANSACTION SNAPSHOT is not implemented")));
7060 WarnNoTransactionChain(isTopLevel, "SET TRANSACTION");
7061 Assert(IsA(con, A_Const));
7062 Assert(nodeTag(&con->val) == T_String);
7063 ImportSnapshot(strVal(&con->val));
7066 elog(ERROR, "unexpected SET MULTI element: %s",
7069 case VAR_SET_DEFAULT:
7071 WarnNoTransactionChain(isTopLevel, "SET LOCAL");
7074 if (strcmp(stmt->name, "transaction_isolation") == 0)
7075 WarnNoTransactionChain(isTopLevel, "RESET TRANSACTION");
7077 (void) set_config_option(stmt->name,
7079 (superuser() ? PGC_SUSET : PGC_USERSET),
7081 action, true, 0, false);
7090 * Get the value to assign for a VariableSetStmt, or NULL if it's RESET.
7091 * The result is palloc'd.
7093 * This is exported for use by actions such as ALTER ROLE SET.
7096 ExtractSetVariableArgs(VariableSetStmt *stmt)
7101 return flatten_set_variable_args(stmt->name, stmt->args);
7102 case VAR_SET_CURRENT:
7103 return GetConfigOptionByName(stmt->name, NULL, false);
7110 * SetPGVariable - SET command exported as an easily-C-callable function.
7112 * This provides access to SET TO value, as well as SET TO DEFAULT (expressed
7113 * by passing args == NIL), but not SET FROM CURRENT functionality.
7116 SetPGVariable(const char *name, List *args, bool is_local)
7118 char *argstring = flatten_set_variable_args(name, args);
7120 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
7121 (void) set_config_option(name,
7123 (superuser() ? PGC_SUSET : PGC_USERSET),
7125 is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET,
7130 * SET command wrapped as a SQL callable function.
7133 set_config_by_name(PG_FUNCTION_ARGS)
7140 if (PG_ARGISNULL(0))
7142 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
7143 errmsg("SET requires parameter name")));
7145 /* Get the GUC variable name */
7146 name = TextDatumGetCString(PG_GETARG_DATUM(0));
7148 /* Get the desired value or set to NULL for a reset request */
7149 if (PG_ARGISNULL(1))
7152 value = TextDatumGetCString(PG_GETARG_DATUM(1));
7155 * Get the desired state of is_local. Default to false if provided value
7158 if (PG_ARGISNULL(2))
7161 is_local = PG_GETARG_BOOL(2);
7163 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
7164 (void) set_config_option(name,
7166 (superuser() ? PGC_SUSET : PGC_USERSET),
7168 is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET,
7171 /* get the new current value */
7172 new_value = GetConfigOptionByName(name, NULL, false);
7174 /* Convert return string to text */
7175 PG_RETURN_TEXT_P(cstring_to_text(new_value));
7180 * Common code for DefineCustomXXXVariable subroutines: allocate the
7181 * new variable's config struct and fill in generic fields.
7183 static struct config_generic *
7184 init_custom_variable(const char *name,
7185 const char *short_desc,
7186 const char *long_desc,
7189 enum config_type type,
7192 struct config_generic *gen;
7195 * Only allow custom PGC_POSTMASTER variables to be created during shared
7196 * library preload; any later than that, we can't ensure that the value
7197 * doesn't change after startup. This is a fatal elog if it happens; just
7198 * erroring out isn't safe because we don't know what the calling loadable
7199 * module might already have hooked into.
7201 if (context == PGC_POSTMASTER &&
7202 !process_shared_preload_libraries_in_progress)
7203 elog(FATAL, "cannot create PGC_POSTMASTER variables after startup");
7205 gen = (struct config_generic *) guc_malloc(ERROR, sz);
7208 gen->name = guc_strdup(ERROR, name);
7209 gen->context = context;
7210 gen->group = CUSTOM_OPTIONS;
7211 gen->short_desc = short_desc;
7212 gen->long_desc = long_desc;
7214 gen->vartype = type;
7220 * Common code for DefineCustomXXXVariable subroutines: insert the new
7221 * variable into the GUC variable array, replacing any placeholder.
7224 define_custom_variable(struct config_generic * variable)
7226 const char *name = variable->name;
7227 const char **nameAddr = &name;
7228 struct config_string *pHolder;
7229 struct config_generic **res;
7232 * See if there's a placeholder by the same name.
7234 res = (struct config_generic **) bsearch((void *) &nameAddr,
7235 (void *) guc_variables,
7237 sizeof(struct config_generic *),
7242 * No placeholder to replace, so we can just add it ... but first,
7243 * make sure it's initialized to its default value.
7245 InitializeOneGUCOption(variable);
7246 add_guc_variable(variable, ERROR);
7251 * This better be a placeholder
7253 if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
7255 (errcode(ERRCODE_INTERNAL_ERROR),
7256 errmsg("attempt to redefine parameter \"%s\"", name)));
7258 Assert((*res)->vartype == PGC_STRING);
7259 pHolder = (struct config_string *) (*res);
7262 * First, set the variable to its default value. We must do this even
7263 * though we intend to immediately apply a new value, since it's possible
7264 * that the new value is invalid.
7266 InitializeOneGUCOption(variable);
7269 * Replace the placeholder. We aren't changing the name, so no re-sorting
7275 * Assign the string value(s) stored in the placeholder to the real
7276 * variable. Essentially, we need to duplicate all the active and stacked
7277 * values, but with appropriate validation and datatype adjustment.
7279 * If an assignment fails, we report a WARNING and keep going. We don't
7280 * want to throw ERROR for bad values, because it'd bollix the add-on
7281 * module that's presumably halfway through getting loaded. In such cases
7282 * the default or previous state will become active instead.
7285 /* First, apply the reset value if any */
7286 if (pHolder->reset_val)
7287 (void) set_config_option(name, pHolder->reset_val,
7288 pHolder->gen.reset_scontext,
7289 pHolder->gen.reset_source,
7290 GUC_ACTION_SET, true, WARNING, false);
7291 /* That should not have resulted in stacking anything */
7292 Assert(variable->stack == NULL);
7294 /* Now, apply current and stacked values, in the order they were stacked */
7295 reapply_stacked_values(variable, pHolder, pHolder->gen.stack,
7296 *(pHolder->variable),
7297 pHolder->gen.scontext, pHolder->gen.source);
7299 /* Also copy over any saved source-location information */
7300 if (pHolder->gen.sourcefile)
7301 set_config_sourcefile(name, pHolder->gen.sourcefile,
7302 pHolder->gen.sourceline);
7305 * Free up as much as we conveniently can of the placeholder structure.
7306 * (This neglects any stack items, so it's possible for some memory to be
7307 * leaked. Since this can only happen once per session per variable, it
7308 * doesn't seem worth spending much code on.)
7310 set_string_field(pHolder, pHolder->variable, NULL);
7311 set_string_field(pHolder, &pHolder->reset_val, NULL);
7317 * Recursive subroutine for define_custom_variable: reapply non-reset values
7319 * We recurse so that the values are applied in the same order as originally.
7320 * At each recursion level, apply the upper-level value (passed in) in the
7321 * fashion implied by the stack entry.
7324 reapply_stacked_values(struct config_generic * variable,
7325 struct config_string * pHolder,
7327 const char *curvalue,
7328 GucContext curscontext, GucSource cursource)
7330 const char *name = variable->name;
7331 GucStack *oldvarstack = variable->stack;
7335 /* First, recurse, so that stack items are processed bottom to top */
7336 reapply_stacked_values(variable, pHolder, stack->prev,
7337 stack->prior.val.stringval,
7338 stack->scontext, stack->source);
7340 /* See how to apply the passed-in value */
7341 switch (stack->state)
7344 (void) set_config_option(name, curvalue,
7345 curscontext, cursource,
7346 GUC_ACTION_SAVE, true,
7351 (void) set_config_option(name, curvalue,
7352 curscontext, cursource,
7353 GUC_ACTION_SET, true,
7358 (void) set_config_option(name, curvalue,
7359 curscontext, cursource,
7360 GUC_ACTION_LOCAL, true,
7365 /* first, apply the masked value as SET */
7366 (void) set_config_option(name, stack->masked.val.stringval,
7367 stack->masked_scontext, PGC_S_SESSION,
7368 GUC_ACTION_SET, true,
7370 /* then apply the current value as LOCAL */
7371 (void) set_config_option(name, curvalue,
7372 curscontext, cursource,
7373 GUC_ACTION_LOCAL, true,
7378 /* If we successfully made a stack entry, adjust its nest level */
7379 if (variable->stack != oldvarstack)
7380 variable->stack->nest_level = stack->nest_level;
7385 * We are at the end of the stack. If the active/previous value is
7386 * different from the reset value, it must represent a previously
7387 * committed session value. Apply it, and then drop the stack entry
7388 * that set_config_option will have created under the impression that
7389 * this is to be just a transactional assignment. (We leak the stack
7392 if (curvalue != pHolder->reset_val ||
7393 curscontext != pHolder->gen.reset_scontext ||
7394 cursource != pHolder->gen.reset_source)
7396 (void) set_config_option(name, curvalue,
7397 curscontext, cursource,
7398 GUC_ACTION_SET, true, WARNING, false);
7399 variable->stack = NULL;
7405 DefineCustomBoolVariable(const char *name,
7406 const char *short_desc,
7407 const char *long_desc,
7412 GucBoolCheckHook check_hook,
7413 GucBoolAssignHook assign_hook,
7414 GucShowHook show_hook)
7416 struct config_bool *var;
7418 var = (struct config_bool *)
7419 init_custom_variable(name, short_desc, long_desc, context, flags,
7420 PGC_BOOL, sizeof(struct config_bool));
7421 var->variable = valueAddr;
7422 var->boot_val = bootValue;
7423 var->reset_val = bootValue;
7424 var->check_hook = check_hook;
7425 var->assign_hook = assign_hook;
7426 var->show_hook = show_hook;
7427 define_custom_variable(&var->gen);
7431 DefineCustomIntVariable(const char *name,
7432 const char *short_desc,
7433 const char *long_desc,
7440 GucIntCheckHook check_hook,
7441 GucIntAssignHook assign_hook,
7442 GucShowHook show_hook)
7444 struct config_int *var;
7446 var = (struct config_int *)
7447 init_custom_variable(name, short_desc, long_desc, context, flags,
7448 PGC_INT, sizeof(struct config_int));
7449 var->variable = valueAddr;
7450 var->boot_val = bootValue;
7451 var->reset_val = bootValue;
7452 var->min = minValue;
7453 var->max = maxValue;
7454 var->check_hook = check_hook;
7455 var->assign_hook = assign_hook;
7456 var->show_hook = show_hook;
7457 define_custom_variable(&var->gen);
7461 DefineCustomRealVariable(const char *name,
7462 const char *short_desc,
7463 const char *long_desc,
7470 GucRealCheckHook check_hook,
7471 GucRealAssignHook assign_hook,
7472 GucShowHook show_hook)
7474 struct config_real *var;
7476 var = (struct config_real *)
7477 init_custom_variable(name, short_desc, long_desc, context, flags,
7478 PGC_REAL, sizeof(struct config_real));
7479 var->variable = valueAddr;
7480 var->boot_val = bootValue;
7481 var->reset_val = bootValue;
7482 var->min = minValue;
7483 var->max = maxValue;
7484 var->check_hook = check_hook;
7485 var->assign_hook = assign_hook;
7486 var->show_hook = show_hook;
7487 define_custom_variable(&var->gen);
7491 DefineCustomStringVariable(const char *name,
7492 const char *short_desc,
7493 const char *long_desc,
7495 const char *bootValue,
7498 GucStringCheckHook check_hook,
7499 GucStringAssignHook assign_hook,
7500 GucShowHook show_hook)
7502 struct config_string *var;
7504 var = (struct config_string *)
7505 init_custom_variable(name, short_desc, long_desc, context, flags,
7506 PGC_STRING, sizeof(struct config_string));
7507 var->variable = valueAddr;
7508 var->boot_val = bootValue;
7509 var->check_hook = check_hook;
7510 var->assign_hook = assign_hook;
7511 var->show_hook = show_hook;
7512 define_custom_variable(&var->gen);
7516 DefineCustomEnumVariable(const char *name,
7517 const char *short_desc,
7518 const char *long_desc,
7521 const struct config_enum_entry * options,
7524 GucEnumCheckHook check_hook,
7525 GucEnumAssignHook assign_hook,
7526 GucShowHook show_hook)
7528 struct config_enum *var;
7530 var = (struct config_enum *)
7531 init_custom_variable(name, short_desc, long_desc, context, flags,
7532 PGC_ENUM, sizeof(struct config_enum));
7533 var->variable = valueAddr;
7534 var->boot_val = bootValue;
7535 var->reset_val = bootValue;
7536 var->options = options;
7537 var->check_hook = check_hook;
7538 var->assign_hook = assign_hook;
7539 var->show_hook = show_hook;
7540 define_custom_variable(&var->gen);
7544 EmitWarningsOnPlaceholders(const char *className)
7546 int classLen = strlen(className);
7549 for (i = 0; i < num_guc_variables; i++)
7551 struct config_generic *var = guc_variables[i];
7553 if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
7554 strncmp(className, var->name, classLen) == 0 &&
7555 var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
7558 (errcode(ERRCODE_UNDEFINED_OBJECT),
7559 errmsg("unrecognized configuration parameter \"%s\"",
7570 GetPGVariable(const char *name, DestReceiver *dest)
7572 if (guc_name_compare(name, "all") == 0)
7573 ShowAllGUCConfig(dest);
7575 ShowGUCConfigOption(name, dest);
7579 GetPGVariableResultDesc(const char *name)
7583 if (guc_name_compare(name, "all") == 0)
7585 /* need a tuple descriptor representing three TEXT columns */
7586 tupdesc = CreateTemplateTupleDesc(3, false);
7587 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
7589 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
7591 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
7596 const char *varname;
7598 /* Get the canonical spelling of name */
7599 (void) GetConfigOptionByName(name, &varname, false);
7601 /* need a tuple descriptor representing a single TEXT column */
7602 tupdesc = CreateTemplateTupleDesc(1, false);
7603 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
7614 ShowGUCConfigOption(const char *name, DestReceiver *dest)
7616 TupOutputState *tstate;
7618 const char *varname;
7621 /* Get the value and canonical spelling of name */
7622 value = GetConfigOptionByName(name, &varname, false);
7624 /* need a tuple descriptor representing a single TEXT column */
7625 tupdesc = CreateTemplateTupleDesc(1, false);
7626 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
7629 /* prepare for projection of tuples */
7630 tstate = begin_tup_output_tupdesc(dest, tupdesc);
7633 do_text_output_oneline(tstate, value);
7635 end_tup_output(tstate);
7642 ShowAllGUCConfig(DestReceiver *dest)
7644 bool am_superuser = superuser();
7646 TupOutputState *tstate;
7649 bool isnull[3] = {false, false, false};
7651 /* need a tuple descriptor representing three TEXT columns */
7652 tupdesc = CreateTemplateTupleDesc(3, false);
7653 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
7655 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
7657 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
7660 /* prepare for projection of tuples */
7661 tstate = begin_tup_output_tupdesc(dest, tupdesc);
7663 for (i = 0; i < num_guc_variables; i++)
7665 struct config_generic *conf = guc_variables[i];
7668 if ((conf->flags & GUC_NO_SHOW_ALL) ||
7669 ((conf->flags & GUC_SUPERUSER_ONLY) && !am_superuser))
7672 /* assign to the values array */
7673 values[0] = PointerGetDatum(cstring_to_text(conf->name));
7675 setting = _ShowOption(conf, true);
7678 values[1] = PointerGetDatum(cstring_to_text(setting));
7683 values[1] = PointerGetDatum(NULL);
7687 values[2] = PointerGetDatum(cstring_to_text(conf->short_desc));
7689 /* send it to dest */
7690 do_tup_output(tstate, values, isnull);
7693 pfree(DatumGetPointer(values[0]));
7697 pfree(DatumGetPointer(values[1]));
7699 pfree(DatumGetPointer(values[2]));
7702 end_tup_output(tstate);
7706 * Return GUC variable value by name; optionally return canonical form of
7707 * name. If the GUC is unset, then throw an error unless missing_ok is true,
7708 * in which case return NULL. Return value is palloc'd (but *varname isn't).
7711 GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
7713 struct config_generic *record;
7715 record = find_option(name, false, ERROR);
7726 (errcode(ERRCODE_UNDEFINED_OBJECT),
7727 errmsg("unrecognized configuration parameter \"%s\"", name)));
7730 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
7732 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7733 errmsg("must be superuser to examine \"%s\"", name)));
7736 *varname = record->name;
7738 return _ShowOption(record, true);
7742 * Return GUC variable value by variable number; optionally return canonical
7743 * form of name. Return value is palloc'd.
7746 GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
7749 struct config_generic *conf;
7751 /* check requested variable number valid */
7752 Assert((varnum >= 0) && (varnum < num_guc_variables));
7754 conf = guc_variables[varnum];
7758 if ((conf->flags & GUC_NO_SHOW_ALL) ||
7759 ((conf->flags & GUC_SUPERUSER_ONLY) && !superuser()))
7765 /* first get the generic attributes */
7768 values[0] = conf->name;
7770 /* setting : use _ShowOption in order to avoid duplicating the logic */
7771 values[1] = _ShowOption(conf, false);
7774 if (conf->vartype == PGC_INT)
7778 switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
7783 case GUC_UNIT_BLOCKS:
7784 snprintf(buf, sizeof(buf), "%dkB", BLCKSZ / 1024);
7787 case GUC_UNIT_XBLOCKS:
7788 snprintf(buf, sizeof(buf), "%dkB", XLOG_BLCKSZ / 1024);
7809 values[3] = config_group_names[conf->group];
7812 values[4] = conf->short_desc;
7815 values[5] = conf->long_desc;
7818 values[6] = GucContext_Names[conf->context];
7821 values[7] = config_type_names[conf->vartype];
7824 values[8] = GucSource_Names[conf->source];
7826 /* now get the type specifc attributes */
7827 switch (conf->vartype)
7831 struct config_bool *lconf = (struct config_bool *) conf;
7843 values[12] = pstrdup(lconf->boot_val ? "on" : "off");
7846 values[13] = pstrdup(lconf->reset_val ? "on" : "off");
7852 struct config_int *lconf = (struct config_int *) conf;
7855 snprintf(buffer, sizeof(buffer), "%d", lconf->min);
7856 values[9] = pstrdup(buffer);
7859 snprintf(buffer, sizeof(buffer), "%d", lconf->max);
7860 values[10] = pstrdup(buffer);
7866 snprintf(buffer, sizeof(buffer), "%d", lconf->boot_val);
7867 values[12] = pstrdup(buffer);
7870 snprintf(buffer, sizeof(buffer), "%d", lconf->reset_val);
7871 values[13] = pstrdup(buffer);
7877 struct config_real *lconf = (struct config_real *) conf;
7880 snprintf(buffer, sizeof(buffer), "%g", lconf->min);
7881 values[9] = pstrdup(buffer);
7884 snprintf(buffer, sizeof(buffer), "%g", lconf->max);
7885 values[10] = pstrdup(buffer);
7891 snprintf(buffer, sizeof(buffer), "%g", lconf->boot_val);
7892 values[12] = pstrdup(buffer);
7895 snprintf(buffer, sizeof(buffer), "%g", lconf->reset_val);
7896 values[13] = pstrdup(buffer);
7902 struct config_string *lconf = (struct config_string *) conf;
7914 if (lconf->boot_val == NULL)
7917 values[12] = pstrdup(lconf->boot_val);
7920 if (lconf->reset_val == NULL)
7923 values[13] = pstrdup(lconf->reset_val);
7929 struct config_enum *lconf = (struct config_enum *) conf;
7940 * NOTE! enumvals with double quotes in them are not
7943 values[11] = config_enum_get_options((struct config_enum *) conf,
7944 "{\"", "\"}", "\",\"");
7947 values[12] = pstrdup(config_enum_lookup_by_value(lconf,
7951 values[13] = pstrdup(config_enum_lookup_by_value(lconf,
7959 * should never get here, but in case we do, set 'em to NULL
7981 * If the setting came from a config file, set the source location. For
7982 * security reasons, we don't show source file/line number for
7985 if (conf->source == PGC_S_FILE && superuser())
7987 values[14] = conf->sourcefile;
7988 snprintf(buffer, sizeof(buffer), "%d", conf->sourceline);
7989 values[15] = pstrdup(buffer);
7997 values[16] = (conf->status & GUC_PENDING_RESTART) ? "t" : "f";
8001 * Return the total number of GUC variables
8004 GetNumConfigOptions(void)
8006 return num_guc_variables;
8010 * show_config_by_name - equiv to SHOW X command but implemented as
8014 show_config_by_name(PG_FUNCTION_ARGS)
8016 char *varname = TextDatumGetCString(PG_GETARG_DATUM(0));
8020 varval = GetConfigOptionByName(varname, NULL, false);
8022 /* Convert to text */
8023 PG_RETURN_TEXT_P(cstring_to_text(varval));
8027 * show_config_by_name_missing_ok - equiv to SHOW X command but implemented as
8028 * a function. If X does not exist, suppress the error and just return NULL
8029 * if missing_ok is TRUE.
8032 show_config_by_name_missing_ok(PG_FUNCTION_ARGS)
8034 char *varname = TextDatumGetCString(PG_GETARG_DATUM(0));
8035 bool missing_ok = PG_GETARG_BOOL(1);
8039 varval = GetConfigOptionByName(varname, NULL, missing_ok);
8041 /* return NULL if no such variable */
8045 /* Convert to text */
8046 PG_RETURN_TEXT_P(cstring_to_text(varval));
8050 * show_all_settings - equiv to SHOW ALL command but implemented as
8053 #define NUM_PG_SETTINGS_ATTS 17
8056 show_all_settings(PG_FUNCTION_ARGS)
8058 FuncCallContext *funcctx;
8062 AttInMetadata *attinmeta;
8063 MemoryContext oldcontext;
8065 /* stuff done only on the first call of the function */
8066 if (SRF_IS_FIRSTCALL())
8068 /* create a function context for cross-call persistence */
8069 funcctx = SRF_FIRSTCALL_INIT();
8072 * switch to memory context appropriate for multiple function calls
8074 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
8077 * need a tuple descriptor representing NUM_PG_SETTINGS_ATTS columns
8078 * of the appropriate types
8080 tupdesc = CreateTemplateTupleDesc(NUM_PG_SETTINGS_ATTS, false);
8081 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
8083 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
8085 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "unit",
8087 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "category",
8089 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "short_desc",
8091 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "extra_desc",
8093 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "context",
8095 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "vartype",
8097 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "source",
8099 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "min_val",
8101 TupleDescInitEntry(tupdesc, (AttrNumber) 11, "max_val",
8103 TupleDescInitEntry(tupdesc, (AttrNumber) 12, "enumvals",
8104 TEXTARRAYOID, -1, 0);
8105 TupleDescInitEntry(tupdesc, (AttrNumber) 13, "boot_val",
8107 TupleDescInitEntry(tupdesc, (AttrNumber) 14, "reset_val",
8109 TupleDescInitEntry(tupdesc, (AttrNumber) 15, "sourcefile",
8111 TupleDescInitEntry(tupdesc, (AttrNumber) 16, "sourceline",
8113 TupleDescInitEntry(tupdesc, (AttrNumber) 17, "pending_restart",
8117 * Generate attribute metadata needed later to produce tuples from raw
8120 attinmeta = TupleDescGetAttInMetadata(tupdesc);
8121 funcctx->attinmeta = attinmeta;
8123 /* total number of tuples to be returned */
8124 funcctx->max_calls = GetNumConfigOptions();
8126 MemoryContextSwitchTo(oldcontext);
8129 /* stuff done on every call of the function */
8130 funcctx = SRF_PERCALL_SETUP();
8132 call_cntr = funcctx->call_cntr;
8133 max_calls = funcctx->max_calls;
8134 attinmeta = funcctx->attinmeta;
8136 if (call_cntr < max_calls) /* do when there is more left to send */
8138 char *values[NUM_PG_SETTINGS_ATTS];
8144 * Get the next visible GUC variable name and value
8148 GetConfigOptionByNum(call_cntr, (const char **) values, &noshow);
8151 /* bump the counter and get the next config setting */
8152 call_cntr = ++funcctx->call_cntr;
8154 /* make sure we haven't gone too far now */
8155 if (call_cntr >= max_calls)
8156 SRF_RETURN_DONE(funcctx);
8161 tuple = BuildTupleFromCStrings(attinmeta, values);
8163 /* make the tuple into a datum */
8164 result = HeapTupleGetDatum(tuple);
8166 SRF_RETURN_NEXT(funcctx, result);
8170 /* do when there is no more left */
8171 SRF_RETURN_DONE(funcctx);
8176 * show_all_file_settings
8178 * Returns a table of all parameter settings in all configuration files
8179 * which includes the config file pathname, the line number, a sequence number
8180 * indicating the order in which the settings were encountered, the parameter
8181 * name and value, a bool showing if the value could be applied, and possibly
8182 * an associated error message. (For problems such as syntax errors, the
8183 * parameter name/value might be NULL.)
8185 * Note: no filtering is done here, instead we depend on the GRANT system
8186 * to prevent unprivileged users from accessing this function or the view
8187 * built on top of it.
8190 show_all_file_settings(PG_FUNCTION_ARGS)
8192 #define NUM_PG_FILE_SETTINGS_ATTS 7
8193 ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
8195 Tuplestorestate *tupstore;
8196 ConfigVariable *conf;
8198 MemoryContext per_query_ctx;
8199 MemoryContext oldcontext;
8201 /* Check to see if caller supports us returning a tuplestore */
8202 if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo))
8204 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8205 errmsg("set-valued function called in context that cannot accept a set")));
8206 if (!(rsinfo->allowedModes & SFRM_Materialize))
8208 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8209 errmsg("materialize mode required, but it is not " \
8210 "allowed in this context")));
8212 /* Scan the config files using current context as workspace */
8213 conf = ProcessConfigFileInternal(PGC_SIGHUP, false, DEBUG3);
8215 /* Switch into long-lived context to construct returned data structures */
8216 per_query_ctx = rsinfo->econtext->ecxt_per_query_memory;
8217 oldcontext = MemoryContextSwitchTo(per_query_ctx);
8219 /* Build a tuple descriptor for our result type */
8220 tupdesc = CreateTemplateTupleDesc(NUM_PG_FILE_SETTINGS_ATTS, false);
8221 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "sourcefile",
8223 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "sourceline",
8225 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "seqno",
8227 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "name",
8229 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "setting",
8231 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "applied",
8233 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "error",
8236 /* Build a tuplestore to return our results in */
8237 tupstore = tuplestore_begin_heap(true, false, work_mem);
8238 rsinfo->returnMode = SFRM_Materialize;
8239 rsinfo->setResult = tupstore;
8240 rsinfo->setDesc = tupdesc;
8242 /* The rest can be done in short-lived context */
8243 MemoryContextSwitchTo(oldcontext);
8245 /* Process the results and create a tuplestore */
8246 for (seqno = 1; conf != NULL; conf = conf->next, seqno++)
8248 Datum values[NUM_PG_FILE_SETTINGS_ATTS];
8249 bool nulls[NUM_PG_FILE_SETTINGS_ATTS];
8251 memset(values, 0, sizeof(values));
8252 memset(nulls, 0, sizeof(nulls));
8256 values[0] = PointerGetDatum(cstring_to_text(conf->filename));
8260 /* sourceline (not meaningful if no sourcefile) */
8262 values[1] = Int32GetDatum(conf->sourceline);
8267 values[2] = Int32GetDatum(seqno);
8271 values[3] = PointerGetDatum(cstring_to_text(conf->name));
8277 values[4] = PointerGetDatum(cstring_to_text(conf->value));
8282 values[5] = BoolGetDatum(conf->applied);
8286 values[6] = PointerGetDatum(cstring_to_text(conf->errmsg));
8290 /* shove row into tuplestore */
8291 tuplestore_putvalues(tupstore, tupdesc, values, nulls);
8294 tuplestore_donestoring(tupstore);
8300 _ShowOption(struct config_generic * record, bool use_units)
8305 switch (record->vartype)
8309 struct config_bool *conf = (struct config_bool *) record;
8311 if (conf->show_hook)
8312 val = (*conf->show_hook) ();
8314 val = *conf->variable ? "on" : "off";
8320 struct config_int *conf = (struct config_int *) record;
8322 if (conf->show_hook)
8323 val = (*conf->show_hook) ();
8327 * Use int64 arithmetic to avoid overflows in units
8330 int64 result = *conf->variable;
8333 if (use_units && result > 0 && (record->flags & GUC_UNIT))
8335 convert_from_base_unit(result, record->flags & GUC_UNIT,
8341 snprintf(buffer, sizeof(buffer), INT64_FORMAT "%s",
8350 struct config_real *conf = (struct config_real *) record;
8352 if (conf->show_hook)
8353 val = (*conf->show_hook) ();
8356 snprintf(buffer, sizeof(buffer), "%g",
8365 struct config_string *conf = (struct config_string *) record;
8367 if (conf->show_hook)
8368 val = (*conf->show_hook) ();
8369 else if (*conf->variable && **conf->variable)
8370 val = *conf->variable;
8378 struct config_enum *conf = (struct config_enum *) record;
8380 if (conf->show_hook)
8381 val = (*conf->show_hook) ();
8383 val = config_enum_lookup_by_value(conf, *conf->variable);
8388 /* just to keep compiler quiet */
8393 return pstrdup(val);
8400 * These routines dump out all non-default GUC options into a binary
8401 * file that is read by all exec'ed backends. The format is:
8403 * variable name, string, null terminated
8404 * variable value, string, null terminated
8405 * variable sourcefile, string, null terminated (empty if none)
8406 * variable sourceline, integer
8407 * variable source, integer
8408 * variable scontext, integer
8411 write_one_nondefault_variable(FILE *fp, struct config_generic * gconf)
8413 if (gconf->source == PGC_S_DEFAULT)
8416 fprintf(fp, "%s", gconf->name);
8419 switch (gconf->vartype)
8423 struct config_bool *conf = (struct config_bool *) gconf;
8425 if (*conf->variable)
8426 fprintf(fp, "true");
8428 fprintf(fp, "false");
8434 struct config_int *conf = (struct config_int *) gconf;
8436 fprintf(fp, "%d", *conf->variable);
8442 struct config_real *conf = (struct config_real *) gconf;
8444 fprintf(fp, "%.17g", *conf->variable);
8450 struct config_string *conf = (struct config_string *) gconf;
8452 fprintf(fp, "%s", *conf->variable);
8458 struct config_enum *conf = (struct config_enum *) gconf;
8461 config_enum_lookup_by_value(conf, *conf->variable));
8468 if (gconf->sourcefile)
8469 fprintf(fp, "%s", gconf->sourcefile);
8472 fwrite(&gconf->sourceline, 1, sizeof(gconf->sourceline), fp);
8473 fwrite(&gconf->source, 1, sizeof(gconf->source), fp);
8474 fwrite(&gconf->scontext, 1, sizeof(gconf->scontext), fp);
8478 write_nondefault_variables(GucContext context)
8484 Assert(context == PGC_POSTMASTER || context == PGC_SIGHUP);
8486 elevel = (context == PGC_SIGHUP) ? LOG : ERROR;
8491 fp = AllocateFile(CONFIG_EXEC_PARAMS_NEW, "w");
8495 (errcode_for_file_access(),
8496 errmsg("could not write to file \"%s\": %m",
8497 CONFIG_EXEC_PARAMS_NEW)));
8501 for (i = 0; i < num_guc_variables; i++)
8503 write_one_nondefault_variable(fp, guc_variables[i]);
8509 (errcode_for_file_access(),
8510 errmsg("could not write to file \"%s\": %m",
8511 CONFIG_EXEC_PARAMS_NEW)));
8516 * Put new file in place. This could delay on Win32, but we don't hold
8517 * any exclusive locks.
8519 rename(CONFIG_EXEC_PARAMS_NEW, CONFIG_EXEC_PARAMS);
8524 * Read string, including null byte from file
8526 * Return NULL on EOF and nothing read
8529 read_string_with_null(FILE *fp)
8538 if ((ch = fgetc(fp)) == EOF)
8543 elog(FATAL, "invalid format of exec config params file");
8546 str = guc_malloc(FATAL, maxlen);
8547 else if (i == maxlen)
8548 str = guc_realloc(FATAL, str, maxlen *= 2);
8557 * This routine loads a previous postmaster dump of its non-default
8561 read_nondefault_variables(void)
8568 GucSource varsource;
8569 GucContext varscontext;
8572 * Assert that PGC_BACKEND/PGC_SU_BACKEND case in set_config_option() will
8573 * do the right thing.
8575 Assert(IsInitProcessingMode());
8580 fp = AllocateFile(CONFIG_EXEC_PARAMS, "r");
8583 /* File not found is fine */
8584 if (errno != ENOENT)
8586 (errcode_for_file_access(),
8587 errmsg("could not read from file \"%s\": %m",
8588 CONFIG_EXEC_PARAMS)));
8594 struct config_generic *record;
8596 if ((varname = read_string_with_null(fp)) == NULL)
8599 if ((record = find_option(varname, true, FATAL)) == NULL)
8600 elog(FATAL, "failed to locate variable \"%s\" in exec config params file", varname);
8602 if ((varvalue = read_string_with_null(fp)) == NULL)
8603 elog(FATAL, "invalid format of exec config params file");
8604 if ((varsourcefile = read_string_with_null(fp)) == NULL)
8605 elog(FATAL, "invalid format of exec config params file");
8606 if (fread(&varsourceline, 1, sizeof(varsourceline), fp) != sizeof(varsourceline))
8607 elog(FATAL, "invalid format of exec config params file");
8608 if (fread(&varsource, 1, sizeof(varsource), fp) != sizeof(varsource))
8609 elog(FATAL, "invalid format of exec config params file");
8610 if (fread(&varscontext, 1, sizeof(varscontext), fp) != sizeof(varscontext))
8611 elog(FATAL, "invalid format of exec config params file");
8613 (void) set_config_option(varname, varvalue,
8614 varscontext, varsource,
8615 GUC_ACTION_SET, true, 0, true);
8616 if (varsourcefile[0])
8617 set_config_sourcefile(varname, varsourcefile, varsourceline);
8621 free(varsourcefile);
8626 #endif /* EXEC_BACKEND */
8630 * When serializing, determine whether to skip this GUC. When restoring, the
8631 * negation of this test determines whether to restore the compiled-in default
8632 * value before processing serialized values.
8634 * A PGC_S_DEFAULT setting on the serialize side will typically match new
8635 * postmaster children, but that can be false when got_SIGHUP == true and the
8636 * pending configuration change modifies this setting. Nonetheless, we omit
8637 * PGC_S_DEFAULT settings from serialization and make up for that by restoring
8638 * defaults before applying serialized values.
8640 * PGC_POSTMASTER variables always have the same value in every child of a
8641 * particular postmaster. Most PGC_INTERNAL variables are compile-time
8642 * constants; a few, like server_encoding and lc_ctype, are handled specially
8643 * outside the serialize/restore procedure. Therefore, SerializeGUCState()
8644 * never sends these, and RestoreGUCState() never changes them.
8647 can_skip_gucvar(struct config_generic * gconf)
8649 return gconf->context == PGC_POSTMASTER ||
8650 gconf->context == PGC_INTERNAL || gconf->source == PGC_S_DEFAULT;
8654 * estimate_variable_size:
8655 * Estimate max size for dumping the given GUC variable.
8658 estimate_variable_size(struct config_generic * gconf)
8663 if (can_skip_gucvar(gconf))
8668 size = add_size(size, strlen(gconf->name) + 1);
8670 /* Get the maximum display length of the GUC value. */
8671 switch (gconf->vartype)
8675 valsize = 5; /* max(strlen('true'), strlen('false')) */
8681 struct config_int *conf = (struct config_int *) gconf;
8684 * Instead of getting the exact display length, use max
8685 * length. Also reduce the max length for typical ranges of
8686 * small values. Maximum value is 2147483647, i.e. 10 chars.
8687 * Include one byte for sign.
8689 if (abs(*conf->variable) < 1000)
8699 * We are going to print it with %.17g. Account for sign,
8700 * decimal point, and e+nnn notation. E.g.
8701 * -3.9932904234000002e+110
8703 valsize = REALTYPE_PRECISION + 1 + 1 + 5;
8709 struct config_string *conf = (struct config_string *) gconf;
8711 valsize = strlen(*conf->variable);
8717 struct config_enum *conf = (struct config_enum *) gconf;
8719 valsize = strlen(config_enum_lookup_by_value(conf, *conf->variable));
8724 /* Allow space for terminating zero-byte */
8725 size = add_size(size, valsize + 1);
8727 if (gconf->sourcefile)
8728 size = add_size(size, strlen(gconf->sourcefile));
8730 /* Allow space for terminating zero-byte */
8731 size = add_size(size, 1);
8733 /* Include line whenever we include file. */
8734 if (gconf->sourcefile)
8735 size = add_size(size, sizeof(gconf->sourceline));
8737 size = add_size(size, sizeof(gconf->source));
8738 size = add_size(size, sizeof(gconf->scontext));
8744 * EstimateGUCStateSpace:
8745 * Returns the size needed to store the GUC state for the current process
8748 EstimateGUCStateSpace(void)
8753 /* Add space reqd for saving the data size of the guc state */
8754 size = sizeof(Size);
8756 /* Add up the space needed for each GUC variable */
8757 for (i = 0; i < num_guc_variables; i++)
8758 size = add_size(size,
8759 estimate_variable_size(guc_variables[i]));
8766 * Copies the formatted string into the destination. Moves ahead the
8767 * destination pointer, and decrements the maxbytes by that many bytes. If
8768 * maxbytes is not sufficient to copy the string, error out.
8771 do_serialize(char **destptr, Size *maxbytes, const char *fmt,...)
8777 elog(ERROR, "not enough space to serialize GUC state");
8779 va_start(vargs, fmt);
8780 n = vsnprintf(*destptr, *maxbytes, fmt, vargs);
8784 * Cater to portability hazards in the vsnprintf() return value just like
8785 * appendPQExpBufferVA() does. Note that this requires an extra byte of
8786 * slack at the end of the buffer. Since serialize_variable() ends with a
8787 * do_serialize_binary() rather than a do_serialize(), we'll always have
8788 * that slack; estimate_variable_size() need not add a byte for it.
8790 if (n < 0 || n >= *maxbytes - 1)
8792 if (n < 0 && errno != 0 && errno != ENOMEM)
8793 /* Shouldn't happen. Better show errno description. */
8794 elog(ERROR, "vsnprintf failed: %m");
8796 elog(ERROR, "not enough space to serialize GUC state");
8799 /* Shift the destptr ahead of the null terminator */
8804 /* Binary copy version of do_serialize() */
8806 do_serialize_binary(char **destptr, Size *maxbytes, void *val, Size valsize)
8808 if (valsize > *maxbytes)
8809 elog(ERROR, "not enough space to serialize GUC state");
8811 memcpy(*destptr, val, valsize);
8812 *destptr += valsize;
8813 *maxbytes -= valsize;
8817 * serialize_variable:
8818 * Dumps name, value and other information of a GUC variable into destptr.
8821 serialize_variable(char **destptr, Size *maxbytes,
8822 struct config_generic * gconf)
8824 if (can_skip_gucvar(gconf))
8827 do_serialize(destptr, maxbytes, "%s", gconf->name);
8829 switch (gconf->vartype)
8833 struct config_bool *conf = (struct config_bool *) gconf;
8835 do_serialize(destptr, maxbytes,
8836 (*conf->variable ? "true" : "false"));
8842 struct config_int *conf = (struct config_int *) gconf;
8844 do_serialize(destptr, maxbytes, "%d", *conf->variable);
8850 struct config_real *conf = (struct config_real *) gconf;
8852 do_serialize(destptr, maxbytes, "%.*g",
8853 REALTYPE_PRECISION, *conf->variable);
8859 struct config_string *conf = (struct config_string *) gconf;
8861 do_serialize(destptr, maxbytes, "%s", *conf->variable);
8867 struct config_enum *conf = (struct config_enum *) gconf;
8869 do_serialize(destptr, maxbytes, "%s",
8870 config_enum_lookup_by_value(conf, *conf->variable));
8875 do_serialize(destptr, maxbytes, "%s",
8876 (gconf->sourcefile ? gconf->sourcefile : ""));
8878 if (gconf->sourcefile)
8879 do_serialize_binary(destptr, maxbytes, &gconf->sourceline,
8880 sizeof(gconf->sourceline));
8882 do_serialize_binary(destptr, maxbytes, &gconf->source,
8883 sizeof(gconf->source));
8884 do_serialize_binary(destptr, maxbytes, &gconf->scontext,
8885 sizeof(gconf->scontext));
8889 * SerializeGUCState:
8890 * Dumps the complete GUC state onto the memory location at start_address.
8893 SerializeGUCState(Size maxsize, char *start_address)
8901 /* Reserve space for saving the actual size of the guc state */
8902 Assert(maxsize > sizeof(actual_size));
8903 curptr = start_address + sizeof(actual_size);
8904 bytes_left = maxsize - sizeof(actual_size);
8906 for (i = 0; i < num_guc_variables; i++)
8909 * It's pretty ugly, but we've got to force "role" to be initialized
8910 * after "session_authorization"; otherwise, the latter will override
8913 if (strcmp(guc_variables[i]->name, "role") == 0)
8916 serialize_variable(&curptr, &bytes_left, guc_variables[i]);
8919 serialize_variable(&curptr, &bytes_left, guc_variables[i_role]);
8921 /* Store actual size without assuming alignment of start_address. */
8922 actual_size = maxsize - bytes_left - sizeof(actual_size);
8923 memcpy(start_address, &actual_size, sizeof(actual_size));
8928 * Actually it does not read anything, just returns the srcptr. But it does
8929 * move the srcptr past the terminating zero byte, so that the caller is ready
8930 * to read the next string.
8933 read_gucstate(char **srcptr, char *srcend)
8935 char *retptr = *srcptr;
8938 if (*srcptr >= srcend)
8939 elog(ERROR, "incomplete GUC state");
8941 /* The string variables are all null terminated */
8942 for (ptr = *srcptr; ptr < srcend && *ptr != '\0'; ptr++)
8946 elog(ERROR, "could not find null terminator in GUC state");
8948 /* Set the new position to the byte following the terminating NUL */
8954 /* Binary read version of read_gucstate(). Copies into dest */
8956 read_gucstate_binary(char **srcptr, char *srcend, void *dest, Size size)
8958 if (*srcptr + size > srcend)
8959 elog(ERROR, "incomplete GUC state");
8961 memcpy(dest, *srcptr, size);
8967 * Reads the GUC state at the specified address and updates the GUCs with the
8968 * values read from the GUC state.
8971 RestoreGUCState(void *gucstate)
8977 GucSource varsource;
8978 GucContext varscontext;
8979 char *srcptr = (char *) gucstate;
8984 /* See comment at can_skip_gucvar(). */
8985 for (i = 0; i < num_guc_variables; i++)
8986 if (!can_skip_gucvar(guc_variables[i]))
8987 InitializeOneGUCOption(guc_variables[i]);
8989 /* First item is the length of the subsequent data */
8990 memcpy(&len, gucstate, sizeof(len));
8992 srcptr += sizeof(len);
8993 srcend = srcptr + len;
8995 while (srcptr < srcend)
8999 if ((varname = read_gucstate(&srcptr, srcend)) == NULL)
9002 varvalue = read_gucstate(&srcptr, srcend);
9003 varsourcefile = read_gucstate(&srcptr, srcend);
9004 if (varsourcefile[0])
9005 read_gucstate_binary(&srcptr, srcend,
9006 &varsourceline, sizeof(varsourceline));
9007 read_gucstate_binary(&srcptr, srcend,
9008 &varsource, sizeof(varsource));
9009 read_gucstate_binary(&srcptr, srcend,
9010 &varscontext, sizeof(varscontext));
9012 result = set_config_option(varname, varvalue, varscontext, varsource,
9013 GUC_ACTION_SET, true, ERROR, true);
9016 (errcode(ERRCODE_INTERNAL_ERROR),
9017 errmsg("parameter \"%s\" could not be set", varname)));
9018 if (varsourcefile[0])
9019 set_config_sourcefile(varname, varsourcefile, varsourceline);
9024 * A little "long argument" simulation, although not quite GNU
9025 * compliant. Takes a string of the form "some-option=some value" and
9026 * returns name = "some_option" and value = "some value" in malloc'ed
9027 * storage. Note that '-' is converted to '_' in the option name. If
9028 * there is no '=' in the input string then value will be NULL.
9031 ParseLongOption(const char *string, char **name, char **value)
9040 equal_pos = strcspn(string, "=");
9042 if (string[equal_pos] == '=')
9044 *name = guc_malloc(FATAL, equal_pos + 1);
9045 strlcpy(*name, string, equal_pos + 1);
9047 *value = guc_strdup(FATAL, &string[equal_pos + 1]);
9051 /* no equal sign in string */
9052 *name = guc_strdup(FATAL, string);
9056 for (cp = *name; *cp; cp++)
9063 * Handle options fetched from pg_db_role_setting.setconfig,
9064 * pg_proc.proconfig, etc. Caller must specify proper context/source/action.
9066 * The array parameter must be an array of TEXT (it must not be NULL).
9069 ProcessGUCArray(ArrayType *array,
9070 GucContext context, GucSource source, GucAction action)
9074 Assert(array != NULL);
9075 Assert(ARR_ELEMTYPE(array) == TEXTOID);
9076 Assert(ARR_NDIM(array) == 1);
9077 Assert(ARR_LBOUND(array)[0] == 1);
9079 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9087 d = array_ref(array, 1, &i,
9088 -1 /* varlenarray */ ,
9089 -1 /* TEXT's typlen */ ,
9090 false /* TEXT's typbyval */ ,
9091 'i' /* TEXT's typalign */ ,
9097 s = TextDatumGetCString(d);
9099 ParseLongOption(s, &name, &value);
9103 (errcode(ERRCODE_SYNTAX_ERROR),
9104 errmsg("could not parse setting for parameter \"%s\"",
9110 (void) set_config_option(name, value,
9112 action, true, 0, false);
9123 * Add an entry to an option array. The array parameter may be NULL
9124 * to indicate the current table entry is NULL.
9127 GUCArrayAdd(ArrayType *array, const char *name, const char *value)
9129 struct config_generic *record;
9137 /* test if the option is valid and we're allowed to set it */
9138 (void) validate_option_array_item(name, value, false);
9140 /* normalize name (converts obsolete GUC names to modern spellings) */
9141 record = find_option(name, false, WARNING);
9143 name = record->name;
9145 /* build new item for array */
9146 newval = psprintf("%s=%s", name, value);
9147 datum = CStringGetTextDatum(newval);
9155 Assert(ARR_ELEMTYPE(array) == TEXTOID);
9156 Assert(ARR_NDIM(array) == 1);
9157 Assert(ARR_LBOUND(array)[0] == 1);
9159 index = ARR_DIMS(array)[0] + 1; /* add after end */
9161 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9166 d = array_ref(array, 1, &i,
9167 -1 /* varlenarray */ ,
9168 -1 /* TEXT's typlen */ ,
9169 false /* TEXT's typbyval */ ,
9170 'i' /* TEXT's typalign */ ,
9174 current = TextDatumGetCString(d);
9176 /* check for match up through and including '=' */
9177 if (strncmp(current, newval, strlen(name) + 1) == 0)
9184 a = array_set(array, 1, &index,
9187 -1 /* varlena array */ ,
9188 -1 /* TEXT's typlen */ ,
9189 false /* TEXT's typbyval */ ,
9190 'i' /* TEXT's typalign */ );
9193 a = construct_array(&datum, 1,
9202 * Delete an entry from an option array. The array parameter may be NULL
9203 * to indicate the current table entry is NULL. Also, if the return value
9204 * is NULL then a null should be stored.
9207 GUCArrayDelete(ArrayType *array, const char *name)
9209 struct config_generic *record;
9210 ArrayType *newarray;
9216 /* test if the option is valid and we're allowed to set it */
9217 (void) validate_option_array_item(name, NULL, false);
9219 /* normalize name (converts obsolete GUC names to modern spellings) */
9220 record = find_option(name, false, WARNING);
9222 name = record->name;
9224 /* if array is currently null, then surely nothing to delete */
9231 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9237 d = array_ref(array, 1, &i,
9238 -1 /* varlenarray */ ,
9239 -1 /* TEXT's typlen */ ,
9240 false /* TEXT's typbyval */ ,
9241 'i' /* TEXT's typalign */ ,
9245 val = TextDatumGetCString(d);
9247 /* ignore entry if it's what we want to delete */
9248 if (strncmp(val, name, strlen(name)) == 0
9249 && val[strlen(name)] == '=')
9252 /* else add it to the output array */
9254 newarray = array_set(newarray, 1, &index,
9257 -1 /* varlenarray */ ,
9258 -1 /* TEXT's typlen */ ,
9259 false /* TEXT's typbyval */ ,
9260 'i' /* TEXT's typalign */ );
9262 newarray = construct_array(&d, 1,
9274 * Given a GUC array, delete all settings from it that our permission
9275 * level allows: if superuser, delete them all; if regular user, only
9276 * those that are PGC_USERSET
9279 GUCArrayReset(ArrayType *array)
9281 ArrayType *newarray;
9285 /* if array is currently null, nothing to do */
9289 /* if we're superuser, we can delete everything, so just do it */
9296 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9303 d = array_ref(array, 1, &i,
9304 -1 /* varlenarray */ ,
9305 -1 /* TEXT's typlen */ ,
9306 false /* TEXT's typbyval */ ,
9307 'i' /* TEXT's typalign */ ,
9311 val = TextDatumGetCString(d);
9313 eqsgn = strchr(val, '=');
9316 /* skip if we have permission to delete it */
9317 if (validate_option_array_item(val, NULL, true))
9320 /* else add it to the output array */
9322 newarray = array_set(newarray, 1, &index,
9325 -1 /* varlenarray */ ,
9326 -1 /* TEXT's typlen */ ,
9327 false /* TEXT's typbyval */ ,
9328 'i' /* TEXT's typalign */ );
9330 newarray = construct_array(&d, 1,
9342 * Validate a proposed option setting for GUCArrayAdd/Delete/Reset.
9344 * name is the option name. value is the proposed value for the Add case,
9345 * or NULL for the Delete/Reset cases. If skipIfNoPermissions is true, it's
9346 * not an error to have no permissions to set the option.
9348 * Returns TRUE if OK, FALSE if skipIfNoPermissions is true and user does not
9349 * have permission to change this option (all other error cases result in an
9350 * error being thrown).
9353 validate_option_array_item(const char *name, const char *value,
9354 bool skipIfNoPermissions)
9357 struct config_generic *gconf;
9360 * There are three cases to consider:
9362 * name is a known GUC variable. Check the value normally, check
9363 * permissions normally (ie, allow if variable is USERSET, or if it's
9364 * SUSET and user is superuser).
9366 * name is not known, but exists or can be created as a placeholder (i.e.,
9367 * it has a prefixed name). We allow this case if you're a superuser,
9368 * otherwise not. Superusers are assumed to know what they're doing. We
9369 * can't allow it for other users, because when the placeholder is
9370 * resolved it might turn out to be a SUSET variable;
9371 * define_custom_variable assumes we checked that.
9373 * name is not known and can't be created as a placeholder. Throw error,
9374 * unless skipIfNoPermissions is true, in which case return FALSE.
9376 gconf = find_option(name, true, WARNING);
9379 /* not known, failed to make a placeholder */
9380 if (skipIfNoPermissions)
9383 (errcode(ERRCODE_UNDEFINED_OBJECT),
9384 errmsg("unrecognized configuration parameter \"%s\"",
9388 if (gconf->flags & GUC_CUSTOM_PLACEHOLDER)
9391 * We cannot do any meaningful check on the value, so only permissions
9392 * are useful to check.
9396 if (skipIfNoPermissions)
9399 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
9400 errmsg("permission denied to set parameter \"%s\"", name)));
9403 /* manual permissions check so we can avoid an error being thrown */
9404 if (gconf->context == PGC_USERSET)
9406 else if (gconf->context == PGC_SUSET && superuser())
9408 else if (skipIfNoPermissions)
9410 /* if a permissions error should be thrown, let set_config_option do it */
9412 /* test for permissions and valid option value */
9413 (void) set_config_option(name, value,
9414 superuser() ? PGC_SUSET : PGC_USERSET,
9415 PGC_S_TEST, GUC_ACTION_SET, false, 0, false);
9422 * Called by check_hooks that want to override the normal
9423 * ERRCODE_INVALID_PARAMETER_VALUE SQLSTATE for check hook failures.
9425 * Note that GUC_check_errmsg() etc are just macros that result in a direct
9426 * assignment to the associated variables. That is ugly, but forced by the
9427 * limitations of C's macro mechanisms.
9430 GUC_check_errcode(int sqlerrcode)
9432 GUC_check_errcode_value = sqlerrcode;
9437 * Convenience functions to manage calling a variable's check_hook.
9438 * These mostly take care of the protocol for letting check hooks supply
9439 * portions of the error report on failure.
9443 call_bool_check_hook(struct config_bool * conf, bool *newval, void **extra,
9444 GucSource source, int elevel)
9446 /* Quick success if no hook */
9447 if (!conf->check_hook)
9450 /* Reset variables that might be set by hook */
9451 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
9452 GUC_check_errmsg_string = NULL;
9453 GUC_check_errdetail_string = NULL;
9454 GUC_check_errhint_string = NULL;
9456 if (!(*conf->check_hook) (newval, extra, source))
9459 (errcode(GUC_check_errcode_value),
9460 GUC_check_errmsg_string ?
9461 errmsg_internal("%s", GUC_check_errmsg_string) :
9462 errmsg("invalid value for parameter \"%s\": %d",
9463 conf->gen.name, (int) *newval),
9464 GUC_check_errdetail_string ?
9465 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
9466 GUC_check_errhint_string ?
9467 errhint("%s", GUC_check_errhint_string) : 0));
9468 /* Flush any strings created in ErrorContext */
9477 call_int_check_hook(struct config_int * conf, int *newval, void **extra,
9478 GucSource source, int elevel)
9480 /* Quick success if no hook */
9481 if (!conf->check_hook)
9484 /* Reset variables that might be set by hook */
9485 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
9486 GUC_check_errmsg_string = NULL;
9487 GUC_check_errdetail_string = NULL;
9488 GUC_check_errhint_string = NULL;
9490 if (!(*conf->check_hook) (newval, extra, source))
9493 (errcode(GUC_check_errcode_value),
9494 GUC_check_errmsg_string ?
9495 errmsg_internal("%s", GUC_check_errmsg_string) :
9496 errmsg("invalid value for parameter \"%s\": %d",
9497 conf->gen.name, *newval),
9498 GUC_check_errdetail_string ?
9499 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
9500 GUC_check_errhint_string ?
9501 errhint("%s", GUC_check_errhint_string) : 0));
9502 /* Flush any strings created in ErrorContext */
9511 call_real_check_hook(struct config_real * conf, double *newval, void **extra,
9512 GucSource source, int elevel)
9514 /* Quick success if no hook */
9515 if (!conf->check_hook)
9518 /* Reset variables that might be set by hook */
9519 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
9520 GUC_check_errmsg_string = NULL;
9521 GUC_check_errdetail_string = NULL;
9522 GUC_check_errhint_string = NULL;
9524 if (!(*conf->check_hook) (newval, extra, source))
9527 (errcode(GUC_check_errcode_value),
9528 GUC_check_errmsg_string ?
9529 errmsg_internal("%s", GUC_check_errmsg_string) :
9530 errmsg("invalid value for parameter \"%s\": %g",
9531 conf->gen.name, *newval),
9532 GUC_check_errdetail_string ?
9533 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
9534 GUC_check_errhint_string ?
9535 errhint("%s", GUC_check_errhint_string) : 0));
9536 /* Flush any strings created in ErrorContext */
9545 call_string_check_hook(struct config_string * conf, char **newval, void **extra,
9546 GucSource source, int elevel)
9548 /* Quick success if no hook */
9549 if (!conf->check_hook)
9552 /* Reset variables that might be set by hook */
9553 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
9554 GUC_check_errmsg_string = NULL;
9555 GUC_check_errdetail_string = NULL;
9556 GUC_check_errhint_string = NULL;
9558 if (!(*conf->check_hook) (newval, extra, source))
9561 (errcode(GUC_check_errcode_value),
9562 GUC_check_errmsg_string ?
9563 errmsg_internal("%s", GUC_check_errmsg_string) :
9564 errmsg("invalid value for parameter \"%s\": \"%s\"",
9565 conf->gen.name, *newval ? *newval : ""),
9566 GUC_check_errdetail_string ?
9567 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
9568 GUC_check_errhint_string ?
9569 errhint("%s", GUC_check_errhint_string) : 0));
9570 /* Flush any strings created in ErrorContext */
9579 call_enum_check_hook(struct config_enum * conf, int *newval, void **extra,
9580 GucSource source, int elevel)
9582 /* Quick success if no hook */
9583 if (!conf->check_hook)
9586 /* Reset variables that might be set by hook */
9587 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
9588 GUC_check_errmsg_string = NULL;
9589 GUC_check_errdetail_string = NULL;
9590 GUC_check_errhint_string = NULL;
9592 if (!(*conf->check_hook) (newval, extra, source))
9595 (errcode(GUC_check_errcode_value),
9596 GUC_check_errmsg_string ?
9597 errmsg_internal("%s", GUC_check_errmsg_string) :
9598 errmsg("invalid value for parameter \"%s\": \"%s\"",
9600 config_enum_lookup_by_value(conf, *newval)),
9601 GUC_check_errdetail_string ?
9602 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
9603 GUC_check_errhint_string ?
9604 errhint("%s", GUC_check_errhint_string) : 0));
9605 /* Flush any strings created in ErrorContext */
9615 * check_hook, assign_hook and show_hook subroutines
9619 check_log_destination(char **newval, void **extra, GucSource source)
9627 /* Need a modifiable copy of string */
9628 rawstring = pstrdup(*newval);
9630 /* Parse string into list of identifiers */
9631 if (!SplitIdentifierString(rawstring, ',', &elemlist))
9633 /* syntax error in list */
9634 GUC_check_errdetail("List syntax is invalid.");
9636 list_free(elemlist);
9640 foreach(l, elemlist)
9642 char *tok = (char *) lfirst(l);
9644 if (pg_strcasecmp(tok, "stderr") == 0)
9645 newlogdest |= LOG_DESTINATION_STDERR;
9646 else if (pg_strcasecmp(tok, "csvlog") == 0)
9647 newlogdest |= LOG_DESTINATION_CSVLOG;
9649 else if (pg_strcasecmp(tok, "syslog") == 0)
9650 newlogdest |= LOG_DESTINATION_SYSLOG;
9653 else if (pg_strcasecmp(tok, "eventlog") == 0)
9654 newlogdest |= LOG_DESTINATION_EVENTLOG;
9658 GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
9660 list_free(elemlist);
9666 list_free(elemlist);
9668 myextra = (int *) guc_malloc(ERROR, sizeof(int));
9669 *myextra = newlogdest;
9670 *extra = (void *) myextra;
9676 assign_log_destination(const char *newval, void *extra)
9678 Log_destination = *((int *) extra);
9682 assign_syslog_facility(int newval, void *extra)
9685 set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
9688 /* Without syslog support, just ignore it */
9692 assign_syslog_ident(const char *newval, void *extra)
9695 set_syslog_parameters(newval, syslog_facility);
9697 /* Without syslog support, it will always be set to "none", so ignore */
9702 assign_session_replication_role(int newval, void *extra)
9705 * Must flush the plan cache when changing replication role; but don't
9706 * flush unnecessarily.
9708 if (SessionReplicationRole != newval)
9713 check_temp_buffers(int *newval, void **extra, GucSource source)
9716 * Once local buffers have been initialized, it's too late to change this.
9718 if (NLocBuffer && NLocBuffer != *newval)
9720 GUC_check_errdetail("\"temp_buffers\" cannot be changed after any temporary tables have been accessed in the session.");
9727 check_bonjour(bool *newval, void **extra, GucSource source)
9732 GUC_check_errmsg("Bonjour is not supported by this build");
9740 check_ssl(bool *newval, void **extra, GucSource source)
9745 GUC_check_errmsg("SSL is not supported by this build");
9753 check_stage_log_stats(bool *newval, void **extra, GucSource source)
9755 if (*newval && log_statement_stats)
9757 GUC_check_errdetail("Cannot enable parameter when \"log_statement_stats\" is true.");
9764 check_log_stats(bool *newval, void **extra, GucSource source)
9767 (log_parser_stats || log_planner_stats || log_executor_stats))
9769 GUC_check_errdetail("Cannot enable \"log_statement_stats\" when "
9770 "\"log_parser_stats\", \"log_planner_stats\", "
9771 "or \"log_executor_stats\" is true.");
9778 check_canonical_path(char **newval, void **extra, GucSource source)
9781 * Since canonicalize_path never enlarges the string, we can just modify
9782 * newval in-place. But watch out for NULL, which is the default value
9783 * for external_pid_file.
9786 canonicalize_path(*newval);
9791 check_timezone_abbreviations(char **newval, void **extra, GucSource source)
9794 * The boot_val given above for timezone_abbreviations is NULL. When we
9795 * see this we just do nothing. If this value isn't overridden from the
9796 * config file then pg_timezone_abbrev_initialize() will eventually
9797 * replace it with "Default". This hack has two purposes: to avoid
9798 * wasting cycles loading values that might soon be overridden from the
9799 * config file, and to avoid trying to read the timezone abbrev files
9800 * during InitializeGUCOptions(). The latter doesn't work in an
9801 * EXEC_BACKEND subprocess because my_exec_path hasn't been set yet and so
9802 * we can't locate PGSHAREDIR.
9804 if (*newval == NULL)
9806 Assert(source == PGC_S_DEFAULT);
9810 /* OK, load the file and produce a malloc'd TimeZoneAbbrevTable */
9811 *extra = load_tzoffsets(*newval);
9813 /* tzparser.c returns NULL on failure, reporting via GUC_check_errmsg */
9821 assign_timezone_abbreviations(const char *newval, void *extra)
9823 /* Do nothing for the boot_val default of NULL */
9827 InstallTimeZoneAbbrevs((TimeZoneAbbrevTable *) extra);
9831 * pg_timezone_abbrev_initialize --- set default value if not done already
9833 * This is called after initial loading of postgresql.conf. If no
9834 * timezone_abbreviations setting was found therein, select default.
9835 * If a non-default value is already installed, nothing will happen.
9837 * This can also be called from ProcessConfigFile to establish the default
9838 * value after a postgresql.conf entry for it is removed.
9841 pg_timezone_abbrev_initialize(void)
9843 SetConfigOption("timezone_abbreviations", "Default",
9844 PGC_POSTMASTER, PGC_S_DYNAMIC_DEFAULT);
9848 show_archive_command(void)
9850 if (XLogArchivingActive())
9851 return XLogArchiveCommand;
9853 return "(disabled)";
9857 assign_tcp_keepalives_idle(int newval, void *extra)
9860 * The kernel API provides no way to test a value without setting it; and
9861 * once we set it we might fail to unset it. So there seems little point
9862 * in fully implementing the check-then-assign GUC API for these
9863 * variables. Instead we just do the assignment on demand. pqcomm.c
9864 * reports any problems via elog(LOG).
9866 * This approach means that the GUC value might have little to do with the
9867 * actual kernel value, so we use a show_hook that retrieves the kernel
9868 * value rather than trusting GUC's copy.
9870 (void) pq_setkeepalivesidle(newval, MyProcPort);
9874 show_tcp_keepalives_idle(void)
9876 /* See comments in assign_tcp_keepalives_idle */
9877 static char nbuf[16];
9879 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesidle(MyProcPort));
9884 assign_tcp_keepalives_interval(int newval, void *extra)
9886 /* See comments in assign_tcp_keepalives_idle */
9887 (void) pq_setkeepalivesinterval(newval, MyProcPort);
9891 show_tcp_keepalives_interval(void)
9893 /* See comments in assign_tcp_keepalives_idle */
9894 static char nbuf[16];
9896 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesinterval(MyProcPort));
9901 assign_tcp_keepalives_count(int newval, void *extra)
9903 /* See comments in assign_tcp_keepalives_idle */
9904 (void) pq_setkeepalivescount(newval, MyProcPort);
9908 show_tcp_keepalives_count(void)
9910 /* See comments in assign_tcp_keepalives_idle */
9911 static char nbuf[16];
9913 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivescount(MyProcPort));
9918 check_maxconnections(int *newval, void **extra, GucSource source)
9920 if (*newval + autovacuum_max_workers + 1 +
9921 max_worker_processes > MAX_BACKENDS)
9927 check_autovacuum_max_workers(int *newval, void **extra, GucSource source)
9929 if (MaxConnections + *newval + 1 + max_worker_processes > MAX_BACKENDS)
9935 check_autovacuum_work_mem(int *newval, void **extra, GucSource source)
9938 * -1 indicates fallback.
9940 * If we haven't yet changed the boot_val default of -1, just let it be.
9941 * Autovacuum will look to maintenance_work_mem instead.
9947 * We clamp manually-set values to at least 1MB. Since
9948 * maintenance_work_mem is always set to at least this value, do the same
9958 check_max_worker_processes(int *newval, void **extra, GucSource source)
9960 if (MaxConnections + autovacuum_max_workers + 1 + *newval > MAX_BACKENDS)
9966 check_effective_io_concurrency(int *newval, void **extra, GucSource source)
9969 double new_prefetch_pages;
9971 if (ComputeIoConcurrency(*newval, &new_prefetch_pages))
9973 int *myextra = (int *) guc_malloc(ERROR, sizeof(int));
9975 *myextra = (int) rint(new_prefetch_pages);
9976 *extra = (void *) myextra;
9984 #endif /* USE_PREFETCH */
9988 assign_effective_io_concurrency(int newval, void *extra)
9991 target_prefetch_pages = *((int *) extra);
9992 #endif /* USE_PREFETCH */
9996 assign_pgstat_temp_directory(const char *newval, void *extra)
9998 /* check_canonical_path already canonicalized newval for us */
10004 dname = guc_malloc(ERROR, strlen(newval) + 1); /* runtime dir */
10005 sprintf(dname, "%s", newval);
10008 tname = guc_malloc(ERROR, strlen(newval) + 12); /* /global.tmp */
10009 sprintf(tname, "%s/global.tmp", newval);
10010 fname = guc_malloc(ERROR, strlen(newval) + 13); /* /global.stat */
10011 sprintf(fname, "%s/global.stat", newval);
10013 if (pgstat_stat_directory)
10014 free(pgstat_stat_directory);
10015 pgstat_stat_directory = dname;
10016 if (pgstat_stat_tmpname)
10017 free(pgstat_stat_tmpname);
10018 pgstat_stat_tmpname = tname;
10019 if (pgstat_stat_filename)
10020 free(pgstat_stat_filename);
10021 pgstat_stat_filename = fname;
10025 check_application_name(char **newval, void **extra, GucSource source)
10027 /* Only allow clean ASCII chars in the application name */
10030 for (p = *newval; *p; p++)
10032 if (*p < 32 || *p > 126)
10040 assign_application_name(const char *newval, void *extra)
10042 /* Update the pg_stat_activity view */
10043 pgstat_report_appname(newval);
10047 check_cluster_name(char **newval, void **extra, GucSource source)
10049 /* Only allow clean ASCII chars in the cluster name */
10052 for (p = *newval; *p; p++)
10054 if (*p < 32 || *p > 126)
10061 static const char *
10062 show_unix_socket_permissions(void)
10064 static char buf[8];
10066 snprintf(buf, sizeof(buf), "%04o", Unix_socket_permissions);
10070 static const char *
10071 show_log_file_mode(void)
10073 static char buf[8];
10075 snprintf(buf, sizeof(buf), "%04o", Log_file_mode);
10079 #include "guc-file.c"