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_bonjour(bool *newval, void **extra, GucSource source);
178 static bool check_ssl(bool *newval, void **extra, GucSource source);
179 static bool check_stage_log_stats(bool *newval, void **extra, GucSource source);
180 static bool check_log_stats(bool *newval, void **extra, GucSource source);
181 static bool check_canonical_path(char **newval, void **extra, GucSource source);
182 static bool check_timezone_abbreviations(char **newval, void **extra, GucSource source);
183 static void assign_timezone_abbreviations(const char *newval, void *extra);
184 static void pg_timezone_abbrev_initialize(void);
185 static const char *show_archive_command(void);
186 static void assign_tcp_keepalives_idle(int newval, void *extra);
187 static void assign_tcp_keepalives_interval(int newval, void *extra);
188 static void assign_tcp_keepalives_count(int newval, void *extra);
189 static const char *show_tcp_keepalives_idle(void);
190 static const char *show_tcp_keepalives_interval(void);
191 static const char *show_tcp_keepalives_count(void);
192 static bool check_maxconnections(int *newval, void **extra, GucSource source);
193 static bool check_max_worker_processes(int *newval, void **extra, GucSource source);
194 static bool check_autovacuum_max_workers(int *newval, void **extra, GucSource source);
195 static bool check_autovacuum_work_mem(int *newval, void **extra, GucSource source);
196 static bool check_effective_io_concurrency(int *newval, void **extra, GucSource source);
197 static void assign_effective_io_concurrency(int newval, void *extra);
198 static void assign_pgstat_temp_directory(const char *newval, void *extra);
199 static bool check_application_name(char **newval, void **extra, GucSource source);
200 static void assign_application_name(const char *newval, void *extra);
201 static const char *show_unix_socket_permissions(void);
202 static const char *show_log_file_mode(void);
204 static char *config_enum_get_options(struct config_enum * record,
205 const char *prefix, const char *suffix,
206 const char *separator);
208 static bool validate_conf_option(struct config_generic * record,
209 const char *name, const char *value, GucSource source,
210 int elevel, bool freemem, void *newval, void **newextra);
214 * Options for enum values defined in this module.
216 * NOTE! Option values may not contain double quotes!
219 static const struct config_enum_entry bytea_output_options[] = {
220 {"escape", BYTEA_OUTPUT_ESCAPE, false},
221 {"hex", BYTEA_OUTPUT_HEX, false},
226 * We have different sets for client and server message level options because
227 * they sort slightly different (see "log" level)
229 static const struct config_enum_entry client_message_level_options[] = {
230 {"debug", DEBUG2, true},
231 {"debug5", DEBUG5, false},
232 {"debug4", DEBUG4, false},
233 {"debug3", DEBUG3, false},
234 {"debug2", DEBUG2, false},
235 {"debug1", DEBUG1, false},
237 {"info", INFO, true},
238 {"notice", NOTICE, false},
239 {"warning", WARNING, false},
240 {"error", ERROR, false},
241 {"fatal", FATAL, true},
242 {"panic", PANIC, true},
246 static const struct config_enum_entry server_message_level_options[] = {
247 {"debug", DEBUG2, true},
248 {"debug5", DEBUG5, false},
249 {"debug4", DEBUG4, false},
250 {"debug3", DEBUG3, false},
251 {"debug2", DEBUG2, false},
252 {"debug1", DEBUG1, false},
253 {"info", INFO, false},
254 {"notice", NOTICE, false},
255 {"warning", WARNING, false},
256 {"error", ERROR, false},
258 {"fatal", FATAL, false},
259 {"panic", PANIC, false},
263 static const struct config_enum_entry intervalstyle_options[] = {
264 {"postgres", INTSTYLE_POSTGRES, false},
265 {"postgres_verbose", INTSTYLE_POSTGRES_VERBOSE, false},
266 {"sql_standard", INTSTYLE_SQL_STANDARD, false},
267 {"iso_8601", INTSTYLE_ISO_8601, false},
271 static const struct config_enum_entry log_error_verbosity_options[] = {
272 {"terse", PGERROR_TERSE, false},
273 {"default", PGERROR_DEFAULT, false},
274 {"verbose", PGERROR_VERBOSE, false},
278 static const struct config_enum_entry log_statement_options[] = {
279 {"none", LOGSTMT_NONE, false},
280 {"ddl", LOGSTMT_DDL, false},
281 {"mod", LOGSTMT_MOD, false},
282 {"all", LOGSTMT_ALL, false},
286 static const struct config_enum_entry isolation_level_options[] = {
287 {"serializable", XACT_SERIALIZABLE, false},
288 {"repeatable read", XACT_REPEATABLE_READ, false},
289 {"read committed", XACT_READ_COMMITTED, false},
290 {"read uncommitted", XACT_READ_UNCOMMITTED, false},
294 static const struct config_enum_entry session_replication_role_options[] = {
295 {"origin", SESSION_REPLICATION_ROLE_ORIGIN, false},
296 {"replica", SESSION_REPLICATION_ROLE_REPLICA, false},
297 {"local", SESSION_REPLICATION_ROLE_LOCAL, false},
301 static const struct config_enum_entry syslog_facility_options[] = {
303 {"local0", LOG_LOCAL0, false},
304 {"local1", LOG_LOCAL1, false},
305 {"local2", LOG_LOCAL2, false},
306 {"local3", LOG_LOCAL3, false},
307 {"local4", LOG_LOCAL4, false},
308 {"local5", LOG_LOCAL5, false},
309 {"local6", LOG_LOCAL6, false},
310 {"local7", LOG_LOCAL7, false},
317 static const struct config_enum_entry track_function_options[] = {
318 {"none", TRACK_FUNC_OFF, false},
319 {"pl", TRACK_FUNC_PL, false},
320 {"all", TRACK_FUNC_ALL, false},
324 static const struct config_enum_entry xmlbinary_options[] = {
325 {"base64", XMLBINARY_BASE64, false},
326 {"hex", XMLBINARY_HEX, false},
330 static const struct config_enum_entry xmloption_options[] = {
331 {"content", XMLOPTION_CONTENT, false},
332 {"document", XMLOPTION_DOCUMENT, false},
337 * Although only "on", "off", and "safe_encoding" are documented, we
338 * accept all the likely variants of "on" and "off".
340 static const struct config_enum_entry backslash_quote_options[] = {
341 {"safe_encoding", BACKSLASH_QUOTE_SAFE_ENCODING, false},
342 {"on", BACKSLASH_QUOTE_ON, false},
343 {"off", BACKSLASH_QUOTE_OFF, false},
344 {"true", BACKSLASH_QUOTE_ON, true},
345 {"false", BACKSLASH_QUOTE_OFF, true},
346 {"yes", BACKSLASH_QUOTE_ON, true},
347 {"no", BACKSLASH_QUOTE_OFF, true},
348 {"1", BACKSLASH_QUOTE_ON, true},
349 {"0", BACKSLASH_QUOTE_OFF, true},
354 * Although only "on", "off", and "partition" are documented, we
355 * accept all the likely variants of "on" and "off".
357 static const struct config_enum_entry constraint_exclusion_options[] = {
358 {"partition", CONSTRAINT_EXCLUSION_PARTITION, false},
359 {"on", CONSTRAINT_EXCLUSION_ON, false},
360 {"off", CONSTRAINT_EXCLUSION_OFF, false},
361 {"true", CONSTRAINT_EXCLUSION_ON, true},
362 {"false", CONSTRAINT_EXCLUSION_OFF, true},
363 {"yes", CONSTRAINT_EXCLUSION_ON, true},
364 {"no", CONSTRAINT_EXCLUSION_OFF, true},
365 {"1", CONSTRAINT_EXCLUSION_ON, true},
366 {"0", CONSTRAINT_EXCLUSION_OFF, true},
371 * Although only "on", "off", "remote_write", and "local" are documented, we
372 * accept all the likely variants of "on" and "off".
374 static const struct config_enum_entry synchronous_commit_options[] = {
375 {"local", SYNCHRONOUS_COMMIT_LOCAL_FLUSH, false},
376 {"remote_write", SYNCHRONOUS_COMMIT_REMOTE_WRITE, false},
377 {"on", SYNCHRONOUS_COMMIT_ON, false},
378 {"off", SYNCHRONOUS_COMMIT_OFF, false},
379 {"true", SYNCHRONOUS_COMMIT_ON, true},
380 {"false", SYNCHRONOUS_COMMIT_OFF, true},
381 {"yes", SYNCHRONOUS_COMMIT_ON, true},
382 {"no", SYNCHRONOUS_COMMIT_OFF, true},
383 {"1", SYNCHRONOUS_COMMIT_ON, true},
384 {"0", SYNCHRONOUS_COMMIT_OFF, true},
389 * Although only "on", "off", "try" are documented, we accept all the likely
390 * variants of "on" and "off".
392 static const struct config_enum_entry huge_pages_options[] = {
393 {"off", HUGE_PAGES_OFF, false},
394 {"on", HUGE_PAGES_ON, false},
395 {"try", HUGE_PAGES_TRY, false},
396 {"true", HUGE_PAGES_ON, true},
397 {"false", HUGE_PAGES_OFF, true},
398 {"yes", HUGE_PAGES_ON, true},
399 {"no", HUGE_PAGES_OFF, true},
400 {"1", HUGE_PAGES_ON, true},
401 {"0", HUGE_PAGES_OFF, true},
406 * Options for enum values stored in other modules
408 extern const struct config_enum_entry wal_level_options[];
409 extern const struct config_enum_entry sync_method_options[];
410 extern const struct config_enum_entry dynamic_shared_memory_options[];
413 * GUC option variables that are exported from this module
415 bool log_duration = false;
416 bool Debug_print_plan = false;
417 bool Debug_print_parse = false;
418 bool Debug_print_rewritten = false;
419 bool Debug_pretty_print = true;
421 bool log_parser_stats = false;
422 bool log_planner_stats = false;
423 bool log_executor_stats = false;
424 bool log_statement_stats = false; /* this is sort of all three
426 bool log_btree_build_stats = false;
429 bool check_function_bodies = true;
430 bool default_with_oids = false;
431 bool SQL_inheritance = true;
433 bool Password_encryption = true;
435 int log_min_error_statement = ERROR;
436 int log_min_messages = WARNING;
437 int client_min_messages = NOTICE;
438 int log_min_duration_statement = -1;
439 int log_temp_files = -1;
440 int trace_recovery_messages = LOG;
442 int temp_file_limit = -1;
444 int num_temp_buffers = 1024;
446 char *data_directory;
447 char *ConfigFileName;
450 char *external_pid_file;
452 char *pgstat_temp_directory;
454 char *application_name;
456 int tcp_keepalives_idle;
457 int tcp_keepalives_interval;
458 int tcp_keepalives_count;
461 * This really belongs in pg_shmem.c, but is defined here so that it doesn't
462 * need to be duplicated in all the different implementations of pg_shmem.c.
467 * These variables are all dummies that don't do anything, except in some
468 * cases provide the value for SHOW to display. The real state is elsewhere
469 * and is kept in sync by assign_hooks.
471 static char *syslog_ident_str;
472 static bool phony_autocommit;
473 static bool session_auth_is_superuser;
474 static double phony_random_seed;
475 static char *client_encoding_string;
476 static char *datestyle_string;
477 static char *locale_collate;
478 static char *locale_ctype;
479 static char *server_encoding_string;
480 static char *server_version_string;
481 static int server_version_num;
482 static char *timezone_string;
483 static char *log_timezone_string;
484 static char *timezone_abbreviations_string;
485 static char *XactIsoLevel_string;
486 static char *session_authorization_string;
487 static int max_function_args;
488 static int max_index_keys;
489 static int max_identifier_length;
490 static int block_size;
491 static int segment_size;
492 static int wal_block_size;
493 static bool data_checksums;
494 static int wal_segment_size;
495 static bool integer_datetimes;
496 static int effective_io_concurrency;
497 static bool assert_enabled;
499 /* should be static, but commands/variable.c needs to get at this */
504 * Displayable names for context types (enum GucContext)
506 * Note: these strings are deliberately not localized.
508 const char *const GucContext_Names[] =
510 /* PGC_INTERNAL */ "internal",
511 /* PGC_POSTMASTER */ "postmaster",
512 /* PGC_SIGHUP */ "sighup",
513 /* PGC_BACKEND */ "backend",
514 /* PGC_SUSET */ "superuser",
515 /* PGC_USERSET */ "user"
519 * Displayable names for source types (enum GucSource)
521 * Note: these strings are deliberately not localized.
523 const char *const GucSource_Names[] =
525 /* PGC_S_DEFAULT */ "default",
526 /* PGC_S_DYNAMIC_DEFAULT */ "default",
527 /* PGC_S_ENV_VAR */ "environment variable",
528 /* PGC_S_FILE */ "configuration file",
529 /* PGC_S_ARGV */ "command line",
530 /* PGC_S_GLOBAL */ "global",
531 /* PGC_S_DATABASE */ "database",
532 /* PGC_S_USER */ "user",
533 /* PGC_S_DATABASE_USER */ "database user",
534 /* PGC_S_CLIENT */ "client",
535 /* PGC_S_OVERRIDE */ "override",
536 /* PGC_S_INTERACTIVE */ "interactive",
537 /* PGC_S_TEST */ "test",
538 /* PGC_S_SESSION */ "session"
542 * Displayable names for the groupings defined in enum config_group
544 const char *const config_group_names[] =
547 gettext_noop("Ungrouped"),
549 gettext_noop("File Locations"),
551 gettext_noop("Connections and Authentication"),
552 /* CONN_AUTH_SETTINGS */
553 gettext_noop("Connections and Authentication / Connection Settings"),
554 /* CONN_AUTH_SECURITY */
555 gettext_noop("Connections and Authentication / Security and Authentication"),
557 gettext_noop("Resource Usage"),
559 gettext_noop("Resource Usage / Memory"),
561 gettext_noop("Resource Usage / Disk"),
562 /* RESOURCES_KERNEL */
563 gettext_noop("Resource Usage / Kernel Resources"),
564 /* RESOURCES_VACUUM_DELAY */
565 gettext_noop("Resource Usage / Cost-Based Vacuum Delay"),
566 /* RESOURCES_BGWRITER */
567 gettext_noop("Resource Usage / Background Writer"),
568 /* RESOURCES_ASYNCHRONOUS */
569 gettext_noop("Resource Usage / Asynchronous Behavior"),
571 gettext_noop("Write-Ahead Log"),
573 gettext_noop("Write-Ahead Log / Settings"),
574 /* WAL_CHECKPOINTS */
575 gettext_noop("Write-Ahead Log / Checkpoints"),
577 gettext_noop("Write-Ahead Log / Archiving"),
579 gettext_noop("Replication"),
580 /* REPLICATION_SENDING */
581 gettext_noop("Replication / Sending Servers"),
582 /* REPLICATION_MASTER */
583 gettext_noop("Replication / Master Server"),
584 /* REPLICATION_STANDBY */
585 gettext_noop("Replication / Standby Servers"),
587 gettext_noop("Query Tuning"),
588 /* QUERY_TUNING_METHOD */
589 gettext_noop("Query Tuning / Planner Method Configuration"),
590 /* QUERY_TUNING_COST */
591 gettext_noop("Query Tuning / Planner Cost Constants"),
592 /* QUERY_TUNING_GEQO */
593 gettext_noop("Query Tuning / Genetic Query Optimizer"),
594 /* QUERY_TUNING_OTHER */
595 gettext_noop("Query Tuning / Other Planner Options"),
597 gettext_noop("Reporting and Logging"),
599 gettext_noop("Reporting and Logging / Where to Log"),
601 gettext_noop("Reporting and Logging / When to Log"),
603 gettext_noop("Reporting and Logging / What to Log"),
605 gettext_noop("Statistics"),
606 /* STATS_MONITORING */
607 gettext_noop("Statistics / Monitoring"),
608 /* STATS_COLLECTOR */
609 gettext_noop("Statistics / Query and Index Statistics Collector"),
611 gettext_noop("Autovacuum"),
613 gettext_noop("Client Connection Defaults"),
614 /* CLIENT_CONN_STATEMENT */
615 gettext_noop("Client Connection Defaults / Statement Behavior"),
616 /* CLIENT_CONN_LOCALE */
617 gettext_noop("Client Connection Defaults / Locale and Formatting"),
618 /* CLIENT_CONN_PRELOAD */
619 gettext_noop("Client Connection Defaults / Shared Library Preloading"),
620 /* CLIENT_CONN_OTHER */
621 gettext_noop("Client Connection Defaults / Other Defaults"),
622 /* LOCK_MANAGEMENT */
623 gettext_noop("Lock Management"),
625 gettext_noop("Version and Platform Compatibility"),
626 /* COMPAT_OPTIONS_PREVIOUS */
627 gettext_noop("Version and Platform Compatibility / Previous PostgreSQL Versions"),
628 /* COMPAT_OPTIONS_CLIENT */
629 gettext_noop("Version and Platform Compatibility / Other Platforms and Clients"),
631 gettext_noop("Error Handling"),
633 gettext_noop("Preset Options"),
635 gettext_noop("Customized Options"),
636 /* DEVELOPER_OPTIONS */
637 gettext_noop("Developer Options"),
638 /* help_config wants this array to be null-terminated */
643 * Displayable names for GUC variable types (enum config_type)
645 * Note: these strings are deliberately not localized.
647 const char *const config_type_names[] =
649 /* PGC_BOOL */ "bool",
650 /* PGC_INT */ "integer",
651 /* PGC_REAL */ "real",
652 /* PGC_STRING */ "string",
653 /* PGC_ENUM */ "enum"
658 * Contents of GUC tables
660 * See src/backend/utils/misc/README for design notes.
664 * 1. Declare a global variable of type bool, int, double, or char*
665 * and make use of it.
667 * 2. Decide at what times it's safe to set the option. See guc.h for
670 * 3. Decide on a name, a default value, upper and lower bounds (if
673 * 4. Add a record below.
675 * 5. Add it to src/backend/utils/misc/postgresql.conf.sample, if
678 * 6. Don't forget to document the option (at least in config.sgml).
680 * 7. If it's a new GUC_LIST option you must edit pg_dumpall.c to ensure
681 * it is not single quoted at dump time.
685 /******** option records follow ********/
687 static struct config_bool ConfigureNamesBool[] =
690 {"enable_seqscan", PGC_USERSET, QUERY_TUNING_METHOD,
691 gettext_noop("Enables the planner's use of sequential-scan plans."),
699 {"enable_indexscan", PGC_USERSET, QUERY_TUNING_METHOD,
700 gettext_noop("Enables the planner's use of index-scan plans."),
708 {"enable_indexonlyscan", PGC_USERSET, QUERY_TUNING_METHOD,
709 gettext_noop("Enables the planner's use of index-only-scan plans."),
712 &enable_indexonlyscan,
717 {"enable_bitmapscan", PGC_USERSET, QUERY_TUNING_METHOD,
718 gettext_noop("Enables the planner's use of bitmap-scan plans."),
726 {"enable_tidscan", PGC_USERSET, QUERY_TUNING_METHOD,
727 gettext_noop("Enables the planner's use of TID scan plans."),
735 {"enable_sort", PGC_USERSET, QUERY_TUNING_METHOD,
736 gettext_noop("Enables the planner's use of explicit sort steps."),
744 {"enable_hashagg", PGC_USERSET, QUERY_TUNING_METHOD,
745 gettext_noop("Enables the planner's use of hashed aggregation plans."),
753 {"enable_material", PGC_USERSET, QUERY_TUNING_METHOD,
754 gettext_noop("Enables the planner's use of materialization."),
762 {"enable_nestloop", PGC_USERSET, QUERY_TUNING_METHOD,
763 gettext_noop("Enables the planner's use of nested-loop join plans."),
771 {"enable_mergejoin", PGC_USERSET, QUERY_TUNING_METHOD,
772 gettext_noop("Enables the planner's use of merge join plans."),
780 {"enable_hashjoin", PGC_USERSET, QUERY_TUNING_METHOD,
781 gettext_noop("Enables the planner's use of hash join plans."),
789 {"geqo", PGC_USERSET, QUERY_TUNING_GEQO,
790 gettext_noop("Enables genetic query optimization."),
791 gettext_noop("This algorithm attempts to do planning without "
792 "exhaustive searching.")
799 /* Not for general use --- used by SET SESSION AUTHORIZATION */
800 {"is_superuser", PGC_INTERNAL, UNGROUPED,
801 gettext_noop("Shows whether the current user is a superuser."),
803 GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
805 &session_auth_is_superuser,
810 {"bonjour", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
811 gettext_noop("Enables advertising the server via Bonjour."),
816 check_bonjour, NULL, NULL
819 {"ssl", PGC_POSTMASTER, CONN_AUTH_SECURITY,
820 gettext_noop("Enables SSL connections."),
825 check_ssl, NULL, NULL
828 {"ssl_prefer_server_ciphers", PGC_POSTMASTER, CONN_AUTH_SECURITY,
829 gettext_noop("Give priority to server ciphersuite order."),
832 &SSLPreferServerCiphers,
837 {"fsync", PGC_SIGHUP, WAL_SETTINGS,
838 gettext_noop("Forces synchronization of updates to disk."),
839 gettext_noop("The server will use the fsync() system call in several places to make "
840 "sure that updates are physically written to disk. This insures "
841 "that a database cluster will recover to a consistent state after "
842 "an operating system or hardware crash.")
849 {"ignore_checksum_failure", PGC_SUSET, DEVELOPER_OPTIONS,
850 gettext_noop("Continues processing after a checksum failure."),
851 gettext_noop("Detection of a checksum failure normally causes PostgreSQL to "
852 "report an error, aborting the current transaction. Setting "
853 "ignore_checksum_failure to true causes the system to ignore the failure "
854 "(but still report a warning), and continue processing. This "
855 "behavior could cause crashes or other serious problems. Only "
856 "has an effect if checksums are enabled."),
859 &ignore_checksum_failure,
864 {"zero_damaged_pages", PGC_SUSET, DEVELOPER_OPTIONS,
865 gettext_noop("Continues processing past damaged page headers."),
866 gettext_noop("Detection of a damaged page header normally causes PostgreSQL to "
867 "report an error, aborting the current transaction. Setting "
868 "zero_damaged_pages to true causes the system to instead report a "
869 "warning, zero out the damaged page, and continue processing. This "
870 "behavior will destroy data, namely all the rows on the damaged page."),
878 {"full_page_writes", PGC_SIGHUP, WAL_SETTINGS,
879 gettext_noop("Writes full pages to WAL when first modified after a checkpoint."),
880 gettext_noop("A page write in process during an operating system crash might be "
881 "only partially written to disk. During recovery, the row changes "
882 "stored in WAL are not enough to recover. This option writes "
883 "pages when first modified after a checkpoint to WAL so full recovery "
892 {"wal_log_hints", PGC_POSTMASTER, WAL_SETTINGS,
893 gettext_noop("Writes full pages to WAL when first modified after a checkpoint, even for a non-critical modifications"),
902 {"log_checkpoints", PGC_SIGHUP, LOGGING_WHAT,
903 gettext_noop("Logs each checkpoint."),
911 {"log_connections", PGC_BACKEND, LOGGING_WHAT,
912 gettext_noop("Logs each successful connection."),
920 {"log_disconnections", PGC_BACKEND, LOGGING_WHAT,
921 gettext_noop("Logs end of a session, including duration."),
929 {"debug_assertions", PGC_INTERNAL, PRESET_OPTIONS,
930 gettext_noop("Shows whether the running server has assertion checks enabled."),
932 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
935 #ifdef USE_ASSERT_CHECKING
944 {"exit_on_error", PGC_USERSET, ERROR_HANDLING_OPTIONS,
945 gettext_noop("Terminate session on any error."),
953 {"restart_after_crash", PGC_SIGHUP, ERROR_HANDLING_OPTIONS,
954 gettext_noop("Reinitialize server after backend crash."),
957 &restart_after_crash,
963 {"log_duration", PGC_SUSET, LOGGING_WHAT,
964 gettext_noop("Logs the duration of each completed SQL statement."),
972 {"debug_print_parse", PGC_USERSET, LOGGING_WHAT,
973 gettext_noop("Logs each query's parse tree."),
981 {"debug_print_rewritten", PGC_USERSET, LOGGING_WHAT,
982 gettext_noop("Logs each query's rewritten parse tree."),
985 &Debug_print_rewritten,
990 {"debug_print_plan", PGC_USERSET, LOGGING_WHAT,
991 gettext_noop("Logs each query's execution plan."),
999 {"debug_pretty_print", PGC_USERSET, LOGGING_WHAT,
1000 gettext_noop("Indents parse and plan tree displays."),
1003 &Debug_pretty_print,
1008 {"log_parser_stats", PGC_SUSET, STATS_MONITORING,
1009 gettext_noop("Writes parser performance statistics to the server log."),
1014 check_stage_log_stats, NULL, NULL
1017 {"log_planner_stats", PGC_SUSET, STATS_MONITORING,
1018 gettext_noop("Writes planner performance statistics to the server log."),
1023 check_stage_log_stats, NULL, NULL
1026 {"log_executor_stats", PGC_SUSET, STATS_MONITORING,
1027 gettext_noop("Writes executor performance statistics to the server log."),
1030 &log_executor_stats,
1032 check_stage_log_stats, NULL, NULL
1035 {"log_statement_stats", PGC_SUSET, STATS_MONITORING,
1036 gettext_noop("Writes cumulative performance statistics to the server log."),
1039 &log_statement_stats,
1041 check_log_stats, NULL, NULL
1043 #ifdef BTREE_BUILD_STATS
1045 {"log_btree_build_stats", PGC_SUSET, DEVELOPER_OPTIONS,
1046 gettext_noop("Logs system resource usage statistics (memory and CPU) on various B-tree operations."),
1050 &log_btree_build_stats,
1057 {"track_activities", PGC_SUSET, STATS_COLLECTOR,
1058 gettext_noop("Collects information about executing commands."),
1059 gettext_noop("Enables the collection of information on the currently "
1060 "executing command of each session, along with "
1061 "the time at which that command began execution.")
1063 &pgstat_track_activities,
1068 {"track_counts", PGC_SUSET, STATS_COLLECTOR,
1069 gettext_noop("Collects statistics on database activity."),
1072 &pgstat_track_counts,
1077 {"track_io_timing", PGC_SUSET, STATS_COLLECTOR,
1078 gettext_noop("Collects timing statistics for database I/O activity."),
1087 {"update_process_title", PGC_SUSET, STATS_COLLECTOR,
1088 gettext_noop("Updates the process title to show the active SQL command."),
1089 gettext_noop("Enables updating of the process title every time a new SQL command is received by the server.")
1091 &update_process_title,
1097 {"autovacuum", PGC_SIGHUP, AUTOVACUUM,
1098 gettext_noop("Starts the autovacuum subprocess."),
1101 &autovacuum_start_daemon,
1107 {"trace_notify", PGC_USERSET, DEVELOPER_OPTIONS,
1108 gettext_noop("Generates debugging output for LISTEN and NOTIFY."),
1119 {"trace_locks", PGC_SUSET, DEVELOPER_OPTIONS,
1120 gettext_noop("Emits information about lock usage."),
1129 {"trace_userlocks", PGC_SUSET, DEVELOPER_OPTIONS,
1130 gettext_noop("Emits information about user lock usage."),
1139 {"trace_lwlocks", PGC_SUSET, DEVELOPER_OPTIONS,
1140 gettext_noop("Emits information about lightweight lock usage."),
1149 {"debug_deadlocks", PGC_SUSET, DEVELOPER_OPTIONS,
1150 gettext_noop("Dumps information about all current locks when a deadlock timeout occurs."),
1161 {"log_lock_waits", PGC_SUSET, LOGGING_WHAT,
1162 gettext_noop("Logs long lock waits."),
1171 {"log_hostname", PGC_SIGHUP, LOGGING_WHAT,
1172 gettext_noop("Logs the host name in the connection logs."),
1173 gettext_noop("By default, connection logs only show the IP address "
1174 "of the connecting host. If you want them to show the host name you "
1175 "can turn this on, but depending on your host name resolution "
1176 "setup it might impose a non-negligible performance penalty.")
1183 {"sql_inheritance", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1184 gettext_noop("Causes subtables to be included by default in various commands."),
1192 {"password_encryption", PGC_USERSET, CONN_AUTH_SECURITY,
1193 gettext_noop("Encrypt passwords."),
1194 gettext_noop("When a password is specified in CREATE USER or "
1195 "ALTER USER without writing either ENCRYPTED or UNENCRYPTED, "
1196 "this parameter determines whether the password is to be encrypted.")
1198 &Password_encryption,
1203 {"transform_null_equals", PGC_USERSET, COMPAT_OPTIONS_CLIENT,
1204 gettext_noop("Treats \"expr=NULL\" as \"expr IS NULL\"."),
1205 gettext_noop("When turned on, expressions of the form expr = NULL "
1206 "(or NULL = expr) are treated as expr IS NULL, that is, they "
1207 "return true if expr evaluates to the null value, and false "
1208 "otherwise. The correct behavior of expr = NULL is to always "
1209 "return null (unknown).")
1211 &Transform_null_equals,
1216 {"db_user_namespace", PGC_SIGHUP, CONN_AUTH_SECURITY,
1217 gettext_noop("Enables per-database user names."),
1225 /* only here for backwards compatibility */
1226 {"autocommit", PGC_USERSET, CLIENT_CONN_STATEMENT,
1227 gettext_noop("This parameter doesn't do anything."),
1228 gettext_noop("It's just here so that we won't choke on SET AUTOCOMMIT TO ON from 7.3-vintage clients."),
1229 GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
1233 check_phony_autocommit, NULL, NULL
1236 {"default_transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
1237 gettext_noop("Sets the default read-only status of new transactions."),
1240 &DefaultXactReadOnly,
1245 {"transaction_read_only", PGC_USERSET, CLIENT_CONN_STATEMENT,
1246 gettext_noop("Sets the current transaction's read-only status."),
1248 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1252 check_transaction_read_only, NULL, NULL
1255 {"default_transaction_deferrable", PGC_USERSET, CLIENT_CONN_STATEMENT,
1256 gettext_noop("Sets the default deferrable status of new transactions."),
1259 &DefaultXactDeferrable,
1264 {"transaction_deferrable", PGC_USERSET, CLIENT_CONN_STATEMENT,
1265 gettext_noop("Whether to defer a read-only serializable transaction until it can be executed with no possible serialization failures."),
1267 GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1271 check_transaction_deferrable, NULL, NULL
1274 {"check_function_bodies", PGC_USERSET, CLIENT_CONN_STATEMENT,
1275 gettext_noop("Check function bodies during CREATE FUNCTION."),
1278 &check_function_bodies,
1283 {"array_nulls", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1284 gettext_noop("Enable input of NULL elements in arrays."),
1285 gettext_noop("When turned on, unquoted NULL in an array input "
1286 "value means a null value; "
1287 "otherwise it is taken literally.")
1294 {"default_with_oids", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1295 gettext_noop("Create new tables with OIDs by default."),
1303 {"logging_collector", PGC_POSTMASTER, LOGGING_WHERE,
1304 gettext_noop("Start a subprocess to capture stderr output and/or csvlogs into log files."),
1312 {"log_truncate_on_rotation", PGC_SIGHUP, LOGGING_WHERE,
1313 gettext_noop("Truncate existing log files of same name during log rotation."),
1316 &Log_truncate_on_rotation,
1323 {"trace_sort", PGC_USERSET, DEVELOPER_OPTIONS,
1324 gettext_noop("Emit information about resource usage in sorting."),
1334 #ifdef TRACE_SYNCSCAN
1335 /* this is undocumented because not exposed in a standard build */
1337 {"trace_syncscan", PGC_USERSET, DEVELOPER_OPTIONS,
1338 gettext_noop("Generate debugging output for synchronized scanning."),
1348 #ifdef DEBUG_BOUNDED_SORT
1349 /* this is undocumented because not exposed in a standard build */
1352 "optimize_bounded_sort", PGC_USERSET, QUERY_TUNING_METHOD,
1353 gettext_noop("Enable bounded sorting using heap sort."),
1357 &optimize_bounded_sort,
1365 {"wal_debug", PGC_SUSET, DEVELOPER_OPTIONS,
1366 gettext_noop("Emit WAL-related debugging output."),
1377 {"integer_datetimes", PGC_INTERNAL, PRESET_OPTIONS,
1378 gettext_noop("Datetimes are integer based."),
1380 GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1383 #ifdef HAVE_INT64_TIMESTAMP
1392 {"krb_caseins_users", PGC_SIGHUP, CONN_AUTH_SECURITY,
1393 gettext_noop("Sets whether Kerberos and GSSAPI user names should be treated as case-insensitive."),
1396 &pg_krb_caseins_users,
1402 {"escape_string_warning", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1403 gettext_noop("Warn about backslash escapes in ordinary string literals."),
1406 &escape_string_warning,
1412 {"standard_conforming_strings", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1413 gettext_noop("Causes '...' strings to treat backslashes literally."),
1417 &standard_conforming_strings,
1423 {"synchronize_seqscans", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1424 gettext_noop("Enable synchronized sequential scans."),
1427 &synchronize_seqscans,
1433 {"archive_mode", PGC_POSTMASTER, WAL_ARCHIVING,
1434 gettext_noop("Allows archiving of WAL files using archive_command."),
1443 {"hot_standby", PGC_POSTMASTER, REPLICATION_STANDBY,
1444 gettext_noop("Allows connections and queries during recovery."),
1453 {"hot_standby_feedback", PGC_SIGHUP, REPLICATION_STANDBY,
1454 gettext_noop("Allows feedback from a hot standby to the primary that will avoid query conflicts."),
1457 &hot_standby_feedback,
1463 {"allow_system_table_mods", PGC_POSTMASTER, DEVELOPER_OPTIONS,
1464 gettext_noop("Allows modifications of the structure of system tables."),
1468 &allowSystemTableMods,
1474 {"ignore_system_indexes", PGC_BACKEND, DEVELOPER_OPTIONS,
1475 gettext_noop("Disables reading from system indexes."),
1476 gettext_noop("It does not prevent updating the indexes, so it is safe "
1477 "to use. The worst consequence is slowness."),
1480 &IgnoreSystemIndexes,
1486 {"lo_compat_privileges", PGC_SUSET, COMPAT_OPTIONS_PREVIOUS,
1487 gettext_noop("Enables backward compatibility mode for privilege checks on large objects."),
1488 gettext_noop("Skips privilege checks when reading or modifying large objects, "
1489 "for compatibility with PostgreSQL releases prior to 9.0.")
1491 &lo_compat_privileges,
1497 {"quote_all_identifiers", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1498 gettext_noop("When generating SQL fragments, quote all identifiers."),
1501 "e_all_identifiers,
1507 {"data_checksums", PGC_INTERNAL, PRESET_OPTIONS,
1508 gettext_noop("Shows whether data checksums are turned on for this cluster."),
1510 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1517 /* End-of-list marker */
1519 {NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL, NULL
1524 static struct config_int ConfigureNamesInt[] =
1527 {"archive_timeout", PGC_SIGHUP, WAL_ARCHIVING,
1528 gettext_noop("Forces a switch to the next xlog file if a "
1529 "new file has not been started within N seconds."),
1533 &XLogArchiveTimeout,
1538 {"post_auth_delay", PGC_BACKEND, DEVELOPER_OPTIONS,
1539 gettext_noop("Waits N seconds on connection startup after authentication."),
1540 gettext_noop("This allows attaching a debugger to the process."),
1541 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
1544 0, 0, INT_MAX / 1000000,
1548 {"default_statistics_target", PGC_USERSET, QUERY_TUNING_OTHER,
1549 gettext_noop("Sets the default statistics target."),
1550 gettext_noop("This applies to table columns that have not had a "
1551 "column-specific target set via ALTER TABLE SET STATISTICS.")
1553 &default_statistics_target,
1558 {"from_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1559 gettext_noop("Sets the FROM-list size beyond which subqueries "
1560 "are not collapsed."),
1561 gettext_noop("The planner will merge subqueries into upper "
1562 "queries if the resulting FROM list would have no more than "
1565 &from_collapse_limit,
1570 {"join_collapse_limit", PGC_USERSET, QUERY_TUNING_OTHER,
1571 gettext_noop("Sets the FROM-list size beyond which JOIN "
1572 "constructs are not flattened."),
1573 gettext_noop("The planner will flatten explicit JOIN "
1574 "constructs into lists of FROM items whenever a "
1575 "list of no more than this many items would result.")
1577 &join_collapse_limit,
1582 {"geqo_threshold", PGC_USERSET, QUERY_TUNING_GEQO,
1583 gettext_noop("Sets the threshold of FROM items beyond which GEQO is used."),
1591 {"geqo_effort", PGC_USERSET, QUERY_TUNING_GEQO,
1592 gettext_noop("GEQO: effort is used to set the default for other GEQO parameters."),
1596 DEFAULT_GEQO_EFFORT, MIN_GEQO_EFFORT, MAX_GEQO_EFFORT,
1600 {"geqo_pool_size", PGC_USERSET, QUERY_TUNING_GEQO,
1601 gettext_noop("GEQO: number of individuals in the population."),
1602 gettext_noop("Zero selects a suitable default value.")
1609 {"geqo_generations", PGC_USERSET, QUERY_TUNING_GEQO,
1610 gettext_noop("GEQO: number of iterations of the algorithm."),
1611 gettext_noop("Zero selects a suitable default value.")
1619 /* This is PGC_SUSET to prevent hiding from log_lock_waits. */
1620 {"deadlock_timeout", PGC_SUSET, LOCK_MANAGEMENT,
1621 gettext_noop("Sets the time to wait on a lock before checking for deadlock."),
1631 {"max_standby_archive_delay", PGC_SIGHUP, REPLICATION_STANDBY,
1632 gettext_noop("Sets the maximum delay before canceling queries when a hot standby server is processing archived WAL data."),
1636 &max_standby_archive_delay,
1637 30 * 1000, -1, INT_MAX,
1642 {"max_standby_streaming_delay", PGC_SIGHUP, REPLICATION_STANDBY,
1643 gettext_noop("Sets the maximum delay before canceling queries when a hot standby server is processing streamed WAL data."),
1647 &max_standby_streaming_delay,
1648 30 * 1000, -1, INT_MAX,
1653 {"wal_receiver_status_interval", PGC_SIGHUP, REPLICATION_STANDBY,
1654 gettext_noop("Sets the maximum interval between WAL receiver status reports to the primary."),
1658 &wal_receiver_status_interval,
1659 10, 0, INT_MAX / 1000,
1664 {"wal_receiver_timeout", PGC_SIGHUP, REPLICATION_STANDBY,
1665 gettext_noop("Sets the maximum wait time to receive data from the primary."),
1669 &wal_receiver_timeout,
1670 60 * 1000, 0, INT_MAX,
1675 {"max_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1676 gettext_noop("Sets the maximum number of concurrent connections."),
1680 100, 1, MAX_BACKENDS,
1681 check_maxconnections, NULL, NULL
1685 {"superuser_reserved_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1686 gettext_noop("Sets the number of connection slots reserved for superusers."),
1695 * We sometimes multiply the number of shared buffers by two without
1696 * checking for overflow, so we mustn't allow more than INT_MAX / 2.
1699 {"shared_buffers", PGC_POSTMASTER, RESOURCES_MEM,
1700 gettext_noop("Sets the number of shared memory buffers used by the server."),
1705 1024, 16, INT_MAX / 2,
1710 {"temp_buffers", PGC_USERSET, RESOURCES_MEM,
1711 gettext_noop("Sets the maximum number of temporary buffers used by each session."),
1716 1024, 100, INT_MAX / 2,
1717 check_temp_buffers, NULL, NULL
1721 {"port", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1722 gettext_noop("Sets the TCP port the server listens on."),
1726 DEF_PGPORT, 1, 65535,
1731 {"unix_socket_permissions", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
1732 gettext_noop("Sets the access permissions of the Unix-domain socket."),
1733 gettext_noop("Unix-domain sockets use the usual Unix file system "
1734 "permission set. The parameter value is expected "
1735 "to be a numeric mode specification in the form "
1736 "accepted by the chmod and umask system calls. "
1737 "(To use the customary octal format the number must "
1738 "start with a 0 (zero).)")
1740 &Unix_socket_permissions,
1742 NULL, NULL, show_unix_socket_permissions
1746 {"log_file_mode", PGC_SIGHUP, LOGGING_WHERE,
1747 gettext_noop("Sets the file permissions for log files."),
1748 gettext_noop("The parameter value is expected "
1749 "to be a numeric mode specification in the form "
1750 "accepted by the chmod and umask system calls. "
1751 "(To use the customary octal format the number must "
1752 "start with a 0 (zero).)")
1756 NULL, NULL, show_log_file_mode
1760 {"work_mem", PGC_USERSET, RESOURCES_MEM,
1761 gettext_noop("Sets the maximum memory to be used for query workspaces."),
1762 gettext_noop("This much memory can be used by each internal "
1763 "sort operation and hash table before switching to "
1764 "temporary disk files."),
1768 4096, 64, MAX_KILOBYTES,
1773 {"maintenance_work_mem", PGC_USERSET, RESOURCES_MEM,
1774 gettext_noop("Sets the maximum memory to be used for maintenance operations."),
1775 gettext_noop("This includes operations such as VACUUM and CREATE INDEX."),
1778 &maintenance_work_mem,
1779 65536, 1024, MAX_KILOBYTES,
1784 * We use the hopefully-safely-small value of 100kB as the compiled-in
1785 * default for max_stack_depth. InitializeGUCOptions will increase it if
1786 * possible, depending on the actual platform-specific stack limit.
1789 {"max_stack_depth", PGC_SUSET, RESOURCES_MEM,
1790 gettext_noop("Sets the maximum stack depth, in kilobytes."),
1795 100, 100, MAX_KILOBYTES,
1796 check_max_stack_depth, assign_max_stack_depth, NULL
1800 {"temp_file_limit", PGC_SUSET, RESOURCES_DISK,
1801 gettext_noop("Limits the total size of all temporary files used by each session."),
1802 gettext_noop("-1 means no limit."),
1811 {"vacuum_cost_page_hit", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1812 gettext_noop("Vacuum cost for a page found in the buffer cache."),
1821 {"vacuum_cost_page_miss", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1822 gettext_noop("Vacuum cost for a page not found in the buffer cache."),
1825 &VacuumCostPageMiss,
1831 {"vacuum_cost_page_dirty", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1832 gettext_noop("Vacuum cost for a page dirtied by vacuum."),
1835 &VacuumCostPageDirty,
1841 {"vacuum_cost_limit", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1842 gettext_noop("Vacuum cost amount available before napping."),
1851 {"vacuum_cost_delay", PGC_USERSET, RESOURCES_VACUUM_DELAY,
1852 gettext_noop("Vacuum cost delay in milliseconds."),
1862 {"autovacuum_vacuum_cost_delay", PGC_SIGHUP, AUTOVACUUM,
1863 gettext_noop("Vacuum cost delay in milliseconds, for autovacuum."),
1867 &autovacuum_vac_cost_delay,
1873 {"autovacuum_vacuum_cost_limit", PGC_SIGHUP, AUTOVACUUM,
1874 gettext_noop("Vacuum cost amount available before napping, for autovacuum."),
1877 &autovacuum_vac_cost_limit,
1883 {"max_files_per_process", PGC_POSTMASTER, RESOURCES_KERNEL,
1884 gettext_noop("Sets the maximum number of simultaneously open files for each server process."),
1887 &max_files_per_process,
1893 * See also CheckRequiredParameterValues() if this parameter changes
1896 {"max_prepared_transactions", PGC_POSTMASTER, RESOURCES_MEM,
1897 gettext_noop("Sets the maximum number of simultaneously prepared transactions."),
1900 &max_prepared_xacts,
1907 {"trace_lock_oidmin", PGC_SUSET, DEVELOPER_OPTIONS,
1908 gettext_noop("Sets the minimum OID of tables for tracking locks."),
1909 gettext_noop("Is used to avoid output on system tables."),
1913 FirstNormalObjectId, 0, INT_MAX,
1917 {"trace_lock_table", PGC_SUSET, DEVELOPER_OPTIONS,
1918 gettext_noop("Sets the OID of the table with unconditionally lock tracing."),
1929 {"statement_timeout", PGC_USERSET, CLIENT_CONN_STATEMENT,
1930 gettext_noop("Sets the maximum allowed duration of any statement."),
1931 gettext_noop("A value of 0 turns off the timeout."),
1940 {"lock_timeout", PGC_USERSET, CLIENT_CONN_STATEMENT,
1941 gettext_noop("Sets the maximum allowed duration of any wait for a lock."),
1942 gettext_noop("A value of 0 turns off the timeout."),
1951 {"vacuum_freeze_min_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1952 gettext_noop("Minimum age at which VACUUM should freeze a table row."),
1955 &vacuum_freeze_min_age,
1956 50000000, 0, 1000000000,
1961 {"vacuum_freeze_table_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1962 gettext_noop("Age at which VACUUM should scan whole table to freeze tuples."),
1965 &vacuum_freeze_table_age,
1966 150000000, 0, 2000000000,
1971 {"vacuum_multixact_freeze_min_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1972 gettext_noop("Minimum age at which VACUUM should freeze a MultiXactId in a table row."),
1975 &vacuum_multixact_freeze_min_age,
1976 5000000, 0, 1000000000,
1981 {"vacuum_multixact_freeze_table_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
1982 gettext_noop("Multixact age at which VACUUM should scan whole table to freeze tuples."),
1985 &vacuum_multixact_freeze_table_age,
1986 150000000, 0, 2000000000,
1991 {"vacuum_defer_cleanup_age", PGC_SIGHUP, REPLICATION_MASTER,
1992 gettext_noop("Number of transactions by which VACUUM and HOT cleanup should be deferred, if any."),
1995 &vacuum_defer_cleanup_age,
2001 * See also CheckRequiredParameterValues() if this parameter changes
2004 {"max_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
2005 gettext_noop("Sets the maximum number of locks per transaction."),
2006 gettext_noop("The shared lock table is sized on the assumption that "
2007 "at most max_locks_per_transaction * max_connections distinct "
2008 "objects will need to be locked at any one time.")
2010 &max_locks_per_xact,
2016 {"max_pred_locks_per_transaction", PGC_POSTMASTER, LOCK_MANAGEMENT,
2017 gettext_noop("Sets the maximum number of predicate locks per transaction."),
2018 gettext_noop("The shared predicate lock table is sized on the assumption that "
2019 "at most max_pred_locks_per_transaction * max_connections distinct "
2020 "objects will need to be locked at any one time.")
2022 &max_predicate_locks_per_xact,
2028 {"authentication_timeout", PGC_SIGHUP, CONN_AUTH_SECURITY,
2029 gettext_noop("Sets the maximum allowed time to complete client authentication."),
2033 &AuthenticationTimeout,
2039 /* Not for general use */
2040 {"pre_auth_delay", PGC_SIGHUP, DEVELOPER_OPTIONS,
2041 gettext_noop("Waits N seconds on connection startup before authentication."),
2042 gettext_noop("This allows attaching a debugger to the process."),
2043 GUC_NOT_IN_SAMPLE | GUC_UNIT_S
2051 {"wal_keep_segments", PGC_SIGHUP, REPLICATION_SENDING,
2052 gettext_noop("Sets the number of WAL files held for standby servers."),
2061 {"checkpoint_segments", PGC_SIGHUP, WAL_CHECKPOINTS,
2062 gettext_noop("Sets the maximum distance in log segments between automatic WAL checkpoints."),
2065 &CheckPointSegments,
2071 {"checkpoint_timeout", PGC_SIGHUP, WAL_CHECKPOINTS,
2072 gettext_noop("Sets the maximum time between automatic WAL checkpoints."),
2082 {"checkpoint_warning", PGC_SIGHUP, WAL_CHECKPOINTS,
2083 gettext_noop("Enables warnings if checkpoint segments are filled more "
2084 "frequently than this."),
2085 gettext_noop("Write a message to the server log if checkpoints "
2086 "caused by the filling of checkpoint segment files happens more "
2087 "frequently than this number of seconds. Zero turns off the warning."),
2096 {"wal_buffers", PGC_POSTMASTER, WAL_SETTINGS,
2097 gettext_noop("Sets the number of disk-page buffers in shared memory for WAL."),
2103 check_wal_buffers, NULL, NULL
2107 {"wal_writer_delay", PGC_SIGHUP, WAL_SETTINGS,
2108 gettext_noop("WAL writer sleep time between WAL flushes."),
2118 {"xloginsert_locks", PGC_POSTMASTER, WAL_SETTINGS,
2119 gettext_noop("Sets the number of locks used for concurrent xlog insertions."),
2123 &num_xloginsert_locks,
2129 /* see max_connections */
2130 {"max_wal_senders", PGC_POSTMASTER, REPLICATION_SENDING,
2131 gettext_noop("Sets the maximum number of simultaneously running WAL sender processes."),
2140 /* see max_connections */
2141 {"max_replication_slots", PGC_POSTMASTER, REPLICATION_SENDING,
2142 gettext_noop("Sets the maximum number of simultaneously defined replication slots."),
2145 &max_replication_slots,
2146 0, 0, MAX_BACKENDS /* XXX? */ ,
2151 {"wal_sender_timeout", PGC_SIGHUP, REPLICATION_SENDING,
2152 gettext_noop("Sets the maximum time to wait for WAL replication."),
2156 &wal_sender_timeout,
2157 60 * 1000, 0, INT_MAX,
2162 {"commit_delay", PGC_SUSET, WAL_SETTINGS,
2163 gettext_noop("Sets the delay in microseconds between transaction commit and "
2164 "flushing WAL to disk."),
2166 /* we have no microseconds designation, so can't supply units here */
2174 {"commit_siblings", PGC_USERSET, WAL_SETTINGS,
2175 gettext_noop("Sets the minimum concurrent open transactions before performing "
2185 {"extra_float_digits", PGC_USERSET, CLIENT_CONN_LOCALE,
2186 gettext_noop("Sets the number of digits displayed for floating-point values."),
2187 gettext_noop("This affects real, double precision, and geometric data types. "
2188 "The parameter value is added to the standard number of digits "
2189 "(FLT_DIG or DBL_DIG as appropriate).")
2191 &extra_float_digits,
2197 {"log_min_duration_statement", PGC_SUSET, LOGGING_WHEN,
2198 gettext_noop("Sets the minimum execution time above which "
2199 "statements will be logged."),
2200 gettext_noop("Zero prints all queries. -1 turns this feature off."),
2203 &log_min_duration_statement,
2209 {"log_autovacuum_min_duration", PGC_SIGHUP, LOGGING_WHAT,
2210 gettext_noop("Sets the minimum execution time above which "
2211 "autovacuum actions will be logged."),
2212 gettext_noop("Zero prints all actions. -1 turns autovacuum logging off."),
2215 &Log_autovacuum_min_duration,
2221 {"bgwriter_delay", PGC_SIGHUP, RESOURCES_BGWRITER,
2222 gettext_noop("Background writer sleep time between rounds."),
2232 {"bgwriter_lru_maxpages", PGC_SIGHUP, RESOURCES_BGWRITER,
2233 gettext_noop("Background writer maximum number of LRU pages to flush per round."),
2236 &bgwriter_lru_maxpages,
2242 {"effective_io_concurrency",
2248 RESOURCES_ASYNCHRONOUS,
2249 gettext_noop("Number of simultaneous requests that can be handled efficiently by the disk subsystem."),
2250 gettext_noop("For RAID arrays, this should be approximately the number of drive spindles in the array.")
2252 &effective_io_concurrency,
2258 check_effective_io_concurrency, assign_effective_io_concurrency, NULL
2262 {"max_worker_processes",
2264 RESOURCES_ASYNCHRONOUS,
2265 gettext_noop("Maximum number of concurrent worker processes."),
2268 &max_worker_processes,
2270 check_max_worker_processes, NULL, NULL
2274 {"log_rotation_age", PGC_SIGHUP, LOGGING_WHERE,
2275 gettext_noop("Automatic log file rotation will occur after N minutes."),
2280 HOURS_PER_DAY * MINS_PER_HOUR, 0, INT_MAX / SECS_PER_MINUTE,
2285 {"log_rotation_size", PGC_SIGHUP, LOGGING_WHERE,
2286 gettext_noop("Automatic log file rotation will occur after N kilobytes."),
2291 10 * 1024, 0, INT_MAX / 1024,
2296 {"max_function_args", PGC_INTERNAL, PRESET_OPTIONS,
2297 gettext_noop("Shows the maximum number of function arguments."),
2299 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2302 FUNC_MAX_ARGS, FUNC_MAX_ARGS, FUNC_MAX_ARGS,
2307 {"max_index_keys", PGC_INTERNAL, PRESET_OPTIONS,
2308 gettext_noop("Shows the maximum number of index keys."),
2310 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2313 INDEX_MAX_KEYS, INDEX_MAX_KEYS, INDEX_MAX_KEYS,
2318 {"max_identifier_length", PGC_INTERNAL, PRESET_OPTIONS,
2319 gettext_noop("Shows the maximum identifier length."),
2321 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2323 &max_identifier_length,
2324 NAMEDATALEN - 1, NAMEDATALEN - 1, NAMEDATALEN - 1,
2329 {"block_size", PGC_INTERNAL, PRESET_OPTIONS,
2330 gettext_noop("Shows the size of a disk block."),
2332 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2335 BLCKSZ, BLCKSZ, BLCKSZ,
2340 {"segment_size", PGC_INTERNAL, PRESET_OPTIONS,
2341 gettext_noop("Shows the number of pages per disk file."),
2343 GUC_UNIT_BLOCKS | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2346 RELSEG_SIZE, RELSEG_SIZE, RELSEG_SIZE,
2351 {"wal_block_size", PGC_INTERNAL, PRESET_OPTIONS,
2352 gettext_noop("Shows the block size in the write ahead log."),
2354 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2357 XLOG_BLCKSZ, XLOG_BLCKSZ, XLOG_BLCKSZ,
2362 {"wal_segment_size", PGC_INTERNAL, PRESET_OPTIONS,
2363 gettext_noop("Shows the number of pages per write ahead log segment."),
2365 GUC_UNIT_XBLOCKS | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2368 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
2369 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
2370 (XLOG_SEG_SIZE / XLOG_BLCKSZ),
2375 {"autovacuum_naptime", PGC_SIGHUP, AUTOVACUUM,
2376 gettext_noop("Time to sleep between autovacuum runs."),
2380 &autovacuum_naptime,
2381 60, 1, INT_MAX / 1000,
2385 {"autovacuum_vacuum_threshold", PGC_SIGHUP, AUTOVACUUM,
2386 gettext_noop("Minimum number of tuple updates or deletes prior to vacuum."),
2389 &autovacuum_vac_thresh,
2394 {"autovacuum_analyze_threshold", PGC_SIGHUP, AUTOVACUUM,
2395 gettext_noop("Minimum number of tuple inserts, updates, or deletes prior to analyze."),
2398 &autovacuum_anl_thresh,
2403 /* see varsup.c for why this is PGC_POSTMASTER not PGC_SIGHUP */
2404 {"autovacuum_freeze_max_age", PGC_POSTMASTER, AUTOVACUUM,
2405 gettext_noop("Age at which to autovacuum a table to prevent transaction ID wraparound."),
2408 &autovacuum_freeze_max_age,
2409 /* see pg_resetxlog if you change the upper-limit value */
2410 200000000, 100000000, 2000000000,
2414 /* see varsup.c for why this is PGC_POSTMASTER not PGC_SIGHUP */
2415 {"autovacuum_multixact_freeze_max_age", PGC_POSTMASTER, AUTOVACUUM,
2416 gettext_noop("Multixact age at which to autovacuum a table to prevent multixact wraparound."),
2419 &autovacuum_multixact_freeze_max_age,
2420 400000000, 10000000, 2000000000,
2424 /* see max_connections */
2425 {"autovacuum_max_workers", PGC_POSTMASTER, AUTOVACUUM,
2426 gettext_noop("Sets the maximum number of simultaneously running autovacuum worker processes."),
2429 &autovacuum_max_workers,
2431 check_autovacuum_max_workers, NULL, NULL
2435 {"autovacuum_work_mem", PGC_SIGHUP, RESOURCES_MEM,
2436 gettext_noop("Sets the maximum memory to be used by each autovacuum worker process."),
2440 &autovacuum_work_mem,
2441 -1, -1, MAX_KILOBYTES,
2442 check_autovacuum_work_mem, NULL, NULL
2446 {"tcp_keepalives_idle", PGC_USERSET, CLIENT_CONN_OTHER,
2447 gettext_noop("Time between issuing TCP keepalives."),
2448 gettext_noop("A value of 0 uses the system default."),
2451 &tcp_keepalives_idle,
2453 NULL, assign_tcp_keepalives_idle, show_tcp_keepalives_idle
2457 {"tcp_keepalives_interval", PGC_USERSET, CLIENT_CONN_OTHER,
2458 gettext_noop("Time between TCP keepalive retransmits."),
2459 gettext_noop("A value of 0 uses the system default."),
2462 &tcp_keepalives_interval,
2464 NULL, assign_tcp_keepalives_interval, show_tcp_keepalives_interval
2468 {"ssl_renegotiation_limit", PGC_USERSET, CONN_AUTH_SECURITY,
2469 gettext_noop("Set the amount of traffic to send and receive before renegotiating the encryption keys."),
2473 &ssl_renegotiation_limit,
2474 512 * 1024, 0, MAX_KILOBYTES,
2479 {"tcp_keepalives_count", PGC_USERSET, CLIENT_CONN_OTHER,
2480 gettext_noop("Maximum number of TCP keepalive retransmits."),
2481 gettext_noop("This controls the number of consecutive keepalive retransmits that can be "
2482 "lost before a connection is considered dead. A value of 0 uses the "
2485 &tcp_keepalives_count,
2487 NULL, assign_tcp_keepalives_count, show_tcp_keepalives_count
2491 {"gin_fuzzy_search_limit", PGC_USERSET, CLIENT_CONN_OTHER,
2492 gettext_noop("Sets the maximum allowed result for exact search by GIN."),
2496 &GinFuzzySearchLimit,
2502 {"effective_cache_size", PGC_USERSET, QUERY_TUNING_COST,
2503 gettext_noop("Sets the planner's assumption about the size of the disk cache."),
2504 gettext_noop("That is, the portion of the kernel's disk cache that "
2505 "will be used for PostgreSQL data files. This is measured in disk "
2506 "pages, which are normally 8 kB each."),
2509 &effective_cache_size,
2510 DEFAULT_EFFECTIVE_CACHE_SIZE, 1, INT_MAX,
2515 /* Can't be set in postgresql.conf */
2516 {"server_version_num", PGC_INTERNAL, PRESET_OPTIONS,
2517 gettext_noop("Shows the server version as an integer."),
2519 GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
2521 &server_version_num,
2522 PG_VERSION_NUM, PG_VERSION_NUM, PG_VERSION_NUM,
2527 {"log_temp_files", PGC_SUSET, LOGGING_WHAT,
2528 gettext_noop("Log the use of temporary files larger than this number of kilobytes."),
2529 gettext_noop("Zero logs all files. The default is -1 (turning this feature off)."),
2538 {"track_activity_query_size", PGC_POSTMASTER, RESOURCES_MEM,
2539 gettext_noop("Sets the size reserved for pg_stat_activity.query, in bytes."),
2543 * There is no _bytes_ unit, so the user can't supply units for
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."),
3094 * Can't be set by ALTER SYSTEM as it can lead to recursive definition
3095 * of data_directory.
3097 {"data_directory", PGC_POSTMASTER, FILE_LOCATIONS,
3098 gettext_noop("Sets the server's data directory."),
3100 GUC_SUPERUSER_ONLY | GUC_DISALLOW_IN_AUTO_FILE
3108 {"config_file", PGC_POSTMASTER, FILE_LOCATIONS,
3109 gettext_noop("Sets the server's main configuration file."),
3111 GUC_DISALLOW_IN_FILE | GUC_SUPERUSER_ONLY
3119 {"hba_file", PGC_POSTMASTER, FILE_LOCATIONS,
3120 gettext_noop("Sets the server's \"hba\" configuration file."),
3130 {"ident_file", PGC_POSTMASTER, FILE_LOCATIONS,
3131 gettext_noop("Sets the server's \"ident\" configuration file."),
3141 {"external_pid_file", PGC_POSTMASTER, FILE_LOCATIONS,
3142 gettext_noop("Writes the postmaster PID to the specified file."),
3148 check_canonical_path, NULL, NULL
3152 {"ssl_cert_file", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3153 gettext_noop("Location of the SSL server certificate file."),
3162 {"ssl_key_file", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3163 gettext_noop("Location of the SSL server private key file."),
3172 {"ssl_ca_file", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3173 gettext_noop("Location of the SSL certificate authority file."),
3182 {"ssl_crl_file", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3183 gettext_noop("Location of the SSL certificate revocation list file."),
3192 {"stats_temp_directory", PGC_SIGHUP, STATS_COLLECTOR,
3193 gettext_noop("Writes temporary statistics files to the specified directory."),
3197 &pgstat_temp_directory,
3199 check_canonical_path, assign_pgstat_temp_directory, NULL
3203 {"synchronous_standby_names", PGC_SIGHUP, REPLICATION_MASTER,
3204 gettext_noop("List of names of potential synchronous standbys."),
3208 &SyncRepStandbyNames,
3210 check_synchronous_standby_names, NULL, NULL
3214 {"default_text_search_config", PGC_USERSET, CLIENT_CONN_LOCALE,
3215 gettext_noop("Sets default text search configuration."),
3219 "pg_catalog.simple",
3220 check_TSCurrentConfig, assign_TSCurrentConfig, NULL
3224 {"ssl_ciphers", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3225 gettext_noop("Sets the list of allowed SSL ciphers."),
3231 "HIGH:MEDIUM:+3DES:!aNULL",
3239 {"ssl_ecdh_curve", PGC_POSTMASTER, CONN_AUTH_SECURITY,
3240 gettext_noop("Sets the curve to use for ECDH."),
3254 {"application_name", PGC_USERSET, LOGGING_WHAT,
3255 gettext_noop("Sets the application name to be reported in statistics and logs."),
3257 GUC_IS_NAME | GUC_REPORT | GUC_NOT_IN_SAMPLE
3261 check_application_name, assign_application_name, NULL
3264 /* End-of-list marker */
3266 {NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL, NULL
3271 static struct config_enum ConfigureNamesEnum[] =
3274 {"backslash_quote", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
3275 gettext_noop("Sets whether \"\\'\" is allowed in string literals."),
3279 BACKSLASH_QUOTE_SAFE_ENCODING, backslash_quote_options,
3284 {"bytea_output", PGC_USERSET, CLIENT_CONN_STATEMENT,
3285 gettext_noop("Sets the output format for bytea."),
3289 BYTEA_OUTPUT_HEX, bytea_output_options,
3294 {"client_min_messages", PGC_USERSET, LOGGING_WHEN,
3295 gettext_noop("Sets the message levels that are sent to the client."),
3296 gettext_noop("Each level includes all the levels that follow it. The later"
3297 " the level, the fewer messages are sent.")
3299 &client_min_messages,
3300 NOTICE, client_message_level_options,
3305 {"constraint_exclusion", PGC_USERSET, QUERY_TUNING_OTHER,
3306 gettext_noop("Enables the planner to use constraints to optimize queries."),
3307 gettext_noop("Table scans will be skipped if their constraints"
3308 " guarantee that no rows match the query.")
3310 &constraint_exclusion,
3311 CONSTRAINT_EXCLUSION_PARTITION, constraint_exclusion_options,
3316 {"default_transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
3317 gettext_noop("Sets the transaction isolation level of each new transaction."),
3320 &DefaultXactIsoLevel,
3321 XACT_READ_COMMITTED, isolation_level_options,
3326 {"IntervalStyle", PGC_USERSET, CLIENT_CONN_LOCALE,
3327 gettext_noop("Sets the display format for interval values."),
3332 INTSTYLE_POSTGRES, intervalstyle_options,
3337 {"log_error_verbosity", PGC_SUSET, LOGGING_WHAT,
3338 gettext_noop("Sets the verbosity of logged messages."),
3341 &Log_error_verbosity,
3342 PGERROR_DEFAULT, log_error_verbosity_options,
3347 {"log_min_messages", PGC_SUSET, LOGGING_WHEN,
3348 gettext_noop("Sets the message levels that are logged."),
3349 gettext_noop("Each level includes all the levels that follow it. The later"
3350 " the level, the fewer messages are sent.")
3353 WARNING, server_message_level_options,
3358 {"log_min_error_statement", PGC_SUSET, LOGGING_WHEN,
3359 gettext_noop("Causes all statements generating error at or above this level to be logged."),
3360 gettext_noop("Each level includes all the levels that follow it. The later"
3361 " the level, the fewer messages are sent.")
3363 &log_min_error_statement,
3364 ERROR, server_message_level_options,
3369 {"log_statement", PGC_SUSET, LOGGING_WHAT,
3370 gettext_noop("Sets the type of statements logged."),
3374 LOGSTMT_NONE, log_statement_options,
3379 {"syslog_facility", PGC_SIGHUP, LOGGING_WHERE,
3380 gettext_noop("Sets the syslog \"facility\" to be used when syslog enabled."),
3389 syslog_facility_options,
3390 NULL, assign_syslog_facility, NULL
3394 {"session_replication_role", PGC_SUSET, CLIENT_CONN_STATEMENT,
3395 gettext_noop("Sets the session's behavior for triggers and rewrite rules."),
3398 &SessionReplicationRole,
3399 SESSION_REPLICATION_ROLE_ORIGIN, session_replication_role_options,
3400 NULL, assign_session_replication_role, NULL
3404 {"synchronous_commit", PGC_USERSET, WAL_SETTINGS,
3405 gettext_noop("Sets the current transaction's synchronization level."),
3408 &synchronous_commit,
3409 SYNCHRONOUS_COMMIT_ON, synchronous_commit_options,
3410 NULL, assign_synchronous_commit, NULL
3414 {"trace_recovery_messages", PGC_SIGHUP, DEVELOPER_OPTIONS,
3415 gettext_noop("Enables logging of recovery-related debugging information."),
3416 gettext_noop("Each level includes all the levels that follow it. The later"
3417 " the level, the fewer messages are sent.")
3419 &trace_recovery_messages,
3422 * client_message_level_options allows too many values, really, but
3423 * it's not worth having a separate options array for this.
3425 LOG, client_message_level_options,
3430 {"track_functions", PGC_SUSET, STATS_COLLECTOR,
3431 gettext_noop("Collects function-level statistics on database activity."),
3434 &pgstat_track_functions,
3435 TRACK_FUNC_OFF, track_function_options,
3440 {"wal_level", PGC_POSTMASTER, WAL_SETTINGS,
3441 gettext_noop("Set the level of information written to the WAL."),
3445 WAL_LEVEL_MINIMAL, wal_level_options,
3450 {"dynamic_shared_memory_type", PGC_POSTMASTER, RESOURCES_MEM,
3451 gettext_noop("Selects the dynamic shared memory implementation used."),
3454 &dynamic_shared_memory_type,
3455 DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE, dynamic_shared_memory_options,
3460 {"wal_sync_method", PGC_SIGHUP, WAL_SETTINGS,
3461 gettext_noop("Selects the method used for forcing WAL updates to disk."),
3465 DEFAULT_SYNC_METHOD, sync_method_options,
3466 NULL, assign_xlog_sync_method, NULL
3470 {"xmlbinary", PGC_USERSET, CLIENT_CONN_STATEMENT,
3471 gettext_noop("Sets how binary values are to be encoded in XML."),
3475 XMLBINARY_BASE64, xmlbinary_options,
3480 {"xmloption", PGC_USERSET, CLIENT_CONN_STATEMENT,
3481 gettext_noop("Sets whether XML data in implicit parsing and serialization "
3482 "operations is to be considered as documents or content fragments."),
3486 XMLOPTION_CONTENT, xmloption_options,
3491 {"huge_pages", PGC_POSTMASTER, RESOURCES_MEM,
3492 gettext_noop("Use of huge pages on Linux"),
3496 HUGE_PAGES_TRY, huge_pages_options,
3500 /* End-of-list marker */
3502 {NULL, 0, 0, NULL, NULL}, NULL, 0, NULL, NULL, NULL, NULL
3506 /******** end of options list ********/
3510 * To allow continued support of obsolete names for GUC variables, we apply
3511 * the following mappings to any unrecognized name. Note that an old name
3512 * should be mapped to a new one only if the new variable has very similar
3513 * semantics to the old.
3515 static const char *const map_old_guc_names[] = {
3516 "sort_mem", "work_mem",
3517 "vacuum_mem", "maintenance_work_mem",
3523 * Actual lookup of variables is done through this single, sorted array.
3525 static struct config_generic **guc_variables;
3527 /* Current number of variables contained in the vector */
3528 static int num_guc_variables;
3530 /* Vector capacity */
3531 static int size_guc_variables;
3534 static bool guc_dirty; /* TRUE if need to do commit/abort work */
3536 static bool reporting_enabled; /* TRUE to enable GUC_REPORT */
3538 static int GUCNestLevel = 0; /* 1 when in main transaction */
3541 static int guc_var_compare(const void *a, const void *b);
3542 static int guc_name_compare(const char *namea, const char *nameb);
3543 static void InitializeGUCOptionsFromEnvironment(void);
3544 static void InitializeOneGUCOption(struct config_generic * gconf);
3545 static void push_old_value(struct config_generic * gconf, GucAction action);
3546 static void ReportGUCOption(struct config_generic * record);
3547 static void reapply_stacked_values(struct config_generic * variable,
3548 struct config_string * pHolder,
3550 const char *curvalue,
3551 GucContext curscontext, GucSource cursource);
3552 static void ShowGUCConfigOption(const char *name, DestReceiver *dest);
3553 static void ShowAllGUCConfig(DestReceiver *dest);
3554 static char *_ShowOption(struct config_generic * record, bool use_units);
3555 static bool validate_option_array_item(const char *name, const char *value,
3556 bool skipIfNoPermissions);
3557 static void write_auto_conf_file(int fd, const char *filename, ConfigVariable **head_p);
3558 static void replace_auto_config_value(ConfigVariable **head_p, ConfigVariable **tail_p,
3559 char *config_file, char *name, char *value);
3563 * Some infrastructure for checking malloc/strdup/realloc calls
3566 guc_malloc(int elevel, size_t size)
3570 /* Avoid unportable behavior of malloc(0) */
3573 data = malloc(size);
3576 (errcode(ERRCODE_OUT_OF_MEMORY),
3577 errmsg("out of memory")));
3582 guc_realloc(int elevel, void *old, size_t size)
3586 /* Avoid unportable behavior of realloc(NULL, 0) */
3587 if (old == NULL && size == 0)
3589 data = realloc(old, size);
3592 (errcode(ERRCODE_OUT_OF_MEMORY),
3593 errmsg("out of memory")));
3598 guc_strdup(int elevel, const char *src)
3605 (errcode(ERRCODE_OUT_OF_MEMORY),
3606 errmsg("out of memory")));
3612 * Detect whether strval is referenced anywhere in a GUC string item
3615 string_field_used(struct config_string * conf, char *strval)
3619 if (strval == *(conf->variable) ||
3620 strval == conf->reset_val ||
3621 strval == conf->boot_val)
3623 for (stack = conf->gen.stack; stack; stack = stack->prev)
3625 if (strval == stack->prior.val.stringval ||
3626 strval == stack->masked.val.stringval)
3633 * Support for assigning to a field of a string GUC item. Free the prior
3634 * value if it's not referenced anywhere else in the item (including stacked
3638 set_string_field(struct config_string * conf, char **field, char *newval)
3640 char *oldval = *field;
3642 /* Do the assignment */
3645 /* Free old value if it's not NULL and isn't referenced anymore */
3646 if (oldval && !string_field_used(conf, oldval))
3651 * Detect whether an "extra" struct is referenced anywhere in a GUC item
3654 extra_field_used(struct config_generic * gconf, void *extra)
3658 if (extra == gconf->extra)
3660 switch (gconf->vartype)
3663 if (extra == ((struct config_bool *) gconf)->reset_extra)
3667 if (extra == ((struct config_int *) gconf)->reset_extra)
3671 if (extra == ((struct config_real *) gconf)->reset_extra)
3675 if (extra == ((struct config_string *) gconf)->reset_extra)
3679 if (extra == ((struct config_enum *) gconf)->reset_extra)
3683 for (stack = gconf->stack; stack; stack = stack->prev)
3685 if (extra == stack->prior.extra ||
3686 extra == stack->masked.extra)
3694 * Support for assigning to an "extra" field of a GUC item. Free the prior
3695 * value if it's not referenced anywhere else in the item (including stacked
3699 set_extra_field(struct config_generic * gconf, void **field, void *newval)
3701 void *oldval = *field;
3703 /* Do the assignment */
3706 /* Free old value if it's not NULL and isn't referenced anymore */
3707 if (oldval && !extra_field_used(gconf, oldval))
3712 * Support for copying a variable's active value into a stack entry.
3713 * The "extra" field associated with the active value is copied, too.
3715 * NB: be sure stringval and extra fields of a new stack entry are
3716 * initialized to NULL before this is used, else we'll try to free() them.
3719 set_stack_value(struct config_generic * gconf, config_var_value *val)
3721 switch (gconf->vartype)
3725 *((struct config_bool *) gconf)->variable;
3729 *((struct config_int *) gconf)->variable;
3733 *((struct config_real *) gconf)->variable;
3736 set_string_field((struct config_string *) gconf,
3737 &(val->val.stringval),
3738 *((struct config_string *) gconf)->variable);
3742 *((struct config_enum *) gconf)->variable;
3745 set_extra_field(gconf, &(val->extra), gconf->extra);
3749 * Support for discarding a no-longer-needed value in a stack entry.
3750 * The "extra" field associated with the stack entry is cleared, too.
3753 discard_stack_value(struct config_generic * gconf, config_var_value *val)
3755 switch (gconf->vartype)
3761 /* no need to do anything */
3764 set_string_field((struct config_string *) gconf,
3765 &(val->val.stringval),
3769 set_extra_field(gconf, &(val->extra), NULL);
3774 * Fetch the sorted array pointer (exported for help_config.c's use ONLY)
3776 struct config_generic **
3777 get_guc_variables(void)
3779 return guc_variables;
3784 * Build the sorted array. This is split out so that it could be
3785 * re-executed after startup (eg, we could allow loadable modules to
3786 * add vars, and then we'd need to re-sort).
3789 build_guc_variables(void)
3793 struct config_generic **guc_vars;
3796 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
3798 struct config_bool *conf = &ConfigureNamesBool[i];
3800 /* Rather than requiring vartype to be filled in by hand, do this: */
3801 conf->gen.vartype = PGC_BOOL;
3805 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
3807 struct config_int *conf = &ConfigureNamesInt[i];
3809 conf->gen.vartype = PGC_INT;
3813 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
3815 struct config_real *conf = &ConfigureNamesReal[i];
3817 conf->gen.vartype = PGC_REAL;
3821 for (i = 0; ConfigureNamesString[i].gen.name; i++)
3823 struct config_string *conf = &ConfigureNamesString[i];
3825 conf->gen.vartype = PGC_STRING;
3829 for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
3831 struct config_enum *conf = &ConfigureNamesEnum[i];
3833 conf->gen.vartype = PGC_ENUM;
3838 * Create table with 20% slack
3840 size_vars = num_vars + num_vars / 4;
3842 guc_vars = (struct config_generic **)
3843 guc_malloc(FATAL, size_vars * sizeof(struct config_generic *));
3847 for (i = 0; ConfigureNamesBool[i].gen.name; i++)
3848 guc_vars[num_vars++] = &ConfigureNamesBool[i].gen;
3850 for (i = 0; ConfigureNamesInt[i].gen.name; i++)
3851 guc_vars[num_vars++] = &ConfigureNamesInt[i].gen;
3853 for (i = 0; ConfigureNamesReal[i].gen.name; i++)
3854 guc_vars[num_vars++] = &ConfigureNamesReal[i].gen;
3856 for (i = 0; ConfigureNamesString[i].gen.name; i++)
3857 guc_vars[num_vars++] = &ConfigureNamesString[i].gen;
3859 for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
3860 guc_vars[num_vars++] = &ConfigureNamesEnum[i].gen;
3863 free(guc_variables);
3864 guc_variables = guc_vars;
3865 num_guc_variables = num_vars;
3866 size_guc_variables = size_vars;
3867 qsort((void *) guc_variables, num_guc_variables,
3868 sizeof(struct config_generic *), guc_var_compare);
3872 * Add a new GUC variable to the list of known variables. The
3873 * list is expanded if needed.
3876 add_guc_variable(struct config_generic * var, int elevel)
3878 if (num_guc_variables + 1 >= size_guc_variables)
3881 * Increase the vector by 25%
3883 int size_vars = size_guc_variables + size_guc_variables / 4;
3884 struct config_generic **guc_vars;
3889 guc_vars = (struct config_generic **)
3890 guc_malloc(elevel, size_vars * sizeof(struct config_generic *));
3894 guc_vars = (struct config_generic **)
3895 guc_realloc(elevel, guc_variables, size_vars * sizeof(struct config_generic *));
3898 if (guc_vars == NULL)
3899 return false; /* out of memory */
3901 guc_variables = guc_vars;
3902 size_guc_variables = size_vars;
3904 guc_variables[num_guc_variables++] = var;
3905 qsort((void *) guc_variables, num_guc_variables,
3906 sizeof(struct config_generic *), guc_var_compare);
3911 * Create and add a placeholder variable for a custom variable name.
3913 static struct config_generic *
3914 add_placeholder_variable(const char *name, int elevel)
3916 size_t sz = sizeof(struct config_string) + sizeof(char *);
3917 struct config_string *var;
3918 struct config_generic *gen;
3920 var = (struct config_string *) guc_malloc(elevel, sz);
3926 gen->name = guc_strdup(elevel, name);
3927 if (gen->name == NULL)
3933 gen->context = PGC_USERSET;
3934 gen->group = CUSTOM_OPTIONS;
3935 gen->short_desc = "GUC placeholder variable";
3936 gen->flags = GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_CUSTOM_PLACEHOLDER;
3937 gen->vartype = PGC_STRING;
3940 * The char* is allocated at the end of the struct since we have no
3941 * 'static' place to point to. Note that the current value, as well as
3942 * the boot and reset values, start out NULL.
3944 var->variable = (char **) (var + 1);
3946 if (!add_guc_variable((struct config_generic *) var, elevel))
3948 free((void *) gen->name);
3957 * Look up option NAME. If it exists, return a pointer to its record,
3958 * else return NULL. If create_placeholders is TRUE, we'll create a
3959 * placeholder record for a valid-looking custom variable name.
3961 static struct config_generic *
3962 find_option(const char *name, bool create_placeholders, int elevel)
3964 const char **key = &name;
3965 struct config_generic **res;
3971 * By equating const char ** with struct config_generic *, we are assuming
3972 * the name field is first in config_generic.
3974 res = (struct config_generic **) bsearch((void *) &key,
3975 (void *) guc_variables,
3977 sizeof(struct config_generic *),
3983 * See if the name is an obsolete name for a variable. We assume that the
3984 * set of supported old names is short enough that a brute-force search is
3987 for (i = 0; map_old_guc_names[i] != NULL; i += 2)
3989 if (guc_name_compare(name, map_old_guc_names[i]) == 0)
3990 return find_option(map_old_guc_names[i + 1], false, elevel);
3993 if (create_placeholders)
3996 * Check if the name is qualified, and if so, add a placeholder.
3998 if (strchr(name, GUC_QUALIFIER_SEPARATOR) != NULL)
3999 return add_placeholder_variable(name, elevel);
4008 * comparator for qsorting and bsearching guc_variables array
4011 guc_var_compare(const void *a, const void *b)
4013 const struct config_generic *confa = *(struct config_generic * const *) a;
4014 const struct config_generic *confb = *(struct config_generic * const *) b;
4016 return guc_name_compare(confa->name, confb->name);
4020 * the bare comparison function for GUC names
4023 guc_name_compare(const char *namea, const char *nameb)
4026 * The temptation to use strcasecmp() here must be resisted, because the
4027 * array ordering has to remain stable across setlocale() calls. So, build
4028 * our own with a simple ASCII-only downcasing.
4030 while (*namea && *nameb)
4032 char cha = *namea++;
4033 char chb = *nameb++;
4035 if (cha >= 'A' && cha <= 'Z')
4037 if (chb >= 'A' && chb <= 'Z')
4043 return 1; /* a is longer */
4045 return -1; /* b is longer */
4051 * Initialize GUC options during program startup.
4053 * Note that we cannot read the config file yet, since we have not yet
4054 * processed command-line switches.
4057 InitializeGUCOptions(void)
4062 * Before log_line_prefix could possibly receive a nonempty setting, make
4063 * sure that timezone processing is minimally alive (see elog.c).
4065 pg_timezone_initialize();
4068 * Build sorted array of all GUC variables.
4070 build_guc_variables();
4073 * Load all variables with their compiled-in defaults, and initialize
4074 * status fields as needed.
4076 for (i = 0; i < num_guc_variables; i++)
4078 InitializeOneGUCOption(guc_variables[i]);
4083 reporting_enabled = false;
4086 * Prevent any attempt to override the transaction modes from
4087 * non-interactive sources.
4089 SetConfigOption("transaction_isolation", "default",
4090 PGC_POSTMASTER, PGC_S_OVERRIDE);
4091 SetConfigOption("transaction_read_only", "no",
4092 PGC_POSTMASTER, PGC_S_OVERRIDE);
4093 SetConfigOption("transaction_deferrable", "no",
4094 PGC_POSTMASTER, PGC_S_OVERRIDE);
4097 * For historical reasons, some GUC parameters can receive defaults from
4098 * environment variables. Process those settings.
4100 InitializeGUCOptionsFromEnvironment();
4104 * Assign any GUC values that can come from the server's environment.
4106 * This is called from InitializeGUCOptions, and also from ProcessConfigFile
4107 * to deal with the possibility that a setting has been removed from
4108 * postgresql.conf and should now get a value from the environment.
4109 * (The latter is a kludge that should probably go away someday; if so,
4110 * fold this back into InitializeGUCOptions.)
4113 InitializeGUCOptionsFromEnvironment(void)
4118 env = getenv("PGPORT");
4120 SetConfigOption("port", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
4122 env = getenv("PGDATESTYLE");
4124 SetConfigOption("datestyle", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
4126 env = getenv("PGCLIENTENCODING");
4128 SetConfigOption("client_encoding", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
4131 * rlimit isn't exactly an "environment variable", but it behaves about
4132 * the same. If we can identify the platform stack depth rlimit, increase
4133 * default stack depth setting up to whatever is safe (but at most 2MB).
4135 stack_rlimit = get_stack_depth_rlimit();
4136 if (stack_rlimit > 0)
4138 long new_limit = (stack_rlimit - STACK_DEPTH_SLOP) / 1024L;
4140 if (new_limit > 100)
4144 new_limit = Min(new_limit, 2048);
4145 sprintf(limbuf, "%ld", new_limit);
4146 SetConfigOption("max_stack_depth", limbuf,
4147 PGC_POSTMASTER, PGC_S_ENV_VAR);
4153 * Initialize one GUC option variable to its compiled-in default.
4155 * Note: the reason for calling check_hooks is not that we think the boot_val
4156 * might fail, but that the hooks might wish to compute an "extra" struct.
4159 InitializeOneGUCOption(struct config_generic * gconf)
4162 gconf->source = PGC_S_DEFAULT;
4163 gconf->reset_source = PGC_S_DEFAULT;
4164 gconf->scontext = PGC_INTERNAL;
4165 gconf->reset_scontext = PGC_INTERNAL;
4166 gconf->stack = NULL;
4167 gconf->extra = NULL;
4168 gconf->sourcefile = NULL;
4169 gconf->sourceline = 0;
4171 switch (gconf->vartype)
4175 struct config_bool *conf = (struct config_bool *) gconf;
4176 bool newval = conf->boot_val;
4179 if (!call_bool_check_hook(conf, &newval, &extra,
4180 PGC_S_DEFAULT, LOG))
4181 elog(FATAL, "failed to initialize %s to %d",
4182 conf->gen.name, (int) newval);
4183 if (conf->assign_hook)
4184 (*conf->assign_hook) (newval, extra);
4185 *conf->variable = conf->reset_val = newval;
4186 conf->gen.extra = conf->reset_extra = extra;
4191 struct config_int *conf = (struct config_int *) gconf;
4192 int newval = conf->boot_val;
4195 Assert(newval >= conf->min);
4196 Assert(newval <= conf->max);
4197 if (!call_int_check_hook(conf, &newval, &extra,
4198 PGC_S_DEFAULT, LOG))
4199 elog(FATAL, "failed to initialize %s to %d",
4200 conf->gen.name, newval);
4201 if (conf->assign_hook)
4202 (*conf->assign_hook) (newval, extra);
4203 *conf->variable = conf->reset_val = newval;
4204 conf->gen.extra = conf->reset_extra = extra;
4209 struct config_real *conf = (struct config_real *) gconf;
4210 double newval = conf->boot_val;
4213 Assert(newval >= conf->min);
4214 Assert(newval <= conf->max);
4215 if (!call_real_check_hook(conf, &newval, &extra,
4216 PGC_S_DEFAULT, LOG))
4217 elog(FATAL, "failed to initialize %s to %g",
4218 conf->gen.name, newval);
4219 if (conf->assign_hook)
4220 (*conf->assign_hook) (newval, extra);
4221 *conf->variable = conf->reset_val = newval;
4222 conf->gen.extra = conf->reset_extra = extra;
4227 struct config_string *conf = (struct config_string *) gconf;
4231 /* non-NULL boot_val must always get strdup'd */
4232 if (conf->boot_val != NULL)
4233 newval = guc_strdup(FATAL, conf->boot_val);
4237 if (!call_string_check_hook(conf, &newval, &extra,
4238 PGC_S_DEFAULT, LOG))
4239 elog(FATAL, "failed to initialize %s to \"%s\"",
4240 conf->gen.name, newval ? newval : "");
4241 if (conf->assign_hook)
4242 (*conf->assign_hook) (newval, extra);
4243 *conf->variable = conf->reset_val = newval;
4244 conf->gen.extra = conf->reset_extra = extra;
4249 struct config_enum *conf = (struct config_enum *) gconf;
4250 int newval = conf->boot_val;
4253 if (!call_enum_check_hook(conf, &newval, &extra,
4254 PGC_S_DEFAULT, LOG))
4255 elog(FATAL, "failed to initialize %s to %d",
4256 conf->gen.name, newval);
4257 if (conf->assign_hook)
4258 (*conf->assign_hook) (newval, extra);
4259 *conf->variable = conf->reset_val = newval;
4260 conf->gen.extra = conf->reset_extra = extra;
4268 * Select the configuration files and data directory to be used, and
4269 * do the initial read of postgresql.conf.
4271 * This is called after processing command-line switches.
4272 * userDoption is the -D switch value if any (NULL if unspecified).
4273 * progname is just for use in error messages.
4275 * Returns true on success; on failure, prints a suitable error message
4276 * to stderr and returns false.
4279 SelectConfigFiles(const char *userDoption, const char *progname)
4283 struct stat stat_buf;
4285 /* configdir is -D option, or $PGDATA if no -D */
4287 configdir = make_absolute_path(userDoption);
4289 configdir = make_absolute_path(getenv("PGDATA"));
4292 * Find the configuration file: if config_file was specified on the
4293 * command line, use it, else use configdir/postgresql.conf. In any case
4294 * ensure the result is an absolute path, so that it will be interpreted
4295 * the same way by future backends.
4298 fname = make_absolute_path(ConfigFileName);
4301 fname = guc_malloc(FATAL,
4302 strlen(configdir) + strlen(CONFIG_FILENAME) + 2);
4303 sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME);
4307 write_stderr("%s does not know where to find the server configuration file.\n"
4308 "You must specify the --config-file or -D invocation "
4309 "option or set the PGDATA environment variable.\n",
4315 * Set the ConfigFileName GUC variable to its final value, ensuring that
4316 * it can't be overridden later.
4318 SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4322 * Now read the config file for the first time.
4324 if (stat(ConfigFileName, &stat_buf) != 0)
4326 write_stderr("%s cannot access the server configuration file \"%s\": %s\n",
4327 progname, ConfigFileName, strerror(errno));
4332 ProcessConfigFile(PGC_POSTMASTER);
4335 * If the data_directory GUC variable has been set, use that as DataDir;
4336 * otherwise use configdir if set; else punt.
4338 * Note: SetDataDir will copy and absolute-ize its argument, so we don't
4342 SetDataDir(data_directory);
4344 SetDataDir(configdir);
4347 write_stderr("%s does not know where to find the database system data.\n"
4348 "This can be specified as \"data_directory\" in \"%s\", "
4349 "or by the -D invocation option, or by the "
4350 "PGDATA environment variable.\n",
4351 progname, ConfigFileName);
4356 * Reflect the final DataDir value back into the data_directory GUC var.
4357 * (If you are wondering why we don't just make them a single variable,
4358 * it's because the EXEC_BACKEND case needs DataDir to be transmitted to
4359 * child backends specially. XXX is that still true? Given that we now
4360 * chdir to DataDir, EXEC_BACKEND can read the config file without knowing
4361 * DataDir in advance.)
4363 SetConfigOption("data_directory", DataDir, PGC_POSTMASTER, PGC_S_OVERRIDE);
4366 * Now read the config file a second time, allowing any settings in
4367 * the PG_AUTOCONF_FILENAME file to take effect. (This is pretty ugly,
4368 * but since we have to determine the DataDir before we can find the
4369 * autoconf file, the alternatives seem worse.)
4371 ProcessConfigFile(PGC_POSTMASTER);
4374 * If timezone_abbreviations wasn't set in the configuration file, install
4375 * the default value. We do it this way because we can't safely install a
4376 * "real" value until my_exec_path is set, which may not have happened
4377 * when InitializeGUCOptions runs, so the bootstrap default value cannot
4378 * be the real desired default.
4380 pg_timezone_abbrev_initialize();
4383 * Figure out where pg_hba.conf is, and make sure the path is absolute.
4386 fname = make_absolute_path(HbaFileName);
4389 fname = guc_malloc(FATAL,
4390 strlen(configdir) + strlen(HBA_FILENAME) + 2);
4391 sprintf(fname, "%s/%s", configdir, HBA_FILENAME);
4395 write_stderr("%s does not know where to find the \"hba\" configuration file.\n"
4396 "This can be specified as \"hba_file\" in \"%s\", "
4397 "or by the -D invocation option, or by the "
4398 "PGDATA environment variable.\n",
4399 progname, ConfigFileName);
4402 SetConfigOption("hba_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4406 * Likewise for pg_ident.conf.
4409 fname = make_absolute_path(IdentFileName);
4412 fname = guc_malloc(FATAL,
4413 strlen(configdir) + strlen(IDENT_FILENAME) + 2);
4414 sprintf(fname, "%s/%s", configdir, IDENT_FILENAME);
4418 write_stderr("%s does not know where to find the \"ident\" configuration file.\n"
4419 "This can be specified as \"ident_file\" in \"%s\", "
4420 "or by the -D invocation option, or by the "
4421 "PGDATA environment variable.\n",
4422 progname, ConfigFileName);
4425 SetConfigOption("ident_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE);
4435 * Reset all options to their saved default values (implements RESET ALL)
4438 ResetAllOptions(void)
4442 for (i = 0; i < num_guc_variables; i++)
4444 struct config_generic *gconf = guc_variables[i];
4446 /* Don't reset non-SET-able values */
4447 if (gconf->context != PGC_SUSET &&
4448 gconf->context != PGC_USERSET)
4450 /* Don't reset if special exclusion from RESET ALL */
4451 if (gconf->flags & GUC_NO_RESET_ALL)
4453 /* No need to reset if wasn't SET */
4454 if (gconf->source <= PGC_S_OVERRIDE)
4457 /* Save old value to support transaction abort */
4458 push_old_value(gconf, GUC_ACTION_SET);
4460 switch (gconf->vartype)
4464 struct config_bool *conf = (struct config_bool *) gconf;
4466 if (conf->assign_hook)
4467 (*conf->assign_hook) (conf->reset_val,
4469 *conf->variable = conf->reset_val;
4470 set_extra_field(&conf->gen, &conf->gen.extra,
4476 struct config_int *conf = (struct config_int *) gconf;
4478 if (conf->assign_hook)
4479 (*conf->assign_hook) (conf->reset_val,
4481 *conf->variable = conf->reset_val;
4482 set_extra_field(&conf->gen, &conf->gen.extra,
4488 struct config_real *conf = (struct config_real *) gconf;
4490 if (conf->assign_hook)
4491 (*conf->assign_hook) (conf->reset_val,
4493 *conf->variable = conf->reset_val;
4494 set_extra_field(&conf->gen, &conf->gen.extra,
4500 struct config_string *conf = (struct config_string *) gconf;
4502 if (conf->assign_hook)
4503 (*conf->assign_hook) (conf->reset_val,
4505 set_string_field(conf, conf->variable, conf->reset_val);
4506 set_extra_field(&conf->gen, &conf->gen.extra,
4512 struct config_enum *conf = (struct config_enum *) gconf;
4514 if (conf->assign_hook)
4515 (*conf->assign_hook) (conf->reset_val,
4517 *conf->variable = conf->reset_val;
4518 set_extra_field(&conf->gen, &conf->gen.extra,
4524 gconf->source = gconf->reset_source;
4525 gconf->scontext = gconf->reset_scontext;
4527 if (gconf->flags & GUC_REPORT)
4528 ReportGUCOption(gconf);
4535 * Push previous state during transactional assignment to a GUC variable.
4538 push_old_value(struct config_generic * gconf, GucAction action)
4542 /* If we're not inside a nest level, do nothing */
4543 if (GUCNestLevel == 0)
4546 /* Do we already have a stack entry of the current nest level? */
4547 stack = gconf->stack;
4548 if (stack && stack->nest_level >= GUCNestLevel)
4550 /* Yes, so adjust its state if necessary */
4551 Assert(stack->nest_level == GUCNestLevel);
4554 case GUC_ACTION_SET:
4555 /* SET overrides any prior action at same nest level */
4556 if (stack->state == GUC_SET_LOCAL)
4558 /* must discard old masked value */
4559 discard_stack_value(gconf, &stack->masked);
4561 stack->state = GUC_SET;
4563 case GUC_ACTION_LOCAL:
4564 if (stack->state == GUC_SET)
4566 /* SET followed by SET LOCAL, remember SET's value */
4567 stack->masked_scontext = gconf->scontext;
4568 set_stack_value(gconf, &stack->masked);
4569 stack->state = GUC_SET_LOCAL;
4571 /* in all other cases, no change to stack entry */
4573 case GUC_ACTION_SAVE:
4574 /* Could only have a prior SAVE of same variable */
4575 Assert(stack->state == GUC_SAVE);
4578 Assert(guc_dirty); /* must be set already */
4583 * Push a new stack entry
4585 * We keep all the stack entries in TopTransactionContext for simplicity.
4587 stack = (GucStack *) MemoryContextAllocZero(TopTransactionContext,
4590 stack->prev = gconf->stack;
4591 stack->nest_level = GUCNestLevel;
4594 case GUC_ACTION_SET:
4595 stack->state = GUC_SET;
4597 case GUC_ACTION_LOCAL:
4598 stack->state = GUC_LOCAL;
4600 case GUC_ACTION_SAVE:
4601 stack->state = GUC_SAVE;
4604 stack->source = gconf->source;
4605 stack->scontext = gconf->scontext;
4606 set_stack_value(gconf, &stack->prior);
4608 gconf->stack = stack;
4610 /* Ensure we remember to pop at end of xact */
4616 * Do GUC processing at main transaction start.
4622 * The nest level should be 0 between transactions; if it isn't, somebody
4623 * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
4624 * throw a warning but make no other effort to clean up.
4626 if (GUCNestLevel != 0)
4627 elog(WARNING, "GUC nest level = %d at transaction start",
4633 * Enter a new nesting level for GUC values. This is called at subtransaction
4634 * start, and when entering a function that has proconfig settings, and in
4635 * some other places where we want to set GUC variables transiently.
4636 * NOTE we must not risk error here, else subtransaction start will be unhappy.
4639 NewGUCNestLevel(void)
4641 return ++GUCNestLevel;
4645 * Do GUC processing at transaction or subtransaction commit or abort, or
4646 * when exiting a function that has proconfig settings, or when undoing a
4647 * transient assignment to some GUC variables. (The name is thus a bit of
4648 * a misnomer; perhaps it should be ExitGUCNestLevel or some such.)
4649 * During abort, we discard all GUC settings that were applied at nesting
4650 * levels >= nestLevel. nestLevel == 1 corresponds to the main transaction.
4653 AtEOXact_GUC(bool isCommit, int nestLevel)
4659 * Note: it's possible to get here with GUCNestLevel == nestLevel-1 during
4660 * abort, if there is a failure during transaction start before
4661 * AtStart_GUC is called.
4663 Assert(nestLevel > 0 &&
4664 (nestLevel <= GUCNestLevel ||
4665 (nestLevel == GUCNestLevel + 1 && !isCommit)));
4667 /* Quick exit if nothing's changed in this transaction */
4670 GUCNestLevel = nestLevel - 1;
4674 still_dirty = false;
4675 for (i = 0; i < num_guc_variables; i++)
4677 struct config_generic *gconf = guc_variables[i];
4681 * Process and pop each stack entry within the nest level. To simplify
4682 * fmgr_security_definer() and other places that use GUC_ACTION_SAVE,
4683 * we allow failure exit from code that uses a local nest level to be
4684 * recovered at the surrounding transaction or subtransaction abort;
4685 * so there could be more than one stack entry to pop.
4687 while ((stack = gconf->stack) != NULL &&
4688 stack->nest_level >= nestLevel)
4690 GucStack *prev = stack->prev;
4691 bool restorePrior = false;
4692 bool restoreMasked = false;
4696 * In this next bit, if we don't set either restorePrior or
4697 * restoreMasked, we must "discard" any unwanted fields of the
4698 * stack entries to avoid leaking memory. If we do set one of
4699 * those flags, unused fields will be cleaned up after restoring.
4701 if (!isCommit) /* if abort, always restore prior value */
4702 restorePrior = true;
4703 else if (stack->state == GUC_SAVE)
4704 restorePrior = true;
4705 else if (stack->nest_level == 1)
4707 /* transaction commit */
4708 if (stack->state == GUC_SET_LOCAL)
4709 restoreMasked = true;
4710 else if (stack->state == GUC_SET)
4712 /* we keep the current active value */
4713 discard_stack_value(gconf, &stack->prior);
4715 else /* must be GUC_LOCAL */
4716 restorePrior = true;
4718 else if (prev == NULL ||
4719 prev->nest_level < stack->nest_level - 1)
4721 /* decrement entry's level and do not pop it */
4722 stack->nest_level--;
4728 * We have to merge this stack entry into prev. See README for
4729 * discussion of this bit.
4731 switch (stack->state)
4734 Assert(false); /* can't get here */
4737 /* next level always becomes SET */
4738 discard_stack_value(gconf, &stack->prior);
4739 if (prev->state == GUC_SET_LOCAL)
4740 discard_stack_value(gconf, &prev->masked);
4741 prev->state = GUC_SET;
4745 if (prev->state == GUC_SET)
4747 /* LOCAL migrates down */
4748 prev->masked_scontext = stack->scontext;
4749 prev->masked = stack->prior;
4750 prev->state = GUC_SET_LOCAL;
4754 /* else just forget this stack level */
4755 discard_stack_value(gconf, &stack->prior);
4760 /* prior state at this level no longer wanted */
4761 discard_stack_value(gconf, &stack->prior);
4762 /* copy down the masked state */
4763 prev->masked_scontext = stack->masked_scontext;
4764 if (prev->state == GUC_SET_LOCAL)
4765 discard_stack_value(gconf, &prev->masked);
4766 prev->masked = stack->masked;
4767 prev->state = GUC_SET_LOCAL;
4774 if (restorePrior || restoreMasked)
4776 /* Perform appropriate restoration of the stacked value */
4777 config_var_value newvalue;
4778 GucSource newsource;
4779 GucContext newscontext;
4783 newvalue = stack->masked;
4784 newsource = PGC_S_SESSION;
4785 newscontext = stack->masked_scontext;
4789 newvalue = stack->prior;
4790 newsource = stack->source;
4791 newscontext = stack->scontext;
4794 switch (gconf->vartype)
4798 struct config_bool *conf = (struct config_bool *) gconf;
4799 bool newval = newvalue.val.boolval;
4800 void *newextra = newvalue.extra;
4802 if (*conf->variable != newval ||
4803 conf->gen.extra != newextra)
4805 if (conf->assign_hook)
4806 (*conf->assign_hook) (newval, newextra);
4807 *conf->variable = newval;
4808 set_extra_field(&conf->gen, &conf->gen.extra,
4816 struct config_int *conf = (struct config_int *) gconf;
4817 int newval = newvalue.val.intval;
4818 void *newextra = newvalue.extra;
4820 if (*conf->variable != newval ||
4821 conf->gen.extra != newextra)
4823 if (conf->assign_hook)
4824 (*conf->assign_hook) (newval, newextra);
4825 *conf->variable = newval;
4826 set_extra_field(&conf->gen, &conf->gen.extra,
4834 struct config_real *conf = (struct config_real *) gconf;
4835 double newval = newvalue.val.realval;
4836 void *newextra = newvalue.extra;
4838 if (*conf->variable != newval ||
4839 conf->gen.extra != newextra)
4841 if (conf->assign_hook)
4842 (*conf->assign_hook) (newval, newextra);
4843 *conf->variable = newval;
4844 set_extra_field(&conf->gen, &conf->gen.extra,
4852 struct config_string *conf = (struct config_string *) gconf;
4853 char *newval = newvalue.val.stringval;
4854 void *newextra = newvalue.extra;
4856 if (*conf->variable != newval ||
4857 conf->gen.extra != newextra)
4859 if (conf->assign_hook)
4860 (*conf->assign_hook) (newval, newextra);
4861 set_string_field(conf, conf->variable, newval);
4862 set_extra_field(&conf->gen, &conf->gen.extra,
4868 * Release stacked values if not used anymore. We
4869 * could use discard_stack_value() here, but since
4870 * we have type-specific code anyway, might as
4873 set_string_field(conf, &stack->prior.val.stringval, NULL);
4874 set_string_field(conf, &stack->masked.val.stringval, NULL);
4879 struct config_enum *conf = (struct config_enum *) gconf;
4880 int newval = newvalue.val.enumval;
4881 void *newextra = newvalue.extra;
4883 if (*conf->variable != newval ||
4884 conf->gen.extra != newextra)
4886 if (conf->assign_hook)
4887 (*conf->assign_hook) (newval, newextra);
4888 *conf->variable = newval;
4889 set_extra_field(&conf->gen, &conf->gen.extra,
4898 * Release stacked extra values if not used anymore.
4900 set_extra_field(gconf, &(stack->prior.extra), NULL);
4901 set_extra_field(gconf, &(stack->masked.extra), NULL);
4903 /* And restore source information */
4904 gconf->source = newsource;
4905 gconf->scontext = newscontext;
4908 /* Finish popping the state stack */
4909 gconf->stack = prev;
4912 /* Report new value if we changed it */
4913 if (changed && (gconf->flags & GUC_REPORT))
4914 ReportGUCOption(gconf);
4915 } /* end of stack-popping loop */
4921 /* If there are no remaining stack entries, we can reset guc_dirty */
4922 guc_dirty = still_dirty;
4924 /* Update nesting level */
4925 GUCNestLevel = nestLevel - 1;
4930 * Start up automatic reporting of changes to variables marked GUC_REPORT.
4931 * This is executed at completion of backend startup.
4934 BeginReportingGUCOptions(void)
4939 * Don't do anything unless talking to an interactive frontend of protocol
4942 if (whereToSendOutput != DestRemote ||
4943 PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
4946 reporting_enabled = true;
4948 /* Transmit initial values of interesting variables */
4949 for (i = 0; i < num_guc_variables; i++)
4951 struct config_generic *conf = guc_variables[i];
4953 if (conf->flags & GUC_REPORT)
4954 ReportGUCOption(conf);
4959 * ReportGUCOption: if appropriate, transmit option value to frontend
4962 ReportGUCOption(struct config_generic * record)
4964 if (reporting_enabled && (record->flags & GUC_REPORT))
4966 char *val = _ShowOption(record, false);
4967 StringInfoData msgbuf;
4969 pq_beginmessage(&msgbuf, 'S');
4970 pq_sendstring(&msgbuf, record->name);
4971 pq_sendstring(&msgbuf, val);
4972 pq_endmessage(&msgbuf);
4979 * Try to parse value as an integer. The accepted formats are the
4980 * usual decimal, octal, or hexadecimal formats, optionally followed by
4981 * a unit name if "flags" indicates a unit is allowed.
4983 * If the string parses okay, return true, else false.
4984 * If okay and result is not NULL, return the value in *result.
4985 * If not okay and hintmsg is not NULL, *hintmsg is set to a suitable
4986 * HINT message, or NULL if no hint provided.
4989 parse_int(const char *value, int *result, int flags, const char **hintmsg)
4994 /* To suppress compiler warnings, always set output params */
5000 /* We assume here that int64 is at least as wide as long */
5002 val = strtol(value, &endptr, 0);
5004 if (endptr == value)
5005 return false; /* no HINT for integer syntax error */
5007 if (errno == ERANGE || val != (int64) ((int32) val))
5010 *hintmsg = gettext_noop("Value exceeds integer range.");
5014 /* allow whitespace between integer and unit */
5015 while (isspace((unsigned char) *endptr))
5018 /* Handle possible unit */
5019 if (*endptr != '\0')
5022 * Note: the multiple-switch coding technique here is a bit tedious,
5023 * but seems necessary to avoid intermediate-value overflows.
5025 if (flags & GUC_UNIT_MEMORY)
5027 /* Set hint for use if no match or trailing garbage */
5029 *hintmsg = gettext_noop("Valid units for this parameter are \"kB\", \"MB\", \"GB\", and \"TB\".");
5031 #if BLCKSZ < 1024 || BLCKSZ > (1024*1024)
5032 #error BLCKSZ must be between 1KB and 1MB
5034 #if XLOG_BLCKSZ < 1024 || XLOG_BLCKSZ > (1024*1024)
5035 #error XLOG_BLCKSZ must be between 1KB and 1MB
5038 if (strncmp(endptr, "kB", 2) == 0)
5041 switch (flags & GUC_UNIT_MEMORY)
5043 case GUC_UNIT_BLOCKS:
5044 val /= (BLCKSZ / 1024);
5046 case GUC_UNIT_XBLOCKS:
5047 val /= (XLOG_BLCKSZ / 1024);
5051 else if (strncmp(endptr, "MB", 2) == 0)
5054 switch (flags & GUC_UNIT_MEMORY)
5059 case GUC_UNIT_BLOCKS:
5060 val *= KB_PER_MB / (BLCKSZ / 1024);
5062 case GUC_UNIT_XBLOCKS:
5063 val *= KB_PER_MB / (XLOG_BLCKSZ / 1024);
5067 else if (strncmp(endptr, "GB", 2) == 0)
5070 switch (flags & GUC_UNIT_MEMORY)
5075 case GUC_UNIT_BLOCKS:
5076 val *= KB_PER_GB / (BLCKSZ / 1024);
5078 case GUC_UNIT_XBLOCKS:
5079 val *= KB_PER_GB / (XLOG_BLCKSZ / 1024);
5083 else if (strncmp(endptr, "TB", 2) == 0)
5086 switch (flags & GUC_UNIT_MEMORY)
5091 case GUC_UNIT_BLOCKS:
5092 val *= KB_PER_TB / (BLCKSZ / 1024);
5094 case GUC_UNIT_XBLOCKS:
5095 val *= KB_PER_TB / (XLOG_BLCKSZ / 1024);
5100 else if (flags & GUC_UNIT_TIME)
5102 /* Set hint for use if no match or trailing garbage */
5104 *hintmsg = gettext_noop("Valid units for this parameter are \"ms\", \"s\", \"min\", \"h\", and \"d\".");
5106 if (strncmp(endptr, "ms", 2) == 0)
5109 switch (flags & GUC_UNIT_TIME)
5119 else if (strncmp(endptr, "s", 1) == 0)
5122 switch (flags & GUC_UNIT_TIME)
5132 else if (strncmp(endptr, "min", 3) == 0)
5135 switch (flags & GUC_UNIT_TIME)
5145 else if (strncmp(endptr, "h", 1) == 0)
5148 switch (flags & GUC_UNIT_TIME)
5161 else if (strncmp(endptr, "d", 1) == 0)
5164 switch (flags & GUC_UNIT_TIME)
5179 /* allow whitespace after unit */
5180 while (isspace((unsigned char) *endptr))
5183 if (*endptr != '\0')
5184 return false; /* appropriate hint, if any, already set */
5186 /* Check for overflow due to units conversion */
5187 if (val != (int64) ((int32) val))
5190 *hintmsg = gettext_noop("Value exceeds integer range.");
5196 *result = (int) val;
5203 * Try to parse value as a floating point number in the usual format.
5204 * If the string parses okay, return true, else false.
5205 * If okay and result is not NULL, return the value in *result.
5208 parse_real(const char *value, double *result)
5214 *result = 0; /* suppress compiler warning */
5217 val = strtod(value, &endptr);
5218 if (endptr == value || errno == ERANGE)
5221 /* allow whitespace after number */
5222 while (isspace((unsigned char) *endptr))
5224 if (*endptr != '\0')
5234 * Lookup the name for an enum option with the selected value.
5235 * Should only ever be called with known-valid values, so throws
5236 * an elog(ERROR) if the enum option is not found.
5238 * The returned string is a pointer to static data and not
5239 * allocated for modification.
5242 config_enum_lookup_by_value(struct config_enum * record, int val)
5244 const struct config_enum_entry *entry;
5246 for (entry = record->options; entry && entry->name; entry++)
5248 if (entry->val == val)
5252 elog(ERROR, "could not find enum option %d for %s",
5253 val, record->gen.name);
5254 return NULL; /* silence compiler */
5259 * Lookup the value for an enum option with the selected name
5260 * (case-insensitive).
5261 * If the enum option is found, sets the retval value and returns
5262 * true. If it's not found, return FALSE and retval is set to 0.
5265 config_enum_lookup_by_name(struct config_enum * record, const char *value,
5268 const struct config_enum_entry *entry;
5270 for (entry = record->options; entry && entry->name; entry++)
5272 if (pg_strcasecmp(value, entry->name) == 0)
5274 *retval = entry->val;
5285 * Return a list of all available options for an enum, excluding
5286 * hidden ones, separated by the given separator.
5287 * If prefix is non-NULL, it is added before the first enum value.
5288 * If suffix is non-NULL, it is added to the end of the string.
5291 config_enum_get_options(struct config_enum * record, const char *prefix,
5292 const char *suffix, const char *separator)
5294 const struct config_enum_entry *entry;
5295 StringInfoData retstr;
5298 initStringInfo(&retstr);
5299 appendStringInfoString(&retstr, prefix);
5301 seplen = strlen(separator);
5302 for (entry = record->options; entry && entry->name; entry++)
5306 appendStringInfoString(&retstr, entry->name);
5307 appendBinaryStringInfo(&retstr, separator, seplen);
5312 * All the entries may have been hidden, leaving the string empty if no
5313 * prefix was given. This indicates a broken GUC setup, since there is no
5314 * use for an enum without any values, so we just check to make sure we
5315 * don't write to invalid memory instead of actually trying to do
5316 * something smart with it.
5318 if (retstr.len >= seplen)
5320 /* Replace final separator */
5321 retstr.data[retstr.len - seplen] = '\0';
5322 retstr.len -= seplen;
5325 appendStringInfoString(&retstr, suffix);
5331 * Validates configuration parameter and value, by calling check hook functions
5332 * depending on record's vartype. It validates if the parameter
5333 * value given is in range of expected predefined value for that parameter.
5335 * freemem - true indicates memory for newval and newextra will be
5336 * freed in this function, false indicates it will be freed
5339 * 1: the value is valid
5340 * 0: the name or value is invalid
5343 validate_conf_option(struct config_generic * record, const char *name,
5344 const char *value, GucSource source, int elevel,
5345 bool freemem, void *newval, void **newextra)
5348 * Validate the value for the passed record, to ensure it is in expected
5351 switch (record->vartype)
5356 struct config_bool *conf = (struct config_bool *) record;
5360 newval = &tmpnewval;
5364 if (!parse_bool(value, newval))
5367 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5368 errmsg("parameter \"%s\" requires a Boolean value",
5373 if (!call_bool_check_hook(conf, newval, newextra,
5377 if (*newextra && freemem)
5384 struct config_int *conf = (struct config_int *) record;
5388 newval = &tmpnewval;
5392 const char *hintmsg;
5394 if (!parse_int(value, newval, conf->gen.flags, &hintmsg))
5397 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5398 errmsg("invalid value for parameter \"%s\": \"%s\"",
5400 hintmsg ? errhint("%s", _(hintmsg)) : 0));
5404 if (*((int *) newval) < conf->min || *((int *) newval) > conf->max)
5407 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5408 errmsg("%d is outside the valid range for parameter \"%s\" (%d .. %d)",
5409 *((int *) newval), name, conf->min, conf->max)));
5413 if (!call_int_check_hook(conf, newval, newextra,
5417 if (*newextra && freemem)
5424 struct config_real *conf = (struct config_real *) record;
5428 newval = &tmpnewval;
5432 if (!parse_real(value, newval))
5435 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5436 errmsg("parameter \"%s\" requires a numeric value",
5441 if (*((double *) newval) < conf->min || *((double *) newval) > conf->max)
5444 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5445 errmsg("%g is outside the valid range for parameter \"%s\" (%g .. %g)",
5446 *((double *) newval), name, conf->min, conf->max)));
5450 if (!call_real_check_hook(conf, newval, newextra,
5454 if (*newextra && freemem)
5461 struct config_string *conf = (struct config_string *) record;
5463 char **tmpnewval = newval;
5466 tmpnewval = &tempPtr;
5471 * The value passed by the caller could be transient, so
5472 * we always strdup it.
5474 *tmpnewval = guc_strdup(elevel, value);
5475 if (*tmpnewval == NULL)
5479 * The only built-in "parsing" check we have is to apply
5480 * truncation if GUC_IS_NAME.
5482 if (conf->gen.flags & GUC_IS_NAME)
5483 truncate_identifier(*tmpnewval, strlen(*tmpnewval), true);
5485 if (!call_string_check_hook(conf, tmpnewval, newextra,
5492 /* Free the malloc'd data if any */
5495 if (*tmpnewval != NULL)
5497 if (*newextra != NULL)
5505 struct config_enum *conf = (struct config_enum *) record;
5509 newval = &tmpnewval;
5513 if (!config_enum_lookup_by_name(conf, value, newval))
5517 hintmsg = config_enum_get_options(conf,
5518 "Available values: ",
5522 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5523 errmsg("invalid value for parameter \"%s\": \"%s\"",
5525 hintmsg ? errhint("%s", _(hintmsg)) : 0));
5527 if (hintmsg != NULL)
5531 if (!call_enum_check_hook(conf, newval, newextra,
5535 if (*newextra && freemem)
5546 * Sets option `name' to given value.
5548 * The value should be a string, which will be parsed and converted to
5549 * the appropriate data type. The context and source parameters indicate
5550 * in which context this function is being called, so that it can apply the
5551 * access restrictions properly.
5553 * If value is NULL, set the option to its default value (normally the
5554 * reset_val, but if source == PGC_S_DEFAULT we instead use the boot_val).
5556 * action indicates whether to set the value globally in the session, locally
5557 * to the current top transaction, or just for the duration of a function call.
5559 * If changeVal is false then don't really set the option but do all
5560 * the checks to see if it would work.
5562 * elevel should normally be passed as zero, allowing this function to make
5563 * its standard choice of ereport level. However some callers need to be
5564 * able to override that choice; they should pass the ereport level to use.
5567 * +1: the value is valid and was successfully applied.
5568 * 0: the name or value is invalid (but see below).
5569 * -1: the value was not applied because of context, priority, or changeVal.
5571 * If there is an error (non-existing option, invalid value) then an
5572 * ereport(ERROR) is thrown *unless* this is called for a source for which
5573 * we don't want an ERROR (currently, those are defaults, the config file,
5574 * and per-database or per-user settings, as well as callers who specify
5575 * a less-than-ERROR elevel). In those cases we write a suitable error
5576 * message via ereport() and return 0.
5578 * See also SetConfigOption for an external interface.
5581 set_config_option(const char *name, const char *value,
5582 GucContext context, GucSource source,
5583 GucAction action, bool changeVal, int elevel)
5585 struct config_generic *record;
5586 bool prohibitValueChange = false;
5591 if (source == PGC_S_DEFAULT || source == PGC_S_FILE)
5594 * To avoid cluttering the log, only the postmaster bleats loudly
5595 * about problems with the config file.
5597 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
5599 else if (source == PGC_S_GLOBAL || source == PGC_S_DATABASE || source == PGC_S_USER ||
5600 source == PGC_S_DATABASE_USER)
5606 record = find_option(name, true, elevel);
5610 (errcode(ERRCODE_UNDEFINED_OBJECT),
5611 errmsg("unrecognized configuration parameter \"%s\"", name)));
5616 * Check if the option can be set at this time. See guc.h for the precise
5619 switch (record->context)
5622 if (context != PGC_INTERNAL)
5625 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5626 errmsg("parameter \"%s\" cannot be changed",
5631 case PGC_POSTMASTER:
5632 if (context == PGC_SIGHUP)
5635 * We are re-reading a PGC_POSTMASTER variable from
5636 * postgresql.conf. We can't change the setting, so we should
5637 * give a warning if the DBA tries to change it. However,
5638 * because of variant formats, canonicalization by check
5639 * hooks, etc, we can't just compare the given string directly
5640 * to what's stored. Set a flag to check below after we have
5641 * the final storable value.
5643 prohibitValueChange = true;
5645 else if (context != PGC_POSTMASTER)
5648 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5649 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5655 if (context != PGC_SIGHUP && context != PGC_POSTMASTER)
5658 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5659 errmsg("parameter \"%s\" cannot be changed now",
5665 * Hmm, the idea of the SIGHUP context is "ought to be global, but
5666 * can be changed after postmaster start". But there's nothing
5667 * that prevents a crafty administrator from sending SIGHUP
5668 * signals to individual backends only.
5672 if (context == PGC_SIGHUP)
5675 * If a PGC_BACKEND parameter is changed in the config file,
5676 * we want to accept the new value in the postmaster (whence
5677 * it will propagate to subsequently-started backends), but
5678 * ignore it in existing backends. This is a tad klugy, but
5679 * necessary because we don't re-read the config file during
5682 * In EXEC_BACKEND builds, this works differently: we load all
5683 * nondefault settings from the CONFIG_EXEC_PARAMS file during
5684 * backend start. In that case we must accept PGC_SIGHUP
5685 * settings, so as to have the same value as if we'd forked
5686 * from the postmaster. We detect this situation by checking
5687 * IsInitProcessingMode, which is a bit ugly, but it doesn't
5688 * seem worth passing down an explicit flag saying we're doing
5689 * read_nondefault_variables().
5692 if (IsUnderPostmaster && !IsInitProcessingMode())
5695 if (IsUnderPostmaster)
5699 else if (context != PGC_POSTMASTER && context != PGC_BACKEND &&
5700 source != PGC_S_CLIENT)
5703 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5704 errmsg("parameter \"%s\" cannot be set after connection start",
5710 if (context == PGC_USERSET || context == PGC_BACKEND)
5713 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5714 errmsg("permission denied to set parameter \"%s\"",
5725 * Disallow changing GUC_NOT_WHILE_SEC_REST values if we are inside a
5726 * security restriction context. We can reject this regardless of the GUC
5727 * context or source, mainly because sources that it might be reasonable
5728 * to override for won't be seen while inside a function.
5730 * Note: variables marked GUC_NOT_WHILE_SEC_REST should usually be marked
5731 * GUC_NO_RESET_ALL as well, because ResetAllOptions() doesn't check this.
5732 * An exception might be made if the reset value is assumed to be "safe".
5734 * Note: this flag is currently used for "session_authorization" and
5735 * "role". We need to prohibit changing these inside a local userid
5736 * context because when we exit it, GUC won't be notified, leaving things
5737 * out of sync. (This could be fixed by forcing a new GUC nesting level,
5738 * but that would change behavior in possibly-undesirable ways.) Also, we
5739 * prohibit changing these in a security-restricted operation because
5740 * otherwise RESET could be used to regain the session user's privileges.
5742 if (record->flags & GUC_NOT_WHILE_SEC_REST)
5744 if (InLocalUserIdChange())
5747 * Phrasing of this error message is historical, but it's the most
5751 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5752 errmsg("cannot set parameter \"%s\" within security-definer function",
5756 if (InSecurityRestrictedOperation())
5759 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5760 errmsg("cannot set parameter \"%s\" within security-restricted operation",
5767 * Should we set reset/stacked values? (If so, the behavior is not
5768 * transactional.) This is done either when we get a default value from
5769 * the database's/user's/client's default settings or when we reset a
5770 * value to its default.
5772 makeDefault = changeVal && (source <= PGC_S_OVERRIDE) &&
5773 ((value != NULL) || source == PGC_S_DEFAULT);
5776 * Ignore attempted set if overridden by previously processed setting.
5777 * However, if changeVal is false then plow ahead anyway since we are
5778 * trying to find out if the value is potentially good, not actually use
5779 * it. Also keep going if makeDefault is true, since we may want to set
5780 * the reset/stacked values even if we can't set the variable itself.
5782 if (record->source > source)
5784 if (changeVal && !makeDefault)
5786 elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
5794 * Evaluate value and set variable.
5796 switch (record->vartype)
5800 struct config_bool *conf = (struct config_bool *) record;
5802 void *newextra = NULL;
5806 if (!validate_conf_option(record, name, value, source,
5807 elevel, false, &newval,
5811 else if (source == PGC_S_DEFAULT)
5813 newval = conf->boot_val;
5814 if (!call_bool_check_hook(conf, &newval, &newextra,
5820 newval = conf->reset_val;
5821 newextra = conf->reset_extra;
5822 source = conf->gen.reset_source;
5823 context = conf->gen.reset_scontext;
5826 if (prohibitValueChange)
5828 if (*conf->variable != newval)
5831 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5832 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5841 /* Save old value to support transaction abort */
5843 push_old_value(&conf->gen, action);
5845 if (conf->assign_hook)
5846 (*conf->assign_hook) (newval, newextra);
5847 *conf->variable = newval;
5848 set_extra_field(&conf->gen, &conf->gen.extra,
5850 conf->gen.source = source;
5851 conf->gen.scontext = context;
5857 if (conf->gen.reset_source <= source)
5859 conf->reset_val = newval;
5860 set_extra_field(&conf->gen, &conf->reset_extra,
5862 conf->gen.reset_source = source;
5863 conf->gen.reset_scontext = context;
5865 for (stack = conf->gen.stack; stack; stack = stack->prev)
5867 if (stack->source <= source)
5869 stack->prior.val.boolval = newval;
5870 set_extra_field(&conf->gen, &stack->prior.extra,
5872 stack->source = source;
5873 stack->scontext = context;
5878 /* Perhaps we didn't install newextra anywhere */
5879 if (newextra && !extra_field_used(&conf->gen, newextra))
5886 struct config_int *conf = (struct config_int *) record;
5888 void *newextra = NULL;
5892 if (!validate_conf_option(record, name, value, source,
5893 elevel, false, &newval,
5897 else if (source == PGC_S_DEFAULT)
5899 newval = conf->boot_val;
5900 if (!call_int_check_hook(conf, &newval, &newextra,
5906 newval = conf->reset_val;
5907 newextra = conf->reset_extra;
5908 source = conf->gen.reset_source;
5909 context = conf->gen.reset_scontext;
5912 if (prohibitValueChange)
5914 if (*conf->variable != newval)
5917 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
5918 errmsg("parameter \"%s\" cannot be changed without restarting the server",
5927 /* Save old value to support transaction abort */
5929 push_old_value(&conf->gen, action);
5931 if (conf->assign_hook)
5932 (*conf->assign_hook) (newval, newextra);
5933 *conf->variable = newval;
5934 set_extra_field(&conf->gen, &conf->gen.extra,
5936 conf->gen.source = source;
5937 conf->gen.scontext = context;
5943 if (conf->gen.reset_source <= source)
5945 conf->reset_val = newval;
5946 set_extra_field(&conf->gen, &conf->reset_extra,
5948 conf->gen.reset_source = source;
5949 conf->gen.reset_scontext = context;
5951 for (stack = conf->gen.stack; stack; stack = stack->prev)
5953 if (stack->source <= source)
5955 stack->prior.val.intval = newval;
5956 set_extra_field(&conf->gen, &stack->prior.extra,
5958 stack->source = source;
5959 stack->scontext = context;
5964 /* Perhaps we didn't install newextra anywhere */
5965 if (newextra && !extra_field_used(&conf->gen, newextra))
5972 struct config_real *conf = (struct config_real *) record;
5974 void *newextra = NULL;
5978 if (!validate_conf_option(record, name, value, source,
5979 elevel, false, &newval,
5983 else if (source == PGC_S_DEFAULT)
5985 newval = conf->boot_val;
5986 if (!call_real_check_hook(conf, &newval, &newextra,
5992 newval = conf->reset_val;
5993 newextra = conf->reset_extra;
5994 source = conf->gen.reset_source;
5995 context = conf->gen.reset_scontext;
5998 if (prohibitValueChange)
6000 if (*conf->variable != newval)
6003 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6004 errmsg("parameter \"%s\" cannot be changed without restarting the server",
6013 /* Save old value to support transaction abort */
6015 push_old_value(&conf->gen, action);
6017 if (conf->assign_hook)
6018 (*conf->assign_hook) (newval, newextra);
6019 *conf->variable = newval;
6020 set_extra_field(&conf->gen, &conf->gen.extra,
6022 conf->gen.source = source;
6023 conf->gen.scontext = context;
6029 if (conf->gen.reset_source <= source)
6031 conf->reset_val = newval;
6032 set_extra_field(&conf->gen, &conf->reset_extra,
6034 conf->gen.reset_source = source;
6035 conf->gen.reset_scontext = context;
6037 for (stack = conf->gen.stack; stack; stack = stack->prev)
6039 if (stack->source <= source)
6041 stack->prior.val.realval = newval;
6042 set_extra_field(&conf->gen, &stack->prior.extra,
6044 stack->source = source;
6045 stack->scontext = context;
6050 /* Perhaps we didn't install newextra anywhere */
6051 if (newextra && !extra_field_used(&conf->gen, newextra))
6058 struct config_string *conf = (struct config_string *) record;
6060 void *newextra = NULL;
6064 if (!validate_conf_option(record, name, value, source,
6065 elevel, false, &newval,
6069 else if (source == PGC_S_DEFAULT)
6071 /* non-NULL boot_val must always get strdup'd */
6072 if (conf->boot_val != NULL)
6074 newval = guc_strdup(elevel, conf->boot_val);
6081 if (!call_string_check_hook(conf, &newval, &newextra,
6091 * strdup not needed, since reset_val is already under
6094 newval = conf->reset_val;
6095 newextra = conf->reset_extra;
6096 source = conf->gen.reset_source;
6097 context = conf->gen.reset_scontext;
6100 if (prohibitValueChange)
6102 /* newval shouldn't be NULL, so we're a bit sloppy here */
6103 if (*conf->variable == NULL || newval == NULL ||
6104 strcmp(*conf->variable, newval) != 0)
6107 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6108 errmsg("parameter \"%s\" cannot be changed without restarting the server",
6117 /* Save old value to support transaction abort */
6119 push_old_value(&conf->gen, action);
6121 if (conf->assign_hook)
6122 (*conf->assign_hook) (newval, newextra);
6123 set_string_field(conf, conf->variable, newval);
6124 set_extra_field(&conf->gen, &conf->gen.extra,
6126 conf->gen.source = source;
6127 conf->gen.scontext = context;
6134 if (conf->gen.reset_source <= source)
6136 set_string_field(conf, &conf->reset_val, newval);
6137 set_extra_field(&conf->gen, &conf->reset_extra,
6139 conf->gen.reset_source = source;
6140 conf->gen.reset_scontext = context;
6142 for (stack = conf->gen.stack; stack; stack = stack->prev)
6144 if (stack->source <= source)
6146 set_string_field(conf, &stack->prior.val.stringval,
6148 set_extra_field(&conf->gen, &stack->prior.extra,
6150 stack->source = source;
6151 stack->scontext = context;
6156 /* Perhaps we didn't install newval anywhere */
6157 if (newval && !string_field_used(conf, newval))
6159 /* Perhaps we didn't install newextra anywhere */
6160 if (newextra && !extra_field_used(&conf->gen, newextra))
6167 struct config_enum *conf = (struct config_enum *) record;
6169 void *newextra = NULL;
6173 if (!validate_conf_option(record, name, value, source,
6174 elevel, false, &newval,
6178 else if (source == PGC_S_DEFAULT)
6180 newval = conf->boot_val;
6181 if (!call_enum_check_hook(conf, &newval, &newextra,
6187 newval = conf->reset_val;
6188 newextra = conf->reset_extra;
6189 source = conf->gen.reset_source;
6190 context = conf->gen.reset_scontext;
6193 if (prohibitValueChange)
6195 if (*conf->variable != newval)
6198 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6199 errmsg("parameter \"%s\" cannot be changed without restarting the server",
6208 /* Save old value to support transaction abort */
6210 push_old_value(&conf->gen, action);
6212 if (conf->assign_hook)
6213 (*conf->assign_hook) (newval, newextra);
6214 *conf->variable = newval;
6215 set_extra_field(&conf->gen, &conf->gen.extra,
6217 conf->gen.source = source;
6218 conf->gen.scontext = context;
6224 if (conf->gen.reset_source <= source)
6226 conf->reset_val = newval;
6227 set_extra_field(&conf->gen, &conf->reset_extra,
6229 conf->gen.reset_source = source;
6230 conf->gen.reset_scontext = context;
6232 for (stack = conf->gen.stack; stack; stack = stack->prev)
6234 if (stack->source <= source)
6236 stack->prior.val.enumval = newval;
6237 set_extra_field(&conf->gen, &stack->prior.extra,
6239 stack->source = source;
6240 stack->scontext = context;
6245 /* Perhaps we didn't install newextra anywhere */
6246 if (newextra && !extra_field_used(&conf->gen, newextra))
6252 if (changeVal && (record->flags & GUC_REPORT))
6253 ReportGUCOption(record);
6255 return changeVal ? 1 : -1;
6260 * Set the fields for source file and line number the setting came from.
6263 set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
6265 struct config_generic *record;
6269 * To avoid cluttering the log, only the postmaster bleats loudly about
6270 * problems with the config file.
6272 elevel = IsUnderPostmaster ? DEBUG3 : LOG;
6274 record = find_option(name, true, elevel);
6275 /* should not happen */
6277 elog(ERROR, "unrecognized configuration parameter \"%s\"", name);
6279 sourcefile = guc_strdup(elevel, sourcefile);
6280 if (record->sourcefile)
6281 free(record->sourcefile);
6282 record->sourcefile = sourcefile;
6283 record->sourceline = sourceline;
6287 * Set a config option to the given value.
6289 * See also set_config_option; this is just the wrapper to be called from
6290 * outside GUC. (This function should be used when possible, because its API
6291 * is more stable than set_config_option's.)
6293 * Note: there is no support here for setting source file/line, as it
6294 * is currently not needed.
6297 SetConfigOption(const char *name, const char *value,
6298 GucContext context, GucSource source)
6300 (void) set_config_option(name, value, context, source,
6301 GUC_ACTION_SET, true, 0);
6307 * Fetch the current value of the option `name', as a string.
6309 * If the option doesn't exist, return NULL if missing_ok is true (NOTE that
6310 * this cannot be distinguished from a string variable with a NULL value!),
6311 * otherwise throw an ereport and don't return.
6313 * If restrict_superuser is true, we also enforce that only superusers can
6314 * see GUC_SUPERUSER_ONLY variables. This should only be passed as true
6315 * in user-driven calls.
6317 * The string is *not* allocated for modification and is really only
6318 * valid until the next call to configuration related functions.
6321 GetConfigOption(const char *name, bool missing_ok, bool restrict_superuser)
6323 struct config_generic *record;
6324 static char buffer[256];
6326 record = find_option(name, false, ERROR);
6332 (errcode(ERRCODE_UNDEFINED_OBJECT),
6333 errmsg("unrecognized configuration parameter \"%s\"",
6336 if (restrict_superuser &&
6337 (record->flags & GUC_SUPERUSER_ONLY) &&
6340 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6341 errmsg("must be superuser to examine \"%s\"", name)));
6343 switch (record->vartype)
6346 return *((struct config_bool *) record)->variable ? "on" : "off";
6349 snprintf(buffer, sizeof(buffer), "%d",
6350 *((struct config_int *) record)->variable);
6354 snprintf(buffer, sizeof(buffer), "%g",
6355 *((struct config_real *) record)->variable);
6359 return *((struct config_string *) record)->variable;
6362 return config_enum_lookup_by_value((struct config_enum *) record,
6363 *((struct config_enum *) record)->variable);
6369 * Get the RESET value associated with the given option.
6371 * Note: this is not re-entrant, due to use of static result buffer;
6372 * not to mention that a string variable could have its reset_val changed.
6373 * Beware of assuming the result value is good for very long.
6376 GetConfigOptionResetString(const char *name)
6378 struct config_generic *record;
6379 static char buffer[256];
6381 record = find_option(name, false, ERROR);
6384 (errcode(ERRCODE_UNDEFINED_OBJECT),
6385 errmsg("unrecognized configuration parameter \"%s\"", name)));
6386 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
6388 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6389 errmsg("must be superuser to examine \"%s\"", name)));
6391 switch (record->vartype)
6394 return ((struct config_bool *) record)->reset_val ? "on" : "off";
6397 snprintf(buffer, sizeof(buffer), "%d",
6398 ((struct config_int *) record)->reset_val);
6402 snprintf(buffer, sizeof(buffer), "%g",
6403 ((struct config_real *) record)->reset_val);
6407 return ((struct config_string *) record)->reset_val;
6410 return config_enum_lookup_by_value((struct config_enum *) record,
6411 ((struct config_enum *) record)->reset_val);
6418 * flatten_set_variable_args
6419 * Given a parsenode List as emitted by the grammar for SET,
6420 * convert to the flat string representation used by GUC.
6422 * We need to be told the name of the variable the args are for, because
6423 * the flattening rules vary (ugh).
6425 * The result is NULL if args is NIL (ie, SET ... TO DEFAULT), otherwise
6426 * a palloc'd string.
6429 flatten_set_variable_args(const char *name, List *args)
6431 struct config_generic *record;
6436 /* Fast path if just DEFAULT */
6441 * Get flags for the variable; if it's not known, use default flags.
6442 * (Caller might throw error later, but not our business to do so here.)
6444 record = find_option(name, false, WARNING);
6446 flags = record->flags;
6450 /* Complain if list input and non-list variable */
6451 if ((flags & GUC_LIST_INPUT) == 0 &&
6452 list_length(args) != 1)
6454 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6455 errmsg("SET %s takes only one argument", name)));
6457 initStringInfo(&buf);
6460 * Each list member may be a plain A_Const node, or an A_Const within a
6461 * TypeCast; the latter case is supported only for ConstInterval arguments
6462 * (for SET TIME ZONE).
6466 Node *arg = (Node *) lfirst(l);
6468 TypeName *typeName = NULL;
6471 if (l != list_head(args))
6472 appendStringInfoString(&buf, ", ");
6474 if (IsA(arg, TypeCast))
6476 TypeCast *tc = (TypeCast *) arg;
6479 typeName = tc->typeName;
6482 if (!IsA(arg, A_Const))
6483 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
6484 con = (A_Const *) arg;
6486 switch (nodeTag(&con->val))
6489 appendStringInfo(&buf, "%ld", intVal(&con->val));
6492 /* represented as a string, so just copy it */
6493 appendStringInfoString(&buf, strVal(&con->val));
6496 val = strVal(&con->val);
6497 if (typeName != NULL)
6500 * Must be a ConstInterval argument for TIME ZONE. Coerce
6501 * to interval and back to normalize the value and account
6509 typenameTypeIdAndMod(NULL, typeName, &typoid, &typmod);
6510 Assert(typoid == INTERVALOID);
6513 DirectFunctionCall3(interval_in,
6514 CStringGetDatum(val),
6515 ObjectIdGetDatum(InvalidOid),
6516 Int32GetDatum(typmod));
6519 DatumGetCString(DirectFunctionCall1(interval_out,
6521 appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
6526 * Plain string literal or identifier. For quote mode,
6527 * quote it if it's not a vanilla identifier.
6529 if (flags & GUC_LIST_QUOTE)
6530 appendStringInfoString(&buf, quote_identifier(val));
6532 appendStringInfoString(&buf, val);
6536 elog(ERROR, "unrecognized node type: %d",
6537 (int) nodeTag(&con->val));
6546 * Write updated configuration parameter values into a temporary file.
6547 * This function traverses the list of parameters and quotes the string
6548 * values before writing them.
6551 write_auto_conf_file(int fd, const char *filename, ConfigVariable **head_p)
6553 ConfigVariable *item;
6556 initStringInfo(&buf);
6557 appendStringInfoString(&buf, "# Do not edit this file manually!\n");
6558 appendStringInfoString(&buf, "# It will be overwritten by ALTER SYSTEM command.\n");
6561 * write the file header message before contents, so that if there is no
6562 * item it can contain message
6564 if (write(fd, buf.data, buf.len) < 0)
6566 (errmsg("failed to write to \"%s\" file", filename)));
6567 resetStringInfo(&buf);
6570 * traverse the list of parameters, quote the string parameter and write
6571 * it to file. Once all parameters are written fsync the file.
6574 for (item = *head_p; item != NULL; item = item->next)
6578 appendStringInfoString(&buf, item->name);
6579 appendStringInfoString(&buf, " = ");
6581 appendStringInfoString(&buf, "\'");
6582 escaped = escape_single_quotes_ascii(item->value);
6583 appendStringInfoString(&buf, escaped);
6585 appendStringInfoString(&buf, "\'");
6587 appendStringInfoString(&buf, "\n");
6589 if (write(fd, buf.data, buf.len) < 0)
6591 (errmsg("failed to write to \"%s\" file", filename)));
6592 resetStringInfo(&buf);
6595 if (pg_fsync(fd) != 0)
6597 (errcode_for_file_access(),
6598 errmsg("could not fsync file \"%s\": %m", filename)));
6605 * This function takes list of all configuration parameters in
6606 * PG_AUTOCONF_FILENAME and parameter to be updated as input arguments and
6607 * replace the updated configuration parameter value in a list. If the
6608 * parameter to be updated is new then it is appended to the list of
6612 replace_auto_config_value(ConfigVariable **head_p, ConfigVariable **tail_p,
6614 char *name, char *value)
6616 ConfigVariable *item,
6619 if (*head_p != NULL)
6621 for (item = *head_p; item != NULL; item = item->next)
6623 if (strcmp(item->name, name) == 0)
6627 /* update the parameter value */
6628 item->value = pstrdup(value);
6631 /* delete the configuration parameter from list */
6632 if (*head_p == item)
6633 *head_p = item->next;
6635 prev->next = item->next;
6637 if (*tail_p == item)
6641 pfree(item->filename);
6653 item = palloc(sizeof *item);
6654 item->name = pstrdup(name);
6655 item->value = pstrdup(value);
6656 item->filename = pstrdup(config_file);
6659 if (*head_p == NULL)
6661 item->sourceline = 1;
6666 item->sourceline = (*tail_p)->sourceline + 1;
6667 (*tail_p)->next = item;
6677 * Persist the configuration parameter value.
6679 * This function takes all previous configuration parameters
6680 * set by ALTER SYSTEM command and the currently set ones
6681 * and write them all to the automatic configuration file.
6683 * The configuration parameters are written to a temporary
6684 * file then renamed to the final name.
6686 * An LWLock is used to serialize writing to the same file.
6688 * In case of an error, we leave the original automatic
6689 * configuration file (PG_AUTOCONF_FILENAME) intact.
6692 AlterSystemSetConfigFile(AlterSystemStmt *altersysstmt)
6698 struct config_generic *record;
6699 ConfigVariable *head = NULL;
6700 ConfigVariable *tail = NULL;
6701 char AutoConfFileName[MAXPGPATH];
6702 char AutoConfTmpFileName[MAXPGPATH];
6704 void *newextra = NULL;
6708 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
6709 (errmsg("must be superuser to execute ALTER SYSTEM command"))));
6712 * Validate the name and arguments [value1, value2 ... ].
6714 name = altersysstmt->setstmt->name;
6716 switch (altersysstmt->setstmt->kind)
6719 value = ExtractSetVariableArgs(altersysstmt->setstmt);
6722 case VAR_SET_DEFAULT:
6726 elog(ERROR, "unrecognized alter system stmt type: %d",
6727 altersysstmt->setstmt->kind);
6731 record = find_option(name, false, LOG);
6734 (errcode(ERRCODE_UNDEFINED_OBJECT),
6735 errmsg("unrecognized configuration parameter \"%s\"", name)));
6738 * Don't allow the parameters which can't be set in configuration
6739 * files to be set in PG_AUTOCONF_FILENAME file.
6741 if ((record->context == PGC_INTERNAL) ||
6742 (record->flags & GUC_DISALLOW_IN_FILE) ||
6743 (record->flags & GUC_DISALLOW_IN_AUTO_FILE))
6745 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
6746 errmsg("parameter \"%s\" cannot be changed",
6749 if (!validate_conf_option(record, name, value, PGC_S_FILE,
6753 (errmsg("invalid value for parameter \"%s\": \"%s\"", name, value)));
6757 * Use data directory as reference path for PG_AUTOCONF_FILENAME and its
6758 * corresponding temporary file.
6760 join_path_components(AutoConfFileName, data_directory, PG_AUTOCONF_FILENAME);
6761 canonicalize_path(AutoConfFileName);
6762 snprintf(AutoConfTmpFileName, sizeof(AutoConfTmpFileName), "%s.%s",
6767 * One backend is allowed to operate on file PG_AUTOCONF_FILENAME, to
6768 * ensure that we need to update the contents of the file with
6769 * AutoFileLock. To ensure crash safety, first the contents are written to
6770 * a temporary file which is then renameed to PG_AUTOCONF_FILENAME. In
6771 * case there exists a temp file from previous crash, that can be reused.
6774 LWLockAcquire(AutoFileLock, LW_EXCLUSIVE);
6776 Tmpfd = open(AutoConfTmpFileName, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
6779 (errcode_for_file_access(),
6780 errmsg("failed to open auto conf temp file \"%s\": %m ",
6781 AutoConfTmpFileName)));
6785 if (stat(AutoConfFileName, &st) == 0)
6787 /* open file PG_AUTOCONF_FILENAME */
6788 infile = AllocateFile(AutoConfFileName, "r");
6791 (errmsg("failed to open auto conf file \"%s\": %m ",
6792 AutoConfFileName)));
6795 ParseConfigFp(infile, AutoConfFileName, 0, LOG, &head, &tail);
6801 * replace with new value if the configuration parameter already
6802 * exists OR add it as a new cofiguration parameter in the file.
6804 replace_auto_config_value(&head, &tail, AutoConfFileName, name, value);
6806 /* Write and sync the new contents to the temporary file */
6807 write_auto_conf_file(Tmpfd, AutoConfTmpFileName, &head);
6813 * As the rename is atomic operation, if any problem occurs after this
6814 * at max it can loose the parameters set by last ALTER SYSTEM
6817 if (rename(AutoConfTmpFileName, AutoConfFileName) < 0)
6819 (errcode_for_file_access(),
6820 errmsg("could not rename file \"%s\" to \"%s\" : %m",
6821 AutoConfTmpFileName, AutoConfFileName)));
6828 unlink(AutoConfTmpFileName);
6829 FreeConfigVariables(head);
6834 FreeConfigVariables(head);
6835 LWLockRelease(AutoFileLock);
6843 ExecSetVariableStmt(VariableSetStmt *stmt, bool isTopLevel)
6845 GucAction action = stmt->is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET;
6850 case VAR_SET_CURRENT:
6852 WarnNoTransactionChain(isTopLevel, "SET LOCAL");
6853 (void) set_config_option(stmt->name,
6854 ExtractSetVariableArgs(stmt),
6855 (superuser() ? PGC_SUSET : PGC_USERSET),
6864 * Special-case SQL syntaxes. The TRANSACTION and SESSION
6865 * CHARACTERISTICS cases effectively set more than one variable
6866 * per statement. TRANSACTION SNAPSHOT only takes one argument,
6867 * but we put it here anyway since it's a special case and not
6868 * related to any GUC variable.
6870 if (strcmp(stmt->name, "TRANSACTION") == 0)
6874 WarnNoTransactionChain(isTopLevel, "SET TRANSACTION");
6876 foreach(head, stmt->args)
6878 DefElem *item = (DefElem *) lfirst(head);
6880 if (strcmp(item->defname, "transaction_isolation") == 0)
6881 SetPGVariable("transaction_isolation",
6882 list_make1(item->arg), stmt->is_local);
6883 else if (strcmp(item->defname, "transaction_read_only") == 0)
6884 SetPGVariable("transaction_read_only",
6885 list_make1(item->arg), stmt->is_local);
6886 else if (strcmp(item->defname, "transaction_deferrable") == 0)
6887 SetPGVariable("transaction_deferrable",
6888 list_make1(item->arg), stmt->is_local);
6890 elog(ERROR, "unexpected SET TRANSACTION element: %s",
6894 else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0)
6898 foreach(head, stmt->args)
6900 DefElem *item = (DefElem *) lfirst(head);
6902 if (strcmp(item->defname, "transaction_isolation") == 0)
6903 SetPGVariable("default_transaction_isolation",
6904 list_make1(item->arg), stmt->is_local);
6905 else if (strcmp(item->defname, "transaction_read_only") == 0)
6906 SetPGVariable("default_transaction_read_only",
6907 list_make1(item->arg), stmt->is_local);
6908 else if (strcmp(item->defname, "transaction_deferrable") == 0)
6909 SetPGVariable("default_transaction_deferrable",
6910 list_make1(item->arg), stmt->is_local);
6912 elog(ERROR, "unexpected SET SESSION element: %s",
6916 else if (strcmp(stmt->name, "TRANSACTION SNAPSHOT") == 0)
6918 A_Const *con = (A_Const *) linitial(stmt->args);
6922 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6923 errmsg("SET LOCAL TRANSACTION SNAPSHOT is not implemented")));
6925 WarnNoTransactionChain(isTopLevel, "SET TRANSACTION");
6926 Assert(IsA(con, A_Const));
6927 Assert(nodeTag(&con->val) == T_String);
6928 ImportSnapshot(strVal(&con->val));
6931 elog(ERROR, "unexpected SET MULTI element: %s",
6934 case VAR_SET_DEFAULT:
6936 WarnNoTransactionChain(isTopLevel, "SET LOCAL");
6939 if (strcmp(stmt->name, "transaction_isolation") == 0)
6940 WarnNoTransactionChain(isTopLevel, "RESET TRANSACTION");
6942 (void) set_config_option(stmt->name,
6944 (superuser() ? PGC_SUSET : PGC_USERSET),
6957 * Get the value to assign for a VariableSetStmt, or NULL if it's RESET.
6958 * The result is palloc'd.
6960 * This is exported for use by actions such as ALTER ROLE SET.
6963 ExtractSetVariableArgs(VariableSetStmt *stmt)
6968 return flatten_set_variable_args(stmt->name, stmt->args);
6969 case VAR_SET_CURRENT:
6970 return GetConfigOptionByName(stmt->name, NULL);
6977 * SetPGVariable - SET command exported as an easily-C-callable function.
6979 * This provides access to SET TO value, as well as SET TO DEFAULT (expressed
6980 * by passing args == NIL), but not SET FROM CURRENT functionality.
6983 SetPGVariable(const char *name, List *args, bool is_local)
6985 char *argstring = flatten_set_variable_args(name, args);
6987 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
6988 (void) set_config_option(name,
6990 (superuser() ? PGC_SUSET : PGC_USERSET),
6992 is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET,
6998 * SET command wrapped as a SQL callable function.
7001 set_config_by_name(PG_FUNCTION_ARGS)
7008 if (PG_ARGISNULL(0))
7010 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
7011 errmsg("SET requires parameter name")));
7013 /* Get the GUC variable name */
7014 name = TextDatumGetCString(PG_GETARG_DATUM(0));
7016 /* Get the desired value or set to NULL for a reset request */
7017 if (PG_ARGISNULL(1))
7020 value = TextDatumGetCString(PG_GETARG_DATUM(1));
7023 * Get the desired state of is_local. Default to false if provided value
7026 if (PG_ARGISNULL(2))
7029 is_local = PG_GETARG_BOOL(2);
7031 /* Note SET DEFAULT (argstring == NULL) is equivalent to RESET */
7032 (void) set_config_option(name,
7034 (superuser() ? PGC_SUSET : PGC_USERSET),
7036 is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET,
7040 /* get the new current value */
7041 new_value = GetConfigOptionByName(name, NULL);
7043 /* Convert return string to text */
7044 PG_RETURN_TEXT_P(cstring_to_text(new_value));
7049 * Common code for DefineCustomXXXVariable subroutines: allocate the
7050 * new variable's config struct and fill in generic fields.
7052 static struct config_generic *
7053 init_custom_variable(const char *name,
7054 const char *short_desc,
7055 const char *long_desc,
7058 enum config_type type,
7061 struct config_generic *gen;
7064 * Only allow custom PGC_POSTMASTER variables to be created during shared
7065 * library preload; any later than that, we can't ensure that the value
7066 * doesn't change after startup. This is a fatal elog if it happens; just
7067 * erroring out isn't safe because we don't know what the calling loadable
7068 * module might already have hooked into.
7070 if (context == PGC_POSTMASTER &&
7071 !process_shared_preload_libraries_in_progress)
7072 elog(FATAL, "cannot create PGC_POSTMASTER variables after startup");
7074 gen = (struct config_generic *) guc_malloc(ERROR, sz);
7077 gen->name = guc_strdup(ERROR, name);
7078 gen->context = context;
7079 gen->group = CUSTOM_OPTIONS;
7080 gen->short_desc = short_desc;
7081 gen->long_desc = long_desc;
7083 gen->vartype = type;
7089 * Common code for DefineCustomXXXVariable subroutines: insert the new
7090 * variable into the GUC variable array, replacing any placeholder.
7093 define_custom_variable(struct config_generic * variable)
7095 const char *name = variable->name;
7096 const char **nameAddr = &name;
7097 struct config_string *pHolder;
7098 struct config_generic **res;
7101 * See if there's a placeholder by the same name.
7103 res = (struct config_generic **) bsearch((void *) &nameAddr,
7104 (void *) guc_variables,
7106 sizeof(struct config_generic *),
7111 * No placeholder to replace, so we can just add it ... but first,
7112 * make sure it's initialized to its default value.
7114 InitializeOneGUCOption(variable);
7115 add_guc_variable(variable, ERROR);
7120 * This better be a placeholder
7122 if (((*res)->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
7124 (errcode(ERRCODE_INTERNAL_ERROR),
7125 errmsg("attempt to redefine parameter \"%s\"", name)));
7127 Assert((*res)->vartype == PGC_STRING);
7128 pHolder = (struct config_string *) (*res);
7131 * First, set the variable to its default value. We must do this even
7132 * though we intend to immediately apply a new value, since it's possible
7133 * that the new value is invalid.
7135 InitializeOneGUCOption(variable);
7138 * Replace the placeholder. We aren't changing the name, so no re-sorting
7144 * Assign the string value(s) stored in the placeholder to the real
7145 * variable. Essentially, we need to duplicate all the active and stacked
7146 * values, but with appropriate validation and datatype adjustment.
7148 * If an assignment fails, we report a WARNING and keep going. We don't
7149 * want to throw ERROR for bad values, because it'd bollix the add-on
7150 * module that's presumably halfway through getting loaded. In such cases
7151 * the default or previous state will become active instead.
7154 /* First, apply the reset value if any */
7155 if (pHolder->reset_val)
7156 (void) set_config_option(name, pHolder->reset_val,
7157 pHolder->gen.reset_scontext,
7158 pHolder->gen.reset_source,
7159 GUC_ACTION_SET, true, WARNING);
7160 /* That should not have resulted in stacking anything */
7161 Assert(variable->stack == NULL);
7163 /* Now, apply current and stacked values, in the order they were stacked */
7164 reapply_stacked_values(variable, pHolder, pHolder->gen.stack,
7165 *(pHolder->variable),
7166 pHolder->gen.scontext, pHolder->gen.source);
7168 /* Also copy over any saved source-location information */
7169 if (pHolder->gen.sourcefile)
7170 set_config_sourcefile(name, pHolder->gen.sourcefile,
7171 pHolder->gen.sourceline);
7174 * Free up as much as we conveniently can of the placeholder structure.
7175 * (This neglects any stack items, so it's possible for some memory to be
7176 * leaked. Since this can only happen once per session per variable, it
7177 * doesn't seem worth spending much code on.)
7179 set_string_field(pHolder, pHolder->variable, NULL);
7180 set_string_field(pHolder, &pHolder->reset_val, NULL);
7186 * Recursive subroutine for define_custom_variable: reapply non-reset values
7188 * We recurse so that the values are applied in the same order as originally.
7189 * At each recursion level, apply the upper-level value (passed in) in the
7190 * fashion implied by the stack entry.
7193 reapply_stacked_values(struct config_generic * variable,
7194 struct config_string * pHolder,
7196 const char *curvalue,
7197 GucContext curscontext, GucSource cursource)
7199 const char *name = variable->name;
7200 GucStack *oldvarstack = variable->stack;
7204 /* First, recurse, so that stack items are processed bottom to top */
7205 reapply_stacked_values(variable, pHolder, stack->prev,
7206 stack->prior.val.stringval,
7207 stack->scontext, stack->source);
7209 /* See how to apply the passed-in value */
7210 switch (stack->state)
7213 (void) set_config_option(name, curvalue,
7214 curscontext, cursource,
7215 GUC_ACTION_SAVE, true, WARNING);
7219 (void) set_config_option(name, curvalue,
7220 curscontext, cursource,
7221 GUC_ACTION_SET, true, WARNING);
7225 (void) set_config_option(name, curvalue,
7226 curscontext, cursource,
7227 GUC_ACTION_LOCAL, true, WARNING);
7231 /* first, apply the masked value as SET */
7232 (void) set_config_option(name, stack->masked.val.stringval,
7233 stack->masked_scontext, PGC_S_SESSION,
7234 GUC_ACTION_SET, true, WARNING);
7235 /* then apply the current value as LOCAL */
7236 (void) set_config_option(name, curvalue,
7237 curscontext, cursource,
7238 GUC_ACTION_LOCAL, true, WARNING);
7242 /* If we successfully made a stack entry, adjust its nest level */
7243 if (variable->stack != oldvarstack)
7244 variable->stack->nest_level = stack->nest_level;
7249 * We are at the end of the stack. If the active/previous value is
7250 * different from the reset value, it must represent a previously
7251 * committed session value. Apply it, and then drop the stack entry
7252 * that set_config_option will have created under the impression that
7253 * this is to be just a transactional assignment. (We leak the stack
7256 if (curvalue != pHolder->reset_val ||
7257 curscontext != pHolder->gen.reset_scontext ||
7258 cursource != pHolder->gen.reset_source)
7260 (void) set_config_option(name, curvalue,
7261 curscontext, cursource,
7262 GUC_ACTION_SET, true, WARNING);
7263 variable->stack = NULL;
7269 DefineCustomBoolVariable(const char *name,
7270 const char *short_desc,
7271 const char *long_desc,
7276 GucBoolCheckHook check_hook,
7277 GucBoolAssignHook assign_hook,
7278 GucShowHook show_hook)
7280 struct config_bool *var;
7282 var = (struct config_bool *)
7283 init_custom_variable(name, short_desc, long_desc, context, flags,
7284 PGC_BOOL, sizeof(struct config_bool));
7285 var->variable = valueAddr;
7286 var->boot_val = bootValue;
7287 var->reset_val = bootValue;
7288 var->check_hook = check_hook;
7289 var->assign_hook = assign_hook;
7290 var->show_hook = show_hook;
7291 define_custom_variable(&var->gen);
7295 DefineCustomIntVariable(const char *name,
7296 const char *short_desc,
7297 const char *long_desc,
7304 GucIntCheckHook check_hook,
7305 GucIntAssignHook assign_hook,
7306 GucShowHook show_hook)
7308 struct config_int *var;
7310 var = (struct config_int *)
7311 init_custom_variable(name, short_desc, long_desc, context, flags,
7312 PGC_INT, sizeof(struct config_int));
7313 var->variable = valueAddr;
7314 var->boot_val = bootValue;
7315 var->reset_val = bootValue;
7316 var->min = minValue;
7317 var->max = maxValue;
7318 var->check_hook = check_hook;
7319 var->assign_hook = assign_hook;
7320 var->show_hook = show_hook;
7321 define_custom_variable(&var->gen);
7325 DefineCustomRealVariable(const char *name,
7326 const char *short_desc,
7327 const char *long_desc,
7334 GucRealCheckHook check_hook,
7335 GucRealAssignHook assign_hook,
7336 GucShowHook show_hook)
7338 struct config_real *var;
7340 var = (struct config_real *)
7341 init_custom_variable(name, short_desc, long_desc, context, flags,
7342 PGC_REAL, sizeof(struct config_real));
7343 var->variable = valueAddr;
7344 var->boot_val = bootValue;
7345 var->reset_val = bootValue;
7346 var->min = minValue;
7347 var->max = maxValue;
7348 var->check_hook = check_hook;
7349 var->assign_hook = assign_hook;
7350 var->show_hook = show_hook;
7351 define_custom_variable(&var->gen);
7355 DefineCustomStringVariable(const char *name,
7356 const char *short_desc,
7357 const char *long_desc,
7359 const char *bootValue,
7362 GucStringCheckHook check_hook,
7363 GucStringAssignHook assign_hook,
7364 GucShowHook show_hook)
7366 struct config_string *var;
7368 var = (struct config_string *)
7369 init_custom_variable(name, short_desc, long_desc, context, flags,
7370 PGC_STRING, sizeof(struct config_string));
7371 var->variable = valueAddr;
7372 var->boot_val = bootValue;
7373 var->check_hook = check_hook;
7374 var->assign_hook = assign_hook;
7375 var->show_hook = show_hook;
7376 define_custom_variable(&var->gen);
7380 DefineCustomEnumVariable(const char *name,
7381 const char *short_desc,
7382 const char *long_desc,
7385 const struct config_enum_entry * options,
7388 GucEnumCheckHook check_hook,
7389 GucEnumAssignHook assign_hook,
7390 GucShowHook show_hook)
7392 struct config_enum *var;
7394 var = (struct config_enum *)
7395 init_custom_variable(name, short_desc, long_desc, context, flags,
7396 PGC_ENUM, sizeof(struct config_enum));
7397 var->variable = valueAddr;
7398 var->boot_val = bootValue;
7399 var->reset_val = bootValue;
7400 var->options = options;
7401 var->check_hook = check_hook;
7402 var->assign_hook = assign_hook;
7403 var->show_hook = show_hook;
7404 define_custom_variable(&var->gen);
7408 EmitWarningsOnPlaceholders(const char *className)
7410 int classLen = strlen(className);
7413 for (i = 0; i < num_guc_variables; i++)
7415 struct config_generic *var = guc_variables[i];
7417 if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
7418 strncmp(className, var->name, classLen) == 0 &&
7419 var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
7422 (errcode(ERRCODE_UNDEFINED_OBJECT),
7423 errmsg("unrecognized configuration parameter \"%s\"",
7434 GetPGVariable(const char *name, DestReceiver *dest)
7436 if (guc_name_compare(name, "all") == 0)
7437 ShowAllGUCConfig(dest);
7439 ShowGUCConfigOption(name, dest);
7443 GetPGVariableResultDesc(const char *name)
7447 if (guc_name_compare(name, "all") == 0)
7449 /* need a tuple descriptor representing three TEXT columns */
7450 tupdesc = CreateTemplateTupleDesc(3, false);
7451 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
7453 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
7455 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
7460 const char *varname;
7462 /* Get the canonical spelling of name */
7463 (void) GetConfigOptionByName(name, &varname);
7465 /* need a tuple descriptor representing a single TEXT column */
7466 tupdesc = CreateTemplateTupleDesc(1, false);
7467 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
7478 ShowGUCConfigOption(const char *name, DestReceiver *dest)
7480 TupOutputState *tstate;
7482 const char *varname;
7485 /* Get the value and canonical spelling of name */
7486 value = GetConfigOptionByName(name, &varname);
7488 /* need a tuple descriptor representing a single TEXT column */
7489 tupdesc = CreateTemplateTupleDesc(1, false);
7490 TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
7493 /* prepare for projection of tuples */
7494 tstate = begin_tup_output_tupdesc(dest, tupdesc);
7497 do_text_output_oneline(tstate, value);
7499 end_tup_output(tstate);
7506 ShowAllGUCConfig(DestReceiver *dest)
7508 bool am_superuser = superuser();
7510 TupOutputState *tstate;
7513 bool isnull[3] = {false, false, false};
7515 /* need a tuple descriptor representing three TEXT columns */
7516 tupdesc = CreateTemplateTupleDesc(3, false);
7517 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
7519 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
7521 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
7524 /* prepare for projection of tuples */
7525 tstate = begin_tup_output_tupdesc(dest, tupdesc);
7527 for (i = 0; i < num_guc_variables; i++)
7529 struct config_generic *conf = guc_variables[i];
7532 if ((conf->flags & GUC_NO_SHOW_ALL) ||
7533 ((conf->flags & GUC_SUPERUSER_ONLY) && !am_superuser))
7536 /* assign to the values array */
7537 values[0] = PointerGetDatum(cstring_to_text(conf->name));
7539 setting = _ShowOption(conf, true);
7542 values[1] = PointerGetDatum(cstring_to_text(setting));
7547 values[1] = PointerGetDatum(NULL);
7551 values[2] = PointerGetDatum(cstring_to_text(conf->short_desc));
7553 /* send it to dest */
7554 do_tup_output(tstate, values, isnull);
7557 pfree(DatumGetPointer(values[0]));
7561 pfree(DatumGetPointer(values[1]));
7563 pfree(DatumGetPointer(values[2]));
7566 end_tup_output(tstate);
7570 * Return GUC variable value by name; optionally return canonical
7571 * form of name. Return value is palloc'd.
7574 GetConfigOptionByName(const char *name, const char **varname)
7576 struct config_generic *record;
7578 record = find_option(name, false, ERROR);
7581 (errcode(ERRCODE_UNDEFINED_OBJECT),
7582 errmsg("unrecognized configuration parameter \"%s\"", name)));
7583 if ((record->flags & GUC_SUPERUSER_ONLY) && !superuser())
7585 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7586 errmsg("must be superuser to examine \"%s\"", name)));
7589 *varname = record->name;
7591 return _ShowOption(record, true);
7595 * Return GUC variable value by variable number; optionally return canonical
7596 * form of name. Return value is palloc'd.
7599 GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
7602 struct config_generic *conf;
7604 /* check requested variable number valid */
7605 Assert((varnum >= 0) && (varnum < num_guc_variables));
7607 conf = guc_variables[varnum];
7611 if ((conf->flags & GUC_NO_SHOW_ALL) ||
7612 ((conf->flags & GUC_SUPERUSER_ONLY) && !superuser()))
7618 /* first get the generic attributes */
7621 values[0] = conf->name;
7623 /* setting : use _ShowOption in order to avoid duplicating the logic */
7624 values[1] = _ShowOption(conf, false);
7627 if (conf->vartype == PGC_INT)
7631 switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
7636 case GUC_UNIT_BLOCKS:
7637 snprintf(buf, sizeof(buf), "%dkB", BLCKSZ / 1024);
7640 case GUC_UNIT_XBLOCKS:
7641 snprintf(buf, sizeof(buf), "%dkB", XLOG_BLCKSZ / 1024);
7662 values[3] = config_group_names[conf->group];
7665 values[4] = conf->short_desc;
7668 values[5] = conf->long_desc;
7671 values[6] = GucContext_Names[conf->context];
7674 values[7] = config_type_names[conf->vartype];
7677 values[8] = GucSource_Names[conf->source];
7679 /* now get the type specifc attributes */
7680 switch (conf->vartype)
7684 struct config_bool *lconf = (struct config_bool *) conf;
7696 values[12] = pstrdup(lconf->boot_val ? "on" : "off");
7699 values[13] = pstrdup(lconf->reset_val ? "on" : "off");
7705 struct config_int *lconf = (struct config_int *) conf;
7708 snprintf(buffer, sizeof(buffer), "%d", lconf->min);
7709 values[9] = pstrdup(buffer);
7712 snprintf(buffer, sizeof(buffer), "%d", lconf->max);
7713 values[10] = pstrdup(buffer);
7719 snprintf(buffer, sizeof(buffer), "%d", lconf->boot_val);
7720 values[12] = pstrdup(buffer);
7723 snprintf(buffer, sizeof(buffer), "%d", lconf->reset_val);
7724 values[13] = pstrdup(buffer);
7730 struct config_real *lconf = (struct config_real *) conf;
7733 snprintf(buffer, sizeof(buffer), "%g", lconf->min);
7734 values[9] = pstrdup(buffer);
7737 snprintf(buffer, sizeof(buffer), "%g", lconf->max);
7738 values[10] = pstrdup(buffer);
7744 snprintf(buffer, sizeof(buffer), "%g", lconf->boot_val);
7745 values[12] = pstrdup(buffer);
7748 snprintf(buffer, sizeof(buffer), "%g", lconf->reset_val);
7749 values[13] = pstrdup(buffer);
7755 struct config_string *lconf = (struct config_string *) conf;
7767 if (lconf->boot_val == NULL)
7770 values[12] = pstrdup(lconf->boot_val);
7773 if (lconf->reset_val == NULL)
7776 values[13] = pstrdup(lconf->reset_val);
7782 struct config_enum *lconf = (struct config_enum *) conf;
7793 * NOTE! enumvals with double quotes in them are not
7796 values[11] = config_enum_get_options((struct config_enum *) conf,
7797 "{\"", "\"}", "\",\"");
7800 values[12] = pstrdup(config_enum_lookup_by_value(lconf,
7804 values[13] = pstrdup(config_enum_lookup_by_value(lconf,
7812 * should never get here, but in case we do, set 'em to NULL
7834 * If the setting came from a config file, set the source location. For
7835 * security reasons, we don't show source file/line number for
7838 if (conf->source == PGC_S_FILE && superuser())
7840 values[14] = conf->sourcefile;
7841 snprintf(buffer, sizeof(buffer), "%d", conf->sourceline);
7842 values[15] = pstrdup(buffer);
7852 * Return the total number of GUC variables
7855 GetNumConfigOptions(void)
7857 return num_guc_variables;
7861 * show_config_by_name - equiv to SHOW X command but implemented as
7865 show_config_by_name(PG_FUNCTION_ARGS)
7870 /* Get the GUC variable name */
7871 varname = TextDatumGetCString(PG_GETARG_DATUM(0));
7874 varval = GetConfigOptionByName(varname, NULL);
7876 /* Convert to text */
7877 PG_RETURN_TEXT_P(cstring_to_text(varval));
7881 * show_all_settings - equiv to SHOW ALL command but implemented as
7884 #define NUM_PG_SETTINGS_ATTS 16
7887 show_all_settings(PG_FUNCTION_ARGS)
7889 FuncCallContext *funcctx;
7893 AttInMetadata *attinmeta;
7894 MemoryContext oldcontext;
7896 /* stuff done only on the first call of the function */
7897 if (SRF_IS_FIRSTCALL())
7899 /* create a function context for cross-call persistence */
7900 funcctx = SRF_FIRSTCALL_INIT();
7903 * switch to memory context appropriate for multiple function calls
7905 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
7908 * need a tuple descriptor representing NUM_PG_SETTINGS_ATTS columns
7909 * of the appropriate types
7911 tupdesc = CreateTemplateTupleDesc(NUM_PG_SETTINGS_ATTS, false);
7912 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
7914 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
7916 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "unit",
7918 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "category",
7920 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "short_desc",
7922 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "extra_desc",
7924 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "context",
7926 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "vartype",
7928 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "source",
7930 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "min_val",
7932 TupleDescInitEntry(tupdesc, (AttrNumber) 11, "max_val",
7934 TupleDescInitEntry(tupdesc, (AttrNumber) 12, "enumvals",
7935 TEXTARRAYOID, -1, 0);
7936 TupleDescInitEntry(tupdesc, (AttrNumber) 13, "boot_val",
7938 TupleDescInitEntry(tupdesc, (AttrNumber) 14, "reset_val",
7940 TupleDescInitEntry(tupdesc, (AttrNumber) 15, "sourcefile",
7942 TupleDescInitEntry(tupdesc, (AttrNumber) 16, "sourceline",
7946 * Generate attribute metadata needed later to produce tuples from raw
7949 attinmeta = TupleDescGetAttInMetadata(tupdesc);
7950 funcctx->attinmeta = attinmeta;
7952 /* total number of tuples to be returned */
7953 funcctx->max_calls = GetNumConfigOptions();
7955 MemoryContextSwitchTo(oldcontext);
7958 /* stuff done on every call of the function */
7959 funcctx = SRF_PERCALL_SETUP();
7961 call_cntr = funcctx->call_cntr;
7962 max_calls = funcctx->max_calls;
7963 attinmeta = funcctx->attinmeta;
7965 if (call_cntr < max_calls) /* do when there is more left to send */
7967 char *values[NUM_PG_SETTINGS_ATTS];
7973 * Get the next visible GUC variable name and value
7977 GetConfigOptionByNum(call_cntr, (const char **) values, &noshow);
7980 /* bump the counter and get the next config setting */
7981 call_cntr = ++funcctx->call_cntr;
7983 /* make sure we haven't gone too far now */
7984 if (call_cntr >= max_calls)
7985 SRF_RETURN_DONE(funcctx);
7990 tuple = BuildTupleFromCStrings(attinmeta, values);
7992 /* make the tuple into a datum */
7993 result = HeapTupleGetDatum(tuple);
7995 SRF_RETURN_NEXT(funcctx, result);
7999 /* do when there is no more left */
8000 SRF_RETURN_DONE(funcctx);
8005 _ShowOption(struct config_generic * record, bool use_units)
8010 switch (record->vartype)
8014 struct config_bool *conf = (struct config_bool *) record;
8016 if (conf->show_hook)
8017 val = (*conf->show_hook) ();
8019 val = *conf->variable ? "on" : "off";
8025 struct config_int *conf = (struct config_int *) record;
8027 if (conf->show_hook)
8028 val = (*conf->show_hook) ();
8032 * Use int64 arithmetic to avoid overflows in units
8035 int64 result = *conf->variable;
8038 if (use_units && result > 0 &&
8039 (record->flags & GUC_UNIT_MEMORY))
8041 switch (record->flags & GUC_UNIT_MEMORY)
8043 case GUC_UNIT_BLOCKS:
8044 result *= BLCKSZ / 1024;
8046 case GUC_UNIT_XBLOCKS:
8047 result *= XLOG_BLCKSZ / 1024;
8051 if (result % KB_PER_TB == 0)
8053 result /= KB_PER_TB;
8056 else if (result % KB_PER_GB == 0)
8058 result /= KB_PER_GB;
8061 else if (result % KB_PER_MB == 0)
8063 result /= KB_PER_MB;
8071 else if (use_units && result > 0 &&
8072 (record->flags & GUC_UNIT_TIME))
8074 switch (record->flags & GUC_UNIT_TIME)
8080 result *= MS_PER_MIN;
8084 if (result % MS_PER_D == 0)
8089 else if (result % MS_PER_H == 0)
8094 else if (result % MS_PER_MIN == 0)
8096 result /= MS_PER_MIN;
8099 else if (result % MS_PER_S == 0)
8112 snprintf(buffer, sizeof(buffer), INT64_FORMAT "%s",
8121 struct config_real *conf = (struct config_real *) record;
8123 if (conf->show_hook)
8124 val = (*conf->show_hook) ();
8127 snprintf(buffer, sizeof(buffer), "%g",
8136 struct config_string *conf = (struct config_string *) record;
8138 if (conf->show_hook)
8139 val = (*conf->show_hook) ();
8140 else if (*conf->variable && **conf->variable)
8141 val = *conf->variable;
8149 struct config_enum *conf = (struct config_enum *) record;
8151 if (conf->show_hook)
8152 val = (*conf->show_hook) ();
8154 val = config_enum_lookup_by_value(conf, *conf->variable);
8159 /* just to keep compiler quiet */
8164 return pstrdup(val);
8171 * These routines dump out all non-default GUC options into a binary
8172 * file that is read by all exec'ed backends. The format is:
8174 * variable name, string, null terminated
8175 * variable value, string, null terminated
8176 * variable sourcefile, string, null terminated (empty if none)
8177 * variable sourceline, integer
8178 * variable source, integer
8179 * variable scontext, integer
8182 write_one_nondefault_variable(FILE *fp, struct config_generic * gconf)
8184 if (gconf->source == PGC_S_DEFAULT)
8187 fprintf(fp, "%s", gconf->name);
8190 switch (gconf->vartype)
8194 struct config_bool *conf = (struct config_bool *) gconf;
8196 if (*conf->variable)
8197 fprintf(fp, "true");
8199 fprintf(fp, "false");
8205 struct config_int *conf = (struct config_int *) gconf;
8207 fprintf(fp, "%d", *conf->variable);
8213 struct config_real *conf = (struct config_real *) gconf;
8215 fprintf(fp, "%.17g", *conf->variable);
8221 struct config_string *conf = (struct config_string *) gconf;
8223 fprintf(fp, "%s", *conf->variable);
8229 struct config_enum *conf = (struct config_enum *) gconf;
8232 config_enum_lookup_by_value(conf, *conf->variable));
8239 if (gconf->sourcefile)
8240 fprintf(fp, "%s", gconf->sourcefile);
8243 fwrite(&gconf->sourceline, 1, sizeof(gconf->sourceline), fp);
8244 fwrite(&gconf->source, 1, sizeof(gconf->source), fp);
8245 fwrite(&gconf->scontext, 1, sizeof(gconf->scontext), fp);
8249 write_nondefault_variables(GucContext context)
8255 Assert(context == PGC_POSTMASTER || context == PGC_SIGHUP);
8257 elevel = (context == PGC_SIGHUP) ? LOG : ERROR;
8262 fp = AllocateFile(CONFIG_EXEC_PARAMS_NEW, "w");
8266 (errcode_for_file_access(),
8267 errmsg("could not write to file \"%s\": %m",
8268 CONFIG_EXEC_PARAMS_NEW)));
8272 for (i = 0; i < num_guc_variables; i++)
8274 write_one_nondefault_variable(fp, guc_variables[i]);
8280 (errcode_for_file_access(),
8281 errmsg("could not write to file \"%s\": %m",
8282 CONFIG_EXEC_PARAMS_NEW)));
8287 * Put new file in place. This could delay on Win32, but we don't hold
8288 * any exclusive locks.
8290 rename(CONFIG_EXEC_PARAMS_NEW, CONFIG_EXEC_PARAMS);
8295 * Read string, including null byte from file
8297 * Return NULL on EOF and nothing read
8300 read_string_with_null(FILE *fp)
8309 if ((ch = fgetc(fp)) == EOF)
8314 elog(FATAL, "invalid format of exec config params file");
8317 str = guc_malloc(FATAL, maxlen);
8318 else if (i == maxlen)
8319 str = guc_realloc(FATAL, str, maxlen *= 2);
8328 * This routine loads a previous postmaster dump of its non-default
8332 read_nondefault_variables(void)
8339 GucSource varsource;
8340 GucContext varscontext;
8343 * Assert that PGC_BACKEND case in set_config_option() will do the right
8346 Assert(IsInitProcessingMode());
8351 fp = AllocateFile(CONFIG_EXEC_PARAMS, "r");
8354 /* File not found is fine */
8355 if (errno != ENOENT)
8357 (errcode_for_file_access(),
8358 errmsg("could not read from file \"%s\": %m",
8359 CONFIG_EXEC_PARAMS)));
8365 struct config_generic *record;
8367 if ((varname = read_string_with_null(fp)) == NULL)
8370 if ((record = find_option(varname, true, FATAL)) == NULL)
8371 elog(FATAL, "failed to locate variable \"%s\" in exec config params file", varname);
8373 if ((varvalue = read_string_with_null(fp)) == NULL)
8374 elog(FATAL, "invalid format of exec config params file");
8375 if ((varsourcefile = read_string_with_null(fp)) == NULL)
8376 elog(FATAL, "invalid format of exec config params file");
8377 if (fread(&varsourceline, 1, sizeof(varsourceline), fp) != sizeof(varsourceline))
8378 elog(FATAL, "invalid format of exec config params file");
8379 if (fread(&varsource, 1, sizeof(varsource), fp) != sizeof(varsource))
8380 elog(FATAL, "invalid format of exec config params file");
8381 if (fread(&varscontext, 1, sizeof(varscontext), fp) != sizeof(varscontext))
8382 elog(FATAL, "invalid format of exec config params file");
8384 (void) set_config_option(varname, varvalue,
8385 varscontext, varsource,
8386 GUC_ACTION_SET, true, 0);
8387 if (varsourcefile[0])
8388 set_config_sourcefile(varname, varsourcefile, varsourceline);
8392 free(varsourcefile);
8397 #endif /* EXEC_BACKEND */
8401 * A little "long argument" simulation, although not quite GNU
8402 * compliant. Takes a string of the form "some-option=some value" and
8403 * returns name = "some_option" and value = "some value" in malloc'ed
8404 * storage. Note that '-' is converted to '_' in the option name. If
8405 * there is no '=' in the input string then value will be NULL.
8408 ParseLongOption(const char *string, char **name, char **value)
8417 equal_pos = strcspn(string, "=");
8419 if (string[equal_pos] == '=')
8421 *name = guc_malloc(FATAL, equal_pos + 1);
8422 strlcpy(*name, string, equal_pos + 1);
8424 *value = guc_strdup(FATAL, &string[equal_pos + 1]);
8428 /* no equal sign in string */
8429 *name = guc_strdup(FATAL, string);
8433 for (cp = *name; *cp; cp++)
8440 * Handle options fetched from pg_db_role_setting.setconfig,
8441 * pg_proc.proconfig, etc. Caller must specify proper context/source/action.
8443 * The array parameter must be an array of TEXT (it must not be NULL).
8446 ProcessGUCArray(ArrayType *array,
8447 GucContext context, GucSource source, GucAction action)
8451 Assert(array != NULL);
8452 Assert(ARR_ELEMTYPE(array) == TEXTOID);
8453 Assert(ARR_NDIM(array) == 1);
8454 Assert(ARR_LBOUND(array)[0] == 1);
8456 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
8464 d = array_ref(array, 1, &i,
8465 -1 /* varlenarray */ ,
8466 -1 /* TEXT's typlen */ ,
8467 false /* TEXT's typbyval */ ,
8468 'i' /* TEXT's typalign */ ,
8474 s = TextDatumGetCString(d);
8476 ParseLongOption(s, &name, &value);
8480 (errcode(ERRCODE_SYNTAX_ERROR),
8481 errmsg("could not parse setting for parameter \"%s\"",
8487 (void) set_config_option(name, value,
8500 * Add an entry to an option array. The array parameter may be NULL
8501 * to indicate the current table entry is NULL.
8504 GUCArrayAdd(ArrayType *array, const char *name, const char *value)
8506 struct config_generic *record;
8514 /* test if the option is valid and we're allowed to set it */
8515 (void) validate_option_array_item(name, value, false);
8517 /* normalize name (converts obsolete GUC names to modern spellings) */
8518 record = find_option(name, false, WARNING);
8520 name = record->name;
8522 /* build new item for array */
8523 newval = psprintf("%s=%s", name, value);
8524 datum = CStringGetTextDatum(newval);
8532 Assert(ARR_ELEMTYPE(array) == TEXTOID);
8533 Assert(ARR_NDIM(array) == 1);
8534 Assert(ARR_LBOUND(array)[0] == 1);
8536 index = ARR_DIMS(array)[0] + 1; /* add after end */
8538 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
8543 d = array_ref(array, 1, &i,
8544 -1 /* varlenarray */ ,
8545 -1 /* TEXT's typlen */ ,
8546 false /* TEXT's typbyval */ ,
8547 'i' /* TEXT's typalign */ ,
8551 current = TextDatumGetCString(d);
8553 /* check for match up through and including '=' */
8554 if (strncmp(current, newval, strlen(name) + 1) == 0)
8561 a = array_set(array, 1, &index,
8564 -1 /* varlena array */ ,
8565 -1 /* TEXT's typlen */ ,
8566 false /* TEXT's typbyval */ ,
8567 'i' /* TEXT's typalign */ );
8570 a = construct_array(&datum, 1,
8579 * Delete an entry from an option array. The array parameter may be NULL
8580 * to indicate the current table entry is NULL. Also, if the return value
8581 * is NULL then a null should be stored.
8584 GUCArrayDelete(ArrayType *array, const char *name)
8586 struct config_generic *record;
8587 ArrayType *newarray;
8593 /* test if the option is valid and we're allowed to set it */
8594 (void) validate_option_array_item(name, NULL, false);
8596 /* normalize name (converts obsolete GUC names to modern spellings) */
8597 record = find_option(name, false, WARNING);
8599 name = record->name;
8601 /* if array is currently null, then surely nothing to delete */
8608 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
8614 d = array_ref(array, 1, &i,
8615 -1 /* varlenarray */ ,
8616 -1 /* TEXT's typlen */ ,
8617 false /* TEXT's typbyval */ ,
8618 'i' /* TEXT's typalign */ ,
8622 val = TextDatumGetCString(d);
8624 /* ignore entry if it's what we want to delete */
8625 if (strncmp(val, name, strlen(name)) == 0
8626 && val[strlen(name)] == '=')
8629 /* else add it to the output array */
8631 newarray = array_set(newarray, 1, &index,
8634 -1 /* varlenarray */ ,
8635 -1 /* TEXT's typlen */ ,
8636 false /* TEXT's typbyval */ ,
8637 'i' /* TEXT's typalign */ );
8639 newarray = construct_array(&d, 1,
8651 * Given a GUC array, delete all settings from it that our permission
8652 * level allows: if superuser, delete them all; if regular user, only
8653 * those that are PGC_USERSET
8656 GUCArrayReset(ArrayType *array)
8658 ArrayType *newarray;
8662 /* if array is currently null, nothing to do */
8666 /* if we're superuser, we can delete everything, so just do it */
8673 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
8680 d = array_ref(array, 1, &i,
8681 -1 /* varlenarray */ ,
8682 -1 /* TEXT's typlen */ ,
8683 false /* TEXT's typbyval */ ,
8684 'i' /* TEXT's typalign */ ,
8688 val = TextDatumGetCString(d);
8690 eqsgn = strchr(val, '=');
8693 /* skip if we have permission to delete it */
8694 if (validate_option_array_item(val, NULL, true))
8697 /* else add it to the output array */
8699 newarray = array_set(newarray, 1, &index,
8702 -1 /* varlenarray */ ,
8703 -1 /* TEXT's typlen */ ,
8704 false /* TEXT's typbyval */ ,
8705 'i' /* TEXT's typalign */ );
8707 newarray = construct_array(&d, 1,
8719 * Validate a proposed option setting for GUCArrayAdd/Delete/Reset.
8721 * name is the option name. value is the proposed value for the Add case,
8722 * or NULL for the Delete/Reset cases. If skipIfNoPermissions is true, it's
8723 * not an error to have no permissions to set the option.
8725 * Returns TRUE if OK, FALSE if skipIfNoPermissions is true and user does not
8726 * have permission to change this option (all other error cases result in an
8727 * error being thrown).
8730 validate_option_array_item(const char *name, const char *value,
8731 bool skipIfNoPermissions)
8734 struct config_generic *gconf;
8737 * There are three cases to consider:
8739 * name is a known GUC variable. Check the value normally, check
8740 * permissions normally (ie, allow if variable is USERSET, or if it's
8741 * SUSET and user is superuser).
8743 * name is not known, but exists or can be created as a placeholder (i.e.,
8744 * it has a prefixed name). We allow this case if you're a superuser,
8745 * otherwise not. Superusers are assumed to know what they're doing. We
8746 * can't allow it for other users, because when the placeholder is
8747 * resolved it might turn out to be a SUSET variable;
8748 * define_custom_variable assumes we checked that.
8750 * name is not known and can't be created as a placeholder. Throw error,
8751 * unless skipIfNoPermissions is true, in which case return FALSE.
8753 gconf = find_option(name, true, WARNING);
8756 /* not known, failed to make a placeholder */
8757 if (skipIfNoPermissions)
8760 (errcode(ERRCODE_UNDEFINED_OBJECT),
8761 errmsg("unrecognized configuration parameter \"%s\"",
8765 if (gconf->flags & GUC_CUSTOM_PLACEHOLDER)
8768 * We cannot do any meaningful check on the value, so only permissions
8769 * are useful to check.
8773 if (skipIfNoPermissions)
8776 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
8777 errmsg("permission denied to set parameter \"%s\"", name)));
8780 /* manual permissions check so we can avoid an error being thrown */
8781 if (gconf->context == PGC_USERSET)
8783 else if (gconf->context == PGC_SUSET && superuser())
8785 else if (skipIfNoPermissions)
8787 /* if a permissions error should be thrown, let set_config_option do it */
8789 /* test for permissions and valid option value */
8790 (void) set_config_option(name, value,
8791 superuser() ? PGC_SUSET : PGC_USERSET,
8792 PGC_S_TEST, GUC_ACTION_SET, false, 0);
8799 * Called by check_hooks that want to override the normal
8800 * ERRCODE_INVALID_PARAMETER_VALUE SQLSTATE for check hook failures.
8802 * Note that GUC_check_errmsg() etc are just macros that result in a direct
8803 * assignment to the associated variables. That is ugly, but forced by the
8804 * limitations of C's macro mechanisms.
8807 GUC_check_errcode(int sqlerrcode)
8809 GUC_check_errcode_value = sqlerrcode;
8814 * Convenience functions to manage calling a variable's check_hook.
8815 * These mostly take care of the protocol for letting check hooks supply
8816 * portions of the error report on failure.
8820 call_bool_check_hook(struct config_bool * conf, bool *newval, void **extra,
8821 GucSource source, int elevel)
8823 /* Quick success if no hook */
8824 if (!conf->check_hook)
8827 /* Reset variables that might be set by hook */
8828 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8829 GUC_check_errmsg_string = NULL;
8830 GUC_check_errdetail_string = NULL;
8831 GUC_check_errhint_string = NULL;
8833 if (!(*conf->check_hook) (newval, extra, source))
8836 (errcode(GUC_check_errcode_value),
8837 GUC_check_errmsg_string ?
8838 errmsg_internal("%s", GUC_check_errmsg_string) :
8839 errmsg("invalid value for parameter \"%s\": %d",
8840 conf->gen.name, (int) *newval),
8841 GUC_check_errdetail_string ?
8842 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
8843 GUC_check_errhint_string ?
8844 errhint("%s", GUC_check_errhint_string) : 0));
8845 /* Flush any strings created in ErrorContext */
8854 call_int_check_hook(struct config_int * conf, int *newval, void **extra,
8855 GucSource source, int elevel)
8857 /* Quick success if no hook */
8858 if (!conf->check_hook)
8861 /* Reset variables that might be set by hook */
8862 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8863 GUC_check_errmsg_string = NULL;
8864 GUC_check_errdetail_string = NULL;
8865 GUC_check_errhint_string = NULL;
8867 if (!(*conf->check_hook) (newval, extra, source))
8870 (errcode(GUC_check_errcode_value),
8871 GUC_check_errmsg_string ?
8872 errmsg_internal("%s", GUC_check_errmsg_string) :
8873 errmsg("invalid value for parameter \"%s\": %d",
8874 conf->gen.name, *newval),
8875 GUC_check_errdetail_string ?
8876 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
8877 GUC_check_errhint_string ?
8878 errhint("%s", GUC_check_errhint_string) : 0));
8879 /* Flush any strings created in ErrorContext */
8888 call_real_check_hook(struct config_real * conf, double *newval, void **extra,
8889 GucSource source, int elevel)
8891 /* Quick success if no hook */
8892 if (!conf->check_hook)
8895 /* Reset variables that might be set by hook */
8896 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8897 GUC_check_errmsg_string = NULL;
8898 GUC_check_errdetail_string = NULL;
8899 GUC_check_errhint_string = NULL;
8901 if (!(*conf->check_hook) (newval, extra, source))
8904 (errcode(GUC_check_errcode_value),
8905 GUC_check_errmsg_string ?
8906 errmsg_internal("%s", GUC_check_errmsg_string) :
8907 errmsg("invalid value for parameter \"%s\": %g",
8908 conf->gen.name, *newval),
8909 GUC_check_errdetail_string ?
8910 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
8911 GUC_check_errhint_string ?
8912 errhint("%s", GUC_check_errhint_string) : 0));
8913 /* Flush any strings created in ErrorContext */
8922 call_string_check_hook(struct config_string * conf, char **newval, void **extra,
8923 GucSource source, int elevel)
8925 /* Quick success if no hook */
8926 if (!conf->check_hook)
8929 /* Reset variables that might be set by hook */
8930 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8931 GUC_check_errmsg_string = NULL;
8932 GUC_check_errdetail_string = NULL;
8933 GUC_check_errhint_string = NULL;
8935 if (!(*conf->check_hook) (newval, extra, source))
8938 (errcode(GUC_check_errcode_value),
8939 GUC_check_errmsg_string ?
8940 errmsg_internal("%s", GUC_check_errmsg_string) :
8941 errmsg("invalid value for parameter \"%s\": \"%s\"",
8942 conf->gen.name, *newval ? *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 */
8956 call_enum_check_hook(struct config_enum * conf, int *newval, void **extra,
8957 GucSource source, int elevel)
8959 /* Quick success if no hook */
8960 if (!conf->check_hook)
8963 /* Reset variables that might be set by hook */
8964 GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
8965 GUC_check_errmsg_string = NULL;
8966 GUC_check_errdetail_string = NULL;
8967 GUC_check_errhint_string = NULL;
8969 if (!(*conf->check_hook) (newval, extra, source))
8972 (errcode(GUC_check_errcode_value),
8973 GUC_check_errmsg_string ?
8974 errmsg_internal("%s", GUC_check_errmsg_string) :
8975 errmsg("invalid value for parameter \"%s\": \"%s\"",
8977 config_enum_lookup_by_value(conf, *newval)),
8978 GUC_check_errdetail_string ?
8979 errdetail_internal("%s", GUC_check_errdetail_string) : 0,
8980 GUC_check_errhint_string ?
8981 errhint("%s", GUC_check_errhint_string) : 0));
8982 /* Flush any strings created in ErrorContext */
8992 * check_hook, assign_hook and show_hook subroutines
8996 check_log_destination(char **newval, void **extra, GucSource source)
9004 /* Need a modifiable copy of string */
9005 rawstring = pstrdup(*newval);
9007 /* Parse string into list of identifiers */
9008 if (!SplitIdentifierString(rawstring, ',', &elemlist))
9010 /* syntax error in list */
9011 GUC_check_errdetail("List syntax is invalid.");
9013 list_free(elemlist);
9017 foreach(l, elemlist)
9019 char *tok = (char *) lfirst(l);
9021 if (pg_strcasecmp(tok, "stderr") == 0)
9022 newlogdest |= LOG_DESTINATION_STDERR;
9023 else if (pg_strcasecmp(tok, "csvlog") == 0)
9024 newlogdest |= LOG_DESTINATION_CSVLOG;
9026 else if (pg_strcasecmp(tok, "syslog") == 0)
9027 newlogdest |= LOG_DESTINATION_SYSLOG;
9030 else if (pg_strcasecmp(tok, "eventlog") == 0)
9031 newlogdest |= LOG_DESTINATION_EVENTLOG;
9035 GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
9037 list_free(elemlist);
9043 list_free(elemlist);
9045 myextra = (int *) guc_malloc(ERROR, sizeof(int));
9046 *myextra = newlogdest;
9047 *extra = (void *) myextra;
9053 assign_log_destination(const char *newval, void *extra)
9055 Log_destination = *((int *) extra);
9059 assign_syslog_facility(int newval, void *extra)
9062 set_syslog_parameters(syslog_ident_str ? syslog_ident_str : "postgres",
9065 /* Without syslog support, just ignore it */
9069 assign_syslog_ident(const char *newval, void *extra)
9072 set_syslog_parameters(newval, syslog_facility);
9074 /* Without syslog support, it will always be set to "none", so ignore */
9079 assign_session_replication_role(int newval, void *extra)
9082 * Must flush the plan cache when changing replication role; but don't
9083 * flush unnecessarily.
9085 if (SessionReplicationRole != newval)
9090 check_temp_buffers(int *newval, void **extra, GucSource source)
9093 * Once local buffers have been initialized, it's too late to change this.
9095 if (NLocBuffer && NLocBuffer != *newval)
9097 GUC_check_errdetail("\"temp_buffers\" cannot be changed after any temporary tables have been accessed in the session.");
9104 check_phony_autocommit(bool *newval, void **extra, GucSource source)
9108 GUC_check_errcode(ERRCODE_FEATURE_NOT_SUPPORTED);
9109 GUC_check_errmsg("SET AUTOCOMMIT TO OFF is no longer supported");
9116 check_bonjour(bool *newval, void **extra, GucSource source)
9121 GUC_check_errmsg("Bonjour is not supported by this build");
9129 check_ssl(bool *newval, void **extra, GucSource source)
9134 GUC_check_errmsg("SSL is not supported by this build");
9142 check_stage_log_stats(bool *newval, void **extra, GucSource source)
9144 if (*newval && log_statement_stats)
9146 GUC_check_errdetail("Cannot enable parameter when \"log_statement_stats\" is true.");
9153 check_log_stats(bool *newval, void **extra, GucSource source)
9156 (log_parser_stats || log_planner_stats || log_executor_stats))
9158 GUC_check_errdetail("Cannot enable \"log_statement_stats\" when "
9159 "\"log_parser_stats\", \"log_planner_stats\", "
9160 "or \"log_executor_stats\" is true.");
9167 check_canonical_path(char **newval, void **extra, GucSource source)
9170 * Since canonicalize_path never enlarges the string, we can just modify
9171 * newval in-place. But watch out for NULL, which is the default value
9172 * for external_pid_file.
9175 canonicalize_path(*newval);
9180 check_timezone_abbreviations(char **newval, void **extra, GucSource source)
9183 * The boot_val given above for timezone_abbreviations is NULL. When we
9184 * see this we just do nothing. If this value isn't overridden from the
9185 * config file then pg_timezone_abbrev_initialize() will eventually
9186 * replace it with "Default". This hack has two purposes: to avoid
9187 * wasting cycles loading values that might soon be overridden from the
9188 * config file, and to avoid trying to read the timezone abbrev files
9189 * during InitializeGUCOptions(). The latter doesn't work in an
9190 * EXEC_BACKEND subprocess because my_exec_path hasn't been set yet and so
9191 * we can't locate PGSHAREDIR.
9193 if (*newval == NULL)
9195 Assert(source == PGC_S_DEFAULT);
9199 /* OK, load the file and produce a malloc'd TimeZoneAbbrevTable */
9200 *extra = load_tzoffsets(*newval);
9202 /* tzparser.c returns NULL on failure, reporting via GUC_check_errmsg */
9210 assign_timezone_abbreviations(const char *newval, void *extra)
9212 /* Do nothing for the boot_val default of NULL */
9216 InstallTimeZoneAbbrevs((TimeZoneAbbrevTable *) extra);
9220 * pg_timezone_abbrev_initialize --- set default value if not done already
9222 * This is called after initial loading of postgresql.conf. If no
9223 * timezone_abbreviations setting was found therein, select default.
9224 * If a non-default value is already installed, nothing will happen.
9226 * This can also be called from ProcessConfigFile to establish the default
9227 * value after a postgresql.conf entry for it is removed.
9230 pg_timezone_abbrev_initialize(void)
9232 SetConfigOption("timezone_abbreviations", "Default",
9233 PGC_POSTMASTER, PGC_S_DYNAMIC_DEFAULT);
9237 show_archive_command(void)
9239 if (XLogArchivingActive())
9240 return XLogArchiveCommand;
9242 return "(disabled)";
9246 assign_tcp_keepalives_idle(int newval, void *extra)
9249 * The kernel API provides no way to test a value without setting it; and
9250 * once we set it we might fail to unset it. So there seems little point
9251 * in fully implementing the check-then-assign GUC API for these
9252 * variables. Instead we just do the assignment on demand. pqcomm.c
9253 * reports any problems via elog(LOG).
9255 * This approach means that the GUC value might have little to do with the
9256 * actual kernel value, so we use a show_hook that retrieves the kernel
9257 * value rather than trusting GUC's copy.
9259 (void) pq_setkeepalivesidle(newval, MyProcPort);
9263 show_tcp_keepalives_idle(void)
9265 /* See comments in assign_tcp_keepalives_idle */
9266 static char nbuf[16];
9268 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesidle(MyProcPort));
9273 assign_tcp_keepalives_interval(int newval, void *extra)
9275 /* See comments in assign_tcp_keepalives_idle */
9276 (void) pq_setkeepalivesinterval(newval, MyProcPort);
9280 show_tcp_keepalives_interval(void)
9282 /* See comments in assign_tcp_keepalives_idle */
9283 static char nbuf[16];
9285 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesinterval(MyProcPort));
9290 assign_tcp_keepalives_count(int newval, void *extra)
9292 /* See comments in assign_tcp_keepalives_idle */
9293 (void) pq_setkeepalivescount(newval, MyProcPort);
9297 show_tcp_keepalives_count(void)
9299 /* See comments in assign_tcp_keepalives_idle */
9300 static char nbuf[16];
9302 snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivescount(MyProcPort));
9307 check_maxconnections(int *newval, void **extra, GucSource source)
9309 if (*newval + autovacuum_max_workers + 1 +
9310 max_worker_processes > MAX_BACKENDS)
9316 check_autovacuum_max_workers(int *newval, void **extra, GucSource source)
9318 if (MaxConnections + *newval + 1 + max_worker_processes > MAX_BACKENDS)
9324 check_autovacuum_work_mem(int *newval, void **extra, GucSource source)
9327 * -1 indicates fallback.
9329 * If we haven't yet changed the boot_val default of -1, just let it be.
9330 * Autovacuum will look to maintenance_work_mem instead.
9336 * We clamp manually-set values to at least 1MB. Since
9337 * maintenance_work_mem is always set to at least this value, do the same
9347 check_max_worker_processes(int *newval, void **extra, GucSource source)
9349 if (MaxConnections + autovacuum_max_workers + 1 + *newval > MAX_BACKENDS)
9355 check_effective_io_concurrency(int *newval, void **extra, GucSource source)
9358 double new_prefetch_pages = 0.0;
9362 * The user-visible GUC parameter is the number of drives (spindles),
9363 * which we need to translate to a number-of-pages-to-prefetch target.
9364 * The target value is stashed in *extra and then assigned to the actual
9365 * variable by assign_effective_io_concurrency.
9367 * The expected number of prefetch pages needed to keep N drives busy is:
9369 * drives | I/O requests
9370 * -------+----------------
9373 * 3 | 3/1 + 3/2 + 3/3 = 5 1/2
9374 * 4 | 4/1 + 4/2 + 4/3 + 4/4 = 8 1/3
9377 * This is called the "coupon collector problem" and H(n) is called the
9378 * harmonic series. This could be approximated by n * ln(n), but for
9379 * reasonable numbers of drives we might as well just compute the series.
9381 * Alternatively we could set the target to the number of pages necessary
9382 * so that the expected number of active spindles is some arbitrary
9383 * percentage of the total. This sounds the same but is actually slightly
9384 * different. The result ends up being ln(1-P)/ln((n-1)/n) where P is
9385 * that desired fraction.
9387 * Experimental results show that both of these formulas aren't aggressive
9388 * enough, but we don't really have any better proposals.
9390 * Note that if *newval = 0 (disabled), we must set target = 0.
9394 for (i = 1; i <= *newval; i++)
9395 new_prefetch_pages += (double) *newval / (double) i;
9397 /* This range check shouldn't fail, but let's be paranoid */
9398 if (new_prefetch_pages >= 0.0 && new_prefetch_pages < (double) INT_MAX)
9400 int *myextra = (int *) guc_malloc(ERROR, sizeof(int));
9402 *myextra = (int) rint(new_prefetch_pages);
9403 *extra = (void *) myextra;
9411 #endif /* USE_PREFETCH */
9415 assign_effective_io_concurrency(int newval, void *extra)
9418 target_prefetch_pages = *((int *) extra);
9419 #endif /* USE_PREFETCH */
9423 assign_pgstat_temp_directory(const char *newval, void *extra)
9425 /* check_canonical_path already canonicalized newval for us */
9431 dname = guc_malloc(ERROR, strlen(newval) + 1); /* runtime dir */
9432 sprintf(dname, "%s", newval);
9435 tname = guc_malloc(ERROR, strlen(newval) + 12); /* /global.tmp */
9436 sprintf(tname, "%s/global.tmp", newval);
9437 fname = guc_malloc(ERROR, strlen(newval) + 13); /* /global.stat */
9438 sprintf(fname, "%s/global.stat", newval);
9440 if (pgstat_stat_directory)
9441 free(pgstat_stat_directory);
9442 pgstat_stat_directory = dname;
9443 if (pgstat_stat_tmpname)
9444 free(pgstat_stat_tmpname);
9445 pgstat_stat_tmpname = tname;
9446 if (pgstat_stat_filename)
9447 free(pgstat_stat_filename);
9448 pgstat_stat_filename = fname;
9452 check_application_name(char **newval, void **extra, GucSource source)
9454 /* Only allow clean ASCII chars in the application name */
9457 for (p = *newval; *p; p++)
9459 if (*p < 32 || *p > 126)
9467 assign_application_name(const char *newval, void *extra)
9469 /* Update the pg_stat_activity view */
9470 pgstat_report_appname(newval);
9474 show_unix_socket_permissions(void)
9478 snprintf(buf, sizeof(buf), "%04o", Unix_socket_permissions);
9483 show_log_file_mode(void)
9487 snprintf(buf, sizeof(buf), "%04o", Log_file_mode);
9491 #include "guc-file.c"