8

I am running various tests that spend a lot of time in the database.

I'd like to keep it all in memory and have it not touch the db, hopefully that would speed things up. Like using sqlite3's in-memory option. I don't need persistence/durability/whatnot, everything is immediately discarded after the test.

Is that possible? I tried tweaking my postgres memory-related vars (as in the solution below), but that doesn't seem to affect the number of db writes it performs, and I couldn't find anything that looks like an 'in-memory' option.

https://dba.stackexchange.com/questions/18484/tuning-postgresql-for-large-amounts-of-ram

14
  • 1
    It's impossible to achieve durability without writing to disk and actually waiting for it to finish. Commented Jul 19, 2013 at 0:15
  • @branko That makes sense. I don't need durability in this case. Commented Jul 19, 2013 at 0:17
  • If you don't need persistence, what do you need the database for? Commented Jul 19, 2013 at 0:20
  • 1
    @branko I just need it to persist for the duration of the test, in memory :) Commented Jul 19, 2013 at 0:21
  • You don't need a database for that. Commented Jul 19, 2013 at 0:22

1 Answer 1

11

I wrote a detailed post on this some time ago:

Optimise PostgreSQL for fast testing

You may find it informative; it covers options for making PostgreSQL run without durability and other tweaks that're useful for running tests.

You do not actually need in-memory operation. If PostgreSQL is set not to flush changes to disk then in practice there'll be little difference for DBs that fit in RAM, and for DBs that don't fit in RAM it won't crash.

You should test with the same database engine you're using in production. Testing with SQLite, Derby, H2, etc then deploying live on PostgreSQL doesn't make tons of sense... as any Heroku/Rails user can tell you from experience.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.