How to Fix SQL Server Error 845 (Msg 845)

Published
Length
3 min read

Luis Felipe Dias

All posts

A buffer latch wait time-out triggers sql server error 845 when a thread waits too long for a data page. You fix this error by finding slow disk reads, tuning heavy queries, or adding server memory. Database engines use latches to keep memory pages safe while threads read or write data. Unlike locks that guard logical rows, latches guard the physical page in the buffer pool. When a disk subsystem stalls or memory runs low, threads line up and wait. If that wait passes the internal limit, the en

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

A buffer latch wait time-out triggers sql server error 845 when a thread waits too long for a data page. You fix this error by finding slow disk reads, tuning heavy queries, or adding server memory.

Database engines use latches to keep memory pages safe while threads read or write data. Unlike locks that guard logical rows, latches guard the physical page in the buffer pool. When a disk subsystem stalls or memory runs low, threads line up and wait. If that wait passes the internal limit, the engine throws a severity 17 message and stops the request.

What causes sql server error 845 in production

The official message for sql server error 845 states that a time-out occurred while waiting for a buffer latch for a specific page and database ID. It logs with severity 17, which means the query hit a resource limit that the engine could not clear on its own. The error log records the latch type, the page ID. The database ID so you can trace the exact spot of the stall.

Slow storage is the most common root cause behind this failure. When a query needs a page that is not in memory, the engine grabs a latch and waits for the disk to return the page. If the storage array or network disk stalls, the latch stays held and other threads time out.

Heavy memory pressure also sets off this chain of events. When the buffer pool is too small for the active workload, the server flushes pages out to disk and reads them back in all the time. Long transactions, missing indexes, and huge table scans make this churn much worse. Sometimes a background task like a file shrink or a busy temp database creates a bottleneck on allocation pages.

How to diagnose and fix buffer latch time-outs safely

Start your check by reading the database error log to find the database ID and page number from the message. Check the system wait views to see if the latch wait is tied to disk reads or memory contention. If disk waits are high, ask your storage team to check disk latency, queue depth, and host bus health.

Kubernetes API Server Access + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Next, look at the queries that were running when the error fired. Find queries that do large table scans or big sorts, and add indexes to cut down the number of pages they touch. Check that server memory limits leave enough room for both the buffer pool and the host operating system. If the page ID points to the temp database, spreading temp files across fast disks can ease page wait pressure.

Controlling database permissions during incident response

When an urgent severity 17 error hits production, engineers often ask for broad admin rights to inspect the server. Giving out the fixed owner role is risky because members can change any setting and even drop the database. Instead, teams should scope database users to the smallest role needed for the job.

A database user represents the identity of a login when it connects to a database. For people who need access to one or a few databases, an admin can set up a contained database user with a password instead of a login in the master database. When an engineer only needs to inspect user tables during a check, the fixed data reader role lets them read all user tables and views without writing data. Data masking can also rewrite matched fields like emails, phone numbers, card numbers, or national IDs in query results during live checks.

Govern SQL Server queries and responses in flight

Table grants decide which SQL Server objects a caller may touch. They do not check query intent or rewrite sensitive values in results across every client and agent. By design, hoop.dev sits inline in the TDS wire protocol next to SQL Server as a sidecar for your SQL Server. On every production batch from an engineer or AI agent, hoop.dev decides to pass, mask, block, or hold it for approval.

With hoop.dev guardrails and hoop.dev data masking, banned statements are refused or held for review, matched sensitive fields in supported result columns are masked in memory, and each decision is logged. Check out the code on GitHub.

Frequently asked questions

What does severity 17 mean for error 845?

Severity 17 means the statement ran into a resource problem, such as a disk stall or memory bottleneck. An app user cannot fix it by changing query syntax alone. As a result, an admin must check server hardware and workload load.

Is a buffer latch the same thing as a database lock?

No, a lock protects logical data rows during a transaction. Meanwhile, a latch protects the physical memory page in the buffer pool. You cannot clear a buffer latch wait by changing transaction isolation levels.

How can I tell if disk speed caused the latch time-out?

Check the error log and system wait stats around the time of the failure. High page read wait times alongside disk warnings in the system log point straight to slow storage.

The query runs. The emails stay hidden.