SQL Server, PASS, and other data mishaps
SQL Server
How valuable are good employees
Mar 1st
Every successful business knows that its employees are its biggest asset.
As driven employees, we strive to be members of highly functioning teams. Company management wants a highly effective team, everyone would seem to want the same thing yet it can be hard to achieve for a number of reasons. Highly effective employees on great teams are the fundamental bedrock of all successful businesses. But, what is the difference between an average team and an exceptional team? A interesting discussion I had today about these differences prompted this post.
Are you an above average member of your team?
What makes someone a great technical team member, Is it deep knowledge of a technical subject? Business application of said technology? Ability to schmooze the boss? Any of these things can lead a person to be known as a highly effective employee. likewise inability to execute on any of these things (plus a host of others!) can lead someone to be an average performer or worse an under performer.
What are you worth to your team?
Would you consider yourself 10% above average? 20%? , 50%?. I’ve asked around and when most people are asked their self assessments are that they are at least 20% above average. With that thought, as a business manager would you consider a 1% above average (what is average anyway ????) employee desirable?
Consider the math
As a team member at a reasonable sized organization lets say you are responsible for 50 Million$ in information (data for the DBA’s reading this). If you are able to perform at a 1% higher level than average, you should be able to manage about 500K more than an average team member. If somehow you managed the herculean task of being 20% better than average you’d be able to manage 10 Million$ more. Likewise If you have a team member who is performing at a lower level , say 1% below average they’d only be able to manage 49.5 Million$. 20% below average and well, lets just say its a bad day to be responsible for 40 Million$. If you extrapolate those numbers further and compound them yearly for a few years the 1% better employee Vs the 1% underperformer would look something like this
The 1% high performer nets $51,515,050
while the 1% underperforming employee nets $48,514,950
Thats a 3 Million dollar difference for a 1% above average performance. (not bad!!)
End result is the same
The next time you’re debating with your boss about the value you bring to your team, it can be helpful to point out the math especially if you can make a reasonable leap to huge numbers like billions of dollars in assets and 2% above average Vs 1% below. 1 great employee who brings tons to the table and say works at a 5% above average range is potentially worth more than the entire rest of an under-performing team. Of course, asking your boss for a 500K raise might not go over well either but If you are lucky enough to be able to tie your work product to actual company revenue, this is a great way to show the leaders in your organization how important it is to hire good people, even if they are ONLY better than average by 1%
The 3 most important words for a DBA
Feb 15th
Occasionally I’m asked what the most important thing for a DBA to know is. It seems some people want to know what 1 thing to focus on in order to be successful long term as a DBA. I’ve pondered this question for quite a long time and I’ve given various answers over the years.
Reality intervenes
Ive come to the conclusion that there really is no one special thing or “skill” that its important for a DBA to know. Sure, there are lots of qualities that tend to make a successful DBA. Things like attention to detail, thirst for knowledge, and an uncanny love of BACON… The problem is as huge as the SQL Server product is becoming it is also becoming increasingly difficult to be an expert in everything. I am actually of the opinion that it is impossible to be an expert in everything SQL Server.
Knowing what you dont know
The most important thing for a DBA to know can be summed up in 3 simple words ” I Dont Know” Why is that important? Because, knowing what you don’t know, and being able to admit it to those around you is by far the most valuable skill that you can poses as a DBA at any skill level.
When in doubt its always good to remember that its ok to say “I don’t know” The Corollary to this statement is of course “Ill find out, or find someone who does know”. Ive seen many small issues blow up into large problems over the years because someone didn’t really understand what was going on and they were afraid to let their coworkers (or boss) know that they don’t understand. In many cases if we’ll just learn to say “I don’t know” some further pain can easily be avoided.
Database Automagic
Feb 8th
This months TSQL Tuesday is hosted by a good friend Pat right over at SQL Asylum
For this months entry I decided to keep it short and sweet, following in my Bits N Bytes theme.
The Meta Script
In the true sense of the word automation, this really doesn’t fit but, in the terms of quickly getting something done that would otherwise be a mundane repetitive task, this can save a world of time.
Lets say we have a list of objects in the Sales Schema and we have a request to grant Select and Insert access to a user for those objects. There are two approaches, 1 is to grant select and insert to the actual schema like this
GRANT SELECT, INSERT ON SCHEMA::Sales TO BusinessUser
However you might decide that you only want to grant direct SELECT and INSERT on the tables that exist in the DBO Schema today not those tables which may be created in the future (auditors love to make us do this)
A simple way to automate granting these rights is by writing a script that writes a script like so
ON obj.schema_id = sch.schema_id
and obj.type = ‘U’
This should give you a result set that looks something like the following:
GRANT SELECT, INSERT ON Sales.People TO BusinessUser
GRANT SELECT, INSERT ON Sales.Sales TO BusinessUser
At this point, run the output in a separate command window and viola you’ve automated that grant of permissions
This may not be true “automation” in the sense that Pat was looking for but, perfecting the ability to write scripts that write scripts is a huge timesaver
A tall tale of SQL database corruption
Feb 1st
This corruption story begins like many. Somebody in a server room far far away decided to make a change to a VMware guest machine and that little change rippled through our poor server like a lady Gaga Meat Dress through the VMA’s. Needless to say, it wasnt pretty. The full set of events may never be known by me but it appeared as though our guest server ran out of disk space on the OS and some form of recovery was done.
What we started with was a sql 2005 sp3 server where 1 of the drives was apparently corrupted, So 2 SQL instances wouldnt start. They were both erroring with the message :
Error: 9003, Severity: 20, State: 1.
The log scan number (23:5736:37) passed to log scan in database ‘master’ is not valid. This error may indicate data corruption or that the log file (.ldf) does not match the data file (.mdf). If this error occurred during replication, re-create the publication. Otherwise, restore from backup if the problem results in a failure during startup.
Using trace flag 3608 and startup parameters -c -m I set about to do a normal “disaster” recovery of our server
After rebuilding the master database, everything came online successfully. Then master was recovered from the previous backup. Once master was online I started getting the very same error message about the model database
Error: 9003, Severity: 20, State: 1.
The LSN (11:999:1) passed to log scan in database ‘model’ is invalid
This would prove to be a trying error! it took about several iterations and quite a time to figure out exactly what was going on.
On this server after initial setup we had moved the system databases from the install drive to seperate drives for log and data. When rebuilding master, the system db’s wind up back in the default directories but, after recovering master, the databases are pointed back to the original locations.
Once we got the server started the log scan error message for model showed up so, I began what I thought would be a normal restore of the model database. Unfortunately, there was no way for model to be restored. During the restore command, I got alternating messages that the model database log file was corrupted
Error: 3283, Severity: 16, State: 1.
The file “modellog” failed to initialize correctly. Examine the error logs for more detail
The Error 3283 Would be followed by
the database ‘model’ is marked RESTORING and is in a state that does not allow recovery to be run.
After trying various iterations of deleting the existing model log & database files, copying in the newly created ones and running restores, nothing was working. I began to think the disks were actually having problems, or the backup was bad. After verifying both the backup and the disk config I was left with only a hail mary –> sp_detach_db
After detaching model, I copied in the newly created model files (from the rebuild of master) and ran sp_attach_db on them. Once the Model database was attached the instance started successfully!
After the instance started model was restored from the same backup and the instance restarted. Finally, once the instance came online, it was a standard restore of all the user databases.
Im not sure what about the logscan error in model caused the errors I saw, but, both instances behaved exactly the same. I had to detach and reattach a blank model to make the other instance work as well.
After going through this, I went back and tried to reproduce the problems by intentionally corrupting model and its transaction log in various ways. Every corruption I could cause in model behaved as I expected and a simple restore statement worked. Im still not sure WHY this happened but, hopefully it wont happen again and if it does there wont be so much testing to figure out how to get model online
Changing the owner of nearly anything in SQL Server
Jan 17th
The other day we were going through some old scripts and had a huge discussion about changing object ownership in SQL. Forever the only answers were to recreate the objects or use the stored procedures: sp_changeobjectowner or sp_changedbowner. Alternatively at times there were those of us who used some other undisclosed hack of system tables but, I’ve never done anything like that…
Since SQL 2005 Alter Authorization has been the right way to change ownership of nearly anything
This is the most common use of alter authorization but there are many more.
sp_changeobjectowner would look like this
sp_changeobjectowner 'Products.Description','AllenK'
While the updated syntax would look like this
ALTER AUTHORIZATION ON OBJECT::[Products].[Description] TO [AllenK]
What really brought this post about was because I was working with certificates recently and at the time I needed to change who the owner and I just exported/imported & recreated them. It was easy and what I knew would work. After looking through the syntax for alter authorization I realized I could & probably should have done it this way. I guess old habits die hard.
ALTER AUTHORIZATION ON CERTIFICATE::[MYCERTIFICATE] TO [CERTOWNER]
Some out there might question why I’m rehashing syntax changes that happened nearly 5 years ago, The reality is that even in 2011 a lot of the installations of SQL Server I look at are still 2005 and many of the people I run into still use old ways of doing things, this is for you (and me)!
ALTER AUTHORIZATION ON OBJECT::[Products].[Description] TO [AllenK]
