0% found this document useful (0 votes)
2 views3 pages

Cara Fixe SQL Memory Usage

The document provides a detailed analysis of SQL Server performance issues, specifically focusing on the `sys.dm_exec_requests` output to identify slowness. It highlights key columns to monitor, particularly the `wait_type` indicating memory allocation issues, and suggests actions to alleviate memory pressure, such as limiting SQL Server's max memory and identifying memory-heavy queries. The document concludes with a summary of recommended steps to take for optimizing memory usage and improving performance.

Uploaded by

muhamad jazuli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Cara Fixe SQL Memory Usage

The document provides a detailed analysis of SQL Server performance issues, specifically focusing on the `sys.dm_exec_requests` output to identify slowness. It highlights key columns to monitor, particularly the `wait_type` indicating memory allocation issues, and suggests actions to alleviate memory pressure, such as limiting SQL Server's max memory and identifying memory-heavy queries. The document concludes with a summary of recommended steps to take for optimizing memory usage and improving performance.

Uploaded by

muhamad jazuli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Thanks for sharing the `sys.

dm_exec_requests` output — this is a **very useful


diagnostic view** when troubleshooting SQL Server slowness.

Let’s break down the **most important columns** to focus on when diagnosing
**performance or slowness issues**, based on your

---

### ✅ **Key Columns to Check for Slowness Issues**

| Column | Why It Matters | Your Value / Observation |


|-------|----------------|--------------------------|
| **`status`** | Shows current state of request. `running`, `suspended`,
`background`, etc. | `running` → normal, but if stuck for long, could be CPU-bound.
|
| **`command`** | What type of command is running. Helps identify workload type. |
`SELECT` → Could be a heavy query. |
| **`wait_type`** | **CRITICAL** – Tells you *why* the query is waiting. |
`MEMORY_ALLOCATION_EXT` → **This is the red flag.** |
| **`last_wait_type`** | Previous wait type (if not currently waiting). | Same →
consistent memory pressure. |
| **`wait_resource`** | Details about the resource being waited on. | Empty → not
helpful here. |
| **`cpu_time`** | CPU time used (in ms). High = CPU-intensive. | `2` ms → very low
→ not CPU-bound. |
| **`total_elapsed_time`** | Total time since query started (ms). | `2` ms → very
short → this query just started. |
| **`logical_reads`** | Number of data pages read from memory. High = heavy I/O. |
`0` → nothing read yet. |
| **`reads`** | Physical reads from disk. High = disk I/O bottleneck. | `0` → no
disk reads yet. |
| **`writes`** | Writes to disk. | `0` → no writes. |
| **`open_transaction_count`** | Open transactions can block others. | `0` → good.
|
| **`blocking_session_id`** | If >0, this session is blocked by another. | `0` →
not blocked. |
| **`percent_complete`** | For long ops (e.g., backup, index rebuild). | `0` → not
applicable. |
| **`estimated_completion_time`** | When will long op finish? | `0` → not
applicable. |
| **`scheduler_id`** | Which CPU scheduler is used. | Normal. |
| **`database_id`** | Which DB is involved. | `172` → check which DB this is:
`SELECT name FROM sys.databases WHERE database_id = 172` |

---

### 🔥 **Critical Finding: `wait_type = MEMORY_ALLOCATION_EXT`**

This is the **most important clue**.

#### What does `MEMORY_ALLOCATION_EXT` mean?


- The query is **waiting to allocate memory** before it can start executing.
- This happens when:
- SQL Server doesn't have enough **memory grants** available.
- There’s **memory pressure** (RAM exhausted).
- Too many large queries running at once.
- **max server memory** is set too low or too high (starving OS or other
processes).
> ⚠️ This explains **slowness**: even if the query is simple, it can't start
because it’s waiting for memory.

---

### 🧩 Root Cause Summary

Based on your
- The query **hasn't really started yet** (0 reads, 0 CPU, 2ms elapsed).
- It’s **queued waiting for memory** (`MEMORY_ALLOCATION_EXT`).
- This suggests **system-wide memory pressure**, not a slow individual query.

This aligns with your earlier Task Manager screenshot showing **~27.5 GB RAM
usage** by `sqlservr.exe`.

---

### ✅ Recommended Actions

#### 1. **Check Available System Memory**


- Is your machine running out of RAM?
- Is the OS or other apps being starved?

#### 2. **Limit SQL Server Max Memory**


By default, SQL Server can use **all available RAM**. You should cap it.

```sql
-- Check current max memory
SELECT name, value_in_use
FROM sys.configurations
WHERE name = 'max server memory (MB)';

-- Example: Set to 24 GB on a 32 GB machine


EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;
EXEC sp_configure 'max server memory (MB)', 24576;
RECONFIGURE;
```

> Leave 4–8 GB for OS and other apps.

#### 3. **Find Memory-Heavy Queries**


Run this to see what’s consuming memory:

```sql
SELECT TOP 10
text = SUBSTRING(text, statement_start_offset/2,
(CASE WHEN statement_end_offset = -1 THEN LEN(CONVERT(nvarchar(max),text))
* 2
ELSE statement_end_offset END - statement_start_offset)/2),
cpu_time,
total_elapsed_time,
logical_reads,
session_id,
memory_usage * 8 / 1024.0 AS memory_used_mb
FROM sys.dm_exec_requests
CROSS APPLY sys.dm_exec_sql_text(sql_handle)
ORDER BY memory_usage DESC;
```
#### 4. **Check for Memory Grants**
See pending memory grants:

```sql
SELECT
session_id,
request_id,
start_time,
status,
command,
wait_type,
wait_time,
total_elapsed_time,
query_cost,
requested_memory_kb,
granted_memory_kb,
used_memory_kb
FROM sys.dm_exec_query_memory_grants
ORDER BY requested_memory_kb DESC;
```

> If `granted_memory_kb` is `0`, it’s waiting — confirms `MEMORY_ALLOCATION_EXT`.

#### 5. **Restart SQL Server (if safe)**


If you can restart:
- Frees all memory.
- Resets memory pressure.
- Good for temporary relief.

---

### 📌 TL;DR – What You Need to Do Now

1. **Limit SQL Server max memory** → Prevents system-wide lag.


2. **Check if other queries are waiting on memory** → Use
`dm_exec_query_memory_grants`.
3. **Avoid running too many heavy queries at once** → Throttle reporting jobs.
4. **Upgrade RAM if this is normal workload** → 32GB+ if running large DBs.

---

Let me know:
- Total RAM on the server
- Purpose of SQL Server (dev, prod, reporting?)
- Whether this happens during specific times (e.g., nightly jobs)

I’ll help you tune memory settings accordingly.

You might also like