Cdc Sql2008


Published on

Published in: Technology
  • Be the first to comment

Cdc Sql2008

  1. 1. Israeli SQL Server Users Group<br />Change Data Capture<br />Yossi MihailoviciSQL Server<br />
  2. 2. Agenda<br />Introduction to CDC<br />How does CDC work?<br />DDL changes on a tracked table<br />CDC objects overview<br />What is it useful for?<br />Performance issues<br />
  3. 3. Mechanism that records any DML changes (Insert,Update,Delete) on a table<br />Changes are captured for each row in a table<br />All changes are recorded into designated table<br />This feature is available only in SQL 2008 Enterprise<br />Introduction<br />
  4. 4. CDC needs to be enabled on DB level and on table level<br />When enabling CDC for the first time, it automatically generates 2 jobs:<br />Job for capture*<br />Job for cleanup<br />The capture job runs every 5 seconds and scans the transaction log for changes in the tracked table<br />Once a change has been recognized and commited in the log, it’s recorded into a designated table<br />How does it work?<br />
  5. 5. Data Flow<br />
  6. 6. The tracking table is created when CDC is enabled for a table<br />The table is named according to the captured instance name and is categorized as system table under cdc schema<br />Like any regular table, it can be queried, and indexes can be created on it<br />This table consists of 5 fixed columns + 1 column for each tracked column<br />Tracking Table <br />
  7. 7. Alter column is cascaded to the tracked table<br />When dropping a tracked column, the tracking table shows null values for this column<br />Adding a column isn’t supported in the captured instance<br />All DDL changes on a tracked table are recorded in cdc.ddl_history<br />DDL Changes<br />
  8. 8. System Tables:<br />cdc.captured_columns<br />cdc.change_tables<br />cdc.ddl_history<br />cdc.index_columns<br />cdc.lsn_time_mapping<br />cdc.Schema_Name_CT (change tables)<br />DMVs:<br />sys.dm_cdc_log_scan_sessions<br />sys.dm_repl_traninfo<br />sys.dm_cdc_errors<br />CDC Objects Overview<br />
  9. 9. System Stored Procedures:<br />sys.sp_cdc_cleanup_change_table<br />sys.sp_cdc_disable_db_change_data_capture<br />sys.sp_cdc_disable_table_change_data_capture<br />sys.sp_cdc_enable_db_change_data_capture<br />sys.sp_cdc_enable_table_change_data_capture<br />sys.sp_cdc_get_ddl_history<br />sys.sp_cdc_get_captured_columns<br />sys.sp_cdc_help_change_data_capture<br />sys.sp_cdc_help_jobs<br />sys.sp_cdc_change_job<br />CDC Objects Overview<br />
  10. 10. System Functions:<br />cdc.fn_cdc_get_all_changes_&lt;capture_instance&gt;<br />cdc.fn_cdc_get_net_changes_&lt;capture_instance&gt;<br />sys.fn_cdc_decrement_lsn<br />sys.fn_cdc_get_column_ordinal<br />sys.fn_cdc_get_max_lsn<br />sys.fn_cdc_get_min_lsn<br />sys.fn_cdc_has_column_changed<br />sys.fn_cdc_increment_lsn<br />sys.fn_cdc_is_bit_set<br />sys.fn_cdc_map_lsn_to_time<br />sys.fn_cdc_map_time_to_lsn<br />CDC Objects Overview<br />
  11. 11. ETL process to Data Warehouse – No need in “Date Last Change” column<br />Trigger replacement<br />Auditing<br />Snapshot for a table<br />Fixing human errors<br />Evaluate workload on a table<br />Analyzing data changes<br />What is it useful for?<br />
  12. 12. Doesn’t support new column types introduced in SQL 2008<br />Doesn’t support partition swicth operation<br />Only 2 captured instances can be created on a table<br />Transaction log can’t be truncated as long as there are changes marked for capture<br />Capture and cleanup jobs have the same definitions for all capture tables<br />Limitations<br />
  13. 13. LOB data types that weren’t updated aren’t shown in the before update row<br />CDC can’t be enabled on another CDC table<br />In order to support net changes tracking, table must have PK or unique index<br />Table tracked by CDC can’t be truncated<br />Limitations<br />
  14. 14. CDC overhead is mostly on the transaction log file and on the tracking table<br />To increase performance, it is recommended to separate CDC table to a different data file<br />If capture job is disabled, there is still some overhead, but it’s very minimal<br />Effect on Performance<br />
  15. 15. Thank You!<br />