0% found this document useful (0 votes)
17 views6 pages

Step by Step Guide To SQL Server Performance Tuning 1738662788

This document provides a step-by-step guide to SQL Server performance tuning, structured as a flow chart with actionable steps and real-world examples. It covers monitoring symptoms, identifying root causes, implementing fixes, testing, and documenting changes, emphasizing the importance of DMVs in diagnosing issues. Key takeaways highlight the cyclical nature of performance tuning and the impact of small fixes on overall system performance.

Uploaded by

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

Step by Step Guide To SQL Server Performance Tuning 1738662788

This document provides a step-by-step guide to SQL Server performance tuning, structured as a flow chart with actionable steps and real-world examples. It covers monitoring symptoms, identifying root causes, implementing fixes, testing, and documenting changes, emphasizing the importance of DMVs in diagnosing issues. Key takeaways highlight the cyclical nature of performance tuning and the impact of small fixes on overall system performance.

Uploaded by

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

1

Mohammed Ahmer Mohiuddin


SQL Server DBA | Azure, AWS & GCP Cloud Engineer | PostgreSQL | PowerShell | Cloud Admin | Linux
Expert | 4 x Microsoft Azure | ITIL®
www.linkedin.com/in/mohammed-ahmer-mohiuddin-a22a0432

Step-by-step guide to SQL Server performance tuning, structured as a


flow chart with actionable steps, DMVs/DMFs, and real-world analogies.
This guide is designed for experts but explained in simple terms.

Flow Chart Overview

[Start] → Monitor Symptoms → Identify Root Cause → Analyze with


DMVs/DMFs → Implement Fix → Test & Validate → Repeat
(Visualize this as a cyclical process with feedback loops.)

Step 1: Monitor Symptoms

Goal: Detect where the bottleneck lies (CPU, Memory, I/O, etc.).
Tools:

 Performance Monitor (PerfMon): Track % Processor Time, Page Life Expectancy, Disk
Read/Write Latency.
 SQL Server Activity Monitor: Check "Recent Expensive Queries" and "Resource Waits".
 DMVs:
o sys.dm_os_wait_stats (identify wait types like PAGEIOLATCH, CXPACKET).
o sys.dm_exec_requests (find currently running queries).

Real-Life Example:

 High CPU usage → Check sys.dm_exec_query_stats for queries with high total_worker_time.
 Slow reports → Look for PAGEIOLATCH waits indicating disk I/O bottlenecks.

Step 2: Identify Root Causes

Break down common issues and their DMV/DMF correlations:

1. CPU Bottlenecks

 Causes:
2
Mohammed Ahmer Mohiuddin
SQL Server DBA | Azure, AWS & GCP Cloud Engineer | PostgreSQL | PowerShell | Cloud Admin | Linux
Expert | 4 x Microsoft Azure | ITIL®
www.linkedin.com/in/mohammed-ahmer-mohiuddin-a22a0432

o Expensive queries (e.g., sorting, hashing).


o Missing indexes leading to scans.
o Parameter sniffing issues.
 DMVs:
o sys.dm_exec_query_stats: Find high total_worker_time queries.
o sys.dm_exec_query_plan: Check execution plans for scans.
 Fix:
o Optimize queries (avoid ORDER BY on large datasets).
o Add missing indexes.
o Use OPTION (RECOMPILE) for parameter sniffing.

2. Memory Pressure

 Causes:
o Insufficient memory allocated to SQL Server.
o Memory grants for sorts/hashes consuming RAM.
 DMVs:
o sys.dm_os_process_memory: Check physical_memory_in_use.
o sys.dm_exec_query_memory_grants: Find queries reserving memory.
 Fix:
o Increase max server memory (leave 4-8GB for OS).
o Optimize queries with ORDER BY/GROUP BY.

3. High I/O (Disk Latency)

 Causes:
o Table/index scans due to missing indexes.
o Poorly configured TempDB.
 DMVs:
o sys.dm_io_virtual_file_stats: Identify high read/write files.
o sys.dm_db_index_usage_stats: Find indexes with high scans.
 Fix:
o Add indexes to reduce scans.
o Separate TempDB files (1 file per CPU core).
3
Mohammed Ahmer Mohiuddin
SQL Server DBA | Azure, AWS & GCP Cloud Engineer | PostgreSQL | PowerShell | Cloud Admin | Linux
Expert | 4 x Microsoft Azure | ITIL®
www.linkedin.com/in/mohammed-ahmer-mohiuddin-a22a0432

4. Expensive Queries

 Causes:
o Complex joins, nested loops, or implicit conversions.
o Queries using SELECT * or functions in WHERE clauses.
 DMVs:
o sys.dm_exec_query_stats: Sort by total_logical_reads.
o sys.dm_exec_sql_text: Fetch query text.
 Fix:
