PostgreSQL归档配置及自动清理归档日志的操作
导读:收集整理的这篇文章主要介绍了PostgreSQL归档配置及自动清理归档日志的操作,觉得挺不错的,现在分享给大家,也给大家做个参考。 在一般的生产环境中,数据库都需要开启归档模式,那么在P...
收集整理的这篇文章主要介绍了PostgreSQL归档配置及自动清理归档日志的操作,觉得挺不错的,现在分享给大家,也给大家做个参考。 在一般的生产环境中,数据库都需要开启归档模式,那么在Pg中如何开启归档模式呢?
pg中的归档配置涉及几个参数如下:
# - Archiving - 是否开启归档 #archive_mode = off # enables archiving;
off, on, or always # (change requires restart) 归档命令,注意 %p %f %% 格式化的含义。 %p 是被归档的redo文件的路径, %f 是被归档的redo文档的文件名 %% 是百分号 #archive_command = '' # 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' 超时强制归档,例:如果10分钟数据库都没有什么活动,一个redo文件没有写完,就不会归档, 但是我们希望数据库至少10分钟要切换一个日志,则可以使用archive_timeout #archive_timeout = 0 # force a logfile segment swITch after this # number of seconds;
0 disables –归档配置方法为:
1、创建归档目录
pg12@oracle->
mkdir -p $PGDATA/archive/2、编辑归档脚本
该脚本还可以删除7天内的归档日志。
pg12@oracle->
vi $PGDATA/arch.shtest ! -f $PGDATA/arch/$1 &
&
cp --PReserve=timestamps $2 $PGDATA/arch/$1 ;
find /arch/ -tyPE f -mtime +7 -exec rm -f {
}
\;
3、配置归档相关参数
wal_level = replica archive_mode = on archive_command = 'arch.sh %f %p'
配置完之后重启数据库服务即可。
pg12@oracle->
ps -ef|grep archiverpg12 21338 21331 0 20:20 ? 00:00:00 postgres: archiver补充:postgreSQL归档失败并在日志文件中存在报错
PG运行过程中出现归档失败的情况,并在日志文件中存在报错。
报错如下:
cp: writing `/arch/20171204/000000010000000000000002': No space left on deviceLOG: archive command failed with exit code 1DETAIL: The failed archive command was: DATE=`date +%Y%m%d`;
DIR="/arch/$DATE";
(test -d $DIR || mkdir -p $DIR)&
&
cp pg_xlog/000000010000000000000002 $DIR/000000010000000000000002cp: writing `/arch/20171204/000000010000000000000002': No space left on deviceLOG: archive command failed with exit code 1DETAIL: The failed archive command was: DATE=`date +%Y%m%d`;
DIR="/arch/$DATE";
(test -d $DIR || mkdir -p $DIR)&
&
cp pg_xlog/000000010000000000000002 $DIR/000000010000000000000002cp: writing `/arch/20171204/000000010000000000000002': No space left on deviceLOG: archive command failed with exit code 1DETAIL: The failed archive command was: DATE=`date +%Y%m%d`;
DIR="/arch/$DATE";
(test -d $DIR || mkdir -p $DIR)&
&
cp pg_xlog/000000010000000000000002 $DIR/000000010000000000000002WARNING: archiving transaction log file "000000010000000000000002" failed too many times, will try again later原因是归档日志所在文件系统/arch空间不足。
通过清理该文件系统下过期的临时文件,或将归档日志存放至更大的系统空间中。
以上为个人经验,希望能给大家一个参考,也希望大家多多支持。如有错误或未考虑完全的地方,望不吝赐教。
您可能感兴趣的文章:- PostgreSQL 性能优化之服务器参数配置操作
- postgresql 性能参数配置方式
- postgresql安装及配置超详细教程
- Postgresql的日志配置教程详解
- PostgreSQL 逻辑复制 配置操作
- 基于PostgreSQL pg_hba.conf 配置参数的使用说明
- PostgreSQL 自动Vacuum配置方式
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: PostgreSQL归档配置及自动清理归档日志的操作
本文地址: https://pptw.com/jishu/633091.html
