Skip to content

txn: open transactions, 2PC and XID horizons

Inspect open transactions, prepared 2PC transactions, and oldest xmin/xid vacuum horizon holders.

Identify long-running transactions, unfinished two-phase commits (2PC), and the session, 2PC, or replication slot holding back the vacuum horizon. Read-only: never commits, rolls back, or cancels transactions.

Usage

kbdiag txn                              # open txns, 2PCs, and oldest horizon holder
kbdiag txn --xact-warn 600 --prepared-warn 600
kbdiag txn --limit 20                   # display cap (0 for all; rules judge all)
kbdiag txn --json                       # raw 64-bit XIDs and raw 2PC GIDs

Key Options

OptionEffect
--xact-warn <sec>WARN age threshold for open transactions (default 300s)
--prepared-warn <sec>WARN age threshold for prepared 2PC transactions (default 900s)
--limit <N>Max open-transaction rows rendered (0 unlimited; prepared 2PC rows remain unlimited and verdict evaluates all rows)
--jsonEmit structured JSON (session.activity, txn.prepared, slot.list, raw GIDs and XIDs)

Verdict & Reading Output

  • WARN (exit=1): txn.long (open transaction age >= --xact-warn, default 300s) or txn.prepared (2PC age >= --prepared-warn, default 900s).
  • UNKNOWN (exit=3): session.activity unavailable/masked or primary txn.prepared probe failed.
  • Horizon & standby rules: [OVERVIEW] compares backend_xid, backend_xmin, 2PC XIDs, and slot xmin together (tie-breaking in favor of actual transaction writers over snapshot retainers). On standbys, txn.prepared reports not_applicable; check 2PC on the primary. Never commit or roll back a prepared 2PC without checking its coordinator first.

Example (KES V9 Primary, --xact-warn 1 --prepared-warn 1, COLUMNS=80)

txn  WARN  (primary, system@local, endpoint=/tmp/.s.KINGBASE.54321,
    2026-12-02T15:14:41Z)

[WARN] txn.long  session 92181 has had a transaction open for 2s, now idle in
  transaction
  verify: kbdiag session 92181  # what it is running, which locks it holds,
    whether it blocks anyone

[WARN] txn.prepared  two-phase transaction kbdiag_txn_2pc_day3 prepared 1s ago
  and not finished, holding back the vacuum horizon
  verify: kbdiag txn --json  # check the 2PC coordinator in database test for
    the intended outcome before COMMIT PREPARED or ROLLBACK PREPARED

[OVERVIEW]
  oldest observed xid/xmin : 6641
  +- horizon holder : slot repmgr_slot_2 xmin

[OPEN TRANSACTIONS]
  open : 2 | hidden/untracked without visible xid : 0
  +- PID 92181 | idle in transaction | xact 2s
     > xid=6681 xmin=- | system/test
     > UPDATE public.kb_txn_day3 SET val='held' WHERE id=1;
  +- PID 92179 | idle in transaction | xact 2s
     > xid=- xmin=6681 | system/test
     > SELECT count(*) FROM public.kb_txn_day3;

[PREPARED TRANSACTIONS]
  prepared : 1
  Check the 2PC coordinator before deciding to commit or roll back.
  +- 2PC | xid 6682 | age 1s
     > gid=kbdiag_txn_2pc_day3 | system/test

[NEXT]
  - inspect horizon/transaction: kbdiag session 92181
  - inspect slot horizon: kbdiag slots
  - check 2PC coordinator before commit/rollback: kbdiag txn --json