Svan
Svan

Reputation: 111

Postgresql in memory database django

For performance issues I would like to execute an optimization algorithm on an in memory database in django (I'm likely to execute a lot of queries). I know it's possible to use a sqlite in memory (How to run Django's test database only in memory?) but I would rather use postgresql because our prod database is a postgresql one.

Does someone knows how to tell django to create the postgresql database in the memory ?

Thanks in advance

Upvotes: 9

Views: 4509

Answers (2)

e4c5
e4c5

Reputation: 53734

This is premature optimization. Postgresql is very very fast even if you are running it on a cold metal hard disk provided you use the right indexes. If you don't persist the data on disk, you are opening yourself upto a world of pain.

If on the other hand you want to speed up your tests by running an in memory postgresql database you can try something like these non durability optimizations:

http://www.postgresql.org/docs/9.1/static/non-durability.html

The most drastic suggestion is to use a ramdisk on that page. Here's how to set up one. After following the OS/Postgresql steps edit django settings.py and add the tablespace to the DATABASES section.

Last but not least: This is just a complete waste of time.

Upvotes: 8

Jamie Counsell
Jamie Counsell

Reputation: 8113

This is not possible. You cannot use PostgreSQL exclusively in memory; at least not without defeating the purpose of using PostgreSQL over something else. An in-memory data store like Redis running alongside PostgreSQL is the best you can do.

Also, at this point, the configuration is far out of Django's hands. It will have to be done outside of Django's environment.

It appears you may be missing some understanding about how these systems work. Build your app first to verify that everything is working, then worry about optimizing the database in such ways.

Upvotes: 1

Related Questions