Snappy - PostgreSQL Snapshot Manager

Jul 26, 2024

gopostgresCLI

Quick PostgreSQL snapshots when you need them: https://github.com/brequet/snappy

At work, I’m constantly testing database migrations or switching between development versions of applications. I needed a way to snapshot my dev databases without losing the data I’d set up. Snappy was born from that need - a straightforward CLI to freeze database states and restore them when needed.

How it works

Snappy uses PostgreSQL’s template databases under the hood. When you snapshot a database, it creates a template copy with a generated name. Restoration swaps databases around - drop the old one, restore from the template. Everything is tracked in a dedicated snappy database with metadata tables.

Commands

snappy snapshot <db> <snapshot-name>
snappy list
snappy restore <snapshot-name>
snappy remove <snapshot-name>
snappy rename <old-name> <new-name>

Configuration comes from standard PostgreSQL environment variables (PGUSER, PGPASSWORD) or flags (-U, -h, -p).

Why it didn’t work out

This project is technically a failure. The concept seemed solid to me, but PostgreSQL’s template database mechanism has limitations I didn’t account for. User permissions and database roles don’t transfer correctly during the template copy. After restoring a snapshot, my applications would fail with permission errors because the database wasn’t in the correct state.

I could’ve added logic to handle permission restoration, but at that point the tool’s complexity would’ve defeated its purpose. The whole idea was instant snapshots, not wrestling with pg_dump-style metadata exports.