Wait for LSN
wait_for_lsnBlock the current PostgreSQL session until WAL replay reaches a specified LSN, with an optional timeout to limit waiting.
Instructions
Issue WAIT FOR LSN '<lsn>' TIMEOUT <ms> and block until WAL replay catches up on the connected backend. timeout_ms defaults to 0 (wait indefinitely); a positive value bounds the wait — on timeout the helper returns timed_out=true rather than raising so the caller can decide whether to retry or fall through. LSN format is strictly validated (hex/hex) before any SQL is composed. Requires PG 19+; raises on older servers with the poll-loop fallback in the message. Returns an object with lsn, timeout_ms (int), timed_out (bool), and wait_sql (the rendered statement).
Example: wait_for_lsn(lsn='0/1234ABCD', timeout_ms=5000)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| lsn | Yes | ||
| database | No | Optional: target a configured secondary (read-only) database by name; omit for the primary. Call list_databases to see the configured ids. | |
| timeout_ms | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| lsn | Yes | ||
| wait_sql | Yes | ||
| timed_out | Yes | ||
| timeout_ms | Yes |