Tuesday, 8 December 2015

Sample database and scripts for SQL 2016 CTP3



You can download the AdventureWorks sample database and sample scripts from the Microsoft website, here's the sample script topics:

  • Advanced Analytics          
  • Always Encrypted            
  • Clustered Columnstore Index 
  • Data Masking                
  • In-Memory OLTP              
  • JSON                        
  • PolyBase                   
  • Row-Level Security          
  • Query Store                 
  • Stretch DB                  
  • Temporal Tables 


And here's the link!

http://www.microsoft.com/en-us/download/details.aspx?id=49502

Monday, 7 December 2015

It's that time of year again...time to cross train!



No, I don't mean the post Xmas gym binge to burn off all those extra calories! I'm talking about skill set development and specifically those skills that fall outside of our primary area. Personally speaking, I haven't done too much outside of SQL for a couple of years now having been very focused on the internals of MSSQL, that is changing this year!

Just to head something up first. I won't be dropping any learning/development in SQL Server. SQL 2016 is coming after all, CTP 3.1 is out now and there are plenty of things to be getting stuck into in the new release - new data capabilities, analytics, data warehousing improvements and of course core SQL changes too (I know I keep mentioning it but the In-Memory OLTP functionality is getting more and more practical; it deserves more focus!!). 

The cloud too. Make no mistake, the cloud is the future. It might just be me but I haven't witnessed a big embrace of this technology by the leading SQL experts, not socially anyway. That is clearly changing now and lets be honest, even if your organisation isn't using it at the moment they're sure as hell thinking about it and you should be clued up.

So what else should we be focusing on, we are talking cross training here?! My opening paragraph mentioned being outside of SQL Server and I haven't really mentioned anything particularly out there yet!

Well, this is where it comes down to what interests you. The web is inundated with articles explaining what skills we should be focused on next year. What skills will be commanding the biggest salaries and of course, what skills are just plain trendy but I don't believe following for those reasons works out well in the long term, or the medium...maybe even the short!

So what about me? Well I used to be a developer and it might surprise a few that know me when I say I quite fancy at least getting my hands a little bit dirty in the development game again. The .NET framework has evolved somewhat, JavaScript is right up there of course, JSON too...which leads rather nicely to NoSQL...I know, databases again!

Like the cloud more and more organisations are using non relational databases (just look at the big players that are using MongoDB presently!) and its an area that I really want to know more about.

So, I've kind of hit the surface of my training plans for next year but I would like to know other peoples views on this. Is cross training beneficial or should we stay focused on our main area of expertise? Can we stray too far from our core skill set and if you are training in new or different area's, what are they?



Thursday, 3 December 2015

Incorrect PFS free space information for page...

This article is a bit of a follow up to my why corruption shouldn't be that scary article. Actually, I guess for this example it should be called why failed consistency checks aren't that scary.

Anyway, here's a real life example:

So let's say consistency check (SQL 2005 btw) has failed with the following:

Incorrect PFS free space information for page (1:538) in object ID 60, index ID 1, partition ID 281474980642816, alloc unit ID 71776119065149440 (type LOB data). Expected value   0_PCT_FULL, actual value 100_PCT_FULL.

Oh oh, consistency check failures are bad; time to...



Now before I jump into what is going on here and what to do to fix it I did a quick search on the internet to see what advice people were giving. I found restarting SQL Server to be fairly common, one mentioned connecting via DAC, run some commands and the most common bit of advice I found was to completely restore the database!

They're all wrong, and this is why in my previous article I said to know exactly what you're up against when corruption occurs. You see in this case, it isn't actually corruption that is causing the consistency check to fail but a bug in an internal tracking algorithm.

This particular consistency error is one that can be fixed by running a checkdb with repair allow data loss. Whoa, what did you say there!? Surely you know you should never, ever run that command unless its completely a last resort?!

Well, that's true if we were dealing with corruption at page levels but in this case as no data is specifically involved it is fine (and the consistency check hasn't given us any additional errors). 

So lets fix this by running a repair with the following command:

DBCC CHECKDB ('MyBrokenDatabase', REPAIR_ALLOW_DATA_LOSS)

That isn't going to work, in order for a repair we have to put the database in single user mode.

Msg 7919, Level 16, State 3, Line 1
Repair statement not processed. Database needs to be in single user mode.

Here's the remaining commands:

ALTER DATABASE MyBrokenDatabase SET SINGLE_USER
GO

DBCC CHECKDB ('MyBrokenDatabase', REPAIR_ALLOW_DATA_LOSS)
GO

ALTER DATABASE MyBrokenDatabase SET MULTI_USER
GO

DBCC CHECKDB ('MyBrokenDatabase')

CHECKDB found 0 allocation errors and 0 consistency errors in database 'MyBrokenDatabase'.

And there we have it. A database that has failed a consistency check that we haven't had to restore from backup and we didn't actually need to do any of this straight away. We could have waited for some acceptable downtime to avoid any resource usage by the process.

For another approach on dealing with this error check out this post from Dave Mason from his blog.

Wednesday, 2 December 2015

GREAT READS: Troubleshooting SQL Server: A Guide for the Accidental DBA

Troubleshooting SQL Server: A Guide for the Accidental DBA - 

By Jonathan Kehayias and Ted Krueger



I love this book. I believe that everyone that works or is planning to work with SQL Server should read it. 

OK, I could leave it there but I should explain why do I love it so much? 

