Postgresql 流复制同步模式
来源:互联网 发布:php 多个图片合成一张 编辑:程序博客网 时间:2024/05/31 05:29
Postgresql 流复制同步模式
这里配基于同步复制的Hot-Standby 就非常容易了,简单的来讲基于第6个教程只需要修改两个地方:
编辑 postgresql.conf 以支持 WAL archiving:
wal_level = archive
archive_mode = on
archive_command = 'cp %p /home/postgres/archive/%f'
max_wal_senders = 1
里增加配置:
synchronous_standby_names = 'mydb_standby1'
以及B. 在“3.配置Warm-standby,并启动”中:
然后编辑recovery.conf里修改primary_conninfo 配置为:
standby_mode = on
restore_command = 'cp /home/postgres/archive/%f %p'
primary_conninfo = 'host=10.211.55.4 port=5432 user=repuser password=123456 application_name=mydb_standby1'
trigger_file = '/home/postgres/trigger/pgsql.trigger.6432'
这个时候我们看主库的报警日志
LOG: shutting down
LOG: database system is shut down
LOG: database system was shut down at 2015-08-15 04:26:43 CST
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
LOG: connection received: host=10.211.55.3 port=23237
LOG: replication connection authorized: user=repuser
LOG: standby "mydb_standby1" is now the synchronous standby with priority 1
LOG: connection received: host=[local]
LOG: connection authorized: user=postgres database=postgres
可以看到备库已经处于了同步模式中
我们后面如何的去修改这种同步,异步的模式呢?
就只需要去修改
synchronous_standby_names = 'mydb_standby1'这个参数
然后在主库重新装在配置 pg_ctl reload
LOG: connection received: host=[local]
LOG: connection authorized: user=postgres database=postgres
LOG: received SIGHUP, reloading configuration files
LOG: parameter "synchronous_standby_names" removed from configuration file, reset to default
然后我们测试下,在备库不能够使用的情况下,主库的状态
可以看到,主库的状态是可以开启的状态
但是我们这个时候如果进行操作,比如创建一个数据库的操作
postgres=# create database test1 with owner kiwi;
这个时候可以看到,这个数据库处于hang住的状态,操作不能够执行
这个就是同步复制的最大好处,能够永远保证主备课数据的一致性
我们cancel掉这步操作,可以看到这样的报错信息
postgres=# create database test1 with owner kiwi;
^CCancel request sent
WARNING: canceling wait for synchronous replication due to user request
DETAIL: The transaction has already committed locally, but might not have been replicated to the standby.
CREATE DATABASE
如果我们这个时候再把备库启动
可以看到虽然我们已经cancel掉了这步的操作,但是我们test1数据库还是创建成功了。
结论:在同步模式下,虽然能够保证备库的数据的不丢失,但是很显然的,存在了备库会影响主库的问题,更多了一层的风险。所以在实际的生产环境中,我们一般不去采用这种同步复制的方式。
这里配基于同步复制的Hot-Standby 就非常容易了,简单的来讲基于第6个教程只需要修改两个地方:
编辑 postgresql.conf 以支持 WAL archiving:
wal_level = archive
archive_mode = on
archive_command = 'cp %p /home/postgres/archive/%f'
max_wal_senders = 1
里增加配置:
synchronous_standby_names = 'mydb_standby1'
以及B. 在“3.配置Warm-standby,并启动”中:
然后编辑recovery.conf里修改primary_conninfo 配置为:
standby_mode = on
restore_command = 'cp /home/postgres/archive/%f %p'
primary_conninfo = 'host=10.211.55.4 port=5432 user=repuser password=123456 application_name=mydb_standby1'
trigger_file = '/home/postgres/trigger/pgsql.trigger.6432'
这个时候我们看主库的报警日志
LOG: shutting down
LOG: database system is shut down
LOG: database system was shut down at 2015-08-15 04:26:43 CST
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
LOG: connection received: host=10.211.55.3 port=23237
LOG: replication connection authorized: user=repuser
LOG: standby "mydb_standby1" is now the synchronous standby with priority 1
LOG: connection received: host=[local]
LOG: connection authorized: user=postgres database=postgres
可以看到备库已经处于了同步模式中
我们后面如何的去修改这种同步,异步的模式呢?
就只需要去修改
synchronous_standby_names = 'mydb_standby1'这个参数
然后在主库重新装在配置 pg_ctl reload
LOG: connection received: host=[local]
LOG: connection authorized: user=postgres database=postgres
LOG: received SIGHUP, reloading configuration files
LOG: parameter "synchronous_standby_names" removed from configuration file, reset to default
然后我们测试下,在备库不能够使用的情况下,主库的状态
可以看到,主库的状态是可以开启的状态
postgres=# \l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+-------------+-------------+----------------------- kiwi | kiwi | UTF8 | en_US.UTF-8 | en_US.UTF-8 | postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres test | kiwi | UTF8 | en_US.UTF-8 | en_US.UTF-8 | (5 rows)
但是我们这个时候如果进行操作,比如创建一个数据库的操作
postgres=# create database test1 with owner kiwi;
这个时候可以看到,这个数据库处于hang住的状态,操作不能够执行
这个就是同步复制的最大好处,能够永远保证主备课数据的一致性
我们cancel掉这步操作,可以看到这样的报错信息
postgres=# create database test1 with owner kiwi;
^CCancel request sent
WARNING: canceling wait for synchronous replication due to user request
DETAIL: The transaction has already committed locally, but might not have been replicated to the standby.
CREATE DATABASE
如果我们这个时候再把备库启动
postgres=# create database test1 with owner kiwi;ERROR: database "test1" already existspostgres=# \l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+-------------+-------------+----------------------- kiwi | kiwi | UTF8 | en_US.UTF-8 | en_US.UTF-8 | postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres test | kiwi | UTF8 | en_US.UTF-8 | en_US.UTF-8 | test1 | kiwi | UTF8 | en_US.UTF-8 | en_US.UTF-8 | (6 rows)
可以看到虽然我们已经cancel掉了这步的操作,但是我们test1数据库还是创建成功了。
结论:在同步模式下,虽然能够保证备库的数据的不丢失,但是很显然的,存在了备库会影响主库的问题,更多了一层的风险。所以在实际的生产环境中,我们一般不去采用这种同步复制的方式。
0 0
- Postgresql 流复制同步模式
- Postgresql 同步流复制
- postgresql同步流复制的Hot Standby
- postgresql 数据库同步复制
- PostgreSQL学习篇16.2 同步流复制的standby数据库
- 半同步复制模式
- postgresql 异步流复制
- postgresql流复制配置
- postgresql流复制
- Postgresql 异步流复制
- Postgresql流复制
- postgresql 流复制切换
- Postgresql主备同步流复制及主备切换、IP漂移
- postgresql异步流复制实现
- 【Postgresql源码分析之一】主备同步复制介绍
- 【Postgresql源码分析之二】同步复制源码分析
- 【Postgresql源码分析之三】同步复制源码分析
- 【Postgresql源码分析之一】主备同步复制介绍
- 算法时间复杂度分析
- Atom设置震撼的编辑效果
- Swift2.1关键字 @noescape介绍
- 基因数据处理3之bwakit安装和使用
- 云计算+大数据+深度学习+人工智能+量子计算=?
- Postgresql 流复制同步模式
- HttpClient使用详解
- c++上机实验
- 实现ListView的弹性效果,下拉隐藏ToolBar(ActionBar),上拉显示ToolBar
- 如何保护 .NET 应用的安全?
- Android属性动画封装之快速构建动画
- 字符串按字典排序
- yii2随笔(五):mysql 防注入 实现 mysql_real_escape_string 功能
- 判断一个字符串是否全为空格的方法