Pcornel
Browse topics
Options
Recent
Favorites
Databases · Technical reference

Performance & Capacity

Direct answer

Database performance and capacity: query efficiency, connections, memory (buffer pools), I/O, locks and growth of data and logs.

When to use this

Use it when a database is slow or approaching limits.

First 30 seconds

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.

Operational verification

workload → queries → waits (CPU, I/O, locks) → resources

Evidence · next step

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
Common mistakes
What not to infer

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.

Platform / version applicability
MariaDB / MySQL / PostgreSQL / Microsoft SQL Server concepts
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformMariaDB / MySQL / PostgreSQL / Microsoft SQL Server concepts · 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.
Scope / prerequisiteUse it when a database is slow or approaching limits.
What next?3 suggested next steps
Child topics (this level)3
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

2 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

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 references

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.

test · 1
Drill down

Subtopics

Go one level deeper into this subject.

Key points

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.

Key checks
  • SELECT query,calls,total_exec_time FROM pg_stat_statements ORDER BY total_exec_time DESC LIMIT 10; — first check for this topic
  • psql -c "SELECT now(), version();" — PostgreSQL reachable and version
  • mysql -e "SELECT NOW(), VERSION();" — MariaDB/MySQL reachable and version
  • sqlcmd -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.

AreaWhat to watch
QueriesTop queries by total time (pg_stat_statements, Performance Schema, Query Store)
MemoryBuffer/cache hit ratio, working set vs RAM
I/ORead/write latency, IOPS, WAL/log throughput
ConnectionsActive vs max, pooling
Locks and waitsBlocking, wait statistics
GrowthDatabase 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
Technical examples

Configuration & expected output

Concrete examples are shown only when the stored reference contains an actual configuration or output shape for this Topic.

Configuration example

PostgreSQL PostgreSQL 14 or laterFind the queries that use the most total time.

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

PostgreSQL PostgreSQL 14 or laterSELECT 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.
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-29 · otherMariaDB / PostgreSQL / Microsoft SQL Server concepts PostgreSQL current documentation

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%
Technical changelog & impact

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.

Related reference impactReview these references after material technical changes when their shared boundary is affected.
Terminology layer

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.

Aliases that resolve here
performance & capacitydatabase performanceslow query troubleshootingdatabase capacity planning
Embedded reference data

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.

BoundaryInspectHealthy interpretationDo not infer
IntentCPU, memory and storage-I/O symptomsIntended object/scope is explicit and versioned where relevantIntent is already effective
Owning runtime/control planeBuffer/cache behavior / Connection saturationOwner accepts and reports the expected object stateDownstream dependencies are healthy
Effective stateSlow queriesIndependent read-back matches the intended stateEvery client sees the same result
Consumer outcomeQuery-plan driftThe original bounded check succeeds in the same time windowProduction correctness outside this scope
Depth when you need it

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.

Confirmation

Confirm action

Continue?