{"id":6276,"date":"2019-03-07T13:58:35","date_gmt":"2019-03-07T13:58:35","guid":{"rendered":"https:\/\/ittutorial.org\/?p=6276"},"modified":"2019-11-28T07:06:07","modified_gmt":"2019-11-28T07:06:07","slug":"sql-server-wait-events","status":"publish","type":"post","link":"https:\/\/ittutorial.org\/sql-server-wait-events\/","title":{"rendered":"SQL Server Wait Events -1"},"content":{"rendered":"<p>Hi,<\/p>\n<p>You should find that which of wait events are in the SQL Server database.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6277\" src=\"https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/03\/sql_server_wait_types_in_DPA_494x150.jpg\" alt=\"\" width=\"494\" height=\"150\" srcset=\"https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/03\/sql_server_wait_types_in_DPA_494x150.jpg 494w, https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/03\/sql_server_wait_types_in_DPA_494x150-300x91.jpg 300w\" sizes=\"auto, (max-width: 494px) 100vw, 494px\" \/><\/p>\n<p><!--more--><\/p>\n\n<p>&nbsp;<\/p>\n<p>To solve slowness of SQL Server database, you should find which wait events exists in the database.<\/p>\n<p>You can find wait events of database with following query.<\/p>\n<p>&nbsp;<\/p>\n<pre>with waits as\r\n(select\r\nwait_type,\r\nwait_time_ms \/ 1000.0 as waits,\r\n(wait_time_ms - signal_wait_time_ms) \/ 1000.0 as resources,\r\nsignal_wait_time_ms \/ 1000.0 as signals,\r\nwaiting_tasks_count as waitcount,\r\n100.0 * wait_time_ms \/ sum (wait_time_ms) over() as percentage,\r\nrow_number() over(order by wait_time_ms desc) as rownum\r\nfrom sys.dm_os_wait_stats\r\nwhere wait_type not in (\r\nN'CLR_SEMAPHORE', N'LAZYWRITER_SLEEP',\r\nN'RESOURCE_QUEUE', N'SQLTRACE_BUFFER_FLUSH',\r\nN'SLEEP_TASK', N'SLEEP_SYSTEMTASK',\r\nN'WAITFOR', N'HADR_FILESTREAM_IOMGR_IOCOMPLETION',\r\nN'CHECKPOINT_QUEUE', N'REQUEST_FOR_DEADLOCK_SEARCH',\r\nN'XE_TIMER_EVENT', N'XE_DISPATCHER_JOIN',\r\nN'LOGMGR_QUEUE', N'FT_IFTS_SCHEDULER_IDLE_WAIT',\r\nN'BROKER_TASK_STOP', N'CLR_MANUAL_EVENT',\r\nN'CLR_AUTO_EVENT', N'DISPATCHER_QUEUE_SEMAPHORE',\r\nN'TRACEWRITE', N'XE_DISPATCHER_WAIT',\r\nN'BROKER_TO_FLUSH', N'BROKER_EVENTHANDLER',\r\nN'FT_IFTSHC_MUTEX', N'SQLTRACE_INCREMENTAL_FLUSH_SLEEP',\r\nN'DIRTY_PAGE_POLL', N'SP_SERVER_DIAGNOSTICS_SLEEP')\r\n)\r\nselect\r\nw1.wait_type as waittype, \r\ncast (w1.waits as decimal(14, 2)) wait_s,\r\ncast (w1.resources as decimal(14, 2)) resource_s,\r\ncast (w1.signals as decimal(14, 2)) signal_s,\r\nw1.waitcount wait_count,\r\ncast (w1.percentage as decimal(4, 2)) percentage,\r\ncast ((w1.waits \/ w1.waitcount) as decimal (14, 4)) avgWait_s,\r\ncast ((w1.resources \/ w1.waitcount) as decimal (14, 4)) avgResource_s,\r\ncast ((w1.signals \/ w1.waitcount) as decimal (14, 4)) avgSignal_s\r\nfrom waits as w1\r\ninner join waits as w2 on w2.rownum &lt;= w1.rownum\r\ngroup by w1.rownum, w1.wait_type, w1.waits, w1.resources, w1.signals, w1.waitcount, w1.percentage\r\nhaving sum (w2.percentage) - w1.percentage &lt; 95; -- percentage threshold<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><span style=\"color: #ff0000;\">Do you want to learn Microsoft SQL Server DBA Tutorials for Beginners, then read the following articles.<\/span><\/h4>\n<p><a href=\"https:\/\/ittutorial.org\/sql-server-tutorials-microsoft-database-for-beginners\/\">https:\/\/ittutorial.org\/sql-server-tutorials-microsoft-database-for-beginners\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, You should find that which of wait events are in the SQL Server database.<\/p>\n","protected":false},"author":1,"featured_media":6277,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3828,2227,3827],"tags":[1028,1031,1600,1610,2231,2264,2263,2275,2232,2273,2237,2236,2267,2270,2269,2230,2229,2274,2265,2266],"class_list":["post-6276","post","type-post","status-publish","format-standard","has-post-thumbnail","","category-sql-scripts","category-sql-server-2","category-sql-server-dba-scripts","tag-mehmet-deveci","tag-mehmet-salih-deveci","tag-sql-server-2012","tag-sql-server-2014","tag-sql-server-2019","tag-sql-server-active-sessions","tag-sql-server-active-sessions-and-status","tag-sql-server-database-wait-events","tag-sql-server-inventory-script","tag-sql-server-optimizer","tag-sql-server-select-inventory","tag-sql-server-select-machine-name","tag-sql-server-sessions","tag-sql-server-statistics","tag-sql-server-stats","tag-sql-server-useful-query","tag-sql-server-useful-script","tag-sql-server-wait-events","tag-sql-server-whoisactive","tag-whoisactive"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/03\/sql_server_wait_types_in_DPA_494x150.jpg","jetpack_sharing_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts\/6276","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/comments?post=6276"}],"version-history":[{"count":3,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts\/6276\/revisions"}],"predecessor-version":[{"id":12972,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts\/6276\/revisions\/12972"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/media\/6277"}],"wp:attachment":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/media?parent=6276"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/categories?post=6276"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/tags?post=6276"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}