找回密码
 立即注册
首页 业界区 安全 PostgreSQL pg_auto_failover 高可用 2:pg_auto_failov ...

PostgreSQL pg_auto_failover 高可用 2:pg_auto_failover集群运维

师佳思 3 小时前
 
PostgreSQL pg_auto_failover 高可用 1:pg_auto_failover集群搭建 
PostgreSQL pg_auto_failover 高可用 2:pg_auto_failover集群运维 
 
 
鉴于官方https://pg-auto-failover.readthedocs.io/en/main/operations.html有很多命令,并且有些命令笔者也没有弄清楚,这里仅列出部分命令。1, pg_auto_failover故障转移节点设置

通过pg_autoctl get formation settings查看集群参数设置
  1. root@ubuntu11:~# pg_autoctl get formation settings
  2.   Context |     Name |                   Setting | Value
  3. ----------+----------+---------------------------+------------------------------------
  4. formation |  default |     number_sync_standbys | 0
  5.   primary | ubuntu12 |   synchronous_standby_names | 'ANY 1 (pgautofailover_standby_60)'
  6.      node | ubuntu13 |    candidate priority | 50
  7.      node | ubuntu12 |    candidate priority | 50
  8.      node | ubuntu13 |    replication quorum | true
  9.      node | ubuntu12 |    replication quorum | true
复制代码
参数说明
number_sync_standbys:同步备库的数量
number_sync_standbys表示设置强同步节点的数量,如果为0的话,表示当从节点故障之后,主节点依旧可以支持读写,否则,如果可用的备用节点数量小于number_sync_standbys设置的个数的时候,主节点的写操作会被挂起。
number_sync_standbys的设置
pg_autoctl set formation number_sync_standbys  1
Replication quorum
此参数可设置为 true或 false,默认情况下为 true,表示有可能成为同步备库。如果设置为 false,表示使用异步复制。
Candidate Priority
该参数表示候选备库优先级,可以设为0 到100 间的任意值,缺省值是50。优先级越大,越容易备选择成为主库。如果设置为0,则不会选择该节点为新主库。
当备库候选优先级相同时,Monitor节点将选择LSN位置最高的的备库。如果各个备库的LSN位置相同,则随机选择一个备库。
 
实际测试中到一个有意思的问题,主备节点都正常的情况下
1,从pg_auto_failover的维度看,synchronous_standby_names 为 'ANY 1 (pgautofailover_standby_60)'
2,从postgresql实例的维度看,synchronous_commit = on,synchronous_standby_names=ANY 1 (pgautofailover_standby_60)
这意味着主备节点是同步复制。
但是当关闭备节点来模拟备节点故障的时候,发现synchronous_standby_names为'',此时再从主节点查询synchronous_standby_names,其值也变为'',意味着自动降级为异步复制。
  1. select name,setting from pg_settings where name like '%synchronous_commit%';
  2. name              |setting|
  3. ------------------+-------+
  4. synchronous_commit|on     |
  5. select name,setting from pg_settings where name like '%synchronous_standby_names%' ;
  6. name                     |setting                          |
  7. -------------------------+---------------------------------+
  8. synchronous_standby_names|ANY 1 (pgautofailover_standby_60)|
复制代码
1.png

如果想设置为强同步模式,通过pg_autoctl set formation number-sync-standbys 1设置,这时会发现,一主一备的模式是不支持的
2.png

 
2,pg_auto_failover故障转移监控参数设置

如下是pgautofailover故障转移相关的监控参数,参考https://pg-auto-failover.readthedocs.io/en/main/ref/configuration.html#configuration
  1. select name, setting, unit, short_desc from pg_settings where name ~ 'pgautofailover.';
  2. name                                            |setting |unit|short_desc                                                                                          |
  3. ------------------------------------------------+--------+----+----------------------------------------------------------------------------------------------------+
  4. pgautofailover.enable_sync_wal_log_threshold    |16777216|    |Don't enable synchronous replication until secondary xlog is within this many bytes of the primary's|
  5. pgautofailover.health_check_max_retries         |2       |    |Maximum number of re-tries before marking a node as failed.                                         |
  6. pgautofailover.health_check_period              |5000    |ms  |Duration between each check (in milliseconds).                                                      |
  7. pgautofailover.health_check_retry_delay         |2000    |ms  |Delay between consecutive retries.                                                                  |
  8. pgautofailover.health_check_timeout             |5000    |ms  |Connect timeout (in milliseconds).                                                                  |
  9. pgautofailover.node_considered_unhealthy_timeout|20000   |ms  |Mark node unhealthy if last ping was over this long ago                                             |
  10. pgautofailover.primary_demote_timeout           |30000   |ms  |Give the primary this long to drain before promoting the secondary                                  |
  11. pgautofailover.promote_wal_log_threshold        |16777216|    |Don't promote secondary unless xlog is with this many bytes of the master                           |
  12. pgautofailover.startup_grace_period             |10000   |ms  |Wait for at least this much time after startup before initiating a failover.                        |
