RAC环境下误操作将数据文件添加到本地存储

今天碰到个有意思的事情,有客户在Oracle RAC环境,误操作将新增的数据文件直接创建到了其中一个节点的本地存储上。发现网上去搜的话这种问题还真不少,对应解决方案也各式各样,客户问我选择哪种方案可行,看来基础的数据维护工作还是有必要进一步规范的。
数据库是归档模式,那么我们实际可以利用rman的backup as copy datafile xxx format ''以及 switch datafile xxx to copy来操作,这样来解决是最简单且最不容易误操作的。

简单做一个实验来说明,整个过程如下:

1.模拟误操作添加一个数据文件到本地存储目录下

SQL> alter tablespace users add datafile '/tmp/user02.dbf' size 50M; Tablespace altered. SQL> select file_id, file_name from dba_data_files; FILE_ID FILE_NAME ---------- ------------------------------------------------------------------ 1 +DATA/NEWDB1/DATAFILE/system.257.954241433 3 +DATA/NEWDB1/DATAFILE/sysaux.258.954241497 4 +DATA/NEWDB1/DATAFILE/undotbs1.259.954241533 7 +DATA/NEWDB1/DATAFILE/users.260.954241535 15 /tmp/user02.dbf 9 +DATA/NEWDB1/DATAFILE/undotbs2.269.954241841 6 rows selected.

查到这个误操作新增的数据文件号是15.

2.利用RMAN把15号文件备份副本(backup as copy)

RMAN> backup as copy datafile 15 format '+data'; Starting backup at 05-DEC-17 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=47 instance=newdb11 device type=DISK channel ORA_DISK_1: starting datafile copy input datafile file number=00015 name=/tmp/user02.dbf output file name=+DATA/NEWDB1/DATAFILE/users.279.961935881 tag=TAG20171205T122439 RECID=4 STAMP=961935880 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01 Finished backup at 05-DEC-17 Starting Control File and SPFILE Autobackup at 05-DEC-17 piece handle=+FRA/NEWDB1/AUTOBACKUP/017_12_05/s_961935881.262.961935883 comment=NONE Finished Control File and SPFILE Autobackup at 05-DEC-17

3.将15号数据文件离线
可以只将错误的15号数据文件离线,减小影响;

RMAN> alter database datafile 15 offline; Statement processed

4.切换15号数据文件到copy副本

RMAN> switch datafile 15 to copy; datafile 15 switched to datafile copy "+DATA/NEWDB1/DATAFILE/users.279.961935881"

5.恢复15号数据文件

RMAN> recover datafile 15; Starting recover at 05-DEC-17 using channel ORA_DISK_1 starting media recovery media recovery complete, elapsed time: 00:00:00 Finished recover at 05-DEC-17

6.将15号数据文件上线

RMAN> alter database datafile 15 online; Statement processed FILE_ID FILE_NAME ---------- ------------------------------------------------------------------ 1 +DATA/NEWDB1/DATAFILE/system.257.954241433 3 +DATA/NEWDB1/DATAFILE/sysaux.258.954241497 4 +DATA/NEWDB1/DATAFILE/undotbs1.259.954241533 7 +DATA/NEWDB1/DATAFILE/users.260.954241535 15 +DATA/NEWDB1/DATAFILE/users.279.961935881 9 +DATA/NEWDB1/DATAFILE/undotbs2.269.954241841 6 rows selected.

注:如果客户有特殊要求,backup as copy时直接将数据文件名改成规范的,比如在步骤2中可以这样指定具体的名字:

RMAN> backup as copy datafile 15 format '+data/NEWDB1/DATAFILE/users02.DBF';

实际上users02.dbf这种也只是个别名,底层还是OMF那种命名的文件,这样做没什么太大的实际意义,但有时候客户会喜欢这种看起来更好管理的方式。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/a38cc764622267f845c4cf5e18624553.html