Skip to content

refactor: add pg_autoctl inspect and manual sub-command groups - #1130

Merged
dimitri merged 3 commits into
mainfrom
pg-autoctl-commands
Jul 6, 2026
Merged

refactor: add pg_autoctl inspect and manual sub-command groups#1130
dimitri merged 3 commits into
mainfrom
pg-autoctl-commands

Conversation

@dimitri

@dimitri dimitri commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Add two new always-visible sub-command groups to pg_autoctl, and remove the PG_AUTOCTL_DEBUG command-visibility gate:

  • pg_autoctl inspect — read-only diagnostics: pgsetup, fsm state/list/gv, monitor queries, network/show utilities. Safe to run on a live node.
  • pg_autoctl manual — operator-driven FSM operations for manual cluster recovery: fsm init/assign/step/nodes, service restart/pgctl, monitor register/active/version, primary/standby/coordinator ops.

Both groups are always visible in pg_autoctl --help. PG_AUTOCTL_DEBUG now only controls log verbosity — the root_with_debug dual-root pattern and the env-var command-dispatch gate are deleted.

Sub-process entry points are registered as a hidden pg_autoctl internal service command set — routable but absent from --help. The supervisor spawns pg_autoctl internal service postgres|listener|node-active instead of the old pg_autoctl do service ... path.

Changes

New dispatch layer

  • cli_inspect.c / cli_inspect.h: new pg_autoctl inspect dispatch (fsm, pgsetup, monitor, show, getpid)
  • cli_manual.c / cli_manual.h: new pg_autoctl manual dispatch (fsm, service, monitor, primary, standby, coordinator)
  • cli_root.c: add &inspect_commands, &manual_commands, &internal_commands to the root sub-command table

Hidden internal entry points

  • cli_do_root.c: add hidden pg_autoctl internal service (pgcontroller, postgres, listener, node-active) via make_hidden_command_set
  • commandline.h / commandline.c: add bool hidden field to CommandLine struct; add make_hidden_command_set macro; skip hidden commands in commandline_pretty_print_subcommands

Supervisor fix

  • service_postgres_ctl.c, service_monitor.c, service_keeper.c: supervisor spawns pg_autoctl internal service ... instead of the deleted pg_autoctl do service ... path

Symbol visibility

  • cli_do_fsm.c: remove static from fsm_init/state/list/gv/assign/step so cli_inspect.c and cli_manual.c can compose them
  • cli_do_monitor.c: remove static from monitor_get_command, monitor_parse_notification_command, monitor_register_command, monitor_node_active_command, monitor_version_command
  • cli_do_root.h: updated extern declarations for all newly-public symbols

Dead-code removal

  • cli_root.c / cli_root.h: delete root_with_debug and root_subcommands_with_debug (now identical to root)
  • main.c, cli_common.c: remove env_exists(PG_AUTOCTL_DEBUG) command-dispatch blocks

Tests and docs

  • tests/pgautofailover_utils.py: update do pgsetupinspect pgsetup, do fsminspect fsm (read-only) or manual fsm (mutating), do service restartmanual service restart
  • Add docs/ref/pg_autoctl_inspect.rst, pg_autoctl_inspect_pgsetup.rst, pg_autoctl_inspect_show.rst, pg_autoctl_manual.rst, pg_autoctl_manual_service_restart.rst
  • Trim docs/ref/pg_autoctl_do.rst to tmux/demo only; delete superseded pgsetup/show/service_restart pages
  • Update docs/ref/manual.rst toctree and docs/failover-state-machine.rst (remove PG_AUTOCTL_DEBUG=1 requirement from inspect fsm gv example)

Testing

Verified locally with a full test_basic_operation run (32 tests, OK) against a PG 17 Docker image.

@dimitri dimitri self-assigned this Jul 6, 2026
@dimitri dimitri added enhancement New feature or request Developer productivity Enhancements to ability to ship quality code labels Jul 6, 2026
@dimitri
dimitri changed the base branch from remove-azure to main July 6, 2026 17:55
@dimitri
dimitri force-pushed the pg-autoctl-commands branch 2 times, most recently from f1e2085 to 651da2e Compare July 6, 2026 18:11
Reorganise the operator-facing commands to make the binary more
approachable without the PG_AUTOCTL_DEBUG environment variable gate:

pg_autoctl inspect — read-only diagnostics, always visible
  inspect pgsetup   local PostgreSQL setup inspection
  inspect fsm       FSM state / list / graphviz (read-only subset)
  inspect monitor   get primary/others/candidate-count, parse-notification
  inspect show      ipaddr, cidr, lookup, hostname, reverse

pg_autoctl manual — operator-driven FSM operations for manual recovery
  manual fsm        assign / step / nodes get+set
  manual service    restart postgres|listener|node-active; pgctl on|off
  manual monitor    register / active / version
  manual coordinator add / activate / remove / update

Both groups are always visible regardless of PG_AUTOCTL_DEBUG.
PG_AUTOCTL_DEBUG now only controls log verbosity, not command visibility.

Implementation details:
- Add bool hidden field to CommandLine struct so make_hidden_command_set
  can register the internal sub-process entry points (pg_autoctl internal
  service postgres|listener|node-active) without surfacing them in --help
- The supervisor now spawns pg_autoctl internal service ... instead of
  the old pg_autoctl do service ... path; pg_autoctl do is trimmed to
  tmux and demo tooling only
- Python test helpers updated to use inspect/manual in place of do

Documentation:
- Add docs/ref/pg_autoctl_inspect.rst and pg_autoctl_inspect_pgsetup.rst,
  pg_autoctl_inspect_show.rst
- Add docs/ref/pg_autoctl_manual.rst and pg_autoctl_manual_service_restart.rst
- Trim docs/ref/pg_autoctl_do.rst to tmux/demo only; remove superseded
  pg_autoctl_do_pgsetup.rst, pg_autoctl_do_service_restart.rst,
  pg_autoctl_do_show.rst
- Update failover-state-machine.rst: pg_autoctl inspect fsm gv (no longer
  requires PG_AUTOCTL_DEBUG)
@dimitri
dimitri force-pushed the pg-autoctl-commands branch from 651da2e to f876e82 Compare July 6, 2026 18:36
dimitri added 2 commits July 6, 2026 22:37
…tatic fsm/monitor symbols

- Remove the PG_AUTOCTL_DEBUG command-dispatch branch: root_with_debug and
  root_subcommands_with_debug are identical to root now that inspect/manual
  are always-visible. Delete them from cli_root.c and cli_root.h; remove the
  env_exists(PG_AUTOCTL_DEBUG) gate from main.c and cli_common.c.

- Add pg_autoctl internal service (hidden) — the supervisor spawns subprocess
  entry points via fork+exec as:
      pg_autoctl internal service postgres|listener|node-active --pgdata ...
  make_hidden_command_set keeps these out of --help output.  Replaces the old
  'pg_autoctl do service' path that was broken when 'do' was renamed to 'internal'.

- Export fsm_init/state/list/gv/assign/step and monitor_get_command/
  parse_notification/register/node_active/version from their respective
  cli_do_*.c files (remove static) so cli_inspect.c and cli_manual.c can
  compose them into the inspect/manual sub-command trees.

- Drop fsm_node_state and monitor_node_state/formation_states from
  cli_inspect.c — these symbols exist only in pgaftest-infra, not origin/main.
@dimitri
dimitri merged commit c32eb03 into main Jul 6, 2026
51 of 52 checks passed
@dimitri
dimitri deleted the pg-autoctl-commands branch July 6, 2026 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Developer productivity Enhancements to ability to ship quality code enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant