PG_AUTOCTL ENABLE MAINTENANCE(1)

✨ NAME ✨

okay bestie, so this is pg_autoctl enable maintenance β€” and it's literally the command that flips Postgres maintenance mode ON for this node. πŸ’…

It's part of the pg_auto_failover crew, and this page is the <red>pg_autoctl enable maintenance</red>(1) manual. Welcome, you're gonna love it here. πŸŽ€


🌸 SYNOPSIS 🌸

A pg_auto_failover node can be put into a maintenance state, and honestly? It's giving "brb don't touch me." 🫢 While it's in there, the Postgres node is still registered to the monitor, but the monitor knows it's unreliable until maintenance gets disabled. And the big one, no cap: a node in the maintenance state is not a candidate for promotion. πŸ‘‘

Typical glow-up reasons you'd use maintenance state: an Operating System or Postgres reboot β€” like when you're applying security upgrades. πŸ’–

usage: pg_autoctl enable maintenance  [ --pgdata --allow-failover ]

--pgdata      path to data directory

⭐ OPTIONS ⭐

  • --pgdata β€” where the Postgres node that's being managed locally lives. Defaults to the environment variable PGDATA. Also, heads up: use --monitor to connect to a monitor from anywhere, instead of the monitor URI that a local Postgres node managed with pg_autoctl would use. 🌈
  • --formation β€” the target formation where you wanna enable the secondary feature. πŸ¦‹

🧚 ENVIRONMENT 🧚

  • PGDATA β€” Postgres directory location. You can use this instead of the --pgdata option. ✨
  • PG_AUTOCTL_MONITOR β€” Postgres URI to connect to the monitor node. Can be used instead of the --monitor option. πŸ’œ
  • 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 πŸ’–

okay so first, vibe check the cluster:

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

now watch node3 go take its little nap 😴:

$ pg_autoctl enable maintenance --pgdata node3
12:06:12 47086 INFO  Listening monitor notifications about state changes in formation "default" and group 0
12:06:12 47086 INFO  Following table displays times when notifications are received
    Time |  Name |  Node |      Host:Port |       Current State |      Assigned State
---------+-------+-------+----------------+---------------------+--------------------
12:06:12 | node1 |     1 | localhost:5501 |             primary |        join_primary
12:06:12 | node3 |     3 | localhost:5503 |           secondary |    wait_maintenance
12:06:12 | node3 |     3 | localhost:5503 |    wait_maintenance |    wait_maintenance
12:06:12 | node1 |     1 | localhost:5501 |        join_primary |        join_primary
12:06:12 | node3 |     3 | localhost:5503 |    wait_maintenance |         maintenance
12:06:12 | node1 |     1 | localhost:5501 |        join_primary |             primary
12:06:13 | node3 |     3 | localhost:5503 |         maintenance |         maintenance

and then check the state again, look at her 😭:

$ pg_autoctl show state
 Name |  Node |      Host:Port |       LSN |   Connection |       Current State |      Assigned State
------+-------+----------------+-----------+--------------+---------------------+--------------------
node1 |     1 | localhost:5501 | 0/4000810 |   read-write |             primary |             primary
node2 |     2 | localhost:5502 | 0/4000810 |    read-only |           secondary |           secondary
node3 |     3 | localhost:5503 | 0/4000810 |         none |         maintenance |         maintenance
bestie the Connection column literally says none for node3 now β€” that's the maintenance era. iconic behavior. πŸ’…

πŸ’€ AUTHOR πŸ’€

Microsoft


Copyright (c) Microsoft Corporation. All rights reserved.


and that's the whole page, periodt. 🌟 this was pg_auto_failover version 2.2, dated Apr 07, 2025 β€” catch you on the flip side, bestie, go forth and maintain responsibly πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from