如何擷取oracle dbid,擷取oracledbid

來源:互聯網
上載者:User

如何擷取oracle dbid,擷取oracledbid
1.查詢v$database獲得


由於DBID在控制檔案和資料檔案中都存在記錄,所以如果能夠mount資料庫就可以查詢v$database視圖獲得. 



SQL> alter database mount;


Database altered.


SQL> select dbid from v$database;


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






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-1363251591-20051221-00
-rw-r----- 1 oracle dba 3358720 Jan 21 14:03 c-1363251591-20060121-00
-rw-r----- 1 oracle dba 3358720 Jan 21 14:08 c-1363251591-20060121-01




這裡的1363251591就是DBID。在10g中,使用Flash Recovery Area,則沒有這個命名規則。


3.從自動備份中恢複


需要或缺DBID進行恢複通常是因為丟失了所有的控制檔案.在恢複時會遇到錯誤.




[oracle@jumper 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 




如果存在自動備份,我們通常可以直接恢複控制檔案,mount資料庫之後就好辦了: 




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.直接從倖存的檔案中讀取


由於DBID存在於資料檔案及控制檔案中,所以我們可以通過PL/SQL程式直接從檔案中讀取: 




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


 其實更簡單的,用BBED就好了。


這種方法僅為測試興趣所致,不被推薦.
--此處為eygle自訂的函數  (抽時間我會補上)




5、通過dump資料檔案擷取dbid:
SYS@orcl> alter system dump datafile 'D:\APP\ADMINISTRATOR\ORADATA\ORCL\USERS01.DBF' block 1000;


系統已更改。


SYS@orcl> select tracefile from v$process where addr in (select paddr from v$session where sid in (select sid from v$mystat));


--查看trace檔案: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.




ORACLE丟失控制檔案情況怎獲得DBID?

如果資料檔案都在,可以通過重建控制檔案獲得
 
oracle中怎擷取2010-05-21中的月份

substr('2010-05-21',6,7)
 

相關文章

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.