复制代码
 

3, pg_auto_failover主从切换

3.1 自动故障切换

通过重启主节点的pgautofailover服务来模拟故障,发现会备用节点自动切换为主节点,原主节点启动后作为备用节点加入集群。
  1. root@ubuntu11:~#
  2. root@ubuntu11:~# pg_autoctl show state
  3.     Name |  Node |     Host:Port |       TLI: LSN |   Connection |      Reported State |      Assigned State
  4. ---------+-------+---------------+----------------+--------------+---------------------+--------------------
  5. ubuntu13 |    60 | ubuntu13:9300 |   9: 0/5039798 |    read-only |           secondary |           secondary
  6. ubuntu12 |    68 | ubuntu12:9300 |   9: 0/5039798 |   read-write |             primary |             primary
  7. root@ubuntu11:~#
  8. root@ubuntu11:~#
  9. root@ubuntu11:~# pg_autoctl show state
  10.     Name |  Node |     Host:Port |       TLI: LSN |   Connection |      Reported State |      Assigned State
  11. ---------+-------+---------------+----------------+--------------+---------------------+--------------------
  12. ubuntu13 |    60 | ubuntu13:9300 |  10: 0/5039960 |   read-write |        wait_primary |        wait_primary
  13. ubuntu12 |    68 | ubuntu12:9300 |   9: 0/5039810 |         none |             demoted |          catchingup
  14. root@ubuntu11:~#
  15. root@ubuntu11:~#
  16. root@ubuntu11:~# pg_autoctl show state
  17.     Name |  Node |     Host:Port |       TLI: LSN |   Connection |      Reported State |      Assigned State
  18. ---------+-------+---------------+----------------+--------------+---------------------+--------------------
  19. ubuntu13 |    60 | ubuntu13:9300 |  10: 0/5039A10 |   read-write |             primary |             primary
  20. ubuntu12 |    68 | ubuntu12:9300 |  10: 0/5039A10 |    read-only |           secondary |           secondary
  21. root@ubuntu11:~#
复制代码
 
3.2 switchover手动切换

在待提升为主节点的备节点上执行pg_autoctl perform switchover,可以看到当前节点提升为主节点
  1. root@ubuntu12:~# pg_autoctl perform switchover
  2. 05:12:23 213044 INFO  Targetting group 0 in formation "default"
  3. 05:12:23 213044 INFO  Listening monitor notifications about state changes in formation "default" and group 0
  4. 05:12:23 213044 INFO  Following table displays times when notifications are received
  5.     Time |     Name |  Node |     Host:Port |       Current State |      Assigned State
  6. ---------+----------+-------+---------------+---------------------+--------------------
  7. 05:12:23 | ubuntu13 |    60 | ubuntu13:9300 |             primary |            draining
  8. 05:12:23 | ubuntu12 |    68 | ubuntu12:9300 |           secondary |   prepare_promotion
  9. 05:12:23 | ubuntu12 |    68 | ubuntu12:9300 |   prepare_promotion |   prepare_promotion
  10. 05:12:23 | ubuntu12 |    68 | ubuntu12:9300 |   prepare_promotion |    stop_replication
  11. 05:12:23 | ubuntu13 |    60 | ubuntu13:9300 |             primary |      demote_timeout
  12. 05:12:23 | ubuntu13 |    60 | ubuntu13:9300 |            draining |      demote_timeout
  13. 05:12:23 | ubuntu13 |    60 | ubuntu13:9300 |      demote_timeout |      demote_timeout
  14. 05:12:24 | ubuntu12 |    68 | ubuntu12:9300 |    stop_replication |    stop_replication
  15. 05:12:24 | ubuntu12 |    68 | ubuntu12:9300 |    stop_replication |        wait_primary
  16. 05:12:24 | ubuntu13 |    60 | ubuntu13:9300 |      demote_timeout |             demoted
  17. 05:12:24 | ubuntu13 |    60 | ubuntu13:9300 |             demoted |             demoted
  18. 05:12:24 | ubuntu12 |    68 | ubuntu12:9300 |        wait_primary |        wait_primary
  19. 05:12:24 | ubuntu13 |    60 | ubuntu13:9300 |             demoted |          catchingup
  20. 05:12:25 | ubuntu13 |    60 | ubuntu13:9300 |          catchingup |          catchingup
  21. 05:12:26 | ubuntu13 |    60 | ubuntu13:9300 |          catchingup |           secondary
  22. 05:12:26 | ubuntu13 |    60 | ubuntu13:9300 |           secondary |           secondary
  23. 05:12:26 | ubuntu12 |    68 | ubuntu12:9300 |        wait_primary |             primary
  24. 05:12:26 | ubuntu12 |    68 | ubuntu12:9300 |             primary |             primary
  25. root@ubuntu12:~#
