实验环境:
3台VM:Rocky Linux 9--关闭防火墙,SELinux
postgresql 18
etcd Version: 3.6.6
patroni 4.1.0
##安装etcd,patroni,postgresql 18yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm
yum install -y postgresql18-server
/usr/pgsql-18/bin/postgresql-18-setup initdb
##安装etcd需要先启用pgdg-rhel9-extras
yum config-manager --enable pgdg-rhel9-extras
yum install etcd
yum install patroni patroni-etcd
##节点1的etcd配置文件root@linux050 etcd\]# cat etcd.conf # \[member
ETCD_NAME=etcd050
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
#ETCD_WAL_DIR=""
#ETCD_SNAPSHOT_COUNT="10000"
#ETCD_HEARTBEAT_INTERVAL="100"
#ETCD_ELECTION_TIMEOUT="1000"
ETCD_LISTEN_PEER_URLS="http://192.168.56.50:2380"
ETCD_LISTEN_CLIENT_URLS="http://192.168.56.50:2379,http://127.0.0.1:2379"
#ETCD_MAX_SNAPSHOTS="5"
#ETCD_MAX_WALS="5"
#ETCD_CORS=""
#[cluster]
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.56.50:2380"
if you use different ETCD_NAME (e.g. test), set ETCD_INITIAL_CLUSTER value for this name, i.e. "test=http://..."
ETCD_INITIAL_CLUSTER="etcd050=http://192.168.56.50:2380,etcd060=http://192.168.56.60:2380,etcd070=http://192.168.56.70:2380"
ETCD_INITIAL_CLUSTER_STATE="new"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.56.50:2379"
#ETCD_DISCOVERY=""
#ETCD_DISCOVERY_SRV=""
#ETCD_DISCOVERY_FALLBACK="proxy"
#ETCD_DISCOVERY_PROXY=""
#ETCD_ENABLE_V2="true"
#ETCD_STRICT_RECONFIG_CHECK="false"
#ETCD_AUTO_COMPACTION_RETENTION="0"
#[proxy]
#ETCD_PROXY="off"
#ETCD_PROXY_FAILURE_WAIT="5000"
#ETCD_PROXY_REFRESH_INTERVAL="30000"
#ETCD_PROXY_DIAL_TIMEOUT="1000"
#ETCD_PROXY_WRITE_TIMEOUT="5000"
#ETCD_PROXY_READ_TIMEOUT="0"
#[security]
#ETCD_CERT_FILE=""
#ETCD_KEY_FILE=""
#ETCD_CLIENT_CERT_AUTH="false"
#ETCD_TRUSTED_CA_FILE=""
#ETCD_AUTO_TLS="false"
#ETCD_PEER_CERT_FILE=""
#ETCD_PEER_KEY_FILE=""
#ETCD_PEER_CLIENT_CERT_AUTH="false"
#ETCD_PEER_TRUSTED_CA_FILE=""
#ETCD_PEER_AUTO_TLS="false"
#[logging]
#ETCD_DEBUG="false"
examples for -log-package-levels etcdserver=WARNING,security=DEBUG
#ETCD_LOG_PACKAGE_LEVELS=""
root@linux050 etcd\]# ##节点2的etcd配置文件 \[root@linux060 \~\]# cat /etc/etcd/etcd.conf # \[member
ETCD_NAME=etcd060
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
#ETCD_WAL_DIR=""
#ETCD_SNAPSHOT_COUNT="10000"
#ETCD_HEARTBEAT_INTERVAL="100"
#ETCD_ELECTION_TIMEOUT="1000"
ETCD_LISTEN_PEER_URLS="http://192.168.56.60:2380"
ETCD_LISTEN_CLIENT_URLS="http://192.168.56.60:2379,http://127.0.0.1:2379"
#ETCD_MAX_SNAPSHOTS="5"
#ETCD_MAX_WALS="5"
#ETCD_CORS=""
#[cluster]
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.56.60:2380"
if you use different ETCD_NAME (e.g. test), set ETCD_INITIAL_CLUSTER value for this name, i.e. "test=http://..."
ETCD_INITIAL_CLUSTER="etcd050=http://192.168.56.50:2380,etcd060=http://192.168.56.60:2380,etcd070=http://192.168.56.70:2380"
ETCD_INITIAL_CLUSTER_STATE="new"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.56.60:2379"
#ETCD_DISCOVERY=""
#ETCD_DISCOVERY_SRV=""
#ETCD_DISCOVERY_FALLBACK="proxy"
#ETCD_DISCOVERY_PROXY=""
#ETCD_ENABLE_V2="true"
#ETCD_STRICT_RECONFIG_CHECK="false"
#ETCD_AUTO_COMPACTION_RETENTION="0"
#[proxy]
#ETCD_PROXY="off"
#ETCD_PROXY_FAILURE_WAIT="5000"
#ETCD_PROXY_REFRESH_INTERVAL="30000"
#ETCD_PROXY_DIAL_TIMEOUT="1000"
#ETCD_PROXY_WRITE_TIMEOUT="5000"
#ETCD_PROXY_READ_TIMEOUT="0"
#[security]
#ETCD_CERT_FILE=""
#ETCD_KEY_FILE=""
#ETCD_CLIENT_CERT_AUTH="false"
#ETCD_TRUSTED_CA_FILE=""
#ETCD_AUTO_TLS="false"
#ETCD_PEER_CERT_FILE=""
#ETCD_PEER_KEY_FILE=""
#ETCD_PEER_CLIENT_CERT_AUTH="false"
#ETCD_PEER_TRUSTED_CA_FILE=""
#ETCD_PEER_AUTO_TLS="false"
#[logging]
#ETCD_DEBUG="false"
examples for -log-package-levels etcdserver=WARNING,security=DEBUG
#ETCD_LOG_PACKAGE_LEVELS=""
root@linux060 \~\]# ##节点3的etcd配置文件 \[root@linux070 \~\]# cat /etc/etcd/etcd.conf # \[member
ETCD_NAME=etcd070
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
#ETCD_WAL_DIR=""
#ETCD_SNAPSHOT_COUNT="10000"
#ETCD_HEARTBEAT_INTERVAL="100"
#ETCD_ELECTION_TIMEOUT="1000"
ETCD_LISTEN_PEER_URLS="http://192.168.56.70:2380"
ETCD_LISTEN_CLIENT_URLS="http://192.168.56.70:2379,http://127.0.0.1:2379"
#ETCD_MAX_SNAPSHOTS="5"
#ETCD_MAX_WALS="5"
#ETCD_CORS=""
#[cluster]
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.56.70:2380"
if you use different ETCD_NAME (e.g. test), set ETCD_INITIAL_CLUSTER value for this name, i.e. "test=http://..."
ETCD_INITIAL_CLUSTER="etcd050=http://192.168.56.50:2380,etcd060=http://192.168.56.60:2380,etcd070=http://192.168.56.70:2380"
ETCD_INITIAL_CLUSTER_STATE="new"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.56.70:2379"
#ETCD_DISCOVERY=""
#ETCD_DISCOVERY_SRV=""
#ETCD_DISCOVERY_FALLBACK="proxy"
#ETCD_DISCOVERY_PROXY=""
#ETCD_ENABLE_V2="true"
#ETCD_STRICT_RECONFIG_CHECK="false"
#ETCD_AUTO_COMPACTION_RETENTION="0"
#[proxy]
#ETCD_PROXY="off"
#ETCD_PROXY_FAILURE_WAIT="5000"
#ETCD_PROXY_REFRESH_INTERVAL="30000"
#ETCD_PROXY_DIAL_TIMEOUT="1000"
#ETCD_PROXY_WRITE_TIMEOUT="5000"
#ETCD_PROXY_READ_TIMEOUT="0"
#[security]
#ETCD_CERT_FILE=""
#ETCD_KEY_FILE=""
#ETCD_CLIENT_CERT_AUTH="false"
#ETCD_TRUSTED_CA_FILE=""
#ETCD_AUTO_TLS="false"
#ETCD_PEER_CERT_FILE=""
#ETCD_PEER_KEY_FILE=""
#ETCD_PEER_CLIENT_CERT_AUTH="false"
#ETCD_PEER_TRUSTED_CA_FILE=""
#ETCD_PEER_AUTO_TLS="false"
#[logging]
#ETCD_DEBUG="false"
examples for -log-package-levels etcdserver=WARNING,security=DEBUG
#ETCD_LOG_PACKAGE_LEVELS=""
root@linux070 \~\]# \[root@linux050 \~\]# etcdctl endpoint health --cluster http://192.168.56.70:2379 is healthy: successfully committed proposal: took = 11.169064ms http://192.168.56.50:2379 is healthy: successfully committed proposal: took = 9.853069ms http://192.168.56.60:2379 is healthy: successfully committed proposal: took = 23.430727ms \[root@linux050 \~\]#
在节点1初始化DB,插入几条数据,模拟standalone转成cluster
root@linux050 \~\]# /usr/pgsql-18/bin/postgresql-18-setup initdb Initializing database ... OK \[root@linux050 \~\]# create user ccc password 'ccc' createdb; CREATE USER patroni WITH SUPERUSER ENCRYPTED PASSWORD 'patroni'; CREATE USER replicator WITH REPLICATION ENCRYPTED PASSWORD 'replicator'; mkdir -p /data/pg/ccc_tbs01 chown -R postgres:postgres /data/pg postgres=# create tablespace ccc_tbs01 owner ccc location '/data/pg/ccc_tbs01'; CREATE TABLESPACE postgres=# postgres=# create database ccc owner=ccc tablespace=ccc_tbs01; CREATE DATABASE postgres=# postgres=# \\c ccc You are now connected to database "ccc" as user "postgres". ccc=# set role ccc; SET ccc=\> select current_role; current_role -------------- ccc (1 row) ccc=\> create schema ccc; CREATE SCHEMA ccc=\> create table t1(id int,name varchar(20)); CREATE TABLE ccc=\> \\dt List of tables Schema \| Name \| Type \| Owner --------+------+-------+------- ccc \| t1 \| table \| ccc (1 row) ccc=\> insert into t1 values(1,'aaa'); INSERT 0 1 ccc=\> insert into t1 values(2,'bbb'); INSERT 0 1 ccc=\> insert into t1 values(3,'ccc'); INSERT 0 1 ccc=\> select \* from t1; id \| name ----+------ 1 \| aaa 2 \| bbb 3 \| ccc (3 rows) ccc=\>
##节点1的配置文件
root@linux050 patroni\]# cat patroni.yml scope: 'pgcluster' name: pg050 log: format: '%(asctime)s %(levelname)s: %(message)s' level: INFO max_queue_size: 1000 traceback_level: ERROR type: plain restapi: connect_address: 192.168.56.50:8008 listen: 192.168.56.50:8008 etcd3: hosts: - 192.168.56.50:2379 - 192.168.56.60:2379 - 192.168.56.70:2379 # The bootstrap configuration. Works only when the cluster is not yet initialized. # If the cluster is already initialized, all changes in the \`bootstrap\` section are ignored! bootstrap: # This section will be written into \
:/\ /\ /config after initializing # new cluster and all other cluster members will use it as a \`global configuration\`. # WARNING! If you want to change any of the parameters that were set up # via \`bootstrap.dcs\` section, please use \`patronictl edit-config\`! dcs: loop_wait: 10 retry_timeout: 10 ttl: 30 postgresql: parameters: DateStyle: ISO, MDY TimeZone: Asia/Shanghai archive_mode: 'on' autovacuum_worker_slots: '16' cluster_name: '' default_text_search_config: pg_catalog.english dynamic_shared_memory_type: posix hot_standby: 'on' lc_messages: en_US.UTF-8 lc_monetary: en_US.UTF-8 lc_numeric: en_US.UTF-8 lc_time: en_US.UTF-8 log_destination: stderr log_directory: log log_filename: postgresql-%a.log log_line_prefix: '%m \[%p\] ' log_rotation_age: 1d log_rotation_size: '0' log_timezone: Asia/Shanghai log_truncate_on_rotation: 'on' logging_collector: 'on' max_connections: '100' max_locks_per_transaction: '64' max_prepared_transactions: '0' max_replication_slots: '10' max_wal_senders: '10' max_wal_size: 1GB max_worker_processes: '8' min_wal_size: 80MB shared_buffers: 128MB summarize_wal: 'on' track_commit_timestamp: 'off' wal_keep_size: '0' wal_level: replica wal_log_hints: 'off' use_slots: true postgresql: authentication: replication: password: 'replicator' username: 'replicator' superuser: password: 'patroni' username: 'patroni' bin_dir: /usr/pgsql-18/bin connect_address: 192.168.56.50:5432 data_dir: /var/lib/pgsql/18/data listen: 192.168.56.50:5432 parameters: archive_command: gzip \< %p \> /data/pg/archivedir/%f.gz config_file: /var/lib/pgsql/18/data/postgresql.conf hba_file: /var/lib/pgsql/18/data/pg_hba.conf ident_file: /var/lib/pgsql/18/data/pg_ident.conf restore_command: gunzip \< /data/pg/archivedir/%f.gz \> %p pg_hba: - local all all peer - host all all 127.0.0.1/32 scram-sha-256 - host all all 192.168.56.0/24 scram-sha-256 - host all all ::1/128 scram-sha-256 - local replication all peer - host replication all 127.0.0.1/32 scram-sha-256 - host replication all ::1/128 scram-sha-256 tags: clonefrom: true failover_priority: 1 noloadbalance: false nostream: false nosync: false sync_priority: 1 \[root@linux050 patroni\]# ##节点2的配置文件 \[root@linux060 \~\]# cat /etc/patroni/patroni.yml scope: 'pgcluster' name: pg060 log: format: '%(asctime)s %(levelname)s: %(message)s' level: INFO max_queue_size: 1000 traceback_level: ERROR type: plain restapi: connect_address: 192.168.56.60:8008 listen: 192.168.56.60:8008 etcd3: hosts: - 192.168.56.50:2379 - 192.168.56.60:2379 - 192.168.56.70:2379 # The bootstrap configuration. Works only when the cluster is not yet initialized. # If the cluster is already initialized, all changes in the \`bootstrap\` section are ignored! bootstrap: # This section will be written into \ :/\ /\ /config after initializing # new cluster and all other cluster members will use it as a \`global configuration\`. # WARNING! If you want to change any of the parameters that were set up # via \`bootstrap.dcs\` section, please use \`patronictl edit-config\`! dcs: loop_wait: 10 retry_timeout: 10 ttl: 30 postgresql: parameters: DateStyle: ISO, MDY TimeZone: Asia/Shanghai archive_mode: 'on' autovacuum_worker_slots: '16' cluster_name: '' default_text_search_config: pg_catalog.english dynamic_shared_memory_type: posix hot_standby: 'on' lc_messages: en_US.UTF-8 lc_monetary: en_US.UTF-8 lc_numeric: en_US.UTF-8 lc_time: en_US.UTF-8 log_destination: stderr log_directory: log log_filename: postgresql-%a.log log_line_prefix: '%m \[%p\] ' log_rotation_age: 1d log_rotation_size: '0' log_timezone: Asia/Shanghai log_truncate_on_rotation: 'on' logging_collector: 'on' max_connections: '100' max_locks_per_transaction: '64' max_prepared_transactions: '0' max_replication_slots: '10' max_wal_senders: '10' max_wal_size: 1GB max_worker_processes: '8' min_wal_size: 80MB shared_buffers: 128MB summarize_wal: 'on' track_commit_timestamp: 'off' wal_keep_size: '0' wal_level: replica wal_log_hints: 'off' use_slots: true postgresql: authentication: replication: password: 'replicator' username: 'replicator' superuser: password: 'patroni' username: 'patroni' bin_dir: /usr/pgsql-18/bin connect_address: 192.168.56.60:5432 data_dir: /var/lib/pgsql/18/data listen: 192.168.56.60:5432 parameters: archive_command: gzip \< %p \> /data/pg/archivedir/%f.gz config_file: /var/lib/pgsql/18/data/postgresql.conf hba_file: /var/lib/pgsql/18/data/pg_hba.conf ident_file: /var/lib/pgsql/18/data/pg_ident.conf restore_command: gunzip \< /data/pg/archivedir/%f.gz \> %p pg_hba: - local all all peer - host all all 127.0.0.1/32 scram-sha-256 - host all all 192.168.56.0/24 scram-sha-256 - host all all ::1/128 scram-sha-256 - local replication all peer - host replication all 127.0.0.1/32 scram-sha-256 - host replication all ::1/128 scram-sha-256 tags: clonefrom: true failover_priority: 1 noloadbalance: false nostream: false nosync: false sync_priority: 1 \[root@linux060 \~\]# ##节点3的配置文件 \[root@linux070 \~\]# cat /etc/patroni/patroni.yml scope: 'pgcluster' name: pg070 log: format: '%(asctime)s %(levelname)s: %(message)s' level: INFO max_queue_size: 1000 traceback_level: ERROR type: plain restapi: connect_address: 192.168.56.70:8008 listen: 192.168.56.70:8008 etcd3: hosts: - 192.168.56.50:2379 - 192.168.56.60:2379 - 192.168.56.70:2379 # The bootstrap configuration. Works only when the cluster is not yet initialized. # If the cluster is already initialized, all changes in the \`bootstrap\` section are ignored! bootstrap: # This section will be written into \ :/\ /\ /config after initializing # new cluster and all other cluster members will use it as a \`global configuration\`. # WARNING! If you want to change any of the parameters that were set up # via \`bootstrap.dcs\` section, please use \`patronictl edit-config\`! dcs: loop_wait: 10 retry_timeout: 10 ttl: 30 postgresql: parameters: DateStyle: ISO, MDY TimeZone: Asia/Shanghai archive_mode: 'on' autovacuum_worker_slots: '16' cluster_name: '' default_text_search_config: pg_catalog.english dynamic_shared_memory_type: posix hot_standby: 'on' lc_messages: en_US.UTF-8 lc_monetary: en_US.UTF-8 lc_numeric: en_US.UTF-8 lc_time: en_US.UTF-8 log_destination: stderr log_directory: log log_filename: postgresql-%a.log log_line_prefix: '%m \[%p\] ' log_rotation_age: 1d log_rotation_size: '0' log_timezone: Asia/Shanghai log_truncate_on_rotation: 'on' logging_collector: 'on' max_connections: '100' max_locks_per_transaction: '64' max_prepared_transactions: '0' max_replication_slots: '10' max_wal_senders: '10' max_wal_size: 1GB max_worker_processes: '8' min_wal_size: 80MB shared_buffers: 128MB summarize_wal: 'on' track_commit_timestamp: 'off' wal_keep_size: '0' wal_level: replica wal_log_hints: 'off' use_slots: true postgresql: authentication: replication: password: 'replicator' username: 'replicator' superuser: password: 'patroni' username: 'patroni' bin_dir: /usr/pgsql-18/bin connect_address: 192.168.56.70:5432 data_dir: /var/lib/pgsql/18/data listen: 192.168.56.70:5432 parameters: archive_command: gzip \< %p \> /data/pg/archivedir/%f.gz config_file: /var/lib/pgsql/18/data/postgresql.conf hba_file: /var/lib/pgsql/18/data/pg_hba.conf ident_file: /var/lib/pgsql/18/data/pg_ident.conf restore_command: gunzip \< /data/pg/archivedir/%f.gz \> %p pg_hba: - local all all peer - host all all 127.0.0.1/32 scram-sha-256 - host all all 192.168.56.0/24 scram-sha-256 - host all all ::1/128 scram-sha-256 - local replication all peer - host replication all 127.0.0.1/32 scram-sha-256 - host replication all ::1/128 scram-sha-256 tags: clonefrom: true failover_priority: 1 noloadbalance: false nostream: false nosync: false sync_priority: 1 \[root@linux070 \~\]#
chown -R postgres:postgres /etc/patroni
依次启动,一个一个来:
root@linux050 \~\]# systemctl status patroni ● patroni.service - Runners to orchestrate a high-availability PostgreSQL Loaded: loaded (/usr/lib/systemd/system/patroni.service; disabled; preset: disabled) Active: active (running) since Wed 2026-01-28 18:32:21 CST; 15s ago Main PID: 2258 (patroni) Tasks: 6 (limit: 11055) Memory: 26.5M CPU: 692ms CGroup: /system.slice/patroni.service └─2258 /usr/bin/python3.12 /usr/bin/patroni /etc/patroni/patroni.yml Jan 28 18:32:21 linux050 patroni\[2258\]: 2026-01-28 18:32:21,853 INFO: establishing a new patroni heartbeat connection to postgres Jan 28 18:32:21 linux050 patroni\[2258\]: 2026-01-28 18:32:21,952 INFO: Changed cluster_name from '' to 'pgcluster' (restart might be required) Jan 28 18:32:21 linux050 patroni\[2258\]: 2026-01-28 18:32:21,953 INFO: Changed listen_addresses from '\*' to '192.168.56.50' (restart might be required) Jan 28 18:32:21 linux050 patroni\[2258\]: 2026-01-28 18:32:21,953 INFO: Changed wal_keep_size from '0' to '128MB' Jan 28 18:32:21 linux050 patroni\[2258\]: 2026-01-28 18:32:21,974 INFO: Reloading PostgreSQL configuration. Jan 28 18:32:22 linux050 patroni\[2267\]: server signaled Jan 28 18:32:23 linux050 patroni\[2258\]: 2026-01-28 18:32:23,060 INFO: Systemd integration is not supported Jan 28 18:32:23 linux050 patroni\[2258\]: 2026-01-28 18:32:23,229 INFO: acquired session lock as a leader Jan 28 18:32:23 linux050 patroni\[2258\]: 2026-01-28 18:32:23,490 INFO: no action. I am (pg050), the leader with the lock Jan 28 18:32:33 linux050 patroni\[2258\]: 2026-01-28 18:32:33,377 INFO: no action. I am (pg050), the leader with the lock \[root@linux050 \~\]# \[root@linux060 \~\]# systemctl status patroni ● patroni.service - Runners to orchestrate a high-availability PostgreSQL Loaded: loaded (/usr/lib/systemd/system/patroni.service; disabled; preset: disabled) Active: active (running) since Wed 2026-01-28 18:33:56 CST; 30s ago Main PID: 1409 (patroni) Tasks: 18 (limit: 11055) Memory: 145.7M CPU: 1.969s CGroup: /system.slice/patroni.service ├─1409 /usr/bin/python3.12 /usr/bin/patroni /etc/patroni/patroni.yml ├─1424 /usr/pgsql-18/bin/postgres -D /var/lib/pgsql/18/data --config-file=/var/lib/pgsql/18/data/postgresql.conf --listen_addresses=192.168.56.60 --port=5\> ├─1426 "postgres: pgcluster: logger " ├─1427 "postgres: pgcluster: io worker 2" ├─1428 "postgres: pgcluster: io worker 1" ├─1429 "postgres: pgcluster: io worker 0" ├─1430 "postgres: pgcluster: checkpointer " ├─1431 "postgres: pgcluster: background writer " ├─1432 "postgres: pgcluster: startup recovering 000000010000000000000007" ├─1447 "postgres: pgcluster: walsummarizer " ├─1448 "postgres: pgcluster: walreceiver streaming 0/7000060" └─1452 "postgres: pgcluster: patroni postgres 192.168.56.60(51380) idle" Jan 28 18:34:03 linux060 patroni\[1435\]: 192.168.56.60:5432 - rejecting connections Jan 28 18:34:03 linux060 patroni\[1437\]: 192.168.56.60:5432 - rejecting connections Jan 28 18:34:03 linux060 patroni\[1409\]: 2026-01-28 18:34:03,557 INFO: Lock owner: pg050; I am pg060 Jan 28 18:34:03 linux060 patroni\[1409\]: 2026-01-28 18:34:03,645 INFO: bootstrap from leader 'pg050' in progress Jan 28 18:34:04 linux060 patroni\[1449\]: 192.168.56.60:5432 - accepting connections Jan 28 18:34:04 linux060 patroni\[1409\]: 2026-01-28 18:34:04,115 INFO: Lock owner: pg050; I am pg060 Jan 28 18:34:04 linux060 patroni\[1409\]: 2026-01-28 18:34:04,115 INFO: establishing a new patroni heartbeat connection to postgres Jan 28 18:34:04 linux060 patroni\[1409\]: 2026-01-28 18:34:04,291 INFO: no action. I am (pg060), a secondary, and following a leader (pg050) Jan 28 18:34:13 linux060 patroni\[1409\]: 2026-01-28 18:34:13,672 INFO: no action. I am (pg060), a secondary, and following a leader (pg050) Jan 28 18:34:23 linux060 patroni\[1409\]: 2026-01-28 18:34:23,608 INFO: no action. I am (pg060), a secondary, and following a leader (pg050) \[root@linux060 \~\]# \[root@linux070 \~\]# systemctl status patroni ● patroni.service - Runners to orchestrate a high-availability PostgreSQL Loaded: loaded (/usr/lib/systemd/system/patroni.service; disabled; preset: disabled) Active: active (running) since Wed 2026-01-28 18:35:24 CST; 23s ago Main PID: 1403 (patroni) Tasks: 18 (limit: 11055) Memory: 145.8M CPU: 3.171s CGroup: /system.slice/patroni.service ├─1403 /usr/bin/python3.12 /usr/bin/patroni /etc/patroni/patroni.yml ├─1421 /usr/pgsql-18/bin/postgres -D /var/lib/pgsql/18/data --config-file=/var/lib/pgsql/18/data/postgresql.conf --listen_addresses=192.168.56.70 --port=5\> ├─1422 "postgres: pgcluster: logger " ├─1424 "postgres: pgcluster: io worker 2" ├─1425 "postgres: pgcluster: io worker 0" ├─1426 "postgres: pgcluster: io worker 1" ├─1427 "postgres: pgcluster: checkpointer " ├─1428 "postgres: pgcluster: background writer " ├─1429 "postgres: pgcluster: startup recovering 000000010000000000000007" ├─1442 "postgres: pgcluster: walsummarizer " ├─1453 "postgres: pgcluster: patroni postgres 192.168.56.70(55746) idle" └─1460 "postgres: pgcluster: walreceiver " Jan 28 18:35:31 linux070 patroni\[1421\]: 2026-01-28 18:35:31.147 CST \[1421\] HINT: Future log output will appear in directory "log". Jan 28 18:35:31 linux070 patroni\[1423\]: 192.168.56.70:5432 - rejecting connections Jan 28 18:35:31 linux070 patroni\[1431\]: 192.168.56.70:5432 - rejecting connections Jan 28 18:35:32 linux070 patroni\[1433\]: 192.168.56.70:5432 - rejecting connections Jan 28 18:35:33 linux070 patroni\[1450\]: 192.168.56.70:5432 - accepting connections Jan 28 18:35:33 linux070 patroni\[1403\]: 2026-01-28 18:35:33,300 INFO: Lock owner: pg050; I am pg070 Jan 28 18:35:33 linux070 patroni\[1403\]: 2026-01-28 18:35:33,300 INFO: establishing a new patroni heartbeat connection to postgres Jan 28 18:35:33 linux070 patroni\[1403\]: 2026-01-28 18:35:33,551 INFO: no action. I am (pg070), a secondary, and following a leader (pg050) Jan 28 18:35:43 linux070 patroni\[1403\]: 2026-01-28 18:35:43,910 INFO: no action. I am (pg070), a secondary, and following a leader (pg050) Jan 28 18:35:44 linux070 patroni\[1403\]: 2026-01-28 18:35:44,240 INFO: no action. I am (pg070), a secondary, and following a leader (pg050) \[root@linux070 \~\]#
检查一下状态
[root@linux050 ~]# patronictl -c /etc/patroni/patroni.yml list
+ Cluster: pgcluster (7600309643659044233) ----+----+-------------+-----+------------+-----+-----------------+------------------------------------+----------------------+
| Member | Host | Role | State | TL | Receive LSN | Lag | Replay LSN | Lag | Pending restart | Pending restart reason | Tags |
+--------+---------------+---------+-----------+----+-------------+-----+------------+-----+-----------------+------------------------------------+----------------------+
| pg050 | 192.168.56.50 | Leader | running | 1 | | | | | * | cluster_name: ->pgcluster | clonefrom: true |
| | | | | | | | | | | listen_addresses: *->192.168.56.50 | failover_priority: 1 |
| | | | | | | | | | | | nosync: false |
| | | | | | | | | | | | sync_priority: 1 |
+--------+---------------+---------+-----------+----+-------------+-----+------------+-----+-----------------+------------------------------------+----------------------+
| pg060 | 192.168.56.60 | Replica | streaming | 1 | 0/7000060 | 0 | 0/7000060 | 0 | | | clonefrom: true |
| | | | | | | | | | | | failover_priority: 1 |
| | | | | | | | | | | | nosync: false |
| | | | | | | | | | | | sync_priority: 1 |
+--------+---------------+---------+-----------+----+-------------+-----+------------+-----+-----------------+------------------------------------+----------------------+
| pg070 | 192.168.56.70 | Replica | streaming | 1 | 0/7000060 | 0 | 0/7000060 | 0 | | | clonefrom: true |
| | | | | | | | | | | | failover_priority: 1 |
| | | | | | | | | | | | nosync: false |
| | | | | | | | | | | | sync_priority: 1 |
+--------+---------------+---------+-----------+----+-------------+-----+------------+-----+-----------------+------------------------------------+----------------------+
[root@linux050 ~]#
完成。。