txn OK (KingbaseES V008R006C009B0014, primary, system@local, 2026-09-27T13:35:18+08:00)
oldest xid: 6343 (1045715 xid, 1045724 xmin, 1046007 xmin, 1046088 xmin)
open transactions: 5
pid user database application state xact xid xmin sql
1045715 system test kbdiag_inj_lock_holder idle in transaction 31s 6343 - lock table kbdiag_inj_lock in access exclusive mode;
1045724 system test kbdiag_inj_lock_waiter active 30s - 6343 select count(*) from kbdiag_inj_lock;
1045809 system test kbdiag_inj_idle_txn idle in transaction 29s 6344 - select txid_current() as kbdiag_last, pg_sleep(1);
1046007 system test kbdiag_inj_prepared_waiter active 25s 6347 6343 lock table kbdiag_inj_2pc in access exclusive mode;
1046088 system test kbdiag_inj_long_query active 25s - 6343 select pg_sleep(3600);
prepared: 1
gid owner database age xid
kbdiag_inj_2pc system test 26s 6346
EXIT_CODE=0
txn WARN (KingbaseES V008R006C009B0014, primary, system@local, 2026-09-27T13:35:21+08:00)
[WARN] txn.long session 1045715 has had a transaction open for 34s, now idle in transaction
verify: kbdiag session 1045715 # what it is running, which locks it holds, whether it blocks anyone
[WARN] txn.long session 1045724 has had a transaction open for 34s, now active
verify: kbdiag session 1045724 # what it is running, which locks it holds, whether it blocks anyone
[WARN] txn.long session 1045809 has had a transaction open for 32s, now idle in transaction
verify: kbdiag session 1045809 # what it is running, which locks it holds, whether it blocks anyone
[WARN] txn.long session 1046007 has had a transaction open for 28s, now active
verify: kbdiag session 1046007 # what it is running, which locks it holds, whether it blocks anyone
[WARN] txn.long session 1046088 has had a transaction open for 28s, now active
verify: kbdiag session 1046088 # what it is running, which locks it holds, whether it blocks anyone
[WARN] txn.prepared two-phase transaction kbdiag_inj_2pc prepared 29s ago and not finished, holding back the vacuum horizon
fix: ROLLBACK PREPARED 'kbdiag_inj_2pc' # check with the application whether to commit (COMMIT PREPARED) or roll back; run it connected to database test, outside a transaction block
oldest xid: 6343 (1045715 xid, 1045724 xmin, 1046007 xmin, 1046088 xmin)
open transactions: 5
pid user database application state xact xid xmin sql
1045715 system test kbdiag_inj_lock_holder idle in transaction 34s 6343 - lock table kbdiag_inj_lock in access exclusive mode;
1045724 system test kbdiag_inj_lock_waiter active 34s - 6343 select count(*) from kbdiag_inj_lock;
1045809 system test kbdiag_inj_idle_txn idle in transaction 32s 6344 - select txid_current() as kbdiag_last, pg_sleep(1);
1046007 system test kbdiag_inj_prepared_waiter active 28s 6347 6343 lock table kbdiag_inj_2pc in access exclusive mode;
1046088 system test kbdiag_inj_long_query active 28s - 6343 select pg_sleep(3600);
prepared: 1
gid owner database age xid
kbdiag_inj_2pc system test 29s 6346
EXIT_CODE=1
默认阈值下,idle in transaction 超过 300 秒的会话也会被 sessions 报成 session.idle_in_txn。两条回答的问题不同。
在备库上
~/kbdiag txn
echoEXIT_CODE=$?
txn OK (KingbaseES V008R006C009B0014, standby, system@local, 2026-09-27T13:37:20+08:00)
oldest xid: 6354 (599825 xmin)
open transactions: 1
pid user database application state xact xid xmin sql
599825 system test kbdiag_inj_lock_waiter active 14s - 6354 select pg_advisory_lock(424242);
txn.prepared: not_applicable (a standby cannot see the primary's two-phase transactions: run kbdiag txn on the primary)
EXIT_CODE=0