在12c以前的版本中,想要移动数据文件的位置,只有在数据库mount阶段或者表空间数据文件offline的情况下才可以移动,这就意味着想要移动数据文件只能在停机窗口下进行,在12c以及之后的版本中可以在线进行数据文件的move动作,减少停机窗口时间。具体可参考如下文档.
GOAL
In this release, a data file can now be moved online while it is open and being accessed, even for data files in system tablespace.
Being able to move a data file online means that many maintenance operations, such as moving data to another storage device or moving databases into Oracle Automatic Storage Management (Oracle ASM), can be performed while users are accessing the system. This ensures that continuity of service and service-level agreements (SLA) on uptime can be met.
SOLUTION
With Oracle 12C, you can now do the following operations while the datafile is online and being accessed:
- Renaming an Online Data File
- Relocating an Online Data File
- Copying an Online Data File
- Relocating an Online Data File and Overwriting an Existing File
- Relocating an Online Data File to Oracle ASM
The following is an example of how each operation is done:
Renaming an Online Data File:
SQL> CREATE TABLESPACE test DATAFILE ‘
EXTENT MANAGEMENT LOCAL
SEGMENT SPACE MANAGEMENT AUTO; 2 3
Tablespace created.
SQL> select file_name, status, online_status from dba_data_files;
FILE_NAME
STATUS ONLINE_
AVAILABLE SYSTEM
AVAILABLE ONLINE
AVAILABLE ONLINE
AVAILABLE ONLINE
AVAILABLE ONLINE
SQL> ALTER DATABASE MOVE DATAFILE ‘
TO ‘
Database altered.
SQL> select file_name, status, online_status from dba_data_files where file_name=’
FILE_NAME
STATUS ONLINE_
AVAILABLE ONLINE
- Relocating an Online Data File:
===================================
SQL> ALTER DATABASE MOVE DATAFILE ‘//test_renamed.dbf’
TO ‘/test_renamed.dbf’;
Database altered.
SQL> select file_name, status, online_status from dba_data_files where file_name=’
no rows selected
SQL> select file_name, status, online_status from dba_data_files;
FILE_NAME
STATUS ONLINE_
AVAILABLE SYSTEM
AVAILABLE ONLINE
AVAILABLE ONLINE
AVAILABLE ONLINE
AVAILABLE ONLINE
- Copying an Online Data File:
=================================
SQL> ALTER DATABASE MOVE DATAFILE ‘//test_renamed.dbf’
TO ‘/test_renamed.dbf’ keep;
Database altered.
SQL> select file_name, status, online_status from dba_data_files where file_name=’
no rows selected
SQL> select file_name, status, online_status from dba_data_files;
FILE_NAME
STATUS ONLINE_
AVAILABLE SYSTEM
AVAILABLE ONLINE
AVAILABLE ONLINE
AVAILABLE ONLINE
AVAILABLE ONLINE
– expect to see the entry:
–
– AVAILABLE ONLINE
– However, when i try to move the datafile to the location
– which verifies that the datafile was indeed copied and kept available in the old location:
SQL> ALTER DATABASE MOVE DATAFILE ‘
TO ‘
ALTER DATABASE MOVE DATAFILE ‘
*
ERROR at line 1:
ORA-01119: error in creating database file
‘
ORA-27038: created file already exists
Additional information: 1
- Example of relocating an Online Data File and Overwriting an Existing File:
=====================================================================
SQL> ALTER DATABASE MOVE DATAFILE ‘/test_renamed.dbf’
TO ‘//test_renamed.dbf’ REUSE;
Database altered.
SQL> select file_name, status, online_status from dba_data_files where file_name=’
FILE_NAME
STATUS ONLINE_
AVAILABLE ONLINE
SQL> select file_name, status, online_status from dba_data_files;
FILE_NAME
STATUS ONLINE_
AVAILABLE SYSTEM
AVAILABLE ONLINE
AVAILABLE ONLINE
AVAILABLE ONLINE
AVAILABLE ONLINE
- Relocate an Online Data File to Oracle ASM:
================================================
This example moves the data file user1.dbf fromdirectory to an Oracle ASM location.
ALTER DATABASE MOVE DATAFILE ‘
TO ‘+dg_group1/user1.dbf’;
This example moves the data file from one Oracle ASM location to another Oracle ASM location.
ALTER DATABASE MOVE DATAFILE +dg_group1/user1.dbf’
TO ‘+dg_group2/user1.dbf’;
For more information about moving a datafile online, please refer to: http://docs.oracle.com/cd/E16655_01/server.121/e17636/dfiles.htm#ADMIN13837