Pgtestdb is a Go/Postgres testing package that leverages Postgres template databases. This built-in Postgres feature allows for rapid creation of new databases by copying an existing template. The process involves Postgres enumerating relations and copying materialized heap, index, and catalog files in 8 kB page chunks, making it faster than migrating a database from scratch or using Docker-based techniques.
A comparison was conducted between pgtestdb's template cloning approach and a schema-based testing methodology used in the River project. The schema-based method, while slower than test transactions, offers advantages in isolation and uses lighter-weight Postgres schemas. However, schemas cannot be cloned, requiring migrations to run every time, which is where pgtestdb's approach has a potential advantage.
The initial setup time for both pgtestdb's database cloning and the schema-based approach was found to be remarkably similar, both around 100 milliseconds. This finding challenged the assumption that creating new databases would be inherently slow. Despite the similar setup times, the overall test suite using the schema-based method ran approximately 3.5 times faster. This was attributed to an optimization in River's test helpers that creates test schemas as needed for Go's parallelization.
While the River project will continue using its existing schema-based method due to its overall speed and the incidental benefit of verifying schema-based configuration, pgtestdb is recommended for users focused on end-to-end testing. Its fast database cloning capability is beneficial for scenarios where a full database environment needs to be quickly instantiated for each test.
✨ This summary was generated by AI from the outlets' reporting listed below. It is not independently verified and may contain errors — check the original sources. How BrevFeed works →
One email each morning: the day's tech stories, clustered across outlets and summarized. No account needed.
One email a day. Unsubscribe in one click, any time.
Spend a few minutes, get the whole day. Every topic's top stories in one hands-free rundown — listen, watch, or read the transcript.
▶ Play today's briefNew every morning, and the back catalogue is archived by date.
A comparison of pgtestdb, a Go/Postgres testing package utilizing Postgres template databases, found its setup time to be comparable to a schema-based testing approach. While the overall test suite using pgtestdb was slower due to other optimizations in the schema-based method, pgtestdb's database cloning is faster than migrating a test database from scratch. This matters for developers seeking efficient database testing strategies, particularly for end-to-end testing scenarios.