SQL SERVER 2014 Change Data Capture Dave Bland

Slides:



Advertisements
Similar presentations
Yukon – What is New Rajesh Gala. Yukon – What is new.NET Framework Programming Data Types Exception Handling Batches Databases Database Engine Administration.
Advertisements

By: Jose Chinchilla July 31, Jose Chinchilla MCITP: SQL Server 2008, Database Administrator MCTS: SQL Server 2005/2008, Business Intelligence DBA.
Module 12: Auditing SQL Server Environments
Database Security and Auditing: Protecting Data Integrity and Accessibility Chapter 8 Application Data Auditing.
Database Security and Auditing: Protecting Data Integrity and Accessibility Chapter 8 Application Data Auditing.
Week 6: Chapter 6 Agenda Automation of SQL Server tasks using: SQL Server Agent Scheduling Scripting Technologies.
Change Data Capture & Change Tracking Deep Dive
Fundamentals, Design, and Implementation, 9/e Chapter 11 Managing Databases with SQL Server 2000.
Brian Alderman | MCT, CEO / Founder of MicroTechPoint Pete Harris | Microsoft Senior Content Publisher.
January 15, Tips for using SQL Server Change Data Capture (Introduction) The Baker’s Dozen Business Intelligence Webcast Radio 13 SQL Server -Business.
Working with SQL and PL/SQL/ Session 1 / 1 of 27 SQL Server Architecture.
Transaction log grows unexpectedly
1 Chapter Overview Transferring and Transforming Data Introducing Microsoft Data Transformation Services (DTS) Transferring and Transforming Data with.
Adapted from Afyouni, Database Security and Auditing Database Application Auditing – Ch. 8.
SQL Server 2008 for Developers John
It is one of the techniques to create a stand by server. Introduced in SQL 2000,enhanced in It is a High Availability as well as Disaster recovery.
Sofia, Bulgaria | 9-10 October SQL Server 2005 High Availability for developers Vladimir Tchalkov Crossroad Ltd. Vladimir Tchalkov Crossroad Ltd.
By Lecturer / Aisha Dawood 1.  You can control the number of dispatcher processes in the instance. Unlike the number of shared servers, the number of.
MICROSOFT SQL SERVER 2005 SECURITY  Special Purpose Logins and Users  SQL Server 2005 Authentication Modes  Permissions  Roles  Managing Server Logins.
The protection of the DB against intentional or unintentional threats using computer-based or non- computer-based controls. Database Security – Part 2.
Triggers A Quick Reference and Summary BIT 275. Triggers SQL code permits you to access only one table for an INSERT, UPDATE, or DELETE statement. The.
Oracle Data Integrator Procedures, Advanced Workflows.
Understanding SQL Server 2008 Change Data Capture Bret Stateham Training Manager Vortex Learning Solutions blogs.netconnex.com.
Module 15 Monitoring SQL Server 2008 R2 with Alerts and Notifications.
7 Copyright © 2005, Oracle. All rights reserved. Managing Undo Data.
CHANGE DATA CAPTURE: A BRIEF OVERVIEW PRESENTED BY TIM WEIGEL
02 | Data Flow – Extract Data Richard Currey | Senior Technical Trainer–New Horizons United George Squillace | Senior Technical Trainer–New Horizons Great.
Confidencial - TRACASA Automatize test [e- Reporting]
SQL SERVER AUDITING. Jean Joseph DBA/Consultant Contact Info: Blog:
Log Shipping, Mirroring, Replication and Clustering Which should I use? That depends on a few questions we must ask the user. We will go over these questions.
Dave LinkedIn
SQL Basics Review Reviewing what we’ve learned so far…….
SQL Server DML Change Capture An overview of several useful SQL Server data change capture technologies Matt Smith Software Architect, Enterprise Data.
11 Copyright © 2009, Oracle. All rights reserved. Enhancing ETL Performance.
9 Copyright © 2005, Oracle. All rights reserved. Managing Undo Data.
10 Copyright © 2007, Oracle. All rights reserved. Managing Undo Data.
SQL Database Management
SQL Server Analysis Services Fundamentals
With Temporal Tables and More
Data Virtualization Demoette… Caching – Database – Multi Table
Microsoft SQL Server 2014 for Oracle DBAs Module 8
Temporal Databases Microsoft SQL Server 2016
TABLES AND INDEXES Ashima Wadhwa.
Maintaining Online Redo Log Files
Monitoring Data Changes with Change Data Capture
Temporal Databases Microsoft SQL Server 2016
Antonio Abalos Castillo
A Technical Overview of Microsoft® SQL Server™ 2005 High Availability Beta 2 Matthew Stephen IT Pro Evangelist (SQL Server)
Example of a page header
Designing an alternative to Replication
Methodology – Physical Database Design for Relational Databases
Auditing in SQL Server 2008 DBA-364-M
Solving ETL Bottlenecks with SSIS Scale Out
Transparent Data Encryption (TDE)
SQL Server Analysis Services Fundamentals
SQL Server Analysis Services Fundamentals
Traveling in time with SQL Server 2017
SQL Azure Database – No CDC, No Problem!
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
Statistics: What are they and How do I use them
Chapter 4 Indexes.
CH 4 Indexes.
CH 4 Indexes.
Chapter 11 Managing Databases with SQL Server 2000
Change Tracking Live Data Warehouse
Understanding Core Database Concepts
T-SQL Tools: Simplicity for Synchronizing Changes Martin Perez.
Data Time Travel with Temporal Tables
Presentation transcript:

