Friday, February 01, 2019

"A connection timeout has occurred on a previously established connection to availability replica"

I previously spent some time troubleshooting this issue at one client, and then having encountered it twice more this year, I figured I'd include it in a blog post. Yep, the fix, which is delivered in a CU for SQL 2012, 2014, or 2016 does fix the issue.
Message 35201: A connection timeout has occurred while attempting to establish a connection to availability replica 'replicaname' with id [availability_group_id]. Either a networking or firewall issue exists, or the endpoint address provided for the replica is not the database mirroring endpoint of the host server instance. 
Message 35206: A connection timeout has occurred on a previously established connection to availability replica 'replicaname' with id [availability_group_id]. Either a networking or a firewall issue exists or the availability replica has transitioned to the resolving role.
If you are troubleshooting the above errors, make sure you are on one of these versions (or later)*
  • SQL Server 2016 RTM CU5 or SP1 CU1
  • SQL Server 2014 SP2 CU4
  • SQL Server 2012 SP3 CU7 
*This patch was out before SQL Server 2017 was released, SQL 2017 is not susceptible.

This issue was very problematic because as databases stopped synchronizing, the log files on the primary replica continued to grow. This would eventually create an outage once the volume filled to capacity. Despite all our best efforts, like the KB article says, there's no fix other than rebooting the secondary or removing/recreating the replica. Obviously rebooting/removing the secondary replica doesn't necessarily impact production, but it does impact high availability.

I have encountered this error in multiple environments, once in an Availability Group with 50+ databases, and another also with just 3 databases, one of which had constant high-transactional volume. According to the KB article, "This problem might occur only on very powerful computers and when SQL Server is very busy. For example, in one scenario, this problem occurred on a very busy system with 24 cores."

Tuesday, December 18, 2018

Actual Emails: What is a "soft delete"?

What's a "soft delete", and why should DBAs be aware of such behavior in tables?

So, a DELETE statement is a “hard” delete. The data is gone.

However, it is a common practice to build into tables a set of auditing fields…

For example:
CREATE TABLE dbo.whatever(
Id int identity(1,1) not null primary key,
WhateverInt int not null,
…
Createddate datetimeoffset(0) not null,
Createdby varchar(250) not null,
Modifieddate datetimeoffset(0) null,
Modifiedby varchar(250) not null,
IsActive bit not null CONSTRAINT DF_whatever_IsActive
DEFAULT (1)
)
The IsActive field, or anything similarly named like IsArchived or IsDeleted, is a common strategy to “soft” delete something and remove it from resultsets, but still retain history. All the queries on the table would then use WHERE IsActive = 1 to make sure they only viewed Active data, for example.

So, if you UPDATE a record to IsActive = 0 instead of DELETEing it, it disappears from queries and reports and screens, but it’s still there in case it’s useful. There may be some queries that intentionally want to query IsActive = 0 for historical or auditing purposes. 

Often, a filtered nonclustered index (introduced in SQL 2008) can be used to match the WHERE IsActive = 1, and then the index is smaller as a result and allows SQL Server to dramatically increase performance here. This is really only effective if a majority of the data has actually been soft-deleted.

For example: 
CREATE NONCLUSTERED INDEX IDX_NC_whatever_WhateverInt
ON dbo.whatever (WhateverInt) 
WHERE IsActive = 1
We had one client with an IsArchived flag (or similar) on a table with tens of millions of rows. Only 1% of the data was “active” and waiting to be archived. Their queries specified WHERE IsArchived=0, but still performed very poorly – lots of data still to be accessed. We added and modified some nonclustered indexes as filtered indexes to account for IsArchived = 0, and not only did this greatly reduce the size the indexes, but the query result time went from minutes to instantaneous. Huge difference. We could also have added similarly-filtered nonclustered columnstore indexes.


DBAs need to understand table design and recognize "soft delete" keys and the associated business logic in applications, because the Missing Indexes feature and other common query tuning tools won't include them in recommendations for filtering.

Furthermore, we can even enforce filtered uniqueness using a unique nonclustered index. In this way, we could make sure that there is only one active record for a given key set, but allow many inactive records for the same key set!



Tuesday, November 06, 2018

No Speaker? No Problem! Host a non-traditional User Group meeting

Was honored to speak to fellow User Group leaders at the PASS Summit User Group leader meeting on Tuesday. Here's detail and links to some of the things I mentioned. Thanks to everyone who chimed in at the end provided their own ideas to the room of user group leaders from around the world!

First, consider having a joint meeting with a shared speaker with other user groups, like a .NET or Analytics UG in your area. Share sponsor, food, speaker, networking. More critical mass of fellow professionals, more ROI for sponsors, more potential future speakers and volunteers.

Second, make sure you ABC - Always Be 'Cruiting - new speakers, attracting people to get their feet wet for the first time with technical speaking. Make sure the atmosphere of your group remains approachable, constructive, and not intimidating to new speakers. Make sure you are always reaching out directly to new speakers, offering short-format speaking timeslots at your meetings, and offering mentoring and constructive feedback.

Non-traditional meeting ideas: I'm not claiming credit for creating any of these ideas, they've been executed by others for sure, in fact, I've tried to link to them when possible.
  • "Game shows" - Most fun if game shows actually have individuals at play, not just "ask the crowd" style
  • SQL Jeopardy! using PowerPoint - Not hard to make at all, just what it sounds like. Don't forget to phrase your answer in the form of a query!
  • I have a slidedeck for three rounds of Jeopardy! from SQLSaturday Baton Rouge 2016, happy to share
  • Here's another Jeopardy! game shared by the Baltimore SQL Server User Group
  • Here's another from Chad Crawford of the Utah SQL Server User Group
  • SQL Family Feud - Chad from the Utah County SQL Server Users Group also put out an online survey and delivered the data to anyone who requested it in January 2018. - SQLSat Dallas did it this year for a big finale as well, or, ask around to collect your own "surveys"!
  • There are a lot of list games that are fine for group play, including SQL-themed games in the style of Listography and the Game of Things, like topics like: write down as many data types as you can in the next 20 seconds, or "things developers say", or "most common table name"!
  • Lead an interactive Normalized Database Design for a topic that many people know the business rules for, or, for a brand new business case with a guest product owner - https://www.sqltact.com/2013/01/try-database-design-exercise-at-your.html
  • Lead an interactive "choose your own" Database Corruption Recovery Challenge from Steve Stedman's blog series - http://stevestedman.com/server-health/database-corruption-challenge/
  • Speaker Idol - self-explanatory - well in advance of the meeting, put the call out for "short-format" speakers only, ask bosses, sponsors, spouses etc. to be judges.
  • Licensing - this is not a common topic - ask a local software reseller to send a SQL licensing specialist to talk and do Q&A for an hour, can be very informative.
  • The Toolbox - ask everyone in advance to bring handwritten tsql or powershell scripts from their own "toolbox" to share and briefly demo
  • Networking Night - invite a wide array of people to give short-format talks on career, interview, soft-skills, invite attendees to bring resumes. In BTR, we also add this meeting as a Gold tier SQLSaturday sponsorship
  • New speakers night - another short-format idea, invite only new speakers to give talks, with experienced speakers primed to give constructive, positive feedback
  • PASS Summit knowledge transfer - invite everyone who attended the PASS Summit to give a recap/best-of style presentation to do knowledge transfer to everyone else.
  • Panel of Experts - again, make sure your group remains constructive, approachable and non-intimidating. But a panel of "experts" for Q&A might be a great idea to attract user group attendees with name recognition.