‘Managing a cluster’¶
クラスター情報¶
クラスターに関する情報を取得するには、 list またはtopology
エンドポイントを使用します。
$ patronictl -c /etc/patroni.yml list
+ Cluster: demo-cluster-1 (7106835957012965359) ----+----+-----------+
| Member | Host | Role | State | TL | Lag in MB |
+-------------+-----------------+---------+---------+----+-----------+
| pg-patroni1 | xxx.xxx.xxx.xxx | Leader | running | 1 | |
| pg-patroni2 | xxx.xxx.xxx.xxx | Replica | running | 1 | 0 |
+-------------+-----------------+---------+---------+----+-----------+
$ patronictl -c /etc/patroni.yml topology
+ Cluster: demo-cluster-1 (7106835957012965359) ------+----+-----------+
| Member | Host | Role | State | TL | Lag in MB |
+---------------+-----------------+---------+---------+----+-----------+
| pg-patroni1 | xxx.xxx.xxx.xxx | Leader | running | 1 | |
| + pg-patroni2 | xxx.xxx.xxx.xxx | Replica | running | 1 | 0 |
+---------------+-----------------+---------+---------+----+-----------+
Patroniログ¶
Patroniログはsystemdによってシステムログに送信されます。 journalctl
システムユーティリティを使用して取得します。
$ sudo journalctl -u patroni.service -n 100 -f
Jun 08 12:26:29 pg-patroni1 patroni[26589]: 2022-06-08 12:26:29,000 INFO: no action. I am (pg-patroni1), a secondary, and following a leader (pg-patroni2)
...
メンテナンスモード¶
クラスター管理を一時停止または再開するには、次を使用します。
$ patronictl -c /etc/patroni.yml pause
Success: cluster management is paused
$ patronictl -c /etc/patroni.yml list
+ Cluster: demo-cluster-1 (7106835957012965359) ----+----+-----------+
| Member | Host | Role | State | TL | Lag in MB |
+-------------+-----------------+---------+---------+----+-----------+
| pg-patroni1 | xxx.xxx.xxx.xxx | Leader | running | 1 | |
| pg-patroni2 | xxx.xxx.xxx.xxx | Replica | running | 1 | 0 |
+-------------+-----------------+---------+---------+----+-----------+
Maintenance mode: on
$ patronictl -c /etc/patroni.yml resume
Success: cluster management is resumed
手動フェイルオーバーまたはスイッチオーバー¶
フェールオーバーエンドポイントを使用すると、正常なノードがない場合に手動フェールオーバーを実行できます。スイッチオーバーをスケジュールすることはできません。
Usage: patronictl failover [OPTIONS] [CLUSTER_NAME]
Failover to a replica
Options:
--master TEXT The name of the current master
--candidate TEXT The name of the candidate
--force Do not ask for confirmation at any point
--help Show this message and exit.
スイッチオーバーエンドポイントは、クラスターが正常な場合、つまりリーダーがいる場合にのみ機能します。これにより、スイッチオーバーをスケジュールできます。
Usage: patronictl switchover [OPTIONS] [CLUSTER_NAME]
Switchover to a replica
Options:
--master TEXT The name of the current master
--candidate TEXT The name of the candidate
--scheduled TEXT Timestamp of a scheduled switchover in unambiguous format
(e.g. ISO 8601)
--force Do not ask for confirmation at any point
--help Show this message and exit.
例:
$ patronictl -c /etc/patroni.yml switchover --candidate pg-patroni2
Master [pg-patroni1]:
When should the switchover take place (e.g. 2022-06-08T13:14 ) [now]:
Current cluster topology
+ Cluster: demo-cluster-1 (7106835957012965359) ----+----+-----------+
| Member | Host | Role | State | TL | Lag in MB |
+-------------+-----------------+---------+---------+----+-----------+
| pg-patroni1 | xxx.xxx.xxx.xxx | Leader | running | 1 | |
| pg-patroni2 | xxx.xxx.xxx.xxx | Replica | running | 1 | 0 |
+-------------+-----------------+---------+---------+----+-----------+
Are you sure you want to switchover cluster demo-cluster-1, demoting current master pg-patroni1? [y/N]: y
2022-06-08 12:14:48.01625 Successfully switched over to "pg-patroni2"
+ Cluster: demo-cluster-1 (7106835957012965359) ----+----+-----------+
| Member | Host | Role | State | TL | Lag in MB |
+-------------+-----------------+---------+---------+----+-----------+
| pg-patroni1 | xxx.xxx.xxx.xxx | Replica | stopped | | unknown |
| pg-patroni2 | xxx.xxx.xxx.xxx | Leader | running | 1 | |
+-------------+-----------------+---------+---------+----+-----------+
$ patronictl -c /etc/patroni.yml list
+ Cluster: demo-cluster-1 (7106835957012965359) ----+----+-----------+
| Member | Host | Role | State | TL | Lag in MB |
+-------------+-----------------+---------+---------+----+-----------+
| pg-patroni1 | xxx.xxx.xxx.xxx | Replica | running | 2 | 0 |
| pg-patroni2 | xxx.xxx.xxx.xxx | Leader | running | 2 | |
+-------------+-----------------+---------+---------+----+-----------+
$ patronictl -c /etc/patroni.yml history
+----+----------+------------------------------+----------------------------------+-------------+
| TL | LSN | Reason | Timestamp | New Leader |
+----+----------+------------------------------+----------------------------------+-------------+
| 1 | 67109024 | no recovery target specified | 2022-06-08T12:14:47.785857+00:00 | pg-patroni2 |
+----+----------+------------------------------+----------------------------------+-------------+