@cryptotaxi247 / infra / commits / 9d4cded1

mimas: tune postgresql

Adapt worker size, allow more memory use, disable JIT, enable io_uring.

Martin Weinelt committed Jul 16, 2026 at 22:38 UTC 9d4cded16965cceb6d7752f592d3586cc768e137
1 file changed +26 -19
build/mimas/postgresql.nix
+26 -19
@@ -20,13 +20,14 @@
20
21 services.postgresql = {
22 enable = true;
23 - enableJIT = true;
23 package = pkgs.postgresql_18;
24 # https://pgtune.leopard.in.ua/#/
25 + # https://vadosware.io/post/everything-ive-seen-on-optimizing-postgres-on-zfs-on-linux/#zfs-related-tunables-on-the-postgres-side
26 settings = {
27 - # https://vadosware.io/post/everything-ive-seen-on-optimizing-postgres-on-zfs-on-linux/#zfs-related-tunables-on-the-postgres-side
27 + # no page tearing on ZFS
28 full_page_writes = "off";
29
30 + # avoid zero-filling with ZFS
31 wal_init_zero = "off";
32 wal_recycle = "off";
33
@@ -47,37 +48,43 @@
48 log_autovacuum_min_duration = 0;
49 log_line_prefix = "user=%u,db=%d,app=%a,client=%h ";
50
50 - max_connections = 500;
51 - work_mem = "20MB";
52 - maintenance_work_mem = "2GB";
51 + max_worker_processes = 48;
52 + max_parallel_workers_per_gather = 4;
53 + max_parallel_workers = 48;
54 + max_parallel_maintenance_workers = 4;
55 +
56 + max_connections = 100;
57 + work_mem = "150MB";
58 + maintenance_work_mem = "8GB";
59
60 # 25% of memory
61 shared_buffers = "32GB";
62
57 - # Checkpoint every 1GB. (default)
58 - # increased after seeing many warnings about frequent checkpoints
63 + # Reduce WAL file creation churn
64 min_wal_size = "1GB";
65 max_wal_size = "4GB";
66 +
67 + # Shared memory allocation before writing WAL to disk
68 wal_buffers = "16MB";
69
63 - max_worker_processes = 32;
64 - max_parallel_workers_per_gather = 4;
65 - max_parallel_workers = 32;
70 + # Async I/O over shared ringbuffer with the kernel
71 + io_method = "io_uring";
72
73 # NVMe related performance tuning
68 - effective_io_concurrency = 200;
74 + effective_io_concurrency = 1000;
75 random_page_cost = "1.1";
76
71 - # We can risk losing some transactions.
72 - synchronous_commit = "off";
77 + # query planner estimate for memory available for disk caching
78 + effective_cache_size = "96GB";
79
74 - effective_cache_size = "64GB";
80 + # With ZFS we can risk losing some transactions.
81 + synchronous_commit = "off";
82
76 - # try to allocate huge pages, if possible
83 + # Try to allocate huge pages, if possible
84 huge_pages = "try";
85
79 - # Enable JIT compilation if possible.
80 - jit = "on";
86 + # Only useful for long-running CPU-bound queries
87 + jit = "off";
88
89 # autovacuum and autoanalyze much more frequently:
90 # at these values vacuum should run approximately
@@ -86,8 +93,8 @@
93 # benefit from frequent vacuums, so this should
94 # help. In particular, I'm thinking the jobsets
95 # pages.
89 - autovacuum_vacuum_scale_factor = 0.02;
90 - autovacuum_analyze_scale_factor = 0.01;
96 + autovacuum_vacuum_scale_factor = 0.02; # down from 0.2
97 + autovacuum_analyze_scale_factor = 0.01; # down from 0.1
98
99 shared_preload_libraries = "pg_stat_statements";
100 compute_query_id = "on";