--- title: "Ring buffers for health information on availability groups" description: "Obtain certain diagnostics information about Always On availability groups using the SQL Server ring buffers." ms.custom: "seo-lt-2019" ms.date: "06/13/2017" ms.prod: sql ms.reviewer: "" ms.technology: high-availability ms.topic: conceptual ms.assetid: 47bb7a1a-c0a5-473c-a7db-d9f4bf3ee650 author: rothja ms.author: jroth --- # Use ring buffers to obtain health information about Always On availability groups [!INCLUDE[appliesto-ss-xxxx-xxxx-xxx-md](../../../includes/appliesto-ss-xxxx-xxxx-xxx-md.md)] Some diagnostic Always On Availability Groups information can be obtained from the SQL Server ring buffers, or the sys.dm_os_ring_buffers dynamic management view (DMV). The ring buffers are created during SQL Server startup, and record alerts within the SQL Server system for internal diagnostics. They are not supported, but you can still extract valuable information from them when troubleshooting issues. These ring buffers provide another source of diagnostics when SQL Server hangs or has crashed. The following Transact-SQL (T-SQL) query retrieves all event records from the availability groups ring buffers. ```sql SELECT * FROM sys.dm_os_ring_buffers WHERE ring_buffer_type LIKE '%HADR%' ``` To make the data more manageable, filter the data by date and the ring buffer type. The following query retrieves records from the specified ring buffer that occurred today. ```sql DECLARE @runtime datetime SET @runtime = GETDATE() SELECT CONVERT (varchar(30), @runtime, 121) as data_collection_runtime, DATEADD (ms, -1 * (inf.ms_ticks - ring.[timestamp]), GETDATE()) AS ring_buffer_record_time, ring.[timestamp] AS record_timestamp, inf.ms_ticks AS cur_timestamp, ring.* FROM sys.dm_os_ring_buffers ring CROSS JOIN sys.dm_os_sys_info inf where ring_buffer_type='' ``` The Record column in each record contains diagnostic data in XML format. The XML data differs between the ring buffer types. For more information on each ring buffer type, see [Availability groups ring buffer types](#BKMK_RingBufferTypes). To make the XML data more readable, you need to customize your T-SQL query to extract the desired XML elements. For example, the following query retrieves all events from the RING_BUFFER_HADRDBMGR_API ring buffer and formats the XML data into separate table columns. ```sql WITH hadr(ts, type, record) AS ( SELECT timestamp AS ts, ring_buffer_type AS type, CAST(record AS XML) AS record FROM sys.dm_os_ring_buffers WHERE ring_buffer_type = 'RING_BUFFER_HADRDBMGR_API' ) SELECT ts, type, record.value('(./Record/@id)[1]','bigint') AS [Record ID], record.value('(./Record/@time)[1]','bigint') AS [Time], record.value('(./Record/HadrDbMgrAPI/dbId)[1]', 'bigint') AS [DBID], record.value('(/Record/HadrDbMgrAPI/API)[1]', 'varchar(50)') AS [API], record.value('(/Record/HadrDbMgrAPI/Action)[1]', 'varchar(50)') AS [Action], record.value('(/Record/HadrDbMgrAPI/role)[1]', 'int') AS [Role], record.value('(/Record/Stack)[1]', 'varchar(100)') AS [Call Stack] FROM hadr ORDER BY record.value('(./Record/@time)[1]','bigint') DESC GO ``` ## Availability groups ring buffer types There are four availability groups ring buffers in sys.dm_os_ring_buffers. The table below describes the ring buffer types and a sample of the content of the Record column for each ring buffer type. **RING_BUFFER_HADRDBMGR_API** Records state transitions that have taken place or are taking place. When looking at the state transitions pay close attention to the objectType values. ```xml HadrUsers HDbMState_Starting HDbMState_Started HDbMState_Started Y 1 ``` **RING_BUFFER_HADRDBMGR_STATE** Records internal method or function calls made by Always On activity. It can show information such as suspend, resume, or role changes, including both the entry and exit points. ```xml 5 HadrDbMgr HDbMState_Starting HDbMState_Started HDbMState_Started Y 2 ``` **RING_BUFFER_HADRDBMGR_COMMIT** ```xml 5 883a18f5-97d5-450f-8f8f-9983a4fa5299 KillAll 0x0 0 0 KillAll 0x0 0x0000000000000000 Y N 2 ``` **RING_BUFFER_HADR_TRANSPORT_STATE** ```xml 08264B79-D10B-412F-B38D-CA07B08E9BD8 883A18F5-97D5-450F-8F8F-9983A4FA5299 628D6349-72DD-4D18-A6E1-1272645660BA HadrSession_Configuring HadrSession_Connected Y ``` ## Parse XML data from a ring buffer You can parse the Record field from the ring buffer you are inspecting by using [value() Method (xml Data Type)](~/t-sql/xml/value-method-xml-data-type.md) in your query. To use this method, you first need to [CAST](~/t-sql/functions/cast-and-convert-transact-sql.md) the record column in the ring buffer into XML. For example, the query below demonstrates how to parse RING_BUFFER_HADRDBMGR_API into readable format using this method. ```sql WITH hadr(ts, type, record) AS (SELECT timestamp AS ts, ring_buffer_type AS type, CAST(record AS XML) AS record FROM sys.dm_os_ring_buffers WHERE ring_buffer_type = 'RING_BUFFER_HADRDBMGR_API') SELECT ts, type, record.value('(./Record/@id)[1]','bigint') AS [Record id], record.value('(./Record/@time)[1]','bigint') AS [Time], record.value('(./Record/HadrDbMgrAPI/dbId)[1]', 'bigint') AS [dbid], record.value('(/Record/HadrDbMgrAPI/API)[1]', 'varchar(50)') AS [API], record.value('(/Record/HadrDbMgrAPI/Action)[1]', 'varchar(50)') AS [Action], record.value('(/Record/HadrDbMgrAPI/role)[1]', 'int') AS [Role], record.value('(/Record/Stack)[1]', 'varchar(100)') AS [Call Stack] FROM hadr ORDER BY record.value('(./Record/@time)[1]','bigint') DESC GO ```