Why does last_sent_time column of sys.dm_hadr_database_replica_states always show NULL

Chinni 21 Reputation points
2022-04-01T16:34:20.11+00:00

I always say NULL for column last_sent_time of sys.dm_hadr_database_replica_states on primary replica. It shows correct value for secondary replica.

Why is this not showing correct data for primary?

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,706 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Ronen Ariely 15,096 Reputation points
    2022-04-01T18:31:26+00:00

    Hi,

    Why is this not showing correct data for primary?

    It is showing correct data for primary which is null :-)

    Did you check what this column is?

    When querying the primary replica, last_sent_time is reported for each secondary replica database row. Time when the last log block was sent.

    it is by definition mean to report for each secondary replica and not for primary

    ----------

    14150-image.pngRonen Ariely
    Personal Site | Blog | Facebook | Linkedin


  2. CathyJi-MSFT 21,091 Reputation points Microsoft Vendor
    2022-04-04T05:30:44.557+00:00

    Hi @Chinni ,

    last_sent_time column of sys.dm_hadr_database_replica_states show NULL, this is a correct value for primary replica.

    last_sent_time and last_received_time are all reported for each secondary replicas in SQL AG. Below is a result in my environment, I have one SQL AG has three replicas.

    189641-screenshot-2022-04-04-132906.jpg

    In addition, please refer to this blog.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    0 comments No comments

  3. Chinni 21 Reputation points
    2022-04-04T19:31:35.537+00:00

    I understand the columns last_sent_tim, last_received_time much better now. Thanks for the replies. But I still can't understand that there is nothing to monitor the log sent information (in terms of time) on Primary directly.

    Also to your question

    "If you have multiple secondary then who told that the last_sent_time is the same to all these replicas?!? "

    Since we have one row per secondary, this should not be a problem right? it can show the send times per secondary.

    My main requirement is that I want to monitor if there is any* progress at from the Primary in terms of sending logs to secondary. I can't use the queue size on primary as this can increase or decrease.

    In Database Mirroring we have the counter 'Log Bytes Sent/sec' which is not null on Principal and it updates (cumulative) every time a log is sent to Mirror. I do not see any such counter for alwayson.

    Mirroring: https://learn.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-database-mirroring-object?view=sql-server-ver15