Question

I experienced a deadlock between the database replication agent and a select statement that uses the nolock hint. The select statement was chosen as the victim. Here is the select statement, and as you can see it uses the nolock hint on both objects in the FROM clause:

SELECT col1, col2, etc.
FROM dbo.view1 AS vw WITH (nolock) 
INNER JOIN dbo.table1 AS tbl WITH (nolock) 
    ON vw.column1 = tbl.column1 
    AND vw.column2 = tbl.column2

Here are some further details about the deadlock:

I have a SQL Agent job on "Server B" that calls a SSIS package to move a large volume of data from Server A to Server B. The data source on Server A is replicated with transactional replication. Server A is running SQL Server 2008 R2 SP2, and Server B is running SQL Server 2008 SP3.

The Data Flow Task in the SSIS package needs to move up to 1GB of data, and Server A and Server B are geographically distant from one another so the query can take some time. I didn't want the replication agent on Server A to be blocked so I used the nolock hint in the Data Flow Task. Data integrity is not a huge concern with this data.

The SSIS package has run several times with no incident, but last time it ran there was a deadlock between the replication agent on Server A and the SSIS package's select statement that uses the nolock hint, which caused the job to fail. Here is the error message from the SQL Server error log on Server A:

Replication-Replication Snapshot Subsystem: agent <replication-agent-name> scheduled for retry. The replication agent had encountered an exception.
Source: Replication
Exception Type: Microsoft.SqlServer.Replication.SqlDeadlockException
Exception Message: Transaction (Process ID 72) was deadlocked on lock resources with another process and has be

And the error message from the SQL Agent job history on Server B:

Transaction (Process ID 75) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top