小记修改DBID(原创)

我们知道在进行备份恢复时,可以通过rman的catalog命令注册备份文件信息,但是 catalog注册同一数据库的备份文件,如果需要注册不同数据库的备份文件,则需要将目标数据库的DBID修改成和源数据库一致。当然实际情况下,有很 多更“安全“的方法可以达到我们想要的目的,这里只是提供一个思路和解决方式,仅供参考

[oracle@dg2 ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Thu Mar 22 16:07:39 2012
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
Connected to an idle instance.

SQL> startup;
ORACLE instance started.

Total System Global Area  222298112 bytes
Fixed Size                  1218628 bytes
Variable Size             100665276 bytes
Database Buffers          117440512 bytes
Redo Buffers                2973696 bytes
Database mounted.
Database opened.
SQL> select dbid from v$database;                   

      DBID
----------
3467808954

SQL> exec dbms_backup_restore.nidbegin('LGDG','LGDG','3467808666','3467808954',0,0,10)
PL/SQL procedure successfully completed.       
注意:第二个TEST1必须大写,两个dbid前面的为修改后的,后面的为修改之前的。

SQL> variable a number;
SQL> variable b number;
SQL> variable c number;
SQL> exec dbms_backup_restore.nidprocessdf(0,0,:a,:b,:c);

PL/SQL procedure successfully completed.

SQL> print :a
         A
----------
         0

SQL> print :b
         B
----------
         1

SQL> print :c
         C
----------
         0

SQL> exec dbms_backup_restore.nidprocesscf(:a,:b);
PL/SQL procedure successfully completed.

SQL> print :a
         A
----------
         1

SQL> print :b
         B
----------
         0

SQL> exec dbms_backup_restore.nidend;
PL/SQL procedure successfully completed.

SQL> select dbid from v$database;
      DBID
----------
3467808666
需要重启数据库,使修改被确认
SQL> shutdown immediate;
ORA-03113: end-of-file on communication channel

SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
[oracle@dg2 ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Thu Mar 22 17:20:30 2012
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
Connected to an idle instance.

SQL> startup;
ORACLE instance started.
Total System Global Area  222298112 bytes
Fixed Size                  1218628 bytes
Variable Size             100665276 bytes
Database Buffers          117440512 bytes
Redo Buffers                2973696 bytes
Database mounted.
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

SQL> recover database using backup controlfile until cancel;
ORA-00279: change 519903 generated at 03/22/2012 17:14:26 needed for thread 1
ORA-00289: suggestion : /u01/archive/1_2_777032519.dbf
ORA-00280: change 519903 for thread 1 is in sequence #2

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
auto
ORA-00308: cannot open archived log '/u01/archive/1_2_777032519.dbf'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3

ORA-00308: cannot open archived log '/u01/archive/1_2_777032519.dbf'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3

ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below
ORA-01194: file 1 needs more recovery to be consistent
ORA-01110: data file 1: '/u01/app/oradata/standby/system01.dbf'

经检查发现,并不存在 /u01/archive/1_2_777032519.dbf 文件,需要强制打开不一致的数据库 ,设置undo_management和_allow_resetlogs_corruption参数即可。大家先看操作


SQL> alter system set undo_management='manual' scope=spfile;
System altered.

SQL> shutdown immediate;
ORA-01109: database not open

Database dismounted.
ORACLE instance shut down.


SQL> startup mount;
ORACLE instance started.
Total System Global Area  222298112 bytes
Fixed Size                  1218628 bytes
Variable Size             100665276 bytes
Database Buffers          117440512 bytes
Redo Buffers                2973696 bytes
Database mounted.
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

SQL> alter database open resetlogs;
alter database open resetlogs
*
ERROR at line 1:
ORA-01194: file 1 needs more recovery to be consistent
ORA-01110: data file 1: '/u01/app/oradata/standby/system01.dbf'

SQL> alter system set "_allow_resetlogs_corruption"=true scope=spfile;

System altered.

SQL> shutdown immediate;
ORA-01109: database not open


Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.

Total System Global Area  222298112 bytes
Fixed Size                  1218628 bytes
Variable Size             100665276 bytes
Database Buffers          117440512 bytes
Redo Buffers                2973696 bytes
Database mounted.
SQL> alter database open resetlogs;
alter database open resetlogs
*
ERROR at line 1:
ORA-01092: ORACLE instance terminated. Disconnection forced

SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options


[oracle@dg2 ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Thu Mar 22 17:25:36 2012
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
Connected to an idle instance.

SQL> startup;
ORACLE instance started.

Total System Global Area  222298112 bytes
Fixed Size                  1218628 bytes
Variable Size             100665276 bytes
Database Buffers          117440512 bytes
Redo Buffers                2973696 bytes
Database mounted.
Database opened.
SQL> show parameter allow

NAME                                 TYPE                              VALUE
------------------------------------ --------------------------------- ------------------------------
_allow_resetlogs_corruption          boolean                           TRUE
SQL> show parameter undo_manage

NAME                                 TYPE                              VALUE
------------------------------------ --------------------------------- ------------------------------
undo_management                      string                            MANUAL
undo_management和 _allow_resetlogs_corruption修改回默认值
SQL> alter system set "_allow_resetlogs_corruption"= false scope=spfile;
System altered.

SQL>  alter system set undo_management=auto scope=spfile;
System altered.

SQL> select dbid from v$database;
      DBID
----------
3467808666

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup;
ORACLE instance started.

Total System Global Area  222298112 bytes
Fixed Size                  1218628 bytes
Variable Size             100665276 bytes
Database Buffers          117440512 bytes
Redo Buffers                2973696 bytes
Database mounted.
Database opened.

这里顺便提下undo的相关概念
1. 回滚段已过时(undo_management = maual),10g以后都以撤销段为概念(undo_management = auto).
2. 撤销段只能存在于专门针对撤销目的创建的某个表空间内,而回滚段则可以被创建在任何表空间内.
3. 回滚段呆在数据库创建阶段,除了数据字典之外,ORACLE还会在SYSTEM表空间内创建一个过时的回滚段,这个回滚段在数据库创建期间使用,但是决不会在正常运行期间使用.
4. 撤销段的类型命名为TYPE2 UNDO,而回滚段为ROLLBACK,即为TYPE1 UNDO.
5. 一个数据库中可以存在多个撤销表空间,但是在任意给定时刻都只能使用一个撤销表空间.
6. 撤销表空间必须被创建为持久的/本地管理的表空间.
7. 任何一个事务都只能受一个撤销段保护,一个事务生成的撤销数据无法被分配到多个撤销段中,因此撤销段大小可变.如果某个事务填满了自己使用的撤销段,那么ORACLE会自动为该撤销段添加另一个区间,从而使这个事务能继续进行.

8. undo表空间和DB不同步的情况下无法打开DB,故设置undo_management为maua 可以在打开DB时不启用undo。

_allow_resetlogs_corruption可以在数据库打开时跳过某些一致性检查,也就是说,设置了这个参数后可以打开不一致的数据库。 设置这个隐含参数后,要使用resetlogs选项打开数据库,隐含参数才会生效,否则Oracle在打开数据库时会忽略此参数。 一般该参数适用于下列场景。
当数据库中某些数据文件损坏,而从备份恢复这个文件所需的某个(或某些)联机日志文件或归档日志文件丢失时,只能把这些文件部分恢复,从而与数据库中其他文件不同步,我们可以通过下面的步骤还原并打开数据库:
用之前的备份恢复损坏的数据文件。
尽量还原损坏的文件。
把数据库启动到nomount。
用SQL命令重建控制文件(要求之前用“alter database backup controlfile to trace”做过控制文件的文本备份)               #这步有时可以省略,具体视实际情况而定
设置隐含参数:alter system set “_allow_resetlogs_corruption”=true scope=spfile;
然后关闭数据库,用下面命令重启:alter database open resetlogs
这时,数据库可以打开。但是数据库中的数据可能不一致,某些查询如果涉及这些不一致的数据,会遇到ora-600错误。打开数据库后,我们可以从部分恢复的数据文件及其他正常数据文件中导出尽可能多的数据,然后重建数据库,导入之前导出的数据,从而让损失降低到最小。

参考至:http://blog.chinaunix.net/uid-182041-id-209523.html
            http://lawzjf.itpub.net/post/417/107758

            http://space.itpub.net/15119715/viewspace-677118
本文原创,转载请注明出处、作者
如有错误,欢迎指正
邮箱:czmcj@163.com

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值