SQL SERVER 2014 Change Data Capture Dave Bland www.linkedin.com/pub/dave-bland/a/19b/530 @SQLDave29

About me Degree in Education Microsoft Certified Trainer since 1998 11 years DBA experience .NET and BI Developer Currently supervise a DBA team at Stericycle SQL Server and SharePoint Instructor at Harper College, Palatine, IL SQL Server Consultant Einstein Technology Solutions, Lombard, IL

Certifications

Agenda What is Change Data Capture Differences between Change Tracking and Change Data Capture CDC Workflow Enabling and Using Change Data Capture CDC Functions Performance and Best Practices related to CDC Why Use Change Data Capture Demo

What is Change data capture A way to capture changes made to data in a table Used to capture data for auditing Can be used to load Data Warehouse

Cdc Requirements SQL Server Agent Service needs to be running Enable CDC for database by a member of the sysadmin fixed server role Enable CDC for individual table by the members of the db_owner fixed database role Change Data Capture is available only on the Enterprise, Developer and Evaluation editions of SQL Server The requirements for CDC are pretty simple. Enable CDC fails with error Msg 22830, Level 16, State 1, Procedure sp_cdc_enable_db_internal, Line 186 - If you get this error it could be solved by changing the database owner to SA

Differences between CDC and Change Tracking Feature Change Data Capture Change Tracking Tracked changes DML changes Yes Tracked information Historical data No Whether column was changed DML type There is a difference in the set up and configuration, however in terms of functionality there is a difference. CDC allows for historical changes, while Change Tracking does not.

Cdc workflow DML statements are executed against the tracked tables Entries made to transaction log Capture process reads the log Adds the changes to the Change tables User uses functions to access the change data Clean up job removes old data from Change Tables Uses the sp_replcmds system stored procedure to capture the changes from the Transaction log. This is the same internal stored proc that Transactional Replication uses. Transactions in the log that have not been captured by the CDC process will remain until they are. CHECKPOINT will not truncate the Transaction log. Images from Microsoft.com

CDC Functions sys.sp_cdc_add_job sys.sp_cdc_change_job sys.sp_cdc_disable_db sys.sp_cdc_disable_table sys.sp_cdc_help_change_data_capture sys.sp_cdc_drop_job sys.sp_cdc_help_jobs sys.sp_cdc_enable_db sys.sp_cdc_start_job sys.sp_cdc_enable_table sys.sp_cdc_stop_job Change Data Captures is configured and used via stored procedures. Very little can be completed is Management Studio. SQL Server 2014 includes a number of templates that can easily be used.

Enable\Disable CDC EXECUTE sys.sp_cdc_disable_db EXECUTE sys.sp_cdc_enable_db Objects Created Meta data tables CDC schema CDC database user Sets is_cdc_enabled column in the Sys.Databases view to 1 Cannot be enabled on system databases. When disabling CDC on a database, the objects created will be deleted. Does not create the Agent jobs until a table is enabled for CDC. SQL Server will allow for the creation of the CDC schema. EXECUTE sys.sp_cdc_disable_db

Enable CDC for a table EXEC sys.sp_cdc_enable_table @source_schema = N'HumanResources' , @source_name = N'Department' , @role_name = N'cdc_admin' , @capture_instance = N'HR_Department' , @supports_net_changes = 1 , @index_name = 'AK_Department_Name' , @captured_column_list = N'DepartmentID, Name, GroupName' , @filegroup_name = N'PRIMARY'; GO Will create two Agent jobs One to Capture the Changes One to clean up @supports_net_change - Determines if procs to capture net change(1) and\or All changes(0). Defaults to 1 if Primary Key detected or unique index Index name provided using the @index_name parameter A role for controlling access to a change table. The purpose of the named role is to control access to the change data. The specified role can be an existing fixed server role or a database role. If the specified role does not already exist, a database role of that name is created automatically. Members of either the sysadmin or db_owner role have full access to the data in the change tables. All other users must have SELECT permission on all the captured columns of the source table. In addition, when a role is specified, users who are not members of either thesysadmin or db_owner role must also be members of the specified role. If you do not want to use a gating role, explicitly set the @role_name parameter to NULL. See the Enable a Table Without Using a Gating Role template for an example of enabling a table without a gating role. EXEC sys.sp_cdc_enable_table @source_schema = N'dbo', @source_name = N'MyTable', @role_name = N'MyRole', @filegroup_name = N'MyDB_CT', @supports_net_changes = 1 GO [ @supports_net_changes = ] supports_net_changesIndicates whether support for querying for net changes is to be enabled for this capture instance. supports_net_changes is bit with a default of 1 if the table has a primary key or the table has a unique index that has been identified by using the @index_name parameter. Otherwise, the parameter defaults to 0. If 0, only the support functions to query for all changes are generated. If 1, the functions that are needed to query for net changes are also generated. If supports_net_changes is set to 1, index_name must be specified, or the source table must have a defined primary key. Is the filegroup to be used for the change table created for the capture instance. filegroup_name is sysname and can be NULL. If specified, filegroup_name must be defined for the current database. If NULL, the default filegroup is used. We recommend creating a separate filegroup for change data capture change tables. [ @capture_instance = ] 'capture_instance'Is the name of the capture instance used to name instance-specific change data capture objects. capture_instance is sysname and cannot be NULL. If not specified, the name is derived from the source schema name plus the source table name in the format schemaname_sourcename. capture_instance cannot exceed 100 characters and must be unique within the database. Whether specified or derived, capture_instance is trimmed of any white space to the right of the string. A source table can have a maximum of two capture instances. For more information see, sys.sp_cdc_help_change_data_capture (Transact-SQL). The name of a unique index to use to uniquely identify rows in the source table. index_name is sysname and can be NULL. If specified, index_name must be a valid unique index on the source table. If index_name is specified, the identified index columns takes precedence over any defined primary key columns as the unique row identifier for the table CDC tables are placed in the default filegroup by default Subsequent changes to the primary key will not be allowed without first disabling change data capture for the table.

First cdc table Job 'cdc.AdventureWorksDW2012_capture' started successfully. Job 'cdc.AdventureWorksDW2012_cleanup' started successfully.

Getting changes….