复制代码
从monitor节点也可以看到主备身份发生了变化
  1. root@ubuntu11:~#
  2. root@ubuntu11:~# pg_autoctl show state
  3.     Name |  Node |     Host:Port |       TLI: LSN |   Connection |      Reported State |      Assigned State
  4. ---------+-------+---------------+----------------+--------------+---------------------+--------------------
  5. ubuntu13 |    60 | ubuntu13:9300 |  11: 0/5039CC0 |    read-only |           secondary |           secondary
  6. ubuntu12 |    68 | ubuntu12:9300 |  11: 0/5039CC0 |   read-write |             primary |             primary
复制代码
 
3.3  failover 切换

pg_autoctl perform failover需要在monitor节点上执行,其结果会将备用节点提升为主节点。
  1. root@ubuntu11:~# pg_autoctl perform failover
  2. 05:15:57 774844 INFO  Waiting 60 secs for a notification with state "primary" in formation "default" and group 0
  3. 05:15:57 774844 INFO  Listening monitor notifications about state changes in formation "default" and group 0
  4. 05:15:57 774844 INFO  Following table displays times when notifications are received
  5.     Time |     Name |  Node |     Host:Port |       Current State |      Assigned State
  6. ---------+----------+-------+---------------+---------------------+--------------------
  7. 05:15:57 | ubuntu12 |    68 | ubuntu12:9300 |             primary |            draining
  8. 05:15:57 | ubuntu13 |    60 | ubuntu13:9300 |           secondary |   prepare_promotion
  9. 05:15:57 | ubuntu13 |    60 | ubuntu13:9300 |   prepare_promotion |   prepare_promotion
  10. 05:15:57 | ubuntu13 |    60 | ubuntu13:9300 |   prepare_promotion |    stop_replication
  11. 05:15:57 | ubuntu12 |    68 | ubuntu12:9300 |             primary |      demote_timeout
  12. 05:15:57 | ubuntu12 |    68 | ubuntu12:9300 |            draining |      demote_timeout
  13. 05:15:57 | ubuntu12 |    68 | ubuntu12:9300 |      demote_timeout |      demote_timeout
  14. 05:15:58 | ubuntu13 |    60 | ubuntu13:9300 |    stop_replication |    stop_replication
  15. 05:15:58 | ubuntu13 |    60 | ubuntu13:9300 |    stop_replication |        wait_primary
  16. 05:15:58 | ubuntu12 |    68 | ubuntu12:9300 |      demote_timeout |             demoted
  17. 05:15:58 | ubuntu12 |    68 | ubuntu12:9300 |             demoted |             demoted
  18. 05:15:58 | ubuntu13 |    60 | ubuntu13:9300 |        wait_primary |        wait_primary
  19. 05:15:58 | ubuntu12 |    68 | ubuntu12:9300 |             demoted |          catchingup
  20. 05:15:59 | ubuntu12 |    68 | ubuntu12:9300 |          catchingup |          catchingup
  21. 05:16:00 | ubuntu12 |    68 | ubuntu12:9300 |          catchingup |           secondary
  22. 05:16:00 | ubuntu12 |    68 | ubuntu12:9300 |           secondary |           secondary
  23. 05:16:00 | ubuntu13 |    60 | ubuntu13:9300 |        wait_primary |             primary
  24. 05:16:00 | ubuntu13 |    60 | ubuntu13:9300 |             primary |             primary
  25. root@ubuntu11:~#
  26. root@ubuntu11:~# pg_autoctl show state
  27.     Name |  Node |     Host:Port |       TLI: LSN |   Connection |      Reported State |      Assigned State
  28. ---------+-------+---------------+----------------+--------------+---------------------+--------------------
  29. ubuntu13 |    60 | ubuntu13:9300 |  12: 0/503A0E8 |   read-write |             primary |             primary
  30. ubuntu12 |    68 | ubuntu12:9300 |  12: 0/503A0E8 |    read-only |           secondary |           secondary
  31. root@ubuntu11:~#
  32. root@ubuntu11:~#
