postgresql - pg_wal正在占用大量磁盘空间

标签 postgresql docker pgbackrest

我已经使用docker-compose在容器化的环境中安装了postgres,因为我已经使用了这个docker镜像crunchydata/crunchy-postgres-gis:centos7-11.5-2.4.2,直到我意识到PG_DIR/pg_wal占用了大量磁盘空间为止,所有命令都运行正常,我不想每次都不要使用pg_archivecleanup一项cron作业,但是我想配置postgres使其自动执行。请问,正确的配置是什么?
这是我的postgresql.conf文件。

listen_addresses = '*'          # what IP address(es) to listen on;
port = 5432                             # (change requires restart)
unix_socket_directories = '/tmp'        # comma-separated list of directories
unix_socket_permissions = 0777          # begin with 0 to use octal notation
temp_buffers = 8MB                      # min 800kB

max_connections = 400
shared_buffers = 1536MB
effective_cache_size = 4608MB
maintenance_work_mem = 384MB
checkpoint_completion_target = 0.7
wal_buffers = 16MB
default_statistics_target = 100
random_page_cost = 1.1
effective_io_concurrency = 200
work_mem = 4MB
min_wal_size = 1GB
max_wal_size = 2GB
max_worker_processes = 4
max_parallel_workers_per_gather = 2
max_parallel_workers = 4
unix_socket_directories = '/tmp'        # comma-separated list of directories
unix_socket_permissions = 0777          # begin with 0 to use octal notation
shared_preload_libraries = 'pg_stat_statements.so'              # (change requires restart)

#------------------------------------------------------------------------------
# WRITE AHEAD LOG
#------------------------------------------------------------------------------
wal_level = hot_standby                 # minimal, archive, or hot_standby
max_wal_senders = 6             # max number of walsender processes
wal_keep_segments = 400         # in logfile segments, 16MB each; 0 disables
hot_standby = on                        # "on" allows queries during recovery
max_standby_archive_delay = 30s # max delay before canceling queries
max_standby_streaming_delay = 30s       # max delay before canceling queries
wal_receiver_status_interval = 10s      # send replies at least this often
archive_mode = on               # enables archiving; off, on, or always
# (change requires restart)
archive_command = 'pgbackrest archive-push %p'          # command to use to archive a logfile segment
# placeholders: %p = path of file to archive
#               %f = file name only
# e.g. 'test ! -f /mnt/server/archivedir/%f && cp %p /mnt/server/archivedir/%f'
archive_timeout = 60            # force a logfile segment switch after this
# number of seconds; 0 disables
#------------------------------------------------------------------------------
# ERROR REPORTING AND LOGGING
#------------------------------------------------------------------------------
log_destination = 'stderr'              # Valid values are combinations of
logging_collector = on                  # Enable capturing of stderr and csvlog
log_directory = 'pg_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_min_duration_statement = 0  # -1 is disabled, 0 logs all statements
log_checkpoints = on
log_connections = on
log_disconnections = on
log_line_prefix = '%t [%p]: [%l-1] user=%u,db=%d,app=%a,client=%h'
log_lock_waits = on                     # log lock waits >= deadlock_timeout
log_timezone = 'US/Eastern'
log_autovacuum_min_duration = 0 # -1 disables, 0 logs all actions and
datestyle = 'iso, mdy'
timezone = 'US/Eastern'
lc_messages = 'C'                       # locale for system error message
lc_monetary = 'C'                       # locale for monetary formatting
lc_numeric = 'C'                        # locale for number formatting
lc_time = 'C'                           # locale for time formatting
default_text_search_config = 'pg_catalog.english'
谢谢

最佳答案

您尚未向我们显示pgbackrest与此有关的任何证据。如果失败,则应该在服务器的日志文件中看到有关该消息的消息。如果成功了,那么它应该占用归档文件中的空间,无论它在哪里,而不是pg_wal中。
但是wal_keep_segments = 400将导致保留超过6.25GB的pg_wal。我不知道这是否构成“很多”。pg_archivecleanup不是用于清理pg_wal,而是用于清理存档。

关于postgresql - pg_wal正在占用大量磁盘空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64380348/

相关文章:

php - INSERT 如果不存在,否则返回 id

Docker Buildx 无法从本地拉取继承的镜像

bash - Bash 脚本中的 $@ 为 ENTRYPOINT 空白,除非 --entrypoint

Docker compose - 在 shell 中运行 shell 和应用程序

json - 如何使用 jq 获得每个组和子组的最大值

postgresql - 无法使用 DBeaver 连接到本地 postgresql 数据库

postgresql - 将来自多行的 tsvectors 合并为一个

sql - PostgreSQL : Add constraint with mulitple conditions