patroni-配置文件参数修改

网友投稿 1275 2022-05-30

export PATRONICTL_CONFIG_FILE=/etc/patroni/patroni_postgresql.yml

#  configfile         Patroni may also read the configuration from the

PATRONI_CONFIGURATION environment variable

# 可以查看命令的使用说明

patronictl --help

# 查看版本号

patronictl -c /etc/patroni.yml version

# 查看所有成员信息

patronictl -c /etc/patroni.yml list

# 重新加载配置

patronictl -c /etc/patroni.yml reload

# 移除集群,重新配置的时候使用

patronictl -c /etc/patroni.yml remove postgres

# 重启数据库集群

patronictl -c /etc/patroni.yml restart postgres

# 切换 Leader,将一个 slave 切换成 leader。

patronictl -c /etc/patroni.yml switchover

#查看历史failovers/switchovers

patronictl -c /etc/patroni/patroni_postgresql.yml history

#默认配置文件位置:

#patronictl configure

#Configuration file [/root/.config/patroni/patronictl.yaml]:

/root/.config/patroni/patronictl.yaml

[root@db03 patroni]# cp /etc/patroni/patroni_postgresql.yml  ./patronictl.yaml

[root@db03 patroni]# patronictl  list

+--------+---------------+---------+---------+----+-----------+

| Member | Host          | Role    | State   | TL | Lag in MB |

+ Cluster: pgha (7025507499523621070) -------+----+-----------+

| node1  | 192.168.5.201 | Replica | running |  6 |         0 |

| node2  | 192.168.5.202 | Replica | running |  6 |         0 |

| node3  | 192.168.5.203 | Leader  | running |  6 |           |

+--------+---------------+---------+---------+----+-----------+

故障位置

patroni-配置文件参数修改

故障场景

patroni动作

备库

PG备库停止

拉起PG备库服务

备库

正常停止备库patroni

停止PG备库

备库

备库patroni异常停止

无动作

备库

备库无法连接ETCD

无动作

备库

非leader角色但PG处于生产模式

重启PG并切换到恢复模式作为备库

备库

备库主机重启

patroni启动拉起PG备库

主库

PG主库停止

启动PG,如果启动时间超过master_start_timeout,进行主备切换

主库

正常停止主库patroni

关闭主库,从备库中选举新主库

主库

主库patroni异常停止

看门狗重启主机,启动后如果拿到Leader锁,主备不切换,否则选举新主,切换主备

主库

主库无法连接ETCD

主库降级为备库,触发故障转移

-

ETCD故障

主库降级,集群中全部备库

-

同步模式下,无可用同步备库

临时切换为异步模式,在恢复同步模式之前自动故障转移不可用

官网连接

https://patroni.readthedocs.io/en/latest/dynamic_configuration.html

https://patroni.readthedocs.io/en/latest/

常用命令:

patronictl -c /etc/patroni/patroni_postgresql.yml list

patronictl -c /etc/patroni/patroni_postgresql.yml show-config

patronictl -c /etc/patroni/patroni_postgresql.yml edit-config

patronictl -c /etc/patroni/patroni_postgresql.yml restart (集群名称) (node1)

patronictl -c /etc/patroni/patroni_postgresql.yml switchover

patronictl -c /etc/patroni/patroni_postgresql.yml reinit (集群名称) (node1)

PG:配置文件生效顺序:

1. load parameters from file postgresql.base.conf (or from a custom_conf file, if set)

2. load parameters from file postgresql.conf

3. load parameters from file postgresql.auto.conf

4. run-time parameter using -o –name=value

#https://patroni.readthedocs.io/en/latest/dynamic_configuration.html

编辑配置文件: //必须更改 DCS 中的共享配置,本地配置修改不生效(在一个节点执行即可)

patronictl -c /etc/patroni/patroni_postgresql.yml edit-config

重启数据库集群(三个节点都执行)

patronictl -c /usr/patroni/conf/patroni_postgresql.yml restart pgha(集群名称)

查询集群名称:

patronictl -c /etc/patroni/patroni_postgresql.yml list

+--------+---------------+---------+---------+----+-----------+-----------------+

| Member | Host          | Role    | State   | TL | Lag in MB | Pending restart |

+ Cluster: pgha (7025507499523621070) -------+----+-----------+-----------------+

| node1  | 192.168.5.201 | Replica | running |  3 |         0 |                 |

| node2  | 192.168.5.202 | Replica | running |  3 |         0 |                 |

| node3  | 192.168.5.203 | Leader  | running |  3 |           | *               |

+--------+---------------+---------+---------+----+-----------+-----------------+

查看配置文件:

[root@db03 patroni]# patronictl -c /etc/patroni/patroni_postgresql.yml show-config

loop_wait: 10

master_start_timeout: 300

maximum_lag_on_failover: 20485760

postgresql:

parameters:

hot_standby: 'on'

listen_addresses: '*'

max_connections: 150

max_replication_slots: 10

max_wal_senders: 10

max_wal_size: 1GB

port: 5432

wal_keep_segments: 1000

wal_level: logical

wal_log_hints: 'on'

use_pg_rewind: true

use_slots: false

retry_timeout: 10

ttl: 30

参考:

https://github.com/zalando/patroni

https://patroni.readthedocs.io/en/latest/

https://patroni.readthedocs.io/en/latest/ENVIRONMENT.html

https://github.com/zalando/patroni/blob/master/docs/replication_modes.rst

https://postgresconf.org/system/events/document/000/000/228/Patroni_tutorial_4x3-2.pdf

云容灾

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:程序员常访问的国外技术交流网站汇总
下一篇:【大厂面试】腾讯面试,你真的懂HTTP吗?
相关文章