SlideShare una empresa de Scribd logo
1 de 23
SQL Server Wait Types 
Everyone Should Know 
Dean Richards
Who Am I 
• 20+ years of experience in SQL Server and Oracle 
• Speak at many user groups throughout US 
• Owner of DRConsulting 
• Dean.Richards@databaseperformance.guru 
• @ConfioDean 
• Focus on application and database performance 
• Review performance for hundreds of customers per year 
• Common thread – how do I do performance tuning?
What Are Wait Types 
• SQL Server has been instrumented to give clues about what it is 
doing when processing SQL statements 
• Wait Types identify a step being taken by SQL statement and its 
latencies 
• These clues help immensely when doing SQL analysis/tuning 
• Knowing a SQL waits on locking issues will lead to a different 
solution than if it were waiting on disk reads 
• SQL Server 2012 – 649 Wait Types 
• SQL Server 2014 – 800+ Waits 
• For a more complete description (for SQL 2005 but still relevant) 
• Microsoft Waits and Queue Document
Useful DMVs for Wait Types 
• sys.dm_os_wait_stats 
• Cumulative since instance startup 
• select * from sys.dm_os_wait_stats order by wait_time_ms desc 
• Exclude idle wait types in slide notes 
• Provides a view into what your instance is waiting for 
• sys.dm_exec_requests 
• Real-time view into what each session/SQL is waiting for 
• See slide notes for example query 
• Suspended state means the session is waiting for the wait_type 
• Running means the session is on the CPU 
• Sleeping means the session is idle
Wait Type DMV Problem 
• No Time Based View 
• What happened between 3am-5am this morning is not possible 
to get from the DMV objects 
• Need to use other tools 
• Extended Events Session to gather waits and query results 
• System_health default session *does not* gather waits 
• Solarwinds Database Performance Analyzer (DPA formerly Confio 
Ignite) does a great job of this 
• DPA provides great views into which SQLs are problematic and 
what they are waiting for. Also includes a knowledge base for 
many wait types. 
Different DMV Problem
Top 8 List of Wait Types 
• From my experience, there is a small list of wait types 
you need to know well 
• The other 500+ you can Google or ask Microsoft 
• Need to know: 
• What causes these waits 
• How to reduce / fix these waits 
• This presentation discusses common wait types I have 
personally encountered the most from over 400 
customers
1. PAGEIOLATCH_* 
• Disk read when a page required by a SQL is not in the 
buffer cache 
• Where * in: 
• SH – shared: session reads the data 
• EX – exclusive: session needs exclusive access to page 
• UP – update: session needs to update data 
• DT – destroy: session needs to remove the page 
• KP – keep: temporary while SQL Server decides 
• NL – undocumented 
• The SH, EX and UP latches are by far the most common
1. PAGEIOLATCH_* Solutions 
• Do fewer disk reads 
• Tune the SQL statement to do less I/O 
• Cache more data, i.e. bigger buffer cache so disk reads no needed 
• Many SQLs waiting – bigger cache may help 
• A few SQLs waiting – probably means SQL tuning 
• Use query in notes to check MB/sec – are you trying to read/write 
way too much data and overloading disks – tune SQL. 
• Make disk reads faster 
• Check file/disk latency with sys.dm_io_virtual_file_stats DMO 
• Use query in notes 
• Anything higher than ~ 15 ms would be considered slow on a 
production class server 
• Talk to storage team but remember there are many layers between 
the database and storage, i.e. O/S, virtualization, network, etc
2. WRITELOG 
• Waiting for a log flush to complete 
• Log flush commonly occurs because of checkpoint or commit 
• Commits can be explicit (commit) or implicit (auto-commit)
2. WRITELOG Solutions 
• Do less work 
• Develop code to do more batch processing 
• Single row processing inside loop rather than set based 
processing? 
• Make disk writes faster 
• Avoid RAID5/6 – write I/O penalty 
• Check file/disk latency with sys.dm_io_virtual_file_stats DMO 
• Review the write latencies for the transaction logs 
• Reduce I/O contention on disks containing logs 
• Solid State? – many questions about this but several test cases 
have seen good results 
• Size the transaction logs properly – see notes for a good 
references on this subject
3. ASYNC_NETWORK_IO 
• Query produces result set and sends back to client. While 
client processes data SQL Server waits on this 
• Often caused by large result sets being returned 
• Application that queries every row from large tables 
• See MS Access joining SQL Server data to Access data. Access 
must get all data in SQL table, bring back to Access to join it. Will 
see “select * from <large table>” queries 
• Can also apply to linked server queries 
• Slow client processing 
• Client machine is very busy and not processing results quickly 
• Client is reading data and doing processing on it that is slow 
• Could be a slow network connection from client to server
3. ASYNC_NETWORK_IO Solutions 
• Limit the result sets 
• Some poorly written applications read data from entire table and 
then filter at client. Filter from database first or write rows to 
temp table and have client read temp data 
• Avoid joins across Access to SQL Server data. This also applies to 
Linked Server and other distributed queries 
• Check performance of client machine. If it is resource 
constrained, it may not process results quickly 
• Check logic of client application and avoid retrieving 
large result sets if possible. Do more result set processing 
in database 
• Check the speed and stability of the network between 
client and server.
4. CXPACKET 
• Session is running a SQL in parallel 
• More of a status and not necessarily a problem. May be 
very normal for data warehouse but less so for OLTP 
• Master process will farm work out to slave processes and 
then wait on CXPACKET until all have completed 
• SQL Server will try to parallel-ize big queries up to 
MAXDOP – can be set instance wide down to this query 
• MAXDOP = 0 by default meaning unlimited 
• http://support.microsoft.com/kb/2806535 - recommendations 
• MAXDOP should not be set higher than 8 in most cases
4. CXPACKET More Information 
• Need to understand the slave processes and what they 
are doing / waiting for 
• Use sys.dm_os_waiting_tasks 
select session_id, exec_context_id, wait_type, wait_duration_ms, resource_description 
from sys.dm_os_waiting_tasks 
where session_id in ( 
select session_id from sys.dm_exec_requests 
where wait_type='CXPACKET') 
order by session_id, exec_context_id 
• Example Output 
session_id exec_context_id wait_type wait_duration_ms resource_description 
64 0 CXPACKET 417920 
64 1 PAGEIOLATCH_SH 149 5:1:1358830 
64 2 PAGEIOLATCH_SH 368 5:1:3514639 
64 3 PAGEIOLATCH_SH 84 5:1:3484089 
64 4 PAGEIOLATCH_SH 156 5:1:1348098 
• In this case, tune PAGEIOLATCH_SH waits
4. CXPACKET Solutions 
• Tune MAXDOP according to KB article provided 
• Not all queries do well in parallel, so experiment with 
MAXDOP settings at SQL level 
• Much bad advice about reducing MAXDOP server wide 
but avoid doing this blanket change 
• Tune the parallel slave process waits (previous slide) 
• Inefficient queries reading a lot of data will often be 
parallel-ized by SQL Server. Tune the queries 
• Review data skew and bad statistics which can cause one 
or few slave processes to do a bulk of the work
5. CPU 
• Not a wait type - identifies time on CPU 
• Query Response Time = Wait Time (wait types) + Service Time (CPU) 
• Waiting on CPU when sys.dm_exec_request has: 
• status = running 
• wait_type is often null 
• wait_time = 0 
• CPU time is often spent doing logical I/O 
• Could also come from compiles/recompiles and other 
CPU intensive operations
5. CPU Solutions 
• Tune queries with high amount of CPU time and often 
high logical I/O (see notes) 
• Reduce high execution count queries – do more batch 
processing 
• Check O/S for other activity putting pressure on CPU – 
may see high CPU queue lengths 
• Is the hardware undersized – may need to purchase 
larger/faster servers
6. LCK_M_* 
• Classic locking/blocking scenario 
• Where * in 21 different possibilities. Most common are: 
• U – trying to update the same resource 
• S – trying to modify data while it is being read 
• X – trying to lock a resource exclusively 
• IU, IS, IX – indicates intent to lock 
• SCH – schema locks – object is changing underneath 
• A session waiting on LCK_M_* wait is the victim. Need to 
use blocking_session_id in dm_exec_request to see the 
root cause (see query in slide notes) 
• Not to be confused with deadlocks – special locking case
6. LCK_M_* Solutions 
• Review the wait_description data to understand the locked 
resource. See slide notes for information. 
• Review the blocking session and understand the relationship 
with the blockee. Does the application need to be redesigned? 
• Blocking issues are often associated with a session holding 
locks for longer than necessary 
• Does the blocking session go on to do a lot of other SQLs? Can the 
transactions be committed sooner? 
• Does the blocking session execute inefficient SQLs while holding 
locks? Tuning the poor SQL could reduce the blocking time. 
• Has the client process waited and finally terminated due to 
timeouts? The SQL Server session could be left behind (orphaned) 
and never go away. Terminating the session should release the locks. 
• Is the client not fetching the whole result set quickly enough? See 
the ASYNC_NETWORK_IO wait description. 
• Is the session rolling back data? If so, that process must complete 
before locks are released
7. PREEMPTIVE_* 
• Often associated with external calls to O/S etc 
• Code being executed is outside SQL Server 
• OS_GETPROCADDRESS – seen with xp_fixeddrives, 
xp_readerrorlog, etc. Session is going to the O/S to get 
information 
• OLEDBOPS – seen with bulk loads from file and other 
external database operations 
• OS_AUTHENTICATIONOPS – seen when using 
xp_fixeddrives 
• OS_PIPEOPS – seen when using xp_cmdshell
8. PAGELATCH_* 
• Not as common, but 8 is my lucky number and I needed 
one more wait type  
• Latches synchronize access to internal SQL Server 
memory structures 
• Many different classes of latches, but BUFFER is most 
common, i.e. control access to buffer cache 
• Where * is the same set of values shown in 
PAGEIOLATCH waits slide 
• Not a disk read – do not confuse with PAGEIOLATCH
PAGELATCH_* Solutions 
• Use wait_resource to determine the page waited for. See 
slide notes for LCK_M_* for decoding this data 
• Could be TEMPDB contention. Check the wait_resource 
column from dm_exec_requests to see if the dbid (first 
part) is 2 to verify. 
• If so, good document from Microsoft - 
http://www.microsoft.com/en-gb/ 
download/details.aspx?id=26665 
• Can be caused by index page splitting 
• Specify fill factors properly 
• Tune SQL statements waiting for this. Inefficient SQL read 
more data from memory than needed and increase the 
likelihood of this wat
Summary 
• Wait Types provide the best information about why a 
SQL statement is running slow 
• SQL Server includes several DMVs showing Wait Types 
but lacks the point in time view which allows you to go 
back to 3-5am when something was slow 
• Use Extended Events to collect the data 
• Use tools like Solarwinds Database Performance Analyzer (DPA) 
• Memorize these 8 wait types, what causes them, how to 
fix them and you will be good to go 
• Contact me at: 
• Dean.Richards@databaseperformance.guru 
• @ConfioDean 
• www.linkedin.com/in/deanrichardsconsulting/

