PostgreSQL Performance – Running Tests Without Durability

postgresqlpostgresql-performance

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.

Best Answer

  • use UNLOGGED tables throughout

  • set shared_buffers big enough to contain the whole database

  • if you have bigger queries, increase work_mem

  • have enough RAM to contain shared_buffers plus work_mem times the number of client connections

Typically, you can gain most by tuning the queries that use most of the time.