pglogical 之一 setup

os: centos 7.4
db: postgresql 11.7
pglogical: 2.3.1

pglogical is a logical replication system implemented entirely as a PostgreSQL extension.
Fully integrated, it requires no triggers or external programs.
This alternative to physical replication is a highly efficient method of replicating data using a publish/subscribe model for selective replication.

192.168.56.111  pg1
192.168.56.112  pg2
192.168.56.113  pg3

版本

# cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core) 
# 
# 
# yum list installed |grep -i postgresql
postgresql11.x86_64                11.7-1PGDG.rhel7                    @pgdg11  
postgresql11-contrib.x86_64        11.7-1PGDG.rhel7                    @pgdg11  
postgresql11-debuginfo.x86_64      11.5-1PGDG.rhel7                    @pgdg11  
postgresql11-devel.x86_64          11.7-1PGDG.rhel7                    @pgdg11  
postgresql11-docs.x86_64           11.7-1PGDG.rhel7                    @pgdg11  
postgresql11-libs.x86_64           11.7-1PGDG.rhel7                    @pgdg11  
postgresql11-llvmjit.x86_64        11.7-1PGDG.rhel7                    @pgdg11  
postgresql11-odbc.x86_64           12.01.0000-1PGDG.rhel7              @pgdg11  
postgresql11-plperl.x86_64         11.7-1PGDG.rhel7                    @pgdg11  
postgresql11-plpython.x86_64       11.7-1PGDG.rhel7                    @pgdg11  
postgresql11-plpython3.x86_64      11.7-1PGDG.rhel7                    @pgdg11  
postgresql11-pltcl.x86_64          11.7-1PGDG.rhel7                    @pgdg11  
postgresql11-server.x86_64         11.7-1PGDG.rhel7                    @pgdg11  
postgresql11-tcl.x86_64            2.4.0-2.rhel7.1                     @pgdg11  
postgresql11-test.x86_64           11.7-1PGDG.rhel7                    @pgdg11

# su - postgres
Last login: Wed Jan 15 18:34:12 CST 2020 on pts/0
$
$
$ psql -c "select version();"
                                                 version                                                 
---------------------------------------------------------------------------------------------------------
 PostgreSQL 11.7 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39), 64-bit
(1 row)

安裝

三個節點都安裝

# vi /etc/hosts

192.168.56.111  pg1
192.168.56.112  pg2
192.168.56.113  pg3

# yum list all|grep -i pglogical
pglogical_11.x86_64                        2.3.1-1.rhel7          pgdg11

# yum install pglogical_11;

# vi /var/lib/pgsql/11/data/postgresql.conf

wal_level = 'logical'
max_worker_processes = 20   # one per database needed on provider node
                            # one per node needed on subscriber node
max_replication_slots = 20  # one per node needed on provider node
max_wal_senders = 20        # one per node needed on provider node
shared_preload_libraries = 'pglogical'
track_commit_timestamp = on # needed for last/first update wins conflict resolution
                            # property available in PostgreSQL 9.5+
# systemctl restart postgresql-11.service

查看啓動日誌

2020-05-09 14:46:17.340 CST,,,3460,,5eb62b33.d84,3,,2020-05-09 12:01:55 CST,,0,LOG,00000,"received fast shutdown request",,,,,,,,,""
2020-05-09 14:46:17.415 CST,,,3460,,5eb62b33.d84,4,,2020-05-09 12:01:55 CST,,0,LOG,00000,"aborting any active transactions",,,,,,,,,""
2020-05-09 14:46:17.418 CST,,,3460,,5eb62b33.d84,5,,2020-05-09 12:01:55 CST,,0,LOG,00000,"background worker ""logical replication launcher"" (PID 3469) exited with exit code 1",,,,,,,,,""
2020-05-09 14:46:17.418 CST,,,3464,,5eb62b33.d88,3,,2020-05-09 12:01:55 CST,,0,LOG,00000,"shutting down",,,,,,,,,""
2020-05-09 14:46:17.421 CST,,,3464,,5eb62b33.d88,4,,2020-05-09 12:01:55 CST,,0,LOG,00000,"checkpoint starting: shutdown immediate",,,,,,,,,""
2020-05-09 14:46:17.432 CST,,,3464,,5eb62b33.d88,5,,2020-05-09 12:01:55 CST,,0,LOG,00000,"checkpoint complete: wrote 0 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.000 s, sync=0.000 s, total=0.013 s; sync files=0, longest=0.000 s, average=0.000 s; distance=0 kB, estimate=0 kB",,,,,,,,,""
2020-05-09 14:46:17.446 CST,,,3460,,5eb62b33.d84,6,,2020-05-09 12:01:55 CST,,0,LOG,00000,"database system is shut down",,,,,,,,,""
2020-05-09 14:46:17.645 CST,,,13430,,5eb651b9.3476,1,,2020-05-09 14:46:17 CST,,0,LOG,00000,"ending log output to stderr",,"Future log output will go to log destination ""csvlog"".",,,,,,,""
2020-05-09 14:46:17.655 CST,,,13432,,5eb651b9.3478,1,,2020-05-09 14:46:17 CST,,0,LOG,00000,"database system was shut down at 2020-05-09 14:46:17 CST",,,,,,,,,""
2020-05-09 14:46:17.674 CST,,,13430,,5eb651b9.3476,2,,2020-05-09 14:46:17 CST,,0,LOG,00000,"database system is ready to accept connections",,,,,,,,,""

2020-05-09 14:46:17.674 CST,,,13438,,5eb651b9.347e,1,,2020-05-09 14:46:17 CST,,0,LOG,00000,"starting pglogical supervisor",,,,,,,,,"pglogical supervisor"
2020-05-09 14:46:17.900 CST,,"postgres",13440,,5eb651b9.3480,1,"",2020-05-09 14:46:17 CST,4/0,0,LOG,00000,"manager worker [13440] at slot 0 generation 1 detaching cleanly",,,,,,,,,"pglogical manager 13881"
2020-05-09 14:46:18.163 CST,,"template1",13444,,5eb651ba.3484,1,"",2020-05-09 14:46:18 CST,4/0,0,LOG,00000,"manager worker [13444] at slot 0 generation 2 detaching cleanly",,,,,,,,,"pglogical manager 1"
2020-05-09 14:46:18.313 CST,,"pgbenchdb",13445,,5eb651ba.3485,1,"",2020-05-09 14:46:18 CST,4/0,0,LOG,00000,"manager worker [13445] at slot 0 generation 3 detaching cleanly",,,,,,,,,"pglogical manager 41068"
2020-05-09 14:46:18.491 CST,,"yewudb",13446,,5eb651ba.3486,1,"",2020-05-09 14:46:18 CST,4/0,0,LOG,00000,"manager worker [13446] at slot 0 generation 4 detaching cleanly",,,,,,,,,"pglogical manager 50433"
2020-05-09 14:46:18.596 CST,,"pgbench_plprofiler",13447,,5eb651ba.3487,1,"",2020-05-09 14:46:18 CST,4/0,0,LOG,00000,"manager worker [13447] at slot 0 generation 5 detaching cleanly",,,,,,,,,"pglogical manager 57828"

可以看到,每個數據庫啓動了一個 manager worker 進程

參考:

https://www.2ndquadrant.com/en/resources/pglogical/
https://www.2ndquadrant.com/en/resources/pglogical/pglogical-docs/
https://www.2ndquadrant.com/en/resources/pglogical/pglogical-installation-instructions/

https://github.com/2ndQuadrant/pglogical

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章