How to rename or move a datafile in oracle
How to
rename or move a datafile in oracle
Renaming/Relocating a Data File or Tablespace
1. Take the tablespace offline:
ALTER TABLESPACE USER_DATA OFFLINE;
2. Copy the file to the new
location by using OS commands on the disk.
3. Rename the files in the
database by using one of the following two commands. The number of data files
specified before the keyword TO should be equal to the number of files
specified after the keyword.
ALTER DATABASE RENAME FILE
‘/disk1/oradata/DB01/user_data01.dbf‘,
‘/disk1/oradata/DB01/userdata2.dbf‘,
‘/disk1/oradata/DB01/user_data03.dbf‘
TO
‘/disk2/oradata/DB01/user_data01.dbf‘,
‘/disk2/oradata/DB01/user_data02.dbf‘,
‘/disk2/oradata/DB01/user_data03.dbf‘;
Or
ALTER TABLESPACE USER_DATA RENAME DATAFILE
‘/disk1/oradata/DB01/user_data01.dbf‘,
‘/disk1/oradata/DB01/userdata2.dbf‘,
‘/disk1/oradata/DB01/user_data03.dbf‘
TO
‘/disk2/oradata/DB01/user_data01.dbf‘,
‘/disk2/oradata/DB01/user_data02.dbf‘,
‘/disk2/oradata/DB01/user_data03.dbf‘;
4. Bring the tablespace online:
ALTER TABLESPACE USER_DATA ONLINE;
Renaming or Relocating Files
Belonging to Multiple Tablespaces
If you need to rename or relocate files
belonging to multiple tablespaces or if the file belongs to the SYSTEM
tablespace, you must follow these steps:
1. Shut down the database. A
complete backup is recommended before making any structural changes.
2. Copy or rename the files on
the disk by using OS commands.
3. Start up and mount the
database (STARTUP MOUNT).
4. Rename the files in the
database by using the ALTER DATABASE RENAME FILE command.
5. Open the database by using
ALTER DATABASE OPEN.
Moving Read-Only Tablespaces
If you need to move read-only tablespaces to
a CD-ROM or any write-once read-many device, follow these steps:
1. Make the tablespace
read-only.
2. Copy the data files
belonging to the tablespace to the read-only device.
3. Rename the files in the database by
using the ALTER DATABASE RENAME FILE command.
A Real World
Scenario
Your operating-system administrator informed
you that he is seeing lot of contention on the H drive and is seeking options
to move some of the reads off the H drive and to G drive. As a DBA, you can
move one of the hot files belonging to the receivables tablespace to the G
drive.
You need to take a tablespace offline to
perform some maintenance operations, such as recovering the tablespace or
moving the data files to a new location. Use the OFFLINE clause with an ALTER
TABLESPACE statement to take a tablespace offline. Follow these steps to rename
or move a data file:
1. Take the receivables
tablespace offline:
ALTER TABLESPACE receivables OFFLINE;
2. Use an operating-system
program to physically move the file, such as Copy in Microsoft Windows or cp in
Unix.
3. Tell the database about the
new location:
ALTER TABLESPACE receivables RENAME DATAFILE
‘H:\ORACLE\ORADATA\ORA10\RECEIVABLES02.DBF’
TO
‘G:\ORACLE\ORADATA\ORA10\RECEIVABLES02.DBF’ ;
4. Bring the tablespace back
online:
ALTER TABLESPACE receivables ONLINE;
Comments
Post a Comment