1、
https://www.cnblogs.com/kreo/p/15304980.html
https://www.jb51.net/article/203722.htm
1、事先检查命令
# 查看数据目录(找出conf文件位置)
postgres=# SHOW data_directory;
# 查看归档模式情况
postgres=# show archive_mode;
archive_mode
--------------
off
2 . 启用归档模式
首先建立归档目录
#建立归档目录
mkdir -p /u02/pgsql95log/arch/
# 更改所有者 , 权限给postgres用户
chown -R postgres.postgres /u02/pgsql95log/arch/
打开并修改postgresql.conf , 并修改三个参数
# 打开归档模式
archive_mode = on
# 配置归档命令
archive_command = 'DATE=`date +%Y%m%d`;DIR="/u02/pgsql95log/arch/$DATE";(test -d $DIR || mkdir -p $DIR)&& cp %p $DIR/%f'
# 日志等级 10版本以上为reploca(默认值) 可以不用修改
wal_level = archive
简单说明一下archive_command :
他的值可以是一条shell命令或者一个复杂的shell脚本。
%p : 表示将要归档的wal文件包含完整路径的信息的文件名(就是需要归档的临时文件)
%f : 代表不包含路径信息的wal文件的文件名
%% : 表示%
比如 :
# 创建一个shell
vi /home/postgres/bin/arch.sh
# 以下为shell的内容
# 测试目录 , 复制日志文件 , 并删除7天前的日志文件
test ! -f /home/postgres/arch/$1 && cp --preserve=timestamps $2 /home/postgres/arch/$1 ; find /home/postgres/arch/ -type f -mtime +7 -exec rm -f {} \;
# 以下为archive_command
archive_command = '/home/postgres/bin/arch.sh %f %p'
5. 重启PostgreSQL服务
4 . 验证归档模式启用情况
查看归档情况 >>>
# 查看归档模式
postgres=# show archive_mode;
# 检查点 , 刷新脏数据
postgres=# checkpoint
# 查看归档情况
postgres=# select pg_switch_wal();
查看归档日志存放目录 >>>
[postgres@localhost arch]$ ls -l /u02/pgsql95log/arch
total 0
drwx------ 2 postgres postgres 37 Sep 17 15:28 20210917
[postgres@localhost arch]$ ls -l /u02/pgsql95log/arch/20210917/
total 16384
-rw------- 1 postgres postgres 16777216 Sep 17 15:28 000000010000004500000019
分类:
数据库
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2018-09-21 bash-4.2$ bash: /home/test/.bashrc: 权限不够