Is it possible to use Read Uncommitted isolation level on read-only Availability Group secondary?



  • We are using availability groups in SQL 2019 Enterprise edition. We are using the enterprise feature to allow the AG secondary nodes to be in Read-only mode, and then running reporting queries against the secondary by connecting to the listener with ApplicationIntent=ReadOnly parameter.

    For locking and performance reasons, we have some queries that run using Read Uncommitted isolation level on the primary.

    It seems that on the secondary all isolation levels are converted to RCSI regardless of specified locking/isolation level - presumably because it's essential that there are no locks that could block the AG sync.

    Is it possible to run queries in Read Uncommitted on the secondary, which would presumably also ensure no locks are taken but, and, under some circumstances can perform better, or will it always have to be RCSI for queries on the Read-Only secondary?



  • bzzt

    https://sqlperformance.com/2015/04/t-sql-queries/the-read-uncommitted-isolation-level doesn't mean your queries don't take locks, it means your queries ignore locks taken by other queries. The hints really should have been called NORESPECT instead. The current naming is quite misleading. They leave you open to returning dirty reads.

    Queries under this isolation level will still take schema stability locks, like any other read query.

    A much cleaner implementation of this is RCSI, which gives you the last known good version of rows that are currently locked by modification queries rather than potentially returning data from in-flight data from them.

    To answer your question, usually local query hints will override database-level settings like https://sqlperformance.com/2014/05/t-sql-queries/read-committed-snapshot-isolation or https://sqlperformance.com/2014/06/sql-performance/the-snapshot-isolation-level . But even query level locking hints are ignored by queries against readable secondaries:

    https://docs.microsoft.com/en-us/sql/database-engine/availability-groups/windows/active-secondaries-readable-secondary-replicas-always-on-availability-groups?view=sql-server-ver15#bkmk_Benefits

    All queries that run against the secondary databases are automatically mapped to snapshot isolation transaction level, even when other transaction isolation levels are explicitly set. Also, all locking hints are ignored. This eliminates reader/writer contention.

    If you're already using one or both of those row-versioning isolation levels, there shouldn't be any https://www.erikdarlingdata.com/execution-plans/help-my-query-got-slower-without-nolock/ to use Read Uncommitted/NOLOCK.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2