views:

33

answers:

2

Is there a way to speed up PostgreSQL's createdb command?

Normally I wouldn't care, but doing unit testing in Django creates a database every time, and it takes about 5 seconds.

I'm using openSUSE 11.2 64-bit, PostgreSQL 8.4.2

A: 
  • If Django supported postgres schemas then you could simply drop the schema in question & recreate it instead of killing the entire database.
  • You can still use DROP OWNED BY ... CASCADE to drop all objects created by whichever user is configured in Django, bringing the database back to an essentially pristine condition. See how much faster this is.
  • You can shut down Postgres, then untar an existing database cold backup instead of running initdb. See how much faster this is.
vladr
A: 

It won't help you now, but there has been some work done around this in PostgreSQL 9.0.`

What you can try as a workaround is to run with fsync=off. Of course, don't even think about doing this if you have actual data in your database, but if it runs on a test system only, that will make your CREATE DATABASE run a lot faster.

Magnus Hagander
Just tested createdb on Postgres started with "-F" option: less than 0,2s. For unit testing fsync=off should be good.
Tometzky