The Multifunctioning DBA:

MSSQL

Oct 27 2009   3:30AM GMT

Active, Active, Active



Posted by: Colin Smith
MSSQL, MSSQL Administration, MSSQL Install, MSSQL Server, SQL Server 2008, Cluster

Last week I got the chance to work on an Active, Active, Active SQL Server 2008 Cluster install. This was new to me and very fun. We have three physical hosts all using SQL Server 2008 Enterprise Edition. The Servers are also running Windows Server 2008 Enterprise Edition. I worked with one of our windows admins to do the install. First the windows admin set up the windows cluster and assigned all of the storage to the cluster but did not assign it to an application or service. Once that was done we had to set up the Distributed Transaction Coordinator and give it its storage. Now we started the install of SQL Server 2008. Since all of the storage was owned by one server we installed all three instances, one for each node, of SQL Server on that server and that created the different cluster applications for us. Then on each of the other servers we added a node three times, again once for each instance. Now that is complete we can fail over the resources for any instance to any of the physical nodes. Very cool.

Oct 22 2009   10:00AM GMT

MCTS Exam



Posted by: Colin Smith
Certification, Study, MSSQL, MS SQL Server

So Like I said before I did take the MCTS Exam and I did pass. I can not go into any detail about the test as you have to agree to an NDA before you take it. The test was, in my opinion, not as hard as the study material. I think that MS did a great job with the study material for this test. I was not sure if I was really ready for the test but it turns out I was more than ready.
I finished the test very early. I had about 40 minutes left when I completed the question portion and still over 1 hour left when I completed the simulation portion of the Exam. To study I purchased the following kit and I am about to start on the second book to prepare for the second of the three tests required for the MCITP:DBA certification. Think I will start hitting that hard when I return from Hawaii.

 http://www.amazon.com/gp/product/0735623…

Read the book and spend time doing the practices and questions in the book and definitely take the practice tests. You will do well if you do all that.


Sep 16 2009   3:23PM GMT

Installing SQL Server 2008



Posted by: Colin Smith
MSSQL Server, MSSQL Administration, MSSQL, MSSQL Install

Yesterday I had to install SQL Server 2008 for the first time. I went through it on a development server first before installing on a production server. As I went through the setup process I noticed one thing that I think is long overdue. The Database Configuration step is a great addition to the install process. It is about time that MS allowed us to seperate out where all the Database and Log files will be before we actually do the install. This makes it easy to break out tempdb from the other databases and also to separate your data and log files. Make sure that you take advantage of this and plan out where you want all of the data files and log files to be on the file system. This will save some headache in the future when you have to move all of your databases as well as the system databases.


Jul 28 2009   10:18PM GMT

Migrating SQL 2005 Reporting Services



Posted by: Colin Smith
MSSQL Administration, MSSQL Server, MSSQL, Database Administration, Reporting Services

I have been asked to help with Migrating a SQL Server 2005 Reporting Services server from one host to another. I set up a couple VM’s and away I went. I found that it is pretty straight forward though. I did run into a couple little hickups along the way but nothing to dificult. I did have a problem though, after I attached the database on the new server and brought up the reporting services configuration manager. I could not get the server to initialize. To resolve the issue I had t delete the encryption keys. Then I was able to initialize the server but I could not get any of my reports to run. Kept getting error about connection string not being initialized. I then changed the encryption keys in the configuration manager and all started working again. One other thing is to make sure that you have the RSExecRole setup. Here is a link on migrating a reporting services server.

 http://msdn.microsoft.com/en-us/library/…


Jul 14 2009   3:53PM GMT

New Job



Posted by: Colin Smith
MSSQL Administration, MSSQL, Job Market, Job

Last Thursday my company did some layoffs and re-orginization. I survived the layoffs but my job has changed. I am no longer a Database Administrator for a major media company in Phoenix Arizona, but now I am a Database Analyst for a nation wide media company. I am still based in the Phoenix area and still use my same desk, computer and all that. I will still be doing Database Administration for the company in Phoenix as well, but my role is expanding. This company is a big MS Shop and I will be essentailly the only Administrator for all instances that this large enterprise has. I am very excited about this opportunity and look forward to the challenges ahead of me. I know that this will put my learning on the fast track and I am hoping to have my first test done in a month or two at the most. Well wish me luck and I am sure that I will have many new stories and experiances to share as I move forward on this new adventure.


