SQL Server Error 845 ("timeout occurred while waiting for buffer") means the server couldn’t allocate memory for a buffer pool operation within the allowed time, often due to memory pressure or resource contention. This does not indicate a syntax or connectivity issue—it reflects system-level resource exhaustion. The fix involves identifying and reducing memory pressure, adjusting configuration, or optimizing queries.

What You’ll Need

  • SQL Server Management Studio (SSMS) installed on a machine with network access to the SQL Server instance
  • sysadmin or equivalent permissions on the SQL Server instance
  • Access to Windows Performance Monitor (perfmon) for real-time memory metrics
  • Basic understanding of SQL Server memory architecture (buffer pool, plan cache, etc.)

Step-by-Step

  1. Verify the error context: Check the SQL Server error log for surrounding messages. In SSMS, run EXEC xp_readerrorlog 0, 1, 'Error: 845' to locate recent occurrences. Note the timestamp and any related errors (e.g., memory grants, I/O bottlenecks).
  2. Check available system memory: On the SQL Server host, open Task Manager (Ctrl+Shift+Esc), go to the Performance tab, and review memory usage. If committed memory is near or exceeds physical RAM (especially with large page file usage), memory pressure is likely. Also check Available MBytes in Performance Monitor—values below 200 MB indicate critical pressure.
  3. Monitor SQL Server memory usage: In SSMS, run SELECT * FROM sys.dm_os_process_memory to see physical_memory_in_use_kb and virtual_memory_in_use_kb. Then run SELECT * FROM sys.dm_os_buffer_descriptors WHERE database_id > 4 ORDER BY database_id to assess buffer pool usage by database. High cache usage in non-critical databases may indicate inefficient caching.
  4. Adjust max server memory: If max server memory is set too high (or left at default, which allows SQL Server to consume nearly all system RAM), reduce it to reserve memory for the OS and other processes. In SSMS, right-click the server > Properties > Memory. Set Maximum server memory (MB) to: Total RAM − 4096 MB (for dedicated SQL Servers) or Total RAM − 6144 MB (for shared servers). Avoid setting it below the buffer pool’s current usage (check SELECT (cntr_value/1024) AS [Buffer Pool MB] FROM sys.dm_os_performance_counters WHERE counter_name = 'Total Server Memory (KB)').
  5. Clear non-essential caches: Run DBCC FREEPROCCACHE to flush the plan cache (temporarily increases CPU during recompilation but frees memory quickly). For specific databases, use DBCC DROPCLEANBUFFERS after forcing dirty pages to disk with CHECKPOINT—this clears clean buffers and should only be done in non-production testing, as it degrades performance until warmed up.
  6. Identify memory-intensive queries: Run SELECT TOP 10 total_worker_time, total_elapsed_time, execution_count, SUBSTRING(text, (statement_start_offset/2)+1, ((CASE statement_end_offset WHEN -1 THEN LEN(CONVERT(NVARCHAR(MAX), text)) * 2 ELSE statement_end_offset END - statement_start_offset)/2)+1) AS query_text FROM sys.dm_exec_query_stats CROSS APPLY sys.dm_exec_sql_text(sql_handle) ORDER BY total_worker_time DESC to find high-CPU queries. Also check sys.dm_exec_requests for wait_type = 'RESOURCE_SEMAPHORE' (indicates waiting for memory grants).
  7. Optimize high-memory queries: For problematic queries, add appropriate indexes to reduce sort/hash operations, avoid SELECT *, and limit result sets with TOP or WHERE filters. Use OPTION (MAXDOP 1) for queries causing excessive parallel memory consumption. Test changes in a non-production environment first.
  8. Adjust query memory grants: If queries frequently exceed memory limits, cap memory grants per query using ALTER WORKLOAD GROUP [default] WITH (REQUEST_MEMORY_GRANT_TIMEOUT_SEC = 120) (default is 25 seconds). Run this in master after verifying it doesn’t impact SLAs—lower timeouts force early query failure instead of prolonged blocking.
  9. Restart SQL Server service (last resort): If memory leaks are suspected or the server is severely degraded, restart the SQL Server service via SQL Server Configuration Manager or PowerShell (Stop-Service -Name 'MSSQL$INSTANCE' ; Start-Service -Name 'MSSQL$INSTANCE'). This clears all caches but causes brief downtime—schedule during maintenance windows.

