The Multifunctioning DBA:

April, 2009

Apr 30 2009   9:15PM GMT

Powershell Ping (Cont)



Posted by: Colin Smith
Database, Powershell, SQL Server, Monitoring, Ping, System Administration, Database Administration

Earlier this month I posted about SQL Ping Servers Script that I was working on to notify different groups if a server was down or just SQL Server was down or just the agent was down. Well here is the next part. This is the Ping_Interface Function of the script. This goes out and does a normal dos ping and looks at the return value. Sends only 1 packet and checks for 0% loss to be in the return value. Anything but that and it fails. If it fails it checks the ping_failure variable. If that is 0 then it knows to send the notification out and it puts the touch file on the filesystem so that on the next run it knows that it sent the notification out on the last run. Windows team did not want to be overtly notified that a server was down. Not my idea. So here is the function and if you have any questions head to http://sysadminsmith.com and click the ‘Submit a Question’ link.

##Ping_Interface

function
Ping_Interface

{

echo
“nt users are $ntusers”

$pingresult
=
ping
$machine
-n 1

if ($pingresult
-like
“*(0% loss*”)

{

## Server Interface is responsive

## Remove Ping Failure file from monitoring folder if ping is successful and file exists.

$pingfail
= 0

if (test-path
“i:\$folder\ping_Failure.txt”)

{

del
“i:\$folder\ping_Failure.txt”

}

echo
“Ping Interface is succseful for $machine” >> “i:\OUT\ping_with_service_check.txt”

Check_Services
## Check to see if the SQL Server and the SQLAgent are running via WMI

}

else

{

## Server Interface is non-responsive

$pingfail
= 1

if (!(test-path
“i:\$folder\ping_Failure.txt”))

{

New-Item
-force
-itemType
file
-path
“i:\$folder\ping_Failure.txt”

}

## Check if this is first time and if it has been more than 6 hours since notification was sent.

if (($pingfail
-eq 1) -and ($pingnoemail
-eq 0))

{

$users
=
get-content
-path
“i:\$folder\email”
|
Sort-Object
|
Get-Unique

$users
=
$users
+
$NTusers

$Subject
=
“Unable to Ping $machine”

$body
=
“$machine is not responding to Ping. $pingresult.”

echo
“Ping interface failed for $machine, Sending notification to Systems Team and DBA Team” >> “i:\OUT\ping_with_service_check.txt”

Notify

}

else

{

echo
“Ping interface failed for $machine, notification has already been sent.” >> “i:\OUT\ping_with_service_check.txt”

}


}

}

Apr 29 2009   9:26PM GMT

SQL Server Training Kit



Posted by: Colin Smith
Education, Training, MCITP: DBA, Certifications

I received my SQL Server 2005 Certification Training kit in the mail and have started on the first book. I am trying to do a chapter a day so that I will be able to take the test in a month or less. So far I have only done two chapters in two days but the book is not bad to read and has good explanation. I am doing all the practices, questions, and case studies. So far nothing has been to hard and it has been stuff that I already have a good understanding of with the exception of the bit of encryption that it got into. Nothing to hard though. I am looking forward to Chapter 3 to learn more about the configuration options on the server. I am hoping to be able to help performance on some of my instances once I get a feel for what all the options really mean and how they affect the server.


Apr 29 2009   7:27PM GMT

Error while installing SQL Server 2005 SP 3



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

I have installed SP3 on a few SQL Servers with no issue at all. The other day I go to install it on a production instance and it fails with the following error:

A Recently Applied Update, KB955706, failed to install.

The update failed with that error for the following services:

Database Services

Notification Services

Integration Services

Client Components

I then went and looked into the log files for each that failed and I noticed some interesting things. Here are the highlights:

Warning: Local cached package ‘C:\WINDOWS\Installer\8510ea.msi’ is missing.

Couldn’t find local patch ‘C:\WINDOWS\Installer\549bc1bf.msp’. Looking for it at its source.

MainEngineThread is returning 1635

This patch package could not be opened. Verify that the patch package exists and that you can access it, or contact the application vendor to verify that this is a valid Windows Installer patch package.

D:\SQL Installer\Disk 1\Setup\SqlRun_SQL.msi

So I started googleing like crazy and I was just about ready to call MS to open a case when I found the best writeup ever on this problem.

http://blogs.msdn.com/sqlserverfaq/archive/2009/01/30/part-1-sql-server-2005-patch-fails-to-install-with-an-error-unable-to-install-windows-installer-msp-file.aspx

I followed the instructions here on a clone of the server and everything worked perfect. Now I just need to make sure that no one ever touches the c:\Windows\Installer directory when trying to free up disk space.


Apr 28 2009   10:15PM GMT

SQL Version Script



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

I needed a quick audit of some of the SQL Servers in my environment. We wanted to know what version and what SP each instance was running. I threw this together and it is pretty simple. It only checks for SQL Server 2000 SP4 and SQL Server 2005 RTM thru SP3.

New-PSDrive
i
-PSProvider
filesystem
-Root
Path
to
where
input
file
is

Clear-Content
“Path to results file”

$OUTFILE
=
path
to
outfile

$servers
=
Import-Csv
-Path
“i:\sqltab.txt”

$sqlquery1
=
“select @@version”

$sqlcatalog
=
“master”

foreach ($server
in
$servers)

{

$machine
=
$server.server

$instance
=
$server.instance

$torp
=
$server.torp

$ping
=
$server.ping


if ($instance
-eq
“NULL”)

{

$SqlServer
=
$server.server

$folder
=
$server.server

}

else

{

$SqlServer
=
“$machine\$instance”

$folder
=
“$machine-$instance”

}

$sqlcommandpath
=
“c:\Program Files\Microsoft SQL Server\90\Tools\binn\”

cd
$sqlcommandpath

$version
= ./sqlcmd.exe
-Q
“`”$sqlquery1`” -S $SqlServer -d $sqlcatalog -Y 255″

if ($version
-like
“*1399*”)

{$sqlversion
=
“SQL Server 2005 No Service Pack”}

if ($version
-like
“*2047*”)

{$sqlversion
=
“SQL Server 2005 SP1″}

if ($version
-like
“*3042*”)

{$sqlversion
=
“SQL Server 2005 SP2″}

if ($version
-like
“*4035*”)

{$sqlversion
=
“SQL Server 2005 SP3″}

if ($version
-like
“*2050*”)

{$sqlversion
=
“SQL Server 2000 SP4″}

echo
“`n######################################################################” >> $OUTFILE

echo
”         Server = $SqlServer                                ” >> $OUTFILE

echo
“            $sqlversion                                     ”>> $OUTFILE

echo
“######################################################################`n” >> $OUTFILE

If you have read my other posts then you know that sqltab is a csv file with all the information about my servers. If you have any questions about this or anything else head over to
http://sysadminsmith.com
and click on ‘Submit a Question’



Apr 24 2009   6:53PM GMT

MS Employee Comments on Blog



Posted by: Colin Smith
Microsofr, SQL Server, Installation, DBA, Database Administration

Yesterday I posted a blog about installing SQL Server 2008 SSIS DTS Package Migration Wizard. This can be found at http://itknowledgeexchange.techtarget.com/dba/dts-migration-to-sql-server-2008-ssis/. I received a comment from Andrew Fryer who is a Microsoft Employee about the post. His blog can be found here and he has some pretty cool stuff that you might want to check out. http://blogs.technet.com/andrew/default.aspx

First off I think it is very cool that an MS Employee read my post and actually commented on it. Here is Andrew’s comment.
The backward compatibility stuff is part of the SQL Server feature pack,
http://www.microsoft.com/downloads/details.aspx?FamilyId=C6C3E9EF-BA29-4A43-8D69-A2BED18FE73C&displaylang=en

and we don’t put all this in by default to keep the size of the install down and reduce it’s
complexity as it’s not always needed. My other comment would be that DTSXChange is the killer
tool for migrating DTS to SSIS.

Andrew

I really appreciate the comment and I responded to him telling him that I appreciate that MS
wants to keep the install as lean as possible but I would like to have the option in the installer
to install this feature instead of having to drill down to the MSI file on the installation media.
Andrew again replied saying that I should make this suggestion to the product team know via connect (http://connect.microsoft.com). I ask that all of you, if you agree with me, make this known to the Project team.

Thanks again Andrew.

If you have any questions please let me know by heading to http://sysadminsmith.com and clicking he ‘Submit a Question’ Link.


Apr 24 2009   4:15PM GMT

SQL Ping Servers Improved



Posted by: Colin Smith
Powershell, SQL Server, DBA, Monitoring, Database Administration, Windows Administration

Not long ago I did a post about pinging the interface of a server since you may encounter a problem connecting to WMI even if a server is up. The article is at http://itknowledgeexchange.techtarget.com/dba/powershell-ping/.

So Like I describe in that post I did not want our DBA team to be paged about a SQL Server being down when it was really an issue with the host server. In that case I would like the Windows Administration team to be notified so that they can take care of the issue. I also wanted to check on some other things about the server. I wanted to check the physical interface, check that the agent service is running, and also verify that connections to the database can be made. I have finished the script to do this and I will go over it with you a function at a time. First we will look at the Main function. This is where everything gets set up.

#################################

####### Start Script ############

#################################

$ErrorActionPreference
=
“SilentlyContinue”

$time
=
Get-Date
-displayhint
time

$date
=
date

New-PSDrive
i
-PSProvider
filesystem
-Root \\SomeServer\SomeShare

if (test-path
“i:\OUT\ping_with_service_check.txt”)

{

Clear-Content
-path
“i:\OUT\ping_with_service_check.txt”

}

##Read in List of SQL Servers And set up all needed variables for script

$NTusers
=
“phx.it.systems.nt@pni.com”

$servers
=
Import-Csv
-Path
“i:\inputs\sqltab.txt”

foreach ($server
in
$servers)

{

$machine
=
$server.server

$instance
=
$server.instance

$torp
=
$server.torp

$ping
=
$server.ping

if ($instance
-eq
“NULL”)

{

$SqlServer
=
$server.server

$folder
=
$server.server

$sqlagent
=
“sqlserveragent”

$sqlserverservice
=
“mssqlserver”

}

else

{

$SqlServer
=
“$machine\$instance”

$folder
=
“$machine-$instance”

$sqlagent
=
“sqlagent`$$instance”

$sqlserverservice
=
“mssql`$$instance”

}

echo
“`n############################”

echo
“`n############################” >> “i:\OUT\ping_with_service_check.txt”

$machine >> “i:\OUT\ping_with_service_check.txt”

$machine

if ($ping
-eq
“Y”)

{

if (test-path
“i:\$folder\wmi_Failure.txt”)

{

$wmierror
= 1

$wminoemail
= 1

$wmifile
=
Get-ChildItem
“i:\$folder”
|
where{$_.name
-eq
“wmi_failure.txt”}


$filetime
=
$wmifile.lastwritetime

if($filetime-le
$date.AddDays(-1))

{

del
“i:\$folder\wmi_Failure.txt”

}

}

if (!(test-path
“i:\$folder\wmi_Failure.txt”))

{

$wmierror
= 0

$wminoemail
= 0

}

if (test-path
“i:\$folder\ping_Failure.txt”)

{

$pingfail
= 1

$pingnoemail
= 1

$pingfile
=
Get-ChildItem
“i:\$folder”
|
where{$_.name
-eq
“ping_failure.txt”}

$pingfiletime
=
$pingfile.lastwritetime

$pingfiletime


if ($pingfiletime
-le
$date.AddHours(-6))

{

echo
“File was created more than 1 minute ago. $pingfiletime”

del
“i:\$folder\ping_failure.txt”

}

}

if (!(test-path
“i:\$folder\ping_Failure.txt”))

{

$pingfail
= 0

$pingnoemail
= 0

}

if (test-path
“i:\$folder\agent_Failure.txt”)

{

$agentfail
= 1

}

if (!(test-path
“i:\$folder\agent_Failure.txt”))

{

$agentfail
= 0

}

Ping_Interface


}

if ($ping
-eq
“N”)

{


echo
“$sqlserver - is not being pinged at this time. Check SQLTAB” >> i:\OUT\ping_with_service_check.txt

echo
“############################” >> “i:\OUT\ping_with_service_check.txt”

}

}

Ok so you can see from looking at the script that this is where the script starts even though, you will see when you see the entire script, that this is the end of the script. That is because in Powershell you must define all functions before the script begins.

As you can see I start out by setting some things upand clearing out my log file. You could just keep appending to the file but I chose not to. You can also see that I set up a variable called $servers. This is populated by a .csv file that I have that has all the information about my SQL Servers that I am going to need for this script and for my other monitoring script. The heading of that file is as follows.

Monitor,Server,Instance,TorP,ErrorLog,Ping,OS2000

This way I know if I want to monitor the server, I may choose not to if it is out of commission for a while, I know the hostname, instance name, if it is Test or Production, if I want to run this Ping Servers Script on it and if it is running Windows Server 2000 as I can not run powershell locally on those servers.

Now that I have that variable populated I can start my loop. I start setting up each individual variable that I am going to need later on. Now I start looking for some touch files called wmi_failure.txt and ping_failure.txt. These are so I will know if either a wmi call or a physical interface ping failed on the last run of the script. On both of these I do not want to send out notification every 10 minutes but for wmi failures just once a day and for interface failures once every 6 hours. Now you may be asking why only every 6 hours if a servers interface is down since that means the server is basically useless. I would agree with you, but remember I wanted to notify our Windows Team about this issue and this was there call. No pages and only email us once every 6 hours about the issue. I was shocked at this response. Anyway, I look at the file if it is there and then I check how old it is based on the current time of the script running. If it has been passed the allotted amount of time then I remove that file and set the failure variables to 0 so the script will know to send out notifications about the failures should they still occur. Once I set all that up I can call my firs function if this script should be run against the server. That is noted by $ping being equal to Y or N. Next time I will show you my Ping_Interface function.

If you have any questions or comments about this script please let me know at http://sysadminsmith.com and click the ‘Submit a Question’ link to the right.


Apr 23 2009   9:31PM GMT

DTS Migration to SQL Server 2008 SSIS



Posted by: Colin Smith
SQL Server, DBA, Database Administration, Installation

Today I had a developer ask about moving old DTS packages into SQL Server 2008 SSIS. This is our first real test SQL Server 2008 instance and we had never done this. He was attempting to use the Package Migration Wizard to move the package into SSIS. We installed the BI Visual Studio Components and also the Backward Compatibility Components during the SQL Server 2008 installation. We verified all this and asked if he could try again. He did and sent us the same error. I found the following article that explains how to resolve the issue.

http://msdn.microsoft.com/en-us/library/ms143755.aspx

Apparently, in MS’s infinite wisdom, the decided that you will also need to install the following.

SQLServer2005_BC*.msi

This on the install media you just need to dig down and find it. Once we installed this everything was fine and the developer was able to move the DTS package over using the Wizard. Not sure why they make us do an additional install that is not available during the install of the product.


Apr 23 2009   2:25AM GMT

Oracle Upgrade Complete



Posted by: Colin Smith
Oracle, Upgrade, DBA, Database Administration

I was able to finish up the Oracle Upgrade that I wanted to do today. First I removed the previous installation of Oracle 10 on the server. I then installed the software and all patches that I needed. I then changed my variables to reflect the new Oracle Home Directory that I wanted to use. After that I launched the dbua and walked thru each step, I did not move the files during the upgrade so it was an in place upgrade. I did have a good backup that I could fail back to if needed. This is very important. After a couple hours the upgrade had finished. I still had to copy over the tns folder and change the listener.ora file also to reflect the new Oracle Home. I also needed to change some parameters in the spfile.ora. The application that uses this DB has provided a tool to edit the spfile directly. I edited the file and I started the DB with no issue. This took me just under 4 hours and that was my target time. I think that I am ready to upgrade our production servers and feel confidant that I will not have any issues that I can not overcome.


Apr 22 2009   3:34PM GMT

Oracle Upgrade Testing Once Again



Posted by: Colin Smith
Oracle, Upgrade, DBA, Database Administration

Today I will again embark on the journey that is Upgrading Oracle. This will be the third and final time that I do this on our test system in preparation to upgrade our Production Cluster that also has a DataGaurd Backup solution. I expect this process to take a about 4 hours including the removal of the current Oracle 10 software that I have installed on the server. I am running through this from the very beginning and expect to hit no road bumps this time around. If all does go well this time then I will start to plan how I am going to handle the production environment and how much downtime I am going to require. I will require downtime since we are doing an in place upgrade. It would be nice to have enough disk to install 10 on one Cluster node and upgrade the Database files while moving them to a new disk location and then failing over the cluster once that is complete. I, however, will have to upgrade the files in place and use only the DR server as a backup. That should not be a problem though. I think I will upgrade one node bring the DB up and then install Oracle on the second node. Once that is complete the Cluster should be done. Then in a day I will upgrade the DataGaurd server as well and re-enable the replication.


Apr 21 2009   9:06PM GMT

SQL Server Education



Posted by: Colin Smith
SQL, SQL Server, DBA, Database Administration, Education

In an earlier post I said that I was about to start reading some books from the advanced Sybase Training course. I have changed course since then and I have decided to move on with some SQL Server education instead. I have decided that I would like to get my MCITP: Database Administrator certificate. I have never really felt like certificates were very meaningful while I was doing workstation and Windows administration. I have changed my views of certificates when it comes to the Database world. I have decided to tackle SQL Server first for a couple of reasons.

  1. It is a MS Product and has a nice GUI. I come from a Windows Administration background and feel that this is the logical course.
  2. My company has roughly 50 production SQL servers that we really do not do much with. I have written a Powershell script to monitor the SQL Servers for errors but we need to do more.

I have already started my journey and have finished reading my first MS SQL Server book. I read Beginning SQL Server 2005 Administration by Wrox publishing. I enjoyed the book and I ordered the next in the series called Professional SQL Server 2005 Administration. I like the way the books are laid out and have hands on examples that you can try if you have installed the AdventureWorks Database.

I have also ordered the study material for the three tests that I will have to take in order to get the certification. I am hoping to get these books in the mail in the next day or two. I would like to try to take one test a month and have my certification in about three months. I am looking forward to doing more in SQL Server and have learned a lot just from the first book. I will continue to keep you updated on this and hopefully you can learn along with me.

If you have any questions please head over to http://sysadminsmith.com and click the submit a question link to the right.