I first read read this book very early on in my career as a DBA. As we all know, when you first jump into SQL it can be an incredibly overwhelming experience especially when things aren't working properly.

And this is where the book comes in. It's authors recognise just how many people are thrown in at the deep end and as such it is written specifically for the "Accidental DBA". It's because of this approach that I find it such an easy read but yet the technical content is not sacrificed in the slightest,

What this book does is teaches the correct approach to troubleshooting SQL Server, how to gather evidence from a number of sources to put all of the jigsaw pieces together to see what the server is actually doing and where the problem lies, and of course, what to do about it.

The fundamental techniques taught in this book have stayed with me for years, to this day, and whenever I get asked about what SQL Server books someone should read, this one is always the first I recommend. 

And you can get it HERE. 

You don't have to take my word for it though, did I mention its available as a free PDF download too!

Enjoy!

Tuesday, 1 December 2015

Get the most out of SQL Server 2016...

Upcoming blog series from the SQL Server Team about the 2016 release, kicks off on the 3rd of December. Corporate VP of Microsoft's Data Group is calling it the best SQL Server release in history - do you agree from what you have seen so far?!

http://blogs.technet.com/b/dataplatforminsider/archive/2015/12/01/get-the-most-out-of-sql-server-2016.aspx


Why database corruption shouldn't be that scary.

A rather clever SQL person by the name of Paul Randal once said. "There are two types of people in this world. Those that have experienced database corruption, and those that will."

He's absolutely right. It's more than an occupational hazard, it happens all of the time but despite it's commonality the mere mention of it can still strike fear into many would be database administrators.

Now be assured, I am not trivialising corruption here, not one bit! I've been there. It can turn a good day into a very bad one (the night too), but there are good reasons why you should not live in fear of it.

Firstly database corruption comes in different shapes and sizes and you need to know what you're up against. Yes its likely that it's irrecoverable meaning a full restore is the only way things are going back to normal. But it could a problem with something like metadata such as a view rowcount meaning the object just needs recreating. The time compared to doing that to a full restore could be huge, so lesson one, don't panic and know your enemy! 

The Panic Button - DON'T press it!


There is though a much more important reason as to why you shouldn't fear database corruption and that is because you're are prepared. As another wise man once said that we don't plan to fail, we fail to plan.

If you're having to restore a database into production then you should already be armed with a few bits of critical information. What services are affected, who needs informing and also, how long is this going to take. See my SQL inheritance tax article here on why you really need this info!

You also need to know that your backups are up to date and consistent. I have lost count of the amount of times that I have read on a forum that a database has become corrupt and the only backup is from four weeks ago, if one even exists that is. Seriously, all the time. 

This is where fear really comes from. It's the not knowing. You have to know the backups are there and ready. You have to know how long a restore is going to take and you know why you should know? Because you should have already done it. Recently, and documented it. You've consistency checked it too because you don't just rely on verifying your backups!

So here's a few guidelines:

Backup your databases, regularly.
It's a given I know. No, it should be a given but like I mentioned earlier it is often not the case!

Know your backup jobs.
Do you know if your backup jobs are running successfully? Your backup jobs should definitely notify you in the event of failure but also consider how are you going to know if the job actually ran. If SQL Agent is down, you won't be getting any notifications that way so think about success notifications and customised reporting on your backup tables.

Know your RPO and RTO. 
Standard backup routines are fine but different databases have different recovery objectives and you need to ensure they can be met in the event of disaster. You also need to know what the databases are doing, what services will be affected and who to notify when things go wrong.

Are your databases consistent?
Consistency checking is another given but how often should you do it? Personally, I like to check as often as possible (resource allowing), a minimum of 1 + number of full backups. System databases, every day...why not? And yes, that includes TempDB. Remember corruption often indicates a problem at the IO subsystem, you need to know about it sooner rather than later, speaking of which...

Are you alert?
Consistency checking is all well and good but its scheduled and you need almost real time notifications that things are not quite as they should be. Add SQL Agent alerts for errors 823, 824 and 825 among others.

Your backup strategy is only as good as your restore strategy.
Many times I have encountered SQL instances with sound backup plans and absolutely no restore checks. Verify only is not enough, neither is checksum for that matter...seriously, I'm not kidding! The only way to guarantee that your backup can be restored is to restore it and consistency check it. For critical databases plan a restore check on a regular schedule. 

In the event of corruption, know what you're dealing with.
The golden rule is simple...don't panic! Ensure you know what is being affected here and how. There are several different types of corruption with different methods on how to resolve the problem and it might not necessarily mean a stack of downtime (although it still might). If you are going to have to restore then make sure of one thing; that this is not the first time you have done this!! You want to be going from a plan that is documented, proven to work and rehearsed.

So remember, corruption is not a mythical beast it is very real, it will happen, but rather than be scared of it, be prepared for it.


SQL Server 2016 CTP 3.1

Community Technology Preview 3.1 for SQL 2016 is out now and includes enhancements in several areas.

For me, really looking forward to seeing In-Memory OLTP develop. This release enhances a feature that I was initially quite underwhelmed by. Very promising sure but extremely limited and perhaps now it is becoming more of a practical solution?

We can now look forward to unique indexes, LOB data types and Indexes with NULLable key columns!

Here's the link:

http://blogs.technet.com/b/dataplatforminsider/archive/2015/11/30/introducing-sql-server-2016-community-technology-preview-3-1.aspx