What better way to kick off the sixth day of pre-Christmas than with six slices of foie-gras? No animals have been hurt in the making of this post!
This could be a pretty festive dish thanks in part to those geese. I enjoy a little foie gras every now and again.
No, this was not just a clever ploy to bring fat into another post. Rather, I feel that foie gras is more of a delicacy than eggs.
Today, we will be talking of a delicacy in the database world. It is a feature that should help every DBA sleep better at night. Sadly, this delicacy can be tainted by another feature that may just give you hear burn instead.
First though, let’s recap.
My DBA gave to me a way to ensure my databases are not corrupt.
Sadly, the method chosen is to force feed (gravage) the checkdb through an SSIS style maintenance plan. Have you ever tried to run checkdb through a maintenance plan? It doesn’t always work so well.
Many times, when running checkdb, you may run into this pretty little error message.
Msg 5808, Level 16, State 1, Line 2
Ad hoc update to system catalogs is not supported.
Well, that is just downright wrong. If I am provided a tool to create maintenance plans, then the tool should not generate an error such as that when I want to run consistency checks against the database. This is akin to force feeding us something that isn’t all that good for our health. There was even a connect item filed for this behavior, here.
Well, there are a couple of things that contribute to this behavior. This can be reproduced from tsql as well. To find what is causing this behavior, I used a tool that is a bit more reliable. To recreate the failure, I created a small test database and then created a maintenance plan to run consistency checks for that database. Then the reliable tool I used is Profiler.
Next up is to run the profiler with a filter for the test database, then to start the maintenance plan. It shouldn’t take too long to have the maintenance plan complete. When it completes, it is time to investigate the TSQL generated by Profiler and it should become apparent pretty quick what TSQL is being run during a maintenance plan that causes the checkdb to fail with the above mentioned error.
Are you ready? This code is pretty complex and perplexing. You better sit down so you don’t fall from the surprise and shock.
EXEC sys.SP_CONFIGURE N'user options', 0 RECONFIGURE
Why would a maintenance plan need to run that snippet every time that a checkdb is performed?
Now, there is another piece to this puzzle. This error is thrown when another configuration setting is present. If we change that setting, the error no longer happens. Soooo, a quick fix would be to change that setting. The setting in question is “Allow Updates”. It has a value of 1 and must be changed to a value of 0. Since SQL 2005, we want it to be a 0 anyway.
EXEC SP_CONFIGURE 'allow updates' ,0 RECONFIGURE WITH override
Now, another option for this issue would be that the maintenance plan not run the sp_configure at all. Or, if it is deemed necessary, that it be changed to the following.
EXEC sys.SP_CONFIGURE N'user options', 0 RECONFIGURE WITH override
The best option in my opinion is that a maintenance plan not be used for consistency checks. I’d prefer to see a custom built routine, a routine using sp_msforeachdb, or the maintenance plan routines developed by Ola Hallengren that can be found here. All of these methods require that a little more thought be put into the consistency checking of your database, but that means you will get better sleep through the night.