The symptom
Everything got slower at once, disk I/O spiked, and the plans did not change. That is memory pressure: the pages queries need are not in the buffer cache, so every read pays for disk. The fix is measurement first - 'more RAM' is only sometimes the answer.
Diagnose it
SQL Server: buffer pool and memory clerks
SELECT type, SUM(pages_kb) / 1024 AS mb
FROM sys.dm_os_memory_clerks
GROUP BY type
ORDER BY SUM(pages_kb) DESC;
MEMORYCLERK_SQLBUFFERPOOL is the data cache. CACHESTORE_SQLCP (ad-hoc and prepared plans) growing to several gigabytes is plan cache bloat from unparameterized SQL, memory taken away from data pages; CACHESTORE_OBJCP is procedure and trigger plans. To see which databases hold the buffer pool:
SELECT COUNT(*) / 128 AS cached_mb, DB_NAME(database_id) AS database_name
FROM sys.dm_os_buffer_descriptors
GROUP BY database_id
ORDER BY cached_mb DESC;
That view has one row per 8 KB page in memory, so on a server with hundreds of gigabytes it is slow; run it off-peak. Two more signals: Page Life Expectancy from sys.dm_os_performance_counters (counter_name = 'Page life expectancy'), read as a trend rather than against a fixed number, and queries waiting for workspace memory, which show up as RESOURCE_SEMAPHORE waits and as rows in sys.dm_exec_query_memory_grants を伴う granted_memory_kb IS NULL.
PostgreSQL: buffers in the plan, cache stats in the view
EXPLAIN (ANALYZE, BUFFERS) SELECT ...;
-- Buffers: shared hit=84 all pages found in shared_buffers
-- Buffers: shared hit=7 read=4 4 pages fetched from the OS
SELECT round(blks_hit * 100.0 / nullif(blks_hit + blks_read, 0), 2) AS hit_pct
FROM pg_stat_database WHERE datname = current_database();
Persistent read= counts on a query that runs constantly are the direct evidence of pressure. Read the database-wide ratio with care: blks_read counts pages PostgreSQL asked the operating system for, and many of those come from the OS page cache, not the disk. A ratio in the low 90s on an OLTP database is worth investigating; confirm with OS disk metrics, or with track_io_timing = on, which adds I/O time to EXPLAIN and pg_stat_statements. The pg_buffercache extension (CREATE EXTENSION pg_buffercache;、スーパーユーザーまたは pg_monitor) shows which tables and indexes occupy shared_buffers.
MySQL: the buffer pool counters
SHOW GLOBAL STATUS LIKE 'Innodb_buffer_pool_read%';
-- hit% = 1 - Innodb_buffer_pool_reads / Innodb_buffer_pool_read_requests
Innodb_buffer_pool_reads counts reads InnoDB had to take from disk; both counters run from server start, so compare the change between two readings. If disk reads climb as a share of requests during the day, the pool no longer holds the working set. sys.innodb_buffer_stats_by_table shows which tables occupy the pool, but it walks every page and is expensive on a large pool.
Oracle: SGA and PGA in the dynamic views
SELECT component, round(current_size / 1024 / 1024) AS mb
FROM v$sga_dynamic_components
WHERE current_size > 0;
SELECT size_for_estimate AS cache_mb, size_factor,
estd_physical_read_factor
FROM v$db_cache_advice
WHERE name = 'DEFAULT'
AND block_size = (SELECT value FROM v$parameter WHERE name = 'db_block_size')
ORDER BY size_for_estimate;
SELECT round(pga_target_for_estimate / 1024 / 1024) AS pga_mb,
pga_target_factor, estd_pga_cache_hit_percentage, estd_overalloc_count
FROM v$pga_target_advice
ORDER BY pga_target_for_estimate;
The buffer cache advisory estimates physical reads at other cache sizes: size_factor = 1 is today's size, and if estd_physical_read_factor barely drops at 1.5 or 2, more cache will not help. In the PGA advisory, look at the row with pga_target_factor = 1: an estd_pga_cache_hit_percentage well below 100 means sorts and hashes are spilling to temp, and a non-zero estd_overalloc_count means the target is too small even for the minimum the workload needs. Sessions dominated by User I/O waits (db file sequential read for index blocks, db file scattered read for full scans) are the symptom: the cache is missing the blocks hot queries want.
Fix it
Size the main cache to the working set, not the database. Most databases have a hot subset far smaller than their total size. Measure it (the queries above show which tables and indexes actually hold cache), set the buffer pool or shared_buffers so that set fits, and leave the rest to the OS cache - PostgreSQL in particular expects hot pages to live in the OS cache too, not only in shared_buffers.
Fix waste before adding RAM. On SQL Server, a plan cache full of single-use ad-hoc plans shrinks with sp_configure 'optimize for ad hoc workloads', 1, which caches only a small stub until a statement runs a second time; parameterizing the SQL fixes the cause. On PostgreSQL, a large work_mem multiplied by many concurrent sorts and hashes can exhaust RAM - size it for the concurrency you actually have, and raise it per session or per role for the reporting jobs that need it.
Check what else shares the box. A backup agent, an app server, or another instance on the same host competes for the same RAM. Set SQL Server's max server memory so the OS and other processes keep their headroom; the default (2,147,483,647 MB, effectively unlimited) lets SQL Server take nearly everything. Setup has suggested a value since SQL Server 2019, but upgraded instances often still have the old default.
Reduce the working set itself. Narrowing the widest hot table, archiving old rows, and fixing the scans in the index guide all shrink what the cache has to hold - sometimes enough to make the sizing question disappear. When a plan shows sorts spilling to disk that did not spill before, paste it into the query plan viewer; the spilled operator is where the cache gave up.
The checklist
Work through it in order. Each step gives you the evidence for the next one.
- Measure the cache hit rate for the engine (queries above) over a peak hour.
- Find what actually holds cache: sys.dm_os_buffer_descriptors (SQL Server), the pg_buffercache extension, sys.innodb_buffer_stats_by_table (MySQL), v$db_cache_advice (Oracle).
- Separate working set from waste: single-use plans in the SQL Server plan cache and an oversized work_mem are configuration problems, not a need for RAM.
- Set the main cache to fit the measured working set with headroom.
- Bound SQL Server memory with max server memory if anything else runs on the host.
- Re-measure the hit rate the next peak: disk reads should fall to near-zero for hot paths.
- If the working set genuinely does not fit, archive data or add RAM - in that order.
Questions that come up
Is a low page life expectancy always bad?
No. PLE drops whenever something reads a lot of new pages - an index rebuild, a big report, a restore - and climbs back afterwards. The old 300-second rule of thumb dates from servers with 4 GB of RAM and means little on a large buffer pool. On NUMA hardware, check the per-node values under Buffer Node as well. What matters is a persistently falling PLE on a server with steady I/O wait - that means the cache cannot hold the working set. Judge it alongside the I/O waits, never alone.
How big should shared_buffers be on PostgreSQL?
The classic starting point is 25% of RAM on a dedicated database server, with the OS cache holding much of the rest - PostgreSQL reads through the OS cache anyway. The right number is the one that fits the measured working set; check the hit rate from pg_stat_database after each change instead of following folklore.
Can work_mem cause out-of-memory crashes?
Yes. work_mem is a limit per sort or hash operation, not per query: a query with five sorts can use five times the setting, each parallel worker gets its own allowance, and hash operations may use work_mem x hash_mem_multiplier (2.0 by default since PostgreSQL 15). Multiply by concurrent sessions and a generous setting can exceed RAM. On Linux the OOM killer then kills a backend and the postmaster restarts every session; vm.overcommit_memory = 2 makes the failing query get an out-of-memory error instead.
The hit rate is 99% but users still report slowness. Is memory still the problem?
Probably not. A 99% hit rate means the cache is doing its job; the slowness is in the remaining 1% (an unlucky scan), in lock waits, or in CPU-bound per-row work. Follow the slow query and blocking guides before touching memory sizing.
Where does memory sizing interact with query plans?
Undersized memory forces sorts and hashes to spill to disk, which shows in plans as spill or temp-buffer operators and can be orders of magnitude slower. If plans suddenly show spills that were not there before, memory pressure changed the plan's cost - fix the memory or the query's sort size, and the plan returns to normal.