o Rewrite queries to use indexed columns.
o Avoid functions in predicates (e.g., WHERE YEAR(Date) = 2023 → WHERE Date >=
'2023-01-01').

5. Missing Indexes

 Causes:
o SQL Server suggests indexes in execution plans but they’re not created.
o Frequent scans on large tables.
 DMVs:
o sys.dm_db_missing_index_details: Lists missing indexes.
o sys.dm_db_index_usage_stats: Compare seeks vs scans.
 Fix:
o Create filtered/non-clustered indexes on frequently queried columns.
o Example: Add index on OrderDate for WHERE OrderDate BETWEEN ....

6. Blocking/Deadlocks

 Causes:
o Long-running transactions locking resources.
o Poor isolation levels (e.g., READ UNCOMMITTED).
 DMVs:
o sys.dm_tran_locks: Check lock types (e.g., X for exclusive).
o sys.dm_os_waiting_tasks: Find blocked sessions.
4
Mohammed Ahmer Mohiuddin
SQL Server DBA | Azure, AWS & GCP Cloud Engineer | PostgreSQL | PowerShell | Cloud Admin | Linux
Expert | 4 x Microsoft Azure | ITIL®
www.linkedin.com/in/mohammed-ahmer-mohiuddin-a22a0432

 Fix:
o Use NOLOCK (carefully!) for read-heavy systems.
o Optimize transactions to commit faster.

7. Outdated Statistics

 Causes:
o Auto-update stats disabled or infrequent.
o Queries using stale stats for execution plans.
 DMVs:
o sys.dm_db_stats_properties: Check last_updated date.
o sys.dm_exec_query_stats: Look for last_worker_time spikes.
 Fix:
o Update stats manually: UPDATE STATISTICS TableName.
o Enable AUTO_UPDATE_STATISTICS.

8. TempDB Contention

 Causes:
o Excessive temp table usage or version stores.
o Insufficient TempDB files.
 DMVs:
o sys.dm_db_task_space_usage: Track TempDB allocations.
o sys.dm_os_wait_stats: Look for PAGELATCH waits on TempDB.
 Fix:
o Add multiple TempDB files (1 per CPU core).
o Use SNAPSHOT ISOLATION to reduce version store pressure.

Step 3: Implement Fixes

Prioritize: Start with the biggest bottleneck (e.g., a query affecting 80% of users).
Example Workflow:

1. Find high CPU query → Check its execution plan → Add missing index → Test → Deploy.
5
Mohammed Ahmer Mohiuddin
SQL Server DBA | Azure, AWS & GCP Cloud Engineer | PostgreSQL | PowerShell | Cloud Admin | Linux
Expert | 4 x Microsoft Azure | ITIL®
www.linkedin.com/in/mohammed-ahmer-mohiuddin-a22a0432

2. If disk I/O is high → Check sys.dm_io_virtual_file_stats → Optimize table partitioning.

Step 4: Test & Validate

Tools:

 Query Store: Compare pre/post-fix performance.


 Execution Plans: Check for index usage or reduced scans.
 DMVs: Re-run sys.dm_os_wait_stats to see if waits decreased.

Example:

 After adding an index, verify sys.dm_db_index_usage_stats shows increased user_seeks.

Step 5: Document & Iterate

 Log changes (e.g., "Added index on Orders.OrderDate").


 Schedule regular health checks using DMVs.

DMV/DMF Quick Reference Table

Issue Key DMV/DMF What to Check


CPU Bottlenecks sys.dm_exec_query_stats total_worker_time
Missing Indexes sys.dm_db_missing_index_details equality_columns, inequality_columns
Blocking sys.dm_tran_locks request_session_id, resource_type
I/O Latency sys.dm_io_virtual_file_stats io_stall_read_ms, io_stall_write_ms
Memory Pressure sys.dm_os_process_memory physical_memory_in_use

Real-World Scenario

Problem: An e-commerce site times out during flash sales.


Steps:
6
Mohammed Ahmer Mohiuddin
SQL Server DBA | Azure, AWS & GCP Cloud Engineer | PostgreSQL | PowerShell | Cloud Admin | Linux
Expert | 4 x Microsoft Azure | ITIL®
www.linkedin.com/in/mohammed-ahmer-mohiuddin-a22a0432

1. Monitor: High PAGEIOLATCH waits → I/O bottleneck.


2. Analyze: sys.dm_io_virtual_file_stats shows high reads on Orders table.
3. Fix: Add non-clustered index on CustomerID and OrderDate.
4. Test: sys.dm_db_index_usage_stats confirms index seeks.
5. Result: Page load time drops from 15s to 2s.

Key Takeaways

 Cycle: Performance tuning never ends—data grows, usage changes.


 DMVs are your best friend: They reveal what’s happening under the hood.
 Small fixes matter: A single missing index can save hours of downtime.

By following this guide, you’ll turn SQL Server performance issues from "Why is this so slow?"
to "Wow, that was easy!" 💡

You might also like