Download presentation
Presentation is loading. Please wait.
Published byNickolas Johnson Modified over 6 years ago
1
Monitoring Data Changes with Change Data Capture
Arie D. Jones (AJ) Principal Technology Manager Perpetual Technologies, Inc Blog : Company Site: Twitter: programmersedge #45 Louisville
2
Arie Jones (AJ) 20 + years application development experience
10 + years database experience Bunch of Alphabet Soup behind name The blog, the webcasts, the events….. Prolific writer SQL Functions Learn SQL in 24 Hours Learn SQL in 1Hour a Day Live Lessons: SQL
3
Agenda How does Change Data Capture work How to implement
How to get to the data Sneaky Ninja DBA Tips
4
? How it Works So how does this mysterious Change Data Capture work? Let‘s take a look at how the magic happens….. That big question mark is editable – use whatever character you want!
5
Why use this? Gives you consistency Reduces programmatic overhead
Reduces computational overhead
6
How it all works! Database Source Tables Log File Change Tables
Capture Process User Queries
7
? How to Implement That’s awesome AJ but how to you get the thing working?? Let’s find out! That big question mark is editable – use whatever character you want!
8
Your Pre-Flight Checklist
SQL Agent is on and set to Auto-Start You or someone you know has SysAdmin privileges CDC user does not exist in database A CDC schema does not exist in database You have a good cover story to explain how difficult the following process is to your manager/boss so as to strengthen your argument for a raise
9
Step #1 Enable on the instance
Use sp_cdc_enable_db_change_data_capture Use sp_cdc_enable_db You may double check in sys.databases This you must have SysAdmin privileges for
10
Step #2 Wipe sweaty brow Enable CDC per table
Use sp_cdc_enable_table_change_data_capture Use sp_cdc_enable_table You can double check in sys.tables You will notice 2 jobs having been created 1 = Get Stuff 2 = Cleanup Stuff
11
Sp_cdc_enable_table_change_data_capture
@source_schema @source_name @role_name @capture_instance @supports_net_changes @index_name @captured_column_list @filegroup_name
12
Demo Let’s look at this in action!
13
? How to Query the Data Now, how do we get to the actual data that we are saving up? That big question mark is editable – use whatever character you want!
14
Querying Data Super easy syntax TableName_CT
Will normally need system functions to get LSN Sys.fn_cdc_map_time_to_lsn Then will use one of 2 CDC query TVF Cdc.fn_cdc_get_all_changes_<schema>_<table> Cdc.fn_cdc_get_net_changes_<schema>_<table>
15
Sneaky Ninja DBA TIP #1! ETL Processes!
16
Demo Straight to a demo!
17
Sneaky Ninja DBA TIP #2! data forensics
18
Who’s making changes? You’ll notice in the CDC tables that there is no username… 2 Things you need to think about How are the users accessing the system? How much flexibility do you have to change things?
19
Easy way! ID Customer User Updated 1 Jane Good DBA 2 Steve
Evil Developer 3 Bob ID Customer 1 Jane 2 Steve 3 Bob Change Data Capture takes care of the rest!!
20
Sneaky Ninja DBA TIP #3! Performance tuning!
21
Let me explain the process
Job Sys.sp_MScdc_capture_job No Parameters! That’s CRAZY! Sys.sp_cdc_scan Hey wait! Isn’t that used in transactional replication? Sys.sp_replcmds
22
Demo Let’s jump into some code!
23
So What’s a DBA to Do? @captured_column_list @supports_net_changes
Limit # of columns to only those you truly need @supports_net_changes Only use if you need net changes Puts an additional nonclustered index on change table @filegroup_name If not specified then change table is placed in default filegroup
24
Performance Tips Storage Workload Watch your log space
Watch you log I/O Make sure you know which file group you have things stored in Workload Reduce the number of columns to the minimum Modify default scan parameters on BOTH the capture and cleanup jobs!
25
Thank You ! Questions and Answers Evaluation Sheets!
Be sure to check out my upcoming events! PTI Monthly Webcasts:
26
SQL Saturday #45 Louisville
@ SQL Saturday # Louisville Monitoring Data Changes with Change Data Capture Arie Jones(AJ) Twitter: programmersedge Company:
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.