MES PostgreSQL数据库active standby 系统的配置搭建和容灾切换
从上面备库上的两图结果可以看出,日志的接收和应用已经同步完成。
保密 Confidential第36页 | 共47页
MES PostgreSQL数据库active standby 系统的配置搭建和容灾切换
6.4测试主库和备库的数据同步
在主库上做一些操作:
$ /opt/Postgresql/9.1/bin/psql-h 192.168.15.122 -p 5432 -d postgres postgres=# create table t (idint primary key,namevarchar(20)); postgres=# insert into t values (1,'xxxxxxx'); postgres=# insert into t values (2,'xxxxxxx'); postgres=#
然后在备库上看是否同步到了备库:
$ /opt/Postgresql/9.1/bin/psql-h 192.168.15.121-p 5432 -d postgres postgres=# \\d 保密 Confidential第37页 | 共47页
MES PostgreSQL数据库active standby 系统的配置搭建和容灾切换 postgres=#select* from t;
可以看到主库上创建的表和插入的数据已经同步到备库。
7.备库上的备份设置
7.1备机上的备份目录
数据库备份目录:/data/mes_backup
#chown postgres:postgres/data/mes_backup
保密 Confidential第38页 | 共47页
MES PostgreSQL数据库active standby 系统的配置搭建和容灾切换
7.2备份脚本
1、脚本存放位置:/home/postgres/ 2、脚本内容:
备份的脚本mesdb_backup.sh: #!/bin/sh
export LD_LIBRARY_PATH=/opt/PostgreSQL/9.1/lib:/opt/pgAgent/lib:$LD_LIBRARY_PATH export
PATH=/opt/PostgreSQL/9.1/bin:/opt/pgAgent/bin:/opt/PostgreSQL/9.1/lib:/opt/pgAgent/lib:$PATH export PGDATA=/data/mes_data/mes export PGPASSWORD=postgres
echo \
pg_dumpall -h localhost -p 5432 -U postgres -l postgres > /home/postgres/mesdb_`date '+%Y%m%d%H%M%S'`.backup
echo \exit;
保密 Confidential第39页 | 共47页
MES PostgreSQL数据库active standby 系统的配置搭建和容灾切换
7.3调度备份任务
1. 设置检查脚本用户组和权限
#chown postgres:postgres/home/postgres/mesdb_backup.sh #chmod +x /home/postgres/mesdb_backup.sh //赋予可执行权限 2. 每天凌晨1:00执行全备份
在crontab文件中新增备份的调度配置 (login as root) : #crontab -e
0 1 * * * su - postgres -c“/home/postgres/mesdb_backup.sh>/data/mes_backup/mesdb_backup.log” 保存退出。脚本将会在每天凌晨1:00点自动执行进行数据库备份。
保密 Confidential第40页 | 共47页