复制代码
 
4,pg_auto_failover添加节点

这里初始化新的机器ubuntu14,IP地址为192.168.152.124。此时主机列表如下,依次修改前三台主机的hosts映射文件,增加ubuntu14的地址与主机名。
192.168.152.121 ubuntu11
192.168.152.122 ubuntu12
192.168.152.123 ubuntu13
192.168.152.124 ubuntu14
使用pg_autoctl 创建注册到monitor节点。
/usr/local/pgsql16/server/bin/pg_autoctl create postgres --hostname ubuntu14 --name ubuntu14 --pgdata /usr/local/pgsql16/pg9300/data/ --pgport 9300 --auth trust --ssl-self-signed --monitor 'postgres://autoctl_node@ubuntu11:9300/pg_auto_failover?sslmode=require'
  1. root@ubuntu14:~# su - postgres
  2. postgres@ubuntu14:~$
  3. postgres@ubuntu14:~$
  4. postgres@ubuntu14:~$ /usr/local/pgsql16/server/bin/pg_autoctl create postgres --hostname ubuntu14 --name ubuntu14 --pgdata /usr/local/pgsql16/pg9300/data/ --pgport 9300 --auth trust --ssl-self-signed --monitor 'postgres://autoctl_node@ubuntu11:9300/pg_auto_failover?sslmode=require'
  5. 06:09:25 2643 INFO  Using default --ssl-mode "require"
  6. 06:09:25 2643 INFO  Using --ssl-self-signed: pg_autoctl will create self-signed certificates, allowing for encrypted network traffic
  7. 06:09:25 2643 WARN  Self-signed certificates provide protection against eavesdropping; this setup does NOT protect against Man-In-The-Middle attacks nor Impersonation attacks.
  8. 06:09:25 2643 WARN  See https://www.postgresql.org/docs/current/libpq-ssl.html for details
  9. 06:09:25 2643 INFO  Started pg_autoctl postgres service with pid 2645
  10. 06:09:25 2643 INFO  Started pg_autoctl node-init service with pid 2646
  11. 06:09:25 2645 INFO   /usr/local/pgsql16/server/bin/pg_autoctl do service postgres --pgdata /usr/local/pgsql16/pg9300/data/ -v
  12. 06:09:25 2646 INFO  Registered node 75 "ubuntu14" (ubuntu14:9300) in formation "default", group 0, state "wait_standby"
  13. 06:09:25 2646 INFO  Writing keeper state file at "/home/postgres/.local/share/pg_autoctl/usr/local/pgsql16/pg9300/data/pg_autoctl.state"
  14. 06:09:25 2646 INFO  Writing keeper init state file at "/home/postgres/.local/share/pg_autoctl/usr/local/pgsql16/pg9300/data/pg_autoctl.init"
  15. 06:09:25 2646 INFO  Successfully registered as "wait_standby" to the monitor.
  16. 06:09:25 2646 INFO  FSM transition from "init" to "wait_standby": Start following a primary
  17. 06:09:25 2646 INFO  Transition complete: current state is now "wait_standby"
  18. 06:09:26 2646 INFO  FSM transition from "wait_standby" to "catchingup": The primary is now ready to accept a standby
  19. 06:09:26 2646 INFO  Initialising PostgreSQL as a hot standby
  20. 06:09:26 2646 INFO   /usr/local/pgsql16/server/bin/pg_basebackup -w -d 'application_name=pgautofailover_standby_75 host=ubuntu13 port=9300 user=pgautofailover_replicator sslmode=require' --pgdata /usr/local/pgsql16/pg9300/backup/node_75 -U pgautofailover_replicator --verbose --progress --max-rate 100M --wal-method=stream --slot pgautofailover_standby_75
  21. 06:09:26 2646 INFO  pg_basebackup: initiating base backup, waiting for checkpoint to complete
  22. 06:09:26 2646 INFO  pg_basebackup: checkpoint completed
  23. 06:09:26 2646 INFO  pg_basebackup: write-ahead log start point: 0/6000028 on timeline 12
  24. 06:09:26 2646 INFO  pg_basebackup: starting background WAL receiver
  25. 06:09:26 2646 INFO  22759/22759 kB (100%), 0/1 tablespace (...backup/node_75/global/pg_control)
  26. 06:09:26 2646 INFO  22759/22759 kB (100%), 1/1 tablespace
  27. 06:09:26 2646 INFO  pg_basebackup:
  28. 06:09:26 2646 INFO
  29. 06:09:26 2646 INFO  write-ahead log end point: 0/6000100
  30. 06:09:26 2646 INFO  pg_basebackup:
  31. 06:09:26 2646 INFO
  32. 06:09:26 2646 INFO  waiting for background process to finish streaming ...
  33. 06:09:26 2646 INFO  pg_basebackup:
  34. 06:09:26 2646 INFO
  35. 06:09:26 2646 INFO  syncing data to disk ...
  36. 06:09:27 2646 INFO  pg_basebackup:
  37. 06:09:27 2646 INFO
  38. 06:09:27 2646 INFO  renaming backup_manifest.tmp to backup_manifest
  39. 06:09:27 2646 INFO  pg_basebackup:
  40. 06:09:27 2646 INFO
  41. 06:09:27 2646 INFO  base backup completed
  42. 06:09:27 2646 INFO  Creating the standby signal file at "/usr/local/pgsql16/pg9300/data/standby.signal", and replication setup at "/usr/local/pgsql16/pg9300/data/postgresql-auto-failover-standby.conf"
  43. 06:09:27 2646 INFO  Contents of "/usr/local/pgsql16/pg9300/data/postgresql-auto-failover-standby.conf" have changed, overwriting
  44. 06:09:27 2646 INFO   /usr/bin/openssl req -new -x509 -days 365 -nodes -text -out /usr/local/pgsql16/pg9300/data/server.crt -keyout /usr/local/pgsql16/pg9300/data/server.key -subj "/CN=ubuntu14"
  45. 06:09:27 2668 INFO   /usr/local/pgsql16/server/bin/postgres -D /usr/local/pgsql16/pg9300/data -p 9300 -h *
  46. 06:09:27 2646 INFO  PostgreSQL started on port 9300
  47. 06:09:27 2646 INFO  Fetched current list of 2 other nodes from the monitor to update HBA rules, including 2 changes.
  48. 06:09:27 2646 INFO  Ensuring HBA rules for node 60 "ubuntu13" (ubuntu13:9300)
  49. 06:09:27 2646 INFO  Ensuring HBA rules for node 68 "ubuntu12" (ubuntu12:9300)
  50. 06:09:27 2646 INFO  Reloading Postgres configuration and HBA rules
  51. 06:09:27 2645 INFO  Postgres is now serving PGDATA "/usr/local/pgsql16/pg9300/data" on port 9300 with pid 2668
  52. 06:09:27 2646 INFO  Transition complete: current state is now "catchingup"
  53. 06:09:27 2646 INFO  keeper has been successfully initialized.
  54. 06:09:27 2643 WARN  pg_autoctl service node-init exited with exit status 0
  55. 06:09:27 2645 INFO  Postgres controller service received signal SIGTERM, terminating
  56. 06:09:27 2645 INFO  Stopping pg_autoctl postgres service
  57. 06:09:27 2645 INFO  /usr/local/pgsql16/server/bin/pg_ctl --pgdata /usr/local/pgsql16/pg9300/data --wait stop --mode fast
  58. 06:09:27 2643 INFO  Stop pg_autoctl
  59. postgres@ubuntu14:~$
