Pages

Sunday, November 11, 2018

Move Datafile from Location to a new Location

==================================
General
==================================
Example of moving Datafile from Location A to Location B

==================================
Example
==================================
Steps
Check Database Archive Mode
SQL> SELECT log_mode FROM V$DATABASE;

LOG_MODE
---------------------------
ARCHIVELOG

==================================
Database is in ARCHIVELOG mode
==================================
- Take the datafile offline.
ALTER DATABASE DATAFILE '/old/datafile/location/datafile_01.dbf' OFFLINE;

SQL>Database Altered

- Copy or move the datafile to its new location.
dd if=/old/location/datafile_01.dbf of=new/location/datafile_01.dbf bs='4096
or
cp -p /old/location/datafile_01.dbf /new/location/datafile_01.dbf

- Point Database to the new datafile location.
ALTER DATABASE RENAME FILE '/old/location/datafile_01.dbf' TO 'new/location/datafile_01.dbf';

SQL>Database altered.

- Recover new datafile.

RECOVER DATAFILE '/new/location/datafile_01.dbf';

SQL>Media recovery complete.

- Bring Datafile Online.

ALTER DATABASE DATAFILE 'new/location/datafile_01.dbf' ONLINE;

SQL>Database altered.

Delete datafile from old location
rm -f /old/location/datafile_01.dbf

==================================
Database is in NOARCHIVELOG mode
==================================
- Shutdown the database
SHUTDOWN IMMEDIATE;

- Copy or move the datafile to its new location.
dd if=/old/location/datafile_01.dbf of=new/location/datafile_01.dbf bs=4096
or
cp -p /old/location/datafile_01.dbf /new/location/datafile_01.dbf


- STARTUP MOUNT
STARTUP MOUNT;

- Rename the file:
ALTER DATABASE RENAME FILE '/old/location/datafile_01.dbf' TO '/new/location/datafile_01.dbf';

-Open The Database
ALTER DATABASE OPEN;