Querying Change Tracking Tables Against a Secondary AG Replica

If you aren't familiar with Change Tracking I would recommend heading out and reading Kendra Little's Change Tracking master post which contains a wealth of information. 

I've been using CT for a while now and it does what it says on the box. The performance can be painful when querying tables that have changed a lot (the changetable function performs a huge amount of aggregation and seems to be optimized for 1000 rows of data). One of the things that I've always wanted to do is perform loads into an ODS from a DR site. 

I use AvailabilityGroups to ensure that a near real-time copy of the data is kept in another data center in another part of the country. I've tried a couple of times to query the change information from one of the secondary replicas, but sadly it's not supported and so I would get the error

Msg 22117, Level 16, State 1, Line 1
For databases that are members of a secondary availability replica, change tracking is not supported. Run change tracking queries on the databases in the primary availability replica.

 

Yesterday I was messing around with database snapshots and was really happy to discover that it is possible to use the changetable function against a snapshot and not receive any errors. This will only work against readable secondary replicas (as the database needs to be online in order to be able to take the snapshot).

This is also the case with log shipped copies of databases. If the database is in standby then you can access the changetable function directly, or do so off a snapshot.

 

It doesn't seem like this is a big deal, but if you like to load data into an ODS or Data Warehouse server and it's not located in the same location as your AG primary, then this is huge as you can asynchronously write data over a WAN and then do all your data loads local to the ODS. This is far more efficient (and your network admin will like you a lot more) than pulling the data over in a large chunk nightly and saturating a part of the network.

Just another way that you can make your DR system work for you.

Rolling Upgrades With Availability Groups - A Warning

One of the great options provided by Availability Groups, in SQL Server 2012 Enterprise Edition and newer, is the ability to perform rolling upgrades to new Service Packs or Cumulative Updates.

The basic idea is that you apply the update to one of the AG secondary servers and then perform a failover of SQL to that server which then does the necessary things on the user databases to bring them up to the level of the update. The big advantage to this is that it minimizes the outage required to get the SP/CU applied, so that you are down for a few seconds instead of 40 minutes.

 

This is works really well for your regular user databases, however there is a problem when applying a CU or SP to a secondary server where a Integration Services (typically called SSISDB) is a member of an Availability Group. If you attempt to apply the CU/SP then it can fail and the SSISDB be left in an offline state. 

In order to apply the CU/SP you would first have to remove SSISDB from the Availability Group and recover it on each server you want to patch. Once you have completed patching all the servers you can add SSISDB back to the AG. But for that period of time you will be at risk, so get through and patch a couple of the machines and get the AG working for those as soon as possible.

Interestingly this does not apply for all CU/SP releases. Some do not make changes to SSISDB and this isn't required. You can only find this out by patching, so be sure to get it going in your test environments first.

An Open Letter To SQLSaturday & User Group Organizers

Dear event organizers;

 While this letter is directed at the SQL Server community the points I present here are valid in other situations.

 

The SQL Community

One of the things that makes SQL Server stand out so much from other products (not just RDBMS) is the level of support and caring that it receives from its user base, frequently known as the SQL Community. There are many levels to this: from folks that read a daily newsletter, to those that help run a professional association dedicated to the product. 

Sitting between those two areas are those that like to give back to the community by writing blog posts, answering peoples questions, and presenting at one of the many events that are run throughout the world. These SQL related events are run at several levels: from small local user groups which may attract 20-30 people, to SQL Saturday events that pull in a few hundred, all the way up to the large conferences where attendees number in the thousands.

 

 Starting Speaking 

Everybody has to start somewhere. The people that speak at the large conferences have perfected their craft at the smaller events. The smaller arenas make for a tighter audience where material can be first presented, then improved over time. As important as the adjustments in the material are the changes in the presenters. They figure out the things that do, and do not, work for them. They learn how to read the crowd, handle questions, push through when problems arise with demos, and pace themselves to give a great and informative session which gives the attending audience great things to walk away with.

Breaking into this speaking arena is as difficult as it is daunting. This is why things like SQL Saturday and local user groups are so great. They allow a fairly safe opportunity for people to get their feet wet. Despite the relatively low visibility a presenter may get from an event like this it is still incredibly scary for them to step up in front of complete strangers that first time.

 

Anna's Story

Anna (not a real person, name randomly generated) has worked with SQL Server for 10 years and knows the ins and outs of optimizing stored procedure performance. She makes the decision that she would like to share some of this knowledge with other people, and so spends a few hours making an outline of a presentation with all the things she wants to put in there. After figuring out the key items she puts together an abstract for her local SQL Saturday event and it gets accepted. After another 40 hours of work Anna has a presentation that she feels will wow the crowd. She shows up Saturday morning and walks into a room. There's a projector in front of her, a screen behind her, and 50 people seated, waiting for her to start. Another 15 people file in, there are no chairs, so they are standing around, leaning against the walls. Anna looks around trying to find a friendly face, but there is nobody she knows there.

 Anna manages to get her laptop connected and is projecting things at the right resolution on the screen behind her. That's never an easy task, especially when people are watching. The clock ticks round and she starts her presentation. As she welcomes everyone to the room and gives a brief outline of what people should expect from her session she sees a couple of people get up and leave. 

 Anna now wonders what she did wrong. What happened that these people left? What did she just say? 

