One of the big slowdowns with postgres (and RDBMSs in general) is writing data to disk and ensuring data integrity. So to make that process faster, here’s a way to put a postgres db on a ram disk and turn off some of the data integrity in favour of faster operation.
So assuming /tmp has a ram fs of some kind mounted on it (tmpfs on linux, OSX has one, I’m not sure what it’s called or how to mount it):
1 2 3 4 5 6 7 8 9 10 |
|
Now tell rails where to find your db. Edit config/database.yml
to have
1 2 3 4 5 |
|
… and the test setup dance
1
|
|
Run tests fast(er). For fun say sudo iotop in another terminal to check that the
postgres processes do not write data to disks. You might also want to create
log/test.log
as a link to a file on the ramfs:
1 2 3 |
|
When you’re finished, say
1 2 |
|