HeadlinesBriefing favicon HeadlinesBriefing.com

Pgtestdb's Template Cloning for Faster Testing

Hacker News •
×

Peter Downs' pgtestdb, a Go/Postgres testing package, leverages Postgres template databases for fast test setup. This approach copies existing template databases, a process significantly quicker than migrating from scratch or using Docker-based methods. Postgres achieves this by copying materialized heap, index, and catalog files in small chunks.

Comparing pgtestdb's template cloning with River's schema-based testing, initial setup times were remarkably similar, around 100 ms. While River's schema-based method, which leaves test state intact for examination and supports database-wide features, had a longer overall test suite execution time (14.54s vs. 51.07s for pgtestdb clone), it benefits from an optimization where test schemas are pooled and reused. This reuse, if implemented with pgtestdb, could reduce test setup time to 10-20 ms, making it comparable to test transactions for large test suites.