Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2771184
  • 博文数量: 389
  • 博客积分: 4177
  • 博客等级: 上校
  • 技术积分: 4773
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-16 23:29
文章分类

全部博文(389)

分类: Oracle

2014-04-20 21:22:57


                            获取DBID的几种方法

    在使用RMAN的时候,dbid极为重要,dbid唯一的标识了一个数据库。在12C的CDB架构
中每个pdb都有自己的pdb。可以通过以下几种方法来查询数据库的pdb


1,查询v$database中的dbid或是12C的v$containers

SQL> select dbid from v$database;

      DBID
----------
 461042625


SQL> select name,dbid from v$pdbs;

NAME                                 DBID
------------------------------ ----------
PDB$SEED                       4062019834
PDBNEW3                        3955412277
PDB2                           3885634569


SQL> select name,dbid from v$containers;

NAME                                 DBID
------------------------------ ----------
CDB$ROOT                        461042625
PDB$SEED                       4062019834
PDBNEW3                        3955412277
PDB2                           3885634569

2,通过RMAN的输出来得到当前的dbid或nid

[oracle@o12c ~]$ $ORACLE_HOME/bin/rman target / nocatalog

Recovery Manager: Release 12.1.0.1.0 - Production on Wed Mar 12 02:16:24 2014

Copyright (c) 1982, 2013, Oracle and/or its affiliates.  All rights reserved.

connected to target database: C12 (DBID=461042625)

......................................


[oracle@o12c ~]$ nid target=c12 sys/sys

DBNEWID: Release 12.1.0.1.0 - Production on Wed Mar 12 02:27:14 2014

Copyright (c) 1982, 2013, Oracle and/or its affiliates.  All rights reserved.

Connected to database C12 (DBID=461042625)

NID-00121: Database should not be open
.........................................

 

3,通过controlfile autobackup生成的文件名.当rman配置成controlfile autobackup on
且没有定义FRA时,RMAN会自动备份控制文件到$ORACLE_HOME/dbs目录下,其中的文件名就包含
了dbid信息

RMAN> show controlfile autobackup;

RMAN configuration parameters for database with db_unique_name C12 are:
CONFIGURE CONTROLFILE AUTOBACKUP ON; # default

SQL> alter system set db_recovery_file_dest='';

System altered.

SQL> show parameter db_recovery_file_dest;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest                string
db_recovery_file_dest_size           big integer 10G

 

RMAN> backup tablespace users;

......................
Starting Control File and SPFILE Autobackup at 12-MAR-14
piece handle=/u01/app/oracle/product/12.1.0/db_1/dbs/c-461042625-20140312-03 comment=NONE
Finished Control File and SPFILE Autobackup at 12-MAR-14.

.........................

c-461042625-20140312-03 文件中的461042625为数据库的dbid信息.


4,前三种方法都是在正常的情况下情况得到的,对于很多时候我们可能并没有记录dbid信息,这时候
只有数据文件或是控制文件就可以了,然后通过dump文件来得到


SQL> startup nomount;
ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size                  2293880 bytes
Variable Size             322965384 bytes
Database Buffers          503316480 bytes
Redo Buffers                6529024 bytes

SQL> alter system dump datafile '/u01/app/oracle/oradata/c12/sysaux01.dbf' block 1;

System altered.

SQL>  oradebug setmypid;
Statement processed.
SQL>  oradebug tracefile_name;
/u01/app/oracle/diag/rdbms/c12/c12/trace/c12_ora_5435.trc

数据件头信息
Start dump data block from file /u01/app/oracle/oradata/c12/sysaux01.dbf minblk 1 maxblk 1
 V10 STYLE FILE HEADER:
        Compatibility Vsn = 202375168=0xc100000
        Db ID=461042625=0x1b7af3c1, Db Name='C12'
        Activation ID=0=0x0
        Control Seq=34457=0x8699, File size=192000=0x2ee00
        File Number=3, Blksiz=8192, File Type=3 DATA
Dump all the blocks in range:

 Db ID=461042625=0x1b7af3c1为该数据库的dbid信息

 


SQL> alter session set events 'immediate trace name controlf level 4';

Session altered...

....................

PLUGGABLE DATABASE RECORDS
***************************************************************************
 (size = 684, compat size = 684, section max = 10, section in-use = 5,
  last-recid= 16, old-recno = 0, last-recno = 0)
 (extent = 1, blkno = 550, numrecs = 10)
Pluggable DataBase record=1
  id=1
  dbid=461042625
  name=CDB$ROOT
  first datafile link=1
 ............................
Pluggable DataBase record=3
  id=3
  dbid=3955412277
  name=PDBNEW3
  first datafile link=40
..............................

通过dump controlfile得到的信息最为详尽,其中包括了所有的pdb的dbid信息.

阅读(3268) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~