Getting Changes…. Column name Data type Description __$start_lsn binary(10) Commit LSN associated with the change that preserves the commit order of the change. Changes committed in the same transaction share the same commit LSN value. __$seqval Sequence value used to order changes to a row within a transaction. __$operation int Identifies the data manipulation language (DML) operation needed to apply the row of change data to the target data source. Can be one of the following: 1 = delete 2 = insert 3 = update (captured column values are those before the update operation). This value applies only when the row filter option 'all update old' is specified. 4 = update (captured column values are those after the update operation) __$update_mask varbinary(128) A bit mask with a bit corresponding to each captured column identified for the capture instance. This value has all defined bits set to 1 when __$operation = 1 or 2. When __$operation = 3 or 4, only those bits corresponding to columns that changed are set to 1. <captured source table columns> varies The remaining columns returned by the function are the captured columns identified when the capture instance was created. If no columns were specified in the captured column list, all columns in the source table are returned.

DDL History Stored in the cdc.ddl_history table Is populated using a trigger Captures command, but not the user

Capture Job Parameters Set by using the sys.sp_cdc_change_job stored procedure Using the default values, the most number of transactions that can be grabbed every 5 seconds is 5000 Maxtrans Parameter - Default value 500 The maxtrans parameter specifies the maximum number of transactions that can be processed in a single scan cycle of the log Maxscans Parameter - Default value 10 The maxscans parameter specifies the maximum number of scan cycles that are attempted to drain the log Pollinginterval Parameter – Default is 5 seconds The amount of time to wait between log scans 

Database recovery model Once change data capture is enabled, the transaction log behaves just as it does with transactional replication—the log cannot be truncated until the log reader has processed it. A checkpoint operation, even in SIMPLE recovery mode, will not truncate the log unless it has already been processed by the logreader BULK_LOGGED recovery model is used to reduce logging, change data capture will force everything to become fully logged, except for index create/drop/rebuild operations.

Back up and restore If a database is restored to the same server with the same database name If a database is restored to another server If a database is detached and attached to the same server or another server, CDC remains If a database is attached or restored with the KEEP_CDC option to any edition other than Enterprise If a database is restored to the same server with the same database name, change data capture remains enabled. If a database is restored to another server, by default change data capture is disabled and all related metadata is deleted. To retain change data capture, use the KEEP_CDC option when restoring the database. If a database is detached and attached to the same server or another server, change data capture remains enabled. If a database is attached or restored with the KEEP_CDC option to any edition other than Enterprise, the operation is blocked.

Reasons to use CDC There is reduced development time Schema changes are not required. There is a built-in cleanup mechanism There is low overhead to DML operations. Change Data Capture is based on committed transactions. Standard tools are available that you can use to configure and manage

Cdc best practices Change data capture cannot function properly when the Database Engine service or the SQL Server Agent service is running under the NETWORK SERVICE account. This can result in error 22832. To prevent log scanning from adding load during periods of peak demand is to stop the capture job and restart it when demand is reduced. Avoid having two Capture instances on the same table Create a designated File Group for the Change Data Try to avoid using change data capture to capture changes to tables that have frequent large update transactions Continued on next slide

Cdc best practices Limit the list of columns captured by change data capture to only the columns you really need to track If change data capture with default parameters cannot keep up with the workload and latency becomes too high, adjust the Maxscans and/ormaxtrans  or you can reduce pollinginterval to 1.  If possible, run cleanup when there is no other workload active When planning change data capture architecture, take a significant increase in log size and log volume I/O operations into account. In general, querying for all changes is more efficient than querying for  net changes Coordinate ETL jobs and Clean up job

What’s next CDC SSIS packages Monitoring Change Data Capture Data Management Views sys.dm_cdc_log_scan_sessions - Returns one row for each log scan session in the current database. The last row returned represents the current session. You can use this view to return status information about the current log scan session, or aggregated information about all sessions since the instance of SQL Server was last started. sys.dm_cdc_errors - Returns one row for each error encountered during the change data capture log scan session.