Postgres 9.3工作负载消耗所有内存和交换

时间:2018-03-20 18:11:12

标签: postgresql postgresql-9.3

我有一个运行Postgres 9.3的AWS实例,带有4GB内存和2个vCPU。似乎有一个临界点,重负载测试导致postmaster进程开始消耗所有内存并最终消耗所有swap(1GB)。我认为postgresql.conf文件中的值看起来相当保守。

我甚至尝试将shared_buffers丢弃到2GB,将max_connections放到20 ......没有效果它只是继续吃内存和交换。

应该注意的是,我有100个架构。谁能发现我失踪的东西?

archive_command = 'cd .'
archive_mode = on
archive_timeout = 300
checkpoint_completion_target = 0.9
checkpoint_segments = 64
datestyle = 'iso, mdy'
default_statistics_target = 100
default_text_search_config = 'pg_catalog.english'
effective_cache_size = 3GB
hot_standby = on
lc_messages = 'en_US.UTF-8'
lc_monetary = 'en_US.UTF-8'
lc_numeric = 'en_US.UTF-8'
lc_time = 'en_US.UTF-8'
listen_addresses = '*'
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
logging_collector = on
log_rotation_age = 1d
log_rotation_size = 0
log_timezone = 'UTC'
log_truncate_on_rotation = on
maintenance_work_mem = 256MB
max_connections = 80
max_wal_senders = 10
password_encryption = on
shared_buffers = 1GB
shared_preload_libraries = 'repmgr_funcs'
timezone = 'UTC'
track_activities = on
track_counts = on
track_io_timing = on
wal_buffers = 16MB
wal_keep_segments = 288
wal_level = 'hot_standby'
max_locks_per_transaction=256
work_mem = 4MB

1 个答案:

答案 0 :(得分:0)

我建议采用以下方法:

  1. 确保这是一个问题。那就是:将数据库驱动到"失败"条件,并拍摄top输出的快照。您想要找到具有最大postgresql
  2. RSS-SHR进程
  3. 分析有问题的postgresql进程的内存消耗。您可以关注PostgreSQL wiki和/或https://www.cybertec-postgresql.com/en/checking-per-memory-context-memory-consumption/
  4. 小睡一下
  5. 仅通过对#2
  6. 的分析来识别错误
  7. 如果#4失败,请将#1和#2发布到pgsql-hackers邮件列表