使用Etcd和Patroni能夠構建高可用PostgreSQL集羣.node
Etcd用於Patroni節點之間共享信息.python
Patroni監控本地的PostgreSQL狀態。若是主庫(Primary)故障,Patroni把一個從庫(Standby)拉起來,做爲新的主(Primary)數據庫. 若是一個故障PostgreSQL被搶救過來了,可以從新自動或手動加入集羣。算法
Etcd按照Raft算法和協議開發的,是一個強一致性的、分佈式的key-value數據庫。它爲分佈式系統提供了可靠的數據存儲訪問機制。sql
只有一個etcd節點被選作Leader, 其它的etcd節點做爲Follower.數據庫
Etcd裏的數據以key標識, 例如可使用以下數據bootstrap
key = /service/postgresql/leader value = postgresql1
來表示一個PostgreSQL集羣中的主庫是'postgresql1'.vim
figure1: an etcd cluster including three etcd nodes =================================================== |---------------| |-------------| |etcd1<follower>| <----------+-----------> |etcd2<leader>| |---------------| | |-------------| | | | |-------V-------| |etcd3<follower>| |---------------|
下面的圖中(figure2), 使用三個主機(host1,host2,host3) 構建一個PostgreSQL集羣。 每個主機上都安裝部署Etcd, Patroni 和 PostgreSQL。api
figure2: a PostgreSQL cluster with 3 hosts, each host having etcd, Partoni and PostgreSQL ===================================================================================== ......................................................................... . <host1> . . |------------| |-------------| |-------------| . +--<-------->| etcd1 |<------->| patroni1 +---------->| postgresql1 | . | . |------------| |-------------| |-------------| . | . . | ......................................................................... | | | | ......................................................................... | . <host2> . | . |------------| |-------------| |-------------| . +-<--------->| etcd2 |<------->| patroni2 +---------->| postgresql2 | . | . |------------| |-------------| |-------------| . | . . | ......................................................................... | | | | .......................................................................... | . <host3> . | . |------------| |-------------| |-------------| . +--<-------->| etcd3 |<------->| patroni3 +---------->| postgresql3 | . . |------------| |-------------| |-------------| . . . ..........................................................................
Etcd一、etcd二、 etcd3做爲分佈式的Key-Value數據庫,被partroni一、 patroni二、 patroni3讀/寫,用於共享/傳遞信息。每個 Patroni都能讀/寫etcd中的數據.app
每個 Patroni實例監控/控制本地的PostgreSQL,把本地本地PostgreSQL信息/狀態寫入etcd 。curl
一個Patroni實例可以經過讀取etcd獲取外地PostgreSQL的信息/狀態.
Patroni判斷本地PostgreSQL是否能夠做爲Primary庫。若是能夠,Paroni試圖選舉本地PostgreSQL做爲Primary(Leader) ,選舉方式是:把etcd中的某個key(e.g. /service/postgresql/leader) 更新成爲本地PostgreSQL的名字(e.g. postgresql1)。
若是多個Paroni同時更改同一個key,只有一個能改爲功,而後成爲Primary(Leader)。
NO. | IP | HOSTNAME -----+-----------------+--------------- 1 | 192.168.56.10 | host1 2 | 192.168.56.11 | host2 3 | 192.168.56.12 | host3
[rudi@host1 ~]$ more /etc/hosts 192.168.56.10 host1 192.168.56.11 host2 192.168.56.12 host3
yum -y install etcd libyaml
yum -y install flex bison readline-devel zlib-devel wget https://ftp.postgresql.org/pub/source/v11.3/postgresql-11.3.tar.gz tar zxvf postgresql-11.3.tar.gz cd postgresql-11.3/ ./configure make su make install
yum install libffi-devel openssl-devel wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz tar zxvf Python-3.7.4.tgz cd Python-3.7.4/ ./configure make
su make install python3 -m pip install --upgrade pip python3 -m pip install psycopg2_binary python3 -m pip install patroni[etcd]
cd ~ mkdir ~/scripts mkdir ~/pgdata
cd ~/scripts vim etcd1.sh
etcd --name etcdnode1 --initial-advertise-peer-urls http://192.168.56.10:2380 \ --listen-peer-urls http://192.168.56.10:2380 \ --listen-client-urls http://192.168.56.10:2379,http://127.0.0.1:2379 \ --advertise-client-urls http://192.168.56.10:2379 \ --initial-cluster-token etcd-cluster-1 \ --initial-cluster etcdnode1=http://192.168.56.10:2380,etcdnode2=http://192.168.56.11:2380,etcdnode3=http://192.168.56.12:2380 \ --initial-cluster-state new
cd ~/scripts vim etcd2.sh
etcd --name etcdnode2 --initial-advertise-peer-urls http://192.168.56.11:2380 \ --listen-peer-urls http://192.168.56.11:2380 \ --listen-client-urls http://192.168.56.11:2379,http://127.0.0.1:2379 \ --advertise-client-urls http://192.168.56.11:2379 \ --initial-cluster-token etcd-cluster-1 \ --initial-cluster etcdnode1=http://192.168.56.10:2380,etcdnode2=http://192.168.56.11:2380,etcdnode3=http://192.168.56.12:2380 \ --initial-cluster-state new
cd ~/scripts vim etcd3.sh
etcd --name etcdnode3 --initial-advertise-peer-urls http://192.168.56.12:2380 \ --listen-peer-urls http://192.168.56.12:2380 \ --listen-client-urls http://192.168.56.12:2379,http://127.0.0.1:2379 \ --advertise-client-urls http://192.168.56.12:2379 \ --initial-cluster-token etcd-cluster-1 \ --initial-cluster etcdnode1=http://192.168.56.10:2380,etcdnode2=http://192.168.56.11:2380,etcdnode3=http://192.168.56.12:2380 \ --initial-cluster-state new
cd ~/scripts vim postgresql1.yml
scope: postgresql namespace: /service/ name: postgresql1 restapi: listen: 192.168.56.10:8008 connect_address: 192.168.56.10:8008 etcd: host: 192.168.56.10:2379 bootstrap: dcs: ttl: 30 loop_wait: 10 retry_timeout: 10 maximum_lag_on_failover: 1048576 postgresql: use_pg_rewind: true initdb: - encoding: UTF8 - data-checksums pg_hba: - host replication replicator 127.0.0.1/32 md5 - host replication replicator 192.168.56.10/0 md5 - host replication replicator 192.168.56.11/0 md5 - host replication replicator 192.168.56.12/0 md5 - host all all 0.0.0.0/0 md5 users: admin: password: admin options: - createrole - createdb postgresql: listen: 192.168.56.10:15432 connect_address: 192.168.56.10:15432 bin_dir: /usr/local/pgsql/bin data_dir: /home/rudi/pgdata pgpass: /tmp/pgpass1 authentication: replication: username: replicator password: rep-pass superuser: username: postgres password: secretpassword parameters: unix_socket_directories: '.' synchronous_commit: "on" synchronous_standby_names: "*" tags: nofailover: false noloadbalance: false clonefrom: false nosync: false
cd ~/scripts vim postgresql2.yml
scope: postgresql namespace: /service/ name: postgresql2 restapi: listen: 192.168.56.11:8008 connect_address: 192.168.56.11:8008 etcd: host: 192.168.56.11:2379 bootstrap: dcs: ttl: 30 loop_wait: 10 retry_timeout: 10 maximum_lag_on_failover: 1048576 postgresql: use_pg_rewind: true initdb: - encoding: UTF8 - data-checksums pg_hba: - host replication replicator 127.0.0.1/32 md5 - host replication replicator 192.168.56.10/0 md5 - host replication replicator 192.168.56.11/0 md5 - host replication replicator 192.168.56.12/0 md5 - host all all 0.0.0.0/0 md5 users: admin: password: admin options: - createrole - createdb postgresql: listen: 192.168.56.11:15432 connect_address: 192.168.56.11:15432 bin_dir: /usr/local/pgsql/bin data_dir: /home/rudi/pgdata pgpass: /tmp/pgpass1 authentication: replication: username: replicator password: rep-pass superuser: username: postgres password: secretpassword parameters: unix_socket_directories: '.' synchronous_commit: "on" synchronous_standby_names: "*" tags: nofailover: false noloadbalance: false clonefrom: false nosync: false
cd ~/scripts vim postgresql3.yml
scope: postgresql namespace: /service/ name: postgresql3 restapi: listen: 192.168.56.12:8008 connect_address: 192.168.56.12:8008 etcd: host: 192.168.56.12:2379 bootstrap: dcs: ttl: 30 loop_wait: 10 retry_timeout: 10 maximum_lag_on_failover: 1048576 postgresql: use_pg_rewind: true initdb: - encoding: UTF8 - data-checksums pg_hba: - host replication replicator 127.0.0.1/32 md5 - host replication replicator 192.168.56.10/0 md5 - host replication replicator 192.168.56.11/0 md5 - host replication replicator 192.168.56.12/0 md5 - host all all 0.0.0.0/0 md5 users: admin: password: admin options: - createrole - createdb postgresql: listen: 192.168.56.12:15432 connect_address: 192.168.56.12:15432 bin_dir: /usr/local/pgsql/bin data_dir: /home/rudi/pgdata pgpass: /tmp/pgpass1 authentication: replication: username: replicator password: rep-pass superuser: username: postgres password: secretpassword parameters: unix_socket_directories: '.' synchronous_commit: "on" synchronous_standby_names: "*" tags: nofailover: false noloadbalance: false clonefrom: false nosync: false
systemctl stop firewalld systemctl disable firewalld
host1:
cd ~ source ./scripts/etcd1.sh
host2:
cd ~ source ./scripts/etcd2.sh
host3:
cd ~ source ./scripts/etcd3.sh
查看etcd狀態信息:
[rudi@host1 ~]$ curl -L http://host2:2379/version {"etcdserver":"3.3.11","etcdcluster":"3.3.0"} [rudi@host1 ~]$ curl -L http://host3:2379/version {"etcdserver":"3.3.11","etcdcluster":"3.3.0"} [rudi@host1 ~]$ curl -L http://host1:2379/version {"etcdserver":"3.3.11","etcdcluster":"3.3.0"} [rudi@host1 scripts]$ etcdctl member list 51b08bf82e03e049: name=etcdnode1 peerURLs=http://192.168.56.10:2380 clientURLs=http://192.168.56.10:2379 isLeader=true 6d36a224cc993604: name=etcdnode2 peerURLs=http://192.168.56.11:2380 clientURLs=http://192.168.56.11:2379 isLeader=false bb961ca5e3abf011: name=etcdnode3 peerURLs=http://192.168.56.12:2380 clientURLs=http://192.168.56.12:2379 isLeader=false
cd ~ patroni ./scripts/postgresql1.yml
host2:
cd ~ patroni ./scripts/postgresql2.yml
host3:
cd ~ patroni ./scripts/postgresql3.yml
[rudi@host1 ~]$ curl -L http://host1:8008/ {"state": "running", "postmaster_start_time": "2019-09-17 04:15:30.959 EDT", "role": "master", "server_version": 110003, "cluster_unlocked": false, "xlog": {"location": 83886400}, "timeline": 1, "replication": [{"usename": "replicator", "application_name": "postgresql2", "client_addr": "192.168.56.11", "state": "streaming", "sync_state": "sync", "sync_priority": 1}, {"usename": "replicator", "application_name": "postgresql3", "client_addr": "192.168.56.12", "state": "streaming", "sync_state": "potential", "sync_priority": 1}], "database_system_identifier": "6737550116166691859", "patroni": {"version": "1.6.0", "scope": "postgresql"}}
[rudi@host1 ~]$ patronictl version patronictl version 1.6.0 [rudi@host1 ~]$ patronictl -c ./scripts/postgresql1.yml list postgresql +------------+-------------+---------------------+--------+---------+----+-----------+ | Cluster | Member | Host | Role | State | TL | Lag in MB | +------------+-------------+---------------------+--------+---------+----+-----------+ | postgresql | postgresql1 | 192.168.56.10:15432 | Leader | running | 1 | 0 | | postgresql | postgresql2 | 192.168.56.11:15432 | | running | 1 | 0 | | postgresql | postgresql3 | 192.168.56.12:15432 | | running | 1 | 0 | +------------+-------------+---------------------+--------+---------+----+-----------+
[rudi@host1 ~]$ [rudi@host1 ~]$ patronictl -d etcd://host1:2379 list postgresql +------------+-------------+---------------------+--------+---------+----+-----------+ | Cluster | Member | Host | Role | State | TL | Lag in MB | +------------+-------------+---------------------+--------+---------+----+-----------+ | postgresql | postgresql1 | 192.168.56.10:15432 | Leader | running | 1 | 0 | | postgresql | postgresql2 | 192.168.56.11:15432 | | running | 1 | 0 | | postgresql | postgresql3 | 192.168.56.12:15432 | | running | 1 | 0 | +------------+-------------+---------------------+--------+---------+----+-----------+
[rudi@host1 scripts]$ etcdctl ls --recursive --sort -p /service /service/postgresql/ /service/postgresql/config /service/postgresql/initialize /service/postgresql/leader /service/postgresql/members/ /service/postgresql/members/postgresql1 /service/postgresql/members/postgresql2 /service/postgresql/members/postgresql3 /service/postgresql/optime/ /service/postgresql/optime/leader [rudi@host1 ~]$ etcdctl get /service/postgresql/leader postgresql1 [rudi@host1 ~]$ etcdctl get /service/postgresql/members/postgresql1 {"conn_url":"postgres://192.168.56.10:15432/postgres","api_url":"http://192.168.56.10:8008/patroni","state":"running","role":"master","version":"1.6.0","xlog_location":83888056,"timeline":1}
經過任意一臺主機( host1,host2, host3)訪問數據庫
export PATH=$PATH:/usr/local/pgsql/bin psql -U postgres -d postgres -p 15432 -h host1
create table test (id int, name varchar(100)); postgres=# create table test (id int, name varchar(100)); CREATE TABLE postgres=# insert into test values ( 1,'1'); INSERT 0 1 postgres=# select * from test; id | name ----+------ 1 | 1 (1 row)
psql -U postgres -d postgres -p 15432 -h host2
postgres=# insert into test values ( 1,'1'); ERROR: cannot execute INSERT in a read-only transaction
psql -U postgres -d postgres -p 15432 -h host3
postgres=# select * from test; id | name ----+------ 1 | 1 (1 row)
[rudi@host1 ~]$ patronictl -d etcd://host1:2379 list postgresql +------------+-------------+---------------------+--------+---------+----+-----------+ | Cluster | Member | Host | Role | State | TL | Lag in MB | +------------+-------------+---------------------+--------+---------+----+-----------+ | postgresql | postgresql1 | 192.168.56.10:15432 | Leader | running | 1 | 0 | | postgresql | postgresql2 | 192.168.56.11:15432 | | running | 1 | 0 | | postgresql | postgresql3 | 192.168.56.12:15432 | | running | 1 | 0 | +------------+-------------+---------------------+--------+---------+----+-----------+
[rudi@host1 ~]$ ps -ef|grep postgres rudi 3908 3759 0 11:35 pts/5 00:00:01 /usr/local/bin/python3 /usr/local/bin/patroni ./scripts/postgresql1.yml rudi 3929 1 0 11:35 ? 00:00:00 /usr/local/pgsql/bin/postgres -D /home/rudi/pgdata --config-file=/home/rudi/pgdata/postgresql.conf --listen_addresses=192.168.56.10 --port=15432 --cluster_name=postgresql --wal_level=replica --hot_standby=on --max_connections=100 --max_wal_senders=10 --max_prepared_transactions=0 --max_locks_per_transaction=64 --track_commit_timestamp=off --max_replication_slots=10 --max_worker_processes=8 --wal_log_hints=on rudi 3935 3929 0 11:35 ? 00:00:00 postgres: postgresql: checkpointer rudi 3936 3929 0 11:35 ? 00:00:00 postgres: postgresql: background writer rudi 3937 3929 0 11:35 ? 00:00:00 postgres: postgresql: walwriter rudi 3938 3929 0 11:35 ? 00:00:00 postgres: postgresql: autovacuum launcher rudi 3939 3929 0 11:35 ? 00:00:00 postgres: postgresql: stats collector rudi 3940 3929 0 11:35 ? 00:00:00 postgres: postgresql: logical replication launcher rudi 3944 3929 0 11:35 ? 00:00:00 postgres: postgresql: postgres postgres 192.168.56.10(44044) idle rudi 3954 3929 0 11:35 ? 00:00:00 postgres: postgresql: walsender replicator 192.168.56.11(42620) streaming 0/4019F60 rudi 3958 3929 0 11:35 ? 00:00:00 postgres: postgresql: walsender replicator 192.168.56.12(46540) streaming 0/4019F60 [rudi@host1 ~]$ kill -9 3929 [rudi@host1 ~]$
[rudi@host1 ~]$ patronictl -d etcd://host1:2379 list postgresql +------------+-------------+---------------------+--------+---------+----+-----------+ | Cluster | Member | Host | Role | State | TL | Lag in MB | +------------+-------------+---------------------+--------+---------+----+-----------+ | postgresql | postgresql1 | 192.168.56.10:15432 | Leader | running | | unknown | | postgresql | postgresql2 | 192.168.56.11:15432 | | running | 2 | 0 | | postgresql | postgresql3 | 192.168.56.12:15432 | | running | 2 | 0 | +------------+-------------+---------------------+--------+---------+----+-----------+
[rudi@host1 ~]$ ps -ef|grep postgres rudi 3908 3759 0 11:35 pts/5 00:00:01 /usr/local/bin/python3 /usr/local/bin/patroni ./scripts/postgresql1.yml rudi 4034 1 0 11:46 ? 00:00:00 /usr/local/pgsql/bin/postgres -D /home/rudi/pgdata --config-file=/home/rudi/pgda ta/postgresql.conf --listen_addresses=192.168.56.10 --port=15432 --cluster_name=postgresql --wal_level=replica --hot_standby=on --max_connections=100 --max_wal_senders=10 --max_prepared_transactions=0 --max_locks_per_transaction=64 --track_commit_timestamp =off --max_replication_slots=10 --max_worker_processes=8 --wal_log_hints=on rudi 4037 4034 0 11:46 ? 00:00:00 postgres: postgresql: checkpointer rudi 4038 4034 0 11:46 ? 00:00:00 postgres: postgresql: background writer rudi 4039 4034 0 11:46 ? 00:00:00 postgres: postgresql: stats collector rudi 4044 4034 0 11:46 ? 00:00:00 postgres: postgresql: postgres postgres 192.168.56.10(44742) idle rudi 4049 4034 0 11:46 ? 00:00:00 postgres: postgresql: walwriter rudi 4050 4034 0 11:46 ? 00:00:00 postgres: postgresql: autovacuum launcher rudi 4051 4034 0 11:46 ? 00:00:00 postgres: postgresql: logical replication launcher rudi 4054 4034 0 11:46 ? 00:00:00 postgres: postgresql: walsender replicator 192.168.56.11(43266) streaming 0/50001A8 rudi 4055 4034 0 11:46 ? 00:00:00 postgres: postgresql: walsender replicator 192.168.56.12(47174) streaming 0/50001A8
[rudi@host1 ~]$ patronictl -d etcd://host1:2379 list postgresql +------------+-------------+---------------------+--------+---------+----+-----------+ | Cluster | Member | Host | Role | State | TL | Lag in MB | +------------+-------------+---------------------+--------+---------+----+-----------+ | postgresql | postgresql1 | 192.168.56.10:15432 | Leader | running | 3 | 0 | | postgresql | postgresql2 | 192.168.56.11:15432 | | running | 3 | 0 | | postgresql | postgresql3 | 192.168.56.12:15432 | | running | 3 | 0 | +------------+-------------+---------------------+--------+---------+----+-----------+
[rudi@host1 ~]$ patronictl -d etcd://host1:2379 list postgresql +------------+-------------+---------------------+--------+---------+----+-----------+ | Cluster | Member | Host | Role | State | TL | Lag in MB | +------------+-------------+---------------------+--------+---------+----+-----------+ | postgresql | postgresql1 | 192.168.56.10:15432 | Leader | running | 3 | 0 | | postgresql | postgresql2 | 192.168.56.11:15432 | | running | 3 | 0 | | postgresql | postgresql3 | 192.168.56.12:15432 | | running | 3 | 0 | +------------+-------------+---------------------+--------+---------+----+-----------+
[rudi@host1 ~]$ patronictl -d etcd://host1:2379 switchover postgresql Master [postgresql1]: Candidate ['postgresql2', 'postgresql3'] []: postgresql3 When should the switchover take place (e.g. 2019-09-17T12:53 ) [now]: Current cluster topology +------------+-------------+---------------------+--------+---------+----+-----------+ | Cluster | Member | Host | Role | State | TL | Lag in MB | +------------+-------------+---------------------+--------+---------+----+-----------+ | postgresql | postgresql1 | 192.168.56.10:15432 | Leader | running | 3 | 0 | | postgresql | postgresql2 | 192.168.56.11:15432 | | running | 3 | 0 | | postgresql | postgresql3 | 192.168.56.12:15432 | | running | 3 | 0 | +------------+-------------+---------------------+--------+---------+----+-----------+ Are you sure you want to switchover cluster postgresql, demoting current master postgresql1? [y/N]: y 2019-09-17 11:53:12.19439 Successfully switched over to "postgresql3" +------------+-------------+---------------------+--------+---------+----+-----------+ | Cluster | Member | Host | Role | State | TL | Lag in MB | +------------+-------------+---------------------+--------+---------+----+-----------+ | postgresql | postgresql1 | 192.168.56.10:15432 | | stopped | | unknown | | postgresql | postgresql2 | 192.168.56.11:15432 | | running | 3 | 0 | | postgresql | postgresql3 | 192.168.56.12:15432 | Leader | running | 3 | | +------------+-------------+---------------------+--------+---------+----+-----------+
[rudi@host1 ~]$ patronictl -d etcd://host1:2379 list postgresql +------------+-------------+---------------------+--------+---------+----+-----------+ | Cluster | Member | Host | Role | State | TL | Lag in MB | +------------+-------------+---------------------+--------+---------+----+-----------+ | postgresql | postgresql1 | 192.168.56.10:15432 | | stopped | | unknown | | postgresql | postgresql2 | 192.168.56.11:15432 | | running | 4 | | | postgresql | postgresql3 | 192.168.56.12:15432 | Leader | running | 4 | 0 | +------------+-------------+---------------------+--------+---------+----+-----------+ [rudi@host1 ~]$ patronictl -d etcd://host1:2379 list postgresql +------------+-------------+---------------------+--------+---------+----+-----------+ | Cluster | Member | Host | Role | State | TL | Lag in MB | +------------+-------------+---------------------+--------+---------+----+-----------+ | postgresql | postgresql1 | 192.168.56.10:15432 | | running | 4 | 0 | | postgresql | postgresql2 | 192.168.56.11:15432 | | running | 4 | 0 | | postgresql | postgresql3 | 192.168.56.12:15432 | Leader | running | 4 | 0 | +------------+-------------+---------------------+--------+---------+----+-----------+
[rudi@host1 ~]$ patronictl -d etcd://host1:2379 list postgresql +------------+-------------+---------------------+--------+---------+----+-----------+ | Cluster | Member | Host | Role | State | TL | Lag in MB | +------------+-------------+---------------------+--------+---------+----+-----------+ | postgresql | postgresql1 | 192.168.56.10:15432 | | running | 4 | 0 | | postgresql | postgresql2 | 192.168.56.11:15432 | | running | 4 | 0 | | postgresql | postgresql3 | 192.168.56.12:15432 | Leader | running | 4 | 0 | +------------+-------------+---------------------+--------+---------+----+-----------+
[root@host3 ~]# reboot Connection to host3 closed by remote host. Connection to host3 closed.
[rudi@host1 ~]$ patronictl -d etcd://host1:2379 list postgresql +------------+-------------+---------------------+--------+---------+----+-----------+ | Cluster | Member | Host | Role | State | TL | Lag in MB | +------------+-------------+---------------------+--------+---------+----+-----------+ | postgresql | postgresql1 | 192.168.56.10:15432 | Leader | running | 5 | 0 | | postgresql | postgresql2 | 192.168.56.11:15432 | | running | 5 | 0 | | postgresql | postgresql3 | 192.168.56.12:15432 | | stopped | | unknown | +------------+-------------+---------------------+--------+---------+----+-----------+
[rudi@host3 ~]source ./scripts/etcd3.sh
[rudi@host3 ~]patroni ./scripts/postgresql3.yml
[rudi@host1 ~]$ patronictl -d etcd://host1:2379 list postgresql +------------+-------------+---------------------+--------+---------+----+-----------+ | Cluster | Member | Host | Role | State | TL | Lag in MB | +------------+-------------+---------------------+--------+---------+----+-----------+ | postgresql | postgresql1 | 192.168.56.10:15432 | Leader | running | 5 | 0 | | postgresql | postgresql2 | 192.168.56.11:15432 | | running | 5 | 0 | | postgresql | postgresql3 | 192.168.56.12:15432 | | running | 5 | 0 | +------------+-------------+---------------------+--------+---------+----+-----------+
[rudi@host1 ~]$ patronictl -d etcd://host1:2379 list postgresql +------------+-------------+---------------------+--------+---------+----+-----------+ | Cluster | Member | Host | Role | State | TL | Lag in MB | +------------+-------------+---------------------+--------+---------+----+-----------+ | postgresql | postgresql1 | 192.168.56.10:15432 | Leader | running | 5 | 0 | | postgresql | postgresql2 | 192.168.56.11:15432 | | running | 5 | 0 | | postgresql | postgresql3 | 192.168.56.12:15432 | | running | 5 | 0 | +------------+-------------+---------------------+--------+---------+----+-----------+
[root@host2 ~]# reboot Connection to host2 closed by remote host. Connection to host2 closed.
[rudi@host1 ~]$ patronictl -d etcd://host1:2379 list postgresql +------------+-------------+---------------------+--------+---------+----+-----------+ | Cluster | Member | Host | Role | State | TL | Lag in MB | +------------+-------------+---------------------+--------+---------+----+-----------+ | postgresql | postgresql1 | 192.168.56.10:15432 | Leader | running | 5 | 0 | | postgresql | postgresql2 | 192.168.56.11:15432 | | stopped | | unknown | | postgresql | postgresql3 | 192.168.56.12:15432 | | running | 5 | 0 | +------------+-------------+---------------------+--------+---------+----+-----------+
[rudi@host2 ~]source ./scripts/etcd2.sh
[rudi@host2 ~]patroni ./scripts/postgresql2.yml
[rudi@host1 ~]$ patronictl -d etcd://host1:2379 list postgresql +------------+-------------+---------------------+--------+---------+----+-----------+ | Cluster | Member | Host | Role | State | TL | Lag in MB | +------------+-------------+---------------------+--------+---------+----+-----------+ | postgresql | postgresql1 | 192.168.56.10:15432 | Leader | running | 5 | 0 | | postgresql | postgresql2 | 192.168.56.11:15432 | | running | 5 | 0 | | postgresql | postgresql3 | 192.168.56.12:15432 | | running | 5 | 0 | +------------+-------------+---------------------+--------+---------+----+-----------+