Más contenido relacionado

La actualidad más candente

MySQL Timeout Variables Explained
MySQL Timeout Variables Explained MySQL Timeout Variables Explained
MySQL Timeout Variables Explained Mydbops
 
Sql Server Performance Tuning
Sql Server Performance TuningSql Server Performance Tuning
Sql Server Performance TuningBala Subra
 
10 Problems with your RMAN backup script
10 Problems with your RMAN backup script10 Problems with your RMAN backup script
10 Problems with your RMAN backup scriptYury Velikanov
 
Ms sql server architecture
Ms sql server architectureMs sql server architecture
Ms sql server architectureAjeet Singh
 
Always on in sql server 2017
Always on in sql server 2017Always on in sql server 2017
Always on in sql server 2017Gianluca Hotz
 
Sql server performance tuning
Sql server performance tuningSql server performance tuning
Sql server performance tuningngupt28
 
Parallel Replication in MySQL and MariaDB
Parallel Replication in MySQL and MariaDBParallel Replication in MySQL and MariaDB
Parallel Replication in MySQL and MariaDBMydbops
 
Oracle Performance Tuning Fundamentals
Oracle Performance Tuning FundamentalsOracle Performance Tuning Fundamentals
Oracle Performance Tuning FundamentalsCarlos Sierra
 
