Consider the following scenario: I got a oracle database that reside in /db/mydb. For some reason I need to copy or move the database to somewhere else, let’s say /db2/mydb2.
To do this, follow the steps:
- Shutdown the database either using service or sql statement:
shutdown immediate. - Copy or move the database to
/db2and rename the new database directory tomydb2. - Edit the initialize parameter file in the
mydb2(something like initxxx.ora), change the all the paths to the new path (from/db/mydbto/db2/mydb2) - Log in to sqlplus with NOLOG (run in terminal):
sqlplus /nolog - Connect to empty instance (run in SQLPLUS):
connection / as sysdba - Create SPFILE, aware that the path of the initialize parameter file might be vary (run in SQLPLUS):
create spfile from pfile='/db2/mydb2/admin/pfile/initxxx.ora'; - Start database in mount mode (run in SQLPLUS):
startup mount; - Change the data file path to the new path (run in SQLPLUS):
alter database rename file '/db/mydb/data.dbf', '/db/mydb/system.dbf' to '/db2/mydb2/data.dbf', '/db2/mydb2/system.dbf'; - Ensure you change all the data file path! Or else it will cause the orginal database cannot be startup!
- Open your database (run in SQLPLUS):
alter database open; - Now it is good to go.
- Rename the new database to mydb2
- Remember to change the database name in
mydb2parameter file as well. - Log into SQLPLUS. At this point, you need to aware the
SID_NAMEin your environment parameter, need to be point to the database that you want to log in. Now we want to log in to the original, so we set theSID_NAMEtomydb(terminal):export SID_NAME=mydb - Connect to empty instance (SQLPLUS):
connect / as sysdba - Create the SPFILE again using the original parameter file (SQLPLUS):
create spfile from pfile='/db/mydb/admin/pfile/initxxx.ora'; - Now you should able to start your database (SQLPLUS):
startup




