We have an Always On architecture of 4 servers. 2 servers are in availability mode synchronous commit. let's call them A and B. and 2 servers are in availability mode asynchronous commit. let's call them C and D.
In our database, AUTO_UPDATE_STATISTICS is on as well as AUTO_UPDATE_STATISTICS_ASYNC is on. We have a daily job using ola hallengren's script to update statistics.
We have a table that gets updated frequently. It is not big. Data is deleted and added all the time.
Our issue is that we get throughout the day several deadlocks on this table on updating statistics on a non-index column on the C/D server. Seems the primary is updating statistics before or during the async secondary is just doing the first update stats.
Our isolation level is read committed due to the fact that money transactions is our core business.
Would love any assistance to solve this.
<deadlock>
<victim-list>
<victimProcess id="process251f88cd088" />
</victim-list>
<process-list>
<process id="process251f88cd088" taskpriority="20" logused="0" waitresource="METADATA: database_id = 9 STATS(object_id = 1244635577, stats_id = 5), lockPartitionId = 0" waittime="1" ownerId="7702177286" transactionname="UpdateQPStats" lasttranstarted="2023-03-19T17:09:24.460" XDES="0x2d0bc918460" lockMode="Sch-M" schedulerid="10" kpid="5388" status="background" spid="56" sbid="0" ecid="0" priority="0" trancount="1">
<executionStack />
<inputbuf />
</process>
<process id="process24f4fd95848" taskpriority="-20" logused="0" waitresource="METADATA: database_id = 9 STATS(object_id = 1244635577, stats_id = 5), lockPartitionId = 9" waittime="18" XDES="0x25328670040" lockMode="Sch-M" schedulerid="3" kpid="6952" status="background" spid="93" sbid="0" ecid="0" priority="0" trancount="0">
<executionStack />
<inputbuf />
</process>
</process-list>
<resource-list>
<metadatalock subresource="STATS" classid="object_id = 1244635577, stats_id = 5" dbid="9" lockPartition="0" id="lock27adc589c80" mode="Sch-M">
<owner-list>
<owner id="process24f4fd95848" mode="Sch-M" />
</owner-list>
<waiter-list>
<waiter id="process251f88cd088" mode="Sch-M" requestType="wait" />
</waiter-list>
</metadatalock>
<metadatalock subresource="STATS" classid="object_id = 1244635577, stats_id = 5" dbid="9" lockPartition="9" id="lock26b98caf480" mode="Sch-S">
<owner-list>
<owner id="process251f88cd088" mode="Sch-S" />
</owner-list>
<waiter-list>
<waiter id="process24f4fd95848" mode="Sch-M" requestType="wait" />
</waiter-list>
</metadatalock>
</resource-list>
</deadlock>
We tried turning AUTO_UPDATE_STATISTICS_ASYNC off.
We tried to cancel update statistics job as well.
None of the above solved our issue.
We didn't try to move C,D replica servers to Sync mode because it is our report servers.