Average Active Sessions - OaktableWorld 2013
Average Active Sessions - OaktableWorld 2013Average Active Sessions - OaktableWorld 2013
Average Active Sessions - OaktableWorld 2013John Beresniewicz
 
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentalsDB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentalsJohn Beresniewicz
 
Less01 architecture
Less01 architectureLess01 architecture
Less01 architectureAmit Bhalla
 
Oracle database performance tuning
Oracle database performance tuningOracle database performance tuning
Oracle database performance tuningYogiji Creations
 
Christo kutrovsky oracle, memory & linux
Christo kutrovsky   oracle, memory & linuxChristo kutrovsky   oracle, memory & linux
Christo kutrovsky oracle, memory & linuxKyle Hailey
 
Performance Tuning And Optimization Microsoft SQL Database
Performance Tuning And Optimization Microsoft SQL DatabasePerformance Tuning And Optimization Microsoft SQL Database
Performance Tuning And Optimization Microsoft SQL DatabaseTung Nguyen Thanh
 
Tanel Poder - Scripts and Tools short
Tanel Poder - Scripts and Tools shortTanel Poder - Scripts and Tools short
Tanel Poder - Scripts and Tools shortTanel Poder
 
SQL vs NoSQL | MySQL vs MongoDB Tutorial | Edureka
SQL vs NoSQL | MySQL vs MongoDB Tutorial | EdurekaSQL vs NoSQL | MySQL vs MongoDB Tutorial | Edureka
SQL vs NoSQL | MySQL vs MongoDB Tutorial | EdurekaEdureka!
 
Average Active Sessions RMOUG2007
Average Active Sessions RMOUG2007Average Active Sessions RMOUG2007
Average Active Sessions RMOUG2007John Beresniewicz
 
End-to-end Troubleshooting Checklist for Microsoft SQL Server
End-to-end Troubleshooting Checklist for Microsoft SQL ServerEnd-to-end Troubleshooting Checklist for Microsoft SQL Server
End-to-end Troubleshooting Checklist for Microsoft SQL ServerKevin Kline
 

La actualidad más candente (20)

MySQL Timeout Variables Explained
MySQL Timeout Variables Explained MySQL Timeout Variables Explained
MySQL Timeout Variables Explained
 
Sql Server Performance Tuning
Sql Server Performance TuningSql Server Performance Tuning
Sql Server Performance Tuning
 
10 Problems with your RMAN backup script
10 Problems with your RMAN backup script10 Problems with your RMAN backup script
10 Problems with your RMAN backup script
 
Ms sql server architecture
Ms sql server architectureMs sql server architecture
Ms sql server architecture
 
Always on in sql server 2017
Always on in sql server 2017Always on in sql server 2017
Always on in sql server 2017
 
Sql server performance tuning
Sql server performance tuningSql server performance tuning
Sql server performance tuning
 
Parallel Replication in MySQL and MariaDB
Parallel Replication in MySQL and MariaDBParallel Replication in MySQL and MariaDB
Parallel Replication in MySQL and MariaDB
 
Oracle Performance Tuning Fundamentals
Oracle Performance Tuning FundamentalsOracle Performance Tuning Fundamentals
Oracle Performance Tuning Fundamentals
 
Average Active Sessions - OaktableWorld 2013
Average Active Sessions - OaktableWorld 2013Average Active Sessions - OaktableWorld 2013
Average Active Sessions - OaktableWorld 2013
 
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentalsDB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
 
Postgresql tutorial
Postgresql tutorialPostgresql tutorial
Postgresql tutorial
 
Less01 architecture
Less01 architectureLess01 architecture
Less01 architecture
 
Oracle database performance tuning
Oracle database performance tuningOracle database performance tuning
Oracle database performance tuning
 
Christo kutrovsky oracle, memory & linux
Christo kutrovsky   oracle, memory & linuxChristo kutrovsky   oracle, memory & linux
Christo kutrovsky oracle, memory & linux
 
