表空间数据文件迁移到另外的位置(backup as copy tablespace)

喜欢而已 提交于 2019-12-19 02:32:59

环境:

OS: Centos 7

DB:12.2.0.1 数据库必须在归档模式

1.创建表空间
12c pdb下创建表空间
create tablespace tps_data
logging
datafile '/u01/app/oracle/oradata/ora12c/ora12cpdb1/tps_data01.dbf'
size 100m
autoextend on
next 10m maxsize 24G
extent management local;

表空间添加数据文件
alter tablespace tps_data add datafile '/u01/app/oracle/oradata/ora12c/ora12cpdb1/tps_data02.dbf' size 100m;

2.备份表空间tps_data
提前创建目录
mkdir -p /u01/app/oracle/oradata_temp/ora12cpdb1
rman target /
backup as copy tablespace  ORA12CPDB1:tps_data format '/u01/app/oracle/oradata_temp/ora12cpdb1/%N%f.dbf';
(%N为表空间名、%f为数据文件绝对文件号)

3.目录转移
将表空间进行offline
进入pdb
SQL> alter session set container=ORA12CPDB1;
SQL> alter tablespace  tps_data offline;

rman模式执行
RMAN> switch tablespace ORA12CPDB1:tps_data to copy;

datafile 13 switched to datafile copy "/u01/app/oracle/oradata_temp/ora12cpdb1/TPS_DATA13.dbf"
datafile 14 switched to datafile copy "/u01/app/oracle/oradata_temp/ora12cpdb1/TPS_DATA14.dbf"

RMAN> recover tablespace ORA12CPDB1:tps_data;

Starting recover at 06-DEC-19
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=71 device type=DISK

starting media recovery
media recovery complete, elapsed time: 00:00:00

Finished recover at 06-DEC-1

进入pdb
SQL> alter session set container=ORA12CPDB1;
SQL> alter tablespace  tps_data online;

Tablespace altered

4.验证
SQL> Select Name From v$datafile;

NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/ora12c/ora12cpdb1/system01.dbf
/u01/app/oracle/oradata/ora12c/ora12cpdb1/sysaux01.dbf
/u01/app/oracle/oradata/ora12c/ora12cpdb1/undotbs01.dbf
/u01/app/oracle/oradata/ora12c/ora12cpdb1/users01.dbf
/u01/app/oracle/oradata_temp/ora12cpdb1/TPS_DATA13.dbf
/u01/app/oracle/oradata_temp/ora12cpdb1/TPS_DATA14.dbf

6 rows selected.


但是原来的文件还是存在的,可以手工删除掉
[oracle@localhost ora12cpdb1]$ ls -1 /u01/app/oracle/oradata/ora12c/ora12cpdb1
sysaux01.dbf
system01.dbf
temp01.dbf
tps_data01.dbf
tps_data02.dbf
undotbs01.dbf
users01.dbf

 

--The End --

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!