Use it when a database is slow or approaching limits.
Performance & Capacity
Database performance and capacity: query efficiency, connections, memory (buffer pools), I/O, locks and growth of data and logs.
1. Top queries by total time: SELECT query,calls,total_exec_time FROM pg_stat_statements ORDER BY total_exec_time DESC LIMIT 10; / Query Store.
2. Waits: SELECT * FROM sys.dm_os_wait_stats ORDER BY wait_time_ms DESC; / blocking views.
3. Buffer/cache hit ratio.
4. Disk latency and space.
5. Connection count vs limit.
workload → queries → waits (CPU, I/O, locks) → resources
Common errors are tuning from one host metric, raising connection limits without memory analysis, adding indexes without write-cost review, ignoring plan/statistics drift, allowing log/temp/data volumes to fill and assuming high cache hit rate means queries are efficient. Preserve the first divergent observation and repeat the same bounded verification after remediation.
Continue only after interpreting the current observation.Context & applicabilityCommon mistakes · platform/version boundaries
Databases owns engine waits, plans, connection/cache behavior and data-file growth. Observability owns durable telemetry pipelines; Storage owns physical I/O devices and filesystems.
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Verification workflow Verify boundary
Start with workload latency/throughput and wait/engine diagnostics for the same interval. Correlate slow queries, locks, connections, CPU, cache hit/memory pressure, temp spills and storage latency. Compare plan/runtime changes before tuning global settings or adding hardware.
Step 2 Failure signatures and limits Narrow the fault
Common errors are tuning from one host metric, raising connection limits without memory analysis, adding indexes without write-cost review, ignoring plan/statistics drift, allowing log/temp/data volumes to fill and assuming high cache hit rate means queries are efficient.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
Subtopics
Go one level deeper into this subject.
The slow query log records statements that take longer than a threshold, so you can find and fix the queries that cost the most.
Subtopic Database Memory and Disk SizingDatabase performance depends on keeping the working set in memory and having storage with enough IOPS and low latency for writes.
Subtopic Table PartitioningPartitioning splits a large table into smaller pieces by a key such as date, so queries and maintenance can work on one piece at a time.
Find the top queries by total time first (pg_stat_statements, Performance Schema, Query Store). Then check waits, memory hit ratios and I/O latency. Plan capacity from growth trends.
SELECT query,calls,total_exec_time FROM pg_stat_statements ORDER BY total_exec_time DESC LIMIT 10;— first check for this topicpsql -c "SELECT now(), version();"— PostgreSQL reachable and versionmysql -e "SELECT NOW(), VERSION();"— MariaDB/MySQL reachable and versionsqlcmd -S <server> -Q "SELECT @@VERSION"— SQL Server reachable and version
ReferenceWhat it is1 section · depth on demand
Operating model
Performance & Capacity treats database latency as a queue of possible constraints: query/plan work, locks, connection pressure, CPU, memory/cache behavior, temporary work and storage I/O. Capacity planning also includes data/log growth and maintenance headroom, not only current database size.
ReferenceHow it works1 section · depth on demand
In depth
Database performance and capacity management keeps response times acceptable as data and load grow. Most problems come from a few expensive queries, missing indexes, insufficient memory for the working set, or contention — not from the database engine itself.
| Area | What to watch |
|---|---|
| Queries | Top queries by total time (pg_stat_statements, Performance Schema, Query Store) |
| Memory | Buffer/cache hit ratio, working set vs RAM |
| I/O | Read/write latency, IOPS, WAL/log throughput |
| Connections | Active vs max, pooling |
| Locks and waits | Blocking, wait statistics |
| Growth | Database and table size trends, free disk |
Method: measure first (find the queries that consume the most total time), fix with indexes or query changes, re-measure. Plan capacity from growth trends — databases filling their disk is one of the most avoidable outages.
ReferenceImportant terms & boundaries1 section · depth on demand
Scope map
- CPU, memory and storage-I/O symptoms
- Buffer/cache behavior
- Connection saturation
- Slow queries
- Query-plan drift
- Temp/sort pressure
- Growth and free-space monitoring
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Configuration & expected output
Concrete examples are shown only when the stored reference contains an actual configuration or output shape for this Topic.
Configuration example
Assumptions: pg_stat_statements is in shared_preload_libraries and the extension is created.
# postgresql.conf
shared_preload_libraries = 'pg_stat_statements'
-- in the database
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
SELECT calls, round(total_exec_time) AS total_ms, round(mean_exec_time,1) AS mean_ms, left(query,60)
FROM pg_stat_statements ORDER BY total_exec_time DESC LIMIT 5;Expected output
SELECT calls, round(mean_exec_time,1) AS mean_ms, left(query,40) FROM pg_stat_statements ORDER BY total_exec_time DESC LIMIT 3;Expected state: The top statements are known, and their mean time is within the service target.
calls | mean_ms | left
--------+---------+------------------------------------------
812344 | 0.4 | SELECT * FROM orders WHERE customer_id =
1203 | 310.2 | SELECT date_trunc($1, created_at), sum(
48210 | 6.8 | UPDATE inventory SET qty = qty - $1 WHE
(3 rows)Optimise by total time, not only by the slowest single query: many fast calls can cost more than one slow report. Illustrative authored output: field layout matches the tool, values will differ in your environment.Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Documentation verification: confirms the upstream model used by the Topic. It does not assert local production behavior.
Basis: https://www.postgresql.org/docs/current/performance-tips.html · confidence 92%What changed and what may be affected
Recent technical edits are separated from ordinary page timestamps. Relationship impact is advisory: it identifies nearby canonical references to review, not automatic breakage.
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.
Quick lookup tables
Performance & Capacity verification boundary matrix
A compact lookup separating intent, owning component state, effective state and consumer-visible outcome for Performance & Capacity.
| Boundary | Inspect | Healthy interpretation | Do not infer |
|---|---|---|---|
| Intent | CPU, memory and storage-I/O symptoms | Intended object/scope is explicit and versioned where relevant | Intent is already effective |
| Owning runtime/control plane | Buffer/cache behavior / Connection saturation | Owner accepts and reports the expected object state | Downstream dependencies are healthy |
| Effective state | Slow queries | Independent read-back matches the intended state | Every client sees the same result |
| Consumer outcome | Query-plan drift | The original bounded check succeeds in the same time window | Production correctness outside this scope |
Deep reference
Design & tradeoffs
Scope
Databases owns engine waits, plans, connection/cache behavior and data-file growth. Observability owns durable telemetry pipelines; Storage owns physical I/O devices and filesystems.