Oracle数据库文件迁移
1.背景
由于业务需求,需要把A服务器上的数据库迁移到B服务器上,B服务器已经有数据库了,而且和A服务器上的数据库数据文件目录名相同,此时,准备把B服务器的数据库所有数据文件重命名。
2.拼接重命名脚本
select 'ALTER DATABASE RENAME FILE '''||FILE_NAME||''' TO '''||REPLACE(FILE_NAME,'data01','t_data01')||''';' from dba_data_files where file_name like '/data01%'
union all
select 'ALTER DATABASE RENAME FILE '''||FILE_NAME||''' TO '''||REPLACE(FILE_NAME,'data01','t_data01')||''';' from dba_temp_files where file_name like '/data01%'
union all
select 'ALTER DATABASE RENAME FILE '''||MEMBER||''' TO '''||REPLACE(MEMBER,'data01','t_data01')||''';' from v$logfile where MEMBER like '/data01%';
3.新增目录
mkdir /t_data01
4.控制文件更换目录
-- 查看控制文件目录
select * from v$parameter where name like '%control_files%';
sqlplus / as sysdba
shutdown immediate;
cp /data01/monkey/control01.ctl /data02/monkey/control01.ctl
sqlplus / as sysdba
startup nomount;
alter system set control_files='/data02/monkey/control01.ctl', '/data02/monkey/control02.ctl', '/data03/monkey/control03.ctl' scope=spfile;
shutdown immediate;
startup mount;
5.重新挂载目录
umount /data01
mount -t vxfs /dev/vx/dsk/t_dg01/t_vol01 /t_data01
6.重命名文件
ALTER DATABASE RENAME FILE '/data01/monkey/datafile/system.259.947709021' TO '/t_data01/monkey/datafile/system.259.947709021';
ALTER DATABASE RENAME FILE '/data01/monkey/datafile/sysaux.260.947708975' TO '/t_data01/monkey/datafile/sysaux.260.947708975';
ALTER DATABASE RENAME FILE '/data01/monkey/datafile/undotbs1.261.947708953' TO '/t_data01/monkey/datafile/undotbs1.261.947708953';
ALTER DATABASE RENAME FILE '/data01/monkey/datafile/users.262.947709021' TO '/t_data01/monkey/datafile/users.262.947709021';
7.打开数据库
alter database open;