Automated tuning is only useful when it understands the workload. The same work_mem value can be conservative for an analytical system with a few sessions and dangerous for OLTP with hundreds of concurrent operations. Recommendations must start by classifying how PostgreSQL is actually used.
The risk of generic PostgreSQL tuning
Static lists often begin with RAM percentages and end without measuring queries, concurrency, temporary files, WAL, or storage latency. Those values may be laboratory starting points, but they do not prove that a production change is safe.
shared_bufferscoexists with operating-system page cache.work_memcan be consumed several times by one query and its parallel workers.max_connectionsis a ceiling, not a target for useful concurrency.- WAL and checkpoint decisions must respect disk capacity and recovery objectives.
OLTP and OLAP require different decisions
OLTP workloads
- Many short transactions and high concurrency.
- Sensitive to locks, connection overhead, and per-operation latency.
- Selective indexes and predictable query paths matter greatly.
- The global
work_membudget usually needs to remain conservative.
OLAP workloads
- Fewer queries with larger scans, joins, sorts, and hashes.
- More opportunity for controlled session memory and parallelism.
- Report throughput may matter more than transactional latency.
- Partitioning, statistics, and I/O behavior carry more weight.
Real systems are often hybrid. An OLTP service may run heavy reports during business hours; role- or session-level settings are frequently safer than a global increase.
Signals that classify a workload
Classification should use history rather than one snapshot. Useful signals include:
- duration, calls, and total time per
pg_stat_statementsfingerprint; - the relationship between commits, reads, inserts, updates, and deletes;
- active connections, waits, locks, and long transactions;
- temporary files, parallel operations, and disk spills;
- WAL rate, checkpoints, autovacuum, and per-table behavior;
- CPU, memory, and storage latency over the same interval.
Turn classification into a reviewable recommendation
A responsible recommendation states the current value, proposed scope, evidence, expected impact, risk, parameter context, success metric, and rollback. It also distinguishes reloadable settings from those that require restart.
Parameter: work_mem
Hypothesis: important sorts are writing temporary files
Initial scope: reporting role, not the global value
Evidence: temp_blks_written and representative EXPLAIN plans
Validation: p95 latency, temp bytes, memory, and concurrency
Rollback: restore the previous role setting
Why work_mem needs concurrency context
Dividing memory by max_connections ignores operations and workers. A useful budget estimates simultaneous heavy queries, sort or hash operations per query, and parallelism. The result is still a starting limit that must be validated under representative load.
Use the Configuration Planner to model those factors and read the complete PostgreSQL tuning guide for the baseline, test, and rollback process.
Automation should recommend without hiding risk
A tool can reduce the work of correlating metrics, but critical changes still need review. A recent deployment, open incident, connection pressure, low disk headroom, or missing baseline are valid reasons to defer an otherwise plausible change.
PG Monitoring classifies workload patterns and presents configuration recommendations alongside operational signals. The evidence remains visible so the team can evaluate timing and decide how the result will be measured.
Next step
Monitor recurring problems across time. If production is already degraded and the investigation must connect queries, plans, configuration, and infrastructure, explore our PostgreSQL tuning consulting service.