Our Django tests are getting slow, and a lot of time is spend in cursor.execue()
.
There are roughly two ways now: Rewrite the tests to mock the ORM, or make PostgreSQL faster.
This question is about "make PostgreSQL faster".
What can I do to improve PostgreSQL speed if D (Durability) of ACID is not important. Everything could be kept in RAM.
Constraint: This question is about what you can do without modifying the Django/Python/SQL code.
1 Answer 1
use
UNLOGGED
tables throughoutset
shared_buffers
big enough to contain the whole databaseif you have bigger queries, increase
work_mem
have enough RAM to contain
shared_buffers
pluswork_mem
times the number of client connections
Typically, you can gain most by tuning the queries that use most of the time.
-
If the data isn't important, turning off
fsync
will probably speed up things as welluser1822– user18222021年03月02日 13:30:51 +00:00Commented Mar 2, 2021 at 13:30 -
@a_horse_with_no_name For unlogged tables that won't make much difference.Laurenz Albe– Laurenz Albe2021年03月02日 13:59:15 +00:00Commented Mar 2, 2021 at 13:59
-
But the unlogged tables require changing the SQL scripts that setup the database, whereas turning off fsync requires no changes to the schema migration scriptsuser1822– user18222021年03月02日 14:00:28 +00:00Commented Mar 2, 2021 at 14:00
-
1@a_horse_with_no_name True. But then I'd set
synchronous_commit = off
rather than the dreadedfsync
. Bypassing WAL altogether with unlogged table should perform best of all.Laurenz Albe– Laurenz Albe2021年03月02日 14:13:04 +00:00Commented Mar 2, 2021 at 14:13 -
I love PG, since the docs are great. Now I found an official page which exactly this topic postgresql.org/docs/current/non-durability.htmlguettli– guettli2021年03月03日 06:58:22 +00:00Commented Mar 3, 2021 at 6:58
EXPLAIN ANALYZE
, and the database schema, likely we can recommend ways to improve them.