A little rattled, Anna tries to remain on track and gets into her slide deck. She explains the concepts that are up on the screen and a man at the back of the room raises his hand and asks a question. Fortunately it's a quick one and she's able to answer briefly and jump into a demo. The first demo goes well, but the guy is raising his hand again and asking another question. This one is a little more complicated. Anna tries to explain but the guy isn't getting the answer and is starting to get a little impatient with her. Other people are turning to look at him and giving looks, but nobody is saying a word. Isolated, Anna tries to handle it as best she can and return back to the presentation.

 As Anna progresses through her slide deck she can hear the guy at the back mumbling to himself. Then he opens up and instead of asking a question blurts out loudly that she's wrong and he knows it. Anna isn't sure how to respond to this. She tries her best to push on but she is feeling intimidated by this loud individual who seems to want to do nothing more than prove how much smarter he is than her. 

Then there is an issue with one of the demos. A query doesn't behave how it should and Anna is confused as to why. She pushes on, hoping that nobody noticed what happened. Of course the one obnoxious guy is quick to point it out. 

 Exhausted from this Anna wraps up the remaining slides quickly, thanks the room, and shuts down her laptop. People slowly file out, dropping slips of paper containing feedback on a desk as they do so. A couple of people stop by to say thank you for the presentation and ask where they can get copies of the slides and demos. She points them to her website, they thank her and leave. Someone else stops to ask a question, but exhausted she can barely answer.

The next presenter comes wandering in the room getting ready to setup for her session. She asks how it went. Anna just looks at her and shakes her head dejectedly. 

 Anna walks out of the room vowing to never present again. It was a horrible experience that she never wants to repeat. She leaves behind 40 slips of paper that rate her session as a 5 out of 5. She misses the comments that state that this was one of the best sessions that they've seen and how her explanation of parameter sniffing finally made them get it and that they can't wait to take all that they've learned back to the office and explain it to the devs and DBAs so that they can get it too.

The community just lost a great speaker who can reach people on topics and that has a wealth of experience behind her. 

  

To SQLSaturday and User Group Event Organizers

Anna is just a single example of what new speakers run into constantly. I've seen this happen first hand to new presenters. It's not pretty and it's not right. Public speaking is a deep held fear for most people, so standing up in front of an audience is a very scary proposition.

I would like to make a suggestion that, in my opinion, should be implemented at all events. When someone is new (or newer) to speaking given them a "buddy." Pair them up with a more experienced speaker who has done the circuit, is comfortable in front of a room, and knows how to handle a crowd or a question. Give that new speaker a friendly face in the room.

 Does it make a difference? Ask Anna what it would have been like if she had been able to look out and see someone give her a smile and a nod, just letting her know that she was doing a good job. 

How much easier would it have been if Anna had someone to help her get setup on the projector?

What about someone to stand up when and ask if the intense questions could be taken offline so that a more in depth discussion could take place to provide the answers that were being asked for?

How would Anna have felt if someone had asked the gentleman berating her to please stop and raise any big issues after the presentation? Or backed up what Anna had been saying?

 If someone had been there would Anna have been as exhausted when things were done? Would she have quickly skipped over peoples questions? Or would she have been engaged, and thrilled that people wanted to hang out and ask about the things she presented? Would she have walked out of the room deciding to never present again, or would she have eagerly grabbed the feedback papers and gone through them trying to gauge peoples feelings?

The chances are that Anna would have walked out feeling tired, but great about what she did. She would have been talking away with her "buddy" about what worked, what didn't, and asking if they had any idea what happened with that demo that went wrong. They would walk away, tweak the session some, add some things, remove some things, fix that demo and move on to submit and present at another event.

On top of that Anna would have made at least one friend that day. The "buddy" never really goes away. It's someone that they keep in contact with, talk to every once in a while, and bounce new ideas off of. The community grows by one new fully engaged member. 

  

To New Speakers

If you are a first time or reasonably new speaker and are feeling nervous about giving that presentation, speak to the event organizers. Ask them ahead of time if there is someone who might be able to come sit in your session to provide some support.

Should you get no assistance or response from the organizers then try to find someone yourself. For a local user group look to find folks who go regularly and drop them a line, see if you can get together beforehand. For a SQL Saturday ask people in the speaker room; scary though they may seem they are really decent people who would be more than happy to help.

 Don't ever feel like you have to go out there alone. There are always options to get someone on your side.

  

TL:DR

  • Organizers: don't let new speakers go out and present without giving them individual support 
  • Presenters: if the organizer doesn't help you, find someone who can be in the room when you present to give you some support