----------------------非系统表空间
SQL> set linesize 150
SQL> set pagesize 400
SQL> column file_name format a65
SQL> column tablespace_name format a25
SQL> select file_name,file_id,ONLINE_STATUS,tablespace_name from dba_data_files;
FILE_NAME FILE_ID ONLINE_ TABLESPACE_NAME
----------------------------------------------------------------- ---------- ------- -------------------------
+DATA/hyw/datafile/users.259.903803203 4 ONLINE USERS
+DATA/hyw/datafile/undotbs1.258.903803203 3 ONLINE UNDOTBS1
+DATA/hyw/datafile/sysaux.257.903803203 2 ONLINE SYSAUX
+DATA/hyw/datafile/system.256.903803201 1 SYSTEM SYSTEM
+DATA/hyw/datafile/undotbs2.265.903803821 5 ONLINE UNDOTBS2
SQL> create tablespace tdb datafile '/u02/app/oracle/datafile/tdb.dbf' size 10m autoextend off; //模拟添加数据文件
Tablespace created.
将数据文件offline
SQL> alter database datafile 6 offline;
Database altered.
使用RMAN移动本地文件到asm
RMAN> copy datafile '/u02/app/oracle/datafile/tdb.dbf' to '+DATA';
Starting backup at 03-FEB-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=35 instance=orcl1 device type=DISK
channel ORA_DISK_1: starting datafile copy
input datafile file number=00006 name=/u02/app/oracle/datafile/tdb.dbf
output file name=+DATA/orcl/datafile/tdb.268.902813699 tag=TAG20160203T053456 RECID=1 STAMP=902813699
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
Finished backup at 03-FEB-16
注册一下
RMAN> switch datafile '/u02/app/oracle/datafile/tdb.dbf' to copy;
将数据文件online
SQL> alter database datafile 6 online;
Database altered.
检查数据文件
select file_name,file_id,ONLINE_STATUS,tablespace_name from dba_data_files;
-------------------------系统表空间
alter tablespace system add datafile '/home/oracle/scripts/00.dbf' size 10m autoextend off; //模拟添加数据文件
SQL> alter database datafile 6 offline;
alter database datafile 6 offline
*
ERROR at line 1:
ORA-01541: system tablespace cannot be brought offline; shut down if necessary --这就是为什么需要停机时间
在一个节点执行:
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
另一个节点:
SQL> select open_mode from gv$database;
OPEN_MODE
--------------------
READ WRITE
5.使用asmcmd将本地文件移动到asm
ASMCMD [+data/orcl/datafile] > cp /home/oracle/scripts/00.dbf +DATA
copying /home/oracle/scripts/00.dbf -> +DATA/hyw/datafile/00.dbf
6.启动数据库到mount状态
SQL> startup mount;
ORACLE instance started.
Total System Global Area 1336176640 bytes
Fixed Size 2213136 bytes
Variable Size 587205360 bytes
Database Buffers 738197504 bytes
Redo Buffers 8560640 bytes
Database mounted.
7.修改数据文件路径
SQL> alter database rename file '/home/oracle/scripts/00.dbf' to '+DATA/hyw/datafile/00.dbf';
Database altered.
8.启动数据库
SQL> alter database open;
Database altered.
9.检查数据文件状态
节点一:
FILE_NAME FILE_ID ONLINE_ TABLESPACE_NAME
----------------------------------------------------------------- ---------- ------- -------------------------
+DATA/hyw/datafile/users.259.903803203 4 ONLINE USERS
+DATA/hyw/datafile/undotbs1.258.903803203 3 ONLINE UNDOTBS1
+DATA/hyw/datafile/sysaux.257.903803203 2 ONLINE SYSAUX
+DATA/hyw/datafile/system.256.903803201 1 SYSTEM SYSTEM
+DATA/hyw/datafile/undotbs2.265.903803821 5 ONLINE UNDOTBS2
+DATA/hyw/datafile/00.dbf 6 SYSTEM SYSTEM
节点二:
SQL> select file_name,file_id,ONLINE_STATUS,tablespace_name from dba_data_files;
ERROR:
ORA-01157: cannot identify/lock data file 6 - see DBWR trace file
ORA-01110: data file 6: '+DATA/hyw/datafile/00.dbf'
10.所以最后一步,是要重启节点二
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 1336176640 bytes
Fixed Size 2213136 bytes
Variable Size 486542064 bytes
Database Buffers 838860800 bytes
Redo Buffers 8560640 bytes
Database mounted.
Database opened.
11.检查数据文件
FILE_NAME FILE_ID ONLINE_ TABLESPACE_NAME
----------------------------------------------------------------- ---------- ------- -------------------------
+DATA/hyw/datafile/users.259.903803203 4 ONLINE USERS
+DATA/hyw/datafile/undotbs1.258.903803203 3 ONLINE UNDOTBS1
+DATA/hyw/datafile/sysaux.257.903803203 2 ONLINE SYSAUX
+DATA/hyw/datafile/system.256.903803201 1 SYSTEM SYSTEM
+DATA/hyw/datafile/undotbs2.265.903803821 5 ONLINE UNDOTBS2
+DATA/hyw/datafile/00.dbf 6 SYSTEM SYSTEM