Windows-first PostgreSQL restore utility for a narrow operational scenario: rebuilding a local or operator-controlled database quickly after workstation failure, reinstall, or environment corruption.
This is not positioned as a production-grade managed restore platform. It is a niche recovery tool built around a real support workflow where the target database is already offline, the operator is present, and the fastest safe-enough rebuild path matters more than broad platform coverage.
This repository is best understood as a support engineering artifact, not a general-purpose backup product.
It shows how I think about:
- operator-guided recovery instead of blind automation
- explicit tradeoffs between speed and safety
- Windows-based PostgreSQL support realities
- restore workflows that fail loudly on destructive steps instead of silently continuing
It is intentionally scoped to a narrower problem than cloud backup tooling, PITR orchestration, or multi-environment disaster recovery.
This version is a publishable niche tool with several hardening improvements already applied:
- profile-based restore tuning (
safe,fast,unsafe) - subprocess-local credential handling in the main restore path
- safer default restore acceleration via session-level settings
- explicit failure handling for
DROP DATABASEandCREATE DATABASE - archive validation before non-SQL restores
It still has important non-goals and limitations:
- Windows-first assumptions remain throughout the repo
- post-restore validation is intentionally lightweight
- it is not a managed cloud restore system
- it is not a zero-risk production restore tool
If you are evaluating this repo, the right question is not "is this a universal PostgreSQL restore solution?" The right question is "does this encode a real, narrow recovery workflow honestly and pragmatically?"
The original idea behind this tool is simple:
- a local PC or workstation fails
- the local PostgreSQL setup needs to be rebuilt
- the target database is effectively offline already
- there is no need to preserve an in-use running database during the restore
- speed matters more than conservative defaults
In that scenario, the operator usually needs a fast, repeatable workflow to:
- find a backup file
- connect to the local PostgreSQL instance
- drop and recreate the damaged database if necessary
- restore it as quickly as possible
- confirm that the database is back online
That is the problem this repository is trying to solve.
This project assumes all of the following are true:
- the restore is performed on Windows
- PostgreSQL is running locally or in a local controlled environment
- the database is not serving active application traffic during restore
- the operator is present and making the decisions interactively
- the target database may be dropped and recreated from scratch
- the backup being restored is the source of truth for recovery
If those assumptions are not true, this tool is probably the wrong tool.
This tool was designed around the environment where it was actually used: Windows machines.
That decision is intentional, not accidental.
Reasons:
- the real deployment environment was Windows
- PostgreSQL detection was built around Windows paths and Windows service discovery
- operator workflow was based on local Windows support and recovery
- reducing cross-platform abstraction kept the tool simpler and faster to operate
The goal here was not broad portability. The goal was to make the Windows recovery path practical.
The tool now uses restore profiles instead of one always-aggressive turbo mode.
Available profiles:
safe: no durability changes, no session tuningfast: safer default, uses session-level restore tuning onlyunsafe: keeps the old cluster-wide durability tradeoffs and requires explicit confirmation
The default fast profile avoids changing cluster-wide durability settings. Instead, it applies per-process restore settings such as:
synchronous_commit = off- higher
maintenance_work_mem
That keeps restore performance improvements local to the restore session and avoids weakening unrelated databases in the same cluster.
unsafe mode still exists for isolated recovery cases, but it should be used only when the PostgreSQL instance is dedicated to the restore operation.
This tool is not "safe" in the conservative enterprise sense.
Its safety model is narrower:
- fail explicitly on destructive database operations
- validate archive backups before restoring them
- stop
.sqlrestores on the first meaningful SQL error - always attempt to restore unsafe profile settings in a
finallyblock - provide lightweight post-restore validation
This is meant to reduce avoidable operator mistakes inside a destructive recovery workflow. It is not meant to make destructive recovery non-destructive.
Typical use cases:
- reinstalling PostgreSQL on a Windows PC
- recovering a broken local application database
- rebuilding a local environment after machine failure
- restoring a known-good backup into a newly recreated database
Typical flow:
- Detect PostgreSQL binaries and local instances.
- Locate a backup file.
- Connect using operator-provided credentials.
- Optionally create a safety backup of the current database.
- Drop and recreate the target database if needed.
- Prepare the selected restore profile.
- Restore the selected backup.
- Disable turbo mode.
- Run lightweight validation.
This project is intentionally not trying to be:
- a managed-cloud restore orchestrator
- a multi-platform PostgreSQL recovery framework
- a zero-risk production migration tool
- a full backup catalog and retention system
- a continuous automation/CI restore pipeline
Those are different products with different tradeoffs.
The current version includes several corrections to make the tool more reliable without changing its core philosophy:
DROP DATABASEandCREATE DATABASEfail explicitly instead of being ignored- turbo mode is always disabled in a
finallyblock .sqlrestores useON_ERROR_STOP=1pg_restoreno longer uses incorrect restore format flags- the main restore flow now dispatches
sql,custom,tar, anddirectorytypes correctly - administrative SQL quoting was corrected
- broken sequence realignment was removed from the main flow
- connection checks now use
PGSSLMODEcorrectly - pre-restore backup command construction was corrected
- the operator-facing interface was translated fully to English
Use this tool only when the target database is offline or effectively offline.
Do not use this workflow when:
- applications are actively connected
- the database must remain durable throughout the operation
- server-wide settings cannot be changed
- the environment requires conservative production-grade recovery controls
This tool is designed for fast rebuild and recovery on Windows, not for live in-place restore under load.
This repo complements the rest of the PostgreSQL support tooling in my public profile:
incident-response-runbook: how I structure diagnosis, escalation, and communication during incidentspg-incident-recovery: how I automate safe recovery on multi-cluster Windows hosts after crashes or rebootswindows-postgres-deployment-installer: how I standardize PostgreSQL deployment on Windows while keeping a human operator in the loop
pg_restore_tool sits lower in the stack than those repos: it focuses specifically on the restore path for a single target database in a controlled rebuild scenario.