The Multifunctioning DBA:

DBA

Sep 23 2009   4:52PM GMT

Oracle Dataguard Replication Scare



Posted by: Colin Smith
Oracle, Dataguard, Standby Database, DBA, Oracle Administration, DR

I had to bring down the standby server for the power outage in our DR location a few nights agon. No big deal, shut off replication from the primary, go to the standby and do a shutdown imediate, since you can not do a shutdown on the standby server. When things cam up I go to the secondary and do a startup nomount; and then alter database mount standby database; Well I thougt that was all I needed. About 10 minutes later I get some pages about the primary not being able to connect to the standby… DUH I forgot to start the listener on the standby. No Problem. I run lsnrctl start on the standby host and I am in business now. No more pages all is good. Well I thought so until after the cold backup that we run overnight from the standby database. Now I get a page saying that recover managed standby database cancel can not execute since this is not a managed standby database. I think that is odd and I check to see if archive logs are being applied and they are not and have not been for over 13 huors now. I find that I forgot to run alter database recover managed standby database; I run that command and look at that. Now my Archive logs are being applied. It took about 4 hours to get caught up but it did. So when bringing up the standby just do the following:

STARTUP NOMOUNT;

ALTER DATABASE MOUNT STANDBY DATABASE;

ALTER DATABASE RECOVER MANGED STANDBY DATABASE;

If you have enabled the primary to send archive logs then you are all set.

Jul 30 2009   3:17PM GMT

Add a AD Group to MSSQL Server and add to a role using Powershell



Posted by: Colin Smith
SQL Server, Powershell, DBA, Database Administration, Groups, Roles

In SQL Server 2005 the Builtin Administrators group is a login, by default, to your MSSQL Server Instance and is also a member of the sysadmin role. Well this has been changed in SQL Server 2008 with good reason. I decided that I would like to add a group for my DBA Group to every SQL Server in the company and also add this group to the sysadmin role. This way I do not need to have the builtin administrators group be a member of the sysadmin group or even a login to the server. Here is how I did it.

$servers = Import-Csv “csv listing of all servers”
#########################################################
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()
#########################################################

[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

$logins = $s.Logins
$query = “CREATE LOGIN $sqladmin FROM WINDOWS WITH DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english]“
$dba = $logins | where{$_.Name -eq $sqladmin}
#$dba
if ($dba -eq $null)
{
Echo “DBA Group does not exist.`n Adding Group”
Invoke-Sqlcmd -ServerInstance $instance -Query $query
$logins = $s.Logins
$dba = $logins | where{$_.Name -eq $sqladmin}
if ($dba -ne $null)
{
Echo “`n Group Created”
$dba.name
}
}
else
{
Echo “Group already exists.”
$dba.name
}
if ($dba -ne $null)
{
$sroles = $s.Roles
foreach ($srole in $sroles | where{$_.name -eq “sysadmin”})
    {
    $srole.AddMember($sqladmin)

}

This script walks through the list of all my instances and adds the login using sqlcmd and then also adds that new group to the sysadmin role. Let me know if you have any questions or need anything at all.

 


Jul 24 2009   3:47PM GMT

Another New Language



Posted by: Colin Smith
Monitoring, DBA, Database Administration, Education, Perl, Scripting

My team is going to be developing a new application that will handle all of our monitoring. Currently that includes the monitoring of Sybase Servers, Oracle Instances, and MSSQL Servers. We will also be adding another Database Type that will house all of the Monitoring data. We will be using a MYSQL backend for this application. This application will be developed to run on a unix host so I need to be able to connect to my MSSQL servers from the unix host and insert rows of data back into the MYSQL database. To do this I think that we have decided on Perl for the language of choice. So I now get to go learn Perl. I am excited to learn another language as I am of the befleif that the more tools I have in my box the better off I will be. I will be starting my educational journey of Perl at

 http://www.perl.com/pub/a/2000/10/begper…

I am looking forward to this project and I will keep you up to date on the progress and features.


Jul 17 2009   3:59PM GMT

Update sysindexes table in Sybase 12.5.4



Posted by: Colin Smith
DBA, Sybase, Database Administration, Update System Tables

I am moving a Sybase instance from one host to another. I have done all the installation and patching and I have loaded all the databases with little to no issues. I ran into a big issue when attempting to change to indexes in sysservers to allow duplicate rows. I had to go and find out what the binary value for the setting that I wanted was and then find out what column held that value. I determined, from looking at my current instance, that I needed the Status colunm to be changed to 64. I then verified this by looking here at the definitions for the table.

 http://infocenter.sybase.com/help/index….

I attempted droping the indexes so that I could just recreate them but you are not able to use Drop Index when working with system tables. That is when I decided to find the value and the column to update. So then I ran a query:

Select name, status from sysindexes

where name = ‘csysservers’

and status = 146

go

This returned on row for me and I thought now I can run the update

update sysindexes

set status = 40

where name = ‘csysservers’

and status = 146

go

Now I get the following error:

Cannot update more than 1 sysindexes row at a time.

Well this did not make sense at all. When I run the select I only get one row returned. But I took the advice of the error and modified my where clause to include more columns and then I was able to make the updates that I needed.


Jul 17 2009   2:56PM GMT

MR. Denny has a webcast



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

I just saw this and I am looking forward to attending. MR. Denny is a great SQL Resource and I am sure that I will learn new things during this webcast. Here is a link to his blog entry about the webcast.

 http://itknowledgeexchange.techtarget.co…

I suggest you check it out and learn something new from a knowledgable SQL Server DBA.


May 29 2009   10:01PM GMT

Oracle Upgrade Final Test this weekend



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

The Oracle 9 to 10GR2 upgrade that I completed last week will be getting its final test on Sunday. We will be failing over to our standby server and see what happens. I am not worried about this as all the files that are associated with the upgrade are on disk that is shared between the two cluster nodes. The only exception is in /var/opt/oracle and I have modified those files to be what they need to be. Keep your fingers crossed for me but I think I am in good shape.


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.