9

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

1

2 Answers 2

8

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.

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

1 Comment

You are perhaps right, it could be premature optimization. On a first time I will work without. Later when my algo will be ok, I'll try to see whether I get some gain or not. Thanks
1

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.

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.