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.

PostgreSQL Configuration – managing scary settings的更多相关文章

  1. 创建 userSettings/Microsoft.SqlServer.Configuration.LandingPage.Properties.Settings 的配置节处理程序时出错: 未能加载文件或程序集“System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”或它的某一个依赖项。系统没找到指定的文件

    创建 userSettings/Microsoft.SqlServer.Configuration.LandingPage.Properties.Settings 的配置节处理程序时出错: 未能加载文 ...

  2. PostgreSQL configuration file postgresql.conf recommanded settings and how it works

    1        Set max_connections to three times the number of processor cores on the server. Include vir ...

  3. P6 EPPM Installation and Configuration Guide 16 R1 April 2016

    P6 EPPM Installation and Configuration Guide 16 R1         April 2016 Contents About Installing and ...

  4. P6 Professional Installation and Configuration Guide (Microsoft SQL Server Database) 16 R1

    P6 Professional Installation and Configuration Guide (Microsoft SQL Server Database) 16 R1       May ...

  5. 【转载】使用barman备份PostgreSQL

    什么是barman Barman (备份和恢复管理器) 是 PostgreSQL 数据库服务器中非常方便的备份和恢复工具,允许远程备份多个服务器,允许从一个备份集中一个命令就恢复数据库.同时还可以对多 ...

  6. postgresql 开启远程访问

    1.如果服务器启用了防火墙,需要在防火墙上开启 5432 端口. 2.修改 PostgreSQL 配置文件 postgresql.conf.postgresql.conf,Linux 配置文件所在路径 ...

  7. Managing Group Policy with PowerShell

    Overview In this article, I’ll talk about your options when it comes to managing Group Policy using ...

  8. postgresql安装概览

    先从官网下载解压包:https://www.enterprisedb.com/download-postgresql-binaries 这种是解压后,进行配置就可以使用. 另外一种是要用./confi ...

  9. Dockerize PostgreSQL

    Dockerize PostgreSQL Installing PostgreSQL on Docker Assuming there is no Docker image that suits yo ...

随机推荐

  1. MySQL 绿色版(zip) 安装

    设置环境变量Path,指向到MYSQL下的bin目录 修改MYSQL下的my-default.ini basedir=%MYSQL_HOME% datadir=%MYSQL_HOME%\data 到M ...

  2. java CountDownLatch

    Listing -. Using a Countdown Latch to Trigger a Coordinated Start import java.util.concurrent.CountD ...

  3. Delphi 缩放图像代码 - 支持PNG透明通道

    要求Delphi2007或者更高版本, 系统要求至少XP-SP2以上 实际上是利用了Windows的windowscodecs.dll这个文件的功能 在VCL里已经封装为TWICImage类 proc ...

  4. 文件对比工具Beyond Compare使用方法

    今天向大家介绍一个使用起来十分方便且功能十分强大的文件对比工具-Beyond Compare. 1    工具下载 工具的下载很简单,百度搜索Beyond Compare即可. 下载完成后,解压缩,双 ...

  5. php curl多线程抓取网页

    PHP 利用 Curl Functions 可以完成各种传送文件操作,比如模拟浏览器发送GET,POST请求等等,受限于php语言本身不支持多线程,所以开发爬虫程序效率并不高,这时候往往需 要借助Cu ...

  6. Redis学习笔记(6)-SortedSet

    package cn.com; import java.util.HashMap; import java.util.Map; import java.util.Set; import redis.c ...

  7. AutoLayout技术选型和应用

    前言:这篇文章是笔者在项目中对布局技术进行技术选型和应用的相关介绍,供大家参考. && [self.buttonscount] > 0) { UIButton *button = ...

  8. CENTOS安装vnc

    先直接进入命令模式,如果是服务器则可以使用putty连接进入命令行模式. 现在知道的centos下的vnc是:tigervnc,由于是服务端所以我们只安装tigervnc-server即可: yum ...

  9. [LeetCode]题解(python):039-Combination Sum

    题目来源 https://leetcode.com/problems/combination-sum/ Given a set of candidate numbers (C) and a targe ...

  10. 错误提示: An App ID with identifier "*****" is not avaliable. Please enter a different string.

    百度了很多,但大多的解决办法就是 更改BundleID,的确管用,,但是有的情况下,你需要跟同事合作,公用同一个BundleID, 我是这样处理的:工具栏中打开Window—project删除所有工程 ...