Oracle-如何獲得數據庫的DBID
2024-08-29 13:49:58
供稿:網友
在進行數據庫恢復的過程中,很多時候我們需要知道Oracle數據庫的DBID,通常有以下幾種方法可以獲得數據庫的DBID.1.查詢v$database獲得由于DBID在控制文件和數據文件中都存在記錄,所以假如能夠mount數據庫就可以查詢v$database視圖獲得. SQL> alter database mount;Database altered.SQL> select dbid from v$database; DBID----------3152029224SQL> 2.在nomount狀態時假如數據庫配置了自動控制文件備份(Oracle9i),并且名稱是缺省的,那么我們可以從自動備份文件獲得DBID.[oracle@jumper dbs]$ cd $ORACLE_HOME/dbs
[oracle@jumper dbs]$ ll c-*
-rw-r----- 1 oracle dba 3375104 Dec 21 11:13 c-3152029224-20051221-00
-rw-r----- 1 oracle dba 3358720 Jan 21 14:03 c-3152029224-20060121-00
-rw-r----- 1 oracle dba 3358720 Jan 21 14:08 c-3152029224-20060121-01這里的3152029224就是DBID.3.從自動備份中恢復需要或缺DBID進行恢復通常是因為丟失了所有的控制文件.在恢復時會碰到錯誤.[oracle@jumper dbs]$ rman target /Recovery Manager: Release 9.2.0.4.0 - PRodUCtionCopyright (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-06using target database controlfile instead of recovery catalogallocated channel: ORA_DISK_1channel ORA_DISK_1: sid=11 devtype=DISKRMAN-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 假如存在自動備份,我們通常可以直接恢復控制文件,mount數據庫之后就好辦了: RMAN> restore controlfile from '/opt/oracle/product/9.2.0/dbs/c-3152029224-20051221-00';Starting restore at 05-FEB-06using channel ORA_DISK_1channel ORA_DISK_1: restoring controlfilechannel ORA_DISK_1: restore completereplicating controlfileinput filename=/opt/oracle/oradata/conner/control01.ctloutput filename=/opt/oracle/oradata/conner/control02.ctloutput filename=/opt/oracle/oradata/conner/control03.ctlFinished restore at 05-FEB-06 4.直接從幸存的文件中讀取由于DBID存在于數據文件及控制文件中,所以我們可以通過PL/SQL程序直接從文件中讀取: SQL> select eygle.get_dbid('/opt/oracle/oradata/conner','user02.dbf') from dual;
EYGLE.GET_DBID('/OPT/ORACLE/OR
------------------------------
3152029224SQL> select dbid from v$database;DBID
----------
3152029224 這種方法僅為測試愛好所致,不被推薦.