logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

postgresql.md (2112B)


  1. # Optimizing PostgreSQL performance
  2. Pleroma performance is largely dependent on performance of the underlying database. Better performance can be achieved by adjusting a few settings.
  3. ## PGTune
  4. [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.
  5. ## Disable generic query plans
  6. 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.
  7. 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.
  8. 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:
  9. ```elixir
  10. config :pleroma, Pleroma.Repo,
  11. prepare: :named,
  12. parameters: [
  13. plan_cache_mode: "force_custom_plan"
  14. ]
  15. ```
  16. A more detailed explanation of the issue can be found at <https://blog.soykaf.com/post/postgresql-elixir-troubles/>.
  17. ## Example configurations
  18. Here are some configuration suggestions for PostgreSQL 10+.
  19. ### 1GB RAM, 1 CPU
  20. ```
  21. shared_buffers = 256MB
  22. effective_cache_size = 768MB
  23. maintenance_work_mem = 64MB
  24. work_mem = 13107kB
  25. ```
  26. ### 2GB RAM, 2 CPU
  27. ```
  28. shared_buffers = 512MB
  29. effective_cache_size = 1536MB
  30. maintenance_work_mem = 128MB
  31. work_mem = 26214kB
  32. max_worker_processes = 2
  33. max_parallel_workers_per_gather = 1
  34. max_parallel_workers = 2
  35. ```