Pcornel
Browse topics
Options
Recent
Favorites
Databases · Technical reference

Database Memory and Disk Sizing

Direct answer

Database sizing plans memory (buffer pools, work memory), CPU, disk capacity and IOPS, and growth for data, indexes, logs and backups.

When to use this

Use it when planning a server or when a database runs out of memory or space.

First 30 seconds

1. Data size: SELECT pg_size_pretty(pg_database_size('db')); / information_schema sizes.

2. Growth trend.

3. Disk free and IOPS headroom.

4. Memory settings vs RAM.

5. Plan capacity 6–12 months ahead.

Operational verification

workload → memory/CPU/IO needs → growth → capacity plan

Context & applicabilityCommon mistakes · platform/version boundaries
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
Scope / prerequisiteUse it when planning a server or when a database runs out of memory or space.
What next?2 suggested next steps
Evidence0
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 How to verify Verify boundary

Watch cache hit ratio and disk latency under peak load. Alert at a disk free threshold that leaves time to act.

Step 2 Common failures Narrow the fault

Network storage with high latency makes commits slow even at low load. Indexes often use as much space as the data. Backups and WAL/binlog archives on the same disk fill it unexpectedly.

Key points

Measure growth per month. Leave space for maintenance (VACUUM FULL, index rebuilds) and WAL bursts. Per-query memory (work_mem, sort buffers) multiplies with connections.

Key checks
  • SELECT pg_size_pretty(pg_database_size('db')); — 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

How it works

Reads served from memory take microseconds; reads from disk take far longer. Commit latency is bounded by log flush time. Running out of disk stops writes entirely.

ReferenceImportant terms & boundaries3 sections · depth on demand

Sizing guidance

ResourceGuidance
MemoryHot data + indexes fit in cache (buffer pool, shared_buffers + OS cache)
Disk latency< 1 ms on SSD/NVMe for OLTP; separate log/WAL disk on busy systems
Disk spaceData + indexes + logs + temp + backups + 30 % headroom
CPUCores for concurrent queries; parallel query for analytics

PostgreSQL: shared_buffers ~25 % of RAM, effective_cache_size ~50–75 %. Monitor growth monthly.

In depth

Memory model

EngineShared cachePer operation / per connection
PostgreSQLshared_buffers (often ~25 % of RAM) + the OS page cache for the restwork_mem per sort/hash node, maintenance_work_mem for VACUUM/CREATE INDEX
MySQL InnoDBinnodb_buffer_pool_size (50–75 % of RAM)sort_buffer_size, join_buffer_size, temp tables per connection
SQL Servermax server memory (leave several GB for the OS)Query memory grants from the same pool

work_mem arithmetic

work_mem is allowed per sort or hash operation, per parallel worker. A query with four hash joins and a sort, run by 50 connections, can use up to 50 × 5 × work_mem. Setting work_mem = 256MB globally can therefore push the server into swap or the OOM killer under load. Keep the global value modest (for example 16–64 MB) and raise it per session or per role for reports:

ALTER ROLE reporting SET work_mem = '256MB';

Signs it is too small: Sort Method: external merge Disk: … and temp file growth in pg_stat_database.temp_bytes.

Disk

MeasureWhy
Write latency of the log device (fsync)Every commit waits for it
Random read IOPS for dataCache misses
Free space with headroomSpace for growth, temp files, index rebuilds, WAL/binlog spikes, local backups

Separate the transaction log from data files only if they really land on different physical devices; on shared cloud volumes it mostly helps with accounting and with keeping a full data disk from stopping log writes.

Growth planning

Track database size per week (pg_database_size, information_schema.TABLES), extrapolate, and alert on days-until-full rather than a fixed percentage.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

Common mistakes

  • Sizing memory without considering OS cache.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
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
database memory and disk sizingdatabase capacity planningdisk latency database
Confirmation

Confirm action

Continue?