Jul 13 2009   5:31PM GMT

MSSQL Server Renaming Physical Host



Posted by: Colin Smith
MS SQL, MSSQL, MS SQL Server, Database Administration

Recently I had a server that hosts a MSSQL 2005 SQL Server named instance and the Windows group decided that the name of the server had to be changed. I thought that this may cuase an issue since the MSSQL Server name is ‘hostname\instancename’. I did a bit of research and found that a solution is available for this problem. At first I thought that I may have to reinstall a new instance of SQL Server in order to get the name correct. I did not want to go thru all of that though.

I found that MS has a couple of Stored Procs that will help with this problem.

sp_dropserver ‘hostname\instancename’ –of the old server\instancename

sp_addserver ‘hostname\instancename’, ‘local’ –of the new server\instancename

I found that when I did a select @@servername I still got the old server name returned. I also found that when I did a sp_helpserver I got the new name. I decided I would restart the server to see if that would update the @@servername variable. I right clicked on the server and said restart. After it cam back up I got a ‘NULL’ from select @@servername. I did not understand why and really still do not. I was able to resolve the issue by going to the services.msc and restarting the SQL Server Service from there. Now I see the new server name from select @@servername as well as sp_helpserver.


Jun 26 2009   5:46PM GMT

Finding what account a Service is running as



Posted by: Colin Smith
Powershell, Services, MSSQL, Database Administration

Yesterday my boss came to me asking if I knew what server an account was running on. I know that the account is used as a SQL Server service account because of the naming convention that was used. I also know that the account is being used as I used the Quest Software cmdlet get-qaduser to query AD for the account and get the last logon time. Now I just needed to find out what server it was running on. With the account naming conventions that we use this normally would not be an issue but in this case it was as the server that it should have been used on no longer exists. The server had been virtualized and now has a new name. So I put together a script that would identify the server for me. I had the script read in all of my servers from my sqltab file that I have talked about before, and list all of the sql server services and the accounts that they were running as for each server. Here is a nice little one liner that will get you a listing of all sql server services on a server and the account that they are running as. Hope you can get some use out of this.

Get-WmiObject Win32_service -computername $computername | select name, startname | Where-Object{$_.name -like “*SQL*”}


Jun 25 2009   9:24PM GMT

PowerShell SQL Server Health Check Script



Posted by: Colin Smith
Powershell, SQL Server, MSSQL, Excel, Monitoring

OK so I think that I have everything I want in my script to check on the health of my SQL Servers. I will run this at least once a day and more if needed. I hope that this will help some people out and if you have any questions, comments, or ideas of what else might be good to include please let me know.

SQL Health Check Script:


