How to obtain Oracle dbid

Source: Internet
Author: User
Tags naming convention

1. Query V$database get


Since Dbid has records in both the control file and the data file, the V$database view can be queried if the Mount database is available.



Sql> ALTER DATABASE Mount;


Database altered.


Sql> select dbid from V$database;


DBID
----------
1363251591






2. In the Nomount state


If the database is configured with automatic file backup (oracle9i) and the name is the default, then we can get dbid from the automatic backup file.




[Email protected] dbs]$ CD $ORACLE _home/dbs
[email protected] dbs]$ ll c-*
-RW-R-----1 Oracle DBA 3375104 DEC 11:13 C1363251591-20051221-00
-RW-R-----1 Oracle DBA 3358720 Jan 14:03 C1363251591-20060121-00
-RW-R-----1 Oracle DBA 3358720 Jan 14:08 C1363251591-20060121-01




Here's1363251591is dbid. In 10g, using the Flash Recovery area, there is no such naming convention.


3. Recovering from automated backups


The need or lack of dbid for recovery is usually due to the loss of all control files. Errors are encountered when recovering.




[[email protected] dbs]$ Rman target/


Recovery Manager:release 9.2.0.4.0-production


Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.


Connected to target Database:conner (not mounted)


rman> restore controlfile from Autobackup;


Starting restore at 05-feb-06


Using target database Controlfile instead of recovery catalog
Allocated Channel:ora_disk_1
Channel ora_disk_1:sid=11 Devtype=disk
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE, STACK follows ===============
RMAN-00571: ===========================================================
Rman-03002:failure of Restore command at 02/05/2006 20:47:25
Rman-06495:must explicitly specify DBID with SET DBID command




If there is an automatic backup, we can usually restore the control file directly, and then the Mount database is ready:




rman> restore Controlfile from '/opt/oracle/product/9.2.0/dbs/c-1363251591-20051221-00 ';


Starting restore at 05-feb-06


Using channel Ora_disk_1
Channel Ora_disk_1:restoring Controlfile
Channel Ora_disk_1:restore Complete
Replicating Controlfile
Input Filename=/opt/oracle/oradata/conner/control01.ctl
Output Filename=/opt/oracle/oradata/conner/control02.ctl
Output Filename=/opt/oracle/oradata/conner/control03.ctl
Finished restore at 05-feb-06





4. Read directly from the surviving file


Since dbid exists in data files and control files, we can read them directly from the file via the PL/SQL program:




Sql> Select Eygle.get_dbid ('/opt/oracle/oradata/conner ', ' user02.dbf ') from dual;


Eygle. Get_dbid ('/opt/oracle/or
------------------------------
1363251591


Sql> select dbid from V$database;


DBID
----------
1363251591


In fact, even more simple, with bbed on the good.


This method is only for testing interest and is not recommended.
-- This is a eygle custom function (I'll make up the time)




5. Get dbid via dump data file:
[Email protected]> alter system dump datafile ' D:\APP\ADMINISTRATOR\ORADATA\ORCL\USERS01. DBF ' Block 1000;


The system has changed.


[Email protected]> Select tracefile from v$process where addr in (select Paddr from v$session where SID in (select SID from V$mystat));


--View trace file: Db id=1363251591
Tracefile
------------------------------------------------------------------------------
D:\app\administrator\diag\rdbms\orcl\orcl\trace\orcl_ora_6740.trc


Start dump data block from file D:\APP\ADMINISTRATOR\ORADATA\ORCL\USERS01. DBF minblk 0 maxblk-1
V10 STYLE FILE HEADER:
Compatibility Vsn = 186646528=0xb200000
Db id=1363251591=0x51419187, Db name= ' ORCL '
Activation id=0=0x0
Control seq=10579=0x2953, File size=1600=0x640
File number=4, blksiz=8192, file type=3 DATA

Dump all the blocks in range:

...





-------------------------------

Dylan presents.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.