SlideShare a Scribd company logo
Microsoft SQL Server
Monitoring and Profiling
Alireza Sadeghipour, Abouzar Noori
24th Azar 1394
Microsoft SQL Server:
Monitoring and Profiling
• Performance Monitoring
• Estimated Execution Plan
• Indexing
• Database Engine Tuning Advisor
• SQL Server Profiling
Before MS SQL
• Be aware of Select N+1 Problem when using EF lazy loading
• Log EF queries to find the problem:
Performance Monitoring
Resource Monitor
• First of all, check Resource Monitor and find sqlserver.exe
SQL Server Performance Counters
SQL Server Performance Counters
• Access Methods: Full Scans/sec
• Buffer Manager: Buffer Cache Hit Ratio
• Database: Transactions/sec
• Database: Write Transactions/sec
• General Statistics: User Connections
SQL Server Performance Counters (cont.)
• Locks: Lock Requests / Sec
• Locks: Lock Waits / Sec
• Locks: Lock Timeouts/sec
• Locks: Number of Deadlocks/sec
• SQL Statistics: Batch Requests/Sec
• SQL Statistics: SQL Re-Compilations/sec
• SQL Statistics: SQL Compilations/sec
Checking Execution Plan with SSMS
Actual Execution Plan in SQL Server
IO Statistics
• Copy message into http://www.statisticsparser.com/
• Logical reads is the most prominent counter
Indexing
Indexing
• Clustered index
• Primary Key: Includes all columns
• Non-clustered index
• One or more columns: Include as many columns as needed
• SELECT * FROM Device WHERE Serial = ‘0123456789’
• Execution plan suggests to add:
• CREATE NONCLUSTERED INDEX (…) ON Device (Serial)
Indexing (cont.)
• A new index is a new copy of the table, containing “key columns”
and “include columns”
• 4,516 logical read
• SSMS hints:
• Logical reads decreases to 13
Indexing (cont.)
• Indexing helps
• SELECT item using COLUMN = VALUE
• COLUMN compare VALUE
• INDEX name on table (a, b)
• Sort on a values, then b values in each bucket on a
• Not good for
• SELECT id FROM table WHERE a > 100 and b = 200
• SELECT id FROM table WHERE b = 200
• Good for
• SELECT id FROM table WHERE b > 100 and a = 200
• SELECT id FROM table WHERE a > 100
Investigating index usage (index_usage_stats)
• SELECT OBJECT_NAME(ddius.[object_id], ddius.database_id) AS [object_name] ,
ddius.index_id ,
ddius.user_seeks ,
ddius.user_scans ,
ddius.user_lookups ,
ddius.user_seeks + ddius.user_scans + ddius.user_lookups
AS user_reads ,
ddius.user_updates AS user_writes ,
ddius.last_user_scan ,
ddius.last_user_update
FROM sys.dm_db_index_usage_stats ddius
WHERE ddius.database_id > 4 -- filter out system tables
AND OBJECTPROPERTY(ddius.OBJECT_ID, 'IsUserTable') = 1
AND ddius.index_id > 0 -- filter out heaps
ORDER BY ddius.user_scans DESC
Identify indexes that have never been
accessed
• SELECT OBJECT_NAME(i.[object_id]) AS [Table Name] , i.name FROM
sys.indexes AS I INNER JOIN sys.objects AS o ON i.[object_id] =
o.[object_id] WHERE i.index_id NOT IN ( SELECT ddius.index_id
FROM sys.dm_db_index_usage_stats AS ddius
WHERE ddius.[object_id] = i.[object_id] AND i.index_id =
ddius.index_id AND database_id = DB_ID() ) AND o.[type] = 'U‘
ORDER BY OBJECT_NAME(i.[object_id]) ASC
Tune Your Indexing Strategy with SQL Server
DMVs
• https://www.simple-talk.com/sql/performance/tune-your-indexing-
strategy-with-sql-server-dmvs/
Database Engine Tuning Advisor
SQL Server 2014 Monitoring and Profiling
SQL Server 2014 Monitoring and Profiling
SQL Server Profiling
Some Columns in DB are Locked!
• Use sp_who2 and check BlkBy to see who has blocked whom
• sp_whoisactive does it in a better way
SQL Server Profiler
Profile Using Execution Plan Cache
• Install sp_BlitzCache
• Run: sp_blitzcache @sort_order = 'reads', @top = 20
• You will find “Query Text”, “Total Reads”, “# Executions”, “Execution Plan”,
and some hints about how to improve performance of those queries.
• It gave us a hint to add the following index:
• We thought indexing this table is not important since it is solely used in
admin panel. But sp_BlitzCache tells that 20% of reads are related to this
function.
Other Diagnosing Stored Procedures
• sp_BlitzIndex: Gives you hints on how much your indexes are used and
suggestions for new indexes and their estimated effect
• sp_Blitz: Checks common health measures of your DB
• sp_AskBrent: For 5 seconds watches your DB and gives you a report on:
• Blocking or long-running queries
• If a backup, DBCC, or index maintenance job was running
• Query wait statistics to figure out SQL Server’s current bottleneck
• Perf. counters for CPU use, slow drive response times, or low Page Life Expectance
• You can create an agent job which runs sp_AskBrent every 15 minutes and
appends the result to a table in your DB (more info)
• All these stored procedures are packaged in the ZIP file containing
sp_BlitzCache
Evidences of Effect!
• # of lock requests / sec
• Avg. wait time
• CPU usage
Questions?