#Create a new Excel object using COM $Excel = New-Object -ComObject Excel.Application $Excel.visible = $True #$Excel.visible = $False #$workbook = $excel.Workbooks.Open("D:\pac health checks.xlsx") $Excel = $Excel.Workbooks.Add() $Sheet = $Excel.Worksheets.Item(1) #Counter variable for rows $intRow = 2 #Read thru the contents of the SQL_Servers.txt file #$servers = Import-Csv "\\pni-vmdbasql\d$\monitoring\inputs\sqltab.txt" $servers = Import-Csv "\\ent-pocpacapcx01\d$\monitoring\sqltab.txt" ######################################################### foreach ($entry in $servers) { $torp = $entry.TorP $mon = $entry.monitor $machine = $entry.server $errorlog = $entry.errorlog $os = $entry.os2000 $iname = $entry.Instance if ($iname -eq "Null") { $instance = "$machine" } else { $instance = "$machine\$iname" } if ($torp -eq "Prod") { $ServerType = "Production" } else { $ServerType = "Test" } $instance = $instance.toupper() ######################################################### #foreach ($instance in get-content "D:\SQL_Servers.txt") #{ #Create column headers $Sheet.Cells.Item($intRow,1) = "INSTANCE NAME:" $Sheet.Cells.Item($intRow,2) = $instance ################################################ #This script gets SQL Server database information using PowerShell [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null # Create an SMO connection to the instance $s = New-Object ('Microsoft.SqlServer.Management.Smo.Server') $instance $dbs = $s.Databases #$dbs | SELECT Name, Collation, CompatibilityLevel, AutoShrink, RecoveryModel, Size, SpaceAvailable #Formatting using Excel $version = $s.VersionString if ($version -like "*9.00.1399*") { $sqlversion = "SQL Server 2005 No Service Pack" } elseif ($version -like "*9.00.2047*") { $sqlversion = "SQL Server 2005 SP1" } elseif ($version -like "*9.00.3042*") { $sqlversion = "SQL Server 2005 SP2" } elseif ($version -like "*9.00.3068*") { $sqlversion = "SQL Server 2005 SP2" } elseif ($version -like "*9.00.3054*") { $sqlversion = "SQL Server 2005 SP2 with Q934458" } elseif ($version -like "*9.00.3073*") { $sqlversion = "SQL Server 2005 SP2 with Q954606" } elseif ($version -like "*9.00.3186*") { $sqlversion = "SQL Server 2005 SP2 with Q939562" } elseif ($version -like "*9.00.4035*") { $sqlversion = "SQL Server 2005 SP3" } ## SQL Server 2000 Checks elseif ($version -like "*8.00.194*") { $sqlversion = "SQL Server 2000 No SP" } elseif ($version -like "*8.00.384*") { $sqlversion = "SQL Server 2000 SP1" } elseif ($version -like "*8.00.532*") { $sqlversion = "SQL Server 2000 SP2" } elseif ($version -like "*8.00.760*") { $sqlversion = "SQL Server 2000 SP3" } elseif ($version -like "*8.00.818*") { $sqlversion = "SQL Server 2000 SP3 with MS03-031" } elseif ($version -like "*8.00.2039*") { $sqlversion = "SQL Server 2000 SP4" } elseif ($version -like "*8.00.2040*") { $sqlversion = "SQL Server 2000 NoSP with Q274329" } elseif ($version -like "*8.00.2050*") { $sqlversion = "SQL Server 2000 SP4 with MS08-040" } elseif ($version -like "*8.00.2187*") { $sqlversion = "SQL Server 2000 SP1 with Q923849" } elseif ($version -like "*8.00.2282*") { $sqlversion = "SQL Server 2000 QFE" } elseif ($version -like "*8.00.3073*") { $sqlversion = "SQL Server 2000 SP2 with Q954606" } #SQL Server 7 elseif ($version -like "*7.00.1094*") { $sqlversion = "SQL Server 7 SP4 with Q815495, Q821279" } #SQL Server 2008 elseif ($version -like "*10.0.1442.32*") { $sqlversion = "SQL Server 2008 X64 MSDN Beta" } else { $sqlversion = "Check me $version" } $Sheet.Cells.Item($intRow,3) = "Version:" $Sheet.Cells.Item($intRow,4) = $sqlversion $Sheet.Cells.Item($intRow,5) = $ServerType if ($Servertype -eq "Production") { $fgColor = 35 } else { $fgColor = 0 } $Sheet.Cells.item($intRow, 5).Interior.ColorIndex = $fgColor ########################################################### $Sheet.Cells.Item($intRow,1).Font.Bold = $True $Sheet.Cells.Item($intRow,2).Font.Bold = $True $Sheet.Cells.Item($intRow,3).Font.Bold = $True $Sheet.Cells.Item($intRow,4).Font.Bold = $True $Sheet.Cells.Item($intRow,5).Font.Bold = $True ############################################## ## Are full and tranlog backups running? ## DB Reindexing running? ############################################## $intRow ++ $jobsserver = $s.JobServer $jobs = $jobsserver.Jobs $ijob = 0 $backjob = 0 $tranjob = 0 foreach ($job in $jobs) { if (($job.name -like "*backup*") -and ($job.name -notlike "*Tranlog*")) { $backjob = 1 $fullbackup = $job.name $fullbackupstatus = $job.LastRunOutcome $fullbackupdate = $job.LastRunDate } if ($job.Name -like "*tranlog*") { $tranjob = 1 $tranlogbackup = $job.name $tranlogbackupstatus = $job.LastRunOutcome $tranlogbackupdate = $job.LastRunDate } if ($job.Name -like "*index*") { $ijob = 1 $rebuildindex = $job.Name $rebuildindexstatus = $job.LastRunOutcome $rebuildindexdate = $job.LastRunDate } } ## Check to verify full backups are running ## $dayago = [datetime]::Now.AddDays(-1) if (($fullbackupstatus -eq "Succeeded") -and ($fullbackupdate -gt $dayago)) { $fullbackupjob = "Full Backups Running" } elseif(($fullbackupstatus -ne "succeeded") -or ($fullbackupdate -lt $dayago)) { $fullbackupjob = "Full Backups Failing" } if ($backjob -eq 0) { $fullbackupjob = "No Full Backup Job" } ## Check to verify that Tranlogs backups are running fine ## $hourago = [datetime]::Now.AddHours(-1) if (($tranlogbackupstatus -eq "Succeeded") -and ($tranlogbackupdate -gt $hourago)) { $tranbackupjob = "Tran Backup Running" } if(($tranlogbackupstatus -ne "succeeded") -or ($tranlogbackupdate -lt $hourago)) { $tranbackupjob = "Tran BackupFailing" } if ($tranjob -eq 0) { $tranbackupjob = "No Tran Backup Job" } $weekago = [datetime]::Now.AddDays(-7) if (($rebuildindexstatus -eq "Succeeded") -and ($rebuildindexdate -gt $weekago)) { $indexjob = "Indexing Running" } elseif(($rebuildindexstatus -ne "succeeded") -or ($rebuildindexdate -lt $weekago)) { $indexjob = "Indexing Failing" } if ($ijob -eq 0) { $indexjob = "No Indexing Job" } $Sheet.Cells.Item($intRow,1) = $fullbackupjob $Sheet.Cells.Item($intRow,2) = $tranbackupjob $Sheet.Cells.Item($intRow,3) = $indexjob $Sheet.Cells.Item($intRow,1).Font.Bold = $True $Sheet.Cells.Item($intRow,2).Font.Bold = $True $Sheet.Cells.Item($intRow,3).Font.Bold = $True ############################################## $intRow++ $Sheet.Cells.Item($intRow,1) = "DATABASE NAME" $Sheet.Cells.Item($intRow,2) = "RECOVERY MODEL" $Sheet.Cells.Item($intRow,3) = "SIZE (MB)" $Sheet.Cells.Item($intRow,4) = "SPACE AVAILABLE (MB)" $Sheet.Cells.Item($intRow,5) = "DATA DRIVE" $Sheet.Cells.Item($intRow,6) = "SPACE AVAILABLE ON DISK (GB)" $Sheet.Cells.Item($intRow,7) = "MIRROR STATUS" $Sheet.Cells.Item($intRow,8) = "LOG SIZE (MB)" #Format the column headers for ($col = 1; $col –le 8; $col++) { $Sheet.Cells.Item($intRow,$col).Font.Bold = $True $Sheet.Cells.Item($intRow,$col).Interior.ColorIndex = 48 $Sheet.Cells.Item($intRow,$col).Font.ColorIndex = 34 } $intRow++ ####################################################### # #This script gets SQL Server database information using PowerShell # # [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null # # # Create an SMO connection to the instance # $s = New-Object ('Microsoft.SqlServer.Management.Smo.Server') $instance # # $dbs = $s.Databases # # #$dbs | SELECT Name, Collation, CompatibilityLevel, AutoShrink, RecoveryModel, Size, SpaceAvailable # # #Formatting using Excel foreach ($db in $dbs) { $name = $db.name $model = $db.recoverymodel if ($model -eq 1) { $modelname = "Full" } elseif ($model -eq 2) { $modelname = "Bulk Logged" } elseif ($model -eq 3) { $modelname = "Simple" } $logfiles = $db.LogFiles foreach ($log in $logfiles) { $logsize = $log.size/1KB $logsize = [math]::Round($logsize, 2) } #if(($name -ne "master") -and ($name -ne "model")) # -and ($name -ne "msdb")) #{ #Divide the value of SpaceAvailable by 1KB $dbSpaceAvailable = $db.SpaceAvailable/1KB #Format the results to a number with three decimal places $dbSpaceAvailable = "{0:N3}" -f $dbSpaceAvailable $Sheet.Cells.Item($intRow, 1) = $db.Name $Sheet.Cells.Item($intRow, 2) = $modelname $Sheet.Cells.Item($intRow, 3) = "{0:N3}" -f $db.Size #Change the background color of the Cell depending on the SpaceAvailable property value if ($dbSpaceAvailable -eq 0.00) { $fgColor = 38 } else { $fgColor = 0 } $Sheet.Cells.Item($intRow, 4) = $dbSpaceAvailable $Sheet.Cells.item($intRow, 4).Interior.ColorIndex = $fgColor $dblocation = $db.primaryfilepath $dblocation = $dblocation.split(":") $dbdrive = $dblocation[0] $drives = Get-WmiObject -ComputerName $machine Win32_LogicalDisk | Where-Object {$_.DriveType -eq 3} foreach($drive in $drives) { $size1 = $drive.size / 1GB $size = "{0:N2}" -f $size1 $free1 = $drive.freespace / 1GB $free = "{0:N2}" -f $free1 $ID = $drive.DeviceID $a = $free1 / $size1 * 100 $b = "{0:N2}" -f $a if ($dbdrive -eq "C") { $fgColor = 38 } else { $fgColor = 0 } $Sheet.Cells.Item($intRow,5) = $dbdrive $Sheet.Cells.item($intRow, 5).Interior.ColorIndex = $fgColor if ($id -like "$dbdrive*") { if ($free1 -lt 5) { $fgColor = 38 } else { $fgColor = 0 } if (($ID -eq "C:") -and ($free1 -lt 1)) { $fgColor = 38 } $Sheet.Cells.Item($intRow,6) = $free1 $Sheet.Cells.item($intRow, 6).Interior.ColorIndex = $fgColor } } if($version -like "*2000*") {$mirrorstate = 0} else { $mirrorstate = $db.MirroringStatus } if ($mirrorstate -eq 0) { $mirror = "No Mirror" } if ($mirrorstate -eq 1) {$mirror = "Suspended" } if($mirrorstate -eq 5) { $mirror = "Synchronized" } if ($mirrorstate -eq 1) { $fgcolor = 38 } else { $fgcolor = 0 } $Sheet.Cells.Item($intRow,7) = $mirror $Sheet.Cells.item($intRow, 7).Interior.ColorIndex = $fgColor if ($logsize -gt 500) { $fgColor = 38 } else { $fgColor = 0 } $Sheet.Cells.Item($intRow,8) = $logsize $Sheet.Cells.item($intRow, 8).Interior.ColorIndex = $fgColor $intRow ++ #} } $intRow ++ } $Sheet.UsedRange.EntireColumn.AutoFit() cls $workbook.saveas("D:\pac health checks.xlsx") #$excel.Quit() $WorkBook = $Null $WorkSheet = $Null $Excel = $Null [GC]::Collect()

