Postgresql 交换即使有足够的空闲内存

问题描述 投票:0回答:0

让我问一个关于我在生产数据库中处理的问题。我们有 postgresql 13 数据库,即使有足够的内存,它也使用交换,我根本不明白。你知道我的设置有什么问题吗? - 从我的角度来看,应该没有交换。 swap 甚至没有释放——一旦它被填满,它就会保持 100% 使用

Red Hat Enterprise Linux 8 上的 Postgresql-13 版本 Postgresql.conf

listen_addresses = '0.0.0.0'        # what IP address(es) to listen on;
max_connections = 2000          # (change requires restart)
tcp_keepalives_idle = 600
tcp_keepalives_interval = 5
tcp_keepalives_count = 2
shared_buffers = 16GB           # min 128kB
work_mem = 50MB
maintenance_work_mem = 512MB        # min 1MB
dynamic_shared_memory_type = posix  # the default is the first option
wal_level = 'hot_standby'           # minimal, replica, or logical
wal_log_hints = on          # also do full page writes of non-critical updates
max_wal_size = 6GB
min_wal_size = 2GB
archive_mode = on       # enables archiving; off, on, or always
archive_command = 'test -w /u02/postgres/wal && test ! -f /u02/postgres/wal/%f && cp %p /u02/postgres/wal/%f'
max_wal_senders = 10        # max number of walsender processes
wal_keep_size = 4000        # in megabytes; 0 disables
max_replication_slots = 10  # max number of replication slots
hot_standby = on            # "off" disallows queries during recovery
effective_cache_size = 32GB
log_destination = 'stderr'      # Valid values are combinations of
logging_collector = on          # Enable capturing of stderr and csvlog
log_directory = 'log'           # directory where log files are written,
log_filename = 'postgresql-%a.log'  # log file name pattern,
log_truncate_on_rotation = on       # If on, an existing log file with the
log_rotation_age = 1d           # Automatic rotation of logfiles will
log_rotation_size = 0           # Automatic rotation of logfiles will
log_line_prefix = '%t [%p]: user=%u,db=%d,app=%a,client=%h '        # special values:
log_timezone = 'Europe/Prague'
datestyle = 'iso, mdy'
timezone = 'Europe/Prague'
lc_messages = 'en_US.UTF-8'         # locale for system error message
lc_monetary = 'en_US.UTF-8'         # locale for monetary formatting
lc_numeric = 'en_US.UTF-8'          # locale for number formatting
lc_time = 'en_US.UTF-8'             # locale for time formatting
default_text_search_config = 'pg_catalog.english'
shared_preload_libraries = 'pg_stat_statements'

实际内存

 free -h
              total        used        free      shared  buff/cache   available
Mem:           62Gi       1.7Gi        43Gi        16Gi        17Gi        43Gi
Swap:         2.0Gi       2.0Gi       0.0Ki

我将 shared_buffers 从 4G 更改为 16G,work_mem 从 4MB 更改为 50MB,effective_cache_size 从 8G 更改为 32G。

linux postgresql memory swap
© www.soinside.com 2019 - 2024. All rights reserved.