unit testing with in-memory database

Lucas Smith picture Lucas Smith · Aug 1, 2012 · Viewed 8.5k times · Source

I have PostgreSQL database. It is used for unit testing.

  • I want to speed the tests up so I want to use some kind of in-memory databases (e.g. H2).
  • I want to dump the database (from PostgreSQL) and the import such a dump into in-memory database.

Do you have any suggestion concerning in-memory database choice? I want that database to be compatible with PostgreSQL.

Answer

Tometzky picture Tometzky · Aug 1, 2012

I'd simply create a database directory (called a cluster in PostgreSQL) in tmpfs (essentially a RAM-disk - /dev/shm is configured as such in most Linux distributions) and simply run postgres there on non-standard port, for example like this:

initdb -D /dev/shm/pgtest
postmaster -D /dev/shm/pgtest -p 11111