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 期待 ...
随机推荐
- HK游记 Day2迪斯尼(下)
接下来我们要去看狮子王庆典,绕啊绕啊,终于进场了,说实话我对一大帮人扮演动物歌舞表演不是很感冒,静倒是觉得很好看,印象最深的是狮子王的主题曲,还有大象车,长颈鹿车,狮子王车,静举着手机拍视频. 看完表 ...
- 【微信开发之问题集锦】redirect_uri 参数错误
问题答案:看看网页授权域名是不是以"http://",是则去掉.(如果网页授权域名都没修改,那就去修改吧,要注意域名不要带"http://"."htt ...
- Android轻量缓存框架--ASimpleCache
[转] 大神真面目 稀土掘金,这是一个针对技术开发者的一个应用,你可以在掘金上获取最新最优质的技术干货,不仅仅是Android知识.前端.后端以至于产品和设计都有涉猎,想成为全栈工程师的朋友不要错过! ...
- NSString的常见方法
//1.创建常量字符串. NSString *astring = @"This is a String!"; //2.创建空字符串,给予赋值. NSString *astrin ...
- Ubuntu 12.04+DarwinStreamingSrvr6.0.3 架设流媒体服务器
1.安装Ubuntu 12.04操作系统,网上很多教程.. 2.打开终端,下载darwin源代码DarwinStreamingSrvr6.0.3-Source.tar,补丁patch dss-6.0. ...
- [LeetCode]题解(python):050-Pow(x, n)
题目来源 https://leetcode.com/problems/powx-n/ Implement pow(x, n). 题意分析 Input: x,n Output:pow(x,n) Cond ...
- 【C++】函数指针宏定义
看耗子叔文章学习虚函数表(http://blog.csdn.net/haoel/article/details/1948051)的时候被例子的第一句惊到了 typedef void(*Fun)(voi ...
- NavigationController popToViewController跳转之前任意ViewController方法
NSArray *viewControllers = self.navigationController.viewControllers;A *viewController = [viewContro ...
- ORACLE十进制与十六进制的转换
十进制与十六进制的转换 十进制-->十六进制 select to_char(100,'XX') from dual; 十六进制-->十进制select to_number('7D','XX ...
- iOS: 悬浮的条件筛选框使用二
一.介绍: 在前面已经介绍了一种条件悬浮框,使用的是tableView的Plain分组样式实现的,因为这是tableView本身就具备的功能,分组悬浮效果.这次我来介绍第二种更加简单的方法,采用两个S ...