Performance Tuning And Optimization Microsoft SQL Database
Performance Tuning And Optimization Microsoft SQL DatabasePerformance Tuning And Optimization Microsoft SQL Database
Performance Tuning And Optimization Microsoft SQL Database
 
Tanel Poder - Scripts and Tools short
Tanel Poder - Scripts and Tools shortTanel Poder - Scripts and Tools short
Tanel Poder - Scripts and Tools short
 
SQL vs NoSQL | MySQL vs MongoDB Tutorial | Edureka
SQL vs NoSQL | MySQL vs MongoDB Tutorial | EdurekaSQL vs NoSQL | MySQL vs MongoDB Tutorial | Edureka
SQL vs NoSQL | MySQL vs MongoDB Tutorial | Edureka
 
SQL
SQLSQL
SQL
 
Average Active Sessions RMOUG2007
Average Active Sessions RMOUG2007Average Active Sessions RMOUG2007
Average Active Sessions RMOUG2007
 
End-to-end Troubleshooting Checklist for Microsoft SQL Server
End-to-end Troubleshooting Checklist for Microsoft SQL ServerEnd-to-end Troubleshooting Checklist for Microsoft SQL Server
End-to-end Troubleshooting Checklist for Microsoft SQL Server
 

Destacado

Codemotion - Modern Branding en SharePoint desde todos los ángulos
Codemotion - Modern Branding en SharePoint desde todos los ángulosCodemotion - Modern Branding en SharePoint desde todos los ángulos
Codemotion - Modern Branding en SharePoint desde todos los ángulosSantiago Porras Rodríguez
 
Spatial Data in SQL Server
Spatial Data in SQL ServerSpatial Data in SQL Server
Spatial Data in SQL ServerEduardo Castro
 
Unidad 1 algoritmos y programas
Unidad 1 algoritmos y programasUnidad 1 algoritmos y programas
Unidad 1 algoritmos y programasRoberth Camana
 
Variables, tipos de datos, operadores
Variables, tipos de datos, operadores Variables, tipos de datos, operadores
Variables, tipos de datos, operadores juan ventura
 
Identificadores Graficos
Identificadores GraficosIdentificadores Graficos
Identificadores Graficosbloody-crow
 
Foro Universidades 2014. Pensando en la nube - SharePoint como Web Corporativa
Foro Universidades 2014. Pensando en la nube - SharePoint como Web CorporativaForo Universidades 2014. Pensando en la nube - SharePoint como Web Corporativa
Foro Universidades 2014. Pensando en la nube - SharePoint como Web Corporativawww.encamina.com
 
Consideraciones de discos sql server hardware
Consideraciones de discos sql server hardwareConsideraciones de discos sql server hardware
Consideraciones de discos sql server hardwareEduardo Castro
 
Servicios cognitivos y su integración
Servicios cognitivos y su integraciónServicios cognitivos y su integración
Servicios cognitivos y su integraciónEduardo Castro
 
Introduccion a Big Data stack
Introduccion a Big Data stackIntroduccion a Big Data stack
Introduccion a Big Data stackEduardo Castro
 
Consideraciones de memoria sql server hardware
Consideraciones de memoria sql server hardwareConsideraciones de memoria sql server hardware
Consideraciones de memoria sql server hardwareEduardo Castro
 
Vistazo a lo nuevo en SQL Server 2016
Vistazo a lo nuevo en SQL Server 2016Vistazo a lo nuevo en SQL Server 2016
Vistazo a lo nuevo en SQL Server 2016Eduardo Castro
 
Consideraciones de sql server hardware
Consideraciones de sql server hardwareConsideraciones de sql server hardware
Consideraciones de sql server hardwareEduardo Castro
 
Charla windows 10 para Empresas
Charla windows 10 para EmpresasCharla windows 10 para Empresas
Charla windows 10 para EmpresasEduardo Castro
 
SQL Server Query Processor
SQL Server Query ProcessorSQL Server Query Processor
SQL Server Query ProcessorEduardo Castro
 
Interfaz base de datos
Interfaz base de datosInterfaz base de datos
Interfaz base de datosariandrea
 
Cabildo abierto ETB - presentación Aurelio Suárez
Cabildo abierto ETB - presentación Aurelio SuárezCabildo abierto ETB - presentación Aurelio Suárez
Cabildo abierto ETB - presentación Aurelio SuárezAurelio Suárez
 

Destacado (20)

Codemotion - Modern Branding en SharePoint desde todos los ángulos
Codemotion - Modern Branding en SharePoint desde todos los ángulosCodemotion - Modern Branding en SharePoint desde todos los ángulos
Codemotion - Modern Branding en SharePoint desde todos los ángulos
 
Spatial Data in SQL Server
Spatial Data in SQL ServerSpatial Data in SQL Server
Spatial Data in SQL Server
 
Unidad 1 algoritmos y programas
Unidad 1 algoritmos y programasUnidad 1 algoritmos y programas
Unidad 1 algoritmos y programas
 
Variables, tipos de datos, operadores
Variables, tipos de datos, operadores Variables, tipos de datos, operadores
Variables, tipos de datos, operadores
 
EO_0317
EO_0317EO_0317
EO_0317
 
Identificadores Graficos
Identificadores GraficosIdentificadores Graficos
Identificadores Graficos
 
Formato neissen
Formato neissenFormato neissen
Formato neissen
 
Foro Universidades 2014. Pensando en la nube - SharePoint como Web Corporativa
Foro Universidades 2014. Pensando en la nube - SharePoint como Web CorporativaForo Universidades 2014. Pensando en la nube - SharePoint como Web Corporativa
Foro Universidades 2014. Pensando en la nube - SharePoint como Web Corporativa
 