复制代码
然后创建systemctl服务
pg_autoctl -q show systemd --pgdata "/usr/local/pgsql16/pg9300/data" | tee /etc/systemd/system/pgautofailover.servicesystemctl daemon-reloadsystemctl enable pgautofailoversystemctl start pgautofailover 此时从monitor节点中看到,新的ubuntu14节点已经作为从节点加入到了集群中。
  1. root@ubuntu11:~# pg_autoctl show state
  2.     Name |  Node |     Host:Port |       TLI: LSN |   Connection |      Reported State |      Assigned State
  3. ---------+-------+---------------+----------------+--------------+---------------------+--------------------
  4. ubuntu13 |    60 | ubuntu13:9300 |  12: 0/7000060 |   read-write |             primary |             primary
  5. ubuntu12 |    68 | ubuntu12:9300 |  12: 0/7000060 |    read-only |           secondary |           secondary
  6. ubuntu14 |    75 | ubuntu14:9300 |  12: 0/7000060 |    read-only |           secondary |           secondary
  7. root@ubuntu11:~#
  8. root@ubuntu11:~# pg_autoctl show state
  9.     Name |  Node |     Host:Port |       TLI: LSN |   Connection |      Reported State |      Assigned State
  10. ---------+-------+---------------+----------------+--------------+---------------------+--------------------
  11. ubuntu13 |    60 | ubuntu13:9300 |  12: 0/7000060 |   read-write |             primary |             primary
  12. ubuntu12 |    68 | ubuntu12:9300 |  12: 0/7000060 |    read-only |           secondary |           secondary
  13. ubuntu14 |    75 | ubuntu14:9300 |  12: 0/7000060 |    read-only |           secondary |           secondary
  14. root@ubuntu11:~#
  15. root@ubuntu11:~#
