Skip to content

feat: show pg_restore progress in console via pg_stat_progress_copy#256

Open
raymondjacobson wants to merge 1 commit intomainfrom
feat/restore-progress-console
Open

feat: show pg_restore progress in console via pg_stat_progress_copy#256
raymondjacobson wants to merge 1 commit intomainfrom
feat/restore-progress-console

Conversation

@raymondjacobson
Copy link
Copy Markdown
Contributor

Summary

  • Adds a DB Restore card to the console overview that shows live progress during state sync database restoration, and is hidden when no restore is active
  • New restore_progress.go with two clean helpers: pollCopyProgress (goroutine driver) and queryCopyProgress (single poll via pg_stat_progress_copy)
  • RestoreDatabase now emits phase labels through each step — schema restore → truncate → data COPY (with per-table live progress) → converting to LOGGED → building indexes → completed
  • Progress string format: core_transactions — 14.2 / 18.1 GB (78%) when bytes_total is available, core_transactions — 14.2 GB otherwise

How it works

During the data COPY phase, a background goroutine polls pg_stat_progress_copy every 2 seconds and writes the result into the restore process metadata via RunningProcessWithMetadata. The poller is cancelled as soon as pg_restore returns.

The console card only renders when ProcessInfo.Restore.State != COMPLETED, so it's invisible during normal operation.

Changes

File What changed
proto/core/v1/types.proto Added restore = 11 field to ProcessInfo
pkg/core/server/restore_progress.go New file: pollCopyProgress + queryCopyProgress
pkg/core/server/cache.go ProcessStateRestore constant, restoreState cache field, init, switch case
pkg/core/server/connect.go Fetch and expose restoreState in processInfo
pkg/core/server/state_sync.go Phase labels + polling goroutine in RestoreDatabase
pkg/core/console/views/pages/overview_page.templ DB Restore card (hidden when completed)

Test plan

  • Start state sync on a node and verify the DB Restore card appears in /console/ with live table/progress info
  • Verify card disappears after restore completes and node transitions to block sync
  • Verify normal nodes (no state sync) show no DB Restore card

🤖 Generated with Claude Code

Adds a new "DB Restore" process entry to the console overview that is
visible during state sync database restoration and hidden otherwise.

- New ProcessStateRestore ("restore") process key, cache entry, and
  proto field (ProcessInfo.restore = 11)
- restore_progress.go: pollCopyProgress + queryCopyProgress helpers
  that query pg_stat_progress_copy every 2s and format output as
  "<table> — X.X / Y.Y GB (Z%)"
- RestoreDatabase now updates the restore process metadata through each
  phase: restoring schema → truncating → data COPY (live progress) →
  converting to LOGGED → building indexes → completed
- Console overview renders the "DB Restore" card only when the restore
  process is actively running (hidden when completed)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant