Does AlwaysOn setup adds to row versioning on Primary replica

Udham Singh 41 Reputation points
2021-09-24T15:37:38.117+00:00

Hi,

We have 4 replica set of an AOAG in SQL server 2016 Enterprise edition, 2 sync and 2 async. We have notice that on primary replica we are getting "NonSnapshot Version Transactions" counter value in sys.dm_os_performance_counters. And hence sometime it is triggering the "Longest Transaction Running Time" alert threshold > 50.

Nowhere we are using\changing the isolation level to SNAPSHOT or READ_COMMITED_ISOLATION level, it is the default one i.e. READ COMMITTED for every transaction that is happening.

Any idea how row versioning is happening on Primary replica.

Regards,
Udham Singh

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,760 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,555 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Dmitri Korotkevitch 101 Reputation points
    2021-09-28T21:48:30.367+00:00

    Hi All,

    First of all - let me apologize regarding slight error in Apress blog post content. This is the old post and I corrected it in my upcoming troubleshooting and performance tuning book. :)

    Udham is indeed correct - row versioning is not used on primary when it is not enabled. With readable secondaries, you would get 14-byte pointer added (beware of fragmentation impact). You would also have ghost cleanup (and version store cleanup when used) deferred based on oldest active transactions across all nodes. But SQL Server would not use version store on primary unless it is enabled or used by other processes (triggers, MARS, online index rebuild, etc).

    Speaking of Longest Transaction Running Time - unfortunately, I don't know the answer. I cannot duplicate the problem in simple setup - active explicit transaction on secondary does not increase this counter on primary in my setup (would be easy to check in your environment with perf monitor, I suppose). I don't want to question monitoring strategy but I'd be a bit reluctant to use this performance counter to drive conclusions. It is not sampled frequently enough and it may be hard to correlate the information with the other sources. It is entirely possible that long running transaction on primary is gone by the time you received the alert.

    So bottom line - why do you think long running transaction alert is triggered by secondaries activity instead of legit long running transaction on primary?

    I would look at sys.dm_tran_database_transactions and other transactions DMV to confirm that the problem exists in the first place.

    Sincerely,
    Dmitri

    1 person found this answer helpful.

  2. Erland Sommarskog 101.4K Reputation points MVP
    2021-09-24T21:52:27.903+00:00

    I assume that at least one of your secondary replicas is a readable secondary? That will indeed triggering vesion-store handling on the primary, in the same manner as if you had enabled READ_COMMITTED_SNAPSHOT.


  3. YufeiShao-msft 7,056 Reputation points
    2021-09-27T07:58:42.34+00:00

    Hi @Udham Singh

    This counter only shows activity when the database is under committed snapshot isolation level, it does not log any activity if the database is in any other isolation level.

    But 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.
    https://learn.microsoft.com/en-us/sql/database-engine/availability-groups/windows/active-secondaries-readable-secondary-replicas-always-on-availability-groups?view=sql-server-ver15