How to Move Oracle Tablespaces and Datafiles to a New Location
This guide explains step‑by‑step how to offline Oracle datafiles or tablespaces, copy them to a new directory, rename them, recover if needed, bring them back online, and safely shut down and restart the database to complete the migration.
Moving Tablespaces and Datafiles Offline
The process begins by taking the target datafile or tablespace offline, copying the physical file to the new location, renaming it within the database, performing any required recovery, and finally bringing the object back online.
Offline by Datafile
Take the specific datafile offline:
ALTER DATABASE DATAFILE 'D:/ORACLE/ORADATA/DBA/TEST01.DBF' OFFLINE;Copy the physical file to the new directory (e.g., D:/TEST01.DBF).
Rename the file inside the database:
ALTER DATABASE RENAME FILE 'D:/ORACLE/ORADATA/DBA/TEST01.DBF' TO 'D:/TEST01.DBF';Recover the datafile because an offline file requires media recovery: RECOVER DATAFILE 'D:/TEST01.DBF'; Bring the datafile online:
ALTER DATABASE DATAFILE 'D:/TEST01.DBF' ONLINE;Offline by Tablespace
Take the tablespace offline: ALTER TABLESPACE TEST OFFLINE; Copy the associated datafile(s) to the new location.
Rename the datafile inside the tablespace:
ALTER TABLESPACE TEST RENAME DATAFILE 'D:/TEST01.DBF' TO 'D:/ORACLE/ORADATA/DBA/TEST01.DBF';Bring the tablespace online:
ALTER TABLESPACE TEST ONLINE;Shutdown and Restart the Database
C:> set ORACLE_SID=DBA C:> sqlplus /nolog SQL*Plus: Release 10.2.0.1.0 - Production on Sun Nov 29 11:14:02 2009 SQL> conn sys/admin as sysdba SQL> shutdown immediate -- Database is now shut down.
After the shutdown, copy the datafile to its new location, then restart the instance in mount mode to perform the rename:
SQL> startup mount SQL> ALTER DATABASE RENAME FILE 'D:/ORACLE/ORADATA/DBA/TEST01.DBF' TO 'D:/TEST01.DBF'; SQL> ALTER DATABASE OPEN; SQL> SELECT file#, name, status FROM v$datafile;
The query confirms that the moved file (e.g., D:/TEST01.DBF) is now ONLINE along with the other datafiles.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ITPUB
Official ITPUB account sharing technical insights, community news, and exciting events.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
