Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keeping postgres entirely in memory

Tags:

postgresql

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

like image 649
bevanb Avatar asked Jul 19 '13 00:07

bevanb


1 Answers

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.

like image 56
Craig Ringer Avatar answered Sep 23 '22 21:09

Craig Ringer