Consideraciones de discos sql server hardware
Consideraciones de discos sql server hardwareConsideraciones de discos sql server hardware
Consideraciones de discos sql server hardware
 
Microsoft R Server
Microsoft R ServerMicrosoft R Server
Microsoft R Server
 
Servicios cognitivos y su integración
Servicios cognitivos y su integraciónServicios cognitivos y su integración
Servicios cognitivos y su integración
 
Introduccion a Big Data stack
Introduccion a Big Data stackIntroduccion a Big Data stack
Introduccion a Big Data stack
 
Consideraciones de memoria sql server hardware
Consideraciones de memoria sql server hardwareConsideraciones de memoria sql server hardware
Consideraciones de memoria sql server hardware
 
Vistazo a lo nuevo en SQL Server 2016
Vistazo a lo nuevo en SQL Server 2016Vistazo a lo nuevo en SQL Server 2016
Vistazo a lo nuevo en SQL Server 2016
 
Consideraciones de sql server hardware
Consideraciones de sql server hardwareConsideraciones de sql server hardware
Consideraciones de sql server hardware
 
Charla windows 10 para Empresas
Charla windows 10 para EmpresasCharla windows 10 para Empresas
Charla windows 10 para Empresas
 
발표자료
발표자료발표자료
발표자료
 
SQL Server Query Processor
SQL Server Query ProcessorSQL Server Query Processor
SQL Server Query Processor
 
Interfaz base de datos
Interfaz base de datosInterfaz base de datos
Interfaz base de datos
 
Cabildo abierto ETB - presentación Aurelio Suárez
Cabildo abierto ETB - presentación Aurelio SuárezCabildo abierto ETB - presentación Aurelio Suárez
Cabildo abierto ETB - presentación Aurelio Suárez
 

Similar a SQL Server Wait Types Everyone Should Know

SQL Explore 2012: P&T Part 1
SQL Explore 2012: P&T Part 1SQL Explore 2012: P&T Part 1
SQL Explore 2012: P&T Part 1sqlserver.co.il
 
Roman Rehak: 24/7 Database Administration + Database Mail Unleashed
Roman Rehak: 24/7 Database Administration + Database Mail UnleashedRoman Rehak: 24/7 Database Administration + Database Mail Unleashed
Roman Rehak: 24/7 Database Administration + Database Mail UnleashedMSDEVMTL
 
Presto At Treasure Data
Presto At Treasure DataPresto At Treasure Data
Presto At Treasure DataTaro L. Saito
 
Practical examples of using extended events
Practical examples of using extended eventsPractical examples of using extended events
Practical examples of using extended eventsDean Richards
 
Day 7 - Make it Fast
Day 7 - Make it FastDay 7 - Make it Fast
Day 7 - Make it FastBarry Jones
 
MySQL Performance Tuning at COSCUP 2014
MySQL Performance Tuning at COSCUP 2014MySQL Performance Tuning at COSCUP 2014
MySQL Performance Tuning at COSCUP 2014Ryusuke Kajiyama
 
Collaborate 2011-tuning-ebusiness-416502
Collaborate 2011-tuning-ebusiness-416502Collaborate 2011-tuning-ebusiness-416502
Collaborate 2011-tuning-ebusiness-416502kaziul Islam Bulbul
 
Collaborate 2019 - How to Understand an AWR Report
Collaborate 2019 - How to Understand an AWR ReportCollaborate 2019 - How to Understand an AWR Report
Collaborate 2019 - How to Understand an AWR ReportAlfredo Krieg
 
Oracle database performance tuning
Oracle database performance tuningOracle database performance tuning
Oracle database performance tuningAbishek V S
 
Scaling apps for the big time
Scaling apps for the big timeScaling apps for the big time
Scaling apps for the big timeproitconsult
 
Visibility-from web application interface to the database
Visibility-from web application interface to the databaseVisibility-from web application interface to the database
Visibility-from web application interface to the databaseManageEngine, Zoho Corporation
 
SQL Server Tuning to Improve Database Performance
SQL Server Tuning to Improve Database PerformanceSQL Server Tuning to Improve Database Performance
SQL Server Tuning to Improve Database PerformanceMark Ginnebaugh
 
collab2011-tuning-ebusiness-421966.pdf
collab2011-tuning-ebusiness-421966.pdfcollab2011-tuning-ebusiness-421966.pdf
collab2011-tuning-ebusiness-421966.pdfElboulmaniMohamed
 
Performance Tuning
Performance TuningPerformance Tuning
Performance TuningJannet Peetz
 
(ATS4-PLAT08) Server Pool Management
(ATS4-PLAT08) Server Pool Management(ATS4-PLAT08) Server Pool Management
(ATS4-PLAT08) Server Pool ManagementBIOVIA
 
Why & how to optimize sql server for performance from design to query
Why & how to optimize sql server for performance from design to queryWhy & how to optimize sql server for performance from design to query
Why & how to optimize sql server for performance from design to queryAntonios Chatzipavlis
 

Similar a SQL Server Wait Types Everyone Should Know (20)

SQL Explore 2012: P&T Part 1
SQL Explore 2012: P&T Part 1SQL Explore 2012: P&T Part 1
SQL Explore 2012: P&T Part 1
 
Roman Rehak: 24/7 Database Administration + Database Mail Unleashed
Roman Rehak: 24/7 Database Administration + Database Mail UnleashedRoman Rehak: 24/7 Database Administration + Database Mail Unleashed
Roman Rehak: 24/7 Database Administration + Database Mail Unleashed
 
