Wednesday, November 3, 2010

How to write DBID to alert long on a regular basis? --Moid

Every Oracle database has an internal unique DBID that can be queried from V$DATABASE
as follows:

SQL> select dbid from v$database;DBID------------------------------1794272723

RMAN uses the DBID to uniquely identify databases. The DBID helps RMAN identify the
correct RMAN backup piece from which to restore the control file. If you don’t use a flash
recovery area or a recovery catalog, then you should record the DBID in a safe location and
have it available in the event you need to restore your control file.


Writing the DBID to the Alert.log File

Another way of recording the DBID is to make sure that it is written to the alert.log file on a
regular basis using the DBMS_SYSTEM package. For example, you could have this SQL code execute as part of your backup job

COL dbid NEW_VALUE hold_dbidSELECT dbid FROM v$database;exec dbms_system.ksdwrt(2,'DBID: '||TO_CHAR(&hold_dbid));

After running the previous code, you should see a text message in your target database
alert.log file that looks like this:

==> alert_PrimeDG.log <==Wed Nov  3 03:06:47 2010DBID: 1794272723
You can easily put this in a cron job to write on a daily or weekly basis.Extracting of DBID from Redo Log fileAnother way of getting DBID is possible by getting the dump of the any availabe datafile, redolog or archvied log. I chosed to take a dumpfile of the online redolog and following are the steps I have taken.
SQL> ALTER SESSION SET sql_trace = true;Session altered.SQL> ALTER SESSION SET tracefile_identifier=Moid_Logfile_dump;Session altered.SQL> alter system dump logfile '/u15/oradata/Prime/redo01a.rdo';System altered.
At this point, I changed my directory to the user dump destination and dumpfile is available to be skinned.
Linux-223:(PrimeDG)$ pwd/u01/app/oracle/admin/PrimeDG/udumpLinux-223:(PrimeDG)$ ls -ltrhtotal 203M-rw-r-----  1 oracle oinstall  948 Nov  3 03:39 primedg_rfs_8676.trc-rw-r-----  1 oracle oinstall  947 Nov  3 03:44 primedg_rfs_8809.trc-rw-r-----  1 oracle oinstall 135M Nov  3 03:49 primedg_ora_8712.trc-rw-r-----  1 oracle oinstall  947 Nov  3 03:49 primedg_rfs_8979.trc-rw-r-----  1 oracle oinstall  68M Nov  3 03:49 primedg_ora_8712_MOID_LOGFILE_DUMP.trc
A simple cat of the file, provided me what I was looking for, DBID of my database.
Linux-223:(PrimeDG)$ cat primedg_ora_8712_MOID_LOGFILE_DUMP.trc |grep "Db ID"        Db ID=1794272723=0x6af26dd3, Db Name='PRIME'
--Moid
The above instructions can also be found here. 

Sunday, October 31, 2010

How to add a number to null in Oracle?

select ename, sal, comm, sal+COALESCE(comm,0) as total_compensation from emp;

Click here for the screenshot.

--Moid

Saturday, September 25, 2010

MIITDocID-904: How to check the root blocker (blocking session) and kill it?

Document can be found here.

--Moid

How to display the output of the query vertically?

Create a procedure called Print_Table as sys

It uses authid_current user so you can install it ONCE per database and many people can use it (with roles and all intact):

Procedure and display instructions are here.


Reference: http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:1035431863958
Google Key words: "Tom Kyte Print_Table"

--Moid

How to check the total “Used” and “Free” database space?

Here is a script to check the total "Used" and "Free" space in a database.

--Moid

Thursday, September 23, 2010

How to subscribe to free monthly edition of Oracle Magazine? --Moid

To subscribe Oracle Magazine, go here and select "Oracle Magazine" and follow the instructions. Or you can go directly to the subscription page by clicking here.

--Moid

Monday, September 20, 2010

Find the last recovery time/date of the Oracle database when "resetlogs" option was used to open the database (or when incarnation took place)?

Hi,

Have you ever been asked when was the database restored/reopened (with resetlog options)? It is a simple thing but sometimes a time consuming task especially if you are not very familiar with Oracle DBA dictionary or if you are a Jr. DBAs. Well, the answer can be found here. Hope this comes handy to someone in need.

--Moid


Keywords:

Last recovery date
Last restore date
Last recovery time
last restore time

Sunday, September 19, 2010

Friday, September 10, 2010

How to get the client's machine name and their IP Address in Oracle 10g?

Salam,

I was recently asked to spool out the client’s machine, their IP addresses and the service_name they are using to connect to RAC DB into a text file. I came up with the following queryand it worked like a charm. Although I tested it on a non-RAC db server, I have no doubt it will work on any RAC cluster.

--Moid

Tuesday, July 13, 2010

Tuesday, July 6, 2010

Linux script to take a daily Oracle export of a schema --Moid

I was recently asked to schedule a daily export of a schema. Although it is a simple task, I think it might help someone out there some day.

Click here for the link.

--Moid Muhammad

Followers