# lock: blocking chains and DDL queue predecessors

> Inspect lock waits, blocker trees, and DDL queue predecessors.

---

LLMS index: [llms.txt](/kbdiag-docs/llms.txt)

---

Find who holds locks, who is waiting in the queue, and whether a blocked DDL request is stalling downstream reads or writes. Read-only: never terminates holders or drops locks.

## Usage

```bash
kbdiag lock                       # active blockers and waiters summary
kbdiag lock --tree                # blocking hierarchy + DDL predecessors
kbdiag lock 91815                 # focus display on chains touching PID 91815
kbdiag lock --table public.orders # focus display on chains for one table
kbdiag lock --tree --limit 100    # raise waiter display cap (0 for all)
```

## Key Options

| Option | Effect |
|---|---|
| `--tree` | Render blocking hierarchy and highlight `[DDL queue predecessor]` nodes |
| `--table <name>` | Filter displayed chains to one relation (resolved within current database) |
| `--lock-wait-warn <sec>` | Wait duration threshold for `WARN` (default `10`s) |
| `--limit <N>` | Cap rendered waiter rows (`0` unlimited); blocker edge lookup samples up to 50 global waiting PIDs |

## Verdict & Reading Output

- **`WARN` (`exit=1`)**: Waiting lock duration `>= --lock-wait-warn` (default `10`s), including waits blocked by an uncommitted prepared transaction (`2PC`).
- **`UNKNOWN` (`exit=3`)**: Non-monitoring users unable to read wait times see `UNKNOWN`; probe collection caps blocker edge lookups at 50 waiting PIDs globally (`--table` and `<pid>` filter display after collection without expanding the 50-PID global edge budget).
- **V8R6 vs V9**: Versions lacking `sys_locks.waitstart` estimate upper-bound waits as `<=Ns (est.)` from `state_change`.

## Example (KES V9 Primary, `--lock-wait-warn 1 --tree`, `COLUMNS=80`)

```text
locks  WARN  (primary, system@local, endpoint=/tmp/.s.KINGBASE.54321, db=test,
    2026-12-02T14:56:23Z)

[WARN] lock.waiting  session 91817 has waited 2s for AccessExclusiveLock on
  public.kb_lock_day3, blocked by 91815

[WARN] lock.waiting  session 91819 has waited 2s for AccessShareLock on
  public.kb_lock_day3, blocked by 91817

[OVERVIEW]
  waiting : 2 sessions, 2 lock requests

[BLOCKING TREE]
  +- PID 91815 [root holder]
     > public.kb_lock_day3 RowShareLock
     > user=system app=kbdiag_lock_holder
     > SQL: SELECT * FROM public.kb_lock_day3 WHERE id=1 FOR UPDATE;
  | +- PID 91817 [DDL queue predecessor]
        > queued ahead for public.kb_lock_day3 AccessExclusiveLock
        > user=system app=kbdiag_lock_ddl
        > SQL: ALTER TABLE public.kb_lock_day3 ADD COLUMN extra int;
  | | +- PID 91819

[WAITING]
  +- PID 91817 | waited 2s | by 91815
     > AccessExclusiveLock | public.kb_lock_day3
  +- PID 91819 | waited 2s | by 91817
     > AccessShareLock | public.kb_lock_day3
     > user=system app=kbdiag_lock_reader
     > SQL: SELECT * FROM public.kb_lock_day3;

[NEXT]
  - inspect blocker: kbdiag session 91815
  - inspect blocker: kbdiag session 91817
```

## Related Commands

- [`kbdiag session`](/kbdiag-docs/docs/reference/session/) — inspect the root holder PID's transaction state and full SQL
- [`kbdiag txn`](/kbdiag-docs/docs/reference/txn/) — investigate `2PC` prepared transactions or long open blockers
- [`kbdiag progress`](/kbdiag-docs/docs/reference/progress/) — check whether an index build or vacuum is waiting on snapshots
