0
点赞
收藏
分享

微信扫一扫

PG 归档日志清理方案

waaagh 2022-07-13 阅读 64


清理 1 天 之前的数据

cat >>  $PGDATA/arch.sh <<"EOF"
test ! -f /postgresql/archive_log/$1 && cp --preserve=timestamps $2 /postgresql/archive_log/$1 ; find /postgresql/archive_log -type f -mtime +1 -exec rm -f {} \;
EOF

清理20分钟之前的文件 归档并清理日志文件的 脚本

cat >>  $PGDATA/arch.sh <<"EOF"
test ! -f /postgresql/archive_log/$1 && cp --preserve=timestamps $2 /postgresql/archive_log/$1 ; find /postgresql/archive_log -type f -mmin +20 -exec rm -f {} \;
EOF


chmod +x $PGDATA/arch.sh


cat >> $PGDATA/postgresql.sh <<"EOF"
listen_addresses = '*'
logging_collector = on
log_destination = 'csvlog'
log_directory = '/postgresql/running_log'
log_filename = 'postgresql-%u.log'
wal_log_hints = on
archive_mode = on
archive_command = '/postgresql/data/arch.sh %f %p'
EOF

cat >> $PGDATA/recovery.conf <<"EOF"
recovery_target_timeline='latest'
archive_cleanup_command = 'pg_archivecleanup /postgresql/archive_log %r'
EOF


举报

相关推荐

0 条评论