More Related Content

What's hot (20)

PPTX
Database in Android
MaryadelMar85
 
PPT
resource governor
Aaron Shilo
 
PPTX
Query Optimization in SQL Server
Rajesh Gunasundaram
 
PDF
Troubleshooting sql server
Antonios Chatzipavlis
 
PPTX
SQLite database in android
Gourav Kumar Saini
 
PPT
Less11 Security
vivaankumar
 
PPTX
Android Database Tutorial
Perfect APK
 
PPTX
Databases in Android Application
Mark Lester Navarro
 
PDF
Persitance Data with sqlite
Arif Huda
 
PDF
New fordevelopersinsql server2008
Aaron Shilo
 
PPTX
09.1. Android - Local Database (Sqlite)
Oum Saokosal
 
ODP
Introduction4 SQLite
Stanley Huang
 
PPTX
Using sqlite database in android with sqlite manager browser add ons
Vincent Clyde
 
PPTX
Sqlite
Raghu nath
 
PDF
SQLite 3
Scott MacVicar
 
PPTX
Database Performance Tuning
Arno Huetter
 
PPT
Less03 D B D B C A
vivaankumar
 
PPTX
SharePoint Framework, React, and Office UI Fabric spc adriatics 2016
Sonja Madsen
 
PPT
Less16 Recovery
vivaankumar
 
PPT
Less12 Proactive
vivaankumar
 
Database in Android
MaryadelMar85
 
resource governor
Aaron Shilo
 
Query Optimization in SQL Server
Rajesh Gunasundaram
 
Troubleshooting sql server
Antonios Chatzipavlis
 
SQLite database in android
Gourav Kumar Saini
 
Less11 Security
vivaankumar
 
Android Database Tutorial
Perfect APK
 
Databases in Android Application
Mark Lester Navarro
 
Persitance Data with sqlite
Arif Huda
 
New fordevelopersinsql server2008
Aaron Shilo
 
09.1. Android - Local Database (Sqlite)
Oum Saokosal
 
Introduction4 SQLite
Stanley Huang
 
Using sqlite database in android with sqlite manager browser add ons
Vincent Clyde
 
Sqlite
Raghu nath
 
SQLite 3
Scott MacVicar
 
Database Performance Tuning
Arno Huetter
 
Less03 D B D B C A
vivaankumar
 
SharePoint Framework, React, and Office UI Fabric spc adriatics 2016
Sonja Madsen
 
Less16 Recovery
vivaankumar
 
Less12 Proactive
vivaankumar
 

Viewers also liked (11)

DOCX
FGFisher_resume
Frank Fisher PMP
 
PDF
Pervaporacion
Elias Rodas Palomino
 
PDF
Amin priatna(A3.1300033)
aminpriatnaa
 
PPTX
Group 7
Nguyên Huỳnh
 
DOCX
Vision, leadership and ethics
The Concept Store
 
DOC
KACHEPA CURRICULUM VITAE 2015 REVISED
KENALA KACHEPA
 
PPT
Patrick O'Brien - Guerras y crecimiento económico a largo plazo
Fundación Ramón Areces
 
PPTX
Guido Smorto, Sharing In the Cities: Local Rules for a Global Innovation
LabGov
 
PDF
Microservices; A Quick Introduction
Abouzar Noori
 
PPTX
Logo competition BG
М. М.
 
PDF
Nestle Performance Management (2)
Muhammad Kamran Aqeel
 
