首页 > 学院 > 开发设计 > 正文

PostgreSQL学习篇15.2 同步流复制的standby数据库

2019-11-08 20:34:58
字体:
来源:转载
供稿:网友
从9.1后,提供了同步流复制的架构。同步复制要求在数据写入standby数据库后,事务的commit才返回,所以standby库出现问题时,会导致主库hang住。可以启动两个standby数据库,只要有一个是正常的,主库就不会hang住。但是因为资源限制,这里只配置一个standby库。环境:主机名ip地址角色数据目录pg186.168.100.14主库/PostgreSQL/9.6.1/datanpghs186.168.100.24standby/PostgreSQL/9.6.1/datass实现同步复制功能主要是在主库上配置参数“synchronous_standby_names”,这个参数指定多个standby的名称,各个名称通过逗号分隔,而standby名称是在standby连接到主库时,由连接参数“application_name”指定的。要使用同步复制,standby库中的recovery.conf里的PRimary_conninfo一定要指定“application_name”。配置步骤:在主库上配置:host    replication     postgres       186.168.100.0/24                  trustpostgresql.conf设置:listen_addresses = '*'max_wal_senders = 5wal_level = hot_standby增加:synchronous_standby_names='standby01'      --在最后只需reloadstandby库的操作:[postgres@pghs ~]$ pg_basebackup -h 186.168.100.14 -U postgres -F p -P -x -R -D /PostgreSQL/9.6.1/datass -l  postgresbackup2017021045098/45098 kB (100%), 2/2 tablespaces修改recovery.confstandby_mode = 'on'primary_conninfo = 'application_name=standby01 user=postgres host=186.168.100.14 port=5432 sslmode=disable sslcompression=1'在主库reload,使synchronous_standby_names='standby01'  生效起备库:[postgres@pghs datass]$ pg_ctl start -D /PostgreSQL/9.6.1/datass测试:主库创建新表及插入数据:postgres=# create table testss(id int ,name varchar(10));CREATE TABLEpostgres=# insert into testss values(1,'dxmy');INSERT 0 1目标端查看:[postgres@pghs ~]$ psqlpsql (9.6.1)Type "help" for help.postgres=# select * from testss; id | name----+------  1 | dxmy(1 row)postgres=模拟备库挂掉:[postgres@pghs ~]$ pg_ctl stop -D /PostgreSQL/9.6.1/datass/waiting for server to shut down.... doneserver stopped在主库插入数据尝试:postgres=# insert into testss values(2,'dxmy');一直卡着,不完成备库起来:postgres=# insert into testss values(2,'dxmy');INSERT 0 1立马成功!
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表