Tuning databases on 256 GB to 2 TB dedicated servers requires shifting focus from raw RAM capacity to NUMA memory locality, Linux hugepage allocation, and dirty-page writeback pacing. Allocate 25-40% of RAM to PostgreSQL shared_buffers (with HugePages) or 60-75% to MySQL innodb_buffer_pool_size across multiple buffer pool instances, disable Transparent Huge Pages (THP), and clamp vm.dirty_background_bytes so checkpoint flushes never saturate NVMe queues.
Default configuration templates packaged with PostgreSQL, MySQL, and Redis assume modest 4 GB to 16 GB virtual machines. Deploying those stock settings on a dual-socket 512 GB bare-metal server wastes 90% of installed DRAM—or worse, blindly raising buffers without tuning Linux virtual memory (vm.dirty_*) and NUMA interleaving triggers multi-second checkpoint stalls, TLB cache thrashing, and Out-Of-Memory (OOM) kills under peak write bursts.
Pin 2 MB explicit HugePages and avoid remote-socket memory penalties.
Byte-capped vm.dirty_bytes eliminates 30-second Linux kernel fsync stalls.
Calibrate shared_buffers, InnoDB pools, and Redis RDB fork headroom.
Linux Virtual Memory, NUMA Topology, and HugePages Foundations
Effective high-memory database server tuning starts in the Linux kernel before touching database configuration files. On multi-socket servers—whether comparing Intel Xeon or AMD EPYC dedicated server architectures—memory is partitioned into Non-Uniform Memory Access (NUMA) nodes. If a database process fills Node 0 completely with OS page cache while trying to allocate buffers locally, the kernel either stalls in direct reclaim or silently spills allocations across the UPI/Infinity Fabric interconnect, adding 30-50% memory latency.
Why Percentage-Based vm.dirty_ratio Fails Above 128 GB RAM
Linux’s default vm.dirty_background_ratio=10 and vm.dirty_ratio=20 were designed decades ago. On a 512 GB server, 20% equals over 100 GB of unflushed dirty pages accumulating in RAM before the kernel blocks writers for synchronous flush. Even fast enterprise NVMe vs. SATA SSD dedicated server storage arrays hit tail-latency cliffs when 50-100 GB dumps into the controller simultaneously. Always override ratios with fixed byte caps (vm.dirty_background_bytes and vm.dirty_bytes).
Explicit HugePages vs. Transparent Huge Pages (THP)
Managing a 256 GB buffer pool using standard 4 KB pages produces over 67 million page table entries, overwhelming the CPU Translation Lookaside Buffer (TLB). PostgreSQL should use explicit static 2 MB HugePages (huge_pages = on), whereas Linux Transparent Huge Pages (THP) must be set to never or madvise because background THP compaction causes severe latency spikes in Redis, MySQL, and PostgreSQL.
PostgreSQL, MySQL (InnoDB), and Redis Memory Allocation Matrix
Each engine utilizes operating system page cache differently. PostgreSQL relies heavily on the Linux OS page cache alongside shared_buffers, whereas InnoDB bypasses OS page cache via O_DIRECT, and Redis stores its entire dataset in private heap memory requiring 50% copy-on-write safety headroom during snapshots.
| Parameter / Subsystem | PostgreSQL 16/17 | MySQL 8.0 / MariaDB InnoDB | Redis 7.x |
|---|---|---|---|
| Primary Buffer Share | shared_buffers: 25-40% RAM |
innodb_buffer_pool_size: 60-75% RAM |
maxmemory: 45-60% RAM (if RDB/AOF on) |
| OS Page Cache Role | Critical (effective_cache_size = 75% RAM) |
Minimal (use innodb_flush_method=O_DIRECT) |
Used during fork() RDB/AOF rewrites |
| Per-Connection / Sort RAM | work_mem (16-64 MB) × active ops |
sort_buffer_size / join_buffer_size (2-8 MB) |
Single-threaded main loop + io-threads |
| HugePages Policy | Static 2 MB HugePages (huge_pages=on) |
Large pages optional; THP never |
THP strictly never (prevents fork lag) |
| NUMA Strategy | numactl --interleave=all on multi-socket |
innodb_numa_interleave=ON |
Pin shard instance per single NUMA node |
Production PostgreSQL & MySQL InnoDB Configuration Recipes
As detailed in the PostgreSQL Resource Consumption documentation, shared_buffers should be paired with effective_io_concurrency (set to 200-300 for NVMe arrays), generous max_wal_size (16-64 GB) to stretch checkpoints across 15-30 minutes, and conservative work_mem so concurrent hash joins do not trigger OOM events. On MySQL 8.0, splitting innodb_buffer_pool_instances (8-32 instances) reduces mutex contention across CPU cores, while dedicated NVMe RAID 10 for database servers absorbs parallel redo-log writes.
# /etc/sysctl.d/99-db-highmem.conf (Example for 512 GB RAM NVMe DB Server)
vm.swappiness = 1
vm.overcommit_memory = 1 # Required for Redis BGSAVE fork(); use 0 or 2 on strict PG hosts
vm.dirty_background_bytes = 268435456 # 256 MB
vm.dirty_bytes = 1073741824 # 1 GB max dirty buffer before synchronous throttling
vm.zone_reclaim_mode = 0
# Calculate exact HugePages for PostgreSQL: (shared_buffers_kB / 2048) + 10% margin
vm.nr_hugepages = 68000 # ~136 GB reserved for 128 GB shared_buffers
# postgresql.conf key overrides (512 GB RAM, 32+ cores, NVMe)
shared_buffers = 128GB
huge_pages = on
effective_cache_size = 384GB
work_mem = 32MB
maintenance_work_mem = 2GB
max_wal_size = 32GB
checkpoint_completion_target = 0.9
random_page_cost = 1.1
effective_io_concurrency = 200
Redis High-Memory Safety: RDB Forks, Copy-on-Write, and NUMA Pinning
Because Redis executes commands on a single primary event loop (with optional I/O threads for socket reads/writes), a 512 GB server running one massive 300 GB Redis process suffers three bottlenecks: cross-NUMA latency, multi-minute RDB serialization, and catastrophic copy-on-write (CoW) memory doubling during BGSAVE or AOF rewrites. Instead, shard Redis into multiple independent processes—one per physical CPU core or NUMA node—capped at 32-64 GB each.
- Disable THP Permanently: Add a systemd unit setting
/sys/kernel/mm/transparent_hugepage/enabledanddefragtonever; THP forces 2 MB CoW copies instead of 4 KB pages during Redis forks. - Reserve 40-50% RAM Headroom: Heavy write traffic during an RDB snapshot can duplicate modified pages via CoW before the child exits.
- Set
vm.overcommit_memory=1on Redis Nodes: Prevents Linux from rejectingfork()even when virtual address space exceeds physical RAM. - Protect from Linux OOM Killer: Set
OOMScoreAdjust=-900in the PostgreSQL/MySQL systemd drop-in while keeping tight connection limits via PgBouncer or ProxySQL.
Rollback & Safety Precaution: Allocating vm.nr_hugepages locks memory out of the normal Linux page pool immediately. If you miscalculate and reserve more HugePages than physical RAM leaves for the OS and worker connections, SSH or database workers will fail to allocate memory. Always test sysctl and shared_buffers changes on a staging host, verify HugePages_Free in /proc/meminfo, and keep an out-of-band console open before applying persistent sysctl reloads.
Validating Memory Tuning Under Synthetic and Live Telemetry
Never declare a high-memory tuning pass complete based solely on idle startup. Observe system behavior under sustained checkpoint and compaction load before opening production traffic:
- Check NUMA Balance: Run
numastat -p $(pgrep -n postgres)to confirm allocations distribute evenly across sockets withoutnuma_missspikes. - Verify HugePages Consumption: Inspect
grep -i huge /proc/meminfoafter service restart to ensureHugePages_Total - HugePages_Freematches your database buffer allocation. - Measure p99 Write Latency During Checkpoints: Run
pgbenchorsysbenchat 2× expected write IOPS while watchingiostat -xz 1forawaitspikes. - Audit Connection Pooling: Confirm PgBouncer or application connection pools cap active backend processes (typically 2-4× CPU cores) so per-connection
work_memnever multiplies uncontrollably.
Frequently Asked Questions
Why shouldn't I give PostgreSQL 80% of RAM for shared_buffers?
Unlike MySQL InnoDB, PostgreSQL writes through the Linux OS page cache. Setting shared_buffers above 40% causes double-buffering (the same data cached in both shared_buffers and OS cache) and bloats background writer and checkpoint overhead.
Why does Redis recommend disabling Transparent Huge Pages (THP)?
During BGSAVE or AOF rewrite, Redis forks a child process. With 4 KB pages, a single key modification copies 4 KB via Copy-on-Write; with 2 MB THP, each random key write forces the kernel to copy an entire 2 MB block, spiking latency and memory usage.
What does vm.dirty_bytes=1073741824 accomplish on a 512 GB server?
It forces the Linux kernel to throttle dirty page accumulation at 1 GB instead of waiting for 20% of RAM (~102 GB) to turn dirty, ensuring NVMe SSDs flush data smoothly without 30-second fsync freezes.
Should I enable Linux swap on a high-memory database server?
Keep a small emergency swap partition (4-8 GB) with vm.swappiness=1 rather than disabling swap completely. Having minimal swap allows the kernel to page out truly cold daemon memory instead of abruptly invoking the OOM killer during brief spikes.
How many innodb_buffer_pool_instances should MySQL 8.0 use?
For buffer pools larger than 16 GB, set innodb_buffer_pool_instances to 8-32 (never exceeding physical CPU cores) so multiple threads can scan and flush hash tables concurrently without hitting a global buffer pool mutex.
When is numactl –interleave=all necessary?
On multi-socket Xeon or EPYC servers where a single PostgreSQL or MySQL instance spans more RAM than one NUMA node holds, interleaving distributes pages round-robin across sockets to prevent Node 0 exhaustion and sudden kernel swap storms.
Run PostgreSQL, MySQL, and Redis on dedicated bare-metal nodes engineered with enterprise NVMe arrays and up to terabytes of ECC RAM.
