question

JoshDani avatar image
0 Votes"
JoshDani asked pituach commented

Why does last_sent_time column of sys.dm_hadr_database_replica_states always show NULL

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-general
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

pituach avatar image
0 Votes"
pituach answered pituach edited

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


· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


I am not sure if that is what it is meant, why can't this be meaning "primary reporting the time of last log back sent from primary to each secondary"?

The description also says "Time when the last log block was sent."

It must be sent from primary right? so it should the time that primary sends the logs?


Also we have another column in the same dmv which is last_received_time

"When querying a secondary replica, last_received_time is reported for the local secondary replica database row."

last_received_time is showing the time received at the secondary. So this column is addressing the secondary side of the things




0 Votes 0 ·

Hi,

why can't this be meaning "primary reporting the time of last log back sent from primary to each secondary"?

Maybe because this is not the meaning so it does not say so...

If you have multiple secondary then who told that the last_sent_time is the same to all these replicas?!? This value relevant per secondary and not per primary. It report for each secondary replica database row

last_received_time is showing the time received at the secondary. So this column is addressing the secondary side of the things

Yes, this column addressing the secondary side and provide totally different information. The time something sent is not always the same time as it received

Real story: I am waiting for a package from US which was sent to several people. The time that was sent to each of us was different last_sent_time) and I am still waiting for my package while others got it already so we each have different last_received_time and some did not even received it :-)

1 Vote 1 ·

Off-topic, the package I was waiting for has arrives :-)

A huge thanks to the Microsoft Power Platforms team


189718-image.png


0 Votes 0 ·
image.png (1.2 MiB)
Cathyji-msft avatar image
0 Votes"
Cathyji-msft answered

Hi @JoshDani,

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".




5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JoshDani avatar image
0 Votes"
JoshDani answered pituach commented

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://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-database-mirroring-object?view=sql-server-ver15

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi :-)

I understand the columns last_sent_tim, last_received_time much better now.

Glad we could help a bit in this :-)

But I still can't understand that there is nothing to monitor the log sent information (in terms of time) on Primary directly.

The time that the Primary send is different from one secondary to the other, so the information come in the records of the secondary. What do you expect to have differently? Do you want to get multiple duplicate rows for the primary in order to have a different value for the sending time!?? Do you want to get the time of the first sending or the last sending? you cannot have multiple values in one column in the a table :-)

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

True and it does. It is in the rows related to the secondary and not in the rows of the primary

This is exactly the meaning last_sent_time in the secondary information.






0 Votes 0 ·

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.

This is good question

I think that your best solution is to get the information from each of the secondary

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.

Database Mirroring is a very very and deprecated solution. Time move and we have new solutions to get some task while other task simply not needed anymore :-)

You can get this information using Extended Events which were not exists when data mirroring invented

0 Votes 0 ·

Thank you for the responses

0 Votes 0 ·