PG_AUTOCTL_PERFORM_FAILOVER(1)

πŸ“¦
version 2.1 Β· 2 versions
, in fedora 43, fedora 44

πŸ‘‘ pg_autoctl perform failover β€” the glow-up where your standby takes the crown

okay bestie, so this is one of the pages from the pg_auto_failover manual, and it's literally the "hand the crown to somebody else" button. Sit down, hydrate, let's go πŸ’–


✨ NAME ✨

pg_autoctl perform failover β€” pg_autoctl perform failover

pg_autoctl perform failover β€” Perform a failover for given formation and group


🌸 SYNOPSIS 🌸

This command starts a Postgres failover orchestration from the pg_auto_failover monitor:

usage: pg_autoctl perform failover  [ --pgdata --formation --group ]

--pgdata      path to data directory
--formation   formation to target, defaults to 'default'
--group       group to target, defaults to 0
--wait        how many seconds to wait, default to 60

πŸ¦‹ DESCRIPTION πŸ¦‹

So the pg_auto_failover monitor can orchestrate a manual failover for you β€” some people call it a switchover, same energy, different name, iykyk. And the way it does that without anybody getting hurt? It uses intermediary states in the Finite State Machine, which is the whole reason split-brain is prevented. no cap. πŸ’…

The pg_autoctl perform failover command waits until the failover is known complete on the monitor, or until the hard-coded 60s timeout has passed. Whichever hits first, bestie.

And here's the part that matters: the failover orchestration is done in the background by the monitor. So even if your pg_autoctl perform failover stops on the timeout, the failover orchestration just keeps going at the monitor. She doesn't need you watching. main character energy fr fr πŸ‘‘


πŸ’… OPTIONS πŸ’…

  • --pgdata β€” Where the Postgres node being managed locally lives. Defaults to the environment variable PGDATA. Use --monitor to connect to a monitor from anywhere, instead of the monitor URI used by a local Postgres node managed with pg_autoctl.
  • --formation β€” The formation to target for the operation. Defaults to default.
  • --group β€” The Postgres group to target for the operation. Defaults to 0. Heads up: only Citus formations may have more than one group. 🫢
  • --wait β€” How many seconds to wait for notifications about the promotion. The command stops when the promotion is finished (a node is primary), or when the timeout has elapsed, whichever comes first. And the special lil trick: the value 0 (zero) disables the timeout and lets the command wait forever. immortal behavior honestly ⭐

🌈 ENVIRONMENT 🌈

  • PGDATA β€” Postgres directory location. Can be used instead of the --pgdata option.
  • PG_AUTOCTL_MONITOR β€” Postgres URI to connect to the monitor node, can be used instead of the --monitor option.
  • PGHOST, PGPORT, PGDATABASE, PGUSER, PGCONNECT_TIMEOUT, ... β€” See the Postgres docs about Environment Variables for details.
  • TMPDIR β€” The pgcopydb command creates all its work files and directories in ${TMPDIR}/pgcopydb, and defaults to /tmp/pgcopydb.
  • XDG_CONFIG_HOME β€” The pg_autoctl command stores its configuration files in the standard place XDG_CONFIG_HOME. See the XDG Base Directory Specification.
  • XDG_DATA_HOME β€” The pg_autoctl command stores its internal states files in the standard place XDG_DATA_HOME, which defaults to ~/.local/share. See the XDG Base Directory Specification.

πŸŽ€ EXAMPLES πŸŽ€

watch her cook πŸ”₯

$ pg_autoctl perform failover
12:57:30 3635 INFO  Listening monitor notifications about state changes in formation "default" and group 0
12:57:30 3635 INFO  Following table displays times when notifications are received
    Time |  Name |  Node |      Host:Port |       Current State |      Assigned State
---------+-------+-------+----------------+---------------------+--------------------
12:57:30 | node1 |     1 | localhost:5501 |             primary |            draining
12:57:30 | node1 |     1 | localhost:5501 |            draining |            draining
12:57:30 | node2 |     2 | localhost:5502 |           secondary |          report_lsn
12:57:30 | node3 |     3 | localhost:5503 |           secondary |          report_lsn
12:57:36 | node3 |     3 | localhost:5503 |          report_lsn |          report_lsn
12:57:36 | node2 |     2 | localhost:5502 |          report_lsn |          report_lsn
12:57:36 | node2 |     2 | localhost:5502 |          report_lsn |   prepare_promotion
12:57:36 | node2 |     2 | localhost:5502 |   prepare_promotion |   prepare_promotion
12:57:36 | node2 |     2 | localhost:5502 |   prepare_promotion |    stop_replication
12:57:36 | node1 |     1 | localhost:5501 |            draining |      demote_timeout
12:57:36 | node3 |     3 | localhost:5503 |          report_lsn |      join_secondary
12:57:36 | node1 |     1 | localhost:5501 |      demote_timeout |      demote_timeout
12:57:36 | node3 |     3 | localhost:5503 |      join_secondary |      join_secondary
12:57:37 | node2 |     2 | localhost:5502 |    stop_replication |    stop_replication
12:57:37 | node2 |     2 | localhost:5502 |    stop_replication |        wait_primary
12:57:37 | node1 |     1 | localhost:5501 |      demote_timeout |             demoted
12:57:37 | node1 |     1 | localhost:5501 |             demoted |             demoted
12:57:37 | node2 |     2 | localhost:5502 |        wait_primary |        wait_primary
12:57:37 | node3 |     3 | localhost:5503 |      join_secondary |           secondary
12:57:37 | node1 |     1 | localhost:5501 |             demoted |          catchingup
12:57:38 | node3 |     3 | localhost:5503 |           secondary |           secondary
12:57:38 | node2 |     2 | localhost:5502 |        wait_primary |             primary
12:57:38 | node1 |     1 | localhost:5501 |          catchingup |          catchingup
12:57:38 | node2 |     2 | localhost:5502 |             primary |             primary

and then you check the receipts:

$ pg_autoctl show state
 Name |  Node |      Host:Port |       LSN |   Connection |       Current State |      Assigned State
------+-------+----------------+-----------+--------------+---------------------+--------------------
node1 |     1 | localhost:5501 | 0/4000F50 |    read-only |           secondary |           secondary
node2 |     2 | localhost:5502 | 0/4000F50 |   read-write |             primary |             primary
node3 |     3 | localhost:5503 | 0/4000F50 |    read-only |           secondary |           secondary

πŸ’œ AUTHOR πŸ’œ

Microsoft


Copyright (c) Microsoft Corporation. All rights reserved.


okay that's the whole page, you ate it, no crumbs πŸ“ this was the pg_autoctl perform failover(1) page from the pg_auto_failover manual, version 2.1, dated Jan 18, 2025 β€” mwah, go promote something responsibly bestie πŸ’–βœ¨πŸ‘‘

πŸ“¦ where this page comes from