Online Class • Core DBA Skills
In this lesson, you will learn how SQL Server uses memory and CPU, how to recognize
resource pressure, and how to fix the right problem without guessing. Many “slow SQL Server” incidents are not caused by
one bad query—they are caused by memory grants, CPU scheduling pressure, or a workload that outgrew its resources.
This lesson gives you the DBA toolbox to diagnose and stabilize performance.
SQL Server performance depends heavily on how efficiently it can use memory (to avoid disk reads and execute operations)
and how fairly it can schedule CPU time across concurrent requests. In a healthy system, most reads are served from memory,
and CPU time is shared smoothly. In an unhealthy system, you see unstable performance: queries run fast sometimes and slow
other times, timeouts appear during peak hours, and “small” queries wait behind “big” queries.
Resource tuning is about workload control. You can’t “configure” your way out of a workload that is doing too much
work. The fastest way to stabilize SQL Server is to identify what is consuming memory/CPU, reduce unnecessary work (reads, sorts, hashes),
and ensure the instance has safe, correct settings (especially max server memory and parallelism).
120–180 minutes (deep concepts + evidence scripts + lab)
To manage memory, you must first understand what memory is doing. In SQL Server, memory usage is usually dominated by:
(1) data cache and (2) query execution memory.
The buffer pool stores data pages in memory so SQL Server can read them quickly without going to disk. If your working set
(the pages you need most often) fits in the buffer pool, performance is stable and fast. If not, SQL Server must read from disk
more often (physical reads), which is slower and less predictable.
Many operations need workspace memory: sort, hash join, hash aggregate,
and sometimes batch mode operations. SQL Server gives queries memory grants so they can execute efficiently. If the grant is too small,
the query can spill to TempDB (slow). If grants are too large or too many queries run at once, queries can wait for memory
(memory grant waits) and the entire system becomes slow during peak time.
Key teaching point: Memory grants depend on cardinality estimates. Bad estimates lead to wrong memory grants,
which leads to spills or excessive reservation.
SQL Server uses CPU through a scheduling system. Understanding CPU in SQL Server is not only “CPU %.”
It’s also about how many requests are waiting for CPU time and how parallelism affects concurrency.
SQL Server assigns work to CPU schedulers. Each running request needs a worker (thread) to do work.
When CPU is busy, requests queue up waiting their turn. This is when you feel “the database is slow” even if your queries are correct.
Key teaching point: CPU problems are often workload problems. The fix is frequently:
reduce reads, optimize expensive queries, and control parallelism—not “buy more CPU first.”
Students often confuse CPU, memory, and I/O issues because the symptom is the same: “slow.”
Use this mental model:
Rule: Don’t tune until you identify the dominant bottleneck.
The scripts below help you capture evidence for memory and CPU behavior. These are safe to run in a lab and are commonly used by DBAs.
They do not change data.
SELECT cpu_count, scheduler_count, hyperthread_ratio, physical_memory_kb/1024 AS physical_memory_mb, committed_kb/1024 AS committed_mb, committed_target_kb/1024 AS committed_target_mb, sqlserver_start_time FROM sys.dm_os_sys_info;
How to interpret: This gives you the basic hardware and SQL Server memory target/commit levels.
It’s the starting point for any resource discussion.
-- Top memory consumers inside SQL Server SELECT TOP (15) type AS memory_clerk, pages_kb/1024 AS pages_mb, virtual_memory_committed_kb/1024 AS vm_committed_mb, virtual_memory_reserved_kb/1024 AS vm_reserved_mb FROM sys.dm_os_memory_clerks ORDER BY pages_kb DESC;
How to interpret: This shows broad memory usage categories (cache, query execution structures, etc.).
You don’t “fix” memory clerks directly—this is evidence for what’s dominating.
SELECT r.session_id, s.login_name, s.host_name, s.program_name, r.status, r.cpu_time, r.total_elapsed_time, r.logical_reads, r.reads, r.writes, r.wait_type, r.wait_time, r.blocking_session_id, DB_NAME(r.database_id) AS database_name FROM sys.dm_exec_requests r JOIN sys.dm_exec_sessions s ON r.session_id = s.session_id WHERE r.session_id <> @@SPID ORDER BY r.cpu_time DESC;
How to interpret: Sort by CPU to find CPU-hungry requests. Sort by elapsed time to find “long runners.”
If elapsed time is high but CPU is low, it may be waiting (I/O, locks, memory grant).
SELECT DB_NAME(vfs.database_id) AS database_name, mf.type_desc, mf.physical_name, vfs.num_of_reads, vfs.num_of_writes, CASE WHEN vfs.num_of_reads = 0 THEN 0 ELSE vfs.io_stall_read_ms / vfs.num_of_reads END AS avg_read_ms, CASE WHEN vfs.num_of_writes = 0 THEN 0 ELSE vfs.io_stall_write_ms / vfs.num_of_writes END AS avg_write_ms FROM sys.dm_io_virtual_file_stats(NULL, NULL) vfs JOIN sys.master_files mf ON vfs.database_id = mf.database_id AND vfs.file_id = mf.file_id ORDER BY (vfs.io_stall_read_ms + vfs.io_stall_write_ms) DESC;
How to interpret: High read latency suggests storage pressure or queries doing too many physical reads.
High log write latency suggests log bottlenecks (write-heavy workloads).
SELECT TOP (20) wait_type, waiting_tasks_count, wait_time_ms, signal_wait_time_ms FROM sys.dm_os_wait_stats WHERE wait_type NOT LIKE 'SLEEP%' ORDER BY wait_time_ms DESC;
How to interpret: Use waits to guide your investigation.
Then confirm using active requests + I/O latency + query metrics.
This section teaches you what changes DBAs make when memory or CPU is the bottleneck. The goal is stability, not “one fast query.”
This commonly indicates memory grant competition (big sorts/hashes waiting for workspace memory).
Students will produce a simple report that answers: Is this environment CPU-bound, memory-pressured, I/O-bound, or blocked?
They will support their conclusion with evidence from DMVs.
Prompt:
“A system slows down every time a large monthly report runs. After the report finishes, the system stays slower for 20 minutes.
What does this suggest about memory and cache behavior? What would you monitor and what would you change first?”
In the next lesson, we will cover SQL Server Profiler and Trace Analysis.
You will learn how to capture workload evidence (especially in environments where Query Store is not available or where you need
detailed event timing), and how to turn trace evidence into tuning decisions without drowning in noise.
Not a member yet? Register now
Are you a member? Login now