PostgreSQL Active Standby系统的配置搭建和容灾切换 - part1(8)

2019-04-16 19:16

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页


PostgreSQL Active Standby系统的配置搭建和容灾切换 - part1(8).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:面向对象程序设计(java)题库

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: