Featured

    Featured Posts

Renaming/Relocating a Datafile from original location to new location?



We can achieve this task in two ways..ie,
1.Offline method. 2.Online method.
To rename/relocate the datafile from the original location to new location, tablespace should be offline first. otherwise the following error is encountered.
ORA-01511: error in renaming log/data files
ORA-01121: cannot rename database file <string> – file is in use or recoveryORA-01110: data file <string>: ‘datafile.dbf’
Method 1:
  1. Login to SQLPlus.
  2. Connect as SYS DBA with CONNECT / AS SYSDBA command.
  3. Shutdown the database instance with SHUTDOWN command.
  4. Rename or/and move the datafiles at operating system level.
  5. Start Oracle database in mount state with STARTUP MOUNT command.
  6. Modify the name or location of datafiles in Oracle data dictionary using following command syntax:
  7. Open Oracle database instance completely with ALTER DATABASE OPEN command.
$ sqlplus sys/oracle@TNS as sysdba
SQL>shutdown immediate 
$mv /u01/app/oradata/users01.dbf /u02/app/oradata/users01.dbf
$ sqlplus sys/oracle@TNS as sysdba
SQL>startup mount;
SQL> ALTER DATABASE RENAME FILE '/u01/app/oradata/users01.dbf ' TO '/u02/app/oradata/users01.dbf ';
SQL> alter database open;

If the datafiles that need to be changed or moved do not belong to SYSTEM tablespaces, and do not contain active rollback segments or temporary segments, there is another workaround that does not require database instance to be shutdown. Instead, only the particular tablespace that contains the date files is taken offline.
Method 2:
  1. Login to SQLPlus.
  2. Connect as SYS DBA with CONNECT / AS SYSDBA command.
  3. Make offline the affected tablespace with ALTER TABLESPACE <tablespace name> OFFLINE; 
  4.  Modify the name or location of datafiles in Oracle data dictionary using following command syntax:
SQL>ALTER TABLESPACE USERS RENAME DATAFILE '/u01/app/oradata/users01.dbf ' TO '/u02/app/oradata/users01.dbf ';
  1. Bring the tablespace online again with ALTER TABLESPACE <tablespace name> ONLINE;


$ sqlplus sys/oracle@TNS as sysdba
SQL>ALTER TABLESPACE USERS OFFLINE;
SQL>ALTER TABLESPACE USERS RENAME DATAFILE '/u01/app/oradata/users01.dbf ' TO '/u02/app/oradata/users01.dbf ';
SQL>ALTER TABLESPACE USERS ONLINE;

Facebook like and share

Related Posts You might be Interested:

Do you like this post? Please share this article.

HTML Link Code:

Post a Comment

https://marthadba.blogspot.in/

Copyright © MARTHADBA|About Us |Disclaimer | Contact Us |Sitemap |Designed By CodeNirvana