复制代码
与此同时,pg_auto_failover会自动将集群升级为强同步模式(number_sync_standbys=1)
  1. root@ubuntu11:~# pg_autoctl get formation settings
  2.   Context |     Name |                   Setting | Value
  3. ----------+----------+---------------------------+---------------------------------------------------------------
  4. formation |  default |      number_sync_standbys | 1
  5.   primary | ubuntu13 | synchronous_standby_names | 'ANY 1 (pgautofailover_standby_68, pgautofailover_standby_75)'
  6.      node | ubuntu13 |        candidate priority | 50
  7.      node | ubuntu12 |        candidate priority | 50
  8.      node | ubuntu14 |        candidate priority | 50
  9.      node | ubuntu13 |        replication quorum | true
  10.      node | ubuntu12 |        replication quorum | true
  11.      node | ubuntu14 |        replication quorum | true
  12. root@ubuntu11:~#
复制代码
如果不希望新节点的candidate-priority为默认的50,可以降低其candidate-priority优先级
在ubuntu14自身节点上执行pg_autoctl set node candidate-priority --name ubuntu14 10 --monitor 'postgres://autoctl_node@ubuntu11:9300/pg_auto_failover?sslmode=require'
  1. root@ubuntu14:~# pg_autoctl set node candidate-priority --name ubuntu14 10 --monitor 'postgres://autoctl_node@ubuntu11:9300/pg_auto_failover?sslmode=require'
  2. 06:26:00 6614 INFO  Waiting for the settings to have been applied to the monitor and primary node
  3. 06:26:00 6614 INFO  New state is reported by node 60 "ubuntu13" (ubuntu13:9300): "apply_settings"
  4. 06:26:00 6614 INFO  Setting goal state of node 60 "ubuntu13" (ubuntu13:9300) to primary after it applied replication properties change.
  5. 06:26:01 6614 INFO  New state is reported by node 60 "ubuntu13" (ubuntu13:9300): "primary"
  6. 10
  7. root@ubuntu14:~#
