Add pg_stat_recovery system view

  • Jump to comment-1
    Xuneng Zhou<xunengzhou@gmail.com>
    Jan 27, 2026, 7:24 AM UTC
    Hi Hackers,
    This patch series introduces pgstatrecovery, a new view that exposes
    the startup process’s internal recovery state at the SQL level. It
    follows the pattern of pgstatwal_receiver, but focuses on WAL replay
    and recovery rather than WAL reception.
    The view provides visibility into replay progress, recovery timing,
    and operational status—information that was previously scattered
    across separate function calls or not exposed at all.
    As Michael suggested [1][2], this view is intentionally independent of
    walreceiver state, since the startup process can consume WAL from
    multiple sources (archive, pg_wal, or streaming), not just streaming
    replication.
    The patch series:
    0001: Refactor: move XLogRecoveryCtlData struct to xlogrecovery.h
    Move the XLogRecoveryCtlData struct definition from xlogrecovery.c to
    xlogrecovery.h,
    0002: Add pgstatrecovery system view
    Introduces the core view with columns
    0003: Refactor: move XLogSource enum to xlogrecovery.h
    Preparatory refactoring to make XLogSource visible externally.
    0004: Add walsource column to pgstat_recovery
    Adds wal_source column showing where WAL was last read from:
    'archive', 'pg_wal', or 'stream'.
    Example usage on a standby:
    SELECT promote_triggered, pause_state, wal_source,
    pg_size_pretty(pg_wal_lsn_diff(replay_end_lsn, last_replayed_end_lsn))
    FROM pg_stat_recovery;
    promote_triggeredpause_statewal_sourcepg_size_pretty
    fnot pausedstream0 bytes
    Feedbacks welcome.
    [1] https://www.postgresql.org/message-id/aW13GJn_RfTJIFCa@paquier.xyz
    [2] https://www.postgresql.org/message-id/aW68b79-9U3WPZiz@paquier.xyz
    --
    Best,
    Xuneng