一、 概述
目前在各个行业业务中存在大量的Oracle RAC环境,尤其对于中小型企业及一些管理不规范的环境中,对数据库的操作也就显得杂乱无章了,它不是核心系统,但有问题也够运维人员喝一壶的。下面说一个常见的问题,就是在RAC环境中,往往会遇到本地数据文件,也就是只能在一个节点访问,出现这样的状况,主要有两个原因,命名不规范,造成Oracle自动创建到DBS目录下,再个对RAC系统不了解,按照之前方式创建。那么在出现这个问题时怎么解决呢,下面我们简单学习一下。
二、操作过程
本次操作对象为非系统表空间,环境rhel5.8_x64+Oracle RAC11g
1、 RAC为归档模式,不停库,通过Oracle11g asmcmd 中cp命令,操作。
首先模拟环境:
SQL> create tablespace ceshi datafile 'ceshi.dbf' size 10m;
Tablespace created.
SQL> select file_name from dba_data_files;
FILE_NAME
--------------------------------------------------
+OCR/prod/datafile/users.259.905592109
+OCR/prod/datafile/undotbs1.258.905592109
+OCR/prod/datafile/sysaux.257.905592107
+OCR/prod/datafile/system.256.905592107
+OCR/prod/datafile/undotbs2.264.905592463
+OCR/prod/datafile/lcl.dbf
/s01/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/ceshi.dbf
7 rows selected.
节点1,查看数据文件状态、信息
SQL> set lines 150
SQL> col file_name for a55SQL> select file_name,file_id,ONLINE_STATUS,tablespace_name from dba_data_files;
FILE_NAME FILE_ID ONLINE_ TABLESPACE_NAME
-------------------------------------------------- ---------- ------- ------------------------------
+OCR/prod/datafile/users.259.905592109 4 ONLINE USERS
+OCR/prod/datafile/undotbs1.258.905592109 3 ONLINE UNDOTBS1
+OCR/prod/datafile/sysaux.257.905592107 2 ONLINE SYSAUX
+OCR/prod/datafile/system.256.905592107 1 SYSTEM SYSTEM
+OCR/prod/datafile/undotbs2.264.905592463 5 ONLINE UNDOTBS2
+OCR/prod/datafile/lcl.dbf 6 ONLINE LCL
/s01/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/ceshi.dbf 7 ONLINE CESHI
7 rows selected.
节点2,查看数据文件状态,信息
SQL> set lines 200
SQL> col file_name for a50
SQL> col tablespace_name for a10
SQL> select file_name,file_id,ONLINE_STATUS,tablespace_name from dba_data_files;
ERROR:
ORA-01157: cannot identify/lock data file 7 - see DBWR trace file
ORA-01110: data file 7: '/s01/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/ceshi.dbf'
no rows selected
因为不是在共享存储上,所以节点2报错
将本地数据文件OFFLINE,或可以将整个表空间OFFLINE
SQL> alter database datafile 7 offline;
通过ASMCMD CP命令拷贝数据文件
ASMCMD> cp /s01/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/ceshi.dbf +OCR/prod/datafile/ceshi.dbf
copying /s01/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/ceshi.dbf -> +OCR/prod/datafile/ceshi.dbf
ASMCMD>
ASMCMD> ls -lrt
WARNING:option 'r' is deprecated for 'ls'
please use 'reverse'
DATAFILE HIGH COARSE MAR 04 09:00:00 Y SYSTEM.256.905592107
DATAFILE HIGH COARSE MAR 04 09:00:00 Y UNDOTBS1.258.905592109
DATAFILE HIGH COARSE MAR 04 09:00:00 Y UNDOTBS2.264.905592463
DATAFILE HIGH COARSE MAR 04 09:00:00 Y USERS.259.905592109
DATAFILE HIGH COARSE MAR 04 10:00:00 Y SYSAUX.257.905592107
N ceshi.dbf => +OCR/ASM/DATAFILE/ceshi.dbf.269.905597105
N lcl.dbf => +OCR/ASM/DATAFILE/lcl.dbf.268.905595941
rename数据文件,并查看信息
SQL> alter database rename file '/s01/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/ceshi.dbf' to '+OCR/prod/datafile/ceshi.dbf';
Database altered.
SQL> set lines 200
SQL> col file_name for a50
SQL> select file_name,file_id,ONLINE_STATUS,tablespace_name from dba_data_files;
FILE_NAME FILE_ID ONLINE_ TABLESPACE_NAME
-------------------------------------------------- ---------- ------- ------------------------------
+OCR/prod/datafile/users.259.905592109 4 ONLINE USERS
+OCR/prod/datafile/undotbs1.258.905592109 3 ONLINE UNDOTBS1
+OCR/prod/datafile/sysaux.257.905592107 2 ONLINE SYSAUX
+OCR/prod/datafile/system.256.905592107 1 SYSTEM SYSTEM
+OCR/prod/datafile/undotbs2.264.905592463 5 ONLINE UNDOTBS2
+OCR/prod/datafile/lcl.dbf 6 ONLINE LCL
+OCR/prod/datafile/ceshi.dbf 7 RECOVER CESHI
7 rows selected.
我们可以看到,数据文件已移植到ASM中,但需要recover。
recover数据文件,再次将数据文件online
SQL> recover datafile 7;
Media recovery complete.
SQL> alter database datafile 7 online;
Database altered.
SQL> set lines 150
SQL> col file_name for a55
SQL> select file_name,file_id,ONLINE_STATUS,tablespace_name from dba_data_files;
FILE_NAME FILE_ID ONLINE_ TABLESPACE_NAME
-------------------------------------------------- ---------- ------- ------------------------------
+OCR/prod/datafile/users.259.905592109 4 ONLINE USERS
+OCR/prod/datafile/undotbs1.258.905592109 3 ONLINE UNDOTBS1
+OCR/prod/datafile/sysaux.257.905592107 2 ONLINE SYSAUX
+OCR/prod/datafile/system.256.905592107 1 SYSTEM SYSTEM
+OCR/prod/datafile/undotbs2.264.905592463 5 ONLINE UNDOTBS2
+OCR/prod/datafile/lcl.dbf 6 ONLINE LCL
+OCR/prod/datafile/ceshi.dbf 7 ONLINE CESHI
7 rows selected.
两个节点查看,都正常。