Insufficient shared_buffers causes excessive disk reads and slow queries
warningperformanceUpdated Feb 7, 2025
Technologies:
How to detect:
Default shared_buffers of 128MB is too low for production workloads, causing PostgreSQL to read from disk instead of memory cache, resulting in slow query performance. Optimal setting is 25-40% of available RAM after OS reservation.
Recommended action:
Set shared_buffers to 25-40% of available RAM in postgresql.conf. Example for 16GB RAM: shared_buffers = 4GB (after reserving 3-4GB for OS). Apply with SELECT pg_reload_conf(); Test impact by monitoring cache hit ratio with: SELECT round(blks_hit*100/(blks_hit+blks_read), 2) AS cache_hit_ratio FROM pg_stat_database WHERE datname = current_database(); Target >95% cache hit ratio.