As a follow up to my talk on CDC for the Nashville PASS group I wanted to point out two DMVs that support CDC processing in our instance.
The first is sys.dm_cdc_errors which returns errors encountered in each log scan session. This DMV requires VIEW DATABASE STATE permissions and returns the errors for the past 32 sessions. The column list for the DMV is pretty straightforward but we can add one wrinkle:
SELECT e.session_id
,e.phase_number
,e.entry_time
,e.[error_number]
,e.[error_severity]
,e.[error_state]
,e.[error_message]
,e.start_lsn
,sys.fn_cdc_map_lsn_to_time(e.start_lsn) AS StartLSNTime
,e.begin_lsn
,sys.fn_cdc_map_lsn_to_time(e.begin_lsn) AS BeginLSNTime
,e.sequence_value
FROM sys.dm_cdc_errors AS e;
We can make use of the system functions sys.fn_cdc_map_lsn_to_time which will give us a datetime representation of the log sequence number (LSN).
The second DMV is sys.dm_cdc_log_scan_sessions which returns a row for each log scan session in the database. There are two important points to remember when dealing with this DMV:
- The session_id of 0 is an aggregate row for all sessions since the last restart of the SQL Server service.
- The column empty_scan_count can be greater than 1 for successive scans that yield no changes.
We can run the following two queries to either get detail or summary data on our CDC processing:
--Aggregate CDC information since last restart
SELECT session_id
,start_time
,end_time
,scan_phase
,error_count
,tran_count
,last_commit_cdc_lsn
,last_commit_time
,log_record_count
,command_count / COALESCE(NULLIF(duration, 0), 1) AS Throughput
,latency
,empty_scan_count
,failed_sessions_count
FROM sys.dm_cdc_log_scan_sessions
WHERE session_id = 0;
--Detailed CDC information since restart
SELECT session_id
,start_time
,end_time
,scan_phase
,error_count
,tran_count
,last_commit_cdc_lsn
,last_commit_time
,log_record_count
,command_count
,duration
,latency
,empty_scan_count
,failed_sessions_count
FROM sys.dm_cdc_log_scan_sessions
WHERE session_id > 0;
Between the two DMVs we can manage our CDC implementation for both errors and general performance.
Next up, a look at the metadata that CDC uses to manage what data is captured and stored.
186c414f-9ff2-47ac-9cce-896e193df3b4|1|5.0