复制代码
然后从monitor上查看
  1. ###candidate priority修改前
  2. root@ubuntu11:~# pg_autoctl get formation settings
  3.   Context |     Name |                   Setting | Value
  4. ----------+----------+---------------------------+---------------------------------------------------------------
  5. formation |  default |      number_sync_standbys | 1
  6.   primary | ubuntu13 | synchronous_standby_names | 'ANY 1 (pgautofailover_standby_68, pgautofailover_standby_75)'
  7.      node | ubuntu13 |        candidate priority | 50
  8.      node | ubuntu12 |        candidate priority | 50
  9.      node | ubuntu14 |        candidate priority | 50
  10.      node | ubuntu13 |        replication quorum | true
  11.      node | ubuntu12 |        replication quorum | true
  12.      node | ubuntu14 |        replication quorum | true
  13. ###candidate priority修改后
  14. root@ubuntu11:~#
  15. root@ubuntu11:~# pg_autoctl get formation settings
  16.   Context |     Name |                   Setting | Value
  17. ----------+----------+---------------------------+---------------------------------------------------------------
  18. formation |  default |      number_sync_standbys | 1
  19.   primary | ubuntu13 | synchronous_standby_names | 'ANY 1 (pgautofailover_standby_68, pgautofailover_standby_75)'
  20.      node | ubuntu13 |        candidate priority | 50
  21.      node | ubuntu12 |        candidate priority | 50
  22.      node | ubuntu14 |        candidate priority | 10
  23.      node | ubuntu13 |        replication quorum | true
  24.      node | ubuntu12 |        replication quorum | true
  25.      node | ubuntu14 |        replication quorum | true
复制代码
尝试将ubuntu14节点的quorum设置为false时报错,应该是条件不满足
  1. root@ubuntu14:~# pg_autoctl set node replication-quorum --name ubuntu14 false  --pgdata /usr/local/pgsql16/pg9300/data/   --monitor 'postgres://autoctl_node@ubuntu11:9300/pg_auto_failover?sslmode=require'
  2. 06:30:53 7313 WARN  Given --monitor URI, the --pgdata option is ignored
  3. 06:30:53 7313 INFO  Connecting to monitor at "postgres://autoctl_node@ubuntu11:9300/pg_auto_failover?sslmode=require"
  4. 06:30:53 7313 ERROR Monitor ERROR:  can't set replication quorum to false
  5. 06:30:53 7313 ERROR Monitor DETAIL:  At least 2 standby nodes are required in formation default with number_sync_standbys = 1, and only 1 would be participating in the replication quorum
  6. 06:30:53 7313 ERROR SQL query: SELECT pgautofailover.set_node_replication_quorum($1, $2, $3)
  7. 06:30:53 7313 ERROR SQL params: 'default', 'ubuntu14', 'false'
  8. 06:30:53 7313 ERROR Failed to update node replication quorum on node "ubuntu14"in formation "default" for replication_quorum: "false"
  9. 06:30:53 7313 ERROR Failed to set "replication-quorum" to "false".
  10. root@ubuntu14:~#
复制代码
 
5,其他命令

配置文件查看pg_autoctl show file
monitor节点
  1. root@ubuntu11:~# pg_autoctl show file
  2.    File | Path
  3. --------+----------------
  4.  Config | /root/.config/pg_autoctl/usr/local/pgsql16/pg9300/data/pg_autoctl.cfg
  5.     Pid | /run/user/0/pg_autoctl/usr/local/pgsql16/pg9300/data/pg_autoctl.pid
  6. root@ubuntu11:~#
复制代码
数据节点
  1. root@ubuntu12:~#
  2. root@ubuntu12:~# pg_autoctl show file
  3.    File | Path
  4. --------+----------------
  5. Config | /root/.config/pg_autoctl/usr/local/pgsql16/pg9300/data/pg_autoctl.cfg
  6.   State | /root/.local/share/pg_autoctl/usr/local/pgsql16/pg9300/data/pg_autoctl.state
  7.    Init | /root/.local/share/pg_autoctl/usr/local/pgsql16/pg9300/data/pg_autoctl.init
  8.     Pid | /run/user/0/pg_autoctl/usr/local/pgsql16/pg9300/data/pg_autoctl.pid
复制代码
 
 
从monitor中删除节点
pg_autoctl drop node --hostname ubuntu13
清除.local中的文件
pg_autoctl drop node  --destory
 

来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

相关推荐

您需要登录后才可以回帖 登录 | 立即注册