When it comes to highly available database servers and configuration, a very important aspect is whether or not a changed setting requires a database restart before taking effect. While it is true that many of these are important enough and they should be set correctly before starting the server, our requirements evolve sometimes.
If or when this happens, there is no alternative but to restart the PostgreSQL service. There are, of course, steps we can take to avoid this fate. Perhaps, an existing server didn't need the WAL output to be compatible with hot standby servers. Maybe, we need to move the logfile, enable WAL archival, or increase the amount of connections.
These are all scenarios that require us to restart PostgreSQL. We can avoid this by identifying these settings early and paying special attention to them.
PostgreSQL has a lot of useful views for DBAs to get information about the database and its current state. For this section, we will concentrate on the pg_settings view, which supplies a wealth of data regarding the current server settings, defaults, and usage context. We recommend that you peruse the PostgreSQL documentation for this view.
Follow these steps to learn more about PostgreSQL settings:
Execute the following query to obtain a list of settings that require a server restart
and their current value:
[postgres@node1 ~]$ psql -h localhost
psql (9.5.1)
Type "help" for help.
postgres=# select name,setting,unit from pg_settings where context = 'postmaster';
name | setting | unit
-------------------------------------+---------------------------------------+------
allow_system_table_mods | off |
archive_mode | on |
autovacuum_freeze_max_age | 200000000 |
autovacuum_max_workers | 3 |
autovacuum_multixact_freeze_max_age | 400000000 |
bonjour | off |
bonjour_name | |
cluster_name | |
config_file | /usr/local/pg951/data/postgresql.conf |
data_directory | /usr/local/pg951/data |
dynamic_shared_memory_type | posix |
event_source | PostgreSQL |
external_pid_file | |
hba_file | /usr/local/pg951/data/pg_hba.conf |
hot_standby | on |
huge_pages | try |
ident_file | /usr/local/pg951/data/pg_ident.conf |
listen_addresses | * |
logging_collector | off |
max_connections | 100 |
max_files_per_process | 1000 |
max_locks_per_transaction | 64 |
max_pred_locks_per_transaction | 64 |
max_prepared_transactions | 0 |
max_replication_slots | 0 |
max_wal_senders | 10 |
max_worker_processes | 8 |
port | 5432 |
shared_buffers | 16384 | 8kB
shared_preload_libraries | |
ssl | off |
ssl_ca_file | |
ssl_cert_file | server.crt |
ssl_ciphers | none |
ssl_crl_file | |
ssl_ecdh_curve | none |
ssl_key_file | server.key |
ssl_prefer_server_ciphers | on |
superuser_reserved_connections | 3 |
track_activity_query_size | 1024 |
track_commit_timestamp | off |
unix_socket_directories | . |
unix_socket_group | |
unix_socket_permissions | 0777 |
wal_buffers | 512 | 8kB
wal_level | hot_standby |
wal_log_hints | off |
(47 rows)
Execute this query for a list of only those settings that are not changed from the
default and require restart:
postgres=# select name,setting,boot_val from pg_settings
postgres-# where context = 'postmaster' and boot_val = setting;
name | setting | boot_val
-------------------------------------+------------+------------
allow_system_table_mods | off | off
autovacuum_freeze_max_age | 200000000 | 200000000
autovacuum_max_workers | 3 | 3
autovacuum_multixact_freeze_max_age | 400000000 | 400000000
bonjour | off | off
bonjour_name | |
cluster_name | |
dynamic_shared_memory_type | posix | posix
event_source | PostgreSQL | PostgreSQL
huge_pages | try | try
logging_collector | off | off
max_connections | 100 | 100
max_files_per_process | 1000 | 1000
max_locks_per_transaction | 64 | 64
max_pred_locks_per_transaction | 64 | 64
max_prepared_transactions | 0 | 0
max_replication_slots | 0 | 0
max_worker_processes | 8 | 8
port | 5432 | 5432
shared_preload_libraries | |
ssl | off | off
ssl_ca_file | |
ssl_cert_file | server.crt | server.crt
ssl_ciphers | none | none
ssl_crl_file | |
ssl_ecdh_curve | none | none
ssl_key_file | server.key | server.key
ssl_prefer_server_ciphers | on | on
superuser_reserved_connections | 3 | 3
track_activity_query_size | 1024 | 1024
track_commit_timestamp | off | off
unix_socket_group | |
wal_log_hints | off | off
Execute the following query for a list of all settings and a translation of how the
setting is managed:
postgres=# SELECT name,
postgres-# CASE context
postgres-# WHEN 'postmaster' THEN 'REQUIRES RESTART'
postgres-# WHEN 'sighup' THEN 'Reload Config'
postgres-# WHEN 'backend' THEN 'Reload Config'
postgres-# WHEN 'superuser' THEN 'Reload Config / Superuser'
postgres-# WHEN 'user' THEN 'Reload Config / User SET'
postgres-# END AS when_changed
postgres-# FROM pg_settings
postgres-# WHERE context != 'internal'
postgres-# ORDER BY when_changed;
name | when_changed
-------------------------------------+---------------------------
shared_buffers | REQUIRES RESTART
port | REQUIRES RESTART
max_worker_processes | REQUIRES RESTART
max_wal_senders | REQUIRES RESTART
max_replication_slots | REQUIRES RESTART
max_prepared_transactions | REQUIRES RESTART
max_pred_locks_per_transaction | REQUIRES RESTART
max_locks_per_transaction | REQUIRES RESTART
max_files_per_process | REQUIRES RESTART
max_connections | REQUIRES RESTART
dynamic_shared_memory_type | REQUIRES RESTART
logging_collector | REQUIRES RESTART
listen_addresses | REQUIRES RESTART
ident_file | REQUIRES RESTART
huge_pages | REQUIRES RESTART
hot_standby | REQUIRES RESTART
hba_file | REQUIRES RESTART
external_pid_file | REQUIRES RESTART
event_source | REQUIRES RESTART
wal_buffers | REQUIRES RESTART
wal_log_hints | REQUIRES RESTART
wal_level | REQUIRES RESTART
archive_mode | REQUIRES RESTART
bonjour | REQUIRES RESTART
bonjour_name | REQUIRES RESTART
unix_socket_permissions | REQUIRES RESTART
unix_socket_group | REQUIRES RESTART
autovacuum_freeze_max_age | REQUIRES RESTART
autovacuum_max_workers | REQUIRES RESTART
allow_system_table_mods | REQUIRES RESTART
unix_socket_directories | REQUIRES RESTART
track_commit_timestamp | REQUIRES RESTART
cluster_name | REQUIRES RESTART
track_activity_query_size | REQUIRES RESTART
superuser_reserved_connections | REQUIRES RESTART
config_file | REQUIRES RESTART
ssl_prefer_server_ciphers | REQUIRES RESTART
ssl_key_file | REQUIRES RESTART
ssl_ecdh_curve | REQUIRES RESTART
ssl_crl_file | REQUIRES RESTART
ssl_ciphers | REQUIRES RESTART
data_directory | REQUIRES RESTART
ssl_cert_file | REQUIRES RESTART
autovacuum_multixact_freeze_max_age | REQUIRES RESTART
ssl_ca_file | REQUIRES RESTART
ssl | REQUIRES RESTART
shared_preload_libraries | REQUIRES RESTART
checkpoint_warning | Reload Config
archive_command | Reload Config
archive_timeout | Reload Config
authentication_timeout | Reload Config
autovacuum | Reload Config
autovacuum_analyze_scale_factor | Reload Config
autovacuum_analyze_threshold | Reload Config
autovacuum_naptime | Reload Config
autovacuum_vacuum_cost_delay | Reload Config
autovacuum_vacuum_cost_limit | Reload Config
autovacuum_vacuum_scale_factor | Reload Config
autovacuum_vacuum_threshold | Reload Config
autovacuum_work_mem | Reload Config
bgwriter_delay | Reload Config
bgwriter_lru_maxpages | Reload Config
bgwriter_lru_multiplier | Reload Config
checkpoint_completion_target | Reload Config
checkpoint_timeout | Reload Config
db_user_namespace | Reload Config
fsync | Reload Config
full_page_writes | Reload Config
hot_standby_feedback | Reload Config
ignore_system_indexes | Reload Config
krb_caseins_users | Reload Config
krb_server_keyfile | Reload Config
log_autovacuum_min_duration | Reload Config
log_checkpoints | Reload Config
log_destination | Reload Config
log_directory | Reload Config
log_file_mode | Reload Config
log_filename | Reload Config
log_hostname | Reload Config
log_line_prefix | Reload Config
log_rotation_age | Reload Config
log_rotation_size | Reload Config
log_timezone | Reload Config
log_truncate_on_rotation | Reload Config
max_standby_archive_delay | Reload Config
max_standby_streaming_delay | Reload Config
max_wal_size | Reload Config
min_wal_size | Reload Config
post_auth_delay | Reload Config
pre_auth_delay | Reload Config
restart_after_crash | Reload Config
stats_temp_directory | Reload Config
synchronous_standby_names | Reload Config
syslog_facility | Reload Config
syslog_ident | Reload Config
trace_recovery_messages | Reload Config
vacuum_defer_cleanup_age | Reload Config
wal_keep_segments | Reload Config
wal_receiver_status_interval | Reload Config
wal_receiver_timeout | Reload Config
wal_retrieve_retry_interval | Reload Config
wal_sender_timeout | Reload Config
wal_sync_method | Reload Config
wal_writer_delay | Reload Config
lo_compat_privileges | Reload Config / Superuser
lc_messages | Reload Config / Superuser
update_process_title | Reload Config / Superuser
log_duration | Reload Config / Superuser
dynamic_library_path | Reload Config / Superuser
log_lock_waits | Reload Config / Superuser
wal_compression | Reload Config / Superuser
log_min_duration_statement | Reload Config / Superuser
commit_delay | Reload Config / Superuser
log_min_error_statement | Reload Config / Superuser
log_min_messages | Reload Config / Superuser
session_preload_libraries | Reload Config / Superuser
session_replication_role | Reload Config / Superuser
log_parser_stats | Reload Config / Superuser
max_stack_depth | Reload Config / Superuser
temp_file_limit | Reload Config / Superuser
log_planner_stats | Reload Config / Superuser
log_replication_commands | Reload Config / Superuser
deadlock_timeout | Reload Config / Superuser
log_error_verbosity | Reload Config / Superuser
zero_damaged_pages | Reload Config / Superuser
track_counts | Reload Config / Superuser
log_executor_stats | Reload Config / Superuser
track_activities | Reload Config / Superuser
ignore_checksum_failure | Reload Config / Superuser
track_functions | Reload Config / Superuser
log_statement | Reload Config / Superuser
log_statement_stats | Reload Config / Superuser
track_io_timing | Reload Config / Superuser
log_temp_files | Reload Config / Superuser
vacuum_multixact_freeze_table_age | Reload Config / User SET
backslash_quote | Reload Config / User SET
quote_all_identifiers | Reload Config / User SET
random_page_cost | Reload Config / User SET
row_security | Reload Config / User SET
search_path | Reload Config / User SET
seq_page_cost | Reload Config / User SET
debug_print_plan | Reload Config / User SET
debug_print_parse | Reload Config / User SET
sql_inheritance | Reload Config / User SET
debug_pretty_print | Reload Config / User SET
DateStyle | Reload Config / User SET
cursor_tuple_fraction | Reload Config / User SET
cpu_tuple_cost | Reload Config / User SET
cpu_operator_cost | Reload Config / User SET
cpu_index_tuple_cost | Reload Config / User SET
constraint_exclusion | Reload Config / User SET
standard_conforming_strings | Reload Config / User SET
statement_timeout | Reload Config / User SET
xmlbinary | Reload Config / User SET
commit_siblings | Reload Config / User SET
synchronize_seqscans | Reload Config / User SET
synchronous_commit | Reload Config / User SET
array_nulls | Reload Config / User SET
application_name | Reload Config / User SET
xmloption | Reload Config / User SET
tcp_keepalives_count | Reload Config / User SET
tcp_keepalives_idle | Reload Config / User SET
tcp_keepalives_interval | Reload Config / User SET
temp_buffers | Reload Config / User SET
temp_tablespaces | Reload Config / User SET
TimeZone | Reload Config / User SET
timezone_abbreviations | Reload Config / User SET
trace_notify | Reload Config / User SET
trace_sort | Reload Config / User SET
enable_mergejoin | Reload Config / User SET
enable_nestloop | Reload Config / User SET
enable_seqscan | Reload Config / User SET
enable_sort | Reload Config / User SET
enable_tidscan | Reload Config / User SET
escape_string_warning | Reload Config / User SET
enable_material | Reload Config / User SET
exit_on_error | Reload Config / User SET
enable_indexscan | Reload Config / User SET
extra_float_digits | Reload Config / User SET
from_collapse_limit | Reload Config / User SET
client_min_messages | Reload Config / User SET
geqo | Reload Config / User SET
geqo_effort | Reload Config / User SET
geqo_generations | Reload Config / User SET
geqo_pool_size | Reload Config / User SET
geqo_seed | Reload Config / User SET
geqo_selection_bias | Reload Config / User SET
geqo_threshold | Reload Config / User SET
gin_fuzzy_search_limit | Reload Config / User SET
gin_pending_list_limit | Reload Config / User SET
enable_indexonlyscan | Reload Config / User SET
enable_hashjoin | Reload Config / User SET
enable_hashagg | Reload Config / User SET
enable_bitmapscan | Reload Config / User SET
IntervalStyle | Reload Config / User SET
join_collapse_limit | Reload Config / User SET
transaction_deferrable | Reload Config / User SET
effective_io_concurrency | Reload Config / User SET
local_preload_libraries | Reload Config / User SET
lock_timeout | Reload Config / User SET
transaction_isolation | Reload Config / User SET
transaction_read_only | Reload Config / User SET
transform_null_equals | Reload Config / User SET
client_encoding | Reload Config / User SET
check_function_bodies | Reload Config / User SET
bytea_output | Reload Config / User SET
vacuum_cost_delay | Reload Config / User SET
vacuum_cost_limit | Reload Config / User SET
vacuum_cost_page_dirty | Reload Config / User SET
vacuum_cost_page_hit | Reload Config / User SET
vacuum_cost_page_miss | Reload Config / User SET
effective_cache_size | Reload Config / User SET
maintenance_work_mem | Reload Config / User SET
default_with_oids | Reload Config / User SET
default_transaction_read_only | Reload Config / User SET
default_transaction_isolation | Reload Config / User SET
default_transaction_deferrable | Reload Config / User SET
default_text_search_config | Reload Config / User SET
work_mem | Reload Config / User SET
vacuum_freeze_min_age | Reload Config / User SET
default_tablespace | Reload Config / User SET
vacuum_freeze_table_age | Reload Config / User SET
default_statistics_target | Reload Config / User SET
vacuum_multixact_freeze_min_age | Reload Config / User SET
operator_precedence_warning | Reload Config / User SET
password_encryption | Reload Config / User SET
debug_print_rewritten | Reload Config / User SET
lc_numeric | Reload Config / User SET
lc_time | Reload Config / User SET
lc_monetary | Reload Config / User SET
log_disconnections |
log_connections |
(232 rows)
The first query, and the simplest one, merely identifies the name and value for each setting that can only be modified by restarting PostgreSQL. In relation to all the available settings, this list is relatively short. However, there are a few notable settings that could affect us.
The second query only shows the settings that we have not already changed but would require server restart. This list is potentially more interesting and concise, as we are presumably seeking further parameters to modify. Of course, the opposite can also be argued; we have only modified the settings we care about.
The final query is a bit more complicated as it uses a CASE statement, yet it also simplifies the contents of the view. First, consider the WHERE clause, which purges internal settings. We don't care about these specifically because they can only be set when compiling PostgreSQL itself. While such an action may be necessary to apply an emergency patch from the PostgreSQL developers, we cannot modify several of these parameters without rebuilding the entire contents of every affected database. These settings are for experts only, and these experts rarely even consider changing them.
Within SELECT, we fetch the setting name as well as how it is modified. Note that all settings that require a server reload to take effect are found in postgresql.conf. Subsequent changes applied at the session level can also be overridden using SET syntax, so we included that as well.