TSQL Scripts for Troubleshooting Common Issues with SQL Server

Published Mar 16 2022 04:25 AM 1,837 Views
Microsoft

This blog provides TSQL samples for troubleshooting common SQL Server issues as listed below. You can modify the parameters (i.e. database name, table name, keyword name, duration, etc.) based on customized environment settings and requirements. (Test these scripts before implementing in PROD environment. Please be aware of all potential risks for implementing the script in your PROD environment.)

 

1. Performance Troubleshooting(blocking, high CPU, memory, idle, query execution)

2. Deadlock and Database Object ID mapping

3. HA (Clustered SQL Server)

4. Backup & Transaction Log Related Issue

5. Query Store (QDS)

6. Database Encryption (TDE)

7. Tool (Profiler trace and X-event)

 

 

 

Performance Troubleshooting

=========================

(blocking, high CPU, memory, idle, query execution)

 

 

       1.List all active sessions and its queries that contain your target table name or specific TSQL structure (input your target key word)

 

SELECT sqltext.TEXT,

req.session_id,

req.status,

req.command,

req.cpu_time,req.database_id,

req.total_elapsed_time

FROM sys.dm_exec_requests req

CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS sqltext where sqltext.text like '%Your Target Key Word%'

 

 

 

        2.List all sleeping user sessions that have been idle for over 15 minutes with detailed queries (You can customize the session’s status and idle time)

 

SELECT CURRENT_TIMESTAMP as currenttime, datediff(minute,last_batch,GETDATE()) as 'idletime_in_minute' ,sp.status,sp.spid,sp.login_time,sp.program_name,sp.hostprocess,sp.loginame,text FROM sys.sysprocesses sp CROSS APPLY sys.dm_exec_sql_text(sp.sql_handle) AS QT where sp.status = 'sleeping' and datediff(minute,last_batch,GETDATE()) >15 and spid>50

 

 

 

         3.List top 10 high CPU queries that currently running in this SQL instance

 

SELECT s.session_id,r.status,r.blocking_session_id 'Blk by',r.wait_type,wait_resource,r.wait_time / (1000 * 60) 'Wait M',r.cpu_time,r.logical_reads,r.reads,r.writes,r.total_elapsed_time / (1000 * 60) 'Elaps M',Substring(st.TEXT,(r.statement_start_offset / 2) + 1,

((CASE r.statement_end_offset WHEN -1 THEN Datalength(st.TEXT) ELSE r.statement_end_offset END - r.statement_start_offset) / 2) + 1) AS statement_text,

Coalesce(Quotename(Db_name(st.dbid)) + N'.' + Quotename(Object_schema_name(st.objectid, st.dbid)) + N'.' + Quotename(Object_name(st.objectid, st.dbid)), '') AS command_text,r.command,s.login_name,

s.host_name,s.program_name,s.last_request_end_time,s.login_time, r.open_transaction_count FROM sys.dm_exec_sessions AS s JOIN sys.dm_exec_requests AS r ON r.session_id = s.session_id

CROSS APPLY sys.Dm_exec_sql_text(r.sql_handle) AS st WHERE r.session_id != @@SPID ORDER BY r.cpu_time desc

 

 

        4. List top 10 high memory usage queries that currently running in this SQL instance

SELECT mg.session_id,mg.granted_memory_kb,mg.requested_memory_kb,mg.ideal_memory_kb,mg.request_time,mg.grant_time,mg.query_cost,mg.dop,st.[TEXT],qp.query_plan

FROM sys.dm_exec_query_memory_grants AS mg CROSS APPLY sys.dm_exec_sql_text(mg.plan_handle) AS st

CROSS APPLY sys.dm_exec_query_plan(mg.plan_handle) AS qp ORDER BY mg.required_memory_kb DESC

 

       5. List detailed memory usage for each memory clerk

DBCC MEMORYSTATUS

 

      6. List memory usage for plan cache and its maximum size based on current setting. By removing the WHERE condition, you will get a full list for all memory cache clerks’ information

 

select name, type, buckets_count

from sys.dm_os_memory_cache_hash_tables

where name IN ( 'SQL Plans' , 'Object Plans' , 'Bound Trees' ,'Extended Stored Procedures')

 

select name, type, pages_kb, entries_count

from sys.dm_os_memory_cache_counters

where name IN ( 'SQL Plans' , 'Object Plans' ,  'Bound Trees' ,'Extended Stored Procedures')

 

 

       7. List progressive (on-going) execution plan for a specific session (Starting with SQL 2016)

  • For SQL 2016 and 2017, please first run below TSQL in the query session of which the execution plan you wish to extract later

                  set statistics profile on

  • Run below query to extract the on-going execution plan for your target session (input the SPID in the bracket)

        SELECT * FROM sys.dm_exec_query_statistics_xml(59);

 

 

       8.List all block header queries that currently detected in this SQL instance

 

declare @blocker varchar(100),@sql varchar(100)