Common Mistakes

  • Setting max server memory too low (e.g., below 2 GB), causing constant buffer pool churn and increased I/O. Always leave at least 2–4 GB for the OS.
  • Running DBCC DROPCLEANBUFFERS on production without understanding it clears the buffer pool, forcing disk reads on next queries—only use for testing.
  • Ignoring third-party processes (e.g., antivirus, backup tools) that spike memory usage during backups or scans, indirectly starving SQL Server.
  • Overusing parallelism (MAXDOP > 8 on servers with ample cores) without adjusting cost threshold for parallelism, leading to memory grant contention.

Tips

  • Monitor Page Life Expectancy (PLE) in Performance Monitor—values below 300 seconds (on servers with >4 GB RAM) suggest buffer pool pressure. PLE = cntr_value from sys.dm_os_performance_counters where counter_name = 'Page Life Expectancy'.
  • Use Resource Governor to limit memory for non-critical workloads: create a resource pool with MAX_MEMORY_PERCENT = 20 and assign low-priority queries to it.
  • Enable Lock Pages in Memory for the SQL Server service account (via Local Security Policy > User Rights Assignment) on 64-bit systems to prevent OS paging—but only after confirming sufficient physical RAM exists.
  • After resolving memory pressure, run DBCC FREESYSTEMCACHE ('ALL') cautiously to clear unused system caches, but avoid frequent use—it can increase CPU load temporarily.

Troubleshooting

If Error 845 persists after applying the above steps:

  1. Check for memory leaks: Use DBCC MEMORYSTATUS to inspect memory clerks (e.g., MEMORYCLERK_SQLBUFFERPOOL). If single_pages_kb or multi_pages_kb grow continuously, contact Microsoft Support—this may indicate a known bug.
  2. Review memory-intensive agents: Disable SQL Agent jobs (especially SSIS packages or large ETL processes) temporarily. Some jobs request memory grants but fail to release them promptly.
  3. Verify NUMA configuration: On multi-socket servers, run SELECT * FROM sys.dm_os_nodes WHERE status = 0x01. If nodes are unbalanced, adjust max server memory per NUMA node (e.g., set to total RAM / node count − 2048).
  4. Inspect disk latency: High disk latency (e.g., Avg. Disk sec/Read > 15 ms in PerfMon) can delay buffer writes, causing timeouts. Defragment disks, upgrade to SSDs, or separate data/log files to dedicated drives.
  5. Update SQL Server: Apply the latest cumulative update (CU) from Microsoft—Error 845 has been fixed in specific builds (e.g., SQL Server 2019 CU 18+).

Frequently Asked Questions

Can I ignore Error 845 if it happens rarely?

No—even isolated occurrences indicate memory pressure that can cause cascading failures (e.g., query timeouts, deadlocks). Investigate and resolve to prevent performance degradation.

Does increasing RAM always fix Error 845?

Not necessarily. If queries lack indexes or use inefficient plans, they may consume memory faster than expected. Optimize queries first; add RAM only if system memory is consistently exhausted.

How do I know if max server memory is set correctly?

After adjusting, monitor Target Server Memory (KB) vs. Total Server Memory (KB) in PerfMon. If Total consistently hits Target and PLE drops, increase max server memory by 512 MB increments.

Can connection pooling cause Error 845?

No—connection pooling manages client-side connections and does not affect SQL Server’s buffer pool memory. Focus on server-side memory usage instead.

Will clearing the plan cache help long-term?

Short-term, yes—it frees memory instantly. Long-term, no—without fixing root causes (e.g., missing indexes), queries will recompile and re-consume memory. Use it only for immediate relief.

Is Error 845 specific to SQL Server 2016 or newer?

No—it occurs across SQL Server versions (2008 R2+), though memory management improvements in newer versions reduce frequency. Always check version-specific behavior in Microsoft’s documentation.