About Me - Who is DR DBA?

Hello. My name is Rudy Panigas and I am a Production Senior Microsoft SQL Server Database Administrator (DBA) with over 14 years of experience. Have published articles with SQL Central, am a leader for the my local PASS chapter in Toronto (TORPASS) and love to automate anything SQL including disaster recovery. I created this blog to share my views, knowledge and to discuss Microsoft SQL server in order to help out others in this field. Please test these scripts before using. I do not warranty and do not take any responsibility for it, its misuse or output it creates. You can reach me at this email address: sqlsurgeon@outlook.com

Wednesday, August 24, 2011

Using SQL Server to collect information from your Oracle server




How many DBA's out there have to manage Microsoft SQL Server instances and Oracle database
servers? More than you think, and I am one of them. Just over a year ago one of our departments
wanted to purchase a very expensive product that only runs on an Oracle database.

When the software was purchased; 2 Oracle DBAs were also hired. Then it started, and we were
all asked to cross train each other on the two database systems.
On the SQL Server side I had created several reports to provide information on all our SQL Servers
via a linked server connection. I decided to do the same and collect basically the same
information from the Oracle servers. Here is a list of data I wanted to collect from Oracle.
  • Job Status Data
  • Current Error Information
  • Database ONLINE Status
  • Patch Data
  • Patch Set Data
To perform this task I first had to install the Oracle client (in this case it was for Oracle 10g)
on the SQL server that will create the linked connection to the Oracle server. Without the
client installed the link server parameter '@provider=' would not work as the Microsoft
provided Oracle driver does not work properly. Even Microsoft recommends using the
Oracle client. So make sure you install the Oracle client. If you are using a 64bit server just
install the 32bit client as the 64 bit client may cause issues. I never did find out why this is
the case. Once installed you can open up the SQL Server Management Studio (SSMS) and
create a link connection from your SQL server to your Oracle server. This link can be
created by the GUI (see Books On Line) or with the script below.

Note: You must replace 'ORACLESRV1' with the name of your Oracle server. Also you need
to change the user name 'REPORTS_USER' and provide its password 'PASSWORD'.
Once complete you can execute this code. The user and password are the credentials you have
created on the Oracle server. You can download the script here: https://docs.google.com/file/d/0B07PMQYOhF2DWmVIOVducTc1Yjg/edit?usp=sharing

Ensure that the login has the rights to the VIEWs on SYSMAN.MGMT$*
 
PRINT 'Creating Oracle link connection...'PRINT ' 'EXEC master.dbo.sp_addlinkedserver 
@server = N'ORACLESRV1', 
@srvproduct=N'Oracle', 
@provider=N'OraOLEDB.Oracle', 
@datasrc=N'ORACLESP'EXEC master.dbo.sp_addlinkedsrvlogin 
@rmtsrvname=N'ORACLESRV1',
@useself=N'False',
@locallogin=NULL,
@rmtuser=N'REPORTS_USER',
@rmtpassword='PASSWORD'
EXEC master.dbo.sp_serveroption 
@server=N'ORACLESRV1', 
@optname=N'collation compatible', 
@optvalue=N'true'EXEC master.dbo.sp_serveroption 
@server=N'ORACLESRV1', 
@optname=N'data access', 
@optvalue=N'true'EXEC master.dbo.sp_serveroption 
@server=N'ORACLESRV1', 
@optname=N'use remote collation', 
@optvalue=N'true'

Now that you have created a linked connection to the Oracle server you can test this connection
with the following script. It performs a SELECT against a system view on the Oracle server.
 
SELECT
 [JOB_NAME], [JOB_OWNER], [JOB_TYPE], [SCHEDULED_TIME],
 [START_TIME], [END_TIME], [STATUS], [TARGET_NAME],
 [TARGET_TYPE]
 FROM ORACLESRV1..[SYSMAN].[MGMT$JOB_EXECUTION_HISTORY]

The information displayed is the execution history for jobs on your Oracle server. Neat!
By querying other system views you can get a lot of information that is also displayed in the
Oracle Enterprise Manager Web interface.

Now that your tests are good you should delete the linked connection with the script below.
 
IF EXISTS (SELECT srv.name FROM sys.servers srv WHERE srv.server_id != 0 
AND srv.name = N'ORACLESRV1')EXEC master.dbo.sp_dropserver 
@server=N'ORACLESRV1',@droplogins='droplogins'

This code will detect if the linked connection is there and delete it.

There you have it. You can now see and collect information regarding your Oracle server without using any Oracle tools. You can now collect the related information and display it in SQL Server Report Server (SSRS). The script provided will perform the following:
  1. Creates a database called: ORACLEREPORTS
  2. Creates permanent tables: tblOracleJobStats - Job statistics, tblOracleCurrErrors - Shows errors, tblOracleOnlinStatus - Show if databases are online, tblOraclePatches and tblOraclePatchSets - Show level of patches installed
  3. Creates a stored procedure called: sp_dba_Oracle_Status - This stored procedure will create a new link connection to your Oracle server, perform a TRUNCATE on your tables and then repopulated with several SELECT statements. You can add this stored procedure to a job to collect your data whenever you like. I run this on an hourly basis.
Once the script has executed you can just run the stored procedure to collect your information.
Also you can create simple reports in SSRS to display the data. The completed SQL script is
located in the Resources section below with additional notes within it.

Thanks,
Rudy

Tuesday, August 2, 2011

Query your Active Directory from with SQL server

Here is a script I wrote to query active directory. Because I needed to get some information on users that had a login in SQL server using Windows Authentication.

Remember to change the script so that your domain name used.

Thanks,

Rudy

Download script here: https://docs.google.com/file/d/0B07PMQYOhF2Dd0I0S3hmOHpXbzg/edit?usp=sharing