FGFisher_resume
Frank Fisher PMP
 
Pervaporacion
Elias Rodas Palomino
 
Amin priatna(A3.1300033)
aminpriatnaa
 
Vision, leadership and ethics
The Concept Store
 
KACHEPA CURRICULUM VITAE 2015 REVISED
KENALA KACHEPA
 
Patrick O'Brien - Guerras y crecimiento económico a largo plazo
Fundación Ramón Areces
 
Guido Smorto, Sharing In the Cities: Local Rules for a Global Innovation
LabGov
 
Microservices; A Quick Introduction
Abouzar Noori
 
Logo competition BG
М. М.
 
Nestle Performance Management (2)
Muhammad Kamran Aqeel
 
Ad

Similar to SQL Server 2014 Monitoring and Profiling (20)

PDF
Practical SQL query monitoring and optimization
Ivo Andreev
 
PPTX
SQL Explore 2012: P&T Part 1
sqlserver.co.il
 
PPT
Sql Server Performance Tuning
Bala Subra
 
PDF
Advanced tips for making Oracle databases faster
SolarWinds
 
PPTX
T sql performance guidelines for better db stress powers
Shehap Elnagar
 
PPTX
T sql performance guidelines for better db stress powers
Shehap Elnagar
 
PPT
Sql server performance tuning
ngupt28
 
PDF
Why & how to optimize sql server for performance from design to query
Antonios Chatzipavlis
 
PPT
Optimizing Data Accessin Sq Lserver2005
rainynovember12
 
PDF
SQL Server Query Tuning Tips - Get it Right the First Time
Dean Richards
 
PPTX
DB
Samchu Li
 
PDF
Microsoft SQL Server Query Tuning
Mark Ginnebaugh
 
PPTX
Sql query analyzer & maintenance
nspyrenet
 
PPTX
T sql performance guidelines for better db stress powers
Shehap Elnagar
 
PPTX
Perfmon And Profiler 101
Quest Software
 
PPTX
Oracle performance tuning_sfsf
Mao Geng
 
PPTX
Enhancements that will make your sql database roar sp1 edition sql bits 2017
Bob Ward
 
PPTX
Database Performance
Boris Hristov
 
PDF
See sql server graphical execution plans in action tech republic
Kaing Menglieng
 
