PGV is a local developer tool that provides fast rollback, branching, and restore for PostgreSQL with data included, without relying on slow logical dump/restore workflows. It operates like Git, but versions your physical database state.
- You're running Postgres locally (e.g. in Docker).
- You apply migrations, run destructive tests, or accidentally delete data.
- You want to instantly return to an older database state including all rows, without waiting 15 minutes for
pg_dumpandpg_restore. - You want to test a feature on an isolated branch with a copy of your main database.
Ensure you have Docker installed and running.
Clone this repository and compile the binary:
go build -o pgv ./cmd/pgv
mv pgv /usr/local/bin/ # Or anywhere in your PATHYou probably already have a database running via Docker Compose or locally. PGV makes it incredibly easy to bring that existing data into its versioned workflow.
There are two primary ways to do this:
If you have an existing physical PGDATA directory (e.g., mapped as a volume in docker-compose.yml), you can initialize PGV using that data directory directly. This is virtually instantaneous since it bypasses logical dumps.
- Stop your existing database container.
docker compose stop db
- Initialize PGV pointing to your old data directory.
pgv init --from-dir ./path/to/your/db/data
- Start your new PGV-managed database.
Your database is now available on port 5540, fully managed by PGV!
pgv start main
If you prefer keeping your database running, or if you want to pull down data from a remote staging/production environment:
- Initialize a fresh PGV repository and start the main branch.
pgv init pgv start main
- Import data directly via connection string.
PGV uses Docker to stream the dump directly into your branch, requiring no host binaries!
pgv import postgres://user:password@host:port/dbname
- Save your new state.
pgv checkpoint "initial import"
Once your data is inside PGV, your workflow feels just like Git:
Create a checkpoint before doing something dangerous:
pgv checkpoint "before dropping users table"Branch off to try a new feature isolated from main:
pgv branch "before dropping users table" feature-branch
pgv checkout feature-branch
# Optional: keep both running for side-by-side testing
pgv start main --parallelNote
PGV stops the currently running branch (if any) and starts feature-branch on port 5540 by default. Use --parallel when you want multiple branches running on different ports.
Oops, I broke my database! Let's restore it:
pgv rollback # Instantly undoes your changes since the last checkpoint!List all your branches and snapshots:
pgv listEnjoy safe, instant database rollbacks locally!
