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文件操作 之打开远程文件
//配置php.ini 开启allow_url_fopen选项 //访问的文件有可读或者可写的权限 //$f = fopen('http://www.example.com/a.txt','rb'); ...
- PHP关闭提示、打印配置
打印配置 PHP.exe -i > Info.txt 关闭 PHP 提示的方法 搜索php.ini: error_reporting = E_ALL 改为: error_reporting = ...
- locations in main memory to be referenced by descriptive names rather than by numeric addresses
Computer Science An Overview _J. Glenn Brookshear _11th Edition Chapter 6 Programming Languages As s ...
- SQLServer2008:助您轻松编写T-SQL存储过程(原创)【转】
本文主要介绍 SQLServerExpress2008不用第三方工具调试T-SQL语句,经过本文的介绍,用SQLSERVER2008 Manage studio 编写.调试T-SQL存储过程都将是 ...
- 将真彩色转换成增强色的方法(即RGB32位或RGB24位颜色转换成RGB16位颜色的函数)
今天由于程序需要,需要将真彩色转换成增强色进行颜色匹配,上网搜了一下没搜到相应函数,于是研究了一下RGB16位的增强色,写了这个函数: public static int RGB16(int argb ...
- 读书笔记——《图解TCP/IP》(2/4)
经典摘抄 第三章 数据链路 1.实际的通信媒介之间处理的却是电压的高低.光的闪灭以及电波的强弱等信号. 2.数据链路层的相关技术:MAC寻址.介质共享.非公有网络.分组交换.环路检测.VLAN等 3. ...
- python join
# 对序列进行操作 ' '.join(['hello','good','boy','doiido']) hello:good:boy:doiido # 对字符串进行操作 ':'.join(" ...
- 记录下 QT Linux 静态编译遇到的坑
Qt下静态编译Qt,根据我的经验,如果按照Windows下那种直接拿官方sdk安装之后的文件来编译是行不通的,需要直接下载Qt的source包,目前诺基亚的源码叫做qt-everywhere-open ...
- WPF绑定Model的实例对象
创建一个用户控件 1. behindcode指定this.DataContext=XXViewModel 2. "{Binding DataContext.EditModel.MId,Rel ...
- zepto源码--classRE、maybeAddPx、children、defaultDisplay--学习笔记
1.classRE 对获取className的操作,进行缓存.如果缓存中有,直接读取缓存中的值,如果没有,则先进行缓存的存储,再读取值. 利用前面变量定义的classCache={}进行缓存的操作,如 ...