摘要: PostgreSQL同步复制搭建

一、初始化master节点

1. 安装PostgreSQL
2. 初始化db
initdb -D /data/pg940_data

二、配置master节点

1. 修改postgresql.conf
$ vim /data/pg940_data/postgresql.conf
wal_level = hot_standby
fsync = on
synchronous_commit = on #同步复制必须设置为on
wal_sync_method = fdatasync
max_wal_senders = 4 #配置的是两个slave节点,最好设置大一点,方便以后添加slave节点,pg_basebackup使用stream方式需要占用2个槽
wal_keep_segments = 100
2. 修改白名单
$ vim /data/pg940_data/pg_hba.conf
host all all 172.17.0.0/16 md5
host replication all 172.17.0.0/16 md5
3. 启动master节点
$ pg_ctl -D /data/pg940_data start

三、制作slave节点

1. 获取master节点的基础备份
$ sudo mkdir -p /data/pg940_data
$ sudo chown -R postgres:postgres /data/pg940_data
$ pg_basebackup -X s -h 172.17.5.45 -U postgres -D /data/pg940_data
2. 配置postgresql.conf
hot_standby = on
max_standby_archive_delay = 30s
max_standby_streaming_delay = 30s
3. 配置recovery.conf
standby_mode = 'on'
primary_conninfo = 'host=172.17.5.45 port=5432 user=postgres password=xxxxxx application_name=node2'
restore_command = ''
archive_cleanup_command = ''
4. 启动slave节点
$ pg_ctl -D /data/pg940_data start
$ psql -U postgres
postgres=# select * from pg_stat_replication ;
pid | usesysid | usename | application_name | client_addr | client_hostname | client_port | backend_start | backend_xmin | state | sent_location | write_location | fl
ush_location | replay_location | sync_priority | sync_state
-------+----------+----------+------------------+-------------+-----------------+-------------+-------------------------------+--------------+-----------+---------------+----------------+---
-------------+-----------------+---------------+------------
12262 | 10 | postgres | node3 | 172.17.5.47 | | 48691 | 2015-09-06 14:44:52.674976+08 | 400592 | streaming | 1/74000210 | 1/74000210 | 1/
74000210 | 1/74000210 | 0 | async
12263 | 10 | postgres | node2 | 172.17.5.46 | | 35271 | 2015-09-06 14:44:52.677004+08 | 400592 | streaming | 1/74000210 | 1/74000210 | 1/
74000210 | 1/74000210 | 0 | async
(2 rows)

可以看出两个节点现在都还是异步的

四、修改为同步复制

$ vim /data/pg940_data/postgresql.conf
synchronous_standby_names = 'node2, node3' # reload配置就行,不需要重启
$ psql -U postgres
psql (9.4.4)
Type "help" for help.
postgres=# show synchronous_standby_names;
synchronous_standby_names
--------------------------- (1 row)
postgres=# select pg_reload_conf();
pg_reload_conf
----------------
t
(1 row)
postgres=# show synchronous_standby_names;
synchronous_standby_names
---------------------------
node2, node3
(1 row)
postgres=# select * from pg_stat_replication ;
pid | usesysid | usename | application_name | client_addr | client_hostname | client_port | backend_start | backend_xmin | state | sent_location | write_location | fl
ush_location | replay_location | sync_priority | sync_state
-------+----------+----------+------------------+-------------+-----------------+-------------+-------------------------------+--------------+-----------+---------------+----------------+---
-------------+-----------------+---------------+------------
12262 | 10 | postgres | node3 | 172.17.5.47 | | 48691 | 2015-09-06 14:44:52.674976+08 | 400592 | streaming | 1/740002E8 | 1/740002E8 | 1/
740002E8 | 1/740002E8 | 2 | potential
12263 | 10 | postgres | node2 | 172.17.5.46 | | 35271 | 2015-09-06 14:44:52.677004+08 | 400592 | streaming | 1/740002E8 | 1/740002E8 | 1/
740002E8 | 1/740002E8 | 1 | sync
(2 rows)

可以看出现在node2是同步复制的,node3是备用同步复制节点

https://my.oschina.net/aven92/blog/501721

