Redo thread getting blocked while capturing index physical stats
-1
votes
1
answer
158
views
Noticed REDO thread getting blocked for the whole period of running following query, what could be the reason? It is on SQL Server 2019 CU21,
The blocking was for almost more than 1hr+, for the entire period the physical stats on that DB is done. And, the blocked resource is on the same object, curious why it is only one specific object when the index fragmentation stats collection is happening across all objects in that DB.
Can this be controlled or avoided to not keep the redo fall behind for such long duration?
Query:
INSERT INTO #index_fragmentation_log
SELECT GETDATE() AS [LogDate],
DB_NAME() AS [DatabaseName],
SCHEMA_NAME(o.schema_id) AS [SchemaName],
OBJECT_NAME(ips.object_id) AS [TableName],
i.name AS [IndexName],
i.type_desc AS [IndexType],
p.partition_number AS [PartitionNumber],
ips.alloc_unit_type_desc AS [AllocUnitTypeDesc],
ROUND(ips.avg_fragmentation_in_percent, 2) AS [AvgFragmentationInPercent],
ips.fragment_count AS [FragmentCount],
ROUND(ips.page_count * 8 / 1024, 2) AS [IndexSizeMB],
p.[rows] AS [Rows],
i.fill_factor AS [FillFactor],
p.data_compression AS [DataCompression],
NULL AS [Status],
NULL AS [ExceptionLog]
FROM sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, NULL) AS ips
JOIN sys.indexes AS i
ON ips.object_id = i.object_id
AND ips.index_id = i.index_id
JOIN sys.partitions AS p
ON ips.object_id = p.object_id
AND i.index_id = p.index_id
AND ips.partition_number = p.partition_number
JOIN sys.objects AS o
ON ips.object_id = o.object_id
WHERE ips.avg_fragmentation_in_percent > 0.0
AND ips.index_type_desc NOT IN ( 'HEAP' )
AND o.schema_id IN ( SCHEMA_ID('dbo'));
Blocking Details:
| session_id | command | blocking_session_id | wait_time | wait_type | wait_resource |
|------------|------------|---------------------|-----------|--------------------------|------------------------|
| 29 | DB STARTUP | 0 | 43 | REDO_THREAD_PENDING_WORK | |
| 33 | DB STARTUP | 0 | 59 | REDO_THREAD_PENDING_WORK | |
| 37 | DB STARTUP | 1843 | 2564627 | LCK_M_X | OBJECT: 9:309576141:15 |
| 38 | DB STARTUP | 0 | 74 | REDO_THREAD_PENDING_WORK | |
| 48 | DB STARTUP | 0 | 61 | REDO_THREAD_PENDING_WORK | |
| 190 | DB STARTUP | 0 | 105 | REDO_THREAD_PENDING_WORK | |
| 195 | DB STARTUP | 0 | 12 | REDO_THREAD_PENDING_WORK | |
Details the DB fall behind because of Redo thread blocked.
| database_name | recovery_lsn | truncation_lsn | last_hardened_lsn | last_received_lsn | last_redone_lsn | last_redone_time |
|-------------------|------------------------|------------------------|------------------------|------------------------|------------------------|-------------------------|
| db01 | 4656563000100725600001 | 4656602000033369600004 | 4656602000039955200001 | 4656602000039954400001 | 4656602000039947200042 | 2024-01-19 18:15:45.363 |
| db02 | 87431000001092000001 | 87445000001880800001 | 87445000001892800001 | 87445000001892000001 | 87445000001892000001 | 2024-01-19 18:15:28.773 |
| blocked_db03 | 271295000189302400001 | 271577000159532800001 | 271579000053756000001 | 271579000053755200001 | 271577000176204800080 | 2024-01-19 17:24:56.883 |
Asked by S.D.
(754 rep)
Jan 20, 2024, 03:14 AM
Last activity: Jan 31, 2024, 06:42 AM
Last activity: Jan 31, 2024, 06:42 AM