Breaking data
Breaking dataBreaking data
Breaking data
 
Presto At Treasure Data
Presto At Treasure DataPresto At Treasure Data
Presto At Treasure Data
 
Practical examples of using extended events
Practical examples of using extended eventsPractical examples of using extended events
Practical examples of using extended events
 
Day 7 - Make it Fast
Day 7 - Make it FastDay 7 - Make it Fast
Day 7 - Make it Fast
 
MySQL Performance Tuning at COSCUP 2014
MySQL Performance Tuning at COSCUP 2014MySQL Performance Tuning at COSCUP 2014
MySQL Performance Tuning at COSCUP 2014
 
Collaborate 2011-tuning-ebusiness-416502
Collaborate 2011-tuning-ebusiness-416502Collaborate 2011-tuning-ebusiness-416502
Collaborate 2011-tuning-ebusiness-416502
 
Unit 2 oracle9i
Unit 2  oracle9i Unit 2  oracle9i
Unit 2 oracle9i
 
Collaborate 2019 - How to Understand an AWR Report
Collaborate 2019 - How to Understand an AWR ReportCollaborate 2019 - How to Understand an AWR Report
Collaborate 2019 - How to Understand an AWR Report
 
Oracle database performance tuning
Oracle database performance tuningOracle database performance tuning
Oracle database performance tuning
 
Scaling apps for the big time
Scaling apps for the big timeScaling apps for the big time
Scaling apps for the big time
 
Visibility-from web application interface to the database
Visibility-from web application interface to the databaseVisibility-from web application interface to the database
Visibility-from web application interface to the database
 
SQL Server Tuning to Improve Database Performance
SQL Server Tuning to Improve Database PerformanceSQL Server Tuning to Improve Database Performance
SQL Server Tuning to Improve Database Performance
 
collab2011-tuning-ebusiness-421966.pdf
collab2011-tuning-ebusiness-421966.pdfcollab2011-tuning-ebusiness-421966.pdf
collab2011-tuning-ebusiness-421966.pdf
 
Performance Tuning
Performance TuningPerformance Tuning
Performance Tuning
 
Dal deck
Dal deckDal deck
Dal deck
 
(ATS4-PLAT08) Server Pool Management
(ATS4-PLAT08) Server Pool Management(ATS4-PLAT08) Server Pool Management
(ATS4-PLAT08) Server Pool Management
 
Why & how to optimize sql server for performance from design to query
Why & how to optimize sql server for performance from design to queryWhy & how to optimize sql server for performance from design to query
Why & how to optimize sql server for performance from design to query
 
A12 vercelletto indexing_techniques
A12 vercelletto indexing_techniquesA12 vercelletto indexing_techniques
A12 vercelletto indexing_techniques
 

Último

Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 

Último (20)

Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 