PostgreSQL同步复制搭建的更多相关文章

  1. MySQL半同步复制搭建

    默认情况下,MySQL 5.5/5.6/5.7和MariaDB 10.0/10.1的复制是异步的,异步复制可以提供最佳性能,主库把binlog日志发送给从库,这一动作就结束了,并不会验证从库是否接收完 ...

  2. PostgreSQL 同步复制(1master+2standby)

    OS: Red Hat Enterprise Linux Server release 6.5 (Santiago) PostgreSQL: postgresql-9.4.5.tar.bz2 mast ...

  3. PostgreSQL单机、同步复制、异步复制性能测试对比

    测试环境: •测试机:PC •内存:8GB •CPU:Intel(R) Core(TM) i5-3450 3.10GHz •硬盘:HDD •数据量:20GB •测试工具:pgbench •Postgr ...

  4. 1018关于MySQL复制搭建[异步复制和半同步复制]

    转自:http://www.cnblogs.com/ivictor/p/5735580.html 搭建MySQL数据库的主从架构,还是蛮简单的.重要的几个命令整理一下. 主从服务器上: SHOW VA ...

  5. PostgreSQL Replication之第五章 设置同步复制(1)

    到目前为止,我们已经处理了基于文件的复制(或日志传送)和简单的基于流复制的设置.在两种情况中,在master上事务被提交之后,数据被提交,由slave接收.在master提交和slave实际上完全地接 ...

  6. MySQL半同步复制

    从MySQL5.5开始,MySQL以插件的形式支持半同步复制.如何理解半同步呢?首先我们来看看异步,全同步的概念 异步复制(Asynchronous replication) MySQL默认的复制即是 ...

  7. 安装MySQL半同步复制

    一.简介 从MySQL5.5开始,MySQL以插件的形式支持半同步复制.如何理解半同步呢?首先我们来看看异步,全同步的概念 异步复制(Asynchronous replication) MySQL默认 ...

  8. MySQL-半同步复制原理实践

    参考文档: http://mysql.taobao.org/monthly/2017/04/01/ 阿里内核月报半同步复制的数据一致性 https://www.cnblogs.com/ivictor/ ...

  9. PostgreSQL异步主从流复制搭建

    1 总体规划   Master库 Slave库 操作系统 CentOS Linux release 7.5.1804 CentOS Linux release 7.5.1804 处理器 1 1 内存 ...

随机推荐

  1. Jquery的优势

    (1)轻量级.jQuery非常轻巧,采用Dean Edwards的Packer(http://dean.edwards.name/packer/)压缩后,只有不到30KB的大小,如果服务器端启用gzi ...

  2. 流式布局&固定宽度&响应式&rem

    我们现在在切页面布局的使用常用的单位是px,这是一个绝对单位,web app的屏幕适配有很多中做法,例如:流式布局.限死宽度,还有就是通过响应式来做,但是这些方案都不是最佳的解决方法. 1.流式布局: ...

  3. CSS3初学篇章_4(边框样式/段落样式)

    边框样式 1.边框线语法:border-style : none | hidden | dotted | dashed | solid | double | groove | ridge | inse ...

  4. Rocky4.2下安装金仓v7数据库(KingbaseES)

    1.准备操作系统 1.1 系统登录界面 1.2 操作系统版本信息 jdbh:~ # uname -ra Linux jdbh -x86_64 # SMP Fri Dec :: CST x86_64 G ...

  5. JavaScript入门篇 第一天

    使用<script>标签在HTML网页中插入JavaScript代码.注意, <script>标签要成对出现,并把JavaScript代码写在<script>< ...

  6. Emgu 决策树

    MCvDTreeParams cvFolds //If this parameter is >1, the tree is pruned using cv_folds-fold cross va ...

  7. String-自定义功能

    <script> /* *发现js中的String对象有限,想要对字符串操作的其他功能. *比如:去除字符串两端的空格.这时只能自.定义 */ //去除字符串两端的空格 function ...

  8. html5:地理信息 LBS基于地理的服务和百度地图API的使用

    地理位置请求 单次定位请求getCurrentPosition(请求成功函数,请求失败函数,数据收集方式) 多次定位请求watchPosition(请求成功函数,请求失败函数,数据收集方式) 关闭更新 ...

  9. [IT新应用]如何用好搜索引擎学习英语

    用谷歌可以学习英语,用必应也可以的. 输入如下地址:global.bing.com,如果是中文界面,就单击顶部右侧“Switch to Bing in English”. 这个界面有很多英文原版的时事 ...

  10. window.self ->window.top->window.parent

    在应用有frameset或者iframe的页面时,parent是父窗口,top是最顶级父窗口(有的窗口中套了好几层frameset或者iframe),self是当前窗口, opener是用open方法 ...