print convert(varchar(20), getdate(),120)

   select distinct blocked into #blocker from sysprocesses where blocked <> 0

   DECLARE blocker CURSOR FOR

   select spid from sysprocesses where spid in (select * from #blocker) and blocked = 0

   OPEN blocker

   FETCH NEXT

      FROM blocker

      INTO @blocker

 

   WHILE @@FETCH_STATUS = 0

   BEGIN     

       set @sql='DBCC inputbuffer(' + @blocker + ')'

       execute (@sql)

    set @sql= 'select * from sysprocesses where spid=' + @blocker

    execute (@sql)

 

          FETCH NEXT

         FROM blocker

         INTO @blocker

   END

   CLOSE blocker

   DEALLOCATE blocker

   drop table #blocker

 

      9.Kill all sleeping sessions that has been idle over 1 hour (You can customize the idle duration)

 

DECLARE @user_spid INT

DECLARE CurSPID CURSOR FAST_FORWARD

FOR

SELECT SPID

FROM master.dbo.sysprocesses (NOLOCK)

WHERE spid>50

AND status='sleeping' -- only sleeping threads

AND DATEDIFF(HOUR,last_batch,GETDATE())>=1 -- thread sleeping for 1 hours

AND spid<>@@spid -- ignore current spid

OPEN CurSPID

FETCH NEXT FROM CurSPID INTO @user_spid

WHILE (@@FETCH_STATUS=0)

BEGIN

PRINT 'Killing '+CONVERT(VARCHAR,@user_spid)

EXEC('KILL '+@user_spid)

FETCH NEXT FROM CurSPID INTO @user_spid

END

CLOSE CurSPID

DEALLOCATE CurSPID

GO

 

 

       10.Kill all block headers. This script will continuously scan every 5 seconds for all block header sessions and kill all block headers

 

 

Use master

go

 

while 1=1

Begin

declare @blocker varchar(100),@sql varchar(100)

print convert(varchar(20), getdate(),120)

   select distinct blocked into #blocker from sysprocesses where blocked <> 0

   DECLARE blocker CURSOR FOR

   select spid from sysprocesses where spid in (select * from #blocker) and status='sleeping'

   OPEN blocker

 

   FETCH NEXT

      FROM blocker

      INTO @blocker

 

   WHILE @@FETCH_STATUS = 0

   BEGIN     

       set @sql='DBCC inputbuffer(' + @blocker + ')'

       execute (@sql)

    set @sql= 'kill ' + @blocker

    execute (@sql)

 

          FETCH NEXT

         FROM blocker

         INTO @blocker

   END

    CLOSE blocker

   DEALLOCATE blocker

   drop table #blocker

waitfor delay '0:0:05'

End

 

 

Deadlock and Database Object ID mapping

===================================

Below are 3 examples to map the issued object based on the ID to its source database, index or schema. 

 

           1. Key type wait resource

 

waitresource=KEY: 6:12345678990 (987654321a9b)

  • database_id = 6
  • hobt_id = 12345678990
  • hash value = (987654321a9b)

 

  • We can use below TSQL to check the database name based on DATABASE ID

select db_name(6)

 

  • Use below TSQL to check the schema, object, and index details related to this key

USE DatabaseName

GO

SELECT

   sc.name as schema_name,

    so.name as object_name,

    si.name as index_name

FROM sys.partitions AS p

JOIN sys.objects as so on

    p.object_id=so.object_id

JOIN sys.indexes as si on

    p.index_id=si.index_id and

    p.object_id=si.object_id

JOIN sys.schemas AS sc on

    so.schema_id=sc.schema_id

WHERE hobt_id = 12345678990

 

         2. Object Wait resource type

 

waitresource=OBJECT: 6:1234567890:4 

  • database_id = 6
  • Object ID = 1234567890

 

We can use below TSQL to check the specific object name based on the waitresource details

 

select OBJECT_NAME(1234567890,6) 

 

         3. Page Wait Resource Type

 

waitresource=“PAGE: 6:3:70133 ” = Database_Id : FileId : PageNumber

 

  • database_id=6
  • data_file_id = 3
  • page_number = 70133

 

HA (Clustered SQL Server)

===================

  1. List the latest error encountered by local AG replica for connection timeout

select r.replica_server_name, r.endpoint_url,

rs.connected_state_desc, rs.last_connect_error_description,

rs.last_connect_error_number, rs.last_connect_error_timestamp

from sys.dm_hadr_availability_replica_states rs join sys.availability_replicas r

on rs.replica_id=r.replica_id

where rs.is_local=1

 

  1. List the current redo rate, redo queue size, log send rate, log send queue size for current AG replica

SELECT CURRENT_TIMESTAMP as currenttime,drs.last_commit_time,ar.replica_server_name, adc.database_name, ag.name AS ag_name, drs.is_local, drs.is_primary_replica, drs.log_send_queue_size, drs.log_send_rate, drs.redo_queue_size, drs.redo_rate FROM sys.dm_hadr_database_replica_states AS drs INNER JOIN sys.availability_databases_cluster AS adc ON drs.group_id = adc.group_id AND drs.group_database_id = adc.group_database_id INNER JOIN sys.availability_groups AS ag ON ag.group_id = drs.group_id INNER JOIN sys.availability_replicas AS ar ON drs.group_id = ar.group_id AND drs.replica_id = ar.replica_id

 

  1. Restart endpoint
    • Check SQL AG endpoint name

SELECT * FROM sys.endpoints

  • Restart AG endpoint on this local replica

ALTER ENDPOINT <Your AG Endpoint Name> STATE=STOPPED 

ALTER ENDPOINT <Your AG Endpoint Name> STATE=STARTED

 

 

Backup & Transaction Log Related Issue

================================

  1. List all backup history and backup file details for the past 7 days (You can modify the date)

 

SELECT CONVERT(CHAR(100), SERVERPROPERTY('Servername')) AS Server, msdb.dbo.backupset.database_name, msdb.dbo.backupset.backup_start_date, msdb.dbo.backupset.backup_finish_date, msdb.dbo.backupset.expiration_date,

CASE msdb..backupset.type WHEN 'D' THEN 'Database' WHEN 'L' THEN 'Log' END AS backup_type, msdb.dbo.backupset.backup_size, msdb.dbo.backupmediafamily.logical_device_name,

msdb.dbo.backupmediafamily.physical_device_name, msdb.dbo.backupset.name AS backupset_name, msdb.dbo.backupset.description

FROM msdb.dbo.backupmediafamily INNER JOIN msdb.dbo.backupset ON msdb.dbo.backupmediafamily.media_set_id = msdb.dbo.backupset.media_set_id

WHERE (CONVERT(datetime, msdb.dbo.backupset.backup_start_date, 102) >= GETDATE() - 7)

ORDER BY msdb.dbo.backupset.database_name, msdb.dbo.backupset.backup_finish_date

 

  1. List all databases’ data and log file path and logical name

USE master;

SELECT name 'Logical Name', physical_name 'File Location' FROM sys.master_files;

 

  1. List each database’ transaction log size usage and space

DBCC SQLPERF(LOGSPACE)

 

  1. List VLF size and counts for all databases as well as detailed size for your target database

select * from sys.dm_db_log_info(5); /*input here your DB ID to get detailed size for existing VLFs on this database*/

SELECT [name], s.database_id,

COUNT(l.database_id) AS 'VLF Count',

SUM(vlf_size_mb) AS 'VLF Size (MB)',

SUM(CAST(vlf_active AS INT)) AS 'Active VLF',

SUM(vlf_active*vlf_size_mb) AS 'Active VLF Size (MB)',

COUNT(l.database_id)-SUM(CAST(vlf_active AS INT)) AS 'In-active VLF',

SUM(vlf_size_mb)-SUM(vlf_active*vlf_size_mb) AS 'In-active VLF Size (MB)'

FROM sys.databases s

CROSS APPLY sys.dm_db_log_info(s.database_id) l

GROUP BY [name], s.database_id

ORDER BY 'VLF Count' DESC

GO

 

  1. For the purpose of shrinking transaction log file, check the log_reuse_wait_desc type for all database

select name,database_id,log_reuse_wait, log_reuse_wait_desc from sys.databases

 

Please refer this link for how to fix each of the log_reuse_wait_desc type when it is not “NOTHING”  https://docs.microsoft.com/en-us/sql/relational-databases/system-catalog-views/sys-databases-transac...

  1. Database Corruption Issue

Force repair of database with REPAIR_ALLOW_DATA_LOSS option (data loss expected and sometimes can cause more damage. Please refrain from using this method unless as for a last resort. More details for fixing database corruption, please refer this link https://docs.microsoft.com/en-us/sql/t-sql/database-console-commands/dbcc-checkdb-transact-sql?view=...)

 

Alter database YourDBName set single_user with rollback immediate;

DBCC CHECKDB('YourDBName', REPAIR_ALLOW_DATA_LOSS);

Alter database YourDBName set multi_user with rollback immediate;

 

Query Store (QDS)

=================

 

1.List a database’s query store status

 

select * from sys.database_query_store_options

 

 2. List all databases that have query store configured

 

select name as 'DATABASE NAME',

CASE is_query_store_on when 1 then 'ENABLED'

else 'OTHER' END AS 'QUERY STORE STATE'

from sys.databases

where is_query_store_on = 1

order by 1 ;

 

Database Encryption (TDE)

======================

  1. Check if the DMK exist in master database

 

USE master

GO

 

SELECT * FROM sys.symmetric_keys WHERE name = '##MS_DatabaseMasterKey##'

 

  1. Check if the certificate is created in master database. A certificate is equivalent to an asymmetric key

 

USE master

GO

 

select * from sys.certificates

 

  1. Check if the database is encrypted/progress (encryption_state = 3 encrypted; =2 in progress)

 

 

USE master

GO

SELECT db_name(database_id) [TDE Encrypted DB Name], c.name as CertName, encryptor_thumbprint , dek.*     FROM sys.dm_database_encryption_keys dek     INNER JOIN sys.certificates c on dek.encryptor_thumbprint = c.thumbprint

 

  1. Check if the DMK in the master database is now encrypted by the SMK (is_master_key_encrypted_by_server = 1)

 

select is_master_key_encrypted_by_server, * from sys.databases

where database_id = db_id(N'master')

 

 

Tool (Profiler trace and X-event)

=======================

 

  1. Import SQL Profiler trace into SQL Server database tables

USE DatabaseName

GO

select * into Sample from fn_trace_gettable('c:\trace\YourFolderToStoreTheTrace\YourTraceFile.trc',default) where eventclass in (10, 12)

 

For event class ID, check the list in this link https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-trace-setevent...

  1. Use XELoader to process X-event and import the data into SQL database table for data analysis purpose.

 

  • XELoader can be downloaded from this opensource link

https://github.com/suresh-kandoth/XELoader

 

  • Use CMD script to load the X-event files into SQL Server database

Sample script:

 

C:\XELoader\6.2>XELoader.exe -D"C:\Users\yixin\Desktop\xeloader\xevent" -SYourServerName\InstanceName -dYourDBName

 

  • Use TSQL query to check aggregated data result

 

Sample TSQL:

 

SELECT sum(c_duration) as SUM_DURAION,sum(c_signal_duration) as SUM_SIGNAL_DURATION,c_wait_type from [xel].[wait_info] group by c_wait_type order by SUM_DURAION desc

 

 

DISCLAIMER : THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.

 

%3CLINGO-SUB%20id%3D%22lingo-sub-3258618%22%20slang%3D%22en-US%22%3ETSQL%20Scripts%20for%20Troubleshooting%20Common%20Issues%20with%20SQL%20Server%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3258618%22%20slang%3D%22en-US%22%3E%3CP%3EThis%20blog%20provides%20TSQL%20samples%20for%20troubleshooting%20common%20SQL%20Server%20issues%20as%20listed%20below.%20You%20can%20modify%20the%20parameters%20(i.e.%20database%20name%2C%20table%20name%2C%20keyword%20name%2C%20duration%2C%20etc.)%20based%20on%20customized%20environment%20settings%20and%20requirements.%20(Test%20these%20scripts%20before%20implementing%20in%20PROD%20environment.%20Please%20be%20aware%20of%20all%20potential%20risks%20for%20implementing%20the%20script%20in%20your%20PROD%20environment.)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E1.%20Performance%20Troubleshooting(blocking%2C%20high%20CPU%2C%20memory%2C%20idle%2C%20query%20execution)%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E2.%26nbsp%3BDeadlock%20and%20Database%20Object%20ID%20mapping%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E3.%26nbsp%3BHA%20(Clustered%20SQL%20Server)%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E4.%20Backup%20%26amp%3B%20Transaction%20Log%20Related%20Issue%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E5.%26nbsp%3BQuery%20Store%20(QDS)%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E6.%26nbsp%3BDatabase%20Encryption%20(TDE)%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E7.%20Tool%20(Profiler%20trace%20and%20X-event)%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EPerformance%20Troubleshooting%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E(blocking%2C%20high%20CPU%2C%20memory%2C%20idle%2C%20query%20execution)%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B1.List%20all%20active%20sessions%20and%20its%20queries%20that%20contain%20your%20target%20table%20name%20or%20specific%20TSQL%20structure%20(input%20your%20target%20key%20word)%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3ESELECT%20sqltext.TEXT%2C%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Ereq.session_id%2C%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Ereq.status%2C%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Ereq.command%2C%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Ereq.cpu_time%2Creq.database_id%2C%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Ereq.total_elapsed_time%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EFROM%20sys.dm_exec_requests%20req%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3ECROSS%20APPLY%20sys.dm_exec_sql_text(sql_handle)%20AS%20sqltext%20where%20sqltext.text%20like%20'%25Your%20Target%20Key%20Word%25'%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%202.List%20all%20sleeping%20user%20sessions%20that%20have%20been%20idle%20for%20over%2015%20minutes%20with%20detailed%20queries%20(You%20can%20customize%20the%20session%E2%80%99s%20status%20and%20idle%20time)%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3ESELECT%20CURRENT_TIMESTAMP%20as%20currenttime%2C%20datediff(minute%2Clast_batch%2CGETDATE())%20as%20'idletime_in_minute'%20%2Csp.status%2Csp.spid%2Csp.login_time%2Csp.program_name%2Csp.hostprocess%2Csp.loginame%2Ctext%20FROM%20sys.sysprocesses%20sp%20CROSS%20APPLY%20sys.dm_exec_sql_text(sp.sql_handle)%20AS%20QT%20where%20sp.status%20%3D%20'sleeping'%20and%20datediff(minute%2Clast_batch%2CGETDATE())%20%26gt%3B15%20and%20spid%26gt%3B50%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B3.List%20top%2010%20high%20CPU%20queries%20that%20currently%20running%20in%20this%20SQL%20instance%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3ESELECT%20s.session_id%2Cr.status%2Cr.blocking_session_id%20'Blk%20by'%2Cr.wait_type%2Cwait_resource%2Cr.wait_time%20%2F%20(1000%20*%2060)%20'Wait%20M'%2Cr.cpu_time%2Cr.logical_reads%2Cr.reads%2Cr.writes%2Cr.total_elapsed_time%20%2F%20(1000%20*%2060)%20'Elaps%20M'%2CSubstring(st.TEXT%2C(r.statement_start_offset%20%2F%202)%20%2B%201%2C%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E((CASE%20r.statement_end_offset%20WHEN%20-1%20THEN%20Datalength(st.TEXT)%20ELSE%20r.statement_end_offset%20END%20-%20r.statement_start_offset)%20%2F%202)%20%2B%201)%20AS%20statement_text%2C%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3ECoalesce(Quotename(Db_name(st.dbid))%20%2B%20N'.'%20%2B%20Quotename(Object_schema_name(st.objectid%2C%20st.dbid))%20%2B%20N'.'%20%2B%20Quotename(Object_name(st.objectid%2C%20st.dbid))%2C%20'')%20AS%20command_text%2Cr.command%2Cs.login_name%2C%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Es.host_name%2Cs.program_name%2Cs.last_request_end_time%2Cs.login_time%2C%20r.open_transaction_count%20FROM%20sys.dm_exec_sessions%20AS%20s%20JOIN%20sys.dm_exec_requests%20AS%20r%20ON%20r.session_id%20%3D%20s.session_id%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3ECROSS%20APPLY%20sys.Dm_exec_sql_text(r.sql_handle)%20AS%20st%20WHERE%20r.session_id%20!%3D%20%40%40SPID%20ORDER%20BY%20r.cpu_time%20desc%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%204.%20List%20top%2010%20high%20memory%20usage%20queries%20that%20currently%20running%20in%20this%20SQL%20instance%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3ESELECT%20mg.session_id%2Cmg.granted_memory_kb%2Cmg.requested_memory_kb%2Cmg.ideal_memory_kb%2Cmg.request_time%2Cmg.grant_time%2Cmg.query_cost%2Cmg.dop%2Cst.%5BTEXT%5D%2Cqp.query_plan%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EFROM%20sys.dm_exec_query_memory_grants%20AS%20mg%20CROSS%20APPLY%20sys.dm_exec_sql_text(mg.plan_handle)%20AS%20st%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3ECROSS%20APPLY%20sys.dm_exec_query_plan(mg.plan_handle)%20AS%20qp%20ORDER%20BY%20mg.required_memory_kb%20DESC%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B5.%20List%20detailed%20memory%20usage%20for%20each%20memory%20clerk%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EDBCC%20MEMORYSTATUS%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3CSTRONG%3E6.%3C%2FSTRONG%3E%26nbsp%3B%3CSTRONG%3EList%20memory%20usage%20for%20plan%20cache%20and%20its%20maximum%20size%20based%20on%20current%20setting.%20By%20removing%20the%20WHERE%20condition%2C%20you%20will%20get%20a%20full%20list%20for%20all%20memory%20cache%20clerks%E2%80%99%20information%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Eselect%20name%2C%20type%2C%20buckets_count%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Efrom%20sys.dm_os_memory_cache_hash_tables%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Ewhere%20name%20IN%20(%20'SQL%20Plans'%20%2C%20'Object%20Plans'%20%2C%20'Bound%20Trees'%20%2C'Extended%20Stored%20Procedures')%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Eselect%20name%2C%20type%2C%20pages_kb%2C%20entries_count%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Efrom%20sys.dm_os_memory_cache_counters%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Ewhere%20name%20IN%20(%20'SQL%20Plans'%20%2C%20'Object%20Plans'%20%2C%26nbsp%3B%20'Bound%20Trees'%20%2C'Extended%20Stored%20Procedures')%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B7.%20List%20progressive%20(on-going)%20execution%20plan%20for%20a%20specific%20session%20(Starting%20with%20SQL%202016)%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EFor%20SQL%202016%20and%202017%2C%20please%20first%20run%20below%20TSQL%20in%20the%20query%20session%20of%20which%20the%20execution%20plan%20you%20wish%20to%20extract%20later%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3CFONT%20color%3D%22%232356EF%22%3Eset%20statistics%20profile%20on%3C%2FFONT%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ERun%20below%20query%20to%20extract%20the%20on-going%20execution%20plan%20for%20your%20target%20session%20(input%20the%20SPID%20in%20the%20bracket)%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3CFONT%20color%3D%22%232356EF%22%3ESELECT%20*%20FROM%20sys.dm_exec_query_statistics_xml(59)%3B%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B8.List%20all%20block%20header%20queries%20that%20currently%20detected%20in%20this%20SQL%20instance%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Edeclare%20%40blocker%20varchar(100)%2C%40sql%20varchar(100)%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Eprint%20convert(varchar(20)%2C%20getdate()%2C120)%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%20select%20distinct%20blocked%20into%20%23blocker%20from%20sysprocesses%20where%20blocked%20%26lt%3B%26gt%3B%200%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%20DECLARE%20blocker%20CURSOR%20FOR%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%20select%20spid%20from%20sysprocesses%20where%20spid%20in%20(select%20*%20from%20%23blocker)%20and%20blocked%20%3D%200%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%20OPEN%20blocker%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%20FETCH%20NEXT%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20FROM%20blocker%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20INTO%20%40blocker%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%20WHILE%20%40%40FETCH_STATUS%20%3D%200%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%20BEGIN%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20set%20%40sql%3D'DBCC%20inputbuffer('%20%2B%20%40blocker%20%2B%20')'%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20execute%20(%40sql)%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20set%20%40sql%3D%20'select%20*%20from%20sysprocesses%20where%20spid%3D'%20%2B%20%40blocker%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20execute%20(%40sql)%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20FETCH%20NEXT%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20FROM%20blocker%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20INTO%20%40blocker%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%20END%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%20CLOSE%20blocker%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%20DEALLOCATE%20blocker%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%20drop%20table%20%23blocker%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%209.Kill%20all%20sleeping%20sessions%20that%20has%20been%20idle%20over%201%20hour%20(You%20can%20customize%20the%20idle%20duration)%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EDECLARE%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F528645%22%20target%3D%22_blank%22%3E%40user%3C%2FA%3E_spid%20INT%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EDECLARE%20CurSPID%20CURSOR%20FAST_FORWARD%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EFOR%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3ESELECT%20SPID%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EFROM%20master.dbo.sysprocesses%20(NOLOCK)%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EWHERE%20spid%26gt%3B50%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EAND%20status%3D'sleeping'%20--%20only%20sleeping%20threads%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EAND%20DATEDIFF(HOUR%2Clast_batch%2CGETDATE())%26gt%3B%3CSTRONG%3E%3D%3C%2FSTRONG%3E%3CSTRONG%3E1%3C%2FSTRONG%3E%20--%20thread%20sleeping%20for%201%20hours%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EAND%20spid%26lt%3B%26gt%3B%40%40spid%20--%20ignore%20current%20spid%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EOPEN%20CurSPID%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EFETCH%20NEXT%20FROM%20CurSPID%20INTO%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F528645%22%20target%3D%22_blank%22%3E%40user%3C%2FA%3E_spid%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EWHILE%20(%40%40FETCH_STATUS%3D0)%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EBEGIN%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EPRINT%20'Killing%20'%2BCONVERT(VARCHAR%2C%40user_spid)%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EEXEC('KILL%20'%2B%40user_spid)%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EFETCH%20NEXT%20FROM%20CurSPID%20INTO%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F528645%22%20target%3D%22_blank%22%3E%40user%3C%2FA%3E_spid%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EEND%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3ECLOSE%20CurSPID%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EDEALLOCATE%20CurSPID%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EGO%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B10.Kill%20all%20block%20headers.%20This%20script%20will%20continuously%20scan%20every%205%20seconds%20for%20all%20block%20header%20sessions%20and%20kill%20all%20block%20headers%20%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EUse%20master%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Ego%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Ewhile%201%3D1%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EBegin%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Edeclare%20%40blocker%20varchar(100)%2C%40sql%20varchar(100)%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Eprint%20convert(varchar(20)%2C%20getdate()%2C120)%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%20select%20distinct%20blocked%20into%20%23blocker%20from%20sysprocesses%20where%20blocked%20%26lt%3B%26gt%3B%200%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%20DECLARE%20blocker%20CURSOR%20FOR%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%20select%20spid%20from%20sysprocesses%20where%20spid%20in%20(select%20*%20from%20%23blocker)%20and%20status%3D'sleeping'%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%20OPEN%20blocker%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%20FETCH%20NEXT%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20FROM%20blocker%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20INTO%20%40blocker%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%20WHILE%20%40%40FETCH_STATUS%20%3D%200%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%20BEGIN%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20set%20%40sql%3D'DBCC%20inputbuffer('%20%2B%20%40blocker%20%2B%20')'%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20execute%20(%40sql)%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20set%20%40sql%3D%20'kill%20'%20%2B%20%40blocker%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20execute%20(%40sql)%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20FETCH%20NEXT%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20FROM%20blocker%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20INTO%20%40blocker%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%20END%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20CLOSE%20blocker%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%20DEALLOCATE%20blocker%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%20drop%20table%20%23blocker%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Ewaitfor%20delay%20'0%3A0%3A05'%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EEnd%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EDeadlock%20and%20Database%20Object%20ID%20mapping%20%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EBelow%20are%203%20examples%20to%20map%20the%20issued%20object%20based%20on%20the%20ID%20to%20its%20source%20database%2C%20index%20or%20schema.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B1.%20Key%20type%20wait%20resource%20%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3Ewaitresource%3DKEY%3A%206%3A12345678990%20(987654321a9b)%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3Edatabase_id%20%3D%20%3CSTRONG%3E6%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3Ehobt_id%20%3D%20%3CSTRONG%3E12345678990%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3Ehash%20value%20%3D%26nbsp%3B(%3CSTRONG%3E987654321a9b%3C%2FSTRONG%3E)%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3EWe%20can%20use%20below%20TSQL%20to%20check%20the%20database%20name%20based%20on%20DATABASE%20ID%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Eselect%20db_name%3CSTRONG%3E%3CFONT%20color%3D%22%23DF0000%22%3E(6)%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EUse%20below%20TSQL%20to%20check%20the%20schema%2C%20object%2C%20and%20index%20details%20related%20to%20this%20key%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EUSE%20%3CFONT%20color%3D%22%23DF0000%22%3E%3CSTRONG%3EDatabaseName%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EGO%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3ESELECT%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%20sc.name%20as%20schema_name%2C%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3Bso.name%20as%20object_name%2C%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3Bsi.name%20as%20index_name%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EFROM%20sys.partitions%20AS%20p%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EJOIN%20sys.objects%20as%20so%20on%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3Bp.object_id%3Dso.object_id%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EJOIN%20sys.indexes%20as%20si%20on%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3Bp.index_id%3Dsi.index_id%20and%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3Bp.object_id%3Dsi.object_id%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EJOIN%20sys.schemas%20AS%20sc%20on%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3Bso.schema_id%3Dsc.schema_id%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EWHERE%20hobt_id%20%3D%20%3C%2FFONT%3E%3CSTRONG%3E%3CFONT%20color%3D%22%23DF0000%22%3E12345678990%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B2.%20Object%20Wait%20resource%20type%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3Ewaitresource%3DOBJECT%3A%206%3A1234567890%3A4%3C%2FSTRONG%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3Edatabase_id%20%3D%20%3CSTRONG%3E6%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3EObject%20ID%20%3D%20%3CSTRONG%3E1234567890%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20can%20use%20below%20TSQL%20to%20check%20the%20specific%20object%20name%20based%20on%20the%20waitresource%20details%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eselect%20OBJECT_NAME(%3CSTRONG%3E%3CFONT%20color%3D%22%23DF0000%22%3E1234567890%2C6%3C%2FFONT%3E%3C%2FSTRONG%3E%3CFONT%20color%3D%22%23DF0000%22%3E%3CFONT%20color%3D%22%232356EF%22%3E)%3C%2FFONT%3E%3C%2FFONT%3E%3CFONT%20color%3D%22%232356EF%22%3E%26nbsp%3B%3C%2FFONT%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B3.%20Page%20Wait%20Resource%20Type%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3Ewaitresource%3D%E2%80%9CPAGE%3A%206%3A3%3A70133%26nbsp%3B%E2%80%9D%20%3D%26nbsp%3BDatabase_Id%20%3A%20FileId%20%3A%20PageNumber%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3Edatabase_id%3D%3CSTRONG%3E6%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3Edata_file_id%20%3D%20%3CSTRONG%3E3%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3Epage_number%20%3D%20%3CSTRONG%3E70133%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EHA%20(Clustered%20SQL%20Server)%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3C%2FSTRONG%3E%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3E%3CSTRONG%3EList%20the%20latest%20error%20encountered%20by%20local%20AG%20replica%20for%20connection%20timeout%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Eselect%20r.replica_server_name%2C%20r.endpoint_url%2C%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Ers.connected_state_desc%2C%20rs.last_connect_error_description%2C%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Ers.last_connect_error_number%2C%20rs.last_connect_error_timestamp%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Efrom%20sys.dm_hadr_availability_replica_states%20rs%20join%20sys.availability_replicas%20r%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Eon%20rs.replica_id%3Dr.replica_id%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Ewhere%20rs.is_local%3D1%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%20start%3D%222%22%3E%0A%3CLI%3E%3CSTRONG%3EList%20the%20current%20redo%20rate%2C%20redo%20queue%20size%2C%20log%20send%20rate%2C%20log%20send%20queue%20size%20for%20current%20AG%20replica%20%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3ESELECT%20CURRENT_TIMESTAMP%20as%20currenttime%2Cdrs.last_commit_time%2Car.replica_server_name%2C%20adc.database_name%2C%20ag.name%20AS%20ag_name%2C%20drs.is_local%2C%20drs.is_primary_replica%2C%20drs.log_send_queue_size%2C%20drs.log_send_rate%2C%20drs.redo_queue_size%2C%20drs.redo_rate%20FROM%20sys.dm_hadr_database_replica_states%20AS%20drs%20INNER%20JOIN%20sys.availability_databases_cluster%20AS%20adc%20ON%20drs.group_id%20%3D%20adc.group_id%20AND%20drs.group_database_id%20%3D%20adc.group_database_id%20INNER%20JOIN%20sys.availability_groups%20AS%20ag%20ON%20ag.group_id%20%3D%20drs.group_id%20INNER%20JOIN%20sys.availability_replicas%20AS%20ar%20ON%20drs.group_id%20%3D%20ar.group_id%20AND%20drs.replica_id%20%3D%20ar.replica_id%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%20start%3D%223%22%3E%0A%3CLI%3E%3CSTRONG%3ERestart%20endpoint%20%3C%2FSTRONG%3E%3CUL%3E%0A%3CLI%3E%3CSTRONG%3ECheck%20SQL%20AG%20endpoint%20name%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3ESELECT%20*%20FROM%20sys.endpoints%3C%2FFONT%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3ERestart%20AG%20endpoint%20on%20this%20local%20replica%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EALTER%20ENDPOINT%20%3CYOUR%20ag%3D%22%22%20endpoint%3D%22%22%20name%3D%22%22%3E%20STATE%3DSTOPPED%26nbsp%3B%3C%2FYOUR%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EALTER%20ENDPOINT%20%3CYOUR%20ag%3D%22%22%20endpoint%3D%22%22%20name%3D%22%22%3E%20STATE%3DSTARTED%3C%2FYOUR%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EBackup%20%26amp%3B%20Transaction%20Log%20Related%20Issue%20%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3C%2FSTRONG%3E%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3E%3CSTRONG%3EList%20all%20backup%20history%20and%20backup%20file%20details%20for%20the%20past%207%20days%20(You%20can%20modify%20the%20date)%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3ESELECT%20CONVERT(CHAR(100)%2C%20SERVERPROPERTY('Servername'))%20AS%20Server%2C%20msdb.dbo.backupset.database_name%2C%20msdb.dbo.backupset.backup_start_date%2C%20msdb.dbo.backupset.backup_finish_date%2C%20msdb.dbo.backupset.expiration_date%2C%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3ECASE%20msdb..backupset.type%20WHEN%20'D'%20THEN%20'Database'%20WHEN%20'L'%20THEN%20'Log'%20END%20AS%20backup_type%2C%20msdb.dbo.backupset.backup_size%2C%20msdb.dbo.backupmediafamily.logical_device_name%2C%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Emsdb.dbo.backupmediafamily.physical_device_name%2C%20msdb.dbo.backupset.name%20AS%20backupset_name%2C%20msdb.dbo.backupset.description%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EFROM%20msdb.dbo.backupmediafamily%20INNER%20JOIN%20msdb.dbo.backupset%20ON%20msdb.dbo.backupmediafamily.media_set_id%20%3D%20msdb.dbo.backupset.media_set_id%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EWHERE%20(CONVERT(datetime%2C%20msdb.dbo.backupset.backup_start_date%2C%20102)%20%26gt%3B%3D%20%3CFONT%20color%3D%22%23DF0000%22%3EGETDATE()%20-%207)%3C%2FFONT%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EORDER%20BY%20msdb.dbo.backupset.database_name%2C%20msdb.dbo.backupset.backup_finish_date%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%20start%3D%222%22%3E%0A%3CLI%3E%3CSTRONG%3EList%20all%20databases%E2%80%99%20data%20and%20log%20file%20path%20and%20logical%20name%20%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EUSE%20master%3B%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3ESELECT%20name%20'Logical%20Name'%2C%20physical_name%20'File%20Location'%20FROM%20sys.master_files%3B%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%20start%3D%223%22%3E%0A%3CLI%3E%3CSTRONG%3EList%20each%20database%E2%80%99%20transaction%20log%20size%20usage%20and%20space%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EDBCC%20SQLPERF(LOGSPACE)%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%20start%3D%224%22%3E%0A%3CLI%3E%3CSTRONG%3EList%20VLF%20size%20and%20counts%20for%20all%20databases%20as%20well%20as%20detailed%20size%20for%20your%20target%20database%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Eselect%20*%20from%20sys.dm_db_log_info(5)%3B%20%2F*input%20here%20your%20DB%20ID%20to%20get%20detailed%20size%20for%20existing%20VLFs%20on%20this%20database*%2F%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3ESELECT%20%5Bname%5D%2C%20s.database_id%2C%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3ECOUNT(l.database_id)%20AS%20'VLF%20Count'%2C%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3ESUM(vlf_size_mb)%20AS%20'VLF%20Size%20(MB)'%2C%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3ESUM(CAST(vlf_active%20AS%20INT))%20AS%20'Active%20VLF'%2C%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3ESUM(vlf_active*vlf_size_mb)%20AS%20'Active%20VLF%20Size%20(MB)'%2C%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3ECOUNT(l.database_id)-SUM(CAST(vlf_active%20AS%20INT))%20AS%20'In-active%20VLF'%2C%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3ESUM(vlf_size_mb)-SUM(vlf_active*vlf_size_mb)%20AS%20'In-active%20VLF%20Size%20(MB)'%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EFROM%20sys.databases%20s%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3ECROSS%20APPLY%20sys.dm_db_log_info(s.database_id)%20l%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EGROUP%20BY%20%5Bname%5D%2C%20s.database_id%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EORDER%20BY%20'VLF%20Count'%20DESC%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EGO%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%20start%3D%225%22%3E%0A%3CLI%3E%3CSTRONG%3EFor%20the%20purpose%20of%20shrinking%20transaction%20log%20file%2C%20check%20the%20log_reuse_wait_desc%20type%20for%20all%20database%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Eselect%20name%2Cdatabase_id%2Clog_reuse_wait%2C%20log_reuse_wait_desc%20from%20sys.databases%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPlease%20refer%20this%20link%20for%20how%20to%20fix%20each%20of%20the%20log_reuse_wait_desc%20type%20when%20it%20is%20not%20%E2%80%9CNOTHING%E2%80%9D%26nbsp%3B%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Frelational-databases%2Fsystem-catalog-views%2Fsys-databases-transact-sql%3Fview%3Dsql-server-ver15%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Frelational-databases%2Fsystem-catalog-views%2Fsys-databases-transact-sql%3Fview%3Dsql-server-ver15%3C%2FA%3E%3C%2FP%3E%0A%3COL%20start%3D%226%22%3E%0A%3CLI%3E%3CSTRONG%3EDatabase%20Corruption%20Issue%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CSTRONG%3EForce%20repair%20of%20database%20with%20REPAIR_ALLOW_DATA_LOSS%20option%20(data%20loss%20expected%20and%20sometimes%20can%20cause%20more%20damage.%20Please%20refrain%20from%20using%20this%20method%20unless%20as%20for%20a%20last%20resort.%20More%20details%20for%20fixing%20database%20corruption%2C%20please%20refer%20this%20link%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Ft-sql%2Fdatabase-console-commands%2Fdbcc-checkdb-transact-sql%3Fview%3Dsql-server-ver15%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Ft-sql%2Fdatabase-console-commands%2Fdbcc-checkdb-transact-sql%3Fview%3Dsql-server-ver15%3C%2FA%3E)%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EAlter%20database%20YourDBName%20set%20single_user%20with%20rollback%20immediate%3B%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EDBCC%20CHECKDB('YourDBName'%2C%20REPAIR_ALLOW_DATA_LOSS)%3B%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EAlter%20database%20YourDBName%20set%20multi_user%20with%20rollback%20immediate%3B%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EQuery%20Store%20(QDS)%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E1.List%20a%20database%E2%80%99s%20query%20store%20status%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Eselect%26nbsp%3B*%26nbsp%3Bfrom%26nbsp%3Bsys.database_query_store_options%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B2.%20List%20all%20databases%20that%20have%20query%20store%20configured%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Eselect%26nbsp%3Bname%26nbsp%3Bas%26nbsp%3B'DATABASE%20NAME'%2C%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3ECASE%26nbsp%3Bis_query_store_on%26nbsp%3Bwhen%26nbsp%3B1%26nbsp%3Bthen%26nbsp%3B'ENABLED'%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Eelse%26nbsp%3B'OTHER'%26nbsp%3BEND%26nbsp%3BAS%26nbsp%3B'QUERY%20STORE%20STATE'%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Efrom%26nbsp%3Bsys.databases%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Ewhere%26nbsp%3Bis_query_store_on%26nbsp%3B%3D%26nbsp%3B1%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Eorder%26nbsp%3Bby%26nbsp%3B1%26nbsp%3B%3B%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EDatabase%20Encryption%20(TDE)%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3C%2FSTRONG%3E%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3E%3CSTRONG%3ECheck%20if%20the%20DMK%20exist%20in%20master%20database%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EUSE%20master%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EGO%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3ESELECT%20*%20FROM%20sys.symmetric_keys%20WHERE%20name%20%3D%20'%23%23MS_DatabaseMasterKey%23%23'%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%20start%3D%222%22%3E%0A%3CLI%3E%3CSTRONG%3ECheck%20if%20the%20certificate%20is%20created%20in%20master%20database.%20A%20certificate%20is%20equivalent%20to%20an%20asymmetric%20key%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EUSE%20master%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EGO%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Eselect%20*%20from%20sys.certificates%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%20start%3D%223%22%3E%0A%3CLI%3E%3CSTRONG%3ECheck%20if%20the%20database%20is%20encrypted%2Fprogress%20(encryption_state%20%3D%203%20encrypted%3B%20%3D2%20in%20progress)%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EUSE%20master%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EGO%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3ESELECT%20db_name(database_id)%20%5BTDE%20Encrypted%20DB%20Name%5D%2C%20c.name%20as%20CertName%2C%20encryptor_thumbprint%20%2C%20dek.*%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20FROM%20sys.dm_database_encryption_keys%20dek%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20INNER%20JOIN%20sys.certificates%20c%20on%20dek.encryptor_thumbprint%20%3D%20c.thumbprint%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%20start%3D%224%22%3E%0A%3CLI%3E%3CSTRONG%3ECheck%20if%20the%20DMK%20in%20the%20master%20database%20is%20now%20encrypted%20by%20the%20SMK%20(is_master_key_encrypted_by_server%20%3D%201)%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Eselect%20is_master_key_encrypted_by_server%2C%20*%20from%20sys.databases%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Ewhere%20database_id%20%3D%20db_id(N'master')%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ETool%20(Profiler%20trace%20and%20X-event)%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3E%3CSTRONG%3EImport%20SQL%20Profiler%20trace%20into%20SQL%20Server%20database%20tables%20%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EUSE%20DatabaseName%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EGO%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3Eselect%20*%20into%20Sample%20from%20fn_trace_gettable('c%3A%5Ctrace%5CYourFolderToStoreTheTrace%5CYourTraceFile.trc'%2Cdefault)%20where%20eventclass%20in%20(10%2C%2012)%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20event%20class%20ID%2C%20check%20the%20list%20in%20this%20link%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Frelational-databases%2Fsystem-stored-procedures%2Fsp-trace-setevent-transact-sql%3Fview%3Dsql-server-ver15%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Frelational-databases%2Fsystem-stored-procedures%2Fsp-trace-setevent-transact-sql%3Fview%3Dsql-server-ver15%3C%2FA%3E%3C%2FP%3E%0A%3COL%20start%3D%222%22%3E%0A%3CLI%3E%3CSTRONG%3EUse%20XELoader%20to%20process%20X-event%20and%20import%20the%20data%20into%20SQL%20database%20table%20for%20data%20analysis%20purpose.%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3EXELoader%20can%20be%20downloaded%20from%20this%20opensource%20link%20%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fsuresh-kandoth%2FXELoader%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fsuresh-kandoth%2FXELoader%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3EUse%20CMD%20script%20to%20load%20the%20X-event%20files%20into%20SQL%20Server%20database%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3ESample%20script%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3EC%3A%5CXELoader%5C6.2%26gt%3BXELoader.exe%20-D%22C%3A%5CUsers%5Cyixin%5CDesktop%5Cxeloader%5Cxevent%22%20-SYourServerName%5CInstanceName%20-dYourDBName%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3EUse%20TSQL%20query%20to%20check%20aggregated%20data%20result%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESample%20TSQL%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%232356EF%22%3ESELECT%20sum(c_duration)%20as%20SUM_DURAION%2Csum(c_signal_duration)%20as%20SUM_SIGNAL_DURATION%2Cc_wait_type%20from%20%5Bxel%5D.%5Bwait_info%5D%20group%20by%20c_wait_type%20order%20by%20SUM_DURAION%20desc%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CEM%3EDISCLAIMER%20%3A%20THIS%20CODE%20AND%20INFORMATION%20IS%20PROVIDED%20%22AS%20IS%22%20WITHOUT%20WARRANTY%20OF%20ANY%20KIND%2C%20EITHER%20EXPRESSED%20OR%20IMPLIED%2C%20INCLUDING%20BUT%20NOT%20LIMITED%20TO%20THE%20IMPLIED%20WARRANTIES%20OF%20MERCHANTABILITY%20AND%20FITNESS%20FOR%20A%20PARTICULAR%20PURPOSE.%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3258618%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20SQL%20VM%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EErrors%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Ehigh%20availability%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Esql%202012%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESQL%202014%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Esql%202017%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESQL%202019%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EStorage%20Engine%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Etroubleshooting%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ETSQL%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Co-Authors
Version history
Last update:
‎Mar 16 2022 04:46 AM
Updated by: