Hacker News new | ask | show | jobs
by williamdclt 1016 days ago
I was surprised but CREATE DATABASE TEMPLATE is still pretty slow, a few hundred ms on my machine. Better than alternatives though.

A few more application-level optimisations: if you need to clear your database between tests, the best way is to wrap each test in a transaction and roll it back (Postgres supports nested transactions with checkpoints which might help make that transparent to the application under test). The second best way is usually to use DELETE rather than TRUNCATE, the latter is much slower on small tables (but much faster on big ones). The third fastest way is to create a new DB from template, although it plays nice with parallelisation.