Here is a sample of what the report will look like when you have run it.

Report Output Sample

Report Output Sample


Jun 25 2009   3:30PM GMT

SQL Server Health Report



Posted by: Colin Smith
SQL Server, MSSQL, Microsoft, Powershell, Monitoring, Reporting

Yesterday I posted about a great article that I found on how to use Powershell to create an excel file and also use SMO to get information about SQL Server. I am working on a report that I will have run daily. This report is going to give me an overall health check of my SQL Servers. I am going to have it report to me if all of my important jobs are set up and running properly, These jobs being things like backups, tranlog backups (if the Database is using the Full Recovery Model), Rebuild indexes, and things like that. it will tell me how big each Database is, where the MDF and LDF files are on the filesystem, How much drive space we have available for those databases on the filesystem, how much space allocated to the DB is Free, and finally, for instances that have mirroring set up it will tell me the state of the mirror.

For the servers that I am working with on this report I feel that this really does give me a good health check of the server. I am sure that as time goes on I will add more and perhaps modify this to output as a web page and then put some nice eye candy on it for things like cache hit ratio and other metrics like that. I will be posting the code for this report when I am complete with it.


Jun 23 2009   7:54PM GMT

Powershell and SQL Server



Posted by: Colin Smith
Powershell, SQL Server, MSSQL, Reporting

Today I wanted to use Powershell to create a report about my SQL Servers. I found a great article about how to do this using Excel at this link. http://www.mssqltips.com/tip.asp?tip=175… the author does a great job here and has a great sample script that you can start with and then modify as you need. I am doing some modifications and adding some information from the filesystem to the report as well. If you want a good quick easy way to get some eyecandy reporting done in Powershell this is a great article. Thanks to Edwin Sarmiento for putting this out there.