Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Using SQL Server to collect information from your Oracle server

By Rudy Panigas,

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. 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

 

 

Resources:

Oracle Data Collection.sql
Total article views: 3358 | Views in the last 30 days: 5
 
Related Articles
FORUM

Linked Server connecting to Oracle problem

Unable to connect to oracle linked server

FORUM

Oracle 64bit Connectivity

Difficulty using a linked server connection from SQL Server 2008 64bit to Oracle.

FORUM

SSIS 2008 and Oracle database connectivity Issue in a 64 bit machine

SSIS2008<->Oracle Connectivity Issue

FORUM

Creating DB link b/w Oracle and SQL server

Creating DB link b/w Oracle and SQL server

FORUM

SQL Server And Oracle

SQL Server And Oracle

Tags
monitoring    
oracle    
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones