Skip to main content
1 of 6
Newbie-DBA
  • 794
  • 4
  • 20

LATCH_EX and CX_PACKETS for a stored proc seen when timing out

I am trying to troubleshoot an issue with below things noticed:-

There is this stored proc which gets timed out on some random days while other days or after retry may complete faster. Time out setting 1 hour. When completes, it does under 15 mins.

What we have noticed-

  • The database in question is a LS standby readonly database which keeps getting restored every 4 hours from Primary.

  • Therefore the SP resides on secondary LS read only database and user query once its accessible.

  • After restore is completed certain mornings we see this SP gets timed out with below as TOP 2 waits

    LATCH_EX and CX_PACKETS    (wait time  
    showing accumulating upto 8 hours for that 1 hour run,    possibly   
    because MAXDOP is 8)
    

However when we retry the same proc after next cycle of restore of database, same SP just completes under 15 minutes.

When it Completes-

  • We do see CXPACKETS but that wait time is very less

  • We do not see any LATCH_EX waits

What possibly is going on here and how can i troubleshoot this further? We have already shared the code level tuning which can be done but DEVs are more interested why same SP gets completed in under 15 mins sometime and fails may be one random day in a week

Newbie-DBA
  • 794
  • 4
  • 20