SQL Server Wait Types Everyone Should Know

  • 1. SQL Server Wait Types Everyone Should Know Dean Richards
  • 2. Who Am I • 20+ years of experience in SQL Server and Oracle • Speak at many user groups throughout US • Owner of DRConsulting • Dean.Richards@databaseperformance.guru • @ConfioDean • Focus on application and database performance • Review performance for hundreds of customers per year • Common thread – how do I do performance tuning?
  • 3. What Are Wait Types • SQL Server has been instrumented to give clues about what it is doing when processing SQL statements • Wait Types identify a step being taken by SQL statement and its latencies • These clues help immensely when doing SQL analysis/tuning • Knowing a SQL waits on locking issues will lead to a different solution than if it were waiting on disk reads • SQL Server 2012 – 649 Wait Types • SQL Server 2014 – 800+ Waits • For a more complete description (for SQL 2005 but still relevant) • Microsoft Waits and Queue Document
  • 4. Useful DMVs for Wait Types • sys.dm_os_wait_stats • Cumulative since instance startup • select * from sys.dm_os_wait_stats order by wait_time_ms desc • Exclude idle wait types in slide notes • Provides a view into what your instance is waiting for • sys.dm_exec_requests • Real-time view into what each session/SQL is waiting for • See slide notes for example query • Suspended state means the session is waiting for the wait_type • Running means the session is on the CPU • Sleeping means the session is idle
  • 5. Wait Type DMV Problem • No Time Based View • What happened between 3am-5am this morning is not possible to get from the DMV objects • Need to use other tools • Extended Events Session to gather waits and query results • System_health default session *does not* gather waits • Solarwinds Database Performance Analyzer (DPA formerly Confio Ignite) does a great job of this • DPA provides great views into which SQLs are problematic and what they are waiting for. Also includes a knowledge base for many wait types. Different DMV Problem
  • 6. Top 8 List of Wait Types • From my experience, there is a small list of wait types you need to know well • The other 500+ you can Google or ask Microsoft • Need to know: • What causes these waits • How to reduce / fix these waits • This presentation discusses common wait types I have personally encountered the most from over 400 customers
  • 7. 1. PAGEIOLATCH_* • Disk read when a page required by a SQL is not in the buffer cache • Where * in: • SH – shared: session reads the data • EX – exclusive: session needs exclusive access to page • UP – update: session needs to update data • DT – destroy: session needs to remove the page • KP – keep: temporary while SQL Server decides • NL – undocumented • The SH, EX and UP latches are by far the most common
  • 8. 1. PAGEIOLATCH_* Solutions • Do fewer disk reads • Tune the SQL statement to do less I/O • Cache more data, i.e. bigger buffer cache so disk reads no needed • Many SQLs waiting – bigger cache may help • A few SQLs waiting – probably means SQL tuning • Use query in notes to check MB/sec – are you trying to read/write way too much data and overloading disks – tune SQL. • Make disk reads faster • Check file/disk latency with sys.dm_io_virtual_file_stats DMO • Use query in notes • Anything higher than ~ 15 ms would be considered slow on a production class server • Talk to storage team but remember there are many layers between the database and storage, i.e. O/S, virtualization, network, etc
  • 9. 2. WRITELOG • Waiting for a log flush to complete • Log flush commonly occurs because of checkpoint or commit • Commits can be explicit (commit) or implicit (auto-commit)
  • 10. 2. WRITELOG Solutions • Do less work • Develop code to do more batch processing • Single row processing inside loop rather than set based processing? • Make disk writes faster • Avoid RAID5/6 – write I/O penalty • Check file/disk latency with sys.dm_io_virtual_file_stats DMO • Review the write latencies for the transaction logs • Reduce I/O contention on disks containing logs • Solid State? – many questions about this but several test cases have seen good results • Size the transaction logs properly – see notes for a good references on this subject
  • 11. 3. ASYNC_NETWORK_IO • Query produces result set and sends back to client. While client processes data SQL Server waits on this • Often caused by large result sets being returned • Application that queries every row from large tables • See MS Access joining SQL Server data to Access data. Access must get all data in SQL table, bring back to Access to join it. Will see “select * from <large table>” queries • Can also apply to linked server queries • Slow client processing • Client machine is very busy and not processing results quickly • Client is reading data and doing processing on it that is slow • Could be a slow network connection from client to server
  • 12. 3. ASYNC_NETWORK_IO Solutions • Limit the result sets • Some poorly written applications read data from entire table and then filter at client. Filter from database first or write rows to temp table and have client read temp data • Avoid joins across Access to SQL Server data. This also applies to Linked Server and other distributed queries • Check performance of client machine. If it is resource constrained, it may not process results quickly • Check logic of client application and avoid retrieving large result sets if possible. Do more result set processing in database • Check the speed and stability of the network between client and server.
  • 13. 4. CXPACKET • Session is running a SQL in parallel • More of a status and not necessarily a problem. May be very normal for data warehouse but less so for OLTP • Master process will farm work out to slave processes and then wait on CXPACKET until all have completed • SQL Server will try to parallel-ize big queries up to MAXDOP – can be set instance wide down to this query • MAXDOP = 0 by default meaning unlimited • http://support.microsoft.com/kb/2806535 - recommendations • MAXDOP should not be set higher than 8 in most cases
  • 14. 4. CXPACKET More Information • Need to understand the slave processes and what they are doing / waiting for • Use sys.dm_os_waiting_tasks select session_id, exec_context_id, wait_type, wait_duration_ms, resource_description from sys.dm_os_waiting_tasks where session_id in ( select session_id from sys.dm_exec_requests where wait_type='CXPACKET') order by session_id, exec_context_id • Example Output session_id exec_context_id wait_type wait_duration_ms resource_description 64 0 CXPACKET 417920 64 1 PAGEIOLATCH_SH 149 5:1:1358830 64 2 PAGEIOLATCH_SH 368 5:1:3514639 64 3 PAGEIOLATCH_SH 84 5:1:3484089 64 4 PAGEIOLATCH_SH 156 5:1:1348098 • In this case, tune PAGEIOLATCH_SH waits
  • 15. 4. CXPACKET Solutions • Tune MAXDOP according to KB article provided • Not all queries do well in parallel, so experiment with MAXDOP settings at SQL level • Much bad advice about reducing MAXDOP server wide but avoid doing this blanket change • Tune the parallel slave process waits (previous slide) • Inefficient queries reading a lot of data will often be parallel-ized by SQL Server. Tune the queries • Review data skew and bad statistics which can cause one or few slave processes to do a bulk of the work
  • 16. 5. CPU • Not a wait type - identifies time on CPU • Query Response Time = Wait Time (wait types) + Service Time (CPU) • Waiting on CPU when sys.dm_exec_request has: • status = running • wait_type is often null • wait_time = 0 • CPU time is often spent doing logical I/O • Could also come from compiles/recompiles and other CPU intensive operations
  • 17. 5. CPU Solutions • Tune queries with high amount of CPU time and often high logical I/O (see notes) • Reduce high execution count queries – do more batch processing • Check O/S for other activity putting pressure on CPU – may see high CPU queue lengths • Is the hardware undersized – may need to purchase larger/faster servers
  • 18. 6. LCK_M_* • Classic locking/blocking scenario • Where * in 21 different possibilities. Most common are: • U – trying to update the same resource • S – trying to modify data while it is being read • X – trying to lock a resource exclusively • IU, IS, IX – indicates intent to lock • SCH – schema locks – object is changing underneath • A session waiting on LCK_M_* wait is the victim. Need to use blocking_session_id in dm_exec_request to see the root cause (see query in slide notes) • Not to be confused with deadlocks – special locking case
  • 19. 6. LCK_M_* Solutions • Review the wait_description data to understand the locked resource. See slide notes for information. • Review the blocking session and understand the relationship with the blockee. Does the application need to be redesigned? • Blocking issues are often associated with a session holding locks for longer than necessary • Does the blocking session go on to do a lot of other SQLs? Can the transactions be committed sooner? • Does the blocking session execute inefficient SQLs while holding locks? Tuning the poor SQL could reduce the blocking time. • Has the client process waited and finally terminated due to timeouts? The SQL Server session could be left behind (orphaned) and never go away. Terminating the session should release the locks. • Is the client not fetching the whole result set quickly enough? See the ASYNC_NETWORK_IO wait description. • Is the session rolling back data? If so, that process must complete before locks are released
  • 20. 7. PREEMPTIVE_* • Often associated with external calls to O/S etc • Code being executed is outside SQL Server • OS_GETPROCADDRESS – seen with xp_fixeddrives, xp_readerrorlog, etc. Session is going to the O/S to get information • OLEDBOPS – seen with bulk loads from file and other external database operations • OS_AUTHENTICATIONOPS – seen when using xp_fixeddrives • OS_PIPEOPS – seen when using xp_cmdshell
  • 21. 8. PAGELATCH_* • Not as common, but 8 is my lucky number and I needed one more wait type  • Latches synchronize access to internal SQL Server memory structures • Many different classes of latches, but BUFFER is most common, i.e. control access to buffer cache • Where * is the same set of values shown in PAGEIOLATCH waits slide • Not a disk read – do not confuse with PAGEIOLATCH
  • 22. PAGELATCH_* Solutions • Use wait_resource to determine the page waited for. See slide notes for LCK_M_* for decoding this data • Could be TEMPDB contention. Check the wait_resource column from dm_exec_requests to see if the dbid (first part) is 2 to verify. • If so, good document from Microsoft - http://www.microsoft.com/en-gb/ download/details.aspx?id=26665 • Can be caused by index page splitting • Specify fill factors properly • Tune SQL statements waiting for this. Inefficient SQL read more data from memory than needed and increase the likelihood of this wat
  • 23. Summary • Wait Types provide the best information about why a SQL statement is running slow • SQL Server includes several DMVs showing Wait Types but lacks the point in time view which allows you to go back to 3-5am when something was slow • Use Extended Events to collect the data • Use tools like Solarwinds Database Performance Analyzer (DPA) • Memorize these 8 wait types, what causes them, how to fix them and you will be good to go • Contact me at: • Dean.Richards@databaseperformance.guru • @ConfioDean • www.linkedin.com/in/deanrichardsconsulting/

