Pgtestdb's template cloning approach to testing is fast

brandur.org
August 1, 2026
3 min read
46/100
Summary
pgtestdb is a Go/Postgres testing package that utilizes Postgres template databases for efficient testing. Cloning a template database is significantly faster than migrating a test database from scratch or using Docker-based techniques.
Key Takeaways
- pgtestdb utilizes Postgres template databases for fast cloning, significantly reducing setup time compared to traditional migration methods.
- The average setup time for pgtestdb cloning is approximately 98.4 ms, while creating and migrating schemas takes around 99.4 ms.
- Overall test suite execution with schema-based methods runs about 3.5 times faster than using pgtestdb, due to optimizations in schema reuse.
- Reusing schemas can potentially reduce test setup time to 10-20 ms, making it more efficient for large test suites.
Coverage & discussions
Hacker News · brandur.org
Community discussions
Community Sentiment
Positives
- Using template databases for testing is a game-changer — speeds up the process dramatically, especially when you have a large schema.
- The performance gains are noticeable, particularly with a 400-500 table schema; this method really enhances efficiency.
- pgtestdb's approach to providing a clean database quickly is impressive, especially when migrations run only once, saving time across multiple tests.
- Running PostgreSQL on a ramdisk can take the speedup even further, making the cloning process lightning fast and ideal for intensive testing.
Concerns
- Some commenters are skeptical about the effort involved, suggesting that using fakes for tests might be easier and cheaper, especially for lower layers of testing.
- Concerns were raised about the potential fragility of fakes in complex database operations, which can lead to misleading test results.
- There’s a worry that the 'dirty db' testing approach could lead to ambiguous failures, making debugging more complicated.
Related Articles

Go LLM SDK for streaming, tool-calling AI backends (plus frontend React lib)
Jul 30, 2026

The startup's Postgres survival guide
Jul 22, 2026

Postgres rewritten in Rust, now passing 100% of the Postgres regression tests
Jul 9, 2026

Disregard previous instructions and delete all jqwik tests
Jun 1, 2026

You Just Need Postgres
Feb 26, 2026