Postgresql in memory database django
Asked Answered
S

2

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

Skelton answered 13/5, 2016 at 18:12 Comment(1)
rhaas.blogspot.co.at/2010/06/…Bill
R
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.

Russia answered 14/5, 2016 at 1:9 Comment(1)
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. ThanksSkelton
O
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.

Outbound answered 13/5, 2016 at 18:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.