试验了很多次Oracle数据库迁移才成功,贴出来给大家参考一下,我看到有的地方写迁移之后还需要重新建立temp表空间,这个还没有研究。另外说一点的是两个数据库的版本一定要一致,之前失败过一次,就是因为两个数据库的版本不一致,无法迁移,查询版本:
show parameter compatible
1. 获取原数据库相关信息
首先要查看一下数据库的文件内容
SQL> select name from v$datafile;
NAME
--------------------------------------------------------
G:\ORACLE\ORADATA\orcl\SYSTEM01.DBF
G:\ORACLE\ORADATA\orcl\UNDOTBS01.DBF
G:\ORACLE\ORADATA\orcl\SYSAUX01.DBF
G:\ORACLE\ORADATA\orcl\USERS01.DBF
G:\ORACLE\ORADATA\orcl\EXAMPLE01.DBF
G:\ORACLE\ORADATA\orcl\HOTELFILE
G:\ORACLE\ORADATA\orcl\MEMBERFILE
E:\ELITEDATA\ELITE
G:\ORACLE\ORADATA\orcl\ELITE_BAK
G:\ORACLE\ORADATA\orcl\HOTEL0826FILE
G:\ORACLE\ORADATA\orcl\ELITEOB
SQL> select name from v$controlfile;
NAME
--------------------------------------------
G:\ORACLE\ORADATA\orcl\CONTROL01.CTL
G:\ORACLE\ORADATA\orcl\CONTROL02.CTL
G:\ORACLE\ORADATA\orcl\CONTROL03.CTL
SQL> select member from v$logfile;
MEMBER
---------------------------------------
G:\ORACLE\ORADATA\orcl\REDO01.LOG
G:\ORACLE\ORADATA\orcl\REDO03.LOG
G:\ORACLE\ORADATA\orcl\REDO02.LOG
2. 移动应用数据文件
shutdown immediate
关闭数据库,拷贝以上文件到另外一个目录下,一定要保证数据库完全停掉
3. 修改数据库文件的位置
启动MOUNT模式,将现有数据库SYSTEM01.DBF文件指向拷贝过的SYSTEM01.DBF文件
- startup mount;
- alter database rename file 'E:\oracle\product\10.2.0\oradata\orcl\SYSTEM01.DBF'
- to 'E:\orcl\SYSTEM01.DBF';
4. 修改pfile文件
备份spfile文件到pfile文件,注:不要直接修改pfile文件,两者可能存在差异
create pfile='D:\oracle\product\10.2.0\admin\orcl\pfile\init.ora' from spfile;
修改init.ora文件中的内容:
*.control_files='E:\orcl\control01.ctl','E:\orcl\control02.ctl','E:\orcl\control03.ctl'
5. 从pfile重启数据库
- shutdown immediate
- startup pfile='D:\oracle\product\10.2.0\admin\orcl\pfile\init.ora'
报错6. rname数据库文件路径
- alter database rename file 'G:\ORACLE\ORADATA\orcl\SYSTEM01.DBF'
- to 'E:\orcl\SYSTEM01.DBF';
- alter database rename file 'G:\ORACLE\ORADATA\orcl\UNDOTBS01.DBF'
- to 'E:\orcl\UNDOTBS01.DBF';
- alter database rename file 'G:\ORACLE\ORADATA\orcl\SYSAUX01.DBF'
- to 'E:\orcl\SYSAUX01.DBF';
- alter database rename file 'G:\ORACLE\ORADATA\orcl\USERS01.DBF'
- to 'E:\orcl\USERS01.DBF';
- alter database rename file 'G:\ORACLE\ORADATA\orcl\EXAMPLE01.DBF'
- to 'E:\orcl\EXAMPLE01.DBF';
- alter database rename file 'G:\ORACLE\ORADATA\orcl\HOTELFILE'
- to 'E:\orcl\HOTELFILE';
- alter database rename file 'G:\ORACLE\ORADATA\orcl\MEMBERFILE'
- to 'E:\orcl\MEMBERFILE';
- alter database rename file 'E:\ELITEDATA\ELITE'
- to 'E:\orcl\ELITE';
- alter database rename file 'G:\ORACLE\ORADATA\orcl\ELITE_BAK'
- to 'E:\orcl\ELITE_BAK';
- alter database rename file 'G:\ORACLE\ORADATA\orcl\HOTEL0826FILE'
- to 'E:\orcl\HOTEL0826FILE';
- alter database rename file 'G:\ORACLE\ORADATA\orcl\ELITEOB'
- to 'E:\orcl\ELITEOB';
-
- alter database rename file 'G:\ORACLE\ORADATA\orcl\REDO01.LOG'
- to 'E:\orcl\REDO01.LOG';
- alter database rename file 'G:\ORACLE\ORADATA\orcl\REDO03.LOG'
- to 'E:\orcl\REDO03.LOG';
- alter database rename file 'G:\ORACLE\ORADATA\orcl\REDO02.LOG'
- to 'E:\orcl\REDO02.LOG';
7. 从pfile重启数据库,并重建spfile
- shutdown immediate
- startup pfile='D:\oracle\product\10.2.0\admin\orcl\pfile\init.ora'
- create spfile from pfile='D:\oracle\product\10.2.0\admin\orcl\pfile\init.ora';