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-2014, PostgreSQL Global Development Group
10 * Written by Peter Eisentraut <peter_e@gmx.net>.
13 * src/backend/utils/misc/guc.c
15 *--------------------------------------------------------------------
29 #include "access/gin.h"
30 #include "access/transam.h"
31 #include "access/twophase.h"
32 #include "access/xact.h"
33 #include "catalog/namespace.h"
34 #include "commands/async.h"
35 #include "commands/prepare.h"
36 #include "commands/vacuum.h"
37 #include "commands/variable.h"
38 #include "commands/trigger.h"
40 #include "libpq/auth.h"
41 #include "libpq/be-fsstubs.h"
42 #include "libpq/libpq.h"
43 #include "libpq/pqformat.h"
44 #include "miscadmin.h"
45 #include "optimizer/cost.h"
46 #include "optimizer/geqo.h"
47 #include "optimizer/paths.h"
48 #include "optimizer/planmain.h"
49 #include "parser/parse_expr.h"
50 #include "parser/parse_type.h"
51 #include "parser/parser.h"
52 #include "parser/scansup.h"
54 #include "postmaster/autovacuum.h"
55 #include "postmaster/bgworker.h"
56 #include "postmaster/bgwriter.h"
57 #include "postmaster/postmaster.h"
58 #include "postmaster/syslogger.h"
59 #include "postmaster/walwriter.h"
60 #include "replication/slot.h"
61 #include "replication/syncrep.h"
62 #include "replication/walreceiver.h"
63 #include "replication/walsender.h"
64 #include "storage/bufmgr.h"
65 #include "storage/dsm_impl.h"
66 #include "storage/standby.h"
67 #include "storage/fd.h"
68 #include "storage/pg_shmem.h"
69 #include "storage/proc.h"
70 #include "storage/predicate.h"
71 #include "tcop/tcopprot.h"
72 #include "tsearch/ts_cache.h"
73 #include "utils/builtins.h"
74 #include "utils/bytea.h"
75 #include "utils/guc_tables.h"
76 #include "utils/memutils.h"
77 #include "utils/pg_locale.h"
78 #include "utils/plancache.h"
79 #include "utils/portal.h"
80 #include "utils/ps_status.h"
81 #include "utils/snapmgr.h"
82 #include "utils/tzparser.h"
83 #include "utils/xml.h"
86 #define PG_KRB_SRVTAB ""
89 #define CONFIG_FILENAME "postgresql.conf"
90 #define HBA_FILENAME "pg_hba.conf"
91 #define IDENT_FILENAME "pg_ident.conf"
94 #define CONFIG_EXEC_PARAMS "global/config_exec_params"
95 #define CONFIG_EXEC_PARAMS_NEW "global/config_exec_params.new"
98 /* upper limit for GUC variables measured in kilobytes of memory */
99 /* note that various places assume the byte size fits in a "long" variable */
100 #if SIZEOF_SIZE_T > 4 && SIZEOF_LONG > 4
101 #define MAX_KILOBYTES INT_MAX
103 #define MAX_KILOBYTES (INT_MAX / 1024)
106 #define KB_PER_MB (1024)
107 #define KB_PER_GB (1024*1024)
108 #define KB_PER_TB (1024*1024*1024)
110 #define MS_PER_S 1000
112 #define MS_PER_MIN (1000 * 60)
114 #define S_PER_H (60 * 60)
115 #define MS_PER_H (1000 * 60 * 60)
116 #define MIN_PER_D (60 * 24)
117 #define S_PER_D (60 * 60 * 24)
118 #define MS_PER_D (1000 * 60 * 60 * 24)
120 /* XXX these should appear in other modules' header files */
121 extern bool Log_disconnections;
122 extern int CommitDelay;
123 extern int CommitSiblings;
124 extern char *default_tablespace;
125 extern char *temp_tablespaces;
126 extern bool ignore_checksum_failure;
127 extern bool synchronize_seqscans;
128 extern char *SSLCipherSuites;
129 extern char *SSLECDHCurve;
130 extern bool SSLPreferServerCiphers;
133 extern bool trace_sort;
135 #ifdef TRACE_SYNCSCAN
136 extern bool trace_syncscan;
138 #ifdef DEBUG_BOUNDED_SORT
139 extern bool optimize_bounded_sort;
142 static int GUC_check_errcode_value;
144 /* global variables for check hook support */
145 char *GUC_check_errmsg_string;
146 char *GUC_check_errdetail_string;
147 char *GUC_check_errhint_string;
150 static void set_config_sourcefile(const char *name, char *sourcefile,
152 static bool call_bool_check_hook(struct config_bool * conf, bool *newval,
153 void **extra, GucSource source, int elevel);
154 static bool call_int_check_hook(struct config_int * conf, int *newval,
155 void **extra, GucSource source, int elevel);
156 static bool call_real_check_hook(struct config_real * conf, double *newval,
157 void **extra, GucSource source, int elevel);
158 static bool call_string_check_hook(struct config_string * conf, char **newval,
159 void **extra, GucSource source, int elevel);
160 static bool call_enum_check_hook(struct config_enum * conf, int *newval,
161 void **extra, GucSource source, int elevel);
163 static bool check_log_destination(char **newval, void **extra, GucSource source);
164 static void assign_log_destination(const char *newval, void *extra);
167 static int syslog_facility = LOG_LOCAL0;
169 static int syslog_facility = 0;
172 static void assign_syslog_facility(int newval, void *extra);
173 static void assign_syslog_ident(const char *newval, void *extra);
174 static void assign_session_replication_role(int newval, void *extra);
175 static bool check_temp_buffers(int *newval, void **extra, GucSource source);
176 static bool check_phony_autocommit(bool *newval, void **extra, GucSource source);
177 static bool check_debug_assertions(bool *newval, void **extra, GucSource source);
178 static bool check_bonjour(bool *newval, void **extra, GucSource source);
179 static bool check_ssl(bool *newval, void **extra, GucSource source);
180 static bool check_stage_log_stats(bool *newval, void **extra, GucSource source);
181 static bool check_log_stats(bool *newval, void **extra, GucSource source);
182 static bool check_canonical_path(char **newval, void **extra, GucSource source);
183 static bool check_timezone_abbreviations(char **newval, void **extra, GucSource source);
184 static void assign_timezone_abbreviations(const char *newval, void *extra);
185 static void pg_timezone_abbrev_initialize(void);
186 static const char *show_archive_command(void);
187 static void assign_tcp_keepalives_idle(int newval, void *extra);
188 static void assign_tcp_keepalives_interval(int newval, void *extra);
189 static void assign_tcp_keepalives_count(int newval, void *extra);
190 static const char *show_tcp_keepalives_idle(void);
191 static const char *show_tcp_keepalives_interval(void);
192 static const char *show_tcp_keepalives_count(void);
193 static bool check_maxconnections(int *newval, void **extra, GucSource source);
194 static bool check_max_worker_processes(int *newval, void **extra, GucSource source);
195 static bool check_autovacuum_max_workers(int *newval, void **extra, GucSource source);
196 static bool check_autovacuum_work_mem(int *newval, void **extra, GucSource source);
197 static bool check_effective_io_concurrency(int *newval, void **extra, GucSource source);
198 static void assign_effective_io_concurrency(int newval, void *extra);
199 static void assign_pgstat_temp_directory(const char *newval, void *extra);
200 static bool check_application_name(char **newval, void **extra, GucSource source);
201 static void assign_application_name(const char *newval, void *extra);
202 static const char *show_unix_socket_permissions(void);
203 static const char *show_log_file_mode(void);
205 static char *config_enum_get_options(struct config_enum * record,
206 const char *prefix, const char *suffix,
207 const char *separator);
209 static bool validate_conf_option(struct config_generic * record,
210 const char *name, const char *value, GucSource source,
211 int elevel, bool freemem, void *newval, void **newextra);
215 * Options for enum values defined in this module.
217 * NOTE! Option values may not contain double quotes!
220 static const struct config_enum_entry bytea_output_options[] = {
221 {"escape", BYTEA_OUTPUT_ESCAPE, false},
222 {"hex", BYTEA_OUTPUT_HEX, false},
227 * We have different sets for client and server message level options because
228 * they sort slightly different (see "log" level)
230 static const struct config_enum_entry client_message_level_options[] = {
231 {"debug", DEBUG2, true},
232 {"debug5", DEBUG5, false},
233 {"debug4", DEBUG4, false},
234 {"debug3", DEBUG3, false},
235 {"debug2", DEBUG2, false},
236 {"debug1", DEBUG1, false},
238 {"info", INFO, true},
239 {"notice", NOTICE, false},
240 {"warning", WARNING, false},
241 {"error", ERROR, false},
242 {"fatal", FATAL, true},
243 {"panic", PANIC, true},
247 static const struct config_enum_entry server_message_level_options[] = {
248 {"debug", DEBUG2, true},
249 {"debug5", DEBUG5, false},
250 {"debug4", DEBUG4, false},
251 {"debug3", DEBUG3, false},
252 {"debug2", DEBUG2, false},
253 {"debug1", DEBUG1, false},
254 {"info", INFO, false},
255 {"notice", NOTICE, false},
256 {"warning", WARNING, false},
257 {"error", ERROR, false},
259 {"fatal", FATAL, false},
260 {"panic", PANIC, false},
264 static const struct config_enum_entry intervalstyle_options[] = {
265 {"postgres", INTSTYLE_POSTGRES, false},
266 {"postgres_verbose", INTSTYLE_POSTGRES_VERBOSE, false},
267 {"sql_standard", INTSTYLE_SQL_STANDARD, false},
268 {"iso_8601", INTSTYLE_ISO_8601, false},
272 static const struct config_enum_entry log_error_verbosity_options[] = {
273 {"terse", PGERROR_TERSE, false},
274 {"default", PGERROR_DEFAULT, false},
275 {"verbose", PGERROR_VERBOSE, false},
279 static const struct config_enum_entry log_statement_options[] = {
280 {"none", LOGSTMT_NONE, false},
281 {"ddl", LOGSTMT_DDL, false},
282 {"mod", LOGSTMT_MOD, false},
283 {"all", LOGSTMT_ALL, false},
287 static const struct config_enum_entry isolation_level_options[] = {
288 {"serializable", XACT_SERIALIZABLE, false},
289 {"repeatable read", XACT_REPEATABLE_READ, false},
290 {"read committed", XACT_READ_COMMITTED, false},
291 {"read uncommitted", XACT_READ_UNCOMMITTED, false},
295 static const struct config_enum_entry session_replication_role_options[] = {
296 {"origin", SESSION_REPLICATION_ROLE_ORIGIN, false},
297 {"replica", SESSION_REPLICATION_ROLE_REPLICA, false},
298 {"local", SESSION_REPLICATION_ROLE_LOCAL, false},
302 static const struct config_enum_entry syslog_facility_options[] = {
304 {"local0", LOG_LOCAL0, false},
305 {"local1", LOG_LOCAL1, false},
306 {"local2", LOG_LOCAL2, false},
307 {"local3", LOG_LOCAL3, false},
308 {"local4", LOG_LOCAL4, false},
309 {"local5", LOG_LOCAL5, false},
310 {"local6", LOG_LOCAL6, false},
311 {"local7", LOG_LOCAL7, false},
318 static const struct config_enum_entry track_function_options[] = {
319 {"none", TRACK_FUNC_OFF, false},
320 {"pl", TRACK_FUNC_PL, false},
321 {"all", TRACK_FUNC_ALL, false},
325 static const struct config_enum_entry xmlbinary_options[] = {
326 {"base64", XMLBINARY_BASE64, false},
327 {"hex", XMLBINARY_HEX, false},
331 static const struct config_enum_entry xmloption_options[] = {
332 {"content", XMLOPTION_CONTENT, false},
333 {"document", XMLOPTION_DOCUMENT, false},
338 * Although only "on", "off", and "safe_encoding" are documented, we
339 * accept all the likely variants of "on" and "off".
341 static const struct config_enum_entry backslash_quote_options[] = {
342 {"safe_encoding", BACKSLASH_QUOTE_SAFE_ENCODING, false},
343 {"on", BACKSLASH_QUOTE_ON, false},
344 {"off", BACKSLASH_QUOTE_OFF, false},
345 {"true", BACKSLASH_QUOTE_ON, true},
346 {"false", BACKSLASH_QUOTE_OFF, true},
347 {"yes", BACKSLASH_QUOTE_ON, true},
348 {"no", BACKSLASH_QUOTE_OFF, true},
349 {"1", BACKSLASH_QUOTE_ON, true},
350 {"0", BACKSLASH_QUOTE_OFF, true},
355 * Although only "on", "off", and "partition" are documented, we
356 * accept all the likely variants of "on" and "off".
358 static const struct config_enum_entry constraint_exclusion_options[] = {
359 {"partition", CONSTRAINT_EXCLUSION_PARTITION, false},
360 {"on", CONSTRAINT_EXCLUSION_ON, false},
361 {"off", CONSTRAINT_EXCLUSION_OFF, false},
362 {"true", CONSTRAINT_EXCLUSION_ON, true},
363 {"false", CONSTRAINT_EXCLUSION_OFF, true},
364 {"yes", CONSTRAINT_EXCLUSION_ON, true},
365 {"no", CONSTRAINT_EXCLUSION_OFF, true},
366 {"1", CONSTRAINT_EXCLUSION_ON, true},
367 {"0", CONSTRAINT_EXCLUSION_OFF, true},
372 * Although only "on", "off", "remote_write", and "local" are documented, we
373 * accept all the likely variants of "on" and "off".
375 static const struct config_enum_entry synchronous_commit_options[] = {
376 {"local", SYNCHRONOUS_COMMIT_LOCAL_FLUSH, false},
377 {"remote_write", SYNCHRONOUS_COMMIT_REMOTE_WRITE, false},
378 {"on", SYNCHRONOUS_COMMIT_ON, false},
379 {"off", SYNCHRONOUS_COMMIT_OFF, false},
380 {"true", SYNCHRONOUS_COMMIT_ON, true},
381 {"false", SYNCHRONOUS_COMMIT_OFF, true},
382 {"yes", SYNCHRONOUS_COMMIT_ON, true},
383 {"no", SYNCHRONOUS_COMMIT_OFF, true},
384 {"1", SYNCHRONOUS_COMMIT_ON, true},
385 {"0", SYNCHRONOUS_COMMIT_OFF, true},
390 * Although only "on", "off", "try" are documented, we accept all the likely
391 * variants of "on" and "off".
393 static const struct config_enum_entry huge_pages_options[] = {
394 {"off", HUGE_PAGES_OFF, false},
395 {"on", HUGE_PAGES_ON, false},
396 {"try", HUGE_PAGES_TRY, false},
397 {"true", HUGE_PAGES_ON, true},
398 {"false", HUGE_PAGES_OFF, true},
399 {"yes", HUGE_PAGES_ON, true},
400 {"no", HUGE_PAGES_OFF, true},
401 {"1", HUGE_PAGES_ON, true},
402 {"0", HUGE_PAGES_OFF, true},
407 * Options for enum values stored in other modules
409 extern const struct config_enum_entry wal_level_options[];
410 extern const struct config_enum_entry sync_method_options[];
411 extern const struct config_enum_entry dynamic_shared_memory_options[];
414 * GUC option variables that are exported from this module
416 #ifdef USE_ASSERT_CHECKING
417 bool assert_enabled = true;
419 bool assert_enabled = false;
421 bool log_duration = false;
422 bool Debug_print_plan = false;
423 bool Debug_print_parse = false;
424 bool Debug_print_rewritten = false;
425 bool Debug_pretty_print = true;
427 bool log_parser_stats = false;
428 bool log_planner_stats = false;
429 bool log_executor_stats = false;
430 bool log_statement_stats = false; /* this is sort of all three
432 bool log_btree_build_stats = false;
435 bool check_function_bodies = true;
436 bool default_with_oids = false;
437 bool SQL_inheritance = true;
439 bool Password_encryption = true;
441 int log_min_error_statement = ERROR;
442 int log_min_messages = WARNING;
443 int client_min_messages = NOTICE;
444 int log_min_duration_statement = -1;
445 int log_temp_files = -1;
446 int trace_recovery_messages = LOG;
448 int temp_file_limit = -1;
450 int num_temp_buffers = 1024;
452 char *data_directory;
453 char *ConfigFileName;
456 char *external_pid_file;
458 char *pgstat_temp_directory;
460 char *application_name;
462 int tcp_keepalives_idle;
463 int tcp_keepalives_interval;
464 int tcp_keepalives_count;
467 * This really belongs in pg_shmem.c, but is defined here so that it doesn't
468 * need to be duplicated in all the different implementations of pg_shmem.c.
473 * These variables are all dummies that don't do anything, except in some
474 * cases provide the value for SHOW to display. The real state is elsewhere
475 * and is kept in sync by assign_hooks.
477 static char *syslog_ident_str;
478 static bool phony_autocommit;
479 static bool session_auth_is_superuser;
480 static double phony_random_seed;
481 static char *client_encoding_string;
482 static char *datestyle_string;
483 static char *locale_collate;
484 static char *locale_ctype;
485 static char *server_encoding_string;
486 static char *server_version_string;
487 static int server_version_num;
488 static char *timezone_string;
489 static char *log_timezone_string;
490 static char *timezone_abbreviations_string;
491 static char *XactIsoLevel_string;
492 static char *session_authorization_string;
493 static int max_function_args;
494 static int max_index_keys;
495 static int max_identifier_length;
496 static int block_size;
497 static int segment_size;
498 static int wal_block_size;
499 static bool data_checksums;
500 static int wal_segment_size;
501 static bool integer_datetimes;
502 static int effective_io_concurrency;
504 /* should be static, but commands/variable.c needs to get at this */
509 * Displayable names for context types (enum GucContext)
511 * Note: these strings are deliberately not localized.
513 const char *const GucContext_Names[] =
515 /* PGC_INTERNAL */ "internal",
516 /* PGC_POSTMASTER */ "postmaster",
517 /* PGC_SIGHUP */ "sighup",
518 /* PGC_BACKEND */ "backend",
519 /* PGC_SUSET */ "superuser",
520 /* PGC_USERSET */ "user"
524 * Displayable names for source types (enum GucSource)
526 * Note: these strings are deliberately not localized.
528 const char *const GucSource_Names[] =
530 /* PGC_S_DEFAULT */ "default",
531 /* PGC_S_DYNAMIC_DEFAULT */ "default",
532 /* PGC_S_ENV_VAR */ "environment variable",
533 /* PGC_S_FILE */ "configuration file",
534 /* PGC_S_ARGV */ "command line",
535 /* PGC_S_GLOBAL */ "global",
536 /* PGC_S_DATABASE */ "database",
537 /* PGC_S_USER */ "user",
538 /* PGC_S_DATABASE_USER */ "database user",
539 /* PGC_S_CLIENT */ "client",
540 /* PGC_S_OVERRIDE */ "override",
541 /* PGC_S_INTERACTIVE */ "interactive",
542 /* PGC_S_TEST */ "test",
543 /* PGC_S_SESSION */ "session"
547 * Displayable names for the groupings defined in enum config_group
549 const char *const config_group_names[] =
552 gettext_noop("Ungrouped"),
554 gettext_noop("File Locations"),
556 gettext_noop("Connections and Authentication"),
557 /* CONN_AUTH_SETTINGS */
558 gettext_noop("Connections and Authentication / Connection Settings"),
559 /* CONN_AUTH_SECURITY */
560 gettext_noop("Connections and Authentication / Security and Authentication"),
562 gettext_noop("Resource Usage"),
564 gettext_noop("Resource Usage / Memory"),
566 gettext_noop("Resource Usage / Disk"),
567 /* RESOURCES_KERNEL */
568 gettext_noop("Resource Usage / Kernel Resources"),
569 /* RESOURCES_VACUUM_DELAY */
570 gettext_noop("Resource Usage / Cost-Based Vacuum Delay"),
571 /* RESOURCES_BGWRITER */
572 gettext_noop("Resource Usage / Background Writer"),
573 /* RESOURCES_ASYNCHRONOUS */
574 gettext_noop("Resource Usage / Asynchronous Behavior"),
576 gettext_noop("Write-Ahead Log"),
578 gettext_noop("Write-Ahead Log / Settings"),
579 /* WAL_CHECKPOINTS */
580 gettext_noop("Write-Ahead Log / Checkpoints"),
582 gettext_noop("Write-Ahead Log / Archiving"),
584 gettext_noop("Replication"),
585 /* REPLICATION_SENDING */
586 gettext_noop("Replication / Sending Servers"),
587 /* REPLICATION_MASTER */
588 gettext_noop("Replication / Master Server"),
589 /* REPLICATION_STANDBY */
590 gettext_noop("Replication / Standby Servers"),
592 gettext_noop("Query Tuning"),
593 /* QUERY_TUNING_METHOD */
594 gettext_noop("Query Tuning / Planner Method Configuration"),
595 /* QUERY_TUNING_COST */
596 gettext_noop("Query Tuning / Planner Cost Constants"),
597 /* QUERY_TUNING_GEQO */
598 gettext_noop("Query Tuning / Genetic Query Optimizer"),
599 /* QUERY_TUNING_OTHER */
600 gettext_noop("Query Tuning / Other Planner Options"),
602 gettext_noop("Reporting and Logging"),
604 gettext_noop("Reporting and Logging / Where to Log"),
606 gettext_noop("Reporting and Logging / When to Log"),
608 gettext_noop("Reporting and Logging / What to Log"),
610 gettext_noop("Statistics"),
611 /* STATS_MONITORING */
612 gettext_noop("Statistics / Monitoring"),
613 /* STATS_COLLECTOR */
614 gettext_noop("Statistics / Query and Index Statistics Collector"),
616 gettext_noop("Autovacuum"),
618 gettext_noop("Client Connection Defaults"),
619 /* CLIENT_CONN_STATEMENT */
620 gettext_noop("Client Connection Defaults / Statement Behavior"),
621 /* CLIENT_CONN_LOCALE */
622 gettext_noop("Client Connection Defaults / Locale and Formatting"),
623 /* CLIENT_CONN_PRELOAD */
624 gettext_noop("Client Connection Defaults / Shared Library Preloading"),
625 /* CLIENT_CONN_OTHER */
626 gettext_noop("Client Connection Defaults / Other Defaults"),
627 /* LOCK_MANAGEMENT */
628 gettext_noop("Lock Management"),
630 gettext_noop("Version and Platform Compatibility"),
631 /* COMPAT_OPTIONS_PREVIOUS */
632 gettext_noop("Version and Platform Compatibility / Previous PostgreSQL Versions"),
633 /* COMPAT_OPTIONS_CLIENT */
634 gettext_noop("Version and Platform Compatibility / Other Platforms and Clients"),
636 gettext_noop("Error Handling"),
638 gettext_noop("Preset Options"),
640 gettext_noop("Customized Options"),
641 /* DEVELOPER_OPTIONS */
642 gettext_noop("Developer Options"),
643 /* help_config wants this array to be null-terminated */
648 * Displayable names for GUC variable types (enum config_type)
650 * Note: these strings are deliberately not localized.
652 const char *const config_type_names[] =
654 /* PGC_BOOL */ "bool",
655 /* PGC_INT */ "integer",
656 /* PGC_REAL */ "real",
657 /* PGC_STRING */ "string",
658 /* PGC_ENUM */ "enum"
663 * Contents of GUC tables
665 * See src/backend/utils/misc/README for design notes.
669 * 1. Declare a global variable of type bool, int, double, or char*
670 * and make use of it.
672 * 2. Decide at what times it's safe to set the option. See guc.h for
675 * 3. Decide on a name, a default value, upper and lower bounds (if
678 * 4. Add a record below.
680 * 5. Add it to src/backend/utils/misc/postgresql.conf.sample, if
683 * 6. Don't forget to document the option (at least in config.sgml).
685 * 7. If it's a new GUC_LIST option you must edit pg_dumpall.c to ensure
686 * it is not single quoted at dump time.
690 /******** option records follow ********/
692 static struct config_bool ConfigureNamesBool[] =
695 {"enable_seqscan", PGC_USERSET, QUERY_TUNING_METHOD,
696 gettext_noop("Enables the planner's use of sequential-scan plans."),
704 {"enable_indexscan", PGC_USERSET, QUERY_TUNING_METHOD,
705 gettext_noop("Enables the planner's use of index-scan plans."),
713 {"enable_indexonlyscan", PGC_USERSET, QUERY_TUNING_METHOD,
714 gettext_noop("Enables the planner's use of index-only-scan plans."),
717 &enable_indexonlyscan,
722 {"enable_bitmapscan", PGC_USERSET, QUERY_TUNING_METHOD,
723 gettext_noop("Enables the planner's use of bitmap-scan plans."),
731 {"enable_tidscan", PGC_USERSET, QUERY_TUNING_METHOD,
732 gettext_noop("Enables the planner's use of TID scan plans."),
740 {"enable_sort", PGC_USERSET, QUERY_TUNING_METHOD,
741 gettext_noop("Enables the planner's use of explicit sort steps."),
749 {"enable_hashagg", PGC_USERSET, QUERY_TUNING_METHOD,
750 gettext_noop("Enables the planner's use of hashed aggregation plans."),
758 {"enable_material", PGC_USERSET, QUERY_TUNING_METHOD,
759 gettext_noop("Enables the planner's use of materialization."),
767 {"enable_nestloop", PGC_USERSET, QUERY_TUNING_METHOD,
768 gettext_noop("Enables the planner's use of nested-loop join plans."),
776 {"enable_mergejoin", PGC_USERSET, QUERY_TUNING_METHOD,
777 gettext_noop("Enables the planner's use of merge join plans."),
785 {"enable_hashjoin", PGC_USERSET, QUERY_TUNING_METHOD,
786 gettext_noop("Enables the planner's use of hash join plans."),
794 {"geqo", PGC_USERSET, QUERY_TUNING_GEQO,
795 gettext_noop("Enables genetic query optimization."),
796 gettext_noop("This algorithm attempts to do planning without "
797 "exhaustive searching.")
804 /* Not for general use --- used by SET SESSION AUTHORIZATION */
805 {"is_superuser", PGC_INTERNAL, UNGROUPED,
806 gettext_noop("Shows whether the current user is a superuser."),
808 GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
810 &session_auth_is_superuser,
815 {"bonjour", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
816 gettext_noop("Enables advertising the server via Bonjour."),
821 check_bonjour, NULL, NULL
824 {"ssl", PGC_POSTMASTER, CONN_AUTH_SECURITY,
825 gettext_noop("Enables SSL connections."),
830 check_ssl, NULL, NULL
833 {"ssl_prefer_server_ciphers", PGC_POSTMASTER, CONN_AUTH_SECURITY,
834 gettext_noop("Give priority to server ciphersuite order."),
837 &SSLPreferServerCiphers,
842 {"fsync", PGC_SIGHUP, WAL_SETTINGS,
843 gettext_noop("Forces synchronization of updates to disk."),
844 gettext_noop("The server will use the fsync() system call in several places to make "
845 "sure that updates are physically written to disk. This insures "
846 "that a database cluster will recover to a consistent state after "
847 "an operating system or hardware crash.")
854 {"ignore_checksum_failure", PGC_SUSET, DEVELOPER_OPTIONS,
855 gettext_noop("Continues processing after a checksum failure."),
856 gettext_noop("Detection of a checksum failure normally causes PostgreSQL to "
857 "report an error, aborting the current transaction. Setting "
858 "ignore_checksum_failure to true causes the system to ignore the failure "
859 "(but still report a warning), and continue processing. This "
860 "behavior could cause crashes or other serious problems. Only "
861 "has an effect if checksums are enabled."),
864 &ignore_checksum_failure,
869 {"zero_damaged_pages", PGC_SUSET, DEVELOPER_OPTIONS,
870 gettext_noop("Continues processing past damaged page headers."),
871 gettext_noop("Detection of a damaged page header normally causes PostgreSQL to "
872 "report an error, aborting the current transaction. Setting "
873 "zero_damaged_pages to true causes the system to instead report a "
874 "warning, zero out the damaged page, and continue processing. This "
875 "behavior will destroy data, namely all the rows on the damaged page."),
883 {"full_page_writes", PGC_SIGHUP, WAL_SETTINGS,
884 gettext_noop("Writes full pages to WAL when first modified after a checkpoint."),
885 gettext_noop("A page write in process during an operating system crash might be "
886 "only partially written to disk. During recovery, the row changes "
887 "stored in WAL are not enough to recover. This option writes "
888 "pages when first modified after a checkpoint to WAL so full recovery "
897 {"wal_log_hints", PGC_POSTMASTER, WAL_SETTINGS,
898 gettext_noop("Writes full pages to WAL when first modified after a checkpoint, even for a non-critical modifications"),
907 {"log_checkpoints", PGC_SIGHUP, LOGGING_WHAT,
908 gettext_noop("Logs each checkpoint."),
916 {"log_connections", PGC_BACKEND, LOGGING_WHAT,
917 gettext_noop("Logs each successful connection."),
925 {"log_disconnections", PGC_BACKEND, LOGGING_WHAT,
926 gettext_noop("Logs end of a session, including duration."),
934 {"debug_assertions", PGC_USERSET, DEVELOPER_OPTIONS,
935 gettext_noop("Turns on various assertion checks."),
936 gettext_noop("This is a debugging aid."),
940 #ifdef USE_ASSERT_CHECKING
945 check_debug_assertions, NULL, NULL
949 {"exit_on_error", PGC_USERSET, ERROR_HANDLING_OPTIONS,
950 gettext_noop("Terminate session on any error."),
958 {"restart_after_crash", PGC_SIGHUP, ERROR_HANDLING_OPTIONS,
959 gettext_noop("Reinitialize server after backend crash."),
962 &restart_after_crash,
968 {"log_duration", PGC_SUSET, LOGGING_WHAT,
969 gettext_noop("Logs the duration of each completed SQL statement."),
977 {"debug_print_parse", PGC_USERSET, LOGGING_WHAT,
978 gettext_noop("Logs each query's parse tree."),
986 {"debug_print_rewritten", PGC_USERSET, LOGGING_WHAT,
987 gettext_noop("Logs each query's rewritten parse tree."),
990 &Debug_print_rewritten,
995 {"debug_print_plan", PGC_USERSET, LOGGING_WHAT,
996 gettext_noop("Logs each query's execution plan."),
1004 {"debug_pretty_print", PGC_USERSET, LOGGING_WHAT,
1005 gettext_noop("Indents parse and plan tree displays."),
1008 &Debug_pretty_print,
1013 {"log_parser_stats", PGC_SUSET, STATS_MONITORING,
1014 gettext_noop("Writes parser performance statistics to the server log."),
1019 check_stage_log_stats, NULL, NULL
1022 {"log_planner_stats", PGC_SUSET, STATS_MONITORING,
1023 gettext_noop("Writes planner performance statistics to the server log."),
1028 check_stage_log_stats, NULL, NULL
1031 {"log_executor_stats", PGC_SUSET, STATS_MONITORING,
1032 gettext_noop("Writes executor performance statistics to the server log."),
1035 &log_executor_stats,
1037 check_stage_log_stats, NULL, NULL
1040 {"log_statement_stats", PGC_SUSET, STATS_MONITORING,
1041 gettext_noop("Writes cumulative performance statistics to the server log."),
1044 &log_statement_stats,
1046 check_log_stats, NULL, NULL
1048 #ifdef BTREE_BUILD_STATS
1050 {"log_btree_build_stats", PGC_SUSET, DEVELOPER_OPTIONS,
1051 gettext_noop("Logs system resource usage statistics (memory and CPU) on various B-tree operations."),
1055 &log_btree_build_stats,
1062 {"track_activities", PGC_SUSET, STATS_COLLECTOR,
1063 gettext_noop("Collects information about executing commands."),
1064 gettext_noop("Enables the collection of information on the currently "
1065 "executing command of each session, along with "
1066 "the time at which that command began execution.")
1068 &pgstat_track_activities,
1073 {"track_counts", PGC_SUSET, STATS_COLLECTOR,
1074 gettext_noop("Collects statistics on database activity."),
1077 &pgstat_track_counts,
1082 {"track_io_timing", PGC_SUSET, STATS_COLLECTOR,
1083 gettext_noop("Collects timing statistics for database I/O activity."),
1092 {"update_process_title", PGC_SUSET, STATS_COLLECTOR,
1093 gettext_noop("Updates the process title to show the active SQL command."),
1094 gettext_noop("Enables updating of the process title every time a new SQL command is received by the server.")
1096 &update_process_title,
1102 {"autovacuum", PGC_SIGHUP, AUTOVACUUM,
1103 gettext_noop("Starts the autovacuum subprocess."),
1106 &autovacuum_start_daemon,
1112 {"trace_notify", PGC_USERSET, DEVELOPER_OPTIONS,
1113 gettext_noop("Generates debugging output for LISTEN and NOTIFY."),
1124 {"trace_locks", PGC_SUSET, DEVELOPER_OPTIONS,
1125 gettext_noop("Emits information about lock usage."),
1134 {"trace_userlocks", PGC_SUSET, DEVELOPER_OPTIONS,
1135 gettext_noop("Emits information about user lock usage."),
1144 {"trace_lwlocks", PGC_SUSET, DEVELOPER_OPTIONS,
1145 gettext_noop("Emits information about lightweight lock usage."),
1154 {"debug_deadlocks", PGC_SUSET, DEVELOPER_OPTIONS,
1155 gettext_noop("Dumps information about all current locks when a deadlock timeout occurs."),
1166 {"log_lock_waits", PGC_SUSET, LOGGING_WHAT,
1167 gettext_noop("Logs long lock waits."),
1176 {"log_hostname", PGC_SIGHUP, LOGGING_WHAT,
1177 gettext_noop("Logs the host name in the connection logs."),
1178 gettext_noop("By default, connection logs only show the IP address "
1179 "of the connecting host. If you want them to show the host name you "
1180 "can turn this on, but depending on your host name resolution "
1181 "setup it might impose a non-negligible performance penalty.")
1188 {"sql_inheritance", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1189 gettext_noop("Causes subtables to be included by default in various commands."),
1197 {"password_encryption", PGC_USERSET, CONN_AUTH_SECURITY,
1198 gettext_noop("Encrypt passwords."),
1199 gettext_noop("When a password is specified in CREATE USER or "
1200 "ALTER USER without writing either ENCRYPTED or UNENCRYPTED, "
1201 "this parameter determines whether the password is to be encrypted.")
1203 &Password_encryption,
1208 {"transform_null_equals", PGC_USERSET, COMPAT_OPTIONS_CLIENT,
1209 gettext_noop("Treats \"expr=NULL\" as \"expr IS NULL\"."),
1210 gettext_noop("When turned on, expressions of the form expr = NULL "
1211 "(or NULL = expr) are treated as expr IS NULL, that is, they "
1212 "return true if expr evaluates to the null value, and false "
1213 "otherwise. The correct behavior of expr = NULL is to always "
1214 "return null (unknown).")
1216 &Transform_null_equals,
1221 {"db_user_namespace", PGC_SIGHUP, CONN_AUTH_SECURITY,
1222 gettext_noop("Enables per-database user names."),
1230 /* only here for backwards compatibility */
1231 {"autocommit", PGC_USERSET, CLIENT_CONN_STATEMENT,
1232 gettext_noop("This parameter doesn't do anything."),
1233 gettext_noop("It's just here so that we won't choke on SET AUTOCOMMIT TO ON from 7.3-vintage clients."),
1234 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
1238 check_phony_autocommit, NULL, NULL
1241 {"default_transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
1242 gettext_noop("Sets the default read-only status of new transactions."),
1245 &DefaultXactReadOnly,
1250 {"transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
1251 gettext_noop("Sets the current transaction's read-only status."),
1253 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1257 check_transaction_read_only, NULL, NULL
1260 {"default_transaction_deferrable", PGC_USERSET, CLIENT_CONN_STATEMENT,
1261 gettext_noop("Sets the default deferrable status of new transactions."),
1264 &DefaultXactDeferrable,
1269 {"transaction_deferrable", PGC_USERSET, CLIENT_CONN_STATEMENT,
1270 gettext_noop("Whether to defer a read-only serializable transaction until it can be executed with no possible serialization failures."),
1272 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1276 check_transaction_deferrable, NULL, NULL
1279 {"check_function_bodies", PGC_USERSET, CLIENT_CONN_STATEMENT,
1280 gettext_noop("Check function bodies during CREATE FUNCTION."),
1283 &check_function_bodies,
1288 {"array_nulls", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1289 gettext_noop("Enable input of NULL elements in arrays."),
1290 gettext_noop("When turned on, unquoted NULL in an array input "
1291 "value means a null value; "
1292 "otherwise it is taken literally.")
1299 {"default_with_oids", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1300 gettext_noop("Create new tables with OIDs by default."),
1308 {"logging_collector", PGC_POSTMASTER, LOGGING_WHERE,
1309 gettext_noop("Start a subprocess to capture stderr output and/or csvlogs into log files."),
1317 {"log_truncate_on_rotation", PGC_SIGHUP, LOGGING_WHERE,
1318 gettext_noop("Truncate existing log files of same name during log rotation."),
1321 &Log_truncate_on_rotation,
1328 {"trace_sort", PGC_USERSET, DEVELOPER_OPTIONS,
1329 gettext_noop("Emit information about resource usage in sorting."),
1339 #ifdef TRACE_SYNCSCAN
1340 /* this is undocumented because not exposed in a standard build */
1342 {"trace_syncscan", PGC_USERSET, DEVELOPER_OPTIONS,
1343 gettext_noop("Generate debugging output for synchronized scanning."),
1353 #ifdef DEBUG_BOUNDED_SORT
1354 /* this is undocumented because not exposed in a standard build */
1357 "optimize_bounded_sort", PGC_USERSET, QUERY_TUNING_METHOD,
1358 gettext_noop("Enable bounded sorting using heap sort."),
1362 &optimize_bounded_sort,
1370 {"wal_debug", PGC_SUSET, DEVELOPER_OPTIONS,
1371 gettext_noop("Emit WAL-related debugging output."),
1382 {"integer_datetimes", PGC_INTERNAL, PRESET_OPTIONS,
1383 gettext_noop("Datetimes are integer based."),
1385 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1388 #ifdef HAVE_INT64_TIMESTAMP
1397 {"krb_caseins_users", PGC_SIGHUP, CONN_AUTH_SECURITY,
1398 gettext_noop("Sets whether Kerberos and GSSAPI user names should be treated as case-insensitive."),
1401 &pg_krb_caseins_users,
1407 {"escape_string_warning", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1408 gettext_noop("Warn about backslash escapes in ordinary string literals."),
1411 &escape_string_warning,
1417 {"standard_conforming_strings", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1418 gettext_noop("Causes '...' strings to treat backslashes literally."),
1422 &standard_conforming_strings,
1428 {"synchronize_seqscans", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1429 gettext_noop("Enable synchronized sequential scans."),
1432 &synchronize_seqscans,
1438 {"archive_mode", PGC_POSTMASTER, WAL_ARCHIVING,
1439 gettext_noop("Allows archiving of WAL files using archive_command."),
1448 {"hot_standby", PGC_POSTMASTER, REPLICATION_STANDBY,
1449 gettext_noop("Allows connections and queries during recovery."),
1458 {"hot_standby_feedback", PGC_SIGHUP, REPLICATION_STANDBY,
1459 gettext_noop("Allows feedback from a hot standby to the primary that will avoid query conflicts."),
1462 &hot_standby_feedback,
1468 {"allow_system_table_mods", PGC_POSTMASTER, DEVELOPER_OPTIONS,
1469 gettext_noop("Allows modifications of the structure of system tables."),
1473 &allowSystemTableMods,
1479 {"ignore_system_indexes", PGC_BACKEND, DEVELOPER_OPTIONS,
1480 gettext_noop("Disables reading from system indexes."),
1481 gettext_noop("It does not prevent updating the indexes, so it is safe "
1482 "to use. The worst consequence is slowness."),
1485 &IgnoreSystemIndexes,
1491 {"lo_compat_privileges", PGC_SUSET, COMPAT_OPTIONS_PREVIOUS,
1492 gettext_noop("Enables backward compatibility mode for privilege checks on large objects."),
1493 gettext_noop("Skips privilege checks when reading or modifying large objects, "
1494 "for compatibility with PostgreSQL releases prior to 9.0.")
1496 &lo_compat_privileges,
1502 {"quote_all_identifiers", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1503 gettext_noop("When generating SQL fragments, quote all identifiers."),
1506 "e_all_identifiers,
1512 {"data_checksums", PGC_INTERNAL, PRESET_OPTIONS,
1513 gettext_noop("Shows whether data checksums are turned on for this cluster."),
1515 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1522 /* End-of-list marker */
1524 {NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL, NULL
1529 static struct config_int ConfigureNamesInt[] =
1532 {"archive_timeout", PGC_SIGHUP, WAL_ARCHIVING,
1533 gettext_noop("Forces a switch to the next xlog file if a "
1534 "new file has not been started within N seconds."),
1538 &XLogArchiveTimeout,
1543 {"post_auth_delay", PGC_BACKEND, DEVELOPER_OPTIONS,
1544 gettext_noop("Waits N seconds on connection startup after authentication."),
1545 gettext_noop("This allows attaching a debugger to the process."),
1546 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1549 0, 0, INT_MAX / 1000000,
1553 {"default_statistics_target", PGC_USERSET, QUERY_TUNING_OTHER,
1554 gettext_noop("Sets the default statistics target."),
1555 gettext_noop("This applies to table columns that have not had a "
1556 "column-specific target set via ALTER TABLE SET STATISTICS.")
1558 &default_statistics_target,
1563 {"from_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1564 gettext_noop("Sets the FROM-list size beyond which subqueries "
1565 "are not collapsed."),
1566 gettext_noop("The planner will merge subqueries into upper "
1567 "queries if the resulting FROM list would have no more than "
1570 &from_collapse_limit,
1575 {"join_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1576 gettext_noop("Sets the FROM-list size beyond which JOIN "
1577 "constructs are not flattened."),
1578 gettext_noop("The planner will flatten explicit JOIN "
1579 "constructs into lists of FROM items whenever a "
1580 "list of no more than this many items would result.")
1582 &join_collapse_limit,
1587 {"geqo_threshold", PGC_USERSET, QUERY_TUNING_GEQO,
1588 gettext_noop("Sets the threshold of FROM items beyond which GEQO is used."),
1596 {"geqo_effort", PGC_USERSET, QUERY_TUNING_GEQO,
1597 gettext_noop("GEQO: effort is used to set the default for other GEQO parameters."),
1601 DEFAULT_GEQO_EFFORT, MIN_GEQO_EFFORT, MAX_GEQO_EFFORT,
1605 {"geqo_pool_size", PGC_USERSET, QUERY_TUNING_GEQO,
1606 gettext_noop("GEQO: number of individuals in the population."),
1607 gettext_noop("Zero selects a suitable default value.")
1614 {"geqo_generations", PGC_USERSET, QUERY_TUNING_GEQO,
1615 gettext_noop("GEQO: number of iterations of the algorithm."),
1616 gettext_noop("Zero selects a suitable default value.")
1624 /* This is PGC_SUSET to prevent hiding from log_lock_waits. */
1625 {"deadlock_timeout", PGC_SUSET, LOCK_MANAGEMENT,
1626 gettext_noop("Sets the time to wait on a lock before checking for deadlock."),
1636 {"max_standby_archive_delay", PGC_SIGHUP, REPLICATION_STANDBY,
1637 gettext_noop("Sets the maximum delay before canceling queries when a hot standby server is processing archived WAL data."),
1641 &max_standby_archive_delay,
1642 30 * 1000, -1, INT_MAX,
1647 {"max_standby_streaming_delay", PGC_SIGHUP, REPLICATION_STANDBY,
1648 gettext_noop("Sets the maximum delay before canceling queries when a hot standby server is processing streamed WAL data."),
1652 &max_standby_streaming_delay,
1653 30 * 1000, -1, INT_MAX,
1658 {"wal_receiver_status_interval", PGC_SIGHUP, REPLICATION_STANDBY,
1659 gettext_noop("Sets the maximum interval between WAL receiver status reports to the primary."),
1663 &wal_receiver_status_interval,
1664 10, 0, INT_MAX / 1000,
1669 {"wal_receiver_timeout", PGC_SIGHUP, REPLICATION_STANDBY,
1670 gettext_noop("Sets the maximum wait time to receive data from the primary."),
1674 &wal_receiver_timeout,
1675 60 * 1000, 0, INT_MAX,
1680 {"max_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1681 gettext_noop("Sets the maximum number of concurrent connections."),
1685 100, 1, MAX_BACKENDS,
1686 check_maxconnections, NULL, NULL
1690 {"superuser_reserved_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1691 gettext_noop("Sets the number of connection slots reserved for superusers."),
1700 * We sometimes multiply the number of shared buffers by two without
1701 * checking for overflow, so we mustn't allow more than INT_MAX / 2.
1704 {"shared_buffers", PGC_POSTMASTER, RESOURCES_MEM,
1705 gettext_noop("Sets the number of shared memory buffers used by the server."),
1710 1024, 16, INT_MAX / 2,
1715 {"temp_buffers", PGC_USERSET, RESOURCES_MEM,
1716 gettext_noop("Sets the maximum number of temporary buffers used by each session."),
1721 1024, 100, INT_MAX / 2,
1722 check_temp_buffers, NULL, NULL
1726 {"port", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1727 gettext_noop("Sets the TCP port the server listens on."),
1731 DEF_PGPORT, 1, 65535,
1736 {"unix_socket_permissions", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1737 gettext_noop("Sets the access permissions of the Unix-domain socket."),
1738 gettext_noop("Unix-domain sockets use the usual Unix file system "
1739 "permission set. The parameter value is expected "
1740 "to be a numeric mode specification in the form "
1741 "accepted by the chmod and umask system calls. "
1742 "(To use the customary octal format the number must "
1743 "start with a 0 (zero).)")
1745 &Unix_socket_permissions,
1747 NULL, NULL, show_unix_socket_permissions
1751 {"log_file_mode", PGC_SIGHUP, LOGGING_WHERE,
1752 gettext_noop("Sets the file permissions for log files."),
1753 gettext_noop("The parameter value is expected "
1754 "to be a numeric mode specification in the form "
1755 "accepted by the chmod and umask system calls. "
1756 "(To use the customary octal format the number must "
1757 "start with a 0 (zero).)")
1761 NULL, NULL, show_log_file_mode
1765 {"work_mem", PGC_USERSET, RESOURCES_MEM,
1766 gettext_noop("Sets the maximum memory to be used for query workspaces."),
1767 gettext_noop("This much memory can be used by each internal "
1768 "sort operation and hash table before switching to "
1769 "temporary disk files."),
1773 4096, 64, MAX_KILOBYTES,
1778 {"maintenance_work_mem", PGC_USERSET, RESOURCES_MEM,
1779 gettext_noop("Sets the maximum memory to be used for maintenance operations."),
1780 gettext_noop("This includes operations such as VACUUM and CREATE INDEX."),
1783 &maintenance_work_mem,
1784 65536, 1024, MAX_KILOBYTES,
1789 * We use the hopefully-safely-small value of 100kB as the compiled-in
1790 * default for max_stack_depth. InitializeGUCOptions will increase it if
1791 * possible, depending on the actual platform-specific stack limit.
1794 {"max_stack_depth", PGC_SUSET, RESOURCES_MEM,
1795 gettext_noop("Sets the maximum stack depth, in kilobytes."),
1800 100, 100, MAX_KILOBYTES,
1801 check_max_stack_depth, assign_max_stack_depth, NULL
1805 {"temp_file_limit", PGC_SUSET, RESOURCES_DISK,
1806 gettext_noop("Limits the total size of all temporary files used by each session."),
1807 gettext_noop("-1 means no limit."),
1816 {"vacuum_cost_page_hit", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1817 gettext_noop("Vacuum cost for a page found in the buffer cache."),
1826 {"vacuum_cost_page_miss", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1827 gettext_noop("Vacuum cost for a page not found in the buffer cache."),
1830 &VacuumCostPageMiss,
1836 {"vacuum_cost_page_dirty", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1837 gettext_noop("Vacuum cost for a page dirtied by vacuum."),
1840 &VacuumCostPageDirty,
1846 {"vacuum_cost_limit", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1847 gettext_noop("Vacuum cost amount available before napping."),
1856 {"vacuum_cost_delay", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1857 gettext_noop("Vacuum cost delay in milliseconds."),
1867 {"autovacuum_vacuum_cost_delay", PGC_SIGHUP, AUTOVACUUM,
1868 gettext_noop("Vacuum cost delay in milliseconds, for autovacuum."),
1872 &autovacuum_vac_cost_delay,
1878 {"autovacuum_vacuum_cost_limit", PGC_SIGHUP, AUTOVACUUM,
1879 gettext_noop("Vacuum cost amount available before napping, for autovacuum."),
1882 &autovacuum_vac_cost_limit,
1888 {"max_files_per_process", PGC_POSTMASTER, RESOURCES_KERNEL,
1889 gettext_noop("Sets the maximum number of simultaneously open files for each server process."),
1892 &max_files_per_process,
1898 * See also CheckRequiredParameterValues() if this parameter changes
1901 {"max_prepared_transactions", PGC_POSTMASTER, RESOURCES_MEM,
1902 gettext_noop("Sets the maximum number of simultaneously prepared transactions."),
1905 &max_prepared_xacts,
1912 {"trace_lock_oidmin", PGC_SUSET, DEVELOPER_OPTIONS,
1913 gettext_noop("Sets the minimum OID of tables for tracking locks."),
1914 gettext_noop("Is used to avoid output on system tables."),
1918 FirstNormalObjectId, 0, INT_MAX,
1922 {"trace_lock_table", PGC_SUSET, DEVELOPER_OPTIONS,
1923 gettext_noop("Sets the OID of the table with unconditionally lock tracing."),
1934 {"statement_timeout", PGC_USERSET, CLIENT_CONN_STATEMENT,
1935 gettext_noop("Sets the maximum allowed duration of any statement."),
1936 gettext_noop("A value of 0 turns off the timeout."),
1945 {"lock_timeout", PGC_USERSET, CLIENT_CONN_STATEMENT,
1946 gettext_noop("Sets the maximum allowed duration of any wait for a lock."),
1947 gettext_noop("A value of 0 turns off the timeout."),
1956 {"vacuum_freeze_min_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1957 gettext_noop("Minimum age at which VACUUM should freeze a table row."),
1960 &vacuum_freeze_min_age,
1961 50000000, 0, 1000000000,
1966 {"vacuum_freeze_table_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1967 gettext_noop("Age at which VACUUM should scan whole table to freeze tuples."),
1970 &vacuum_freeze_table_age,
1971 150000000, 0, 2000000000,
1976 {"vacuum_multixact_freeze_min_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1977 gettext_noop("Minimum age at which VACUUM should freeze a MultiXactId in a table row."),
1980 &vacuum_multixact_freeze_min_age,
1981 5000000, 0, 1000000000,
1986 {"vacuum_multixact_freeze_table_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1987 gettext_noop("Multixact age at which VACUUM should scan whole table to freeze tuples."),
1990 &vacuum_multixact_freeze_table_age,
1991 150000000, 0, 2000000000,
1996 {"vacuum_defer_cleanup_age", PGC_SIGHUP, REPLICATION_MASTER,
1997 gettext_noop("Number of transactions by which VACUUM and HOT cleanup should be deferred, if any."),
2000 &vacuum_defer_cleanup_age,
2006 * See also CheckRequiredParameterValues() if this parameter changes
2009 {"max_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
2010 gettext_noop("Sets the maximum number of locks per transaction."),
2011 gettext_noop("The shared lock table is sized on the assumption that "
2012 "at most max_locks_per_transaction * max_connections distinct "
2013 "objects will need to be locked at any one time.")
2015 &max_locks_per_xact,
2021 {"max_pred_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
2022 gettext_noop("Sets the maximum number of predicate locks per transaction."),
2023 gettext_noop("The shared predicate lock table is sized on the assumption that "
2024 "at most max_pred_locks_per_transaction * max_connections distinct "
2025 "objects will need to be locked at any one time.")
2027 &max_predicate_locks_per_xact,
2033 {"authentication_timeout", PGC_SIGHUP, CONN_AUTH_SECURITY,
2034 gettext_noop("Sets the maximum allowed time to complete client authentication."),
2038 &AuthenticationTimeout,
2044 /* Not for general use */
2045 {"pre_auth_delay", PGC_SIGHUP, DEVELOPER_OPTIONS,
2046 gettext_noop("Waits N seconds on connection startup before authentication."),
2047 gettext_noop("This allows attaching a debugger to the process."),
2048 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
2056 {"wal_keep_segments", PGC_SIGHUP, REPLICATION_SENDING,
2057 gettext_noop("Sets the number of WAL files held for standby servers."),
2066 {"checkpoint_segments", PGC_SIGHUP, WAL_CHECKPOINTS,
2067 gettext_noop("Sets the maximum distance in log segments between automatic WAL checkpoints."),
2070 &CheckPointSegments,
2076 {"checkpoint_timeout", PGC_SIGHUP, WAL_CHECKPOINTS,
2077 gettext_noop("Sets the maximum time between automatic WAL checkpoints."),
2087 {"checkpoint_warning", PGC_SIGHUP, WAL_CHECKPOINTS,
2088 gettext_noop("Enables warnings if checkpoint segments are filled more "
2089 "frequently than this."),
2090 gettext_noop("Write a message to the server log if checkpoints "
2091 "caused by the filling of checkpoint segment files happens more "
2092 "frequently than this number of seconds. Zero turns off the warning."),
2101 {"wal_buffers", PGC_POSTMASTER, WAL_SETTINGS,
2102 gettext_noop("Sets the number of disk-page buffers in shared memory for WAL."),
2108 check_wal_buffers, NULL, NULL
2112 {"wal_writer_delay", PGC_SIGHUP, WAL_SETTINGS,
2113 gettext_noop("WAL writer sleep time between WAL flushes."),
2123 {"xloginsert_locks", PGC_POSTMASTER, WAL_SETTINGS,
2124 gettext_noop("Sets the number of locks used for concurrent xlog insertions."),
2128 &num_xloginsert_locks,
2134 /* see max_connections */
2135 {"max_wal_senders", PGC_POSTMASTER, REPLICATION_SENDING,
2136 gettext_noop("Sets the maximum number of simultaneously running WAL sender processes."),
2145 /* see max_connections */
2146 {"max_replication_slots", PGC_POSTMASTER, REPLICATION_SENDING,
2147 gettext_noop("Sets the maximum number of simultaneously defined replication slots."),
2150 &max_replication_slots,
2151 0, 0, MAX_BACKENDS /* XXX?*/,
2156 {"wal_sender_timeout", PGC_SIGHUP, REPLICATION_SENDING,
2157 gettext_noop("Sets the maximum time to wait for WAL replication."),
2161 &wal_sender_timeout,
2162 60 * 1000, 0, INT_MAX,
2167 {"commit_delay", PGC_SUSET, WAL_SETTINGS,
2168 gettext_noop("Sets the delay in microseconds between transaction commit and "
2169 "flushing WAL to disk."),
2171 /* we have no microseconds designation, so can't supply units here */
2179 {"commit_siblings", PGC_USERSET, WAL_SETTINGS,
2180 gettext_noop("Sets the minimum concurrent open transactions before performing "
2190 {"extra_float_digits", PGC_USERSET, CLIENT_CONN_LOCALE,
2191 gettext_noop("Sets the number of digits displayed for floating-point values."),
2192 gettext_noop("This affects real, double precision, and geometric data types. "
2193 "The parameter value is added to the standard number of digits "
2194 "(FLT_DIG or DBL_DIG as appropriate).")
2196 &extra_float_digits,
2202 {"log_min_duration_statement", PGC_SUSET, LOGGING_WHEN,
2203 gettext_noop("Sets the minimum execution time above which "
2204 "statements will be logged."),
2205 gettext_noop("Zero prints all queries. -1 turns this feature off."),
2208 &log_min_duration_statement,
2214 {"log_autovacuum_min_duration", PGC_SIGHUP, LOGGING_WHAT,
2215 gettext_noop("Sets the minimum execution time above which "
2216 "autovacuum actions will be logged."),
2217 gettext_noop("Zero prints all actions. -1 turns autovacuum logging off."),
2220 &Log_autovacuum_min_duration,
2226 {"bgwriter_delay", PGC_SIGHUP, RESOURCES_BGWRITER,
2227 gettext_noop("Background writer sleep time between rounds."),
2237 {"bgwriter_lru_maxpages", PGC_SIGHUP, RESOURCES_BGWRITER,
2238 gettext_noop("Background writer maximum number of LRU pages to flush per round."),
2241 &bgwriter_lru_maxpages,
2247 {"effective_io_concurrency",
2253 RESOURCES_ASYNCHRONOUS,
2254 gettext_noop("Number of simultaneous requests that can be handled efficiently by the disk subsystem."),
2255 gettext_noop("For RAID arrays, this should be approximately the number of drive spindles in the array.")
2257 &effective_io_concurrency,
2263 check_effective_io_concurrency, assign_effective_io_concurrency, NULL
2267 {"max_worker_processes",
2269 RESOURCES_ASYNCHRONOUS,
2270 gettext_noop("Maximum number of concurrent worker processes."),
2273 &max_worker_processes,
2275 check_max_worker_processes, NULL, NULL
2279 {"log_rotation_age", PGC_SIGHUP, LOGGING_WHERE,
2280 gettext_noop("Automatic log file rotation will occur after N minutes."),
2285 HOURS_PER_DAY * MINS_PER_HOUR, 0, INT_MAX / SECS_PER_MINUTE,
2290 {"log_rotation_size", PGC_SIGHUP, LOGGING_WHERE,
2291 gettext_noop("Automatic log file rotation will occur after N kilobytes."),
2296 10 * 1024, 0, INT_MAX / 1024,
2301 {"max_function_args", PGC_INTERNAL, PRESET_OPTIONS,
2302 gettext_noop("Shows the maximum number of function arguments."),
2304 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2307 FUNC_MAX_ARGS, FUNC_MAX_ARGS, FUNC_MAX_ARGS,
2312 {"max_index_keys", PGC_INTERNAL, PRESET_OPTIONS,
2313 gettext_noop("Shows the maximum number of index keys."),
2315 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2318 INDEX_MAX_KEYS, INDEX_MAX_KEYS, INDEX_MAX_KEYS,
2323 {"max_identifier_length", PGC_INTERNAL, PRESET_OPTIONS,
2324 gettext_noop("Shows the maximum identifier length."),
2326 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2328 &max_identifier_length,
2329 NAMEDATALEN - 1, NAMEDATALEN - 1, NAMEDATALEN - 1,
2334 {"block_size", PGC_INTERNAL, PRESET_OPTIONS,
2335 gettext_noop("Shows the size of a disk block."),
2337 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2340 BLCKSZ, BLCKSZ, BLCKSZ,
2345 {"segment_size", PGC_INTERNAL, PRESET_OPTIONS,
2346 gettext_noop("Shows the number of pages per disk file."),
2348 GUC_UNIT_BLOCKS | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2351 RELSEG_SIZE, RELSEG_SIZE, RELSEG_SIZE,
2356 {"wal_block_size", PGC_INTERNAL, PRESET_OPTIONS,
2357 gettext_noop("Shows the block size in the write ahead log."),
2359 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2362 XLOG_BLCKSZ, XLOG_BLCKSZ, XLOG_BLCKSZ,
2367 {"wal_segment_size", PGC_INTERNAL, PRESET_OPTIONS,
2368 gettext_noop("Shows the number of pages per write ahead log segment."),
2370 GUC_UNIT_XBLOCKS | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2373 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
2374 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
2375 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
2380 {"autovacuum_naptime", PGC_SIGHUP, AUTOVACUUM,
2381 gettext_noop("Time to sleep between autovacuum runs."),
2385 &autovacuum_naptime,
2386 60, 1, INT_MAX / 1000,
2390 {"autovacuum_vacuum_threshold", PGC_SIGHUP, AUTOVACUUM,
2391 gettext_noop("Minimum number of tuple updates or deletes prior to vacuum."),
2394 &autovacuum_vac_thresh,
2399 {"autovacuum_analyze_threshold", PGC_SIGHUP, AUTOVACUUM,
2400 gettext_noop("Minimum number of tuple inserts, updates, or deletes prior to analyze."),
2403 &autovacuum_anl_thresh,
2408 /* see varsup.c for why this is PGC_POSTMASTER not PGC_SIGHUP */
2409 {"autovacuum_freeze_max_age", PGC_POSTMASTER, AUTOVACUUM,
2410 gettext_noop("Age at which to autovacuum a table to prevent transaction ID wraparound."),
2413 &autovacuum_freeze_max_age,
2414 /* see pg_resetxlog if you change the upper-limit value */
2415 200000000, 100000000, 2000000000,
2419 /* see varsup.c for why this is PGC_POSTMASTER not PGC_SIGHUP */
2420 {"autovacuum_multixact_freeze_max_age", PGC_POSTMASTER, AUTOVACUUM,
2421 gettext_noop("Multixact age at which to autovacuum a table to prevent multixact wraparound."),
2424 &autovacuum_multixact_freeze_max_age,
2425 400000000, 10000000, 2000000000,
2429 /* see max_connections */
2430 {"autovacuum_max_workers", PGC_POSTMASTER, AUTOVACUUM,
2431 gettext_noop("Sets the maximum number of simultaneously running autovacuum worker processes."),
2434 &autovacuum_max_workers,
2436 check_autovacuum_max_workers, NULL, NULL
2440 {"autovacuum_work_mem", PGC_SIGHUP, RESOURCES_MEM,
2441 gettext_noop("Sets the maximum memory to be used by each autovacuum worker process."),
2445 &autovacuum_work_mem,
2446 -1, -1, MAX_KILOBYTES,
2447 check_autovacuum_work_mem, NULL, NULL
2451 {"tcp_keepalives_idle", PGC_USERSET, CLIENT_CONN_OTHER,
2452 gettext_noop("Time between issuing TCP keepalives."),
2453 gettext_noop("A value of 0 uses the system default."),
2456 &tcp_keepalives_idle,
2458 NULL, assign_tcp_keepalives_idle, show_tcp_keepalives_idle
2462 {"tcp_keepalives_interval", PGC_USERSET, CLIENT_CONN_OTHER,
2463 gettext_noop("Time between TCP keepalive retransmits."),
2464 gettext_noop("A value of 0 uses the system default."),
2467 &tcp_keepalives_interval,
2469 NULL, assign_tcp_keepalives_interval, show_tcp_keepalives_interval
2473 {"ssl_renegotiation_limit", PGC_USERSET, CONN_AUTH_SECURITY,
2474 gettext_noop("Set the amount of traffic to send and receive before renegotiating the encryption keys."),
2478 &ssl_renegotiation_limit,
2479 512 * 1024, 0, MAX_KILOBYTES,
2484 {"tcp_keepalives_count", PGC_USERSET, CLIENT_CONN_OTHER,
2485 gettext_noop("Maximum number of TCP keepalive retransmits."),
2486 gettext_noop("This controls the number of consecutive keepalive retransmits that can be "
2487 "lost before a connection is considered dead. A value of 0 uses the "
2490 &tcp_keepalives_count,
2492 NULL, assign_tcp_keepalives_count, show_tcp_keepalives_count
2496 {"gin_fuzzy_search_limit", PGC_USERSET, CLIENT_CONN_OTHER,
2497 gettext_noop("Sets the maximum allowed result for exact search by GIN."),
2501 &GinFuzzySearchLimit,
2507 {"effective_cache_size", PGC_USERSET, QUERY_TUNING_COST,
2508 gettext_noop("Sets the planner's assumption about the size of the disk cache."),
2509 gettext_noop("That is, the portion of the kernel's disk cache that "
2510 "will be used for PostgreSQL data files. This is measured in disk "
2511 "pages, which are normally 8 kB each."),
2514 &effective_cache_size,
2516 check_effective_cache_size, NULL, NULL
2520 /* Can't be set in postgresql.conf */
2521 {"server_version_num", PGC_INTERNAL, PRESET_OPTIONS,
2522 gettext_noop("Shows the server version as an integer."),
2524 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2526 &server_version_num,
2527 PG_VERSION_NUM, PG_VERSION_NUM, PG_VERSION_NUM,
2532 {"log_temp_files", PGC_SUSET, LOGGING_WHAT,
2533 gettext_noop("Log the use of temporary files larger than this number of kilobytes."),
2534 gettext_noop("Zero logs all files. The default is -1 (turning this feature off)."),
2543 {"track_activity_query_size", PGC_POSTMASTER, RESOURCES_MEM,
2544 gettext_noop("Sets the size reserved for pg_stat_activity.query, in bytes."),
2547 &pgstat_track_activity_query_size,
2552 /* End-of-list marker */
2554 {NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL, NULL
2559 static struct config_real ConfigureNamesReal[] =
2562 {"seq_page_cost", PGC_USERSET, QUERY_TUNING_COST,
2563 gettext_noop("Sets the planner's estimate of the cost of a "
2564 "sequentially fetched disk page."),
2568 DEFAULT_SEQ_PAGE_COST, 0, DBL_MAX,
2572 {"random_page_cost", PGC_USERSET, QUERY_TUNING_COST,
2573 gettext_noop("Sets the planner's estimate of the cost of a "
2574 "nonsequentially fetched disk page."),
2578 DEFAULT_RANDOM_PAGE_COST, 0, DBL_MAX,
2582 {"cpu_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
2583 gettext_noop("Sets the planner's estimate of the cost of "
2584 "processing each tuple (row)."),
2588 DEFAULT_CPU_TUPLE_COST, 0, DBL_MAX,
2592 {"cpu_index_tuple_cost", PGC_USERSET, QUERY_TUNING_COST,
2593 gettext_noop("Sets the planner's estimate of the cost of "
2594 "processing each index entry during an index scan."),
2597 &cpu_index_tuple_cost,
2598 DEFAULT_CPU_INDEX_TUPLE_COST, 0, DBL_MAX,
2602 {"cpu_operator_cost", PGC_USERSET, QUERY_TUNING_COST,
2603 gettext_noop("Sets the planner's estimate of the cost of "
2604 "processing each operator or function call."),
2608 DEFAULT_CPU_OPERATOR_COST, 0, DBL_MAX,
2613 {"cursor_tuple_fraction", PGC_USERSET, QUERY_TUNING_OTHER,
2614 gettext_noop("Sets the planner's estimate of the fraction of "
2615 "a cursor's rows that will be retrieved."),
2618 &cursor_tuple_fraction,
2619 DEFAULT_CURSOR_TUPLE_FRACTION, 0.0, 1.0,
2624 {"geqo_selection_bias", PGC_USERSET, QUERY_TUNING_GEQO,
2625 gettext_noop("GEQO: selective pressure within the population."),
2628 &Geqo_selection_bias,
2629 DEFAULT_GEQO_SELECTION_BIAS,
2630 MIN_GEQO_SELECTION_BIAS, MAX_GEQO_SELECTION_BIAS,
2634 {"geqo_seed", PGC_USERSET, QUERY_TUNING_GEQO,
2635 gettext_noop("GEQO: seed for random path selection."),
2644 {"bgwriter_lru_multiplier", PGC_SIGHUP, RESOURCES_BGWRITER,
2645 gettext_noop("Multiple of the average buffer usage to free per round."),
2648 &bgwriter_lru_multiplier,
2654 {"seed", PGC_USERSET, UNGROUPED,
2655 gettext_noop("Sets the seed for random-number generation."),
2657 GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2661 check_random_seed, assign_random_seed, show_random_seed
2665 {"autovacuum_vacuum_scale_factor", PGC_SIGHUP, AUTOVACUUM,
2666 gettext_noop("Number of tuple updates or deletes prior to vacuum as a fraction of reltuples."),
2669 &autovacuum_vac_scale,
2674 {"autovacuum_analyze_scale_factor", PGC_SIGHUP, AUTOVACUUM,
2675 gettext_noop("Number of tuple inserts, updates, or deletes prior to analyze as a fraction of reltuples."),
2678 &autovacuum_anl_scale,
2684 {"checkpoint_completion_target", PGC_SIGHUP, WAL_CHECKPOINTS,
2685 gettext_noop("Time spent flushing dirty buffers during checkpoint, as fraction of checkpoint interval."),
2688 &CheckPointCompletionTarget,
2693 /* End-of-list marker */
2695 {NULL, 0, 0, NULL, NULL}, NULL, 0.0, 0.0, 0.0, NULL, NULL, NULL
2700 static struct config_string ConfigureNamesString[] =
2703 {"archive_command", PGC_SIGHUP, WAL_ARCHIVING,
2704 gettext_noop("Sets the shell command that will be called to archive a WAL file."),
2707 &XLogArchiveCommand,
2709 NULL, NULL, show_archive_command
2713 {"client_encoding", PGC_USERSET, CLIENT_CONN_LOCALE,
2714 gettext_noop("Sets the client's character set encoding."),
2716 GUC_IS_NAME | GUC_REPORT
2718 &client_encoding_string,
2720 check_client_encoding, assign_client_encoding, NULL
2724 {"log_line_prefix", PGC_SIGHUP, LOGGING_WHAT,
2725 gettext_noop("Controls information prefixed to each log line."),
2726 gettext_noop("If blank, no prefix is used.")
2734 {"log_timezone", PGC_SIGHUP, LOGGING_WHAT,
2735 gettext_noop("Sets the time zone to use in log messages."),
2738 &log_timezone_string,
2740 check_log_timezone, assign_log_timezone, show_log_timezone
2744 {"DateStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
2745 gettext_noop("Sets the display format for date and time values."),
2746 gettext_noop("Also controls interpretation of ambiguous "
2748 GUC_LIST_INPUT | GUC_REPORT
2752 check_datestyle, assign_datestyle, NULL
2756 {"default_tablespace", PGC_USERSET, CLIENT_CONN_STATEMENT,
2757 gettext_noop("Sets the default tablespace to create tables and indexes in."),
2758 gettext_noop("An empty string selects the database's default tablespace."),
2761 &default_tablespace,
2763 check_default_tablespace, NULL, NULL
2767 {"temp_tablespaces", PGC_USERSET, CLIENT_CONN_STATEMENT,
2768 gettext_noop("Sets the tablespace(s) to use for temporary tables and sort files."),
2770 GUC_LIST_INPUT | GUC_LIST_QUOTE
2774 check_temp_tablespaces, assign_temp_tablespaces, NULL
2778 {"dynamic_library_path", PGC_SUSET, CLIENT_CONN_OTHER,
2779 gettext_noop("Sets the path for dynamically loadable modules."),
2780 gettext_noop("If a dynamically loadable module needs to be opened and "
2781 "the specified name does not have a directory component (i.e., the "
2782 "name does not contain a slash), the system will search this path for "
2783 "the specified file."),
2786 &Dynamic_library_path,
2792 {"krb_server_keyfile", PGC_SIGHUP, CONN_AUTH_SECURITY,
2793 gettext_noop("Sets the location of the Kerberos server key file."),
2797 &pg_krb_server_keyfile,
2803 {"bonjour_name", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
2804 gettext_noop("Sets the Bonjour service name."),
2812 /* See main.c about why defaults for LC_foo are not all alike */
2815 {"lc_collate", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2816 gettext_noop("Shows the collation order locale."),
2818 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2826 {"lc_ctype", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2827 gettext_noop("Shows the character classification and case conversion locale."),
2829 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2837 {"lc_messages", PGC_SUSET, CLIENT_CONN_LOCALE,
2838 gettext_noop("Sets the language in which messages are displayed."),
2843 check_locale_messages, assign_locale_messages, NULL
2847 {"lc_monetary", PGC_USERSET, CLIENT_CONN_LOCALE,
2848 gettext_noop("Sets the locale for formatting monetary amounts."),
2853 check_locale_monetary, assign_locale_monetary, NULL
2857 {"lc_numeric", PGC_USERSET, CLIENT_CONN_LOCALE,
2858 gettext_noop("Sets the locale for formatting numbers."),
2863 check_locale_numeric, assign_locale_numeric, NULL
2867 {"lc_time", PGC_USERSET, CLIENT_CONN_LOCALE,
2868 gettext_noop("Sets the locale for formatting date and time values."),
2873 check_locale_time, assign_locale_time, NULL
2877 {"session_preload_libraries", PGC_SUSET, CLIENT_CONN_PRELOAD,
2878 gettext_noop("Lists shared libraries to preload into each backend."),
2880 GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
2882 &session_preload_libraries_string,
2888 {"shared_preload_libraries", PGC_POSTMASTER, CLIENT_CONN_PRELOAD,
2889 gettext_noop("Lists shared libraries to preload into server."),
2891 GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY
2893 &shared_preload_libraries_string,
2899 {"local_preload_libraries", PGC_BACKEND, CLIENT_CONN_PRELOAD,
2900 gettext_noop("Lists unprivileged shared libraries to preload into each backend."),
2902 GUC_LIST_INPUT | GUC_LIST_QUOTE
2904 &local_preload_libraries_string,
2910 {"search_path", PGC_USERSET, CLIENT_CONN_STATEMENT,
2911 gettext_noop("Sets the schema search order for names that are not schema-qualified."),
2913 GUC_LIST_INPUT | GUC_LIST_QUOTE
2915 &namespace_search_path,
2917 check_search_path, assign_search_path, NULL
2921 /* Can't be set in postgresql.conf */
2922 {"server_encoding", PGC_INTERNAL, CLIENT_CONN_LOCALE,
2923 gettext_noop("Sets the server (database) character set encoding."),
2925 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2927 &server_encoding_string,
2933 /* Can't be set in postgresql.conf */
2934 {"server_version", PGC_INTERNAL, PRESET_OPTIONS,
2935 gettext_noop("Shows the server version."),
2937 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2939 &server_version_string,
2945 /* Not for general use --- used by SET ROLE */
2946 {"role", PGC_USERSET, UNGROUPED,
2947 gettext_noop("Sets the current role."),
2949 GUC_IS_NAME | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_NOT_WHILE_SEC_REST
2953 check_role, assign_role, show_role
2957 /* Not for general use --- used by SET SESSION AUTHORIZATION */
2958 {"session_authorization", PGC_USERSET, UNGROUPED,
2959 gettext_noop("Sets the session user name."),
2961 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
2963 &session_authorization_string,
2965 check_session_authorization, assign_session_authorization, NULL
2969 {"log_destination", PGC_SIGHUP, LOGGING_WHERE,
2970 gettext_noop("Sets the destination for server log output."),
2971 gettext_noop("Valid values are combinations of \"stderr\", "
2972 "\"syslog\", \"csvlog\", and \"eventlog\", "
2973 "depending on the platform."),
2976 &Log_destination_string,
2978 check_log_destination, assign_log_destination, NULL
2981 {"log_directory", PGC_SIGHUP, LOGGING_WHERE,
2982 gettext_noop("Sets the destination directory for log files."),
2983 gettext_noop("Can be specified as relative to the data directory "
2984 "or as absolute path."),
2989 check_canonical_path, NULL, NULL
2992 {"log_filename", PGC_SIGHUP, LOGGING_WHERE,
2993 gettext_noop("Sets the file name pattern for log files."),
2998 "postgresql-%Y-%m-%d_%H%M%S.log",
3003 {"syslog_ident", PGC_SIGHUP, LOGGING_WHERE,
3004 gettext_noop("Sets the program name used to identify PostgreSQL "
3005 "messages in syslog."),
3010 NULL, assign_syslog_ident, NULL
3014 {"event_source", PGC_POSTMASTER, LOGGING_WHERE,
3015 gettext_noop("Sets the application name used to identify "
3016 "PostgreSQL messages in the event log."),
3025 {"TimeZone", PGC_USERSET, CLIENT_CONN_LOCALE,
3026 gettext_noop("Sets the time zone for displaying and interpreting time stamps."),
3032 check_timezone, assign_timezone, show_timezone
3035 {"timezone_abbreviations", PGC_USERSET, CLIENT_CONN_LOCALE,
3036 gettext_noop("Selects a file of time zone abbreviations."),
3039 &timezone_abbreviations_string,
3041 check_timezone_abbreviations, assign_timezone_abbreviations, NULL
3045 {"transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
3046 gettext_noop("Sets the current transaction's isolation level."),
3048 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
3050 &XactIsoLevel_string,
3052 check_XactIsoLevel, assign_XactIsoLevel, show_XactIsoLevel
3056 {"unix_socket_group", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
3057 gettext_noop("Sets the owning group of the Unix-domain socket."),
3058 gettext_noop("The owning user of the socket is always the user "
3059 "that starts the server.")
3067 {"unix_socket_directories", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
3068 gettext_noop("Sets the directories where Unix-domain sockets will be created."),
3072 &Unix_socket_directories,
3073 #ifdef HAVE_UNIX_SOCKETS
3074 DEFAULT_PGSOCKET_DIR,
3082 {"listen_addresses", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
3083 gettext_noop("Sets the host name or IP address(es) to listen to."),
3093 {"data_directory", PGC_POSTMASTER, FILE_LOCATIONS,
3094 gettext_noop("Sets the server's data directory."),
3104 {"config_file", PGC_POSTMASTER, FILE_LOCATIONS,
3105 gettext_noop("Sets the server's main configuration file."),
3107 GUC_DISALLOW_IN_FILE | GUC_SUPERUSER_ONLY
3115 {"hba_file", PGC_POSTMASTER, FILE_LOCATIONS,
3116 gettext_noop("Sets the server's \"hba\" configuration file."),
3126 {"ident_file", PGC_POSTMASTER, FILE_LOCATIONS,
3127 gettext_noop("Sets the server's \"ident\" configuration file."),
3137 {"external_pid_file", PGC_POSTMASTER, FILE_LOCATIONS,
3138 gettext_noop("Writes the postmaster PID to the specified file."),
3144 check_canonical_path, NULL, NULL
3148 {"ssl_cert_file", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3149 gettext_noop("Location of the SSL server certificate file."),
3158 {"ssl_key_file", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3159 gettext_noop("Location of the SSL server private key file."),
3168 {"ssl_ca_file", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3169 gettext_noop("Location of the SSL certificate authority file."),
3178 {"ssl_crl_file", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3179 gettext_noop("Location of the SSL certificate revocation list file."),
3188 {"stats_temp_directory", PGC_SIGHUP, STATS_COLLECTOR,
3189 gettext_noop("Writes temporary statistics files to the specified directory."),
3193 &pgstat_temp_directory,
3195 check_canonical_path, assign_pgstat_temp_directory, NULL
3199 {"synchronous_standby_names", PGC_SIGHUP, REPLICATION_MASTER,
3200 gettext_noop("List of names of potential synchronous standbys."),
3204 &SyncRepStandbyNames,
3206 check_synchronous_standby_names, NULL, NULL
3210 {"default_text_search_config", PGC_USERSET, CLIENT_CONN_LOCALE,
3211 gettext_noop("Sets default text search configuration."),
3215 "pg_catalog.simple",
3216 check_TSCurrentConfig, assign_TSCurrentConfig, NULL
3220 {"ssl_ciphers", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3221 gettext_noop("Sets the list of allowed SSL ciphers."),
3227 "HIGH:MEDIUM:+3DES:!aNULL",
3235 {"ssl_ecdh_curve", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3236 gettext_noop("Sets the curve to use for ECDH."),
3250 {"application_name", PGC_USERSET, LOGGING_WHAT,
3251 gettext_noop("Sets the application name to be reported in statistics and logs."),
3253 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE
3257 check_application_name, assign_application_name, NULL
3260 /* End-of-list marker */
3262 {NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL, NULL
3267 static struct config_enum ConfigureNamesEnum[] =
3270 {"backslash_quote", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
3271 gettext_noop("Sets whether \"\\'\" is allowed in string literals."),
3275 BACKSLASH_QUOTE_SAFE_ENCODING, backslash_quote_options,
3280 {"bytea_output", PGC_USERSET, CLIENT_CONN_STATEMENT,
3281 gettext_noop("Sets the output format for bytea."),
3285 BYTEA_OUTPUT_HEX, bytea_output_options,
3290 {"client_min_messages", PGC_USERSET, LOGGING_WHEN,
3291 gettext_noop("Sets the message levels that are sent to the client."),
3292 gettext_noop("Each level includes all the levels that follow it. The later"
3293 " the level, the fewer messages are sent.")
3295 &client_min_messages,
3296 NOTICE, client_message_level_options,
3301 {"constraint_exclusion", PGC_USERSET, QUERY_TUNING_OTHER,
3302 gettext_noop("Enables the planner to use constraints to optimize queries."),
3303 gettext_noop("Table scans will be skipped if their constraints"
3304 " guarantee that no rows match the query.")
3306 &constraint_exclusion,
3307 CONSTRAINT_EXCLUSION_PARTITION, constraint_exclusion_options,
3312 {"default_transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
3313 gettext_noop("Sets the transaction isolation level of each new transaction."),
3316 &DefaultXactIsoLevel,
3317 XACT_READ_COMMITTED, isolation_level_options,
3322 {"IntervalStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
3323 gettext_noop("Sets the display format for interval values."),
3328 INTSTYLE_POSTGRES, intervalstyle_options,
3333 {"log_error_verbosity", PGC_SUSET, LOGGING_WHAT,
3334 gettext_noop("Sets the verbosity of logged messages."),
3337 &Log_error_verbosity,
3338 PGERROR_DEFAULT, log_error_verbosity_options,
3343 {"log_min_messages", PGC_SUSET, LOGGING_WHEN,
3344 gettext_noop("Sets the message levels that are logged."),
3345 gettext_noop("Each level includes all the levels that follow it. The later"
3346 " the level, the fewer messages are sent.")
3349 WARNING, server_message_level_options,
3354 {"log_min_error_statement", PGC_SUSET, LOGGING_WHEN,
3355 gettext_noop("Causes all statements generating error at or above this level to be logged."),
3356 gettext_noop("Each level includes all the levels that follow it. The later"
3357 " the level, the fewer messages are sent.")
3359 &log_min_error_statement,
3360 ERROR, server_message_level_options,
3365 {"log_statement", PGC_SUSET, LOGGING_WHAT,
3366 gettext_noop("Sets the type of statements logged."),
3370 LOGSTMT_NONE, log_statement_options,
3375 {"syslog_facility", PGC_SIGHUP, LOGGING_WHERE,
3376 gettext_noop("Sets the syslog \"facility\" to be used when syslog enabled."),
3385 syslog_facility_options,
3386 NULL, assign_syslog_facility, NULL
3390 {"session_replication_role", PGC_SUSET, CLIENT_CONN_STATEMENT,
3391 gettext_noop("Sets the session's behavior for triggers and rewrite rules."),
3394 &SessionReplicationRole,
3395 SESSION_REPLICATION_ROLE_ORIGIN, session_replication_role_options,
3396 NULL, assign_session_replication_role, NULL
3400 {"synchronous_commit", PGC_USERSET, WAL_SETTINGS,
3401 gettext_noop("Sets the current transaction's synchronization level."),
3404 &synchronous_commit,
3405 SYNCHRONOUS_COMMIT_ON, synchronous_commit_options,
3406 NULL, assign_synchronous_commit, NULL
3410 {"trace_recovery_messages", PGC_SIGHUP, DEVELOPER_OPTIONS,
3411 gettext_noop("Enables logging of recovery-related debugging information."),
3412 gettext_noop("Each level includes all the levels that follow it. The later"
3413 " the level, the fewer messages are sent.")
3415 &trace_recovery_messages,
3418 * client_message_level_options allows too many values, really, but
3419 * it's not worth having a separate options array for this.
3421 LOG, client_message_level_options,
3426 {"track_functions", PGC_SUSET, STATS_COLLECTOR,
3427 gettext_noop("Collects function-level statistics on database activity."),
3430 &pgstat_track_functions,
3431 TRACK_FUNC_OFF, track_function_options,
3436 {"wal_level", PGC_POSTMASTER, WAL_SETTINGS,
3437 gettext_noop("Set the level of information written to the WAL."),
3441 WAL_LEVEL_MINIMAL, wal_level_options,
3446 {"dynamic_shared_memory_type", PGC_POSTMASTER, RESOURCES_MEM,
3447 gettext_noop("Selects the dynamic shared memory implementation used."),
3450 &dynamic_shared_memory_type,
3451 DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE, dynamic_shared_memory_options,
3456 {"wal_sync_method", PGC_SIGHUP, WAL_SETTINGS,
3457 gettext_noop("Selects the method used for forcing WAL updates to disk."),
3461 DEFAULT_SYNC_METHOD, sync_method_options,
3462 NULL, assign_xlog_sync_method, NULL
3466 {"xmlbinary", PGC_USERSET, CLIENT_CONN_STATEMENT,
3467 gettext_noop("Sets how binary values are to be encoded in XML."),
3471 XMLBINARY_BASE64, xmlbinary_options,
3476 {"xmloption", PGC_USERSET, CLIENT_CONN_STATEMENT,
3477 gettext_noop("Sets whether XML data in implicit parsing and serialization "
3478 "operations is to be considered as documents or content fragments."),
3482 XMLOPTION_CONTENT, xmloption_options,
3487 {"huge_pages", PGC_POSTMASTER, RESOURCES_MEM,
3488 gettext_noop("Use of huge pages on Linux"),
3492 HUGE_PAGES_TRY, huge_pages_options,
3496 /* End-of-list marker */
3498 {NULL, 0, 0, NULL, NULL}, NULL, 0, NULL, NULL, NULL, NULL
3502 /******** end of options list ********/
3506 * To allow continued support of obsolete names for GUC variables, we apply
3507 * the following mappings to any unrecognized name. Note that an old name
3508 * should be mapped to a new one only if the new variable has very similar
3509 * semantics to the old.
3511 static const char *const map_old_guc_names[] = {
3512 "sort_mem", "work_mem",
3513 "vacuum_mem", "maintenance_work_mem",
3519 * Actual lookup of variables is done through this single, sorted array.
3521 static struct config_generic **guc_variables;
3523 /* Current number of variables contained in the vector */
3524 static int num_guc_variables;
3526 /* Vector capacity */
3527 static int size_guc_variables;
3530 static bool guc_dirty; /* TRUE if need to do commit/abort work */
3532 static bool reporting_enabled; /* TRUE to enable GUC_REPORT */
3534 static int GUCNestLevel = 0; /* 1 when in main transaction */
3537 static int guc_var_compare(const void *a, const void *b);
3538 static int guc_name_compare(const char *namea, const char *nameb);
3539 static void InitializeGUCOptionsFromEnvironment(void);
3540 static void InitializeOneGUCOption(struct config_generic * gconf);
3541 static void push_old_value(struct config_generic * gconf, GucAction action);
3542 static void ReportGUCOption(struct config_generic * record);
3543 static void reapply_stacked_values(struct config_generic * variable,
3544 struct config_string * pHolder,
3546 const char *curvalue,
3547 GucContext curscontext, GucSource cursource);
3548 static void ShowGUCConfigOption(const char *name, DestReceiver *dest);
3549 static void ShowAllGUCConfig(DestReceiver *dest);
3550 static char *_ShowOption(struct config_generic * record, bool use_units);
3551 static bool validate_option_array_item(const char *name, const char *value,
3552 bool skipIfNoPermissions);
3553 static void write_auto_conf_file(int fd, const char *filename, ConfigVariable **head_p);
3554 static void replace_auto_config_value(ConfigVariable **head_p, ConfigVariable **tail_p,
3555 char *config_file, char *name, char *value);
3559 * Some infrastructure for checking malloc/strdup/realloc calls
3562 guc_malloc(int elevel, size_t size)
3566 /* Avoid unportable behavior of malloc(0) */
3569 data = malloc(size);
3572 (errcode(ERRCODE_OUT_OF_MEMORY),
3573 errmsg("out of memory")));
3578 guc_realloc(int elevel, void *old, size_t size)
3582 /* Avoid unportable behavior of realloc(NULL, 0) */
3583 if (old == NULL && size == 0)
3585 data = realloc(old, size);
3588 (errcode(ERRCODE_OUT_OF_MEMORY),
3589 errmsg("out of memory")));
3594 guc_strdup(int elevel, const char *src)
3601 (errcode(ERRCODE_OUT_OF_MEMORY),
3602 errmsg("out of memory")));
3608 * Detect whether strval is referenced anywhere in a GUC string item
3611 string_field_used(struct config_string * conf, char *strval)
3615 if (strval == *(conf->variable) ||
3616 strval == conf->reset_val ||
3617 strval == conf->boot_val)
3619 for (stack = conf->gen.stack; stack; stack = stack->prev)
3621 if (strval == stack->prior.val.stringval ||
3622 strval == stack->masked.val.stringval)
3629 * Support for assigning to a field of a string GUC item. Free the prior
3630 * value if it's not referenced anywhere else in the item (including stacked
3634 set_string_field(struct config_string * conf, char **field, char *newval)
3636 char *oldval = *field;
3638 /* Do the assignment */
3641 /* Free old value if it's not NULL and isn't referenced anymore */
3642 if (oldval && !string_field_used(conf, oldval))
3647 * Detect whether an "extra" struct is referenced anywhere in a GUC item
3650 extra_field_used(struct config_generic * gconf, void *extra)
3654 if (extra == gconf->extra)
3656 switch (gconf->vartype)
3659 if (extra == ((struct config_bool *) gconf)->reset_extra)
3663 if (extra == ((struct config_int *) gconf)->reset_extra)
3667 if (extra == ((struct config_real *) gconf)->reset_extra)
3671 if (extra == ((struct config_string *) gconf)->reset_extra)
3675 if (extra == ((struct config_enum *) gconf)->reset_extra)
3679 for (stack = gconf->stack; stack; stack = stack->prev)
3681 if (extra == stack->prior.extra ||
3682 extra == stack->masked.extra)
3690 * Support for assigning to an "extra" field of a GUC item. Free the prior
3691 * value if it's not referenced anywhere else in the item (including stacked
3695 set_extra_field(struct config_generic * gconf, void **field, void *newval)
3697 void *oldval = *field;
3699 /* Do the assignment */
3702 /* Free old value if it's not NULL and isn't referenced anymore */
3703 if (oldval && !extra_field_used(gconf, oldval))
3708 * Support for copying a variable's active value into a stack entry.
3709 * The "extra" field associated with the active value is copied, too.
3711 * NB: be sure stringval and extra fields of a new stack entry are
3712 * initialized to NULL before this is used, else we'll try to free() them.
3715 set_stack_value(struct config_generic * gconf, config_var_value *val)
3717 switch (gconf->vartype)
3721 *((struct config_bool *) gconf)->variable;
3725 *((struct config_int *) gconf)->variable;
3729 *((struct config_real *) gconf)->variable;
3732 set_string_field((struct config_string *) gconf,
3733 &(val->val.stringval),
3734 *((struct config_string *) gconf)->variable);
3738 *((struct config_enum *) gconf)->variable;
3741 set_extra_field(gconf, &(val->extra), gconf->extra);
3745 * Support for discarding a no-longer-needed value in a stack entry.
3746 * The "extra" field associated with the stack entry is cleared, too.
3749 discard_stack_value(struct config_generic * gconf, config_var_value *val)
3751 switch (gconf->vartype)
3757 /* no need to do anything */
3760 set_string_field((struct config_string *) gconf,
3761 &(val->val.stringval),
3765 set_extra_field(gconf, &(val->extra), NULL);
3770 * Fetch the sorted array pointer (exported for help_config.c's use ONLY)
3772 struct config_generic **
3773 get_guc_variables(void)
3775 return guc_variables;
3780 * Build the sorted array. This is split out so that it could be
3781 * re-executed after startup (eg, we could allow loadable modules to
3782 * add vars, and then we'd need to re-sort).
3785 build_guc_variables(void)
3789 struct config_generic **guc_vars;
3792 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
3794 struct config_bool *conf = &ConfigureNamesBool[i];
3796 /* Rather than requiring vartype to be filled in by hand, do this: */
3797 conf->gen.vartype = PGC_BOOL;
3801 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
3803 struct config_int *conf = &ConfigureNamesInt[i];
3805 conf->gen.vartype = PGC_INT;
3809 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
3811 struct config_real *conf = &ConfigureNamesReal[i];
3813 conf->gen.vartype = PGC_REAL;
3817 for (i = 0; ConfigureNamesString[i].gen.name; i++)
3819 struct config_string *conf = &ConfigureNamesString[i];
3821 conf->gen.vartype = PGC_STRING;
3825 for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
3827 struct config_enum *conf = &ConfigureNamesEnum[i];
3829 conf->gen.vartype = PGC_ENUM;
3834 * Create table with 20% slack
3836 size_vars = num_vars + num_vars / 4;
3838 guc_vars = (struct config_generic **)
3839 guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
3843 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
3844 guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
3846 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
3847 guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
3849 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
3850 guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
3852 for (i = 0; ConfigureNamesString[i].gen.name; i++)
3853 guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
3855 for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
3856 guc_vars[num_vars++] = &ConfigureNamesEnum[i].gen;
3859 free(guc_variables);
3860 guc_variables = guc_vars;
3861 num_guc_variables = num_vars;
3862 size_guc_variables = size_vars;
3863 qsort((void *) guc_variables, num_guc_variables,
3864 sizeof(struct config_generic *), guc_var_compare);
3868 * Add a new GUC variable to the list of known variables. The
3869 * list is expanded if needed.
3872 add_guc_variable(struct config_generic * var, int elevel)
3874 if (num_guc_variables + 1 >= size_guc_variables)
3877 * Increase the vector by 25%
3879 int size_vars = size_guc_variables + size_guc_variables / 4;
3880 struct config_generic **guc_vars;
3885 guc_vars = (struct config_generic **)
3886 guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
3890 guc_vars = (struct config_generic **)
3891 guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
3894 if (guc_vars == NULL)
3895 return false; /* out of memory */
3897 guc_variables = guc_vars;
3898 size_guc_variables = size_vars;
3900 guc_variables[num_guc_variables++] = var;
3901 qsort((void *) guc_variables, num_guc_variables,
3902 sizeof(struct config_generic *), guc_var_compare);
3907 * Create and add a placeholder variable for a custom variable name.
3909 static struct config_generic *
3910 add_placeholder_variable(const char *name, int elevel)
3912 size_t sz = sizeof(struct config_string) + sizeof(char *);
3913 struct config_string *var;
3914 struct config_generic *gen;
3916 var = (struct config_string *) guc_malloc(elevel, sz);
3922 gen->name = guc_strdup(elevel, name);
3923 if (gen->name == NULL)
3929 gen->context = PGC_USERSET;
3930 gen->group = CUSTOM_OPTIONS;
3931 gen->short_desc = "GUC placeholder variable";
3932 gen->flags = GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_CUSTOM_PLACEHOLDER;
3933 gen->vartype = PGC_STRING;
3936 * The char* is allocated at the end of the struct since we have no
3937 * 'static' place to point to. Note that the current value, as well as
3938 * the boot and reset values, start out NULL.
3940 var->variable = (char **) (var + 1);
3942 if (!add_guc_variable((struct config_generic *) var, elevel))
3944 free((void *) gen->name);
3953 * Look up option NAME. If it exists, return a pointer to its record,
3954 * else return NULL. If create_placeholders is TRUE, we'll create a
3955 * placeholder record for a valid-looking custom variable name.
3957 static struct config_generic *
3958 find_option(const char *name, bool create_placeholders, int elevel)
3960 const char **key = &name;
3961 struct config_generic **res;
3967 * By equating const char ** with struct config_generic *, we are assuming
3968 * the name field is first in config_generic.
3970 res = (struct config_generic **) bsearch((void *) &key,
3971 (void *) guc_variables,
3973 sizeof(struct config_generic *),
3979 * See if the name is an obsolete name for a variable. We assume that the
3980 * set of supported old names is short enough that a brute-force search is
3983 for (i = 0; map_old_guc_names[i] != NULL; i += 2)
3985 if (guc_name_compare(name, map_old_guc_names[i]) == 0)
3986 return find_option(map_old_guc_names[i + 1], false, elevel);
3989 if (create_placeholders)
3992 * Check if the name is qualified, and if so, add a placeholder.
3994 if (strchr(name, GUC_QUALIFIER_SEPARATOR) != NULL)
3995 return add_placeholder_variable(name, elevel);
4004 * comparator for qsorting and bsearching guc_variables array
4007 guc_var_compare(const void *a, const void *b)
4009 const struct config_generic *confa = *(struct config_generic * const *) a;
4010 const struct config_generic *confb = *(struct config_generic * const *) b;
4012 return guc_name_compare(confa->name, confb->name);
4016 * the bare comparison function for GUC names
4019 guc_name_compare(const char *namea, const char *nameb)
4022 * The temptation to use strcasecmp() here must be resisted, because the
4023 * array ordering has to remain stable across setlocale() calls. So, build
4024 * our own with a simple ASCII-only downcasing.
4026 while (*namea && *nameb)
4028 char cha = *namea++;
4029 char chb = *nameb++;
4031 if (cha >= 'A' && cha <= 'Z')
4033 if (chb >= 'A' && chb <= 'Z')
4039 return 1; /* a is longer */
4041 return -1; /* b is longer */
4047 * Initialize GUC options during program startup.
4049 * Note that we cannot read the config file yet, since we have not yet
4050 * processed command-line switches.
4053 InitializeGUCOptions(void)
4058 * Before log_line_prefix could possibly receive a nonempty setting, make
4059 * sure that timezone processing is minimally alive (see elog.c).
4061 pg_timezone_initialize();
4064 * Build sorted array of all GUC variables.
4066 build_guc_variables();
4069 * Load all variables with their compiled-in defaults, and initialize
4070 * status fields as needed.
4072 for (i = 0; i < num_guc_variables; i++)
4074 InitializeOneGUCOption(guc_variables[i]);
4079 reporting_enabled = false;
4082 * Prevent any attempt to override the transaction modes from
4083 * non-interactive sources.
4085 SetConfigOption("transaction_isolation", "default",
4086 PGC_POSTMASTER, PGC_S_OVERRIDE);
4087 SetConfigOption("transaction_read_only", "no",
4088 PGC_POSTMASTER, PGC_S_OVERRIDE);
4089 SetConfigOption("transaction_deferrable", "no",
4090 PGC_POSTMASTER, PGC_S_OVERRIDE);
4093 * For historical reasons, some GUC parameters can receive defaults from
4094 * environment variables. Process those settings.
4096 InitializeGUCOptionsFromEnvironment();
4100 * Assign any GUC values that can come from the server's environment.
4102 * This is called from InitializeGUCOptions, and also from ProcessConfigFile
4103 * to deal with the possibility that a setting has been removed from
4104 * postgresql.conf and should now get a value from the environment.
4105 * (The latter is a kludge that should probably go away someday; if so,
4106 * fold this back into InitializeGUCOptions.)
4109 InitializeGUCOptionsFromEnvironment(void)
4114 env = getenv("PGPORT");
4116 SetConfigOption("port", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
4118 env = getenv("PGDATESTYLE");
4120 SetConfigOption("datestyle", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
4122 env = getenv("PGCLIENTENCODING");
4124 SetConfigOption("client_encoding", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
4127 * rlimit isn't exactly an "environment variable", but it behaves about
4128 * the same. If we can identify the platform stack depth rlimit, increase
4129 * default stack depth setting up to whatever is safe (but at most 2MB).
4131 stack_rlimit = get_stack_depth_rlimit();
4132 if (stack_rlimit > 0)
4134 long new_limit = (stack_rlimit - STACK_DEPTH_SLOP) / 1024L;
4136 if (new_limit > 100)
4140 new_limit = Min(new_limit, 2048);
4141 sprintf(limbuf, "%ld", new_limit);
4142 SetConfigOption("max_stack_depth", limbuf,
4143 PGC_POSTMASTER, PGC_S_ENV_VAR);
4149 * Initialize one GUC option variable to its compiled-in default.
4151 * Note: the reason for calling check_hooks is not that we think the boot_val
4152 * might fail, but that the hooks might wish to compute an "extra" struct.
4155 InitializeOneGUCOption(struct config_generic * gconf)
4158 gconf->source = PGC_S_DEFAULT;
4159 gconf->reset_source = PGC_S_DEFAULT;
4160 gconf->scontext = PGC_INTERNAL;
4161 gconf->reset_scontext = PGC_INTERNAL;
4162 gconf->stack = NULL;
4163 gconf->extra = NULL;
4164 gconf->sourcefile = NULL;
4165 gconf->sourceline = 0;
4167 switch (gconf->vartype)
4171 struct config_bool *conf = (struct config_bool *) gconf;
4172 bool newval = conf->boot_val;
4175 if (!call_bool_check_hook(conf, &newval, &extra,
4176 PGC_S_DEFAULT, LOG))
4177 elog(FATAL, "failed to initialize %s to %d",
4178 conf->gen.name, (int) newval);
4179 if (conf->assign_hook)
4180 (*conf->assign_hook) (newval, extra);
4181 *conf->variable = conf->reset_val = newval;
4182 conf->gen.extra = conf->reset_extra = extra;
4187 struct config_int *conf = (struct config_int *) gconf;
4188 int newval = conf->boot_val;
4191 Assert(newval >= conf->min);
4192 Assert(newval <= conf->max);
4193 if (!call_int_check_hook(conf, &newval, &extra,
4194 PGC_S_DEFAULT, LOG))
4195 elog(FATAL, "failed to initialize %s to %d",
4196 conf->gen.name, newval);
4197 if (conf->assign_hook)
4198 (*conf->assign_hook) (newval, extra);
4199 *conf->variable = conf->reset_val = newval;
4200 conf->gen.extra = conf->reset_extra = extra;
4205 struct config_real *conf = (struct config_real *) gconf;
4206 double newval = conf->boot_val;
4209 Assert(newval >= conf->min);
4210 Assert(newval <= conf->max);
4211 if (!call_real_check_hook(conf, &newval, &extra,
4212 PGC_S_DEFAULT, LOG))
4213 elog(FATAL, "failed to initialize %s to %g",
4214 conf->gen.name, newval);
4215 if (conf->assign_hook)
4216 (*conf->assign_hook) (newval, extra);
4217 *conf->variable = conf->reset_val = newval;
4218 conf->gen.extra = conf->reset_extra = extra;
4223 struct config_string *conf = (struct config_string *) gconf;
4227 /* non-NULL boot_val must always get strdup'd */
4228 if (conf->boot_val != NULL)
4229 newval = guc_strdup(FATAL, conf->boot_val);
4233 if (!call_string_check_hook(conf, &newval, &extra,
4234 PGC_S_DEFAULT, LOG))
4235 elog(FATAL, "failed to initialize %s to \"%s\"",
4236 conf->gen.name, newval ? newval : "");
4237 if (conf->assign_hook)
4238 (*conf->assign_hook) (newval, extra);
4239 *conf->variable = conf->reset_val = newval;
4240 conf->gen.extra = conf->reset_extra = extra;
4245 struct config_enum *conf = (struct config_enum *) gconf;
4246 int newval = conf->boot_val;
4249 if (!call_enum_check_hook(conf, &newval, &extra,
4250 PGC_S_DEFAULT, LOG))
4251 elog(FATAL, "failed to initialize %s to %d",
4252 conf->gen.name, newval);
4253 if (conf->assign_hook)
4254 (*conf->assign_hook) (newval, extra);
4255 *conf->variable = conf->reset_val = newval;
4256 conf->gen.extra = conf->reset_extra = extra;
4264 * Select the configuration files and data directory to be used, and
4265 * do the initial read of postgresql.conf.
4267 * This is called after processing command-line switches.
4268 * userDoption is the -D switch value if any (NULL if unspecified).
4269 * progname is just for use in error messages.
4271 * Returns true on success; on failure, prints a suitable error message
4272 * to stderr and returns false.
4275 SelectConfigFiles(const char *userDoption, const char *progname)
4279 struct stat stat_buf;
4281 /* configdir is -D option, or $PGDATA if no -D */
4283 configdir = make_absolute_path(userDoption);
4285 configdir = make_absolute_path(getenv("PGDATA"));
4288 * Find the configuration file: if config_file was specified on the
4289 * command line, use it, else use configdir/postgresql.conf. In any case
4290 * ensure the result is an absolute path, so that it will be interpreted
4291 * the same way by future backends.
4294 fname = make_absolute_path(ConfigFileName);
4297 fname = guc_malloc(FATAL,
4298 strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
4299 sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
4303 write_stderr("%s does not know where to find the server configuration file.\n"
4304 "You must specify the --config-file or -D invocation "
4305 "option or set the PGDATA environment variable.\n",
4311 * Set the ConfigFileName GUC variable to its final value, ensuring that
4312 * it can't be overridden later.
4314 SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4318 * Now read the config file for the first time.
4320 if (stat(ConfigFileName, &stat_buf) != 0)
4322 write_stderr("%s cannot access the server configuration file \"%s\": %s\n",
4323 progname, ConfigFileName, strerror(errno));
4328 ProcessConfigFile(PGC_POSTMASTER);
4331 * If the data_directory GUC variable has been set, use that as DataDir;
4332 * otherwise use configdir if set; else punt.
4334 * Note: SetDataDir will copy and absolute-ize its argument, so we don't
4338 SetDataDir(data_directory);
4340 SetDataDir(configdir);
4343 write_stderr("%s does not know where to find the database system data.\n"
4344 "This can be specified as \"data_directory\" in \"%s\", "
4345 "or by the -D invocation option, or by the "
4346 "PGDATA environment variable.\n",
4347 progname, ConfigFileName);
4352 * Reflect the final DataDir value back into the data_directory GUC var.
4353 * (If you are wondering why we don't just make them a single variable,
4354 * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
4355 * child backends specially. XXX is that still true? Given that we now
4356 * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
4357 * DataDir in advance.)
4359 SetConfigOption("data_directory", DataDir, PGC_POSTMASTER, PGC_S_OVERRIDE);
4362 * If timezone_abbreviations wasn't set in the configuration file, install
4363 * the default value. We do it this way because we can't safely install a
4364 * "real" value until my_exec_path is set, which may not have happened
4365 * when InitializeGUCOptions runs, so the bootstrap default value cannot
4366 * be the real desired default.
4368 pg_timezone_abbrev_initialize();
4370 /* Also install the correct value for effective_cache_size */
4371 set_default_effective_cache_size();
4374 * Figure out where pg_hba.conf is, and make sure the path is absolute.
4377 fname = make_absolute_path(HbaFileName);
4380 fname = guc_malloc(FATAL,
4381 strlen(configdir) + strlen(HBA_FILENAME) + 2);
4382 sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
4386 write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
4387 "This can be specified as \"hba_file\" in \"%s\", "
4388 "or by the -D invocation option, or by the "
4389 "PGDATA environment variable.\n",
4390 progname, ConfigFileName);
4393 SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4397 * Likewise for pg_ident.conf.
4400 fname = make_absolute_path(IdentFileName);
4403 fname = guc_malloc(FATAL,
4404 strlen(configdir) + strlen(IDENT_FILENAME) + 2);
4405 sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
4409 write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
4410 "This can be specified as \"ident_file\" in \"%s\", "
4411 "or by the -D invocation option, or by the "
4412 "PGDATA environment variable.\n",
4413 progname, ConfigFileName);
4416 SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4426 * Reset all options to their saved default values (implements RESET ALL)
4429 ResetAllOptions(void)
4433 for (i = 0; i < num_guc_variables; i++)
4435 struct config_generic *gconf = guc_variables[i];
4437 /* Don't reset non-SET-able values */
4438 if (gconf->context != PGC_SUSET &&
4439 gconf->context != PGC_USERSET)
4441 /* Don't reset if special exclusion from RESET ALL */
4442 if (gconf->flags & GUC_NO_RESET_ALL)
4444 /* No need to reset if wasn't SET */
4445 if (gconf->source <= PGC_S_OVERRIDE)
4448 /* Save old value to support transaction abort */
4449 push_old_value(gconf, GUC_ACTION_SET);
4451 switch (gconf->vartype)
4455 struct config_bool *conf = (struct config_bool *) gconf;
4457 if (conf->assign_hook)
4458 (*conf->assign_hook) (conf->reset_val,
4460 *conf->variable = conf->reset_val;
4461 set_extra_field(&conf->gen, &conf->gen.extra,
4467 struct config_int *conf = (struct config_int *) gconf;
4469 if (conf->assign_hook)
4470 (*conf->assign_hook) (conf->reset_val,
4472 *conf->variable = conf->reset_val;
4473 set_extra_field(&conf->gen, &conf->gen.extra,
4479 struct config_real *conf = (struct config_real *) gconf;
4481 if (conf->assign_hook)
4482 (*conf->assign_hook) (conf->reset_val,
4484 *conf->variable = conf->reset_val;
4485 set_extra_field(&conf->gen, &conf->gen.extra,
4491 struct config_string *conf = (struct config_string *) gconf;
4493 if (conf->assign_hook)
4494 (*conf->assign_hook) (conf->reset_val,
4496 set_string_field(conf, conf->variable, conf->reset_val);
4497 set_extra_field(&conf->gen, &conf->gen.extra,
4503 struct config_enum *conf = (struct config_enum *) gconf;
4505 if (conf->assign_hook)
4506 (*conf->assign_hook) (conf->reset_val,
4508 *conf->variable = conf->reset_val;
4509 set_extra_field(&conf->gen, &conf->gen.extra,
4515 gconf->source = gconf->reset_source;
4516 gconf->scontext = gconf->reset_scontext;
4518 if (gconf->flags & GUC_REPORT)
4519 ReportGUCOption(gconf);
4526 * Push previous state during transactional assignment to a GUC variable.
4529 push_old_value(struct config_generic * gconf, GucAction action)
4533 /* If we're not inside a nest level, do nothing */
4534 if (GUCNestLevel == 0)
4537 /* Do we already have a stack entry of the current nest level? */
4538 stack = gconf->stack;
4539 if (stack && stack->nest_level >= GUCNestLevel)
4541 /* Yes, so adjust its state if necessary */
4542 Assert(stack->nest_level == GUCNestLevel);
4545 case GUC_ACTION_SET:
4546 /* SET overrides any prior action at same nest level */
4547 if (stack->state == GUC_SET_LOCAL)
4549 /* must discard old masked value */
4550 discard_stack_value(gconf, &stack->masked);
4552 stack->state = GUC_SET;
4554 case GUC_ACTION_LOCAL:
4555 if (stack->state == GUC_SET)
4557 /* SET followed by SET LOCAL, remember SET's value */
4558 stack->masked_scontext = gconf->scontext;
4559 set_stack_value(gconf, &stack->masked);
4560 stack->state = GUC_SET_LOCAL;
4562 /* in all other cases, no change to stack entry */
4564 case GUC_ACTION_SAVE:
4565 /* Could only have a prior SAVE of same variable */
4566 Assert(stack->state == GUC_SAVE);
4569 Assert(guc_dirty); /* must be set already */
4574 * Push a new stack entry
4576 * We keep all the stack entries in TopTransactionContext for simplicity.
4578 stack = (GucStack *) MemoryContextAllocZero(TopTransactionContext,
4581 stack->prev = gconf->stack;
4582 stack->nest_level = GUCNestLevel;
4585 case GUC_ACTION_SET:
4586 stack->state = GUC_SET;
4588 case GUC_ACTION_LOCAL:
4589 stack->state = GUC_LOCAL;
4591 case GUC_ACTION_SAVE:
4592 stack->state = GUC_SAVE;
4595 stack->source = gconf->source;
4596 stack->scontext = gconf->scontext;
4597 set_stack_value(gconf, &stack->prior);
4599 gconf->stack = stack;
4601 /* Ensure we remember to pop at end of xact */
4607 * Do GUC processing at main transaction start.
4613 * The nest level should be 0 between transactions; if it isn't, somebody
4614 * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
4615 * throw a warning but make no other effort to clean up.
4617 if (GUCNestLevel != 0)
4618 elog(WARNING, "GUC nest level = %d at transaction start",
4624 * Enter a new nesting level for GUC values. This is called at subtransaction
4625 * start, and when entering a function that has proconfig settings, and in
4626 * some other places where we want to set GUC variables transiently.
4627 * NOTE we must not risk error here, else subtransaction start will be unhappy.
4630 NewGUCNestLevel(void)
4632 return ++GUCNestLevel;
4636 * Do GUC processing at transaction or subtransaction commit or abort, or
4637 * when exiting a function that has proconfig settings, or when undoing a
4638 * transient assignment to some GUC variables. (The name is thus a bit of
4639 * a misnomer; perhaps it should be ExitGUCNestLevel or some such.)
4640 * During abort, we discard all GUC settings that were applied at nesting
4641 * levels >= nestLevel. nestLevel == 1 corresponds to the main transaction.
4644 AtEOXact_GUC(bool isCommit, int nestLevel)
4650 * Note: it's possible to get here with GUCNestLevel == nestLevel-1 during
4651 * abort, if there is a failure during transaction start before
4652 * AtStart_GUC is called.
4654 Assert(nestLevel > 0 &&
4655 (nestLevel <= GUCNestLevel ||
4656 (nestLevel == GUCNestLevel + 1 && !isCommit)));
4658 /* Quick exit if nothing's changed in this transaction */
4661 GUCNestLevel = nestLevel - 1;
4665 still_dirty = false;
4666 for (i = 0; i < num_guc_variables; i++)
4668 struct config_generic *gconf = guc_variables[i];
4672 * Process and pop each stack entry within the nest level. To simplify
4673 * fmgr_security_definer() and other places that use GUC_ACTION_SAVE,
4674 * we allow failure exit from code that uses a local nest level to be
4675 * recovered at the surrounding transaction or subtransaction abort;
4676 * so there could be more than one stack entry to pop.
4678 while ((stack = gconf->stack) != NULL &&
4679 stack->nest_level >= nestLevel)
4681 GucStack *prev = stack->prev;
4682 bool restorePrior = false;
4683 bool restoreMasked = false;
4687 * In this next bit, if we don't set either restorePrior or
4688 * restoreMasked, we must "discard" any unwanted fields of the
4689 * stack entries to avoid leaking memory. If we do set one of
4690 * those flags, unused fields will be cleaned up after restoring.
4692 if (!isCommit) /* if abort, always restore prior value */
4693 restorePrior = true;
4694 else if (stack->state == GUC_SAVE)
4695 restorePrior = true;
4696 else if (stack->nest_level == 1)
4698 /* transaction commit */
4699 if (stack->state == GUC_SET_LOCAL)
4700 restoreMasked = true;
4701 else if (stack->state == GUC_SET)
4703 /* we keep the current active value */
4704 discard_stack_value(gconf, &stack->prior);
4706 else /* must be GUC_LOCAL */
4707 restorePrior = true;
4709 else if (prev == NULL ||
4710 prev->nest_level < stack->nest_level - 1)
4712 /* decrement entry's level and do not pop it */
4713 stack->nest_level--;
4719 * We have to merge this stack entry into prev. See README for
4720 * discussion of this bit.
4722 switch (stack->state)
4725 Assert(false); /* can't get here */
4728 /* next level always becomes SET */
4729 discard_stack_value(gconf, &stack->prior);
4730 if (prev->state == GUC_SET_LOCAL)
4731 discard_stack_value(gconf, &prev->masked);
4732 prev->state = GUC_SET;
4736 if (prev->state == GUC_SET)
4738 /* LOCAL migrates down */
4739 prev->masked_scontext = stack->scontext;
4740 prev->masked = stack->prior;
4741 prev->state = GUC_SET_LOCAL;
4745 /* else just forget this stack level */
4746 discard_stack_value(gconf, &stack->prior);
4751 /* prior state at this level no longer wanted */
4752 discard_stack_value(gconf, &stack->prior);
4753 /* copy down the masked state */
4754 prev->masked_scontext = stack->masked_scontext;
4755 if (prev->state == GUC_SET_LOCAL)
4756 discard_stack_value(gconf, &prev->masked);
4757 prev->masked = stack->masked;
4758 prev->state = GUC_SET_LOCAL;
4765 if (restorePrior || restoreMasked)
4767 /* Perform appropriate restoration of the stacked value */
4768 config_var_value newvalue;
4769 GucSource newsource;
4770 GucContext newscontext;
4774 newvalue = stack->masked;
4775 newsource = PGC_S_SESSION;
4776 newscontext = stack->masked_scontext;
4780 newvalue = stack->prior;
4781 newsource = stack->source;
4782 newscontext = stack->scontext;
4785 switch (gconf->vartype)
4789 struct config_bool *conf = (struct config_bool *) gconf;
4790 bool newval = newvalue.val.boolval;
4791 void *newextra = newvalue.extra;
4793 if (*conf->variable != newval ||
4794 conf->gen.extra != newextra)
4796 if (conf->assign_hook)
4797 (*conf->assign_hook) (newval, newextra);
4798 *conf->variable = newval;
4799 set_extra_field(&conf->gen, &conf->gen.extra,
4807 struct config_int *conf = (struct config_int *) gconf;
4808 int newval = newvalue.val.intval;
4809 void *newextra = newvalue.extra;
4811 if (*conf->variable != newval ||
4812 conf->gen.extra != newextra)
4814 if (conf->assign_hook)
4815 (*conf->assign_hook) (newval, newextra);
4816 *conf->variable = newval;
4817 set_extra_field(&conf->gen, &conf->gen.extra,
4825 struct config_real *conf = (struct config_real *) gconf;
4826 double newval = newvalue.val.realval;
4827 void *newextra = newvalue.extra;
4829 if (*conf->variable != newval ||
4830 conf->gen.extra != newextra)
4832 if (conf->assign_hook)
4833 (*conf->assign_hook) (newval, newextra);
4834 *conf->variable = newval;
4835 set_extra_field(&conf->gen, &conf->gen.extra,
4843 struct config_string *conf = (struct config_string *) gconf;
4844 char *newval = newvalue.val.stringval;
4845 void *newextra = newvalue.extra;
4847 if (*conf->variable != newval ||
4848 conf->gen.extra != newextra)
4850 if (conf->assign_hook)
4851 (*conf->assign_hook) (newval, newextra);
4852 set_string_field(conf, conf->variable, newval);
4853 set_extra_field(&conf->gen, &conf->gen.extra,
4859 * Release stacked values if not used anymore. We
4860 * could use discard_stack_value() here, but since
4861 * we have type-specific code anyway, might as
4864 set_string_field(conf, &stack->prior.val.stringval, NULL);
4865 set_string_field(conf, &stack->masked.val.stringval, NULL);
4870 struct config_enum *conf = (struct config_enum *) gconf;
4871 int newval = newvalue.val.enumval;
4872 void *newextra = newvalue.extra;
4874 if (*conf->variable != newval ||
4875 conf->gen.extra != newextra)
4877 if (conf->assign_hook)
4878 (*conf->assign_hook) (newval, newextra);
4879 *conf->variable = newval;
4880 set_extra_field(&conf->gen, &conf->gen.extra,
4889 * Release stacked extra values if not used anymore.
4891 set_extra_field(gconf, &(stack->prior.extra), NULL);
4892 set_extra_field(gconf, &(stack->masked.extra), NULL);
4894 /* And restore source information */
4895 gconf->source = newsource;
4896 gconf->scontext = newscontext;
4899 /* Finish popping the state stack */
4900 gconf->stack = prev;
4903 /* Report new value if we changed it */
4904 if (changed && (gconf->flags & GUC_REPORT))
4905 ReportGUCOption(gconf);
4906 } /* end of stack-popping loop */
4912 /* If there are no remaining stack entries, we can reset guc_dirty */
4913 guc_dirty = still_dirty;
4915 /* Update nesting level */
4916 GUCNestLevel = nestLevel - 1;
4921 * Start up automatic reporting of changes to variables marked GUC_REPORT.
4922 * This is executed at completion of backend startup.
4925 BeginReportingGUCOptions(void)
4930 * Don't do anything unless talking to an interactive frontend of protocol
4933 if (whereToSendOutput != DestRemote ||
4934 PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
4937 reporting_enabled = true;
4939 /* Transmit initial values of interesting variables */
4940 for (i = 0; i < num_guc_variables; i++)
4942 struct config_generic *conf = guc_variables[i];
4944 if (conf->flags & GUC_REPORT)
4945 ReportGUCOption(conf);
4950 * ReportGUCOption: if appropriate, transmit option value to frontend
4953 ReportGUCOption(struct config_generic * record)
4955 if (reporting_enabled && (record->flags & GUC_REPORT))
4957 char *val = _ShowOption(record, false);
4958 StringInfoData msgbuf;
4960 pq_beginmessage(&msgbuf, 'S');
4961 pq_sendstring(&msgbuf, record->name);
4962 pq_sendstring(&msgbuf, val);
4963 pq_endmessage(&msgbuf);
4970 * Try to parse value as an integer. The accepted formats are the
4971 * usual decimal, octal, or hexadecimal formats, optionally followed by
4972 * a unit name if "flags" indicates a unit is allowed.
4974 * If the string parses okay, return true, else false.
4975 * If okay and result is not NULL, return the value in *result.
4976 * If not okay and hintmsg is not NULL, *hintmsg is set to a suitable
4977 * HINT message, or NULL if no hint provided.
4980 parse_int(const char *value, int *result, int flags, const char **hintmsg)
4985 /* To suppress compiler warnings, always set output params */
4991 /* We assume here that int64 is at least as wide as long */
4993 val = strtol(value, &endptr, 0);
4995 if (endptr == value)
4996 return false; /* no HINT for integer syntax error */
4998 if (errno == ERANGE || val != (int64) ((int32) val))
5001 *hintmsg = gettext_noop("Value exceeds integer range.");
5005 /* allow whitespace between integer and unit */
5006 while (isspace((unsigned char) *endptr))
5009 /* Handle possible unit */
5010 if (*endptr != '\0')
5013 * Note: the multiple-switch coding technique here is a bit tedious,
5014 * but seems necessary to avoid intermediate-value overflows.
5016 if (flags & GUC_UNIT_MEMORY)
5018 /* Set hint for use if no match or trailing garbage */
5020 *hintmsg = gettext_noop("Valid units for this parameter are \"kB\", \"MB\", \"GB\", and \"TB\".");
5022 #if BLCKSZ < 1024 || BLCKSZ > (1024*1024)
5023 #error BLCKSZ must be between 1KB and 1MB
5025 #if XLOG_BLCKSZ < 1024 || XLOG_BLCKSZ > (1024*1024)
5026 #error XLOG_BLCKSZ must be between 1KB and 1MB
5029 if (strncmp(endptr, "kB", 2) == 0)
5032 switch (flags & GUC_UNIT_MEMORY)
5034 case GUC_UNIT_BLOCKS:
5035 val /= (BLCKSZ / 1024);
5037 case GUC_UNIT_XBLOCKS:
5038 val /= (XLOG_BLCKSZ / 1024);
5042 else if (strncmp(endptr, "MB", 2) == 0)
5045 switch (flags & GUC_UNIT_MEMORY)
5050 case GUC_UNIT_BLOCKS:
5051 val *= KB_PER_MB / (BLCKSZ / 1024);
5053 case GUC_UNIT_XBLOCKS:
5054 val *= KB_PER_MB / (XLOG_BLCKSZ / 1024);
5058 else if (strncmp(endptr, "GB", 2) == 0)
5061 switch (flags & GUC_UNIT_MEMORY)
5066 case GUC_UNIT_BLOCKS:
5067 val *= KB_PER_GB / (BLCKSZ / 1024);
5069 case GUC_UNIT_XBLOCKS:
5070 val *= KB_PER_GB / (XLOG_BLCKSZ / 1024);
5074 else if (strncmp(endptr, "TB", 2) == 0)
5077 switch (flags & GUC_UNIT_MEMORY)
5082 case GUC_UNIT_BLOCKS:
5083 val *= KB_PER_TB / (BLCKSZ / 1024);
5085 case GUC_UNIT_XBLOCKS:
5086 val *= KB_PER_TB / (XLOG_BLCKSZ / 1024);
5091 else if (flags & GUC_UNIT_TIME)
5093 /* Set hint for use if no match or trailing garbage */
5095 *hintmsg = gettext_noop("Valid units for this parameter are \"ms\", \"s\", \"min\", \"h\", and \"d\".");
5097 if (strncmp(endptr, "ms", 2) == 0)
5100 switch (flags & GUC_UNIT_TIME)
5110 else if (strncmp(endptr, "s", 1) == 0)
5113 switch (flags & GUC_UNIT_TIME)
5123 else if (strncmp(endptr, "min", 3) == 0)
5126 switch (flags & GUC_UNIT_TIME)
5136 else if (strncmp(endptr, "h", 1) == 0)
5139 switch (flags & GUC_UNIT_TIME)
5152 else if (strncmp(endptr, "d", 1) == 0)
5155 switch (flags & GUC_UNIT_TIME)
5170 /* allow whitespace after unit */
5171 while (isspace((unsigned char) *endptr))
5174 if (*endptr != '\0')
5175 return false; /* appropriate hint, if any, already set */
5177 /* Check for overflow due to units conversion */
5178 if (val != (int64) ((int32) val))
5181 *hintmsg = gettext_noop("Value exceeds integer range.");
5187 *result = (int) val;
5194 * Try to parse value as a floating point number in the usual format.
5195 * If the string parses okay, return true, else false.
5196 * If okay and result is not NULL, return the value in *result.
5199 parse_real(const char *value, double *result)
5205 *result = 0; /* suppress compiler warning */
5208 val = strtod(value, &endptr);
5209 if (endptr == value || errno == ERANGE)
5212 /* allow whitespace after number */
5213 while (isspace((unsigned char) *endptr))
5215 if (*endptr != '\0')
5225 * Lookup the name for an enum option with the selected value.
5226 * Should only ever be called with known-valid values, so throws
5227 * an elog(ERROR) if the enum option is not found.
5229 * The returned string is a pointer to static data and not
5230 * allocated for modification.
5233 config_enum_lookup_by_value(struct config_enum * record, int val)
5235 const struct config_enum_entry *entry;
5237 for (entry = record->options; entry && entry->name; entry++)
5239 if (entry->val == val)
5243 elog(ERROR, "could not find enum option %d for %s",
5244 val, record->gen.name);
5245 return NULL; /* silence compiler */
5250 * Lookup the value for an enum option with the selected name
5251 * (case-insensitive).
5252 * If the enum option is found, sets the retval value and returns
5253 * true. If it's not found, return FALSE and retval is set to 0.
5256 config_enum_lookup_by_name(struct config_enum * record, const char *value,
5259 const struct config_enum_entry *entry;
5261 for (entry = record->options; entry && entry->name; entry++)
5263 if (pg_strcasecmp(value, entry->name) == 0)
5265 *retval = entry->val;
5276 * Return a list of all available options for an enum, excluding
5277 * hidden ones, separated by the given separator.
5278 * If prefix is non-NULL, it is added before the first enum value.
5279 * If suffix is non-NULL, it is added to the end of the string.
5282 config_enum_get_options(struct config_enum * record, const char *prefix,
5283 const char *suffix, const char *separator)
5285 const struct config_enum_entry *entry;
5286 StringInfoData retstr;
5289 initStringInfo(&retstr);
5290 appendStringInfoString(&retstr, prefix);
5292 seplen = strlen(separator);
5293 for (entry = record->options; entry && entry->name; entry++)
5297 appendStringInfoString(&retstr, entry->name);
5298 appendBinaryStringInfo(&retstr, separator, seplen);
5303 * All the entries may have been hidden, leaving the string empty if no
5304 * prefix was given. This indicates a broken GUC setup, since there is no
5305 * use for an enum without any values, so we just check to make sure we
5306 * don't write to invalid memory instead of actually trying to do
5307 * something smart with it.
5309 if (retstr.len >= seplen)
5311 /* Replace final separator */
5312 retstr.data[retstr.len - seplen] = '\0';
5313 retstr.len -= seplen;
5316 appendStringInfoString(&retstr, suffix);
5322 * Validates configuration parameter and value, by calling check hook functions
5323 * depending on record's vartype. It validates if the parameter
5324 * value given is in range of expected predefined value for that parameter.
5326 * freemem - true indicates memory for newval and newextra will be
5327 * freed in this function, false indicates it will be freed
5330 * 1: the value is valid
5331 * 0: the name or value is invalid
5334 validate_conf_option(struct config_generic * record, const char *name,
5335 const char *value, GucSource source, int elevel,
5336 bool freemem, void *newval, void **newextra)
5339 * Validate the value for the passed record, to ensure it is in expected
5342 switch (record->vartype)
5347 struct config_bool *conf = (struct config_bool *) record;
5351 newval = &tmpnewval;
5355 if (!parse_bool(value, newval))
5358 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5359 errmsg("parameter \"%s\" requires a Boolean value",
5364 if (!call_bool_check_hook(conf, newval, newextra,
5368 if (*newextra && freemem)
5375 struct config_int *conf = (struct config_int *) record;
5379 newval = &tmpnewval;
5383 const char *hintmsg;
5385 if (!parse_int(value, newval, conf->gen.flags, &hintmsg))
5388 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5389 errmsg("invalid value for parameter \"%s\": \"%s\"",
5391 hintmsg ? errhint("%s", _(hintmsg)) : 0));
5395 if (*((int *) newval) < conf->min || *((int *) newval) > conf->max)
5398 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5399 errmsg("%d is outside the valid range for parameter \"%s\" (%d .. %d)",
5400 *((int *) newval), name, conf->min, conf->max)));
5404 if (!call_int_check_hook(conf, newval, newextra,
5408 if (*newextra && freemem)
5415 struct config_real *conf = (struct config_real *) record;
5419 newval = &tmpnewval;
5423 if (!parse_real(value, newval))
5426 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5427 errmsg("parameter \"%s\" requires a numeric value",
5432 if (*((double *) newval) < conf->min || *((double *) newval) > conf->max)
5435 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5436 errmsg("%g is outside the valid range for parameter \"%s\" (%g .. %g)",
5437 *((double *) newval), name, conf->min, conf->max)));
5441 if (!call_real_check_hook(conf, newval, newextra,
5445 if (*newextra && freemem)
5452 struct config_string *conf = (struct config_string *) record;
5454 char **tmpnewval = newval;
5457 tmpnewval = &tempPtr;
5462 * The value passed by the caller could be transient, so
5463 * we always strdup it.
5465 *tmpnewval = guc_strdup(elevel, value);
5466 if (*tmpnewval == NULL)
5470 * The only built-in "parsing" check we have is to apply
5471 * truncation if GUC_IS_NAME.
5473 if (conf->gen.flags & GUC_IS_NAME)
5474 truncate_identifier(*tmpnewval, strlen(*tmpnewval), true);
5476 if (!call_string_check_hook(conf, tmpnewval, newextra,
5483 /* Free the malloc'd data if any */
5486 if (*tmpnewval != NULL)
5488 if (*newextra != NULL)
5496 struct config_enum *conf = (struct config_enum *) record;
5500 newval = &tmpnewval;
5504 if (!config_enum_lookup_by_name(conf, value, newval))
5508 hintmsg = config_enum_get_options(conf,
5509 "Available values: ",
5513 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5514 errmsg("invalid value for parameter \"%s\": \"%s\"",
5516 hintmsg ? errhint("%s", _(hintmsg)) : 0));
5518 if (hintmsg != NULL)
5522 if (!call_enum_check_hook(conf, newval, newextra,
5526 if (*newextra && freemem)
5537 * Sets option `name' to given value.
5539 * The value should be a string, which will be parsed and converted to
5540 * the appropriate data type. The context and source parameters indicate
5541 * in which context this function is being called, so that it can apply the
5542 * access restrictions properly.
5544 * If value is NULL, set the option to its default value (normally the
5545 * reset_val, but if source == PGC_S_DEFAULT we instead use the boot_val).
5547 * action indicates whether to set the value globally in the session, locally
5548 * to the current top transaction, or just for the duration of a function call.
5550 * If changeVal is false then don't really set the option but do all
5551 * the checks to see if it would work.
5553 * elevel should normally be passed as zero, allowing this function to make
5554 * its standard choice of ereport level. However some callers need to be
5555 * able to override that choice; they should pass the ereport level to use.
5558 * +1: the value is valid and was successfully applied.
5559 * 0: the name or value is invalid (but see below).
5560 * -1: the value was not applied because of context, priority, or changeVal.
5562 * If there is an error (non-existing option, invalid value) then an
5563 * ereport(ERROR) is thrown *unless* this is called for a source for which
5564 * we don't want an ERROR (currently, those are defaults, the config file,
5565 * and per-database or per-user settings, as well as callers who specify
5566 * a less-than-ERROR elevel). In those cases we write a suitable error
5567 * message via ereport() and return 0.
5569 * See also SetConfigOption for an external interface.
5572 set_config_option(const char *name, const char *value,
5573 GucContext context, GucSource source,
5574 GucAction action, bool changeVal, int elevel)
5576 struct config_generic *record;
5577 bool prohibitValueChange = false;
5582 if (source == PGC_S_DEFAULT || source == PGC_S_FILE)
5585 * To avoid cluttering the log, only the postmaster bleats loudly
5586 * about problems with the config file.
5588 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
5590 else if (source == PGC_S_GLOBAL || source == PGC_S_DATABASE || source == PGC_S_USER ||
5591 source == PGC_S_DATABASE_USER)
5597 record = find_option(name, true, elevel);
5601 (errcode(ERRCODE_UNDEFINED_OBJECT),
5602 errmsg("unrecognized configuration parameter \"%s\"", name)));
5607 * Check if the option can be set at this time. See guc.h for the precise
5610 switch (record->context)
5613 if (context != PGC_INTERNAL)
5616 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5617 errmsg("parameter \"%s\" cannot be changed",
5622 case PGC_POSTMASTER:
5623 if (context == PGC_SIGHUP)
5626 * We are re-reading a PGC_POSTMASTER variable from
5627 * postgresql.conf. We can't change the setting, so we should
5628 * give a warning if the DBA tries to change it. However,
5629 * because of variant formats, canonicalization by check
5630 * hooks, etc, we can't just compare the given string directly
5631 * to what's stored. Set a flag to check below after we have
5632 * the final storable value.
5634 prohibitValueChange = true;
5636 else if (context != PGC_POSTMASTER)
5639 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5640 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5646 if (context != PGC_SIGHUP && context != PGC_POSTMASTER)
5649 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5650 errmsg("parameter \"%s\" cannot be changed now",
5656 * Hmm, the idea of the SIGHUP context is "ought to be global, but
5657 * can be changed after postmaster start". But there's nothing
5658 * that prevents a crafty administrator from sending SIGHUP
5659 * signals to individual backends only.
5663 if (context == PGC_SIGHUP)
5666 * If a PGC_BACKEND parameter is changed in the config file,
5667 * we want to accept the new value in the postmaster (whence
5668 * it will propagate to subsequently-started backends), but
5669 * ignore it in existing backends. This is a tad klugy, but
5670 * necessary because we don't re-read the config file during
5673 if (IsUnderPostmaster)
5676 else if (context != PGC_POSTMASTER && context != PGC_BACKEND &&
5677 source != PGC_S_CLIENT)
5680 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5681 errmsg("parameter \"%s\" cannot be set after connection start",
5687 if (context == PGC_USERSET || context == PGC_BACKEND)
5690 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5691 errmsg("permission denied to set parameter \"%s\"",
5702 * Disallow changing GUC_NOT_WHILE_SEC_REST values if we are inside a
5703 * security restriction context. We can reject this regardless of the GUC
5704 * context or source, mainly because sources that it might be reasonable
5705 * to override for won't be seen while inside a function.
5707 * Note: variables marked GUC_NOT_WHILE_SEC_REST should usually be marked
5708 * GUC_NO_RESET_ALL as well, because ResetAllOptions() doesn't check this.
5709 * An exception might be made if the reset value is assumed to be "safe".
5711 * Note: this flag is currently used for "session_authorization" and
5712 * "role". We need to prohibit changing these inside a local userid
5713 * context because when we exit it, GUC won't be notified, leaving things
5714 * out of sync. (This could be fixed by forcing a new GUC nesting level,
5715 * but that would change behavior in possibly-undesirable ways.) Also, we
5716 * prohibit changing these in a security-restricted operation because
5717 * otherwise RESET could be used to regain the session user's privileges.
5719 if (record->flags & GUC_NOT_WHILE_SEC_REST)
5721 if (InLocalUserIdChange())
5724 * Phrasing of this error message is historical, but it's the most
5728 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5729 errmsg("cannot set parameter \"%s\" within security-definer function",
5733 if (InSecurityRestrictedOperation())
5736 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5737 errmsg("cannot set parameter \"%s\" within security-restricted operation",
5744 * Should we set reset/stacked values? (If so, the behavior is not
5745 * transactional.) This is done either when we get a default value from
5746 * the database's/user's/client's default settings or when we reset a
5747 * value to its default.
5749 makeDefault = changeVal && (source <= PGC_S_OVERRIDE) &&
5750 ((value != NULL) || source == PGC_S_DEFAULT);
5753 * Ignore attempted set if overridden by previously processed setting.
5754 * However, if changeVal is false then plow ahead anyway since we are
5755 * trying to find out if the value is potentially good, not actually use
5756 * it. Also keep going if makeDefault is true, since we may want to set
5757 * the reset/stacked values even if we can't set the variable itself.
5759 if (record->source > source)
5761 if (changeVal && !makeDefault)
5763 elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
5771 * Evaluate value and set variable.
5773 switch (record->vartype)
5777 struct config_bool *conf = (struct config_bool *) record;
5779 void *newextra = NULL;
5783 if (!validate_conf_option(record, name, value, source,
5784 elevel, false, &newval,
5788 else if (source == PGC_S_DEFAULT)
5790 newval = conf->boot_val;
5791 if (!call_bool_check_hook(conf, &newval, &newextra,
5797 newval = conf->reset_val;
5798 newextra = conf->reset_extra;
5799 source = conf->gen.reset_source;
5800 context = conf->gen.reset_scontext;
5803 if (prohibitValueChange)
5805 if (*conf->variable != newval)
5808 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5809 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5818 /* Save old value to support transaction abort */
5820 push_old_value(&conf->gen, action);
5822 if (conf->assign_hook)
5823 (*conf->assign_hook) (newval, newextra);
5824 *conf->variable = newval;
5825 set_extra_field(&conf->gen, &conf->gen.extra,
5827 conf->gen.source = source;
5828 conf->gen.scontext = context;
5834 if (conf->gen.reset_source <= source)
5836 conf->reset_val = newval;
5837 set_extra_field(&conf->gen, &conf->reset_extra,
5839 conf->gen.reset_source = source;
5840 conf->gen.reset_scontext = context;
5842 for (stack = conf->gen.stack; stack; stack = stack->prev)
5844 if (stack->source <= source)
5846 stack->prior.val.boolval = newval;
5847 set_extra_field(&conf->gen, &stack->prior.extra,
5849 stack->source = source;
5850 stack->scontext = context;
5855 /* Perhaps we didn't install newextra anywhere */
5856 if (newextra && !extra_field_used(&conf->gen, newextra))
5863 struct config_int *conf = (struct config_int *) record;
5865 void *newextra = NULL;
5869 if (!validate_conf_option(record, name, value, source,
5870 elevel, false, &newval,
5874 else if (source == PGC_S_DEFAULT)
5876 newval = conf->boot_val;
5877 if (!call_int_check_hook(conf, &newval, &newextra,
5883 newval = conf->reset_val;
5884 newextra = conf->reset_extra;
5885 source = conf->gen.reset_source;
5886 context = conf->gen.reset_scontext;
5889 if (prohibitValueChange)
5891 if (*conf->variable != newval)
5894 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5895 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5904 /* Save old value to support transaction abort */
5906 push_old_value(&conf->gen, action);
5908 if (conf->assign_hook)
5909 (*conf->assign_hook) (newval, newextra);
5910 *conf->variable = newval;
5911 set_extra_field(&conf->gen, &conf->gen.extra,
5913 conf->gen.source = source;
5914 conf->gen.scontext = context;
5920 if (conf->gen.reset_source <= source)
5922 conf->reset_val = newval;
5923 set_extra_field(&conf->gen, &conf->reset_extra,
5925 conf->gen.reset_source = source;
5926 conf->gen.reset_scontext = context;
5928 for (stack = conf->gen.stack; stack; stack = stack->prev)
5930 if (stack->source <= source)
5932 stack->prior.val.intval = newval;
5933 set_extra_field(&conf->gen, &stack->prior.extra,
5935 stack->source = source;
5936 stack->scontext = context;
5941 /* Perhaps we didn't install newextra anywhere */
5942 if (newextra && !extra_field_used(&conf->gen, newextra))
5949 struct config_real *conf = (struct config_real *) record;
5951 void *newextra = NULL;
5955 if (!validate_conf_option(record, name, value, source,
5956 elevel, false, &newval,
5960 else if (source == PGC_S_DEFAULT)
5962 newval = conf->boot_val;
5963 if (!call_real_check_hook(conf, &newval, &newextra,
5969 newval = conf->reset_val;
5970 newextra = conf->reset_extra;
5971 source = conf->gen.reset_source;
5972 context = conf->gen.reset_scontext;
5975 if (prohibitValueChange)
5977 if (*conf->variable != newval)
5980 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5981 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5990 /* Save old value to support transaction abort */
5992 push_old_value(&conf->gen, action);
5994 if (conf->assign_hook)
5995 (*conf->assign_hook) (newval, newextra);
5996 *conf->variable = newval;
5997 set_extra_field(&conf->gen, &conf->gen.extra,
5999 conf->gen.source = source;
6000 conf->gen.scontext = context;
6006 if (conf->gen.reset_source <= source)
6008 conf->reset_val = newval;
6009 set_extra_field(&conf->gen, &conf->reset_extra,
6011 conf->gen.reset_source = source;
6012 conf->gen.reset_scontext = context;
6014 for (stack = conf->gen.stack; stack; stack = stack->prev)
6016 if (stack->source <= source)
6018 stack->prior.val.realval = newval;
6019 set_extra_field(&conf->gen, &stack->prior.extra,
6021 stack->source = source;
6022 stack->scontext = context;
6027 /* Perhaps we didn't install newextra anywhere */
6028 if (newextra && !extra_field_used(&conf->gen, newextra))
6035 struct config_string *conf = (struct config_string *) record;
6037 void *newextra = NULL;
6041 if (!validate_conf_option(record, name, value, source,
6042 elevel, false, &newval,
6046 else if (source == PGC_S_DEFAULT)
6048 /* non-NULL boot_val must always get strdup'd */
6049 if (conf->boot_val != NULL)
6051 newval = guc_strdup(elevel, conf->boot_val);
6058 if (!call_string_check_hook(conf, &newval, &newextra,
6068 * strdup not needed, since reset_val is already under
6071 newval = conf->reset_val;
6072 newextra = conf->reset_extra;
6073 source = conf->gen.reset_source;
6074 context = conf->gen.reset_scontext;
6077 if (prohibitValueChange)
6079 /* newval shouldn't be NULL, so we're a bit sloppy here */
6080 if (*conf->variable == NULL || newval == NULL ||
6081 strcmp(*conf->variable, newval) != 0)
6084 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6085 errmsg("parameter \"%s\" cannot be changed without restarting the server",
6094 /* Save old value to support transaction abort */
6096 push_old_value(&conf->gen, action);
6098 if (conf->assign_hook)
6099 (*conf->assign_hook) (newval, newextra);
6100 set_string_field(conf, conf->variable, newval);
6101 set_extra_field(&conf->gen, &conf->gen.extra,
6103 conf->gen.source = source;
6104 conf->gen.scontext = context;
6111 if (conf->gen.reset_source <= source)
6113 set_string_field(conf, &conf->reset_val, newval);
6114 set_extra_field(&conf->gen, &conf->reset_extra,
6116 conf->gen.reset_source = source;
6117 conf->gen.reset_scontext = context;
6119 for (stack = conf->gen.stack; stack; stack = stack->prev)
6121 if (stack->source <= source)
6123 set_string_field(conf, &stack->prior.val.stringval,
6125 set_extra_field(&conf->gen, &stack->prior.extra,
6127 stack->source = source;
6128 stack->scontext = context;
6133 /* Perhaps we didn't install newval anywhere */
6134 if (newval && !string_field_used(conf, newval))
6136 /* Perhaps we didn't install newextra anywhere */
6137 if (newextra && !extra_field_used(&conf->gen, newextra))
6144 struct config_enum *conf = (struct config_enum *) record;
6146 void *newextra = NULL;
6150 if (!validate_conf_option(record, name, value, source,
6151 elevel, false, &newval,
6155 else if (source == PGC_S_DEFAULT)
6157 newval = conf->boot_val;
6158 if (!call_enum_check_hook(conf, &newval, &newextra,
6164 newval = conf->reset_val;
6165 newextra = conf->reset_extra;
6166 source = conf->gen.reset_source;
6167 context = conf->gen.reset_scontext;
6170 if (prohibitValueChange)
6172 if (*conf->variable != newval)
6175 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6176 errmsg("parameter \"%s\" cannot be changed without restarting the server",
6185 /* Save old value to support transaction abort */
6187 push_old_value(&conf->gen, action);
6189 if (conf->assign_hook)
6190 (*conf->assign_hook) (newval, newextra);
6191 *conf->variable = newval;
6192 set_extra_field(&conf->gen, &conf->gen.extra,
6194 conf->gen.source = source;
6195 conf->gen.scontext = context;
6201 if (conf->gen.reset_source <= source)
6203 conf->reset_val = newval;
6204 set_extra_field(&conf->gen, &conf->reset_extra,
6206 conf->gen.reset_source = source;
6207 conf->gen.reset_scontext = context;
6209 for (stack = conf->gen.stack; stack; stack = stack->prev)
6211 if (stack->source <= source)
6213 stack->prior.val.enumval = newval;
6214 set_extra_field(&conf->gen, &stack->prior.extra,
6216 stack->source = source;
6217 stack->scontext = context;
6222 /* Perhaps we didn't install newextra anywhere */
6223 if (newextra && !extra_field_used(&conf->gen, newextra))
6229 if (changeVal && (record->flags & GUC_REPORT))
6230 ReportGUCOption(record);
6232 return changeVal ? 1 : -1;
6237 * Set the fields for source file and line number the setting came from.
6240 set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
6242 struct config_generic *record;
6246 * To avoid cluttering the log, only the postmaster bleats loudly about
6247 * problems with the config file.
6249 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
6251 record = find_option(name, true, elevel);
6252 /* should not happen */
6254 elog(ERROR, "unrecognized configuration parameter \"%s\"", name);
6256 sourcefile = guc_strdup(elevel, sourcefile);
6257 if (record->sourcefile)
6258 free(record->sourcefile);
6259 record->sourcefile = sourcefile;
6260 record->sourceline = sourceline;
6264 * Set a config option to the given value.
6266 * See also set_config_option; this is just the wrapper to be called from
6267 * outside GUC. (This function should be used when possible, because its API
6268 * is more stable than set_config_option's.)
6270 * Note: there is no support here for setting source file/line, as it
6271 * is currently not needed.
6274 SetConfigOption(const char *name, const char *value,
6275 GucContext context, GucSource source)
6277 (void) set_config_option(name, value, context, source,
6278 GUC_ACTION_SET, true, 0);
6284 * Fetch the current value of the option `name', as a string.
6286 * If the option doesn't exist, return NULL if missing_ok is true (NOTE that
6287 * this cannot be distinguished from a string variable with a NULL value!),
6288 * otherwise throw an ereport and don't return.
6290 * If restrict_superuser is true, we also enforce that only superusers can
6291 * see GUC_SUPERUSER_ONLY variables. This should only be passed as true
6292 * in user-driven calls.
6294 * The string is *not* allocated for modification and is really only
6295 * valid until the next call to configuration related functions.
6298 GetConfigOption(const char *name, bool missing_ok, bool restrict_superuser)
6300 struct config_generic *record;
6301 static char buffer[256];
6303 record = find_option(name, false, ERROR);
6309 (errcode(ERRCODE_UNDEFINED_OBJECT),
6310 errmsg("unrecognized configuration parameter \"%s\"",
6313 if (restrict_superuser &&
6314 (record->flags & GUC_SUPERUSER_ONLY) &&
6317 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6318 errmsg("must be superuser to examine \"%s\"", name)));
6320 switch (record->vartype)
6323 return *((struct config_bool *) record)->variable ? "on" : "off";
6326 snprintf(buffer, sizeof(buffer), "%d",
6327 *((struct config_int *) record)->variable);
6331 snprintf(buffer, sizeof(buffer), "%g",
6332 *((struct config_real *) record)->variable);
6336 return *((struct config_string *) record)->variable;
6339 return config_enum_lookup_by_value((struct config_enum *) record,
6340 *((struct config_enum *) record)->variable);
6346 * Get the RESET value associated with the given option.
6348 * Note: this is not re-entrant, due to use of static result buffer;
6349 * not to mention that a string variable could have its reset_val changed.
6350 * Beware of assuming the result value is good for very long.
6353 GetConfigOptionResetString(const char *name)
6355 struct config_generic *record;
6356 static char buffer[256];
6358 record = find_option(name, false, ERROR);
6361 (errcode(ERRCODE_UNDEFINED_OBJECT),
6362 errmsg("unrecognized configuration parameter \"%s\"", name)));
6363 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
6365 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6366 errmsg("must be superuser to examine \"%s\"", name)));
6368 switch (record->vartype)
6371 return ((struct config_bool *) record)->reset_val ? "on" : "off";
6374 snprintf(buffer, sizeof(buffer), "%d",
6375 ((struct config_int *) record)->reset_val);
6379 snprintf(buffer, sizeof(buffer), "%g",
6380 ((struct config_real *) record)->reset_val);
6384 return ((struct config_string *) record)->reset_val;
6387 return config_enum_lookup_by_value((struct config_enum *) record,
6388 ((struct config_enum *) record)->reset_val);
6395 * flatten_set_variable_args
6396 * Given a parsenode List as emitted by the grammar for SET,
6397 * convert to the flat string representation used by GUC.
6399 * We need to be told the name of the variable the args are for, because
6400 * the flattening rules vary (ugh).
6402 * The result is NULL if args is NIL (ie, SET ... TO DEFAULT), otherwise
6403 * a palloc'd string.
6406 flatten_set_variable_args(const char *name, List *args)
6408 struct config_generic *record;
6413 /* Fast path if just DEFAULT */
6418 * Get flags for the variable; if it's not known, use default flags.
6419 * (Caller might throw error later, but not our business to do so here.)
6421 record = find_option(name, false, WARNING);
6423 flags = record->flags;
6427 /* Complain if list input and non-list variable */
6428 if ((flags & GUC_LIST_INPUT) == 0 &&
6429 list_length(args) != 1)
6431 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6432 errmsg("SET %s takes only one argument", name)));
6434 initStringInfo(&buf);
6437 * Each list member may be a plain A_Const node, or an A_Const within a
6438 * TypeCast; the latter case is supported only for ConstInterval arguments
6439 * (for SET TIME ZONE).
6443 Node *arg = (Node *) lfirst(l);
6445 TypeName *typeName = NULL;
6448 if (l != list_head(args))
6449 appendStringInfoString(&buf, ", ");
6451 if (IsA(arg, TypeCast))
6453 TypeCast *tc = (TypeCast *) arg;
6456 typeName = tc->typeName;
6459 if (!IsA(arg, A_Const))
6460 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
6461 con = (A_Const *) arg;
6463 switch (nodeTag(&con->val))
6466 appendStringInfo(&buf, "%ld", intVal(&con->val));
6469 /* represented as a string, so just copy it */
6470 appendStringInfoString(&buf, strVal(&con->val));
6473 val = strVal(&con->val);
6474 if (typeName != NULL)
6477 * Must be a ConstInterval argument for TIME ZONE. Coerce
6478 * to interval and back to normalize the value and account
6486 typenameTypeIdAndMod(NULL, typeName, &typoid, &typmod);
6487 Assert(typoid == INTERVALOID);
6490 DirectFunctionCall3(interval_in,
6491 CStringGetDatum(val),
6492 ObjectIdGetDatum(InvalidOid),
6493 Int32GetDatum(typmod));
6496 DatumGetCString(DirectFunctionCall1(interval_out,
6498 appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
6503 * Plain string literal or identifier. For quote mode,
6504 * quote it if it's not a vanilla identifier.
6506 if (flags & GUC_LIST_QUOTE)
6507 appendStringInfoString(&buf, quote_identifier(val));
6509 appendStringInfoString(&buf, val);
6513 elog(ERROR, "unrecognized node type: %d",
6514 (int) nodeTag(&con->val));
6523 * Write updated configuration parameter values into a temporary file.
6524 * This function traverses the list of parameters and quotes the string
6525 * values before writing them.
6528 write_auto_conf_file(int fd, const char *filename, ConfigVariable **head_p)
6530 ConfigVariable *item;
6533 initStringInfo(&buf);
6534 appendStringInfoString(&buf, "# Do not edit this file manually!\n");
6535 appendStringInfoString(&buf, "# It will be overwritten by ALTER SYSTEM command.\n");
6538 * write the file header message before contents, so that if there is no
6539 * item it can contain message
6541 if (write(fd, buf.data, buf.len) < 0)
6543 (errmsg("failed to write to \"%s\" file", filename)));
6544 resetStringInfo(&buf);
6547 * traverse the list of parameters, quote the string parameter and write
6548 * it to file. Once all parameters are written fsync the file.
6551 for (item = *head_p; item != NULL; item = item->next)
6555 appendStringInfoString(&buf, item->name);
6556 appendStringInfoString(&buf, " = ");
6558 appendStringInfoString(&buf, "\'");
6559 escaped = escape_single_quotes_ascii(item->value);
6560 appendStringInfoString(&buf, escaped);
6562 appendStringInfoString(&buf, "\'");
6564 appendStringInfoString(&buf, "\n");
6566 if (write(fd, buf.data, buf.len) < 0)
6568 (errmsg("failed to write to \"%s\" file", filename)));
6569 resetStringInfo(&buf);
6572 if (pg_fsync(fd) != 0)
6574 (errcode_for_file_access(),
6575 errmsg("could not fsync file \"%s\": %m", filename)));
6582 * This function takes list of all configuration parameters in
6583 * PG_AUTOCONF_FILENAME and parameter to be updated as input arguments and
6584 * replace the updated configuration parameter value in a list. If the
6585 * parameter to be updated is new then it is appended to the list of
6589 replace_auto_config_value(ConfigVariable **head_p, ConfigVariable **tail_p,
6591 char *name, char *value)
6593 ConfigVariable *item,
6596 if (*head_p != NULL)
6598 for (item = *head_p; item != NULL; item = item->next)
6600 if (strcmp(item->name, name) == 0)
6604 /* update the parameter value */
6605 item->value = pstrdup(value);
6608 /* delete the configuration parameter from list */
6609 if (*head_p == item)
6610 *head_p = item->next;
6612 prev->next = item->next;
6614 if (*tail_p == item)
6618 pfree(item->filename);
6630 item = palloc(sizeof *item);
6631 item->name = pstrdup(name);
6632 item->value = pstrdup(value);
6633 item->filename = pstrdup(config_file);
6636 if (*head_p == NULL)
6638 item->sourceline = 1;
6643 item->sourceline = (*tail_p)->sourceline + 1;
6644 (*tail_p)->next = item;
6654 * Persist the configuration parameter value.
6656 * This function takes all previous configuration parameters
6657 * set by ALTER SYSTEM command and the currently set ones
6658 * and write them all to the automatic configuration file.
6660 * The configuration parameters are written to a temporary
6661 * file then renamed to the final name.
6663 * An LWLock is used to serialize writing to the same file.
6665 * In case of an error, we leave the original automatic
6666 * configuration file (PG_AUTOCONF_FILENAME) intact.
6669 AlterSystemSetConfigFile(AlterSystemStmt * altersysstmt)
6675 struct config_generic *record;
6676 ConfigVariable *head = NULL;
6677 ConfigVariable *tail = NULL;
6678 char AutoConfFileName[MAXPGPATH];
6679 char AutoConfTmpFileName[MAXPGPATH];
6681 void *newextra = NULL;
6685 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6686 (errmsg("must be superuser to execute ALTER SYSTEM command"))));
6689 * Validate the name and arguments [value1, value2 ... ].
6691 name = altersysstmt->setstmt->name;
6693 switch (altersysstmt->setstmt->kind)
6696 value = ExtractSetVariableArgs(altersysstmt->setstmt);
6699 case VAR_SET_DEFAULT:
6703 elog(ERROR, "unrecognized alter system stmt type: %d",
6704 altersysstmt->setstmt->kind);
6708 record = find_option(name, false, LOG);
6711 (errcode(ERRCODE_UNDEFINED_OBJECT),
6712 errmsg("unrecognized configuration parameter \"%s\"", name)));
6714 if ((record->context == PGC_INTERNAL) ||
6715 (record->flags & GUC_DISALLOW_IN_FILE))
6717 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6718 errmsg("parameter \"%s\" cannot be changed",
6721 if (!validate_conf_option(record, name, value, PGC_S_FILE,
6725 (errmsg("invalid value for parameter \"%s\": \"%s\"", name, value)));
6729 * Use data directory as reference path for PG_AUTOCONF_FILENAME and its
6730 * corresponding temporary file.
6732 join_path_components(AutoConfFileName, data_directory, PG_AUTOCONF_FILENAME);
6733 canonicalize_path(AutoConfFileName);
6734 snprintf(AutoConfTmpFileName, sizeof(AutoConfTmpFileName), "%s.%s",
6739 * One backend is allowed to operate on file PG_AUTOCONF_FILENAME, to
6740 * ensure that we need to update the contents of the file with
6741 * AutoFileLock. To ensure crash safety, first the contents are written to
6742 * a temporary file which is then renameed to PG_AUTOCONF_FILENAME. In case
6743 * there exists a temp file from previous crash, that can be reused.
6746 LWLockAcquire(AutoFileLock, LW_EXCLUSIVE);
6748 Tmpfd = open(AutoConfTmpFileName, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
6751 (errcode_for_file_access(),
6752 errmsg("failed to open auto conf temp file \"%s\": %m ",
6753 AutoConfTmpFileName)));
6757 if (stat(AutoConfFileName, &st) == 0)
6759 /* open file PG_AUTOCONF_FILENAME */
6760 infile = AllocateFile(AutoConfFileName, "r");
6763 (errmsg("failed to open auto conf file \"%s\": %m ",
6764 AutoConfFileName)));
6767 ParseConfigFp(infile, AutoConfFileName, 0, LOG, &head, &tail);
6773 * replace with new value if the configuration parameter already
6774 * exists OR add it as a new cofiguration parameter in the file.
6776 replace_auto_config_value(&head, &tail, AutoConfFileName, name, value);
6778 /* Write and sync the new contents to the temporary file */
6779 write_auto_conf_file(Tmpfd, AutoConfTmpFileName, &head);
6785 * As the rename is atomic operation, if any problem occurs after this
6786 * at max it can loose the parameters set by last ALTER SYSTEM
6789 if (rename(AutoConfTmpFileName, AutoConfFileName) < 0)
6791 (errcode_for_file_access(),
6792 errmsg("could not rename file \"%s\" to \"%s\" : %m",
6793 AutoConfTmpFileName, AutoConfFileName)));
6800 unlink(AutoConfTmpFileName);
6801 FreeConfigVariables(head);
6806 FreeConfigVariables(head);
6807 LWLockRelease(AutoFileLock);
6815 ExecSetVariableStmt(VariableSetStmt *stmt, bool isTopLevel)
6817 GucAction action = stmt->is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET;
6822 case VAR_SET_CURRENT:
6824 WarnNoTransactionChain(isTopLevel, "SET LOCAL");
6825 (void) set_config_option(stmt->name,
6826 ExtractSetVariableArgs(stmt),
6827 (superuser() ? PGC_SUSET : PGC_USERSET),
6835 * Special-case SQL syntaxes. The TRANSACTION and SESSION
6836 * CHARACTERISTICS cases effectively set more than one variable
6837 * per statement. TRANSACTION SNAPSHOT only takes one argument,
6838 * but we put it here anyway since it's a special case and not
6839 * related to any GUC variable.
6841 if (strcmp(stmt->name, "TRANSACTION") == 0)
6845 WarnNoTransactionChain(isTopLevel, "SET TRANSACTION");
6847 foreach(head, stmt->args)
6849 DefElem *item = (DefElem *) lfirst(head);
6851 if (strcmp(item->defname, "transaction_isolation") == 0)
6852 SetPGVariable("transaction_isolation",
6853 list_make1(item->arg), stmt->is_local);
6854 else if (strcmp(item->defname, "transaction_read_only") == 0)
6855 SetPGVariable("transaction_read_only",
6856 list_make1(item->arg), stmt->is_local);
6857 else if (strcmp(item->defname, "transaction_deferrable") == 0)
6858 SetPGVariable("transaction_deferrable",
6859 list_make1(item->arg), stmt->is_local);
6861 elog(ERROR, "unexpected SET TRANSACTION element: %s",
6865 else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
6869 foreach(head, stmt->args)
6871 DefElem *item = (DefElem *) lfirst(head);
6873 if (strcmp(item->defname, "transaction_isolation") == 0)
6874 SetPGVariable("default_transaction_isolation",
6875 list_make1(item->arg), stmt->is_local);
6876 else if (strcmp(item->defname, "transaction_read_only") == 0)
6877 SetPGVariable("default_transaction_read_only",
6878 list_make1(item->arg), stmt->is_local);
6879 else if (strcmp(item->defname, "transaction_deferrable") == 0)
6880 SetPGVariable("default_transaction_deferrable",
6881 list_make1(item->arg), stmt->is_local);
6883 elog(ERROR, "unexpected SET SESSION element: %s",
6887 else if (strcmp(stmt->name, "TRANSACTION SNAPSHOT") == 0)
6889 A_Const *con = (A_Const *) linitial(stmt->args);
6893 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6894 errmsg("SET LOCAL TRANSACTION SNAPSHOT is not implemented")));
6896 WarnNoTransactionChain(isTopLevel, "SET TRANSACTION");
6897 Assert(IsA(con, A_Const));
6898 Assert(nodeTag(&con->val) == T_String);
6899 ImportSnapshot(strVal(&con->val));
6902 elog(ERROR, "unexpected SET MULTI element: %s",
6905 case VAR_SET_DEFAULT:
6907 WarnNoTransactionChain(isTopLevel, "SET LOCAL");
6910 if (strcmp(stmt->name, "transaction_isolation") == 0)
6911 WarnNoTransactionChain(isTopLevel, "RESET TRANSACTION");
6913 (void) set_config_option(stmt->name,
6915 (superuser() ? PGC_SUSET : PGC_USERSET),
6928 * Get the value to assign for a VariableSetStmt, or NULL if it's RESET.
6929 * The result is palloc'd.
6931 * This is exported for use by actions such as ALTER ROLE SET.
6934 ExtractSetVariableArgs(VariableSetStmt *stmt)
6939 return flatten_set_variable_args(stmt->name, stmt->args);
6940 case VAR_SET_CURRENT:
6941 return GetConfigOptionByName(stmt->name, NULL);
6948 * SetPGVariable - SET command exported as an easily-C-callable function.
6950 * This provides access to SET TO value, as well as SET TO DEFAULT (expressed
6951 * by passing args == NIL), but not SET FROM CURRENT functionality.
6954 SetPGVariable(const char *name, List *args, bool is_local)
6956 char *argstring = flatten_set_variable_args(name, args);
6958 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
6959 (void) set_config_option(name,
6961 (superuser() ? PGC_SUSET : PGC_USERSET),
6963 is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET,
6969 * SET command wrapped as a SQL callable function.
6972 set_config_by_name(PG_FUNCTION_ARGS)
6979 if (PG_ARGISNULL(0))
6981 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
6982 errmsg("SET requires parameter name")));
6984 /* Get the GUC variable name */
6985 name = TextDatumGetCString(PG_GETARG_DATUM(0));
6987 /* Get the desired value or set to NULL for a reset request */
6988 if (PG_ARGISNULL(1))
6991 value = TextDatumGetCString(PG_GETARG_DATUM(1));
6994 * Get the desired state of is_local. Default to false if provided value
6997 if (PG_ARGISNULL(2))
7000 is_local = PG_GETARG_BOOL(2);
7002 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
7003 (void) set_config_option(name,
7005 (superuser() ? PGC_SUSET : PGC_USERSET),
7007 is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET,
7011 /* get the new current value */
7012 new_value = GetConfigOptionByName(name, NULL);
7014 /* Convert return string to text */
7015 PG_RETURN_TEXT_P(cstring_to_text(new_value));
7020 * Common code for DefineCustomXXXVariable subroutines: allocate the
7021 * new variable's config struct and fill in generic fields.
7023 static struct config_generic *
7024 init_custom_variable(const char *name,
7025 const char *short_desc,
7026 const char *long_desc,
7029 enum config_type type,
7032 struct config_generic *gen;
7035 * Only allow custom PGC_POSTMASTER variables to be created during shared
7036 * library preload; any later than that, we can't ensure that the value
7037 * doesn't change after startup. This is a fatal elog if it happens; just
7038 * erroring out isn't safe because we don't know what the calling loadable
7039 * module might already have hooked into.
7041 if (context == PGC_POSTMASTER &&
7042 !process_shared_preload_libraries_in_progress)
7043 elog(FATAL, "cannot create PGC_POSTMASTER variables after startup");
7045 gen = (struct config_generic *) guc_malloc(ERROR, sz);
7048 gen->name = guc_strdup(ERROR, name);
7049 gen->context = context;
7050 gen->group = CUSTOM_OPTIONS;
7051 gen->short_desc = short_desc;
7052 gen->long_desc = long_desc;
7054 gen->vartype = type;
7060 * Common code for DefineCustomXXXVariable subroutines: insert the new
7061 * variable into the GUC variable array, replacing any placeholder.
7064 define_custom_variable(struct config_generic * variable)
7066 const char *name = variable->name;
7067 const char **nameAddr = &name;
7068 struct config_string *pHolder;
7069 struct config_generic **res;
7072 * See if there's a placeholder by the same name.
7074 res = (struct config_generic **) bsearch((void *) &nameAddr,
7075 (void *) guc_variables,
7077 sizeof(struct config_generic *),
7082 * No placeholder to replace, so we can just add it ... but first,
7083 * make sure it's initialized to its default value.
7085 InitializeOneGUCOption(variable);
7086 add_guc_variable(variable, ERROR);
7091 * This better be a placeholder
7093 if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
7095 (errcode(ERRCODE_INTERNAL_ERROR),
7096 errmsg("attempt to redefine parameter \"%s\"", name)));
7098 Assert((*res)->vartype == PGC_STRING);
7099 pHolder = (struct config_string *) (*res);
7102 * First, set the variable to its default value. We must do this even
7103 * though we intend to immediately apply a new value, since it's possible
7104 * that the new value is invalid.
7106 InitializeOneGUCOption(variable);
7109 * Replace the placeholder. We aren't changing the name, so no re-sorting
7115 * Assign the string value(s) stored in the placeholder to the real
7116 * variable. Essentially, we need to duplicate all the active and stacked
7117 * values, but with appropriate validation and datatype adjustment.
7119 * If an assignment fails, we report a WARNING and keep going. We don't
7120 * want to throw ERROR for bad values, because it'd bollix the add-on
7121 * module that's presumably halfway through getting loaded. In such cases
7122 * the default or previous state will become active instead.
7125 /* First, apply the reset value if any */
7126 if (pHolder->reset_val)
7127 (void) set_config_option(name, pHolder->reset_val,
7128 pHolder->gen.reset_scontext,
7129 pHolder->gen.reset_source,
7130 GUC_ACTION_SET, true, WARNING);
7131 /* That should not have resulted in stacking anything */
7132 Assert(variable->stack == NULL);
7134 /* Now, apply current and stacked values, in the order they were stacked */
7135 reapply_stacked_values(variable, pHolder, pHolder->gen.stack,
7136 *(pHolder->variable),
7137 pHolder->gen.scontext, pHolder->gen.source);
7139 /* Also copy over any saved source-location information */
7140 if (pHolder->gen.sourcefile)
7141 set_config_sourcefile(name, pHolder->gen.sourcefile,
7142 pHolder->gen.sourceline);
7145 * Free up as much as we conveniently can of the placeholder structure.
7146 * (This neglects any stack items, so it's possible for some memory to be
7147 * leaked. Since this can only happen once per session per variable, it
7148 * doesn't seem worth spending much code on.)
7150 set_string_field(pHolder, pHolder->variable, NULL);
7151 set_string_field(pHolder, &pHolder->reset_val, NULL);
7157 * Recursive subroutine for define_custom_variable: reapply non-reset values
7159 * We recurse so that the values are applied in the same order as originally.
7160 * At each recursion level, apply the upper-level value (passed in) in the
7161 * fashion implied by the stack entry.
7164 reapply_stacked_values(struct config_generic * variable,
7165 struct config_string * pHolder,
7167 const char *curvalue,
7168 GucContext curscontext, GucSource cursource)
7170 const char *name = variable->name;
7171 GucStack *oldvarstack = variable->stack;
7175 /* First, recurse, so that stack items are processed bottom to top */
7176 reapply_stacked_values(variable, pHolder, stack->prev,
7177 stack->prior.val.stringval,
7178 stack->scontext, stack->source);
7180 /* See how to apply the passed-in value */
7181 switch (stack->state)
7184 (void) set_config_option(name, curvalue,
7185 curscontext, cursource,
7186 GUC_ACTION_SAVE, true, WARNING);
7190 (void) set_config_option(name, curvalue,
7191 curscontext, cursource,
7192 GUC_ACTION_SET, true, WARNING);
7196 (void) set_config_option(name, curvalue,
7197 curscontext, cursource,
7198 GUC_ACTION_LOCAL, true, WARNING);
7202 /* first, apply the masked value as SET */
7203 (void) set_config_option(name, stack->masked.val.stringval,
7204 stack->masked_scontext, PGC_S_SESSION,
7205 GUC_ACTION_SET, true, WARNING);
7206 /* then apply the current value as LOCAL */
7207 (void) set_config_option(name, curvalue,
7208 curscontext, cursource,
7209 GUC_ACTION_LOCAL, true, WARNING);
7213 /* If we successfully made a stack entry, adjust its nest level */
7214 if (variable->stack != oldvarstack)
7215 variable->stack->nest_level = stack->nest_level;
7220 * We are at the end of the stack. If the active/previous value is
7221 * different from the reset value, it must represent a previously
7222 * committed session value. Apply it, and then drop the stack entry
7223 * that set_config_option will have created under the impression that
7224 * this is to be just a transactional assignment. (We leak the stack
7227 if (curvalue != pHolder->reset_val ||
7228 curscontext != pHolder->gen.reset_scontext ||
7229 cursource != pHolder->gen.reset_source)
7231 (void) set_config_option(name, curvalue,
7232 curscontext, cursource,
7233 GUC_ACTION_SET, true, WARNING);
7234 variable->stack = NULL;
7240 DefineCustomBoolVariable(const char *name,
7241 const char *short_desc,
7242 const char *long_desc,
7247 GucBoolCheckHook check_hook,
7248 GucBoolAssignHook assign_hook,
7249 GucShowHook show_hook)
7251 struct config_bool *var;
7253 var = (struct config_bool *)
7254 init_custom_variable(name, short_desc, long_desc, context, flags,
7255 PGC_BOOL, sizeof(struct config_bool));
7256 var->variable = valueAddr;
7257 var->boot_val = bootValue;
7258 var->reset_val = bootValue;
7259 var->check_hook = check_hook;
7260 var->assign_hook = assign_hook;
7261 var->show_hook = show_hook;
7262 define_custom_variable(&var->gen);
7266 DefineCustomIntVariable(const char *name,
7267 const char *short_desc,
7268 const char *long_desc,
7275 GucIntCheckHook check_hook,
7276 GucIntAssignHook assign_hook,
7277 GucShowHook show_hook)
7279 struct config_int *var;
7281 var = (struct config_int *)
7282 init_custom_variable(name, short_desc, long_desc, context, flags,
7283 PGC_INT, sizeof(struct config_int));
7284 var->variable = valueAddr;
7285 var->boot_val = bootValue;
7286 var->reset_val = bootValue;
7287 var->min = minValue;
7288 var->max = maxValue;
7289 var->check_hook = check_hook;
7290 var->assign_hook = assign_hook;
7291 var->show_hook = show_hook;
7292 define_custom_variable(&var->gen);
7296 DefineCustomRealVariable(const char *name,
7297 const char *short_desc,
7298 const char *long_desc,
7305 GucRealCheckHook check_hook,
7306 GucRealAssignHook assign_hook,
7307 GucShowHook show_hook)
7309 struct config_real *var;
7311 var = (struct config_real *)
7312 init_custom_variable(name, short_desc, long_desc, context, flags,
7313 PGC_REAL, sizeof(struct config_real));
7314 var->variable = valueAddr;
7315 var->boot_val = bootValue;
7316 var->reset_val = bootValue;
7317 var->min = minValue;
7318 var->max = maxValue;
7319 var->check_hook = check_hook;
7320 var->assign_hook = assign_hook;
7321 var->show_hook = show_hook;
7322 define_custom_variable(&var->gen);
7326 DefineCustomStringVariable(const char *name,
7327 const char *short_desc,
7328 const char *long_desc,
7330 const char *bootValue,
7333 GucStringCheckHook check_hook,
7334 GucStringAssignHook assign_hook,
7335 GucShowHook show_hook)
7337 struct config_string *var;
7339 var = (struct config_string *)
7340 init_custom_variable(name, short_desc, long_desc, context, flags,
7341 PGC_STRING, sizeof(struct config_string));
7342 var->variable = valueAddr;
7343 var->boot_val = bootValue;
7344 var->check_hook = check_hook;
7345 var->assign_hook = assign_hook;
7346 var->show_hook = show_hook;
7347 define_custom_variable(&var->gen);
7351 DefineCustomEnumVariable(const char *name,
7352 const char *short_desc,
7353 const char *long_desc,
7356 const struct config_enum_entry * options,
7359 GucEnumCheckHook check_hook,
7360 GucEnumAssignHook assign_hook,
7361 GucShowHook show_hook)
7363 struct config_enum *var;
7365 var = (struct config_enum *)
7366 init_custom_variable(name, short_desc, long_desc, context, flags,
7367 PGC_ENUM, sizeof(struct config_enum));
7368 var->variable = valueAddr;
7369 var->boot_val = bootValue;
7370 var->reset_val = bootValue;
7371 var->options = options;
7372 var->check_hook = check_hook;
7373 var->assign_hook = assign_hook;
7374 var->show_hook = show_hook;
7375 define_custom_variable(&var->gen);
7379 EmitWarningsOnPlaceholders(const char *className)
7381 int classLen = strlen(className);
7384 for (i = 0; i < num_guc_variables; i++)
7386 struct config_generic *var = guc_variables[i];
7388 if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
7389 strncmp(className, var->name, classLen) == 0 &&
7390 var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
7393 (errcode(ERRCODE_UNDEFINED_OBJECT),
7394 errmsg("unrecognized configuration parameter \"%s\"",
7405 GetPGVariable(const char *name, DestReceiver *dest)
7407 if (guc_name_compare(name, "all") == 0)
7408 ShowAllGUCConfig(dest);
7410 ShowGUCConfigOption(name, dest);
7414 GetPGVariableResultDesc(const char *name)
7418 if (guc_name_compare(name, "all") == 0)
7420 /* need a tuple descriptor representing three TEXT columns */
7421 tupdesc = CreateTemplateTupleDesc(3, false);
7422 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
7424 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
7426 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
7431 const char *varname;
7433 /* Get the canonical spelling of name */
7434 (void) GetConfigOptionByName(name, &varname);
7436 /* need a tuple descriptor representing a single TEXT column */
7437 tupdesc = CreateTemplateTupleDesc(1, false);
7438 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
7449 ShowGUCConfigOption(const char *name, DestReceiver *dest)
7451 TupOutputState *tstate;
7453 const char *varname;
7456 /* Get the value and canonical spelling of name */
7457 value = GetConfigOptionByName(name, &varname);
7459 /* need a tuple descriptor representing a single TEXT column */
7460 tupdesc = CreateTemplateTupleDesc(1, false);
7461 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
7464 /* prepare for projection of tuples */
7465 tstate = begin_tup_output_tupdesc(dest, tupdesc);
7468 do_text_output_oneline(tstate, value);
7470 end_tup_output(tstate);
7477 ShowAllGUCConfig(DestReceiver *dest)
7479 bool am_superuser = superuser();
7481 TupOutputState *tstate;
7484 bool isnull[3] = {false, false, false};
7486 /* need a tuple descriptor representing three TEXT columns */
7487 tupdesc = CreateTemplateTupleDesc(3, false);
7488 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
7490 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
7492 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
7495 /* prepare for projection of tuples */
7496 tstate = begin_tup_output_tupdesc(dest, tupdesc);
7498 for (i = 0; i < num_guc_variables; i++)
7500 struct config_generic *conf = guc_variables[i];
7503 if ((conf->flags & GUC_NO_SHOW_ALL) ||
7504 ((conf->flags & GUC_SUPERUSER_ONLY) && !am_superuser))
7507 /* assign to the values array */
7508 values[0] = PointerGetDatum(cstring_to_text(conf->name));
7510 setting = _ShowOption(conf, true);
7513 values[1] = PointerGetDatum(cstring_to_text(setting));
7518 values[1] = PointerGetDatum(NULL);
7522 values[2] = PointerGetDatum(cstring_to_text(conf->short_desc));
7524 /* send it to dest */
7525 do_tup_output(tstate, values, isnull);
7528 pfree(DatumGetPointer(values[0]));
7532 pfree(DatumGetPointer(values[1]));
7534 pfree(DatumGetPointer(values[2]));
7537 end_tup_output(tstate);
7541 * Return GUC variable value by name; optionally return canonical
7542 * form of name. Return value is palloc'd.
7545 GetConfigOptionByName(const char *name, const char **varname)
7547 struct config_generic *record;
7549 record = find_option(name, false, ERROR);
7552 (errcode(ERRCODE_UNDEFINED_OBJECT),
7553 errmsg("unrecognized configuration parameter \"%s\"", name)));
7554 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
7556 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7557 errmsg("must be superuser to examine \"%s\"", name)));
7560 *varname = record->name;
7562 return _ShowOption(record, true);
7566 * Return GUC variable value by variable number; optionally return canonical
7567 * form of name. Return value is palloc'd.
7570 GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
7573 struct config_generic *conf;
7575 /* check requested variable number valid */
7576 Assert((varnum >= 0) && (varnum < num_guc_variables));
7578 conf = guc_variables[varnum];
7582 if ((conf->flags & GUC_NO_SHOW_ALL) ||
7583 ((conf->flags & GUC_SUPERUSER_ONLY) && !superuser()))
7589 /* first get the generic attributes */
7592 values[0] = conf->name;
7594 /* setting : use _ShowOption in order to avoid duplicating the logic */
7595 values[1] = _ShowOption(conf, false);
7598 if (conf->vartype == PGC_INT)
7602 switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
7607 case GUC_UNIT_BLOCKS:
7608 snprintf(buf, sizeof(buf), "%dkB", BLCKSZ / 1024);
7611 case GUC_UNIT_XBLOCKS:
7612 snprintf(buf, sizeof(buf), "%dkB", XLOG_BLCKSZ / 1024);
7633 values[3] = config_group_names[conf->group];
7636 values[4] = conf->short_desc;
7639 values[5] = conf->long_desc;
7642 values[6] = GucContext_Names[conf->context];
7645 values[7] = config_type_names[conf->vartype];
7648 values[8] = GucSource_Names[conf->source];
7650 /* now get the type specifc attributes */
7651 switch (conf->vartype)
7655 struct config_bool *lconf = (struct config_bool *) conf;
7667 values[12] = pstrdup(lconf->boot_val ? "on" : "off");
7670 values[13] = pstrdup(lconf->reset_val ? "on" : "off");
7676 struct config_int *lconf = (struct config_int *) conf;
7679 snprintf(buffer, sizeof(buffer), "%d", lconf->min);
7680 values[9] = pstrdup(buffer);
7683 snprintf(buffer, sizeof(buffer), "%d", lconf->max);
7684 values[10] = pstrdup(buffer);
7690 snprintf(buffer, sizeof(buffer), "%d", lconf->boot_val);
7691 values[12] = pstrdup(buffer);
7694 snprintf(buffer, sizeof(buffer), "%d", lconf->reset_val);
7695 values[13] = pstrdup(buffer);
7701 struct config_real *lconf = (struct config_real *) conf;
7704 snprintf(buffer, sizeof(buffer), "%g", lconf->min);
7705 values[9] = pstrdup(buffer);
7708 snprintf(buffer, sizeof(buffer), "%g", lconf->max);
7709 values[10] = pstrdup(buffer);
7715 snprintf(buffer, sizeof(buffer), "%g", lconf->boot_val);
7716 values[12] = pstrdup(buffer);
7719 snprintf(buffer, sizeof(buffer), "%g", lconf->reset_val);
7720 values[13] = pstrdup(buffer);
7726 struct config_string *lconf = (struct config_string *) conf;
7738 if (lconf->boot_val == NULL)
7741 values[12] = pstrdup(lconf->boot_val);
7744 if (lconf->reset_val == NULL)
7747 values[13] = pstrdup(lconf->reset_val);
7753 struct config_enum *lconf = (struct config_enum *) conf;
7764 * NOTE! enumvals with double quotes in them are not
7767 values[11] = config_enum_get_options((struct config_enum *) conf,
7768 "{\"", "\"}", "\",\"");
7771 values[12] = pstrdup(config_enum_lookup_by_value(lconf,
7775 values[13] = pstrdup(config_enum_lookup_by_value(lconf,
7783 * should never get here, but in case we do, set 'em to NULL
7805 * If the setting came from a config file, set the source location. For
7806 * security reasons, we don't show source file/line number for
7809 if (conf->source == PGC_S_FILE && superuser())
7811 values[14] = conf->sourcefile;
7812 snprintf(buffer, sizeof(buffer), "%d", conf->sourceline);
7813 values[15] = pstrdup(buffer);
7823 * Return the total number of GUC variables
7826 GetNumConfigOptions(void)
7828 return num_guc_variables;
7832 * show_config_by_name - equiv to SHOW X command but implemented as
7836 show_config_by_name(PG_FUNCTION_ARGS)
7841 /* Get the GUC variable name */
7842 varname = TextDatumGetCString(PG_GETARG_DATUM(0));
7845 varval = GetConfigOptionByName(varname, NULL);
7847 /* Convert to text */
7848 PG_RETURN_TEXT_P(cstring_to_text(varval));
7852 * show_all_settings - equiv to SHOW ALL command but implemented as
7855 #define NUM_PG_SETTINGS_ATTS 16
7858 show_all_settings(PG_FUNCTION_ARGS)
7860 FuncCallContext *funcctx;
7864 AttInMetadata *attinmeta;
7865 MemoryContext oldcontext;
7867 /* stuff done only on the first call of the function */
7868 if (SRF_IS_FIRSTCALL())
7870 /* create a function context for cross-call persistence */
7871 funcctx = SRF_FIRSTCALL_INIT();
7874 * switch to memory context appropriate for multiple function calls
7876 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
7879 * need a tuple descriptor representing NUM_PG_SETTINGS_ATTS columns
7880 * of the appropriate types
7882 tupdesc = CreateTemplateTupleDesc(NUM_PG_SETTINGS_ATTS, false);
7883 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
7885 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
7887 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "unit",
7889 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "category",
7891 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "short_desc",
7893 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "extra_desc",
7895 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "context",
7897 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "vartype",
7899 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "source",
7901 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "min_val",
7903 TupleDescInitEntry(tupdesc, (AttrNumber) 11, "max_val",
7905 TupleDescInitEntry(tupdesc, (AttrNumber) 12, "enumvals",
7906 TEXTARRAYOID, -1, 0);
7907 TupleDescInitEntry(tupdesc, (AttrNumber) 13, "boot_val",
7909 TupleDescInitEntry(tupdesc, (AttrNumber) 14, "reset_val",
7911 TupleDescInitEntry(tupdesc, (AttrNumber) 15, "sourcefile",
7913 TupleDescInitEntry(tupdesc, (AttrNumber) 16, "sourceline",
7917 * Generate attribute metadata needed later to produce tuples from raw
7920 attinmeta = TupleDescGetAttInMetadata(tupdesc);
7921 funcctx->attinmeta = attinmeta;
7923 /* total number of tuples to be returned */
7924 funcctx->max_calls = GetNumConfigOptions();
7926 MemoryContextSwitchTo(oldcontext);
7929 /* stuff done on every call of the function */
7930 funcctx = SRF_PERCALL_SETUP();
7932 call_cntr = funcctx->call_cntr;
7933 max_calls = funcctx->max_calls;
7934 attinmeta = funcctx->attinmeta;
7936 if (call_cntr < max_calls) /* do when there is more left to send */
7938 char *values[NUM_PG_SETTINGS_ATTS];
7944 * Get the next visible GUC variable name and value
7948 GetConfigOptionByNum(call_cntr, (const char **) values, &noshow);
7951 /* bump the counter and get the next config setting */
7952 call_cntr = ++funcctx->call_cntr;
7954 /* make sure we haven't gone too far now */
7955 if (call_cntr >= max_calls)
7956 SRF_RETURN_DONE(funcctx);
7961 tuple = BuildTupleFromCStrings(attinmeta, values);
7963 /* make the tuple into a datum */
7964 result = HeapTupleGetDatum(tuple);
7966 SRF_RETURN_NEXT(funcctx, result);
7970 /* do when there is no more left */
7971 SRF_RETURN_DONE(funcctx);
7976 _ShowOption(struct config_generic * record, bool use_units)
7981 switch (record->vartype)
7985 struct config_bool *conf = (struct config_bool *) record;
7987 if (conf->show_hook)
7988 val = (*conf->show_hook) ();
7990 val = *conf->variable ? "on" : "off";
7996 struct config_int *conf = (struct config_int *) record;
7998 if (conf->show_hook)
7999 val = (*conf->show_hook) ();
8003 * Use int64 arithmetic to avoid overflows in units
8006 int64 result = *conf->variable;
8009 if (use_units && result > 0 &&
8010 (record->flags & GUC_UNIT_MEMORY))
8012 switch (record->flags & GUC_UNIT_MEMORY)
8014 case GUC_UNIT_BLOCKS:
8015 result *= BLCKSZ / 1024;
8017 case GUC_UNIT_XBLOCKS:
8018 result *= XLOG_BLCKSZ / 1024;
8022 if (result % KB_PER_TB == 0)
8024 result /= KB_PER_TB;
8027 else if (result % KB_PER_GB == 0)
8029 result /= KB_PER_GB;
8032 else if (result % KB_PER_MB == 0)
8034 result /= KB_PER_MB;
8042 else if (use_units && result > 0 &&
8043 (record->flags & GUC_UNIT_TIME))
8045 switch (record->flags & GUC_UNIT_TIME)
8051 result *= MS_PER_MIN;
8055 if (result % MS_PER_D == 0)
8060 else if (result % MS_PER_H == 0)
8065 else if (result % MS_PER_MIN == 0)
8067 result /= MS_PER_MIN;
8070 else if (result % MS_PER_S == 0)
8083 snprintf(buffer, sizeof(buffer), INT64_FORMAT "%s",
8092 struct config_real *conf = (struct config_real *) record;
8094 if (conf->show_hook)
8095 val = (*conf->show_hook) ();
8098 snprintf(buffer, sizeof(buffer), "%g",
8107 struct config_string *conf = (struct config_string *) record;
8109 if (conf->show_hook)
8110 val = (*conf->show_hook) ();
8111 else if (*conf->variable && **conf->variable)
8112 val = *conf->variable;
8120 struct config_enum *conf = (struct config_enum *) record;
8122 if (conf->show_hook)
8123 val = (*conf->show_hook) ();
8125 val = config_enum_lookup_by_value(conf, *conf->variable);
8130 /* just to keep compiler quiet */
8135 return pstrdup(val);
8142 * These routines dump out all non-default GUC options into a binary
8143 * file that is read by all exec'ed backends. The format is:
8145 * variable name, string, null terminated
8146 * variable value, string, null terminated
8147 * variable sourcefile, string, null terminated (empty if none)
8148 * variable sourceline, integer
8149 * variable source, integer
8150 * variable scontext, integer
8153 write_one_nondefault_variable(FILE *fp, struct config_generic * gconf)
8155 if (gconf->source == PGC_S_DEFAULT)
8158 fprintf(fp, "%s", gconf->name);
8161 switch (gconf->vartype)
8165 struct config_bool *conf = (struct config_bool *) gconf;
8167 if (*conf->variable)
8168 fprintf(fp, "true");
8170 fprintf(fp, "false");
8176 struct config_int *conf = (struct config_int *) gconf;
8178 fprintf(fp, "%d", *conf->variable);
8184 struct config_real *conf = (struct config_real *) gconf;
8186 fprintf(fp, "%.17g", *conf->variable);
8192 struct config_string *conf = (struct config_string *) gconf;
8194 fprintf(fp, "%s", *conf->variable);
8200 struct config_enum *conf = (struct config_enum *) gconf;
8203 config_enum_lookup_by_value(conf, *conf->variable));
8210 if (gconf->sourcefile)
8211 fprintf(fp, "%s", gconf->sourcefile);
8214 fwrite(&gconf->sourceline, 1, sizeof(gconf->sourceline), fp);
8215 fwrite(&gconf->source, 1, sizeof(gconf->source), fp);
8216 fwrite(&gconf->scontext, 1, sizeof(gconf->scontext), fp);
8220 write_nondefault_variables(GucContext context)
8226 Assert(context == PGC_POSTMASTER || context == PGC_SIGHUP);
8228 elevel = (context == PGC_SIGHUP) ? LOG : ERROR;
8233 fp = AllocateFile(CONFIG_EXEC_PARAMS_NEW, "w");
8237 (errcode_for_file_access(),
8238 errmsg("could not write to file \"%s\": %m",
8239 CONFIG_EXEC_PARAMS_NEW)));
8243 for (i = 0; i < num_guc_variables; i++)
8245 write_one_nondefault_variable(fp, guc_variables[i]);
8251 (errcode_for_file_access(),
8252 errmsg("could not write to file \"%s\": %m",
8253 CONFIG_EXEC_PARAMS_NEW)));
8258 * Put new file in place. This could delay on Win32, but we don't hold
8259 * any exclusive locks.
8261 rename(CONFIG_EXEC_PARAMS_NEW, CONFIG_EXEC_PARAMS);
8266 * Read string, including null byte from file
8268 * Return NULL on EOF and nothing read
8271 read_string_with_null(FILE *fp)
8280 if ((ch = fgetc(fp)) == EOF)
8285 elog(FATAL, "invalid format of exec config params file");
8288 str = guc_malloc(FATAL, maxlen);
8289 else if (i == maxlen)
8290 str = guc_realloc(FATAL, str, maxlen *= 2);
8299 * This routine loads a previous postmaster dump of its non-default
8303 read_nondefault_variables(void)
8310 GucSource varsource;
8311 GucContext varscontext;
8316 fp = AllocateFile(CONFIG_EXEC_PARAMS, "r");
8319 /* File not found is fine */
8320 if (errno != ENOENT)
8322 (errcode_for_file_access(),
8323 errmsg("could not read from file \"%s\": %m",
8324 CONFIG_EXEC_PARAMS)));
8330 struct config_generic *record;
8332 if ((varname = read_string_with_null(fp)) == NULL)
8335 if ((record = find_option(varname, true, FATAL)) == NULL)
8336 elog(FATAL, "failed to locate variable \"%s\" in exec config params file", varname);
8338 if ((varvalue = read_string_with_null(fp)) == NULL)
8339 elog(FATAL, "invalid format of exec config params file");
8340 if ((varsourcefile = read_string_with_null(fp)) == NULL)
8341 elog(FATAL, "invalid format of exec config params file");
8342 if (fread(&varsourceline, 1, sizeof(varsourceline), fp) != sizeof(varsourceline))
8343 elog(FATAL, "invalid format of exec config params file");
8344 if (fread(&varsource, 1, sizeof(varsource), fp) != sizeof(varsource))
8345 elog(FATAL, "invalid format of exec config params file");
8346 if (fread(&varscontext, 1, sizeof(varscontext), fp) != sizeof(varscontext))
8347 elog(FATAL, "invalid format of exec config params file");
8349 (void) set_config_option(varname, varvalue,
8350 varscontext, varsource,
8351 GUC_ACTION_SET, true, 0);
8352 if (varsourcefile[0])
8353 set_config_sourcefile(varname, varsourcefile, varsourceline);
8357 free(varsourcefile);
8362 #endif /* EXEC_BACKEND */
8366 * A little "long argument" simulation, although not quite GNU
8367 * compliant. Takes a string of the form "some-option=some value" and
8368 * returns name = "some_option" and value = "some value" in malloc'ed
8369 * storage. Note that '-' is converted to '_' in the option name. If
8370 * there is no '=' in the input string then value will be NULL.
8373 ParseLongOption(const char *string, char **name, char **value)
8382 equal_pos = strcspn(string, "=");
8384 if (string[equal_pos] == '=')
8386 *name = guc_malloc(FATAL, equal_pos + 1);
8387 strlcpy(*name, string, equal_pos + 1);
8389 *value = guc_strdup(FATAL, &string[equal_pos + 1]);
8393 /* no equal sign in string */
8394 *name = guc_strdup(FATAL, string);
8398 for (cp = *name; *cp; cp++)
8405 * Handle options fetched from pg_db_role_setting.setconfig,
8406 * pg_proc.proconfig, etc. Caller must specify proper context/source/action.
8408 * The array parameter must be an array of TEXT (it must not be NULL).
8411 ProcessGUCArray(ArrayType *array,
8412 GucContext context, GucSource source, GucAction action)
8416 Assert(array != NULL);
8417 Assert(ARR_ELEMTYPE(array) == TEXTOID);
8418 Assert(ARR_NDIM(array) == 1);
8419 Assert(ARR_LBOUND(array)[0] == 1);
8421 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
8429 d = array_ref(array, 1, &i,
8430 -1 /* varlenarray */ ,
8431 -1 /* TEXT's typlen */ ,
8432 false /* TEXT's typbyval */ ,
8433 'i' /* TEXT's typalign */ ,
8439 s = TextDatumGetCString(d);
8441 ParseLongOption(s, &name, &value);
8445 (errcode(ERRCODE_SYNTAX_ERROR),
8446 errmsg("could not parse setting for parameter \"%s\"",
8452 (void) set_config_option(name, value,
8465 * Add an entry to an option array. The array parameter may be NULL
8466 * to indicate the current table entry is NULL.
8469 GUCArrayAdd(ArrayType *array, const char *name, const char *value)
8471 struct config_generic *record;
8479 /* test if the option is valid and we're allowed to set it */
8480 (void) validate_option_array_item(name, value, false);
8482 /* normalize name (converts obsolete GUC names to modern spellings) */
8483 record = find_option(name, false, WARNING);
8485 name = record->name;
8487 /* build new item for array */
8488 newval = psprintf("%s=%s", name, value);
8489 datum = CStringGetTextDatum(newval);
8497 Assert(ARR_ELEMTYPE(array) == TEXTOID);
8498 Assert(ARR_NDIM(array) == 1);
8499 Assert(ARR_LBOUND(array)[0] == 1);
8501 index = ARR_DIMS(array)[0] + 1; /* add after end */
8503 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
8508 d = array_ref(array, 1, &i,
8509 -1 /* varlenarray */ ,
8510 -1 /* TEXT's typlen */ ,
8511 false /* TEXT's typbyval */ ,
8512 'i' /* TEXT's typalign */ ,
8516 current = TextDatumGetCString(d);
8518 /* check for match up through and including '=' */
8519 if (strncmp(current, newval, strlen(name) + 1) == 0)
8526 a = array_set(array, 1, &index,
8529 -1 /* varlena array */ ,
8530 -1 /* TEXT's typlen */ ,
8531 false /* TEXT's typbyval */ ,
8532 'i' /* TEXT's typalign */ );
8535 a = construct_array(&datum, 1,
8544 * Delete an entry from an option array. The array parameter may be NULL
8545 * to indicate the current table entry is NULL. Also, if the return value
8546 * is NULL then a null should be stored.
8549 GUCArrayDelete(ArrayType *array, const char *name)
8551 struct config_generic *record;
8552 ArrayType *newarray;
8558 /* test if the option is valid and we're allowed to set it */
8559 (void) validate_option_array_item(name, NULL, false);
8561 /* normalize name (converts obsolete GUC names to modern spellings) */
8562 record = find_option(name, false, WARNING);
8564 name = record->name;
8566 /* if array is currently null, then surely nothing to delete */
8573 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
8579 d = array_ref(array, 1, &i,
8580 -1 /* varlenarray */ ,
8581 -1 /* TEXT's typlen */ ,
8582 false /* TEXT's typbyval */ ,
8583 'i' /* TEXT's typalign */ ,
8587 val = TextDatumGetCString(d);
8589 /* ignore entry if it's what we want to delete */
8590 if (strncmp(val, name, strlen(name)) == 0
8591 && val[strlen(name)] == '=')
8594 /* else add it to the output array */
8596 newarray = array_set(newarray, 1, &index,
8599 -1 /* varlenarray */ ,
8600 -1 /* TEXT's typlen */ ,
8601 false /* TEXT's typbyval */ ,
8602 'i' /* TEXT's typalign */ );
8604 newarray = construct_array(&d, 1,
8616 * Given a GUC array, delete all settings from it that our permission
8617 * level allows: if superuser, delete them all; if regular user, only
8618 * those that are PGC_USERSET
8621 GUCArrayReset(ArrayType *array)
8623 ArrayType *newarray;
8627 /* if array is currently null, nothing to do */
8631 /* if we're superuser, we can delete everything, so just do it */
8638 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
8645 d = array_ref(array, 1, &i,
8646 -1 /* varlenarray */ ,
8647 -1 /* TEXT's typlen */ ,
8648 false /* TEXT's typbyval */ ,
8649 'i' /* TEXT's typalign */ ,
8653 val = TextDatumGetCString(d);
8655 eqsgn = strchr(val, '=');
8658 /* skip if we have permission to delete it */
8659 if (validate_option_array_item(val, NULL, true))
8662 /* else add it to the output array */
8664 newarray = array_set(newarray, 1, &index,
8667 -1 /* varlenarray */ ,
8668 -1 /* TEXT's typlen */ ,
8669 false /* TEXT's typbyval */ ,
8670 'i' /* TEXT's typalign */ );
8672 newarray = construct_array(&d, 1,
8684 * Validate a proposed option setting for GUCArrayAdd/Delete/Reset.
8686 * name is the option name. value is the proposed value for the Add case,
8687 * or NULL for the Delete/Reset cases. If skipIfNoPermissions is true, it's
8688 * not an error to have no permissions to set the option.
8690 * Returns TRUE if OK, FALSE if skipIfNoPermissions is true and user does not
8691 * have permission to change this option (all other error cases result in an
8692 * error being thrown).
8695 validate_option_array_item(const char *name, const char *value,
8696 bool skipIfNoPermissions)
8699 struct config_generic *gconf;
8702 * There are three cases to consider:
8704 * name is a known GUC variable. Check the value normally, check
8705 * permissions normally (ie, allow if variable is USERSET, or if it's
8706 * SUSET and user is superuser).
8708 * name is not known, but exists or can be created as a placeholder (i.e.,
8709 * it has a prefixed name). We allow this case if you're a superuser,
8710 * otherwise not. Superusers are assumed to know what they're doing. We
8711 * can't allow it for other users, because when the placeholder is
8712 * resolved it might turn out to be a SUSET variable;
8713 * define_custom_variable assumes we checked that.
8715 * name is not known and can't be created as a placeholder. Throw error,
8716 * unless skipIfNoPermissions is true, in which case return FALSE.
8718 gconf = find_option(name, true, WARNING);
8721 /* not known, failed to make a placeholder */
8722 if (skipIfNoPermissions)
8725 (errcode(ERRCODE_UNDEFINED_OBJECT),
8726 errmsg("unrecognized configuration parameter \"%s\"",
8730 if (gconf->flags & GUC_CUSTOM_PLACEHOLDER)
8733 * We cannot do any meaningful check on the value, so only permissions
8734 * are useful to check.
8738 if (skipIfNoPermissions)
8741 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
8742 errmsg("permission denied to set parameter \"%s\"", name)));
8745 /* manual permissions check so we can avoid an error being thrown */
8746 if (gconf->context == PGC_USERSET)
8748 else if (gconf->context == PGC_SUSET && superuser())
8750 else if (skipIfNoPermissions)
8752 /* if a permissions error should be thrown, let set_config_option do it */
8754 /* test for permissions and valid option value */
8755 (void) set_config_option(name, value,
8756 superuser() ? PGC_SUSET : PGC_USERSET,
8757 PGC_S_TEST, GUC_ACTION_SET, false, 0);
8764 * Called by check_hooks that want to override the normal
8765 * ERRCODE_INVALID_PARAMETER_VALUE SQLSTATE for check hook failures.
8767 * Note that GUC_check_errmsg() etc are just macros that result in a direct
8768 * assignment to the associated variables. That is ugly, but forced by the
8769 * limitations of C's macro mechanisms.
8772 GUC_check_errcode(int sqlerrcode)
8774 GUC_check_errcode_value = sqlerrcode;
8779 * Convenience functions to manage calling a variable's check_hook.
8780 * These mostly take care of the protocol for letting check hooks supply
8781 * portions of the error report on failure.
8785 call_bool_check_hook(struct config_bool * conf, bool *newval, void **extra,
8786 GucSource source, int elevel)
8788 /* Quick success if no hook */
8789 if (!conf->check_hook)
8792 /* Reset variables that might be set by hook */
8793 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8794 GUC_check_errmsg_string = NULL;
8795 GUC_check_errdetail_string = NULL;
8796 GUC_check_errhint_string = NULL;
8798 if (!(*conf->check_hook) (newval, extra, source))
8801 (errcode(GUC_check_errcode_value),
8802 GUC_check_errmsg_string ?
8803 errmsg_internal("%s", GUC_check_errmsg_string) :
8804 errmsg("invalid value for parameter \"%s\": %d",
8805 conf->gen.name, (int) *newval),
8806 GUC_check_errdetail_string ?
8807 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
8808 GUC_check_errhint_string ?
8809 errhint("%s", GUC_check_errhint_string) : 0));
8810 /* Flush any strings created in ErrorContext */
8819 call_int_check_hook(struct config_int * conf, int *newval, void **extra,
8820 GucSource source, int elevel)
8822 /* Quick success if no hook */
8823 if (!conf->check_hook)
8826 /* Reset variables that might be set by hook */
8827 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8828 GUC_check_errmsg_string = NULL;
8829 GUC_check_errdetail_string = NULL;
8830 GUC_check_errhint_string = NULL;
8832 if (!(*conf->check_hook) (newval, extra, source))
8835 (errcode(GUC_check_errcode_value),
8836 GUC_check_errmsg_string ?
8837 errmsg_internal("%s", GUC_check_errmsg_string) :
8838 errmsg("invalid value for parameter \"%s\": %d",
8839 conf->gen.name, *newval),
8840 GUC_check_errdetail_string ?
8841 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
8842 GUC_check_errhint_string ?
8843 errhint("%s", GUC_check_errhint_string) : 0));
8844 /* Flush any strings created in ErrorContext */
8853 call_real_check_hook(struct config_real * conf, double *newval, void **extra,
8854 GucSource source, int elevel)
8856 /* Quick success if no hook */
8857 if (!conf->check_hook)
8860 /* Reset variables that might be set by hook */
8861 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8862 GUC_check_errmsg_string = NULL;
8863 GUC_check_errdetail_string = NULL;
8864 GUC_check_errhint_string = NULL;
8866 if (!(*conf->check_hook) (newval, extra, source))
8869 (errcode(GUC_check_errcode_value),
8870 GUC_check_errmsg_string ?
8871 errmsg_internal("%s", GUC_check_errmsg_string) :
8872 errmsg("invalid value for parameter \"%s\": %g",
8873 conf->gen.name, *newval),
8874 GUC_check_errdetail_string ?
8875 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
8876 GUC_check_errhint_string ?
8877 errhint("%s", GUC_check_errhint_string) : 0));
8878 /* Flush any strings created in ErrorContext */
8887 call_string_check_hook(struct config_string * conf, char **newval, void **extra,
8888 GucSource source, int elevel)
8890 /* Quick success if no hook */
8891 if (!conf->check_hook)
8894 /* Reset variables that might be set by hook */
8895 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8896 GUC_check_errmsg_string = NULL;
8897 GUC_check_errdetail_string = NULL;
8898 GUC_check_errhint_string = NULL;
8900 if (!(*conf->check_hook) (newval, extra, source))
8903 (errcode(GUC_check_errcode_value),
8904 GUC_check_errmsg_string ?
8905 errmsg_internal("%s", GUC_check_errmsg_string) :
8906 errmsg("invalid value for parameter \"%s\": \"%s\"",
8907 conf->gen.name, *newval ? *newval : ""),
8908 GUC_check_errdetail_string ?
8909 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
8910 GUC_check_errhint_string ?
8911 errhint("%s", GUC_check_errhint_string) : 0));
8912 /* Flush any strings created in ErrorContext */
8921 call_enum_check_hook(struct config_enum * conf, int *newval, void **extra,
8922 GucSource source, int elevel)
8924 /* Quick success if no hook */
8925 if (!conf->check_hook)
8928 /* Reset variables that might be set by hook */
8929 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8930 GUC_check_errmsg_string = NULL;
8931 GUC_check_errdetail_string = NULL;
8932 GUC_check_errhint_string = NULL;
8934 if (!(*conf->check_hook) (newval, extra, source))
8937 (errcode(GUC_check_errcode_value),
8938 GUC_check_errmsg_string ?
8939 errmsg_internal("%s", GUC_check_errmsg_string) :
8940 errmsg("invalid value for parameter \"%s\": \"%s\"",
8942 config_enum_lookup_by_value(conf, *newval)),
8943 GUC_check_errdetail_string ?
8944 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
8945 GUC_check_errhint_string ?
8946 errhint("%s", GUC_check_errhint_string) : 0));
8947 /* Flush any strings created in ErrorContext */
8957 * check_hook, assign_hook and show_hook subroutines
8961 check_log_destination(char **newval, void **extra, GucSource source)
8969 /* Need a modifiable copy of string */
8970 rawstring = pstrdup(*newval);
8972 /* Parse string into list of identifiers */
8973 if (!SplitIdentifierString(rawstring, ',', &elemlist))
8975 /* syntax error in list */
8976 GUC_check_errdetail("List syntax is invalid.");
8978 list_free(elemlist);
8982 foreach(l, elemlist)
8984 char *tok = (char *) lfirst(l);
8986 if (pg_strcasecmp(tok, "stderr") == 0)
8987 newlogdest |= LOG_DESTINATION_STDERR;
8988 else if (pg_strcasecmp(tok, "csvlog") == 0)
8989 newlogdest |= LOG_DESTINATION_CSVLOG;
8991 else if (pg_strcasecmp(tok, "syslog") == 0)
8992 newlogdest |= LOG_DESTINATION_SYSLOG;
8995 else if (pg_strcasecmp(tok, "eventlog") == 0)
8996 newlogdest |= LOG_DESTINATION_EVENTLOG;
9000 GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
9002 list_free(elemlist);
9008 list_free(elemlist);
9010 myextra = (int *) guc_malloc(ERROR, sizeof(int));
9011 *myextra = newlogdest;
9012 *extra = (void *) myextra;
9018 assign_log_destination(const char *newval, void *extra)
9020 Log_destination = *((int *) extra);
9024 assign_syslog_facility(int newval, void *extra)
9027 set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
9030 /* Without syslog support, just ignore it */
9034 assign_syslog_ident(const char *newval, void *extra)
9037 set_syslog_parameters(newval, syslog_facility);
9039 /* Without syslog support, it will always be set to "none", so ignore */
9044 assign_session_replication_role(int newval, void *extra)
9047 * Must flush the plan cache when changing replication role; but don't
9048 * flush unnecessarily.
9050 if (SessionReplicationRole != newval)
9055 check_temp_buffers(int *newval, void **extra, GucSource source)
9058 * Once local buffers have been initialized, it's too late to change this.
9060 if (NLocBuffer && NLocBuffer != *newval)
9062 GUC_check_errdetail("\"temp_buffers\" cannot be changed after any temporary tables have been accessed in the session.");
9069 check_phony_autocommit(bool *newval, void **extra, GucSource source)
9073 GUC_check_errcode(ERRCODE_FEATURE_NOT_SUPPORTED);
9074 GUC_check_errmsg("SET AUTOCOMMIT TO OFF is no longer supported");
9081 check_debug_assertions(bool *newval, void **extra, GucSource source)
9083 #ifndef USE_ASSERT_CHECKING
9086 GUC_check_errmsg("assertion checking is not supported by this build");
9094 check_bonjour(bool *newval, void **extra, GucSource source)
9099 GUC_check_errmsg("Bonjour is not supported by this build");
9107 check_ssl(bool *newval, void **extra, GucSource source)
9112 GUC_check_errmsg("SSL is not supported by this build");
9120 check_stage_log_stats(bool *newval, void **extra, GucSource source)
9122 if (*newval && log_statement_stats)
9124 GUC_check_errdetail("Cannot enable parameter when \"log_statement_stats\" is true.");
9131 check_log_stats(bool *newval, void **extra, GucSource source)
9134 (log_parser_stats || log_planner_stats || log_executor_stats))
9136 GUC_check_errdetail("Cannot enable \"log_statement_stats\" when "
9137 "\"log_parser_stats\", \"log_planner_stats\", "
9138 "or \"log_executor_stats\" is true.");
9145 check_canonical_path(char **newval, void **extra, GucSource source)
9148 * Since canonicalize_path never enlarges the string, we can just modify
9149 * newval in-place. But watch out for NULL, which is the default value
9150 * for external_pid_file.
9153 canonicalize_path(*newval);
9158 check_timezone_abbreviations(char **newval, void **extra, GucSource source)
9161 * The boot_val given above for timezone_abbreviations is NULL. When we
9162 * see this we just do nothing. If this value isn't overridden from the
9163 * config file then pg_timezone_abbrev_initialize() will eventually
9164 * replace it with "Default". This hack has two purposes: to avoid
9165 * wasting cycles loading values that might soon be overridden from the
9166 * config file, and to avoid trying to read the timezone abbrev files
9167 * during InitializeGUCOptions(). The latter doesn't work in an
9168 * EXEC_BACKEND subprocess because my_exec_path hasn't been set yet and so
9169 * we can't locate PGSHAREDIR.
9171 if (*newval == NULL)
9173 Assert(source == PGC_S_DEFAULT);
9177 /* OK, load the file and produce a malloc'd TimeZoneAbbrevTable */
9178 *extra = load_tzoffsets(*newval);
9180 /* tzparser.c returns NULL on failure, reporting via GUC_check_errmsg */
9188 assign_timezone_abbreviations(const char *newval, void *extra)
9190 /* Do nothing for the boot_val default of NULL */
9194 InstallTimeZoneAbbrevs((TimeZoneAbbrevTable *) extra);
9198 * pg_timezone_abbrev_initialize --- set default value if not done already
9200 * This is called after initial loading of postgresql.conf. If no
9201 * timezone_abbreviations setting was found therein, select default.
9202 * If a non-default value is already installed, nothing will happen.
9204 * This can also be called from ProcessConfigFile to establish the default
9205 * value after a postgresql.conf entry for it is removed.
9208 pg_timezone_abbrev_initialize(void)
9210 SetConfigOption("timezone_abbreviations", "Default",
9211 PGC_POSTMASTER, PGC_S_DYNAMIC_DEFAULT);
9215 show_archive_command(void)
9217 if (XLogArchivingActive())
9218 return XLogArchiveCommand;
9220 return "(disabled)";
9224 assign_tcp_keepalives_idle(int newval, void *extra)
9227 * The kernel API provides no way to test a value without setting it; and
9228 * once we set it we might fail to unset it. So there seems little point
9229 * in fully implementing the check-then-assign GUC API for these
9230 * variables. Instead we just do the assignment on demand. pqcomm.c
9231 * reports any problems via elog(LOG).
9233 * This approach means that the GUC value might have little to do with the
9234 * actual kernel value, so we use a show_hook that retrieves the kernel
9235 * value rather than trusting GUC's copy.
9237 (void) pq_setkeepalivesidle(newval, MyProcPort);
9241 show_tcp_keepalives_idle(void)
9243 /* See comments in assign_tcp_keepalives_idle */
9244 static char nbuf[16];
9246 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesidle(MyProcPort));
9251 assign_tcp_keepalives_interval(int newval, void *extra)
9253 /* See comments in assign_tcp_keepalives_idle */
9254 (void) pq_setkeepalivesinterval(newval, MyProcPort);
9258 show_tcp_keepalives_interval(void)
9260 /* See comments in assign_tcp_keepalives_idle */
9261 static char nbuf[16];
9263 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesinterval(MyProcPort));
9268 assign_tcp_keepalives_count(int newval, void *extra)
9270 /* See comments in assign_tcp_keepalives_idle */
9271 (void) pq_setkeepalivescount(newval, MyProcPort);
9275 show_tcp_keepalives_count(void)
9277 /* See comments in assign_tcp_keepalives_idle */
9278 static char nbuf[16];
9280 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivescount(MyProcPort));
9285 check_maxconnections(int *newval, void **extra, GucSource source)
9287 if (*newval + autovacuum_max_workers + 1 +
9288 max_worker_processes > MAX_BACKENDS)
9294 check_autovacuum_max_workers(int *newval, void **extra, GucSource source)
9296 if (MaxConnections + *newval + 1 + max_worker_processes > MAX_BACKENDS)
9302 check_autovacuum_work_mem(int *newval, void **extra, GucSource source)
9305 * -1 indicates fallback.
9307 * If we haven't yet changed the boot_val default of -1, just let it be.
9308 * Autovacuum will look to maintenance_work_mem instead.
9314 * We clamp manually-set values to at least 1MB. Since
9315 * maintenance_work_mem is always set to at least this value, do the same
9325 check_max_worker_processes(int *newval, void **extra, GucSource source)
9327 if (MaxConnections + autovacuum_max_workers + 1 + *newval > MAX_BACKENDS)
9333 check_effective_io_concurrency(int *newval, void **extra, GucSource source)
9336 double new_prefetch_pages = 0.0;
9340 * The user-visible GUC parameter is the number of drives (spindles),
9341 * which we need to translate to a number-of-pages-to-prefetch target.
9342 * The target value is stashed in *extra and then assigned to the actual
9343 * variable by assign_effective_io_concurrency.
9345 * The expected number of prefetch pages needed to keep N drives busy is:
9347 * drives | I/O requests
9348 * -------+----------------
9351 * 3 | 3/1 + 3/2 + 3/3 = 5 1/2
9352 * 4 | 4/1 + 4/2 + 4/3 + 4/4 = 8 1/3
9355 * This is called the "coupon collector problem" and H(n) is called the
9356 * harmonic series. This could be approximated by n * ln(n), but for
9357 * reasonable numbers of drives we might as well just compute the series.
9359 * Alternatively we could set the target to the number of pages necessary
9360 * so that the expected number of active spindles is some arbitrary
9361 * percentage of the total. This sounds the same but is actually slightly
9362 * different. The result ends up being ln(1-P)/ln((n-1)/n) where P is
9363 * that desired fraction.
9365 * Experimental results show that both of these formulas aren't aggressive
9366 * enough, but we don't really have any better proposals.
9368 * Note that if *newval = 0 (disabled), we must set target = 0.
9372 for (i = 1; i <= *newval; i++)
9373 new_prefetch_pages += (double) *newval / (double) i;
9375 /* This range check shouldn't fail, but let's be paranoid */
9376 if (new_prefetch_pages >= 0.0 && new_prefetch_pages < (double) INT_MAX)
9378 int *myextra = (int *) guc_malloc(ERROR, sizeof(int));
9380 *myextra = (int) rint(new_prefetch_pages);
9381 *extra = (void *) myextra;
9389 #endif /* USE_PREFETCH */
9393 assign_effective_io_concurrency(int newval, void *extra)
9396 target_prefetch_pages = *((int *) extra);
9397 #endif /* USE_PREFETCH */
9401 assign_pgstat_temp_directory(const char *newval, void *extra)
9403 /* check_canonical_path already canonicalized newval for us */
9409 dname = guc_malloc(ERROR, strlen(newval) + 1); /* runtime dir */
9410 sprintf(dname, "%s", newval);
9413 tname = guc_malloc(ERROR, strlen(newval) + 12); /* /global.tmp */
9414 sprintf(tname, "%s/global.tmp", newval);
9415 fname = guc_malloc(ERROR, strlen(newval) + 13); /* /global.stat */
9416 sprintf(fname, "%s/global.stat", newval);
9418 if (pgstat_stat_directory)
9419 free(pgstat_stat_directory);
9420 pgstat_stat_directory = dname;
9421 if (pgstat_stat_tmpname)
9422 free(pgstat_stat_tmpname);
9423 pgstat_stat_tmpname = tname;
9424 if (pgstat_stat_filename)
9425 free(pgstat_stat_filename);
9426 pgstat_stat_filename = fname;
9430 check_application_name(char **newval, void **extra, GucSource source)
9432 /* Only allow clean ASCII chars in the application name */
9435 for (p = *newval; *p; p++)
9437 if (*p < 32 || *p > 126)
9445 assign_application_name(const char *newval, void *extra)
9447 /* Update the pg_stat_activity view */
9448 pgstat_report_appname(newval);
9452 show_unix_socket_permissions(void)
9456 snprintf(buf, sizeof(buf), "%04o", Unix_socket_permissions);
9461 show_log_file_mode(void)
9465 snprintf(buf, sizeof(buf), "%04o", Log_file_mode);
9469 #include "guc-file.c"