PostgreSQL Cascade Replication
PostgreSQL Cascade Replication
node1:master:10.2.208.10:repclia(user)
node2:upstreamnode:10.2.208.11:replica(user)
node3:downstreamnode:10.2.208.12:replica(user)
[root@node1 data]# uname -av
Linux node1 3.10.0-229.el7.x86_64 #1 SMP Fri Mar 6 11:36:42 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
[root@node2 ~]# uname -av
Linux node2 3.10.0-229.el7.x86_64 #1 SMP Fri Mar 6 11:36:42 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
[root@node3 data]# uname -a
Linux node3 3.10.0-229.el7.x86_64 #1 SMP Fri Mar 6 11:36:42 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
[replica@node1 bin]$ ./psql -h localhost -p 6432 -U replica -d postgres
psql (9.5.1)
Type "help" for help.
postgres=# select version();
version
---------------------------------------------------------------------------------------------------------
PostgreSQL 9.5.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9), 64-bit
(1 row)
[replica@node2 bin]$ ./psql -h localhost -p 6432 -d postgres
psql (9.5.1)
Type "help" for help.
postgres=# select version();
version
---------------------------------------------------------------------------------------------------------
PostgreSQL 9.5.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9), 64-bit
(1 row)
[replica@node3 bin]$ ./psql -h localhost -p 6432 -d postgres -U replica
psql (9.5.1)
Type "help" for help.
postgres=# select version();
version
---------------------------------------------------------------------------------------------------------
PostgreSQL 9.5.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9), 64-bit
(1 row)
1 master:installing,init,start
postgresql.conf
wal_level = hot_standby
fsync = on
synchronous_commit = on
archive_mode = on
archive_command = 'cd .'
max_wal_senders = 10
synchronous_standby_names = 'node2'
hot_standby = on
pg_hba.conf
host all all 0.0.0.0/0 trust
host replication replica 0.0.0.0/0 trust
[replica@node1 bin]$ ./pg_ctl -D ../data/ start
server starting
[replica@node1 bin]$ LOG: database system was shut down at 2016-03-08 11:27:56 CST
LOG: MultiXact member wraparound protections are now enabled
LOG: autovacuum launcher started
LOG: database system is ready to accept connections
[replica@node1 bin]$ ./pg_controldata -D /home/replica/data/
pg_control version number: 942
Catalog version number: 201510051
Database system identifier: 6259518217727406929
Database cluster state: in production
pg_control last modified: Tue 08 Mar 2016 03:20:08 PM CST
Latest checkpoint location: 0/3016740
Prior checkpoint location: 0/3016660
Latest checkpoint's REDO location: 0/3016708
Latest checkpoint's REDO WAL file: 000000010000000000000003
Latest checkpoint's TimeLineID: 1
Latest checkpoint's PrevTimeLineID: 1
Latest checkpoint's full_page_writes: on
Latest checkpoint's NextXID: 0/1834
Latest checkpoint's NextOID: 24576
Latest checkpoint's NextMultiXactId: 1
Latest checkpoint's NextMultiOffset: 0
Latest checkpoint's oldestXID: 1822
Latest checkpoint's oldestXID's DB: 1
Latest checkpoint's oldestActiveXID: 1834
Latest checkpoint's oldestMultiXid: 1
Latest checkpoint's oldestMulti's DB: 1
Latest checkpoint's oldestCommitTsXid:0
Latest checkpoint's newestCommitTsXid:0
Time of latest checkpoint: Tue 08 Mar 2016 03:20:08 PM CST
Fake LSN counter for unlogged rels: 0/1
Minimum recovery ending location: 0/0
Min recovery ending loc's timeline: 0
Backup start location: 0/0
Backup end location: 0/0
End-of-backup record required: no
wal_level setting: hot_standby
wal_log_hints setting: off
max_connections setting: 100
max_worker_processes setting: 8
max_prepared_xacts setting: 0
max_locks_per_xact setting: 64
track_commit_timestamp setting: off
Maximum data alignment: 8
Database block size: 8192
Blocks per segment of large relation: 131072
WAL block size: 8192
Bytes per WAL segment: 16777216
Maximum length of identifiers: 64
Maximum columns in an index: 32
Maximum size of a TOAST chunk: 1996
Size of a large-object chunk: 2048
Date/time type storage: 64-bit integers
Float4 argument passing: by value
Float8 argument passing: by value
Data page checksum version: 0
[replica@node1 bin]$ ./psql -h localhost -p 6432 -U replica -d postgres
psql (9.5.1)
Type "help" for help.
postgres=# select pg_is_in_recovery();
pg_is_in_recovery
-------------------
f
(1 row)
postgres=# \x
Expanded display is on.
postgres=# select * from pg_stat_replication ;
-[ RECORD 1 ]----+------------------------------
pid | 29562
usesysid | 10
usename | replica
application_name | node2
client_addr | 10.2.208.11
client_hostname |
client_port | 44082
backend_start | 2016-03-08 15:17:25.334968+08
backend_xmin |
state | streaming
sent_location | 0/30169A8
write_location | 0/30169A8
flush_location | 0/30169A8
replay_location | 0/30169A8
sync_priority | 1
sync_state | sync
[replica@node1 bin]$ ./psql -h localhost -p 6432
FATAL: database "replica" does not exist
psql: FATAL: database "replica" does not exist
[replica@node1 bin]$ ./psql -h localhost -p 6432 -d postgres
psql (9.5.1)
Type "help" for help.
postgres=# \d
No relations found.
[replica@node1 bin]$ pwd
/home/replica/bin
replica 25816 1 0 11:40 pts/4 00:00:00 /home/replica/bin/postgres -D ../data
replica 25818 25816 0 11:40 ? 00:00:00 postgres: checkpointer process
replica 25819 25816 0 11:40 ? 00:00:00 postgres: writer process
replica 25820 25816 0 11:40 ? 00:00:00 postgres: wal writer process
replica 25821 25816 0 11:40 ? 00:00:00 postgres: autovacuum launcher process
replica 25822 25816 0 11:40 ? 00:00:00 postgres: archiver process last was 000000010000000000000002.00000028.backup
replica 25823 25816 0 11:40 ? 00:00:00 postgres: stats collector process
replica 28345 25816 0 14:06 ? 00:00:00 postgres: wal sender process replica 10.2.208.11(44077) streaming 0/30004C0
replica 28679 25340 0 14:26 pts/4 00:00:00 grep --color=auto postgres
2 upstreamnode,installing,from master do pg_basebackup
postgresql.conf
wal_level = hot_standby
fsync = on
synchronous_commit = on
archive_mode = on
archive_command = 'cd .'
max_wal_senders = 10
synchronous_standby_names = ' '
hot_standby = on
recovery.conf
recovery_target_timeline = 'latest'
standby_mode = on
primary_conninfo = 'host=10.2.208.10 port=6432 user=replica password=replica application_name=node2'
pg_hba.conf
host all all 0.0.0.0/0 trust
host replication replica 0.0.0.0/0 trust
[replica@node2 bin]$ ./pg_basebackup -h 10.2.208.10 -P -Fp -Xs -v -p 6432 -U replica -D /home/replica/data/
transaction log start point: 0/2000028 on timeline 1
pg_basebackup: starting background WAL receiver
22511/22511 kB (100%), 1/1 tablespace
transaction log end point: 0/2000130
pg_basebackup: waiting for background process to finish streaming ...
pg_basebackup: base backup completed
[replica@node2 bin]$ ./pg_ctl -D /home/replica/data/ start
server starting
[replica@node2 bin]$ LOG: database system was interrupted; last known up at 2016-03-08 14:00:06 CST
LOG: entering standby mode
LOG: redo starts at 0/2000028
LOG: consistent recovery state reached at 0/2000130
LOG: database system is ready to accept read only connections
LOG: started streaming WAL from primary at 0/3000000 on timeline 1
[replica@node2 bin]$ ./pg_controldata -D /home/replica/data/
pg_control version number: 942
Catalog version number: 201510051
Database system identifier: 6259518217727406929
Database cluster state: in archive recovery
pg_control last modified: Tue 08 Mar 2016 03:22:22 PM CST
Latest checkpoint location: 0/3016740
Prior checkpoint location: 0/3016318
Latest checkpoint's REDO location: 0/3016708
Latest checkpoint's REDO WAL file: 000000010000000000000003
Latest checkpoint's TimeLineID: 1
Latest checkpoint's PrevTimeLineID: 1
Latest checkpoint's full_page_writes: on
Latest checkpoint's NextXID: 0/1834
Latest checkpoint's NextOID: 24576
Latest checkpoint's NextMultiXactId: 1
Latest checkpoint's NextMultiOffset: 0
Latest checkpoint's oldestXID: 1822
Latest checkpoint's oldestXID's DB: 1
Latest checkpoint's oldestActiveXID: 1834
Latest checkpoint's oldestMultiXid: 1
Latest checkpoint's oldestMulti's DB: 1
Latest checkpoint's oldestCommitTsXid:0
Latest checkpoint's newestCommitTsXid:0
Time of latest checkpoint: Tue 08 Mar 2016 03:20:08 PM CST
Fake LSN counter for unlogged rels: 0/1
Minimum recovery ending location: 0/30167E8
Min recovery ending loc's timeline: 1
Backup start location: 0/0
Backup end location: 0/0
End-of-backup record required: no
wal_level setting: hot_standby
wal_log_hints setting: off
max_connections setting: 100
max_worker_processes setting: 8
max_prepared_xacts setting: 0
max_locks_per_xact setting: 64
track_commit_timestamp setting: off
Maximum data alignment: 8
Database block size: 8192
Blocks per segment of large relation: 131072
WAL block size: 8192
Bytes per WAL segment: 16777216
Maximum length of identifiers: 64
Maximum columns in an index: 32
Maximum size of a TOAST chunk: 1996
Size of a large-object chunk: 2048
Date/time type storage: 64-bit integers
Float4 argument passing: by value
Float8 argument passing: by value
Data page checksum version: 0
[replica@node2 bin]$ ./psql -h localhost -p 6432 -d postgres
psql (9.5.1)
Type "help" for help.
postgres=# select * from pg_is_in_recovery();
pg_is_in_recovery
-------------------
t
(1 row)
postgres=# \x
Expanded display is on.
postgres=# select * from pg_stat_replication ;
-[ RECORD 1 ]----+------------------------------
pid | 8594
usesysid | 10
usename | replica
application_name | walreceiver
client_addr | 10.2.208.12
client_hostname |
client_port | 54798
backend_start | 2016-03-08 15:17:25.291373+08
backend_xmin |
state | streaming
sent_location | 0/30169A8
write_location | 0/30169A8
flush_location | 0/30169A8
replay_location | 0/30169A8
sync_priority | 0
sync_state | async
[replica@node2 bin]$ ./psql -h localhost -p 6432 -d postgres
psql (9.5.1)
Type "help" for help.
postgres=# \d
No relations found.
postgres=# \q
[replica@node2 bin]$ ps -ef|grep postgres
replica 7564 1 0 14:06 pts/2 00:00:00 /home/replica/bin/postgres -D /home/replica/data
replica 7565 7564 0 14:06 ? 00:00:00 postgres: startup process recovering 000000010000000000000003
replica 7566 7564 0 14:06 ? 00:00:00 postgres: checkpointer process
replica 7567 7564 0 14:06 ? 00:00:00 postgres: writer process
replica 7568 7564 0 14:06 ? 00:00:00 postgres: stats collector process
replica 7569 7564 0 14:06 ? 00:00:00 postgres: wal receiver process streaming 0/3000568
replica 7927 7047 0 14:30 pts/2 00:00:00 grep --color=auto postgres
3 downstreamnode:installing,from upstreamnode do pg_basebackup
postgresql.conf
wal_level = hot_standby
fsync = on
synchronous_commit = on
archive_mode = on
archive_command = 'cd .'
max_wal_senders = 10
synchronous_standby_names = ' '
hot_standby = on
recovery.conf
recovery_target_timeline = 'latest'
standby_mode = on
primary_conninfo = 'host=10.2.208.11 port=6432 user=replica password=replica'
pg_hba.conf
host all all 0.0.0.0/0 trust
host replication replica 0.0.0.0/0 trust
[replica@node3 bin]$ ./pg_basebackup -h 10.2.208.11 -P -Fp -Xs -v -p 6432 -U replica -D /home/replica/data/
transaction log start point: 0/3000220 on timeline 1
pg_basebackup: starting background WAL receiver
22512/22512 kB (100%), 1/1 tablespace
transaction log end point: 0/3000300
pg_basebackup: waiting for background process to finish streaming ...
pg_basebackup: base backup completed
[replica@node3 bin]$ ./pg_ctl -D ../data/ start
server starting
[replica@node3 bin]$ LOG: database system was interrupted while in recovery at log time 2016-03-08 14:15:07 CST
HINT: If this has occurred more than once some data might be corrupted and you might need to choose an earlier recovery target.
LOG: entering standby mode
LOG: redo starts at 0/3000220
LOG: consistent recovery state reached at 0/3000300
LOG: invalid record length at 0/3000300
LOG: database system is ready to accept read only connections
LOG: started streaming WAL from primary at 0/3000000 on timeline 1
[replica@node3 bin]$ ./pg_controldata -D /home/replica/data/
pg_control version number: 942
Catalog version number: 201510051
Database system identifier: 6259518217727406929
Database cluster state: in archive recovery
pg_control last modified: Tue 08 Mar 2016 03:27:30 PM CST
Latest checkpoint location: 0/3016820
Prior checkpoint location: 0/3016740
Latest checkpoint's REDO location: 0/30167E8
Latest checkpoint's REDO WAL file: 000000010000000000000003
Latest checkpoint's TimeLineID: 1
Latest checkpoint's PrevTimeLineID: 1
Latest checkpoint's full_page_writes: on
Latest checkpoint's NextXID: 0/1834
Latest checkpoint's NextOID: 24576
Latest checkpoint's NextMultiXactId: 1
Latest checkpoint's NextMultiOffset: 0
Latest checkpoint's oldestXID: 1822
Latest checkpoint's oldestXID's DB: 1
Latest checkpoint's oldestActiveXID: 1834
Latest checkpoint's oldestMultiXid: 1
Latest checkpoint's oldestMulti's DB: 1
Latest checkpoint's oldestCommitTsXid:0
Latest checkpoint's newestCommitTsXid:0
Time of latest checkpoint: Tue 08 Mar 2016 03:25:08 PM CST
Fake LSN counter for unlogged rels: 0/1
Minimum recovery ending location: 0/3016708
Min recovery ending loc's timeline: 1
Backup start location: 0/0
Backup end location: 0/0
End-of-backup record required: no
wal_level setting: hot_standby
wal_log_hints setting: off
max_connections setting: 100
max_worker_processes setting: 8
max_prepared_xacts setting: 0
max_locks_per_xact setting: 64
track_commit_timestamp setting: off
Maximum data alignment: 8
Database block size: 8192
Blocks per segment of large relation: 131072
WAL block size: 8192
Bytes per WAL segment: 16777216
Maximum length of identifiers: 64
Maximum columns in an index: 32
Maximum size of a TOAST chunk: 1996
Size of a large-object chunk: 2048
Date/time type storage: 64-bit integers
Float4 argument passing: by value
Float8 argument passing: by value
Data page checksum version: 0
[replica@node3 bin]$ ./psql -h localhost -p 6432 -d postgres -U replica
psql (9.5.1)
Type "help" for help.
postgres=# select pg_is_in_recovery();
pg_is_in_recovery
-------------------
t
(1 row)
[replica@node3 bin]$ ./psql -h localhost -p 6432 -d postgres -U replica
psql (9.5.1)
Type "help" for help.
postgres=# select * from pg_stat_replication ;
pid | usesysid | usename | application_name | client_addr | client_hostname | client_port | backend_start | backend_xmin | state | sent_locati
on | write_location | flush_location | replay_location | sync_priority | sync_state
-----+----------+---------+------------------+-------------+-----------------+-------------+---------------+--------------+-------+------------
---+----------------+----------------+-----------------+---------------+------------
(0 rows)
[replica@node3 bin]$ ./psql -h localhost -p 6432 -d postgres -U replica
psql (9.5.1)
Type "help" for help.
postgres=# \d
No relations found.
在master上创建表并插入数据
[replica@node1 bin]$ ./psql -h localhost -p 6432 -d postgres -U replica
psql (9.5.1)
Type "help" for help.
postgres=# create table test_tb(id int);
CREATE TABLE
postgres=# insert into test_tb values (1),(2),(3),(4),(5);
INSERT 0 5
postgres=# select * from test_tb ;
id
----
1
2
3
4
5
(5 rows)
upstreamnode
[replica@node2 bin]$ ./psql -h localhost -p 6432 -d postgres
psql (9.5.1)
Type "help" for help.
postgres=# \d
List of relations
Schema | Name | Type | Owner
--------+---------+-------+---------
public | test_tb | table | replica
(1 row)
postgres=# select * from test_tb ;
id
----
1
2
3
4
5
(5 rows)
downstreamnode
[replica@node3 bin]$ ./psql -h localhost -p 6432 -d postgres -U replica
psql (9.5.1)
Type "help" for help.
postgres=# \d
List of relations
Schema | Name | Type | Owner
--------+---------+-------+---------
public | test_tb | table | replica
(1 row)
postgres=# select * from test_tb ;
id
----
1
2
3
4
5
(5 rows)
PostgreSQL Cascade Replication的更多相关文章
- 配置PostgreSQL Streaming Replication集群
运行环境: Primary: 192.168.0.11 Standby: 192.168.0.21, 192.168.0.22 OS: CentOS 6.2 PostgreSQL: 9.1.2 版本以 ...
- PostgreSQL Streaming Replication的FATAL ERROR
磨砺技术珠矶,践行数据之道,追求卓越价值回到上一级页面: PostgreSQL集群方案相关索引页 回到顶级页面:PostgreSQL索引页[作者 高健@博客园 luckyjackgao@gm ...
- postgresql Streaming Replication监控与注意事项
一监控Streaming Replication集群 1 pg_stat_replication视图(主库端执行) pid Wal sender process的进程ID usesysid 执行流复制 ...
- 14 - How to check replication status
The people using PostgreSQL and the Streaming Replication feature seem to ask many of the same quest ...
- PostgreSQL Q&A: Building an Enterprise-Grade PostgreSQL Setup Using Open Source Tools
转自:https://www.percona.com/blog/2018/10/19/postgresql-building-enterprise-grade-setup-with-open-sour ...
- PostgreSQL逻辑复制之pglogical篇
PostgreSQL逻辑复制之slony篇 一.pglogical介绍 pglogical 是 PostgreSQL 的拓展模块, 为 PostgreSQL 数据库提供了逻辑流复制发布和订阅的功能. ...
- PostgreSQL 恢复大法 - 恢复部分数据库、跳过坏块、修复无法启动的数据库
转载自:https://yq.aliyun.com/articles/582880 背景 一个较大的数据库,如何只恢复一部分数据(例如只恢复某个DB). 如果访问有坏块的表. 如何从无法启动的数据库中 ...
- pg 资料大全1
https://github.com/ty4z2008/Qix/blob/master/pg.md?from=timeline&isappinstalled=0 PostgreSQL(数据库) ...
- DBLog: A Generic Change-Data-Capture Framework
转自:https://medium.com/netflix-techblog/dblog-a-generic-change-data-capture-framework-69351fb9099b 期待 ...
随机推荐
- 【php学习】数组操作
1.json字符串和数组之间的转换 json_decode($jsonStr) json字符串解码为php变量,若第二个参数默认为false,返回一个对象:若第二个参数设置true,则返回一 ...
- ROSE User Case View
用例视图(User Case View) 在面向对象的分析过程中,此视图应该是需求分析的过程中采用,主要包括如下过程 01涉众分析--->02业务分析--->03概念分析--->04 ...
- ngios
一.Nagios简介 Nagios是一款开源的电脑系统和网络监视工具,能有效监控Windows.Linux和Unix的主机状态,交换机路由器等网络设置,打印机等.在系统或服务状态异常时发出邮件或短信报 ...
- MySQL- 锁(1)
锁是计算机协调多个进程或线程并发访问某一资源的机制.在数据库中,除传统的计算资源(如CPU.RAM.I/O等)的争用以外,数据也是一种供许多用户共享的资源.如何保证数据并发访问的一致性.有效性是所有数 ...
- Android源码剖析之Framework层升级版(窗口、系统启动)
本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 看本篇文章之前,建议先查看: Android源码剖析之Framework层基础版 前面讲了frame ...
- Google物联网操作系统协同框架Weave深度解析
1. Google Weave框架 在2015年的Google I/O大会上,负责Android业务的桑达.皮查伊(SundarPichai)宣布了Google最新的物联网战略.这包括一个 ...
- Delphi xe7 FireMonkey / Mobile (Android, iOS)生成 QR Code完整实例
这个实例在windows.OS X.IOS和Android等平台运行正常.本文参考这个网站提供的方法:http://zarko-gajic.iz.hr/firemonkey-mobile-androi ...
- 利用VS编译libiconv库
参考文章:http://blog.csdn.net/ghevinn/article/details/9834119 关于中文字符编码问题,这篇文章里面讲的很详细-->http://www.tui ...
- 在sublime中使用less
高亮显示: 可以在Less文件中显示语法高亮,这样看起来会更舒服一些. 按下Ctrl+Shift+P调出命令面板:输入install调出Install Package选项并回车:输入less,选中并安 ...
- DPM总结
DPM:Deformable Parts Model(来自http://www.cs.berkeley.edu/~rbg/latent/index.html) 目标检测算法 先计算梯度方向直方图,在用 ...