Activity.Search: fallback on status resolution on DB Timeout
[akkoma] / docs / configuration / postgresql.md
1 # Optimizing PostgreSQL performance
2
3 Pleroma performance is largely dependent on performance of the underlying database. Better performance can be achieved by adjusting a few settings.
4
5 ## PGTune
6
7 [PgTune](https://pgtune.leopard.in.ua) can be used to get recommended settings. Be sure to set "Number of Connections" to 20, otherwise it might produce settings hurtful to database performance. It is also recommended to not use "Network Storage" option.
8
9 ## Disable generic query plans
10
11 When PostgreSQL receives a query, it decides on a strategy for searching the requested data, this is called a query plan. The query planner has two modes: generic and custom. Generic makes a plan for all queries of the same shape, ignoring the parameters, which is then cached and reused. Custom, on the contrary, generates a unique query plan based on query parameters.
12
13 By default PostgreSQL has an algorithm to decide which mode is more efficient for particular query, however this algorithm has been observed to be wrong on some of the queries Pleroma sends, leading to serious performance loss. Therefore, it is recommended to disable generic mode.
14
15
16 Pleroma already avoids generic query plans by default, however the method it uses is not the most efficient because it needs to be compatible with all supported PostgreSQL versions. For PostgreSQL 12 and higher additional performance can be gained by adding the following to Pleroma configuration:
17 ```elixir
18 config :pleroma, Pleroma.Repo,
19 prepare: :named,
20 parameters: [
21 plan_cache_mode: "force_custom_plan"
22 ]
23 ```
24
25 A more detailed explaination of the issue can be found at <https://blog.soykaf.com/post/postgresql-elixir-troubles/>.
26
27 ## Example configurations
28
29 Here are some configuration suggestions for PostgreSQL 10+.
30
31 ### 1GB RAM, 1 CPU
32 ```
33 shared_buffers = 256MB
34 effective_cache_size = 768MB
35 maintenance_work_mem = 64MB
36 work_mem = 13107kB
37 ```
38
39 ### 2GB RAM, 2 CPU
40 ```
41 shared_buffers = 512MB
42 effective_cache_size = 1536MB
43 maintenance_work_mem = 128MB
44 work_mem = 26214kB
45 max_worker_processes = 2
46 max_parallel_workers_per_gather = 1
47 max_parallel_workers = 2
48 ```