eygle.com   eygle.com
eygle.com  
 

« 一生的忠告 | Blog首页 | Expert Oracle-版权,还是版权 »

Oracle HowTo:如何获得数据库的DBID

作者:eygle |【转载时请以超链接形式标明文章和作者信息及本声明
链接:

在进行数据库恢复的过程中,很多时候我们需要知道Oracle数据库的DBID,通常有以下几种方法可以获得数据库的DBID.

1.查询v$database获得

由于DBID在控制文件和数据文件中都存在记录,所以如果能够mount数据库就可以查询v$database视图获得. 

SQL> alter database mount;
Database altered.
SQL> select dbid from v$database;
      DBID
----------
3152029224
SQL>  

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 - 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-3152029224-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
------------------------------
3152029224
SQL> select dbid from v$database;
DBID
----------
3152029224
 

这种方法仅为测试兴趣所致,不被推荐.

相关文章参考:

使用Oracle9i的自动控制文件备份功能

使用RMAN的备份及恢复一例-丢失所有控制文件

 


历史上的今天...
      >> 2009-02-05文章:
      >> 2008-02-05文章:
             祝福大家新年好 2008梦想成真
      >> 2007-02-05文章:
      >> 2005-02-05文章:
             华友世纪成功登陆纳斯达克
------
这篇 【Oracle HowTo:如何获得数据库的DBID】来自 eygle.com | CSDN网摘| del.icio.us|Google订阅 | 鲜果订阅 | 抓虾订阅

By eygle on 2006-02-05 22:43 | Comments (2) | Posted to HowTo | Edit |

相关文章 随机文章
  • 20090811-墨墨、书书、Oracle
  • Oracle收购GoldenGate - 甲骨文到底想做什么
  • Oracle 74亿美元购SUN - 彻底改变产业格局
  • TimesTen:Cache Group局部数据缓存及Aging
  • TimesTen 7.0.5 For Linx安装过程记录
  • DBA警世录:更新系统表(props$)修改字符集
    雅虎中国Oracle DBA职位虚席以待
    Oracle10.2.0.3 RAC的VIP及实例依赖关系
    Oracle10gR2中的Mutex竞争的案例
    珍爱这一天 - 祝朋友们圣诞快乐
    搜索本站:

    留言 (2)

    SQL> select eygle.get_dbid('/orahome/oracle/oradata/jyc','abc.dbf') from dual;
    select eygle.get_dbid('/orahome/oracle/oradata/jyc','abc.dbf') from dual
    *
    ERROR at line 1:
    ORA-00904: "EYGLE"."GET_DBID": invalid identifier
    您这个eygle.get_dbid 内容是什么啊?

    Posted by: jyc at August 17, 2007 1:04 PM

    还有一个方法:如果存在catalog的话,可以用rman用户登陆catalog库查询db表。 :)

    Posted by: yghzjj at October 22, 2008 10:05 AM

    发表留言:



    Remember Me?
    (输入验证码后方可评论,谢谢支持)



    CopyRight © 2004~2010 eygle.com, All rights reserved.