oracle中如何获得数据库的DBID信息
1.查询v$database获得
由于dbid在控制文件和数据文件中都存在记录,所以如果能够mount数据库就可以查询v$database视图获得.
sql> alter database mount;
database altered.
sql> select dbid from v$database;
dbid
----------
3152029224
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。在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-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
其实更简单的,用bbed就好了。
这种方法仅为测试兴趣所致,不被推荐.
上一篇: Oracle中创建和管理表详解