PDF
Discovering the plan cache (#SQLSat211)
Jason Strate
 
Practical SQL query monitoring and optimization
Ivo Andreev
 
SQL Explore 2012: P&T Part 1
sqlserver.co.il
 
Sql Server Performance Tuning
Bala Subra
 
Advanced tips for making Oracle databases faster
SolarWinds
 
T sql performance guidelines for better db stress powers
Shehap Elnagar
 
T sql performance guidelines for better db stress powers
Shehap Elnagar
 
Sql server performance tuning
ngupt28
 
Why & how to optimize sql server for performance from design to query
Antonios Chatzipavlis
 
Optimizing Data Accessin Sq Lserver2005
rainynovember12
 
SQL Server Query Tuning Tips - Get it Right the First Time
Dean Richards
 
Microsoft SQL Server Query Tuning
Mark Ginnebaugh
 
Sql query analyzer & maintenance
nspyrenet
 
T sql performance guidelines for better db stress powers
Shehap Elnagar
 
Perfmon And Profiler 101
Quest Software
 
Oracle performance tuning_sfsf
Mao Geng
 
Enhancements that will make your sql database roar sp1 edition sql bits 2017
Bob Ward
 
Database Performance
Boris Hristov
 
See sql server graphical execution plans in action tech republic
Kaing Menglieng
 
Discovering the plan cache (#SQLSat211)
Jason Strate
 
Ad

Recently uploaded (20)

PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PPTX
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PDF
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
PDF
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 

SQL Server 2014 Monitoring and Profiling

  • 1. Microsoft SQL Server Monitoring and Profiling Alireza Sadeghipour, Abouzar Noori 24th Azar 1394
  • 2. Microsoft SQL Server: Monitoring and Profiling • Performance Monitoring • Estimated Execution Plan • Indexing • Database Engine Tuning Advisor • SQL Server Profiling
  • 3. Before MS SQL • Be aware of Select N+1 Problem when using EF lazy loading • Log EF queries to find the problem:
  • 5. Resource Monitor • First of all, check Resource Monitor and find sqlserver.exe
  • 7. SQL Server Performance Counters • Access Methods: Full Scans/sec • Buffer Manager: Buffer Cache Hit Ratio • Database: Transactions/sec • Database: Write Transactions/sec • General Statistics: User Connections
  • 8. SQL Server Performance Counters (cont.) • Locks: Lock Requests / Sec • Locks: Lock Waits / Sec • Locks: Lock Timeouts/sec • Locks: Number of Deadlocks/sec • SQL Statistics: Batch Requests/Sec • SQL Statistics: SQL Re-Compilations/sec • SQL Statistics: SQL Compilations/sec
  • 10. Actual Execution Plan in SQL Server
  • 11. IO Statistics • Copy message into http://www.statisticsparser.com/ • Logical reads is the most prominent counter
  • 13. Indexing • Clustered index • Primary Key: Includes all columns • Non-clustered index • One or more columns: Include as many columns as needed • SELECT * FROM Device WHERE Serial = ‘0123456789’ • Execution plan suggests to add: • CREATE NONCLUSTERED INDEX (…) ON Device (Serial)
  • 14. Indexing (cont.) • A new index is a new copy of the table, containing “key columns” and “include columns” • 4,516 logical read • SSMS hints: • Logical reads decreases to 13
  • 15. Indexing (cont.) • Indexing helps • SELECT item using COLUMN = VALUE • COLUMN compare VALUE • INDEX name on table (a, b) • Sort on a values, then b values in each bucket on a • Not good for • SELECT id FROM table WHERE a > 100 and b = 200 • SELECT id FROM table WHERE b = 200 • Good for • SELECT id FROM table WHERE b > 100 and a = 200 • SELECT id FROM table WHERE a > 100
  • 16. Investigating index usage (index_usage_stats) • SELECT OBJECT_NAME(ddius.[object_id], ddius.database_id) AS [object_name] , ddius.index_id , ddius.user_seeks , ddius.user_scans , ddius.user_lookups , ddius.user_seeks + ddius.user_scans + ddius.user_lookups AS user_reads , ddius.user_updates AS user_writes , ddius.last_user_scan , ddius.last_user_update FROM sys.dm_db_index_usage_stats ddius WHERE ddius.database_id > 4 -- filter out system tables AND OBJECTPROPERTY(ddius.OBJECT_ID, 'IsUserTable') = 1 AND ddius.index_id > 0 -- filter out heaps ORDER BY ddius.user_scans DESC
  • 17. Identify indexes that have never been accessed • SELECT OBJECT_NAME(i.[object_id]) AS [Table Name] , i.name FROM sys.indexes AS I INNER JOIN sys.objects AS o ON i.[object_id] = o.[object_id] WHERE i.index_id NOT IN ( SELECT ddius.index_id FROM sys.dm_db_index_usage_stats AS ddius WHERE ddius.[object_id] = i.[object_id] AND i.index_id = ddius.index_id AND database_id = DB_ID() ) AND o.[type] = 'U‘ ORDER BY OBJECT_NAME(i.[object_id]) ASC
  • 18. Tune Your Indexing Strategy with SQL Server DMVs • https://www.simple-talk.com/sql/performance/tune-your-indexing- strategy-with-sql-server-dmvs/
  • 23. Some Columns in DB are Locked! • Use sp_who2 and check BlkBy to see who has blocked whom • sp_whoisactive does it in a better way
  • 25. Profile Using Execution Plan Cache • Install sp_BlitzCache • Run: sp_blitzcache @sort_order = 'reads', @top = 20 • You will find “Query Text”, “Total Reads”, “# Executions”, “Execution Plan”, and some hints about how to improve performance of those queries. • It gave us a hint to add the following index: • We thought indexing this table is not important since it is solely used in admin panel. But sp_BlitzCache tells that 20% of reads are related to this function.
  • 26. Other Diagnosing Stored Procedures • sp_BlitzIndex: Gives you hints on how much your indexes are used and suggestions for new indexes and their estimated effect • sp_Blitz: Checks common health measures of your DB • sp_AskBrent: For 5 seconds watches your DB and gives you a report on: • Blocking or long-running queries • If a backup, DBCC, or index maintenance job was running • Query wait statistics to figure out SQL Server’s current bottleneck • Perf. counters for CPU use, slow drive response times, or low Page Life Expectance • You can create an agent job which runs sp_AskBrent every 15 minutes and appends the result to a table in your DB (more info) • All these stored procedures are packaged in the ZIP file containing sp_BlitzCache
  • 27. Evidences of Effect! • # of lock requests / sec • Avg. wait time • CPU usage