环境准备
数据库:postgresql 11
系统:阿里云centos7
测试过程
数据库安装过程不再描述。
准备测试环境
//创建保存wal日志归档的目录,并修改目录拥有者
mkdir /usr/wallog_bk
chown postgres:postgres -R wallog_bk
//修改PG数据库配置文件postgresql.conf
vi /usr/pgsql-11/data/postgresql.conf
//修改如下配置项:
wal_level = replica
archive_mode = on //打开归档功能
archive_command = 'cp %p /usr/wallog_bk/%f' //配置归档命令,拷贝到wal文件到指定目录,%p为实际的wal文件目录,%f为wal文件名称
//保存后重启数据库
su postgres
pg_ctl restart
此时已打开wal日志归档功能。
准备测试数据
创建test库,并在test库中创建test表,并写入1000条数据
postgres=# create database test;
postgres=# \c test
You are now connected to database "test" as user "postgres".
test=# create table test(id int, name text);
CREATE TABLE
test