How can I track database state changes

jingwen li 1 Reputation point
2021-11-21T14:29:23.333+00:00

For example, the database can be changed from ONLINE to RECOVERING/RESTORING/OFFLINE, I want to tracking this status change.

Azure SQL Database
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Alberto Morillo 32,896 Reputation points MVP
    2021-11-21T17:11:16.047+00:00

    The following dynamic management view DMV gives you the state of the database:

    SELECT * FROM sys.dm_database_replica_states
    

    See the database_state_desc column in the result.

    In addition, the sys.databases DMV provides that information.

    SELECT name, user_access_desc, is_read_only, state_desc, recovery_model_desc
    FROM sys.databases;