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, 100000, 2000000000,
2517 /* see multixact.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, 10000, 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 {"max_parallel_degree", PGC_SUSET, RESOURCES_ASYNCHRONOUS,
2539 gettext_noop("Sets the maximum number of parallel processes per executor node."),
2542 &max_parallel_degree,
2548 {"autovacuum_work_mem", PGC_SIGHUP, RESOURCES_MEM,
2549 gettext_noop("Sets the maximum memory to be used by each autovacuum worker process."),
2553 &autovacuum_work_mem,
2554 -1, -1, MAX_KILOBYTES,
2555 check_autovacuum_work_mem, NULL, NULL
2559 {"tcp_keepalives_idle", PGC_USERSET, CLIENT_CONN_OTHER,
2560 gettext_noop("Time between issuing TCP keepalives."),
2561 gettext_noop("A value of 0 uses the system default."),
2564 &tcp_keepalives_idle,
2566 NULL, assign_tcp_keepalives_idle, show_tcp_keepalives_idle
2570 {"tcp_keepalives_interval", PGC_USERSET, CLIENT_CONN_OTHER,
2571 gettext_noop("Time between TCP keepalive retransmits."),
2572 gettext_noop("A value of 0 uses the system default."),
2575 &tcp_keepalives_interval,
2577 NULL, assign_tcp_keepalives_interval, show_tcp_keepalives_interval
2581 {"tcp_keepalives_count", PGC_USERSET, CLIENT_CONN_OTHER,
2582 gettext_noop("Maximum number of TCP keepalive retransmits."),
2583 gettext_noop("This controls the number of consecutive keepalive retransmits that can be "
2584 "lost before a connection is considered dead. A value of 0 uses the "
2587 &tcp_keepalives_count,
2589 NULL, assign_tcp_keepalives_count, show_tcp_keepalives_count
2593 {"gin_fuzzy_search_limit", PGC_USERSET, CLIENT_CONN_OTHER,
2594 gettext_noop("Sets the maximum allowed result for exact search by GIN."),
2598 &GinFuzzySearchLimit,
2604 {"effective_cache_size", PGC_USERSET, QUERY_TUNING_COST,
2605 gettext_noop("Sets the planner's assumption about the size of the disk cache."),
2606 gettext_noop("That is, the portion of the kernel's disk cache that "
2607 "will be used for PostgreSQL data files. This is measured in disk "
2608 "pages, which are normally 8 kB each."),
2611 &effective_cache_size,
2612 DEFAULT_EFFECTIVE_CACHE_SIZE, 1, INT_MAX,
2617 /* Can't be set in postgresql.conf */
2618 {"server_version_num", PGC_INTERNAL, PRESET_OPTIONS,
2619 gettext_noop("Shows the server version as an integer."),
2621 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2623 &server_version_num,
2624 PG_VERSION_NUM, PG_VERSION_NUM, PG_VERSION_NUM,
2629 {"log_temp_files", PGC_SUSET, LOGGING_WHAT,
2630 gettext_noop("Log the use of temporary files larger than this number of kilobytes."),
2631 gettext_noop("Zero logs all files. The default is -1 (turning this feature off)."),
2640 {"track_activity_query_size", PGC_POSTMASTER, RESOURCES_MEM,
2641 gettext_noop("Sets the size reserved for pg_stat_activity.query, in bytes."),
2645 * There is no _bytes_ unit, so the user can't supply units for
2649 &pgstat_track_activity_query_size,
2655 {"gin_pending_list_limit", PGC_USERSET, CLIENT_CONN_STATEMENT,
2656 gettext_noop("Sets the maximum size of the pending list for GIN index."),
2660 &gin_pending_list_limit,
2661 4096, 64, MAX_KILOBYTES,
2665 /* End-of-list marker */
2667 {NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL, NULL
2672 static struct config_real ConfigureNamesReal[] =
2675 {"seq_page_cost", PGC_USERSET, QUERY_TUNING_COST,
2676 gettext_noop("Sets the planner's estimate of the cost of a "
2677 "sequentially fetched disk page."),
2681 DEFAULT_SEQ_PAGE_COST, 0, DBL_MAX,
2685 {"random_page_cost", PGC_USERSET, QUERY_TUNING_COST,
2686 gettext_noop("Sets the planner's estimate of the cost of a "
2687 "nonsequentially fetched disk page."),
2691 DEFAULT_RANDOM_PAGE_COST, 0, DBL_MAX,
2695 {"cpu_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
2696 gettext_noop("Sets the planner's estimate of the cost of "
2697 "processing each tuple (row)."),
2701 DEFAULT_CPU_TUPLE_COST, 0, DBL_MAX,
2705 {"cpu_index_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
2706 gettext_noop("Sets the planner's estimate of the cost of "
2707 "processing each index entry during an index scan."),
2710 &cpu_index_tuple_cost,
2711 DEFAULT_CPU_INDEX_TUPLE_COST, 0, DBL_MAX,
2715 {"cpu_operator_cost", PGC_USERSET, QUERY_TUNING_COST,
2716 gettext_noop("Sets the planner's estimate of the cost of "
2717 "processing each operator or function call."),
2721 DEFAULT_CPU_OPERATOR_COST, 0, DBL_MAX,
2725 {"parallel_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
2726 gettext_noop("Sets the planner's estimate of the cost of "
2727 "passing each tuple (row) from worker to master backend."),
2730 ¶llel_tuple_cost,
2731 DEFAULT_PARALLEL_TUPLE_COST, 0, DBL_MAX,
2735 {"parallel_setup_cost", PGC_USERSET, QUERY_TUNING_COST,
2736 gettext_noop("Sets the planner's estimate of the cost of "
2737 "starting up worker processes for parallel query."),
2740 ¶llel_setup_cost,
2741 DEFAULT_PARALLEL_SETUP_COST, 0, DBL_MAX,
2746 {"cursor_tuple_fraction", PGC_USERSET, QUERY_TUNING_OTHER,
2747 gettext_noop("Sets the planner's estimate of the fraction of "
2748 "a cursor's rows that will be retrieved."),
2751 &cursor_tuple_fraction,
2752 DEFAULT_CURSOR_TUPLE_FRACTION, 0.0, 1.0,
2757 {"geqo_selection_bias", PGC_USERSET, QUERY_TUNING_GEQO,
2758 gettext_noop("GEQO: selective pressure within the population."),
2761 &Geqo_selection_bias,
2762 DEFAULT_GEQO_SELECTION_BIAS,
2763 MIN_GEQO_SELECTION_BIAS, MAX_GEQO_SELECTION_BIAS,
2767 {"geqo_seed", PGC_USERSET, QUERY_TUNING_GEQO,
2768 gettext_noop("GEQO: seed for random path selection."),
2777 {"bgwriter_lru_multiplier", PGC_SIGHUP, RESOURCES_BGWRITER,
2778 gettext_noop("Multiple of the average buffer usage to free per round."),
2781 &bgwriter_lru_multiplier,
2787 {"seed", PGC_USERSET, UNGROUPED,
2788 gettext_noop("Sets the seed for random-number generation."),
2790 GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2794 check_random_seed, assign_random_seed, show_random_seed
2798 {"autovacuum_vacuum_scale_factor", PGC_SIGHUP, AUTOVACUUM,
2799 gettext_noop("Number of tuple updates or deletes prior to vacuum as a fraction of reltuples."),
2802 &autovacuum_vac_scale,
2807 {"autovacuum_analyze_scale_factor", PGC_SIGHUP, AUTOVACUUM,
2808 gettext_noop("Number of tuple inserts, updates, or deletes prior to analyze as a fraction of reltuples."),
2811 &autovacuum_anl_scale,
2817 {"checkpoint_completion_target", PGC_SIGHUP, WAL_CHECKPOINTS,
2818 gettext_noop("Time spent flushing dirty buffers during checkpoint, as fraction of checkpoint interval."),
2821 &CheckPointCompletionTarget,
2826 /* End-of-list marker */
2828 {NULL, 0, 0, NULL, NULL}, NULL, 0.0, 0.0, 0.0, NULL, NULL, NULL
2833 static struct config_string ConfigureNamesString[] =
2836 {"archive_command", PGC_SIGHUP, WAL_ARCHIVING,
2837 gettext_noop("Sets the shell command that will be called to archive a WAL file."),
2840 &XLogArchiveCommand,
2842 NULL, NULL, show_archive_command
2846 {"client_encoding", PGC_USERSET, CLIENT_CONN_LOCALE,
2847 gettext_noop("Sets the client's character set encoding."),
2849 GUC_IS_NAME | GUC_REPORT
2851 &client_encoding_string,
2853 check_client_encoding, assign_client_encoding, NULL
2857 {"log_line_prefix", PGC_SIGHUP, LOGGING_WHAT,
2858 gettext_noop("Controls information prefixed to each log line."),
2859 gettext_noop("If blank, no prefix is used.")
2867 {"log_timezone", PGC_SIGHUP, LOGGING_WHAT,
2868 gettext_noop("Sets the time zone to use in log messages."),
2871 &log_timezone_string,
2873 check_log_timezone, assign_log_timezone, show_log_timezone
2877 {"DateStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
2878 gettext_noop("Sets the display format for date and time values."),
2879 gettext_noop("Also controls interpretation of ambiguous "
2881 GUC_LIST_INPUT | GUC_REPORT
2885 check_datestyle, assign_datestyle, NULL
2889 {"default_tablespace", PGC_USERSET, CLIENT_CONN_STATEMENT,
2890 gettext_noop("Sets the default tablespace to create tables and indexes in."),
2891 gettext_noop("An empty string selects the database's default tablespace."),
2894 &default_tablespace,
2896 check_default_tablespace, NULL, NULL
2900 {"temp_tablespaces", PGC_USERSET, CLIENT_CONN_STATEMENT,
2901 gettext_noop("Sets the tablespace(s) to use for temporary tables and sort files."),
2903 GUC_LIST_INPUT | GUC_LIST_QUOTE
2907 check_temp_tablespaces, assign_temp_tablespaces, NULL
2911 {"dynamic_library_path", PGC_SUSET, CLIENT_CONN_OTHER,
2912 gettext_noop("Sets the path for dynamically loadable modules."),
2913 gettext_noop("If a dynamically loadable module needs to be opened and "
2914 "the specified name does not have a directory component (i.e., the "
2915 "name does not contain a slash), the system will search this path for "
2916 "the specified file."),
2919 &Dynamic_library_path,
2925 {"krb_server_keyfile", PGC_SIGHUP, CONN_AUTH_SECURITY,
2926 gettext_noop("Sets the location of the Kerberos server key file."),
2930 &pg_krb_server_keyfile,
2936 {"bonjour_name", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2937 gettext_noop("Sets the Bonjour service name."),
2945 /* See main.c about why defaults for LC_foo are not all alike */
2948 {"lc_collate", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2949 gettext_noop("Shows the collation order locale."),
2951 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2959 {"lc_ctype", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2960 gettext_noop("Shows the character classification and case conversion locale."),
2962 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2970 {"lc_messages", PGC_SUSET, CLIENT_CONN_LOCALE,
2971 gettext_noop("Sets the language in which messages are displayed."),
2976 check_locale_messages, assign_locale_messages, NULL
2980 {"lc_monetary", PGC_USERSET, CLIENT_CONN_LOCALE,
2981 gettext_noop("Sets the locale for formatting monetary amounts."),
2986 check_locale_monetary, assign_locale_monetary, NULL
2990 {"lc_numeric", PGC_USERSET, CLIENT_CONN_LOCALE,
2991 gettext_noop("Sets the locale for formatting numbers."),
2996 check_locale_numeric, assign_locale_numeric, NULL
3000 {"lc_time", PGC_USERSET, CLIENT_CONN_LOCALE,
3001 gettext_noop("Sets the locale for formatting date and time values."),
3006 check_locale_time, assign_locale_time, NULL
3010 {"session_preload_libraries", PGC_SUSET, CLIENT_CONN_PRELOAD,
3011 gettext_noop("Lists shared libraries to preload into each backend."),
3013 GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
3015 &session_preload_libraries_string,
3021 {"shared_preload_libraries", PGC_POSTMASTER, CLIENT_CONN_PRELOAD,
3022 gettext_noop("Lists shared libraries to preload into server."),
3024 GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
3026 &shared_preload_libraries_string,
3032 {"local_preload_libraries", PGC_USERSET, CLIENT_CONN_PRELOAD,
3033 gettext_noop("Lists unprivileged shared libraries to preload into each backend."),
3035 GUC_LIST_INPUT | GUC_LIST_QUOTE
3037 &local_preload_libraries_string,
3043 {"search_path", PGC_USERSET, CLIENT_CONN_STATEMENT,
3044 gettext_noop("Sets the schema search order for names that are not schema-qualified."),
3046 GUC_LIST_INPUT | GUC_LIST_QUOTE
3048 &namespace_search_path,
3049 "\"$user\", public",
3050 check_search_path, assign_search_path, NULL
3054 /* Can't be set in postgresql.conf */
3055 {"server_encoding", PGC_INTERNAL, CLIENT_CONN_LOCALE,
3056 gettext_noop("Sets the server (database) character set encoding."),
3058 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
3060 &server_encoding_string,
3066 /* Can't be set in postgresql.conf */
3067 {"server_version", PGC_INTERNAL, PRESET_OPTIONS,
3068 gettext_noop("Shows the server version."),
3070 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
3072 &server_version_string,
3078 /* Not for general use --- used by SET ROLE */
3079 {"role", PGC_USERSET, UNGROUPED,
3080 gettext_noop("Sets the current role."),
3082 GUC_IS_NAME | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_NOT_WHILE_SEC_REST
3086 check_role, assign_role, show_role
3090 /* Not for general use --- used by SET SESSION AUTHORIZATION */
3091 {"session_authorization", PGC_USERSET, UNGROUPED,
3092 gettext_noop("Sets the session user name."),
3094 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
3096 &session_authorization_string,
3098 check_session_authorization, assign_session_authorization, NULL
3102 {"log_destination", PGC_SIGHUP, LOGGING_WHERE,
3103 gettext_noop("Sets the destination for server log output."),
3104 gettext_noop("Valid values are combinations of \"stderr\", "
3105 "\"syslog\", \"csvlog\", and \"eventlog\", "
3106 "depending on the platform."),
3109 &Log_destination_string,
3111 check_log_destination, assign_log_destination, NULL
3114 {"log_directory", PGC_SIGHUP, LOGGING_WHERE,
3115 gettext_noop("Sets the destination directory for log files."),
3116 gettext_noop("Can be specified as relative to the data directory "
3117 "or as absolute path."),
3122 check_canonical_path, NULL, NULL
3125 {"log_filename", PGC_SIGHUP, LOGGING_WHERE,
3126 gettext_noop("Sets the file name pattern for log files."),
3131 "postgresql-%Y-%m-%d_%H%M%S.log",
3136 {"syslog_ident", PGC_SIGHUP, LOGGING_WHERE,
3137 gettext_noop("Sets the program name used to identify PostgreSQL "
3138 "messages in syslog."),
3143 NULL, assign_syslog_ident, NULL
3147 {"event_source", PGC_POSTMASTER, LOGGING_WHERE,
3148 gettext_noop("Sets the application name used to identify "
3149 "PostgreSQL messages in the event log."),
3153 DEFAULT_EVENT_SOURCE,
3158 {"TimeZone", PGC_USERSET, CLIENT_CONN_LOCALE,
3159 gettext_noop("Sets the time zone for displaying and interpreting time stamps."),
3165 check_timezone, assign_timezone, show_timezone
3168 {"timezone_abbreviations", PGC_USERSET, CLIENT_CONN_LOCALE,
3169 gettext_noop("Selects a file of time zone abbreviations."),
3172 &timezone_abbreviations_string,
3174 check_timezone_abbreviations, assign_timezone_abbreviations, NULL
3178 {"transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
3179 gettext_noop("Sets the current transaction's isolation level."),
3181 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
3183 &XactIsoLevel_string,
3185 check_XactIsoLevel, assign_XactIsoLevel, show_XactIsoLevel
3189 {"unix_socket_group", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
3190 gettext_noop("Sets the owning group of the Unix-domain socket."),
3191 gettext_noop("The owning user of the socket is always the user "
3192 "that starts the server.")
3200 {"unix_socket_directories", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
3201 gettext_noop("Sets the directories where Unix-domain sockets will be created."),
3205 &Unix_socket_directories,
3206 #ifdef HAVE_UNIX_SOCKETS
3207 DEFAULT_PGSOCKET_DIR,
3215 {"listen_addresses", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
3216 gettext_noop("Sets the host name or IP address(es) to listen to."),
3227 * Can't be set by ALTER SYSTEM as it can lead to recursive definition
3228 * of data_directory.
3230 {"data_directory", PGC_POSTMASTER, FILE_LOCATIONS,
3231 gettext_noop("Sets the server's data directory."),
3233 GUC_SUPERUSER_ONLY | GUC_DISALLOW_IN_AUTO_FILE
3241 {"config_file", PGC_POSTMASTER, FILE_LOCATIONS,
3242 gettext_noop("Sets the server's main configuration file."),
3244 GUC_DISALLOW_IN_FILE | GUC_SUPERUSER_ONLY
3252 {"hba_file", PGC_POSTMASTER, FILE_LOCATIONS,
3253 gettext_noop("Sets the server's \"hba\" configuration file."),
3263 {"ident_file", PGC_POSTMASTER, FILE_LOCATIONS,
3264 gettext_noop("Sets the server's \"ident\" configuration file."),
3274 {"external_pid_file", PGC_POSTMASTER, FILE_LOCATIONS,
3275 gettext_noop("Writes the postmaster PID to the specified file."),
3281 check_canonical_path, NULL, NULL
3285 {"ssl_cert_file", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3286 gettext_noop("Location of the SSL server certificate file."),
3295 {"ssl_key_file", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3296 gettext_noop("Location of the SSL server private key file."),
3305 {"ssl_ca_file", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3306 gettext_noop("Location of the SSL certificate authority file."),
3315 {"ssl_crl_file", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3316 gettext_noop("Location of the SSL certificate revocation list file."),
3325 {"stats_temp_directory", PGC_SIGHUP, STATS_COLLECTOR,
3326 gettext_noop("Writes temporary statistics files to the specified directory."),
3330 &pgstat_temp_directory,
3332 check_canonical_path, assign_pgstat_temp_directory, NULL
3336 {"synchronous_standby_names", PGC_SIGHUP, REPLICATION_MASTER,
3337 gettext_noop("List of names of potential synchronous standbys."),
3341 &SyncRepStandbyNames,
3343 check_synchronous_standby_names, NULL, NULL
3347 {"default_text_search_config", PGC_USERSET, CLIENT_CONN_LOCALE,
3348 gettext_noop("Sets default text search configuration."),
3352 "pg_catalog.simple",
3353 check_TSCurrentConfig, assign_TSCurrentConfig, NULL
3357 {"ssl_ciphers", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3358 gettext_noop("Sets the list of allowed SSL ciphers."),
3364 "HIGH:MEDIUM:+3DES:!aNULL",
3372 {"ssl_ecdh_curve", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3373 gettext_noop("Sets the curve to use for ECDH."),
3387 {"application_name", PGC_USERSET, LOGGING_WHAT,
3388 gettext_noop("Sets the application name to be reported in statistics and logs."),
3390 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE
3394 check_application_name, assign_application_name, NULL
3398 {"cluster_name", PGC_POSTMASTER, LOGGING_WHAT,
3399 gettext_noop("Sets the name of the cluster which is included in the process title."),
3405 check_cluster_name, NULL, NULL
3408 /* End-of-list marker */
3410 {NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL, NULL
3415 static struct config_enum ConfigureNamesEnum[] =
3418 {"backslash_quote", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
3419 gettext_noop("Sets whether \"\\'\" is allowed in string literals."),
3423 BACKSLASH_QUOTE_SAFE_ENCODING, backslash_quote_options,
3428 {"bytea_output", PGC_USERSET, CLIENT_CONN_STATEMENT,
3429 gettext_noop("Sets the output format for bytea."),
3433 BYTEA_OUTPUT_HEX, bytea_output_options,
3438 {"client_min_messages", PGC_USERSET, LOGGING_WHEN,
3439 gettext_noop("Sets the message levels that are sent to the client."),
3440 gettext_noop("Each level includes all the levels that follow it. The later"
3441 " the level, the fewer messages are sent.")
3443 &client_min_messages,
3444 NOTICE, client_message_level_options,
3449 {"constraint_exclusion", PGC_USERSET, QUERY_TUNING_OTHER,
3450 gettext_noop("Enables the planner to use constraints to optimize queries."),
3451 gettext_noop("Table scans will be skipped if their constraints"
3452 " guarantee that no rows match the query.")
3454 &constraint_exclusion,
3455 CONSTRAINT_EXCLUSION_PARTITION, constraint_exclusion_options,
3460 {"default_transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
3461 gettext_noop("Sets the transaction isolation level of each new transaction."),
3464 &DefaultXactIsoLevel,
3465 XACT_READ_COMMITTED, isolation_level_options,
3470 {"IntervalStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
3471 gettext_noop("Sets the display format for interval values."),
3476 INTSTYLE_POSTGRES, intervalstyle_options,
3481 {"log_error_verbosity", PGC_SUSET, LOGGING_WHAT,
3482 gettext_noop("Sets the verbosity of logged messages."),
3485 &Log_error_verbosity,
3486 PGERROR_DEFAULT, log_error_verbosity_options,
3491 {"log_min_messages", PGC_SUSET, LOGGING_WHEN,
3492 gettext_noop("Sets the message levels that are logged."),
3493 gettext_noop("Each level includes all the levels that follow it. The later"
3494 " the level, the fewer messages are sent.")
3497 WARNING, server_message_level_options,
3502 {"log_min_error_statement", PGC_SUSET, LOGGING_WHEN,
3503 gettext_noop("Causes all statements generating error at or above this level to be logged."),
3504 gettext_noop("Each level includes all the levels that follow it. The later"
3505 " the level, the fewer messages are sent.")
3507 &log_min_error_statement,
3508 ERROR, server_message_level_options,
3513 {"log_statement", PGC_SUSET, LOGGING_WHAT,
3514 gettext_noop("Sets the type of statements logged."),
3518 LOGSTMT_NONE, log_statement_options,
3523 {"syslog_facility", PGC_SIGHUP, LOGGING_WHERE,
3524 gettext_noop("Sets the syslog \"facility\" to be used when syslog enabled."),
3533 syslog_facility_options,
3534 NULL, assign_syslog_facility, NULL
3538 {"session_replication_role", PGC_SUSET, CLIENT_CONN_STATEMENT,
3539 gettext_noop("Sets the session's behavior for triggers and rewrite rules."),
3542 &SessionReplicationRole,
3543 SESSION_REPLICATION_ROLE_ORIGIN, session_replication_role_options,
3544 NULL, assign_session_replication_role, NULL
3548 {"synchronous_commit", PGC_USERSET, WAL_SETTINGS,
3549 gettext_noop("Sets the current transaction's synchronization level."),
3552 &synchronous_commit,
3553 SYNCHRONOUS_COMMIT_ON, synchronous_commit_options,
3554 NULL, assign_synchronous_commit, NULL
3558 {"archive_mode", PGC_POSTMASTER, WAL_ARCHIVING,
3559 gettext_noop("Allows archiving of WAL files using archive_command."),
3563 ARCHIVE_MODE_OFF, archive_mode_options,
3568 {"trace_recovery_messages", PGC_SIGHUP, DEVELOPER_OPTIONS,
3569 gettext_noop("Enables logging of recovery-related debugging information."),
3570 gettext_noop("Each level includes all the levels that follow it. The later"
3571 " the level, the fewer messages are sent.")
3573 &trace_recovery_messages,
3576 * client_message_level_options allows too many values, really, but
3577 * it's not worth having a separate options array for this.
3579 LOG, client_message_level_options,
3584 {"track_functions", PGC_SUSET, STATS_COLLECTOR,
3585 gettext_noop("Collects function-level statistics on database activity."),
3588 &pgstat_track_functions,
3589 TRACK_FUNC_OFF, track_function_options,
3594 {"wal_level", PGC_POSTMASTER, WAL_SETTINGS,
3595 gettext_noop("Set the level of information written to the WAL."),
3599 WAL_LEVEL_MINIMAL, wal_level_options,
3604 {"dynamic_shared_memory_type", PGC_POSTMASTER, RESOURCES_MEM,
3605 gettext_noop("Selects the dynamic shared memory implementation used."),
3608 &dynamic_shared_memory_type,
3609 DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE, dynamic_shared_memory_options,
3614 {"wal_sync_method", PGC_SIGHUP, WAL_SETTINGS,
3615 gettext_noop("Selects the method used for forcing WAL updates to disk."),
3619 DEFAULT_SYNC_METHOD, sync_method_options,
3620 NULL, assign_xlog_sync_method, NULL
3624 {"xmlbinary", PGC_USERSET, CLIENT_CONN_STATEMENT,
3625 gettext_noop("Sets how binary values are to be encoded in XML."),
3629 XMLBINARY_BASE64, xmlbinary_options,
3634 {"xmloption", PGC_USERSET, CLIENT_CONN_STATEMENT,
3635 gettext_noop("Sets whether XML data in implicit parsing and serialization "
3636 "operations is to be considered as documents or content fragments."),
3640 XMLOPTION_CONTENT, xmloption_options,
3645 {"huge_pages", PGC_POSTMASTER, RESOURCES_MEM,
3646 gettext_noop("Use of huge pages on Linux."),
3650 HUGE_PAGES_TRY, huge_pages_options,
3654 /* End-of-list marker */
3656 {NULL, 0, 0, NULL, NULL}, NULL, 0, NULL, NULL, NULL, NULL
3660 /******** end of options list ********/
3664 * To allow continued support of obsolete names for GUC variables, we apply
3665 * the following mappings to any unrecognized name. Note that an old name
3666 * should be mapped to a new one only if the new variable has very similar
3667 * semantics to the old.
3669 static const char *const map_old_guc_names[] = {
3670 "sort_mem", "work_mem",
3671 "vacuum_mem", "maintenance_work_mem",
3677 * Actual lookup of variables is done through this single, sorted array.
3679 static struct config_generic **guc_variables;
3681 /* Current number of variables contained in the vector */
3682 static int num_guc_variables;
3684 /* Vector capacity */
3685 static int size_guc_variables;
3688 static bool guc_dirty; /* TRUE if need to do commit/abort work */
3690 static bool reporting_enabled; /* TRUE to enable GUC_REPORT */
3692 static int GUCNestLevel = 0; /* 1 when in main transaction */
3695 static int guc_var_compare(const void *a, const void *b);
3696 static int guc_name_compare(const char *namea, const char *nameb);
3697 static void InitializeGUCOptionsFromEnvironment(void);
3698 static void InitializeOneGUCOption(struct config_generic * gconf);
3699 static void push_old_value(struct config_generic * gconf, GucAction action);
3700 static void ReportGUCOption(struct config_generic * record);
3701 static void reapply_stacked_values(struct config_generic * variable,
3702 struct config_string * pHolder,
3704 const char *curvalue,
3705 GucContext curscontext, GucSource cursource);
3706 static void ShowGUCConfigOption(const char *name, DestReceiver *dest);
3707 static void ShowAllGUCConfig(DestReceiver *dest);
3708 static char *_ShowOption(struct config_generic * record, bool use_units);
3709 static bool validate_option_array_item(const char *name, const char *value,
3710 bool skipIfNoPermissions);
3711 static void write_auto_conf_file(int fd, const char *filename, ConfigVariable *head_p);
3712 static void replace_auto_config_value(ConfigVariable **head_p, ConfigVariable **tail_p,
3713 const char *name, const char *value);
3717 * Some infrastructure for checking malloc/strdup/realloc calls
3720 guc_malloc(int elevel, size_t size)
3724 /* Avoid unportable behavior of malloc(0) */
3727 data = malloc(size);
3730 (errcode(ERRCODE_OUT_OF_MEMORY),
3731 errmsg("out of memory")));
3736 guc_realloc(int elevel, void *old, size_t size)
3740 /* Avoid unportable behavior of realloc(NULL, 0) */
3741 if (old == NULL && size == 0)
3743 data = realloc(old, size);
3746 (errcode(ERRCODE_OUT_OF_MEMORY),
3747 errmsg("out of memory")));
3752 guc_strdup(int elevel, const char *src)
3759 (errcode(ERRCODE_OUT_OF_MEMORY),
3760 errmsg("out of memory")));
3766 * Detect whether strval is referenced anywhere in a GUC string item
3769 string_field_used(struct config_string * conf, char *strval)
3773 if (strval == *(conf->variable) ||
3774 strval == conf->reset_val ||
3775 strval == conf->boot_val)
3777 for (stack = conf->gen.stack; stack; stack = stack->prev)
3779 if (strval == stack->prior.val.stringval ||
3780 strval == stack->masked.val.stringval)
3787 * Support for assigning to a field of a string GUC item. Free the prior
3788 * value if it's not referenced anywhere else in the item (including stacked
3792 set_string_field(struct config_string * conf, char **field, char *newval)
3794 char *oldval = *field;
3796 /* Do the assignment */
3799 /* Free old value if it's not NULL and isn't referenced anymore */
3800 if (oldval && !string_field_used(conf, oldval))
3805 * Detect whether an "extra" struct is referenced anywhere in a GUC item
3808 extra_field_used(struct config_generic * gconf, void *extra)
3812 if (extra == gconf->extra)
3814 switch (gconf->vartype)
3817 if (extra == ((struct config_bool *) gconf)->reset_extra)
3821 if (extra == ((struct config_int *) gconf)->reset_extra)
3825 if (extra == ((struct config_real *) gconf)->reset_extra)
3829 if (extra == ((struct config_string *) gconf)->reset_extra)
3833 if (extra == ((struct config_enum *) gconf)->reset_extra)
3837 for (stack = gconf->stack; stack; stack = stack->prev)
3839 if (extra == stack->prior.extra ||
3840 extra == stack->masked.extra)
3848 * Support for assigning to an "extra" field of a GUC item. Free the prior
3849 * value if it's not referenced anywhere else in the item (including stacked
3853 set_extra_field(struct config_generic * gconf, void **field, void *newval)
3855 void *oldval = *field;
3857 /* Do the assignment */
3860 /* Free old value if it's not NULL and isn't referenced anymore */
3861 if (oldval && !extra_field_used(gconf, oldval))
3866 * Support for copying a variable's active value into a stack entry.
3867 * The "extra" field associated with the active value is copied, too.
3869 * NB: be sure stringval and extra fields of a new stack entry are
3870 * initialized to NULL before this is used, else we'll try to free() them.
3873 set_stack_value(struct config_generic * gconf, config_var_value *val)
3875 switch (gconf->vartype)
3879 *((struct config_bool *) gconf)->variable;
3883 *((struct config_int *) gconf)->variable;
3887 *((struct config_real *) gconf)->variable;
3890 set_string_field((struct config_string *) gconf,
3891 &(val->val.stringval),
3892 *((struct config_string *) gconf)->variable);
3896 *((struct config_enum *) gconf)->variable;
3899 set_extra_field(gconf, &(val->extra), gconf->extra);
3903 * Support for discarding a no-longer-needed value in a stack entry.
3904 * The "extra" field associated with the stack entry is cleared, too.
3907 discard_stack_value(struct config_generic * gconf, config_var_value *val)
3909 switch (gconf->vartype)
3915 /* no need to do anything */
3918 set_string_field((struct config_string *) gconf,
3919 &(val->val.stringval),
3923 set_extra_field(gconf, &(val->extra), NULL);
3928 * Fetch the sorted array pointer (exported for help_config.c's use ONLY)
3930 struct config_generic **
3931 get_guc_variables(void)
3933 return guc_variables;
3938 * Build the sorted array. This is split out so that it could be
3939 * re-executed after startup (eg, we could allow loadable modules to
3940 * add vars, and then we'd need to re-sort).
3943 build_guc_variables(void)
3947 struct config_generic **guc_vars;
3950 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
3952 struct config_bool *conf = &ConfigureNamesBool[i];
3954 /* Rather than requiring vartype to be filled in by hand, do this: */
3955 conf->gen.vartype = PGC_BOOL;
3959 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
3961 struct config_int *conf = &ConfigureNamesInt[i];
3963 conf->gen.vartype = PGC_INT;
3967 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
3969 struct config_real *conf = &ConfigureNamesReal[i];
3971 conf->gen.vartype = PGC_REAL;
3975 for (i = 0; ConfigureNamesString[i].gen.name; i++)
3977 struct config_string *conf = &ConfigureNamesString[i];
3979 conf->gen.vartype = PGC_STRING;
3983 for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
3985 struct config_enum *conf = &ConfigureNamesEnum[i];
3987 conf->gen.vartype = PGC_ENUM;
3992 * Create table with 20% slack
3994 size_vars = num_vars + num_vars / 4;
3996 guc_vars = (struct config_generic **)
3997 guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
4001 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
4002 guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
4004 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
4005 guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
4007 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
4008 guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
4010 for (i = 0; ConfigureNamesString[i].gen.name; i++)
4011 guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
4013 for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
4014 guc_vars[num_vars++] = &ConfigureNamesEnum[i].gen;
4017 free(guc_variables);
4018 guc_variables = guc_vars;
4019 num_guc_variables = num_vars;
4020 size_guc_variables = size_vars;
4021 qsort((void *) guc_variables, num_guc_variables,
4022 sizeof(struct config_generic *), guc_var_compare);
4026 * Add a new GUC variable to the list of known variables. The
4027 * list is expanded if needed.
4030 add_guc_variable(struct config_generic * var, int elevel)
4032 if (num_guc_variables + 1 >= size_guc_variables)
4035 * Increase the vector by 25%
4037 int size_vars = size_guc_variables + size_guc_variables / 4;
4038 struct config_generic **guc_vars;
4043 guc_vars = (struct config_generic **)
4044 guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
4048 guc_vars = (struct config_generic **)
4049 guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
4052 if (guc_vars == NULL)
4053 return false; /* out of memory */
4055 guc_variables = guc_vars;
4056 size_guc_variables = size_vars;
4058 guc_variables[num_guc_variables++] = var;
4059 qsort((void *) guc_variables, num_guc_variables,
4060 sizeof(struct config_generic *), guc_var_compare);
4065 * Create and add a placeholder variable for a custom variable name.
4067 static struct config_generic *
4068 add_placeholder_variable(const char *name, int elevel)
4070 size_t sz = sizeof(struct config_string) + sizeof(char *);
4071 struct config_string *var;
4072 struct config_generic *gen;
4074 var = (struct config_string *) guc_malloc(elevel, sz);
4080 gen->name = guc_strdup(elevel, name);
4081 if (gen->name == NULL)
4087 gen->context = PGC_USERSET;
4088 gen->group = CUSTOM_OPTIONS;
4089 gen->short_desc = "GUC placeholder variable";
4090 gen->flags = GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_CUSTOM_PLACEHOLDER;
4091 gen->vartype = PGC_STRING;
4094 * The char* is allocated at the end of the struct since we have no
4095 * 'static' place to point to. Note that the current value, as well as
4096 * the boot and reset values, start out NULL.
4098 var->variable = (char **) (var + 1);
4100 if (!add_guc_variable((struct config_generic *) var, elevel))
4102 free((void *) gen->name);
4111 * Look up option NAME. If it exists, return a pointer to its record,
4112 * else return NULL. If create_placeholders is TRUE, we'll create a
4113 * placeholder record for a valid-looking custom variable name.
4115 static struct config_generic *
4116 find_option(const char *name, bool create_placeholders, int elevel)
4118 const char **key = &name;
4119 struct config_generic **res;
4125 * By equating const char ** with struct config_generic *, we are assuming
4126 * the name field is first in config_generic.
4128 res = (struct config_generic **) bsearch((void *) &key,
4129 (void *) guc_variables,
4131 sizeof(struct config_generic *),
4137 * See if the name is an obsolete name for a variable. We assume that the
4138 * set of supported old names is short enough that a brute-force search is
4141 for (i = 0; map_old_guc_names[i] != NULL; i += 2)
4143 if (guc_name_compare(name, map_old_guc_names[i]) == 0)
4144 return find_option(map_old_guc_names[i + 1], false, elevel);
4147 if (create_placeholders)
4150 * Check if the name is qualified, and if so, add a placeholder.
4152 if (strchr(name, GUC_QUALIFIER_SEPARATOR) != NULL)
4153 return add_placeholder_variable(name, elevel);
4162 * comparator for qsorting and bsearching guc_variables array
4165 guc_var_compare(const void *a, const void *b)
4167 const struct config_generic *confa = *(struct config_generic * const *) a;
4168 const struct config_generic *confb = *(struct config_generic * const *) b;
4170 return guc_name_compare(confa->name, confb->name);
4174 * the bare comparison function for GUC names
4177 guc_name_compare(const char *namea, const char *nameb)
4180 * The temptation to use strcasecmp() here must be resisted, because the
4181 * array ordering has to remain stable across setlocale() calls. So, build
4182 * our own with a simple ASCII-only downcasing.
4184 while (*namea && *nameb)
4186 char cha = *namea++;
4187 char chb = *nameb++;
4189 if (cha >= 'A' && cha <= 'Z')
4191 if (chb >= 'A' && chb <= 'Z')
4197 return 1; /* a is longer */
4199 return -1; /* b is longer */
4205 * Initialize GUC options during program startup.
4207 * Note that we cannot read the config file yet, since we have not yet
4208 * processed command-line switches.
4211 InitializeGUCOptions(void)
4216 * Before log_line_prefix could possibly receive a nonempty setting, make
4217 * sure that timezone processing is minimally alive (see elog.c).
4219 pg_timezone_initialize();
4222 * Build sorted array of all GUC variables.
4224 build_guc_variables();
4227 * Load all variables with their compiled-in defaults, and initialize
4228 * status fields as needed.
4230 for (i = 0; i < num_guc_variables; i++)
4232 InitializeOneGUCOption(guc_variables[i]);
4237 reporting_enabled = false;
4240 * Prevent any attempt to override the transaction modes from
4241 * non-interactive sources.
4243 SetConfigOption("transaction_isolation", "default",
4244 PGC_POSTMASTER, PGC_S_OVERRIDE);
4245 SetConfigOption("transaction_read_only", "no",
4246 PGC_POSTMASTER, PGC_S_OVERRIDE);
4247 SetConfigOption("transaction_deferrable", "no",
4248 PGC_POSTMASTER, PGC_S_OVERRIDE);
4251 * For historical reasons, some GUC parameters can receive defaults from
4252 * environment variables. Process those settings.
4254 InitializeGUCOptionsFromEnvironment();
4258 * Assign any GUC values that can come from the server's environment.
4260 * This is called from InitializeGUCOptions, and also from ProcessConfigFile
4261 * to deal with the possibility that a setting has been removed from
4262 * postgresql.conf and should now get a value from the environment.
4263 * (The latter is a kludge that should probably go away someday; if so,
4264 * fold this back into InitializeGUCOptions.)
4267 InitializeGUCOptionsFromEnvironment(void)
4272 env = getenv("PGPORT");
4274 SetConfigOption("port", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
4276 env = getenv("PGDATESTYLE");
4278 SetConfigOption("datestyle", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
4280 env = getenv("PGCLIENTENCODING");
4282 SetConfigOption("client_encoding", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
4285 * rlimit isn't exactly an "environment variable", but it behaves about
4286 * the same. If we can identify the platform stack depth rlimit, increase
4287 * default stack depth setting up to whatever is safe (but at most 2MB).
4289 stack_rlimit = get_stack_depth_rlimit();
4290 if (stack_rlimit > 0)
4292 long new_limit = (stack_rlimit - STACK_DEPTH_SLOP) / 1024L;
4294 if (new_limit > 100)
4298 new_limit = Min(new_limit, 2048);
4299 sprintf(limbuf, "%ld", new_limit);
4300 SetConfigOption("max_stack_depth", limbuf,
4301 PGC_POSTMASTER, PGC_S_ENV_VAR);
4307 * Initialize one GUC option variable to its compiled-in default.
4309 * Note: the reason for calling check_hooks is not that we think the boot_val
4310 * might fail, but that the hooks might wish to compute an "extra" struct.
4313 InitializeOneGUCOption(struct config_generic * gconf)
4316 gconf->source = PGC_S_DEFAULT;
4317 gconf->reset_source = PGC_S_DEFAULT;
4318 gconf->scontext = PGC_INTERNAL;
4319 gconf->reset_scontext = PGC_INTERNAL;
4320 gconf->stack = NULL;
4321 gconf->extra = NULL;
4322 gconf->sourcefile = NULL;
4323 gconf->sourceline = 0;
4325 switch (gconf->vartype)
4329 struct config_bool *conf = (struct config_bool *) gconf;
4330 bool newval = conf->boot_val;
4333 if (!call_bool_check_hook(conf, &newval, &extra,
4334 PGC_S_DEFAULT, LOG))
4335 elog(FATAL, "failed to initialize %s to %d",
4336 conf->gen.name, (int) newval);
4337 if (conf->assign_hook)
4338 (*conf->assign_hook) (newval, extra);
4339 *conf->variable = conf->reset_val = newval;
4340 conf->gen.extra = conf->reset_extra = extra;
4345 struct config_int *conf = (struct config_int *) gconf;
4346 int newval = conf->boot_val;
4349 Assert(newval >= conf->min);
4350 Assert(newval <= conf->max);
4351 if (!call_int_check_hook(conf, &newval, &extra,
4352 PGC_S_DEFAULT, LOG))
4353 elog(FATAL, "failed to initialize %s to %d",
4354 conf->gen.name, newval);
4355 if (conf->assign_hook)
4356 (*conf->assign_hook) (newval, extra);
4357 *conf->variable = conf->reset_val = newval;
4358 conf->gen.extra = conf->reset_extra = extra;
4363 struct config_real *conf = (struct config_real *) gconf;
4364 double newval = conf->boot_val;
4367 Assert(newval >= conf->min);
4368 Assert(newval <= conf->max);
4369 if (!call_real_check_hook(conf, &newval, &extra,
4370 PGC_S_DEFAULT, LOG))
4371 elog(FATAL, "failed to initialize %s to %g",
4372 conf->gen.name, newval);
4373 if (conf->assign_hook)
4374 (*conf->assign_hook) (newval, extra);
4375 *conf->variable = conf->reset_val = newval;
4376 conf->gen.extra = conf->reset_extra = extra;
4381 struct config_string *conf = (struct config_string *) gconf;
4385 /* non-NULL boot_val must always get strdup'd */
4386 if (conf->boot_val != NULL)
4387 newval = guc_strdup(FATAL, conf->boot_val);
4391 if (!call_string_check_hook(conf, &newval, &extra,
4392 PGC_S_DEFAULT, LOG))
4393 elog(FATAL, "failed to initialize %s to \"%s\"",
4394 conf->gen.name, newval ? newval : "");
4395 if (conf->assign_hook)
4396 (*conf->assign_hook) (newval, extra);
4397 *conf->variable = conf->reset_val = newval;
4398 conf->gen.extra = conf->reset_extra = extra;
4403 struct config_enum *conf = (struct config_enum *) gconf;
4404 int newval = conf->boot_val;
4407 if (!call_enum_check_hook(conf, &newval, &extra,
4408 PGC_S_DEFAULT, LOG))
4409 elog(FATAL, "failed to initialize %s to %d",
4410 conf->gen.name, newval);
4411 if (conf->assign_hook)
4412 (*conf->assign_hook) (newval, extra);
4413 *conf->variable = conf->reset_val = newval;
4414 conf->gen.extra = conf->reset_extra = extra;
4422 * Select the configuration files and data directory to be used, and
4423 * do the initial read of postgresql.conf.
4425 * This is called after processing command-line switches.
4426 * userDoption is the -D switch value if any (NULL if unspecified).
4427 * progname is just for use in error messages.
4429 * Returns true on success; on failure, prints a suitable error message
4430 * to stderr and returns false.
4433 SelectConfigFiles(const char *userDoption, const char *progname)
4437 struct stat stat_buf;
4439 /* configdir is -D option, or $PGDATA if no -D */
4441 configdir = make_absolute_path(userDoption);
4443 configdir = make_absolute_path(getenv("PGDATA"));
4446 * Find the configuration file: if config_file was specified on the
4447 * command line, use it, else use configdir/postgresql.conf. In any case
4448 * ensure the result is an absolute path, so that it will be interpreted
4449 * the same way by future backends.
4452 fname = make_absolute_path(ConfigFileName);
4455 fname = guc_malloc(FATAL,
4456 strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
4457 sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
4461 write_stderr("%s does not know where to find the server configuration file.\n"
4462 "You must specify the --config-file or -D invocation "
4463 "option or set the PGDATA environment variable.\n",
4469 * Set the ConfigFileName GUC variable to its final value, ensuring that
4470 * it can't be overridden later.
4472 SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4476 * Now read the config file for the first time.
4478 if (stat(ConfigFileName, &stat_buf) != 0)
4480 write_stderr("%s cannot access the server configuration file \"%s\": %s\n",
4481 progname, ConfigFileName, strerror(errno));
4487 * Read the configuration file for the first time. This time only the
4488 * data_directory parameter is picked up to determine the data directory,
4489 * so that we can read the PG_AUTOCONF_FILENAME file next time.
4491 ProcessConfigFile(PGC_POSTMASTER);
4494 * If the data_directory GUC variable has been set, use that as DataDir;
4495 * otherwise use configdir if set; else punt.
4497 * Note: SetDataDir will copy and absolute-ize its argument, so we don't
4501 SetDataDir(data_directory);
4503 SetDataDir(configdir);
4506 write_stderr("%s does not know where to find the database system data.\n"
4507 "This can be specified as \"data_directory\" in \"%s\", "
4508 "or by the -D invocation option, or by the "
4509 "PGDATA environment variable.\n",
4510 progname, ConfigFileName);
4515 * Reflect the final DataDir value back into the data_directory GUC var.
4516 * (If you are wondering why we don't just make them a single variable,
4517 * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
4518 * child backends specially. XXX is that still true? Given that we now
4519 * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
4520 * DataDir in advance.)
4522 SetConfigOption("data_directory", DataDir, PGC_POSTMASTER, PGC_S_OVERRIDE);
4525 * Now read the config file a second time, allowing any settings in the
4526 * PG_AUTOCONF_FILENAME file to take effect. (This is pretty ugly, but
4527 * since we have to determine the DataDir before we can find the autoconf
4528 * file, the alternatives seem worse.)
4530 ProcessConfigFile(PGC_POSTMASTER);
4533 * If timezone_abbreviations wasn't set in the configuration file, install
4534 * the default value. We do it this way because we can't safely install a
4535 * "real" value until my_exec_path is set, which may not have happened
4536 * when InitializeGUCOptions runs, so the bootstrap default value cannot
4537 * be the real desired default.
4539 pg_timezone_abbrev_initialize();
4542 * Figure out where pg_hba.conf is, and make sure the path is absolute.
4545 fname = make_absolute_path(HbaFileName);
4548 fname = guc_malloc(FATAL,
4549 strlen(configdir) + strlen(HBA_FILENAME) + 2);
4550 sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
4554 write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
4555 "This can be specified as \"hba_file\" in \"%s\", "
4556 "or by the -D invocation option, or by the "
4557 "PGDATA environment variable.\n",
4558 progname, ConfigFileName);
4561 SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4565 * Likewise for pg_ident.conf.
4568 fname = make_absolute_path(IdentFileName);
4571 fname = guc_malloc(FATAL,
4572 strlen(configdir) + strlen(IDENT_FILENAME) + 2);
4573 sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
4577 write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
4578 "This can be specified as \"ident_file\" in \"%s\", "
4579 "or by the -D invocation option, or by the "
4580 "PGDATA environment variable.\n",
4581 progname, ConfigFileName);
4584 SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4594 * Reset all options to their saved default values (implements RESET ALL)
4597 ResetAllOptions(void)
4601 for (i = 0; i < num_guc_variables; i++)
4603 struct config_generic *gconf = guc_variables[i];
4605 /* Don't reset non-SET-able values */
4606 if (gconf->context != PGC_SUSET &&
4607 gconf->context != PGC_USERSET)
4609 /* Don't reset if special exclusion from RESET ALL */
4610 if (gconf->flags & GUC_NO_RESET_ALL)
4612 /* No need to reset if wasn't SET */
4613 if (gconf->source <= PGC_S_OVERRIDE)
4616 /* Save old value to support transaction abort */
4617 push_old_value(gconf, GUC_ACTION_SET);
4619 switch (gconf->vartype)
4623 struct config_bool *conf = (struct config_bool *) gconf;
4625 if (conf->assign_hook)
4626 (*conf->assign_hook) (conf->reset_val,
4628 *conf->variable = conf->reset_val;
4629 set_extra_field(&conf->gen, &conf->gen.extra,
4635 struct config_int *conf = (struct config_int *) gconf;
4637 if (conf->assign_hook)
4638 (*conf->assign_hook) (conf->reset_val,
4640 *conf->variable = conf->reset_val;
4641 set_extra_field(&conf->gen, &conf->gen.extra,
4647 struct config_real *conf = (struct config_real *) gconf;
4649 if (conf->assign_hook)
4650 (*conf->assign_hook) (conf->reset_val,
4652 *conf->variable = conf->reset_val;
4653 set_extra_field(&conf->gen, &conf->gen.extra,
4659 struct config_string *conf = (struct config_string *) gconf;
4661 if (conf->assign_hook)
4662 (*conf->assign_hook) (conf->reset_val,
4664 set_string_field(conf, conf->variable, conf->reset_val);
4665 set_extra_field(&conf->gen, &conf->gen.extra,
4671 struct config_enum *conf = (struct config_enum *) gconf;
4673 if (conf->assign_hook)
4674 (*conf->assign_hook) (conf->reset_val,
4676 *conf->variable = conf->reset_val;
4677 set_extra_field(&conf->gen, &conf->gen.extra,
4683 gconf->source = gconf->reset_source;
4684 gconf->scontext = gconf->reset_scontext;
4686 if (gconf->flags & GUC_REPORT)
4687 ReportGUCOption(gconf);
4694 * Push previous state during transactional assignment to a GUC variable.
4697 push_old_value(struct config_generic * gconf, GucAction action)
4701 /* If we're not inside a nest level, do nothing */
4702 if (GUCNestLevel == 0)
4705 /* Do we already have a stack entry of the current nest level? */
4706 stack = gconf->stack;
4707 if (stack && stack->nest_level >= GUCNestLevel)
4709 /* Yes, so adjust its state if necessary */
4710 Assert(stack->nest_level == GUCNestLevel);
4713 case GUC_ACTION_SET:
4714 /* SET overrides any prior action at same nest level */
4715 if (stack->state == GUC_SET_LOCAL)
4717 /* must discard old masked value */
4718 discard_stack_value(gconf, &stack->masked);
4720 stack->state = GUC_SET;
4722 case GUC_ACTION_LOCAL:
4723 if (stack->state == GUC_SET)
4725 /* SET followed by SET LOCAL, remember SET's value */
4726 stack->masked_scontext = gconf->scontext;
4727 set_stack_value(gconf, &stack->masked);
4728 stack->state = GUC_SET_LOCAL;
4730 /* in all other cases, no change to stack entry */
4732 case GUC_ACTION_SAVE:
4733 /* Could only have a prior SAVE of same variable */
4734 Assert(stack->state == GUC_SAVE);
4737 Assert(guc_dirty); /* must be set already */
4742 * Push a new stack entry
4744 * We keep all the stack entries in TopTransactionContext for simplicity.
4746 stack = (GucStack *) MemoryContextAllocZero(TopTransactionContext,
4749 stack->prev = gconf->stack;
4750 stack->nest_level = GUCNestLevel;
4753 case GUC_ACTION_SET:
4754 stack->state = GUC_SET;
4756 case GUC_ACTION_LOCAL:
4757 stack->state = GUC_LOCAL;
4759 case GUC_ACTION_SAVE:
4760 stack->state = GUC_SAVE;
4763 stack->source = gconf->source;
4764 stack->scontext = gconf->scontext;
4765 set_stack_value(gconf, &stack->prior);
4767 gconf->stack = stack;
4769 /* Ensure we remember to pop at end of xact */
4775 * Do GUC processing at main transaction start.
4781 * The nest level should be 0 between transactions; if it isn't, somebody
4782 * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
4783 * throw a warning but make no other effort to clean up.
4785 if (GUCNestLevel != 0)
4786 elog(WARNING, "GUC nest level = %d at transaction start",
4792 * Enter a new nesting level for GUC values. This is called at subtransaction
4793 * start, and when entering a function that has proconfig settings, and in
4794 * some other places where we want to set GUC variables transiently.
4795 * NOTE we must not risk error here, else subtransaction start will be unhappy.
4798 NewGUCNestLevel(void)
4800 return ++GUCNestLevel;
4804 * Do GUC processing at transaction or subtransaction commit or abort, or
4805 * when exiting a function that has proconfig settings, or when undoing a
4806 * transient assignment to some GUC variables. (The name is thus a bit of
4807 * a misnomer; perhaps it should be ExitGUCNestLevel or some such.)
4808 * During abort, we discard all GUC settings that were applied at nesting
4809 * levels >= nestLevel. nestLevel == 1 corresponds to the main transaction.
4812 AtEOXact_GUC(bool isCommit, int nestLevel)
4818 * Note: it's possible to get here with GUCNestLevel == nestLevel-1 during
4819 * abort, if there is a failure during transaction start before
4820 * AtStart_GUC is called.
4822 Assert(nestLevel > 0 &&
4823 (nestLevel <= GUCNestLevel ||
4824 (nestLevel == GUCNestLevel + 1 && !isCommit)));
4826 /* Quick exit if nothing's changed in this transaction */
4829 GUCNestLevel = nestLevel - 1;
4833 still_dirty = false;
4834 for (i = 0; i < num_guc_variables; i++)
4836 struct config_generic *gconf = guc_variables[i];
4840 * Process and pop each stack entry within the nest level. To simplify
4841 * fmgr_security_definer() and other places that use GUC_ACTION_SAVE,
4842 * we allow failure exit from code that uses a local nest level to be
4843 * recovered at the surrounding transaction or subtransaction abort;
4844 * so there could be more than one stack entry to pop.
4846 while ((stack = gconf->stack) != NULL &&
4847 stack->nest_level >= nestLevel)
4849 GucStack *prev = stack->prev;
4850 bool restorePrior = false;
4851 bool restoreMasked = false;
4855 * In this next bit, if we don't set either restorePrior or
4856 * restoreMasked, we must "discard" any unwanted fields of the
4857 * stack entries to avoid leaking memory. If we do set one of
4858 * those flags, unused fields will be cleaned up after restoring.
4860 if (!isCommit) /* if abort, always restore prior value */
4861 restorePrior = true;
4862 else if (stack->state == GUC_SAVE)
4863 restorePrior = true;
4864 else if (stack->nest_level == 1)
4866 /* transaction commit */
4867 if (stack->state == GUC_SET_LOCAL)
4868 restoreMasked = true;
4869 else if (stack->state == GUC_SET)
4871 /* we keep the current active value */
4872 discard_stack_value(gconf, &stack->prior);
4874 else /* must be GUC_LOCAL */
4875 restorePrior = true;
4877 else if (prev == NULL ||
4878 prev->nest_level < stack->nest_level - 1)
4880 /* decrement entry's level and do not pop it */
4881 stack->nest_level--;
4887 * We have to merge this stack entry into prev. See README for
4888 * discussion of this bit.
4890 switch (stack->state)
4893 Assert(false); /* can't get here */
4896 /* next level always becomes SET */
4897 discard_stack_value(gconf, &stack->prior);
4898 if (prev->state == GUC_SET_LOCAL)
4899 discard_stack_value(gconf, &prev->masked);
4900 prev->state = GUC_SET;
4904 if (prev->state == GUC_SET)
4906 /* LOCAL migrates down */
4907 prev->masked_scontext = stack->scontext;
4908 prev->masked = stack->prior;
4909 prev->state = GUC_SET_LOCAL;
4913 /* else just forget this stack level */
4914 discard_stack_value(gconf, &stack->prior);
4919 /* prior state at this level no longer wanted */
4920 discard_stack_value(gconf, &stack->prior);
4921 /* copy down the masked state */
4922 prev->masked_scontext = stack->masked_scontext;
4923 if (prev->state == GUC_SET_LOCAL)
4924 discard_stack_value(gconf, &prev->masked);
4925 prev->masked = stack->masked;
4926 prev->state = GUC_SET_LOCAL;
4933 if (restorePrior || restoreMasked)
4935 /* Perform appropriate restoration of the stacked value */
4936 config_var_value newvalue;
4937 GucSource newsource;
4938 GucContext newscontext;
4942 newvalue = stack->masked;
4943 newsource = PGC_S_SESSION;
4944 newscontext = stack->masked_scontext;
4948 newvalue = stack->prior;
4949 newsource = stack->source;
4950 newscontext = stack->scontext;
4953 switch (gconf->vartype)
4957 struct config_bool *conf = (struct config_bool *) gconf;
4958 bool newval = newvalue.val.boolval;
4959 void *newextra = newvalue.extra;
4961 if (*conf->variable != newval ||
4962 conf->gen.extra != newextra)
4964 if (conf->assign_hook)
4965 (*conf->assign_hook) (newval, newextra);
4966 *conf->variable = newval;
4967 set_extra_field(&conf->gen, &conf->gen.extra,
4975 struct config_int *conf = (struct config_int *) gconf;
4976 int newval = newvalue.val.intval;
4977 void *newextra = newvalue.extra;
4979 if (*conf->variable != newval ||
4980 conf->gen.extra != newextra)
4982 if (conf->assign_hook)
4983 (*conf->assign_hook) (newval, newextra);
4984 *conf->variable = newval;
4985 set_extra_field(&conf->gen, &conf->gen.extra,
4993 struct config_real *conf = (struct config_real *) gconf;
4994 double newval = newvalue.val.realval;
4995 void *newextra = newvalue.extra;
4997 if (*conf->variable != newval ||
4998 conf->gen.extra != newextra)
5000 if (conf->assign_hook)
5001 (*conf->assign_hook) (newval, newextra);
5002 *conf->variable = newval;
5003 set_extra_field(&conf->gen, &conf->gen.extra,
5011 struct config_string *conf = (struct config_string *) gconf;
5012 char *newval = newvalue.val.stringval;
5013 void *newextra = newvalue.extra;
5015 if (*conf->variable != newval ||
5016 conf->gen.extra != newextra)
5018 if (conf->assign_hook)
5019 (*conf->assign_hook) (newval, newextra);
5020 set_string_field(conf, conf->variable, newval);
5021 set_extra_field(&conf->gen, &conf->gen.extra,
5027 * Release stacked values if not used anymore. We
5028 * could use discard_stack_value() here, but since
5029 * we have type-specific code anyway, might as
5032 set_string_field(conf, &stack->prior.val.stringval, NULL);
5033 set_string_field(conf, &stack->masked.val.stringval, NULL);
5038 struct config_enum *conf = (struct config_enum *) gconf;
5039 int newval = newvalue.val.enumval;
5040 void *newextra = newvalue.extra;
5042 if (*conf->variable != newval ||
5043 conf->gen.extra != newextra)
5045 if (conf->assign_hook)
5046 (*conf->assign_hook) (newval, newextra);
5047 *conf->variable = newval;
5048 set_extra_field(&conf->gen, &conf->gen.extra,
5057 * Release stacked extra values if not used anymore.
5059 set_extra_field(gconf, &(stack->prior.extra), NULL);
5060 set_extra_field(gconf, &(stack->masked.extra), NULL);
5062 /* And restore source information */
5063 gconf->source = newsource;
5064 gconf->scontext = newscontext;
5067 /* Finish popping the state stack */
5068 gconf->stack = prev;
5071 /* Report new value if we changed it */
5072 if (changed && (gconf->flags & GUC_REPORT))
5073 ReportGUCOption(gconf);
5074 } /* end of stack-popping loop */
5080 /* If there are no remaining stack entries, we can reset guc_dirty */
5081 guc_dirty = still_dirty;
5083 /* Update nesting level */
5084 GUCNestLevel = nestLevel - 1;
5089 * Start up automatic reporting of changes to variables marked GUC_REPORT.
5090 * This is executed at completion of backend startup.
5093 BeginReportingGUCOptions(void)
5098 * Don't do anything unless talking to an interactive frontend of protocol
5101 if (whereToSendOutput != DestRemote ||
5102 PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
5105 reporting_enabled = true;
5107 /* Transmit initial values of interesting variables */
5108 for (i = 0; i < num_guc_variables; i++)
5110 struct config_generic *conf = guc_variables[i];
5112 if (conf->flags & GUC_REPORT)
5113 ReportGUCOption(conf);
5118 * ReportGUCOption: if appropriate, transmit option value to frontend
5121 ReportGUCOption(struct config_generic * record)
5123 if (reporting_enabled && (record->flags & GUC_REPORT))
5125 char *val = _ShowOption(record, false);
5126 StringInfoData msgbuf;
5128 pq_beginmessage(&msgbuf, 'S');
5129 pq_sendstring(&msgbuf, record->name);
5130 pq_sendstring(&msgbuf, val);
5131 pq_endmessage(&msgbuf);
5138 * Convert a value from one of the human-friendly units ("kB", "min" etc.)
5139 * to the given base unit. 'value' and 'unit' are the input value and unit
5140 * to convert from. The converted value is stored in *base_value.
5142 * Returns true on success, false if the input unit is not recognized.
5145 convert_to_base_unit(int64 value, const char *unit,
5146 int base_unit, int64 *base_value)
5148 const unit_conversion *table;
5151 if (base_unit & GUC_UNIT_MEMORY)
5152 table = memory_unit_conversion_table;
5154 table = time_unit_conversion_table;
5156 for (i = 0; *table[i].unit; i++)
5158 if (base_unit == table[i].base_unit &&
5159 strcmp(unit, table[i].unit) == 0)
5161 if (table[i].multiplier < 0)
5162 *base_value = value / (-table[i].multiplier);
5164 *base_value = value * table[i].multiplier;
5172 * Convert a value in some base unit to a human-friendly unit. The output
5173 * unit is chosen so that it's the greatest unit that can represent the value
5174 * without loss. For example, if the base unit is GUC_UNIT_KB, 1024 is
5175 * converted to 1 MB, but 1025 is represented as 1025 kB.
5178 convert_from_base_unit(int64 base_value, int base_unit,
5179 int64 *value, const char **unit)
5181 const unit_conversion *table;
5186 if (base_unit & GUC_UNIT_MEMORY)
5187 table = memory_unit_conversion_table;
5189 table = time_unit_conversion_table;
5191 for (i = 0; *table[i].unit; i++)
5193 if (base_unit == table[i].base_unit)
5196 * Accept the first conversion that divides the value evenly. We
5197 * assume that the conversions for each base unit are ordered from
5198 * greatest unit to the smallest!
5200 if (table[i].multiplier < 0)
5202 *value = base_value * (-table[i].multiplier);
5203 *unit = table[i].unit;
5206 else if (base_value % table[i].multiplier == 0)
5208 *value = base_value / table[i].multiplier;
5209 *unit = table[i].unit;
5215 Assert(*unit != NULL);
5220 * Try to parse value as an integer. The accepted formats are the
5221 * usual decimal, octal, or hexadecimal formats, optionally followed by
5222 * a unit name if "flags" indicates a unit is allowed.
5224 * If the string parses okay, return true, else false.
5225 * If okay and result is not NULL, return the value in *result.
5226 * If not okay and hintmsg is not NULL, *hintmsg is set to a suitable
5227 * HINT message, or NULL if no hint provided.
5230 parse_int(const char *value, int *result, int flags, const char **hintmsg)
5235 /* To suppress compiler warnings, always set output params */
5241 /* We assume here that int64 is at least as wide as long */
5243 val = strtol(value, &endptr, 0);
5245 if (endptr == value)
5246 return false; /* no HINT for integer syntax error */
5248 if (errno == ERANGE || val != (int64) ((int32) val))
5251 *hintmsg = gettext_noop("Value exceeds integer range.");
5255 /* allow whitespace between integer and unit */
5256 while (isspace((unsigned char) *endptr))
5259 /* Handle possible unit */
5260 if (*endptr != '\0')
5262 char unit[MAX_UNIT_LEN + 1];
5264 bool converted = false;
5266 if ((flags & GUC_UNIT) == 0)
5267 return false; /* this setting does not accept a unit */
5270 while (*endptr != '\0' && !isspace((unsigned char) *endptr) &&
5271 unitlen < MAX_UNIT_LEN)
5272 unit[unitlen++] = *(endptr++);
5273 unit[unitlen] = '\0';
5274 /* allow whitespace after unit */
5275 while (isspace((unsigned char) *endptr))
5278 if (*endptr == '\0')
5279 converted = convert_to_base_unit(val, unit, (flags & GUC_UNIT),
5283 /* invalid unit, or garbage after the unit; set hint and fail. */
5286 if (flags & GUC_UNIT_MEMORY)
5287 *hintmsg = memory_units_hint;
5289 *hintmsg = time_units_hint;
5294 /* Check for overflow due to units conversion */
5295 if (val != (int64) ((int32) val))
5298 *hintmsg = gettext_noop("Value exceeds integer range.");
5304 *result = (int) val;
5311 * Try to parse value as a floating point number in the usual format.
5312 * If the string parses okay, return true, else false.
5313 * If okay and result is not NULL, return the value in *result.
5316 parse_real(const char *value, double *result)
5322 *result = 0; /* suppress compiler warning */
5325 val = strtod(value, &endptr);
5326 if (endptr == value || errno == ERANGE)
5329 /* allow whitespace after number */
5330 while (isspace((unsigned char) *endptr))
5332 if (*endptr != '\0')
5342 * Lookup the name for an enum option with the selected value.
5343 * Should only ever be called with known-valid values, so throws
5344 * an elog(ERROR) if the enum option is not found.
5346 * The returned string is a pointer to static data and not
5347 * allocated for modification.
5350 config_enum_lookup_by_value(struct config_enum * record, int val)
5352 const struct config_enum_entry *entry;
5354 for (entry = record->options; entry && entry->name; entry++)
5356 if (entry->val == val)
5360 elog(ERROR, "could not find enum option %d for %s",
5361 val, record->gen.name);
5362 return NULL; /* silence compiler */
5367 * Lookup the value for an enum option with the selected name
5368 * (case-insensitive).
5369 * If the enum option is found, sets the retval value and returns
5370 * true. If it's not found, return FALSE and retval is set to 0.
5373 config_enum_lookup_by_name(struct config_enum * record, const char *value,
5376 const struct config_enum_entry *entry;
5378 for (entry = record->options; entry && entry->name; entry++)
5380 if (pg_strcasecmp(value, entry->name) == 0)
5382 *retval = entry->val;
5393 * Return a list of all available options for an enum, excluding
5394 * hidden ones, separated by the given separator.
5395 * If prefix is non-NULL, it is added before the first enum value.
5396 * If suffix is non-NULL, it is added to the end of the string.
5399 config_enum_get_options(struct config_enum * record, const char *prefix,
5400 const char *suffix, const char *separator)
5402 const struct config_enum_entry *entry;
5403 StringInfoData retstr;
5406 initStringInfo(&retstr);
5407 appendStringInfoString(&retstr, prefix);
5409 seplen = strlen(separator);
5410 for (entry = record->options; entry && entry->name; entry++)
5414 appendStringInfoString(&retstr, entry->name);
5415 appendBinaryStringInfo(&retstr, separator, seplen);
5420 * All the entries may have been hidden, leaving the string empty if no
5421 * prefix was given. This indicates a broken GUC setup, since there is no
5422 * use for an enum without any values, so we just check to make sure we
5423 * don't write to invalid memory instead of actually trying to do
5424 * something smart with it.
5426 if (retstr.len >= seplen)
5428 /* Replace final separator */
5429 retstr.data[retstr.len - seplen] = '\0';
5430 retstr.len -= seplen;
5433 appendStringInfoString(&retstr, suffix);
5439 * Parse and validate a proposed value for the specified configuration
5442 * This does built-in checks (such as range limits for an integer parameter)
5443 * and also calls any check hook the parameter may have.
5445 * record: GUC variable's info record
5446 * name: variable name (should match the record of course)
5447 * value: proposed value, as a string
5448 * source: identifies source of value (check hooks may need this)
5449 * elevel: level to log any error reports at
5450 * newval: on success, converted parameter value is returned here
5451 * newextra: on success, receives any "extra" data returned by check hook
5452 * (caller must initialize *newextra to NULL)
5454 * Returns true if OK, false if not (or throws error, if elevel >= ERROR)
5457 parse_and_validate_value(struct config_generic * record,
5458 const char *name, const char *value,
5459 GucSource source, int elevel,
5460 union config_var_val * newval, void **newextra)
5462 switch (record->vartype)
5466 struct config_bool *conf = (struct config_bool *) record;
5468 if (!parse_bool(value, &newval->boolval))
5471 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5472 errmsg("parameter \"%s\" requires a Boolean value",
5477 if (!call_bool_check_hook(conf, &newval->boolval, newextra,
5484 struct config_int *conf = (struct config_int *) record;
5485 const char *hintmsg;
5487 if (!parse_int(value, &newval->intval,
5488 conf->gen.flags, &hintmsg))
5491 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5492 errmsg("invalid value for parameter \"%s\": \"%s\"",
5494 hintmsg ? errhint("%s", _(hintmsg)) : 0));
5498 if (newval->intval < conf->min || newval->intval > conf->max)
5501 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5502 errmsg("%d is outside the valid range for parameter \"%s\" (%d .. %d)",
5503 newval->intval, name,
5504 conf->min, conf->max)));
5508 if (!call_int_check_hook(conf, &newval->intval, newextra,
5515 struct config_real *conf = (struct config_real *) record;
5517 if (!parse_real(value, &newval->realval))
5520 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5521 errmsg("parameter \"%s\" requires a numeric value",
5526 if (newval->realval < conf->min || newval->realval > conf->max)
5529 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5530 errmsg("%g is outside the valid range for parameter \"%s\" (%g .. %g)",
5531 newval->realval, name,
5532 conf->min, conf->max)));
5536 if (!call_real_check_hook(conf, &newval->realval, newextra,
5543 struct config_string *conf = (struct config_string *) record;
5546 * The value passed by the caller could be transient, so we
5549 newval->stringval = guc_strdup(elevel, value);
5550 if (newval->stringval == NULL)
5554 * The only built-in "parsing" check we have is to apply
5555 * truncation if GUC_IS_NAME.
5557 if (conf->gen.flags & GUC_IS_NAME)
5558 truncate_identifier(newval->stringval,
5559 strlen(newval->stringval),
5562 if (!call_string_check_hook(conf, &newval->stringval, newextra,
5565 free(newval->stringval);
5566 newval->stringval = NULL;
5573 struct config_enum *conf = (struct config_enum *) record;
5575 if (!config_enum_lookup_by_name(conf, value, &newval->enumval))
5579 hintmsg = config_enum_get_options(conf,
5580 "Available values: ",
5584 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5585 errmsg("invalid value for parameter \"%s\": \"%s\"",
5587 hintmsg ? errhint("%s", _(hintmsg)) : 0));
5594 if (!call_enum_check_hook(conf, &newval->enumval, newextra,
5606 * Sets option `name' to given value.
5608 * The value should be a string, which will be parsed and converted to
5609 * the appropriate data type. The context and source parameters indicate
5610 * in which context this function is being called, so that it can apply the
5611 * access restrictions properly.
5613 * If value is NULL, set the option to its default value (normally the
5614 * reset_val, but if source == PGC_S_DEFAULT we instead use the boot_val).
5616 * action indicates whether to set the value globally in the session, locally
5617 * to the current top transaction, or just for the duration of a function call.
5619 * If changeVal is false then don't really set the option but do all
5620 * the checks to see if it would work.
5622 * elevel should normally be passed as zero, allowing this function to make
5623 * its standard choice of ereport level. However some callers need to be
5624 * able to override that choice; they should pass the ereport level to use.
5627 * +1: the value is valid and was successfully applied.
5628 * 0: the name or value is invalid (but see below).
5629 * -1: the value was not applied because of context, priority, or changeVal.
5631 * If there is an error (non-existing option, invalid value) then an
5632 * ereport(ERROR) is thrown *unless* this is called for a source for which
5633 * we don't want an ERROR (currently, those are defaults, the config file,
5634 * and per-database or per-user settings, as well as callers who specify
5635 * a less-than-ERROR elevel). In those cases we write a suitable error
5636 * message via ereport() and return 0.
5638 * See also SetConfigOption for an external interface.
5641 set_config_option(const char *name, const char *value,
5642 GucContext context, GucSource source,
5643 GucAction action, bool changeVal, int elevel,
5646 struct config_generic *record;
5647 union config_var_val newval_union;
5648 void *newextra = NULL;
5649 bool prohibitValueChange = false;
5654 if (source == PGC_S_DEFAULT || source == PGC_S_FILE)
5657 * To avoid cluttering the log, only the postmaster bleats loudly
5658 * about problems with the config file.
5660 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
5662 else if (source == PGC_S_GLOBAL ||
5663 source == PGC_S_DATABASE ||
5664 source == PGC_S_USER ||
5665 source == PGC_S_DATABASE_USER)
5672 * GUC_ACTION_SAVE changes are acceptable during a parallel operation,
5673 * because the current worker will also pop the change. We're probably
5674 * dealing with a function having a proconfig entry. Only the function's
5675 * body should observe the change, and peer workers do not share in the
5676 * execution of a function call started by this worker.
5678 * Other changes might need to affect other workers, so forbid them.
5680 if (IsInParallelMode() && changeVal && action != GUC_ACTION_SAVE)
5682 (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
5683 errmsg("cannot set parameters during a parallel operation")));
5685 record = find_option(name, true, elevel);
5689 (errcode(ERRCODE_UNDEFINED_OBJECT),
5690 errmsg("unrecognized configuration parameter \"%s\"", name)));
5695 * Check if the option can be set at this time. See guc.h for the precise
5698 switch (record->context)
5701 if (context != PGC_INTERNAL)
5704 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5705 errmsg("parameter \"%s\" cannot be changed",
5710 case PGC_POSTMASTER:
5711 if (context == PGC_SIGHUP)
5714 * We are re-reading a PGC_POSTMASTER variable from
5715 * postgresql.conf. We can't change the setting, so we should
5716 * give a warning if the DBA tries to change it. However,
5717 * because of variant formats, canonicalization by check
5718 * hooks, etc, we can't just compare the given string directly
5719 * to what's stored. Set a flag to check below after we have
5720 * the final storable value.
5722 prohibitValueChange = true;
5724 else if (context != PGC_POSTMASTER)
5727 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5728 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5734 if (context != PGC_SIGHUP && context != PGC_POSTMASTER)
5737 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5738 errmsg("parameter \"%s\" cannot be changed now",
5744 * Hmm, the idea of the SIGHUP context is "ought to be global, but
5745 * can be changed after postmaster start". But there's nothing
5746 * that prevents a crafty administrator from sending SIGHUP
5747 * signals to individual backends only.
5750 case PGC_SU_BACKEND:
5751 /* Reject if we're connecting but user is not superuser */
5752 if (context == PGC_BACKEND)
5755 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5756 errmsg("permission denied to set parameter \"%s\"",
5760 /* FALL THRU to process the same as PGC_BACKEND */
5762 if (context == PGC_SIGHUP)
5765 * If a PGC_BACKEND or PGC_SU_BACKEND parameter is changed in
5766 * the config file, we want to accept the new value in the
5767 * postmaster (whence it will propagate to
5768 * subsequently-started backends), but ignore it in existing
5769 * backends. This is a tad klugy, but necessary because we
5770 * don't re-read the config file during backend start.
5772 * In EXEC_BACKEND builds, this works differently: we load all
5773 * nondefault settings from the CONFIG_EXEC_PARAMS file during
5774 * backend start. In that case we must accept PGC_SIGHUP
5775 * settings, so as to have the same value as if we'd forked
5776 * from the postmaster. This can also happen when using
5777 * RestoreGUCState() within a background worker that needs to
5778 * have the same settings as the user backend that started it.
5779 * is_reload will be true when either situation applies.
5781 if (IsUnderPostmaster && !is_reload)
5784 else if (context != PGC_POSTMASTER &&
5785 context != PGC_BACKEND &&
5786 context != PGC_SU_BACKEND &&
5787 source != PGC_S_CLIENT)
5790 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5791 errmsg("parameter \"%s\" cannot be set after connection start",
5797 if (context == PGC_USERSET || context == PGC_BACKEND)
5800 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5801 errmsg("permission denied to set parameter \"%s\"",
5812 * Disallow changing GUC_NOT_WHILE_SEC_REST values if we are inside a
5813 * security restriction context. We can reject this regardless of the GUC
5814 * context or source, mainly because sources that it might be reasonable
5815 * to override for won't be seen while inside a function.
5817 * Note: variables marked GUC_NOT_WHILE_SEC_REST should usually be marked
5818 * GUC_NO_RESET_ALL as well, because ResetAllOptions() doesn't check this.
5819 * An exception might be made if the reset value is assumed to be "safe".
5821 * Note: this flag is currently used for "session_authorization" and
5822 * "role". We need to prohibit changing these inside a local userid
5823 * context because when we exit it, GUC won't be notified, leaving things
5824 * out of sync. (This could be fixed by forcing a new GUC nesting level,
5825 * but that would change behavior in possibly-undesirable ways.) Also, we
5826 * prohibit changing these in a security-restricted operation because
5827 * otherwise RESET could be used to regain the session user's privileges.
5829 if (record->flags & GUC_NOT_WHILE_SEC_REST)
5831 if (InLocalUserIdChange())
5834 * Phrasing of this error message is historical, but it's the most
5838 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5839 errmsg("cannot set parameter \"%s\" within security-definer function",
5843 if (InSecurityRestrictedOperation())
5846 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5847 errmsg("cannot set parameter \"%s\" within security-restricted operation",
5854 * Should we set reset/stacked values? (If so, the behavior is not
5855 * transactional.) This is done either when we get a default value from
5856 * the database's/user's/client's default settings or when we reset a
5857 * value to its default.
5859 makeDefault = changeVal && (source <= PGC_S_OVERRIDE) &&
5860 ((value != NULL) || source == PGC_S_DEFAULT);
5863 * Ignore attempted set if overridden by previously processed setting.
5864 * However, if changeVal is false then plow ahead anyway since we are
5865 * trying to find out if the value is potentially good, not actually use
5866 * it. Also keep going if makeDefault is true, since we may want to set
5867 * the reset/stacked values even if we can't set the variable itself.
5869 if (record->source > source)
5871 if (changeVal && !makeDefault)
5873 elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
5881 * Evaluate value and set variable.
5883 switch (record->vartype)
5887 struct config_bool *conf = (struct config_bool *) record;
5889 #define newval (newval_union.boolval)
5893 if (!parse_and_validate_value(record, name, value,
5895 &newval_union, &newextra))
5898 else if (source == PGC_S_DEFAULT)
5900 newval = conf->boot_val;
5901 if (!call_bool_check_hook(conf, &newval, &newextra,
5907 newval = conf->reset_val;
5908 newextra = conf->reset_extra;
5909 source = conf->gen.reset_source;
5910 context = conf->gen.reset_scontext;
5913 if (prohibitValueChange)
5915 if (*conf->variable != newval)
5917 record->status |= GUC_PENDING_RESTART;
5919 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5920 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5924 record->status &= ~GUC_PENDING_RESTART;
5930 /* Save old value to support transaction abort */
5932 push_old_value(&conf->gen, action);
5934 if (conf->assign_hook)
5935 (*conf->assign_hook) (newval, newextra);
5936 *conf->variable = newval;
5937 set_extra_field(&conf->gen, &conf->gen.extra,
5939 conf->gen.source = source;
5940 conf->gen.scontext = context;
5946 if (conf->gen.reset_source <= source)
5948 conf->reset_val = newval;
5949 set_extra_field(&conf->gen, &conf->reset_extra,
5951 conf->gen.reset_source = source;
5952 conf->gen.reset_scontext = context;
5954 for (stack = conf->gen.stack; stack; stack = stack->prev)
5956 if (stack->source <= source)
5958 stack->prior.val.boolval = newval;
5959 set_extra_field(&conf->gen, &stack->prior.extra,
5961 stack->source = source;
5962 stack->scontext = context;
5967 /* Perhaps we didn't install newextra anywhere */
5968 if (newextra && !extra_field_used(&conf->gen, newextra))
5977 struct config_int *conf = (struct config_int *) record;
5979 #define newval (newval_union.intval)
5983 if (!parse_and_validate_value(record, name, value,
5985 &newval_union, &newextra))
5988 else if (source == PGC_S_DEFAULT)
5990 newval = conf->boot_val;
5991 if (!call_int_check_hook(conf, &newval, &newextra,
5997 newval = conf->reset_val;
5998 newextra = conf->reset_extra;
5999 source = conf->gen.reset_source;
6000 context = conf->gen.reset_scontext;
6003 if (prohibitValueChange)
6005 if (*conf->variable != newval)
6007 record->status |= GUC_PENDING_RESTART;
6009 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6010 errmsg("parameter \"%s\" cannot be changed without restarting the server",
6014 record->status &= ~GUC_PENDING_RESTART;
6020 /* Save old value to support transaction abort */
6022 push_old_value(&conf->gen, action);
6024 if (conf->assign_hook)
6025 (*conf->assign_hook) (newval, newextra);
6026 *conf->variable = newval;
6027 set_extra_field(&conf->gen, &conf->gen.extra,
6029 conf->gen.source = source;
6030 conf->gen.scontext = context;
6036 if (conf->gen.reset_source <= source)
6038 conf->reset_val = newval;
6039 set_extra_field(&conf->gen, &conf->reset_extra,
6041 conf->gen.reset_source = source;
6042 conf->gen.reset_scontext = context;
6044 for (stack = conf->gen.stack; stack; stack = stack->prev)
6046 if (stack->source <= source)
6048 stack->prior.val.intval = newval;
6049 set_extra_field(&conf->gen, &stack->prior.extra,
6051 stack->source = source;
6052 stack->scontext = context;
6057 /* Perhaps we didn't install newextra anywhere */
6058 if (newextra && !extra_field_used(&conf->gen, newextra))
6067 struct config_real *conf = (struct config_real *) record;
6069 #define newval (newval_union.realval)
6073 if (!parse_and_validate_value(record, name, value,
6075 &newval_union, &newextra))
6078 else if (source == PGC_S_DEFAULT)
6080 newval = conf->boot_val;
6081 if (!call_real_check_hook(conf, &newval, &newextra,
6087 newval = conf->reset_val;
6088 newextra = conf->reset_extra;
6089 source = conf->gen.reset_source;
6090 context = conf->gen.reset_scontext;
6093 if (prohibitValueChange)
6095 if (*conf->variable != newval)
6097 record->status |= GUC_PENDING_RESTART;
6099 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6100 errmsg("parameter \"%s\" cannot be changed without restarting the server",
6104 record->status &= ~GUC_PENDING_RESTART;
6110 /* Save old value to support transaction abort */
6112 push_old_value(&conf->gen, action);
6114 if (conf->assign_hook)
6115 (*conf->assign_hook) (newval, newextra);
6116 *conf->variable = newval;
6117 set_extra_field(&conf->gen, &conf->gen.extra,
6119 conf->gen.source = source;
6120 conf->gen.scontext = context;
6126 if (conf->gen.reset_source <= source)
6128 conf->reset_val = newval;
6129 set_extra_field(&conf->gen, &conf->reset_extra,
6131 conf->gen.reset_source = source;
6132 conf->gen.reset_scontext = context;
6134 for (stack = conf->gen.stack; stack; stack = stack->prev)
6136 if (stack->source <= source)
6138 stack->prior.val.realval = newval;
6139 set_extra_field(&conf->gen, &stack->prior.extra,
6141 stack->source = source;
6142 stack->scontext = context;
6147 /* Perhaps we didn't install newextra anywhere */
6148 if (newextra && !extra_field_used(&conf->gen, newextra))
6157 struct config_string *conf = (struct config_string *) record;
6159 #define newval (newval_union.stringval)
6163 if (!parse_and_validate_value(record, name, value,
6165 &newval_union, &newextra))
6168 else if (source == PGC_S_DEFAULT)
6170 /* non-NULL boot_val must always get strdup'd */
6171 if (conf->boot_val != NULL)
6173 newval = guc_strdup(elevel, conf->boot_val);
6180 if (!call_string_check_hook(conf, &newval, &newextra,
6190 * strdup not needed, since reset_val is already under
6193 newval = conf->reset_val;
6194 newextra = conf->reset_extra;
6195 source = conf->gen.reset_source;
6196 context = conf->gen.reset_scontext;
6199 if (prohibitValueChange)
6201 /* newval shouldn't be NULL, so we're a bit sloppy here */
6202 if (*conf->variable == NULL || newval == NULL ||
6203 strcmp(*conf->variable, newval) != 0)
6205 record->status |= GUC_PENDING_RESTART;
6207 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6208 errmsg("parameter \"%s\" cannot be changed without restarting the server",
6212 record->status &= ~GUC_PENDING_RESTART;
6218 /* Save old value to support transaction abort */
6220 push_old_value(&conf->gen, action);
6222 if (conf->assign_hook)
6223 (*conf->assign_hook) (newval, newextra);
6224 set_string_field(conf, conf->variable, newval);
6225 set_extra_field(&conf->gen, &conf->gen.extra,
6227 conf->gen.source = source;
6228 conf->gen.scontext = context;
6235 if (conf->gen.reset_source <= source)
6237 set_string_field(conf, &conf->reset_val, newval);
6238 set_extra_field(&conf->gen, &conf->reset_extra,
6240 conf->gen.reset_source = source;
6241 conf->gen.reset_scontext = context;
6243 for (stack = conf->gen.stack; stack; stack = stack->prev)
6245 if (stack->source <= source)
6247 set_string_field(conf, &stack->prior.val.stringval,
6249 set_extra_field(&conf->gen, &stack->prior.extra,
6251 stack->source = source;
6252 stack->scontext = context;
6257 /* Perhaps we didn't install newval anywhere */
6258 if (newval && !string_field_used(conf, newval))
6260 /* Perhaps we didn't install newextra anywhere */
6261 if (newextra && !extra_field_used(&conf->gen, newextra))
6270 struct config_enum *conf = (struct config_enum *) record;
6272 #define newval (newval_union.enumval)
6276 if (!parse_and_validate_value(record, name, value,
6278 &newval_union, &newextra))
6281 else if (source == PGC_S_DEFAULT)
6283 newval = conf->boot_val;
6284 if (!call_enum_check_hook(conf, &newval, &newextra,
6290 newval = conf->reset_val;
6291 newextra = conf->reset_extra;
6292 source = conf->gen.reset_source;
6293 context = conf->gen.reset_scontext;
6296 if (prohibitValueChange)
6298 if (*conf->variable != newval)
6300 record->status |= GUC_PENDING_RESTART;
6302 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6303 errmsg("parameter \"%s\" cannot be changed without restarting the server",
6307 record->status &= ~GUC_PENDING_RESTART;
6313 /* Save old value to support transaction abort */
6315 push_old_value(&conf->gen, action);
6317 if (conf->assign_hook)
6318 (*conf->assign_hook) (newval, newextra);
6319 *conf->variable = newval;
6320 set_extra_field(&conf->gen, &conf->gen.extra,
6322 conf->gen.source = source;
6323 conf->gen.scontext = context;
6329 if (conf->gen.reset_source <= source)
6331 conf->reset_val = newval;
6332 set_extra_field(&conf->gen, &conf->reset_extra,
6334 conf->gen.reset_source = source;
6335 conf->gen.reset_scontext = context;
6337 for (stack = conf->gen.stack; stack; stack = stack->prev)
6339 if (stack->source <= source)
6341 stack->prior.val.enumval = newval;
6342 set_extra_field(&conf->gen, &stack->prior.extra,
6344 stack->source = source;
6345 stack->scontext = context;
6350 /* Perhaps we didn't install newextra anywhere */
6351 if (newextra && !extra_field_used(&conf->gen, newextra))
6359 if (changeVal && (record->flags & GUC_REPORT))
6360 ReportGUCOption(record);
6362 return changeVal ? 1 : -1;
6367 * Set the fields for source file and line number the setting came from.
6370 set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
6372 struct config_generic *record;
6376 * To avoid cluttering the log, only the postmaster bleats loudly about
6377 * problems with the config file.
6379 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
6381 record = find_option(name, true, elevel);
6382 /* should not happen */
6384 elog(ERROR, "unrecognized configuration parameter \"%s\"", name);
6386 sourcefile = guc_strdup(elevel, sourcefile);
6387 if (record->sourcefile)
6388 free(record->sourcefile);
6389 record->sourcefile = sourcefile;
6390 record->sourceline = sourceline;
6394 * Set a config option to the given value.
6396 * See also set_config_option; this is just the wrapper to be called from
6397 * outside GUC. (This function should be used when possible, because its API
6398 * is more stable than set_config_option's.)
6400 * Note: there is no support here for setting source file/line, as it
6401 * is currently not needed.
6404 SetConfigOption(const char *name, const char *value,
6405 GucContext context, GucSource source)
6407 (void) set_config_option(name, value, context, source,
6408 GUC_ACTION_SET, true, 0, false);
6414 * Fetch the current value of the option `name', as a string.
6416 * If the option doesn't exist, return NULL if missing_ok is true (NOTE that
6417 * this cannot be distinguished from a string variable with a NULL value!),
6418 * otherwise throw an ereport and don't return.
6420 * If restrict_superuser is true, we also enforce that only superusers can
6421 * see GUC_SUPERUSER_ONLY variables. This should only be passed as true
6422 * in user-driven calls.
6424 * The string is *not* allocated for modification and is really only
6425 * valid until the next call to configuration related functions.
6428 GetConfigOption(const char *name, bool missing_ok, bool restrict_superuser)
6430 struct config_generic *record;
6431 static char buffer[256];
6433 record = find_option(name, false, ERROR);
6439 (errcode(ERRCODE_UNDEFINED_OBJECT),
6440 errmsg("unrecognized configuration parameter \"%s\"",
6443 if (restrict_superuser &&
6444 (record->flags & GUC_SUPERUSER_ONLY) &&
6447 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6448 errmsg("must be superuser to examine \"%s\"", name)));
6450 switch (record->vartype)
6453 return *((struct config_bool *) record)->variable ? "on" : "off";
6456 snprintf(buffer, sizeof(buffer), "%d",
6457 *((struct config_int *) record)->variable);
6461 snprintf(buffer, sizeof(buffer), "%g",
6462 *((struct config_real *) record)->variable);
6466 return *((struct config_string *) record)->variable;
6469 return config_enum_lookup_by_value((struct config_enum *) record,
6470 *((struct config_enum *) record)->variable);
6476 * Get the RESET value associated with the given option.
6478 * Note: this is not re-entrant, due to use of static result buffer;
6479 * not to mention that a string variable could have its reset_val changed.
6480 * Beware of assuming the result value is good for very long.
6483 GetConfigOptionResetString(const char *name)
6485 struct config_generic *record;
6486 static char buffer[256];
6488 record = find_option(name, false, ERROR);
6491 (errcode(ERRCODE_UNDEFINED_OBJECT),
6492 errmsg("unrecognized configuration parameter \"%s\"", name)));
6493 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
6495 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6496 errmsg("must be superuser to examine \"%s\"", name)));
6498 switch (record->vartype)
6501 return ((struct config_bool *) record)->reset_val ? "on" : "off";
6504 snprintf(buffer, sizeof(buffer), "%d",
6505 ((struct config_int *) record)->reset_val);
6509 snprintf(buffer, sizeof(buffer), "%g",
6510 ((struct config_real *) record)->reset_val);
6514 return ((struct config_string *) record)->reset_val;
6517 return config_enum_lookup_by_value((struct config_enum *) record,
6518 ((struct config_enum *) record)->reset_val);
6525 * flatten_set_variable_args
6526 * Given a parsenode List as emitted by the grammar for SET,
6527 * convert to the flat string representation used by GUC.
6529 * We need to be told the name of the variable the args are for, because
6530 * the flattening rules vary (ugh).
6532 * The result is NULL if args is NIL (ie, SET ... TO DEFAULT), otherwise
6533 * a palloc'd string.
6536 flatten_set_variable_args(const char *name, List *args)
6538 struct config_generic *record;
6543 /* Fast path if just DEFAULT */
6548 * Get flags for the variable; if it's not known, use default flags.
6549 * (Caller might throw error later, but not our business to do so here.)
6551 record = find_option(name, false, WARNING);
6553 flags = record->flags;
6557 /* Complain if list input and non-list variable */
6558 if ((flags & GUC_LIST_INPUT) == 0 &&
6559 list_length(args) != 1)
6561 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6562 errmsg("SET %s takes only one argument", name)));
6564 initStringInfo(&buf);
6567 * Each list member may be a plain A_Const node, or an A_Const within a
6568 * TypeCast; the latter case is supported only for ConstInterval arguments
6569 * (for SET TIME ZONE).
6573 Node *arg = (Node *) lfirst(l);
6575 TypeName *typeName = NULL;
6578 if (l != list_head(args))
6579 appendStringInfoString(&buf, ", ");
6581 if (IsA(arg, TypeCast))
6583 TypeCast *tc = (TypeCast *) arg;
6586 typeName = tc->typeName;
6589 if (!IsA(arg, A_Const))
6590 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
6591 con = (A_Const *) arg;
6593 switch (nodeTag(&con->val))
6596 appendStringInfo(&buf, "%ld", intVal(&con->val));
6599 /* represented as a string, so just copy it */
6600 appendStringInfoString(&buf, strVal(&con->val));
6603 val = strVal(&con->val);
6604 if (typeName != NULL)
6607 * Must be a ConstInterval argument for TIME ZONE. Coerce
6608 * to interval and back to normalize the value and account
6616 typenameTypeIdAndMod(NULL, typeName, &typoid, &typmod);
6617 Assert(typoid == INTERVALOID);
6620 DirectFunctionCall3(interval_in,
6621 CStringGetDatum(val),
6622 ObjectIdGetDatum(InvalidOid),
6623 Int32GetDatum(typmod));
6626 DatumGetCString(DirectFunctionCall1(interval_out,
6628 appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
6633 * Plain string literal or identifier. For quote mode,
6634 * quote it if it's not a vanilla identifier.
6636 if (flags & GUC_LIST_QUOTE)
6637 appendStringInfoString(&buf, quote_identifier(val));
6639 appendStringInfoString(&buf, val);
6643 elog(ERROR, "unrecognized node type: %d",
6644 (int) nodeTag(&con->val));
6653 * Write updated configuration parameter values into a temporary file.
6654 * This function traverses the list of parameters and quotes the string
6655 * values before writing them.
6658 write_auto_conf_file(int fd, const char *filename, ConfigVariable *head)
6661 ConfigVariable *item;
6663 initStringInfo(&buf);
6665 /* Emit file header containing warning comment */
6666 appendStringInfoString(&buf, "# Do not edit this file manually!\n");
6667 appendStringInfoString(&buf, "# It will be overwritten by ALTER SYSTEM command.\n");
6670 if (write(fd, buf.data, buf.len) != buf.len)
6672 /* if write didn't set errno, assume problem is no disk space */
6676 (errcode_for_file_access(),
6677 errmsg("could not write to file \"%s\": %m", filename)));
6680 /* Emit each parameter, properly quoting the value */
6681 for (item = head; item != NULL; item = item->next)
6685 resetStringInfo(&buf);
6687 appendStringInfoString(&buf, item->name);
6688 appendStringInfoString(&buf, " = '");
6690 escaped = escape_single_quotes_ascii(item->value);
6693 (errcode(ERRCODE_OUT_OF_MEMORY),
6694 errmsg("out of memory")));
6695 appendStringInfoString(&buf, escaped);
6698 appendStringInfoString(&buf, "'\n");
6701 if (write(fd, buf.data, buf.len) != buf.len)
6703 /* if write didn't set errno, assume problem is no disk space */
6707 (errcode_for_file_access(),
6708 errmsg("could not write to file \"%s\": %m", filename)));
6712 /* fsync before considering the write to be successful */
6713 if (pg_fsync(fd) != 0)
6715 (errcode_for_file_access(),
6716 errmsg("could not fsync file \"%s\": %m", filename)));
6722 * Update the given list of configuration parameters, adding, replacing
6723 * or deleting the entry for item "name" (delete if "value" == NULL).
6726 replace_auto_config_value(ConfigVariable **head_p, ConfigVariable **tail_p,
6727 const char *name, const char *value)
6729 ConfigVariable *item,
6732 /* Search the list for an existing match (we assume there's only one) */
6733 for (item = *head_p; item != NULL; item = item->next)
6735 if (strcmp(item->name, name) == 0)
6737 /* found a match, replace it */
6741 /* update the parameter value */
6742 item->value = pstrdup(value);
6746 /* delete the configuration parameter from list */
6747 if (*head_p == item)
6748 *head_p = item->next;
6750 prev->next = item->next;
6751 if (*tail_p == item)
6755 pfree(item->filename);
6763 /* Not there; no work if we're trying to delete it */
6767 /* OK, append a new entry */
6768 item = palloc(sizeof *item);
6769 item->name = pstrdup(name);
6770 item->value = pstrdup(value);
6771 item->errmsg = NULL;
6772 item->filename = pstrdup(""); /* new item has no location */
6773 item->sourceline = 0;
6774 item->ignore = false;
6775 item->applied = false;
6778 if (*head_p == NULL)
6781 (*tail_p)->next = item;
6787 * Execute ALTER SYSTEM statement.
6789 * Read the old PG_AUTOCONF_FILENAME file, merge in the new variable value,
6790 * and write out an updated file. If the command is ALTER SYSTEM RESET ALL,
6791 * we can skip reading the old file and just write an empty file.
6793 * An LWLock is used to serialize updates of the configuration file.
6795 * In case of an error, we leave the original automatic
6796 * configuration file (PG_AUTOCONF_FILENAME) intact.
6799 AlterSystemSetConfigFile(AlterSystemStmt *altersysstmt)
6803 bool resetall = false;
6804 ConfigVariable *head = NULL;
6805 ConfigVariable *tail = NULL;
6807 char AutoConfFileName[MAXPGPATH];
6808 char AutoConfTmpFileName[MAXPGPATH];
6812 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6813 (errmsg("must be superuser to execute ALTER SYSTEM command"))));
6816 * Extract statement arguments
6818 name = altersysstmt->setstmt->name;
6820 switch (altersysstmt->setstmt->kind)
6823 value = ExtractSetVariableArgs(altersysstmt->setstmt);
6826 case VAR_SET_DEFAULT:
6837 elog(ERROR, "unrecognized alter system stmt type: %d",
6838 altersysstmt->setstmt->kind);
6843 * Unless it's RESET_ALL, validate the target variable and value
6847 struct config_generic *record;
6849 record = find_option(name, false, ERROR);
6852 (errcode(ERRCODE_UNDEFINED_OBJECT),
6853 errmsg("unrecognized configuration parameter \"%s\"",
6857 * Don't allow parameters that can't be set in configuration files to
6858 * be set in PG_AUTOCONF_FILENAME file.
6860 if ((record->context == PGC_INTERNAL) ||
6861 (record->flags & GUC_DISALLOW_IN_FILE) ||
6862 (record->flags & GUC_DISALLOW_IN_AUTO_FILE))
6864 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6865 errmsg("parameter \"%s\" cannot be changed",
6870 union config_var_val newval;
6871 void *newextra = NULL;
6873 if (!parse_and_validate_value(record, name, value,
6875 &newval, &newextra))
6877 (errmsg("invalid value for parameter \"%s\": \"%s\"",
6880 if (record->vartype == PGC_STRING && newval.stringval != NULL)
6881 free(newval.stringval);
6888 * PG_AUTOCONF_FILENAME and its corresponding temporary file are always in
6889 * the data directory, so we can reference them by simple relative paths.
6891 snprintf(AutoConfFileName, sizeof(AutoConfFileName), "%s",
6892 PG_AUTOCONF_FILENAME);
6893 snprintf(AutoConfTmpFileName, sizeof(AutoConfTmpFileName), "%s.%s",
6898 * Only one backend is allowed to operate on PG_AUTOCONF_FILENAME at a
6899 * time. Use AutoFileLock to ensure that. We must hold the lock while
6900 * reading the old file contents.
6902 LWLockAcquire(AutoFileLock, LW_EXCLUSIVE);
6905 * If we're going to reset everything, then no need to open or parse the
6906 * old file. We'll just write out an empty list.
6912 if (stat(AutoConfFileName, &st) == 0)
6914 /* open old file PG_AUTOCONF_FILENAME */
6917 infile = AllocateFile(AutoConfFileName, "r");
6920 (errmsg("could not open file \"%s\": %m",
6921 AutoConfFileName)));
6924 if (!ParseConfigFp(infile, AutoConfFileName, 0, LOG, &head, &tail))
6926 (errmsg("could not parse contents of file \"%s\"",
6927 AutoConfFileName)));
6933 * Now, replace any existing entry with the new value, or add it if
6936 replace_auto_config_value(&head, &tail, name, value);
6940 * To ensure crash safety, first write the new file data to a temp file,
6941 * then atomically rename it into place.
6943 * If there is a temp file left over due to a previous crash, it's okay to
6944 * truncate and reuse it.
6946 Tmpfd = BasicOpenFile(AutoConfTmpFileName,
6947 O_CREAT | O_RDWR | O_TRUNC,
6951 (errcode_for_file_access(),
6952 errmsg("could not open file \"%s\": %m",
6953 AutoConfTmpFileName)));
6956 * Use a TRY block to clean up the file if we fail. Since we need a TRY
6957 * block anyway, OK to use BasicOpenFile rather than OpenTransientFile.
6961 /* Write and sync the new contents to the temporary file */
6962 write_auto_conf_file(Tmpfd, AutoConfTmpFileName, head);
6964 /* Close before renaming; may be required on some platforms */
6969 * As the rename is atomic operation, if any problem occurs after this
6970 * at worst it can lose the parameters set by last ALTER SYSTEM
6973 if (rename(AutoConfTmpFileName, AutoConfFileName) < 0)
6975 (errcode_for_file_access(),
6976 errmsg("could not rename file \"%s\" to \"%s\": %m",
6977 AutoConfTmpFileName, AutoConfFileName)));
6981 /* Close file first, else unlink might fail on some platforms */
6985 /* Unlink, but ignore any error */
6986 (void) unlink(AutoConfTmpFileName);
6992 FreeConfigVariables(head);
6994 LWLockRelease(AutoFileLock);
7001 ExecSetVariableStmt(VariableSetStmt *stmt, bool isTopLevel)
7003 GucAction action = stmt->is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET;
7006 * Workers synchronize these parameters at the start of the parallel
7007 * operation; then, we block SET during the operation.
7009 if (IsInParallelMode())
7011 (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
7012 errmsg("cannot set parameters during a parallel operation")));
7017 case VAR_SET_CURRENT:
7019 WarnNoTransactionChain(isTopLevel, "SET LOCAL");
7020 (void) set_config_option(stmt->name,
7021 ExtractSetVariableArgs(stmt),
7022 (superuser() ? PGC_SUSET : PGC_USERSET),
7024 action, true, 0, false);
7029 * Special-case SQL syntaxes. The TRANSACTION and SESSION
7030 * CHARACTERISTICS cases effectively set more than one variable
7031 * per statement. TRANSACTION SNAPSHOT only takes one argument,
7032 * but we put it here anyway since it's a special case and not
7033 * related to any GUC variable.
7035 if (strcmp(stmt->name, "TRANSACTION") == 0)
7039 WarnNoTransactionChain(isTopLevel, "SET TRANSACTION");
7041 foreach(head, stmt->args)
7043 DefElem *item = (DefElem *) lfirst(head);
7045 if (strcmp(item->defname, "transaction_isolation") == 0)
7046 SetPGVariable("transaction_isolation",
7047 list_make1(item->arg), stmt->is_local);
7048 else if (strcmp(item->defname, "transaction_read_only") == 0)
7049 SetPGVariable("transaction_read_only",
7050 list_make1(item->arg), stmt->is_local);
7051 else if (strcmp(item->defname, "transaction_deferrable") == 0)
7052 SetPGVariable("transaction_deferrable",
7053 list_make1(item->arg), stmt->is_local);
7055 elog(ERROR, "unexpected SET TRANSACTION element: %s",
7059 else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
7063 foreach(head, stmt->args)
7065 DefElem *item = (DefElem *) lfirst(head);
7067 if (strcmp(item->defname, "transaction_isolation") == 0)
7068 SetPGVariable("default_transaction_isolation",
7069 list_make1(item->arg), stmt->is_local);
7070 else if (strcmp(item->defname, "transaction_read_only") == 0)
7071 SetPGVariable("default_transaction_read_only",
7072 list_make1(item->arg), stmt->is_local);
7073 else if (strcmp(item->defname, "transaction_deferrable") == 0)
7074 SetPGVariable("default_transaction_deferrable",
7075 list_make1(item->arg), stmt->is_local);
7077 elog(ERROR, "unexpected SET SESSION element: %s",
7081 else if (strcmp(stmt->name, "TRANSACTION SNAPSHOT") == 0)
7083 A_Const *con = (A_Const *) linitial(stmt->args);
7087 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7088 errmsg("SET LOCAL TRANSACTION SNAPSHOT is not implemented")));
7090 WarnNoTransactionChain(isTopLevel, "SET TRANSACTION");
7091 Assert(IsA(con, A_Const));
7092 Assert(nodeTag(&con->val) == T_String);
7093 ImportSnapshot(strVal(&con->val));
7096 elog(ERROR, "unexpected SET MULTI element: %s",
7099 case VAR_SET_DEFAULT:
7101 WarnNoTransactionChain(isTopLevel, "SET LOCAL");
7104 if (strcmp(stmt->name, "transaction_isolation") == 0)
7105 WarnNoTransactionChain(isTopLevel, "RESET TRANSACTION");
7107 (void) set_config_option(stmt->name,
7109 (superuser() ? PGC_SUSET : PGC_USERSET),
7111 action, true, 0, false);
7120 * Get the value to assign for a VariableSetStmt, or NULL if it's RESET.
7121 * The result is palloc'd.
7123 * This is exported for use by actions such as ALTER ROLE SET.
7126 ExtractSetVariableArgs(VariableSetStmt *stmt)
7131 return flatten_set_variable_args(stmt->name, stmt->args);
7132 case VAR_SET_CURRENT:
7133 return GetConfigOptionByName(stmt->name, NULL, false);
7140 * SetPGVariable - SET command exported as an easily-C-callable function.
7142 * This provides access to SET TO value, as well as SET TO DEFAULT (expressed
7143 * by passing args == NIL), but not SET FROM CURRENT functionality.
7146 SetPGVariable(const char *name, List *args, bool is_local)
7148 char *argstring = flatten_set_variable_args(name, args);
7150 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
7151 (void) set_config_option(name,
7153 (superuser() ? PGC_SUSET : PGC_USERSET),
7155 is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET,
7160 * SET command wrapped as a SQL callable function.
7163 set_config_by_name(PG_FUNCTION_ARGS)
7170 if (PG_ARGISNULL(0))
7172 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
7173 errmsg("SET requires parameter name")));
7175 /* Get the GUC variable name */
7176 name = TextDatumGetCString(PG_GETARG_DATUM(0));
7178 /* Get the desired value or set to NULL for a reset request */
7179 if (PG_ARGISNULL(1))
7182 value = TextDatumGetCString(PG_GETARG_DATUM(1));
7185 * Get the desired state of is_local. Default to false if provided value
7188 if (PG_ARGISNULL(2))
7191 is_local = PG_GETARG_BOOL(2);
7193 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
7194 (void) set_config_option(name,
7196 (superuser() ? PGC_SUSET : PGC_USERSET),
7198 is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET,
7201 /* get the new current value */
7202 new_value = GetConfigOptionByName(name, NULL, false);
7204 /* Convert return string to text */
7205 PG_RETURN_TEXT_P(cstring_to_text(new_value));
7210 * Common code for DefineCustomXXXVariable subroutines: allocate the
7211 * new variable's config struct and fill in generic fields.
7213 static struct config_generic *
7214 init_custom_variable(const char *name,
7215 const char *short_desc,
7216 const char *long_desc,
7219 enum config_type type,
7222 struct config_generic *gen;
7225 * Only allow custom PGC_POSTMASTER variables to be created during shared
7226 * library preload; any later than that, we can't ensure that the value
7227 * doesn't change after startup. This is a fatal elog if it happens; just
7228 * erroring out isn't safe because we don't know what the calling loadable
7229 * module might already have hooked into.
7231 if (context == PGC_POSTMASTER &&
7232 !process_shared_preload_libraries_in_progress)
7233 elog(FATAL, "cannot create PGC_POSTMASTER variables after startup");
7235 gen = (struct config_generic *) guc_malloc(ERROR, sz);
7238 gen->name = guc_strdup(ERROR, name);
7239 gen->context = context;
7240 gen->group = CUSTOM_OPTIONS;
7241 gen->short_desc = short_desc;
7242 gen->long_desc = long_desc;
7244 gen->vartype = type;
7250 * Common code for DefineCustomXXXVariable subroutines: insert the new
7251 * variable into the GUC variable array, replacing any placeholder.
7254 define_custom_variable(struct config_generic * variable)
7256 const char *name = variable->name;
7257 const char **nameAddr = &name;
7258 struct config_string *pHolder;
7259 struct config_generic **res;
7262 * See if there's a placeholder by the same name.
7264 res = (struct config_generic **) bsearch((void *) &nameAddr,
7265 (void *) guc_variables,
7267 sizeof(struct config_generic *),
7272 * No placeholder to replace, so we can just add it ... but first,
7273 * make sure it's initialized to its default value.
7275 InitializeOneGUCOption(variable);
7276 add_guc_variable(variable, ERROR);
7281 * This better be a placeholder
7283 if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
7285 (errcode(ERRCODE_INTERNAL_ERROR),
7286 errmsg("attempt to redefine parameter \"%s\"", name)));
7288 Assert((*res)->vartype == PGC_STRING);
7289 pHolder = (struct config_string *) (*res);
7292 * First, set the variable to its default value. We must do this even
7293 * though we intend to immediately apply a new value, since it's possible
7294 * that the new value is invalid.
7296 InitializeOneGUCOption(variable);
7299 * Replace the placeholder. We aren't changing the name, so no re-sorting
7305 * Assign the string value(s) stored in the placeholder to the real
7306 * variable. Essentially, we need to duplicate all the active and stacked
7307 * values, but with appropriate validation and datatype adjustment.
7309 * If an assignment fails, we report a WARNING and keep going. We don't
7310 * want to throw ERROR for bad values, because it'd bollix the add-on
7311 * module that's presumably halfway through getting loaded. In such cases
7312 * the default or previous state will become active instead.
7315 /* First, apply the reset value if any */
7316 if (pHolder->reset_val)
7317 (void) set_config_option(name, pHolder->reset_val,
7318 pHolder->gen.reset_scontext,
7319 pHolder->gen.reset_source,
7320 GUC_ACTION_SET, true, WARNING, false);
7321 /* That should not have resulted in stacking anything */
7322 Assert(variable->stack == NULL);
7324 /* Now, apply current and stacked values, in the order they were stacked */
7325 reapply_stacked_values(variable, pHolder, pHolder->gen.stack,
7326 *(pHolder->variable),
7327 pHolder->gen.scontext, pHolder->gen.source);
7329 /* Also copy over any saved source-location information */
7330 if (pHolder->gen.sourcefile)
7331 set_config_sourcefile(name, pHolder->gen.sourcefile,
7332 pHolder->gen.sourceline);
7335 * Free up as much as we conveniently can of the placeholder structure.
7336 * (This neglects any stack items, so it's possible for some memory to be
7337 * leaked. Since this can only happen once per session per variable, it
7338 * doesn't seem worth spending much code on.)
7340 set_string_field(pHolder, pHolder->variable, NULL);
7341 set_string_field(pHolder, &pHolder->reset_val, NULL);
7347 * Recursive subroutine for define_custom_variable: reapply non-reset values
7349 * We recurse so that the values are applied in the same order as originally.
7350 * At each recursion level, apply the upper-level value (passed in) in the
7351 * fashion implied by the stack entry.
7354 reapply_stacked_values(struct config_generic * variable,
7355 struct config_string * pHolder,
7357 const char *curvalue,
7358 GucContext curscontext, GucSource cursource)
7360 const char *name = variable->name;
7361 GucStack *oldvarstack = variable->stack;
7365 /* First, recurse, so that stack items are processed bottom to top */
7366 reapply_stacked_values(variable, pHolder, stack->prev,
7367 stack->prior.val.stringval,
7368 stack->scontext, stack->source);
7370 /* See how to apply the passed-in value */
7371 switch (stack->state)
7374 (void) set_config_option(name, curvalue,
7375 curscontext, cursource,
7376 GUC_ACTION_SAVE, true,
7381 (void) set_config_option(name, curvalue,
7382 curscontext, cursource,
7383 GUC_ACTION_SET, true,
7388 (void) set_config_option(name, curvalue,
7389 curscontext, cursource,
7390 GUC_ACTION_LOCAL, true,
7395 /* first, apply the masked value as SET */
7396 (void) set_config_option(name, stack->masked.val.stringval,
7397 stack->masked_scontext, PGC_S_SESSION,
7398 GUC_ACTION_SET, true,
7400 /* then apply the current value as LOCAL */
7401 (void) set_config_option(name, curvalue,
7402 curscontext, cursource,
7403 GUC_ACTION_LOCAL, true,
7408 /* If we successfully made a stack entry, adjust its nest level */
7409 if (variable->stack != oldvarstack)
7410 variable->stack->nest_level = stack->nest_level;
7415 * We are at the end of the stack. If the active/previous value is
7416 * different from the reset value, it must represent a previously
7417 * committed session value. Apply it, and then drop the stack entry
7418 * that set_config_option will have created under the impression that
7419 * this is to be just a transactional assignment. (We leak the stack
7422 if (curvalue != pHolder->reset_val ||
7423 curscontext != pHolder->gen.reset_scontext ||
7424 cursource != pHolder->gen.reset_source)
7426 (void) set_config_option(name, curvalue,
7427 curscontext, cursource,
7428 GUC_ACTION_SET, true, WARNING, false);
7429 variable->stack = NULL;
7435 DefineCustomBoolVariable(const char *name,
7436 const char *short_desc,
7437 const char *long_desc,
7442 GucBoolCheckHook check_hook,
7443 GucBoolAssignHook assign_hook,
7444 GucShowHook show_hook)
7446 struct config_bool *var;
7448 var = (struct config_bool *)
7449 init_custom_variable(name, short_desc, long_desc, context, flags,
7450 PGC_BOOL, sizeof(struct config_bool));
7451 var->variable = valueAddr;
7452 var->boot_val = bootValue;
7453 var->reset_val = bootValue;
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 DefineCustomIntVariable(const char *name,
7462 const char *short_desc,
7463 const char *long_desc,
7470 GucIntCheckHook check_hook,
7471 GucIntAssignHook assign_hook,
7472 GucShowHook show_hook)
7474 struct config_int *var;
7476 var = (struct config_int *)
7477 init_custom_variable(name, short_desc, long_desc, context, flags,
7478 PGC_INT, sizeof(struct config_int));
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 DefineCustomRealVariable(const char *name,
7492 const char *short_desc,
7493 const char *long_desc,
7500 GucRealCheckHook check_hook,
7501 GucRealAssignHook assign_hook,
7502 GucShowHook show_hook)
7504 struct config_real *var;
7506 var = (struct config_real *)
7507 init_custom_variable(name, short_desc, long_desc, context, flags,
7508 PGC_REAL, sizeof(struct config_real));
7509 var->variable = valueAddr;
7510 var->boot_val = bootValue;
7511 var->reset_val = bootValue;
7512 var->min = minValue;
7513 var->max = maxValue;
7514 var->check_hook = check_hook;
7515 var->assign_hook = assign_hook;
7516 var->show_hook = show_hook;
7517 define_custom_variable(&var->gen);
7521 DefineCustomStringVariable(const char *name,
7522 const char *short_desc,
7523 const char *long_desc,
7525 const char *bootValue,
7528 GucStringCheckHook check_hook,
7529 GucStringAssignHook assign_hook,
7530 GucShowHook show_hook)
7532 struct config_string *var;
7534 var = (struct config_string *)
7535 init_custom_variable(name, short_desc, long_desc, context, flags,
7536 PGC_STRING, sizeof(struct config_string));
7537 var->variable = valueAddr;
7538 var->boot_val = bootValue;
7539 var->check_hook = check_hook;
7540 var->assign_hook = assign_hook;
7541 var->show_hook = show_hook;
7542 define_custom_variable(&var->gen);
7546 DefineCustomEnumVariable(const char *name,
7547 const char *short_desc,
7548 const char *long_desc,
7551 const struct config_enum_entry * options,
7554 GucEnumCheckHook check_hook,
7555 GucEnumAssignHook assign_hook,
7556 GucShowHook show_hook)
7558 struct config_enum *var;
7560 var = (struct config_enum *)
7561 init_custom_variable(name, short_desc, long_desc, context, flags,
7562 PGC_ENUM, sizeof(struct config_enum));
7563 var->variable = valueAddr;
7564 var->boot_val = bootValue;
7565 var->reset_val = bootValue;
7566 var->options = options;
7567 var->check_hook = check_hook;
7568 var->assign_hook = assign_hook;
7569 var->show_hook = show_hook;
7570 define_custom_variable(&var->gen);
7574 EmitWarningsOnPlaceholders(const char *className)
7576 int classLen = strlen(className);
7579 for (i = 0; i < num_guc_variables; i++)
7581 struct config_generic *var = guc_variables[i];
7583 if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
7584 strncmp(className, var->name, classLen) == 0 &&
7585 var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
7588 (errcode(ERRCODE_UNDEFINED_OBJECT),
7589 errmsg("unrecognized configuration parameter \"%s\"",
7600 GetPGVariable(const char *name, DestReceiver *dest)
7602 if (guc_name_compare(name, "all") == 0)
7603 ShowAllGUCConfig(dest);
7605 ShowGUCConfigOption(name, dest);
7609 GetPGVariableResultDesc(const char *name)
7613 if (guc_name_compare(name, "all") == 0)
7615 /* need a tuple descriptor representing three TEXT columns */
7616 tupdesc = CreateTemplateTupleDesc(3, false);
7617 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
7619 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
7621 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
7626 const char *varname;
7628 /* Get the canonical spelling of name */
7629 (void) GetConfigOptionByName(name, &varname, false);
7631 /* need a tuple descriptor representing a single TEXT column */
7632 tupdesc = CreateTemplateTupleDesc(1, false);
7633 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
7644 ShowGUCConfigOption(const char *name, DestReceiver *dest)
7646 TupOutputState *tstate;
7648 const char *varname;
7651 /* Get the value and canonical spelling of name */
7652 value = GetConfigOptionByName(name, &varname, false);
7654 /* need a tuple descriptor representing a single TEXT column */
7655 tupdesc = CreateTemplateTupleDesc(1, false);
7656 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
7659 /* prepare for projection of tuples */
7660 tstate = begin_tup_output_tupdesc(dest, tupdesc);
7663 do_text_output_oneline(tstate, value);
7665 end_tup_output(tstate);
7672 ShowAllGUCConfig(DestReceiver *dest)
7674 bool am_superuser = superuser();
7676 TupOutputState *tstate;
7679 bool isnull[3] = {false, false, false};
7681 /* need a tuple descriptor representing three TEXT columns */
7682 tupdesc = CreateTemplateTupleDesc(3, false);
7683 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
7685 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
7687 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
7690 /* prepare for projection of tuples */
7691 tstate = begin_tup_output_tupdesc(dest, tupdesc);
7693 for (i = 0; i < num_guc_variables; i++)
7695 struct config_generic *conf = guc_variables[i];
7698 if ((conf->flags & GUC_NO_SHOW_ALL) ||
7699 ((conf->flags & GUC_SUPERUSER_ONLY) && !am_superuser))
7702 /* assign to the values array */
7703 values[0] = PointerGetDatum(cstring_to_text(conf->name));
7705 setting = _ShowOption(conf, true);
7708 values[1] = PointerGetDatum(cstring_to_text(setting));
7713 values[1] = PointerGetDatum(NULL);
7717 values[2] = PointerGetDatum(cstring_to_text(conf->short_desc));
7719 /* send it to dest */
7720 do_tup_output(tstate, values, isnull);
7723 pfree(DatumGetPointer(values[0]));
7727 pfree(DatumGetPointer(values[1]));
7729 pfree(DatumGetPointer(values[2]));
7732 end_tup_output(tstate);
7736 * Return GUC variable value by name; optionally return canonical form of
7737 * name. If the GUC is unset, then throw an error unless missing_ok is true,
7738 * in which case return NULL. Return value is palloc'd (but *varname isn't).
7741 GetConfigOptionByName(const char *name, const char **varname, bool missing_ok)
7743 struct config_generic *record;
7745 record = find_option(name, false, ERROR);
7756 (errcode(ERRCODE_UNDEFINED_OBJECT),
7757 errmsg("unrecognized configuration parameter \"%s\"", name)));
7760 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
7762 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7763 errmsg("must be superuser to examine \"%s\"", name)));
7766 *varname = record->name;
7768 return _ShowOption(record, true);
7772 * Return GUC variable value by variable number; optionally return canonical
7773 * form of name. Return value is palloc'd.
7776 GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
7779 struct config_generic *conf;
7781 /* check requested variable number valid */
7782 Assert((varnum >= 0) && (varnum < num_guc_variables));
7784 conf = guc_variables[varnum];
7788 if ((conf->flags & GUC_NO_SHOW_ALL) ||
7789 ((conf->flags & GUC_SUPERUSER_ONLY) && !superuser()))
7795 /* first get the generic attributes */
7798 values[0] = conf->name;
7800 /* setting : use _ShowOption in order to avoid duplicating the logic */
7801 values[1] = _ShowOption(conf, false);
7804 if (conf->vartype == PGC_INT)
7808 switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
7813 case GUC_UNIT_BLOCKS:
7814 snprintf(buf, sizeof(buf), "%dkB", BLCKSZ / 1024);
7817 case GUC_UNIT_XBLOCKS:
7818 snprintf(buf, sizeof(buf), "%dkB", XLOG_BLCKSZ / 1024);
7839 values[3] = config_group_names[conf->group];
7842 values[4] = conf->short_desc;
7845 values[5] = conf->long_desc;
7848 values[6] = GucContext_Names[conf->context];
7851 values[7] = config_type_names[conf->vartype];
7854 values[8] = GucSource_Names[conf->source];
7856 /* now get the type specifc attributes */
7857 switch (conf->vartype)
7861 struct config_bool *lconf = (struct config_bool *) conf;
7873 values[12] = pstrdup(lconf->boot_val ? "on" : "off");
7876 values[13] = pstrdup(lconf->reset_val ? "on" : "off");
7882 struct config_int *lconf = (struct config_int *) conf;
7885 snprintf(buffer, sizeof(buffer), "%d", lconf->min);
7886 values[9] = pstrdup(buffer);
7889 snprintf(buffer, sizeof(buffer), "%d", lconf->max);
7890 values[10] = pstrdup(buffer);
7896 snprintf(buffer, sizeof(buffer), "%d", lconf->boot_val);
7897 values[12] = pstrdup(buffer);
7900 snprintf(buffer, sizeof(buffer), "%d", lconf->reset_val);
7901 values[13] = pstrdup(buffer);
7907 struct config_real *lconf = (struct config_real *) conf;
7910 snprintf(buffer, sizeof(buffer), "%g", lconf->min);
7911 values[9] = pstrdup(buffer);
7914 snprintf(buffer, sizeof(buffer), "%g", lconf->max);
7915 values[10] = pstrdup(buffer);
7921 snprintf(buffer, sizeof(buffer), "%g", lconf->boot_val);
7922 values[12] = pstrdup(buffer);
7925 snprintf(buffer, sizeof(buffer), "%g", lconf->reset_val);
7926 values[13] = pstrdup(buffer);
7932 struct config_string *lconf = (struct config_string *) conf;
7944 if (lconf->boot_val == NULL)
7947 values[12] = pstrdup(lconf->boot_val);
7950 if (lconf->reset_val == NULL)
7953 values[13] = pstrdup(lconf->reset_val);
7959 struct config_enum *lconf = (struct config_enum *) conf;
7970 * NOTE! enumvals with double quotes in them are not
7973 values[11] = config_enum_get_options((struct config_enum *) conf,
7974 "{\"", "\"}", "\",\"");
7977 values[12] = pstrdup(config_enum_lookup_by_value(lconf,
7981 values[13] = pstrdup(config_enum_lookup_by_value(lconf,
7989 * should never get here, but in case we do, set 'em to NULL
8011 * If the setting came from a config file, set the source location. For
8012 * security reasons, we don't show source file/line number for
8015 if (conf->source == PGC_S_FILE && superuser())
8017 values[14] = conf->sourcefile;
8018 snprintf(buffer, sizeof(buffer), "%d", conf->sourceline);
8019 values[15] = pstrdup(buffer);
8027 values[16] = (conf->status & GUC_PENDING_RESTART) ? "t" : "f";
8031 * Return the total number of GUC variables
8034 GetNumConfigOptions(void)
8036 return num_guc_variables;
8040 * show_config_by_name - equiv to SHOW X command but implemented as
8044 show_config_by_name(PG_FUNCTION_ARGS)
8046 char *varname = TextDatumGetCString(PG_GETARG_DATUM(0));
8050 varval = GetConfigOptionByName(varname, NULL, false);
8052 /* Convert to text */
8053 PG_RETURN_TEXT_P(cstring_to_text(varval));
8057 * show_config_by_name_missing_ok - equiv to SHOW X command but implemented as
8058 * a function. If X does not exist, suppress the error and just return NULL
8059 * if missing_ok is TRUE.
8062 show_config_by_name_missing_ok(PG_FUNCTION_ARGS)
8064 char *varname = TextDatumGetCString(PG_GETARG_DATUM(0));
8065 bool missing_ok = PG_GETARG_BOOL(1);
8069 varval = GetConfigOptionByName(varname, NULL, missing_ok);
8071 /* return NULL if no such variable */
8075 /* Convert to text */
8076 PG_RETURN_TEXT_P(cstring_to_text(varval));
8080 * show_all_settings - equiv to SHOW ALL command but implemented as
8083 #define NUM_PG_SETTINGS_ATTS 17
8086 show_all_settings(PG_FUNCTION_ARGS)
8088 FuncCallContext *funcctx;
8092 AttInMetadata *attinmeta;
8093 MemoryContext oldcontext;
8095 /* stuff done only on the first call of the function */
8096 if (SRF_IS_FIRSTCALL())
8098 /* create a function context for cross-call persistence */
8099 funcctx = SRF_FIRSTCALL_INIT();
8102 * switch to memory context appropriate for multiple function calls
8104 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
8107 * need a tuple descriptor representing NUM_PG_SETTINGS_ATTS columns
8108 * of the appropriate types
8110 tupdesc = CreateTemplateTupleDesc(NUM_PG_SETTINGS_ATTS, false);
8111 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
8113 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
8115 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "unit",
8117 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "category",
8119 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "short_desc",
8121 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "extra_desc",
8123 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "context",
8125 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "vartype",
8127 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "source",
8129 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "min_val",
8131 TupleDescInitEntry(tupdesc, (AttrNumber) 11, "max_val",
8133 TupleDescInitEntry(tupdesc, (AttrNumber) 12, "enumvals",
8134 TEXTARRAYOID, -1, 0);
8135 TupleDescInitEntry(tupdesc, (AttrNumber) 13, "boot_val",
8137 TupleDescInitEntry(tupdesc, (AttrNumber) 14, "reset_val",
8139 TupleDescInitEntry(tupdesc, (AttrNumber) 15, "sourcefile",
8141 TupleDescInitEntry(tupdesc, (AttrNumber) 16, "sourceline",
8143 TupleDescInitEntry(tupdesc, (AttrNumber) 17, "pending_restart",
8147 * Generate attribute metadata needed later to produce tuples from raw
8150 attinmeta = TupleDescGetAttInMetadata(tupdesc);
8151 funcctx->attinmeta = attinmeta;
8153 /* total number of tuples to be returned */
8154 funcctx->max_calls = GetNumConfigOptions();
8156 MemoryContextSwitchTo(oldcontext);
8159 /* stuff done on every call of the function */
8160 funcctx = SRF_PERCALL_SETUP();
8162 call_cntr = funcctx->call_cntr;
8163 max_calls = funcctx->max_calls;
8164 attinmeta = funcctx->attinmeta;
8166 if (call_cntr < max_calls) /* do when there is more left to send */
8168 char *values[NUM_PG_SETTINGS_ATTS];
8174 * Get the next visible GUC variable name and value
8178 GetConfigOptionByNum(call_cntr, (const char **) values, &noshow);
8181 /* bump the counter and get the next config setting */
8182 call_cntr = ++funcctx->call_cntr;
8184 /* make sure we haven't gone too far now */
8185 if (call_cntr >= max_calls)
8186 SRF_RETURN_DONE(funcctx);
8191 tuple = BuildTupleFromCStrings(attinmeta, values);
8193 /* make the tuple into a datum */
8194 result = HeapTupleGetDatum(tuple);
8196 SRF_RETURN_NEXT(funcctx, result);
8200 /* do when there is no more left */
8201 SRF_RETURN_DONE(funcctx);
8206 * show_all_file_settings
8208 * Returns a table of all parameter settings in all configuration files
8209 * which includes the config file pathname, the line number, a sequence number
8210 * indicating the order in which the settings were encountered, the parameter
8211 * name and value, a bool showing if the value could be applied, and possibly
8212 * an associated error message. (For problems such as syntax errors, the
8213 * parameter name/value might be NULL.)
8215 * Note: no filtering is done here, instead we depend on the GRANT system
8216 * to prevent unprivileged users from accessing this function or the view
8217 * built on top of it.
8220 show_all_file_settings(PG_FUNCTION_ARGS)
8222 #define NUM_PG_FILE_SETTINGS_ATTS 7
8223 ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
8225 Tuplestorestate *tupstore;
8226 ConfigVariable *conf;
8228 MemoryContext per_query_ctx;
8229 MemoryContext oldcontext;
8231 /* Check to see if caller supports us returning a tuplestore */
8232 if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo))
8234 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8235 errmsg("set-valued function called in context that cannot accept a set")));
8236 if (!(rsinfo->allowedModes & SFRM_Materialize))
8238 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8239 errmsg("materialize mode required, but it is not " \
8240 "allowed in this context")));
8242 /* Scan the config files using current context as workspace */
8243 conf = ProcessConfigFileInternal(PGC_SIGHUP, false, DEBUG3);
8245 /* Switch into long-lived context to construct returned data structures */
8246 per_query_ctx = rsinfo->econtext->ecxt_per_query_memory;
8247 oldcontext = MemoryContextSwitchTo(per_query_ctx);
8249 /* Build a tuple descriptor for our result type */
8250 tupdesc = CreateTemplateTupleDesc(NUM_PG_FILE_SETTINGS_ATTS, false);
8251 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "sourcefile",
8253 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "sourceline",
8255 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "seqno",
8257 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "name",
8259 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "setting",
8261 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "applied",
8263 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "error",
8266 /* Build a tuplestore to return our results in */
8267 tupstore = tuplestore_begin_heap(true, false, work_mem);
8268 rsinfo->returnMode = SFRM_Materialize;
8269 rsinfo->setResult = tupstore;
8270 rsinfo->setDesc = tupdesc;
8272 /* The rest can be done in short-lived context */
8273 MemoryContextSwitchTo(oldcontext);
8275 /* Process the results and create a tuplestore */
8276 for (seqno = 1; conf != NULL; conf = conf->next, seqno++)
8278 Datum values[NUM_PG_FILE_SETTINGS_ATTS];
8279 bool nulls[NUM_PG_FILE_SETTINGS_ATTS];
8281 memset(values, 0, sizeof(values));
8282 memset(nulls, 0, sizeof(nulls));
8286 values[0] = PointerGetDatum(cstring_to_text(conf->filename));
8290 /* sourceline (not meaningful if no sourcefile) */
8292 values[1] = Int32GetDatum(conf->sourceline);
8297 values[2] = Int32GetDatum(seqno);
8301 values[3] = PointerGetDatum(cstring_to_text(conf->name));
8307 values[4] = PointerGetDatum(cstring_to_text(conf->value));
8312 values[5] = BoolGetDatum(conf->applied);
8316 values[6] = PointerGetDatum(cstring_to_text(conf->errmsg));
8320 /* shove row into tuplestore */
8321 tuplestore_putvalues(tupstore, tupdesc, values, nulls);
8324 tuplestore_donestoring(tupstore);
8330 _ShowOption(struct config_generic * record, bool use_units)
8335 switch (record->vartype)
8339 struct config_bool *conf = (struct config_bool *) record;
8341 if (conf->show_hook)
8342 val = (*conf->show_hook) ();
8344 val = *conf->variable ? "on" : "off";
8350 struct config_int *conf = (struct config_int *) record;
8352 if (conf->show_hook)
8353 val = (*conf->show_hook) ();
8357 * Use int64 arithmetic to avoid overflows in units
8360 int64 result = *conf->variable;
8363 if (use_units && result > 0 && (record->flags & GUC_UNIT))
8365 convert_from_base_unit(result, record->flags & GUC_UNIT,
8371 snprintf(buffer, sizeof(buffer), INT64_FORMAT "%s",
8380 struct config_real *conf = (struct config_real *) record;
8382 if (conf->show_hook)
8383 val = (*conf->show_hook) ();
8386 snprintf(buffer, sizeof(buffer), "%g",
8395 struct config_string *conf = (struct config_string *) record;
8397 if (conf->show_hook)
8398 val = (*conf->show_hook) ();
8399 else if (*conf->variable && **conf->variable)
8400 val = *conf->variable;
8408 struct config_enum *conf = (struct config_enum *) record;
8410 if (conf->show_hook)
8411 val = (*conf->show_hook) ();
8413 val = config_enum_lookup_by_value(conf, *conf->variable);
8418 /* just to keep compiler quiet */
8423 return pstrdup(val);
8430 * These routines dump out all non-default GUC options into a binary
8431 * file that is read by all exec'ed backends. The format is:
8433 * variable name, string, null terminated
8434 * variable value, string, null terminated
8435 * variable sourcefile, string, null terminated (empty if none)
8436 * variable sourceline, integer
8437 * variable source, integer
8438 * variable scontext, integer
8441 write_one_nondefault_variable(FILE *fp, struct config_generic * gconf)
8443 if (gconf->source == PGC_S_DEFAULT)
8446 fprintf(fp, "%s", gconf->name);
8449 switch (gconf->vartype)
8453 struct config_bool *conf = (struct config_bool *) gconf;
8455 if (*conf->variable)
8456 fprintf(fp, "true");
8458 fprintf(fp, "false");
8464 struct config_int *conf = (struct config_int *) gconf;
8466 fprintf(fp, "%d", *conf->variable);
8472 struct config_real *conf = (struct config_real *) gconf;
8474 fprintf(fp, "%.17g", *conf->variable);
8480 struct config_string *conf = (struct config_string *) gconf;
8482 fprintf(fp, "%s", *conf->variable);
8488 struct config_enum *conf = (struct config_enum *) gconf;
8491 config_enum_lookup_by_value(conf, *conf->variable));
8498 if (gconf->sourcefile)
8499 fprintf(fp, "%s", gconf->sourcefile);
8502 fwrite(&gconf->sourceline, 1, sizeof(gconf->sourceline), fp);
8503 fwrite(&gconf->source, 1, sizeof(gconf->source), fp);
8504 fwrite(&gconf->scontext, 1, sizeof(gconf->scontext), fp);
8508 write_nondefault_variables(GucContext context)
8514 Assert(context == PGC_POSTMASTER || context == PGC_SIGHUP);
8516 elevel = (context == PGC_SIGHUP) ? LOG : ERROR;
8521 fp = AllocateFile(CONFIG_EXEC_PARAMS_NEW, "w");
8525 (errcode_for_file_access(),
8526 errmsg("could not write to file \"%s\": %m",
8527 CONFIG_EXEC_PARAMS_NEW)));
8531 for (i = 0; i < num_guc_variables; i++)
8533 write_one_nondefault_variable(fp, guc_variables[i]);
8539 (errcode_for_file_access(),
8540 errmsg("could not write to file \"%s\": %m",
8541 CONFIG_EXEC_PARAMS_NEW)));
8546 * Put new file in place. This could delay on Win32, but we don't hold
8547 * any exclusive locks.
8549 rename(CONFIG_EXEC_PARAMS_NEW, CONFIG_EXEC_PARAMS);
8554 * Read string, including null byte from file
8556 * Return NULL on EOF and nothing read
8559 read_string_with_null(FILE *fp)
8568 if ((ch = fgetc(fp)) == EOF)
8573 elog(FATAL, "invalid format of exec config params file");
8576 str = guc_malloc(FATAL, maxlen);
8577 else if (i == maxlen)
8578 str = guc_realloc(FATAL, str, maxlen *= 2);
8587 * This routine loads a previous postmaster dump of its non-default
8591 read_nondefault_variables(void)
8598 GucSource varsource;
8599 GucContext varscontext;
8602 * Assert that PGC_BACKEND/PGC_SU_BACKEND case in set_config_option() will
8603 * do the right thing.
8605 Assert(IsInitProcessingMode());
8610 fp = AllocateFile(CONFIG_EXEC_PARAMS, "r");
8613 /* File not found is fine */
8614 if (errno != ENOENT)
8616 (errcode_for_file_access(),
8617 errmsg("could not read from file \"%s\": %m",
8618 CONFIG_EXEC_PARAMS)));
8624 struct config_generic *record;
8626 if ((varname = read_string_with_null(fp)) == NULL)
8629 if ((record = find_option(varname, true, FATAL)) == NULL)
8630 elog(FATAL, "failed to locate variable \"%s\" in exec config params file", varname);
8632 if ((varvalue = read_string_with_null(fp)) == NULL)
8633 elog(FATAL, "invalid format of exec config params file");
8634 if ((varsourcefile = read_string_with_null(fp)) == NULL)
8635 elog(FATAL, "invalid format of exec config params file");
8636 if (fread(&varsourceline, 1, sizeof(varsourceline), fp) != sizeof(varsourceline))
8637 elog(FATAL, "invalid format of exec config params file");
8638 if (fread(&varsource, 1, sizeof(varsource), fp) != sizeof(varsource))
8639 elog(FATAL, "invalid format of exec config params file");
8640 if (fread(&varscontext, 1, sizeof(varscontext), fp) != sizeof(varscontext))
8641 elog(FATAL, "invalid format of exec config params file");
8643 (void) set_config_option(varname, varvalue,
8644 varscontext, varsource,
8645 GUC_ACTION_SET, true, 0, true);
8646 if (varsourcefile[0])
8647 set_config_sourcefile(varname, varsourcefile, varsourceline);
8651 free(varsourcefile);
8656 #endif /* EXEC_BACKEND */
8660 * When serializing, determine whether to skip this GUC. When restoring, the
8661 * negation of this test determines whether to restore the compiled-in default
8662 * value before processing serialized values.
8664 * A PGC_S_DEFAULT setting on the serialize side will typically match new
8665 * postmaster children, but that can be false when got_SIGHUP == true and the
8666 * pending configuration change modifies this setting. Nonetheless, we omit
8667 * PGC_S_DEFAULT settings from serialization and make up for that by restoring
8668 * defaults before applying serialized values.
8670 * PGC_POSTMASTER variables always have the same value in every child of a
8671 * particular postmaster. Most PGC_INTERNAL variables are compile-time
8672 * constants; a few, like server_encoding and lc_ctype, are handled specially
8673 * outside the serialize/restore procedure. Therefore, SerializeGUCState()
8674 * never sends these, and RestoreGUCState() never changes them.
8677 can_skip_gucvar(struct config_generic * gconf)
8679 return gconf->context == PGC_POSTMASTER ||
8680 gconf->context == PGC_INTERNAL || gconf->source == PGC_S_DEFAULT;
8684 * estimate_variable_size:
8685 * Estimate max size for dumping the given GUC variable.
8688 estimate_variable_size(struct config_generic * gconf)
8693 if (can_skip_gucvar(gconf))
8698 size = add_size(size, strlen(gconf->name) + 1);
8700 /* Get the maximum display length of the GUC value. */
8701 switch (gconf->vartype)
8705 valsize = 5; /* max(strlen('true'), strlen('false')) */
8711 struct config_int *conf = (struct config_int *) gconf;
8714 * Instead of getting the exact display length, use max
8715 * length. Also reduce the max length for typical ranges of
8716 * small values. Maximum value is 2147483647, i.e. 10 chars.
8717 * Include one byte for sign.
8719 if (abs(*conf->variable) < 1000)
8729 * We are going to print it with %.17g. Account for sign,
8730 * decimal point, and e+nnn notation. E.g.
8731 * -3.9932904234000002e+110
8733 valsize = REALTYPE_PRECISION + 1 + 1 + 5;
8739 struct config_string *conf = (struct config_string *) gconf;
8741 valsize = strlen(*conf->variable);
8747 struct config_enum *conf = (struct config_enum *) gconf;
8749 valsize = strlen(config_enum_lookup_by_value(conf, *conf->variable));
8754 /* Allow space for terminating zero-byte */
8755 size = add_size(size, valsize + 1);
8757 if (gconf->sourcefile)
8758 size = add_size(size, strlen(gconf->sourcefile));
8760 /* Allow space for terminating zero-byte */
8761 size = add_size(size, 1);
8763 /* Include line whenever we include file. */
8764 if (gconf->sourcefile)
8765 size = add_size(size, sizeof(gconf->sourceline));
8767 size = add_size(size, sizeof(gconf->source));
8768 size = add_size(size, sizeof(gconf->scontext));
8774 * EstimateGUCStateSpace:
8775 * Returns the size needed to store the GUC state for the current process
8778 EstimateGUCStateSpace(void)
8783 /* Add space reqd for saving the data size of the guc state */
8784 size = sizeof(Size);
8786 /* Add up the space needed for each GUC variable */
8787 for (i = 0; i < num_guc_variables; i++)
8788 size = add_size(size,
8789 estimate_variable_size(guc_variables[i]));
8796 * Copies the formatted string into the destination. Moves ahead the
8797 * destination pointer, and decrements the maxbytes by that many bytes. If
8798 * maxbytes is not sufficient to copy the string, error out.
8801 do_serialize(char **destptr, Size *maxbytes, const char *fmt,...)
8807 elog(ERROR, "not enough space to serialize GUC state");
8809 va_start(vargs, fmt);
8810 n = vsnprintf(*destptr, *maxbytes, fmt, vargs);
8814 * Cater to portability hazards in the vsnprintf() return value just like
8815 * appendPQExpBufferVA() does. Note that this requires an extra byte of
8816 * slack at the end of the buffer. Since serialize_variable() ends with a
8817 * do_serialize_binary() rather than a do_serialize(), we'll always have
8818 * that slack; estimate_variable_size() need not add a byte for it.
8820 if (n < 0 || n >= *maxbytes - 1)
8822 if (n < 0 && errno != 0 && errno != ENOMEM)
8823 /* Shouldn't happen. Better show errno description. */
8824 elog(ERROR, "vsnprintf failed: %m");
8826 elog(ERROR, "not enough space to serialize GUC state");
8829 /* Shift the destptr ahead of the null terminator */
8834 /* Binary copy version of do_serialize() */
8836 do_serialize_binary(char **destptr, Size *maxbytes, void *val, Size valsize)
8838 if (valsize > *maxbytes)
8839 elog(ERROR, "not enough space to serialize GUC state");
8841 memcpy(*destptr, val, valsize);
8842 *destptr += valsize;
8843 *maxbytes -= valsize;
8847 * serialize_variable:
8848 * Dumps name, value and other information of a GUC variable into destptr.
8851 serialize_variable(char **destptr, Size *maxbytes,
8852 struct config_generic * gconf)
8854 if (can_skip_gucvar(gconf))
8857 do_serialize(destptr, maxbytes, "%s", gconf->name);
8859 switch (gconf->vartype)
8863 struct config_bool *conf = (struct config_bool *) gconf;
8865 do_serialize(destptr, maxbytes,
8866 (*conf->variable ? "true" : "false"));
8872 struct config_int *conf = (struct config_int *) gconf;
8874 do_serialize(destptr, maxbytes, "%d", *conf->variable);
8880 struct config_real *conf = (struct config_real *) gconf;
8882 do_serialize(destptr, maxbytes, "%.*g",
8883 REALTYPE_PRECISION, *conf->variable);
8889 struct config_string *conf = (struct config_string *) gconf;
8891 do_serialize(destptr, maxbytes, "%s", *conf->variable);
8897 struct config_enum *conf = (struct config_enum *) gconf;
8899 do_serialize(destptr, maxbytes, "%s",
8900 config_enum_lookup_by_value(conf, *conf->variable));
8905 do_serialize(destptr, maxbytes, "%s",
8906 (gconf->sourcefile ? gconf->sourcefile : ""));
8908 if (gconf->sourcefile)
8909 do_serialize_binary(destptr, maxbytes, &gconf->sourceline,
8910 sizeof(gconf->sourceline));
8912 do_serialize_binary(destptr, maxbytes, &gconf->source,
8913 sizeof(gconf->source));
8914 do_serialize_binary(destptr, maxbytes, &gconf->scontext,
8915 sizeof(gconf->scontext));
8919 * SerializeGUCState:
8920 * Dumps the complete GUC state onto the memory location at start_address.
8923 SerializeGUCState(Size maxsize, char *start_address)
8931 /* Reserve space for saving the actual size of the guc state */
8932 Assert(maxsize > sizeof(actual_size));
8933 curptr = start_address + sizeof(actual_size);
8934 bytes_left = maxsize - sizeof(actual_size);
8936 for (i = 0; i < num_guc_variables; i++)
8939 * It's pretty ugly, but we've got to force "role" to be initialized
8940 * after "session_authorization"; otherwise, the latter will override
8943 if (strcmp(guc_variables[i]->name, "role") == 0)
8946 serialize_variable(&curptr, &bytes_left, guc_variables[i]);
8949 serialize_variable(&curptr, &bytes_left, guc_variables[i_role]);
8951 /* Store actual size without assuming alignment of start_address. */
8952 actual_size = maxsize - bytes_left - sizeof(actual_size);
8953 memcpy(start_address, &actual_size, sizeof(actual_size));
8958 * Actually it does not read anything, just returns the srcptr. But it does
8959 * move the srcptr past the terminating zero byte, so that the caller is ready
8960 * to read the next string.
8963 read_gucstate(char **srcptr, char *srcend)
8965 char *retptr = *srcptr;
8968 if (*srcptr >= srcend)
8969 elog(ERROR, "incomplete GUC state");
8971 /* The string variables are all null terminated */
8972 for (ptr = *srcptr; ptr < srcend && *ptr != '\0'; ptr++)
8976 elog(ERROR, "could not find null terminator in GUC state");
8978 /* Set the new position to the byte following the terminating NUL */
8984 /* Binary read version of read_gucstate(). Copies into dest */
8986 read_gucstate_binary(char **srcptr, char *srcend, void *dest, Size size)
8988 if (*srcptr + size > srcend)
8989 elog(ERROR, "incomplete GUC state");
8991 memcpy(dest, *srcptr, size);
8997 * Reads the GUC state at the specified address and updates the GUCs with the
8998 * values read from the GUC state.
9001 RestoreGUCState(void *gucstate)
9007 GucSource varsource;
9008 GucContext varscontext;
9009 char *srcptr = (char *) gucstate;
9014 /* See comment at can_skip_gucvar(). */
9015 for (i = 0; i < num_guc_variables; i++)
9016 if (!can_skip_gucvar(guc_variables[i]))
9017 InitializeOneGUCOption(guc_variables[i]);
9019 /* First item is the length of the subsequent data */
9020 memcpy(&len, gucstate, sizeof(len));
9022 srcptr += sizeof(len);
9023 srcend = srcptr + len;
9025 while (srcptr < srcend)
9029 if ((varname = read_gucstate(&srcptr, srcend)) == NULL)
9032 varvalue = read_gucstate(&srcptr, srcend);
9033 varsourcefile = read_gucstate(&srcptr, srcend);
9034 if (varsourcefile[0])
9035 read_gucstate_binary(&srcptr, srcend,
9036 &varsourceline, sizeof(varsourceline));
9037 read_gucstate_binary(&srcptr, srcend,
9038 &varsource, sizeof(varsource));
9039 read_gucstate_binary(&srcptr, srcend,
9040 &varscontext, sizeof(varscontext));
9042 result = set_config_option(varname, varvalue, varscontext, varsource,
9043 GUC_ACTION_SET, true, ERROR, true);
9046 (errcode(ERRCODE_INTERNAL_ERROR),
9047 errmsg("parameter \"%s\" could not be set", varname)));
9048 if (varsourcefile[0])
9049 set_config_sourcefile(varname, varsourcefile, varsourceline);
9054 * A little "long argument" simulation, although not quite GNU
9055 * compliant. Takes a string of the form "some-option=some value" and
9056 * returns name = "some_option" and value = "some value" in malloc'ed
9057 * storage. Note that '-' is converted to '_' in the option name. If
9058 * there is no '=' in the input string then value will be NULL.
9061 ParseLongOption(const char *string, char **name, char **value)
9070 equal_pos = strcspn(string, "=");
9072 if (string[equal_pos] == '=')
9074 *name = guc_malloc(FATAL, equal_pos + 1);
9075 strlcpy(*name, string, equal_pos + 1);
9077 *value = guc_strdup(FATAL, &string[equal_pos + 1]);
9081 /* no equal sign in string */
9082 *name = guc_strdup(FATAL, string);
9086 for (cp = *name; *cp; cp++)
9093 * Handle options fetched from pg_db_role_setting.setconfig,
9094 * pg_proc.proconfig, etc. Caller must specify proper context/source/action.
9096 * The array parameter must be an array of TEXT (it must not be NULL).
9099 ProcessGUCArray(ArrayType *array,
9100 GucContext context, GucSource source, GucAction action)
9104 Assert(array != NULL);
9105 Assert(ARR_ELEMTYPE(array) == TEXTOID);
9106 Assert(ARR_NDIM(array) == 1);
9107 Assert(ARR_LBOUND(array)[0] == 1);
9109 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9117 d = array_ref(array, 1, &i,
9118 -1 /* varlenarray */ ,
9119 -1 /* TEXT's typlen */ ,
9120 false /* TEXT's typbyval */ ,
9121 'i' /* TEXT's typalign */ ,
9127 s = TextDatumGetCString(d);
9129 ParseLongOption(s, &name, &value);
9133 (errcode(ERRCODE_SYNTAX_ERROR),
9134 errmsg("could not parse setting for parameter \"%s\"",
9140 (void) set_config_option(name, value,
9142 action, true, 0, false);
9153 * Add an entry to an option array. The array parameter may be NULL
9154 * to indicate the current table entry is NULL.
9157 GUCArrayAdd(ArrayType *array, const char *name, const char *value)
9159 struct config_generic *record;
9167 /* test if the option is valid and we're allowed to set it */
9168 (void) validate_option_array_item(name, value, false);
9170 /* normalize name (converts obsolete GUC names to modern spellings) */
9171 record = find_option(name, false, WARNING);
9173 name = record->name;
9175 /* build new item for array */
9176 newval = psprintf("%s=%s", name, value);
9177 datum = CStringGetTextDatum(newval);
9185 Assert(ARR_ELEMTYPE(array) == TEXTOID);
9186 Assert(ARR_NDIM(array) == 1);
9187 Assert(ARR_LBOUND(array)[0] == 1);
9189 index = ARR_DIMS(array)[0] + 1; /* add after end */
9191 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9196 d = array_ref(array, 1, &i,
9197 -1 /* varlenarray */ ,
9198 -1 /* TEXT's typlen */ ,
9199 false /* TEXT's typbyval */ ,
9200 'i' /* TEXT's typalign */ ,
9204 current = TextDatumGetCString(d);
9206 /* check for match up through and including '=' */
9207 if (strncmp(current, newval, strlen(name) + 1) == 0)
9214 a = array_set(array, 1, &index,
9217 -1 /* varlena array */ ,
9218 -1 /* TEXT's typlen */ ,
9219 false /* TEXT's typbyval */ ,
9220 'i' /* TEXT's typalign */ );
9223 a = construct_array(&datum, 1,
9232 * Delete an entry from an option array. The array parameter may be NULL
9233 * to indicate the current table entry is NULL. Also, if the return value
9234 * is NULL then a null should be stored.
9237 GUCArrayDelete(ArrayType *array, const char *name)
9239 struct config_generic *record;
9240 ArrayType *newarray;
9246 /* test if the option is valid and we're allowed to set it */
9247 (void) validate_option_array_item(name, NULL, false);
9249 /* normalize name (converts obsolete GUC names to modern spellings) */
9250 record = find_option(name, false, WARNING);
9252 name = record->name;
9254 /* if array is currently null, then surely nothing to delete */
9261 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9267 d = array_ref(array, 1, &i,
9268 -1 /* varlenarray */ ,
9269 -1 /* TEXT's typlen */ ,
9270 false /* TEXT's typbyval */ ,
9271 'i' /* TEXT's typalign */ ,
9275 val = TextDatumGetCString(d);
9277 /* ignore entry if it's what we want to delete */
9278 if (strncmp(val, name, strlen(name)) == 0
9279 && val[strlen(name)] == '=')
9282 /* else add it to the output array */
9284 newarray = array_set(newarray, 1, &index,
9287 -1 /* varlenarray */ ,
9288 -1 /* TEXT's typlen */ ,
9289 false /* TEXT's typbyval */ ,
9290 'i' /* TEXT's typalign */ );
9292 newarray = construct_array(&d, 1,
9304 * Given a GUC array, delete all settings from it that our permission
9305 * level allows: if superuser, delete them all; if regular user, only
9306 * those that are PGC_USERSET
9309 GUCArrayReset(ArrayType *array)
9311 ArrayType *newarray;
9315 /* if array is currently null, nothing to do */
9319 /* if we're superuser, we can delete everything, so just do it */
9326 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
9333 d = array_ref(array, 1, &i,
9334 -1 /* varlenarray */ ,
9335 -1 /* TEXT's typlen */ ,
9336 false /* TEXT's typbyval */ ,
9337 'i' /* TEXT's typalign */ ,
9341 val = TextDatumGetCString(d);
9343 eqsgn = strchr(val, '=');
9346 /* skip if we have permission to delete it */
9347 if (validate_option_array_item(val, NULL, true))
9350 /* else add it to the output array */
9352 newarray = array_set(newarray, 1, &index,
9355 -1 /* varlenarray */ ,
9356 -1 /* TEXT's typlen */ ,
9357 false /* TEXT's typbyval */ ,
9358 'i' /* TEXT's typalign */ );
9360 newarray = construct_array(&d, 1,
9372 * Validate a proposed option setting for GUCArrayAdd/Delete/Reset.
9374 * name is the option name. value is the proposed value for the Add case,
9375 * or NULL for the Delete/Reset cases. If skipIfNoPermissions is true, it's
9376 * not an error to have no permissions to set the option.
9378 * Returns TRUE if OK, FALSE if skipIfNoPermissions is true and user does not
9379 * have permission to change this option (all other error cases result in an
9380 * error being thrown).
9383 validate_option_array_item(const char *name, const char *value,
9384 bool skipIfNoPermissions)
9387 struct config_generic *gconf;
9390 * There are three cases to consider:
9392 * name is a known GUC variable. Check the value normally, check
9393 * permissions normally (ie, allow if variable is USERSET, or if it's
9394 * SUSET and user is superuser).
9396 * name is not known, but exists or can be created as a placeholder (i.e.,
9397 * it has a prefixed name). We allow this case if you're a superuser,
9398 * otherwise not. Superusers are assumed to know what they're doing. We
9399 * can't allow it for other users, because when the placeholder is
9400 * resolved it might turn out to be a SUSET variable;
9401 * define_custom_variable assumes we checked that.
9403 * name is not known and can't be created as a placeholder. Throw error,
9404 * unless skipIfNoPermissions is true, in which case return FALSE.
9406 gconf = find_option(name, true, WARNING);
9409 /* not known, failed to make a placeholder */
9410 if (skipIfNoPermissions)
9413 (errcode(ERRCODE_UNDEFINED_OBJECT),
9414 errmsg("unrecognized configuration parameter \"%s\"",
9418 if (gconf->flags & GUC_CUSTOM_PLACEHOLDER)
9421 * We cannot do any meaningful check on the value, so only permissions
9422 * are useful to check.
9426 if (skipIfNoPermissions)
9429 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
9430 errmsg("permission denied to set parameter \"%s\"", name)));
9433 /* manual permissions check so we can avoid an error being thrown */
9434 if (gconf->context == PGC_USERSET)
9436 else if (gconf->context == PGC_SUSET && superuser())
9438 else if (skipIfNoPermissions)
9440 /* if a permissions error should be thrown, let set_config_option do it */
9442 /* test for permissions and valid option value */
9443 (void) set_config_option(name, value,
9444 superuser() ? PGC_SUSET : PGC_USERSET,
9445 PGC_S_TEST, GUC_ACTION_SET, false, 0, false);
9452 * Called by check_hooks that want to override the normal
9453 * ERRCODE_INVALID_PARAMETER_VALUE SQLSTATE for check hook failures.
9455 * Note that GUC_check_errmsg() etc are just macros that result in a direct
9456 * assignment to the associated variables. That is ugly, but forced by the
9457 * limitations of C's macro mechanisms.
9460 GUC_check_errcode(int sqlerrcode)
9462 GUC_check_errcode_value = sqlerrcode;
9467 * Convenience functions to manage calling a variable's check_hook.
9468 * These mostly take care of the protocol for letting check hooks supply
9469 * portions of the error report on failure.
9473 call_bool_check_hook(struct config_bool * conf, bool *newval, void **extra,
9474 GucSource source, int elevel)
9476 /* Quick success if no hook */
9477 if (!conf->check_hook)
9480 /* Reset variables that might be set by hook */
9481 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
9482 GUC_check_errmsg_string = NULL;
9483 GUC_check_errdetail_string = NULL;
9484 GUC_check_errhint_string = NULL;
9486 if (!(*conf->check_hook) (newval, extra, source))
9489 (errcode(GUC_check_errcode_value),
9490 GUC_check_errmsg_string ?
9491 errmsg_internal("%s", GUC_check_errmsg_string) :
9492 errmsg("invalid value for parameter \"%s\": %d",
9493 conf->gen.name, (int) *newval),
9494 GUC_check_errdetail_string ?
9495 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
9496 GUC_check_errhint_string ?
9497 errhint("%s", GUC_check_errhint_string) : 0));
9498 /* Flush any strings created in ErrorContext */
9507 call_int_check_hook(struct config_int * conf, int *newval, void **extra,
9508 GucSource source, int elevel)
9510 /* Quick success if no hook */
9511 if (!conf->check_hook)
9514 /* Reset variables that might be set by hook */
9515 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
9516 GUC_check_errmsg_string = NULL;
9517 GUC_check_errdetail_string = NULL;
9518 GUC_check_errhint_string = NULL;
9520 if (!(*conf->check_hook) (newval, extra, source))
9523 (errcode(GUC_check_errcode_value),
9524 GUC_check_errmsg_string ?
9525 errmsg_internal("%s", GUC_check_errmsg_string) :
9526 errmsg("invalid value for parameter \"%s\": %d",
9527 conf->gen.name, *newval),
9528 GUC_check_errdetail_string ?
9529 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
9530 GUC_check_errhint_string ?
9531 errhint("%s", GUC_check_errhint_string) : 0));
9532 /* Flush any strings created in ErrorContext */
9541 call_real_check_hook(struct config_real * conf, double *newval, void **extra,
9542 GucSource source, int elevel)
9544 /* Quick success if no hook */
9545 if (!conf->check_hook)
9548 /* Reset variables that might be set by hook */
9549 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
9550 GUC_check_errmsg_string = NULL;
9551 GUC_check_errdetail_string = NULL;
9552 GUC_check_errhint_string = NULL;
9554 if (!(*conf->check_hook) (newval, extra, source))
9557 (errcode(GUC_check_errcode_value),
9558 GUC_check_errmsg_string ?
9559 errmsg_internal("%s", GUC_check_errmsg_string) :
9560 errmsg("invalid value for parameter \"%s\": %g",
9561 conf->gen.name, *newval),
9562 GUC_check_errdetail_string ?
9563 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
9564 GUC_check_errhint_string ?
9565 errhint("%s", GUC_check_errhint_string) : 0));
9566 /* Flush any strings created in ErrorContext */
9575 call_string_check_hook(struct config_string * conf, char **newval, void **extra,
9576 GucSource source, int elevel)
9578 /* Quick success if no hook */
9579 if (!conf->check_hook)
9582 /* Reset variables that might be set by hook */
9583 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
9584 GUC_check_errmsg_string = NULL;
9585 GUC_check_errdetail_string = NULL;
9586 GUC_check_errhint_string = NULL;
9588 if (!(*conf->check_hook) (newval, extra, source))
9591 (errcode(GUC_check_errcode_value),
9592 GUC_check_errmsg_string ?
9593 errmsg_internal("%s", GUC_check_errmsg_string) :
9594 errmsg("invalid value for parameter \"%s\": \"%s\"",
9595 conf->gen.name, *newval ? *newval : ""),
9596 GUC_check_errdetail_string ?
9597 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
9598 GUC_check_errhint_string ?
9599 errhint("%s", GUC_check_errhint_string) : 0));
9600 /* Flush any strings created in ErrorContext */
9609 call_enum_check_hook(struct config_enum * conf, int *newval, void **extra,
9610 GucSource source, int elevel)
9612 /* Quick success if no hook */
9613 if (!conf->check_hook)
9616 /* Reset variables that might be set by hook */
9617 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
9618 GUC_check_errmsg_string = NULL;
9619 GUC_check_errdetail_string = NULL;
9620 GUC_check_errhint_string = NULL;
9622 if (!(*conf->check_hook) (newval, extra, source))
9625 (errcode(GUC_check_errcode_value),
9626 GUC_check_errmsg_string ?
9627 errmsg_internal("%s", GUC_check_errmsg_string) :
9628 errmsg("invalid value for parameter \"%s\": \"%s\"",
9630 config_enum_lookup_by_value(conf, *newval)),
9631 GUC_check_errdetail_string ?
9632 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
9633 GUC_check_errhint_string ?
9634 errhint("%s", GUC_check_errhint_string) : 0));
9635 /* Flush any strings created in ErrorContext */
9645 * check_hook, assign_hook and show_hook subroutines
9649 check_log_destination(char **newval, void **extra, GucSource source)
9657 /* Need a modifiable copy of string */
9658 rawstring = pstrdup(*newval);
9660 /* Parse string into list of identifiers */
9661 if (!SplitIdentifierString(rawstring, ',', &elemlist))
9663 /* syntax error in list */
9664 GUC_check_errdetail("List syntax is invalid.");
9666 list_free(elemlist);
9670 foreach(l, elemlist)
9672 char *tok = (char *) lfirst(l);
9674 if (pg_strcasecmp(tok, "stderr") == 0)
9675 newlogdest |= LOG_DESTINATION_STDERR;
9676 else if (pg_strcasecmp(tok, "csvlog") == 0)
9677 newlogdest |= LOG_DESTINATION_CSVLOG;
9679 else if (pg_strcasecmp(tok, "syslog") == 0)
9680 newlogdest |= LOG_DESTINATION_SYSLOG;
9683 else if (pg_strcasecmp(tok, "eventlog") == 0)
9684 newlogdest |= LOG_DESTINATION_EVENTLOG;
9688 GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
9690 list_free(elemlist);
9696 list_free(elemlist);
9698 myextra = (int *) guc_malloc(ERROR, sizeof(int));
9699 *myextra = newlogdest;
9700 *extra = (void *) myextra;
9706 assign_log_destination(const char *newval, void *extra)
9708 Log_destination = *((int *) extra);
9712 assign_syslog_facility(int newval, void *extra)
9715 set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
9718 /* Without syslog support, just ignore it */
9722 assign_syslog_ident(const char *newval, void *extra)
9725 set_syslog_parameters(newval, syslog_facility);
9727 /* Without syslog support, it will always be set to "none", so ignore */
9732 assign_session_replication_role(int newval, void *extra)
9735 * Must flush the plan cache when changing replication role; but don't
9736 * flush unnecessarily.
9738 if (SessionReplicationRole != newval)
9743 check_temp_buffers(int *newval, void **extra, GucSource source)
9746 * Once local buffers have been initialized, it's too late to change this.
9748 if (NLocBuffer && NLocBuffer != *newval)
9750 GUC_check_errdetail("\"temp_buffers\" cannot be changed after any temporary tables have been accessed in the session.");
9757 check_bonjour(bool *newval, void **extra, GucSource source)
9762 GUC_check_errmsg("Bonjour is not supported by this build");
9770 check_ssl(bool *newval, void **extra, GucSource source)
9775 GUC_check_errmsg("SSL is not supported by this build");
9783 check_stage_log_stats(bool *newval, void **extra, GucSource source)
9785 if (*newval && log_statement_stats)
9787 GUC_check_errdetail("Cannot enable parameter when \"log_statement_stats\" is true.");
9794 check_log_stats(bool *newval, void **extra, GucSource source)
9797 (log_parser_stats || log_planner_stats || log_executor_stats))
9799 GUC_check_errdetail("Cannot enable \"log_statement_stats\" when "
9800 "\"log_parser_stats\", \"log_planner_stats\", "
9801 "or \"log_executor_stats\" is true.");
9808 check_canonical_path(char **newval, void **extra, GucSource source)
9811 * Since canonicalize_path never enlarges the string, we can just modify
9812 * newval in-place. But watch out for NULL, which is the default value
9813 * for external_pid_file.
9816 canonicalize_path(*newval);
9821 check_timezone_abbreviations(char **newval, void **extra, GucSource source)
9824 * The boot_val given above for timezone_abbreviations is NULL. When we
9825 * see this we just do nothing. If this value isn't overridden from the
9826 * config file then pg_timezone_abbrev_initialize() will eventually
9827 * replace it with "Default". This hack has two purposes: to avoid
9828 * wasting cycles loading values that might soon be overridden from the
9829 * config file, and to avoid trying to read the timezone abbrev files
9830 * during InitializeGUCOptions(). The latter doesn't work in an
9831 * EXEC_BACKEND subprocess because my_exec_path hasn't been set yet and so
9832 * we can't locate PGSHAREDIR.
9834 if (*newval == NULL)
9836 Assert(source == PGC_S_DEFAULT);
9840 /* OK, load the file and produce a malloc'd TimeZoneAbbrevTable */
9841 *extra = load_tzoffsets(*newval);
9843 /* tzparser.c returns NULL on failure, reporting via GUC_check_errmsg */
9851 assign_timezone_abbreviations(const char *newval, void *extra)
9853 /* Do nothing for the boot_val default of NULL */
9857 InstallTimeZoneAbbrevs((TimeZoneAbbrevTable *) extra);
9861 * pg_timezone_abbrev_initialize --- set default value if not done already
9863 * This is called after initial loading of postgresql.conf. If no
9864 * timezone_abbreviations setting was found therein, select default.
9865 * If a non-default value is already installed, nothing will happen.
9867 * This can also be called from ProcessConfigFile to establish the default
9868 * value after a postgresql.conf entry for it is removed.
9871 pg_timezone_abbrev_initialize(void)
9873 SetConfigOption("timezone_abbreviations", "Default",
9874 PGC_POSTMASTER, PGC_S_DYNAMIC_DEFAULT);
9878 show_archive_command(void)
9880 if (XLogArchivingActive())
9881 return XLogArchiveCommand;
9883 return "(disabled)";
9887 assign_tcp_keepalives_idle(int newval, void *extra)
9890 * The kernel API provides no way to test a value without setting it; and
9891 * once we set it we might fail to unset it. So there seems little point
9892 * in fully implementing the check-then-assign GUC API for these
9893 * variables. Instead we just do the assignment on demand. pqcomm.c
9894 * reports any problems via elog(LOG).
9896 * This approach means that the GUC value might have little to do with the
9897 * actual kernel value, so we use a show_hook that retrieves the kernel
9898 * value rather than trusting GUC's copy.
9900 (void) pq_setkeepalivesidle(newval, MyProcPort);
9904 show_tcp_keepalives_idle(void)
9906 /* See comments in assign_tcp_keepalives_idle */
9907 static char nbuf[16];
9909 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesidle(MyProcPort));
9914 assign_tcp_keepalives_interval(int newval, void *extra)
9916 /* See comments in assign_tcp_keepalives_idle */
9917 (void) pq_setkeepalivesinterval(newval, MyProcPort);
9921 show_tcp_keepalives_interval(void)
9923 /* See comments in assign_tcp_keepalives_idle */
9924 static char nbuf[16];
9926 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesinterval(MyProcPort));
9931 assign_tcp_keepalives_count(int newval, void *extra)
9933 /* See comments in assign_tcp_keepalives_idle */
9934 (void) pq_setkeepalivescount(newval, MyProcPort);
9938 show_tcp_keepalives_count(void)
9940 /* See comments in assign_tcp_keepalives_idle */
9941 static char nbuf[16];
9943 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivescount(MyProcPort));
9948 check_maxconnections(int *newval, void **extra, GucSource source)
9950 if (*newval + autovacuum_max_workers + 1 +
9951 max_worker_processes > MAX_BACKENDS)
9957 check_autovacuum_max_workers(int *newval, void **extra, GucSource source)
9959 if (MaxConnections + *newval + 1 + max_worker_processes > MAX_BACKENDS)
9965 check_autovacuum_work_mem(int *newval, void **extra, GucSource source)
9968 * -1 indicates fallback.
9970 * If we haven't yet changed the boot_val default of -1, just let it be.
9971 * Autovacuum will look to maintenance_work_mem instead.
9977 * We clamp manually-set values to at least 1MB. Since
9978 * maintenance_work_mem is always set to at least this value, do the same
9988 check_max_worker_processes(int *newval, void **extra, GucSource source)
9990 if (MaxConnections + autovacuum_max_workers + 1 + *newval > MAX_BACKENDS)
9996 check_effective_io_concurrency(int *newval, void **extra, GucSource source)
9999 double new_prefetch_pages;
10001 if (ComputeIoConcurrency(*newval, &new_prefetch_pages))
10003 int *myextra = (int *) guc_malloc(ERROR, sizeof(int));
10005 *myextra = (int) rint(new_prefetch_pages);
10006 *extra = (void *) myextra;
10014 #endif /* USE_PREFETCH */
10018 assign_effective_io_concurrency(int newval, void *extra)
10020 #ifdef USE_PREFETCH
10021 target_prefetch_pages = *((int *) extra);
10022 #endif /* USE_PREFETCH */
10026 assign_pgstat_temp_directory(const char *newval, void *extra)
10028 /* check_canonical_path already canonicalized newval for us */
10034 dname = guc_malloc(ERROR, strlen(newval) + 1); /* runtime dir */
10035 sprintf(dname, "%s", newval);
10038 tname = guc_malloc(ERROR, strlen(newval) + 12); /* /global.tmp */
10039 sprintf(tname, "%s/global.tmp", newval);
10040 fname = guc_malloc(ERROR, strlen(newval) + 13); /* /global.stat */
10041 sprintf(fname, "%s/global.stat", newval);
10043 if (pgstat_stat_directory)
10044 free(pgstat_stat_directory);
10045 pgstat_stat_directory = dname;
10046 if (pgstat_stat_tmpname)
10047 free(pgstat_stat_tmpname);
10048 pgstat_stat_tmpname = tname;
10049 if (pgstat_stat_filename)
10050 free(pgstat_stat_filename);
10051 pgstat_stat_filename = fname;
10055 check_application_name(char **newval, void **extra, GucSource source)
10057 /* Only allow clean ASCII chars in the application name */
10060 for (p = *newval; *p; p++)
10062 if (*p < 32 || *p > 126)
10070 assign_application_name(const char *newval, void *extra)
10072 /* Update the pg_stat_activity view */
10073 pgstat_report_appname(newval);
10077 check_cluster_name(char **newval, void **extra, GucSource source)
10079 /* Only allow clean ASCII chars in the cluster name */
10082 for (p = *newval; *p; p++)
10084 if (*p < 32 || *p > 126)
10091 static const char *
10092 show_unix_socket_permissions(void)
10094 static char buf[8];
10096 snprintf(buf, sizeof(buf), "%04o", Unix_socket_permissions);
10100 static const char *
10101 show_log_file_mode(void)
10103 static char buf[8];
10105 snprintf(buf, sizeof(buf), "%04o", Log_file_mode);
10109 #include "guc-file.c"