Re: Add pg_stat_recovery system view
Xuneng Zhou <xunengzhou@gmail.com>
From: Xuneng Zhou <xunengzhou@gmail.com>
To: pgsql-hackers <pgsql-hackers@lists.postgresql.org>
Cc: Michael Paquier <michael@paquier.xyz>
Date: 2026-03-04T01:02:29Z
Lists: pgsql-hackers
Attachments
- v2-0003-Refactor-move-XLogSource-enum-to-xlogrecovery.h.patch (application/octet-stream) patch v2-0003
- v2-0002-Add-pg_stat_recovery-system-view.patch (application/octet-stream) patch v2-0002
- v2-0001-Refactor-move-XLogRecoveryCtlData-struct-to-xlogr.patch (application/octet-stream) patch v2-0001
- v2-0004-Add-wal_source-column-to-pg_stat_recovery.patch (application/octet-stream) patch v2-0004
Hi, On Tue, Jan 27, 2026 at 3:23 PM Xuneng Zhou <xunengzhou@gmail.com> wrote: > > Hi Hackers, > > This patch series introduces pg_stat_recovery, a new view that exposes > the startup process’s internal recovery state at the SQL level. It > follows the pattern of pg_stat_wal_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 pg_stat_recovery 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 wal_source column to pg_stat_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_triggered | pause_state | wal_source | pg_size_pretty > -------------------+-------------+------------+---------------- > f | not paused | stream | 0 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 Just rebase. -- Best, Xuneng
Commits
-
Fix order of columns in pg_stat_recovery
- 2d4ead6f4bd0 19 (unreleased) landed
-
Add system view pg_stat_recovery
- 01d485b142e4 19 (unreleased) landed
-
Refactor code retrieving string for RecoveryPauseState
- 42a12856a6a0 19 (unreleased) landed
-
Move definition of XLogRecoveryCtlData to xlogrecovery.h
- 5f8124a0cf33 19 (unreleased) landed