根据实际需要,有时安装了oracle之后需要扩展磁盘空间时,往往是新增一个单独的文件路径并挂载存储,这时便需要整体迁移数据库文件

(1)首先确认需要迁移的数据库文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
SQL> select name from v$controlfile;
NAME
-----------------------------------------
D:\ORACLE\ORADATA\XSFREE\CONTROL01.CTL
D:\ORACLE\ORADATA\XSFREE\CONTROL02.CTL
SQL> select name from v$datafile;
NAME
-----------------------------------------
D:\ORACLE\ORADATA\XSFREE\SYSTEM01.DBF
D:\ORACLE\ORADATA\XSFREE\SYSAUX01.DBF
D:\ORACLE\ORADATA\XSFREE\UNDOTBS01.DBF
D:\ORACLE\ORADATA\XSFREE\USERS01.DBF
SQL> select member from v$logfile;
MEMBER
---------------------------------------------
D:\ORACLE\ORADATA\XSFREE\REDO01.LOG
D:\ORACLE\ORADATA\XSFREE\REDO02.LOG
D:\ORACLE\ORADATA\XSFREE\REDO03.LOG
SQL> select name from v$tempfile;
NAME
--------------------------------------
D:\ORACLE\ORADATA\XSFREE\TEMP01.DBF

(2)创建pfile,备份spfile

1
2
3
SQL> create pfile from spfile;
move SPFILEXSFREE.ORA SPFILEXSFREE.ORA_bak

(3)关闭数据库

1
SQL> shutdown immediate;

(4)迁移数据库文件

将D:\oracle\oradata下的文件复制到D:\oracle\oradata_bak下(本测试是将oradata目录下的数据库文件迁移至oradata_bak下)

(5)修改pfile中控制文件路径

1
*.control_files='D:\oracle\oradata_bak\xsfree\control01.ctl','D:\oracle\oradata_bak\xsfree\control02.ctl'

(6)rename文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
SQL> startup mount pfile='D:\oracle\product\11.2.0\dbhome_1\database\INITxsfree.ORA';
SQL> alter database rename file 'D:\ORACLE\ORADATA\XSFREE\SYSTEM01.DBF' to 'D:\ORACLE\ORADATA_BAK\XSFREE\SYSTEM01.DBF';
SQL> alter database rename file 'D:\ORACLE\ORADATA\XSFREE\SYSAUX01.DBF' to 'D:\ORACLE\ORADATA_BAK\XSFREE\SYSAUX01.DBF';
SQL> alter database rename file 'D:\ORACLE\ORADATA\XSFREE\UNDOTBS01.DBF' to 'D:\ORACLE\ORADATA_BAK\XSFREE\UNDOTBS01.DBF';
SQL> alter database rename file 'D:\ORACLE\ORADATA\XSFREE\USERS01.DBF' to 'D:\ORACLE\ORADATA_BAK\XSFREE\USERS01.DBF';
SQL> alter database rename file 'D:\ORACLE\ORADATA\XSFREE\REDO01.LOG' to 'D:\ORACLE\ORADATA_BAK\XSFREE\REDO01.LOG';
SQL> alter database rename file 'D:\ORACLE\ORADATA\XSFREE\REDO02.LOG' to 'D:\ORACLE\ORADATA_BAK\XSFREE\REDO02.LOG';
SQL> alter database rename file 'D:\ORACLE\ORADATA\XSFREE\REDO03.LOG' to 'D:\ORACLE\ORADATA_BAK\XSFREE\REDO03.LOG';
SQL> alter database rename file 'D:\ORACLE\ORADATA\XSFREE\TEMP01.DBF' to 'D:\ORACLE\ORADATA_BAK\XSFREE\TEMP01.DBF';

(7)打开数据库

1
2
3
SQL> alter database open;
SQL> create spfile from pfile='D:\oracle\product\11.2.0\dbhome_1\database\INITxsfree.ORA';