Notas del editor

  1. DM_EXEC_REQUESTS Query SELECT r.session_id, r.wait_time, r.status, r.wait_type, r.blocking_session_id, s.text, r.statement_start_offset, r.statement_end_offset, p.query_plan FROM sys.dm_exec_requests r OUTER APPLY sys.dm_exec_sql_text (r.sql_handle) s OUTER APPLY sys.dm_exec_text_query_plan (r.plan_handle, r.statement_start_offset, r.statement_end_offset) p
  2. select db_name(database_id) [db_name], FILE_NAME(file_id) [file_name], num_of_reads, num_of_bytes_read / 1048576.0 / sample_ms*1000 [read_mb_per_sec], io_stall_read_ms / num_of_reads read_latency, num_of_writes, num_of_bytes_written / 1048576.0 / sample_ms*1000 [write_mb_per_sec], io_stall_write_ms / num_of_writes write_latency from sys.dm_io_virtual_file_stats (null, null)
  3. Transaction Log Sizing - http://sqlmag.com/blog/sizing-your-transaction-log Transaction Log Management – http://www.sqlskills.com/BLOGS/PAUL/post/Importance-of-proper-transaction-log-size-management.aspx
  4. SELECT TOP 10 total_worker_time [CPU Time], SUBSTRING(st.text, (qs.statement_start_offset/2)+1, ((CASE qs.statement_end_offset WHEN -1 THEN DATALENGTH(st.text) ELSE qs.statement_end_offset END - qs.statement_start_offset)/2) + 1) AS sql_text, qs.execution_count, qs.total_logical_reads, qs.total_logical_reads/qs.execution_count [LIO Per Exec], qp.query_plan FROM sys.dm_exec_query_stats AS qs OUTER APPLY sys.dm_exec_sql_text(qs.sql_handle) AS st OUTER APPLY sys.dm_exec_query_plan (qs.sql_handle) qp ORDER BY total_worker_time DESC
  5. See blocker and blockee sessions and what they are doing select r1.session_id, SUBSTRING(s1.text, (r1.statement_start_offset/2)+1, ((CASE r1.statement_end_offset WHEN -1 THEN DATALENGTH(s1.text) ELSE r1.statement_end_offset END - r1.statement_start_offset)/2) + 1) AS blocked_sql_text, r1.blocking_session_id, SUBSTRING(s2.text, (r2.statement_start_offset/2)+1, ((CASE r2.statement_end_offset WHEN -1 THEN DATALENGTH(s2.text) ELSE r2.statement_end_offset END - r2.statement_start_offset)/2) + 1) AS blocker_sql_text, r1.wait_resource from sys.dm_exec_requests r1 left outer join sys.dm_exec_requests r2 on r1.blocking_session_id = r2.session_id outer apply sys.dm_exec_sql_text (r1.sql_handle) s1 outer apply sys.dm_exec_sql_text (r2.sql_handle) s2 where r1.blocking_session_id > 0
  6. Using wait_description data -- usually in 3 parts separated by colons -- example: 5:1:4111532 -- 1st number – database_id – select db_name(5) -- 2nd file number – select * from sys.database_files where file_id=1 -- 3rd page number – see below to get details of that page dbcc traceon (3604) go dbcc page (5, 1, 4111532) -- get ObjectID from output select * from sys.objects where object_id=37575172